/** * AuthContextManager - Manages authentication context for action execution * * This utility allows developers to set up authentication once per app/env * combination, and have those credentials automatically merged into action * inputs without needing to specify them on every call. * * @example * ```ts * // Set up auth once * ductape.action.auth({ * app: 'stripe', * env: 'prd', * headers: { Authorization: 'Bearer sk_live_xxx' } * }); * * // Now all stripe actions in prd env automatically include auth * const result = await ductape.action.run({ * app: 'stripe', * env: 'prd', * action: 'create-charge', * input: { amount: 1000, currency: 'usd' } * }); * // Headers automatically include Authorization from auth context * ``` */ import { IResolvedInput } from './input-resolver'; /** * Auth context configuration for an app/env combination */ export interface IAuthContextConfig { /** App tag */ app: string; /** Environment slug */ env: string; /** Optional product tag (defaults to current product) */ product?: string; /** Headers to inject (e.g., Authorization) */ headers?: Record; /** Body fields to inject */ body?: Record; /** Query parameters to inject */ query?: Record; /** Path parameters to inject */ params?: Record; } /** * Validation error thrown for invalid auth context */ export declare class AuthContextError extends Error { readonly errorType: 'invalid_config' | 'not_found' | 'duplicate'; constructor(message: string, errorType: 'invalid_config' | 'not_found' | 'duplicate'); } /** * AuthContextManager stores and retrieves authentication contexts * for app/env combinations. */ export declare class AuthContextManager { /** Storage for auth contexts, keyed by app:env or product:app:env */ private contexts; /** Default product for contexts without explicit product */ private defaultProduct?; /** * Set the default product for auth contexts */ setDefaultProduct(product: string): void; /** * Get the default product */ getDefaultProduct(): string | undefined; /** * Register an authentication context for an app/env combination * * @param config - Auth context configuration * @throws AuthContextError if configuration is invalid */ setAuth(config: IAuthContextConfig): void; /** * Validate that credential values are valid (not undefined) */ private validateCredentialValues; /** * Get authentication context for an app/env combination * * @param app - App tag * @param env - Environment slug * @param product - Optional product tag * @returns Auth context or undefined if not set */ getAuth(app: string, env: string, product?: string): IResolvedInput | undefined; /** * Check if auth context exists for an app/env combination */ hasAuth(app: string, env: string, product?: string): boolean; /** * Remove authentication context for an app/env combination * * @param app - App tag * @param env - Environment slug * @param product - Optional product tag * @returns true if context was removed, false if it didn't exist */ removeAuth(app: string, env: string, product?: string): boolean; /** * Clear all authentication contexts */ clearAll(): void; /** * Clear all authentication contexts for a specific app */ clearApp(app: string): void; /** * Clear all authentication contexts for a specific environment */ clearEnv(env: string): void; /** * Get all registered app/env combinations */ listContexts(): Array<{ app: string; env: string; product?: string; }>; /** * Merge auth context with user-provided input * Auth context values are used as defaults; user input takes precedence * * @param authContext - Auth context from manager * @param userInput - User-provided resolved input * @returns Merged input with auth context as defaults */ mergeWithInput(authContext: IResolvedInput, userInput: IResolvedInput): IResolvedInput; } /** * Singleton instance for convenience */ export declare const authContextManager: AuthContextManager;