"use strict";
var __importDefault = (this && this.__importDefault) || function (mod) {
    return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
const constants_1 = require("./constants");
const createConstituentAction_1 = __importDefault(require("./createConstituentAction"));
const createGift_1 = __importDefault(require("./createGift"));
const createOrUpdateIndividualConstituent_1 = __importDefault(require("./createOrUpdateIndividualConstituent"));
const destination = {
    name: "Blackbaud Raiser's Edge NXT",
    slug: 'actions-blackbaud-raisers-edge-nxt',
    mode: 'cloud',
    authentication: {
        scheme: 'oauth-managed',
        fields: {
            bbApiSubscriptionKey: {
                label: 'Blackbaud API Subscription Key',
                description: 'The access key found on your Blackbaud "My subscriptions" page.',
                type: 'string',
                required: true
            }
        },
        testAuthentication: (request) => {
            return request(`${constants_1.SKY_API_CONSTITUENT_URL}/emailaddresstypes`);
        },
        refreshAccessToken: async (request, { auth }) => {
            const res = await request(constants_1.SKY_OAUTH2_TOKEN_URL, {
                method: 'POST',
                body: new URLSearchParams({
                    grant_type: 'refresh_token',
                    refresh_token: auth.refreshToken,
                    preserve_refresh_token: 'true',
                    client_id: auth.clientId,
                    client_secret: auth.clientSecret
                })
            });
            return { accessToken: res.data.access_token, refreshToken: res.data.refresh_token };
        }
    },
    extendRequest({ auth, settings }) {
        return {
            headers: {
                authorization: `Bearer ${auth?.accessToken}`,
                'Bb-Api-Subscription-Key': `${settings.bbApiSubscriptionKey}`
            }
        };
    },
    onDelete: async () => {
    },
    actions: {
        createConstituentAction: createConstituentAction_1.default,
        createGift: createGift_1.default,
        createOrUpdateIndividualConstituent: createOrUpdateIndividualConstituent_1.default
    }
};
exports.default = destination;
//# sourceMappingURL=index.js.map