@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
|
@@ -54,15 +54,11 @@ function isZodSchema(schema) {
|
|
|
54
54
|
return schema instanceof z.ZodType;
|
|
55
55
|
}
|
|
56
56
|
function zodJsonSchema(schema) {
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
}
|
|
61
|
-
catch (error) {
|
|
62
|
-
if (error instanceof Error)
|
|
63
|
-
return undefined;
|
|
64
|
-
throw error;
|
|
57
|
+
const jsonSchema = toJsonValue(z.toJSONSchema(schema));
|
|
58
|
+
if (jsonSchema === undefined) {
|
|
59
|
+
throw new TypeError("z.toJSONSchema() returned a non-JSON value");
|
|
65
60
|
}
|
|
61
|
+
return jsonSchema;
|
|
66
62
|
}
|
|
67
63
|
function getSchemaTypeName(schema) {
|
|
68
64
|
if (!isRecord(schema))
|
package/dist/contract-types.d.ts
CHANGED
|
@@ -11,6 +11,7 @@ export interface ProviderContractSnapshot {
|
|
|
11
11
|
readonly allowedHosts?: readonly string[];
|
|
12
12
|
readonly stealth?: JsonValue;
|
|
13
13
|
readonly proxy?: JsonValue;
|
|
14
|
+
readonly ocr?: JsonValue;
|
|
14
15
|
readonly stt?: JsonValue;
|
|
15
16
|
readonly browser?: JsonValue;
|
|
16
17
|
readonly auth?: JsonValue;
|
|
@@ -26,17 +27,23 @@ export interface ProviderContractSnapshot {
|
|
|
26
27
|
}
|
|
27
28
|
export interface ProviderContractOperation {
|
|
28
29
|
readonly id: string;
|
|
30
|
+
readonly connectionMode?: JsonValue;
|
|
31
|
+
readonly connectionExternalRefParam?: JsonValue;
|
|
32
|
+
readonly riskClass: JsonValue;
|
|
33
|
+
readonly approval?: JsonValue;
|
|
34
|
+
readonly timeoutMs?: JsonValue;
|
|
35
|
+
readonly titleKey?: JsonValue;
|
|
29
36
|
readonly descriptionKey?: JsonValue;
|
|
30
|
-
readonly
|
|
37
|
+
readonly summaryKey?: JsonValue;
|
|
38
|
+
readonly markdownKey?: JsonValue;
|
|
31
39
|
readonly whenToUseKeys?: JsonValue;
|
|
32
40
|
readonly whenNotToUseKeys?: JsonValue;
|
|
33
|
-
readonly
|
|
34
|
-
readonly
|
|
35
|
-
readonly
|
|
41
|
+
readonly normalizationNotesKeys?: JsonValue;
|
|
42
|
+
readonly errorCodes?: JsonValue;
|
|
43
|
+
readonly examples?: JsonValue;
|
|
36
44
|
readonly contract?: JsonValue;
|
|
37
45
|
readonly tags?: JsonValue;
|
|
38
46
|
readonly relatedOperations?: JsonValue;
|
|
39
|
-
readonly toolRouter?: JsonValue;
|
|
40
47
|
readonly observability?: JsonValue;
|
|
41
48
|
readonly transport?: JsonValue;
|
|
42
49
|
readonly inputSchema: JsonValue;
|
package/dist/contract.js
CHANGED
|
@@ -7,6 +7,7 @@ export function extractProviderContract(provider) {
|
|
|
7
7
|
const auth = extractAuth(provider.auth);
|
|
8
8
|
const stealth = toJsonValue(provider.stealth);
|
|
9
9
|
const proxy = toJsonValue(provider.proxy);
|
|
10
|
+
const ocr = toJsonValue(provider.ocr);
|
|
10
11
|
const stt = toJsonValue(provider.stt);
|
|
11
12
|
const browser = toJsonValue(provider.browser);
|
|
12
13
|
const reviewed = toJsonValue(provider.reviewed);
|
|
@@ -30,6 +31,7 @@ export function extractProviderContract(provider) {
|
|
|
30
31
|
...(provider.allowedHosts ? { allowedHosts: [...provider.allowedHosts].sort() } : {}),
|
|
31
32
|
...(stealth === undefined ? {} : { stealth }),
|
|
32
33
|
...(proxy === undefined ? {} : { proxy }),
|
|
34
|
+
...(ocr === undefined ? {} : { ocr }),
|
|
33
35
|
...(stt === undefined ? {} : { stt }),
|
|
34
36
|
...(browser === undefined ? {} : { browser }),
|
|
35
37
|
...(auth === undefined ? {} : { auth }),
|
|
@@ -46,17 +48,22 @@ export function digestProviderContract(snapshot) {
|
|
|
46
48
|
return createHash("sha256").update(canonicalJson(snapshot)).digest("hex");
|
|
47
49
|
}
|
|
48
50
|
function extractOperation(operationId, operation) {
|
|
51
|
+
const connectionMode = toJsonValue(operation.connectionMode);
|
|
52
|
+
const connectionExternalRefParam = toJsonValue(operation.connectionExternalRefParam);
|
|
53
|
+
const approval = toJsonValue(operation.approval);
|
|
54
|
+
const timeoutMs = toJsonValue(operation.timeoutMs);
|
|
55
|
+
const titleKey = toJsonValue(operation.titleKey);
|
|
49
56
|
const descriptionKey = toJsonValue(operation.descriptionKey);
|
|
50
|
-
const
|
|
57
|
+
const summaryKey = toJsonValue(operation.summaryKey);
|
|
58
|
+
const markdownKey = toJsonValue(operation.markdownKey);
|
|
51
59
|
const whenToUseKeys = toJsonValue(operation.whenToUseKeys);
|
|
52
60
|
const whenNotToUseKeys = toJsonValue(operation.whenNotToUseKeys);
|
|
53
|
-
const
|
|
54
|
-
const
|
|
55
|
-
const
|
|
61
|
+
const normalizationNotesKeys = toJsonValue(operation.normalizationNotesKeys);
|
|
62
|
+
const errorCodes = toJsonValue(operation.errorCodes);
|
|
63
|
+
const examples = toJsonValue(operation.examples);
|
|
56
64
|
const contract = toJsonValue(operation.contract);
|
|
57
65
|
const tags = toJsonValue(operation.tags);
|
|
58
66
|
const relatedOperations = toJsonValue(operation.relatedOperations);
|
|
59
|
-
const toolRouter = toJsonValue(operation.toolRouter);
|
|
60
67
|
const observability = toJsonValue(operation.observability);
|
|
61
68
|
const transport = extractTransport(operation.transport);
|
|
62
69
|
const fixtures = toJsonValue(operation.fixtures);
|
|
@@ -68,17 +75,23 @@ function extractOperation(operationId, operation) {
|
|
|
68
75
|
id: operationId,
|
|
69
76
|
inputSchema: describeSchema(operation.input),
|
|
70
77
|
outputSchema: describeSchema(operation.output),
|
|
78
|
+
...(connectionMode === undefined ? {} : { connectionMode }),
|
|
79
|
+
...(connectionExternalRefParam === undefined ? {} : { connectionExternalRefParam }),
|
|
80
|
+
riskClass: operation.riskClass,
|
|
81
|
+
...(approval === undefined ? {} : { approval }),
|
|
82
|
+
...(timeoutMs === undefined ? {} : { timeoutMs }),
|
|
83
|
+
...(titleKey === undefined ? {} : { titleKey }),
|
|
71
84
|
...(descriptionKey === undefined ? {} : { descriptionKey }),
|
|
72
|
-
...(
|
|
85
|
+
...(summaryKey === undefined ? {} : { summaryKey }),
|
|
86
|
+
...(markdownKey === undefined ? {} : { markdownKey }),
|
|
73
87
|
...(whenToUseKeys === undefined ? {} : { whenToUseKeys }),
|
|
74
88
|
...(whenNotToUseKeys === undefined ? {} : { whenNotToUseKeys }),
|
|
75
|
-
...(
|
|
76
|
-
...(
|
|
77
|
-
...(
|
|
89
|
+
...(normalizationNotesKeys === undefined ? {} : { normalizationNotesKeys }),
|
|
90
|
+
...(errorCodes === undefined ? {} : { errorCodes }),
|
|
91
|
+
...(examples === undefined ? {} : { examples }),
|
|
78
92
|
...(contract === undefined ? {} : { contract }),
|
|
79
93
|
...(tags === undefined ? {} : { tags }),
|
|
80
94
|
...(relatedOperations === undefined ? {} : { relatedOperations }),
|
|
81
|
-
...(toolRouter === undefined ? {} : { toolRouter }),
|
|
82
95
|
...(observability === undefined ? {} : { observability }),
|
|
83
96
|
...(transport === undefined ? {} : { transport }),
|
|
84
97
|
...(fixtures === undefined ? {} : { fixtures }),
|
|
@@ -128,6 +141,7 @@ function extractHealthCheck(value) {
|
|
|
128
141
|
name: item.name,
|
|
129
142
|
description: item.description,
|
|
130
143
|
input: toJsonValue(item.input),
|
|
144
|
+
scenario: toJsonValue(item.scenario),
|
|
131
145
|
degradedThresholdMs: item.degradedThresholdMs,
|
|
132
146
|
timeoutMs: item.timeoutMs,
|
|
133
147
|
expectedStatus: item.expectedStatus,
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import { ProviderError } from "./errors.js";
|
|
2
|
+
import type { ProviderDefinition } from "./types.js";
|
|
3
|
+
export declare const DECLARATION_INVALID_CODE = "DECLARATION_INVALID";
|
|
4
|
+
export declare const DECLARATION_RULE_IDS: {
|
|
5
|
+
readonly challengeShape: "credentials-challenge-shape";
|
|
6
|
+
readonly journeyExecutable: "health-journey-executable";
|
|
7
|
+
readonly journeyRunScenarioExclusive: "health-journey-run-scenario-exclusive";
|
|
8
|
+
readonly journeyScenarioValid: "health-journey-scenario-valid";
|
|
9
|
+
readonly schemaSerializable: "operation-schema-serializable";
|
|
10
|
+
readonly proxyExplicitPolicy: "proxy-explicit-policy";
|
|
11
|
+
readonly proxyVendorExclusive: "proxy-vendor-fields-exclusive";
|
|
12
|
+
readonly proxyNoMixedVendors: "proxy-no-mixed-vendors";
|
|
13
|
+
readonly proxySmartproxyGeo: "proxy-smartproxy-country-only";
|
|
14
|
+
readonly operationUpstreamProxy: "operation-upstream-proxy-unsupported";
|
|
15
|
+
readonly pinnedWireFieldPathValid: "public-schema-pinned-wire-field-valid";
|
|
16
|
+
};
|
|
17
|
+
export type DeclarationRuleId = (typeof DECLARATION_RULE_IDS)[keyof typeof DECLARATION_RULE_IDS];
|
|
18
|
+
export type DeclarationViolation = {
|
|
19
|
+
ruleId: DeclarationRuleId;
|
|
20
|
+
path: string;
|
|
21
|
+
message: string;
|
|
22
|
+
fix: string;
|
|
23
|
+
};
|
|
24
|
+
export declare function declarationInvalidError(violations: readonly DeclarationViolation[]): ProviderError;
|
|
25
|
+
/** Enforces declaration rules whose runtime behavior would otherwise fail open. */
|
|
26
|
+
export declare function validateFailClosedDeclaration(provider: ProviderDefinition): void;
|
|
27
|
+
type ProviderDeclarationRulesInput = Pick<ProviderDefinition, "healthJourneys" | "meta" | "proxy">;
|
|
28
|
+
type OperationDeclarationRulesInput = Pick<ProviderDefinition, "operations">;
|
|
29
|
+
/** Enforces fail-closed rules that only depend on the provider declaration. */
|
|
30
|
+
export declare function validateFailClosedProviderDeclaration(provider: ProviderDeclarationRulesInput): void;
|
|
31
|
+
/** Enforces fail-closed rules that depend on the operation implementation. */
|
|
32
|
+
export declare function validateFailClosedOperationDeclaration(provider: OperationDeclarationRulesInput): void;
|
|
33
|
+
export {};
|
|
@@ -0,0 +1,266 @@
|
|
|
1
|
+
import { describeSchema } from "./contract-serialization.js";
|
|
2
|
+
import { ProviderError } from "./errors.js";
|
|
3
|
+
import { HealthScenarioSchema } from "./health-scenario.js";
|
|
4
|
+
export const DECLARATION_INVALID_CODE = "DECLARATION_INVALID";
|
|
5
|
+
export const DECLARATION_RULE_IDS = {
|
|
6
|
+
challengeShape: "credentials-challenge-shape",
|
|
7
|
+
journeyExecutable: "health-journey-executable",
|
|
8
|
+
journeyRunScenarioExclusive: "health-journey-run-scenario-exclusive",
|
|
9
|
+
journeyScenarioValid: "health-journey-scenario-valid",
|
|
10
|
+
schemaSerializable: "operation-schema-serializable",
|
|
11
|
+
proxyExplicitPolicy: "proxy-explicit-policy",
|
|
12
|
+
proxyVendorExclusive: "proxy-vendor-fields-exclusive",
|
|
13
|
+
proxyNoMixedVendors: "proxy-no-mixed-vendors",
|
|
14
|
+
proxySmartproxyGeo: "proxy-smartproxy-country-only",
|
|
15
|
+
operationUpstreamProxy: "operation-upstream-proxy-unsupported",
|
|
16
|
+
pinnedWireFieldPathValid: "public-schema-pinned-wire-field-valid",
|
|
17
|
+
};
|
|
18
|
+
export function declarationInvalidError(violations) {
|
|
19
|
+
const summary = violations
|
|
20
|
+
.map((violation) => `${violation.path} [${violation.ruleId}]: ${violation.message}`)
|
|
21
|
+
.join("\n");
|
|
22
|
+
return new ProviderError(`Provider declaration is invalid (${violations.length} violation${violations.length === 1 ? "" : "s"}).${summary ? `\n${summary}` : ""}`, {
|
|
23
|
+
code: DECLARATION_INVALID_CODE,
|
|
24
|
+
details: { violations: [...violations] },
|
|
25
|
+
fix: "Apply every violation's fix hint, then validate the declaration again.",
|
|
26
|
+
});
|
|
27
|
+
}
|
|
28
|
+
/** Enforces declaration rules whose runtime behavior would otherwise fail open. */
|
|
29
|
+
export function validateFailClosedDeclaration(provider) {
|
|
30
|
+
const violations = [];
|
|
31
|
+
validateHealthDeclaration(provider, violations);
|
|
32
|
+
validatePinnedWireFieldPaths(provider, violations);
|
|
33
|
+
validateSchemaDeclaration(provider, violations);
|
|
34
|
+
validateProxyDeclaration(provider, violations);
|
|
35
|
+
validateOperationDeclaration(provider, violations);
|
|
36
|
+
if (violations.length > 0)
|
|
37
|
+
throw declarationInvalidError(violations);
|
|
38
|
+
}
|
|
39
|
+
/** Enforces fail-closed rules that only depend on the provider declaration. */
|
|
40
|
+
export function validateFailClosedProviderDeclaration(provider) {
|
|
41
|
+
const violations = [];
|
|
42
|
+
collectProviderDeclarationViolations(provider, violations);
|
|
43
|
+
if (violations.length > 0)
|
|
44
|
+
throw declarationInvalidError(violations);
|
|
45
|
+
}
|
|
46
|
+
/** Enforces fail-closed rules that depend on the operation implementation. */
|
|
47
|
+
export function validateFailClosedOperationDeclaration(provider) {
|
|
48
|
+
const violations = [];
|
|
49
|
+
collectOperationDeclarationViolations(provider, violations);
|
|
50
|
+
if (violations.length > 0)
|
|
51
|
+
throw declarationInvalidError(violations);
|
|
52
|
+
}
|
|
53
|
+
function collectProviderDeclarationViolations(provider, violations) {
|
|
54
|
+
validateHealthDeclaration(provider, violations);
|
|
55
|
+
validatePinnedWireFieldPaths(provider, violations);
|
|
56
|
+
validateProxyDeclaration(provider, violations);
|
|
57
|
+
}
|
|
58
|
+
function validatePinnedWireFieldPaths(provider, violations) {
|
|
59
|
+
const pins = provider.meta?.contract?.pinnedWireFieldPaths;
|
|
60
|
+
if (pins === undefined)
|
|
61
|
+
return;
|
|
62
|
+
if (!Array.isArray(pins)) {
|
|
63
|
+
violations.push({
|
|
64
|
+
ruleId: DECLARATION_RULE_IDS.pinnedWireFieldPathValid,
|
|
65
|
+
path: "meta.contract.pinnedWireFieldPaths",
|
|
66
|
+
message: "pinned wire field paths must be an array.",
|
|
67
|
+
fix: "Declare a readonly array of { path, reason } entries.",
|
|
68
|
+
});
|
|
69
|
+
return;
|
|
70
|
+
}
|
|
71
|
+
const seenPaths = new Set();
|
|
72
|
+
for (const [index, pin] of pins.entries()) {
|
|
73
|
+
const entryPath = `meta.contract.pinnedWireFieldPaths[${index}]`;
|
|
74
|
+
if (!pin || typeof pin !== "object" || Array.isArray(pin)) {
|
|
75
|
+
violations.push({
|
|
76
|
+
ruleId: DECLARATION_RULE_IDS.pinnedWireFieldPathValid,
|
|
77
|
+
path: entryPath,
|
|
78
|
+
message: "each pinned wire field path must be an object.",
|
|
79
|
+
fix: `Replace ${entryPath} with { path: "operations.<operation-id>.<field-path>", reason: "<non-empty reason>" }.`,
|
|
80
|
+
});
|
|
81
|
+
continue;
|
|
82
|
+
}
|
|
83
|
+
const path = "path" in pin ? pin.path : undefined;
|
|
84
|
+
const reason = "reason" in pin ? pin.reason : undefined;
|
|
85
|
+
if (typeof path !== "string" || path.trim().length === 0) {
|
|
86
|
+
violations.push({
|
|
87
|
+
ruleId: DECLARATION_RULE_IDS.pinnedWireFieldPathValid,
|
|
88
|
+
path: `${entryPath}.path`,
|
|
89
|
+
message: "path must be a non-empty string.",
|
|
90
|
+
fix: `Set ${entryPath}.path to the exact public-schema-upstream-field diagnostic path.`,
|
|
91
|
+
});
|
|
92
|
+
}
|
|
93
|
+
else if (seenPaths.has(path)) {
|
|
94
|
+
violations.push({
|
|
95
|
+
ruleId: DECLARATION_RULE_IDS.pinnedWireFieldPathValid,
|
|
96
|
+
path: `${entryPath}.path`,
|
|
97
|
+
message: `duplicate pinned wire field path ${JSON.stringify(path)}.`,
|
|
98
|
+
fix: `Keep exactly one declaration for ${JSON.stringify(path)}.`,
|
|
99
|
+
});
|
|
100
|
+
}
|
|
101
|
+
else {
|
|
102
|
+
seenPaths.add(path);
|
|
103
|
+
}
|
|
104
|
+
if (typeof reason !== "string" || reason.trim().length === 0) {
|
|
105
|
+
violations.push({
|
|
106
|
+
ruleId: DECLARATION_RULE_IDS.pinnedWireFieldPathValid,
|
|
107
|
+
path: `${entryPath}.reason`,
|
|
108
|
+
message: "reason must be a non-empty string.",
|
|
109
|
+
fix: `Document why renaming the exact wire field would break the upstream contract.`,
|
|
110
|
+
});
|
|
111
|
+
}
|
|
112
|
+
}
|
|
113
|
+
}
|
|
114
|
+
function collectOperationDeclarationViolations(provider, violations) {
|
|
115
|
+
validateSchemaDeclaration(provider, violations);
|
|
116
|
+
validateOperationDeclaration(provider, violations);
|
|
117
|
+
}
|
|
118
|
+
function validateHealthDeclaration(provider, violations) {
|
|
119
|
+
for (const [index, journey] of (provider.healthJourneys ?? []).entries()) {
|
|
120
|
+
if (!journey || typeof journey !== "object")
|
|
121
|
+
continue;
|
|
122
|
+
const hasRun = journey.run !== undefined;
|
|
123
|
+
const hasScenario = journey.scenario !== undefined;
|
|
124
|
+
if (hasRun && hasScenario) {
|
|
125
|
+
const journeyPath = healthJourneyPath(journey, index);
|
|
126
|
+
violations.push({
|
|
127
|
+
ruleId: DECLARATION_RULE_IDS.journeyRunScenarioExclusive,
|
|
128
|
+
path: journeyPath,
|
|
129
|
+
message: "A health journey must declare exactly one of run or scenario, not both.",
|
|
130
|
+
fix: `Remove either ${journeyPath}.run or ${journeyPath}.scenario.`,
|
|
131
|
+
});
|
|
132
|
+
}
|
|
133
|
+
if (!hasRun && !hasScenario) {
|
|
134
|
+
const journeyPath = healthJourneyPath(journey, index);
|
|
135
|
+
violations.push({
|
|
136
|
+
ruleId: DECLARATION_RULE_IDS.journeyExecutable,
|
|
137
|
+
path: `${journeyPath}.run`,
|
|
138
|
+
message: "coversOperations cannot provide health coverage without run or a declarative scenario.",
|
|
139
|
+
fix: `Add an async run(ctx) implementation or a valid scenario to ${journeyPath}.`,
|
|
140
|
+
});
|
|
141
|
+
}
|
|
142
|
+
if (hasScenario) {
|
|
143
|
+
const parsed = HealthScenarioSchema.safeParse(journey.scenario);
|
|
144
|
+
if (!parsed.success) {
|
|
145
|
+
const journeyPath = healthJourneyPath(journey, index);
|
|
146
|
+
violations.push({
|
|
147
|
+
ruleId: DECLARATION_RULE_IDS.journeyScenarioValid,
|
|
148
|
+
path: `${journeyPath}.scenario`,
|
|
149
|
+
message: "scenario must conform to HealthScenario.",
|
|
150
|
+
fix: "Build the scenario with defineHealthScenario().",
|
|
151
|
+
});
|
|
152
|
+
}
|
|
153
|
+
}
|
|
154
|
+
}
|
|
155
|
+
// NOTE: healthCheck.cases[].enabled is intentionally NOT validated here.
|
|
156
|
+
// self-test.ts reports a gated case as status "skipped" with skipReason
|
|
157
|
+
// "disabled", so the skip is visible in results rather than silent — it is a
|
|
158
|
+
// supported conditional-execution feature, not a class-1 silent no-op.
|
|
159
|
+
}
|
|
160
|
+
function healthJourneyPath(journey, index) {
|
|
161
|
+
return typeof journey.id === "string" && journey.id.length > 0
|
|
162
|
+
? `healthJourneys.${journey.id}`
|
|
163
|
+
: `healthJourneys[${index}]`;
|
|
164
|
+
}
|
|
165
|
+
function validateSchemaDeclaration(provider, violations) {
|
|
166
|
+
for (const [operationId, operation] of Object.entries(provider.operations ?? {})) {
|
|
167
|
+
const schemaEntries = [
|
|
168
|
+
[`operations.${operationId}.input`, operation.input],
|
|
169
|
+
[`operations.${operationId}.output`, operation.output],
|
|
170
|
+
];
|
|
171
|
+
// SSE event schemas reach contract extraction the same way input/output do,
|
|
172
|
+
// so a transform-bearing event schema would abort extraction at runtime while
|
|
173
|
+
// passing declaration checks. Validate them under the same rule.
|
|
174
|
+
const transport = operation.transport;
|
|
175
|
+
if (transport?.kind === "sse") {
|
|
176
|
+
for (const [eventName, eventSchema] of Object.entries(transport.events ?? {})) {
|
|
177
|
+
schemaEntries.push([
|
|
178
|
+
`operations.${operationId}.transport.events.${eventName}`,
|
|
179
|
+
eventSchema,
|
|
180
|
+
]);
|
|
181
|
+
}
|
|
182
|
+
}
|
|
183
|
+
for (const [path, schema] of schemaEntries) {
|
|
184
|
+
try {
|
|
185
|
+
describeSchema(schema);
|
|
186
|
+
}
|
|
187
|
+
catch (error) {
|
|
188
|
+
const reason = error instanceof Error ? error.message : String(error);
|
|
189
|
+
violations.push({
|
|
190
|
+
ruleId: DECLARATION_RULE_IDS.schemaSerializable,
|
|
191
|
+
path,
|
|
192
|
+
message: `schema conversion to JSON Schema failed: ${reason}`,
|
|
193
|
+
fix: `Replace unsupported constructs in ${path} so z.toJSONSchema() succeeds.`,
|
|
194
|
+
});
|
|
195
|
+
}
|
|
196
|
+
}
|
|
197
|
+
}
|
|
198
|
+
}
|
|
199
|
+
const MANAGED_PROXY_VENDORS = new Set(["smartproxy", "nodemaven"]);
|
|
200
|
+
const STATIC_PROXY_VENDORS = new Set(["custom", "decodo"]);
|
|
201
|
+
function validateProxyDeclaration(provider, violations) {
|
|
202
|
+
if (provider.proxy === true) {
|
|
203
|
+
violations.push({
|
|
204
|
+
ruleId: DECLARATION_RULE_IDS.proxyExplicitPolicy,
|
|
205
|
+
path: "proxy",
|
|
206
|
+
message: "proxy: true does not require resolvable proxy egress.",
|
|
207
|
+
fix: 'Replace proxy: true with an explicit policy such as proxy: { mode: "required", providers: ["smartproxy"] }.',
|
|
208
|
+
});
|
|
209
|
+
return;
|
|
210
|
+
}
|
|
211
|
+
if (!provider.proxy || typeof provider.proxy !== "object")
|
|
212
|
+
return;
|
|
213
|
+
const policy = provider.proxy;
|
|
214
|
+
const hasProvider = policy.provider !== undefined;
|
|
215
|
+
const hasProviders = policy.providers !== undefined;
|
|
216
|
+
if (hasProvider && hasProviders) {
|
|
217
|
+
violations.push({
|
|
218
|
+
ruleId: DECLARATION_RULE_IDS.proxyVendorExclusive,
|
|
219
|
+
path: "proxy",
|
|
220
|
+
message: "provider and providers are ambiguous when declared together.",
|
|
221
|
+
fix: "Keep either proxy.provider or proxy.providers, and remove the other field.",
|
|
222
|
+
});
|
|
223
|
+
}
|
|
224
|
+
const vendors = declaredProxyVendors(policy);
|
|
225
|
+
if (vendors.some((vendor) => MANAGED_PROXY_VENDORS.has(vendor)) &&
|
|
226
|
+
vendors.some((vendor) => STATIC_PROXY_VENDORS.has(vendor))) {
|
|
227
|
+
violations.push({
|
|
228
|
+
ruleId: DECLARATION_RULE_IDS.proxyNoMixedVendors,
|
|
229
|
+
path: hasProviders ? "proxy.providers" : "proxy.provider",
|
|
230
|
+
message: "managed and deprecated static proxy vendors cannot share a chain.",
|
|
231
|
+
fix: "Use only smartproxy/nodemaven vendors, or only deprecated static markers, in one policy.",
|
|
232
|
+
});
|
|
233
|
+
}
|
|
234
|
+
if (vendors.includes("smartproxy")) {
|
|
235
|
+
for (const field of ["subdivision", "city"]) {
|
|
236
|
+
if (policy.geo?.[field] === undefined)
|
|
237
|
+
continue;
|
|
238
|
+
const path = `proxy.geo.${field}`;
|
|
239
|
+
violations.push({
|
|
240
|
+
ruleId: DECLARATION_RULE_IDS.proxySmartproxyGeo,
|
|
241
|
+
path,
|
|
242
|
+
message: `smartproxy cannot honor ${field}-level geo targeting.`,
|
|
243
|
+
fix: `Remove ${path} or use a vendor chain that can honor it.`,
|
|
244
|
+
});
|
|
245
|
+
}
|
|
246
|
+
}
|
|
247
|
+
}
|
|
248
|
+
function declaredProxyVendors(policy) {
|
|
249
|
+
const vendors = [...(policy.providers ?? [])];
|
|
250
|
+
if (policy.provider !== undefined)
|
|
251
|
+
vendors.push(policy.provider);
|
|
252
|
+
return vendors;
|
|
253
|
+
}
|
|
254
|
+
function validateOperationDeclaration(provider, violations) {
|
|
255
|
+
for (const [operationId, operation] of Object.entries(provider.operations ?? {})) {
|
|
256
|
+
if (!operation.upstream?.proxy)
|
|
257
|
+
continue;
|
|
258
|
+
const path = `operations.${operationId}.upstream.proxy`;
|
|
259
|
+
violations.push({
|
|
260
|
+
ruleId: DECLARATION_RULE_IDS.operationUpstreamProxy,
|
|
261
|
+
path,
|
|
262
|
+
message: "operation-level proxy policy is not wired into operation execution.",
|
|
263
|
+
fix: `Remove ${path} and declare the effective policy at provider.proxy.`,
|
|
264
|
+
});
|
|
265
|
+
}
|
|
266
|
+
}
|
package/dist/define.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { AuthConfig, BrowserEngine, ContextDeclaration, CredentialDeclaration, HealthJourneyDefinition, HealthJourneySchedule, HealthScheduleRandomization, InferSchemaOutput, OperationDefinition, OperationHandlerResult, OperationHttpStreamTransport, OperationSseTransport, OperationWebSocketTransport, ProviderAccessConfig, ProviderDefinition, ProviderDeploymentOverrides, ProviderHealthMonitorConfig, ProviderProxyConfig, ProviderPublicProfile, ProviderReviewed, ProviderSecretDeclaration, ProviderStreamEvent, ProviderSttConfig, SchemaLike, SmsOtpMatcherDefinition,
|
|
1
|
+
import type { AuthConfig, BrowserEngine, ContextDeclaration, CredentialDeclaration, HealthJourneyDefinition, HealthJourneySchedule, HealthScheduleRandomization, InferSchemaOutput, NativeProviderConfig, OperationDefinition, OperationHandlerResult, OperationHttpStreamTransport, OperationSseTransport, OperationWebSocketTransport, ProviderAccessConfig, ProviderContext, ProviderDefinition, ProviderDeploymentOverrides, ProviderHealthMonitorConfig, ProviderOcrConfig, ProviderProxyConfig, ProviderPublicProfile, ProviderResolverConfig, ProviderReviewed, ProviderRuntimeTarget, ProviderSecretDeclaration, ProviderStreamEvent, ProviderSttConfig, SchemaLike, SmsOtpMatcherDefinition, StealthProfileSelection } from "./types.js";
|
|
2
2
|
type ProviderImplementationSourceAccess = "official_api" | "private_api" | "browser_flow" | "hybrid";
|
|
3
3
|
type ProviderImplementationCredentialStrategy = "apifuse_managed" | "workspace_secret" | "user_oauth" | "user_session" | "none";
|
|
4
4
|
interface ProviderImplementationProfile {
|
|
@@ -8,39 +8,46 @@ interface ProviderImplementationProfile {
|
|
|
8
8
|
operatorNotes?: string;
|
|
9
9
|
visibility: "internal" | "operator";
|
|
10
10
|
}
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
11
|
+
export declare const VALID_PROVIDER_RESOLVER_VENDORS: readonly ["browser", "capsolver", "capmonster", "2captcha", "custom"];
|
|
12
|
+
export declare const VALID_PROVIDER_CHALLENGE_KINDS: readonly ["turnstile", "recaptcha_v2", "recaptcha_v3", "hcaptcha", "cloudflare_interstitial", "aws_waf", "akamai_sec_cpt", "akamai_sensor"];
|
|
13
|
+
type ProviderOperation = OperationDefinition<any, any, any>;
|
|
14
|
+
type OperationConfig<TInput extends SchemaLike, TOutput extends SchemaLike, TContext = ProviderContext> = Omit<OperationDefinition<TInput, TOutput, TContext>, "handler"> & {
|
|
15
|
+
handler(ctx: TContext, input: InferSchemaOutput<TInput>): OperationHandlerResult<InferSchemaOutput<TOutput>> | Promise<OperationHandlerResult<InferSchemaOutput<TOutput>>>;
|
|
14
16
|
};
|
|
15
|
-
type OperationMapConfig<TOperations extends Record<string, ProviderOperation
|
|
16
|
-
[K in keyof TOperations]: TOperations[K] extends OperationDefinition<infer TInput, infer TOutput> ? OperationConfig<TInput, TOutput> | OperationDefinition<TInput, TOutput> : never;
|
|
17
|
+
type OperationMapConfig<TOperations extends Record<string, ProviderOperation>, TContext = ProviderContext> = {
|
|
18
|
+
[K in keyof TOperations]: TOperations[K] extends OperationDefinition<infer TInput, infer TOutput> ? OperationConfig<TInput, TOutput, TContext> | OperationDefinition<TInput, TOutput, TContext> : never;
|
|
17
19
|
};
|
|
18
|
-
type StreamOperationConfig<TInput extends SchemaLike, TOutput extends SchemaLike> = SseOperationConfig<TInput, TOutput> | HttpStreamOperationConfig<TInput, TOutput> | WebSocketOperationConfig<TInput, TOutput>;
|
|
19
|
-
type SseOperationConfig<TInput extends SchemaLike, TOutput extends SchemaLike> = Omit<OperationConfig<TInput, TOutput>, "handler" | "transport"> & {
|
|
20
|
+
type StreamOperationConfig<TInput extends SchemaLike, TOutput extends SchemaLike, TContext = ProviderContext> = SseOperationConfig<TInput, TOutput, TContext> | HttpStreamOperationConfig<TInput, TOutput, TContext> | WebSocketOperationConfig<TInput, TOutput, TContext>;
|
|
21
|
+
type SseOperationConfig<TInput extends SchemaLike, TOutput extends SchemaLike, TContext = ProviderContext> = Omit<OperationConfig<TInput, TOutput, TContext>, "handler" | "transport"> & {
|
|
20
22
|
transport: OperationSseTransport;
|
|
21
|
-
handler(ctx:
|
|
23
|
+
handler(ctx: TContext, input: InferSchemaOutput<TInput>): AsyncIterable<ProviderStreamEvent> | Promise<AsyncIterable<ProviderStreamEvent>>;
|
|
22
24
|
};
|
|
23
|
-
type HttpStreamOperationConfig<TInput extends SchemaLike, TOutput extends SchemaLike> = Omit<OperationConfig<TInput, TOutput>, "handler" | "transport"> & {
|
|
25
|
+
type HttpStreamOperationConfig<TInput extends SchemaLike, TOutput extends SchemaLike, TContext = ProviderContext> = Omit<OperationConfig<TInput, TOutput, TContext>, "handler" | "transport"> & {
|
|
24
26
|
transport: OperationHttpStreamTransport;
|
|
25
|
-
handler(ctx:
|
|
27
|
+
handler(ctx: TContext, input: InferSchemaOutput<TInput>): Response | ReadableStream<Uint8Array> | Promise<Response | ReadableStream<Uint8Array>>;
|
|
26
28
|
};
|
|
27
|
-
type WebSocketOperationConfig<TInput extends SchemaLike, TOutput extends SchemaLike> = Omit<OperationConfig<TInput, TOutput>, "handler" | "transport"> & {
|
|
29
|
+
type WebSocketOperationConfig<TInput extends SchemaLike, TOutput extends SchemaLike, TContext = ProviderContext> = Omit<OperationConfig<TInput, TOutput, TContext>, "handler" | "transport"> & {
|
|
28
30
|
transport: OperationWebSocketTransport;
|
|
29
|
-
handler(ctx:
|
|
31
|
+
handler(ctx: TContext, input: InferSchemaOutput<TInput>): Response | ReadableStream<Uint8Array> | Promise<Response | ReadableStream<Uint8Array>>;
|
|
30
32
|
};
|
|
31
|
-
type
|
|
33
|
+
type AuthStartHandlerNoInputGuard<TStart> = TStart extends (...args: infer TArgs) => unknown ? TArgs["length"] extends 0 | 1 ? unknown : {
|
|
34
|
+
"auth start handlers must not declare input parameters; return a form turn from start and receive user input in continue": never;
|
|
35
|
+
} : unknown;
|
|
36
|
+
export type AuthStartNoInputGuard<TConfig> = TConfig extends {
|
|
32
37
|
auth?: {
|
|
33
38
|
flow?: {
|
|
34
39
|
start: infer TStart;
|
|
35
40
|
};
|
|
36
41
|
};
|
|
37
|
-
} ? TStart
|
|
38
|
-
|
|
39
|
-
}
|
|
40
|
-
export interface
|
|
42
|
+
} ? AuthStartHandlerNoInputGuard<TStart> : TConfig extends {
|
|
43
|
+
start: infer TStart;
|
|
44
|
+
} ? AuthStartHandlerNoInputGuard<TStart> : unknown;
|
|
45
|
+
export interface ProviderDeclaration {
|
|
41
46
|
id: string;
|
|
42
47
|
version: string;
|
|
43
48
|
runtime: "standard" | "shared" | "browser";
|
|
49
|
+
/** Provider business-logic target. Omit only while migrating a legacy provider. */
|
|
50
|
+
runtimeTarget?: ProviderRuntimeTarget;
|
|
44
51
|
/**
|
|
45
52
|
* Optional deployment overrides, passed through verbatim onto the returned
|
|
46
53
|
* provider definition. The SDK types this field but does not deep-validate
|
|
@@ -48,22 +55,38 @@ export interface ProviderConfig<TOperations extends Record<string, ProviderOpera
|
|
|
48
55
|
* resolves omitted fields against the runtime deployment profiles.
|
|
49
56
|
*/
|
|
50
57
|
deployment?: ProviderDeploymentOverrides;
|
|
58
|
+
/** Declares the HTTP capability binding. A bare object states use without configuration. */
|
|
59
|
+
http?: Record<string, never> | true;
|
|
60
|
+
/** Declares upstream host policy; this does not add a `ctx.allowedHosts` member. */
|
|
51
61
|
allowedHosts?: string[];
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
};
|
|
62
|
+
native?: NativeProviderConfig;
|
|
63
|
+
stealth?: StealthProfileSelection;
|
|
64
|
+
/** Declares proxy policy; this is provider intent and does not add a `ctx.proxy` member. */
|
|
56
65
|
proxy?: ProviderProxyConfig;
|
|
66
|
+
ocr?: ProviderOcrConfig;
|
|
57
67
|
stt?: ProviderSttConfig;
|
|
68
|
+
resolver?: ProviderResolverConfig;
|
|
58
69
|
browser?: {
|
|
59
70
|
engine: BrowserEngine;
|
|
60
71
|
};
|
|
61
72
|
auth?: AuthConfig;
|
|
73
|
+
/** Declares the choice capability binding. A bare object states use without configuration. */
|
|
74
|
+
choice?: Record<string, never> | true;
|
|
62
75
|
reviewed?: ProviderReviewed;
|
|
63
76
|
access?: ProviderAccessConfig;
|
|
77
|
+
/** Declares secret requirements; this does not add a `ctx.secrets` member. */
|
|
64
78
|
secrets?: ProviderSecretDeclaration[];
|
|
79
|
+
/** Declares the environment capability binding. A bare object states use without configuration. */
|
|
80
|
+
env?: Record<string, never> | true;
|
|
65
81
|
credential?: CredentialDeclaration;
|
|
82
|
+
/** Declares provider context metadata; this does not add a `ctx.context` member. */
|
|
66
83
|
context?: ContextDeclaration;
|
|
84
|
+
/** Declares the state capability binding. A bare object states use without configuration. */
|
|
85
|
+
state?: Record<string, never> | true;
|
|
86
|
+
/** Declares the cache capability binding. A bare object states use without configuration. */
|
|
87
|
+
cache?: Record<string, never> | true;
|
|
88
|
+
/** Declares the files capability binding. A bare object states use without configuration. */
|
|
89
|
+
files?: Record<string, never> | true;
|
|
67
90
|
meta: {
|
|
68
91
|
displayName: string;
|
|
69
92
|
displayNameKey?: string;
|
|
@@ -83,18 +106,21 @@ export interface ProviderConfig<TOperations extends Record<string, ProviderOpera
|
|
|
83
106
|
implementationProfile?: ProviderImplementationProfile;
|
|
84
107
|
contract?: {
|
|
85
108
|
publicSchemaFieldNames?: "normalized";
|
|
109
|
+
readonly pinnedWireFieldPaths?: readonly {
|
|
110
|
+
readonly path: string;
|
|
111
|
+
readonly reason: string;
|
|
112
|
+
}[];
|
|
86
113
|
};
|
|
87
114
|
};
|
|
88
|
-
operations: OperationMapConfig<TOperations>;
|
|
89
115
|
healthMonitor?: ProviderHealthMonitorConfig;
|
|
90
116
|
/** New name for `healthMonitor` (transitional alias); declaring both is a ValidationError. */
|
|
91
117
|
healthProbe?: ProviderHealthMonitorConfig;
|
|
92
118
|
healthJourneys?: readonly HealthJourneyDefinition[];
|
|
93
119
|
}
|
|
94
|
-
/** Define one provider operation with schema-driven handler inference. */
|
|
95
|
-
export declare function defineOperation<TInput extends SchemaLike, TOutput extends SchemaLike>(
|
|
96
|
-
/** Define a non-JSON
|
|
97
|
-
export declare function defineStreamOperation<TInput extends SchemaLike, TOutput extends SchemaLike>(
|
|
120
|
+
/** Define one factored provider operation with schema-driven handler inference. */
|
|
121
|
+
export declare function defineOperation<TContext>(): <TInput extends SchemaLike, TOutput extends SchemaLike>(config: OperationConfig<TInput, TOutput, TContext>) => OperationDefinition<TInput, TOutput, TContext>;
|
|
122
|
+
/** Define a factored non-JSON operation with explicit transport metadata. */
|
|
123
|
+
export declare function defineStreamOperation<TContext>(): <TInput extends SchemaLike, TOutput extends SchemaLike>(config: StreamOperationConfig<TInput, TOutput, TContext>) => OperationDefinition<TInput, TOutput, TContext>;
|
|
98
124
|
export declare function every(interval: string, options?: {
|
|
99
125
|
jitter?: string;
|
|
100
126
|
randomize?: HealthScheduleRandomization;
|
|
@@ -103,7 +129,18 @@ export declare function centered(maxOffset: string): HealthScheduleRandomization
|
|
|
103
129
|
export declare function delayed(maxDelay: string): HealthScheduleRandomization;
|
|
104
130
|
export declare function defineSmsOtpMatcher(config: Omit<SmsOtpMatcherDefinition, "extractOtp">): SmsOtpMatcherDefinition;
|
|
105
131
|
export declare function defineHealthJourney(config: HealthJourneyDefinition): HealthJourneyDefinition;
|
|
106
|
-
|
|
107
|
-
|
|
132
|
+
/** The second authoring phase for a declaration established by defineProvider. */
|
|
133
|
+
export type ProviderBuilder<TConfig extends ProviderDeclaration> = <TOperations extends Record<string, ProviderOperation>>(implementation: {
|
|
134
|
+
operations: OperationMapConfig<TOperations, ProviderContext<TConfig>>;
|
|
135
|
+
}) => Omit<ProviderDefinition, "operations"> & {
|
|
136
|
+
operations: OperationMapConfig<TOperations, ProviderContext<TConfig>>;
|
|
108
137
|
};
|
|
138
|
+
/** Extract the declaration-derived operation context from a provider builder. */
|
|
139
|
+
export type ProviderContextOf<TBuilder> = TBuilder extends ProviderBuilder<infer TConfig> ? ProviderContext<TConfig> : never;
|
|
140
|
+
/** Annotate an operation while preserving the declaration-derived context. */
|
|
141
|
+
export type OperationDefinitionFor<TBuilder, TInput extends SchemaLike = SchemaLike, TOutput extends SchemaLike = SchemaLike> = OperationDefinition<TInput, TOutput, ProviderContextOf<TBuilder>>;
|
|
142
|
+
/** Annotate a built provider while preserving the declaration-derived context. */
|
|
143
|
+
export type ProviderDefinitionFor<TBuilder> = ProviderDefinition<ProviderContextOf<TBuilder>>;
|
|
144
|
+
/** Establish a provider declaration before its operations are contextually typed. */
|
|
145
|
+
export declare function defineProvider<const TConfig extends ProviderDeclaration>(declaration: TConfig & Record<Exclude<keyof TConfig, keyof ProviderDeclaration>, never> & AuthStartNoInputGuard<TConfig>): ProviderBuilder<TConfig>;
|
|
109
146
|
export {};
|