@lenne.tech/nest-server 12.10.1 → 12.11.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 (123) hide show
  1. package/.claude/rules/better-auth.md +28 -0
  2. package/.claude/rules/configurable-features.md +11 -9
  3. package/.claude/rules/package-management.md +1 -1
  4. package/.claude/rules/role-system.md +4 -1
  5. package/.claude/rules/testing.md +4 -4
  6. package/CLAUDE.md +6 -1
  7. package/FRAMEWORK-API.md +2 -1
  8. package/dist/core/common/decorators/unified-field.decorator.js +5 -2
  9. package/dist/core/common/decorators/unified-field.decorator.js.map +1 -1
  10. package/dist/core/common/helpers/config.helper.js +31 -9
  11. package/dist/core/common/helpers/config.helper.js.map +1 -1
  12. package/dist/core/common/helpers/graceful-shutdown.helper.js +3 -1
  13. package/dist/core/common/helpers/graceful-shutdown.helper.js.map +1 -1
  14. package/dist/core/common/helpers/graphql-ws-connection.helper.d.ts +8 -3
  15. package/dist/core/common/helpers/graphql-ws-connection.helper.js +44 -0
  16. package/dist/core/common/helpers/graphql-ws-connection.helper.js.map +1 -1
  17. package/dist/core/common/helpers/http-stream-auth.helper.d.ts +13 -0
  18. package/dist/core/common/helpers/http-stream-auth.helper.js +90 -0
  19. package/dist/core/common/helpers/http-stream-auth.helper.js.map +1 -0
  20. package/dist/core/common/helpers/shutdown-state.helper.d.ts +3 -0
  21. package/dist/core/common/helpers/shutdown-state.helper.js +11 -0
  22. package/dist/core/common/helpers/shutdown-state.helper.js.map +1 -0
  23. package/dist/core/common/interfaces/cron-job-config-with-utc-offset.interface.d.ts +1 -1
  24. package/dist/core/common/interfaces/cron-job-config.interface.d.ts +1 -1
  25. package/dist/core/common/interfaces/server-options.interface.d.ts +14 -0
  26. package/dist/core/common/services/core-cron-jobs.service.d.ts +13 -0
  27. package/dist/core/common/services/core-cron-jobs.service.js +129 -4
  28. package/dist/core/common/services/core-cron-jobs.service.js.map +1 -1
  29. package/dist/core/modules/better-auth/better-auth.config.js +48 -4
  30. package/dist/core/modules/better-auth/better-auth.config.js.map +1 -1
  31. package/dist/core/modules/better-auth/core-better-auth-api.middleware.js +7 -3
  32. package/dist/core/modules/better-auth/core-better-auth-api.middleware.js.map +1 -1
  33. package/dist/core/modules/better-auth/core-better-auth-jwt-session.cache.d.ts +8 -0
  34. package/dist/core/modules/better-auth/core-better-auth-jwt-session.cache.js +47 -0
  35. package/dist/core/modules/better-auth/core-better-auth-jwt-session.cache.js.map +1 -0
  36. package/dist/core/modules/better-auth/core-better-auth-models.d.ts +1 -0
  37. package/dist/core/modules/better-auth/core-better-auth-models.js +7 -0
  38. package/dist/core/modules/better-auth/core-better-auth-models.js.map +1 -1
  39. package/dist/core/modules/better-auth/core-better-auth-session-token.helper.d.ts +1 -0
  40. package/dist/core/modules/better-auth/core-better-auth-session-token.helper.js +3 -1
  41. package/dist/core/modules/better-auth/core-better-auth-session-token.helper.js.map +1 -1
  42. package/dist/core/modules/better-auth/core-better-auth-sign-in-factors.helper.d.ts +11 -0
  43. package/dist/core/modules/better-auth/core-better-auth-sign-in-factors.helper.js +62 -0
  44. package/dist/core/modules/better-auth/core-better-auth-sign-in-factors.helper.js.map +1 -0
  45. package/dist/core/modules/better-auth/core-better-auth-user.mapper.d.ts +1 -0
  46. package/dist/core/modules/better-auth/core-better-auth-user.mapper.js +28 -1
  47. package/dist/core/modules/better-auth/core-better-auth-user.mapper.js.map +1 -1
  48. package/dist/core/modules/better-auth/core-better-auth.controller.js +3 -2
  49. package/dist/core/modules/better-auth/core-better-auth.controller.js.map +1 -1
  50. package/dist/core/modules/better-auth/core-better-auth.middleware.js +2 -2
  51. package/dist/core/modules/better-auth/core-better-auth.middleware.js.map +1 -1
  52. package/dist/core/modules/better-auth/core-better-auth.resolver.js +1 -0
  53. package/dist/core/modules/better-auth/core-better-auth.resolver.js.map +1 -1
  54. package/dist/core/modules/better-auth/core-better-auth.service.d.ts +16 -2
  55. package/dist/core/modules/better-auth/core-better-auth.service.js +109 -22
  56. package/dist/core/modules/better-auth/core-better-auth.service.js.map +1 -1
  57. package/dist/core/modules/health-check/core-health-check-readiness.controller.d.ts +6 -0
  58. package/dist/core/modules/health-check/core-health-check-readiness.controller.js +36 -0
  59. package/dist/core/modules/health-check/core-health-check-readiness.controller.js.map +1 -0
  60. package/dist/core/modules/health-check/core-health-check.helpers.d.ts +10 -0
  61. package/dist/core/modules/health-check/core-health-check.helpers.js +31 -0
  62. package/dist/core/modules/health-check/core-health-check.helpers.js.map +1 -0
  63. package/dist/core/modules/health-check/core-health-check.module.d.ts +9 -0
  64. package/dist/core/modules/health-check/core-health-check.module.js +13 -2
  65. package/dist/core/modules/health-check/core-health-check.module.js.map +1 -1
  66. package/dist/core/modules/health-check/core-health-check.service.d.ts +8 -1
  67. package/dist/core/modules/health-check/core-health-check.service.js +66 -29
  68. package/dist/core/modules/health-check/core-health-check.service.js.map +1 -1
  69. package/dist/core/modules/sync/core-sync.service.d.ts +2 -0
  70. package/dist/core/modules/sync/core-sync.service.js +11 -1
  71. package/dist/core/modules/sync/core-sync.service.js.map +1 -1
  72. package/dist/core.module.js +5 -1
  73. package/dist/core.module.js.map +1 -1
  74. package/dist/index.d.ts +4 -0
  75. package/dist/index.js +4 -0
  76. package/dist/index.js.map +1 -1
  77. package/dist/main.js.map +1 -1
  78. package/docs/.navigation.yml +4 -0
  79. package/docs/REQUEST-LIFECYCLE.md +8 -5
  80. package/docs/choosing-a-database.md +4 -1
  81. package/docs/error-codes.md +4 -1
  82. package/docs/index.md +34 -0
  83. package/docs/{brevo-manual-test.md → internal/brevo-manual-test.md} +1 -1
  84. package/docs/native-driver-security.md +4 -1
  85. package/docs/offline-sync-protocol.md +9 -4
  86. package/docs/process-performance-optimization.md +158 -126
  87. package/docs/security-overrides.md +5 -2
  88. package/migration-guides/12.10.x-to-12.11.x.md +297 -0
  89. package/migration-guides/12.11.0-to-12.11.1.md +86 -0
  90. package/package.json +20 -20
  91. package/src/core/common/decorators/unified-field.decorator.ts +14 -4
  92. package/src/core/common/helpers/config.helper.ts +55 -8
  93. package/src/core/common/helpers/graceful-shutdown.helper.ts +10 -3
  94. package/src/core/common/helpers/graphql-ws-connection.helper.ts +99 -4
  95. package/src/core/common/helpers/http-stream-auth.helper.ts +197 -0
  96. package/src/core/common/helpers/shutdown-state.helper.ts +28 -0
  97. package/src/core/common/interfaces/cron-job-config-with-utc-offset.interface.ts +1 -1
  98. package/src/core/common/interfaces/cron-job-config.interface.ts +1 -1
  99. package/src/core/common/interfaces/server-options.interface.ts +113 -1
  100. package/src/core/common/services/core-cron-jobs.service.ts +241 -14
  101. package/src/core/modules/better-auth/INTEGRATION-CHECKLIST.md +27 -10
  102. package/src/core/modules/better-auth/README.md +37 -8
  103. package/src/core/modules/better-auth/better-auth.config.ts +83 -12
  104. package/src/core/modules/better-auth/core-better-auth-api.middleware.ts +8 -4
  105. package/src/core/modules/better-auth/core-better-auth-jwt-session.cache.ts +104 -0
  106. package/src/core/modules/better-auth/core-better-auth-models.ts +5 -0
  107. package/src/core/modules/better-auth/core-better-auth-session-token.helper.ts +18 -1
  108. package/src/core/modules/better-auth/core-better-auth-sign-in-factors.helper.ts +105 -0
  109. package/src/core/modules/better-auth/core-better-auth-user.mapper.ts +37 -1
  110. package/src/core/modules/better-auth/core-better-auth.controller.ts +7 -4
  111. package/src/core/modules/better-auth/core-better-auth.middleware.ts +4 -3
  112. package/src/core/modules/better-auth/core-better-auth.module.ts +1 -1
  113. package/src/core/modules/better-auth/core-better-auth.resolver.ts +1 -0
  114. package/src/core/modules/better-auth/core-better-auth.service.ts +177 -31
  115. package/src/core/modules/health-check/core-health-check-readiness.controller.ts +27 -0
  116. package/src/core/modules/health-check/core-health-check.helpers.ts +65 -0
  117. package/src/core/modules/health-check/core-health-check.module.ts +37 -2
  118. package/src/core/modules/health-check/core-health-check.service.ts +154 -59
  119. package/src/core/modules/sync/README.md +18 -6
  120. package/src/core/modules/sync/core-sync.service.ts +35 -6
  121. package/src/core.module.ts +9 -1
  122. package/src/index.ts +4 -0
  123. package/src/main.ts +2 -1
@@ -1,22 +1,33 @@
1
- # nest-server: process() Performance-Optimierung
1
+ ---
2
+ title: "process() Performance Optimization"
3
+ description: "How the process() pipeline of CrudService avoids memory and CPU overhead on hot paths and service cascades, without weakening any security check."
4
+ ---
5
+
6
+ > **Status: implemented in 11.23.0** (see `migration-guides/11.22.x-to-11.23.0.md`). This page records the changes as
7
+ > they were made. The code excerpts and line numbers show the state at that time; the current implementation may
8
+ > differ in detail — the source files named below are authoritative.
2
9
 
3
- ## Kontext
10
+ ## Context
4
11
 
5
- Die `process()` Pipeline in `ModuleService` ist der zentrale Verarbeitungspfad fuer alle CRUD-Operationen. Bei hochfrequenten oder verschachtelten Aufrufen (Service-Kaskaden) entsteht unnoetig hoher Memory- und CPU-Verbrauch. Die folgenden Optimierungen reduzieren den Overhead ohne die Sicherheit herabzusetzen.
12
+ The `process()` pipeline in `ModuleService` is the central processing path for all CRUD operations. With
13
+ high-frequency or nested calls (service cascades) it caused unnecessarily high memory and CPU usage. The optimizations
14
+ below reduce the overhead without weakening security.
6
15
 
7
- **Analyse-Basis:** 8 Kundenprojekte + 13 lenne.tech-Projekte geprueft — alle Aenderungen sind rueckwaertskompatibel.
16
+ **Basis of the analysis:** 8 customer projects and 13 lenne.tech projects were checked — all changes are backward
17
+ compatible.
8
18
 
9
19
  ---
10
20
 
11
- ## Aenderung 1: JSON.stringify Debug konfigurierbar machen
21
+ ## Change 1: Make the JSON.stringify debug output configurable
12
22
 
13
- ### Datei: `src/core/common/services/module.service.ts`
23
+ ### File: `src/core/common/services/module.service.ts`
14
24
 
15
25
  ### Problem
16
26
 
17
- Zeilen 149-164 serialisieren den Input bei **jedem** process()-Aufruf zweimal (vorher/nachher) — nur fuer einen `console.debug` Vergleich. Das `new Promise(() => ...)` ist ein Fire-and-Forget ohne await.
27
+ Lines 149-164 serialized the input **twice** on every `process()` call (before and after) — only for a
28
+ `console.debug` comparison. The `new Promise(() => ...)` was fire-and-forget without `await`.
18
29
 
19
- ### Aktueller Code (Zeile 149-165)
30
+ ### Code before (lines 149-165)
20
31
 
21
32
  ```typescript
22
33
  const originalInput = config.input;
@@ -38,12 +49,12 @@ new Promise(() => {
38
49
  config.input = preparedInput;
39
50
  ```
40
51
 
41
- ### Neuer Code
52
+ ### New code
42
53
 
43
54
  ```typescript
44
55
  const preparedInput = await this.prepareInput(config.input, config);
45
56
 
46
- // Debug-Vergleich nur wenn explizit konfiguriert (default: false)
57
+ // Debug comparison only when explicitly configured (default: false)
47
58
  if (this.configService?.getFastButReadOnly('debugProcessInput', false)) {
48
59
  try {
49
60
  const originalJSON = JSON.stringify(config.input)?.replace(/"password":\s*"[^"]*"/, '');
@@ -57,16 +68,16 @@ if (this.configService?.getFastButReadOnly('debugProcessInput', false)) {
57
68
  );
58
69
  }
59
70
  } catch {
60
- // JSON.stringify kann bei zirkulaeren Referenzen fehlschlagen — ignorieren
71
+ // JSON.stringify can fail on circular references — ignore
61
72
  }
62
73
  }
63
74
 
64
75
  config.input = preparedInput;
65
76
  ```
66
77
 
67
- ### Datei: `src/core/common/interfaces/server-options.interface.ts`
78
+ ### File: `src/core/common/interfaces/server-options.interface.ts`
68
79
 
69
- In das `IServerOptions`-Interface (oder dem passenden Config-Bereich) hinzufuegen:
80
+ Added to the `IServerOptions` interface:
70
81
 
71
82
  ```typescript
72
83
  /**
@@ -76,27 +87,30 @@ In das `IServerOptions`-Interface (oder dem passenden Config-Bereich) hinzufuege
76
87
  debugProcessInput?: boolean;
77
88
  ```
78
89
 
79
- ### Sicherheit
90
+ ### Security
80
91
 
81
- Nicht betroffen — rein diagnostisch.
92
+ Not affected — purely diagnostic.
82
93
 
83
- ### Kompatibilitaet
94
+ ### Compatibility
84
95
 
85
- Default `false` — kein bestehendes Projekt aendert sein Verhalten.
96
+ Default `false` — no existing project changes its behavior.
86
97
 
87
98
  ---
88
99
 
89
- ## Aenderung 2: this.get(dbObject) durch Lean Query ersetzen
100
+ ## Change 2: Replace this.get(dbObject) with a lean query
90
101
 
91
- ### Datei: `src/core/common/services/module.service.ts`
102
+ ### File: `src/core/common/services/module.service.ts`
92
103
 
93
104
  ### Problem
94
105
 
95
- Zeilen 168-176 rufen `this.get()` auf, was **rekursiv** die gesamte process()-Pipeline durchlaeuft — inklusive prepareInput, checkRights, processFieldSelection, prepareOutput. Das ist unnoetig, weil das dbObject nur als Kontext fuer den Rights-Check gebraucht wird.
106
+ Lines 168-176 called `this.get()`, which runs the whole `process()` pipeline **recursively** — including
107
+ `prepareInput`, `checkRights`, `processFieldSelection` and `prepareOutput`. That is unnecessary, because the
108
+ `dbObject` is only needed as context for the rights check.
96
109
 
97
- Zusaetzlich ist es sogar **kontraproduktiv**: `this.get()` ohne `force` kann Felder wie `createdBy` entfernen (wegen `@Restricted(RoleEnum.ADMIN)`), die dann fuer den `S_CREATOR`-Check fehlen.
110
+ It was even **counterproductive**: `this.get()` without `force` can remove fields such as `createdBy` (because of
111
+ `@Restricted(RoleEnum.ADMIN)`), which are then missing for the `S_CREATOR` check.
98
112
 
99
- ### Aktueller Code (Zeile 168-176)
113
+ ### Code before (lines 168-176)
100
114
 
101
115
  ```typescript
102
116
  // Get DB object
@@ -110,7 +124,7 @@ if (config.dbObject && config.checkRights && this.checkRights) {
110
124
  }
111
125
  ```
112
126
 
113
- ### Neuer Code
127
+ ### New code
114
128
 
115
129
  ```typescript
116
130
  // Get DB object for rights checking — lean query to avoid recursive process() call.
@@ -132,38 +146,45 @@ if (config.dbObject && config.checkRights && this.checkRights) {
132
146
  }
133
147
  ```
134
148
 
135
- ### Sicherheit
149
+ ### Security
136
150
 
137
- **Verbessert** — lean Query behaelt alle Felder (z.B. `createdBy`), was den `S_CREATOR`-Check zuverlaessiger macht als der aktuelle Code.
151
+ **Improved** — the lean query keeps all fields (e.g. `createdBy`), which makes the `S_CREATOR` check more reliable
152
+ than the previous code.
138
153
 
139
- ### Nachfolgende Prozesse geprueft
154
+ ### Downstream steps checked
140
155
 
141
- - `checkRights(input)` (Zeile 179-184): Verwendet `config.dbObject` fuer `S_CREATOR`/`S_SELF`/`memberOf` Checks via `equalIds()` — funktioniert mit lean+map, da `equalIds` sowohl ObjectIds als auch Strings vergleicht.
142
- - `checkRights(output)` (Zeile 239-250): Gleiche Nutzung — funktioniert.
143
- - `validateRestricted()` in `checkRestricted()` (restricted.decorator.ts, Zeile 172-174): Prueft `'createdBy' in data && equalIds(data.createdBy, user)` — lean-Objekt hat `createdBy` immer (nicht entfernt durch Pipeline).
144
- - `memberOf`-Check (Zeile 196-218): Liest `config.dbObject?.[property]` — lean-Objekt hat alle Properties.
156
+ - `checkRights(input)` (lines 179-184): uses `config.dbObject` for the `S_CREATOR` / `S_SELF` / `memberOf` checks via
157
+ `equalIds()` — works with lean + map, because `equalIds` compares ObjectIds as well as strings.
158
+ - `checkRights(output)` (lines 239-250): same usage — works.
159
+ - `validateRestricted()` in `checkRestricted()` (`restricted.decorator.ts`, lines 172-174): checks
160
+ `'createdBy' in data && equalIds(data.createdBy, user)` — the lean object always has `createdBy` (not removed by the
161
+ pipeline).
162
+ - `memberOf` check (lines 196-218): reads `config.dbObject?.[property]` — the lean object has all properties.
145
163
 
146
- ### Kompatibilitaet
164
+ ### Compatibility
147
165
 
148
- - `CrudService.update()` (Zeile 552): Setzt `dbObject` bereits als lean-Objekt (`findById().lean()`) → konsistent.
149
- - Kein Projekt uebergibt ein Mongoose-Document als dbObject → kein Konflikt.
150
- - Services die `process()` direkt aufrufen mit `dbObject` als String (z.B. swaktiv/OfferService): Profitieren von der Optimierung.
166
+ - `CrudService.update()` (line 552) already sets `dbObject` as a lean object (`findById().lean()`) → consistent.
167
+ - No project passes a Mongoose document as `dbObject` → no conflict.
168
+ - Services that call `process()` directly with `dbObject` as a string (for example a project's own offer service)
169
+ benefit from the optimization.
151
170
 
152
171
  ---
153
172
 
154
- ## Aenderung 3: Depth-Tracking in RequestContext
173
+ ## Change 3: Depth tracking in RequestContext
155
174
 
156
- ### Datei: `src/core/common/services/request-context.service.ts`
175
+ ### File: `src/core/common/services/request-context.service.ts`
157
176
 
158
177
  ### Problem
159
178
 
160
- Bei Service-Kaskaden (A.create → B.create → C.create) laeuft die volle process()-Pipeline auf jeder Ebene. Populate, prepareOutput-Mapping und Output-checkRights auf inneren Ebenen sind unnoetig, weil die aeussere Ebene und der CheckSecurityInterceptor diese Aufgaben uebernehmen.
179
+ In service cascades (A.create → B.create → C.create) the full `process()` pipeline ran on every level. Populate,
180
+ `prepareOutput` mapping and the output `checkRights` on inner levels are unnecessary, because the outer level and the
181
+ `CheckSecurityInterceptor` take care of them.
161
182
 
162
- ### Aenderung am Interface
183
+ ### Change to the interface
163
184
 
164
185
  ```typescript
165
186
  export interface IRequestContext {
166
- // ... bestehende Felder ...
187
+ // ... existing fields ...
167
188
 
168
189
  /**
169
190
  * Tracks the nesting depth of process() calls.
@@ -175,7 +196,7 @@ export interface IRequestContext {
175
196
  }
176
197
  ```
177
198
 
178
- ### Neue Methoden
199
+ ### New methods
179
200
 
180
201
  ```typescript
181
202
  /**
@@ -201,19 +222,19 @@ static runWithIncrementedProcessDepth<T>(fn: () => T): T {
201
222
  }
202
223
  ```
203
224
 
204
- ### Sicherheit
225
+ ### Security
205
226
 
206
- Nicht betroffen — das Depth-Tracking ist rein informativ und aendert keine Berechtigungen.
227
+ Not affected — depth tracking is purely informational and changes no permissions.
207
228
 
208
229
  ---
209
230
 
210
- ## Aenderung 4: process() — Depth-basierte Optimierung
231
+ ## Change 4: Depth-based optimization in process()
211
232
 
212
- ### Datei: `src/core/common/services/module.service.ts`
233
+ ### File: `src/core/common/services/module.service.ts`
213
234
 
214
- ### Aenderung in process() (Zeile 81ff)
235
+ ### Change in process() (line 81 ff.)
215
236
 
216
- Am Anfang der Methode nach der Config-Erstellung (nach Zeile 108):
237
+ At the start of the method, after the config is created (after line 108):
217
238
 
218
239
  ```typescript
219
240
  // Detect nested process() calls
@@ -221,7 +242,7 @@ const currentDepth = RequestContext.getProcessDepth();
221
242
  const isNested = currentDepth > 0;
222
243
  ```
223
244
 
224
- ### serviceFunc mit Depth-Tracking ausfuehren (Zeile 201-205 ersetzen)
245
+ ### Run serviceFunc with depth tracking (replaces lines 201-205)
225
246
 
226
247
  ```typescript
227
248
  // Run service function with incremented depth
@@ -234,7 +255,7 @@ let result = config.force
234
255
  : await executeServiceFunc();
235
256
  ```
236
257
 
237
- ### processFieldSelection bei inneren Calls ueberspringen (Zeile 207-217 ersetzen)
258
+ ### Skip processFieldSelection on inner calls (replaces lines 207-217)
238
259
 
239
260
  ```typescript
240
261
  // Pop and map main model
@@ -254,12 +275,15 @@ if (config.processFieldSelection && config.fieldSelection && this.processFieldSe
254
275
  }
255
276
  ```
256
277
 
257
- **Logik:**
258
- - `isNested = false` (Depth 0, aeusserster Call): Populate laeuft immer → User bekommt vollstaendiges Ergebnis.
259
- - `isNested = true` (Depth > 0, innerer Call) OHNE `config.populate`: Populate wird uebersprungen → Ergebnis wird intern weiterverarbeitet.
260
- - `isNested = true` MIT `config.populate` (explizit vom Caller gesetzt): Populate laeuft → der innere Service hat das explizit angefordert weil er die Daten braucht.
278
+ **Logic:**
261
279
 
262
- ### prepareOutput bei inneren Calls reduzieren (Zeile 219-236 ersetzen)
280
+ - `isNested = false` (depth 0, outermost call): populate always runs → the user gets the complete result.
281
+ - `isNested = true` (depth > 0, inner call) WITHOUT `config.populate`: populate is skipped → the result is processed
282
+ further internally.
283
+ - `isNested = true` WITH `config.populate` (set explicitly by the caller): populate runs → the inner service asked for
284
+ it explicitly because it needs the data.
285
+
286
+ ### Reduce prepareOutput on inner calls (replaces lines 219-236)
263
287
 
264
288
  ```typescript
265
289
  // Prepare output
@@ -290,7 +314,7 @@ if (config.prepareOutput && this.prepareOutput) {
290
314
  }
291
315
  ```
292
316
 
293
- ### Output-checkRights bei inneren Calls ueberspringen (Zeile 238-250 ersetzen)
317
+ ### Skip the output checkRights on inner calls (replaces lines 238-250)
294
318
 
295
319
  ```typescript
296
320
  // Check output rights
@@ -310,38 +334,44 @@ if (!isNested && config.checkRights && (await this.checkRights(undefined, config
310
334
  }
311
335
  ```
312
336
 
313
- ### Sicherheit
337
+ ### Security
338
+
339
+ **Ensured by three layers:**
340
+
341
+ 1. **The input checkRights ALWAYS runs** (also when `isNested`) — unauthorized input is caught on every level.
342
+ 2. **The output checkRights runs at depth 0** — the outermost call filters the final result.
343
+ 3. **CheckSecurityInterceptor** — the last safety net in the HTTP response pipeline calls `securityCheck()`
344
+ recursively on the whole response tree, including every nested object.
314
345
 
315
- **Gewaehrleistet durch drei Schichten:**
346
+ **Counter-check:** What happens when an inner service returns an object the user may not see?
316
347
 
317
- 1. **Input-checkRights laeuft IMMER** (auch bei isNested) — unberechtigte Eingaben werden auf jeder Ebene abgefangen.
318
- 2. **Output-checkRights auf Depth 0** — der aeusserste Call filtert das finale Ergebnis.
319
- 3. **CheckSecurityInterceptor** — das letzte Sicherheitsnetz in der HTTP-Response-Pipeline ruft `securityCheck()` rekursiv auf dem gesamten Response-Baum auf, inklusive aller verschachtelten Objekte.
348
+ - The inner `process()` skips the output rights check → the object stays unchanged.
349
+ - The outer `process()` runs the output rights check → the fields are removed.
350
+ - If the outer `process()` misses it as well → `CheckSecurityInterceptor` removes the fields.
320
351
 
321
- **Gegenprobe:** Was passiert wenn ein innerer Service ein Objekt zurueckgibt das der User nicht sehen darf?
322
- - Der innere process() ueberspringt den Output-Rights-Check → Objekt bleibt unveraendert
323
- - Der aeussere process() fuehrt den Output-Rights-Check durch → Felder werden entfernt
324
- - Falls der aeussere process() es auch verpasst → CheckSecurityInterceptor entfernt die Felder
352
+ ### Compatibility
325
353
 
326
- ### Kompatibilitaet
354
+ Checked against real cascades:
327
355
 
328
- Geprueft an realen Kaskaden:
329
- - **CompanyService.create()** (5-Ebenen-Kaskade): Innere creates (ProfileSite, ProfileCategory, ProfileEntry, Form) brauchen kein Populate — Ergebnisse werden nur fuer IDs weiterverwendet.
330
- - **ParticipationService → UserService**: UserService.create() Ergebnis wird inline weiterverwendet, nicht an User zurueckgegeben.
331
- - **ShippingService → BounceService/EmailService**: Kein Populate auf inneren Ebenen noetig.
332
- - **Services mit explizitem `populate:`**: Funktionieren weiterhin, da `config.populate` den isNested-Skip ueberschreibt.
356
+ - **A five-level create cascade** (a company with its profile sites, categories, entries and forms): the inner creates
357
+ need no populate — their results are only used for their ids.
358
+ - **A participation service calling `UserService.create()`**: the result is used inline, not returned to the user.
359
+ - **A shipping service calling bounce and e-mail services**: no populate needed on inner levels.
360
+ - **Services with an explicit `populate:`** keep working, because `config.populate` overrides the `isNested` skip.
333
361
 
334
362
  ---
335
363
 
336
- ## Aenderung 5: checkRestricted Metadata-Caching
364
+ ## Change 5: Caching of the checkRestricted metadata
337
365
 
338
- ### Datei: `src/core/common/decorators/restricted.decorator.ts`
366
+ ### File: `src/core/common/decorators/restricted.decorator.ts`
339
367
 
340
368
  ### Problem
341
369
 
342
- `getRestricted()` (Zeile 50-58) ruft bei jedem Property-Check `Reflect.getMetadata()` auf. Bei einem Objekt mit 15 Properties und verschachtelten Objekten summieren sich hunderte Reflect-Lookups pro Request. Die Metadata aendert sich zur Laufzeit nie (Decorators sind statisch).
370
+ `getRestricted()` (lines 50-58) called `Reflect.getMetadata()` for every property check. For an object with 15
371
+ properties and nested objects, this adds up to hundreds of Reflect lookups per request. The metadata never changes at
372
+ runtime (decorators are static).
343
373
 
344
- ### Aktueller Code (Zeile 50-58)
374
+ ### Code before (lines 50-58)
345
375
 
346
376
  ```typescript
347
377
  export const getRestricted = (object: unknown, propertyKey?: string): RestrictedType => {
@@ -355,7 +385,7 @@ export const getRestricted = (object: unknown, propertyKey?: string): Restricted
355
385
  };
356
386
  ```
357
387
 
358
- ### Neuer Code
388
+ ### New code
359
389
 
360
390
  ```typescript
361
391
  // Cache for Restricted metadata — decorators are static, metadata never changes at runtime.
@@ -404,90 +434,92 @@ export const getRestricted = (object: unknown, propertyKey?: string): Restricted
404
434
  };
405
435
  ```
406
436
 
407
- ### Zusaetzlich: _.uniq()-Optimierung in checkRestricted (Zeile 260)
437
+ ### Additionally: _.uniq() optimization in checkRestricted (line 260)
408
438
 
409
439
  ```typescript
410
- // Aktuell:
440
+ // Before:
411
441
  const concatenatedRestrictions = config.mergeRoles ? _.uniq(objectRestrictions.concat(restricted)) : restricted;
412
442
 
413
- // Optimiert — vermeidet Array-Allokation wenn objectRestrictions leer:
443
+ // Optimized — avoids an array allocation when objectRestrictions is empty:
414
444
  const concatenatedRestrictions = config.mergeRoles && objectRestrictions.length
415
445
  ? _.uniq(objectRestrictions.concat(restricted))
416
446
  : restricted;
417
447
  ```
418
448
 
419
- Diese Zeile wird fuer **jede Property jedes Objekts** aufgerufen. Wenn `objectRestrictions` leer ist (haeufig bei Models ohne Class-Level `@Restricted`), spart das eine Array-Allokation + uniq-Berechnung pro Property.
449
+ This line runs for **every property of every object**. When `objectRestrictions` is empty (common for models without
450
+ a class-level `@Restricted`), it saves one array allocation and one `uniq` computation per property.
420
451
 
421
- ### Sicherheit
452
+ ### Security
422
453
 
423
- **Nicht betroffen** — gleiche Ergebnisse, da Decorator-Metadata sich zur Laufzeit nicht aendert. Der Cache liefert exakt die gleichen Werte wie der direkte Reflect-Lookup.
454
+ **Not affected** — same results, because decorator metadata does not change at runtime. The cache returns exactly the
455
+ values of the direct Reflect lookup.
424
456
 
425
- ### Kompatibilitaet
457
+ ### Compatibility
426
458
 
427
- Transparent — kein Projekt muss angepasst werden.
459
+ Transparent — no project needs to be adapted.
428
460
 
429
461
  ---
430
462
 
431
- ## Zusammenfassung der Einsparungen
463
+ ## Summary of the savings
432
464
 
433
- ### Einzelner API-Call (Depth 0, kein Nesting):
465
+ ### Single API call (depth 0, no nesting)
434
466
 
435
- | Aenderung | Einsparung |
436
- |-----------|------------|
437
- | JSON.stringify entfaellt | ~0.1-1 KB + 2x Serialisierung |
438
- | Lean dbObject statt this.get() | ~5-15 KB + 1 rekursiver process()-Durchlauf |
439
- | Metadata-Cache | CPU: ~hunderte Reflect-Lookups weniger |
467
+ | Change | Saving |
468
+ |--------|--------|
469
+ | No JSON.stringify | ~0.1-1 KB + 2 serializations |
470
+ | Lean dbObject instead of this.get() | ~5-15 KB + 1 recursive process() run |
471
+ | Metadata cache | CPU: hundreds of Reflect lookups fewer |
440
472
 
441
- ### Verschachtelter Call (Depth > 0):
473
+ ### Nested call (depth > 0)
442
474
 
443
- | Schritt | Vorher | Nachher |
444
- |---------|--------|---------|
445
- | JSON.stringify | 2x Serialisierung | Uebersprungen |
446
- | prepareInput | Laeuft | Laeuft (unveraendert) |
447
- | this.get(dbObject) | Rekursives process() | Lean Query + Map |
448
- | checkRights(input) | Laeuft | Laeuft (unveraendert) |
449
- | serviceFunc | Laeuft | Laeuft (unveraendert) |
450
- | processFieldSelection | Volle Population | Uebersprungen (ausser explizites populate) |
451
- | prepareOutput | Volles Mapping | Nur Secrets-Removal |
452
- | checkRights(output) | Laeuft | Uebersprungen |
475
+ | Step | Before | After |
476
+ |------|--------|-------|
477
+ | JSON.stringify | 2 serializations | Skipped |
478
+ | prepareInput | Runs | Runs (unchanged) |
479
+ | this.get(dbObject) | Recursive process() | Lean query + map |
480
+ | checkRights(input) | Runs | Runs (unchanged) |
481
+ | serviceFunc | Runs | Runs (unchanged) |
482
+ | processFieldSelection | Full population | Skipped (unless populate is explicit) |
483
+ | prepareOutput | Full mapping | Secret removal only |
484
+ | checkRights(output) | Runs | Skipped |
453
485
 
454
- **Pro verschachteltem Call: ~30-70 KB + 2-5 DB-Queries weniger.**
486
+ **Per nested call: ~30-70 KB and 2-5 database queries fewer.**
455
487
 
456
- ### Beispiel: 8-stufige Service-Kaskade (z.B. Incident-Handling):
488
+ ### Example: an 8-level service cascade (e.g. incident handling)
457
489
 
458
- - Vorher: 8 x ~50 KB = ~400 KB
459
- - Nachher: 1 x ~50 KB (aeusserer) + 7 x ~10 KB (innere) = ~120 KB
460
- - **~70% weniger Memory**
490
+ - Before: 8 × ~50 KB = ~400 KB
491
+ - After: 1 × ~50 KB (outer) + 7 × ~10 KB (inner) = ~120 KB
492
+ - **~70% less memory**
461
493
 
462
494
  ---
463
495
 
464
- ## Betroffene Dateien
496
+ ## Affected files
465
497
 
466
- | Datei | Aenderung |
467
- |-------|-----------|
468
- | `src/core/common/services/module.service.ts` | Aenderungen 1, 2, 4 |
469
- | `src/core/common/services/request-context.service.ts` | Aenderung 3 |
470
- | `src/core/common/decorators/restricted.decorator.ts` | Aenderung 5 |
471
- | `src/core/common/interfaces/server-options.interface.ts` | Config-Option `debugProcessInput` |
498
+ | File | Change |
499
+ |------|--------|
500
+ | `src/core/common/services/module.service.ts` | Changes 1, 2, 4 |
501
+ | `src/core/common/services/request-context.service.ts` | Change 3 |
502
+ | `src/core/common/decorators/restricted.decorator.ts` | Change 5 |
503
+ | `src/core/common/interfaces/server-options.interface.ts` | Config option `debugProcessInput` |
472
504
 
473
505
  ---
474
506
 
475
- ## Verifizierung
507
+ ## Verification
476
508
 
477
- 1. **Bestehende E2E-Tests** muessen alle gruen bleiben — die Aenderungen sind rueckwaertskompatibel
478
- 2. **Service-Kaskade testen**: z.B. ein create() das intern andere Services aufruft
479
- 3. **Populate auf aeusserster Ebene**: `{ populate: ['user', 'customer'] }` muss weiterhin funktionieren
480
- 4. **securityCheck()**: Sensitive Felder (password, etc.) duerfen nie in der Response auftauchen
481
- 5. **S_CREATOR-Check**: User der ein Objekt erstellt hat, muss es weiterhin bearbeiten koennen
482
- 6. **Performance**: `process.memoryUsage()` vor/nach Optimierung bei verschachtelten Calls messen
509
+ 1. **Existing E2E tests** must all stay green — the changes are backward compatible.
510
+ 2. **Test a service cascade**: e.g. a `create()` that calls other services internally.
511
+ 3. **Populate on the outermost level**: `{ populate: ['user', 'customer'] }` must keep working.
512
+ 4. **securityCheck()**: sensitive fields (password etc.) must never appear in the response.
513
+ 5. **S_CREATOR check**: the user who created an object must still be able to edit it.
514
+ 6. **Performance**: measure `process.memoryUsage()` before and after the optimization for nested calls.
483
515
 
484
516
  ---
485
517
 
486
- ## Risiken
518
+ ## Risks
487
519
 
488
- | Risiko | Absicherung |
489
- |--------|-------------|
490
- | Innerer Service braucht populate-Ergebnis | `config.populate` ueberschreibt den isNested-Skip — explizite Anforderung wird respektiert |
491
- | Output-Rights-Check auf innerem Ergebnis fehlt | CheckSecurityInterceptor ist das Sicherheitsnetz auf HTTP-Ebene |
492
- | Metadata-Cache wird stale | Unmoeglich — Decorator-Metadata ist zur Compile-Zeit fixiert |
493
- | Lean dbObject hat andere Struktur als hydriertes | `modelConstructor.map()` stellt die erwartete Struktur her |
520
+ | Risk | Safeguard |
521
+ |------|-----------|
522
+ | An inner service needs the populate result | `config.populate` overrides the `isNested` skip — an explicit request is respected |
523
+ | The output rights check on the inner result is missing | `CheckSecurityInterceptor` is the safety net on the HTTP level |
524
+ | The metadata cache becomes stale | Impossible — decorator metadata is fixed when the classes are defined |
525
+ | The lean `dbObject` has a different structure than a hydrated one | `modelConstructor.map()` restores the expected structure |
@@ -1,4 +1,7 @@
1
- # Security Overrides — and why yours are not inherited
1
+ ---
2
+ title: "Security Overrides — and why yours are not inherited"
3
+ description: "Why the pnpm overrides of nest-server do not reach your project, and how to keep the dependency tree of your project free of known vulnerabilities."
4
+ ---
2
5
 
3
6
  ## The problem in one sentence
4
7
 
@@ -227,6 +230,6 @@ These are the same rules the framework applies to itself
227
230
 
228
231
  ## Related
229
232
 
230
- - [`.claude/rules/package-management.md`](../.claude/rules/package-management.md) — fixed-version
233
+ - [`.claude/rules/package-management.md`](https://github.com/lenneTech/nest-server/blob/main/.claude/rules/package-management.md) — fixed-version
231
234
  policy, the pnpm pin contract, and the incident behind rule 1
232
235
  - `pnpm-workspace.yaml` in this package — the framework's own annotated override block