Skip to content

Allow custom fetch transport injection #28

@Lakes41

Description

@Lakes41

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

  • GuildPassClient accepts a custom fetch-compatible function
  • HttpClient uses the injected transport instead of global fetch
  • Existing usage without a custom transport still works
  • Missing fetch support produces a clear GuildPassError
  • Tests no longer require global fetch stubbing for all HTTP cases
  • Documentation includes a short custom transport example

Additional Notes

This should not introduce Node-only transport dependencies because the SDK targets browser and Edge runtimes.

Metadata

Metadata

Assignees

No one assigned

    Labels

    GrantFox OSSIssue tracked in GrantFox OSSMaybe RewardedIssue may be eligible for a GrantFox rewardOfficial CampaignCampaign: Official Campaign

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions