@plyaz/types 1.27.10 → 1.27.11

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1050,3 +1050,118 @@ export interface PermissionCheckerConfig {
1050
1050
  /** Enable audit logging */
1051
1051
  enableAuditLog: boolean;
1052
1052
  }
1053
+ /**
1054
+ * @fileoverview Session store interface for @plyaz/auth
1055
+ * @module @plyaz/auth/session/session-store
1056
+ *
1057
+ * @description
1058
+ * Defines the interface for session storage implementations.
1059
+ * Provides abstraction over different storage backends (cookie, memory, Redis)
1060
+ * enabling flexible session management strategies. All session stores must
1061
+ * implement this interface for consistent behavior across the auth system.
1062
+ *
1063
+ * @example
1064
+ * ```typescript
1065
+ * import { SessionStore, CookieStore } from '@plyaz/auth';
1066
+ *
1067
+ * const store: SessionStore = new CookieStore();
1068
+ * await store.set('session_123', sessionData, 3600);
1069
+ * const session = await store.get('session_123');
1070
+ * ```
1071
+ */
1072
+ /**
1073
+ * Session data interface for storage
1074
+ * Contains session information and metadata
1075
+ */
1076
+ export interface SessionData {
1077
+ /** Session ID */
1078
+ id: string;
1079
+ /** User ID */
1080
+ userId: string;
1081
+ /** Session expiration timestamp */
1082
+ expiresAt: Date;
1083
+ /** Session creation timestamp */
1084
+ createdAt: Date;
1085
+ /** Last activity timestamp */
1086
+ lastActivityAt: Date;
1087
+ /** IP address */
1088
+ ipAddress?: string;
1089
+ /** User agent string */
1090
+ userAgent?: string;
1091
+ /** Additional session metadata */
1092
+ metadata?: Record<string, unknown>;
1093
+ }
1094
+ /**
1095
+ * Session store interface
1096
+ * Defines contract for session storage implementations
1097
+ */
1098
+ export interface SessionStore {
1099
+ /**
1100
+ * Store session data
1101
+ * @param sessionId - Unique session identifier
1102
+ * @param data - Session data to store
1103
+ * @param ttlSeconds - Time to live in seconds
1104
+ * @returns Promise that resolves when session is stored
1105
+ */
1106
+ set(sessionId: string, data: SessionData, ttlSeconds: number): Promise<void>;
1107
+ /**
1108
+ * Retrieve session data
1109
+ * @param sessionId - Session identifier
1110
+ * @returns Promise that resolves to session data or null if not found
1111
+ */
1112
+ get(sessionId: string): Promise<SessionData | null>;
1113
+ /**
1114
+ * Delete session data
1115
+ * @param sessionId - Session identifier
1116
+ * @returns Promise that resolves when session is deleted
1117
+ */
1118
+ delete(sessionId: string): Promise<void>;
1119
+ /**
1120
+ * Delete all sessions for a user
1121
+ * @param userId - User identifier
1122
+ * @returns Promise that resolves to number of deleted sessions
1123
+ */
1124
+ deleteByUserId(userId: string): Promise<number>;
1125
+ /**
1126
+ * Update session activity timestamp
1127
+ * @param sessionId - Session identifier
1128
+ * @returns Promise that resolves when activity is updated
1129
+ */
1130
+ updateActivity(sessionId: string): Promise<void>;
1131
+ /**
1132
+ * Check if session exists
1133
+ * @param sessionId - Session identifier
1134
+ * @returns Promise that resolves to true if session exists
1135
+ */
1136
+ exists(sessionId: string): Promise<boolean>;
1137
+ /**
1138
+ * Get all active sessions for a user
1139
+ * @param userId - User identifier
1140
+ * @returns Promise that resolves to array of session data
1141
+ */
1142
+ getByUserId(userId: string): Promise<SessionData[]>;
1143
+ /**
1144
+ * Clean up expired sessions
1145
+ * @returns Promise that resolves to number of cleaned sessions
1146
+ */
1147
+ cleanup(): Promise<number>;
1148
+ /**
1149
+ * Get session count for a user
1150
+ * @param userId - User identifier
1151
+ * @returns Promise that resolves to session count
1152
+ */
1153
+ getSessionCount(userId: string): Promise<number>;
1154
+ }
1155
+ /**
1156
+ * Session store configuration interface
1157
+ */
1158
+ export interface SessionStoreConfig {
1159
+ /** Default TTL in seconds */
1160
+ defaultTTL: number;
1161
+ /** Maximum sessions per user */
1162
+ maxSessionsPerUser: number;
1163
+ /** Cleanup interval in seconds */
1164
+ cleanupInterval: number;
1165
+ /** Key prefix for storage */
1166
+ keyPrefix: string;
1167
+ }