"use strict";
var __importDefault = (this && this.__importDefault) || function (mod) {
    return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
const sendgrid_properties_1 = require("./sendgrid-properties");
const updateUserProfile_1 = __importDefault(require("./updateUserProfile"));
const sendEmail_1 = __importDefault(require("./sendEmail"));
const destination = {
    name: 'SendGrid',
    slug: 'actions-sendgrid',
    mode: 'cloud',
    description: 'Trigger emails from SendGrid and sync Contacts to SendGrid Markeitng Campaigns.',
    authentication: {
        scheme: 'custom',
        fields: {
            sendGridApiKey: {
                label: 'API Key',
                type: 'password',
                description: 'The Api key for your SendGrid account.',
                required: true
            },
            endpoint: {
                label: 'Regional Processing Endpoint',
                type: 'string',
                description: 'The regional processing endpoint for your SendGrid account. [See more details](https://www.twilio.com/en-us/blog/send-emails-in-eu?_gl=1*7hyri9*_gcl_au*MTg0MTQwMjAzNi4xNzQzMDAyNzc4*_ga*MTk4OTI2MDk1LjE3NDMwMDI3Nzg.*_ga_8W5LR442LD*MTc0MzY3NTc2NC41LjAuMTc0MzY3NTc2NC4wLjAuMA..)',
                required: false,
                format: 'uri',
                default: sendgrid_properties_1.GLOBAL_ENDPOINT,
                choices: [
                    { label: `Global (${sendgrid_properties_1.GLOBAL_ENDPOINT})`, value: sendgrid_properties_1.GLOBAL_ENDPOINT },
                    { label: `EU (${sendgrid_properties_1.EU_ENDPOINT})`, value: sendgrid_properties_1.EU_ENDPOINT }
                ]
            }
        },
        testAuthentication: (request, { settings }) => {
            const endpoint = settings?.endpoint || sendgrid_properties_1.GLOBAL_ENDPOINT;
            return request(`${endpoint}/v3/user/account`);
        }
    },
    extendRequest({ settings }) {
        return {
            headers: {
                Authorization: `Bearer ${settings.sendGridApiKey}`,
                Accept: 'application/json'
            }
        };
    },
    actions: {
        updateUserProfile: updateUserProfile_1.default,
        sendEmail: sendEmail_1.default
    }
};
exports.default = destination;
//# sourceMappingURL=index.js.map