"use strict";
var __importDefault = (this && this.__importDefault) || function (mod) {
    return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
const contact_1 = __importDefault(require("./contact"));
const dataExtension_1 = __importDefault(require("./dataExtension"));
const contactDataExtension_1 = __importDefault(require("./contactDataExtension"));
const apiEvent_1 = __importDefault(require("./apiEvent"));
const dataExtensionV2_1 = __importDefault(require("./dataExtensionV2"));
const asyncDataExtension_1 = __importDefault(require("./asyncDataExtension"));
const contactDataExtensionV2_1 = __importDefault(require("./contactDataExtensionV2"));
const versioning_info_1 = require("./versioning-info");
const destination = {
    name: 'Salesforce Marketing Cloud (Actions)',
    slug: 'actions-salesforce-marketing-cloud',
    mode: 'cloud',
    authentication: {
        scheme: 'oauth2',
        fields: {
            subdomain: {
                label: 'Subdomain',
                description: 'The unique subdomain Salesforce Marketing Cloud assigned to your account. Subdomains are tenant specific and should be a 28-character string starting with the letters "mc". Do not include the .rest.marketingcloudapis.com part of your subdomain URL. See more information on how to find your subdomain [here](https://developer.salesforce.com/docs/marketing/marketing-cloud/guide/your-subdomain-tenant-specific-endpoints.html).',
                type: 'string',
                required: true
            },
            account_id: {
                label: 'Account ID',
                description: 'Your Salesforce Marketing Cloud account identifier (or MID). See more information on how to find your MID [here](https://help.salesforce.com/s/articleView?id=sf.mc_overview_determine_your_marketing_cloud_instance.htm&type=5).',
                type: 'string',
                required: true
            },
            client_id: {
                label: 'Client ID',
                description: 'Your Salesforce Marketing Cloud client ID. The client ID is issued when you create an API integration in [Installed Packages](https://developer.salesforce.com/docs/marketing/marketing-cloud/guide/install-packages.html).',
                type: 'string',
                required: true
            },
            client_secret: {
                label: 'Client Secret',
                description: 'Your Salesforce Marketing Cloud client secret. The client secret is issued when you create an API integration in Installed Packages.',
                type: 'password',
                required: true
            }
        },
        refreshAccessToken: async (request, { settings }) => {
            const baseUrl = `https://${settings.subdomain}.auth.marketingcloudapis.com/${versioning_info_1.SALESFORCE_MARKETING_CLOUD_AUTH_API_VERSION}/token`;
            const res = await request(`${baseUrl}`, {
                method: 'POST',
                body: new URLSearchParams({
                    account_id: settings.account_id,
                    client_id: settings.client_id,
                    client_secret: settings.client_secret,
                    grant_type: 'client_credentials'
                })
            });
            return { accessToken: res.data.access_token };
        }
    },
    extendRequest({ auth }) {
        return {
            headers: {
                authorization: `Bearer ${auth?.accessToken}`
            }
        };
    },
    actions: {
        contact: contact_1.default,
        dataExtension: dataExtension_1.default,
        contactDataExtension: contactDataExtension_1.default,
        apiEvent: apiEvent_1.default,
        dataExtensionV2: dataExtensionV2_1.default,
        contactDataExtensionV2: contactDataExtensionV2_1.default,
        asyncDataExtension: asyncDataExtension_1.default
    }
};
exports.default = destination;
//# sourceMappingURL=index.js.map