stitchkit 0.8.0 → 0.8.1
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/cli.js +3 -7
- package/dist/contract/index.js +0 -1
- package/dist/{index-za2p453b.js → index-031q8xmx.js} +1 -1
- package/dist/{index-5qe31283.js → index-9zrq8x5z.js} +9 -6
- package/dist/{index-tr7r1530.js → index-f39j6twc.js} +4 -8
- package/dist/index-jgpsd7dy.js +105 -0
- package/dist/{index-mwmpw6j1.js → index-p9m9c0jw.js} +2 -4
- package/dist/{index-5789sbt8.js → index-svvpy5bz.js} +8 -16
- package/dist/index-tm7dqzxc.js +20 -0
- package/dist/index.js +429 -13
- package/dist/node.js +4 -8
- package/dist/observability/index.js +4 -7
- package/dist/react.js +0 -2
- package/dist/server/index.js +89 -34
- package/dist/tools/mcp-app.d.ts.map +1 -1
- package/dist/tools.js +253 -21
- package/package.json +5 -3
- package/dist/index-37x76zdn.js +0 -4
- package/dist/index-48ffdxgk.js +0 -6
- package/dist/index-809wc1tt.js +0 -18
- package/dist/index-a1702zj4.js +0 -72
- package/dist/index-kdkvp26v.js +0 -380
- package/dist/index-kzfs85xp.js +0 -9
- package/dist/index-wjwj5bz2.js +0 -37
- package/dist/index-x3fcszf8.js +0 -8
package/dist/cli.js
CHANGED
|
@@ -4,14 +4,10 @@ import {
|
|
|
4
4
|
emitResult,
|
|
5
5
|
parseCliArgs,
|
|
6
6
|
pollUntilDone
|
|
7
|
-
} from "./index-
|
|
7
|
+
} from "./index-f39j6twc.js";
|
|
8
8
|
import"./index-0ed3bx43.js";
|
|
9
|
-
import"./index-
|
|
10
|
-
import"./index-
|
|
11
|
-
import"./index-eq29zkrx.js";
|
|
12
|
-
import"./index-kzfs85xp.js";
|
|
13
|
-
import"./index-809wc1tt.js";
|
|
14
|
-
import"./index-37x76zdn.js";
|
|
9
|
+
import"./index-jgpsd7dy.js";
|
|
10
|
+
import"./index-tm7dqzxc.js";
|
|
15
11
|
export {
|
|
16
12
|
pollUntilDone,
|
|
17
13
|
parseCliArgs,
|
package/dist/contract/index.js
CHANGED
|
@@ -1,14 +1,12 @@
|
|
|
1
1
|
import {
|
|
2
2
|
forbidden,
|
|
3
3
|
unauthorized
|
|
4
|
-
} from "./index-
|
|
4
|
+
} from "./index-jgpsd7dy.js";
|
|
5
5
|
import {
|
|
6
|
+
isRecord,
|
|
6
7
|
isUnsafeKey,
|
|
7
8
|
safeJsonParse
|
|
8
|
-
} from "./index-
|
|
9
|
-
import {
|
|
10
|
-
isRecord
|
|
11
|
-
} from "./index-809wc1tt.js";
|
|
9
|
+
} from "./index-tm7dqzxc.js";
|
|
12
10
|
|
|
13
11
|
// src/server/middleware/cookies.ts
|
|
14
12
|
function parseCookies(header) {
|
|
@@ -216,4 +214,9 @@ async function verifyPkce(verifier, challenge) {
|
|
|
216
214
|
return derived === challenge;
|
|
217
215
|
}
|
|
218
216
|
|
|
219
|
-
|
|
217
|
+
// src/internal/http-input.ts
|
|
218
|
+
function inputIsQuery(method) {
|
|
219
|
+
return method === "GET" || method === "DELETE";
|
|
220
|
+
}
|
|
221
|
+
|
|
222
|
+
export { parseCookies, serializeCookie, defineCookie, verifyJwt, signJwt, extractToken, createAuthHook, createBearerResolver, deriveCodeChallenge, verifyPkce, inputIsQuery };
|
|
@@ -2,21 +2,17 @@ import {
|
|
|
2
2
|
jsonSchemaFields,
|
|
3
3
|
toJsonSchema
|
|
4
4
|
} from "./index-0ed3bx43.js";
|
|
5
|
-
import {
|
|
6
|
-
isWithinDir
|
|
7
|
-
} from "./index-x3fcszf8.js";
|
|
8
5
|
import {
|
|
9
6
|
formatZodError,
|
|
7
|
+
isWithinDir,
|
|
10
8
|
normalizeError,
|
|
11
9
|
validateHandlerOutput
|
|
12
|
-
} from "./index-
|
|
10
|
+
} from "./index-jgpsd7dy.js";
|
|
13
11
|
import {
|
|
12
|
+
isRecord,
|
|
14
13
|
isUnsafeKey,
|
|
15
14
|
safeJsonParse
|
|
16
|
-
} from "./index-
|
|
17
|
-
import {
|
|
18
|
-
isRecord
|
|
19
|
-
} from "./index-809wc1tt.js";
|
|
15
|
+
} from "./index-tm7dqzxc.js";
|
|
20
16
|
|
|
21
17
|
// src/tools/coerce.ts
|
|
22
18
|
import { z } from "zod";
|
|
@@ -0,0 +1,105 @@
|
|
|
1
|
+
// src/contract/errors.ts
|
|
2
|
+
class AppError extends Error {
|
|
3
|
+
code;
|
|
4
|
+
status;
|
|
5
|
+
details;
|
|
6
|
+
hint;
|
|
7
|
+
constructor(code, message, status = 500, details, hint) {
|
|
8
|
+
super(message ?? code);
|
|
9
|
+
this.code = code;
|
|
10
|
+
this.status = status;
|
|
11
|
+
this.details = details;
|
|
12
|
+
this.hint = hint;
|
|
13
|
+
this.name = "AppError";
|
|
14
|
+
}
|
|
15
|
+
static is(err) {
|
|
16
|
+
return err instanceof AppError;
|
|
17
|
+
}
|
|
18
|
+
toJSON() {
|
|
19
|
+
return {
|
|
20
|
+
error: {
|
|
21
|
+
code: this.code,
|
|
22
|
+
message: this.message,
|
|
23
|
+
...this.details && { details: this.details },
|
|
24
|
+
...this.hint && { hint: this.hint }
|
|
25
|
+
}
|
|
26
|
+
};
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
function notFound(message = "Not found") {
|
|
30
|
+
throw new AppError("NOT_FOUND", message, 404);
|
|
31
|
+
}
|
|
32
|
+
function badRequest(message, details) {
|
|
33
|
+
throw new AppError("BAD_REQUEST", message, 400, details);
|
|
34
|
+
}
|
|
35
|
+
function unauthorized(message = "Unauthorized") {
|
|
36
|
+
throw new AppError("UNAUTHORIZED", message, 401);
|
|
37
|
+
}
|
|
38
|
+
function forbidden(message = "Forbidden") {
|
|
39
|
+
throw new AppError("FORBIDDEN", message, 403);
|
|
40
|
+
}
|
|
41
|
+
function conflict(message = "Conflict", details) {
|
|
42
|
+
throw new AppError("CONFLICT", message, 409, details);
|
|
43
|
+
}
|
|
44
|
+
function rateLimited(message = "Too many requests") {
|
|
45
|
+
throw new AppError("RATE_LIMITED", message, 429);
|
|
46
|
+
}
|
|
47
|
+
var STITCH_ERROR_STATUS = {
|
|
48
|
+
BAD_REQUEST: 400,
|
|
49
|
+
UNAUTHORIZED: 401,
|
|
50
|
+
FORBIDDEN: 403,
|
|
51
|
+
NOT_FOUND: 404,
|
|
52
|
+
METHOD_NOT_ALLOWED: 405,
|
|
53
|
+
CONFLICT: 409,
|
|
54
|
+
RATE_LIMITED: 429,
|
|
55
|
+
VALIDATION_ERROR: 400,
|
|
56
|
+
INTERNAL_SERVER_ERROR: 500
|
|
57
|
+
};
|
|
58
|
+
function isStitchErrorCode(code) {
|
|
59
|
+
return code in STITCH_ERROR_STATUS;
|
|
60
|
+
}
|
|
61
|
+
function appError(code, message, details) {
|
|
62
|
+
throw new AppError(code, message, isStitchErrorCode(code) ? STITCH_ERROR_STATUS[code] : 500, details);
|
|
63
|
+
}
|
|
64
|
+
// src/contract/pagination.ts
|
|
65
|
+
import { z } from "zod";
|
|
66
|
+
// src/internal/errors.ts
|
|
67
|
+
import { z as z2 } from "zod";
|
|
68
|
+
function formatZodError(error) {
|
|
69
|
+
const issues = error.issues.slice(0, 5);
|
|
70
|
+
const lines = issues.map((issue) => {
|
|
71
|
+
const path = issue.path.length > 0 ? issue.path.join(".") : "(root)";
|
|
72
|
+
return `${path}: ${issue.message}`;
|
|
73
|
+
});
|
|
74
|
+
const suffix = error.issues.length > 5 ? `
|
|
75
|
+
...and ${error.issues.length - 5} more issues` : "";
|
|
76
|
+
return lines.join(`
|
|
77
|
+
`) + suffix;
|
|
78
|
+
}
|
|
79
|
+
function normalizeError(err) {
|
|
80
|
+
if (AppError.is(err))
|
|
81
|
+
return err;
|
|
82
|
+
if (err instanceof z2.ZodError) {
|
|
83
|
+
return new AppError("VALIDATION_ERROR", formatZodError(err), 400);
|
|
84
|
+
}
|
|
85
|
+
console.error("[stitchkit] unhandled error:", err);
|
|
86
|
+
return new AppError("INTERNAL_SERVER_ERROR", "Internal server error", 500);
|
|
87
|
+
}
|
|
88
|
+
function validateHandlerOutput(schema, data) {
|
|
89
|
+
const parsed = schema.safeParse(data);
|
|
90
|
+
if (parsed.success)
|
|
91
|
+
return { ok: true, data: parsed.data };
|
|
92
|
+
return {
|
|
93
|
+
ok: false,
|
|
94
|
+
message: `Handler output does not match the contract: ${formatZodError(parsed.error)}`
|
|
95
|
+
};
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
// src/internal/within-dir.ts
|
|
99
|
+
import { sep } from "node:path";
|
|
100
|
+
function isWithinDir(root, target) {
|
|
101
|
+
const base = root.endsWith(sep) ? root.slice(0, -sep.length) : root;
|
|
102
|
+
return target === root || target === base || target.startsWith(base + sep);
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
export { AppError, notFound, badRequest, unauthorized, forbidden, conflict, rateLimited, STITCH_ERROR_STATUS, isStitchErrorCode, appError, formatZodError, normalizeError, validateHandlerOutput, isWithinDir };
|
|
@@ -1,31 +1,23 @@
|
|
|
1
1
|
import {
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
2
|
+
AppError,
|
|
3
|
+
badRequest,
|
|
4
|
+
isWithinDir,
|
|
5
5
|
normalizeError,
|
|
6
6
|
validateHandlerOutput
|
|
7
|
-
} from "./index-
|
|
8
|
-
import {
|
|
9
|
-
AppError,
|
|
10
|
-
badRequest
|
|
11
|
-
} from "./index-eq29zkrx.js";
|
|
7
|
+
} from "./index-jgpsd7dy.js";
|
|
12
8
|
import {
|
|
13
9
|
extractIp,
|
|
14
10
|
getClientInfo,
|
|
15
11
|
parseQueryParams,
|
|
16
12
|
resolveSocketIp,
|
|
17
13
|
resolveTraceId
|
|
18
|
-
} from "./index-
|
|
14
|
+
} from "./index-p9m9c0jw.js";
|
|
19
15
|
import {
|
|
16
|
+
__require,
|
|
20
17
|
isUnsafeKey,
|
|
21
|
-
safeJsonParse
|
|
22
|
-
} from "./index-kzfs85xp.js";
|
|
23
|
-
import {
|
|
18
|
+
safeJsonParse,
|
|
24
19
|
typedEntries
|
|
25
|
-
} from "./index-
|
|
26
|
-
import {
|
|
27
|
-
__require
|
|
28
|
-
} from "./index-37x76zdn.js";
|
|
20
|
+
} from "./index-tm7dqzxc.js";
|
|
29
21
|
|
|
30
22
|
// src/server/multipart.ts
|
|
31
23
|
var DEFAULT_MAX_UPLOAD_BYTES = 25 * 1024 * 1024;
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { createRequire } from "node:module";
|
|
2
|
+
var __require = /* @__PURE__ */ createRequire(import.meta.url);
|
|
3
|
+
|
|
4
|
+
// src/internal/safe-json.ts
|
|
5
|
+
function isUnsafeKey(key) {
|
|
6
|
+
return key === "__proto__";
|
|
7
|
+
}
|
|
8
|
+
function safeJsonParse(text) {
|
|
9
|
+
return JSON.parse(text, (key, value) => isUnsafeKey(key) ? undefined : value);
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
// src/internal/typed.ts
|
|
13
|
+
function typedEntries(value) {
|
|
14
|
+
return Object.entries(value);
|
|
15
|
+
}
|
|
16
|
+
function isRecord(value) {
|
|
17
|
+
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
export { __require, isUnsafeKey, safeJsonParse, typedEntries, isRecord };
|