/** * AuthClientProvider manages AuthClient instances for multiple custom domains * @internal */ import type { DomainResolver } from "../types/mcd.js"; import type { AuthClient } from "./auth-client.js"; /** * Options for AuthClientProvider. */ interface AuthClientProviderOptions { /** * Either a static domain string or a DomainResolver function. * If a string, operates in static mode. * If a function, operates in resolver mode. */ domain: string | DomainResolver; /** * Factory function to create an AuthClient for a given domain. * Called when a new domain client is needed. */ createAuthClient: (domain: string) => AuthClient; } /** * AuthClientProvider manages creating and caching AuthClient instances for MCD mode. * * Features: * - Detects static vs resolver mode from configuration * - Pre-populates cache in static mode * - Provides request-scoped access via forRequest() in resolver mode * - Maintains bounded LRU cache of domain clients * - Shares discovery cache across all domains * * @internal */ export declare class AuthClientProvider { private mode; private staticDomain?; private resolver?; private domainClients; private createAuthClientFactory; private proxyFetchers; /** * Creates a new AuthClientProvider instance. * * @param options - Configuration options * @throws {InvalidConfigurationError} If configuration is invalid (neither domain nor resolver) * * @internal */ constructor(options: AuthClientProviderOptions); /** * Returns the configured static domain (if in static mode). * * @returns The static domain, or undefined if in resolver mode * * @internal */ get configuredDomain(): string | undefined; /** * Returns true if operating in resolver mode, false in static mode. * * @returns True if using a domain resolver, false if using a static domain * * @internal */ get isResolverMode(): boolean; /** * Gets the AuthClient for static mode (if available). * * Used internally to update provider references after construction. * * @returns The cached AuthClient in static mode, or undefined in resolver mode * * @internal */ getAuthClientForStaticMode(): AuthClient | undefined; /** * Gets an AuthClient for the current request in resolver mode. * * In static mode, always returns the same cached client. * In resolver mode, resolves the domain from headers and caches the client. * * @param headers - Request headers used for domain resolution * @param url - Optional request URL for enhanced domain resolution * @returns A promise resolving to the appropriate AuthClient * @throws {DomainResolutionError} If domain resolution fails * * @internal */ forRequest(headers: Headers, url?: URL): Promise; /** * Gets an AuthClient for a specific domain synchronously. * * Uses bounded LRU caching. If the cache exceeds MAX_DOMAIN_CLIENTS, * the oldest entry is evicted. * * @param domain - The domain to get a client for * @returns The AuthClient for the domain * * @internal */ forDomainSync(domain: string): AuthClient; /** * Gets a proxy fetcher from cache or creates one via the provided factory. * * Proxy fetchers are cached per key to avoid creating multiple instances * for the same audience or configuration. * * @param key - A unique key for the fetcher (e.g., "domain:audience") * @param factory - Factory function to create the fetcher if not cached * @returns The cached or newly created fetcher * * @internal */ getProxyFetcher(key: string, factory: () => Promise): Promise; /** * Resolves the domain from request headers using the resolver function. * * Only valid in resolver mode. * * @param headers - Request headers * @param url - Optional request URL for enhanced domain resolution * @returns A promise resolving to the resolved domain * @throws {DomainResolutionError} If resolution fails or returns empty string * * @private * @internal */ private resolveDomain; } export {};