Summary
Allow consumers to provide a custom fetch implementation so the SDK works reliably across Node.js, browsers, Edge runtimes, tests, and specialised network environments.
Current Behaviour
HttpClient calls the global fetch directly. This makes it harder to test without global stubbing and limits consumers who need custom agents, tracing, proxy support, or runtime-specific fetch implementations.
Expected Behaviour
The SDK should support dependency injection for the HTTP transport while preserving the current default behaviour.
Suggested Implementation
Add a fetch?: typeof fetch or lightweight transport option to GuildPassClientConfig. Pass it into HttpClient, defaulting to globalThis.fetch. Validate that a fetch-compatible function exists at runtime and throw a clear config error if it does not.
Files or Areas Likely Affected
src/client/GuildPassClient.ts
src/http/httpClient.ts
src/http/http.types.ts
src/config/sdkConfig.ts
src/errors/errorCodes.ts
tests/client.test.ts
tests/httpClient.test.ts
docs/integration-guide.md
Acceptance Criteria
Additional Notes
This should not introduce Node-only transport dependencies because the SDK targets browser and Edge runtimes.
Summary
Allow consumers to provide a custom
fetchimplementation so the SDK works reliably across Node.js, browsers, Edge runtimes, tests, and specialised network environments.Current Behaviour
HttpClientcalls the globalfetchdirectly. This makes it harder to test without global stubbing and limits consumers who need custom agents, tracing, proxy support, or runtime-specific fetch implementations.Expected Behaviour
The SDK should support dependency injection for the HTTP transport while preserving the current default behaviour.
Suggested Implementation
Add a
fetch?: typeof fetchor lightweighttransportoption toGuildPassClientConfig. Pass it intoHttpClient, defaulting toglobalThis.fetch. Validate that a fetch-compatible function exists at runtime and throw a clear config error if it does not.Files or Areas Likely Affected
src/client/GuildPassClient.tssrc/http/httpClient.tssrc/http/http.types.tssrc/config/sdkConfig.tssrc/errors/errorCodes.tstests/client.test.tstests/httpClient.test.tsdocs/integration-guide.mdAcceptance Criteria
GuildPassClientaccepts a custom fetch-compatible functionHttpClientuses the injected transport instead of globalfetchGuildPassErrorAdditional Notes
This should not introduce Node-only transport dependencies because the SDK targets browser and Edge runtimes.