@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
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
export type DiagnosticRedactor = (text: string) => string;
|
|
2
|
+
export declare const REDACTION_FAILED = "[REDACTION_FAILED]";
|
|
3
|
+
/** Observer failures must never return the original diagnostic, including via ?? fallbacks. */
|
|
4
|
+
export declare function redactDiagnosticText(text: string, redact?: DiagnosticRedactor): string;
|
|
5
|
+
export interface DiagnosticSensitiveRegistry {
|
|
6
|
+
redact: DiagnosticRedactor;
|
|
7
|
+
readonly redactCritical: DiagnosticRedactor;
|
|
8
|
+
readonly redactStructured: DiagnosticRedactor;
|
|
9
|
+
readonly suppressed: boolean;
|
|
10
|
+
has(value: string): boolean;
|
|
11
|
+
add(values: readonly string[]): void;
|
|
12
|
+
suppress(): void;
|
|
13
|
+
}
|
|
14
|
+
/** Opaque handle: callers cannot modify either of the two independently compiled matchers. */
|
|
15
|
+
export interface CompiledDiagnosticSensitiveValues {
|
|
16
|
+
readonly kind: "compiled-diagnostic-sensitive-values";
|
|
17
|
+
}
|
|
18
|
+
export declare function compileDiagnosticSensitiveValues(values: readonly string[]): CompiledDiagnosticSensitiveValues;
|
|
19
|
+
/**
|
|
20
|
+
* Give an independent runtime/configuration evaluation its own fallback lifetime.
|
|
21
|
+
* Apps created inside the scope retain that inventory, including across awaits and
|
|
22
|
+
* after the callback returns. Ordinary startup/CLI reads keep the process lifetime.
|
|
23
|
+
* This also lets test harnesses isolate synthetic env reads without clearing live
|
|
24
|
+
* apps' credentials or weakening registration, matching, or exhaustion policies.
|
|
25
|
+
*/
|
|
26
|
+
export declare function withDiagnosticFallbackScope<T>(fn: () => T): T;
|
|
27
|
+
/** Re-enter the app's existing lifetime, including for detached request callbacks. */
|
|
28
|
+
export declare function withAppDiagnosticFallback<T>(staticValues: CompiledDiagnosticSensitiveValues, fn: () => T): T;
|
|
29
|
+
export declare function suppressProcessDiagnosticValues(): void;
|
|
30
|
+
export declare function registerProcessDiagnosticValues(values: readonly string[]): void;
|
|
31
|
+
/** The app's static inventory and the shared outside-context fallback form one static part. */
|
|
32
|
+
export declare function compileProcessDiagnosticSensitiveValues(values: readonly string[]): CompiledDiagnosticSensitiveValues;
|
|
33
|
+
/** One small mutable registry per request, composed with precompiled process-static values. */
|
|
34
|
+
export declare function createDiagnosticRedactor(values?: readonly string[], staticValues?: CompiledDiagnosticSensitiveValues): DiagnosticSensitiveRegistry;
|
|
35
|
+
/** Internal binding; neither the registry nor its values enter provider-facing context types. */
|
|
36
|
+
export declare function bindDiagnosticSensitiveRegistry(trace: object, registry: DiagnosticSensitiveRegistry): void;
|
|
37
|
+
export declare function registerDiagnosticSensitiveValues(trace: object, values: readonly string[]): void;
|
|
38
|
+
export declare function bindCriticalDiagnosticRedactor(redact: DiagnosticRedactor, critical: DiagnosticRedactor, structured?: DiagnosticRedactor, isSuppressed?: () => boolean): void;
|
|
39
|
+
export declare function isDiagnosticRedactionSuppressed(redact?: DiagnosticRedactor): boolean;
|
|
40
|
+
/** Typed values and keys still match known credentials, but never blanket suppression. */
|
|
41
|
+
export declare function diagnosticStructuredRedactor(redact?: DiagnosticRedactor): DiagnosticRedactor | undefined;
|
|
42
|
+
export declare function redactDiagnosticAttributeKey(key: string, redact?: DiagnosticRedactor): string;
|
|
43
|
+
export declare function redactCriticalDiagnosticText(text: string, redact?: DiagnosticRedactor): string;
|
|
44
|
+
/**
|
|
45
|
+
* The redactor for one attribute value. A value its producer declares as a closed-enum literal for
|
|
46
|
+
* this key is a contract, like a typed number: exhaustion suppression skips it, while registered
|
|
47
|
+
* credentials still match. Any other value under the same key stays free text.
|
|
48
|
+
*/
|
|
49
|
+
export declare function diagnosticAttributeRedactor(key: string, redact?: DiagnosticRedactor, value?: unknown): DiagnosticRedactor | undefined;
|
|
50
|
+
export declare function isDiagnosticBigintAttribute(attributes: object, key: string): boolean;
|
|
51
|
+
export declare function copyDiagnosticAttributeTypes<T extends Record<string, unknown>>(source: Record<string, unknown>, target: T): T;
|
|
52
|
+
/** Reserve existing keys so independently redacted names never drop an attribute. */
|
|
53
|
+
export declare function redactedKeyAllocator(keys: Iterable<string>): () => string;
|
|
54
|
+
export declare function isRedactedKey(key: string): boolean;
|
|
@@ -0,0 +1,571 @@
|
|
|
1
|
+
import { AsyncLocalStorage } from "node:async_hooks";
|
|
2
|
+
import { allSensitiveValueVariants, normalizePercentEscapes, REDACTED_QUERY_VALUE, } from "./request-options.js";
|
|
3
|
+
import { RESOLVER_CLOSED_ENUM_SPAN_ATTRIBUTES } from "./resolver-span-attributes.js";
|
|
4
|
+
export const REDACTION_FAILED = "[REDACTION_FAILED]";
|
|
5
|
+
// No supported credential source needs 1–3 character secrets. Registering these
|
|
6
|
+
// common tokens damages unrelated IDs and diagnostics even with token boundaries.
|
|
7
|
+
// Apply the same floor to static, fallback and request inventories (as self-test does).
|
|
8
|
+
const MINIMUM_REGISTERED_VALUE_LENGTH = 4;
|
|
9
|
+
/** Observer failures must never return the original diagnostic, including via ?? fallbacks. */
|
|
10
|
+
export function redactDiagnosticText(text, redact) {
|
|
11
|
+
try {
|
|
12
|
+
const result = redact ? redact(text) : text;
|
|
13
|
+
return typeof result === "string" ? result : REDACTION_FAILED;
|
|
14
|
+
}
|
|
15
|
+
catch {
|
|
16
|
+
return REDACTION_FAILED;
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
function node() {
|
|
20
|
+
return { next: new Map() };
|
|
21
|
+
}
|
|
22
|
+
function compile(variants) {
|
|
23
|
+
const matcher = {
|
|
24
|
+
exact: node(),
|
|
25
|
+
folded: node(),
|
|
26
|
+
hasFolded: false,
|
|
27
|
+
// Only long values participate in encoded matching. Unreserved ASCII is
|
|
28
|
+
// percent-encodable too (%6f for o); encodeURIComponent(value) === value
|
|
29
|
+
// does NOT prove that residual escapes cannot conceal that credential.
|
|
30
|
+
canMatchPercentEncoded: variants.some((variant) => variant.caseInsensitive),
|
|
31
|
+
size: variants.length,
|
|
32
|
+
minimumLength: variants.reduce((minimum, variant) => Math.min(minimum, variant.value.length), Infinity),
|
|
33
|
+
cache: new Map(),
|
|
34
|
+
};
|
|
35
|
+
if (variants.some((variant) => !variant.caseInsensitive))
|
|
36
|
+
matcher.encoded = compile(variants.filter((variant) => variant.caseInsensitive));
|
|
37
|
+
// A few request credentials are cheaper as native literal searches; large
|
|
38
|
+
// process-static inventories use tries to avoid per-needle scans.
|
|
39
|
+
if (variants.length <= 16) {
|
|
40
|
+
matcher.needles = variants.map((variant) => ({
|
|
41
|
+
...variant,
|
|
42
|
+
value: variant.caseInsensitive ? variant.value.toLowerCase() : variant.value,
|
|
43
|
+
}));
|
|
44
|
+
matcher.hasFolded = variants.some((variant) => variant.caseInsensitive);
|
|
45
|
+
return matcher;
|
|
46
|
+
}
|
|
47
|
+
for (const variant of variants) {
|
|
48
|
+
let current = variant.caseInsensitive ? matcher.folded : matcher.exact;
|
|
49
|
+
if (variant.caseInsensitive)
|
|
50
|
+
matcher.hasFolded = true;
|
|
51
|
+
const value = variant.caseInsensitive ? variant.value.toLowerCase() : variant.value;
|
|
52
|
+
for (let index = 0; index < value.length; index++) {
|
|
53
|
+
const character = value[index];
|
|
54
|
+
let child = current.next.get(character);
|
|
55
|
+
if (!child) {
|
|
56
|
+
child = node();
|
|
57
|
+
current.next.set(character, child);
|
|
58
|
+
}
|
|
59
|
+
current = child;
|
|
60
|
+
}
|
|
61
|
+
current.boundary =
|
|
62
|
+
current.boundary === undefined
|
|
63
|
+
? variant.requiresTokenBoundary
|
|
64
|
+
: current.boundary && variant.requiresTokenBoundary;
|
|
65
|
+
}
|
|
66
|
+
return matcher;
|
|
67
|
+
}
|
|
68
|
+
const compiledValues = new WeakMap();
|
|
69
|
+
export function compileDiagnosticSensitiveValues(values) {
|
|
70
|
+
const handle = Object.freeze({
|
|
71
|
+
kind: "compiled-diagnostic-sensitive-values",
|
|
72
|
+
});
|
|
73
|
+
const registered = values.filter((value) => value.length >= MINIMUM_REGISTERED_VALUE_LENGTH);
|
|
74
|
+
const variants = allSensitiveValueVariants(registered);
|
|
75
|
+
const primary = compile(variants), check = compile(variants);
|
|
76
|
+
compiledValues.set(handle, {
|
|
77
|
+
primary,
|
|
78
|
+
check,
|
|
79
|
+
criticalPrimary: primary.encoded ?? primary,
|
|
80
|
+
criticalCheck: check.encoded ?? check,
|
|
81
|
+
values: new Set(registered),
|
|
82
|
+
});
|
|
83
|
+
return handle;
|
|
84
|
+
}
|
|
85
|
+
// Outside-context reads are process lifetime data, bounded like request harvesting.
|
|
86
|
+
const PROCESS_VALUE_LIMIT = 1024;
|
|
87
|
+
const PROCESS_BYTE_LIMIT = 64 * 1024;
|
|
88
|
+
function createDiagnosticFallback() {
|
|
89
|
+
return {
|
|
90
|
+
values: new Set(),
|
|
91
|
+
bytes: 0,
|
|
92
|
+
suppressed: false,
|
|
93
|
+
version: 0,
|
|
94
|
+
compiledVersion: -1,
|
|
95
|
+
compiled: undefined,
|
|
96
|
+
};
|
|
97
|
+
}
|
|
98
|
+
const processFallback = createDiagnosticFallback();
|
|
99
|
+
const fallbackScopes = new AsyncLocalStorage();
|
|
100
|
+
const processCompositions = new WeakMap();
|
|
101
|
+
/**
|
|
102
|
+
* Give an independent runtime/configuration evaluation its own fallback lifetime.
|
|
103
|
+
* Apps created inside the scope retain that inventory, including across awaits and
|
|
104
|
+
* after the callback returns. Ordinary startup/CLI reads keep the process lifetime.
|
|
105
|
+
* This also lets test harnesses isolate synthetic env reads without clearing live
|
|
106
|
+
* apps' credentials or weakening registration, matching, or exhaustion policies.
|
|
107
|
+
*/
|
|
108
|
+
export function withDiagnosticFallbackScope(fn) {
|
|
109
|
+
return fallbackScopes.run(createDiagnosticFallback(), fn);
|
|
110
|
+
}
|
|
111
|
+
/** Re-enter the app's existing lifetime, including for detached request callbacks. */
|
|
112
|
+
export function withAppDiagnosticFallback(staticValues, fn) {
|
|
113
|
+
return fallbackScopes.run(processCompositions.get(staticValues) ?? currentDiagnosticFallback(), fn);
|
|
114
|
+
}
|
|
115
|
+
function currentDiagnosticFallback() {
|
|
116
|
+
return fallbackScopes.getStore() ?? processFallback;
|
|
117
|
+
}
|
|
118
|
+
export function suppressProcessDiagnosticValues() {
|
|
119
|
+
const fallback = currentDiagnosticFallback();
|
|
120
|
+
if (fallback.suppressed)
|
|
121
|
+
return;
|
|
122
|
+
fallback.suppressed = true;
|
|
123
|
+
console.warn("[apifuse] diagnostic redaction failed closed; reason=static_registry_limit; limit=1024_entries/65536_bytes");
|
|
124
|
+
}
|
|
125
|
+
export function registerProcessDiagnosticValues(values) {
|
|
126
|
+
const fallback = currentDiagnosticFallback();
|
|
127
|
+
if (fallback.suppressed)
|
|
128
|
+
return;
|
|
129
|
+
for (const value of values) {
|
|
130
|
+
if (value.length < MINIMUM_REGISTERED_VALUE_LENGTH || fallback.values.has(value))
|
|
131
|
+
continue;
|
|
132
|
+
const bytes = Buffer.byteLength(value);
|
|
133
|
+
if (fallback.values.size >= PROCESS_VALUE_LIMIT ||
|
|
134
|
+
fallback.bytes + bytes > PROCESS_BYTE_LIMIT) {
|
|
135
|
+
suppressProcessDiagnosticValues();
|
|
136
|
+
return;
|
|
137
|
+
}
|
|
138
|
+
fallback.values.add(value);
|
|
139
|
+
fallback.bytes += bytes;
|
|
140
|
+
fallback.version++;
|
|
141
|
+
}
|
|
142
|
+
}
|
|
143
|
+
/** The app's static inventory and the shared outside-context fallback form one static part. */
|
|
144
|
+
export function compileProcessDiagnosticSensitiveValues(values) {
|
|
145
|
+
const handle = compileDiagnosticSensitiveValues(values);
|
|
146
|
+
processCompositions.set(handle, currentDiagnosticFallback());
|
|
147
|
+
return handle;
|
|
148
|
+
}
|
|
149
|
+
function isTokenCharacter(value) {
|
|
150
|
+
return value !== undefined && /[\p{L}\p{N}]/u.test(value);
|
|
151
|
+
}
|
|
152
|
+
function matchLength(root, comparable, original, start) {
|
|
153
|
+
let current = root;
|
|
154
|
+
let length = 0;
|
|
155
|
+
for (let index = start; index < comparable.length; index++) {
|
|
156
|
+
const child = current.next.get(comparable[index]);
|
|
157
|
+
if (!child)
|
|
158
|
+
break;
|
|
159
|
+
current = child;
|
|
160
|
+
if (current.boundary !== undefined &&
|
|
161
|
+
(!current.boundary ||
|
|
162
|
+
(!isTokenCharacter(original[start - 1]) && !isTokenCharacter(original[index + 1])))) {
|
|
163
|
+
length = index - start + 1;
|
|
164
|
+
}
|
|
165
|
+
}
|
|
166
|
+
return length;
|
|
167
|
+
}
|
|
168
|
+
function replaceNeedles(text, matcher, checkOnly) {
|
|
169
|
+
const comparable = text.includes("%") ? normalizePercentEscapes(text) : text;
|
|
170
|
+
const folded = matcher.hasFolded ? comparable.toLowerCase() : comparable;
|
|
171
|
+
let cursor = 0;
|
|
172
|
+
let output = "";
|
|
173
|
+
while (cursor < text.length) {
|
|
174
|
+
let first = text.length;
|
|
175
|
+
let length = 0;
|
|
176
|
+
for (const variant of matcher.needles ?? []) {
|
|
177
|
+
const source = variant.caseInsensitive ? folded : text;
|
|
178
|
+
let index = source.indexOf(variant.value, cursor);
|
|
179
|
+
while (index !== -1) {
|
|
180
|
+
const end = index + variant.value.length;
|
|
181
|
+
const markerStart = source.lastIndexOf("[", index);
|
|
182
|
+
const withinMarker = markerStart !== -1 && index < markerStart + markerLength(comparable, markerStart);
|
|
183
|
+
if (!withinMarker &&
|
|
184
|
+
(!variant.requiresTokenBoundary ||
|
|
185
|
+
(!isTokenCharacter(source[index - 1]) && !isTokenCharacter(source[end]))))
|
|
186
|
+
break;
|
|
187
|
+
index = source.indexOf(variant.value, index + 1);
|
|
188
|
+
}
|
|
189
|
+
if (index === -1)
|
|
190
|
+
continue;
|
|
191
|
+
if (checkOnly || (variant.caseInsensitive && folded.length !== text.length))
|
|
192
|
+
return REDACTED_QUERY_VALUE;
|
|
193
|
+
if (index < first || (index === first && variant.value.length > length)) {
|
|
194
|
+
first = index;
|
|
195
|
+
length = variant.value.length;
|
|
196
|
+
}
|
|
197
|
+
}
|
|
198
|
+
if (!length)
|
|
199
|
+
break;
|
|
200
|
+
output += text.slice(cursor, first) + REDACTED_QUERY_VALUE;
|
|
201
|
+
cursor = first + length;
|
|
202
|
+
}
|
|
203
|
+
return cursor ? output + text.slice(cursor) : text;
|
|
204
|
+
}
|
|
205
|
+
/** Literal tries have no secret-built regular expressions and no per-needle no-match scans. */
|
|
206
|
+
function replaceMatches(text, matchers, checkOnly = false) {
|
|
207
|
+
if (matchers.length === 1 && matchers[0].needles)
|
|
208
|
+
return replaceNeedles(text, matchers[0], checkOnly);
|
|
209
|
+
const comparable = text.includes("%") ? normalizePercentEscapes(text) : text;
|
|
210
|
+
const folded = matchers.some((matcher) => matcher.hasFolded)
|
|
211
|
+
? comparable.toLowerCase()
|
|
212
|
+
: comparable;
|
|
213
|
+
// Unicode case folding can change offsets. Suppress the field on a folded match.
|
|
214
|
+
if (folded.length !== comparable.length) {
|
|
215
|
+
for (const matcher of matchers) {
|
|
216
|
+
for (let index = 0; index < folded.length; index++) {
|
|
217
|
+
if (matchLength(matcher.folded, folded, folded, index))
|
|
218
|
+
return REDACTED_QUERY_VALUE;
|
|
219
|
+
}
|
|
220
|
+
}
|
|
221
|
+
}
|
|
222
|
+
let cursor = 0;
|
|
223
|
+
let output = "";
|
|
224
|
+
for (let index = 0; index < text.length; index++) {
|
|
225
|
+
// Sentinels are emitted constants, not evidence of a residual credential.
|
|
226
|
+
const marker = markerLength(text, index);
|
|
227
|
+
if (marker) {
|
|
228
|
+
index += marker - 1;
|
|
229
|
+
continue;
|
|
230
|
+
}
|
|
231
|
+
let length = 0;
|
|
232
|
+
for (const matcher of matchers) {
|
|
233
|
+
length = Math.max(length, matchLength(matcher.exact, text, text, index));
|
|
234
|
+
if (matcher.hasFolded && folded.length === comparable.length) {
|
|
235
|
+
length = Math.max(length, matchLength(matcher.folded, folded, text, index));
|
|
236
|
+
}
|
|
237
|
+
}
|
|
238
|
+
if (!length)
|
|
239
|
+
continue;
|
|
240
|
+
if (checkOnly)
|
|
241
|
+
return REDACTED_QUERY_VALUE;
|
|
242
|
+
output += text.slice(cursor, index) + REDACTED_QUERY_VALUE;
|
|
243
|
+
cursor = index + length;
|
|
244
|
+
index = cursor - 1;
|
|
245
|
+
}
|
|
246
|
+
return cursor === 0 ? text : output + text.slice(cursor);
|
|
247
|
+
}
|
|
248
|
+
function decodePercent(text) {
|
|
249
|
+
try {
|
|
250
|
+
return decodeURIComponent(text);
|
|
251
|
+
}
|
|
252
|
+
catch {
|
|
253
|
+
// An unrelated malformed escape must not hide valid encoded credential text.
|
|
254
|
+
return text.replace(/(?:%[\da-f]{2})+/gi, (part) => {
|
|
255
|
+
try {
|
|
256
|
+
return decodeURIComponent(part);
|
|
257
|
+
}
|
|
258
|
+
catch {
|
|
259
|
+
return part.replace(/%([\da-f]{2})/gi, (encodedByte, hex) => {
|
|
260
|
+
const byte = Number.parseInt(hex, 16);
|
|
261
|
+
return byte < 128 ? String.fromCharCode(byte) : encodedByte;
|
|
262
|
+
});
|
|
263
|
+
}
|
|
264
|
+
});
|
|
265
|
+
}
|
|
266
|
+
}
|
|
267
|
+
function applyMatcher(text, matcher) {
|
|
268
|
+
if (!matcher.size)
|
|
269
|
+
return text;
|
|
270
|
+
// ASCII cannot grow under NFC/case folding; without escapes, a shorter field
|
|
271
|
+
// cannot contain any needle. Keep decoding and Unicode checks on the full path.
|
|
272
|
+
if (text.length < matcher.minimumLength && !text.includes("%") && !/[\u0080-\uffff]/.test(text))
|
|
273
|
+
return text;
|
|
274
|
+
const cached = matcher.cache.get(text);
|
|
275
|
+
if (cached !== undefined)
|
|
276
|
+
return cached;
|
|
277
|
+
const matchers = [matcher];
|
|
278
|
+
const direct = replaceMatches(text, matchers);
|
|
279
|
+
let result = direct;
|
|
280
|
+
let normalized = direct;
|
|
281
|
+
for (let round = 0; round < 3 && normalized.includes("%"); round++) {
|
|
282
|
+
const decoded = decodePercent(normalized);
|
|
283
|
+
if (decoded === normalized)
|
|
284
|
+
break;
|
|
285
|
+
normalized = decoded;
|
|
286
|
+
if (replaceMatches(normalized, [matcher.encoded ?? matcher], true) !== normalized) {
|
|
287
|
+
result = REDACTED_QUERY_VALUE;
|
|
288
|
+
}
|
|
289
|
+
}
|
|
290
|
+
// A residual escape is unresolved after the fixed work budget: emit less,
|
|
291
|
+
// if this nonempty registry can match percent-encoded credentials, even when
|
|
292
|
+
// another representation matched. Both independent roles use this.
|
|
293
|
+
if (matcher.canMatchPercentEncoded && /%[\da-f]{2}/i.test(normalized))
|
|
294
|
+
result = REDACTION_FAILED;
|
|
295
|
+
const nfc = normalized.normalize("NFC");
|
|
296
|
+
if (result !== REDACTION_FAILED &&
|
|
297
|
+
nfc !== normalized &&
|
|
298
|
+
replaceMatches(nfc, [matcher.encoded ?? matcher], true) !== nfc)
|
|
299
|
+
result = REDACTED_QUERY_VALUE;
|
|
300
|
+
// Matchers are immutable; additions compile a new request matcher. Independent
|
|
301
|
+
// request-local caches reuse results across repeated span/resource exports. Bound
|
|
302
|
+
// entry count and input size; process-static lookup data never caches request text.
|
|
303
|
+
if (text.length <= 4096) {
|
|
304
|
+
if (matcher.cache.size >= 256)
|
|
305
|
+
matcher.cache.clear();
|
|
306
|
+
matcher.cache.set(text, result);
|
|
307
|
+
}
|
|
308
|
+
return result;
|
|
309
|
+
}
|
|
310
|
+
function applyMatchers(text, matchers) {
|
|
311
|
+
let result = text;
|
|
312
|
+
for (const matcher of matchers) {
|
|
313
|
+
const candidate = applyMatcher(text, matcher);
|
|
314
|
+
if (candidate === text)
|
|
315
|
+
continue;
|
|
316
|
+
// Static and request secrets may overlap. Scan original text independently
|
|
317
|
+
// so an earlier replacement cannot hide the rest of a longer credential.
|
|
318
|
+
if (result !== text && result !== candidate)
|
|
319
|
+
return REDACTED_QUERY_VALUE;
|
|
320
|
+
result = candidate;
|
|
321
|
+
}
|
|
322
|
+
return result;
|
|
323
|
+
}
|
|
324
|
+
/** One small mutable registry per request, composed with precompiled process-static values. */
|
|
325
|
+
export function createDiagnosticRedactor(values = [], staticValues) {
|
|
326
|
+
const compiled = staticValues ? compiledValues.get(staticValues) : undefined;
|
|
327
|
+
// Share immutable lookup data only. Raw diagnostic cache keys die with this scope.
|
|
328
|
+
const requestMatcher = (matcher) => ({ ...matcher, cache: new Map() });
|
|
329
|
+
const staticPrimary = compiled?.primary.size ? requestMatcher(compiled.primary) : undefined;
|
|
330
|
+
const staticCheck = compiled?.check.size ? requestMatcher(compiled.check) : undefined;
|
|
331
|
+
const staticCriticalPrimary = compiled?.criticalPrimary.size
|
|
332
|
+
? compiled.criticalPrimary === compiled.primary
|
|
333
|
+
? staticPrimary
|
|
334
|
+
: requestMatcher(compiled.criticalPrimary)
|
|
335
|
+
: undefined;
|
|
336
|
+
const staticCriticalCheck = compiled?.criticalCheck.size
|
|
337
|
+
? compiled.criticalCheck === compiled.check
|
|
338
|
+
? staticCheck
|
|
339
|
+
: requestMatcher(compiled.criticalCheck)
|
|
340
|
+
: undefined;
|
|
341
|
+
const known = new Set();
|
|
342
|
+
const fallback = staticValues === undefined ? undefined : processCompositions.get(staticValues);
|
|
343
|
+
const has = (value) => known.has(value) ||
|
|
344
|
+
compiled?.values.has(value) === true ||
|
|
345
|
+
fallback?.values.has(value) === true;
|
|
346
|
+
let seenProcessVersion = -1;
|
|
347
|
+
let fallbackPrimary = [];
|
|
348
|
+
let fallbackCheck = [];
|
|
349
|
+
let fallbackCriticalPrimary = [];
|
|
350
|
+
let fallbackCriticalCheck = [];
|
|
351
|
+
let requestPrimary;
|
|
352
|
+
let requestCheck;
|
|
353
|
+
let suppressed = false;
|
|
354
|
+
let primary = staticPrimary ? [staticPrimary] : [];
|
|
355
|
+
let check = staticCheck ? [staticCheck] : [];
|
|
356
|
+
let criticalPrimary = staticCriticalPrimary ? [staticCriticalPrimary] : [];
|
|
357
|
+
let criticalCheck = staticCriticalCheck ? [staticCriticalCheck] : [];
|
|
358
|
+
const variants = [];
|
|
359
|
+
let uncompiled = [];
|
|
360
|
+
const add = (incoming) => {
|
|
361
|
+
for (const value of incoming) {
|
|
362
|
+
if (value.length < MINIMUM_REGISTERED_VALUE_LENGTH || has(value))
|
|
363
|
+
continue;
|
|
364
|
+
known.add(value);
|
|
365
|
+
uncompiled.push(value);
|
|
366
|
+
}
|
|
367
|
+
};
|
|
368
|
+
const ensureCompiled = () => {
|
|
369
|
+
const processChanged = fallback !== undefined && seenProcessVersion !== fallback.version;
|
|
370
|
+
if (!uncompiled.length && !processChanged)
|
|
371
|
+
return;
|
|
372
|
+
if (processChanged) {
|
|
373
|
+
if (fallback.compiledVersion !== fallback.version) {
|
|
374
|
+
fallback.compiled = compileDiagnosticSensitiveValues([...fallback.values]);
|
|
375
|
+
fallback.compiledVersion = fallback.version;
|
|
376
|
+
}
|
|
377
|
+
const compiledFallback = fallback.compiled && compiledValues.get(fallback.compiled);
|
|
378
|
+
fallbackPrimary = compiledFallback?.primary.size
|
|
379
|
+
? [requestMatcher(compiledFallback.primary)]
|
|
380
|
+
: [];
|
|
381
|
+
fallbackCheck = compiledFallback?.check.size ? [requestMatcher(compiledFallback.check)] : [];
|
|
382
|
+
fallbackCriticalPrimary = compiledFallback?.criticalPrimary.size
|
|
383
|
+
? [requestMatcher(compiledFallback.criticalPrimary)]
|
|
384
|
+
: [];
|
|
385
|
+
fallbackCriticalCheck = compiledFallback?.criticalCheck.size
|
|
386
|
+
? [requestMatcher(compiledFallback.criticalCheck)]
|
|
387
|
+
: [];
|
|
388
|
+
seenProcessVersion = fallback.version;
|
|
389
|
+
}
|
|
390
|
+
if (uncompiled.length) {
|
|
391
|
+
// Generate each value's variants once, lazily on the first actual match.
|
|
392
|
+
variants.push(...allSensitiveValueVariants(uncompiled));
|
|
393
|
+
uncompiled = [];
|
|
394
|
+
requestPrimary = compile(variants);
|
|
395
|
+
requestCheck = compile(variants);
|
|
396
|
+
}
|
|
397
|
+
primary = [
|
|
398
|
+
...(staticPrimary ? [staticPrimary] : []),
|
|
399
|
+
...fallbackPrimary,
|
|
400
|
+
...(requestPrimary ? [requestPrimary] : []),
|
|
401
|
+
];
|
|
402
|
+
check = [
|
|
403
|
+
...(staticCheck ? [staticCheck] : []),
|
|
404
|
+
...fallbackCheck,
|
|
405
|
+
...(requestCheck ? [requestCheck] : []),
|
|
406
|
+
];
|
|
407
|
+
criticalPrimary = [
|
|
408
|
+
...(staticCriticalPrimary ? [staticCriticalPrimary] : []),
|
|
409
|
+
...fallbackCriticalPrimary,
|
|
410
|
+
...(requestPrimary ? [requestPrimary.encoded ?? requestPrimary] : []),
|
|
411
|
+
];
|
|
412
|
+
criticalCheck = [
|
|
413
|
+
...(staticCriticalCheck ? [staticCriticalCheck] : []),
|
|
414
|
+
...fallbackCriticalCheck,
|
|
415
|
+
...(requestCheck ? [requestCheck.encoded ?? requestCheck] : []),
|
|
416
|
+
];
|
|
417
|
+
};
|
|
418
|
+
add(values);
|
|
419
|
+
const protect = (callback, critical = false, freeText = !critical) => (text) => {
|
|
420
|
+
if (text === REDACTED_QUERY_VALUE || text === REDACTION_FAILED)
|
|
421
|
+
return text;
|
|
422
|
+
if ((suppressed || fallback?.suppressed) && freeText)
|
|
423
|
+
return REDACTION_FAILED;
|
|
424
|
+
ensureCompiled();
|
|
425
|
+
const result = redactDiagnosticText(text, callback);
|
|
426
|
+
ensureCompiled(); // A replaced callback may register a value during the call.
|
|
427
|
+
if ((suppressed || fallback?.suppressed) && freeText)
|
|
428
|
+
return REDACTION_FAILED;
|
|
429
|
+
// This private matcher is a separate object from the callback's matcher,
|
|
430
|
+
// survives callback replacement, and sees additions made after trace creation.
|
|
431
|
+
return applyMatchers(result, critical ? criticalCheck : check) === result
|
|
432
|
+
? result
|
|
433
|
+
: REDACTION_FAILED;
|
|
434
|
+
};
|
|
435
|
+
let safeRedact = protect((text) => applyMatchers(text, primary));
|
|
436
|
+
let safeCritical = protect((text) => applyMatchers(text, criticalPrimary), true);
|
|
437
|
+
let safeStructured = protect((text) => applyMatchers(text, primary), false, false);
|
|
438
|
+
const critical = (text) => safeCritical(text);
|
|
439
|
+
const structured = (text) => safeStructured(text);
|
|
440
|
+
const isSuppressed = () => suppressed || fallback?.suppressed === true;
|
|
441
|
+
bindCriticalDiagnosticRedactor(safeRedact, critical, structured, isSuppressed);
|
|
442
|
+
return {
|
|
443
|
+
add,
|
|
444
|
+
has,
|
|
445
|
+
redactCritical: critical,
|
|
446
|
+
redactStructured: structured,
|
|
447
|
+
get suppressed() {
|
|
448
|
+
return isSuppressed();
|
|
449
|
+
},
|
|
450
|
+
suppress() {
|
|
451
|
+
suppressed = true;
|
|
452
|
+
},
|
|
453
|
+
get redact() {
|
|
454
|
+
return safeRedact;
|
|
455
|
+
},
|
|
456
|
+
set redact(callback) {
|
|
457
|
+
safeRedact = protect(callback);
|
|
458
|
+
safeCritical = protect(callback, true);
|
|
459
|
+
safeStructured = protect(callback, false, false);
|
|
460
|
+
bindCriticalDiagnosticRedactor(safeRedact, critical, structured, isSuppressed);
|
|
461
|
+
},
|
|
462
|
+
};
|
|
463
|
+
}
|
|
464
|
+
const requestRegistries = new WeakMap();
|
|
465
|
+
/** Internal binding; neither the registry nor its values enter provider-facing context types. */
|
|
466
|
+
export function bindDiagnosticSensitiveRegistry(trace, registry) {
|
|
467
|
+
requestRegistries.set(trace, registry);
|
|
468
|
+
}
|
|
469
|
+
export function registerDiagnosticSensitiveValues(trace, values) {
|
|
470
|
+
requestRegistries.get(trace)?.add(values);
|
|
471
|
+
}
|
|
472
|
+
// Policy metadata is internal: public callbacks remain backward-compatible unary functions.
|
|
473
|
+
const criticalRedactors = new WeakMap();
|
|
474
|
+
const structuredRedactors = new WeakMap();
|
|
475
|
+
const redactionSuppression = new WeakMap();
|
|
476
|
+
export function bindCriticalDiagnosticRedactor(redact, critical, structured, isSuppressed) {
|
|
477
|
+
criticalRedactors.set(redact, critical);
|
|
478
|
+
if (structured)
|
|
479
|
+
structuredRedactors.set(redact, structured);
|
|
480
|
+
if (isSuppressed)
|
|
481
|
+
redactionSuppression.set(redact, isSuppressed);
|
|
482
|
+
}
|
|
483
|
+
export function isDiagnosticRedactionSuppressed(redact) {
|
|
484
|
+
return redact ? redactionSuppression.get(redact)?.() === true : false;
|
|
485
|
+
}
|
|
486
|
+
/** Typed values and keys still match known credentials, but never blanket suppression. */
|
|
487
|
+
export function diagnosticStructuredRedactor(redact) {
|
|
488
|
+
return redact ? (structuredRedactors.get(redact) ?? redact) : undefined;
|
|
489
|
+
}
|
|
490
|
+
export function redactDiagnosticAttributeKey(key, redact) {
|
|
491
|
+
return redactDiagnosticText(key, diagnosticStructuredRedactor(diagnosticAttributeRedactor(key, redact)));
|
|
492
|
+
}
|
|
493
|
+
export function redactCriticalDiagnosticText(text, redact) {
|
|
494
|
+
return redactDiagnosticText(text, redact ? (criticalRedactors.get(redact) ?? redact) : undefined);
|
|
495
|
+
}
|
|
496
|
+
/**
|
|
497
|
+
* The redactor for one attribute value. A value its producer declares as a closed-enum literal for
|
|
498
|
+
* this key is a contract, like a typed number: exhaustion suppression skips it, while registered
|
|
499
|
+
* credentials still match. Any other value under the same key stays free text.
|
|
500
|
+
*/
|
|
501
|
+
export function diagnosticAttributeRedactor(key, redact, value) {
|
|
502
|
+
if (typeof value === "string" && CLOSED_ENUM_ATTRIBUTE_VALUES.get(key)?.has(value)) {
|
|
503
|
+
return diagnosticStructuredRedactor(redact);
|
|
504
|
+
}
|
|
505
|
+
return CRITICAL_ATTRIBUTE_KEYS.has(key) && redact
|
|
506
|
+
? (criticalRedactors.get(redact) ?? redact)
|
|
507
|
+
: redact;
|
|
508
|
+
}
|
|
509
|
+
// Structured debugging contracts use only >=8-character values. Other attributes are free text.
|
|
510
|
+
const CRITICAL_ATTRIBUTE_KEYS = new Set([
|
|
511
|
+
"request_id",
|
|
512
|
+
"requestId",
|
|
513
|
+
"trace_id",
|
|
514
|
+
"traceId",
|
|
515
|
+
"span_id",
|
|
516
|
+
"spanId",
|
|
517
|
+
"route",
|
|
518
|
+
"operation_id",
|
|
519
|
+
"operation",
|
|
520
|
+
"http.status_code",
|
|
521
|
+
]);
|
|
522
|
+
// SDK-owned closed enums are contracts, like typed numbers and booleans. The table is the
|
|
523
|
+
// producers' own declaration of which span attributes are closed enums and of every literal each
|
|
524
|
+
// one can carry; it exempts only exhaustion suppression, and registered credentials still match.
|
|
525
|
+
const CLOSED_ENUM_ATTRIBUTE_VALUES = new Map(Object.entries(RESOLVER_CLOSED_ENUM_SPAN_ATTRIBUTES).map(([key, values]) => [
|
|
526
|
+
key,
|
|
527
|
+
new Set(values),
|
|
528
|
+
]));
|
|
529
|
+
// Bigints normalize to strings for OTLP. Carry their type policy through internal
|
|
530
|
+
// detached copies without treating arbitrary numeric-looking free text as typed.
|
|
531
|
+
const bigintAttributes = new WeakMap();
|
|
532
|
+
export function isDiagnosticBigintAttribute(attributes, key) {
|
|
533
|
+
return bigintAttributes.get(attributes)?.has(key) === true;
|
|
534
|
+
}
|
|
535
|
+
export function copyDiagnosticAttributeTypes(source, target) {
|
|
536
|
+
const keys = Object.keys(source).filter((key) => (typeof source[key] === "bigint" || isDiagnosticBigintAttribute(source, key)) &&
|
|
537
|
+
String(source[key]) === target[key]);
|
|
538
|
+
if (keys.length)
|
|
539
|
+
bigintAttributes.set(target, new Set(keys));
|
|
540
|
+
return target;
|
|
541
|
+
}
|
|
542
|
+
/** Reserve existing keys so independently redacted names never drop an attribute. */
|
|
543
|
+
export function redactedKeyAllocator(keys) {
|
|
544
|
+
// Snapshot the inventory now, but allocate its lookup only if a key changes.
|
|
545
|
+
const inventory = [...keys];
|
|
546
|
+
let reserved;
|
|
547
|
+
let sequence = 0;
|
|
548
|
+
return () => {
|
|
549
|
+
reserved ??= new Set(inventory);
|
|
550
|
+
let key;
|
|
551
|
+
do {
|
|
552
|
+
key = `[REDACTED#${++sequence}]`;
|
|
553
|
+
} while (reserved.has(key));
|
|
554
|
+
reserved.add(key);
|
|
555
|
+
return key;
|
|
556
|
+
};
|
|
557
|
+
}
|
|
558
|
+
export function isRedactedKey(key) {
|
|
559
|
+
return /^\[REDACTED#\d+\]$/.test(key);
|
|
560
|
+
}
|
|
561
|
+
function markerLength(text, index) {
|
|
562
|
+
if (text[index] !== "[")
|
|
563
|
+
return 0;
|
|
564
|
+
if (text.startsWith(REDACTED_QUERY_VALUE, index))
|
|
565
|
+
return REDACTED_QUERY_VALUE.length;
|
|
566
|
+
if (text.startsWith(REDACTION_FAILED, index))
|
|
567
|
+
return REDACTION_FAILED.length;
|
|
568
|
+
if (text.startsWith("[REDACTED#", index))
|
|
569
|
+
return /^\[REDACTED#\d+\]/.exec(text.slice(index))?.[0].length ?? 0;
|
|
570
|
+
return 0;
|
|
571
|
+
}
|