"use strict";
var __importDefault = (this && this.__importDefault) || function (mod) {
    return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
const crypto_1 = require("crypto");
const send_1 = __importDefault(require("./send"));
const destination = {
    name: 'Webhook',
    slug: 'actions-webhook',
    mode: 'cloud',
    authentication: {
        scheme: 'custom',
        fields: {
            sharedSecret: {
                type: 'password',
                label: 'Shared Secret',
                description: 'If set, Segment will sign requests with an HMAC in the "X-Signature" request header. The HMAC is a hex-encoded SHA1 hash generated using this shared secret and the request body.'
            }
        }
    },
    extendRequest: ({ settings, payload }) => {
        const payloadData = payload.length ? payload[0]['data'] : payload['data'];
        if (settings.sharedSecret && payloadData) {
            const digest = (0, crypto_1.createHmac)('sha1', settings.sharedSecret).update(JSON.stringify(payloadData), 'utf8').digest('hex');
            return { headers: { 'X-Signature': digest } };
        }
        return {};
    },
    actions: {
        send: send_1.default
    }
};
exports.default = destination;
//# sourceMappingURL=index.js.map