@halonicjs/testing 0.0.0-stage → 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +202 -0
- package/NOTICE +1 -0
- package/README.md +40 -2
- package/dist/adapters/http-kit/src/address-class.d.ts +34 -0
- package/dist/adapters/http-kit/src/address-class.js +109 -0
- package/dist/adapters/http-kit/src/index.d.ts +2 -0
- package/dist/adapters/http-kit/src/index.js +2 -0
- package/dist/adapters/http-kit/src/ip-address.d.ts +23 -0
- package/dist/adapters/http-kit/src/ip-address.js +89 -0
- package/dist/adapters/integration-kit/src/declaration.d.ts +14 -0
- package/dist/adapters/integration-kit/src/declaration.js +77 -0
- package/dist/adapters/integration-kit/src/host.d.ts +28 -0
- package/dist/adapters/integration-kit/src/host.js +30 -0
- package/dist/adapters/integration-kit/src/index.d.ts +14 -0
- package/dist/adapters/integration-kit/src/index.js +21 -0
- package/dist/adapters/integration-kit/src/leak-attempt.d.ts +14 -0
- package/dist/adapters/integration-kit/src/leak-attempt.js +16 -0
- package/dist/adapters/integration-kit/src/limited-http.d.ts +49 -0
- package/dist/adapters/integration-kit/src/limited-http.js +182 -0
- package/dist/adapters/integration-kit/src/load-problem.d.ts +20 -0
- package/dist/adapters/integration-kit/src/load-problem.js +1 -0
- package/dist/adapters/integration-kit/src/loader.d.ts +104 -0
- package/dist/adapters/integration-kit/src/loader.js +219 -0
- package/dist/adapters/integration-kit/src/local-address.d.ts +15 -0
- package/dist/adapters/integration-kit/src/local-address.js +25 -0
- package/dist/adapters/integration-kit/src/own-request.d.ts +33 -0
- package/dist/adapters/integration-kit/src/own-request.js +36 -0
- package/dist/adapters/integration-kit/src/plugin-load.d.ts +14 -0
- package/dist/adapters/integration-kit/src/plugin-load.js +58 -0
- package/dist/adapters/integration-kit/src/policy.d.ts +55 -0
- package/dist/adapters/integration-kit/src/policy.js +37 -0
- package/dist/adapters/integration-kit/src/request-body.d.ts +38 -0
- package/dist/adapters/integration-kit/src/request-body.js +68 -0
- package/dist/adapters/integration-kit/src/request-log.d.ts +25 -0
- package/dist/adapters/integration-kit/src/request-log.js +17 -0
- package/dist/adapters/integration-kit/src/response-body.d.ts +23 -0
- package/dist/adapters/integration-kit/src/response-body.js +117 -0
- package/dist/adapters/integration-kit/src/scoped-tokens.d.ts +14 -0
- package/dist/adapters/integration-kit/src/scoped-tokens.js +27 -0
- package/dist/adapters/integration-kit/src/secret-filter.d.ts +84 -0
- package/dist/adapters/integration-kit/src/secret-filter.js +205 -0
- package/dist/adapters/integration-kit/src/secret-in-request.d.ts +59 -0
- package/dist/adapters/integration-kit/src/secret-in-request.js +133 -0
- package/dist/adapters/integration-kit/src/secret-placement.d.ts +36 -0
- package/dist/adapters/integration-kit/src/secret-placement.js +190 -0
- package/dist/adapters/integration-kit/src/wait.d.ts +16 -0
- package/dist/adapters/integration-kit/src/wait.js +35 -0
- package/dist/core/events/src/add-usage.d.ts +10 -0
- package/dist/core/events/src/add-usage.js +27 -0
- package/dist/core/events/src/agent-resume.d.ts +24 -0
- package/dist/core/events/src/agent-resume.js +1 -0
- package/dist/core/events/src/home-path.d.ts +13 -0
- package/dist/core/events/src/home-path.js +26 -0
- package/dist/core/events/src/index.d.ts +13 -0
- package/dist/core/events/src/index.js +7 -0
- package/dist/core/events/src/run-basics.d.ts +205 -0
- package/dist/core/events/src/run-basics.js +1 -0
- package/dist/core/events/src/run-event.d.ts +434 -0
- package/dist/core/events/src/run-event.js +1 -0
- package/dist/core/events/src/run-summary.d.ts +108 -0
- package/dist/core/events/src/run-summary.js +1 -0
- package/dist/core/events/src/sandbox-blocked.d.ts +42 -0
- package/dist/core/events/src/sandbox-blocked.js +26 -0
- package/dist/core/events/src/sandbox-opened-read.d.ts +17 -0
- package/dist/core/events/src/sandbox-opened-read.js +63 -0
- package/dist/core/events/src/sandbox-opened.d.ts +94 -0
- package/dist/core/events/src/sandbox-opened.js +52 -0
- package/dist/core/events/src/summarize.d.ts +14 -0
- package/dist/core/events/src/summarize.js +188 -0
- package/dist/core/events/src/timeline-entry.d.ts +21 -0
- package/dist/core/events/src/timeline-entry.js +105 -0
- package/dist/core/events/src/upgrade.d.ts +23 -0
- package/dist/core/events/src/upgrade.js +49 -0
- package/dist/core/format/src/compact.d.ts +30 -0
- package/dist/core/format/src/compact.js +72 -0
- package/dist/core/format/src/index.d.ts +37 -0
- package/dist/core/format/src/index.js +23 -0
- package/dist/core/format/src/integration/index.d.ts +6 -0
- package/dist/core/format/src/integration/index.js +9 -0
- package/dist/core/format/src/json-schema.d.ts +26 -0
- package/dist/core/format/src/json-schema.js +48 -0
- package/dist/core/format/src/kind.d.ts +65 -0
- package/dist/core/format/src/kind.js +1 -0
- package/dist/core/format/src/kinds/agent/kind.d.ts +4 -0
- package/dist/core/format/src/kinds/agent/kind.js +10 -0
- package/dist/core/format/src/kinds/agent/sandbox-fields.d.ts +89 -0
- package/dist/core/format/src/kinds/agent/sandbox-fields.js +197 -0
- package/dist/core/format/src/kinds/agent/schema.d.ts +147 -0
- package/dist/core/format/src/kinds/agent/schema.js +107 -0
- package/dist/core/format/src/kinds/agent/working-folder-start.d.ts +74 -0
- package/dist/core/format/src/kinds/agent/working-folder-start.js +312 -0
- package/dist/core/format/src/kinds/collection/kind.d.ts +8 -0
- package/dist/core/format/src/kinds/collection/kind.js +14 -0
- package/dist/core/format/src/kinds/collection/schema.d.ts +89 -0
- package/dist/core/format/src/kinds/collection/schema.js +90 -0
- package/dist/core/format/src/kinds/connector/is-local.d.ts +10 -0
- package/dist/core/format/src/kinds/connector/is-local.js +43 -0
- package/dist/core/format/src/kinds/connector/kind.d.ts +4 -0
- package/dist/core/format/src/kinds/connector/kind.js +119 -0
- package/dist/core/format/src/kinds/connector/schema.d.ts +50 -0
- package/dist/core/format/src/kinds/connector/schema.js +92 -0
- package/dist/core/format/src/kinds/deployments/kind.d.ts +4 -0
- package/dist/core/format/src/kinds/deployments/kind.js +25 -0
- package/dist/core/format/src/kinds/deployments/schema.d.ts +37 -0
- package/dist/core/format/src/kinds/deployments/schema.js +42 -0
- package/dist/core/format/src/kinds/hub/kind.d.ts +4 -0
- package/dist/core/format/src/kinds/hub/kind.js +10 -0
- package/dist/core/format/src/kinds/hub/schema.d.ts +54 -0
- package/dist/core/format/src/kinds/hub/schema.js +34 -0
- package/dist/core/format/src/kinds/integration/kind.d.ts +16 -0
- package/dist/core/format/src/kinds/integration/kind.js +138 -0
- package/dist/core/format/src/kinds/integration/parse-sheet.d.ts +19 -0
- package/dist/core/format/src/kinds/integration/parse-sheet.js +24 -0
- package/dist/core/format/src/kinds/integration/policy.d.ts +67 -0
- package/dist/core/format/src/kinds/integration/policy.js +268 -0
- package/dist/core/format/src/kinds/integration/schema.d.ts +233 -0
- package/dist/core/format/src/kinds/integration/schema.js +233 -0
- package/dist/core/format/src/kinds/knowledge/kind.d.ts +4 -0
- package/dist/core/format/src/kinds/knowledge/kind.js +13 -0
- package/dist/core/format/src/kinds/knowledge/schema.d.ts +18 -0
- package/dist/core/format/src/kinds/knowledge/schema.js +25 -0
- package/dist/core/format/src/kinds/models/kind.d.ts +4 -0
- package/dist/core/format/src/kinds/models/kind.js +10 -0
- package/dist/core/format/src/kinds/models/schema.d.ts +92 -0
- package/dist/core/format/src/kinds/models/schema.js +38 -0
- package/dist/core/format/src/kinds/plugin/backend.d.ts +22 -0
- package/dist/core/format/src/kinds/plugin/backend.js +31 -0
- package/dist/core/format/src/kinds/plugin/checks.d.ts +13 -0
- package/dist/core/format/src/kinds/plugin/checks.js +131 -0
- package/dist/core/format/src/kinds/plugin/kind.d.ts +8 -0
- package/dist/core/format/src/kinds/plugin/kind.js +16 -0
- package/dist/core/format/src/kinds/plugin/problems.d.ts +24 -0
- package/dist/core/format/src/kinds/plugin/problems.js +65 -0
- package/dist/core/format/src/kinds/plugin/schema.d.ts +542 -0
- package/dist/core/format/src/kinds/plugin/schema.js +261 -0
- package/dist/core/format/src/kinds/plugin/setting-values.d.ts +17 -0
- package/dist/core/format/src/kinds/plugin/setting-values.js +38 -0
- package/dist/core/format/src/kinds/plugin/ui-checks.d.ts +8 -0
- package/dist/core/format/src/kinds/plugin/ui-checks.js +94 -0
- package/dist/core/format/src/kinds/provider/kind.d.ts +4 -0
- package/dist/core/format/src/kinds/provider/kind.js +24 -0
- package/dist/core/format/src/kinds/provider/schema.d.ts +17 -0
- package/dist/core/format/src/kinds/provider/schema.js +22 -0
- package/dist/core/format/src/kinds/routine/kind.d.ts +8 -0
- package/dist/core/format/src/kinds/routine/kind.js +25 -0
- package/dist/core/format/src/kinds/routine/schema.d.ts +84 -0
- package/dist/core/format/src/kinds/routine/schema.js +93 -0
- package/dist/core/format/src/kinds/runtime/kind.d.ts +4 -0
- package/dist/core/format/src/kinds/runtime/kind.js +13 -0
- package/dist/core/format/src/kinds/runtime/schema.d.ts +10 -0
- package/dist/core/format/src/kinds/runtime/schema.js +12 -0
- package/dist/core/format/src/kinds/skill/kind.d.ts +4 -0
- package/dist/core/format/src/kinds/skill/kind.js +10 -0
- package/dist/core/format/src/kinds/skill/schema.d.ts +17 -0
- package/dist/core/format/src/kinds/skill/schema.js +17 -0
- package/dist/core/format/src/kinds/skill/scripts-folder.d.ts +27 -0
- package/dist/core/format/src/kinds/skill/scripts-folder.js +37 -0
- package/dist/core/format/src/kinds/workflow/kind.d.ts +8 -0
- package/dist/core/format/src/kinds/workflow/kind.js +14 -0
- package/dist/core/format/src/kinds/workflow/schema.d.ts +162 -0
- package/dist/core/format/src/kinds/workflow/schema.js +106 -0
- package/dist/core/format/src/kinds/workflow-test/kind.d.ts +4 -0
- package/dist/core/format/src/kinds/workflow-test/kind.js +14 -0
- package/dist/core/format/src/kinds/workflow-test/schema.d.ts +67 -0
- package/dist/core/format/src/kinds/workflow-test/schema.js +59 -0
- package/dist/core/format/src/kinds/workspace/kind.d.ts +4 -0
- package/dist/core/format/src/kinds/workspace/kind.js +10 -0
- package/dist/core/format/src/kinds/workspace/schema.d.ts +72 -0
- package/dist/core/format/src/kinds/workspace/schema.js +66 -0
- package/dist/core/format/src/parse-file.d.ts +69 -0
- package/dist/core/format/src/parse-file.js +105 -0
- package/dist/core/format/src/recording/format.d.ts +81 -0
- package/dist/core/format/src/recording/format.js +102 -0
- package/dist/core/format/src/recording/index.d.ts +1 -0
- package/dist/core/format/src/recording/index.js +3 -0
- package/dist/core/format/src/registry.d.ts +64 -0
- package/dist/core/format/src/registry.js +61 -0
- package/dist/core/format/src/reserved.d.ts +20 -0
- package/dist/core/format/src/reserved.js +30 -0
- package/dist/core/format/src/shared/fields.d.ts +37 -0
- package/dist/core/format/src/shared/fields.js +54 -0
- package/dist/core/format/src/shared/guard.d.ts +32 -0
- package/dist/core/format/src/shared/guard.js +16 -0
- package/dist/core/format/src/shared/key-in-value.d.ts +28 -0
- package/dist/core/format/src/shared/key-in-value.js +82 -0
- package/dist/core/format/src/shared/legacy-keys.d.ts +8 -0
- package/dist/core/format/src/shared/legacy-keys.js +17 -0
- package/dist/core/format/src/shared/program-start.d.ts +60 -0
- package/dist/core/format/src/shared/program-start.js +99 -0
- package/dist/core/format/src/shared/relative-path.d.ts +29 -0
- package/dist/core/format/src/shared/relative-path.js +50 -0
- package/dist/core/format/src/shared/secret-name.d.ts +24 -0
- package/dist/core/format/src/shared/secret-name.js +107 -0
- package/dist/core/format/src/source.d.ts +16 -0
- package/dist/core/format/src/source.js +73 -0
- package/dist/core/ports/src/agent-placement-store.d.ts +74 -0
- package/dist/core/ports/src/agent-placement-store.js +27 -0
- package/dist/core/ports/src/blob-store.d.ts +33 -0
- package/dist/core/ports/src/blob-store.js +2 -0
- package/dist/core/ports/src/cant-try-error.d.ts +35 -0
- package/dist/core/ports/src/cant-try-error.js +44 -0
- package/dist/core/ports/src/chat.d.ts +127 -0
- package/dist/core/ports/src/chat.js +1 -0
- package/dist/core/ports/src/clock.d.ts +7 -0
- package/dist/core/ports/src/clock.js +2 -0
- package/dist/core/ports/src/connection-settings-store.d.ts +57 -0
- package/dist/core/ports/src/connection-settings-store.js +2 -0
- package/dist/core/ports/src/connector-client.d.ts +259 -0
- package/dist/core/ports/src/connector-client.js +2 -0
- package/dist/core/ports/src/coordination.d.ts +84 -0
- package/dist/core/ports/src/coordination.js +2 -0
- package/dist/core/ports/src/definition-store.d.ts +208 -0
- package/dist/core/ports/src/definition-store.js +122 -0
- package/dist/core/ports/src/digest.d.ts +14 -0
- package/dist/core/ports/src/digest.js +2 -0
- package/dist/core/ports/src/folder-reader.d.ts +89 -0
- package/dist/core/ports/src/folder-reader.js +2 -0
- package/dist/core/ports/src/harness-bridge-server.d.ts +189 -0
- package/dist/core/ports/src/harness-bridge-server.js +37 -0
- package/dist/core/ports/src/harness.d.ts +250 -0
- package/dist/core/ports/src/harness.js +45 -0
- package/dist/core/ports/src/http-client.d.ts +27 -0
- package/dist/core/ports/src/http-client.js +2 -0
- package/dist/core/ports/src/id-generator.d.ts +14 -0
- package/dist/core/ports/src/id-generator.js +2 -0
- package/dist/core/ports/src/index.d.ts +37 -0
- package/dist/core/ports/src/index.js +36 -0
- package/dist/core/ports/src/integration.d.ts +178 -0
- package/dist/core/ports/src/integration.js +13 -0
- package/dist/core/ports/src/knowledge-provider.d.ts +65 -0
- package/dist/core/ports/src/knowledge-provider.js +2 -0
- package/dist/core/ports/src/llm-cache.d.ts +13 -0
- package/dist/core/ports/src/llm-cache.js +2 -0
- package/dist/core/ports/src/llm-provider.d.ts +184 -0
- package/dist/core/ports/src/llm-provider.js +136 -0
- package/dist/core/ports/src/model-price.d.ts +34 -0
- package/dist/core/ports/src/model-price.js +25 -0
- package/dist/core/ports/src/password-hasher.d.ts +47 -0
- package/dist/core/ports/src/password-hasher.js +2 -0
- package/dist/core/ports/src/plugin-folder-writer.d.ts +104 -0
- package/dist/core/ports/src/plugin-folder-writer.js +95 -0
- package/dist/core/ports/src/port-versions.d.ts +44 -0
- package/dist/core/ports/src/port-versions.js +74 -0
- package/dist/core/ports/src/program-probe.d.ts +46 -0
- package/dist/core/ports/src/program-probe.js +2 -0
- package/dist/core/ports/src/record-store.d.ts +62 -0
- package/dist/core/ports/src/record-store.js +38 -0
- package/dist/core/ports/src/resource-probe.d.ts +59 -0
- package/dist/core/ports/src/resource-probe.js +2 -0
- package/dist/core/ports/src/run-executor.d.ts +302 -0
- package/dist/core/ports/src/run-executor.js +2 -0
- package/dist/core/ports/src/run-failure-error.d.ts +49 -0
- package/dist/core/ports/src/run-failure-error.js +47 -0
- package/dist/core/ports/src/run-store.d.ts +194 -0
- package/dist/core/ports/src/run-store.js +131 -0
- package/dist/core/ports/src/sandbox.d.ts +247 -0
- package/dist/core/ports/src/sandbox.js +34 -0
- package/dist/core/ports/src/scheduler.d.ts +85 -0
- package/dist/core/ports/src/scheduler.js +2 -0
- package/dist/core/ports/src/secrets.d.ts +128 -0
- package/dist/core/ports/src/secrets.js +144 -0
- package/dist/core/ports/src/token-store.d.ts +19 -0
- package/dist/core/ports/src/token-store.js +2 -0
- package/dist/core/ports/src/tool-approval-store.d.ts +211 -0
- package/dist/core/ports/src/tool-approval-store.js +57 -0
- package/dist/core/ports/src/trust-store.d.ts +72 -0
- package/dist/core/ports/src/trust-store.js +2 -0
- package/dist/core/ports/src/unfenced-run-consent-store.d.ts +43 -0
- package/dist/core/ports/src/unfenced-run-consent-store.js +2 -0
- package/dist/core/ports/src/vcs.d.ts +394 -0
- package/dist/core/ports/src/vcs.js +48 -0
- package/dist/core/schema-kit/src/builders.d.ts +50 -0
- package/dist/core/schema-kit/src/builders.js +72 -0
- package/dist/core/schema-kit/src/depth.d.ts +15 -0
- package/dist/core/schema-kit/src/depth.js +37 -0
- package/dist/core/schema-kit/src/index.d.ts +6 -0
- package/dist/core/schema-kit/src/index.js +6 -0
- package/dist/core/schema-kit/src/issue.d.ts +22 -0
- package/dist/core/schema-kit/src/issue.js +23 -0
- package/dist/core/schema-kit/src/json-schema.d.ts +23 -0
- package/dist/core/schema-kit/src/json-schema.js +22 -0
- package/dist/core/schema-kit/src/parse.d.ts +17 -0
- package/dist/core/schema-kit/src/parse.js +25 -0
- package/dist/core/schema-kit/src/schema.d.ts +12 -0
- package/dist/core/schema-kit/src/schema.js +1 -0
- package/dist/core/std/src/ascii-host.d.ts +18 -0
- package/dist/core/std/src/ascii-host.js +110 -0
- package/dist/core/std/src/assert.d.ts +39 -0
- package/dist/core/std/src/assert.js +59 -0
- package/dist/core/std/src/base64url.d.ts +23 -0
- package/dist/core/std/src/base64url.js +65 -0
- package/dist/core/std/src/canonical-json.d.ts +18 -0
- package/dist/core/std/src/canonical-json.js +56 -0
- package/dist/core/std/src/clock.d.ts +27 -0
- package/dist/core/std/src/clock.js +33 -0
- package/dist/core/std/src/constant-time.d.ts +16 -0
- package/dist/core/std/src/constant-time.js +26 -0
- package/dist/core/std/src/content-digest.d.ts +24 -0
- package/dist/core/std/src/content-digest.js +28 -0
- package/dist/core/std/src/deep-clone.d.ts +15 -0
- package/dist/core/std/src/deep-clone.js +59 -0
- package/dist/core/std/src/deep-equal.d.ts +23 -0
- package/dist/core/std/src/deep-equal.js +64 -0
- package/dist/core/std/src/emitter.d.ts +42 -0
- package/dist/core/std/src/emitter.js +74 -0
- package/dist/core/std/src/error-kind.d.ts +88 -0
- package/dist/core/std/src/error-kind.js +98 -0
- package/dist/core/std/src/hex.d.ts +10 -0
- package/dist/core/std/src/hex.js +16 -0
- package/dist/core/std/src/ids.d.ts +45 -0
- package/dist/core/std/src/ids.js +49 -0
- package/dist/core/std/src/index.d.ts +25 -0
- package/dist/core/std/src/index.js +26 -0
- package/dist/core/std/src/keyed-queue.d.ts +18 -0
- package/dist/core/std/src/keyed-queue.js +32 -0
- package/dist/core/std/src/line-diff.d.ts +83 -0
- package/dist/core/std/src/line-diff.js +179 -0
- package/dist/core/std/src/line-merge.d.ts +63 -0
- package/dist/core/std/src/line-merge.js +138 -0
- package/dist/core/std/src/plain-data.d.ts +32 -0
- package/dist/core/std/src/plain-data.js +57 -0
- package/dist/core/std/src/posix-path.d.ts +61 -0
- package/dist/core/std/src/posix-path.js +121 -0
- package/dist/core/std/src/result.d.ts +55 -0
- package/dist/core/std/src/result.js +52 -0
- package/dist/core/std/src/secret-scrubber.d.ts +54 -0
- package/dist/core/std/src/secret-scrubber.js +124 -0
- package/dist/core/std/src/secret-shape.d.ts +20 -0
- package/dist/core/std/src/secret-shape.js +53 -0
- package/dist/core/std/src/stop-signal.d.ts +44 -0
- package/dist/core/std/src/stop-signal.js +77 -0
- package/dist/core/std/src/text.d.ts +28 -0
- package/dist/core/std/src/text.js +54 -0
- package/dist/core/std/src/utf8.d.ts +23 -0
- package/dist/core/std/src/utf8.js +110 -0
- package/dist/core/std/src/version.d.ts +48 -0
- package/dist/core/std/src/version.js +103 -0
- package/dist/core/yaml/src/depth.d.ts +14 -0
- package/dist/core/yaml/src/depth.js +140 -0
- package/dist/core/yaml/src/edit-data.d.ts +47 -0
- package/dist/core/yaml/src/edit-data.js +286 -0
- package/dist/core/yaml/src/edit-text.d.ts +92 -0
- package/dist/core/yaml/src/edit-text.js +267 -0
- package/dist/core/yaml/src/edit.d.ts +47 -0
- package/dist/core/yaml/src/edit.js +198 -0
- package/dist/core/yaml/src/index.d.ts +5 -0
- package/dist/core/yaml/src/index.js +4 -0
- package/dist/core/yaml/src/problem.d.ts +20 -0
- package/dist/core/yaml/src/problem.js +1 -0
- package/dist/core/yaml/src/read.d.ts +47 -0
- package/dist/core/yaml/src/read.js +130 -0
- package/dist/core/yaml/src/splice-node.d.ts +47 -0
- package/dist/core/yaml/src/splice-node.js +333 -0
- package/dist/core/yaml/src/splice.d.ts +13 -0
- package/dist/core/yaml/src/splice.js +174 -0
- package/dist/core/yaml/src/unsupported.d.ts +26 -0
- package/dist/core/yaml/src/unsupported.js +70 -0
- package/dist/core/yaml/src/write.d.ts +35 -0
- package/dist/core/yaml/src/write.js +44 -0
- package/dist/testing/integration/src/canaries.d.ts +14 -0
- package/dist/testing/integration/src/canaries.js +17 -0
- package/dist/testing/integration/src/checks.d.ts +37 -0
- package/dist/testing/integration/src/checks.js +195 -0
- package/dist/testing/integration/src/describe.d.ts +35 -0
- package/dist/testing/integration/src/describe.js +74 -0
- package/dist/testing/integration/src/failure.d.ts +6 -0
- package/dist/testing/integration/src/failure.js +8 -0
- package/dist/testing/integration/src/fake-wait.d.ts +18 -0
- package/dist/testing/integration/src/fake-wait.js +21 -0
- package/dist/testing/integration/src/index.d.ts +10 -0
- package/dist/testing/integration/src/index.js +11 -0
- package/dist/testing/integration/src/load.d.ts +14 -0
- package/dist/testing/integration/src/load.js +45 -0
- package/dist/testing/integration/src/plugin-folder.d.ts +23 -0
- package/dist/testing/integration/src/plugin-folder.js +59 -0
- package/dist/testing/integration/src/plugin.d.ts +32 -0
- package/dist/testing/integration/src/plugin.js +57 -0
- package/dist/testing/integration/src/recording.d.ts +84 -0
- package/dist/testing/integration/src/recording.js +164 -0
- package/dist/testing/integration/src/run.d.ts +60 -0
- package/dist/testing/integration/src/run.js +81 -0
- package/dist/testing/integration/src/source-scan.d.ts +16 -0
- package/dist/testing/integration/src/source-scan.js +40 -0
- package/package.json +35 -4
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import { classifyAddress, parseIpAddress } from "../../http-kit/src/index.js";
|
|
2
|
+
/**
|
|
3
|
+
* Addresses on the user's own machine or network, for the plain `http` hosts
|
|
4
|
+
* a user may choose in a setting. Only literal addresses and
|
|
5
|
+
* `localhost` count: a name can resolve anywhere. Takes `URL.hostname`, which
|
|
6
|
+
* has already normalised the address. The classes come from `http-kit`, so
|
|
7
|
+
* this check and the Node transport's address check can't disagree.
|
|
8
|
+
*/
|
|
9
|
+
/** `localhost`, `127.0.0.0/8` or `::1`: the user's own machine. */
|
|
10
|
+
export function isLoopback(hostname) {
|
|
11
|
+
const host = hostname.toLowerCase();
|
|
12
|
+
return host === "localhost" || literalClass(host) === "loopback";
|
|
13
|
+
}
|
|
14
|
+
/**
|
|
15
|
+
* Loopback, or a private network address (`10/8`, `172.16/12`,
|
|
16
|
+
* `192.168/16`, IPv6 `fc00::/7`). Link-local and metadata addresses don't
|
|
17
|
+
* count: `169.254.169.254` is where cloud machines serve their credentials.
|
|
18
|
+
*/
|
|
19
|
+
export function isLocalAddress(hostname) {
|
|
20
|
+
return isLoopback(hostname) || literalClass(hostname.toLowerCase()) === "private";
|
|
21
|
+
}
|
|
22
|
+
/** The class of an IP address literal; undefined for a name. */
|
|
23
|
+
function literalClass(host) {
|
|
24
|
+
return parseIpAddress(host) === undefined ? undefined : classifyAddress(host);
|
|
25
|
+
}
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import type { IntegrationRequestInit, SecretPlacement } 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 SecretPlacement[];
|
|
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 "./secret-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` other than
|
|
6
|
+
* this Halonic's `integrationVersion`, and, when the backend's code is
|
|
7
|
+
* given, 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` other than
|
|
10
|
+
* this Halonic's `integrationVersion`, and, when the backend's code is
|
|
11
|
+
* given, 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}: built against SDK ${plugin.sdk}, but 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,55 @@
|
|
|
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
|
+
/** The token names it may read and write. */
|
|
27
|
+
readonly tokens: readonly string[];
|
|
28
|
+
}
|
|
29
|
+
/** One secret in the permission sheet. */
|
|
30
|
+
export interface DeclaredSecret {
|
|
31
|
+
readonly hosts: readonly string[];
|
|
32
|
+
readonly optional?: boolean;
|
|
33
|
+
/** The only way the kit may place it; any other placement is refused. */
|
|
34
|
+
readonly placement: DeclaredPlacement;
|
|
35
|
+
}
|
|
36
|
+
/** Where the sheet puts a secret: a `SecretPlacement` without the secret's name. */
|
|
37
|
+
export type DeclaredPlacement = {
|
|
38
|
+
readonly as: "bearer";
|
|
39
|
+
} | {
|
|
40
|
+
readonly as: "header";
|
|
41
|
+
readonly header: string;
|
|
42
|
+
readonly prefix?: string;
|
|
43
|
+
} | {
|
|
44
|
+
readonly as: "form";
|
|
45
|
+
readonly field: string;
|
|
46
|
+
};
|
|
47
|
+
/** Lower-case words joined by `-`: integration, secret-reference and token names. */
|
|
48
|
+
export declare const namePattern: RegExp;
|
|
49
|
+
/**
|
|
50
|
+
* Parses a URL the integration asked for, refusing anything but an allowed
|
|
51
|
+
* `https` host or an allowed local `http` host.
|
|
52
|
+
*/
|
|
53
|
+
export declare function allowedUrl(policy: IntegrationPolicy, raw: unknown, base?: URL): URL;
|
|
54
|
+
/** Whether the URL's host is in the list, by exact match ignoring case. */
|
|
55
|
+
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,23 @@
|
|
|
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
|
+
/** The secrets of this request, removed from the status text, the headers, the URL, the body and its errors. */
|
|
14
|
+
readonly secrets: SecretForms;
|
|
15
|
+
}
|
|
16
|
+
/**
|
|
17
|
+
* Passes the body through with the request's secrets removed, failing it when it grows over the size limit, when no data comes
|
|
18
|
+
* for the idle time while the integration is waiting, or when the request
|
|
19
|
+
* is aborted. Time the integration spends between reads doesn't count.
|
|
20
|
+
*/
|
|
21
|
+
export declare function guardBody(policy: IntegrationPolicy, response: Response, url: URL, guard: BodyGuard): Response;
|
|
22
|
+
/** Settles like the promise, or rejects as soon as the signal aborts, whatever the transport does. */
|
|
23
|
+
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
|
+
}
|