This commit is contained in:
2026-10-20 10:12:33 -04:00
parent 2dd7382004
commit f2bd3e38e2
2 changed files with 16 additions and 1 deletions
+4 -1
View File
@@ -9,7 +9,10 @@ export class StateClient {
private cache: { chainId: string; blocks: TestnetBlock[]; bytes: number } | undefined;
private inFlight: Promise<TestnetSnapshot> | undefined;
private readonly fetcher: typeof fetch;
constructor(fetcher: typeof fetch = fetch) { this.fetcher = fetcher; }
constructor(fetcher: typeof fetch = globalThis.fetch) {
// Browser Web APIs require the Window/global receiver, not this StateClient instance.
this.fetcher = fetcher.bind(globalThis);
}
async json<T>(path: string, signal: AbortSignal): Promise<T> {
const response = await this.fetcher(`/api/${path}`, { cache: 'no-store', redirect: 'error', signal });
if (!/^application\/json(?:\s*;|$)/i.test(response.headers.get('content-type') ?? '') || !response.body) throw new Error('Node must return JSON.');