From 839fb08b947359563bad253519bed2fa5444e2b0 Mon Sep 17 00:00:00 2001 From: Omar McIver Date: Tue, 23 Sep 2025 09:03:27 -0500 Subject: [PATCH 1/3] fix: ESM compatibility - avoid direct Response object mutation When using fetch in ESM environments (e.g., node-fetch v3+), the Response object is read-only and attempting to set properties like 'data' and 'error' directly throws an error. This fix creates a wrapper object that delegates to the original Response while allowing the assignment of custom properties, ensuring compatibility with both CommonJS and ESM environments. Fixes compatibility with node-fetch v3+ and other ESM-only fetch implementations. --- .../base/http-clients/fetch-http-client.ejs | 26 +- tests/__snapshots__/extended.test.ts.snap | 1144 +++++++++++++++-- tests/__snapshots__/simple.test.ts.snap | 1144 +++++++++++++++-- .../__snapshots__/basic.test.ts.snap | 26 +- .../__snapshots__/basic.test.ts.snap | 26 +- .../__snapshots__/basic.test.ts.snap | 26 +- .../__snapshots__/basic.test.ts.snap | 26 +- .../__snapshots__/basic.test.ts.snap | 26 +- .../__snapshots__/basic.test.ts.snap | 26 +- .../__snapshots__/basic.test.ts.snap | 26 +- .../__snapshots__/inline.test.ts.snap | 26 +- .../__snapshots__/basic.test.ts.snap | 26 +- .../__snapshots__/basic.test.ts.snap | 26 +- .../__snapshots__/basic.test.ts.snap | 26 +- .../__snapshots__/basic.test.ts.snap | 26 +- .../__snapshots__/basic.test.ts.snap | 26 +- .../jsAxios/__snapshots__/basic.test.ts.snap | 26 +- .../__snapshots__/basic.test.ts.snap | 26 +- .../__snapshots__/basic.test.ts.snap | 26 +- .../__snapshots__/basic.test.ts.snap | 26 +- .../__snapshots__/basic.test.ts.snap | 26 +- .../__snapshots__/basic.test.ts.snap | 26 +- .../patch/__snapshots__/basic.test.ts.snap | 26 +- .../__snapshots__/basic.test.ts.snap | 26 +- .../__snapshots__/basic.test.ts.snap | 26 +- .../__snapshots__/basic.test.ts.snap | 26 +- .../__snapshots__/basic.test.ts.snap | 26 +- .../__snapshots__/basic.test.ts.snap | 26 +- .../__snapshots__/basic.test.ts.snap | 26 +- 29 files changed, 2645 insertions(+), 345 deletions(-) diff --git a/templates/base/http-clients/fetch-http-client.ejs b/templates/base/http-clients/fetch-http-client.ejs index 9f6a5c30..9f144712 100644 --- a/templates/base/http-clients/fetch-http-client.ejs +++ b/templates/base/http-clients/fetch-http-client.ejs @@ -196,9 +196,29 @@ export class HttpClient { body: typeof body === "undefined" || body === null ? null : payloadFormatter(body), } ).then(async (response) => { - const r = response as HttpResponse; - r.data = (null as unknown) as T; - r.error = (null as unknown) as E; + // Create a wrapper object that doesn't mutate the Response + // This ensures compatibility with ESM environments where Response is read-only + const r = { + data: (null as unknown) as T, + error: (null as unknown) as E, + // Delegate Response properties + ok: response.ok, + status: response.status, + statusText: response.statusText, + headers: response.headers, + url: response.url, + redirected: response.redirected, + type: response.type, + body: response.body, + bodyUsed: response.bodyUsed, + // Delegate Response methods + arrayBuffer: () => response.arrayBuffer(), + blob: () => response.blob(), + clone: () => response.clone(), + formData: () => response.formData(), + json: () => response.json(), + text: () => response.text(), + } as HttpResponse; const responseToParse = responseFormat ? response.clone() : response; const data = !responseFormat ? r : await responseToParse[responseFormat]() diff --git a/tests/__snapshots__/extended.test.ts.snap b/tests/__snapshots__/extended.test.ts.snap index e95bc232..3b4ec5f8 100644 --- a/tests/__snapshots__/extended.test.ts.snap +++ b/tests/__snapshots__/extended.test.ts.snap @@ -2941,9 +2941,29 @@ export class HttpClient { : payloadFormatter(body), }, ).then(async (response) => { - const r = response as HttpResponse; - r.data = null as unknown as T; - r.error = null as unknown as E; + // Create a wrapper object that doesn't mutate the Response + // This ensures compatibility with ESM environments where Response is read-only + const r = { + data: null as unknown as T, + error: null as unknown as E, + // Delegate Response properties + ok: response.ok, + status: response.status, + statusText: response.statusText, + headers: response.headers, + url: response.url, + redirected: response.redirected, + type: response.type, + body: response.body, + bodyUsed: response.bodyUsed, + // Delegate Response methods + arrayBuffer: () => response.arrayBuffer(), + blob: () => response.blob(), + clone: () => response.clone(), + formData: () => response.formData(), + json: () => response.json(), + text: () => response.text(), + } as HttpResponse; const responseToParse = responseFormat ? response.clone() : response; const data = !responseFormat @@ -4947,9 +4967,29 @@ export class HttpClient { : payloadFormatter(body), }, ).then(async (response) => { - const r = response as HttpResponse; - r.data = null as unknown as T; - r.error = null as unknown as E; + // Create a wrapper object that doesn't mutate the Response + // This ensures compatibility with ESM environments where Response is read-only + const r = { + data: null as unknown as T, + error: null as unknown as E, + // Delegate Response properties + ok: response.ok, + status: response.status, + statusText: response.statusText, + headers: response.headers, + url: response.url, + redirected: response.redirected, + type: response.type, + body: response.body, + bodyUsed: response.bodyUsed, + // Delegate Response methods + arrayBuffer: () => response.arrayBuffer(), + blob: () => response.blob(), + clone: () => response.clone(), + formData: () => response.formData(), + json: () => response.json(), + text: () => response.text(), + } as HttpResponse; const responseToParse = responseFormat ? response.clone() : response; const data = !responseFormat @@ -5229,9 +5269,29 @@ export class HttpClient { : payloadFormatter(body), }, ).then(async (response) => { - const r = response as HttpResponse; - r.data = null as unknown as T; - r.error = null as unknown as E; + // Create a wrapper object that doesn't mutate the Response + // This ensures compatibility with ESM environments where Response is read-only + const r = { + data: null as unknown as T, + error: null as unknown as E, + // Delegate Response properties + ok: response.ok, + status: response.status, + statusText: response.statusText, + headers: response.headers, + url: response.url, + redirected: response.redirected, + type: response.type, + body: response.body, + bodyUsed: response.bodyUsed, + // Delegate Response methods + arrayBuffer: () => response.arrayBuffer(), + blob: () => response.blob(), + clone: () => response.clone(), + formData: () => response.formData(), + json: () => response.json(), + text: () => response.text(), + } as HttpResponse; const responseToParse = responseFormat ? response.clone() : response; const data = !responseFormat @@ -5546,9 +5606,29 @@ export class HttpClient { : payloadFormatter(body), }, ).then(async (response) => { - const r = response as HttpResponse; - r.data = null as unknown as T; - r.error = null as unknown as E; + // Create a wrapper object that doesn't mutate the Response + // This ensures compatibility with ESM environments where Response is read-only + const r = { + data: null as unknown as T, + error: null as unknown as E, + // Delegate Response properties + ok: response.ok, + status: response.status, + statusText: response.statusText, + headers: response.headers, + url: response.url, + redirected: response.redirected, + type: response.type, + body: response.body, + bodyUsed: response.bodyUsed, + // Delegate Response methods + arrayBuffer: () => response.arrayBuffer(), + blob: () => response.blob(), + clone: () => response.clone(), + formData: () => response.formData(), + json: () => response.json(), + text: () => response.text(), + } as HttpResponse; const responseToParse = responseFormat ? response.clone() : response; const data = !responseFormat @@ -6566,9 +6646,29 @@ export class HttpClient { : payloadFormatter(body), }, ).then(async (response) => { - const r = response as HttpResponse; - r.data = null as unknown as T; - r.error = null as unknown as E; + // Create a wrapper object that doesn't mutate the Response + // This ensures compatibility with ESM environments where Response is read-only + const r = { + data: null as unknown as T, + error: null as unknown as E, + // Delegate Response properties + ok: response.ok, + status: response.status, + statusText: response.statusText, + headers: response.headers, + url: response.url, + redirected: response.redirected, + type: response.type, + body: response.body, + bodyUsed: response.bodyUsed, + // Delegate Response methods + arrayBuffer: () => response.arrayBuffer(), + blob: () => response.blob(), + clone: () => response.clone(), + formData: () => response.formData(), + json: () => response.json(), + text: () => response.text(), + } as HttpResponse; const responseToParse = responseFormat ? response.clone() : response; const data = !responseFormat @@ -7384,9 +7484,29 @@ export class HttpClient { : payloadFormatter(body), }, ).then(async (response) => { - const r = response as HttpResponse; - r.data = null as unknown as T; - r.error = null as unknown as E; + // Create a wrapper object that doesn't mutate the Response + // This ensures compatibility with ESM environments where Response is read-only + const r = { + data: null as unknown as T, + error: null as unknown as E, + // Delegate Response properties + ok: response.ok, + status: response.status, + statusText: response.statusText, + headers: response.headers, + url: response.url, + redirected: response.redirected, + type: response.type, + body: response.body, + bodyUsed: response.bodyUsed, + // Delegate Response methods + arrayBuffer: () => response.arrayBuffer(), + blob: () => response.blob(), + clone: () => response.clone(), + formData: () => response.formData(), + json: () => response.json(), + text: () => response.text(), + } as HttpResponse; const responseToParse = responseFormat ? response.clone() : response; const data = !responseFormat @@ -7744,9 +7864,29 @@ export class HttpClient { : payloadFormatter(body), }, ).then(async (response) => { - const r = response as HttpResponse; - r.data = null as unknown as T; - r.error = null as unknown as E; + // Create a wrapper object that doesn't mutate the Response + // This ensures compatibility with ESM environments where Response is read-only + const r = { + data: null as unknown as T, + error: null as unknown as E, + // Delegate Response properties + ok: response.ok, + status: response.status, + statusText: response.statusText, + headers: response.headers, + url: response.url, + redirected: response.redirected, + type: response.type, + body: response.body, + bodyUsed: response.bodyUsed, + // Delegate Response methods + arrayBuffer: () => response.arrayBuffer(), + blob: () => response.blob(), + clone: () => response.clone(), + formData: () => response.formData(), + json: () => response.json(), + text: () => response.text(), + } as HttpResponse; const responseToParse = responseFormat ? response.clone() : response; const data = !responseFormat @@ -8062,9 +8202,29 @@ export class HttpClient { : payloadFormatter(body), }, ).then(async (response) => { - const r = response as HttpResponse; - r.data = null as unknown as T; - r.error = null as unknown as E; + // Create a wrapper object that doesn't mutate the Response + // This ensures compatibility with ESM environments where Response is read-only + const r = { + data: null as unknown as T, + error: null as unknown as E, + // Delegate Response properties + ok: response.ok, + status: response.status, + statusText: response.statusText, + headers: response.headers, + url: response.url, + redirected: response.redirected, + type: response.type, + body: response.body, + bodyUsed: response.bodyUsed, + // Delegate Response methods + arrayBuffer: () => response.arrayBuffer(), + blob: () => response.blob(), + clone: () => response.clone(), + formData: () => response.formData(), + json: () => response.json(), + text: () => response.text(), + } as HttpResponse; const responseToParse = responseFormat ? response.clone() : response; const data = !responseFormat @@ -8428,9 +8588,29 @@ export class HttpClient { : payloadFormatter(body), }, ).then(async (response) => { - const r = response as HttpResponse; - r.data = null as unknown as T; - r.error = null as unknown as E; + // Create a wrapper object that doesn't mutate the Response + // This ensures compatibility with ESM environments where Response is read-only + const r = { + data: null as unknown as T, + error: null as unknown as E, + // Delegate Response properties + ok: response.ok, + status: response.status, + statusText: response.statusText, + headers: response.headers, + url: response.url, + redirected: response.redirected, + type: response.type, + body: response.body, + bodyUsed: response.bodyUsed, + // Delegate Response methods + arrayBuffer: () => response.arrayBuffer(), + blob: () => response.blob(), + clone: () => response.clone(), + formData: () => response.formData(), + json: () => response.json(), + text: () => response.text(), + } as HttpResponse; const responseToParse = responseFormat ? response.clone() : response; const data = !responseFormat @@ -9298,9 +9478,29 @@ export class HttpClient { : payloadFormatter(body), }, ).then(async (response) => { - const r = response as HttpResponse; - r.data = null as unknown as T; - r.error = null as unknown as E; + // Create a wrapper object that doesn't mutate the Response + // This ensures compatibility with ESM environments where Response is read-only + const r = { + data: null as unknown as T, + error: null as unknown as E, + // Delegate Response properties + ok: response.ok, + status: response.status, + statusText: response.statusText, + headers: response.headers, + url: response.url, + redirected: response.redirected, + type: response.type, + body: response.body, + bodyUsed: response.bodyUsed, + // Delegate Response methods + arrayBuffer: () => response.arrayBuffer(), + blob: () => response.blob(), + clone: () => response.clone(), + formData: () => response.formData(), + json: () => response.json(), + text: () => response.text(), + } as HttpResponse; const responseToParse = responseFormat ? response.clone() : response; const data = !responseFormat @@ -9924,9 +10124,29 @@ export class HttpClient { : payloadFormatter(body), }, ).then(async (response) => { - const r = response as HttpResponse; - r.data = null as unknown as T; - r.error = null as unknown as E; + // Create a wrapper object that doesn't mutate the Response + // This ensures compatibility with ESM environments where Response is read-only + const r = { + data: null as unknown as T, + error: null as unknown as E, + // Delegate Response properties + ok: response.ok, + status: response.status, + statusText: response.statusText, + headers: response.headers, + url: response.url, + redirected: response.redirected, + type: response.type, + body: response.body, + bodyUsed: response.bodyUsed, + // Delegate Response methods + arrayBuffer: () => response.arrayBuffer(), + blob: () => response.blob(), + clone: () => response.clone(), + formData: () => response.formData(), + json: () => response.json(), + text: () => response.text(), + } as HttpResponse; const responseToParse = responseFormat ? response.clone() : response; const data = !responseFormat @@ -10241,9 +10461,29 @@ export class HttpClient { : payloadFormatter(body), }, ).then(async (response) => { - const r = response as HttpResponse; - r.data = null as unknown as T; - r.error = null as unknown as E; + // Create a wrapper object that doesn't mutate the Response + // This ensures compatibility with ESM environments where Response is read-only + const r = { + data: null as unknown as T, + error: null as unknown as E, + // Delegate Response properties + ok: response.ok, + status: response.status, + statusText: response.statusText, + headers: response.headers, + url: response.url, + redirected: response.redirected, + type: response.type, + body: response.body, + bodyUsed: response.bodyUsed, + // Delegate Response methods + arrayBuffer: () => response.arrayBuffer(), + blob: () => response.blob(), + clone: () => response.clone(), + formData: () => response.formData(), + json: () => response.json(), + text: () => response.text(), + } as HttpResponse; const responseToParse = responseFormat ? response.clone() : response; const data = !responseFormat @@ -10564,9 +10804,29 @@ export class HttpClient { : payloadFormatter(body), }, ).then(async (response) => { - const r = response as HttpResponse; - r.data = null as unknown as T; - r.error = null as unknown as E; + // Create a wrapper object that doesn't mutate the Response + // This ensures compatibility with ESM environments where Response is read-only + const r = { + data: null as unknown as T, + error: null as unknown as E, + // Delegate Response properties + ok: response.ok, + status: response.status, + statusText: response.statusText, + headers: response.headers, + url: response.url, + redirected: response.redirected, + type: response.type, + body: response.body, + bodyUsed: response.bodyUsed, + // Delegate Response methods + arrayBuffer: () => response.arrayBuffer(), + blob: () => response.blob(), + clone: () => response.clone(), + formData: () => response.formData(), + json: () => response.json(), + text: () => response.text(), + } as HttpResponse; const responseToParse = responseFormat ? response.clone() : response; const data = !responseFormat @@ -10917,9 +11177,29 @@ export class HttpClient { : payloadFormatter(body), }, ).then(async (response) => { - const r = response as HttpResponse; - r.data = null as unknown as T; - r.error = null as unknown as E; + // Create a wrapper object that doesn't mutate the Response + // This ensures compatibility with ESM environments where Response is read-only + const r = { + data: null as unknown as T, + error: null as unknown as E, + // Delegate Response properties + ok: response.ok, + status: response.status, + statusText: response.statusText, + headers: response.headers, + url: response.url, + redirected: response.redirected, + type: response.type, + body: response.body, + bodyUsed: response.bodyUsed, + // Delegate Response methods + arrayBuffer: () => response.arrayBuffer(), + blob: () => response.blob(), + clone: () => response.clone(), + formData: () => response.formData(), + json: () => response.json(), + text: () => response.text(), + } as HttpResponse; const responseToParse = responseFormat ? response.clone() : response; const data = !responseFormat @@ -11271,9 +11551,29 @@ export class HttpClient { : payloadFormatter(body), }, ).then(async (response) => { - const r = response as HttpResponse; - r.data = null as unknown as T; - r.error = null as unknown as E; + // Create a wrapper object that doesn't mutate the Response + // This ensures compatibility with ESM environments where Response is read-only + const r = { + data: null as unknown as T, + error: null as unknown as E, + // Delegate Response properties + ok: response.ok, + status: response.status, + statusText: response.statusText, + headers: response.headers, + url: response.url, + redirected: response.redirected, + type: response.type, + body: response.body, + bodyUsed: response.bodyUsed, + // Delegate Response methods + arrayBuffer: () => response.arrayBuffer(), + blob: () => response.blob(), + clone: () => response.clone(), + formData: () => response.formData(), + json: () => response.json(), + text: () => response.text(), + } as HttpResponse; const responseToParse = responseFormat ? response.clone() : response; const data = !responseFormat @@ -11650,9 +11950,29 @@ export class HttpClient { : payloadFormatter(body), }, ).then(async (response) => { - const r = response as HttpResponse; - r.data = null as unknown as T; - r.error = null as unknown as E; + // Create a wrapper object that doesn't mutate the Response + // This ensures compatibility with ESM environments where Response is read-only + const r = { + data: null as unknown as T, + error: null as unknown as E, + // Delegate Response properties + ok: response.ok, + status: response.status, + statusText: response.statusText, + headers: response.headers, + url: response.url, + redirected: response.redirected, + type: response.type, + body: response.body, + bodyUsed: response.bodyUsed, + // Delegate Response methods + arrayBuffer: () => response.arrayBuffer(), + blob: () => response.blob(), + clone: () => response.clone(), + formData: () => response.formData(), + json: () => response.json(), + text: () => response.text(), + } as HttpResponse; const responseToParse = responseFormat ? response.clone() : response; const data = !responseFormat @@ -11997,9 +12317,29 @@ export class HttpClient { : payloadFormatter(body), }, ).then(async (response) => { - const r = response as HttpResponse; - r.data = null as unknown as T; - r.error = null as unknown as E; + // Create a wrapper object that doesn't mutate the Response + // This ensures compatibility with ESM environments where Response is read-only + const r = { + data: null as unknown as T, + error: null as unknown as E, + // Delegate Response properties + ok: response.ok, + status: response.status, + statusText: response.statusText, + headers: response.headers, + url: response.url, + redirected: response.redirected, + type: response.type, + body: response.body, + bodyUsed: response.bodyUsed, + // Delegate Response methods + arrayBuffer: () => response.arrayBuffer(), + blob: () => response.blob(), + clone: () => response.clone(), + formData: () => response.formData(), + json: () => response.json(), + text: () => response.text(), + } as HttpResponse; const responseToParse = responseFormat ? response.clone() : response; const data = !responseFormat @@ -50405,9 +50745,29 @@ export class HttpClient { : payloadFormatter(body), }, ).then(async (response) => { - const r = response as HttpResponse; - r.data = null as unknown as T; - r.error = null as unknown as E; + // Create a wrapper object that doesn't mutate the Response + // This ensures compatibility with ESM environments where Response is read-only + const r = { + data: null as unknown as T, + error: null as unknown as E, + // Delegate Response properties + ok: response.ok, + status: response.status, + statusText: response.statusText, + headers: response.headers, + url: response.url, + redirected: response.redirected, + type: response.type, + body: response.body, + bodyUsed: response.bodyUsed, + // Delegate Response methods + arrayBuffer: () => response.arrayBuffer(), + blob: () => response.blob(), + clone: () => response.clone(), + formData: () => response.formData(), + json: () => response.json(), + text: () => response.text(), + } as HttpResponse; const responseToParse = responseFormat ? response.clone() : response; const data = !responseFormat @@ -66208,9 +66568,29 @@ export class HttpClient { : payloadFormatter(body), }, ).then(async (response) => { - const r = response as HttpResponse; - r.data = null as unknown as T; - r.error = null as unknown as E; + // Create a wrapper object that doesn't mutate the Response + // This ensures compatibility with ESM environments where Response is read-only + const r = { + data: null as unknown as T, + error: null as unknown as E, + // Delegate Response properties + ok: response.ok, + status: response.status, + statusText: response.statusText, + headers: response.headers, + url: response.url, + redirected: response.redirected, + type: response.type, + body: response.body, + bodyUsed: response.bodyUsed, + // Delegate Response methods + arrayBuffer: () => response.arrayBuffer(), + blob: () => response.blob(), + clone: () => response.clone(), + formData: () => response.formData(), + json: () => response.json(), + text: () => response.text(), + } as HttpResponse; const responseToParse = responseFormat ? response.clone() : response; const data = !responseFormat @@ -67247,9 +67627,29 @@ export class HttpClient { : payloadFormatter(body), }, ).then(async (response) => { - const r = response as HttpResponse; - r.data = null as unknown as T; - r.error = null as unknown as E; + // Create a wrapper object that doesn't mutate the Response + // This ensures compatibility with ESM environments where Response is read-only + const r = { + data: null as unknown as T, + error: null as unknown as E, + // Delegate Response properties + ok: response.ok, + status: response.status, + statusText: response.statusText, + headers: response.headers, + url: response.url, + redirected: response.redirected, + type: response.type, + body: response.body, + bodyUsed: response.bodyUsed, + // Delegate Response methods + arrayBuffer: () => response.arrayBuffer(), + blob: () => response.blob(), + clone: () => response.clone(), + formData: () => response.formData(), + json: () => response.json(), + text: () => response.text(), + } as HttpResponse; const responseToParse = responseFormat ? response.clone() : response; const data = !responseFormat @@ -67745,9 +68145,29 @@ export class HttpClient { : payloadFormatter(body), }, ).then(async (response) => { - const r = response as HttpResponse; - r.data = null as unknown as T; - r.error = null as unknown as E; + // Create a wrapper object that doesn't mutate the Response + // This ensures compatibility with ESM environments where Response is read-only + const r = { + data: null as unknown as T, + error: null as unknown as E, + // Delegate Response properties + ok: response.ok, + status: response.status, + statusText: response.statusText, + headers: response.headers, + url: response.url, + redirected: response.redirected, + type: response.type, + body: response.body, + bodyUsed: response.bodyUsed, + // Delegate Response methods + arrayBuffer: () => response.arrayBuffer(), + blob: () => response.blob(), + clone: () => response.clone(), + formData: () => response.formData(), + json: () => response.json(), + text: () => response.text(), + } as HttpResponse; const responseToParse = responseFormat ? response.clone() : response; const data = !responseFormat @@ -68194,9 +68614,29 @@ export class HttpClient { : payloadFormatter(body), }, ).then(async (response) => { - const r = response as HttpResponse; - r.data = null as unknown as T; - r.error = null as unknown as E; + // Create a wrapper object that doesn't mutate the Response + // This ensures compatibility with ESM environments where Response is read-only + const r = { + data: null as unknown as T, + error: null as unknown as E, + // Delegate Response properties + ok: response.ok, + status: response.status, + statusText: response.statusText, + headers: response.headers, + url: response.url, + redirected: response.redirected, + type: response.type, + body: response.body, + bodyUsed: response.bodyUsed, + // Delegate Response methods + arrayBuffer: () => response.arrayBuffer(), + blob: () => response.blob(), + clone: () => response.clone(), + formData: () => response.formData(), + json: () => response.json(), + text: () => response.text(), + } as HttpResponse; const responseToParse = responseFormat ? response.clone() : response; const data = !responseFormat @@ -68590,9 +69030,29 @@ export class HttpClient { : payloadFormatter(body), }, ).then(async (response) => { - const r = response as HttpResponse; - r.data = null as unknown as T; - r.error = null as unknown as E; + // Create a wrapper object that doesn't mutate the Response + // This ensures compatibility with ESM environments where Response is read-only + const r = { + data: null as unknown as T, + error: null as unknown as E, + // Delegate Response properties + ok: response.ok, + status: response.status, + statusText: response.statusText, + headers: response.headers, + url: response.url, + redirected: response.redirected, + type: response.type, + body: response.body, + bodyUsed: response.bodyUsed, + // Delegate Response methods + arrayBuffer: () => response.arrayBuffer(), + blob: () => response.blob(), + clone: () => response.clone(), + formData: () => response.formData(), + json: () => response.json(), + text: () => response.text(), + } as HttpResponse; const responseToParse = responseFormat ? response.clone() : response; const data = !responseFormat @@ -68904,9 +69364,29 @@ export class HttpClient { : payloadFormatter(body), }, ).then(async (response) => { - const r = response as HttpResponse; - r.data = null as unknown as T; - r.error = null as unknown as E; + // Create a wrapper object that doesn't mutate the Response + // This ensures compatibility with ESM environments where Response is read-only + const r = { + data: null as unknown as T, + error: null as unknown as E, + // Delegate Response properties + ok: response.ok, + status: response.status, + statusText: response.statusText, + headers: response.headers, + url: response.url, + redirected: response.redirected, + type: response.type, + body: response.body, + bodyUsed: response.bodyUsed, + // Delegate Response methods + arrayBuffer: () => response.arrayBuffer(), + blob: () => response.blob(), + clone: () => response.clone(), + formData: () => response.formData(), + json: () => response.json(), + text: () => response.text(), + } as HttpResponse; const responseToParse = responseFormat ? response.clone() : response; const data = !responseFormat @@ -69266,9 +69746,29 @@ export class HttpClient { : payloadFormatter(body), }, ).then(async (response) => { - const r = response as HttpResponse; - r.data = null as unknown as T; - r.error = null as unknown as E; + // Create a wrapper object that doesn't mutate the Response + // This ensures compatibility with ESM environments where Response is read-only + const r = { + data: null as unknown as T, + error: null as unknown as E, + // Delegate Response properties + ok: response.ok, + status: response.status, + statusText: response.statusText, + headers: response.headers, + url: response.url, + redirected: response.redirected, + type: response.type, + body: response.body, + bodyUsed: response.bodyUsed, + // Delegate Response methods + arrayBuffer: () => response.arrayBuffer(), + blob: () => response.blob(), + clone: () => response.clone(), + formData: () => response.formData(), + json: () => response.json(), + text: () => response.text(), + } as HttpResponse; const responseToParse = responseFormat ? response.clone() : response; const data = !responseFormat @@ -69980,9 +70480,29 @@ export class HttpClient { : payloadFormatter(body), }, ).then(async (response) => { - const r = response as HttpResponse; - r.data = null as unknown as T; - r.error = null as unknown as E; + // Create a wrapper object that doesn't mutate the Response + // This ensures compatibility with ESM environments where Response is read-only + const r = { + data: null as unknown as T, + error: null as unknown as E, + // Delegate Response properties + ok: response.ok, + status: response.status, + statusText: response.statusText, + headers: response.headers, + url: response.url, + redirected: response.redirected, + type: response.type, + body: response.body, + bodyUsed: response.bodyUsed, + // Delegate Response methods + arrayBuffer: () => response.arrayBuffer(), + blob: () => response.blob(), + clone: () => response.clone(), + formData: () => response.formData(), + json: () => response.json(), + text: () => response.text(), + } as HttpResponse; const responseToParse = responseFormat ? response.clone() : response; const data = !responseFormat @@ -70565,9 +71085,29 @@ export class HttpClient { : payloadFormatter(body), }, ).then(async (response) => { - const r = response as HttpResponse; - r.data = null as unknown as T; - r.error = null as unknown as E; + // Create a wrapper object that doesn't mutate the Response + // This ensures compatibility with ESM environments where Response is read-only + const r = { + data: null as unknown as T, + error: null as unknown as E, + // Delegate Response properties + ok: response.ok, + status: response.status, + statusText: response.statusText, + headers: response.headers, + url: response.url, + redirected: response.redirected, + type: response.type, + body: response.body, + bodyUsed: response.bodyUsed, + // Delegate Response methods + arrayBuffer: () => response.arrayBuffer(), + blob: () => response.blob(), + clone: () => response.clone(), + formData: () => response.formData(), + json: () => response.json(), + text: () => response.text(), + } as HttpResponse; const responseToParse = responseFormat ? response.clone() : response; const data = !responseFormat @@ -70994,9 +71534,29 @@ export class HttpClient { : payloadFormatter(body), }, ).then(async (response) => { - const r = response as HttpResponse; - r.data = null as unknown as T; - r.error = null as unknown as E; + // Create a wrapper object that doesn't mutate the Response + // This ensures compatibility with ESM environments where Response is read-only + const r = { + data: null as unknown as T, + error: null as unknown as E, + // Delegate Response properties + ok: response.ok, + status: response.status, + statusText: response.statusText, + headers: response.headers, + url: response.url, + redirected: response.redirected, + type: response.type, + body: response.body, + bodyUsed: response.bodyUsed, + // Delegate Response methods + arrayBuffer: () => response.arrayBuffer(), + blob: () => response.blob(), + clone: () => response.clone(), + formData: () => response.formData(), + json: () => response.json(), + text: () => response.text(), + } as HttpResponse; const responseToParse = responseFormat ? response.clone() : response; const data = !responseFormat @@ -71459,9 +72019,29 @@ export class HttpClient { : payloadFormatter(body), }, ).then(async (response) => { - const r = response as HttpResponse; - r.data = null as unknown as T; - r.error = null as unknown as E; + // Create a wrapper object that doesn't mutate the Response + // This ensures compatibility with ESM environments where Response is read-only + const r = { + data: null as unknown as T, + error: null as unknown as E, + // Delegate Response properties + ok: response.ok, + status: response.status, + statusText: response.statusText, + headers: response.headers, + url: response.url, + redirected: response.redirected, + type: response.type, + body: response.body, + bodyUsed: response.bodyUsed, + // Delegate Response methods + arrayBuffer: () => response.arrayBuffer(), + blob: () => response.blob(), + clone: () => response.clone(), + formData: () => response.formData(), + json: () => response.json(), + text: () => response.text(), + } as HttpResponse; const responseToParse = responseFormat ? response.clone() : response; const data = !responseFormat @@ -71988,9 +72568,29 @@ export class HttpClient { : payloadFormatter(body), }, ).then(async (response) => { - const r = response as HttpResponse; - r.data = null as unknown as T; - r.error = null as unknown as E; + // Create a wrapper object that doesn't mutate the Response + // This ensures compatibility with ESM environments where Response is read-only + const r = { + data: null as unknown as T, + error: null as unknown as E, + // Delegate Response properties + ok: response.ok, + status: response.status, + statusText: response.statusText, + headers: response.headers, + url: response.url, + redirected: response.redirected, + type: response.type, + body: response.body, + bodyUsed: response.bodyUsed, + // Delegate Response methods + arrayBuffer: () => response.arrayBuffer(), + blob: () => response.blob(), + clone: () => response.clone(), + formData: () => response.formData(), + json: () => response.json(), + text: () => response.text(), + } as HttpResponse; const responseToParse = responseFormat ? response.clone() : response; const data = !responseFormat @@ -72380,9 +72980,29 @@ export class HttpClient { : payloadFormatter(body), }, ).then(async (response) => { - const r = response as HttpResponse; - r.data = null as unknown as T; - r.error = null as unknown as E; + // Create a wrapper object that doesn't mutate the Response + // This ensures compatibility with ESM environments where Response is read-only + const r = { + data: null as unknown as T, + error: null as unknown as E, + // Delegate Response properties + ok: response.ok, + status: response.status, + statusText: response.statusText, + headers: response.headers, + url: response.url, + redirected: response.redirected, + type: response.type, + body: response.body, + bodyUsed: response.bodyUsed, + // Delegate Response methods + arrayBuffer: () => response.arrayBuffer(), + blob: () => response.blob(), + clone: () => response.clone(), + formData: () => response.formData(), + json: () => response.json(), + text: () => response.text(), + } as HttpResponse; const responseToParse = responseFormat ? response.clone() : response; const data = !responseFormat @@ -72820,9 +73440,29 @@ export class HttpClient { : payloadFormatter(body), }, ).then(async (response) => { - const r = response as HttpResponse; - r.data = null as unknown as T; - r.error = null as unknown as E; + // Create a wrapper object that doesn't mutate the Response + // This ensures compatibility with ESM environments where Response is read-only + const r = { + data: null as unknown as T, + error: null as unknown as E, + // Delegate Response properties + ok: response.ok, + status: response.status, + statusText: response.statusText, + headers: response.headers, + url: response.url, + redirected: response.redirected, + type: response.type, + body: response.body, + bodyUsed: response.bodyUsed, + // Delegate Response methods + arrayBuffer: () => response.arrayBuffer(), + blob: () => response.blob(), + clone: () => response.clone(), + formData: () => response.formData(), + json: () => response.json(), + text: () => response.text(), + } as HttpResponse; const responseToParse = responseFormat ? response.clone() : response; const data = !responseFormat @@ -73757,9 +74397,29 @@ export class HttpClient { : payloadFormatter(body), }, ).then(async (response) => { - const r = response as HttpResponse; - r.data = null as unknown as T; - r.error = null as unknown as E; + // Create a wrapper object that doesn't mutate the Response + // This ensures compatibility with ESM environments where Response is read-only + const r = { + data: null as unknown as T, + error: null as unknown as E, + // Delegate Response properties + ok: response.ok, + status: response.status, + statusText: response.statusText, + headers: response.headers, + url: response.url, + redirected: response.redirected, + type: response.type, + body: response.body, + bodyUsed: response.bodyUsed, + // Delegate Response methods + arrayBuffer: () => response.arrayBuffer(), + blob: () => response.blob(), + clone: () => response.clone(), + formData: () => response.formData(), + json: () => response.json(), + text: () => response.text(), + } as HttpResponse; const responseToParse = responseFormat ? response.clone() : response; const data = !responseFormat @@ -74566,9 +75226,29 @@ export class HttpClient { : payloadFormatter(body), }, ).then(async (response) => { - const r = response as HttpResponse; - r.data = null as unknown as T; - r.error = null as unknown as E; + // Create a wrapper object that doesn't mutate the Response + // This ensures compatibility with ESM environments where Response is read-only + const r = { + data: null as unknown as T, + error: null as unknown as E, + // Delegate Response properties + ok: response.ok, + status: response.status, + statusText: response.statusText, + headers: response.headers, + url: response.url, + redirected: response.redirected, + type: response.type, + body: response.body, + bodyUsed: response.bodyUsed, + // Delegate Response methods + arrayBuffer: () => response.arrayBuffer(), + blob: () => response.blob(), + clone: () => response.clone(), + formData: () => response.formData(), + json: () => response.json(), + text: () => response.text(), + } as HttpResponse; const responseToParse = responseFormat ? response.clone() : response; const data = !responseFormat @@ -74961,9 +75641,29 @@ export class HttpClient { : payloadFormatter(body), }, ).then(async (response) => { - const r = response as HttpResponse; - r.data = null as unknown as T; - r.error = null as unknown as E; + // Create a wrapper object that doesn't mutate the Response + // This ensures compatibility with ESM environments where Response is read-only + const r = { + data: null as unknown as T, + error: null as unknown as E, + // Delegate Response properties + ok: response.ok, + status: response.status, + statusText: response.statusText, + headers: response.headers, + url: response.url, + redirected: response.redirected, + type: response.type, + body: response.body, + bodyUsed: response.bodyUsed, + // Delegate Response methods + arrayBuffer: () => response.arrayBuffer(), + blob: () => response.blob(), + clone: () => response.clone(), + formData: () => response.formData(), + json: () => response.json(), + text: () => response.text(), + } as HttpResponse; const responseToParse = responseFormat ? response.clone() : response; const data = !responseFormat @@ -75274,9 +75974,29 @@ export class HttpClient { : payloadFormatter(body), }, ).then(async (response) => { - const r = response as HttpResponse; - r.data = null as unknown as T; - r.error = null as unknown as E; + // Create a wrapper object that doesn't mutate the Response + // This ensures compatibility with ESM environments where Response is read-only + const r = { + data: null as unknown as T, + error: null as unknown as E, + // Delegate Response properties + ok: response.ok, + status: response.status, + statusText: response.statusText, + headers: response.headers, + url: response.url, + redirected: response.redirected, + type: response.type, + body: response.body, + bodyUsed: response.bodyUsed, + // Delegate Response methods + arrayBuffer: () => response.arrayBuffer(), + blob: () => response.blob(), + clone: () => response.clone(), + formData: () => response.formData(), + json: () => response.json(), + text: () => response.text(), + } as HttpResponse; const responseToParse = responseFormat ? response.clone() : response; const data = !responseFormat @@ -75570,9 +76290,29 @@ export class HttpClient { : payloadFormatter(body), }, ).then(async (response) => { - const r = response as HttpResponse; - r.data = null as unknown as T; - r.error = null as unknown as E; + // Create a wrapper object that doesn't mutate the Response + // This ensures compatibility with ESM environments where Response is read-only + const r = { + data: null as unknown as T, + error: null as unknown as E, + // Delegate Response properties + ok: response.ok, + status: response.status, + statusText: response.statusText, + headers: response.headers, + url: response.url, + redirected: response.redirected, + type: response.type, + body: response.body, + bodyUsed: response.bodyUsed, + // Delegate Response methods + arrayBuffer: () => response.arrayBuffer(), + blob: () => response.blob(), + clone: () => response.clone(), + formData: () => response.formData(), + json: () => response.json(), + text: () => response.text(), + } as HttpResponse; const responseToParse = responseFormat ? response.clone() : response; const data = !responseFormat @@ -75904,9 +76644,29 @@ export class HttpClient { : payloadFormatter(body), }, ).then(async (response) => { - const r = response as HttpResponse; - r.data = null as unknown as T; - r.error = null as unknown as E; + // Create a wrapper object that doesn't mutate the Response + // This ensures compatibility with ESM environments where Response is read-only + const r = { + data: null as unknown as T, + error: null as unknown as E, + // Delegate Response properties + ok: response.ok, + status: response.status, + statusText: response.statusText, + headers: response.headers, + url: response.url, + redirected: response.redirected, + type: response.type, + body: response.body, + bodyUsed: response.bodyUsed, + // Delegate Response methods + arrayBuffer: () => response.arrayBuffer(), + blob: () => response.blob(), + clone: () => response.clone(), + formData: () => response.formData(), + json: () => response.json(), + text: () => response.text(), + } as HttpResponse; const responseToParse = responseFormat ? response.clone() : response; const data = !responseFormat @@ -76647,9 +77407,29 @@ export class HttpClient { : payloadFormatter(body), }, ).then(async (response) => { - const r = response as HttpResponse; - r.data = null as unknown as T; - r.error = null as unknown as E; + // Create a wrapper object that doesn't mutate the Response + // This ensures compatibility with ESM environments where Response is read-only + const r = { + data: null as unknown as T, + error: null as unknown as E, + // Delegate Response properties + ok: response.ok, + status: response.status, + statusText: response.statusText, + headers: response.headers, + url: response.url, + redirected: response.redirected, + type: response.type, + body: response.body, + bodyUsed: response.bodyUsed, + // Delegate Response methods + arrayBuffer: () => response.arrayBuffer(), + blob: () => response.blob(), + clone: () => response.clone(), + formData: () => response.formData(), + json: () => response.json(), + text: () => response.text(), + } as HttpResponse; const responseToParse = responseFormat ? response.clone() : response; const data = !responseFormat @@ -77546,9 +78326,29 @@ export class HttpClient { : payloadFormatter(body), }, ).then(async (response) => { - const r = response as HttpResponse; - r.data = null as unknown as T; - r.error = null as unknown as E; + // Create a wrapper object that doesn't mutate the Response + // This ensures compatibility with ESM environments where Response is read-only + const r = { + data: null as unknown as T, + error: null as unknown as E, + // Delegate Response properties + ok: response.ok, + status: response.status, + statusText: response.statusText, + headers: response.headers, + url: response.url, + redirected: response.redirected, + type: response.type, + body: response.body, + bodyUsed: response.bodyUsed, + // Delegate Response methods + arrayBuffer: () => response.arrayBuffer(), + blob: () => response.blob(), + clone: () => response.clone(), + formData: () => response.formData(), + json: () => response.json(), + text: () => response.text(), + } as HttpResponse; const responseToParse = responseFormat ? response.clone() : response; const data = !responseFormat @@ -79372,9 +80172,29 @@ export class HttpClient { : payloadFormatter(body), }, ).then(async (response) => { - const r = response as HttpResponse; - r.data = null as unknown as T; - r.error = null as unknown as E; + // Create a wrapper object that doesn't mutate the Response + // This ensures compatibility with ESM environments where Response is read-only + const r = { + data: null as unknown as T, + error: null as unknown as E, + // Delegate Response properties + ok: response.ok, + status: response.status, + statusText: response.statusText, + headers: response.headers, + url: response.url, + redirected: response.redirected, + type: response.type, + body: response.body, + bodyUsed: response.bodyUsed, + // Delegate Response methods + arrayBuffer: () => response.arrayBuffer(), + blob: () => response.blob(), + clone: () => response.clone(), + formData: () => response.formData(), + json: () => response.json(), + text: () => response.text(), + } as HttpResponse; const responseToParse = responseFormat ? response.clone() : response; const data = !responseFormat @@ -80153,9 +80973,29 @@ export class HttpClient { : payloadFormatter(body), }, ).then(async (response) => { - const r = response as HttpResponse; - r.data = null as unknown as T; - r.error = null as unknown as E; + // Create a wrapper object that doesn't mutate the Response + // This ensures compatibility with ESM environments where Response is read-only + const r = { + data: null as unknown as T, + error: null as unknown as E, + // Delegate Response properties + ok: response.ok, + status: response.status, + statusText: response.statusText, + headers: response.headers, + url: response.url, + redirected: response.redirected, + type: response.type, + body: response.body, + bodyUsed: response.bodyUsed, + // Delegate Response methods + arrayBuffer: () => response.arrayBuffer(), + blob: () => response.blob(), + clone: () => response.clone(), + formData: () => response.formData(), + json: () => response.json(), + text: () => response.text(), + } as HttpResponse; const responseToParse = responseFormat ? response.clone() : response; const data = !responseFormat @@ -80504,9 +81344,29 @@ export class HttpClient { : payloadFormatter(body), }, ).then(async (response) => { - const r = response as HttpResponse; - r.data = null as unknown as T; - r.error = null as unknown as E; + // Create a wrapper object that doesn't mutate the Response + // This ensures compatibility with ESM environments where Response is read-only + const r = { + data: null as unknown as T, + error: null as unknown as E, + // Delegate Response properties + ok: response.ok, + status: response.status, + statusText: response.statusText, + headers: response.headers, + url: response.url, + redirected: response.redirected, + type: response.type, + body: response.body, + bodyUsed: response.bodyUsed, + // Delegate Response methods + arrayBuffer: () => response.arrayBuffer(), + blob: () => response.blob(), + clone: () => response.clone(), + formData: () => response.formData(), + json: () => response.json(), + text: () => response.text(), + } as HttpResponse; const responseToParse = responseFormat ? response.clone() : response; const data = !responseFormat @@ -80961,9 +81821,29 @@ export class HttpClient { : payloadFormatter(body), }, ).then(async (response) => { - const r = response as HttpResponse; - r.data = null as unknown as T; - r.error = null as unknown as E; + // Create a wrapper object that doesn't mutate the Response + // This ensures compatibility with ESM environments where Response is read-only + const r = { + data: null as unknown as T, + error: null as unknown as E, + // Delegate Response properties + ok: response.ok, + status: response.status, + statusText: response.statusText, + headers: response.headers, + url: response.url, + redirected: response.redirected, + type: response.type, + body: response.body, + bodyUsed: response.bodyUsed, + // Delegate Response methods + arrayBuffer: () => response.arrayBuffer(), + blob: () => response.blob(), + clone: () => response.clone(), + formData: () => response.formData(), + json: () => response.json(), + text: () => response.text(), + } as HttpResponse; const responseToParse = responseFormat ? response.clone() : response; const data = !responseFormat diff --git a/tests/__snapshots__/simple.test.ts.snap b/tests/__snapshots__/simple.test.ts.snap index 710b2300..36c5efc5 100644 --- a/tests/__snapshots__/simple.test.ts.snap +++ b/tests/__snapshots__/simple.test.ts.snap @@ -394,9 +394,29 @@ export class HttpClient { : payloadFormatter(body), }, ).then(async (response) => { - const r = response as HttpResponse; - r.data = null as unknown as T; - r.error = null as unknown as E; + // Create a wrapper object that doesn't mutate the Response + // This ensures compatibility with ESM environments where Response is read-only + const r = { + data: null as unknown as T, + error: null as unknown as E, + // Delegate Response properties + ok: response.ok, + status: response.status, + statusText: response.statusText, + headers: response.headers, + url: response.url, + redirected: response.redirected, + type: response.type, + body: response.body, + bodyUsed: response.bodyUsed, + // Delegate Response methods + arrayBuffer: () => response.arrayBuffer(), + blob: () => response.blob(), + clone: () => response.clone(), + formData: () => response.formData(), + json: () => response.json(), + text: () => response.text(), + } as HttpResponse; const responseToParse = responseFormat ? response.clone() : response; const data = !responseFormat @@ -2746,9 +2766,29 @@ export class HttpClient { : payloadFormatter(body), }, ).then(async (response) => { - const r = response as HttpResponse; - r.data = null as unknown as T; - r.error = null as unknown as E; + // Create a wrapper object that doesn't mutate the Response + // This ensures compatibility with ESM environments where Response is read-only + const r = { + data: null as unknown as T, + error: null as unknown as E, + // Delegate Response properties + ok: response.ok, + status: response.status, + statusText: response.statusText, + headers: response.headers, + url: response.url, + redirected: response.redirected, + type: response.type, + body: response.body, + bodyUsed: response.bodyUsed, + // Delegate Response methods + arrayBuffer: () => response.arrayBuffer(), + blob: () => response.blob(), + clone: () => response.clone(), + formData: () => response.formData(), + json: () => response.json(), + text: () => response.text(), + } as HttpResponse; const responseToParse = responseFormat ? response.clone() : response; const data = !responseFormat @@ -3028,9 +3068,29 @@ export class HttpClient { : payloadFormatter(body), }, ).then(async (response) => { - const r = response as HttpResponse; - r.data = null as unknown as T; - r.error = null as unknown as E; + // Create a wrapper object that doesn't mutate the Response + // This ensures compatibility with ESM environments where Response is read-only + const r = { + data: null as unknown as T, + error: null as unknown as E, + // Delegate Response properties + ok: response.ok, + status: response.status, + statusText: response.statusText, + headers: response.headers, + url: response.url, + redirected: response.redirected, + type: response.type, + body: response.body, + bodyUsed: response.bodyUsed, + // Delegate Response methods + arrayBuffer: () => response.arrayBuffer(), + blob: () => response.blob(), + clone: () => response.clone(), + formData: () => response.formData(), + json: () => response.json(), + text: () => response.text(), + } as HttpResponse; const responseToParse = responseFormat ? response.clone() : response; const data = !responseFormat @@ -3319,9 +3379,29 @@ export class HttpClient { : payloadFormatter(body), }, ).then(async (response) => { - const r = response as HttpResponse; - r.data = null as unknown as T; - r.error = null as unknown as E; + // Create a wrapper object that doesn't mutate the Response + // This ensures compatibility with ESM environments where Response is read-only + const r = { + data: null as unknown as T, + error: null as unknown as E, + // Delegate Response properties + ok: response.ok, + status: response.status, + statusText: response.statusText, + headers: response.headers, + url: response.url, + redirected: response.redirected, + type: response.type, + body: response.body, + bodyUsed: response.bodyUsed, + // Delegate Response methods + arrayBuffer: () => response.arrayBuffer(), + blob: () => response.blob(), + clone: () => response.clone(), + formData: () => response.formData(), + json: () => response.json(), + text: () => response.text(), + } as HttpResponse; const responseToParse = responseFormat ? response.clone() : response; const data = !responseFormat @@ -3747,9 +3827,29 @@ export class HttpClient { : payloadFormatter(body), }, ).then(async (response) => { - const r = response as HttpResponse; - r.data = null as unknown as T; - r.error = null as unknown as E; + // Create a wrapper object that doesn't mutate the Response + // This ensures compatibility with ESM environments where Response is read-only + const r = { + data: null as unknown as T, + error: null as unknown as E, + // Delegate Response properties + ok: response.ok, + status: response.status, + statusText: response.statusText, + headers: response.headers, + url: response.url, + redirected: response.redirected, + type: response.type, + body: response.body, + bodyUsed: response.bodyUsed, + // Delegate Response methods + arrayBuffer: () => response.arrayBuffer(), + blob: () => response.blob(), + clone: () => response.clone(), + formData: () => response.formData(), + json: () => response.json(), + text: () => response.text(), + } as HttpResponse; const responseToParse = responseFormat ? response.clone() : response; const data = !responseFormat @@ -4518,9 +4618,29 @@ export class HttpClient { : payloadFormatter(body), }, ).then(async (response) => { - const r = response as HttpResponse; - r.data = null as unknown as T; - r.error = null as unknown as E; + // Create a wrapper object that doesn't mutate the Response + // This ensures compatibility with ESM environments where Response is read-only + const r = { + data: null as unknown as T, + error: null as unknown as E, + // Delegate Response properties + ok: response.ok, + status: response.status, + statusText: response.statusText, + headers: response.headers, + url: response.url, + redirected: response.redirected, + type: response.type, + body: response.body, + bodyUsed: response.bodyUsed, + // Delegate Response methods + arrayBuffer: () => response.arrayBuffer(), + blob: () => response.blob(), + clone: () => response.clone(), + formData: () => response.formData(), + json: () => response.json(), + text: () => response.text(), + } as HttpResponse; const responseToParse = responseFormat ? response.clone() : response; const data = !responseFormat @@ -4860,9 +4980,29 @@ export class HttpClient { : payloadFormatter(body), }, ).then(async (response) => { - const r = response as HttpResponse; - r.data = null as unknown as T; - r.error = null as unknown as E; + // Create a wrapper object that doesn't mutate the Response + // This ensures compatibility with ESM environments where Response is read-only + const r = { + data: null as unknown as T, + error: null as unknown as E, + // Delegate Response properties + ok: response.ok, + status: response.status, + statusText: response.statusText, + headers: response.headers, + url: response.url, + redirected: response.redirected, + type: response.type, + body: response.body, + bodyUsed: response.bodyUsed, + // Delegate Response methods + arrayBuffer: () => response.arrayBuffer(), + blob: () => response.blob(), + clone: () => response.clone(), + formData: () => response.formData(), + json: () => response.json(), + text: () => response.text(), + } as HttpResponse; const responseToParse = responseFormat ? response.clone() : response; const data = !responseFormat @@ -5158,9 +5298,29 @@ export class HttpClient { : payloadFormatter(body), }, ).then(async (response) => { - const r = response as HttpResponse; - r.data = null as unknown as T; - r.error = null as unknown as E; + // Create a wrapper object that doesn't mutate the Response + // This ensures compatibility with ESM environments where Response is read-only + const r = { + data: null as unknown as T, + error: null as unknown as E, + // Delegate Response properties + ok: response.ok, + status: response.status, + statusText: response.statusText, + headers: response.headers, + url: response.url, + redirected: response.redirected, + type: response.type, + body: response.body, + bodyUsed: response.bodyUsed, + // Delegate Response methods + arrayBuffer: () => response.arrayBuffer(), + blob: () => response.blob(), + clone: () => response.clone(), + formData: () => response.formData(), + json: () => response.json(), + text: () => response.text(), + } as HttpResponse; const responseToParse = responseFormat ? response.clone() : response; const data = !responseFormat @@ -5468,9 +5628,29 @@ export class HttpClient { : payloadFormatter(body), }, ).then(async (response) => { - const r = response as HttpResponse; - r.data = null as unknown as T; - r.error = null as unknown as E; + // Create a wrapper object that doesn't mutate the Response + // This ensures compatibility with ESM environments where Response is read-only + const r = { + data: null as unknown as T, + error: null as unknown as E, + // Delegate Response properties + ok: response.ok, + status: response.status, + statusText: response.statusText, + headers: response.headers, + url: response.url, + redirected: response.redirected, + type: response.type, + body: response.body, + bodyUsed: response.bodyUsed, + // Delegate Response methods + arrayBuffer: () => response.arrayBuffer(), + blob: () => response.blob(), + clone: () => response.clone(), + formData: () => response.formData(), + json: () => response.json(), + text: () => response.text(), + } as HttpResponse; const responseToParse = responseFormat ? response.clone() : response; const data = !responseFormat @@ -5852,9 +6032,29 @@ export class HttpClient { : payloadFormatter(body), }, ).then(async (response) => { - const r = response as HttpResponse; - r.data = null as unknown as T; - r.error = null as unknown as E; + // Create a wrapper object that doesn't mutate the Response + // This ensures compatibility with ESM environments where Response is read-only + const r = { + data: null as unknown as T, + error: null as unknown as E, + // Delegate Response properties + ok: response.ok, + status: response.status, + statusText: response.statusText, + headers: response.headers, + url: response.url, + redirected: response.redirected, + type: response.type, + body: response.body, + bodyUsed: response.bodyUsed, + // Delegate Response methods + arrayBuffer: () => response.arrayBuffer(), + blob: () => response.blob(), + clone: () => response.clone(), + formData: () => response.formData(), + json: () => response.json(), + text: () => response.text(), + } as HttpResponse; const responseToParse = responseFormat ? response.clone() : response; const data = !responseFormat @@ -6507,9 +6707,29 @@ export class HttpClient { : payloadFormatter(body), }, ).then(async (response) => { - const r = response as HttpResponse; - r.data = null as unknown as T; - r.error = null as unknown as E; + // Create a wrapper object that doesn't mutate the Response + // This ensures compatibility with ESM environments where Response is read-only + const r = { + data: null as unknown as T, + error: null as unknown as E, + // Delegate Response properties + ok: response.ok, + status: response.status, + statusText: response.statusText, + headers: response.headers, + url: response.url, + redirected: response.redirected, + type: response.type, + body: response.body, + bodyUsed: response.bodyUsed, + // Delegate Response methods + arrayBuffer: () => response.arrayBuffer(), + blob: () => response.blob(), + clone: () => response.clone(), + formData: () => response.formData(), + json: () => response.json(), + text: () => response.text(), + } as HttpResponse; const responseToParse = responseFormat ? response.clone() : response; const data = !responseFormat @@ -6822,9 +7042,29 @@ export class HttpClient { : payloadFormatter(body), }, ).then(async (response) => { - const r = response as HttpResponse; - r.data = null as unknown as T; - r.error = null as unknown as E; + // Create a wrapper object that doesn't mutate the Response + // This ensures compatibility with ESM environments where Response is read-only + const r = { + data: null as unknown as T, + error: null as unknown as E, + // Delegate Response properties + ok: response.ok, + status: response.status, + statusText: response.statusText, + headers: response.headers, + url: response.url, + redirected: response.redirected, + type: response.type, + body: response.body, + bodyUsed: response.bodyUsed, + // Delegate Response methods + arrayBuffer: () => response.arrayBuffer(), + blob: () => response.blob(), + clone: () => response.clone(), + formData: () => response.formData(), + json: () => response.json(), + text: () => response.text(), + } as HttpResponse; const responseToParse = responseFormat ? response.clone() : response; const data = !responseFormat @@ -7128,9 +7368,29 @@ export class HttpClient { : payloadFormatter(body), }, ).then(async (response) => { - const r = response as HttpResponse; - r.data = null as unknown as T; - r.error = null as unknown as E; + // Create a wrapper object that doesn't mutate the Response + // This ensures compatibility with ESM environments where Response is read-only + const r = { + data: null as unknown as T, + error: null as unknown as E, + // Delegate Response properties + ok: response.ok, + status: response.status, + statusText: response.statusText, + headers: response.headers, + url: response.url, + redirected: response.redirected, + type: response.type, + body: response.body, + bodyUsed: response.bodyUsed, + // Delegate Response methods + arrayBuffer: () => response.arrayBuffer(), + blob: () => response.blob(), + clone: () => response.clone(), + formData: () => response.formData(), + json: () => response.json(), + text: () => response.text(), + } as HttpResponse; const responseToParse = responseFormat ? response.clone() : response; const data = !responseFormat @@ -7481,9 +7741,29 @@ export class HttpClient { : payloadFormatter(body), }, ).then(async (response) => { - const r = response as HttpResponse; - r.data = null as unknown as T; - r.error = null as unknown as E; + // Create a wrapper object that doesn't mutate the Response + // This ensures compatibility with ESM environments where Response is read-only + const r = { + data: null as unknown as T, + error: null as unknown as E, + // Delegate Response properties + ok: response.ok, + status: response.status, + statusText: response.statusText, + headers: response.headers, + url: response.url, + redirected: response.redirected, + type: response.type, + body: response.body, + bodyUsed: response.bodyUsed, + // Delegate Response methods + arrayBuffer: () => response.arrayBuffer(), + blob: () => response.blob(), + clone: () => response.clone(), + formData: () => response.formData(), + json: () => response.json(), + text: () => response.text(), + } as HttpResponse; const responseToParse = responseFormat ? response.clone() : response; const data = !responseFormat @@ -7796,9 +8076,29 @@ export class HttpClient { : payloadFormatter(body), }, ).then(async (response) => { - const r = response as HttpResponse; - r.data = null as unknown as T; - r.error = null as unknown as E; + // Create a wrapper object that doesn't mutate the Response + // This ensures compatibility with ESM environments where Response is read-only + const r = { + data: null as unknown as T, + error: null as unknown as E, + // Delegate Response properties + ok: response.ok, + status: response.status, + statusText: response.statusText, + headers: response.headers, + url: response.url, + redirected: response.redirected, + type: response.type, + body: response.body, + bodyUsed: response.bodyUsed, + // Delegate Response methods + arrayBuffer: () => response.arrayBuffer(), + blob: () => response.blob(), + clone: () => response.clone(), + formData: () => response.formData(), + json: () => response.json(), + text: () => response.text(), + } as HttpResponse; const responseToParse = responseFormat ? response.clone() : response; const data = !responseFormat @@ -8125,9 +8425,29 @@ export class HttpClient { : payloadFormatter(body), }, ).then(async (response) => { - const r = response as HttpResponse; - r.data = null as unknown as T; - r.error = null as unknown as E; + // Create a wrapper object that doesn't mutate the Response + // This ensures compatibility with ESM environments where Response is read-only + const r = { + data: null as unknown as T, + error: null as unknown as E, + // Delegate Response properties + ok: response.ok, + status: response.status, + statusText: response.statusText, + headers: response.headers, + url: response.url, + redirected: response.redirected, + type: response.type, + body: response.body, + bodyUsed: response.bodyUsed, + // Delegate Response methods + arrayBuffer: () => response.arrayBuffer(), + blob: () => response.blob(), + clone: () => response.clone(), + formData: () => response.formData(), + json: () => response.json(), + text: () => response.text(), + } as HttpResponse; const responseToParse = responseFormat ? response.clone() : response; const data = !responseFormat @@ -8452,9 +8772,29 @@ export class HttpClient { : payloadFormatter(body), }, ).then(async (response) => { - const r = response as HttpResponse; - r.data = null as unknown as T; - r.error = null as unknown as E; + // Create a wrapper object that doesn't mutate the Response + // This ensures compatibility with ESM environments where Response is read-only + const r = { + data: null as unknown as T, + error: null as unknown as E, + // Delegate Response properties + ok: response.ok, + status: response.status, + statusText: response.statusText, + headers: response.headers, + url: response.url, + redirected: response.redirected, + type: response.type, + body: response.body, + bodyUsed: response.bodyUsed, + // Delegate Response methods + arrayBuffer: () => response.arrayBuffer(), + blob: () => response.blob(), + clone: () => response.clone(), + formData: () => response.formData(), + json: () => response.json(), + text: () => response.text(), + } as HttpResponse; const responseToParse = responseFormat ? response.clone() : response; const data = !responseFormat @@ -17424,9 +17764,29 @@ export class HttpClient { : payloadFormatter(body), }, ).then(async (response) => { - const r = response as HttpResponse; - r.data = null as unknown as T; - r.error = null as unknown as E; + // Create a wrapper object that doesn't mutate the Response + // This ensures compatibility with ESM environments where Response is read-only + const r = { + data: null as unknown as T, + error: null as unknown as E, + // Delegate Response properties + ok: response.ok, + status: response.status, + statusText: response.statusText, + headers: response.headers, + url: response.url, + redirected: response.redirected, + type: response.type, + body: response.body, + bodyUsed: response.bodyUsed, + // Delegate Response methods + arrayBuffer: () => response.arrayBuffer(), + blob: () => response.blob(), + clone: () => response.clone(), + formData: () => response.formData(), + json: () => response.json(), + text: () => response.text(), + } as HttpResponse; const responseToParse = responseFormat ? response.clone() : response; const data = !responseFormat @@ -38561,9 +38921,29 @@ export class HttpClient { : payloadFormatter(body), }, ).then(async (response) => { - const r = response as HttpResponse; - r.data = null as unknown as T; - r.error = null as unknown as E; + // Create a wrapper object that doesn't mutate the Response + // This ensures compatibility with ESM environments where Response is read-only + const r = { + data: null as unknown as T, + error: null as unknown as E, + // Delegate Response properties + ok: response.ok, + status: response.status, + statusText: response.statusText, + headers: response.headers, + url: response.url, + redirected: response.redirected, + type: response.type, + body: response.body, + bodyUsed: response.bodyUsed, + // Delegate Response methods + arrayBuffer: () => response.arrayBuffer(), + blob: () => response.blob(), + clone: () => response.clone(), + formData: () => response.formData(), + json: () => response.json(), + text: () => response.text(), + } as HttpResponse; const responseToParse = responseFormat ? response.clone() : response; const data = !responseFormat @@ -39137,9 +39517,29 @@ export class HttpClient { : payloadFormatter(body), }, ).then(async (response) => { - const r = response as HttpResponse; - r.data = null as unknown as T; - r.error = null as unknown as E; + // Create a wrapper object that doesn't mutate the Response + // This ensures compatibility with ESM environments where Response is read-only + const r = { + data: null as unknown as T, + error: null as unknown as E, + // Delegate Response properties + ok: response.ok, + status: response.status, + statusText: response.statusText, + headers: response.headers, + url: response.url, + redirected: response.redirected, + type: response.type, + body: response.body, + bodyUsed: response.bodyUsed, + // Delegate Response methods + arrayBuffer: () => response.arrayBuffer(), + blob: () => response.blob(), + clone: () => response.clone(), + formData: () => response.formData(), + json: () => response.json(), + text: () => response.text(), + } as HttpResponse; const responseToParse = responseFormat ? response.clone() : response; const data = !responseFormat @@ -39812,9 +40212,29 @@ export class HttpClient { : payloadFormatter(body), }, ).then(async (response) => { - const r = response as HttpResponse; - r.data = null as unknown as T; - r.error = null as unknown as E; + // Create a wrapper object that doesn't mutate the Response + // This ensures compatibility with ESM environments where Response is read-only + const r = { + data: null as unknown as T, + error: null as unknown as E, + // Delegate Response properties + ok: response.ok, + status: response.status, + statusText: response.statusText, + headers: response.headers, + url: response.url, + redirected: response.redirected, + type: response.type, + body: response.body, + bodyUsed: response.bodyUsed, + // Delegate Response methods + arrayBuffer: () => response.arrayBuffer(), + blob: () => response.blob(), + clone: () => response.clone(), + formData: () => response.formData(), + json: () => response.json(), + text: () => response.text(), + } as HttpResponse; const responseToParse = responseFormat ? response.clone() : response; const data = !responseFormat @@ -40106,9 +40526,29 @@ export class HttpClient { : payloadFormatter(body), }, ).then(async (response) => { - const r = response as HttpResponse; - r.data = null as unknown as T; - r.error = null as unknown as E; + // Create a wrapper object that doesn't mutate the Response + // This ensures compatibility with ESM environments where Response is read-only + const r = { + data: null as unknown as T, + error: null as unknown as E, + // Delegate Response properties + ok: response.ok, + status: response.status, + statusText: response.statusText, + headers: response.headers, + url: response.url, + redirected: response.redirected, + type: response.type, + body: response.body, + bodyUsed: response.bodyUsed, + // Delegate Response methods + arrayBuffer: () => response.arrayBuffer(), + blob: () => response.blob(), + clone: () => response.clone(), + formData: () => response.formData(), + json: () => response.json(), + text: () => response.text(), + } as HttpResponse; const responseToParse = responseFormat ? response.clone() : response; const data = !responseFormat @@ -40505,9 +40945,29 @@ export class HttpClient { : payloadFormatter(body), }, ).then(async (response) => { - const r = response as HttpResponse; - r.data = null as unknown as T; - r.error = null as unknown as E; + // Create a wrapper object that doesn't mutate the Response + // This ensures compatibility with ESM environments where Response is read-only + const r = { + data: null as unknown as T, + error: null as unknown as E, + // Delegate Response properties + ok: response.ok, + status: response.status, + statusText: response.statusText, + headers: response.headers, + url: response.url, + redirected: response.redirected, + type: response.type, + body: response.body, + bodyUsed: response.bodyUsed, + // Delegate Response methods + arrayBuffer: () => response.arrayBuffer(), + blob: () => response.blob(), + clone: () => response.clone(), + formData: () => response.formData(), + json: () => response.json(), + text: () => response.text(), + } as HttpResponse; const responseToParse = responseFormat ? response.clone() : response; const data = !responseFormat @@ -40793,9 +41253,29 @@ export class HttpClient { : payloadFormatter(body), }, ).then(async (response) => { - const r = response as HttpResponse; - r.data = null as unknown as T; - r.error = null as unknown as E; + // Create a wrapper object that doesn't mutate the Response + // This ensures compatibility with ESM environments where Response is read-only + const r = { + data: null as unknown as T, + error: null as unknown as E, + // Delegate Response properties + ok: response.ok, + status: response.status, + statusText: response.statusText, + headers: response.headers, + url: response.url, + redirected: response.redirected, + type: response.type, + body: response.body, + bodyUsed: response.bodyUsed, + // Delegate Response methods + arrayBuffer: () => response.arrayBuffer(), + blob: () => response.blob(), + clone: () => response.clone(), + formData: () => response.formData(), + json: () => response.json(), + text: () => response.text(), + } as HttpResponse; const responseToParse = responseFormat ? response.clone() : response; const data = !responseFormat @@ -41088,9 +41568,29 @@ export class HttpClient { : payloadFormatter(body), }, ).then(async (response) => { - const r = response as HttpResponse; - r.data = null as unknown as T; - r.error = null as unknown as E; + // Create a wrapper object that doesn't mutate the Response + // This ensures compatibility with ESM environments where Response is read-only + const r = { + data: null as unknown as T, + error: null as unknown as E, + // Delegate Response properties + ok: response.ok, + status: response.status, + statusText: response.statusText, + headers: response.headers, + url: response.url, + redirected: response.redirected, + type: response.type, + body: response.body, + bodyUsed: response.bodyUsed, + // Delegate Response methods + arrayBuffer: () => response.arrayBuffer(), + blob: () => response.blob(), + clone: () => response.clone(), + formData: () => response.formData(), + json: () => response.json(), + text: () => response.text(), + } as HttpResponse; const responseToParse = responseFormat ? response.clone() : response; const data = !responseFormat @@ -41584,9 +42084,29 @@ export class HttpClient { : payloadFormatter(body), }, ).then(async (response) => { - const r = response as HttpResponse; - r.data = null as unknown as T; - r.error = null as unknown as E; + // Create a wrapper object that doesn't mutate the Response + // This ensures compatibility with ESM environments where Response is read-only + const r = { + data: null as unknown as T, + error: null as unknown as E, + // Delegate Response properties + ok: response.ok, + status: response.status, + statusText: response.statusText, + headers: response.headers, + url: response.url, + redirected: response.redirected, + type: response.type, + body: response.body, + bodyUsed: response.bodyUsed, + // Delegate Response methods + arrayBuffer: () => response.arrayBuffer(), + blob: () => response.blob(), + clone: () => response.clone(), + formData: () => response.formData(), + json: () => response.json(), + text: () => response.text(), + } as HttpResponse; const responseToParse = responseFormat ? response.clone() : response; const data = !responseFormat @@ -42082,9 +42602,29 @@ export class HttpClient { : payloadFormatter(body), }, ).then(async (response) => { - const r = response as HttpResponse; - r.data = null as unknown as T; - r.error = null as unknown as E; + // Create a wrapper object that doesn't mutate the Response + // This ensures compatibility with ESM environments where Response is read-only + const r = { + data: null as unknown as T, + error: null as unknown as E, + // Delegate Response properties + ok: response.ok, + status: response.status, + statusText: response.statusText, + headers: response.headers, + url: response.url, + redirected: response.redirected, + type: response.type, + body: response.body, + bodyUsed: response.bodyUsed, + // Delegate Response methods + arrayBuffer: () => response.arrayBuffer(), + blob: () => response.blob(), + clone: () => response.clone(), + formData: () => response.formData(), + json: () => response.json(), + text: () => response.text(), + } as HttpResponse; const responseToParse = responseFormat ? response.clone() : response; const data = !responseFormat @@ -42436,9 +42976,29 @@ export class HttpClient { : payloadFormatter(body), }, ).then(async (response) => { - const r = response as HttpResponse; - r.data = null as unknown as T; - r.error = null as unknown as E; + // Create a wrapper object that doesn't mutate the Response + // This ensures compatibility with ESM environments where Response is read-only + const r = { + data: null as unknown as T, + error: null as unknown as E, + // Delegate Response properties + ok: response.ok, + status: response.status, + statusText: response.statusText, + headers: response.headers, + url: response.url, + redirected: response.redirected, + type: response.type, + body: response.body, + bodyUsed: response.bodyUsed, + // Delegate Response methods + arrayBuffer: () => response.arrayBuffer(), + blob: () => response.blob(), + clone: () => response.clone(), + formData: () => response.formData(), + json: () => response.json(), + text: () => response.text(), + } as HttpResponse; const responseToParse = responseFormat ? response.clone() : response; const data = !responseFormat @@ -42791,9 +43351,29 @@ export class HttpClient { : payloadFormatter(body), }, ).then(async (response) => { - const r = response as HttpResponse; - r.data = null as unknown as T; - r.error = null as unknown as E; + // Create a wrapper object that doesn't mutate the Response + // This ensures compatibility with ESM environments where Response is read-only + const r = { + data: null as unknown as T, + error: null as unknown as E, + // Delegate Response properties + ok: response.ok, + status: response.status, + statusText: response.statusText, + headers: response.headers, + url: response.url, + redirected: response.redirected, + type: response.type, + body: response.body, + bodyUsed: response.bodyUsed, + // Delegate Response methods + arrayBuffer: () => response.arrayBuffer(), + blob: () => response.blob(), + clone: () => response.clone(), + formData: () => response.formData(), + json: () => response.json(), + text: () => response.text(), + } as HttpResponse; const responseToParse = responseFormat ? response.clone() : response; const data = !responseFormat @@ -43182,9 +43762,29 @@ export class HttpClient { : payloadFormatter(body), }, ).then(async (response) => { - const r = response as HttpResponse; - r.data = null as unknown as T; - r.error = null as unknown as E; + // Create a wrapper object that doesn't mutate the Response + // This ensures compatibility with ESM environments where Response is read-only + const r = { + data: null as unknown as T, + error: null as unknown as E, + // Delegate Response properties + ok: response.ok, + status: response.status, + statusText: response.statusText, + headers: response.headers, + url: response.url, + redirected: response.redirected, + type: response.type, + body: response.body, + bodyUsed: response.bodyUsed, + // Delegate Response methods + arrayBuffer: () => response.arrayBuffer(), + blob: () => response.blob(), + clone: () => response.clone(), + formData: () => response.formData(), + json: () => response.json(), + text: () => response.text(), + } as HttpResponse; const responseToParse = responseFormat ? response.clone() : response; const data = !responseFormat @@ -43563,9 +44163,29 @@ export class HttpClient { : payloadFormatter(body), }, ).then(async (response) => { - const r = response as HttpResponse; - r.data = null as unknown as T; - r.error = null as unknown as E; + // Create a wrapper object that doesn't mutate the Response + // This ensures compatibility with ESM environments where Response is read-only + const r = { + data: null as unknown as T, + error: null as unknown as E, + // Delegate Response properties + ok: response.ok, + status: response.status, + statusText: response.statusText, + headers: response.headers, + url: response.url, + redirected: response.redirected, + type: response.type, + body: response.body, + bodyUsed: response.bodyUsed, + // Delegate Response methods + arrayBuffer: () => response.arrayBuffer(), + blob: () => response.blob(), + clone: () => response.clone(), + formData: () => response.formData(), + json: () => response.json(), + text: () => response.text(), + } as HttpResponse; const responseToParse = responseFormat ? response.clone() : response; const data = !responseFormat @@ -43887,9 +44507,29 @@ export class HttpClient { : payloadFormatter(body), }, ).then(async (response) => { - const r = response as HttpResponse; - r.data = null as unknown as T; - r.error = null as unknown as E; + // Create a wrapper object that doesn't mutate the Response + // This ensures compatibility with ESM environments where Response is read-only + const r = { + data: null as unknown as T, + error: null as unknown as E, + // Delegate Response properties + ok: response.ok, + status: response.status, + statusText: response.statusText, + headers: response.headers, + url: response.url, + redirected: response.redirected, + type: response.type, + body: response.body, + bodyUsed: response.bodyUsed, + // Delegate Response methods + arrayBuffer: () => response.arrayBuffer(), + blob: () => response.blob(), + clone: () => response.clone(), + formData: () => response.formData(), + json: () => response.json(), + text: () => response.text(), + } as HttpResponse; const responseToParse = responseFormat ? response.clone() : response; const data = !responseFormat @@ -44303,9 +44943,29 @@ export class HttpClient { : payloadFormatter(body), }, ).then(async (response) => { - const r = response as HttpResponse; - r.data = null as unknown as T; - r.error = null as unknown as E; + // Create a wrapper object that doesn't mutate the Response + // This ensures compatibility with ESM environments where Response is read-only + const r = { + data: null as unknown as T, + error: null as unknown as E, + // Delegate Response properties + ok: response.ok, + status: response.status, + statusText: response.statusText, + headers: response.headers, + url: response.url, + redirected: response.redirected, + type: response.type, + body: response.body, + bodyUsed: response.bodyUsed, + // Delegate Response methods + arrayBuffer: () => response.arrayBuffer(), + blob: () => response.blob(), + clone: () => response.clone(), + formData: () => response.formData(), + json: () => response.json(), + text: () => response.text(), + } as HttpResponse; const responseToParse = responseFormat ? response.clone() : response; const data = !responseFormat @@ -44995,9 +45655,29 @@ export class HttpClient { : payloadFormatter(body), }, ).then(async (response) => { - const r = response as HttpResponse; - r.data = null as unknown as T; - r.error = null as unknown as E; + // Create a wrapper object that doesn't mutate the Response + // This ensures compatibility with ESM environments where Response is read-only + const r = { + data: null as unknown as T, + error: null as unknown as E, + // Delegate Response properties + ok: response.ok, + status: response.status, + statusText: response.statusText, + headers: response.headers, + url: response.url, + redirected: response.redirected, + type: response.type, + body: response.body, + bodyUsed: response.bodyUsed, + // Delegate Response methods + arrayBuffer: () => response.arrayBuffer(), + blob: () => response.blob(), + clone: () => response.clone(), + formData: () => response.formData(), + json: () => response.json(), + text: () => response.text(), + } as HttpResponse; const responseToParse = responseFormat ? response.clone() : response; const data = !responseFormat @@ -45351,9 +46031,29 @@ export class HttpClient { : payloadFormatter(body), }, ).then(async (response) => { - const r = response as HttpResponse; - r.data = null as unknown as T; - r.error = null as unknown as E; + // Create a wrapper object that doesn't mutate the Response + // This ensures compatibility with ESM environments where Response is read-only + const r = { + data: null as unknown as T, + error: null as unknown as E, + // Delegate Response properties + ok: response.ok, + status: response.status, + statusText: response.statusText, + headers: response.headers, + url: response.url, + redirected: response.redirected, + type: response.type, + body: response.body, + bodyUsed: response.bodyUsed, + // Delegate Response methods + arrayBuffer: () => response.arrayBuffer(), + blob: () => response.blob(), + clone: () => response.clone(), + formData: () => response.formData(), + json: () => response.json(), + text: () => response.text(), + } as HttpResponse; const responseToParse = responseFormat ? response.clone() : response; const data = !responseFormat @@ -45671,9 +46371,29 @@ export class HttpClient { : payloadFormatter(body), }, ).then(async (response) => { - const r = response as HttpResponse; - r.data = null as unknown as T; - r.error = null as unknown as E; + // Create a wrapper object that doesn't mutate the Response + // This ensures compatibility with ESM environments where Response is read-only + const r = { + data: null as unknown as T, + error: null as unknown as E, + // Delegate Response properties + ok: response.ok, + status: response.status, + statusText: response.statusText, + headers: response.headers, + url: response.url, + redirected: response.redirected, + type: response.type, + body: response.body, + bodyUsed: response.bodyUsed, + // Delegate Response methods + arrayBuffer: () => response.arrayBuffer(), + blob: () => response.blob(), + clone: () => response.clone(), + formData: () => response.formData(), + json: () => response.json(), + text: () => response.text(), + } as HttpResponse; const responseToParse = responseFormat ? response.clone() : response; const data = !responseFormat @@ -45948,9 +46668,29 @@ export class HttpClient { : payloadFormatter(body), }, ).then(async (response) => { - const r = response as HttpResponse; - r.data = null as unknown as T; - r.error = null as unknown as E; + // Create a wrapper object that doesn't mutate the Response + // This ensures compatibility with ESM environments where Response is read-only + const r = { + data: null as unknown as T, + error: null as unknown as E, + // Delegate Response properties + ok: response.ok, + status: response.status, + statusText: response.statusText, + headers: response.headers, + url: response.url, + redirected: response.redirected, + type: response.type, + body: response.body, + bodyUsed: response.bodyUsed, + // Delegate Response methods + arrayBuffer: () => response.arrayBuffer(), + blob: () => response.blob(), + clone: () => response.clone(), + formData: () => response.formData(), + json: () => response.json(), + text: () => response.text(), + } as HttpResponse; const responseToParse = responseFormat ? response.clone() : response; const data = !responseFormat @@ -46250,9 +46990,29 @@ export class HttpClient { : payloadFormatter(body), }, ).then(async (response) => { - const r = response as HttpResponse; - r.data = null as unknown as T; - r.error = null as unknown as E; + // Create a wrapper object that doesn't mutate the Response + // This ensures compatibility with ESM environments where Response is read-only + const r = { + data: null as unknown as T, + error: null as unknown as E, + // Delegate Response properties + ok: response.ok, + status: response.status, + statusText: response.statusText, + headers: response.headers, + url: response.url, + redirected: response.redirected, + type: response.type, + body: response.body, + bodyUsed: response.bodyUsed, + // Delegate Response methods + arrayBuffer: () => response.arrayBuffer(), + blob: () => response.blob(), + clone: () => response.clone(), + formData: () => response.formData(), + json: () => response.json(), + text: () => response.text(), + } as HttpResponse; const responseToParse = responseFormat ? response.clone() : response; const data = !responseFormat @@ -46675,9 +47435,29 @@ export class HttpClient { : payloadFormatter(body), }, ).then(async (response) => { - const r = response as HttpResponse; - r.data = null as unknown as T; - r.error = null as unknown as E; + // Create a wrapper object that doesn't mutate the Response + // This ensures compatibility with ESM environments where Response is read-only + const r = { + data: null as unknown as T, + error: null as unknown as E, + // Delegate Response properties + ok: response.ok, + status: response.status, + statusText: response.statusText, + headers: response.headers, + url: response.url, + redirected: response.redirected, + type: response.type, + body: response.body, + bodyUsed: response.bodyUsed, + // Delegate Response methods + arrayBuffer: () => response.arrayBuffer(), + blob: () => response.blob(), + clone: () => response.clone(), + formData: () => response.formData(), + json: () => response.json(), + text: () => response.text(), + } as HttpResponse; const responseToParse = responseFormat ? response.clone() : response; const data = !responseFormat @@ -47326,9 +48106,29 @@ export class HttpClient { : payloadFormatter(body), }, ).then(async (response) => { - const r = response as HttpResponse; - r.data = null as unknown as T; - r.error = null as unknown as E; + // Create a wrapper object that doesn't mutate the Response + // This ensures compatibility with ESM environments where Response is read-only + const r = { + data: null as unknown as T, + error: null as unknown as E, + // Delegate Response properties + ok: response.ok, + status: response.status, + statusText: response.statusText, + headers: response.headers, + url: response.url, + redirected: response.redirected, + type: response.type, + body: response.body, + bodyUsed: response.bodyUsed, + // Delegate Response methods + arrayBuffer: () => response.arrayBuffer(), + blob: () => response.blob(), + clone: () => response.clone(), + formData: () => response.formData(), + json: () => response.json(), + text: () => response.text(), + } as HttpResponse; const responseToParse = responseFormat ? response.clone() : response; const data = !responseFormat @@ -48513,9 +49313,29 @@ export class HttpClient { : payloadFormatter(body), }, ).then(async (response) => { - const r = response as HttpResponse; - r.data = null as unknown as T; - r.error = null as unknown as E; + // Create a wrapper object that doesn't mutate the Response + // This ensures compatibility with ESM environments where Response is read-only + const r = { + data: null as unknown as T, + error: null as unknown as E, + // Delegate Response properties + ok: response.ok, + status: response.status, + statusText: response.statusText, + headers: response.headers, + url: response.url, + redirected: response.redirected, + type: response.type, + body: response.body, + bodyUsed: response.bodyUsed, + // Delegate Response methods + arrayBuffer: () => response.arrayBuffer(), + blob: () => response.blob(), + clone: () => response.clone(), + formData: () => response.formData(), + json: () => response.json(), + text: () => response.text(), + } as HttpResponse; const responseToParse = responseFormat ? response.clone() : response; const data = !responseFormat @@ -49306,9 +50126,29 @@ export class HttpClient { : payloadFormatter(body), }, ).then(async (response) => { - const r = response as HttpResponse; - r.data = null as unknown as T; - r.error = null as unknown as E; + // Create a wrapper object that doesn't mutate the Response + // This ensures compatibility with ESM environments where Response is read-only + const r = { + data: null as unknown as T, + error: null as unknown as E, + // Delegate Response properties + ok: response.ok, + status: response.status, + statusText: response.statusText, + headers: response.headers, + url: response.url, + redirected: response.redirected, + type: response.type, + body: response.body, + bodyUsed: response.bodyUsed, + // Delegate Response methods + arrayBuffer: () => response.arrayBuffer(), + blob: () => response.blob(), + clone: () => response.clone(), + formData: () => response.formData(), + json: () => response.json(), + text: () => response.text(), + } as HttpResponse; const responseToParse = responseFormat ? response.clone() : response; const data = !responseFormat @@ -49671,9 +50511,29 @@ export class HttpClient { : payloadFormatter(body), }, ).then(async (response) => { - const r = response as HttpResponse; - r.data = null as unknown as T; - r.error = null as unknown as E; + // Create a wrapper object that doesn't mutate the Response + // This ensures compatibility with ESM environments where Response is read-only + const r = { + data: null as unknown as T, + error: null as unknown as E, + // Delegate Response properties + ok: response.ok, + status: response.status, + statusText: response.statusText, + headers: response.headers, + url: response.url, + redirected: response.redirected, + type: response.type, + body: response.body, + bodyUsed: response.bodyUsed, + // Delegate Response methods + arrayBuffer: () => response.arrayBuffer(), + blob: () => response.blob(), + clone: () => response.clone(), + formData: () => response.formData(), + json: () => response.json(), + text: () => response.text(), + } as HttpResponse; const responseToParse = responseFormat ? response.clone() : response; const data = !responseFormat @@ -49973,9 +50833,29 @@ export class HttpClient { : payloadFormatter(body), }, ).then(async (response) => { - const r = response as HttpResponse; - r.data = null as unknown as T; - r.error = null as unknown as E; + // Create a wrapper object that doesn't mutate the Response + // This ensures compatibility with ESM environments where Response is read-only + const r = { + data: null as unknown as T, + error: null as unknown as E, + // Delegate Response properties + ok: response.ok, + status: response.status, + statusText: response.statusText, + headers: response.headers, + url: response.url, + redirected: response.redirected, + type: response.type, + body: response.body, + bodyUsed: response.bodyUsed, + // Delegate Response methods + arrayBuffer: () => response.arrayBuffer(), + blob: () => response.blob(), + clone: () => response.clone(), + formData: () => response.formData(), + json: () => response.json(), + text: () => response.text(), + } as HttpResponse; const responseToParse = responseFormat ? response.clone() : response; const data = !responseFormat diff --git a/tests/spec/another-query-params/__snapshots__/basic.test.ts.snap b/tests/spec/another-query-params/__snapshots__/basic.test.ts.snap index f987d808..65347a71 100644 --- a/tests/spec/another-query-params/__snapshots__/basic.test.ts.snap +++ b/tests/spec/another-query-params/__snapshots__/basic.test.ts.snap @@ -265,9 +265,29 @@ export class HttpClient { : payloadFormatter(body), }, ).then(async (response) => { - const r = response as HttpResponse; - r.data = null as unknown as T; - r.error = null as unknown as E; + // Create a wrapper object that doesn't mutate the Response + // This ensures compatibility with ESM environments where Response is read-only + const r = { + data: null as unknown as T, + error: null as unknown as E, + // Delegate Response properties + ok: response.ok, + status: response.status, + statusText: response.statusText, + headers: response.headers, + url: response.url, + redirected: response.redirected, + type: response.type, + body: response.body, + bodyUsed: response.bodyUsed, + // Delegate Response methods + arrayBuffer: () => response.arrayBuffer(), + blob: () => response.blob(), + clone: () => response.clone(), + formData: () => response.formData(), + json: () => response.json(), + text: () => response.text(), + } as HttpResponse; const responseToParse = responseFormat ? response.clone() : response; const data = !responseFormat diff --git a/tests/spec/custom-extensions/__snapshots__/basic.test.ts.snap b/tests/spec/custom-extensions/__snapshots__/basic.test.ts.snap index aedb9d00..c879965d 100644 --- a/tests/spec/custom-extensions/__snapshots__/basic.test.ts.snap +++ b/tests/spec/custom-extensions/__snapshots__/basic.test.ts.snap @@ -237,9 +237,29 @@ export class HttpClient { : payloadFormatter(body), }, ).then(async (response) => { - const r = response as HttpResponse; - r.data = null as unknown as T; - r.error = null as unknown as E; + // Create a wrapper object that doesn't mutate the Response + // This ensures compatibility with ESM environments where Response is read-only + const r = { + data: null as unknown as T, + error: null as unknown as E, + // Delegate Response properties + ok: response.ok, + status: response.status, + statusText: response.statusText, + headers: response.headers, + url: response.url, + redirected: response.redirected, + type: response.type, + body: response.body, + bodyUsed: response.bodyUsed, + // Delegate Response methods + arrayBuffer: () => response.arrayBuffer(), + blob: () => response.blob(), + clone: () => response.clone(), + formData: () => response.formData(), + json: () => response.json(), + text: () => response.text(), + } as HttpResponse; const responseToParse = responseFormat ? response.clone() : response; const data = !responseFormat diff --git a/tests/spec/defaultAsSuccess/__snapshots__/basic.test.ts.snap b/tests/spec/defaultAsSuccess/__snapshots__/basic.test.ts.snap index 3b138631..f3e5a02f 100644 --- a/tests/spec/defaultAsSuccess/__snapshots__/basic.test.ts.snap +++ b/tests/spec/defaultAsSuccess/__snapshots__/basic.test.ts.snap @@ -277,9 +277,29 @@ export class HttpClient { : payloadFormatter(body), }, ).then(async (response) => { - const r = response as HttpResponse; - r.data = null as unknown as T; - r.error = null as unknown as E; + // Create a wrapper object that doesn't mutate the Response + // This ensures compatibility with ESM environments where Response is read-only + const r = { + data: null as unknown as T, + error: null as unknown as E, + // Delegate Response properties + ok: response.ok, + status: response.status, + statusText: response.statusText, + headers: response.headers, + url: response.url, + redirected: response.redirected, + type: response.type, + body: response.body, + bodyUsed: response.bodyUsed, + // Delegate Response methods + arrayBuffer: () => response.arrayBuffer(), + blob: () => response.blob(), + clone: () => response.clone(), + formData: () => response.formData(), + json: () => response.json(), + text: () => response.text(), + } as HttpResponse; const responseToParse = responseFormat ? response.clone() : response; const data = !responseFormat diff --git a/tests/spec/defaultResponse/__snapshots__/basic.test.ts.snap b/tests/spec/defaultResponse/__snapshots__/basic.test.ts.snap index a2198338..4cda2433 100644 --- a/tests/spec/defaultResponse/__snapshots__/basic.test.ts.snap +++ b/tests/spec/defaultResponse/__snapshots__/basic.test.ts.snap @@ -237,9 +237,29 @@ export class HttpClient { : payloadFormatter(body), }, ).then(async (response) => { - const r = response as HttpResponse; - r.data = null as unknown as T; - r.error = null as unknown as E; + // Create a wrapper object that doesn't mutate the Response + // This ensures compatibility with ESM environments where Response is read-only + const r = { + data: null as unknown as T, + error: null as unknown as E, + // Delegate Response properties + ok: response.ok, + status: response.status, + statusText: response.statusText, + headers: response.headers, + url: response.url, + redirected: response.redirected, + type: response.type, + body: response.body, + bodyUsed: response.bodyUsed, + // Delegate Response methods + arrayBuffer: () => response.arrayBuffer(), + blob: () => response.blob(), + clone: () => response.clone(), + formData: () => response.formData(), + json: () => response.json(), + text: () => response.text(), + } as HttpResponse; const responseToParse = responseFormat ? response.clone() : response; const data = !responseFormat diff --git a/tests/spec/deprecated/__snapshots__/basic.test.ts.snap b/tests/spec/deprecated/__snapshots__/basic.test.ts.snap index a8e4b05d..221243ac 100644 --- a/tests/spec/deprecated/__snapshots__/basic.test.ts.snap +++ b/tests/spec/deprecated/__snapshots__/basic.test.ts.snap @@ -237,9 +237,29 @@ export class HttpClient { : payloadFormatter(body), }, ).then(async (response) => { - const r = response as HttpResponse; - r.data = null as unknown as T; - r.error = null as unknown as E; + // Create a wrapper object that doesn't mutate the Response + // This ensures compatibility with ESM environments where Response is read-only + const r = { + data: null as unknown as T, + error: null as unknown as E, + // Delegate Response properties + ok: response.ok, + status: response.status, + statusText: response.statusText, + headers: response.headers, + url: response.url, + redirected: response.redirected, + type: response.type, + body: response.body, + bodyUsed: response.bodyUsed, + // Delegate Response methods + arrayBuffer: () => response.arrayBuffer(), + blob: () => response.blob(), + clone: () => response.clone(), + formData: () => response.formData(), + json: () => response.json(), + text: () => response.text(), + } as HttpResponse; const responseToParse = responseFormat ? response.clone() : response; const data = !responseFormat diff --git a/tests/spec/dot-path-params/__snapshots__/basic.test.ts.snap b/tests/spec/dot-path-params/__snapshots__/basic.test.ts.snap index 161782a2..dbc7735a 100644 --- a/tests/spec/dot-path-params/__snapshots__/basic.test.ts.snap +++ b/tests/spec/dot-path-params/__snapshots__/basic.test.ts.snap @@ -239,9 +239,29 @@ export class HttpClient { : payloadFormatter(body), }, ).then(async (response) => { - const r = response as HttpResponse; - r.data = null as unknown as T; - r.error = null as unknown as E; + // Create a wrapper object that doesn't mutate the Response + // This ensures compatibility with ESM environments where Response is read-only + const r = { + data: null as unknown as T, + error: null as unknown as E, + // Delegate Response properties + ok: response.ok, + status: response.status, + statusText: response.statusText, + headers: response.headers, + url: response.url, + redirected: response.redirected, + type: response.type, + body: response.body, + bodyUsed: response.bodyUsed, + // Delegate Response methods + arrayBuffer: () => response.arrayBuffer(), + blob: () => response.blob(), + clone: () => response.clone(), + formData: () => response.formData(), + json: () => response.json(), + text: () => response.text(), + } as HttpResponse; const responseToParse = responseFormat ? response.clone() : response; const data = !responseFormat diff --git a/tests/spec/enumNamesAsValues/__snapshots__/basic.test.ts.snap b/tests/spec/enumNamesAsValues/__snapshots__/basic.test.ts.snap index 626a368e..ab50f685 100644 --- a/tests/spec/enumNamesAsValues/__snapshots__/basic.test.ts.snap +++ b/tests/spec/enumNamesAsValues/__snapshots__/basic.test.ts.snap @@ -429,9 +429,29 @@ export class HttpClient { : payloadFormatter(body), }, ).then(async (response) => { - const r = response as HttpResponse; - r.data = null as unknown as T; - r.error = null as unknown as E; + // Create a wrapper object that doesn't mutate the Response + // This ensures compatibility with ESM environments where Response is read-only + const r = { + data: null as unknown as T, + error: null as unknown as E, + // Delegate Response properties + ok: response.ok, + status: response.status, + statusText: response.statusText, + headers: response.headers, + url: response.url, + redirected: response.redirected, + type: response.type, + body: response.body, + bodyUsed: response.bodyUsed, + // Delegate Response methods + arrayBuffer: () => response.arrayBuffer(), + blob: () => response.blob(), + clone: () => response.clone(), + formData: () => response.formData(), + json: () => response.json(), + text: () => response.text(), + } as HttpResponse; const responseToParse = responseFormat ? response.clone() : response; const data = !responseFormat diff --git a/tests/spec/enumNamesAsValues/__snapshots__/inline.test.ts.snap b/tests/spec/enumNamesAsValues/__snapshots__/inline.test.ts.snap index 816ee868..25f0776d 100644 --- a/tests/spec/enumNamesAsValues/__snapshots__/inline.test.ts.snap +++ b/tests/spec/enumNamesAsValues/__snapshots__/inline.test.ts.snap @@ -249,9 +249,29 @@ export class HttpClient { : payloadFormatter(body), }, ).then(async (response) => { - const r = response as HttpResponse; - r.data = null as unknown as T; - r.error = null as unknown as E; + // Create a wrapper object that doesn't mutate the Response + // This ensures compatibility with ESM environments where Response is read-only + const r = { + data: null as unknown as T, + error: null as unknown as E, + // Delegate Response properties + ok: response.ok, + status: response.status, + statusText: response.statusText, + headers: response.headers, + url: response.url, + redirected: response.redirected, + type: response.type, + body: response.body, + bodyUsed: response.bodyUsed, + // Delegate Response methods + arrayBuffer: () => response.arrayBuffer(), + blob: () => response.blob(), + clone: () => response.clone(), + formData: () => response.formData(), + json: () => response.json(), + text: () => response.text(), + } as HttpResponse; const responseToParse = responseFormat ? response.clone() : response; const data = !responseFormat diff --git a/tests/spec/enumNotFirstInComponents/__snapshots__/basic.test.ts.snap b/tests/spec/enumNotFirstInComponents/__snapshots__/basic.test.ts.snap index ed22a3bd..00dca337 100644 --- a/tests/spec/enumNotFirstInComponents/__snapshots__/basic.test.ts.snap +++ b/tests/spec/enumNotFirstInComponents/__snapshots__/basic.test.ts.snap @@ -267,9 +267,29 @@ export class HttpClient { : payloadFormatter(body), }, ).then(async (response) => { - const r = response as HttpResponse; - r.data = null as unknown as T; - r.error = null as unknown as E; + // Create a wrapper object that doesn't mutate the Response + // This ensures compatibility with ESM environments where Response is read-only + const r = { + data: null as unknown as T, + error: null as unknown as E, + // Delegate Response properties + ok: response.ok, + status: response.status, + statusText: response.statusText, + headers: response.headers, + url: response.url, + redirected: response.redirected, + type: response.type, + body: response.body, + bodyUsed: response.bodyUsed, + // Delegate Response methods + arrayBuffer: () => response.arrayBuffer(), + blob: () => response.blob(), + clone: () => response.clone(), + formData: () => response.formData(), + json: () => response.json(), + text: () => response.text(), + } as HttpResponse; const responseToParse = responseFormat ? response.clone() : response; const data = !responseFormat diff --git a/tests/spec/extractRequestBody/__snapshots__/basic.test.ts.snap b/tests/spec/extractRequestBody/__snapshots__/basic.test.ts.snap index f34bbe52..46b2db76 100644 --- a/tests/spec/extractRequestBody/__snapshots__/basic.test.ts.snap +++ b/tests/spec/extractRequestBody/__snapshots__/basic.test.ts.snap @@ -408,9 +408,29 @@ export class HttpClient { : payloadFormatter(body), }, ).then(async (response) => { - const r = response as HttpResponse; - r.data = null as unknown as T; - r.error = null as unknown as E; + // Create a wrapper object that doesn't mutate the Response + // This ensures compatibility with ESM environments where Response is read-only + const r = { + data: null as unknown as T, + error: null as unknown as E, + // Delegate Response properties + ok: response.ok, + status: response.status, + statusText: response.statusText, + headers: response.headers, + url: response.url, + redirected: response.redirected, + type: response.type, + body: response.body, + bodyUsed: response.bodyUsed, + // Delegate Response methods + arrayBuffer: () => response.arrayBuffer(), + blob: () => response.blob(), + clone: () => response.clone(), + formData: () => response.formData(), + json: () => response.json(), + text: () => response.text(), + } as HttpResponse; const responseToParse = responseFormat ? response.clone() : response; const data = !responseFormat diff --git a/tests/spec/extractRequestParams/__snapshots__/basic.test.ts.snap b/tests/spec/extractRequestParams/__snapshots__/basic.test.ts.snap index 985bf2f2..40cd642c 100644 --- a/tests/spec/extractRequestParams/__snapshots__/basic.test.ts.snap +++ b/tests/spec/extractRequestParams/__snapshots__/basic.test.ts.snap @@ -367,9 +367,29 @@ export class HttpClient { : payloadFormatter(body), }, ).then(async (response) => { - const r = response as HttpResponse; - r.data = null as unknown as T; - r.error = null as unknown as E; + // Create a wrapper object that doesn't mutate the Response + // This ensures compatibility with ESM environments where Response is read-only + const r = { + data: null as unknown as T, + error: null as unknown as E, + // Delegate Response properties + ok: response.ok, + status: response.status, + statusText: response.statusText, + headers: response.headers, + url: response.url, + redirected: response.redirected, + type: response.type, + body: response.body, + bodyUsed: response.bodyUsed, + // Delegate Response methods + arrayBuffer: () => response.arrayBuffer(), + blob: () => response.blob(), + clone: () => response.clone(), + formData: () => response.formData(), + json: () => response.json(), + text: () => response.text(), + } as HttpResponse; const responseToParse = responseFormat ? response.clone() : response; const data = !responseFormat diff --git a/tests/spec/extractResponseBody/__snapshots__/basic.test.ts.snap b/tests/spec/extractResponseBody/__snapshots__/basic.test.ts.snap index eaf33c1d..6de7acbc 100644 --- a/tests/spec/extractResponseBody/__snapshots__/basic.test.ts.snap +++ b/tests/spec/extractResponseBody/__snapshots__/basic.test.ts.snap @@ -392,9 +392,29 @@ export class HttpClient { : payloadFormatter(body), }, ).then(async (response) => { - const r = response as HttpResponse; - r.data = null as unknown as T; - r.error = null as unknown as E; + // Create a wrapper object that doesn't mutate the Response + // This ensures compatibility with ESM environments where Response is read-only + const r = { + data: null as unknown as T, + error: null as unknown as E, + // Delegate Response properties + ok: response.ok, + status: response.status, + statusText: response.statusText, + headers: response.headers, + url: response.url, + redirected: response.redirected, + type: response.type, + body: response.body, + bodyUsed: response.bodyUsed, + // Delegate Response methods + arrayBuffer: () => response.arrayBuffer(), + blob: () => response.blob(), + clone: () => response.clone(), + formData: () => response.formData(), + json: () => response.json(), + text: () => response.text(), + } as HttpResponse; const responseToParse = responseFormat ? response.clone() : response; const data = !responseFormat diff --git a/tests/spec/extractResponseError/__snapshots__/basic.test.ts.snap b/tests/spec/extractResponseError/__snapshots__/basic.test.ts.snap index e4a3e4f2..1d2bb6da 100644 --- a/tests/spec/extractResponseError/__snapshots__/basic.test.ts.snap +++ b/tests/spec/extractResponseError/__snapshots__/basic.test.ts.snap @@ -387,9 +387,29 @@ export class HttpClient { : payloadFormatter(body), }, ).then(async (response) => { - const r = response as HttpResponse; - r.data = null as unknown as T; - r.error = null as unknown as E; + // Create a wrapper object that doesn't mutate the Response + // This ensures compatibility with ESM environments where Response is read-only + const r = { + data: null as unknown as T, + error: null as unknown as E, + // Delegate Response properties + ok: response.ok, + status: response.status, + statusText: response.statusText, + headers: response.headers, + url: response.url, + redirected: response.redirected, + type: response.type, + body: response.body, + bodyUsed: response.bodyUsed, + // Delegate Response methods + arrayBuffer: () => response.arrayBuffer(), + blob: () => response.blob(), + clone: () => response.clone(), + formData: () => response.formData(), + json: () => response.json(), + text: () => response.text(), + } as HttpResponse; const responseToParse = responseFormat ? response.clone() : response; const data = !responseFormat diff --git a/tests/spec/jsAxios/__snapshots__/basic.test.ts.snap b/tests/spec/jsAxios/__snapshots__/basic.test.ts.snap index 0b4dbc53..650334b6 100644 --- a/tests/spec/jsAxios/__snapshots__/basic.test.ts.snap +++ b/tests/spec/jsAxios/__snapshots__/basic.test.ts.snap @@ -170,9 +170,29 @@ export class HttpClient { : payloadFormatter(body), }, ).then(async (response) => { - const r = response; - r.data = null; - r.error = null; + // Create a wrapper object that doesn't mutate the Response + // This ensures compatibility with ESM environments where Response is read-only + const r = { + data: null, + error: null, + // Delegate Response properties + ok: response.ok, + status: response.status, + statusText: response.statusText, + headers: response.headers, + url: response.url, + redirected: response.redirected, + type: response.type, + body: response.body, + bodyUsed: response.bodyUsed, + // Delegate Response methods + arrayBuffer: () => response.arrayBuffer(), + blob: () => response.blob(), + clone: () => response.clone(), + formData: () => response.formData(), + json: () => response.json(), + text: () => response.text(), + }; const responseToParse = responseFormat ? response.clone() : response; const data = !responseFormat ? r diff --git a/tests/spec/jsonapi-media-type/__snapshots__/basic.test.ts.snap b/tests/spec/jsonapi-media-type/__snapshots__/basic.test.ts.snap index 5f4c7ab8..c1f494dc 100644 --- a/tests/spec/jsonapi-media-type/__snapshots__/basic.test.ts.snap +++ b/tests/spec/jsonapi-media-type/__snapshots__/basic.test.ts.snap @@ -263,9 +263,29 @@ export class HttpClient { : payloadFormatter(body), }, ).then(async (response) => { - const r = response as HttpResponse; - r.data = null as unknown as T; - r.error = null as unknown as E; + // Create a wrapper object that doesn't mutate the Response + // This ensures compatibility with ESM environments where Response is read-only + const r = { + data: null as unknown as T, + error: null as unknown as E, + // Delegate Response properties + ok: response.ok, + status: response.status, + statusText: response.statusText, + headers: response.headers, + url: response.url, + redirected: response.redirected, + type: response.type, + body: response.body, + bodyUsed: response.bodyUsed, + // Delegate Response methods + arrayBuffer: () => response.arrayBuffer(), + blob: () => response.blob(), + clone: () => response.clone(), + formData: () => response.formData(), + json: () => response.json(), + text: () => response.text(), + } as HttpResponse; const responseToParse = responseFormat ? response.clone() : response; const data = !responseFormat diff --git a/tests/spec/moduleNameFirstTag/__snapshots__/basic.test.ts.snap b/tests/spec/moduleNameFirstTag/__snapshots__/basic.test.ts.snap index 347ca8d6..6982078d 100644 --- a/tests/spec/moduleNameFirstTag/__snapshots__/basic.test.ts.snap +++ b/tests/spec/moduleNameFirstTag/__snapshots__/basic.test.ts.snap @@ -362,9 +362,29 @@ export class HttpClient { : payloadFormatter(body), }, ).then(async (response) => { - const r = response as HttpResponse; - r.data = null as unknown as T; - r.error = null as unknown as E; + // Create a wrapper object that doesn't mutate the Response + // This ensures compatibility with ESM environments where Response is read-only + const r = { + data: null as unknown as T, + error: null as unknown as E, + // Delegate Response properties + ok: response.ok, + status: response.status, + statusText: response.statusText, + headers: response.headers, + url: response.url, + redirected: response.redirected, + type: response.type, + body: response.body, + bodyUsed: response.bodyUsed, + // Delegate Response methods + arrayBuffer: () => response.arrayBuffer(), + blob: () => response.blob(), + clone: () => response.clone(), + formData: () => response.formData(), + json: () => response.json(), + text: () => response.text(), + } as HttpResponse; const responseToParse = responseFormat ? response.clone() : response; const data = !responseFormat diff --git a/tests/spec/moduleNameIndex/__snapshots__/basic.test.ts.snap b/tests/spec/moduleNameIndex/__snapshots__/basic.test.ts.snap index fe0d3c47..91f62c5d 100644 --- a/tests/spec/moduleNameIndex/__snapshots__/basic.test.ts.snap +++ b/tests/spec/moduleNameIndex/__snapshots__/basic.test.ts.snap @@ -362,9 +362,29 @@ export class HttpClient { : payloadFormatter(body), }, ).then(async (response) => { - const r = response as HttpResponse; - r.data = null as unknown as T; - r.error = null as unknown as E; + // Create a wrapper object that doesn't mutate the Response + // This ensures compatibility with ESM environments where Response is read-only + const r = { + data: null as unknown as T, + error: null as unknown as E, + // Delegate Response properties + ok: response.ok, + status: response.status, + statusText: response.statusText, + headers: response.headers, + url: response.url, + redirected: response.redirected, + type: response.type, + body: response.body, + bodyUsed: response.bodyUsed, + // Delegate Response methods + arrayBuffer: () => response.arrayBuffer(), + blob: () => response.blob(), + clone: () => response.clone(), + formData: () => response.formData(), + json: () => response.json(), + text: () => response.text(), + } as HttpResponse; const responseToParse = responseFormat ? response.clone() : response; const data = !responseFormat diff --git a/tests/spec/on-insert-path-param/__snapshots__/basic.test.ts.snap b/tests/spec/on-insert-path-param/__snapshots__/basic.test.ts.snap index 9328e352..b44091ac 100644 --- a/tests/spec/on-insert-path-param/__snapshots__/basic.test.ts.snap +++ b/tests/spec/on-insert-path-param/__snapshots__/basic.test.ts.snap @@ -237,9 +237,29 @@ export class HttpClient { : payloadFormatter(body), }, ).then(async (response) => { - const r = response as HttpResponse; - r.data = null as unknown as T; - r.error = null as unknown as E; + // Create a wrapper object that doesn't mutate the Response + // This ensures compatibility with ESM environments where Response is read-only + const r = { + data: null as unknown as T, + error: null as unknown as E, + // Delegate Response properties + ok: response.ok, + status: response.status, + statusText: response.statusText, + headers: response.headers, + url: response.url, + redirected: response.redirected, + type: response.type, + body: response.body, + bodyUsed: response.bodyUsed, + // Delegate Response methods + arrayBuffer: () => response.arrayBuffer(), + blob: () => response.blob(), + clone: () => response.clone(), + formData: () => response.formData(), + json: () => response.json(), + text: () => response.text(), + } as HttpResponse; const responseToParse = responseFormat ? response.clone() : response; const data = !responseFormat diff --git a/tests/spec/operationId-starting-with-number/__snapshots__/basic.test.ts.snap b/tests/spec/operationId-starting-with-number/__snapshots__/basic.test.ts.snap index d1b17a5a..adaa1cc4 100644 --- a/tests/spec/operationId-starting-with-number/__snapshots__/basic.test.ts.snap +++ b/tests/spec/operationId-starting-with-number/__snapshots__/basic.test.ts.snap @@ -258,9 +258,29 @@ export class HttpClient { body: typeof body === "undefined" || body === null ? null : payloadFormatter(body), } ).then(async (response) => { - const r = response as HttpResponse; - r.data = (null as unknown) as T; - r.error = (null as unknown) as E; + // Create a wrapper object that doesn't mutate the Response + // This ensures compatibility with ESM environments where Response is read-only + const r = { + data: (null as unknown) as T, + error: (null as unknown) as E, + // Delegate Response properties + ok: response.ok, + status: response.status, + statusText: response.statusText, + headers: response.headers, + url: response.url, + redirected: response.redirected, + type: response.type, + body: response.body, + bodyUsed: response.bodyUsed, + // Delegate Response methods + arrayBuffer: () => response.arrayBuffer(), + blob: () => response.blob(), + clone: () => response.clone(), + formData: () => response.formData(), + json: () => response.json(), + text: () => response.text(), + } as HttpResponse; const responseToParse = responseFormat ? response.clone() : response; const data = !responseFormat ? r : await responseToParse[responseFormat]() diff --git a/tests/spec/patch/__snapshots__/basic.test.ts.snap b/tests/spec/patch/__snapshots__/basic.test.ts.snap index a307e33c..8fd53a79 100644 --- a/tests/spec/patch/__snapshots__/basic.test.ts.snap +++ b/tests/spec/patch/__snapshots__/basic.test.ts.snap @@ -1994,9 +1994,29 @@ export class HttpClient { : payloadFormatter(body), }, ).then(async (response) => { - const r = response as HttpResponse; - r.data = null as unknown as T; - r.error = null as unknown as E; + // Create a wrapper object that doesn't mutate the Response + // This ensures compatibility with ESM environments where Response is read-only + const r = { + data: null as unknown as T, + error: null as unknown as E, + // Delegate Response properties + ok: response.ok, + status: response.status, + statusText: response.statusText, + headers: response.headers, + url: response.url, + redirected: response.redirected, + type: response.type, + body: response.body, + bodyUsed: response.bodyUsed, + // Delegate Response methods + arrayBuffer: () => response.arrayBuffer(), + blob: () => response.blob(), + clone: () => response.clone(), + formData: () => response.formData(), + json: () => response.json(), + text: () => response.text(), + } as HttpResponse; const responseToParse = responseFormat ? response.clone() : response; const data = !responseFormat diff --git a/tests/spec/responses/__snapshots__/basic.test.ts.snap b/tests/spec/responses/__snapshots__/basic.test.ts.snap index c368fa92..1ff7d460 100644 --- a/tests/spec/responses/__snapshots__/basic.test.ts.snap +++ b/tests/spec/responses/__snapshots__/basic.test.ts.snap @@ -277,9 +277,29 @@ export class HttpClient { : payloadFormatter(body), }, ).then(async (response) => { - const r = response as HttpResponse; - r.data = null as unknown as T; - r.error = null as unknown as E; + // Create a wrapper object that doesn't mutate the Response + // This ensures compatibility with ESM environments where Response is read-only + const r = { + data: null as unknown as T, + error: null as unknown as E, + // Delegate Response properties + ok: response.ok, + status: response.status, + statusText: response.statusText, + headers: response.headers, + url: response.url, + redirected: response.redirected, + type: response.type, + body: response.body, + bodyUsed: response.bodyUsed, + // Delegate Response methods + arrayBuffer: () => response.arrayBuffer(), + blob: () => response.blob(), + clone: () => response.clone(), + formData: () => response.formData(), + json: () => response.json(), + text: () => response.text(), + } as HttpResponse; const responseToParse = responseFormat ? response.clone() : response; const data = !responseFormat diff --git a/tests/spec/singleHttpClient/__snapshots__/basic.test.ts.snap b/tests/spec/singleHttpClient/__snapshots__/basic.test.ts.snap index 3679cfb0..710d6699 100644 --- a/tests/spec/singleHttpClient/__snapshots__/basic.test.ts.snap +++ b/tests/spec/singleHttpClient/__snapshots__/basic.test.ts.snap @@ -237,9 +237,29 @@ export class HttpClient { : payloadFormatter(body), }, ).then(async (response) => { - const r = response as HttpResponse; - r.data = null as unknown as T; - r.error = null as unknown as E; + // Create a wrapper object that doesn't mutate the Response + // This ensures compatibility with ESM environments where Response is read-only + const r = { + data: null as unknown as T, + error: null as unknown as E, + // Delegate Response properties + ok: response.ok, + status: response.status, + statusText: response.statusText, + headers: response.headers, + url: response.url, + redirected: response.redirected, + type: response.type, + body: response.body, + bodyUsed: response.bodyUsed, + // Delegate Response methods + arrayBuffer: () => response.arrayBuffer(), + blob: () => response.blob(), + clone: () => response.clone(), + formData: () => response.formData(), + json: () => response.json(), + text: () => response.text(), + } as HttpResponse; const responseToParse = responseFormat ? response.clone() : response; const data = !responseFormat diff --git a/tests/spec/sortTypes-false/__snapshots__/basic.test.ts.snap b/tests/spec/sortTypes-false/__snapshots__/basic.test.ts.snap index 69d5302e..5e5c37eb 100644 --- a/tests/spec/sortTypes-false/__snapshots__/basic.test.ts.snap +++ b/tests/spec/sortTypes-false/__snapshots__/basic.test.ts.snap @@ -1994,9 +1994,29 @@ export class HttpClient { : payloadFormatter(body), }, ).then(async (response) => { - const r = response as HttpResponse; - r.data = null as unknown as T; - r.error = null as unknown as E; + // Create a wrapper object that doesn't mutate the Response + // This ensures compatibility with ESM environments where Response is read-only + const r = { + data: null as unknown as T, + error: null as unknown as E, + // Delegate Response properties + ok: response.ok, + status: response.status, + statusText: response.statusText, + headers: response.headers, + url: response.url, + redirected: response.redirected, + type: response.type, + body: response.body, + bodyUsed: response.bodyUsed, + // Delegate Response methods + arrayBuffer: () => response.arrayBuffer(), + blob: () => response.blob(), + clone: () => response.clone(), + formData: () => response.formData(), + json: () => response.json(), + text: () => response.text(), + } as HttpResponse; const responseToParse = responseFormat ? response.clone() : response; const data = !responseFormat diff --git a/tests/spec/sortTypes/__snapshots__/basic.test.ts.snap b/tests/spec/sortTypes/__snapshots__/basic.test.ts.snap index 785d970c..f128795e 100644 --- a/tests/spec/sortTypes/__snapshots__/basic.test.ts.snap +++ b/tests/spec/sortTypes/__snapshots__/basic.test.ts.snap @@ -1994,9 +1994,29 @@ export class HttpClient { : payloadFormatter(body), }, ).then(async (response) => { - const r = response as HttpResponse; - r.data = null as unknown as T; - r.error = null as unknown as E; + // Create a wrapper object that doesn't mutate the Response + // This ensures compatibility with ESM environments where Response is read-only + const r = { + data: null as unknown as T, + error: null as unknown as E, + // Delegate Response properties + ok: response.ok, + status: response.status, + statusText: response.statusText, + headers: response.headers, + url: response.url, + redirected: response.redirected, + type: response.type, + body: response.body, + bodyUsed: response.bodyUsed, + // Delegate Response methods + arrayBuffer: () => response.arrayBuffer(), + blob: () => response.blob(), + clone: () => response.clone(), + formData: () => response.formData(), + json: () => response.json(), + text: () => response.text(), + } as HttpResponse; const responseToParse = responseFormat ? response.clone() : response; const data = !responseFormat diff --git a/tests/spec/typeSuffixPrefix/__snapshots__/basic.test.ts.snap b/tests/spec/typeSuffixPrefix/__snapshots__/basic.test.ts.snap index aef88bef..76f37c8b 100644 --- a/tests/spec/typeSuffixPrefix/__snapshots__/basic.test.ts.snap +++ b/tests/spec/typeSuffixPrefix/__snapshots__/basic.test.ts.snap @@ -2006,9 +2006,29 @@ export class HttpClient { : payloadFormatter(body), }, ).then(async (response) => { - const r = response as HttpResponse; - r.data = null as unknown as T; - r.error = null as unknown as E; + // Create a wrapper object that doesn't mutate the Response + // This ensures compatibility with ESM environments where Response is read-only + const r = { + data: null as unknown as T, + error: null as unknown as E, + // Delegate Response properties + ok: response.ok, + status: response.status, + statusText: response.statusText, + headers: response.headers, + url: response.url, + redirected: response.redirected, + type: response.type, + body: response.body, + bodyUsed: response.bodyUsed, + // Delegate Response methods + arrayBuffer: () => response.arrayBuffer(), + blob: () => response.blob(), + clone: () => response.clone(), + formData: () => response.formData(), + json: () => response.json(), + text: () => response.text(), + } as HttpResponse; const responseToParse = responseFormat ? response.clone() : response; const data = !responseFormat diff --git a/tests/spec/unionEnums/__snapshots__/basic.test.ts.snap b/tests/spec/unionEnums/__snapshots__/basic.test.ts.snap index 1c138869..3cc520be 100644 --- a/tests/spec/unionEnums/__snapshots__/basic.test.ts.snap +++ b/tests/spec/unionEnums/__snapshots__/basic.test.ts.snap @@ -249,9 +249,29 @@ export class HttpClient { : payloadFormatter(body), }, ).then(async (response) => { - const r = response as HttpResponse; - r.data = null as unknown as T; - r.error = null as unknown as E; + // Create a wrapper object that doesn't mutate the Response + // This ensures compatibility with ESM environments where Response is read-only + const r = { + data: null as unknown as T, + error: null as unknown as E, + // Delegate Response properties + ok: response.ok, + status: response.status, + statusText: response.statusText, + headers: response.headers, + url: response.url, + redirected: response.redirected, + type: response.type, + body: response.body, + bodyUsed: response.bodyUsed, + // Delegate Response methods + arrayBuffer: () => response.arrayBuffer(), + blob: () => response.blob(), + clone: () => response.clone(), + formData: () => response.formData(), + json: () => response.json(), + text: () => response.text(), + } as HttpResponse; const responseToParse = responseFormat ? response.clone() : response; const data = !responseFormat From 59bb4c7c760c1c949dab329373b0455faf99fe0b Mon Sep 17 00:00:00 2001 From: Omar McIver Date: Tue, 14 Oct 2025 12:27:41 -0500 Subject: [PATCH 2/3] refactor: use Proxy for ESM-safe Response wrapping Replace static property wrapper with Proxy-based delegation to fix critical issues identified in automated reviews: - Fix stale bodyUsed property (P1 bug) - Ensure all Response properties remain live/dynamic - Automatically include all Response methods (including stream()) - Maintain correct 'this' binding for delegated methods - Preserve prototype chain and type checking The Proxy approach provides true delegation while preventing Response mutation, ensuring compatibility with both CommonJS and ESM environments. Addresses feedback on PR #1430 --- .../base/http-clients/fetch-http-client.ejs | 59 ++++++++++++------- 1 file changed, 37 insertions(+), 22 deletions(-) diff --git a/templates/base/http-clients/fetch-http-client.ejs b/templates/base/http-clients/fetch-http-client.ejs index 9f144712..dd2df425 100644 --- a/templates/base/http-clients/fetch-http-client.ejs +++ b/templates/base/http-clients/fetch-http-client.ejs @@ -196,29 +196,44 @@ export class HttpClient { body: typeof body === "undefined" || body === null ? null : payloadFormatter(body), } ).then(async (response) => { - // Create a wrapper object that doesn't mutate the Response + // Create a Proxy that wraps the Response without mutating it // This ensures compatibility with ESM environments where Response is read-only - const r = { - data: (null as unknown) as T, - error: (null as unknown) as E, - // Delegate Response properties - ok: response.ok, - status: response.status, - statusText: response.statusText, - headers: response.headers, - url: response.url, - redirected: response.redirected, - type: response.type, - body: response.body, - bodyUsed: response.bodyUsed, - // Delegate Response methods - arrayBuffer: () => response.arrayBuffer(), - blob: () => response.blob(), - clone: () => response.clone(), - formData: () => response.formData(), - json: () => response.json(), - text: () => response.text(), - } as HttpResponse; + // while maintaining all Response properties and methods as live/dynamic values + const r = new Proxy(response, { + get(target, prop) { + // Custom properties for our API wrapper + if (prop === 'data') { + return target._data !== undefined ? target._data : (null as unknown) as T; + } + if (prop === 'error') { + return target._error !== undefined ? target._error : (null as unknown) as E; + } + + // Delegate everything else to the actual Response object + const value = target[prop]; + + // Bind methods to the original response to maintain correct 'this' context + if (typeof value === 'function') { + return value.bind(target); + } + + return value; + }, + set(target, prop, value) { + // Allow setting data and error properties + if (prop === 'data') { + target._data = value; + return true; + } + if (prop === 'error') { + target._error = value; + return true; + } + + // Prevent mutation of Response properties (ESM safety) + return false; + } + }) as HttpResponse; const responseToParse = responseFormat ? response.clone() : response; const data = !responseFormat ? r : await responseToParse[responseFormat]() From 837a3810c9611e861754dbfe12480c13b5cc8c9d Mon Sep 17 00:00:00 2001 From: Omar McIver Date: Tue, 14 Oct 2025 12:31:10 -0500 Subject: [PATCH 3/3] test: update snapshots for Proxy-based Response wrapper All snapshot tests updated to reflect the new Proxy implementation. The generated code now uses Proxy for dynamic property delegation instead of static property copying. All 133 tests passing with updated snapshots. --- tests/__snapshots__/extended.test.ts.snap | 2772 +++++++++++------ tests/__snapshots__/simple.test.ts.snap | 2772 +++++++++++------ .../__snapshots__/basic.test.ts.snap | 63 +- .../__snapshots__/basic.test.ts.snap | 63 +- .../__snapshots__/basic.test.ts.snap | 63 +- .../__snapshots__/basic.test.ts.snap | 63 +- .../__snapshots__/basic.test.ts.snap | 63 +- .../__snapshots__/basic.test.ts.snap | 63 +- .../__snapshots__/basic.test.ts.snap | 63 +- .../__snapshots__/inline.test.ts.snap | 63 +- .../__snapshots__/basic.test.ts.snap | 63 +- .../__snapshots__/basic.test.ts.snap | 63 +- .../__snapshots__/basic.test.ts.snap | 63 +- .../__snapshots__/basic.test.ts.snap | 63 +- .../__snapshots__/basic.test.ts.snap | 63 +- .../jsAxios/__snapshots__/basic.test.ts.snap | 55 +- .../__snapshots__/basic.test.ts.snap | 63 +- .../__snapshots__/basic.test.ts.snap | 63 +- .../__snapshots__/basic.test.ts.snap | 63 +- .../__snapshots__/basic.test.ts.snap | 63 +- .../__snapshots__/basic.test.ts.snap | 59 +- .../patch/__snapshots__/basic.test.ts.snap | 63 +- .../__snapshots__/basic.test.ts.snap | 63 +- .../__snapshots__/basic.test.ts.snap | 63 +- .../__snapshots__/basic.test.ts.snap | 63 +- .../__snapshots__/basic.test.ts.snap | 63 +- .../__snapshots__/basic.test.ts.snap | 63 +- .../__snapshots__/basic.test.ts.snap | 63 +- 28 files changed, 4662 insertions(+), 2508 deletions(-) diff --git a/tests/__snapshots__/extended.test.ts.snap b/tests/__snapshots__/extended.test.ts.snap index 3b4ec5f8..89658979 100644 --- a/tests/__snapshots__/extended.test.ts.snap +++ b/tests/__snapshots__/extended.test.ts.snap @@ -2941,29 +2941,48 @@ export class HttpClient { : payloadFormatter(body), }, ).then(async (response) => { - // Create a wrapper object that doesn't mutate the Response + // Create a Proxy that wraps the Response without mutating it // This ensures compatibility with ESM environments where Response is read-only - const r = { - data: null as unknown as T, - error: null as unknown as E, - // Delegate Response properties - ok: response.ok, - status: response.status, - statusText: response.statusText, - headers: response.headers, - url: response.url, - redirected: response.redirected, - type: response.type, - body: response.body, - bodyUsed: response.bodyUsed, - // Delegate Response methods - arrayBuffer: () => response.arrayBuffer(), - blob: () => response.blob(), - clone: () => response.clone(), - formData: () => response.formData(), - json: () => response.json(), - text: () => response.text(), - } as HttpResponse; + // while maintaining all Response properties and methods as live/dynamic values + const r = new Proxy(response, { + get(target, prop) { + // Custom properties for our API wrapper + if (prop === "data") { + return target._data !== undefined + ? target._data + : (null as unknown as T); + } + if (prop === "error") { + return target._error !== undefined + ? target._error + : (null as unknown as E); + } + + // Delegate everything else to the actual Response object + const value = target[prop]; + + // Bind methods to the original response to maintain correct 'this' context + if (typeof value === "function") { + return value.bind(target); + } + + return value; + }, + set(target, prop, value) { + // Allow setting data and error properties + if (prop === "data") { + target._data = value; + return true; + } + if (prop === "error") { + target._error = value; + return true; + } + + // Prevent mutation of Response properties (ESM safety) + return false; + }, + }) as HttpResponse; const responseToParse = responseFormat ? response.clone() : response; const data = !responseFormat @@ -4967,29 +4986,48 @@ export class HttpClient { : payloadFormatter(body), }, ).then(async (response) => { - // Create a wrapper object that doesn't mutate the Response + // Create a Proxy that wraps the Response without mutating it // This ensures compatibility with ESM environments where Response is read-only - const r = { - data: null as unknown as T, - error: null as unknown as E, - // Delegate Response properties - ok: response.ok, - status: response.status, - statusText: response.statusText, - headers: response.headers, - url: response.url, - redirected: response.redirected, - type: response.type, - body: response.body, - bodyUsed: response.bodyUsed, - // Delegate Response methods - arrayBuffer: () => response.arrayBuffer(), - blob: () => response.blob(), - clone: () => response.clone(), - formData: () => response.formData(), - json: () => response.json(), - text: () => response.text(), - } as HttpResponse; + // while maintaining all Response properties and methods as live/dynamic values + const r = new Proxy(response, { + get(target, prop) { + // Custom properties for our API wrapper + if (prop === "data") { + return target._data !== undefined + ? target._data + : (null as unknown as T); + } + if (prop === "error") { + return target._error !== undefined + ? target._error + : (null as unknown as E); + } + + // Delegate everything else to the actual Response object + const value = target[prop]; + + // Bind methods to the original response to maintain correct 'this' context + if (typeof value === "function") { + return value.bind(target); + } + + return value; + }, + set(target, prop, value) { + // Allow setting data and error properties + if (prop === "data") { + target._data = value; + return true; + } + if (prop === "error") { + target._error = value; + return true; + } + + // Prevent mutation of Response properties (ESM safety) + return false; + }, + }) as HttpResponse; const responseToParse = responseFormat ? response.clone() : response; const data = !responseFormat @@ -5269,29 +5307,48 @@ export class HttpClient { : payloadFormatter(body), }, ).then(async (response) => { - // Create a wrapper object that doesn't mutate the Response + // Create a Proxy that wraps the Response without mutating it // This ensures compatibility with ESM environments where Response is read-only - const r = { - data: null as unknown as T, - error: null as unknown as E, - // Delegate Response properties - ok: response.ok, - status: response.status, - statusText: response.statusText, - headers: response.headers, - url: response.url, - redirected: response.redirected, - type: response.type, - body: response.body, - bodyUsed: response.bodyUsed, - // Delegate Response methods - arrayBuffer: () => response.arrayBuffer(), - blob: () => response.blob(), - clone: () => response.clone(), - formData: () => response.formData(), - json: () => response.json(), - text: () => response.text(), - } as HttpResponse; + // while maintaining all Response properties and methods as live/dynamic values + const r = new Proxy(response, { + get(target, prop) { + // Custom properties for our API wrapper + if (prop === "data") { + return target._data !== undefined + ? target._data + : (null as unknown as T); + } + if (prop === "error") { + return target._error !== undefined + ? target._error + : (null as unknown as E); + } + + // Delegate everything else to the actual Response object + const value = target[prop]; + + // Bind methods to the original response to maintain correct 'this' context + if (typeof value === "function") { + return value.bind(target); + } + + return value; + }, + set(target, prop, value) { + // Allow setting data and error properties + if (prop === "data") { + target._data = value; + return true; + } + if (prop === "error") { + target._error = value; + return true; + } + + // Prevent mutation of Response properties (ESM safety) + return false; + }, + }) as HttpResponse; const responseToParse = responseFormat ? response.clone() : response; const data = !responseFormat @@ -5606,29 +5663,48 @@ export class HttpClient { : payloadFormatter(body), }, ).then(async (response) => { - // Create a wrapper object that doesn't mutate the Response + // Create a Proxy that wraps the Response without mutating it // This ensures compatibility with ESM environments where Response is read-only - const r = { - data: null as unknown as T, - error: null as unknown as E, - // Delegate Response properties - ok: response.ok, - status: response.status, - statusText: response.statusText, - headers: response.headers, - url: response.url, - redirected: response.redirected, - type: response.type, - body: response.body, - bodyUsed: response.bodyUsed, - // Delegate Response methods - arrayBuffer: () => response.arrayBuffer(), - blob: () => response.blob(), - clone: () => response.clone(), - formData: () => response.formData(), - json: () => response.json(), - text: () => response.text(), - } as HttpResponse; + // while maintaining all Response properties and methods as live/dynamic values + const r = new Proxy(response, { + get(target, prop) { + // Custom properties for our API wrapper + if (prop === "data") { + return target._data !== undefined + ? target._data + : (null as unknown as T); + } + if (prop === "error") { + return target._error !== undefined + ? target._error + : (null as unknown as E); + } + + // Delegate everything else to the actual Response object + const value = target[prop]; + + // Bind methods to the original response to maintain correct 'this' context + if (typeof value === "function") { + return value.bind(target); + } + + return value; + }, + set(target, prop, value) { + // Allow setting data and error properties + if (prop === "data") { + target._data = value; + return true; + } + if (prop === "error") { + target._error = value; + return true; + } + + // Prevent mutation of Response properties (ESM safety) + return false; + }, + }) as HttpResponse; const responseToParse = responseFormat ? response.clone() : response; const data = !responseFormat @@ -6646,29 +6722,48 @@ export class HttpClient { : payloadFormatter(body), }, ).then(async (response) => { - // Create a wrapper object that doesn't mutate the Response + // Create a Proxy that wraps the Response without mutating it // This ensures compatibility with ESM environments where Response is read-only - const r = { - data: null as unknown as T, - error: null as unknown as E, - // Delegate Response properties - ok: response.ok, - status: response.status, - statusText: response.statusText, - headers: response.headers, - url: response.url, - redirected: response.redirected, - type: response.type, - body: response.body, - bodyUsed: response.bodyUsed, - // Delegate Response methods - arrayBuffer: () => response.arrayBuffer(), - blob: () => response.blob(), - clone: () => response.clone(), - formData: () => response.formData(), - json: () => response.json(), - text: () => response.text(), - } as HttpResponse; + // while maintaining all Response properties and methods as live/dynamic values + const r = new Proxy(response, { + get(target, prop) { + // Custom properties for our API wrapper + if (prop === "data") { + return target._data !== undefined + ? target._data + : (null as unknown as T); + } + if (prop === "error") { + return target._error !== undefined + ? target._error + : (null as unknown as E); + } + + // Delegate everything else to the actual Response object + const value = target[prop]; + + // Bind methods to the original response to maintain correct 'this' context + if (typeof value === "function") { + return value.bind(target); + } + + return value; + }, + set(target, prop, value) { + // Allow setting data and error properties + if (prop === "data") { + target._data = value; + return true; + } + if (prop === "error") { + target._error = value; + return true; + } + + // Prevent mutation of Response properties (ESM safety) + return false; + }, + }) as HttpResponse; const responseToParse = responseFormat ? response.clone() : response; const data = !responseFormat @@ -7484,29 +7579,48 @@ export class HttpClient { : payloadFormatter(body), }, ).then(async (response) => { - // Create a wrapper object that doesn't mutate the Response + // Create a Proxy that wraps the Response without mutating it // This ensures compatibility with ESM environments where Response is read-only - const r = { - data: null as unknown as T, - error: null as unknown as E, - // Delegate Response properties - ok: response.ok, - status: response.status, - statusText: response.statusText, - headers: response.headers, - url: response.url, - redirected: response.redirected, - type: response.type, - body: response.body, - bodyUsed: response.bodyUsed, - // Delegate Response methods - arrayBuffer: () => response.arrayBuffer(), - blob: () => response.blob(), - clone: () => response.clone(), - formData: () => response.formData(), - json: () => response.json(), - text: () => response.text(), - } as HttpResponse; + // while maintaining all Response properties and methods as live/dynamic values + const r = new Proxy(response, { + get(target, prop) { + // Custom properties for our API wrapper + if (prop === "data") { + return target._data !== undefined + ? target._data + : (null as unknown as T); + } + if (prop === "error") { + return target._error !== undefined + ? target._error + : (null as unknown as E); + } + + // Delegate everything else to the actual Response object + const value = target[prop]; + + // Bind methods to the original response to maintain correct 'this' context + if (typeof value === "function") { + return value.bind(target); + } + + return value; + }, + set(target, prop, value) { + // Allow setting data and error properties + if (prop === "data") { + target._data = value; + return true; + } + if (prop === "error") { + target._error = value; + return true; + } + + // Prevent mutation of Response properties (ESM safety) + return false; + }, + }) as HttpResponse; const responseToParse = responseFormat ? response.clone() : response; const data = !responseFormat @@ -7864,29 +7978,48 @@ export class HttpClient { : payloadFormatter(body), }, ).then(async (response) => { - // Create a wrapper object that doesn't mutate the Response + // Create a Proxy that wraps the Response without mutating it // This ensures compatibility with ESM environments where Response is read-only - const r = { - data: null as unknown as T, - error: null as unknown as E, - // Delegate Response properties - ok: response.ok, - status: response.status, - statusText: response.statusText, - headers: response.headers, - url: response.url, - redirected: response.redirected, - type: response.type, - body: response.body, - bodyUsed: response.bodyUsed, - // Delegate Response methods - arrayBuffer: () => response.arrayBuffer(), - blob: () => response.blob(), - clone: () => response.clone(), - formData: () => response.formData(), - json: () => response.json(), - text: () => response.text(), - } as HttpResponse; + // while maintaining all Response properties and methods as live/dynamic values + const r = new Proxy(response, { + get(target, prop) { + // Custom properties for our API wrapper + if (prop === "data") { + return target._data !== undefined + ? target._data + : (null as unknown as T); + } + if (prop === "error") { + return target._error !== undefined + ? target._error + : (null as unknown as E); + } + + // Delegate everything else to the actual Response object + const value = target[prop]; + + // Bind methods to the original response to maintain correct 'this' context + if (typeof value === "function") { + return value.bind(target); + } + + return value; + }, + set(target, prop, value) { + // Allow setting data and error properties + if (prop === "data") { + target._data = value; + return true; + } + if (prop === "error") { + target._error = value; + return true; + } + + // Prevent mutation of Response properties (ESM safety) + return false; + }, + }) as HttpResponse; const responseToParse = responseFormat ? response.clone() : response; const data = !responseFormat @@ -8202,29 +8335,48 @@ export class HttpClient { : payloadFormatter(body), }, ).then(async (response) => { - // Create a wrapper object that doesn't mutate the Response + // Create a Proxy that wraps the Response without mutating it // This ensures compatibility with ESM environments where Response is read-only - const r = { - data: null as unknown as T, - error: null as unknown as E, - // Delegate Response properties - ok: response.ok, - status: response.status, - statusText: response.statusText, - headers: response.headers, - url: response.url, - redirected: response.redirected, - type: response.type, - body: response.body, - bodyUsed: response.bodyUsed, - // Delegate Response methods - arrayBuffer: () => response.arrayBuffer(), - blob: () => response.blob(), - clone: () => response.clone(), - formData: () => response.formData(), - json: () => response.json(), - text: () => response.text(), - } as HttpResponse; + // while maintaining all Response properties and methods as live/dynamic values + const r = new Proxy(response, { + get(target, prop) { + // Custom properties for our API wrapper + if (prop === "data") { + return target._data !== undefined + ? target._data + : (null as unknown as T); + } + if (prop === "error") { + return target._error !== undefined + ? target._error + : (null as unknown as E); + } + + // Delegate everything else to the actual Response object + const value = target[prop]; + + // Bind methods to the original response to maintain correct 'this' context + if (typeof value === "function") { + return value.bind(target); + } + + return value; + }, + set(target, prop, value) { + // Allow setting data and error properties + if (prop === "data") { + target._data = value; + return true; + } + if (prop === "error") { + target._error = value; + return true; + } + + // Prevent mutation of Response properties (ESM safety) + return false; + }, + }) as HttpResponse; const responseToParse = responseFormat ? response.clone() : response; const data = !responseFormat @@ -8588,29 +8740,48 @@ export class HttpClient { : payloadFormatter(body), }, ).then(async (response) => { - // Create a wrapper object that doesn't mutate the Response + // Create a Proxy that wraps the Response without mutating it // This ensures compatibility with ESM environments where Response is read-only - const r = { - data: null as unknown as T, - error: null as unknown as E, - // Delegate Response properties - ok: response.ok, - status: response.status, - statusText: response.statusText, - headers: response.headers, - url: response.url, - redirected: response.redirected, - type: response.type, - body: response.body, - bodyUsed: response.bodyUsed, - // Delegate Response methods - arrayBuffer: () => response.arrayBuffer(), - blob: () => response.blob(), - clone: () => response.clone(), - formData: () => response.formData(), - json: () => response.json(), - text: () => response.text(), - } as HttpResponse; + // while maintaining all Response properties and methods as live/dynamic values + const r = new Proxy(response, { + get(target, prop) { + // Custom properties for our API wrapper + if (prop === "data") { + return target._data !== undefined + ? target._data + : (null as unknown as T); + } + if (prop === "error") { + return target._error !== undefined + ? target._error + : (null as unknown as E); + } + + // Delegate everything else to the actual Response object + const value = target[prop]; + + // Bind methods to the original response to maintain correct 'this' context + if (typeof value === "function") { + return value.bind(target); + } + + return value; + }, + set(target, prop, value) { + // Allow setting data and error properties + if (prop === "data") { + target._data = value; + return true; + } + if (prop === "error") { + target._error = value; + return true; + } + + // Prevent mutation of Response properties (ESM safety) + return false; + }, + }) as HttpResponse; const responseToParse = responseFormat ? response.clone() : response; const data = !responseFormat @@ -9478,29 +9649,48 @@ export class HttpClient { : payloadFormatter(body), }, ).then(async (response) => { - // Create a wrapper object that doesn't mutate the Response + // Create a Proxy that wraps the Response without mutating it // This ensures compatibility with ESM environments where Response is read-only - const r = { - data: null as unknown as T, - error: null as unknown as E, - // Delegate Response properties - ok: response.ok, - status: response.status, - statusText: response.statusText, - headers: response.headers, - url: response.url, - redirected: response.redirected, - type: response.type, - body: response.body, - bodyUsed: response.bodyUsed, - // Delegate Response methods - arrayBuffer: () => response.arrayBuffer(), - blob: () => response.blob(), - clone: () => response.clone(), - formData: () => response.formData(), - json: () => response.json(), - text: () => response.text(), - } as HttpResponse; + // while maintaining all Response properties and methods as live/dynamic values + const r = new Proxy(response, { + get(target, prop) { + // Custom properties for our API wrapper + if (prop === "data") { + return target._data !== undefined + ? target._data + : (null as unknown as T); + } + if (prop === "error") { + return target._error !== undefined + ? target._error + : (null as unknown as E); + } + + // Delegate everything else to the actual Response object + const value = target[prop]; + + // Bind methods to the original response to maintain correct 'this' context + if (typeof value === "function") { + return value.bind(target); + } + + return value; + }, + set(target, prop, value) { + // Allow setting data and error properties + if (prop === "data") { + target._data = value; + return true; + } + if (prop === "error") { + target._error = value; + return true; + } + + // Prevent mutation of Response properties (ESM safety) + return false; + }, + }) as HttpResponse; const responseToParse = responseFormat ? response.clone() : response; const data = !responseFormat @@ -10124,29 +10314,48 @@ export class HttpClient { : payloadFormatter(body), }, ).then(async (response) => { - // Create a wrapper object that doesn't mutate the Response + // Create a Proxy that wraps the Response without mutating it // This ensures compatibility with ESM environments where Response is read-only - const r = { - data: null as unknown as T, - error: null as unknown as E, - // Delegate Response properties - ok: response.ok, - status: response.status, - statusText: response.statusText, - headers: response.headers, - url: response.url, - redirected: response.redirected, - type: response.type, - body: response.body, - bodyUsed: response.bodyUsed, - // Delegate Response methods - arrayBuffer: () => response.arrayBuffer(), - blob: () => response.blob(), - clone: () => response.clone(), - formData: () => response.formData(), - json: () => response.json(), - text: () => response.text(), - } as HttpResponse; + // while maintaining all Response properties and methods as live/dynamic values + const r = new Proxy(response, { + get(target, prop) { + // Custom properties for our API wrapper + if (prop === "data") { + return target._data !== undefined + ? target._data + : (null as unknown as T); + } + if (prop === "error") { + return target._error !== undefined + ? target._error + : (null as unknown as E); + } + + // Delegate everything else to the actual Response object + const value = target[prop]; + + // Bind methods to the original response to maintain correct 'this' context + if (typeof value === "function") { + return value.bind(target); + } + + return value; + }, + set(target, prop, value) { + // Allow setting data and error properties + if (prop === "data") { + target._data = value; + return true; + } + if (prop === "error") { + target._error = value; + return true; + } + + // Prevent mutation of Response properties (ESM safety) + return false; + }, + }) as HttpResponse; const responseToParse = responseFormat ? response.clone() : response; const data = !responseFormat @@ -10461,29 +10670,48 @@ export class HttpClient { : payloadFormatter(body), }, ).then(async (response) => { - // Create a wrapper object that doesn't mutate the Response + // Create a Proxy that wraps the Response without mutating it // This ensures compatibility with ESM environments where Response is read-only - const r = { - data: null as unknown as T, - error: null as unknown as E, - // Delegate Response properties - ok: response.ok, - status: response.status, - statusText: response.statusText, - headers: response.headers, - url: response.url, - redirected: response.redirected, - type: response.type, - body: response.body, - bodyUsed: response.bodyUsed, - // Delegate Response methods - arrayBuffer: () => response.arrayBuffer(), - blob: () => response.blob(), - clone: () => response.clone(), - formData: () => response.formData(), - json: () => response.json(), - text: () => response.text(), - } as HttpResponse; + // while maintaining all Response properties and methods as live/dynamic values + const r = new Proxy(response, { + get(target, prop) { + // Custom properties for our API wrapper + if (prop === "data") { + return target._data !== undefined + ? target._data + : (null as unknown as T); + } + if (prop === "error") { + return target._error !== undefined + ? target._error + : (null as unknown as E); + } + + // Delegate everything else to the actual Response object + const value = target[prop]; + + // Bind methods to the original response to maintain correct 'this' context + if (typeof value === "function") { + return value.bind(target); + } + + return value; + }, + set(target, prop, value) { + // Allow setting data and error properties + if (prop === "data") { + target._data = value; + return true; + } + if (prop === "error") { + target._error = value; + return true; + } + + // Prevent mutation of Response properties (ESM safety) + return false; + }, + }) as HttpResponse; const responseToParse = responseFormat ? response.clone() : response; const data = !responseFormat @@ -10804,29 +11032,48 @@ export class HttpClient { : payloadFormatter(body), }, ).then(async (response) => { - // Create a wrapper object that doesn't mutate the Response + // Create a Proxy that wraps the Response without mutating it // This ensures compatibility with ESM environments where Response is read-only - const r = { - data: null as unknown as T, - error: null as unknown as E, - // Delegate Response properties - ok: response.ok, - status: response.status, - statusText: response.statusText, - headers: response.headers, - url: response.url, - redirected: response.redirected, - type: response.type, - body: response.body, - bodyUsed: response.bodyUsed, - // Delegate Response methods - arrayBuffer: () => response.arrayBuffer(), - blob: () => response.blob(), - clone: () => response.clone(), - formData: () => response.formData(), - json: () => response.json(), - text: () => response.text(), - } as HttpResponse; + // while maintaining all Response properties and methods as live/dynamic values + const r = new Proxy(response, { + get(target, prop) { + // Custom properties for our API wrapper + if (prop === "data") { + return target._data !== undefined + ? target._data + : (null as unknown as T); + } + if (prop === "error") { + return target._error !== undefined + ? target._error + : (null as unknown as E); + } + + // Delegate everything else to the actual Response object + const value = target[prop]; + + // Bind methods to the original response to maintain correct 'this' context + if (typeof value === "function") { + return value.bind(target); + } + + return value; + }, + set(target, prop, value) { + // Allow setting data and error properties + if (prop === "data") { + target._data = value; + return true; + } + if (prop === "error") { + target._error = value; + return true; + } + + // Prevent mutation of Response properties (ESM safety) + return false; + }, + }) as HttpResponse; const responseToParse = responseFormat ? response.clone() : response; const data = !responseFormat @@ -11177,29 +11424,48 @@ export class HttpClient { : payloadFormatter(body), }, ).then(async (response) => { - // Create a wrapper object that doesn't mutate the Response + // Create a Proxy that wraps the Response without mutating it // This ensures compatibility with ESM environments where Response is read-only - const r = { - data: null as unknown as T, - error: null as unknown as E, - // Delegate Response properties - ok: response.ok, - status: response.status, - statusText: response.statusText, - headers: response.headers, - url: response.url, - redirected: response.redirected, - type: response.type, - body: response.body, - bodyUsed: response.bodyUsed, - // Delegate Response methods - arrayBuffer: () => response.arrayBuffer(), - blob: () => response.blob(), - clone: () => response.clone(), - formData: () => response.formData(), - json: () => response.json(), - text: () => response.text(), - } as HttpResponse; + // while maintaining all Response properties and methods as live/dynamic values + const r = new Proxy(response, { + get(target, prop) { + // Custom properties for our API wrapper + if (prop === "data") { + return target._data !== undefined + ? target._data + : (null as unknown as T); + } + if (prop === "error") { + return target._error !== undefined + ? target._error + : (null as unknown as E); + } + + // Delegate everything else to the actual Response object + const value = target[prop]; + + // Bind methods to the original response to maintain correct 'this' context + if (typeof value === "function") { + return value.bind(target); + } + + return value; + }, + set(target, prop, value) { + // Allow setting data and error properties + if (prop === "data") { + target._data = value; + return true; + } + if (prop === "error") { + target._error = value; + return true; + } + + // Prevent mutation of Response properties (ESM safety) + return false; + }, + }) as HttpResponse; const responseToParse = responseFormat ? response.clone() : response; const data = !responseFormat @@ -11551,29 +11817,48 @@ export class HttpClient { : payloadFormatter(body), }, ).then(async (response) => { - // Create a wrapper object that doesn't mutate the Response + // Create a Proxy that wraps the Response without mutating it // This ensures compatibility with ESM environments where Response is read-only - const r = { - data: null as unknown as T, - error: null as unknown as E, - // Delegate Response properties - ok: response.ok, - status: response.status, - statusText: response.statusText, - headers: response.headers, - url: response.url, - redirected: response.redirected, - type: response.type, - body: response.body, - bodyUsed: response.bodyUsed, - // Delegate Response methods - arrayBuffer: () => response.arrayBuffer(), - blob: () => response.blob(), - clone: () => response.clone(), - formData: () => response.formData(), - json: () => response.json(), - text: () => response.text(), - } as HttpResponse; + // while maintaining all Response properties and methods as live/dynamic values + const r = new Proxy(response, { + get(target, prop) { + // Custom properties for our API wrapper + if (prop === "data") { + return target._data !== undefined + ? target._data + : (null as unknown as T); + } + if (prop === "error") { + return target._error !== undefined + ? target._error + : (null as unknown as E); + } + + // Delegate everything else to the actual Response object + const value = target[prop]; + + // Bind methods to the original response to maintain correct 'this' context + if (typeof value === "function") { + return value.bind(target); + } + + return value; + }, + set(target, prop, value) { + // Allow setting data and error properties + if (prop === "data") { + target._data = value; + return true; + } + if (prop === "error") { + target._error = value; + return true; + } + + // Prevent mutation of Response properties (ESM safety) + return false; + }, + }) as HttpResponse; const responseToParse = responseFormat ? response.clone() : response; const data = !responseFormat @@ -11950,29 +12235,48 @@ export class HttpClient { : payloadFormatter(body), }, ).then(async (response) => { - // Create a wrapper object that doesn't mutate the Response + // Create a Proxy that wraps the Response without mutating it // This ensures compatibility with ESM environments where Response is read-only - const r = { - data: null as unknown as T, - error: null as unknown as E, - // Delegate Response properties - ok: response.ok, - status: response.status, - statusText: response.statusText, - headers: response.headers, - url: response.url, - redirected: response.redirected, - type: response.type, - body: response.body, - bodyUsed: response.bodyUsed, - // Delegate Response methods - arrayBuffer: () => response.arrayBuffer(), - blob: () => response.blob(), - clone: () => response.clone(), - formData: () => response.formData(), - json: () => response.json(), - text: () => response.text(), - } as HttpResponse; + // while maintaining all Response properties and methods as live/dynamic values + const r = new Proxy(response, { + get(target, prop) { + // Custom properties for our API wrapper + if (prop === "data") { + return target._data !== undefined + ? target._data + : (null as unknown as T); + } + if (prop === "error") { + return target._error !== undefined + ? target._error + : (null as unknown as E); + } + + // Delegate everything else to the actual Response object + const value = target[prop]; + + // Bind methods to the original response to maintain correct 'this' context + if (typeof value === "function") { + return value.bind(target); + } + + return value; + }, + set(target, prop, value) { + // Allow setting data and error properties + if (prop === "data") { + target._data = value; + return true; + } + if (prop === "error") { + target._error = value; + return true; + } + + // Prevent mutation of Response properties (ESM safety) + return false; + }, + }) as HttpResponse; const responseToParse = responseFormat ? response.clone() : response; const data = !responseFormat @@ -12317,29 +12621,48 @@ export class HttpClient { : payloadFormatter(body), }, ).then(async (response) => { - // Create a wrapper object that doesn't mutate the Response + // Create a Proxy that wraps the Response without mutating it // This ensures compatibility with ESM environments where Response is read-only - const r = { - data: null as unknown as T, - error: null as unknown as E, - // Delegate Response properties - ok: response.ok, - status: response.status, - statusText: response.statusText, - headers: response.headers, - url: response.url, - redirected: response.redirected, - type: response.type, - body: response.body, - bodyUsed: response.bodyUsed, - // Delegate Response methods - arrayBuffer: () => response.arrayBuffer(), - blob: () => response.blob(), - clone: () => response.clone(), - formData: () => response.formData(), - json: () => response.json(), - text: () => response.text(), - } as HttpResponse; + // while maintaining all Response properties and methods as live/dynamic values + const r = new Proxy(response, { + get(target, prop) { + // Custom properties for our API wrapper + if (prop === "data") { + return target._data !== undefined + ? target._data + : (null as unknown as T); + } + if (prop === "error") { + return target._error !== undefined + ? target._error + : (null as unknown as E); + } + + // Delegate everything else to the actual Response object + const value = target[prop]; + + // Bind methods to the original response to maintain correct 'this' context + if (typeof value === "function") { + return value.bind(target); + } + + return value; + }, + set(target, prop, value) { + // Allow setting data and error properties + if (prop === "data") { + target._data = value; + return true; + } + if (prop === "error") { + target._error = value; + return true; + } + + // Prevent mutation of Response properties (ESM safety) + return false; + }, + }) as HttpResponse; const responseToParse = responseFormat ? response.clone() : response; const data = !responseFormat @@ -50745,29 +51068,48 @@ export class HttpClient { : payloadFormatter(body), }, ).then(async (response) => { - // Create a wrapper object that doesn't mutate the Response + // Create a Proxy that wraps the Response without mutating it // This ensures compatibility with ESM environments where Response is read-only - const r = { - data: null as unknown as T, - error: null as unknown as E, - // Delegate Response properties - ok: response.ok, - status: response.status, - statusText: response.statusText, - headers: response.headers, - url: response.url, - redirected: response.redirected, - type: response.type, - body: response.body, - bodyUsed: response.bodyUsed, - // Delegate Response methods - arrayBuffer: () => response.arrayBuffer(), - blob: () => response.blob(), - clone: () => response.clone(), - formData: () => response.formData(), - json: () => response.json(), - text: () => response.text(), - } as HttpResponse; + // while maintaining all Response properties and methods as live/dynamic values + const r = new Proxy(response, { + get(target, prop) { + // Custom properties for our API wrapper + if (prop === "data") { + return target._data !== undefined + ? target._data + : (null as unknown as T); + } + if (prop === "error") { + return target._error !== undefined + ? target._error + : (null as unknown as E); + } + + // Delegate everything else to the actual Response object + const value = target[prop]; + + // Bind methods to the original response to maintain correct 'this' context + if (typeof value === "function") { + return value.bind(target); + } + + return value; + }, + set(target, prop, value) { + // Allow setting data and error properties + if (prop === "data") { + target._data = value; + return true; + } + if (prop === "error") { + target._error = value; + return true; + } + + // Prevent mutation of Response properties (ESM safety) + return false; + }, + }) as HttpResponse; const responseToParse = responseFormat ? response.clone() : response; const data = !responseFormat @@ -66568,29 +66910,48 @@ export class HttpClient { : payloadFormatter(body), }, ).then(async (response) => { - // Create a wrapper object that doesn't mutate the Response + // Create a Proxy that wraps the Response without mutating it // This ensures compatibility with ESM environments where Response is read-only - const r = { - data: null as unknown as T, - error: null as unknown as E, - // Delegate Response properties - ok: response.ok, - status: response.status, - statusText: response.statusText, - headers: response.headers, - url: response.url, - redirected: response.redirected, - type: response.type, - body: response.body, - bodyUsed: response.bodyUsed, - // Delegate Response methods - arrayBuffer: () => response.arrayBuffer(), - blob: () => response.blob(), - clone: () => response.clone(), - formData: () => response.formData(), - json: () => response.json(), - text: () => response.text(), - } as HttpResponse; + // while maintaining all Response properties and methods as live/dynamic values + const r = new Proxy(response, { + get(target, prop) { + // Custom properties for our API wrapper + if (prop === "data") { + return target._data !== undefined + ? target._data + : (null as unknown as T); + } + if (prop === "error") { + return target._error !== undefined + ? target._error + : (null as unknown as E); + } + + // Delegate everything else to the actual Response object + const value = target[prop]; + + // Bind methods to the original response to maintain correct 'this' context + if (typeof value === "function") { + return value.bind(target); + } + + return value; + }, + set(target, prop, value) { + // Allow setting data and error properties + if (prop === "data") { + target._data = value; + return true; + } + if (prop === "error") { + target._error = value; + return true; + } + + // Prevent mutation of Response properties (ESM safety) + return false; + }, + }) as HttpResponse; const responseToParse = responseFormat ? response.clone() : response; const data = !responseFormat @@ -67627,29 +67988,48 @@ export class HttpClient { : payloadFormatter(body), }, ).then(async (response) => { - // Create a wrapper object that doesn't mutate the Response + // Create a Proxy that wraps the Response without mutating it // This ensures compatibility with ESM environments where Response is read-only - const r = { - data: null as unknown as T, - error: null as unknown as E, - // Delegate Response properties - ok: response.ok, - status: response.status, - statusText: response.statusText, - headers: response.headers, - url: response.url, - redirected: response.redirected, - type: response.type, - body: response.body, - bodyUsed: response.bodyUsed, - // Delegate Response methods - arrayBuffer: () => response.arrayBuffer(), - blob: () => response.blob(), - clone: () => response.clone(), - formData: () => response.formData(), - json: () => response.json(), - text: () => response.text(), - } as HttpResponse; + // while maintaining all Response properties and methods as live/dynamic values + const r = new Proxy(response, { + get(target, prop) { + // Custom properties for our API wrapper + if (prop === "data") { + return target._data !== undefined + ? target._data + : (null as unknown as T); + } + if (prop === "error") { + return target._error !== undefined + ? target._error + : (null as unknown as E); + } + + // Delegate everything else to the actual Response object + const value = target[prop]; + + // Bind methods to the original response to maintain correct 'this' context + if (typeof value === "function") { + return value.bind(target); + } + + return value; + }, + set(target, prop, value) { + // Allow setting data and error properties + if (prop === "data") { + target._data = value; + return true; + } + if (prop === "error") { + target._error = value; + return true; + } + + // Prevent mutation of Response properties (ESM safety) + return false; + }, + }) as HttpResponse; const responseToParse = responseFormat ? response.clone() : response; const data = !responseFormat @@ -68145,29 +68525,48 @@ export class HttpClient { : payloadFormatter(body), }, ).then(async (response) => { - // Create a wrapper object that doesn't mutate the Response + // Create a Proxy that wraps the Response without mutating it // This ensures compatibility with ESM environments where Response is read-only - const r = { - data: null as unknown as T, - error: null as unknown as E, - // Delegate Response properties - ok: response.ok, - status: response.status, - statusText: response.statusText, - headers: response.headers, - url: response.url, - redirected: response.redirected, - type: response.type, - body: response.body, - bodyUsed: response.bodyUsed, - // Delegate Response methods - arrayBuffer: () => response.arrayBuffer(), - blob: () => response.blob(), - clone: () => response.clone(), - formData: () => response.formData(), - json: () => response.json(), - text: () => response.text(), - } as HttpResponse; + // while maintaining all Response properties and methods as live/dynamic values + const r = new Proxy(response, { + get(target, prop) { + // Custom properties for our API wrapper + if (prop === "data") { + return target._data !== undefined + ? target._data + : (null as unknown as T); + } + if (prop === "error") { + return target._error !== undefined + ? target._error + : (null as unknown as E); + } + + // Delegate everything else to the actual Response object + const value = target[prop]; + + // Bind methods to the original response to maintain correct 'this' context + if (typeof value === "function") { + return value.bind(target); + } + + return value; + }, + set(target, prop, value) { + // Allow setting data and error properties + if (prop === "data") { + target._data = value; + return true; + } + if (prop === "error") { + target._error = value; + return true; + } + + // Prevent mutation of Response properties (ESM safety) + return false; + }, + }) as HttpResponse; const responseToParse = responseFormat ? response.clone() : response; const data = !responseFormat @@ -68614,29 +69013,48 @@ export class HttpClient { : payloadFormatter(body), }, ).then(async (response) => { - // Create a wrapper object that doesn't mutate the Response + // Create a Proxy that wraps the Response without mutating it // This ensures compatibility with ESM environments where Response is read-only - const r = { - data: null as unknown as T, - error: null as unknown as E, - // Delegate Response properties - ok: response.ok, - status: response.status, - statusText: response.statusText, - headers: response.headers, - url: response.url, - redirected: response.redirected, - type: response.type, - body: response.body, - bodyUsed: response.bodyUsed, - // Delegate Response methods - arrayBuffer: () => response.arrayBuffer(), - blob: () => response.blob(), - clone: () => response.clone(), - formData: () => response.formData(), - json: () => response.json(), - text: () => response.text(), - } as HttpResponse; + // while maintaining all Response properties and methods as live/dynamic values + const r = new Proxy(response, { + get(target, prop) { + // Custom properties for our API wrapper + if (prop === "data") { + return target._data !== undefined + ? target._data + : (null as unknown as T); + } + if (prop === "error") { + return target._error !== undefined + ? target._error + : (null as unknown as E); + } + + // Delegate everything else to the actual Response object + const value = target[prop]; + + // Bind methods to the original response to maintain correct 'this' context + if (typeof value === "function") { + return value.bind(target); + } + + return value; + }, + set(target, prop, value) { + // Allow setting data and error properties + if (prop === "data") { + target._data = value; + return true; + } + if (prop === "error") { + target._error = value; + return true; + } + + // Prevent mutation of Response properties (ESM safety) + return false; + }, + }) as HttpResponse; const responseToParse = responseFormat ? response.clone() : response; const data = !responseFormat @@ -69030,29 +69448,48 @@ export class HttpClient { : payloadFormatter(body), }, ).then(async (response) => { - // Create a wrapper object that doesn't mutate the Response + // Create a Proxy that wraps the Response without mutating it // This ensures compatibility with ESM environments where Response is read-only - const r = { - data: null as unknown as T, - error: null as unknown as E, - // Delegate Response properties - ok: response.ok, - status: response.status, - statusText: response.statusText, - headers: response.headers, - url: response.url, - redirected: response.redirected, - type: response.type, - body: response.body, - bodyUsed: response.bodyUsed, - // Delegate Response methods - arrayBuffer: () => response.arrayBuffer(), - blob: () => response.blob(), - clone: () => response.clone(), - formData: () => response.formData(), - json: () => response.json(), - text: () => response.text(), - } as HttpResponse; + // while maintaining all Response properties and methods as live/dynamic values + const r = new Proxy(response, { + get(target, prop) { + // Custom properties for our API wrapper + if (prop === "data") { + return target._data !== undefined + ? target._data + : (null as unknown as T); + } + if (prop === "error") { + return target._error !== undefined + ? target._error + : (null as unknown as E); + } + + // Delegate everything else to the actual Response object + const value = target[prop]; + + // Bind methods to the original response to maintain correct 'this' context + if (typeof value === "function") { + return value.bind(target); + } + + return value; + }, + set(target, prop, value) { + // Allow setting data and error properties + if (prop === "data") { + target._data = value; + return true; + } + if (prop === "error") { + target._error = value; + return true; + } + + // Prevent mutation of Response properties (ESM safety) + return false; + }, + }) as HttpResponse; const responseToParse = responseFormat ? response.clone() : response; const data = !responseFormat @@ -69364,29 +69801,48 @@ export class HttpClient { : payloadFormatter(body), }, ).then(async (response) => { - // Create a wrapper object that doesn't mutate the Response + // Create a Proxy that wraps the Response without mutating it // This ensures compatibility with ESM environments where Response is read-only - const r = { - data: null as unknown as T, - error: null as unknown as E, - // Delegate Response properties - ok: response.ok, - status: response.status, - statusText: response.statusText, - headers: response.headers, - url: response.url, - redirected: response.redirected, - type: response.type, - body: response.body, - bodyUsed: response.bodyUsed, - // Delegate Response methods - arrayBuffer: () => response.arrayBuffer(), - blob: () => response.blob(), - clone: () => response.clone(), - formData: () => response.formData(), - json: () => response.json(), - text: () => response.text(), - } as HttpResponse; + // while maintaining all Response properties and methods as live/dynamic values + const r = new Proxy(response, { + get(target, prop) { + // Custom properties for our API wrapper + if (prop === "data") { + return target._data !== undefined + ? target._data + : (null as unknown as T); + } + if (prop === "error") { + return target._error !== undefined + ? target._error + : (null as unknown as E); + } + + // Delegate everything else to the actual Response object + const value = target[prop]; + + // Bind methods to the original response to maintain correct 'this' context + if (typeof value === "function") { + return value.bind(target); + } + + return value; + }, + set(target, prop, value) { + // Allow setting data and error properties + if (prop === "data") { + target._data = value; + return true; + } + if (prop === "error") { + target._error = value; + return true; + } + + // Prevent mutation of Response properties (ESM safety) + return false; + }, + }) as HttpResponse; const responseToParse = responseFormat ? response.clone() : response; const data = !responseFormat @@ -69746,29 +70202,48 @@ export class HttpClient { : payloadFormatter(body), }, ).then(async (response) => { - // Create a wrapper object that doesn't mutate the Response + // Create a Proxy that wraps the Response without mutating it // This ensures compatibility with ESM environments where Response is read-only - const r = { - data: null as unknown as T, - error: null as unknown as E, - // Delegate Response properties - ok: response.ok, - status: response.status, - statusText: response.statusText, - headers: response.headers, - url: response.url, - redirected: response.redirected, - type: response.type, - body: response.body, - bodyUsed: response.bodyUsed, - // Delegate Response methods - arrayBuffer: () => response.arrayBuffer(), - blob: () => response.blob(), - clone: () => response.clone(), - formData: () => response.formData(), - json: () => response.json(), - text: () => response.text(), - } as HttpResponse; + // while maintaining all Response properties and methods as live/dynamic values + const r = new Proxy(response, { + get(target, prop) { + // Custom properties for our API wrapper + if (prop === "data") { + return target._data !== undefined + ? target._data + : (null as unknown as T); + } + if (prop === "error") { + return target._error !== undefined + ? target._error + : (null as unknown as E); + } + + // Delegate everything else to the actual Response object + const value = target[prop]; + + // Bind methods to the original response to maintain correct 'this' context + if (typeof value === "function") { + return value.bind(target); + } + + return value; + }, + set(target, prop, value) { + // Allow setting data and error properties + if (prop === "data") { + target._data = value; + return true; + } + if (prop === "error") { + target._error = value; + return true; + } + + // Prevent mutation of Response properties (ESM safety) + return false; + }, + }) as HttpResponse; const responseToParse = responseFormat ? response.clone() : response; const data = !responseFormat @@ -70480,29 +70955,48 @@ export class HttpClient { : payloadFormatter(body), }, ).then(async (response) => { - // Create a wrapper object that doesn't mutate the Response + // Create a Proxy that wraps the Response without mutating it // This ensures compatibility with ESM environments where Response is read-only - const r = { - data: null as unknown as T, - error: null as unknown as E, - // Delegate Response properties - ok: response.ok, - status: response.status, - statusText: response.statusText, - headers: response.headers, - url: response.url, - redirected: response.redirected, - type: response.type, - body: response.body, - bodyUsed: response.bodyUsed, - // Delegate Response methods - arrayBuffer: () => response.arrayBuffer(), - blob: () => response.blob(), - clone: () => response.clone(), - formData: () => response.formData(), - json: () => response.json(), - text: () => response.text(), - } as HttpResponse; + // while maintaining all Response properties and methods as live/dynamic values + const r = new Proxy(response, { + get(target, prop) { + // Custom properties for our API wrapper + if (prop === "data") { + return target._data !== undefined + ? target._data + : (null as unknown as T); + } + if (prop === "error") { + return target._error !== undefined + ? target._error + : (null as unknown as E); + } + + // Delegate everything else to the actual Response object + const value = target[prop]; + + // Bind methods to the original response to maintain correct 'this' context + if (typeof value === "function") { + return value.bind(target); + } + + return value; + }, + set(target, prop, value) { + // Allow setting data and error properties + if (prop === "data") { + target._data = value; + return true; + } + if (prop === "error") { + target._error = value; + return true; + } + + // Prevent mutation of Response properties (ESM safety) + return false; + }, + }) as HttpResponse; const responseToParse = responseFormat ? response.clone() : response; const data = !responseFormat @@ -71085,29 +71579,48 @@ export class HttpClient { : payloadFormatter(body), }, ).then(async (response) => { - // Create a wrapper object that doesn't mutate the Response + // Create a Proxy that wraps the Response without mutating it // This ensures compatibility with ESM environments where Response is read-only - const r = { - data: null as unknown as T, - error: null as unknown as E, - // Delegate Response properties - ok: response.ok, - status: response.status, - statusText: response.statusText, - headers: response.headers, - url: response.url, - redirected: response.redirected, - type: response.type, - body: response.body, - bodyUsed: response.bodyUsed, - // Delegate Response methods - arrayBuffer: () => response.arrayBuffer(), - blob: () => response.blob(), - clone: () => response.clone(), - formData: () => response.formData(), - json: () => response.json(), - text: () => response.text(), - } as HttpResponse; + // while maintaining all Response properties and methods as live/dynamic values + const r = new Proxy(response, { + get(target, prop) { + // Custom properties for our API wrapper + if (prop === "data") { + return target._data !== undefined + ? target._data + : (null as unknown as T); + } + if (prop === "error") { + return target._error !== undefined + ? target._error + : (null as unknown as E); + } + + // Delegate everything else to the actual Response object + const value = target[prop]; + + // Bind methods to the original response to maintain correct 'this' context + if (typeof value === "function") { + return value.bind(target); + } + + return value; + }, + set(target, prop, value) { + // Allow setting data and error properties + if (prop === "data") { + target._data = value; + return true; + } + if (prop === "error") { + target._error = value; + return true; + } + + // Prevent mutation of Response properties (ESM safety) + return false; + }, + }) as HttpResponse; const responseToParse = responseFormat ? response.clone() : response; const data = !responseFormat @@ -71534,29 +72047,48 @@ export class HttpClient { : payloadFormatter(body), }, ).then(async (response) => { - // Create a wrapper object that doesn't mutate the Response + // Create a Proxy that wraps the Response without mutating it // This ensures compatibility with ESM environments where Response is read-only - const r = { - data: null as unknown as T, - error: null as unknown as E, - // Delegate Response properties - ok: response.ok, - status: response.status, - statusText: response.statusText, - headers: response.headers, - url: response.url, - redirected: response.redirected, - type: response.type, - body: response.body, - bodyUsed: response.bodyUsed, - // Delegate Response methods - arrayBuffer: () => response.arrayBuffer(), - blob: () => response.blob(), - clone: () => response.clone(), - formData: () => response.formData(), - json: () => response.json(), - text: () => response.text(), - } as HttpResponse; + // while maintaining all Response properties and methods as live/dynamic values + const r = new Proxy(response, { + get(target, prop) { + // Custom properties for our API wrapper + if (prop === "data") { + return target._data !== undefined + ? target._data + : (null as unknown as T); + } + if (prop === "error") { + return target._error !== undefined + ? target._error + : (null as unknown as E); + } + + // Delegate everything else to the actual Response object + const value = target[prop]; + + // Bind methods to the original response to maintain correct 'this' context + if (typeof value === "function") { + return value.bind(target); + } + + return value; + }, + set(target, prop, value) { + // Allow setting data and error properties + if (prop === "data") { + target._data = value; + return true; + } + if (prop === "error") { + target._error = value; + return true; + } + + // Prevent mutation of Response properties (ESM safety) + return false; + }, + }) as HttpResponse; const responseToParse = responseFormat ? response.clone() : response; const data = !responseFormat @@ -72019,29 +72551,48 @@ export class HttpClient { : payloadFormatter(body), }, ).then(async (response) => { - // Create a wrapper object that doesn't mutate the Response + // Create a Proxy that wraps the Response without mutating it // This ensures compatibility with ESM environments where Response is read-only - const r = { - data: null as unknown as T, - error: null as unknown as E, - // Delegate Response properties - ok: response.ok, - status: response.status, - statusText: response.statusText, - headers: response.headers, - url: response.url, - redirected: response.redirected, - type: response.type, - body: response.body, - bodyUsed: response.bodyUsed, - // Delegate Response methods - arrayBuffer: () => response.arrayBuffer(), - blob: () => response.blob(), - clone: () => response.clone(), - formData: () => response.formData(), - json: () => response.json(), - text: () => response.text(), - } as HttpResponse; + // while maintaining all Response properties and methods as live/dynamic values + const r = new Proxy(response, { + get(target, prop) { + // Custom properties for our API wrapper + if (prop === "data") { + return target._data !== undefined + ? target._data + : (null as unknown as T); + } + if (prop === "error") { + return target._error !== undefined + ? target._error + : (null as unknown as E); + } + + // Delegate everything else to the actual Response object + const value = target[prop]; + + // Bind methods to the original response to maintain correct 'this' context + if (typeof value === "function") { + return value.bind(target); + } + + return value; + }, + set(target, prop, value) { + // Allow setting data and error properties + if (prop === "data") { + target._data = value; + return true; + } + if (prop === "error") { + target._error = value; + return true; + } + + // Prevent mutation of Response properties (ESM safety) + return false; + }, + }) as HttpResponse; const responseToParse = responseFormat ? response.clone() : response; const data = !responseFormat @@ -72568,29 +73119,48 @@ export class HttpClient { : payloadFormatter(body), }, ).then(async (response) => { - // Create a wrapper object that doesn't mutate the Response + // Create a Proxy that wraps the Response without mutating it // This ensures compatibility with ESM environments where Response is read-only - const r = { - data: null as unknown as T, - error: null as unknown as E, - // Delegate Response properties - ok: response.ok, - status: response.status, - statusText: response.statusText, - headers: response.headers, - url: response.url, - redirected: response.redirected, - type: response.type, - body: response.body, - bodyUsed: response.bodyUsed, - // Delegate Response methods - arrayBuffer: () => response.arrayBuffer(), - blob: () => response.blob(), - clone: () => response.clone(), - formData: () => response.formData(), - json: () => response.json(), - text: () => response.text(), - } as HttpResponse; + // while maintaining all Response properties and methods as live/dynamic values + const r = new Proxy(response, { + get(target, prop) { + // Custom properties for our API wrapper + if (prop === "data") { + return target._data !== undefined + ? target._data + : (null as unknown as T); + } + if (prop === "error") { + return target._error !== undefined + ? target._error + : (null as unknown as E); + } + + // Delegate everything else to the actual Response object + const value = target[prop]; + + // Bind methods to the original response to maintain correct 'this' context + if (typeof value === "function") { + return value.bind(target); + } + + return value; + }, + set(target, prop, value) { + // Allow setting data and error properties + if (prop === "data") { + target._data = value; + return true; + } + if (prop === "error") { + target._error = value; + return true; + } + + // Prevent mutation of Response properties (ESM safety) + return false; + }, + }) as HttpResponse; const responseToParse = responseFormat ? response.clone() : response; const data = !responseFormat @@ -72980,29 +73550,48 @@ export class HttpClient { : payloadFormatter(body), }, ).then(async (response) => { - // Create a wrapper object that doesn't mutate the Response + // Create a Proxy that wraps the Response without mutating it // This ensures compatibility with ESM environments where Response is read-only - const r = { - data: null as unknown as T, - error: null as unknown as E, - // Delegate Response properties - ok: response.ok, - status: response.status, - statusText: response.statusText, - headers: response.headers, - url: response.url, - redirected: response.redirected, - type: response.type, - body: response.body, - bodyUsed: response.bodyUsed, - // Delegate Response methods - arrayBuffer: () => response.arrayBuffer(), - blob: () => response.blob(), - clone: () => response.clone(), - formData: () => response.formData(), - json: () => response.json(), - text: () => response.text(), - } as HttpResponse; + // while maintaining all Response properties and methods as live/dynamic values + const r = new Proxy(response, { + get(target, prop) { + // Custom properties for our API wrapper + if (prop === "data") { + return target._data !== undefined + ? target._data + : (null as unknown as T); + } + if (prop === "error") { + return target._error !== undefined + ? target._error + : (null as unknown as E); + } + + // Delegate everything else to the actual Response object + const value = target[prop]; + + // Bind methods to the original response to maintain correct 'this' context + if (typeof value === "function") { + return value.bind(target); + } + + return value; + }, + set(target, prop, value) { + // Allow setting data and error properties + if (prop === "data") { + target._data = value; + return true; + } + if (prop === "error") { + target._error = value; + return true; + } + + // Prevent mutation of Response properties (ESM safety) + return false; + }, + }) as HttpResponse; const responseToParse = responseFormat ? response.clone() : response; const data = !responseFormat @@ -73440,29 +74029,48 @@ export class HttpClient { : payloadFormatter(body), }, ).then(async (response) => { - // Create a wrapper object that doesn't mutate the Response + // Create a Proxy that wraps the Response without mutating it // This ensures compatibility with ESM environments where Response is read-only - const r = { - data: null as unknown as T, - error: null as unknown as E, - // Delegate Response properties - ok: response.ok, - status: response.status, - statusText: response.statusText, - headers: response.headers, - url: response.url, - redirected: response.redirected, - type: response.type, - body: response.body, - bodyUsed: response.bodyUsed, - // Delegate Response methods - arrayBuffer: () => response.arrayBuffer(), - blob: () => response.blob(), - clone: () => response.clone(), - formData: () => response.formData(), - json: () => response.json(), - text: () => response.text(), - } as HttpResponse; + // while maintaining all Response properties and methods as live/dynamic values + const r = new Proxy(response, { + get(target, prop) { + // Custom properties for our API wrapper + if (prop === "data") { + return target._data !== undefined + ? target._data + : (null as unknown as T); + } + if (prop === "error") { + return target._error !== undefined + ? target._error + : (null as unknown as E); + } + + // Delegate everything else to the actual Response object + const value = target[prop]; + + // Bind methods to the original response to maintain correct 'this' context + if (typeof value === "function") { + return value.bind(target); + } + + return value; + }, + set(target, prop, value) { + // Allow setting data and error properties + if (prop === "data") { + target._data = value; + return true; + } + if (prop === "error") { + target._error = value; + return true; + } + + // Prevent mutation of Response properties (ESM safety) + return false; + }, + }) as HttpResponse; const responseToParse = responseFormat ? response.clone() : response; const data = !responseFormat @@ -74397,29 +75005,48 @@ export class HttpClient { : payloadFormatter(body), }, ).then(async (response) => { - // Create a wrapper object that doesn't mutate the Response + // Create a Proxy that wraps the Response without mutating it // This ensures compatibility with ESM environments where Response is read-only - const r = { - data: null as unknown as T, - error: null as unknown as E, - // Delegate Response properties - ok: response.ok, - status: response.status, - statusText: response.statusText, - headers: response.headers, - url: response.url, - redirected: response.redirected, - type: response.type, - body: response.body, - bodyUsed: response.bodyUsed, - // Delegate Response methods - arrayBuffer: () => response.arrayBuffer(), - blob: () => response.blob(), - clone: () => response.clone(), - formData: () => response.formData(), - json: () => response.json(), - text: () => response.text(), - } as HttpResponse; + // while maintaining all Response properties and methods as live/dynamic values + const r = new Proxy(response, { + get(target, prop) { + // Custom properties for our API wrapper + if (prop === "data") { + return target._data !== undefined + ? target._data + : (null as unknown as T); + } + if (prop === "error") { + return target._error !== undefined + ? target._error + : (null as unknown as E); + } + + // Delegate everything else to the actual Response object + const value = target[prop]; + + // Bind methods to the original response to maintain correct 'this' context + if (typeof value === "function") { + return value.bind(target); + } + + return value; + }, + set(target, prop, value) { + // Allow setting data and error properties + if (prop === "data") { + target._data = value; + return true; + } + if (prop === "error") { + target._error = value; + return true; + } + + // Prevent mutation of Response properties (ESM safety) + return false; + }, + }) as HttpResponse; const responseToParse = responseFormat ? response.clone() : response; const data = !responseFormat @@ -75226,29 +75853,48 @@ export class HttpClient { : payloadFormatter(body), }, ).then(async (response) => { - // Create a wrapper object that doesn't mutate the Response + // Create a Proxy that wraps the Response without mutating it // This ensures compatibility with ESM environments where Response is read-only - const r = { - data: null as unknown as T, - error: null as unknown as E, - // Delegate Response properties - ok: response.ok, - status: response.status, - statusText: response.statusText, - headers: response.headers, - url: response.url, - redirected: response.redirected, - type: response.type, - body: response.body, - bodyUsed: response.bodyUsed, - // Delegate Response methods - arrayBuffer: () => response.arrayBuffer(), - blob: () => response.blob(), - clone: () => response.clone(), - formData: () => response.formData(), - json: () => response.json(), - text: () => response.text(), - } as HttpResponse; + // while maintaining all Response properties and methods as live/dynamic values + const r = new Proxy(response, { + get(target, prop) { + // Custom properties for our API wrapper + if (prop === "data") { + return target._data !== undefined + ? target._data + : (null as unknown as T); + } + if (prop === "error") { + return target._error !== undefined + ? target._error + : (null as unknown as E); + } + + // Delegate everything else to the actual Response object + const value = target[prop]; + + // Bind methods to the original response to maintain correct 'this' context + if (typeof value === "function") { + return value.bind(target); + } + + return value; + }, + set(target, prop, value) { + // Allow setting data and error properties + if (prop === "data") { + target._data = value; + return true; + } + if (prop === "error") { + target._error = value; + return true; + } + + // Prevent mutation of Response properties (ESM safety) + return false; + }, + }) as HttpResponse; const responseToParse = responseFormat ? response.clone() : response; const data = !responseFormat @@ -75641,29 +76287,48 @@ export class HttpClient { : payloadFormatter(body), }, ).then(async (response) => { - // Create a wrapper object that doesn't mutate the Response + // Create a Proxy that wraps the Response without mutating it // This ensures compatibility with ESM environments where Response is read-only - const r = { - data: null as unknown as T, - error: null as unknown as E, - // Delegate Response properties - ok: response.ok, - status: response.status, - statusText: response.statusText, - headers: response.headers, - url: response.url, - redirected: response.redirected, - type: response.type, - body: response.body, - bodyUsed: response.bodyUsed, - // Delegate Response methods - arrayBuffer: () => response.arrayBuffer(), - blob: () => response.blob(), - clone: () => response.clone(), - formData: () => response.formData(), - json: () => response.json(), - text: () => response.text(), - } as HttpResponse; + // while maintaining all Response properties and methods as live/dynamic values + const r = new Proxy(response, { + get(target, prop) { + // Custom properties for our API wrapper + if (prop === "data") { + return target._data !== undefined + ? target._data + : (null as unknown as T); + } + if (prop === "error") { + return target._error !== undefined + ? target._error + : (null as unknown as E); + } + + // Delegate everything else to the actual Response object + const value = target[prop]; + + // Bind methods to the original response to maintain correct 'this' context + if (typeof value === "function") { + return value.bind(target); + } + + return value; + }, + set(target, prop, value) { + // Allow setting data and error properties + if (prop === "data") { + target._data = value; + return true; + } + if (prop === "error") { + target._error = value; + return true; + } + + // Prevent mutation of Response properties (ESM safety) + return false; + }, + }) as HttpResponse; const responseToParse = responseFormat ? response.clone() : response; const data = !responseFormat @@ -75974,29 +76639,48 @@ export class HttpClient { : payloadFormatter(body), }, ).then(async (response) => { - // Create a wrapper object that doesn't mutate the Response + // Create a Proxy that wraps the Response without mutating it // This ensures compatibility with ESM environments where Response is read-only - const r = { - data: null as unknown as T, - error: null as unknown as E, - // Delegate Response properties - ok: response.ok, - status: response.status, - statusText: response.statusText, - headers: response.headers, - url: response.url, - redirected: response.redirected, - type: response.type, - body: response.body, - bodyUsed: response.bodyUsed, - // Delegate Response methods - arrayBuffer: () => response.arrayBuffer(), - blob: () => response.blob(), - clone: () => response.clone(), - formData: () => response.formData(), - json: () => response.json(), - text: () => response.text(), - } as HttpResponse; + // while maintaining all Response properties and methods as live/dynamic values + const r = new Proxy(response, { + get(target, prop) { + // Custom properties for our API wrapper + if (prop === "data") { + return target._data !== undefined + ? target._data + : (null as unknown as T); + } + if (prop === "error") { + return target._error !== undefined + ? target._error + : (null as unknown as E); + } + + // Delegate everything else to the actual Response object + const value = target[prop]; + + // Bind methods to the original response to maintain correct 'this' context + if (typeof value === "function") { + return value.bind(target); + } + + return value; + }, + set(target, prop, value) { + // Allow setting data and error properties + if (prop === "data") { + target._data = value; + return true; + } + if (prop === "error") { + target._error = value; + return true; + } + + // Prevent mutation of Response properties (ESM safety) + return false; + }, + }) as HttpResponse; const responseToParse = responseFormat ? response.clone() : response; const data = !responseFormat @@ -76290,29 +76974,48 @@ export class HttpClient { : payloadFormatter(body), }, ).then(async (response) => { - // Create a wrapper object that doesn't mutate the Response + // Create a Proxy that wraps the Response without mutating it // This ensures compatibility with ESM environments where Response is read-only - const r = { - data: null as unknown as T, - error: null as unknown as E, - // Delegate Response properties - ok: response.ok, - status: response.status, - statusText: response.statusText, - headers: response.headers, - url: response.url, - redirected: response.redirected, - type: response.type, - body: response.body, - bodyUsed: response.bodyUsed, - // Delegate Response methods - arrayBuffer: () => response.arrayBuffer(), - blob: () => response.blob(), - clone: () => response.clone(), - formData: () => response.formData(), - json: () => response.json(), - text: () => response.text(), - } as HttpResponse; + // while maintaining all Response properties and methods as live/dynamic values + const r = new Proxy(response, { + get(target, prop) { + // Custom properties for our API wrapper + if (prop === "data") { + return target._data !== undefined + ? target._data + : (null as unknown as T); + } + if (prop === "error") { + return target._error !== undefined + ? target._error + : (null as unknown as E); + } + + // Delegate everything else to the actual Response object + const value = target[prop]; + + // Bind methods to the original response to maintain correct 'this' context + if (typeof value === "function") { + return value.bind(target); + } + + return value; + }, + set(target, prop, value) { + // Allow setting data and error properties + if (prop === "data") { + target._data = value; + return true; + } + if (prop === "error") { + target._error = value; + return true; + } + + // Prevent mutation of Response properties (ESM safety) + return false; + }, + }) as HttpResponse; const responseToParse = responseFormat ? response.clone() : response; const data = !responseFormat @@ -76644,29 +77347,48 @@ export class HttpClient { : payloadFormatter(body), }, ).then(async (response) => { - // Create a wrapper object that doesn't mutate the Response + // Create a Proxy that wraps the Response without mutating it // This ensures compatibility with ESM environments where Response is read-only - const r = { - data: null as unknown as T, - error: null as unknown as E, - // Delegate Response properties - ok: response.ok, - status: response.status, - statusText: response.statusText, - headers: response.headers, - url: response.url, - redirected: response.redirected, - type: response.type, - body: response.body, - bodyUsed: response.bodyUsed, - // Delegate Response methods - arrayBuffer: () => response.arrayBuffer(), - blob: () => response.blob(), - clone: () => response.clone(), - formData: () => response.formData(), - json: () => response.json(), - text: () => response.text(), - } as HttpResponse; + // while maintaining all Response properties and methods as live/dynamic values + const r = new Proxy(response, { + get(target, prop) { + // Custom properties for our API wrapper + if (prop === "data") { + return target._data !== undefined + ? target._data + : (null as unknown as T); + } + if (prop === "error") { + return target._error !== undefined + ? target._error + : (null as unknown as E); + } + + // Delegate everything else to the actual Response object + const value = target[prop]; + + // Bind methods to the original response to maintain correct 'this' context + if (typeof value === "function") { + return value.bind(target); + } + + return value; + }, + set(target, prop, value) { + // Allow setting data and error properties + if (prop === "data") { + target._data = value; + return true; + } + if (prop === "error") { + target._error = value; + return true; + } + + // Prevent mutation of Response properties (ESM safety) + return false; + }, + }) as HttpResponse; const responseToParse = responseFormat ? response.clone() : response; const data = !responseFormat @@ -77407,29 +78129,48 @@ export class HttpClient { : payloadFormatter(body), }, ).then(async (response) => { - // Create a wrapper object that doesn't mutate the Response + // Create a Proxy that wraps the Response without mutating it // This ensures compatibility with ESM environments where Response is read-only - const r = { - data: null as unknown as T, - error: null as unknown as E, - // Delegate Response properties - ok: response.ok, - status: response.status, - statusText: response.statusText, - headers: response.headers, - url: response.url, - redirected: response.redirected, - type: response.type, - body: response.body, - bodyUsed: response.bodyUsed, - // Delegate Response methods - arrayBuffer: () => response.arrayBuffer(), - blob: () => response.blob(), - clone: () => response.clone(), - formData: () => response.formData(), - json: () => response.json(), - text: () => response.text(), - } as HttpResponse; + // while maintaining all Response properties and methods as live/dynamic values + const r = new Proxy(response, { + get(target, prop) { + // Custom properties for our API wrapper + if (prop === "data") { + return target._data !== undefined + ? target._data + : (null as unknown as T); + } + if (prop === "error") { + return target._error !== undefined + ? target._error + : (null as unknown as E); + } + + // Delegate everything else to the actual Response object + const value = target[prop]; + + // Bind methods to the original response to maintain correct 'this' context + if (typeof value === "function") { + return value.bind(target); + } + + return value; + }, + set(target, prop, value) { + // Allow setting data and error properties + if (prop === "data") { + target._data = value; + return true; + } + if (prop === "error") { + target._error = value; + return true; + } + + // Prevent mutation of Response properties (ESM safety) + return false; + }, + }) as HttpResponse; const responseToParse = responseFormat ? response.clone() : response; const data = !responseFormat @@ -78326,29 +79067,48 @@ export class HttpClient { : payloadFormatter(body), }, ).then(async (response) => { - // Create a wrapper object that doesn't mutate the Response + // Create a Proxy that wraps the Response without mutating it // This ensures compatibility with ESM environments where Response is read-only - const r = { - data: null as unknown as T, - error: null as unknown as E, - // Delegate Response properties - ok: response.ok, - status: response.status, - statusText: response.statusText, - headers: response.headers, - url: response.url, - redirected: response.redirected, - type: response.type, - body: response.body, - bodyUsed: response.bodyUsed, - // Delegate Response methods - arrayBuffer: () => response.arrayBuffer(), - blob: () => response.blob(), - clone: () => response.clone(), - formData: () => response.formData(), - json: () => response.json(), - text: () => response.text(), - } as HttpResponse; + // while maintaining all Response properties and methods as live/dynamic values + const r = new Proxy(response, { + get(target, prop) { + // Custom properties for our API wrapper + if (prop === "data") { + return target._data !== undefined + ? target._data + : (null as unknown as T); + } + if (prop === "error") { + return target._error !== undefined + ? target._error + : (null as unknown as E); + } + + // Delegate everything else to the actual Response object + const value = target[prop]; + + // Bind methods to the original response to maintain correct 'this' context + if (typeof value === "function") { + return value.bind(target); + } + + return value; + }, + set(target, prop, value) { + // Allow setting data and error properties + if (prop === "data") { + target._data = value; + return true; + } + if (prop === "error") { + target._error = value; + return true; + } + + // Prevent mutation of Response properties (ESM safety) + return false; + }, + }) as HttpResponse; const responseToParse = responseFormat ? response.clone() : response; const data = !responseFormat @@ -80172,29 +80932,48 @@ export class HttpClient { : payloadFormatter(body), }, ).then(async (response) => { - // Create a wrapper object that doesn't mutate the Response + // Create a Proxy that wraps the Response without mutating it // This ensures compatibility with ESM environments where Response is read-only - const r = { - data: null as unknown as T, - error: null as unknown as E, - // Delegate Response properties - ok: response.ok, - status: response.status, - statusText: response.statusText, - headers: response.headers, - url: response.url, - redirected: response.redirected, - type: response.type, - body: response.body, - bodyUsed: response.bodyUsed, - // Delegate Response methods - arrayBuffer: () => response.arrayBuffer(), - blob: () => response.blob(), - clone: () => response.clone(), - formData: () => response.formData(), - json: () => response.json(), - text: () => response.text(), - } as HttpResponse; + // while maintaining all Response properties and methods as live/dynamic values + const r = new Proxy(response, { + get(target, prop) { + // Custom properties for our API wrapper + if (prop === "data") { + return target._data !== undefined + ? target._data + : (null as unknown as T); + } + if (prop === "error") { + return target._error !== undefined + ? target._error + : (null as unknown as E); + } + + // Delegate everything else to the actual Response object + const value = target[prop]; + + // Bind methods to the original response to maintain correct 'this' context + if (typeof value === "function") { + return value.bind(target); + } + + return value; + }, + set(target, prop, value) { + // Allow setting data and error properties + if (prop === "data") { + target._data = value; + return true; + } + if (prop === "error") { + target._error = value; + return true; + } + + // Prevent mutation of Response properties (ESM safety) + return false; + }, + }) as HttpResponse; const responseToParse = responseFormat ? response.clone() : response; const data = !responseFormat @@ -80973,29 +81752,48 @@ export class HttpClient { : payloadFormatter(body), }, ).then(async (response) => { - // Create a wrapper object that doesn't mutate the Response + // Create a Proxy that wraps the Response without mutating it // This ensures compatibility with ESM environments where Response is read-only - const r = { - data: null as unknown as T, - error: null as unknown as E, - // Delegate Response properties - ok: response.ok, - status: response.status, - statusText: response.statusText, - headers: response.headers, - url: response.url, - redirected: response.redirected, - type: response.type, - body: response.body, - bodyUsed: response.bodyUsed, - // Delegate Response methods - arrayBuffer: () => response.arrayBuffer(), - blob: () => response.blob(), - clone: () => response.clone(), - formData: () => response.formData(), - json: () => response.json(), - text: () => response.text(), - } as HttpResponse; + // while maintaining all Response properties and methods as live/dynamic values + const r = new Proxy(response, { + get(target, prop) { + // Custom properties for our API wrapper + if (prop === "data") { + return target._data !== undefined + ? target._data + : (null as unknown as T); + } + if (prop === "error") { + return target._error !== undefined + ? target._error + : (null as unknown as E); + } + + // Delegate everything else to the actual Response object + const value = target[prop]; + + // Bind methods to the original response to maintain correct 'this' context + if (typeof value === "function") { + return value.bind(target); + } + + return value; + }, + set(target, prop, value) { + // Allow setting data and error properties + if (prop === "data") { + target._data = value; + return true; + } + if (prop === "error") { + target._error = value; + return true; + } + + // Prevent mutation of Response properties (ESM safety) + return false; + }, + }) as HttpResponse; const responseToParse = responseFormat ? response.clone() : response; const data = !responseFormat @@ -81344,29 +82142,48 @@ export class HttpClient { : payloadFormatter(body), }, ).then(async (response) => { - // Create a wrapper object that doesn't mutate the Response + // Create a Proxy that wraps the Response without mutating it // This ensures compatibility with ESM environments where Response is read-only - const r = { - data: null as unknown as T, - error: null as unknown as E, - // Delegate Response properties - ok: response.ok, - status: response.status, - statusText: response.statusText, - headers: response.headers, - url: response.url, - redirected: response.redirected, - type: response.type, - body: response.body, - bodyUsed: response.bodyUsed, - // Delegate Response methods - arrayBuffer: () => response.arrayBuffer(), - blob: () => response.blob(), - clone: () => response.clone(), - formData: () => response.formData(), - json: () => response.json(), - text: () => response.text(), - } as HttpResponse; + // while maintaining all Response properties and methods as live/dynamic values + const r = new Proxy(response, { + get(target, prop) { + // Custom properties for our API wrapper + if (prop === "data") { + return target._data !== undefined + ? target._data + : (null as unknown as T); + } + if (prop === "error") { + return target._error !== undefined + ? target._error + : (null as unknown as E); + } + + // Delegate everything else to the actual Response object + const value = target[prop]; + + // Bind methods to the original response to maintain correct 'this' context + if (typeof value === "function") { + return value.bind(target); + } + + return value; + }, + set(target, prop, value) { + // Allow setting data and error properties + if (prop === "data") { + target._data = value; + return true; + } + if (prop === "error") { + target._error = value; + return true; + } + + // Prevent mutation of Response properties (ESM safety) + return false; + }, + }) as HttpResponse; const responseToParse = responseFormat ? response.clone() : response; const data = !responseFormat @@ -81821,29 +82638,48 @@ export class HttpClient { : payloadFormatter(body), }, ).then(async (response) => { - // Create a wrapper object that doesn't mutate the Response + // Create a Proxy that wraps the Response without mutating it // This ensures compatibility with ESM environments where Response is read-only - const r = { - data: null as unknown as T, - error: null as unknown as E, - // Delegate Response properties - ok: response.ok, - status: response.status, - statusText: response.statusText, - headers: response.headers, - url: response.url, - redirected: response.redirected, - type: response.type, - body: response.body, - bodyUsed: response.bodyUsed, - // Delegate Response methods - arrayBuffer: () => response.arrayBuffer(), - blob: () => response.blob(), - clone: () => response.clone(), - formData: () => response.formData(), - json: () => response.json(), - text: () => response.text(), - } as HttpResponse; + // while maintaining all Response properties and methods as live/dynamic values + const r = new Proxy(response, { + get(target, prop) { + // Custom properties for our API wrapper + if (prop === "data") { + return target._data !== undefined + ? target._data + : (null as unknown as T); + } + if (prop === "error") { + return target._error !== undefined + ? target._error + : (null as unknown as E); + } + + // Delegate everything else to the actual Response object + const value = target[prop]; + + // Bind methods to the original response to maintain correct 'this' context + if (typeof value === "function") { + return value.bind(target); + } + + return value; + }, + set(target, prop, value) { + // Allow setting data and error properties + if (prop === "data") { + target._data = value; + return true; + } + if (prop === "error") { + target._error = value; + return true; + } + + // Prevent mutation of Response properties (ESM safety) + return false; + }, + }) as HttpResponse; const responseToParse = responseFormat ? response.clone() : response; const data = !responseFormat diff --git a/tests/__snapshots__/simple.test.ts.snap b/tests/__snapshots__/simple.test.ts.snap index 36c5efc5..8cf08192 100644 --- a/tests/__snapshots__/simple.test.ts.snap +++ b/tests/__snapshots__/simple.test.ts.snap @@ -394,29 +394,48 @@ export class HttpClient { : payloadFormatter(body), }, ).then(async (response) => { - // Create a wrapper object that doesn't mutate the Response + // Create a Proxy that wraps the Response without mutating it // This ensures compatibility with ESM environments where Response is read-only - const r = { - data: null as unknown as T, - error: null as unknown as E, - // Delegate Response properties - ok: response.ok, - status: response.status, - statusText: response.statusText, - headers: response.headers, - url: response.url, - redirected: response.redirected, - type: response.type, - body: response.body, - bodyUsed: response.bodyUsed, - // Delegate Response methods - arrayBuffer: () => response.arrayBuffer(), - blob: () => response.blob(), - clone: () => response.clone(), - formData: () => response.formData(), - json: () => response.json(), - text: () => response.text(), - } as HttpResponse; + // while maintaining all Response properties and methods as live/dynamic values + const r = new Proxy(response, { + get(target, prop) { + // Custom properties for our API wrapper + if (prop === "data") { + return target._data !== undefined + ? target._data + : (null as unknown as T); + } + if (prop === "error") { + return target._error !== undefined + ? target._error + : (null as unknown as E); + } + + // Delegate everything else to the actual Response object + const value = target[prop]; + + // Bind methods to the original response to maintain correct 'this' context + if (typeof value === "function") { + return value.bind(target); + } + + return value; + }, + set(target, prop, value) { + // Allow setting data and error properties + if (prop === "data") { + target._data = value; + return true; + } + if (prop === "error") { + target._error = value; + return true; + } + + // Prevent mutation of Response properties (ESM safety) + return false; + }, + }) as HttpResponse; const responseToParse = responseFormat ? response.clone() : response; const data = !responseFormat @@ -2766,29 +2785,48 @@ export class HttpClient { : payloadFormatter(body), }, ).then(async (response) => { - // Create a wrapper object that doesn't mutate the Response + // Create a Proxy that wraps the Response without mutating it // This ensures compatibility with ESM environments where Response is read-only - const r = { - data: null as unknown as T, - error: null as unknown as E, - // Delegate Response properties - ok: response.ok, - status: response.status, - statusText: response.statusText, - headers: response.headers, - url: response.url, - redirected: response.redirected, - type: response.type, - body: response.body, - bodyUsed: response.bodyUsed, - // Delegate Response methods - arrayBuffer: () => response.arrayBuffer(), - blob: () => response.blob(), - clone: () => response.clone(), - formData: () => response.formData(), - json: () => response.json(), - text: () => response.text(), - } as HttpResponse; + // while maintaining all Response properties and methods as live/dynamic values + const r = new Proxy(response, { + get(target, prop) { + // Custom properties for our API wrapper + if (prop === "data") { + return target._data !== undefined + ? target._data + : (null as unknown as T); + } + if (prop === "error") { + return target._error !== undefined + ? target._error + : (null as unknown as E); + } + + // Delegate everything else to the actual Response object + const value = target[prop]; + + // Bind methods to the original response to maintain correct 'this' context + if (typeof value === "function") { + return value.bind(target); + } + + return value; + }, + set(target, prop, value) { + // Allow setting data and error properties + if (prop === "data") { + target._data = value; + return true; + } + if (prop === "error") { + target._error = value; + return true; + } + + // Prevent mutation of Response properties (ESM safety) + return false; + }, + }) as HttpResponse; const responseToParse = responseFormat ? response.clone() : response; const data = !responseFormat @@ -3068,29 +3106,48 @@ export class HttpClient { : payloadFormatter(body), }, ).then(async (response) => { - // Create a wrapper object that doesn't mutate the Response + // Create a Proxy that wraps the Response without mutating it // This ensures compatibility with ESM environments where Response is read-only - const r = { - data: null as unknown as T, - error: null as unknown as E, - // Delegate Response properties - ok: response.ok, - status: response.status, - statusText: response.statusText, - headers: response.headers, - url: response.url, - redirected: response.redirected, - type: response.type, - body: response.body, - bodyUsed: response.bodyUsed, - // Delegate Response methods - arrayBuffer: () => response.arrayBuffer(), - blob: () => response.blob(), - clone: () => response.clone(), - formData: () => response.formData(), - json: () => response.json(), - text: () => response.text(), - } as HttpResponse; + // while maintaining all Response properties and methods as live/dynamic values + const r = new Proxy(response, { + get(target, prop) { + // Custom properties for our API wrapper + if (prop === "data") { + return target._data !== undefined + ? target._data + : (null as unknown as T); + } + if (prop === "error") { + return target._error !== undefined + ? target._error + : (null as unknown as E); + } + + // Delegate everything else to the actual Response object + const value = target[prop]; + + // Bind methods to the original response to maintain correct 'this' context + if (typeof value === "function") { + return value.bind(target); + } + + return value; + }, + set(target, prop, value) { + // Allow setting data and error properties + if (prop === "data") { + target._data = value; + return true; + } + if (prop === "error") { + target._error = value; + return true; + } + + // Prevent mutation of Response properties (ESM safety) + return false; + }, + }) as HttpResponse; const responseToParse = responseFormat ? response.clone() : response; const data = !responseFormat @@ -3379,29 +3436,48 @@ export class HttpClient { : payloadFormatter(body), }, ).then(async (response) => { - // Create a wrapper object that doesn't mutate the Response + // Create a Proxy that wraps the Response without mutating it // This ensures compatibility with ESM environments where Response is read-only - const r = { - data: null as unknown as T, - error: null as unknown as E, - // Delegate Response properties - ok: response.ok, - status: response.status, - statusText: response.statusText, - headers: response.headers, - url: response.url, - redirected: response.redirected, - type: response.type, - body: response.body, - bodyUsed: response.bodyUsed, - // Delegate Response methods - arrayBuffer: () => response.arrayBuffer(), - blob: () => response.blob(), - clone: () => response.clone(), - formData: () => response.formData(), - json: () => response.json(), - text: () => response.text(), - } as HttpResponse; + // while maintaining all Response properties and methods as live/dynamic values + const r = new Proxy(response, { + get(target, prop) { + // Custom properties for our API wrapper + if (prop === "data") { + return target._data !== undefined + ? target._data + : (null as unknown as T); + } + if (prop === "error") { + return target._error !== undefined + ? target._error + : (null as unknown as E); + } + + // Delegate everything else to the actual Response object + const value = target[prop]; + + // Bind methods to the original response to maintain correct 'this' context + if (typeof value === "function") { + return value.bind(target); + } + + return value; + }, + set(target, prop, value) { + // Allow setting data and error properties + if (prop === "data") { + target._data = value; + return true; + } + if (prop === "error") { + target._error = value; + return true; + } + + // Prevent mutation of Response properties (ESM safety) + return false; + }, + }) as HttpResponse; const responseToParse = responseFormat ? response.clone() : response; const data = !responseFormat @@ -3827,29 +3903,48 @@ export class HttpClient { : payloadFormatter(body), }, ).then(async (response) => { - // Create a wrapper object that doesn't mutate the Response + // Create a Proxy that wraps the Response without mutating it // This ensures compatibility with ESM environments where Response is read-only - const r = { - data: null as unknown as T, - error: null as unknown as E, - // Delegate Response properties - ok: response.ok, - status: response.status, - statusText: response.statusText, - headers: response.headers, - url: response.url, - redirected: response.redirected, - type: response.type, - body: response.body, - bodyUsed: response.bodyUsed, - // Delegate Response methods - arrayBuffer: () => response.arrayBuffer(), - blob: () => response.blob(), - clone: () => response.clone(), - formData: () => response.formData(), - json: () => response.json(), - text: () => response.text(), - } as HttpResponse; + // while maintaining all Response properties and methods as live/dynamic values + const r = new Proxy(response, { + get(target, prop) { + // Custom properties for our API wrapper + if (prop === "data") { + return target._data !== undefined + ? target._data + : (null as unknown as T); + } + if (prop === "error") { + return target._error !== undefined + ? target._error + : (null as unknown as E); + } + + // Delegate everything else to the actual Response object + const value = target[prop]; + + // Bind methods to the original response to maintain correct 'this' context + if (typeof value === "function") { + return value.bind(target); + } + + return value; + }, + set(target, prop, value) { + // Allow setting data and error properties + if (prop === "data") { + target._data = value; + return true; + } + if (prop === "error") { + target._error = value; + return true; + } + + // Prevent mutation of Response properties (ESM safety) + return false; + }, + }) as HttpResponse; const responseToParse = responseFormat ? response.clone() : response; const data = !responseFormat @@ -4618,29 +4713,48 @@ export class HttpClient { : payloadFormatter(body), }, ).then(async (response) => { - // Create a wrapper object that doesn't mutate the Response + // Create a Proxy that wraps the Response without mutating it // This ensures compatibility with ESM environments where Response is read-only - const r = { - data: null as unknown as T, - error: null as unknown as E, - // Delegate Response properties - ok: response.ok, - status: response.status, - statusText: response.statusText, - headers: response.headers, - url: response.url, - redirected: response.redirected, - type: response.type, - body: response.body, - bodyUsed: response.bodyUsed, - // Delegate Response methods - arrayBuffer: () => response.arrayBuffer(), - blob: () => response.blob(), - clone: () => response.clone(), - formData: () => response.formData(), - json: () => response.json(), - text: () => response.text(), - } as HttpResponse; + // while maintaining all Response properties and methods as live/dynamic values + const r = new Proxy(response, { + get(target, prop) { + // Custom properties for our API wrapper + if (prop === "data") { + return target._data !== undefined + ? target._data + : (null as unknown as T); + } + if (prop === "error") { + return target._error !== undefined + ? target._error + : (null as unknown as E); + } + + // Delegate everything else to the actual Response object + const value = target[prop]; + + // Bind methods to the original response to maintain correct 'this' context + if (typeof value === "function") { + return value.bind(target); + } + + return value; + }, + set(target, prop, value) { + // Allow setting data and error properties + if (prop === "data") { + target._data = value; + return true; + } + if (prop === "error") { + target._error = value; + return true; + } + + // Prevent mutation of Response properties (ESM safety) + return false; + }, + }) as HttpResponse; const responseToParse = responseFormat ? response.clone() : response; const data = !responseFormat @@ -4980,29 +5094,48 @@ export class HttpClient { : payloadFormatter(body), }, ).then(async (response) => { - // Create a wrapper object that doesn't mutate the Response + // Create a Proxy that wraps the Response without mutating it // This ensures compatibility with ESM environments where Response is read-only - const r = { - data: null as unknown as T, - error: null as unknown as E, - // Delegate Response properties - ok: response.ok, - status: response.status, - statusText: response.statusText, - headers: response.headers, - url: response.url, - redirected: response.redirected, - type: response.type, - body: response.body, - bodyUsed: response.bodyUsed, - // Delegate Response methods - arrayBuffer: () => response.arrayBuffer(), - blob: () => response.blob(), - clone: () => response.clone(), - formData: () => response.formData(), - json: () => response.json(), - text: () => response.text(), - } as HttpResponse; + // while maintaining all Response properties and methods as live/dynamic values + const r = new Proxy(response, { + get(target, prop) { + // Custom properties for our API wrapper + if (prop === "data") { + return target._data !== undefined + ? target._data + : (null as unknown as T); + } + if (prop === "error") { + return target._error !== undefined + ? target._error + : (null as unknown as E); + } + + // Delegate everything else to the actual Response object + const value = target[prop]; + + // Bind methods to the original response to maintain correct 'this' context + if (typeof value === "function") { + return value.bind(target); + } + + return value; + }, + set(target, prop, value) { + // Allow setting data and error properties + if (prop === "data") { + target._data = value; + return true; + } + if (prop === "error") { + target._error = value; + return true; + } + + // Prevent mutation of Response properties (ESM safety) + return false; + }, + }) as HttpResponse; const responseToParse = responseFormat ? response.clone() : response; const data = !responseFormat @@ -5298,29 +5431,48 @@ export class HttpClient { : payloadFormatter(body), }, ).then(async (response) => { - // Create a wrapper object that doesn't mutate the Response + // Create a Proxy that wraps the Response without mutating it // This ensures compatibility with ESM environments where Response is read-only - const r = { - data: null as unknown as T, - error: null as unknown as E, - // Delegate Response properties - ok: response.ok, - status: response.status, - statusText: response.statusText, - headers: response.headers, - url: response.url, - redirected: response.redirected, - type: response.type, - body: response.body, - bodyUsed: response.bodyUsed, - // Delegate Response methods - arrayBuffer: () => response.arrayBuffer(), - blob: () => response.blob(), - clone: () => response.clone(), - formData: () => response.formData(), - json: () => response.json(), - text: () => response.text(), - } as HttpResponse; + // while maintaining all Response properties and methods as live/dynamic values + const r = new Proxy(response, { + get(target, prop) { + // Custom properties for our API wrapper + if (prop === "data") { + return target._data !== undefined + ? target._data + : (null as unknown as T); + } + if (prop === "error") { + return target._error !== undefined + ? target._error + : (null as unknown as E); + } + + // Delegate everything else to the actual Response object + const value = target[prop]; + + // Bind methods to the original response to maintain correct 'this' context + if (typeof value === "function") { + return value.bind(target); + } + + return value; + }, + set(target, prop, value) { + // Allow setting data and error properties + if (prop === "data") { + target._data = value; + return true; + } + if (prop === "error") { + target._error = value; + return true; + } + + // Prevent mutation of Response properties (ESM safety) + return false; + }, + }) as HttpResponse; const responseToParse = responseFormat ? response.clone() : response; const data = !responseFormat @@ -5628,29 +5780,48 @@ export class HttpClient { : payloadFormatter(body), }, ).then(async (response) => { - // Create a wrapper object that doesn't mutate the Response + // Create a Proxy that wraps the Response without mutating it // This ensures compatibility with ESM environments where Response is read-only - const r = { - data: null as unknown as T, - error: null as unknown as E, - // Delegate Response properties - ok: response.ok, - status: response.status, - statusText: response.statusText, - headers: response.headers, - url: response.url, - redirected: response.redirected, - type: response.type, - body: response.body, - bodyUsed: response.bodyUsed, - // Delegate Response methods - arrayBuffer: () => response.arrayBuffer(), - blob: () => response.blob(), - clone: () => response.clone(), - formData: () => response.formData(), - json: () => response.json(), - text: () => response.text(), - } as HttpResponse; + // while maintaining all Response properties and methods as live/dynamic values + const r = new Proxy(response, { + get(target, prop) { + // Custom properties for our API wrapper + if (prop === "data") { + return target._data !== undefined + ? target._data + : (null as unknown as T); + } + if (prop === "error") { + return target._error !== undefined + ? target._error + : (null as unknown as E); + } + + // Delegate everything else to the actual Response object + const value = target[prop]; + + // Bind methods to the original response to maintain correct 'this' context + if (typeof value === "function") { + return value.bind(target); + } + + return value; + }, + set(target, prop, value) { + // Allow setting data and error properties + if (prop === "data") { + target._data = value; + return true; + } + if (prop === "error") { + target._error = value; + return true; + } + + // Prevent mutation of Response properties (ESM safety) + return false; + }, + }) as HttpResponse; const responseToParse = responseFormat ? response.clone() : response; const data = !responseFormat @@ -6032,29 +6203,48 @@ export class HttpClient { : payloadFormatter(body), }, ).then(async (response) => { - // Create a wrapper object that doesn't mutate the Response + // Create a Proxy that wraps the Response without mutating it // This ensures compatibility with ESM environments where Response is read-only - const r = { - data: null as unknown as T, - error: null as unknown as E, - // Delegate Response properties - ok: response.ok, - status: response.status, - statusText: response.statusText, - headers: response.headers, - url: response.url, - redirected: response.redirected, - type: response.type, - body: response.body, - bodyUsed: response.bodyUsed, - // Delegate Response methods - arrayBuffer: () => response.arrayBuffer(), - blob: () => response.blob(), - clone: () => response.clone(), - formData: () => response.formData(), - json: () => response.json(), - text: () => response.text(), - } as HttpResponse; + // while maintaining all Response properties and methods as live/dynamic values + const r = new Proxy(response, { + get(target, prop) { + // Custom properties for our API wrapper + if (prop === "data") { + return target._data !== undefined + ? target._data + : (null as unknown as T); + } + if (prop === "error") { + return target._error !== undefined + ? target._error + : (null as unknown as E); + } + + // Delegate everything else to the actual Response object + const value = target[prop]; + + // Bind methods to the original response to maintain correct 'this' context + if (typeof value === "function") { + return value.bind(target); + } + + return value; + }, + set(target, prop, value) { + // Allow setting data and error properties + if (prop === "data") { + target._data = value; + return true; + } + if (prop === "error") { + target._error = value; + return true; + } + + // Prevent mutation of Response properties (ESM safety) + return false; + }, + }) as HttpResponse; const responseToParse = responseFormat ? response.clone() : response; const data = !responseFormat @@ -6707,29 +6897,48 @@ export class HttpClient { : payloadFormatter(body), }, ).then(async (response) => { - // Create a wrapper object that doesn't mutate the Response + // Create a Proxy that wraps the Response without mutating it // This ensures compatibility with ESM environments where Response is read-only - const r = { - data: null as unknown as T, - error: null as unknown as E, - // Delegate Response properties - ok: response.ok, - status: response.status, - statusText: response.statusText, - headers: response.headers, - url: response.url, - redirected: response.redirected, - type: response.type, - body: response.body, - bodyUsed: response.bodyUsed, - // Delegate Response methods - arrayBuffer: () => response.arrayBuffer(), - blob: () => response.blob(), - clone: () => response.clone(), - formData: () => response.formData(), - json: () => response.json(), - text: () => response.text(), - } as HttpResponse; + // while maintaining all Response properties and methods as live/dynamic values + const r = new Proxy(response, { + get(target, prop) { + // Custom properties for our API wrapper + if (prop === "data") { + return target._data !== undefined + ? target._data + : (null as unknown as T); + } + if (prop === "error") { + return target._error !== undefined + ? target._error + : (null as unknown as E); + } + + // Delegate everything else to the actual Response object + const value = target[prop]; + + // Bind methods to the original response to maintain correct 'this' context + if (typeof value === "function") { + return value.bind(target); + } + + return value; + }, + set(target, prop, value) { + // Allow setting data and error properties + if (prop === "data") { + target._data = value; + return true; + } + if (prop === "error") { + target._error = value; + return true; + } + + // Prevent mutation of Response properties (ESM safety) + return false; + }, + }) as HttpResponse; const responseToParse = responseFormat ? response.clone() : response; const data = !responseFormat @@ -7042,29 +7251,48 @@ export class HttpClient { : payloadFormatter(body), }, ).then(async (response) => { - // Create a wrapper object that doesn't mutate the Response + // Create a Proxy that wraps the Response without mutating it // This ensures compatibility with ESM environments where Response is read-only - const r = { - data: null as unknown as T, - error: null as unknown as E, - // Delegate Response properties - ok: response.ok, - status: response.status, - statusText: response.statusText, - headers: response.headers, - url: response.url, - redirected: response.redirected, - type: response.type, - body: response.body, - bodyUsed: response.bodyUsed, - // Delegate Response methods - arrayBuffer: () => response.arrayBuffer(), - blob: () => response.blob(), - clone: () => response.clone(), - formData: () => response.formData(), - json: () => response.json(), - text: () => response.text(), - } as HttpResponse; + // while maintaining all Response properties and methods as live/dynamic values + const r = new Proxy(response, { + get(target, prop) { + // Custom properties for our API wrapper + if (prop === "data") { + return target._data !== undefined + ? target._data + : (null as unknown as T); + } + if (prop === "error") { + return target._error !== undefined + ? target._error + : (null as unknown as E); + } + + // Delegate everything else to the actual Response object + const value = target[prop]; + + // Bind methods to the original response to maintain correct 'this' context + if (typeof value === "function") { + return value.bind(target); + } + + return value; + }, + set(target, prop, value) { + // Allow setting data and error properties + if (prop === "data") { + target._data = value; + return true; + } + if (prop === "error") { + target._error = value; + return true; + } + + // Prevent mutation of Response properties (ESM safety) + return false; + }, + }) as HttpResponse; const responseToParse = responseFormat ? response.clone() : response; const data = !responseFormat @@ -7368,29 +7596,48 @@ export class HttpClient { : payloadFormatter(body), }, ).then(async (response) => { - // Create a wrapper object that doesn't mutate the Response + // Create a Proxy that wraps the Response without mutating it // This ensures compatibility with ESM environments where Response is read-only - const r = { - data: null as unknown as T, - error: null as unknown as E, - // Delegate Response properties - ok: response.ok, - status: response.status, - statusText: response.statusText, - headers: response.headers, - url: response.url, - redirected: response.redirected, - type: response.type, - body: response.body, - bodyUsed: response.bodyUsed, - // Delegate Response methods - arrayBuffer: () => response.arrayBuffer(), - blob: () => response.blob(), - clone: () => response.clone(), - formData: () => response.formData(), - json: () => response.json(), - text: () => response.text(), - } as HttpResponse; + // while maintaining all Response properties and methods as live/dynamic values + const r = new Proxy(response, { + get(target, prop) { + // Custom properties for our API wrapper + if (prop === "data") { + return target._data !== undefined + ? target._data + : (null as unknown as T); + } + if (prop === "error") { + return target._error !== undefined + ? target._error + : (null as unknown as E); + } + + // Delegate everything else to the actual Response object + const value = target[prop]; + + // Bind methods to the original response to maintain correct 'this' context + if (typeof value === "function") { + return value.bind(target); + } + + return value; + }, + set(target, prop, value) { + // Allow setting data and error properties + if (prop === "data") { + target._data = value; + return true; + } + if (prop === "error") { + target._error = value; + return true; + } + + // Prevent mutation of Response properties (ESM safety) + return false; + }, + }) as HttpResponse; const responseToParse = responseFormat ? response.clone() : response; const data = !responseFormat @@ -7741,29 +7988,48 @@ export class HttpClient { : payloadFormatter(body), }, ).then(async (response) => { - // Create a wrapper object that doesn't mutate the Response + // Create a Proxy that wraps the Response without mutating it // This ensures compatibility with ESM environments where Response is read-only - const r = { - data: null as unknown as T, - error: null as unknown as E, - // Delegate Response properties - ok: response.ok, - status: response.status, - statusText: response.statusText, - headers: response.headers, - url: response.url, - redirected: response.redirected, - type: response.type, - body: response.body, - bodyUsed: response.bodyUsed, - // Delegate Response methods - arrayBuffer: () => response.arrayBuffer(), - blob: () => response.blob(), - clone: () => response.clone(), - formData: () => response.formData(), - json: () => response.json(), - text: () => response.text(), - } as HttpResponse; + // while maintaining all Response properties and methods as live/dynamic values + const r = new Proxy(response, { + get(target, prop) { + // Custom properties for our API wrapper + if (prop === "data") { + return target._data !== undefined + ? target._data + : (null as unknown as T); + } + if (prop === "error") { + return target._error !== undefined + ? target._error + : (null as unknown as E); + } + + // Delegate everything else to the actual Response object + const value = target[prop]; + + // Bind methods to the original response to maintain correct 'this' context + if (typeof value === "function") { + return value.bind(target); + } + + return value; + }, + set(target, prop, value) { + // Allow setting data and error properties + if (prop === "data") { + target._data = value; + return true; + } + if (prop === "error") { + target._error = value; + return true; + } + + // Prevent mutation of Response properties (ESM safety) + return false; + }, + }) as HttpResponse; const responseToParse = responseFormat ? response.clone() : response; const data = !responseFormat @@ -8076,29 +8342,48 @@ export class HttpClient { : payloadFormatter(body), }, ).then(async (response) => { - // Create a wrapper object that doesn't mutate the Response + // Create a Proxy that wraps the Response without mutating it // This ensures compatibility with ESM environments where Response is read-only - const r = { - data: null as unknown as T, - error: null as unknown as E, - // Delegate Response properties - ok: response.ok, - status: response.status, - statusText: response.statusText, - headers: response.headers, - url: response.url, - redirected: response.redirected, - type: response.type, - body: response.body, - bodyUsed: response.bodyUsed, - // Delegate Response methods - arrayBuffer: () => response.arrayBuffer(), - blob: () => response.blob(), - clone: () => response.clone(), - formData: () => response.formData(), - json: () => response.json(), - text: () => response.text(), - } as HttpResponse; + // while maintaining all Response properties and methods as live/dynamic values + const r = new Proxy(response, { + get(target, prop) { + // Custom properties for our API wrapper + if (prop === "data") { + return target._data !== undefined + ? target._data + : (null as unknown as T); + } + if (prop === "error") { + return target._error !== undefined + ? target._error + : (null as unknown as E); + } + + // Delegate everything else to the actual Response object + const value = target[prop]; + + // Bind methods to the original response to maintain correct 'this' context + if (typeof value === "function") { + return value.bind(target); + } + + return value; + }, + set(target, prop, value) { + // Allow setting data and error properties + if (prop === "data") { + target._data = value; + return true; + } + if (prop === "error") { + target._error = value; + return true; + } + + // Prevent mutation of Response properties (ESM safety) + return false; + }, + }) as HttpResponse; const responseToParse = responseFormat ? response.clone() : response; const data = !responseFormat @@ -8425,29 +8710,48 @@ export class HttpClient { : payloadFormatter(body), }, ).then(async (response) => { - // Create a wrapper object that doesn't mutate the Response + // Create a Proxy that wraps the Response without mutating it // This ensures compatibility with ESM environments where Response is read-only - const r = { - data: null as unknown as T, - error: null as unknown as E, - // Delegate Response properties - ok: response.ok, - status: response.status, - statusText: response.statusText, - headers: response.headers, - url: response.url, - redirected: response.redirected, - type: response.type, - body: response.body, - bodyUsed: response.bodyUsed, - // Delegate Response methods - arrayBuffer: () => response.arrayBuffer(), - blob: () => response.blob(), - clone: () => response.clone(), - formData: () => response.formData(), - json: () => response.json(), - text: () => response.text(), - } as HttpResponse; + // while maintaining all Response properties and methods as live/dynamic values + const r = new Proxy(response, { + get(target, prop) { + // Custom properties for our API wrapper + if (prop === "data") { + return target._data !== undefined + ? target._data + : (null as unknown as T); + } + if (prop === "error") { + return target._error !== undefined + ? target._error + : (null as unknown as E); + } + + // Delegate everything else to the actual Response object + const value = target[prop]; + + // Bind methods to the original response to maintain correct 'this' context + if (typeof value === "function") { + return value.bind(target); + } + + return value; + }, + set(target, prop, value) { + // Allow setting data and error properties + if (prop === "data") { + target._data = value; + return true; + } + if (prop === "error") { + target._error = value; + return true; + } + + // Prevent mutation of Response properties (ESM safety) + return false; + }, + }) as HttpResponse; const responseToParse = responseFormat ? response.clone() : response; const data = !responseFormat @@ -8772,29 +9076,48 @@ export class HttpClient { : payloadFormatter(body), }, ).then(async (response) => { - // Create a wrapper object that doesn't mutate the Response + // Create a Proxy that wraps the Response without mutating it // This ensures compatibility with ESM environments where Response is read-only - const r = { - data: null as unknown as T, - error: null as unknown as E, - // Delegate Response properties - ok: response.ok, - status: response.status, - statusText: response.statusText, - headers: response.headers, - url: response.url, - redirected: response.redirected, - type: response.type, - body: response.body, - bodyUsed: response.bodyUsed, - // Delegate Response methods - arrayBuffer: () => response.arrayBuffer(), - blob: () => response.blob(), - clone: () => response.clone(), - formData: () => response.formData(), - json: () => response.json(), - text: () => response.text(), - } as HttpResponse; + // while maintaining all Response properties and methods as live/dynamic values + const r = new Proxy(response, { + get(target, prop) { + // Custom properties for our API wrapper + if (prop === "data") { + return target._data !== undefined + ? target._data + : (null as unknown as T); + } + if (prop === "error") { + return target._error !== undefined + ? target._error + : (null as unknown as E); + } + + // Delegate everything else to the actual Response object + const value = target[prop]; + + // Bind methods to the original response to maintain correct 'this' context + if (typeof value === "function") { + return value.bind(target); + } + + return value; + }, + set(target, prop, value) { + // Allow setting data and error properties + if (prop === "data") { + target._data = value; + return true; + } + if (prop === "error") { + target._error = value; + return true; + } + + // Prevent mutation of Response properties (ESM safety) + return false; + }, + }) as HttpResponse; const responseToParse = responseFormat ? response.clone() : response; const data = !responseFormat @@ -17764,29 +18087,48 @@ export class HttpClient { : payloadFormatter(body), }, ).then(async (response) => { - // Create a wrapper object that doesn't mutate the Response + // Create a Proxy that wraps the Response without mutating it // This ensures compatibility with ESM environments where Response is read-only - const r = { - data: null as unknown as T, - error: null as unknown as E, - // Delegate Response properties - ok: response.ok, - status: response.status, - statusText: response.statusText, - headers: response.headers, - url: response.url, - redirected: response.redirected, - type: response.type, - body: response.body, - bodyUsed: response.bodyUsed, - // Delegate Response methods - arrayBuffer: () => response.arrayBuffer(), - blob: () => response.blob(), - clone: () => response.clone(), - formData: () => response.formData(), - json: () => response.json(), - text: () => response.text(), - } as HttpResponse; + // while maintaining all Response properties and methods as live/dynamic values + const r = new Proxy(response, { + get(target, prop) { + // Custom properties for our API wrapper + if (prop === "data") { + return target._data !== undefined + ? target._data + : (null as unknown as T); + } + if (prop === "error") { + return target._error !== undefined + ? target._error + : (null as unknown as E); + } + + // Delegate everything else to the actual Response object + const value = target[prop]; + + // Bind methods to the original response to maintain correct 'this' context + if (typeof value === "function") { + return value.bind(target); + } + + return value; + }, + set(target, prop, value) { + // Allow setting data and error properties + if (prop === "data") { + target._data = value; + return true; + } + if (prop === "error") { + target._error = value; + return true; + } + + // Prevent mutation of Response properties (ESM safety) + return false; + }, + }) as HttpResponse; const responseToParse = responseFormat ? response.clone() : response; const data = !responseFormat @@ -38921,29 +39263,48 @@ export class HttpClient { : payloadFormatter(body), }, ).then(async (response) => { - // Create a wrapper object that doesn't mutate the Response + // Create a Proxy that wraps the Response without mutating it // This ensures compatibility with ESM environments where Response is read-only - const r = { - data: null as unknown as T, - error: null as unknown as E, - // Delegate Response properties - ok: response.ok, - status: response.status, - statusText: response.statusText, - headers: response.headers, - url: response.url, - redirected: response.redirected, - type: response.type, - body: response.body, - bodyUsed: response.bodyUsed, - // Delegate Response methods - arrayBuffer: () => response.arrayBuffer(), - blob: () => response.blob(), - clone: () => response.clone(), - formData: () => response.formData(), - json: () => response.json(), - text: () => response.text(), - } as HttpResponse; + // while maintaining all Response properties and methods as live/dynamic values + const r = new Proxy(response, { + get(target, prop) { + // Custom properties for our API wrapper + if (prop === "data") { + return target._data !== undefined + ? target._data + : (null as unknown as T); + } + if (prop === "error") { + return target._error !== undefined + ? target._error + : (null as unknown as E); + } + + // Delegate everything else to the actual Response object + const value = target[prop]; + + // Bind methods to the original response to maintain correct 'this' context + if (typeof value === "function") { + return value.bind(target); + } + + return value; + }, + set(target, prop, value) { + // Allow setting data and error properties + if (prop === "data") { + target._data = value; + return true; + } + if (prop === "error") { + target._error = value; + return true; + } + + // Prevent mutation of Response properties (ESM safety) + return false; + }, + }) as HttpResponse; const responseToParse = responseFormat ? response.clone() : response; const data = !responseFormat @@ -39517,29 +39878,48 @@ export class HttpClient { : payloadFormatter(body), }, ).then(async (response) => { - // Create a wrapper object that doesn't mutate the Response + // Create a Proxy that wraps the Response without mutating it // This ensures compatibility with ESM environments where Response is read-only - const r = { - data: null as unknown as T, - error: null as unknown as E, - // Delegate Response properties - ok: response.ok, - status: response.status, - statusText: response.statusText, - headers: response.headers, - url: response.url, - redirected: response.redirected, - type: response.type, - body: response.body, - bodyUsed: response.bodyUsed, - // Delegate Response methods - arrayBuffer: () => response.arrayBuffer(), - blob: () => response.blob(), - clone: () => response.clone(), - formData: () => response.formData(), - json: () => response.json(), - text: () => response.text(), - } as HttpResponse; + // while maintaining all Response properties and methods as live/dynamic values + const r = new Proxy(response, { + get(target, prop) { + // Custom properties for our API wrapper + if (prop === "data") { + return target._data !== undefined + ? target._data + : (null as unknown as T); + } + if (prop === "error") { + return target._error !== undefined + ? target._error + : (null as unknown as E); + } + + // Delegate everything else to the actual Response object + const value = target[prop]; + + // Bind methods to the original response to maintain correct 'this' context + if (typeof value === "function") { + return value.bind(target); + } + + return value; + }, + set(target, prop, value) { + // Allow setting data and error properties + if (prop === "data") { + target._data = value; + return true; + } + if (prop === "error") { + target._error = value; + return true; + } + + // Prevent mutation of Response properties (ESM safety) + return false; + }, + }) as HttpResponse; const responseToParse = responseFormat ? response.clone() : response; const data = !responseFormat @@ -40212,29 +40592,48 @@ export class HttpClient { : payloadFormatter(body), }, ).then(async (response) => { - // Create a wrapper object that doesn't mutate the Response + // Create a Proxy that wraps the Response without mutating it // This ensures compatibility with ESM environments where Response is read-only - const r = { - data: null as unknown as T, - error: null as unknown as E, - // Delegate Response properties - ok: response.ok, - status: response.status, - statusText: response.statusText, - headers: response.headers, - url: response.url, - redirected: response.redirected, - type: response.type, - body: response.body, - bodyUsed: response.bodyUsed, - // Delegate Response methods - arrayBuffer: () => response.arrayBuffer(), - blob: () => response.blob(), - clone: () => response.clone(), - formData: () => response.formData(), - json: () => response.json(), - text: () => response.text(), - } as HttpResponse; + // while maintaining all Response properties and methods as live/dynamic values + const r = new Proxy(response, { + get(target, prop) { + // Custom properties for our API wrapper + if (prop === "data") { + return target._data !== undefined + ? target._data + : (null as unknown as T); + } + if (prop === "error") { + return target._error !== undefined + ? target._error + : (null as unknown as E); + } + + // Delegate everything else to the actual Response object + const value = target[prop]; + + // Bind methods to the original response to maintain correct 'this' context + if (typeof value === "function") { + return value.bind(target); + } + + return value; + }, + set(target, prop, value) { + // Allow setting data and error properties + if (prop === "data") { + target._data = value; + return true; + } + if (prop === "error") { + target._error = value; + return true; + } + + // Prevent mutation of Response properties (ESM safety) + return false; + }, + }) as HttpResponse; const responseToParse = responseFormat ? response.clone() : response; const data = !responseFormat @@ -40526,29 +40925,48 @@ export class HttpClient { : payloadFormatter(body), }, ).then(async (response) => { - // Create a wrapper object that doesn't mutate the Response + // Create a Proxy that wraps the Response without mutating it // This ensures compatibility with ESM environments where Response is read-only - const r = { - data: null as unknown as T, - error: null as unknown as E, - // Delegate Response properties - ok: response.ok, - status: response.status, - statusText: response.statusText, - headers: response.headers, - url: response.url, - redirected: response.redirected, - type: response.type, - body: response.body, - bodyUsed: response.bodyUsed, - // Delegate Response methods - arrayBuffer: () => response.arrayBuffer(), - blob: () => response.blob(), - clone: () => response.clone(), - formData: () => response.formData(), - json: () => response.json(), - text: () => response.text(), - } as HttpResponse; + // while maintaining all Response properties and methods as live/dynamic values + const r = new Proxy(response, { + get(target, prop) { + // Custom properties for our API wrapper + if (prop === "data") { + return target._data !== undefined + ? target._data + : (null as unknown as T); + } + if (prop === "error") { + return target._error !== undefined + ? target._error + : (null as unknown as E); + } + + // Delegate everything else to the actual Response object + const value = target[prop]; + + // Bind methods to the original response to maintain correct 'this' context + if (typeof value === "function") { + return value.bind(target); + } + + return value; + }, + set(target, prop, value) { + // Allow setting data and error properties + if (prop === "data") { + target._data = value; + return true; + } + if (prop === "error") { + target._error = value; + return true; + } + + // Prevent mutation of Response properties (ESM safety) + return false; + }, + }) as HttpResponse; const responseToParse = responseFormat ? response.clone() : response; const data = !responseFormat @@ -40945,29 +41363,48 @@ export class HttpClient { : payloadFormatter(body), }, ).then(async (response) => { - // Create a wrapper object that doesn't mutate the Response + // Create a Proxy that wraps the Response without mutating it // This ensures compatibility with ESM environments where Response is read-only - const r = { - data: null as unknown as T, - error: null as unknown as E, - // Delegate Response properties - ok: response.ok, - status: response.status, - statusText: response.statusText, - headers: response.headers, - url: response.url, - redirected: response.redirected, - type: response.type, - body: response.body, - bodyUsed: response.bodyUsed, - // Delegate Response methods - arrayBuffer: () => response.arrayBuffer(), - blob: () => response.blob(), - clone: () => response.clone(), - formData: () => response.formData(), - json: () => response.json(), - text: () => response.text(), - } as HttpResponse; + // while maintaining all Response properties and methods as live/dynamic values + const r = new Proxy(response, { + get(target, prop) { + // Custom properties for our API wrapper + if (prop === "data") { + return target._data !== undefined + ? target._data + : (null as unknown as T); + } + if (prop === "error") { + return target._error !== undefined + ? target._error + : (null as unknown as E); + } + + // Delegate everything else to the actual Response object + const value = target[prop]; + + // Bind methods to the original response to maintain correct 'this' context + if (typeof value === "function") { + return value.bind(target); + } + + return value; + }, + set(target, prop, value) { + // Allow setting data and error properties + if (prop === "data") { + target._data = value; + return true; + } + if (prop === "error") { + target._error = value; + return true; + } + + // Prevent mutation of Response properties (ESM safety) + return false; + }, + }) as HttpResponse; const responseToParse = responseFormat ? response.clone() : response; const data = !responseFormat @@ -41253,29 +41690,48 @@ export class HttpClient { : payloadFormatter(body), }, ).then(async (response) => { - // Create a wrapper object that doesn't mutate the Response + // Create a Proxy that wraps the Response without mutating it // This ensures compatibility with ESM environments where Response is read-only - const r = { - data: null as unknown as T, - error: null as unknown as E, - // Delegate Response properties - ok: response.ok, - status: response.status, - statusText: response.statusText, - headers: response.headers, - url: response.url, - redirected: response.redirected, - type: response.type, - body: response.body, - bodyUsed: response.bodyUsed, - // Delegate Response methods - arrayBuffer: () => response.arrayBuffer(), - blob: () => response.blob(), - clone: () => response.clone(), - formData: () => response.formData(), - json: () => response.json(), - text: () => response.text(), - } as HttpResponse; + // while maintaining all Response properties and methods as live/dynamic values + const r = new Proxy(response, { + get(target, prop) { + // Custom properties for our API wrapper + if (prop === "data") { + return target._data !== undefined + ? target._data + : (null as unknown as T); + } + if (prop === "error") { + return target._error !== undefined + ? target._error + : (null as unknown as E); + } + + // Delegate everything else to the actual Response object + const value = target[prop]; + + // Bind methods to the original response to maintain correct 'this' context + if (typeof value === "function") { + return value.bind(target); + } + + return value; + }, + set(target, prop, value) { + // Allow setting data and error properties + if (prop === "data") { + target._data = value; + return true; + } + if (prop === "error") { + target._error = value; + return true; + } + + // Prevent mutation of Response properties (ESM safety) + return false; + }, + }) as HttpResponse; const responseToParse = responseFormat ? response.clone() : response; const data = !responseFormat @@ -41568,29 +42024,48 @@ export class HttpClient { : payloadFormatter(body), }, ).then(async (response) => { - // Create a wrapper object that doesn't mutate the Response + // Create a Proxy that wraps the Response without mutating it // This ensures compatibility with ESM environments where Response is read-only - const r = { - data: null as unknown as T, - error: null as unknown as E, - // Delegate Response properties - ok: response.ok, - status: response.status, - statusText: response.statusText, - headers: response.headers, - url: response.url, - redirected: response.redirected, - type: response.type, - body: response.body, - bodyUsed: response.bodyUsed, - // Delegate Response methods - arrayBuffer: () => response.arrayBuffer(), - blob: () => response.blob(), - clone: () => response.clone(), - formData: () => response.formData(), - json: () => response.json(), - text: () => response.text(), - } as HttpResponse; + // while maintaining all Response properties and methods as live/dynamic values + const r = new Proxy(response, { + get(target, prop) { + // Custom properties for our API wrapper + if (prop === "data") { + return target._data !== undefined + ? target._data + : (null as unknown as T); + } + if (prop === "error") { + return target._error !== undefined + ? target._error + : (null as unknown as E); + } + + // Delegate everything else to the actual Response object + const value = target[prop]; + + // Bind methods to the original response to maintain correct 'this' context + if (typeof value === "function") { + return value.bind(target); + } + + return value; + }, + set(target, prop, value) { + // Allow setting data and error properties + if (prop === "data") { + target._data = value; + return true; + } + if (prop === "error") { + target._error = value; + return true; + } + + // Prevent mutation of Response properties (ESM safety) + return false; + }, + }) as HttpResponse; const responseToParse = responseFormat ? response.clone() : response; const data = !responseFormat @@ -42084,29 +42559,48 @@ export class HttpClient { : payloadFormatter(body), }, ).then(async (response) => { - // Create a wrapper object that doesn't mutate the Response + // Create a Proxy that wraps the Response without mutating it // This ensures compatibility with ESM environments where Response is read-only - const r = { - data: null as unknown as T, - error: null as unknown as E, - // Delegate Response properties - ok: response.ok, - status: response.status, - statusText: response.statusText, - headers: response.headers, - url: response.url, - redirected: response.redirected, - type: response.type, - body: response.body, - bodyUsed: response.bodyUsed, - // Delegate Response methods - arrayBuffer: () => response.arrayBuffer(), - blob: () => response.blob(), - clone: () => response.clone(), - formData: () => response.formData(), - json: () => response.json(), - text: () => response.text(), - } as HttpResponse; + // while maintaining all Response properties and methods as live/dynamic values + const r = new Proxy(response, { + get(target, prop) { + // Custom properties for our API wrapper + if (prop === "data") { + return target._data !== undefined + ? target._data + : (null as unknown as T); + } + if (prop === "error") { + return target._error !== undefined + ? target._error + : (null as unknown as E); + } + + // Delegate everything else to the actual Response object + const value = target[prop]; + + // Bind methods to the original response to maintain correct 'this' context + if (typeof value === "function") { + return value.bind(target); + } + + return value; + }, + set(target, prop, value) { + // Allow setting data and error properties + if (prop === "data") { + target._data = value; + return true; + } + if (prop === "error") { + target._error = value; + return true; + } + + // Prevent mutation of Response properties (ESM safety) + return false; + }, + }) as HttpResponse; const responseToParse = responseFormat ? response.clone() : response; const data = !responseFormat @@ -42602,29 +43096,48 @@ export class HttpClient { : payloadFormatter(body), }, ).then(async (response) => { - // Create a wrapper object that doesn't mutate the Response + // Create a Proxy that wraps the Response without mutating it // This ensures compatibility with ESM environments where Response is read-only - const r = { - data: null as unknown as T, - error: null as unknown as E, - // Delegate Response properties - ok: response.ok, - status: response.status, - statusText: response.statusText, - headers: response.headers, - url: response.url, - redirected: response.redirected, - type: response.type, - body: response.body, - bodyUsed: response.bodyUsed, - // Delegate Response methods - arrayBuffer: () => response.arrayBuffer(), - blob: () => response.blob(), - clone: () => response.clone(), - formData: () => response.formData(), - json: () => response.json(), - text: () => response.text(), - } as HttpResponse; + // while maintaining all Response properties and methods as live/dynamic values + const r = new Proxy(response, { + get(target, prop) { + // Custom properties for our API wrapper + if (prop === "data") { + return target._data !== undefined + ? target._data + : (null as unknown as T); + } + if (prop === "error") { + return target._error !== undefined + ? target._error + : (null as unknown as E); + } + + // Delegate everything else to the actual Response object + const value = target[prop]; + + // Bind methods to the original response to maintain correct 'this' context + if (typeof value === "function") { + return value.bind(target); + } + + return value; + }, + set(target, prop, value) { + // Allow setting data and error properties + if (prop === "data") { + target._data = value; + return true; + } + if (prop === "error") { + target._error = value; + return true; + } + + // Prevent mutation of Response properties (ESM safety) + return false; + }, + }) as HttpResponse; const responseToParse = responseFormat ? response.clone() : response; const data = !responseFormat @@ -42976,29 +43489,48 @@ export class HttpClient { : payloadFormatter(body), }, ).then(async (response) => { - // Create a wrapper object that doesn't mutate the Response + // Create a Proxy that wraps the Response without mutating it // This ensures compatibility with ESM environments where Response is read-only - const r = { - data: null as unknown as T, - error: null as unknown as E, - // Delegate Response properties - ok: response.ok, - status: response.status, - statusText: response.statusText, - headers: response.headers, - url: response.url, - redirected: response.redirected, - type: response.type, - body: response.body, - bodyUsed: response.bodyUsed, - // Delegate Response methods - arrayBuffer: () => response.arrayBuffer(), - blob: () => response.blob(), - clone: () => response.clone(), - formData: () => response.formData(), - json: () => response.json(), - text: () => response.text(), - } as HttpResponse; + // while maintaining all Response properties and methods as live/dynamic values + const r = new Proxy(response, { + get(target, prop) { + // Custom properties for our API wrapper + if (prop === "data") { + return target._data !== undefined + ? target._data + : (null as unknown as T); + } + if (prop === "error") { + return target._error !== undefined + ? target._error + : (null as unknown as E); + } + + // Delegate everything else to the actual Response object + const value = target[prop]; + + // Bind methods to the original response to maintain correct 'this' context + if (typeof value === "function") { + return value.bind(target); + } + + return value; + }, + set(target, prop, value) { + // Allow setting data and error properties + if (prop === "data") { + target._data = value; + return true; + } + if (prop === "error") { + target._error = value; + return true; + } + + // Prevent mutation of Response properties (ESM safety) + return false; + }, + }) as HttpResponse; const responseToParse = responseFormat ? response.clone() : response; const data = !responseFormat @@ -43351,29 +43883,48 @@ export class HttpClient { : payloadFormatter(body), }, ).then(async (response) => { - // Create a wrapper object that doesn't mutate the Response + // Create a Proxy that wraps the Response without mutating it // This ensures compatibility with ESM environments where Response is read-only - const r = { - data: null as unknown as T, - error: null as unknown as E, - // Delegate Response properties - ok: response.ok, - status: response.status, - statusText: response.statusText, - headers: response.headers, - url: response.url, - redirected: response.redirected, - type: response.type, - body: response.body, - bodyUsed: response.bodyUsed, - // Delegate Response methods - arrayBuffer: () => response.arrayBuffer(), - blob: () => response.blob(), - clone: () => response.clone(), - formData: () => response.formData(), - json: () => response.json(), - text: () => response.text(), - } as HttpResponse; + // while maintaining all Response properties and methods as live/dynamic values + const r = new Proxy(response, { + get(target, prop) { + // Custom properties for our API wrapper + if (prop === "data") { + return target._data !== undefined + ? target._data + : (null as unknown as T); + } + if (prop === "error") { + return target._error !== undefined + ? target._error + : (null as unknown as E); + } + + // Delegate everything else to the actual Response object + const value = target[prop]; + + // Bind methods to the original response to maintain correct 'this' context + if (typeof value === "function") { + return value.bind(target); + } + + return value; + }, + set(target, prop, value) { + // Allow setting data and error properties + if (prop === "data") { + target._data = value; + return true; + } + if (prop === "error") { + target._error = value; + return true; + } + + // Prevent mutation of Response properties (ESM safety) + return false; + }, + }) as HttpResponse; const responseToParse = responseFormat ? response.clone() : response; const data = !responseFormat @@ -43762,29 +44313,48 @@ export class HttpClient { : payloadFormatter(body), }, ).then(async (response) => { - // Create a wrapper object that doesn't mutate the Response + // Create a Proxy that wraps the Response without mutating it // This ensures compatibility with ESM environments where Response is read-only - const r = { - data: null as unknown as T, - error: null as unknown as E, - // Delegate Response properties - ok: response.ok, - status: response.status, - statusText: response.statusText, - headers: response.headers, - url: response.url, - redirected: response.redirected, - type: response.type, - body: response.body, - bodyUsed: response.bodyUsed, - // Delegate Response methods - arrayBuffer: () => response.arrayBuffer(), - blob: () => response.blob(), - clone: () => response.clone(), - formData: () => response.formData(), - json: () => response.json(), - text: () => response.text(), - } as HttpResponse; + // while maintaining all Response properties and methods as live/dynamic values + const r = new Proxy(response, { + get(target, prop) { + // Custom properties for our API wrapper + if (prop === "data") { + return target._data !== undefined + ? target._data + : (null as unknown as T); + } + if (prop === "error") { + return target._error !== undefined + ? target._error + : (null as unknown as E); + } + + // Delegate everything else to the actual Response object + const value = target[prop]; + + // Bind methods to the original response to maintain correct 'this' context + if (typeof value === "function") { + return value.bind(target); + } + + return value; + }, + set(target, prop, value) { + // Allow setting data and error properties + if (prop === "data") { + target._data = value; + return true; + } + if (prop === "error") { + target._error = value; + return true; + } + + // Prevent mutation of Response properties (ESM safety) + return false; + }, + }) as HttpResponse; const responseToParse = responseFormat ? response.clone() : response; const data = !responseFormat @@ -44163,29 +44733,48 @@ export class HttpClient { : payloadFormatter(body), }, ).then(async (response) => { - // Create a wrapper object that doesn't mutate the Response + // Create a Proxy that wraps the Response without mutating it // This ensures compatibility with ESM environments where Response is read-only - const r = { - data: null as unknown as T, - error: null as unknown as E, - // Delegate Response properties - ok: response.ok, - status: response.status, - statusText: response.statusText, - headers: response.headers, - url: response.url, - redirected: response.redirected, - type: response.type, - body: response.body, - bodyUsed: response.bodyUsed, - // Delegate Response methods - arrayBuffer: () => response.arrayBuffer(), - blob: () => response.blob(), - clone: () => response.clone(), - formData: () => response.formData(), - json: () => response.json(), - text: () => response.text(), - } as HttpResponse; + // while maintaining all Response properties and methods as live/dynamic values + const r = new Proxy(response, { + get(target, prop) { + // Custom properties for our API wrapper + if (prop === "data") { + return target._data !== undefined + ? target._data + : (null as unknown as T); + } + if (prop === "error") { + return target._error !== undefined + ? target._error + : (null as unknown as E); + } + + // Delegate everything else to the actual Response object + const value = target[prop]; + + // Bind methods to the original response to maintain correct 'this' context + if (typeof value === "function") { + return value.bind(target); + } + + return value; + }, + set(target, prop, value) { + // Allow setting data and error properties + if (prop === "data") { + target._data = value; + return true; + } + if (prop === "error") { + target._error = value; + return true; + } + + // Prevent mutation of Response properties (ESM safety) + return false; + }, + }) as HttpResponse; const responseToParse = responseFormat ? response.clone() : response; const data = !responseFormat @@ -44507,29 +45096,48 @@ export class HttpClient { : payloadFormatter(body), }, ).then(async (response) => { - // Create a wrapper object that doesn't mutate the Response + // Create a Proxy that wraps the Response without mutating it // This ensures compatibility with ESM environments where Response is read-only - const r = { - data: null as unknown as T, - error: null as unknown as E, - // Delegate Response properties - ok: response.ok, - status: response.status, - statusText: response.statusText, - headers: response.headers, - url: response.url, - redirected: response.redirected, - type: response.type, - body: response.body, - bodyUsed: response.bodyUsed, - // Delegate Response methods - arrayBuffer: () => response.arrayBuffer(), - blob: () => response.blob(), - clone: () => response.clone(), - formData: () => response.formData(), - json: () => response.json(), - text: () => response.text(), - } as HttpResponse; + // while maintaining all Response properties and methods as live/dynamic values + const r = new Proxy(response, { + get(target, prop) { + // Custom properties for our API wrapper + if (prop === "data") { + return target._data !== undefined + ? target._data + : (null as unknown as T); + } + if (prop === "error") { + return target._error !== undefined + ? target._error + : (null as unknown as E); + } + + // Delegate everything else to the actual Response object + const value = target[prop]; + + // Bind methods to the original response to maintain correct 'this' context + if (typeof value === "function") { + return value.bind(target); + } + + return value; + }, + set(target, prop, value) { + // Allow setting data and error properties + if (prop === "data") { + target._data = value; + return true; + } + if (prop === "error") { + target._error = value; + return true; + } + + // Prevent mutation of Response properties (ESM safety) + return false; + }, + }) as HttpResponse; const responseToParse = responseFormat ? response.clone() : response; const data = !responseFormat @@ -44943,29 +45551,48 @@ export class HttpClient { : payloadFormatter(body), }, ).then(async (response) => { - // Create a wrapper object that doesn't mutate the Response + // Create a Proxy that wraps the Response without mutating it // This ensures compatibility with ESM environments where Response is read-only - const r = { - data: null as unknown as T, - error: null as unknown as E, - // Delegate Response properties - ok: response.ok, - status: response.status, - statusText: response.statusText, - headers: response.headers, - url: response.url, - redirected: response.redirected, - type: response.type, - body: response.body, - bodyUsed: response.bodyUsed, - // Delegate Response methods - arrayBuffer: () => response.arrayBuffer(), - blob: () => response.blob(), - clone: () => response.clone(), - formData: () => response.formData(), - json: () => response.json(), - text: () => response.text(), - } as HttpResponse; + // while maintaining all Response properties and methods as live/dynamic values + const r = new Proxy(response, { + get(target, prop) { + // Custom properties for our API wrapper + if (prop === "data") { + return target._data !== undefined + ? target._data + : (null as unknown as T); + } + if (prop === "error") { + return target._error !== undefined + ? target._error + : (null as unknown as E); + } + + // Delegate everything else to the actual Response object + const value = target[prop]; + + // Bind methods to the original response to maintain correct 'this' context + if (typeof value === "function") { + return value.bind(target); + } + + return value; + }, + set(target, prop, value) { + // Allow setting data and error properties + if (prop === "data") { + target._data = value; + return true; + } + if (prop === "error") { + target._error = value; + return true; + } + + // Prevent mutation of Response properties (ESM safety) + return false; + }, + }) as HttpResponse; const responseToParse = responseFormat ? response.clone() : response; const data = !responseFormat @@ -45655,29 +46282,48 @@ export class HttpClient { : payloadFormatter(body), }, ).then(async (response) => { - // Create a wrapper object that doesn't mutate the Response + // Create a Proxy that wraps the Response without mutating it // This ensures compatibility with ESM environments where Response is read-only - const r = { - data: null as unknown as T, - error: null as unknown as E, - // Delegate Response properties - ok: response.ok, - status: response.status, - statusText: response.statusText, - headers: response.headers, - url: response.url, - redirected: response.redirected, - type: response.type, - body: response.body, - bodyUsed: response.bodyUsed, - // Delegate Response methods - arrayBuffer: () => response.arrayBuffer(), - blob: () => response.blob(), - clone: () => response.clone(), - formData: () => response.formData(), - json: () => response.json(), - text: () => response.text(), - } as HttpResponse; + // while maintaining all Response properties and methods as live/dynamic values + const r = new Proxy(response, { + get(target, prop) { + // Custom properties for our API wrapper + if (prop === "data") { + return target._data !== undefined + ? target._data + : (null as unknown as T); + } + if (prop === "error") { + return target._error !== undefined + ? target._error + : (null as unknown as E); + } + + // Delegate everything else to the actual Response object + const value = target[prop]; + + // Bind methods to the original response to maintain correct 'this' context + if (typeof value === "function") { + return value.bind(target); + } + + return value; + }, + set(target, prop, value) { + // Allow setting data and error properties + if (prop === "data") { + target._data = value; + return true; + } + if (prop === "error") { + target._error = value; + return true; + } + + // Prevent mutation of Response properties (ESM safety) + return false; + }, + }) as HttpResponse; const responseToParse = responseFormat ? response.clone() : response; const data = !responseFormat @@ -46031,29 +46677,48 @@ export class HttpClient { : payloadFormatter(body), }, ).then(async (response) => { - // Create a wrapper object that doesn't mutate the Response + // Create a Proxy that wraps the Response without mutating it // This ensures compatibility with ESM environments where Response is read-only - const r = { - data: null as unknown as T, - error: null as unknown as E, - // Delegate Response properties - ok: response.ok, - status: response.status, - statusText: response.statusText, - headers: response.headers, - url: response.url, - redirected: response.redirected, - type: response.type, - body: response.body, - bodyUsed: response.bodyUsed, - // Delegate Response methods - arrayBuffer: () => response.arrayBuffer(), - blob: () => response.blob(), - clone: () => response.clone(), - formData: () => response.formData(), - json: () => response.json(), - text: () => response.text(), - } as HttpResponse; + // while maintaining all Response properties and methods as live/dynamic values + const r = new Proxy(response, { + get(target, prop) { + // Custom properties for our API wrapper + if (prop === "data") { + return target._data !== undefined + ? target._data + : (null as unknown as T); + } + if (prop === "error") { + return target._error !== undefined + ? target._error + : (null as unknown as E); + } + + // Delegate everything else to the actual Response object + const value = target[prop]; + + // Bind methods to the original response to maintain correct 'this' context + if (typeof value === "function") { + return value.bind(target); + } + + return value; + }, + set(target, prop, value) { + // Allow setting data and error properties + if (prop === "data") { + target._data = value; + return true; + } + if (prop === "error") { + target._error = value; + return true; + } + + // Prevent mutation of Response properties (ESM safety) + return false; + }, + }) as HttpResponse; const responseToParse = responseFormat ? response.clone() : response; const data = !responseFormat @@ -46371,29 +47036,48 @@ export class HttpClient { : payloadFormatter(body), }, ).then(async (response) => { - // Create a wrapper object that doesn't mutate the Response + // Create a Proxy that wraps the Response without mutating it // This ensures compatibility with ESM environments where Response is read-only - const r = { - data: null as unknown as T, - error: null as unknown as E, - // Delegate Response properties - ok: response.ok, - status: response.status, - statusText: response.statusText, - headers: response.headers, - url: response.url, - redirected: response.redirected, - type: response.type, - body: response.body, - bodyUsed: response.bodyUsed, - // Delegate Response methods - arrayBuffer: () => response.arrayBuffer(), - blob: () => response.blob(), - clone: () => response.clone(), - formData: () => response.formData(), - json: () => response.json(), - text: () => response.text(), - } as HttpResponse; + // while maintaining all Response properties and methods as live/dynamic values + const r = new Proxy(response, { + get(target, prop) { + // Custom properties for our API wrapper + if (prop === "data") { + return target._data !== undefined + ? target._data + : (null as unknown as T); + } + if (prop === "error") { + return target._error !== undefined + ? target._error + : (null as unknown as E); + } + + // Delegate everything else to the actual Response object + const value = target[prop]; + + // Bind methods to the original response to maintain correct 'this' context + if (typeof value === "function") { + return value.bind(target); + } + + return value; + }, + set(target, prop, value) { + // Allow setting data and error properties + if (prop === "data") { + target._data = value; + return true; + } + if (prop === "error") { + target._error = value; + return true; + } + + // Prevent mutation of Response properties (ESM safety) + return false; + }, + }) as HttpResponse; const responseToParse = responseFormat ? response.clone() : response; const data = !responseFormat @@ -46668,29 +47352,48 @@ export class HttpClient { : payloadFormatter(body), }, ).then(async (response) => { - // Create a wrapper object that doesn't mutate the Response + // Create a Proxy that wraps the Response without mutating it // This ensures compatibility with ESM environments where Response is read-only - const r = { - data: null as unknown as T, - error: null as unknown as E, - // Delegate Response properties - ok: response.ok, - status: response.status, - statusText: response.statusText, - headers: response.headers, - url: response.url, - redirected: response.redirected, - type: response.type, - body: response.body, - bodyUsed: response.bodyUsed, - // Delegate Response methods - arrayBuffer: () => response.arrayBuffer(), - blob: () => response.blob(), - clone: () => response.clone(), - formData: () => response.formData(), - json: () => response.json(), - text: () => response.text(), - } as HttpResponse; + // while maintaining all Response properties and methods as live/dynamic values + const r = new Proxy(response, { + get(target, prop) { + // Custom properties for our API wrapper + if (prop === "data") { + return target._data !== undefined + ? target._data + : (null as unknown as T); + } + if (prop === "error") { + return target._error !== undefined + ? target._error + : (null as unknown as E); + } + + // Delegate everything else to the actual Response object + const value = target[prop]; + + // Bind methods to the original response to maintain correct 'this' context + if (typeof value === "function") { + return value.bind(target); + } + + return value; + }, + set(target, prop, value) { + // Allow setting data and error properties + if (prop === "data") { + target._data = value; + return true; + } + if (prop === "error") { + target._error = value; + return true; + } + + // Prevent mutation of Response properties (ESM safety) + return false; + }, + }) as HttpResponse; const responseToParse = responseFormat ? response.clone() : response; const data = !responseFormat @@ -46990,29 +47693,48 @@ export class HttpClient { : payloadFormatter(body), }, ).then(async (response) => { - // Create a wrapper object that doesn't mutate the Response + // Create a Proxy that wraps the Response without mutating it // This ensures compatibility with ESM environments where Response is read-only - const r = { - data: null as unknown as T, - error: null as unknown as E, - // Delegate Response properties - ok: response.ok, - status: response.status, - statusText: response.statusText, - headers: response.headers, - url: response.url, - redirected: response.redirected, - type: response.type, - body: response.body, - bodyUsed: response.bodyUsed, - // Delegate Response methods - arrayBuffer: () => response.arrayBuffer(), - blob: () => response.blob(), - clone: () => response.clone(), - formData: () => response.formData(), - json: () => response.json(), - text: () => response.text(), - } as HttpResponse; + // while maintaining all Response properties and methods as live/dynamic values + const r = new Proxy(response, { + get(target, prop) { + // Custom properties for our API wrapper + if (prop === "data") { + return target._data !== undefined + ? target._data + : (null as unknown as T); + } + if (prop === "error") { + return target._error !== undefined + ? target._error + : (null as unknown as E); + } + + // Delegate everything else to the actual Response object + const value = target[prop]; + + // Bind methods to the original response to maintain correct 'this' context + if (typeof value === "function") { + return value.bind(target); + } + + return value; + }, + set(target, prop, value) { + // Allow setting data and error properties + if (prop === "data") { + target._data = value; + return true; + } + if (prop === "error") { + target._error = value; + return true; + } + + // Prevent mutation of Response properties (ESM safety) + return false; + }, + }) as HttpResponse; const responseToParse = responseFormat ? response.clone() : response; const data = !responseFormat @@ -47435,29 +48157,48 @@ export class HttpClient { : payloadFormatter(body), }, ).then(async (response) => { - // Create a wrapper object that doesn't mutate the Response + // Create a Proxy that wraps the Response without mutating it // This ensures compatibility with ESM environments where Response is read-only - const r = { - data: null as unknown as T, - error: null as unknown as E, - // Delegate Response properties - ok: response.ok, - status: response.status, - statusText: response.statusText, - headers: response.headers, - url: response.url, - redirected: response.redirected, - type: response.type, - body: response.body, - bodyUsed: response.bodyUsed, - // Delegate Response methods - arrayBuffer: () => response.arrayBuffer(), - blob: () => response.blob(), - clone: () => response.clone(), - formData: () => response.formData(), - json: () => response.json(), - text: () => response.text(), - } as HttpResponse; + // while maintaining all Response properties and methods as live/dynamic values + const r = new Proxy(response, { + get(target, prop) { + // Custom properties for our API wrapper + if (prop === "data") { + return target._data !== undefined + ? target._data + : (null as unknown as T); + } + if (prop === "error") { + return target._error !== undefined + ? target._error + : (null as unknown as E); + } + + // Delegate everything else to the actual Response object + const value = target[prop]; + + // Bind methods to the original response to maintain correct 'this' context + if (typeof value === "function") { + return value.bind(target); + } + + return value; + }, + set(target, prop, value) { + // Allow setting data and error properties + if (prop === "data") { + target._data = value; + return true; + } + if (prop === "error") { + target._error = value; + return true; + } + + // Prevent mutation of Response properties (ESM safety) + return false; + }, + }) as HttpResponse; const responseToParse = responseFormat ? response.clone() : response; const data = !responseFormat @@ -48106,29 +48847,48 @@ export class HttpClient { : payloadFormatter(body), }, ).then(async (response) => { - // Create a wrapper object that doesn't mutate the Response + // Create a Proxy that wraps the Response without mutating it // This ensures compatibility with ESM environments where Response is read-only - const r = { - data: null as unknown as T, - error: null as unknown as E, - // Delegate Response properties - ok: response.ok, - status: response.status, - statusText: response.statusText, - headers: response.headers, - url: response.url, - redirected: response.redirected, - type: response.type, - body: response.body, - bodyUsed: response.bodyUsed, - // Delegate Response methods - arrayBuffer: () => response.arrayBuffer(), - blob: () => response.blob(), - clone: () => response.clone(), - formData: () => response.formData(), - json: () => response.json(), - text: () => response.text(), - } as HttpResponse; + // while maintaining all Response properties and methods as live/dynamic values + const r = new Proxy(response, { + get(target, prop) { + // Custom properties for our API wrapper + if (prop === "data") { + return target._data !== undefined + ? target._data + : (null as unknown as T); + } + if (prop === "error") { + return target._error !== undefined + ? target._error + : (null as unknown as E); + } + + // Delegate everything else to the actual Response object + const value = target[prop]; + + // Bind methods to the original response to maintain correct 'this' context + if (typeof value === "function") { + return value.bind(target); + } + + return value; + }, + set(target, prop, value) { + // Allow setting data and error properties + if (prop === "data") { + target._data = value; + return true; + } + if (prop === "error") { + target._error = value; + return true; + } + + // Prevent mutation of Response properties (ESM safety) + return false; + }, + }) as HttpResponse; const responseToParse = responseFormat ? response.clone() : response; const data = !responseFormat @@ -49313,29 +50073,48 @@ export class HttpClient { : payloadFormatter(body), }, ).then(async (response) => { - // Create a wrapper object that doesn't mutate the Response + // Create a Proxy that wraps the Response without mutating it // This ensures compatibility with ESM environments where Response is read-only - const r = { - data: null as unknown as T, - error: null as unknown as E, - // Delegate Response properties - ok: response.ok, - status: response.status, - statusText: response.statusText, - headers: response.headers, - url: response.url, - redirected: response.redirected, - type: response.type, - body: response.body, - bodyUsed: response.bodyUsed, - // Delegate Response methods - arrayBuffer: () => response.arrayBuffer(), - blob: () => response.blob(), - clone: () => response.clone(), - formData: () => response.formData(), - json: () => response.json(), - text: () => response.text(), - } as HttpResponse; + // while maintaining all Response properties and methods as live/dynamic values + const r = new Proxy(response, { + get(target, prop) { + // Custom properties for our API wrapper + if (prop === "data") { + return target._data !== undefined + ? target._data + : (null as unknown as T); + } + if (prop === "error") { + return target._error !== undefined + ? target._error + : (null as unknown as E); + } + + // Delegate everything else to the actual Response object + const value = target[prop]; + + // Bind methods to the original response to maintain correct 'this' context + if (typeof value === "function") { + return value.bind(target); + } + + return value; + }, + set(target, prop, value) { + // Allow setting data and error properties + if (prop === "data") { + target._data = value; + return true; + } + if (prop === "error") { + target._error = value; + return true; + } + + // Prevent mutation of Response properties (ESM safety) + return false; + }, + }) as HttpResponse; const responseToParse = responseFormat ? response.clone() : response; const data = !responseFormat @@ -50126,29 +50905,48 @@ export class HttpClient { : payloadFormatter(body), }, ).then(async (response) => { - // Create a wrapper object that doesn't mutate the Response + // Create a Proxy that wraps the Response without mutating it // This ensures compatibility with ESM environments where Response is read-only - const r = { - data: null as unknown as T, - error: null as unknown as E, - // Delegate Response properties - ok: response.ok, - status: response.status, - statusText: response.statusText, - headers: response.headers, - url: response.url, - redirected: response.redirected, - type: response.type, - body: response.body, - bodyUsed: response.bodyUsed, - // Delegate Response methods - arrayBuffer: () => response.arrayBuffer(), - blob: () => response.blob(), - clone: () => response.clone(), - formData: () => response.formData(), - json: () => response.json(), - text: () => response.text(), - } as HttpResponse; + // while maintaining all Response properties and methods as live/dynamic values + const r = new Proxy(response, { + get(target, prop) { + // Custom properties for our API wrapper + if (prop === "data") { + return target._data !== undefined + ? target._data + : (null as unknown as T); + } + if (prop === "error") { + return target._error !== undefined + ? target._error + : (null as unknown as E); + } + + // Delegate everything else to the actual Response object + const value = target[prop]; + + // Bind methods to the original response to maintain correct 'this' context + if (typeof value === "function") { + return value.bind(target); + } + + return value; + }, + set(target, prop, value) { + // Allow setting data and error properties + if (prop === "data") { + target._data = value; + return true; + } + if (prop === "error") { + target._error = value; + return true; + } + + // Prevent mutation of Response properties (ESM safety) + return false; + }, + }) as HttpResponse; const responseToParse = responseFormat ? response.clone() : response; const data = !responseFormat @@ -50511,29 +51309,48 @@ export class HttpClient { : payloadFormatter(body), }, ).then(async (response) => { - // Create a wrapper object that doesn't mutate the Response + // Create a Proxy that wraps the Response without mutating it // This ensures compatibility with ESM environments where Response is read-only - const r = { - data: null as unknown as T, - error: null as unknown as E, - // Delegate Response properties - ok: response.ok, - status: response.status, - statusText: response.statusText, - headers: response.headers, - url: response.url, - redirected: response.redirected, - type: response.type, - body: response.body, - bodyUsed: response.bodyUsed, - // Delegate Response methods - arrayBuffer: () => response.arrayBuffer(), - blob: () => response.blob(), - clone: () => response.clone(), - formData: () => response.formData(), - json: () => response.json(), - text: () => response.text(), - } as HttpResponse; + // while maintaining all Response properties and methods as live/dynamic values + const r = new Proxy(response, { + get(target, prop) { + // Custom properties for our API wrapper + if (prop === "data") { + return target._data !== undefined + ? target._data + : (null as unknown as T); + } + if (prop === "error") { + return target._error !== undefined + ? target._error + : (null as unknown as E); + } + + // Delegate everything else to the actual Response object + const value = target[prop]; + + // Bind methods to the original response to maintain correct 'this' context + if (typeof value === "function") { + return value.bind(target); + } + + return value; + }, + set(target, prop, value) { + // Allow setting data and error properties + if (prop === "data") { + target._data = value; + return true; + } + if (prop === "error") { + target._error = value; + return true; + } + + // Prevent mutation of Response properties (ESM safety) + return false; + }, + }) as HttpResponse; const responseToParse = responseFormat ? response.clone() : response; const data = !responseFormat @@ -50833,29 +51650,48 @@ export class HttpClient { : payloadFormatter(body), }, ).then(async (response) => { - // Create a wrapper object that doesn't mutate the Response + // Create a Proxy that wraps the Response without mutating it // This ensures compatibility with ESM environments where Response is read-only - const r = { - data: null as unknown as T, - error: null as unknown as E, - // Delegate Response properties - ok: response.ok, - status: response.status, - statusText: response.statusText, - headers: response.headers, - url: response.url, - redirected: response.redirected, - type: response.type, - body: response.body, - bodyUsed: response.bodyUsed, - // Delegate Response methods - arrayBuffer: () => response.arrayBuffer(), - blob: () => response.blob(), - clone: () => response.clone(), - formData: () => response.formData(), - json: () => response.json(), - text: () => response.text(), - } as HttpResponse; + // while maintaining all Response properties and methods as live/dynamic values + const r = new Proxy(response, { + get(target, prop) { + // Custom properties for our API wrapper + if (prop === "data") { + return target._data !== undefined + ? target._data + : (null as unknown as T); + } + if (prop === "error") { + return target._error !== undefined + ? target._error + : (null as unknown as E); + } + + // Delegate everything else to the actual Response object + const value = target[prop]; + + // Bind methods to the original response to maintain correct 'this' context + if (typeof value === "function") { + return value.bind(target); + } + + return value; + }, + set(target, prop, value) { + // Allow setting data and error properties + if (prop === "data") { + target._data = value; + return true; + } + if (prop === "error") { + target._error = value; + return true; + } + + // Prevent mutation of Response properties (ESM safety) + return false; + }, + }) as HttpResponse; const responseToParse = responseFormat ? response.clone() : response; const data = !responseFormat diff --git a/tests/spec/another-query-params/__snapshots__/basic.test.ts.snap b/tests/spec/another-query-params/__snapshots__/basic.test.ts.snap index 65347a71..a44d56ea 100644 --- a/tests/spec/another-query-params/__snapshots__/basic.test.ts.snap +++ b/tests/spec/another-query-params/__snapshots__/basic.test.ts.snap @@ -265,29 +265,48 @@ export class HttpClient { : payloadFormatter(body), }, ).then(async (response) => { - // Create a wrapper object that doesn't mutate the Response + // Create a Proxy that wraps the Response without mutating it // This ensures compatibility with ESM environments where Response is read-only - const r = { - data: null as unknown as T, - error: null as unknown as E, - // Delegate Response properties - ok: response.ok, - status: response.status, - statusText: response.statusText, - headers: response.headers, - url: response.url, - redirected: response.redirected, - type: response.type, - body: response.body, - bodyUsed: response.bodyUsed, - // Delegate Response methods - arrayBuffer: () => response.arrayBuffer(), - blob: () => response.blob(), - clone: () => response.clone(), - formData: () => response.formData(), - json: () => response.json(), - text: () => response.text(), - } as HttpResponse; + // while maintaining all Response properties and methods as live/dynamic values + const r = new Proxy(response, { + get(target, prop) { + // Custom properties for our API wrapper + if (prop === "data") { + return target._data !== undefined + ? target._data + : (null as unknown as T); + } + if (prop === "error") { + return target._error !== undefined + ? target._error + : (null as unknown as E); + } + + // Delegate everything else to the actual Response object + const value = target[prop]; + + // Bind methods to the original response to maintain correct 'this' context + if (typeof value === "function") { + return value.bind(target); + } + + return value; + }, + set(target, prop, value) { + // Allow setting data and error properties + if (prop === "data") { + target._data = value; + return true; + } + if (prop === "error") { + target._error = value; + return true; + } + + // Prevent mutation of Response properties (ESM safety) + return false; + }, + }) as HttpResponse; const responseToParse = responseFormat ? response.clone() : response; const data = !responseFormat diff --git a/tests/spec/custom-extensions/__snapshots__/basic.test.ts.snap b/tests/spec/custom-extensions/__snapshots__/basic.test.ts.snap index c879965d..2533e5df 100644 --- a/tests/spec/custom-extensions/__snapshots__/basic.test.ts.snap +++ b/tests/spec/custom-extensions/__snapshots__/basic.test.ts.snap @@ -237,29 +237,48 @@ export class HttpClient { : payloadFormatter(body), }, ).then(async (response) => { - // Create a wrapper object that doesn't mutate the Response + // Create a Proxy that wraps the Response without mutating it // This ensures compatibility with ESM environments where Response is read-only - const r = { - data: null as unknown as T, - error: null as unknown as E, - // Delegate Response properties - ok: response.ok, - status: response.status, - statusText: response.statusText, - headers: response.headers, - url: response.url, - redirected: response.redirected, - type: response.type, - body: response.body, - bodyUsed: response.bodyUsed, - // Delegate Response methods - arrayBuffer: () => response.arrayBuffer(), - blob: () => response.blob(), - clone: () => response.clone(), - formData: () => response.formData(), - json: () => response.json(), - text: () => response.text(), - } as HttpResponse; + // while maintaining all Response properties and methods as live/dynamic values + const r = new Proxy(response, { + get(target, prop) { + // Custom properties for our API wrapper + if (prop === "data") { + return target._data !== undefined + ? target._data + : (null as unknown as T); + } + if (prop === "error") { + return target._error !== undefined + ? target._error + : (null as unknown as E); + } + + // Delegate everything else to the actual Response object + const value = target[prop]; + + // Bind methods to the original response to maintain correct 'this' context + if (typeof value === "function") { + return value.bind(target); + } + + return value; + }, + set(target, prop, value) { + // Allow setting data and error properties + if (prop === "data") { + target._data = value; + return true; + } + if (prop === "error") { + target._error = value; + return true; + } + + // Prevent mutation of Response properties (ESM safety) + return false; + }, + }) as HttpResponse; const responseToParse = responseFormat ? response.clone() : response; const data = !responseFormat diff --git a/tests/spec/defaultAsSuccess/__snapshots__/basic.test.ts.snap b/tests/spec/defaultAsSuccess/__snapshots__/basic.test.ts.snap index f3e5a02f..e43b184b 100644 --- a/tests/spec/defaultAsSuccess/__snapshots__/basic.test.ts.snap +++ b/tests/spec/defaultAsSuccess/__snapshots__/basic.test.ts.snap @@ -277,29 +277,48 @@ export class HttpClient { : payloadFormatter(body), }, ).then(async (response) => { - // Create a wrapper object that doesn't mutate the Response + // Create a Proxy that wraps the Response without mutating it // This ensures compatibility with ESM environments where Response is read-only - const r = { - data: null as unknown as T, - error: null as unknown as E, - // Delegate Response properties - ok: response.ok, - status: response.status, - statusText: response.statusText, - headers: response.headers, - url: response.url, - redirected: response.redirected, - type: response.type, - body: response.body, - bodyUsed: response.bodyUsed, - // Delegate Response methods - arrayBuffer: () => response.arrayBuffer(), - blob: () => response.blob(), - clone: () => response.clone(), - formData: () => response.formData(), - json: () => response.json(), - text: () => response.text(), - } as HttpResponse; + // while maintaining all Response properties and methods as live/dynamic values + const r = new Proxy(response, { + get(target, prop) { + // Custom properties for our API wrapper + if (prop === "data") { + return target._data !== undefined + ? target._data + : (null as unknown as T); + } + if (prop === "error") { + return target._error !== undefined + ? target._error + : (null as unknown as E); + } + + // Delegate everything else to the actual Response object + const value = target[prop]; + + // Bind methods to the original response to maintain correct 'this' context + if (typeof value === "function") { + return value.bind(target); + } + + return value; + }, + set(target, prop, value) { + // Allow setting data and error properties + if (prop === "data") { + target._data = value; + return true; + } + if (prop === "error") { + target._error = value; + return true; + } + + // Prevent mutation of Response properties (ESM safety) + return false; + }, + }) as HttpResponse; const responseToParse = responseFormat ? response.clone() : response; const data = !responseFormat diff --git a/tests/spec/defaultResponse/__snapshots__/basic.test.ts.snap b/tests/spec/defaultResponse/__snapshots__/basic.test.ts.snap index 4cda2433..490e402a 100644 --- a/tests/spec/defaultResponse/__snapshots__/basic.test.ts.snap +++ b/tests/spec/defaultResponse/__snapshots__/basic.test.ts.snap @@ -237,29 +237,48 @@ export class HttpClient { : payloadFormatter(body), }, ).then(async (response) => { - // Create a wrapper object that doesn't mutate the Response + // Create a Proxy that wraps the Response without mutating it // This ensures compatibility with ESM environments where Response is read-only - const r = { - data: null as unknown as T, - error: null as unknown as E, - // Delegate Response properties - ok: response.ok, - status: response.status, - statusText: response.statusText, - headers: response.headers, - url: response.url, - redirected: response.redirected, - type: response.type, - body: response.body, - bodyUsed: response.bodyUsed, - // Delegate Response methods - arrayBuffer: () => response.arrayBuffer(), - blob: () => response.blob(), - clone: () => response.clone(), - formData: () => response.formData(), - json: () => response.json(), - text: () => response.text(), - } as HttpResponse; + // while maintaining all Response properties and methods as live/dynamic values + const r = new Proxy(response, { + get(target, prop) { + // Custom properties for our API wrapper + if (prop === "data") { + return target._data !== undefined + ? target._data + : (null as unknown as T); + } + if (prop === "error") { + return target._error !== undefined + ? target._error + : (null as unknown as E); + } + + // Delegate everything else to the actual Response object + const value = target[prop]; + + // Bind methods to the original response to maintain correct 'this' context + if (typeof value === "function") { + return value.bind(target); + } + + return value; + }, + set(target, prop, value) { + // Allow setting data and error properties + if (prop === "data") { + target._data = value; + return true; + } + if (prop === "error") { + target._error = value; + return true; + } + + // Prevent mutation of Response properties (ESM safety) + return false; + }, + }) as HttpResponse; const responseToParse = responseFormat ? response.clone() : response; const data = !responseFormat diff --git a/tests/spec/deprecated/__snapshots__/basic.test.ts.snap b/tests/spec/deprecated/__snapshots__/basic.test.ts.snap index 221243ac..217d2f1b 100644 --- a/tests/spec/deprecated/__snapshots__/basic.test.ts.snap +++ b/tests/spec/deprecated/__snapshots__/basic.test.ts.snap @@ -237,29 +237,48 @@ export class HttpClient { : payloadFormatter(body), }, ).then(async (response) => { - // Create a wrapper object that doesn't mutate the Response + // Create a Proxy that wraps the Response without mutating it // This ensures compatibility with ESM environments where Response is read-only - const r = { - data: null as unknown as T, - error: null as unknown as E, - // Delegate Response properties - ok: response.ok, - status: response.status, - statusText: response.statusText, - headers: response.headers, - url: response.url, - redirected: response.redirected, - type: response.type, - body: response.body, - bodyUsed: response.bodyUsed, - // Delegate Response methods - arrayBuffer: () => response.arrayBuffer(), - blob: () => response.blob(), - clone: () => response.clone(), - formData: () => response.formData(), - json: () => response.json(), - text: () => response.text(), - } as HttpResponse; + // while maintaining all Response properties and methods as live/dynamic values + const r = new Proxy(response, { + get(target, prop) { + // Custom properties for our API wrapper + if (prop === "data") { + return target._data !== undefined + ? target._data + : (null as unknown as T); + } + if (prop === "error") { + return target._error !== undefined + ? target._error + : (null as unknown as E); + } + + // Delegate everything else to the actual Response object + const value = target[prop]; + + // Bind methods to the original response to maintain correct 'this' context + if (typeof value === "function") { + return value.bind(target); + } + + return value; + }, + set(target, prop, value) { + // Allow setting data and error properties + if (prop === "data") { + target._data = value; + return true; + } + if (prop === "error") { + target._error = value; + return true; + } + + // Prevent mutation of Response properties (ESM safety) + return false; + }, + }) as HttpResponse; const responseToParse = responseFormat ? response.clone() : response; const data = !responseFormat diff --git a/tests/spec/dot-path-params/__snapshots__/basic.test.ts.snap b/tests/spec/dot-path-params/__snapshots__/basic.test.ts.snap index dbc7735a..8d456d2e 100644 --- a/tests/spec/dot-path-params/__snapshots__/basic.test.ts.snap +++ b/tests/spec/dot-path-params/__snapshots__/basic.test.ts.snap @@ -239,29 +239,48 @@ export class HttpClient { : payloadFormatter(body), }, ).then(async (response) => { - // Create a wrapper object that doesn't mutate the Response + // Create a Proxy that wraps the Response without mutating it // This ensures compatibility with ESM environments where Response is read-only - const r = { - data: null as unknown as T, - error: null as unknown as E, - // Delegate Response properties - ok: response.ok, - status: response.status, - statusText: response.statusText, - headers: response.headers, - url: response.url, - redirected: response.redirected, - type: response.type, - body: response.body, - bodyUsed: response.bodyUsed, - // Delegate Response methods - arrayBuffer: () => response.arrayBuffer(), - blob: () => response.blob(), - clone: () => response.clone(), - formData: () => response.formData(), - json: () => response.json(), - text: () => response.text(), - } as HttpResponse; + // while maintaining all Response properties and methods as live/dynamic values + const r = new Proxy(response, { + get(target, prop) { + // Custom properties for our API wrapper + if (prop === "data") { + return target._data !== undefined + ? target._data + : (null as unknown as T); + } + if (prop === "error") { + return target._error !== undefined + ? target._error + : (null as unknown as E); + } + + // Delegate everything else to the actual Response object + const value = target[prop]; + + // Bind methods to the original response to maintain correct 'this' context + if (typeof value === "function") { + return value.bind(target); + } + + return value; + }, + set(target, prop, value) { + // Allow setting data and error properties + if (prop === "data") { + target._data = value; + return true; + } + if (prop === "error") { + target._error = value; + return true; + } + + // Prevent mutation of Response properties (ESM safety) + return false; + }, + }) as HttpResponse; const responseToParse = responseFormat ? response.clone() : response; const data = !responseFormat diff --git a/tests/spec/enumNamesAsValues/__snapshots__/basic.test.ts.snap b/tests/spec/enumNamesAsValues/__snapshots__/basic.test.ts.snap index ab50f685..d8ffae6e 100644 --- a/tests/spec/enumNamesAsValues/__snapshots__/basic.test.ts.snap +++ b/tests/spec/enumNamesAsValues/__snapshots__/basic.test.ts.snap @@ -429,29 +429,48 @@ export class HttpClient { : payloadFormatter(body), }, ).then(async (response) => { - // Create a wrapper object that doesn't mutate the Response + // Create a Proxy that wraps the Response without mutating it // This ensures compatibility with ESM environments where Response is read-only - const r = { - data: null as unknown as T, - error: null as unknown as E, - // Delegate Response properties - ok: response.ok, - status: response.status, - statusText: response.statusText, - headers: response.headers, - url: response.url, - redirected: response.redirected, - type: response.type, - body: response.body, - bodyUsed: response.bodyUsed, - // Delegate Response methods - arrayBuffer: () => response.arrayBuffer(), - blob: () => response.blob(), - clone: () => response.clone(), - formData: () => response.formData(), - json: () => response.json(), - text: () => response.text(), - } as HttpResponse; + // while maintaining all Response properties and methods as live/dynamic values + const r = new Proxy(response, { + get(target, prop) { + // Custom properties for our API wrapper + if (prop === "data") { + return target._data !== undefined + ? target._data + : (null as unknown as T); + } + if (prop === "error") { + return target._error !== undefined + ? target._error + : (null as unknown as E); + } + + // Delegate everything else to the actual Response object + const value = target[prop]; + + // Bind methods to the original response to maintain correct 'this' context + if (typeof value === "function") { + return value.bind(target); + } + + return value; + }, + set(target, prop, value) { + // Allow setting data and error properties + if (prop === "data") { + target._data = value; + return true; + } + if (prop === "error") { + target._error = value; + return true; + } + + // Prevent mutation of Response properties (ESM safety) + return false; + }, + }) as HttpResponse; const responseToParse = responseFormat ? response.clone() : response; const data = !responseFormat diff --git a/tests/spec/enumNamesAsValues/__snapshots__/inline.test.ts.snap b/tests/spec/enumNamesAsValues/__snapshots__/inline.test.ts.snap index 25f0776d..ac6eeb92 100644 --- a/tests/spec/enumNamesAsValues/__snapshots__/inline.test.ts.snap +++ b/tests/spec/enumNamesAsValues/__snapshots__/inline.test.ts.snap @@ -249,29 +249,48 @@ export class HttpClient { : payloadFormatter(body), }, ).then(async (response) => { - // Create a wrapper object that doesn't mutate the Response + // Create a Proxy that wraps the Response without mutating it // This ensures compatibility with ESM environments where Response is read-only - const r = { - data: null as unknown as T, - error: null as unknown as E, - // Delegate Response properties - ok: response.ok, - status: response.status, - statusText: response.statusText, - headers: response.headers, - url: response.url, - redirected: response.redirected, - type: response.type, - body: response.body, - bodyUsed: response.bodyUsed, - // Delegate Response methods - arrayBuffer: () => response.arrayBuffer(), - blob: () => response.blob(), - clone: () => response.clone(), - formData: () => response.formData(), - json: () => response.json(), - text: () => response.text(), - } as HttpResponse; + // while maintaining all Response properties and methods as live/dynamic values + const r = new Proxy(response, { + get(target, prop) { + // Custom properties for our API wrapper + if (prop === "data") { + return target._data !== undefined + ? target._data + : (null as unknown as T); + } + if (prop === "error") { + return target._error !== undefined + ? target._error + : (null as unknown as E); + } + + // Delegate everything else to the actual Response object + const value = target[prop]; + + // Bind methods to the original response to maintain correct 'this' context + if (typeof value === "function") { + return value.bind(target); + } + + return value; + }, + set(target, prop, value) { + // Allow setting data and error properties + if (prop === "data") { + target._data = value; + return true; + } + if (prop === "error") { + target._error = value; + return true; + } + + // Prevent mutation of Response properties (ESM safety) + return false; + }, + }) as HttpResponse; const responseToParse = responseFormat ? response.clone() : response; const data = !responseFormat diff --git a/tests/spec/enumNotFirstInComponents/__snapshots__/basic.test.ts.snap b/tests/spec/enumNotFirstInComponents/__snapshots__/basic.test.ts.snap index 00dca337..3babd9ca 100644 --- a/tests/spec/enumNotFirstInComponents/__snapshots__/basic.test.ts.snap +++ b/tests/spec/enumNotFirstInComponents/__snapshots__/basic.test.ts.snap @@ -267,29 +267,48 @@ export class HttpClient { : payloadFormatter(body), }, ).then(async (response) => { - // Create a wrapper object that doesn't mutate the Response + // Create a Proxy that wraps the Response without mutating it // This ensures compatibility with ESM environments where Response is read-only - const r = { - data: null as unknown as T, - error: null as unknown as E, - // Delegate Response properties - ok: response.ok, - status: response.status, - statusText: response.statusText, - headers: response.headers, - url: response.url, - redirected: response.redirected, - type: response.type, - body: response.body, - bodyUsed: response.bodyUsed, - // Delegate Response methods - arrayBuffer: () => response.arrayBuffer(), - blob: () => response.blob(), - clone: () => response.clone(), - formData: () => response.formData(), - json: () => response.json(), - text: () => response.text(), - } as HttpResponse; + // while maintaining all Response properties and methods as live/dynamic values + const r = new Proxy(response, { + get(target, prop) { + // Custom properties for our API wrapper + if (prop === "data") { + return target._data !== undefined + ? target._data + : (null as unknown as T); + } + if (prop === "error") { + return target._error !== undefined + ? target._error + : (null as unknown as E); + } + + // Delegate everything else to the actual Response object + const value = target[prop]; + + // Bind methods to the original response to maintain correct 'this' context + if (typeof value === "function") { + return value.bind(target); + } + + return value; + }, + set(target, prop, value) { + // Allow setting data and error properties + if (prop === "data") { + target._data = value; + return true; + } + if (prop === "error") { + target._error = value; + return true; + } + + // Prevent mutation of Response properties (ESM safety) + return false; + }, + }) as HttpResponse; const responseToParse = responseFormat ? response.clone() : response; const data = !responseFormat diff --git a/tests/spec/extractRequestBody/__snapshots__/basic.test.ts.snap b/tests/spec/extractRequestBody/__snapshots__/basic.test.ts.snap index 46b2db76..e9e70552 100644 --- a/tests/spec/extractRequestBody/__snapshots__/basic.test.ts.snap +++ b/tests/spec/extractRequestBody/__snapshots__/basic.test.ts.snap @@ -408,29 +408,48 @@ export class HttpClient { : payloadFormatter(body), }, ).then(async (response) => { - // Create a wrapper object that doesn't mutate the Response + // Create a Proxy that wraps the Response without mutating it // This ensures compatibility with ESM environments where Response is read-only - const r = { - data: null as unknown as T, - error: null as unknown as E, - // Delegate Response properties - ok: response.ok, - status: response.status, - statusText: response.statusText, - headers: response.headers, - url: response.url, - redirected: response.redirected, - type: response.type, - body: response.body, - bodyUsed: response.bodyUsed, - // Delegate Response methods - arrayBuffer: () => response.arrayBuffer(), - blob: () => response.blob(), - clone: () => response.clone(), - formData: () => response.formData(), - json: () => response.json(), - text: () => response.text(), - } as HttpResponse; + // while maintaining all Response properties and methods as live/dynamic values + const r = new Proxy(response, { + get(target, prop) { + // Custom properties for our API wrapper + if (prop === "data") { + return target._data !== undefined + ? target._data + : (null as unknown as T); + } + if (prop === "error") { + return target._error !== undefined + ? target._error + : (null as unknown as E); + } + + // Delegate everything else to the actual Response object + const value = target[prop]; + + // Bind methods to the original response to maintain correct 'this' context + if (typeof value === "function") { + return value.bind(target); + } + + return value; + }, + set(target, prop, value) { + // Allow setting data and error properties + if (prop === "data") { + target._data = value; + return true; + } + if (prop === "error") { + target._error = value; + return true; + } + + // Prevent mutation of Response properties (ESM safety) + return false; + }, + }) as HttpResponse; const responseToParse = responseFormat ? response.clone() : response; const data = !responseFormat diff --git a/tests/spec/extractRequestParams/__snapshots__/basic.test.ts.snap b/tests/spec/extractRequestParams/__snapshots__/basic.test.ts.snap index 40cd642c..e4c8a623 100644 --- a/tests/spec/extractRequestParams/__snapshots__/basic.test.ts.snap +++ b/tests/spec/extractRequestParams/__snapshots__/basic.test.ts.snap @@ -367,29 +367,48 @@ export class HttpClient { : payloadFormatter(body), }, ).then(async (response) => { - // Create a wrapper object that doesn't mutate the Response + // Create a Proxy that wraps the Response without mutating it // This ensures compatibility with ESM environments where Response is read-only - const r = { - data: null as unknown as T, - error: null as unknown as E, - // Delegate Response properties - ok: response.ok, - status: response.status, - statusText: response.statusText, - headers: response.headers, - url: response.url, - redirected: response.redirected, - type: response.type, - body: response.body, - bodyUsed: response.bodyUsed, - // Delegate Response methods - arrayBuffer: () => response.arrayBuffer(), - blob: () => response.blob(), - clone: () => response.clone(), - formData: () => response.formData(), - json: () => response.json(), - text: () => response.text(), - } as HttpResponse; + // while maintaining all Response properties and methods as live/dynamic values + const r = new Proxy(response, { + get(target, prop) { + // Custom properties for our API wrapper + if (prop === "data") { + return target._data !== undefined + ? target._data + : (null as unknown as T); + } + if (prop === "error") { + return target._error !== undefined + ? target._error + : (null as unknown as E); + } + + // Delegate everything else to the actual Response object + const value = target[prop]; + + // Bind methods to the original response to maintain correct 'this' context + if (typeof value === "function") { + return value.bind(target); + } + + return value; + }, + set(target, prop, value) { + // Allow setting data and error properties + if (prop === "data") { + target._data = value; + return true; + } + if (prop === "error") { + target._error = value; + return true; + } + + // Prevent mutation of Response properties (ESM safety) + return false; + }, + }) as HttpResponse; const responseToParse = responseFormat ? response.clone() : response; const data = !responseFormat diff --git a/tests/spec/extractResponseBody/__snapshots__/basic.test.ts.snap b/tests/spec/extractResponseBody/__snapshots__/basic.test.ts.snap index 6de7acbc..2957b874 100644 --- a/tests/spec/extractResponseBody/__snapshots__/basic.test.ts.snap +++ b/tests/spec/extractResponseBody/__snapshots__/basic.test.ts.snap @@ -392,29 +392,48 @@ export class HttpClient { : payloadFormatter(body), }, ).then(async (response) => { - // Create a wrapper object that doesn't mutate the Response + // Create a Proxy that wraps the Response without mutating it // This ensures compatibility with ESM environments where Response is read-only - const r = { - data: null as unknown as T, - error: null as unknown as E, - // Delegate Response properties - ok: response.ok, - status: response.status, - statusText: response.statusText, - headers: response.headers, - url: response.url, - redirected: response.redirected, - type: response.type, - body: response.body, - bodyUsed: response.bodyUsed, - // Delegate Response methods - arrayBuffer: () => response.arrayBuffer(), - blob: () => response.blob(), - clone: () => response.clone(), - formData: () => response.formData(), - json: () => response.json(), - text: () => response.text(), - } as HttpResponse; + // while maintaining all Response properties and methods as live/dynamic values + const r = new Proxy(response, { + get(target, prop) { + // Custom properties for our API wrapper + if (prop === "data") { + return target._data !== undefined + ? target._data + : (null as unknown as T); + } + if (prop === "error") { + return target._error !== undefined + ? target._error + : (null as unknown as E); + } + + // Delegate everything else to the actual Response object + const value = target[prop]; + + // Bind methods to the original response to maintain correct 'this' context + if (typeof value === "function") { + return value.bind(target); + } + + return value; + }, + set(target, prop, value) { + // Allow setting data and error properties + if (prop === "data") { + target._data = value; + return true; + } + if (prop === "error") { + target._error = value; + return true; + } + + // Prevent mutation of Response properties (ESM safety) + return false; + }, + }) as HttpResponse; const responseToParse = responseFormat ? response.clone() : response; const data = !responseFormat diff --git a/tests/spec/extractResponseError/__snapshots__/basic.test.ts.snap b/tests/spec/extractResponseError/__snapshots__/basic.test.ts.snap index 1d2bb6da..c4d72f60 100644 --- a/tests/spec/extractResponseError/__snapshots__/basic.test.ts.snap +++ b/tests/spec/extractResponseError/__snapshots__/basic.test.ts.snap @@ -387,29 +387,48 @@ export class HttpClient { : payloadFormatter(body), }, ).then(async (response) => { - // Create a wrapper object that doesn't mutate the Response + // Create a Proxy that wraps the Response without mutating it // This ensures compatibility with ESM environments where Response is read-only - const r = { - data: null as unknown as T, - error: null as unknown as E, - // Delegate Response properties - ok: response.ok, - status: response.status, - statusText: response.statusText, - headers: response.headers, - url: response.url, - redirected: response.redirected, - type: response.type, - body: response.body, - bodyUsed: response.bodyUsed, - // Delegate Response methods - arrayBuffer: () => response.arrayBuffer(), - blob: () => response.blob(), - clone: () => response.clone(), - formData: () => response.formData(), - json: () => response.json(), - text: () => response.text(), - } as HttpResponse; + // while maintaining all Response properties and methods as live/dynamic values + const r = new Proxy(response, { + get(target, prop) { + // Custom properties for our API wrapper + if (prop === "data") { + return target._data !== undefined + ? target._data + : (null as unknown as T); + } + if (prop === "error") { + return target._error !== undefined + ? target._error + : (null as unknown as E); + } + + // Delegate everything else to the actual Response object + const value = target[prop]; + + // Bind methods to the original response to maintain correct 'this' context + if (typeof value === "function") { + return value.bind(target); + } + + return value; + }, + set(target, prop, value) { + // Allow setting data and error properties + if (prop === "data") { + target._data = value; + return true; + } + if (prop === "error") { + target._error = value; + return true; + } + + // Prevent mutation of Response properties (ESM safety) + return false; + }, + }) as HttpResponse; const responseToParse = responseFormat ? response.clone() : response; const data = !responseFormat diff --git a/tests/spec/jsAxios/__snapshots__/basic.test.ts.snap b/tests/spec/jsAxios/__snapshots__/basic.test.ts.snap index 650334b6..df693dbe 100644 --- a/tests/spec/jsAxios/__snapshots__/basic.test.ts.snap +++ b/tests/spec/jsAxios/__snapshots__/basic.test.ts.snap @@ -170,29 +170,40 @@ export class HttpClient { : payloadFormatter(body), }, ).then(async (response) => { - // Create a wrapper object that doesn't mutate the Response + // Create a Proxy that wraps the Response without mutating it // This ensures compatibility with ESM environments where Response is read-only - const r = { - data: null, - error: null, - // Delegate Response properties - ok: response.ok, - status: response.status, - statusText: response.statusText, - headers: response.headers, - url: response.url, - redirected: response.redirected, - type: response.type, - body: response.body, - bodyUsed: response.bodyUsed, - // Delegate Response methods - arrayBuffer: () => response.arrayBuffer(), - blob: () => response.blob(), - clone: () => response.clone(), - formData: () => response.formData(), - json: () => response.json(), - text: () => response.text(), - }; + // while maintaining all Response properties and methods as live/dynamic values + const r = new Proxy(response, { + get(target, prop) { + // Custom properties for our API wrapper + if (prop === "data") { + return target._data !== undefined ? target._data : null; + } + if (prop === "error") { + return target._error !== undefined ? target._error : null; + } + // Delegate everything else to the actual Response object + const value = target[prop]; + // Bind methods to the original response to maintain correct 'this' context + if (typeof value === "function") { + return value.bind(target); + } + return value; + }, + set(target, prop, value) { + // Allow setting data and error properties + if (prop === "data") { + target._data = value; + return true; + } + if (prop === "error") { + target._error = value; + return true; + } + // Prevent mutation of Response properties (ESM safety) + return false; + }, + }); const responseToParse = responseFormat ? response.clone() : response; const data = !responseFormat ? r diff --git a/tests/spec/jsonapi-media-type/__snapshots__/basic.test.ts.snap b/tests/spec/jsonapi-media-type/__snapshots__/basic.test.ts.snap index c1f494dc..b7523b8e 100644 --- a/tests/spec/jsonapi-media-type/__snapshots__/basic.test.ts.snap +++ b/tests/spec/jsonapi-media-type/__snapshots__/basic.test.ts.snap @@ -263,29 +263,48 @@ export class HttpClient { : payloadFormatter(body), }, ).then(async (response) => { - // Create a wrapper object that doesn't mutate the Response + // Create a Proxy that wraps the Response without mutating it // This ensures compatibility with ESM environments where Response is read-only - const r = { - data: null as unknown as T, - error: null as unknown as E, - // Delegate Response properties - ok: response.ok, - status: response.status, - statusText: response.statusText, - headers: response.headers, - url: response.url, - redirected: response.redirected, - type: response.type, - body: response.body, - bodyUsed: response.bodyUsed, - // Delegate Response methods - arrayBuffer: () => response.arrayBuffer(), - blob: () => response.blob(), - clone: () => response.clone(), - formData: () => response.formData(), - json: () => response.json(), - text: () => response.text(), - } as HttpResponse; + // while maintaining all Response properties and methods as live/dynamic values + const r = new Proxy(response, { + get(target, prop) { + // Custom properties for our API wrapper + if (prop === "data") { + return target._data !== undefined + ? target._data + : (null as unknown as T); + } + if (prop === "error") { + return target._error !== undefined + ? target._error + : (null as unknown as E); + } + + // Delegate everything else to the actual Response object + const value = target[prop]; + + // Bind methods to the original response to maintain correct 'this' context + if (typeof value === "function") { + return value.bind(target); + } + + return value; + }, + set(target, prop, value) { + // Allow setting data and error properties + if (prop === "data") { + target._data = value; + return true; + } + if (prop === "error") { + target._error = value; + return true; + } + + // Prevent mutation of Response properties (ESM safety) + return false; + }, + }) as HttpResponse; const responseToParse = responseFormat ? response.clone() : response; const data = !responseFormat diff --git a/tests/spec/moduleNameFirstTag/__snapshots__/basic.test.ts.snap b/tests/spec/moduleNameFirstTag/__snapshots__/basic.test.ts.snap index 6982078d..def48e75 100644 --- a/tests/spec/moduleNameFirstTag/__snapshots__/basic.test.ts.snap +++ b/tests/spec/moduleNameFirstTag/__snapshots__/basic.test.ts.snap @@ -362,29 +362,48 @@ export class HttpClient { : payloadFormatter(body), }, ).then(async (response) => { - // Create a wrapper object that doesn't mutate the Response + // Create a Proxy that wraps the Response without mutating it // This ensures compatibility with ESM environments where Response is read-only - const r = { - data: null as unknown as T, - error: null as unknown as E, - // Delegate Response properties - ok: response.ok, - status: response.status, - statusText: response.statusText, - headers: response.headers, - url: response.url, - redirected: response.redirected, - type: response.type, - body: response.body, - bodyUsed: response.bodyUsed, - // Delegate Response methods - arrayBuffer: () => response.arrayBuffer(), - blob: () => response.blob(), - clone: () => response.clone(), - formData: () => response.formData(), - json: () => response.json(), - text: () => response.text(), - } as HttpResponse; + // while maintaining all Response properties and methods as live/dynamic values + const r = new Proxy(response, { + get(target, prop) { + // Custom properties for our API wrapper + if (prop === "data") { + return target._data !== undefined + ? target._data + : (null as unknown as T); + } + if (prop === "error") { + return target._error !== undefined + ? target._error + : (null as unknown as E); + } + + // Delegate everything else to the actual Response object + const value = target[prop]; + + // Bind methods to the original response to maintain correct 'this' context + if (typeof value === "function") { + return value.bind(target); + } + + return value; + }, + set(target, prop, value) { + // Allow setting data and error properties + if (prop === "data") { + target._data = value; + return true; + } + if (prop === "error") { + target._error = value; + return true; + } + + // Prevent mutation of Response properties (ESM safety) + return false; + }, + }) as HttpResponse; const responseToParse = responseFormat ? response.clone() : response; const data = !responseFormat diff --git a/tests/spec/moduleNameIndex/__snapshots__/basic.test.ts.snap b/tests/spec/moduleNameIndex/__snapshots__/basic.test.ts.snap index 91f62c5d..16474cfa 100644 --- a/tests/spec/moduleNameIndex/__snapshots__/basic.test.ts.snap +++ b/tests/spec/moduleNameIndex/__snapshots__/basic.test.ts.snap @@ -362,29 +362,48 @@ export class HttpClient { : payloadFormatter(body), }, ).then(async (response) => { - // Create a wrapper object that doesn't mutate the Response + // Create a Proxy that wraps the Response without mutating it // This ensures compatibility with ESM environments where Response is read-only - const r = { - data: null as unknown as T, - error: null as unknown as E, - // Delegate Response properties - ok: response.ok, - status: response.status, - statusText: response.statusText, - headers: response.headers, - url: response.url, - redirected: response.redirected, - type: response.type, - body: response.body, - bodyUsed: response.bodyUsed, - // Delegate Response methods - arrayBuffer: () => response.arrayBuffer(), - blob: () => response.blob(), - clone: () => response.clone(), - formData: () => response.formData(), - json: () => response.json(), - text: () => response.text(), - } as HttpResponse; + // while maintaining all Response properties and methods as live/dynamic values + const r = new Proxy(response, { + get(target, prop) { + // Custom properties for our API wrapper + if (prop === "data") { + return target._data !== undefined + ? target._data + : (null as unknown as T); + } + if (prop === "error") { + return target._error !== undefined + ? target._error + : (null as unknown as E); + } + + // Delegate everything else to the actual Response object + const value = target[prop]; + + // Bind methods to the original response to maintain correct 'this' context + if (typeof value === "function") { + return value.bind(target); + } + + return value; + }, + set(target, prop, value) { + // Allow setting data and error properties + if (prop === "data") { + target._data = value; + return true; + } + if (prop === "error") { + target._error = value; + return true; + } + + // Prevent mutation of Response properties (ESM safety) + return false; + }, + }) as HttpResponse; const responseToParse = responseFormat ? response.clone() : response; const data = !responseFormat diff --git a/tests/spec/on-insert-path-param/__snapshots__/basic.test.ts.snap b/tests/spec/on-insert-path-param/__snapshots__/basic.test.ts.snap index b44091ac..fb673897 100644 --- a/tests/spec/on-insert-path-param/__snapshots__/basic.test.ts.snap +++ b/tests/spec/on-insert-path-param/__snapshots__/basic.test.ts.snap @@ -237,29 +237,48 @@ export class HttpClient { : payloadFormatter(body), }, ).then(async (response) => { - // Create a wrapper object that doesn't mutate the Response + // Create a Proxy that wraps the Response without mutating it // This ensures compatibility with ESM environments where Response is read-only - const r = { - data: null as unknown as T, - error: null as unknown as E, - // Delegate Response properties - ok: response.ok, - status: response.status, - statusText: response.statusText, - headers: response.headers, - url: response.url, - redirected: response.redirected, - type: response.type, - body: response.body, - bodyUsed: response.bodyUsed, - // Delegate Response methods - arrayBuffer: () => response.arrayBuffer(), - blob: () => response.blob(), - clone: () => response.clone(), - formData: () => response.formData(), - json: () => response.json(), - text: () => response.text(), - } as HttpResponse; + // while maintaining all Response properties and methods as live/dynamic values + const r = new Proxy(response, { + get(target, prop) { + // Custom properties for our API wrapper + if (prop === "data") { + return target._data !== undefined + ? target._data + : (null as unknown as T); + } + if (prop === "error") { + return target._error !== undefined + ? target._error + : (null as unknown as E); + } + + // Delegate everything else to the actual Response object + const value = target[prop]; + + // Bind methods to the original response to maintain correct 'this' context + if (typeof value === "function") { + return value.bind(target); + } + + return value; + }, + set(target, prop, value) { + // Allow setting data and error properties + if (prop === "data") { + target._data = value; + return true; + } + if (prop === "error") { + target._error = value; + return true; + } + + // Prevent mutation of Response properties (ESM safety) + return false; + }, + }) as HttpResponse; const responseToParse = responseFormat ? response.clone() : response; const data = !responseFormat diff --git a/tests/spec/operationId-starting-with-number/__snapshots__/basic.test.ts.snap b/tests/spec/operationId-starting-with-number/__snapshots__/basic.test.ts.snap index adaa1cc4..93968e6d 100644 --- a/tests/spec/operationId-starting-with-number/__snapshots__/basic.test.ts.snap +++ b/tests/spec/operationId-starting-with-number/__snapshots__/basic.test.ts.snap @@ -258,29 +258,44 @@ export class HttpClient { body: typeof body === "undefined" || body === null ? null : payloadFormatter(body), } ).then(async (response) => { - // Create a wrapper object that doesn't mutate the Response + // Create a Proxy that wraps the Response without mutating it // This ensures compatibility with ESM environments where Response is read-only - const r = { - data: (null as unknown) as T, - error: (null as unknown) as E, - // Delegate Response properties - ok: response.ok, - status: response.status, - statusText: response.statusText, - headers: response.headers, - url: response.url, - redirected: response.redirected, - type: response.type, - body: response.body, - bodyUsed: response.bodyUsed, - // Delegate Response methods - arrayBuffer: () => response.arrayBuffer(), - blob: () => response.blob(), - clone: () => response.clone(), - formData: () => response.formData(), - json: () => response.json(), - text: () => response.text(), - } as HttpResponse; + // while maintaining all Response properties and methods as live/dynamic values + const r = new Proxy(response, { + get(target, prop) { + // Custom properties for our API wrapper + if (prop === 'data') { + return target._data !== undefined ? target._data : (null as unknown) as T; + } + if (prop === 'error') { + return target._error !== undefined ? target._error : (null as unknown) as E; + } + + // Delegate everything else to the actual Response object + const value = target[prop]; + + // Bind methods to the original response to maintain correct 'this' context + if (typeof value === 'function') { + return value.bind(target); + } + + return value; + }, + set(target, prop, value) { + // Allow setting data and error properties + if (prop === 'data') { + target._data = value; + return true; + } + if (prop === 'error') { + target._error = value; + return true; + } + + // Prevent mutation of Response properties (ESM safety) + return false; + } + }) as HttpResponse; const responseToParse = responseFormat ? response.clone() : response; const data = !responseFormat ? r : await responseToParse[responseFormat]() diff --git a/tests/spec/patch/__snapshots__/basic.test.ts.snap b/tests/spec/patch/__snapshots__/basic.test.ts.snap index 8fd53a79..1870e62f 100644 --- a/tests/spec/patch/__snapshots__/basic.test.ts.snap +++ b/tests/spec/patch/__snapshots__/basic.test.ts.snap @@ -1994,29 +1994,48 @@ export class HttpClient { : payloadFormatter(body), }, ).then(async (response) => { - // Create a wrapper object that doesn't mutate the Response + // Create a Proxy that wraps the Response without mutating it // This ensures compatibility with ESM environments where Response is read-only - const r = { - data: null as unknown as T, - error: null as unknown as E, - // Delegate Response properties - ok: response.ok, - status: response.status, - statusText: response.statusText, - headers: response.headers, - url: response.url, - redirected: response.redirected, - type: response.type, - body: response.body, - bodyUsed: response.bodyUsed, - // Delegate Response methods - arrayBuffer: () => response.arrayBuffer(), - blob: () => response.blob(), - clone: () => response.clone(), - formData: () => response.formData(), - json: () => response.json(), - text: () => response.text(), - } as HttpResponse; + // while maintaining all Response properties and methods as live/dynamic values + const r = new Proxy(response, { + get(target, prop) { + // Custom properties for our API wrapper + if (prop === "data") { + return target._data !== undefined + ? target._data + : (null as unknown as T); + } + if (prop === "error") { + return target._error !== undefined + ? target._error + : (null as unknown as E); + } + + // Delegate everything else to the actual Response object + const value = target[prop]; + + // Bind methods to the original response to maintain correct 'this' context + if (typeof value === "function") { + return value.bind(target); + } + + return value; + }, + set(target, prop, value) { + // Allow setting data and error properties + if (prop === "data") { + target._data = value; + return true; + } + if (prop === "error") { + target._error = value; + return true; + } + + // Prevent mutation of Response properties (ESM safety) + return false; + }, + }) as HttpResponse; const responseToParse = responseFormat ? response.clone() : response; const data = !responseFormat diff --git a/tests/spec/responses/__snapshots__/basic.test.ts.snap b/tests/spec/responses/__snapshots__/basic.test.ts.snap index 1ff7d460..3985226f 100644 --- a/tests/spec/responses/__snapshots__/basic.test.ts.snap +++ b/tests/spec/responses/__snapshots__/basic.test.ts.snap @@ -277,29 +277,48 @@ export class HttpClient { : payloadFormatter(body), }, ).then(async (response) => { - // Create a wrapper object that doesn't mutate the Response + // Create a Proxy that wraps the Response without mutating it // This ensures compatibility with ESM environments where Response is read-only - const r = { - data: null as unknown as T, - error: null as unknown as E, - // Delegate Response properties - ok: response.ok, - status: response.status, - statusText: response.statusText, - headers: response.headers, - url: response.url, - redirected: response.redirected, - type: response.type, - body: response.body, - bodyUsed: response.bodyUsed, - // Delegate Response methods - arrayBuffer: () => response.arrayBuffer(), - blob: () => response.blob(), - clone: () => response.clone(), - formData: () => response.formData(), - json: () => response.json(), - text: () => response.text(), - } as HttpResponse; + // while maintaining all Response properties and methods as live/dynamic values + const r = new Proxy(response, { + get(target, prop) { + // Custom properties for our API wrapper + if (prop === "data") { + return target._data !== undefined + ? target._data + : (null as unknown as T); + } + if (prop === "error") { + return target._error !== undefined + ? target._error + : (null as unknown as E); + } + + // Delegate everything else to the actual Response object + const value = target[prop]; + + // Bind methods to the original response to maintain correct 'this' context + if (typeof value === "function") { + return value.bind(target); + } + + return value; + }, + set(target, prop, value) { + // Allow setting data and error properties + if (prop === "data") { + target._data = value; + return true; + } + if (prop === "error") { + target._error = value; + return true; + } + + // Prevent mutation of Response properties (ESM safety) + return false; + }, + }) as HttpResponse; const responseToParse = responseFormat ? response.clone() : response; const data = !responseFormat diff --git a/tests/spec/singleHttpClient/__snapshots__/basic.test.ts.snap b/tests/spec/singleHttpClient/__snapshots__/basic.test.ts.snap index 710d6699..423e7ec7 100644 --- a/tests/spec/singleHttpClient/__snapshots__/basic.test.ts.snap +++ b/tests/spec/singleHttpClient/__snapshots__/basic.test.ts.snap @@ -237,29 +237,48 @@ export class HttpClient { : payloadFormatter(body), }, ).then(async (response) => { - // Create a wrapper object that doesn't mutate the Response + // Create a Proxy that wraps the Response without mutating it // This ensures compatibility with ESM environments where Response is read-only - const r = { - data: null as unknown as T, - error: null as unknown as E, - // Delegate Response properties - ok: response.ok, - status: response.status, - statusText: response.statusText, - headers: response.headers, - url: response.url, - redirected: response.redirected, - type: response.type, - body: response.body, - bodyUsed: response.bodyUsed, - // Delegate Response methods - arrayBuffer: () => response.arrayBuffer(), - blob: () => response.blob(), - clone: () => response.clone(), - formData: () => response.formData(), - json: () => response.json(), - text: () => response.text(), - } as HttpResponse; + // while maintaining all Response properties and methods as live/dynamic values + const r = new Proxy(response, { + get(target, prop) { + // Custom properties for our API wrapper + if (prop === "data") { + return target._data !== undefined + ? target._data + : (null as unknown as T); + } + if (prop === "error") { + return target._error !== undefined + ? target._error + : (null as unknown as E); + } + + // Delegate everything else to the actual Response object + const value = target[prop]; + + // Bind methods to the original response to maintain correct 'this' context + if (typeof value === "function") { + return value.bind(target); + } + + return value; + }, + set(target, prop, value) { + // Allow setting data and error properties + if (prop === "data") { + target._data = value; + return true; + } + if (prop === "error") { + target._error = value; + return true; + } + + // Prevent mutation of Response properties (ESM safety) + return false; + }, + }) as HttpResponse; const responseToParse = responseFormat ? response.clone() : response; const data = !responseFormat diff --git a/tests/spec/sortTypes-false/__snapshots__/basic.test.ts.snap b/tests/spec/sortTypes-false/__snapshots__/basic.test.ts.snap index 5e5c37eb..ad0c9a82 100644 --- a/tests/spec/sortTypes-false/__snapshots__/basic.test.ts.snap +++ b/tests/spec/sortTypes-false/__snapshots__/basic.test.ts.snap @@ -1994,29 +1994,48 @@ export class HttpClient { : payloadFormatter(body), }, ).then(async (response) => { - // Create a wrapper object that doesn't mutate the Response + // Create a Proxy that wraps the Response without mutating it // This ensures compatibility with ESM environments where Response is read-only - const r = { - data: null as unknown as T, - error: null as unknown as E, - // Delegate Response properties - ok: response.ok, - status: response.status, - statusText: response.statusText, - headers: response.headers, - url: response.url, - redirected: response.redirected, - type: response.type, - body: response.body, - bodyUsed: response.bodyUsed, - // Delegate Response methods - arrayBuffer: () => response.arrayBuffer(), - blob: () => response.blob(), - clone: () => response.clone(), - formData: () => response.formData(), - json: () => response.json(), - text: () => response.text(), - } as HttpResponse; + // while maintaining all Response properties and methods as live/dynamic values + const r = new Proxy(response, { + get(target, prop) { + // Custom properties for our API wrapper + if (prop === "data") { + return target._data !== undefined + ? target._data + : (null as unknown as T); + } + if (prop === "error") { + return target._error !== undefined + ? target._error + : (null as unknown as E); + } + + // Delegate everything else to the actual Response object + const value = target[prop]; + + // Bind methods to the original response to maintain correct 'this' context + if (typeof value === "function") { + return value.bind(target); + } + + return value; + }, + set(target, prop, value) { + // Allow setting data and error properties + if (prop === "data") { + target._data = value; + return true; + } + if (prop === "error") { + target._error = value; + return true; + } + + // Prevent mutation of Response properties (ESM safety) + return false; + }, + }) as HttpResponse; const responseToParse = responseFormat ? response.clone() : response; const data = !responseFormat diff --git a/tests/spec/sortTypes/__snapshots__/basic.test.ts.snap b/tests/spec/sortTypes/__snapshots__/basic.test.ts.snap index f128795e..42749b8f 100644 --- a/tests/spec/sortTypes/__snapshots__/basic.test.ts.snap +++ b/tests/spec/sortTypes/__snapshots__/basic.test.ts.snap @@ -1994,29 +1994,48 @@ export class HttpClient { : payloadFormatter(body), }, ).then(async (response) => { - // Create a wrapper object that doesn't mutate the Response + // Create a Proxy that wraps the Response without mutating it // This ensures compatibility with ESM environments where Response is read-only - const r = { - data: null as unknown as T, - error: null as unknown as E, - // Delegate Response properties - ok: response.ok, - status: response.status, - statusText: response.statusText, - headers: response.headers, - url: response.url, - redirected: response.redirected, - type: response.type, - body: response.body, - bodyUsed: response.bodyUsed, - // Delegate Response methods - arrayBuffer: () => response.arrayBuffer(), - blob: () => response.blob(), - clone: () => response.clone(), - formData: () => response.formData(), - json: () => response.json(), - text: () => response.text(), - } as HttpResponse; + // while maintaining all Response properties and methods as live/dynamic values + const r = new Proxy(response, { + get(target, prop) { + // Custom properties for our API wrapper + if (prop === "data") { + return target._data !== undefined + ? target._data + : (null as unknown as T); + } + if (prop === "error") { + return target._error !== undefined + ? target._error + : (null as unknown as E); + } + + // Delegate everything else to the actual Response object + const value = target[prop]; + + // Bind methods to the original response to maintain correct 'this' context + if (typeof value === "function") { + return value.bind(target); + } + + return value; + }, + set(target, prop, value) { + // Allow setting data and error properties + if (prop === "data") { + target._data = value; + return true; + } + if (prop === "error") { + target._error = value; + return true; + } + + // Prevent mutation of Response properties (ESM safety) + return false; + }, + }) as HttpResponse; const responseToParse = responseFormat ? response.clone() : response; const data = !responseFormat diff --git a/tests/spec/typeSuffixPrefix/__snapshots__/basic.test.ts.snap b/tests/spec/typeSuffixPrefix/__snapshots__/basic.test.ts.snap index 76f37c8b..4bc930ae 100644 --- a/tests/spec/typeSuffixPrefix/__snapshots__/basic.test.ts.snap +++ b/tests/spec/typeSuffixPrefix/__snapshots__/basic.test.ts.snap @@ -2006,29 +2006,48 @@ export class HttpClient { : payloadFormatter(body), }, ).then(async (response) => { - // Create a wrapper object that doesn't mutate the Response + // Create a Proxy that wraps the Response without mutating it // This ensures compatibility with ESM environments where Response is read-only - const r = { - data: null as unknown as T, - error: null as unknown as E, - // Delegate Response properties - ok: response.ok, - status: response.status, - statusText: response.statusText, - headers: response.headers, - url: response.url, - redirected: response.redirected, - type: response.type, - body: response.body, - bodyUsed: response.bodyUsed, - // Delegate Response methods - arrayBuffer: () => response.arrayBuffer(), - blob: () => response.blob(), - clone: () => response.clone(), - formData: () => response.formData(), - json: () => response.json(), - text: () => response.text(), - } as HttpResponse; + // while maintaining all Response properties and methods as live/dynamic values + const r = new Proxy(response, { + get(target, prop) { + // Custom properties for our API wrapper + if (prop === "data") { + return target._data !== undefined + ? target._data + : (null as unknown as T); + } + if (prop === "error") { + return target._error !== undefined + ? target._error + : (null as unknown as E); + } + + // Delegate everything else to the actual Response object + const value = target[prop]; + + // Bind methods to the original response to maintain correct 'this' context + if (typeof value === "function") { + return value.bind(target); + } + + return value; + }, + set(target, prop, value) { + // Allow setting data and error properties + if (prop === "data") { + target._data = value; + return true; + } + if (prop === "error") { + target._error = value; + return true; + } + + // Prevent mutation of Response properties (ESM safety) + return false; + }, + }) as HttpResponse; const responseToParse = responseFormat ? response.clone() : response; const data = !responseFormat diff --git a/tests/spec/unionEnums/__snapshots__/basic.test.ts.snap b/tests/spec/unionEnums/__snapshots__/basic.test.ts.snap index 3cc520be..afd20245 100644 --- a/tests/spec/unionEnums/__snapshots__/basic.test.ts.snap +++ b/tests/spec/unionEnums/__snapshots__/basic.test.ts.snap @@ -249,29 +249,48 @@ export class HttpClient { : payloadFormatter(body), }, ).then(async (response) => { - // Create a wrapper object that doesn't mutate the Response + // Create a Proxy that wraps the Response without mutating it // This ensures compatibility with ESM environments where Response is read-only - const r = { - data: null as unknown as T, - error: null as unknown as E, - // Delegate Response properties - ok: response.ok, - status: response.status, - statusText: response.statusText, - headers: response.headers, - url: response.url, - redirected: response.redirected, - type: response.type, - body: response.body, - bodyUsed: response.bodyUsed, - // Delegate Response methods - arrayBuffer: () => response.arrayBuffer(), - blob: () => response.blob(), - clone: () => response.clone(), - formData: () => response.formData(), - json: () => response.json(), - text: () => response.text(), - } as HttpResponse; + // while maintaining all Response properties and methods as live/dynamic values + const r = new Proxy(response, { + get(target, prop) { + // Custom properties for our API wrapper + if (prop === "data") { + return target._data !== undefined + ? target._data + : (null as unknown as T); + } + if (prop === "error") { + return target._error !== undefined + ? target._error + : (null as unknown as E); + } + + // Delegate everything else to the actual Response object + const value = target[prop]; + + // Bind methods to the original response to maintain correct 'this' context + if (typeof value === "function") { + return value.bind(target); + } + + return value; + }, + set(target, prop, value) { + // Allow setting data and error properties + if (prop === "data") { + target._data = value; + return true; + } + if (prop === "error") { + target._error = value; + return true; + } + + // Prevent mutation of Response properties (ESM safety) + return false; + }, + }) as HttpResponse; const responseToParse = responseFormat ? response.clone() : response; const data = !responseFormat