@rapidraptor/auth-shared 0.2.0

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.
@@ -0,0 +1,46 @@
1
+ /**
2
+ * Error codes
3
+ * Type is derived from these constants in types.ts (single source of truth)
4
+ */
5
+ export declare const ERROR_CODES: {
6
+ readonly SESSION_EXPIRED: "SESSION_EXPIRED";
7
+ readonly TOKEN_EXPIRED: "TOKEN_EXPIRED";
8
+ readonly AUTH_FAILED: "AUTH_FAILED";
9
+ readonly INTERNAL_ERROR: "INTERNAL_ERROR";
10
+ readonly SERVICE_UNAVAILABLE: "SERVICE_UNAVAILABLE";
11
+ };
12
+ /**
13
+ * Default configuration values
14
+ */
15
+ export declare const DEFAULTS: {
16
+ /**
17
+ * Default inactivity timeout: 24 hours in milliseconds
18
+ */
19
+ readonly INACTIVITY_TIMEOUT_MS: number;
20
+ /**
21
+ * Default Firestore write throttle: 5 minutes in milliseconds
22
+ */
23
+ readonly FIRESTORE_WRITE_THROTTLE_MS: number;
24
+ /**
25
+ * Default Firestore collection name for sessions
26
+ */
27
+ readonly FIRESTORE_SESSIONS_COLLECTION_NAME: "user_sessions";
28
+ /**
29
+ * Default Firestore collection name for logout records
30
+ */
31
+ readonly FIRESTORE_LOGOUTS_COLLECTION_NAME: "user_logouts";
32
+ /**
33
+ * Default logout record TTL: 1 hour in milliseconds
34
+ * Matches typical JWT lifetime
35
+ */
36
+ readonly LOGOUT_TTL_MS: 3600000;
37
+ /**
38
+ * Default max retries for token refresh
39
+ */
40
+ readonly MAX_RETRIES: 1;
41
+ /**
42
+ * Default API timeout: 10 seconds
43
+ */
44
+ readonly API_TIMEOUT_MS: number;
45
+ };
46
+ //# sourceMappingURL=constants.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"constants.d.ts","sourceRoot":"","sources":["../src/constants.ts"],"names":[],"mappings":"AAAA;;;GAGG;AACH,eAAO,MAAM,WAAW;;;;;;CAMd,CAAC;AAEX;;GAEG;AACH,eAAO,MAAM,QAAQ;IACnB;;OAEG;;IAGH;;OAEG;;IAGH;;OAEG;;IAGH;;OAEG;;IAGH;;;OAGG;;IAGH;;OAEG;;IAGH;;OAEG;;CAEK,CAAC"}
@@ -0,0 +1,46 @@
1
+ /**
2
+ * Error codes
3
+ * Type is derived from these constants in types.ts (single source of truth)
4
+ */
5
+ export const ERROR_CODES = {
6
+ SESSION_EXPIRED: 'SESSION_EXPIRED',
7
+ TOKEN_EXPIRED: 'TOKEN_EXPIRED',
8
+ AUTH_FAILED: 'AUTH_FAILED',
9
+ INTERNAL_ERROR: 'INTERNAL_ERROR',
10
+ SERVICE_UNAVAILABLE: 'SERVICE_UNAVAILABLE',
11
+ };
12
+ /**
13
+ * Default configuration values
14
+ */
15
+ export const DEFAULTS = {
16
+ /**
17
+ * Default inactivity timeout: 24 hours in milliseconds
18
+ */
19
+ INACTIVITY_TIMEOUT_MS: 24 * 60 * 60 * 1000,
20
+ /**
21
+ * Default Firestore write throttle: 5 minutes in milliseconds
22
+ */
23
+ FIRESTORE_WRITE_THROTTLE_MS: 5 * 60 * 1000,
24
+ /**
25
+ * Default Firestore collection name for sessions
26
+ */
27
+ FIRESTORE_SESSIONS_COLLECTION_NAME: 'user_sessions',
28
+ /**
29
+ * Default Firestore collection name for logout records
30
+ */
31
+ FIRESTORE_LOGOUTS_COLLECTION_NAME: 'user_logouts',
32
+ /**
33
+ * Default logout record TTL: 1 hour in milliseconds
34
+ * Matches typical JWT lifetime
35
+ */
36
+ LOGOUT_TTL_MS: 3600000,
37
+ /**
38
+ * Default max retries for token refresh
39
+ */
40
+ MAX_RETRIES: 1,
41
+ /**
42
+ * Default API timeout: 10 seconds
43
+ */
44
+ API_TIMEOUT_MS: 10 * 1000,
45
+ };
46
+ //# sourceMappingURL=constants.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"constants.js","sourceRoot":"","sources":["../src/constants.ts"],"names":[],"mappings":"AAAA;;;GAGG;AACH,MAAM,CAAC,MAAM,WAAW,GAAG;IACzB,eAAe,EAAE,iBAAiB;IAClC,aAAa,EAAE,eAAe;IAC9B,WAAW,EAAE,aAAa;IAC1B,cAAc,EAAE,gBAAgB;IAChC,mBAAmB,EAAE,qBAAqB;CAClC,CAAC;AAEX;;GAEG;AACH,MAAM,CAAC,MAAM,QAAQ,GAAG;IACtB;;OAEG;IACH,qBAAqB,EAAE,EAAE,GAAG,EAAE,GAAG,EAAE,GAAG,IAAI;IAE1C;;OAEG;IACH,2BAA2B,EAAE,CAAC,GAAG,EAAE,GAAG,IAAI;IAE1C;;OAEG;IACH,kCAAkC,EAAE,eAAe;IAEnD;;OAEG;IACH,iCAAiC,EAAE,cAAc;IAEjD;;;OAGG;IACH,aAAa,EAAE,OAAO;IAEtB;;OAEG;IACH,WAAW,EAAE,CAAC;IAEd;;OAEG;IACH,cAAc,EAAE,EAAE,GAAG,IAAI;CACjB,CAAC"}
@@ -0,0 +1,4 @@
1
+ export type { SessionInfo, ErrorResponse, ErrorCode, ApiClientConfig, SessionServiceConfig, FirestoreSessionDocument, FirestoreLogoutDocument, FirestoreTimestamp, FirebaseAuth, FirebaseUser, } from './types.js';
2
+ export { SessionValidationStatus } from './types.js';
3
+ export { ERROR_CODES, DEFAULTS } from './constants.js';
4
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AACA,YAAY,EACV,WAAW,EACX,aAAa,EACb,SAAS,EACT,eAAe,EACf,oBAAoB,EACpB,wBAAwB,EACxB,uBAAuB,EACvB,kBAAkB,EAClB,YAAY,EACZ,YAAY,GACb,MAAM,YAAY,CAAC;AAGpB,OAAO,EAAE,uBAAuB,EAAE,MAAM,YAAY,CAAC;AAGrD,OAAO,EAAE,WAAW,EAAE,QAAQ,EAAE,MAAM,gBAAgB,CAAC"}
package/dist/index.js ADDED
@@ -0,0 +1,5 @@
1
+ // Enums
2
+ export { SessionValidationStatus } from './types.js';
3
+ // Constants
4
+ export { ERROR_CODES, DEFAULTS } from './constants.js';
5
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAcA,QAAQ;AACR,OAAO,EAAE,uBAAuB,EAAE,MAAM,YAAY,CAAC;AAErD,YAAY;AACZ,OAAO,EAAE,WAAW,EAAE,QAAQ,EAAE,MAAM,gBAAgB,CAAC"}
@@ -0,0 +1,99 @@
1
+ import { ERROR_CODES } from './constants.js';
2
+ /**
3
+ * Session information stored in Firestore and cache
4
+ */
5
+ export interface SessionInfo {
6
+ userId: string;
7
+ createdAt: Date;
8
+ lastActivityAt: Date;
9
+ expiresAt: Date;
10
+ }
11
+ /**
12
+ * Session validation status
13
+ * Used to avoid boolean blindness when checking session validity
14
+ * Provides explicit information about why a session is invalid
15
+ */
16
+ export declare enum SessionValidationStatus {
17
+ VALID = "VALID",
18
+ NOT_FOUND = "NOT_FOUND",
19
+ EXPIRED = "EXPIRED",
20
+ DATA_INTEGRITY_ERROR = "DATA_INTEGRITY_ERROR"
21
+ }
22
+ /**
23
+ * Error codes returned by the authentication system
24
+ * Type derived from ERROR_CODES in constants.ts (single source of truth)
25
+ * This extracts the union of all values from the ERROR_CODES object
26
+ */
27
+ export type ErrorCode = (typeof ERROR_CODES)[keyof typeof ERROR_CODES];
28
+ /**
29
+ * Error response format from server
30
+ */
31
+ export interface ErrorResponse {
32
+ error: {
33
+ code: ErrorCode;
34
+ message: string;
35
+ requiresLogout: boolean;
36
+ sessionExpired: boolean;
37
+ timestamp: string;
38
+ };
39
+ }
40
+ /**
41
+ * Minimal interface representing a Firebase User
42
+ * Used to avoid firebase dependency in shared package
43
+ */
44
+ export interface FirebaseUser {
45
+ getIdToken(forceRefresh?: boolean): Promise<string>;
46
+ }
47
+ /**
48
+ * Minimal interface representing a Firebase Auth instance
49
+ * Used to avoid firebase dependency in shared package
50
+ */
51
+ export interface FirebaseAuth {
52
+ currentUser: FirebaseUser | null;
53
+ }
54
+ /**
55
+ * Configuration for API client
56
+ */
57
+ export interface ApiClientConfig {
58
+ baseURL: string;
59
+ auth: FirebaseAuth;
60
+ onLogout?: () => void | Promise<void>;
61
+ maxRetries?: number;
62
+ timeout?: number;
63
+ logoutEndpoint?: string;
64
+ }
65
+ /**
66
+ * Session service configuration
67
+ */
68
+ export interface SessionServiceConfig {
69
+ inactivityTimeoutMs: number;
70
+ firestoreWriteThrottleMs: number;
71
+ firestoreCollectionName?: string;
72
+ firestoreLogoutsCollectionName?: string;
73
+ logoutTtlMs?: number;
74
+ }
75
+ /**
76
+ * Minimal interface representing a Firestore Timestamp
77
+ * Used to avoid firebase-admin dependency in shared package
78
+ */
79
+ export interface FirestoreTimestamp {
80
+ toDate(): Date;
81
+ }
82
+ /**
83
+ * Firestore document structure for session
84
+ */
85
+ export interface FirestoreSessionDocument {
86
+ userId: string;
87
+ createdAt: FirestoreTimestamp | Date;
88
+ lastActivityAt: FirestoreTimestamp | Date;
89
+ expiresAt: FirestoreTimestamp | Date;
90
+ }
91
+ /**
92
+ * Firestore document structure for logout records
93
+ */
94
+ export interface FirestoreLogoutDocument {
95
+ userId: string;
96
+ loggedOutAt: FirestoreTimestamp | Date;
97
+ expiresAt: FirestoreTimestamp | Date;
98
+ }
99
+ //# sourceMappingURL=types.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,MAAM,gBAAgB,CAAC;AAE7C;;GAEG;AACH,MAAM,WAAW,WAAW;IAC1B,MAAM,EAAE,MAAM,CAAC;IACf,SAAS,EAAE,IAAI,CAAC;IAChB,cAAc,EAAE,IAAI,CAAC;IACrB,SAAS,EAAE,IAAI,CAAC;CACjB;AAED;;;;GAIG;AACH,oBAAY,uBAAuB;IACjC,KAAK,UAAU;IACf,SAAS,cAAc;IACvB,OA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EAAE,kBAAkB,GAAG,IAAI,CAAC;IACrC,cAAc,EAAE,kBAAkB,GAAG,IAAI,CAAC;IAC1C,SAAS,EAAE,kBAAkB,GAAG,IAAI,CAAC;CACtC;AAED;;GAEG;AACH,MAAM,WAAW,uBAAuB;IACtC,MAAM,EAAE,MAAM,CAAC;IACf,WAAW,EAAE,kBAAkB,GAAG,IAAI,CAAC;IACvC,SAAS,EAAE,kBAAkB,GAAG,IAAI,CAAC;CACtC"}
package/dist/types.js ADDED
@@ -0,0 +1,13 @@
1
+ /**
2
+ * Session validation status
3
+ * Used to avoid boolean blindness when checking session validity
4
+ * Provides explicit information about why a session is invalid
5
+ */
6
+ export var SessionValidationStatus;
7
+ (function (SessionValidationStatus) {
8
+ SessionValidationStatus["VALID"] = "VALID";
9
+ SessionValidationStatus["NOT_FOUND"] = "NOT_FOUND";
10
+ SessionValidationStatus["EXPIRED"] = "EXPIRED";
11
+ SessionValidationStatus["DATA_INTEGRITY_ERROR"] = "DATA_INTEGRITY_ERROR";
12
+ })(SessionValidationStatus || (SessionValidationStatus = {}));
13
+ //# sourceMappingURL=types.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"types.js","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAYA;;;;GAIG;AACH,MAAM,CAAN,IAAY,uBAKX;AALD,WAAY,uBAAuB;IACjC,0CAAe,CAAA;IACf,kDAAuB,CAAA;IACvB,8CAAmB,CAAA;IACnB,wEAA6C,CAAA;AAC/C,CAAC,EALW,uBAAuB,KAAvB,uBAAuB,QAKlC"}
package/package.json ADDED
@@ -0,0 +1,27 @@
1
+ {
2
+ "name": "@rapidraptor/auth-shared",
3
+ "version": "0.2.0",
4
+ "description": "Shared types and constants for @rapidraptor/auth",
5
+ "main": "./dist/index.js",
6
+ "types": "./dist/index.d.ts",
7
+ "files": [
8
+ "dist"
9
+ ],
10
+ "exports": {
11
+ ".": {
12
+ "types": "./dist/index.d.ts",
13
+ "default": "./dist/index.js"
14
+ }
15
+ },
16
+ "publishConfig": {
17
+ "access": "public"
18
+ },
19
+ "scripts": {
20
+ "build": "tsc",
21
+ "clean": "rm -rf dist",
22
+ "test": "vitest"
23
+ },
24
+ "devDependencies": {
25
+ "typescript": "^5.4.5"
26
+ }
27
+ }