UNPKG

@dev-team-tool/feature-switches

Version:

Library to access feature-switches from dev-team-tools.com programatically

112 lines (109 loc) 4.04 kB
"use strict"; var __defProp = Object.defineProperty; var __getOwnPropDesc = Object.getOwnPropertyDescriptor; var __getOwnPropNames = Object.getOwnPropertyNames; var __hasOwnProp = Object.prototype.hasOwnProperty; var __typeError = (msg) => { throw TypeError(msg); }; var __export = (target, all) => { for (var name in all) __defProp(target, name, { get: all[name], enumerable: true }); }; var __copyProps = (to, from, except, desc) => { if (from && typeof from === "object" || typeof from === "function") { for (let key of __getOwnPropNames(from)) if (!__hasOwnProp.call(to, key) && key !== except) __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable }); } return to; }; var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod); var __accessCheck = (obj, member, msg) => member.has(obj) || __typeError("Cannot " + msg); var __privateGet = (obj, member, getter) => (__accessCheck(obj, member, "read from private field"), getter ? getter.call(obj) : member.get(obj)); var __privateAdd = (obj, member, value) => member.has(obj) ? __typeError("Cannot add the same private member more than once") : member instanceof WeakSet ? member.add(obj) : member.set(obj, value); var __privateSet = (obj, member, value, setter) => (__accessCheck(obj, member, "write to private field"), setter ? setter.call(obj, value) : member.set(obj, value), value); // src/index.ts var index_exports = {}; __export(index_exports, { FeatureSwitchManager: () => FeatureSwitchManagerImpl }); module.exports = __toCommonJS(index_exports); // src/FeatureSwitchManagerImp.ts var _url, _token, _environment; var FeatureSwitchManagerImpl = class { constructor(token, environment) { __privateAdd(this, _url, "https://feature-switches.harry-9ce.workers.dev"); __privateAdd(this, _token); __privateAdd(this, _environment); this.getSwitchValue = async (key, userRequest) => { const body = userRequest ? userRequest : void 0; const url = `${__privateGet(this, _url)}/${__privateGet(this, _environment)}/${key}`; let response; try { response = await fetch(url, { method: "POST", headers: { "User-Agent": "dev-team-tools-node", "Content-Type": "application/json", Authorization: __privateGet(this, _token) }, body: JSON.stringify(body) }); if (response.status > 299) { console.error(`Status code: ${response.status} returned`); return false; } } catch (err) { console.error(err); return false; } try { const result = await response.json(); return result.value; } catch (err) { console.error(err); return false; } }; this.getSwitches = async (userRequest) => { const body = userRequest ? userRequest : void 0; const url = `${__privateGet(this, _url)}/${__privateGet(this, _environment)}`; let response; try { response = await fetch(url, { method: "POST", headers: { "User-Agent": "dev-team-tools-node", "Content-Type": "application/json", Authorization: __privateGet(this, _token) }, body: JSON.stringify(body) }); if (response.status > 299) { console.error(`Status code: ${response.status} returned`); return []; } } catch (err) { console.error(err); return []; } try { const result = await response.json(); return result; } catch (err) { console.error(err); return []; } }; __privateSet(this, _token, token); __privateSet(this, _environment, environment); } }; _url = new WeakMap(); _token = new WeakMap(); _environment = new WeakMap(); // Annotate the CommonJS export names for ESM import in node: 0 && (module.exports = { FeatureSwitchManager });