/** * @file Unified Storage Manager * @description Consolidates all storage access (localStorage, sessionStorage, IndexedDB) * with healthcare compliance, encryption, and type safety. * * This replaces 4 separate storage implementations with a single, configurable system * that handles encryption, validation, expiration, and healthcare data protection. * * @see {@link https://example.com/docs/storage} for architecture documentation */ /** * Storage type options */ export declare enum StorageType { /** Browser localStorage - persists across sessions */ Local = "local", /** Browser sessionStorage - cleared when tab closes */ Session = "session", /** IndexedDB - persists, larger capacity, async */ IndexedDB = "indexeddb", /** Memory only - cleared on page reload */ Memory = "memory" } /** * Encryption algorithm options */ export declare enum EncryptionAlgorithm { None = "none", AES_GCM = "AES-GCM" } /** * Storage entry metadata */ export interface StorageEntry { /** The actual stored value */ value: T; /** When the entry was created */ timestamp: number; /** When the entry expires (if applicable) */ expiresAt?: number; /** Encryption algorithm used */ encryption: EncryptionAlgorithm; /** Version for migration purposes */ version: number; /** Whether this entry contains healthcare data (PHI) */ containsPHI: boolean; } /** * Configuration for a storage entry */ export interface StorageEntryConfig { /** How long to keep this entry (in ms), undefined = never expires */ ttl?: number; /** Whether this entry contains Protected Health Information */ containsPHI?: boolean; /** Encryption algorithm to use */ encryption?: EncryptionAlgorithm; } /** * Storage operation options */ export interface StorageOptions extends StorageEntryConfig { /** Whether to throw on error (default) or return undefined */ throwOnError?: boolean; } /** * Whitelist/Blacklist configuration for storage access */ export interface StorageAccessControl { /** Keys allowed in localStorage (if defined, only these are allowed) */ localstorageWhitelist?: string[]; /** Keys denied from localStorage */ localstorageBlacklist?: string[]; /** Keys allowed in sessionStorage */ sessionstoragWhitelist?: string[]; /** Keys denied from sessionStorage */ sessionstorageBlacklist?: string[]; } /** * Central storage manager for the entire application * * Provides unified access to all storage types with: * - Type safety * - Automatic expiration * - Healthcare data protection (PHI detection) * - Encryption support * - Access control (whitelist/blacklist) * - Async operations (IndexedDB) * * @example * ```typescript * const storage = StorageManager.getInstance(); * * // Simple usage * storage.setItem('theme', 'dark'); * const theme = storage.getItem('theme'); * * // With healthcare data * storage.setItem('patientId', 'PAT-12345', { * containsPHI: true, * encryption: EncryptionAlgorithm.AES_GCM, * ttl: 24 * 60 * 60 * 1000, // 24 hours * }); * * // Async IndexedDB access * await storage.setItemAsync('largeData', complexObject, { * storageType: StorageType.IndexedDB, * }); * ``` */ export declare class StorageManager { private static instance; private memoryStore; private accessControl; private dbName; private dbVersion; private constructor(); /** * Get or create the storage manager instance (singleton) */ static getInstance(accessControl?: StorageAccessControl): StorageManager; /** * Store a value in localStorage * * @param key - Storage key * @param value - Value to store * @param options - Storage options (ttl, encryption, etc.) * @throws Error if key is blacklisted or storage fails * * @example * ```typescript * storage.setItem('userId', '12345'); * storage.setItem('authToken', token, { containsPHI: true, ttl: 3600000 }); * ``` */ setItem(key: string, value: T, options?: StorageOptions): void; /** * Retrieve a value from localStorage * * @param key - Storage key * @param options - Storage options * @returns The stored value, or undefined if not found or expired * * @example * ```typescript * const userId = storage.getItem('userId'); * const theme = storage.getItem('theme', { throwOnError: false }); * ``` */ getItem(key: string, options?: StorageOptions): T | undefined; /** * Remove a value from localStorage * * @param key - Storage key * @param options - Storage options * * @example * ```typescript * storage.removeItem('authToken'); * ``` */ removeItem(key: string, options?: StorageOptions): void; /** * Check if a key exists in localStorage * * @param key - Storage key * @returns true if key exists and is not expired */ hasItem(key: string): boolean; /** * Set a value in sessionStorage (clears when tab closes) * * @param key - Storage key * @param value - Value to store * @param options - Storage options */ setSessionItem(key: string, value: T, options?: StorageOptions): void; /** * Get a value from sessionStorage * * @param key - Storage key * @param options - Storage options * @returns The stored value, or undefined if not found */ getSessionItem(key: string, options?: StorageOptions): T | undefined; /** * Set a value in memory (cleared on page reload) * * @param key - Storage key * @param value - Value to store * @param options - Storage options */ setMemoryItem(key: string, value: T, options?: StorageOptions): void; /** * Get a value from memory * * @param key - Storage key * @returns The stored value, or undefined if not found */ getMemoryItem(key: string): T | undefined; /** * Remove a value from memory * * @param key - Storage key */ removeMemoryItem(key: string): void; /** * Clear all memory storage */ clearMemory(): void; /** * Set a value in IndexedDB (async, larger capacity) * * @param key - Storage key * @param value - Value to store * @param options - Storage options * * @example * ```typescript * await storage.setItemAsync('largeData', complexObject, { * storageType: StorageType.IndexedDB, * }); * ``` */ setItemAsync(key: string, value: T, options?: StorageOptions): Promise; /** * Get a value from IndexedDB (async) * * @param key - Storage key * @param options - Storage options * @returns The stored value, or undefined if not found or expired */ getItemAsync(key: string, options?: StorageOptions): Promise; /** * Remove a value from IndexedDB * * @param key - Storage key */ removeItemAsync(key: string): Promise; /** * Clear all localStorage items (except whitelisted) * * @example * ```typescript * storage.clearLocalStorage(); * ``` */ clearLocalStorage(): void; /** * Clear all sessionStorage items */ clearSessionStorage(): void; /** * Clear all storage (localStorage, sessionStorage, memory, IndexedDB) */ clearAll(): Promise; /** * Validate that a key is allowed for the specified storage type */ private validateAccess; /** * Handle storage errors with optional error reporting */ private handleError; /** * Open IndexedDB connection */ private openDatabase; } /** * Get the global storage manager instance * * @example * ```typescript * import { getStorage } from '@/lib/shared/storage-manager'; * * const storage = getStorage(); * storage.setItem('key', 'value'); * ``` */ export declare function getStorage(accessControl?: StorageAccessControl): StorageManager;