"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 ecommerce_1 = __importDefault(require("./ecommerce"));
const ecommerceSingleProduct_1 = __importDefault(require("./ecommerceSingleProduct"));
const createAlias_1 = __importDefault(require("./createAlias"));
const createAlias2_1 = __importDefault(require("./createAlias2"));
const identifyUser_1 = __importDefault(require("./identifyUser"));
const identifyUser2_1 = __importDefault(require("./identifyUser2"));
const trackEvent_1 = __importDefault(require("./trackEvent"));
const trackPurchase_1 = __importDefault(require("./trackPurchase"));
const updateUserProfile_1 = __importDefault(require("./updateUserProfile"));
const trackEvent2_1 = __importDefault(require("./trackEvent2"));
const trackPurchase2_1 = __importDefault(require("./trackPurchase2"));
const updateUserProfile2_1 = __importDefault(require("./updateUserProfile2"));
const triggerCampaign_1 = __importDefault(require("./triggerCampaign"));
const triggerCanvas_1 = __importDefault(require("./triggerCanvas"));
const constants_1 = require("./ecommerce/constants");
const upsertCatalogItem_1 = __importDefault(require("./upsertCatalogItem"));
const destination = {
    name: 'Braze Cloud Mode (Actions)',
    slug: 'actions-braze-cloud',
    mode: 'cloud',
    description: 'Send events server-side to the Braze REST API.',
    authentication: {
        scheme: 'custom',
        fields: {
            api_key: {
                label: 'API Key',
                description: 'Created under Developer Console in the Braze Dashboard.',
                type: 'password',
                required: true
            },
            app_id: {
                label: 'App ID',
                description: 'The app identifier used to reference specific Apps in requests made to the Braze API. Created under Developer Console in the Braze Dashboard.',
                type: 'string'
            },
            endpoint: {
                label: 'REST Endpoint',
                description: 'Your Braze REST endpoint. [See more details](https://www.braze.com/docs/api/basics/#endpoints)',
                type: 'string',
                format: 'uri',
                choices: [
                    { label: 'US-01	(https://dashboard-01.braze.com)', value: 'https://rest.iad-01.braze.com' },
                    { label: 'US-02	(https://dashboard-02.braze.com)', value: 'https://rest.iad-02.braze.com' },
                    { label: 'US-03	(https://dashboard-03.braze.com)', value: 'https://rest.iad-03.braze.com' },
                    { label: 'US-04	(https://dashboard-04.braze.com)', value: 'https://rest.iad-04.braze.com' },
                    { label: 'US-05	(https://dashboard-05.braze.com)', value: 'https://rest.iad-05.braze.com' },
                    { label: 'US-06	(https://dashboard-06.braze.com)', value: 'https://rest.iad-06.braze.com' },
                    { label: 'US-07	(https://dashboard-07.braze.com)', value: 'https://rest.iad-07.braze.com' },
                    { label: 'US-08	(https://dashboard-08.braze.com)', value: 'https://rest.iad-08.braze.com' },
                    { label: 'US-09	(https://dashboard-09.braze.com)', value: 'https://rest.us-09.braze.com' },
                    { label: 'US-10	(https://dashboard-10.braze.com)', value: 'https://rest.us-10.braze.com' },
                    { label: 'EU-01	(https://dashboard-01.braze.eu)', value: 'https://rest.fra-01.braze.eu' },
                    { label: 'EU-02	(https://dashboard-02.braze.eu)', value: 'https://rest.fra-02.braze.eu' },
                    { label: 'AU-01 (https://dashboard.au-01.braze.com)', value: 'https://rest.au-01.braze.com' },
                    { label: 'ID-01 (https://dashboard.id-01.braze.com)', value: 'https://rest.id-01.braze.com' },
                    { label: 'JP-01 (https://dashboard.jp-01.braze.com)', value: 'https://rest.jp-01.braze.com' }
                ],
                default: 'https://rest.iad-01.braze.com',
                required: true
            }
        }
    },
    onDelete: async (request, { payload, settings }) => {
        return request(`${settings.endpoint}/users/delete`, {
            method: 'post',
            json: {
                external_ids: [payload.userId]
            }
        });
    },
    extendRequest({ settings }) {
        return {
            headers: {
                Authorization: `Bearer ${settings.api_key}`
            },
            timeout: Math.max(30000, actions_core_1.DEFAULT_REQUEST_TIMEOUT)
        };
    },
    actions: {
        updateUserProfile: updateUserProfile_1.default,
        trackEvent: trackEvent_1.default,
        trackPurchase: trackPurchase_1.default,
        createAlias: createAlias_1.default,
        identifyUser: identifyUser_1.default,
        identifyUser2: identifyUser2_1.default,
        trackEvent2: trackEvent2_1.default,
        trackPurchase2: trackPurchase2_1.default,
        updateUserProfile2: updateUserProfile2_1.default,
        createAlias2: createAlias2_1.default,
        upsertCatalogItem: upsertCatalogItem_1.default,
        triggerCampaign: triggerCampaign_1.default,
        triggerCanvas: triggerCanvas_1.default,
        ecommerce: ecommerce_1.default,
        ecommerceSingleProduct: ecommerceSingleProduct_1.default
    },
    presets: [
        {
            name: 'Track Calls',
            subscribe: 'type = "track" and event != "Order Completed" and event != "Checkout Started" and event != "Order Refunded" and event != "Order Cancelled" and event != "Product Viewed"',
            partnerAction: 'trackEvent',
            mapping: (0, actions_core_1.defaultValues)(trackEvent_1.default.fields),
            type: 'automatic'
        },
        {
            name: 'Order Placed (beta)',
            subscribe: 'event = "Order Completed"',
            partnerAction: 'ecommerce',
            mapping: {
                ...(0, actions_core_1.defaultValues)(ecommerce_1.default.fields),
                name: constants_1.EVENT_NAMES.ORDER_PLACED,
                metadata: {
                    order_status_url: { '@path': '$.properties.order_status_url' }
                }
            },
            type: 'automatic'
        },
        {
            name: 'Checkout Started (beta)',
            subscribe: 'event = "Checkout Started"',
            partnerAction: 'ecommerce',
            mapping: {
                ...(0, actions_core_1.defaultValues)(ecommerce_1.default.fields),
                name: constants_1.EVENT_NAMES.CHECKOUT_STARTED,
                metadata: {
                    checkout_url: { '@path': '$.properties.checkout_url' }
                }
            },
            type: 'automatic'
        },
        {
            name: 'Order Refunded (beta)',
            subscribe: 'event = "Order Refunded"',
            partnerAction: 'ecommerce',
            mapping: {
                ...(0, actions_core_1.defaultValues)(ecommerce_1.default.fields),
                name: constants_1.EVENT_NAMES.ORDER_REFUNDED,
                metadata: {
                    order_status_url: { '@path': '$.properties.order_status_url' }
                }
            },
            type: 'automatic'
        },
        {
            name: 'Order Cancelled (beta)',
            subscribe: 'event = "Order Cancelled"',
            partnerAction: 'ecommerce',
            mapping: {
                ...(0, actions_core_1.defaultValues)(ecommerce_1.default.fields),
                name: constants_1.EVENT_NAMES.ORDER_CANCELLED,
                metadata: {
                    order_status_url: { '@path': '$.properties.order_status_url' }
                }
            },
            type: 'automatic'
        },
        {
            name: 'Product Viewed (beta)',
            subscribe: 'event = "Product Viewed"',
            partnerAction: 'ecommerceSingleProduct',
            mapping: {
                ...(0, actions_core_1.defaultValues)(ecommerceSingleProduct_1.default.fields),
                name: constants_1.EVENT_NAMES.PRODUCT_VIEWED
            },
            type: 'automatic'
        },
        {
            name: 'Identify Calls',
            subscribe: 'type = "identify"',
            partnerAction: 'updateUserProfile',
            mapping: (0, actions_core_1.defaultValues)(updateUserProfile_1.default.fields),
            type: 'automatic'
        },
        {
            name: 'Associated Entity Added',
            partnerAction: 'trackEvent',
            mapping: {
                ...(0, actions_core_1.defaultValues)(trackEvent_1.default.fields),
                properties: {
                    '@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),
                properties: {
                    '@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),
                properties: {
                    '@path': '$.properties'
                }
            },
            type: 'specificEvent',
            eventSlug: 'warehouse_audience_entered_track'
        },
        {
            name: 'Entities Exited',
            partnerAction: 'trackEvent',
            mapping: {
                ...(0, actions_core_1.defaultValues)(trackEvent_1.default.fields),
                properties: {
                    '@path': '$.properties'
                }
            },
            type: 'specificEvent',
            eventSlug: 'warehouse_audience_exited_track'
        },
        {
            name: 'Entities Audience Membership Changed',
            partnerAction: 'updateUserProfile',
            mapping: {
                ...(0, actions_core_1.defaultValues)(updateUserProfile_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),
                properties: {
                    '@path': '$.properties'
                }
            },
            type: 'specificEvent',
            eventSlug: 'journeys_step_entered_track'
        }
    ]
};
exports.default = destination;
//# sourceMappingURL=index.js.map