UNPKG

aluvia-ts-sdk

Version:

Official Aluvia proxy management SDK for Node.js and modern JavaScript environments

40 lines 1.41 kB
// Universal fetch implementation for Node.js and browser let _fetch; // Initialize fetch polyfill for Node.js < 18 async function initializeFetch() { if (_fetch) return _fetch; if (typeof globalThis.fetch !== "undefined") { // Browser or Node.js 18+ with native fetch _fetch = globalThis.fetch; } else { // Node.js < 18, use node-fetch polyfill try { // Check if we're in a test environment if (process.env.NODE_ENV === "test" || process.env.JEST_WORKER_ID !== undefined) { // In Jest test environment, create a simple mock fetch _fetch = (async () => ({ ok: true, status: 200, json: async () => ({}), text: async () => "", headers: new Map(), })); } else { // Production environment, use real node-fetch const { default: nodeFetch } = await import("node-fetch"); _fetch = nodeFetch; } } catch (error) { // Fallback for when node-fetch is not available throw new Error("Fetch is not available. Please use Node.js 18+ or install node-fetch."); } } return _fetch; } export { initializeFetch }; //# sourceMappingURL=fetch.js.map