@lenne.tech/nest-server 11.10.2 → 11.10.4

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 (67) hide show
  1. package/dist/config.env.js +16 -133
  2. package/dist/config.env.js.map +1 -1
  3. package/dist/core/common/interfaces/server-options.interface.d.ts +4 -0
  4. package/dist/core/modules/auth/core-auth.module.js +8 -4
  5. package/dist/core/modules/auth/core-auth.module.js.map +1 -1
  6. package/dist/core/modules/auth/guards/roles-guard-registry.d.ts +9 -0
  7. package/dist/core/modules/auth/guards/roles-guard-registry.js +30 -0
  8. package/dist/core/modules/auth/guards/roles-guard-registry.js.map +1 -0
  9. package/dist/core/modules/better-auth/better-auth.config.d.ts +3 -0
  10. package/dist/core/modules/better-auth/better-auth.config.js +176 -47
  11. package/dist/core/modules/better-auth/better-auth.config.js.map +1 -1
  12. package/dist/core/modules/better-auth/core-better-auth-api.middleware.d.ts +5 -1
  13. package/dist/core/modules/better-auth/core-better-auth-api.middleware.js +101 -8
  14. package/dist/core/modules/better-auth/core-better-auth-api.middleware.js.map +1 -1
  15. package/dist/core/modules/better-auth/core-better-auth-challenge.service.d.ts +20 -0
  16. package/dist/core/modules/better-auth/core-better-auth-challenge.service.js +142 -0
  17. package/dist/core/modules/better-auth/core-better-auth-challenge.service.js.map +1 -0
  18. package/dist/core/modules/better-auth/core-better-auth-user.mapper.js +1 -1
  19. package/dist/core/modules/better-auth/core-better-auth-user.mapper.js.map +1 -1
  20. package/dist/core/modules/better-auth/core-better-auth-web.helper.d.ts +2 -0
  21. package/dist/core/modules/better-auth/core-better-auth-web.helper.js +29 -1
  22. package/dist/core/modules/better-auth/core-better-auth-web.helper.js.map +1 -1
  23. package/dist/core/modules/better-auth/core-better-auth.controller.js +5 -13
  24. package/dist/core/modules/better-auth/core-better-auth.controller.js.map +1 -1
  25. package/dist/core/modules/better-auth/core-better-auth.middleware.d.ts +0 -1
  26. package/dist/core/modules/better-auth/core-better-auth.middleware.js +6 -19
  27. package/dist/core/modules/better-auth/core-better-auth.middleware.js.map +1 -1
  28. package/dist/core/modules/better-auth/core-better-auth.module.d.ts +5 -1
  29. package/dist/core/modules/better-auth/core-better-auth.module.js +74 -27
  30. package/dist/core/modules/better-auth/core-better-auth.module.js.map +1 -1
  31. package/dist/core/modules/better-auth/core-better-auth.resolver.js +7 -6
  32. package/dist/core/modules/better-auth/core-better-auth.resolver.js.map +1 -1
  33. package/dist/core/modules/better-auth/core-better-auth.service.d.ts +0 -2
  34. package/dist/core/modules/better-auth/core-better-auth.service.js +23 -37
  35. package/dist/core/modules/better-auth/core-better-auth.service.js.map +1 -1
  36. package/dist/core.module.js +10 -1
  37. package/dist/core.module.js.map +1 -1
  38. package/dist/index.d.ts +1 -0
  39. package/dist/index.js +1 -0
  40. package/dist/index.js.map +1 -1
  41. package/dist/server/modules/better-auth/better-auth.module.d.ts +4 -1
  42. package/dist/server/modules/better-auth/better-auth.module.js +4 -1
  43. package/dist/server/modules/better-auth/better-auth.module.js.map +1 -1
  44. package/dist/server/server.module.js +1 -4
  45. package/dist/server/server.module.js.map +1 -1
  46. package/dist/tsconfig.build.tsbuildinfo +1 -1
  47. package/package.json +1 -1
  48. package/src/config.env.ts +24 -174
  49. package/src/core/common/interfaces/server-options.interface.ts +288 -35
  50. package/src/core/modules/auth/core-auth.module.ts +11 -5
  51. package/src/core/modules/auth/guards/roles-guard-registry.ts +57 -0
  52. package/src/core/modules/better-auth/INTEGRATION-CHECKLIST.md +85 -56
  53. package/src/core/modules/better-auth/README.md +132 -35
  54. package/src/core/modules/better-auth/better-auth.config.ts +402 -70
  55. package/src/core/modules/better-auth/core-better-auth-api.middleware.ts +158 -18
  56. package/src/core/modules/better-auth/core-better-auth-challenge.service.ts +254 -0
  57. package/src/core/modules/better-auth/core-better-auth-user.mapper.ts +1 -1
  58. package/src/core/modules/better-auth/core-better-auth-web.helper.ts +64 -1
  59. package/src/core/modules/better-auth/core-better-auth.controller.ts +6 -14
  60. package/src/core/modules/better-auth/core-better-auth.middleware.ts +7 -20
  61. package/src/core/modules/better-auth/core-better-auth.module.ts +173 -38
  62. package/src/core/modules/better-auth/core-better-auth.resolver.ts +7 -6
  63. package/src/core/modules/better-auth/core-better-auth.service.ts +27 -48
  64. package/src/core.module.ts +21 -3
  65. package/src/index.ts +1 -0
  66. package/src/server/modules/better-auth/better-auth.module.ts +40 -10
  67. package/src/server/server.module.ts +2 -4
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@lenne.tech/nest-server",
3
- "version": "11.10.2",
3
+ "version": "11.10.4",
4
4
  "description": "Modern, fast, powerful Node.js web framework in TypeScript based on Nest with a GraphQL API and a connection to MongoDB (or other databases).",
5
5
  "keywords": [
6
6
  "node",
package/src/config.env.ts CHANGED
@@ -7,6 +7,7 @@ import { IServerOptions } from './core/common/interfaces/server-options.interfac
7
7
 
8
8
  /**
9
9
  * Configuration for the different environments
10
+ * @see IServerOptions for documentation of all options
10
11
  */
11
12
  dotenv.config();
12
13
  const config: { [env: string]: IServerOptions } = {
@@ -14,68 +15,11 @@ const config: { [env: string]: IServerOptions } = {
14
15
  // Development environment
15
16
  // ===========================================================================
16
17
  development: {
17
- // Legacy Auth endpoint controls (for migration to BetterAuth)
18
- // Set to false after all users have migrated to BetterAuth (IAM)
19
- // See: .claude/rules/module-deprecation.md
20
18
  auth: {
21
- legacyEndpoints: {
22
- enabled: true, // Set to false to disable legacy auth endpoints (returns HTTP 410)
23
- // graphql: true, // Optionally disable only GraphQL endpoints
24
- // rest: true, // Optionally disable only REST endpoints
25
- },
19
+ legacyEndpoints: { enabled: true },
26
20
  },
27
21
  automaticObjectIdFiltering: true,
28
- betterAuth: {
29
- basePath: '/iam',
30
- baseUrl: 'http://localhost:3000',
31
- // enabled: true by default - set false to explicitly disable
32
- jwt: {
33
- enabled: true,
34
- expiresIn: '15m',
35
- },
36
- passkey: {
37
- enabled: false,
38
- origin: 'http://localhost:3000',
39
- rpId: 'localhost',
40
- rpName: 'Nest Server Development',
41
- },
42
- rateLimit: {
43
- enabled: true,
44
- max: 20,
45
- message: 'Too many requests, please try again later.',
46
- skipEndpoints: ['/session', '/callback'],
47
- strictEndpoints: ['/sign-in', '/sign-up', '/forgot-password', '/reset-password'],
48
- windowSeconds: 60,
49
- },
50
- secret: 'BETTER_AUTH_SECRET_DEV_32_CHARS_MIN',
51
- socialProviders: {
52
- apple: {
53
- clientId: process.env.SOCIAL_APPLE_CLIENT_ID || '',
54
- clientSecret: process.env.SOCIAL_APPLE_CLIENT_SECRET || '',
55
- enabled: false,
56
- },
57
- github: {
58
- clientId: process.env.SOCIAL_GITHUB_CLIENT_ID || '',
59
- clientSecret: process.env.SOCIAL_GITHUB_CLIENT_SECRET || '',
60
- enabled: false,
61
- },
62
- google: {
63
- clientId: process.env.SOCIAL_GOOGLE_CLIENT_ID || '',
64
- clientSecret: process.env.SOCIAL_GOOGLE_CLIENT_SECRET || '',
65
- enabled: false,
66
- },
67
- },
68
- twoFactor: {
69
- appName: 'Nest Server Development',
70
- enabled: false,
71
- },
72
- // CORS trustedOrigins configuration:
73
- // - Not set + Passkey disabled: All origins allowed (default)
74
- // - Not set + Passkey enabled: Server startup FAILS (trustedOrigins required)
75
- // - Set explicitly: Only configured origins allowed
76
- // Uncomment and configure when enabling Passkey:
77
- // trustedOrigins: ['http://localhost:3000', 'http://localhost:3001'],
78
- },
22
+ baseUrl: 'http://localhost:3000',
79
23
  compression: true,
80
24
  cookies: false,
81
25
  email: {
@@ -128,14 +72,12 @@ const config: { [env: string]: IServerOptions } = {
128
72
  // Each secret should be unique and not reused in other environments,
129
73
  // also the JWT secret should be different from the Refresh secret!
130
74
  // crypto.randomBytes(512).toString('base64') (see https://nodejs.org/api/crypto.html#crypto)
131
- // tslint:disable-next-line:max-line-length
132
75
  secret: 'SECRET_OR_PRIVATE_KEY_DEV_REFRESH',
133
76
  signInOptions: {
134
77
  expiresIn: '7d',
135
78
  },
136
79
  },
137
80
  sameTokenIdPeriod: 2000,
138
- // tslint:disable-next-line:max-line-length
139
81
  secret: 'SECRET_OR_PRIVATE_KEY_DEV',
140
82
  signInOptions: {
141
83
  expiresIn: '15m',
@@ -175,68 +117,30 @@ const config: { [env: string]: IServerOptions } = {
175
117
  },
176
118
 
177
119
  // ===========================================================================
178
- // Local environment
120
+ // Local environment (env: 'local' → auto URLs + Passkey)
179
121
  // ===========================================================================
180
122
  local: {
181
- // Legacy Auth endpoint controls (for migration to BetterAuth)
182
- // Set to false after all users have migrated to BetterAuth (IAM)
183
- // See: .claude/rules/module-deprecation.md
184
123
  auth: {
185
- legacyEndpoints: {
186
- enabled: true, // Set to false to disable legacy auth endpoints (returns HTTP 410)
187
- // graphql: true, // Optionally disable only GraphQL endpoints
188
- // rest: true, // Optionally disable only REST endpoints
189
- },
124
+ legacyEndpoints: { enabled: true },
190
125
  },
191
126
  automaticObjectIdFiltering: true,
192
127
  betterAuth: {
193
- basePath: '/iam',
194
- baseUrl: 'http://localhost:3000',
195
- enabled: true, // Enable for Scenario 2 (Legacy + IAM) testing
196
- jwt: {
197
- enabled: true,
198
- expiresIn: '15m',
199
- },
200
- passkey: {
201
- enabled: true,
202
- origin: 'http://localhost:3000',
203
- rpId: 'localhost',
204
- rpName: 'Nest Server Local',
205
- },
206
- rateLimit: {
207
- enabled: true,
208
- max: 100, // Higher limit for local testing
209
- message: 'Too many requests, please try again later.',
210
- skipEndpoints: ['/session', '/callback'],
211
- strictEndpoints: ['/sign-in', '/sign-up', '/forgot-password', '/reset-password'],
212
- windowSeconds: 60,
213
- },
128
+ // JWT enabled by default (zero-config)
129
+ jwt: { enabled: true, expiresIn: '15m' },
130
+ // Passkey auto-activated when URLs can be resolved (env: 'local' → localhost defaults)
131
+ passkey: { enabled: true, origin: 'http://localhost:3001', rpId: 'localhost', rpName: 'Nest Server Local' },
132
+ rateLimit: { enabled: true, max: 100, windowSeconds: 60 },
214
133
  secret: 'BETTER_AUTH_SECRET_LOCAL_32_CHARS_M',
134
+ // Social providers disabled in local environment (no credentials)
215
135
  socialProviders: {
216
- apple: {
217
- clientId: process.env.SOCIAL_APPLE_CLIENT_ID || '',
218
- clientSecret: process.env.SOCIAL_APPLE_CLIENT_SECRET || '',
219
- enabled: false,
220
- },
221
- github: {
222
- clientId: process.env.SOCIAL_GITHUB_CLIENT_ID || '',
223
- clientSecret: process.env.SOCIAL_GITHUB_CLIENT_SECRET || '',
224
- enabled: false,
225
- },
226
- google: {
227
- clientId: process.env.SOCIAL_GOOGLE_CLIENT_ID || '',
228
- clientSecret: process.env.SOCIAL_GOOGLE_CLIENT_SECRET || '',
229
- enabled: false,
230
- },
136
+ apple: { clientId: '', clientSecret: '', enabled: false },
137
+ github: { clientId: '', clientSecret: '', enabled: false },
138
+ google: { clientId: '', clientSecret: '', enabled: false },
231
139
  },
232
- // REQUIRED when Passkey is enabled!
233
- // Passkey uses credentials: 'include' which requires explicit CORS origins.
234
- // Server startup will fail if Passkey is enabled without trustedOrigins.
140
+ // Trusted origins for Passkey (localhost defaults)
235
141
  trustedOrigins: ['http://localhost:3000', 'http://localhost:3001'],
236
- twoFactor: {
237
- appName: 'Nest Server Local',
238
- enabled: true,
239
- },
142
+ // 2FA enabled for local testing
143
+ twoFactor: { appName: 'Nest Server Local', enabled: true },
240
144
  },
241
145
  compression: true,
242
146
  cookies: false,
@@ -305,14 +209,12 @@ const config: { [env: string]: IServerOptions } = {
305
209
  // Each secret should be unique and not reused in other environments,
306
210
  // also the JWT secret should be different from the Refresh secret!
307
211
  // crypto.randomBytes(512).toString('base64') (see https://nodejs.org/api/crypto.html#crypto)
308
- // tslint:disable-next-line:max-line-length
309
212
  secret: 'SECRET_OR_PRIVATE_KEY_LOCAL_REFRESH',
310
213
  signInOptions: {
311
214
  expiresIn: '7d',
312
215
  },
313
216
  },
314
217
  sameTokenIdPeriod: 2000,
315
- // tslint:disable-next-line:max-line-length
316
218
  secret: 'SECRET_OR_PRIVATE_KEY_LOCAL',
317
219
  signInOptions: {
318
220
  expiresIn: '15m',
@@ -352,72 +254,22 @@ const config: { [env: string]: IServerOptions } = {
352
254
  },
353
255
 
354
256
  // ===========================================================================
355
- // Production environment
257
+ // Production environment (set BASE_URL env var for auto Passkey)
356
258
  // ===========================================================================
357
259
  production: {
358
- // Legacy Auth endpoint controls (for migration to BetterAuth)
359
- // Set to false after all users have migrated to BetterAuth (IAM)
360
- // See: .claude/rules/module-deprecation.md
361
260
  auth: {
362
- legacyEndpoints: {
363
- enabled: process.env.LEGACY_AUTH_ENABLED !== 'false', // Disable via env var
364
- // graphql: true, // Optionally disable only GraphQL endpoints
365
- // rest: true, // Optionally disable only REST endpoints
366
- },
261
+ legacyEndpoints: { enabled: process.env.LEGACY_AUTH_ENABLED !== 'false' },
367
262
  },
368
263
  automaticObjectIdFiltering: true,
264
+ baseUrl: process.env.BASE_URL,
369
265
  betterAuth: {
370
- basePath: '/iam',
371
- baseUrl: process.env.BETTER_AUTH_URL || 'https://example.com',
372
- // enabled: true by default - set false to explicitly disable
373
- jwt: {
374
- enabled: true,
375
- expiresIn: '15m',
376
- },
377
- passkey: {
378
- enabled: false,
379
- origin: process.env.BETTER_AUTH_URL || 'https://example.com',
380
- rpId: process.env.PASSKEY_RP_ID || 'example.com',
381
- rpName: process.env.PASSKEY_RP_NAME || 'Nest Server Production',
382
- },
383
- rateLimit: {
384
- enabled: process.env.RATE_LIMIT_ENABLED !== 'false',
385
- max: parseInt(process.env.RATE_LIMIT_MAX || '10', 10),
386
- message: process.env.RATE_LIMIT_MESSAGE || 'Too many requests, please try again later.',
387
- skipEndpoints: ['/session', '/callback'],
388
- strictEndpoints: ['/sign-in', '/sign-up', '/forgot-password', '/reset-password'],
389
- windowSeconds: parseInt(process.env.RATE_LIMIT_WINDOW_SECONDS || '60', 10),
390
- },
391
- // IMPORTANT: Set BETTER_AUTH_SECRET in production!
392
- // Without it, an insecure default is used which allows session forgery.
393
- // Generate with: node -e "console.log(require('crypto').randomBytes(32).toString('base64'))"
266
+ rateLimit: { enabled: process.env.RATE_LIMIT_ENABLED !== 'false', max: parseInt(process.env.RATE_LIMIT_MAX || '10', 10) },
394
267
  secret: process.env.BETTER_AUTH_SECRET,
395
268
  socialProviders: {
396
- apple: {
397
- clientId: process.env.SOCIAL_APPLE_CLIENT_ID || '',
398
- clientSecret: process.env.SOCIAL_APPLE_CLIENT_SECRET || '',
399
- enabled: !!process.env.SOCIAL_APPLE_CLIENT_ID,
400
- },
401
- github: {
402
- clientId: process.env.SOCIAL_GITHUB_CLIENT_ID || '',
403
- clientSecret: process.env.SOCIAL_GITHUB_CLIENT_SECRET || '',
404
- enabled: !!process.env.SOCIAL_GITHUB_CLIENT_ID,
405
- },
406
- google: {
407
- clientId: process.env.SOCIAL_GOOGLE_CLIENT_ID || '',
408
- clientSecret: process.env.SOCIAL_GOOGLE_CLIENT_SECRET || '',
409
- enabled: !!process.env.SOCIAL_GOOGLE_CLIENT_ID,
410
- },
411
- },
412
- // REQUIRED for Passkey in production!
413
- // Passkey uses credentials: 'include' which requires explicit origins (no wildcard '*')
414
- // Configure all frontend URLs that need Passkey authentication:
415
- trustedOrigins: process.env.TRUSTED_ORIGINS?.split(',') || [],
416
- twoFactor: {
417
- appName: process.env.TWO_FACTOR_APP_NAME || 'Nest Server',
418
- enabled: process.env.TWO_FACTOR_ENABLED === 'true',
269
+ github: { clientId: process.env.SOCIAL_GITHUB_CLIENT_ID || '', clientSecret: process.env.SOCIAL_GITHUB_CLIENT_SECRET || '' },
270
+ google: { clientId: process.env.SOCIAL_GOOGLE_CLIENT_ID || '', clientSecret: process.env.SOCIAL_GOOGLE_CLIENT_SECRET || '' },
419
271
  },
420
- // Example: TRUSTED_ORIGINS=https://app.example.com,https://admin.example.com
272
+ twoFactor: { appName: process.env.TWO_FACTOR_APP_NAME || 'Nest Server' },
421
273
  },
422
274
  compression: true,
423
275
  cookies: false,
@@ -471,14 +323,12 @@ const config: { [env: string]: IServerOptions } = {
471
323
  // Each secret should be unique and not reused in other environments,
472
324
  // also the JWT secret should be different from the Refresh secret!
473
325
  // crypto.randomBytes(512).toString('base64') (see https://nodejs.org/api/crypto.html#crypto)
474
- // tslint:disable-next-line:max-line-length
475
326
  secret: 'SECRET_OR_PRIVATE_KEY_PROD_REFRESH',
476
327
  signInOptions: {
477
328
  expiresIn: '7d',
478
329
  },
479
330
  },
480
331
  sameTokenIdPeriod: 2000,
481
- // tslint:disable-next-line:max-line-length
482
332
  secret: 'SECRET_OR_PRIVATE_KEY_PROD',
483
333
  signInOptions: {
484
334
  expiresIn: '15m',