"use strict";
var __importDefault = (this && this.__importDefault) || function (mod) {
    return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
const syncAudience_1 = __importDefault(require("./syncAudience"));
const actions_core_1 = require("@segment/actions-core");
const constants_1 = require("./constants");
const destination = {
    name: 'LaunchDarkly Audiences',
    slug: 'actions-launchdarkly-audiences',
    mode: 'cloud',
    description: 'Sync [Segment Audiences](https://segment.com/docs/engage/audiences/) to LaunchDarkly [Big Segments](https://docs.launchdarkly.com/home/contexts/big-segments).',
    authentication: {
        scheme: 'custom',
        fields: {
            apiKey: {
                label: 'LaunchDarkly Service Token',
                description: 'We recommend creating a dedicated [LaunchDarkly service token](https://docs.launchdarkly.com/home/account-security/api-access-tokens#service-tokens) for this destination. The service token must have the ability to perform the `createSegment` and `updateIncluded` [role actions](https://docs.launchdarkly.com/home/members/role-actions#segment-actions).',
                type: 'password',
                required: true
            },
            clientId: {
                label: 'LaunchDarkly client-side ID',
                description: 'Copy the [client-side ID](https://app.launchdarkly.com/settings/projects) of the environment for your segment. You can find this in the LaunchDarkly **Account settings** page for your project.',
                type: 'string',
                required: true
            }
        },
        testAuthentication: (request, { settings }) => {
            return Promise.all([
                request(`${constants_1.CONSTANTS.LD_CLIENT_SDK_BASE_URL}/sdk/goals/${settings.clientId}`, { method: 'head' }),
                request(`${constants_1.CONSTANTS.LD_API_BASE_URL}/versions`, {
                    method: 'GET',
                    headers: {
                        Authorization: `${settings.apiKey}`
                    }
                })
            ]);
        }
    },
    extendRequest({ settings }) {
        return {
            headers: {
                'User-Agent': 'SegmentSyncAudiences/1.0.0',
                'Content-Type': 'application/json',
                Authorization: `${settings.apiKey}`,
                'LD-API-Version': '20220603'
            }
        };
    },
    actions: {
        syncAudience: syncAudience_1.default
    },
    presets: [
        {
            name: 'Sync Engage Audience to LaunchDarkly',
            subscribe: 'type = "identify" or type = "track"',
            partnerAction: 'syncAudience',
            mapping: (0, actions_core_1.defaultValues)(syncAudience_1.default.fields),
            type: 'automatic'
        }
    ]
};
exports.default = destination;
//# sourceMappingURL=index.js.map