"use strict";
var __importDefault = (this && this.__importDefault) || function (mod) {
    return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
const btoa_lite_1 = __importDefault(require("btoa-lite"));
const group_1 = __importDefault(require("./group"));
const identify_1 = __importDefault(require("./identify"));
const page_1 = __importDefault(require("./page"));
const track_1 = __importDefault(require("./track"));
const actions_core_1 = require("@segment/actions-core");
const destination = {
    name: 'Ripe Cloud Mode (Actions)',
    slug: 'actions-ripe-cloud',
    mode: 'cloud',
    description: 'Send server-side events to the Ripe REST API.',
    authentication: {
        scheme: 'custom',
        fields: {
            apiKey: {
                label: 'API Key',
                description: 'The Ripe API key found in the Ripe App',
                type: 'password',
                required: true
            },
            endpoint: {
                label: 'API Endpoint',
                description: `The Ripe API endpoint (do not change this unless you know what you're doing)`,
                type: 'string',
                format: 'uri',
                default: 'https://api.getripe.com/event'
            }
        },
        testAuthentication: async (request, { settings }) => {
            const res = await request(`${settings.endpoint}/auth/sdk`, {
                method: 'get'
            });
            return res.status == 200;
        }
    },
    extendRequest({ settings }) {
        return {
            headers: {
                Authorization: `Basic ${(0, btoa_lite_1.default)(settings.apiKey)}`,
                'Content-Type': 'application/json'
            }
        };
    },
    actions: {
        group: group_1.default,
        identify: identify_1.default,
        page: page_1.default,
        track: track_1.default
    },
    presets: [
        {
            name: 'Group user',
            subscribe: 'type = "group"',
            partnerAction: 'group',
            mapping: (0, actions_core_1.defaultValues)(group_1.default.fields),
            type: 'automatic'
        },
        {
            name: 'Identify user',
            subscribe: 'type = "identify"',
            partnerAction: 'identify',
            mapping: (0, actions_core_1.defaultValues)(identify_1.default.fields),
            type: 'automatic'
        },
        {
            name: 'Page view',
            subscribe: 'type = "page"',
            partnerAction: 'page',
            mapping: (0, actions_core_1.defaultValues)(page_1.default.fields),
            type: 'automatic'
        },
        {
            name: 'Track event',
            subscribe: 'type = "track"',
            partnerAction: 'track',
            mapping: (0, actions_core_1.defaultValues)(track_1.default.fields),
            type: 'automatic'
        }
    ]
};
exports.default = destination;
//# sourceMappingURL=index.js.map