"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 trackEvent_1 = __importDefault(require("./trackEvent"));
const identifyUser_1 = __importDefault(require("./identifyUser"));
const groupIdentifyUser_1 = __importDefault(require("./groupIdentifyUser"));
const utils_1 = require("./utils");
const presets = [
    {
        name: 'Track Calls',
        subscribe: 'type = "track" and event != "Order Completed"',
        partnerAction: 'trackEvent',
        mapping: (0, actions_core_1.defaultValues)(trackEvent_1.default.fields),
        type: 'automatic'
    },
    {
        name: 'Page Calls',
        subscribe: 'type = "page"',
        partnerAction: 'trackEvent',
        mapping: {
            ...(0, actions_core_1.defaultValues)(trackEvent_1.default.fields),
            event: {
                '@template': 'Viewed {{name}}'
            }
        },
        type: 'automatic'
    },
    {
        name: 'Screen Calls',
        subscribe: 'type = "screen"',
        partnerAction: 'trackEvent',
        mapping: {
            ...(0, actions_core_1.defaultValues)(trackEvent_1.default.fields),
            event: {
                '@template': 'Viewed {{name}}'
            }
        },
        type: 'automatic'
    },
    {
        name: 'Identify Calls',
        subscribe: 'type = "identify"',
        partnerAction: 'identifyUser',
        mapping: (0, actions_core_1.defaultValues)(identifyUser_1.default.fields),
        type: 'automatic'
    },
    {
        name: 'Group Calls',
        subscribe: 'type = "group"',
        partnerAction: 'groupIdentifyUser',
        mapping: (0, actions_core_1.defaultValues)(groupIdentifyUser_1.default.fields),
        type: 'automatic'
    }
];
const destination = {
    name: 'Launchpad (Actions)',
    slug: 'actions-launchpad',
    mode: 'cloud',
    authentication: {
        scheme: 'custom',
        fields: {
            apiSecret: {
                label: 'Secret Key',
                description: 'Launchpad project secret. You can find that in the settings in your Launchpad.pm account.',
                type: 'password',
                required: true
            },
            apiRegion: {
                label: 'Data Residency',
                description: 'Learn about [EU data residency](https://help.launchpad.pm).',
                type: 'string',
                choices: Object.values(utils_1.ApiRegions).map((apiRegion) => ({ label: apiRegion, value: apiRegion })),
                default: utils_1.ApiRegions.US
            },
            sourceName: {
                label: 'Source Name',
                description: "This value, if it's not blank, will be sent as segment_source_name to Launchpad for every event/page/screen call.",
                type: 'string'
            }
        },
        testAuthentication: (request, { settings }) => {
            return request(`https://backend.launchpad.pm/api/data/validate-project-credentials/`, {
                method: 'post',
                body: JSON.stringify({
                    api_secret: settings.apiSecret
                })
            });
        }
    },
    presets,
    actions: {
        trackEvent: trackEvent_1.default,
        identifyUser: identifyUser_1.default,
        groupIdentifyUser: groupIdentifyUser_1.default
    }
};
exports.default = destination;
//# sourceMappingURL=index.js.map