UNPKG

@piarre/ts-freebox

Version:

122 lines (117 loc) 4.1 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/lib/connection.ts var connection_exports = {}; __export(connection_exports, { Connection: () => Connection }); module.exports = __toCommonJS(connection_exports); // src/utils/fetch.ts 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; // src/lib/submodule.ts var Submodule = class { _freebox; baseUrl; token; constructor(freebox) { this._freebox = freebox; this.baseUrl = this._freebox._configuration.baseUrl; this.token = this._freebox.token; } }; var submodule_default = Submodule; // src/lib/connection.ts var Connection = class extends submodule_default { constructor(freebox) { super(freebox); } /** * Get the current Connection status * @link https://mafreebox.freebox.fr/doc/index.html?v=b828168f17942dd3e241fff4f01ccdd14bcc89aa#connection-status-object * @returns {Promise<Response<ConnectionStatus>>} */ async status() { return await fetch_default(`${this.baseUrl}/connection/`, this.token); } /** * Get the current Connection configuration * @link https://mafreebox.freebox.fr/doc/index.html?v=b828168f17942dd3e241fff4f01ccdd14bcc89aa#get-the-current-connection-configuration * @returns {Promise<Response<ConnectionConfig>>} */ async config() { return await fetch_default(`${this.baseUrl}/connection/config/`, this.token); } /** * Update the Connection configuration * @link https://mafreebox.freebox.fr/doc/index.html?v=b828168f17942dd3e241fff4f01ccdd14bcc89aa#update-the-connection-configuration * @param body The new configuration * @returns {Promise<Response<ConnectionConfig>>} */ async updateConfig(body) { return await fetch_default(`${this.baseUrl}/connection/config/`, this.token, { body }); } /** * Get the current IPv6 Connection configuration * @link https://mafreebox.freebox.fr/doc/index.html?v=b828168f17942dd3e241fff4f01ccdd14bcc89aa#get-the-current-ipv6-connection-configuration * @returns {Promise<Response<IPv6ConnectionConfiguration>>} */ async IPv6config() { return await fetch_default(`${this.baseUrl}/connection/ipv6/config/`, this.token); } /** * Update the IPv6 Connection configuration * @link https://mafreebox.freebox.fr/doc/index.html?v=b828168f17942dd3e241fff4f01ccdd14bcc89aa#update-the-ipv6-connection-configuration * @param body The new configuration * @returns {Promise<Response<IPv6ConnectionConfiguration>>} */ async updateIPv6Config(body) { return await fetch_default( `${this.baseUrl}/connection/ipv6/config/`, this.token, { body }, "PUT" ); } }; // Annotate the CommonJS export names for ESM import in node: 0 && (module.exports = { Connection });