stitchkit 0.45.0 → 0.47.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/README.md +5 -4
- package/dist/browser/cancellation.d.ts +14 -0
- package/dist/browser/cancellation.d.ts.map +1 -0
- package/dist/browser/client-multipart.d.ts +3 -1
- package/dist/browser/client-multipart.d.ts.map +1 -1
- package/dist/browser/client.d.ts +1 -0
- package/dist/browser/client.d.ts.map +1 -1
- package/dist/browser/http.d.ts +1 -0
- package/dist/browser/http.d.ts.map +1 -1
- package/dist/browser/socket-io.d.ts +3 -1
- package/dist/browser/socket-io.d.ts.map +1 -1
- package/dist/cli.js +3 -4
- package/dist/contract/define.d.ts +59 -15
- package/dist/contract/define.d.ts.map +1 -1
- package/dist/contract/errors.d.ts +1 -0
- package/dist/contract/errors.d.ts.map +1 -1
- package/dist/contract/index.d.ts +1 -1
- package/dist/contract/index.d.ts.map +1 -1
- package/dist/contract/index.js +2 -2
- package/dist/{index-w0mec79h.js → index-44xysy8r.js} +697 -301
- package/dist/{index-r6czv7yt.js → index-45dz4m51.js} +50 -3
- package/dist/index-8ekq6res.js +181 -0
- package/dist/{index-yh0p5ddn.js → index-ee621cmy.js} +39 -19
- package/dist/{index-mvjyq9h9.js → index-kp8xamqp.js} +309 -144
- package/dist/{index-36f1xkdb.js → index-nrytvb30.js} +5 -4
- package/dist/{index-6jypn22c.js → index-r1qp4rve.js} +9 -1
- package/dist/{index-s4qsmgwe.js → index-tss6bk5c.js} +4 -1
- package/dist/index-yxpe3phd.js +63 -0
- package/dist/index.d.ts +1 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +315 -134
- package/dist/internal/errors.d.ts.map +1 -1
- package/dist/internal/secure-fetch.d.ts +23 -3
- package/dist/internal/secure-fetch.d.ts.map +1 -1
- package/dist/internal/typed.d.ts +7 -0
- package/dist/internal/typed.d.ts.map +1 -1
- package/dist/internal/within-dir.d.ts +6 -0
- package/dist/internal/within-dir.d.ts.map +1 -1
- package/dist/logger.d.ts +8 -0
- package/dist/logger.d.ts.map +1 -0
- package/dist/node.js +3 -4
- package/dist/observability/audit.d.ts +22 -3
- package/dist/observability/audit.d.ts.map +1 -1
- package/dist/observability/event.d.ts +7 -0
- package/dist/observability/event.d.ts.map +1 -1
- package/dist/observability/index.d.ts +1 -1
- package/dist/observability/index.d.ts.map +1 -1
- package/dist/observability/index.js +130 -134
- package/dist/observability/sanitize.d.ts +8 -1
- package/dist/observability/sanitize.d.ts.map +1 -1
- package/dist/observability/trace.d.ts +3 -1
- package/dist/observability/trace.d.ts.map +1 -1
- package/dist/react/cache-bridge.d.ts +4 -0
- package/dist/react/cache-bridge.d.ts.map +1 -1
- package/dist/react.js +46 -5
- package/dist/realtime/contract.d.ts +4 -1
- package/dist/realtime/contract.d.ts.map +1 -1
- package/dist/realtime/rejection.d.ts +10 -0
- package/dist/realtime/rejection.d.ts.map +1 -0
- package/dist/realtime/socket.d.ts +14 -1
- package/dist/realtime/socket.d.ts.map +1 -1
- package/dist/server/cache.d.ts +5 -1
- package/dist/server/cache.d.ts.map +1 -1
- package/dist/server/context.d.ts +8 -5
- package/dist/server/context.d.ts.map +1 -1
- package/dist/server/create.d.ts.map +1 -1
- package/dist/server/error-hook.d.ts +1 -0
- package/dist/server/error-hook.d.ts.map +1 -1
- package/dist/server/file.d.ts +6 -0
- package/dist/server/file.d.ts.map +1 -1
- package/dist/server/implement.d.ts +33 -2
- package/dist/server/implement.d.ts.map +1 -1
- package/dist/server/index.d.ts +5 -6
- package/dist/server/index.d.ts.map +1 -1
- package/dist/server/index.js +133 -14
- package/dist/server/middleware/auth.d.ts +7 -4
- package/dist/server/middleware/auth.d.ts.map +1 -1
- package/dist/server/middleware/cors.d.ts.map +1 -1
- package/dist/server/multipart.d.ts +13 -18
- package/dist/server/multipart.d.ts.map +1 -1
- package/dist/server/openapi.d.ts.map +1 -1
- package/dist/server/realtime.d.ts +2 -0
- package/dist/server/realtime.d.ts.map +1 -1
- package/dist/server/router.d.ts +0 -8
- package/dist/server/router.d.ts.map +1 -1
- package/dist/server/stream.d.ts.map +1 -1
- package/dist/server/types.d.ts +50 -22
- package/dist/server/types.d.ts.map +1 -1
- package/dist/tools/cli-args.d.ts +11 -3
- package/dist/tools/cli-args.d.ts.map +1 -1
- package/dist/tools/cli.d.ts +5 -0
- package/dist/tools/cli.d.ts.map +1 -1
- package/dist/tools/coerce.d.ts.map +1 -1
- package/dist/tools/json-schema.d.ts.map +1 -1
- package/dist/tools/mcp-handler.d.ts +4 -3
- package/dist/tools/mcp-handler.d.ts.map +1 -1
- package/dist/tools/mcp-prepare.d.ts +95 -0
- package/dist/tools/mcp-prepare.d.ts.map +1 -0
- package/dist/tools/mcp-round.d.ts +4 -0
- package/dist/tools/mcp-round.d.ts.map +1 -1
- package/dist/tools/mcp-stdio.d.ts +2 -1
- package/dist/tools/mcp-stdio.d.ts.map +1 -1
- package/dist/tools/mcp.d.ts +2 -78
- package/dist/tools/mcp.d.ts.map +1 -1
- package/dist/tools/mount-download.d.ts +5 -0
- package/dist/tools/mount-download.d.ts.map +1 -1
- package/dist/tools/native-mcp.d.ts +1 -1
- package/dist/tools/native-mcp.d.ts.map +1 -1
- package/dist/tools/oauth-provider.d.ts +20 -1
- package/dist/tools/oauth-provider.d.ts.map +1 -1
- package/dist/tools/tool-logger.d.ts +1 -1
- package/dist/tools/tool-logger.d.ts.map +1 -1
- package/dist/tools/view-file.d.ts +9 -0
- package/dist/tools/view-file.d.ts.map +1 -1
- package/dist/tools.d.ts +2 -1
- package/dist/tools.d.ts.map +1 -1
- package/dist/tools.js +505 -278
- package/llms-full.txt +473 -85
- package/llms.txt +1 -1
- package/package.json +2 -2
- package/dist/index-frfyw9fa.js +0 -33
- package/dist/index-x3fcszf8.js +0 -8
|
@@ -6,7 +6,7 @@ import {
|
|
|
6
6
|
isUnsafeKey,
|
|
7
7
|
safeJsonParse,
|
|
8
8
|
unauthorized
|
|
9
|
-
} from "./index-
|
|
9
|
+
} from "./index-ee621cmy.js";
|
|
10
10
|
|
|
11
11
|
// src/server/middleware/cookies.ts
|
|
12
12
|
function parseCookies(header) {
|
|
@@ -151,13 +151,13 @@ function extractToken(req, cookieName) {
|
|
|
151
151
|
function createAuthHook(config) {
|
|
152
152
|
const onAnonymous = config.onAnonymous ?? (() => unauthorized());
|
|
153
153
|
const onForbidden = config.onForbidden ?? (() => forbidden());
|
|
154
|
-
|
|
154
|
+
async function auth(ctx, endpoint) {
|
|
155
155
|
const identity = ctx.source === "http" ? await config.resolve(ctx) : await config.resolveFromContext?.(ctx) ?? null;
|
|
156
156
|
config.inject?.(ctx, identity);
|
|
157
157
|
const scope = endpoint.scope ?? config.defaultScope;
|
|
158
158
|
if (!scope)
|
|
159
159
|
return;
|
|
160
|
-
const rule = config.rules[scope];
|
|
160
|
+
const rule = Object.hasOwn(config.rules, scope) ? config.rules[scope] : undefined;
|
|
161
161
|
if (!rule) {
|
|
162
162
|
throw new Error(`[stitchkit] auth: no rule for scope "${scope}"`);
|
|
163
163
|
}
|
|
@@ -171,7 +171,8 @@ function createAuthHook(config) {
|
|
|
171
171
|
return;
|
|
172
172
|
if (!await rule(identity, ctx))
|
|
173
173
|
onForbidden();
|
|
174
|
-
}
|
|
174
|
+
}
|
|
175
|
+
return auth;
|
|
175
176
|
}
|
|
176
177
|
function createBearerResolver(config) {
|
|
177
178
|
return async (req) => {
|
|
@@ -5,9 +5,17 @@ function assertCorsConfig(config) {
|
|
|
5
5
|
if (config.credentials && (config.origin === undefined || config.origin === "*")) {
|
|
6
6
|
throw new Error("[stitchkit] cors: `credentials: true` cannot be combined with a wildcard origin. " + "Set `origin` to an explicit string or list.");
|
|
7
7
|
}
|
|
8
|
+
if (config.origin === undefined) {
|
|
9
|
+
throw new Error("[stitchkit] cors: `origin` is required. Pass an explicit origin (or list), or '*' to deliberately allow every origin — omit `cors` entirely to emit no CORS headers.");
|
|
10
|
+
}
|
|
11
|
+
if (Array.isArray(config.origin) && config.origin.length === 0) {
|
|
12
|
+
throw new Error("[stitchkit] cors: `origin` cannot be an empty list. Pass explicit origins, or '*' to deliberately allow every origin.");
|
|
13
|
+
}
|
|
8
14
|
}
|
|
9
15
|
function resolveOrigin(config, requestOrigin) {
|
|
10
|
-
if (config.origin === undefined
|
|
16
|
+
if (config.origin === undefined)
|
|
17
|
+
return;
|
|
18
|
+
if (config.origin === "*") {
|
|
11
19
|
return "*";
|
|
12
20
|
}
|
|
13
21
|
if (Array.isArray(config.origin)) {
|
|
@@ -5,6 +5,9 @@ function typedEntries(value) {
|
|
|
5
5
|
function isRecord(value) {
|
|
6
6
|
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
7
7
|
}
|
|
8
|
+
function transportResult(value) {
|
|
9
|
+
return value;
|
|
10
|
+
}
|
|
8
11
|
function mapObject(source, mapper) {
|
|
9
12
|
const result = {};
|
|
10
13
|
for (const [key, value] of typedEntries(source)) {
|
|
@@ -18,4 +21,4 @@ function mapObjectTypeBoundary(source, mapper) {
|
|
|
18
21
|
return mapObject(source, (key, value) => mapper(key, value));
|
|
19
22
|
}
|
|
20
23
|
|
|
21
|
-
export { typedEntries, isRecord, mapObject, mapObjectTypeBoundary };
|
|
24
|
+
export { typedEntries, isRecord, transportResult, mapObject, mapObjectTypeBoundary };
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
// src/internal/within-dir.ts
|
|
2
|
+
import { realpath } from "node:fs/promises";
|
|
3
|
+
import { sep } from "node:path";
|
|
4
|
+
function isWithinDir(root, target) {
|
|
5
|
+
const base = root.endsWith(sep) ? root.slice(0, -sep.length) : root;
|
|
6
|
+
return target === root || target === base || target.startsWith(base + sep);
|
|
7
|
+
}
|
|
8
|
+
async function realPathWithinDir(root, target) {
|
|
9
|
+
const [realRoot, realTarget] = await Promise.all([
|
|
10
|
+
realpath(root).catch(() => null),
|
|
11
|
+
realpath(target).catch(() => null)
|
|
12
|
+
]);
|
|
13
|
+
if (realRoot === null || realTarget === null)
|
|
14
|
+
return null;
|
|
15
|
+
return isWithinDir(realRoot, realTarget) ? realTarget : null;
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
// src/tools/json-schema.ts
|
|
19
|
+
import { z } from "zod";
|
|
20
|
+
function toJsonSchema(schema, io, unrepresentable = "throw", target = "draft-2020-12") {
|
|
21
|
+
return z.toJSONSchema(schema, {
|
|
22
|
+
io,
|
|
23
|
+
target,
|
|
24
|
+
unrepresentable,
|
|
25
|
+
cycles: "ref"
|
|
26
|
+
});
|
|
27
|
+
}
|
|
28
|
+
function isObjectNode(value) {
|
|
29
|
+
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
30
|
+
}
|
|
31
|
+
function jsonSchemaFields(jsonSchema) {
|
|
32
|
+
const properties = jsonSchema.properties;
|
|
33
|
+
if (!isObjectNode(properties)) {
|
|
34
|
+
const conjunctive = Array.isArray(jsonSchema.allOf);
|
|
35
|
+
const members = conjunctive ? jsonSchema.allOf : Array.isArray(jsonSchema.oneOf) ? jsonSchema.oneOf : Array.isArray(jsonSchema.anyOf) ? jsonSchema.anyOf : [];
|
|
36
|
+
const byName = new Map;
|
|
37
|
+
for (const member of Array.isArray(members) ? members : []) {
|
|
38
|
+
if (!isObjectNode(member))
|
|
39
|
+
continue;
|
|
40
|
+
for (const field of jsonSchemaFields(member)) {
|
|
41
|
+
const existing = byName.get(field.name);
|
|
42
|
+
const required2 = existing ? conjunctive ? existing.required || field.required : existing.required && field.required : field.required;
|
|
43
|
+
byName.set(field.name, existing ? { ...field, required: required2 } : field);
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
return [...byName.values()];
|
|
47
|
+
}
|
|
48
|
+
const required = new Set(Array.isArray(jsonSchema.required) ? jsonSchema.required.filter((k) => typeof k === "string") : []);
|
|
49
|
+
const fields = [];
|
|
50
|
+
for (const [name, raw] of Object.entries(properties)) {
|
|
51
|
+
const schema = isObjectNode(raw) ? raw : {};
|
|
52
|
+
const description = typeof schema.description === "string" ? schema.description : undefined;
|
|
53
|
+
fields.push({
|
|
54
|
+
name,
|
|
55
|
+
schema,
|
|
56
|
+
required: required.has(name),
|
|
57
|
+
...description && { description }
|
|
58
|
+
});
|
|
59
|
+
}
|
|
60
|
+
return fields;
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
export { isWithinDir, realPathWithinDir, toJsonSchema, jsonSchemaFields };
|
package/dist/index.d.ts
CHANGED
|
@@ -4,6 +4,7 @@ export type { RealtimeClient, RealtimeClientOptions, SocketEventMap, SocketIOCli
|
|
|
4
4
|
export { createRealtimeClient, createSocketIOClient } from './browser/socket-io';
|
|
5
5
|
export { type ParseSSEOptions, parseSSE } from './browser/stream';
|
|
6
6
|
export * from './contract';
|
|
7
|
+
export type { StitchLogger } from './logger';
|
|
7
8
|
export { childSpan, createTraceContext, formatTraceparent, parseTraceparent, type TraceContext, } from './observability/trace';
|
|
8
9
|
export * from './realtime';
|
|
9
10
|
export { createRetainedTopics, type RetainedTopics } from './retained';
|
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,KAAK,YAAY,EACjB,KAAK,cAAc,EACnB,KAAK,mBAAmB,EACxB,KAAK,oBAAoB,EACzB,wBAAwB,EACxB,YAAY,EACZ,aAAa,EACb,mBAAmB,EACnB,uBAAuB,EACvB,gBAAgB,EAChB,iBAAiB,EACjB,KAAK,cAAc,EACnB,KAAK,aAAa,EAClB,KAAK,kBAAkB,EACvB,KAAK,oBAAoB,EACzB,KAAK,wBAAwB,EAC7B,KAAK,gBAAgB,GACtB,MAAM,kBAAkB,CAAC;AAC1B,OAAO,EACL,QAAQ,EACR,KAAK,QAAQ,EACb,KAAK,gBAAgB,EACrB,KAAK,oBAAoB,EACzB,gBAAgB,EAChB,KAAK,cAAc,EACnB,KAAK,UAAU,EACf,KAAK,gBAAgB,EACrB,KAAK,cAAc,EACnB,KAAK,mBAAmB,GACzB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