UNPKG

@setten/mercure

Version:
33 lines (32 loc) 1.08 kB
"use strict"; /** * @setten/mercure * * @license MIT * @copyright Setten - Romain Lanz <romain.lanz@setten.io> */ var __importDefault = (this && this.__importDefault) || function (mod) { return (mod && mod.__esModule) ? mod : { "default": mod }; }; Object.defineProperty(exports, "__esModule", { value: true }); const got_1 = __importDefault(require("got")); class Update { constructor(config) { Object.defineProperty(this, "config", { enumerable: true, configurable: true, writable: true, value: config }); } send(topics, data = {}, isPrivate = false) { topics = Array.isArray(topics) ? topics : [topics]; return got_1.default.post(this.config.endpoint, { headers: { Authorization: `Bearer ${this.config.adminToken}`, }, form: [...topics.map((topic) => ['topic', topic]), ['data', JSON.stringify(data)]].concat(isPrivate ? [['private', 'on']] : []), }); } } exports.default = Update;