@apifuse/provider-sdk 2.2.0-beta.2 → 2.2.0-beta.21
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 +487 -0
- package/CHANGELOG.md +90 -0
- package/README.md +49 -3
- package/SUBMISSION.md +1 -1
- package/bin/apifuse-check.ts +44 -59
- package/bin/apifuse-create.ts +1 -1
- package/bin/apifuse-dev.ts +27 -52
- package/bin/apifuse-pack-check.ts +14 -0
- package/bin/apifuse-pack-smoke.ts +36 -81
- package/bin/apifuse-pack-types.ts +305 -0
- package/bin/apifuse-perf.ts +45 -127
- package/bin/apifuse-record.ts +659 -111
- package/bin/apifuse-submit-check.ts +546 -48
- package/bin/apifuse-sync-assets.ts +117 -0
- package/bin/apifuse.ts +1 -1
- package/bin/submit-check-delimited-text.ts +50 -0
- package/bin/submit-check-xml-semantics.ts +204 -0
- package/bin/submit-check-xml.ts +134 -0
- package/dist/auth-turn/index.d.ts +3 -3
- package/dist/auth.d.ts +2 -2
- package/dist/auth.js +9 -18
- package/dist/ceremonies/index.d.ts +9 -1
- package/dist/ceremonies/index.js +65 -18
- package/dist/cli/commands.d.ts +1 -1
- package/dist/cli/commands.js +8 -0
- package/dist/cli/create.d.ts +3 -0
- package/dist/cli/create.js +34 -35
- 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/config/loader.d.ts +176 -8
- package/dist/config/loader.js +424 -95
- package/dist/contract-serialization.d.ts +2 -2
- package/dist/contract-serialization.js +3 -6
- package/dist/contract-types.d.ts +2 -2
- package/dist/contract.d.ts +3 -3
- package/dist/contract.js +4 -6
- package/dist/define.d.ts +9 -1
- package/dist/define.js +304 -119
- package/dist/dev.d.ts +1 -1
- package/dist/dev.js +1 -1
- package/dist/error-resolution.d.ts +2 -0
- package/dist/error-resolution.js +90 -0
- package/dist/errors.d.ts +22 -1
- package/dist/errors.js +88 -0
- package/dist/fixture-sanitization.d.ts +26 -0
- package/dist/fixture-sanitization.js +216 -0
- package/dist/i18n/catalog.d.ts +2 -2
- package/dist/i18n/catalog.js +4 -10
- package/dist/i18n/index.d.ts +2 -2
- package/dist/i18n/index.js +2 -2
- package/dist/i18n/keys.d.ts +2 -2
- package/dist/index.d.ts +46 -42
- package/dist/index.js +41 -37
- package/dist/lint.d.ts +1 -1
- package/dist/lint.js +8 -15
- 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 +12 -11
- package/dist/provider.js +10 -9
- package/dist/public-schema-field-lint.d.ts +1 -1
- package/dist/recipes/gov-api.js +1 -1
- package/dist/runtime/auth-flow.d.ts +2 -1
- package/dist/runtime/auth-flow.js +4 -3
- package/dist/runtime/browser.d.ts +1 -1
- package/dist/runtime/browser.js +15 -29
- package/dist/runtime/cache.d.ts +1 -1
- package/dist/runtime/cache.js +4 -8
- package/dist/runtime/choice.d.ts +1 -1
- package/dist/runtime/choice.js +31 -35
- package/dist/runtime/credential.d.ts +1 -1
- package/dist/runtime/credential.js +1 -1
- package/dist/runtime/env.d.ts +1 -1
- package/dist/runtime/executor.d.ts +1 -1
- package/dist/runtime/executor.js +31 -4
- package/dist/runtime/http.d.ts +2 -2
- package/dist/runtime/http.js +387 -47
- package/dist/runtime/insights.d.ts +1 -1
- package/dist/runtime/insights.js +6 -13
- package/dist/runtime/instrumentation.d.ts +2 -2
- package/dist/runtime/instrumentation.js +345 -22
- package/dist/runtime/keyring.js +1 -1
- package/dist/runtime/namespace.js +1 -1
- package/dist/runtime/native-network.d.ts +127 -0
- package/dist/runtime/native-network.js +1298 -0
- package/dist/runtime/otlp.d.ts +1 -1
- package/dist/runtime/perf.d.ts +1 -1
- package/dist/runtime/provider.d.ts +1 -1
- package/dist/runtime/provider.js +1 -2
- package/dist/runtime/proxy-errors.d.ts +1 -1
- package/dist/runtime/proxy-errors.js +9 -7
- package/dist/runtime/proxy-nodemaven.d.ts +56 -0
- package/dist/runtime/proxy-nodemaven.js +146 -0
- package/dist/runtime/proxy-retry-policy.d.ts +2 -2
- package/dist/runtime/proxy-retry-policy.js +2 -2
- package/dist/runtime/proxy-telemetry.d.ts +2 -1
- package/dist/runtime/proxy-telemetry.js +55 -52
- 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 +2 -4
- package/dist/runtime/request-options.d.ts +68 -1
- package/dist/runtime/request-options.js +548 -0
- package/dist/runtime/secrets.d.ts +27 -0
- package/dist/runtime/secrets.js +51 -0
- package/dist/runtime/state.d.ts +2 -2
- package/dist/runtime/state.js +238 -26
- package/dist/runtime/stealth.d.ts +5 -3
- package/dist/runtime/stealth.js +423 -143
- package/dist/runtime/stt.d.ts +1 -1
- package/dist/runtime/stt.js +11 -15
- package/dist/runtime/trace.d.ts +2 -2
- package/dist/runtime/trace.js +2 -4
- package/dist/runtime/waterfall.d.ts +1 -1
- package/dist/schema.d.ts +1 -1
- package/dist/schema.js +7 -15
- package/dist/serve.d.ts +1 -1
- package/dist/serve.js +1 -1
- package/dist/server/index.d.ts +7 -7
- package/dist/server/index.js +6 -6
- 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.d.ts +1 -1
- package/dist/server/self-test-redaction.js +1 -1
- package/dist/server/self-test.d.ts +104 -3
- package/dist/server/self-test.js +673 -115
- package/dist/server/serve.d.ts +116 -4
- package/dist/server/serve.js +799 -128
- package/dist/server/types.d.ts +34 -9
- package/dist/server/types.js +8 -1
- package/dist/stateful/errors.d.ts +14 -0
- package/dist/stateful/errors.js +14 -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 +71 -0
- package/dist/stateful/stateful-provider-session-routing.js +353 -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 +1 -1
- package/dist/stealth/profiles.js +5 -14
- package/dist/stream-evidence.d.ts +74 -0
- package/dist/stream-evidence.js +785 -0
- package/dist/stream.d.ts +1 -1
- package/dist/testing/index.d.ts +2 -2
- package/dist/testing/index.js +2 -2
- package/dist/testing/run.d.ts +32 -2
- package/dist/testing/run.js +478 -28
- package/dist/types.d.ts +342 -14
- package/dist/types.js +1 -0
- package/dist/user-input.d.ts +30 -0
- package/dist/user-input.js +66 -0
- package/package.json +16 -5
- package/src/auth-turn/index.ts +1 -1
- package/src/auth.ts +28 -86
- package/src/ceremonies/index.ts +103 -78
- package/src/cli/commands.ts +10 -0
- package/src/cli/create.ts +42 -35
- package/src/cli/prompt-assets.ts +865 -0
- package/src/cli/templates/provider/AGENTS.md.tpl +17 -8
- package/src/config/loader.ts +652 -204
- package/src/contract-serialization.ts +5 -11
- package/src/contract-types.ts +2 -2
- package/src/contract.ts +12 -28
- package/src/define.ts +499 -498
- package/src/dev.ts +4 -9
- package/src/error-resolution.ts +91 -0
- package/src/errors.ts +110 -5
- package/src/fixture-sanitization.ts +247 -0
- package/src/i18n/catalog.ts +10 -32
- package/src/i18n/index.ts +2 -2
- package/src/i18n/keys.ts +5 -11
- package/src/index.ts +112 -42
- package/src/lint.ts +88 -152
- 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 +66 -11
- package/src/public-schema-field-lint.ts +7 -33
- package/src/recipes/gov-api.ts +2 -5
- package/src/runtime/auth-flow.ts +7 -7
- package/src/runtime/browser.ts +64 -187
- package/src/runtime/cache.ts +20 -67
- package/src/runtime/choice.ts +79 -132
- package/src/runtime/credential.ts +2 -2
- package/src/runtime/env.ts +1 -1
- package/src/runtime/executor.ts +43 -20
- package/src/runtime/http.ts +494 -57
- package/src/runtime/insights.ts +15 -53
- package/src/runtime/instrumentation.ts +495 -66
- package/src/runtime/keyring.ts +7 -19
- package/src/runtime/namespace.ts +2 -7
- package/src/runtime/native-network.ts +1686 -0
- package/src/runtime/otlp.ts +12 -23
- package/src/runtime/perf.ts +1 -1
- package/src/runtime/provider.ts +4 -9
- package/src/runtime/proxy-errors.ts +29 -42
- package/src/runtime/proxy-nodemaven.ts +221 -0
- package/src/runtime/proxy-retry-policy.ts +3 -3
- package/src/runtime/proxy-telemetry.ts +79 -77
- package/src/runtime/redirects.ts +66 -0
- package/src/runtime/redis.ts +4 -12
- package/src/runtime/request-options.ts +679 -9
- package/src/runtime/secrets.ts +64 -0
- package/src/runtime/state.ts +353 -133
- package/src/runtime/stealth.ts +505 -154
- package/src/runtime/stt.ts +38 -94
- package/src/runtime/trace.ts +14 -44
- package/src/runtime/waterfall.ts +5 -18
- package/src/schema.ts +23 -84
- package/src/serve.ts +1 -1
- package/src/server/index.ts +29 -7
- package/src/server/self-test-input-tokens.ts +29 -14
- package/src/server/self-test-redaction.ts +2 -2
- package/src/server/self-test.ts +857 -132
- package/src/server/serve.ts +1151 -328
- package/src/server/types.ts +12 -13
- package/src/stateful/README.md +146 -0
- package/src/stateful/errors.ts +23 -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 +555 -0
- package/src/stateful/stateful-provider-session-runtime.ts +403 -0
- package/src/stateful-signing.ts +46 -0
- package/src/stealth/profiles.ts +10 -26
- package/src/stream-evidence.ts +988 -0
- package/src/stream.ts +8 -19
- package/src/testing/index.ts +10 -2
- package/src/testing/run.ts +653 -74
- package/src/types.ts +408 -28
- package/src/user-input.ts +118 -0
- 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,288 @@
|
|
|
1
|
+
import { canonicalizeEgressHost, classifyEgressHost, formatIpv6, parseIpv4Cidr, parseIpv6Cidr, } from "./native-address.js";
|
|
2
|
+
const NATIVE_PROVIDER_FIELD_RECORD = {
|
|
3
|
+
network: true,
|
|
4
|
+
};
|
|
5
|
+
const NATIVE_NETWORK_FIELD_RECORD = {
|
|
6
|
+
tcp: true,
|
|
7
|
+
dynamicTcp: true,
|
|
8
|
+
};
|
|
9
|
+
const NATIVE_TCP_RULE_FIELD_RECORD = {
|
|
10
|
+
host: true,
|
|
11
|
+
ports: true,
|
|
12
|
+
tls: true,
|
|
13
|
+
};
|
|
14
|
+
const NATIVE_DYNAMIC_TCP_RULE_FIELD_RECORD = {
|
|
15
|
+
sourceHost: true,
|
|
16
|
+
sourceHostSuffixes: true,
|
|
17
|
+
sourceIpv4Cidrs: true,
|
|
18
|
+
sourceIpv6Cidrs: true,
|
|
19
|
+
sourcePorts: true,
|
|
20
|
+
sourcePortRanges: true,
|
|
21
|
+
targetHostSuffixes: true,
|
|
22
|
+
targetIpv4Cidrs: true,
|
|
23
|
+
targetIpv6Cidrs: true,
|
|
24
|
+
targetPorts: true,
|
|
25
|
+
targetPortRanges: true,
|
|
26
|
+
tls: true,
|
|
27
|
+
ttlMs: true,
|
|
28
|
+
maxGrants: true,
|
|
29
|
+
};
|
|
30
|
+
const NATIVE_TCP_PORT_RANGE_FIELD_RECORD = {
|
|
31
|
+
start: true,
|
|
32
|
+
end: true,
|
|
33
|
+
};
|
|
34
|
+
const NATIVE_PROVIDER_FIELDS = Object.keys(NATIVE_PROVIDER_FIELD_RECORD);
|
|
35
|
+
const NATIVE_NETWORK_FIELDS = Object.keys(NATIVE_NETWORK_FIELD_RECORD);
|
|
36
|
+
const NATIVE_TCP_RULE_FIELDS = Object.keys(NATIVE_TCP_RULE_FIELD_RECORD);
|
|
37
|
+
const NATIVE_DYNAMIC_TCP_RULE_FIELDS = Object.keys(NATIVE_DYNAMIC_TCP_RULE_FIELD_RECORD);
|
|
38
|
+
const NATIVE_TCP_PORT_RANGE_FIELDS = Object.keys(NATIVE_TCP_PORT_RANGE_FIELD_RECORD);
|
|
39
|
+
export class NativeEgressPolicyValidationError extends Error {
|
|
40
|
+
constructor(message) {
|
|
41
|
+
super(message);
|
|
42
|
+
this.name = "NativeEgressPolicyValidationError";
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
function fail(message) {
|
|
46
|
+
throw new NativeEgressPolicyValidationError(message);
|
|
47
|
+
}
|
|
48
|
+
function dataRecord(value, fieldPath, allowed) {
|
|
49
|
+
if (!value || typeof value !== "object" || Array.isArray(value))
|
|
50
|
+
fail(`${fieldPath} must be an object`);
|
|
51
|
+
const prototype = Reflect.getPrototypeOf(value);
|
|
52
|
+
if (prototype !== Object.prototype && prototype !== null)
|
|
53
|
+
fail(`${fieldPath} must be a plain object`);
|
|
54
|
+
const record = {};
|
|
55
|
+
for (const key of Reflect.ownKeys(value)) {
|
|
56
|
+
if (typeof key !== "string")
|
|
57
|
+
fail(`${fieldPath} must not contain symbol fields`);
|
|
58
|
+
if (!allowed.includes(key))
|
|
59
|
+
fail(`Unknown field ${fieldPath}.${key}`);
|
|
60
|
+
const descriptor = Reflect.getOwnPropertyDescriptor(value, key);
|
|
61
|
+
if (!descriptor || !("value" in descriptor))
|
|
62
|
+
fail(`${fieldPath}.${key} must be a data field`);
|
|
63
|
+
record[key] = descriptor.value;
|
|
64
|
+
}
|
|
65
|
+
return record;
|
|
66
|
+
}
|
|
67
|
+
function dataArray(value, fieldPath) {
|
|
68
|
+
if (!Array.isArray(value))
|
|
69
|
+
fail(`${fieldPath} must be an array`);
|
|
70
|
+
const result = [];
|
|
71
|
+
for (const key of Reflect.ownKeys(value)) {
|
|
72
|
+
if (key === "length")
|
|
73
|
+
continue;
|
|
74
|
+
if (typeof key !== "string" || !/^(?:0|[1-9]\d*)$/.test(key))
|
|
75
|
+
fail(`${fieldPath} must not contain non-index fields`);
|
|
76
|
+
const descriptor = Reflect.getOwnPropertyDescriptor(value, key);
|
|
77
|
+
if (!descriptor || !("value" in descriptor))
|
|
78
|
+
fail(`${fieldPath}[${key}] must be a data field`);
|
|
79
|
+
result[Number(key)] = descriptor.value;
|
|
80
|
+
}
|
|
81
|
+
if (result.length !== value.length)
|
|
82
|
+
fail(`${fieldPath} must not be sparse`);
|
|
83
|
+
for (let index = 0; index < result.length; index += 1) {
|
|
84
|
+
if (!(index in result))
|
|
85
|
+
fail(`${fieldPath} must not be sparse`);
|
|
86
|
+
}
|
|
87
|
+
return result;
|
|
88
|
+
}
|
|
89
|
+
function host(value, fieldPath, suffix = false) {
|
|
90
|
+
if (typeof value === "string" && value.includes("*"))
|
|
91
|
+
fail(`${fieldPath} must be an exact ${suffix ? "DNS suffix" : "hostname"}, not a wildcard`);
|
|
92
|
+
const canonical = canonicalizeEgressHost(value);
|
|
93
|
+
if (!canonical.ok)
|
|
94
|
+
fail(`${fieldPath} must be a non-empty hostname`);
|
|
95
|
+
const kind = classifyEgressHost(canonical.host);
|
|
96
|
+
if (kind === "numeric-ambiguous")
|
|
97
|
+
fail(`${fieldPath} value is an unresolvable numeric-ambiguous spelling`);
|
|
98
|
+
if (suffix && kind !== "dns") {
|
|
99
|
+
const family = kind === "ipv4" ? "IPv4" : "IPv6";
|
|
100
|
+
fail(`${fieldPath} must be a DNS suffix, not an ${family} literal`);
|
|
101
|
+
}
|
|
102
|
+
return canonical.host;
|
|
103
|
+
}
|
|
104
|
+
function port(value, fieldPath) {
|
|
105
|
+
if (typeof value !== "number" || !Number.isSafeInteger(value) || value < 1 || value > 65_535)
|
|
106
|
+
fail(`${fieldPath} must be an integer from 1 to 65535`);
|
|
107
|
+
return value;
|
|
108
|
+
}
|
|
109
|
+
function ports(value, fieldPath) {
|
|
110
|
+
return dataArray(value, fieldPath).map((value, index) => port(value, `${fieldPath}[${index}]`));
|
|
111
|
+
}
|
|
112
|
+
function hostSuffixes(value, fieldPath) {
|
|
113
|
+
return dataArray(value, fieldPath).map((value, index) => host(value, `${fieldPath}[${index}]`, true));
|
|
114
|
+
}
|
|
115
|
+
function ipv4Cidrs(value, fieldPath) {
|
|
116
|
+
const seen = new Set();
|
|
117
|
+
return dataArray(value, fieldPath).map((value, index) => {
|
|
118
|
+
const cidrPath = `${fieldPath}[${index}]`;
|
|
119
|
+
if (typeof value !== "string")
|
|
120
|
+
fail(`${cidrPath} must be an IPv4 CIDR in a.b.c.d/nn form`);
|
|
121
|
+
const parsed = parseIpv4Cidr(value);
|
|
122
|
+
if (!parsed.ok) {
|
|
123
|
+
if (parsed.reason === "non-canonical-network")
|
|
124
|
+
fail(`${cidrPath} must use the canonical network address with no host bits set`);
|
|
125
|
+
fail(`${cidrPath} must be an IPv4 CIDR in a.b.c.d/nn form`);
|
|
126
|
+
}
|
|
127
|
+
const duplicateKey = `${parsed.network}/${parsed.prefix}`;
|
|
128
|
+
if (seen.has(duplicateKey))
|
|
129
|
+
fail(`${fieldPath} must not contain duplicate CIDRs`);
|
|
130
|
+
seen.add(duplicateKey);
|
|
131
|
+
return value;
|
|
132
|
+
});
|
|
133
|
+
}
|
|
134
|
+
function ipv6Cidrs(value, fieldPath) {
|
|
135
|
+
const seen = new Set();
|
|
136
|
+
return dataArray(value, fieldPath).map((value, index) => {
|
|
137
|
+
const cidrPath = `${fieldPath}[${index}]`;
|
|
138
|
+
if (typeof value !== "string")
|
|
139
|
+
fail(`${cidrPath} must be an IPv6 CIDR in address/nn form`);
|
|
140
|
+
const parsed = parseIpv6Cidr(value);
|
|
141
|
+
if (!parsed.ok) {
|
|
142
|
+
if (parsed.reason === "non-canonical-network")
|
|
143
|
+
fail(`${cidrPath} must use the canonical network address with no host bits set`);
|
|
144
|
+
if (parsed.overlap === "ipv4-mapped")
|
|
145
|
+
fail(`${cidrPath} overlaps IPv4-mapped ::ffff:0:0/96 address space`);
|
|
146
|
+
if (parsed.overlap === "ipv4-compatible")
|
|
147
|
+
fail(`${cidrPath} overlaps IPv4-compatible ::/96 address space`);
|
|
148
|
+
fail(`${cidrPath} must be an IPv6 CIDR in address/nn form`);
|
|
149
|
+
}
|
|
150
|
+
const duplicateKey = `${formatIpv6(parsed.network)}/${parsed.prefix}`;
|
|
151
|
+
if (seen.has(duplicateKey))
|
|
152
|
+
fail(`${fieldPath} must not contain duplicate CIDRs`);
|
|
153
|
+
seen.add(duplicateKey);
|
|
154
|
+
return value;
|
|
155
|
+
});
|
|
156
|
+
}
|
|
157
|
+
function ranges(value, fieldPath) {
|
|
158
|
+
return dataArray(value, fieldPath).map((value, index) => {
|
|
159
|
+
const rangePath = `${fieldPath}[${index}]`;
|
|
160
|
+
const record = dataRecord(value, rangePath, NATIVE_TCP_PORT_RANGE_FIELDS);
|
|
161
|
+
const start = port(record.start, `${rangePath}.start`);
|
|
162
|
+
const end = port(record.end, `${rangePath}.end`);
|
|
163
|
+
if (start > end)
|
|
164
|
+
fail(`${rangePath}.start must not exceed end`);
|
|
165
|
+
return { start, end };
|
|
166
|
+
});
|
|
167
|
+
}
|
|
168
|
+
function tls(value, fieldPath) {
|
|
169
|
+
if (value !== "required" && value !== "allowed" && value !== "disabled")
|
|
170
|
+
fail(`${fieldPath} must be required, allowed, or disabled`);
|
|
171
|
+
return value;
|
|
172
|
+
}
|
|
173
|
+
function positiveInteger(value, fieldPath) {
|
|
174
|
+
if (typeof value !== "number" || !Number.isSafeInteger(value) || value <= 0)
|
|
175
|
+
fail(`${fieldPath} must be a positive integer`);
|
|
176
|
+
return value;
|
|
177
|
+
}
|
|
178
|
+
export function parseNativeEgressPolicy(value) {
|
|
179
|
+
try {
|
|
180
|
+
const policy = dataRecord(value, "native.network", NATIVE_NETWORK_FIELDS);
|
|
181
|
+
const staticRules = policy.tcp === undefined
|
|
182
|
+
? []
|
|
183
|
+
: dataArray(policy.tcp, "native.network.tcp").map((value, index) => {
|
|
184
|
+
const fieldPath = `native.network.tcp[${index}]`;
|
|
185
|
+
const rule = dataRecord(value, fieldPath, NATIVE_TCP_RULE_FIELDS);
|
|
186
|
+
const declaredPorts = ports(rule.ports, `${fieldPath}.ports`);
|
|
187
|
+
if (declaredPorts.length === 0)
|
|
188
|
+
fail(`${fieldPath}.ports must not be empty`);
|
|
189
|
+
return {
|
|
190
|
+
host: host(rule.host, `${fieldPath}.host`),
|
|
191
|
+
ports: declaredPorts,
|
|
192
|
+
tls: tls(rule.tls, `${fieldPath}.tls`),
|
|
193
|
+
};
|
|
194
|
+
});
|
|
195
|
+
const dynamicRules = policy.dynamicTcp === undefined
|
|
196
|
+
? []
|
|
197
|
+
: dataArray(policy.dynamicTcp, "native.network.dynamicTcp").map((value, index) => {
|
|
198
|
+
const fieldPath = `native.network.dynamicTcp[${index}]`;
|
|
199
|
+
const rule = dataRecord(value, fieldPath, NATIVE_DYNAMIC_TCP_RULE_FIELDS);
|
|
200
|
+
const sourceHost = rule.sourceHost === undefined
|
|
201
|
+
? undefined
|
|
202
|
+
: host(rule.sourceHost, `${fieldPath}.sourceHost`);
|
|
203
|
+
const sourceHostSuffixes = rule.sourceHostSuffixes === undefined
|
|
204
|
+
? []
|
|
205
|
+
: hostSuffixes(rule.sourceHostSuffixes, `${fieldPath}.sourceHostSuffixes`);
|
|
206
|
+
const sourceIpv4Cidrs = rule.sourceIpv4Cidrs === undefined
|
|
207
|
+
? []
|
|
208
|
+
: ipv4Cidrs(rule.sourceIpv4Cidrs, `${fieldPath}.sourceIpv4Cidrs`);
|
|
209
|
+
const sourceIpv6Cidrs = rule.sourceIpv6Cidrs === undefined
|
|
210
|
+
? []
|
|
211
|
+
: ipv6Cidrs(rule.sourceIpv6Cidrs, `${fieldPath}.sourceIpv6Cidrs`);
|
|
212
|
+
if (sourceHost === undefined &&
|
|
213
|
+
sourceHostSuffixes.length === 0 &&
|
|
214
|
+
sourceIpv4Cidrs.length === 0 &&
|
|
215
|
+
sourceIpv6Cidrs.length === 0)
|
|
216
|
+
fail(`${fieldPath} must declare sourceHost or a non-empty sourceHostSuffixes, sourceIpv4Cidrs, or sourceIpv6Cidrs list`);
|
|
217
|
+
const sourcePorts = rule.sourcePorts === undefined
|
|
218
|
+
? []
|
|
219
|
+
: ports(rule.sourcePorts, `${fieldPath}.sourcePorts`);
|
|
220
|
+
const sourcePortRanges = rule.sourcePortRanges === undefined
|
|
221
|
+
? []
|
|
222
|
+
: ranges(rule.sourcePortRanges, `${fieldPath}.sourcePortRanges`);
|
|
223
|
+
if (sourcePorts.length === 0 && sourcePortRanges.length === 0)
|
|
224
|
+
fail(`${fieldPath} must declare a non-empty sourcePorts or sourcePortRanges list`);
|
|
225
|
+
const targetHostSuffixes = rule.targetHostSuffixes === undefined
|
|
226
|
+
? []
|
|
227
|
+
: hostSuffixes(rule.targetHostSuffixes, `${fieldPath}.targetHostSuffixes`);
|
|
228
|
+
const targetIpv4Cidrs = rule.targetIpv4Cidrs === undefined
|
|
229
|
+
? []
|
|
230
|
+
: ipv4Cidrs(rule.targetIpv4Cidrs, `${fieldPath}.targetIpv4Cidrs`);
|
|
231
|
+
const targetIpv6Cidrs = rule.targetIpv6Cidrs === undefined
|
|
232
|
+
? []
|
|
233
|
+
: ipv6Cidrs(rule.targetIpv6Cidrs, `${fieldPath}.targetIpv6Cidrs`);
|
|
234
|
+
if (targetHostSuffixes.length === 0 &&
|
|
235
|
+
targetIpv4Cidrs.length === 0 &&
|
|
236
|
+
targetIpv6Cidrs.length === 0)
|
|
237
|
+
fail(`${fieldPath} must declare a non-empty targetHostSuffixes, targetIpv4Cidrs, or targetIpv6Cidrs list`);
|
|
238
|
+
const targetPorts = rule.targetPorts === undefined
|
|
239
|
+
? []
|
|
240
|
+
: ports(rule.targetPorts, `${fieldPath}.targetPorts`);
|
|
241
|
+
const targetPortRanges = rule.targetPortRanges === undefined
|
|
242
|
+
? []
|
|
243
|
+
: ranges(rule.targetPortRanges, `${fieldPath}.targetPortRanges`);
|
|
244
|
+
if (targetPorts.length === 0 && targetPortRanges.length === 0)
|
|
245
|
+
fail(`${fieldPath} must declare a non-empty targetPorts or targetPortRanges list`);
|
|
246
|
+
return {
|
|
247
|
+
...(sourceHost === undefined ? {} : { sourceHost }),
|
|
248
|
+
sourceHostSuffixes,
|
|
249
|
+
sourceIpv4Cidrs,
|
|
250
|
+
sourceIpv6Cidrs,
|
|
251
|
+
sourcePorts,
|
|
252
|
+
sourcePortRanges,
|
|
253
|
+
targetHostSuffixes,
|
|
254
|
+
targetIpv4Cidrs,
|
|
255
|
+
targetIpv6Cidrs,
|
|
256
|
+
targetPorts,
|
|
257
|
+
targetPortRanges,
|
|
258
|
+
tls: tls(rule.tls, `${fieldPath}.tls`),
|
|
259
|
+
...(rule.ttlMs === undefined
|
|
260
|
+
? {}
|
|
261
|
+
: { ttlMs: positiveInteger(rule.ttlMs, `${fieldPath}.ttlMs`) }),
|
|
262
|
+
...(rule.maxGrants === undefined
|
|
263
|
+
? {}
|
|
264
|
+
: { maxGrants: positiveInteger(rule.maxGrants, `${fieldPath}.maxGrants`) }),
|
|
265
|
+
};
|
|
266
|
+
});
|
|
267
|
+
return { staticRules, dynamicRules };
|
|
268
|
+
}
|
|
269
|
+
catch (error) {
|
|
270
|
+
if (error instanceof NativeEgressPolicyValidationError)
|
|
271
|
+
throw error;
|
|
272
|
+
throw new NativeEgressPolicyValidationError("Native egress policy could not be inspected safely");
|
|
273
|
+
}
|
|
274
|
+
}
|
|
275
|
+
export function validateNativeProviderConfig(value) {
|
|
276
|
+
if (value === undefined)
|
|
277
|
+
return;
|
|
278
|
+
try {
|
|
279
|
+
const native = dataRecord(value, "native", NATIVE_PROVIDER_FIELDS);
|
|
280
|
+
if (native.network !== undefined)
|
|
281
|
+
parseNativeEgressPolicy(native.network);
|
|
282
|
+
}
|
|
283
|
+
catch (error) {
|
|
284
|
+
if (error instanceof NativeEgressPolicyValidationError)
|
|
285
|
+
throw error;
|
|
286
|
+
throw new NativeEgressPolicyValidationError("Native provider config could not be inspected safely");
|
|
287
|
+
}
|
|
288
|
+
}
|
package/dist/observability.d.ts
CHANGED
|
@@ -1,5 +1,8 @@
|
|
|
1
|
-
export declare const PROVIDER_OBSERVABILITY_TAXONOMY_VERSION = "2026-
|
|
2
|
-
export declare const PROVIDER_ERROR_CATEGORIES: readonly ["ok", "timeout", "network", "upstream_http", "upstream_rate_limited", "upstream_auth", "upstream_schema_drift", "proxy_pool", "anti_bot_blocked", "credential_expired", "credential_unavailable", "input_validation", "output_validation", "provider_error", "internal_error", "unclassified"];
|
|
1
|
+
export declare const PROVIDER_OBSERVABILITY_TAXONOMY_VERSION = "2026-08-07";
|
|
2
|
+
export declare const PROVIDER_ERROR_CATEGORIES: readonly ["ok", "timeout", "network", "upstream_http", "upstream_rate_limited", "upstream_auth", "upstream_rejected", "upstream_schema_drift", "proxy_pool", "anti_bot_blocked", "credential_expired", "credential_unavailable", "input_validation", "output_validation", "provider_error", "internal_error", "dependency_unavailable", "unsupported_transport", "client_cancelled", "unclassified"];
|
|
3
3
|
export type ProviderErrorCategory = (typeof PROVIDER_ERROR_CATEGORIES)[number];
|
|
4
4
|
export declare function categoryForStatus(status: number): ProviderErrorCategory;
|
|
5
5
|
export declare function isRetryableCategory(category: ProviderErrorCategory): boolean;
|
|
6
|
+
export declare const PROVIDER_ERROR_SOURCES: readonly ["client", "upstream_rule", "upstream_failure", "apifuse"];
|
|
7
|
+
export type ProviderErrorSource = (typeof PROVIDER_ERROR_SOURCES)[number];
|
|
8
|
+
export declare function sourceForCategory(category: ProviderErrorCategory): ProviderErrorSource;
|
package/dist/observability.js
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
|
|
1
|
+
// Mirrors packages/provider-observability in the platform monorepo (SoT).
|
|
2
|
+
export const PROVIDER_OBSERVABILITY_TAXONOMY_VERSION = "2026-08-07";
|
|
2
3
|
export const PROVIDER_ERROR_CATEGORIES = [
|
|
3
4
|
"ok",
|
|
4
5
|
"timeout",
|
|
@@ -6,6 +7,7 @@ export const PROVIDER_ERROR_CATEGORIES = [
|
|
|
6
7
|
"upstream_http",
|
|
7
8
|
"upstream_rate_limited",
|
|
8
9
|
"upstream_auth",
|
|
10
|
+
"upstream_rejected",
|
|
9
11
|
"upstream_schema_drift",
|
|
10
12
|
"proxy_pool",
|
|
11
13
|
"anti_bot_blocked",
|
|
@@ -15,6 +17,9 @@ export const PROVIDER_ERROR_CATEGORIES = [
|
|
|
15
17
|
"output_validation",
|
|
16
18
|
"provider_error",
|
|
17
19
|
"internal_error",
|
|
20
|
+
"dependency_unavailable",
|
|
21
|
+
"unsupported_transport",
|
|
22
|
+
"client_cancelled",
|
|
18
23
|
"unclassified",
|
|
19
24
|
];
|
|
20
25
|
export function categoryForStatus(status) {
|
|
@@ -26,6 +31,10 @@ export function categoryForStatus(status) {
|
|
|
26
31
|
return "upstream_rate_limited";
|
|
27
32
|
if (status === 401 || status === 403)
|
|
28
33
|
return "upstream_auth";
|
|
34
|
+
// provider-error-contract: 409/410/422 are the deterministic
|
|
35
|
+
// upstream-rejection status class — not a retryable upstream failure.
|
|
36
|
+
if (status === 409 || status === 410 || status === 422)
|
|
37
|
+
return "upstream_rejected";
|
|
29
38
|
if (status >= 400)
|
|
30
39
|
return "upstream_http";
|
|
31
40
|
return "unclassified";
|
|
@@ -37,3 +46,41 @@ export function isRetryableCategory(category) {
|
|
|
37
46
|
category === "upstream_http" ||
|
|
38
47
|
category === "proxy_pool");
|
|
39
48
|
}
|
|
49
|
+
// Who stopped the request (honest-provider-error-contract). A deliberately
|
|
50
|
+
// small public projection of the internal taxonomy:
|
|
51
|
+
// - client: the request itself is fixable by the caller
|
|
52
|
+
// - upstream_rule: the upstream service refused it under its own business
|
|
53
|
+
// rules (deterministic) or rate limits
|
|
54
|
+
// - upstream_failure: the upstream service malfunctioned — retryable
|
|
55
|
+
// - apifuse: an APIFuse-side fault (provider bug, platform dependency)
|
|
56
|
+
export const PROVIDER_ERROR_SOURCES = [
|
|
57
|
+
"client",
|
|
58
|
+
"upstream_rule",
|
|
59
|
+
"upstream_failure",
|
|
60
|
+
"apifuse",
|
|
61
|
+
];
|
|
62
|
+
export function sourceForCategory(category) {
|
|
63
|
+
switch (category) {
|
|
64
|
+
case "input_validation":
|
|
65
|
+
case "credential_expired":
|
|
66
|
+
case "credential_unavailable":
|
|
67
|
+
case "client_cancelled":
|
|
68
|
+
return "client";
|
|
69
|
+
case "upstream_rejected":
|
|
70
|
+
case "upstream_rate_limited":
|
|
71
|
+
return "upstream_rule";
|
|
72
|
+
case "timeout":
|
|
73
|
+
case "network":
|
|
74
|
+
case "upstream_http":
|
|
75
|
+
case "upstream_auth":
|
|
76
|
+
case "upstream_schema_drift":
|
|
77
|
+
case "anti_bot_blocked":
|
|
78
|
+
return "upstream_failure";
|
|
79
|
+
default:
|
|
80
|
+
// ok never reaches error serialization; provider_error,
|
|
81
|
+
// internal_error, output_validation, proxy_pool,
|
|
82
|
+
// dependency_unavailable, unsupported_transport, unclassified are
|
|
83
|
+
// APIFuse-side faults.
|
|
84
|
+
return "apifuse";
|
|
85
|
+
}
|
|
86
|
+
}
|
package/dist/provider.d.ts
CHANGED
|
@@ -1,11 +1,12 @@
|
|
|
1
|
-
export { AuthAbortError, credentialsAuthChallenge, createAuthFlowHelpers, defineCredentialsAuth, } from "./auth";
|
|
2
|
-
export type { CredentialsAuthChallengeDefinition, CredentialsAuthChallengeRequest, CredentialsAuthCompleteResult, CredentialsAuthCredential, CredentialsAuthField, CredentialsAuthFields, CredentialsAuthFieldType, CredentialsAuthInput, CredentialsAuthLoginResult, DefineCredentialsAuthOptions, DefinedCredentialsAuth, } from "./auth";
|
|
3
|
-
export { createFormCeremony } from "./ceremonies";
|
|
4
|
-
export { assertFreshProviderChoiceIssuedAt, createProviderChoiceToken, ProviderChoiceTokenError, type ProviderChoiceTokenErrorReason, type ProviderChoiceTokenPayload, parseProviderChoiceToken, } from "./choice-token";
|
|
5
|
-
export { centered, delayed, defineHealthJourney, defineOperation, defineProvider, defineSmsOtpMatcher, every, } from "./define";
|
|
6
|
-
export { AuthError, ProviderError, SessionExpiredError, TransportError, ValidationError, } from "./errors";
|
|
7
|
-
export { getProviderLocalePath, providerLocaleKey, qualifyProviderLocaleKey, } from "./i18n";
|
|
8
|
-
export { type CreateProviderChoiceContextOptions, createProviderChoiceContext, createTestProviderChoiceContext, PROVIDER_RUNTIME_CHOICE_TOKEN_MASTER_SECRET_ENV, } from "./runtime/choice";
|
|
9
|
-
export { APIFUSE_DESCRIPTION_KEY_META_KEY, APIFUSE_REDACTION_MARKER, APIFUSE_SENSITIVE_KIND_META_KEY, APIFUSE_SENSITIVE_META_KEY, collectSensitivePaths, describeKey, field, fields, isSensitiveSchema, redactPayload, type SensitiveFieldKind, type SensitiveFieldOptions, type SensitivePath, sensitive, z, } from "./schema";
|
|
10
|
-
export type { AuthAbortData, AuthAbortRetry, AuthFlowTerminalContext, AuthMode, AuthSafeData, AuthSafeJson, FlowContext, HealthCheckAssertionContext, HealthCheckCase, HealthCheckSuite, HealthCheckUnsupported, HealthJourneyDefinition, HealthJourneyEventContext, HealthJourneyManualTriggerPolicy, HealthJourneyRunContext, HealthJourneyRunResult, HealthScheduleRandomization, HttpRetryOptions, HttpRetrySummary, InferSchemaOutput, OperationApprovalPolicy, OperationContractMetadata, OperationDefinition, OperationDocMeta, OperationErrorCode, OperationInputExample, OperationLifecycle, OperationObservabilityConfig, OperationObservabilitySensitiveConfig, OperationRelationships, OperationRiskClass, OperationSensitivePath, OperationToolRouterMetadata, OperationTransport, ProviderAccessVisibility, ProviderChoiceBindingOptions, ProviderChoiceContext, ProviderChoiceIssueOptions, ProviderChoiceParseOptions, ProviderContext, ProviderDefinition, ProviderLocale, ProviderLocaleKey, ProviderLocaleKeyInput, ProviderLogoProfile, ProviderProxyPolicy, ProviderPublicConnectionMode, ProviderPublicProfile, ProviderRuntimeState, ProviderStateDurationString, ProviderStateNamespace, ProviderSupportLevel, SchemaLike, SmsOtpMatcherDefinition, StandardSchemaV1, StateCasResult, StateNamespaceOptions, StateValue, StateWriteOptions, } from "./types";
|
|
11
|
-
export {
|
|
1
|
+
export { AuthAbortError, credentialsAuthChallenge, createAuthFlowHelpers, defineCredentialsAuth, } from "./auth.js";
|
|
2
|
+
export type { CredentialsAuthChallengeDefinition, CredentialsAuthChallengeRequest, CredentialsAuthCompleteResult, CredentialsAuthCredential, CredentialsAuthField, CredentialsAuthFields, CredentialsAuthFieldType, CredentialsAuthInput, CredentialsAuthLoginResult, DefineCredentialsAuthOptions, DefinedCredentialsAuth, } from "./auth.js";
|
|
3
|
+
export { createFormCeremony } from "./ceremonies/index.js";
|
|
4
|
+
export { assertFreshProviderChoiceIssuedAt, createProviderChoiceToken, ProviderChoiceTokenError, type ProviderChoiceTokenErrorReason, type ProviderChoiceTokenPayload, parseProviderChoiceToken, } from "./choice-token.js";
|
|
5
|
+
export { centered, delayed, defineHealthJourney, defineOperation, defineProvider, defineSmsOtpMatcher, every, } from "./define.js";
|
|
6
|
+
export { AuthError, HttpRedirectError, isProviderError, isSessionExpiredError, isTransportError, ProviderError, SessionExpiredError, TransportError, ValidationError, } from "./errors.js";
|
|
7
|
+
export { getProviderLocalePath, providerLocaleKey, qualifyProviderLocaleKey, } from "./i18n/index.js";
|
|
8
|
+
export { type CreateProviderChoiceContextOptions, createProviderChoiceContext, createTestProviderChoiceContext, PROVIDER_RUNTIME_CHOICE_TOKEN_MASTER_SECRET_ENV, } from "./runtime/choice.js";
|
|
9
|
+
export { APIFUSE_DESCRIPTION_KEY_META_KEY, APIFUSE_REDACTION_MARKER, APIFUSE_SENSITIVE_KIND_META_KEY, APIFUSE_SENSITIVE_META_KEY, collectSensitivePaths, describeKey, field, fields, isSensitiveSchema, redactPayload, type SensitiveFieldKind, type SensitiveFieldOptions, type SensitivePath, sensitive, z, } from "./schema.js";
|
|
10
|
+
export type { AuthAbortData, AuthAbortRetry, AuthFlowTerminalContext, AuthMode, AuthSafeData, AuthSafeJson, FlowContext, HealthCheckAssertionContext, HealthCheckCase, HealthCheckSuite, HealthCheckUnsupported, HealthJourneyDefinition, HealthJourneyEventContext, HealthJourneyManualTriggerPolicy, HealthJourneyRunContext, HealthJourneyRunResult, HealthScheduleRandomization, HttpRedirectFailureReason, HttpRedirectPolicy, HttpRedirectPolicyMode, HttpRetryOptions, HttpRetrySummary, InferSchemaOutput, NativeContext, NativeNetworkClient, NativeNetworkCloseReason, NativeNetworkConnection, NativeNetworkConnectInput, NativeNetworkConnectOptions, NativeNetworkDynamicGrantOptions, NativeNetworkEgressGrant, NativeProviderConfig, NativeProviderContext, NativeProxyDrainHandler, NativeProxyEgressInfo, NativeProxyExpiringEvent, NativeProxyExpiringReason, NativeTcpDynamicEgressRule, NativeTcpEgressGrant, NativeTcpEgressRule, NativeTcpPortRange, NativeTcpTlsMode, NativeTlsConnectOptions, OperationApprovalPolicy, OperationContractMetadata, OperationDefinition, OperationDocMeta, OperationErrorCode, ProviderErrorStatus, OperationInputExample, OperationLifecycle, OperationObservabilityConfig, OperationObservabilitySensitiveConfig, OperationRelationships, OperationRiskClass, OperationSensitivePath, OperationToolRouterMetadata, OperationTransport, ProviderAccessVisibility, ProviderChoiceBindingOptions, ProviderChoiceContext, ProviderChoiceIssueOptions, ProviderChoiceParseOptions, ProviderContext, ProviderDefinition, ProviderDeploymentOverrides, ProviderFileRef, ProviderFilesContext, ProviderLocale, ProviderLocaleKey, ProviderLocaleKeyInput, ProviderLogoProfile, ProviderProxyPolicy, ProxiedOAuthConfig, ProviderPublicConnectionMode, ProviderPublicProfile, ProviderResolvedFile, ProviderRuntimeState, ProviderStateDurationString, ProviderStateNamespace, ProviderSupportLevel, RedirectRunReason, SchemaLike, SmsOtpMatcherDefinition, StandardSchemaV1, StateCasResult, StateNamespaceOptions, StateValue, StateWriteOptions, } from "./types.js";
|
|
11
|
+
export { createNativeNetworkClient, createEnvVendorCredentialResolver, deriveNativeCredentialAffinityKey, NativeEgressGrantExpiredError, NativeEgressNotDeclaredError, NativeIdleTimeoutError, NativeNetworkError, NativeProxyExpiredError, resolveNativeGatewayProxy, type NativeGatewayProxy, type NativeGatewayProxyResolutionInput, type NativeGatewayProxySkipReason, type NativeGatewayProxySynthesizer, type NativeGatewayProxySynthesisResult, type NativeGatewayProxySynthesisInput, type NativeNetworkClientOptions, type NativeNetworkErrorCode, type VendorCredentialLookup, type VendorCredentialResolver, } from "./runtime/native-network.js";
|
|
12
|
+
export { HttpRetryAfterPolicy, HttpRetryDelayStrategy, HttpRetryJitter, HttpRetryPreset, HttpRetryUnsafeMethodPolicy, } from "./types.js";
|
package/dist/provider.js
CHANGED
|
@@ -1,9 +1,10 @@
|
|
|
1
|
-
export { AuthAbortError, credentialsAuthChallenge, createAuthFlowHelpers, defineCredentialsAuth, } from "./auth";
|
|
2
|
-
export { createFormCeremony } from "./ceremonies";
|
|
3
|
-
export { assertFreshProviderChoiceIssuedAt, createProviderChoiceToken, ProviderChoiceTokenError, parseProviderChoiceToken, } from "./choice-token";
|
|
4
|
-
export { centered, delayed, defineHealthJourney, defineOperation, defineProvider, defineSmsOtpMatcher, every, } from "./define";
|
|
5
|
-
export { AuthError, ProviderError, SessionExpiredError, TransportError, ValidationError, } from "./errors";
|
|
6
|
-
export { getProviderLocalePath, providerLocaleKey, qualifyProviderLocaleKey, } from "./i18n";
|
|
7
|
-
export { createProviderChoiceContext, createTestProviderChoiceContext, PROVIDER_RUNTIME_CHOICE_TOKEN_MASTER_SECRET_ENV, } from "./runtime/choice";
|
|
8
|
-
export { APIFUSE_DESCRIPTION_KEY_META_KEY, APIFUSE_REDACTION_MARKER, APIFUSE_SENSITIVE_KIND_META_KEY, APIFUSE_SENSITIVE_META_KEY, collectSensitivePaths, describeKey, field, fields, isSensitiveSchema, redactPayload, sensitive, z, } from "./schema";
|
|
9
|
-
export {
|
|
1
|
+
export { AuthAbortError, credentialsAuthChallenge, createAuthFlowHelpers, defineCredentialsAuth, } from "./auth.js";
|
|
2
|
+
export { createFormCeremony } from "./ceremonies/index.js";
|
|
3
|
+
export { assertFreshProviderChoiceIssuedAt, createProviderChoiceToken, ProviderChoiceTokenError, parseProviderChoiceToken, } from "./choice-token.js";
|
|
4
|
+
export { centered, delayed, defineHealthJourney, defineOperation, defineProvider, defineSmsOtpMatcher, every, } from "./define.js";
|
|
5
|
+
export { AuthError, HttpRedirectError, isProviderError, isSessionExpiredError, isTransportError, ProviderError, SessionExpiredError, TransportError, ValidationError, } from "./errors.js";
|
|
6
|
+
export { getProviderLocalePath, providerLocaleKey, qualifyProviderLocaleKey, } from "./i18n/index.js";
|
|
7
|
+
export { createProviderChoiceContext, createTestProviderChoiceContext, PROVIDER_RUNTIME_CHOICE_TOKEN_MASTER_SECRET_ENV, } from "./runtime/choice.js";
|
|
8
|
+
export { APIFUSE_DESCRIPTION_KEY_META_KEY, APIFUSE_REDACTION_MARKER, APIFUSE_SENSITIVE_KIND_META_KEY, APIFUSE_SENSITIVE_META_KEY, collectSensitivePaths, describeKey, field, fields, isSensitiveSchema, redactPayload, sensitive, z, } from "./schema.js";
|
|
9
|
+
export { createNativeNetworkClient, createEnvVendorCredentialResolver, deriveNativeCredentialAffinityKey, NativeEgressGrantExpiredError, NativeEgressNotDeclaredError, NativeIdleTimeoutError, NativeNetworkError, NativeProxyExpiredError, resolveNativeGatewayProxy, } from "./runtime/native-network.js";
|
|
10
|
+
export { HttpRetryAfterPolicy, HttpRetryDelayStrategy, HttpRetryJitter, HttpRetryPreset, HttpRetryUnsafeMethodPolicy, } from "./types.js";
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import type { LintDiagnostic } from "./lint";
|
|
1
|
+
import type { LintDiagnostic } from "./lint.js";
|
|
2
2
|
export declare function lintPublicSchemaFieldNames(providerId: string | undefined, operationId: string, input: unknown, output: unknown, enforce: boolean): LintDiagnostic[];
|
package/dist/recipes/gov-api.js
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
|
-
import type { ContextScratchpad, EnvContext, FlowContext, HttpClient, StealthClient, SttContext } from "../types";
|
|
1
|
+
import type { ContextScratchpad, EnvContext, FlowContext, HttpClient, StealthClient, SttContext } from "../types.js";
|
|
2
2
|
export declare function createScratchpad(allowedKeys: string[], initial?: Record<string, unknown>): ContextScratchpad;
|
|
3
3
|
export declare function createFlowContext(options: {
|
|
4
|
+
flowId?: string;
|
|
4
5
|
http: HttpClient;
|
|
5
6
|
stealth: StealthClient;
|
|
6
7
|
env: EnvContext;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { ContextAccessError } from "../errors";
|
|
2
|
-
import { createAuthFlowHelpers } from "../auth";
|
|
3
|
-
import { createUnsupportedSttClient } from "./stt";
|
|
1
|
+
import { ContextAccessError } from "../errors.js";
|
|
2
|
+
import { createAuthFlowHelpers } from "../auth.js";
|
|
3
|
+
import { createUnsupportedSttClient } from "./stt.js";
|
|
4
4
|
function normalizeAllowedKeys(allowedKeys) {
|
|
5
5
|
return new Set(allowedKeys.filter((key) => key.trim().length > 0));
|
|
6
6
|
}
|
|
@@ -32,6 +32,7 @@ export function createScratchpad(allowedKeys, initial = {}) {
|
|
|
32
32
|
}
|
|
33
33
|
export function createFlowContext(options) {
|
|
34
34
|
return {
|
|
35
|
+
flowId: options.flowId,
|
|
35
36
|
connectionId: options.connectionId,
|
|
36
37
|
externalRef: options.externalRef,
|
|
37
38
|
tenantId: options.tenantId,
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { BrowserChallengeRequest, BrowserChallengeResult, BrowserClient as BrowserClientContract, BrowserEngine, BrowserOptions, BrowserPage } from "../types";
|
|
1
|
+
import type { BrowserChallengeRequest, BrowserChallengeResult, BrowserClient as BrowserClientContract, BrowserEngine, BrowserOptions, BrowserPage } from "../types.js";
|
|
2
2
|
type BrowserPageContract = BrowserPage;
|
|
3
3
|
export type BrowserClientOptions = BrowserOptions & {
|
|
4
4
|
allowedHosts?: string[];
|
package/dist/runtime/browser.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { createRequire } from "node:module";
|
|
2
|
-
import { ProviderError } from "../errors";
|
|
2
|
+
import { ProviderError } from "../errors.js";
|
|
3
3
|
const require = createRequire(import.meta.url);
|
|
4
4
|
const DEFAULT_WAIT_TIMEOUT_MS = 30_000;
|
|
5
5
|
const SELECTOR_POLL_INTERVAL_MS = 100;
|
|
@@ -83,13 +83,14 @@ function matchesResourceRoute(match, request) {
|
|
|
83
83
|
function toCdpFulfillParams(requestId, decision) {
|
|
84
84
|
const body = toResourceBody(decision.body);
|
|
85
85
|
return {
|
|
86
|
-
...(body === undefined
|
|
87
|
-
? {}
|
|
88
|
-
: { body: Buffer.from(body).toString("base64") }),
|
|
86
|
+
...(body === undefined ? {} : { body: Buffer.from(body).toString("base64") }),
|
|
89
87
|
...(decision.headers === undefined
|
|
90
88
|
? {}
|
|
91
89
|
: {
|
|
92
|
-
responseHeaders: Object.entries(decision.headers).map(([name, value]) => ({
|
|
90
|
+
responseHeaders: Object.entries(decision.headers).map(([name, value]) => ({
|
|
91
|
+
name,
|
|
92
|
+
value,
|
|
93
|
+
})),
|
|
93
94
|
}),
|
|
94
95
|
requestId,
|
|
95
96
|
responseCode: decision.status ?? 200,
|
|
@@ -574,16 +575,13 @@ function parsePoolAcquireResponse(value) {
|
|
|
574
575
|
code: "BROWSER_RUNTIME_UNSUPPORTED",
|
|
575
576
|
});
|
|
576
577
|
}
|
|
577
|
-
if (value.browserContextId !== undefined &&
|
|
578
|
-
typeof value.browserContextId !== "string") {
|
|
578
|
+
if (value.browserContextId !== undefined && typeof value.browserContextId !== "string") {
|
|
579
579
|
throw new ProviderError("CDP Pool returned an invalid acquire response", {
|
|
580
580
|
code: "BROWSER_RUNTIME_UNSUPPORTED",
|
|
581
581
|
});
|
|
582
582
|
}
|
|
583
583
|
return {
|
|
584
|
-
...(value.browserContextId
|
|
585
|
-
? { browserContextId: value.browserContextId }
|
|
586
|
-
: {}),
|
|
584
|
+
...(value.browserContextId ? { browserContextId: value.browserContextId } : {}),
|
|
587
585
|
pageId: value.pageId,
|
|
588
586
|
wsEndpoint: value.wsEndpoint,
|
|
589
587
|
};
|
|
@@ -605,9 +603,7 @@ function parseCdpFrameTreeNode(value) {
|
|
|
605
603
|
frame: {
|
|
606
604
|
id: frameId,
|
|
607
605
|
name: typeof value.frame.name === "string" ? value.frame.name : undefined,
|
|
608
|
-
parentId: typeof value.frame.parentId === "string"
|
|
609
|
-
? value.frame.parentId
|
|
610
|
-
: undefined,
|
|
606
|
+
parentId: typeof value.frame.parentId === "string" ? value.frame.parentId : undefined,
|
|
611
607
|
url: typeof value.frame.url === "string" ? value.frame.url : undefined,
|
|
612
608
|
},
|
|
613
609
|
...(childFrames ? { childFrames } : {}),
|
|
@@ -620,9 +616,7 @@ function getCdpExecutionContext(params) {
|
|
|
620
616
|
const contextId = params.context.id;
|
|
621
617
|
const auxData = params.context.auxData;
|
|
622
618
|
return {
|
|
623
|
-
frameId: isRecord(auxData) && typeof auxData.frameId === "string"
|
|
624
|
-
? auxData.frameId
|
|
625
|
-
: undefined,
|
|
619
|
+
frameId: isRecord(auxData) && typeof auxData.frameId === "string" ? auxData.frameId : undefined,
|
|
626
620
|
id: typeof contextId === "number" ? contextId : undefined,
|
|
627
621
|
};
|
|
628
622
|
}
|
|
@@ -773,8 +767,7 @@ class CdpPoolBrowserPage {
|
|
|
773
767
|
returnByValue: true,
|
|
774
768
|
});
|
|
775
769
|
if (result.exceptionDetails) {
|
|
776
|
-
throw new Error(String(result.exceptionDetails.text ??
|
|
777
|
-
"Browser evaluation failed"));
|
|
770
|
+
throw new Error(String(result.exceptionDetails.text ?? "Browser evaluation failed"));
|
|
778
771
|
}
|
|
779
772
|
return result.result?.value;
|
|
780
773
|
}
|
|
@@ -859,9 +852,7 @@ class CdpPoolBrowserPage {
|
|
|
859
852
|
this.closed = true;
|
|
860
853
|
try {
|
|
861
854
|
await this.release({
|
|
862
|
-
...(this.browserContextId
|
|
863
|
-
? { browserContextId: this.browserContextId }
|
|
864
|
-
: {}),
|
|
855
|
+
...(this.browserContextId ? { browserContextId: this.browserContextId } : {}),
|
|
865
856
|
pageId: this.pageId,
|
|
866
857
|
});
|
|
867
858
|
}
|
|
@@ -1002,12 +993,8 @@ class CdpPoolBrowserClient {
|
|
|
1002
993
|
}
|
|
1003
994
|
async acquirePage(options) {
|
|
1004
995
|
const acquireResult = parsePoolAcquireResponse(await this.poolClient.send("acquire", {
|
|
1005
|
-
...(this.allowedHosts.length > 0
|
|
1006
|
-
|
|
1007
|
-
: {}),
|
|
1008
|
-
...(options?.isolatedContext
|
|
1009
|
-
? { isolationMode: "browserContext" }
|
|
1010
|
-
: {}),
|
|
996
|
+
...(this.allowedHosts.length > 0 ? { allowedHosts: this.allowedHosts } : {}),
|
|
997
|
+
...(options?.isolatedContext ? { isolationMode: "browserContext" } : {}),
|
|
1011
998
|
}));
|
|
1012
999
|
const pageClient = new JsonRpcWebSocketClient(acquireResult.wsEndpoint);
|
|
1013
1000
|
const page = new CdpPoolBrowserPage(acquireResult.pageId, acquireResult.browserContextId, pageClient, async (request) => {
|
|
@@ -1223,8 +1210,7 @@ async function solveRecaptchaChallenge(page, request) {
|
|
|
1223
1210
|
async function findRecaptchaFrame(frames, siteKey) {
|
|
1224
1211
|
for (const frame of frames) {
|
|
1225
1212
|
const url = await frame.url();
|
|
1226
|
-
const matchesRecaptcha = url.includes("google.com/recaptcha") ||
|
|
1227
|
-
url.includes("recaptcha.net/recaptcha");
|
|
1213
|
+
const matchesRecaptcha = url.includes("google.com/recaptcha") || url.includes("recaptcha.net/recaptcha");
|
|
1228
1214
|
const matchesSiteKey = !siteKey || url.includes(siteKey);
|
|
1229
1215
|
if (matchesRecaptcha && matchesSiteKey) {
|
|
1230
1216
|
return frame;
|
package/dist/runtime/cache.d.ts
CHANGED
package/dist/runtime/cache.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { createHash } from "node:crypto";
|
|
2
|
-
import { providerCacheRedisUrlFromEnv } from "../config/loader";
|
|
3
|
-
import { createProviderRedisClient, ensureRedisReady, withRedisTimeout, } from "./redis";
|
|
2
|
+
import { providerCacheRedisUrlFromEnv } from "../config/loader.js";
|
|
3
|
+
import { createProviderRedisClient, ensureRedisReady, withRedisTimeout, } from "./redis.js";
|
|
4
4
|
const DEFAULT_PREFIX = "apifuse:provider-cache:v1";
|
|
5
5
|
const DEFAULT_MEMORY_MAX_ENTRIES = 1_000;
|
|
6
6
|
const DEFAULT_REDIS_TIMEOUT_MS = 150;
|
|
@@ -71,10 +71,7 @@ function normalizeKeyPart(value, extra) {
|
|
|
71
71
|
return value;
|
|
72
72
|
}
|
|
73
73
|
function stableHash(value) {
|
|
74
|
-
return createHash("sha256")
|
|
75
|
-
.update(JSON.stringify(value))
|
|
76
|
-
.digest("hex")
|
|
77
|
-
.slice(0, 32);
|
|
74
|
+
return createHash("sha256").update(JSON.stringify(value)).digest("hex").slice(0, 32);
|
|
78
75
|
}
|
|
79
76
|
function jitteredTtlMs(ttlMs, jitterPct) {
|
|
80
77
|
if (!jitterPct || jitterPct <= 0)
|
|
@@ -282,8 +279,7 @@ export function createProviderCache(options) {
|
|
|
282
279
|
async delete(key) {
|
|
283
280
|
backend.memory.delete(key);
|
|
284
281
|
const redis = backend.redis;
|
|
285
|
-
if (!redis ||
|
|
286
|
-
!(await ensureRedisReady(redis, DEFAULT_REDIS_TIMEOUT_MS))) {
|
|
282
|
+
if (!redis || !(await ensureRedisReady(redis, DEFAULT_REDIS_TIMEOUT_MS))) {
|
|
287
283
|
return;
|
|
288
284
|
}
|
|
289
285
|
await withRedisFallback(() => redis.del(key));
|
package/dist/runtime/choice.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { CredentialContext, EnvContext, ProviderChoiceContext, ProviderRequestContext, ProviderRuntimeState } from "../types";
|
|
1
|
+
import type { CredentialContext, EnvContext, ProviderChoiceContext, ProviderRequestContext, ProviderRuntimeState } from "../types.js";
|
|
2
2
|
export declare const PROVIDER_RUNTIME_CHOICE_TOKEN_MASTER_SECRET_ENV = "APIFUSE__PROVIDER_RUNTIME__CHOICE_TOKEN_MASTER_SECRET";
|
|
3
3
|
export type CreateProviderChoiceContextOptions = {
|
|
4
4
|
readonly providerId: string;
|