@lenne.tech/nest-server 11.21.2 → 11.22.0
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.
- package/.claude/rules/architecture.md +79 -0
- package/.claude/rules/better-auth.md +262 -0
- package/.claude/rules/configurable-features.md +308 -0
- package/.claude/rules/core-modules.md +205 -0
- package/.claude/rules/migration-guides.md +149 -0
- package/.claude/rules/module-deprecation.md +214 -0
- package/.claude/rules/module-inheritance.md +97 -0
- package/.claude/rules/package-management.md +112 -0
- package/.claude/rules/role-system.md +146 -0
- package/.claude/rules/testing.md +120 -0
- package/.claude/rules/versioning.md +53 -0
- package/CLAUDE.md +172 -0
- package/dist/core/common/interfaces/server-options.interface.d.ts +10 -0
- package/dist/core/modules/better-auth/core-better-auth-user.mapper.js +25 -25
- package/dist/core/modules/better-auth/core-better-auth-user.mapper.js.map +1 -1
- package/dist/core/modules/better-auth/core-better-auth.service.js +8 -4
- package/dist/core/modules/better-auth/core-better-auth.service.js.map +1 -1
- package/dist/core/modules/error-code/error-code.module.js.map +1 -1
- package/dist/core/modules/tenant/core-tenant.guard.d.ts +1 -0
- package/dist/core/modules/tenant/core-tenant.guard.js +59 -4
- package/dist/core/modules/tenant/core-tenant.guard.js.map +1 -1
- package/dist/core/modules/tenant/core-tenant.helpers.js.map +1 -1
- package/dist/core.module.d.ts +3 -3
- package/dist/core.module.js +17 -4
- package/dist/core.module.js.map +1 -1
- package/dist/server/server.module.js +6 -6
- package/dist/server/server.module.js.map +1 -1
- package/dist/test/test.helper.d.ts +6 -2
- package/dist/test/test.helper.js +28 -6
- package/dist/test/test.helper.js.map +1 -1
- package/dist/tsconfig.build.tsbuildinfo +1 -1
- package/docs/REQUEST-LIFECYCLE.md +1256 -0
- package/docs/error-codes.md +446 -0
- package/migration-guides/11.10.x-to-11.11.x.md +266 -0
- package/migration-guides/11.11.x-to-11.12.x.md +323 -0
- package/migration-guides/11.12.x-to-11.13.0.md +612 -0
- package/migration-guides/11.13.x-to-11.14.0.md +348 -0
- package/migration-guides/11.14.x-to-11.15.0.md +262 -0
- package/migration-guides/11.15.0-to-11.15.3.md +118 -0
- package/migration-guides/11.15.x-to-11.16.0.md +497 -0
- package/migration-guides/11.16.x-to-11.17.0.md +130 -0
- package/migration-guides/11.17.x-to-11.18.0.md +393 -0
- package/migration-guides/11.18.x-to-11.19.0.md +151 -0
- package/migration-guides/11.19.x-to-11.20.0.md +170 -0
- package/migration-guides/11.20.x-to-11.21.0.md +216 -0
- package/migration-guides/11.21.0-to-11.21.1.md +194 -0
- package/migration-guides/11.21.1-to-11.21.2.md +114 -0
- package/migration-guides/11.21.2-to-11.21.3.md +175 -0
- package/migration-guides/11.21.x-to-11.22.0.md +224 -0
- package/migration-guides/11.3.x-to-11.4.x.md +233 -0
- package/migration-guides/11.6.x-to-11.7.x.md +394 -0
- package/migration-guides/11.7.x-to-11.8.x.md +318 -0
- package/migration-guides/11.8.x-to-11.9.x.md +322 -0
- package/migration-guides/11.9.x-to-11.10.x.md +571 -0
- package/migration-guides/TEMPLATE.md +113 -0
- package/package.json +8 -3
- package/src/core/common/interfaces/server-options.interface.ts +83 -16
- package/src/core/modules/better-auth/CUSTOMIZATION.md +24 -17
- package/src/core/modules/better-auth/INTEGRATION-CHECKLIST.md +5 -5
- package/src/core/modules/better-auth/core-better-auth-user.mapper.ts +29 -25
- package/src/core/modules/better-auth/core-better-auth.service.ts +13 -9
- package/src/core/modules/error-code/INTEGRATION-CHECKLIST.md +42 -12
- package/src/core/modules/error-code/error-code.module.ts +4 -9
- package/src/core/modules/tenant/INTEGRATION-CHECKLIST.md +13 -2
- package/src/core/modules/tenant/README.md +26 -1
- package/src/core/modules/tenant/core-tenant.guard.ts +142 -11
- package/src/core/modules/tenant/core-tenant.helpers.ts +6 -2
- package/src/core.module.ts +52 -10
- package/src/server/server.module.ts +7 -9
- package/src/test/README.md +47 -0
- package/src/test/test.helper.ts +55 -6
|
@@ -0,0 +1,322 @@
|
|
|
1
|
+
# Migration Guide: 11.8.x → 11.9.x
|
|
2
|
+
|
|
3
|
+
## Overview
|
|
4
|
+
|
|
5
|
+
| Category | Details |
|
|
6
|
+
|----------|---------|
|
|
7
|
+
| **Breaking Changes** | None |
|
|
8
|
+
| **New Features** | ErrorCodeModule for centralized error handling with i18n translations |
|
|
9
|
+
| **Bugfixes** | None |
|
|
10
|
+
| **Migration Effort** | Minimal (~5 minutes for basic update, optional feature adoption) |
|
|
11
|
+
|
|
12
|
+
---
|
|
13
|
+
|
|
14
|
+
## Quick Migration (No Breaking Changes)
|
|
15
|
+
|
|
16
|
+
```bash
|
|
17
|
+
# Update package
|
|
18
|
+
npm install @lenne.tech/nest-server@11.9.x
|
|
19
|
+
|
|
20
|
+
# Verify build
|
|
21
|
+
npm run build
|
|
22
|
+
|
|
23
|
+
# Run tests
|
|
24
|
+
npm test
|
|
25
|
+
```
|
|
26
|
+
|
|
27
|
+
**That's it!** The ErrorCodeModule is automatically registered and provides error translations at `/api/i18n/errors/:locale`.
|
|
28
|
+
|
|
29
|
+
---
|
|
30
|
+
|
|
31
|
+
## What's New in 11.9.x
|
|
32
|
+
|
|
33
|
+
### 1. ErrorCodeModule - Centralized Error Handling with i18n
|
|
34
|
+
|
|
35
|
+
The new ErrorCodeModule provides a centralized system for error codes with internationalization support.
|
|
36
|
+
|
|
37
|
+
#### Features
|
|
38
|
+
|
|
39
|
+
- **REST API** for error translations (Nuxt i18n compatible)
|
|
40
|
+
- **Type-safe error codes** with `ErrorCode` constant
|
|
41
|
+
- **Extensible** for project-specific error codes
|
|
42
|
+
- **Auto-registered** in CoreModule by default
|
|
43
|
+
|
|
44
|
+
#### New REST Endpoints
|
|
45
|
+
|
|
46
|
+
| Endpoint | Method | Description |
|
|
47
|
+
|----------|--------|-------------|
|
|
48
|
+
| `/api/i18n/errors/de` | GET | German error translations |
|
|
49
|
+
| `/api/i18n/errors/en` | GET | English error translations |
|
|
50
|
+
|
|
51
|
+
#### Response Format (Nuxt i18n compatible)
|
|
52
|
+
|
|
53
|
+
```json
|
|
54
|
+
{
|
|
55
|
+
"errors": {
|
|
56
|
+
"LTNS_0001": "Benutzer wurde nicht gefunden.",
|
|
57
|
+
"LTNS_0002": "Das eingegebene Passwort ist ungültig.",
|
|
58
|
+
"LTNS_0100": "Sie sind nicht angemeldet.",
|
|
59
|
+
"LTNS_0101": "Zugriff verweigert - Unzureichende Berechtigungen."
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
```
|
|
63
|
+
|
|
64
|
+
> **Note:** The translations returned by the i18n API are user-friendly messages intended for end users. They may differ from the technical error messages used in exceptions (e.g., `#LTNS_0100: Unauthorized - User is not logged in`).
|
|
65
|
+
|
|
66
|
+
#### Error Code Ranges
|
|
67
|
+
|
|
68
|
+
| Range | Category |
|
|
69
|
+
|-------|----------|
|
|
70
|
+
| LTNS_0001-0099 | Authentication errors |
|
|
71
|
+
| LTNS_0100-0199 | Authorization errors |
|
|
72
|
+
| LTNS_0200-0299 | User errors |
|
|
73
|
+
| LTNS_0300-0399 | Validation errors |
|
|
74
|
+
| LTNS_0400-0499 | Resource errors |
|
|
75
|
+
| LTNS_0500-0599 | File errors |
|
|
76
|
+
| LTNS_0900-0999 | Internal errors |
|
|
77
|
+
|
|
78
|
+
---
|
|
79
|
+
|
|
80
|
+
## Using Error Codes in Your Code
|
|
81
|
+
|
|
82
|
+
### Basic Usage
|
|
83
|
+
|
|
84
|
+
```typescript
|
|
85
|
+
import { UnauthorizedException, BadRequestException } from '@nestjs/common';
|
|
86
|
+
import { ErrorCode } from '@lenne.tech/nest-server';
|
|
87
|
+
|
|
88
|
+
// Throw with standardized error code
|
|
89
|
+
throw new UnauthorizedException(ErrorCode.UNAUTHORIZED);
|
|
90
|
+
// Response: { statusCode: 401, message: "#LTNS_0100: Unauthorized - User is not logged in" }
|
|
91
|
+
|
|
92
|
+
throw new BadRequestException(ErrorCode.VALIDATION_FAILED);
|
|
93
|
+
// Response: { statusCode: 400, message: "#LTNS_0300: Validation failed" }
|
|
94
|
+
```
|
|
95
|
+
|
|
96
|
+
### Available Error Codes
|
|
97
|
+
|
|
98
|
+
```typescript
|
|
99
|
+
ErrorCode.USER_NOT_FOUND // #LTNS_0001: User not found
|
|
100
|
+
ErrorCode.INVALID_PASSWORD // #LTNS_0002: Invalid password
|
|
101
|
+
ErrorCode.INVALID_TOKEN // #LTNS_0003: Invalid or malformed token
|
|
102
|
+
ErrorCode.TOKEN_EXPIRED // #LTNS_0004: Token has expired
|
|
103
|
+
ErrorCode.REFRESH_TOKEN_REQUIRED // #LTNS_0005: Refresh token required
|
|
104
|
+
ErrorCode.USER_NOT_VERIFIED // #LTNS_0006: User email not verified
|
|
105
|
+
ErrorCode.UNAUTHORIZED // #LTNS_0100: Unauthorized - User is not logged in
|
|
106
|
+
ErrorCode.ACCESS_DENIED // #LTNS_0101: Access denied - Insufficient permissions
|
|
107
|
+
ErrorCode.RESOURCE_FORBIDDEN // #LTNS_0102: Resource access forbidden
|
|
108
|
+
ErrorCode.EMAIL_ALREADY_EXISTS // #LTNS_0200: Email already registered
|
|
109
|
+
ErrorCode.USERNAME_ALREADY_EXISTS // #LTNS_0201: Username already taken
|
|
110
|
+
ErrorCode.VALIDATION_FAILED // #LTNS_0300: Validation failed
|
|
111
|
+
ErrorCode.REQUIRED_FIELD_MISSING // #LTNS_0301: Required field missing
|
|
112
|
+
ErrorCode.INVALID_FIELD_FORMAT // #LTNS_0302: Invalid field format
|
|
113
|
+
ErrorCode.RESOURCE_NOT_FOUND // #LTNS_0400: Resource not found
|
|
114
|
+
ErrorCode.RESOURCE_ALREADY_EXISTS // #LTNS_0401: Resource already exists
|
|
115
|
+
ErrorCode.FILE_NOT_FOUND // #LTNS_0500: File not found
|
|
116
|
+
ErrorCode.FILE_UPLOAD_FAILED // #LTNS_0501: File upload failed
|
|
117
|
+
ErrorCode.FILE_TYPE_NOT_ALLOWED // #LTNS_0502: File type not allowed
|
|
118
|
+
ErrorCode.INTERNAL_ERROR // #LTNS_0900: Internal server error
|
|
119
|
+
ErrorCode.SERVICE_UNAVAILABLE // #LTNS_0901: Service temporarily unavailable
|
|
120
|
+
ErrorCode.LEGACY_AUTH_DISABLED // #LTNS_0902: Legacy authentication is disabled
|
|
121
|
+
```
|
|
122
|
+
|
|
123
|
+
---
|
|
124
|
+
|
|
125
|
+
## Adding Project-Specific Error Codes (Optional)
|
|
126
|
+
|
|
127
|
+
### Scenario A: Simple Addition via Config (Recommended)
|
|
128
|
+
|
|
129
|
+
The easiest way to add project-specific error codes.
|
|
130
|
+
|
|
131
|
+
**1. Create error codes file:**
|
|
132
|
+
|
|
133
|
+
```typescript
|
|
134
|
+
// src/server/common/errors/project-errors.ts
|
|
135
|
+
import { IErrorRegistry, mergeErrorCodes } from '@lenne.tech/nest-server';
|
|
136
|
+
|
|
137
|
+
export const ProjectErrors = {
|
|
138
|
+
ORDER_NOT_FOUND: {
|
|
139
|
+
code: 'PROJ_0001',
|
|
140
|
+
message: 'Order not found',
|
|
141
|
+
translations: {
|
|
142
|
+
de: 'Bestellung mit ID {orderId} wurde nicht gefunden.',
|
|
143
|
+
en: 'Order with ID {orderId} was not found.',
|
|
144
|
+
},
|
|
145
|
+
},
|
|
146
|
+
PAYMENT_FAILED: {
|
|
147
|
+
code: 'PROJ_0002',
|
|
148
|
+
message: 'Payment processing failed',
|
|
149
|
+
translations: {
|
|
150
|
+
de: 'Die Zahlung konnte nicht verarbeitet werden: {reason}',
|
|
151
|
+
en: 'Payment processing failed: {reason}',
|
|
152
|
+
},
|
|
153
|
+
},
|
|
154
|
+
} as const satisfies IErrorRegistry;
|
|
155
|
+
|
|
156
|
+
// Merged error codes for type-safe usage
|
|
157
|
+
export const ErrorCode = mergeErrorCodes(ProjectErrors);
|
|
158
|
+
```
|
|
159
|
+
|
|
160
|
+
**2. Add to config.env.ts:**
|
|
161
|
+
|
|
162
|
+
```typescript
|
|
163
|
+
import { ProjectErrors } from './server/common/errors/project-errors';
|
|
164
|
+
|
|
165
|
+
const config = {
|
|
166
|
+
// ... other config ...
|
|
167
|
+
errorCode: {
|
|
168
|
+
additionalErrorRegistry: ProjectErrors,
|
|
169
|
+
},
|
|
170
|
+
};
|
|
171
|
+
```
|
|
172
|
+
|
|
173
|
+
**Done!** Your project errors are now available via `/api/i18n/errors/:locale`.
|
|
174
|
+
|
|
175
|
+
### Scenario B: Custom Service (For Additional Locales)
|
|
176
|
+
|
|
177
|
+
Use this when you need additional locales beyond German and English.
|
|
178
|
+
|
|
179
|
+
See [INTEGRATION-CHECKLIST.md](../src/core/modules/error-code/INTEGRATION-CHECKLIST.md) for detailed instructions.
|
|
180
|
+
|
|
181
|
+
### Scenario C: Custom Controller (For Custom Routes)
|
|
182
|
+
|
|
183
|
+
Use this when you need custom endpoints like `/codes` listing.
|
|
184
|
+
|
|
185
|
+
See [INTEGRATION-CHECKLIST.md](../src/core/modules/error-code/INTEGRATION-CHECKLIST.md) for detailed instructions.
|
|
186
|
+
|
|
187
|
+
---
|
|
188
|
+
|
|
189
|
+
## Configuration Reference
|
|
190
|
+
|
|
191
|
+
### New Config Option: errorCode
|
|
192
|
+
|
|
193
|
+
```typescript
|
|
194
|
+
// config.env.ts
|
|
195
|
+
const config: IServerOptions = {
|
|
196
|
+
// ... other config ...
|
|
197
|
+
|
|
198
|
+
/**
|
|
199
|
+
* ErrorCodeModule configuration (new in 11.9.0)
|
|
200
|
+
*/
|
|
201
|
+
errorCode: {
|
|
202
|
+
/**
|
|
203
|
+
* Additional error registry to merge with core LTNS_* errors
|
|
204
|
+
* @optional
|
|
205
|
+
*/
|
|
206
|
+
additionalErrorRegistry: ProjectErrors,
|
|
207
|
+
|
|
208
|
+
/**
|
|
209
|
+
* Auto-register ErrorCodeModule in CoreModule
|
|
210
|
+
* Set to false to provide your own module with custom controller/service
|
|
211
|
+
* @default true
|
|
212
|
+
*/
|
|
213
|
+
autoRegister: true,
|
|
214
|
+
},
|
|
215
|
+
};
|
|
216
|
+
```
|
|
217
|
+
|
|
218
|
+
---
|
|
219
|
+
|
|
220
|
+
## Compatibility Notes
|
|
221
|
+
|
|
222
|
+
### Existing Projects
|
|
223
|
+
|
|
224
|
+
- **No changes required** - ErrorCodeModule is auto-registered and provides translations immediately
|
|
225
|
+
- **Existing error handling** continues to work unchanged
|
|
226
|
+
- **New error codes** are opt-in and can be adopted gradually
|
|
227
|
+
|
|
228
|
+
### Custom Auth Implementations
|
|
229
|
+
|
|
230
|
+
If your project extends CoreAuthService or CoreAuthResolver, you can now use standardized error codes:
|
|
231
|
+
|
|
232
|
+
```typescript
|
|
233
|
+
// Before (still works)
|
|
234
|
+
throw new UnauthorizedException('Invalid password');
|
|
235
|
+
|
|
236
|
+
// After (recommended)
|
|
237
|
+
import { ErrorCode } from '@lenne.tech/nest-server';
|
|
238
|
+
throw new UnauthorizedException(ErrorCode.INVALID_PASSWORD);
|
|
239
|
+
```
|
|
240
|
+
|
|
241
|
+
---
|
|
242
|
+
|
|
243
|
+
## Troubleshooting
|
|
244
|
+
|
|
245
|
+
### Error translations not loading
|
|
246
|
+
|
|
247
|
+
**Symptom:** `/api/i18n/errors/de` returns 404
|
|
248
|
+
|
|
249
|
+
**Solution:** Ensure you're on version 11.9.x and the server has been restarted:
|
|
250
|
+
|
|
251
|
+
```bash
|
|
252
|
+
npm install @lenne.tech/nest-server@11.9.x
|
|
253
|
+
npm run build
|
|
254
|
+
npm run start:dev
|
|
255
|
+
```
|
|
256
|
+
|
|
257
|
+
### Custom errors not appearing
|
|
258
|
+
|
|
259
|
+
**Symptom:** Project-specific errors not in translation response
|
|
260
|
+
|
|
261
|
+
**Solution:** Verify your config.env.ts includes the additionalErrorRegistry:
|
|
262
|
+
|
|
263
|
+
```typescript
|
|
264
|
+
import { ProjectErrors } from './server/common/errors/project-errors';
|
|
265
|
+
|
|
266
|
+
errorCode: {
|
|
267
|
+
additionalErrorRegistry: ProjectErrors,
|
|
268
|
+
}
|
|
269
|
+
```
|
|
270
|
+
|
|
271
|
+
### Route conflict with custom controller
|
|
272
|
+
|
|
273
|
+
**Symptom:** `/codes` endpoint returns locale error
|
|
274
|
+
|
|
275
|
+
**Solution:** Use a standalone controller (not extending CoreErrorCodeController). See the INTEGRATION-CHECKLIST.md for details.
|
|
276
|
+
|
|
277
|
+
---
|
|
278
|
+
|
|
279
|
+
## Module Documentation
|
|
280
|
+
|
|
281
|
+
### ErrorCodeModule
|
|
282
|
+
|
|
283
|
+
- **Integration Checklist:** [src/core/modules/error-code/INTEGRATION-CHECKLIST.md](../src/core/modules/error-code/INTEGRATION-CHECKLIST.md)
|
|
284
|
+
- **Reference Implementation:** `src/server/modules/error-code/`
|
|
285
|
+
- **Key Files:**
|
|
286
|
+
- `error-codes.ts` - Core error definitions and ErrorCode constant
|
|
287
|
+
- `core-error-code.service.ts` - Service for translation handling
|
|
288
|
+
- `core-error-code.controller.ts` - REST controller
|
|
289
|
+
- `interfaces/error-code.interfaces.ts` - Type definitions
|
|
290
|
+
|
|
291
|
+
---
|
|
292
|
+
|
|
293
|
+
## New Exports
|
|
294
|
+
|
|
295
|
+
The following are now exported from `@lenne.tech/nest-server`:
|
|
296
|
+
|
|
297
|
+
```typescript
|
|
298
|
+
// Error Code types and constants
|
|
299
|
+
export { ErrorCode } from './core/modules/error-code/error-codes';
|
|
300
|
+
export { LtnsErrors } from './core/modules/error-code/error-codes';
|
|
301
|
+
export { IErrorDefinition, IErrorRegistry, ErrorCodeKey, ErrorCodeType, RawErrorCode } from './core/modules/error-code/error-codes';
|
|
302
|
+
export { getAllErrorDefinitions, mergeErrorCodes } from './core/modules/error-code/error-codes';
|
|
303
|
+
|
|
304
|
+
// Module and services
|
|
305
|
+
export { ErrorCodeModule } from './core/modules/error-code/error-code.module';
|
|
306
|
+
export { CoreErrorCodeService } from './core/modules/error-code/core-error-code.service';
|
|
307
|
+
export { CoreErrorCodeController } from './core/modules/error-code/core-error-code.controller';
|
|
308
|
+
|
|
309
|
+
// Interfaces
|
|
310
|
+
export { IErrorCodeModuleConfig, IErrorTranslationResponse, SupportedLocale } from './core/modules/error-code/interfaces/error-code.interfaces';
|
|
311
|
+
|
|
312
|
+
// Config interface
|
|
313
|
+
export { IErrorCode } from './core/common/interfaces/server-options.interface';
|
|
314
|
+
```
|
|
315
|
+
|
|
316
|
+
---
|
|
317
|
+
|
|
318
|
+
## References
|
|
319
|
+
|
|
320
|
+
- [ErrorCodeModule Integration Checklist](../src/core/modules/error-code/INTEGRATION-CHECKLIST.md)
|
|
321
|
+
- [nest-server-starter](https://github.com/lenneTech/nest-server-starter) (reference implementation)
|
|
322
|
+
- [Error Code Documentation](../docs/error-codes.md) (if available)
|