@nauth-toolkit/core 0.1.87 → 0.1.89

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 (174) hide show
  1. package/dist/dto/admin-get-mfa-status.dto.d.ts +20 -0
  2. package/dist/dto/admin-get-mfa-status.dto.d.ts.map +1 -0
  3. package/dist/dto/{change-password-request.dto.js → admin-get-mfa-status.dto.js} +22 -32
  4. package/dist/dto/admin-get-mfa-status.dto.js.map +1 -0
  5. package/dist/dto/admin-get-user-auth-history.dto.d.ts +62 -0
  6. package/dist/dto/admin-get-user-auth-history.dto.d.ts.map +1 -0
  7. package/dist/dto/admin-get-user-auth-history.dto.js +87 -0
  8. package/dist/dto/admin-get-user-auth-history.dto.js.map +1 -0
  9. package/dist/dto/admin-logout-all.dto.d.ts +48 -0
  10. package/dist/dto/admin-logout-all.dto.d.ts.map +1 -0
  11. package/dist/dto/admin-logout-all.dto.js +85 -0
  12. package/dist/dto/admin-logout-all.dto.js.map +1 -0
  13. package/dist/dto/admin-remove-devices.dto.d.ts +25 -0
  14. package/dist/dto/admin-remove-devices.dto.d.ts.map +1 -0
  15. package/dist/dto/admin-remove-devices.dto.js +50 -0
  16. package/dist/dto/admin-remove-devices.dto.js.map +1 -0
  17. package/dist/dto/admin-reset-password.dto.d.ts +15 -19
  18. package/dist/dto/admin-reset-password.dto.d.ts.map +1 -1
  19. package/dist/dto/admin-reset-password.dto.js +21 -41
  20. package/dist/dto/admin-reset-password.dto.js.map +1 -1
  21. package/dist/dto/admin-revoke-session.dto.d.ts +22 -0
  22. package/dist/dto/admin-revoke-session.dto.d.ts.map +1 -0
  23. package/dist/dto/admin-revoke-session.dto.js +48 -0
  24. package/dist/dto/admin-revoke-session.dto.js.map +1 -0
  25. package/dist/dto/admin-set-password.dto.d.ts +8 -10
  26. package/dist/dto/admin-set-password.dto.d.ts.map +1 -1
  27. package/dist/dto/admin-set-password.dto.js +11 -21
  28. package/dist/dto/admin-set-password.dto.js.map +1 -1
  29. package/dist/dto/admin-set-preferred-method.dto.d.ts +25 -0
  30. package/dist/dto/admin-set-preferred-method.dto.d.ts.map +1 -0
  31. package/dist/dto/admin-set-preferred-method.dto.js +50 -0
  32. package/dist/dto/admin-set-preferred-method.dto.js.map +1 -0
  33. package/dist/dto/admin-update-user-attributes.dto.d.ts +41 -0
  34. package/dist/dto/admin-update-user-attributes.dto.d.ts.map +1 -0
  35. package/dist/dto/{update-user-attributes-request.dto.js → admin-update-user-attributes.dto.js} +12 -17
  36. package/dist/dto/admin-update-user-attributes.dto.js.map +1 -0
  37. package/dist/dto/auth-challenge.dto.d.ts +2 -2
  38. package/dist/dto/auth-challenge.dto.d.ts.map +1 -1
  39. package/dist/dto/auth-challenge.dto.js +3 -3
  40. package/dist/dto/auth-challenge.dto.js.map +1 -1
  41. package/dist/dto/auth-response.dto.d.ts +1 -1
  42. package/dist/dto/auth-response.dto.d.ts.map +1 -1
  43. package/dist/dto/auth-response.dto.js +1 -1
  44. package/dist/dto/auth-response.dto.js.map +1 -1
  45. package/dist/dto/get-mfa-status.dto.d.ts +3 -32
  46. package/dist/dto/get-mfa-status.dto.d.ts.map +1 -1
  47. package/dist/dto/get-mfa-status.dto.js +4 -55
  48. package/dist/dto/get-mfa-status.dto.js.map +1 -1
  49. package/dist/dto/get-risk-assessment-history.dto.d.ts +3 -3
  50. package/dist/dto/get-risk-assessment-history.dto.d.ts.map +1 -1
  51. package/dist/dto/get-risk-assessment-history.dto.js +5 -5
  52. package/dist/dto/get-risk-assessment-history.dto.js.map +1 -1
  53. package/dist/dto/get-suspicious-activity.dto.d.ts +3 -3
  54. package/dist/dto/get-suspicious-activity.dto.d.ts.map +1 -1
  55. package/dist/dto/get-suspicious-activity.dto.js +5 -5
  56. package/dist/dto/get-suspicious-activity.dto.js.map +1 -1
  57. package/dist/dto/get-user-auth-history.dto.d.ts +4 -39
  58. package/dist/dto/get-user-auth-history.dto.d.ts.map +1 -1
  59. package/dist/dto/get-user-auth-history.dto.js +53 -51
  60. package/dist/dto/get-user-auth-history.dto.js.map +1 -1
  61. package/dist/dto/get-user-devices.dto.d.ts +5 -18
  62. package/dist/dto/get-user-devices.dto.d.ts.map +1 -1
  63. package/dist/dto/get-user-devices.dto.js +5 -39
  64. package/dist/dto/get-user-devices.dto.js.map +1 -1
  65. package/dist/dto/get-user-sessions-response.dto.d.ts +1 -1
  66. package/dist/dto/get-user-sessions-response.dto.js +1 -1
  67. package/dist/dto/get-user-sessions.dto.d.ts +1 -1
  68. package/dist/dto/get-user-sessions.dto.js +1 -1
  69. package/dist/dto/index.d.ts +9 -2
  70. package/dist/dto/index.d.ts.map +1 -1
  71. package/dist/dto/index.js +9 -2
  72. package/dist/dto/index.js.map +1 -1
  73. package/dist/dto/logout-all-response.dto.d.ts +1 -1
  74. package/dist/dto/logout-all-response.dto.js +1 -1
  75. package/dist/dto/logout-all.dto.d.ts +1 -18
  76. package/dist/dto/logout-all.dto.d.ts.map +1 -1
  77. package/dist/dto/logout-all.dto.js +1 -30
  78. package/dist/dto/logout-all.dto.js.map +1 -1
  79. package/dist/dto/logout-session.dto.d.ts +0 -5
  80. package/dist/dto/logout-session.dto.d.ts.map +1 -1
  81. package/dist/dto/logout-session.dto.js +0 -12
  82. package/dist/dto/logout-session.dto.js.map +1 -1
  83. package/dist/dto/logout.dto.d.ts +1 -18
  84. package/dist/dto/logout.dto.d.ts.map +1 -1
  85. package/dist/dto/logout.dto.js +1 -30
  86. package/dist/dto/logout.dto.js.map +1 -1
  87. package/dist/dto/remove-devices.dto.d.ts +4 -16
  88. package/dist/dto/remove-devices.dto.d.ts.map +1 -1
  89. package/dist/dto/remove-devices.dto.js +4 -26
  90. package/dist/dto/remove-devices.dto.js.map +1 -1
  91. package/dist/dto/set-mfa-exemption.dto.d.ts +8 -9
  92. package/dist/dto/set-mfa-exemption.dto.d.ts.map +1 -1
  93. package/dist/dto/set-mfa-exemption.dto.js +11 -13
  94. package/dist/dto/set-mfa-exemption.dto.js.map +1 -1
  95. package/dist/dto/set-must-change-password.dto.d.ts +3 -3
  96. package/dist/dto/set-must-change-password.dto.d.ts.map +1 -1
  97. package/dist/dto/set-must-change-password.dto.js +5 -5
  98. package/dist/dto/set-must-change-password.dto.js.map +1 -1
  99. package/dist/dto/set-preferred-method.dto.d.ts +4 -16
  100. package/dist/dto/set-preferred-method.dto.d.ts.map +1 -1
  101. package/dist/dto/set-preferred-method.dto.js +4 -26
  102. package/dist/dto/set-preferred-method.dto.js.map +1 -1
  103. package/dist/dto/setup-mfa.dto.d.ts +3 -18
  104. package/dist/dto/setup-mfa.dto.d.ts.map +1 -1
  105. package/dist/dto/setup-mfa.dto.js +3 -30
  106. package/dist/dto/setup-mfa.dto.js.map +1 -1
  107. package/dist/dto/social-auth.dto.d.ts +4 -34
  108. package/dist/dto/social-auth.dto.d.ts.map +1 -1
  109. package/dist/dto/social-auth.dto.js +10 -68
  110. package/dist/dto/social-auth.dto.js.map +1 -1
  111. package/dist/dto/update-user-attributes.dto.d.ts +26 -0
  112. package/dist/dto/update-user-attributes.dto.d.ts.map +1 -0
  113. package/dist/dto/update-user-attributes.dto.js +30 -0
  114. package/dist/dto/update-user-attributes.dto.js.map +1 -0
  115. package/dist/index.d.ts +5 -0
  116. package/dist/index.d.ts.map +1 -1
  117. package/dist/index.js +5 -0
  118. package/dist/index.js.map +1 -1
  119. package/dist/interfaces/hooks.interface.d.ts +2 -1
  120. package/dist/interfaces/hooks.interface.d.ts.map +1 -1
  121. package/dist/interfaces/mfa-provider.interface.d.ts +7 -8
  122. package/dist/interfaces/mfa-provider.interface.d.ts.map +1 -1
  123. package/dist/interfaces/provider.interface.d.ts +1 -1
  124. package/dist/interfaces/provider.interface.d.ts.map +1 -1
  125. package/dist/services/adaptive-mfa-decision.service.js +2 -2
  126. package/dist/services/adaptive-mfa-decision.service.js.map +1 -1
  127. package/dist/services/admin-auth.service.d.ts +307 -0
  128. package/dist/services/admin-auth.service.d.ts.map +1 -0
  129. package/dist/services/admin-auth.service.js +885 -0
  130. package/dist/services/admin-auth.service.js.map +1 -0
  131. package/dist/services/auth-audit.service.d.ts +16 -16
  132. package/dist/services/auth-audit.service.d.ts.map +1 -1
  133. package/dist/services/auth-audit.service.js +33 -33
  134. package/dist/services/auth-audit.service.js.map +1 -1
  135. package/dist/services/auth-challenge-helper.service.js +3 -3
  136. package/dist/services/auth-challenge-helper.service.js.map +1 -1
  137. package/dist/services/auth-service-internal-helpers.d.ts +13 -2
  138. package/dist/services/auth-service-internal-helpers.d.ts.map +1 -1
  139. package/dist/services/auth-service-internal-helpers.js +39 -1
  140. package/dist/services/auth-service-internal-helpers.js.map +1 -1
  141. package/dist/services/auth.service.d.ts +94 -438
  142. package/dist/services/auth.service.d.ts.map +1 -1
  143. package/dist/services/auth.service.js +388 -1255
  144. package/dist/services/auth.service.js.map +1 -1
  145. package/dist/services/mfa-base.service.d.ts +14 -4
  146. package/dist/services/mfa-base.service.d.ts.map +1 -1
  147. package/dist/services/mfa-base.service.js +22 -1
  148. package/dist/services/mfa-base.service.js.map +1 -1
  149. package/dist/services/mfa.service.d.ts +107 -33
  150. package/dist/services/mfa.service.d.ts.map +1 -1
  151. package/dist/services/mfa.service.js +456 -333
  152. package/dist/services/mfa.service.js.map +1 -1
  153. package/dist/services/social-auth.service.d.ts +7 -0
  154. package/dist/services/social-auth.service.d.ts.map +1 -1
  155. package/dist/services/social-auth.service.js +38 -26
  156. package/dist/services/social-auth.service.js.map +1 -1
  157. package/dist/services/user.service.d.ts +3 -3
  158. package/dist/services/user.service.d.ts.map +1 -1
  159. package/dist/services/user.service.js +7 -7
  160. package/dist/services/user.service.js.map +1 -1
  161. package/dist/utils/dto-validator.d.ts.map +1 -1
  162. package/dist/utils/dto-validator.js +50 -4
  163. package/dist/utils/dto-validator.js.map +1 -1
  164. package/dist/utils/setup/init-services.d.ts +2 -1
  165. package/dist/utils/setup/init-services.d.ts.map +1 -1
  166. package/dist/utils/setup/init-services.js +2 -0
  167. package/dist/utils/setup/init-services.js.map +1 -1
  168. package/package.json +1 -1
  169. package/dist/dto/change-password-request.dto.d.ts +0 -43
  170. package/dist/dto/change-password-request.dto.d.ts.map +0 -1
  171. package/dist/dto/change-password-request.dto.js.map +0 -1
  172. package/dist/dto/update-user-attributes-request.dto.d.ts +0 -44
  173. package/dist/dto/update-user-attributes-request.dto.d.ts.map +0 -1
  174. package/dist/dto/update-user-attributes-request.dto.js.map +0 -1
@@ -14,48 +14,55 @@ 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 { GetUserAuthHistoryDTO } from '../dto/get-user-auth-history.dto';
41
+ import { GetUserAuthHistoryResponseDTO } from '../dto/admin-get-user-auth-history.dto';
54
42
  import { PasswordResetService } from './password-reset.service';
55
43
  import { SocialAuthService } from './social-auth.service';
56
44
  import { HookRegistryService } from './hook-registry.service';
57
45
  import { NAuthConfig } from '../interfaces/config.interface';
58
46
  import { NAuthLogger } from '../utils/nauth-logger';
47
+ /**
48
+ * Core user-facing authentication service
49
+ *
50
+ * This service implements **self-service** authentication flows for the currently authenticated user:
51
+ * - Signup, login, challenge completion, refresh token rotation
52
+ * - Logout / logout-all / logout-session (self-management)
53
+ * - Profile management and password change (self-management)
54
+ *
55
+ * Admin-only operations (explicit targeting via `sub`) are intentionally owned by {@link AdminAuthService}.
56
+ *
57
+ * @example
58
+ * ```typescript
59
+ * // Login (self-service)
60
+ * const result = await authService.login({ identifier: 'user@example.com', password: 'Password123!' });
61
+ *
62
+ * // Refresh (self-service; cookies or JSON depending on config)
63
+ * const refreshed = await authService.refreshToken({ refreshToken: '...' });
64
+ * ```
65
+ */
59
66
  export declare class AuthService {
60
67
  private readonly userRepository;
61
68
  private readonly loginAttemptRepository;
@@ -118,194 +125,6 @@ export declare class AuthService {
118
125
  * ```
119
126
  */
120
127
  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
128
  /**
310
129
  * Log in a user with identifier (email, username, or phone) and password.
311
130
  *
@@ -453,9 +272,8 @@ export declare class AuthService {
453
272
  * - Requires authentication - session ID must be present in request context
454
273
  * - Endpoint MUST be protected by authentication guards
455
274
  * - User cannot specify which session to logout (always current session)
456
- * - Optional sub validation for additional security
457
275
  *
458
- * @param dto - Logout options (optional sub for validation, optional forgetMe flag)
276
+ * @param dto - Logout options (optional forgetMe flag)
459
277
  * @returns Success status
460
278
  * @throws {NAuthException} SESSION_NOT_FOUND if session ID not found in request context
461
279
  *
@@ -464,10 +282,7 @@ export declare class AuthService {
464
282
  * @UseGuards(AuthGuard)
465
283
  * @Get('logout')
466
284
  * 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);
285
+ * return this.authService.logout({ forgetMe: forgetMe === 'true' });
471
286
  * }
472
287
  * ```
473
288
  */
@@ -479,16 +294,13 @@ export declare class AuthService {
479
294
  * Optionally revokes all trusted devices if forgetDevices flag is set.
480
295
  *
481
296
  * 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)
297
+ * - **User-initiated**: User logs out from all their own sessions (protected endpoint)
484
298
  *
485
299
  * 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
300
+ * - Uses authenticated user context for sub
301
+ * - Endpoint MUST be protected by authentication guards
490
302
  *
491
- * @param dto - User sub and optional forgetDevices flag
303
+ * @param dto - Logout options (forgetDevices flag)
492
304
  * @returns Number of sessions revoked
493
305
  * @throws {NAuthException} NOT_FOUND if user not found
494
306
  *
@@ -498,17 +310,17 @@ export declare class AuthService {
498
310
  * @UseGuards(AuthGuard)
499
311
  * @Post('logout/all')
500
312
  * async logoutAll(@CurrentUser() user: IUser, @Body() body: { forgetDevices?: boolean }) {
501
- * return this.authService.logoutAll({ sub: user.sub, forgetDevices: body.forgetDevices });
313
+ * return this.authService.logoutAll({ forgetDevices: body.forgetDevices });
502
314
  * }
503
315
  * ```
504
316
  *
505
317
  * @example Admin-initiated (admin manages any user)
506
318
  * ```typescript
507
- * // Admin provides target user's sub
319
+ * // Use AdminAuthService.logoutAll with target sub
508
320
  * @UseGuards(AuthGuard, AdminGuard)
509
321
  * @Post('admin/users/:sub/logout-all')
510
322
  * async adminLogoutAll(@Param('sub') sub: string, @Body() body: { forgetDevices?: boolean }) {
511
- * return this.authService.logoutAll({ sub, forgetDevices: body.forgetDevices });
323
+ * return this.adminAuthService.logoutAll({ sub, forgetDevices: body.forgetDevices });
512
324
  * }
513
325
  * ```
514
326
  */
@@ -521,16 +333,12 @@ export declare class AuthService {
521
333
  * Current session (if called from authenticated context) is marked with isCurrent=true.
522
334
  *
523
335
  * 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)
336
+ * - **User viewing own sessions**: User views their active sessions (protected endpoint)
526
337
  *
527
338
  * 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
339
+ * - Uses authenticated user context for sub
340
+ * - Endpoint MUST be protected by authentication guards
532
341
  *
533
- * @param dto - Contains user sub
534
342
  * @returns Array of sessions with device info, auth method, and isCurrent flag
535
343
  * @throws {NAuthException} NOT_FOUND if user not found
536
344
  *
@@ -539,7 +347,7 @@ export declare class AuthService {
539
347
  * @UseGuards(AuthGuard)
540
348
  * @Get('sessions')
541
349
  * async getSessions(@CurrentUser() user: IUser) {
542
- * return this.authService.getUserSessions({ sub: user.sub });
350
+ * return this.authService.getUserSessions();
543
351
  * }
544
352
  * ```
545
353
  *
@@ -548,11 +356,43 @@ export declare class AuthService {
548
356
  * @UseGuards(AuthGuard, AdminGuard)
549
357
  * @Get('admin/users/:sub/sessions')
550
358
  * async adminGetSessions(@Param('sub') sub: string) {
551
- * return this.authService.getUserSessions({ sub });
359
+ * return this.adminAuthService.getUserSessions({ sub });
360
+ * }
361
+ * ```
362
+ */
363
+ getUserSessions(): Promise<GetUserSessionsResponseDTO>;
364
+ /**
365
+ * Get authentication audit history for current authenticated user
366
+ *
367
+ * Returns paginated audit trail of authentication events for the user:
368
+ * - Login attempts (success/failure)
369
+ * - Password changes
370
+ * - MFA setup/verification
371
+ * - Device trust events
372
+ * - Device information, location, risk factors
373
+ *
374
+ * Usage Patterns:
375
+ * - **User viewing own audit history**: User views their authentication history (protected endpoint)
376
+ *
377
+ * Security:
378
+ * - Uses authenticated user context for sub
379
+ * - Endpoint MUST be protected by authentication guards
380
+ *
381
+ * @param dto - Optional query parameters for filtering and pagination
382
+ * @returns Paginated audit history response
383
+ * @throws {NAuthException} FORBIDDEN if user not authenticated
384
+ * @throws {NAuthException} NOT_FOUND if user not found
385
+ *
386
+ * @example User viewing own audit history
387
+ * ```typescript
388
+ * @UseGuards(AuthGuard)
389
+ * @Get('audit/history')
390
+ * async getAuditHistory(@Query() query: GetUserAuthHistoryDTO) {
391
+ * return this.authService.getUserAuthHistory(query);
552
392
  * }
553
393
  * ```
554
394
  */
555
- getUserSessions(dto: GetUserSessionsDTO): Promise<GetUserSessionsResponseDTO>;
395
+ getUserAuthHistory(dto?: GetUserAuthHistoryDTO): Promise<GetUserAuthHistoryResponseDTO>;
556
396
  /**
557
397
  * Logout a specific session by ID
558
398
  *
@@ -561,17 +401,14 @@ export declare class AuthService {
561
401
  * Useful for "sign out from device" functionality in user dashboards.
562
402
  *
563
403
  * 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)
404
+ * - **User logging out own session**: User revokes specific session (protected endpoint)
566
405
  *
567
406
  * Security:
568
- * - Requires explicit sub parameter
407
+ * - Uses authenticated user context for sub
569
408
  * - 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
409
+ * - Endpoint MUST be protected by authentication guards
573
410
  *
574
- * @param dto - Contains sessionId and user sub
411
+ * @param dto - Contains sessionId
575
412
  * @returns Success status and whether it was the current session
576
413
  * @throws {NAuthException} NOT_FOUND if user not found
577
414
  * @throws {NAuthException} SESSION_NOT_FOUND if session not found
@@ -582,7 +419,7 @@ export declare class AuthService {
582
419
  * @UseGuards(AuthGuard)
583
420
  * @Delete('sessions/:sessionId')
584
421
  * async logoutSession(@CurrentUser() user: IUser, @Param('sessionId') sessionId: string) {
585
- * return this.authService.logoutSession({ sub: user.sub, sessionId });
422
+ * return this.authService.logoutSession({ sessionId });
586
423
  * }
587
424
  * ```
588
425
  *
@@ -591,7 +428,7 @@ export declare class AuthService {
591
428
  * @UseGuards(AuthGuard, AdminGuard)
592
429
  * @Delete('admin/users/:sub/sessions/:sessionId')
593
430
  * async adminRevokeSession(@Param('sub') sub: string, @Param('sessionId') sessionId: string) {
594
- * return this.authService.logoutSession({ sub, sessionId });
431
+ * return this.adminAuthService.revokeUserSession({ sub, sessionId });
595
432
  * }
596
433
  * ```
597
434
  */
@@ -603,69 +440,51 @@ export declare class AuthService {
603
440
  * checks password reuse policy, and updates the user's password hash and history.
604
441
  * Executes configured pre-change hooks if provided.
605
442
  *
606
- * @param sub - External user identifier (sub/UUID)
607
443
  * @param dto - ChangePasswordDTO containing old and new password
608
444
  * @returns void
609
445
  * @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
446
  *
611
447
  * @example
612
448
  * ```typescript
613
- * await authService.changePassword('user-uuid', {
449
+ * await authService.changePassword({
614
450
  * oldPassword: 'currentPass123!',
615
451
  * newPassword: 'newStr0ngPass!@#',
616
452
  * });
617
453
  * ```
618
454
  */
619
- changePassword(dto: ChangePasswordRequestDTO): Promise<ChangePasswordResponseDTO>;
455
+ changePassword(dto: ChangePasswordDTO): Promise<ChangePasswordResponseDTO>;
620
456
  /**
621
457
  * Update user profile attributes.
622
458
  *
623
459
  * Updates user fields (name, email, phone, username, metadata) and enforces unique constraints and verification rules.
624
460
  *
625
- * @param dto - UpdateUserAttributesRequestDTO containing sub and fields to update
461
+ * @param dto - UpdateUserAttributesDTO containing fields to update
626
462
  * @returns Updated user object
627
463
  * @throws {NAuthException} If user not found or unique constraint violated
628
464
  *
629
465
  * @example
630
- * await authService.updateUserAttributes({ sub: 'user-uuid', email: 'test@example.com' });
466
+ * await authService.updateUserAttributes({ email: 'test@example.com' });
631
467
  */
632
- updateUserAttributes(dto: UpdateUserAttributesRequestDTO): Promise<UserResponseDto>;
468
+ updateUserAttributes(dto: UpdateUserAttributesDTO): Promise<UserResponseDto>;
633
469
  /**
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.
470
+ * Get user for authentication context
638
471
  *
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)
472
+ * Loads user by sub (external identifier) with all fields needed for auth context.
473
+ * Computes hasPasswordHash from passwordHash, then removes passwordHash and other sensitive fields.
643
474
  *
644
- * Audit:
645
- * - Records EMAIL_VERIFIED or PHONE_VERIFIED audit events
646
- * - Includes performedBy from authenticated admin context
475
+ * This method is used by AuthHandler and AuthGuard to load authenticated users.
476
+ * It ensures consistent user object shape across platforms (core + NestJS).
647
477
  *
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
478
+ * @param sub - External user identifier (UUID)
479
+ * @returns User object with hasPasswordHash flag, without sensitive fields
480
+ * @throws {NAuthException} If user not found or account is inactive
651
481
  *
652
482
  * @example
653
483
  * ```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
- * });
484
+ * const user = await authService.getUserForAuthContext('user-uuid');
666
485
  * ```
667
486
  */
668
- updateVerifiedStatus(dto: UpdateVerifiedStatusRequestDTO): Promise<UserResponseDto>;
487
+ getUserForAuthContext(sub: string): Promise<IUser>;
669
488
  /**
670
489
  * Validate JWT access token
671
490
  *
@@ -702,170 +521,6 @@ export declare class AuthService {
702
521
  * ```
703
522
  */
704
523
  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 a verification code.
810
- *
811
- * NOTE:
812
- * - Links (when provided) should include the same verification code as a query parameter
813
- * (e.g., `...?code=123456`) to keep consumer apps code-only and consistent.
814
- *
815
- * Security:
816
- * - Verifies code 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
- * await authService.confirmAdminResetPassword({
829
- * identifier: 'user@example.com',
830
- * code: '123456',
831
- * newPassword: 'NewSecurePass123!'
832
- * });
833
- * ```
834
- */
835
- confirmAdminResetPassword(dto: ConfirmAdminResetPasswordDTO): Promise<ConfirmAdminResetPasswordResponseDTO>;
836
- /**
837
- * Admin-only: Reset a user's password by identifier.
838
- *
839
- * Allows administrators to reset a user's password using any identifier
840
- * (email, username, phone, or sub). Automatically revokes sessions and optionally
841
- * requires password change on next login using the existing challenge system.
842
- *
843
- * SECURITY: This is an admin-only operation. Ensure proper authorization
844
- * checks are in place before calling this method.
845
- *
846
- * @param dto - Admin reset password request
847
- * @returns Response with success status and session revocation count
848
- * @throws {NAuthException} If user not found, user has no password (social-only), or password validation fails
849
- *
850
- * @example
851
- * ```typescript
852
- * // Reset with force password change
853
- * const result = await authService.adminSetPassword({
854
- * identifier: 'user@example.com',
855
- * newPassword: 'NewSecurePassword123!',
856
- * mustChangePassword: true,
857
- * revokeSessions: true
858
- * });
859
- *
860
- * // Reset without forcing password change
861
- * const result = await authService.adminSetPassword({
862
- * identifier: 'a21b654c-2746-4168-acee-c175083a65cd',
863
- * newPassword: 'NewSecurePassword123!',
864
- * mustChangePassword: false
865
- * });
866
- * ```
867
- */
868
- adminSetPassword(dto: AdminSetPasswordDTO): Promise<AdminSetPasswordResponseDTO>;
869
524
  /**
870
525
  * Request a password reset code for an account.
871
526
  *
@@ -897,5 +552,6 @@ export declare class AuthService {
897
552
  * @throws {NAuthException} PASSWORD_RESET_CODE_INVALID | PASSWORD_RESET_CODE_EXPIRED | PASSWORD_RESET_MAX_ATTEMPTS
898
553
  */
899
554
  confirmForgotPassword(dto: ConfirmForgotPasswordDTO): Promise<ConfirmForgotPasswordResponseDTO>;
555
+ private getCurrentUserOrThrow;
900
556
  }
901
557
  //# sourceMappingURL=auth.service.d.ts.map