@wirebench/engine 2.2.1 → 3.1.0-rc.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (566) hide show
  1. package/README.md +134 -1
  2. package/dist/account/schema.d.ts +34 -0
  3. package/dist/account/schema.js +29 -0
  4. package/dist/assert/callback.d.ts +76 -0
  5. package/dist/assert/callback.js +320 -0
  6. package/dist/assert/capture-source.d.ts +50 -0
  7. package/dist/assert/capture-source.js +89 -0
  8. package/dist/assert/check.d.ts +8 -0
  9. package/dist/assert/check.js +18 -0
  10. package/dist/assert/header.d.ts +5 -0
  11. package/dist/assert/header.js +48 -0
  12. package/dist/assert/index.d.ts +2 -2
  13. package/dist/assert/index.js +12 -0
  14. package/dist/assert/match.d.ts +6 -0
  15. package/dist/assert/match.js +13 -4
  16. package/dist/assert/model.d.ts +110 -3
  17. package/dist/assert/model.js +16 -1
  18. package/dist/assert/schema.d.ts +194 -1
  19. package/dist/assert/schema.js +154 -12
  20. package/dist/assert/status-names.d.ts +9 -0
  21. package/dist/assert/status-names.js +27 -0
  22. package/dist/assert/status.d.ts +4 -1
  23. package/dist/assert/status.js +27 -3
  24. package/dist/asyncapi/browser.d.ts +7 -0
  25. package/dist/asyncapi/browser.js +6 -0
  26. package/dist/asyncapi/frame-check-worker-host.d.ts +44 -0
  27. package/dist/asyncapi/frame-check-worker-host.js +175 -0
  28. package/dist/asyncapi/frame-check-worker.d.ts +12 -0
  29. package/dist/asyncapi/frame-check-worker.js +25 -0
  30. package/dist/asyncapi/frame-check.d.ts +25 -0
  31. package/dist/asyncapi/frame-check.js +78 -0
  32. package/dist/asyncapi/import.d.ts +25 -0
  33. package/dist/asyncapi/import.js +34 -0
  34. package/dist/asyncapi/map.d.ts +40 -0
  35. package/dist/asyncapi/map.js +230 -0
  36. package/dist/asyncapi/model.d.ts +84 -0
  37. package/dist/asyncapi/model.js +7 -0
  38. package/dist/asyncapi/normalise-2.d.ts +13 -0
  39. package/dist/asyncapi/normalise-2.js +113 -0
  40. package/dist/asyncapi/normalise-3.d.ts +14 -0
  41. package/dist/asyncapi/normalise-3.js +133 -0
  42. package/dist/asyncapi/parse.d.ts +31 -0
  43. package/dist/asyncapi/parse.js +85 -0
  44. package/dist/asyncapi/read.d.ts +35 -0
  45. package/dist/asyncapi/read.js +186 -0
  46. package/dist/asyncapi/security.d.ts +14 -0
  47. package/dist/asyncapi/security.js +55 -0
  48. package/dist/asyncapi/update.d.ts +53 -0
  49. package/dist/asyncapi/update.js +220 -0
  50. package/dist/errors.d.ts +16 -0
  51. package/dist/errors.js +22 -0
  52. package/dist/grpc/events.d.ts +22 -0
  53. package/dist/grpc/events.js +1 -0
  54. package/dist/grpc/expand.d.ts +1 -1
  55. package/dist/grpc/expand.js +15 -5
  56. package/dist/grpc/files.d.ts +271 -0
  57. package/dist/grpc/files.js +62 -0
  58. package/dist/grpc/model.d.ts +11 -1
  59. package/dist/grpc/module.d.ts +2 -0
  60. package/dist/grpc/module.js +13 -0
  61. package/dist/grpc/run.d.ts +73 -0
  62. package/dist/grpc/run.js +407 -0
  63. package/dist/grpc/script-types.d.ts +8 -0
  64. package/dist/grpc/script-types.js +149 -0
  65. package/dist/grpc/scripting.d.ts +34 -0
  66. package/dist/grpc/scripting.js +147 -0
  67. package/dist/grpc/send-input.d.ts +46 -0
  68. package/dist/grpc/send-input.js +42 -0
  69. package/dist/grpc/send.d.ts +2 -2
  70. package/dist/grpc/status.d.ts +9 -2
  71. package/dist/grpc/status.js +11 -24
  72. package/dist/grpc/storage.d.ts +9 -0
  73. package/dist/grpc/storage.js +167 -0
  74. package/dist/{rest/auth.d.ts → http/auth/apply-auth.d.ts} +4 -4
  75. package/dist/{rest/auth.js → http/auth/apply-auth.js} +1 -1
  76. package/dist/http/auth/apply.d.ts +1 -1
  77. package/dist/{rest → http/auth}/oauth2.d.ts +2 -2
  78. package/dist/{rest → http/auth}/oauth2.js +1 -1
  79. package/dist/http/auth/send-auth.d.ts +57 -0
  80. package/dist/http/auth/send-auth.js +7 -0
  81. package/dist/http/client.js +150 -8
  82. package/dist/http/cookies.d.ts +79 -0
  83. package/dist/http/cookies.js +81 -0
  84. package/dist/http/curl.d.ts +4 -14
  85. package/dist/http/curl.js +4 -154
  86. package/dist/http/decompress.d.ts +7 -0
  87. package/dist/http/decompress.js +23 -1
  88. package/dist/http/document-fetch.d.ts +42 -0
  89. package/dist/http/document-fetch.js +207 -0
  90. package/dist/http/entries.d.ts +27 -0
  91. package/dist/http/entries.js +16 -0
  92. package/dist/http/escape.d.ts +18 -0
  93. package/dist/http/escape.js +30 -0
  94. package/dist/http/fetch-document.d.ts +28 -0
  95. package/dist/{wsdl/fetch.js → http/fetch-document.js} +8 -16
  96. package/dist/http/media-type.d.ts +9 -0
  97. package/dist/http/media-type.js +12 -0
  98. package/dist/http/transcript-cap.d.ts +26 -0
  99. package/dist/http/transcript-cap.js +36 -0
  100. package/dist/http/types.d.ts +59 -0
  101. package/dist/http/webhook-signature.d.ts +81 -0
  102. package/dist/http/webhook-signature.js +227 -0
  103. package/dist/import-detect.d.ts +2 -2
  104. package/dist/import-detect.js +10 -1
  105. package/dist/index.d.ts +207 -55
  106. package/dist/index.js +129 -32
  107. package/dist/json/cursor.d.ts +2 -0
  108. package/dist/json/cursor.js +1 -0
  109. package/dist/json/pointer-range.d.ts +18 -0
  110. package/dist/json/pointer-range.js +157 -0
  111. package/dist/json/schema/model.d.ts +59 -0
  112. package/dist/json/schema/model.js +8 -0
  113. package/dist/json/schema/parse-text.d.ts +16 -0
  114. package/dist/json/schema/parse-text.js +37 -0
  115. package/dist/{rest/openapi → json/schema}/refs.d.ts +2 -2
  116. package/dist/{rest/openapi → json/schema}/refs.js +3 -3
  117. package/dist/{rest/openapi → json/schema}/sample.d.ts +4 -0
  118. package/dist/{rest/openapi → json/schema}/sample.js +2 -2
  119. package/dist/json/schema/source.d.ts +21 -0
  120. package/dist/json/schema/source.js +8 -0
  121. package/dist/json/schema-validate.d.ts +49 -0
  122. package/dist/json/schema-validate.js +557 -0
  123. package/dist/{wss/keystore → keystore}/index.js +1 -1
  124. package/dist/{wss/keystore → keystore}/pem.js +1 -1
  125. package/dist/{wss/keystore → keystore}/pkcs12.js +1 -1
  126. package/dist/project/attachments-cache.d.ts +3 -1
  127. package/dist/{wsdl → project}/cache-naming.js +1 -1
  128. package/dist/project/endpoints.d.ts +18 -8
  129. package/dist/project/endpoints.js +21 -6
  130. package/dist/project/environments.d.ts +7 -5
  131. package/dist/project/history.d.ts +105 -9
  132. package/dist/project/history.js +195 -23
  133. package/dist/project/inherit.d.ts +7 -0
  134. package/dist/project/inherit.js +9 -0
  135. package/dist/project/keystores.d.ts +1 -1
  136. package/dist/project/load-helpers.d.ts +89 -0
  137. package/dist/project/load-helpers.js +177 -0
  138. package/dist/project/load.d.ts +30 -4
  139. package/dist/project/load.js +168 -545
  140. package/dist/project/managed-files.d.ts +36 -0
  141. package/dist/project/managed-files.js +97 -0
  142. package/dist/project/migrate.d.ts +2 -2
  143. package/dist/project/migrate.js +2 -2
  144. package/dist/project/model.d.ts +92 -14
  145. package/dist/project/model.js +50 -4
  146. package/dist/project/paths.d.ts +10 -1
  147. package/dist/project/paths.js +10 -1
  148. package/dist/project/preferences.d.ts +11 -2
  149. package/dist/project/preferences.js +5 -1
  150. package/dist/project/properties.d.ts +31 -17
  151. package/dist/project/properties.js +89 -70
  152. package/dist/project/request-location.d.ts +20 -0
  153. package/dist/project/request-location.js +62 -0
  154. package/dist/project/save.d.ts +12 -2
  155. package/dist/project/save.js +186 -141
  156. package/dist/project/schema-parts.d.ts +337 -0
  157. package/dist/project/schema-parts.js +248 -0
  158. package/dist/project/schema.d.ts +72 -928
  159. package/dist/project/schema.js +17 -466
  160. package/dist/project/sequence-guards.d.ts +43 -0
  161. package/dist/project/sequence-guards.js +109 -0
  162. package/dist/project/serialize-helpers.d.ts +60 -0
  163. package/dist/project/serialize-helpers.js +108 -0
  164. package/dist/project/serialize.d.ts +7 -8
  165. package/dist/project/serialize.js +34 -293
  166. package/dist/protocol/features.d.ts +51 -0
  167. package/dist/protocol/features.js +64 -0
  168. package/dist/protocol/index.d.ts +7 -0
  169. package/dist/protocol/index.js +4 -0
  170. package/dist/protocol/module.d.ts +247 -0
  171. package/dist/protocol/module.js +48 -0
  172. package/dist/protocol/registry.d.ts +42 -0
  173. package/dist/protocol/registry.js +47 -0
  174. package/dist/protocols.d.ts +77 -0
  175. package/dist/protocols.js +40 -0
  176. package/dist/redact/index.d.ts +12 -1
  177. package/dist/redact/index.js +55 -7
  178. package/dist/redact/literal.d.ts +10 -0
  179. package/dist/redact/literal.js +110 -12
  180. package/dist/rest/body.d.ts +2 -10
  181. package/dist/rest/body.js +3 -25
  182. package/dist/rest/browser.d.ts +4 -0
  183. package/dist/rest/browser.js +5 -0
  184. package/dist/rest/contract-check-worker-host.d.ts +36 -0
  185. package/dist/rest/contract-check-worker-host.js +158 -0
  186. package/dist/rest/contract-check-worker.d.ts +7 -0
  187. package/dist/rest/contract-check-worker.js +28 -0
  188. package/dist/rest/contract-check.d.ts +43 -0
  189. package/dist/rest/contract-check.js +217 -0
  190. package/dist/rest/cookie-jar.d.ts +62 -0
  191. package/dist/rest/cookie-jar.js +262 -0
  192. package/dist/rest/cookies.d.ts +6 -22
  193. package/dist/rest/cookies.js +6 -42
  194. package/dist/rest/curl.js +5 -1
  195. package/dist/rest/events.d.ts +12 -0
  196. package/dist/rest/events.js +1 -0
  197. package/dist/rest/expand.d.ts +6 -1
  198. package/dist/rest/expand.js +29 -11
  199. package/dist/rest/files.d.ts +439 -0
  200. package/dist/rest/files.js +107 -0
  201. package/dist/rest/json-form.d.ts +97 -0
  202. package/dist/rest/json-form.js +396 -0
  203. package/dist/rest/model.d.ts +35 -24
  204. package/dist/rest/model.js +6 -9
  205. package/dist/rest/module.d.ts +2 -0
  206. package/dist/rest/module.js +13 -0
  207. package/dist/rest/openapi/cache.d.ts +7 -2
  208. package/dist/rest/openapi/cache.js +2 -2
  209. package/dist/rest/openapi/import.d.ts +11 -16
  210. package/dist/rest/openapi/import.js +6 -2
  211. package/dist/rest/openapi/map.d.ts +38 -1
  212. package/dist/rest/openapi/map.js +151 -41
  213. package/dist/rest/openapi/match.d.ts +20 -0
  214. package/dist/rest/openapi/match.js +117 -0
  215. package/dist/rest/openapi/model.d.ts +33 -45
  216. package/dist/rest/openapi/parse.d.ts +3 -12
  217. package/dist/rest/openapi/parse.js +138 -67
  218. package/dist/rest/openapi/responses.d.ts +23 -0
  219. package/dist/rest/openapi/responses.js +59 -0
  220. package/dist/rest/openapi/runtime-expression.d.ts +69 -0
  221. package/dist/rest/openapi/runtime-expression.js +213 -0
  222. package/dist/rest/openapi/update.d.ts +116 -0
  223. package/dist/rest/openapi/update.js +456 -0
  224. package/dist/rest/postman/map.d.ts +1 -0
  225. package/dist/rest/postman/map.js +66 -4
  226. package/dist/rest/postman/model.d.ts +9 -0
  227. package/dist/rest/postman/parse.js +33 -10
  228. package/dist/rest/response.d.ts +2 -23
  229. package/dist/rest/response.js +3 -75
  230. package/dist/rest/run.d.ts +56 -0
  231. package/dist/rest/run.js +395 -0
  232. package/dist/rest/script-types.d.ts +7 -0
  233. package/dist/rest/script-types.js +83 -0
  234. package/dist/rest/scripting.d.ts +38 -0
  235. package/dist/rest/scripting.js +282 -0
  236. package/dist/rest/send-input.d.ts +54 -0
  237. package/dist/rest/send-input.js +73 -0
  238. package/dist/rest/send.d.ts +77 -4
  239. package/dist/rest/send.js +128 -7
  240. package/dist/rest/sse-transcript.d.ts +25 -0
  241. package/dist/rest/sse-transcript.js +95 -0
  242. package/dist/rest/sse.d.ts +43 -0
  243. package/dist/rest/sse.js +195 -0
  244. package/dist/rest/storage.d.ts +26 -0
  245. package/dist/rest/storage.js +262 -0
  246. package/dist/rest/url.d.ts +10 -4
  247. package/dist/rest/url.js +38 -5
  248. package/dist/run/baseline-update.d.ts +35 -0
  249. package/dist/run/baseline-update.js +97 -0
  250. package/dist/run/baseline.d.ts +42 -0
  251. package/dist/run/baseline.js +93 -0
  252. package/dist/run/context.d.ts +86 -0
  253. package/dist/run/context.js +31 -0
  254. package/dist/run/current-values.d.ts +32 -0
  255. package/dist/run/current-values.js +43 -0
  256. package/dist/run/event-queue.d.ts +14 -0
  257. package/dist/run/event-queue.js +46 -0
  258. package/dist/run/exchange.d.ts +62 -0
  259. package/dist/run/exchange.js +65 -0
  260. package/dist/run/host.d.ts +89 -0
  261. package/dist/run/host.js +1 -0
  262. package/dist/run/index.d.ts +20 -7
  263. package/dist/run/index.js +12 -4
  264. package/dist/run/oauth2-token.d.ts +42 -0
  265. package/dist/run/oauth2-token.js +92 -0
  266. package/dist/run/open.d.ts +12 -0
  267. package/dist/run/open.js +16 -0
  268. package/dist/run/run.d.ts +124 -4
  269. package/dist/run/run.js +293 -134
  270. package/dist/run/scope.d.ts +11 -0
  271. package/dist/run/scope.js +26 -0
  272. package/dist/run/script-support.d.ts +53 -0
  273. package/dist/run/script-support.js +68 -0
  274. package/dist/run/secret-needs.d.ts +11 -4
  275. package/dist/run/secret-needs.js +48 -96
  276. package/dist/run/select.d.ts +34 -25
  277. package/dist/run/select.js +45 -54
  278. package/dist/run/send-helpers.d.ts +93 -0
  279. package/dist/run/send-helpers.js +255 -0
  280. package/dist/run/tree.d.ts +50 -0
  281. package/dist/run/tree.js +54 -0
  282. package/dist/script/api/postman.d.ts +10 -0
  283. package/dist/script/api/postman.js +264 -0
  284. package/dist/script/api/prelude.d.ts +20 -0
  285. package/dist/script/api/prelude.js +215 -0
  286. package/dist/script/apply.d.ts +44 -0
  287. package/dist/script/apply.js +120 -0
  288. package/dist/script/check/host.d.ts +41 -0
  289. package/dist/script/check/host.js +143 -0
  290. package/dist/script/check/service.d.ts +52 -0
  291. package/dist/script/check/service.js +195 -0
  292. package/dist/script/check/worker.d.ts +1 -0
  293. package/dist/script/check/worker.js +40 -0
  294. package/dist/script/index.d.ts +16 -0
  295. package/dist/script/index.js +10 -0
  296. package/dist/script/lookup.d.ts +10 -0
  297. package/dist/script/lookup.js +23 -0
  298. package/dist/script/model.d.ts +82 -0
  299. package/dist/script/model.js +18 -0
  300. package/dist/script/props.d.ts +8 -0
  301. package/dist/script/props.js +28 -0
  302. package/dist/script/request-scripts.d.ts +83 -0
  303. package/dist/script/request-scripts.js +160 -0
  304. package/dist/script/run.d.ts +47 -0
  305. package/dist/script/run.js +146 -0
  306. package/dist/script/sandbox/execute.d.ts +26 -0
  307. package/dist/script/sandbox/execute.js +212 -0
  308. package/dist/script/sandbox/host-api.d.ts +27 -0
  309. package/dist/script/sandbox/host-api.js +101 -0
  310. package/dist/script/sandbox/host.d.ts +18 -0
  311. package/dist/script/sandbox/host.js +172 -0
  312. package/dist/script/sandbox/model.d.ts +69 -0
  313. package/dist/script/sandbox/model.js +24 -0
  314. package/dist/script/sandbox/worker.d.ts +1 -0
  315. package/dist/script/sandbox/worker.js +20 -0
  316. package/dist/script/send.d.ts +27 -0
  317. package/dist/script/send.js +76 -0
  318. package/dist/script/strip.d.ts +5 -0
  319. package/dist/script/strip.js +43 -0
  320. package/dist/script/types/api.d.ts +38 -0
  321. package/dist/script/types/api.js +113 -0
  322. package/dist/script/types/json-schema.d.ts +26 -0
  323. package/dist/script/types/json-schema.js +206 -0
  324. package/dist/secrets/env-names.d.ts +9 -1
  325. package/dist/secrets/env-names.js +17 -1
  326. package/dist/secrets/resolve.d.ts +44 -4
  327. package/dist/secrets/resolve.js +58 -1
  328. package/dist/secrets/scan/apply.d.ts +36 -0
  329. package/dist/secrets/scan/apply.js +194 -0
  330. package/dist/secrets/scan/rules.d.ts +32 -0
  331. package/dist/secrets/scan/rules.js +346 -0
  332. package/dist/secrets/scan/scan.d.ts +6 -0
  333. package/dist/secrets/scan/scan.js +57 -0
  334. package/dist/secrets/scan/walk.d.ts +70 -0
  335. package/dist/secrets/scan/walk.js +156 -0
  336. package/dist/secrets/secret-refs.d.ts +8 -0
  337. package/dist/secrets/secret-refs.js +25 -0
  338. package/dist/secrets/secret-token.d.ts +17 -0
  339. package/dist/secrets/secret-token.js +25 -0
  340. package/dist/sequence/file.d.ts +169 -0
  341. package/dist/sequence/file.js +237 -0
  342. package/dist/sequence/index.d.ts +7 -0
  343. package/dist/sequence/index.js +5 -0
  344. package/dist/sequence/load.d.ts +32 -0
  345. package/dist/sequence/load.js +56 -0
  346. package/dist/sequence/model.d.ts +115 -0
  347. package/dist/sequence/model.js +53 -0
  348. package/dist/sequence/run.d.ts +131 -0
  349. package/dist/sequence/run.js +191 -0
  350. package/dist/sequence/transfer.d.ts +24 -0
  351. package/dist/sequence/transfer.js +75 -0
  352. package/dist/server-api/audit.d.ts +455 -0
  353. package/dist/server-api/audit.js +186 -0
  354. package/dist/server-api/ci-tokens.d.ts +50 -0
  355. package/dist/server-api/ci-tokens.js +35 -0
  356. package/dist/server-api/hooks.d.ts +337 -0
  357. package/dist/server-api/hooks.js +152 -0
  358. package/dist/server-api/identity.d.ts +210 -0
  359. package/dist/server-api/identity.js +115 -0
  360. package/dist/server-api/licensing.d.ts +80 -0
  361. package/dist/server-api/licensing.js +53 -0
  362. package/dist/server-api/live.d.ts +132 -0
  363. package/dist/server-api/live.js +102 -0
  364. package/dist/server-api/meta.d.ts +31 -0
  365. package/dist/server-api/meta.js +21 -0
  366. package/dist/server-api/sync.d.ts +179 -0
  367. package/dist/server-api/sync.js +124 -0
  368. package/dist/server-api/teams.d.ts +306 -0
  369. package/dist/server-api/teams.js +113 -0
  370. package/dist/snapshot/diff.d.ts +30 -0
  371. package/dist/snapshot/diff.js +75 -0
  372. package/dist/snapshot/format.d.ts +17 -0
  373. package/dist/snapshot/format.js +40 -0
  374. package/dist/snapshot/golden-file.d.ts +45 -0
  375. package/dist/snapshot/golden-file.js +173 -0
  376. package/dist/snapshot/ignore.d.ts +14 -0
  377. package/dist/snapshot/ignore.js +79 -0
  378. package/dist/snapshot/index.d.ts +9 -0
  379. package/dist/snapshot/index.js +9 -0
  380. package/dist/snapshot/json-diff.d.ts +3 -0
  381. package/dist/snapshot/json-diff.js +93 -0
  382. package/dist/snapshot/xml-diff.d.ts +10 -0
  383. package/dist/snapshot/xml-diff.js +194 -0
  384. package/dist/soap/auth.d.ts +26 -0
  385. package/dist/soap/auth.js +54 -0
  386. package/dist/soap/curl.d.ts +20 -0
  387. package/dist/soap/curl.js +161 -0
  388. package/dist/soap/expand.d.ts +24 -0
  389. package/dist/soap/expand.js +95 -0
  390. package/dist/soap/files.d.ts +384 -0
  391. package/dist/soap/files.js +114 -0
  392. package/dist/soap/form-request.d.ts +13 -0
  393. package/dist/soap/form-request.js +2 -2
  394. package/dist/soap/generate.d.ts +12 -0
  395. package/dist/{generate.js → soap/generate.js} +4 -4
  396. package/dist/{import.d.ts → soap/import.d.ts} +4 -4
  397. package/dist/{import.js → soap/import.js} +13 -13
  398. package/dist/soap/json-operation.d.ts +35 -0
  399. package/dist/soap/json-operation.js +225 -0
  400. package/dist/soap/legacy-project/env-refs.d.ts +19 -0
  401. package/dist/soap/legacy-project/env-refs.js +105 -0
  402. package/dist/soap/legacy-project/map.d.ts +2 -2
  403. package/dist/soap/legacy-project/map.js +6 -0
  404. package/dist/soap/mime/multipart.d.ts +2 -2
  405. package/dist/soap/mime/multipart.js +2 -5
  406. package/dist/soap/mime/send-pipeline.d.ts +1 -1
  407. package/dist/soap/mime/send-pipeline.js +1 -1
  408. package/dist/soap/mime/types.d.ts +1 -3
  409. package/dist/soap/module.d.ts +2 -0
  410. package/dist/soap/module.js +13 -0
  411. package/dist/soap/namespace-scope.js +1 -1
  412. package/dist/soap/operations.d.ts +12 -0
  413. package/dist/{operations.js → soap/operations.js} +4 -4
  414. package/dist/soap/run.d.ts +70 -0
  415. package/dist/soap/run.js +549 -0
  416. package/dist/soap/script-types.d.ts +65 -0
  417. package/dist/soap/script-types.js +379 -0
  418. package/dist/soap/scripting.d.ts +45 -0
  419. package/dist/soap/scripting.js +221 -0
  420. package/dist/soap/send-input.d.ts +61 -0
  421. package/dist/{send-options.js → soap/send-input.js} +5 -109
  422. package/dist/{send.d.ts → soap/send.d.ts} +1 -1
  423. package/dist/{send.js → soap/send.js} +28 -12
  424. package/dist/soap/storage.d.ts +9 -0
  425. package/dist/soap/storage.js +237 -0
  426. package/dist/soap/transforms.d.ts +3 -12
  427. package/dist/soap/transforms.js +3 -14
  428. package/dist/{types.d.ts → soap/types.d.ts} +34 -84
  429. package/dist/sync/git-cli.d.ts +202 -0
  430. package/dist/sync/git-cli.js +684 -0
  431. package/dist/sync/three-way-merge.d.ts +41 -0
  432. package/dist/sync/three-way-merge.js +85 -0
  433. package/dist/sync/tree-paths.d.ts +34 -0
  434. package/dist/sync/tree-paths.js +131 -0
  435. package/dist/team-secrets/envelope.d.ts +10 -0
  436. package/dist/team-secrets/envelope.js +121 -0
  437. package/dist/team-secrets/errors.d.ts +26 -0
  438. package/dist/team-secrets/errors.js +27 -0
  439. package/dist/team-secrets/index.d.ts +14 -0
  440. package/dist/team-secrets/index.js +8 -0
  441. package/dist/team-secrets/keys.d.ts +52 -0
  442. package/dist/team-secrets/keys.js +158 -0
  443. package/dist/team-secrets/log.d.ts +48 -0
  444. package/dist/team-secrets/log.js +175 -0
  445. package/dist/team-secrets/resolve-conflict.d.ts +7 -0
  446. package/dist/team-secrets/resolve-conflict.js +14 -0
  447. package/dist/team-secrets/schema.d.ts +97 -0
  448. package/dist/team-secrets/schema.js +157 -0
  449. package/dist/team-secrets/sign.d.ts +24 -0
  450. package/dist/team-secrets/sign.js +71 -0
  451. package/dist/team-secrets/vault.d.ts +49 -0
  452. package/dist/team-secrets/vault.js +148 -0
  453. package/dist/validate/wsi/run-message.d.ts +2 -2
  454. package/dist/validate/wsi/run-message.js +1 -1
  455. package/dist/validate/wsi/run-wsdl.d.ts +2 -2
  456. package/dist/validate/wsi/run-wsdl.js +1 -1
  457. package/dist/validate/wsi/types.d.ts +1 -1
  458. package/dist/webhooks/model.d.ts +138 -0
  459. package/dist/webhooks/model.js +150 -0
  460. package/dist/workspace/commit-message.d.ts +1 -1
  461. package/dist/workspace/commit-message.js +6 -1
  462. package/dist/workspace/environments.d.ts +11 -4
  463. package/dist/workspace/environments.js +12 -0
  464. package/dist/workspace/index.d.ts +3 -3
  465. package/dist/workspace/index.js +2 -2
  466. package/dist/workspace/paths.d.ts +5 -2
  467. package/dist/workspace/paths.js +5 -2
  468. package/dist/workspace/schema.d.ts +7 -3
  469. package/dist/workspace/schema.js +24 -3
  470. package/dist/workspace/share.d.ts +30 -11
  471. package/dist/workspace/share.js +32 -6
  472. package/dist/ws/call.d.ts +1 -1
  473. package/dist/ws/call.js +2 -2
  474. package/dist/ws/connect.d.ts +60 -0
  475. package/dist/ws/connect.js +131 -0
  476. package/dist/ws/events.d.ts +17 -0
  477. package/dist/ws/events.js +1 -0
  478. package/dist/ws/expand.d.ts +1 -1
  479. package/dist/ws/expand.js +1 -1
  480. package/dist/ws/files.d.ts +284 -0
  481. package/dist/ws/files.js +71 -0
  482. package/dist/ws/history-entry.d.ts +44 -0
  483. package/dist/ws/history-entry.js +93 -0
  484. package/dist/ws/model.d.ts +44 -3
  485. package/dist/ws/model.js +3 -0
  486. package/dist/ws/module.d.ts +2 -0
  487. package/dist/ws/module.js +11 -0
  488. package/dist/ws/run.d.ts +63 -0
  489. package/dist/ws/run.js +470 -0
  490. package/dist/ws/session.d.ts +18 -0
  491. package/dist/ws/session.js +52 -25
  492. package/dist/ws/storage.d.ts +9 -0
  493. package/dist/ws/storage.js +176 -0
  494. package/dist/ws/transcript.d.ts +3 -4
  495. package/dist/ws/transcript.js +26 -17
  496. package/dist/ws/url.d.ts +1 -1
  497. package/dist/wsdl/cache.js +1 -1
  498. package/dist/wsdl/docs-generator.d.ts +3 -3
  499. package/dist/wsdl/docs-generator.js +1 -1
  500. package/dist/wsdl/export-definition.js +1 -1
  501. package/dist/wsdl/qname.d.ts +2 -5
  502. package/dist/wsdl/resolver.d.ts +4 -11
  503. package/dist/wsdl/resolver.js +3 -3
  504. package/dist/wsdl/update-definition.d.ts +5 -5
  505. package/dist/wsdl/update-definition.js +6 -6
  506. package/dist/wss/apply.js +1 -1
  507. package/dist/{project/wss-configs.d.ts → wss/configs.d.ts} +2 -2
  508. package/dist/{project/wss-configs.js → wss/configs.js} +2 -2
  509. package/dist/wss/incoming/decrypt.d.ts +1 -1
  510. package/dist/wss/incoming/index.js +1 -1
  511. package/dist/wss/incoming/verify.d.ts +1 -1
  512. package/dist/wss/incoming/verify.js +1 -1
  513. package/dist/wss/key-identifiers.js +1 -1
  514. package/dist/wss/model.d.ts +1 -1
  515. package/dist/wss/outgoing/encryption.d.ts +1 -1
  516. package/dist/wss/outgoing/signature.d.ts +1 -1
  517. package/dist/xml/decode.d.ts +15 -0
  518. package/dist/xml/decode.js +22 -0
  519. package/dist/xml/entitize.d.ts +17 -0
  520. package/dist/xml/entitize.js +19 -0
  521. package/dist/xml/index.d.ts +1 -1
  522. package/dist/xml/index.js +1 -1
  523. package/dist/xml/locate.d.ts +39 -0
  524. package/dist/xml/locate.js +117 -0
  525. package/dist/xml/qname.d.ts +12 -0
  526. package/dist/xml/qname.js +8 -0
  527. package/dist/xpath/evaluate-async.d.ts +19 -0
  528. package/dist/xpath/evaluate-async.js +31 -11
  529. package/dist/xpath/evaluate.d.ts +1 -1
  530. package/dist/xpath/namespaces.js +1 -1
  531. package/dist/xpath/worker.d.ts +11 -5
  532. package/dist/xpath/worker.js +24 -7
  533. package/dist/xsd/form-model.d.ts +19 -2
  534. package/dist/xsd/form-model.js +14 -2
  535. package/dist/xsd/json-bridge.d.ts +152 -0
  536. package/dist/xsd/json-bridge.js +1213 -0
  537. package/dist/xsd/locate.d.ts +2 -30
  538. package/dist/xsd/locate.js +1 -109
  539. package/dist/xsd/xml-scan.d.ts +2 -0
  540. package/dist/xsd/xml-scan.js +1 -1
  541. package/dist/xsd/xml-writer.d.ts +2 -0
  542. package/dist/xsd/xml-writer.js +4 -0
  543. package/package.json +12 -1
  544. package/dist/generate.d.ts +0 -12
  545. package/dist/operations.d.ts +0 -12
  546. package/dist/run/effective-auth.d.ts +0 -10
  547. package/dist/run/effective-auth.js +0 -19
  548. package/dist/run/prepare.d.ts +0 -43
  549. package/dist/run/prepare.js +0 -280
  550. package/dist/send-options.d.ts +0 -141
  551. package/dist/wsdl/fetch.d.ts +0 -13
  552. /package/dist/{soap → http}/charset.d.ts +0 -0
  553. /package/dist/{soap → http}/charset.js +0 -0
  554. /package/dist/{wsdl → http}/ref-policy.d.ts +0 -0
  555. /package/dist/{wsdl → http}/ref-policy.js +0 -0
  556. /package/dist/{wss/keystore → keystore}/certificate.d.ts +0 -0
  557. /package/dist/{wss/keystore → keystore}/certificate.js +0 -0
  558. /package/dist/{wss/keystore → keystore}/index.d.ts +0 -0
  559. /package/dist/{wss/keystore → keystore}/model.d.ts +0 -0
  560. /package/dist/{wss/keystore → keystore}/model.js +0 -0
  561. /package/dist/{wss/keystore → keystore}/pem.d.ts +0 -0
  562. /package/dist/{wss/keystore → keystore}/pkcs12.d.ts +0 -0
  563. /package/dist/{wsdl → project}/cache-naming.d.ts +0 -0
  564. /package/dist/{types.js → soap/types.js} +0 -0
  565. /package/dist/{soap → xml}/prefixes.d.ts +0 -0
  566. /package/dist/{soap → xml}/prefixes.js +0 -0
package/dist/rest/send.js CHANGED
@@ -10,10 +10,14 @@
10
10
  */
11
11
  import { WirebenchError } from '../errors.js';
12
12
  import { sendWithAuth } from '../http/auth/apply.js';
13
- import { applyAuth } from './auth.js';
13
+ import { signWebhook } from '../http/webhook-signature.js';
14
+ import { applyAuth } from '../http/auth/apply-auth.js';
14
15
  import { encodeRestBody } from './body.js';
16
+ import { mergeCookieHeader } from './cookie-jar.js';
15
17
  import { cookieHeader } from './cookies.js';
16
18
  import { decodeResponseText, detectLanguage, parseSetCookie } from './response.js';
19
+ import { createSseParser, isEventStream } from './sse.js';
20
+ import { createSseRowStore } from './sse-transcript.js';
17
21
  import { composeUrl } from './url.js';
18
22
  /**
19
23
  * Merges the header sources in precedence order, lowest first: host defaults, then what the body
@@ -47,6 +51,31 @@ function mergeRequestHeaders(input) {
47
51
  }
48
52
  return Object.fromEntries([...merged.values()]);
49
53
  }
54
+ /** `headers` with the signing headers set over `body`, replacing any header of the same name. */
55
+ function withSignature(headers, sign, body) {
56
+ const out = { ...headers };
57
+ for (const [name, value] of signWebhook(sign.scheme, sign.secret, body)) {
58
+ for (const key of Object.keys(out)) {
59
+ if (key.toLowerCase() === name.toLowerCase())
60
+ delete out[key];
61
+ }
62
+ out[name] = value;
63
+ }
64
+ return out;
65
+ }
66
+ /**
67
+ * The credentials `applyAuth` put on the request, for `sendHttp` to keep to the request's origin
68
+ * across redirects. `Authorization` is dropped on a cross-origin hop anyway; an API key's custom
69
+ * header or query parameter is only known here.
70
+ */
71
+ function originCredentialsFor(applied) {
72
+ const headers = Object.keys(applied.headers);
73
+ const query = applied.query.map(({ name, value }) => ({ name, value }));
74
+ if (headers.length === 0 && query.length === 0) {
75
+ return {};
76
+ }
77
+ return { originCredentials: { headers, query } };
78
+ }
50
79
  /** The methods this transport will send. A custom method is passed through as given. */
51
80
  function methodFor(method) {
52
81
  return method.toUpperCase();
@@ -64,6 +93,7 @@ function methodFor(method) {
64
93
  * status is not a failure: it is a response, and the caller inspects it.
65
94
  *
66
95
  * @throws WirebenchError `rest-url-incomplete` when the URL could not be completed
96
+ * @throws WirebenchError `webhook-signing-secret` when a `standard` signing secret cannot be decoded
67
97
  */
68
98
  export async function sendRest(input) {
69
99
  const { request, settings } = input;
@@ -80,8 +110,8 @@ export async function sendRest(input) {
80
110
  ...(input.boundary !== undefined ? { boundary: input.boundary } : {}),
81
111
  ...(input.signal !== undefined ? { signal: input.signal } : {}),
82
112
  });
83
- const cookies = cookieHeader(input.cookies ?? []);
84
- const headers = mergeRequestHeaders({
113
+ const cookies = input.jar === undefined ? cookieHeader(input.cookies ?? []) : undefined;
114
+ const merged = mergeRequestHeaders({
85
115
  defaults: input.defaultHeaders ?? {},
86
116
  computed: {
87
117
  ...applied.headers,
@@ -90,6 +120,21 @@ export async function sendRest(input) {
90
120
  },
91
121
  typed: request.headers,
92
122
  });
123
+ // Signing runs last (§5.2): after auth, encoding and merging, so it signs the bytes that go out.
124
+ const headers = input.sign === undefined ? merged : withSignature(merged, input.sign, encoded.bytes ?? new Uint8Array());
125
+ const onStream = input.onStream;
126
+ const sseState = onStream !== undefined ? createSseState() : undefined;
127
+ // The jar stores every hop's cookies whatever the setting; it is read only when `send` is on.
128
+ const jar = input.jar;
129
+ const received = {};
130
+ const cookieHook = jar === undefined
131
+ ? undefined
132
+ : {
133
+ header: (url, handSet) => (jar.send ? mergeCookieHeader(jar.host.cookiesFor(url), handSet) : handSet),
134
+ received: (url, rawHeaders) => {
135
+ received.verdicts = jar.host.remember(url, parseSetCookie(rawHeaders));
136
+ },
137
+ };
93
138
  const httpRequest = {
94
139
  url: composed.url,
95
140
  method: methodFor(request.method),
@@ -100,21 +145,68 @@ export async function sendRest(input) {
100
145
  ...(settings.maxRedirects !== undefined ? { maxRedirects: settings.maxRedirects } : {}),
101
146
  ...(settings.keepBodyOnRedirect === true ? { preserveMethodOnRedirect: true } : {}),
102
147
  ...(settings.maxSizeBytes !== undefined ? { maxSizeBytes: settings.maxSizeBytes } : {}),
148
+ ...originCredentialsFor(applied),
103
149
  ...(settings.localAddress !== undefined ? { localAddress: settings.localAddress } : {}),
104
150
  ...(settings.allowH2 === true ? { allowH2: true } : {}),
105
151
  ...(settings.decompress !== undefined ? { decompress: settings.decompress } : {}),
106
152
  ...(input.tls !== undefined ? { tls: input.tls } : {}),
107
153
  ...(input.proxy !== undefined ? { proxy: input.proxy } : {}),
108
154
  ...(input.signal !== undefined ? { signal: input.signal } : {}),
155
+ ...(sseState !== undefined && onStream !== undefined ? { stream: sseState.hook(onStream) } : {}),
156
+ ...(cookieHook !== undefined ? { cookies: cookieHook } : {}),
109
157
  };
110
158
  // Basic and NTLM may need a round trip of their own; every other scheme is already in `headers`.
111
159
  const authenticated = await sendWithAuth(httpRequest, applied.transportAuth);
112
160
  return {
113
- ...decodeRestResponse(authenticated.http, methodFor(request.method)),
161
+ ...decodeRestResponse(authenticated.http, methodFor(request.method), sseState),
114
162
  ...(authenticated.auth !== undefined ? { auth: authenticated.auth } : {}),
163
+ // The last hop reported is the final response, whose cookies `cookies` lists.
164
+ ...(received.verdicts !== undefined ? { cookieVerdicts: received.verdicts } : {}),
115
165
  durationMs: authenticated.durationMs,
116
166
  };
117
167
  }
168
+ function createSseState() {
169
+ const store = createSseRowStore();
170
+ const counts = { events: 0, comments: 0, retries: 0, bytes: 0 };
171
+ const state = {
172
+ store,
173
+ counts,
174
+ lastEventId: '',
175
+ hook(onStream) {
176
+ return {
177
+ accept(status, headers) {
178
+ if (!isEventStream(headers['content-type']))
179
+ return undefined;
180
+ onStream.onOpen?.(status, headers);
181
+ const headersAt = performance.now();
182
+ const parser = createSseParser((row) => {
183
+ store.add(row);
184
+ counts.bytes += row.size;
185
+ if (row.kind === 'event') {
186
+ counts.events++;
187
+ state.lastEventId = row.lastEventId;
188
+ }
189
+ else if (row.kind === 'comment') {
190
+ counts.comments++;
191
+ }
192
+ else {
193
+ counts.retries++;
194
+ state.retryMs = row.ms;
195
+ }
196
+ onStream.onRow?.(row);
197
+ });
198
+ state.parser = parser;
199
+ return {
200
+ onChunk(bytes) {
201
+ parser.push(bytes, performance.now() - headersAt);
202
+ },
203
+ };
204
+ },
205
+ };
206
+ },
207
+ };
208
+ return state;
209
+ }
118
210
  /** The error a URL that cannot be completed raises, naming every problem at once. */
119
211
  function urlIncomplete(problems, url) {
120
212
  const missing = problems.filter((problem) => problem.code === 'missing-path-param').map((problem) => problem.name);
@@ -130,12 +222,26 @@ function urlIncomplete(problems, url) {
130
222
  * Split out so a response replayed from history or from the exchange cache is presented exactly as
131
223
  * a live one.
132
224
  */
133
- export function decodeRestResponse(exchange, sentMethod) {
225
+ export function decodeRestResponse(exchange, sentMethod, sse) {
226
+ const stream = buildEventStream(exchange, sse);
227
+ // Worked out once, for a streamed exchange and a buffered one alike: the redirect chain is the same.
228
+ const methodChanged = sentMethod !== 'GET' &&
229
+ exchange.redirects.some((hop) => hop.status === 303 || ((hop.status === 301 || hop.status === 302) && sentMethod === 'POST'));
230
+ if (stream !== undefined) {
231
+ // A streamed response has an empty body and no text form of its own; the rows are the content.
232
+ return {
233
+ ...exchange,
234
+ durationMs: exchange.timings.totalMs,
235
+ text: '',
236
+ language: 'text',
237
+ cookies: parseSetCookie(exchange.rawHeaders),
238
+ methodChanged,
239
+ stream,
240
+ };
241
+ }
134
242
  const contentType = exchange.headers['content-type'];
135
243
  const language = detectLanguage(contentType, exchange.body);
136
244
  const decoded = language === 'image' || language === 'binary' ? { text: '' } : decodeResponseText(exchange.body, contentType);
137
- const methodChanged = sentMethod !== 'GET' &&
138
- exchange.redirects.some((hop) => hop.status === 303 || ((hop.status === 301 || hop.status === 302) && sentMethod === 'POST'));
139
245
  return {
140
246
  ...exchange,
141
247
  durationMs: exchange.timings.totalMs,
@@ -146,3 +252,18 @@ export function decodeRestResponse(exchange, sentMethod) {
146
252
  methodChanged,
147
253
  };
148
254
  }
255
+ /** Finalizes the parser and builds the `RestEventStream`, when the response was accepted as one. */
256
+ function buildEventStream(exchange, sse) {
257
+ if (sse?.parser === undefined || exchange.streamEnd === undefined)
258
+ return undefined;
259
+ sse.parser.end();
260
+ return {
261
+ rows: sse.store.rows,
262
+ counts: { ...sse.counts },
263
+ lastEventId: sse.lastEventId,
264
+ ...(sse.retryMs !== undefined ? { retryMs: sse.retryMs } : {}),
265
+ endedBy: exchange.streamEnd.by,
266
+ ...(exchange.streamEnd.error !== undefined ? { error: exchange.streamEnd.error } : {}),
267
+ droppedRows: sse.store.droppedRows,
268
+ };
269
+ }
@@ -0,0 +1,25 @@
1
+ /**
2
+ * Caps on an SSE row list: the same head/tail/byte-budget shape as the WebSocket transcript's
3
+ * `capFrames`, shared via `capByEnds`, plus an in-memory store for a live stream that keeps growing.
4
+ */
5
+ import type { CapLimits } from '../http/transcript-cap.js';
6
+ import type { SseRow } from './sse.js';
7
+ export declare const SSE_MEMORY_ROWS = 10000;
8
+ export declare const SSE_MEMORY_BYTES = 33554432;
9
+ export declare const SSE_SUMMARY_LIMITS: CapLimits;
10
+ export declare const SSE_HISTORY_LIMITS: CapLimits;
11
+ export interface SseTranscript {
12
+ readonly rows: readonly SseRow[];
13
+ readonly truncated: boolean;
14
+ readonly omittedRows: number;
15
+ }
16
+ export declare function capSseRows(rows: readonly SseRow[], limits: CapLimits): SseTranscript;
17
+ export interface SseRowStore {
18
+ add(row: SseRow): void;
19
+ readonly rows: readonly SseRow[];
20
+ readonly droppedRows: number;
21
+ }
22
+ export declare function createSseRowStore(limits?: {
23
+ rows: number;
24
+ bytes: number;
25
+ }): SseRowStore;
@@ -0,0 +1,95 @@
1
+ import { capByEnds, WS_HISTORY_HEAD, WS_HISTORY_MAX_BYTES, WS_HISTORY_TAIL } from '../http/transcript-cap.js';
2
+ export const SSE_MEMORY_ROWS = 10_000;
3
+ export const SSE_MEMORY_BYTES = 33_554_432;
4
+ export const SSE_SUMMARY_LIMITS = { head: 400, tail: 4_600, maxBytes: SSE_MEMORY_BYTES };
5
+ export const SSE_HISTORY_LIMITS = {
6
+ head: WS_HISTORY_HEAD,
7
+ tail: WS_HISTORY_TAIL,
8
+ maxBytes: WS_HISTORY_MAX_BYTES,
9
+ };
10
+ function stripRow(row) {
11
+ if (row.kind !== 'event')
12
+ return undefined; // comment/retry rows keep their (small) text
13
+ return { ...row, data: '', payloadTruncated: true };
14
+ }
15
+ export function capSseRows(rows, limits) {
16
+ const r = capByEnds(rows, limits, (row) => row.size, stripRow);
17
+ return { rows: r.items, truncated: r.truncated, omittedRows: r.omitted };
18
+ }
19
+ const HEAD_CAP = 400;
20
+ /**
21
+ * A FIFO queue backed by a circular array, so pushing and evicting the oldest element are both O(1)
22
+ * (amortized for push, which occasionally doubles the backing array — never an O(n) shift). Used for
23
+ * the store's tail, which can hold thousands of rows on a long-running stream.
24
+ */
25
+ class RingBuffer {
26
+ buf = new Array(8).fill(undefined);
27
+ start = 0;
28
+ len = 0;
29
+ get length() {
30
+ return this.len;
31
+ }
32
+ push(item) {
33
+ if (this.len === this.buf.length)
34
+ this.grow();
35
+ this.buf[(this.start + this.len) % this.buf.length] = item;
36
+ this.len++;
37
+ }
38
+ evictFront() {
39
+ if (this.len === 0)
40
+ return undefined;
41
+ const item = this.buf[this.start];
42
+ this.buf[this.start] = undefined;
43
+ this.start = (this.start + 1) % this.buf.length;
44
+ this.len--;
45
+ return item;
46
+ }
47
+ toArray() {
48
+ const out = [];
49
+ for (let i = 0; i < this.len; i++)
50
+ out.push(this.buf[(this.start + i) % this.buf.length]);
51
+ return out;
52
+ }
53
+ grow() {
54
+ const next = new Array(this.buf.length * 2).fill(undefined);
55
+ for (let i = 0; i < this.len; i++)
56
+ next[i] = this.buf[(this.start + i) % this.buf.length];
57
+ this.buf = next;
58
+ this.start = 0;
59
+ }
60
+ }
61
+ export function createSseRowStore(limits = { rows: SSE_MEMORY_ROWS, bytes: SSE_MEMORY_BYTES }) {
62
+ const head = [];
63
+ const tail = new RingBuffer();
64
+ let headBytes = 0;
65
+ let tailBytes = 0;
66
+ let droppedRows = 0;
67
+ const headCap = Math.min(HEAD_CAP, limits.rows);
68
+ return {
69
+ add(row) {
70
+ if (head.length < headCap) {
71
+ // The head is never evicted: a byte budget smaller than the head's own bytes leaves the
72
+ // store permanently over budget rather than losing head rows (see the test that pins this).
73
+ head.push(row);
74
+ headBytes += row.size;
75
+ }
76
+ else {
77
+ tail.push(row);
78
+ tailBytes += row.size;
79
+ }
80
+ while (tail.length > 0 && (head.length + tail.length > limits.rows || headBytes + tailBytes > limits.bytes)) {
81
+ const dropped = tail.evictFront();
82
+ if (dropped === undefined)
83
+ break;
84
+ tailBytes -= dropped.size;
85
+ droppedRows++;
86
+ }
87
+ },
88
+ get rows() {
89
+ return [...head, ...tail.toArray()];
90
+ },
91
+ get droppedRows() {
92
+ return droppedRows;
93
+ },
94
+ };
95
+ }
@@ -0,0 +1,43 @@
1
+ /**
2
+ * An in-house parser for the `text/event-stream` format (the WHATWG event-stream rules), browser-safe
3
+ * and dependency-free so it can be shared between the desktop send path and the renderer's own
4
+ * decoding needs. Re-exported from `rest/browser.ts`, so this module must not import from `node:*`.
5
+ *
6
+ * A stream arrives as arbitrary byte chunks — a line, a field, even a single UTF-8 code point can be
7
+ * split across chunk boundaries — and the parser has to produce the same rows regardless of how the
8
+ * bytes were sliced. `createSseParser` does the incremental decode; `isEventStream` decides whether a
9
+ * response should go through it at all; `eventStreamDocument` and `serializeEventStream` turn a row
10
+ * list back into, respectively, the JSON document the Query view runs over and the event-stream text
11
+ * used for HAR export.
12
+ */
13
+ export type SseRow = {
14
+ readonly kind: 'event';
15
+ readonly index: number;
16
+ readonly at: number;
17
+ readonly size: number;
18
+ readonly event: string;
19
+ readonly data: string;
20
+ readonly id?: string;
21
+ readonly lastEventId: string;
22
+ readonly payloadTruncated?: true;
23
+ } | {
24
+ readonly kind: 'comment';
25
+ readonly index: number;
26
+ readonly at: number;
27
+ readonly size: number;
28
+ readonly text: string;
29
+ } | {
30
+ readonly kind: 'retry';
31
+ readonly index: number;
32
+ readonly at: number;
33
+ readonly size: number;
34
+ readonly ms: number;
35
+ };
36
+ export interface SseParser {
37
+ push(chunk: Uint8Array, at: number): void;
38
+ end(): void;
39
+ }
40
+ export declare function createSseParser(onRow: (row: SseRow) => void): SseParser;
41
+ export declare function isEventStream(contentType: string | undefined): boolean;
42
+ export declare function eventStreamDocument(rows: readonly SseRow[]): string;
43
+ export declare function serializeEventStream(rows: readonly SseRow[]): string;
@@ -0,0 +1,195 @@
1
+ /**
2
+ * An in-house parser for the `text/event-stream` format (the WHATWG event-stream rules), browser-safe
3
+ * and dependency-free so it can be shared between the desktop send path and the renderer's own
4
+ * decoding needs. Re-exported from `rest/browser.ts`, so this module must not import from `node:*`.
5
+ *
6
+ * A stream arrives as arbitrary byte chunks — a line, a field, even a single UTF-8 code point can be
7
+ * split across chunk boundaries — and the parser has to produce the same rows regardless of how the
8
+ * bytes were sliced. `createSseParser` does the incremental decode; `isEventStream` decides whether a
9
+ * response should go through it at all; `eventStreamDocument` and `serializeEventStream` turn a row
10
+ * list back into, respectively, the JSON document the Query view runs over and the event-stream text
11
+ * used for HAR export.
12
+ */
13
+ const enc = new TextEncoder();
14
+ /** UTF-8 byte length of a row's lines, each counted with its trailing LF (spec decision 4). */
15
+ function lineSize(...lines) {
16
+ return lines.reduce((sum, line) => sum + enc.encode(line).length + 1, 0);
17
+ }
18
+ export function createSseParser(onRow) {
19
+ const decoder = new TextDecoder('utf-8', { fatal: false });
20
+ let carry = '';
21
+ let sawText = false;
22
+ let pendingCr = false;
23
+ let index = 0;
24
+ /** The arrival time of the last chunk pushed, which is when anything `end()` flushes arrived. */
25
+ let lastAt = 0;
26
+ let eventType = '';
27
+ let dataLines = [];
28
+ let eventId;
29
+ let eventLines = [];
30
+ let lastEventId = '';
31
+ let hasData = false;
32
+ function resetEvent() {
33
+ eventType = '';
34
+ dataLines = [];
35
+ eventLines = [];
36
+ eventId = undefined;
37
+ hasData = false;
38
+ }
39
+ resetEvent();
40
+ function handleField(line, at) {
41
+ if (line === '') {
42
+ if (hasData) {
43
+ const data = dataLines.join('\n');
44
+ onRow({
45
+ kind: 'event',
46
+ index: index++,
47
+ at,
48
+ size: lineSize(...eventLines),
49
+ event: eventType === '' ? 'message' : eventType,
50
+ data,
51
+ ...(eventId !== undefined ? { id: eventId } : {}),
52
+ lastEventId,
53
+ });
54
+ }
55
+ resetEvent();
56
+ return;
57
+ }
58
+ if (line.startsWith(':')) {
59
+ const text = line.slice(1);
60
+ onRow({ kind: 'comment', index: index++, at, size: lineSize(line), text });
61
+ return;
62
+ }
63
+ const colon = line.indexOf(':');
64
+ let field;
65
+ let value;
66
+ if (colon === -1) {
67
+ field = line;
68
+ value = '';
69
+ }
70
+ else {
71
+ field = line.slice(0, colon);
72
+ value = line.slice(colon + 1);
73
+ if (value.startsWith(' '))
74
+ value = value.slice(1);
75
+ }
76
+ switch (field) {
77
+ case 'event':
78
+ eventType = value;
79
+ eventLines.push(line);
80
+ break;
81
+ case 'data':
82
+ dataLines.push(value);
83
+ eventLines.push(line);
84
+ hasData = true;
85
+ break;
86
+ case 'id':
87
+ if (!value.includes('\u0000')) {
88
+ eventId = value;
89
+ lastEventId = value;
90
+ }
91
+ eventLines.push(line);
92
+ break;
93
+ case 'retry':
94
+ if (/^[0-9]+$/.test(value)) {
95
+ onRow({ kind: 'retry', index: index++, at, size: lineSize(line), ms: Number(value) });
96
+ }
97
+ break;
98
+ default:
99
+ // unknown field: not dispatched, but its bytes still belong to the event they arrived in
100
+ eventLines.push(line);
101
+ break;
102
+ }
103
+ }
104
+ function consumeText(text, at) {
105
+ if (!sawText) {
106
+ sawText = true;
107
+ if (text.startsWith('\uFEFF'))
108
+ text = text.slice(1);
109
+ }
110
+ let buf = carry + text;
111
+ carry = '';
112
+ if (pendingCr) {
113
+ pendingCr = false;
114
+ if (buf.startsWith('\n'))
115
+ buf = buf.slice(1);
116
+ }
117
+ // Normalize CR/CRLF to LF, but hold back a trailing CR in case it's split from its LF: it already
118
+ // ends the line it closes, so a synthetic LF stands in for it once split.
119
+ let endsWithCr = false;
120
+ if (buf.endsWith('\r')) {
121
+ endsWithCr = true;
122
+ buf = buf.slice(0, -1);
123
+ }
124
+ let normalized = buf.replace(/\r\n|\r/g, '\n');
125
+ if (endsWithCr) {
126
+ pendingCr = true;
127
+ normalized += '\n';
128
+ }
129
+ const lines = normalized.split('\n');
130
+ carry = lines.pop() ?? '';
131
+ for (const line of lines)
132
+ handleField(line, at);
133
+ }
134
+ return {
135
+ push(chunk, at) {
136
+ lastAt = at;
137
+ const text = decoder.decode(chunk, { stream: true });
138
+ consumeText(text, at);
139
+ },
140
+ end() {
141
+ const text = decoder.decode();
142
+ if (text !== '')
143
+ consumeText(text, lastAt);
144
+ // An unterminated event at end of stream is discarded per spec.
145
+ },
146
+ };
147
+ }
148
+ export function isEventStream(contentType) {
149
+ if (contentType === undefined)
150
+ return false;
151
+ const mediaType = contentType.split(';', 1)[0]?.trim().toLowerCase();
152
+ return mediaType === 'text/event-stream';
153
+ }
154
+ export function eventStreamDocument(rows) {
155
+ const entries = rows
156
+ .filter((row) => row.kind === 'event')
157
+ .map((row) => {
158
+ let data = row.data;
159
+ try {
160
+ data = JSON.parse(row.data);
161
+ }
162
+ catch {
163
+ data = row.data;
164
+ }
165
+ return {
166
+ event: row.event,
167
+ ...(row.id !== undefined ? { id: row.id } : {}),
168
+ data,
169
+ at: row.at,
170
+ };
171
+ });
172
+ return JSON.stringify(entries);
173
+ }
174
+ export function serializeEventStream(rows) {
175
+ let out = '';
176
+ for (const row of rows) {
177
+ if (row.kind === 'comment') {
178
+ out += `:${row.text}\n\n`;
179
+ }
180
+ else if (row.kind === 'retry') {
181
+ out += `retry: ${row.ms}\n\n`;
182
+ }
183
+ else {
184
+ if (row.event !== 'message')
185
+ out += `event: ${row.event}\n`;
186
+ if (row.id !== undefined)
187
+ out += `id: ${row.id}\n`;
188
+ const dataLines = row.data.split('\n');
189
+ for (const line of dataLines)
190
+ out += `data: ${line}\n`;
191
+ out += '\n';
192
+ }
193
+ }
194
+ return out;
195
+ }
@@ -0,0 +1,26 @@
1
+ /**
2
+ * How REST APIs are stored in a project folder (spec §3.2): `apis/<slug>/api.yaml` with
3
+ * `kind: rest`, and a tree of folders and `*.request.yaml` files under `requests/`, a raw body in
4
+ * the sibling `<slug>.body.<ext>`.
5
+ *
6
+ * `restRequestReader` and `signingOf` are exported for core's loader, which reads the project's
7
+ * webhook collection (REST requests in a tree of their own) until phase 3 of #184 moves it here.
8
+ */
9
+ import type { FsLike } from '../project/fs.js';
10
+ import type { RequestReader } from '../project/load-helpers.js';
11
+ import type { ProjectProblem } from '../project/load.js';
12
+ import type { WebhookSigningFile } from '../project/schema-parts.js';
13
+ import type { RequestWriter } from '../project/serialize-helpers.js';
14
+ import type { ProtocolStorage } from '../protocol/module.js';
15
+ import type { WebhookSigning } from '../webhooks/model.js';
16
+ import type { RestApi, RestRequestDef } from './model.js';
17
+ /** A parsed `signing` key as the model holds it. */
18
+ export declare function signingOf(parsed: WebhookSigningFile): WebhookSigning;
19
+ /** Reads a REST request and its raw body file. */
20
+ export declare function restRequestReader(fs: FsLike, root: string, problems: ProjectProblem[]): RequestReader<RestRequestDef>;
21
+ /** A `signing` key as written: the scheme's own fields, and references only. */
22
+ export declare function signingDocument(signing: WebhookSigning | undefined): Record<string, unknown> | undefined;
23
+ /** A REST request as written: its document, its raw body file and its script files. Core writes the webhook collection's items with it. */
24
+ export declare const writeRestRequest: RequestWriter<RestRequestDef>;
25
+ /** REST's storage facet. */
26
+ export declare const restStorage: ProtocolStorage<RestApi>;