import { HttpRequestOptions, HttpResponse } from "./../../types"; export async function httpBrowser( method: string, url: string, body: any, options: HttpRequestOptions ): Promise> { const controller = new AbortController(); const timeout = options.timeout ?? 8000; const timer = setTimeout(() => controller.abort(), timeout); const res = await fetch(url, { method, headers: { "Content-Type": "application/json", ...(options.headers || {}) }, body: body ? JSON.stringify(body) : undefined, signal: controller.signal, }); clearTimeout(timer); const data = options.json === false ? await res.text() : await res.json().catch(() => null); if (!res.ok) { throw new Error(`Fetch error: ${res.status} ${res.statusText}`); } return { status: res.status, data, headers: {} }; }