/** * Unified Storage Manager * * Handles all storage operations for sessions and users with consistent * cookie handling across different persistence methods. * * Storage methods: * - `cookie`: Browser cookies with cross-subdomain support * - `localStorage`: Persistent local storage * - `sessionStorage`: Tab-specific storage (cleared on tab close) * - `localStorage+cookie`: Hybrid mode (default) - full data in localStorage, * critical identity properties also in cookies for SSR support * - `memory`: In-memory only (no persistence) * * The `localStorage+cookie` mode is designed for traditional server-side * rendered websites where each page navigation reloads JavaScript: * - Critical properties (anonymous_id, device_id, etc.) are stored in cookies * - Cookies ensure identity persists across full page reloads * - localStorage provides fast access for SPA-style navigation * - Falls back to cookie-only if localStorage is unavailable */ import { PersistenceMethod } from "./types"; /** * Critical properties persisted to cookies in `localStorage+cookie` mode. * These ensure identity survives full page reloads in traditional SSR websites. */ export declare const COOKIE_PERSISTED_PROPERTIES: readonly ["__vt_anonymous_id", "__vt_device_id", "__vt_distinct_id", "__vt_user_state"]; /** Session cookie TTL: 30 minutes */ export declare const SESSION_COOKIE_MAX_AGE = 1800; /** User cookie TTL: 1 year */ export declare const USER_COOKIE_MAX_AGE = 31536000; export interface StorageOptions { method: PersistenceMethod; /** Enable cross-subdomain cookies (auto-detected if not specified) */ cross_subdomain?: boolean; /** Use secure cookies (auto-detected from protocol if not specified) */ secure?: boolean; /** Cookie SameSite attribute */ sameSite?: "Strict" | "Lax" | "None"; } export interface StorageItem { value: T; expiry?: number; } /** * Check if cross-subdomain cookies should be enabled. * Returns false for shared hosting platforms to prevent cookie conflicts. */ export declare function shouldUseCrossSubdomainCookie(): boolean; /** * Unified Storage Manager * * Provides consistent storage operations across all persistence methods * with automatic fallbacks and SSR support. */ export declare class StorageManager { private method; private cross_subdomain; private secure; private sameSite; private memoryStorage; private _localStorageSupported; constructor(options: StorageOptions); /** Check if localStorage is available (result is cached) */ private isLocalStorageSupported; /** Check if a key should be persisted to cookies */ private isCriticalProperty; /** * Get a value from storage. * * For `localStorage+cookie` mode: * - Critical properties: read cookie first (for SSR), fall back to localStorage * - Non-critical properties: read from localStorage only */ get(key: string): string | null; /** * Set a value in storage. * @param maxAge Cookie max age in seconds (only for cookie-based storage) * * For `localStorage+cookie` mode: * - All values stored in localStorage (if available) * - Critical properties ALWAYS stored in cookies for SSR support */ set(key: string, value: string, maxAge?: number): void; /** Remove a value from storage */ remove(key: string): void; private getLocalStoragePlusCookie; private setLocalStoragePlusCookie; private removeLocalStoragePlusCookie; private getLocalStorage; private setLocalStorage; private removeLocalStorage; private readFromSessionStorage; private writeToSessionStorage; private removeFromSessionStorage; private getCookie; private setCookie; private removeCookie; /** Get JSON value with expiry check */ getWithExpiry(key: string): T | null; /** Set JSON value with optional TTL */ setWithExpiry(key: string, value: T, ttlMs?: number): void; /** Get parsed JSON value */ getJSON(key: string): T | null; /** Set JSON value */ setJSON(key: string, value: T, maxAge?: number): void; /** Check if sessionStorage is available */ canUseSessionStorage(): boolean; /** Get sessionStorage instance (for window_id which always uses sessionStorage) */ getSessionStorage(): Storage | null; /** Update storage method at runtime */ setMethod(method: PersistenceMethod): void; /** Get current storage method */ getMethod(): PersistenceMethod; } /** Factory function to create a StorageManager with default settings */ export declare function createStorageManager(method: PersistenceMethod, cross_subdomain?: boolean): StorageManager;