"use strict";
var __importDefault = (this && this.__importDefault) || function (mod) {
    return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
const sendCustomBehavioralEvent_1 = __importDefault(require("./sendCustomBehavioralEvent"));
const upsertContact_1 = __importDefault(require("./upsertContact"));
const upsertCompany_1 = __importDefault(require("./upsertCompany"));
const upsertCustomObjectRecord_1 = __importDefault(require("./upsertCustomObjectRecord"));
const upsertObject_1 = __importDefault(require("./upsertObject"));
const customEvent_1 = __importDefault(require("./customEvent"));
const properties_1 = require("./properties");
const versioning_info_1 = require("./versioning-info");
const destination = {
    name: 'HubSpot Cloud Mode (Actions)',
    slug: 'actions-hubspot-cloud',
    mode: 'cloud',
    authentication: {
        scheme: 'oauth2',
        fields: {
            portalId: {
                description: 'The Hub ID of your HubSpot account.',
                label: 'Hub ID',
                type: 'string'
            }
        },
        testAuthentication: (request) => {
            return request(`${properties_1.HUBSPOT_BASE_URL}/crm/${versioning_info_1.HUBSPOT_CRM_API_VERSION}/objects/contacts?limit=1`);
        },
        refreshAccessToken: async (request, { auth }) => {
            const res = await request(`${properties_1.HUBSPOT_BASE_URL}/oauth/${versioning_info_1.HUBSPOT_OAUTH_API_VERSION}/token`, {
                method: 'POST',
                body: new URLSearchParams({
                    refresh_token: auth.refreshToken,
                    client_id: auth.clientId,
                    client_secret: auth.clientSecret,
                    grant_type: 'refresh_token'
                })
            });
            return { accessToken: res.data?.access_token };
        }
    },
    extendRequest({ auth }) {
        return {
            skipResponseCloning: true,
            headers: {
                authorization: `Bearer ${auth?.accessToken}`
            }
        };
    },
    actions: {
        sendCustomBehavioralEvent: sendCustomBehavioralEvent_1.default,
        upsertContact: upsertContact_1.default,
        upsertCompany: upsertCompany_1.default,
        upsertCustomObjectRecord: upsertCustomObjectRecord_1.default,
        upsertObject: upsertObject_1.default,
        customEvent: customEvent_1.default
    }
};
exports.default = destination;
//# sourceMappingURL=index.js.map