@apifuse/provider-sdk 2.2.0-beta.2 → 2.2.0-beta.20
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 +85 -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 +1 -1
- package/dist/ceremonies/index.js +8 -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 +208 -125
- 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.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 +1 -1
- package/dist/runtime/auth-flow.js +3 -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 +15 -4
- 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 +115 -4
- package/dist/server/serve.js +792 -127
- package/dist/server/types.d.ts +30 -9
- package/dist/server/types.js +8 -7
- 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 +477 -33
- package/dist/types.d.ts +323 -11
- 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 +24 -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 +368 -504
- 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 +111 -42
- package/src/lint.ts +89 -159
- 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 +65 -11
- package/src/public-schema-field-lint.ts +7 -33
- package/src/recipes/gov-api.ts +2 -5
- package/src/runtime/auth-flow.ts +5 -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 +41 -110
- 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 +1141 -324
- package/src/server/types.ts +12 -19
- 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 +652 -79
- package/src/types.ts +369 -11
- 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/types.d.ts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import type ms from "ms";
|
|
2
|
+
import type { SerializedCookieJar } from "tough-cookie";
|
|
2
3
|
import type { infer as ZodInfer, ZodType } from "zod";
|
|
3
4
|
/** Minimal Standard Schema v1 shape accepted by provider operations. */
|
|
4
5
|
export interface StandardSchemaV1<Input = unknown, Output = Input> {
|
|
@@ -609,9 +610,11 @@ export interface HealthMonitorProbeOverride {
|
|
|
609
610
|
/** Optional degraded threshold override for generated registry probes. */
|
|
610
611
|
degradedThresholdMs?: number;
|
|
611
612
|
}
|
|
613
|
+
export declare const VALID_OPERATION_ERROR_STATUSES: readonly [400, 401, 404, 409, 410, 422, 429, 500, 502, 503, 504];
|
|
614
|
+
export type ProviderErrorStatus = (typeof VALID_OPERATION_ERROR_STATUSES)[number];
|
|
612
615
|
export interface OperationErrorCode {
|
|
613
616
|
code: string;
|
|
614
|
-
status?:
|
|
617
|
+
status?: ProviderErrorStatus;
|
|
615
618
|
description: string;
|
|
616
619
|
retryable?: boolean;
|
|
617
620
|
}
|
|
@@ -650,7 +653,25 @@ export type ConnectionMode = AuthMode;
|
|
|
650
653
|
export type ProviderReviewed = "first-party" | "community" | "staging";
|
|
651
654
|
export type ProviderAccessVisibility = "public" | "early_access";
|
|
652
655
|
export type ProviderProxyMode = "disabled" | "optional" | "required";
|
|
653
|
-
|
|
656
|
+
/**
|
|
657
|
+
* Proxy egress vendors. These are FOUR DISTINCT services — do not conflate them
|
|
658
|
+
* (a common mistake because the names collide with a well-known rebrand):
|
|
659
|
+
*
|
|
660
|
+
* - `smartproxy` — **api.smartproxy.org**, a residential proxy with an IP
|
|
661
|
+
* *extraction/allocation* API (app_key → a pool of raw `ip:port` CONNECT
|
|
662
|
+
* endpoints). This is our own vendor. It is NOT the company formerly named
|
|
663
|
+
* "Smartproxy". Credentials: `APIFUSE__PROXY__SMARTPROXY_APP_KEY`.
|
|
664
|
+
* - `nodemaven` — **gate.nodemaven.com**, a *gateway* proxy with static
|
|
665
|
+
* credentials; geo/session encoded in the username, no allocation API.
|
|
666
|
+
* - `decodo` — **decodo.com**, the *gateway* proxy that was named "Smartproxy"
|
|
667
|
+
* (smartproxy.com) before its 2025 rebrand to Decodo. Sticky sessions via
|
|
668
|
+
* username params. A different company from `smartproxy` above.
|
|
669
|
+
* **@deprecated** — unused; no managed adapter. Use `smartproxy`/`nodemaven`,
|
|
670
|
+
* or the `APIFUSE__PROXY__URL` bring-your-own escape hatch.
|
|
671
|
+
* - `custom` — **@deprecated** bring-your-own static proxy URL marker. The
|
|
672
|
+
* `APIFUSE__PROXY__URL` env still works without declaring this value.
|
|
673
|
+
*/
|
|
674
|
+
export type ProviderProxyProvider = "smartproxy" | "nodemaven" | "decodo" | "custom";
|
|
654
675
|
export type ProviderProxySessionAffinity = "request" | "operation" | "auth-flow" | "connection";
|
|
655
676
|
export interface ProviderProxyPolicy {
|
|
656
677
|
/**
|
|
@@ -658,7 +679,18 @@ export interface ProviderProxyPolicy {
|
|
|
658
679
|
* certificate verification, and vendor allocator endpoints are SDK-owned.
|
|
659
680
|
*/
|
|
660
681
|
mode: ProviderProxyMode;
|
|
682
|
+
/**
|
|
683
|
+
* @deprecated Use `providers: [...]` to declare an ordered vendor fallback
|
|
684
|
+
* chain. A single-element `providers` list is equivalent to this field.
|
|
685
|
+
*/
|
|
661
686
|
provider?: ProviderProxyProvider;
|
|
687
|
+
/**
|
|
688
|
+
* Ordered proxy-vendor fallback chain. The SDK tries each vendor in order and
|
|
689
|
+
* fails over to the next when a vendor lacks credentials or its allocation /
|
|
690
|
+
* transport is exhausted. When omitted, `provider` (or the platform default)
|
|
691
|
+
* is used as a single-vendor chain.
|
|
692
|
+
*/
|
|
693
|
+
providers?: ProviderProxyProvider[];
|
|
662
694
|
geo?: {
|
|
663
695
|
/** ISO 3166-1 alpha-2 country code, for example KR or US. */
|
|
664
696
|
country?: Iso3166Alpha2CountryCode;
|
|
@@ -669,6 +701,12 @@ export interface ProviderProxyPolicy {
|
|
|
669
701
|
affinity?: ProviderProxySessionAffinity;
|
|
670
702
|
lifetimeMinutes?: number;
|
|
671
703
|
poolSize?: number;
|
|
704
|
+
/**
|
|
705
|
+
* Seconds before hard sticky expiry at which native connections receive
|
|
706
|
+
* the `expiring` event so the provider can drain and reconnect cleanly.
|
|
707
|
+
* Declared by the provider; the SDK does not assume a default cut point.
|
|
708
|
+
*/
|
|
709
|
+
drainLeadSeconds?: number;
|
|
672
710
|
};
|
|
673
711
|
}
|
|
674
712
|
export type ProviderProxyConfig = boolean | ProviderProxyPolicy;
|
|
@@ -810,6 +848,11 @@ export interface HttpRetrySummary {
|
|
|
810
848
|
export interface RequestOptions {
|
|
811
849
|
headers?: Record<string, string>;
|
|
812
850
|
params?: RequestParams;
|
|
851
|
+
/**
|
|
852
|
+
* Query parameters whose values contain credentials or other secret material.
|
|
853
|
+
* They are sent like `params`, but redacted from SDK errors, traces, and recorded fixtures.
|
|
854
|
+
*/
|
|
855
|
+
sensitiveParams?: Record<string, string>;
|
|
813
856
|
proxy?: string;
|
|
814
857
|
timeout?: number;
|
|
815
858
|
/**
|
|
@@ -818,12 +861,33 @@ export interface RequestOptions {
|
|
|
818
861
|
*/
|
|
819
862
|
throwOnHttpError?: boolean;
|
|
820
863
|
retry?: boolean | HttpRetryPreset | HttpRetryOptions;
|
|
864
|
+
/**
|
|
865
|
+
* Opt-in redirect-hop enforcement for ctx.http. When present, redirects are
|
|
866
|
+
* evaluated before the next request is issued. Existing callers that omit
|
|
867
|
+
* this policy retain the native fetch redirect behavior.
|
|
868
|
+
*/
|
|
869
|
+
redirectPolicy?: HttpRedirectPolicy;
|
|
821
870
|
}
|
|
871
|
+
export type RedirectRunReason = "completed" | "stopped" | "max_hops" | "missing_location" | "loop";
|
|
872
|
+
export type HttpRedirectPolicyMode = "same-origin";
|
|
873
|
+
export interface HttpRedirectPolicy {
|
|
874
|
+
/** Only follow redirects whose canonical scheme, host, and port match the initial URL. */
|
|
875
|
+
mode: HttpRedirectPolicyMode;
|
|
876
|
+
/** Maximum number of redirect hops that may be followed. Must be an integer from 0 to 20. */
|
|
877
|
+
maxHops: number;
|
|
878
|
+
}
|
|
879
|
+
export type HttpRedirectFailureReason = Exclude<RedirectRunReason, "completed">;
|
|
822
880
|
export type HttpMethod = "HEAD" | "head" | "GET" | "get" | "POST" | "post" | "PUT" | "put" | "DELETE" | "delete" | "OPTIONS" | "options" | "TRACE" | "trace" | "PATCH" | "patch";
|
|
823
|
-
export interface StealthFetchOptions extends RequestOptions {
|
|
881
|
+
export interface StealthFetchOptions extends Omit<RequestOptions, "redirectPolicy"> {
|
|
824
882
|
method?: HttpMethod;
|
|
825
883
|
body?: string | Buffer;
|
|
826
884
|
redirect?: "follow" | "manual" | "error";
|
|
885
|
+
/**
|
|
886
|
+
* Maximum decoded response-body bytes to buffer. When set, the stealth
|
|
887
|
+
* transport aborts the response and throws `response_too_large` if the
|
|
888
|
+
* declared or streamed body exceeds this limit.
|
|
889
|
+
*/
|
|
890
|
+
maxBodyBytes?: number;
|
|
827
891
|
/**
|
|
828
892
|
* Offsets policy-managed proxy pool selection for caller-managed retries.
|
|
829
893
|
* Use when a request receives an upstream challenge page rather than a
|
|
@@ -843,17 +907,42 @@ export interface StealthFetchOptions extends RequestOptions {
|
|
|
843
907
|
};
|
|
844
908
|
}
|
|
845
909
|
export interface CookieJar {
|
|
846
|
-
|
|
847
|
-
|
|
848
|
-
|
|
849
|
-
|
|
910
|
+
/** URL-less reads use the jar's response URL or session base URL. */
|
|
911
|
+
get(name: string, url?: string): string | undefined;
|
|
912
|
+
getAll(url?: string): Record<string, string>;
|
|
913
|
+
toString(url?: string): string;
|
|
914
|
+
find?(predicate: (cookie: string) => boolean, url?: string): string | undefined;
|
|
850
915
|
}
|
|
916
|
+
/**
|
|
917
|
+
* Version 1 of the JSON-safe, attribute-preserving stealth cookie store.
|
|
918
|
+
* The nested jar is tough-cookie's serialized form and retains cookie origin,
|
|
919
|
+
* Path, Secure, expiry, host-only, and other RFC attributes.
|
|
920
|
+
*/
|
|
921
|
+
export interface StealthCookieStoreV1 {
|
|
922
|
+
readonly version: 1;
|
|
923
|
+
readonly jar: SerializedCookieJar;
|
|
924
|
+
}
|
|
925
|
+
/** Cookie persistence formats understood by this SDK version. */
|
|
926
|
+
export type StealthCookieStore = StealthCookieStoreV1;
|
|
851
927
|
export interface StealthSessionCookies extends CookieJar {
|
|
852
|
-
has(name: string): boolean;
|
|
853
|
-
|
|
854
|
-
|
|
928
|
+
has(name: string, url?: string): boolean;
|
|
929
|
+
/** URL-less writes are scoped to the session base URL. */
|
|
930
|
+
setFromCookieStrings(cookieStrings: readonly string[], url?: string): void;
|
|
931
|
+
toHeader(url?: string): string;
|
|
932
|
+
/**
|
|
933
|
+
* Returns every cookie as a flat name/value map, collapsing duplicate names.
|
|
934
|
+
* @deprecated Use serialize() for lossless, attribute-preserving persistence.
|
|
935
|
+
*/
|
|
855
936
|
snapshot(): Record<string, string>;
|
|
937
|
+
/**
|
|
938
|
+
* Restores flat values as host-only, Path=/ cookies on the session base URL.
|
|
939
|
+
* @deprecated Use deserialize() with state produced by serialize().
|
|
940
|
+
*/
|
|
856
941
|
restore(cookies: Record<string, string>): void;
|
|
942
|
+
/** Returns a versioned, JSON-safe, attribute-preserving representation of every cookie. */
|
|
943
|
+
serialize(): StealthCookieStoreV1;
|
|
944
|
+
/** Replaces the jar with a previously serialized, attribute-preserving cookie store. */
|
|
945
|
+
deserialize(state: StealthCookieStore): void;
|
|
857
946
|
clear(): void;
|
|
858
947
|
}
|
|
859
948
|
export interface DeclarativeStealthResponse {
|
|
@@ -895,8 +984,14 @@ export interface StealthRedirectRunOptions extends Omit<StealthFetchOptions, "re
|
|
|
895
984
|
export interface StealthRedirectRunResult {
|
|
896
985
|
final: StealthResponse;
|
|
897
986
|
hops: StealthRedirectHop[];
|
|
898
|
-
reason:
|
|
987
|
+
reason: RedirectRunReason;
|
|
988
|
+
/**
|
|
989
|
+
* Complete flat view across all redirect hosts. Attributes and duplicate names are lost.
|
|
990
|
+
* @deprecated Use cookieStore for lossless persistence.
|
|
991
|
+
*/
|
|
899
992
|
cookies: Record<string, string>;
|
|
993
|
+
/** Versioned, attribute-preserving cookie state accumulated across the redirect chain. */
|
|
994
|
+
cookieStore: StealthCookieStoreV1;
|
|
900
995
|
}
|
|
901
996
|
export interface StealthSession {
|
|
902
997
|
fetch(url: string, options?: StealthFetchOptions): Promise<StealthResponse>;
|
|
@@ -959,6 +1054,154 @@ export interface HttpClient {
|
|
|
959
1054
|
stream(url: string, options?: RequestWithMethodOptions): Promise<HttpStreamResponse>;
|
|
960
1055
|
sse(url: string, options?: RequestWithMethodOptions): Promise<AsyncIterable<SseMessage>>;
|
|
961
1056
|
}
|
|
1057
|
+
/** Request-scoped file reference accepted by provider operation inputs. */
|
|
1058
|
+
export interface ProviderFileRef {
|
|
1059
|
+
readonly type: "request_file";
|
|
1060
|
+
readonly id: string;
|
|
1061
|
+
readonly filename: string;
|
|
1062
|
+
readonly mime_type?: string;
|
|
1063
|
+
readonly size: number;
|
|
1064
|
+
readonly sha256?: string;
|
|
1065
|
+
}
|
|
1066
|
+
/** File body resolved from a request-scoped {@link ProviderFileRef}. */
|
|
1067
|
+
export type ProviderResolvedFile = Omit<ProviderFileRef, "mime_type"> & {
|
|
1068
|
+
readonly mimeType?: string;
|
|
1069
|
+
arrayBuffer(): Promise<ArrayBuffer>;
|
|
1070
|
+
bytes(): Promise<Uint8Array>;
|
|
1071
|
+
stream(): ReadableStream<Uint8Array>;
|
|
1072
|
+
};
|
|
1073
|
+
/** Resolver supplied by runtimes that accept request-scoped file inputs. */
|
|
1074
|
+
export interface ProviderFilesContext {
|
|
1075
|
+
has(input: string | ProviderFileRef): boolean;
|
|
1076
|
+
resolve(input: string | ProviderFileRef): Promise<ProviderResolvedFile>;
|
|
1077
|
+
}
|
|
1078
|
+
export type NativeTcpTlsMode = "required" | "allowed" | "disabled";
|
|
1079
|
+
export interface NativeTcpPortRange {
|
|
1080
|
+
readonly start: number;
|
|
1081
|
+
readonly end: number;
|
|
1082
|
+
}
|
|
1083
|
+
/** Static native TCP egress declared by a provider. */
|
|
1084
|
+
export interface NativeTcpEgressRule {
|
|
1085
|
+
readonly host: string;
|
|
1086
|
+
readonly ports: readonly number[];
|
|
1087
|
+
readonly tls: NativeTcpTlsMode;
|
|
1088
|
+
}
|
|
1089
|
+
/**
|
|
1090
|
+
* Bounded native TCP egress discovered through a declared bootstrap endpoint.
|
|
1091
|
+
* Host suffixes are exact DNS suffixes, not wildcard patterns.
|
|
1092
|
+
* Dynamic rules must declare at least one target host selector through
|
|
1093
|
+
* targetHostSuffixes, targetIpv4Cidrs, and/or targetIpv6Cidrs. Literal grant
|
|
1094
|
+
* sources and targets match only same-family selectors (except exact
|
|
1095
|
+
* sourceHost); DNS names match only host/suffix selectors. IPv4-mapped and
|
|
1096
|
+
* IPv4-compatible IPv6 literals are authorized only by IPv4 CIDRs.
|
|
1097
|
+
*
|
|
1098
|
+
* Dynamic rules are ordered. The first rule whose source, target, port, and TLS
|
|
1099
|
+
* selectors match exclusively owns the grant; its ttlMs and maxGrants bounds
|
|
1100
|
+
* apply, and an exhausted/shorter rule never falls through to a later overlap.
|
|
1101
|
+
* Every rule must declare a source host selector, source port list/range, and
|
|
1102
|
+
* target port list/range; omitted ttlMs/maxGrants remain unbounded.
|
|
1103
|
+
*/
|
|
1104
|
+
export interface NativeTcpDynamicEgressRule {
|
|
1105
|
+
readonly sourceHost?: string;
|
|
1106
|
+
readonly sourceHostSuffixes?: readonly string[];
|
|
1107
|
+
readonly sourceIpv4Cidrs?: readonly string[];
|
|
1108
|
+
readonly sourceIpv6Cidrs?: readonly string[];
|
|
1109
|
+
readonly sourcePorts?: readonly number[];
|
|
1110
|
+
readonly sourcePortRanges?: readonly NativeTcpPortRange[];
|
|
1111
|
+
readonly targetHostSuffixes?: readonly string[];
|
|
1112
|
+
readonly targetIpv4Cidrs?: readonly string[];
|
|
1113
|
+
readonly targetIpv6Cidrs?: readonly string[];
|
|
1114
|
+
readonly targetPorts?: readonly number[];
|
|
1115
|
+
readonly targetPortRanges?: readonly NativeTcpPortRange[];
|
|
1116
|
+
readonly tls: NativeTcpTlsMode;
|
|
1117
|
+
readonly ttlMs?: number;
|
|
1118
|
+
readonly maxGrants?: number;
|
|
1119
|
+
}
|
|
1120
|
+
/** Common TCP/TLS connection input supported by the native runtime. */
|
|
1121
|
+
export interface NativeNetworkConnectInput {
|
|
1122
|
+
readonly host: string;
|
|
1123
|
+
readonly port: number;
|
|
1124
|
+
readonly serverName?: string;
|
|
1125
|
+
readonly rejectUnauthorized?: boolean;
|
|
1126
|
+
/**
|
|
1127
|
+
* Maximum time without a successful socket read before the connection is
|
|
1128
|
+
* closed. Opt-in; when absent, reads can remain pending indefinitely.
|
|
1129
|
+
*/
|
|
1130
|
+
readonly idleTimeoutMs?: number;
|
|
1131
|
+
/** Maximum time allowed to establish the TCP/SOCKS/TLS connection. */
|
|
1132
|
+
readonly timeoutMs?: number;
|
|
1133
|
+
readonly signal?: AbortSignal;
|
|
1134
|
+
/** Overrides the credential-derived sticky affinity key. */
|
|
1135
|
+
readonly affinityKey?: string;
|
|
1136
|
+
}
|
|
1137
|
+
export type NativeNetworkConnectOptions = Omit<NativeNetworkConnectInput, "serverName" | "rejectUnauthorized">;
|
|
1138
|
+
export type NativeTlsConnectOptions = NativeNetworkConnectInput;
|
|
1139
|
+
export interface NativeNetworkDynamicGrantOptions {
|
|
1140
|
+
readonly sourceHost: string;
|
|
1141
|
+
readonly sourcePort: number;
|
|
1142
|
+
readonly host: string;
|
|
1143
|
+
readonly port: number;
|
|
1144
|
+
readonly tls: NativeTcpTlsMode;
|
|
1145
|
+
readonly ttlMs?: number;
|
|
1146
|
+
}
|
|
1147
|
+
export interface NativeNetworkEgressGrant {
|
|
1148
|
+
revoke(): void;
|
|
1149
|
+
}
|
|
1150
|
+
/** Consumer-facing alias used by native TCP providers. */
|
|
1151
|
+
export type NativeTcpEgressGrant = NativeNetworkEgressGrant;
|
|
1152
|
+
/** Resolved egress identity for a native connection routed through a proxy. */
|
|
1153
|
+
export interface NativeProxyEgressInfo {
|
|
1154
|
+
readonly vendor: ProviderProxyProvider;
|
|
1155
|
+
readonly sticky: boolean;
|
|
1156
|
+
/** Vendor sticky session id (sid). Absent for rotating sessions. */
|
|
1157
|
+
readonly sessionId?: string;
|
|
1158
|
+
/** Hard expiry of the sticky binding, ISO 8601. */
|
|
1159
|
+
readonly expiresAt?: string;
|
|
1160
|
+
}
|
|
1161
|
+
export type NativeProxyExpiringReason = "sticky_expiry";
|
|
1162
|
+
export interface NativeProxyExpiringEvent {
|
|
1163
|
+
readonly expiresAt: string;
|
|
1164
|
+
readonly leadSeconds: number;
|
|
1165
|
+
readonly reason: NativeProxyExpiringReason;
|
|
1166
|
+
}
|
|
1167
|
+
/**
|
|
1168
|
+
* Cooperative drain handler. The SDK awaits this before closing a socket whose
|
|
1169
|
+
* sticky proxy binding is about to expire, then force-closes at hard expiry.
|
|
1170
|
+
*/
|
|
1171
|
+
export type NativeProxyDrainHandler = (event: NativeProxyExpiringEvent) => void | Promise<void>;
|
|
1172
|
+
/** Typed reason recorded when the SDK closes a native connection intentionally. */
|
|
1173
|
+
export interface NativeNetworkCloseReason {
|
|
1174
|
+
readonly code: string;
|
|
1175
|
+
readonly message: string;
|
|
1176
|
+
}
|
|
1177
|
+
/** Byte-oriented connection returned by the native TCP/TLS runtime. */
|
|
1178
|
+
export interface NativeNetworkConnection {
|
|
1179
|
+
/** Present when the connection was routed through a proxy. */
|
|
1180
|
+
readonly proxy?: NativeProxyEgressInfo;
|
|
1181
|
+
/** Present after an SDK-planned close, such as sticky proxy expiry. */
|
|
1182
|
+
readonly closeReason?: NativeNetworkCloseReason;
|
|
1183
|
+
/** Register a cooperative drain handler for sticky-expiry reconnects. */
|
|
1184
|
+
onExpiring?(handler: NativeProxyDrainHandler): void;
|
|
1185
|
+
read(): Promise<Uint8Array | null>;
|
|
1186
|
+
write(data: Uint8Array): Promise<void>;
|
|
1187
|
+
close(): Promise<void>;
|
|
1188
|
+
}
|
|
1189
|
+
export interface NativeNetworkClient {
|
|
1190
|
+
connectTcp(input: NativeNetworkConnectOptions): Promise<NativeNetworkConnection>;
|
|
1191
|
+
connectTls(input: NativeTlsConnectOptions): Promise<NativeNetworkConnection>;
|
|
1192
|
+
grantTcpEgress(input: NativeNetworkDynamicGrantOptions): NativeNetworkEgressGrant;
|
|
1193
|
+
}
|
|
1194
|
+
export interface NativeContext {
|
|
1195
|
+
readonly network: NativeNetworkClient;
|
|
1196
|
+
}
|
|
1197
|
+
/** Consumer-facing alias for the native capability on provider contexts. */
|
|
1198
|
+
export type NativeProviderContext = NativeContext;
|
|
1199
|
+
export interface NativeProviderConfig {
|
|
1200
|
+
readonly network?: {
|
|
1201
|
+
readonly tcp?: readonly NativeTcpEgressRule[];
|
|
1202
|
+
readonly dynamicTcp?: readonly NativeTcpDynamicEgressRule[];
|
|
1203
|
+
};
|
|
1204
|
+
}
|
|
962
1205
|
export interface ProviderCacheKeyOptions {
|
|
963
1206
|
/**
|
|
964
1207
|
* Additional field names to omit from stable key material. The SDK always
|
|
@@ -1290,6 +1533,8 @@ export interface FlowContext {
|
|
|
1290
1533
|
tenantId: string;
|
|
1291
1534
|
providerId: string;
|
|
1292
1535
|
http: HttpClient;
|
|
1536
|
+
/** Present when the selected runtime supplies native network capabilities. */
|
|
1537
|
+
readonly native?: NativeProviderContext;
|
|
1293
1538
|
stealth: StealthClient;
|
|
1294
1539
|
env: EnvContext;
|
|
1295
1540
|
credential?: CredentialContext;
|
|
@@ -1375,6 +1620,10 @@ export interface ProviderContext {
|
|
|
1375
1620
|
credential: CredentialContext;
|
|
1376
1621
|
request?: ProviderRequestContext;
|
|
1377
1622
|
http: HttpClient;
|
|
1623
|
+
/** Present for requests carrying runtime-resolvable file references. */
|
|
1624
|
+
readonly files?: ProviderFilesContext;
|
|
1625
|
+
/** Present when the selected runtime supplies native network capabilities. */
|
|
1626
|
+
readonly native?: NativeProviderContext;
|
|
1378
1627
|
cache: ProviderCache;
|
|
1379
1628
|
state: ProviderRuntimeState;
|
|
1380
1629
|
stealth: StealthClient;
|
|
@@ -1418,6 +1667,19 @@ export interface OperationContractMetadata {
|
|
|
1418
1667
|
deprecation?: OperationDeprecationMetadata;
|
|
1419
1668
|
}
|
|
1420
1669
|
export interface OperationDefinition<TInput extends SchemaLike = SchemaLike, TOutput extends SchemaLike = SchemaLike> {
|
|
1670
|
+
/**
|
|
1671
|
+
* Short English display title for the operation. The SDK passes it through
|
|
1672
|
+
* verbatim; the APIFuse registry derives the operation's en locale title
|
|
1673
|
+
* baseline from it (`docs.titleKey` remains available as an explicit key
|
|
1674
|
+
* override).
|
|
1675
|
+
*/
|
|
1676
|
+
title?: string;
|
|
1677
|
+
/**
|
|
1678
|
+
* Raw English operation description. The SDK passes it through verbatim;
|
|
1679
|
+
* keyed descriptions via `descriptionKey` remain the primary flow, and
|
|
1680
|
+
* provider lint rules for raw prose descriptions still apply.
|
|
1681
|
+
*/
|
|
1682
|
+
description?: string;
|
|
1421
1683
|
descriptionKey?: ProviderLocaleKeyInput;
|
|
1422
1684
|
docs?: OperationDocMeta;
|
|
1423
1685
|
whenToUseKeys?: readonly ProviderLocaleKeyInput[];
|
|
@@ -1438,6 +1700,11 @@ export interface OperationDefinition<TInput extends SchemaLike = SchemaLike, TOu
|
|
|
1438
1700
|
fixtures?: {
|
|
1439
1701
|
request: InferSchemaOutput<TInput>;
|
|
1440
1702
|
response: InferSchemaOutput<TOutput>;
|
|
1703
|
+
/**
|
|
1704
|
+
* KST calendar date when `response` evidence was captured. Date fields in
|
|
1705
|
+
* the response align with this date, not a resolved relative request date.
|
|
1706
|
+
*/
|
|
1707
|
+
recordedAt?: string;
|
|
1441
1708
|
};
|
|
1442
1709
|
upstream?: {
|
|
1443
1710
|
baseUrl?: string;
|
|
@@ -1447,11 +1714,56 @@ export interface OperationDefinition<TInput extends SchemaLike = SchemaLike, TOu
|
|
|
1447
1714
|
healthCheck?: HealthCheckSuite<InferSchemaOutput<TInput>, InferSchemaOutput<TOutput>>;
|
|
1448
1715
|
healthCheckUnsupported?: HealthCheckUnsupported;
|
|
1449
1716
|
}
|
|
1717
|
+
/**
|
|
1718
|
+
* Author-declared deployment overrides accepted as the optional top-level
|
|
1719
|
+
* `deployment` key on `defineProvider()`.
|
|
1720
|
+
*
|
|
1721
|
+
* The SDK passes this object through VERBATIM onto the returned provider
|
|
1722
|
+
* definition — it is typed here but deliberately not deep-validated: the
|
|
1723
|
+
* APIFuse registry builder owns deployment validation and resolves omitted
|
|
1724
|
+
* fields against the runtime deployment profiles. The shape mirrors the
|
|
1725
|
+
* registry's `ProviderDeploymentOverrides` contract; every field is
|
|
1726
|
+
* optional. Note that the deployment `runtime` axis
|
|
1727
|
+
* (`shared`/`dedicated`/`browser`) is distinct from the provider execution
|
|
1728
|
+
* `runtime` (`standard`/`shared`/`browser`).
|
|
1729
|
+
*/
|
|
1730
|
+
export interface ProviderDeploymentOverrides {
|
|
1731
|
+
runtime?: "shared" | "dedicated" | "browser";
|
|
1732
|
+
language?: "typescript" | "python";
|
|
1733
|
+
replicas?: number;
|
|
1734
|
+
hpa?: {
|
|
1735
|
+
enabled: boolean;
|
|
1736
|
+
minReplicas?: number;
|
|
1737
|
+
maxReplicas?: number;
|
|
1738
|
+
targetCPUUtilizationPercentage?: number;
|
|
1739
|
+
};
|
|
1740
|
+
resources?: {
|
|
1741
|
+
cpu: string;
|
|
1742
|
+
memory: string;
|
|
1743
|
+
};
|
|
1744
|
+
cache?: {
|
|
1745
|
+
redis?: {
|
|
1746
|
+
enabled: boolean;
|
|
1747
|
+
url?: string;
|
|
1748
|
+
};
|
|
1749
|
+
};
|
|
1750
|
+
network?: {
|
|
1751
|
+
additionalTcpPorts?: number[];
|
|
1752
|
+
};
|
|
1753
|
+
buildContext?: string;
|
|
1754
|
+
}
|
|
1450
1755
|
export interface ProviderDefinition {
|
|
1451
1756
|
id: string;
|
|
1452
1757
|
version: string;
|
|
1453
1758
|
runtime: "standard" | "shared" | "browser";
|
|
1759
|
+
/**
|
|
1760
|
+
* Optional deployment overrides, passed through verbatim from
|
|
1761
|
+
* `defineProvider({ deployment })`. Validation and profile resolution are
|
|
1762
|
+
* owned by the APIFuse registry builder, not the SDK.
|
|
1763
|
+
*/
|
|
1764
|
+
deployment?: ProviderDeploymentOverrides;
|
|
1454
1765
|
allowedHosts?: string[];
|
|
1766
|
+
native?: NativeProviderConfig;
|
|
1455
1767
|
stealth?: {
|
|
1456
1768
|
profile: string;
|
|
1457
1769
|
platform: StealthPlatform;
|
package/dist/types.js
CHANGED
|
@@ -32,6 +32,7 @@ export const HEALTH_CHECK_TIMEOUT_MS_MIN = 1;
|
|
|
32
32
|
export const HEALTH_CHECK_TIMEOUT_MS_MAX = 60_000;
|
|
33
33
|
export const HEALTH_CHECK_DEGRADED_THRESHOLD_MS_MIN = 1;
|
|
34
34
|
export const HEALTH_CHECK_DEGRADED_THRESHOLD_MS_MAX = 60_000;
|
|
35
|
+
export const VALID_OPERATION_ERROR_STATUSES = [400, 401, 404, 409, 410, 422, 429, 500, 502, 503, 504];
|
|
35
36
|
export const HttpRetryPreset = {
|
|
36
37
|
Off: "off",
|
|
37
38
|
TransportTransient: "transport_transient",
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
export declare const NEEDS_INPUT_STATUS: "needs_input";
|
|
2
|
+
export interface ProviderSelectionOption {
|
|
3
|
+
readonly selection_value: string;
|
|
4
|
+
readonly label: string;
|
|
5
|
+
readonly [extra: string]: unknown;
|
|
6
|
+
}
|
|
7
|
+
export interface ProviderRequiredSelection {
|
|
8
|
+
readonly selection_key: string;
|
|
9
|
+
readonly label: string;
|
|
10
|
+
readonly required: boolean;
|
|
11
|
+
readonly selection_type?: string;
|
|
12
|
+
readonly valid_options: readonly ProviderSelectionOption[];
|
|
13
|
+
readonly [extra: string]: unknown;
|
|
14
|
+
}
|
|
15
|
+
export interface ProviderSelectedOption {
|
|
16
|
+
readonly selection_key: string;
|
|
17
|
+
readonly selection_value: string;
|
|
18
|
+
/** Free-text answer for text-kind selections. */
|
|
19
|
+
readonly text?: string;
|
|
20
|
+
/** Quantity for quantity-kind selections. */
|
|
21
|
+
readonly quantity?: number;
|
|
22
|
+
}
|
|
23
|
+
export interface ProviderNeedsInputPayload {
|
|
24
|
+
readonly status: typeof NEEDS_INPUT_STATUS;
|
|
25
|
+
readonly required_selections: readonly ProviderRequiredSelection[];
|
|
26
|
+
readonly selected_options?: readonly ProviderSelectedOption[];
|
|
27
|
+
/** Provider-specific fresh state token(s), e.g. `reservation_state`. */
|
|
28
|
+
readonly [extra: string]: unknown;
|
|
29
|
+
}
|
|
30
|
+
export declare function isProviderNeedsInputPayload(value: unknown): value is ProviderNeedsInputPayload;
|
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
// Official cross-provider contract for user-input round-trips.
|
|
2
|
+
//
|
|
3
|
+
// Doctrine (born from the 2026-07-20 CatchTable reserve incident): an
|
|
4
|
+
// operation MUST NOT dead-end on a problem the end user can resolve by
|
|
5
|
+
// choosing among live options. Instead of throwing, the provider returns a
|
|
6
|
+
// SUCCESSFUL payload with `status: "needs_input"` that carries everything a
|
|
7
|
+
// consumer-side agent needs to relay the choice verbatim and retry:
|
|
8
|
+
//
|
|
9
|
+
// - `required_selections`: only the still-pending questions, each with
|
|
10
|
+
// human-readable `label`s and `valid_options` the agent shows the user
|
|
11
|
+
// as-is. The agent never chooses on the user's behalf.
|
|
12
|
+
// - `selected_options`: selections already settled, echoed so the follow-up
|
|
13
|
+
// call keeps them without the agent reconstructing anything.
|
|
14
|
+
// - a fresh provider-specific state token (e.g. `reservation_state`) minted
|
|
15
|
+
// at response time, so the retry never races an expired token.
|
|
16
|
+
//
|
|
17
|
+
// Keeping this success-shaped (instead of error `details`) is deliberate:
|
|
18
|
+
// consumer error-shaping layers routinely strip error metadata, and a model
|
|
19
|
+
// that only sees "error" narrates failure to the user. Complex recovery
|
|
20
|
+
// logic belongs to the system, not the model.
|
|
21
|
+
//
|
|
22
|
+
// Deliberately ABSENT: retry templates, next-action routing, or any other
|
|
23
|
+
// agent choreography. Provider payloads carry upstream-backed data only; how
|
|
24
|
+
// to phrase the ask and shape the retry call is the consumer's contract
|
|
25
|
+
// (apifuse#1030). The retry is fully determined by data: copy the echoed
|
|
26
|
+
// selected_options, add the user's new answers, resend with the fresh state.
|
|
27
|
+
export const NEEDS_INPUT_STATUS = "needs_input";
|
|
28
|
+
function isRecord(value) {
|
|
29
|
+
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
30
|
+
}
|
|
31
|
+
function isSelectionOption(value) {
|
|
32
|
+
return (isRecord(value) &&
|
|
33
|
+
typeof value.selection_value === "string" &&
|
|
34
|
+
typeof value.label === "string");
|
|
35
|
+
}
|
|
36
|
+
function isRequiredSelection(value) {
|
|
37
|
+
return (isRecord(value) &&
|
|
38
|
+
typeof value.selection_key === "string" &&
|
|
39
|
+
typeof value.label === "string" &&
|
|
40
|
+
typeof value.required === "boolean" &&
|
|
41
|
+
Array.isArray(value.valid_options) &&
|
|
42
|
+
value.valid_options.every(isSelectionOption));
|
|
43
|
+
}
|
|
44
|
+
function isSelectedOption(value) {
|
|
45
|
+
return (isRecord(value) &&
|
|
46
|
+
typeof value.selection_key === "string" &&
|
|
47
|
+
typeof value.selection_value === "string");
|
|
48
|
+
}
|
|
49
|
+
export function isProviderNeedsInputPayload(value) {
|
|
50
|
+
if (!isRecord(value)) {
|
|
51
|
+
return false;
|
|
52
|
+
}
|
|
53
|
+
if (value.status !== NEEDS_INPUT_STATUS ||
|
|
54
|
+
!Array.isArray(value.required_selections) ||
|
|
55
|
+
!value.required_selections.every(isRequiredSelection)) {
|
|
56
|
+
return false;
|
|
57
|
+
}
|
|
58
|
+
// A needs_input with nothing to ask AND nothing settled to echo is a
|
|
59
|
+
// no-op dead end — reject it so providers cannot ship it accidentally.
|
|
60
|
+
if (value.required_selections.length > 0) {
|
|
61
|
+
return true;
|
|
62
|
+
}
|
|
63
|
+
return (Array.isArray(value.selected_options) &&
|
|
64
|
+
value.selected_options.length > 0 &&
|
|
65
|
+
value.selected_options.every(isSelectedOption));
|
|
66
|
+
}
|
package/package.json
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
{
|
|
2
|
-
"version": "2.2.0-beta.
|
|
2
|
+
"version": "2.2.0-beta.20",
|
|
3
3
|
"name": "@apifuse/provider-sdk",
|
|
4
4
|
"private": false,
|
|
5
5
|
"type": "module",
|
|
@@ -61,6 +61,11 @@
|
|
|
61
61
|
"import": "./dist/server/index.js",
|
|
62
62
|
"default": "./dist/server/index.js"
|
|
63
63
|
},
|
|
64
|
+
"./stateful": {
|
|
65
|
+
"types": "./dist/stateful/index.d.ts",
|
|
66
|
+
"import": "./dist/stateful/index.js",
|
|
67
|
+
"default": "./dist/stateful/index.js"
|
|
68
|
+
},
|
|
64
69
|
"./testing": {
|
|
65
70
|
"types": "./dist/testing/index.d.ts",
|
|
66
71
|
"import": "./dist/testing/index.js",
|
|
@@ -75,24 +80,28 @@
|
|
|
75
80
|
"scripts": {
|
|
76
81
|
"lint": "biome lint .",
|
|
77
82
|
"lint:fix": "biome lint --write",
|
|
83
|
+
"lint:deprecated": "bun run scripts/lint-deprecated-usage.ts",
|
|
78
84
|
"format": "biome format --write",
|
|
79
|
-
"type-check": "
|
|
85
|
+
"type-check": "tsc --noEmit",
|
|
80
86
|
"test": "bun test",
|
|
81
|
-
"check": "bun run lint && bun run type-check && bun run build",
|
|
87
|
+
"check": "bun run lint && bun run type-check && bun run lint:deprecated && bun run build",
|
|
82
88
|
"pack:check": "bun run build && bun bin/apifuse-pack-check.ts",
|
|
83
89
|
"pack:smoke": "bun run build && bun bin/apifuse-pack-smoke.ts",
|
|
90
|
+
"pack:types": "bun run build && bun bin/apifuse-pack-types.ts",
|
|
84
91
|
"release:guard": "bun scripts/guard-release-pr.ts",
|
|
85
92
|
"format:check": "biome format .",
|
|
86
|
-
"build": "
|
|
93
|
+
"build": "tsc -p tsconfig.build.json && rm -rf dist/cli/templates && cp -R src/cli/templates dist/cli/templates && rm -rf dist/auth-turn/fixtures && cp -R src/auth-turn/fixtures dist/auth-turn/fixtures && cp src/auth-turn/auth-turn.v1.schema.json dist/auth-turn/auth-turn.v1.schema.json"
|
|
87
94
|
},
|
|
88
95
|
"devDependencies": {
|
|
96
|
+
"@arethetypeswrong/cli": "^0.18.5",
|
|
89
97
|
"@biomejs/biome": "^2.5.0",
|
|
90
98
|
"@types/bun": "latest",
|
|
91
99
|
"@types/node": "^25.9.3",
|
|
92
|
-
"
|
|
100
|
+
"typescript": "6.0.3"
|
|
93
101
|
},
|
|
94
102
|
"dependencies": {
|
|
95
103
|
"@clack/prompts": "^1.5.1",
|
|
104
|
+
"@rgrove/parse-xml": "4.2.2",
|
|
96
105
|
"@types/ms": "^2.1.0",
|
|
97
106
|
"acorn": "^8.17.0",
|
|
98
107
|
"ajv": "^8.17",
|
|
@@ -105,6 +114,8 @@
|
|
|
105
114
|
"puppeteer-extra-plugin-stealth": "^2.11.2",
|
|
106
115
|
"re2-wasm": "^1.0",
|
|
107
116
|
"safe-regex": "^2.1",
|
|
117
|
+
"socks": "^2.8.9",
|
|
118
|
+
"tough-cookie": "^6.0.2",
|
|
108
119
|
"zod": "^4.4.3"
|
|
109
120
|
},
|
|
110
121
|
"repository": {
|
package/src/auth-turn/index.ts
CHANGED