@nauth-toolkit/core 0.1.86 → 0.1.88

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 (166) hide show
  1. package/dist/dto/admin-get-user-auth-history.dto.d.ts +62 -0
  2. package/dist/dto/admin-get-user-auth-history.dto.d.ts.map +1 -0
  3. package/dist/dto/admin-get-user-auth-history.dto.js +87 -0
  4. package/dist/dto/admin-get-user-auth-history.dto.js.map +1 -0
  5. package/dist/dto/admin-logout-all.dto.d.ts +48 -0
  6. package/dist/dto/admin-logout-all.dto.d.ts.map +1 -0
  7. package/dist/dto/{change-password-request.dto.js → admin-logout-all.dto.js} +36 -21
  8. package/dist/dto/admin-logout-all.dto.js.map +1 -0
  9. package/dist/dto/admin-remove-devices.dto.d.ts +25 -0
  10. package/dist/dto/admin-remove-devices.dto.d.ts.map +1 -0
  11. package/dist/dto/admin-remove-devices.dto.js +50 -0
  12. package/dist/dto/admin-remove-devices.dto.js.map +1 -0
  13. package/dist/dto/admin-reset-password.dto.d.ts +24 -49
  14. package/dist/dto/admin-reset-password.dto.d.ts.map +1 -1
  15. package/dist/dto/admin-reset-password.dto.js +30 -82
  16. package/dist/dto/admin-reset-password.dto.js.map +1 -1
  17. package/dist/dto/admin-revoke-session.dto.d.ts +22 -0
  18. package/dist/dto/admin-revoke-session.dto.d.ts.map +1 -0
  19. package/dist/dto/admin-revoke-session.dto.js +48 -0
  20. package/dist/dto/admin-revoke-session.dto.js.map +1 -0
  21. package/dist/dto/admin-set-password.dto.d.ts +8 -10
  22. package/dist/dto/admin-set-password.dto.d.ts.map +1 -1
  23. package/dist/dto/admin-set-password.dto.js +11 -21
  24. package/dist/dto/admin-set-password.dto.js.map +1 -1
  25. package/dist/dto/admin-set-preferred-method.dto.d.ts +25 -0
  26. package/dist/dto/admin-set-preferred-method.dto.d.ts.map +1 -0
  27. package/dist/dto/admin-set-preferred-method.dto.js +50 -0
  28. package/dist/dto/admin-set-preferred-method.dto.js.map +1 -0
  29. package/dist/dto/admin-update-user-attributes.dto.d.ts +41 -0
  30. package/dist/dto/admin-update-user-attributes.dto.d.ts.map +1 -0
  31. package/dist/dto/{update-user-attributes-request.dto.js → admin-update-user-attributes.dto.js} +12 -17
  32. package/dist/dto/admin-update-user-attributes.dto.js.map +1 -0
  33. package/dist/dto/auth-challenge.dto.d.ts +2 -2
  34. package/dist/dto/auth-challenge.dto.d.ts.map +1 -1
  35. package/dist/dto/auth-challenge.dto.js +3 -3
  36. package/dist/dto/auth-challenge.dto.js.map +1 -1
  37. package/dist/dto/auth-response.dto.d.ts +1 -1
  38. package/dist/dto/auth-response.dto.d.ts.map +1 -1
  39. package/dist/dto/auth-response.dto.js +1 -1
  40. package/dist/dto/auth-response.dto.js.map +1 -1
  41. package/dist/dto/get-mfa-status.dto.d.ts +8 -4
  42. package/dist/dto/get-mfa-status.dto.d.ts.map +1 -1
  43. package/dist/dto/get-mfa-status.dto.js +8 -4
  44. package/dist/dto/get-mfa-status.dto.js.map +1 -1
  45. package/dist/dto/get-risk-assessment-history.dto.d.ts +3 -3
  46. package/dist/dto/get-risk-assessment-history.dto.d.ts.map +1 -1
  47. package/dist/dto/get-risk-assessment-history.dto.js +5 -5
  48. package/dist/dto/get-risk-assessment-history.dto.js.map +1 -1
  49. package/dist/dto/get-suspicious-activity.dto.d.ts +3 -3
  50. package/dist/dto/get-suspicious-activity.dto.d.ts.map +1 -1
  51. package/dist/dto/get-suspicious-activity.dto.js +5 -5
  52. package/dist/dto/get-suspicious-activity.dto.js.map +1 -1
  53. package/dist/dto/get-user-auth-history.dto.d.ts +4 -39
  54. package/dist/dto/get-user-auth-history.dto.d.ts.map +1 -1
  55. package/dist/dto/get-user-auth-history.dto.js +53 -51
  56. package/dist/dto/get-user-auth-history.dto.js.map +1 -1
  57. package/dist/dto/get-user-devices.dto.d.ts +5 -18
  58. package/dist/dto/get-user-devices.dto.d.ts.map +1 -1
  59. package/dist/dto/get-user-devices.dto.js +5 -39
  60. package/dist/dto/get-user-devices.dto.js.map +1 -1
  61. package/dist/dto/get-user-sessions-response.dto.d.ts +1 -1
  62. package/dist/dto/get-user-sessions-response.dto.js +1 -1
  63. package/dist/dto/get-user-sessions.dto.d.ts +1 -1
  64. package/dist/dto/get-user-sessions.dto.js +1 -1
  65. package/dist/dto/index.d.ts +8 -2
  66. package/dist/dto/index.d.ts.map +1 -1
  67. package/dist/dto/index.js +8 -2
  68. package/dist/dto/index.js.map +1 -1
  69. package/dist/dto/logout-all-response.dto.d.ts +1 -1
  70. package/dist/dto/logout-all-response.dto.js +1 -1
  71. package/dist/dto/logout-all.dto.d.ts +1 -18
  72. package/dist/dto/logout-all.dto.d.ts.map +1 -1
  73. package/dist/dto/logout-all.dto.js +1 -30
  74. package/dist/dto/logout-all.dto.js.map +1 -1
  75. package/dist/dto/logout-session.dto.d.ts +0 -5
  76. package/dist/dto/logout-session.dto.d.ts.map +1 -1
  77. package/dist/dto/logout-session.dto.js +0 -12
  78. package/dist/dto/logout-session.dto.js.map +1 -1
  79. package/dist/dto/logout.dto.d.ts +1 -18
  80. package/dist/dto/logout.dto.d.ts.map +1 -1
  81. package/dist/dto/logout.dto.js +1 -30
  82. package/dist/dto/logout.dto.js.map +1 -1
  83. package/dist/dto/remove-devices.dto.d.ts +4 -16
  84. package/dist/dto/remove-devices.dto.d.ts.map +1 -1
  85. package/dist/dto/remove-devices.dto.js +4 -26
  86. package/dist/dto/remove-devices.dto.js.map +1 -1
  87. package/dist/dto/set-mfa-exemption.dto.d.ts +4 -2
  88. package/dist/dto/set-mfa-exemption.dto.d.ts.map +1 -1
  89. package/dist/dto/set-mfa-exemption.dto.js +5 -3
  90. package/dist/dto/set-mfa-exemption.dto.js.map +1 -1
  91. package/dist/dto/set-must-change-password.dto.d.ts +3 -3
  92. package/dist/dto/set-must-change-password.dto.d.ts.map +1 -1
  93. package/dist/dto/set-must-change-password.dto.js +5 -5
  94. package/dist/dto/set-must-change-password.dto.js.map +1 -1
  95. package/dist/dto/set-preferred-method.dto.d.ts +4 -16
  96. package/dist/dto/set-preferred-method.dto.d.ts.map +1 -1
  97. package/dist/dto/set-preferred-method.dto.js +4 -26
  98. package/dist/dto/set-preferred-method.dto.js.map +1 -1
  99. package/dist/dto/setup-mfa.dto.d.ts +3 -18
  100. package/dist/dto/setup-mfa.dto.d.ts.map +1 -1
  101. package/dist/dto/setup-mfa.dto.js +3 -30
  102. package/dist/dto/setup-mfa.dto.js.map +1 -1
  103. package/dist/dto/social-auth.dto.d.ts +4 -34
  104. package/dist/dto/social-auth.dto.d.ts.map +1 -1
  105. package/dist/dto/social-auth.dto.js +10 -68
  106. package/dist/dto/social-auth.dto.js.map +1 -1
  107. package/dist/dto/update-user-attributes.dto.d.ts +26 -0
  108. package/dist/dto/update-user-attributes.dto.d.ts.map +1 -0
  109. package/dist/dto/update-user-attributes.dto.js +30 -0
  110. package/dist/dto/update-user-attributes.dto.js.map +1 -0
  111. package/dist/index.d.ts +5 -0
  112. package/dist/index.d.ts.map +1 -1
  113. package/dist/index.js +5 -0
  114. package/dist/index.js.map +1 -1
  115. package/dist/interfaces/hooks.interface.d.ts +2 -1
  116. package/dist/interfaces/hooks.interface.d.ts.map +1 -1
  117. package/dist/interfaces/provider.interface.d.ts +1 -1
  118. package/dist/interfaces/provider.interface.d.ts.map +1 -1
  119. package/dist/services/adaptive-mfa-decision.service.js +2 -2
  120. package/dist/services/adaptive-mfa-decision.service.js.map +1 -1
  121. package/dist/services/admin-auth.service.d.ts +307 -0
  122. package/dist/services/admin-auth.service.d.ts.map +1 -0
  123. package/dist/services/admin-auth.service.js +885 -0
  124. package/dist/services/admin-auth.service.js.map +1 -0
  125. package/dist/services/auth-audit.service.d.ts +16 -16
  126. package/dist/services/auth-audit.service.d.ts.map +1 -1
  127. package/dist/services/auth-audit.service.js +33 -33
  128. package/dist/services/auth-audit.service.js.map +1 -1
  129. package/dist/services/auth-challenge-helper.service.js +3 -3
  130. package/dist/services/auth-challenge-helper.service.js.map +1 -1
  131. package/dist/services/auth-service-internal-helpers.d.ts +2 -2
  132. package/dist/services/auth-service-internal-helpers.d.ts.map +1 -1
  133. package/dist/services/auth-service-internal-helpers.js.map +1 -1
  134. package/dist/services/auth.service.d.ts +122 -446
  135. package/dist/services/auth.service.d.ts.map +1 -1
  136. package/dist/services/auth.service.js +424 -1274
  137. package/dist/services/auth.service.js.map +1 -1
  138. package/dist/services/mfa.service.d.ts +90 -12
  139. package/dist/services/mfa.service.d.ts.map +1 -1
  140. package/dist/services/mfa.service.js +395 -264
  141. package/dist/services/mfa.service.js.map +1 -1
  142. package/dist/services/password-reset.service.d.ts.map +1 -1
  143. package/dist/services/password-reset.service.js +80 -29
  144. package/dist/services/password-reset.service.js.map +1 -1
  145. package/dist/services/social-auth.service.d.ts +7 -0
  146. package/dist/services/social-auth.service.d.ts.map +1 -1
  147. package/dist/services/social-auth.service.js +38 -26
  148. package/dist/services/social-auth.service.js.map +1 -1
  149. package/dist/services/user.service.d.ts +3 -3
  150. package/dist/services/user.service.d.ts.map +1 -1
  151. package/dist/services/user.service.js +7 -7
  152. package/dist/services/user.service.js.map +1 -1
  153. package/dist/utils/dto-validator.d.ts.map +1 -1
  154. package/dist/utils/dto-validator.js +50 -4
  155. package/dist/utils/dto-validator.js.map +1 -1
  156. package/dist/utils/setup/init-services.d.ts +2 -1
  157. package/dist/utils/setup/init-services.d.ts.map +1 -1
  158. package/dist/utils/setup/init-services.js +2 -0
  159. package/dist/utils/setup/init-services.js.map +1 -1
  160. package/package.json +1 -1
  161. package/dist/dto/change-password-request.dto.d.ts +0 -43
  162. package/dist/dto/change-password-request.dto.d.ts.map +0 -1
  163. package/dist/dto/change-password-request.dto.js.map +0 -1
  164. package/dist/dto/update-user-attributes-request.dto.d.ts +0 -44
  165. package/dist/dto/update-user-attributes-request.dto.d.ts.map +0 -1
  166. package/dist/dto/update-user-attributes-request.dto.js.map +0 -1
@@ -14,48 +14,56 @@ import { InternalAuthAuditService as AuthAuditService } from './auth-audit.servi
14
14
  import { TrustedDeviceService } from './trusted-device.service';
15
15
  import { MFAService } from './mfa.service';
16
16
  import { SignupDTO } from '../dto/signup.dto';
17
- import { AdminSignupDTO, AdminSignupResponseDTO } from '../dto/admin-signup.dto';
18
- import { AdminSignupSocialDTO, AdminSignupSocialResponseDTO } from '../dto/admin-signup-social.dto';
19
- import { DeleteUserDTO, DeleteUserResponseDTO } from '../dto/delete-user.dto';
20
- import { GetUsersDTO, GetUsersResponseDTO } from '../dto/get-users.dto';
21
- import { DisableUserDTO, DisableUserResponseDTO } from '../dto/disable-user.dto';
22
- import { EnableUserDTO, EnableUserResponseDTO } from '../dto/enable-user.dto';
23
17
  import { LoginDTO } from '../dto/login.dto';
24
- import { ChangePasswordRequestDTO } from '../dto/change-password-request.dto';
18
+ import { ChangePasswordDTO } from '../dto/change-password.dto';
25
19
  import { ChangePasswordResponseDTO } from '../dto/change-password-response.dto';
26
- import { UpdateUserAttributesRequestDTO } from '../dto/update-user-attributes-request.dto';
27
- import { UpdateVerifiedStatusRequestDTO } from '../dto/update-verified-status-request.dto';
20
+ import { UpdateUserAttributesDTO } from '../dto/update-user-attributes.dto';
28
21
  import { UserResponseDto } from '../dto/user-response.dto';
29
22
  import { AuthResponseDTO, TokenResponse } from '../dto/auth-response.dto';
30
23
  import { RespondChallengeDTO } from '../dto/respond-challenge.dto';
31
- import { GetUserByEmailDTO } from '../dto/get-user-by-email.dto';
32
- import { GetUserByIdDTO } from '../dto/get-user-by-id.dto';
33
24
  import { LogoutDTO } from '../dto/logout.dto';
34
25
  import { LogoutResponseDTO } from '../dto/logout-response.dto';
35
26
  import { LogoutAllDTO } from '../dto/logout-all.dto';
36
27
  import { LogoutAllResponseDTO } from '../dto/logout-all-response.dto';
37
- import { GetUserSessionsDTO } from '../dto/get-user-sessions.dto';
38
28
  import { GetUserSessionsResponseDTO } from '../dto/get-user-sessions-response.dto';
39
29
  import { LogoutSessionDTO } from '../dto/logout-session.dto';
40
30
  import { LogoutSessionResponseDTO } from '../dto/logout-session-response.dto';
41
31
  import { RefreshTokenDTO } from '../dto/refresh-token.dto';
42
32
  import { ResendCodeDTO } from '../dto/resend-code.dto';
43
33
  import { ResendCodeResponseDTO } from '../dto/resend-code-response.dto';
44
- import { SetMustChangePasswordDTO } from '../dto/set-must-change-password.dto';
45
- import { SetMustChangePasswordResponseDTO } from '../dto/set-must-change-password-response.dto';
46
- import { AdminSetPasswordDTO, AdminSetPasswordResponseDTO } from '../dto/admin-set-password.dto';
47
- import { AdminResetPasswordDTO, AdminResetPasswordResponseDTO, ConfirmAdminResetPasswordDTO, ConfirmAdminResetPasswordResponseDTO } from '../dto/admin-reset-password.dto';
34
+ import { ValidateAccessTokenDTO } from '../dto/validate-access-token.dto';
35
+ import { ValidateAccessTokenResponseDTO } from '../dto/validate-access-token-response.dto';
48
36
  import { ForgotPasswordDTO, ForgotPasswordResponseDTO } from '../dto/forgot-password.dto';
49
37
  import { ConfirmForgotPasswordDTO, ConfirmForgotPasswordResponseDTO } from '../dto/confirm-forgot-password.dto';
50
38
  import { TrustDeviceResponseDTO } from '../dto/trust-device-response.dto';
51
39
  import { IsTrustedDeviceResponseDTO } from '../dto/is-trusted-device-response.dto';
52
- import { ValidateAccessTokenDTO } from '../dto/validate-access-token.dto';
53
- import { ValidateAccessTokenResponseDTO } from '../dto/validate-access-token-response.dto';
40
+ import { GetMFAStatusResponseDTO } from '../dto/get-mfa-status.dto';
41
+ import { GetUserAuthHistoryDTO } from '../dto/get-user-auth-history.dto';
42
+ import { GetUserAuthHistoryResponseDTO } from '../dto/admin-get-user-auth-history.dto';
54
43
  import { PasswordResetService } from './password-reset.service';
55
44
  import { SocialAuthService } from './social-auth.service';
56
45
  import { HookRegistryService } from './hook-registry.service';
57
46
  import { NAuthConfig } from '../interfaces/config.interface';
58
47
  import { NAuthLogger } from '../utils/nauth-logger';
48
+ /**
49
+ * Core user-facing authentication service
50
+ *
51
+ * This service implements **self-service** authentication flows for the currently authenticated user:
52
+ * - Signup, login, challenge completion, refresh token rotation
53
+ * - Logout / logout-all / logout-session (self-management)
54
+ * - Profile management and password change (self-management)
55
+ *
56
+ * Admin-only operations (explicit targeting via `sub`) are intentionally owned by {@link AdminAuthService}.
57
+ *
58
+ * @example
59
+ * ```typescript
60
+ * // Login (self-service)
61
+ * const result = await authService.login({ identifier: 'user@example.com', password: 'Password123!' });
62
+ *
63
+ * // Refresh (self-service; cookies or JSON depending on config)
64
+ * const refreshed = await authService.refreshToken({ refreshToken: '...' });
65
+ * ```
66
+ */
59
67
  export declare class AuthService {
60
68
  private readonly userRepository;
61
69
  private readonly loginAttemptRepository;
@@ -118,194 +126,6 @@ export declare class AuthService {
118
126
  * ```
119
127
  */
120
128
  signup(dto: SignupDTO): Promise<AuthResponseDTO>;
121
- /**
122
- * Administrative user creation with override capabilities
123
- *
124
- * Allows administrators to create user accounts with:
125
- * - Bypass email/phone verification requirements
126
- * - Force password change on first login
127
- * - Auto-generate secure passwords
128
- *
129
- * Security:
130
- * - No built-in authentication - endpoint must be protected by framework adapter
131
- * - All duplicate checks still enforced
132
- * - Password policy still enforced (unless auto-generated)
133
- * - Audit trail records admin-created accounts
134
- *
135
- * @param dto - Admin signup DTO with override flags
136
- * @returns User object and optionally generated password
137
- * @throws {NAuthException} EMAIL_EXISTS | USERNAME_EXISTS | PHONE_EXISTS | WEAK_PASSWORD
138
- *
139
- * @example
140
- * ```typescript
141
- * // Create user with pre-verified email
142
- * const result = await authService.adminSignup({
143
- * email: 'user@example.com',
144
- * password: 'SecurePass123!',
145
- * isEmailVerified: true,
146
- * });
147
- *
148
- * // Create user with auto-generated password
149
- * const result = await authService.adminSignup({
150
- * email: 'user@example.com',
151
- * generatePassword: true,
152
- * isEmailVerified: true,
153
- * mustChangePassword: true,
154
- * });
155
- * // result.generatedPassword contains the temporary password
156
- * ```
157
- */
158
- adminSignup(dto: AdminSignupDTO): Promise<AdminSignupResponseDTO>;
159
- /**
160
- * Administrative social user import with override capabilities
161
- *
162
- * Allows administrators to import existing social users from external platforms
163
- * (e.g., Cognito, Auth0) into nauth with:
164
- * - Bypass email/phone verification requirements
165
- * - Optional password for hybrid social+password accounts
166
- * - Social account linkage (provider + providerId)
167
- * - Automatic user flag updates (hasSocialAuth)
168
- *
169
- * Use case: Migrating users from external authentication platforms while
170
- * preserving their social login connections for transparent future logins.
171
- *
172
- * Security:
173
- * - No built-in authentication - endpoint must be protected by framework adapter
174
- * - All duplicate checks enforced (email, username, phone, provider+providerId)
175
- * - Password policy enforced if password provided
176
- * - Audit trail records admin-imported social accounts
177
- *
178
- * @param dto - Admin social signup DTO with social account details
179
- * @returns User object and social account confirmation
180
- * @throws {NAuthException} EMAIL_EXISTS | USERNAME_EXISTS | PHONE_EXISTS | SOCIAL_ACCOUNT_EXISTS | WEAK_PASSWORD
181
- *
182
- * @example
183
- * ```typescript
184
- * // Import social-only user from Cognito
185
- * // Note: Email is automatically verified for social imports (like normal social signup)
186
- * const result = await authService.adminSignupSocial({
187
- * email: 'user@example.com',
188
- * provider: 'google',
189
- * providerId: 'google_12345',
190
- * providerEmail: 'user@gmail.com',
191
- * socialMetadata: { sub: 'google_12345', given_name: 'John' },
192
- * });
193
- *
194
- * // Import hybrid user with password + social
195
- * const result = await authService.adminSignupSocial({
196
- * email: 'user@example.com',
197
- * password: 'SecurePass123!',
198
- * provider: 'apple',
199
- * providerId: 'apple_67890',
200
- * });
201
- * ```
202
- */
203
- adminSignupSocial(dto: AdminSignupSocialDTO): Promise<AdminSignupSocialResponseDTO>;
204
- /**
205
- * Administrative user deletion with complete cascade cleanup
206
- *
207
- * HARD DELETE - Permanently removes user and ALL associated data including:
208
- * - Sessions, verification tokens, MFA devices, trusted devices
209
- * - Social accounts, login attempts, challenge sessions, audit logs
210
- *
211
- * Security:
212
- * - NO built-in authentication - endpoint MUST be protected by admin guards
213
- * - Records admin action in separate audit log (not deleted with user)
214
- * - Irreversible operation - all data permanently removed
215
- *
216
- * @param dto - User sub to delete
217
- * @returns Deletion confirmation with cascade counts
218
- * @throws {NAuthException} USER_NOT_FOUND
219
- *
220
- * @example
221
- * ```typescript
222
- * const result = await authService.deleteUser({ sub: 'user-uuid-123' });
223
- * console.log(`Deleted user: ${result.deletedUserId}`);
224
- * console.log(`Deleted ${result.deletedRecords.sessions} sessions`);
225
- * ```
226
- */
227
- deleteUser(dto: DeleteUserDTO): Promise<DeleteUserResponseDTO>;
228
- /**
229
- * Get paginated list of users with advanced filtering
230
- *
231
- * Supports pagination, boolean filters, exact match filters,
232
- * date filters with operators (gt, gte, lt, lte, eq), and flexible sorting.
233
- *
234
- * Security:
235
- * - NO built-in authentication - endpoint MUST be protected by admin guards
236
- * - Returns sanitized user data (no passwordHash, secrets)
237
- *
238
- * @param dto - Filters, pagination, sorting
239
- * @returns Paginated user list with metadata
240
- *
241
- * @example
242
- * ```typescript
243
- * const result = await authService.getUsers({
244
- * page: 1,
245
- * limit: 20,
246
- * isEmailVerified: true,
247
- * hasSocialAuth: true,
248
- * createdAt: { operator: 'gte', value: new Date('2024-01-01') },
249
- * sortBy: 'createdAt',
250
- * sortOrder: 'DESC'
251
- * });
252
- * ```
253
- */
254
- getUsers(dto: GetUsersDTO): Promise<GetUsersResponseDTO>;
255
- /**
256
- * Administrative permanent account locking
257
- *
258
- * Sets permanent lock (lockedUntil=NULL) and immediately revokes all active sessions.
259
- * Reuses existing rate-limit lock fields (isLocked, lockReason, lockedAt, lockedUntil).
260
- *
261
- * Permanent vs Temporary locks:
262
- * - Rate limiting: lockedUntil = future date (temporary auto-unlock)
263
- * - Admin disableUser: lockedUntil = NULL (permanent manual lock)
264
- *
265
- * Security:
266
- * - NO built-in authentication - endpoint MUST be protected by admin guards
267
- * - Revokes all sessions immediately (forced logout)
268
- * - Records ACCOUNT_DISABLED audit event with admin identifier
269
- *
270
- * @param dto - User sub and optional reason
271
- * @returns User object with updated lock status and revoked session count
272
- * @throws {NAuthException} USER_NOT_FOUND
273
- *
274
- * @example
275
- * ```typescript
276
- * const result = await authService.disableUser({
277
- * sub: 'user-uuid-123',
278
- * reason: 'Suspicious activity detected'
279
- * });
280
- * console.log(`Revoked ${result.revokedSessions} sessions`);
281
- * ```
282
- */
283
- disableUser(dto: DisableUserDTO): Promise<DisableUserResponseDTO>;
284
- /**
285
- * Enable (unlock) user account
286
- *
287
- * Unlocks a previously locked user account by clearing all lock fields.
288
- * This reverses the effect of disableUser() or rate-limit lockouts.
289
- *
290
- * Security:
291
- * - NO built-in authentication - endpoint MUST be protected by admin guards
292
- * - Clears lock fields (isLocked, lockReason, lockedAt, lockedUntil)
293
- * - Resets failed login attempts counter
294
- * - Records ACCOUNT_ENABLED audit event with admin identifier
295
- *
296
- * @param dto - User sub to enable
297
- * @returns User object with updated lock status
298
- * @throws {NAuthException} USER_NOT_FOUND
299
- *
300
- * @example
301
- * ```typescript
302
- * const result = await authService.enableUser({
303
- * sub: 'user-uuid-123'
304
- * });
305
- * console.log(`User unlocked: ${result.user.email}`);
306
- * ```
307
- */
308
- enableUser(dto: EnableUserDTO): Promise<EnableUserResponseDTO>;
309
129
  /**
310
130
  * Log in a user with identifier (email, username, or phone) and password.
311
131
  *
@@ -453,9 +273,8 @@ export declare class AuthService {
453
273
  * - Requires authentication - session ID must be present in request context
454
274
  * - Endpoint MUST be protected by authentication guards
455
275
  * - User cannot specify which session to logout (always current session)
456
- * - Optional sub validation for additional security
457
276
  *
458
- * @param dto - Logout options (optional sub for validation, optional forgetMe flag)
277
+ * @param dto - Logout options (optional forgetMe flag)
459
278
  * @returns Success status
460
279
  * @throws {NAuthException} SESSION_NOT_FOUND if session ID not found in request context
461
280
  *
@@ -464,10 +283,7 @@ export declare class AuthService {
464
283
  * @UseGuards(AuthGuard)
465
284
  * @Get('logout')
466
285
  * async logout(@CurrentUser() user: IUser, @Query('forgetMe') forgetMe?: string) {
467
- * const dto = new LogoutDTO();
468
- * dto.sub = user.sub; // Optional validation
469
- * dto.forgetMe = forgetMe === 'true';
470
- * return this.authService.logout(dto);
286
+ * return this.authService.logout({ forgetMe: forgetMe === 'true' });
471
287
  * }
472
288
  * ```
473
289
  */
@@ -479,16 +295,13 @@ export declare class AuthService {
479
295
  * Optionally revokes all trusted devices if forgetDevices flag is set.
480
296
  *
481
297
  * Usage Patterns:
482
- * - **User-initiated**: User logs out from all their own sessions (protected endpoint, user provides their own sub)
483
- * - **Admin-initiated**: Admin force-logs out any user (admin-protected endpoint, admin provides target user's sub)
298
+ * - **User-initiated**: User logs out from all their own sessions (protected endpoint)
484
299
  *
485
300
  * Security:
486
- * - Requires explicit sub parameter
487
- * - NO built-in authentication - endpoint MUST be protected by guards
488
- * - For user endpoints: Extract sub from authenticated user context (@CurrentUser)
489
- * - For admin endpoints: Accept sub from route parameter and protect with admin guards
301
+ * - Uses authenticated user context for sub
302
+ * - Endpoint MUST be protected by authentication guards
490
303
  *
491
- * @param dto - User sub and optional forgetDevices flag
304
+ * @param dto - Logout options (forgetDevices flag)
492
305
  * @returns Number of sessions revoked
493
306
  * @throws {NAuthException} NOT_FOUND if user not found
494
307
  *
@@ -498,17 +311,17 @@ export declare class AuthService {
498
311
  * @UseGuards(AuthGuard)
499
312
  * @Post('logout/all')
500
313
  * async logoutAll(@CurrentUser() user: IUser, @Body() body: { forgetDevices?: boolean }) {
501
- * return this.authService.logoutAll({ sub: user.sub, forgetDevices: body.forgetDevices });
314
+ * return this.authService.logoutAll({ forgetDevices: body.forgetDevices });
502
315
  * }
503
316
  * ```
504
317
  *
505
318
  * @example Admin-initiated (admin manages any user)
506
319
  * ```typescript
507
- * // Admin provides target user's sub
320
+ * // Use AdminAuthService.logoutAll with target sub
508
321
  * @UseGuards(AuthGuard, AdminGuard)
509
322
  * @Post('admin/users/:sub/logout-all')
510
323
  * async adminLogoutAll(@Param('sub') sub: string, @Body() body: { forgetDevices?: boolean }) {
511
- * return this.authService.logoutAll({ sub, forgetDevices: body.forgetDevices });
324
+ * return this.adminAuthService.logoutAll({ sub, forgetDevices: body.forgetDevices });
512
325
  * }
513
326
  * ```
514
327
  */
@@ -521,16 +334,12 @@ export declare class AuthService {
521
334
  * Current session (if called from authenticated context) is marked with isCurrent=true.
522
335
  *
523
336
  * Usage Patterns:
524
- * - **User viewing own sessions**: User views their active sessions (protected endpoint, user provides their own sub)
525
- * - **Admin viewing any user's sessions**: Admin views any user's sessions (admin-protected endpoint, admin provides target user's sub)
337
+ * - **User viewing own sessions**: User views their active sessions (protected endpoint)
526
338
  *
527
339
  * Security:
528
- * - Requires explicit sub parameter
529
- * - NO built-in authentication - endpoint MUST be protected by guards
530
- * - For user endpoints: Extract sub from authenticated user context (@CurrentUser)
531
- * - For admin endpoints: Accept sub from route parameter and protect with admin guards
340
+ * - Uses authenticated user context for sub
341
+ * - Endpoint MUST be protected by authentication guards
532
342
  *
533
- * @param dto - Contains user sub
534
343
  * @returns Array of sessions with device info, auth method, and isCurrent flag
535
344
  * @throws {NAuthException} NOT_FOUND if user not found
536
345
  *
@@ -539,7 +348,7 @@ export declare class AuthService {
539
348
  * @UseGuards(AuthGuard)
540
349
  * @Get('sessions')
541
350
  * async getSessions(@CurrentUser() user: IUser) {
542
- * return this.authService.getUserSessions({ sub: user.sub });
351
+ * return this.authService.getUserSessions();
543
352
  * }
544
353
  * ```
545
354
  *
@@ -548,11 +357,70 @@ export declare class AuthService {
548
357
  * @UseGuards(AuthGuard, AdminGuard)
549
358
  * @Get('admin/users/:sub/sessions')
550
359
  * async adminGetSessions(@Param('sub') sub: string) {
551
- * return this.authService.getUserSessions({ sub });
360
+ * return this.adminAuthService.getUserSessions({ sub });
361
+ * }
362
+ * ```
363
+ */
364
+ getUserSessions(): Promise<GetUserSessionsResponseDTO>;
365
+ /**
366
+ * Get MFA status for current authenticated user
367
+ *
368
+ * Returns comprehensive MFA status including enabled status, configured methods,
369
+ * available methods, backup codes, and exemption information.
370
+ *
371
+ * Usage Patterns:
372
+ * - **User viewing own MFA status**: User views their MFA configuration (protected endpoint)
373
+ *
374
+ * Security:
375
+ * - Uses authenticated user context for sub
376
+ * - Endpoint MUST be protected by authentication guards
377
+ *
378
+ * @returns MFA status response
379
+ * @throws {NAuthException} FORBIDDEN if user not authenticated
380
+ * @throws {NAuthException} NOT_FOUND if user not found
381
+ *
382
+ * @example User viewing own MFA status
383
+ * ```typescript
384
+ * @UseGuards(AuthGuard)
385
+ * @Get('mfa/status')
386
+ * async getMFAStatus() {
387
+ * return this.authService.getMFAStatus();
552
388
  * }
553
389
  * ```
554
390
  */
555
- getUserSessions(dto: GetUserSessionsDTO): Promise<GetUserSessionsResponseDTO>;
391
+ getMFAStatus(): Promise<GetMFAStatusResponseDTO>;
392
+ /**
393
+ * Get authentication audit history for current authenticated user
394
+ *
395
+ * Returns paginated audit trail of authentication events for the user:
396
+ * - Login attempts (success/failure)
397
+ * - Password changes
398
+ * - MFA setup/verification
399
+ * - Device trust events
400
+ * - Device information, location, risk factors
401
+ *
402
+ * Usage Patterns:
403
+ * - **User viewing own audit history**: User views their authentication history (protected endpoint)
404
+ *
405
+ * Security:
406
+ * - Uses authenticated user context for sub
407
+ * - Endpoint MUST be protected by authentication guards
408
+ *
409
+ * @param dto - Optional query parameters for filtering and pagination
410
+ * @returns Paginated audit history response
411
+ * @throws {NAuthException} FORBIDDEN if user not authenticated
412
+ * @throws {NAuthException} NOT_FOUND if user not found
413
+ *
414
+ * @example User viewing own audit history
415
+ * ```typescript
416
+ * @UseGuards(AuthGuard)
417
+ * @Get('audit/history')
418
+ * async getAuditHistory(@Query() query: GetUserAuthHistoryDTO) {
419
+ * return this.authService.getUserAuthHistory(query);
420
+ * }
421
+ * ```
422
+ */
423
+ getUserAuthHistory(dto?: GetUserAuthHistoryDTO): Promise<GetUserAuthHistoryResponseDTO>;
556
424
  /**
557
425
  * Logout a specific session by ID
558
426
  *
@@ -561,17 +429,14 @@ export declare class AuthService {
561
429
  * Useful for "sign out from device" functionality in user dashboards.
562
430
  *
563
431
  * Usage Patterns:
564
- * - **User logging out own session**: User revokes specific session (protected endpoint, user provides their own sub)
565
- * - **Admin revoking any user's session**: Admin revokes specific session for any user (admin-protected endpoint, admin provides target user's sub)
432
+ * - **User logging out own session**: User revokes specific session (protected endpoint)
566
433
  *
567
434
  * Security:
568
- * - Requires explicit sub parameter
435
+ * - Uses authenticated user context for sub
569
436
  * - Validates session belongs to user (prevents unauthorized session revocation)
570
- * - NO built-in authentication - endpoint MUST be protected by guards
571
- * - For user endpoints: Extract sub from authenticated user context (@CurrentUser)
572
- * - For admin endpoints: Accept sub from route parameter and protect with admin guards
437
+ * - Endpoint MUST be protected by authentication guards
573
438
  *
574
- * @param dto - Contains sessionId and user sub
439
+ * @param dto - Contains sessionId
575
440
  * @returns Success status and whether it was the current session
576
441
  * @throws {NAuthException} NOT_FOUND if user not found
577
442
  * @throws {NAuthException} SESSION_NOT_FOUND if session not found
@@ -582,7 +447,7 @@ export declare class AuthService {
582
447
  * @UseGuards(AuthGuard)
583
448
  * @Delete('sessions/:sessionId')
584
449
  * async logoutSession(@CurrentUser() user: IUser, @Param('sessionId') sessionId: string) {
585
- * return this.authService.logoutSession({ sub: user.sub, sessionId });
450
+ * return this.authService.logoutSession({ sessionId });
586
451
  * }
587
452
  * ```
588
453
  *
@@ -591,7 +456,7 @@ export declare class AuthService {
591
456
  * @UseGuards(AuthGuard, AdminGuard)
592
457
  * @Delete('admin/users/:sub/sessions/:sessionId')
593
458
  * async adminRevokeSession(@Param('sub') sub: string, @Param('sessionId') sessionId: string) {
594
- * return this.authService.logoutSession({ sub, sessionId });
459
+ * return this.adminAuthService.revokeUserSession({ sub, sessionId });
595
460
  * }
596
461
  * ```
597
462
  */
@@ -603,69 +468,51 @@ export declare class AuthService {
603
468
  * checks password reuse policy, and updates the user's password hash and history.
604
469
  * Executes configured pre-change hooks if provided.
605
470
  *
606
- * @param sub - External user identifier (sub/UUID)
607
471
  * @param dto - ChangePasswordDTO containing old and new password
608
472
  * @returns void
609
473
  * @throws {NAuthException} If the user is not found, current password is incorrect, the new password is weak, password reuse is detected, or password change is disallowed by hooks.
610
474
  *
611
475
  * @example
612
476
  * ```typescript
613
- * await authService.changePassword('user-uuid', {
477
+ * await authService.changePassword({
614
478
  * oldPassword: 'currentPass123!',
615
479
  * newPassword: 'newStr0ngPass!@#',
616
480
  * });
617
481
  * ```
618
482
  */
619
- changePassword(dto: ChangePasswordRequestDTO): Promise<ChangePasswordResponseDTO>;
483
+ changePassword(dto: ChangePasswordDTO): Promise<ChangePasswordResponseDTO>;
620
484
  /**
621
485
  * Update user profile attributes.
622
486
  *
623
487
  * Updates user fields (name, email, phone, username, metadata) and enforces unique constraints and verification rules.
624
488
  *
625
- * @param dto - UpdateUserAttributesRequestDTO containing sub and fields to update
489
+ * @param dto - UpdateUserAttributesDTO containing fields to update
626
490
  * @returns Updated user object
627
491
  * @throws {NAuthException} If user not found or unique constraint violated
628
492
  *
629
493
  * @example
630
- * await authService.updateUserAttributes({ sub: 'user-uuid', email: 'test@example.com' });
494
+ * await authService.updateUserAttributes({ email: 'test@example.com' });
631
495
  */
632
- updateUserAttributes(dto: UpdateUserAttributesRequestDTO): Promise<UserResponseDto>;
496
+ updateUserAttributes(dto: UpdateUserAttributesDTO): Promise<UserResponseDto>;
633
497
  /**
634
- * Update email and/or phone verification status.
635
- *
636
- * Intended for admin use cases such as migration or offline validation.
637
- * Updates verification status without requiring actual verification codes.
498
+ * Get user for authentication context
638
499
  *
639
- * Validation:
640
- * - Cannot set verified=true if email/phone doesn't exist
641
- * - Can set verified=false even if email/phone doesn't exist (default state)
642
- * - Only updates provided fields (partial update)
500
+ * Loads user by sub (external identifier) with all fields needed for auth context.
501
+ * Computes hasPasswordHash from passwordHash, then removes passwordHash and other sensitive fields.
643
502
  *
644
- * Audit:
645
- * - Records EMAIL_VERIFIED or PHONE_VERIFIED audit events
646
- * - Includes performedBy from authenticated admin context
503
+ * This method is used by AuthHandler and AuthGuard to load authenticated users.
504
+ * It ensures consistent user object shape across platforms (core + NestJS).
647
505
  *
648
- * @param dto - Request DTO containing sub and verification status flags
649
- * @returns Updated user object
650
- * @throws {NAuthException} If user not found or trying to verify non-existent email/phone
506
+ * @param sub - External user identifier (UUID)
507
+ * @returns User object with hasPasswordHash flag, without sensitive fields
508
+ * @throws {NAuthException} If user not found or account is inactive
651
509
  *
652
510
  * @example
653
511
  * ```typescript
654
- * // Update email verification only
655
- * await authService.updateVerifiedStatus({
656
- * sub: 'user-uuid',
657
- * isEmailVerified: true
658
- * });
659
- *
660
- * // Update both email and phone verification
661
- * await authService.updateVerifiedStatus({
662
- * sub: 'user-uuid',
663
- * isEmailVerified: true,
664
- * isPhoneVerified: false
665
- * });
512
+ * const user = await authService.getUserForAuthContext('user-uuid');
666
513
  * ```
667
514
  */
668
- updateVerifiedStatus(dto: UpdateVerifiedStatusRequestDTO): Promise<UserResponseDto>;
515
+ getUserForAuthContext(sub: string): Promise<IUser>;
669
516
  /**
670
517
  * Validate JWT access token
671
518
  *
@@ -702,178 +549,6 @@ export declare class AuthService {
702
549
  * ```
703
550
  */
704
551
  validateAccessToken(dto: ValidateAccessTokenDTO): Promise<ValidateAccessTokenResponseDTO>;
705
- /**
706
- * Get user for authentication context
707
- *
708
- * Loads user by sub (external identifier) with all fields needed for auth context.
709
- * Computes hasPasswordHash from passwordHash, then removes passwordHash and other sensitive fields.
710
- *
711
- * This method is used by AuthHandler and AuthGuard to load authenticated users.
712
- * It ensures consistent user object shape across platforms (core + NestJS).
713
- *
714
- * @param sub - External user identifier (UUID)
715
- * @returns User object with hasPasswordHash flag, without sensitive fields
716
- * @throws {NAuthException} If user not found or account is inactive
717
- *
718
- * @example
719
- * ```typescript
720
- * const user = await authService.getUserForAuthContext('user-uuid-123');
721
- * // user.hasPasswordHash === true/false
722
- * // user.passwordHash === undefined (removed)
723
- * ```
724
- */
725
- getUserForAuthContext(sub: string): Promise<IUser>;
726
- /**
727
- * Get user by external identifier (sub/UUID).
728
- *
729
- * @param dto - GetUserByIdDTO containing sub
730
- * @returns User response DTO or null if not found
731
- *
732
- * @example
733
- * ```typescript
734
- * const user = await authService.getUserById({ sub: 'user-uuid' });
735
- * ```
736
- */
737
- getUserById(dto: GetUserByIdDTO): Promise<UserResponseDto | null>;
738
- /**
739
- * Get user by email address.
740
- *
741
- * @param dto - GetUserByEmailDTO containing email and optional requireEmailVerified
742
- * @returns User response DTO or null if not found
743
- * @internal - For use by social auth providers
744
- *
745
- * @example
746
- * ```typescript
747
- * const user = await authService.getUserByEmail({ email: 'user@example.com', requireEmailVerified: true });
748
- * ```
749
- */
750
- getUserByEmail(dto: GetUserByEmailDTO): Promise<UserResponseDto | null>;
751
- /**
752
- * Require user to change password at next login.
753
- *
754
- * Throws if user not found or has no password set (e.g. social login only).
755
- *
756
- * @param dto - SetMustChangePasswordDTO containing userId (sub)
757
- * @returns Success response
758
- * @throws {NAuthException} If user is not found or cannot change password
759
- *
760
- * @example
761
- * ```typescript
762
- * await authService.setMustChangePassword({ userId: 'user-uuid-123' });
763
- * ```
764
- */
765
- setMustChangePassword(dto: SetMustChangePasswordDTO): Promise<SetMustChangePasswordResponseDTO>;
766
- /**
767
- * Admin-only: Initiate a code-based password reset workflow.
768
- *
769
- * Unlike adminSetPassword(), this sends a verification code (and optional link)
770
- * to the user via email/SMS and allows them to set their own password.
771
- *
772
- * Features:
773
- * - Code + optional link delivery (like email verification)
774
- * - Optional immediate session revocation
775
- * - Configurable expiry (default 1 hour)
776
- * - Admin-specific email template
777
- * - No rate limiting (admin bypass)
778
- * - Separate audit trail with reason
779
- *
780
- * Security:
781
- * - Admin-only operation (protect route with admin guard)
782
- * - Non-enumerating (throws NOT_FOUND if user doesn't exist)
783
- * - Separate token type ('admin_password_reset')
784
- * - Audit logging with reason
785
- *
786
- * @param dto - Admin reset password request
787
- * @returns Response with masked destination, expiry, and sessions revoked count
788
- * @throws {NAuthException} NOT_FOUND when user not found
789
- *
790
- * @example
791
- * ```typescript
792
- * // With link for custom UI
793
- * const result = await authService.adminResetPassword({
794
- * identifier: 'user@example.com',
795
- * baseUrl: 'https://myapp.com/reset-password',
796
- * revokeSessions: true,
797
- * reason: 'User reported compromise'
798
- * });
799
- * // result: { success: true, destination: 'u***r@example.com', expiresIn: 3600, sessionsRevoked: 3 }
800
- *
801
- * // Code only (no link)
802
- * const result = await authService.adminResetPassword({
803
- * identifier: 'user@example.com'
804
- * });
805
- * ```
806
- */
807
- adminResetPassword(dto: AdminResetPasswordDTO): Promise<AdminResetPasswordResponseDTO>;
808
- /**
809
- * Complete admin-initiated password reset with verification code or token.
810
- *
811
- * Accepts either:
812
- * - code: Short numeric code from email/SMS (6-10 digits, attempt tracking)
813
- * - token: Long hex token from link (64 chars, single use, no attempts)
814
- *
815
- * Security:
816
- * - Verifies code/token via PasswordResetService
817
- * - Enforces password policy and history
818
- * - Always revokes all sessions on completion
819
- * - Does not force password change (user already set new password)
820
- * - Records audit event
821
- *
822
- * @param dto - Confirm admin reset password request
823
- * @returns Success response
824
- * @throws {NAuthException} NOT_FOUND | PASSWORD_RESET_CODE_INVALID | PASSWORD_RESET_CODE_EXPIRED | PASSWORD_RESET_MAX_ATTEMPTS | WEAK_PASSWORD | PASSWORD_REUSED | INVALID_CREDENTIALS
825
- *
826
- * @example
827
- * ```typescript
828
- * // With code
829
- * await authService.confirmAdminResetPassword({
830
- * identifier: 'user@example.com',
831
- * code: '123456',
832
- * newPassword: 'NewSecurePass123!'
833
- * });
834
- *
835
- * // With token from link
836
- * await authService.confirmAdminResetPassword({
837
- * identifier: 'user@example.com',
838
- * token: '64-char-hex-token',
839
- * newPassword: 'NewSecurePass123!'
840
- * });
841
- * ```
842
- */
843
- confirmAdminResetPassword(dto: ConfirmAdminResetPasswordDTO): Promise<ConfirmAdminResetPasswordResponseDTO>;
844
- /**
845
- * Admin-only: Reset a user's password by identifier.
846
- *
847
- * Allows administrators to reset a user's password using any identifier
848
- * (email, username, phone, or sub). Automatically revokes sessions and optionally
849
- * requires password change on next login using the existing challenge system.
850
- *
851
- * SECURITY: This is an admin-only operation. Ensure proper authorization
852
- * checks are in place before calling this method.
853
- *
854
- * @param dto - Admin reset password request
855
- * @returns Response with success status and session revocation count
856
- * @throws {NAuthException} If user not found, user has no password (social-only), or password validation fails
857
- *
858
- * @example
859
- * ```typescript
860
- * // Reset with force password change
861
- * const result = await authService.adminSetPassword({
862
- * identifier: 'user@example.com',
863
- * newPassword: 'NewSecurePassword123!',
864
- * mustChangePassword: true,
865
- * revokeSessions: true
866
- * });
867
- *
868
- * // Reset without forcing password change
869
- * const result = await authService.adminSetPassword({
870
- * identifier: 'a21b654c-2746-4168-acee-c175083a65cd',
871
- * newPassword: 'NewSecurePassword123!',
872
- * mustChangePassword: false
873
- * });
874
- * ```
875
- */
876
- adminSetPassword(dto: AdminSetPasswordDTO): Promise<AdminSetPasswordResponseDTO>;
877
552
  /**
878
553
  * Request a password reset code for an account.
879
554
  *
@@ -905,5 +580,6 @@ export declare class AuthService {
905
580
  * @throws {NAuthException} PASSWORD_RESET_CODE_INVALID | PASSWORD_RESET_CODE_EXPIRED | PASSWORD_RESET_MAX_ATTEMPTS
906
581
  */
907
582
  confirmForgotPassword(dto: ConfirmForgotPasswordDTO): Promise<ConfirmForgotPasswordResponseDTO>;
583
+ private getCurrentUserOrThrow;
908
584
  }
909
585
  //# sourceMappingURL=auth.service.d.ts.map