Skip to content

feat(management): add sub-package exports and management auth helper#1373

Merged
developerkunal merged 3 commits into
masterfrom
feat/management-subpackage-exports
Jul 22, 2026
Merged

feat(management): add sub-package exports and management auth helper#1373
developerkunal merged 3 commits into
masterfrom
feat/management-subpackage-exports

Conversation

@developerkunal

Copy link
Copy Markdown
Contributor

Changes

This adds per-resource sub-package entry points and a lightweight authentication helper so applications can use the Management API without importing the full ManagementClient. This keeps bundles small on size-constrained runtimes such as Cloudflare Workers and other edge environments.

New package entry points

  • Each Management API resource is now exported from its own subpath, for example auth0/clients, auth0/users, auth0/connections, and nested resources such as auth0/clients/connections. A bundler only includes the resources an application imports, instead of the entire resource graph that the top-level ManagementClient references.
  • Adds a auth0/management entry point that exposes the management wrapper surface.

New authentication helpers (exported from auth0/management)

  • createManagementAuth(options) configures authentication once and returns { baseUrl, getToken, clientOptions }. Spread clientOptions into any sub-client so they share one cached, auto-refreshing token. Supports client credentials (client secret or client assertion) and static tokens.
  • TokenProvider is now exported for lower-level control over the token lifecycle. It performs the client credentials grant and caches the token until shortly before it expires.
  • Adds the ManagementAuth and ManagementAuthOptions types.

Usage

import { createManagementAuth } from "auth0/management";
import { ClientsClient } from "auth0/clients";
import { UsersClient } from "auth0/users";
import type { Management } from "auth0";

const auth = createManagementAuth({
  domain: "your-tenant.auth0.com",
  clientId: "your-client-id",
  clientSecret: "your-client-secret",
});

const clients = new ClientsClient(auth.clientOptions);
const users = new UsersClient(auth.clientOptions);

const body: Management.CreateClientRequestContent = { name: "My App" };
await clients.create(body);

Request and response types remain under the shared Management namespace and are imported with import type { Management } from "auth0". Because they are interfaces, they are erased at compile time and add nothing to the bundle.

These smaller bundles rely on tree-shaking, so they apply when the SDK is consumed as ESM through a bundler. A CommonJS require() cannot tree-shake and loads the full resource graph.

References

N/A

Testing

  • The full existing test suite passes without errors.

  • The build produces the new entry points for both CJS and ESM, and publint validates the exports map against the built output.

  • Bundling a single sub-client with a tree-shaking bundler confirms only the imported resource plus shared core and error code is included, and the auth helper does not pull in ManagementClient.

  • This change adds unit test coverage

  • This change adds integration test coverage

Checklist

Expose each Management API resource as its own package entry point (for example auth0/clients, auth0/users) so bundlers only include the resources an application uses. Add createManagementAuth and export TokenProvider from auth0/management so callers can configure authentication once and reuse it across sub-clients without pulling in the full ManagementClient.
@developerkunal
developerkunal requested a review from a team as a code owner July 20, 2026 14:50
@codecov

codecov Bot commented Jul 20, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 31.25000% with 11 lines in your changes missing coverage. Please review.
✅ Project coverage is 89.71%. Comparing base (a823058) to head (b72a936).

Files with missing lines Patch % Lines
src/management/wrapper/management-auth.ts 21.42% 11 Missing ⚠️
Additional details and impacted files

Impacted file tree graph

@@            Coverage Diff             @@
##           master    #1373      +/-   ##
==========================================
- Coverage   89.76%   89.71%   -0.05%     
==========================================
  Files         431      432       +1     
  Lines       20108    20124      +16     
  Branches     9782     9458     -324     
==========================================
+ Hits        18049    18054       +5     
- Misses       2059     2070      +11     
Flag Coverage Δ
alltests 89.71% <31.25%> (-0.05%) ⬇️

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

Files with missing lines Coverage Δ
src/management/index.ts 100.00% <100.00%> (ø)
src/management/wrapper/management-auth.ts 21.42% <21.42%> (ø)
🚀 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.

developerkunal and others added 2 commits July 22, 2026 17:35
… createManagementAuth

Extract the telemetry-header, token-supplier, and client-credentials type-guard logic into a shared wrapper/auth-helpers module. Both the full ManagementClient and the createManagementAuth helper now consume it, removing the duplicated implementations. createManagementAuth's clientOptions gain full parity with the full client (Auth0-Client telemetry header, custom domain header, timeout, retries, and logging passthrough) while keeping the module tree-shakeable for sub-package imports.

@ankita10119 ankita10119 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

LGTM

ankita10119
ankita10119 previously approved these changes Jul 22, 2026
@ankita10119
ankita10119 dismissed their stale review July 22, 2026 12:15

Dismissed - approved in error

@developerkunal
developerkunal merged commit 490e563 into master Jul 22, 2026
9 checks passed
@developerkunal
developerkunal deleted the feat/management-subpackage-exports branch July 22, 2026 12:23
@ankita10119 ankita10119 mentioned this pull request Jul 22, 2026
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.

4 participants