@lenne.tech/nest-server 11.18.0 → 11.20.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/dist/core/common/interfaces/server-options.interface.d.ts +6 -0
- package/dist/core/common/middleware/request-context.middleware.js +8 -0
- package/dist/core/common/middleware/request-context.middleware.js.map +1 -1
- package/dist/core/common/plugins/mongoose-audit-fields.plugin.js +72 -0
- package/dist/core/common/plugins/mongoose-audit-fields.plugin.js.map +1 -1
- package/dist/core/common/plugins/mongoose-password.plugin.js +35 -0
- package/dist/core/common/plugins/mongoose-password.plugin.js.map +1 -1
- package/dist/core/common/plugins/mongoose-role-guard.plugin.js +61 -0
- package/dist/core/common/plugins/mongoose-role-guard.plugin.js.map +1 -1
- package/dist/core/common/plugins/mongoose-tenant.plugin.d.ts +1 -0
- package/dist/core/common/plugins/mongoose-tenant.plugin.js +108 -0
- package/dist/core/common/plugins/mongoose-tenant.plugin.js.map +1 -0
- package/dist/core/common/services/request-context.service.d.ts +5 -0
- package/dist/core/common/services/request-context.service.js +14 -0
- package/dist/core/common/services/request-context.service.js.map +1 -1
- package/dist/core/modules/better-auth/core-better-auth.resolver.js +3 -1
- package/dist/core/modules/better-auth/core-better-auth.resolver.js.map +1 -1
- package/dist/core/modules/error-code/core-error-code.controller.js +1 -1
- package/dist/core/modules/error-code/core-error-code.controller.js.map +1 -1
- package/dist/core/modules/system-setup/core-system-setup.controller.js +1 -1
- package/dist/core/modules/system-setup/core-system-setup.controller.js.map +1 -1
- package/dist/core.module.js +4 -0
- package/dist/core.module.js.map +1 -1
- package/dist/index.d.ts +1 -0
- package/dist/index.js +1 -0
- package/dist/index.js.map +1 -1
- package/dist/server/modules/error-code/error-code.controller.js +1 -1
- package/dist/server/modules/error-code/error-code.controller.js.map +1 -1
- package/dist/tsconfig.build.tsbuildinfo +1 -1
- package/package.json +11 -12
- package/src/core/common/interfaces/server-options.interface.ts +82 -2
- package/src/core/common/middleware/request-context.middleware.ts +8 -1
- package/src/core/common/plugins/mongoose-audit-fields.plugin.ts +84 -0
- package/src/core/common/plugins/mongoose-password.plugin.ts +41 -1
- package/src/core/common/plugins/mongoose-role-guard.plugin.ts +65 -1
- package/src/core/common/plugins/mongoose-tenant.plugin.ts +165 -0
- package/src/core/common/services/request-context.service.ts +37 -0
- package/src/core/modules/better-auth/core-better-auth.resolver.ts +3 -1
- package/src/core/modules/error-code/INTEGRATION-CHECKLIST.md +8 -8
- package/src/core/modules/error-code/core-error-code.controller.ts +3 -3
- package/src/core/modules/error-code/interfaces/error-code.interfaces.ts +1 -1
- package/src/core/modules/system-setup/INTEGRATION-CHECKLIST.md +5 -5
- package/src/core/modules/system-setup/README.md +9 -9
- package/src/core/modules/system-setup/core-system-setup.controller.ts +1 -1
- package/src/core.module.ts +5 -0
- package/src/index.ts +1 -0
- package/src/server/modules/error-code/README.md +5 -5
- package/src/server/modules/error-code/error-code.controller.ts +3 -3
|
@@ -86,7 +86,7 @@ const config = {
|
|
|
86
86
|
};
|
|
87
87
|
```
|
|
88
88
|
|
|
89
|
-
**Done!** Your project errors are now available via `/
|
|
89
|
+
**Done!** Your project errors are now available via `/i18n/errors/:locale`.
|
|
90
90
|
|
|
91
91
|
---
|
|
92
92
|
|
|
@@ -221,14 +221,14 @@ After integration, verify:
|
|
|
221
221
|
|
|
222
222
|
- [ ] `npm run build` succeeds without errors
|
|
223
223
|
- [ ] `npm test` passes
|
|
224
|
-
- [ ] `GET /
|
|
225
|
-
- [ ] `GET /
|
|
224
|
+
- [ ] `GET /i18n/errors/de` returns your project error codes
|
|
225
|
+
- [ ] `GET /i18n/errors/en` returns English translations
|
|
226
226
|
- [ ] Error codes follow format `PREFIX_XXXX` (e.g., `PROJ_0001`)
|
|
227
227
|
- [ ] Translations include placeholders where needed (`{param}`)
|
|
228
228
|
|
|
229
229
|
### For Scenario C only:
|
|
230
230
|
|
|
231
|
-
- [ ] `GET /
|
|
231
|
+
- [ ] `GET /i18n/errors/codes` returns all error codes (if implemented)
|
|
232
232
|
|
|
233
233
|
---
|
|
234
234
|
|
|
@@ -269,10 +269,10 @@ const orderCode = ProjectErrorCode.ORDER_NOT_FOUND; // '#PROJ_0001: Order not fo
|
|
|
269
269
|
|
|
270
270
|
### REST Endpoints
|
|
271
271
|
|
|
272
|
-
| Endpoint
|
|
273
|
-
|
|
|
274
|
-
| `/
|
|
275
|
-
| `/
|
|
272
|
+
| Endpoint | Method | Description |
|
|
273
|
+
| ---------------------- | ------ | ----------------------------------------- |
|
|
274
|
+
| `/i18n/errors/:locale` | GET | Get translations for locale (de, en, ...) |
|
|
275
|
+
| `/i18n/errors/codes` | GET | Get all error codes (Scenario C only) |
|
|
276
276
|
|
|
277
277
|
### Response Format (Nuxt i18n compatible)
|
|
278
278
|
|
|
@@ -12,10 +12,10 @@ import { IErrorTranslationResponse, SupportedLocale } from './interfaces/error-c
|
|
|
12
12
|
* This controller is publicly accessible (no authentication required).
|
|
13
13
|
*
|
|
14
14
|
* @example
|
|
15
|
-
* GET /
|
|
16
|
-
* GET /
|
|
15
|
+
* GET /i18n/errors/de - Get German translations
|
|
16
|
+
* GET /i18n/errors/en - Get English translations
|
|
17
17
|
*/
|
|
18
|
-
@Controller('
|
|
18
|
+
@Controller('i18n/errors')
|
|
19
19
|
export class CoreErrorCodeController {
|
|
20
20
|
constructor(protected readonly errorCodeService: CoreErrorCodeService) {}
|
|
21
21
|
|
|
@@ -36,7 +36,7 @@ export interface IErrorCodeModuleConfig {
|
|
|
36
36
|
* @example
|
|
37
37
|
* ```typescript
|
|
38
38
|
* // Standalone controller (RECOMMENDED)
|
|
39
|
-
* @Controller('
|
|
39
|
+
* @Controller('i18n/errors')
|
|
40
40
|
* export class ErrorCodeController {
|
|
41
41
|
* constructor(protected readonly errorCodeService: ErrorCodeService) {}
|
|
42
42
|
*
|
|
@@ -68,7 +68,7 @@ Only needed if you want to add extra validation, logging, or custom fields.
|
|
|
68
68
|
import { Controller } from '@nestjs/common';
|
|
69
69
|
import { CoreSystemSetupController, Roles, RoleEnum } from '@lenne.tech/nest-server';
|
|
70
70
|
|
|
71
|
-
@Controller('
|
|
71
|
+
@Controller('system-setup')
|
|
72
72
|
@Roles(RoleEnum.ADMIN)
|
|
73
73
|
export class SystemSetupController extends CoreSystemSetupController {
|
|
74
74
|
// Override methods here for custom logic
|
|
@@ -83,10 +83,10 @@ export class SystemSetupController extends CoreSystemSetupController {
|
|
|
83
83
|
|
|
84
84
|
- [ ] `npm run build` succeeds
|
|
85
85
|
- [ ] `npm test` passes
|
|
86
|
-
- [ ] `GET /
|
|
87
|
-
- [ ] `POST /
|
|
88
|
-
- [ ] `GET /
|
|
89
|
-
- [ ] `POST /
|
|
86
|
+
- [ ] `GET /system-setup/status` returns `{ needsSetup: true }` on empty database
|
|
87
|
+
- [ ] `POST /system-setup/init` creates admin user with correct role
|
|
88
|
+
- [ ] `GET /system-setup/status` returns `{ needsSetup: false }` after init
|
|
89
|
+
- [ ] `POST /system-setup/init` returns 403 when users already exist
|
|
90
90
|
|
|
91
91
|
---
|
|
92
92
|
|
|
@@ -42,12 +42,12 @@ Once any user exists, the init endpoint is permanently locked (returns 403) and
|
|
|
42
42
|
|
|
43
43
|
## Endpoints
|
|
44
44
|
|
|
45
|
-
| Method | Endpoint
|
|
46
|
-
| ------ |
|
|
47
|
-
| GET | `/
|
|
48
|
-
| POST | `/
|
|
45
|
+
| Method | Endpoint | Description |
|
|
46
|
+
| ------ | ---------------------- | --------------------------- |
|
|
47
|
+
| GET | `/system-setup/status` | Check if system needs setup |
|
|
48
|
+
| POST | `/system-setup/init` | Create initial admin user |
|
|
49
49
|
|
|
50
|
-
### GET /
|
|
50
|
+
### GET /system-setup/status
|
|
51
51
|
|
|
52
52
|
Returns the current setup status.
|
|
53
53
|
|
|
@@ -60,7 +60,7 @@ Returns the current setup status.
|
|
|
60
60
|
}
|
|
61
61
|
```
|
|
62
62
|
|
|
63
|
-
### POST /
|
|
63
|
+
### POST /system-setup/init
|
|
64
64
|
|
|
65
65
|
Creates the initial admin user. Only works when zero users exist.
|
|
66
66
|
|
|
@@ -195,12 +195,12 @@ Typical frontend flow:
|
|
|
195
195
|
|
|
196
196
|
```typescript
|
|
197
197
|
// 1. Check if setup is needed
|
|
198
|
-
const status = await fetch('/
|
|
198
|
+
const status = await fetch('/system-setup/status');
|
|
199
199
|
const { needsSetup } = await status.json();
|
|
200
200
|
|
|
201
201
|
if (needsSetup) {
|
|
202
202
|
// 2. Show setup form and submit
|
|
203
|
-
const result = await fetch('/
|
|
203
|
+
const result = await fetch('/system-setup/init', {
|
|
204
204
|
method: 'POST',
|
|
205
205
|
headers: { 'Content-Type': 'application/json' },
|
|
206
206
|
body: JSON.stringify({
|
|
@@ -225,7 +225,7 @@ if (needsSetup) {
|
|
|
225
225
|
|
|
226
226
|
**Solutions:**
|
|
227
227
|
|
|
228
|
-
1. Check `GET /
|
|
228
|
+
1. Check `GET /system-setup/status` - `needsSetup` should be `true`
|
|
229
229
|
2. If this is a fresh deployment, verify the database is empty
|
|
230
230
|
|
|
231
231
|
### Init returns 403 "System setup requires BetterAuth"
|
|
@@ -35,7 +35,7 @@ export class SystemSetupInitDto {
|
|
|
35
35
|
* that no users exist before allowing creation.
|
|
36
36
|
*/
|
|
37
37
|
@ApiTags('System Setup')
|
|
38
|
-
@Controller('
|
|
38
|
+
@Controller('system-setup')
|
|
39
39
|
@Roles(RoleEnum.ADMIN)
|
|
40
40
|
export class CoreSystemSetupController {
|
|
41
41
|
constructor(protected readonly systemSetupService: CoreSystemSetupService) {}
|
package/src/core.module.ts
CHANGED
|
@@ -20,6 +20,7 @@ import { mongooseIdPlugin } from './core/common/plugins/mongoose-id.plugin';
|
|
|
20
20
|
import { mongooseAuditFieldsPlugin } from './core/common/plugins/mongoose-audit-fields.plugin';
|
|
21
21
|
import { mongoosePasswordPlugin } from './core/common/plugins/mongoose-password.plugin';
|
|
22
22
|
import { mongooseRoleGuardPlugin } from './core/common/plugins/mongoose-role-guard.plugin';
|
|
23
|
+
import { mongooseTenantPlugin } from './core/common/plugins/mongoose-tenant.plugin';
|
|
23
24
|
import { ConfigService } from './core/common/services/config.service';
|
|
24
25
|
import { EmailService } from './core/common/services/email.service';
|
|
25
26
|
import { MailjetService } from './core/common/services/mailjet.service';
|
|
@@ -214,6 +215,10 @@ export class CoreModule implements NestModule {
|
|
|
214
215
|
if (config.security?.mongooseAuditFieldsPlugin !== false) {
|
|
215
216
|
connection.plugin(mongooseAuditFieldsPlugin);
|
|
216
217
|
}
|
|
218
|
+
// Add tenant isolation plugin (opt-in via multiTenancy config)
|
|
219
|
+
if (config.multiTenancy && config.multiTenancy.enabled !== false) {
|
|
220
|
+
connection.plugin(mongooseTenantPlugin);
|
|
221
|
+
}
|
|
217
222
|
return connection;
|
|
218
223
|
};
|
|
219
224
|
|
package/src/index.ts
CHANGED
|
@@ -75,6 +75,7 @@ export * from './core/common/plugins/mongoose-id.plugin';
|
|
|
75
75
|
export * from './core/common/plugins/mongoose-audit-fields.plugin';
|
|
76
76
|
export * from './core/common/plugins/mongoose-password.plugin';
|
|
77
77
|
export * from './core/common/plugins/mongoose-role-guard.plugin';
|
|
78
|
+
export * from './core/common/plugins/mongoose-tenant.plugin';
|
|
78
79
|
export * from './core/common/scalars/any.scalar';
|
|
79
80
|
export * from './core/common/scalars/date-timestamp.scalar';
|
|
80
81
|
export * from './core/common/scalars/date.scalar';
|
|
@@ -33,9 +33,9 @@ Demonstrates **Scenario C: Custom Service + Controller via forRoot()** where a p
|
|
|
33
33
|
│ │ ErrorCodeService │ │ ErrorCodeController │ │
|
|
34
34
|
│ │ extends Core... │ │ (standalone - see below) │ │
|
|
35
35
|
│ │ │ │ │ │
|
|
36
|
-
│ │ - LTNS_* (core) │ │ GET /
|
|
37
|
-
│ │ - SRV_* (server) │ │ GET /
|
|
38
|
-
│ │ │ │ GET /
|
|
36
|
+
│ │ - LTNS_* (core) │ │ GET /i18n/errors/codes │ │
|
|
37
|
+
│ │ - SRV_* (server) │ │ GET /i18n/errors/de │ │
|
|
38
|
+
│ │ │ │ GET /i18n/errors/en │ │
|
|
39
39
|
│ └─────────────────────┘ └─────────────────────────────┘ │
|
|
40
40
|
└──────────────────────────────────────────────────────────────┘
|
|
41
41
|
```
|
|
@@ -107,7 +107,7 @@ static routes (`/codes`), even if you re-declare the methods.
|
|
|
107
107
|
|
|
108
108
|
```typescript
|
|
109
109
|
// DOES NOT WORK - parent route registered first!
|
|
110
|
-
@Controller('
|
|
110
|
+
@Controller('i18n/errors')
|
|
111
111
|
export class ErrorCodeController extends CoreErrorCodeController {
|
|
112
112
|
@Get('codes') // Registered AFTER parent's :locale
|
|
113
113
|
getAllCodes(): string[] {}
|
|
@@ -117,7 +117,7 @@ export class ErrorCodeController extends CoreErrorCodeController {
|
|
|
117
117
|
}
|
|
118
118
|
|
|
119
119
|
// WORKS - standalone ensures correct order
|
|
120
|
-
@Controller('
|
|
120
|
+
@Controller('i18n/errors')
|
|
121
121
|
export class ErrorCodeController {
|
|
122
122
|
@Get('codes') // Registered first
|
|
123
123
|
getAllCodes(): string[] {}
|
|
@@ -16,8 +16,8 @@ import { ErrorCodeService } from './error-code.service';
|
|
|
16
16
|
* correct route registration order.
|
|
17
17
|
*
|
|
18
18
|
* Endpoints:
|
|
19
|
-
* - GET /
|
|
20
|
-
* - GET /
|
|
19
|
+
* - GET /i18n/errors/codes - Get all available error codes (custom)
|
|
20
|
+
* - GET /i18n/errors/:locale - Get translations for a locale
|
|
21
21
|
*
|
|
22
22
|
* **WHY standalone instead of extending CoreErrorCodeController?**
|
|
23
23
|
* NestJS registers routes from parent classes first, regardless of method declaration
|
|
@@ -33,7 +33,7 @@ import { ErrorCodeService } from './error-code.service';
|
|
|
33
33
|
* })
|
|
34
34
|
* ```
|
|
35
35
|
*/
|
|
36
|
-
@Controller('
|
|
36
|
+
@Controller('i18n/errors')
|
|
37
37
|
export class ErrorCodeController {
|
|
38
38
|
constructor(protected readonly errorCodeService: ErrorCodeService) {}
|
|
39
39
|
|