"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 api_1 = require("./constants/api");
const identify_1 = __importDefault(require("./identify"));
const group_1 = __importDefault(require("./group"));
const destination = {
    name: 'Canny (Actions)',
    slug: 'actions-canny',
    mode: 'cloud',
    authentication: {
        scheme: 'custom',
        fields: {
            apiKey: {
                label: 'API Key',
                description: 'You can find your API Key in the Segment Integration page in your admin settings.',
                type: 'password',
                required: true
            }
        },
        testAuthentication(request) {
            return request(`${api_1.BASE_API_URL}/validateAPIKey`, {
                method: 'post'
            });
        }
    },
    extendRequest({ settings }) {
        const auth = Buffer.from(settings.apiKey + ':').toString('base64');
        return {
            headers: {
                Accept: 'application/json',
                Authorization: `Basic ${auth}`,
                'Content-Type': 'application/json'
            }
        };
    },
    presets: [
        {
            name: 'Create or update a Company',
            subscribe: 'type = "group"',
            partnerAction: 'group',
            mapping: (0, actions_core_1.defaultValues)(group_1.default.fields),
            type: 'automatic'
        },
        {
            name: 'Create or update a User',
            subscribe: 'type = "identify"',
            partnerAction: 'identify',
            mapping: (0, actions_core_1.defaultValues)(identify_1.default.fields),
            type: 'automatic'
        }
    ],
    actions: {
        identify: identify_1.default,
        group: group_1.default
    }
};
exports.default = destination;
//# sourceMappingURL=index.js.map