@apifuse/provider-sdk 2.2.0-beta.7 → 2.2.0-beta.9
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/CHANGELOG.md +8 -0
- package/dist/auth-turn/index.d.ts +2 -2
- package/dist/config/loader.d.ts +147 -6
- package/dist/config/loader.js +360 -48
- package/dist/define.js +63 -8
- package/dist/runtime/choice.js +20 -2
- package/dist/runtime/http.js +115 -9
- package/dist/runtime/proxy-errors.js +6 -2
- package/dist/runtime/proxy-nodemaven.d.ts +35 -0
- package/dist/runtime/proxy-nodemaven.js +128 -0
- package/dist/runtime/proxy-telemetry.d.ts +2 -1
- package/dist/runtime/proxy-telemetry.js +39 -4
- package/dist/runtime/state.js +12 -1
- package/dist/runtime/stealth.js +60 -18
- package/dist/server/serve.js +11 -0
- package/dist/server/types.d.ts +9 -9
- package/dist/types.d.ts +30 -1
- package/package.json +4 -3
- package/src/config/loader.ts +514 -61
- package/src/define.ts +76 -13
- package/src/runtime/choice.ts +25 -4
- package/src/runtime/http.ts +134 -11
- package/src/runtime/proxy-errors.ts +12 -4
- package/src/runtime/proxy-nodemaven.ts +178 -0
- package/src/runtime/proxy-telemetry.ts +56 -5
- package/src/runtime/state.ts +11 -1
- package/src/runtime/stealth.ts +68 -22
- package/src/server/serve.ts +11 -0
- package/src/types.ts +30 -1
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,13 @@
|
|
|
1
1
|
# @apifuse/provider-sdk Changelog
|
|
2
2
|
|
|
3
|
+
## 2.2.0-beta.9
|
|
4
|
+
|
|
5
|
+
- Release candidate for main commit 5c78c8b (bundles #67 nodemaven required-secret + #68 transport vendor-advance).
|
|
6
|
+
|
|
7
|
+
## 2.2.0-beta.8
|
|
8
|
+
|
|
9
|
+
- Release candidate for main commit 9e8a3f028ee78b9cab29d4aa3f5494ac9cffa65f.
|
|
10
|
+
|
|
3
11
|
## 2.2.0-beta.7
|
|
4
12
|
|
|
5
13
|
- Release candidate for main commit 2ce4ea4bd36ce333eba8b3b474bf6e82b5e9216c.
|
|
@@ -87,7 +87,7 @@ export declare const AUTH_TURN_SCHEMA: {
|
|
|
87
87
|
};
|
|
88
88
|
readonly $defs: {
|
|
89
89
|
readonly completeTurnData: {
|
|
90
|
-
readonly title:
|
|
90
|
+
readonly title: "Terminal payload for kind \"complete\"";
|
|
91
91
|
readonly description: "data payload of a complete turn. The gateway extracts data.credential for persistence; complete turns are never echoed to browsers.";
|
|
92
92
|
readonly type: "object";
|
|
93
93
|
readonly additionalProperties: true;
|
|
@@ -104,7 +104,7 @@ export declare const AUTH_TURN_SCHEMA: {
|
|
|
104
104
|
};
|
|
105
105
|
};
|
|
106
106
|
readonly abortTurnData: {
|
|
107
|
-
readonly title:
|
|
107
|
+
readonly title: "Terminal payload for kind \"abort\"";
|
|
108
108
|
readonly description: "data payload of an abort turn. code, when present, is the machine-readable abort reason.";
|
|
109
109
|
readonly type: "object";
|
|
110
110
|
readonly additionalProperties: true;
|
package/dist/config/loader.d.ts
CHANGED
|
@@ -1,5 +1,9 @@
|
|
|
1
1
|
import { Redis } from "ioredis";
|
|
2
2
|
import type { ProviderProxyPolicy, TraceConfig } from "../types.js";
|
|
3
|
+
import { type ProxyProtocol } from "../runtime/proxy-nodemaven.js";
|
|
4
|
+
export type { ProxyProtocol } from "../runtime/proxy-nodemaven.js";
|
|
5
|
+
/** Proxy vendors the SDK resolves natively (as opposed to the static env path). */
|
|
6
|
+
export type ProxyVendorName = "smartproxy" | "nodemaven";
|
|
3
7
|
export declare const SMARTPROXY_APP_KEY_ENV = "APIFUSE__PROXY__SMARTPROXY_APP_KEY";
|
|
4
8
|
export declare const SMARTPROXY_MAX_LIFETIME_MINUTES = 2000;
|
|
5
9
|
export declare const DEFAULT_SMARTPROXY_POOL_SIZE = 20;
|
|
@@ -42,12 +46,33 @@ export type ProxyResolutionOptions = {
|
|
|
42
46
|
affinityKey?: string;
|
|
43
47
|
/** Zero-based proxy-pool attempt index used by SDK transports for failover. */
|
|
44
48
|
proxyAttempt?: number;
|
|
49
|
+
/**
|
|
50
|
+
* Tunnelling protocols the calling transport can use. When a resolved
|
|
51
|
+
* protocol is not in this set the resolver fails with
|
|
52
|
+
* `PROXY_PROTOCOL_UNSUPPORTED` instead of silently downgrading. Unset means
|
|
53
|
+
* permissive (both protocols allowed).
|
|
54
|
+
*/
|
|
55
|
+
transportProtocols?: readonly ProxyProtocol[];
|
|
56
|
+
/**
|
|
57
|
+
* Explicit protocol override. Internal — for the verification harness and
|
|
58
|
+
* tests, or an advanced caller. Normal callers omit it and each vendor uses
|
|
59
|
+
* its own benchmarked default protocol (see VENDOR_DEFAULT_PROTOCOL). Not an
|
|
60
|
+
* env var and not a provider-policy field.
|
|
61
|
+
*/
|
|
62
|
+
protocol?: ProxyProtocol;
|
|
63
|
+
/**
|
|
64
|
+
* Gateway pool "refresh" generation. Bumped by transports on pool refresh to
|
|
65
|
+
* derive a fresh gateway session set (ignored by allocation-style vendors,
|
|
66
|
+
* whose refresh is driven by cache invalidation).
|
|
67
|
+
*/
|
|
68
|
+
proxyRefreshEpoch?: number;
|
|
45
69
|
telemetry?: ProxyTelemetrySink;
|
|
46
70
|
};
|
|
47
71
|
export type ProxyCacheStatus = "memory_hit" | "redis_hit" | "allocator" | "soft_stale_refresh" | "lock_wait" | "redis_error" | "redis_corrupt" | "disabled";
|
|
48
72
|
export type SmartproxyAllocatorBodyClass = "network_error" | "http_error" | "empty" | "json_without_proxies" | "text_without_proxies" | "usable_proxy_endpoints";
|
|
49
73
|
export type ProxyResolutionTelemetryEvent = {
|
|
50
|
-
provider:
|
|
74
|
+
provider: ProxyVendorName;
|
|
75
|
+
protocol?: ProxyProtocol;
|
|
51
76
|
cacheStatus: ProxyCacheStatus;
|
|
52
77
|
cacheHit: boolean;
|
|
53
78
|
resolutionMs: number;
|
|
@@ -64,7 +89,7 @@ export type ProxyResolutionTelemetryEvent = {
|
|
|
64
89
|
refreshes?: number;
|
|
65
90
|
};
|
|
66
91
|
export type ProxyAttemptTelemetryEvent = {
|
|
67
|
-
provider:
|
|
92
|
+
provider: ProxyVendorName;
|
|
68
93
|
attempt: number;
|
|
69
94
|
poolIndex?: number;
|
|
70
95
|
proxyHash?: string;
|
|
@@ -73,22 +98,40 @@ export type ProxyAttemptTelemetryEvent = {
|
|
|
73
98
|
status?: number;
|
|
74
99
|
durationMs?: number;
|
|
75
100
|
};
|
|
101
|
+
export type ProxyVendorFailoverTelemetryEvent = {
|
|
102
|
+
/** Vendor that failed or was skipped. */
|
|
103
|
+
vendor: ProxyVendorName;
|
|
104
|
+
/** Vendor tried next, or undefined when the chain is exhausted. */
|
|
105
|
+
nextVendor?: ProxyVendorName;
|
|
106
|
+
phase: "resolution" | "transport";
|
|
107
|
+
reason: "no_credentials" | "allocation_failed" | "pool_exhausted" | "protocol_unsupported";
|
|
108
|
+
attempt?: number;
|
|
109
|
+
};
|
|
76
110
|
export type ProxyTelemetrySink = {
|
|
77
111
|
recordProxyResolution(event: ProxyResolutionTelemetryEvent): void;
|
|
78
112
|
recordProxyAttempt?(event: ProxyAttemptTelemetryEvent): void;
|
|
113
|
+
recordProxyVendorFailover?(event: ProxyVendorFailoverTelemetryEvent): void;
|
|
79
114
|
};
|
|
80
115
|
export type ResolvedProxyConfig = {
|
|
81
116
|
shouldWarn: boolean;
|
|
82
117
|
url?: string;
|
|
83
|
-
source?: "explicit" | "env" | "config" | "smartproxy-allocator";
|
|
118
|
+
source?: "explicit" | "env" | "config" | "smartproxy-allocator" | "nodemaven-gateway";
|
|
119
|
+
protocol?: ProxyProtocol;
|
|
84
120
|
diagnostics?: Record<string, string | number | boolean>;
|
|
85
121
|
};
|
|
122
|
+
export type ProxyResolutionErrorCode = "PROXY_REQUIRED" | "PROXY_ALLOCATION_FAILED" | "PROXY_PROTOCOL_UNSUPPORTED";
|
|
86
123
|
export declare class ProxyResolutionError extends Error {
|
|
87
|
-
readonly code:
|
|
124
|
+
readonly code: ProxyResolutionErrorCode;
|
|
88
125
|
readonly telemetry?: ProxyResolutionTelemetryEvent;
|
|
89
|
-
|
|
126
|
+
readonly vendor?: ProxyVendorName;
|
|
127
|
+
readonly vendorChain?: ProxyVendorName[];
|
|
128
|
+
readonly protocol?: ProxyProtocol;
|
|
129
|
+
constructor(code: ProxyResolutionErrorCode, message: string, options?: {
|
|
90
130
|
cause?: unknown;
|
|
91
131
|
telemetry?: ProxyResolutionTelemetryEvent;
|
|
132
|
+
vendor?: ProxyVendorName;
|
|
133
|
+
vendorChain?: ProxyVendorName[];
|
|
134
|
+
protocol?: ProxyProtocol;
|
|
92
135
|
});
|
|
93
136
|
}
|
|
94
137
|
type ProxyRedisClient = Pick<Redis, "connect" | "del" | "eval" | "get" | "on" | "pttl" | "set" | "status">;
|
|
@@ -99,9 +142,107 @@ export declare function __setProxyRedisForTests(redis: ProxyRedisClient | undefi
|
|
|
99
142
|
export declare function __setSmartproxyAllocatorDeadlineMsForTests(deadlineMs: number | undefined): void;
|
|
100
143
|
export declare function resolveProxyConfig(options?: ProxyResolutionOptions): ResolvedProxyConfig;
|
|
101
144
|
export declare function resolveProxyConfigAsync(options?: ProxyResolutionOptions): Promise<ResolvedProxyConfig>;
|
|
145
|
+
/**
|
|
146
|
+
* Guard the No-MITM invariant: a resolved proxy URL must use a tunnelling scheme
|
|
147
|
+
* (http CONNECT or socks5) so the client TLS handshake reaches the origin
|
|
148
|
+
* end-to-end. Anything else would intercept TLS and break fingerprinting.
|
|
149
|
+
*/
|
|
150
|
+
export declare function assertTunnelingScheme(url: string): void;
|
|
151
|
+
/**
|
|
152
|
+
* Ordered list of SDK-native proxy vendors declared by the policy. `providers`
|
|
153
|
+
* takes precedence over the legacy singular `provider`; the platform default
|
|
154
|
+
* env is the final fallback. Non-registry names (decodo/custom) are dropped so
|
|
155
|
+
* an all-static chain falls through to the legacy env-URL path unchanged.
|
|
156
|
+
*/
|
|
157
|
+
export declare function resolveVendorChain(policy: ProviderProxyPolicy): ProxyVendorName[];
|
|
158
|
+
/**
|
|
159
|
+
* Total attempt span across a policy's vendor chain — the sum of each vendor's
|
|
160
|
+
* pool size. Transports use this so successive attempts rotate a vendor's pool
|
|
161
|
+
* and then fail over to the next vendor via the flat attempt index. With one
|
|
162
|
+
* vendor this equals that vendor's pool size (today's behaviour).
|
|
163
|
+
*/
|
|
164
|
+
export declare function resolvePolicyProxyPoolSpan(policy: ProviderProxyPolicy): number;
|
|
165
|
+
/**
|
|
166
|
+
* Absolute upper bound on a chain's attempt span — the sum of each vendor's
|
|
167
|
+
* *maximum* pool size. Unlike `resolvePolicyProxyPoolSpan` (the configured
|
|
168
|
+
* span), this backstop is independent of `session.poolSize`, so it never
|
|
169
|
+
* truncates a legitimately large pool below the point where the flat attempt
|
|
170
|
+
* index would cross into the next vendor (e.g. a 50-slot NodeMaven pool).
|
|
171
|
+
*/
|
|
172
|
+
export declare function maxPolicyProxyPoolSpan(policy: ProviderProxyPolicy): number;
|
|
173
|
+
/**
|
|
174
|
+
* Transport-retry attempt cap for a policy-managed request. A transport failure
|
|
175
|
+
* rotates the flat attempt index onto the *next* endpoint (and, once the index
|
|
176
|
+
* passes the primary vendor's pool span, the *next vendor*), so the cap must be
|
|
177
|
+
* the chain's full pool span for failover to reach the fallback vendor — the
|
|
178
|
+
* per-endpoint retry budget (default 3) never gets there.
|
|
179
|
+
*
|
|
180
|
+
* The span only widens beyond the caller's retry budget when ALL hold:
|
|
181
|
+
* - the request is policy-allocator managed (not a caller-supplied proxy URL);
|
|
182
|
+
* - the caller did NOT pin an explicit retry policy — `HttpRetryOptions.attempts`
|
|
183
|
+
* is the documented total-attempt ceiling and must be honoured verbatim;
|
|
184
|
+
* - the method is safe/idempotent — an unsafe request must never be duplicated
|
|
185
|
+
* across the pool even if some framework default would allow it;
|
|
186
|
+
* - the policy resolves a non-empty *registry* vendor chain (smartproxy /
|
|
187
|
+
* nodemaven). Static vendors (custom / decodo) and credential-less policies
|
|
188
|
+
* resolve no allocator pool, so every attempt would hit the same endpoint
|
|
189
|
+
* with no possible crossover — they keep the retry budget.
|
|
190
|
+
*
|
|
191
|
+
* The widened cap is bounded by the chain's true maximum span (sum of each
|
|
192
|
+
* vendor's max pool size), so a large NodeMaven pool (≤50) stays reachable and
|
|
193
|
+
* a pathological chain can never spin unbounded.
|
|
194
|
+
*/
|
|
195
|
+
/**
|
|
196
|
+
* True when a policy request is in *implicit chain-rotation* mode: successive
|
|
197
|
+
* transport attempts rotate the flat index across the concatenated vendor pool
|
|
198
|
+
* spans (and, past the primary vendor's span, into the fallback vendor). This is
|
|
199
|
+
* the ONLY mode in which the transport loop widens its attempt cap AND
|
|
200
|
+
* de-duplicates repeated endpoints — the two behaviours must share one predicate
|
|
201
|
+
* so they never diverge. It holds when ALL of the widening conditions hold:
|
|
202
|
+
* - the request is policy-allocator managed (not a caller-supplied proxy URL);
|
|
203
|
+
* - the caller did NOT pin an explicit retry policy — its `attempts` ceiling is
|
|
204
|
+
* the documented contract and must be honoured verbatim against whatever
|
|
205
|
+
* endpoint each attempt resolves (even a repeated one), so no de-duplication;
|
|
206
|
+
* - the method is safe/idempotent — an unsafe request is never duplicated;
|
|
207
|
+
* - the policy resolves a non-empty registry vendor chain (smartproxy /
|
|
208
|
+
* nodemaven). Static vendors (custom / decodo) resolve the same URL every
|
|
209
|
+
* attempt, so there is nothing to rotate or de-duplicate.
|
|
210
|
+
*/
|
|
211
|
+
export declare function policyRotatesTransportVendorChain(input: {
|
|
212
|
+
policy: ProviderProxyPolicy | undefined;
|
|
213
|
+
usesPolicyAllocator: boolean;
|
|
214
|
+
explicitRetry: boolean;
|
|
215
|
+
method: string;
|
|
216
|
+
}): boolean;
|
|
217
|
+
export declare function resolvePolicyTransportAttemptCap(input: {
|
|
218
|
+
policy: ProviderProxyPolicy | undefined;
|
|
219
|
+
usesPolicyAllocator: boolean;
|
|
220
|
+
retryAttempts: number;
|
|
221
|
+
explicitRetry: boolean;
|
|
222
|
+
method: string;
|
|
223
|
+
}): number;
|
|
224
|
+
/**
|
|
225
|
+
* A registry vendor chain (smartproxy/nodemaven) resolves a potentially
|
|
226
|
+
* *different* endpoint per flat attempt index, so a transport retry should
|
|
227
|
+
* advance across endpoints and de-duplicate once the chain stops yielding new
|
|
228
|
+
* ones. Static/custom/decodo policies (empty registry chain) resolve the *same*
|
|
229
|
+
* URL every attempt by design — retrying that same endpoint is intended, so the
|
|
230
|
+
* transport loop must not de-duplicate them.
|
|
231
|
+
*/
|
|
232
|
+
export declare function policyResolvesRegistryVendorChain(policy: ProviderProxyPolicy | undefined): boolean;
|
|
233
|
+
/** Map a resolved proxy source label to the vendor that served it. */
|
|
234
|
+
export declare function vendorFromResolvedSource(source: ResolvedProxyConfig["source"]): ProxyVendorName | undefined;
|
|
235
|
+
/**
|
|
236
|
+
* Map a flat attempt index into (vendorIndex, poolIndex) by concatenating each
|
|
237
|
+
* vendor's pool space in chain order. With a single vendor this reduces to
|
|
238
|
+
* `attempt % poolSize`, preserving today's behaviour exactly.
|
|
239
|
+
*/
|
|
240
|
+
export declare function mapFlatAttempt(flat: number, sizes: readonly number[]): {
|
|
241
|
+
vendorIndex: number;
|
|
242
|
+
poolIndex: number;
|
|
243
|
+
};
|
|
102
244
|
export declare function clearProxyResolutionCache(): void;
|
|
103
245
|
export declare function invalidateProxyResolutionCache(options?: ProxyResolutionOptions): boolean;
|
|
104
246
|
export declare function invalidateProxyResolutionCacheAsync(options?: ProxyResolutionOptions): Promise<boolean>;
|
|
105
247
|
export declare function defineConfig(config: ApiFuseConfig): ApiFuseConfig;
|
|
106
248
|
export declare function loadApiFuseConfig(dir?: string): Promise<ApiFuseConfig>;
|
|
107
|
-
export {};
|