@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,23 @@
1
+ /** Formats a path for messages: `deployments.prod.name`, `cases[0].events[2]`. */
2
+ export function formatPath(path) {
3
+ let text = "";
4
+ for (const segment of path) {
5
+ if (typeof segment === "number")
6
+ text += `[${segment}]`;
7
+ else
8
+ text += text === "" ? segment : `.${segment}`;
9
+ }
10
+ return text;
11
+ }
12
+ /** Turns one of Zod's issues into ours. */
13
+ export function fromZodIssue(issue) {
14
+ const path = issue.path.map(toPathSegment);
15
+ if (issue.code === "unrecognized_keys") {
16
+ return { code: issue.code, path, message: issue.message, keys: [...issue.keys] };
17
+ }
18
+ return { code: issue.code, path, message: issue.message };
19
+ }
20
+ // Parsed files only have text keys; a symbol can only come from code.
21
+ function toPathSegment(segment) {
22
+ return typeof segment === "symbol" ? String(segment) : segment;
23
+ }
@@ -0,0 +1,23 @@
1
+ import type { Schema } from "./schema.js";
2
+ /** A JSON value: what a JSON Schema document is made of. */
3
+ export type JsonValue = null | boolean | number | string | JsonValue[] | {
4
+ [key: string]: JsonValue;
5
+ };
6
+ /** A JSON Schema document. */
7
+ export type JsonSchema = {
8
+ [key: string]: JsonValue;
9
+ };
10
+ /** The JSON Schema version `toJsonSchema` writes. */
11
+ export declare const JSON_SCHEMA_DRAFT = "https://json-schema.org/draft/2020-12/schema";
12
+ /**
13
+ * Describes a schema as a JSON Schema 2020-12 document, for editors, docs and
14
+ * other engines. It describes the **input**: a key with a default may be left
15
+ * out, so it isn't `required`. Refinements can't be expressed and are left
16
+ * out. Recursive schemas become `$defs` entries referenced with `$ref`.
17
+ *
18
+ * @example
19
+ * toJsonSchema(s.object({ name: s.string().min(1) }).strict());
20
+ * // { $schema: "…/2020-12/schema", type: "object", properties: { name: { type: "string", minLength: 1 } },
21
+ * // required: ["name"], additionalProperties: false }
22
+ */
23
+ export declare function toJsonSchema(schema: Schema): JsonSchema;
@@ -0,0 +1,22 @@
1
+ import { z } from "zod";
2
+ /** The JSON Schema version `toJsonSchema` writes. */
3
+ export const JSON_SCHEMA_DRAFT = "https://json-schema.org/draft/2020-12/schema";
4
+ /**
5
+ * Describes a schema as a JSON Schema 2020-12 document, for editors, docs and
6
+ * other engines. It describes the **input**: a key with a default may be left
7
+ * out, so it isn't `required`. Refinements can't be expressed and are left
8
+ * out. Recursive schemas become `$defs` entries referenced with `$ref`.
9
+ *
10
+ * @example
11
+ * toJsonSchema(s.object({ name: s.string().min(1) }).strict());
12
+ * // { $schema: "…/2020-12/schema", type: "object", properties: { name: { type: "string", minLength: 1 } },
13
+ * // required: ["name"], additionalProperties: false }
14
+ */
15
+ export function toJsonSchema(schema) {
16
+ const document = z.toJSONSchema(schema, {
17
+ target: "draft-2020-12",
18
+ io: "input",
19
+ unrepresentable: "any",
20
+ });
21
+ return document;
22
+ }
@@ -0,0 +1,17 @@
1
+ import { type Result } from "../../std/src/index.js";
2
+ import { type Issue } from "./issue.js";
3
+ import type { Infer, Schema } from "./schema.js";
4
+ /**
5
+ * Checks an input against a schema. Never throws for a bad input: it returns
6
+ * the parsed value, with defaults filled in, or every issue with its path.
7
+ *
8
+ * @param schema - the schema to check against
9
+ * @param input - anything, usually a parsed YAML or JSON file
10
+ * @returns `ok(value)`, or `err(issues)` with at least one issue
11
+ *
12
+ * @example
13
+ * const parsed = parse(Deployment, { name: "prod" });
14
+ * if (!parsed.ok) return reportAt(parsed.error[0].path);
15
+ * deploy(parsed.value);
16
+ */
17
+ export declare function parse<S extends Schema>(schema: S, input: unknown): Result<Infer<S>, Issue[]>;
@@ -0,0 +1,25 @@
1
+ import { err, ok } from "../../std/src/index.js";
2
+ import { findTooDeep } from "./depth.js";
3
+ import { fromZodIssue } from "./issue.js";
4
+ /**
5
+ * Checks an input against a schema. Never throws for a bad input: it returns
6
+ * the parsed value, with defaults filled in, or every issue with its path.
7
+ *
8
+ * @param schema - the schema to check against
9
+ * @param input - anything, usually a parsed YAML or JSON file
10
+ * @returns `ok(value)`, or `err(issues)` with at least one issue
11
+ *
12
+ * @example
13
+ * const parsed = parse(Deployment, { name: "prod" });
14
+ * if (!parsed.ok) return reportAt(parsed.error[0].path);
15
+ * deploy(parsed.value);
16
+ */
17
+ export function parse(schema, input) {
18
+ const tooDeep = findTooDeep(input);
19
+ if (tooDeep !== undefined)
20
+ return err([tooDeep]);
21
+ const result = schema.safeParse(input);
22
+ if (result.success)
23
+ return ok(result.data);
24
+ return err(result.error.issues.map(fromZodIssue));
25
+ }
@@ -0,0 +1,12 @@
1
+ import type { z } from "zod";
2
+ /**
3
+ * A schema that checks an input and produces a value of type `Output`.
4
+ * `Input` is what a file may contain: keys with a default may be left out.
5
+ * Build one with `s`; give a recursive schema this type explicitly:
6
+ * `const Guard: Schema<Guard> = s.lazy(() => …)`.
7
+ */
8
+ export type Schema<Output = unknown, Input = Output> = z.ZodType<Output, Input>;
9
+ /** The value a schema produces, with defaults filled in. Like `z.infer`. */
10
+ export type Infer<S extends Schema> = z.output<S>;
11
+ /** What a schema accepts: keys with a default are optional here. Like `z.input`. */
12
+ export type InferInput<S extends Schema> = z.input<S>;
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,13 @@
1
+ /**
2
+ * Reads an amount the way someone writes it on a receipt: digits, and at
3
+ * most one `.` or `,` before the decimals. No sign, no grouping, no
4
+ * exponent. A single separator is always the decimal one, so `1,000` is 1.
5
+ *
6
+ * @param text - what the user typed; surrounding spaces are ignored
7
+ * @returns the amount, or `undefined` for empty or anything else
8
+ *
9
+ * @example
10
+ * parseAmount("15,00"); // 15
11
+ * parseAmount("1.000,50"); // undefined
12
+ */
13
+ export declare function parseAmount(text: string): number | undefined;
@@ -0,0 +1,22 @@
1
+ const amountShape = /^(\d+)(?:[.,](\d+))?$/;
2
+ /**
3
+ * Reads an amount the way someone writes it on a receipt: digits, and at
4
+ * most one `.` or `,` before the decimals. No sign, no grouping, no
5
+ * exponent. A single separator is always the decimal one, so `1,000` is 1.
6
+ *
7
+ * @param text - what the user typed; surrounding spaces are ignored
8
+ * @returns the amount, or `undefined` for empty or anything else
9
+ *
10
+ * @example
11
+ * parseAmount("15,00"); // 15
12
+ * parseAmount("1.000,50"); // undefined
13
+ */
14
+ export function parseAmount(text) {
15
+ const match = amountShape.exec(text.trim());
16
+ if (match === null) {
17
+ return undefined;
18
+ }
19
+ const [, whole, decimals] = match;
20
+ const amount = Number(decimals === undefined ? whole : `${whole}.${decimals}`);
21
+ return Number.isFinite(amount) ? amount : undefined;
22
+ }
@@ -0,0 +1,18 @@
1
+ /**
2
+ * Writes a host name in its ASCII form: lowercase, and each label with a
3
+ * non-ASCII character as `xn--` plus its Punycode. A host that is already
4
+ * ASCII only becomes lowercase, so `Mcp.Acme.test`, `mcp.acme.test` and
5
+ * `MCP.ACME.TEST` are the same host.
6
+ *
7
+ * It applies Unicode NFC and lowercasing before encoding, which covers the
8
+ * forms a person types. It doesn't apply the full IDNA mapping table, so it
9
+ * never treats two different hosts as one; at worst a rare spelling of the
10
+ * same host gets a different ASCII form.
11
+ *
12
+ * @param host - the host name, without port or brackets
13
+ * @returns the host in ASCII
14
+ *
15
+ * @example
16
+ * asciiHost("Bücher.example"); // "xn--bcher-kva.example"
17
+ */
18
+ export declare function asciiHost(host: string): string;
@@ -0,0 +1,110 @@
1
+ // A host name in its ASCII form, the way the trust prompt shows and hashes it.
2
+ // The core has no `URL` class (plan 4.1), so the Punycode encoding of
3
+ // RFC 3492 is written out here.
4
+ const base = 36;
5
+ const tMin = 1;
6
+ const tMax = 26;
7
+ const skew = 38;
8
+ const damp = 700;
9
+ const initialBias = 72;
10
+ const initialN = 128;
11
+ /**
12
+ * Writes a host name in its ASCII form: lowercase, and each label with a
13
+ * non-ASCII character as `xn--` plus its Punycode. A host that is already
14
+ * ASCII only becomes lowercase, so `Mcp.Acme.test`, `mcp.acme.test` and
15
+ * `MCP.ACME.TEST` are the same host.
16
+ *
17
+ * It applies Unicode NFC and lowercasing before encoding, which covers the
18
+ * forms a person types. It doesn't apply the full IDNA mapping table, so it
19
+ * never treats two different hosts as one; at worst a rare spelling of the
20
+ * same host gets a different ASCII form.
21
+ *
22
+ * @param host - the host name, without port or brackets
23
+ * @returns the host in ASCII
24
+ *
25
+ * @example
26
+ * asciiHost("Bücher.example"); // "xn--bcher-kva.example"
27
+ */
28
+ export function asciiHost(host) {
29
+ return host
30
+ .normalize("NFC")
31
+ .toLowerCase()
32
+ .split(".")
33
+ .map((label) => (isAscii(label) ? label : `xn--${punycode(label)}`))
34
+ .join(".");
35
+ }
36
+ function isAscii(text) {
37
+ for (const character of text) {
38
+ if (codePointOf(character) >= initialN) {
39
+ return false;
40
+ }
41
+ }
42
+ return true;
43
+ }
44
+ function codePointOf(character) {
45
+ // A character from `for…of` over a string always has a code point.
46
+ return character.codePointAt(0) ?? 0;
47
+ }
48
+ /** RFC 3492 section 6.3: encodes one label's code points as Punycode. */
49
+ function punycode(label) {
50
+ const codePoints = Array.from(label, codePointOf);
51
+ let output = codePoints
52
+ .filter((codePoint) => codePoint < initialN)
53
+ .map((codePoint) => String.fromCodePoint(codePoint))
54
+ .join("");
55
+ const basicCount = output.length;
56
+ if (basicCount > 0) {
57
+ output += "-";
58
+ }
59
+ let n = initialN;
60
+ let delta = 0;
61
+ let bias = initialBias;
62
+ let handled = basicCount;
63
+ while (handled < codePoints.length) {
64
+ const next = Math.min(...codePoints.filter((codePoint) => codePoint >= n));
65
+ delta += (next - n) * (handled + 1);
66
+ n = next;
67
+ for (const codePoint of codePoints) {
68
+ if (codePoint < n) {
69
+ delta += 1;
70
+ }
71
+ if (codePoint === n) {
72
+ output += encodeDelta(delta, bias);
73
+ bias = adapt(delta, handled + 1, handled === basicCount);
74
+ delta = 0;
75
+ handled += 1;
76
+ }
77
+ }
78
+ delta += 1;
79
+ n += 1;
80
+ }
81
+ return output;
82
+ }
83
+ /** Writes one delta as a generalized variable-length integer (RFC 3492 section 3.3). */
84
+ function encodeDelta(delta, bias) {
85
+ let output = "";
86
+ let rest = delta;
87
+ for (let k = base;; k += base) {
88
+ const threshold = Math.min(Math.max(k - bias, tMin), tMax);
89
+ if (rest < threshold) {
90
+ return output + digit(rest);
91
+ }
92
+ output += digit(threshold + ((rest - threshold) % (base - threshold)));
93
+ rest = Math.floor((rest - threshold) / (base - threshold));
94
+ }
95
+ }
96
+ /** RFC 3492 section 6.1: the bias for the next delta. */
97
+ function adapt(delta, pointCount, first) {
98
+ let scaled = first ? Math.floor(delta / damp) : Math.floor(delta / 2);
99
+ scaled += Math.floor(scaled / pointCount);
100
+ let k = 0;
101
+ while (scaled > ((base - tMin) * tMax) >> 1) {
102
+ scaled = Math.floor(scaled / (base - tMin));
103
+ k += base;
104
+ }
105
+ return k + Math.floor(((base - tMin + 1) * scaled) / (scaled + skew));
106
+ }
107
+ /** The Punycode digit for 0–35: `a`–`z`, then `0`–`9`. */
108
+ function digit(value) {
109
+ return String.fromCharCode(value < 26 ? 97 + value : 22 + value);
110
+ }
@@ -0,0 +1,39 @@
1
+ /** Thrown when an assertion fails. It always means a bug, never bad user input. */
2
+ export declare class AssertionError extends Error {
3
+ readonly name = "AssertionError";
4
+ }
5
+ /**
6
+ * Throws an `AssertionError` with `message` when `condition` is false.
7
+ * TypeScript treats the condition as true after the call.
8
+ *
9
+ * @param condition - what must hold here
10
+ * @param message - says what was expected, so the failure explains itself
11
+ * @throws AssertionError when `condition` is false
12
+ *
13
+ * @example
14
+ * assert(stepMs > 0, `stepMs must be positive, got ${stepMs}`);
15
+ */
16
+ export declare function assert(condition: boolean, message: string): asserts condition;
17
+ /**
18
+ * Returns `value` when it is neither `undefined` nor `null`, and throws
19
+ * otherwise. Use it instead of the non-null `!` operator.
20
+ *
21
+ * @param value - the value that must be present
22
+ * @param what - names the value in the error, such as `"the run's first event"`
23
+ * @returns the value, with `undefined` and `null` removed from its type
24
+ * @throws AssertionError when the value is missing
25
+ *
26
+ * @example
27
+ * const first = assertDefined(events[0], "the run's first event");
28
+ */
29
+ export declare function assertDefined<T>(value: T, what: string): NonNullable<T>;
30
+ /**
31
+ * Marks a branch that the type system says can't be reached, such as the
32
+ * `default` of a `switch` over every member of a union. It fails to compile
33
+ * when a member is missing, and throws if the code runs anyway.
34
+ *
35
+ * @param value - the value that should have type `never` here
36
+ * @param what - names the value in the error, such as `"state type"`
37
+ * @throws AssertionError always
38
+ */
39
+ export declare function assertNever(value: never, what: string): never;
@@ -0,0 +1,59 @@
1
+ /** Thrown when an assertion fails. It always means a bug, never bad user input. */
2
+ export class AssertionError extends Error {
3
+ name = "AssertionError";
4
+ }
5
+ /**
6
+ * Throws an `AssertionError` with `message` when `condition` is false.
7
+ * TypeScript treats the condition as true after the call.
8
+ *
9
+ * @param condition - what must hold here
10
+ * @param message - says what was expected, so the failure explains itself
11
+ * @throws AssertionError when `condition` is false
12
+ *
13
+ * @example
14
+ * assert(stepMs > 0, `stepMs must be positive, got ${stepMs}`);
15
+ */
16
+ export function assert(condition, message) {
17
+ if (!condition) {
18
+ throw new AssertionError(message);
19
+ }
20
+ }
21
+ /**
22
+ * Returns `value` when it is neither `undefined` nor `null`, and throws
23
+ * otherwise. Use it instead of the non-null `!` operator.
24
+ *
25
+ * @param value - the value that must be present
26
+ * @param what - names the value in the error, such as `"the run's first event"`
27
+ * @returns the value, with `undefined` and `null` removed from its type
28
+ * @throws AssertionError when the value is missing
29
+ *
30
+ * @example
31
+ * const first = assertDefined(events[0], "the run's first event");
32
+ */
33
+ export function assertDefined(value, what) {
34
+ if (value === undefined || value === null) {
35
+ throw new AssertionError(`Expected ${what} to be defined, but it was ${String(value)}.`);
36
+ }
37
+ return value;
38
+ }
39
+ /**
40
+ * Marks a branch that the type system says can't be reached, such as the
41
+ * `default` of a `switch` over every member of a union. It fails to compile
42
+ * when a member is missing, and throws if the code runs anyway.
43
+ *
44
+ * @param value - the value that should have type `never` here
45
+ * @param what - names the value in the error, such as `"state type"`
46
+ * @throws AssertionError always
47
+ */
48
+ export function assertNever(value, what) {
49
+ throw new AssertionError(`Unexpected ${what}: ${describeValue(value)}.`);
50
+ }
51
+ /** JSON where possible, so a string shows its quotes; `String()` for what JSON can't write. */
52
+ function describeValue(value) {
53
+ try {
54
+ return JSON.stringify(value) ?? String(value);
55
+ }
56
+ catch {
57
+ return String(value);
58
+ }
59
+ }
@@ -0,0 +1,23 @@
1
+ /**
2
+ * Writes bytes as base64url, without padding.
3
+ *
4
+ * @param bytes - the bytes to encode
5
+ * @returns the text, using only `A-Z`, `a-z`, `0-9`, `-` and `_`
6
+ *
7
+ * @example
8
+ * encodeBase64url(new Uint8Array([0xfb, 0xff])); // "-_8"
9
+ */
10
+ export declare function encodeBase64url(bytes: Uint8Array): string;
11
+ /**
12
+ * Reads strict base64url text back into bytes: no padding, no other
13
+ * characters, and no stray bits after the last byte. So each byte string has
14
+ * exactly one text that reads as it.
15
+ *
16
+ * @param text - the text to decode
17
+ * @returns the bytes, or `undefined` when the text isn't strict base64url
18
+ *
19
+ * @example
20
+ * decodeBase64url("-_8"); // Uint8Array [0xfb, 0xff]
21
+ * decodeBase64url("-_9"); // undefined: the last character has stray bits
22
+ */
23
+ export declare function decodeBase64url(text: string): Uint8Array<ArrayBuffer> | undefined;
@@ -0,0 +1,65 @@
1
+ // Base64url without padding (RFC 4648, section 5), as PKCE and JSON Web Tokens
2
+ // use it. Written out because `Buffer` doesn't exist in workerd and
3
+ // `Uint8Array.toBase64` and `Uint8Array.fromBase64` aren't everywhere yet.
4
+ const alphabet = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_";
5
+ /** Base64url characters only; padding is never used. */
6
+ const base64urlPattern = /^[A-Za-z0-9_-]*$/;
7
+ /**
8
+ * Writes bytes as base64url, without padding.
9
+ *
10
+ * @param bytes - the bytes to encode
11
+ * @returns the text, using only `A-Z`, `a-z`, `0-9`, `-` and `_`
12
+ *
13
+ * @example
14
+ * encodeBase64url(new Uint8Array([0xfb, 0xff])); // "-_8"
15
+ */
16
+ export function encodeBase64url(bytes) {
17
+ let text = "";
18
+ for (let start = 0; start < bytes.length; start += 3) {
19
+ const chunk = bytes.subarray(start, start + 3);
20
+ const bits = ((chunk[0] ?? 0) << 16) | ((chunk[1] ?? 0) << 8) | (chunk[2] ?? 0);
21
+ // Three bytes give four characters; a shorter last chunk gives one fewer per missing byte.
22
+ const characters = chunk.length + 1;
23
+ for (let index = 0; index < characters; index += 1) {
24
+ text += alphabet[(bits >> (18 - 6 * index)) & 63];
25
+ }
26
+ }
27
+ return text;
28
+ }
29
+ /**
30
+ * Reads strict base64url text back into bytes: no padding, no other
31
+ * characters, and no stray bits after the last byte. So each byte string has
32
+ * exactly one text that reads as it.
33
+ *
34
+ * @param text - the text to decode
35
+ * @returns the bytes, or `undefined` when the text isn't strict base64url
36
+ *
37
+ * @example
38
+ * decodeBase64url("-_8"); // Uint8Array [0xfb, 0xff]
39
+ * decodeBase64url("-_9"); // undefined: the last character has stray bits
40
+ */
41
+ export function decodeBase64url(text) {
42
+ if (!base64urlPattern.test(text) || text.length % 4 === 1) {
43
+ return undefined;
44
+ }
45
+ const bytes = new Uint8Array(Math.floor((text.length * 3) / 4));
46
+ let written = 0;
47
+ for (let start = 0; start < text.length; start += 4) {
48
+ const chunk = text.slice(start, start + 4);
49
+ let bits = 0;
50
+ for (let index = 0; index < 4; index += 1) {
51
+ bits = (bits << 6) | (index < chunk.length ? alphabet.indexOf(chunk.charAt(index)) : 0);
52
+ }
53
+ // Four characters give three bytes; a shorter last chunk gives one fewer per missing character.
54
+ const byteCount = chunk.length - 1;
55
+ const strayBits = bits & ((1 << (8 * (3 - byteCount))) - 1);
56
+ if (strayBits !== 0) {
57
+ return undefined;
58
+ }
59
+ for (let index = 0; index < byteCount; index += 1) {
60
+ bytes[written] = (bits >> (16 - 8 * index)) & 0xff;
61
+ written += 1;
62
+ }
63
+ }
64
+ return bytes;
65
+ }
@@ -0,0 +1,18 @@
1
+ /**
2
+ * Writes plain data as JSON in one canonical form, so equal data always
3
+ * gives the same text and can be hashed: object keys sorted by code unit,
4
+ * arrays kept in order, no spaces. As with `JSON.stringify`, an object key
5
+ * whose value is `undefined` is left out.
6
+ *
7
+ * It throws instead of writing something lossy: a number that isn't finite,
8
+ * `undefined` in an array, or a value JSON can't hold, such as a `Map`, a
9
+ * `Date`, a function or a bigint.
10
+ *
11
+ * @param value - plain data: objects, arrays, strings, finite numbers, booleans and `null`
12
+ * @returns the canonical JSON text
13
+ * @throws when the data isn't plain JSON data, saying where
14
+ *
15
+ * @example
16
+ * canonicalJson({ b: [2, 1], a: "x" }); // '{"a":"x","b":[2,1]}'
17
+ */
18
+ export declare function canonicalJson(value: unknown): string;
@@ -0,0 +1,56 @@
1
+ import { describeObject, isPlainObject, keyPath } from "./plain-data.js";
2
+ /**
3
+ * Writes plain data as JSON in one canonical form, so equal data always
4
+ * gives the same text and can be hashed: object keys sorted by code unit,
5
+ * arrays kept in order, no spaces. As with `JSON.stringify`, an object key
6
+ * whose value is `undefined` is left out.
7
+ *
8
+ * It throws instead of writing something lossy: a number that isn't finite,
9
+ * `undefined` in an array, or a value JSON can't hold, such as a `Map`, a
10
+ * `Date`, a function or a bigint.
11
+ *
12
+ * @param value - plain data: objects, arrays, strings, finite numbers, booleans and `null`
13
+ * @returns the canonical JSON text
14
+ * @throws when the data isn't plain JSON data, saying where
15
+ *
16
+ * @example
17
+ * canonicalJson({ b: [2, 1], a: "x" }); // '{"a":"x","b":[2,1]}'
18
+ */
19
+ export function canonicalJson(value) {
20
+ return write(value, "value");
21
+ }
22
+ function write(value, path) {
23
+ if (value === null || typeof value === "boolean" || typeof value === "string") {
24
+ return JSON.stringify(value);
25
+ }
26
+ if (typeof value === "number") {
27
+ if (!Number.isFinite(value)) {
28
+ throw new TypeError(`Can't write ${path} as JSON: ${value} isn't a finite number.`);
29
+ }
30
+ return JSON.stringify(value);
31
+ }
32
+ if (Array.isArray(value)) {
33
+ const items = value.map((item, index) => {
34
+ if (item === undefined) {
35
+ throw new TypeError(`Can't write ${path}[${index}] as JSON: it is undefined.`);
36
+ }
37
+ return write(item, `${path}[${index}]`);
38
+ });
39
+ return `[${items.join(",")}]`;
40
+ }
41
+ if (isPlainObject(value)) {
42
+ const keys = Object.keys(value)
43
+ .filter((key) => value[key] !== undefined)
44
+ .sort(byCodeUnit);
45
+ const entries = keys.map((key) => `${JSON.stringify(key)}:${write(value[key], keyPath(path, key))}`);
46
+ return `{${entries.join(",")}}`;
47
+ }
48
+ const kind = typeof value === "object" ? describeObject(value) : `a ${typeof value}`;
49
+ throw new TypeError(`Can't write ${path} as JSON: it is ${kind}.`);
50
+ }
51
+ function byCodeUnit(left, right) {
52
+ if (left === right) {
53
+ return 0;
54
+ }
55
+ return left < right ? -1 : 1;
56
+ }
@@ -0,0 +1,27 @@
1
+ /**
2
+ * Tells the current time. Code that needs the time takes a `Clock`, so tests
3
+ * can pass a fixed one and get the same output on every run.
4
+ */
5
+ export interface Clock {
6
+ /** The current time. */
7
+ now(): Date;
8
+ }
9
+ /** The real clock: the time of the machine it runs on. */
10
+ export declare const systemClock: Clock;
11
+ /** The start of `fixedClock` when no start is given: 2026-01-01T00:00:00Z. */
12
+ export declare const fixedClockStart: number;
13
+ /**
14
+ * A clock for tests. The first call returns `start`, and every later call
15
+ * returns a time `stepMs` later than the call before.
16
+ *
17
+ * @param start - the first time, in milliseconds since 1970 (default 2026-01-01T00:00:00Z)
18
+ * @param stepMs - how far the clock moves on per call, zero or more (default 1000)
19
+ * @returns a new clock with its own position
20
+ * @throws AssertionError when `start` or `stepMs` isn't a valid number of milliseconds
21
+ *
22
+ * @example
23
+ * const clock = fixedClock();
24
+ * clock.now().toISOString(); // "2026-01-01T00:00:00.000Z"
25
+ * clock.now().toISOString(); // "2026-01-01T00:00:01.000Z"
26
+ */
27
+ export declare function fixedClock(start?: number, stepMs?: number): Clock;
@@ -0,0 +1,33 @@
1
+ import { assert } from "./assert.js";
2
+ /** The real clock: the time of the machine it runs on. */
3
+ export const systemClock = {
4
+ now: () => new Date(),
5
+ };
6
+ /** The start of `fixedClock` when no start is given: 2026-01-01T00:00:00Z. */
7
+ export const fixedClockStart = Date.UTC(2026, 0, 1);
8
+ /**
9
+ * A clock for tests. The first call returns `start`, and every later call
10
+ * returns a time `stepMs` later than the call before.
11
+ *
12
+ * @param start - the first time, in milliseconds since 1970 (default 2026-01-01T00:00:00Z)
13
+ * @param stepMs - how far the clock moves on per call, zero or more (default 1000)
14
+ * @returns a new clock with its own position
15
+ * @throws AssertionError when `start` or `stepMs` isn't a valid number of milliseconds
16
+ *
17
+ * @example
18
+ * const clock = fixedClock();
19
+ * clock.now().toISOString(); // "2026-01-01T00:00:00.000Z"
20
+ * clock.now().toISOString(); // "2026-01-01T00:00:01.000Z"
21
+ */
22
+ export function fixedClock(start = fixedClockStart, stepMs = 1000) {
23
+ assert(Number.isFinite(start), `fixedClock needs a finite start time, got ${start}.`);
24
+ assert(Number.isFinite(stepMs) && stepMs >= 0, `fixedClock needs a step of zero or more milliseconds, got ${stepMs}.`);
25
+ let current = start;
26
+ return {
27
+ now() {
28
+ const time = new Date(current);
29
+ current += stepMs;
30
+ return time;
31
+ },
32
+ };
33
+ }
@@ -0,0 +1,16 @@
1
+ /**
2
+ * Compares two byte arrays in time that depends only on their length, never
3
+ * on where they first differ. Use it to check password hashes and tokens, so
4
+ * an attacker can't learn a secret from how long a comparison takes.
5
+ *
6
+ * Arrays of different lengths are unequal at once: lengths aren't secret
7
+ * here, because hashes and tokens have a fixed length.
8
+ *
9
+ * @param first - the first bytes
10
+ * @param second - the second bytes
11
+ * @returns true when both hold the same bytes
12
+ *
13
+ * @example
14
+ * constantTimeEqual(storedHash, await hasher.hash(password, salt)); // true or false
15
+ */
16
+ export declare function constantTimeEqual(first: Uint8Array, second: Uint8Array): boolean;