@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.
- package/.claude/rules/package-management.md +7 -7
- package/.claude/rules/role-system.md +10 -0
- package/.claude/rules/testing.md +4 -4
- package/FRAMEWORK-API.md +1 -1
- package/dist/core/common/decorators/rest-user.decorator.js +4 -0
- package/dist/core/common/decorators/rest-user.decorator.js.map +1 -1
- package/dist/core/common/filters/http-exception-log.filter.js +4 -0
- package/dist/core/common/filters/http-exception-log.filter.js.map +1 -1
- package/dist/core/common/helpers/byte-range.helper.d.ts +8 -0
- package/dist/core/common/helpers/byte-range.helper.js +71 -0
- package/dist/core/common/helpers/byte-range.helper.js.map +1 -0
- package/dist/core/common/helpers/context.helper.js +9 -0
- package/dist/core/common/helpers/context.helper.js.map +1 -1
- package/dist/core/common/helpers/decorator.helper.js +4 -0
- package/dist/core/common/helpers/decorator.helper.js.map +1 -1
- package/dist/core/common/helpers/execution-context-request.helper.d.ts +9 -1
- package/dist/core/common/helpers/execution-context-request.helper.js +29 -0
- package/dist/core/common/helpers/execution-context-request.helper.js.map +1 -1
- package/dist/core/common/helpers/graphql-upload.helper.d.ts +10 -0
- package/dist/core/common/helpers/graphql-upload.helper.js +220 -0
- package/dist/core/common/helpers/graphql-upload.helper.js.map +1 -0
- package/dist/core/common/helpers/gridfs.helper.d.ts +7 -2
- package/dist/core/common/helpers/gridfs.helper.js +7 -4
- package/dist/core/common/helpers/gridfs.helper.js.map +1 -1
- package/dist/core/common/interceptors/translate-response.interceptor.js +4 -0
- package/dist/core/common/interceptors/translate-response.interceptor.js.map +1 -1
- package/dist/core/common/services/core-s3.service.d.ts +3 -0
- package/dist/core/common/services/core-s3.service.js +8 -1
- package/dist/core/common/services/core-s3.service.js.map +1 -1
- package/dist/core/modules/auth/guards/auth.guard.js +10 -2
- package/dist/core/modules/auth/guards/auth.guard.js.map +1 -1
- package/dist/core/modules/auth/guards/legacy-auth-rate-limit.guard.js +4 -1
- package/dist/core/modules/auth/guards/legacy-auth-rate-limit.guard.js.map +1 -1
- package/dist/core/modules/auth/guards/roles.guard.js +11 -1
- package/dist/core/modules/auth/guards/roles.guard.js.map +1 -1
- package/dist/core/modules/better-auth/better-auth-roles.guard.js +15 -1
- package/dist/core/modules/better-auth/better-auth-roles.guard.js.map +1 -1
- package/dist/core/modules/error-code/error-codes.d.ts +9 -0
- package/dist/core/modules/error-code/error-codes.js +8 -0
- package/dist/core/modules/error-code/error-codes.js.map +1 -1
- package/dist/core/modules/file/core-file.controller.d.ts +5 -0
- package/dist/core/modules/file/core-file.controller.js +66 -4
- package/dist/core/modules/file/core-file.controller.js.map +1 -1
- package/dist/core/modules/file/core-file.service.d.ts +2 -0
- package/dist/core/modules/file/core-file.service.js +17 -6
- package/dist/core/modules/file/core-file.service.js.map +1 -1
- package/dist/core/modules/file/filesystem-file.helper.d.ts +2 -1
- package/dist/core/modules/file/filesystem-file.helper.js +2 -2
- package/dist/core/modules/file/filesystem-file.helper.js.map +1 -1
- package/dist/core/modules/file/interfaces/file-service-options.interface.d.ts +2 -0
- package/dist/core/modules/file/s3-file.helper.d.ts +2 -0
- package/dist/core/modules/file/s3-file.helper.js.map +1 -1
- package/dist/core/modules/tenant/core-tenant.guard.js +9 -1
- package/dist/core/modules/tenant/core-tenant.guard.js.map +1 -1
- package/dist/core.module.js +2 -1
- package/dist/core.module.js.map +1 -1
- package/dist/index.d.ts +2 -0
- package/dist/index.js +2 -0
- package/dist/index.js.map +1 -1
- package/dist/server/modules/error-code/error-codes.d.ts +1 -0
- package/dist/test/test.helper.d.ts +1 -0
- package/dist/test/test.helper.js +6 -0
- package/dist/test/test.helper.js.map +1 -1
- package/dist/types/graphql-upload.d.ts +34 -2
- package/docs/REQUEST-LIFECYCLE.md +31 -9
- package/docs/error-codes.md +14 -0
- package/docs/security-overrides.md +34 -6
- package/migration-guides/12.6.11-to-12.6.12.md +180 -0
- package/migration-guides/12.6.12-to-12.6.13.md +162 -0
- package/package.json +15 -8
- package/src/core/common/decorators/rest-user.decorator.ts +6 -0
- package/src/core/common/filters/http-exception-log.filter.ts +9 -0
- package/src/core/common/helpers/byte-range.helper.ts +144 -0
- package/src/core/common/helpers/context.helper.ts +14 -0
- package/src/core/common/helpers/decorator.helper.ts +5 -0
- package/src/core/common/helpers/execution-context-request.helper.ts +78 -1
- package/src/core/common/helpers/graphql-upload.helper.ts +482 -0
- package/src/core/common/helpers/gridfs.helper.ts +20 -6
- package/src/core/common/interceptors/translate-response.interceptor.ts +8 -0
- package/src/core/common/services/core-s3.service.ts +16 -2
- package/src/core/modules/auth/guards/auth.guard.ts +19 -2
- package/src/core/modules/auth/guards/legacy-auth-rate-limit.guard.ts +9 -2
- package/src/core/modules/auth/guards/roles.guard.ts +23 -1
- package/src/core/modules/better-auth/better-auth-roles.guard.ts +29 -1
- package/src/core/modules/error-code/error-codes.ts +13 -0
- package/src/core/modules/file/INTEGRATION-CHECKLIST.md +1 -0
- package/src/core/modules/file/README.md +74 -1
- package/src/core/modules/file/core-file.controller.ts +139 -3
- package/src/core/modules/file/core-file.service.ts +33 -13
- package/src/core/modules/file/filesystem-file.helper.ts +8 -3
- package/src/core/modules/file/interfaces/file-service-options.interface.ts +13 -0
- package/src/core/modules/file/s3-file.helper.ts +3 -2
- package/src/core/modules/tenant/core-tenant.guard.ts +13 -1
- package/src/core.module.ts +5 -1
- package/src/index.ts +2 -0
- package/src/test/README.md +8 -4
- package/src/test/test.helper.ts +12 -0
- package/src/types/graphql-upload.d.ts +34 -2
package/src/core.module.ts
CHANGED
|
@@ -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
|
-
|
|
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';
|
package/src/test/README.md
CHANGED
|
@@ -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
|
|
209
|
-
| --------- |
|
|
210
|
-
| `token` | `string`
|
|
211
|
-
| `cookies` | `string`
|
|
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()`)
|
package/src/test/test.helper.ts
CHANGED
|
@@ -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`).
|
|
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
|
|
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
|
|