@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
|
@@ -453,13 +453,13 @@ plus one for the opposite failure, a guard that rejects a declaration which is s
|
|
|
453
453
|
matters just as much: a check that cries wolf on correct entries is a check that gets switched off,
|
|
454
454
|
which is how the hole this feature closes came about in the first place.
|
|
455
455
|
|
|
456
|
-
**Current
|
|
457
|
-
`< 11.0.1
|
|
458
|
-
|
|
459
|
-
|
|
460
|
-
|
|
461
|
-
|
|
462
|
-
|
|
456
|
+
**Current entry (since 2026-10-31, owner decision, DEV-3899).** `GHSA-g3hv-75wg-m249` (minimatch
|
|
457
|
+
`< 11.0.1`, moderate), fixed only in a new major released 2026-10-27 that its remaining consumers cannot take yet
|
|
458
|
+
(`@nestjs/cli` 12.0.11 pins 10.2.6 exactly, `@swc/cli`, `@ts-morph/common`, nodemon). The justification is in the
|
|
459
|
+
comment above `ignoreGhsas`, the declaration in `unusableFixConsumers`. `tests/unit/audit-suppression-scope.spec.ts`
|
|
460
|
+
allows minimatch in the production tree only under `@ts-morph/common` (ts-morph, the Permissions module's scanner,
|
|
461
|
+
matching globs the developer writes) — its `prodVia` form. `GHSA-3g3m-2fjr-6pw4` (glob `<= 14.0.1`) was a second
|
|
462
|
+
entry until 2026-11-14 on this line (12.6.x), when rimraf 6.1.4 moved to glob 14 and no affected glob remained.
|
|
463
463
|
|
|
464
464
|
**Before that, no entry from 2026-10-24.** `GHSA-vfj7-8cjw-p6xm` (braces, via nodemon / npm-watch) was
|
|
465
465
|
listed from 2026-10-11 to 2026-10-24: a dev-tooling-only path of an advisory with no patched release
|
|
@@ -502,6 +502,16 @@ reserved for a socket whose rights changed while it was open (above). Pinned by
|
|
|
502
502
|
`tests/subscription-session-iam.e2e-spec.ts` / `tests/subscription-session-legacy.e2e-spec.ts` (mutations
|
|
503
503
|
`iam-ws-handshake-refusal-throws`, `legacy-ws-handshake-refusal-throws`).
|
|
504
504
|
|
|
505
|
+
## Agent function and MCP calls (12.6.x backport of 12.10.0)
|
|
506
|
+
|
|
507
|
+
`@nestjs/ai` (`@AgentFunction()`) and `@nestjs/mcp` (`@Tool()` …) run every global guard around their methods with the
|
|
508
|
+
context types `'ai'` / `'mcp'` and the arguments `[input, call]`. Index 0 is what the model or the MCP client wrote.
|
|
509
|
+
`resolveGuardRequest()` answers `call.request` there — never index 0, which the HTTP fallback returned before (tool
|
|
510
|
+
arguments `{ "user": { "roles": ["admin"] } }` were the caller). A REQUEST-LESS caller (`caller: { user }`, a durable
|
|
511
|
+
run, stdio) is anonymous: public methods run, everything else is 401 in every guard, `CoreTenantGuard` included.
|
|
512
|
+
Nothing changes for any other transport. Pinned by `tests/unit/agent-call-context.spec.ts`.
|
|
513
|
+
**When you add a guard, resolve the request through `resolveGuardRequest()`; never `switchToHttp()` on its own.**
|
|
514
|
+
|
|
505
515
|
## Role Check Implementation
|
|
506
516
|
|
|
507
517
|
The role system is evaluated in:
|
package/.claude/rules/testing.md
CHANGED
|
@@ -410,7 +410,7 @@ pnpm run check:mutations -- --id=<id> # one mutation
|
|
|
410
410
|
pnpm run check:mutations -- --list # the registry, without running anything
|
|
411
411
|
pnpm run check:mutations -- --allow-dirty # when the fix and its evidence share a working tree
|
|
412
412
|
pnpm run check:mutations -- --jobs=4 # N mutations at a time (default: 2, or 4 on >=12 cores)
|
|
413
|
-
pnpm run check:mutations -- --no-infra # only the
|
|
413
|
+
pnpm run check:mutations -- --no-infra # only the 427 that need no MongoDB
|
|
414
414
|
pnpm run check:mutations -- --since=<ref> # only mutations touching files changed since <ref>
|
|
415
415
|
pnpm run check:mutations -- --shard=2/4 # this job's quarter of the selection (CI splits the full run)
|
|
416
416
|
```
|
|
@@ -430,7 +430,7 @@ when the registry, a vitest config or a setup file changed, since those can move
|
|
|
430
430
|
commit, and in CI alongside the publish without blocking it. The price of caching is a cache that
|
|
431
431
|
has to model each spec's full dependency closure correctly, and getting that wrong produces a stale
|
|
432
432
|
PASS for a test that has since gone vacuous — exactly what the gate is there to prevent. Bad trade
|
|
433
|
-
at
|
|
433
|
+
at 666 mutations.
|
|
434
434
|
|
|
435
435
|
**Decided 2026-10-03 (repo owner): keep the full run.** Measured at 128 mutations, the CI job for
|
|
436
436
|
11.41.6 took **14 minutes**. The trigger to revisit is that wall time, not the mutation count —
|
|
@@ -501,9 +501,9 @@ exactly the environment where the answer matters.
|
|
|
501
501
|
|
|
502
502
|
### The cost is vitest's cold start, not the tests
|
|
503
503
|
|
|
504
|
-
Worth knowing before optimising the wrong thing: the specs behind all
|
|
504
|
+
Worth knowing before optimising the wrong thing: the specs behind all 239 e2e mutations add up to
|
|
505
505
|
**~40 seconds**. The step takes ~740s. The remaining ~700s is paying vitest's startup — process
|
|
506
|
-
spawn, transform, module graph, mongod connect, DB create and drop — once per mutation,
|
|
506
|
+
spawn, transform, module graph, mongod connect, DB create and drop — once per mutation, 666 times.
|
|
507
507
|
That work is largely single-threaded I/O and barely scales with cores: the full registry measures
|
|
508
508
|
**744s on a 12-core laptop and 777s on a 4-vCPU CI runner**.
|
|
509
509
|
|
package/FRAMEWORK-API.md
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
# @lenne.tech/nest-server — Framework API Reference
|
|
2
2
|
|
|
3
|
-
> Auto-generated from source code as of 2026-11-
|
|
3
|
+
> Auto-generated from source code as of 2026-11-15 (v12.6.13)
|
|
4
4
|
> File: `FRAMEWORK-API.md` — compact, machine-readable API surface for Claude Code
|
|
5
5
|
|
|
6
6
|
## CoreModule.forRoot()
|
|
@@ -1,5 +1,9 @@
|
|
|
1
1
|
import { createParamDecorator } from '@nestjs/common';
|
|
2
|
+
import { isAgentCallContext, resolveAgentCallRequest } from '../helpers/execution-context-request.helper.js';
|
|
2
3
|
export const RESTUser = createParamDecorator((data, ctx) => {
|
|
4
|
+
if (isAgentCallContext(ctx)) {
|
|
5
|
+
return resolveAgentCallRequest(ctx)?.user;
|
|
6
|
+
}
|
|
3
7
|
const request = ctx.switchToHttp().getRequest();
|
|
4
8
|
return request.user;
|
|
5
9
|
});
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"rest-user.decorator.js","sourceRoot":"","sources":["../../../../src/core/common/decorators/rest-user.decorator.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,oBAAoB,EAAoB,MAAM,gBAAgB,CAAC;
|
|
1
|
+
{"version":3,"file":"rest-user.decorator.js","sourceRoot":"","sources":["../../../../src/core/common/decorators/rest-user.decorator.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,oBAAoB,EAAoB,MAAM,gBAAgB,CAAC;AAExE,OAAO,EAAE,kBAAkB,EAAE,uBAAuB,EAAE,MAAM,gDAAgD,CAAC;AAK7G,MAAM,CAAC,MAAM,QAAQ,GAAG,oBAAoB,CAAC,CAAC,IAAa,EAAE,GAAqB,EAAE,EAAE;IAEpF,IAAI,kBAAkB,CAAC,GAAG,CAAC,EAAE,CAAC;QAC5B,OAAO,uBAAuB,CAAC,GAAG,CAAC,EAAE,IAAI,CAAC;IAC5C,CAAC;IACD,MAAM,OAAO,GAAG,GAAG,CAAC,YAAY,EAAE,CAAC,UAAU,EAAE,CAAC;IAChD,OAAO,OAAO,CAAC,IAAI,CAAC;AACtB,CAAC,CAAC,CAAC"}
|
|
@@ -5,6 +5,7 @@ var __decorate = (this && this.__decorate) || function (decorators, target, key,
|
|
|
5
5
|
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
6
6
|
};
|
|
7
7
|
import { Catch, HttpException, Logger, ServiceUnavailableException, } from '@nestjs/common';
|
|
8
|
+
import { isAgentCallContext } from '../helpers/execution-context-request.helper.js';
|
|
8
9
|
const exceptionLogger = new Logger('HttpExceptionLogFilter');
|
|
9
10
|
let HttpExceptionLogFilter = class HttpExceptionLogFilter {
|
|
10
11
|
catch(exception, host) {
|
|
@@ -13,6 +14,9 @@ let HttpExceptionLogFilter = class HttpExceptionLogFilter {
|
|
|
13
14
|
if (type === 'graphql') {
|
|
14
15
|
return exception;
|
|
15
16
|
}
|
|
17
|
+
if (isAgentCallContext(host)) {
|
|
18
|
+
return undefined;
|
|
19
|
+
}
|
|
16
20
|
const ctx = host.switchToHttp();
|
|
17
21
|
const res = ctx.getResponse();
|
|
18
22
|
const status = exception.getStatus();
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"http-exception-log.filter.js","sourceRoot":"","sources":["../../../../src/core/common/filters/http-exception-log.filter.ts"],"names":[],"mappings":";;;;;;AAAA,OAAO,EAEL,KAAK,EAEL,aAAa,EACb,MAAM,EACN,2BAA2B,GAC5B,MAAM,gBAAgB,CAAC;
|
|
1
|
+
{"version":3,"file":"http-exception-log.filter.js","sourceRoot":"","sources":["../../../../src/core/common/filters/http-exception-log.filter.ts"],"names":[],"mappings":";;;;;;AAAA,OAAO,EAEL,KAAK,EAEL,aAAa,EACb,MAAM,EACN,2BAA2B,GAC5B,MAAM,gBAAgB,CAAC;AAGxB,OAAO,EAAE,kBAAkB,EAAE,MAAM,gDAAgD,CAAC;AAOpF,MAAM,eAAe,GAAG,IAAI,MAAM,CAAC,wBAAwB,CAAC,CAAC;AAGtD,IAAM,sBAAsB,GAA5B,MAAM,sBAAsB;IAIjC,KAAK,CAAC,SAAwB,EAAE,IAAmB;QAEjD,eAAe,CAAC,KAAK,CAAC,SAAS,CAAC,KAAK,CAAC,CAAC;QAGvC,MAAM,IAAI,GAAG,IAAI,CAAC,OAAO,EAAkB,CAAC;QAC5C,IAAI,IAAI,KAAK,SAAS,EAAE,CAAC;YACvB,OAAO,SAAS,CAAC;QACnB,CAAC;QAMD,IAAI,kBAAkB,CAAC,IAAI,CAAC,EAAE,CAAC;YAC7B,OAAO,SAAS,CAAC;QACnB,CAAC;QAGD,MAAM,GAAG,GAAG,IAAI,CAAC,YAAY,EAAE,CAAC;QAChC,MAAM,GAAG,GAAG,GAAG,CAAC,WAAW,EAAY,CAAC;QACxC,MAAM,MAAM,GAAG,SAAS,CAAC,SAAS,EAAE,CAAC;QAIrC,MAAM,IAAI,GAA4B,EAAE,GAAG,SAAS,EAAE,CAAC;QACvD,OAAO,IAAI,CAAC,OAAO,CAAC;QACpB,OAAO,IAAI,CAAC,KAAK,CAAC;QAClB,GAAG,CAAC,MAAM,CAAC,MAAM,CAAC,CAAC,IAAI,CAAC,SAAS,YAAY,2BAA2B,CAAC,CAAC,CAAC,IAAI,CAAC,QAAQ,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC;IACnG,CAAC;CACF,CAAA;AAlCY,sBAAsB;IADlC,KAAK,CAAC,aAAa,CAAC;GACR,sBAAsB,CAkClC"}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
export interface ByteRange {
|
|
2
|
+
end: number;
|
|
3
|
+
start: number;
|
|
4
|
+
}
|
|
5
|
+
export type RangeHeaderDecision = 'unsatisfiable' | ByteRange | undefined;
|
|
6
|
+
export declare function parseRangeHeader(header: string | string[] | undefined, length: number | undefined): RangeHeaderDecision;
|
|
7
|
+
export declare function assertByteRange(range: unknown): ByteRange | undefined;
|
|
8
|
+
export declare function contentRangeValue(range: ByteRange, length: number): string;
|
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
const MAX_RANGE_HEADER_LENGTH = 200;
|
|
2
|
+
const RANGE_SPEC = /^(\d*)[ \t]*-[ \t]*(\d*)$/;
|
|
3
|
+
const RANGE_UNIT = /^[ \t]*bytes[ \t]*=(.*)$/i;
|
|
4
|
+
export function parseRangeHeader(header, length) {
|
|
5
|
+
if (typeof length !== 'number' || !Number.isSafeInteger(length) || length < 0) {
|
|
6
|
+
return undefined;
|
|
7
|
+
}
|
|
8
|
+
const value = Array.isArray(header) ? header.join(',') : header;
|
|
9
|
+
if (typeof value !== 'string' || !value || value.length > MAX_RANGE_HEADER_LENGTH) {
|
|
10
|
+
return undefined;
|
|
11
|
+
}
|
|
12
|
+
const unit = RANGE_UNIT.exec(value);
|
|
13
|
+
if (!unit) {
|
|
14
|
+
return undefined;
|
|
15
|
+
}
|
|
16
|
+
const specs = unit[1]
|
|
17
|
+
.split(',')
|
|
18
|
+
.map((spec) => spec.trim())
|
|
19
|
+
.filter(Boolean);
|
|
20
|
+
if (specs.length !== 1) {
|
|
21
|
+
return undefined;
|
|
22
|
+
}
|
|
23
|
+
const match = RANGE_SPEC.exec(specs[0]);
|
|
24
|
+
if (!match) {
|
|
25
|
+
return undefined;
|
|
26
|
+
}
|
|
27
|
+
const [, first, last] = match;
|
|
28
|
+
if (!first && !last) {
|
|
29
|
+
return undefined;
|
|
30
|
+
}
|
|
31
|
+
if (!first) {
|
|
32
|
+
const suffix = toSafeInteger(last);
|
|
33
|
+
if (suffix === undefined) {
|
|
34
|
+
return undefined;
|
|
35
|
+
}
|
|
36
|
+
if (suffix === 0 || length === 0) {
|
|
37
|
+
return 'unsatisfiable';
|
|
38
|
+
}
|
|
39
|
+
return { end: length - 1, start: Math.max(0, length - suffix) };
|
|
40
|
+
}
|
|
41
|
+
const start = toSafeInteger(first);
|
|
42
|
+
const end = last ? toSafeInteger(last) : length - 1;
|
|
43
|
+
if (start === undefined || end === undefined) {
|
|
44
|
+
return undefined;
|
|
45
|
+
}
|
|
46
|
+
if (last && end < start) {
|
|
47
|
+
return undefined;
|
|
48
|
+
}
|
|
49
|
+
if (start >= length) {
|
|
50
|
+
return 'unsatisfiable';
|
|
51
|
+
}
|
|
52
|
+
return { end: Math.min(end, length - 1), start };
|
|
53
|
+
}
|
|
54
|
+
export function assertByteRange(range) {
|
|
55
|
+
if (range === undefined || range === null) {
|
|
56
|
+
return undefined;
|
|
57
|
+
}
|
|
58
|
+
const { end, start } = range;
|
|
59
|
+
if (!Number.isSafeInteger(start) || !Number.isSafeInteger(end) || start < 0 || end < start) {
|
|
60
|
+
throw new RangeError(`Invalid byte range { start: ${String(start)}, end: ${String(end)} }: start and end must be integers with 0 <= start <= end (end inclusive)`);
|
|
61
|
+
}
|
|
62
|
+
return { end, start };
|
|
63
|
+
}
|
|
64
|
+
export function contentRangeValue(range, length) {
|
|
65
|
+
return `bytes ${range.start}-${range.end}/${length}`;
|
|
66
|
+
}
|
|
67
|
+
function toSafeInteger(digits) {
|
|
68
|
+
const value = Number(digits);
|
|
69
|
+
return Number.isSafeInteger(value) ? value : undefined;
|
|
70
|
+
}
|
|
71
|
+
//# sourceMappingURL=byte-range.helper.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"byte-range.helper.js","sourceRoot":"","sources":["../../../../src/core/common/helpers/byte-range.helper.ts"],"names":[],"mappings":"AA4BA,MAAM,uBAAuB,GAAG,GAAG,CAAC;AAGpC,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AAG,KAAuC,CAAC;IAC/D,IAAI,CAAC,MAAM,CAAC,aAAa,CAAC,KAAK,CAAC,IAAI,CAAC,MAAM,CAAC,aAAa,CAAC,GAAG,CAAC,IAAI,KAAK,GAAG,CAAC,IAAI,GAAG,GAAG,KAAK,EAAE,CAAC;QAC3F,MAAM,IAAI,UAAU,CAClB,+BAA+B,MAAM,CAAC,KAAK,CAAC,UAAU,MAAM,CAAC,GAAG,CAAC,2EAA2E,CAC7I,CAAC;IACJ,CAAC;IACD,OAAO,EAAE,GAAG,EAAE,KAAK,EAAE,CAAC;AACxB,CAAC;AAGD,MAAM,UAAU,iBAAiB,CAAC,KAAgB,EAAE,MAAc;IAChE,OAAO,SAAS,KAAK,CAAC,KAAK,IAAI,KAAK,CAAC,GAAG,IAAI,MAAM,EAAE,CAAC;AACvD,CAAC;AAGD,SAAS,aAAa,CAAC,MAAc;IACnC,MAAM,KAAK,GAAG,MAAM,CAAC,MAAM,CAAC,CAAC;IAC7B,OAAO,MAAM,CAAC,aAAa,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,SAAS,CAAC;AACzD,CAAC"}
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { GqlExecutionContext } from '@nestjs/graphql';
|
|
2
|
+
import { isAgentCallContext, resolveAgentCallRequest } from './execution-context-request.helper.js';
|
|
2
3
|
export default class Context {
|
|
3
4
|
static getData(context) {
|
|
4
5
|
return getContextData(context);
|
|
@@ -8,6 +9,14 @@ export function getContextData(context) {
|
|
|
8
9
|
if (!context) {
|
|
9
10
|
return { args: null, currentUser: null, request: null };
|
|
10
11
|
}
|
|
12
|
+
if (isAgentCallContext(context)) {
|
|
13
|
+
const agentRequest = resolveAgentCallRequest(context);
|
|
14
|
+
return {
|
|
15
|
+
args: context.getArgByIndex(0),
|
|
16
|
+
currentUser: agentRequest?.user,
|
|
17
|
+
request: (agentRequest ?? null),
|
|
18
|
+
};
|
|
19
|
+
}
|
|
11
20
|
let user;
|
|
12
21
|
let rawContext = null;
|
|
13
22
|
let ctx = null;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"context.helper.js","sourceRoot":"","sources":["../../../../src/core/common/helpers/context.helper.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,mBAAmB,EAAE,MAAM,iBAAiB,CAAC;
|
|
1
|
+
{"version":3,"file":"context.helper.js","sourceRoot":"","sources":["../../../../src/core/common/helpers/context.helper.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,mBAAmB,EAAE,MAAM,iBAAiB,CAAC;AAGtD,OAAO,EAAE,kBAAkB,EAAE,uBAAuB,EAAE,MAAM,uCAAuC,CAAC;AAMpG,MAAM,CAAC,OAAO,OAAO,OAAO;IAKnB,MAAM,CAAC,OAAO,CAAC,OAAyB;QAK7C,OAAO,cAAc,CAAC,OAAO,CAAC,CAAC;IACjC,CAAC;CACF;AAKD,MAAM,UAAU,cAAc,CAAC,OAAyB;IAMtD,IAAI,CAAC,OAAO,EAAE,CAAC;QACb,OAAO,EAAE,IAAI,EAAE,IAAI,EAAE,WAAW,EAAE,IAAI,EAAE,OAAO,EAAE,IAAI,EAAE,CAAC;IAC1D,CAAC;IAKD,IAAI,kBAAkB,CAAC,OAAO,CAAC,EAAE,CAAC;QAChC,MAAM,YAAY,GAAG,uBAAuB,CAAC,OAAO,CAAC,CAAC;QACtD,OAAO;YACL,IAAI,EAAE,OAAO,CAAC,aAAa,CAAC,CAAC,CAAC;YAC9B,WAAW,EAAE,YAAY,EAAE,IAAI;YAC/B,OAAO,EAAE,CAAC,YAAY,IAAI,IAAI,CAAgB;SAC/C,CAAC;IACJ,CAAC;IAGD,IAAI,IAA4B,CAAC;IACjC,IAAI,UAAU,GAAQ,IAAI,CAAC;IAC3B,IAAI,GAAG,GAAQ,IAAI,CAAC;IACpB,IAAI,OAAY,CAAC;IACjB,IAAI,CAAC;QACH,UAAU,GAAG,mBAAmB,CAAC,MAAM,CAAC,OAAO,CAAC,CAAC;QACjD,GAAG,GAAG,UAAU,EAAE,UAAU,EAAE,CAAC;QAC/B,OAAO,GAAG,GAAG,CAAC,GAAG,CAAC;IACpB,CAAC;IAAC,OAAO,CAAC,EAAE,CAAC;IAEb,CAAC;IAED,IAAI,IAAS,CAAC;IACd,IAAI,UAAU,EAAE,CAAC;QACf,IAAI,CAAC;YACH,IAAI,GAAG,UAAU,CAAC,OAAO,EAAE,CAAC;QAC9B,CAAC;QAAC,OAAO,CAAC,EAAE,CAAC;QAEb,CAAC;IACH,CAAC;IAGD,IAAI,GAAG,EAAE,CAAC;QAER,IAAI,GAAG,GAAG,EAAE,IAAI,IAAI,GAAG,EAAE,GAAG,EAAE,IAAI,CAAC;IACrC,CAAC;SAAM,CAAC;QACN,OAAO,GAAG,OAAO,EAAE,YAAY,CAAC,CAAC,CAAC,OAAO,CAAC,YAAY,EAAE,EAAE,UAAU,EAAE,CAAC,CAAC,CAAC,IAAI,CAAC;QAC9E,IAAI,OAAO,EAAE,CAAC;YACZ,IAAI,GAAG,OAAO,CAAC,IAAI,CAAC;YAGpB,IAAI,GAAG,OAAO,CAAC,IAAI,CAAC;QACtB,CAAC;IACH,CAAC;IAGD,OAAO,EAAE,IAAI,EAAE,WAAW,EAAE,IAAI,EAAE,OAAO,EAAE,CAAC;AAC9C,CAAC"}
|
|
@@ -1,7 +1,11 @@
|
|
|
1
1
|
import { GqlExecutionContext } from '@nestjs/graphql';
|
|
2
2
|
import { getPopulateOptions } from './db.helper.js';
|
|
3
|
+
import { isAgentCallContext, resolveAgentCallRequest } from './execution-context-request.helper.js';
|
|
3
4
|
import { removePropertiesDeep } from './input.helper.js';
|
|
4
5
|
export function currentUserDec(data, ctx) {
|
|
6
|
+
if (isAgentCallContext(ctx)) {
|
|
7
|
+
return resolveAgentCallRequest(ctx)?.user;
|
|
8
|
+
}
|
|
5
9
|
if (ctx.getType() === 'graphql') {
|
|
6
10
|
const gqlContext = GqlExecutionContext.create(ctx);
|
|
7
11
|
return gqlContext.getContext().req.user;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"decorator.helper.js","sourceRoot":"","sources":["../../../../src/core/common/helpers/decorator.helper.ts"],"names":[],"mappings":"AACA,OAAO,EAAkB,mBAAmB,EAAE,MAAM,iBAAiB,CAAC;AAGtE,OAAO,EAAE,kBAAkB,EAAE,MAAM,gBAAgB,CAAC;AACpD,OAAO,EAAE,oBAAoB,EAAE,MAAM,mBAAmB,CAAC;AAKzD,MAAM,UAAU,cAAc,CAAC,IAAI,EAAE,GAAqB;
|
|
1
|
+
{"version":3,"file":"decorator.helper.js","sourceRoot":"","sources":["../../../../src/core/common/helpers/decorator.helper.ts"],"names":[],"mappings":"AACA,OAAO,EAAkB,mBAAmB,EAAE,MAAM,iBAAiB,CAAC;AAGtE,OAAO,EAAE,kBAAkB,EAAE,MAAM,gBAAgB,CAAC;AACpD,OAAO,EAAE,kBAAkB,EAAE,uBAAuB,EAAE,MAAM,uCAAuC,CAAC;AACpG,OAAO,EAAE,oBAAoB,EAAE,MAAM,mBAAmB,CAAC;AAKzD,MAAM,UAAU,cAAc,CAAC,IAAI,EAAE,GAAqB;IAExD,IAAI,kBAAkB,CAAC,GAAG,CAAC,EAAE,CAAC;QAC5B,OAAO,uBAAuB,CAAC,GAAG,CAAC,EAAE,IAAI,CAAC;IAC5C,CAAC;IACD,IAAI,GAAG,CAAC,OAAO,EAAkB,KAAK,SAAS,EAAE,CAAC;QAChD,MAAM,UAAU,GAAG,mBAAmB,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC;QACnD,OAAO,UAAU,CAAC,UAAU,EAAE,CAAC,GAAG,CAAC,IAAI,CAAC;IAC1C,CAAC;IACD,OAAO,GAAG,CAAC,YAAY,EAAE,CAAC,UAAU,EAAE,CAAC,IAAI,CAAC;AAC9C,CAAC;AAaD,MAAM,UAAU,kBAAkB,CAChC,IAAsD,EACtD,GAAqB;IAGrB,IAAI,GAAG,CAAC,OAAO,EAAkB,KAAK,SAAS,EAAE,CAAC;QAChD,OAAO,SAAS,CAAC;IACnB,CAAC;IAGD,MAAM,UAAU,GAAG,mBAAmB,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC;IACnD,MAAM,EAAE,OAAO,EAAE,gBAAgB,EAAE,GAAG;QACpC,OAAO,EAAE,UAAU,CAAC,UAAU,EAAE,CAAC,IAAI;QACrC,gBAAgB,EAAE,IAAI;QACtB,GAAG,IAAI;KACR,CAAC;IAGF,MAAM,eAAe,GAAG,kBAAkB,CAAC,UAAU,CAAC,OAAO,EAAE,EAAE,OAAO,CAAC,CAAC;IAC1E,IAAI,gBAAgB,EAAE,CAAC;QACrB,oBAAoB,CAAC,eAAe,EAAE,CAAC,QAAQ,CAAC,CAAC,CAAC;IACpD,CAAC;IAGD,OAAO,eAAe,CAAC;AACzB,CAAC"}
|
|
@@ -1,4 +1,12 @@
|
|
|
1
|
-
import type { ExecutionContext } from '@nestjs/common';
|
|
1
|
+
import type { ArgumentsHost, ExecutionContext } from '@nestjs/common';
|
|
2
|
+
export declare const AGENT_CALL_CONTEXT_TYPES: ReadonlySet<string>;
|
|
3
|
+
export interface AgentCallLike {
|
|
4
|
+
name?: string;
|
|
5
|
+
request?: GuardRequestLike;
|
|
6
|
+
}
|
|
7
|
+
export declare function isAgentCallContext(context: ArgumentsHost | undefined): boolean;
|
|
8
|
+
export declare function agentCallOf(context: ArgumentsHost | undefined): AgentCallLike | undefined;
|
|
9
|
+
export declare function resolveAgentCallRequest(context: ArgumentsHost | undefined): GuardRequestLike | undefined;
|
|
2
10
|
export interface GuardRequestLike {
|
|
3
11
|
[key: string]: any;
|
|
4
12
|
headers?: Record<string, any>;
|
|
@@ -1,7 +1,36 @@
|
|
|
1
|
+
export const AGENT_CALL_CONTEXT_TYPES = new Set(['ai', 'mcp']);
|
|
2
|
+
export function isAgentCallContext(context) {
|
|
3
|
+
let type;
|
|
4
|
+
try {
|
|
5
|
+
type = context?.getType?.();
|
|
6
|
+
}
|
|
7
|
+
catch {
|
|
8
|
+
return false;
|
|
9
|
+
}
|
|
10
|
+
return typeof type === 'string' && AGENT_CALL_CONTEXT_TYPES.has(type);
|
|
11
|
+
}
|
|
12
|
+
export function agentCallOf(context) {
|
|
13
|
+
if (!isAgentCallContext(context)) {
|
|
14
|
+
return undefined;
|
|
15
|
+
}
|
|
16
|
+
const call = context.getArgByIndex(1);
|
|
17
|
+
return call && typeof call === 'object' ? call : undefined;
|
|
18
|
+
}
|
|
19
|
+
export function resolveAgentCallRequest(context) {
|
|
20
|
+
const call = agentCallOf(context);
|
|
21
|
+
const request = call?.request;
|
|
22
|
+
if (!request || typeof request !== 'object') {
|
|
23
|
+
return undefined;
|
|
24
|
+
}
|
|
25
|
+
return request;
|
|
26
|
+
}
|
|
1
27
|
function isSubscriptionContext(value) {
|
|
2
28
|
return (!!value && typeof value === 'object' && ('socket' in value || 'connectionParams' in value || 'request' in value));
|
|
3
29
|
}
|
|
4
30
|
export function resolveGuardRequest(context, gqlContextOf) {
|
|
31
|
+
if (isAgentCallContext(context)) {
|
|
32
|
+
return resolveAgentCallRequest(context);
|
|
33
|
+
}
|
|
5
34
|
let gqlContext;
|
|
6
35
|
try {
|
|
7
36
|
gqlContext = gqlContextOf(context);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"execution-context-request.helper.js","sourceRoot":"","sources":["../../../../src/core/common/helpers/execution-context-request.helper.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"execution-context-request.helper.js","sourceRoot":"","sources":["../../../../src/core/common/helpers/execution-context-request.helper.ts"],"names":[],"mappings":"AAkDA,MAAM,CAAC,MAAM,wBAAwB,GAAwB,IAAI,GAAG,CAAC,CAAC,IAAI,EAAE,KAAK,CAAC,CAAC,CAAC;AAcpF,MAAM,UAAU,kBAAkB,CAAC,OAAkC;IACnE,IAAI,IAAa,CAAC;IAClB,IAAI,CAAC;QACH,IAAI,GAAG,OAAO,EAAE,OAAO,EAAE,EAAE,CAAC;IAC9B,CAAC;IAAC,MAAM,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UAAU,GAAG,SAAS,CAAC;IACzB,CAAC;IAED,IAAI,UAAU,EAAE,GAAG,EAAE,CAAC;QACpB,OAAO,UAAU,CAAC,GAAG,CAAC;IACxB,CAAC;IAED,IAAI,qBAAqB,CAAC,UAAU,CAAC,EAAE,CAAC;QAItC,IAAI,CAAC,UAAU,CAAC,OAAO,EAAE,CAAC;YACxB,UAAU,CAAC,OAAO,GAAG,UAAU,CAAC,gBAAgB,IAAI,UAAU,CAAC,OAAO,EAAE,OAAO,IAAI,EAAE,CAAC;QACxF,CAAC;QACD,OAAO,UAAU,CAAC;IACpB,CAAC;IAED,IAAI,CAAC;QACH,OAAO,OAAO,CAAC,YAAY,EAAE,CAAC,UAAU,EAAE,CAAC;IAC7C,CAAC;IAAC,MAAM,CAAC;QACP,OAAO,SAAS,CAAC;IACnB,CAAC;AACH,CAAC"}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import type { IncomingMessage, ServerResponse } from 'node:http';
|
|
2
|
+
export declare const GRAPHQL_UPLOAD_MAX_PATH_KEYS = 64;
|
|
3
|
+
export declare const GRAPHQL_UPLOAD_MAX_MAP_KEYS = 10000;
|
|
4
|
+
export interface GraphQlUploadProcessRequestOptions {
|
|
5
|
+
maxFieldSize?: number;
|
|
6
|
+
maxFileSize?: number;
|
|
7
|
+
maxFiles?: number;
|
|
8
|
+
}
|
|
9
|
+
export type GraphQlUploadOperations = Array<Record<string, unknown>> | Record<string, unknown>;
|
|
10
|
+
export declare function processGraphQlUploadRequest(request: IncomingMessage, response: ServerResponse, { maxFieldSize, maxFileSize, maxFiles }?: GraphQlUploadProcessRequestOptions): Promise<GraphQlUploadOperations>;
|
|
@@ -0,0 +1,220 @@
|
|
|
1
|
+
import busboy from 'busboy';
|
|
2
|
+
import { WriteStream } from 'fs-capacitor';
|
|
3
|
+
import Upload from 'graphql-upload/Upload.mjs';
|
|
4
|
+
import createError from 'http-errors';
|
|
5
|
+
import objectPath from 'object-path';
|
|
6
|
+
const GRAPHQL_MULTIPART_REQUEST_SPEC_URL = 'https://github.com/jaydenseric/graphql-multipart-request-spec';
|
|
7
|
+
export const GRAPHQL_UPLOAD_MAX_PATH_KEYS = 64;
|
|
8
|
+
export const GRAPHQL_UPLOAD_MAX_MAP_KEYS = 10_000;
|
|
9
|
+
function ignoreStream(stream) {
|
|
10
|
+
stream.on('error', () => { });
|
|
11
|
+
stream.resume();
|
|
12
|
+
}
|
|
13
|
+
export function processGraphQlUploadRequest(request, response, { maxFieldSize = 1000000, maxFileSize = Infinity, maxFiles = Infinity } = {}) {
|
|
14
|
+
return new Promise((resolve, reject) => {
|
|
15
|
+
let released;
|
|
16
|
+
let exitError;
|
|
17
|
+
let operations;
|
|
18
|
+
let operationsPath;
|
|
19
|
+
let map;
|
|
20
|
+
const parser = busboy({
|
|
21
|
+
headers: request.headers,
|
|
22
|
+
defParamCharset: 'utf8',
|
|
23
|
+
limits: {
|
|
24
|
+
fieldSize: maxFieldSize,
|
|
25
|
+
fields: 2,
|
|
26
|
+
fileSize: maxFileSize,
|
|
27
|
+
files: maxFiles,
|
|
28
|
+
},
|
|
29
|
+
});
|
|
30
|
+
function exit(error, isParserError = false) {
|
|
31
|
+
if (exitError) {
|
|
32
|
+
return;
|
|
33
|
+
}
|
|
34
|
+
exitError = error;
|
|
35
|
+
if (map) {
|
|
36
|
+
for (const upload of map.values()) {
|
|
37
|
+
if (!upload.file) {
|
|
38
|
+
upload.reject(exitError);
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
if (isParserError) {
|
|
43
|
+
parser.destroy();
|
|
44
|
+
}
|
|
45
|
+
else {
|
|
46
|
+
parser.destroy(exitError);
|
|
47
|
+
}
|
|
48
|
+
request.unpipe(parser);
|
|
49
|
+
setImmediate(() => {
|
|
50
|
+
request.resume();
|
|
51
|
+
});
|
|
52
|
+
reject(exitError);
|
|
53
|
+
}
|
|
54
|
+
parser.on('field', (fieldName, value, { valueTruncated }) => {
|
|
55
|
+
if (valueTruncated) {
|
|
56
|
+
return exit(createError(413, `The ‘${fieldName}’ multipart field value exceeds the ${maxFieldSize} byte size limit.`));
|
|
57
|
+
}
|
|
58
|
+
switch (fieldName) {
|
|
59
|
+
case 'operations':
|
|
60
|
+
try {
|
|
61
|
+
operations = JSON.parse(value);
|
|
62
|
+
}
|
|
63
|
+
catch {
|
|
64
|
+
return exit(createError(400, `Invalid JSON in the ‘operations’ multipart field (${GRAPHQL_MULTIPART_REQUEST_SPEC_URL}).`));
|
|
65
|
+
}
|
|
66
|
+
if (typeof operations !== 'object' || !operations) {
|
|
67
|
+
return exit(createError(400, `Invalid type for the ‘operations’ multipart field (${GRAPHQL_MULTIPART_REQUEST_SPEC_URL}).`));
|
|
68
|
+
}
|
|
69
|
+
operationsPath = objectPath(operations);
|
|
70
|
+
break;
|
|
71
|
+
case 'map': {
|
|
72
|
+
if (!operations) {
|
|
73
|
+
return exit(createError(400, `Misordered multipart fields; ‘map’ should follow ‘operations’ (${GRAPHQL_MULTIPART_REQUEST_SPEC_URL}).`));
|
|
74
|
+
}
|
|
75
|
+
let parsedMap;
|
|
76
|
+
try {
|
|
77
|
+
parsedMap = JSON.parse(value);
|
|
78
|
+
}
|
|
79
|
+
catch {
|
|
80
|
+
return exit(createError(400, `Invalid JSON in the ‘map’ multipart field (${GRAPHQL_MULTIPART_REQUEST_SPEC_URL}).`));
|
|
81
|
+
}
|
|
82
|
+
if (typeof parsedMap !== 'object' || !parsedMap || Array.isArray(parsedMap)) {
|
|
83
|
+
return exit(createError(400, `Invalid type for the ‘map’ multipart field (${GRAPHQL_MULTIPART_REQUEST_SPEC_URL}).`));
|
|
84
|
+
}
|
|
85
|
+
const mapEntries = Object.entries(parsedMap);
|
|
86
|
+
if (mapEntries.length > maxFiles) {
|
|
87
|
+
return exit(createError(413, `${maxFiles} max file uploads exceeded.`));
|
|
88
|
+
}
|
|
89
|
+
map = new Map();
|
|
90
|
+
let mapKeyCount = 0;
|
|
91
|
+
for (const [mapFieldName, paths] of mapEntries) {
|
|
92
|
+
if (!Array.isArray(paths)) {
|
|
93
|
+
return exit(createError(400, `Invalid type for the ‘map’ multipart field entry key ‘${mapFieldName}’ array (${GRAPHQL_MULTIPART_REQUEST_SPEC_URL}).`));
|
|
94
|
+
}
|
|
95
|
+
mapKeyCount += 1;
|
|
96
|
+
if (mapKeyCount > GRAPHQL_UPLOAD_MAX_MAP_KEYS) {
|
|
97
|
+
return exit(createError(400, `Invalid ‘map’ multipart field entry key ‘${mapFieldName}’: the map has more than ${GRAPHQL_UPLOAD_MAX_MAP_KEYS} entries and object path keys together (${GRAPHQL_MULTIPART_REQUEST_SPEC_URL}).`));
|
|
98
|
+
}
|
|
99
|
+
map.set(mapFieldName, new Upload());
|
|
100
|
+
for (const [index, path] of paths.entries()) {
|
|
101
|
+
if (typeof path !== 'string') {
|
|
102
|
+
return exit(createError(400, `Invalid type for the ‘map’ multipart field entry key ‘${mapFieldName}’ array index ‘${index}’ value (${GRAPHQL_MULTIPART_REQUEST_SPEC_URL}).`));
|
|
103
|
+
}
|
|
104
|
+
try {
|
|
105
|
+
const keys = path.split('.');
|
|
106
|
+
if (keys.length > GRAPHQL_UPLOAD_MAX_PATH_KEYS) {
|
|
107
|
+
throw new RangeError(`Object path has more than ${GRAPHQL_UPLOAD_MAX_PATH_KEYS} keys.`);
|
|
108
|
+
}
|
|
109
|
+
mapKeyCount += keys.length;
|
|
110
|
+
if (mapKeyCount > GRAPHQL_UPLOAD_MAX_MAP_KEYS) {
|
|
111
|
+
throw new RangeError(`The map has more than ${GRAPHQL_UPLOAD_MAX_MAP_KEYS} entries and object path keys.`);
|
|
112
|
+
}
|
|
113
|
+
let pathValue = operations;
|
|
114
|
+
for (const [keyIndex, key] of keys.entries()) {
|
|
115
|
+
if (key === '__proto__') {
|
|
116
|
+
throw new TypeError('Object path has a `__proto__` key.');
|
|
117
|
+
}
|
|
118
|
+
if (keyIndex < keys.length - 1) {
|
|
119
|
+
pathValue = objectPath.get(pathValue, [key]);
|
|
120
|
+
if (pathValue instanceof Upload) {
|
|
121
|
+
throw new TypeError('Object path traverses an upload.');
|
|
122
|
+
}
|
|
123
|
+
}
|
|
124
|
+
}
|
|
125
|
+
operationsPath.set(path, map.get(mapFieldName));
|
|
126
|
+
}
|
|
127
|
+
catch {
|
|
128
|
+
return exit(createError(400, `Invalid object path for the ‘map’ multipart field entry key ‘${mapFieldName}’ array index ‘${index}’ value ‘${path}’ (${GRAPHQL_MULTIPART_REQUEST_SPEC_URL}).`));
|
|
129
|
+
}
|
|
130
|
+
}
|
|
131
|
+
}
|
|
132
|
+
resolve(operations);
|
|
133
|
+
}
|
|
134
|
+
}
|
|
135
|
+
});
|
|
136
|
+
parser.on('file', (fieldName, stream, { encoding, filename, mimeType: mimetype }) => {
|
|
137
|
+
if (!map) {
|
|
138
|
+
ignoreStream(stream);
|
|
139
|
+
return exit(createError(400, `Misordered multipart fields; files should follow ‘map’ (${GRAPHQL_MULTIPART_REQUEST_SPEC_URL}).`));
|
|
140
|
+
}
|
|
141
|
+
const upload = map.get(fieldName);
|
|
142
|
+
if (!upload || upload.file) {
|
|
143
|
+
ignoreStream(stream);
|
|
144
|
+
return;
|
|
145
|
+
}
|
|
146
|
+
let fileError;
|
|
147
|
+
const capacitor = new WriteStream();
|
|
148
|
+
capacitor.on('error', () => {
|
|
149
|
+
stream.unpipe();
|
|
150
|
+
stream.resume();
|
|
151
|
+
});
|
|
152
|
+
stream.on('limit', () => {
|
|
153
|
+
fileError = createError(413, `File truncated as it exceeds the ${maxFileSize} byte size limit.`);
|
|
154
|
+
stream.unpipe();
|
|
155
|
+
capacitor.destroy(fileError);
|
|
156
|
+
});
|
|
157
|
+
stream.on('error', (error) => {
|
|
158
|
+
fileError = error;
|
|
159
|
+
stream.unpipe();
|
|
160
|
+
capacitor.destroy(fileError);
|
|
161
|
+
});
|
|
162
|
+
const file = {
|
|
163
|
+
filename,
|
|
164
|
+
mimetype,
|
|
165
|
+
encoding,
|
|
166
|
+
createReadStream(options) {
|
|
167
|
+
const error = fileError || (released ? exitError : null);
|
|
168
|
+
if (error) {
|
|
169
|
+
throw error;
|
|
170
|
+
}
|
|
171
|
+
return capacitor.createReadStream(options);
|
|
172
|
+
},
|
|
173
|
+
capacitor,
|
|
174
|
+
};
|
|
175
|
+
Object.defineProperty(file, 'capacitor', {
|
|
176
|
+
enumerable: false,
|
|
177
|
+
configurable: false,
|
|
178
|
+
writable: false,
|
|
179
|
+
});
|
|
180
|
+
stream.pipe(capacitor);
|
|
181
|
+
upload.resolve(file);
|
|
182
|
+
});
|
|
183
|
+
parser.once('filesLimit', () => exit(createError(413, `${maxFiles} max file uploads exceeded.`)));
|
|
184
|
+
parser.once('finish', () => {
|
|
185
|
+
request.unpipe(parser);
|
|
186
|
+
request.resume();
|
|
187
|
+
if (!operations) {
|
|
188
|
+
return exit(createError(400, `Missing multipart field ‘operations’ (${GRAPHQL_MULTIPART_REQUEST_SPEC_URL}).`));
|
|
189
|
+
}
|
|
190
|
+
if (!map) {
|
|
191
|
+
return exit(createError(400, `Missing multipart field ‘map’ (${GRAPHQL_MULTIPART_REQUEST_SPEC_URL}).`));
|
|
192
|
+
}
|
|
193
|
+
for (const upload of map.values()) {
|
|
194
|
+
if (!upload.file) {
|
|
195
|
+
upload.reject(createError(400, 'File missing in the request.'));
|
|
196
|
+
}
|
|
197
|
+
}
|
|
198
|
+
});
|
|
199
|
+
parser.on('error', (error) => {
|
|
200
|
+
exit(error, true);
|
|
201
|
+
});
|
|
202
|
+
response.once('close', () => {
|
|
203
|
+
released = true;
|
|
204
|
+
if (map) {
|
|
205
|
+
for (const upload of map.values()) {
|
|
206
|
+
if (upload.file) {
|
|
207
|
+
upload.file.capacitor.release();
|
|
208
|
+
}
|
|
209
|
+
}
|
|
210
|
+
}
|
|
211
|
+
});
|
|
212
|
+
request.once('close', () => {
|
|
213
|
+
if (!request.readableEnded) {
|
|
214
|
+
exit(createError(499, 'Request disconnected during file upload stream parsing.'));
|
|
215
|
+
}
|
|
216
|
+
});
|
|
217
|
+
request.pipe(parser);
|
|
218
|
+
});
|
|
219
|
+
}
|
|
220
|
+
//# sourceMappingURL=graphql-upload.helper.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"graphql-upload.helper.js","sourceRoot":"","sources":["../../../../src/core/common/helpers/graphql-upload.helper.ts"],"names":[],"mappings":"AA2DA,OAAO,MAAM,MAAM,QAAQ,CAAC;AAC5B,OAAO,EAAE,WAAW,EAAE,MAAM,cAAc,CAAC;AAC3C,OAAO,MAAM,MAAM,2BAA2B,CAAC;AAC/C,OAAO,WAAW,MAAM,aAAa,CAAC;AACtC,OAAO,UAAU,MAAM,aAAa,CAAC;AAMrC,MAAM,kCAAkC,GAAG,+DAA+D,CAAC;AAO3G,MAAM,CAAC,MAAM,4BAA4B,GAAG,EAAE,CAAC;AAW/C,MAAM,CAAC,MAAM,2BAA2B,GAAG,MAAM,CAAC;AAkClD,SAAS,YAAY,CAAC,MAAgB;IAEpC,MAAM,CAAC,EAAE,CAAC,OAAO,EAAE,GAAG,EAAE,GAAE,CAAC,CAAC,CAAC;IAG7B,MAAM,CAAC,MAAM,EAAE,CAAC;AAClB,CAAC;AAaD,MAAM,UAAU,2BAA2B,CACzC,OAAwB,EACxB,QAAwB,EACxB,EAAE,YAAY,GAAG,OAAO,EAAE,WAAW,GAAG,QAAQ,EAAE,QAAQ,GAAG,QAAQ,KAAyC,EAAE;IAEhH,OAAO,IAAI,OAAO,CAAC,CAAC,OAAO,EAAE,MAAM,EAAE,EAAE;QACrC,IAAI,QAAiB,CAAC;QACtB,IAAI,SAA8B,CAAC;QACnC,IAAI,UAAmC,CAAC;QACxC,IAAI,cAA6C,CAAC;QAClD,IAAI,GAAwB,CAAC;QAE7B,MAAM,MAAM,GAAG,MAAM,CAAC;YACpB,OAAO,EAAE,OAAO,CAAC,OAAO;YACxB,eAAe,EAAE,MAAM;YACvB,MAAM,EAAE;gBACN,SAAS,EAAE,YAAY;gBACvB,MAAM,EAAE,CAA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I,CAAC;YAEhB,IAAI,GAAG,EAAE,CAAC;gBACR,KAAK,MAAM,MAAM,IAAI,GAAG,CAAC,MAAM,EAAE,EAAE,CAAC;oBAClC,IAAI,MAAM,CAAC,IAAI,EAAE,CAAC;wBAEf,MAAM,CAAC,IAA4B,CAAC,SAAS,CAAC,OAAO,EAAE,CAAC;oBAC3D,CAAC;gBACH,CAAC;YACH,CAAC;QACH,CAAC,CAAC,CAAC;QAEH,OAAO,CAAC,IAAI,CAAC,OAAO,EAAE,GAAG,EAAE;YACzB,IAAI,CAAC,OAAO,CAAC,aAAa,EAAE,CAAC;gBAC3B,IAAI,CAAC,WAAW,CAAC,GAAG,EAAE,yDAAyD,CAAC,CAAC,CAAC;YACpF,CAAC;QACH,CAAC,CAAC,CAAC;QAEH,OAAO,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC;IACvB,CAAC,CAAC,CAAC;AACL,CAAC"}
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import type { mongo, Types } from 'mongoose';
|
|
2
2
|
import { Readable } from 'stream';
|
|
3
|
+
import type { ByteRange } from './byte-range.helper.js';
|
|
3
4
|
export interface GridFSFileInfo {
|
|
4
5
|
_id: Types.ObjectId;
|
|
5
6
|
chunkSize: number;
|
|
@@ -31,8 +32,12 @@ export declare class GridFSHelper {
|
|
|
31
32
|
static findFiles(bucket: GridFSBucket | undefined, filter?: any, options?: any): Promise<GridFSFileInfo[]>;
|
|
32
33
|
private static mapContentTypeKeys;
|
|
33
34
|
static deleteFile(bucket: GridFSBucket, id: string | Types.ObjectId): Promise<void>;
|
|
34
|
-
static openDownloadStream(bucket: GridFSBucket, id: string | Types.ObjectId): GridFSBucketReadStream;
|
|
35
|
-
static openDownloadStreamByName(bucket: GridFSBucket, filename: string): GridFSBucketReadStream;
|
|
35
|
+
static openDownloadStream(bucket: GridFSBucket, id: string | Types.ObjectId, range?: ByteRange): GridFSBucketReadStream;
|
|
36
|
+
static openDownloadStreamByName(bucket: GridFSBucket, filename: string, range?: ByteRange): GridFSBucketReadStream;
|
|
37
|
+
static streamRange(range?: ByteRange): undefined | {
|
|
38
|
+
end: number;
|
|
39
|
+
start: number;
|
|
40
|
+
};
|
|
36
41
|
static openUploadStream(bucket: GridFSBucket, filename: string, options?: {
|
|
37
42
|
contentType?: string;
|
|
38
43
|
}): mongo.GridFSBucketWriteStream;
|
|
@@ -124,12 +124,15 @@ export class GridFSHelper {
|
|
|
124
124
|
const objectId = typeof id === 'string' ? newObjectId(id) : id;
|
|
125
125
|
await bucket.delete(objectId);
|
|
126
126
|
}
|
|
127
|
-
static openDownloadStream(bucket, id) {
|
|
127
|
+
static openDownloadStream(bucket, id, range) {
|
|
128
128
|
const objectId = typeof id === 'string' ? newObjectId(id) : id;
|
|
129
|
-
return bucket.openDownloadStream(objectId);
|
|
129
|
+
return bucket.openDownloadStream(objectId, GridFSHelper.streamRange(range));
|
|
130
130
|
}
|
|
131
|
-
static openDownloadStreamByName(bucket, filename) {
|
|
132
|
-
return bucket.openDownloadStreamByName(filename);
|
|
131
|
+
static openDownloadStreamByName(bucket, filename, range) {
|
|
132
|
+
return bucket.openDownloadStreamByName(filename, GridFSHelper.streamRange(range));
|
|
133
|
+
}
|
|
134
|
+
static streamRange(range) {
|
|
135
|
+
return range ? { end: range.end + 1, start: range.start } : undefined;
|
|
133
136
|
}
|
|
134
137
|
static openUploadStream(bucket, filename, options) {
|
|
135
138
|
if (options?.contentType) {
|