/** * Offline Mode Utility - TypeScript Implementation * * This module provides offline mode functionality for the qtests framework, * allowing tests to run without network dependencies by automatically switching * to stub implementations when offline mode is detected or explicitly enabled. * * Key features: * - Automatic offline detection based on environment variables * - Dynamic module resolution (real vs stub implementations) * - Secure path validation to prevent directory traversal attacks * - Fallback mechanisms for robust operation * - Cached module loading for performance optimization * * Security considerations: * - Path validation prevents directory traversal attacks * - Explicit stub directory checking ensures module safety * - Error handling prevents information leakage * * Performance optimizations: * - Module caching reduces repeated imports * - Lazy loading only loads modules when needed * - Conditional imports based on offline mode state */ /** * Interface representing the current environment state * Used to track and report offline mode detection and configuration */ interface EnvironmentState { codexFlag: boolean; offlineFlagExplicit: boolean; testEnvironment: boolean; isOffline: boolean; environmentDetected: boolean; } /** * Interface representing environment adapters for external dependencies * Provides unified access to both real and stub implementations */ interface EnvironmentAdapters { isOffline: boolean; axios: any; qerrors: any; } /** * Set offline mode state and clear cached modules * * This function updates the offline mode flag and clears any cached * module instances to ensure the correct implementations are loaded * on next access. * * @param offline - Whether to enable offline mode */ declare function setOfflineMode(offline: boolean): void; /** * Get current offline mode state * * @returns Current offline mode flag value */ declare function isOfflineMode(): boolean; /** * Clear cached module instances * * Forces reloading of modules on next access by clearing the cache. * This is typically called when offline mode state changes. */ declare function clearOfflineCache(): void; /** * Get appropriate axios module based on offline mode state * * This function dynamically loads either the real axios module or * the stub implementation based on the current offline mode state. * It includes comprehensive security validation and fallback mechanisms. * * Security features: * - Path validation to prevent directory traversal * - Explicit directory checking for stub modules * - Error handling with fallback to safe defaults * * @returns Promise resolving to axios module (real or stub) * @throws Error when module loading fails and no fallback is available */ declare function getAxiosModule(): Promise; /** * Get appropriate qerrors module based on offline mode state * * Currently returns a no-op implementation in both online and offline * modes, but provides the structure for future enhancement where * different error handling strategies might be needed. * * @returns Promise resolving to qerrors module */ declare function getQerrors(): Promise; /** * Get current environment state information * * This function analyzes environment variables and current state * to provide a comprehensive view of the offline mode configuration * and detection status. * * @returns EnvironmentState object with current configuration */ declare function getEnvironmentState(): EnvironmentState; /** * Create environment adapters for external dependencies * * This function provides a unified interface for accessing external * dependencies with the appropriate implementations (real or stub) * based on the current offline mode state. * * @returns Promise resolving to EnvironmentAdapters object */ declare function createEnvironmentAdapters(): Promise; export { setOfflineMode, isOfflineMode, getAxiosModule as getAxios, getQerrors, getEnvironmentState, createEnvironmentAdapters, clearOfflineCache }; //# sourceMappingURL=offlineMode.d.ts.map