@nauth-toolkit/core 0.1.27 → 0.1.29
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.
- package/dist/dto/get-events-by-type.dto.d.ts.map +1 -1
- package/dist/dto/get-events-by-type.dto.js +55 -0
- package/dist/dto/get-events-by-type.dto.js.map +1 -1
- package/dist/dto/get-risk-assessment-history.dto.d.ts.map +1 -1
- package/dist/dto/get-risk-assessment-history.dto.js +35 -0
- package/dist/dto/get-risk-assessment-history.dto.js.map +1 -1
- package/dist/dto/get-suspicious-activity.dto.d.ts.map +1 -1
- package/dist/dto/get-suspicious-activity.dto.js +36 -0
- package/dist/dto/get-suspicious-activity.dto.js.map +1 -1
- package/dist/dto/get-user-auth-history.dto.d.ts.map +1 -1
- package/dist/dto/get-user-auth-history.dto.js +76 -0
- package/dist/dto/get-user-auth-history.dto.js.map +1 -1
- package/dist/dto/login.dto.d.ts.map +1 -1
- package/dist/dto/login.dto.js +15 -0
- package/dist/dto/login.dto.js.map +1 -1
- package/dist/dto/verify-mfa-code.dto.d.ts.map +1 -1
- package/dist/dto/verify-mfa-code.dto.js +15 -0
- package/dist/dto/verify-mfa-code.dto.js.map +1 -1
- package/dist/services/auth-audit.service.d.ts.map +1 -1
- package/dist/services/auth-audit.service.js +5 -0
- package/dist/services/auth-audit.service.js.map +1 -1
- package/dist/services/auth.service.d.ts.map +1 -1
- package/dist/services/auth.service.js +49 -0
- package/dist/services/auth.service.js.map +1 -1
- package/dist/services/email-verification.service.d.ts.map +1 -1
- package/dist/services/email-verification.service.js +5 -0
- package/dist/services/email-verification.service.js.map +1 -1
- package/dist/services/mfa.service.d.ts.map +1 -1
- package/dist/services/mfa.service.js +13 -0
- package/dist/services/mfa.service.js.map +1 -1
- package/dist/services/phone-verification.service.d.ts.map +1 -1
- package/dist/services/phone-verification.service.js +6 -0
- package/dist/services/phone-verification.service.js.map +1 -1
- package/dist/services/social-auth.service.d.ts.map +1 -1
- package/dist/services/social-auth.service.js +9 -0
- package/dist/services/social-auth.service.js.map +1 -1
- package/dist/utils/dto-validator.d.ts +113 -0
- package/dist/utils/dto-validator.d.ts.map +1 -0
- package/dist/utils/dto-validator.js +224 -0
- package/dist/utils/dto-validator.js.map +1 -0
- package/dist/utils/index.d.ts +1 -0
- package/dist/utils/index.d.ts.map +1 -1
- package/dist/utils/index.js +1 -0
- package/dist/utils/index.js.map +1 -1
- package/dist/utils/setup/init-services.d.ts.map +1 -1
- package/dist/utils/setup/init-services.js +43 -1
- package/dist/utils/setup/init-services.js.map +1 -1
- package/package.json +1 -1
|
@@ -37,8 +37,24 @@ exports.AuthService = void 0;
|
|
|
37
37
|
const auth_audit_event_type_enum_1 = require("../enums/auth-audit-event-type.enum");
|
|
38
38
|
const risk_factor_enum_1 = require("../enums/risk-factor.enum");
|
|
39
39
|
const context_storage_1 = require("../utils/context-storage");
|
|
40
|
+
const signup_dto_1 = require("../dto/signup.dto");
|
|
41
|
+
const admin_signup_dto_1 = require("../dto/admin-signup.dto");
|
|
42
|
+
const login_dto_1 = require("../dto/login.dto");
|
|
43
|
+
const change_password_request_dto_1 = require("../dto/change-password-request.dto");
|
|
44
|
+
const update_user_attributes_request_dto_1 = require("../dto/update-user-attributes-request.dto");
|
|
40
45
|
const user_response_dto_1 = require("../dto/user-response.dto");
|
|
41
46
|
const auth_challenge_dto_1 = require("../dto/auth-challenge.dto");
|
|
47
|
+
const respond_challenge_dto_1 = require("../dto/respond-challenge.dto");
|
|
48
|
+
const get_user_by_email_dto_1 = require("../dto/get-user-by-email.dto");
|
|
49
|
+
const get_user_by_id_dto_1 = require("../dto/get-user-by-id.dto");
|
|
50
|
+
const logout_dto_1 = require("../dto/logout.dto");
|
|
51
|
+
const logout_all_dto_1 = require("../dto/logout-all.dto");
|
|
52
|
+
const refresh_token_dto_1 = require("../dto/refresh-token.dto");
|
|
53
|
+
const resend_code_dto_1 = require("../dto/resend-code.dto");
|
|
54
|
+
const set_must_change_password_dto_1 = require("../dto/set-must-change-password.dto");
|
|
55
|
+
const admin_set_password_dto_1 = require("../dto/admin-set-password.dto");
|
|
56
|
+
const forgot_password_dto_1 = require("../dto/forgot-password.dto");
|
|
57
|
+
const confirm_forgot_password_dto_1 = require("../dto/confirm-forgot-password.dto");
|
|
42
58
|
const verify_email_dto_1 = require("../dto/verify-email.dto");
|
|
43
59
|
const verify_phone_dto_1 = require("../dto/verify-phone.dto");
|
|
44
60
|
const verify_phone_by_sub_dto_1 = require("../dto/verify-phone-by-sub.dto");
|
|
@@ -48,6 +64,7 @@ const mfa_method_enum_1 = require("../enums/mfa-method.enum");
|
|
|
48
64
|
const class_validator_1 = require("class-validator");
|
|
49
65
|
const crypto = __importStar(require("crypto"));
|
|
50
66
|
const password_generator_1 = require("../utils/password-generator");
|
|
67
|
+
const dto_validator_1 = require("../utils/dto-validator");
|
|
51
68
|
/**
|
|
52
69
|
* Dummy Argon2 hash for constant-time response
|
|
53
70
|
*
|
|
@@ -125,6 +142,8 @@ class AuthService {
|
|
|
125
142
|
* ```
|
|
126
143
|
*/
|
|
127
144
|
async signup(dto) {
|
|
145
|
+
// Ensure DTO is validated (supports direct usage without framework validation)
|
|
146
|
+
dto = await (0, dto_validator_1.ensureValidatedDto)(signup_dto_1.SignupDTO, dto);
|
|
128
147
|
// Get client info from request context (transparent!)
|
|
129
148
|
const clientInfo = this.clientInfoService.get();
|
|
130
149
|
this.logger?.log?.(`Signup attempt for email: ${dto.email}`);
|
|
@@ -330,6 +349,8 @@ class AuthService {
|
|
|
330
349
|
* ```
|
|
331
350
|
*/
|
|
332
351
|
async adminSignup(dto) {
|
|
352
|
+
// Ensure DTO is validated (supports direct usage without framework validation)
|
|
353
|
+
dto = await (0, dto_validator_1.ensureValidatedDto)(admin_signup_dto_1.AdminSignupDTO, dto);
|
|
333
354
|
// Get client info from request context (transparent!)
|
|
334
355
|
const clientInfo = this.clientInfoService.get();
|
|
335
356
|
this.logger?.log?.(`Admin signup attempt for email: ${dto.email}`);
|
|
@@ -504,6 +525,8 @@ class AuthService {
|
|
|
504
525
|
* ```
|
|
505
526
|
*/
|
|
506
527
|
async login(dto) {
|
|
528
|
+
// Ensure DTO is validated (supports direct usage without framework validation)
|
|
529
|
+
dto = await (0, dto_validator_1.ensureValidatedDto)(login_dto_1.LoginDTO, dto);
|
|
507
530
|
// Get client info from request context (transparent!)
|
|
508
531
|
const clientInfo = this.clientInfoService.get();
|
|
509
532
|
const fireAndForget = this.config.auditLogs?.fireAndForget === true;
|
|
@@ -1085,6 +1108,8 @@ class AuthService {
|
|
|
1085
1108
|
* ```
|
|
1086
1109
|
*/
|
|
1087
1110
|
async respondToChallenge(dto) {
|
|
1111
|
+
// Ensure DTO is validated (supports direct usage without framework validation)
|
|
1112
|
+
dto = await (0, dto_validator_1.ensureValidatedDto)(respond_challenge_dto_1.RespondChallengeDTO, dto);
|
|
1088
1113
|
const responseData = dto;
|
|
1089
1114
|
const { session, type } = responseData;
|
|
1090
1115
|
const requestTrace = `${Date.now()}-${Math.random().toString(36).substring(7)}`;
|
|
@@ -1871,6 +1896,8 @@ class AuthService {
|
|
|
1871
1896
|
* ```
|
|
1872
1897
|
*/
|
|
1873
1898
|
async resendCode(dto) {
|
|
1899
|
+
// Ensure DTO is validated (supports direct usage without framework validation)
|
|
1900
|
+
dto = await (0, dto_validator_1.ensureValidatedDto)(resend_code_dto_1.ResendCodeDTO, dto);
|
|
1874
1901
|
this.logger?.debug?.(`Resending verification code: session=${dto.session}`);
|
|
1875
1902
|
// Validate session (session must be valid to resend)
|
|
1876
1903
|
const challengeSession = await this.challengeService.validateSession(dto.session);
|
|
@@ -2133,6 +2160,8 @@ class AuthService {
|
|
|
2133
2160
|
* ```
|
|
2134
2161
|
*/
|
|
2135
2162
|
async refreshToken(dto) {
|
|
2163
|
+
// Ensure DTO is validated (supports direct usage without framework validation)
|
|
2164
|
+
dto = await (0, dto_validator_1.ensureValidatedDto)(refresh_token_dto_1.RefreshTokenDTO, dto);
|
|
2136
2165
|
const tokenHash = this.jwtService.hashToken(dto.refreshToken);
|
|
2137
2166
|
// ============================================================================
|
|
2138
2167
|
// CRITICAL SECURITY FIX #1 & #2: Distributed Lock + Reuse Detection
|
|
@@ -2360,6 +2389,8 @@ class AuthService {
|
|
|
2360
2389
|
* @throws {NAuthException} If session ID is not available in request context
|
|
2361
2390
|
*/
|
|
2362
2391
|
async logout(dto) {
|
|
2392
|
+
// Ensure DTO is validated (supports direct usage without framework validation)
|
|
2393
|
+
dto = await (0, dto_validator_1.ensureValidatedDto)(logout_dto_1.LogoutDTO, dto);
|
|
2363
2394
|
// Get sessionId from context (automatically extracted from JWT token)
|
|
2364
2395
|
const clientInfo = this.clientInfoService.get();
|
|
2365
2396
|
let sessionId = clientInfo.sessionId;
|
|
@@ -2488,6 +2519,8 @@ class AuthService {
|
|
|
2488
2519
|
* @returns Number of sessions revoked
|
|
2489
2520
|
*/
|
|
2490
2521
|
async logoutAll(dto) {
|
|
2522
|
+
// Ensure DTO is validated (supports direct usage without framework validation)
|
|
2523
|
+
dto = await (0, dto_validator_1.ensureValidatedDto)(logout_all_dto_1.LogoutAllDTO, dto);
|
|
2491
2524
|
// Get user by sub to get internal id
|
|
2492
2525
|
const user = (await this.userRepository.findOne({ where: { sub: dto.sub } }));
|
|
2493
2526
|
if (!user) {
|
|
@@ -2621,6 +2654,8 @@ class AuthService {
|
|
|
2621
2654
|
* ```
|
|
2622
2655
|
*/
|
|
2623
2656
|
async changePassword(dto) {
|
|
2657
|
+
// Ensure DTO is validated (supports direct usage without framework validation)
|
|
2658
|
+
dto = await (0, dto_validator_1.ensureValidatedDto)(change_password_request_dto_1.ChangePasswordRequestDTO, dto);
|
|
2624
2659
|
// Get user by sub
|
|
2625
2660
|
const user = (await this.userRepository.findOne({ where: { sub: dto.sub } }));
|
|
2626
2661
|
if (!user || !user.passwordHash) {
|
|
@@ -2669,6 +2704,8 @@ class AuthService {
|
|
|
2669
2704
|
* await authService.updateUserAttributes(sub, { email: 'test@example.com' });
|
|
2670
2705
|
*/
|
|
2671
2706
|
async updateUserAttributes(dto) {
|
|
2707
|
+
// Ensure DTO is validated (supports direct usage without framework validation)
|
|
2708
|
+
dto = await (0, dto_validator_1.ensureValidatedDto)(update_user_attributes_request_dto_1.UpdateUserAttributesRequestDTO, dto);
|
|
2672
2709
|
// Find user by sub (external identifier)
|
|
2673
2710
|
const user = (await this.userRepository.findOne({ where: { sub: dto.sub } }));
|
|
2674
2711
|
if (!user) {
|
|
@@ -3307,6 +3344,8 @@ class AuthService {
|
|
|
3307
3344
|
return safeUser;
|
|
3308
3345
|
}
|
|
3309
3346
|
async getUserById(dto) {
|
|
3347
|
+
// Ensure DTO is validated (supports direct usage without framework validation)
|
|
3348
|
+
dto = await (0, dto_validator_1.ensureValidatedDto)(get_user_by_id_dto_1.GetUserByIdDTO, dto);
|
|
3310
3349
|
const user = (await this.userRepository.findOne({ where: { sub: dto.sub } }));
|
|
3311
3350
|
return user ? user_response_dto_1.UserResponseDto.fromEntity(user) : null;
|
|
3312
3351
|
}
|
|
@@ -3324,6 +3363,8 @@ class AuthService {
|
|
|
3324
3363
|
* ```
|
|
3325
3364
|
*/
|
|
3326
3365
|
async getUserByEmail(dto) {
|
|
3366
|
+
// Ensure DTO is validated (supports direct usage without framework validation)
|
|
3367
|
+
dto = await (0, dto_validator_1.ensureValidatedDto)(get_user_by_email_dto_1.GetUserByEmailDTO, dto);
|
|
3327
3368
|
const where = dto.requireEmailVerified
|
|
3328
3369
|
? { email: dto.email, isEmailVerified: true }
|
|
3329
3370
|
: { email: dto.email };
|
|
@@ -3343,6 +3384,8 @@ class AuthService {
|
|
|
3343
3384
|
* await authService.setMustChangePassword('user-uuid-123');
|
|
3344
3385
|
*/
|
|
3345
3386
|
async setMustChangePassword(dto) {
|
|
3387
|
+
// Ensure DTO is validated (supports direct usage without framework validation)
|
|
3388
|
+
dto = await (0, dto_validator_1.ensureValidatedDto)(set_must_change_password_dto_1.SetMustChangePasswordDTO, dto);
|
|
3346
3389
|
const user = await this.userRepository.findOne({ where: { sub: dto.userId } });
|
|
3347
3390
|
if (!user) {
|
|
3348
3391
|
throw new nauth_exception_1.NAuthException(error_codes_enum_1.AuthErrorCode.NOT_FOUND, 'User not found');
|
|
@@ -3390,6 +3433,8 @@ class AuthService {
|
|
|
3390
3433
|
* ```
|
|
3391
3434
|
*/
|
|
3392
3435
|
async adminSetPassword(dto) {
|
|
3436
|
+
// Ensure DTO is validated (supports direct usage without framework validation)
|
|
3437
|
+
dto = await (0, dto_validator_1.ensureValidatedDto)(admin_set_password_dto_1.AdminSetPasswordDTO, dto);
|
|
3393
3438
|
this.logger?.log?.(`Admin password reset requested for identifier: ${dto.identifier}`);
|
|
3394
3439
|
this.logger?.debug?.(`Reset details: { identifier: ${dto.identifier}, mustChangePassword: ${dto.mustChangePassword ?? true}, revokeSessions: ${dto.revokeSessions ?? true} }`);
|
|
3395
3440
|
// ============================================================================
|
|
@@ -3464,6 +3509,8 @@ class AuthService {
|
|
|
3464
3509
|
* @returns Delivery metadata (masked destination) when available
|
|
3465
3510
|
*/
|
|
3466
3511
|
async forgotPassword(dto) {
|
|
3512
|
+
// Ensure DTO is validated (supports direct usage without framework validation)
|
|
3513
|
+
dto = await (0, dto_validator_1.ensureValidatedDto)(forgot_password_dto_1.ForgotPasswordDTO, dto);
|
|
3467
3514
|
const response = { success: true };
|
|
3468
3515
|
if (!this.passwordResetService) {
|
|
3469
3516
|
// Do not leak configuration details to clients.
|
|
@@ -3546,6 +3593,8 @@ class AuthService {
|
|
|
3546
3593
|
* @throws {NAuthException} PASSWORD_RESET_CODE_INVALID | PASSWORD_RESET_CODE_EXPIRED | PASSWORD_RESET_MAX_ATTEMPTS
|
|
3547
3594
|
*/
|
|
3548
3595
|
async confirmForgotPassword(dto) {
|
|
3596
|
+
// Ensure DTO is validated (supports direct usage without framework validation)
|
|
3597
|
+
dto = await (0, dto_validator_1.ensureValidatedDto)(confirm_forgot_password_dto_1.ConfirmForgotPasswordDTO, dto);
|
|
3549
3598
|
if (!this.passwordResetService) {
|
|
3550
3599
|
throw new nauth_exception_1.NAuthException(error_codes_enum_1.AuthErrorCode.SERVICE_UNAVAILABLE, 'Password reset is not available');
|
|
3551
3600
|
}
|