"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 createUpdateDevice_1 = __importDefault(require("./createUpdateDevice"));
const createUpdateObject_1 = __importDefault(require("./createUpdateObject"));
const createUpdatePerson_1 = __importDefault(require("./createUpdatePerson"));
const deleteDevice_1 = __importDefault(require("./deleteDevice"));
const deleteRelationship_1 = __importDefault(require("./deleteRelationship"));
const deleteObject_1 = __importDefault(require("./deleteObject"));
const deletePerson_1 = __importDefault(require("./deletePerson"));
const mergePeople_1 = __importDefault(require("./mergePeople"));
const reportDeliveryEvent_1 = __importDefault(require("./reportDeliveryEvent"));
const reportContentEvent_1 = __importDefault(require("./reportContentEvent"));
const versioning_info_1 = require("./versioning-info");
const suppressPerson_1 = __importDefault(require("./suppressPerson"));
const unsuppressPerson_1 = __importDefault(require("./unsuppressPerson"));
const trackEvent_1 = __importDefault(require("./trackEvent"));
const trackPageView_1 = __importDefault(require("./trackPageView"));
const trackScreenView_1 = __importDefault(require("./trackScreenView"));
const utils_1 = require("./utils");
const destination = {
    name: 'Actions Customerio',
    slug: 'actions-customerio',
    mode: 'cloud',
    authentication: {
        scheme: 'basic',
        fields: {
            siteId: {
                description: 'Customer.io site ID. This can be found on your [API Credentials page](https://fly.customer.io/settings/api_credentials).',
                label: 'Site ID',
                type: 'password',
                required: true
            },
            apiKey: {
                description: 'Customer.io API key. This can be found on your [API Credentials page](https://fly.customer.io/settings/api_credentials).',
                label: 'API Key',
                type: 'password',
                required: true
            },
            accountRegion: {
                description: 'Learn about [Account Regions](https://customer.io/docs/data-centers/).',
                label: 'Account Region',
                type: 'string',
                choices: Object.values(utils_1.AccountRegion).map((dc) => ({ label: dc, value: dc })),
                default: utils_1.AccountRegion.US
            }
        },
        testAuthentication: (request) => {
            return request('https://track.customer.io/auth');
        }
    },
    extendRequest({ settings }) {
        return {
            username: settings.siteId,
            password: settings.apiKey
        };
    },
    actions: {
        createUpdateDevice: createUpdateDevice_1.default,
        deleteDevice: deleteDevice_1.default,
        deleteRelationship: deleteRelationship_1.default,
        deletePerson: deletePerson_1.default,
        deleteObject: deleteObject_1.default,
        createUpdatePerson: createUpdatePerson_1.default,
        trackEvent: trackEvent_1.default,
        trackPageView: trackPageView_1.default,
        trackScreenView: trackScreenView_1.default,
        createUpdateObject: createUpdateObject_1.default,
        mergePeople: mergePeople_1.default,
        suppressPerson: suppressPerson_1.default,
        unsuppressPerson: unsuppressPerson_1.default,
        reportDeliveryEvent: reportDeliveryEvent_1.default,
        reportContentEvent: reportContentEvent_1.default
    },
    presets: [
        {
            name: 'Create or Update Person',
            subscribe: 'type = "identify"',
            partnerAction: 'createUpdatePerson',
            mapping: (0, actions_core_1.defaultValues)(createUpdatePerson_1.default.fields),
            type: 'automatic'
        },
        {
            name: 'Create or Update Device',
            subscribe: `
        event = "Application Installed"
        or event = "Application Opened"
        or event = "Device Created or Updated"
      `,
            partnerAction: 'createUpdateDevice',
            mapping: (0, actions_core_1.defaultValues)(createUpdateDevice_1.default.fields),
            type: 'automatic'
        },
        {
            name: 'Delete Device',
            subscribe: 'event = "Application Uninstalled" or event = "Device Deleted"',
            partnerAction: 'deleteDevice',
            mapping: (0, actions_core_1.defaultValues)(deleteDevice_1.default.fields),
            type: 'automatic'
        },
        {
            name: 'Delete Relationship',
            subscribe: 'event = "Relationship Deleted"',
            partnerAction: 'deleteRelationship',
            mapping: (0, actions_core_1.defaultValues)(deleteRelationship_1.default.fields),
            type: 'automatic'
        },
        {
            name: 'Delete Person',
            subscribe: 'event = "User Deleted"',
            partnerAction: 'deletePerson',
            mapping: (0, actions_core_1.defaultValues)(deletePerson_1.default.fields),
            type: 'automatic'
        },
        {
            name: 'Delete Object',
            subscribe: 'event = "Object Deleted"',
            partnerAction: 'deleteObject',
            mapping: (0, actions_core_1.defaultValues)(deleteObject_1.default.fields),
            type: 'automatic'
        },
        {
            name: 'Track Event',
            subscribe: `
        type = "track"
        and event != "Application Installed"
        and event != "Application Opened"
        and event != "Application Uninstalled"
        and event != "Device Created or Updated"
        and event != "Device Deleted"
        and event != "Relationship Deleted"
        and event != "User Deleted"
        and event != "User Suppressed"
        and event != "User Unsuppressed"
        and event != "Object Deleted"
        and event != "Report Delivery Event"
        and event != "Report Content Event"
      `,
            partnerAction: 'trackEvent',
            mapping: (0, actions_core_1.defaultValues)(trackEvent_1.default.fields),
            type: 'automatic'
        },
        {
            name: 'Track Page View',
            subscribe: 'type = "page"',
            partnerAction: 'trackPageView',
            mapping: (0, actions_core_1.defaultValues)(trackPageView_1.default.fields),
            type: 'automatic'
        },
        {
            name: 'Track Screen View',
            subscribe: 'type = "screen"',
            partnerAction: 'trackScreenView',
            mapping: (0, actions_core_1.defaultValues)(trackScreenView_1.default.fields),
            type: 'automatic'
        },
        {
            name: 'Create or Update Object',
            subscribe: 'type = "group"',
            partnerAction: 'createUpdateObject',
            mapping: (0, actions_core_1.defaultValues)(createUpdateObject_1.default.fields),
            type: 'automatic'
        },
        {
            name: 'Merge People',
            subscribe: 'type = "alias"',
            partnerAction: 'mergePeople',
            mapping: (0, actions_core_1.defaultValues)(mergePeople_1.default.fields),
            type: 'automatic'
        },
        {
            name: 'Suppress Person',
            subscribe: 'event = "User Suppressed"',
            partnerAction: 'suppressPerson',
            mapping: (0, actions_core_1.defaultValues)(suppressPerson_1.default.fields),
            type: 'automatic'
        },
        {
            name: 'Unsuppress Person',
            subscribe: 'event = "User Unsuppressed"',
            partnerAction: 'unsuppressPerson',
            mapping: (0, actions_core_1.defaultValues)(unsuppressPerson_1.default.fields),
            type: 'automatic'
        },
        {
            name: 'Report Delivery Event',
            subscribe: 'event = "Report Delivery Event"',
            partnerAction: 'reportDeliveryEvent',
            mapping: (0, actions_core_1.defaultValues)(reportDeliveryEvent_1.default.fields),
            type: 'automatic'
        },
        {
            name: 'Report Content Event',
            subscribe: 'event = "Report Content Event"',
            partnerAction: 'reportContentEvent',
            mapping: (0, actions_core_1.defaultValues)(reportContentEvent_1.default.fields),
            type: 'automatic'
        },
        {
            name: 'Associated Entity Added',
            partnerAction: 'trackEvent',
            mapping: {
                ...(0, actions_core_1.defaultValues)(trackEvent_1.default.fields),
                data: {
                    '@path': '$.properties'
                }
            },
            type: 'specificEvent',
            eventSlug: 'warehouse_entity_added_track'
        },
        {
            name: 'Associated Entity Removed',
            partnerAction: 'trackEvent',
            mapping: {
                ...(0, actions_core_1.defaultValues)(trackEvent_1.default.fields),
                data: {
                    '@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),
                data: {
                    '@path': '$.properties'
                }
            },
            type: 'specificEvent',
            eventSlug: 'warehouse_audience_entered_track'
        },
        {
            name: 'Entities Exited',
            partnerAction: 'trackEvent',
            mapping: {
                ...(0, actions_core_1.defaultValues)(trackEvent_1.default.fields),
                data: {
                    '@path': '$.properties'
                }
            },
            type: 'specificEvent',
            eventSlug: 'warehouse_audience_exited_track'
        },
        {
            name: 'Entities Audience Membership Changed',
            partnerAction: 'createUpdatePerson',
            mapping: {
                ...(0, actions_core_1.defaultValues)(createUpdatePerson_1.default.fields),
                custom_attributes: {
                    '@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),
                data: {
                    '@path': '$.properties'
                }
            },
            type: 'specificEvent',
            eventSlug: 'journeys_step_entered_track'
        }
    ],
    onDelete(request, { settings, payload }) {
        const { userId } = payload;
        const url = `${(0, utils_1.trackApiEndpoint)(settings)}/api/${versioning_info_1.CUSTOMERIO_CUSTOMERS_API_VERSION}/customers/${userId}`;
        return request(url, {
            method: 'DELETE'
        });
    }
};
exports.default = destination;
//# sourceMappingURL=index.js.map