stitchkit 0.55.0 → 0.56.0
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/dist/browser/socket-io.d.ts +14 -6
- package/dist/browser/socket-io.d.ts.map +1 -1
- package/dist/cli.js +4 -4
- package/dist/contract/errors.d.ts +7 -0
- package/dist/contract/errors.d.ts.map +1 -1
- package/dist/contract/index.js +1 -1
- package/dist/files/boundary.d.ts +8 -5
- package/dist/files/boundary.d.ts.map +1 -1
- package/dist/files.js +1 -1
- package/dist/{index-rgd18hx3.js → index-28cqssm3.js} +7 -0
- package/dist/index-557by2db.js +34 -0
- package/dist/index-5r13htq1.js +283 -0
- package/dist/index-6y759j86.js +1031 -0
- package/dist/{index-1k16zv57.js → index-bfcpjw20.js} +125 -31
- package/dist/{index-0gv7k0ra.js → index-escqg10p.js} +73 -666
- package/dist/{index-v4bbq3p4.js → index-j3dem06f.js} +1 -1
- package/dist/{index-qx84bqzk.js → index-jcc611vh.js} +1 -1
- package/dist/{index-npye5kt7.js → index-n4nfa7gh.js} +3 -3
- package/dist/{index-pzc32v75.js → index-sm2tjx06.js} +41 -4
- package/dist/{index-js7yexng.js → index-xy8fmh6w.js} +83 -4
- package/dist/index.d.ts +2 -2
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +27 -6
- package/dist/node.js +5 -4
- package/dist/observability/index.js +3 -3
- package/dist/remote.js +1 -1
- package/dist/server/context-contribution.d.ts +8 -0
- package/dist/server/context-contribution.d.ts.map +1 -1
- package/dist/server/index.d.ts +1 -1
- package/dist/server/index.d.ts.map +1 -1
- package/dist/server/index.js +8 -5
- package/dist/server/middleware/auth.d.ts +29 -2
- package/dist/server/middleware/auth.d.ts.map +1 -1
- package/dist/testing/surface-conformance.d.ts +143 -10
- package/dist/testing/surface-conformance.d.ts.map +1 -1
- package/dist/testing/surface-manifest.d.ts +132 -33
- package/dist/testing/surface-manifest.d.ts.map +1 -1
- package/dist/testing.d.ts +2 -2
- package/dist/testing.d.ts.map +1 -1
- package/dist/testing.js +470 -122
- package/dist/tools/async-operation.d.ts +210 -18
- package/dist/tools/async-operation.d.ts.map +1 -1
- package/dist/tools/define-download-tool.d.ts.map +1 -1
- package/dist/tools/define-upload-tool.d.ts.map +1 -1
- package/dist/tools/internal/surface-projector.d.ts +101 -0
- package/dist/tools/internal/surface-projector.d.ts.map +1 -0
- package/dist/tools/managed-file-error.d.ts +6 -0
- package/dist/tools/managed-file-error.d.ts.map +1 -0
- package/dist/tools/mcp-prepare.d.ts +3 -21
- package/dist/tools/mcp-prepare.d.ts.map +1 -1
- package/dist/tools/mcp-round-policy.d.ts +9 -0
- package/dist/tools/mcp-round-policy.d.ts.map +1 -0
- package/dist/tools/mcp-round.d.ts +0 -4
- package/dist/tools/mcp-round.d.ts.map +1 -1
- package/dist/tools/mount-download.d.ts.map +1 -1
- package/dist/tools/mount-upload.d.ts.map +1 -1
- package/dist/tools/mount.d.ts +5 -9
- package/dist/tools/mount.d.ts.map +1 -1
- package/dist/tools/runtime-tool.d.ts.map +1 -1
- package/dist/tools/surface.d.ts +7 -0
- package/dist/tools/surface.d.ts.map +1 -1
- package/dist/tools/view-file.d.ts.map +1 -1
- package/dist/tools.d.ts +1 -1
- package/dist/tools.d.ts.map +1 -1
- package/dist/tools.js +348 -383
- package/llms-full.txt +361 -58
- package/package.json +1 -1
- package/dist/index-h60df7rj.js +0 -110
- package/dist/index-k4dftwf7.js +0 -66
|
@@ -158,9 +158,9 @@ export interface SocketIOClient<TServerEvents extends SocketEventMap, TClientEve
|
|
|
158
158
|
*/
|
|
159
159
|
onConnectionChange(listener: (connected: boolean, reason?: string) => void): () => void;
|
|
160
160
|
}
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
161
|
+
/** Minimal Stitchkit client transport required by a validated realtime binding. */
|
|
162
|
+
export type RealtimeClientTransport = Pick<SocketIOClient<SocketEventMap, SocketEventMap>, 'connected' | 'on' | 'emit' | 'emitWithAck' | 'onConnectionChange'>;
|
|
163
|
+
export interface BoundRealtimeClient<TServerToClient extends RealtimeEventRegistry, TClientToServer extends RealtimeEventRegistry> extends ValidatedRealtimeSocket<TServerToClient, TClientToServer> {
|
|
164
164
|
readonly connected: boolean;
|
|
165
165
|
request<TEvent extends RealtimeAcknowledgedEvent<TClientToServer>>(event: TEvent, ...args: [
|
|
166
166
|
...RealtimeRequestArguments<TClientToServer[TEvent]>,
|
|
@@ -168,12 +168,20 @@ export interface RealtimeClient<TServerToClient extends RealtimeEventRegistry, T
|
|
|
168
168
|
]): Promise<RealtimeAcknowledgement<TClientToServer[TEvent]>>;
|
|
169
169
|
onConnectionChange(listener: (connected: boolean, reason?: string) => void): () => void;
|
|
170
170
|
}
|
|
171
|
-
export interface
|
|
172
|
-
|
|
173
|
-
|
|
171
|
+
export interface RealtimeClient<TServerToClient extends RealtimeEventRegistry, TClientToServer extends RealtimeEventRegistry> extends BoundRealtimeClient<TServerToClient, TClientToServer> {
|
|
172
|
+
connect(): void;
|
|
173
|
+
disconnect(): void;
|
|
174
|
+
}
|
|
175
|
+
export interface BindRealtimeClientOptions {
|
|
174
176
|
onRejected?: RealtimeRejectedEventHook;
|
|
175
177
|
logger?: StitchLogger;
|
|
176
178
|
}
|
|
179
|
+
export interface RealtimeClientOptions<TServerToClient extends RealtimeEventRegistry> extends BindRealtimeClientOptions, SocketIOClientConfig<{
|
|
180
|
+
[TEvent in keyof TServerToClient]: (...args: unknown[]) => void;
|
|
181
|
+
}> {
|
|
182
|
+
}
|
|
183
|
+
/** Add contract validation and typed acknowledgements without owning the transport lifecycle. */
|
|
184
|
+
export declare function bindRealtimeClient<const TServerToClient extends RealtimeEventRegistry, const TClientToServer extends RealtimeEventRegistry>(contract: RealtimeContract<TServerToClient, TClientToServer>, transport: RealtimeClientTransport, { onRejected, logger }?: BindRealtimeClientOptions): BoundRealtimeClient<TServerToClient, TClientToServer>;
|
|
177
185
|
export declare function createRealtimeClient<const TServerToClient extends RealtimeEventRegistry, const TClientToServer extends RealtimeEventRegistry>(contract: RealtimeContract<TServerToClient, TClientToServer>, { onRejected, logger, ...config }: RealtimeClientOptions<TServerToClient>): RealtimeClient<TServerToClient, TClientToServer>;
|
|
178
186
|
export declare function createSocketIOClient<TServerEvents extends SocketEventMap, TClientEvents extends SocketEventMap>(config: SocketIOClientConfig<TServerEvents>): SocketIOClient<TServerEvents, TClientEvents>;
|
|
179
187
|
//# sourceMappingURL=socket-io.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"socket-io.d.ts","sourceRoot":"","sources":["../../src/browser/socket-io.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;GAqBG;AACH,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,8BAA8B,CAAC;AAC9D,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,WAAW,CAAC;AAC9C,OAAO,KAAK,EACV,yBAAyB,EACzB,uBAAuB,EACvB,gBAAgB,EAChB,qBAAqB,EACrB,yBAAyB,EACzB,wBAAwB,EACzB,MAAM,sBAAsB,CAAC;AAC9B,OAAO,EAEL,KAAK,sBAAsB,EAE5B,MAAM,qBAAqB,CAAC;AAC7B,OAAO,EAIL,KAAK,uBAAuB,EAC7B,MAAM,oBAAoB,CAAC;AA0D5B;;;;;;GAMG;AACH,MAAM,MAAM,cAAc,GAAG,SAAS,CAAC;AAEvC,MAAM,WAAW,oBAAoB,CAAC,aAAa,SAAS,cAAc,GAAG,cAAc;IACzF,qDAAqD;IACrD,GAAG,EAAE,MAAM,CAAC;IACZ,sDAAsD;IACtD,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,yEAAyE;IACzE,eAAe,CAAC,EAAE,OAAO,CAAC;IAC1B;;;;;;OAMG;IACH,IAAI,CAAC,EACD,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GACvB,CAAC,MAAM,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG,OAAO,CAAC,MAAM,CAAC,MAAM,EAAE,O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AM,EAAE,GAAE,yBAA8B,GACrD,mBAAmB,CAAC,eAAe,EAAE,eAAe,CAAC,CA2EvD;AAED,wBAAgB,oBAAoB,CAClC,KAAK,CAAC,eAAe,SAAS,qBAAqB,EACnD,KAAK,CAAC,eAAe,SAAS,qBAAqB,EAEnD,QAAQ,EAAE,gBAAgB,CAAC,eAAe,EAAE,eAAe,CAAC,EAC5D,EAAE,UAAU,EAAE,MAAM,EAAE,GAAG,MAAM,EAAE,EAAE,qBAAqB,CAAC,eAAe,CAAC,GACxE,cAAc,CAAC,eAAe,EAAE,eAAe,CAAC,CAWlD;AAED,wBAAgB,oBAAoB,CAClC,aAAa,SAAS,cAAc,EACpC,aAAa,SAAS,cAAc,EACpC,MAAM,EAAE,oBAAoB,CAAC,aAAa,CAAC,GAAG,cAAc,CAAC,aAAa,EAAE,aAAa,CAAC,CA8N3F"}
|
package/dist/cli.js
CHANGED
|
@@ -5,12 +5,12 @@ import {
|
|
|
5
5
|
emitResult,
|
|
6
6
|
parseCliArgs,
|
|
7
7
|
pollUntilDone
|
|
8
|
-
} from "./index-
|
|
8
|
+
} from "./index-escqg10p.js";
|
|
9
9
|
import"./index-sbdmyz75.js";
|
|
10
|
-
import"./index-
|
|
10
|
+
import"./index-6y759j86.js";
|
|
11
11
|
import"./index-cby4ar3v.js";
|
|
12
|
-
import"./index-
|
|
13
|
-
import"./index-
|
|
12
|
+
import"./index-j3dem06f.js";
|
|
13
|
+
import"./index-5r13htq1.js";
|
|
14
14
|
import"./index-6k1937bx.js";
|
|
15
15
|
import"./index-7eq9va6e.js";
|
|
16
16
|
import"./index-1bx83sw4.js";
|
|
@@ -73,6 +73,13 @@ export declare const STITCH_ERROR_STATUS: {
|
|
|
73
73
|
CONFLICT: number;
|
|
74
74
|
RATE_LIMITED: number;
|
|
75
75
|
VALIDATION_ERROR: number;
|
|
76
|
+
FILE_INVALID_PATH: number;
|
|
77
|
+
FILE_OUTSIDE_ROOT: number;
|
|
78
|
+
FILE_NOT_FOUND: number;
|
|
79
|
+
FILE_NOT_REGULAR: number;
|
|
80
|
+
FILE_INSPECTION_REJECTED: number;
|
|
81
|
+
FILE_TOO_LARGE: number;
|
|
82
|
+
FILE_EXISTS: number;
|
|
76
83
|
REALTIME_CONTRACT_VIOLATION: number;
|
|
77
84
|
INTERNAL_SERVER_ERROR: number;
|
|
78
85
|
};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"errors.d.ts","sourceRoot":"","sources":["../../src/contract/errors.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AACH,MAAM,WAAW,aAAa;IAC5B,KAAK,EAAE;QACL,2CAA2C;QAC3C,IAAI,EAAE,MAAM,CAAC;QACb,8BAA8B;QAC9B,OAAO,CAAC,EAAE,MAAM,CAAC;QACjB,gCAAgC;QAChC,OAAO,CAAC,EAAE,OAAO,CAAC;QAClB,0BAA0B;QAC1B,IAAI,CAAC,EAAE,MAAM,CAAC;KACf,CAAC;CACH;AAcD;;;;GAIG;AACH,qBAAa,QAAQ,CACnB,KAAK,SAAS,MAAM,GAAG,MAAM,EAC7B,QAAQ,SAAS,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG,SAAS,GAAG,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG,SAAS,CAC1F,SAAQ,KAAK;aAEK,IAAI,EAAE,KAAK;aAEX,MAAM,EAAE,MAAM;aACd,OAAO,CAAC,EAAE,QAAQ;aAClB,IAAI,CAAC,EAAE,MAAM;IAC7B;;;;OAIG;aACa,OAAO,CAAC,EAAE,MAAM;IAXlC,YACkB,IAAI,EAAE,KAAK,EAC3B,OAAO,CAAC,EAAE,MAAM,EACA,MAAM,GAAE,MAAY,EACpB,OAAO,CAAC,EAAE,QAAQ,YAAA,EAClB,IAAI,CAAC,EAAE,MAAM,YAAA;IAC7B;;;;OAIG;IACa,OAAO,CAAC,EAAE,MAAM,YAAA,EAQjC;IAED,MAAM,CAAC,EAAE,CAAC,GAAG,EAAE,OAAO,GAA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AAC,IAAI,EAAE,MAAM,GAAG,IAAI,IAAI,eAAe,CAEvE;AAED,+FAA+F;AAC/F,wBAAgB,QAAQ,CACtB,IAAI,EAAE,MAAM,EACZ,OAAO,CAAC,EAAE,MAAM,EAChB,OAAO,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAChC,KAAK,CAOP"}
|
package/dist/contract/index.js
CHANGED
package/dist/files/boundary.d.ts
CHANGED
|
@@ -8,18 +8,21 @@ export interface ManagedFileInspectionInput {
|
|
|
8
8
|
prefix: Uint8Array;
|
|
9
9
|
declaredMediaType?: string;
|
|
10
10
|
name: string;
|
|
11
|
+
/** Aborts with the caller or the boundary's inspection deadline. */
|
|
12
|
+
signal: AbortSignal;
|
|
11
13
|
}
|
|
12
|
-
export
|
|
13
|
-
mediaType?: string;
|
|
14
|
-
name?: string;
|
|
15
|
-
}
|
|
14
|
+
export type ManagedFileInspection = Pick<ManagedFileRef, 'mediaType' | 'name'>;
|
|
16
15
|
export type ManagedFileInspector = (input: ManagedFileInspectionInput) => ManagedFileInspection | Promise<ManagedFileInspection>;
|
|
17
16
|
export interface ManagedFileBoundaryConfig {
|
|
18
|
-
/**
|
|
17
|
+
/** Directory owned exclusively by the application or trusted OS actor. */
|
|
19
18
|
root: string;
|
|
19
|
+
/** Create the missing final root below an existing trusted parent. Default `false`. */
|
|
20
|
+
createRoot?: boolean;
|
|
20
21
|
maxReadBytes?: number;
|
|
21
22
|
maxWriteBytes?: number;
|
|
22
23
|
inspectionBytes?: number;
|
|
24
|
+
/** Maximum time to wait for a content inspector. Default 15 seconds. */
|
|
25
|
+
inspectionTimeoutMs?: number;
|
|
23
26
|
inspect?: ManagedFileInspector;
|
|
24
27
|
onCleanupError?: (error: unknown) => void;
|
|
25
28
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"boundary.d.ts","sourceRoot":"","sources":["../../src/files/boundary.ts"],"names":[],"mappings":"AAIA,OAAO,EAEL,KAAK,cAAc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AAI,CAAC;CAC3C;AAED,MAAM,WAAW,sBAAsB;IACrC,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,MAAM,CAAC,EAAE,WAAW,CAAC;CACtB;AAED,MAAM,WAAW,uBAAuB;IACtC,OAAO,CAAC,EAAE,OAAO,CAAC;IAClB,OAAO,CAAC,EAAE,OAAO,CAAC;IAClB,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,MAAM,CAAC,EAAE,WAAW,CAAC;CACtB;AAED,MAAM,WAAW,iBAAiB;IAChC,GAAG,EAAE,cAAc,CAAC;IACpB,KAAK,EAAE,UAAU,CAAC;CACnB;AAED,MAAM,WAAW,mBAAmB;IAClC,IAAI,CAAC,IAAI,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE,sBAAsB,GAAG,OAAO,CAAC,iBAAiB,CAAC,CAAC;IACjF,KAAK,CACH,IAAI,EAAE,MAAM,EACZ,MAAM,EAAE,UAAU,GAAG,cAAc,CAAC,UAAU,CAAC,EAC/C,OAAO,CAAC,EAAE,uBAAuB,GAChC,OAAO,CAAC,cAAc,CAAC,CAAC;CAC5B;AAmRD;;;;GAIG;AACH,wBAAsB,yBAAyB,CAC7C,MAAM,EAAE,yBAAyB,GAChC,OAAO,CAAC,mBAAmB,CAAC,CAyJ9B"}
|
package/dist/files.js
CHANGED
|
@@ -276,6 +276,13 @@ var STITCH_ERROR_STATUS = {
|
|
|
276
276
|
CONFLICT: 409,
|
|
277
277
|
RATE_LIMITED: 429,
|
|
278
278
|
VALIDATION_ERROR: 400,
|
|
279
|
+
FILE_INVALID_PATH: 400,
|
|
280
|
+
FILE_OUTSIDE_ROOT: 400,
|
|
281
|
+
FILE_NOT_FOUND: 404,
|
|
282
|
+
FILE_NOT_REGULAR: 422,
|
|
283
|
+
FILE_INSPECTION_REJECTED: 422,
|
|
284
|
+
FILE_TOO_LARGE: 413,
|
|
285
|
+
FILE_EXISTS: 409,
|
|
279
286
|
REALTIME_CONTRACT_VIOLATION: 500,
|
|
280
287
|
INTERNAL_SERVER_ERROR: 500
|
|
281
288
|
};
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
// src/realtime/request.ts
|
|
2
|
+
class RealtimeRequestTimeoutError extends Error {
|
|
3
|
+
code = "REALTIME_REQUEST_TIMEOUT";
|
|
4
|
+
event;
|
|
5
|
+
timeoutMs;
|
|
6
|
+
constructor(event, timeoutMs) {
|
|
7
|
+
super(`Realtime request "${event}" timed out after ${timeoutMs}ms`);
|
|
8
|
+
this.name = "RealtimeRequestTimeoutError";
|
|
9
|
+
this.event = event;
|
|
10
|
+
this.timeoutMs = timeoutMs;
|
|
11
|
+
}
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
class RealtimeRequestDisconnectedError extends Error {
|
|
15
|
+
code = "REALTIME_REQUEST_DISCONNECTED";
|
|
16
|
+
event;
|
|
17
|
+
constructor(event) {
|
|
18
|
+
super(`Realtime request "${event}" was interrupted by disconnect`);
|
|
19
|
+
this.name = "RealtimeRequestDisconnectedError";
|
|
20
|
+
this.event = event;
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
class RealtimeRequestInvalidAcknowledgementError extends Error {
|
|
25
|
+
code = "REALTIME_REQUEST_INVALID_ACKNOWLEDGEMENT";
|
|
26
|
+
event;
|
|
27
|
+
constructor(event, cause) {
|
|
28
|
+
super(`Realtime request "${event}" received an invalid acknowledgement`, { cause });
|
|
29
|
+
this.name = "RealtimeRequestInvalidAcknowledgementError";
|
|
30
|
+
this.event = event;
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
export { RealtimeRequestTimeoutError, RealtimeRequestDisconnectedError, RealtimeRequestInvalidAcknowledgementError };
|
|
@@ -0,0 +1,283 @@
|
|
|
1
|
+
import {
|
|
2
|
+
parseTrailingWildcard
|
|
3
|
+
} from "./index-7eq9va6e.js";
|
|
4
|
+
|
|
5
|
+
// src/contract/errors.ts
|
|
6
|
+
var APP_ERROR_BRAND = Symbol.for("stitchkit.AppError");
|
|
7
|
+
|
|
8
|
+
class AppError extends Error {
|
|
9
|
+
code;
|
|
10
|
+
status;
|
|
11
|
+
details;
|
|
12
|
+
hint;
|
|
13
|
+
traceId;
|
|
14
|
+
constructor(code, message, status = 500, details, hint, traceId) {
|
|
15
|
+
super(message ?? code);
|
|
16
|
+
this.code = code;
|
|
17
|
+
this.status = status;
|
|
18
|
+
this.details = details;
|
|
19
|
+
this.hint = hint;
|
|
20
|
+
this.traceId = traceId;
|
|
21
|
+
this.name = "AppError";
|
|
22
|
+
Object.defineProperty(this, APP_ERROR_BRAND, { value: true });
|
|
23
|
+
}
|
|
24
|
+
static is(err) {
|
|
25
|
+
return typeof err === "object" && err !== null && APP_ERROR_BRAND in err;
|
|
26
|
+
}
|
|
27
|
+
toJSON() {
|
|
28
|
+
return {
|
|
29
|
+
error: {
|
|
30
|
+
code: this.code,
|
|
31
|
+
message: this.message,
|
|
32
|
+
...this.details && { details: this.details },
|
|
33
|
+
...this.hint && { hint: this.hint }
|
|
34
|
+
}
|
|
35
|
+
};
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
function notFound(message = "Not found") {
|
|
39
|
+
throw new AppError("NOT_FOUND", message, 404);
|
|
40
|
+
}
|
|
41
|
+
function badRequest(message, details) {
|
|
42
|
+
throw new AppError("BAD_REQUEST", message, 400, details);
|
|
43
|
+
}
|
|
44
|
+
function unauthorized(message = "Unauthorized") {
|
|
45
|
+
throw new AppError("UNAUTHORIZED", message, 401);
|
|
46
|
+
}
|
|
47
|
+
function forbidden(message = "Forbidden") {
|
|
48
|
+
throw new AppError("FORBIDDEN", message, 403);
|
|
49
|
+
}
|
|
50
|
+
function conflict(message = "Conflict", details) {
|
|
51
|
+
throw new AppError("CONFLICT", message, 409, details);
|
|
52
|
+
}
|
|
53
|
+
function rateLimited(message = "Too many requests") {
|
|
54
|
+
throw new AppError("RATE_LIMITED", message, 429);
|
|
55
|
+
}
|
|
56
|
+
var STITCH_ERROR_STATUS = {
|
|
57
|
+
BAD_REQUEST: 400,
|
|
58
|
+
UNAUTHORIZED: 401,
|
|
59
|
+
FORBIDDEN: 403,
|
|
60
|
+
NOT_FOUND: 404,
|
|
61
|
+
METHOD_NOT_ALLOWED: 405,
|
|
62
|
+
CONFLICT: 409,
|
|
63
|
+
RATE_LIMITED: 429,
|
|
64
|
+
VALIDATION_ERROR: 400,
|
|
65
|
+
FILE_INVALID_PATH: 400,
|
|
66
|
+
FILE_OUTSIDE_ROOT: 400,
|
|
67
|
+
FILE_NOT_FOUND: 404,
|
|
68
|
+
FILE_NOT_REGULAR: 422,
|
|
69
|
+
FILE_INSPECTION_REJECTED: 422,
|
|
70
|
+
FILE_TOO_LARGE: 413,
|
|
71
|
+
FILE_EXISTS: 409,
|
|
72
|
+
REALTIME_CONTRACT_VIOLATION: 500,
|
|
73
|
+
INTERNAL_SERVER_ERROR: 500
|
|
74
|
+
};
|
|
75
|
+
function isStitchErrorCode(code) {
|
|
76
|
+
return Object.hasOwn(STITCH_ERROR_STATUS, code);
|
|
77
|
+
}
|
|
78
|
+
function appError(code, message, details) {
|
|
79
|
+
throw new AppError(code, message, isStitchErrorCode(code) ? STITCH_ERROR_STATUS[code] : 500, details);
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
// src/contract/define.ts
|
|
83
|
+
import { z } from "zod";
|
|
84
|
+
|
|
85
|
+
// src/internal/safe-json.ts
|
|
86
|
+
function isUnsafeKey(key) {
|
|
87
|
+
return key === "__proto__";
|
|
88
|
+
}
|
|
89
|
+
function safeJsonParse(text) {
|
|
90
|
+
return JSON.parse(text, (key, value) => isUnsafeKey(key) ? undefined : value);
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
// src/contract/define.ts
|
|
94
|
+
function defineContract(meta, endpoints) {
|
|
95
|
+
const toolTransports = new Map;
|
|
96
|
+
for (const [key, ep] of Object.entries(endpoints)) {
|
|
97
|
+
const wildcard = parseTrailingWildcard(ep.path);
|
|
98
|
+
if (wildcard) {
|
|
99
|
+
if (!ep.params) {
|
|
100
|
+
throw new Error(`Contract "${meta.prefix}": endpoint "${key}" wildcard "${wildcard.name}" requires a params schema field`);
|
|
101
|
+
}
|
|
102
|
+
const paramsJson = z.toJSONSchema(ep.params, { io: "input" });
|
|
103
|
+
if (!paramsJson.properties || !(wildcard.name in paramsJson.properties)) {
|
|
104
|
+
throw new Error(`Contract "${meta.prefix}": endpoint "${key}" params schema is missing wildcard field "${wildcard.name}"`);
|
|
105
|
+
}
|
|
106
|
+
}
|
|
107
|
+
if (ep.desc.trim() === "") {
|
|
108
|
+
throw new Error(`Contract "${meta.prefix}": endpoint "${key}" has an empty desc`);
|
|
109
|
+
}
|
|
110
|
+
if (ep.maxJsonBodyBytes !== undefined && (!Number.isSafeInteger(ep.maxJsonBodyBytes) || ep.maxJsonBodyBytes <= 0)) {
|
|
111
|
+
throw new Error(`Contract "${meta.prefix}": endpoint "${key}" maxJsonBodyBytes must be a positive safe integer, received ${ep.maxJsonBodyBytes}`);
|
|
112
|
+
}
|
|
113
|
+
if (ep.multipart)
|
|
114
|
+
assertMultipartEndpoint(meta.prefix, key, ep);
|
|
115
|
+
if (ep.rawResponse)
|
|
116
|
+
assertRawEndpoint(meta.prefix, key, ep);
|
|
117
|
+
if (ep.method === "HEAD")
|
|
118
|
+
assertHeadEndpoint(meta.prefix, key, ep);
|
|
119
|
+
if (ep.rawBody)
|
|
120
|
+
assertRawBodyEndpoint(meta.prefix, key, ep);
|
|
121
|
+
if ("responseMeta" in ep)
|
|
122
|
+
assertResponseMetaEndpoint(meta.prefix, key, ep);
|
|
123
|
+
if (!("toolName" in ep) || !ep.toolName)
|
|
124
|
+
continue;
|
|
125
|
+
const transports = new Set(ep.expose ? ep.expose.filter((t) => t !== "HTTP") : ["MCP", "AGENT"]);
|
|
126
|
+
if (transports.size === 0) {
|
|
127
|
+
throw new Error(`Contract "${meta.prefix}": endpoint "${key}" sets toolName "${ep.toolName}" but is not exposed on any tool transport (MCP / AGENT)`);
|
|
128
|
+
}
|
|
129
|
+
const existing = toolTransports.get(ep.toolName);
|
|
130
|
+
if (existing) {
|
|
131
|
+
for (const t of transports) {
|
|
132
|
+
if (existing.transports.has(t)) {
|
|
133
|
+
throw new Error(`Contract "${meta.prefix}": duplicate toolName "${ep.toolName}" on transport "${t}" (endpoints: "${existing.key}" and "${key}")`);
|
|
134
|
+
}
|
|
135
|
+
existing.transports.add(t);
|
|
136
|
+
}
|
|
137
|
+
} else {
|
|
138
|
+
toolTransports.set(ep.toolName, { key, transports });
|
|
139
|
+
}
|
|
140
|
+
}
|
|
141
|
+
return { meta, endpoints };
|
|
142
|
+
}
|
|
143
|
+
function assertPositiveLimit(where, name, value) {
|
|
144
|
+
if (value !== undefined && (!Number.isSafeInteger(value) || value <= 0)) {
|
|
145
|
+
throw new Error(`${where} ${name} must be a positive safe integer, received ${value}`);
|
|
146
|
+
}
|
|
147
|
+
}
|
|
148
|
+
function assertMultipartEndpoint(prefix, key, ep) {
|
|
149
|
+
const where = `Contract "${prefix}": multipart endpoint "${key}"`;
|
|
150
|
+
if (ep.method !== "POST" && ep.method !== "PUT" && ep.method !== "PATCH") {
|
|
151
|
+
throw new Error(`${where} must use POST, PUT or PATCH`);
|
|
152
|
+
}
|
|
153
|
+
const multipart = ep.multipart;
|
|
154
|
+
if (!multipart || typeof multipart !== "object") {
|
|
155
|
+
throw new Error(`${where} must declare a multipart descriptor`);
|
|
156
|
+
}
|
|
157
|
+
assertPositiveLimit(where, "maxRequestBytes", multipart.maxRequestBytes);
|
|
158
|
+
assertPositiveLimit(where, "maxFieldBytes", multipart.maxFieldBytes);
|
|
159
|
+
const entries = Object.entries(multipart.files);
|
|
160
|
+
if (entries.length === 0)
|
|
161
|
+
throw new Error(`${where} must declare at least one file field`);
|
|
162
|
+
for (const [field, policy] of entries) {
|
|
163
|
+
if (!field || isUnsafeKey(field))
|
|
164
|
+
throw new Error(`${where} has an invalid file field name`);
|
|
165
|
+
assertPositiveLimit(`${where} field "${field}"`, "maxBytes", policy.maxBytes);
|
|
166
|
+
assertPositiveLimit(`${where} field "${field}"`, "maxFiles", policy.maxFiles);
|
|
167
|
+
if (policy.multiple !== true && policy.maxFiles !== undefined) {
|
|
168
|
+
throw new Error(`${where} field "${field}" may set maxFiles only with multiple: true`);
|
|
169
|
+
}
|
|
170
|
+
if (policy.contentTypes) {
|
|
171
|
+
if (policy.contentTypes.length === 0) {
|
|
172
|
+
throw new Error(`${where} field "${field}" contentTypes cannot be empty`);
|
|
173
|
+
}
|
|
174
|
+
for (const contentType of policy.contentTypes) {
|
|
175
|
+
if (!/^[a-z0-9!#$&^_.+-]+\/(?:[a-z0-9!#$&^_.+-]+|\*)$/i.test(contentType)) {
|
|
176
|
+
throw new Error(`${where} field "${field}" has invalid content type policy "${contentType}"`);
|
|
177
|
+
}
|
|
178
|
+
}
|
|
179
|
+
}
|
|
180
|
+
}
|
|
181
|
+
}
|
|
182
|
+
function assertRawEndpoint(prefix, key, ep) {
|
|
183
|
+
const where = `Contract "${prefix}": raw endpoint "${key}"`;
|
|
184
|
+
if (ep.output)
|
|
185
|
+
throw new Error(`${where} cannot declare an output schema`);
|
|
186
|
+
if ("toolName" in ep && ep.toolName)
|
|
187
|
+
throw new Error(`${where} cannot set a toolName`);
|
|
188
|
+
if ("ui" in ep && ep.ui)
|
|
189
|
+
throw new Error(`${where} cannot set MCP ui metadata`);
|
|
190
|
+
if ("annotations" in ep && ep.annotations) {
|
|
191
|
+
throw new Error(`${where} cannot set MCP annotations`);
|
|
192
|
+
}
|
|
193
|
+
const nonHttp = (ep.expose ?? []).filter((t) => t !== "HTTP");
|
|
194
|
+
if (nonHttp.length > 0) {
|
|
195
|
+
throw new Error(`${where} is HTTP-only — remove ${nonHttp.join(", ")} from expose`);
|
|
196
|
+
}
|
|
197
|
+
}
|
|
198
|
+
function assertHeadEndpoint(prefix, key, ep) {
|
|
199
|
+
const where = `Contract "${prefix}": HEAD endpoint "${key}"`;
|
|
200
|
+
if (!ep.rawResponse)
|
|
201
|
+
throw new Error(`${where} must declare rawResponse: true`);
|
|
202
|
+
if (ep.input)
|
|
203
|
+
throw new Error(`${where} cannot declare an input schema`);
|
|
204
|
+
if (ep.multipart)
|
|
205
|
+
throw new Error(`${where} cannot be multipart`);
|
|
206
|
+
if (ep.rawBody)
|
|
207
|
+
throw new Error(`${where} cannot retain a raw body`);
|
|
208
|
+
}
|
|
209
|
+
function assertRawBodyEndpoint(prefix, key, ep) {
|
|
210
|
+
const where = `Contract "${prefix}": rawBody endpoint "${key}"`;
|
|
211
|
+
if (!ep.input)
|
|
212
|
+
throw new Error(`${where} must declare an input schema`);
|
|
213
|
+
if (ep.multipart)
|
|
214
|
+
throw new Error(`${where} cannot be multipart`);
|
|
215
|
+
if (ep.method !== "POST" && ep.method !== "PUT" && ep.method !== "PATCH") {
|
|
216
|
+
throw new Error(`${where} must use POST, PUT or PATCH`);
|
|
217
|
+
}
|
|
218
|
+
if ("toolName" in ep && ep.toolName)
|
|
219
|
+
throw new Error(`${where} cannot set a toolName`);
|
|
220
|
+
if ("ui" in ep && ep.ui)
|
|
221
|
+
throw new Error(`${where} cannot set MCP ui metadata`);
|
|
222
|
+
if ("annotations" in ep && ep.annotations) {
|
|
223
|
+
throw new Error(`${where} cannot set MCP annotations`);
|
|
224
|
+
}
|
|
225
|
+
const nonHttp = (ep.expose ?? []).filter((transport) => transport !== "HTTP");
|
|
226
|
+
if (nonHttp.length > 0) {
|
|
227
|
+
throw new Error(`${where} is HTTP-only — remove ${nonHttp.join(", ")} from expose`);
|
|
228
|
+
}
|
|
229
|
+
}
|
|
230
|
+
function assertResponseMetaEndpoint(prefix, key, ep) {
|
|
231
|
+
const where = `Contract "${prefix}": responseMeta endpoint "${key}"`;
|
|
232
|
+
if (!ep.responseMeta || typeof ep.responseMeta !== "object") {
|
|
233
|
+
throw new Error(`${where} must declare responseMeta as an object`);
|
|
234
|
+
}
|
|
235
|
+
const status = ep.responseMeta.status;
|
|
236
|
+
if (status !== undefined && (!Number.isSafeInteger(status) || status < 200 || status > 299)) {
|
|
237
|
+
throw new Error(`${where} status must be a successful 2xx integer, received ${status}`);
|
|
238
|
+
}
|
|
239
|
+
if (ep.output && (status === 204 || status === 205)) {
|
|
240
|
+
throw new Error(`${where} cannot combine output with bodyless status ${status}`);
|
|
241
|
+
}
|
|
242
|
+
if (ep.rawResponse)
|
|
243
|
+
throw new Error(`${where} cannot also be a rawResponse endpoint`);
|
|
244
|
+
if ("toolName" in ep && ep.toolName)
|
|
245
|
+
throw new Error(`${where} cannot set a toolName`);
|
|
246
|
+
if ("ui" in ep && ep.ui)
|
|
247
|
+
throw new Error(`${where} cannot set MCP ui metadata`);
|
|
248
|
+
if ("annotations" in ep && ep.annotations) {
|
|
249
|
+
throw new Error(`${where} cannot set MCP annotations`);
|
|
250
|
+
}
|
|
251
|
+
const nonHttp = (ep.expose ?? []).filter((transport) => transport !== "HTTP");
|
|
252
|
+
if (nonHttp.length > 0) {
|
|
253
|
+
throw new Error(`${where} is HTTP-only — remove ${nonHttp.join(", ")} from expose`);
|
|
254
|
+
}
|
|
255
|
+
}
|
|
256
|
+
function mergeMeta(contractMeta, endpointMeta) {
|
|
257
|
+
if (!contractMeta)
|
|
258
|
+
return endpointMeta;
|
|
259
|
+
if (!endpointMeta)
|
|
260
|
+
return { ...contractMeta };
|
|
261
|
+
return { ...contractMeta, ...endpointMeta };
|
|
262
|
+
}
|
|
263
|
+
// src/contract/errors-factory.ts
|
|
264
|
+
import { z as z2 } from "zod";
|
|
265
|
+
// src/contract/pagination.ts
|
|
266
|
+
import { z as z3 } from "zod";
|
|
267
|
+
|
|
268
|
+
// src/internal/base64url.ts
|
|
269
|
+
function bytesToBase64Url(bytes) {
|
|
270
|
+
let binary = "";
|
|
271
|
+
for (const byte of bytes)
|
|
272
|
+
binary += String.fromCharCode(byte);
|
|
273
|
+
return btoa(binary).replace(/\+/g, "-").replace(/\//g, "_").replace(/=+$/, "");
|
|
274
|
+
}
|
|
275
|
+
function base64UrlToBytes(segment) {
|
|
276
|
+
if (!/^[A-Za-z0-9_-]*$/.test(segment) || segment.length % 4 === 1) {
|
|
277
|
+
throw new Error("invalid base64url segment");
|
|
278
|
+
}
|
|
279
|
+
const b64 = segment.replace(/-/g, "+").replace(/_/g, "/");
|
|
280
|
+
const padded = b64.padEnd(Math.ceil(b64.length / 4) * 4, "=");
|
|
281
|
+
return Uint8Array.from(atob(padded), (c) => c.charCodeAt(0));
|
|
282
|
+
}
|
|
283
|
+
export { isUnsafeKey, safeJsonParse, defineContract, mergeMeta, AppError, notFound, badRequest, unauthorized, forbidden, conflict, rateLimited, STITCH_ERROR_STATUS, isStitchErrorCode, appError, bytesToBase64Url, base64UrlToBytes };
|