@lenne.tech/nest-server 11.21.3 → 11.22.1

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 (57) hide show
  1. package/.claude/rules/architecture.md +79 -0
  2. package/.claude/rules/better-auth.md +262 -0
  3. package/.claude/rules/configurable-features.md +308 -0
  4. package/.claude/rules/core-modules.md +205 -0
  5. package/.claude/rules/framework-compatibility.md +79 -0
  6. package/.claude/rules/migration-guides.md +149 -0
  7. package/.claude/rules/module-deprecation.md +214 -0
  8. package/.claude/rules/module-inheritance.md +97 -0
  9. package/.claude/rules/package-management.md +112 -0
  10. package/.claude/rules/role-system.md +146 -0
  11. package/.claude/rules/testing.md +120 -0
  12. package/.claude/rules/versioning.md +53 -0
  13. package/CLAUDE.md +174 -0
  14. package/FRAMEWORK-API.md +231 -0
  15. package/dist/core/common/interfaces/server-options.interface.d.ts +10 -0
  16. package/dist/core/modules/error-code/error-code.module.js.map +1 -1
  17. package/dist/core.module.d.ts +3 -3
  18. package/dist/core.module.js +17 -4
  19. package/dist/core.module.js.map +1 -1
  20. package/dist/server/modules/file/file-info.model.d.ts +1 -5
  21. package/dist/server/modules/user/user.model.d.ts +1 -5
  22. package/dist/server/server.module.js +6 -6
  23. package/dist/server/server.module.js.map +1 -1
  24. package/dist/tsconfig.build.tsbuildinfo +1 -1
  25. package/docs/REQUEST-LIFECYCLE.md +1256 -0
  26. package/docs/error-codes.md +446 -0
  27. package/migration-guides/11.10.x-to-11.11.x.md +266 -0
  28. package/migration-guides/11.11.x-to-11.12.x.md +323 -0
  29. package/migration-guides/11.12.x-to-11.13.0.md +612 -0
  30. package/migration-guides/11.13.x-to-11.14.0.md +348 -0
  31. package/migration-guides/11.14.x-to-11.15.0.md +262 -0
  32. package/migration-guides/11.15.0-to-11.15.3.md +118 -0
  33. package/migration-guides/11.15.x-to-11.16.0.md +497 -0
  34. package/migration-guides/11.16.x-to-11.17.0.md +130 -0
  35. package/migration-guides/11.17.x-to-11.18.0.md +393 -0
  36. package/migration-guides/11.18.x-to-11.19.0.md +151 -0
  37. package/migration-guides/11.19.x-to-11.20.0.md +170 -0
  38. package/migration-guides/11.20.x-to-11.21.0.md +216 -0
  39. package/migration-guides/11.21.0-to-11.21.1.md +194 -0
  40. package/migration-guides/11.21.1-to-11.21.2.md +114 -0
  41. package/migration-guides/11.21.2-to-11.21.3.md +175 -0
  42. package/migration-guides/11.21.x-to-11.22.0.md +224 -0
  43. package/migration-guides/11.22.0-to-11.22.1.md +105 -0
  44. package/migration-guides/11.3.x-to-11.4.x.md +233 -0
  45. package/migration-guides/11.6.x-to-11.7.x.md +394 -0
  46. package/migration-guides/11.7.x-to-11.8.x.md +318 -0
  47. package/migration-guides/11.8.x-to-11.9.x.md +322 -0
  48. package/migration-guides/11.9.x-to-11.10.x.md +571 -0
  49. package/migration-guides/TEMPLATE.md +113 -0
  50. package/package.json +25 -18
  51. package/src/core/common/interfaces/server-options.interface.ts +83 -16
  52. package/src/core/modules/better-auth/CUSTOMIZATION.md +24 -17
  53. package/src/core/modules/better-auth/INTEGRATION-CHECKLIST.md +5 -5
  54. package/src/core/modules/error-code/INTEGRATION-CHECKLIST.md +42 -12
  55. package/src/core/modules/error-code/error-code.module.ts +4 -9
  56. package/src/core.module.ts +52 -10
  57. package/src/server/server.module.ts +7 -9
@@ -0,0 +1,323 @@
1
+ # Migration Guide: 11.11.x → 11.12.x
2
+
3
+ ## Overview
4
+
5
+ | Category | Details |
6
+ |----------|---------|
7
+ | **Breaking Changes** | Cookie structure simplified, `better-auth.session_token` removed |
8
+ | **New Features** | Auto AppName detection, Token analysis helpers, Cookie-Mode/JWT-Mode dual support |
9
+ | **Bugfixes** | Passkey/2FA now works correctly in both Cookie and JWT modes |
10
+ | **Migration Effort** | Low (~10 minutes) - Cookie access changes |
11
+
12
+ ---
13
+
14
+ ## Quick Migration
15
+
16
+ ```bash
17
+ # Update package
18
+ npm install @lenne.tech/nest-server@11.12.x
19
+
20
+ # Verify build
21
+ npm run build
22
+
23
+ # Run tests
24
+ npm test
25
+ ```
26
+
27
+ **Note:** If you directly access `better-auth.session_token` or `session` cookies in your code, see the Breaking Changes section below.
28
+
29
+ ---
30
+
31
+ ## What's New in 11.12.x
32
+
33
+ ### 1. Simplified Cookie Strategy
34
+
35
+ The number of authentication cookies has been significantly reduced:
36
+
37
+ | Before (11.11.x) | After (11.12.x) |
38
+ |------------------|-----------------|
39
+ | `token` | `{basePath}.session_token` (e.g., `iam.session_token`) |
40
+ | `iam.session_token` | `token` (only if Legacy Auth active) |
41
+ | `better-auth.session_token` | *(removed)* |
42
+ | `session` | *(removed)* |
43
+ | Custom configured cookie | *(removed)* |
44
+
45
+ **Benefits:**
46
+ - Smaller request headers
47
+ - Fewer cookies to manage
48
+ - Closer alignment with Better-Auth's native behavior
49
+
50
+ ### 2. Auto AppName Detection
51
+
52
+ The `rpName` (for Passkey) and `issuer` (for 2FA/TOTP) are now automatically derived from your project's `package.json`:
53
+
54
+ ```typescript
55
+ // package.json: { "name": "my-awesome-app" }
56
+
57
+ // Automatically becomes:
58
+ // - rpName: "My Awesome App"
59
+ // - issuer: "My Awesome App"
60
+
61
+ // In development environments (local, test, development):
62
+ // - rpName: "My Awesome App (Local)"
63
+ // - issuer: "My Awesome App (Local)"
64
+ ```
65
+
66
+ This helps users distinguish between Passkeys from different projects running on the same localhost.
67
+
68
+ **To override:**
69
+ ```typescript
70
+ // config.env.ts
71
+ betterAuth: {
72
+ passkey: {
73
+ rpName: 'Custom Name', // Override auto-detection
74
+ },
75
+ twoFactor: {
76
+ appName: 'Custom Name', // Override auto-detection
77
+ },
78
+ }
79
+ ```
80
+
81
+ ### 3. Improved Token Analysis
82
+
83
+ New helper functions for robust token type detection:
84
+
85
+ ```typescript
86
+ import {
87
+ analyzeToken,
88
+ isLegacyJwt,
89
+ isBetterAuthJwt,
90
+ isSessionToken,
91
+ TokenType,
92
+ } from '@lenne.tech/nest-server';
93
+
94
+ // Analyze a token's type by examining its payload
95
+ const result = analyzeToken(token);
96
+ // result.type: TokenType.LEGACY_JWT | TokenType.BETTER_AUTH_JWT | TokenType.SESSION_TOKEN
97
+
98
+ // Quick checks
99
+ if (isLegacyJwt(token)) {
100
+ // Has 'id' claim, no 'sub' - handled by Passport
101
+ }
102
+ if (isBetterAuthJwt(token)) {
103
+ // Has 'sub' claim - Better-Auth JWT
104
+ }
105
+ if (isSessionToken(token)) {
106
+ // Opaque token, not a JWT - use session lookup
107
+ }
108
+ ```
109
+
110
+ ### 4. Cookie-Mode / JWT-Mode Dual Support
111
+
112
+ Passkey and 2FA now work correctly in both authentication modes:
113
+
114
+ | Mode | Cookie Behavior |
115
+ |------|-----------------|
116
+ | Cookie-Mode | Session token in `iam.session_token` cookie |
117
+ | JWT-Mode | Session token passed via Authorization header, challenges stored in database |
118
+
119
+ No configuration needed - the mode is auto-detected based on how the client authenticates.
120
+
121
+ ---
122
+
123
+ ## Breaking Changes
124
+
125
+ ### 1. Cookie Names Changed
126
+
127
+ **If you directly access authentication cookies in your code, update the cookie names:**
128
+
129
+ **Before:**
130
+ ```typescript
131
+ // Accessing cookies directly
132
+ const token = req.cookies['better-auth.session_token'];
133
+ const sessionId = req.cookies['session'];
134
+ ```
135
+
136
+ **After:**
137
+ ```typescript
138
+ // Use the basePath-based cookie name
139
+ const token = req.cookies['iam.session_token']; // Default basePath is 'iam'
140
+
141
+ // Or use the extractSessionToken helper
142
+ import { extractSessionToken } from '@lenne.tech/nest-server';
143
+ const token = extractSessionToken(req, '/iam');
144
+ ```
145
+
146
+ ### 2. Legacy Auth Cookies Now Default-Enabled
147
+
148
+ **Before (11.11.x):**
149
+ ```typescript
150
+ // Cookies only set if `cookies: true` in config
151
+ if (this.configService.getFastButReadOnly('cookies')) {
152
+ // Set cookies
153
+ }
154
+ ```
155
+
156
+ **After (11.12.x):**
157
+ ```typescript
158
+ // Cookies enabled by default, unless explicitly disabled
159
+ if (this.configService.getFastButReadOnly('cookies') !== false) {
160
+ // Set cookies
161
+ }
162
+ ```
163
+
164
+ **Impact:** If you relied on cookies NOT being set by default, explicitly disable them:
165
+ ```typescript
166
+ // config.env.ts
167
+ cookies: false,
168
+ ```
169
+
170
+ ### 3. Session Cookie No Longer Set
171
+
172
+ The `session` cookie (containing the session ID) is no longer set. If you used this cookie for debugging or reference, it's no longer available.
173
+
174
+ **Alternative:** Use the session token from `iam.session_token` to look up session details via the API.
175
+
176
+ ---
177
+
178
+ ## Detailed Migration Steps
179
+
180
+ ### Step 1: Update Package
181
+
182
+ ```bash
183
+ npm install @lenne.tech/nest-server@11.12.x
184
+ ```
185
+
186
+ ### Step 2: Search for Direct Cookie Access
187
+
188
+ Search your codebase for direct access to the old cookie names:
189
+
190
+ ```bash
191
+ # Search for old cookie names
192
+ grep -r "better-auth.session_token" src/
193
+ grep -r "cookies\['session'\]" src/
194
+ grep -r "cookies\.session" src/
195
+ ```
196
+
197
+ Replace with the new cookie name or use the helper function.
198
+
199
+ ### Step 3: Verify Cookie Configuration
200
+
201
+ If you explicitly set `cookies: true` in your config, you can remove it (now the default):
202
+
203
+ ```typescript
204
+ // config.env.ts
205
+ // cookies: true, // Can be removed - now default
206
+ ```
207
+
208
+ ### Step 4: Test Authentication Flows
209
+
210
+ Test the following flows in your application:
211
+ - [ ] Email/Password Sign-In (Cookie mode)
212
+ - [ ] Email/Password Sign-In (JWT mode)
213
+ - [ ] Passkey Registration
214
+ - [ ] Passkey Login
215
+ - [ ] 2FA Enable/Verify
216
+ - [ ] Sign-Out
217
+
218
+ ---
219
+
220
+ ## Compatibility Notes
221
+
222
+ ### Existing Projects Without Direct Cookie Access
223
+
224
+ If you don't directly access cookies in your application code (most common case), this update is **fully backward compatible**.
225
+
226
+ ### Projects Using Legacy Auth + Better-Auth
227
+
228
+ When Legacy Auth (Passport/JWT) is active alongside Better-Auth:
229
+ - The `token` cookie is automatically set for backward compatibility
230
+ - Better-Auth's `iam.session_token` is also set
231
+ - Token analysis correctly routes JWTs to Passport and session tokens to Better-Auth
232
+
233
+ ### Frontend Cookie Handling
234
+
235
+ If your frontend (e.g., Nuxt, Next.js) uses the Better-Auth client library, ensure it's configured with the correct cookie name:
236
+
237
+ ```typescript
238
+ // nuxt.config.ts or frontend config
239
+ betterAuth: {
240
+ basePath: '/iam', // Cookies will be named 'iam.session_token'
241
+ }
242
+ ```
243
+
244
+ ---
245
+
246
+ ## Troubleshooting
247
+
248
+ ### Passkey Registration/Login Returns 401
249
+
250
+ **Cause:** Cookie signing mismatch.
251
+
252
+ **Solution:** Ensure `betterAuth.secret` is configured in your environment:
253
+
254
+ ```typescript
255
+ // config.env.ts
256
+ betterAuth: {
257
+ secret: process.env.BETTER_AUTH_SECRET,
258
+ }
259
+ ```
260
+
261
+ ### "No secret configured" Warning
262
+
263
+ **Symptom:** Warning in logs: "No secret configured - setting unsigned cookie"
264
+
265
+ **Solution:** Configure the Better-Auth secret. Without it, Passkey and 2FA may not work correctly.
266
+
267
+ ### Session Not Found After Cookie Migration
268
+
269
+ **Cause:** Old cookies from previous version still in browser.
270
+
271
+ **Solution:** Clear browser cookies and re-authenticate, or sign out and sign in again.
272
+
273
+ ---
274
+
275
+ ## New Exports
276
+
277
+ The following are now exported from `@lenne.tech/nest-server`:
278
+
279
+ ```typescript
280
+ // Token analysis helpers
281
+ export {
282
+ analyzeToken,
283
+ getUserIdFromToken,
284
+ isBetterAuthJwt,
285
+ isJwt,
286
+ isLegacyJwt,
287
+ isSessionToken,
288
+ TokenAnalysisResult,
289
+ TokenType,
290
+ } from './core/modules/better-auth/core-better-auth-token.helper';
291
+
292
+ // Cookie helper
293
+ export {
294
+ AUTH_COOKIE_NAMES,
295
+ AuthCookieOptions,
296
+ BetterAuthCookieHelper,
297
+ BetterAuthCookieHelperConfig,
298
+ CookieProcessingResult,
299
+ createCookieHelper,
300
+ } from './core/modules/better-auth/core-better-auth-cookie.helper';
301
+ ```
302
+
303
+ ---
304
+
305
+ ## Module Documentation
306
+
307
+ ### Better-Auth Module
308
+
309
+ - **README:** [src/core/modules/better-auth/README.md](../src/core/modules/better-auth/README.md)
310
+ - **Integration Checklist:** [src/core/modules/better-auth/INTEGRATION-CHECKLIST.md](../src/core/modules/better-auth/INTEGRATION-CHECKLIST.md)
311
+ - **Reference Implementation:** `src/server/modules/iam/`
312
+ - **Key Files:**
313
+ - `core-better-auth-cookie.helper.ts` - Centralized cookie handling
314
+ - `core-better-auth-token.helper.ts` - Token type analysis
315
+ - `core-better-auth-web.helper.ts` - Web/Express conversion helpers
316
+
317
+ ---
318
+
319
+ ## References
320
+
321
+ - [Better-Auth Module](../src/core/modules/better-auth/) - Core module implementation
322
+ - [nest-server-starter](https://github.com/lenneTech/nest-server-starter) - Reference implementation
323
+ - [Better-Auth Documentation](https://www.better-auth.com/) - Official Better-Auth docs