import { browserDestination } from '../../runtime/shim';
import { defaultValues } from '@segment/actions-core';
import identifyUser from './identifyUser';
import enrichUser from './enrichUser';
export const destination = {
    name: 'Upollo Web (Actions)',
    slug: 'actions-upollo',
    mode: 'device',
    presets: [
        {
            name: 'Identify',
            subscribe: 'type = "identify"',
            partnerAction: 'identifyUser',
            mapping: defaultValues(identifyUser.fields)
        },
        {
            name: 'Enrich',
            subscribe: 'type = "identify"',
            partnerAction: 'enrichUser',
            mapping: defaultValues(enrichUser.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,
        enrichUser
    }
};
export default browserDestination(destination);
//# sourceMappingURL=index.js.map