UNPKG

@piarre/ts-freebox

Version:

52 lines (50 loc) 1.76 kB
var __defProp = Object.defineProperty; var __getOwnPropDesc = Object.getOwnPropertyDescriptor; var __getOwnPropNames = Object.getOwnPropertyNames; var __hasOwnProp = Object.prototype.hasOwnProperty; 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); // src/utils/fetch.ts var fetch_exports = {}; __export(fetch_exports, { default: () => fetch_default, fetchFBX: () => fetchFBX, request: () => request }); module.exports = __toCommonJS(fetch_exports); var formatUrl = (url) => !url.toString().endsWith("/") ? `${url}/` : url; var fetchFBX = (url, token, method, options) => { return fetch(formatUrl(url), { ...options, method, body: JSON.stringify(options?.body), headers: { ...options?.headers, "Content-Type": "application/json", "X-Fbx-App-Auth": token || "", Host: "mafreebox.freebox.fr" } }).then((res) => res.json()).catch((error) => { throw new Error(`\u274C ~ error on call ${url}`, { cause: error }); }); }; var request = (url, token, options, method = "GET") => fetchFBX(url, token, method, options); var fetch_default = request; // Annotate the CommonJS export names for ESM import in node: 0 && (module.exports = { fetchFBX, request });