"use strict";
var __importDefault = (this && this.__importDefault) || function (mod) {
    return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
const sendData_1 = __importDefault(require("./sendData"));
const destination = {
    name: 'Yotpo',
    slug: 'yotpo-actions',
    mode: 'cloud',
    description: 'Send data to Yotpo',
    authentication: {
        scheme: 'oauth-managed',
        fields: {
            store_id: {
                label: 'Store ID',
                description: 'The store ID for your Yotpo account',
                type: 'string',
                required: true
            }
        },
        testAuthentication: (request, data) => {
            return request(`https://developers.yotpo.com/v2/${data.settings.store_id}/info`, {
                method: 'get'
            });
        },
        refreshAccessToken: async (request, data) => {
            const promise = await request(`https://developers.yotpo.com/v2/oauth/token`, {
                method: 'post',
                json: {
                    client_id: data.auth.clientId,
                    client_secret: data.auth.clientSecret,
                    grant_type: 'authorization_code'
                }
            });
            return {
                accessToken: promise.data.access_token
            };
        }
    },
    extendRequest({ auth }) {
        return {
            headers: {
                'X-Yotpo-Token': `${auth?.accessToken}`
            }
        };
    },
    actions: {
        sendData: sendData_1.default
    }
};
exports.default = destination;
//# sourceMappingURL=index.js.map