import { MyOrganizationClient as FernClient } from "../Client.js"; import { type Auth0ClientTelemetryOptions } from "../utils/index.js"; import { type Auth0TokenSupplier, type Auth0FetcherSupplier } from "./auth/index.js"; import { type TokenProvider } from "../auth/index.js"; /** * All supported configuration options for the MyOrganizationClient. * * @group MyOrganization API */ type MyOrganizationClientConfig = MyOrganizationClient.MyOrganizationClientOptionsWithToken | MyOrganizationClient.MyOrganizationClientOptionsWithTokenProvider | MyOrganizationClient.MyOrganizationClientOptionsWithFetcher; export declare namespace MyOrganizationClient { /** * Base configuration options for the MyOrganization Client. * Extends the Fern client options but excludes token and environment * as these are handled by our wrapper. * * @group MyOrganization API * @public */ interface MyOrganizationClientOptions extends Omit { /** Auth0 domain (e.g., 'your-tenant.auth0.com') */ domain: string; /** * Custom base URL if you need a different API endpoint * Example: "https://your-tenant.auth0.com/custom/path" * Overrides the default URL construction from domain */ baseUrl?: string; /** * Enable/disable telemetry. Defaults to true * @defaultValue true */ telemetry?: boolean; /** Custom client information for telemetry */ clientInfo?: Auth0ClientTelemetryOptions["clientInfo"]; } /** * Configuration for token-based authentication. * Use this when you already have a valid access token or can get one. * This is the recommended approach for SPA applications. * * @group MyOrganization API * @public * * @example Static token * ```typescript * const client = new MyOrganizationClient({ * domain: 'your-tenant.auth0.com', * token: 'your-access-token' * }); * ``` * * @example Simple dynamic token * ```typescript * const client = new MyOrganizationClient({ * domain: 'your-tenant.auth0.com', * token: () => getAccessToken() // Function that returns a token * }); * ``` * * @example Recommended: Auto scope-aware token (Auth0 SPA) * ```typescript * const client = new MyOrganizationClient({ * domain: 'your-tenant.auth0.com', * token: async ({ scope }) => { * // SDK automatically passes required scopes for each API call * return await auth0.getTokenSilently({ * authorizationParams: { * scope: `openid profile email ${scope}` * } * }); * } * }); * ``` * * @example Pass your function directly * ```typescript * // Your getAccessToken function receives { scope: '...' } automatically * const client = new MyOrganizationClient({ * domain: 'your-tenant.auth0.com', * token: getAccessToken // SDK calls with required scopes * }); * * async function getAccessToken({ scope }) { * return await auth0.getTokenSilently({ * authorizationParams: { * scope: `openid profile email ${scope}` * } * }); * } * ``` * */ interface MyOrganizationClientOptionsWithToken extends MyOrganizationClientOptions { /** * Token configuration for authentication. * * Supports multiple patterns: * - **String**: Static access token * - **Function**: `(options) => string` - Token supplier that receives scope information * * The SDK always calls the function with `{ scope: string }`. Functions that don't * declare parameters will simply ignore this argument due to JavaScript's flexible * parameter handling. */ token: Auth0TokenSupplier; /** * Optional custom fetch function that can be used alongside token authentication. * When a token is provided, the Authorization header is automatically configured. * The custom fetcher can be used for additional request customization (e.g., logging, retry logic). */ fetcher?: Auth0FetcherSupplier; } /** * Configuration for server-side authentication using a TokenProvider. * Use this approach for server applications where you can use client credentials. * The TokenProvider must be imported from '@auth0/myorganization-js/server'. * * @group MyOrganization API * @public * * @example Using TokenProvider (server-side only) * ```typescript * import { ClientCredentialsTokenProvider } from '@auth0/myorganization-js/server'; * * const tokenProvider = new ClientCredentialsTokenProvider({ * domain: 'your-tenant.auth0.com', * clientId: 'your-client-id', * clientSecret: 'your-client-secret', * organization: 'org_123456789' * }); * * const client = new MyOrganizationClient({ * domain: 'your-tenant.auth0.com', // Domain passed to both (required) * tokenProvider: tokenProvider * }); * ``` */ interface MyOrganizationClientOptionsWithTokenProvider extends MyOrganizationClientOptions { /** A token provider instance (only available from server imports) */ tokenProvider: TokenProvider; /** * Optional custom fetch function that can be used alongside tokenProvider authentication. * When tokenProvider is provided, the Authorization header is automatically configured. * The custom fetcher can be used for additional request customization (e.g., logging, retry logic). */ fetcher?: Auth0FetcherSupplier; } /** * Configuration when using only a custom fetcher without token or tokenProvider. * The fetcher is responsible for handling all authentication. * * @group MyOrganization API * @public * * @example Using only a custom fetcher (fetcher handles auth) * ```typescript * const client = new MyOrganizationClient({ * domain: 'your-tenant.auth0.com', * fetcher: async (url, init, authParams) => { * const token = await getToken(); * return fetch(url, { * ...init, * headers: { * ...init?.headers, * 'Authorization': `Bearer ${token}` * } * }); * } * }); * ``` */ interface MyOrganizationClientOptionsWithFetcher extends MyOrganizationClientOptions { /** * Custom fetch function that handles all authentication and authorization. * When using fetcher without token/tokenProvider, you must add authorization headers yourself. */ fetcher: Auth0FetcherSupplier; } } /** * Auth0 MyOrganization API client wrapper. * * Provides a high-level interface to Auth0's MyOrganization API with automatic * token management, telemetry, and Auth0-specific configuration. * * @group MyOrganization API * @example Using token (SPA/Client-side) * ```typescript * const client = new MyOrganizationClient({ * domain: 'your-tenant.auth0.com', * token: () => getAccessToken() // Function that returns a token * }); * ``` * * @example Using TokenProvider (Server-side) * ```typescript * import { ClientCredentialsTokenProvider } from '@auth0/myorganization-js/server'; * * const tokenProvider = new ClientCredentialsTokenProvider({ * domain: 'your-tenant.auth0.com', * clientId: 'your-client-id', * clientSecret: 'your-client-secret', * organization: 'org_123456789' * }); * * const client = new MyOrganizationClient({ * domain: 'your-tenant.auth0.com', * tokenProvider: tokenProvider * }); * ``` */ export declare class MyOrganizationClient extends FernClient { /** * Creates a new MyOrganization API client instance. * * @param _options - Configuration options for the MyOrganizationClient Client * @group MyOrganization API */ constructor(_options: MyOrganizationClientConfig); } export {};