"use strict";
var __importDefault = (this && this.__importDefault) || function (mod) {
    return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
const postSheet_1 = __importDefault(require("./postSheet"));
const postSheet2_1 = __importDefault(require("./postSheet2"));
const actions_core_1 = require("@segment/actions-core");
const destination = {
    name: 'Google Sheets',
    slug: 'actions-google-sheets',
    mode: 'cloud',
    authentication: {
        scheme: 'oauth2',
        fields: {},
        refreshAccessToken: async (request, { auth }) => {
            const res = await request('https://www.googleapis.com/oauth2/v4/token', {
                method: 'POST',
                body: new URLSearchParams({
                    refresh_token: auth.refreshToken,
                    client_id: auth.clientId,
                    client_secret: auth.clientSecret,
                    grant_type: 'refresh_token'
                })
            });
            return { accessToken: res.data.access_token };
        }
    },
    extendRequest({ auth }) {
        return {
            headers: {
                authorization: `Bearer ${auth?.accessToken}`
            },
            timeout: Math.max(30000, actions_core_1.DEFAULT_REQUEST_TIMEOUT)
        };
    },
    actions: {
        postSheet: postSheet_1.default,
        postSheet2: postSheet2_1.default
    }
};
exports.default = destination;
//# sourceMappingURL=index.js.map