@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.
Files changed (184) hide show
  1. package/LICENSE +90 -0
  2. package/README.md +9 -0
  3. package/package.json +8 -3
  4. package/jest.config.js +0 -15
  5. package/jest.setup.ts +0 -6
  6. package/src/adapters/database-columns.ts +0 -165
  7. package/src/adapters/express.adapter.ts +0 -385
  8. package/src/adapters/fastify.adapter.ts +0 -416
  9. package/src/adapters/index.ts +0 -16
  10. package/src/adapters/storage.factory.ts +0 -143
  11. package/src/bootstrap.ts +0 -374
  12. package/src/dto/auth-challenge.dto.ts +0 -231
  13. package/src/dto/auth-response.dto.ts +0 -253
  14. package/src/dto/challenge-response.dto.ts +0 -234
  15. package/src/dto/change-password-request.dto.ts +0 -50
  16. package/src/dto/change-password-response.dto.ts +0 -29
  17. package/src/dto/change-password.dto.ts +0 -57
  18. package/src/dto/error-response.dto.ts +0 -136
  19. package/src/dto/get-available-methods.dto.ts +0 -55
  20. package/src/dto/get-challenge-data-response.dto.ts +0 -28
  21. package/src/dto/get-challenge-data.dto.ts +0 -69
  22. package/src/dto/get-client-info.dto.ts +0 -104
  23. package/src/dto/get-device-token-response.dto.ts +0 -25
  24. package/src/dto/get-events-by-type.dto.ts +0 -76
  25. package/src/dto/get-ip-address-response.dto.ts +0 -24
  26. package/src/dto/get-mfa-status.dto.ts +0 -94
  27. package/src/dto/get-risk-assessment-history.dto.ts +0 -39
  28. package/src/dto/get-session-id-response.dto.ts +0 -25
  29. package/src/dto/get-setup-data-response.dto.ts +0 -31
  30. package/src/dto/get-setup-data.dto.ts +0 -75
  31. package/src/dto/get-suspicious-activity.dto.ts +0 -42
  32. package/src/dto/get-user-agent-response.dto.ts +0 -23
  33. package/src/dto/get-user-auth-history.dto.ts +0 -95
  34. package/src/dto/get-user-by-email.dto.ts +0 -61
  35. package/src/dto/get-user-by-id.dto.ts +0 -46
  36. package/src/dto/get-user-devices.dto.ts +0 -53
  37. package/src/dto/get-user-response.dto.ts +0 -17
  38. package/src/dto/has-provider.dto.ts +0 -56
  39. package/src/dto/index.ts +0 -57
  40. package/src/dto/is-trusted-device-response.dto.ts +0 -34
  41. package/src/dto/list-providers-response.dto.ts +0 -23
  42. package/src/dto/login.dto.ts +0 -95
  43. package/src/dto/logout-all-response.dto.ts +0 -24
  44. package/src/dto/logout-all.dto.ts +0 -65
  45. package/src/dto/logout-response.dto.ts +0 -25
  46. package/src/dto/logout.dto.ts +0 -64
  47. package/src/dto/refresh-token.dto.ts +0 -36
  48. package/src/dto/remove-devices.dto.ts +0 -85
  49. package/src/dto/resend-code-response.dto.ts +0 -32
  50. package/src/dto/resend-code.dto.ts +0 -51
  51. package/src/dto/reset-password.dto.ts +0 -115
  52. package/src/dto/respond-challenge.dto.ts +0 -272
  53. package/src/dto/set-mfa-exemption.dto.ts +0 -112
  54. package/src/dto/set-must-change-password-response.dto.ts +0 -27
  55. package/src/dto/set-must-change-password.dto.ts +0 -46
  56. package/src/dto/set-preferred-method.dto.ts +0 -80
  57. package/src/dto/setup-mfa.dto.ts +0 -98
  58. package/src/dto/signup.dto.ts +0 -174
  59. package/src/dto/social-auth.dto.ts +0 -422
  60. package/src/dto/trust-device-response.dto.ts +0 -30
  61. package/src/dto/trust-device.dto.ts +0 -9
  62. package/src/dto/update-user-attributes-request.dto.ts +0 -51
  63. package/src/dto/user-response.dto.ts +0 -138
  64. package/src/dto/user-update.dto.ts +0 -222
  65. package/src/dto/verify-email.dto.ts +0 -313
  66. package/src/dto/verify-mfa-code.dto.ts +0 -103
  67. package/src/dto/verify-phone-by-sub.dto.ts +0 -78
  68. package/src/dto/verify-phone.dto.ts +0 -245
  69. package/src/entities/auth-audit.entity.ts +0 -232
  70. package/src/entities/challenge-session.entity.ts +0 -116
  71. package/src/entities/index.ts +0 -29
  72. package/src/entities/login-attempt.entity.ts +0 -64
  73. package/src/entities/mfa-device.entity.ts +0 -151
  74. package/src/entities/rate-limit.entity.ts +0 -44
  75. package/src/entities/session.entity.ts +0 -180
  76. package/src/entities/social-account.entity.ts +0 -96
  77. package/src/entities/storage-lock.entity.ts +0 -39
  78. package/src/entities/trusted-device.entity.ts +0 -112
  79. package/src/entities/user.entity.ts +0 -243
  80. package/src/entities/verification-token.entity.ts +0 -141
  81. package/src/enums/auth-audit-event-type.enum.ts +0 -360
  82. package/src/enums/error-codes.enum.ts +0 -420
  83. package/src/enums/mfa-method.enum.ts +0 -97
  84. package/src/enums/risk-factor.enum.ts +0 -111
  85. package/src/exceptions/nauth.exception.ts +0 -231
  86. package/src/handlers/auth.handler.ts +0 -260
  87. package/src/handlers/client-info.handler.ts +0 -101
  88. package/src/handlers/csrf.handler.ts +0 -156
  89. package/src/handlers/token-delivery.handler.ts +0 -118
  90. package/src/index.ts +0 -118
  91. package/src/interfaces/client-info.interface.ts +0 -85
  92. package/src/interfaces/config.interface.ts +0 -2135
  93. package/src/interfaces/entities.interface.ts +0 -226
  94. package/src/interfaces/index.ts +0 -15
  95. package/src/interfaces/logger.interface.ts +0 -283
  96. package/src/interfaces/mfa-provider.interface.ts +0 -154
  97. package/src/interfaces/oauth.interface.ts +0 -148
  98. package/src/interfaces/provider.interface.ts +0 -47
  99. package/src/interfaces/social-auth-provider.interface.ts +0 -131
  100. package/src/interfaces/storage-adapter.interface.ts +0 -82
  101. package/src/interfaces/template.interface.ts +0 -510
  102. package/src/interfaces/token-verifier.interface.ts +0 -110
  103. package/src/internal.ts +0 -178
  104. package/src/platform/interfaces.ts +0 -299
  105. package/src/schemas/auth-config.schema.ts +0 -646
  106. package/src/services/adaptive-mfa-decision.service.spec.ts +0 -1058
  107. package/src/services/adaptive-mfa-decision.service.ts +0 -457
  108. package/src/services/auth-audit.service.spec.ts +0 -675
  109. package/src/services/auth-audit.service.ts +0 -558
  110. package/src/services/auth-challenge-helper.service.spec.ts +0 -3227
  111. package/src/services/auth-challenge-helper.service.ts +0 -825
  112. package/src/services/auth-flow-context-builder.service.ts +0 -520
  113. package/src/services/auth-flow-rules.ts +0 -202
  114. package/src/services/auth-flow-state-definitions.ts +0 -190
  115. package/src/services/auth-flow-state-machine.service.ts +0 -207
  116. package/src/services/auth-flow-state-machine.types.ts +0 -316
  117. package/src/services/auth.service.spec.ts +0 -4195
  118. package/src/services/auth.service.ts +0 -3727
  119. package/src/services/challenge.service.spec.ts +0 -1363
  120. package/src/services/challenge.service.ts +0 -696
  121. package/src/services/client-info.service.spec.ts +0 -572
  122. package/src/services/client-info.service.ts +0 -374
  123. package/src/services/csrf.service.ts +0 -54
  124. package/src/services/email-verification.service.spec.ts +0 -1229
  125. package/src/services/email-verification.service.ts +0 -578
  126. package/src/services/geo-location.service.spec.ts +0 -603
  127. package/src/services/geo-location.service.ts +0 -599
  128. package/src/services/index.ts +0 -13
  129. package/src/services/jwt.service.spec.ts +0 -882
  130. package/src/services/jwt.service.ts +0 -621
  131. package/src/services/mfa-base.service.spec.ts +0 -246
  132. package/src/services/mfa-base.service.ts +0 -611
  133. package/src/services/mfa.service.spec.ts +0 -693
  134. package/src/services/mfa.service.ts +0 -960
  135. package/src/services/password.service.spec.ts +0 -166
  136. package/src/services/password.service.ts +0 -309
  137. package/src/services/phone-verification.service.spec.ts +0 -1120
  138. package/src/services/phone-verification.service.ts +0 -751
  139. package/src/services/risk-detection.service.spec.ts +0 -1292
  140. package/src/services/risk-detection.service.ts +0 -1012
  141. package/src/services/risk-scoring.service.spec.ts +0 -204
  142. package/src/services/risk-scoring.service.ts +0 -131
  143. package/src/services/session.service.spec.ts +0 -1293
  144. package/src/services/session.service.ts +0 -803
  145. package/src/services/social-account.service.spec.ts +0 -725
  146. package/src/services/social-auth-base.service.spec.ts +0 -418
  147. package/src/services/social-auth-base.service.ts +0 -581
  148. package/src/services/social-auth.service.spec.ts +0 -238
  149. package/src/services/social-auth.service.ts +0 -436
  150. package/src/services/social-provider-registry.service.spec.ts +0 -238
  151. package/src/services/social-provider-registry.service.ts +0 -122
  152. package/src/services/trusted-device.service.spec.ts +0 -505
  153. package/src/services/trusted-device.service.ts +0 -339
  154. package/src/storage/account-lockout-storage.service.spec.ts +0 -310
  155. package/src/storage/account-lockout-storage.service.ts +0 -89
  156. package/src/storage/index.ts +0 -3
  157. package/src/storage/memory-storage.adapter.ts +0 -443
  158. package/src/storage/rate-limit-storage.service.spec.ts +0 -247
  159. package/src/storage/rate-limit-storage.service.ts +0 -38
  160. package/src/templates/html-template.engine.spec.ts +0 -161
  161. package/src/templates/html-template.engine.ts +0 -688
  162. package/src/templates/index.ts +0 -7
  163. package/src/utils/common-passwords.spec.ts +0 -230
  164. package/src/utils/common-passwords.ts +0 -170
  165. package/src/utils/context-storage.ts +0 -188
  166. package/src/utils/cookie-names.util.ts +0 -67
  167. package/src/utils/cookies.util.ts +0 -94
  168. package/src/utils/index.ts +0 -12
  169. package/src/utils/ip-extractor.spec.ts +0 -330
  170. package/src/utils/ip-extractor.ts +0 -220
  171. package/src/utils/nauth-logger.spec.ts +0 -388
  172. package/src/utils/nauth-logger.ts +0 -215
  173. package/src/utils/pii-redactor.spec.ts +0 -130
  174. package/src/utils/pii-redactor.ts +0 -288
  175. package/src/utils/setup/get-repositories.ts +0 -140
  176. package/src/utils/setup/init-services.ts +0 -422
  177. package/src/utils/setup/init-social.ts +0 -189
  178. package/src/utils/setup/init-storage.ts +0 -94
  179. package/src/utils/setup/register-mfa.ts +0 -165
  180. package/src/utils/setup/run-nauth-migrations.ts +0 -61
  181. package/src/utils/token-delivery-policy.ts +0 -38
  182. package/src/validators/template.validator.ts +0 -219
  183. package/tsconfig.json +0 -37
  184. package/tsconfig.lint.json +0 -6
@@ -1,136 +0,0 @@
1
- import { IsNumber, IsString, IsOptional, IsObject, MaxLength, Matches } from 'class-validator';
2
-
3
- /**
4
- * Standard error response format for all nauth-toolkit errors
5
- *
6
- * Provides structured error responses with error codes, metadata,
7
- * and consistent formatting across all authentication operations.
8
- *
9
- * @example
10
- * ```typescript
11
- * // Rate limit error response
12
- * {
13
- * statusCode: 429,
14
- * code: 'RATE_LIMIT_SMS',
15
- * message: 'Too many verification SMS sent. Please try again later.',
16
- * details: {
17
- * retryAfter: 3600,
18
- * currentCount: 4,
19
- * maxAttempts: 3,
20
- * resetAt: '2025-11-01T02:43:03.132Z'
21
- * },
22
- * timestamp: '2025-10-31T01:43:03.132Z',
23
- * path: '/auth/verify-phone/send'
24
- * }
25
- * ```
26
- */
27
- export class ErrorResponseDTO {
28
- /**
29
- * HTTP status code
30
- *
31
- * Validation:
32
- * - Must be a number
33
- * - Valid HTTP status code range (100-599)
34
- *
35
- * @example 400
36
- */
37
- @IsNumber({}, { message: 'Status code must be a number' })
38
- statusCode!: number;
39
-
40
- /**
41
- * Error code for programmatic handling
42
- *
43
- * Allows frontend to identify specific errors without parsing messages.
44
- * Useful for i18n, specific error handling, and analytics.
45
- *
46
- * Validation:
47
- * - Must be a string
48
- * - Max 100 characters (prevents oversized error codes)
49
- * - Alphanumeric and underscores only
50
- *
51
- * @example "RATE_LIMIT_SMS"
52
- */
53
- @IsString({ message: 'Error code must be a string' })
54
- @MaxLength(100, { message: 'Error code must not exceed 100 characters' })
55
- @Matches(/^[A-Z0-9_]+$/, {
56
- message: 'Error code can only contain uppercase letters, numbers, and underscores',
57
- })
58
- code!: string;
59
-
60
- /**
61
- * Human-readable error message
62
- *
63
- * Should be clear and actionable. Can be displayed directly to users
64
- * or used as fallback when error code doesn't have a translation.
65
- *
66
- * Validation:
67
- * - Must be a string
68
- * - Max 500 characters (prevents oversized messages)
69
- *
70
- * @example "Too many verification SMS sent. Please try again later."
71
- */
72
- @IsString({ message: 'Error message must be a string' })
73
- @MaxLength(500, { message: 'Error message must not exceed 500 characters' })
74
- message!: string;
75
-
76
- /**
77
- * Additional error details (optional)
78
- *
79
- * Provides context-specific metadata that can be used for:
80
- * - Retry logic (retryAfter, resetAt)
81
- * - Validation errors (field names, validation rules)
82
- * - Rate limiting (current count, max attempts)
83
- * - Debugging (correlation IDs, request IDs)
84
- *
85
- * Validation:
86
- * - Must be an object if present
87
- *
88
- * @example
89
- * ```typescript
90
- * {
91
- * retryAfter: 3600,
92
- * currentCount: 4,
93
- * maxAttempts: 3,
94
- * resetAt: '2025-11-01T02:43:03.132Z'
95
- * }
96
- * ```
97
- */
98
- @IsOptional()
99
- @IsObject({ message: 'Error details must be an object' })
100
- details?: Record<string, unknown>;
101
-
102
- /**
103
- * Timestamp when error occurred
104
- *
105
- * ISO 8601 format for consistent timezone handling.
106
- *
107
- * Validation:
108
- * - Must be a string
109
- * - Must match ISO 8601 format
110
- * - Max 30 characters (ISO 8601 timestamp length)
111
- *
112
- * @example "2025-10-31T01:43:03.132Z"
113
- */
114
- @IsString({ message: 'Timestamp must be a string' })
115
- @MaxLength(30, { message: 'Timestamp must not exceed 30 characters' })
116
- @Matches(/^\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}(\.\d{3})?Z$/, {
117
- message: 'Timestamp must be in ISO 8601 format',
118
- })
119
- timestamp!: string;
120
-
121
- /**
122
- * Request path where error occurred
123
- *
124
- * Useful for debugging and error tracking.
125
- *
126
- * Validation:
127
- * - Must be a string if present
128
- * - Max 500 characters (prevents oversized paths)
129
- *
130
- * @example "/auth/verify-phone/send"
131
- */
132
- @IsOptional()
133
- @IsString({ message: 'Path must be a string' })
134
- @MaxLength(500, { message: 'Path must not exceed 500 characters' })
135
- path?: string;
136
- }
@@ -1,55 +0,0 @@
1
- /**
2
- * DTO for getting available MFA methods
3
- *
4
- * Used to retrieve all registered and allowed MFA methods that can be set up for a user.
5
- *
6
- * @example
7
- * ```typescript
8
- * const methods = await mfaService.getAvailableMethods({
9
- * sub: 'user-uuid'
10
- * });
11
- * // Returns: ['totp', 'sms', 'passkey']
12
- * ```
13
- */
14
-
15
- import { IsUUID } from 'class-validator';
16
- import { Transform } from 'class-transformer';
17
-
18
- /**
19
- * DTO for getting available MFA methods
20
- */
21
- export class GetAvailableMethodsDTO {
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 available MFA methods
47
- */
48
- export class GetAvailableMethodsResponseDTO {
49
- /**
50
- * Array of available method names
51
- *
52
- * @example ['totp', 'sms', 'passkey', 'email']
53
- */
54
- availableMethods!: string[];
55
- }
@@ -1,28 +0,0 @@
1
- /**
2
- * Response DTO for getting MFA challenge data
3
- *
4
- * Used to return method-specific challenge data during MFA verification.
5
- * Currently only passkey method requires challenge data (WebAuthn options).
6
- *
7
- * @example
8
- * ```typescript
9
- * const challengeData = await mfaService.getChallengeData({
10
- * session: 'challenge-session-token',
11
- * method: 'passkey'
12
- * });
13
- * // Returns: { publicKey: { challenge: '...', ... } }
14
- * ```
15
- */
16
-
17
- /**
18
- * Response DTO for challenge data
19
- */
20
- export class GetChallengeDataResponseDTO {
21
- /**
22
- * Provider-specific challenge data
23
- *
24
- * For passkey: WebAuthn public key options
25
- * Structure: { publicKey: { challenge: string, allowCredentials: [...], ... } }
26
- */
27
- challengeData!: Record<string, unknown>;
28
- }
@@ -1,69 +0,0 @@
1
- /**
2
- * DTO for requesting MFA challenge data
3
- *
4
- * Used to get method-specific challenge information during MFA verification.
5
- * Currently only passkey method requires challenge data (WebAuthn options).
6
- *
7
- * Security:
8
- * - Session token length limited (prevents DoS)
9
- * - Method validated against enum (prevents injection)
10
- *
11
- * @example
12
- * ```typescript
13
- * const challengeData = await authService.getChallengeData({
14
- * session: 'challenge-session-token',
15
- * method: 'passkey'
16
- * });
17
- * // Returns: { publicKey: { challenge: '...', ... } }
18
- * ```
19
- */
20
-
21
- import { IsEnum, IsUUID } from 'class-validator';
22
- import { Transform } from 'class-transformer';
23
-
24
- /**
25
- * MFA method enum for challenge data
26
- * Currently only passkey requires challenge data
27
- */
28
- export enum MFAChallengeMethod {
29
- PASSKEY = 'passkey',
30
- }
31
-
32
- /**
33
- * DTO for getting MFA challenge data
34
- */
35
- export class GetChallengeDataDTO {
36
- /**
37
- * Challenge session token (UUID v4)
38
- *
39
- * Validation:
40
- * - Must be a valid UUID v4 format
41
- * - Generated using randomUUID() in challenge service
42
- * - Matches DB constraint: varchar(255) but UUID format enforced
43
- *
44
- * Sanitization:
45
- * - Trimmed
46
- * - Lowercased for consistency
47
- *
48
- * @example "a21b654c-2746-4168-acee-c175083a65cd"
49
- */
50
- @IsUUID('4', { message: 'Session token must be a valid UUID v4 format' })
51
- @Transform(({ value }) => {
52
- if (typeof value === 'string') {
53
- return value.trim().toLowerCase();
54
- }
55
- return value;
56
- })
57
- session!: string;
58
-
59
- /**
60
- * MFA method requiring challenge data
61
- *
62
- * Validation:
63
- * - Must be 'passkey' (only method that needs challenge data)
64
- */
65
- @IsEnum(MFAChallengeMethod, {
66
- message: 'Method must be: passkey',
67
- })
68
- method!: MFAChallengeMethod;
69
- }
@@ -1,104 +0,0 @@
1
- /**
2
- * Response DTO for getting client information
3
- *
4
- * Used to return client information extracted from the current request context.
5
- * Includes IP address, user agent, device info, and optional geolocation data.
6
- *
7
- * @example
8
- * ```typescript
9
- * const result = await clientInfoService.get();
10
- * // Returns: { ipAddress: '192.168.1.100', userAgent: 'Mozilla/5.0...', ... }
11
- * ```
12
- */
13
-
14
- import { ClientInfo } from '../interfaces/client-info.interface';
15
-
16
- /**
17
- * Response DTO for client information
18
- */
19
- export class GetClientInfoResponseDTO implements ClientInfo {
20
- /**
21
- * Client IP address
22
- *
23
- * Extracted from X-Forwarded-For, CF-Connecting-IP, etc.
24
- * Automatically handles proxies and load balancers.
25
- * Returns 'unknown' if called outside request context.
26
- */
27
- ipAddress!: string;
28
-
29
- /**
30
- * User agent string from the request
31
- *
32
- * Returns 'unknown' if called outside request context.
33
- */
34
- userAgent!: string;
35
-
36
- /**
37
- * Device token for trusted device feature
38
- *
39
- * Extracted from cookie (nauth_device_token) or header (X-Device-Token).
40
- * Optional - only present if device token exists.
41
- */
42
- deviceToken?: string;
43
-
44
- /**
45
- * Optional device name (if provided by client)
46
- */
47
- deviceName?: string;
48
-
49
- /**
50
- * Optional device type (if provided by client)
51
- */
52
- deviceType?: 'mobile' | 'desktop' | 'tablet';
53
-
54
- /**
55
- * Optional IP country (from geolocation, if available)
56
- */
57
- ipCountry?: string;
58
-
59
- /**
60
- * Optional IP city (from geolocation, if available)
61
- */
62
- ipCity?: string;
63
-
64
- /**
65
- * Optional IP latitude (from geolocation, if available)
66
- * Used for impossible travel detection
67
- */
68
- ipLatitude?: number;
69
-
70
- /**
71
- * Optional IP longitude (from geolocation, if available)
72
- * Used for impossible travel detection
73
- */
74
- ipLongitude?: number;
75
-
76
- /**
77
- * Platform extracted from user agent
78
- *
79
- * Examples: "iOS", "Android", "Windows", "macOS"
80
- */
81
- platform?: string;
82
-
83
- /**
84
- * Browser extracted from user agent
85
- *
86
- * Examples: "Chrome", "Safari", "Firefox"
87
- */
88
- browser?: string;
89
-
90
- /**
91
- * Current session ID (if available from authenticated request)
92
- *
93
- * Extracted from JWT token payload after authentication.
94
- */
95
- sessionId?: number;
96
-
97
- /**
98
- * Current user ID (if available from authenticated request)
99
- *
100
- * Extracted from JWT token payload (sub claim) after authentication.
101
- * Used to identify who performed an action (e.g., for audit trails).
102
- */
103
- userId?: number;
104
- }
@@ -1,25 +0,0 @@
1
- /**
2
- * Response DTO for getting device token
3
- *
4
- * Used to return just the device token from the current request context.
5
- * Device token is used for trusted device feature.
6
- *
7
- * @example
8
- * ```typescript
9
- * const result = await clientInfoService.getDeviceToken();
10
- * // Returns: { deviceToken: 'device-token-123' } or { deviceToken: undefined }
11
- * ```
12
- */
13
-
14
- /**
15
- * Response DTO for device token
16
- */
17
- export class GetDeviceTokenResponseDTO {
18
- /**
19
- * Device token for trusted device feature
20
- *
21
- * Extracted from cookie (nauth_device_token) or header (X-Device-Token).
22
- * Optional - undefined if not present.
23
- */
24
- deviceToken?: string;
25
- }
@@ -1,76 +0,0 @@
1
- import { AuthAuditEventType } from '../enums/auth-audit-event-type.enum';
2
- import { IAuthAudit } from '../interfaces/entities.interface';
3
-
4
- /**
5
- * Request DTO for getting events by type
6
- *
7
- * @example
8
- * ```typescript
9
- * const result = await auditService.getEventsByType({
10
- * eventType: AuthAuditEventType.SUSPICIOUS_ACTIVITY,
11
- * page: 1,
12
- * limit: 100,
13
- * startDate: new Date('2025-01-01'),
14
- * });
15
- * ```
16
- */
17
- export class GetEventsByTypeDTO {
18
- /**
19
- * Event type to filter by
20
- */
21
- eventType!: AuthAuditEventType;
22
-
23
- /**
24
- * Page number (1-indexed)
25
- *
26
- * @default 1
27
- */
28
- page?: number;
29
-
30
- /**
31
- * Number of records per page
32
- *
33
- * @default 50
34
- */
35
- limit?: number;
36
-
37
- /**
38
- * Filter events from this date onwards
39
- */
40
- startDate?: Date;
41
-
42
- /**
43
- * Filter events up to this date
44
- */
45
- endDate?: Date;
46
- }
47
-
48
- /**
49
- * Response DTO for paginated events by type
50
- */
51
- export class GetEventsByTypeResponseDTO {
52
- /**
53
- * Array of audit records
54
- */
55
- data!: IAuthAudit[];
56
-
57
- /**
58
- * Total number of records matching the query
59
- */
60
- total!: number;
61
-
62
- /**
63
- * Current page number
64
- */
65
- page!: number;
66
-
67
- /**
68
- * Number of records per page
69
- */
70
- limit!: number;
71
-
72
- /**
73
- * Total number of pages
74
- */
75
- totalPages!: number;
76
- }
@@ -1,24 +0,0 @@
1
- /**
2
- * Response DTO for getting IP address
3
- *
4
- * Used to return just the IP address from the current request context.
5
- *
6
- * @example
7
- * ```typescript
8
- * const result = await clientInfoService.getIpAddress();
9
- * // Returns: { ipAddress: '192.168.1.100' }
10
- * ```
11
- */
12
-
13
- /**
14
- * Response DTO for IP address
15
- */
16
- export class GetIpAddressResponseDTO {
17
- /**
18
- * Client IP address
19
- *
20
- * Extracted from X-Forwarded-For, CF-Connecting-IP, etc.
21
- * Returns 'unknown' if called outside request context.
22
- */
23
- ipAddress!: string;
24
- }
@@ -1,94 +0,0 @@
1
- /**
2
- * DTO for getting MFA status
3
- *
4
- * Used to retrieve comprehensive MFA status for a user including enabled status,
5
- * configured methods, available methods, backup codes, and exemption information.
6
- *
7
- * @example
8
- * ```typescript
9
- * const status = await mfaService.getMFAStatus({
10
- * sub: 'user-uuid'
11
- * });
12
- * ```
13
- */
14
-
15
- import { IsUUID } from 'class-validator';
16
- import { Transform } from 'class-transformer';
17
- import { MFADeviceMethod } from '../enums/mfa-method.enum';
18
-
19
- /**
20
- * DTO for getting MFA status
21
- */
22
- export class GetMFAStatusDTO {
23
- /**
24
- * User's unique identifier (UUID v4)
25
- *
26
- * Validation:
27
- * - Must be a valid UUID v4 format
28
- * - Matches DB constraint: char(36) or uuid
29
- *
30
- * Sanitization:
31
- * - Trimmed
32
- * - Lowercased for consistency
33
- *
34
- * @example "a21b654c-2746-4168-acee-c175083a65cd"
35
- */
36
- @IsUUID('4', { message: 'User sub must be a valid UUID v4 format' })
37
- @Transform(({ value }) => {
38
- if (typeof value === 'string') {
39
- return value.trim().toLowerCase();
40
- }
41
- return value;
42
- })
43
- sub!: string;
44
- }
45
-
46
- /**
47
- * Response DTO for MFA status
48
- */
49
- export class GetMFAStatusResponseDTO {
50
- /**
51
- * Whether MFA is enabled for the user
52
- */
53
- enabled!: boolean;
54
-
55
- /**
56
- * Whether MFA is required (enabled and has configured devices)
57
- */
58
- required!: boolean;
59
-
60
- /**
61
- * Array of configured MFA device methods
62
- */
63
- configuredMethods!: Array<MFADeviceMethod>;
64
-
65
- /**
66
- * Array of available MFA methods that can be set up
67
- */
68
- availableMethods!: Array<string>;
69
-
70
- /**
71
- * Whether user has backup codes
72
- */
73
- hasBackupCodes!: boolean;
74
-
75
- /**
76
- * Preferred MFA method (if set)
77
- */
78
- preferredMethod?: MFADeviceMethod;
79
-
80
- /**
81
- * Whether user is exempt from MFA requirements
82
- */
83
- mfaExempt!: boolean;
84
-
85
- /**
86
- * Reason for MFA exemption (if exempt)
87
- */
88
- mfaExemptReason!: string | null;
89
-
90
- /**
91
- * Date when MFA exemption was granted (if exempt)
92
- */
93
- mfaExemptGrantedAt!: Date | null;
94
- }
@@ -1,39 +0,0 @@
1
- import { IAuthAudit } from '../interfaces/entities.interface';
2
-
3
- /**
4
- * Request DTO for getting risk assessment history
5
- *
6
- * Returns events where risk assessment was performed (ADAPTIVE_MFA_RISK_ASSESSED,
7
- * ADAPTIVE_MFA_TRIGGERED, ADAPTIVE_MFA_BYPASSED).
8
- *
9
- * @example
10
- * ```typescript
11
- * const result = await auditService.getRiskAssessmentHistory({
12
- * userSub: 'user-uuid',
13
- * limit: 50,
14
- * });
15
- * ```
16
- */
17
- export class GetRiskAssessmentHistoryDTO {
18
- /**
19
- * User identifier
20
- */
21
- userSub!: string;
22
-
23
- /**
24
- * Maximum number of records to return
25
- *
26
- * @default 100
27
- */
28
- limit?: number;
29
- }
30
-
31
- /**
32
- * Response DTO for risk assessment history
33
- */
34
- export class GetRiskAssessmentHistoryResponseDTO {
35
- /**
36
- * Array of risk assessment audit events
37
- */
38
- data!: IAuthAudit[];
39
- }
@@ -1,25 +0,0 @@
1
- /**
2
- * Response DTO for getting session ID
3
- *
4
- * Used to return just the session ID from the current request context.
5
- * Session ID is extracted from JWT token payload after authentication.
6
- *
7
- * @example
8
- * ```typescript
9
- * const result = await clientInfoService.getSessionId();
10
- * // Returns: { sessionId: 123 } or { sessionId: undefined }
11
- * ```
12
- */
13
-
14
- /**
15
- * Response DTO for session ID
16
- */
17
- export class GetSessionIdResponseDTO {
18
- /**
19
- * Current session ID (if available from authenticated request)
20
- *
21
- * Extracted from JWT token payload after authentication.
22
- * Optional - undefined if not available.
23
- */
24
- sessionId?: number;
25
- }