UNPKG

@memori.ai/memori-api-client

Version:

React library to integrate a Memori in your app or website

37 lines 1.7 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.apiBinaryFetcher = exports.apiFetcher = void 0; const tslib_1 = require("tslib"); const cross_fetch_1 = tslib_1.__importDefault(require("cross-fetch")); const apiFetcher = (path, opts) => (0, cross_fetch_1.default)(`${opts.apiUrl}${path}`, { ...opts, body: (opts === null || opts === void 0 ? void 0 : opts.body) ? JSON.stringify(opts.body) : undefined, mode: 'cors', credentials: 'include', headers: { 'Content-Type': 'application/json', ...opts === null || opts === void 0 ? void 0 : opts.headers, }, }).then(res => ((opts === null || opts === void 0 ? void 0 : opts.text) ? res.text() : res.json())); exports.apiFetcher = apiFetcher; const apiBinaryFetcher = async (path, opts) => { const responseType = (opts === null || opts === void 0 ? void 0 : opts.responseType) || 'arrayBuffer'; return (0, cross_fetch_1.default)(`${opts.apiUrl}${path}`, { method: opts.method || 'GET', body: (opts === null || opts === void 0 ? void 0 : opts.body) ? JSON.stringify(opts.body) : undefined, mode: 'cors', credentials: 'include', headers: { 'Content-Type': 'application/json', Accept: 'application/octet-stream, application/zip', ...opts === null || opts === void 0 ? void 0 : opts.headers, }, }).then(async (res) => { if (!res.ok) { throw new Error(`API responded with status: ${res.status}`); } return responseType === 'blob' ? res.blob() : res.arrayBuffer(); }); }; exports.apiBinaryFetcher = apiBinaryFetcher; //# sourceMappingURL=apiFetcher.js.map