@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,510 +0,0 @@
1
- /**
2
- * Email Template System Interfaces
3
- *
4
- * Provides flexible template system for email notifications with support for:
5
- * - HTML templates with placeholder tokens ({{variable}})
6
- * - Built-in and custom variables
7
- * - Multiple template types (verification, password reset, etc.)
8
- */
9
-
10
- /**
11
- * Template Variables
12
- *
13
- * Variables that can be used in email templates.
14
- * All variables are optional as not all templates use all variables.
15
- */
16
- export interface TemplateVariables {
17
- // User information
18
- appName?: string;
19
- userName?: string;
20
- firstName?: string;
21
- lastName?: string;
22
- userEmail?: string;
23
-
24
- // Verification and authentication
25
- code?: string;
26
- link?: string;
27
- expiryMinutes?: number;
28
-
29
- // Security alerts
30
- reason?: string;
31
- durationMinutes?: number;
32
- deviceName?: string;
33
- deviceType?: string;
34
- ipAddress?: string;
35
- location?: string;
36
-
37
- // Timestamps
38
- timestamp?: string;
39
- currentYear?: number;
40
-
41
- // Company branding (custom variables)
42
- companyName?: string;
43
- companyAddress?: string;
44
- brandColor?: string;
45
- logoUrl?: string;
46
- dashboardUrl?: string;
47
- supportEmail?: string;
48
- footerDisclaimer?: string;
49
-
50
- // Allow any custom variables
51
- [key: string]: string | number | boolean | undefined;
52
- }
53
-
54
- /**
55
- * Email Template
56
- *
57
- * Defines the structure of an email template with subject and content.
58
- * Both subject and content support placeholder variables.
59
- */
60
- export interface EmailTemplate {
61
- /**
62
- * Email subject line (supports {{variables}})
63
- */
64
- subject: string;
65
-
66
- /**
67
- * HTML content of the email (supports {{variables}})
68
- */
69
- html: string;
70
-
71
- /**
72
- * Optional plain text version (supports {{variables}})
73
- * Falls back to stripping HTML tags if not provided
74
- */
75
- text?: string;
76
- }
77
-
78
- /**
79
- * Template Type
80
- *
81
- * Enum of available email template types
82
- */
83
- export enum TemplateType {
84
- VERIFICATION = 'verification',
85
- PASSWORD_RESET = 'passwordReset',
86
- WELCOME = 'welcome',
87
- ACCOUNT_LOCKOUT = 'accountLockout',
88
- NEW_DEVICE = 'newDevice',
89
- PASSWORD_CHANGED = 'passwordChanged',
90
- EMAIL_CHANGED = 'emailChanged',
91
- MFA_ENABLED = 'mfaEnabled',
92
- }
93
-
94
- /**
95
- * Template Source
96
- *
97
- * Defines how template content can be provided - as a string or file path
98
- */
99
- export interface TemplateSource {
100
- /**
101
- * Template content as a string
102
- */
103
- content?: string;
104
-
105
- /**
106
- * Path to template file (relative or absolute)
107
- * Supports .hbs, .html, .txt, etc.
108
- */
109
- filePath?: string;
110
- }
111
-
112
- /**
113
- * Template Files
114
- *
115
- * Defines template files for subject, HTML, and text content.
116
- * Used for file-based template registration.
117
- *
118
- * @example
119
- * ```typescript
120
- * const templateFiles: TemplateFiles = {
121
- * subject: { filePath: './templates/welcome.subject.hbs' },
122
- * html: { filePath: './templates/welcome.html.hbs' },
123
- * text: { filePath: './templates/welcome.text.hbs' }
124
- * };
125
- * ```
126
- */
127
- export interface TemplateFiles {
128
- /**
129
- * Subject line template source
130
- */
131
- subject: TemplateSource;
132
-
133
- /**
134
- * HTML content template source
135
- */
136
- html: TemplateSource;
137
-
138
- /**
139
- * Plain text content template source (optional)
140
- */
141
- text?: TemplateSource;
142
- }
143
-
144
- /**
145
- * Template Engine Interface
146
- *
147
- * Contract for template engines that can render email templates with variables.
148
- * Implementations can support HTML, MJML, Handlebars, or other template formats.
149
- *
150
- * @example
151
- * ```typescript
152
- * const engine = new HandlebarsTemplateEngine();
153
- * const result = await engine.render(
154
- * TemplateType.VERIFICATION,
155
- * { userName: 'John', code: '123456' }
156
- * );
157
- * logger.debug('Subject:', result.subject); // "Verify your email - My App"
158
- * logger.debug('HTML generated'); // HTML with variables replaced
159
- * ```
160
- */
161
- export interface TemplateEngine {
162
- /**
163
- * Render a template with the provided variables
164
- *
165
- * @param type - Type of template to render
166
- * @param variables - Variables to inject into the template
167
- * @returns Rendered email template with subject and content
168
- *
169
- * @throws {Error} If template type is not found
170
- *
171
- * @example
172
- * ```typescript
173
- * const result = await engine.render(
174
- * TemplateType.VERIFICATION,
175
- * {
176
- * userName: 'John Doe',
177
- * code: '123456',
178
- * expiryMinutes: 60
179
- * }
180
- * );
181
- * ```
182
- */
183
- render(type: TemplateType | string, variables: TemplateVariables): Promise<EmailTemplate>;
184
-
185
- /**
186
- * Register a custom template from inline strings
187
- *
188
- * Allows overriding default templates or adding new ones.
189
- *
190
- * @param type - Template type identifier
191
- * @param template - Template definition with inline content
192
- *
193
- * @example
194
- * ```typescript
195
- * engine.registerTemplate(TemplateType.WELCOME, {
196
- * subject: 'Welcome {{userName}}!',
197
- * html: '<h1>Hello {{userName}}!</h1>',
198
- * text: 'Hello {{userName}}!'
199
- * });
200
- * ```
201
- */
202
- registerTemplate(type: TemplateType | string, template: EmailTemplate): void;
203
-
204
- /**
205
- * Register a custom template from files
206
- *
207
- * Allows loading templates from file system (.hbs, .html, .txt files).
208
- * Consumer apps can provide paths to their own branded templates.
209
- *
210
- * @param type - Template type identifier
211
- * @param templateFiles - Template file paths
212
- *
213
- * @example
214
- * ```typescript
215
- * engine.registerTemplateFromFiles(TemplateType.WELCOME, {
216
- * subject: { filePath: './templates/welcome.subject.hbs' },
217
- * html: { filePath: './templates/welcome.html.hbs' },
218
- * text: { filePath: './templates/welcome.text.hbs' }
219
- * });
220
- * ```
221
- */
222
- registerTemplateFromFiles?(type: TemplateType | string, templateFiles: TemplateFiles): Promise<void>;
223
-
224
- /**
225
- * Register a custom template from mixed sources (strings or files)
226
- *
227
- * Flexible registration that supports both inline content and file paths.
228
- *
229
- * @param type - Template type identifier
230
- * @param templateSources - Template sources (content or file paths)
231
- *
232
- * @example
233
- * ```typescript
234
- * engine.registerTemplateFromSources(TemplateType.WELCOME, {
235
- * subject: { content: 'Welcome {{userName}}!' },
236
- * html: { filePath: './templates/welcome.html.hbs' },
237
- * text: { content: 'Welcome {{userName}}!' }
238
- * });
239
- * ```
240
- */
241
- registerTemplateFromSources?(type: TemplateType | string, templateSources: TemplateFiles): Promise<void>;
242
-
243
- /**
244
- * Get available template types
245
- *
246
- * @returns Array of registered template type identifiers
247
- */
248
- getAvailableTemplates(): string[];
249
-
250
- /**
251
- * Check if a template exists
252
- *
253
- * @param type - Template type to check
254
- * @returns True if template is registered
255
- */
256
- hasTemplate(type: TemplateType | string): boolean;
257
- }
258
-
259
- /**
260
- * Required template parameters for each template type
261
- *
262
- * Defines which variables MUST be present in custom templates.
263
- * Optional variables (firstName, lastName, etc.) can be included but are not required.
264
- */
265
- export interface TemplateRequiredParams {
266
- /**
267
- * Email verification template required parameters
268
- */
269
- [TemplateType.VERIFICATION]: {
270
- code: string;
271
- link: string;
272
- expiryMinutes: number;
273
- };
274
-
275
- /**
276
- * Password reset template required parameters
277
- */
278
- [TemplateType.PASSWORD_RESET]: {
279
- link: string;
280
- expiryMinutes: number;
281
- };
282
-
283
- /**
284
- * Welcome template required parameters
285
- */
286
- [TemplateType.WELCOME]: Record<string, never>; // No required params
287
-
288
- /**
289
- * Account lockout template required parameters
290
- */
291
- [TemplateType.ACCOUNT_LOCKOUT]: {
292
- reason: string;
293
- durationMinutes: number;
294
- };
295
-
296
- /**
297
- * New device template required parameters
298
- */
299
- [TemplateType.NEW_DEVICE]: {
300
- deviceName: string;
301
- deviceType?: string;
302
- ipAddress?: string;
303
- location?: string;
304
- timestamp: string;
305
- };
306
-
307
- /**
308
- * Password changed template required parameters
309
- */
310
- [TemplateType.PASSWORD_CHANGED]: Record<string, never>; // No required params
311
-
312
- /**
313
- * Email changed template required parameters
314
- */
315
- [TemplateType.EMAIL_CHANGED]: {
316
- userEmail: string;
317
- };
318
-
319
- /**
320
- * MFA enabled template required parameters
321
- */
322
- [TemplateType.MFA_ENABLED]: Record<string, never>; // No required params
323
- }
324
-
325
- /**
326
- * Custom template definition with file paths or content
327
- *
328
- * Allows specifying templates as file paths or inline content.
329
- * All templates support Handlebars syntax for dynamic content.
330
- *
331
- * @example
332
- * ```typescript
333
- * const customTemplate: CustomTemplateDefinition = {
334
- * htmlPath: './templates/verification.html.hbs',
335
- * // OR
336
- * html: '<html>{{code}}</html>',
337
- * // Optional text version
338
- * textPath: './templates/verification.text.hbs'
339
- * };
340
- * ```
341
- */
342
- export interface CustomTemplateDefinition {
343
- /**
344
- * Path to HTML template file (supports frontmatter for subject)
345
- * Mutually exclusive with `html`
346
- */
347
- htmlPath?: string;
348
-
349
- /**
350
- * HTML template content as string (supports frontmatter for subject)
351
- * Mutually exclusive with `htmlPath`
352
- */
353
- html?: string;
354
-
355
- /**
356
- * Path to plain text template file
357
- * Mutually exclusive with `text`
358
- */
359
- textPath?: string;
360
-
361
- /**
362
- * Plain text template content as string
363
- * Mutually exclusive with `textPath`
364
- */
365
- text?: string;
366
-
367
- /**
368
- * Email subject (can include Handlebars variables)
369
- * If not provided, will be extracted from HTML frontmatter
370
- */
371
- subject?: string;
372
- }
373
-
374
- /**
375
- * Template Configuration
376
- *
377
- * Configuration options for the template system.
378
- * Used in AuthModule.forRoot() configuration.
379
- *
380
- * Custom templates are validated at startup to ensure they include
381
- * all required parameters for their template type.
382
- *
383
- * @example
384
- * ```typescript
385
- * AuthModule.forRoot({
386
- * email: {
387
- * templates: {
388
- * // Global variables (optional, available to all templates)
389
- * globalVariables: {
390
- * appName: 'My Application',
391
- * companyName: 'My Company Inc.',
392
- * supportEmail: 'support@example.com',
393
- * brandColor: '#4CAF50',
394
- * logoUrl: 'https://example.com/logo.png'
395
- * },
396
- * // Custom templates (override defaults)
397
- * customTemplates: {
398
- * verification: {
399
- * htmlPath: './templates/verification.html.hbs',
400
- * textPath: './templates/verification.text.hbs'
401
- * // Must include: {{code}}, {{link}}, {{expiryMinutes}}
402
- * },
403
- * welcome: {
404
- * html: `
405
- * ---
406
- * subject: Welcome to {{appName}}!
407
- * ---
408
- * <h1>Hello {{firstName}}!</h1>
409
- * `,
410
- * // No required params for welcome
411
- * }
412
- * }
413
- * }
414
- * }
415
- * })
416
- * ```
417
- */
418
- export interface TemplateConfig {
419
- /**
420
- * Template engine instance
421
- *
422
- * @default HandlebarsTemplateEngine with default templates
423
- */
424
- engine?: TemplateEngine;
425
-
426
- /**
427
- * Global variables available to all templates
428
- *
429
- * These are merged with template-specific variables at render time.
430
- * Template-specific variables take precedence over globals.
431
- *
432
- * Common global variables:
433
- * - appName: Your application name
434
- * - companyName: Your company name
435
- * - supportEmail: Support contact email
436
- * - brandColor: Primary brand color (hex)
437
- * - logoUrl: URL to your logo image
438
- * - dashboardUrl: URL to user dashboard
439
- * - footerDisclaimer: Custom footer disclaimer text (optional, has default)
440
- *
441
- * Optional user-specific variables (injected at runtime):
442
- * - firstName, lastName, userName: User information
443
- * - currentYear: Current year (injected automatically)
444
- *
445
- * @example
446
- * ```typescript
447
- * globalVariables: {
448
- * appName: process.env.APP_NAME || 'My App',
449
- * companyName: 'My Company Inc.',
450
- * supportEmail: 'support@example.com',
451
- * brandColor: '#4f46e5',
452
- * logoUrl: 'https://example.com/logo.png'
453
- * }
454
- * ```
455
- */
456
- globalVariables?: TemplateVariables;
457
-
458
- /**
459
- * Custom template definitions
460
- *
461
- * Override default templates or add new ones.
462
- * Templates are validated at startup to ensure required parameters are present.
463
- *
464
- * Key is the template type, value is the template definition.
465
- * Templates can be provided as file paths or inline content.
466
- *
467
- * All templates support Handlebars syntax:
468
- * - {{variable}}: Insert variable
469
- * - {{#if variable}}...{{/if}}: Conditional
470
- * - {{#each items}}...{{/each}}: Loop
471
- *
472
- * Required parameters by template type:
473
- * - verification: {{code}}, {{link}}, {{expiryMinutes}}
474
- * - passwordReset: {{link}}, {{expiryMinutes}}
475
- * - accountLockout: {{reason}}, {{durationMinutes}}
476
- * - newDevice: {{deviceName}}, {{timestamp}}
477
- * - emailChanged: {{userEmail}}
478
- * - welcome, passwordChanged, mfaEnabled: No required params
479
- *
480
- * @example
481
- * ```typescript
482
- * customTemplates: {
483
- * // File-based template (with frontmatter for subject)
484
- * verification: {
485
- * htmlPath: './templates/verification.html.hbs',
486
- * textPath: './templates/verification.text.hbs'
487
- * },
488
- * // Inline template (with frontmatter for subject)
489
- * welcome: {
490
- * html: `
491
- * ---
492
- * subject: Welcome to {{appName}}!
493
- * ---
494
- * <html>
495
- * <h1>Hello {{firstName}}!</h1>
496
- * <p>Welcome to our platform!</p>
497
- * </html>
498
- * `
499
- * },
500
- * // Mixed (HTML from file, explicit subject)
501
- * passwordReset: {
502
- * subject: 'Reset your password - {{appName}}',
503
- * htmlPath: './templates/password-reset.html.hbs',
504
- * text: 'Reset link: {{link}} (expires in {{expiryMinutes}} minutes)'
505
- * }
506
- * }
507
- * ```
508
- */
509
- customTemplates?: Record<string, CustomTemplateDefinition>;
510
- }
@@ -1,110 +0,0 @@
1
- /**
2
- * Token Verifier Service Interface
3
- *
4
- * Defines the contract for OAuth token verification services.
5
- * Each platform-specific implementation must follow this interface.
6
- *
7
- * Note: Provider-specific verified token profile types are defined in each provider package,
8
- * not in core, to maintain proper separation of concerns.
9
- *
10
- * @example
11
- * ```typescript
12
- * // In Google provider package
13
- * import { ITokenVerifierService } from '@nauth-toolkit/core';
14
- *
15
- * interface VerifiedGoogleTokenProfile {
16
- * sub: string;
17
- * email: string;
18
- * // ...
19
- * }
20
- *
21
- * class GoogleTokenVerifierService implements ITokenVerifierService {
22
- * async verifyGoogleToken(idToken: string, clientId: string | string[]): Promise<VerifiedGoogleTokenProfile> {
23
- * // Implementation
24
- * }
25
- * }
26
- * ```
27
- */
28
- export interface ITokenVerifierService {
29
- /**
30
- * Verify Google ID token with cryptographic signature validation
31
- *
32
- * Uses Google's public keys to verify the JWT signature, ensuring the token
33
- * was issued by Google and has not been tampered with.
34
- *
35
- * @param idToken - ID token from Google OAuth
36
- * @param clientId - Google OAuth client ID for audience validation (supports multiple IDs)
37
- * @returns Verified user profile data (provider-specific type)
38
- * @throws {BadRequestException} When token is invalid, expired, or signature fails
39
- *
40
- * @example
41
- * ```typescript
42
- * try {
43
- * const profile = await verifier.verifyGoogleToken(idToken, ['web-client-id', 'ios-client-id']);
44
- * console.log(`Verified email: ${profile.email}`);
45
- * } catch (error) {
46
- * console.error('Token verification failed:', error.message);
47
- * }
48
- * ```
49
- */
50
- verifyGoogleToken?(idToken: string, clientId: string | string[]): Promise<unknown>;
51
-
52
- /**
53
- * Verify Apple ID token with JWT signature validation
54
- *
55
- * Fetches Apple's public keys from their JWKS endpoint and verifies the
56
- * JWT signature to ensure authenticity.
57
- *
58
- * @param idToken - ID token from Apple Sign In
59
- * @param clientId - Apple Services ID (client ID) for audience validation
60
- * @returns Verified user profile data (provider-specific type)
61
- * @throws {BadRequestException} When token is invalid, expired, or signature fails
62
- *
63
- * @example
64
- * ```typescript
65
- * try {
66
- * const profile = await verifier.verifyAppleToken(idToken, 'com.yourapp.service');
67
- * console.log(`Verified email: ${profile.email}`);
68
- * } catch (error) {
69
- * console.error('Token verification failed:', error.message);
70
- * }
71
- * ```
72
- */
73
- verifyAppleToken?(idToken: string, clientId: string): Promise<unknown>;
74
-
75
- /**
76
- * Verify Facebook access token via Graph API
77
- *
78
- * Validates the access token by calling Facebook's debug_token endpoint,
79
- * which checks the token's validity and returns user information.
80
- *
81
- * @param accessToken - Access token from Facebook OAuth
82
- * @param appId - Facebook App ID
83
- * @param appSecret - Facebook App Secret (server-side only)
84
- * @returns Verified user profile data (provider-specific type)
85
- * @throws {BadRequestException} When token is invalid or API call fails
86
- *
87
- * @example
88
- * ```typescript
89
- * try {
90
- * const profile = await verifier.verifyFacebookToken(accessToken, appId, appSecret);
91
- * console.log(`Verified Facebook user: ${profile.id}`);
92
- * } catch (error) {
93
- * console.error('Token verification failed:', error.message);
94
- * }
95
- * ```
96
- */
97
- verifyFacebookToken?(accessToken: string, appId: string, appSecret: string): Promise<unknown>;
98
-
99
- /**
100
- * Clear cached clients and keys
101
- *
102
- * Useful for testing or when configuration changes
103
- *
104
- * @example
105
- * ```typescript
106
- * verifier.clearCache();
107
- * ```
108
- */
109
- clearCache?(): void;
110
- }