"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 identifyUser_1 = __importDefault(require("./identifyUser"));
const trackEvent_1 = __importDefault(require("./trackEvent"));
const identifyUserV2_1 = __importDefault(require("./identifyUserV2"));
const trackEventV2_1 = __importDefault(require("./trackEventV2"));
const request_params_1 = require("./request-params");
const destination = {
    name: 'Fullstory Cloud Mode (Actions)',
    slug: 'actions-fullstory-cloud',
    mode: 'cloud',
    presets: [
        {
            name: 'Track Event',
            subscribe: 'type = "track"',
            partnerAction: 'trackEventV2',
            mapping: (0, actions_core_1.defaultValues)(trackEventV2_1.default.fields),
            type: 'automatic'
        },
        {
            name: 'Identify User',
            subscribe: 'type = "identify"',
            partnerAction: 'identifyUserV2',
            mapping: (0, actions_core_1.defaultValues)(identifyUserV2_1.default.fields),
            type: 'automatic'
        }
    ],
    authentication: {
        scheme: 'custom',
        fields: {
            apiKey: {
                label: 'API Key',
                description: '[FullStory API key](https://help.fullstory.com/hc/en-us/articles/360052021773-Managing-API-Keys)',
                type: 'password',
                required: true
            }
        },
        testAuthentication: (request, { settings }) => {
            const { url, options } = (0, request_params_1.meRequestParams)(settings);
            return request(url, options);
        }
    },
    onDelete: async (request, { settings, payload }) => {
        if (!payload.userId) {
            throw new actions_core_1.PayloadValidationError('User Id is required for user deletion.');
        }
        const { url, options } = (0, request_params_1.deleteUserRequestParams)(settings, payload.userId);
        return request(url, options);
    },
    actions: {
        trackEvent: trackEvent_1.default,
        identifyUser: identifyUser_1.default,
        trackEventV2: trackEventV2_1.default,
        identifyUserV2: identifyUserV2_1.default
    }
};
exports.default = destination;
//# sourceMappingURL=index.js.map