@mostra/protocol 0.0.0-placeholder → 0.1.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 (439) hide show
  1. package/LICENSE +202 -0
  2. package/README.md +37 -1
  3. package/dist/actions.d.ts +273 -0
  4. package/dist/actions.d.ts.map +1 -0
  5. package/dist/actions.js +154 -0
  6. package/dist/actions.js.map +1 -0
  7. package/dist/artifact.d.ts +113 -0
  8. package/dist/artifact.d.ts.map +1 -0
  9. package/dist/artifact.js +79 -0
  10. package/dist/artifact.js.map +1 -0
  11. package/dist/bridge.d.ts +295 -0
  12. package/dist/bridge.d.ts.map +1 -0
  13. package/dist/bridge.js +343 -0
  14. package/dist/bridge.js.map +1 -0
  15. package/dist/browser.d.ts +195 -0
  16. package/dist/browser.d.ts.map +1 -0
  17. package/dist/browser.js +156 -0
  18. package/dist/browser.js.map +1 -0
  19. package/dist/bundle.d.ts +155 -0
  20. package/dist/bundle.d.ts.map +1 -0
  21. package/dist/bundle.js +130 -0
  22. package/dist/bundle.js.map +1 -0
  23. package/dist/canonical.d.ts +23 -0
  24. package/dist/canonical.d.ts.map +1 -0
  25. package/dist/canonical.js +45 -0
  26. package/dist/canonical.js.map +1 -0
  27. package/dist/capability.d.ts +38 -0
  28. package/dist/capability.d.ts.map +1 -0
  29. package/dist/capability.js +61 -0
  30. package/dist/capability.js.map +1 -0
  31. package/dist/diagnostics/codes/a11y.d.ts +8 -0
  32. package/dist/diagnostics/codes/a11y.d.ts.map +1 -0
  33. package/dist/diagnostics/codes/a11y.js +30 -0
  34. package/dist/diagnostics/codes/a11y.js.map +1 -0
  35. package/dist/diagnostics/codes/action.d.ts +8 -0
  36. package/dist/diagnostics/codes/action.d.ts.map +1 -0
  37. package/dist/diagnostics/codes/action.js +110 -0
  38. package/dist/diagnostics/codes/action.js.map +1 -0
  39. package/dist/diagnostics/codes/artifact.d.ts +8 -0
  40. package/dist/diagnostics/codes/artifact.d.ts.map +1 -0
  41. package/dist/diagnostics/codes/artifact.js +121 -0
  42. package/dist/diagnostics/codes/artifact.js.map +1 -0
  43. package/dist/diagnostics/codes/build.d.ts +8 -0
  44. package/dist/diagnostics/codes/build.d.ts.map +1 -0
  45. package/dist/diagnostics/codes/build.js +55 -0
  46. package/dist/diagnostics/codes/build.js.map +1 -0
  47. package/dist/diagnostics/codes/cli.d.ts +8 -0
  48. package/dist/diagnostics/codes/cli.d.ts.map +1 -0
  49. package/dist/diagnostics/codes/cli.js +44 -0
  50. package/dist/diagnostics/codes/cli.js.map +1 -0
  51. package/dist/diagnostics/codes/console.d.ts +8 -0
  52. package/dist/diagnostics/codes/console.d.ts.map +1 -0
  53. package/dist/diagnostics/codes/console.js +30 -0
  54. package/dist/diagnostics/codes/console.js.map +1 -0
  55. package/dist/diagnostics/codes/dep.d.ts +8 -0
  56. package/dist/diagnostics/codes/dep.d.ts.map +1 -0
  57. package/dist/diagnostics/codes/dep.js +88 -0
  58. package/dist/diagnostics/codes/dep.js.map +1 -0
  59. package/dist/diagnostics/codes/env.d.ts +8 -0
  60. package/dist/diagnostics/codes/env.d.ts.map +1 -0
  61. package/dist/diagnostics/codes/env.js +132 -0
  62. package/dist/diagnostics/codes/env.js.map +1 -0
  63. package/dist/diagnostics/codes/field.d.ts +8 -0
  64. package/dist/diagnostics/codes/field.d.ts.map +1 -0
  65. package/dist/diagnostics/codes/field.js +99 -0
  66. package/dist/diagnostics/codes/field.js.map +1 -0
  67. package/dist/diagnostics/codes/home.d.ts +8 -0
  68. package/dist/diagnostics/codes/home.d.ts.map +1 -0
  69. package/dist/diagnostics/codes/home.js +132 -0
  70. package/dist/diagnostics/codes/home.js.map +1 -0
  71. package/dist/diagnostics/codes/host.d.ts +8 -0
  72. package/dist/diagnostics/codes/host.d.ts.map +1 -0
  73. package/dist/diagnostics/codes/host.js +176 -0
  74. package/dist/diagnostics/codes/host.js.map +1 -0
  75. package/dist/diagnostics/codes/hygiene.d.ts +8 -0
  76. package/dist/diagnostics/codes/hygiene.d.ts.map +1 -0
  77. package/dist/diagnostics/codes/hygiene.js +154 -0
  78. package/dist/diagnostics/codes/hygiene.js.map +1 -0
  79. package/dist/diagnostics/codes/index.d.ts +51 -0
  80. package/dist/diagnostics/codes/index.d.ts.map +1 -0
  81. package/dist/diagnostics/codes/index.js +72 -0
  82. package/dist/diagnostics/codes/index.js.map +1 -0
  83. package/dist/diagnostics/codes/live.d.ts +8 -0
  84. package/dist/diagnostics/codes/live.d.ts.map +1 -0
  85. package/dist/diagnostics/codes/live.js +30 -0
  86. package/dist/diagnostics/codes/live.js.map +1 -0
  87. package/dist/diagnostics/codes/manifest.d.ts +8 -0
  88. package/dist/diagnostics/codes/manifest.d.ts.map +1 -0
  89. package/dist/diagnostics/codes/manifest.js +44 -0
  90. package/dist/diagnostics/codes/manifest.js.map +1 -0
  91. package/dist/diagnostics/codes/network.d.ts +8 -0
  92. package/dist/diagnostics/codes/network.d.ts.map +1 -0
  93. package/dist/diagnostics/codes/network.js +30 -0
  94. package/dist/diagnostics/codes/network.js.map +1 -0
  95. package/dist/diagnostics/codes/platform.d.ts +8 -0
  96. package/dist/diagnostics/codes/platform.d.ts.map +1 -0
  97. package/dist/diagnostics/codes/platform.js +18 -0
  98. package/dist/diagnostics/codes/platform.js.map +1 -0
  99. package/dist/diagnostics/codes/publish.d.ts +8 -0
  100. package/dist/diagnostics/codes/publish.d.ts.map +1 -0
  101. package/dist/diagnostics/codes/publish.js +44 -0
  102. package/dist/diagnostics/codes/publish.js.map +1 -0
  103. package/dist/diagnostics/codes/regression.d.ts +8 -0
  104. package/dist/diagnostics/codes/regression.d.ts.map +1 -0
  105. package/dist/diagnostics/codes/regression.js +77 -0
  106. package/dist/diagnostics/codes/regression.js.map +1 -0
  107. package/dist/diagnostics/codes/runtime.d.ts +8 -0
  108. package/dist/diagnostics/codes/runtime.d.ts.map +1 -0
  109. package/dist/diagnostics/codes/runtime.js +66 -0
  110. package/dist/diagnostics/codes/runtime.js.map +1 -0
  111. package/dist/diagnostics/codes/secret.d.ts +8 -0
  112. package/dist/diagnostics/codes/secret.d.ts.map +1 -0
  113. package/dist/diagnostics/codes/secret.js +18 -0
  114. package/dist/diagnostics/codes/secret.js.map +1 -0
  115. package/dist/diagnostics/codes/smoke.d.ts +8 -0
  116. package/dist/diagnostics/codes/smoke.d.ts.map +1 -0
  117. package/dist/diagnostics/codes/smoke.js +30 -0
  118. package/dist/diagnostics/codes/smoke.js.map +1 -0
  119. package/dist/diagnostics/codes/submit.d.ts +8 -0
  120. package/dist/diagnostics/codes/submit.d.ts.map +1 -0
  121. package/dist/diagnostics/codes/submit.js +99 -0
  122. package/dist/diagnostics/codes/submit.js.map +1 -0
  123. package/dist/diagnostics/codes/target.d.ts +8 -0
  124. package/dist/diagnostics/codes/target.d.ts.map +1 -0
  125. package/dist/diagnostics/codes/target.js +18 -0
  126. package/dist/diagnostics/codes/target.js.map +1 -0
  127. package/dist/diagnostics/codes/type.d.ts +8 -0
  128. package/dist/diagnostics/codes/type.d.ts.map +1 -0
  129. package/dist/diagnostics/codes/type.js +30 -0
  130. package/dist/diagnostics/codes/type.js.map +1 -0
  131. package/dist/diagnostics/codes/verify.d.ts +8 -0
  132. package/dist/diagnostics/codes/verify.d.ts.map +1 -0
  133. package/dist/diagnostics/codes/verify.js +99 -0
  134. package/dist/diagnostics/codes/verify.js.map +1 -0
  135. package/dist/diagnostics/diagnostic.d.ts +79 -0
  136. package/dist/diagnostics/diagnostic.d.ts.map +1 -0
  137. package/dist/diagnostics/diagnostic.js +131 -0
  138. package/dist/diagnostics/diagnostic.js.map +1 -0
  139. package/dist/diagnostics/spec.d.ts +49 -0
  140. package/dist/diagnostics/spec.d.ts.map +1 -0
  141. package/dist/diagnostics/spec.js +31 -0
  142. package/dist/diagnostics/spec.js.map +1 -0
  143. package/dist/hygiene.d.ts +66 -0
  144. package/dist/hygiene.d.ts.map +1 -0
  145. package/dist/hygiene.js +134 -0
  146. package/dist/hygiene.js.map +1 -0
  147. package/dist/ids.d.ts +119 -0
  148. package/dist/ids.d.ts.map +1 -0
  149. package/dist/ids.js +135 -0
  150. package/dist/ids.js.map +1 -0
  151. package/dist/index.d.ts +86 -0
  152. package/dist/index.js +86 -0
  153. package/dist/interaction.d.ts +391 -0
  154. package/dist/interaction.d.ts.map +1 -0
  155. package/dist/interaction.js +306 -0
  156. package/dist/interaction.js.map +1 -0
  157. package/dist/manifest.d.ts +97 -0
  158. package/dist/manifest.d.ts.map +1 -0
  159. package/dist/manifest.js +101 -0
  160. package/dist/manifest.js.map +1 -0
  161. package/dist/method.d.ts +26 -0
  162. package/dist/method.d.ts.map +1 -0
  163. package/dist/method.js +10 -0
  164. package/dist/method.js.map +1 -0
  165. package/dist/methods/artifact/create.d.ts +29 -0
  166. package/dist/methods/artifact/create.d.ts.map +1 -0
  167. package/dist/methods/artifact/create.js +31 -0
  168. package/dist/methods/artifact/create.js.map +1 -0
  169. package/dist/methods/artifact/get.d.ts +17 -0
  170. package/dist/methods/artifact/get.d.ts.map +1 -0
  171. package/dist/methods/artifact/get.js +21 -0
  172. package/dist/methods/artifact/get.js.map +1 -0
  173. package/dist/methods/artifact/list.d.ts +22 -0
  174. package/dist/methods/artifact/list.d.ts.map +1 -0
  175. package/dist/methods/artifact/list.js +19 -0
  176. package/dist/methods/artifact/list.js.map +1 -0
  177. package/dist/methods/artifact/publish.d.ts +28 -0
  178. package/dist/methods/artifact/publish.d.ts.map +1 -0
  179. package/dist/methods/artifact/publish.js +28 -0
  180. package/dist/methods/artifact/publish.js.map +1 -0
  181. package/dist/methods/artifact/verify.d.ts +29 -0
  182. package/dist/methods/artifact/verify.d.ts.map +1 -0
  183. package/dist/methods/artifact/verify.js +27 -0
  184. package/dist/methods/artifact/verify.js.map +1 -0
  185. package/dist/methods/deps/add.d.ts +43 -0
  186. package/dist/methods/deps/add.d.ts.map +1 -0
  187. package/dist/methods/deps/add.js +40 -0
  188. package/dist/methods/deps/add.js.map +1 -0
  189. package/dist/methods/dev/start.d.ts +52 -0
  190. package/dist/methods/dev/start.d.ts.map +1 -0
  191. package/dist/methods/dev/start.js +56 -0
  192. package/dist/methods/dev/start.js.map +1 -0
  193. package/dist/methods/dev/stop.d.ts +16 -0
  194. package/dist/methods/dev/stop.d.ts.map +1 -0
  195. package/dist/methods/dev/stop.js +21 -0
  196. package/dist/methods/dev/stop.js.map +1 -0
  197. package/dist/methods/events/ack.d.ts +20 -0
  198. package/dist/methods/events/ack.d.ts.map +1 -0
  199. package/dist/methods/events/ack.js +26 -0
  200. package/dist/methods/events/ack.js.map +1 -0
  201. package/dist/methods/events/read.d.ts +40 -0
  202. package/dist/methods/events/read.d.ts.map +1 -0
  203. package/dist/methods/events/read.js +35 -0
  204. package/dist/methods/events/read.js.map +1 -0
  205. package/dist/methods/events/subscribe.d.ts +54 -0
  206. package/dist/methods/events/subscribe.d.ts.map +1 -0
  207. package/dist/methods/events/subscribe.js +44 -0
  208. package/dist/methods/events/subscribe.js.map +1 -0
  209. package/dist/methods/events/unsubscribe.d.ts +16 -0
  210. package/dist/methods/events/unsubscribe.d.ts.map +1 -0
  211. package/dist/methods/events/unsubscribe.js +21 -0
  212. package/dist/methods/events/unsubscribe.js.map +1 -0
  213. package/dist/methods/gc/run.d.ts +76 -0
  214. package/dist/methods/gc/run.d.ts.map +1 -0
  215. package/dist/methods/gc/run.js +56 -0
  216. package/dist/methods/gc/run.js.map +1 -0
  217. package/dist/methods/index.d.ts +6 -0
  218. package/dist/methods/index.d.ts.map +1 -0
  219. package/dist/methods/index.js +78 -0
  220. package/dist/methods/index.js.map +1 -0
  221. package/dist/methods/instance/check.d.ts +30 -0
  222. package/dist/methods/instance/check.d.ts.map +1 -0
  223. package/dist/methods/instance/check.js +34 -0
  224. package/dist/methods/instance/check.js.map +1 -0
  225. package/dist/methods/instance/status.d.ts +102 -0
  226. package/dist/methods/instance/status.d.ts.map +1 -0
  227. package/dist/methods/instance/status.js +83 -0
  228. package/dist/methods/instance/status.js.map +1 -0
  229. package/dist/methods/live/push.d.ts +28 -0
  230. package/dist/methods/live/push.d.ts.map +1 -0
  231. package/dist/methods/live/push.js +35 -0
  232. package/dist/methods/live/push.js.map +1 -0
  233. package/dist/methods/mostra/initialize.d.ts +143 -0
  234. package/dist/methods/mostra/initialize.d.ts.map +1 -0
  235. package/dist/methods/mostra/initialize.js +97 -0
  236. package/dist/methods/mostra/initialize.js.map +1 -0
  237. package/dist/methods/mostra/shutdown.d.ts +14 -0
  238. package/dist/methods/mostra/shutdown.d.ts.map +1 -0
  239. package/dist/methods/mostra/shutdown.js +22 -0
  240. package/dist/methods/mostra/shutdown.js.map +1 -0
  241. package/dist/methods/port/drafts-mirror.d.ts +30 -0
  242. package/dist/methods/port/drafts-mirror.d.ts.map +1 -0
  243. package/dist/methods/port/drafts-mirror.js +33 -0
  244. package/dist/methods/port/drafts-mirror.js.map +1 -0
  245. package/dist/methods/port/secrets-get.d.ts +19 -0
  246. package/dist/methods/port/secrets-get.d.ts.map +1 -0
  247. package/dist/methods/port/secrets-get.js +31 -0
  248. package/dist/methods/port/secrets-get.js.map +1 -0
  249. package/dist/methods/port/submissions-deliver.d.ts +38 -0
  250. package/dist/methods/port/submissions-deliver.d.ts.map +1 -0
  251. package/dist/methods/port/submissions-deliver.js +38 -0
  252. package/dist/methods/port/submissions-deliver.js.map +1 -0
  253. package/dist/methods/port/trusted-controls-activated.d.ts +27 -0
  254. package/dist/methods/port/trusted-controls-activated.d.ts.map +1 -0
  255. package/dist/methods/port/trusted-controls-activated.js +33 -0
  256. package/dist/methods/port/trusted-controls-activated.js.map +1 -0
  257. package/dist/methods/port/trusted-controls-policy.d.ts +21 -0
  258. package/dist/methods/port/trusted-controls-policy.d.ts.map +1 -0
  259. package/dist/methods/port/trusted-controls-policy.js +27 -0
  260. package/dist/methods/port/trusted-controls-policy.js.map +1 -0
  261. package/dist/methods/results/get.d.ts +32 -0
  262. package/dist/methods/results/get.d.ts.map +1 -0
  263. package/dist/methods/results/get.js +36 -0
  264. package/dist/methods/results/get.js.map +1 -0
  265. package/dist/methods/secret/delete.d.ts +22 -0
  266. package/dist/methods/secret/delete.d.ts.map +1 -0
  267. package/dist/methods/secret/delete.js +32 -0
  268. package/dist/methods/secret/delete.js.map +1 -0
  269. package/dist/methods/secret/list.d.ts +21 -0
  270. package/dist/methods/secret/list.d.ts.map +1 -0
  271. package/dist/methods/secret/list.js +29 -0
  272. package/dist/methods/secret/list.js.map +1 -0
  273. package/dist/methods/secret/set.d.ts +37 -0
  274. package/dist/methods/secret/set.d.ts.map +1 -0
  275. package/dist/methods/secret/set.js +41 -0
  276. package/dist/methods/secret/set.js.map +1 -0
  277. package/dist/methods/state/get.d.ts +25 -0
  278. package/dist/methods/state/get.d.ts.map +1 -0
  279. package/dist/methods/state/get.js +29 -0
  280. package/dist/methods/state/get.js.map +1 -0
  281. package/dist/methods/state/patch.d.ts +32 -0
  282. package/dist/methods/state/patch.d.ts.map +1 -0
  283. package/dist/methods/state/patch.js +29 -0
  284. package/dist/methods/state/patch.js.map +1 -0
  285. package/dist/methods/view/default.d.ts +19 -0
  286. package/dist/methods/view/default.d.ts.map +1 -0
  287. package/dist/methods/view/default.js +23 -0
  288. package/dist/methods/view/default.js.map +1 -0
  289. package/dist/methods/view/launch.d.ts +27 -0
  290. package/dist/methods/view/launch.d.ts.map +1 -0
  291. package/dist/methods/view/launch.js +30 -0
  292. package/dist/methods/view/launch.js.map +1 -0
  293. package/dist/methods/view/revoke.d.ts +19 -0
  294. package/dist/methods/view/revoke.d.ts.map +1 -0
  295. package/dist/methods/view/revoke.js +26 -0
  296. package/dist/methods/view/revoke.js.map +1 -0
  297. package/dist/methods/view/rotate.d.ts +21 -0
  298. package/dist/methods/view/rotate.d.ts.map +1 -0
  299. package/dist/methods/view/rotate.js +27 -0
  300. package/dist/methods/view/rotate.js.map +1 -0
  301. package/dist/methods/view/url.d.ts +52 -0
  302. package/dist/methods/view/url.d.ts.map +1 -0
  303. package/dist/methods/view/url.js +43 -0
  304. package/dist/methods/view/url.js.map +1 -0
  305. package/dist/methods/wait/wait.d.ts +37 -0
  306. package/dist/methods/wait/wait.d.ts.map +1 -0
  307. package/dist/methods/wait/wait.js +39 -0
  308. package/dist/methods/wait/wait.js.map +1 -0
  309. package/dist/revision.d.ts +43 -0
  310. package/dist/revision.d.ts.map +1 -0
  311. package/dist/revision.js +69 -0
  312. package/dist/revision.js.map +1 -0
  313. package/dist/rpc/error.d.ts +47 -0
  314. package/dist/rpc/error.d.ts.map +1 -0
  315. package/dist/rpc/error.js +77 -0
  316. package/dist/rpc/error.js.map +1 -0
  317. package/dist/rpc/lines.d.ts +30 -0
  318. package/dist/rpc/lines.d.ts.map +1 -0
  319. package/dist/rpc/lines.js +63 -0
  320. package/dist/rpc/lines.js.map +1 -0
  321. package/dist/rpc/messages.d.ts +92 -0
  322. package/dist/rpc/messages.d.ts.map +1 -0
  323. package/dist/rpc/messages.js +133 -0
  324. package/dist/rpc/messages.js.map +1 -0
  325. package/dist/rpc/peer.d.ts +81 -0
  326. package/dist/rpc/peer.d.ts.map +1 -0
  327. package/dist/rpc/peer.js +208 -0
  328. package/dist/rpc/peer.js.map +1 -0
  329. package/dist/serializer.d.ts +178 -0
  330. package/dist/serializer.d.ts.map +1 -0
  331. package/dist/serializer.js +929 -0
  332. package/dist/serializer.js.map +1 -0
  333. package/dist/verify.d.ts +254 -0
  334. package/dist/verify.d.ts.map +1 -0
  335. package/dist/verify.js +243 -0
  336. package/dist/verify.js.map +1 -0
  337. package/dist/view.d.ts +103 -0
  338. package/dist/view.d.ts.map +1 -0
  339. package/dist/view.js +110 -0
  340. package/dist/view.js.map +1 -0
  341. package/dist/wire-registry.js +11 -0
  342. package/dist/wire-registry.js.map +1 -0
  343. package/dist/worker.d.ts +249 -0
  344. package/dist/worker.d.ts.map +1 -0
  345. package/dist/worker.js +158 -0
  346. package/dist/worker.js.map +1 -0
  347. package/package.json +114 -4
  348. package/schemas/protocol.draft-07.json +5120 -0
  349. package/schemas/protocol.schema.json +4964 -0
  350. package/src/actions.ts +418 -0
  351. package/src/artifact.ts +187 -0
  352. package/src/bridge.ts +618 -0
  353. package/src/browser.ts +374 -0
  354. package/src/bundle.ts +264 -0
  355. package/src/canonical.ts +49 -0
  356. package/src/capability.ts +92 -0
  357. package/src/diagnostics/codes/a11y.ts +41 -0
  358. package/src/diagnostics/codes/action.ts +125 -0
  359. package/src/diagnostics/codes/artifact.ts +137 -0
  360. package/src/diagnostics/codes/build.ts +65 -0
  361. package/src/diagnostics/codes/cli.ts +53 -0
  362. package/src/diagnostics/codes/console.ts +41 -0
  363. package/src/diagnostics/codes/dep.ts +101 -0
  364. package/src/diagnostics/codes/env.ts +149 -0
  365. package/src/diagnostics/codes/field.ts +113 -0
  366. package/src/diagnostics/codes/home.ts +150 -0
  367. package/src/diagnostics/codes/host.ts +197 -0
  368. package/src/diagnostics/codes/hygiene.ts +175 -0
  369. package/src/diagnostics/codes/index.ts +142 -0
  370. package/src/diagnostics/codes/live.ts +41 -0
  371. package/src/diagnostics/codes/manifest.ts +53 -0
  372. package/src/diagnostics/codes/network.ts +41 -0
  373. package/src/diagnostics/codes/platform.ts +30 -0
  374. package/src/diagnostics/codes/publish.ts +53 -0
  375. package/src/diagnostics/codes/regression.ts +89 -0
  376. package/src/diagnostics/codes/runtime.ts +77 -0
  377. package/src/diagnostics/codes/secret.ts +29 -0
  378. package/src/diagnostics/codes/smoke.ts +41 -0
  379. package/src/diagnostics/codes/submit.ts +113 -0
  380. package/src/diagnostics/codes/target.ts +29 -0
  381. package/src/diagnostics/codes/type.ts +41 -0
  382. package/src/diagnostics/codes/verify.ts +113 -0
  383. package/src/diagnostics/diagnostic.ts +240 -0
  384. package/src/diagnostics/spec.ts +90 -0
  385. package/src/hygiene.ts +224 -0
  386. package/src/ids.ts +279 -0
  387. package/src/index.ts +576 -0
  388. package/src/interaction.ts +728 -0
  389. package/src/manifest.ts +206 -0
  390. package/src/method.ts +42 -0
  391. package/src/methods/artifact/create.ts +56 -0
  392. package/src/methods/artifact/get.ts +30 -0
  393. package/src/methods/artifact/list.ts +42 -0
  394. package/src/methods/artifact/publish.ts +46 -0
  395. package/src/methods/artifact/verify.ts +46 -0
  396. package/src/methods/deps/add.ts +72 -0
  397. package/src/methods/dev/start.ts +84 -0
  398. package/src/methods/dev/stop.ts +32 -0
  399. package/src/methods/events/ack.ts +41 -0
  400. package/src/methods/events/read.ts +67 -0
  401. package/src/methods/events/subscribe.ts +91 -0
  402. package/src/methods/events/unsubscribe.ts +35 -0
  403. package/src/methods/gc/run.ts +125 -0
  404. package/src/methods/index.ts +81 -0
  405. package/src/methods/instance/check.ts +61 -0
  406. package/src/methods/instance/status.ts +172 -0
  407. package/src/methods/live/push.ts +54 -0
  408. package/src/methods/mostra/initialize.ts +249 -0
  409. package/src/methods/mostra/shutdown.ts +31 -0
  410. package/src/methods/port/drafts-mirror.ts +52 -0
  411. package/src/methods/port/secrets-get.ts +40 -0
  412. package/src/methods/port/submissions-deliver.ts +70 -0
  413. package/src/methods/port/trusted-controls-activated.ts +51 -0
  414. package/src/methods/port/trusted-controls-policy.ts +38 -0
  415. package/src/methods/results/get.ts +59 -0
  416. package/src/methods/secret/delete.ts +43 -0
  417. package/src/methods/secret/list.ts +40 -0
  418. package/src/methods/secret/set.ts +69 -0
  419. package/src/methods/state/get.ts +44 -0
  420. package/src/methods/state/patch.ts +51 -0
  421. package/src/methods/view/default.ts +32 -0
  422. package/src/methods/view/launch.ts +47 -0
  423. package/src/methods/view/revoke.ts +39 -0
  424. package/src/methods/view/rotate.ts +37 -0
  425. package/src/methods/view/url.ts +84 -0
  426. package/src/methods/wait/wait.ts +58 -0
  427. package/src/revision.ts +101 -0
  428. package/src/rpc/error.ts +107 -0
  429. package/src/rpc/lines.ts +70 -0
  430. package/src/rpc/messages.ts +188 -0
  431. package/src/rpc/peer.ts +341 -0
  432. package/src/serializer.ts +1217 -0
  433. package/src/timers.d.ts +8 -0
  434. package/src/verify.ts +458 -0
  435. package/src/view.ts +200 -0
  436. package/src/web-crypto.d.ts +9 -0
  437. package/src/web-platform.d.ts +35 -0
  438. package/src/wire-registry.ts +14 -0
  439. package/src/worker.ts +374 -0
@@ -0,0 +1,240 @@
1
+ /**
2
+ * The one diagnostic object every Mostra interface uses for errors, warnings and hints
3
+ * (INTERFACES §1 and §13, AX-03).
4
+ */
5
+ import * as z from "zod";
6
+ import { wireRegistry } from "../wire-registry.ts";
7
+
8
+ /**
9
+ * Diagnostic areas. A code is `MOSTRA_<AREA>_<NAME>`. INTERFACES §13 holds the authoritative list,
10
+ * which only grows.
11
+ */
12
+ export type DiagnosticArea =
13
+ | "MANIFEST"
14
+ | "BUILD"
15
+ | "TYPE"
16
+ | "LINT"
17
+ | "DEP"
18
+ | "KIT"
19
+ | "FIELD"
20
+ | "ACTION"
21
+ | "LIVE"
22
+ | "RUNTIME"
23
+ | "CONSOLE"
24
+ | "NETWORK"
25
+ | "A11Y"
26
+ | "VISUAL"
27
+ | "SMOKE"
28
+ | "REGRESSION"
29
+ | "TERM"
30
+ | "PUBLISH"
31
+ | "SUBMIT"
32
+ | "HOST"
33
+ | "HOME"
34
+ | "HYGIENE"
35
+ | "SECRET"
36
+ | "SHARE"
37
+ | "VERIFY"
38
+ | "TARGET"
39
+ | "ENV"
40
+ | "PLATFORM"
41
+ | "ARTIFACT"
42
+ | "CLI";
43
+
44
+ /** Every diagnostic area, in INTERFACES §13 order. */
45
+ export const DIAGNOSTIC_AREAS: readonly DiagnosticArea[] = [
46
+ "MANIFEST",
47
+ "BUILD",
48
+ "TYPE",
49
+ "LINT",
50
+ "DEP",
51
+ "KIT",
52
+ "FIELD",
53
+ "ACTION",
54
+ "LIVE",
55
+ "RUNTIME",
56
+ "CONSOLE",
57
+ "NETWORK",
58
+ "A11Y",
59
+ "VISUAL",
60
+ "SMOKE",
61
+ "REGRESSION",
62
+ "TERM",
63
+ "PUBLISH",
64
+ "SUBMIT",
65
+ "HOST",
66
+ "HOME",
67
+ "HYGIENE",
68
+ "SECRET",
69
+ "SHARE",
70
+ "VERIFY",
71
+ "TARGET",
72
+ "ENV",
73
+ "PLATFORM",
74
+ "ARTIFACT",
75
+ "CLI",
76
+ ];
77
+
78
+ /**
79
+ * A diagnostic code. Codes are semver surface: once released, a code keeps its meaning and is
80
+ * never removed (AX-03).
81
+ */
82
+ export type DiagnosticCode = `MOSTRA_${DiagnosticArea}_${string}`;
83
+
84
+ /**
85
+ * How bad it is. `error` is only for definite failures; observations that might be fine are
86
+ * warnings (D72).
87
+ */
88
+ export type DiagnosticSeverity = "error" | "warning" | "hint";
89
+
90
+ /** The stage of work that produced the diagnostic. */
91
+ export type DiagnosticPhase =
92
+ | "manifest"
93
+ | "compile"
94
+ | "lint"
95
+ | "runtime"
96
+ | "console"
97
+ | "network"
98
+ | "a11y"
99
+ | "visual"
100
+ | "smoke"
101
+ | "regression"
102
+ | "contract"
103
+ | "publish"
104
+ | "host"
105
+ | "hygiene"
106
+ | "platform";
107
+
108
+ /**
109
+ * A machine-applicable fix. `range` is `[startLine, startColumn, endLine, endColumn]`, 1-based,
110
+ * with the end exclusive.
111
+ */
112
+ export interface DiagnosticFix {
113
+ /** Replace, insert or delete text in `file`, or run `command`. */
114
+ readonly kind: "replace" | "insert" | "delete" | "command";
115
+ /** The file to edit, relative to the artifact or project root. */
116
+ readonly file?: string;
117
+ /** The span to edit. */
118
+ readonly range?: readonly [number, number, number, number];
119
+ /** The replacement or inserted text. */
120
+ readonly text?: string;
121
+ /** The command to run, for `kind: "command"`. */
122
+ readonly command?: string;
123
+ }
124
+
125
+ /** Where the problem is: a source position (1-based) or a place in a rendered viewport. */
126
+ export type DiagnosticLocation =
127
+ | { readonly file: string; readonly line: number; readonly column: number }
128
+ | { readonly viewport: string; readonly selector?: string };
129
+
130
+ /** One diagnostic (INTERFACES §13). */
131
+ export interface Diagnostic {
132
+ /** The stable code, `MOSTRA_<AREA>_<NAME>`. */
133
+ readonly code: DiagnosticCode;
134
+ /** How bad it is. */
135
+ readonly severity: DiagnosticSeverity;
136
+ /** What is wrong, for this occurrence. */
137
+ readonly message: string;
138
+ /** What to do: one imperative sentence. */
139
+ readonly hint?: string;
140
+ /** A machine-applicable fix, when one exists. */
141
+ readonly fix?: DiagnosticFix;
142
+ /** Where the problem is, when it has a place. */
143
+ readonly location?: DiagnosticLocation;
144
+ /** The stage of work that produced it. */
145
+ readonly phase: DiagnosticPhase;
146
+ /** The code's documentation page: `${docsBase}/errors/${code}` (D37). */
147
+ readonly docs: string;
148
+ /** How many identical occurrences this one stands for, when deduplicated. */
149
+ readonly count?: number;
150
+ }
151
+
152
+ const positiveInt = z.int().min(1);
153
+
154
+ /**
155
+ * Codes on the wire accept any area, so a client keeps working when a newer Mostra reports a code
156
+ * from an area it doesn't know yet. Producers are typed against {@link DiagnosticArea}.
157
+ */
158
+ const codeSchema = z
159
+ .string()
160
+ .regex(/^MOSTRA_[A-Z0-9]+_[A-Z0-9_]+$/)
161
+ .register(wireRegistry, {
162
+ id: "DiagnosticCode",
163
+ description: "Stable diagnostic code: MOSTRA_<AREA>_<NAME>.",
164
+ }) as unknown as z.ZodType<DiagnosticCode, string>;
165
+
166
+ /** The Zod schema of the `DiagnosticSeverity` type. */
167
+ export const DiagnosticSeverity: z.ZodType<DiagnosticSeverity, string> = z
168
+ .enum(["error", "warning", "hint"])
169
+ .register(wireRegistry, {
170
+ id: "DiagnosticSeverity",
171
+ description: "How bad it is: error only for definite failures.",
172
+ });
173
+
174
+ /** The Zod schema of the `DiagnosticPhase` type. */
175
+ export const DiagnosticPhase: z.ZodType<DiagnosticPhase, string> = z
176
+ .enum([
177
+ "manifest",
178
+ "compile",
179
+ "lint",
180
+ "runtime",
181
+ "console",
182
+ "network",
183
+ "a11y",
184
+ "visual",
185
+ "smoke",
186
+ "regression",
187
+ "contract",
188
+ "publish",
189
+ "host",
190
+ "hygiene",
191
+ "platform",
192
+ ])
193
+ .register(wireRegistry, {
194
+ id: "DiagnosticPhase",
195
+ description: "The stage of work that produced the diagnostic.",
196
+ });
197
+
198
+ /** The Zod schema of the `DiagnosticFix` type. */
199
+ export const DiagnosticFix: z.ZodType<DiagnosticFix> = z
200
+ .object({
201
+ kind: z.enum(["replace", "insert", "delete", "command"]),
202
+ file: z.string().exactOptional(),
203
+ range: z.tuple([positiveInt, positiveInt, positiveInt, positiveInt]).readonly().exactOptional(),
204
+ text: z.string().exactOptional(),
205
+ command: z.string().exactOptional(),
206
+ })
207
+ .register(wireRegistry, {
208
+ id: "DiagnosticFix",
209
+ description:
210
+ "A machine-applicable fix; range is [startLine, startColumn, endLine, endColumn], 1-based, end exclusive.",
211
+ });
212
+
213
+ /** The Zod schema of the `DiagnosticLocation` type. */
214
+ export const DiagnosticLocation: z.ZodType<DiagnosticLocation> = z
215
+ .union([
216
+ z.object({ file: z.string(), line: positiveInt, column: positiveInt }),
217
+ z.object({ viewport: z.string(), selector: z.string().exactOptional() }),
218
+ ])
219
+ .register(wireRegistry, {
220
+ id: "DiagnosticLocation",
221
+ description: "A 1-based source position, or a place in a rendered viewport.",
222
+ });
223
+
224
+ /** The Zod schema of the `Diagnostic` type. */
225
+ export const Diagnostic: z.ZodType<Diagnostic> = z
226
+ .object({
227
+ code: codeSchema,
228
+ severity: DiagnosticSeverity,
229
+ message: z.string(),
230
+ hint: z.string().exactOptional(),
231
+ fix: DiagnosticFix.exactOptional(),
232
+ location: DiagnosticLocation.exactOptional(),
233
+ phase: DiagnosticPhase,
234
+ docs: z.url(),
235
+ count: positiveInt.exactOptional(),
236
+ })
237
+ .register(wireRegistry, {
238
+ id: "Diagnostic",
239
+ description: "One diagnostic: a stable code, severity, message, hint, fix and docs link.",
240
+ });
@@ -0,0 +1,90 @@
1
+ /**
2
+ * The diagnostic catalog: one entry per code, declared in one source file per area under
3
+ * `codes/`. The catalog feeds `createDiagnostic`, the generated catalog JSON and one docs
4
+ * page per code (AX-03).
5
+ */
6
+ import type {
7
+ Diagnostic,
8
+ DiagnosticArea,
9
+ DiagnosticFix,
10
+ DiagnosticLocation,
11
+ DiagnosticPhase,
12
+ DiagnosticSeverity,
13
+ } from "./diagnostic.ts";
14
+
15
+ /** Everything Mostra knows about one code, besides the code itself. */
16
+ export interface DiagnosticSpec {
17
+ /** The severity of every occurrence. */
18
+ readonly severity: DiagnosticSeverity;
19
+ /** The stage of work that reports it. */
20
+ readonly phase: DiagnosticPhase;
21
+ /** One line naming the condition. It is the docs page's title. */
22
+ readonly title: string;
23
+ /** The default hint: one imperative sentence. An occurrence may give a more specific one. */
24
+ readonly hint: string;
25
+ /** The docs page body. */
26
+ readonly docs: {
27
+ /** What the code means and when Mostra reports it. */
28
+ readonly explanation: string;
29
+ /** The minimal fix. */
30
+ readonly fix: string;
31
+ };
32
+ /**
33
+ * Set when Mostra no longer reports the code, saying what replaced it. Codes are never
34
+ * removed (AX-03).
35
+ */
36
+ readonly deprecated?: string;
37
+ }
38
+
39
+ /** The catalog of one area: exactly the codes `C`, each with its spec. */
40
+ export type AreaCatalog<C extends `MOSTRA_${DiagnosticArea}_${string}`> = {
41
+ readonly [K in C]: DiagnosticSpec;
42
+ };
43
+
44
+ /**
45
+ * Where diagnostics link by default: the GitHub Pages docs site (D37). Hosts and the runtime pass
46
+ * their own base when the docs move.
47
+ */
48
+ export const DEFAULT_DOCS_BASE: string = "https://mostra-dev.github.io/mostra";
49
+
50
+ /** The docs page for `code` under `docsBase`: `${docsBase}/errors/${code}`. */
51
+ export function docsUrl(code: string, docsBase: string = DEFAULT_DOCS_BASE): string {
52
+ let end = docsBase.length;
53
+ while (end > 0 && docsBase.charCodeAt(end - 1) === 47 /* "/" */) end--;
54
+ return `${docsBase.slice(0, end)}/errors/${code}`;
55
+ }
56
+
57
+ /** The parts of a diagnostic that belong to one occurrence rather than to its code. */
58
+ export interface DiagnosticDetails {
59
+ /** What is wrong, for this occurrence. Never include secrets or capability tokens. */
60
+ readonly message: string;
61
+ /** Replaces the catalog's default hint when the occurrence allows a more specific one. */
62
+ readonly hint?: string;
63
+ /** A machine-applicable fix. */
64
+ readonly fix?: DiagnosticFix;
65
+ /** Where the problem is. */
66
+ readonly location?: DiagnosticLocation;
67
+ /** How many identical occurrences this one stands for. */
68
+ readonly count?: number;
69
+ }
70
+
71
+ /**
72
+ * Builds a diagnostic for a cataloged code: severity, phase, hint and docs link come from `spec`,
73
+ * the rest from `details`.
74
+ */
75
+ export function buildDiagnostic(
76
+ code: Diagnostic["code"],
77
+ spec: DiagnosticSpec,
78
+ details: DiagnosticDetails,
79
+ docsBase: string = DEFAULT_DOCS_BASE,
80
+ ): Diagnostic {
81
+ const { hint = spec.hint, ...rest } = details;
82
+ return {
83
+ code,
84
+ severity: spec.severity,
85
+ phase: spec.phase,
86
+ docs: docsUrl(code, docsBase),
87
+ hint,
88
+ ...rest,
89
+ };
90
+ }
package/src/hygiene.ts ADDED
@@ -0,0 +1,224 @@
1
+ /**
2
+ * Request hygiene (D06, ARCHITECTURE §10, HY-01): the checks every Mostra HTTP endpoint applies
3
+ * before it acts on a request, as pure functions with no I/O. The gateway runs them on every
4
+ * request, and `mostra mcp --http` (WP-15) runs the same code (D96), so a request a stranger's
5
+ * page could send is refused the same way everywhere. None of them limits what an artifact, an
6
+ * agent or a viewer may do; they only make sure a request comes from the page it claims to.
7
+ *
8
+ * ```ts
9
+ * const refusal = checkRequest(
10
+ * { origin: "http://127.0.0.1:23456", hosts: ["127.0.0.1:23456"] },
11
+ * { method: "POST", target: "/a/art_…/_mostra/ticket", headers, intent: "mutation", csrf },
12
+ * );
13
+ * if (refusal) return respond(refusal.status, refusal.diagnostic);
14
+ * ```
15
+ */
16
+ import { type HygieneDiagnosticCode, hygieneDiagnostics } from "./diagnostics/codes/hygiene.ts";
17
+ import type { Diagnostic } from "./diagnostics/diagnostic.ts";
18
+ import { buildDiagnostic } from "./diagnostics/spec.ts";
19
+
20
+ /** What one listener serves: its own origin and the exact `Host` values it accepts. */
21
+ export interface RequestPolicy {
22
+ /** The listener's origin, such as `http://127.0.0.1:23456`; `Origin` headers must equal it. */
23
+ readonly origin: string;
24
+ /** Every `host:port` this listener answers to (lowercase): its URL host, plus registered tunnels. */
25
+ readonly hosts: readonly string[];
26
+ }
27
+
28
+ /**
29
+ * What a request is for, which decides the checks beyond the envelope:
30
+ * - `read`: a GET or HEAD of a page or file; a foreign `Origin` is refused, none is fine.
31
+ * - `stream`: an event stream (GET); same-origin only, by `Origin` or `Sec-Fetch-Site`.
32
+ * - `upgrade`: a WebSocket upgrade; `Origin` must be present and equal.
33
+ * - `exchange`: a mutation that starts a session (a capability token or ticket in the body):
34
+ * `Origin` and a JSON content type, but no CSRF token yet.
35
+ * - `mutation`: any other state change: `Origin`, a JSON content type and the session's CSRF
36
+ * token in `X-Mostra-CSRF`.
37
+ */
38
+ export type RequestIntent = "read" | "stream" | "upgrade" | "exchange" | "mutation";
39
+
40
+ /** One request as the transport received it. */
41
+ export interface RequestFacts {
42
+ /** The method, as sent. */
43
+ readonly method: string;
44
+ /** The request target exactly as sent: an origin-form path with its query. */
45
+ readonly target: string;
46
+ /** Every header as `[name, value]` in arrival order, so repeated headers are visible. */
47
+ readonly headers: readonly (readonly [string, string])[];
48
+ /** The intent the matched route declared; omit to check only the envelope. */
49
+ readonly intent?: RequestIntent;
50
+ /** The session's CSRF token, for `mutation` requests. */
51
+ readonly csrf?: string;
52
+ }
53
+
54
+ /** A refused request: the HTTP status to answer with and the diagnostic for its body. */
55
+ export interface Refusal {
56
+ /** The HTTP status: 400, 401, 403, 404, 410, 415, 421 or 429. */
57
+ readonly status: number;
58
+ /** What was refused and why, for the response body and the log. */
59
+ readonly diagnostic: Diagnostic;
60
+ }
61
+
62
+ /** The header that carries a session's CSRF token on every mutation (D98). */
63
+ export const CSRF_HEADER = "x-mostra-csrf";
64
+
65
+ const STATUS: Readonly<Record<HygieneDiagnosticCode, number>> = {
66
+ MOSTRA_HYGIENE_HOST_REFUSED: 421,
67
+ MOSTRA_HYGIENE_ORIGIN_REFUSED: 403,
68
+ MOSTRA_HYGIENE_CSRF_MISSING: 403,
69
+ MOSTRA_HYGIENE_CONTENT_TYPE: 415,
70
+ MOSTRA_HYGIENE_REQUEST_MALFORMED: 400,
71
+ MOSTRA_HYGIENE_SESSION_MISSING: 401,
72
+ MOSTRA_HYGIENE_TOKEN_INVALID: 401,
73
+ MOSTRA_HYGIENE_TOKEN_REVOKED: 410,
74
+ MOSTRA_HYGIENE_SCOPE_DENIED: 403,
75
+ MOSTRA_HYGIENE_RATE_LIMITED: 429,
76
+ MOSTRA_HYGIENE_NOT_SERVED: 404,
77
+ MOSTRA_HYGIENE_SESSION_CONFLICT: 409,
78
+ MOSTRA_HYGIENE_HEADERS_TOO_LARGE: 431,
79
+ };
80
+
81
+ /** Builds a refusal with the status the code's HTTP mapping gives (FAILURE_MODEL §8). */
82
+ export function refusal(code: HygieneDiagnosticCode, message: string, status?: number): Refusal {
83
+ return {
84
+ status: status ?? STATUS[code],
85
+ diagnostic: buildDiagnostic(code, hygieneDiagnostics[code], { message }),
86
+ };
87
+ }
88
+
89
+ /** Headers that must appear at most once: a second copy could mean two different things. */
90
+ const SINGLE = new Set(["host", "origin", "content-type", "content-length", CSRF_HEADER, "cookie"]);
91
+
92
+ /** Characters no header value or path may carry: controls other than tab, and DEL. */
93
+ // biome-ignore lint/suspicious/noControlCharactersInRegex: matching control characters is the point.
94
+ const CONTROL = /[\u0000-\u0008\u000a-\u001f\u007f]/;
95
+
96
+ /** Constant-time comparison of two strings, so timing reveals nothing about a secret. */
97
+ export function safeEqual(a: string, b: string): boolean {
98
+ let difference = a.length ^ b.length;
99
+ const length = Math.max(a.length, b.length);
100
+ for (let index = 0; index < length; index++) {
101
+ difference |= (a.charCodeAt(index) | 0) ^ (b.charCodeAt(index) | 0);
102
+ }
103
+ return difference === 0;
104
+ }
105
+
106
+ /**
107
+ * The path a request target names, decoded, or `undefined` when it isn't a safe origin-form path:
108
+ * absolute and authority forms, `*`, encoded `/` or `\`, `.` or `..` segments (encoded or not),
109
+ * NUL and other controls, and invalid percent-encoding are all refused.
110
+ */
111
+ export function safePath(target: string): string | undefined {
112
+ if (!target.startsWith("/") || target.startsWith("//")) return undefined;
113
+ const end = target.search(/[?#]/);
114
+ const raw = end < 0 ? target : target.slice(0, end);
115
+ if (/%(2f|5c)/i.test(raw) || raw.includes("\\")) return undefined;
116
+ let path: string;
117
+ try {
118
+ path = decodeURIComponent(raw);
119
+ } catch {
120
+ return undefined;
121
+ }
122
+ if (CONTROL.test(path) || path.includes("\u0000")) return undefined;
123
+ if (path.split("/").some((segment) => segment === "." || segment === "..")) return undefined;
124
+ return path;
125
+ }
126
+
127
+ /** The value of a header (case-insensitive name), or `undefined`. */
128
+ export function headerValue(
129
+ headers: readonly (readonly [string, string])[],
130
+ name: string,
131
+ ): string | undefined {
132
+ const lower = name.toLowerCase();
133
+ return headers.find(([key]) => key.toLowerCase() === lower)?.[1];
134
+ }
135
+
136
+ /** Whether a `Content-Type` value is JSON (`application/json`, any parameters). */
137
+ export function isJsonContentType(value: string | undefined): boolean {
138
+ if (value === undefined) return false;
139
+ return value.split(";")[0]?.trim().toLowerCase() === "application/json";
140
+ }
141
+
142
+ /**
143
+ * Checks a request's envelope (the `Host` allowlist, the request target, repeated and malformed
144
+ * headers) and, when `intent` is given, what that intent needs: `Origin`, the JSON content type
145
+ * and the CSRF token. Returns the first refusal, or `undefined` when the request may proceed.
146
+ * Session, token and scope checks follow in the endpoint, which knows its session.
147
+ */
148
+ export function checkRequest(policy: RequestPolicy, request: RequestFacts): Refusal | undefined {
149
+ const counts = new Map<string, number>();
150
+ for (const [name, value] of request.headers) {
151
+ const lower = name.toLowerCase();
152
+ counts.set(lower, (counts.get(lower) ?? 0) + 1);
153
+ if (CONTROL.test(value)) {
154
+ return refusal(
155
+ "MOSTRA_HYGIENE_REQUEST_MALFORMED",
156
+ `The ${lower} header has control characters.`,
157
+ );
158
+ }
159
+ }
160
+ for (const name of SINGLE) {
161
+ if ((counts.get(name) ?? 0) > 1) {
162
+ return refusal("MOSTRA_HYGIENE_REQUEST_MALFORMED", `The request repeats the ${name} header.`);
163
+ }
164
+ }
165
+ const host = headerValue(request.headers, "host")?.toLowerCase();
166
+ if (host === undefined || !policy.hosts.includes(host)) {
167
+ return refusal(
168
+ "MOSTRA_HYGIENE_HOST_REFUSED",
169
+ host === undefined
170
+ ? "The request has no Host header."
171
+ : "The request's Host isn't one this listener serves.",
172
+ );
173
+ }
174
+ if (safePath(request.target) === undefined) {
175
+ return refusal(
176
+ "MOSTRA_HYGIENE_REQUEST_MALFORMED",
177
+ "The request target isn't a plain path inside the served tree.",
178
+ );
179
+ }
180
+ if (request.intent === undefined) return undefined;
181
+
182
+ const origin = headerValue(request.headers, "origin");
183
+ switch (request.intent) {
184
+ case "read":
185
+ if (origin !== undefined && origin !== policy.origin) {
186
+ return refusal("MOSTRA_HYGIENE_ORIGIN_REFUSED", "The request came from another origin.");
187
+ }
188
+ return undefined;
189
+ case "stream": {
190
+ const site = headerValue(request.headers, "sec-fetch-site");
191
+ const sameOrigin = origin === undefined ? site === "same-origin" : origin === policy.origin;
192
+ return sameOrigin
193
+ ? undefined
194
+ : refusal("MOSTRA_HYGIENE_ORIGIN_REFUSED", "A stream must be opened by its own origin.");
195
+ }
196
+ case "upgrade":
197
+ case "exchange":
198
+ case "mutation": {
199
+ if (origin !== policy.origin) {
200
+ return refusal(
201
+ "MOSTRA_HYGIENE_ORIGIN_REFUSED",
202
+ origin === undefined
203
+ ? "The request has no Origin header."
204
+ : "The request came from another origin.",
205
+ );
206
+ }
207
+ if (request.intent === "upgrade") return undefined;
208
+ if (!isJsonContentType(headerValue(request.headers, "content-type"))) {
209
+ return refusal("MOSTRA_HYGIENE_CONTENT_TYPE", "The request's body isn't declared as JSON.");
210
+ }
211
+ if (request.intent === "exchange") return undefined;
212
+ const sent = headerValue(request.headers, CSRF_HEADER);
213
+ if (request.csrf === undefined || sent === undefined || !safeEqual(sent, request.csrf)) {
214
+ return refusal(
215
+ "MOSTRA_HYGIENE_CSRF_MISSING",
216
+ sent === undefined
217
+ ? `The request has no ${CSRF_HEADER} header.`
218
+ : `The request's ${CSRF_HEADER} header doesn't match its session.`,
219
+ );
220
+ }
221
+ return undefined;
222
+ }
223
+ }
224
+ }