Skip to content

feat: expose fetch option on ManagementClient#1352

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

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

Conversation

@tsushanth

@tsushanth tsushanth commented Jun 10, 2026

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

src/management/tests/unit/management-client-fetch.test.ts - two cases:

  • Constructs a ManagementClient with a custom fetch, fires client.rules.list(), and asserts the custom function was invoked against tenant.auth0.com/api/v2/rules and that the parsed return value matches the payload it served.
  • Constructs a ManagementClient without fetch to confirm the default global-fetch route is unchanged.

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,
});
```

@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.75%. Comparing base (a823058) to head (ad61319).

Additional details and impacted files

Impacted file tree graph

@@            Coverage Diff             @@
##           master    #1352      +/-   ##
==========================================
- Coverage   89.76%   89.75%   -0.01%     
==========================================
  Files         431      431              
  Lines       20108    20107       -1     
  Branches     9782     9782              
==========================================
- Hits        18049    18048       -1     
  Misses       2059     2059              
Flag Coverage Δ
alltests 89.75% <ø> (-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.

@harshithRai harshithRai self-assigned this Jul 7, 2026

@harshithRai harshithRai left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi @tsushanth,

Thanks for tracking this down and putting together a clean fix 🙌!
The root cause analysis in the PR description is spot on, and the source change in ManagementClient.ts is exactly right.

A few things to fix before we merge:

Chores on the GitHub side

  1. Unverified commits: The repo requires signed commits. Please rebase with GPG/SSH-signed commits (git rebase --exec 'git commit --amend --no-edit -S' HEAD~N) before we proceed.
  2. Branch is out of date: please rebase on master (ideally as part of the signed-commit rebase above, so it's one step).

Code feedback

  1. Test file location:
    The new test lands in tests/management/, but wrapper-level tests live in src/management/tests/unit/ (see management-client-custom-domain.test.ts). These two suites have different environments; tests/ runs ESM against the compiled package, src/management/tests/unit/ runs CJS directly against source. The wrapper test belongs in the unit suite.

  2. JSDoc on fetch:
    fetch inherits a doc comment from BaseClientOptions in BaseClient.ts, but that's Fern-generated and thinner than the proxy/retry/instrumentation/Workers language from the issue; worth adding an explicit JSDoc override on ManagementClientOptions.

The core fix is solid, just these before it's ready to merge 🙂.

Comment thread tests/management/ManagementClient.test.ts Outdated
@harshithRai harshithRai added enhancement An enhancement or improvement to the SDK that could not be otherwise categorized as a new feature Feature Request A feature has been asked for or suggested by the community labels Jul 9, 2026
tsushanth and others added 2 commits July 16, 2026 13:47
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.
Follow-ups on top of the custom-fetch fix:
- Move the wrapper test from tests/management/ into the unit suite
  (src/management/tests/unit/) alongside the other wrapper tests, and
  assert on the real rules.list() return value.
- Add an explicit enriched JSDoc on the public `fetch` field.
- Fix the adjacent class-level example to use `fetch:` instead of the
  `fetcher:` callback the constructor deletes.
@harshithRai
harshithRai force-pushed the feat/issue-1330-expose-fetch-option branch from 5e96b0b to ad61319 Compare July 16, 2026 08:27
@harshithRai

Copy link
Copy Markdown

Hi @tsushanth! Thanks again for the original fix and root-cause work here. Since the review comments were still open and the branch had fallen behind the v6 release, I've pushed directly to this branch (edits-by-maintainers was enabled) to get it over the line.

What I added on top of your commit:

  • Rebased onto current master (was behind the v6 release).
  • Moved the wrapper test into the unit suite (src/management/tests/unit/) alongside the other wrapper tests, and made it assert on the real rules.list() return value.
  • Added an explicit enriched JSDoc on the public fetch field (proxies, retries, instrumentation, Workers/Bun).
  • Fixed the adjacent class-level example that still used the fetcher: callback (which the constructor deletes); now uses fetch:.

Your core fix is unchanged and remains on your commit.

Your contribution is much appreciated 🙌

@harshithRai
harshithRai self-requested a review July 17, 2026 05:34
@harshithRai harshithRai added the DO NOT MERGE Do not merge this PR, even if approved label Jul 17, 2026
@harshithRai

Copy link
Copy Markdown

After a discussion with @frederikprijck on approach: for consistency with the other Auth0 SDKs, we're going to expose a wrapped fetcher (Auth0FetcherSupplier) rather than a raw fetch. The other SDKs omit both fetch and fetcher from the Fern options and re-expose a stable fetcher wrapper, hiding the codegen internals (example).

Since that's a different design and a larger change, it'll land as a separate PR rather than reworking this branch. Closing this one in favor of that - bu thanks @tsushanth for the root-cause work on #1330 and the original fix; it's what surfaced the whole issue and pointed at exactly the right layer.

Credit carried over to the new PR.

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

Labels

DO NOT MERGE Do not merge this PR, even if approved enhancement An enhancement or improvement to the SDK that could not be otherwise categorized as a new feature Feature Request A feature has been asked for or suggested by the community

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Adding support for fetch options in V5?

2 participants