Skip to content

feat: expose fetch option on ManagementClient#1352

Open
tsushanth wants to merge 1 commit into
auth0:masterfrom
tsushanth:feat/issue-1330-expose-fetch-option
Open

feat: expose fetch option on ManagementClient#1352
tsushanth wants to merge 1 commit into
auth0:masterfrom
tsushanth:feat/issue-1330-expose-fetch-option

Conversation

@tsushanth

Copy link
Copy Markdown

Why

Closes #1330.

The internal fetcher layer added `BaseClientOptions.fetch?: typeof fetch` in #1238 and routes it through `fetcherImpl(args.fetchFn ?? …)`. The public wrapper, however, both omitted `fetch` from `ManagementClientOptions` and explicitly deleted it from the incoming options bag, so library consumers had no supported way to provide their own HTTP transport — even though the SDK is already capable of using one. Typical use cases the reporter and downstream Auth0 users have called out: proxies / corporate egress, retry middlewares, OpenTelemetry instrumentation, and Cloudflare Workers / Bun targets where the global `fetch` needs swapping.

What

  • Drop `"fetch"` from the `Omit<FernClient.Options, …>` list so the field is part of the public `ManagementClientOptions` surface.
  • Stop deleting `_options.fetch` in the `ManagementClient` constructor. The internal `fetcher` is still stripped (it's a Fern implementation detail), with a comment explaining why and linking back to this issue.

Tests

`tests/management/ManagementClient.test.ts` — two cases:

  1. Constructs a `ManagementClient` with a custom `fetch` implementation, fires `client.rules.list()`, asserts the custom function was invoked at least once and that the URL targets `tenant.auth0.com/api/v2/rules`. Without the wrapper change this fails because `fetch` is silently dropped before reaching `fetcherImpl`.
  2. Constructs a `ManagementClient` without `fetch` to confirm the default global-fetch route is unchanged.

`npx jest tests/management/ManagementClient.test.ts` — both pass. `npx tsc --noEmit` clean. `eslint` clean.

Compat

Source-compatible: existing call sites that didn't pass `fetch` see no behavioural difference. Callers can now opt in:

```ts
new ManagementClient({
domain: 'tenant.auth0.com',
token: '...',
fetch: myInstrumentedFetch,
});
```

Closes auth0#1330.

The internal fetcher layer added `BaseClientOptions.fetch?: typeof
fetch` in auth0#1238 and routes it through `fetcherImpl(args.fetchFn ??
…)`. The public wrapper, however, both omitted `fetch` from
`ManagementClientOptions` and explicitly deleted it from the incoming
options bag, so library consumers had no supported way to provide their
own HTTP transport — even though the SDK is already capable of using
one.

- Drop `"fetch"` from the `Omit<FernClient.Options, …>` list so the
  field is part of the public surface.
- Stop deleting `_options.fetch` in the `ManagementClient` constructor.
  The internal `fetcher` is still stripped (it's a Fern implementation
  detail), with a comment explaining why.

Adds a focused test in `tests/management/ManagementClient.test.ts` that
constructs a `ManagementClient` with a custom `fetch`, fires a request,
and asserts the custom implementation was invoked against the expected
URL. Also covers the no-`fetch` happy path to make sure the default
global-fetch route is unchanged.
@tsushanth tsushanth requested a review from a team as a code owner June 10, 2026 18:36
@codecov

codecov Bot commented Jun 25, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 89.62%. Comparing base (71a98da) to head (5e96b0b).
⚠️ Report is 5 commits behind head on master.

Additional details and impacted files

Impacted file tree graph

@@            Coverage Diff             @@
##           master    #1352      +/-   ##
==========================================
- Coverage   89.62%   89.62%   -0.01%     
==========================================
  Files         426      426              
  Lines       19804    19803       -1     
  Branches     9716     9359     -357     
==========================================
- Hits        17749    17748       -1     
  Misses       2055     2055              
Flag Coverage Δ
alltests 89.62% <ø> (-0.01%) ⬇️

Flags with carried forward coverage won't be shown. Click here to find out more.

Files with missing lines Coverage Δ
src/management/wrapper/ManagementClient.ts 100.00% <ø> (ø)
🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Adding support for fetch options in V5?

1 participant