Skip to content

Adding support for fetch options in V5? #1330

@rexhao

Description

@rexhao

Checklist

  • I have looked into the Readme, Examples, and FAQ and have not found a suitable solution or answer.
  • I have looked into the API documentation and have not found a suitable solution or answer.
  • I have searched the issues and have not found a suitable solution or answer.
  • I have searched the Auth0 Community forums and have not found a suitable solution or answer.
  • I agree to the terms within the Auth0 Code of Conduct.

Describe the problem you'd like to have solved

Hi, I'm just wondering if there is a way to add back support for providing a custom fetch implementation in node-auth0 v5 (for example via ManagementClientOptions), so that consumers can control the HTTP transport used by the SDK.

Overview

In PR [#1238](#1238), the generated client and fetcher layer were updated to support a fetchFn override internally:

  • BaseClientOptions now has an optional fetch?: typeof fetch.
  • Resource clients pass this through as fetchFn: this._options?.fetch.
  • fetcherImpl uses args.fetchFn ?? (await getFetchFn()), so a custom fetch can be injected at the core layer.

However, the public wrapper still explicitly prevents this from being used by library consumers:

// ManagementClientOptions omits "fetch" from FernClient.Options:
export interface ManagementClientOptions
  extends Omit<FernClient.Options, "token" | "environment" | "fetcher" | "baseUrl" | "fetch"> {
  // ...
}

The ManagementClient constructor also deletes any fetch property:

// Temporarily remove fetcher from options to avoid people passing it for now
delete (_options as any).fetcher;
delete (_options as any).fetch;

So today, although the underlying transport already supports fetchFn, there is no supported public way for users to provide their own fetch.

There is [a PR](#1324) that aims to address a similar concern around retry behavior, but it seems like it would be much simpler if the SDK just exposed the fetch option so people can plug in their own implementation (including any custom retry logic) directly.

Describe the ideal solution

Officially support a fetch option on the public clients for v5

import { ManagementClient } from "auth0";
import { makeFetchWithRetry } from 'path/to/custom-retry-logic.js';

const management = new ManagementClient({
  domain: "your-tenant.auth0.com",
  clientId: "…",
  clientSecret: "…",
  // New: let consumers supply a custom fetch implementation
  fetch: makeFetchWithRetry,
});

Or if can, is there any official guidance / support for handling such scenarios?

Alternatives and current workarounds

No response

Additional context

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions