@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
|
@@ -0,0 +1,144 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* A byte range of a file: the bytes `start` through `end`, both INCLUSIVE — the way HTTP counts them
|
|
3
|
+
* (`Range: bytes=0-1` is two bytes) and `fs.createReadStream()` takes them.
|
|
4
|
+
*
|
|
5
|
+
* Read with `CoreFileService.getFileStream(id, { range })` / `getFileStreamByName()` or
|
|
6
|
+
* `CoreS3Service.getObject(key, { range })`. The range must lie inside the file (`end` below its
|
|
7
|
+
* length); {@link parseRangeHeader} / `resolveDownloadRange()` produce such a range from a request.
|
|
8
|
+
*/
|
|
9
|
+
export interface ByteRange {
|
|
10
|
+
/** Last byte, inclusive */
|
|
11
|
+
end: number;
|
|
12
|
+
/** First byte, counted from 0 */
|
|
13
|
+
start: number;
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
/**
|
|
17
|
+
* What {@link parseRangeHeader} decided about a `Range` header:
|
|
18
|
+
* - a {@link ByteRange} — deliver these bytes (`206 Partial Content`);
|
|
19
|
+
* - `'unsatisfiable'` — the range starts at or past the end of the file (`416 Range Not Satisfiable`);
|
|
20
|
+
* - `undefined` — deliver the whole file (`200`), the header asks for nothing this server serves.
|
|
21
|
+
*/
|
|
22
|
+
export type RangeHeaderDecision = 'unsatisfiable' | ByteRange | undefined;
|
|
23
|
+
|
|
24
|
+
/**
|
|
25
|
+
* Longest `Range` header that is parsed at all. A single byte range of a file the size of any store's limit is
|
|
26
|
+
* well below 100 characters; a longer header is a list of ranges or garbage, and both are answered with the whole
|
|
27
|
+
* file anyway.
|
|
28
|
+
*/
|
|
29
|
+
const MAX_RANGE_HEADER_LENGTH = 200;
|
|
30
|
+
|
|
31
|
+
/** One range of the set, `first-last`, `first-` or `-suffix`. Anchored and without nested quantifiers. */
|
|
32
|
+
const RANGE_SPEC = /^(\d*)[ \t]*-[ \t]*(\d*)$/;
|
|
33
|
+
|
|
34
|
+
/** The unit and the range set: `bytes=<set>`, the unit case-insensitive (RFC 9110 §14.1) */
|
|
35
|
+
const RANGE_UNIT = /^[ \t]*bytes[ \t]*=(.*)$/i;
|
|
36
|
+
|
|
37
|
+
/**
|
|
38
|
+
* Decide what a `Range` request header asks for, against a file of `length` bytes (RFC 9110 §14.1.2, §14.2).
|
|
39
|
+
*
|
|
40
|
+
* Only ONE range is served. The whole file (`undefined`) is the answer to:
|
|
41
|
+
* - no header, an empty one, or a unit other than `bytes`;
|
|
42
|
+
* - an invalid header (`bytes=5-2`, `bytes=abc`, `bytes=-`) — RFC 9110 lets a server ignore it, and the whole file
|
|
43
|
+
* is what a client that sent garbage can still use;
|
|
44
|
+
* - SEVERAL ranges (`bytes=0-1,5-9`): a `multipart/byteranges` answer is not served, the way Express's `send` does
|
|
45
|
+
* it. Media players and download managers ask for one range at a time;
|
|
46
|
+
* - a file whose length is unknown (`undefined`, negative, not an integer): a `206` must name the total length.
|
|
47
|
+
*
|
|
48
|
+
* `'unsatisfiable'` is the answer to a single range that starts at or past the end of the file, or a suffix range
|
|
49
|
+
* of length 0 — and to every range of an EMPTY file, which has no byte to start at.
|
|
50
|
+
*
|
|
51
|
+
* A range that ends past the file is cut at its last byte, and a suffix longer than the file is the whole file —
|
|
52
|
+
* both are satisfiable by definition, so a client may ask for `bytes=0-` or `bytes=0-999999999` without knowing
|
|
53
|
+
* the size.
|
|
54
|
+
*
|
|
55
|
+
* Pure function, no I/O — the HTTP glue (`resolveDownloadRange()`, `setDownloadRangeHeaders()`) lives next to
|
|
56
|
+
* `pipeFileToResponse()` in the file module.
|
|
57
|
+
*/
|
|
58
|
+
export function parseRangeHeader(
|
|
59
|
+
header: string | string[] | undefined,
|
|
60
|
+
length: number | undefined,
|
|
61
|
+
): RangeHeaderDecision {
|
|
62
|
+
if (typeof length !== 'number' || !Number.isSafeInteger(length) || length < 0) {
|
|
63
|
+
return undefined;
|
|
64
|
+
}
|
|
65
|
+
// Node joins repeated headers with ', ' — a repeated Range header is a list of ranges, answered with the whole file
|
|
66
|
+
const value = Array.isArray(header) ? header.join(',') : header;
|
|
67
|
+
if (typeof value !== 'string' || !value || value.length > MAX_RANGE_HEADER_LENGTH) {
|
|
68
|
+
return undefined;
|
|
69
|
+
}
|
|
70
|
+
const unit = RANGE_UNIT.exec(value);
|
|
71
|
+
if (!unit) {
|
|
72
|
+
return undefined;
|
|
73
|
+
}
|
|
74
|
+
// Empty list elements are allowed and ignored (RFC 9110 §5.6.1)
|
|
75
|
+
const specs = unit[1]
|
|
76
|
+
.split(',')
|
|
77
|
+
.map((spec) => spec.trim())
|
|
78
|
+
.filter(Boolean);
|
|
79
|
+
if (specs.length !== 1) {
|
|
80
|
+
return undefined;
|
|
81
|
+
}
|
|
82
|
+
const match = RANGE_SPEC.exec(specs[0]);
|
|
83
|
+
if (!match) {
|
|
84
|
+
return undefined;
|
|
85
|
+
}
|
|
86
|
+
const [, first, last] = match;
|
|
87
|
+
if (!first && !last) {
|
|
88
|
+
return undefined;
|
|
89
|
+
}
|
|
90
|
+
if (!first) {
|
|
91
|
+
// Suffix range: the last N bytes
|
|
92
|
+
const suffix = toSafeInteger(last);
|
|
93
|
+
if (suffix === undefined) {
|
|
94
|
+
return undefined;
|
|
95
|
+
}
|
|
96
|
+
if (suffix === 0 || length === 0) {
|
|
97
|
+
return 'unsatisfiable';
|
|
98
|
+
}
|
|
99
|
+
return { end: length - 1, start: Math.max(0, length - suffix) };
|
|
100
|
+
}
|
|
101
|
+
const start = toSafeInteger(first);
|
|
102
|
+
const end = last ? toSafeInteger(last) : length - 1;
|
|
103
|
+
if (start === undefined || end === undefined) {
|
|
104
|
+
return undefined;
|
|
105
|
+
}
|
|
106
|
+
if (last && end < start) {
|
|
107
|
+
// `bytes=5-2` is invalid, not unsatisfiable — ignored
|
|
108
|
+
return undefined;
|
|
109
|
+
}
|
|
110
|
+
if (start >= length) {
|
|
111
|
+
return 'unsatisfiable';
|
|
112
|
+
}
|
|
113
|
+
return { end: Math.min(end, length - 1), start };
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
/**
|
|
117
|
+
* Check a range handed to a store read: two safe integers, `0 <= start <= end`. Returns it unchanged, `undefined`
|
|
118
|
+
* for no range, and throws a `RangeError` for anything else — the same answer from every store, before any of them
|
|
119
|
+
* is asked (each would otherwise fail in its own way: S3 with `InvalidRange`, GridFS with a driver error on the
|
|
120
|
+
* stream, the filesystem with a silently empty stream).
|
|
121
|
+
*/
|
|
122
|
+
export function assertByteRange(range: unknown): ByteRange | undefined {
|
|
123
|
+
if (range === undefined || range === null) {
|
|
124
|
+
return undefined;
|
|
125
|
+
}
|
|
126
|
+
const { end, start } = range as { end: number; start: number };
|
|
127
|
+
if (!Number.isSafeInteger(start) || !Number.isSafeInteger(end) || start < 0 || end < start) {
|
|
128
|
+
throw new RangeError(
|
|
129
|
+
`Invalid byte range { start: ${String(start)}, end: ${String(end)} }: start and end must be integers with 0 <= start <= end (end inclusive)`,
|
|
130
|
+
);
|
|
131
|
+
}
|
|
132
|
+
return { end, start };
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
/** The `Content-Range` value of a range of a file with `length` bytes: `bytes 0-1/1234` */
|
|
136
|
+
export function contentRangeValue(range: ByteRange, length: number): string {
|
|
137
|
+
return `bytes ${range.start}-${range.end}/${length}`;
|
|
138
|
+
}
|
|
139
|
+
|
|
140
|
+
/** Digits as a safe integer, `undefined` when they exceed what a Number holds exactly */
|
|
141
|
+
function toSafeInteger(digits: string): number | undefined {
|
|
142
|
+
const value = Number(digits);
|
|
143
|
+
return Number.isSafeInteger(value) ? value : undefined;
|
|
144
|
+
}
|
|
@@ -2,6 +2,8 @@ import { ExecutionContext } from '@nestjs/common';
|
|
|
2
2
|
import { GqlExecutionContext } from '@nestjs/graphql';
|
|
3
3
|
import { Request as RequestType } from 'express';
|
|
4
4
|
|
|
5
|
+
import { isAgentCallContext, resolveAgentCallRequest } from './execution-context-request.helper.js';
|
|
6
|
+
|
|
5
7
|
/**
|
|
6
8
|
* Helper for context processing
|
|
7
9
|
* @deprecated use functions directly
|
|
@@ -33,6 +35,18 @@ export function getContextData(context: ExecutionContext): {
|
|
|
33
35
|
return { args: null, currentUser: null, request: null };
|
|
34
36
|
}
|
|
35
37
|
|
|
38
|
+
// An agent function / MCP call (nestjs-ai plan §1): the user is the one of the request the call runs in — never a
|
|
39
|
+
// `user` in the call's arguments, which the model or the MCP client wrote. A request-less call has no user, so the
|
|
40
|
+
// interceptors filter its result for an anonymous caller (the strictest view).
|
|
41
|
+
if (isAgentCallContext(context)) {
|
|
42
|
+
const agentRequest = resolveAgentCallRequest(context);
|
|
43
|
+
return {
|
|
44
|
+
args: context.getArgByIndex(0),
|
|
45
|
+
currentUser: agentRequest?.user,
|
|
46
|
+
request: (agentRequest ?? null) as RequestType,
|
|
47
|
+
};
|
|
48
|
+
}
|
|
49
|
+
|
|
36
50
|
// Init data
|
|
37
51
|
let user: { [key: string]: any };
|
|
38
52
|
let rawContext: any = null;
|
|
@@ -3,12 +3,17 @@ import { GqlContextType, GqlExecutionContext } from '@nestjs/graphql';
|
|
|
3
3
|
import type { PopulateOptions } from 'mongoose';
|
|
4
4
|
|
|
5
5
|
import { getPopulateOptions } from './db.helper.js';
|
|
6
|
+
import { isAgentCallContext, resolveAgentCallRequest } from './execution-context-request.helper.js';
|
|
6
7
|
import { removePropertiesDeep } from './input.helper.js';
|
|
7
8
|
|
|
8
9
|
/**
|
|
9
10
|
* Decorator function to get current user for Controller (http context) and Resolver (graphql context)
|
|
10
11
|
*/
|
|
11
12
|
export function currentUserDec(data, ctx: ExecutionContext) {
|
|
13
|
+
// An agent function / MCP call: the request's user, never one in the call's arguments (nestjs-ai plan §1)
|
|
14
|
+
if (isAgentCallContext(ctx)) {
|
|
15
|
+
return resolveAgentCallRequest(ctx)?.user;
|
|
16
|
+
}
|
|
12
17
|
if (ctx.getType<GqlContextType>() === 'graphql') {
|
|
13
18
|
const gqlContext = GqlExecutionContext.create(ctx);
|
|
14
19
|
return gqlContext.getContext().req.user;
|
|
@@ -28,7 +28,78 @@
|
|
|
28
28
|
* `src/core/common/**` and from `src/core/modules/**` alike without adding an import edge between
|
|
29
29
|
* them. See `.claude/rules/architecture.md` → "DI Token Placement (SWC-Safe)".
|
|
30
30
|
*/
|
|
31
|
-
import type { ExecutionContext } from '@nestjs/common';
|
|
31
|
+
import type { ArgumentsHost, ExecutionContext } from '@nestjs/common';
|
|
32
|
+
|
|
33
|
+
/**
|
|
34
|
+
* The execution context types of an agent function call (`@nestjs/ai`, `'ai'`) and of an MCP primitive call
|
|
35
|
+
* (`@nestjs/mcp`, `'mcp'`). nestjs-ai plan §1.
|
|
36
|
+
*
|
|
37
|
+
* Both packages wrap a method with Nest's `ExternalContextCreator`, so EVERY global guard, interceptor and filter of
|
|
38
|
+
* the application runs around it — ours included, in any project that installs either package, whether or not it uses
|
|
39
|
+
* the framework's own AI module. Their arguments are `[input, call]`:
|
|
40
|
+
*
|
|
41
|
+
* | Index | `'ai'` (`AgentFunctionContext`) | `'mcp'` (`McpContext`) | Trust |
|
|
42
|
+
* |-------|---------------------------------|------------------------|-------|
|
|
43
|
+
* | 0 | the tool arguments the MODEL wrote | the tool arguments the MCP CLIENT sent | none — attacker-controlled |
|
|
44
|
+
* | 1 | built by `@nestjs/ai` from the call's `caller` (`request`, `user`, `scopes`) | built by `@nestjs/mcp` (`request`, `authInfo`) | server code |
|
|
45
|
+
*
|
|
46
|
+
* Until this fix every guard fell back to `switchToHttp().getRequest()` on such a context — which is index 0, the
|
|
47
|
+
* MODEL's arguments. A tool call `{ "user": { "roles": ["admin"] } }` was then the request a guard decided on. The
|
|
48
|
+
* resolvers below are duck-typed against that argument layout on purpose: `src/core/common/` imports neither package,
|
|
49
|
+
* so a project without them loads nothing new.
|
|
50
|
+
*/
|
|
51
|
+
export const AGENT_CALL_CONTEXT_TYPES: ReadonlySet<string> = new Set(['ai', 'mcp']);
|
|
52
|
+
|
|
53
|
+
/**
|
|
54
|
+
* The second argument of an agent or MCP call, as far as the framework reads it. Everything else on it belongs to the
|
|
55
|
+
* package that built it.
|
|
56
|
+
*/
|
|
57
|
+
export interface AgentCallLike {
|
|
58
|
+
/** The agent function's / tool's name. */
|
|
59
|
+
name?: string;
|
|
60
|
+
/** The HTTP platform's request the call runs in; `undefined` for a queue job, a durable run, stdio. */
|
|
61
|
+
request?: GuardRequestLike;
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
/** Whether `context` is an agent function call (`'ai'`) or an MCP primitive call (`'mcp'`). */
|
|
65
|
+
export function isAgentCallContext(context: ArgumentsHost | undefined): boolean {
|
|
66
|
+
let type: unknown;
|
|
67
|
+
try {
|
|
68
|
+
type = context?.getType?.();
|
|
69
|
+
} catch {
|
|
70
|
+
return false;
|
|
71
|
+
}
|
|
72
|
+
return typeof type === 'string' && AGENT_CALL_CONTEXT_TYPES.has(type);
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
/** The call object (`args[1]`) of an agent or MCP call; `undefined` for any other context. */
|
|
76
|
+
export function agentCallOf(context: ArgumentsHost | undefined): AgentCallLike | undefined {
|
|
77
|
+
if (!isAgentCallContext(context)) {
|
|
78
|
+
return undefined;
|
|
79
|
+
}
|
|
80
|
+
const call = context.getArgByIndex(1);
|
|
81
|
+
return call && typeof call === 'object' ? (call as AgentCallLike) : undefined;
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
/**
|
|
85
|
+
* The request an agent or MCP call runs in — never its arguments.
|
|
86
|
+
*
|
|
87
|
+
* `undefined` for a REQUEST-LESS caller: `@nestjs/ai`'s `caller: { user, scopes }` (a queue job, a durable run) or MCP
|
|
88
|
+
* over stdio. The framework treats such a caller as ANONYMOUS : its
|
|
89
|
+
* `caller.user` is data the calling code put there — a job payload read back from Redis, a workflow's stored input —
|
|
90
|
+
* that nothing authenticated, and the tenant scope of the data layer (`RequestContext`) has no request to come from.
|
|
91
|
+
* So a role-gated agent function or tool refuses it with 401; one open to `S_EVERYONE` runs. A project that runs a
|
|
92
|
+
* role-gated agent function from a job authenticates first and passes the request (`caller: { request }`).
|
|
93
|
+
*
|
|
94
|
+
*/
|
|
95
|
+
export function resolveAgentCallRequest(context: ArgumentsHost | undefined): GuardRequestLike | undefined {
|
|
96
|
+
const call = agentCallOf(context);
|
|
97
|
+
const request = call?.request;
|
|
98
|
+
if (!request || typeof request !== 'object') {
|
|
99
|
+
return undefined;
|
|
100
|
+
}
|
|
101
|
+
return request;
|
|
102
|
+
}
|
|
32
103
|
|
|
33
104
|
/**
|
|
34
105
|
* The shape a guard reads and writes. It is deliberately loose: on HTTP this IS the Express request,
|
|
@@ -61,6 +132,8 @@ function isSubscriptionContext(value: any): boolean {
|
|
|
61
132
|
* Resolve the object a guard should decide on.
|
|
62
133
|
*
|
|
63
134
|
* Order matters:
|
|
135
|
+
* 0. An agent function or MCP call (`'ai'` / `'mcp'`): the request the call runs in, or `undefined` — never the
|
|
136
|
+
* call's arguments, which the HTTP fallback below would return (see {@link resolveAgentCallRequest}).
|
|
64
137
|
* 1. `ctx.getContext().req` — HTTP GraphQL, and the shape every existing consumer expects.
|
|
65
138
|
* 2. The graphql-ws subscription context itself, when it looks like one (see above).
|
|
66
139
|
* 3. `switchToHttp().getRequest()` — REST controllers. On a GraphQL context this returns the
|
|
@@ -73,6 +146,10 @@ export function resolveGuardRequest(
|
|
|
73
146
|
context: ExecutionContext,
|
|
74
147
|
gqlContextOf: (context: ExecutionContext) => any,
|
|
75
148
|
): GuardRequestLike | undefined {
|
|
149
|
+
if (isAgentCallContext(context)) {
|
|
150
|
+
return resolveAgentCallRequest(context);
|
|
151
|
+
}
|
|
152
|
+
|
|
76
153
|
let gqlContext: any;
|
|
77
154
|
try {
|
|
78
155
|
gqlContext = gqlContextOf(context);
|