UNPKG

unleash-server

Version:

Unleash is an enterprise ready feature toggles service. It provides different strategies for handling feature toggles.

38 lines 1.41 kB
"use strict"; var __importDefault = (this && this.__importDefault) || function (mod) { return (mod && mod.__esModule) ? mod : { "default": mod }; }; Object.defineProperty(exports, "__esModule", { value: true }); const mustache_1 = __importDefault(require("mustache")); const addon_1 = __importDefault(require("./addon")); const webhook_definition_1 = __importDefault(require("./webhook-definition")); class Webhook extends addon_1.default { constructor(args) { super(webhook_definition_1.default, args); } async handleEvent(event, parameters) { const { url, bodyTemplate, contentType, authorization } = parameters; const context = { event, }; let body; if (typeof bodyTemplate === 'string' && bodyTemplate.length > 1) { body = mustache_1.default.render(bodyTemplate, context); } else { body = JSON.stringify(event); } const requestOpts = { method: 'POST', headers: { 'Content-Type': contentType || 'application/json', Authorization: authorization || undefined, }, body, }; const res = await this.fetchRetry(url, requestOpts); this.logger.info(`Handled event "${event.type}". Status code: ${res.status}`); } } exports.default = Webhook; //# sourceMappingURL=webhook.js.map