saltfish
Version:
An interactive video-guided tour system for web applications
135 lines • 3.92 kB
TypeScript
import type { AnonymousUserData, PendingNavigation } from '../types';
/**
* Interface for stored session data
*/
export interface StoredSession {
sessionId: string;
lastActivity: number;
}
/**
* Interface for playlist progress data
*/
export interface PlaylistProgressData {
lastStepId: string;
lastVisited: string;
completedWaitingForInteraction?: boolean;
}
/**
* Progress data type - mapping of playlist IDs to progress data
*/
export type ProgressData = Record<string, PlaylistProgressData>;
/**
* Stored progress with user tracking
*/
export interface StoredProgressData {
userId?: string;
playlists: ProgressData;
}
/**
* Centralized manager for all localStorage operations.
*
* This class provides:
* - Type-safe methods for each storage key
* - Consistent error handling across all storage operations
* - JSON serialization/deserialization handled internally
* - Graceful degradation when localStorage is unavailable
* - Easy mocking for testing
* - Singleton pattern to ensure consistent state across the application
*/
export declare class StorageManager {
private static instance;
private isLocalStorageAvailable;
private constructor();
/**
* Get the singleton instance of StorageManager
* @returns The StorageManager instance
*/
static getInstance(): StorageManager;
/**
* Reset the singleton instance (useful for testing)
* @internal
*/
static resetInstance(): void;
/**
* Check if localStorage is available and working
*/
private checkLocalStorageAvailability;
/**
* Safely get an item from localStorage with JSON parsing
*/
private safeGetItem;
/**
* Safely set an item in localStorage with JSON stringification
*/
private safeSetItem;
/**
* Safely clear an item from localStorage
*/
private safeClearItem;
/**
* Clear old data to free up storage space
*/
private clearOldData;
/**
* Get playlist progress data for a specific user
* If userId doesn't match stored userId, returns null (stale data)
* @param userId - The user ID to validate against stored data
*/
getProgress(userId?: string): ProgressData | null;
/**
* Set playlist progress data for a specific user
* Clears existing data if userId changes
* @param progress - The progress data to save
* @param userId - The user ID to associate with this progress
*/
setProgress(progress: ProgressData, userId?: string): boolean;
/**
* Clear all progress data
*/
clearProgress(): void;
/**
* Get session data
*/
getSession(): StoredSession | null;
/**
* Set session data
*/
setSession(session: StoredSession): boolean;
/**
* Clear session data
*/
clearSession(): void;
/**
* Get anonymous user data
*/
getAnonymousUserData(): AnonymousUserData | null;
/**
* Set anonymous user data
*/
setAnonymousUserData(data: AnonymousUserData): boolean;
/**
* Clear anonymous user data
*/
clearAnonymousUserData(): void;
/**
* Get pending navigation data for cross-page URL transitions
* Used when a step has a url-path transition and user navigates causing hard refresh
*/
getPendingNavigation(): PendingNavigation | null;
/**
* Set pending navigation data
* Called when setting up a url-path transition to enable resuming after hard refresh
* @param data - The pending navigation data to save
*/
setPendingNavigation(data: PendingNavigation): boolean;
/**
* Clear pending navigation data
* Called after successful transition or when navigation is no longer valid
*/
clearPendingNavigation(): void;
/**
* Clear all storage data
*/
clearAll(): void;
}
//# sourceMappingURL=StorageManager.d.ts.map