/** * Auth strategy resolution utilities. * * This module provides functions to automatically select and create the appropriate * authentication strategy based on available credentials and allowed methods. * * ## Usage * * ```typescript * import { resolveAuthStrategy, checkAvailableAuthMethods } from '@salesforce/b2c-tooling-sdk'; * * // Auto-select best strategy based on credentials * const strategy = resolveAuthStrategy({ * clientId: 'my-client-id', * clientSecret: process.env.CLIENT_SECRET, * }); * * // Check which methods are available * const { available, unavailable } = checkAvailableAuthMethods(credentials); * ``` * * @module auth/resolve */ import type { AuthStrategy, AuthMethod, AuthCredentials } from './types.js'; /** * Options for resolving an auth strategy. */ export interface ResolveAuthStrategyOptions { /** * Allowed authentication methods in priority order. * The first method with available credentials will be used. * Defaults to: ['client-credentials', 'implicit', 'basic', 'api-key']. * * Note: the `'jwt'` method is defined in the {@link AuthMethod} type but is * not automatically resolvable here, because JWT auth requires file paths * (e.g. `certPath`/`keyPath`) that are not part of the generic * {@link AuthCredentials} accepted by this resolver. To use JWT, instantiate * `JwtOAuthStrategy` directly instead of relying on `resolveAuthStrategy`. */ allowedMethods?: AuthMethod[]; } /** * Result of checking which auth methods are available. */ export interface AvailableAuthMethods { /** Methods that have all required credentials configured */ available: AuthMethod[]; /** Methods that are missing required credentials */ unavailable: { method: AuthMethod; reason: string; }[]; } /** * Checks which auth methods have the required credentials available. * * @param credentials - The available credentials * @param allowedMethods - Methods to check (defaults to all) * @returns Object with available and unavailable methods * * @example * ```typescript * import { checkAvailableAuthMethods } from '@salesforce/b2c-tooling-sdk'; * * const result = checkAvailableAuthMethods({ * clientId: 'my-client', * clientSecret: 'my-secret', * }); * * console.log(result.available); // ['client-credentials', 'implicit'] * ``` */ export declare function checkAvailableAuthMethods(credentials: AuthCredentials, allowedMethods?: AuthMethod[]): AvailableAuthMethods; /** * Resolves and creates the appropriate auth strategy based on credentials and allowed methods. * * Iterates through allowed methods in priority order and returns the first strategy * for which the required credentials are available. * * @param credentials - The available credentials * @param options - Resolution options (allowed methods, etc.) * @returns The resolved auth strategy * @throws Error if no allowed method has the required credentials * * @example * ```typescript * import { resolveAuthStrategy } from '@salesforce/b2c-tooling-sdk'; * * // Will use client-credentials if secret is available, otherwise implicit * const strategy = resolveAuthStrategy({ * clientId: 'my-client-id', * clientSecret: process.env.CLIENT_SECRET, // may be undefined * scopes: ['sfcc.products'], * }); * * // Force implicit auth only * const implicitStrategy = resolveAuthStrategy( * { clientId: 'my-client-id' }, * { allowedMethods: ['implicit'] } * ); * * // Use the strategy * const response = await strategy.fetch('https://example.com/api'); * ``` */ export declare function resolveAuthStrategy(credentials: AuthCredentials, options?: ResolveAuthStrategyOptions): AuthStrategy;