@halonicjs/testing 0.0.0 → 0.1.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 (438) hide show
  1. package/LICENSE +202 -0
  2. package/NOTICE +5 -0
  3. package/README.md +41 -1
  4. package/dist/adapters/http-kit/src/address-checking.d.ts +19 -0
  5. package/dist/adapters/http-kit/src/address-checking.js +1 -0
  6. package/dist/adapters/http-kit/src/address-class.d.ts +34 -0
  7. package/dist/adapters/http-kit/src/address-class.js +109 -0
  8. package/dist/adapters/http-kit/src/index.d.ts +3 -0
  9. package/dist/adapters/http-kit/src/index.js +2 -0
  10. package/dist/adapters/http-kit/src/ip-address.d.ts +23 -0
  11. package/dist/adapters/http-kit/src/ip-address.js +89 -0
  12. package/dist/adapters/integration-kit/src/auth-placement.d.ts +40 -0
  13. package/dist/adapters/integration-kit/src/auth-placement.js +102 -0
  14. package/dist/adapters/integration-kit/src/current-secret-forms.d.ts +28 -0
  15. package/dist/adapters/integration-kit/src/current-secret-forms.js +60 -0
  16. package/dist/adapters/integration-kit/src/declaration.d.ts +15 -0
  17. package/dist/adapters/integration-kit/src/declaration.js +78 -0
  18. package/dist/adapters/integration-kit/src/host.d.ts +34 -0
  19. package/dist/adapters/integration-kit/src/host.js +31 -0
  20. package/dist/adapters/integration-kit/src/index.d.ts +16 -0
  21. package/dist/adapters/integration-kit/src/index.js +22 -0
  22. package/dist/adapters/integration-kit/src/leak-attempt.d.ts +16 -0
  23. package/dist/adapters/integration-kit/src/leak-attempt.js +19 -0
  24. package/dist/adapters/integration-kit/src/limited-http.d.ts +55 -0
  25. package/dist/adapters/integration-kit/src/limited-http.js +225 -0
  26. package/dist/adapters/integration-kit/src/load-problem.d.ts +20 -0
  27. package/dist/adapters/integration-kit/src/load-problem.js +1 -0
  28. package/dist/adapters/integration-kit/src/loader.d.ts +131 -0
  29. package/dist/adapters/integration-kit/src/loader.js +251 -0
  30. package/dist/adapters/integration-kit/src/local-address.d.ts +15 -0
  31. package/dist/adapters/integration-kit/src/local-address.js +25 -0
  32. package/dist/adapters/integration-kit/src/own-request.d.ts +33 -0
  33. package/dist/adapters/integration-kit/src/own-request.js +36 -0
  34. package/dist/adapters/integration-kit/src/plugin-load.d.ts +14 -0
  35. package/dist/adapters/integration-kit/src/plugin-load.js +58 -0
  36. package/dist/adapters/integration-kit/src/policy.d.ts +83 -0
  37. package/dist/adapters/integration-kit/src/policy.js +37 -0
  38. package/dist/adapters/integration-kit/src/request-body.d.ts +38 -0
  39. package/dist/adapters/integration-kit/src/request-body.js +68 -0
  40. package/dist/adapters/integration-kit/src/request-log.d.ts +25 -0
  41. package/dist/adapters/integration-kit/src/request-log.js +17 -0
  42. package/dist/adapters/integration-kit/src/response-body.d.ts +27 -0
  43. package/dist/adapters/integration-kit/src/response-body.js +117 -0
  44. package/dist/adapters/integration-kit/src/scoped-tokens.d.ts +14 -0
  45. package/dist/adapters/integration-kit/src/scoped-tokens.js +27 -0
  46. package/dist/adapters/integration-kit/src/secret-filter.d.ts +84 -0
  47. package/dist/adapters/integration-kit/src/secret-filter.js +220 -0
  48. package/dist/adapters/integration-kit/src/secret-in-request.d.ts +62 -0
  49. package/dist/adapters/integration-kit/src/secret-in-request.js +139 -0
  50. package/dist/adapters/integration-kit/src/secret-placement.d.ts +46 -0
  51. package/dist/adapters/integration-kit/src/secret-placement.js +160 -0
  52. package/dist/adapters/integration-kit/src/sign-in-placement.d.ts +29 -0
  53. package/dist/adapters/integration-kit/src/sign-in-placement.js +92 -0
  54. package/dist/adapters/integration-kit/src/wait.d.ts +16 -0
  55. package/dist/adapters/integration-kit/src/wait.js +35 -0
  56. package/dist/core/events/src/add-usage.d.ts +10 -0
  57. package/dist/core/events/src/add-usage.js +27 -0
  58. package/dist/core/events/src/agent-resume.d.ts +24 -0
  59. package/dist/core/events/src/agent-resume.js +1 -0
  60. package/dist/core/events/src/blocked-sites.d.ts +57 -0
  61. package/dist/core/events/src/blocked-sites.js +89 -0
  62. package/dist/core/events/src/home-path.d.ts +13 -0
  63. package/dist/core/events/src/home-path.js +26 -0
  64. package/dist/core/events/src/index.d.ts +17 -0
  65. package/dist/core/events/src/index.js +10 -0
  66. package/dist/core/events/src/run-basics.d.ts +228 -0
  67. package/dist/core/events/src/run-basics.js +1 -0
  68. package/dist/core/events/src/run-event.d.ts +478 -0
  69. package/dist/core/events/src/run-event.js +1 -0
  70. package/dist/core/events/src/run-reads.d.ts +25 -0
  71. package/dist/core/events/src/run-reads.js +44 -0
  72. package/dist/core/events/src/run-sends.d.ts +47 -0
  73. package/dist/core/events/src/run-sends.js +68 -0
  74. package/dist/core/events/src/run-summary.d.ts +108 -0
  75. package/dist/core/events/src/run-summary.js +1 -0
  76. package/dist/core/events/src/sandbox-blocked.d.ts +42 -0
  77. package/dist/core/events/src/sandbox-blocked.js +26 -0
  78. package/dist/core/events/src/sandbox-opened-read.d.ts +17 -0
  79. package/dist/core/events/src/sandbox-opened-read.js +63 -0
  80. package/dist/core/events/src/sandbox-opened.d.ts +94 -0
  81. package/dist/core/events/src/sandbox-opened.js +52 -0
  82. package/dist/core/events/src/summarize.d.ts +14 -0
  83. package/dist/core/events/src/summarize.js +192 -0
  84. package/dist/core/events/src/timeline-entry.d.ts +21 -0
  85. package/dist/core/events/src/timeline-entry.js +106 -0
  86. package/dist/core/events/src/upgrade.d.ts +23 -0
  87. package/dist/core/events/src/upgrade.js +49 -0
  88. package/dist/core/format/src/compact.d.ts +30 -0
  89. package/dist/core/format/src/compact.js +72 -0
  90. package/dist/core/format/src/index.d.ts +39 -0
  91. package/dist/core/format/src/index.js +25 -0
  92. package/dist/core/format/src/integration/index.d.ts +7 -0
  93. package/dist/core/format/src/integration/index.js +10 -0
  94. package/dist/core/format/src/json-schema.d.ts +26 -0
  95. package/dist/core/format/src/json-schema.js +48 -0
  96. package/dist/core/format/src/kind.d.ts +65 -0
  97. package/dist/core/format/src/kind.js +1 -0
  98. package/dist/core/format/src/kinds/agent/kind.d.ts +4 -0
  99. package/dist/core/format/src/kinds/agent/kind.js +10 -0
  100. package/dist/core/format/src/kinds/agent/sandbox-fields.d.ts +99 -0
  101. package/dist/core/format/src/kinds/agent/sandbox-fields.js +216 -0
  102. package/dist/core/format/src/kinds/agent/schema.d.ts +147 -0
  103. package/dist/core/format/src/kinds/agent/schema.js +107 -0
  104. package/dist/core/format/src/kinds/agent/working-folder-start.d.ts +74 -0
  105. package/dist/core/format/src/kinds/agent/working-folder-start.js +312 -0
  106. package/dist/core/format/src/kinds/collection/kind.d.ts +8 -0
  107. package/dist/core/format/src/kinds/collection/kind.js +14 -0
  108. package/dist/core/format/src/kinds/collection/schema.d.ts +89 -0
  109. package/dist/core/format/src/kinds/collection/schema.js +90 -0
  110. package/dist/core/format/src/kinds/connector/is-local.d.ts +10 -0
  111. package/dist/core/format/src/kinds/connector/is-local.js +43 -0
  112. package/dist/core/format/src/kinds/connector/kind.d.ts +4 -0
  113. package/dist/core/format/src/kinds/connector/kind.js +218 -0
  114. package/dist/core/format/src/kinds/connector/schema.d.ts +74 -0
  115. package/dist/core/format/src/kinds/connector/schema.js +143 -0
  116. package/dist/core/format/src/kinds/deployments/kind.d.ts +4 -0
  117. package/dist/core/format/src/kinds/deployments/kind.js +49 -0
  118. package/dist/core/format/src/kinds/deployments/schema.d.ts +77 -0
  119. package/dist/core/format/src/kinds/deployments/schema.js +94 -0
  120. package/dist/core/format/src/kinds/hub/kind.d.ts +4 -0
  121. package/dist/core/format/src/kinds/hub/kind.js +10 -0
  122. package/dist/core/format/src/kinds/hub/schema.d.ts +54 -0
  123. package/dist/core/format/src/kinds/hub/schema.js +34 -0
  124. package/dist/core/format/src/kinds/integration/approved-sign-ins.d.ts +62 -0
  125. package/dist/core/format/src/kinds/integration/approved-sign-ins.js +125 -0
  126. package/dist/core/format/src/kinds/integration/host-key.d.ts +7 -0
  127. package/dist/core/format/src/kinds/integration/host-key.js +8 -0
  128. package/dist/core/format/src/kinds/integration/kind.d.ts +18 -0
  129. package/dist/core/format/src/kinds/integration/kind.js +175 -0
  130. package/dist/core/format/src/kinds/integration/parse-sheet.d.ts +19 -0
  131. package/dist/core/format/src/kinds/integration/parse-sheet.js +24 -0
  132. package/dist/core/format/src/kinds/integration/policy.d.ts +112 -0
  133. package/dist/core/format/src/kinds/integration/policy.js +327 -0
  134. package/dist/core/format/src/kinds/integration/schema.d.ts +410 -0
  135. package/dist/core/format/src/kinds/integration/schema.js +359 -0
  136. package/dist/core/format/src/kinds/integration/sign-in-checks.d.ts +13 -0
  137. package/dist/core/format/src/kinds/integration/sign-in-checks.js +120 -0
  138. package/dist/core/format/src/kinds/integration/sign-in-urls.d.ts +19 -0
  139. package/dist/core/format/src/kinds/integration/sign-in-urls.js +47 -0
  140. package/dist/core/format/src/kinds/knowledge/kind.d.ts +4 -0
  141. package/dist/core/format/src/kinds/knowledge/kind.js +13 -0
  142. package/dist/core/format/src/kinds/knowledge/schema.d.ts +18 -0
  143. package/dist/core/format/src/kinds/knowledge/schema.js +25 -0
  144. package/dist/core/format/src/kinds/models/kind.d.ts +4 -0
  145. package/dist/core/format/src/kinds/models/kind.js +10 -0
  146. package/dist/core/format/src/kinds/models/schema.d.ts +92 -0
  147. package/dist/core/format/src/kinds/models/schema.js +38 -0
  148. package/dist/core/format/src/kinds/plugin/backend.d.ts +22 -0
  149. package/dist/core/format/src/kinds/plugin/backend.js +31 -0
  150. package/dist/core/format/src/kinds/plugin/checks.d.ts +13 -0
  151. package/dist/core/format/src/kinds/plugin/checks.js +137 -0
  152. package/dist/core/format/src/kinds/plugin/kind.d.ts +8 -0
  153. package/dist/core/format/src/kinds/plugin/kind.js +16 -0
  154. package/dist/core/format/src/kinds/plugin/problems.d.ts +24 -0
  155. package/dist/core/format/src/kinds/plugin/problems.js +65 -0
  156. package/dist/core/format/src/kinds/plugin/schema.d.ts +672 -0
  157. package/dist/core/format/src/kinds/plugin/schema.js +261 -0
  158. package/dist/core/format/src/kinds/plugin/setting-values.d.ts +17 -0
  159. package/dist/core/format/src/kinds/plugin/setting-values.js +38 -0
  160. package/dist/core/format/src/kinds/plugin/ui-checks.d.ts +8 -0
  161. package/dist/core/format/src/kinds/plugin/ui-checks.js +85 -0
  162. package/dist/core/format/src/kinds/provider/kind.d.ts +4 -0
  163. package/dist/core/format/src/kinds/provider/kind.js +24 -0
  164. package/dist/core/format/src/kinds/provider/schema.d.ts +17 -0
  165. package/dist/core/format/src/kinds/provider/schema.js +22 -0
  166. package/dist/core/format/src/kinds/routine/kind.d.ts +8 -0
  167. package/dist/core/format/src/kinds/routine/kind.js +62 -0
  168. package/dist/core/format/src/kinds/routine/schema.d.ts +94 -0
  169. package/dist/core/format/src/kinds/routine/schema.js +115 -0
  170. package/dist/core/format/src/kinds/routine/webhook-headers.d.ts +9 -0
  171. package/dist/core/format/src/kinds/routine/webhook-headers.js +26 -0
  172. package/dist/core/format/src/kinds/runtime/kind.d.ts +4 -0
  173. package/dist/core/format/src/kinds/runtime/kind.js +13 -0
  174. package/dist/core/format/src/kinds/runtime/schema.d.ts +10 -0
  175. package/dist/core/format/src/kinds/runtime/schema.js +12 -0
  176. package/dist/core/format/src/kinds/skill/kind.d.ts +4 -0
  177. package/dist/core/format/src/kinds/skill/kind.js +10 -0
  178. package/dist/core/format/src/kinds/skill/schema.d.ts +17 -0
  179. package/dist/core/format/src/kinds/skill/schema.js +17 -0
  180. package/dist/core/format/src/kinds/skill/scripts-folder.d.ts +27 -0
  181. package/dist/core/format/src/kinds/skill/scripts-folder.js +37 -0
  182. package/dist/core/format/src/kinds/workflow/kind.d.ts +8 -0
  183. package/dist/core/format/src/kinds/workflow/kind.js +14 -0
  184. package/dist/core/format/src/kinds/workflow/schema.d.ts +162 -0
  185. package/dist/core/format/src/kinds/workflow/schema.js +106 -0
  186. package/dist/core/format/src/kinds/workflow-test/kind.d.ts +4 -0
  187. package/dist/core/format/src/kinds/workflow-test/kind.js +14 -0
  188. package/dist/core/format/src/kinds/workflow-test/schema.d.ts +67 -0
  189. package/dist/core/format/src/kinds/workflow-test/schema.js +59 -0
  190. package/dist/core/format/src/kinds/workspace/kind.d.ts +4 -0
  191. package/dist/core/format/src/kinds/workspace/kind.js +10 -0
  192. package/dist/core/format/src/kinds/workspace/schema.d.ts +72 -0
  193. package/dist/core/format/src/kinds/workspace/schema.js +66 -0
  194. package/dist/core/format/src/parse-file.d.ts +69 -0
  195. package/dist/core/format/src/parse-file.js +105 -0
  196. package/dist/core/format/src/recording/format.d.ts +81 -0
  197. package/dist/core/format/src/recording/format.js +102 -0
  198. package/dist/core/format/src/recording/index.d.ts +1 -0
  199. package/dist/core/format/src/recording/index.js +3 -0
  200. package/dist/core/format/src/registry.d.ts +64 -0
  201. package/dist/core/format/src/registry.js +61 -0
  202. package/dist/core/format/src/reserved.d.ts +20 -0
  203. package/dist/core/format/src/reserved.js +30 -0
  204. package/dist/core/format/src/shared/fields.d.ts +34 -0
  205. package/dist/core/format/src/shared/fields.js +74 -0
  206. package/dist/core/format/src/shared/guard.d.ts +32 -0
  207. package/dist/core/format/src/shared/guard.js +16 -0
  208. package/dist/core/format/src/shared/key-in-value.d.ts +28 -0
  209. package/dist/core/format/src/shared/key-in-value.js +82 -0
  210. package/dist/core/format/src/shared/legacy-keys.d.ts +8 -0
  211. package/dist/core/format/src/shared/legacy-keys.js +17 -0
  212. package/dist/core/format/src/shared/program-start.d.ts +60 -0
  213. package/dist/core/format/src/shared/program-start.js +99 -0
  214. package/dist/core/format/src/shared/relative-path.d.ts +29 -0
  215. package/dist/core/format/src/shared/relative-path.js +50 -0
  216. package/dist/core/format/src/shared/secret-name.d.ts +24 -0
  217. package/dist/core/format/src/shared/secret-name.js +107 -0
  218. package/dist/core/format/src/source.d.ts +16 -0
  219. package/dist/core/format/src/source.js +73 -0
  220. package/dist/core/ports/src/agent-placement-store.d.ts +74 -0
  221. package/dist/core/ports/src/agent-placement-store.js +27 -0
  222. package/dist/core/ports/src/agent-runs-not-available.d.ts +21 -0
  223. package/dist/core/ports/src/agent-runs-not-available.js +25 -0
  224. package/dist/core/ports/src/blob-store.d.ts +45 -0
  225. package/dist/core/ports/src/blob-store.js +24 -0
  226. package/dist/core/ports/src/cant-try-error.d.ts +35 -0
  227. package/dist/core/ports/src/cant-try-error.js +44 -0
  228. package/dist/core/ports/src/chat.d.ts +127 -0
  229. package/dist/core/ports/src/chat.js +1 -0
  230. package/dist/core/ports/src/clock.d.ts +7 -0
  231. package/dist/core/ports/src/clock.js +2 -0
  232. package/dist/core/ports/src/connection-settings-store.d.ts +57 -0
  233. package/dist/core/ports/src/connection-settings-store.js +2 -0
  234. package/dist/core/ports/src/connector-client.d.ts +303 -0
  235. package/dist/core/ports/src/connector-client.js +19 -0
  236. package/dist/core/ports/src/coordination.d.ts +84 -0
  237. package/dist/core/ports/src/coordination.js +2 -0
  238. package/dist/core/ports/src/definition-store.d.ts +229 -0
  239. package/dist/core/ports/src/definition-store.js +122 -0
  240. package/dist/core/ports/src/digest.d.ts +14 -0
  241. package/dist/core/ports/src/digest.js +2 -0
  242. package/dist/core/ports/src/folder-reader.d.ts +89 -0
  243. package/dist/core/ports/src/folder-reader.js +2 -0
  244. package/dist/core/ports/src/harness-bridge-server.d.ts +198 -0
  245. package/dist/core/ports/src/harness-bridge-server.js +37 -0
  246. package/dist/core/ports/src/harness-sign-in-command.d.ts +27 -0
  247. package/dist/core/ports/src/harness-sign-in-command.js +31 -0
  248. package/dist/core/ports/src/harness.d.ts +283 -0
  249. package/dist/core/ports/src/harness.js +45 -0
  250. package/dist/core/ports/src/host-settings-store.d.ts +116 -0
  251. package/dist/core/ports/src/host-settings-store.js +106 -0
  252. package/dist/core/ports/src/http-client.d.ts +27 -0
  253. package/dist/core/ports/src/http-client.js +2 -0
  254. package/dist/core/ports/src/id-generator.d.ts +14 -0
  255. package/dist/core/ports/src/id-generator.js +2 -0
  256. package/dist/core/ports/src/index.d.ts +45 -0
  257. package/dist/core/ports/src/index.js +44 -0
  258. package/dist/core/ports/src/instruction-trust-store.d.ts +81 -0
  259. package/dist/core/ports/src/instruction-trust-store.js +43 -0
  260. package/dist/core/ports/src/integration.d.ts +242 -0
  261. package/dist/core/ports/src/integration.js +31 -0
  262. package/dist/core/ports/src/knowledge-provider.d.ts +65 -0
  263. package/dist/core/ports/src/knowledge-provider.js +2 -0
  264. package/dist/core/ports/src/llm-cache.d.ts +13 -0
  265. package/dist/core/ports/src/llm-cache.js +2 -0
  266. package/dist/core/ports/src/llm-provider.d.ts +186 -0
  267. package/dist/core/ports/src/llm-provider.js +139 -0
  268. package/dist/core/ports/src/model-price.d.ts +34 -0
  269. package/dist/core/ports/src/model-price.js +25 -0
  270. package/dist/core/ports/src/password-hasher.d.ts +63 -0
  271. package/dist/core/ports/src/password-hasher.js +2 -0
  272. package/dist/core/ports/src/plugin-folder-writer.d.ts +104 -0
  273. package/dist/core/ports/src/plugin-folder-writer.js +95 -0
  274. package/dist/core/ports/src/port-versions.d.ts +47 -0
  275. package/dist/core/ports/src/port-versions.js +80 -0
  276. package/dist/core/ports/src/program-probe.d.ts +69 -0
  277. package/dist/core/ports/src/program-probe.js +2 -0
  278. package/dist/core/ports/src/provider-default-base-url.d.ts +10 -0
  279. package/dist/core/ports/src/provider-default-base-url.js +18 -0
  280. package/dist/core/ports/src/record-store.d.ts +79 -0
  281. package/dist/core/ports/src/record-store.js +108 -0
  282. package/dist/core/ports/src/resource-probe.d.ts +59 -0
  283. package/dist/core/ports/src/resource-probe.js +2 -0
  284. package/dist/core/ports/src/run-executor.d.ts +303 -0
  285. package/dist/core/ports/src/run-executor.js +2 -0
  286. package/dist/core/ports/src/run-failure-error.d.ts +49 -0
  287. package/dist/core/ports/src/run-failure-error.js +47 -0
  288. package/dist/core/ports/src/run-store.d.ts +194 -0
  289. package/dist/core/ports/src/run-store.js +131 -0
  290. package/dist/core/ports/src/run-target-not-found.d.ts +34 -0
  291. package/dist/core/ports/src/run-target-not-found.js +41 -0
  292. package/dist/core/ports/src/sandbox-setting-store.d.ts +68 -0
  293. package/dist/core/ports/src/sandbox-setting-store.js +33 -0
  294. package/dist/core/ports/src/sandbox.d.ts +364 -0
  295. package/dist/core/ports/src/sandbox.js +70 -0
  296. package/dist/core/ports/src/scheduler.d.ts +85 -0
  297. package/dist/core/ports/src/scheduler.js +2 -0
  298. package/dist/core/ports/src/secrets.d.ts +201 -0
  299. package/dist/core/ports/src/secrets.js +200 -0
  300. package/dist/core/ports/src/token-store.d.ts +19 -0
  301. package/dist/core/ports/src/token-store.js +2 -0
  302. package/dist/core/ports/src/tool-approval-store.d.ts +253 -0
  303. package/dist/core/ports/src/tool-approval-store.js +116 -0
  304. package/dist/core/ports/src/trust-store.d.ts +72 -0
  305. package/dist/core/ports/src/trust-store.js +2 -0
  306. package/dist/core/ports/src/unfenced-run-consent-store.d.ts +43 -0
  307. package/dist/core/ports/src/unfenced-run-consent-store.js +2 -0
  308. package/dist/core/ports/src/vcs-status.d.ts +8 -0
  309. package/dist/core/ports/src/vcs-status.js +90 -0
  310. package/dist/core/ports/src/vcs.d.ts +394 -0
  311. package/dist/core/ports/src/vcs.js +48 -0
  312. package/dist/core/schema-kit/src/builders.d.ts +50 -0
  313. package/dist/core/schema-kit/src/builders.js +72 -0
  314. package/dist/core/schema-kit/src/depth.d.ts +15 -0
  315. package/dist/core/schema-kit/src/depth.js +37 -0
  316. package/dist/core/schema-kit/src/index.d.ts +6 -0
  317. package/dist/core/schema-kit/src/index.js +6 -0
  318. package/dist/core/schema-kit/src/issue.d.ts +22 -0
  319. package/dist/core/schema-kit/src/issue.js +23 -0
  320. package/dist/core/schema-kit/src/json-schema.d.ts +23 -0
  321. package/dist/core/schema-kit/src/json-schema.js +22 -0
  322. package/dist/core/schema-kit/src/parse.d.ts +17 -0
  323. package/dist/core/schema-kit/src/parse.js +25 -0
  324. package/dist/core/schema-kit/src/schema.d.ts +12 -0
  325. package/dist/core/schema-kit/src/schema.js +1 -0
  326. package/dist/core/std/src/amount.d.ts +13 -0
  327. package/dist/core/std/src/amount.js +22 -0
  328. package/dist/core/std/src/ascii-host.d.ts +18 -0
  329. package/dist/core/std/src/ascii-host.js +110 -0
  330. package/dist/core/std/src/assert.d.ts +39 -0
  331. package/dist/core/std/src/assert.js +59 -0
  332. package/dist/core/std/src/base64url.d.ts +23 -0
  333. package/dist/core/std/src/base64url.js +65 -0
  334. package/dist/core/std/src/canonical-json.d.ts +18 -0
  335. package/dist/core/std/src/canonical-json.js +56 -0
  336. package/dist/core/std/src/clock.d.ts +27 -0
  337. package/dist/core/std/src/clock.js +33 -0
  338. package/dist/core/std/src/constant-time.d.ts +16 -0
  339. package/dist/core/std/src/constant-time.js +26 -0
  340. package/dist/core/std/src/content-digest.d.ts +24 -0
  341. package/dist/core/std/src/content-digest.js +28 -0
  342. package/dist/core/std/src/deep-clone.d.ts +15 -0
  343. package/dist/core/std/src/deep-clone.js +59 -0
  344. package/dist/core/std/src/deep-equal.d.ts +23 -0
  345. package/dist/core/std/src/deep-equal.js +64 -0
  346. package/dist/core/std/src/emitter.d.ts +42 -0
  347. package/dist/core/std/src/emitter.js +74 -0
  348. package/dist/core/std/src/error-kind.d.ts +88 -0
  349. package/dist/core/std/src/error-kind.js +98 -0
  350. package/dist/core/std/src/hex.d.ts +10 -0
  351. package/dist/core/std/src/hex.js +16 -0
  352. package/dist/core/std/src/hidden-characters.d.ts +19 -0
  353. package/dist/core/std/src/hidden-characters.js +54 -0
  354. package/dist/core/std/src/ids.d.ts +45 -0
  355. package/dist/core/std/src/ids.js +49 -0
  356. package/dist/core/std/src/index.d.ts +30 -0
  357. package/dist/core/std/src/index.js +31 -0
  358. package/dist/core/std/src/keyed-queue.d.ts +18 -0
  359. package/dist/core/std/src/keyed-queue.js +32 -0
  360. package/dist/core/std/src/line-diff.d.ts +83 -0
  361. package/dist/core/std/src/line-diff.js +179 -0
  362. package/dist/core/std/src/line-merge.d.ts +63 -0
  363. package/dist/core/std/src/line-merge.js +138 -0
  364. package/dist/core/std/src/plain-data.d.ts +32 -0
  365. package/dist/core/std/src/plain-data.js +57 -0
  366. package/dist/core/std/src/posix-path.d.ts +61 -0
  367. package/dist/core/std/src/posix-path.js +121 -0
  368. package/dist/core/std/src/public-suffixes.generated.d.ts +9 -0
  369. package/dist/core/std/src/public-suffixes.generated.js +10429 -0
  370. package/dist/core/std/src/registrable-domain.d.ts +10 -0
  371. package/dist/core/std/src/registrable-domain.js +62 -0
  372. package/dist/core/std/src/result.d.ts +55 -0
  373. package/dist/core/std/src/result.js +52 -0
  374. package/dist/core/std/src/secret-scrubber.d.ts +54 -0
  375. package/dist/core/std/src/secret-scrubber.js +124 -0
  376. package/dist/core/std/src/secret-shape.d.ts +20 -0
  377. package/dist/core/std/src/secret-shape.js +53 -0
  378. package/dist/core/std/src/secret-variable-name.d.ts +12 -0
  379. package/dist/core/std/src/secret-variable-name.js +34 -0
  380. package/dist/core/std/src/site-name.d.ts +35 -0
  381. package/dist/core/std/src/site-name.js +111 -0
  382. package/dist/core/std/src/stop-signal.d.ts +44 -0
  383. package/dist/core/std/src/stop-signal.js +77 -0
  384. package/dist/core/std/src/text.d.ts +28 -0
  385. package/dist/core/std/src/text.js +54 -0
  386. package/dist/core/std/src/url-host.d.ts +35 -0
  387. package/dist/core/std/src/url-host.js +170 -0
  388. package/dist/core/std/src/utf8.d.ts +23 -0
  389. package/dist/core/std/src/utf8.js +110 -0
  390. package/dist/core/std/src/version.d.ts +48 -0
  391. package/dist/core/std/src/version.js +103 -0
  392. package/dist/core/yaml/src/depth.d.ts +14 -0
  393. package/dist/core/yaml/src/depth.js +140 -0
  394. package/dist/core/yaml/src/edit-data.d.ts +47 -0
  395. package/dist/core/yaml/src/edit-data.js +286 -0
  396. package/dist/core/yaml/src/edit-text.d.ts +92 -0
  397. package/dist/core/yaml/src/edit-text.js +267 -0
  398. package/dist/core/yaml/src/edit.d.ts +47 -0
  399. package/dist/core/yaml/src/edit.js +198 -0
  400. package/dist/core/yaml/src/index.d.ts +5 -0
  401. package/dist/core/yaml/src/index.js +4 -0
  402. package/dist/core/yaml/src/problem.d.ts +20 -0
  403. package/dist/core/yaml/src/problem.js +1 -0
  404. package/dist/core/yaml/src/read.d.ts +47 -0
  405. package/dist/core/yaml/src/read.js +130 -0
  406. package/dist/core/yaml/src/splice-node.d.ts +47 -0
  407. package/dist/core/yaml/src/splice-node.js +333 -0
  408. package/dist/core/yaml/src/splice.d.ts +13 -0
  409. package/dist/core/yaml/src/splice.js +174 -0
  410. package/dist/core/yaml/src/unsupported.d.ts +26 -0
  411. package/dist/core/yaml/src/unsupported.js +70 -0
  412. package/dist/core/yaml/src/write.d.ts +35 -0
  413. package/dist/core/yaml/src/write.js +44 -0
  414. package/dist/testing/integration/src/canaries.d.ts +14 -0
  415. package/dist/testing/integration/src/canaries.js +17 -0
  416. package/dist/testing/integration/src/checks.d.ts +37 -0
  417. package/dist/testing/integration/src/checks.js +195 -0
  418. package/dist/testing/integration/src/describe.d.ts +35 -0
  419. package/dist/testing/integration/src/describe.js +74 -0
  420. package/dist/testing/integration/src/failure.d.ts +6 -0
  421. package/dist/testing/integration/src/failure.js +8 -0
  422. package/dist/testing/integration/src/fake-wait.d.ts +18 -0
  423. package/dist/testing/integration/src/fake-wait.js +21 -0
  424. package/dist/testing/integration/src/index.d.ts +10 -0
  425. package/dist/testing/integration/src/index.js +11 -0
  426. package/dist/testing/integration/src/load.d.ts +14 -0
  427. package/dist/testing/integration/src/load.js +47 -0
  428. package/dist/testing/integration/src/plugin-folder.d.ts +23 -0
  429. package/dist/testing/integration/src/plugin-folder.js +59 -0
  430. package/dist/testing/integration/src/plugin.d.ts +32 -0
  431. package/dist/testing/integration/src/plugin.js +57 -0
  432. package/dist/testing/integration/src/recording.d.ts +84 -0
  433. package/dist/testing/integration/src/recording.js +164 -0
  434. package/dist/testing/integration/src/run.d.ts +60 -0
  435. package/dist/testing/integration/src/run.js +81 -0
  436. package/dist/testing/integration/src/source-scan.d.ts +16 -0
  437. package/dist/testing/integration/src/source-scan.js +40 -0
  438. package/package.json +34 -3
@@ -0,0 +1,33 @@
1
+ import type { AuthPlacement, IntegrationRequestInit } from "../../../core/ports/src/index.js";
2
+ import type { IntegrationPolicy } from "./policy.js";
3
+ import type { Body } from "./request-body.js";
4
+ /**
5
+ * The request as the integration's code gave it, copied once. The kit
6
+ * checks and sends only this copy.
7
+ */
8
+ export interface OwnRequest {
9
+ /** The method as given, for the secret check. */
10
+ readonly givenMethod: string | undefined;
11
+ /** The method the kit sends. */
12
+ readonly method: string;
13
+ /**
14
+ * The URL, only when given as plain text. Anything else could give one URL
15
+ * each time it's turned into text, so it's never read, and `allowedUrl`
16
+ * refuses the request.
17
+ */
18
+ readonly url: string | undefined;
19
+ readonly headers: Headers;
20
+ /** The body, with its bytes or form copied. A kind the kit doesn't support stays as given. */
21
+ readonly body: Body;
22
+ readonly placements: readonly AuthPlacement[];
23
+ readonly signal: AbortSignal | undefined;
24
+ }
25
+ /**
26
+ * Copies the request before the kit's first `await`, reading each option
27
+ * once. The code keeps its own objects and could change them, or give a
28
+ * getter, after the secret check and before the request is sent: a
29
+ * `Headers` object or a byte array it changes once `fetch` is called, or a
30
+ * getter that gives the check one value and the transport another. A URL
31
+ * object could likewise give the check one text and the request log another.
32
+ */
33
+ export declare function copyRequest(policy: IntegrationPolicy, url: unknown, init: IntegrationRequestInit): OwnRequest;
@@ -0,0 +1,36 @@
1
+ import { copyPlacements } from "./auth-placement.js";
2
+ /**
3
+ * Copies the request before the kit's first `await`, reading each option
4
+ * once. The code keeps its own objects and could change them, or give a
5
+ * getter, after the secret check and before the request is sent: a
6
+ * `Headers` object or a byte array it changes once `fetch` is called, or a
7
+ * getter that gives the check one value and the transport another. A URL
8
+ * object could likewise give the check one text and the request log another.
9
+ */
10
+ export function copyRequest(policy, url, init) {
11
+ const { method, headers, body, auth, signal } = init;
12
+ const givenMethod = method === undefined ? undefined : String(method);
13
+ return {
14
+ givenMethod,
15
+ method: (givenMethod ?? "GET").toUpperCase(),
16
+ url: typeof url === "string" ? url : undefined,
17
+ headers: new Headers(headers),
18
+ body: copyBody(body ?? null),
19
+ placements: copyPlacements(policy, auth === undefined ? [] : [auth].flat()),
20
+ signal: signal ?? undefined,
21
+ };
22
+ }
23
+ /**
24
+ * A copy of a body the kit supports: text as it is, a new form, and bytes
25
+ * copied out of their buffer. Any other kind is left for `checkBody` to refuse.
26
+ */
27
+ function copyBody(body) {
28
+ if (body instanceof URLSearchParams)
29
+ return new URLSearchParams(body);
30
+ if (body instanceof ArrayBuffer)
31
+ return new Uint8Array(body).slice();
32
+ if (ArrayBuffer.isView(body)) {
33
+ return new Uint8Array(body.buffer, body.byteOffset, body.byteLength).slice();
34
+ }
35
+ return body;
36
+ }
@@ -0,0 +1,14 @@
1
+ import { type Plugin } from "../../../core/format/src/integration/index.js";
2
+ import { type Integration } from "../../../core/ports/src/index.js";
3
+ import type { LoadProblem } from "./load-problem.js";
4
+ /**
5
+ * Why a plugin that passed its own checks can't load: an `sdk` newer than
6
+ * this Halonic's `integrationVersion`, and, when the backend's code is given,
7
+ * every way it differs from the backend, with the same rules as for
8
+ * an integration and its sheet (`declarationProblems`) and each path
9
+ * pointing into `plugin.yaml`. Empty when the plugin can load.
10
+ *
11
+ * @example
12
+ * pluginLoadProblems(plugin, weather); // [] when the SDK and the code match
13
+ */
14
+ export declare function pluginLoadProblems(plugin: Plugin, backendCode?: Integration): LoadProblem[];
@@ -0,0 +1,58 @@
1
+ // The checks a plugin needs when it loads, beyond its own file (ADR
2
+ // 2026-11-09-plugins, section 1.4): the SDK version this Halonic offers,
3
+ // and the backend's code against its backend. The checks inside
4
+ // `plugin.yaml` already ran in the format's `plugin` kind.
5
+ import { backendSheet } from "../../../core/format/src/integration/index.js";
6
+ import { integrationVersion } from "../../../core/ports/src/index.js";
7
+ import { declarationProblems } from "./declaration.js";
8
+ /**
9
+ * Why a plugin that passed its own checks can't load: an `sdk` newer than
10
+ * this Halonic's `integrationVersion`, and, when the backend's code is given,
11
+ * every way it differs from the backend, with the same rules as for
12
+ * an integration and its sheet (`declarationProblems`) and each path
13
+ * pointing into `plugin.yaml`. Empty when the plugin can load.
14
+ *
15
+ * @example
16
+ * pluginLoadProblems(plugin, weather); // [] when the SDK and the code match
17
+ */
18
+ export function pluginLoadProblems(plugin, backendCode) {
19
+ const problems = [];
20
+ if (plugin.sdk > integrationVersion) {
21
+ problems.push({
22
+ code: "sdk-version",
23
+ path: ["sdk"],
24
+ message: `${plugin.id}: this plugin needs a newer version of Halonic (it is built against SDK ${plugin.sdk}, and this Halonic offers SDK ${integrationVersion})`,
25
+ });
26
+ }
27
+ if (backendCode !== undefined) {
28
+ problems.push(...backendProblems(plugin, backendCode));
29
+ }
30
+ return problems;
31
+ }
32
+ function backendProblems(plugin, backendCode) {
33
+ const sheet = backendSheet(plugin);
34
+ if (sheet === undefined) {
35
+ return [
36
+ {
37
+ code: "backend-not-declared",
38
+ path: [],
39
+ message: `${plugin.id}: the plugin has backend code, but plugin.yaml has no backend`,
40
+ },
41
+ ];
42
+ }
43
+ // The sheet's `kit` is the plugin's `sdk`, already reported above.
44
+ return declarationProblems(sheet, backendCode)
45
+ .filter((problem) => problem.code !== "kit-version")
46
+ .map((problem) => ({ ...problem, path: pluginPath(problem.path) }));
47
+ }
48
+ /**
49
+ * A sheet path as a path in `plugin.yaml`: `id` and `version` are the
50
+ * plugin's own, everything else sits under `backend`.
51
+ */
52
+ function pluginPath(path) {
53
+ const [first] = path;
54
+ if (first === "id" || first === "version") {
55
+ return path;
56
+ }
57
+ return ["backend", ...path];
58
+ }
@@ -0,0 +1,83 @@
1
+ /**
2
+ * What one integration may do, taken from its permission sheet after any
3
+ * `fromSetting` host is resolved. The kit enforces exactly this.
4
+ */
5
+ export interface IntegrationPolicy {
6
+ /** The integration's name, for messages and for scoping its tokens. */
7
+ readonly name: string;
8
+ /**
9
+ * The hosts it may call: a host name, or `host:port` for a port other than
10
+ * 443. Matched exactly, ignoring case. No wildcards.
11
+ */
12
+ readonly hosts: readonly string[];
13
+ /**
14
+ * The hosts it may call over plain `http`: only `localhost` or a private
15
+ * address the user chose in a setting, as `host:port`. The kit
16
+ * refuses any other address here, whatever the list says.
17
+ */
18
+ readonly localHosts?: readonly string[];
19
+ /**
20
+ * Each secret it may use, the hosts that secret may go to, and where the
21
+ * sheet puts it. An `optional` secret, such as the key of a server that
22
+ * may need none, is left out of the request when the workspace hasn't set
23
+ * it up, instead of refusing the request.
24
+ */
25
+ readonly secrets: Readonly<Record<string, DeclaredSecret>>;
26
+ /**
27
+ * Each sign-in, the hosts its access token may go to, and where the sheet
28
+ * puts it. Halonic's own code runs the sign-in; the integration can only
29
+ * ask the kit to place the access token.
30
+ */
31
+ readonly signIns: Readonly<Record<string, DeclaredSignIn>>;
32
+ /** The token names it may read and write. */
33
+ readonly tokens: readonly string[];
34
+ }
35
+ /** One secret in the permission sheet. */
36
+ export interface DeclaredSecret {
37
+ readonly hosts: readonly string[];
38
+ readonly optional?: boolean;
39
+ /** The only way the kit may place it; any other placement is refused. */
40
+ readonly placement: DeclaredPlacement;
41
+ }
42
+ /** One sign-in in the permission sheet. */
43
+ export type DeclaredSignIn = DeclaredSignInPlacement & {
44
+ /** The hosts the access token may go to. */
45
+ readonly hosts: readonly string[];
46
+ /**
47
+ * The sign-in's client secret, when it has one. The integration can't
48
+ * place it: only Halonic's sign-in code sends it, to the token and revoke
49
+ * hosts.
50
+ */
51
+ readonly clientSecret?: {
52
+ readonly name: string;
53
+ readonly hosts: readonly string[];
54
+ };
55
+ };
56
+ /** Where the sheet puts a sign-in's access token. There is no `form`. */
57
+ export type DeclaredSignInPlacement = {
58
+ readonly as: "bearer";
59
+ } | {
60
+ readonly as: "header";
61
+ readonly header: string;
62
+ readonly prefix?: string;
63
+ };
64
+ /** Where the sheet puts a secret: a `SecretPlacement` without the secret's name. */
65
+ export type DeclaredPlacement = {
66
+ readonly as: "bearer";
67
+ } | {
68
+ readonly as: "header";
69
+ readonly header: string;
70
+ readonly prefix?: string;
71
+ } | {
72
+ readonly as: "form";
73
+ readonly field: string;
74
+ };
75
+ /** Lower-case words joined by `-`: integration, secret-reference and token names. */
76
+ export declare const namePattern: RegExp;
77
+ /**
78
+ * Parses a URL the integration asked for, refusing anything but an allowed
79
+ * `https` host or an allowed local `http` host.
80
+ */
81
+ export declare function allowedUrl(policy: IntegrationPolicy, raw: unknown, base?: URL): URL;
82
+ /** Whether the URL's host is in the list, by exact match ignoring case. */
83
+ export declare function hostIn(hosts: readonly string[], url: URL): boolean;
@@ -0,0 +1,37 @@
1
+ import { IntegrationRefusedError } from "@halonicjs/adapters/integration-kit";
2
+ import { isLocalAddress } from "./local-address.js";
3
+ /** Lower-case words joined by `-`: integration, secret-reference and token names. */
4
+ export const namePattern = /^[a-z][a-z0-9]*(?:-[a-z0-9]+)*$/;
5
+ /**
6
+ * Parses a URL the integration asked for, refusing anything but an allowed
7
+ * `https` host or an allowed local `http` host.
8
+ */
9
+ export function allowedUrl(policy, raw, base) {
10
+ let url;
11
+ try {
12
+ if (typeof raw !== "string")
13
+ throw new TypeError("not a string");
14
+ url = new URL(raw, base);
15
+ }
16
+ catch {
17
+ throw new IntegrationRefusedError("bad-url", `${policy.name}: the request URL is not a valid absolute URL`);
18
+ }
19
+ const plainLocal = url.protocol === "http:" &&
20
+ hostIn(policy.localHosts ?? [], url) &&
21
+ isLocalAddress(url.hostname);
22
+ if (url.protocol !== "https:" && !plainLocal) {
23
+ throw new IntegrationRefusedError("scheme-not-allowed", `${policy.name}: only https is allowed, not ${url.protocol.replace(/:$/, "")}`);
24
+ }
25
+ if (url.username !== "" || url.password !== "") {
26
+ throw new IntegrationRefusedError("bad-url", `${policy.name}: a URL may not carry a user name or password`);
27
+ }
28
+ if (!plainLocal && !hostIn(policy.hosts, url)) {
29
+ throw new IntegrationRefusedError("host-not-allowed", `${policy.name}: ${url.host} is not one of the hosts in its permission sheet`);
30
+ }
31
+ return url;
32
+ }
33
+ /** Whether the URL's host is in the list, by exact match ignoring case. */
34
+ export function hostIn(hosts, url) {
35
+ const host = url.host.toLowerCase();
36
+ return hosts.some((allowed) => allowed.toLowerCase() === host);
37
+ }
@@ -0,0 +1,38 @@
1
+ import { IntegrationRefusedError } from "@halonicjs/adapters/integration-kit";
2
+ import type { IntegrationPolicy } from "./policy.js";
3
+ /** A request body as `fetch` takes it, or `null` for none. */
4
+ export type Body = NonNullable<RequestInit["body"]> | null;
5
+ /**
6
+ * The largest request body the kit sends: 720 KiB, measured on the bytes
7
+ * sent. It holds in-process and in the fenced runner alike: base64 makes it
8
+ * 983,040 bytes, which leaves room in the bridge's 1 MiB frame for the URL,
9
+ * the headers and the JSON around them. The bridge reuses this constant.
10
+ */
11
+ export declare const maxRequestBodyBytes: number;
12
+ /**
13
+ * The limit for one request: the one asked for, held at
14
+ * {@link maxRequestBodyBytes}, so it can be lowered but never raised.
15
+ *
16
+ * - A value that isn't a finite number, such as `NaN` or `-Infinity`, gets
17
+ * the ceiling.
18
+ * `bytes > NaN` is always false, so passing it through would turn the
19
+ * check off.
20
+ * - A negative finite value is clamped to 0, which allows a request with no body
21
+ * and nothing else. Passed through, it would refuse even an empty body,
22
+ * with a message about a limit of minus some bytes.
23
+ */
24
+ export declare function requestBodyLimit(requested?: number): number;
25
+ /**
26
+ * The number of bytes the transport will send for this body: text as
27
+ * UTF-8, a form after encoding, bytes as they are. {@link checkBody} has
28
+ * already refused every other kind of body.
29
+ */
30
+ export declare function bodyBytes(body: Body): number;
31
+ /**
32
+ * Bodies the kit can measure and send again after a redirect: text, a form
33
+ * or bytes. A stream can be read only once, and anything else, such as a
34
+ * `Blob` or `FormData` from plain JavaScript, has no size the kit can trust.
35
+ */
36
+ export declare function checkBody(policy: IntegrationPolicy, body: unknown): asserts body is Body;
37
+ export declare function requestTooLarge(policy: IntegrationPolicy, url: URL, maxBytes: number): IntegrationRefusedError;
38
+ export declare function toForm(policy: IntegrationPolicy, body: Body): URLSearchParams;
@@ -0,0 +1,68 @@
1
+ import { IntegrationRefusedError } from "@halonicjs/adapters/integration-kit";
2
+ /**
3
+ * The largest request body the kit sends: 720 KiB, measured on the bytes
4
+ * sent. It holds in-process and in the fenced runner alike: base64 makes it
5
+ * 983,040 bytes, which leaves room in the bridge's 1 MiB frame for the URL,
6
+ * the headers and the JSON around them. The bridge reuses this constant.
7
+ */
8
+ export const maxRequestBodyBytes = 720 * 1024;
9
+ /**
10
+ * The limit for one request: the one asked for, held at
11
+ * {@link maxRequestBodyBytes}, so it can be lowered but never raised.
12
+ *
13
+ * - A value that isn't a finite number, such as `NaN` or `-Infinity`, gets
14
+ * the ceiling.
15
+ * `bytes > NaN` is always false, so passing it through would turn the
16
+ * check off.
17
+ * - A negative finite value is clamped to 0, which allows a request with no body
18
+ * and nothing else. Passed through, it would refuse even an empty body,
19
+ * with a message about a limit of minus some bytes.
20
+ */
21
+ export function requestBodyLimit(requested = maxRequestBodyBytes) {
22
+ if (!Number.isFinite(requested))
23
+ return maxRequestBodyBytes;
24
+ return Math.max(0, Math.min(requested, maxRequestBodyBytes));
25
+ }
26
+ const utf8 = new TextEncoder();
27
+ /**
28
+ * The number of bytes the transport will send for this body: text as
29
+ * UTF-8, a form after encoding, bytes as they are. {@link checkBody} has
30
+ * already refused every other kind of body.
31
+ */
32
+ export function bodyBytes(body) {
33
+ if (body === null)
34
+ return 0;
35
+ if (typeof body === "string")
36
+ return utf8.encode(body).byteLength;
37
+ // A serialized form is plain ASCII: every other character is percent-encoded.
38
+ if (body instanceof URLSearchParams)
39
+ return body.toString().length;
40
+ if (body instanceof ArrayBuffer || ArrayBuffer.isView(body))
41
+ return body.byteLength;
42
+ throw new TypeError("bodyBytes: checkBody refuses this body before it is measured");
43
+ }
44
+ /**
45
+ * Bodies the kit can measure and send again after a redirect: text, a form
46
+ * or bytes. A stream can be read only once, and anything else, such as a
47
+ * `Blob` or `FormData` from plain JavaScript, has no size the kit can trust.
48
+ */
49
+ export function checkBody(policy, body) {
50
+ const supported = body === null ||
51
+ typeof body === "string" ||
52
+ body instanceof URLSearchParams ||
53
+ body instanceof ArrayBuffer ||
54
+ ArrayBuffer.isView(body);
55
+ if (!supported) {
56
+ throw new IntegrationRefusedError("body-not-supported", `${policy.name}: this kind of request body is not supported; send text, bytes or a form`);
57
+ }
58
+ }
59
+ export function requestTooLarge(policy, url, maxBytes) {
60
+ return new IntegrationRefusedError("request-too-large", `${policy.name}: the request body to ${url.host}${url.pathname} is larger than ${maxBytes} bytes`);
61
+ }
62
+ export function toForm(policy, body) {
63
+ if (body instanceof URLSearchParams)
64
+ return body;
65
+ if (typeof body === "string")
66
+ return new URLSearchParams(body);
67
+ throw new IntegrationRefusedError("secret-needs-form-body", `${policy.name}: a secret placed in a form field needs a URLSearchParams or text form body`);
68
+ }
@@ -0,0 +1,25 @@
1
+ import type { RefusalCode } from "@halonicjs/adapters/integration-kit";
2
+ /**
3
+ * One request an integration made. Method, host, path, status and time only:
4
+ * no query, no headers and no bodies, so the log never holds a secret or the
5
+ * content of a message. The integration debugger reads only this.
6
+ */
7
+ export interface RequestLogEntry {
8
+ readonly method: string;
9
+ readonly host: string;
10
+ readonly path: string;
11
+ /** The final status, after redirects. Absent when no response came. */
12
+ readonly status?: number;
13
+ readonly durationMs: number;
14
+ readonly outcome: "ok" | "refused" | "failed";
15
+ /** Why the kit refused it, when it did. */
16
+ readonly refusal?: RefusalCode;
17
+ }
18
+ /** The most recent requests of one integration, oldest first. */
19
+ export declare class RequestLog {
20
+ #private;
21
+ constructor(limit?: number);
22
+ add(entry: RequestLogEntry): void;
23
+ /** A copy of the entries, oldest first. */
24
+ entries(): RequestLogEntry[];
25
+ }
@@ -0,0 +1,17 @@
1
+ /** The most recent requests of one integration, oldest first. */
2
+ export class RequestLog {
3
+ #entries = [];
4
+ #limit;
5
+ constructor(limit = 200) {
6
+ this.#limit = limit;
7
+ }
8
+ add(entry) {
9
+ this.#entries.push(entry);
10
+ if (this.#entries.length > this.#limit)
11
+ this.#entries.shift();
12
+ }
13
+ /** A copy of the entries, oldest first. */
14
+ entries() {
15
+ return [...this.#entries];
16
+ }
17
+ }
@@ -0,0 +1,27 @@
1
+ import type { IntegrationPolicy } from "./policy.js";
2
+ import { type SecretForms } from "./secret-filter.js";
3
+ /** What {@link guardBody} enforces while the integration reads the body. */
4
+ export interface BodyGuard {
5
+ /** The caller's signal and the request's deadlines. */
6
+ readonly signal: AbortSignal;
7
+ readonly idleMs: number;
8
+ readonly maxBytes: number;
9
+ /** Ends the request because the body stalled. */
10
+ readonly onIdle: () => void;
11
+ /** Called once when the body is finished, failed or cancelled. */
12
+ readonly done: () => void;
13
+ /**
14
+ * The secrets and tokens of this request, removed from the status text, the
15
+ * headers, the URL, the body and its errors. The kit replaces it when a hop
16
+ * brings in a token that wasn't known before.
17
+ */
18
+ secrets: SecretForms;
19
+ }
20
+ /**
21
+ * Passes the body through with the request's secrets removed, failing it when it grows over the size limit, when no data comes
22
+ * for the idle time while the integration is waiting, or when the request
23
+ * is aborted. Time the integration spends between reads doesn't count.
24
+ */
25
+ export declare function guardBody(policy: IntegrationPolicy, response: Response, url: URL, guard: BodyGuard): Response;
26
+ /** Settles like the promise, or rejects as soon as the signal aborts, whatever the transport does. */
27
+ export declare function untilAborted<T>(promise: Promise<T>, signal: AbortSignal): Promise<T>;
@@ -0,0 +1,117 @@
1
+ import { IntegrationRefusedError } from "@halonicjs/adapters/integration-kit";
2
+ import { removeSecrets, removeSecretsFromError, removeSecretsFromHeaders, SecretRemover, } from "./secret-filter.js";
3
+ /**
4
+ * Passes the body through with the request's secrets removed, failing it when it grows over the size limit, when no data comes
5
+ * for the idle time while the integration is waiting, or when the request
6
+ * is aborted. Time the integration spends between reads doesn't count.
7
+ */
8
+ export function guardBody(policy, response, url, guard) {
9
+ const tooLarge = () => new IntegrationRefusedError("response-too-large", `${policy.name}: the response from ${url.host}${url.pathname} is larger than ${guard.maxBytes} bytes`);
10
+ refuseDeclaredSize(response, guard, tooLarge);
11
+ const status = statusOf(response, guard.secrets);
12
+ const headers = removeSecretsFromHeaders(response.headers, guard.secrets);
13
+ const finalUrl = removeSecrets(url.href, guard.secrets);
14
+ if (response.body === null) {
15
+ guard.done();
16
+ return withUrl(new Response(null, { ...status, headers }), finalUrl);
17
+ }
18
+ // Removing a secret changes the length. The body is filtered as the
19
+ // transport hands it over: `fetch` has already undone the content coding.
20
+ if (guard.secrets.longest > 0)
21
+ headers.delete("content-length");
22
+ const guarded = guardedStream(response.body, guard, tooLarge);
23
+ return withUrl(new Response(guarded, { ...status, headers }), finalUrl);
24
+ }
25
+ /** Refuses a response whose declared length is over the limit, before any of it is read. */
26
+ function refuseDeclaredSize(response, guard, tooLarge) {
27
+ const declared = Number(response.headers.get("content-length") ?? Number.NaN);
28
+ if (!Number.isFinite(declared) || declared <= guard.maxBytes)
29
+ return;
30
+ guard.done();
31
+ void response.body?.cancel();
32
+ throw removeSecretsFromError(tooLarge(), guard.secrets);
33
+ }
34
+ /** The body, filtered and limited, as the stream the integration reads. */
35
+ function guardedStream(body, guard, tooLarge) {
36
+ const reader = body.getReader();
37
+ const state = {
38
+ read: async () => {
39
+ const idle = setTimeout(guard.onIdle, guard.idleMs);
40
+ try {
41
+ return await untilAborted(reader.read(), guard.signal);
42
+ }
43
+ finally {
44
+ clearTimeout(idle);
45
+ }
46
+ },
47
+ remover: new SecretRemover(guard.secrets),
48
+ guard,
49
+ tooLarge,
50
+ seen: 0,
51
+ };
52
+ return new ReadableStream({
53
+ async pull(controller) {
54
+ try {
55
+ await pump(state, controller);
56
+ }
57
+ catch (error) {
58
+ // The size limit and the deadlines name the URL, which a redirect may have chosen.
59
+ const failure = removeSecretsFromError(error, guard.secrets);
60
+ guard.done();
61
+ reader.cancel(failure).catch(() => { });
62
+ throw failure;
63
+ }
64
+ },
65
+ cancel(reason) {
66
+ guard.done();
67
+ return reader.cancel(reason);
68
+ },
69
+ });
70
+ }
71
+ /**
72
+ * Passes on one filtered piece. A piece can be held back whole while the filter waits for the
73
+ * rest of a possible secret, so it reads until there is something to pass on.
74
+ */
75
+ async function pump(state, controller) {
76
+ for (;;) {
77
+ const next = await state.read();
78
+ if (next.done) {
79
+ state.guard.done();
80
+ const rest = state.remover.flush();
81
+ if (rest.length > 0)
82
+ controller.enqueue(rest);
83
+ controller.close();
84
+ return;
85
+ }
86
+ state.seen += next.value.byteLength;
87
+ if (state.seen > state.guard.maxBytes)
88
+ throw state.tooLarge();
89
+ const filtered = state.remover.push(next.value);
90
+ if (filtered.length > 0) {
91
+ controller.enqueue(filtered);
92
+ return;
93
+ }
94
+ }
95
+ }
96
+ /** The status, with the secrets removed from the reason phrase, which the server writes. */
97
+ function statusOf(response, secrets) {
98
+ return { status: response.status, statusText: removeSecrets(response.statusText, secrets) };
99
+ }
100
+ /** Settles like the promise, or rejects as soon as the signal aborts, whatever the transport does. */
101
+ export function untilAborted(promise, signal) {
102
+ return new Promise((resolve, reject) => {
103
+ if (signal.aborted) {
104
+ promise.catch(() => { });
105
+ reject(signal.reason);
106
+ return;
107
+ }
108
+ const onAbort = () => reject(signal.reason);
109
+ signal.addEventListener("abort", onAbort, { once: true });
110
+ promise.then(resolve, reject).finally(() => signal.removeEventListener("abort", onAbort));
111
+ });
112
+ }
113
+ /** Gives the response the URL of the hop that answered, as `fetch` does. */
114
+ function withUrl(target, href) {
115
+ Object.defineProperty(target, "url", { value: href });
116
+ return target;
117
+ }
@@ -0,0 +1,14 @@
1
+ import type { TokenStore } from "../../../core/ports/src/index.js";
2
+ import type { IntegrationPolicy } from "./policy.js";
3
+ /**
4
+ * The name a token is kept under in the shared store: `i<length>_<name>_<token>`.
5
+ * The length makes it unique: integration and token names are lower-case
6
+ * words joined by `-`, so two integrations can never land on the same stored
7
+ * name, even though the store treats `-` and `_` as the same.
8
+ *
9
+ * @example
10
+ * storedTokenName("google-mail", "refresh"); // "i11_google-mail_refresh"
11
+ */
12
+ export declare function storedTokenName(integration: string, token: string): string;
13
+ /** A token store that holds only this integration's declared tokens, under their own names. */
14
+ export declare function scopedTokens(policy: IntegrationPolicy, store: TokenStore): TokenStore;
@@ -0,0 +1,27 @@
1
+ import { IntegrationRefusedError } from "@halonicjs/adapters/integration-kit";
2
+ /**
3
+ * The name a token is kept under in the shared store: `i<length>_<name>_<token>`.
4
+ * The length makes it unique: integration and token names are lower-case
5
+ * words joined by `-`, so two integrations can never land on the same stored
6
+ * name, even though the store treats `-` and `_` as the same.
7
+ *
8
+ * @example
9
+ * storedTokenName("google-mail", "refresh"); // "i11_google-mail_refresh"
10
+ */
11
+ export function storedTokenName(integration, token) {
12
+ return `i${integration.length}_${integration}_${token}`;
13
+ }
14
+ /** A token store that holds only this integration's declared tokens, under their own names. */
15
+ export function scopedTokens(policy, store) {
16
+ const nameOf = (token) => {
17
+ if (!policy.tokens.includes(token)) {
18
+ throw new IntegrationRefusedError("token-not-declared", `${policy.name}: the token "${token}" is not in its permission sheet`);
19
+ }
20
+ return storedTokenName(policy.name, token);
21
+ };
22
+ return {
23
+ get: async (token) => store.get(nameOf(token)),
24
+ set: async (token, value) => store.set(nameOf(token), value),
25
+ remove: async (token) => store.remove(nameOf(token)),
26
+ };
27
+ }