UNPKG

node-firewalla

Version:

Package to talk your firewalla box & API

56 lines (55 loc) 2.38 kB
"use strict"; var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); } return new (P || (P = Promise))(function (resolve, reject) { function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } } function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } } function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); } step((generator = generator.apply(thisArg, _arguments || [])).next()); }); }; var __importDefault = (this && this.__importDefault) || function (mod) { return (mod && mod.__esModule) ? mod : { "default": mod }; }; Object.defineProperty(exports, "__esModule", { value: true }); exports.Networker = void 0; const node_fetch_1 = __importDefault(require("node-fetch")); class Networker { constructor(baseUrl) { this.baseHeaders = {}; this.baseUrl = baseUrl; } setAuth(token) { this.authToken = token; } addHeader(key, value) { this.baseHeaders[key] = value; } authPostRelative(endpoint, body) { return __awaiter(this, void 0, void 0, function* () { return this.authPost(this.baseUrl + endpoint, body); }); } authPost(url, body) { return __awaiter(this, void 0, void 0, function* () { return (0, node_fetch_1.default)(url, { method: "POST", headers: Object.assign({ "Authorization": `Bearer ${this.authToken}`, "Content-Type": "application/json" }, this.baseHeaders), body: JSON.stringify(body) }).then(r => r.json()); }); } authGetRelative(endpoint) { return __awaiter(this, void 0, void 0, function* () { return this.authGet(this.baseUrl + endpoint); }); } authGet(url) { return __awaiter(this, void 0, void 0, function* () { return (0, node_fetch_1.default)(url, { headers: Object.assign({ "Authorization": `Bearer ${this.authToken}` }, this.baseHeaders), }).then(r => r.json()); }); } } exports.Networker = Networker;