"use strict";
var __importDefault = (this && this.__importDefault) || function (mod) {
    return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.headerSecret = exports.authURL = exports.baseURL = void 0;
const actions_core_1 = require("@segment/actions-core");
const track_1 = __importDefault(require("./track"));
exports.baseURL = process?.env?.ACTIONS_APOLLOIO_BASE_URL_SECRET ?? 'https://apollo.io/';
exports.authURL = process?.env?.ACTIONS_APOLLOIO_AUTH_URL_SECRET ?? 'https://apollo.io/';
exports.headerSecret = `${process.env.ACTIONS_APOLLOIO_HEADER_SECRET}`;
const destination = {
    name: 'Apollo.io',
    slug: 'actions-apolloio',
    mode: 'cloud',
    description: 'Send Segment analytics events to Apollo.io',
    authentication: {
        scheme: 'custom',
        fields: {
            apiToken: {
                label: 'API Token',
                description: 'API Token for authorization.',
                type: 'password',
                required: true
            }
        },
        testAuthentication: (request, { settings }) => {
            return request(exports.authURL + settings.apiToken).then(async (response) => {
                const { is_logged_in } = await response.json();
                if (is_logged_in === false) {
                    throw new actions_core_1.IntegrationError(`Invalid API Token`, 'INVALID_API_TOKEN', 401);
                }
            });
        }
    },
    extendRequest({ settings }) {
        return {
            headers: {
                api_key: settings.apiToken,
                secret: exports.headerSecret
            }
        };
    },
    actions: {
        track: track_1.default
    },
    presets: [
        {
            name: 'Track',
            subscribe: 'type = "track"',
            partnerAction: 'track',
            mapping: (0, actions_core_1.defaultValues)(track_1.default.fields),
            type: 'automatic'
        }
    ]
};
exports.default = destination;
//# sourceMappingURL=index.js.map