UNPKG

@oxyhq/services

Version:

Reusable OxyHQ module to handle authentication, user management, karma system, device-based session management and more 🚀

55 lines • 2.52 kB
/** * Session management utilities * * Provides consistent session normalization, deduplication, and sorting * to ensure sessions are always displayed in a predictable order. */ import type { ClientSession } from '../models/session'; /** * Normalize a session to ensure all required fields are present */ export declare function normalizeSession(session: Partial<ClientSession> & { sessionId: string; }): ClientSession; /** * Compare two sessions for equality */ export declare function sessionsEqual(a: ClientSession, b: ClientSession): boolean; /** * Sort sessions by lastActive (most recent first), then by sessionId for stability */ export declare function sortSessions(sessions: ClientSession[]): ClientSession[]; /** * Deduplicate sessions by sessionId, keeping the most recent version */ export declare function deduplicateSessions(sessions: ClientSession[]): ClientSession[]; /** * Deduplicate sessions by userId, keeping only one session per user * Priority: 1) Active session (if provided), 2) Most recent session * This prevents showing duplicate accounts for the same user */ export declare function deduplicateSessionsByUserId(sessions: ClientSession[], activeSessionId?: string | null): ClientSession[]; /** * Normalize, deduplicate, and sort sessions * This ensures consistent session ordering across the application * * @param sessions - Array of sessions to normalize * @param activeSessionId - Optional active session ID to prioritize * @param deduplicateByUserId - If true, deduplicate by userId (one account per user). Default: true */ export declare function normalizeAndSortSessions(sessions: ClientSession[], activeSessionId?: string | null, deduplicateByUserId?: boolean): ClientSession[]; /** * Merge two session arrays, prioritizing newer data * Returns normalized, deduplicated, and sorted sessions * * @param existing - Existing sessions array * @param incoming - New sessions to merge in * @param activeSessionId - Optional active session ID to prioritize * @param deduplicateByUserId - If true, deduplicate by userId (one account per user). Default: true */ export declare function mergeSessions(existing: ClientSession[], incoming: ClientSession[], activeSessionId?: string | null, deduplicateByUserId?: boolean): ClientSession[]; /** * Check if two session arrays are equal (same sessionIds in same order) */ export declare function sessionsArraysEqual(a: ClientSession[], b: ClientSession[]): boolean; //# sourceMappingURL=sessionUtils.d.ts.map