"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 sendUserProfiles_1 = __importDefault(require("./sendUserProfiles"));
const sendAccountProfiles_1 = __importDefault(require("./sendAccountProfiles"));
const constants_1 = require("./constants");
const sendEvents_1 = __importDefault(require("./sendEvents"));
const destination = {
    name: 'Toplyne Cloud Mode (Actions)',
    slug: 'actions-toplyne-cloud',
    mode: 'cloud',
    authentication: {
        scheme: 'custom',
        fields: {
            apiKey: {
                type: 'password',
                label: 'API Key',
                description: 'Your Toplyne API Key',
                required: true
            }
        },
        testAuthentication: async (request, { settings }) => {
            return await request(`${constants_1.baseUrl}/auth/me`, {
                method: 'GET',
                headers: {
                    Authorization: `Bearer ${settings.apiKey}`
                }
            });
        }
    },
    presets: [
        {
            name: 'Send User Profiles',
            subscribe: 'type = "identify"',
            partnerAction: 'sendUserProfiles',
            mapping: (0, actions_core_1.defaultValues)(sendUserProfiles_1.default.fields),
            type: 'automatic'
        },
        {
            name: 'Send Account Profiles',
            subscribe: 'type = "group"',
            partnerAction: 'sendAccountProfiles',
            mapping: (0, actions_core_1.defaultValues)(sendAccountProfiles_1.default.fields),
            type: 'automatic'
        },
        {
            name: 'Send Events',
            subscribe: 'type = "track"',
            partnerAction: 'sendEvents',
            mapping: (0, actions_core_1.defaultValues)(sendEvents_1.default.fields),
            type: 'automatic'
        }
    ],
    extendRequest: ({ settings }) => {
        return {
            headers: {
                Authorization: `Bearer ${settings.apiKey}`
            },
            method: 'POST'
        };
    },
    actions: {
        sendUserProfiles: sendUserProfiles_1.default,
        sendAccountProfiles: sendAccountProfiles_1.default,
        sendEvents: sendEvents_1.default
    }
};
exports.default = destination;
//# sourceMappingURL=index.js.map