@apifuse/provider-sdk 2.2.0-beta.7 → 2.2.0-beta.70
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/AUTHORING.md +943 -51
- package/CHANGELOG.md +273 -1
- package/LICENSE +21 -0
- package/README.md +117 -29
- package/SUBMISSION.md +3 -2
- package/bin/apifuse-check.ts +293 -13
- package/bin/apifuse-dev.ts +42 -19
- package/bin/apifuse-migrate-deployment.ts +200 -0
- package/bin/apifuse-migrate-operation-declaration.ts +55 -0
- package/bin/apifuse-migrate-shape.ts +202 -0
- package/bin/apifuse-pack-check.ts +19 -6
- package/bin/apifuse-pack-smoke.ts +57 -2
- package/bin/apifuse-pack-types.ts +736 -38
- package/bin/apifuse-perf.ts +59 -23
- package/bin/apifuse-record.ts +923 -94
- package/bin/apifuse-submit-check.ts +2313 -281
- package/bin/apifuse-test.ts +3 -1
- package/bin/submit-check-delimited-text.ts +50 -0
- package/dist/auth-turn/index.d.ts +3 -3
- package/dist/auth-turn/index.js +1 -1
- package/dist/auth.d.ts +14 -0
- package/dist/auth.js +67 -0
- package/dist/ceremonies/index.d.ts +16 -0
- package/dist/ceremonies/index.js +141 -36
- package/dist/cli/commands.d.ts +1 -1
- package/dist/cli/commands.js +30 -0
- package/dist/cli/create.d.ts +1 -1
- package/dist/cli/create.js +8 -2
- package/dist/cli/deployment-intent.d.ts +178 -0
- package/dist/cli/deployment-intent.js +277 -0
- package/dist/cli/local-connection.d.ts +111 -0
- package/dist/cli/local-connection.js +151 -0
- package/dist/cli/migrate-deployment-intent.d.ts +132 -0
- package/dist/cli/migrate-deployment-intent.js +1552 -0
- package/dist/cli/migrate-operation-declaration.d.ts +70 -0
- package/dist/cli/migrate-operation-declaration.js +2206 -0
- package/dist/cli/migrate-operation-shape.d.ts +44 -0
- package/dist/cli/migrate-operation-shape.js +113 -0
- package/dist/cli/migrate-provider-shape.d.ts +56 -0
- package/dist/cli/migrate-provider-shape.js +580 -0
- package/dist/cli/resolver-runtime.d.ts +21 -0
- package/dist/cli/resolver-runtime.js +31 -0
- package/dist/cli/templates/provider/.agents/skills/health-checks-and-fail-closed/SKILL.md.tpl +141 -23
- package/dist/cli/templates/provider/Dockerfile.tpl +1 -1
- package/dist/cli/templates/provider/README.md.tpl +41 -19
- package/dist/cli/templates/provider/index.ts.tpl +6 -3
- package/dist/cli/templates/provider/operations/ping.ts.tpl +4 -1
- package/dist/cli/templates/provider/provider.json.tpl +6 -0
- package/dist/config/loader.d.ts +202 -16
- package/dist/config/loader.js +491 -141
- package/dist/contract-serialization.js +4 -8
- package/dist/contract-types.d.ts +12 -5
- package/dist/contract.js +24 -10
- package/dist/declaration-validation.d.ts +34 -0
- package/dist/declaration-validation.js +305 -0
- package/dist/define.d.ts +71 -29
- package/dist/define.js +807 -69
- package/dist/dev.d.ts +5 -0
- package/dist/dev.js +8 -1
- package/dist/engine.d.ts +129 -0
- package/dist/engine.js +209 -0
- package/dist/error-observability.d.ts +7 -0
- package/dist/error-observability.js +61 -0
- package/dist/error-resolution.d.ts +18 -0
- package/dist/error-resolution.js +243 -0
- package/dist/errors.d.ts +74 -0
- package/dist/errors.js +99 -0
- package/dist/fixture-sanitization.d.ts +28 -0
- package/dist/fixture-sanitization.js +371 -0
- package/dist/handle-meta.d.ts +90 -0
- package/dist/handle-meta.js +73 -0
- package/dist/handle.d.ts +226 -0
- package/dist/handle.js +345 -0
- package/dist/health-scenario.d.ts +1901 -0
- package/dist/health-scenario.js +653 -0
- package/dist/i18n/catalog.js +21 -1
- package/dist/i18n/error-messages.d.ts +86 -0
- package/dist/i18n/error-messages.js +192 -0
- package/dist/i18n/index.d.ts +1 -0
- package/dist/i18n/index.js +1 -0
- package/dist/i18n/keys.d.ts +12 -0
- package/dist/i18n/keys.js +76 -5
- package/dist/i18n/operation-locale-namespace.d.ts +2 -0
- package/dist/i18n/operation-locale-namespace.js +7 -0
- package/dist/index.d.ts +40 -15
- package/dist/index.js +29 -11
- package/dist/lint.d.ts +43 -11
- package/dist/lint.js +2512 -177
- package/dist/native-address.d.ts +43 -0
- package/dist/native-address.js +281 -0
- package/dist/native-egress-policy.d.ts +31 -0
- package/dist/native-egress-policy.js +288 -0
- package/dist/observability.d.ts +5 -2
- package/dist/observability.js +48 -1
- package/dist/provider.d.ts +18 -8
- package/dist/provider.js +11 -6
- package/dist/runtime/auth-flow.d.ts +6 -1
- package/dist/runtime/auth-flow.js +8 -0
- package/dist/runtime/bounded-expiring-map.d.ts +21 -0
- package/dist/runtime/bounded-expiring-map.js +64 -0
- package/dist/runtime/browser-telemetry-binding.d.ts +5 -0
- package/dist/runtime/browser-telemetry-binding.js +83 -0
- package/dist/runtime/browser-telemetry.d.ts +76 -0
- package/dist/runtime/browser-telemetry.js +165 -0
- package/dist/runtime/browser.d.ts +4 -0
- package/dist/runtime/browser.js +688 -83
- package/dist/runtime/cache-telemetry.d.ts +71 -0
- package/dist/runtime/cache-telemetry.js +177 -0
- package/dist/runtime/cache.d.ts +3 -0
- package/dist/runtime/cache.js +245 -23
- package/dist/runtime/capability-response.d.ts +3 -0
- package/dist/runtime/capability-response.js +56 -0
- package/dist/runtime/capability-telemetry.d.ts +46 -0
- package/dist/runtime/capability-telemetry.js +68 -0
- package/dist/runtime/chrome149-header-order.d.ts +58 -0
- package/dist/runtime/chrome149-header-order.js +289 -0
- package/dist/runtime/diagnostic-env-values.d.ts +5 -0
- package/dist/runtime/diagnostic-env-values.js +57 -0
- package/dist/runtime/diagnostic-env.d.ts +14 -0
- package/dist/runtime/diagnostic-env.js +44 -0
- package/dist/runtime/diagnostic-redactor.d.ts +54 -0
- package/dist/runtime/diagnostic-redactor.js +571 -0
- package/dist/runtime/egress-lease.d.ts +65 -0
- package/dist/runtime/egress-lease.js +236 -0
- package/dist/runtime/engine-mode.d.ts +74 -0
- package/dist/runtime/engine-mode.js +152 -0
- package/dist/runtime/env.js +14 -1
- package/dist/runtime/executor.d.ts +3 -2
- package/dist/runtime/executor.js +23 -26
- package/dist/runtime/handle-wordlist.d.ts +43 -0
- package/dist/runtime/handle-wordlist.js +256 -0
- package/dist/runtime/handle.d.ts +71 -0
- package/dist/runtime/handle.js +908 -0
- package/dist/runtime/http-telemetry-binding.d.ts +10 -0
- package/dist/runtime/http-telemetry-binding.js +152 -0
- package/dist/runtime/http-telemetry-guard.d.ts +16 -0
- package/dist/runtime/http-telemetry-guard.js +202 -0
- package/dist/runtime/http-telemetry.d.ts +104 -0
- package/dist/runtime/http-telemetry.js +190 -0
- package/dist/runtime/http.d.ts +34 -0
- package/dist/runtime/http.js +680 -121
- package/dist/runtime/insights.js +2 -2
- package/dist/runtime/instrumentation.d.ts +2 -2
- package/dist/runtime/instrumentation.js +462 -19
- package/dist/runtime/native-network-errors.d.ts +33 -0
- package/dist/runtime/native-network-errors.js +69 -0
- package/dist/runtime/native-network.d.ts +105 -0
- package/dist/runtime/native-network.js +1433 -0
- package/dist/runtime/native-telemetry.d.ts +142 -0
- package/dist/runtime/native-telemetry.js +231 -0
- package/dist/runtime/ocr-telemetry.d.ts +82 -0
- package/dist/runtime/ocr-telemetry.js +192 -0
- package/dist/runtime/ocr.d.ts +29 -0
- package/dist/runtime/ocr.js +468 -0
- package/dist/runtime/otlp.d.ts +71 -2
- package/dist/runtime/otlp.js +398 -16
- package/dist/runtime/provider.d.ts +7 -0
- package/dist/runtime/provider.js +14 -0
- package/dist/runtime/proxy-errors.js +6 -2
- package/dist/runtime/proxy-nodemaven.d.ts +56 -0
- package/dist/runtime/proxy-nodemaven.js +147 -0
- package/dist/runtime/proxy-retry-policy.d.ts +4 -1
- package/dist/runtime/proxy-retry-policy.js +11 -2
- package/dist/runtime/proxy-telemetry.d.ts +133 -3
- package/dist/runtime/proxy-telemetry.js +218 -70
- package/dist/runtime/redirect-hop-headers.d.ts +19 -0
- package/dist/runtime/redirect-hop-headers.js +58 -0
- package/dist/runtime/redirects.d.ts +61 -0
- package/dist/runtime/redirects.js +149 -0
- package/dist/runtime/redis.d.ts +1 -1
- package/dist/runtime/redis.js +4 -2
- package/dist/runtime/request-options.d.ts +75 -1
- package/dist/runtime/request-options.js +588 -0
- package/dist/runtime/request-telemetry.d.ts +70 -0
- package/dist/runtime/request-telemetry.js +229 -0
- package/dist/runtime/resolver-config.d.ts +13 -0
- package/dist/runtime/resolver-config.js +14 -0
- package/dist/runtime/resolver-public.d.ts +3 -0
- package/dist/runtime/resolver-public.js +1 -0
- package/dist/runtime/resolver-runtime-options.d.ts +14 -0
- package/dist/runtime/resolver-runtime-options.js +33 -0
- package/dist/runtime/resolver-shared.d.ts +24 -0
- package/dist/runtime/resolver-shared.js +69 -0
- package/dist/runtime/resolver-span-attributes.d.ts +34 -0
- package/dist/runtime/resolver-span-attributes.js +93 -0
- package/dist/runtime/resolver-telemetry.d.ts +135 -0
- package/dist/runtime/resolver-telemetry.js +204 -0
- package/dist/runtime/resolver-usage.d.ts +32 -0
- package/dist/runtime/resolver-usage.js +54 -0
- package/dist/runtime/resolver-vendors/bindings.d.ts +53 -0
- package/dist/runtime/resolver-vendors/bindings.js +45 -0
- package/dist/runtime/resolver-vendors/browser.d.ts +24 -0
- package/dist/runtime/resolver-vendors/browser.js +423 -0
- package/dist/runtime/resolver-vendors/capsolver.d.ts +22 -0
- package/dist/runtime/resolver-vendors/capsolver.js +544 -0
- package/dist/runtime/resolver-vendors/hosts.d.ts +23 -0
- package/dist/runtime/resolver-vendors/hosts.js +68 -0
- package/dist/runtime/resolver-vendors/hypersolutions.d.ts +27 -0
- package/dist/runtime/resolver-vendors/hypersolutions.js +369 -0
- package/dist/runtime/resolver-vendors/twocaptcha.d.ts +24 -0
- package/dist/runtime/resolver-vendors/twocaptcha.js +425 -0
- package/dist/runtime/resolver-vendors/types.d.ts +125 -0
- package/dist/runtime/resolver-vendors/types.js +106 -0
- package/dist/runtime/resolver.d.ts +79 -0
- package/dist/runtime/resolver.js +1094 -0
- package/dist/runtime/state-telemetry.d.ts +79 -0
- package/dist/runtime/state-telemetry.js +194 -0
- package/dist/runtime/state.d.ts +10 -1
- package/dist/runtime/state.js +322 -82
- package/dist/runtime/stealth-akamai-sbsd.d.ts +54 -0
- package/dist/runtime/stealth-akamai-sbsd.js +142 -0
- package/dist/runtime/stealth-cookies.d.ts +24 -0
- package/dist/runtime/stealth-cookies.js +131 -0
- package/dist/runtime/stealth-owned-headers.d.ts +39 -0
- package/dist/runtime/stealth-owned-headers.js +57 -0
- package/dist/runtime/stealth-telemetry.d.ts +92 -0
- package/dist/runtime/stealth-telemetry.js +179 -0
- package/dist/runtime/stealth.d.ts +45 -6
- package/dist/runtime/stealth.js +1775 -320
- package/dist/runtime/stt-telemetry.d.ts +77 -0
- package/dist/runtime/stt-telemetry.js +176 -0
- package/dist/runtime/stt.js +18 -19
- package/dist/runtime/timeout.d.ts +5 -0
- package/dist/runtime/timeout.js +12 -0
- package/dist/runtime/trace-config.d.ts +12 -0
- package/dist/runtime/trace-config.js +62 -0
- package/dist/runtime/trace.d.ts +17 -0
- package/dist/runtime/trace.js +176 -25
- package/dist/runtime-boundary-lint.d.ts +137 -0
- package/dist/runtime-boundary-lint.js +590 -0
- package/dist/schema.d.ts +20 -0
- package/dist/schema.js +72 -2
- package/dist/serve.d.ts +1 -1
- package/dist/serve.js +1 -1
- package/dist/server/error-observability.d.ts +1 -0
- package/dist/server/error-observability.js +1 -0
- package/dist/server/error-stack-frames.d.ts +35 -0
- package/dist/server/error-stack-frames.js +219 -0
- package/dist/server/index.d.ts +21 -2
- package/dist/server/index.js +11 -2
- package/dist/server/runtime-diagnostics.d.ts +165 -0
- package/dist/server/runtime-diagnostics.js +360 -0
- package/dist/server/sdk-version.d.ts +3 -0
- package/dist/server/sdk-version.js +19 -0
- package/dist/server/self-test-input-tokens.d.ts +2 -1
- package/dist/server/self-test-input-tokens.js +18 -14
- package/dist/server/self-test-redaction.js +8 -33
- package/dist/server/self-test.d.ts +18 -3
- package/dist/server/self-test.js +139 -76
- package/dist/server/sensitive-values.d.ts +26 -0
- package/dist/server/sensitive-values.js +137 -0
- package/dist/server/serve-implementation.d.ts +285 -0
- package/dist/server/serve-implementation.js +3172 -0
- package/dist/server/serve.d.ts +1 -75
- package/dist/server/serve.js +1 -1170
- package/dist/server/state-backend-report.d.ts +70 -0
- package/dist/server/state-backend-report.js +113 -0
- package/dist/server/trace-output.d.ts +7 -0
- package/dist/server/trace-output.js +111 -0
- package/dist/server/types.d.ts +37 -5
- package/dist/server/types.js +34 -1
- package/dist/stateful/errors.d.ts +19 -0
- package/dist/stateful/errors.js +24 -0
- package/dist/stateful/http-provider-event-emitter.d.ts +40 -0
- package/dist/stateful/http-provider-event-emitter.js +237 -0
- package/dist/stateful/http-session-owner-registry.d.ts +44 -0
- package/dist/stateful/http-session-owner-registry.js +210 -0
- package/dist/stateful/index.d.ts +18 -0
- package/dist/stateful/index.js +18 -0
- package/dist/stateful/provider-event-delivery-failures.d.ts +32 -0
- package/dist/stateful/provider-event-delivery-failures.js +43 -0
- package/dist/stateful/provider-event-pipeline-metrics.d.ts +46 -0
- package/dist/stateful/provider-event-pipeline-metrics.js +48 -0
- package/dist/stateful/provider-event-pipeline.d.ts +50 -0
- package/dist/stateful/provider-event-pipeline.js +1 -0
- package/dist/stateful/provider-events.d.ts +101 -0
- package/dist/stateful/provider-events.js +289 -0
- package/dist/stateful/session-key.d.ts +15 -0
- package/dist/stateful/session-key.js +86 -0
- package/dist/stateful/stateful-provider-adapter-context.d.ts +5 -0
- package/dist/stateful/stateful-provider-adapter-context.js +42 -0
- package/dist/stateful/stateful-provider-adapter-metrics.d.ts +15 -0
- package/dist/stateful/stateful-provider-adapter-metrics.js +21 -0
- package/dist/stateful/stateful-provider-adapter.d.ts +98 -0
- package/dist/stateful/stateful-provider-adapter.js +287 -0
- package/dist/stateful/stateful-provider-observability.d.ts +62 -0
- package/dist/stateful/stateful-provider-observability.js +161 -0
- package/dist/stateful/stateful-provider-owner-forwarder.d.ts +41 -0
- package/dist/stateful/stateful-provider-owner-forwarder.js +237 -0
- package/dist/stateful/stateful-provider-runtime-context.d.ts +35 -0
- package/dist/stateful/stateful-provider-runtime-context.js +61 -0
- package/dist/stateful/stateful-provider-runtime-executor.d.ts +34 -0
- package/dist/stateful/stateful-provider-runtime-executor.js +52 -0
- package/dist/stateful/stateful-provider-session-routing.d.ts +67 -0
- package/dist/stateful/stateful-provider-session-routing.js +345 -0
- package/dist/stateful/stateful-provider-session-runtime.d.ts +98 -0
- package/dist/stateful/stateful-provider-session-runtime.js +245 -0
- package/dist/stateful-signing.d.ts +18 -0
- package/dist/stateful-signing.js +27 -0
- package/dist/stealth/profiles.d.ts +15 -4
- package/dist/stealth/profiles.js +169 -211
- package/dist/stream-evidence.d.ts +74 -0
- package/dist/stream-evidence.js +785 -0
- package/dist/stream.js +7 -1
- package/dist/testing/index.d.ts +2 -1
- package/dist/testing/index.js +2 -1
- package/dist/testing/run.d.ts +32 -2
- package/dist/testing/run.js +509 -25
- package/dist/trace-sanitization.d.ts +6 -0
- package/dist/trace-sanitization.js +68 -0
- package/dist/types.d.ts +899 -210
- package/dist/types.js +1 -0
- package/dist/typescript-module.d.ts +39 -0
- package/dist/typescript-module.js +72 -0
- package/package.json +52 -6
- package/src/auth-turn/index.ts +1 -1
- package/src/auth.ts +118 -0
- package/src/ceremonies/index.ts +189 -46
- package/src/cli/commands.ts +37 -0
- package/src/cli/create.ts +8 -2
- package/src/cli/deployment-intent.ts +364 -0
- package/src/cli/local-connection.ts +221 -0
- package/src/cli/migrate-deployment-intent.ts +1908 -0
- package/src/cli/migrate-operation-declaration.ts +3026 -0
- package/src/cli/migrate-operation-shape.ts +184 -0
- package/src/cli/migrate-provider-shape.ts +778 -0
- package/src/cli/resolver-runtime.ts +72 -0
- package/src/cli/templates/provider/.agents/skills/health-checks-and-fail-closed/SKILL.md.tpl +141 -23
- package/src/cli/templates/provider/Dockerfile.tpl +1 -1
- package/src/cli/templates/provider/README.md.tpl +41 -19
- package/src/cli/templates/provider/index.ts.tpl +6 -3
- package/src/cli/templates/provider/operations/ping.ts.tpl +4 -1
- package/src/cli/templates/provider/provider.json.tpl +6 -0
- package/src/config/loader.ts +774 -181
- package/src/contract-serialization.ts +5 -7
- package/src/contract-types.ts +12 -5
- package/src/contract.ts +24 -10
- package/src/declaration-validation.ts +376 -0
- package/src/define.ts +1105 -131
- package/src/dev.ts +13 -1
- package/src/engine.ts +390 -0
- package/src/error-observability.ts +64 -0
- package/src/error-resolution.ts +269 -0
- package/src/errors.ts +157 -0
- package/src/fixture-sanitization.ts +422 -0
- package/src/handle-meta.ts +143 -0
- package/src/handle.ts +694 -0
- package/src/health-scenario.ts +960 -0
- package/src/i18n/catalog.ts +23 -1
- package/src/i18n/error-messages.ts +255 -0
- package/src/i18n/index.ts +1 -0
- package/src/i18n/keys.ts +80 -6
- package/src/i18n/operation-locale-namespace.ts +10 -0
- package/src/index.ts +390 -23
- package/src/lint.ts +2975 -234
- package/src/native-address.ts +340 -0
- package/src/native-egress-policy.ts +358 -0
- package/src/observability.ts +51 -1
- package/src/provider.ts +207 -27
- package/src/runtime/auth-flow.ts +15 -0
- package/src/runtime/bounded-expiring-map.ts +67 -0
- package/src/runtime/browser-telemetry-binding.ts +92 -0
- package/src/runtime/browser-telemetry.ts +289 -0
- package/src/runtime/browser.ts +882 -99
- package/src/runtime/cache-telemetry.ts +247 -0
- package/src/runtime/cache.ts +258 -22
- package/src/runtime/capability-response.ts +53 -0
- package/src/runtime/capability-telemetry.ts +101 -0
- package/src/runtime/chrome149-header-order.ts +330 -0
- package/src/runtime/diagnostic-env-values.ts +56 -0
- package/src/runtime/diagnostic-env.ts +65 -0
- package/src/runtime/diagnostic-redactor.ts +668 -0
- package/src/runtime/egress-lease.ts +341 -0
- package/src/runtime/engine-mode.ts +233 -0
- package/src/runtime/env.ts +15 -1
- package/src/runtime/executor.ts +39 -32
- package/src/runtime/handle-wordlist.ts +266 -0
- package/src/runtime/handle.ts +1180 -0
- package/src/runtime/http-telemetry-binding.ts +162 -0
- package/src/runtime/http-telemetry-guard.ts +208 -0
- package/src/runtime/http-telemetry.ts +292 -0
- package/src/runtime/http.ts +896 -150
- package/src/runtime/insights.ts +2 -2
- package/src/runtime/instrumentation.ts +628 -28
- package/src/runtime/native-network-errors.ts +99 -0
- package/src/runtime/native-network.ts +1853 -0
- package/src/runtime/native-telemetry.ts +366 -0
- package/src/runtime/ocr-telemetry.ts +308 -0
- package/src/runtime/ocr.ts +564 -0
- package/src/runtime/otlp.ts +468 -21
- package/src/runtime/provider.ts +15 -0
- package/src/runtime/proxy-errors.ts +12 -4
- package/src/runtime/proxy-nodemaven.ts +222 -0
- package/src/runtime/proxy-retry-policy.ts +12 -1
- package/src/runtime/proxy-telemetry.ts +358 -103
- package/src/runtime/redirect-hop-headers.ts +71 -0
- package/src/runtime/redirects.ts +215 -0
- package/src/runtime/redis.ts +7 -2
- package/src/runtime/request-options.ts +728 -1
- package/src/runtime/request-telemetry.ts +375 -0
- package/src/runtime/resolver-config.ts +18 -0
- package/src/runtime/resolver-public.ts +44 -0
- package/src/runtime/resolver-runtime-options.ts +50 -0
- package/src/runtime/resolver-shared.ts +113 -0
- package/src/runtime/resolver-span-attributes.ts +139 -0
- package/src/runtime/resolver-telemetry.ts +362 -0
- package/src/runtime/resolver-usage.ts +99 -0
- package/src/runtime/resolver-vendors/bindings.ts +61 -0
- package/src/runtime/resolver-vendors/browser.ts +591 -0
- package/src/runtime/resolver-vendors/capsolver.ts +727 -0
- package/src/runtime/resolver-vendors/hosts.ts +81 -0
- package/src/runtime/resolver-vendors/hypersolutions.ts +480 -0
- package/src/runtime/resolver-vendors/twocaptcha.ts +555 -0
- package/src/runtime/resolver-vendors/types.ts +261 -0
- package/src/runtime/resolver.ts +1543 -0
- package/src/runtime/state-telemetry.ts +298 -0
- package/src/runtime/state.ts +435 -89
- package/src/runtime/stealth-akamai-sbsd.ts +207 -0
- package/src/runtime/stealth-cookies.ts +155 -0
- package/src/runtime/stealth-owned-headers.ts +67 -0
- package/src/runtime/stealth-telemetry.ts +309 -0
- package/src/runtime/stealth.ts +2275 -372
- package/src/runtime/stt-telemetry.ts +282 -0
- package/src/runtime/stt.ts +96 -91
- package/src/runtime/timeout.ts +18 -0
- package/src/runtime/trace-config.ts +78 -0
- package/src/runtime/trace.ts +257 -35
- package/src/runtime-boundary-lint.ts +707 -0
- package/src/schema.ts +80 -2
- package/src/serve.ts +6 -1
- package/src/server/error-observability.ts +1 -0
- package/src/server/error-stack-frames.ts +214 -0
- package/src/server/index.ts +184 -2
- package/src/server/runtime-diagnostics.ts +522 -0
- package/src/server/sdk-version.ts +22 -0
- package/src/server/self-test-input-tokens.ts +29 -14
- package/src/server/self-test-redaction.ts +10 -40
- package/src/server/self-test.ts +205 -89
- package/src/server/sensitive-values.ts +211 -0
- package/src/server/serve-implementation.ts +4596 -0
- package/src/server/serve.ts +1 -1685
- package/src/server/state-backend-report.ts +185 -0
- package/src/server/trace-output.ts +189 -0
- package/src/server/types.ts +34 -1
- package/src/stateful/README.md +146 -0
- package/src/stateful/errors.ts +35 -0
- package/src/stateful/http-provider-event-emitter.ts +314 -0
- package/src/stateful/http-session-owner-registry.ts +306 -0
- package/src/stateful/index.ts +18 -0
- package/src/stateful/provider-event-delivery-failures.ts +80 -0
- package/src/stateful/provider-event-pipeline-metrics.ts +95 -0
- package/src/stateful/provider-event-pipeline.ts +61 -0
- package/src/stateful/provider-events.ts +462 -0
- package/src/stateful/session-key.ts +111 -0
- package/src/stateful/stateful-provider-adapter-context.ts +59 -0
- package/src/stateful/stateful-provider-adapter-metrics.ts +48 -0
- package/src/stateful/stateful-provider-adapter.ts +562 -0
- package/src/stateful/stateful-provider-observability.ts +261 -0
- package/src/stateful/stateful-provider-owner-forwarder.ts +310 -0
- package/src/stateful/stateful-provider-runtime-context.ts +96 -0
- package/src/stateful/stateful-provider-runtime-executor.ts +96 -0
- package/src/stateful/stateful-provider-session-routing.ts +546 -0
- package/src/stateful/stateful-provider-session-runtime.ts +403 -0
- package/src/stateful-signing.ts +46 -0
- package/src/stealth/profiles.ts +212 -231
- package/src/stream-evidence.ts +988 -0
- package/src/stream.ts +8 -1
- package/src/testing/index.ts +10 -1
- package/src/testing/run.ts +685 -19
- package/src/trace-sanitization.ts +110 -0
- package/src/types.ts +1014 -273
- package/src/typescript-module.ts +100 -0
- package/dist/choice-token.d.ts +0 -24
- package/dist/choice-token.js +0 -74
- package/dist/runtime/choice.d.ts +0 -15
- package/dist/runtime/choice.js +0 -413
- package/src/choice-token.ts +0 -165
- package/src/runtime/choice.ts +0 -686
package/dist/observability.js
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
|
|
1
|
+
// Mirrors packages/provider-observability in the platform monorepo (SoT).
|
|
2
|
+
export const PROVIDER_OBSERVABILITY_TAXONOMY_VERSION = "2026-08-07";
|
|
2
3
|
export const PROVIDER_ERROR_CATEGORIES = [
|
|
3
4
|
"ok",
|
|
4
5
|
"timeout",
|
|
@@ -6,6 +7,7 @@ export const PROVIDER_ERROR_CATEGORIES = [
|
|
|
6
7
|
"upstream_http",
|
|
7
8
|
"upstream_rate_limited",
|
|
8
9
|
"upstream_auth",
|
|
10
|
+
"upstream_rejected",
|
|
9
11
|
"upstream_schema_drift",
|
|
10
12
|
"proxy_pool",
|
|
11
13
|
"anti_bot_blocked",
|
|
@@ -15,6 +17,9 @@ export const PROVIDER_ERROR_CATEGORIES = [
|
|
|
15
17
|
"output_validation",
|
|
16
18
|
"provider_error",
|
|
17
19
|
"internal_error",
|
|
20
|
+
"dependency_unavailable",
|
|
21
|
+
"unsupported_transport",
|
|
22
|
+
"client_cancelled",
|
|
18
23
|
"unclassified",
|
|
19
24
|
];
|
|
20
25
|
export function categoryForStatus(status) {
|
|
@@ -26,6 +31,10 @@ export function categoryForStatus(status) {
|
|
|
26
31
|
return "upstream_rate_limited";
|
|
27
32
|
if (status === 401 || status === 403)
|
|
28
33
|
return "upstream_auth";
|
|
34
|
+
// provider-error-contract: 409/410/422 are the deterministic
|
|
35
|
+
// upstream-rejection status class — not a retryable upstream failure.
|
|
36
|
+
if (status === 409 || status === 410 || status === 422)
|
|
37
|
+
return "upstream_rejected";
|
|
29
38
|
if (status >= 400)
|
|
30
39
|
return "upstream_http";
|
|
31
40
|
return "unclassified";
|
|
@@ -37,3 +46,41 @@ export function isRetryableCategory(category) {
|
|
|
37
46
|
category === "upstream_http" ||
|
|
38
47
|
category === "proxy_pool");
|
|
39
48
|
}
|
|
49
|
+
// Who stopped the request (honest-provider-error-contract). A deliberately
|
|
50
|
+
// small public projection of the internal taxonomy:
|
|
51
|
+
// - client: the request itself is fixable by the caller
|
|
52
|
+
// - upstream_rule: the upstream service refused it under its own business
|
|
53
|
+
// rules (deterministic) or rate limits
|
|
54
|
+
// - upstream_failure: the upstream service malfunctioned — retryable
|
|
55
|
+
// - apifuse: an APIFuse-side fault (provider bug, platform dependency)
|
|
56
|
+
export const PROVIDER_ERROR_SOURCES = [
|
|
57
|
+
"client",
|
|
58
|
+
"upstream_rule",
|
|
59
|
+
"upstream_failure",
|
|
60
|
+
"apifuse",
|
|
61
|
+
];
|
|
62
|
+
export function sourceForCategory(category) {
|
|
63
|
+
switch (category) {
|
|
64
|
+
case "input_validation":
|
|
65
|
+
case "credential_expired":
|
|
66
|
+
case "credential_unavailable":
|
|
67
|
+
case "client_cancelled":
|
|
68
|
+
return "client";
|
|
69
|
+
case "upstream_rejected":
|
|
70
|
+
case "upstream_rate_limited":
|
|
71
|
+
return "upstream_rule";
|
|
72
|
+
case "timeout":
|
|
73
|
+
case "network":
|
|
74
|
+
case "upstream_http":
|
|
75
|
+
case "upstream_auth":
|
|
76
|
+
case "upstream_schema_drift":
|
|
77
|
+
case "anti_bot_blocked":
|
|
78
|
+
return "upstream_failure";
|
|
79
|
+
default:
|
|
80
|
+
// ok never reaches error serialization; provider_error,
|
|
81
|
+
// internal_error, output_validation, proxy_pool,
|
|
82
|
+
// dependency_unavailable, unsupported_transport, unclassified are
|
|
83
|
+
// APIFuse-side faults.
|
|
84
|
+
return "apifuse";
|
|
85
|
+
}
|
|
86
|
+
}
|
package/dist/provider.d.ts
CHANGED
|
@@ -1,11 +1,21 @@
|
|
|
1
|
-
export { AuthAbortError, credentialsAuthChallenge, createAuthFlowHelpers, defineCredentialsAuth, } from "./auth.js";
|
|
2
1
|
export type { CredentialsAuthChallengeDefinition, CredentialsAuthChallengeRequest, CredentialsAuthCompleteResult, CredentialsAuthCredential, CredentialsAuthField, CredentialsAuthFields, CredentialsAuthFieldType, CredentialsAuthInput, CredentialsAuthLoginResult, DefineCredentialsAuthOptions, DefinedCredentialsAuth, } from "./auth.js";
|
|
2
|
+
export { AuthAbortError, createAuthFlowHelpers, credentialsAuthChallenge, defineCredentialsAuth, } from "./auth.js";
|
|
3
3
|
export { createFormCeremony } from "./ceremonies/index.js";
|
|
4
|
-
export
|
|
5
|
-
export {
|
|
6
|
-
export {
|
|
7
|
-
export {
|
|
8
|
-
export {
|
|
9
|
-
export {
|
|
10
|
-
export
|
|
4
|
+
export type { JsonPrimitive, JsonValue } from "./contract-json.js";
|
|
5
|
+
export type { OperationDefinitionFor, ProviderBuilder, ProviderContextOf, ProviderDeclaration, ProviderDefinitionFor, } from "./define.js";
|
|
6
|
+
export { centered, defineHealthJourney, defineOperation, defineProvider, defineSmsOtpMatcher, delayed, every, } from "./define.js";
|
|
7
|
+
export type { ProviderCapabilityKey, ProviderEngine, ProviderEngineAttachmentInput, ProviderEngineBindingCandidates, ProviderEngineCapabilitySurface, ProviderEngineMode, ProviderEngineRequest, ProviderEngineResidentSurface, ProviderEngineSession, ProviderEngineTransport, } from "./engine.js";
|
|
8
|
+
export { createInProcessProviderEngine, createProviderEnvironment, ENGINE_OWNED_PROXY_CREDENTIAL_ENV_NAMES, ENGINE_OWNED_RESOLVER_CREDENTIAL_ENV_NAMES, ENGINE_OWNED_RUNTIME_ENV_NAMES, ENGINE_OWNED_TELEMETRY_ENV_NAMES, isEngineOwnedEnvName, isEngineOwnedProxyCredentialName, isEngineOwnedResolverCredentialName, isEngineOwnedRuntimeEnvName, isEngineOwnedTelemetryEnvName, PROVIDER_CAPABILITY_KEYS, PROVIDER_ENGINE_MODE_ENV, PROVIDER_ENGINE_PROTOCOL_VERSION, readEngineProxyCredentials, } from "./engine.js";
|
|
9
|
+
export { AuthError, HttpRedirectError, isProviderError, isSessionExpiredError, isTransportError, ProviderEgressDeniedError, ProviderEngineAuthenticationError, ProviderEngineProtocolVersionError, ProviderEngineUnavailableError, ProviderError, type ProviderErrorObservability, SDKError, SessionExpiredError, TransportError, ValidationError, } from "./errors.js";
|
|
10
|
+
export * from "./handle.js";
|
|
11
|
+
export { APIFUSE_HANDLE_META_KEY, HANDLE_KIND_NAME_PATTERN, handleFieldDescription, handleFieldNameFor, handleHasDirectionalFieldNames, isHandleFieldMeta, } from "./handle-meta.js";
|
|
12
|
+
export type { AssertionExpression, AssertionPredicate, AssertResult, AssertStep, AttemptReference, BoundedJsonPath, CandidateBlock, CandidatePolicy, CandidateReference, CredentialRefDeclaration, CredentialReference, EstablishedConnectionReference, ExtractResult, ExtractStep, FindFirst, GuardAttribution, GuardReasonCode, GuardResult, GuardStep, HealthScenario, HealthStep, JournalPolicy, JsonTemplate, ManualTriggerPolicy, NonEmpty, Operand, OperationResult, OperationStep, Quantifier, Reference, ReferenceNode, RelativeDateNode, RetryPolicy, SafeRegex, ScopedAssertionExpression, ScopedAssertionPredicate, ScopedItemReference, ScopedOperand, StepBase, StepReference, ValueType, } from "./health-scenario.js";
|
|
13
|
+
export { AssertionExpressionSchema, AssertionPredicateSchema, AssertStepSchema, BoundedJsonPathSchema, CandidateBlockSchema, CandidatePolicySchema, CredentialRefDeclarationSchema, defineHealthScenario, ExtractStepSchema, FindFirstSchema, GUARD_REASON_CODES, GuardStepSchema, HealthScenarioSchema, HealthStepSchema, JournalPolicySchema, JsonTemplateSchema, ManualTriggerPolicySchema, OperandSchema, OperationStepSchema, QuantifierSchema, ReferenceSchema, RelativeDateNodeSchema, RetryPolicySchema, SafeRegexSchema, ScopedAssertionExpressionSchema, ScopedAssertionPredicateSchema, ScopedItemReferenceSchema, ScopedOperandSchema, StepReferenceSchema, ValueTypeSchema, } from "./health-scenario.js";
|
|
14
|
+
export { getProviderLocalePath, type ProviderErrorMessageParams, providerLocaleKey, qualifyProviderLocaleKey, } from "./i18n/index.js";
|
|
15
|
+
export { type CreateHandleContextOptions, type CreateTestHandleContextOptions, createHandleContext, createTestHandleContext, type HandleNormalizationClass, type NormalizedHandle, normalizeHandle, } from "./runtime/handle.js";
|
|
16
|
+
export type { NativeGatewayProxy, NativeGatewayProxyResolutionInput, NativeGatewayProxySkipReason, NativeGatewayProxySynthesisInput, NativeGatewayProxySynthesisResult, NativeGatewayProxySynthesizer, NativeNetworkClientOptions, NativeNetworkErrorCode, VendorCredentialLookup, VendorCredentialResolver, } from "./runtime/native-network.js";
|
|
17
|
+
export { NativeEgressGrantExpiredError, NativeEgressNotDeclaredError, NativeIdleTimeoutError, NativeNetworkError, NativeProxyExpiredError, } from "./runtime/native-network-errors.js";
|
|
18
|
+
export { createMemoryProviderRuntimeState, createUnsupportedProviderRuntimeState, } from "./runtime/state.js";
|
|
19
|
+
export { APIFUSE_CONTENT_PROVENANCE_META_KEY, APIFUSE_CONTENT_TRUST_META_KEY, APIFUSE_DESCRIPTION_KEY_META_KEY, APIFUSE_REDACTION_MARKER, APIFUSE_SENSITIVE_KIND_META_KEY, APIFUSE_SENSITIVE_META_KEY, collectSensitivePaths, describeKey, field, fields, isSensitiveSchema, publicField, redactPayload, type SensitiveFieldKind, type SensitiveFieldOptions, type SensitivePath, sensitive, untrustedContent, z, } from "./schema.js";
|
|
20
|
+
export type { AuthAbortData, AuthAbortRetry, AuthFlowTerminalContext, AuthMode, AuthSafeData, AuthSafeJson, FlowContext, HealthCheckAssertionContext, HealthCheckCase, HealthCheckSuite, HealthCheckUnsupported, HealthJourneyDefinition, HealthJourneyEventContext, HealthJourneyManualTriggerPolicy, HealthJourneyRunContext, HealthJourneyRunResult, HealthScheduleRandomization, HttpAttemptContext, HttpHeadersFactory, HttpRedirectFailureReason, HttpRedirectPolicy, HttpRedirectPolicyMode, HttpRetryOptions, HttpRetrySummary, InferSchemaOutput, NativeContext, NativeNetworkClient, NativeNetworkCloseReason, NativeNetworkConnectInput, NativeNetworkConnection, NativeNetworkConnectOptions, NativeNetworkDynamicGrantOptions, NativeNetworkEgressGrant, NativeProviderConfig, NativeProxyDrainHandler, NativeProxyEgressInfo, NativeProxyExpiringEvent, NativeProxyExpiringReason, NativeTcpDynamicEgressRule, NativeTcpEgressGrant, NativeTcpEgressRule, NativeTcpPortRange, NativeTcpTlsMode, NativeTlsConnectOptions, OperationApprovalPolicy, OperationContractMetadata, OperationDefinition, OperationErrorCode, OperationExample, OperationLifecycle, OperationObservabilityConfig, OperationObservabilitySensitiveConfig, OperationRelationships, OperationRiskClass, OperationSensitivePath, OperationTransport, ProviderAccessVisibility, ProviderContext, ProviderContextFor, ProviderDefinition, ProviderDeploymentOverrides, ProviderErrorStatus, ProviderFileRef, ProviderFilesContext, ProviderLocale, ProviderLocaleKey, ProviderLocaleKeyInput, ProviderLogoProfile, ProviderProxyPolicy, ProviderPublicConnectionMode, ProviderPublicProfile, ProviderResolvedFile, ProviderRuntimeState, ProviderRuntimeTarget, ProviderStateDurationString, ProviderStateNamespace, ProviderStealthConfig, ProviderSupportLevel, ProxiedOAuthConfig, RedirectRunReason, SchemaLike, SmsOtpMatcherDefinition, StandardSchemaV1, StateCasResult, StateNamespaceOptions, StateNamespaceScope, StateValue, StateWriteOptions, StealthChallengeClassification, } from "./types.js";
|
|
11
21
|
export { HttpRetryAfterPolicy, HttpRetryDelayStrategy, HttpRetryJitter, HttpRetryPreset, HttpRetryUnsafeMethodPolicy, } from "./types.js";
|
package/dist/provider.js
CHANGED
|
@@ -1,9 +1,14 @@
|
|
|
1
|
-
export { AuthAbortError,
|
|
1
|
+
export { AuthAbortError, createAuthFlowHelpers, credentialsAuthChallenge, defineCredentialsAuth, } from "./auth.js";
|
|
2
2
|
export { createFormCeremony } from "./ceremonies/index.js";
|
|
3
|
-
export {
|
|
4
|
-
export {
|
|
5
|
-
export { AuthError, isProviderError, isSessionExpiredError, isTransportError, ProviderError, SessionExpiredError, TransportError, ValidationError, } from "./errors.js";
|
|
3
|
+
export { centered, defineHealthJourney, defineOperation, defineProvider, defineSmsOtpMatcher, delayed, every, } from "./define.js";
|
|
4
|
+
export { createInProcessProviderEngine, createProviderEnvironment, ENGINE_OWNED_PROXY_CREDENTIAL_ENV_NAMES, ENGINE_OWNED_RESOLVER_CREDENTIAL_ENV_NAMES, ENGINE_OWNED_RUNTIME_ENV_NAMES, ENGINE_OWNED_TELEMETRY_ENV_NAMES, isEngineOwnedEnvName, isEngineOwnedProxyCredentialName, isEngineOwnedResolverCredentialName, isEngineOwnedRuntimeEnvName, isEngineOwnedTelemetryEnvName, PROVIDER_CAPABILITY_KEYS, PROVIDER_ENGINE_MODE_ENV, PROVIDER_ENGINE_PROTOCOL_VERSION, readEngineProxyCredentials, } from "./engine.js";
|
|
5
|
+
export { AuthError, HttpRedirectError, isProviderError, isSessionExpiredError, isTransportError, ProviderEgressDeniedError, ProviderEngineAuthenticationError, ProviderEngineProtocolVersionError, ProviderEngineUnavailableError, ProviderError, SDKError, SessionExpiredError, TransportError, ValidationError, } from "./errors.js";
|
|
6
|
+
export * from "./handle.js";
|
|
7
|
+
export { APIFUSE_HANDLE_META_KEY, HANDLE_KIND_NAME_PATTERN, handleFieldDescription, handleFieldNameFor, handleHasDirectionalFieldNames, isHandleFieldMeta, } from "./handle-meta.js";
|
|
8
|
+
export { AssertionExpressionSchema, AssertionPredicateSchema, AssertStepSchema, BoundedJsonPathSchema, CandidateBlockSchema, CandidatePolicySchema, CredentialRefDeclarationSchema, defineHealthScenario, ExtractStepSchema, FindFirstSchema, GUARD_REASON_CODES, GuardStepSchema, HealthScenarioSchema, HealthStepSchema, JournalPolicySchema, JsonTemplateSchema, ManualTriggerPolicySchema, OperandSchema, OperationStepSchema, QuantifierSchema, ReferenceSchema, RelativeDateNodeSchema, RetryPolicySchema, SafeRegexSchema, ScopedAssertionExpressionSchema, ScopedAssertionPredicateSchema, ScopedItemReferenceSchema, ScopedOperandSchema, StepReferenceSchema, ValueTypeSchema, } from "./health-scenario.js";
|
|
6
9
|
export { getProviderLocalePath, providerLocaleKey, qualifyProviderLocaleKey, } from "./i18n/index.js";
|
|
7
|
-
export {
|
|
8
|
-
export {
|
|
10
|
+
export { createHandleContext, createTestHandleContext, normalizeHandle, } from "./runtime/handle.js";
|
|
11
|
+
export { NativeEgressGrantExpiredError, NativeEgressNotDeclaredError, NativeIdleTimeoutError, NativeNetworkError, NativeProxyExpiredError, } from "./runtime/native-network-errors.js";
|
|
12
|
+
export { createMemoryProviderRuntimeState, createUnsupportedProviderRuntimeState, } from "./runtime/state.js";
|
|
13
|
+
export { APIFUSE_CONTENT_PROVENANCE_META_KEY, APIFUSE_CONTENT_TRUST_META_KEY, APIFUSE_DESCRIPTION_KEY_META_KEY, APIFUSE_REDACTION_MARKER, APIFUSE_SENSITIVE_KIND_META_KEY, APIFUSE_SENSITIVE_META_KEY, collectSensitivePaths, describeKey, field, fields, isSensitiveSchema, publicField, redactPayload, sensitive, untrustedContent, z, } from "./schema.js";
|
|
9
14
|
export { HttpRetryAfterPolicy, HttpRetryDelayStrategy, HttpRetryJitter, HttpRetryPreset, HttpRetryUnsafeMethodPolicy, } from "./types.js";
|
|
@@ -1,6 +1,7 @@
|
|
|
1
|
-
import type { ContextScratchpad, EnvContext, FlowContext, HttpClient, StealthClient, SttContext } from "../types.js";
|
|
1
|
+
import type { ContextScratchpad, EnvContext, FlowContext, HttpClient, OcrContext, ProviderRuntimeState, StealthClient, SttContext } from "../types.js";
|
|
2
2
|
export declare function createScratchpad(allowedKeys: string[], initial?: Record<string, unknown>): ContextScratchpad;
|
|
3
3
|
export declare function createFlowContext(options: {
|
|
4
|
+
flowId?: string;
|
|
4
5
|
http: HttpClient;
|
|
5
6
|
stealth: StealthClient;
|
|
6
7
|
env: EnvContext;
|
|
@@ -8,7 +9,11 @@ export declare function createFlowContext(options: {
|
|
|
8
9
|
providerId: string;
|
|
9
10
|
connectionId?: string;
|
|
10
11
|
externalRef?: string;
|
|
12
|
+
/** Host-agnostic: callers pass an already-scoped runtime state, which this helper forwards verbatim. */
|
|
13
|
+
state?: ProviderRuntimeState;
|
|
11
14
|
allowedKeys: string[];
|
|
12
15
|
initialContext?: Record<string, unknown>;
|
|
16
|
+
ocr?: OcrContext;
|
|
13
17
|
stt?: SttContext;
|
|
18
|
+
trace?: FlowContext["trace"];
|
|
14
19
|
}): FlowContext;
|
|
@@ -1,6 +1,9 @@
|
|
|
1
1
|
import { ContextAccessError } from "../errors.js";
|
|
2
2
|
import { createAuthFlowHelpers } from "../auth.js";
|
|
3
|
+
import { createUnsupportedOcrClient } from "./ocr.js";
|
|
4
|
+
import { createUnsupportedResolverClient } from "./resolver-shared.js";
|
|
3
5
|
import { createUnsupportedSttClient } from "./stt.js";
|
|
6
|
+
import { createTraceContext } from "./trace.js";
|
|
4
7
|
function normalizeAllowedKeys(allowedKeys) {
|
|
5
8
|
return new Set(allowedKeys.filter((key) => key.trim().length > 0));
|
|
6
9
|
}
|
|
@@ -32,15 +35,20 @@ export function createScratchpad(allowedKeys, initial = {}) {
|
|
|
32
35
|
}
|
|
33
36
|
export function createFlowContext(options) {
|
|
34
37
|
return {
|
|
38
|
+
flowId: options.flowId,
|
|
35
39
|
connectionId: options.connectionId,
|
|
36
40
|
externalRef: options.externalRef,
|
|
37
41
|
tenantId: options.tenantId,
|
|
38
42
|
providerId: options.providerId,
|
|
43
|
+
trace: options.trace ?? createTraceContext(),
|
|
39
44
|
http: options.http,
|
|
45
|
+
state: options.state,
|
|
40
46
|
stealth: options.stealth,
|
|
41
47
|
env: options.env,
|
|
42
48
|
context: createScratchpad(options.allowedKeys, options.initialContext),
|
|
49
|
+
ocr: options.ocr ?? createUnsupportedOcrClient(),
|
|
43
50
|
stt: options.stt ?? createUnsupportedSttClient(),
|
|
51
|
+
resolver: createUnsupportedResolverClient("Resolver is not available in auth flow context"),
|
|
44
52
|
auth: createAuthFlowHelpers(),
|
|
45
53
|
};
|
|
46
54
|
}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Map whose entries carry an expiry and whose size is capped.
|
|
3
|
+
*
|
|
4
|
+
* Expired entries are dropped when read and swept on every insert, so a
|
|
5
|
+
* process that keeps minting new keys does not retain dead values. When the
|
|
6
|
+
* cap is still exceeded after the sweep, the least recently used entry is
|
|
7
|
+
* evicted and counted in `capacityEvictions` so callers can tell the two
|
|
8
|
+
* kinds of removal apart. Callers pass `now` explicitly so a single timestamp
|
|
9
|
+
* is used across a lookup-then-store sequence.
|
|
10
|
+
*/
|
|
11
|
+
export declare class BoundedExpiringMap<K, V> {
|
|
12
|
+
#private;
|
|
13
|
+
constructor(maxEntries: number, expiresAt: (value: V) => number);
|
|
14
|
+
get size(): number;
|
|
15
|
+
/** Entries removed to satisfy `maxEntries`; expiry removals are not counted. */
|
|
16
|
+
get capacityEvictions(): number;
|
|
17
|
+
get(key: K, now: number): V | undefined;
|
|
18
|
+
set(key: K, value: V, now: number): void;
|
|
19
|
+
delete(key: K): boolean;
|
|
20
|
+
clear(): void;
|
|
21
|
+
}
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Map whose entries carry an expiry and whose size is capped.
|
|
3
|
+
*
|
|
4
|
+
* Expired entries are dropped when read and swept on every insert, so a
|
|
5
|
+
* process that keeps minting new keys does not retain dead values. When the
|
|
6
|
+
* cap is still exceeded after the sweep, the least recently used entry is
|
|
7
|
+
* evicted and counted in `capacityEvictions` so callers can tell the two
|
|
8
|
+
* kinds of removal apart. Callers pass `now` explicitly so a single timestamp
|
|
9
|
+
* is used across a lookup-then-store sequence.
|
|
10
|
+
*/
|
|
11
|
+
export class BoundedExpiringMap {
|
|
12
|
+
#entries = new Map();
|
|
13
|
+
#maxEntries;
|
|
14
|
+
#expiresAt;
|
|
15
|
+
#capacityEvictions = 0;
|
|
16
|
+
constructor(maxEntries, expiresAt) {
|
|
17
|
+
if (!Number.isInteger(maxEntries) || maxEntries <= 0) {
|
|
18
|
+
throw new RangeError("maxEntries must be a positive integer");
|
|
19
|
+
}
|
|
20
|
+
this.#maxEntries = maxEntries;
|
|
21
|
+
this.#expiresAt = expiresAt;
|
|
22
|
+
}
|
|
23
|
+
get size() {
|
|
24
|
+
return this.#entries.size;
|
|
25
|
+
}
|
|
26
|
+
/** Entries removed to satisfy `maxEntries`; expiry removals are not counted. */
|
|
27
|
+
get capacityEvictions() {
|
|
28
|
+
return this.#capacityEvictions;
|
|
29
|
+
}
|
|
30
|
+
get(key, now) {
|
|
31
|
+
if (!this.#entries.has(key))
|
|
32
|
+
return undefined;
|
|
33
|
+
const value = this.#entries.get(key);
|
|
34
|
+
this.#entries.delete(key);
|
|
35
|
+
if (this.#expiresAt(value) <= now)
|
|
36
|
+
return undefined;
|
|
37
|
+
// Re-insert so Map iteration order doubles as the LRU order.
|
|
38
|
+
this.#entries.set(key, value);
|
|
39
|
+
return value;
|
|
40
|
+
}
|
|
41
|
+
set(key, value, now) {
|
|
42
|
+
for (const [existingKey, existing] of this.#entries) {
|
|
43
|
+
if (this.#expiresAt(existing) <= now)
|
|
44
|
+
this.#entries.delete(existingKey);
|
|
45
|
+
}
|
|
46
|
+
this.#entries.delete(key);
|
|
47
|
+
if (this.#expiresAt(value) <= now)
|
|
48
|
+
return;
|
|
49
|
+
this.#entries.set(key, value);
|
|
50
|
+
if (this.#entries.size > this.#maxEntries) {
|
|
51
|
+
const oldest = this.#entries.keys().next();
|
|
52
|
+
if (!oldest.done) {
|
|
53
|
+
this.#entries.delete(oldest.value);
|
|
54
|
+
this.#capacityEvictions += 1;
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
delete(key) {
|
|
59
|
+
return this.#entries.delete(key);
|
|
60
|
+
}
|
|
61
|
+
clear() {
|
|
62
|
+
this.#entries.clear();
|
|
63
|
+
}
|
|
64
|
+
}
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import type { BrowserClient } from "../types.js";
|
|
2
|
+
import type { BrowserTelemetrySink } from "./browser-telemetry.js";
|
|
3
|
+
export declare function isSupportedBrowserBinding(value: unknown): value is BrowserClient;
|
|
4
|
+
export declare function warnUnsupportedBrowserBinding(): void;
|
|
5
|
+
export declare function bindBrowserTelemetry(client: BrowserClient, sink: BrowserTelemetrySink): BrowserClient;
|
|
@@ -0,0 +1,83 @@
|
|
|
1
|
+
import { observeTelemetryCallback } from "./http-telemetry-guard.js";
|
|
2
|
+
const methods = new Set(["newPage", "rawPage", "withIsolatedContext", "solveChallenge"]);
|
|
3
|
+
const adapters = new WeakMap();
|
|
4
|
+
let warned = false;
|
|
5
|
+
export function isSupportedBrowserBinding(value) {
|
|
6
|
+
if ((typeof value !== "object" && typeof value !== "function") || value === null)
|
|
7
|
+
return false;
|
|
8
|
+
return [...methods].some((method) => {
|
|
9
|
+
try {
|
|
10
|
+
return typeof Reflect.get(value, method) === "function";
|
|
11
|
+
}
|
|
12
|
+
catch {
|
|
13
|
+
return false;
|
|
14
|
+
}
|
|
15
|
+
});
|
|
16
|
+
}
|
|
17
|
+
export function warnUnsupportedBrowserBinding() {
|
|
18
|
+
if (warned)
|
|
19
|
+
return;
|
|
20
|
+
warned = true;
|
|
21
|
+
try {
|
|
22
|
+
console.warn("[apifuse] browser telemetry not attached; reason=unsupported_binding_shape");
|
|
23
|
+
}
|
|
24
|
+
catch { }
|
|
25
|
+
}
|
|
26
|
+
export function bindBrowserTelemetry(client, sink) {
|
|
27
|
+
const existing = adapters.get(client);
|
|
28
|
+
if (existing) {
|
|
29
|
+
existing.sink = sink;
|
|
30
|
+
return existing.adapter;
|
|
31
|
+
}
|
|
32
|
+
const wrappers = new Map();
|
|
33
|
+
const adapter = new Proxy(Object.create(client), {
|
|
34
|
+
get(_target, property) {
|
|
35
|
+
const original = Reflect.get(client, property, client);
|
|
36
|
+
if (typeof property !== "string" || !methods.has(property) || typeof original !== "function")
|
|
37
|
+
return original;
|
|
38
|
+
const cached = wrappers.get(property);
|
|
39
|
+
if (cached && cached.original === original)
|
|
40
|
+
return cached.wrapped;
|
|
41
|
+
const wrapped = function (...args) {
|
|
42
|
+
const receiver = this === adapter ? client : this;
|
|
43
|
+
observeTelemetryCallback(state.sink, () => {
|
|
44
|
+
const declared = client.engine;
|
|
45
|
+
const engine = declared === "playwright-stealth" ||
|
|
46
|
+
declared === "nodriver" ||
|
|
47
|
+
declared === "selenium-uc"
|
|
48
|
+
? declared
|
|
49
|
+
: "host";
|
|
50
|
+
return state.sink.recordEngine(engine);
|
|
51
|
+
});
|
|
52
|
+
if (property === "newPage" || property === "rawPage" || property === "withIsolatedContext")
|
|
53
|
+
observeTelemetryCallback(state.sink, () => state.sink.recordPoolAcquire("not_configured"));
|
|
54
|
+
let result;
|
|
55
|
+
try {
|
|
56
|
+
result = Reflect.apply(original, receiver, args);
|
|
57
|
+
}
|
|
58
|
+
catch (error) {
|
|
59
|
+
observeTelemetryCallback(state.sink, () => state.sink.recordError("other"));
|
|
60
|
+
throw error;
|
|
61
|
+
}
|
|
62
|
+
try {
|
|
63
|
+
if (result instanceof Promise)
|
|
64
|
+
void Promise.prototype.then.call(result, undefined, () => {
|
|
65
|
+
observeTelemetryCallback(state.sink, () => state.sink.recordError("other"));
|
|
66
|
+
});
|
|
67
|
+
}
|
|
68
|
+
catch (error) {
|
|
69
|
+
observeTelemetryCallback(state.sink, () => {
|
|
70
|
+
throw error;
|
|
71
|
+
});
|
|
72
|
+
}
|
|
73
|
+
return result;
|
|
74
|
+
};
|
|
75
|
+
wrappers.set(property, { original, wrapped });
|
|
76
|
+
return wrapped;
|
|
77
|
+
},
|
|
78
|
+
});
|
|
79
|
+
const state = { sink, adapter };
|
|
80
|
+
adapters.set(client, state);
|
|
81
|
+
adapters.set(adapter, state);
|
|
82
|
+
return adapter;
|
|
83
|
+
}
|
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
import type { BrowserEngine } from "../types.js";
|
|
2
|
+
export type BrowserTelemetryEngine = BrowserEngine | "host";
|
|
3
|
+
import { type ClosedEnum, type SpanIndex, type TelemetryContributor } from "./request-telemetry.js";
|
|
4
|
+
export type BrowserTelemetryPoolAcquireOutcome = "ok" | "not_configured" | "queue_full" | "timed_out" | "shutting_down" | "unknown_lease" | "unknown_method" | "missing_allowed_hosts" | "transport_failure" | "other";
|
|
5
|
+
export type BrowserTelemetryErrorCode = "BROWSER_CDP_POOL_REQUIRED" | "BROWSER_PROXY_INVALID" | "BROWSER_RUNTIME_UNSUPPORTED" | "BROWSER_CDP_POOL_ERROR" | "other";
|
|
6
|
+
export type BrowserTelemetrySampleName = "browser.newPage" | "browser.page.goto" | "browser.page.fill" | "browser.page.click" | "browser.page.type" | "browser.page.waitForSelector" | "browser.evaluate" | "browser.content" | "browser.screenshot" | "other";
|
|
7
|
+
export type BrowserTelemetryLogPayload = {
|
|
8
|
+
allocateMs: number;
|
|
9
|
+
pages: number;
|
|
10
|
+
navigations: number;
|
|
11
|
+
actions: number;
|
|
12
|
+
evaluate: number;
|
|
13
|
+
content: number;
|
|
14
|
+
screenshot: number;
|
|
15
|
+
poolAcquireOutcome?: BrowserTelemetryPoolAcquireOutcome;
|
|
16
|
+
poolAcquireAttempts: number;
|
|
17
|
+
poolAcquireFailures: number;
|
|
18
|
+
poolAcquireUnknownCode?: number;
|
|
19
|
+
proxyAuthChallenges: number;
|
|
20
|
+
engine?: BrowserTelemetryEngine;
|
|
21
|
+
lastErrorCode?: BrowserTelemetryErrorCode;
|
|
22
|
+
samples: {
|
|
23
|
+
name: BrowserTelemetrySampleName;
|
|
24
|
+
ms: number;
|
|
25
|
+
status: "ok" | "error";
|
|
26
|
+
diagnostics?: string;
|
|
27
|
+
}[];
|
|
28
|
+
dropped: number;
|
|
29
|
+
telemetryFailed?: true;
|
|
30
|
+
};
|
|
31
|
+
export type BrowserTelemetryHeaderPayload = {
|
|
32
|
+
allocateMs: number;
|
|
33
|
+
pages: number;
|
|
34
|
+
navigations: number;
|
|
35
|
+
actions: number;
|
|
36
|
+
evaluate: number;
|
|
37
|
+
content: number;
|
|
38
|
+
screenshot: number;
|
|
39
|
+
poolAcquireOutcome?: ClosedEnum<BrowserTelemetryPoolAcquireOutcome>;
|
|
40
|
+
poolAcquireAttempts: number;
|
|
41
|
+
poolAcquireFailures: number;
|
|
42
|
+
proxyAuthChallenges: number;
|
|
43
|
+
engine?: ClosedEnum<BrowserTelemetryEngine>;
|
|
44
|
+
lastErrorCode?: ClosedEnum<BrowserTelemetryErrorCode>;
|
|
45
|
+
samples: {
|
|
46
|
+
name: ClosedEnum<BrowserTelemetrySampleName>;
|
|
47
|
+
ms: number;
|
|
48
|
+
status: ClosedEnum<"ok" | "error">;
|
|
49
|
+
}[];
|
|
50
|
+
dropped: number;
|
|
51
|
+
};
|
|
52
|
+
export interface BrowserTelemetrySink {
|
|
53
|
+
recordPoolAcquire(outcome: BrowserTelemetryPoolAcquireOutcome): void;
|
|
54
|
+
recordPoolAcquireUnknownCode?(code: number): void;
|
|
55
|
+
recordProxyAuthChallenge(): void;
|
|
56
|
+
recordEngine(engine: BrowserTelemetryEngine): void;
|
|
57
|
+
recordError(code: BrowserTelemetryErrorCode): void;
|
|
58
|
+
markTelemetryFailed?(): void;
|
|
59
|
+
}
|
|
60
|
+
export declare class BrowserTelemetryCollector implements TelemetryContributor<BrowserTelemetryLogPayload, BrowserTelemetryHeaderPayload>, BrowserTelemetrySink {
|
|
61
|
+
#private;
|
|
62
|
+
readonly key: "browser";
|
|
63
|
+
constructor(options?: {
|
|
64
|
+
redact?: (value: string) => string;
|
|
65
|
+
});
|
|
66
|
+
recordPoolAcquire(outcome: BrowserTelemetryPoolAcquireOutcome): void;
|
|
67
|
+
recordPoolAcquireUnknownCode(code: number): void;
|
|
68
|
+
recordProxyAuthChallenge(): void;
|
|
69
|
+
recordEngine(engine: BrowserTelemetryEngine): void;
|
|
70
|
+
recordError(code: BrowserTelemetryErrorCode): void;
|
|
71
|
+
markTelemetryFailed(): void;
|
|
72
|
+
toLogPayload(spans: SpanIndex): BrowserTelemetryLogPayload | undefined;
|
|
73
|
+
toHeaderPayload(log: BrowserTelemetryLogPayload): BrowserTelemetryHeaderPayload;
|
|
74
|
+
}
|
|
75
|
+
/** Defence in depth for diagnostics that accidentally contain protocol headers. */
|
|
76
|
+
export declare function stripBrowserHeaderMaterial(value: string): string;
|
|
@@ -0,0 +1,165 @@
|
|
|
1
|
+
import { Buffer } from "node:buffer";
|
|
2
|
+
import { closedEnum, } from "./request-telemetry.js";
|
|
3
|
+
const MAX_SAMPLES = 24;
|
|
4
|
+
const SAMPLE_NAMES = new Set([
|
|
5
|
+
"browser.newPage",
|
|
6
|
+
"browser.page.goto",
|
|
7
|
+
"browser.page.fill",
|
|
8
|
+
"browser.page.click",
|
|
9
|
+
"browser.page.type",
|
|
10
|
+
"browser.page.waitForSelector",
|
|
11
|
+
"browser.evaluate",
|
|
12
|
+
"browser.content",
|
|
13
|
+
"browser.screenshot",
|
|
14
|
+
]);
|
|
15
|
+
function sampleName(name) {
|
|
16
|
+
if (name === "browser.page.evaluate")
|
|
17
|
+
return "browser.evaluate";
|
|
18
|
+
if (name === "browser.page.content")
|
|
19
|
+
return "browser.content";
|
|
20
|
+
if (name === "browser.page.screenshot")
|
|
21
|
+
return "browser.screenshot";
|
|
22
|
+
return name === "[REDACTION_FAILED]" || !SAMPLE_NAMES.has(name)
|
|
23
|
+
? "other"
|
|
24
|
+
: name;
|
|
25
|
+
}
|
|
26
|
+
function boundedDiagnostics(text, redact) {
|
|
27
|
+
let result;
|
|
28
|
+
try {
|
|
29
|
+
result = stripBrowserHeaderMaterial(redact?.(text) ?? text);
|
|
30
|
+
}
|
|
31
|
+
catch {
|
|
32
|
+
return "[REDACTION_FAILED]";
|
|
33
|
+
}
|
|
34
|
+
const length = Math.min(result.length, 300);
|
|
35
|
+
const units = Buffer.alloc(length * 2);
|
|
36
|
+
for (let i = 0; i < length; i += 1)
|
|
37
|
+
units.writeUInt16LE(result.charCodeAt(i), i * 2);
|
|
38
|
+
return units.toString("utf16le");
|
|
39
|
+
}
|
|
40
|
+
function integer(value) {
|
|
41
|
+
return Math.min(Number.MAX_SAFE_INTEGER, Math.max(0, Math.floor(Number.isFinite(value) ? value : 0)));
|
|
42
|
+
}
|
|
43
|
+
function add(a, b) {
|
|
44
|
+
return Math.min(Number.MAX_SAFE_INTEGER, integer(a) + integer(b));
|
|
45
|
+
}
|
|
46
|
+
export class BrowserTelemetryCollector {
|
|
47
|
+
key = "browser";
|
|
48
|
+
#poolAcquireOutcome;
|
|
49
|
+
#poolAcquireAttempts = 0;
|
|
50
|
+
#poolAcquireFailures = 0;
|
|
51
|
+
#poolAcquireUnknownCode;
|
|
52
|
+
#telemetryFailed = false;
|
|
53
|
+
#proxyAuthChallenges = 0;
|
|
54
|
+
#engine;
|
|
55
|
+
#lastErrorCode;
|
|
56
|
+
#redact;
|
|
57
|
+
constructor(options = {}) {
|
|
58
|
+
this.#redact = options.redact;
|
|
59
|
+
}
|
|
60
|
+
recordPoolAcquire(outcome) {
|
|
61
|
+
this.#poolAcquireOutcome = outcome;
|
|
62
|
+
this.#poolAcquireAttempts = add(this.#poolAcquireAttempts, 1);
|
|
63
|
+
if (outcome !== "ok")
|
|
64
|
+
this.#poolAcquireFailures = add(this.#poolAcquireFailures, 1);
|
|
65
|
+
}
|
|
66
|
+
recordPoolAcquireUnknownCode(code) {
|
|
67
|
+
this.#poolAcquireUnknownCode = code;
|
|
68
|
+
}
|
|
69
|
+
recordProxyAuthChallenge() {
|
|
70
|
+
this.#proxyAuthChallenges = add(this.#proxyAuthChallenges, 1);
|
|
71
|
+
}
|
|
72
|
+
recordEngine(engine) {
|
|
73
|
+
this.#engine = engine;
|
|
74
|
+
}
|
|
75
|
+
recordError(code) {
|
|
76
|
+
this.#lastErrorCode = code;
|
|
77
|
+
}
|
|
78
|
+
markTelemetryFailed() {
|
|
79
|
+
this.#telemetryFailed = true;
|
|
80
|
+
}
|
|
81
|
+
toLogPayload(spans) {
|
|
82
|
+
const browserSpans = spans.spans.filter((span) => span.name === "browser.newPage" ||
|
|
83
|
+
span.name === "browser.rawPage" ||
|
|
84
|
+
span.name === "browser.withIsolatedContext" ||
|
|
85
|
+
span.name.startsWith("browser.page.") ||
|
|
86
|
+
/^browser\.(evaluate|content|screenshot)$/.test(span.name));
|
|
87
|
+
const failedSpan = spans.spans.some((span) => span.name === "[REDACTION_FAILED]");
|
|
88
|
+
if (browserSpans.length === 0 &&
|
|
89
|
+
!failedSpan &&
|
|
90
|
+
!this.#poolAcquireOutcome &&
|
|
91
|
+
this.#proxyAuthChallenges === 0 &&
|
|
92
|
+
!this.#engine &&
|
|
93
|
+
!this.#lastErrorCode &&
|
|
94
|
+
!this.#telemetryFailed)
|
|
95
|
+
return undefined;
|
|
96
|
+
const count = (name) => spans.count(name);
|
|
97
|
+
const sampleSpans = failedSpan
|
|
98
|
+
? [...browserSpans, ...spans.spans.filter((span) => span.name === "[REDACTION_FAILED]")]
|
|
99
|
+
: browserSpans;
|
|
100
|
+
const samples = sampleSpans
|
|
101
|
+
.slice(0, MAX_SAMPLES)
|
|
102
|
+
.map((span) => ({
|
|
103
|
+
name: sampleName(span.name),
|
|
104
|
+
ms: integer(span.duration_ms),
|
|
105
|
+
status: (span.status === "error" ? "error" : "ok"),
|
|
106
|
+
...(span.name === "[REDACTION_FAILED]"
|
|
107
|
+
? { diagnostics: "[REDACTION_FAILED]" }
|
|
108
|
+
: span.error
|
|
109
|
+
? { diagnostics: boundedDiagnostics(span.error, this.#redact) }
|
|
110
|
+
: {}),
|
|
111
|
+
}));
|
|
112
|
+
return {
|
|
113
|
+
allocateMs: integer(browserSpans
|
|
114
|
+
.filter((span) => span.name === "browser.newPage")
|
|
115
|
+
.reduce((sum, span) => sum + Number(span.attributes.allocate_ms ?? span.duration_ms), 0)),
|
|
116
|
+
pages: add(add(count("browser.newPage"), count("browser.rawPage")), count("browser.withIsolatedContext")),
|
|
117
|
+
navigations: integer(count("browser.page.goto")),
|
|
118
|
+
actions: ["fill", "click", "type", "waitForSelector"].reduce((sum, method) => add(sum, count(`browser.page.${method}`)), 0),
|
|
119
|
+
evaluate: add(count("browser.evaluate"), count("browser.page.evaluate")),
|
|
120
|
+
content: add(count("browser.page.content"), count("browser.content")),
|
|
121
|
+
screenshot: add(count("browser.page.screenshot"), count("browser.screenshot")),
|
|
122
|
+
...(this.#poolAcquireOutcome ? { poolAcquireOutcome: this.#poolAcquireOutcome } : {}),
|
|
123
|
+
poolAcquireAttempts: this.#poolAcquireAttempts,
|
|
124
|
+
poolAcquireFailures: this.#poolAcquireFailures,
|
|
125
|
+
...(this.#poolAcquireUnknownCode === undefined
|
|
126
|
+
? {}
|
|
127
|
+
: { poolAcquireUnknownCode: this.#poolAcquireUnknownCode }),
|
|
128
|
+
proxyAuthChallenges: this.#proxyAuthChallenges,
|
|
129
|
+
...(this.#engine ? { engine: this.#engine } : {}),
|
|
130
|
+
...(this.#lastErrorCode ? { lastErrorCode: this.#lastErrorCode } : {}),
|
|
131
|
+
samples,
|
|
132
|
+
dropped: Math.max(0, sampleSpans.length - samples.length),
|
|
133
|
+
...(this.#telemetryFailed ? { telemetryFailed: true } : {}),
|
|
134
|
+
};
|
|
135
|
+
}
|
|
136
|
+
toHeaderPayload(log) {
|
|
137
|
+
return {
|
|
138
|
+
allocateMs: log.allocateMs,
|
|
139
|
+
pages: log.pages,
|
|
140
|
+
navigations: log.navigations,
|
|
141
|
+
actions: log.actions,
|
|
142
|
+
evaluate: log.evaluate,
|
|
143
|
+
content: log.content,
|
|
144
|
+
screenshot: log.screenshot,
|
|
145
|
+
...(log.poolAcquireOutcome ? { poolAcquireOutcome: closedEnum(log.poolAcquireOutcome) } : {}),
|
|
146
|
+
poolAcquireAttempts: log.poolAcquireAttempts,
|
|
147
|
+
poolAcquireFailures: log.poolAcquireFailures,
|
|
148
|
+
proxyAuthChallenges: log.proxyAuthChallenges,
|
|
149
|
+
...(log.engine ? { engine: closedEnum(log.engine) } : {}),
|
|
150
|
+
...(log.lastErrorCode ? { lastErrorCode: closedEnum(log.lastErrorCode) } : {}),
|
|
151
|
+
samples: log.samples.map((sample) => ({
|
|
152
|
+
name: closedEnum(sample.name),
|
|
153
|
+
ms: sample.ms,
|
|
154
|
+
status: closedEnum(sample.status),
|
|
155
|
+
})),
|
|
156
|
+
dropped: log.dropped,
|
|
157
|
+
};
|
|
158
|
+
}
|
|
159
|
+
}
|
|
160
|
+
/** Defence in depth for diagnostics that accidentally contain protocol headers. */
|
|
161
|
+
export function stripBrowserHeaderMaterial(value) {
|
|
162
|
+
return value
|
|
163
|
+
.replace(/(^|[^\p{L}\p{N}_-])[\t ]*(?:cookie|set-cookie|authorization)[\t ]*(?::|=)[^\r\n]*/giu, "$1[REDACTED]")
|
|
164
|
+
.replace(/"(?:cookie|set-cookie|authorization)"[\t ]*:[\t ]*"(?:\\.|[^"\\])*"/giu, "[REDACTED]");
|
|
165
|
+
}
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import type { BrowserTelemetrySink } from "./browser-telemetry.js";
|
|
1
2
|
import type { BrowserChallengeRequest, BrowserChallengeResult, BrowserClient as BrowserClientContract, BrowserEngine, BrowserOptions, BrowserPage } from "../types.js";
|
|
2
3
|
type BrowserPageContract = BrowserPage;
|
|
3
4
|
export type BrowserClientOptions = BrowserOptions & {
|
|
@@ -5,6 +6,8 @@ export type BrowserClientOptions = BrowserOptions & {
|
|
|
5
6
|
cdpUrl?: string;
|
|
6
7
|
executablePath?: string;
|
|
7
8
|
extraArgs?: string[];
|
|
9
|
+
serviceWorkers?: "allow" | "block";
|
|
10
|
+
telemetry?: BrowserTelemetrySink;
|
|
8
11
|
};
|
|
9
12
|
export declare class BrowserClient implements BrowserClientContract {
|
|
10
13
|
private readonly client;
|
|
@@ -12,6 +15,7 @@ export declare class BrowserClient implements BrowserClientContract {
|
|
|
12
15
|
private activePage?;
|
|
13
16
|
private readonly activePages;
|
|
14
17
|
private readonly _engine;
|
|
18
|
+
private readonly telemetry?;
|
|
15
19
|
constructor(options?: BrowserClientOptions);
|
|
16
20
|
get engine(): BrowserEngine;
|
|
17
21
|
newPage(): Promise<BrowserPageContract>;
|