diff --git a/templates/base/http-clients/fetch-http-client.ejs b/templates/base/http-clients/fetch-http-client.ejs index 9f6a5c30..dd2df425 100644 --- a/templates/base/http-clients/fetch-http-client.ejs +++ b/templates/base/http-clients/fetch-http-client.ejs @@ -196,9 +196,44 @@ 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 Proxy that wraps the Response without mutating it + // This ensures compatibility with ESM environments where Response is read-only + // 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/__snapshots__/extended.test.ts.snap b/tests/__snapshots__/extended.test.ts.snap index e95bc232..89658979 100644 --- a/tests/__snapshots__/extended.test.ts.snap +++ b/tests/__snapshots__/extended.test.ts.snap @@ -2941,9 +2941,48 @@ 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 Proxy that wraps the Response without mutating it + // This ensures compatibility with ESM environments where Response is read-only + // 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 @@ -4947,9 +4986,48 @@ 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 Proxy that wraps the Response without mutating it + // This ensures compatibility with ESM environments where Response is read-only + // 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 @@ -5229,9 +5307,48 @@ 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 Proxy that wraps the Response without mutating it + // This ensures compatibility with ESM environments where Response is read-only + // 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 @@ -5546,9 +5663,48 @@ 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 Proxy that wraps the Response without mutating it + // This ensures compatibility with ESM environments where Response is read-only + // 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 @@ -6566,9 +6722,48 @@ 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 Proxy that wraps the Response without mutating it + // This ensures compatibility with ESM environments where Response is read-only + // 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 @@ -7384,9 +7579,48 @@ 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 Proxy that wraps the Response without mutating it + // This ensures compatibility with ESM environments where Response is read-only + // 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 @@ -7744,9 +7978,48 @@ 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 Proxy that wraps the Response without mutating it + // This ensures compatibility with ESM environments where Response is read-only + // 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 @@ -8062,9 +8335,48 @@ 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 Proxy that wraps the Response without mutating it + // This ensures compatibility with ESM environments where Response is read-only + // 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 @@ -8428,9 +8740,48 @@ 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 Proxy that wraps the Response without mutating it + // This ensures compatibility with ESM environments where Response is read-only + // 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 @@ -9298,9 +9649,48 @@ 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 Proxy that wraps the Response without mutating it + // This ensures compatibility with ESM environments where Response is read-only + // 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 @@ -9924,9 +10314,48 @@ 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 Proxy that wraps the Response without mutating it + // This ensures compatibility with ESM environments where Response is read-only + // 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 @@ -10241,9 +10670,48 @@ 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 Proxy that wraps the Response without mutating it + // This ensures compatibility with ESM environments where Response is read-only + // 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 @@ -10564,9 +11032,48 @@ 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 Proxy that wraps the Response without mutating it + // This ensures compatibility with ESM environments where Response is read-only + // 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 @@ -10917,9 +11424,48 @@ 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 Proxy that wraps the Response without mutating it + // This ensures compatibility with ESM environments where Response is read-only + // 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 @@ -11271,9 +11817,48 @@ 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 Proxy that wraps the Response without mutating it + // This ensures compatibility with ESM environments where Response is read-only + // 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 @@ -11650,9 +12235,48 @@ 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 Proxy that wraps the Response without mutating it + // This ensures compatibility with ESM environments where Response is read-only + // 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 @@ -11997,9 +12621,48 @@ 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 Proxy that wraps the Response without mutating it + // This ensures compatibility with ESM environments where Response is read-only + // 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 @@ -50405,9 +51068,48 @@ 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 Proxy that wraps the Response without mutating it + // This ensures compatibility with ESM environments where Response is read-only + // 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 @@ -66208,9 +66910,48 @@ 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 Proxy that wraps the Response without mutating it + // This ensures compatibility with ESM environments where Response is read-only + // 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 @@ -67247,9 +67988,48 @@ 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 Proxy that wraps the Response without mutating it + // This ensures compatibility with ESM environments where Response is read-only + // 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 @@ -67745,9 +68525,48 @@ 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 Proxy that wraps the Response without mutating it + // This ensures compatibility with ESM environments where Response is read-only + // 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 @@ -68194,9 +69013,48 @@ 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 Proxy that wraps the Response without mutating it + // This ensures compatibility with ESM environments where Response is read-only + // 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 @@ -68590,9 +69448,48 @@ 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 Proxy that wraps the Response without mutating it + // This ensures compatibility with ESM environments where Response is read-only + // 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 @@ -68904,9 +69801,48 @@ 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 Proxy that wraps the Response without mutating it + // This ensures compatibility with ESM environments where Response is read-only + // 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 @@ -69266,9 +70202,48 @@ 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 Proxy that wraps the Response without mutating it + // This ensures compatibility with ESM environments where Response is read-only + // 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 @@ -69980,9 +70955,48 @@ 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 Proxy that wraps the Response without mutating it + // This ensures compatibility with ESM environments where Response is read-only + // 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 @@ -70565,9 +71579,48 @@ 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 Proxy that wraps the Response without mutating it + // This ensures compatibility with ESM environments where Response is read-only + // 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 @@ -70994,9 +72047,48 @@ 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 Proxy that wraps the Response without mutating it + // This ensures compatibility with ESM environments where Response is read-only + // 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 @@ -71459,9 +72551,48 @@ 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 Proxy that wraps the Response without mutating it + // This ensures compatibility with ESM environments where Response is read-only + // 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 @@ -71988,9 +73119,48 @@ 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 Proxy that wraps the Response without mutating it + // This ensures compatibility with ESM environments where Response is read-only + // 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 @@ -72380,9 +73550,48 @@ 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 Proxy that wraps the Response without mutating it + // This ensures compatibility with ESM environments where Response is read-only + // 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 @@ -72820,9 +74029,48 @@ 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 Proxy that wraps the Response without mutating it + // This ensures compatibility with ESM environments where Response is read-only + // 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 @@ -73757,9 +75005,48 @@ 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 Proxy that wraps the Response without mutating it + // This ensures compatibility with ESM environments where Response is read-only + // 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 @@ -74566,9 +75853,48 @@ 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 Proxy that wraps the Response without mutating it + // This ensures compatibility with ESM environments where Response is read-only + // 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 @@ -74961,9 +76287,48 @@ 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 Proxy that wraps the Response without mutating it + // This ensures compatibility with ESM environments where Response is read-only + // 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 @@ -75274,9 +76639,48 @@ 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 Proxy that wraps the Response without mutating it + // This ensures compatibility with ESM environments where Response is read-only + // 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 @@ -75570,9 +76974,48 @@ 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 Proxy that wraps the Response without mutating it + // This ensures compatibility with ESM environments where Response is read-only + // 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 @@ -75904,9 +77347,48 @@ 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 Proxy that wraps the Response without mutating it + // This ensures compatibility with ESM environments where Response is read-only + // 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 @@ -76647,9 +78129,48 @@ 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 Proxy that wraps the Response without mutating it + // This ensures compatibility with ESM environments where Response is read-only + // 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 @@ -77546,9 +79067,48 @@ 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 Proxy that wraps the Response without mutating it + // This ensures compatibility with ESM environments where Response is read-only + // 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 @@ -79372,9 +80932,48 @@ 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 Proxy that wraps the Response without mutating it + // This ensures compatibility with ESM environments where Response is read-only + // 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 @@ -80153,9 +81752,48 @@ 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 Proxy that wraps the Response without mutating it + // This ensures compatibility with ESM environments where Response is read-only + // 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 @@ -80504,9 +82142,48 @@ 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 Proxy that wraps the Response without mutating it + // This ensures compatibility with ESM environments where Response is read-only + // 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 @@ -80961,9 +82638,48 @@ 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 Proxy that wraps the Response without mutating it + // This ensures compatibility with ESM environments where Response is read-only + // 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 710b2300..8cf08192 100644 --- a/tests/__snapshots__/simple.test.ts.snap +++ b/tests/__snapshots__/simple.test.ts.snap @@ -394,9 +394,48 @@ 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 Proxy that wraps the Response without mutating it + // This ensures compatibility with ESM environments where Response is read-only + // 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 @@ -2746,9 +2785,48 @@ 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 Proxy that wraps the Response without mutating it + // This ensures compatibility with ESM environments where Response is read-only + // 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 @@ -3028,9 +3106,48 @@ 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 Proxy that wraps the Response without mutating it + // This ensures compatibility with ESM environments where Response is read-only + // 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 @@ -3319,9 +3436,48 @@ 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 Proxy that wraps the Response without mutating it + // This ensures compatibility with ESM environments where Response is read-only + // 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 @@ -3747,9 +3903,48 @@ 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 Proxy that wraps the Response without mutating it + // This ensures compatibility with ESM environments where Response is read-only + // 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 @@ -4518,9 +4713,48 @@ 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 Proxy that wraps the Response without mutating it + // This ensures compatibility with ESM environments where Response is read-only + // 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 @@ -4860,9 +5094,48 @@ 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 Proxy that wraps the Response without mutating it + // This ensures compatibility with ESM environments where Response is read-only + // 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 @@ -5158,9 +5431,48 @@ 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 Proxy that wraps the Response without mutating it + // This ensures compatibility with ESM environments where Response is read-only + // 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 @@ -5468,9 +5780,48 @@ 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 Proxy that wraps the Response without mutating it + // This ensures compatibility with ESM environments where Response is read-only + // 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 @@ -5852,9 +6203,48 @@ 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 Proxy that wraps the Response without mutating it + // This ensures compatibility with ESM environments where Response is read-only + // 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 @@ -6507,9 +6897,48 @@ 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 Proxy that wraps the Response without mutating it + // This ensures compatibility with ESM environments where Response is read-only + // 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 @@ -6822,9 +7251,48 @@ 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 Proxy that wraps the Response without mutating it + // This ensures compatibility with ESM environments where Response is read-only + // 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 @@ -7128,9 +7596,48 @@ 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 Proxy that wraps the Response without mutating it + // This ensures compatibility with ESM environments where Response is read-only + // 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 @@ -7481,9 +7988,48 @@ 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 Proxy that wraps the Response without mutating it + // This ensures compatibility with ESM environments where Response is read-only + // 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 @@ -7796,9 +8342,48 @@ 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 Proxy that wraps the Response without mutating it + // This ensures compatibility with ESM environments where Response is read-only + // 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 @@ -8125,9 +8710,48 @@ 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 Proxy that wraps the Response without mutating it + // This ensures compatibility with ESM environments where Response is read-only + // 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 @@ -8452,9 +9076,48 @@ 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 Proxy that wraps the Response without mutating it + // This ensures compatibility with ESM environments where Response is read-only + // 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 @@ -17424,9 +18087,48 @@ 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 Proxy that wraps the Response without mutating it + // This ensures compatibility with ESM environments where Response is read-only + // 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 @@ -38561,9 +39263,48 @@ 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 Proxy that wraps the Response without mutating it + // This ensures compatibility with ESM environments where Response is read-only + // 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 @@ -39137,9 +39878,48 @@ 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 Proxy that wraps the Response without mutating it + // This ensures compatibility with ESM environments where Response is read-only + // 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 @@ -39812,9 +40592,48 @@ 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 Proxy that wraps the Response without mutating it + // This ensures compatibility with ESM environments where Response is read-only + // 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 @@ -40106,9 +40925,48 @@ 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 Proxy that wraps the Response without mutating it + // This ensures compatibility with ESM environments where Response is read-only + // 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 @@ -40505,9 +41363,48 @@ 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 Proxy that wraps the Response without mutating it + // This ensures compatibility with ESM environments where Response is read-only + // 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 @@ -40793,9 +41690,48 @@ 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 Proxy that wraps the Response without mutating it + // This ensures compatibility with ESM environments where Response is read-only + // 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 @@ -41088,9 +42024,48 @@ 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 Proxy that wraps the Response without mutating it + // This ensures compatibility with ESM environments where Response is read-only + // 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 @@ -41584,9 +42559,48 @@ 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 Proxy that wraps the Response without mutating it + // This ensures compatibility with ESM environments where Response is read-only + // 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 @@ -42082,9 +43096,48 @@ 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 Proxy that wraps the Response without mutating it + // This ensures compatibility with ESM environments where Response is read-only + // 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 @@ -42436,9 +43489,48 @@ 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 Proxy that wraps the Response without mutating it + // This ensures compatibility with ESM environments where Response is read-only + // 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 @@ -42791,9 +43883,48 @@ 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 Proxy that wraps the Response without mutating it + // This ensures compatibility with ESM environments where Response is read-only + // 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 @@ -43182,9 +44313,48 @@ 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 Proxy that wraps the Response without mutating it + // This ensures compatibility with ESM environments where Response is read-only + // 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 @@ -43563,9 +44733,48 @@ 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 Proxy that wraps the Response without mutating it + // This ensures compatibility with ESM environments where Response is read-only + // 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 @@ -43887,9 +45096,48 @@ 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 Proxy that wraps the Response without mutating it + // This ensures compatibility with ESM environments where Response is read-only + // 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 @@ -44303,9 +45551,48 @@ 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 Proxy that wraps the Response without mutating it + // This ensures compatibility with ESM environments where Response is read-only + // 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 @@ -44995,9 +46282,48 @@ 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 Proxy that wraps the Response without mutating it + // This ensures compatibility with ESM environments where Response is read-only + // 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 @@ -45351,9 +46677,48 @@ 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 Proxy that wraps the Response without mutating it + // This ensures compatibility with ESM environments where Response is read-only + // 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 @@ -45671,9 +47036,48 @@ 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 Proxy that wraps the Response without mutating it + // This ensures compatibility with ESM environments where Response is read-only + // 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 @@ -45948,9 +47352,48 @@ 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 Proxy that wraps the Response without mutating it + // This ensures compatibility with ESM environments where Response is read-only + // 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 @@ -46250,9 +47693,48 @@ 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 Proxy that wraps the Response without mutating it + // This ensures compatibility with ESM environments where Response is read-only + // 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 @@ -46675,9 +48157,48 @@ 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 Proxy that wraps the Response without mutating it + // This ensures compatibility with ESM environments where Response is read-only + // 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 @@ -47326,9 +48847,48 @@ 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 Proxy that wraps the Response without mutating it + // This ensures compatibility with ESM environments where Response is read-only + // 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 @@ -48513,9 +50073,48 @@ 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 Proxy that wraps the Response without mutating it + // This ensures compatibility with ESM environments where Response is read-only + // 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 @@ -49306,9 +50905,48 @@ 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 Proxy that wraps the Response without mutating it + // This ensures compatibility with ESM environments where Response is read-only + // 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 @@ -49671,9 +51309,48 @@ 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 Proxy that wraps the Response without mutating it + // This ensures compatibility with ESM environments where Response is read-only + // 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 @@ -49973,9 +51650,48 @@ 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 Proxy that wraps the Response without mutating it + // This ensures compatibility with ESM environments where Response is read-only + // 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 f987d808..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,9 +265,48 @@ 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 Proxy that wraps the Response without mutating it + // This ensures compatibility with ESM environments where Response is read-only + // 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 aedb9d00..2533e5df 100644 --- a/tests/spec/custom-extensions/__snapshots__/basic.test.ts.snap +++ b/tests/spec/custom-extensions/__snapshots__/basic.test.ts.snap @@ -237,9 +237,48 @@ 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 Proxy that wraps the Response without mutating it + // This ensures compatibility with ESM environments where Response is read-only + // 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 3b138631..e43b184b 100644 --- a/tests/spec/defaultAsSuccess/__snapshots__/basic.test.ts.snap +++ b/tests/spec/defaultAsSuccess/__snapshots__/basic.test.ts.snap @@ -277,9 +277,48 @@ 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 Proxy that wraps the Response without mutating it + // This ensures compatibility with ESM environments where Response is read-only + // 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 a2198338..490e402a 100644 --- a/tests/spec/defaultResponse/__snapshots__/basic.test.ts.snap +++ b/tests/spec/defaultResponse/__snapshots__/basic.test.ts.snap @@ -237,9 +237,48 @@ 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 Proxy that wraps the Response without mutating it + // This ensures compatibility with ESM environments where Response is read-only + // 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 a8e4b05d..217d2f1b 100644 --- a/tests/spec/deprecated/__snapshots__/basic.test.ts.snap +++ b/tests/spec/deprecated/__snapshots__/basic.test.ts.snap @@ -237,9 +237,48 @@ 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 Proxy that wraps the Response without mutating it + // This ensures compatibility with ESM environments where Response is read-only + // 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 161782a2..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,9 +239,48 @@ 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 Proxy that wraps the Response without mutating it + // This ensures compatibility with ESM environments where Response is read-only + // 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 626a368e..d8ffae6e 100644 --- a/tests/spec/enumNamesAsValues/__snapshots__/basic.test.ts.snap +++ b/tests/spec/enumNamesAsValues/__snapshots__/basic.test.ts.snap @@ -429,9 +429,48 @@ 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 Proxy that wraps the Response without mutating it + // This ensures compatibility with ESM environments where Response is read-only + // 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 816ee868..ac6eeb92 100644 --- a/tests/spec/enumNamesAsValues/__snapshots__/inline.test.ts.snap +++ b/tests/spec/enumNamesAsValues/__snapshots__/inline.test.ts.snap @@ -249,9 +249,48 @@ 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 Proxy that wraps the Response without mutating it + // This ensures compatibility with ESM environments where Response is read-only + // 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 ed22a3bd..3babd9ca 100644 --- a/tests/spec/enumNotFirstInComponents/__snapshots__/basic.test.ts.snap +++ b/tests/spec/enumNotFirstInComponents/__snapshots__/basic.test.ts.snap @@ -267,9 +267,48 @@ 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 Proxy that wraps the Response without mutating it + // This ensures compatibility with ESM environments where Response is read-only + // 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 f34bbe52..e9e70552 100644 --- a/tests/spec/extractRequestBody/__snapshots__/basic.test.ts.snap +++ b/tests/spec/extractRequestBody/__snapshots__/basic.test.ts.snap @@ -408,9 +408,48 @@ 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 Proxy that wraps the Response without mutating it + // This ensures compatibility with ESM environments where Response is read-only + // 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 985bf2f2..e4c8a623 100644 --- a/tests/spec/extractRequestParams/__snapshots__/basic.test.ts.snap +++ b/tests/spec/extractRequestParams/__snapshots__/basic.test.ts.snap @@ -367,9 +367,48 @@ 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 Proxy that wraps the Response without mutating it + // This ensures compatibility with ESM environments where Response is read-only + // 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 eaf33c1d..2957b874 100644 --- a/tests/spec/extractResponseBody/__snapshots__/basic.test.ts.snap +++ b/tests/spec/extractResponseBody/__snapshots__/basic.test.ts.snap @@ -392,9 +392,48 @@ 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 Proxy that wraps the Response without mutating it + // This ensures compatibility with ESM environments where Response is read-only + // 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 e4a3e4f2..c4d72f60 100644 --- a/tests/spec/extractResponseError/__snapshots__/basic.test.ts.snap +++ b/tests/spec/extractResponseError/__snapshots__/basic.test.ts.snap @@ -387,9 +387,48 @@ 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 Proxy that wraps the Response without mutating it + // This ensures compatibility with ESM environments where Response is read-only + // 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 0b4dbc53..df693dbe 100644 --- a/tests/spec/jsAxios/__snapshots__/basic.test.ts.snap +++ b/tests/spec/jsAxios/__snapshots__/basic.test.ts.snap @@ -170,9 +170,40 @@ export class HttpClient { : payloadFormatter(body), }, ).then(async (response) => { - const r = response; - r.data = null; - r.error = null; + // Create a Proxy that wraps the Response without mutating it + // This ensures compatibility with ESM environments where Response is read-only + // 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 5f4c7ab8..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,9 +263,48 @@ 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 Proxy that wraps the Response without mutating it + // This ensures compatibility with ESM environments where Response is read-only + // 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 347ca8d6..def48e75 100644 --- a/tests/spec/moduleNameFirstTag/__snapshots__/basic.test.ts.snap +++ b/tests/spec/moduleNameFirstTag/__snapshots__/basic.test.ts.snap @@ -362,9 +362,48 @@ 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 Proxy that wraps the Response without mutating it + // This ensures compatibility with ESM environments where Response is read-only + // 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 fe0d3c47..16474cfa 100644 --- a/tests/spec/moduleNameIndex/__snapshots__/basic.test.ts.snap +++ b/tests/spec/moduleNameIndex/__snapshots__/basic.test.ts.snap @@ -362,9 +362,48 @@ 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 Proxy that wraps the Response without mutating it + // This ensures compatibility with ESM environments where Response is read-only + // 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 9328e352..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,9 +237,48 @@ 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 Proxy that wraps the Response without mutating it + // This ensures compatibility with ESM environments where Response is read-only + // 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 d1b17a5a..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,9 +258,44 @@ 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 Proxy that wraps the Response without mutating it + // This ensures compatibility with ESM environments where Response is read-only + // 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 a307e33c..1870e62f 100644 --- a/tests/spec/patch/__snapshots__/basic.test.ts.snap +++ b/tests/spec/patch/__snapshots__/basic.test.ts.snap @@ -1994,9 +1994,48 @@ 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 Proxy that wraps the Response without mutating it + // This ensures compatibility with ESM environments where Response is read-only + // 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 c368fa92..3985226f 100644 --- a/tests/spec/responses/__snapshots__/basic.test.ts.snap +++ b/tests/spec/responses/__snapshots__/basic.test.ts.snap @@ -277,9 +277,48 @@ 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 Proxy that wraps the Response without mutating it + // This ensures compatibility with ESM environments where Response is read-only + // 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 3679cfb0..423e7ec7 100644 --- a/tests/spec/singleHttpClient/__snapshots__/basic.test.ts.snap +++ b/tests/spec/singleHttpClient/__snapshots__/basic.test.ts.snap @@ -237,9 +237,48 @@ 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 Proxy that wraps the Response without mutating it + // This ensures compatibility with ESM environments where Response is read-only + // 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 69d5302e..ad0c9a82 100644 --- a/tests/spec/sortTypes-false/__snapshots__/basic.test.ts.snap +++ b/tests/spec/sortTypes-false/__snapshots__/basic.test.ts.snap @@ -1994,9 +1994,48 @@ 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 Proxy that wraps the Response without mutating it + // This ensures compatibility with ESM environments where Response is read-only + // 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 785d970c..42749b8f 100644 --- a/tests/spec/sortTypes/__snapshots__/basic.test.ts.snap +++ b/tests/spec/sortTypes/__snapshots__/basic.test.ts.snap @@ -1994,9 +1994,48 @@ 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 Proxy that wraps the Response without mutating it + // This ensures compatibility with ESM environments where Response is read-only + // 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 aef88bef..4bc930ae 100644 --- a/tests/spec/typeSuffixPrefix/__snapshots__/basic.test.ts.snap +++ b/tests/spec/typeSuffixPrefix/__snapshots__/basic.test.ts.snap @@ -2006,9 +2006,48 @@ 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 Proxy that wraps the Response without mutating it + // This ensures compatibility with ESM environments where Response is read-only + // 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 1c138869..afd20245 100644 --- a/tests/spec/unionEnums/__snapshots__/basic.test.ts.snap +++ b/tests/spec/unionEnums/__snapshots__/basic.test.ts.snap @@ -249,9 +249,48 @@ 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 Proxy that wraps the Response without mutating it + // This ensures compatibility with ESM environments where Response is read-only + // 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