@plyaz/types 1.27.10 → 1.27.12

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
+ }
@@ -512,3 +512,60 @@ export interface CoreDbServiceConfig {
512
512
  */
513
513
  encryption?: DBEncryptionConfig;
514
514
  }
515
+ /**
516
+ * Core's DbService instance interface
517
+ * Returned by Core.db and DbService.getInstance()
518
+ */
519
+ export interface CoreDbServiceInstance {
520
+ /** Get the underlying database instance */
521
+ getDatabase(): CoreDatabaseInstance | undefined;
522
+ /** Execute a raw SQL query */
523
+ query<T = unknown>(sql: string, params?: unknown[]): Promise<T[]>;
524
+ /** Begin a transaction */
525
+ transaction<T>(fn: (tx: unknown) => Promise<T>): Promise<T>;
526
+ }
527
+ /** Core's database instance interface (from @plyaz/db) */
528
+ export interface CoreDatabaseInstance {
529
+ /** Close the database connection */
530
+ close?(): Promise<unknown>;
531
+ }
532
+ /**
533
+ * Core's CacheService instance interface
534
+ * Returned by Core.cache and CacheService.getInstance()
535
+ */
536
+ export interface CoreCacheServiceInstance {
537
+ /** Get the cache manager instance */
538
+ getCacheManager(): CoreCacheManagerInstance;
539
+ }
540
+ /**
541
+ * Core's CacheManager instance interface
542
+ * The actual cache operations interface
543
+ */
544
+ export interface CoreCacheManagerInstance {
545
+ /** Get a value from cache */
546
+ get<T>(key: string): Promise<T | null>;
547
+ /** Set a value in cache with optional TTL */
548
+ set<T>(key: string, value: T, ttl?: number): Promise<void>;
549
+ /** Delete a value from cache */
550
+ delete(key: string): Promise<void>;
551
+ /** Clear all cached values */
552
+ clear(): Promise<void>;
553
+ /** Check if key exists in cache */
554
+ has(key: string): Promise<boolean>;
555
+ }
556
+ /**
557
+ * Core's StorageService instance interface
558
+ * Returned by Core.storage and StorageService.getInstance()
559
+ */
560
+ export interface CoreStorageServiceInstance {
561
+ /** Close/cleanup the storage service */
562
+ close(): Promise<void>;
563
+ }
564
+ /**
565
+ * Core's NotificationService instance interface
566
+ * Returned by Core.notifications - wraps the actual @plyaz/notifications service
567
+ */
568
+ export interface CoreNotificationServiceInstance {
569
+ /** Close/cleanup the notification service */
570
+ close(): Promise<void>;
571
+ }