@nauth-toolkit/core 0.1.0 → 0.1.5
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/LICENSE +90 -0
- package/README.md +9 -0
- package/package.json +8 -3
- package/jest.config.js +0 -15
- package/jest.setup.ts +0 -6
- package/src/adapters/database-columns.ts +0 -165
- package/src/adapters/express.adapter.ts +0 -385
- package/src/adapters/fastify.adapter.ts +0 -416
- package/src/adapters/index.ts +0 -16
- package/src/adapters/storage.factory.ts +0 -143
- package/src/bootstrap.ts +0 -374
- package/src/dto/auth-challenge.dto.ts +0 -231
- package/src/dto/auth-response.dto.ts +0 -253
- package/src/dto/challenge-response.dto.ts +0 -234
- package/src/dto/change-password-request.dto.ts +0 -50
- package/src/dto/change-password-response.dto.ts +0 -29
- package/src/dto/change-password.dto.ts +0 -57
- package/src/dto/error-response.dto.ts +0 -136
- package/src/dto/get-available-methods.dto.ts +0 -55
- package/src/dto/get-challenge-data-response.dto.ts +0 -28
- package/src/dto/get-challenge-data.dto.ts +0 -69
- package/src/dto/get-client-info.dto.ts +0 -104
- package/src/dto/get-device-token-response.dto.ts +0 -25
- package/src/dto/get-events-by-type.dto.ts +0 -76
- package/src/dto/get-ip-address-response.dto.ts +0 -24
- package/src/dto/get-mfa-status.dto.ts +0 -94
- package/src/dto/get-risk-assessment-history.dto.ts +0 -39
- package/src/dto/get-session-id-response.dto.ts +0 -25
- package/src/dto/get-setup-data-response.dto.ts +0 -31
- package/src/dto/get-setup-data.dto.ts +0 -75
- package/src/dto/get-suspicious-activity.dto.ts +0 -42
- package/src/dto/get-user-agent-response.dto.ts +0 -23
- package/src/dto/get-user-auth-history.dto.ts +0 -95
- package/src/dto/get-user-by-email.dto.ts +0 -61
- package/src/dto/get-user-by-id.dto.ts +0 -46
- package/src/dto/get-user-devices.dto.ts +0 -53
- package/src/dto/get-user-response.dto.ts +0 -17
- package/src/dto/has-provider.dto.ts +0 -56
- package/src/dto/index.ts +0 -57
- package/src/dto/is-trusted-device-response.dto.ts +0 -34
- package/src/dto/list-providers-response.dto.ts +0 -23
- package/src/dto/login.dto.ts +0 -95
- package/src/dto/logout-all-response.dto.ts +0 -24
- package/src/dto/logout-all.dto.ts +0 -65
- package/src/dto/logout-response.dto.ts +0 -25
- package/src/dto/logout.dto.ts +0 -64
- package/src/dto/refresh-token.dto.ts +0 -36
- package/src/dto/remove-devices.dto.ts +0 -85
- package/src/dto/resend-code-response.dto.ts +0 -32
- package/src/dto/resend-code.dto.ts +0 -51
- package/src/dto/reset-password.dto.ts +0 -115
- package/src/dto/respond-challenge.dto.ts +0 -272
- package/src/dto/set-mfa-exemption.dto.ts +0 -112
- package/src/dto/set-must-change-password-response.dto.ts +0 -27
- package/src/dto/set-must-change-password.dto.ts +0 -46
- package/src/dto/set-preferred-method.dto.ts +0 -80
- package/src/dto/setup-mfa.dto.ts +0 -98
- package/src/dto/signup.dto.ts +0 -174
- package/src/dto/social-auth.dto.ts +0 -422
- package/src/dto/trust-device-response.dto.ts +0 -30
- package/src/dto/trust-device.dto.ts +0 -9
- package/src/dto/update-user-attributes-request.dto.ts +0 -51
- package/src/dto/user-response.dto.ts +0 -138
- package/src/dto/user-update.dto.ts +0 -222
- package/src/dto/verify-email.dto.ts +0 -313
- package/src/dto/verify-mfa-code.dto.ts +0 -103
- package/src/dto/verify-phone-by-sub.dto.ts +0 -78
- package/src/dto/verify-phone.dto.ts +0 -245
- package/src/entities/auth-audit.entity.ts +0 -232
- package/src/entities/challenge-session.entity.ts +0 -116
- package/src/entities/index.ts +0 -29
- package/src/entities/login-attempt.entity.ts +0 -64
- package/src/entities/mfa-device.entity.ts +0 -151
- package/src/entities/rate-limit.entity.ts +0 -44
- package/src/entities/session.entity.ts +0 -180
- package/src/entities/social-account.entity.ts +0 -96
- package/src/entities/storage-lock.entity.ts +0 -39
- package/src/entities/trusted-device.entity.ts +0 -112
- package/src/entities/user.entity.ts +0 -243
- package/src/entities/verification-token.entity.ts +0 -141
- package/src/enums/auth-audit-event-type.enum.ts +0 -360
- package/src/enums/error-codes.enum.ts +0 -420
- package/src/enums/mfa-method.enum.ts +0 -97
- package/src/enums/risk-factor.enum.ts +0 -111
- package/src/exceptions/nauth.exception.ts +0 -231
- package/src/handlers/auth.handler.ts +0 -260
- package/src/handlers/client-info.handler.ts +0 -101
- package/src/handlers/csrf.handler.ts +0 -156
- package/src/handlers/token-delivery.handler.ts +0 -118
- package/src/index.ts +0 -118
- package/src/interfaces/client-info.interface.ts +0 -85
- package/src/interfaces/config.interface.ts +0 -2135
- package/src/interfaces/entities.interface.ts +0 -226
- package/src/interfaces/index.ts +0 -15
- package/src/interfaces/logger.interface.ts +0 -283
- package/src/interfaces/mfa-provider.interface.ts +0 -154
- package/src/interfaces/oauth.interface.ts +0 -148
- package/src/interfaces/provider.interface.ts +0 -47
- package/src/interfaces/social-auth-provider.interface.ts +0 -131
- package/src/interfaces/storage-adapter.interface.ts +0 -82
- package/src/interfaces/template.interface.ts +0 -510
- package/src/interfaces/token-verifier.interface.ts +0 -110
- package/src/internal.ts +0 -178
- package/src/platform/interfaces.ts +0 -299
- package/src/schemas/auth-config.schema.ts +0 -646
- package/src/services/adaptive-mfa-decision.service.spec.ts +0 -1058
- package/src/services/adaptive-mfa-decision.service.ts +0 -457
- package/src/services/auth-audit.service.spec.ts +0 -675
- package/src/services/auth-audit.service.ts +0 -558
- package/src/services/auth-challenge-helper.service.spec.ts +0 -3227
- package/src/services/auth-challenge-helper.service.ts +0 -825
- package/src/services/auth-flow-context-builder.service.ts +0 -520
- package/src/services/auth-flow-rules.ts +0 -202
- package/src/services/auth-flow-state-definitions.ts +0 -190
- package/src/services/auth-flow-state-machine.service.ts +0 -207
- package/src/services/auth-flow-state-machine.types.ts +0 -316
- package/src/services/auth.service.spec.ts +0 -4195
- package/src/services/auth.service.ts +0 -3727
- package/src/services/challenge.service.spec.ts +0 -1363
- package/src/services/challenge.service.ts +0 -696
- package/src/services/client-info.service.spec.ts +0 -572
- package/src/services/client-info.service.ts +0 -374
- package/src/services/csrf.service.ts +0 -54
- package/src/services/email-verification.service.spec.ts +0 -1229
- package/src/services/email-verification.service.ts +0 -578
- package/src/services/geo-location.service.spec.ts +0 -603
- package/src/services/geo-location.service.ts +0 -599
- package/src/services/index.ts +0 -13
- package/src/services/jwt.service.spec.ts +0 -882
- package/src/services/jwt.service.ts +0 -621
- package/src/services/mfa-base.service.spec.ts +0 -246
- package/src/services/mfa-base.service.ts +0 -611
- package/src/services/mfa.service.spec.ts +0 -693
- package/src/services/mfa.service.ts +0 -960
- package/src/services/password.service.spec.ts +0 -166
- package/src/services/password.service.ts +0 -309
- package/src/services/phone-verification.service.spec.ts +0 -1120
- package/src/services/phone-verification.service.ts +0 -751
- package/src/services/risk-detection.service.spec.ts +0 -1292
- package/src/services/risk-detection.service.ts +0 -1012
- package/src/services/risk-scoring.service.spec.ts +0 -204
- package/src/services/risk-scoring.service.ts +0 -131
- package/src/services/session.service.spec.ts +0 -1293
- package/src/services/session.service.ts +0 -803
- package/src/services/social-account.service.spec.ts +0 -725
- package/src/services/social-auth-base.service.spec.ts +0 -418
- package/src/services/social-auth-base.service.ts +0 -581
- package/src/services/social-auth.service.spec.ts +0 -238
- package/src/services/social-auth.service.ts +0 -436
- package/src/services/social-provider-registry.service.spec.ts +0 -238
- package/src/services/social-provider-registry.service.ts +0 -122
- package/src/services/trusted-device.service.spec.ts +0 -505
- package/src/services/trusted-device.service.ts +0 -339
- package/src/storage/account-lockout-storage.service.spec.ts +0 -310
- package/src/storage/account-lockout-storage.service.ts +0 -89
- package/src/storage/index.ts +0 -3
- package/src/storage/memory-storage.adapter.ts +0 -443
- package/src/storage/rate-limit-storage.service.spec.ts +0 -247
- package/src/storage/rate-limit-storage.service.ts +0 -38
- package/src/templates/html-template.engine.spec.ts +0 -161
- package/src/templates/html-template.engine.ts +0 -688
- package/src/templates/index.ts +0 -7
- package/src/utils/common-passwords.spec.ts +0 -230
- package/src/utils/common-passwords.ts +0 -170
- package/src/utils/context-storage.ts +0 -188
- package/src/utils/cookie-names.util.ts +0 -67
- package/src/utils/cookies.util.ts +0 -94
- package/src/utils/index.ts +0 -12
- package/src/utils/ip-extractor.spec.ts +0 -330
- package/src/utils/ip-extractor.ts +0 -220
- package/src/utils/nauth-logger.spec.ts +0 -388
- package/src/utils/nauth-logger.ts +0 -215
- package/src/utils/pii-redactor.spec.ts +0 -130
- package/src/utils/pii-redactor.ts +0 -288
- package/src/utils/setup/get-repositories.ts +0 -140
- package/src/utils/setup/init-services.ts +0 -422
- package/src/utils/setup/init-social.ts +0 -189
- package/src/utils/setup/init-storage.ts +0 -94
- package/src/utils/setup/register-mfa.ts +0 -165
- package/src/utils/setup/run-nauth-migrations.ts +0 -61
- package/src/utils/token-delivery-policy.ts +0 -38
- package/src/validators/template.validator.ts +0 -219
- package/tsconfig.json +0 -37
- package/tsconfig.lint.json +0 -6
|
@@ -1,31 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Response DTO for getting MFA setup data
|
|
3
|
-
*
|
|
4
|
-
* Used to return method-specific setup data during MFA enrollment.
|
|
5
|
-
* Structure varies by method (TOTP returns QR code, Passkey returns options, etc.).
|
|
6
|
-
*
|
|
7
|
-
* @example
|
|
8
|
-
* ```typescript
|
|
9
|
-
* const setupData = await mfaService.getSetupData({
|
|
10
|
-
* session: 'challenge-session-token',
|
|
11
|
-
* method: 'totp'
|
|
12
|
-
* });
|
|
13
|
-
* // Returns: { secret: '...', qrCode: '...', manualEntryKey: '...' }
|
|
14
|
-
* ```
|
|
15
|
-
*/
|
|
16
|
-
|
|
17
|
-
/**
|
|
18
|
-
* Response DTO for setup data
|
|
19
|
-
*/
|
|
20
|
-
export class GetSetupDataResponseDTO {
|
|
21
|
-
/**
|
|
22
|
-
* Provider-specific setup data
|
|
23
|
-
*
|
|
24
|
-
* Structure varies by method:
|
|
25
|
-
* - TOTP: { secret: string, qrCode: string, manualEntryKey: string }
|
|
26
|
-
* - SMS: { maskedPhone: string }
|
|
27
|
-
* - Email: { maskedEmail: string }
|
|
28
|
-
* - Passkey: WebAuthn registration options
|
|
29
|
-
*/
|
|
30
|
-
setupData!: Record<string, unknown>;
|
|
31
|
-
}
|
|
@@ -1,75 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* DTO for requesting MFA setup data
|
|
3
|
-
*
|
|
4
|
-
* Used to get method-specific setup information during MFA enrollment.
|
|
5
|
-
* For example, TOTP setup returns QR code and secret.
|
|
6
|
-
*
|
|
7
|
-
* Security:
|
|
8
|
-
* - Session token length limited (prevents DoS)
|
|
9
|
-
* - Method validated against enum (prevents injection)
|
|
10
|
-
*
|
|
11
|
-
* @example
|
|
12
|
-
* ```typescript
|
|
13
|
-
* const setupData = await authService.getSetupData({
|
|
14
|
-
* session: 'challenge-session-token',
|
|
15
|
-
* method: 'totp'
|
|
16
|
-
* });
|
|
17
|
-
* // Returns: { secret: '...', qrCode: '...' }
|
|
18
|
-
* ```
|
|
19
|
-
*/
|
|
20
|
-
|
|
21
|
-
import { IsEnum, IsUUID, IsOptional, IsObject } from 'class-validator';
|
|
22
|
-
import { Transform } from 'class-transformer';
|
|
23
|
-
import { MFAMethod } from '../enums/mfa-method.enum';
|
|
24
|
-
|
|
25
|
-
/**
|
|
26
|
-
* DTO for getting MFA setup data
|
|
27
|
-
*/
|
|
28
|
-
export class GetSetupDataDTO {
|
|
29
|
-
/**
|
|
30
|
-
* Challenge session token (UUID v4)
|
|
31
|
-
*
|
|
32
|
-
* Validation:
|
|
33
|
-
* - Must be a valid UUID v4 format
|
|
34
|
-
* - Generated using randomUUID() in challenge service
|
|
35
|
-
* - Matches DB constraint: varchar(255) but UUID format enforced
|
|
36
|
-
*
|
|
37
|
-
* Sanitization:
|
|
38
|
-
* - Trimmed
|
|
39
|
-
* - Lowercased for consistency
|
|
40
|
-
*
|
|
41
|
-
* @example "a21b654c-2746-4168-acee-c175083a65cd"
|
|
42
|
-
*/
|
|
43
|
-
@IsUUID('4', { message: 'Session token must be a valid UUID v4 format' })
|
|
44
|
-
@Transform(({ value }) => {
|
|
45
|
-
if (typeof value === 'string') {
|
|
46
|
-
return value.trim().toLowerCase();
|
|
47
|
-
}
|
|
48
|
-
return value;
|
|
49
|
-
})
|
|
50
|
-
session!: string;
|
|
51
|
-
|
|
52
|
-
/**
|
|
53
|
-
* MFA method to set up
|
|
54
|
-
*
|
|
55
|
-
* Validation:
|
|
56
|
-
* - Must be one of: sms, email, totp, passkey
|
|
57
|
-
*/
|
|
58
|
-
@IsEnum([MFAMethod.SMS, MFAMethod.EMAIL, MFAMethod.TOTP, MFAMethod.PASSKEY], {
|
|
59
|
-
message: 'Method must be one of: sms, email, totp, passkey',
|
|
60
|
-
})
|
|
61
|
-
method!: MFAMethod;
|
|
62
|
-
|
|
63
|
-
/**
|
|
64
|
-
* Optional provider-specific setup data
|
|
65
|
-
*
|
|
66
|
-
* Validation:
|
|
67
|
-
* - Must be an object if provided
|
|
68
|
-
* - Structure validated by MFA provider services
|
|
69
|
-
*
|
|
70
|
-
* @example { phoneNumber: '+1234567890' } for SMS
|
|
71
|
-
*/
|
|
72
|
-
@IsOptional()
|
|
73
|
-
@IsObject({ message: 'Setup data must be an object' })
|
|
74
|
-
setupData?: Record<string, unknown>;
|
|
75
|
-
}
|
|
@@ -1,42 +0,0 @@
|
|
|
1
|
-
import { IAuthAudit } from '../interfaces/entities.interface';
|
|
2
|
-
|
|
3
|
-
/**
|
|
4
|
-
* Request DTO for getting suspicious activity
|
|
5
|
-
*
|
|
6
|
-
* @example
|
|
7
|
-
* ```typescript
|
|
8
|
-
* // Get all suspicious activity
|
|
9
|
-
* const result = await auditService.getSuspiciousActivity({});
|
|
10
|
-
*
|
|
11
|
-
* // Get suspicious activity for specific user
|
|
12
|
-
* const result = await auditService.getSuspiciousActivity({
|
|
13
|
-
* userSub: 'user-uuid',
|
|
14
|
-
* limit: 50,
|
|
15
|
-
* });
|
|
16
|
-
* ```
|
|
17
|
-
*/
|
|
18
|
-
export class GetSuspiciousActivityDTO {
|
|
19
|
-
/**
|
|
20
|
-
* Optional user identifier to filter by specific user
|
|
21
|
-
*
|
|
22
|
-
* If not provided, returns suspicious activity for all users.
|
|
23
|
-
*/
|
|
24
|
-
userSub?: string;
|
|
25
|
-
|
|
26
|
-
/**
|
|
27
|
-
* Maximum number of records to return
|
|
28
|
-
*
|
|
29
|
-
* @default 100
|
|
30
|
-
*/
|
|
31
|
-
limit?: number;
|
|
32
|
-
}
|
|
33
|
-
|
|
34
|
-
/**
|
|
35
|
-
* Response DTO for suspicious activity
|
|
36
|
-
*/
|
|
37
|
-
export class GetSuspiciousActivityResponseDTO {
|
|
38
|
-
/**
|
|
39
|
-
* Array of suspicious audit events
|
|
40
|
-
*/
|
|
41
|
-
data!: IAuthAudit[];
|
|
42
|
-
}
|
|
@@ -1,23 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Response DTO for getting user agent
|
|
3
|
-
*
|
|
4
|
-
* Used to return just the user agent string from the current request context.
|
|
5
|
-
*
|
|
6
|
-
* @example
|
|
7
|
-
* ```typescript
|
|
8
|
-
* const result = await clientInfoService.getUserAgent();
|
|
9
|
-
* // Returns: { userAgent: 'Mozilla/5.0 (Windows NT 10.0; Win64; x64)...' }
|
|
10
|
-
* ```
|
|
11
|
-
*/
|
|
12
|
-
|
|
13
|
-
/**
|
|
14
|
-
* Response DTO for user agent
|
|
15
|
-
*/
|
|
16
|
-
export class GetUserAgentResponseDTO {
|
|
17
|
-
/**
|
|
18
|
-
* User agent string from the request
|
|
19
|
-
*
|
|
20
|
-
* Returns 'unknown' if called outside request context.
|
|
21
|
-
*/
|
|
22
|
-
userAgent!: string;
|
|
23
|
-
}
|
|
@@ -1,95 +0,0 @@
|
|
|
1
|
-
import { AuthAuditEventType } from '../enums/auth-audit-event-type.enum';
|
|
2
|
-
import { AuthAuditEventStatus } from '../entities/auth-audit.entity';
|
|
3
|
-
import { IAuthAudit } from '../interfaces/entities.interface';
|
|
4
|
-
|
|
5
|
-
/**
|
|
6
|
-
* Request DTO for getting user authentication history
|
|
7
|
-
*
|
|
8
|
-
* @example
|
|
9
|
-
* ```typescript
|
|
10
|
-
* const result = await auditService.getUserAuthHistory({
|
|
11
|
-
* userSub: 'user-uuid',
|
|
12
|
-
* page: 1,
|
|
13
|
-
* limit: 50,
|
|
14
|
-
* eventTypes: [AuthAuditEventType.LOGIN_SUCCESS],
|
|
15
|
-
* startDate: new Date('2025-01-01'),
|
|
16
|
-
* });
|
|
17
|
-
* ```
|
|
18
|
-
*/
|
|
19
|
-
export class GetUserAuthHistoryDTO {
|
|
20
|
-
/**
|
|
21
|
-
* External user identifier (UUID)
|
|
22
|
-
*
|
|
23
|
-
* The service will automatically resolve this to the internal userId
|
|
24
|
-
* for efficient database queries.
|
|
25
|
-
*/
|
|
26
|
-
userSub!: string;
|
|
27
|
-
|
|
28
|
-
/**
|
|
29
|
-
* Page number (1-indexed)
|
|
30
|
-
*
|
|
31
|
-
* @default 1
|
|
32
|
-
*/
|
|
33
|
-
page?: number;
|
|
34
|
-
|
|
35
|
-
/**
|
|
36
|
-
* Number of records per page
|
|
37
|
-
*
|
|
38
|
-
* @default 50
|
|
39
|
-
*/
|
|
40
|
-
limit?: number;
|
|
41
|
-
|
|
42
|
-
/**
|
|
43
|
-
* Filter events from this date onwards
|
|
44
|
-
*/
|
|
45
|
-
startDate?: Date;
|
|
46
|
-
|
|
47
|
-
/**
|
|
48
|
-
* Filter events up to this date
|
|
49
|
-
*/
|
|
50
|
-
endDate?: Date;
|
|
51
|
-
|
|
52
|
-
/**
|
|
53
|
-
* Filter by specific event types
|
|
54
|
-
*
|
|
55
|
-
* If provided, only events matching these types will be returned.
|
|
56
|
-
*/
|
|
57
|
-
eventTypes?: AuthAuditEventType[];
|
|
58
|
-
|
|
59
|
-
/**
|
|
60
|
-
* Filter by event status
|
|
61
|
-
*
|
|
62
|
-
* If provided, only events matching these statuses will be returned.
|
|
63
|
-
*/
|
|
64
|
-
eventStatus?: AuthAuditEventStatus[];
|
|
65
|
-
}
|
|
66
|
-
|
|
67
|
-
/**
|
|
68
|
-
* Response DTO for paginated user authentication history
|
|
69
|
-
*/
|
|
70
|
-
export class GetUserAuthHistoryResponseDTO {
|
|
71
|
-
/**
|
|
72
|
-
* Array of audit records
|
|
73
|
-
*/
|
|
74
|
-
data!: IAuthAudit[];
|
|
75
|
-
|
|
76
|
-
/**
|
|
77
|
-
* Total number of records matching the query
|
|
78
|
-
*/
|
|
79
|
-
total!: number;
|
|
80
|
-
|
|
81
|
-
/**
|
|
82
|
-
* Current page number
|
|
83
|
-
*/
|
|
84
|
-
page!: number;
|
|
85
|
-
|
|
86
|
-
/**
|
|
87
|
-
* Number of records per page
|
|
88
|
-
*/
|
|
89
|
-
limit!: number;
|
|
90
|
-
|
|
91
|
-
/**
|
|
92
|
-
* Total number of pages
|
|
93
|
-
*/
|
|
94
|
-
totalPages!: number;
|
|
95
|
-
}
|
|
@@ -1,61 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Get User By Email DTO
|
|
3
|
-
*
|
|
4
|
-
* Request DTO for retrieving a user by email address.
|
|
5
|
-
*
|
|
6
|
-
* Security:
|
|
7
|
-
* - Email format validated
|
|
8
|
-
* - Max length enforced
|
|
9
|
-
*
|
|
10
|
-
* @example
|
|
11
|
-
* ```typescript
|
|
12
|
-
* const user = await authService.getUserByEmail({
|
|
13
|
-
* email: 'user@example.com',
|
|
14
|
-
* requireEmailVerified: true
|
|
15
|
-
* });
|
|
16
|
-
* ```
|
|
17
|
-
*/
|
|
18
|
-
|
|
19
|
-
import { IsEmail, IsOptional, IsBoolean, MaxLength } from 'class-validator';
|
|
20
|
-
import { Transform } from 'class-transformer';
|
|
21
|
-
|
|
22
|
-
/**
|
|
23
|
-
* Request DTO for getting user by email
|
|
24
|
-
*/
|
|
25
|
-
export class GetUserByEmailDTO {
|
|
26
|
-
/**
|
|
27
|
-
* Email address to search for
|
|
28
|
-
*
|
|
29
|
-
* Validation:
|
|
30
|
-
* - Must be a valid email format
|
|
31
|
-
* - Max 255 characters (matches DB constraint)
|
|
32
|
-
*
|
|
33
|
-
* Sanitization:
|
|
34
|
-
* - Trimmed
|
|
35
|
-
* - Lowercased for consistency
|
|
36
|
-
*
|
|
37
|
-
* @example "user@example.com"
|
|
38
|
-
*/
|
|
39
|
-
@IsEmail({}, { message: 'Email must be a valid email format' })
|
|
40
|
-
@MaxLength(255, { message: 'Email must not exceed 255 characters' })
|
|
41
|
-
@Transform(({ value }) => {
|
|
42
|
-
if (typeof value === 'string') {
|
|
43
|
-
return value.trim().toLowerCase();
|
|
44
|
-
}
|
|
45
|
-
return value;
|
|
46
|
-
})
|
|
47
|
-
email!: string;
|
|
48
|
-
|
|
49
|
-
/**
|
|
50
|
-
* Only return user if email is verified
|
|
51
|
-
*
|
|
52
|
-
* Validation:
|
|
53
|
-
* - Must be a boolean if present
|
|
54
|
-
* - Default: false
|
|
55
|
-
*
|
|
56
|
-
* @example true
|
|
57
|
-
*/
|
|
58
|
-
@IsOptional()
|
|
59
|
-
@IsBoolean({ message: 'requireEmailVerified must be a boolean' })
|
|
60
|
-
requireEmailVerified?: boolean;
|
|
61
|
-
}
|
|
@@ -1,46 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Get User By ID DTO
|
|
3
|
-
*
|
|
4
|
-
* Request DTO for retrieving a user by their unique identifier (sub).
|
|
5
|
-
*
|
|
6
|
-
* Security:
|
|
7
|
-
* - UUID format validated
|
|
8
|
-
* - Prevents injection attacks
|
|
9
|
-
*
|
|
10
|
-
* @example
|
|
11
|
-
* ```typescript
|
|
12
|
-
* const user = await authService.getUserById({
|
|
13
|
-
* sub: 'a21b654c-2746-4168-acee-c175083a65cd'
|
|
14
|
-
* });
|
|
15
|
-
* ```
|
|
16
|
-
*/
|
|
17
|
-
|
|
18
|
-
import { IsUUID } from 'class-validator';
|
|
19
|
-
import { Transform } from 'class-transformer';
|
|
20
|
-
|
|
21
|
-
/**
|
|
22
|
-
* Request DTO for getting user by ID
|
|
23
|
-
*/
|
|
24
|
-
export class GetUserByIdDTO {
|
|
25
|
-
/**
|
|
26
|
-
* User's unique identifier (UUID v4)
|
|
27
|
-
*
|
|
28
|
-
* Validation:
|
|
29
|
-
* - Must be a valid UUID v4 format
|
|
30
|
-
* - Matches DB constraint: char(36) or uuid
|
|
31
|
-
*
|
|
32
|
-
* Sanitization:
|
|
33
|
-
* - Trimmed
|
|
34
|
-
* - Lowercased for consistency
|
|
35
|
-
*
|
|
36
|
-
* @example "a21b654c-2746-4168-acee-c175083a65cd"
|
|
37
|
-
*/
|
|
38
|
-
@IsUUID('4', { message: 'User sub must be a valid UUID v4 format' })
|
|
39
|
-
@Transform(({ value }) => {
|
|
40
|
-
if (typeof value === 'string') {
|
|
41
|
-
return value.trim().toLowerCase();
|
|
42
|
-
}
|
|
43
|
-
return value;
|
|
44
|
-
})
|
|
45
|
-
sub!: string;
|
|
46
|
-
}
|
|
@@ -1,53 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* DTO for getting user MFA devices
|
|
3
|
-
*
|
|
4
|
-
* Used to retrieve all MFA devices configured for a user.
|
|
5
|
-
*
|
|
6
|
-
* @example
|
|
7
|
-
* ```typescript
|
|
8
|
-
* const devices = await mfaService.getUserDevices({
|
|
9
|
-
* sub: 'user-uuid'
|
|
10
|
-
* });
|
|
11
|
-
* ```
|
|
12
|
-
*/
|
|
13
|
-
|
|
14
|
-
import { IsUUID } from 'class-validator';
|
|
15
|
-
import { Transform } from 'class-transformer';
|
|
16
|
-
import { IMFADevice } from '../interfaces/entities.interface';
|
|
17
|
-
|
|
18
|
-
/**
|
|
19
|
-
* DTO for getting user MFA devices
|
|
20
|
-
*/
|
|
21
|
-
export class GetUserDevicesDTO {
|
|
22
|
-
/**
|
|
23
|
-
* User's unique identifier (UUID v4)
|
|
24
|
-
*
|
|
25
|
-
* Validation:
|
|
26
|
-
* - Must be a valid UUID v4 format
|
|
27
|
-
* - Matches DB constraint: char(36) or uuid
|
|
28
|
-
*
|
|
29
|
-
* Sanitization:
|
|
30
|
-
* - Trimmed
|
|
31
|
-
* - Lowercased for consistency
|
|
32
|
-
*
|
|
33
|
-
* @example "a21b654c-2746-4168-acee-c175083a65cd"
|
|
34
|
-
*/
|
|
35
|
-
@IsUUID('4', { message: 'User sub must be a valid UUID v4 format' })
|
|
36
|
-
@Transform(({ value }) => {
|
|
37
|
-
if (typeof value === 'string') {
|
|
38
|
-
return value.trim().toLowerCase();
|
|
39
|
-
}
|
|
40
|
-
return value;
|
|
41
|
-
})
|
|
42
|
-
sub!: string;
|
|
43
|
-
}
|
|
44
|
-
|
|
45
|
-
/**
|
|
46
|
-
* Response DTO for user MFA devices
|
|
47
|
-
*/
|
|
48
|
-
export class GetUserDevicesResponseDTO {
|
|
49
|
-
/**
|
|
50
|
-
* Array of user's MFA devices
|
|
51
|
-
*/
|
|
52
|
-
devices!: IMFADevice[];
|
|
53
|
-
}
|
|
@@ -1,17 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Get User Response DTO
|
|
3
|
-
*
|
|
4
|
-
* Response DTO for user retrieval operations.
|
|
5
|
-
*
|
|
6
|
-
* Note: Methods like getUserById and getUserByEmail return UserResponseDto | null directly.
|
|
7
|
-
* This file exists for type consistency but UserResponseDto is used directly.
|
|
8
|
-
*
|
|
9
|
-
* @example
|
|
10
|
-
* ```typescript
|
|
11
|
-
* const user = await authService.getUserById({ sub: 'user-uuid' });
|
|
12
|
-
* // Returns: UserResponseDto | null
|
|
13
|
-
* ```
|
|
14
|
-
*/
|
|
15
|
-
|
|
16
|
-
// Re-export UserResponseDto for consistency
|
|
17
|
-
export { UserResponseDto as GetUserResponseDTO } from './user-response.dto';
|
|
@@ -1,56 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* DTO for checking if MFA provider is registered
|
|
3
|
-
*
|
|
4
|
-
* Used to check if a specific MFA provider is registered and available.
|
|
5
|
-
*
|
|
6
|
-
* @example
|
|
7
|
-
* ```typescript
|
|
8
|
-
* const hasTotp = await mfaService.hasProvider({
|
|
9
|
-
* methodName: 'totp'
|
|
10
|
-
* });
|
|
11
|
-
* ```
|
|
12
|
-
*/
|
|
13
|
-
|
|
14
|
-
import { IsEnum, IsString, MaxLength } from 'class-validator';
|
|
15
|
-
import { Transform } from 'class-transformer';
|
|
16
|
-
import { MFAMethod } from '../enums/mfa-method.enum';
|
|
17
|
-
|
|
18
|
-
/**
|
|
19
|
-
* DTO for checking if MFA provider is registered
|
|
20
|
-
*/
|
|
21
|
-
export class HasProviderDTO {
|
|
22
|
-
/**
|
|
23
|
-
* Provider method name
|
|
24
|
-
*
|
|
25
|
-
* Validation:
|
|
26
|
-
* - Must be one of: totp, sms, email, passkey
|
|
27
|
-
* - Max 50 characters
|
|
28
|
-
*
|
|
29
|
-
* Sanitization:
|
|
30
|
-
* - Trimmed and lowercased
|
|
31
|
-
*
|
|
32
|
-
* @example "totp"
|
|
33
|
-
*/
|
|
34
|
-
@IsString({ message: 'Method name must be a string' })
|
|
35
|
-
@IsEnum(MFAMethod, {
|
|
36
|
-
message: 'Method name must be one of: totp, sms, email, passkey',
|
|
37
|
-
})
|
|
38
|
-
@MaxLength(50, { message: 'Method name must not exceed 50 characters' })
|
|
39
|
-
@Transform(({ value }) => {
|
|
40
|
-
if (typeof value === 'string') {
|
|
41
|
-
return value.trim().toLowerCase();
|
|
42
|
-
}
|
|
43
|
-
return value;
|
|
44
|
-
})
|
|
45
|
-
methodName!: string;
|
|
46
|
-
}
|
|
47
|
-
|
|
48
|
-
/**
|
|
49
|
-
* Response DTO for has provider check
|
|
50
|
-
*/
|
|
51
|
-
export class HasProviderResponseDTO {
|
|
52
|
-
/**
|
|
53
|
-
* Whether provider is registered
|
|
54
|
-
*/
|
|
55
|
-
hasProvider!: boolean;
|
|
56
|
-
}
|
package/src/dto/index.ts
DELETED
|
@@ -1,57 +0,0 @@
|
|
|
1
|
-
// Core Auth DTOs
|
|
2
|
-
export * from './signup.dto';
|
|
3
|
-
export * from './login.dto';
|
|
4
|
-
export * from './change-password.dto';
|
|
5
|
-
export * from './change-password-request.dto';
|
|
6
|
-
export * from './change-password-response.dto';
|
|
7
|
-
export * from './user-response.dto';
|
|
8
|
-
export * from './user-update.dto';
|
|
9
|
-
export * from './update-user-attributes-request.dto';
|
|
10
|
-
export * from './verify-email.dto';
|
|
11
|
-
export * from './verify-phone.dto';
|
|
12
|
-
export * from './verify-phone-by-sub.dto';
|
|
13
|
-
export * from './reset-password.dto';
|
|
14
|
-
export * from './refresh-token.dto';
|
|
15
|
-
export * from './auth-response.dto';
|
|
16
|
-
export * from './auth-challenge.dto';
|
|
17
|
-
export * from './challenge-response.dto';
|
|
18
|
-
export * from './respond-challenge.dto';
|
|
19
|
-
export * from './get-setup-data.dto';
|
|
20
|
-
export * from './get-setup-data-response.dto';
|
|
21
|
-
export * from './get-challenge-data.dto';
|
|
22
|
-
export * from './get-challenge-data-response.dto';
|
|
23
|
-
export * from './get-available-methods.dto';
|
|
24
|
-
export * from './get-mfa-status.dto';
|
|
25
|
-
export * from './get-user-devices.dto';
|
|
26
|
-
export * from './has-provider.dto';
|
|
27
|
-
export * from './list-providers-response.dto';
|
|
28
|
-
export * from './remove-devices.dto';
|
|
29
|
-
export * from './set-mfa-exemption.dto';
|
|
30
|
-
export * from './set-preferred-method.dto';
|
|
31
|
-
export * from './setup-mfa.dto';
|
|
32
|
-
export * from './verify-mfa-code.dto';
|
|
33
|
-
export * from './get-client-info.dto';
|
|
34
|
-
export * from './get-ip-address-response.dto';
|
|
35
|
-
export * from './get-user-agent-response.dto';
|
|
36
|
-
export * from './get-device-token-response.dto';
|
|
37
|
-
export * from './get-session-id-response.dto';
|
|
38
|
-
export * from './resend-code.dto';
|
|
39
|
-
export * from './resend-code-response.dto';
|
|
40
|
-
export * from './get-user-by-email.dto';
|
|
41
|
-
export * from './get-user-by-id.dto';
|
|
42
|
-
export * from './get-user-response.dto';
|
|
43
|
-
export * from './logout.dto';
|
|
44
|
-
export * from './logout-response.dto';
|
|
45
|
-
export * from './logout-all.dto';
|
|
46
|
-
export * from './logout-all-response.dto';
|
|
47
|
-
export * from './set-must-change-password.dto';
|
|
48
|
-
export * from './set-must-change-password-response.dto';
|
|
49
|
-
// Note: trust-device.dto.ts removed - trustDevice() no longer takes parameters
|
|
50
|
-
export * from './trust-device-response.dto';
|
|
51
|
-
export * from './is-trusted-device-response.dto';
|
|
52
|
-
|
|
53
|
-
export * from './social-auth.dto';
|
|
54
|
-
|
|
55
|
-
// Note: Social and MFA DTOs moved to their respective packages
|
|
56
|
-
// - social-login.dto → @nauth-toolkit/social-*
|
|
57
|
-
// - mfa.dto → @nauth-toolkit/mfa-*
|
|
@@ -1,34 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Is Trusted Device Response DTO
|
|
3
|
-
*
|
|
4
|
-
* Response DTO for checking if the current device is trusted.
|
|
5
|
-
* No validators needed - this is generated internally by the library.
|
|
6
|
-
*
|
|
7
|
-
* Security:
|
|
8
|
-
* - Works in both cookies mode (reads from httpOnly cookie) and JSON mode (reads from X-Device-Token header)
|
|
9
|
-
* - Returns server-validated trusted status
|
|
10
|
-
* - Does not expose device token value for security
|
|
11
|
-
*
|
|
12
|
-
* @example
|
|
13
|
-
* ```typescript
|
|
14
|
-
* const result = await authService.isTrustedDevice();
|
|
15
|
-
* // Returns: { trusted: true }
|
|
16
|
-
* ```
|
|
17
|
-
*/
|
|
18
|
-
|
|
19
|
-
/**
|
|
20
|
-
* Response DTO for checking trusted device status
|
|
21
|
-
*/
|
|
22
|
-
export class IsTrustedDeviceResponseDTO {
|
|
23
|
-
/**
|
|
24
|
-
* Whether the current device is trusted
|
|
25
|
-
*
|
|
26
|
-
* True if the device has a valid trusted device token and trust has not expired.
|
|
27
|
-
* False if no device token exists, device token is invalid, or trust has expired.
|
|
28
|
-
*
|
|
29
|
-
* @example true
|
|
30
|
-
*/
|
|
31
|
-
trusted!: boolean;
|
|
32
|
-
}
|
|
33
|
-
|
|
34
|
-
|
|
@@ -1,23 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Response DTO for listing MFA providers
|
|
3
|
-
*
|
|
4
|
-
* Used to return all registered MFA provider method names.
|
|
5
|
-
*
|
|
6
|
-
* @example
|
|
7
|
-
* ```typescript
|
|
8
|
-
* const providers = await mfaService.listProviders();
|
|
9
|
-
* // Returns: { providers: ['totp', 'sms', 'passkey'] }
|
|
10
|
-
* ```
|
|
11
|
-
*/
|
|
12
|
-
|
|
13
|
-
/**
|
|
14
|
-
* Response DTO for listing providers
|
|
15
|
-
*/
|
|
16
|
-
export class ListProvidersResponseDTO {
|
|
17
|
-
/**
|
|
18
|
-
* Array of registered provider method names
|
|
19
|
-
*
|
|
20
|
-
* @example ['totp', 'sms', 'passkey']
|
|
21
|
-
*/
|
|
22
|
-
providers!: string[];
|
|
23
|
-
}
|