UNPKG

@techolution-ai/computer-vision

Version:

A JavaScript/TypeScript library for computer vision applications, providing tools for image processing, scanning, and MQTT-based messaging.

99 lines (98 loc) 3.43 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/helpers/http-client.ts var http_client_exports = {}; __export(http_client_exports, { default: () => HttpClient }); module.exports = __toCommonJS(http_client_exports); var import_utils = require("./utils.cjs"); var HttpClient = class { constructor(options) { this.baseUrl = options.baseUrl; this.headers = options.headers || { "Content-Type": "application/json" }; this.withCredentials = options.withCredentials || false; this._makeRequest = this._makeRequest.bind(this); } async _makeRequest(url, method, body, options = {}) { let data = null; const _withCredentials = options.withCredentials !== void 0 ? options.withCredentials : this.withCredentials; const combinedHeaders = { ...this.headers, ...options.headers }; const res = await fetch((0, import_utils.prepareRequestUrl)(url, this.baseUrl), { method, headers: combinedHeaders, body: body ? JSON.stringify(body) : null, credentials: _withCredentials ? "include" : "same-origin", signal: options.signal }); try { const contentType = res.headers.get("content-type"); if (contentType && contentType.includes("application/json")) { data = await res.json(); } else if (contentType && contentType.includes("text/")) { data = await res.text(); } else { data = await res.blob(); } } catch (error) { } return { status: res.status, statusText: res.statusText, headers: res.headers, url: res.url, redirected: res.redirected, ok: res.ok, data }; } async get(url, options = {}) { return this._makeRequest(url, "GET", null, options); } async post(url, body = null, options = {}) { return this._makeRequest(url, "POST", body, options); } async put(url, body = null, options = {}) { return this._makeRequest(url, "PUT", body, options); } async delete(url, body = null, options = {}) { return this._makeRequest(url, "DELETE", body, options); } async patch(url, body = null, options = {}) { return this._makeRequest(url, "PATCH", body, options); } async head(url, body = null, options = {}) { return this._makeRequest(url, "HEAD", body, options); } async options(url, body = null, options = {}) { return this._makeRequest(url, "OPTIONS", body, options); } addHeaders(headers) { this.headers = { ...this.headers, ...headers }; } removeHeader(key) { delete this.headers[key]; } clearHeaders() { this.headers = {}; } setWithCredentials(value) { this.withCredentials = value; } }; //# sourceMappingURL=http-client.cjs.map