theokit 0.75.1 → 0.76.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/README.md +88 -1
- package/dist/{actions-virtual-module-MIQPBAZW.js → actions-virtual-module-52O6HJZT.js} +11 -9
- package/dist/actions-virtual-module-52O6HJZT.js.map +1 -0
- package/dist/{actions-virtual-module-QEI6QPK4.js → actions-virtual-module-HS4W7HQU.js} +6 -5
- package/dist/{actions-virtual-module-QEI6QPK4.js.map → actions-virtual-module-HS4W7HQU.js.map} +1 -1
- package/dist/adapters/agent-mount.js +9 -7
- package/dist/{agent-N4OV5MDY.js → agent-HCK5RHH7.js} +4 -3
- package/dist/{app-typed-client-CHSITA46.js → app-typed-client-BWITJLJA.js} +6 -5
- package/dist/{app-typed-client-CHSITA46.js.map → app-typed-client-BWITJLJA.js.map} +1 -1
- package/dist/{app-typed-client-XQJXF646.js → app-typed-client-CJCOALMM.js} +11 -9
- package/dist/app-typed-client-CJCOALMM.js.map +1 -0
- package/dist/{aws-lambda-K5Y6XS5V.js → aws-lambda-XT7ZDJ6B.js} +3 -3
- package/dist/{build-GNKTCEES.js → build-Y3CWTWP6.js} +24 -92
- package/dist/build-Y3CWTWP6.js.map +1 -0
- package/dist/{bun-VPXMWFBA.js → bun-PJLDELDT.js} +5 -5
- package/dist/{chunk-J2KYVTPD.js → chunk-2SGNODVJ.js} +30 -16
- package/dist/chunk-2SGNODVJ.js.map +1 -0
- package/dist/chunk-2SQ7YAU3.js +85 -0
- package/dist/chunk-2SQ7YAU3.js.map +1 -0
- package/dist/{chunk-SYIQV4UH.js → chunk-36ZACTF3.js} +5 -5
- package/dist/{chunk-RY6D4EXL.js → chunk-3GM4GACM.js} +25 -4
- package/dist/{chunk-RY6D4EXL.js.map → chunk-3GM4GACM.js.map} +1 -1
- package/dist/{chunk-EW5IG7GA.js → chunk-42TYMRBG.js} +1 -1
- package/dist/{chunk-EW5IG7GA.js.map → chunk-42TYMRBG.js.map} +1 -1
- package/dist/{chunk-BINRCILF.js → chunk-4JRXZTVQ.js} +4 -13
- package/dist/chunk-4JRXZTVQ.js.map +1 -0
- package/dist/{chunk-R4AMIBZL.js → chunk-4XZOUS5G.js} +8 -8
- package/dist/chunk-4XZOUS5G.js.map +1 -0
- package/dist/{chunk-ICXXHV4V.js → chunk-54BIQFP4.js} +4 -13
- package/dist/chunk-54BIQFP4.js.map +1 -0
- package/dist/{chunk-VPK7ABMB.js → chunk-7MCEJVGV.js} +3 -3
- package/dist/{chunk-D7STTNQN.js → chunk-BXQCJJPT.js} +3 -3
- package/dist/{chunk-NX3P5MLH.js → chunk-C2BRSL4W.js} +50 -6
- package/dist/chunk-C2BRSL4W.js.map +1 -0
- package/dist/{chunk-E5QTCOKC.js → chunk-FEK25JUL.js} +88 -24
- package/dist/chunk-FEK25JUL.js.map +1 -0
- package/dist/{chunk-NLHAYGQQ.js → chunk-G3DDIEYE.js} +4 -2
- package/dist/chunk-G3DDIEYE.js.map +1 -0
- package/dist/chunk-IXXZBZF7.js +70 -0
- package/dist/chunk-IXXZBZF7.js.map +1 -0
- package/dist/{chunk-PVNMLZ5G.js → chunk-JO462JZM.js} +2 -2
- package/dist/chunk-LXV5IEBB.js +76 -0
- package/dist/chunk-LXV5IEBB.js.map +1 -0
- package/dist/{chunk-D2R5SJEL.js → chunk-MAJZ2L3A.js} +2 -2
- package/dist/{chunk-D2R5SJEL.js.map → chunk-MAJZ2L3A.js.map} +1 -1
- package/dist/chunk-NF7LXSXZ.js +19 -0
- package/dist/chunk-NF7LXSXZ.js.map +1 -0
- package/dist/chunk-OED37LE5.js +469 -0
- package/dist/chunk-OED37LE5.js.map +1 -0
- package/dist/{chunk-CLSYYO5F.js → chunk-OIYSUQM7.js} +2 -2
- package/dist/{chunk-2Z7TANA4.js → chunk-PVCXREGE.js} +6 -6
- package/dist/{chunk-EVKNHQWG.js → chunk-QBK6YYZA.js} +48 -5
- package/dist/chunk-QBK6YYZA.js.map +1 -0
- package/dist/{chunk-4X43VTST.js → chunk-TODO6J42.js} +1 -1
- package/dist/chunk-TODO6J42.js.map +1 -0
- package/dist/{chunk-ZDCCILMP.js → chunk-TQTEKNOL.js} +2 -69
- package/dist/chunk-TQTEKNOL.js.map +1 -0
- package/dist/{chunk-3MKRDJQ2.js → chunk-UQQQ3V43.js} +278 -75
- package/dist/chunk-UQQQ3V43.js.map +1 -0
- package/dist/{chunk-MX63AWEK.js → chunk-VXDTQO3S.js} +22 -6
- package/dist/{chunk-MX63AWEK.js.map → chunk-VXDTQO3S.js.map} +1 -1
- package/dist/{chunk-OZB2TKGJ.js → chunk-W2I6L4IJ.js} +2 -2
- package/dist/{chunk-UWV3B3RY.js → chunk-XDLFOATW.js} +5 -5
- package/dist/{chunk-RQKMY3JW.js → chunk-XI4FALFZ.js} +3 -3
- package/dist/chunk-XI4FALFZ.js.map +1 -0
- package/dist/{chunk-2FHNJ7LI.js → chunk-Z76QQR7I.js} +2 -2
- package/dist/chunk-ZICY2CD7.js +16 -0
- package/dist/chunk-ZICY2CD7.js.map +1 -0
- package/dist/chunk-ZN5H7CUR.js +24 -0
- package/dist/chunk-ZN5H7CUR.js.map +1 -0
- package/dist/{chunk-I5PDEWZZ.js → chunk-ZQJORKBM.js} +9 -3
- package/dist/chunk-ZQJORKBM.js.map +1 -0
- package/dist/cli/index.js +21 -15
- package/dist/cli/index.js.map +1 -1
- package/dist/{cloudflare-7EZQE4UV.js → cloudflare-F7KLBOU4.js} +6 -6
- package/dist/{config-support-HUZ4DXR7.js → config-support-2TER2BYD.js} +28 -21
- package/dist/config-support-2TER2BYD.js.map +1 -0
- package/dist/cron-lock-CfAvLApv.d.ts +36 -0
- package/dist/db-ZWDKD57T.js +86 -0
- package/dist/db-ZWDKD57T.js.map +1 -0
- package/dist/{deno-deploy-M5V3PYWU.js → deno-deploy-LJ5JQQVR.js} +5 -5
- package/dist/{dev-7PMNIIOF.js → dev-R2ZYHZV4.js} +60 -11
- package/dist/dev-R2ZYHZV4.js.map +1 -0
- package/dist/{engine-singleton-X4R7AZBJ.js → engine-singleton-BQ5QOMTC.js} +15 -9
- package/dist/{engine-singleton-X4R7AZBJ.js.map → engine-singleton-BQ5QOMTC.js.map} +1 -1
- package/dist/{generate-RW3NO3NR.js → generate-VXBSMUMW.js} +291 -85
- package/dist/generate-VXBSMUMW.js.map +1 -0
- package/dist/{index-CmkWlIDO.d.ts → index-DfsJ3Qhk.d.ts} +1 -1
- package/dist/index.d.ts +10 -1
- package/dist/index.js +12 -10
- package/dist/index.js.map +1 -1
- package/dist/{info-6NAUW5XY.js → info-IPMW56PI.js} +4 -4
- package/dist/{internal-api-R7TTYMCY.js → internal-api-6RAOYIET.js} +6 -5
- package/dist/{internal-api-A5HA7TYF.js → internal-api-YGFPLQ4E.js} +14 -11
- package/dist/job-backend-WvUs5rO1.d.ts +119 -0
- package/dist/{load-config-CLFWJOXN.js → load-config-USRR4GXP.js} +4 -4
- package/dist/{mcp-3NRZAQKY.js → mcp-FBXEX45H.js} +5 -4
- package/dist/{mcp-3NRZAQKY.js.map → mcp-FBXEX45H.js.map} +1 -1
- package/dist/{netlify-NI4HYDKN.js → netlify-ZPQNREFH.js} +2 -2
- package/dist/{node-LORYECWI.js → node-3EV3CVWB.js} +2 -2
- package/dist/{observability-bootstrap-DOWRMADT.js → observability-bootstrap-DMJ7R6WA.js} +3 -3
- package/dist/{openapi-ZHKJB3XL.js → openapi-CA3E3LZH.js} +4 -4
- package/dist/{preview-SNS7VJWH.js → preview-DLIVPM7A.js} +3 -3
- package/dist/registry-3D2KR7UE.js +34 -0
- package/dist/{routes-SMNSI2ZX.js → routes-BJ7GGRCV.js} +4 -4
- package/dist/{schema-DJH3IOVR.js → schema-FBM2UH72.js} +3 -3
- package/dist/{schemas-2R2J64ZH.js → schemas-BUR6PWSA.js} +2 -2
- package/dist/server/agent/index.d.ts +1 -1
- package/dist/server/agent/index.js +2 -1
- package/dist/server/cost/index.d.ts +2 -2
- package/dist/server/cost/index.js +1 -1
- package/dist/server/cost/sqlite/index.d.ts +2 -2
- package/dist/server/cost/sqlite/index.js +1 -1
- package/dist/server/cron/index.d.ts +20 -7
- package/dist/server/cron/index.js +8 -2
- package/dist/server/http/index.d.ts +2 -2
- package/dist/server/http/index.js +9 -7
- package/dist/server/index.d.ts +19 -10
- package/dist/server/index.js +103 -41
- package/dist/server/index.js.map +1 -1
- package/dist/server/jobs/index.d.ts +85 -44
- package/dist/server/jobs/index.js +9 -2
- package/dist/server/observability/index.js +9 -8
- package/dist/server/storage/index.d.ts +6 -2
- package/dist/server/storage/index.js +5 -1
- package/dist/server/webhook/index.d.ts +4 -5
- package/dist/server/webhook/index.js +1 -1
- package/dist/{server-boundary-ZT6HN7ON.js → server-boundary-EKIGYL7B.js} +6 -5
- package/dist/{server-boundary-ZT6HN7ON.js.map → server-boundary-EKIGYL7B.js.map} +1 -1
- package/dist/{server-boundary-HYLYGFZY.js → server-boundary-IDWIB24L.js} +11 -9
- package/dist/server-boundary-IDWIB24L.js.map +1 -0
- package/dist/{start-L5TGWGLU.js → start-LNT5UVSY.js} +118 -185
- package/dist/start-LNT5UVSY.js.map +1 -0
- package/dist/{static-O2RZ5NLR.js → static-VNN4HYRN.js} +2 -2
- package/dist/{storage-manager-3O5PDO6O.js → storage-manager-3IUIEG2P.js} +49 -5
- package/dist/storage-manager-3IUIEG2P.js.map +1 -0
- package/dist/{storage-manager-BtG38jYl.d.ts → storage-manager-Clu2RBpH.d.ts} +15 -3
- package/dist/{storage-types-CFGPFIdB.d.ts → storage-types-ndO0ZZqH.d.ts} +2 -2
- package/dist/{theo-cloud-B4R7GCWK.js → theo-cloud-243SPOIA.js} +2 -2
- package/dist/{vercel-INHLOCSZ.js → vercel-EXKSZ2OQ.js} +5 -5
- package/dist/vite-plugin/index.js +12 -10
- package/dist/{vite-plugin-UXEXT7GX.js → vite-plugin-LE42ZIGV.js} +10 -9
- package/dist/{whatsapp-D_Fnl1LX.d.ts → whatsapp-4W2eK2ij.d.ts} +1 -1
- package/package.json +1 -1
- package/dist/actions-virtual-module-MIQPBAZW.js.map +0 -1
- package/dist/app-typed-client-XQJXF646.js.map +0 -1
- package/dist/build-GNKTCEES.js.map +0 -1
- package/dist/chunk-3MKRDJQ2.js.map +0 -1
- package/dist/chunk-4X43VTST.js.map +0 -1
- package/dist/chunk-BINRCILF.js.map +0 -1
- package/dist/chunk-E5QTCOKC.js.map +0 -1
- package/dist/chunk-EVKNHQWG.js.map +0 -1
- package/dist/chunk-I5PDEWZZ.js.map +0 -1
- package/dist/chunk-ICXXHV4V.js.map +0 -1
- package/dist/chunk-IDEZ7FU2.js +0 -18
- package/dist/chunk-IDEZ7FU2.js.map +0 -1
- package/dist/chunk-J2KYVTPD.js.map +0 -1
- package/dist/chunk-NLHAYGQQ.js.map +0 -1
- package/dist/chunk-NX3P5MLH.js.map +0 -1
- package/dist/chunk-R4AMIBZL.js.map +0 -1
- package/dist/chunk-RQKMY3JW.js.map +0 -1
- package/dist/chunk-YCF3N4JS.js +0 -26
- package/dist/chunk-YCF3N4JS.js.map +0 -1
- package/dist/chunk-ZDCCILMP.js.map +0 -1
- package/dist/config-support-HUZ4DXR7.js.map +0 -1
- package/dist/db-IVVCQE5Z.js +0 -76
- package/dist/db-IVVCQE5Z.js.map +0 -1
- package/dist/dev-7PMNIIOF.js.map +0 -1
- package/dist/generate-RW3NO3NR.js.map +0 -1
- package/dist/job-backend-CgC8Xf33.d.ts +0 -68
- package/dist/registry-3SVWZVIJ.js +0 -34
- package/dist/server-boundary-HYLYGFZY.js.map +0 -1
- package/dist/start-L5TGWGLU.js.map +0 -1
- package/dist/storage-manager-3O5PDO6O.js.map +0 -1
- /package/dist/{agent-N4OV5MDY.js.map → agent-HCK5RHH7.js.map} +0 -0
- /package/dist/{aws-lambda-K5Y6XS5V.js.map → aws-lambda-XT7ZDJ6B.js.map} +0 -0
- /package/dist/{bun-VPXMWFBA.js.map → bun-PJLDELDT.js.map} +0 -0
- /package/dist/{chunk-SYIQV4UH.js.map → chunk-36ZACTF3.js.map} +0 -0
- /package/dist/{chunk-VPK7ABMB.js.map → chunk-7MCEJVGV.js.map} +0 -0
- /package/dist/{chunk-D7STTNQN.js.map → chunk-BXQCJJPT.js.map} +0 -0
- /package/dist/{chunk-PVNMLZ5G.js.map → chunk-JO462JZM.js.map} +0 -0
- /package/dist/{chunk-CLSYYO5F.js.map → chunk-OIYSUQM7.js.map} +0 -0
- /package/dist/{chunk-2Z7TANA4.js.map → chunk-PVCXREGE.js.map} +0 -0
- /package/dist/{chunk-OZB2TKGJ.js.map → chunk-W2I6L4IJ.js.map} +0 -0
- /package/dist/{chunk-UWV3B3RY.js.map → chunk-XDLFOATW.js.map} +0 -0
- /package/dist/{chunk-2FHNJ7LI.js.map → chunk-Z76QQR7I.js.map} +0 -0
- /package/dist/{cloudflare-7EZQE4UV.js.map → cloudflare-F7KLBOU4.js.map} +0 -0
- /package/dist/{deno-deploy-M5V3PYWU.js.map → deno-deploy-LJ5JQQVR.js.map} +0 -0
- /package/dist/{info-6NAUW5XY.js.map → info-IPMW56PI.js.map} +0 -0
- /package/dist/{internal-api-R7TTYMCY.js.map → internal-api-6RAOYIET.js.map} +0 -0
- /package/dist/{internal-api-A5HA7TYF.js.map → internal-api-YGFPLQ4E.js.map} +0 -0
- /package/dist/{load-config-CLFWJOXN.js.map → load-config-USRR4GXP.js.map} +0 -0
- /package/dist/{netlify-NI4HYDKN.js.map → netlify-ZPQNREFH.js.map} +0 -0
- /package/dist/{node-LORYECWI.js.map → node-3EV3CVWB.js.map} +0 -0
- /package/dist/{observability-bootstrap-DOWRMADT.js.map → observability-bootstrap-DMJ7R6WA.js.map} +0 -0
- /package/dist/{openapi-ZHKJB3XL.js.map → openapi-CA3E3LZH.js.map} +0 -0
- /package/dist/{preview-SNS7VJWH.js.map → preview-DLIVPM7A.js.map} +0 -0
- /package/dist/{registry-3SVWZVIJ.js.map → registry-3D2KR7UE.js.map} +0 -0
- /package/dist/{routes-SMNSI2ZX.js.map → routes-BJ7GGRCV.js.map} +0 -0
- /package/dist/{schema-DJH3IOVR.js.map → schema-FBM2UH72.js.map} +0 -0
- /package/dist/{schemas-2R2J64ZH.js.map → schemas-BUR6PWSA.js.map} +0 -0
- /package/dist/{static-O2RZ5NLR.js.map → static-VNN4HYRN.js.map} +0 -0
- /package/dist/{theo-cloud-B4R7GCWK.js.map → theo-cloud-243SPOIA.js.map} +0 -0
- /package/dist/{vercel-INHLOCSZ.js.map → vercel-EXKSZ2OQ.js.map} +0 -0
- /package/dist/{vite-plugin-UXEXT7GX.js.map → vite-plugin-LE42ZIGV.js.map} +0 -0
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
// src/server/http/trace-context.ts
|
|
2
|
+
var TRACE_HEADER = "x-trace-id";
|
|
3
|
+
var TRACE_PARENT_HEADER = "traceparent";
|
|
4
|
+
var REQUEST_ID_HEADER = "x-request-id";
|
|
5
|
+
var TRACEPARENT_RE = /^00-([0-9a-f]{32})-([0-9a-f]{16})-[0-9a-f]{2}$/;
|
|
6
|
+
function parseTraceparentContext(value) {
|
|
7
|
+
if (!value) return null;
|
|
8
|
+
const m = TRACEPARENT_RE.exec(value);
|
|
9
|
+
if (!m) return null;
|
|
10
|
+
const traceId = m[1];
|
|
11
|
+
if (/^0+$/.test(traceId)) return null;
|
|
12
|
+
const parentSpanId = m[2];
|
|
13
|
+
return /^0+$/.test(parentSpanId) ? { traceId } : { traceId, parentSpanId };
|
|
14
|
+
}
|
|
15
|
+
function parseTraceparent(value) {
|
|
16
|
+
return parseTraceparentContext(value)?.traceId ?? null;
|
|
17
|
+
}
|
|
18
|
+
var REQUEST_ID_RE = /^[A-Za-z0-9_.:-]{1,128}$/;
|
|
19
|
+
function isTrustedRequestId(value) {
|
|
20
|
+
return REQUEST_ID_RE.test(value);
|
|
21
|
+
}
|
|
22
|
+
function pickHeader(value, isTrusted = () => true) {
|
|
23
|
+
if (Array.isArray(value)) {
|
|
24
|
+
for (const v of value) {
|
|
25
|
+
if (typeof v === "string" && v.length > 0 && isTrusted(v)) return v;
|
|
26
|
+
}
|
|
27
|
+
return null;
|
|
28
|
+
}
|
|
29
|
+
if (typeof value === "string" && value.length > 0 && isTrusted(value)) return value;
|
|
30
|
+
return null;
|
|
31
|
+
}
|
|
32
|
+
function resolveTraceIdFromHeaders(traceparent, requestId) {
|
|
33
|
+
if (traceparent !== null) {
|
|
34
|
+
const parsed = parseTraceparent(traceparent);
|
|
35
|
+
if (parsed !== null) return parsed;
|
|
36
|
+
}
|
|
37
|
+
if (requestId !== null) return requestId;
|
|
38
|
+
return globalThis.crypto.randomUUID();
|
|
39
|
+
}
|
|
40
|
+
function extractTraceId(req) {
|
|
41
|
+
return resolveTraceIdFromHeaders(
|
|
42
|
+
pickHeader(req.headers[TRACE_PARENT_HEADER]),
|
|
43
|
+
pickHeader(req.headers[REQUEST_ID_HEADER], isTrustedRequestId)
|
|
44
|
+
);
|
|
45
|
+
}
|
|
46
|
+
function extractW3CTraceContext(request) {
|
|
47
|
+
const traceparent = request.headers.get(TRACE_PARENT_HEADER);
|
|
48
|
+
if (traceparent === null) return void 0;
|
|
49
|
+
return parseTraceparentContext(traceparent) ?? void 0;
|
|
50
|
+
}
|
|
51
|
+
function extractTraceIdFromRequest(request) {
|
|
52
|
+
const requestId = request.headers.get(REQUEST_ID_HEADER);
|
|
53
|
+
return resolveTraceIdFromHeaders(
|
|
54
|
+
request.headers.get(TRACE_PARENT_HEADER),
|
|
55
|
+
// Same policy on both resolvers. A validation living on one side only is the
|
|
56
|
+
// gap an attacker picks the other transport to reach.
|
|
57
|
+
requestId !== null && isTrustedRequestId(requestId) ? requestId : null
|
|
58
|
+
);
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
export {
|
|
62
|
+
TRACE_HEADER,
|
|
63
|
+
TRACE_PARENT_HEADER,
|
|
64
|
+
parseTraceparentContext,
|
|
65
|
+
parseTraceparent,
|
|
66
|
+
extractTraceId,
|
|
67
|
+
extractW3CTraceContext,
|
|
68
|
+
extractTraceIdFromRequest
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AA,IACL,WAAW,IAAI,QAAQ,mBAAmB,CAAC;AAAA,IAC3C,WAAW,IAAI,QAAQ,iBAAiB,GAAG,kBAAkB;AAAA,EAC/D;AACF;AAmCO,SAAS,uBAAuB,SAA+C;AACpF,QAAM,cAAc,QAAQ,QAAQ,IAAI,mBAAmB;AAC3D,MAAI,gBAAgB,KAAM,QAAO;AACjC,SAAO,wBAAwB,WAAW,KAAK;AACjD;AAEO,SAAS,0BAA0B,SAA0B;AAClE,QAAM,YAAY,QAAQ,QAAQ,IAAI,iBAAiB;AACvD,SAAO;AAAA,IACL,QAAQ,QAAQ,IAAI,mBAAmB;AAAA;AAAA;AAAA,IAGvC,cAAc,QAAQ,mBAAmB,SAAS,IAAI,YAAY;AAAA,EACpE;AACF;","names":[]}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import {
|
|
2
2
|
extractW3CTraceContext
|
|
3
|
-
} from "./chunk-
|
|
3
|
+
} from "./chunk-IXXZBZF7.js";
|
|
4
4
|
import {
|
|
5
5
|
newSpanId,
|
|
6
6
|
newTraceId
|
|
@@ -404,4 +404,4 @@ export {
|
|
|
404
404
|
resolveAdapter,
|
|
405
405
|
createObservabilityPlugin
|
|
406
406
|
};
|
|
407
|
-
//# sourceMappingURL=chunk-
|
|
407
|
+
//# sourceMappingURL=chunk-JO462JZM.js.map
|
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
import {
|
|
2
|
+
keepPoolErrorsFromExitingTheProcess
|
|
3
|
+
} from "./chunk-ZN5H7CUR.js";
|
|
4
|
+
import {
|
|
5
|
+
createLogger
|
|
6
|
+
} from "./chunk-TQTEKNOL.js";
|
|
7
|
+
|
|
8
|
+
// src/server/cron/cron-lock.ts
|
|
9
|
+
var TABLE_NAME = /^[a-z_][a-z0-9_]*$/;
|
|
10
|
+
var cronLockLogger = createLogger({ context: { component: "theokit:cron" } });
|
|
11
|
+
function createPostgresCronLock(pool, options = {}) {
|
|
12
|
+
const table = options.tableName ?? "theokit_cron_runs";
|
|
13
|
+
if (!TABLE_NAME.test(table)) {
|
|
14
|
+
throw new Error(
|
|
15
|
+
`Invalid cron lock table name "${table}": use lowercase letters, digits and underscores.`
|
|
16
|
+
);
|
|
17
|
+
}
|
|
18
|
+
keepPoolErrorsFromExitingTheProcess(pool, cronLockLogger, { table });
|
|
19
|
+
const retentionDays = options.retentionDays ?? 7;
|
|
20
|
+
let ready;
|
|
21
|
+
const ensureTable = () => {
|
|
22
|
+
ready ??= pool.query(
|
|
23
|
+
`CREATE TABLE IF NOT EXISTS ${table} (
|
|
24
|
+
name TEXT NOT NULL,
|
|
25
|
+
scheduled_at TIMESTAMPTZ NOT NULL,
|
|
26
|
+
fired_at TIMESTAMPTZ NOT NULL DEFAULT NOW(),
|
|
27
|
+
PRIMARY KEY (name, scheduled_at)
|
|
28
|
+
)`
|
|
29
|
+
).catch((err) => {
|
|
30
|
+
const code = err.code;
|
|
31
|
+
if (code === "23505" || code === "42P07" || code === "42710") return;
|
|
32
|
+
ready = void 0;
|
|
33
|
+
throw err;
|
|
34
|
+
});
|
|
35
|
+
return ready;
|
|
36
|
+
};
|
|
37
|
+
return {
|
|
38
|
+
async acquire(name, scheduledAt) {
|
|
39
|
+
await ensureTable();
|
|
40
|
+
const inserted = await pool.query(
|
|
41
|
+
`INSERT INTO ${table} (name, scheduled_at) VALUES ($1, $2)
|
|
42
|
+
ON CONFLICT DO NOTHING RETURNING name`,
|
|
43
|
+
[name, scheduledAt.toISOString()]
|
|
44
|
+
);
|
|
45
|
+
const won = inserted.rows.length === 1;
|
|
46
|
+
if (won) {
|
|
47
|
+
await pool.query(
|
|
48
|
+
`DELETE FROM ${table}
|
|
49
|
+
WHERE name = $1 AND scheduled_at < $2::timestamptz - make_interval(days => $3)`,
|
|
50
|
+
[name, scheduledAt.toISOString(), retentionDays]
|
|
51
|
+
);
|
|
52
|
+
}
|
|
53
|
+
return won;
|
|
54
|
+
}
|
|
55
|
+
};
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
// src/server/_internal/atomic-write.ts
|
|
59
|
+
import { mkdirSync, renameSync, writeFileSync } from "node:fs";
|
|
60
|
+
import { dirname } from "node:path";
|
|
61
|
+
function writeAtomic(path, content) {
|
|
62
|
+
mkdirSync(dirname(path), { recursive: true });
|
|
63
|
+
const randBuf = new Uint8Array(4);
|
|
64
|
+
globalThis.crypto.getRandomValues(randBuf);
|
|
65
|
+
let suffix = "";
|
|
66
|
+
for (const b of randBuf) suffix += b.toString(16).padStart(2, "0");
|
|
67
|
+
const tmp = `${path}.tmp-${process.pid}-${suffix}`;
|
|
68
|
+
writeFileSync(tmp, content, "utf8");
|
|
69
|
+
renameSync(tmp, path);
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
export {
|
|
73
|
+
writeAtomic,
|
|
74
|
+
createPostgresCronLock
|
|
75
|
+
};
|
|
76
|
+
//# sourceMappingURL=chunk-LXV5IEBB.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/server/cron/cron-lock.ts","../src/server/_internal/atomic-write.ts"],"mappings":";;;;;;;;AAwBA,IAAM,aAAa;AACnB,IAAM,iBAAiB,aAAa,EAAE,SAAS,EAAE,WAAW,eAAe,EAAE,CAAC;AAevE,SAAS,uBACd,MACA,UAAmC,CAAC,GAC1B;AACV,QAAM,QAAQ,QAAQ,aAAa;AACnC,MAAI,CAAC,WAAW,KAAK,KAAK,GAAG;AAC3B,UAAM,IAAI;AAAA,MACR,iCAAiC,KAAK;AAAA,IACxC;AAAA,EACF;AACA,sCAAoC,MAAM,gBAAgB,EAAE,MAAM,CAAC;AACnE,QAAM,gBAAgB,QAAQ,iBAAiB;AAC/C,MAAI;AAEJ,QAAM,cAAc,MAAwB;AAC1C,cAAU,KACP;AAAA,MACC,8BAA8B,KAAK;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,IAMrC,EACC,MAAM,CAAC,QAAiB;AAIvB,YAAM,OAAQ,IAA2B;AACzC,UAAI,SAAS,WAAW,SAAS,WAAW,SAAS,QAAS;AAE9D,cAAQ;AACR,YAAM;AAAA,IACR,CAAC;AACH,WAAO;AAAA,EACT;AAEA,SAAO;AAAA,IACL,MAAM,QAAQ,MAAM,aAAa;AAC/B,YAAM,YAAY;AAClB,YAAM,WAAW,MAAM,KAAK;AAAA,QAC1B,eAAe,KAAK;AAAA;AAAA,QAEpB,CAAC,MAAM,YAAY,YAAY,CAAC;AAAA,MAClC;AACA,YAAM,MAAM,SAAS,KAAK,WAAW;AACrC,UAAI,KAAK;AAGP,cAAM,KAAK;AAAA,UACT,eAAe,KAAK;AAAA;AAAA,UAEpB,CAAC,MAAM,YAAY,YAAY,GAAG,aAAa;AAAA,QACjD;AAAA,MACF;AACA,aAAO;AAAA,IACT;AAAA,EACF;AACF;;;ACzFA,SAAS,WAAW,YAAY,qBAAqB;AACrD,SAAS,eAAe;AAkBjB,SAAS,YAAY,MAAc,SAAuB;AAC/D,YAAU,QAAQ,IAAI,GAAG,EAAE,WAAW,KAAK,CAAC;AAK5C,QAAM,UAAU,IAAI,WAAW,CAAC;AAChC,aAAW,OAAO,gBAAgB,OAAO;AACzC,MAAI,SAAS;AACb,aAAW,KAAK,QAAS,WAAU,EAAE,SAAS,EAAE,EAAE,SAAS,GAAG,GAAG;AACjE,QAAM,MAAM,GAAG,IAAI,QAAQ,QAAQ,GAAG,IAAI,MAAM;AAChD,gBAAc,KAAK,SAAS,MAAM;AAClC,aAAW,KAAK,IAAI;AACtB;","names":[]}
|
|
@@ -209,7 +209,7 @@ var storageSchema = z8.object({
|
|
|
209
209
|
servers: z8.record(z8.string(), serverConfigSchema).optional(),
|
|
210
210
|
databases: z8.record(z8.string(), postgresDatabaseConfigSchema).optional(),
|
|
211
211
|
redis: z8.record(z8.string(), redisServerConfigSchema).optional()
|
|
212
|
-
});
|
|
212
|
+
}).strict();
|
|
213
213
|
|
|
214
214
|
export {
|
|
215
215
|
rateLimitSchema,
|
|
@@ -222,4 +222,4 @@ export {
|
|
|
222
222
|
securitySchema,
|
|
223
223
|
storageSchema
|
|
224
224
|
};
|
|
225
|
-
//# sourceMappingURL=chunk-
|
|
225
|
+
//# sourceMappingURL=chunk-MAJZ2L3A.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/config/schemas/rate-limit.ts","../src/config/schemas/upload.ts","../src/config/schemas/logging.ts","../src/config/schemas/cache.ts","../src/config/schemas/observability.ts","../src/config/schemas/security.ts","../src/config/schemas/header-safe.ts","../src/config/schemas/storage.ts"],"sourcesContent":["import { z } from 'zod'\n\n/**\n * Base bucket config — legacy shape preserved for backwards compatibility.\n */\nconst baseRateLimitSchema = z.object({\n windowMs: z.number().min(1),\n max: z.number().int().min(1),\n})\n\n/**\n * B-257 — the durable counter a deployment brings, in the form a generated entry can construct.\n *\n * A reference, never an instance: the entry is generated SOURCE, so whatever is named here has to\n * survive being written into a file. `factory` is the field that cannot be escaped — it lands as a\n * bare identifier in `import { <factory> }` — and `adapters/deployed-rate-limit.ts` validates it\n * there rather than here, because the refusal must name the TARGET being built.\n *\n * The framework ships no store. `server/rate-limit/rate-limit-store.ts:5-7` names Redis and\n * Cloudflare KV as what a deployment opts into, and `docs/adr/0017` states why the framework picks\n * none for anybody.\n */\nconst rateLimitStoreSchema = z.object({\n /** The specifier the generated entry imports from, e.g. `@upstash/redis`. */\n module: z.string().min(1),\n /** The exported name it constructs. Must be a plain identifier — see the build-time refusal. */\n factory: z.string().min(1),\n /** Constructor options, written into the entry as a JSON literal. */\n options: z.record(z.string(), z.union([z.string(), z.number(), z.boolean()])).optional(),\n})\n\n/**\n * T2.2 — Per-route + per-user rate limit. The new shape adds `routes`\n * (path map), `keyBy`, and `cookieName`. The legacy flat shape is still\n * accepted via the union — see `createRouteRateLimiter` for normalization.\n */\nexport const rateLimitSchema = z.union([\n // B-257 — `store` is declared on BOTH branches. `z.object` STRIPS unknown keys, so a config\n // carrying a store matched the base branch, lost it silently, and the build then refused the\n // target with the pre-B-257 message while the operator had done exactly what the feature asks.\n // Measured before the fix: `theoConfigSchema.parse` returned `{windowMs, max}` from a config\n // whose store block was present.\n baseRateLimitSchema.extend({ store: rateLimitStoreSchema.optional() }),\n z.object({\n store: rateLimitStoreSchema.optional(),\n default: baseRateLimitSchema.optional(),\n routes: z.record(z.string(), baseRateLimitSchema).optional(),\n keyBy: z\n .union([\n z.enum(['ip', 'session', 'user']),\n z.function({ input: z.tuple([z.unknown()]), output: z.string() }),\n ])\n .optional(),\n cookieName: z.string().min(1).optional(),\n /**\n * How many reverse proxies sit in front of the app, for `keyBy: 'ip'`. `false` (default)\n * trusts none; `true` means one; a number names a longer chain.\n *\n * Required for correct limiting behind Caddy/nginx/a load balancer — without it every visitor\n * keys on the proxy address and shares a single bucket. Off by default because\n * `x-forwarded-for` is client-writable.\n */\n trustProxy: z.union([z.boolean(), z.number().int().min(0)]).optional(),\n }),\n])\n","import { z } from 'zod'\n\nexport const uploadSchema = z.object({\n maxFileSize: z\n .number()\n .min(1)\n .default(10 * 1024 * 1024), // 10MB\n maxFiles: z.number().int().min(1).default(10),\n maxFieldSize: z\n .number()\n .min(1)\n .default(1 * 1024 * 1024), // 1MB\n})\n","import { z } from 'zod'\n\nexport const loggingSchema = z.object({\n level: z.enum(['debug', 'info', 'warn', 'error', 'silent']).default('info'),\n})\n","import { z } from 'zod'\n\n// `.finite()` was removed from the 4 numeric schemas below (agent-builder#319): in zod 4 it is a\n// no-op — `z.number()` already rejects `Infinity`, `-Infinity` and `NaN` by default. Measured before\n// removing, against the installed zod 4.4.3, and not assumed from the deprecation message: all five\n// cases (`Infinity`, `-Infinity`, `NaN`, `1.5`, `0`) give the SAME verdict with and without it.\n\n/**\n * Cache subsystem config (caching-and-revalidation-plan).\n * Default `cache: undefined` keeps the framework backward-compatible\n * (no engine initialized → no cache primitives available).\n *\n * Setting `cache: {}` opts in with all defaults.\n */\nconst routeRuleSchema = z.object({\n maxAge: z.number().nonnegative().optional(),\n swr: z.number().nonnegative().optional(),\n tags: z.array(z.string()).optional(),\n})\n\nexport const cacheSchema = z.object({\n enabled: z.boolean().default(true),\n /** 'memory' uses InMemoryCacheAdapter; otherwise pass a custom adapter instance. */\n storage: z.union([z.literal('memory'), z.custom<unknown>()]).default('memory'),\n maxEntries: z.number().int().positive().default(1000),\n defaults: z\n .object({\n maxAge: z.number().nonnegative().default(1),\n swr: z.number().nonnegative().optional(),\n cacheErrors: z.boolean().default(false),\n })\n .default({ maxAge: 1, cacheErrors: false }),\n keyDerivation: z\n .object({\n excludeQuery: z.array(z.string()).optional(),\n sortQuery: z.boolean().default(true),\n lowercaseHost: z.boolean().default(true),\n })\n .default({ sortQuery: true, lowercaseHost: true }),\n routeRules: z.record(z.string(), routeRuleSchema).optional(),\n})\n","import { z } from 'zod'\n\n/**\n * Observability subsystem config.\n *\n * `adapter-registry.ts` has documented `theo.config.ts > observability.provider`\n * as the first source in its resolution chain since it was written, and the key\n * did not exist in the schema — so the chain's highest-priority entry was\n * unreachable and every consumer fell through to the environment\n * (usetheokit/theokit#353).\n *\n * Default `observability: undefined` keeps telemetry off, which is what an\n * application that never asked for it should get.\n */\nexport const observabilitySchema = z.object({\n /** Set `false` to opt out even when the environment would enable an exporter. */\n enabled: z.boolean().default(true),\n /**\n * An `ObservabilityAdapter` instance. Validated structurally rather than by\n * shape, for the same reason `storage` and `plugins` are: the config layer\n * cannot import the adapter contract without inverting the module graph, and\n * the adapter is a live object rather than data.\n */\n provider: z.custom<unknown>().optional(),\n})\n","import { z } from 'zod'\n\nimport { headerSafeString } from './header-safe.js'\n\n/**\n * Phase 5 — CSRF warn-first (EC-1).\n *\n * 0.2.0 default: `warn`. Existing apps keep working but get structured\n * warnings about every state-mutating request that does not carry the\n * `X-Theo-Action: 1` header. 0.3.0 will flip the default to `strict`.\n *\n * Set explicitly to `strict` to opt into the future default early,\n * or `off` to disable CSRF entirely (only valid when you have another\n * defense — bearer auth, no session cookies, etc).\n */\n\n/**\n * Phase 6 — Default security headers (D4 / EC-2).\n *\n * 0.2.0 defaults:\n * - CSP in `report-only` mode (EC-2: don't break existing apps)\n * - X-Frame-Options: DENY · X-Content-Type-Options: nosniff\n * - Referrer-Policy: strict-origin-when-cross-origin\n * - HSTS in production only (no TLS on localhost)\n *\n * Users override individual headers, swap CSP to `enforce`, or disable\n * CSP entirely (`csp: false` / `cspMode: 'off'`).\n */\nexport const securityHeadersSchema = z.object({\n csp: z.union([headerSafeString, z.literal(false)]).optional(),\n // T6.1 — default flipped from 'report-only' to 'enforce' for 0.3.0.\n // Users who want the old behaviour set `cspMode: 'report-only'`\n // explicitly.\n cspMode: z.enum(['enforce', 'report-only', 'off']).default('enforce'),\n hsts: z.union([headerSafeString, z.literal(false)]).optional(),\n frameOptions: z.enum(['DENY', 'SAMEORIGIN']).default('DENY'),\n contentTypeOptions: z.literal('nosniff').default('nosniff'),\n referrerPolicy: headerSafeString.default('strict-origin-when-cross-origin'),\n /**\n * T1.1 — Permissions-Policy directive string. EC-3-refined: rejects CR/LF.\n * Pass `false` to suppress the header.\n */\n permissionsPolicy: z.union([headerSafeString, z.literal(false)]).optional(),\n})\n\n/**\n * T5.1 — Disallowed-routes escalation pattern (Rails-inspired).\n *\n * `routes` accepts string (exact match — trailing slash matters) or\n * RegExp entries. Matched routes that would otherwise emit `csrf.warn`\n * dispatch through `disallowedBehavior` instead:\n * - `'warn'` : no-op vs the default warn-mode behavior\n * - `'raise'` : escalate to 403, even when global `csrf` mode is 'warn'\n *\n * Use to roll out strict mode per-route (e.g., flip /api/auth/* first)\n * without committing the entire surface to strict at once.\n */\nconst disallowedConfigSchema = z.object({\n routes: z.array(z.union([z.string(), z.instanceof(RegExp)])),\n behavior: z.enum(['warn', 'raise']).default('raise'),\n})\n\n/**\n * T1.2 — CORS configuration.\n *\n * `origins` accepts a single value (`'*'`, string, RegExp, callback) OR an\n * array of (string | RegExp). The spec-violating `origins: '*'` +\n * `credentials: true` combination is rejected at parse time (browsers\n * ignore wildcards when credentials are sent).\n *\n * EC-3 — `allowedHeaders` and `exposedHeaders` entries go through the\n * header-safe refinement (CR/LF rejected — CWE-113 mitigation).\n */\nexport const corsSchema = z\n .object({\n origins: z.union([\n z.literal('*'),\n headerSafeString,\n z.instanceof(RegExp),\n z.array(z.union([headerSafeString, z.instanceof(RegExp)])),\n z.function({ input: z.tuple([z.string()]), output: z.boolean() }),\n ]),\n methods: z\n .array(z.enum(['GET', 'POST', 'PUT', 'PATCH', 'DELETE', 'OPTIONS', 'HEAD']))\n .optional(),\n allowedHeaders: z.array(headerSafeString).optional(),\n exposedHeaders: z.array(headerSafeString).optional(),\n credentials: z.boolean().default(false),\n maxAge: z.number().int().min(0).max(86400).default(600),\n })\n .refine((c) => !(c.origins === '*' && c.credentials), {\n message: 'CORS spec forbids origins:\"*\" with credentials:true — browsers ignore the wildcard',\n })\n\nexport const securitySchema = z.object({\n // T6.1 — default flipped from 'warn' to 'strict' for 0.3.0. Apps that\n // grep their warn-mode logs from 0.2.x already know which endpoints\n // break; opt back into 'warn' globally OR use disallowedRoutes for\n // surgical migration.\n csrf: z.enum(['off', 'warn', 'strict']).default('strict'),\n headers: securityHeadersSchema.optional(),\n /** T5.1 — per-route escalation (Rails disallowed_warnings pattern). */\n disallowed: disallowedConfigSchema.optional(),\n /** T1.2 — Cross-Origin Resource Sharing. Single global config; runs first in pipeline. */\n cors: corsSchema.optional(),\n /**\n * Permit binding a public network interface while write routes still declare `policy('public')`.\n *\n * Absent means `false`, and that is the point: `theo start` refuses that combination rather\n * than serving it, because an unauthenticated POST reachable from a network is an open endpoint\n * whether or not anyone meant it to be. See `cli/commands/start/public-exposure-gate.ts` for what\n * is refused and — equally important — what is not.\n *\n * Setting it to `true` is a decision, not a switch: the routes stay open, the startup log goes on\n * naming every one of them, and this line in `theo.config.ts` is what an auditor finds when they\n * ask who agreed to it.\n *\n * `.optional()` rather than `.default(false)`: a Zod default lands in the OUTPUT type, so every\n * caller constructing a `SecurityConfig` literal would have to name a field they do not care\n * about. The reader supplies the fallback (`?? false`), which keeps absent and false identical\n * where it matters and keeps the type unchanged for everyone else.\n */\n allowUnauthenticatedWrites: z.boolean().optional(),\n})\n","import { z } from 'zod'\n\n/**\n * EC-3 — CWE-113 HTTP Response Splitting mitigation.\n *\n * Every string that becomes a header value must reject CR/LF. Apps that\n * derive header values from untrusted input (feature flags, tenant config,\n * URL params) would otherwise let attackers inject Set-Cookie / Location\n * headers via `\\r\\n`. Apply this refinement to every header-bound string\n * field: permissionsPolicy, csp, hsts, referrerPolicy, CORS allow/expose.\n */\nexport const headerSafeString = z\n .string()\n .refine((s) => !/[\\r\\n]/.test(s), { message: 'Header value must not contain CR/LF' })\n","import { z } from 'zod'\n\n/**\n * StorageManager schemas (T1.1 / ADR-0007 D4).\n *\n * `theo.config.ts > storage` declares Postgres servers (credentials), the\n * databases on each server (TheoCloud / managed PG / self-host), and Redis\n * servers. The runtime `StorageManager` consumes this block; adapters\n * (PostgresJobBackend, PostgresConversationStorage, etc.) request pools by\n * database name and never see raw credentials at the call site.\n *\n * EC-1 (DOCUMENT in concept doc T4.1): Zod default strip-unknown mode\n * silently drops typo keys (`databasees` instead of `databases`). The\n * concept doc warns users to use exact names; runtime errors are still\n * actionable (`Database \"X\" not configured`).\n *\n * EC-2 (DEFERRED to use-time): `databases.X.server` references a key in\n * `servers`. Cross-field validation is intentionally NOT enforced at parse\n * time — `StorageManager.usePostgres()` throws an actionable error on the\n * first call with the dangling reference, matching Rails / Nitro behavior.\n */\nconst tlsConfigSchema = z.object({\n rejectUnauthorized: z.boolean().optional(),\n caCert: z.string().optional(),\n clientCert: z.string().optional(),\n clientKey: z.string().optional(),\n})\n\nconst serverConfigSchema = z.object({\n host: z.string().min(1),\n port: z.number().int().positive().max(65535).optional(),\n user: z.string().min(1),\n /** Password may be the empty string (some providers permit it). */\n password: z.string(),\n tls: tlsConfigSchema.optional(),\n})\n\nconst postgresPoolConfigSchema = z.object({\n min: z.number().int().nonnegative().optional(),\n max: z.number().int().positive().optional(),\n connectionTimeoutMillis: z.number().int().positive().optional(),\n idleTimeoutMillis: z.number().int().nonnegative().optional(),\n})\n\nconst postgresDatabaseConfigSchema = z.object({\n /** References a key in `storage.servers`. Resolved at `usePostgres()` call time. */\n server: z.string().min(1),\n database: z.string().min(1),\n pool: postgresPoolConfigSchema.optional(),\n})\n\nconst redisServerConfigSchema = serverConfigSchema.extend({\n db: z.number().int().nonnegative().optional(),\n maxRetriesPerRequest: z.number().int().nonnegative().optional(),\n})\n\nexport const storageSchema = z.object({\n servers: z.record(z.string(), serverConfigSchema).optional(),\n databases: z.record(z.string(), postgresDatabaseConfigSchema).optional(),\n redis: z.record(z.string(), redisServerConfigSchema).optional(),\n})\n\nexport type StorageConfig = z.infer<typeof storageSchema>\n"],"mappings":";;;;AAAA,SAAS,SAAS;AAKlB,IAAM,sBAAsB,EAAE,OAAO;AAAA,EACnC,UAAU,EAAE,OAAO,EAAE,IAAI,CAAC;AAAA,EAC1B,KAAK,EAAE,OAAO,EAAE,IAAI,EAAE,IAAI,CAAC;AAC7B,CAAC;AAcD,IAAM,uBAAuB,EAAE,OAAO;AAAA;AAAA,EAEpC,QAAQ,EAAE,OAAO,EAAE,IAAI,CAAC;AAAA;AAAA,EAExB,SAAS,EAAE,OAAO,EAAE,IAAI,CAAC;AAAA;AAAA,EAEzB,SAAS,EAAE,OAAO,EAAE,OAAO,GAAG,EAAE,MAAM,CAAC,EAAE,OAAO,GAAG,EAAE,OAAO,GAAG,EAAE,QAAQ,CAAC,CAAC,CAAC,EAAE,SAAS;AACzF,CAAC;AAOM,IAAM,kBAAkB,EAAE,MAAM;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAMrC,oBAAoB,OAAO,EAAE,OAAO,qBAAqB,SAAS,EAAE,CAAC;AAAA,EACrE,EAAE,OAAO;AAAA,IACP,OAAO,qBAAqB,SAAS;AAAA,IACrC,SAAS,oBAAoB,SAAS;AAAA,IACtC,QAAQ,EAAE,OAAO,EAAE,OAAO,GAAG,mBAAmB,EAAE,SAAS;AAAA,IAC3D,OAAO,EACJ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/rate-limit.ts","../src/config/schemas/upload.ts","../src/config/schemas/logging.ts","../src/config/schemas/cache.ts","../src/config/schemas/observability.ts","../src/config/schemas/security.ts","../src/config/schemas/header-safe.ts","../src/config/schemas/storage.ts"],"sourcesContent":["import { z } from 'zod'\n\n/**\n * Base bucket config — legacy shape preserved for backwards compatibility.\n */\nconst baseRateLimitSchema = z.object({\n windowMs: z.number().min(1),\n max: z.number().int().min(1),\n})\n\n/**\n * B-257 — the durable counter a deployment brings, in the form a generated entry can construct.\n *\n * A reference, never an instance: the entry is generated SOURCE, so whatever is named here has to\n * survive being written into a file. `factory` is the field that cannot be escaped — it lands as a\n * bare identifier in `import { <factory> }` — and `adapters/deployed-rate-limit.ts` validates it\n * there rather than here, because the refusal must name the TARGET being built.\n *\n * The framework ships no store. `server/rate-limit/rate-limit-store.ts:5-7` names Redis and\n * Cloudflare KV as what a deployment opts into, and `docs/adr/0017` states why the framework picks\n * none for anybody.\n */\nconst rateLimitStoreSchema = z.object({\n /** The specifier the generated entry imports from, e.g. `@upstash/redis`. */\n module: z.string().min(1),\n /** The exported name it constructs. Must be a plain identifier — see the build-time refusal. */\n factory: z.string().min(1),\n /** Constructor options, written into the entry as a JSON literal. */\n options: z.record(z.string(), z.union([z.string(), z.number(), z.boolean()])).optional(),\n})\n\n/**\n * T2.2 — Per-route + per-user rate limit. The new shape adds `routes`\n * (path map), `keyBy`, and `cookieName`. The legacy flat shape is still\n * accepted via the union — see `createRouteRateLimiter` for normalization.\n */\nexport const rateLimitSchema = z.union([\n // B-257 — `store` is declared on BOTH branches. `z.object` STRIPS unknown keys, so a config\n // carrying a store matched the base branch, lost it silently, and the build then refused the\n // target with the pre-B-257 message while the operator had done exactly what the feature asks.\n // Measured before the fix: `theoConfigSchema.parse` returned `{windowMs, max}` from a config\n // whose store block was present.\n baseRateLimitSchema.extend({ store: rateLimitStoreSchema.optional() }),\n z.object({\n store: rateLimitStoreSchema.optional(),\n default: baseRateLimitSchema.optional(),\n routes: z.record(z.string(), baseRateLimitSchema).optional(),\n keyBy: z\n .union([\n z.enum(['ip', 'session', 'user']),\n z.function({ input: z.tuple([z.unknown()]), output: z.string() }),\n ])\n .optional(),\n cookieName: z.string().min(1).optional(),\n /**\n * How many reverse proxies sit in front of the app, for `keyBy: 'ip'`. `false` (default)\n * trusts none; `true` means one; a number names a longer chain.\n *\n * Required for correct limiting behind Caddy/nginx/a load balancer — without it every visitor\n * keys on the proxy address and shares a single bucket. Off by default because\n * `x-forwarded-for` is client-writable.\n */\n trustProxy: z.union([z.boolean(), z.number().int().min(0)]).optional(),\n }),\n])\n","import { z } from 'zod'\n\nexport const uploadSchema = z.object({\n maxFileSize: z\n .number()\n .min(1)\n .default(10 * 1024 * 1024), // 10MB\n maxFiles: z.number().int().min(1).default(10),\n maxFieldSize: z\n .number()\n .min(1)\n .default(1 * 1024 * 1024), // 1MB\n})\n","import { z } from 'zod'\n\nexport const loggingSchema = z.object({\n level: z.enum(['debug', 'info', 'warn', 'error', 'silent']).default('info'),\n})\n","import { z } from 'zod'\n\n// `.finite()` was removed from the 4 numeric schemas below (agent-builder#319): in zod 4 it is a\n// no-op — `z.number()` already rejects `Infinity`, `-Infinity` and `NaN` by default. Measured before\n// removing, against the installed zod 4.4.3, and not assumed from the deprecation message: all five\n// cases (`Infinity`, `-Infinity`, `NaN`, `1.5`, `0`) give the SAME verdict with and without it.\n\n/**\n * Cache subsystem config (caching-and-revalidation-plan).\n * Default `cache: undefined` keeps the framework backward-compatible\n * (no engine initialized → no cache primitives available).\n *\n * Setting `cache: {}` opts in with all defaults.\n */\nconst routeRuleSchema = z.object({\n maxAge: z.number().nonnegative().optional(),\n swr: z.number().nonnegative().optional(),\n tags: z.array(z.string()).optional(),\n})\n\nexport const cacheSchema = z.object({\n enabled: z.boolean().default(true),\n /** 'memory' uses InMemoryCacheAdapter; otherwise pass a custom adapter instance. */\n storage: z.union([z.literal('memory'), z.custom<unknown>()]).default('memory'),\n maxEntries: z.number().int().positive().default(1000),\n defaults: z\n .object({\n maxAge: z.number().nonnegative().default(1),\n swr: z.number().nonnegative().optional(),\n cacheErrors: z.boolean().default(false),\n })\n .default({ maxAge: 1, cacheErrors: false }),\n keyDerivation: z\n .object({\n excludeQuery: z.array(z.string()).optional(),\n sortQuery: z.boolean().default(true),\n lowercaseHost: z.boolean().default(true),\n })\n .default({ sortQuery: true, lowercaseHost: true }),\n routeRules: z.record(z.string(), routeRuleSchema).optional(),\n})\n","import { z } from 'zod'\n\n/**\n * Observability subsystem config.\n *\n * `adapter-registry.ts` has documented `theo.config.ts > observability.provider`\n * as the first source in its resolution chain since it was written, and the key\n * did not exist in the schema — so the chain's highest-priority entry was\n * unreachable and every consumer fell through to the environment\n * (usetheokit/theokit#353).\n *\n * Default `observability: undefined` keeps telemetry off, which is what an\n * application that never asked for it should get.\n */\nexport const observabilitySchema = z.object({\n /** Set `false` to opt out even when the environment would enable an exporter. */\n enabled: z.boolean().default(true),\n /**\n * An `ObservabilityAdapter` instance. Validated structurally rather than by\n * shape, for the same reason `storage` and `plugins` are: the config layer\n * cannot import the adapter contract without inverting the module graph, and\n * the adapter is a live object rather than data.\n */\n provider: z.custom<unknown>().optional(),\n})\n","import { z } from 'zod'\n\nimport { headerSafeString } from './header-safe.js'\n\n/**\n * Phase 5 — CSRF warn-first (EC-1).\n *\n * 0.2.0 default: `warn`. Existing apps keep working but get structured\n * warnings about every state-mutating request that does not carry the\n * `X-Theo-Action: 1` header. 0.3.0 will flip the default to `strict`.\n *\n * Set explicitly to `strict` to opt into the future default early,\n * or `off` to disable CSRF entirely (only valid when you have another\n * defense — bearer auth, no session cookies, etc).\n */\n\n/**\n * Phase 6 — Default security headers (D4 / EC-2).\n *\n * 0.2.0 defaults:\n * - CSP in `report-only` mode (EC-2: don't break existing apps)\n * - X-Frame-Options: DENY · X-Content-Type-Options: nosniff\n * - Referrer-Policy: strict-origin-when-cross-origin\n * - HSTS in production only (no TLS on localhost)\n *\n * Users override individual headers, swap CSP to `enforce`, or disable\n * CSP entirely (`csp: false` / `cspMode: 'off'`).\n */\nexport const securityHeadersSchema = z.object({\n csp: z.union([headerSafeString, z.literal(false)]).optional(),\n // T6.1 — default flipped from 'report-only' to 'enforce' for 0.3.0.\n // Users who want the old behaviour set `cspMode: 'report-only'`\n // explicitly.\n cspMode: z.enum(['enforce', 'report-only', 'off']).default('enforce'),\n hsts: z.union([headerSafeString, z.literal(false)]).optional(),\n frameOptions: z.enum(['DENY', 'SAMEORIGIN']).default('DENY'),\n contentTypeOptions: z.literal('nosniff').default('nosniff'),\n referrerPolicy: headerSafeString.default('strict-origin-when-cross-origin'),\n /**\n * T1.1 — Permissions-Policy directive string. EC-3-refined: rejects CR/LF.\n * Pass `false` to suppress the header.\n */\n permissionsPolicy: z.union([headerSafeString, z.literal(false)]).optional(),\n})\n\n/**\n * T5.1 — Disallowed-routes escalation pattern (Rails-inspired).\n *\n * `routes` accepts string (exact match — trailing slash matters) or\n * RegExp entries. Matched routes that would otherwise emit `csrf.warn`\n * dispatch through `disallowedBehavior` instead:\n * - `'warn'` : no-op vs the default warn-mode behavior\n * - `'raise'` : escalate to 403, even when global `csrf` mode is 'warn'\n *\n * Use to roll out strict mode per-route (e.g., flip /api/auth/* first)\n * without committing the entire surface to strict at once.\n */\nconst disallowedConfigSchema = z.object({\n routes: z.array(z.union([z.string(), z.instanceof(RegExp)])),\n behavior: z.enum(['warn', 'raise']).default('raise'),\n})\n\n/**\n * T1.2 — CORS configuration.\n *\n * `origins` accepts a single value (`'*'`, string, RegExp, callback) OR an\n * array of (string | RegExp). The spec-violating `origins: '*'` +\n * `credentials: true` combination is rejected at parse time (browsers\n * ignore wildcards when credentials are sent).\n *\n * EC-3 — `allowedHeaders` and `exposedHeaders` entries go through the\n * header-safe refinement (CR/LF rejected — CWE-113 mitigation).\n */\nexport const corsSchema = z\n .object({\n origins: z.union([\n z.literal('*'),\n headerSafeString,\n z.instanceof(RegExp),\n z.array(z.union([headerSafeString, z.instanceof(RegExp)])),\n z.function({ input: z.tuple([z.string()]), output: z.boolean() }),\n ]),\n methods: z\n .array(z.enum(['GET', 'POST', 'PUT', 'PATCH', 'DELETE', 'OPTIONS', 'HEAD']))\n .optional(),\n allowedHeaders: z.array(headerSafeString).optional(),\n exposedHeaders: z.array(headerSafeString).optional(),\n credentials: z.boolean().default(false),\n maxAge: z.number().int().min(0).max(86400).default(600),\n })\n .refine((c) => !(c.origins === '*' && c.credentials), {\n message: 'CORS spec forbids origins:\"*\" with credentials:true — browsers ignore the wildcard',\n })\n\nexport const securitySchema = z.object({\n // T6.1 — default flipped from 'warn' to 'strict' for 0.3.0. Apps that\n // grep their warn-mode logs from 0.2.x already know which endpoints\n // break; opt back into 'warn' globally OR use disallowedRoutes for\n // surgical migration.\n csrf: z.enum(['off', 'warn', 'strict']).default('strict'),\n headers: securityHeadersSchema.optional(),\n /** T5.1 — per-route escalation (Rails disallowed_warnings pattern). */\n disallowed: disallowedConfigSchema.optional(),\n /** T1.2 — Cross-Origin Resource Sharing. Single global config; runs first in pipeline. */\n cors: corsSchema.optional(),\n /**\n * Permit binding a public network interface while write routes still declare `policy('public')`.\n *\n * Absent means `false`, and that is the point: `theo start` refuses that combination rather\n * than serving it, because an unauthenticated POST reachable from a network is an open endpoint\n * whether or not anyone meant it to be. See `cli/commands/start/public-exposure-gate.ts` for what\n * is refused and — equally important — what is not.\n *\n * Setting it to `true` is a decision, not a switch: the routes stay open, the startup log goes on\n * naming every one of them, and this line in `theo.config.ts` is what an auditor finds when they\n * ask who agreed to it.\n *\n * `.optional()` rather than `.default(false)`: a Zod default lands in the OUTPUT type, so every\n * caller constructing a `SecurityConfig` literal would have to name a field they do not care\n * about. The reader supplies the fallback (`?? false`), which keeps absent and false identical\n * where it matters and keeps the type unchanged for everyone else.\n */\n allowUnauthenticatedWrites: z.boolean().optional(),\n})\n","import { z } from 'zod'\n\n/**\n * EC-3 — CWE-113 HTTP Response Splitting mitigation.\n *\n * Every string that becomes a header value must reject CR/LF. Apps that\n * derive header values from untrusted input (feature flags, tenant config,\n * URL params) would otherwise let attackers inject Set-Cookie / Location\n * headers via `\\r\\n`. Apply this refinement to every header-bound string\n * field: permissionsPolicy, csp, hsts, referrerPolicy, CORS allow/expose.\n */\nexport const headerSafeString = z\n .string()\n .refine((s) => !/[\\r\\n]/.test(s), { message: 'Header value must not contain CR/LF' })\n","import { z } from 'zod'\n\n/**\n * StorageManager schemas (T1.1).\n *\n * `theo.config.ts > storage` declares Postgres servers (credentials), the\n * databases on each server (TheoCloud / managed PG / self-host), and Redis\n * servers. The runtime `StorageManager` consumes this block; adapters\n * (PostgresJobBackend, PostgresConversationStorage, etc.) request pools by\n * database name and never see raw credentials at the call site.\n *\n * EC-1: the top level is `.strict()`, so an unknown key fails `loadConfig`.\n * It used to strip them: a typo (`databasees`) or the `postgres: [{ url }]`\n * shape the scaffolded skill once taught parsed as `{}`, the app booted with\n * no storage, and the first `usePostgres` said `Database \"main\" not\n * configured` with nothing pointing at the config (usetheokit/theokit#1023).\n *\n * EC-2 (DEFERRED to use-time): `databases.X.server` references a key in\n * `servers`. Cross-field validation is intentionally NOT enforced at parse\n * time — `StorageManager.usePostgres()` throws an actionable error on the\n * first call with the dangling reference, matching Rails / Nitro behavior.\n */\nconst tlsConfigSchema = z.object({\n rejectUnauthorized: z.boolean().optional(),\n caCert: z.string().optional(),\n clientCert: z.string().optional(),\n clientKey: z.string().optional(),\n})\n\nconst serverConfigSchema = z.object({\n host: z.string().min(1),\n port: z.number().int().positive().max(65535).optional(),\n user: z.string().min(1),\n /** Password may be the empty string (some providers permit it). */\n password: z.string(),\n tls: tlsConfigSchema.optional(),\n})\n\nconst postgresPoolConfigSchema = z.object({\n min: z.number().int().nonnegative().optional(),\n max: z.number().int().positive().optional(),\n connectionTimeoutMillis: z.number().int().positive().optional(),\n idleTimeoutMillis: z.number().int().nonnegative().optional(),\n})\n\nconst postgresDatabaseConfigSchema = z.object({\n /** References a key in `storage.servers`. Resolved at `usePostgres()` call time. */\n server: z.string().min(1),\n database: z.string().min(1),\n pool: postgresPoolConfigSchema.optional(),\n})\n\nconst redisServerConfigSchema = serverConfigSchema.extend({\n db: z.number().int().nonnegative().optional(),\n maxRetriesPerRequest: z.number().int().nonnegative().optional(),\n})\n\nexport const storageSchema = z\n .object({\n servers: z.record(z.string(), serverConfigSchema).optional(),\n databases: z.record(z.string(), postgresDatabaseConfigSchema).optional(),\n redis: z.record(z.string(), redisServerConfigSchema).optional(),\n })\n .strict()\n\nexport type StorageConfig = z.infer<typeof storageSchema>\n"],"mappings":";;;;AAAA,SAAS,SAAS;AAKlB,IAAM,sBAAsB,EAAE,OAAO;AAAA,EACnC,UAAU,EAAE,OAAO,EAAE,IAAI,CAAC;AAAA,EAC1B,KAAK,EAAE,OAAO,EAAE,IAAI,EAAE,IAAI,CAAC;AAC7B,CAAC;AAcD,IAAM,uBAAuB,EAAE,OAAO;AAAA;AAAA,EAEpC,QAAQ,EAAE,OAAO,EAAE,IAAI,CAAC;AAAA;AAAA,EAExB,SAAS,EAAE,OAAO,EAAE,IAAI,CAAC;AAAA;AAAA,EAEzB,SAAS,EAAE,OAAO,EAAE,OAAO,GAAG,EAAE,MAAM,CAAC,EAAE,OAAO,GAAG,EAAE,OAAO,GAAG,EAAE,QAAQ,CAAC,CAAC,CAAC,EAAE,SAAS;AACzF,CAAC;AAOM,IAAM,kBAAkB,EAAE,MAAM;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAMrC,oBAAoB,OAAO,EAAE,OAAO,qBAAqB,SAAS,EAAE,CAAC;AAAA,EACrE,EAAE,OAAO;AAAA,IACP,OAAO,qBAAqB,SAAS;AAAA,IACrC,SAAS,oBAAoB,SAAS;AAAA,IACtC,QAAQ,EAAE,OAAO,EAAE,OAAO,GAAG,mBAAmB,EAAE,SAAS;AAAA,IAC3D,OAAO,EACJ,MAAM;AAAA,MACL,EAAE,KAAK,CAAC,MAAM,WAAW,MAAM,CAAC;AAAA,MAChC,EAAE,SAAS,EAAE,OAAO,EAAE,MAAM,CAAC,EA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theokit.singleton.";
|
|
6
|
+
function processSingleton(key, factory) {
|
|
7
|
+
const slot = /* @__PURE__ */ Symbol.for(NAMESPACE + key);
|
|
8
|
+
const host = globalThis;
|
|
9
|
+
const existing = host[slot];
|
|
10
|
+
if (existing !== void 0) return existing;
|
|
11
|
+
const created = factory();
|
|
12
|
+
host[slot] = created;
|
|
13
|
+
return created;
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
export {
|
|
17
|
+
processSingleton
|
|
18
|
+
};
|
|
19
|
+
//# sourceMappingURL=chunk-NF7LXSXZ.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/core/process-singleton.ts"],"sourcesContent":["/**\n * One object per PROCESS, whatever the bundler did to the module holding it.\n *\n * ## The defect this exists to remove\n *\n * A module-level `let x` gives one instance per **module instance**, and a bundler is free to place\n * the same source in more than one chunk. When it does, each chunk gets its own `x` and any state\n * written through one is invisible through the other.\n *\n * Measured in this repository's own `dist` (usetheokit/theokit#401) by grepping the built chunks for\n * each module's marker: `provider-resolver` lands in two chunks, and `approval-registry` in two.\n * Neither copy is redundant — one of the provider chunks is tree-shaken to `resolveProvider` and\n * does not carry `resetProviderRegistry` at all, which is precisely how the halves diverge: an\n * application calling `registerProvider` — public API, with a documented self-hosting example —\n * mutated the array in one chunk while `theokit start` resolved against the array in the other.\n *\n * The second is worse in kind, because `approval-registry.ts` states the requirement in its own\n * source: *\"the approval a request awaits and the approval the route resolves MUST be the same\n * object, so a single instance per process is not a convenience but a correctness requirement.\"* A\n * chunk boundary can break that silently, and the symptom would be a HITL pause that never resumes.\n *\n * ## Why `globalThis` and not better chunking\n *\n * Chunking is a bundler heuristic that changes between versions and with the shape of the import\n * graph. A fix that depends on tsup continuing to place this module in exactly one chunk is a fix\n * that holds until someone adds an import. `Symbol.for` gives a key that is equal across every\n * module instance in the realm, so identity stops depending on the build at all.\n *\n * @internal\n */\n\n/** Namespaced so a key cannot collide with an unrelated global. */\nconst NAMESPACE = 'theokit.singleton.'\n\n/**\n * The object registered under `key`, creating it with `factory` the first time.\n *\n * `factory` runs at most once per process. A later call with the same key returns what the first\n * call built and never replaces it — replacing it is the same defect wearing a different hat, since\n * two callers would again hold different objects.\n */\nexport function processSingleton<T extends object>(key: string, factory: () => T): T {\n const slot = Symbol.for(NAMESPACE + key)\n const host = globalThis as unknown as Record<symbol, T | undefined>\n\n const existing = host[slot]\n if (existing !== undefined) return existing\n\n const created = factory()\n host[slot] = created\n return created\n}\n"],"mappings":";;;;AAgCA,IAAM,YAAY;AASX,SAAS,iBAAmC,KAAa,SAAqB;AACnF,QAAM,OAAO,uBAAO,IAAI,YAAY,GAAG;AACvC,QAAM,OAAO;AAEb,QAAM,WAAW,KAAK,IAAI;AAC1B,MAAI,aAAa,OAAW,QAAO;AAEnC,QAAM,UAAU,QAAQ;AACxB,OAAK,IAAI,IAAI;AACb,SAAO;AACT;","names":[]}
|