@apifuse/provider-sdk 2.2.0-beta.3 → 2.2.0-beta.31
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 +493 -5
- package/CHANGELOG.md +131 -1
- package/README.md +52 -6
- package/SUBMISSION.md +1 -1
- package/bin/apifuse-check.ts +106 -62
- package/bin/apifuse-create.ts +1 -1
- package/bin/apifuse-dev.ts +63 -55
- package/bin/apifuse-pack-check.ts +22 -2
- package/bin/apifuse-pack-smoke.ts +78 -82
- package/bin/apifuse-pack-types.ts +583 -0
- package/bin/apifuse-perf.ts +59 -140
- package/bin/apifuse-record.ts +698 -113
- package/bin/apifuse-submit-check.ts +517 -44
- 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.ts +1 -1
- package/dist/auth-turn/index.d.ts +4 -4
- package/dist/auth-turn/index.js +1 -1
- package/dist/auth.d.ts +16 -2
- package/dist/auth.js +76 -18
- package/dist/ceremonies/index.d.ts +9 -1
- package/dist/ceremonies/index.js +117 -29
- 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/cli/templates/provider/README.md.tpl +4 -4
- package/dist/config/loader.d.ts +176 -17
- package/dist/config/loader.js +434 -161
- package/dist/contract-serialization.d.ts +2 -2
- package/dist/contract-serialization.js +7 -14
- package/dist/contract-types.d.ts +3 -2
- package/dist/contract.d.ts +3 -3
- package/dist/contract.js +6 -6
- package/dist/declaration-validation.d.ts +23 -0
- package/dist/declaration-validation.js +159 -0
- package/dist/define.d.ts +13 -1
- package/dist/define.js +391 -122
- package/dist/dev.d.ts +1 -1
- package/dist/dev.js +1 -1
- package/dist/error-resolution.d.ts +4 -0
- package/dist/error-resolution.js +123 -0
- package/dist/errors.d.ts +19 -1
- package/dist/errors.js +41 -3
- 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 +50 -42
- package/dist/index.js +41 -37
- package/dist/lint.d.ts +6 -1
- package/dist/lint.js +370 -18
- 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 +13 -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 +3 -1
- package/dist/runtime/auth-flow.js +8 -3
- package/dist/runtime/browser.d.ts +1 -1
- package/dist/runtime/browser.js +138 -40
- package/dist/runtime/cache.d.ts +2 -1
- package/dist/runtime/cache.js +173 -23
- package/dist/runtime/choice-wordlist.d.ts +9 -0
- package/dist/runtime/choice-wordlist.js +138 -0
- package/dist/runtime/choice.d.ts +14 -1
- package/dist/runtime/choice.js +566 -101
- 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 +25 -3
- package/dist/runtime/http.d.ts +3 -2
- package/dist/runtime/http.js +517 -55
- 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 +371 -23
- package/dist/runtime/keyring.js +1 -1
- package/dist/runtime/namespace.js +1 -1
- 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 +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 +58 -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 +5 -5
- 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 +3 -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 +20 -0
- package/dist/runtime/resolver-vendors/browser.js +282 -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 +368 -0
- package/dist/runtime/resolver-vendors/types.d.ts +83 -0
- package/dist/runtime/resolver-vendors/types.js +69 -0
- package/dist/runtime/resolver.d.ts +59 -0
- package/dist/runtime/resolver.js +705 -0
- package/dist/runtime/secrets.d.ts +27 -0
- package/dist/runtime/secrets.js +51 -0
- package/dist/runtime/state.d.ts +5 -2
- package/dist/runtime/state.js +280 -74
- package/dist/runtime/stealth-cookies.d.ts +20 -0
- package/dist/runtime/stealth-cookies.js +111 -0
- package/dist/runtime/stealth.d.ts +30 -5
- package/dist/runtime/stealth.js +523 -259
- package/dist/runtime/stt.d.ts +1 -1
- package/dist/runtime/stt.js +12 -27
- package/dist/runtime/timeout.d.ts +5 -0
- package/dist/runtime/timeout.js +12 -0
- 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 +117 -3
- package/dist/server/self-test.js +787 -151
- package/dist/server/serve-implementation.d.ts +210 -0
- package/dist/server/serve-implementation.js +2078 -0
- package/dist/server/serve.d.ts +1 -70
- package/dist/server/serve.js +1 -1143
- package/dist/server/types.d.ts +34 -9
- package/dist/server/types.js +8 -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 +1 -1
- package/dist/stealth/profiles.js +21 -21
- package/dist/stream-evidence.d.ts +74 -0
- package/dist/stream-evidence.js +785 -0
- package/dist/stream.d.ts +1 -1
- package/dist/stream.js +7 -1
- package/dist/testing/index.d.ts +3 -2
- package/dist/testing/index.js +3 -2
- package/dist/testing/run.d.ts +32 -2
- package/dist/testing/run.js +488 -28
- package/dist/types.d.ts +566 -19
- package/dist/types.js +1 -0
- package/dist/user-input.d.ts +30 -0
- package/dist/user-input.js +66 -0
- package/package.json +42 -7
- package/src/auth-turn/index.ts +2 -2
- package/src/auth.ts +146 -86
- package/src/ceremonies/index.ts +167 -92
- 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/cli/templates/provider/README.md.tpl +4 -4
- package/src/config/loader.ts +667 -289
- package/src/contract-serialization.ts +10 -18
- package/src/contract-types.ts +3 -2
- package/src/contract.ts +14 -28
- package/src/declaration-validation.ts +202 -0
- package/src/define.ts +631 -495
- package/src/dev.ts +4 -9
- package/src/error-resolution.ts +128 -0
- package/src/errors.ts +56 -11
- 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 +158 -44
- package/src/lint.ts +488 -154
- 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 +13 -7
- package/src/runtime/browser.ts +252 -207
- package/src/runtime/cache.ts +209 -81
- package/src/runtime/choice-wordlist.ts +145 -0
- package/src/runtime/choice.ts +758 -197
- package/src/runtime/credential.ts +2 -2
- package/src/runtime/env.ts +1 -1
- package/src/runtime/executor.ts +37 -19
- package/src/runtime/http.ts +645 -65
- package/src/runtime/insights.ts +15 -53
- package/src/runtime/instrumentation.ts +530 -67
- package/src/runtime/keyring.ts +7 -19
- package/src/runtime/namespace.ts +2 -7
- 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 +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 +84 -77
- package/src/runtime/redirects.ts +66 -0
- package/src/runtime/redis.ts +10 -13
- package/src/runtime/request-options.ts +679 -9
- package/src/runtime/resolver-config.ts +6 -0
- package/src/runtime/resolver-public.ts +18 -0
- package/src/runtime/resolver-shared.ts +17 -0
- package/src/runtime/resolver-vendors/bindings.ts +56 -0
- package/src/runtime/resolver-vendors/browser.ts +408 -0
- package/src/runtime/resolver-vendors/hosts.ts +38 -0
- package/src/runtime/resolver-vendors/twocaptcha.ts +500 -0
- package/src/runtime/resolver-vendors/types.ts +173 -0
- package/src/runtime/resolver.ts +1060 -0
- package/src/runtime/secrets.ts +64 -0
- package/src/runtime/state.ts +399 -161
- package/src/runtime/stealth-cookies.ts +132 -0
- package/src/runtime/stealth.ts +681 -295
- package/src/runtime/stt.ts +39 -113
- package/src/runtime/timeout.ts +18 -0
- package/src/runtime/trace.ts +14 -44
- package/src/runtime/waterfall.ts +5 -18
- package/src/schema.ts +23 -84
- package/src/serve.ts +6 -1
- package/src/server/index.ts +30 -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 +1030 -180
- package/src/server/serve-implementation.ts +3062 -0
- package/src/server/serve.ts +1 -1781
- package/src/server/types.ts +12 -13
- 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 +27 -33
- package/src/stream-evidence.ts +988 -0
- package/src/stream.ts +16 -20
- package/src/testing/index.ts +11 -2
- package/src/testing/run.ts +668 -74
- package/src/types.ts +665 -35
- 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
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,13 @@
|
|
|
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, isProviderError, isSessionExpiredError, isTransportError, 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, PROVIDER_RUNTIME_CHOICE_WORD_ISSUANCE_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, ProviderChoiceConsumeMode, ProviderChoiceConsumeResult, ProviderChoiceContext, ProviderChoiceExplicitParseResult, 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, StateNamespaceScope, StateValue, StateWriteOptions, } from "./types.js";
|
|
11
|
+
export { NativeEgressGrantExpiredError, NativeEgressNotDeclaredError, NativeIdleTimeoutError, NativeNetworkError, NativeProxyExpiredError, } from "./runtime/native-network-errors.js";
|
|
12
|
+
export type { NativeGatewayProxy, NativeGatewayProxyResolutionInput, NativeGatewayProxySkipReason, NativeGatewayProxySynthesizer, NativeGatewayProxySynthesisResult, NativeGatewayProxySynthesisInput, NativeNetworkClientOptions, NativeNetworkErrorCode, VendorCredentialLookup, VendorCredentialResolver, } from "./runtime/native-network.js";
|
|
13
|
+
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, isProviderError, isSessionExpiredError, isTransportError, 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, PROVIDER_RUNTIME_CHOICE_WORD_ISSUANCE_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 { NativeEgressGrantExpiredError, NativeEgressNotDeclaredError, NativeIdleTimeoutError, NativeNetworkError, NativeProxyExpiredError, } from "./runtime/native-network-errors.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, OcrContext, 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;
|
|
@@ -10,5 +11,6 @@ export declare function createFlowContext(options: {
|
|
|
10
11
|
externalRef?: string;
|
|
11
12
|
allowedKeys: string[];
|
|
12
13
|
initialContext?: Record<string, unknown>;
|
|
14
|
+
ocr?: OcrContext;
|
|
13
15
|
stt?: SttContext;
|
|
14
16
|
}): FlowContext;
|
|
@@ -1,6 +1,8 @@
|
|
|
1
|
-
import { ContextAccessError } from "../errors";
|
|
2
|
-
import { createAuthFlowHelpers } from "../auth";
|
|
3
|
-
import {
|
|
1
|
+
import { ContextAccessError } from "../errors.js";
|
|
2
|
+
import { createAuthFlowHelpers } from "../auth.js";
|
|
3
|
+
import { createUnsupportedOcrClient } from "./ocr.js";
|
|
4
|
+
import { createUnsupportedResolverClient } from "./resolver-shared.js";
|
|
5
|
+
import { createUnsupportedSttClient } from "./stt.js";
|
|
4
6
|
function normalizeAllowedKeys(allowedKeys) {
|
|
5
7
|
return new Set(allowedKeys.filter((key) => key.trim().length > 0));
|
|
6
8
|
}
|
|
@@ -32,6 +34,7 @@ export function createScratchpad(allowedKeys, initial = {}) {
|
|
|
32
34
|
}
|
|
33
35
|
export function createFlowContext(options) {
|
|
34
36
|
return {
|
|
37
|
+
flowId: options.flowId,
|
|
35
38
|
connectionId: options.connectionId,
|
|
36
39
|
externalRef: options.externalRef,
|
|
37
40
|
tenantId: options.tenantId,
|
|
@@ -40,7 +43,9 @@ export function createFlowContext(options) {
|
|
|
40
43
|
stealth: options.stealth,
|
|
41
44
|
env: options.env,
|
|
42
45
|
context: createScratchpad(options.allowedKeys, options.initialContext),
|
|
46
|
+
ocr: options.ocr ?? createUnsupportedOcrClient(),
|
|
43
47
|
stt: options.stt ?? createUnsupportedSttClient(),
|
|
48
|
+
resolver: createUnsupportedResolverClient("Resolver is not available in auth flow context"),
|
|
44
49
|
auth: createAuthFlowHelpers(),
|
|
45
50
|
};
|
|
46
51
|
}
|
|
@@ -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,
|
|
@@ -140,7 +141,13 @@ function formatExpression(fn) {
|
|
|
140
141
|
}
|
|
141
142
|
function toLaunchOptions(options) {
|
|
142
143
|
return {
|
|
143
|
-
|
|
144
|
+
// `extraArgs` is optional, but playwright-extra's stealth evasions mutate
|
|
145
|
+
// `options.args` unguarded (navigator.webdriver does
|
|
146
|
+
// `options.args.findIndex(...)` in beforeLaunch). Forwarding `undefined`
|
|
147
|
+
// therefore crashes every stealth launch that omits extraArgs with
|
|
148
|
+
// "TypeError: undefined is not an object (evaluating 'options.args.findIndex')".
|
|
149
|
+
// Always hand the launcher a concrete array.
|
|
150
|
+
args: options.extraArgs ?? [],
|
|
144
151
|
executablePath: options.executablePath,
|
|
145
152
|
headless: options.headless ?? true,
|
|
146
153
|
proxy: options.proxy ? { server: options.proxy } : undefined,
|
|
@@ -356,6 +363,9 @@ class PlaywrightBrowserPage {
|
|
|
356
363
|
async close() {
|
|
357
364
|
await this.page.close();
|
|
358
365
|
}
|
|
366
|
+
async cookies() {
|
|
367
|
+
return (await this.page.context().cookies()).map(toBrowserCookie);
|
|
368
|
+
}
|
|
359
369
|
async withResourcePolicy(policy, run) {
|
|
360
370
|
const allowedMethods = new Set(policy.allowedMethods ?? DEFAULT_RESOURCE_METHODS);
|
|
361
371
|
const handler = async (route) => {
|
|
@@ -456,7 +466,7 @@ function normalizeWebSocketEndpoint(endpoint) {
|
|
|
456
466
|
}
|
|
457
467
|
throw new Error(`Unsupported WebSocket endpoint protocol: ${url.protocol}`);
|
|
458
468
|
}
|
|
459
|
-
class
|
|
469
|
+
class WebSocketCommandClient {
|
|
460
470
|
nextId = 1;
|
|
461
471
|
endpoint;
|
|
462
472
|
listeners = new Map();
|
|
@@ -482,12 +492,7 @@ class JsonRpcWebSocketClient {
|
|
|
482
492
|
const id = this.nextId++;
|
|
483
493
|
return await new Promise((resolve, reject) => {
|
|
484
494
|
this.pending.set(id, { resolve, reject });
|
|
485
|
-
socket.send(JSON.stringify(
|
|
486
|
-
id,
|
|
487
|
-
jsonrpc: "2.0",
|
|
488
|
-
method,
|
|
489
|
-
params,
|
|
490
|
-
}));
|
|
495
|
+
socket.send(JSON.stringify(this.createCommandFrame(id, method, params)));
|
|
491
496
|
});
|
|
492
497
|
}
|
|
493
498
|
async close() {
|
|
@@ -525,7 +530,11 @@ class JsonRpcWebSocketClient {
|
|
|
525
530
|
}
|
|
526
531
|
this.pending.delete(payload.id);
|
|
527
532
|
if (payload.error) {
|
|
528
|
-
|
|
533
|
+
const error = new Error(payload.error.message ?? "JSON-RPC command failed");
|
|
534
|
+
if (typeof payload.error.code === "number") {
|
|
535
|
+
Object.assign(error, { code: payload.error.code });
|
|
536
|
+
}
|
|
537
|
+
pending.reject(error);
|
|
529
538
|
return;
|
|
530
539
|
}
|
|
531
540
|
pending.resolve(payload.result ?? {});
|
|
@@ -553,6 +562,26 @@ class JsonRpcWebSocketClient {
|
|
|
553
562
|
return this.socketPromise;
|
|
554
563
|
}
|
|
555
564
|
}
|
|
565
|
+
class CdpWebSocketClient extends WebSocketCommandClient {
|
|
566
|
+
sessionId;
|
|
567
|
+
constructor(endpoint, sessionId) {
|
|
568
|
+
super(endpoint);
|
|
569
|
+
this.sessionId = sessionId;
|
|
570
|
+
}
|
|
571
|
+
createCommandFrame(id, method, params) {
|
|
572
|
+
return {
|
|
573
|
+
id,
|
|
574
|
+
method,
|
|
575
|
+
params,
|
|
576
|
+
...(this.sessionId === undefined ? {} : { sessionId: this.sessionId }),
|
|
577
|
+
};
|
|
578
|
+
}
|
|
579
|
+
}
|
|
580
|
+
class JsonRpcWebSocketClient extends WebSocketCommandClient {
|
|
581
|
+
createCommandFrame(id, method, params) {
|
|
582
|
+
return { id, jsonrpc: "2.0", method, params };
|
|
583
|
+
}
|
|
584
|
+
}
|
|
556
585
|
function flattenCdpFrameTree(node, out = []) {
|
|
557
586
|
if (!node) {
|
|
558
587
|
return out;
|
|
@@ -566,6 +595,48 @@ function flattenCdpFrameTree(node, out = []) {
|
|
|
566
595
|
function isRecord(value) {
|
|
567
596
|
return value !== null && typeof value === "object" && !Array.isArray(value);
|
|
568
597
|
}
|
|
598
|
+
function isBrowserCookieSameSite(value) {
|
|
599
|
+
return value === "Strict" || value === "Lax" || value === "None";
|
|
600
|
+
}
|
|
601
|
+
function toBrowserCookie(cookie) {
|
|
602
|
+
return {
|
|
603
|
+
name: cookie.name,
|
|
604
|
+
value: cookie.value,
|
|
605
|
+
domain: cookie.domain,
|
|
606
|
+
path: cookie.path,
|
|
607
|
+
...(cookie.expires !== undefined && cookie.expires > 0 ? { expires: cookie.expires } : {}),
|
|
608
|
+
httpOnly: cookie.httpOnly,
|
|
609
|
+
secure: cookie.secure,
|
|
610
|
+
...(isBrowserCookieSameSite(cookie.sameSite) ? { sameSite: cookie.sameSite } : {}),
|
|
611
|
+
};
|
|
612
|
+
}
|
|
613
|
+
function parseCdpCookies(value) {
|
|
614
|
+
if (!Array.isArray(value)) {
|
|
615
|
+
throw new Error("CDP Network.getCookies returned an invalid cookie list");
|
|
616
|
+
}
|
|
617
|
+
return value.map((cookie) => {
|
|
618
|
+
if (!isRecord(cookie) ||
|
|
619
|
+
typeof cookie.name !== "string" ||
|
|
620
|
+
typeof cookie.value !== "string" ||
|
|
621
|
+
typeof cookie.domain !== "string" ||
|
|
622
|
+
typeof cookie.path !== "string" ||
|
|
623
|
+
typeof cookie.expires !== "number" ||
|
|
624
|
+
typeof cookie.httpOnly !== "boolean" ||
|
|
625
|
+
typeof cookie.secure !== "boolean") {
|
|
626
|
+
throw new Error("CDP Network.getCookies returned an invalid cookie");
|
|
627
|
+
}
|
|
628
|
+
return toBrowserCookie({
|
|
629
|
+
name: cookie.name,
|
|
630
|
+
value: cookie.value,
|
|
631
|
+
domain: cookie.domain,
|
|
632
|
+
path: cookie.path,
|
|
633
|
+
expires: cookie.expires,
|
|
634
|
+
httpOnly: cookie.httpOnly,
|
|
635
|
+
secure: cookie.secure,
|
|
636
|
+
sameSite: cookie.sameSite,
|
|
637
|
+
});
|
|
638
|
+
});
|
|
639
|
+
}
|
|
569
640
|
function parsePoolAcquireResponse(value) {
|
|
570
641
|
if (!isRecord(value) ||
|
|
571
642
|
typeof value.pageId !== "string" ||
|
|
@@ -574,16 +645,13 @@ function parsePoolAcquireResponse(value) {
|
|
|
574
645
|
code: "BROWSER_RUNTIME_UNSUPPORTED",
|
|
575
646
|
});
|
|
576
647
|
}
|
|
577
|
-
if (value.browserContextId !== undefined &&
|
|
578
|
-
typeof value.browserContextId !== "string") {
|
|
648
|
+
if (value.browserContextId !== undefined && typeof value.browserContextId !== "string") {
|
|
579
649
|
throw new ProviderError("CDP Pool returned an invalid acquire response", {
|
|
580
650
|
code: "BROWSER_RUNTIME_UNSUPPORTED",
|
|
581
651
|
});
|
|
582
652
|
}
|
|
583
653
|
return {
|
|
584
|
-
...(value.browserContextId
|
|
585
|
-
? { browserContextId: value.browserContextId }
|
|
586
|
-
: {}),
|
|
654
|
+
...(value.browserContextId ? { browserContextId: value.browserContextId } : {}),
|
|
587
655
|
pageId: value.pageId,
|
|
588
656
|
wsEndpoint: value.wsEndpoint,
|
|
589
657
|
};
|
|
@@ -605,9 +673,7 @@ function parseCdpFrameTreeNode(value) {
|
|
|
605
673
|
frame: {
|
|
606
674
|
id: frameId,
|
|
607
675
|
name: typeof value.frame.name === "string" ? value.frame.name : undefined,
|
|
608
|
-
parentId: typeof value.frame.parentId === "string"
|
|
609
|
-
? value.frame.parentId
|
|
610
|
-
: undefined,
|
|
676
|
+
parentId: typeof value.frame.parentId === "string" ? value.frame.parentId : undefined,
|
|
611
677
|
url: typeof value.frame.url === "string" ? value.frame.url : undefined,
|
|
612
678
|
},
|
|
613
679
|
...(childFrames ? { childFrames } : {}),
|
|
@@ -620,12 +686,21 @@ function getCdpExecutionContext(params) {
|
|
|
620
686
|
const contextId = params.context.id;
|
|
621
687
|
const auxData = params.context.auxData;
|
|
622
688
|
return {
|
|
623
|
-
frameId: isRecord(auxData) && typeof auxData.frameId === "string"
|
|
624
|
-
? auxData.frameId
|
|
625
|
-
: undefined,
|
|
689
|
+
frameId: isRecord(auxData) && typeof auxData.frameId === "string" ? auxData.frameId : undefined,
|
|
626
690
|
id: typeof contextId === "number" ? contextId : undefined,
|
|
627
691
|
};
|
|
628
692
|
}
|
|
693
|
+
function getCdpDestroyedExecutionContextId(params) {
|
|
694
|
+
if (!isRecord(params)) {
|
|
695
|
+
return undefined;
|
|
696
|
+
}
|
|
697
|
+
return typeof params.executionContextId === "number"
|
|
698
|
+
? params.executionContextId
|
|
699
|
+
: undefined;
|
|
700
|
+
}
|
|
701
|
+
function isMissingExecutionContextError(error) {
|
|
702
|
+
return error instanceof Error && /\b(?:cannot|failed to) find context\b/i.test(error.message);
|
|
703
|
+
}
|
|
629
704
|
class CdpBrowserLocator {
|
|
630
705
|
frame;
|
|
631
706
|
selector;
|
|
@@ -751,7 +826,19 @@ class CdpPoolBrowserPage {
|
|
|
751
826
|
async evaluateInFrame(frameId, fn) {
|
|
752
827
|
await this.initialize();
|
|
753
828
|
const contextId = await this.getFrameExecutionContextId(frameId);
|
|
754
|
-
|
|
829
|
+
try {
|
|
830
|
+
return await this.evaluateWithContext(fn, contextId);
|
|
831
|
+
}
|
|
832
|
+
catch (error) {
|
|
833
|
+
if (!isMissingExecutionContextError(error)) {
|
|
834
|
+
throw error;
|
|
835
|
+
}
|
|
836
|
+
if (this.frameExecutionContexts.get(frameId) === contextId) {
|
|
837
|
+
this.frameExecutionContexts.delete(frameId);
|
|
838
|
+
}
|
|
839
|
+
const refreshedContextId = await this.getFrameExecutionContextId(frameId);
|
|
840
|
+
return await this.evaluateWithContext(fn, refreshedContextId);
|
|
841
|
+
}
|
|
755
842
|
}
|
|
756
843
|
async waitForSelectorInFrame(frameId, selector, options) {
|
|
757
844
|
const timeout = options?.timeout ?? DEFAULT_WAIT_TIMEOUT_MS;
|
|
@@ -773,8 +860,7 @@ class CdpPoolBrowserPage {
|
|
|
773
860
|
returnByValue: true,
|
|
774
861
|
});
|
|
775
862
|
if (result.exceptionDetails) {
|
|
776
|
-
throw new Error(String(result.exceptionDetails.text ??
|
|
777
|
-
"Browser evaluation failed"));
|
|
863
|
+
throw new Error(String(result.exceptionDetails.text ?? "Browser evaluation failed"));
|
|
778
864
|
}
|
|
779
865
|
return result.result?.value;
|
|
780
866
|
}
|
|
@@ -852,6 +938,11 @@ class CdpPoolBrowserPage {
|
|
|
852
938
|
});
|
|
853
939
|
return Buffer.from(String(result.data ?? ""), "base64");
|
|
854
940
|
}
|
|
941
|
+
async cookies() {
|
|
942
|
+
await this.initialize();
|
|
943
|
+
const result = await this.pageClient.send("Network.getCookies");
|
|
944
|
+
return parseCdpCookies(result.cookies);
|
|
945
|
+
}
|
|
855
946
|
async close() {
|
|
856
947
|
if (this.closed) {
|
|
857
948
|
return;
|
|
@@ -859,9 +950,7 @@ class CdpPoolBrowserPage {
|
|
|
859
950
|
this.closed = true;
|
|
860
951
|
try {
|
|
861
952
|
await this.release({
|
|
862
|
-
...(this.browserContextId
|
|
863
|
-
? { browserContextId: this.browserContextId }
|
|
864
|
-
: {}),
|
|
953
|
+
...(this.browserContextId ? { browserContextId: this.browserContextId } : {}),
|
|
865
954
|
pageId: this.pageId,
|
|
866
955
|
});
|
|
867
956
|
}
|
|
@@ -950,6 +1039,20 @@ class CdpPoolBrowserPage {
|
|
|
950
1039
|
this.frameExecutionContexts.set(context.frameId, context.id);
|
|
951
1040
|
}
|
|
952
1041
|
});
|
|
1042
|
+
this.pageClient.on("Runtime.executionContextDestroyed", (params) => {
|
|
1043
|
+
const destroyedContextId = getCdpDestroyedExecutionContextId(params);
|
|
1044
|
+
if (destroyedContextId === undefined) {
|
|
1045
|
+
return;
|
|
1046
|
+
}
|
|
1047
|
+
for (const [frameId, contextId] of this.frameExecutionContexts) {
|
|
1048
|
+
if (contextId === destroyedContextId) {
|
|
1049
|
+
this.frameExecutionContexts.delete(frameId);
|
|
1050
|
+
}
|
|
1051
|
+
}
|
|
1052
|
+
});
|
|
1053
|
+
this.pageClient.on("Runtime.executionContextsCleared", () => {
|
|
1054
|
+
this.frameExecutionContexts.clear();
|
|
1055
|
+
});
|
|
953
1056
|
await this.pageClient.send("Page.enable");
|
|
954
1057
|
await this.pageClient.send("Runtime.enable");
|
|
955
1058
|
this.initialized = true;
|
|
@@ -1002,14 +1105,10 @@ class CdpPoolBrowserClient {
|
|
|
1002
1105
|
}
|
|
1003
1106
|
async acquirePage(options) {
|
|
1004
1107
|
const acquireResult = parsePoolAcquireResponse(await this.poolClient.send("acquire", {
|
|
1005
|
-
...(this.allowedHosts.length > 0
|
|
1006
|
-
|
|
1007
|
-
: {}),
|
|
1008
|
-
...(options?.isolatedContext
|
|
1009
|
-
? { isolationMode: "browserContext" }
|
|
1010
|
-
: {}),
|
|
1108
|
+
...(this.allowedHosts.length > 0 ? { allowedHosts: this.allowedHosts } : {}),
|
|
1109
|
+
...(options?.isolatedContext ? { isolationMode: "browserContext" } : {}),
|
|
1011
1110
|
}));
|
|
1012
|
-
const pageClient = new
|
|
1111
|
+
const pageClient = new CdpWebSocketClient(acquireResult.wsEndpoint);
|
|
1013
1112
|
const page = new CdpPoolBrowserPage(acquireResult.pageId, acquireResult.browserContextId, pageClient, async (request) => {
|
|
1014
1113
|
await this.poolClient.send("release", request);
|
|
1015
1114
|
});
|
|
@@ -1223,8 +1322,7 @@ async function solveRecaptchaChallenge(page, request) {
|
|
|
1223
1322
|
async function findRecaptchaFrame(frames, siteKey) {
|
|
1224
1323
|
for (const frame of frames) {
|
|
1225
1324
|
const url = await frame.url();
|
|
1226
|
-
const matchesRecaptcha = url.includes("google.com/recaptcha") ||
|
|
1227
|
-
url.includes("recaptcha.net/recaptcha");
|
|
1325
|
+
const matchesRecaptcha = url.includes("google.com/recaptcha") || url.includes("recaptcha.net/recaptcha");
|
|
1228
1326
|
const matchesSiteKey = !siteKey || url.includes(siteKey);
|
|
1229
1327
|
if (matchesRecaptcha && matchesSiteKey) {
|
|
1230
1328
|
return frame;
|
package/dist/runtime/cache.d.ts
CHANGED
|
@@ -1,10 +1,11 @@
|
|
|
1
|
-
import type { ProviderCache } from "../types";
|
|
1
|
+
import type { ProviderCache } from "../types.js";
|
|
2
2
|
export type ProviderCacheOptions = {
|
|
3
3
|
providerId: string;
|
|
4
4
|
redisUrl?: string;
|
|
5
5
|
memoryMaxEntries?: number;
|
|
6
6
|
now?: () => number;
|
|
7
7
|
};
|
|
8
|
+
export declare const APIFUSE__CACHE__KEY_PEPPER_ENV = "APIFUSE__CACHE__KEY_PEPPER";
|
|
8
9
|
export declare function createProviderCache(options: ProviderCacheOptions): ProviderCache;
|
|
9
10
|
export declare function createBypassProviderCache(options: Pick<ProviderCacheOptions, "providerId">): ProviderCache;
|
|
10
11
|
export declare function resetProviderCacheForTests(): void;
|