"use strict";
var __importDefault = (this && this.__importDefault) || function (mod) {
    return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
const trackGoal_1 = __importDefault(require("./trackGoal"));
const trackExposure_1 = __importDefault(require("./trackExposure"));
const actions_core_1 = require("@segment/actions-core");
function patch(field, patch) {
    return {
        ...field,
        ...patch
    };
}
const presets = [
    {
        name: 'Track Calls',
        subscribe: 'type = "track" and event != "Experiment Viewed"',
        partnerAction: 'trackGoal',
        mapping: (0, actions_core_1.defaultValues)(trackGoal_1.default.fields),
        type: 'automatic'
    },
    {
        name: 'Page Calls',
        subscribe: 'type = "page"',
        partnerAction: 'trackGoal',
        mapping: (0, actions_core_1.defaultValues)({
            ...trackGoal_1.default.fields,
            name: patch(trackGoal_1.default.fields.name, { default: { '@template': 'Page: {{ name }}' } })
        }),
        type: 'automatic'
    },
    {
        name: 'Screen Calls',
        subscribe: 'type = "screen"',
        partnerAction: 'trackGoal',
        mapping: (0, actions_core_1.defaultValues)({
            ...trackGoal_1.default.fields,
            name: patch(trackGoal_1.default.fields.name, { default: { '@template': 'Screen: {{ name }}' } })
        }),
        type: 'automatic'
    },
    {
        name: 'Exposures (Verbatim)',
        subscribe: 'type = "track" and event = "Experiment Viewed"',
        partnerAction: 'trackExposure',
        mapping: (0, actions_core_1.defaultValues)(trackExposure_1.default.fields),
        type: 'automatic'
    }
];
const destination = {
    name: 'ABsmartly (Actions)',
    slug: 'actions-absmartly',
    mode: 'cloud',
    description: 'ABsmartly is an online experimentation service. Send events to ABsmartly to track experiments and goals.',
    authentication: {
        scheme: 'custom',
        fields: {
            collectorEndpoint: {
                label: 'Collector Endpoint',
                description: "ABsmartly Collector endpoint, for example: https://you-subdomain.absmartly.io/v1 - Contact ABsmartly Support if you don't know your Collector Endpoint.",
                format: 'uri',
                type: 'string',
                required: true
            },
            apiKey: {
                label: 'API Key',
                description: 'ABsmartly SDK API Key. Create SDK Api Keys in the Settings > API Keys section of the ABsmartly Web Console',
                type: 'string',
                required: true
            },
            environment: {
                label: 'Environment',
                description: "Environment name. Environment name needs to match what's in the Web Console. Create Environments in the Settings > Environments section of the ABsmartly Web Console",
                type: 'string',
                required: true
            }
        },
        testAuthentication: async (request, { settings }) => {
            return request(`${settings.collectorEndpoint}/context/authed`, {
                method: 'get'
            });
        }
    },
    extendRequest({ settings }) {
        return {
            headers: {
                'X-API-Key': settings.apiKey,
                'X-Environment': settings.environment,
                'Content-Type': 'application/json'
            }
        };
    },
    presets,
    actions: {
        trackGoal: trackGoal_1.default,
        trackExposure: trackExposure_1.default
    }
};
exports.default = destination;
//# sourceMappingURL=index.js.map