"use strict";
var __importDefault = (this && this.__importDefault) || function (mod) {
    return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
const actions_core_1 = require("@segment/actions-core");
const aliasUser_1 = __importDefault(require("./aliasUser"));
const trackEvent_1 = __importDefault(require("./trackEvent"));
const utils_1 = require("./utils");
const presets = [
    {
        name: 'Track Event',
        subscribe: 'type = "track"',
        partnerAction: 'trackEvent',
        mapping: (0, actions_core_1.defaultValues)(trackEvent_1.default.fields),
        type: 'automatic'
    },
    {
        name: 'Alias User',
        subscribe: 'type = "identify" or type = "alias"',
        partnerAction: 'aliasUser',
        mapping: (0, actions_core_1.defaultValues)(aliasUser_1.default.fields),
        type: 'automatic'
    }
];
const destination = {
    name: 'LaunchDarkly',
    slug: 'actions-launchdarkly',
    mode: 'cloud',
    description: 'Use Segment events as custom metric events in LaunchDarkly experiments, so you can measure results immediately, without any instrumentation, code, or delays.',
    authentication: {
        scheme: 'custom',
        fields: {
            client_id: {
                label: 'LaunchDarkly client-side ID',
                description: 'Find and copy the client-side ID in the LaunchDarkly account settings page.',
                type: 'string',
                required: true
            },
            events_host_name: {
                label: 'LaunchDarkly events host name',
                description: `Your LaunchDarkly events host name. If not specified, the default value of ${utils_1.DEFAULT_EVENTS_HOST_NAME} will be used. Most customers will not need to change this setting.`,
                type: 'string',
                default: utils_1.DEFAULT_EVENTS_HOST_NAME,
                required: false,
                format: 'hostname'
            }
        },
        testAuthentication: (request, { settings }) => {
            const hostname = settings.events_host_name || utils_1.DEFAULT_EVENTS_HOST_NAME;
            if (hostname !== utils_1.DEFAULT_EVENTS_HOST_NAME) {
                return true;
            }
            return request(`https://clientsdk.launchdarkly.com/sdk/goals/${settings.client_id}`, { method: 'head' });
        }
    },
    extendRequest: () => {
        return {
            headers: {
                'User-Agent': 'SegmentDestination/2.2.0',
                'Content-Type': 'application/json',
                'X-LaunchDarkly-Event-Schema': '4'
            }
        };
    },
    presets,
    actions: {
        aliasUser: aliasUser_1.default,
        trackEvent: trackEvent_1.default
    }
};
exports.default = destination;
//# sourceMappingURL=index.js.map