@payez/next-mvp 4.1.11 → 4.1.20

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.
Files changed (178) hide show
  1. package/dist/api-handlers/account/profile.d.ts +38 -0
  2. package/dist/api-handlers/account/profile.js +73 -45
  3. package/dist/api-handlers/account/recovery/send-code.d.ts +33 -0
  4. package/dist/api-handlers/account/recovery/send-code.js +52 -18
  5. package/dist/api-handlers/account/recovery/verify-code.d.ts +33 -0
  6. package/dist/api-handlers/account/recovery/verify-code.js +52 -18
  7. package/dist/api-handlers/account/verify-email.js +15 -1
  8. package/dist/api-handlers/account/verify-sms.js +15 -1
  9. package/dist/api-handlers/auth/passkey-signin.d.ts +29 -0
  10. package/dist/api-handlers/auth/passkey-signin.js +97 -0
  11. package/dist/api-handlers/mfa/backup-code-verify.d.ts +73 -0
  12. package/dist/api-handlers/mfa/backup-code-verify.js +153 -0
  13. package/dist/api-handlers/mfa/backup-codes.d.ts +7 -0
  14. package/dist/api-handlers/mfa/backup-codes.js +40 -0
  15. package/dist/api-handlers/mfa/methods.d.ts +3 -0
  16. package/dist/api-handlers/mfa/methods.js +41 -0
  17. package/dist/api-handlers/mfa/totp-confirm.d.ts +8 -0
  18. package/dist/api-handlers/mfa/totp-confirm.js +41 -0
  19. package/dist/api-handlers/mfa/totp-enroll.d.ts +8 -0
  20. package/dist/api-handlers/mfa/totp-enroll.js +41 -0
  21. package/dist/api-handlers/mfa/totp-verify.d.ts +47 -0
  22. package/dist/api-handlers/mfa/totp-verify.js +134 -0
  23. package/dist/api-handlers/passkeys/list.d.ts +7 -0
  24. package/dist/api-handlers/passkeys/list.js +29 -0
  25. package/dist/api-handlers/passkeys/manage.d.ts +3 -0
  26. package/dist/api-handlers/passkeys/manage.js +54 -0
  27. package/dist/api-handlers/passkeys/register-options.d.ts +8 -0
  28. package/dist/api-handlers/passkeys/register-options.js +41 -0
  29. package/dist/api-handlers/passkeys/register-verify.d.ts +7 -0
  30. package/dist/api-handlers/passkeys/register-verify.js +40 -0
  31. package/dist/api-handlers/session/viability.js +19 -0
  32. package/dist/auth/better-auth.d.ts +68 -5
  33. package/dist/auth/better-auth.js +256 -42
  34. package/dist/auth/utils/idp-client.d.ts +13 -22
  35. package/dist/auth/utils/idp-client.js +12 -82
  36. package/dist/client/better-auth-client.d.ts +14 -2
  37. package/dist/lib/session-store.js +28 -21
  38. package/dist/lib/startup-init.js +19 -19
  39. package/dist/lib/token-lifecycle.js +40 -4
  40. package/dist/models/SessionModel.d.ts +17 -0
  41. package/dist/pages/login/page.d.ts +10 -1
  42. package/dist/pages/login/page.js +69 -80
  43. package/dist/pages/verify-code/page.d.ts +10 -1
  44. package/dist/pages/verify-code/page.js +72 -4
  45. package/dist/routes/auth/passkey-signin.d.ts +13 -0
  46. package/dist/routes/auth/passkey-signin.js +18 -0
  47. package/dist/routes/auth/viability.d.ts +2 -0
  48. package/dist/routes/auth/viability.js +88 -0
  49. package/dist/routes/mfa/backup-code-verify.d.ts +1 -0
  50. package/dist/routes/mfa/backup-code-verify.js +5 -0
  51. package/dist/routes/mfa/backup-codes.d.ts +10 -0
  52. package/dist/routes/mfa/backup-codes.js +14 -0
  53. package/dist/routes/mfa/methods.d.ts +21 -0
  54. package/dist/routes/mfa/methods.js +10 -0
  55. package/dist/routes/mfa/totp-confirm.d.ts +10 -0
  56. package/dist/routes/mfa/totp-confirm.js +14 -0
  57. package/dist/routes/mfa/totp-enroll.d.ts +10 -0
  58. package/dist/routes/mfa/totp-enroll.js +14 -0
  59. package/dist/routes/mfa/totp-verify.d.ts +14 -0
  60. package/dist/routes/mfa/totp-verify.js +18 -0
  61. package/dist/routes/passkeys/list.d.ts +10 -0
  62. package/dist/routes/passkeys/list.js +14 -0
  63. package/dist/routes/passkeys/manage.d.ts +18 -0
  64. package/dist/routes/passkeys/manage.js +13 -0
  65. package/dist/routes/passkeys/register-options.d.ts +10 -0
  66. package/dist/routes/passkeys/register-options.js +14 -0
  67. package/dist/routes/passkeys/register-verify.d.ts +10 -0
  68. package/dist/routes/passkeys/register-verify.js +14 -0
  69. package/dist/server/auth.d.ts +2 -2
  70. package/dist/server/decode-session.js +37 -3
  71. package/package.json +958 -893
  72. package/scripts/check-internal-url-usage.sh +73 -73
  73. package/src/api/index.ts +17 -17
  74. package/src/api-handlers/account/masked-info.ts +45 -45
  75. package/src/api-handlers/account/profile.ts +99 -80
  76. package/src/api-handlers/account/recovery/initiate.ts +23 -23
  77. package/src/api-handlers/account/recovery/send-code.ts +73 -25
  78. package/src/api-handlers/account/recovery/verify-code.ts +73 -25
  79. package/src/api-handlers/account/reset-password.ts +23 -23
  80. package/src/api-handlers/account/send-code.ts +76 -76
  81. package/src/api-handlers/account/validate-password.ts +118 -118
  82. package/src/api-handlers/account/verify-email.ts +15 -1
  83. package/src/api-handlers/account/verify-sms.ts +15 -1
  84. package/src/api-handlers/admin/stats.ts +249 -249
  85. package/src/api-handlers/anon/preferences.ts +123 -123
  86. package/src/api-handlers/auth/jwks.ts +20 -20
  87. package/src/api-handlers/auth/login.ts +240 -240
  88. package/src/api-handlers/auth/passkey-signin.ts +98 -0
  89. package/src/api-handlers/auth/validate.ts +43 -43
  90. package/src/api-handlers/mfa/backup-code-verify.ts +175 -0
  91. package/src/api-handlers/mfa/backup-codes.ts +41 -0
  92. package/src/api-handlers/mfa/methods.ts +46 -0
  93. package/src/api-handlers/mfa/totp-confirm.ts +42 -0
  94. package/src/api-handlers/mfa/totp-enroll.ts +42 -0
  95. package/src/api-handlers/mfa/totp-verify.ts +156 -0
  96. package/src/api-handlers/passkeys/list.ts +31 -0
  97. package/src/api-handlers/passkeys/manage.ts +54 -0
  98. package/src/api-handlers/passkeys/register-options.ts +42 -0
  99. package/src/api-handlers/passkeys/register-verify.ts +41 -0
  100. package/src/api-handlers/session/viability.ts +161 -142
  101. package/src/auth/better-auth.ts +247 -6
  102. package/src/auth/unauthenticated-routes.ts +2 -2
  103. package/src/auth/utils/idp-client.ts +13 -95
  104. package/src/client/better-auth-client.ts +70 -70
  105. package/src/client/fetchWithSession.ts +21 -21
  106. package/src/client/index.ts +13 -13
  107. package/src/client/useAnonSession.ts +131 -131
  108. package/src/components/admin/VibeAdminContext.tsx +87 -87
  109. package/src/config/logging-config.ts +82 -82
  110. package/src/config/unauthenticated-routes.ts +19 -19
  111. package/src/edge/internal-api-url.ts +65 -65
  112. package/src/edge/middleware.ts +42 -42
  113. package/src/hooks/useProfile.ts +75 -75
  114. package/src/lib/anon-session.ts +213 -213
  115. package/src/lib/auth-secret.ts +137 -137
  116. package/src/lib/demo-mode.ts +17 -17
  117. package/src/lib/idp-client-config.ts +559 -559
  118. package/src/lib/idp-fetch.ts +126 -126
  119. package/src/lib/internal-api.ts +171 -171
  120. package/src/lib/jwt-decode-client.ts +45 -45
  121. package/src/lib/rate-limit-service.ts +9 -9
  122. package/src/lib/redis.ts +26 -26
  123. package/src/lib/refresh-token-validator.ts +64 -64
  124. package/src/lib/secret-validation.ts +8 -8
  125. package/src/lib/session-store.ts +702 -695
  126. package/src/lib/session.ts +34 -34
  127. package/src/lib/startup-init.ts +251 -251
  128. package/src/lib/token-expiry.ts +40 -40
  129. package/src/lib/token-lifecycle.ts +533 -497
  130. package/src/lib/types/api-responses.ts +336 -336
  131. package/src/middleware/auth-decision.ts +43 -43
  132. package/src/models/DecodedAccessToken.ts +16 -16
  133. package/src/models/SessionModel.ts +282 -264
  134. package/src/pages/admin-roles/index.ts +9 -9
  135. package/src/pages/login/page.tsx +123 -228
  136. package/src/pages/security/EnhancedSecurityPage.tsx +9 -9
  137. package/src/pages/verify-code/page.tsx +71 -5
  138. package/src/routes/account/index.ts +31 -31
  139. package/src/routes/account/masked-info.ts +36 -36
  140. package/src/routes/account/send-code.ts +39 -39
  141. package/src/routes/account/verify-email.ts +40 -40
  142. package/src/routes/account/verify-sms.ts +40 -40
  143. package/src/routes/auth/index.ts +22 -22
  144. package/src/routes/auth/passkey-signin.ts +13 -0
  145. package/src/routes/auth/refresh.ts +48 -48
  146. package/src/routes/auth/session.ts +166 -166
  147. package/src/routes/auth/viability.ts +89 -0
  148. package/src/routes/index.ts +17 -17
  149. package/src/routes/mfa/backup-code-verify.ts +1 -0
  150. package/src/routes/mfa/backup-codes.ts +10 -0
  151. package/src/routes/mfa/methods.ts +22 -0
  152. package/src/routes/mfa/totp-confirm.ts +10 -0
  153. package/src/routes/mfa/totp-enroll.ts +10 -0
  154. package/src/routes/mfa/totp-verify.ts +14 -0
  155. package/src/routes/passkeys/list.ts +10 -0
  156. package/src/routes/passkeys/manage.ts +23 -0
  157. package/src/routes/passkeys/register-options.ts +10 -0
  158. package/src/routes/passkeys/register-verify.ts +10 -0
  159. package/src/routes/session/index.ts +7 -7
  160. package/src/routes/session/refresh-viability.ts +17 -17
  161. package/src/server/auth.ts +373 -373
  162. package/src/server/decode-session.ts +235 -202
  163. package/src/services/signalrActivityService.ts +258 -258
  164. package/src/theme/ThemeProvider.tsx +39 -39
  165. package/src/theme/default.ts +33 -33
  166. package/src/theme/index.ts +31 -31
  167. package/src/theme/types.ts +69 -69
  168. package/src/theme/useTheme.ts +57 -57
  169. package/src/theme/utils.ts +40 -40
  170. package/src/types/api.ts +12 -12
  171. package/src/types/auth.d.ts +23 -23
  172. package/src/types/auth.ts +22 -22
  173. package/src/types/logging.ts +11 -11
  174. package/src/types/recovery.ts +54 -54
  175. package/src/utils/api.ts +353 -353
  176. package/src/utils/circuitBreaker.ts +40 -40
  177. package/src/utils/error-message.ts +108 -108
  178. package/src/utils/layout/reservedSpace.ts +124 -124
@@ -1,264 +1,282 @@
1
- /**
2
- * Session Model - Redis Session Data Structure
3
- *
4
- * This is the single source of truth for session data stored in Redis.
5
- * The session contains all authentication state - the JWT cookie only
6
- * stores the session ID (redisSessionId).
7
- *
8
- * FIELD NAMING CONVENTIONS:
9
- * - idp* prefix: Tokens from PayEz IDP (identity provider)
10
- * - oauth* prefix: Tokens from external OAuth providers (Google, etc.)
11
- * - mfa* prefix: Multi-factor authentication related fields
12
- *
13
- * @version 2.0.0 - Normalized field names
14
- * @since auth-refactor-2026-01
15
- */
16
-
17
- // ============================================================================
18
- // NORMALIZED SESSION DATA (v2)
19
- // ============================================================================
20
-
21
- /**
22
- * Session data stored in Redis.
23
- *
24
- * This interface uses normalized field names for clarity.
25
- * All tokens and user data live here - the browser only gets the session ID.
26
- */
27
- export interface SessionData {
28
- // -------------------------------------------------------------------------
29
- // Core Identity
30
- // -------------------------------------------------------------------------
31
-
32
- /** User ID from IDP (sub claim) */
33
- userId: string;
34
-
35
- /** User's email address */
36
- email: string;
37
-
38
- /** Display name (from OAuth profile or IDP) */
39
- name?: string;
40
-
41
- /** Avatar image URL (from OAuth profile) */
42
- image?: string;
43
-
44
- /** User's roles/permissions */
45
- roles: string[];
46
-
47
- // -------------------------------------------------------------------------
48
- // IDP Tokens (from PayEz Identity Provider)
49
- // -------------------------------------------------------------------------
50
-
51
- /** IDP access token (JWT) - used for API calls to PayEz services */
52
- idpAccessToken?: string;
53
-
54
- /** IDP refresh token - used to get new access tokens */
55
- idpRefreshToken?: string;
56
-
57
- /** When the IDP access token expires (Unix timestamp ms) */
58
- idpAccessTokenExpires: number;
59
-
60
- /** When the IDP refresh token expires (Unix timestamp ms) */
61
- idpRefreshTokenExpires?: number;
62
-
63
- /** Decoded IDP access token claims (for quick access without re-decoding) */
64
- decodedAccessToken?: any;
65
-
66
- /**
67
- * Bearer Key ID (kid from JWT header).
68
- * Identifies which IDP signing key was used for this token.
69
- * CRITICAL: This is from the JWT HEADER, not client_id from payload.
70
- */
71
- bearerKeyId?: string;
72
-
73
- // -------------------------------------------------------------------------
74
- // MFA (Multi-Factor Authentication) State
75
- // -------------------------------------------------------------------------
76
-
77
- /** Whether MFA has been verified for this session */
78
- mfaVerified: boolean;
79
-
80
- /** The MFA method used (email, sms, totp) */
81
- mfaMethod?: 'email' | 'sms' | 'totp';
82
-
83
- /** When MFA was completed (Unix timestamp ms) */
84
- mfaCompletedAt?: number;
85
-
86
- /** When MFA verification expires (Unix timestamp ms) */
87
- mfaExpiresAt?: number;
88
-
89
- /** How long MFA is valid in hours */
90
- mfaValidityHours?: number;
91
-
92
- /** Authentication methods from token (amr claim) */
93
- authenticationMethods?: string[];
94
-
95
- /** Authentication level from token (acr claim) */
96
- authenticationLevel?: string;
97
-
98
- // -------------------------------------------------------------------------
99
- // OAuth Provider Tokens (Google, Microsoft, etc.)
100
- // -------------------------------------------------------------------------
101
-
102
- /** Which OAuth provider was used (google, apple, microsoft, etc.) */
103
- oauthProvider?: string;
104
-
105
- /** Access token from OAuth provider */
106
- oauthProviderToken?: string;
107
-
108
- /** Refresh token from OAuth provider */
109
- oauthProviderRefreshToken?: string;
110
-
111
- // -------------------------------------------------------------------------
112
- // Multi-Tenant IDP Assignment
113
- // -------------------------------------------------------------------------
114
-
115
- /** IDP client ID this user belongs to */
116
- idpClientId?: string;
117
-
118
- /** Merchant ID (typically same as client ID) */
119
- merchantId?: string;
120
-
121
- // -------------------------------------------------------------------------
122
- // Legacy Field Support (for backward compatibility)
123
- // -------------------------------------------------------------------------
124
-
125
- /**
126
- * Allow any additional fields for backward compatibility.
127
- * During migration, old sessions may have legacy field names.
128
- */
129
- [key: string]: any;
130
- }
131
-
132
-
133
- // ============================================================================
134
- // SESSION MODEL CLASS
135
- // ============================================================================
136
-
137
- /**
138
- * Session model class for working with session data.
139
- *
140
- * Provides typed access to session fields with normalized names.
141
- */
142
- export class SessionModel {
143
- // Core Identity
144
- userId: string;
145
- email: string;
146
- name?: string;
147
- image?: string;
148
- roles: string[];
149
-
150
- // IDP Tokens
151
- idpAccessToken?: string;
152
- idpRefreshToken?: string;
153
- idpAccessTokenExpires: number;
154
- idpRefreshTokenExpires?: number;
155
- decodedAccessToken?: any;
156
- bearerKeyId?: string;
157
-
158
- // MFA State
159
- mfaVerified: boolean;
160
- mfaMethod?: 'email' | 'sms' | 'totp';
161
- mfaCompletedAt?: number;
162
- mfaExpiresAt?: number;
163
- mfaValidityHours?: number;
164
- authenticationMethods?: string[];
165
- authenticationLevel?: string;
166
-
167
- // OAuth Provider
168
- oauthProvider?: string;
169
- oauthProviderToken?: string;
170
- oauthProviderRefreshToken?: string;
171
-
172
- // Multi-Tenant
173
- idpClientId?: string;
174
- merchantId?: string;
175
-
176
- constructor(data: SessionData) {
177
- // Core Identity
178
- this.userId = data.userId;
179
- this.email = data.email;
180
- this.name = data.name;
181
- this.image = data.image;
182
- this.roles = data.roles || [];
183
-
184
- // IDP Tokens
185
- this.idpAccessToken = data.idpAccessToken;
186
- this.idpRefreshToken = data.idpRefreshToken;
187
- this.idpAccessTokenExpires = data.idpAccessTokenExpires;
188
- this.idpRefreshTokenExpires = data.idpRefreshTokenExpires;
189
- this.decodedAccessToken = data.decodedAccessToken;
190
- this.bearerKeyId = data.bearerKeyId;
191
-
192
- // MFA State
193
- this.mfaVerified = data.mfaVerified ?? false;
194
- this.mfaMethod = data.mfaMethod;
195
- this.mfaCompletedAt = data.mfaCompletedAt;
196
- this.mfaExpiresAt = data.mfaExpiresAt;
197
- this.mfaValidityHours = data.mfaValidityHours;
198
- this.authenticationMethods = data.authenticationMethods;
199
- this.authenticationLevel = data.authenticationLevel;
200
-
201
- // OAuth Provider
202
- this.oauthProvider = data.oauthProvider;
203
- this.oauthProviderToken = data.oauthProviderToken;
204
- this.oauthProviderRefreshToken = data.oauthProviderRefreshToken;
205
-
206
- // Multi-Tenant
207
- this.idpClientId = data.idpClientId;
208
- this.merchantId = data.merchantId;
209
- }
210
-
211
- /**
212
- * Check if the IDP access token has expired.
213
- */
214
- isAccessTokenExpired(): boolean {
215
- return Date.now() >= this.idpAccessTokenExpires;
216
- }
217
-
218
- /**
219
- * Check if the IDP refresh token has expired.
220
- */
221
- isRefreshTokenExpired(): boolean {
222
- if (!this.idpRefreshTokenExpires) return false;
223
- return Date.now() >= this.idpRefreshTokenExpires;
224
- }
225
-
226
- /**
227
- * Check if MFA has expired.
228
- */
229
- isMfaExpired(): boolean {
230
- if (!this.mfaExpiresAt) return false;
231
- return Date.now() > this.mfaExpiresAt;
232
- }
233
-
234
- /**
235
- * Convert to plain object for storage.
236
- */
237
- toJSON(): SessionData {
238
- return {
239
- userId: this.userId,
240
- email: this.email,
241
- name: this.name,
242
- image: this.image,
243
- roles: this.roles,
244
- idpAccessToken: this.idpAccessToken,
245
- idpRefreshToken: this.idpRefreshToken,
246
- idpAccessTokenExpires: this.idpAccessTokenExpires,
247
- idpRefreshTokenExpires: this.idpRefreshTokenExpires,
248
- decodedAccessToken: this.decodedAccessToken,
249
- bearerKeyId: this.bearerKeyId,
250
- mfaVerified: this.mfaVerified,
251
- mfaMethod: this.mfaMethod,
252
- mfaCompletedAt: this.mfaCompletedAt,
253
- mfaExpiresAt: this.mfaExpiresAt,
254
- mfaValidityHours: this.mfaValidityHours,
255
- authenticationMethods: this.authenticationMethods,
256
- authenticationLevel: this.authenticationLevel,
257
- oauthProvider: this.oauthProvider,
258
- oauthProviderToken: this.oauthProviderToken,
259
- oauthProviderRefreshToken: this.oauthProviderRefreshToken,
260
- idpClientId: this.idpClientId,
261
- merchantId: this.merchantId,
262
- };
263
- }
264
- }
1
+ /**
2
+ * Session Model - Redis Session Data Structure
3
+ *
4
+ * This is the single source of truth for session data stored in Redis.
5
+ * The session contains all authentication state - the JWT cookie only
6
+ * stores the session ID (redisSessionId).
7
+ *
8
+ * FIELD NAMING CONVENTIONS:
9
+ * - idp* prefix: Tokens from PayEz IDP (identity provider)
10
+ * - oauth* prefix: Tokens from external OAuth providers (Google, etc.)
11
+ * - mfa* prefix: Multi-factor authentication related fields
12
+ *
13
+ * @version 2.0.0 - Normalized field names
14
+ * @since auth-refactor-2026-01
15
+ */
16
+
17
+ // ============================================================================
18
+ // NORMALIZED SESSION DATA (v2)
19
+ // ============================================================================
20
+
21
+ /**
22
+ * Session data stored in Redis.
23
+ *
24
+ * This interface uses normalized field names for clarity.
25
+ * All tokens and user data live here - the browser only gets the session ID.
26
+ */
27
+ export interface SessionData {
28
+ // -------------------------------------------------------------------------
29
+ // Core Identity
30
+ // -------------------------------------------------------------------------
31
+
32
+ /** User ID from IDP (sub claim) */
33
+ userId: string;
34
+
35
+ /** User's email address */
36
+ email: string;
37
+
38
+ /** Display name (from OAuth profile or IDP) */
39
+ name?: string;
40
+
41
+ /** Avatar image URL (from OAuth profile) */
42
+ image?: string;
43
+
44
+ /** User's roles/permissions */
45
+ roles: string[];
46
+
47
+ // -------------------------------------------------------------------------
48
+ // IDP Tokens (from PayEz Identity Provider)
49
+ // -------------------------------------------------------------------------
50
+
51
+ /** IDP access token (JWT) - used for API calls to PayEz services */
52
+ idpAccessToken?: string;
53
+
54
+ /** IDP refresh token - used to get new access tokens */
55
+ idpRefreshToken?: string;
56
+
57
+ /** When the IDP access token expires (Unix timestamp ms) */
58
+ idpAccessTokenExpires: number;
59
+
60
+ /** When the IDP refresh token expires (Unix timestamp ms) */
61
+ idpRefreshTokenExpires?: number;
62
+
63
+ /** Decoded IDP access token claims (for quick access without re-decoding) */
64
+ decodedAccessToken?: any;
65
+
66
+ /**
67
+ * Bearer Key ID (kid from JWT header).
68
+ * Identifies which IDP signing key was used for this token.
69
+ * CRITICAL: This is from the JWT HEADER, not client_id from payload.
70
+ */
71
+ bearerKeyId?: string;
72
+
73
+ // -------------------------------------------------------------------------
74
+ // MFA (Multi-Factor Authentication) State
75
+ // -------------------------------------------------------------------------
76
+
77
+ /** Whether MFA has been verified for this session */
78
+ mfaVerified: boolean;
79
+
80
+ /**
81
+ * The IDP's own routing decision for a 2FA-pending login (cards 141688 /
82
+ * 141741, IDP WO 113023). Wire name is snake — `next_step`.
83
+ *
84
+ * 'enroll_mfa' — no USABLE method (confirmed and not revoked). The user
85
+ * cannot complete a challenge; they must enrol first.
86
+ * 'mfa_verify' — a usable method exists; challenge them.
87
+ * null — fully authenticated, nothing outstanding.
88
+ *
89
+ * RELAYED, NEVER DERIVED. The IDP owns this fact and is already usable-aware;
90
+ * recomputing it here from a method count would make a second owner and would
91
+ * get the revoked-method case wrong (count>0 but usable=0).
92
+ *
93
+ * NOT A COMPLETION SIGNAL. 'mfa_verify' means "can be challenged", not
94
+ * "is through". `mfaVerified` remains the only field that says they verified.
95
+ */
96
+ nextStep?: 'enroll_mfa' | 'mfa_verify' | null;
97
+
98
+ /** The MFA method used (email, sms, totp) */
99
+ mfaMethod?: 'email' | 'sms' | 'totp';
100
+
101
+ /** When MFA was completed (Unix timestamp ms) */
102
+ mfaCompletedAt?: number;
103
+
104
+ /** When MFA verification expires (Unix timestamp ms) */
105
+ mfaExpiresAt?: number;
106
+
107
+ /** How long MFA is valid in hours */
108
+ mfaValidityHours?: number;
109
+
110
+ /** Authentication methods from token (amr claim) */
111
+ authenticationMethods?: string[];
112
+
113
+ /** Authentication level from token (acr claim) */
114
+ authenticationLevel?: string;
115
+
116
+ // -------------------------------------------------------------------------
117
+ // OAuth Provider Tokens (Google, Microsoft, etc.)
118
+ // -------------------------------------------------------------------------
119
+
120
+ /** Which OAuth provider was used (google, apple, microsoft, etc.) */
121
+ oauthProvider?: string;
122
+
123
+ /** Access token from OAuth provider */
124
+ oauthProviderToken?: string;
125
+
126
+ /** Refresh token from OAuth provider */
127
+ oauthProviderRefreshToken?: string;
128
+
129
+ // -------------------------------------------------------------------------
130
+ // Multi-Tenant IDP Assignment
131
+ // -------------------------------------------------------------------------
132
+
133
+ /** IDP client ID this user belongs to */
134
+ idpClientId?: string;
135
+
136
+ /** Merchant ID (typically same as client ID) */
137
+ merchantId?: string;
138
+
139
+ // -------------------------------------------------------------------------
140
+ // Legacy Field Support (for backward compatibility)
141
+ // -------------------------------------------------------------------------
142
+
143
+ /**
144
+ * Allow any additional fields for backward compatibility.
145
+ * During migration, old sessions may have legacy field names.
146
+ */
147
+ [key: string]: any;
148
+ }
149
+
150
+
151
+ // ============================================================================
152
+ // SESSION MODEL CLASS
153
+ // ============================================================================
154
+
155
+ /**
156
+ * Session model class for working with session data.
157
+ *
158
+ * Provides typed access to session fields with normalized names.
159
+ */
160
+ export class SessionModel {
161
+ // Core Identity
162
+ userId: string;
163
+ email: string;
164
+ name?: string;
165
+ image?: string;
166
+ roles: string[];
167
+
168
+ // IDP Tokens
169
+ idpAccessToken?: string;
170
+ idpRefreshToken?: string;
171
+ idpAccessTokenExpires: number;
172
+ idpRefreshTokenExpires?: number;
173
+ decodedAccessToken?: any;
174
+ bearerKeyId?: string;
175
+
176
+ // MFA State
177
+ mfaVerified: boolean;
178
+ mfaMethod?: 'email' | 'sms' | 'totp';
179
+ mfaCompletedAt?: number;
180
+ mfaExpiresAt?: number;
181
+ mfaValidityHours?: number;
182
+ authenticationMethods?: string[];
183
+ authenticationLevel?: string;
184
+
185
+ // OAuth Provider
186
+ oauthProvider?: string;
187
+ oauthProviderToken?: string;
188
+ oauthProviderRefreshToken?: string;
189
+
190
+ // Multi-Tenant
191
+ idpClientId?: string;
192
+ merchantId?: string;
193
+
194
+ constructor(data: SessionData) {
195
+ // Core Identity
196
+ this.userId = data.userId;
197
+ this.email = data.email;
198
+ this.name = data.name;
199
+ this.image = data.image;
200
+ this.roles = data.roles || [];
201
+
202
+ // IDP Tokens
203
+ this.idpAccessToken = data.idpAccessToken;
204
+ this.idpRefreshToken = data.idpRefreshToken;
205
+ this.idpAccessTokenExpires = data.idpAccessTokenExpires;
206
+ this.idpRefreshTokenExpires = data.idpRefreshTokenExpires;
207
+ this.decodedAccessToken = data.decodedAccessToken;
208
+ this.bearerKeyId = data.bearerKeyId;
209
+
210
+ // MFA State
211
+ this.mfaVerified = data.mfaVerified ?? false;
212
+ this.mfaMethod = data.mfaMethod;
213
+ this.mfaCompletedAt = data.mfaCompletedAt;
214
+ this.mfaExpiresAt = data.mfaExpiresAt;
215
+ this.mfaValidityHours = data.mfaValidityHours;
216
+ this.authenticationMethods = data.authenticationMethods;
217
+ this.authenticationLevel = data.authenticationLevel;
218
+
219
+ // OAuth Provider
220
+ this.oauthProvider = data.oauthProvider;
221
+ this.oauthProviderToken = data.oauthProviderToken;
222
+ this.oauthProviderRefreshToken = data.oauthProviderRefreshToken;
223
+
224
+ // Multi-Tenant
225
+ this.idpClientId = data.idpClientId;
226
+ this.merchantId = data.merchantId;
227
+ }
228
+
229
+ /**
230
+ * Check if the IDP access token has expired.
231
+ */
232
+ isAccessTokenExpired(): boolean {
233
+ return Date.now() >= this.idpAccessTokenExpires;
234
+ }
235
+
236
+ /**
237
+ * Check if the IDP refresh token has expired.
238
+ */
239
+ isRefreshTokenExpired(): boolean {
240
+ if (!this.idpRefreshTokenExpires) return false;
241
+ return Date.now() >= this.idpRefreshTokenExpires;
242
+ }
243
+
244
+ /**
245
+ * Check if MFA has expired.
246
+ */
247
+ isMfaExpired(): boolean {
248
+ if (!this.mfaExpiresAt) return false;
249
+ return Date.now() > this.mfaExpiresAt;
250
+ }
251
+
252
+ /**
253
+ * Convert to plain object for storage.
254
+ */
255
+ toJSON(): SessionData {
256
+ return {
257
+ userId: this.userId,
258
+ email: this.email,
259
+ name: this.name,
260
+ image: this.image,
261
+ roles: this.roles,
262
+ idpAccessToken: this.idpAccessToken,
263
+ idpRefreshToken: this.idpRefreshToken,
264
+ idpAccessTokenExpires: this.idpAccessTokenExpires,
265
+ idpRefreshTokenExpires: this.idpRefreshTokenExpires,
266
+ decodedAccessToken: this.decodedAccessToken,
267
+ bearerKeyId: this.bearerKeyId,
268
+ mfaVerified: this.mfaVerified,
269
+ mfaMethod: this.mfaMethod,
270
+ mfaCompletedAt: this.mfaCompletedAt,
271
+ mfaExpiresAt: this.mfaExpiresAt,
272
+ mfaValidityHours: this.mfaValidityHours,
273
+ authenticationMethods: this.authenticationMethods,
274
+ authenticationLevel: this.authenticationLevel,
275
+ oauthProvider: this.oauthProvider,
276
+ oauthProviderToken: this.oauthProviderToken,
277
+ oauthProviderRefreshToken: this.oauthProviderRefreshToken,
278
+ idpClientId: this.idpClientId,
279
+ merchantId: this.merchantId,
280
+ };
281
+ }
282
+ }
@@ -1,9 +1,9 @@
1
- /**
2
- * Admin Roles Page exports
3
- *
4
- * - RolesAdminPage: Read-only admin interface for viewing roles and permissions (/admin/roles)
5
- *
6
- * MVP scope: Role creation/editing deferred to post-MVP.
7
- */
8
-
9
- export { default as RolesAdminPage } from './RolesAdminPage';
1
+ /**
2
+ * Admin Roles Page exports
3
+ *
4
+ * - RolesAdminPage: Read-only admin interface for viewing roles and permissions (/admin/roles)
5
+ *
6
+ * MVP scope: Role creation/editing deferred to post-MVP.
7
+ */
8
+
9
+ export { default as RolesAdminPage } from './RolesAdminPage';