@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,156 +0,0 @@
1
- /**
2
- * CSRF Handler
3
- *
4
- * Generates and validates CSRF tokens for cookie-based authentication.
5
- *
6
- * **Platform-Agnostic:**
7
- * This handler operates purely on NAuthRequest interface.
8
- * Context is managed by the adapter, not this handler.
9
- *
10
- * **Lazy Validation:**
11
- * CSRF errors are stored in request attributes instead of thrown immediately.
12
- * This allows public routes and requireAuth() to decide how to handle them.
13
- */
14
-
15
- import { NAuthConfig, NAuthException, AuthErrorCode, NAuthLogger } from '../index';
16
- import { CsrfService } from '../services/csrf.service';
17
- import { NAuthRequest, NAuthResponse } from '../platform/interfaces';
18
-
19
- /** HTTP methods that don't require CSRF validation */
20
- const SAFE_METHODS = ['GET', 'HEAD', 'OPTIONS'];
21
-
22
- /**
23
- * CsrfHandler
24
- *
25
- * Handles CSRF token generation and validation for cookie-based authentication.
26
- */
27
- export class CsrfHandler {
28
- constructor(
29
- private readonly csrfService: CsrfService,
30
- private readonly config: NAuthConfig,
31
- private readonly logger?: NAuthLogger,
32
- ) {}
33
-
34
- /**
35
- * Handle request - generate or validate CSRF token
36
- *
37
- * Note: Context is managed by adapter. This handler assumes context is available.
38
- */
39
- public async handle(req: NAuthRequest, res: NAuthResponse, next: () => Promise<void> | void): Promise<void> {
40
- // Skip if token delivery is not cookies or hybrid
41
- const method = this.config.tokenDelivery?.method || 'json';
42
- if (method !== 'cookies' && method !== 'hybrid') {
43
- await next();
44
- return;
45
- }
46
-
47
- // Safe methods: Generate token if missing
48
- if (SAFE_METHODS.includes(req.method)) {
49
- await this.generateTokenIfMissing(req, res);
50
- await next();
51
- return;
52
- }
53
-
54
- // Skip public routes (CSRF not required)
55
- if (req.attributes.nauthPublic) {
56
- await next();
57
- return;
58
- }
59
-
60
- // Skip excluded paths
61
- const excludedPaths = this.config.security?.csrf?.excludedPaths || [];
62
- if (excludedPaths.some((p: string) => req.path.startsWith(p))) {
63
- await next();
64
- return;
65
- }
66
-
67
- // Validate CSRF token for unsafe methods (POST, PUT, DELETE, etc.)
68
- await this.validateToken(req);
69
-
70
- await next();
71
- }
72
-
73
- /**
74
- * Generate CSRF token if not present in cookies
75
- */
76
- private async generateTokenIfMissing(req: NAuthRequest, res: NAuthResponse): Promise<void> {
77
- const cookieName = this.csrfService.getCookieName();
78
- const existingToken = req.cookies[cookieName];
79
-
80
- if (existingToken) {
81
- // Token exists, clear any previous error state
82
- delete req.attributes.nauthCsrfError;
83
- return;
84
- }
85
-
86
- // Generate new token
87
- const token = this.csrfService.generateToken();
88
-
89
- // Build cookie options
90
- const cookieOptions = {
91
- httpOnly: true, // Prevents XSS access to token
92
- secure: this.config.tokenDelivery?.cookieOptions?.secure ?? true,
93
- sameSite: (this.config.tokenDelivery?.cookieOptions?.sameSite || 'strict') as 'strict' | 'lax' | 'none',
94
- domain: this.config.tokenDelivery?.cookieOptions?.domain,
95
- path: '/',
96
- ...this.csrfService.getCookieOptions(),
97
- };
98
-
99
- // Set cookie
100
- res.setCookie(cookieName, token, cookieOptions);
101
-
102
- // Also expose token in response header (since cookie is httpOnly)
103
- res.header(this.csrfService.getHeaderName(), token);
104
-
105
- this.logger?.debug?.('CSRF token generated and set');
106
- }
107
-
108
- /**
109
- * Validate CSRF token from request
110
- *
111
- * Uses lazy validation - stores error in attributes instead of throwing.
112
- * requireAuth() helper will throw if error exists.
113
- */
114
- private async validateToken(req: NAuthRequest): Promise<void> {
115
- const headerName = this.csrfService.getHeaderName();
116
- const cookieName = this.csrfService.getCookieName();
117
-
118
- // Get token from header or body
119
- let tokenFromRequest = req.getHeader(headerName);
120
- if (!tokenFromRequest && req.body) {
121
- // Check common body fields
122
- const body = req.body as Record<string, unknown>;
123
- tokenFromRequest = (body[headerName] || body['_csrf'] || body['csrfToken']) as string | undefined;
124
- }
125
-
126
- // Get token from cookie
127
- const cookieToken = req.cookies[cookieName];
128
-
129
- // Validate - store errors lazily
130
- if (!tokenFromRequest) {
131
- req.attributes.nauthCsrfError = new NAuthException(
132
- AuthErrorCode.CSRF_TOKEN_MISSING,
133
- `CSRF token required. Include ${headerName} header or _csrf/csrfToken in body with the value from ${cookieName} cookie.`,
134
- );
135
- return;
136
- }
137
-
138
- if (!cookieToken) {
139
- req.attributes.nauthCsrfError = new NAuthException(
140
- AuthErrorCode.CSRF_TOKEN_MISSING,
141
- 'CSRF cookie missing. Make a GET request first to obtain a token.',
142
- );
143
- return;
144
- }
145
-
146
- // Validate token matches
147
- const isValid = this.csrfService.validateToken(String(tokenFromRequest), cookieToken);
148
-
149
- if (!isValid) {
150
- req.attributes.nauthCsrfError = new NAuthException(AuthErrorCode.CSRF_TOKEN_INVALID, 'CSRF token mismatch.');
151
- return;
152
- }
153
-
154
- this.logger?.debug?.('CSRF token validated successfully');
155
- }
156
- }
@@ -1,118 +0,0 @@
1
- /**
2
- * Token Delivery Handler
3
- *
4
- * Handles response interception to deliver tokens via Cookies or JSON.
5
- */
6
-
7
- import {
8
- NAuthConfig,
9
- resolveDeliveryForRequest,
10
- getAccessTokenCookieName,
11
- getRefreshTokenCookieName,
12
- NAuthLogger,
13
- } from '../index';
14
- import { NAuthRequest, NAuthResponse, NAuthCookieOptions } from '../platform/interfaces';
15
-
16
- export class TokenDeliveryHandler {
17
- constructor(
18
- private config: NAuthConfig,
19
- private logger?: NAuthLogger,
20
- ) {}
21
-
22
- /**
23
- * Process the response body.
24
- * If it contains tokens, handle delivery and return sanitized body.
25
- * If not, return original body.
26
- */
27
- public async handleResponse(req: NAuthRequest, res: NAuthResponse, body: any): Promise<any> {
28
- // Check if this is an auth response
29
- if (body && typeof body === 'object' && body.accessToken && body.refreshToken) {
30
- const deliveryMode = this.resolveDeliveryMode(req);
31
-
32
- if (deliveryMode === 'cookies') {
33
- this.setTokenCookies(res, body);
34
-
35
- // Remove tokens and expiration fields from body
36
- // Expiration is managed by cookie maxAge, so these fields are not needed
37
- const sanitizedBody = { ...body };
38
- delete sanitizedBody.accessToken;
39
- delete sanitizedBody.refreshToken;
40
- delete sanitizedBody.accessTokenExpiresAt;
41
- delete sanitizedBody.refreshTokenExpiresAt;
42
-
43
- this.logger?.debug?.('Tokens delivered via cookies');
44
- return sanitizedBody;
45
- } else {
46
- this.logger?.debug?.('Tokens delivered via JSON');
47
- return body;
48
- }
49
- }
50
-
51
- return body;
52
- }
53
-
54
- private resolveDeliveryMode(req: NAuthRequest): 'json' | 'cookies' {
55
- const method = this.config.tokenDelivery?.method || 'json';
56
-
57
- // Route override
58
- if (req.attributes['nauthTokenDelivery']) {
59
- return req.attributes['nauthTokenDelivery'];
60
- }
61
-
62
- // Hybrid mode
63
- if (method === 'hybrid') {
64
- return resolveDeliveryForRequest(req.raw, this.config.tokenDelivery?.hybridPolicy);
65
- }
66
-
67
- return method === 'cookies' ? 'cookies' : 'json';
68
- }
69
-
70
- private setTokenCookies(res: NAuthResponse, body: any): void {
71
- const accessTokenCookieName = getAccessTokenCookieName(this.config);
72
- const refreshTokenCookieName = getRefreshTokenCookieName(this.config);
73
-
74
- const cookieOptions: NAuthCookieOptions = {
75
- httpOnly: true,
76
- secure: this.config.tokenDelivery?.cookieOptions?.secure ?? true,
77
- sameSite: (this.config.tokenDelivery?.cookieOptions?.sameSite || 'strict') as 'strict' | 'lax' | 'none',
78
- domain: this.config.tokenDelivery?.cookieOptions?.domain,
79
- path: '/',
80
- };
81
-
82
- const accessMaxAge = this.parseExpiry(this.config.jwt.accessToken.expiresIn) * 1000;
83
- const refreshMaxAge = this.parseExpiry(this.config.jwt.refreshToken.expiresIn) * 1000;
84
-
85
- res.setCookie(accessTokenCookieName, body.accessToken, {
86
- ...cookieOptions,
87
- maxAge: accessMaxAge,
88
- });
89
-
90
- res.setCookie(refreshTokenCookieName, body.refreshToken, {
91
- ...cookieOptions,
92
- maxAge: refreshMaxAge,
93
- });
94
- }
95
-
96
- private parseExpiry(expiry: string | number): number {
97
- if (typeof expiry === 'number') return expiry;
98
-
99
- const match = expiry.match(/^(\d+)([smhd])$/);
100
- if (!match) return 900; // Default 15m
101
-
102
- const value = parseInt(match[1], 10);
103
- const unit = match[2];
104
-
105
- switch (unit) {
106
- case 's':
107
- return value;
108
- case 'm':
109
- return value * 60;
110
- case 'h':
111
- return value * 3600;
112
- case 'd':
113
- return value * 86400;
114
- default:
115
- return 900;
116
- }
117
- }
118
- }
package/src/index.ts DELETED
@@ -1,118 +0,0 @@
1
- // ============================================================================
2
- // Public Services API
3
- // ============================================================================
4
- // These are the services that consumer applications should use directly.
5
- // For internal services needed by framework adapters, see ./internal.ts
6
-
7
- /**
8
- * Main authentication service
9
- * Handles signup, login, logout, password management, and user operations
10
- */
11
- export * from './services/auth.service';
12
-
13
- /**
14
- * Multi-Factor Authentication service
15
- * Manages MFA setup, verification, and device management
16
- */
17
- export * from './services/mfa.service';
18
-
19
- /**
20
- * Social authentication service
21
- * Complete API for OAuth authentication, social account linking, and management
22
- */
23
- export * from './services/social-auth.service';
24
-
25
- /**
26
- * Email verification service
27
- * Handles email verification codes and verification workflows
28
- */
29
- export * from './services/email-verification.service';
30
-
31
- /**
32
- * Phone verification service
33
- * Handles SMS verification codes and phone verification workflows
34
- */
35
- export * from './services/phone-verification.service';
36
-
37
- /**
38
- * Client information service
39
- * Provides access to request context (IP, user agent, device token, session ID)
40
- */
41
- export * from './services/client-info.service';
42
-
43
- /**
44
- * Authentication audit service
45
- * Logs and queries authentication events for security monitoring
46
- *
47
- * Note: Only query methods are available in the public API.
48
- * Event recording is handled internally by the framework.
49
- */
50
- export { AuthAuditService } from './services/auth-audit.service';
51
-
52
- /**
53
- * CSRF Protection Service
54
- */
55
- export { CsrfService } from './services/csrf.service';
56
-
57
- // ============================================================================
58
- // Internal Services - NOT EXPORTED
59
- // ============================================================================
60
- // Internal services are NOT exported from this file. They are only available
61
- // via '@nauth-toolkit/core/internal' for framework adapter development.
62
- //
63
- // Consumer applications should use the public services above (AuthService,
64
- // MFAService, etc.) which provide high-level APIs and automatically manage
65
- // internal services like password hashing, JWT tokens, and sessions.
66
-
67
- // ============================================================================
68
- // DTOs, Exceptions, Interfaces, Entities, Storage, and Utilities
69
- // ============================================================================
70
- // DTOs (Core only - feature DTOs moved to feature packages)
71
- export * from './dto';
72
-
73
- // Exceptions & Error Handling
74
- export { NAuthException, getHttpStatusForErrorCode } from './exceptions/nauth.exception';
75
- export { AuthErrorCode } from './enums/error-codes.enum';
76
- export { AuthAuditEventType } from './enums/auth-audit-event-type.enum';
77
- export { MFAMethod, MFADeviceMethod, MFAVerificationMethod, MFADeviceMethods } from './enums/mfa-method.enum';
78
-
79
- // Interfaces (All interfaces stay in core for contracts)
80
- export * from './interfaces';
81
- // Re-export ClientInfo interface with alias to avoid naming conflicts with decorators
82
- export type { ClientInfo as IClientInfo } from './interfaces/client-info.interface';
83
-
84
- // Zod Schemas (Runtime validation)
85
- export { authConfigSchema, type NAuthConfig as NAuthConfigFromSchema } from './schemas/auth-config.schema';
86
- // Keep interface export for backward compatibility
87
- export type { NAuthConfig } from './interfaces/config.interface';
88
-
89
- // Base Entity Classes (Database-agnostic entities)
90
- export * from './entities';
91
-
92
- // Storage
93
- export * from './storage';
94
-
95
- // Templates (Shared base templates)
96
- export * from './templates';
97
-
98
- // Utilities
99
- export * from './utils';
100
-
101
- // Validators
102
- export * from './validators/template.validator';
103
-
104
- // ============================================================================
105
- // Platform Agnostic Components (New Architecture)
106
- // ============================================================================
107
-
108
- // Bootstrap
109
- export * from './bootstrap';
110
-
111
- // Platform Interfaces
112
- export * from './platform/interfaces';
113
-
114
- // Adapters
115
- export * from './adapters';
116
-
117
- // Storage Factories
118
- export * from './adapters/storage.factory';
@@ -1,85 +0,0 @@
1
- /**
2
- * Client information extracted from HTTP request
3
- *
4
- * This interface represents metadata about the client making the request,
5
- * automatically extracted by nauth-toolkit interceptors.
6
- */
7
- export interface ClientInfo {
8
- /**
9
- * Client IP address (extracted from X-Forwarded-For, CF-Connecting-IP, etc.)
10
- * Automatically handles proxies and load balancers
11
- */
12
- ipAddress: string;
13
-
14
- /**
15
- * User agent string from the request
16
- */
17
- userAgent: string;
18
-
19
- /**
20
- * Device token for trusted device feature
21
- *
22
- * Extracted from:
23
- * - Cookie: `nauth_device_token` (web - httpOnly cookie)
24
- * - Header: `X-Device-Token` (mobile - from secure storage)
25
- *
26
- * This token is server-generated and stored securely by clients.
27
- * Used to identify trusted devices for MFA bypass.
28
- */
29
- deviceToken?: string;
30
-
31
- /**
32
- * Optional device name (if provided by client)
33
- */
34
- deviceName?: string;
35
-
36
- /**
37
- * Optional device type (if provided by client)
38
- */
39
- deviceType?: 'mobile' | 'desktop' | 'tablet';
40
-
41
- /**
42
- * Optional IP country (from geolocation, if available)
43
- */
44
- ipCountry?: string;
45
-
46
- /**
47
- * Optional IP city (from geolocation, if available)
48
- */
49
- ipCity?: string;
50
-
51
- /**
52
- * Optional IP latitude (from geolocation, if available)
53
- * Used for impossible travel detection
54
- */
55
- ipLatitude?: number;
56
-
57
- /**
58
- * Optional IP longitude (from geolocation, if available)
59
- * Used for impossible travel detection
60
- */
61
- ipLongitude?: number;
62
-
63
- /**
64
- * Platform extracted from user agent (e.g., "iOS", "Android", "Windows", "macOS")
65
- */
66
- platform?: string;
67
-
68
- /**
69
- * Browser extracted from user agent (e.g., "Chrome", "Safari", "Firefox")
70
- */
71
- browser?: string;
72
-
73
- /**
74
- * Current session ID (if available from authenticated request)
75
- * Extracted from JWT token payload after authentication
76
- */
77
- sessionId?: number;
78
-
79
- /**
80
- * Current user ID (if available from authenticated request)
81
- * Extracted from JWT token payload (sub claim) after authentication
82
- * Used to identify who performed an action (e.g., for audit trails)
83
- */
84
- userId?: number;
85
- }