"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.ALGOLIA_INSIGHTS_USER_AGENT = void 0;
const productClickedEvents_1 = require("./productClickedEvents");
const conversionEvents_1 = require("./conversionEvents");
const productViewedEvents_1 = require("./productViewedEvents");
const algolia_insight_api_1 = require("./algolia-insight-api");
const productAddedEvents_1 = require("./productAddedEvents");
const productListFilteredEvents_1 = require("./productListFilteredEvents");
const productListViewedEvents_1 = require("./productListViewedEvents");
exports.ALGOLIA_INSIGHTS_USER_AGENT = 'algolia-segment-action-destination: 0.1';
const destination = {
    name: 'Algolia Insights (Actions)',
    slug: 'actions-algolia-insights',
    mode: 'cloud',
    authentication: {
        scheme: 'custom',
        fields: {
            appId: {
                label: 'appId',
                description: 'Your Algolia Application ID.',
                type: 'string',
                required: true
            },
            apiKey: {
                label: 'apiKey',
                description: 'An API key which has write permissions to the Algolia Insights API',
                type: 'password',
                required: true
            }
        },
        testAuthentication: async (request, { settings }) => {
            const response = await request((0, algolia_insight_api_1.algoliaApiPermissionsUrl)(settings));
            if (response.data.acl.indexOf('search') === -1) {
                return Promise.reject('Invalid acl permissions.');
            }
            return response;
        }
    },
    extendRequest: ({ settings }) => {
        return {
            headers: {
                'X-Algolia-Application-Id': settings.appId,
                'X-Algolia-API-Key': settings.apiKey,
                'X-Algolia-Agent': exports.ALGOLIA_INSIGHTS_USER_AGENT
            }
        };
    },
    presets: [
        {
            name: 'Algolia Plugin',
            subscribe: 'type = "track" or type = "identify" or type = "group" or type = "page" or type = "alias"',
            partnerAction: 'algoliaPlugin',
            mapping: {},
            type: 'automatic'
        },
        productClickedEvents_1.productClickPresets,
        conversionEvents_1.purchasePreset,
        productAddedEvents_1.addToCartPreset,
        productViewedEvents_1.productViewedPresets,
        productListFilteredEvents_1.productListFilteredPresets,
        productListViewedEvents_1.productListViewedPresets
    ],
    actions: {
        productClickedEvents: productClickedEvents_1.productClickedEvents,
        conversionEvents: conversionEvents_1.conversionEvents,
        productViewedEvents: productViewedEvents_1.productViewedEvents,
        productAddedEvents: productAddedEvents_1.productAddedEvents,
        productListFilteredEvents: productListFilteredEvents_1.productListFilteredEvents,
        productListViewedEvents: productListViewedEvents_1.productListViewedEvents
    }
};
exports.default = destination;
//# sourceMappingURL=index.js.map