jet-network-fetch.js
1 "use strict"; 2 Object.defineProperty(exports, "__esModule", { value: true }); 3 exports.JetNetworkFetch = void 0; 4 const optional_1 = require("@jet/environment/types/optional"); 5 class JetNetworkFetch { 6 async fetch(request) { 7 var _a, _b, _c; 8 if (optional_1.isNothing(process === null || process === void 0 ? void 0 : process.env.MEDIA_API_TOKEN)) { 9 return await Promise.reject(new Error("process.env.MEDIA_API_TOKEN must be specified")); 10 } 11 const headers = { 12 ...((_a = request.headers) !== null && _a !== void 0 ? _a : {}), 13 authorization: `Bearer ${process === null || process === void 0 ? void 0 : process.env.MEDIA_API_TOKEN}`, 14 }; 15 const response = await fetch(request.url, { 16 body: request.body, 17 method: (_b = request.method) !== null && _b !== void 0 ? _b : undefined, 18 cache: (_c = request.cache) !== null && _c !== void 0 ? _c : undefined, 19 headers: headers, 20 }); 21 return { 22 ok: response.ok, 23 headers: Array.from(response.headers.keys()).reduce((previous, key) => { 24 const value = response.headers.get(key); 25 if (optional_1.isSome(value)) { 26 previous[key] = value; 27 } 28 return previous; 29 }, {}), 30 redirected: response.redirected, 31 status: response.status, 32 statusText: response.statusText, 33 url: response.url, 34 body: await response.text(), 35 metrics: [], 36 }; 37 } 38 } 39 exports.JetNetworkFetch = JetNetworkFetch;