"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 identify_1 = __importDefault(require("./identify"));
const track_1 = __importDefault(require("./track"));
const destination = {
    name: 'Xtremepush (Actions)',
    slug: 'actions-xtremepush',
    mode: 'cloud',
    authentication: {
        scheme: 'custom',
        fields: {
            url: {
                type: 'string',
                format: 'uri',
                label: 'URL',
                description: 'Xtremepush integration URL can be found on the Xtremepush integration overview page',
                required: true
            },
            apiKey: {
                type: 'password',
                label: 'API Key',
                description: 'Auth token for API can be found on the Xtremepush integration overview page',
                required: true
            }
        }
    },
    extendRequest: ({ settings }) => {
        return {
            headers: { Authorization: 'Basic ' + Buffer.from(settings.apiKey + ':').toString('base64') },
            responseType: 'json'
        };
    },
    presets: [
        {
            name: 'Send Analytics Events',
            subscribe: 'type = "track"',
            partnerAction: 'track',
            mapping: (0, actions_core_1.defaultValues)(track_1.default.fields),
            type: 'automatic'
        },
        {
            name: 'Send User Profile Data',
            subscribe: 'type = "identify"',
            partnerAction: 'identify',
            mapping: (0, actions_core_1.defaultValues)(identify_1.default.fields),
            type: 'automatic'
        }
    ],
    actions: {
        identify: identify_1.default,
        track: track_1.default
    },
    onDelete: async (request, { settings, payload }) => {
        const host = settings.url.endsWith('/') ? settings.url.slice(0, -1) : settings.url;
        return request(host + '/api/integration/segment/delete', {
            method: 'post',
            json: payload
        });
    }
};
exports.default = destination;
//# sourceMappingURL=index.js.map