import { MyAccountClient as FernClient } from "../Client.js"; import { type Auth0ClientTelemetryOptions } from "../utils/index.js"; import { type Auth0TokenSupplier, type Auth0FetcherSupplier } from "./auth/index.js"; /** * All supported configuration options for the MyAccountClient. * * @group MyAccount API * @public */ type MyAccountClientConfig = MyAccountClient.MyAccountClientOptionsWithToken | MyAccountClient.MyAccountClientOptionsWithFetcher; export declare namespace MyAccountClient { /** * Base configuration options for the MyAccount Client. * Extends the Fern client options but excludes token and environment * as these are handled by our wrapper. * * @group MyAccount API * @public */ interface MyAccountClientOptions 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 MyAccount API * @public * * @example Static token * ```typescript * const client = new MyAccountClient({ * domain: 'your-tenant.auth0.com', * token: 'your-access-token' * }); * ``` * * @example Simple dynamic token * ```typescript * const client = new MyAccountClient({ * domain: 'your-tenant.auth0.com', * token: () => getAccessToken() // Function that returns a token * }); * ``` * * @example Recommended: Auto scope-aware token (Auth0 SPA) * ```typescript * const client = new MyAccountClient({ * 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 MyAccountClient({ * 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 MyAccountClientOptionsWithToken extends MyAccountClientOptions { /** * Token configuration for authentication. * * Supports multiple patterns: * - **String**: Static access token * - **Simple function**: `() => string` - For dynamic tokens without scope handling * - **Scope-aware function**: `({ scope }) => string` - **RECOMMENDED** for Auth0 applications * * The scope-aware function is ideal for Auth0 applications as the SDK automatically * calls your function with the required scopes (as a space-separated string) for each API endpoint. */ 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 when using only a custom fetcher without token. * The fetcher is responsible for handling all authentication. * * @group MyAccount API * @public * * @example Using only a custom fetcher (fetcher handles auth) * ```typescript * const client = new MyAccountClient({ * 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 MyAccountClientOptionsWithFetcher extends MyAccountClientOptions { /** * Custom fetch function that handles all authentication and authorization. * When using fetcher without token, you must add authorization headers yourself. */ fetcher: Auth0FetcherSupplier; } } /** * Auth0 MyAccount API client wrapper. * * Provides a high-level interface to Auth0's MyAccount API with automatic * token management, telemetry, and Auth0-specific configuration. * * @group MyAccount API * @example Using token (SPA/Client-side) * ```typescript * const client = new MyAccountClient({ * domain: 'your-tenant.auth0.com', * token: () => getAccessToken() // Function that returns a token * }); * ``` * * @example Using custom fetcher * ```typescript * const client = new MyAccountClient({ * domain: 'your-tenant.auth0.com', * fetcher: async (url, init, authParams) => { * const token = await getToken(); * return fetch(url, { * ...init, * headers: { * ...init?.headers, * 'Authorization': `Bearer ${token}` * } * }); * } * }); * ``` */ export declare class MyAccountClient extends FernClient { /** * Creates a new MyAccount API client instance. * * @param _options - Configuration options for the MyAccount Client * @group MyAccount API */ constructor(_options: MyAccountClientConfig); } export {};