"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 sendEvent_1 = __importDefault(require("./sendEvent"));
const destination = {
    name: 'Microsoft Bing CAPI (Actions)',
    slug: 'actions-ms-bing-capi',
    mode: 'cloud',
    authentication: {
        scheme: 'basic',
        fields: {
            UetTag: {
                label: 'Bing UetTag',
                description: 'Your Bing UetTag.',
                type: 'string',
                required: true
            },
            ApiToken: {
                label: 'Bing ApiToken',
                description: 'Your Bing API Token. API token generation is not generally available. To obtain one, you’ll need to contact Microsoft Support, or alternatively, you can [fill out this form](https://forms.office.com/Pages/ResponsePage.aspx?id=v4j5cvGGr0GRqy180BHbRwMZAe0PcMxHmZ0AjDaNRmxUM0o5UURRVktCRkxHNEFLTVNYQjI3NDNBUS4u) to request access.',
                type: 'password',
                required: true
            },
            adStorageConsent: {
                label: 'Ad Storage Consent',
                description: 'Ad Storage Consent for GDPR compliance',
                type: 'string',
                choices: [
                    { label: 'Granted', value: 'G' },
                    { label: 'Denied', value: 'D' }
                ],
                default: 'G',
                required: false
            }
        },
        testAuthentication: (_, { settings }) => {
            if (settings.UetTag.length && settings.ApiToken.length) {
                return true;
            }
            else {
                throw new Error('Invalid UetTag or ApiToken');
            }
        }
    },
    extendRequest: ({ settings }) => {
        return {
            headers: {
                Authorization: `Bearer ${settings.ApiToken}`,
                'Content-Type': 'application/json'
            }
        };
    },
    presets: [
        {
            name: 'Microsoft Bing CAPI msclkid Plugin',
            subscribe: 'type = "track" or type = "identify" or type = "group" or type = "page" or type = "alias"',
            partnerAction: 'msclkidPlugin',
            mapping: {},
            type: 'automatic'
        },
        {
            name: 'Send Purchase Event',
            subscribe: 'type = "track" and event = "Order Completed"',
            partnerAction: 'sendEvent',
            mapping: (0, actions_core_1.defaultValues)({
                ...sendEvent_1.default.fields,
                customData: {
                    ...sendEvent_1.default.fields.customData,
                    eventType: 'purchase'
                }
            }),
            type: 'automatic'
        },
        {
            name: 'Send Cart Event',
            subscribe: 'type = "track" and event = "Add to Cart"',
            partnerAction: 'sendEvent',
            mapping: (0, actions_core_1.defaultValues)({
                ...sendEvent_1.default.fields,
                customData: {
                    ...sendEvent_1.default.fields.customData,
                    eventType: 'cart'
                }
            }),
            type: 'automatic'
        },
        {
            name: 'Send Search Results',
            subscribe: 'type = "track" and event = "Products Searched"',
            partnerAction: 'sendEvent',
            mapping: (0, actions_core_1.defaultValues)({
                ...sendEvent_1.default.fields,
                customData: {
                    ...sendEvent_1.default.fields.customData,
                    eventType: 'searchresults'
                }
            }),
            type: 'automatic'
        },
        {
            name: 'Send Custom Event',
            subscribe: 'type = "track" and event != "Order Completed" and event != "Add to Cart" and event != "Products Searched"',
            partnerAction: 'sendEvent',
            mapping: (0, actions_core_1.defaultValues)(sendEvent_1.default.fields),
            type: 'automatic'
        },
        {
            name: 'Send Pageload',
            subscribe: 'type = "page"',
            partnerAction: 'sendEvent',
            mapping: (0, actions_core_1.defaultValues)({
                ...sendEvent_1.default.fields,
                data: {
                    ...sendEvent_1.default.fields.data,
                    eventType: 'pageLoad'
                }
            }),
            type: 'automatic'
        }
    ],
    actions: {
        sendEvent: sendEvent_1.default
    }
};
exports.default = destination;
//# sourceMappingURL=index.js.map