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.
Files changed (327) hide show
  1. package/README.md +1 -0
  2. package/dist/{actions-virtual-module-YQXRSSMW.js → actions-virtual-module-5WBVSDOM.js} +22 -12
  3. package/dist/actions-virtual-module-5WBVSDOM.js.map +1 -0
  4. package/dist/{actions-virtual-module-LB4NGONI.js → actions-virtual-module-ZYLMNW6K.js} +13 -8
  5. package/dist/{actions-virtual-module-LB4NGONI.js.map → actions-virtual-module-ZYLMNW6K.js.map} +1 -1
  6. package/dist/adapters/agent-mount.d.ts +127 -0
  7. package/dist/adapters/agent-mount.js +24 -0
  8. package/dist/adapters/security-headers.d.ts +132 -0
  9. package/dist/adapters/security-headers.js +64 -0
  10. package/dist/adapters/security-headers.js.map +1 -0
  11. package/dist/adapters/web-shim.d.ts +100 -13
  12. package/dist/adapters/web-shim.js +158 -54
  13. package/dist/adapters/web-shim.js.map +1 -1
  14. package/dist/agent-GKUEL6OH.js +15 -0
  15. package/dist/agent-scan-BZa-pagG.d.ts +16 -0
  16. package/dist/{app-typed-client-GHO3EWZK.js → app-typed-client-4LAIEGFX.js} +23 -13
  17. package/dist/app-typed-client-4LAIEGFX.js.map +1 -0
  18. package/dist/{app-typed-client-G3J5G7E5.js → app-typed-client-DQM3Y6YY.js} +14 -9
  19. package/dist/app-typed-client-DQM3Y6YY.js.map +1 -0
  20. package/dist/aws-lambda-VKMYUMP2.js +261 -0
  21. package/dist/aws-lambda-VKMYUMP2.js.map +1 -0
  22. package/dist/{build-WU6AKKIB.js → build-FLX6VF7Q.js} +71 -26
  23. package/dist/build-FLX6VF7Q.js.map +1 -0
  24. package/dist/{bun-33RD6K7O.js → bun-L7PP6ID5.js} +105 -13
  25. package/dist/bun-L7PP6ID5.js.map +1 -0
  26. package/dist/{check-45NKUVSQ.js → check-GIPZBFTX.js} +2 -2
  27. package/dist/{chunk-KD5G3YXI.js → chunk-2AMLGJJA.js} +35 -9
  28. package/dist/chunk-2AMLGJJA.js.map +1 -0
  29. package/dist/chunk-3PBAN2YE.js +146 -0
  30. package/dist/chunk-3PBAN2YE.js.map +1 -0
  31. package/dist/{chunk-HBU2GIMZ.js → chunk-3QPVEJ7D.js} +15 -9
  32. package/dist/chunk-3QPVEJ7D.js.map +1 -0
  33. package/dist/{chunk-47CINLWF.js → chunk-44J2ANQC.js} +2 -2
  34. package/dist/{chunk-IEES3CHD.js → chunk-47MM2JUK.js} +8 -2
  35. package/dist/chunk-47MM2JUK.js.map +1 -0
  36. package/dist/chunk-4X6H2BXP.js +108 -0
  37. package/dist/chunk-4X6H2BXP.js.map +1 -0
  38. package/dist/{chunk-A7JBF5FO.js → chunk-5K4TDLRG.js} +8 -5
  39. package/dist/chunk-5K4TDLRG.js.map +1 -0
  40. package/dist/chunk-5YPXXSYY.js +181 -0
  41. package/dist/chunk-5YPXXSYY.js.map +1 -0
  42. package/dist/{chunk-YGAXV5HR.js → chunk-6J4JWHDJ.js} +191 -112
  43. package/dist/chunk-6J4JWHDJ.js.map +1 -0
  44. package/dist/chunk-72DMJBXI.js +424 -0
  45. package/dist/chunk-72DMJBXI.js.map +1 -0
  46. package/dist/chunk-7PM6K5EV.js +513 -0
  47. package/dist/chunk-7PM6K5EV.js.map +1 -0
  48. package/dist/{chunk-MTEWLGVY.js → chunk-BPYMC7SU.js} +4 -48
  49. package/dist/chunk-BPYMC7SU.js.map +1 -0
  50. package/dist/chunk-BU6RJPPJ.js +421 -0
  51. package/dist/chunk-BU6RJPPJ.js.map +1 -0
  52. package/dist/{chunk-FB2HBNIC.js → chunk-BX6EUYHU.js} +6 -2
  53. package/dist/chunk-BX6EUYHU.js.map +1 -0
  54. package/dist/{chunk-BIVCP6X5.js → chunk-C62IZEJI.js} +465 -202
  55. package/dist/chunk-C62IZEJI.js.map +1 -0
  56. package/dist/chunk-D4VP2QPR.js +16 -0
  57. package/dist/chunk-D4VP2QPR.js.map +1 -0
  58. package/dist/{chunk-J5MXCGKA.js → chunk-DHAD2O3S.js} +6 -6
  59. package/dist/chunk-DHAD2O3S.js.map +1 -0
  60. package/dist/chunk-E43VJ3E5.js +188 -0
  61. package/dist/chunk-E43VJ3E5.js.map +1 -0
  62. package/dist/chunk-EVZKNA2W.js +110 -0
  63. package/dist/chunk-EVZKNA2W.js.map +1 -0
  64. package/dist/chunk-FD4ZDTQ6.js +181 -0
  65. package/dist/chunk-FD4ZDTQ6.js.map +1 -0
  66. package/dist/chunk-FDOOBTXJ.js +17 -0
  67. package/dist/chunk-FDOOBTXJ.js.map +1 -0
  68. package/dist/chunk-FH3SQR6P.js +275 -0
  69. package/dist/chunk-FH3SQR6P.js.map +1 -0
  70. package/dist/chunk-HJHGTFEJ.js +23 -0
  71. package/dist/chunk-HJHGTFEJ.js.map +1 -0
  72. package/dist/{chunk-LXAESF4Y.js → chunk-HK4AZBKX.js} +7 -4
  73. package/dist/chunk-HK4AZBKX.js.map +1 -0
  74. package/dist/{chunk-T5C46IIU.js → chunk-HWBRS4DZ.js} +28 -269
  75. package/dist/chunk-HWBRS4DZ.js.map +1 -0
  76. package/dist/chunk-IRQGAC4L.js +52 -0
  77. package/dist/chunk-IRQGAC4L.js.map +1 -0
  78. package/dist/{chunk-FNTLKHZ7.js → chunk-JDN5SAAD.js} +7 -4
  79. package/dist/chunk-JDN5SAAD.js.map +1 -0
  80. package/dist/{chunk-GXEX4CBH.js → chunk-JIKNR5LX.js} +673 -484
  81. package/dist/chunk-JIKNR5LX.js.map +1 -0
  82. package/dist/{chunk-GRI4XHBJ.js → chunk-JWRCZIA4.js} +266 -108
  83. package/dist/chunk-JWRCZIA4.js.map +1 -0
  84. package/dist/{chunk-E576KYYT.js → chunk-KI4DOTN4.js} +25 -2
  85. package/dist/chunk-KI4DOTN4.js.map +1 -0
  86. package/dist/{chunk-ZB7D62OA.js → chunk-KUZVRJ7M.js} +3 -3
  87. package/dist/chunk-L4VFNFDL.js +248 -0
  88. package/dist/chunk-L4VFNFDL.js.map +1 -0
  89. package/dist/chunk-M2WC5MF7.js +127 -0
  90. package/dist/chunk-M2WC5MF7.js.map +1 -0
  91. package/dist/{chunk-O3JIAU3V.js → chunk-MCTC6HSE.js} +157 -103
  92. package/dist/chunk-MCTC6HSE.js.map +1 -0
  93. package/dist/{chunk-PXFXSFJL.js → chunk-NZ5JU6D3.js} +9 -9
  94. package/dist/{chunk-YRBR424R.js → chunk-OAUI273L.js} +338 -165
  95. package/dist/chunk-OAUI273L.js.map +1 -0
  96. package/dist/chunk-OGLS76RN.js +43 -0
  97. package/dist/chunk-OGLS76RN.js.map +1 -0
  98. package/dist/{chunk-7LVM22VG.js → chunk-OQCRCXCP.js} +6 -6
  99. package/dist/chunk-OQCRCXCP.js.map +1 -0
  100. package/dist/{chunk-OLGPYOLO.js → chunk-P6OS7652.js} +5 -2
  101. package/dist/chunk-P6OS7652.js.map +1 -0
  102. package/dist/chunk-Q5L5EGWZ.js +26 -0
  103. package/dist/chunk-Q5L5EGWZ.js.map +1 -0
  104. package/dist/{chunk-S433N3CT.js → chunk-QTHVHNJJ.js} +6 -36
  105. package/dist/chunk-QTHVHNJJ.js.map +1 -0
  106. package/dist/chunk-RPET332G.js +84 -0
  107. package/dist/chunk-RPET332G.js.map +1 -0
  108. package/dist/{chunk-646CA6RV.js → chunk-RQW5YMH7.js} +12 -4
  109. package/dist/chunk-RQW5YMH7.js.map +1 -0
  110. package/dist/{chunk-XALU5LCU.js → chunk-RWNYIU6A.js} +550 -146
  111. package/dist/chunk-RWNYIU6A.js.map +1 -0
  112. package/dist/chunk-SL7YUHPV.js +111 -0
  113. package/dist/chunk-SL7YUHPV.js.map +1 -0
  114. package/dist/chunk-U5PWXS3J.js +39 -0
  115. package/dist/chunk-U5PWXS3J.js.map +1 -0
  116. package/dist/chunk-ULDCFL2O.js +273 -0
  117. package/dist/chunk-ULDCFL2O.js.map +1 -0
  118. package/dist/{chunk-RWNSW4FM.js → chunk-UMNXCU3K.js} +12 -6
  119. package/dist/{chunk-RWNSW4FM.js.map → chunk-UMNXCU3K.js.map} +1 -1
  120. package/dist/chunk-VI7ZANB3.js +193 -0
  121. package/dist/chunk-VI7ZANB3.js.map +1 -0
  122. package/dist/chunk-VQPHPQ5L.js +14 -0
  123. package/dist/chunk-VQPHPQ5L.js.map +1 -0
  124. package/dist/chunk-WNJTJRM6.js +147 -0
  125. package/dist/chunk-WNJTJRM6.js.map +1 -0
  126. package/dist/chunk-WOBSEO75.js +790 -0
  127. package/dist/chunk-WOBSEO75.js.map +1 -0
  128. package/dist/{chunk-BMHS4WAN.js → chunk-XS7EX55U.js} +156 -42
  129. package/dist/chunk-XS7EX55U.js.map +1 -0
  130. package/dist/chunk-YN4W7LCX.js +31 -0
  131. package/dist/chunk-YN4W7LCX.js.map +1 -0
  132. package/dist/chunk-YSJOZEI6.js +1 -0
  133. package/dist/{chunk-JA2ZAT5Q.js → chunk-Z4PJMZLM.js} +2 -2
  134. package/dist/chunk-Z4PJMZLM.js.map +1 -0
  135. package/dist/{chunk-7VPQHEAJ.js → chunk-ZNZISJDZ.js} +6 -2
  136. package/dist/chunk-ZNZISJDZ.js.map +1 -0
  137. package/dist/chunk-ZWN3AODA.js +11 -0
  138. package/dist/chunk-ZWN3AODA.js.map +1 -0
  139. package/dist/cli/index.js +25 -10
  140. package/dist/cli/index.js.map +1 -1
  141. package/dist/client/core.d.ts +1 -1
  142. package/dist/client/core.js +2 -0
  143. package/dist/client/core.js.map +1 -1
  144. package/dist/client/index.d.ts +44 -10
  145. package/dist/client/index.js +35 -0
  146. package/dist/client/index.js.map +1 -1
  147. package/dist/cloudflare-SIG42OIW.js +335 -0
  148. package/dist/cloudflare-SIG42OIW.js.map +1 -0
  149. package/dist/config-support-WQHQIJTA.js +104 -0
  150. package/dist/config-support-WQHQIJTA.js.map +1 -0
  151. package/dist/{csrf-BBrEZSBW.d.ts → csrf-Dgot9qSM.d.ts} +1 -1
  152. package/dist/deno-deploy-LQAYOOPW.js +196 -0
  153. package/dist/deno-deploy-LQAYOOPW.js.map +1 -0
  154. package/dist/{dev-MUWJAZRD.js → dev-ANDSEVLB.js} +28 -18
  155. package/dist/dev-ANDSEVLB.js.map +1 -0
  156. package/dist/{dev-emit-GWD6IXV7.js → dev-emit-BFNMDCPB.js} +5 -5
  157. package/dist/{dev-emit-NBT6JD7R.js → dev-emit-MVAJAFGX.js} +5 -3
  158. package/dist/dev-emit-MVAJAFGX.js.map +1 -0
  159. package/dist/engine-singleton-X4R7AZBJ.js +315 -0
  160. package/dist/engine-singleton-X4R7AZBJ.js.map +1 -0
  161. package/dist/{generate-Y3GWM57K.js → generate-EN6EDITF.js} +43 -4
  162. package/dist/generate-EN6EDITF.js.map +1 -0
  163. package/dist/index-CzxtQcnp.d.ts +1058 -0
  164. package/dist/index.d.ts +4 -0
  165. package/dist/index.js +24 -13
  166. package/dist/index.js.map +1 -1
  167. package/dist/{info-XW7HGUPH.js → info-Y55RWS42.js} +8 -6
  168. package/dist/{info-XW7HGUPH.js.map → info-Y55RWS42.js.map} +1 -1
  169. package/dist/{internal-api-V5L65YSJ.js → internal-api-IP35YU3G.js} +22 -12
  170. package/dist/{internal-api-WEOSTMSN.js → internal-api-OPU456AT.js} +30 -16
  171. package/dist/internal-api-OPU456AT.js.map +1 -0
  172. package/dist/load-config-4ATXQUN3.js +16 -0
  173. package/dist/match-DmGgxjIU.d.ts +44 -0
  174. package/dist/{mcp-ULUFJNSZ.js → mcp-5LLNAGKA.js} +7 -7
  175. package/dist/netlify-C2IRCZKI.js +245 -0
  176. package/dist/netlify-C2IRCZKI.js.map +1 -0
  177. package/dist/node-OSVPYQ3D.js +10 -0
  178. package/dist/nonce-BXt7Qu_C.d.ts +31 -0
  179. package/dist/observability-bootstrap-MZMSOE66.js +15 -0
  180. package/dist/{openapi-HZXR335W.js → openapi-VFPEZSRI.js} +13 -11
  181. package/dist/{openapi-HZXR335W.js.map → openapi-VFPEZSRI.js.map} +1 -1
  182. package/dist/{plugin-runner-BFEcgtmJ.d.ts → plugin-runner-BVMOSxvb.d.ts} +1 -1
  183. package/dist/{plugin-types-D69-lJZ9.d.ts → plugin-types-BUVfUQ0V.d.ts} +13 -1
  184. package/dist/preview-GHPT2EQ5.js +23 -0
  185. package/dist/preview-GHPT2EQ5.js.map +1 -0
  186. package/dist/provider-resolver-Dx6QuWrw.d.ts +128 -0
  187. package/dist/registry-KBZDCFVQ.js +23 -0
  188. package/dist/route-config-Cm_ZMA1C.d.ts +72 -0
  189. package/dist/route-policy-BxOycCDq.d.ts +65 -0
  190. package/dist/router/element-scroll-restoration.d.ts +28 -0
  191. package/dist/router/element-scroll-restoration.js +96 -0
  192. package/dist/router/element-scroll-restoration.js.map +1 -0
  193. package/dist/{routes-OLNQX7CT.js → routes-BPLU3ISV.js} +11 -9
  194. package/dist/{routes-OLNQX7CT.js.map → routes-BPLU3ISV.js.map} +1 -1
  195. package/dist/{scan-7MJC6PYU.js → scan-YJEE4KQK.js} +2 -2
  196. package/dist/{schema-ZO3OSWVG.js → schema-SOAD43RQ.js} +7 -5
  197. package/dist/schemas-4AXHQMV3.js +25 -0
  198. package/dist/schemas-4AXHQMV3.js.map +1 -0
  199. package/dist/security-headers-Ccj7ncNx.d.ts +129 -0
  200. package/dist/server/agent/index.d.ts +2 -90
  201. package/dist/server/agent/index.js +1 -1
  202. package/dist/server/auth/index.d.ts +2 -21
  203. package/dist/server/auth/index.js +3 -2
  204. package/dist/server/cron/index.js +4 -3
  205. package/dist/server/define/index.d.ts +51 -57
  206. package/dist/server/define/index.js +10 -1
  207. package/dist/server/http/index.d.ts +7 -5
  208. package/dist/server/http/index.js +56 -12
  209. package/dist/server/index.d.ts +47 -439
  210. package/dist/server/index.js +119 -201
  211. package/dist/server/index.js.map +1 -1
  212. package/dist/server/jobs/index.js +4 -3
  213. package/dist/server/observability/index.d.ts +109 -35
  214. package/dist/server/observability/index.js +10 -7
  215. package/dist/server/plugins/index.d.ts +3 -3
  216. package/dist/server/scan/index.d.ts +47 -12
  217. package/dist/server/scan/index.js +13 -4
  218. package/dist/server/security/index.d.ts +61 -103
  219. package/dist/server/security/index.js +15 -6
  220. package/dist/server/webhook/index.d.ts +90 -3
  221. package/dist/server/webhook/index.js +12 -2
  222. package/dist/server-boundary-6B4ZQUY7.js +148 -0
  223. package/dist/server-boundary-6B4ZQUY7.js.map +1 -0
  224. package/dist/server-boundary-7VZQRPPX.js +133 -0
  225. package/dist/server-boundary-7VZQRPPX.js.map +1 -0
  226. package/dist/{services-typed-client-PSAGRPFF.js → services-typed-client-XGT5SUUN.js} +2 -2
  227. package/dist/{start-KR2JJR7K.js → start-UZDMOT7I.js} +342 -111
  228. package/dist/start-UZDMOT7I.js.map +1 -0
  229. package/dist/{static-M2W4HUWS.js → static-SVDWIOXJ.js} +24 -13
  230. package/dist/static-SVDWIOXJ.js.map +1 -0
  231. package/dist/{theo-cloud-XAHWOUFK.js → theo-cloud-3ET4G5T6.js} +9 -2
  232. package/dist/theo-cloud-3ET4G5T6.js.map +1 -0
  233. package/dist/vercel-BMCQKCWE.js +277 -0
  234. package/dist/vercel-BMCQKCWE.js.map +1 -0
  235. package/dist/vite-plugin/index.js +24 -13
  236. package/dist/vite-plugin-VKCT2LF2.js +42 -0
  237. package/dist/vite-plugin-VKCT2LF2.js.map +1 -0
  238. package/package.json +19 -6
  239. package/dist/actions-virtual-module-YQXRSSMW.js.map +0 -1
  240. package/dist/agent-7JJW3TPB.js +0 -15
  241. package/dist/app-typed-client-G3J5G7E5.js.map +0 -1
  242. package/dist/app-typed-client-GHO3EWZK.js.map +0 -1
  243. package/dist/aws-lambda-CYNDGU5O.js +0 -172
  244. package/dist/aws-lambda-CYNDGU5O.js.map +0 -1
  245. package/dist/build-WU6AKKIB.js.map +0 -1
  246. package/dist/bun-33RD6K7O.js.map +0 -1
  247. package/dist/chunk-646CA6RV.js.map +0 -1
  248. package/dist/chunk-6E5WKMDS.js +0 -67
  249. package/dist/chunk-6E5WKMDS.js.map +0 -1
  250. package/dist/chunk-6GGWS7J3.js +0 -91
  251. package/dist/chunk-6GGWS7J3.js.map +0 -1
  252. package/dist/chunk-7LVM22VG.js.map +0 -1
  253. package/dist/chunk-7VPQHEAJ.js.map +0 -1
  254. package/dist/chunk-A7JBF5FO.js.map +0 -1
  255. package/dist/chunk-AM3QABW5.js +0 -161
  256. package/dist/chunk-AM3QABW5.js.map +0 -1
  257. package/dist/chunk-BIVCP6X5.js.map +0 -1
  258. package/dist/chunk-BMHS4WAN.js.map +0 -1
  259. package/dist/chunk-E576KYYT.js.map +0 -1
  260. package/dist/chunk-FB2HBNIC.js.map +0 -1
  261. package/dist/chunk-FNTLKHZ7.js.map +0 -1
  262. package/dist/chunk-GRI4XHBJ.js.map +0 -1
  263. package/dist/chunk-GVW5EKEU.js +0 -422
  264. package/dist/chunk-GVW5EKEU.js.map +0 -1
  265. package/dist/chunk-GXEX4CBH.js.map +0 -1
  266. package/dist/chunk-HBU2GIMZ.js.map +0 -1
  267. package/dist/chunk-IEES3CHD.js.map +0 -1
  268. package/dist/chunk-J5MXCGKA.js.map +0 -1
  269. package/dist/chunk-JA2ZAT5Q.js.map +0 -1
  270. package/dist/chunk-KD5G3YXI.js.map +0 -1
  271. package/dist/chunk-LNVMHQ2Z.js +0 -54
  272. package/dist/chunk-LNVMHQ2Z.js.map +0 -1
  273. package/dist/chunk-LXAESF4Y.js.map +0 -1
  274. package/dist/chunk-MTEWLGVY.js.map +0 -1
  275. package/dist/chunk-O3JIAU3V.js.map +0 -1
  276. package/dist/chunk-OJLL4YD6.js +0 -403
  277. package/dist/chunk-OJLL4YD6.js.map +0 -1
  278. package/dist/chunk-OLGPYOLO.js.map +0 -1
  279. package/dist/chunk-S433N3CT.js.map +0 -1
  280. package/dist/chunk-T5C46IIU.js.map +0 -1
  281. package/dist/chunk-U267AOWS.js +0 -28
  282. package/dist/chunk-U267AOWS.js.map +0 -1
  283. package/dist/chunk-UW2TEAGR.js +0 -77
  284. package/dist/chunk-UW2TEAGR.js.map +0 -1
  285. package/dist/chunk-WPJOTQA5.js +0 -1
  286. package/dist/chunk-XALU5LCU.js.map +0 -1
  287. package/dist/chunk-XR74JD4M.js +0 -457
  288. package/dist/chunk-XR74JD4M.js.map +0 -1
  289. package/dist/chunk-YGAXV5HR.js.map +0 -1
  290. package/dist/chunk-YRBR424R.js.map +0 -1
  291. package/dist/cloudflare-KYUWCEPL.js +0 -122
  292. package/dist/cloudflare-KYUWCEPL.js.map +0 -1
  293. package/dist/deno-deploy-CCTB7HGS.js +0 -107
  294. package/dist/deno-deploy-CCTB7HGS.js.map +0 -1
  295. package/dist/dev-MUWJAZRD.js.map +0 -1
  296. package/dist/dev-emit-NBT6JD7R.js.map +0 -1
  297. package/dist/generate-Y3GWM57K.js.map +0 -1
  298. package/dist/index-BEtEv6ZH.d.ts +0 -575
  299. package/dist/load-config-VKD6LKWU.js +0 -14
  300. package/dist/match-CfbEFRG4.d.ts +0 -26
  301. package/dist/netlify-AFMDNKT4.js +0 -150
  302. package/dist/netlify-AFMDNKT4.js.map +0 -1
  303. package/dist/node-ZJQEJSP3.js +0 -10
  304. package/dist/registry-GKR3EWRW.js +0 -23
  305. package/dist/start-KR2JJR7K.js.map +0 -1
  306. package/dist/static-M2W4HUWS.js.map +0 -1
  307. package/dist/theo-cloud-XAHWOUFK.js.map +0 -1
  308. package/dist/vercel-SRS2DH6O.js +0 -133
  309. package/dist/vercel-SRS2DH6O.js.map +0 -1
  310. package/dist/vite-plugin-VPJFD4HK.js +0 -36
  311. /package/dist/{chunk-WPJOTQA5.js.map → adapters/agent-mount.js.map} +0 -0
  312. /package/dist/{agent-7JJW3TPB.js.map → agent-GKUEL6OH.js.map} +0 -0
  313. /package/dist/{check-45NKUVSQ.js.map → check-GIPZBFTX.js.map} +0 -0
  314. /package/dist/{chunk-47CINLWF.js.map → chunk-44J2ANQC.js.map} +0 -0
  315. /package/dist/{chunk-ZB7D62OA.js.map → chunk-KUZVRJ7M.js.map} +0 -0
  316. /package/dist/{chunk-PXFXSFJL.js.map → chunk-NZ5JU6D3.js.map} +0 -0
  317. /package/dist/{internal-api-WEOSTMSN.js.map → chunk-YSJOZEI6.js.map} +0 -0
  318. /package/dist/{dev-emit-GWD6IXV7.js.map → dev-emit-BFNMDCPB.js.map} +0 -0
  319. /package/dist/{internal-api-V5L65YSJ.js.map → internal-api-IP35YU3G.js.map} +0 -0
  320. /package/dist/{load-config-VKD6LKWU.js.map → load-config-4ATXQUN3.js.map} +0 -0
  321. /package/dist/{mcp-ULUFJNSZ.js.map → mcp-5LLNAGKA.js.map} +0 -0
  322. /package/dist/{node-ZJQEJSP3.js.map → node-OSVPYQ3D.js.map} +0 -0
  323. /package/dist/{scan-7MJC6PYU.js.map → observability-bootstrap-MZMSOE66.js.map} +0 -0
  324. /package/dist/{registry-GKR3EWRW.js.map → registry-KBZDCFVQ.js.map} +0 -0
  325. /package/dist/{schema-ZO3OSWVG.js.map → scan-YJEE4KQK.js.map} +0 -0
  326. /package/dist/{vite-plugin-VPJFD4HK.js.map → schema-SOAD43RQ.js.map} +0 -0
  327. /package/dist/{services-typed-client-PSAGRPFF.js.map → services-typed-client-XGT5SUUN.js.map} +0 -0
@@ -5,15 +5,17 @@ import {
5
5
  createQueueClient
6
6
  } from "./chunk-47FFT43U.js";
7
7
  import {
8
+ RequestBodyConsumedError,
8
9
  parseRequestBody,
9
10
  warnOnce
10
- } from "./chunk-KD5G3YXI.js";
11
+ } from "./chunk-72DMJBXI.js";
11
12
  import {
12
13
  scanMiddlewares
13
- } from "./chunk-FB2HBNIC.js";
14
+ } from "./chunk-BX6EUYHU.js";
14
15
  import {
15
- enforceCsrf
16
- } from "./chunk-OLGPYOLO.js";
16
+ enforceCsrf,
17
+ validateCsrfRequest
18
+ } from "./chunk-P6OS7652.js";
17
19
  import {
18
20
  envelopeCodeToStatus
19
21
  } from "./chunk-ACKBVBUI.js";
@@ -21,6 +23,13 @@ import {
21
23
  TheoError,
22
24
  serverErrorToEnvelope
23
25
  } from "./chunk-IZ3TIL6K.js";
26
+ import {
27
+ WEB_SHAPED_MIDDLEWARE
28
+ } from "./chunk-D4VP2QPR.js";
29
+ import {
30
+ evaluateRoutePolicy,
31
+ subjectFromContext
32
+ } from "./chunk-YN4W7LCX.js";
24
33
 
25
34
  // src/core/contracts/action-protocol.ts
26
35
  var CODE_TO_STATUS = {
@@ -188,6 +197,20 @@ function isInputError(value) {
188
197
  return value instanceof ActionInputError;
189
198
  }
190
199
 
200
+ // src/core/contracts/client-safe-error.ts
201
+ var INTERNAL_CODES = /* @__PURE__ */ new Set(["INTERNAL_ERROR", "INTERNAL_SERVER_ERROR"]);
202
+ var GENERIC_INTERNAL_MESSAGE = "Internal server error";
203
+ function redacts(code) {
204
+ return INTERNAL_CODES.has(code) && process.env.NODE_ENV === "production";
205
+ }
206
+ function clientSafeErrorMessage(code, message) {
207
+ return redacts(code) ? GENERIC_INTERNAL_MESSAGE : message;
208
+ }
209
+ function clientSafeErrorEnvelope(envelope) {
210
+ if (!redacts(envelope.code)) return envelope;
211
+ return { code: envelope.code, message: GENERIC_INTERNAL_MESSAGE };
212
+ }
213
+
191
214
  // src/server/http/send-response.ts
192
215
  function sendJson(res, data, status = 200, transformer) {
193
216
  const body = transformer ? transformer.serialize(data) : JSON.stringify(data);
@@ -197,6 +220,9 @@ function sendJson(res, data, status = 200, transformer) {
197
220
  });
198
221
  res.end(body);
199
222
  }
223
+ function oneLine(value) {
224
+ return value.replace(/[\r\n]/g, "\\n");
225
+ }
200
226
  function sendError(res, codeOrInput, message, status, issues, requestId, options) {
201
227
  let code;
202
228
  if (typeof codeOrInput === "string") {
@@ -211,9 +237,9 @@ function sendError(res, codeOrInput, message, status, issues, requestId, options
211
237
  requestId = codeOrInput.requestId;
212
238
  options = codeOrInput.options;
213
239
  }
214
- const errorMessage = code === "INTERNAL_ERROR" && process.env.NODE_ENV === "production" ? "Internal server error" : message;
240
+ const errorMessage = clientSafeErrorMessage(code, message);
215
241
  if (code === "INTERNAL_ERROR") {
216
- console.error(`[${requestId ?? "no-id"}] ${message}`);
242
+ console.error(`[${oneLine(requestId ?? "no-id")}] ${oneLine(message)}`);
217
243
  }
218
244
  if (status === 404 && options?.custom404Html) {
219
245
  const body = options.custom404Html;
@@ -247,74 +273,6 @@ function sendError(res, codeOrInput, message, status, issues, requestId, options
247
273
  );
248
274
  }
249
275
 
250
- // src/server/http/middleware-runner.ts
251
- import { existsSync } from "fs";
252
- import { join } from "path";
253
- var middlewareCache = /* @__PURE__ */ new Map();
254
- function _resetMiddlewareCacheForTests() {
255
- middlewareCache.clear();
256
- }
257
- function getCachedScan(serverDir) {
258
- let cached = middlewareCache.get(serverDir);
259
- if (!cached) {
260
- const singleFilePath = join(serverDir, "middleware.ts");
261
- cached = {
262
- singleFilePath,
263
- singleFileExists: existsSync(singleFilePath),
264
- dirMiddlewares: scanMiddlewares(serverDir)
265
- };
266
- middlewareCache.set(serverDir, cached);
267
- }
268
- return cached;
269
- }
270
- async function runOneMiddleware(mw, req, res) {
271
- const state = { nextCalled: false };
272
- await mw(req, res, () => {
273
- state.nextCalled = true;
274
- });
275
- return state;
276
- }
277
- async function runMiddlewareAndContext(req, res, loadModule, serverDir) {
278
- const { singleFilePath, singleFileExists, dirMiddlewares } = getCachedScan(serverDir);
279
- const dirExists = dirMiddlewares.length > 0;
280
- if (singleFileExists && dirExists) {
281
- throw new Error(
282
- "Ambiguous middleware configuration: found both server/middleware.ts and server/middleware/ directory. Use one or the other, not both."
283
- );
284
- }
285
- if (dirExists) {
286
- for (const mwPath of dirMiddlewares) {
287
- const mod = await loadModule(mwPath);
288
- const mw = mod.default;
289
- if (typeof mw !== "function") continue;
290
- const { nextCalled } = await runOneMiddleware(mw, req, res);
291
- if (!nextCalled || res.writableEnded) {
292
- return { ctx: {}, aborted: true };
293
- }
294
- }
295
- }
296
- if (singleFileExists) {
297
- const mod = await loadModule(singleFilePath);
298
- const mw = mod.default;
299
- if (typeof mw === "function") {
300
- const { nextCalled } = await runOneMiddleware(mw, req, res);
301
- if (!nextCalled || res.writableEnded) {
302
- return { ctx: {}, aborted: true };
303
- }
304
- }
305
- }
306
- let ctx = {};
307
- const contextPath = join(serverDir, "context.ts");
308
- if (existsSync(contextPath)) {
309
- const mod = await loadModule(contextPath);
310
- const createContext = mod.createContext;
311
- if (typeof createContext === "function") {
312
- ctx = await createContext({ request: req, response: res });
313
- }
314
- }
315
- return { ctx, aborted: false };
316
- }
317
-
318
276
  // src/server/http/node-request.ts
319
277
  import { Readable } from "stream";
320
278
  function pickHeaderString(value) {
@@ -358,6 +316,13 @@ function incomingMessageToWebRequest(req) {
358
316
  ...{ duplex: "half" }
359
317
  });
360
318
  }
319
+ function createWebRequestSource(req) {
320
+ let converted;
321
+ return {
322
+ method: (req.method ?? "GET").toUpperCase(),
323
+ toRequest: () => converted ??= incomingMessageToWebRequest(req)
324
+ };
325
+ }
361
326
  function incomingMessageToHandlerRequest(req) {
362
327
  return new Request(synthesizeAbsoluteUrl(req), {
363
328
  method: (req.method ?? "GET").toUpperCase(),
@@ -365,17 +330,27 @@ function incomingMessageToHandlerRequest(req) {
365
330
  });
366
331
  }
367
332
 
368
- // src/core/contracts/auth-error-guard.ts
369
- function isAuthRequiredError(err) {
370
- if (err == null || typeof err !== "object") return false;
371
- const e = err;
372
- return e.code === "AUTH_REQUIRED" && e.status === 401;
373
- }
374
-
375
- // src/server/security/csrf-warn-dispatch.ts
376
- function dispatchCsrfWarn(payload) {
377
- const key = `${payload.event}:${payload.method}:${payload.path ?? ""}`;
378
- warnOnce(key, payload);
333
+ // src/server/http/validate-route-input.ts
334
+ function validateRouteInput(config, raw) {
335
+ let query = raw.query;
336
+ if (config.query !== void 0) {
337
+ const parsed = config.query.safeParse(raw.query);
338
+ if (!parsed.success) return { ok: false, channel: "query", error: parsed.error };
339
+ query = parsed.data;
340
+ }
341
+ let body = raw.body;
342
+ if (config.body !== void 0) {
343
+ const parsed = config.body.safeParse(raw.body);
344
+ if (!parsed.success) return { ok: false, channel: "body", error: parsed.error };
345
+ body = parsed.data;
346
+ }
347
+ let params = raw.params;
348
+ if (config.params !== void 0) {
349
+ const parsed = config.params.safeParse(raw.params);
350
+ if (!parsed.success) return { ok: false, channel: "params", error: parsed.error };
351
+ params = parsed.data;
352
+ }
353
+ return { ok: true, query, body, params };
379
354
  }
380
355
 
381
356
  // src/server/http/execute-stages.ts
@@ -393,6 +368,10 @@ async function parseQueryAndBody(req, res, requestId) {
393
368
  body = void 0;
394
369
  }
395
370
  } catch (err) {
371
+ if (err instanceof RequestBodyConsumedError) {
372
+ sendError(res, "INTERNAL_ERROR", err.message, err.status, void 0, requestId);
373
+ return { ok: false };
374
+ }
396
375
  const message = err.message;
397
376
  const status = message.includes("Unsupported Content-Type") ? 415 : 400;
398
377
  sendError(res, "VALIDATION_ERROR", message, status, void 0, requestId);
@@ -452,8 +431,457 @@ function runZodValidation(routeConfig, res, requestId, input) {
452
431
  return { ok: true, data: { query, body, params } };
453
432
  }
454
433
 
455
- // src/server/http/execute.ts
434
+ // src/server/http/web-middleware-runner.ts
435
+ async function runWebMiddleware(request, middleware, context) {
436
+ for (const mw of middleware) {
437
+ const result = await mw(request, context);
438
+ if (result instanceof Response) return result;
439
+ }
440
+ return void 0;
441
+ }
442
+
443
+ // src/server/web-handler.ts
444
+ function searchParamsToObject(params) {
445
+ const out = {};
446
+ for (const [key, value] of params.entries()) {
447
+ if (!Object.hasOwn(out, key)) {
448
+ out[key] = value;
449
+ continue;
450
+ }
451
+ const existing = out[key];
452
+ if (Array.isArray(existing)) {
453
+ existing.push(value);
454
+ } else {
455
+ out[key] = [existing, value];
456
+ }
457
+ }
458
+ return out;
459
+ }
460
+ async function parseBodyInline(request) {
461
+ if (request.method === "GET" || request.method === "HEAD") return void 0;
462
+ const contentType = request.headers.get("content-type") ?? "";
463
+ if (contentType.includes("application/json")) {
464
+ const text = await request.text();
465
+ if (text.length === 0) return void 0;
466
+ try {
467
+ return JSON.parse(text);
468
+ } catch {
469
+ return void 0;
470
+ }
471
+ }
472
+ if (contentType.startsWith("text/")) {
473
+ const text = await request.text();
474
+ return text.length === 0 ? void 0 : text;
475
+ }
476
+ return void 0;
477
+ }
478
+ async function parseBodyFull(request) {
479
+ if (request.method === "GET" || request.method === "HEAD") return void 0;
480
+ const { parseWebRequestBody } = await import("./body-parser-web-4Z2QTPDU.js");
481
+ try {
482
+ const parsed = await parseWebRequestBody(request);
483
+ if (parsed.json === void 0 && Object.keys(parsed.fields).length === 0 && parsed.files.length === 0) {
484
+ return void 0;
485
+ }
486
+ return parsed;
487
+ } catch {
488
+ return void 0;
489
+ }
490
+ }
491
+ function validationErrorResponse(zodError, field) {
492
+ const envelope = {
493
+ code: "BAD_REQUEST",
494
+ message: `Validation failed: ${field}`,
495
+ ext: {
496
+ fields: zodError.issues.map((issue) => ({
497
+ path: issue.path.join("."),
498
+ message: issue.message
499
+ }))
500
+ }
501
+ };
502
+ return new Response(JSON.stringify(envelope), {
503
+ status: 400,
504
+ headers: { "content-type": "application/json" }
505
+ });
506
+ }
507
+ async function runHandler(config, request, bodyParser = "inline", paramsInput = {}, context = {}) {
508
+ const url = new URL(request.url);
509
+ const queryRaw = searchParamsToObject(url.searchParams);
510
+ const bodyRaw = bodyParser === "full" ? await parseBodyFull(request) : await parseBodyInline(request);
511
+ const paramsRaw = paramsInput;
512
+ const validated = validateRouteInput(config, {
513
+ query: queryRaw,
514
+ body: bodyRaw,
515
+ params: paramsRaw
516
+ });
517
+ if (!validated.ok) {
518
+ return { ok: false, response: validationErrorResponse(validated.error, validated.channel) };
519
+ }
520
+ const { query, body, params } = validated;
521
+ const decision = await evaluateRoutePolicy(config.policy, {
522
+ subject: subjectFromContext(context),
523
+ query,
524
+ body,
525
+ params
526
+ });
527
+ if (!decision.allowed) {
528
+ return { ok: false, response: accessDeniedResponse(decision.reason) };
529
+ }
530
+ const result = await config.handler({ query, body, params, request, context });
531
+ return validateResponseOutput(config.response, result) ?? { ok: true, result };
532
+ }
533
+ function validateResponseOutput(response, result) {
534
+ const validatable = result !== void 0 && result !== null && !(result instanceof Response);
535
+ if (!validatable || !isZodLike(response)) return void 0;
536
+ const parsed = response.safeParse(result);
537
+ if (parsed.success) return { ok: true, result: parsed.data };
538
+ const err = new TheoError({
539
+ code: "INTERNAL_SERVER_ERROR",
540
+ message: "response validation failed",
541
+ ext: { issues: parsed.error?.issues }
542
+ });
543
+ return { ok: false, response: handlerErrorResponse(err) };
544
+ }
545
+ function toResponse(result, status) {
546
+ if (result === void 0) {
547
+ return new Response(null, { status: 204 });
548
+ }
549
+ if (result instanceof Response) {
550
+ return result;
551
+ }
552
+ return new Response(JSON.stringify(result), {
553
+ status: status ?? 200,
554
+ headers: { "content-type": "application/json" }
555
+ });
556
+ }
557
+ function handlerErrorResponse(err) {
558
+ const envelope = clientSafeErrorEnvelope(serverErrorToEnvelope(err));
559
+ const status = envelopeCodeToStatus(envelope.code);
560
+ return new Response(JSON.stringify(envelope), {
561
+ status,
562
+ headers: { "content-type": "application/json" }
563
+ });
564
+ }
456
565
  var CSRF_PROTECTED_METHODS = /* @__PURE__ */ new Set(["POST", "PUT", "PATCH", "DELETE"]);
566
+ function mergeHookHeaders(response, hookHeaders) {
567
+ if ([...hookHeaders].length === 0) return response;
568
+ const merged = new Headers(response.headers);
569
+ for (const [k, v] of hookHeaders.entries()) {
570
+ if (k.toLowerCase() === "set-cookie") continue;
571
+ if (!merged.has(k)) merged.set(k, v);
572
+ }
573
+ for (const sc of hookHeaders.getSetCookie()) {
574
+ merged.append("Set-Cookie", sc);
575
+ }
576
+ return new Response(response.body, {
577
+ status: response.status,
578
+ statusText: response.statusText,
579
+ headers: merged
580
+ });
581
+ }
582
+ function methodNotAllowedResponse(method) {
583
+ const envelope = {
584
+ code: "METHOD_NOT_ALLOWED",
585
+ message: `Method ${method} not allowed`
586
+ };
587
+ return new Response(JSON.stringify(envelope), {
588
+ status: 405,
589
+ headers: { "content-type": "application/json" }
590
+ });
591
+ }
592
+ function shouldEnforceCsrf(method, config, csrfMode) {
593
+ if ((csrfMode ?? "strict") === "off") return false;
594
+ if (!CSRF_PROTECTED_METHODS.has(method)) return false;
595
+ return config?.csrf !== false;
596
+ }
597
+ function accessDeniedResponse(reason) {
598
+ const envelope = {
599
+ code: "FORBIDDEN",
600
+ message: `Access denied: ${reason}`
601
+ };
602
+ return new Response(JSON.stringify({ error: envelope }), {
603
+ status: 403,
604
+ headers: { "Content-Type": "application/json" }
605
+ });
606
+ }
607
+ function csrfFailedResponse(reason) {
608
+ const envelope = {
609
+ code: "FORBIDDEN",
610
+ message: `CSRF check failed: ${reason}`
611
+ };
612
+ return new Response(JSON.stringify(envelope), {
613
+ status: 403,
614
+ headers: { "content-type": "application/json" }
615
+ });
616
+ }
617
+ async function executeWebRequest(request, routeModule, opts = {}) {
618
+ const method = request.method.toUpperCase();
619
+ const config = routeModule[method];
620
+ if (opts.hooks === void 0) {
621
+ if (config === void 0 || typeof config.handler !== "function") {
622
+ return methodNotAllowedResponse(method);
623
+ }
624
+ if (shouldEnforceCsrf(method, config, opts.csrfMode)) {
625
+ const csrfCheck = validateCsrfRequest(request);
626
+ if (!csrfCheck.valid) return csrfFailedResponse(csrfCheck.reason);
627
+ }
628
+ try {
629
+ const context = {};
630
+ if (opts.middleware?.length) {
631
+ const shortCircuit = await runWebMiddleware(request, opts.middleware, context);
632
+ if (shortCircuit) return shortCircuit;
633
+ }
634
+ const outcome = await runHandler(
635
+ config,
636
+ request,
637
+ opts.bodyParser ?? "inline",
638
+ opts.params ?? {},
639
+ context
640
+ );
641
+ if (!outcome.ok) return outcome.response;
642
+ return toResponse(outcome.result, config.status);
643
+ } catch (err) {
644
+ return handlerErrorResponse(err);
645
+ }
646
+ }
647
+ return runWithHooks(request, config, opts, opts.hooks);
648
+ }
649
+ async function runPreHandlerPipeline(hookCtx, request, config, opts, hooks) {
650
+ const method = request.method.toUpperCase();
651
+ const runList = async (list) => {
652
+ for (const hook of list) {
653
+ if (hookCtx.response !== void 0) return;
654
+ await hook(hookCtx);
655
+ }
656
+ };
657
+ if (hooks.onRequest) await runList(hooks.onRequest);
658
+ if (hookCtx.response === void 0 && shouldEnforceCsrf(method, config, opts.csrfMode)) {
659
+ const csrfCheck = validateCsrfRequest(request);
660
+ if (!csrfCheck.valid) hookCtx.response = csrfFailedResponse(csrfCheck.reason);
661
+ }
662
+ if (hookCtx.response === void 0 && hooks.preHandler) {
663
+ await runList(hooks.preHandler);
664
+ }
665
+ if (hookCtx.response === void 0) {
666
+ await runHandlerStage(hookCtx, request, config, opts, method);
667
+ }
668
+ }
669
+ async function runHandlerStage(hookCtx, request, config, opts, method) {
670
+ if (config === void 0 || typeof config.handler !== "function") {
671
+ hookCtx.response = methodNotAllowedResponse(method);
672
+ return;
673
+ }
674
+ if (opts.middleware?.length) {
675
+ const shortCircuit = await runWebMiddleware(request, opts.middleware, hookCtx.ctx);
676
+ if (shortCircuit) {
677
+ hookCtx.response = shortCircuit;
678
+ return;
679
+ }
680
+ }
681
+ const outcome = await runHandler(
682
+ config,
683
+ request,
684
+ opts.bodyParser ?? "inline",
685
+ opts.params ?? {},
686
+ hookCtx.ctx
687
+ );
688
+ hookCtx.response = outcome.ok ? toResponse(outcome.result, config.status) : outcome.response;
689
+ }
690
+ async function runWithHooks(request, config, opts, hooks) {
691
+ const hookCtx = {
692
+ request,
693
+ responseHeaders: new Headers(),
694
+ ctx: {},
695
+ requestId: opts.requestId ?? globalThis.crypto.randomUUID()
696
+ };
697
+ try {
698
+ await runPreHandlerPipeline(hookCtx, request, config, opts, hooks);
699
+ if (hooks.onResponse) {
700
+ for (const hook of hooks.onResponse) {
701
+ await hook(hookCtx);
702
+ }
703
+ }
704
+ const finalResponse = hookCtx.response ?? new Response(
705
+ JSON.stringify({ code: "INTERNAL_SERVER_ERROR", message: "No response built" }),
706
+ {
707
+ status: 500,
708
+ headers: { "content-type": "application/json" }
709
+ }
710
+ );
711
+ return mergeHookHeaders(finalResponse, hookCtx.responseHeaders);
712
+ } catch (err) {
713
+ return runErrorHooks(err, hookCtx, hooks.onError);
714
+ }
715
+ }
716
+ async function runErrorHooks(err, hookCtx, onError) {
717
+ const errorResponse = handlerErrorResponse(err);
718
+ if (onError !== void 0) {
719
+ const errorCtx = {
720
+ ...hookCtx,
721
+ response: errorResponse,
722
+ error: err
723
+ };
724
+ for (const hook of onError) {
725
+ try {
726
+ await hook(errorCtx);
727
+ } catch {
728
+ }
729
+ }
730
+ }
731
+ return mergeHookHeaders(errorResponse, hookCtx.responseHeaders);
732
+ }
733
+
734
+ // src/server/http/middleware-runner.ts
735
+ import { existsSync } from "fs";
736
+ import { join } from "path";
737
+
738
+ // src/server/http/node-web-adapter.ts
739
+ async function writeWebResponseToServerResponse(response, res) {
740
+ const setCookies = response.headers.getSetCookie();
741
+ if (setCookies.length > 0) {
742
+ res.setHeader("Set-Cookie", setCookies);
743
+ }
744
+ const otherHeaders = {};
745
+ for (const [key, value] of response.headers.entries()) {
746
+ if (key.toLowerCase() === "set-cookie") continue;
747
+ otherHeaders[key] = value;
748
+ }
749
+ res.writeHead(response.status, response.statusText, otherHeaders);
750
+ if (response.body === null) {
751
+ res.end();
752
+ return;
753
+ }
754
+ const reader = response.body.getReader();
755
+ try {
756
+ for (; ; ) {
757
+ const { done, value } = await reader.read();
758
+ if (done) break;
759
+ res.write(value);
760
+ }
761
+ res.end();
762
+ } finally {
763
+ reader.releaseLock();
764
+ }
765
+ }
766
+
767
+ // src/server/http/middleware-runner.ts
768
+ var middlewareCache = /* @__PURE__ */ new Map();
769
+ function _resetMiddlewareCacheForTests() {
770
+ middlewareCache.clear();
771
+ }
772
+ function getCachedScan(serverDir) {
773
+ let cached = middlewareCache.get(serverDir);
774
+ if (!cached) {
775
+ const singleFilePath = join(serverDir, "middleware.ts");
776
+ cached = {
777
+ singleFilePath,
778
+ singleFileExists: existsSync(singleFilePath),
779
+ dirMiddlewares: scanMiddlewares(serverDir)
780
+ };
781
+ middlewareCache.set(serverDir, cached);
782
+ }
783
+ return cached;
784
+ }
785
+ async function runWebShapedMiddleware(mw, req, res, context) {
786
+ const request = createWebRequestSource(req).toRequest();
787
+ const result = await mw(request, context);
788
+ if (!(result instanceof Response)) return { shortCircuited: false };
789
+ await writeWebResponseToServerResponse(result, res);
790
+ return { shortCircuited: true };
791
+ }
792
+ function isWebShaped(mw) {
793
+ return WEB_SHAPED_MIDDLEWARE in mw;
794
+ }
795
+ async function runScannedMiddleware(mw, req, res, context) {
796
+ if (isWebShaped(mw)) {
797
+ const { shortCircuited } = await runWebShapedMiddleware(mw, req, res, context);
798
+ return { aborted: shortCircuited };
799
+ }
800
+ const { nextCalled } = await runOneMiddleware(mw, req, res);
801
+ return { aborted: !nextCalled || res.writableEnded };
802
+ }
803
+ async function runOneMiddleware(mw, req, res) {
804
+ const state = { nextCalled: false };
805
+ await mw(req, res, () => {
806
+ state.nextCalled = true;
807
+ });
808
+ return state;
809
+ }
810
+ async function runMiddlewareAndContext(req, res, loadModule, serverDir) {
811
+ const { singleFilePath, singleFileExists, dirMiddlewares } = getCachedScan(serverDir);
812
+ const dirExists = dirMiddlewares.length > 0;
813
+ const middlewareCtx = {};
814
+ if (singleFileExists && dirExists) {
815
+ throw new Error(
816
+ "Ambiguous middleware configuration: found both server/middleware.ts and server/middleware/ directory. Use one or the other, not both."
817
+ );
818
+ }
819
+ if (dirExists) {
820
+ for (const mwPath of dirMiddlewares) {
821
+ const mod = await loadModule(mwPath);
822
+ const mw = mod.default;
823
+ if (typeof mw !== "function") continue;
824
+ const { aborted } = await runScannedMiddleware(mw, req, res, middlewareCtx);
825
+ if (aborted) return { ctx: middlewareCtx, aborted: true };
826
+ }
827
+ }
828
+ if (singleFileExists) {
829
+ const mod = await loadModule(singleFilePath);
830
+ const mw = mod.default;
831
+ if (typeof mw === "function") {
832
+ const { aborted } = await runScannedMiddleware(mw, req, res, middlewareCtx);
833
+ if (aborted) return { ctx: middlewareCtx, aborted: true };
834
+ }
835
+ }
836
+ const factoryCtx = await createServerContext(req, res, loadModule, serverDir);
837
+ if (factoryCtx === null || typeof factoryCtx !== "object") {
838
+ return { ctx: middlewareCtx, aborted: false };
839
+ }
840
+ return { ctx: { ...middlewareCtx, ...factoryCtx }, aborted: false };
841
+ }
842
+ async function createServerContext(req, res, loadModule, serverDir) {
843
+ const contextPath = join(serverDir, "context.ts");
844
+ if (!existsSync(contextPath)) return {};
845
+ const mod = await loadModule(contextPath);
846
+ const createContext = mod.createContext;
847
+ if (typeof createContext !== "function") return {};
848
+ return await createContext({ request: req, response: res });
849
+ }
850
+
851
+ // src/core/contracts/auth-error-guard.ts
852
+ function isAuthRequiredError(err) {
853
+ if (err == null || typeof err !== "object") return false;
854
+ const e = err;
855
+ return e.code === "AUTH_REQUIRED" && e.status === 401;
856
+ }
857
+
858
+ // src/server/security/csrf-warn-dispatch.ts
859
+ function dispatchCsrfWarn(payload) {
860
+ const key = `${payload.event}:${payload.method}:${payload.path ?? ""}`;
861
+ warnOnce(key, payload);
862
+ }
863
+
864
+ // src/server/http/execute.ts
865
+ var CSRF_PROTECTED_METHODS2 = /* @__PURE__ */ new Set(["POST", "PUT", "PATCH", "DELETE"]);
866
+ async function waitForDrain(res) {
867
+ if (typeof res.once !== "function") return;
868
+ await new Promise((resolve) => {
869
+ let settled = false;
870
+ const finish = () => {
871
+ if (settled) return;
872
+ settled = true;
873
+ if (typeof res.off === "function") {
874
+ res.off("drain", finish);
875
+ res.off("close", finish);
876
+ res.off("error", finish);
877
+ }
878
+ resolve();
879
+ };
880
+ res.once("drain", finish);
881
+ res.once("close", finish);
882
+ res.once("error", finish);
883
+ });
884
+ }
457
885
  async function pipeWebStreamToResponse(body, res, ctx) {
458
886
  const reader = body.getReader();
459
887
  try {
@@ -461,7 +889,7 @@ async function pipeWebStreamToResponse(body, res, ctx) {
461
889
  while (!done) {
462
890
  const chunk = await reader.read();
463
891
  done = chunk.done;
464
- if (!done) res.write(chunk.value);
892
+ if (!done && res.write(chunk.value) === false) await waitForDrain(res);
465
893
  }
466
894
  } catch (streamErr) {
467
895
  warnOnce(`stream-error:${ctx.routePath}:${ctx.method}`, {
@@ -477,12 +905,15 @@ async function pipeWebStreamToResponse(body, res, ctx) {
477
905
  } catch {
478
906
  }
479
907
  }
908
+ res.destroy(streamErr instanceof Error ? streamErr : new Error(String(streamErr)));
909
+ return false;
480
910
  } finally {
481
911
  try {
482
912
  reader.releaseLock();
483
913
  } catch {
484
914
  }
485
915
  }
916
+ return true;
486
917
  }
487
918
  async function executeRoute(ctx) {
488
919
  const {
@@ -562,7 +993,7 @@ async function executeRoute(ctx) {
562
993
  return;
563
994
  }
564
995
  const routeOptOut = typeof routeConfig === "object" && routeConfig.csrf === false;
565
- if (CSRF_PROTECTED_METHODS.has(method) && !routeOptOut) {
996
+ if (CSRF_PROTECTED_METHODS2.has(method) && !routeOptOut) {
566
997
  const decision = enforceCsrf(
567
998
  req,
568
999
  csrfMode,
@@ -598,6 +1029,23 @@ async function executeRoute(ctx) {
598
1029
  if (preResult.shortCircuited) return;
599
1030
  }
600
1031
  const callableHandler = handler;
1032
+ const accessDecision = await evaluateRoutePolicy(rc.policy, {
1033
+ subject: subjectFromContext(ctx2),
1034
+ query,
1035
+ body,
1036
+ params
1037
+ });
1038
+ if (!accessDecision.allowed) {
1039
+ sendError(
1040
+ res,
1041
+ "FORBIDDEN",
1042
+ `Access denied: ${accessDecision.reason}`,
1043
+ 403,
1044
+ void 0,
1045
+ requestId
1046
+ );
1047
+ return;
1048
+ }
601
1049
  const handlerResult = await callableHandler({ query, body, params, request: webRequest, ctx: ctx2 });
602
1050
  if (handlerResult === void 0 || handlerResult === null) {
603
1051
  sendJson(res, null, rc.status ?? 204, transformer);
@@ -614,8 +1062,9 @@ async function executeRoute(ctx) {
614
1062
  res.setHeader("Set-Cookie", setCookies);
615
1063
  }
616
1064
  res.writeHead(handlerResult.status, headersBag);
1065
+ let bodyCompleted = true;
617
1066
  if (handlerResult.body) {
618
- await pipeWebStreamToResponse(handlerResult.body, res, {
1067
+ bodyCompleted = await pipeWebStreamToResponse(handlerResult.body, res, {
619
1068
  buildPluginCtx,
620
1069
  ctx: ctx2,
621
1070
  method,
@@ -624,7 +1073,7 @@ async function executeRoute(ctx) {
624
1073
  routePath: route.routePath
625
1074
  });
626
1075
  }
627
- res.end();
1076
+ if (bodyCompleted) res.end();
628
1077
  if (pluginRunner) await pluginRunner.runOnResponse(buildPluginCtx(ctx2));
629
1078
  return;
630
1079
  }
@@ -979,7 +1428,7 @@ function enforceCsrfForAction(req, res, ctx) {
979
1428
  );
980
1429
  return false;
981
1430
  }
982
- async function runPreHandlerPipeline(p) {
1431
+ async function runPreHandlerPipeline2(p) {
983
1432
  if (p.serverDir) {
984
1433
  const result = await runMiddlewareAndContext(p.req, p.res, p.loadModule, p.serverDir);
985
1434
  if (result.aborted) return false;
@@ -1103,7 +1552,7 @@ async function executeActionWithOptions(opts) {
1103
1552
  req,
1104
1553
  res
1105
1554
  };
1106
- if (!await runPreHandlerPipeline(pipeline)) return;
1555
+ if (!await runPreHandlerPipeline2(pipeline)) return;
1107
1556
  ctx = pipeline.ctx;
1108
1557
  const bodyOutcome = await readActionBody(req, res, requestId, actionConfig);
1109
1558
  if (!bodyOutcome.ok) return;
@@ -1373,50 +1822,6 @@ function createCorsWebHandler(config) {
1373
1822
  };
1374
1823
  }
1375
1824
 
1376
- // src/server/http/trace-context.ts
1377
- var TRACE_HEADER = "x-trace-id";
1378
- var TRACE_PARENT_HEADER = "traceparent";
1379
- var REQUEST_ID_HEADER = "x-request-id";
1380
- var TRACEPARENT_RE = /^00-([0-9a-f]{32})-([0-9a-f]{16})-[0-9a-f]{2}$/;
1381
- function parseTraceparent(value) {
1382
- if (!value) return null;
1383
- const m = TRACEPARENT_RE.exec(value);
1384
- if (!m) return null;
1385
- const traceId = m[1];
1386
- if (/^0+$/.test(traceId)) return null;
1387
- return traceId;
1388
- }
1389
- function pickHeader(value) {
1390
- if (Array.isArray(value)) {
1391
- for (const v of value) {
1392
- if (typeof v === "string" && v.length > 0) return v;
1393
- }
1394
- return null;
1395
- }
1396
- if (typeof value === "string" && value.length > 0) return value;
1397
- return null;
1398
- }
1399
- function resolveTraceIdFromHeaders(traceparent, requestId) {
1400
- if (traceparent !== null) {
1401
- const parsed = parseTraceparent(traceparent);
1402
- if (parsed !== null) return parsed;
1403
- }
1404
- if (requestId !== null) return requestId;
1405
- return globalThis.crypto.randomUUID();
1406
- }
1407
- function extractTraceId(req) {
1408
- return resolveTraceIdFromHeaders(
1409
- pickHeader(req.headers[TRACE_PARENT_HEADER]),
1410
- pickHeader(req.headers[REQUEST_ID_HEADER])
1411
- );
1412
- }
1413
- function extractTraceIdFromRequest(request) {
1414
- return resolveTraceIdFromHeaders(
1415
- request.headers.get(TRACE_PARENT_HEADER),
1416
- request.headers.get(REQUEST_ID_HEADER)
1417
- );
1418
- }
1419
-
1420
1825
  export {
1421
1826
  ActionError,
1422
1827
  ActionInputError,
@@ -1426,11 +1831,15 @@ export {
1426
1831
  dispatchCsrfWarn,
1427
1832
  sendJson,
1428
1833
  sendError,
1429
- isZodLike,
1430
- _resetMiddlewareCacheForTests,
1431
- runMiddlewareAndContext,
1432
1834
  incomingMessageToWebRequest,
1835
+ createWebRequestSource,
1433
1836
  incomingMessageToHandlerRequest,
1837
+ validateRouteInput,
1838
+ executeWebRequest,
1839
+ writeWebResponseToServerResponse,
1840
+ _resetMiddlewareCacheForTests,
1841
+ runMiddlewareAndContext,
1842
+ createServerContext,
1434
1843
  executeRoute,
1435
1844
  handleRequestError,
1436
1845
  handleWebRequestError,
@@ -1441,11 +1850,6 @@ export {
1441
1850
  handleBatchRequest,
1442
1851
  matchesOrigin,
1443
1852
  createCorsHandler,
1444
- createCorsWebHandler,
1445
- TRACE_HEADER,
1446
- TRACE_PARENT_HEADER,
1447
- parseTraceparent,
1448
- extractTraceId,
1449
- extractTraceIdFromRequest
1853
+ createCorsWebHandler
1450
1854
  };
1451
- //# sourceMappingURL=chunk-XALU5LCU.js.map
1855
+ //# sourceMappingURL=chunk-RWNYIU6A.js.map