"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.destination = void 0;
const tslib_1 = require("tslib");
const shim_1 = require("../../runtime/shim");
const actions_core_1 = require("@segment/actions-core");
const identifyUser_1 = tslib_1.__importDefault(require("./identifyUser"));
const enrichUser_1 = tslib_1.__importDefault(require("./enrichUser"));
exports.destination = {
    name: 'Upollo Web (Actions)',
    slug: 'actions-upollo',
    mode: 'device',
    presets: [
        {
            name: 'Identify',
            subscribe: 'type = "identify"',
            partnerAction: 'identifyUser',
            mapping: actions_core_1.defaultValues(identifyUser_1.default.fields)
        },
        {
            name: 'Enrich',
            subscribe: 'type = "identify"',
            partnerAction: 'enrichUser',
            mapping: actions_core_1.defaultValues(enrichUser_1.default.fields)
        }
    ],
    settings: {
        apiKey: {
            description: 'The api key of your Upollo project. Get it from the Upollo [dashboard](https://upollo.ai/dashboard)',
            label: 'API Key',
            type: 'string',
            required: true
        }
    },
    initialize: async ({ settings }, deps) => {
        try {
            await deps.loadScript('https://cdn.upollo.ai/web/0.2/bundle.min.js');
            await deps.resolveWhen(() => Object.prototype.hasOwnProperty.call(window, 'upollo'), 500);
            return new window.upollo.UpolloClient(settings.apiKey);
        }
        catch (err) {
            throw new Error('Could not load the Upollo client ' + err);
        }
    },
    actions: {
        identifyUser: identifyUser_1.default,
        enrichUser: enrichUser_1.default
    }
};
exports.default = shim_1.browserDestination(exports.destination);
//# sourceMappingURL=index.js.map