"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 identifyContact_1 = __importDefault(require("./identifyContact"));
const trackEvent_1 = __importDefault(require("./trackEvent"));
const destination = {
    name: 'Gleap (Action)',
    slug: 'gleap-cloud-actions',
    description: 'Send Segment analytics events and user profile data to Gleap',
    mode: 'cloud',
    authentication: {
        scheme: 'custom',
        fields: {
            apiToken: {
                type: 'password',
                label: 'Secret API token',
                description: 'Found in `Project settings` -> `Secret API token`.',
                required: true
            }
        },
        testAuthentication: async (request) => {
            return await request('https://api.gleap.io/admin/auth');
        }
    },
    extendRequest({ settings }) {
        return {
            headers: {
                'Api-Token': settings.apiToken
            }
        };
    },
    onDelete: async (request, { payload }) => {
        const userId = payload.userId;
        if (userId) {
            return request(`https://api.gleap.io/admin/contacts/${userId}`, {
                method: 'DELETE'
            });
        }
        else {
            throw new actions_core_1.IntegrationError('No unique contact found', 'Contact not found', 404);
        }
    },
    actions: {
        identifyContact: identifyContact_1.default,
        trackEvent: trackEvent_1.default
    }
};
exports.default = destination;
//# sourceMappingURL=index.js.map