@lenne.tech/nest-server 12.6.11 → 12.6.13

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 (98) hide show
  1. package/.claude/rules/package-management.md +7 -7
  2. package/.claude/rules/role-system.md +10 -0
  3. package/.claude/rules/testing.md +4 -4
  4. package/FRAMEWORK-API.md +1 -1
  5. package/dist/core/common/decorators/rest-user.decorator.js +4 -0
  6. package/dist/core/common/decorators/rest-user.decorator.js.map +1 -1
  7. package/dist/core/common/filters/http-exception-log.filter.js +4 -0
  8. package/dist/core/common/filters/http-exception-log.filter.js.map +1 -1
  9. package/dist/core/common/helpers/byte-range.helper.d.ts +8 -0
  10. package/dist/core/common/helpers/byte-range.helper.js +71 -0
  11. package/dist/core/common/helpers/byte-range.helper.js.map +1 -0
  12. package/dist/core/common/helpers/context.helper.js +9 -0
  13. package/dist/core/common/helpers/context.helper.js.map +1 -1
  14. package/dist/core/common/helpers/decorator.helper.js +4 -0
  15. package/dist/core/common/helpers/decorator.helper.js.map +1 -1
  16. package/dist/core/common/helpers/execution-context-request.helper.d.ts +9 -1
  17. package/dist/core/common/helpers/execution-context-request.helper.js +29 -0
  18. package/dist/core/common/helpers/execution-context-request.helper.js.map +1 -1
  19. package/dist/core/common/helpers/graphql-upload.helper.d.ts +10 -0
  20. package/dist/core/common/helpers/graphql-upload.helper.js +220 -0
  21. package/dist/core/common/helpers/graphql-upload.helper.js.map +1 -0
  22. package/dist/core/common/helpers/gridfs.helper.d.ts +7 -2
  23. package/dist/core/common/helpers/gridfs.helper.js +7 -4
  24. package/dist/core/common/helpers/gridfs.helper.js.map +1 -1
  25. package/dist/core/common/interceptors/translate-response.interceptor.js +4 -0
  26. package/dist/core/common/interceptors/translate-response.interceptor.js.map +1 -1
  27. package/dist/core/common/services/core-s3.service.d.ts +3 -0
  28. package/dist/core/common/services/core-s3.service.js +8 -1
  29. package/dist/core/common/services/core-s3.service.js.map +1 -1
  30. package/dist/core/modules/auth/guards/auth.guard.js +10 -2
  31. package/dist/core/modules/auth/guards/auth.guard.js.map +1 -1
  32. package/dist/core/modules/auth/guards/legacy-auth-rate-limit.guard.js +4 -1
  33. package/dist/core/modules/auth/guards/legacy-auth-rate-limit.guard.js.map +1 -1
  34. package/dist/core/modules/auth/guards/roles.guard.js +11 -1
  35. package/dist/core/modules/auth/guards/roles.guard.js.map +1 -1
  36. package/dist/core/modules/better-auth/better-auth-roles.guard.js +15 -1
  37. package/dist/core/modules/better-auth/better-auth-roles.guard.js.map +1 -1
  38. package/dist/core/modules/error-code/error-codes.d.ts +9 -0
  39. package/dist/core/modules/error-code/error-codes.js +8 -0
  40. package/dist/core/modules/error-code/error-codes.js.map +1 -1
  41. package/dist/core/modules/file/core-file.controller.d.ts +5 -0
  42. package/dist/core/modules/file/core-file.controller.js +66 -4
  43. package/dist/core/modules/file/core-file.controller.js.map +1 -1
  44. package/dist/core/modules/file/core-file.service.d.ts +2 -0
  45. package/dist/core/modules/file/core-file.service.js +17 -6
  46. package/dist/core/modules/file/core-file.service.js.map +1 -1
  47. package/dist/core/modules/file/filesystem-file.helper.d.ts +2 -1
  48. package/dist/core/modules/file/filesystem-file.helper.js +2 -2
  49. package/dist/core/modules/file/filesystem-file.helper.js.map +1 -1
  50. package/dist/core/modules/file/interfaces/file-service-options.interface.d.ts +2 -0
  51. package/dist/core/modules/file/s3-file.helper.d.ts +2 -0
  52. package/dist/core/modules/file/s3-file.helper.js.map +1 -1
  53. package/dist/core/modules/tenant/core-tenant.guard.js +9 -1
  54. package/dist/core/modules/tenant/core-tenant.guard.js.map +1 -1
  55. package/dist/core.module.js +2 -1
  56. package/dist/core.module.js.map +1 -1
  57. package/dist/index.d.ts +2 -0
  58. package/dist/index.js +2 -0
  59. package/dist/index.js.map +1 -1
  60. package/dist/server/modules/error-code/error-codes.d.ts +1 -0
  61. package/dist/test/test.helper.d.ts +1 -0
  62. package/dist/test/test.helper.js +6 -0
  63. package/dist/test/test.helper.js.map +1 -1
  64. package/dist/types/graphql-upload.d.ts +34 -2
  65. package/docs/REQUEST-LIFECYCLE.md +31 -9
  66. package/docs/error-codes.md +14 -0
  67. package/docs/security-overrides.md +34 -6
  68. package/migration-guides/12.6.11-to-12.6.12.md +180 -0
  69. package/migration-guides/12.6.12-to-12.6.13.md +162 -0
  70. package/package.json +15 -8
  71. package/src/core/common/decorators/rest-user.decorator.ts +6 -0
  72. package/src/core/common/filters/http-exception-log.filter.ts +9 -0
  73. package/src/core/common/helpers/byte-range.helper.ts +144 -0
  74. package/src/core/common/helpers/context.helper.ts +14 -0
  75. package/src/core/common/helpers/decorator.helper.ts +5 -0
  76. package/src/core/common/helpers/execution-context-request.helper.ts +78 -1
  77. package/src/core/common/helpers/graphql-upload.helper.ts +482 -0
  78. package/src/core/common/helpers/gridfs.helper.ts +20 -6
  79. package/src/core/common/interceptors/translate-response.interceptor.ts +8 -0
  80. package/src/core/common/services/core-s3.service.ts +16 -2
  81. package/src/core/modules/auth/guards/auth.guard.ts +19 -2
  82. package/src/core/modules/auth/guards/legacy-auth-rate-limit.guard.ts +9 -2
  83. package/src/core/modules/auth/guards/roles.guard.ts +23 -1
  84. package/src/core/modules/better-auth/better-auth-roles.guard.ts +29 -1
  85. package/src/core/modules/error-code/error-codes.ts +13 -0
  86. package/src/core/modules/file/INTEGRATION-CHECKLIST.md +1 -0
  87. package/src/core/modules/file/README.md +74 -1
  88. package/src/core/modules/file/core-file.controller.ts +139 -3
  89. package/src/core/modules/file/core-file.service.ts +33 -13
  90. package/src/core/modules/file/filesystem-file.helper.ts +8 -3
  91. package/src/core/modules/file/interfaces/file-service-options.interface.ts +13 -0
  92. package/src/core/modules/file/s3-file.helper.ts +3 -2
  93. package/src/core/modules/tenant/core-tenant.guard.ts +13 -1
  94. package/src/core.module.ts +5 -1
  95. package/src/index.ts +2 -0
  96. package/src/test/README.md +8 -4
  97. package/src/test/test.helper.ts +12 -0
  98. package/src/types/graphql-upload.d.ts +34 -2
@@ -15,6 +15,7 @@ import graphqlUploadExpress from 'graphql-upload/graphqlUploadExpress.mjs';
15
15
 
16
16
  import { MongooseCastErrorFilter } from './core/common/filters/mongoose-cast-error.filter.js';
17
17
  import { merge } from './core/common/helpers/config.helper.js';
18
+ import { processGraphQlUploadRequest } from './core/common/helpers/graphql-upload.helper.js';
18
19
  import { refuseWsHandshake, registerWsConnection } from './core/common/helpers/graphql-ws-connection.helper.js';
19
20
  import {
20
21
  buildRequestContextAwareExecute,
@@ -122,7 +123,10 @@ export class CoreModule implements NestModule {
122
123
  // config read here and the values there.
123
124
  consumer.apply(SecurityHeadersMiddleware).forRoutes('*');
124
125
  if (CoreModule.graphQlEnabled) {
125
- consumer.apply(graphqlUploadExpress()).forRoutes('graphql');
126
+ // The framework's processRequest, never graphql-upload's default: the default (graphql-upload < 18.0.2) lets
127
+ // one anonymous multipart request crash the process (GHSA-5vm7-vc2x-p3w2) and leaks temporary files on
128
+ // duplicate file fields (GHSA-qwwm-252j-9whw). This middleware runs before any authentication.
129
+ consumer.apply(graphqlUploadExpress({ processRequest: processGraphQlUploadRequest })).forRoutes('graphql');
126
130
  }
127
131
  }
128
132
 
package/src/index.ts CHANGED
@@ -30,6 +30,7 @@ export * from './core/common/enums/sort-order.emum.js';
30
30
  export * from './core/common/exceptions/access-denied.exception.js';
31
31
  export * from './core/common/filters/http-exception-log.filter.js';
32
32
  export * from './core/common/filters/mongoose-cast-error.filter.js';
33
+ export * from './core/common/helpers/byte-range.helper.js';
33
34
  export * from './core/common/helpers/common.helper.js';
34
35
  export * from './core/common/helpers/config.helper.js';
35
36
  export * from './core/common/helpers/config-endpoint.helper.js';
@@ -43,6 +44,7 @@ export * from './core/common/helpers/execution-context-request.helper.js';
43
44
  export * from './core/common/helpers/file.helper.js';
44
45
  export * from './core/common/helpers/filter.helper.js';
45
46
  export * from './core/common/helpers/graphql.helper.js';
47
+ export * from './core/common/helpers/graphql-upload.helper.js';
46
48
  export * from './core/common/helpers/graphql-ws-connection.helper.js';
47
49
  export * from './core/common/helpers/graphql-ws-context.helper.js';
48
50
  export * from './core/common/helpers/idle-stream.helper.js';
@@ -205,10 +205,11 @@ await fs.promises.writeFile('/tmp/downloaded.bin', buffer);
205
205
 
206
206
  The second parameter accepts either a plain token string or a `TestDownloadOptions` object:
207
207
 
208
- | Option | Type | Description |
209
- | --------- | -------- | ------------------------------------------------------------- |
210
- | `token` | `string` | Bearer token via Authorization header (JWT) |
211
- | `cookies` | `string` | Plain session token, converted via `buildBetterAuthCookies()` |
208
+ | Option | Type | Description |
209
+ | --------- | ------------------------ | ------------------------------------------------------------- |
210
+ | `token` | `string` | Bearer token via Authorization header (JWT) |
211
+ | `cookies` | `string` | Plain session token, converted via `buildBetterAuthCookies()` |
212
+ | `headers` | `Record<string, string>` | Additional request headers, e.g. `Range` (since 12.6.12) |
212
213
 
213
214
  Both can be used simultaneously — `token` sets the Authorization header while `cookies` sets the Cookie header.
214
215
 
@@ -224,6 +225,9 @@ await testHelper.download('/files/id/abc123', { cookies: sessionToken });
224
225
 
225
226
  // Both simultaneously
226
227
  await testHelper.download('/files/id/abc123', { cookies: sessionToken, token: jwtToken });
228
+
229
+ // A byte range: 206, `Content-Range: bytes 0-1/<length>`, two bytes in `res.data`
230
+ const res = await testHelper.download('/files/id/abc123', { headers: { Range: 'bytes=0-1' }, token: jwtToken });
227
231
  ```
228
232
 
229
233
  ## GraphQL Testing (`testHelper.graphQl()`)
@@ -190,6 +190,12 @@ export interface TestDownloadOptions {
190
190
  */
191
191
  cookies?: string;
192
192
 
193
+ /**
194
+ * Additional request headers, e.g. `{ Range: 'bytes=0-1' }` for a ranged download or `If-None-Match`.
195
+ * Set before `cookies` and `token`, which win for their own header. Since 12.6.12.
196
+ */
197
+ headers?: Record<string, string>;
198
+
193
199
  /**
194
200
  * Bearer token via Authorization header (JWT authentication).
195
201
  * Can be used simultaneously with `cookies` — token sets the Authorization header
@@ -386,6 +392,9 @@ export class TestHelper {
386
392
  if (typeof tokenOrOptions === 'string') {
387
393
  request.set('Authorization', `bearer ${tokenOrOptions}`);
388
394
  } else if (tokenOrOptions) {
395
+ for (const [name, value] of Object.entries(tokenOrOptions.headers ?? {})) {
396
+ request.set(name, value);
397
+ }
389
398
  if (tokenOrOptions.cookies) {
390
399
  const cookieRecord = TestHelper.buildBetterAuthCookies(tokenOrOptions.cookies);
391
400
  request.set(
@@ -431,6 +440,9 @@ export class TestHelper {
431
440
  if (typeof tokenOrOptions === 'string') {
432
441
  request.set('Authorization', `bearer ${tokenOrOptions}`);
433
442
  } else if (tokenOrOptions) {
443
+ for (const [name, value] of Object.entries(tokenOrOptions.headers ?? {})) {
444
+ request.set(name, value);
445
+ }
434
446
  if (tokenOrOptions.cookies) {
435
447
  const cookieRecord = TestHelper.buildBetterAuthCookies(tokenOrOptions.cookies);
436
448
  request.set(
@@ -4,21 +4,53 @@
4
4
  *
5
5
  * Since graphql-upload 16 the package is ESM: its `exports` map lists only the `.mjs` deep paths, each
6
6
  * with a default export, and it ships no declaration files (its types are JSDoc inside the `.mjs`
7
- * sources, which TypeScript does not read from `node_modules`). Both names below are the ones the
7
+ * sources, which TypeScript does not read from `node_modules`). The names below are the ones the
8
8
  * framework imports.
9
9
  */
10
10
 
11
11
  declare module 'graphql-upload/graphqlUploadExpress.mjs' {
12
12
  import { RequestHandler } from 'express';
13
+ import type { IncomingMessage, ServerResponse } from 'node:http';
13
14
 
14
- interface GraphQLUploadOptions {
15
+ interface GraphQLUploadProcessRequestOptions {
16
+ maxFieldSize?: number;
15
17
  maxFiles?: number;
16
18
  maxFileSize?: number;
17
19
  }
18
20
 
21
+ interface GraphQLUploadOptions extends GraphQLUploadProcessRequestOptions {
22
+ /**
23
+ * The function that parses the multipart request. graphql-upload's default is its own `processRequest`, which is
24
+ * vulnerable to GHSA-5vm7-vc2x-p3w2 and GHSA-qwwm-252j-9whw below 18.0.2 — pass the framework's
25
+ * `processGraphQlUploadRequest`.
26
+ */
27
+ processRequest?: (
28
+ request: IncomingMessage,
29
+ response: ServerResponse,
30
+ options?: GraphQLUploadProcessRequestOptions,
31
+ ) => Promise<unknown>;
32
+ }
33
+
19
34
  export default function graphqlUploadExpress(options?: GraphQLUploadOptions): RequestHandler;
20
35
  }
21
36
 
37
+ declare module 'graphql-upload/Upload.mjs' {
38
+ /**
39
+ * A file expected in a GraphQL multipart request, placed in the operations wherever the `map` names it. The
40
+ * `GraphQLUpload` scalar accepts a value only if it is `instanceof` this class, of the same graphql-upload copy.
41
+ */
42
+ export default class Upload {
43
+ /** The file's details once it streamed in (set by `resolve`). */
44
+ file?: unknown;
45
+ /** Resolves with the file's details; the scalar hands it to the resolver. */
46
+ promise: Promise<unknown>;
47
+ /** Rejects the upload (missing file, aborted request). */
48
+ reject: (error: Error) => void;
49
+ /** Resolves the upload with the file's details. */
50
+ resolve: (file: unknown) => void;
51
+ }
52
+ }
53
+
22
54
  declare module 'graphql-upload/GraphQLUpload.mjs' {
23
55
  import { GraphQLScalarType } from 'graphql';
24
56