theokit 0.48.13 → 0.50.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 +1 -0
- package/dist/{actions-virtual-module-YQXRSSMW.js → actions-virtual-module-5WBVSDOM.js} +22 -12
- package/dist/actions-virtual-module-5WBVSDOM.js.map +1 -0
- package/dist/{actions-virtual-module-LB4NGONI.js → actions-virtual-module-ZYLMNW6K.js} +13 -8
- package/dist/{actions-virtual-module-LB4NGONI.js.map → actions-virtual-module-ZYLMNW6K.js.map} +1 -1
- package/dist/adapters/agent-mount.d.ts +127 -0
- package/dist/adapters/agent-mount.js +24 -0
- package/dist/adapters/security-headers.d.ts +132 -0
- package/dist/adapters/security-headers.js +64 -0
- package/dist/adapters/security-headers.js.map +1 -0
- package/dist/adapters/web-shim.d.ts +100 -13
- package/dist/adapters/web-shim.js +158 -54
- package/dist/adapters/web-shim.js.map +1 -1
- package/dist/agent-GKUEL6OH.js +15 -0
- package/dist/agent-scan-BZa-pagG.d.ts +16 -0
- package/dist/{app-typed-client-GHO3EWZK.js → app-typed-client-4LAIEGFX.js} +23 -13
- package/dist/app-typed-client-4LAIEGFX.js.map +1 -0
- package/dist/{app-typed-client-G3J5G7E5.js → app-typed-client-DQM3Y6YY.js} +14 -9
- package/dist/app-typed-client-DQM3Y6YY.js.map +1 -0
- package/dist/aws-lambda-VKMYUMP2.js +261 -0
- package/dist/aws-lambda-VKMYUMP2.js.map +1 -0
- package/dist/{build-WU6AKKIB.js → build-FLX6VF7Q.js} +71 -26
- package/dist/build-FLX6VF7Q.js.map +1 -0
- package/dist/{bun-33RD6K7O.js → bun-L7PP6ID5.js} +105 -13
- package/dist/bun-L7PP6ID5.js.map +1 -0
- package/dist/{check-45NKUVSQ.js → check-GIPZBFTX.js} +2 -2
- package/dist/{chunk-KD5G3YXI.js → chunk-2AMLGJJA.js} +35 -9
- package/dist/chunk-2AMLGJJA.js.map +1 -0
- package/dist/chunk-3PBAN2YE.js +146 -0
- package/dist/chunk-3PBAN2YE.js.map +1 -0
- package/dist/{chunk-HBU2GIMZ.js → chunk-3QPVEJ7D.js} +15 -9
- package/dist/chunk-3QPVEJ7D.js.map +1 -0
- package/dist/{chunk-47CINLWF.js → chunk-44J2ANQC.js} +2 -2
- package/dist/{chunk-IEES3CHD.js → chunk-47MM2JUK.js} +8 -2
- package/dist/chunk-47MM2JUK.js.map +1 -0
- package/dist/chunk-4X6H2BXP.js +108 -0
- package/dist/chunk-4X6H2BXP.js.map +1 -0
- package/dist/{chunk-A7JBF5FO.js → chunk-5K4TDLRG.js} +8 -5
- package/dist/chunk-5K4TDLRG.js.map +1 -0
- package/dist/chunk-5YPXXSYY.js +181 -0
- package/dist/chunk-5YPXXSYY.js.map +1 -0
- package/dist/{chunk-YGAXV5HR.js → chunk-6J4JWHDJ.js} +191 -112
- package/dist/chunk-6J4JWHDJ.js.map +1 -0
- package/dist/chunk-72DMJBXI.js +424 -0
- package/dist/chunk-72DMJBXI.js.map +1 -0
- package/dist/chunk-7PM6K5EV.js +513 -0
- package/dist/chunk-7PM6K5EV.js.map +1 -0
- package/dist/{chunk-MTEWLGVY.js → chunk-BPYMC7SU.js} +4 -48
- package/dist/chunk-BPYMC7SU.js.map +1 -0
- package/dist/chunk-BU6RJPPJ.js +421 -0
- package/dist/chunk-BU6RJPPJ.js.map +1 -0
- package/dist/{chunk-FB2HBNIC.js → chunk-BX6EUYHU.js} +6 -2
- package/dist/chunk-BX6EUYHU.js.map +1 -0
- package/dist/{chunk-BIVCP6X5.js → chunk-C62IZEJI.js} +465 -202
- package/dist/chunk-C62IZEJI.js.map +1 -0
- package/dist/chunk-D4VP2QPR.js +16 -0
- package/dist/chunk-D4VP2QPR.js.map +1 -0
- package/dist/{chunk-J5MXCGKA.js → chunk-DHAD2O3S.js} +6 -6
- package/dist/chunk-DHAD2O3S.js.map +1 -0
- package/dist/chunk-E43VJ3E5.js +188 -0
- package/dist/chunk-E43VJ3E5.js.map +1 -0
- package/dist/chunk-EVZKNA2W.js +110 -0
- package/dist/chunk-EVZKNA2W.js.map +1 -0
- package/dist/chunk-FD4ZDTQ6.js +181 -0
- package/dist/chunk-FD4ZDTQ6.js.map +1 -0
- package/dist/chunk-FDOOBTXJ.js +17 -0
- package/dist/chunk-FDOOBTXJ.js.map +1 -0
- package/dist/chunk-FH3SQR6P.js +275 -0
- package/dist/chunk-FH3SQR6P.js.map +1 -0
- package/dist/chunk-HJHGTFEJ.js +23 -0
- package/dist/chunk-HJHGTFEJ.js.map +1 -0
- package/dist/{chunk-LXAESF4Y.js → chunk-HK4AZBKX.js} +7 -4
- package/dist/chunk-HK4AZBKX.js.map +1 -0
- package/dist/{chunk-T5C46IIU.js → chunk-HWBRS4DZ.js} +28 -269
- package/dist/chunk-HWBRS4DZ.js.map +1 -0
- package/dist/chunk-IRQGAC4L.js +52 -0
- package/dist/chunk-IRQGAC4L.js.map +1 -0
- package/dist/{chunk-FNTLKHZ7.js → chunk-JDN5SAAD.js} +7 -4
- package/dist/chunk-JDN5SAAD.js.map +1 -0
- package/dist/{chunk-GXEX4CBH.js → chunk-JIKNR5LX.js} +673 -484
- package/dist/chunk-JIKNR5LX.js.map +1 -0
- package/dist/{chunk-GRI4XHBJ.js → chunk-JWRCZIA4.js} +266 -108
- package/dist/chunk-JWRCZIA4.js.map +1 -0
- package/dist/{chunk-E576KYYT.js → chunk-KI4DOTN4.js} +25 -2
- package/dist/chunk-KI4DOTN4.js.map +1 -0
- package/dist/{chunk-ZB7D62OA.js → chunk-KUZVRJ7M.js} +3 -3
- package/dist/chunk-L4VFNFDL.js +248 -0
- package/dist/chunk-L4VFNFDL.js.map +1 -0
- package/dist/chunk-M2WC5MF7.js +127 -0
- package/dist/chunk-M2WC5MF7.js.map +1 -0
- package/dist/{chunk-O3JIAU3V.js → chunk-MCTC6HSE.js} +157 -103
- package/dist/chunk-MCTC6HSE.js.map +1 -0
- package/dist/{chunk-PXFXSFJL.js → chunk-NZ5JU6D3.js} +9 -9
- package/dist/{chunk-YRBR424R.js → chunk-OAUI273L.js} +338 -165
- package/dist/chunk-OAUI273L.js.map +1 -0
- package/dist/chunk-OGLS76RN.js +43 -0
- package/dist/chunk-OGLS76RN.js.map +1 -0
- package/dist/{chunk-7LVM22VG.js → chunk-OQCRCXCP.js} +6 -6
- package/dist/chunk-OQCRCXCP.js.map +1 -0
- package/dist/{chunk-OLGPYOLO.js → chunk-P6OS7652.js} +5 -2
- package/dist/chunk-P6OS7652.js.map +1 -0
- package/dist/chunk-Q5L5EGWZ.js +26 -0
- package/dist/chunk-Q5L5EGWZ.js.map +1 -0
- package/dist/{chunk-S433N3CT.js → chunk-QTHVHNJJ.js} +6 -36
- package/dist/chunk-QTHVHNJJ.js.map +1 -0
- package/dist/chunk-RPET332G.js +84 -0
- package/dist/chunk-RPET332G.js.map +1 -0
- package/dist/{chunk-646CA6RV.js → chunk-RQW5YMH7.js} +12 -4
- package/dist/chunk-RQW5YMH7.js.map +1 -0
- package/dist/{chunk-XALU5LCU.js → chunk-RWNYIU6A.js} +550 -146
- package/dist/chunk-RWNYIU6A.js.map +1 -0
- package/dist/chunk-SL7YUHPV.js +111 -0
- package/dist/chunk-SL7YUHPV.js.map +1 -0
- package/dist/chunk-U5PWXS3J.js +39 -0
- package/dist/chunk-U5PWXS3J.js.map +1 -0
- package/dist/chunk-ULDCFL2O.js +273 -0
- package/dist/chunk-ULDCFL2O.js.map +1 -0
- package/dist/{chunk-RWNSW4FM.js → chunk-UMNXCU3K.js} +12 -6
- package/dist/{chunk-RWNSW4FM.js.map → chunk-UMNXCU3K.js.map} +1 -1
- package/dist/chunk-VI7ZANB3.js +193 -0
- package/dist/chunk-VI7ZANB3.js.map +1 -0
- package/dist/chunk-VQPHPQ5L.js +14 -0
- package/dist/chunk-VQPHPQ5L.js.map +1 -0
- package/dist/chunk-WNJTJRM6.js +147 -0
- package/dist/chunk-WNJTJRM6.js.map +1 -0
- package/dist/chunk-WOBSEO75.js +790 -0
- package/dist/chunk-WOBSEO75.js.map +1 -0
- package/dist/{chunk-BMHS4WAN.js → chunk-XS7EX55U.js} +156 -42
- package/dist/chunk-XS7EX55U.js.map +1 -0
- package/dist/chunk-YN4W7LCX.js +31 -0
- package/dist/chunk-YN4W7LCX.js.map +1 -0
- package/dist/chunk-YSJOZEI6.js +1 -0
- package/dist/{chunk-JA2ZAT5Q.js → chunk-Z4PJMZLM.js} +2 -2
- package/dist/chunk-Z4PJMZLM.js.map +1 -0
- package/dist/{chunk-7VPQHEAJ.js → chunk-ZNZISJDZ.js} +6 -2
- package/dist/chunk-ZNZISJDZ.js.map +1 -0
- package/dist/chunk-ZWN3AODA.js +11 -0
- package/dist/chunk-ZWN3AODA.js.map +1 -0
- package/dist/cli/index.js +25 -10
- package/dist/cli/index.js.map +1 -1
- package/dist/client/core.d.ts +1 -1
- package/dist/client/core.js +2 -0
- package/dist/client/core.js.map +1 -1
- package/dist/client/index.d.ts +44 -10
- package/dist/client/index.js +35 -0
- package/dist/client/index.js.map +1 -1
- package/dist/cloudflare-SIG42OIW.js +335 -0
- package/dist/cloudflare-SIG42OIW.js.map +1 -0
- package/dist/config-support-WQHQIJTA.js +104 -0
- package/dist/config-support-WQHQIJTA.js.map +1 -0
- package/dist/{csrf-BBrEZSBW.d.ts → csrf-Dgot9qSM.d.ts} +1 -1
- package/dist/deno-deploy-LQAYOOPW.js +196 -0
- package/dist/deno-deploy-LQAYOOPW.js.map +1 -0
- package/dist/{dev-MUWJAZRD.js → dev-ANDSEVLB.js} +28 -18
- package/dist/dev-ANDSEVLB.js.map +1 -0
- package/dist/{dev-emit-GWD6IXV7.js → dev-emit-BFNMDCPB.js} +5 -5
- package/dist/{dev-emit-NBT6JD7R.js → dev-emit-MVAJAFGX.js} +5 -3
- package/dist/dev-emit-MVAJAFGX.js.map +1 -0
- package/dist/engine-singleton-X4R7AZBJ.js +315 -0
- package/dist/engine-singleton-X4R7AZBJ.js.map +1 -0
- package/dist/{generate-Y3GWM57K.js → generate-EN6EDITF.js} +43 -4
- package/dist/generate-EN6EDITF.js.map +1 -0
- package/dist/index-CzxtQcnp.d.ts +1058 -0
- package/dist/index.d.ts +4 -0
- package/dist/index.js +24 -13
- package/dist/index.js.map +1 -1
- package/dist/{info-XW7HGUPH.js → info-Y55RWS42.js} +8 -6
- package/dist/{info-XW7HGUPH.js.map → info-Y55RWS42.js.map} +1 -1
- package/dist/{internal-api-V5L65YSJ.js → internal-api-IP35YU3G.js} +22 -12
- package/dist/{internal-api-WEOSTMSN.js → internal-api-OPU456AT.js} +30 -16
- package/dist/internal-api-OPU456AT.js.map +1 -0
- package/dist/load-config-4ATXQUN3.js +16 -0
- package/dist/match-DmGgxjIU.d.ts +44 -0
- package/dist/{mcp-ULUFJNSZ.js → mcp-5LLNAGKA.js} +7 -7
- package/dist/netlify-C2IRCZKI.js +245 -0
- package/dist/netlify-C2IRCZKI.js.map +1 -0
- package/dist/node-OSVPYQ3D.js +10 -0
- package/dist/nonce-BXt7Qu_C.d.ts +31 -0
- package/dist/observability-bootstrap-MZMSOE66.js +15 -0
- package/dist/{openapi-HZXR335W.js → openapi-VFPEZSRI.js} +13 -11
- package/dist/{openapi-HZXR335W.js.map → openapi-VFPEZSRI.js.map} +1 -1
- package/dist/{plugin-runner-BFEcgtmJ.d.ts → plugin-runner-BVMOSxvb.d.ts} +1 -1
- package/dist/{plugin-types-D69-lJZ9.d.ts → plugin-types-BUVfUQ0V.d.ts} +13 -1
- package/dist/preview-GHPT2EQ5.js +23 -0
- package/dist/preview-GHPT2EQ5.js.map +1 -0
- package/dist/provider-resolver-Dx6QuWrw.d.ts +128 -0
- package/dist/registry-KBZDCFVQ.js +23 -0
- package/dist/route-config-Cm_ZMA1C.d.ts +72 -0
- package/dist/route-policy-BxOycCDq.d.ts +65 -0
- package/dist/router/element-scroll-restoration.d.ts +28 -0
- package/dist/router/element-scroll-restoration.js +96 -0
- package/dist/router/element-scroll-restoration.js.map +1 -0
- package/dist/{routes-OLNQX7CT.js → routes-BPLU3ISV.js} +11 -9
- package/dist/{routes-OLNQX7CT.js.map → routes-BPLU3ISV.js.map} +1 -1
- package/dist/{scan-7MJC6PYU.js → scan-YJEE4KQK.js} +2 -2
- package/dist/{schema-ZO3OSWVG.js → schema-SOAD43RQ.js} +7 -5
- package/dist/schemas-4AXHQMV3.js +25 -0
- package/dist/schemas-4AXHQMV3.js.map +1 -0
- package/dist/security-headers-Ccj7ncNx.d.ts +129 -0
- package/dist/server/agent/index.d.ts +2 -90
- package/dist/server/agent/index.js +1 -1
- package/dist/server/auth/index.d.ts +2 -21
- package/dist/server/auth/index.js +3 -2
- package/dist/server/cron/index.js +4 -3
- package/dist/server/define/index.d.ts +51 -57
- package/dist/server/define/index.js +10 -1
- package/dist/server/http/index.d.ts +7 -5
- package/dist/server/http/index.js +56 -12
- package/dist/server/index.d.ts +47 -439
- package/dist/server/index.js +119 -201
- package/dist/server/index.js.map +1 -1
- package/dist/server/jobs/index.js +4 -3
- package/dist/server/observability/index.d.ts +109 -35
- package/dist/server/observability/index.js +10 -7
- package/dist/server/plugins/index.d.ts +3 -3
- package/dist/server/scan/index.d.ts +47 -12
- package/dist/server/scan/index.js +13 -4
- package/dist/server/security/index.d.ts +61 -103
- package/dist/server/security/index.js +15 -6
- package/dist/server/webhook/index.d.ts +90 -3
- package/dist/server/webhook/index.js +12 -2
- package/dist/server-boundary-6B4ZQUY7.js +148 -0
- package/dist/server-boundary-6B4ZQUY7.js.map +1 -0
- package/dist/server-boundary-7VZQRPPX.js +133 -0
- package/dist/server-boundary-7VZQRPPX.js.map +1 -0
- package/dist/{services-typed-client-PSAGRPFF.js → services-typed-client-XGT5SUUN.js} +2 -2
- package/dist/{start-KR2JJR7K.js → start-UZDMOT7I.js} +342 -111
- package/dist/start-UZDMOT7I.js.map +1 -0
- package/dist/{static-M2W4HUWS.js → static-SVDWIOXJ.js} +24 -13
- package/dist/static-SVDWIOXJ.js.map +1 -0
- package/dist/{theo-cloud-XAHWOUFK.js → theo-cloud-3ET4G5T6.js} +9 -2
- package/dist/theo-cloud-3ET4G5T6.js.map +1 -0
- package/dist/vercel-BMCQKCWE.js +277 -0
- package/dist/vercel-BMCQKCWE.js.map +1 -0
- package/dist/vite-plugin/index.js +24 -13
- package/dist/vite-plugin-VKCT2LF2.js +42 -0
- package/dist/vite-plugin-VKCT2LF2.js.map +1 -0
- package/package.json +19 -6
- package/dist/actions-virtual-module-YQXRSSMW.js.map +0 -1
- package/dist/agent-7JJW3TPB.js +0 -15
- package/dist/app-typed-client-G3J5G7E5.js.map +0 -1
- package/dist/app-typed-client-GHO3EWZK.js.map +0 -1
- package/dist/aws-lambda-CYNDGU5O.js +0 -172
- package/dist/aws-lambda-CYNDGU5O.js.map +0 -1
- package/dist/build-WU6AKKIB.js.map +0 -1
- package/dist/bun-33RD6K7O.js.map +0 -1
- package/dist/chunk-646CA6RV.js.map +0 -1
- package/dist/chunk-6E5WKMDS.js +0 -67
- package/dist/chunk-6E5WKMDS.js.map +0 -1
- package/dist/chunk-6GGWS7J3.js +0 -91
- package/dist/chunk-6GGWS7J3.js.map +0 -1
- package/dist/chunk-7LVM22VG.js.map +0 -1
- package/dist/chunk-7VPQHEAJ.js.map +0 -1
- package/dist/chunk-A7JBF5FO.js.map +0 -1
- package/dist/chunk-AM3QABW5.js +0 -161
- package/dist/chunk-AM3QABW5.js.map +0 -1
- package/dist/chunk-BIVCP6X5.js.map +0 -1
- package/dist/chunk-BMHS4WAN.js.map +0 -1
- package/dist/chunk-E576KYYT.js.map +0 -1
- package/dist/chunk-FB2HBNIC.js.map +0 -1
- package/dist/chunk-FNTLKHZ7.js.map +0 -1
- package/dist/chunk-GRI4XHBJ.js.map +0 -1
- package/dist/chunk-GVW5EKEU.js +0 -422
- package/dist/chunk-GVW5EKEU.js.map +0 -1
- package/dist/chunk-GXEX4CBH.js.map +0 -1
- package/dist/chunk-HBU2GIMZ.js.map +0 -1
- package/dist/chunk-IEES3CHD.js.map +0 -1
- package/dist/chunk-J5MXCGKA.js.map +0 -1
- package/dist/chunk-JA2ZAT5Q.js.map +0 -1
- package/dist/chunk-KD5G3YXI.js.map +0 -1
- package/dist/chunk-LNVMHQ2Z.js +0 -54
- package/dist/chunk-LNVMHQ2Z.js.map +0 -1
- package/dist/chunk-LXAESF4Y.js.map +0 -1
- package/dist/chunk-MTEWLGVY.js.map +0 -1
- package/dist/chunk-O3JIAU3V.js.map +0 -1
- package/dist/chunk-OJLL4YD6.js +0 -403
- package/dist/chunk-OJLL4YD6.js.map +0 -1
- package/dist/chunk-OLGPYOLO.js.map +0 -1
- package/dist/chunk-S433N3CT.js.map +0 -1
- package/dist/chunk-T5C46IIU.js.map +0 -1
- package/dist/chunk-U267AOWS.js +0 -28
- package/dist/chunk-U267AOWS.js.map +0 -1
- package/dist/chunk-UW2TEAGR.js +0 -77
- package/dist/chunk-UW2TEAGR.js.map +0 -1
- package/dist/chunk-WPJOTQA5.js +0 -1
- package/dist/chunk-XALU5LCU.js.map +0 -1
- package/dist/chunk-XR74JD4M.js +0 -457
- package/dist/chunk-XR74JD4M.js.map +0 -1
- package/dist/chunk-YGAXV5HR.js.map +0 -1
- package/dist/chunk-YRBR424R.js.map +0 -1
- package/dist/cloudflare-KYUWCEPL.js +0 -122
- package/dist/cloudflare-KYUWCEPL.js.map +0 -1
- package/dist/deno-deploy-CCTB7HGS.js +0 -107
- package/dist/deno-deploy-CCTB7HGS.js.map +0 -1
- package/dist/dev-MUWJAZRD.js.map +0 -1
- package/dist/dev-emit-NBT6JD7R.js.map +0 -1
- package/dist/generate-Y3GWM57K.js.map +0 -1
- package/dist/index-BEtEv6ZH.d.ts +0 -575
- package/dist/load-config-VKD6LKWU.js +0 -14
- package/dist/match-CfbEFRG4.d.ts +0 -26
- package/dist/netlify-AFMDNKT4.js +0 -150
- package/dist/netlify-AFMDNKT4.js.map +0 -1
- package/dist/node-ZJQEJSP3.js +0 -10
- package/dist/registry-GKR3EWRW.js +0 -23
- package/dist/start-KR2JJR7K.js.map +0 -1
- package/dist/static-M2W4HUWS.js.map +0 -1
- package/dist/theo-cloud-XAHWOUFK.js.map +0 -1
- package/dist/vercel-SRS2DH6O.js +0 -133
- package/dist/vercel-SRS2DH6O.js.map +0 -1
- package/dist/vite-plugin-VPJFD4HK.js +0 -36
- /package/dist/{chunk-WPJOTQA5.js.map → adapters/agent-mount.js.map} +0 -0
- /package/dist/{agent-7JJW3TPB.js.map → agent-GKUEL6OH.js.map} +0 -0
- /package/dist/{check-45NKUVSQ.js.map → check-GIPZBFTX.js.map} +0 -0
- /package/dist/{chunk-47CINLWF.js.map → chunk-44J2ANQC.js.map} +0 -0
- /package/dist/{chunk-ZB7D62OA.js.map → chunk-KUZVRJ7M.js.map} +0 -0
- /package/dist/{chunk-PXFXSFJL.js.map → chunk-NZ5JU6D3.js.map} +0 -0
- /package/dist/{internal-api-WEOSTMSN.js.map → chunk-YSJOZEI6.js.map} +0 -0
- /package/dist/{dev-emit-GWD6IXV7.js.map → dev-emit-BFNMDCPB.js.map} +0 -0
- /package/dist/{internal-api-V5L65YSJ.js.map → internal-api-IP35YU3G.js.map} +0 -0
- /package/dist/{load-config-VKD6LKWU.js.map → load-config-4ATXQUN3.js.map} +0 -0
- /package/dist/{mcp-ULUFJNSZ.js.map → mcp-5LLNAGKA.js.map} +0 -0
- /package/dist/{node-ZJQEJSP3.js.map → node-OSVPYQ3D.js.map} +0 -0
- /package/dist/{scan-7MJC6PYU.js.map → observability-bootstrap-MZMSOE66.js.map} +0 -0
- /package/dist/{registry-GKR3EWRW.js.map → registry-KBZDCFVQ.js.map} +0 -0
- /package/dist/{schema-ZO3OSWVG.js.map → scan-YJEE4KQK.js.map} +0 -0
- /package/dist/{vite-plugin-VPJFD4HK.js.map → schema-SOAD43RQ.js.map} +0 -0
- /package/dist/{services-typed-client-PSAGRPFF.js.map → services-typed-client-XGT5SUUN.js.map} +0 -0
|
@@ -0,0 +1,1058 @@
|
|
|
1
|
+
import { a as TheoErrorCode, T as TheoErrorEnvelope, V as ValidationFieldsExt } from './error-envelope-DG47lt8E.js';
|
|
2
|
+
import { IncomingMessage, ServerResponse } from 'node:http';
|
|
3
|
+
import { P as PluginContext, W as WebOnRequestHook, g as WebPreHandlerHook, h as WebOnResponseHook, i as WebOnErrorHook } from './plugin-types-BUVfUQ0V.js';
|
|
4
|
+
import { P as PluginRunner } from './plugin-runner-BVMOSxvb.js';
|
|
5
|
+
import { J as JobBackend } from './job-backend-CgC8Xf33.js';
|
|
6
|
+
import { L as LoadModule, S as ServerRouteNode } from './match-DmGgxjIU.js';
|
|
7
|
+
import { C as CsrfMode, D as DisallowedConfig } from './csrf-Dgot9qSM.js';
|
|
8
|
+
import { z } from 'zod';
|
|
9
|
+
import { R as RouteConfig } from './route-config-Cm_ZMA1C.js';
|
|
10
|
+
|
|
11
|
+
interface ExecuteActionOptions {
|
|
12
|
+
filePath: string;
|
|
13
|
+
exportName: string;
|
|
14
|
+
req: IncomingMessage;
|
|
15
|
+
res: ServerResponse;
|
|
16
|
+
loadModule: LoadModule;
|
|
17
|
+
serverDir?: string;
|
|
18
|
+
requestId?: string;
|
|
19
|
+
pluginRunner?: PluginRunner;
|
|
20
|
+
csrfMode?: CsrfMode;
|
|
21
|
+
disallowed?: DisallowedConfig;
|
|
22
|
+
}
|
|
23
|
+
declare function executeAction(filePath: string, exportName: string, req: IncomingMessage, res: ServerResponse, loadModule: LoadModule, serverDir?: string, requestId?: string, pluginRunner?: PluginRunner, csrfMode?: CsrfMode, disallowed?: DisallowedConfig): Promise<void>;
|
|
24
|
+
|
|
25
|
+
/**
|
|
26
|
+
* T5.2 — pluggable response/request transformer.
|
|
27
|
+
*
|
|
28
|
+
* `superjson` is the default, preserving Date/Map/Set/BigInt/etc.
|
|
29
|
+
* `json` is the lightweight option (plain JSON.stringify/parse).
|
|
30
|
+
* Users can supply a custom object implementing this contract.
|
|
31
|
+
*/
|
|
32
|
+
interface TheoTransformer {
|
|
33
|
+
name: string;
|
|
34
|
+
serialize: (value: unknown) => string;
|
|
35
|
+
deserialize: (raw: string) => unknown;
|
|
36
|
+
}
|
|
37
|
+
declare const superjsonTransformer: TheoTransformer;
|
|
38
|
+
declare const jsonTransformer: TheoTransformer;
|
|
39
|
+
declare function resolveTransformer(selector: 'json' | 'superjson' | TheoTransformer): TheoTransformer;
|
|
40
|
+
|
|
41
|
+
/**
|
|
42
|
+
* server/http/execute-context.ts
|
|
43
|
+
*
|
|
44
|
+
* `ExecuteRouteContext` — the parameter object passed to `executeRoute()`
|
|
45
|
+
* and `executeAction()` per ADR-0016 (T3.1 of architecture-cleanup).
|
|
46
|
+
*
|
|
47
|
+
* Replaces the 12-positional-param signature with a single named-field
|
|
48
|
+
* object, eliminating 3 of 4 eslint-disable comments on `executeRoute`.
|
|
49
|
+
*
|
|
50
|
+
* Location: lives in `server/http/` (not `core/contracts/`) because the
|
|
51
|
+
* shape references server-side types (CsrfMode, JobBackend, PluginRunner,
|
|
52
|
+
* TheoTransformer, ServerRouteNode, LoadModule, DisallowedConfig). Keeping
|
|
53
|
+
* the type here preserves the existing module direction graph — no new
|
|
54
|
+
* `core → server` edges.
|
|
55
|
+
*
|
|
56
|
+
* Consumers within server/ build this object once per request; external
|
|
57
|
+
* callers (router-runner) see the same shape via the `ExecuteRouteContext`
|
|
58
|
+
* named export.
|
|
59
|
+
*/
|
|
60
|
+
|
|
61
|
+
/**
|
|
62
|
+
* The request-execution context. Each request builds one of these and passes
|
|
63
|
+
* it to `executeRoute(ctx)`.
|
|
64
|
+
*
|
|
65
|
+
* All fields are required EXCEPT those with optional `?` markers; defaults
|
|
66
|
+
* are applied inside `executeRoute` via destructure (e.g., `csrfMode = 'strict'`).
|
|
67
|
+
*/
|
|
68
|
+
interface ExecuteRouteContext {
|
|
69
|
+
route: ServerRouteNode;
|
|
70
|
+
method: string;
|
|
71
|
+
params: Record<string, string>;
|
|
72
|
+
req: IncomingMessage;
|
|
73
|
+
res: ServerResponse;
|
|
74
|
+
loadModule: LoadModule;
|
|
75
|
+
serverDir?: string;
|
|
76
|
+
requestId?: string;
|
|
77
|
+
pluginRunner?: PluginRunner;
|
|
78
|
+
transformer?: TheoTransformer;
|
|
79
|
+
/** Defaults to `'strict'` when omitted. */
|
|
80
|
+
csrfMode?: CsrfMode;
|
|
81
|
+
disallowed?: DisallowedConfig;
|
|
82
|
+
/** When provided, `ctx.queue` auto-injects + outbox lifecycle hooks attach. */
|
|
83
|
+
jobBackend?: JobBackend;
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
/**
|
|
87
|
+
* Canonical HTTP response helpers (T5.1 extraction).
|
|
88
|
+
*
|
|
89
|
+
* Moved out of execute.ts so request-pipeline stages (execute-stages.ts,
|
|
90
|
+
* handle-request-error.ts, etc.) can depend on these helpers without
|
|
91
|
+
* creating a cycle through execute.ts.
|
|
92
|
+
*
|
|
93
|
+
* Public surface re-exported from execute.ts for backward compat — every
|
|
94
|
+
* existing caller of `sendError` / `sendJson` continues to work via the
|
|
95
|
+
* `theokit/server` barrel.
|
|
96
|
+
*/
|
|
97
|
+
declare function sendJson(res: ServerResponse, data: unknown, status?: number, transformer?: TheoTransformer): void;
|
|
98
|
+
interface SendErrorOptions {
|
|
99
|
+
custom404Html?: string;
|
|
100
|
+
custom500Html?: string;
|
|
101
|
+
}
|
|
102
|
+
/**
|
|
103
|
+
* Canonical error response.
|
|
104
|
+
*
|
|
105
|
+
* T6.3 (PV-17): the positional 7-param signature is preserved for backward
|
|
106
|
+
* compat. New call sites should use the options-bag form:
|
|
107
|
+
*
|
|
108
|
+
* sendError(res, { code, message, status, issues?, requestId?, options? })
|
|
109
|
+
*
|
|
110
|
+
* Both shapes resolve to the same implementation.
|
|
111
|
+
*/
|
|
112
|
+
interface SendErrorInput {
|
|
113
|
+
code: string;
|
|
114
|
+
message: string;
|
|
115
|
+
status: number;
|
|
116
|
+
issues?: unknown[];
|
|
117
|
+
requestId?: string;
|
|
118
|
+
options?: SendErrorOptions;
|
|
119
|
+
}
|
|
120
|
+
declare function sendError(res: ServerResponse, input: SendErrorInput): void;
|
|
121
|
+
declare function sendError(res: ServerResponse, code: string, message: string, status: number, issues?: unknown[], requestId?: string, options?: SendErrorOptions): void;
|
|
122
|
+
|
|
123
|
+
declare function executeRoute(ctx: ExecuteRouteContext): Promise<void>;
|
|
124
|
+
|
|
125
|
+
/**
|
|
126
|
+
* T1.4 — Server-side batch handler.
|
|
127
|
+
*
|
|
128
|
+
* Receives `{ requests: [...] }` POSTed to `/api/__theo_batch__` and returns
|
|
129
|
+
* `{ results: [...] }` with per-item error isolation. EC-2: items cannot
|
|
130
|
+
* override auth/forwarded headers (would be a session-bypass vector).
|
|
131
|
+
*/
|
|
132
|
+
|
|
133
|
+
declare const STRIPPED_HEADERS: readonly ["authorization", "cookie", "x-forwarded-for", "x-forwarded-host", "x-forwarded-proto", "x-real-ip", "host"];
|
|
134
|
+
declare const BATCH_PATH = "/api/__theo_batch__";
|
|
135
|
+
declare class BatchPathConflictError extends Error {
|
|
136
|
+
constructor(path: string);
|
|
137
|
+
}
|
|
138
|
+
declare const batchRequestSchema: z.ZodObject<{
|
|
139
|
+
path: z.ZodString;
|
|
140
|
+
method: z.ZodString;
|
|
141
|
+
query: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodUnknown>>;
|
|
142
|
+
body: z.ZodOptional<z.ZodUnknown>;
|
|
143
|
+
headers: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodString>>;
|
|
144
|
+
}, z.core.$strip>;
|
|
145
|
+
declare const batchPayloadSchema: z.ZodObject<{
|
|
146
|
+
requests: z.ZodArray<z.ZodObject<{
|
|
147
|
+
path: z.ZodString;
|
|
148
|
+
method: z.ZodString;
|
|
149
|
+
query: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodUnknown>>;
|
|
150
|
+
body: z.ZodOptional<z.ZodUnknown>;
|
|
151
|
+
headers: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodString>>;
|
|
152
|
+
}, z.core.$strip>>;
|
|
153
|
+
}, z.core.$strip>;
|
|
154
|
+
type BatchRequestItem = z.infer<typeof batchRequestSchema>;
|
|
155
|
+
type BatchPayload = z.infer<typeof batchPayloadSchema>;
|
|
156
|
+
type BatchExecuteFn = (req: BatchRequestItem) => Promise<{
|
|
157
|
+
data: unknown;
|
|
158
|
+
} | {
|
|
159
|
+
error: {
|
|
160
|
+
message: string;
|
|
161
|
+
code?: string;
|
|
162
|
+
};
|
|
163
|
+
}>;
|
|
164
|
+
interface HandleBatchOptions {
|
|
165
|
+
execute: BatchExecuteFn;
|
|
166
|
+
/** Max number of items per batch. Default 32. */
|
|
167
|
+
max?: number;
|
|
168
|
+
/** Outer-request headers that override per-item headers in STRIPPED_HEADERS. */
|
|
169
|
+
outerHeaders?: Record<string, string>;
|
|
170
|
+
}
|
|
171
|
+
type BatchResultItem = {
|
|
172
|
+
data: unknown;
|
|
173
|
+
} | {
|
|
174
|
+
error: {
|
|
175
|
+
message: string;
|
|
176
|
+
code?: string;
|
|
177
|
+
};
|
|
178
|
+
};
|
|
179
|
+
interface BatchResponse {
|
|
180
|
+
results: BatchResultItem[];
|
|
181
|
+
}
|
|
182
|
+
/**
|
|
183
|
+
* Validate + execute a batch request.
|
|
184
|
+
*
|
|
185
|
+
* CR-028 fix: previously the signature was `payload: BatchPayload`,
|
|
186
|
+
* suggesting the caller had already validated. In reality `api-middleware`
|
|
187
|
+
* passes `JSON.parse(rawBody) as BatchPayload` — an unsafe cast over raw
|
|
188
|
+
* HTTP input. We widen the input type to `unknown` so the type system
|
|
189
|
+
* forces validation, then run Zod once at this single trust boundary.
|
|
190
|
+
*/
|
|
191
|
+
declare function handleBatchRequest(payload: unknown, options: HandleBatchOptions): Promise<BatchResponse>;
|
|
192
|
+
|
|
193
|
+
/**
|
|
194
|
+
* T1.2 — CORS middleware.
|
|
195
|
+
*
|
|
196
|
+
* Single global middleware that runs FIRST in the request pipeline:
|
|
197
|
+
* CORS preflight → rate limit → CSRF → security headers → handler
|
|
198
|
+
*
|
|
199
|
+
* Preflight (`OPTIONS` with `Access-Control-Request-Method`) is handled
|
|
200
|
+
* by `handlePreflight`, which short-circuits the response with 204 +
|
|
201
|
+
* Access-Control-* headers.
|
|
202
|
+
*
|
|
203
|
+
* Non-preflight requests pass through; `applyHeaders` adds
|
|
204
|
+
* `Access-Control-Allow-Origin` (echoing the request's Origin),
|
|
205
|
+
* `Access-Control-Expose-Headers`, and `Access-Control-Allow-Credentials`.
|
|
206
|
+
*
|
|
207
|
+
* Per ADR D3: preflight responses are deterministic and only the matched
|
|
208
|
+
* origin is echoed back (never `'*'` when credentials are enabled —
|
|
209
|
+
* required by the CORS spec).
|
|
210
|
+
*/
|
|
211
|
+
type CorsOrigin = string | RegExp | readonly (string | RegExp)[] | ((origin: string) => boolean);
|
|
212
|
+
interface CorsConfig {
|
|
213
|
+
origins: CorsOrigin;
|
|
214
|
+
methods?: readonly ('GET' | 'POST' | 'PUT' | 'PATCH' | 'DELETE' | 'OPTIONS' | 'HEAD')[];
|
|
215
|
+
allowedHeaders?: readonly string[];
|
|
216
|
+
exposedHeaders?: readonly string[];
|
|
217
|
+
credentials?: boolean;
|
|
218
|
+
maxAge?: number;
|
|
219
|
+
}
|
|
220
|
+
interface CorsHandler {
|
|
221
|
+
handlePreflight(req: IncomingMessage, res: ServerResponse): boolean;
|
|
222
|
+
applyHeaders(req: IncomingMessage, res: ServerResponse): void;
|
|
223
|
+
}
|
|
224
|
+
/**
|
|
225
|
+
* Test whether `origin` is allowed by `allowed`. Pure function — no I/O.
|
|
226
|
+
*
|
|
227
|
+
* EC-8: callback variants that throw are fail-closed (deny). Without
|
|
228
|
+
* this, a transient datastore outage would silently widen CORS during
|
|
229
|
+
* the failure window.
|
|
230
|
+
*/
|
|
231
|
+
declare function matchesOrigin(origin: string, allowed: CorsOrigin): boolean;
|
|
232
|
+
declare function createCorsHandler(config: CorsConfig): CorsHandler;
|
|
233
|
+
/**
|
|
234
|
+
* T5a.2 Phase B slice 5/6 — Web-Standards CORS handler.
|
|
235
|
+
*
|
|
236
|
+
* Mirror of `createCorsHandler(config): CorsHandler` for the Web `Request`
|
|
237
|
+
* shape. Same `CorsConfig`, same `matchesOrigin` logic (pure helper
|
|
238
|
+
* already), same security guarantees (echo matched origin only — never
|
|
239
|
+
* `'*'` when credentials enabled; EC-8 fail-closed on callback throw).
|
|
240
|
+
*
|
|
241
|
+
* Signature differences vs the IncomingMessage pair:
|
|
242
|
+
* - `handlePreflightRequest(request, config): Response | null` — returns
|
|
243
|
+
* `Response` when this is a CORS preflight; `null` when not. Caller
|
|
244
|
+
* short-circuits accordingly (same control-flow semantic as boolean).
|
|
245
|
+
* - `applyCorsHeaders(request, target, config): void` — mutates a
|
|
246
|
+
* `Headers` instance in place. Caller passes the headers they're
|
|
247
|
+
* building for their Response.
|
|
248
|
+
*/
|
|
249
|
+
interface CorsWebHandler {
|
|
250
|
+
handlePreflightRequest(request: Request): Response | null;
|
|
251
|
+
applyCorsHeaders(request: Request, target: Headers): void;
|
|
252
|
+
}
|
|
253
|
+
declare function createCorsWebHandler(config: CorsConfig): CorsWebHandler;
|
|
254
|
+
|
|
255
|
+
/**
|
|
256
|
+
* Phase 7 — Observability: traceId propagation (D7).
|
|
257
|
+
*
|
|
258
|
+
* Extract a stable identifier from incoming requests so a single value
|
|
259
|
+
* correlates the client request, every server log line, the response
|
|
260
|
+
* envelope, and any downstream span. Precedence:
|
|
261
|
+
*
|
|
262
|
+
* 1. `traceparent` (W3C Trace Context — `00-{32-hex}-{16-hex}-{flags}`)
|
|
263
|
+
* 2. `x-request-id` (Heroku / GCP / generic proxy header)
|
|
264
|
+
* 3. Generated UUID (fresh per request)
|
|
265
|
+
*
|
|
266
|
+
* UUIDs are accepted as trace identifiers by every major vendor that
|
|
267
|
+
* does not enforce strict 32-hex (Datadog, Honeycomb, Sentry, Logflare,
|
|
268
|
+
* Axiom, etc). We don't need ULIDs to ship this surface.
|
|
269
|
+
*/
|
|
270
|
+
declare const TRACE_HEADER = "x-trace-id";
|
|
271
|
+
declare const TRACE_PARENT_HEADER = "traceparent";
|
|
272
|
+
/**
|
|
273
|
+
* What a valid `traceparent` says: the trace to join, and the caller's span
|
|
274
|
+
* inside it.
|
|
275
|
+
*
|
|
276
|
+
* Both halves are on the wire and only the first was ever read, so a span this
|
|
277
|
+
* process opened for an incoming request became a SECOND root of the caller's
|
|
278
|
+
* trace instead of a child of the caller's span — the trace correlated and the
|
|
279
|
+
* waterfall lost its shape (usetheokit/theokit#385).
|
|
280
|
+
*/
|
|
281
|
+
interface W3CTraceContext {
|
|
282
|
+
/** The trace this request belongs to. 32 hex chars. */
|
|
283
|
+
readonly traceId: string;
|
|
284
|
+
/**
|
|
285
|
+
* The caller's span, which a span opened for this request hangs under.
|
|
286
|
+
*
|
|
287
|
+
* Absent when the caller sent the reserved all-zero parent id, which W3C
|
|
288
|
+
* defines as "no parent" rather than as a span to point at.
|
|
289
|
+
*/
|
|
290
|
+
readonly parentSpanId?: string;
|
|
291
|
+
}
|
|
292
|
+
/**
|
|
293
|
+
* Parse a W3C Trace Context `traceparent` header value into the trace it names
|
|
294
|
+
* and the caller's span within it. `null` when the value is not a well-formed
|
|
295
|
+
* `traceparent` or names the reserved all-zero trace.
|
|
296
|
+
*/
|
|
297
|
+
declare function parseTraceparentContext(value: string): W3CTraceContext | null;
|
|
298
|
+
/**
|
|
299
|
+
* Parse a W3C Trace Context `traceparent` header value. Returns the
|
|
300
|
+
* 32-hex trace-id when valid (and not the reserved all-zeros), else
|
|
301
|
+
* `null`.
|
|
302
|
+
*/
|
|
303
|
+
declare function parseTraceparent(value: string): string | null;
|
|
304
|
+
/**
|
|
305
|
+
* Resolve the request's traceId following the precedence above.
|
|
306
|
+
*/
|
|
307
|
+
declare function extractTraceId(req: IncomingMessage): string;
|
|
308
|
+
/**
|
|
309
|
+
* T5a.2 Phase C slice 1/2 — Web-Standards-shaped traceId resolver.
|
|
310
|
+
*
|
|
311
|
+
* Mirror of `extractTraceId(req: IncomingMessage)` for the Web `Request`
|
|
312
|
+
* shape. Same precedence (`traceparent` → `x-request-id` → generated
|
|
313
|
+
* UUID). Uses `request.headers.get(name)` (native Web `Headers` API)
|
|
314
|
+
* instead of the Node indexer.
|
|
315
|
+
*
|
|
316
|
+
* **Multi-value note:** Web `Headers` collapses repeated headers into a
|
|
317
|
+
* single comma-separated string at parse. The IncomingMessage path's
|
|
318
|
+
* `pickHeader` "first non-empty value" semantic is naturally satisfied
|
|
319
|
+
* because there's no array to pick from on the Web side — `.get()`
|
|
320
|
+
* returns the comma-joined value, which for `traceparent` / `x-request-id`
|
|
321
|
+
* is treated as a single string anyway (both headers are conventionally
|
|
322
|
+
* single-valued).
|
|
323
|
+
*/
|
|
324
|
+
/**
|
|
325
|
+
* The request's W3C trace context — the trace to join and the caller's span
|
|
326
|
+
* within it — or `undefined` when the caller supplied no usable `traceparent`.
|
|
327
|
+
*
|
|
328
|
+
* Deliberately narrower than {@link extractTraceIdFromRequest}, which always
|
|
329
|
+
* returns something and may return an `x-request-id` or a generated UUID. Those
|
|
330
|
+
* are fine as a log correlation key and are NOT trace ids: OTLP wants 32 hex
|
|
331
|
+
* characters, and a dashed UUID exported as a `traceId` is a malformed span.
|
|
332
|
+
*
|
|
333
|
+
* So a span-emitting caller asks this question instead — "is there a real trace
|
|
334
|
+
* to join?" — and mints its own when the answer is no (usetheokit/theokit#368).
|
|
335
|
+
*
|
|
336
|
+
* It answers with the whole context rather than the trace id alone, because a
|
|
337
|
+
* span opened for this request belongs in the caller's trace AND under the
|
|
338
|
+
* caller's span. Returning only the first half is what made one request arrive
|
|
339
|
+
* as a trace with two roots (usetheokit/theokit#385).
|
|
340
|
+
*/
|
|
341
|
+
declare function extractW3CTraceContext(request: Request): W3CTraceContext | undefined;
|
|
342
|
+
declare function extractTraceIdFromRequest(request: Request): string;
|
|
343
|
+
|
|
344
|
+
/**
|
|
345
|
+
* `TheoError` — envelope-emitting `Error` subclass per plan
|
|
346
|
+
* g5-error-envelope-cross-layer v1.0 § Phase 1 / T1.2.
|
|
347
|
+
*
|
|
348
|
+
* Mirrors trpc's TRPCError ergonomic pattern (reference:
|
|
349
|
+
* trpc/packages/server/src/unstable-core-do-not-import/error/TRPCError.ts:65-87)
|
|
350
|
+
* adapted for theokit's hybrid envelope model (blueprint Form 4).
|
|
351
|
+
*
|
|
352
|
+
* Per ADR D5: `meta.stack` is auto-stripped in non-dev builds when serialized
|
|
353
|
+
* via `toJSON()` — defense against accidental stack leak to clients (encore
|
|
354
|
+
* `json:"-"` analog).
|
|
355
|
+
*
|
|
356
|
+
* Lives in `core/contracts/` per architecture.md v3 invariant #3.
|
|
357
|
+
*/
|
|
358
|
+
|
|
359
|
+
/**
|
|
360
|
+
* Constructor options. `code` and `message` are required; `cause` follows TC39
|
|
361
|
+
* proposal-error-cause; `meta` and `ext` are opt-in per blueprint ADR D2.
|
|
362
|
+
*/
|
|
363
|
+
interface TheoErrorOptions<TExt = unknown> {
|
|
364
|
+
readonly code: TheoErrorCode;
|
|
365
|
+
readonly message: string;
|
|
366
|
+
readonly cause?: unknown;
|
|
367
|
+
readonly meta?: Record<string, unknown>;
|
|
368
|
+
readonly ext?: TExt;
|
|
369
|
+
}
|
|
370
|
+
/**
|
|
371
|
+
* `TheoError` — envelope-emitting Error subclass. Use this anywhere in
|
|
372
|
+
* `theokit/server`, route handlers, or middleware to emit a typed,
|
|
373
|
+
* cross-layer-compatible error.
|
|
374
|
+
*
|
|
375
|
+
* Mirrors TRPCError pattern: `code` is required, `message` defaults to
|
|
376
|
+
* code if omitted, `cause` chain is preserved via TC39 proposal-error-cause.
|
|
377
|
+
*/
|
|
378
|
+
declare class TheoError<TExt = unknown> extends Error {
|
|
379
|
+
readonly name = "TheoError";
|
|
380
|
+
readonly code: TheoErrorCode;
|
|
381
|
+
readonly meta?: Record<string, unknown>;
|
|
382
|
+
readonly ext?: TExt;
|
|
383
|
+
constructor(opts: TheoErrorOptions<TExt>);
|
|
384
|
+
/**
|
|
385
|
+
* The canonical envelope view of this error. Use when crossing the wire
|
|
386
|
+
* boundary or feeding telemetry — exposes the shape consumers can rely on
|
|
387
|
+
* without depending on the class identity.
|
|
388
|
+
*/
|
|
389
|
+
get envelope(): TheoErrorEnvelope<TExt>;
|
|
390
|
+
/**
|
|
391
|
+
* JSON serialization — emits envelope shape only (no name/stack class
|
|
392
|
+
* internals). Per ADR D5, `meta.stack` is auto-stripped in non-dev to
|
|
393
|
+
* prevent accidental leak; other meta keys are preserved.
|
|
394
|
+
*/
|
|
395
|
+
toJSON(): TheoErrorEnvelope<TExt>;
|
|
396
|
+
}
|
|
397
|
+
/**
|
|
398
|
+
* Coerce any unknown value into a TheoError envelope.
|
|
399
|
+
*
|
|
400
|
+
* - If value is already a TheoError, returns it unchanged (no double-wrap).
|
|
401
|
+
* - If value is a plain Error, wraps it as `INTERNAL_SERVER_ERROR` with
|
|
402
|
+
* `cause` chain preserving the original.
|
|
403
|
+
* - Other values (string, undefined, object) are coerced safely with a
|
|
404
|
+
* meaningful message.
|
|
405
|
+
*
|
|
406
|
+
* Use at framework boundaries (route handler catch-all, middleware catch,
|
|
407
|
+
* SDK egress) to ensure every error crossing the wire carries an envelope.
|
|
408
|
+
*/
|
|
409
|
+
/**
|
|
410
|
+
* `NotFoundError` — typed 404. A `TheoError` with code `NOT_FOUND`, so it
|
|
411
|
+
* carries a stable `code` (not a bare status literal) and maps to HTTP 404 via
|
|
412
|
+
* `envelopeCodeToStatus`. Throw it from a `defineRoute` handler for ergonomic
|
|
413
|
+
* 404s (M7-1).
|
|
414
|
+
*/
|
|
415
|
+
declare class NotFoundError extends TheoError {
|
|
416
|
+
constructor(message?: string, meta?: Record<string, unknown>);
|
|
417
|
+
}
|
|
418
|
+
declare function fromUnknown(value: unknown): TheoError;
|
|
419
|
+
|
|
420
|
+
/**
|
|
421
|
+
* G5 T2.5 — server-side boundary translation per blueprint ADR D3.
|
|
422
|
+
*
|
|
423
|
+
* Translates ad-hoc Error class instances (FileTooLargeError,
|
|
424
|
+
* AuthRequiredError, RouterConventionError, etc.) into the canonical
|
|
425
|
+
* `TheoErrorEnvelope` shape at the wire boundary. This is the SINGLE
|
|
426
|
+
* boundary translation point — class identities stay in place inside the
|
|
427
|
+
* codebase (no invasive call-site rewrites), but the envelope is what
|
|
428
|
+
* crosses to clients.
|
|
429
|
+
*
|
|
430
|
+
* Pure; no I/O. Lives in `core/contracts/` per architecture.md v3
|
|
431
|
+
* invariant #3 (canonical home for shared client↔server types). This file
|
|
432
|
+
* is the EXCEPTION-of-an-exception: it intentionally inspects Error names
|
|
433
|
+
* by string instead of `instanceof` to avoid `core/contracts/` taking a
|
|
434
|
+
* dependency on `server/`. The mapping table is small and grep-discoverable.
|
|
435
|
+
*/
|
|
436
|
+
|
|
437
|
+
/**
|
|
438
|
+
* Translate any server-side Error instance into a canonical envelope.
|
|
439
|
+
*
|
|
440
|
+
* Pass-through behavior:
|
|
441
|
+
* - `TheoError` instances return their `.envelope` unchanged.
|
|
442
|
+
* - Plain `Error` with unknown name → `INTERNAL_SERVER_ERROR`.
|
|
443
|
+
* - Non-Error values → wrapped via `TheoError.fromUnknown` semantics.
|
|
444
|
+
*
|
|
445
|
+
* Meta carries the source class `name` plus class-specific fields when an
|
|
446
|
+
* extractor is registered. This keeps wire-side telemetry useful without
|
|
447
|
+
* leaking implementation details.
|
|
448
|
+
*/
|
|
449
|
+
declare function serverErrorToEnvelope(value: unknown): TheoErrorEnvelope;
|
|
450
|
+
|
|
451
|
+
/**
|
|
452
|
+
* Maps a TheoErrorEnvelope `code` to its canonical HTTP status.
|
|
453
|
+
*
|
|
454
|
+
* Single source of truth — previously duplicated in `web-handler.ts` and
|
|
455
|
+
* `handle-request-error.ts` (architecture-remediation plan T1.2, 2026-06-12).
|
|
456
|
+
*
|
|
457
|
+
* Every TheoErrorCode value MUST have an explicit entry here. SDK-domain codes
|
|
458
|
+
* (AGENT_RUN_ERROR, PROVIDER_KEY_MISSING, BUDGET_EXCEEDED, CREDENTIAL_POOL_EXHAUSTED)
|
|
459
|
+
* intentionally map to 500 — they represent internal failures, not client errors.
|
|
460
|
+
*/
|
|
461
|
+
declare function envelopeCodeToStatus(code: string): number;
|
|
462
|
+
|
|
463
|
+
/**
|
|
464
|
+
* Canonical error handler for HTTP request pipelines (T3.4 of
|
|
465
|
+
* architecture-review-remediation-plan, PV-9 DRY).
|
|
466
|
+
*
|
|
467
|
+
* Replaces the duplicated catch-block logic in `executeRoute` (1 site) and
|
|
468
|
+
* `executeAction` (1 site, via `handleActionError`). Both code paths now
|
|
469
|
+
* share this implementation.
|
|
470
|
+
*
|
|
471
|
+
* Behavior contract (preserved from previous inline catches):
|
|
472
|
+
* - Plugin `onError` fires first (swallowed if it throws — never amplify failure).
|
|
473
|
+
* - `AuthRequiredError` is detected via `instanceof` AND a duck-type shape
|
|
474
|
+
* check (`code === 'AUTH_REQUIRED' && status === 401`) — required because
|
|
475
|
+
* under Vite dev / vitest the module-loader can produce a duplicate
|
|
476
|
+
* AuthRequiredError class identity, breaking `instanceof`.
|
|
477
|
+
* - `onResponse({ inErrorPath: true })` always fires at the end (swallowed
|
|
478
|
+
* if it throws — EC-9).
|
|
479
|
+
*/
|
|
480
|
+
interface HandleRequestErrorCtx {
|
|
481
|
+
req: IncomingMessage;
|
|
482
|
+
res: ServerResponse;
|
|
483
|
+
requestId: string | undefined;
|
|
484
|
+
pluginRunner: PluginRunner | undefined;
|
|
485
|
+
buildPluginCtx: (ctxObj: Record<string, unknown>) => PluginContext;
|
|
486
|
+
}
|
|
487
|
+
declare function handleRequestError(err: unknown, c: HandleRequestErrorCtx): Promise<void>;
|
|
488
|
+
/**
|
|
489
|
+
* T5a.2 Phase G slice 3/N — Web-Standards request error handler.
|
|
490
|
+
*
|
|
491
|
+
* Mirror of `handleRequestError(err, c: HandleRequestErrorCtx)` for the
|
|
492
|
+
* Web `Request` shape. Returns a native `Response` directly instead of
|
|
493
|
+
* mutating `res`. Same behavioral contract:
|
|
494
|
+
*
|
|
495
|
+
* 1. Auth-error detection via `instanceof AuthRequiredError` PLUS a
|
|
496
|
+
* duck-type fallback (`code === 'AUTH_REQUIRED' && status === 401`)
|
|
497
|
+
* — needed because Vite dev / vitest can produce duplicate class
|
|
498
|
+
* identities, breaking `instanceof`.
|
|
499
|
+
* 2. Envelope-shaped JSON body using `serverErrorToEnvelope` (G5 D3
|
|
500
|
+
* boundary translation).
|
|
501
|
+
* 3. Status code derived from envelope.code via `envelopeCodeToStatus`
|
|
502
|
+
* mirror (already implemented inline in web-handler.ts; this slice
|
|
503
|
+
* uses the same mapping table).
|
|
504
|
+
*
|
|
505
|
+
* **Difference vs IncomingMessage path:** the Web path's plugin runner
|
|
506
|
+
* orchestration lives in `executeWebRequest`'s `runWithHooks` /
|
|
507
|
+
* `runErrorHooks` (Phase G slice 1/N) — `handleWebRequestError` is the
|
|
508
|
+
* leaf that builds the error Response WITHOUT touching plugin hooks.
|
|
509
|
+
* Callers compose: `executeWebRequest` (or future Web execute pipeline)
|
|
510
|
+
* catches a throw, calls `handleWebRequestError(err, { requestId })` to
|
|
511
|
+
* build the Response, then routes through onError hooks separately.
|
|
512
|
+
*/
|
|
513
|
+
interface HandleWebRequestErrorCtx {
|
|
514
|
+
requestId?: string;
|
|
515
|
+
}
|
|
516
|
+
declare function handleWebRequestError(err: unknown, ctx?: HandleWebRequestErrorCtx): Promise<Response>;
|
|
517
|
+
|
|
518
|
+
interface MiddlewareResult {
|
|
519
|
+
ctx: unknown;
|
|
520
|
+
aborted: boolean;
|
|
521
|
+
}
|
|
522
|
+
declare function _resetMiddlewareCacheForTests(): void;
|
|
523
|
+
declare function runMiddlewareAndContext(req: IncomingMessage, res: ServerResponse, loadModule: LoadModule, serverDir: string): Promise<MiddlewareResult>;
|
|
524
|
+
/**
|
|
525
|
+
* Run ONLY the application's `server/context.ts` factory and return what it produced.
|
|
526
|
+
*
|
|
527
|
+
* Split out of {@link runMiddlewareAndContext} because the agent endpoints need the identity half
|
|
528
|
+
* of that function and must not take the middleware half with it (usetheokit/theokit#365).
|
|
529
|
+
*
|
|
530
|
+
* The split is not a shortcut, it is the whole of what those endpoints can honestly reuse today:
|
|
531
|
+
* middleware here is `(req, res, next)` and contributes NOTHING to `ctx` — only this factory does.
|
|
532
|
+
* So running the chain would buy the policy no identity it does not already get, while adding
|
|
533
|
+
* abort semantics and header side effects to a dispatch branch that has never had them. Running
|
|
534
|
+
* `server/middleware/` on agent URLs is a separate, larger behaviour change; it is not this one.
|
|
535
|
+
*/
|
|
536
|
+
declare function createServerContext(req: IncomingMessage, res: ServerResponse, loadModule: LoadModule, serverDir: string): Promise<unknown>;
|
|
537
|
+
|
|
538
|
+
interface CookieOptions {
|
|
539
|
+
httpOnly?: boolean;
|
|
540
|
+
secure?: boolean;
|
|
541
|
+
sameSite?: 'strict' | 'lax' | 'none';
|
|
542
|
+
maxAge?: number;
|
|
543
|
+
path?: string;
|
|
544
|
+
domain?: string;
|
|
545
|
+
}
|
|
546
|
+
/**
|
|
547
|
+
* Parse a `Cookie` header into a Map (RFC 6265 §5.4).
|
|
548
|
+
* - Empty/missing input → empty Map.
|
|
549
|
+
* - Malformed entries (no `=`) skipped silently (defensive).
|
|
550
|
+
* - Duplicate names → last-wins.
|
|
551
|
+
* - Values URL-decoded if possible; raw on decode failure (CR-009 protection).
|
|
552
|
+
*
|
|
553
|
+
* Canonical helper (T3.2 of architecture-review-remediation-plan; PV-4 DRY).
|
|
554
|
+
* Consumed by `getCookie` here AND by `rate-limit/rate-limit-per-route.ts`.
|
|
555
|
+
*/
|
|
556
|
+
declare function parseCookieHeader(header: string | undefined): Map<string, string>;
|
|
557
|
+
declare function getCookie(req: IncomingMessage, name: string): string | undefined;
|
|
558
|
+
/**
|
|
559
|
+
* T5a.2 Phase B slice 6/6 — pure Set-Cookie serializer. Extracted from
|
|
560
|
+
* `setCookie(res, ...)` so the IncomingMessage path AND the Web Headers
|
|
561
|
+
* path can share the cookie attribute composition.
|
|
562
|
+
*
|
|
563
|
+
* Returns the canonical `Set-Cookie` header value string (no surrounding
|
|
564
|
+
* `Set-Cookie:` prefix — caller wraps via `res.setHeader('Set-Cookie', ...)`
|
|
565
|
+
* or `headers.append('Set-Cookie', ...)`).
|
|
566
|
+
*
|
|
567
|
+
* Defaults: `httpOnly: true`, `secure: NODE_ENV === 'production'`,
|
|
568
|
+
* `sameSite: 'lax'`, `path: '/'`.
|
|
569
|
+
*/
|
|
570
|
+
declare function serializeCookie(name: string, value: string, options?: CookieOptions): string;
|
|
571
|
+
declare function setCookie(res: ServerResponse, name: string, value: string, options?: CookieOptions): void;
|
|
572
|
+
declare function deleteCookie(res: ServerResponse, name: string, options?: {
|
|
573
|
+
path?: string;
|
|
574
|
+
}): void;
|
|
575
|
+
/**
|
|
576
|
+
* T5a.2 Phase B slice 6/6 — Web-Standards cookie getter.
|
|
577
|
+
*
|
|
578
|
+
* Mirror of `getCookie(req: IncomingMessage, name)` for the Web `Request`
|
|
579
|
+
* shape. Consumes `request.headers.get('cookie')` (native `Headers` API)
|
|
580
|
+
* instead of `req.headers.cookie`. Same parse logic + same malformed
|
|
581
|
+
* percent-encoding sanity (returns undefined when raw value contains a
|
|
582
|
+
* lone `%` that didn't decode, preserving the IncomingMessage path's
|
|
583
|
+
* "treat as unreadable" CR-009 semantics).
|
|
584
|
+
*/
|
|
585
|
+
declare function getCookieFromRequest(request: Request, name: string): string | undefined;
|
|
586
|
+
/**
|
|
587
|
+
* T5a.2 Phase B slice 6/6 — Web-Standards cookie setter.
|
|
588
|
+
*
|
|
589
|
+
* Mirror of `setCookie(res, name, value, options)` for the Web `Headers`
|
|
590
|
+
* shape. Appends a `Set-Cookie` entry to the caller's `Headers` instance
|
|
591
|
+
* via `headers.append('Set-Cookie', ...)`. Multiple appends produce
|
|
592
|
+
* multiple `Set-Cookie` headers per the Web spec; `headers.getSetCookie()`
|
|
593
|
+
* retrieves them as an array (the one multi-value header the Web API
|
|
594
|
+
* exposes natively).
|
|
595
|
+
*
|
|
596
|
+
* Uses the shared `serializeCookie` pure helper — same defaults and
|
|
597
|
+
* attribute composition as the IncomingMessage path.
|
|
598
|
+
*/
|
|
599
|
+
declare function appendCookieToHeaders(target: Headers, name: string, value: string, options?: CookieOptions): void;
|
|
600
|
+
/**
|
|
601
|
+
* T5a.2 Phase B slice 6/6 — Web-Standards cookie deleter.
|
|
602
|
+
*
|
|
603
|
+
* Mirror of `deleteCookie(res, name, options)` — emits a Set-Cookie with
|
|
604
|
+
* `Max-Age=0` so the browser drops the cookie immediately.
|
|
605
|
+
*/
|
|
606
|
+
declare function appendDeleteCookieToHeaders(target: Headers, name: string, options?: {
|
|
607
|
+
path?: string;
|
|
608
|
+
}): void;
|
|
609
|
+
|
|
610
|
+
/**
|
|
611
|
+
* T2.4 — Custom error pages loader.
|
|
612
|
+
*
|
|
613
|
+
* Loads optional `.theokit/client/404.html` and `500.html` from disk so adapters
|
|
614
|
+
* (Node, CF, Vercel, Bun, Netlify, AWS Lambda, Deno) can pass them to the
|
|
615
|
+
* shared `sendError` pipeline.
|
|
616
|
+
*
|
|
617
|
+
* EC-9: caps file size at 1MB. Files beyond the limit are skipped with a
|
|
618
|
+
* console.warn and the default JSON error path is used.
|
|
619
|
+
*/
|
|
620
|
+
declare const MAX_ERROR_HTML_BYTES = 1048576;
|
|
621
|
+
interface CustomErrorPages {
|
|
622
|
+
custom404Html?: string;
|
|
623
|
+
custom500Html?: string;
|
|
624
|
+
}
|
|
625
|
+
/**
|
|
626
|
+
* Load `.theokit/client/{404,500}.html` from the given client directory.
|
|
627
|
+
* Returns object with both fields when present; missing pages remain undefined.
|
|
628
|
+
*/
|
|
629
|
+
declare function loadCustomErrorPages(clientDir: string): CustomErrorPages;
|
|
630
|
+
|
|
631
|
+
declare function serveStaticFile(req: IncomingMessage, res: ServerResponse, clientDir: string): boolean;
|
|
632
|
+
|
|
633
|
+
/**
|
|
634
|
+
* T3.2 — Web-Standards middleware runner for the `executeWebRequest` path.
|
|
635
|
+
*
|
|
636
|
+
* The Node request path (`http/execute.ts`) runs middleware via
|
|
637
|
+
* `runMiddlewareAndContext`, which is coupled to Node `req`/`res`. Per G8
|
|
638
|
+
* (Web Standards over Node APIs) the Web path needs a `Request`-shaped runner;
|
|
639
|
+
* this is it. Extracted to a sibling so `web-handler.ts` stays under its LoC
|
|
640
|
+
* budget (G6).
|
|
641
|
+
*
|
|
642
|
+
* Ordering invariant (EC-3): the caller runs the CSRF gate BEFORE invoking this
|
|
643
|
+
* runner, mirroring the Node path (CSRF stage precedes user middleware).
|
|
644
|
+
*
|
|
645
|
+
* NOTE (D4 / EC-12): this is its own middleware contract — `(request, context)`.
|
|
646
|
+
* Full semantic parity with the Node `defineMiddleware` contract is part of the
|
|
647
|
+
* deferred Node→Web pipeline convergence, not this slice.
|
|
648
|
+
*/
|
|
649
|
+
/** A Web-path middleware: mutate `context`, or return a `Response` to short-circuit. */
|
|
650
|
+
type WebMiddleware = (request: Request, context: Record<string, unknown>) => Promise<Response | undefined> | Response | undefined | void;
|
|
651
|
+
|
|
652
|
+
/**
|
|
653
|
+
* The route module exported by a `server/routes/*.ts` file (after T2.6 G6
|
|
654
|
+
* router lockdown). Method-named exports map to `defineRoute` results.
|
|
655
|
+
*/
|
|
656
|
+
type WebRouteModule = Partial<Record<'GET' | 'POST' | 'PUT' | 'PATCH' | 'DELETE', unknown>>;
|
|
657
|
+
/**
|
|
658
|
+
* Optional behavior knobs for `executeWebRequest`. Each knob defaults to
|
|
659
|
+
* the safe "no-op" stance so existing Phase A consumers (T1.2 fixture
|
|
660
|
+
* tests) keep working unchanged.
|
|
661
|
+
*
|
|
662
|
+
* **`csrfMode`** — the Web request gate runs `validateCsrfRequest` BEFORE
|
|
663
|
+
* method dispatch on state-changing methods (POST/PUT/PATCH/DELETE) and
|
|
664
|
+
* emits a `403 FORBIDDEN` envelope when the check fails. **Omitting the
|
|
665
|
+
* option enforces the gate**; only an explicit `'off'` disables it.
|
|
666
|
+
*
|
|
667
|
+
* The default used to be `'off'`, which meant a caller that never heard of
|
|
668
|
+
* the option served every state-changing request unchecked. A security
|
|
669
|
+
* control that has to be asked for is not a control, and this executor is
|
|
670
|
+
* the boundary the CF / Bun / Deno adapters are built on -- each of them a
|
|
671
|
+
* caller that would have had to remember. A route that legitimately takes
|
|
672
|
+
* third-party POSTs opts out by itself, per route, with `csrf: false` on
|
|
673
|
+
* `defineRoute`; `'off'` is for an application with another defense, such
|
|
674
|
+
* as one that ships no session cookie at all.
|
|
675
|
+
*
|
|
676
|
+
* Per the T5a.2 plan v1.0 § Phase B header-only leaves: csrf.ts is the
|
|
677
|
+
* first leaf to be migrated (slice 1/6); 5 more sibling leaves remain
|
|
678
|
+
* (csrf-multi-header, csrf-readiness-endpoint, csp-report, cors, cookies).
|
|
679
|
+
*/
|
|
680
|
+
interface ExecuteWebRequestOptions {
|
|
681
|
+
csrfMode?: 'off' | 'strict';
|
|
682
|
+
/**
|
|
683
|
+
* T3.1 — route params resolved upstream by `matchRoute` (e.g. `{ id: '42' }`
|
|
684
|
+
* for `/users/:id`). Threaded to the handler's `params` input and validated
|
|
685
|
+
* against `config.params` (Zod) when declared. Defaults to `{}` — callers
|
|
686
|
+
* that don't supply params keep the prior behavior (additive, backward-compat).
|
|
687
|
+
*/
|
|
688
|
+
params?: Record<string, string>;
|
|
689
|
+
/**
|
|
690
|
+
* T3.2 — Web-Standards middleware chain. Runs in order AFTER the CSRF gate
|
|
691
|
+
* (EC-3) and BEFORE the handler. A middleware returning a `Response`
|
|
692
|
+
* short-circuits (handler not reached); mutating `context` passes data to
|
|
693
|
+
* the handler. Omitted → zero overhead (handler runs directly).
|
|
694
|
+
*/
|
|
695
|
+
middleware?: readonly WebMiddleware[];
|
|
696
|
+
/**
|
|
697
|
+
* T5a.2 Phase E — body parser strategy.
|
|
698
|
+
*
|
|
699
|
+
* - `'inline'` (default): handle `application/json` + `text/*` only.
|
|
700
|
+
* Returns the parsed value (object for JSON, string for text). Other
|
|
701
|
+
* content-types (e.g., multipart) return `undefined`.
|
|
702
|
+
* - `'full'`: delegate to `parseWebRequestBody` for multipart support
|
|
703
|
+
* + per-file size caps + max-files cap (Web Standards `request.formData()`
|
|
704
|
+
* under the hood). Returns a `ParsedWebBody` object:
|
|
705
|
+
* `{ json?, fields, files }`. Multipart consumers MUST opt into this
|
|
706
|
+
* mode; JSON-only routes pay zero cost staying on `'inline'`.
|
|
707
|
+
*/
|
|
708
|
+
bodyParser?: 'inline' | 'full';
|
|
709
|
+
/**
|
|
710
|
+
* T5a.2 Phase G slice 1/N — plugin lifecycle hooks.
|
|
711
|
+
*
|
|
712
|
+
* Adapters (Node, CF Workers, Bun, Deno) wire `WebPluginContext`-shaped
|
|
713
|
+
* hooks at the executeWebRequest lifecycle. Lifecycle order mirrors the
|
|
714
|
+
* Fastify / Hono convention:
|
|
715
|
+
*
|
|
716
|
+
* 1. CSRF check (when opts.csrfMode === 'strict')
|
|
717
|
+
* 2. onRequest — earliest, before body parsing. Plugins can short-circuit
|
|
718
|
+
* by setting `ctx.response` (handler skipped; subsequent hooks see
|
|
719
|
+
* the short-circuit response).
|
|
720
|
+
* 3. body parse (inline OR full per opts.bodyParser)
|
|
721
|
+
* 4. preHandler — after body parsed, before handler runs. Same
|
|
722
|
+
* short-circuit semantic.
|
|
723
|
+
* 5. handler invocation
|
|
724
|
+
* 6. onResponse — after handler returns OR after a hook short-circuit.
|
|
725
|
+
* `ctx.response` is populated.
|
|
726
|
+
* 7. onError — fires if any of (handler, onRequest, preHandler) throws.
|
|
727
|
+
* `ctx.response` is the envelope-shaped error response built via
|
|
728
|
+
* serverErrorToEnvelope.
|
|
729
|
+
*
|
|
730
|
+
* `responseHeaders` is shared across hooks; the final Response merges
|
|
731
|
+
* them with the handler's Response headers (handler headers win on
|
|
732
|
+
* conflict; hook headers add new ones). Decorations made via
|
|
733
|
+
* `ctx.ctx[key] = value` persist across hooks (request-scoped state).
|
|
734
|
+
*
|
|
735
|
+
* `hooks: undefined` (default) → no plugin lifecycle, Phase A behavior
|
|
736
|
+
* preserved. Production consumers wire via the WebPluginRunner facade
|
|
737
|
+
* (a future Phase G slice).
|
|
738
|
+
*/
|
|
739
|
+
hooks?: {
|
|
740
|
+
onRequest?: readonly WebOnRequestHook[];
|
|
741
|
+
preHandler?: readonly WebPreHandlerHook[];
|
|
742
|
+
onResponse?: readonly WebOnResponseHook[];
|
|
743
|
+
onError?: readonly WebOnErrorHook[];
|
|
744
|
+
};
|
|
745
|
+
/**
|
|
746
|
+
* Stable request identifier propagated into hook contexts. Adapters
|
|
747
|
+
* resolve via traceparent / x-request-id / generated UUID (see
|
|
748
|
+
* `extractTraceIdFromRequest` from Phase C slice 1/2). Default:
|
|
749
|
+
* `globalThis.crypto.randomUUID()`.
|
|
750
|
+
*/
|
|
751
|
+
requestId?: string;
|
|
752
|
+
}
|
|
753
|
+
declare function executeWebRequest(request: Request, routeModule: WebRouteModule, opts?: ExecuteWebRequestOptions): Promise<Response>;
|
|
754
|
+
|
|
755
|
+
/**
|
|
756
|
+
* M33 — the SINGLE route-input validation pipeline, shared by the HTTP path (`web-handler.ts`
|
|
757
|
+
* `runHandler`) and the in-process caller (`in-process-caller.ts` `callProcedure`).
|
|
758
|
+
*
|
|
759
|
+
* Both surfaces validate the same three channels (`query`/`body`/`params`) against the same
|
|
760
|
+
* `RouteConfig` Zod schemas. Extracting the logic here means there is ONE validation pipeline
|
|
761
|
+
* (no duplication, no drift) — each caller only differs in how it MAPS a failure: the HTTP path
|
|
762
|
+
* emits a 400 Response, the in-process path throws a typed error.
|
|
763
|
+
*/
|
|
764
|
+
|
|
765
|
+
/** The three request-input channels a route may declare a Zod schema for. */
|
|
766
|
+
type RouteInputChannel = 'query' | 'body' | 'params';
|
|
767
|
+
/**
|
|
768
|
+
* The minimal structural shape the validator needs: the three optional channel schemas. Both
|
|
769
|
+
* `RouteConfig` (the 5-arity generic contract) and `WebRouteHandlerConfig` (the Web runtime shape)
|
|
770
|
+
* satisfy this — the validator depends only on the schemas, not the full route generic.
|
|
771
|
+
*/
|
|
772
|
+
interface RouteInputSchemas {
|
|
773
|
+
query?: z.ZodType;
|
|
774
|
+
body?: z.ZodType;
|
|
775
|
+
params?: z.ZodType;
|
|
776
|
+
}
|
|
777
|
+
/** Raw (pre-validation) channel values. A channel absent from the config passes through unchanged. */
|
|
778
|
+
interface RawRouteInput {
|
|
779
|
+
query?: unknown;
|
|
780
|
+
body?: unknown;
|
|
781
|
+
params?: unknown;
|
|
782
|
+
}
|
|
783
|
+
/** Discriminated result — each caller maps `ok:false` to its own surface (Response vs throw). */
|
|
784
|
+
type RouteInputValidation = {
|
|
785
|
+
ok: true;
|
|
786
|
+
query: unknown;
|
|
787
|
+
body: unknown;
|
|
788
|
+
params: unknown;
|
|
789
|
+
} | {
|
|
790
|
+
ok: false;
|
|
791
|
+
channel: RouteInputChannel;
|
|
792
|
+
error: z.ZodError;
|
|
793
|
+
};
|
|
794
|
+
/**
|
|
795
|
+
* Validate the three input channels against the route's declared Zod schemas. A channel with no
|
|
796
|
+
* declared schema passes its raw value through. First failing channel short-circuits (query → body
|
|
797
|
+
* → params order, matching `runHandler`).
|
|
798
|
+
*/
|
|
799
|
+
declare function validateRouteInput(config: RouteInputSchemas, raw: RawRouteInput): RouteInputValidation;
|
|
800
|
+
|
|
801
|
+
/**
|
|
802
|
+
* M33 Phase 1 — `callProcedure`, the in-process typed caller.
|
|
803
|
+
*
|
|
804
|
+
* The load-bearing seam for non-HTTP surfaces (TUI / Tauri / MCP-tools): invoke a route's shared
|
|
805
|
+
* logic with STRUCTURED input, WITHOUT going through the HTTP transport (no URL/body parsing, no
|
|
806
|
+
* middleware chain, no Response). It reuses the SAME Zod validation pipeline as the HTTP path
|
|
807
|
+
* (`validateRouteInput`) so there is no drift, and reuses the SAME `config.response` server-fault
|
|
808
|
+
* check. Failures throw typed errors (there is no HTTP status off-web).
|
|
809
|
+
*
|
|
810
|
+
* Prior art: tRPC `callProcedure` / `createCallerFactory`
|
|
811
|
+
*
|
|
812
|
+
* Design (ADR-0044 / blueprint §5.4): the AUTHOR passes structured input `{query?, body?, params?}`
|
|
813
|
+
* — never synthesizes a Request. A minimal in-process `Request` is provided to the handler ONLY so
|
|
814
|
+
* handlers that read `request.headers`/`request.url` still work (opencode's proven pattern); the
|
|
815
|
+
* input itself is NOT parsed from it.
|
|
816
|
+
*/
|
|
817
|
+
|
|
818
|
+
/** Structured input for an in-process procedure call — one object per declared channel. */
|
|
819
|
+
type ProcedureInput = RawRouteInput;
|
|
820
|
+
/**
|
|
821
|
+
* Thrown when structured input fails the route's Zod validation. The in-process analog of the HTTP
|
|
822
|
+
* 400 — carries the failing channel + the Zod issues (typed error, not a magic value; Rule 8).
|
|
823
|
+
*/
|
|
824
|
+
declare class ProcedureInputError extends Error {
|
|
825
|
+
readonly channel: RouteInputChannel;
|
|
826
|
+
readonly issues: z.core.$ZodIssue[];
|
|
827
|
+
constructor(channel: RouteInputChannel, error: z.ZodError);
|
|
828
|
+
}
|
|
829
|
+
/**
|
|
830
|
+
* Thrown when the handler's plain-object return drifts from `config.response` — a SERVER fault
|
|
831
|
+
* (the handler violated its own declared contract), mirroring the HTTP path's 500 as a throw.
|
|
832
|
+
*/
|
|
833
|
+
declare class ProcedureOutputError extends Error {
|
|
834
|
+
readonly issues: z.core.$ZodIssue[];
|
|
835
|
+
constructor(error: z.ZodError);
|
|
836
|
+
}
|
|
837
|
+
/**
|
|
838
|
+
* Invoke a route/procedure's handler in-process with structured, Zod-validated input.
|
|
839
|
+
*
|
|
840
|
+
* @param config the `RouteConfig` (what `route().build()` produces).
|
|
841
|
+
* @param input structured `{query?, body?, params?}` — validated by the route's schemas.
|
|
842
|
+
* @param ctx the typed run-context the handler receives (built by the CALLER — a TUI/Tauri/MCP
|
|
843
|
+
* surface supplies its own ctx factory; there is no HTTP middleware chain here).
|
|
844
|
+
* @returns the handler's result (validated against `config.response` when declared).
|
|
845
|
+
* @throws ProcedureInputError on invalid structured input (the off-web analog of a 400).
|
|
846
|
+
* @throws ProcedureOutputError on a handler output that drifts from `config.response` (server fault).
|
|
847
|
+
*/
|
|
848
|
+
declare function callProcedure(config: RouteConfig<z.ZodType, z.ZodType, z.ZodType>, input?: ProcedureInput, ctx?: unknown): Promise<unknown>;
|
|
849
|
+
|
|
850
|
+
interface UploadedFile {
|
|
851
|
+
fieldname: string;
|
|
852
|
+
filename: string;
|
|
853
|
+
encoding: string;
|
|
854
|
+
mimeType: string;
|
|
855
|
+
buffer: Buffer;
|
|
856
|
+
size: number;
|
|
857
|
+
}
|
|
858
|
+
interface ParsedBody {
|
|
859
|
+
fields: Record<string, string>;
|
|
860
|
+
files: UploadedFile[];
|
|
861
|
+
json?: unknown;
|
|
862
|
+
}
|
|
863
|
+
interface BodyParserOptions {
|
|
864
|
+
maxFileSize?: number;
|
|
865
|
+
maxFiles?: number;
|
|
866
|
+
maxFieldSize?: number;
|
|
867
|
+
}
|
|
868
|
+
declare class FileTooLargeError extends Error {
|
|
869
|
+
readonly truncatedFilenames: string[];
|
|
870
|
+
readonly maxFileSize: number;
|
|
871
|
+
readonly code = "FILE_TOO_LARGE";
|
|
872
|
+
readonly status = 413;
|
|
873
|
+
constructor(message: string, truncatedFilenames: string[], maxFileSize: number);
|
|
874
|
+
}
|
|
875
|
+
declare function parseRequestBody(req: IncomingMessage, options?: BodyParserOptions): Promise<ParsedBody>;
|
|
876
|
+
|
|
877
|
+
interface OpenApiDocsOptions {
|
|
878
|
+
/** Path to serve Scalar UI (default: '/api/docs'). */
|
|
879
|
+
docsPath?: string;
|
|
880
|
+
/** Path to serve the JSON spec (default: '/api/docs/openapi.json'). */
|
|
881
|
+
openapiJsonPath?: string;
|
|
882
|
+
/** Path to the spec file on disk (default: '.theokit/openapi.json'). */
|
|
883
|
+
specFilePath?: string;
|
|
884
|
+
/** Page title (default: 'API Reference'). */
|
|
885
|
+
pageTitle?: string;
|
|
886
|
+
/** Scalar CDN URL (default: jsdelivr). Must be HTTPS. */
|
|
887
|
+
cdnUrl?: string;
|
|
888
|
+
}
|
|
889
|
+
/**
|
|
890
|
+
* Creates a request handler that serves OpenAPI docs.
|
|
891
|
+
* Returns `null` for non-matching requests (passthrough).
|
|
892
|
+
*/
|
|
893
|
+
declare function createOpenApiHandler(opts?: OpenApiDocsOptions): (request: Request) => Response | null;
|
|
894
|
+
|
|
895
|
+
/**
|
|
896
|
+
* Action protocol — cross-boundary contract for `defineAction` + `useAction`.
|
|
897
|
+
*
|
|
898
|
+
* Per plan g3-server-actions-and-useaction v1.2 § Phase 0 / T0.1, ADRs D1 (encoding)
|
|
899
|
+
* + D6 (full dot-notation path) + D7 (PII mask) — types and runtime referenced
|
|
900
|
+
* by server (`server/http/action-execute.ts`, `server/define/define-action.ts`)
|
|
901
|
+
* and client (`@theokit/react/useAction`, `vite-plugin/actions-virtual-module`).
|
|
902
|
+
*
|
|
903
|
+
* Lives in `core/contracts/` per architecture.md v3.1 exception — cross-module
|
|
904
|
+
* deep imports ALLOWED for this file. Core depends on NOTHING intra-monorepo;
|
|
905
|
+
* `extractUniversalIssues` is implemented INLINE (NOT imported from `@theokit/sdk`)
|
|
906
|
+
* to honor dep-cruiser `core-depends-on-nothing` invariant (EC-1 absorbed).
|
|
907
|
+
*
|
|
908
|
+
* Field-key convention (D6 + EC-13): dot-notation full path. Nested objects use
|
|
909
|
+
* `'user.address.zip'`; array indices use `'items.0.name'` (NOT bracket
|
|
910
|
+
* `'items[0].name'`). Root-level errors (path = []) use empty string `''`
|
|
911
|
+
* (EC-7). Consumers needing bracket notation can write a small `dotToBracket`
|
|
912
|
+
* helper in userland.
|
|
913
|
+
*/
|
|
914
|
+
|
|
915
|
+
/**
|
|
916
|
+
* HTTP-status mapping per IANA HTTP Status Code Registry (subset relevant to
|
|
917
|
+
* action surface). VALIDATION_ERROR → 422 is preferred over Astro's BAD_REQUEST/400
|
|
918
|
+
* (more semantic for input-shape mismatch). PAYLOAD_TOO_LARGE → 413 covers EC-3
|
|
919
|
+
* (response-side size limit; request-side reuses standard 413).
|
|
920
|
+
*/
|
|
921
|
+
type ActionErrorCode = 'VALIDATION_ERROR' | 'BAD_REQUEST' | 'UNAUTHORIZED' | 'FORBIDDEN' | 'NOT_FOUND' | 'METHOD_NOT_ALLOWED' | 'CONFLICT' | 'CONTENT_TOO_LARGE' | 'PAYLOAD_TOO_LARGE' | 'UNSUPPORTED_MEDIA_TYPE' | 'TOO_MANY_REQUESTS' | 'INTERNAL_SERVER_ERROR';
|
|
922
|
+
/**
|
|
923
|
+
* Universal zod issue shape covering BOTH v3 (`z.ZodIssue`) and v4 (`$ZodIssue`).
|
|
924
|
+
* Duck-typed minimum surface: `{path, message}`. Implemented per EC-1 absorbed —
|
|
925
|
+
* consumers chain may ship either zod major; constructor accepts `unknown` and
|
|
926
|
+
* normalizes via `extractUniversalIssues`.
|
|
927
|
+
*/
|
|
928
|
+
interface UniversalZodIssue {
|
|
929
|
+
readonly path: readonly (string | number)[];
|
|
930
|
+
readonly message: string;
|
|
931
|
+
readonly code?: string;
|
|
932
|
+
}
|
|
933
|
+
/**
|
|
934
|
+
* `ActionError` — general server-side action failure. Discriminator `type` is
|
|
935
|
+
* literal `'TheoActionError'`; used by `ActionError.fromJson` to distinguish
|
|
936
|
+
* from `ActionInputError`.
|
|
937
|
+
*/
|
|
938
|
+
declare class ActionError extends Error {
|
|
939
|
+
readonly type: 'TheoActionError' | 'TheoActionInputError';
|
|
940
|
+
readonly code: ActionErrorCode;
|
|
941
|
+
readonly status: number;
|
|
942
|
+
constructor(params: {
|
|
943
|
+
code: ActionErrorCode;
|
|
944
|
+
message?: string;
|
|
945
|
+
stack?: string;
|
|
946
|
+
});
|
|
947
|
+
/**
|
|
948
|
+
* G5 T2.4 — canonical envelope view of the action error. Maps the G3
|
|
949
|
+
* ActionErrorCode to a canonical TheoErrorCode (VALIDATION_ERROR ↔
|
|
950
|
+
* UNPROCESSABLE_ENTITY, CONTENT_TOO_LARGE ↔ PAYLOAD_TOO_LARGE) so consumer
|
|
951
|
+
* UI / SDK code can switch on the unified envelope.
|
|
952
|
+
*
|
|
953
|
+
* Subclasses override to populate `ext` (see `ActionInputError.envelope`).
|
|
954
|
+
*/
|
|
955
|
+
get envelope(): TheoErrorEnvelope;
|
|
956
|
+
/**
|
|
957
|
+
* Translate G3 ActionErrorCode → canonical TheoErrorCode (blueprint
|
|
958
|
+
* Recommendations § "G3 ActionError becomes inaugural envelope user").
|
|
959
|
+
*/
|
|
960
|
+
static toTheoErrorCode(code: ActionErrorCode): TheoErrorCode;
|
|
961
|
+
static codeToStatus(code: ActionErrorCode): number;
|
|
962
|
+
static statusToCode(status: number): ActionErrorCode;
|
|
963
|
+
/**
|
|
964
|
+
* Parse a serialized error JSON back into the typed class hierarchy.
|
|
965
|
+
* Distinguishes `TheoActionInputError` (with `issues` array) from
|
|
966
|
+
* `TheoActionError` via the `type` discriminator. Falls back to
|
|
967
|
+
* `INTERNAL_SERVER_ERROR` for malformed bodies (non-object, missing
|
|
968
|
+
* `type`, unknown `code`).
|
|
969
|
+
*/
|
|
970
|
+
static fromJson(body: unknown): ActionError;
|
|
971
|
+
}
|
|
972
|
+
/**
|
|
973
|
+
* `ActionInputError` — validation failure with field-level mapping.
|
|
974
|
+
*
|
|
975
|
+
* `fields` is auto-derived from `issues`: for each issue, key = full
|
|
976
|
+
* dot-notation path (`'user.address.zip'`; root-level `path:[]` → `''`;
|
|
977
|
+
* array indices as numeric segments → `'items.0.name'`). Multiple messages
|
|
978
|
+
* for the same key accumulate; duplicate (path, message) tuples are deduped.
|
|
979
|
+
*/
|
|
980
|
+
declare class ActionInputError extends ActionError {
|
|
981
|
+
readonly type: "TheoActionInputError";
|
|
982
|
+
readonly issues: readonly UniversalZodIssue[];
|
|
983
|
+
readonly fields: Record<string, string[]>;
|
|
984
|
+
constructor(rawIssues: unknown);
|
|
985
|
+
/**
|
|
986
|
+
* G5 T2.4 — envelope view with ValidationFieldsExt populated from .fields.
|
|
987
|
+
* UI consumers can `switch (env.code)` on `UNPROCESSABLE_ENTITY` and read
|
|
988
|
+
* `(env.ext as ValidationFieldsExt).fields` for field-level rendering.
|
|
989
|
+
*/
|
|
990
|
+
get envelope(): TheoErrorEnvelope<ValidationFieldsExt>;
|
|
991
|
+
}
|
|
992
|
+
/**
|
|
993
|
+
* Normalize zod v3 (`z.ZodIssue`) and v4 (`$ZodIssue`) raw issues to
|
|
994
|
+
* `UniversalZodIssue[]` (EC-1 absorbed). Duck-typed on `{path, message}` —
|
|
995
|
+
* does NOT import zod types (`core/contracts/` depends on no intra-monorepo
|
|
996
|
+
* + zod is consumer-controlled across the boundary).
|
|
997
|
+
*
|
|
998
|
+
* Silently skips entries missing required fields or shape mismatches; returns
|
|
999
|
+
* empty array on non-array input.
|
|
1000
|
+
*/
|
|
1001
|
+
declare function extractUniversalIssues(raw: unknown): UniversalZodIssue[];
|
|
1002
|
+
/**
|
|
1003
|
+
* Type guard for `ActionError` (and its subclass `ActionInputError`). True
|
|
1004
|
+
* iff the value is an instance of `ActionError`. Use `isInputError` to
|
|
1005
|
+
* narrow specifically to validation failures.
|
|
1006
|
+
*/
|
|
1007
|
+
declare function isActionError(value: unknown): value is ActionError;
|
|
1008
|
+
/**
|
|
1009
|
+
* Type guard narrowing to `ActionInputError`. Requires `instanceof` check
|
|
1010
|
+
* (not duck-typing on `type`) to prevent attacker-controlled JSON from
|
|
1011
|
+
* being mistaken for a real error instance.
|
|
1012
|
+
*/
|
|
1013
|
+
declare function isInputError(value: unknown): value is ActionInputError;
|
|
1014
|
+
/**
|
|
1015
|
+
* `ActionResult<TData, TError>` — discriminated union returned by client-side
|
|
1016
|
+
* action invocation. Either `{data, error: undefined}` (success) or
|
|
1017
|
+
* `{data: undefined, error}` (failure). Mirrors Astro `SafeResult` shape.
|
|
1018
|
+
*/
|
|
1019
|
+
type ActionResult<TData = unknown, TError extends ActionError = ActionError> = {
|
|
1020
|
+
data: TData;
|
|
1021
|
+
error: undefined;
|
|
1022
|
+
} | {
|
|
1023
|
+
data: undefined;
|
|
1024
|
+
error: TError;
|
|
1025
|
+
};
|
|
1026
|
+
/**
|
|
1027
|
+
* `SerializedActionResult` — wire-shape emitted by `serializeActionResult`
|
|
1028
|
+
* in `server/http/serialize-action-result.ts` (T1.3). Discriminator `type`
|
|
1029
|
+
* distinguishes data (devalue-encoded), error (JSON), and empty (204) cases.
|
|
1030
|
+
*/
|
|
1031
|
+
type SerializedActionResult = {
|
|
1032
|
+
type: 'data';
|
|
1033
|
+
status: number;
|
|
1034
|
+
contentType: 'application/json+devalue';
|
|
1035
|
+
body: string;
|
|
1036
|
+
} | {
|
|
1037
|
+
type: 'error';
|
|
1038
|
+
status: number;
|
|
1039
|
+
contentType: 'application/json';
|
|
1040
|
+
body: string;
|
|
1041
|
+
} | {
|
|
1042
|
+
type: 'empty';
|
|
1043
|
+
status: 204;
|
|
1044
|
+
};
|
|
1045
|
+
/**
|
|
1046
|
+
* `ActionManifestEntry` — per-action metadata emitted by `action-scan.ts`
|
|
1047
|
+
* (T1.4) into `.theokit/actions-manifest.json`. Consumed by virtual module
|
|
1048
|
+
* `@theo/actions` (T3.1) and G4 devtools "Actions" tab (T5.1).
|
|
1049
|
+
*/
|
|
1050
|
+
interface ActionManifestEntry {
|
|
1051
|
+
readonly name: string;
|
|
1052
|
+
readonly filePath: string;
|
|
1053
|
+
readonly urlPath: string;
|
|
1054
|
+
readonly accept: 'form' | 'json';
|
|
1055
|
+
readonly hasInput: boolean;
|
|
1056
|
+
}
|
|
1057
|
+
|
|
1058
|
+
export { createServerContext as $, ActionError as A, BATCH_PATH as B, type CookieOptions as C, type SerializedActionResult as D, type ExecuteActionOptions as E, FileTooLargeError as F, TRACE_PARENT_HEADER as G, type HandleBatchOptions as H, TheoError as I, type TheoTransformer as J, type UploadedFile as K, appendCookieToHeaders as L, MAX_ERROR_HTML_BYTES as M, NotFoundError as N, type OpenApiDocsOptions as O, type ParsedBody as P, appendDeleteCookieToHeaders as Q, type RawRouteInput as R, STRIPPED_HEADERS as S, TRACE_HEADER as T, type UniversalZodIssue as U, callProcedure as V, type W3CTraceContext as W, createCorsHandler as X, createCorsWebHandler as Y, createOpenApiHandler as Z, _resetMiddlewareCacheForTests as _, type ActionErrorCode as a, deleteCookie as a0, envelopeCodeToStatus as a1, executeAction as a2, executeRoute as a3, executeWebRequest as a4, extractTraceId as a5, extractTraceIdFromRequest as a6, extractUniversalIssues as a7, extractW3CTraceContext as a8, fromUnknown as a9, getCookie as aa, getCookieFromRequest as ab, handleBatchRequest as ac, handleRequestError as ad, handleWebRequestError as ae, isActionError as af, isInputError as ag, jsonTransformer as ah, loadCustomErrorPages as ai, matchesOrigin as aj, parseCookieHeader as ak, parseRequestBody as al, parseTraceparent as am, parseTraceparentContext as an, resolveTransformer as ao, runMiddlewareAndContext as ap, sendError as aq, sendJson as ar, serializeCookie as as, serveStaticFile as at, serverErrorToEnvelope as au, setCookie as av, superjsonTransformer as aw, validateRouteInput as ax, ActionInputError as b, type ActionManifestEntry as c, type ActionResult as d, type BatchExecuteFn as e, BatchPathConflictError as f, type BatchPayload as g, type BatchRequestItem as h, type BatchResponse as i, type BatchResultItem as j, type BodyParserOptions as k, type CorsConfig as l, type CorsHandler as m, type CorsOrigin as n, type CorsWebHandler as o, type CustomErrorPages as p, type ExecuteRouteContext as q, type MiddlewareResult as r, type ProcedureInput as s, ProcedureInputError as t, ProcedureOutputError as u, type RouteInputChannel as v, type RouteInputSchemas as w, type RouteInputValidation as x, type SendErrorInput as y, type SendErrorOptions as z };
|