"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 updateUser_1 = __importDefault(require("./updateUser"));
const trackEvent_1 = __importDefault(require("./trackEvent"));
const updateCart_1 = __importDefault(require("./updateCart"));
const trackPurchase_1 = __importDefault(require("./trackPurchase"));
const utils_1 = require("./utils");
const destination = {
    name: 'Iterable (Actions)',
    slug: 'actions-iterable',
    mode: 'cloud',
    authentication: {
        scheme: 'custom',
        fields: {
            apiKey: {
                type: 'password',
                label: 'API Key',
                description: "To obtain the API Key, go to the Iterable app and naviate to Integrations > API Keys. Create a new API Key with the 'Server-Side' type.",
                required: true
            },
            dataCenterLocation: {
                label: 'Data Center Location',
                description: 'The location where your Iterable data is hosted.',
                type: 'string',
                format: 'text',
                choices: [
                    {
                        label: 'United States',
                        value: 'united_states'
                    },
                    {
                        label: 'Europe',
                        value: 'europe'
                    }
                ],
                default: 'united_states'
            }
        },
        testAuthentication: (request, { settings }) => {
            const endpoint = (0, utils_1.getRegionalEndpoint)('getWebhooks', settings.dataCenterLocation);
            return request(endpoint, {
                method: 'get',
                headers: { 'Api-Key': settings.apiKey }
            });
        }
    },
    extendRequest({ settings }) {
        return {
            headers: { 'Api-Key': settings.apiKey }
        };
    },
    actions: {
        updateUser: updateUser_1.default,
        trackEvent: trackEvent_1.default,
        updateCart: updateCart_1.default,
        trackPurchase: trackPurchase_1.default
    },
    presets: [
        {
            name: 'Track Calls',
            subscribe: 'type = "track" and event != "Order Completed" and event != "Cart Updated"',
            partnerAction: 'trackEvent',
            mapping: (0, actions_core_1.defaultValues)(trackEvent_1.default.fields),
            type: 'automatic'
        },
        {
            name: 'Identify Calls',
            subscribe: 'type = "identify"',
            partnerAction: 'updateUser',
            mapping: (0, actions_core_1.defaultValues)(updateUser_1.default.fields),
            type: 'automatic'
        },
        {
            name: 'Update Cart Calls',
            subscribe: 'type = "track" and event = "Cart Updated"',
            partnerAction: 'updateCart',
            mapping: (0, actions_core_1.defaultValues)(updateCart_1.default.fields),
            type: 'automatic'
        },
        {
            name: 'Order Completed Calls',
            subscribe: 'type = "track" and event = "Order Completed"',
            partnerAction: 'trackPurchase',
            mapping: (0, actions_core_1.defaultValues)(trackPurchase_1.default.fields),
            type: 'automatic'
        },
        {
            name: 'Associated Entity Added',
            partnerAction: 'trackEvent',
            mapping: {
                ...(0, actions_core_1.defaultValues)(trackEvent_1.default.fields)
            },
            type: 'specificEvent',
            eventSlug: 'warehouse_entity_added_track'
        },
        {
            name: 'Associated Entity Removed',
            partnerAction: 'trackEvent',
            mapping: {
                ...(0, actions_core_1.defaultValues)(trackEvent_1.default.fields),
                dataFields: {
                    '@path': '$.properties'
                }
            },
            type: 'specificEvent',
            eventSlug: 'warehouse_entity_removed_track'
        },
        {
            name: 'Entities Audience Entered',
            partnerAction: 'trackEvent',
            mapping: {
                ...(0, actions_core_1.defaultValues)(trackEvent_1.default.fields),
                dataFields: {
                    '@path': '$.properties'
                }
            },
            type: 'specificEvent',
            eventSlug: 'warehouse_audience_entered_track'
        },
        {
            name: 'Entities Exited',
            partnerAction: 'trackEvent',
            mapping: {
                ...(0, actions_core_1.defaultValues)(trackEvent_1.default.fields),
                dataFields: {
                    '@path': '$.properties'
                }
            },
            type: 'specificEvent',
            eventSlug: 'warehouse_audience_exited_track'
        },
        {
            name: 'Entities Audience Membership Changed',
            partnerAction: 'updateUser',
            mapping: {
                ...(0, actions_core_1.defaultValues)(updateUser_1.default.fields),
                dataFields: {
                    '@path': '$.traits'
                }
            },
            type: 'specificEvent',
            eventSlug: 'warehouse_audience_membership_changed_identify'
        },
        {
            name: 'Journeys Step Transition Track',
            partnerAction: 'trackEvent',
            mapping: {
                ...(0, actions_core_1.defaultValues)(trackEvent_1.default.fields),
                dataFields: {
                    '@path': '$.properties'
                }
            },
            type: 'specificEvent',
            eventSlug: 'journeys_step_entered_track'
        },
        {
            name: 'Journeys Step Entered',
            partnerAction: 'updateUser',
            mapping: {
                ...(0, actions_core_1.defaultValues)(updateUser_1.default.fields),
                dataFields: {
                    '@path': '$.traits'
                }
            },
            type: 'specificEvent',
            eventSlug: 'journeys_step_entered_track'
        }
    ]
};
exports.default = destination;
//# sourceMappingURL=index.js.map