@apifuse/provider-sdk 2.2.0-beta.5 → 2.2.0-beta.50
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 +537 -33
- package/CHANGELOG.md +201 -1
- package/README.md +83 -22
- package/SUBMISSION.md +2 -2
- package/bin/apifuse-check.ts +165 -11
- package/bin/apifuse-dev.ts +57 -13
- package/bin/apifuse-migrate-operation-declaration.ts +55 -0
- package/bin/apifuse-migrate-shape.ts +202 -0
- package/bin/apifuse-pack-check.ts +22 -2
- package/bin/apifuse-pack-smoke.ts +57 -2
- package/bin/apifuse-pack-types.ts +357 -38
- package/bin/apifuse-perf.ts +14 -13
- package/bin/apifuse-record.ts +709 -72
- package/bin/apifuse-submit-check.ts +2344 -324
- package/bin/apifuse-sync-assets.ts +117 -0
- 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 +27 -0
- package/dist/cli/create.d.ts +4 -1
- package/dist/cli/create.js +42 -37
- package/dist/cli/migrate-operation-declaration.d.ts +59 -0
- package/dist/cli/migrate-operation-declaration.js +1178 -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 +52 -0
- package/dist/cli/migrate-provider-shape.js +578 -0
- package/dist/cli/prompt-assets.d.ts +80 -0
- package/dist/cli/prompt-assets.js +743 -0
- package/dist/cli/templates/provider/AGENTS.md.tpl +17 -8
- package/dist/cli/templates/provider/Dockerfile.tpl +1 -1
- package/dist/cli/templates/provider/README.md.tpl +5 -5
- 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 +179 -16
- package/dist/config/loader.js +435 -127
- 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 +33 -0
- package/dist/declaration-validation.js +266 -0
- package/dist/define.d.ts +66 -29
- package/dist/define.js +778 -69
- package/dist/dev.d.ts +3 -0
- package/dist/dev.js +1 -1
- package/dist/engine.d.ts +78 -0
- package/dist/engine.js +133 -0
- package/dist/error-observability.d.ts +7 -0
- package/dist/error-observability.js +61 -0
- package/dist/error-resolution.d.ts +4 -0
- package/dist/error-resolution.js +122 -0
- package/dist/errors.d.ts +33 -0
- package/dist/errors.js +40 -0
- package/dist/fixture-sanitization.d.ts +28 -0
- package/dist/fixture-sanitization.js +227 -0
- package/dist/health-scenario.d.ts +1842 -0
- package/dist/health-scenario.js +624 -0
- package/dist/index.d.ts +21 -10
- package/dist/index.js +12 -7
- package/dist/lint.d.ts +23 -11
- package/dist/lint.js +572 -69
- 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 +10 -2
- package/dist/provider.js +4 -1
- package/dist/runtime/auth-flow.d.ts +5 -1
- package/dist/runtime/auth-flow.js +6 -0
- package/dist/runtime/browser.d.ts +1 -0
- package/dist/runtime/browser.js +492 -49
- package/dist/runtime/cache.d.ts +1 -0
- package/dist/runtime/cache.js +169 -15
- package/dist/runtime/choice-wordlist.d.ts +9 -0
- package/dist/runtime/choice-wordlist.js +138 -0
- package/dist/runtime/choice.d.ts +13 -1
- package/dist/runtime/choice.js +490 -102
- package/dist/runtime/chrome149-header-order.d.ts +58 -0
- package/dist/runtime/chrome149-header-order.js +289 -0
- package/dist/runtime/env.js +12 -0
- package/dist/runtime/executor.d.ts +3 -2
- package/dist/runtime/executor.js +26 -25
- package/dist/runtime/http.d.ts +1 -0
- package/dist/runtime/http.js +515 -53
- package/dist/runtime/insights.js +2 -2
- package/dist/runtime/instrumentation.d.ts +2 -2
- package/dist/runtime/instrumentation.js +366 -8
- 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 +96 -0
- package/dist/runtime/native-network.js +1232 -0
- package/dist/runtime/ocr.d.ts +29 -0
- package/dist/runtime/ocr.js +440 -0
- package/dist/runtime/otlp.d.ts +71 -2
- package/dist/runtime/otlp.js +397 -16
- package/dist/runtime/proxy-errors.js +6 -2
- package/dist/runtime/proxy-nodemaven.d.ts +56 -0
- package/dist/runtime/proxy-nodemaven.js +146 -0
- package/dist/runtime/proxy-telemetry.d.ts +80 -1
- package/dist/runtime/proxy-telemetry.js +154 -47
- package/dist/runtime/redirects.d.ts +29 -0
- package/dist/runtime/redirects.js +36 -0
- package/dist/runtime/redis.d.ts +1 -1
- package/dist/runtime/redis.js +4 -2
- package/dist/runtime/request-options.d.ts +68 -1
- package/dist/runtime/request-options.js +548 -0
- package/dist/runtime/resolver-config.d.ts +6 -0
- package/dist/runtime/resolver-config.js +6 -0
- package/dist/runtime/resolver-public.d.ts +1 -0
- package/dist/runtime/resolver-public.js +1 -0
- package/dist/runtime/resolver-shared.d.ts +14 -0
- package/dist/runtime/resolver-shared.js +12 -0
- package/dist/runtime/resolver-vendors/bindings.d.ts +48 -0
- package/dist/runtime/resolver-vendors/bindings.js +40 -0
- package/dist/runtime/resolver-vendors/browser.d.ts +22 -0
- package/dist/runtime/resolver-vendors/browser.js +377 -0
- package/dist/runtime/resolver-vendors/capsolver.d.ts +22 -0
- package/dist/runtime/resolver-vendors/capsolver.js +531 -0
- package/dist/runtime/resolver-vendors/hosts.d.ts +2 -0
- package/dist/runtime/resolver-vendors/hosts.js +33 -0
- package/dist/runtime/resolver-vendors/twocaptcha.d.ts +24 -0
- package/dist/runtime/resolver-vendors/twocaptcha.js +408 -0
- package/dist/runtime/resolver-vendors/types.d.ts +94 -0
- package/dist/runtime/resolver-vendors/types.js +96 -0
- package/dist/runtime/resolver.d.ts +72 -0
- package/dist/runtime/resolver.js +771 -0
- package/dist/runtime/secrets.d.ts +27 -0
- package/dist/runtime/secrets.js +51 -0
- package/dist/runtime/state.d.ts +3 -0
- package/dist/runtime/state.js +277 -71
- package/dist/runtime/stealth-cookies.d.ts +20 -0
- package/dist/runtime/stealth-cookies.js +111 -0
- package/dist/runtime/stealth.d.ts +41 -5
- package/dist/runtime/stealth.js +997 -291
- package/dist/runtime/stt.js +1 -12
- 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 +5 -0
- package/dist/runtime/trace.js +43 -10
- 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/index.d.ts +5 -2
- package/dist/server/index.js +2 -2
- 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.d.ts +14 -3
- package/dist/server/self-test.js +129 -58
- package/dist/server/serve-implementation.d.ts +230 -0
- package/dist/server/serve-implementation.js +2265 -0
- package/dist/server/serve.d.ts +1 -70
- package/dist/server/serve.js +1 -1131
- package/dist/server/trace-output.d.ts +6 -0
- package/dist/server/trace-output.js +79 -0
- package/dist/server/types.d.ts +30 -5
- package/dist/server/types.js +13 -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 +215 -0
- package/dist/stateful/stateful-provider-runtime-context.d.ts +32 -0
- package/dist/stateful/stateful-provider-runtime-context.js +60 -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 +9 -4
- package/dist/stealth/profiles.js +160 -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 +489 -21
- package/dist/trace-sanitization.d.ts +5 -0
- package/dist/trace-sanitization.js +45 -0
- package/dist/types.d.ts +673 -131
- package/dist/types.js +1 -0
- package/package.json +45 -5
- package/src/auth-turn/index.ts +1 -1
- package/src/auth.ts +118 -0
- package/src/ceremonies/index.ts +189 -46
- package/src/cli/__tests__/fixtures/migrate-operation-declaration/approval-override.ts.txt +6 -0
- package/src/cli/__tests__/fixtures/migrate-operation-declaration/codemod-syntax.ts.txt +3 -0
- package/src/cli/__tests__/fixtures/migrate-operation-declaration/connection-precedence.ts.txt +10 -0
- package/src/cli/__tests__/fixtures/migrate-operation-declaration/docs-conflict.ts.txt +8 -0
- package/src/cli/__tests__/fixtures/migrate-operation-declaration/examples-map.ts.txt +5 -0
- package/src/cli/__tests__/fixtures/migrate-operation-declaration/examples-operation.ts.txt +16 -0
- package/src/cli/__tests__/fixtures/migrate-operation-declaration/factory-map.ts.txt +3 -0
- package/src/cli/__tests__/fixtures/migrate-operation-declaration/hoist-all.ts.txt +31 -0
- package/src/cli/__tests__/fixtures/migrate-operation-declaration/hoisted-const.ts.txt +11 -0
- package/src/cli/__tests__/fixtures/migrate-operation-declaration/imported-spread.ts.txt +11 -0
- package/src/cli/__tests__/fixtures/migrate-operation-declaration/inline-map.ts.txt +11 -0
- package/src/cli/__tests__/fixtures/migrate-operation-declaration/inline-spread-cast-tail.ts.txt +21 -0
- package/src/cli/__tests__/fixtures/migrate-operation-declaration/inline-spread-ekitan.ts.txt +11 -0
- package/src/cli/__tests__/fixtures/migrate-operation-declaration/inline-spread-override.ts.txt +14 -0
- package/src/cli/__tests__/fixtures/migrate-operation-declaration/missing-english-locale.ts.txt +7 -0
- package/src/cli/__tests__/fixtures/migrate-operation-declaration/no-safety.ts.txt +6 -0
- package/src/cli/__tests__/fixtures/migrate-operation-declaration/non-literal.ts.txt +7 -0
- package/src/cli/__tests__/fixtures/migrate-operation-declaration/redundant-approval.ts.txt +6 -0
- package/src/cli/__tests__/fixtures/migrate-operation-declaration/safety-conflict.ts.txt +7 -0
- package/src/cli/__tests__/fixtures/migrate-operation-declaration/stream.ts.txt +7 -0
- package/src/cli/__tests__/fixtures/migrate-operation-declaration/tool-router-spread.ts.txt +15 -0
- package/src/cli/__tests__/fixtures/migrate-operation-declaration/unparseable.ts.txt +4 -0
- package/src/cli/__tests__/fixtures/migrate-operation-declaration/verbatim-template.ts.txt +12 -0
- package/src/cli/commands.ts +33 -0
- package/src/cli/create.ts +50 -37
- package/src/cli/migrate-operation-declaration.ts +1654 -0
- package/src/cli/migrate-operation-shape.ts +184 -0
- package/src/cli/migrate-provider-shape.ts +772 -0
- package/src/cli/prompt-assets.ts +865 -0
- package/src/cli/templates/provider/AGENTS.md.tpl +17 -8
- package/src/cli/templates/provider/Dockerfile.tpl +1 -1
- package/src/cli/templates/provider/README.md.tpl +5 -5
- 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 +690 -163
- 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 +330 -0
- package/src/define.ts +1048 -131
- package/src/dev.ts +4 -1
- package/src/engine.ts +279 -0
- package/src/error-observability.ts +64 -0
- package/src/error-resolution.ts +127 -0
- package/src/errors.ts +68 -0
- package/src/fixture-sanitization.ts +264 -0
- package/src/health-scenario.ts +875 -0
- package/src/index.ts +220 -13
- package/src/lint.ts +698 -90
- 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 +161 -3
- package/src/runtime/auth-flow.ts +12 -0
- package/src/runtime/browser.ts +661 -63
- package/src/runtime/cache.ts +189 -14
- package/src/runtime/choice-wordlist.ts +145 -0
- package/src/runtime/choice.ts +631 -120
- package/src/runtime/chrome149-header-order.ts +330 -0
- package/src/runtime/env.ts +13 -0
- package/src/runtime/executor.ts +43 -31
- package/src/runtime/http.ts +641 -61
- package/src/runtime/insights.ts +2 -2
- package/src/runtime/instrumentation.ts +520 -15
- package/src/runtime/native-network-errors.ts +99 -0
- package/src/runtime/native-network.ts +1605 -0
- package/src/runtime/ocr.ts +523 -0
- package/src/runtime/otlp.ts +467 -21
- package/src/runtime/proxy-errors.ts +12 -4
- package/src/runtime/proxy-nodemaven.ts +221 -0
- package/src/runtime/proxy-telemetry.ts +244 -75
- package/src/runtime/redirects.ts +66 -0
- package/src/runtime/redis.ts +7 -2
- package/src/runtime/request-options.ts +680 -1
- package/src/runtime/resolver-config.ts +6 -0
- package/src/runtime/resolver-public.ts +23 -0
- package/src/runtime/resolver-shared.ts +33 -0
- package/src/runtime/resolver-vendors/bindings.ts +56 -0
- package/src/runtime/resolver-vendors/browser.ts +533 -0
- package/src/runtime/resolver-vendors/capsolver.ts +707 -0
- package/src/runtime/resolver-vendors/hosts.ts +38 -0
- package/src/runtime/resolver-vendors/twocaptcha.ts +540 -0
- package/src/runtime/resolver-vendors/types.ts +212 -0
- package/src/runtime/resolver.ts +1157 -0
- package/src/runtime/secrets.ts +64 -0
- package/src/runtime/state.ts +394 -77
- package/src/runtime/stealth-cookies.ts +132 -0
- package/src/runtime/stealth.ts +1280 -336
- package/src/runtime/stt.ts +1 -19
- package/src/runtime/timeout.ts +18 -0
- package/src/runtime/trace-config.ts +78 -0
- package/src/runtime/trace.ts +57 -17
- package/src/serve.ts +6 -1
- package/src/server/error-observability.ts +1 -0
- package/src/server/index.ts +34 -2
- package/src/server/self-test-input-tokens.ts +29 -14
- package/src/server/self-test.ts +191 -68
- package/src/server/serve-implementation.ts +3378 -0
- package/src/server/serve.ts +1 -1632
- package/src/server/trace-output.ts +129 -0
- package/src/server/types.ts +13 -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 +287 -0
- package/src/stateful/stateful-provider-runtime-context.ts +92 -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 +202 -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 +658 -15
- package/src/trace-sanitization.ts +63 -0
- package/src/types.ts +788 -174
- package/dist/cli/templates/provider/CLAUDE.md.tpl +0 -1
- package/src/cli/templates/provider/CLAUDE.md.tpl +0 -1
- /package/dist/cli/templates/provider/{skills → .agents/skills}/fixtures-and-recording/SKILL.md.tpl +0 -0
- /package/dist/cli/templates/provider/{skills → .agents/skills}/health-checks-and-fail-closed/SKILL.md.tpl +0 -0
- /package/dist/cli/templates/provider/{skills → .agents/skills}/normalization-standards/SKILL.md.tpl +0 -0
- /package/dist/cli/templates/provider/{skills → .agents/skills}/pagination-and-counts/SKILL.md.tpl +0 -0
- /package/dist/cli/templates/provider/{skills → .agents/skills}/upstream-contract-verification/SKILL.md.tpl +0 -0
- /package/dist/cli/templates/provider/{skills → .agents/skills}/upstream-notes/README.md.tpl +0 -0
- /package/src/cli/templates/provider/{skills → .agents/skills}/fixtures-and-recording/SKILL.md.tpl +0 -0
- /package/src/cli/templates/provider/{skills → .agents/skills}/health-checks-and-fail-closed/SKILL.md.tpl +0 -0
- /package/src/cli/templates/provider/{skills → .agents/skills}/normalization-standards/SKILL.md.tpl +0 -0
- /package/src/cli/templates/provider/{skills → .agents/skills}/pagination-and-counts/SKILL.md.tpl +0 -0
- /package/src/cli/templates/provider/{skills → .agents/skills}/upstream-contract-verification/SKILL.md.tpl +0 -0
- /package/src/cli/templates/provider/{skills → .agents/skills}/upstream-notes/README.md.tpl +0 -0
|
@@ -0,0 +1,264 @@
|
|
|
1
|
+
import type { JsonValue } from "./contract-json.js";
|
|
2
|
+
|
|
3
|
+
export const REDACTED_FIXTURE_VALUE = "[REDACTED]";
|
|
4
|
+
|
|
5
|
+
const OPAQUE_TOKEN = /^[A-Za-z0-9_+/=.:~-]+$/;
|
|
6
|
+
const OPAQUE_TOKEN_RUN = /[A-Za-z0-9_+/=.:~-]{24,}/g;
|
|
7
|
+
const URL_RUN = /https?:\/\/[^\s"'<>]+/gi;
|
|
8
|
+
const EMAIL_ADDRESS_RUN = /\b[A-Z0-9._%+-]+@[A-Z0-9.-]+\.[A-Z]{2,}\b/gi;
|
|
9
|
+
const DIAGNOSTIC_URL_SENTINEL_DELIMITER = String.fromCodePoint(0);
|
|
10
|
+
const DIAGNOSTIC_URL_SENTINEL_RUN = new RegExp(
|
|
11
|
+
`${DIAGNOSTIC_URL_SENTINEL_DELIMITER}APIFUSE_URL(\\d+)${DIAGNOSTIC_URL_SENTINEL_DELIMITER}`,
|
|
12
|
+
"g",
|
|
13
|
+
);
|
|
14
|
+
const PEM_PRIVATE_KEY =
|
|
15
|
+
/-----BEGIN (?:[A-Z0-9 ]+ )?PRIVATE KEY-----[\s\S]*?-----END (?:[A-Z0-9 ]+ )?PRIVATE KEY-----/g;
|
|
16
|
+
|
|
17
|
+
/** Matches credential field names without treating benign prefixes such as `author` as `auth`. */
|
|
18
|
+
export function isSensitiveFixtureKey(key: string): boolean {
|
|
19
|
+
const normalized = key.replace(/[-_\s]/g, "").toLowerCase();
|
|
20
|
+
const candidates = [normalized, normalized.replace(/(?:value|payload|header)$/, "")];
|
|
21
|
+
return candidates.some(
|
|
22
|
+
(candidate) =>
|
|
23
|
+
/^(?:authorization|authentication|auth|bearer|cookie|credential|password|passwd|privatekey|secret|session|sessionid|token)$/.test(
|
|
24
|
+
candidate,
|
|
25
|
+
) ||
|
|
26
|
+
/^(?:api|client|service|access|consumer)(?:key|secret|token)$/.test(candidate) ||
|
|
27
|
+
/(?:authorization|credential|password|passwd|privatekey|secret|sessionid|token)$/.test(
|
|
28
|
+
candidate,
|
|
29
|
+
),
|
|
30
|
+
);
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
/**
|
|
34
|
+
* Returns JSON fixture data with credential-bearing keys and heuristic-confirmed string secrets
|
|
35
|
+
* replaced. Ordinary short prose and identifiers are retained.
|
|
36
|
+
*/
|
|
37
|
+
export function sanitizeFixture(value: JsonValue): JsonValue {
|
|
38
|
+
if (Array.isArray(value)) {
|
|
39
|
+
return value.map((item) => sanitizeFixture(item));
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
if (typeof value === "string") return sanitizeFixtureString(value);
|
|
43
|
+
if (value === null || typeof value !== "object") return value;
|
|
44
|
+
|
|
45
|
+
return Object.fromEntries(
|
|
46
|
+
Object.entries(value).map(([key, entryValue]) => [
|
|
47
|
+
key,
|
|
48
|
+
isSensitiveFixtureKey(key) ? REDACTED_FIXTURE_VALUE : sanitizeFixture(entryValue),
|
|
49
|
+
]),
|
|
50
|
+
);
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
/** Applies the shared credential-key policy to ordinary JSON fixtures. */
|
|
54
|
+
export function sanitizeOrdinaryFixture(value: JsonValue): JsonValue {
|
|
55
|
+
if (Array.isArray(value)) return value.map((item) => sanitizeOrdinaryFixture(item));
|
|
56
|
+
if (value === null || typeof value !== "object") return value;
|
|
57
|
+
return Object.fromEntries(
|
|
58
|
+
Object.entries(value).map(([key, entryValue]) => [
|
|
59
|
+
key,
|
|
60
|
+
isSensitiveFixtureKey(key) ? REDACTED_FIXTURE_VALUE : sanitizeOrdinaryFixture(entryValue),
|
|
61
|
+
]),
|
|
62
|
+
);
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
/** Sanitizes a primitive fixture string only when textual-secret heuristics match. */
|
|
66
|
+
export function sanitizeFixtureString(value: string): string {
|
|
67
|
+
let sanitized = value.replace(PEM_PRIVATE_KEY, REDACTED_FIXTURE_VALUE);
|
|
68
|
+
const retainedUrls: string[] = [];
|
|
69
|
+
sanitized = sanitized.replace(URL_RUN, (url) => {
|
|
70
|
+
const index =
|
|
71
|
+
retainedUrls.push(isCredentialBearingUrl(url) ? sanitizeUrlForLogs(url) : url) - 1;
|
|
72
|
+
return `APIFUSEURL${index}X`;
|
|
73
|
+
});
|
|
74
|
+
sanitized = redactSensitiveAssignments(sanitized);
|
|
75
|
+
sanitized = sanitized.replace(OPAQUE_TOKEN_RUN, (candidate) =>
|
|
76
|
+
isSensitiveFixtureValue(candidate) ? REDACTED_FIXTURE_VALUE : candidate,
|
|
77
|
+
);
|
|
78
|
+
sanitized = sanitized.replace(
|
|
79
|
+
/APIFUSEURL(\d+)X/g,
|
|
80
|
+
(_match, index: string) => retainedUrls[Number(index)] ?? REDACTED_FIXTURE_VALUE,
|
|
81
|
+
);
|
|
82
|
+
return sanitized;
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
/** True for opaque values that are unsafe to retain in paths or unstructured text. */
|
|
86
|
+
export function isSensitiveFixtureValue(value: string): boolean {
|
|
87
|
+
const candidate = decodePathSegment(value);
|
|
88
|
+
if (/^bot(?:\d{6,}:)?[A-Za-z0-9_-]{16,}$/i.test(candidate)) return true;
|
|
89
|
+
if (/^\d{6,}:[A-Za-z0-9_-]{20,}$/.test(candidate)) return true;
|
|
90
|
+
if (/^(?:gh[opusr]_|sk[-_]|xox[baprs]-)[A-Za-z0-9_-]{16,}$/i.test(candidate)) return true;
|
|
91
|
+
if (!OPAQUE_TOKEN.test(candidate) || candidate.length < 24) return false;
|
|
92
|
+
if (/^[a-f0-9]{32,}$/i.test(candidate)) return true;
|
|
93
|
+
return shannonEntropy(candidate) >= 3.5;
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
/** Sanitizes every path segment and values following a credential-like segment name. */
|
|
97
|
+
export function sanitizePathname(pathname: string): string {
|
|
98
|
+
const segments = pathname.split("/");
|
|
99
|
+
return segments
|
|
100
|
+
.map((segment, index) => {
|
|
101
|
+
if (!segment) return segment;
|
|
102
|
+
const decoded = decodePathSegment(segment);
|
|
103
|
+
const previous = index > 0 ? decodePathSegment(segments[index - 1] as string) : "";
|
|
104
|
+
if (
|
|
105
|
+
isSensitivePathSegment(decoded) ||
|
|
106
|
+
isCredentialPathKey(previous) ||
|
|
107
|
+
isSensitiveFixtureValue(decoded)
|
|
108
|
+
) {
|
|
109
|
+
return REDACTED_FIXTURE_VALUE;
|
|
110
|
+
}
|
|
111
|
+
return segment;
|
|
112
|
+
})
|
|
113
|
+
.join("/");
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
function isCredentialPathKey(key: string): boolean {
|
|
117
|
+
const finalPathPart = key.split("/").at(-1) ?? "";
|
|
118
|
+
const baseSegment = finalPathPart.split(";", 1)[0] ?? "";
|
|
119
|
+
return isSensitiveFixtureKey(baseSegment.split(/[=:]/, 1)[0] ?? "");
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
function isSensitivePathSegment(segment: string): boolean {
|
|
123
|
+
return segment
|
|
124
|
+
.split(/[;/]/)
|
|
125
|
+
.some((part) => isSensitiveFixtureKey(part.split(/[=:]/, 1)[0] ?? ""));
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
/** Removes userinfo, query values, fragments, and credential-like path segments from log URLs. */
|
|
129
|
+
export function sanitizeUrlForLogs(value: string): string {
|
|
130
|
+
try {
|
|
131
|
+
const parsed = new URL(value, "https://fixture.invalid");
|
|
132
|
+
const queryMarker = parsed.search ? `?${REDACTED_FIXTURE_VALUE}` : "";
|
|
133
|
+
const path = sanitizePathname(parsed.pathname);
|
|
134
|
+
if (parsed.origin === "https://fixture.invalid" && !hasExplicitOrigin(value)) {
|
|
135
|
+
return `${path}${queryMarker}`;
|
|
136
|
+
}
|
|
137
|
+
return `${parsed.origin}${path}${queryMarker}`;
|
|
138
|
+
} catch {
|
|
139
|
+
return sanitizePathname(value.split(/[?#]/, 1)[0]);
|
|
140
|
+
}
|
|
141
|
+
}
|
|
142
|
+
|
|
143
|
+
/**
|
|
144
|
+
* Returns query-free request provenance with each path segment scrubbed for credential-like values.
|
|
145
|
+
* Origins, URL userinfo, query values, and fragments are never persisted in request provenance.
|
|
146
|
+
*/
|
|
147
|
+
export function requestPathForFixture(value: string): string {
|
|
148
|
+
try {
|
|
149
|
+
return sanitizePathname(new URL(value, "https://fixture.invalid").pathname);
|
|
150
|
+
} catch {
|
|
151
|
+
const path = value.split(/[?#]/, 1)[0];
|
|
152
|
+
return sanitizePathname(path.startsWith("/") ? path : `/${path}`);
|
|
153
|
+
}
|
|
154
|
+
}
|
|
155
|
+
|
|
156
|
+
/** Scrubs secrets and terminal/log control characters before diagnostic text is emitted. */
|
|
157
|
+
export function sanitizeDiagnosticText(value: string): string {
|
|
158
|
+
const retainedUrls: string[] = [];
|
|
159
|
+
// Remove attacker-controlled NUL delimiters before introducing internal URL sentinels.
|
|
160
|
+
let sanitized = encodeDiagnosticControls(value)
|
|
161
|
+
.replace(URL_RUN, (url) => {
|
|
162
|
+
const index = retainedUrls.push(sanitizeUrlForLogs(url)) - 1;
|
|
163
|
+
return `${DIAGNOSTIC_URL_SENTINEL_DELIMITER}APIFUSE_URL${index}${DIAGNOSTIC_URL_SENTINEL_DELIMITER}`;
|
|
164
|
+
})
|
|
165
|
+
.replace(/\bBearer\s+[A-Za-z0-9._~+/=-]+/gi, `Bearer ${REDACTED_FIXTURE_VALUE}`)
|
|
166
|
+
.replace(EMAIL_ADDRESS_RUN, REDACTED_FIXTURE_VALUE);
|
|
167
|
+
sanitized = redactSensitiveAssignments(sanitized);
|
|
168
|
+
sanitized = sanitized.replace(OPAQUE_TOKEN_RUN, (candidate, offset: number, source: string) => {
|
|
169
|
+
if (/^(?:request|trace|correlation)[-_]?id[:=]/i.test(candidate)) return candidate;
|
|
170
|
+
const prefix = source.slice(Math.max(0, offset - 32), offset);
|
|
171
|
+
if (/(?:request|trace|correlation)[-_]?id\s*[:=]\s*$/i.test(prefix)) return candidate;
|
|
172
|
+
return isSensitiveFixtureValue(candidate) ? REDACTED_FIXTURE_VALUE : candidate;
|
|
173
|
+
});
|
|
174
|
+
sanitized = sanitized.replace(
|
|
175
|
+
DIAGNOSTIC_URL_SENTINEL_RUN,
|
|
176
|
+
(_match, index: string) => retainedUrls[Number(index)] ?? REDACTED_FIXTURE_VALUE,
|
|
177
|
+
);
|
|
178
|
+
return encodeDiagnosticControls(sanitized);
|
|
179
|
+
}
|
|
180
|
+
|
|
181
|
+
function redactSensitiveAssignments(value: string): string {
|
|
182
|
+
return value.replace(
|
|
183
|
+
/((["']?)([\w-]+)\2\s*[:=]\s*)("(?:\\.|[^"\\])*"|'(?:\\.|[^'\\])*'|[^\s,;&]+)/gi,
|
|
184
|
+
(match, prefix: string, _quote: string, key: string, assignmentValue: string) => {
|
|
185
|
+
if (!isSensitiveFixtureKey(key) && key.toLowerCase() !== "key") return match;
|
|
186
|
+
const quote = assignmentValue.startsWith('"')
|
|
187
|
+
? '"'
|
|
188
|
+
: assignmentValue.startsWith("'")
|
|
189
|
+
? "'"
|
|
190
|
+
: "";
|
|
191
|
+
return `${prefix}${quote}${REDACTED_FIXTURE_VALUE}${quote}`;
|
|
192
|
+
},
|
|
193
|
+
);
|
|
194
|
+
}
|
|
195
|
+
|
|
196
|
+
function isCredentialBearingUrl(value: string): boolean {
|
|
197
|
+
try {
|
|
198
|
+
const parsed = new URL(value);
|
|
199
|
+
return (
|
|
200
|
+
parsed.username !== "" ||
|
|
201
|
+
parsed.password !== "" ||
|
|
202
|
+
parsed.hash !== "" ||
|
|
203
|
+
parsed.search !== "" ||
|
|
204
|
+
parsed.pathname.split("/").some((segment, index, segments) => {
|
|
205
|
+
const decoded = decodePathSegment(segment);
|
|
206
|
+
const previous = decodePathSegment(segments[index - 1] ?? "");
|
|
207
|
+
return (
|
|
208
|
+
isSensitiveFixtureKey(decoded) ||
|
|
209
|
+
isCredentialPathKey(previous) ||
|
|
210
|
+
isSensitiveFixtureValue(decoded)
|
|
211
|
+
);
|
|
212
|
+
})
|
|
213
|
+
);
|
|
214
|
+
} catch {
|
|
215
|
+
return false;
|
|
216
|
+
}
|
|
217
|
+
}
|
|
218
|
+
|
|
219
|
+
/** Encodes terminal/log control characters without applying value-level secret heuristics. */
|
|
220
|
+
export function encodeDiagnosticControls(value: string): string {
|
|
221
|
+
let result = "";
|
|
222
|
+
for (const character of value) {
|
|
223
|
+
const code = character.codePointAt(0) ?? 0;
|
|
224
|
+
if (code === 0x0a || code === 0x0d || code === 0x2028 || code === 0x2029) {
|
|
225
|
+
result += " ";
|
|
226
|
+
} else if (
|
|
227
|
+
(code >= 0 && code <= 0x1f) ||
|
|
228
|
+
(code >= 0x7f && code <= 0x9f) ||
|
|
229
|
+
code === 0x061c ||
|
|
230
|
+
code === 0x200e ||
|
|
231
|
+
code === 0x200f ||
|
|
232
|
+
(code >= 0x202a && code <= 0x202e) ||
|
|
233
|
+
(code >= 0x2066 && code <= 0x2069)
|
|
234
|
+
) {
|
|
235
|
+
result += `\\u${code.toString(16).padStart(4, "0")}`;
|
|
236
|
+
} else {
|
|
237
|
+
result += character;
|
|
238
|
+
}
|
|
239
|
+
}
|
|
240
|
+
return result;
|
|
241
|
+
}
|
|
242
|
+
|
|
243
|
+
function decodePathSegment(value: string): string {
|
|
244
|
+
try {
|
|
245
|
+
return decodeURIComponent(value);
|
|
246
|
+
} catch {
|
|
247
|
+
return value;
|
|
248
|
+
}
|
|
249
|
+
}
|
|
250
|
+
|
|
251
|
+
function hasExplicitOrigin(value: string): boolean {
|
|
252
|
+
return /^[a-z][a-z\d+.-]*:\/\//i.test(value);
|
|
253
|
+
}
|
|
254
|
+
|
|
255
|
+
function shannonEntropy(value: string): number {
|
|
256
|
+
const counts = new Map<string, number>();
|
|
257
|
+
for (const character of value) counts.set(character, (counts.get(character) ?? 0) + 1);
|
|
258
|
+
let entropy = 0;
|
|
259
|
+
for (const count of counts.values()) {
|
|
260
|
+
const probability = count / value.length;
|
|
261
|
+
entropy -= probability * Math.log2(probability);
|
|
262
|
+
}
|
|
263
|
+
return entropy;
|
|
264
|
+
}
|