@apifuse/provider-sdk 2.2.0-beta.25 → 2.2.0-beta.26

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.
Files changed (62) hide show
  1. package/AUTHORING.md +7 -6
  2. package/CHANGELOG.md +5 -1
  3. package/README.md +3 -3
  4. package/bin/apifuse-check.ts +62 -3
  5. package/bin/apifuse-pack-check.ts +8 -2
  6. package/bin/apifuse-pack-smoke.ts +43 -2
  7. package/bin/apifuse-pack-types.ts +58 -0
  8. package/dist/auth.js +29 -0
  9. package/dist/cli/templates/provider/README.md.tpl +4 -4
  10. package/dist/contract-serialization.d.ts +20 -1
  11. package/dist/contract-serialization.js +583 -8
  12. package/dist/contract.d.ts +2 -0
  13. package/dist/contract.js +9 -5
  14. package/dist/declaration-validation.d.ts +23 -0
  15. package/dist/declaration-validation.js +159 -0
  16. package/dist/define.d.ts +1 -1
  17. package/dist/define.js +13 -2
  18. package/dist/index.d.ts +3 -2
  19. package/dist/index.js +2 -2
  20. package/dist/lint.js +85 -3
  21. package/dist/provider.d.ts +1 -1
  22. package/dist/provider.js +1 -1
  23. package/dist/runtime/resolver-vendors/bindings.d.ts +42 -2
  24. package/dist/runtime/resolver-vendors/bindings.js +31 -6
  25. package/dist/runtime/resolver-vendors/browser.d.ts +3 -7
  26. package/dist/runtime/resolver-vendors/browser.js +7 -22
  27. package/dist/runtime/resolver-vendors/hosts.d.ts +2 -0
  28. package/dist/runtime/resolver-vendors/hosts.js +33 -0
  29. package/dist/runtime/resolver-vendors/twocaptcha.d.ts +23 -0
  30. package/dist/runtime/resolver-vendors/twocaptcha.js +264 -0
  31. package/dist/runtime/resolver-vendors/types.d.ts +44 -3
  32. package/dist/runtime/resolver-vendors/types.js +10 -0
  33. package/dist/runtime/resolver.d.ts +17 -2
  34. package/dist/runtime/resolver.js +237 -15
  35. package/dist/runtime/stealth.d.ts +26 -4
  36. package/dist/runtime/stealth.js +224 -114
  37. package/dist/schema.d.ts +63 -0
  38. package/dist/schema.js +808 -8
  39. package/dist/server/serve.js +8 -0
  40. package/dist/stealth/profiles.js +16 -7
  41. package/dist/types.d.ts +34 -1
  42. package/package.json +2 -2
  43. package/src/auth.ts +40 -0
  44. package/src/cli/templates/provider/README.md.tpl +4 -4
  45. package/src/contract-serialization.ts +857 -8
  46. package/src/contract.ts +16 -5
  47. package/src/declaration-validation.ts +202 -0
  48. package/src/define.ts +23 -2
  49. package/src/index.ts +12 -0
  50. package/src/lint.ts +98 -3
  51. package/src/provider.ts +10 -0
  52. package/src/runtime/resolver-vendors/bindings.ts +40 -15
  53. package/src/runtime/resolver-vendors/browser.ts +9 -31
  54. package/src/runtime/resolver-vendors/hosts.ts +38 -0
  55. package/src/runtime/resolver-vendors/twocaptcha.ts +366 -0
  56. package/src/runtime/resolver-vendors/types.ts +54 -0
  57. package/src/runtime/resolver.ts +304 -24
  58. package/src/runtime/stealth.ts +317 -136
  59. package/src/schema.ts +1060 -9
  60. package/src/server/serve.ts +8 -0
  61. package/src/stealth/profiles.ts +17 -7
  62. package/src/types.ts +36 -3
@@ -0,0 +1,23 @@
1
+ import type { ChallengeSolution, ProviderChallenge } from "../../types.js";
2
+ import { type ResolverIdentity, type ResolverVendorAdapter } from "./types.js";
3
+ type Delay = (ms: number, signal: AbortSignal) => Promise<void>;
4
+ export interface TwoCaptchaResolverVendorOptions {
5
+ readonly apiKey?: string;
6
+ readonly timeoutMs?: number;
7
+ readonly pollIntervalMs?: number;
8
+ readonly allowedHosts: readonly string[];
9
+ readonly fetchImpl?: typeof fetch;
10
+ readonly baseUrl?: string;
11
+ /** Test-only clock override; supplying it disables the real-time deadline timer. */
12
+ readonly now?: () => number;
13
+ /** Test-only delay override used with `now` to exercise polling without sleeping. */
14
+ readonly delay?: Delay;
15
+ }
16
+ export interface TwoCaptchaResolverVendorAdapter extends ResolverVendorAdapter {
17
+ readonly id: "2captcha";
18
+ solve(challenge: ProviderChallenge, identity: ResolverIdentity | undefined, signal: AbortSignal): Promise<Extract<ChallengeSolution, {
19
+ readonly form: "token";
20
+ }>>;
21
+ }
22
+ export declare function createTwoCaptchaResolverVendorAdapter(options: TwoCaptchaResolverVendorOptions): TwoCaptchaResolverVendorAdapter;
23
+ export {};
@@ -0,0 +1,264 @@
1
+ import { assertResolverHostAllowed } from "./hosts.js";
2
+ import { ResolverVendorUnavailableError, resolverVendorSupports, } from "./types.js";
3
+ const TWOCAPTCHA_VENDOR_ID = "2captcha";
4
+ const DEFAULT_TWOCAPTCHA_BASE_URL = "https://api.2captcha.com";
5
+ const DEFAULT_POLL_INTERVAL_MS = 3_000;
6
+ const DEFAULT_TIMEOUT_MS = 180_000;
7
+ class TwoCaptchaSolveTimeoutError extends Error {
8
+ constructor() {
9
+ super("2captcha resolver solve budget elapsed");
10
+ this.name = "TwoCaptchaSolveTimeoutError";
11
+ }
12
+ }
13
+ function isJsonRecord(value) {
14
+ return value !== null && typeof value === "object" && !Array.isArray(value);
15
+ }
16
+ function abortReason(signal) {
17
+ return signal.reason ?? new DOMException("The operation was aborted", "AbortError");
18
+ }
19
+ function raceWithAbort(operation, signal, phase) {
20
+ if (signal.aborted)
21
+ return Promise.reject(abortReason(signal));
22
+ return new Promise((resolve, reject) => {
23
+ const cleanup = () => signal.removeEventListener("abort", onAbort);
24
+ const onAbort = () => {
25
+ cleanup();
26
+ reject(abortReason(signal));
27
+ };
28
+ signal.addEventListener("abort", onAbort, { once: true });
29
+ operation().then((value) => {
30
+ cleanup();
31
+ resolve(value);
32
+ }, (error) => {
33
+ cleanup();
34
+ if (phase === undefined) {
35
+ reject(error);
36
+ return;
37
+ }
38
+ reject(new ResolverVendorUnavailableError(TWOCAPTCHA_VENDOR_ID, "transport_failure", {
39
+ cause: error,
40
+ phase,
41
+ }));
42
+ });
43
+ });
44
+ }
45
+ async function abortableDelay(ms, signal) {
46
+ let timer;
47
+ try {
48
+ await raceWithAbort(() => new Promise((resolve) => {
49
+ timer = setTimeout(resolve, ms);
50
+ }), signal);
51
+ }
52
+ finally {
53
+ if (timer !== undefined)
54
+ clearTimeout(timer);
55
+ }
56
+ }
57
+ function parseProxyConfiguration(proxyUrl) {
58
+ try {
59
+ const url = new URL(proxyUrl);
60
+ const protocol = url.protocol.slice(0, -1).toLowerCase();
61
+ const proxyType = protocol === "socks4" || protocol === "socks5"
62
+ ? protocol
63
+ : protocol === "http" || protocol === "https"
64
+ ? "http"
65
+ : undefined;
66
+ const defaultPort = proxyType === "http" ? 80 : 1080;
67
+ const proxyPort = Number(url.port || defaultPort);
68
+ if (!proxyType || !url.hostname || !Number.isInteger(proxyPort) || proxyPort <= 0) {
69
+ return undefined;
70
+ }
71
+ const proxyLogin = url.username ? decodeURIComponent(url.username) : undefined;
72
+ const proxyPassword = url.password ? decodeURIComponent(url.password) : undefined;
73
+ return {
74
+ proxyType,
75
+ proxyAddress: url.hostname,
76
+ proxyPort,
77
+ ...(proxyLogin ? { proxyLogin } : {}),
78
+ ...(proxyPassword ? { proxyPassword } : {}),
79
+ };
80
+ }
81
+ catch {
82
+ return undefined;
83
+ }
84
+ }
85
+ function errorText(payload, key) {
86
+ const value = payload[key];
87
+ return typeof value === "string" ? value : "";
88
+ }
89
+ function isAllocationExhausted(payload) {
90
+ const code = errorText(payload, "errorCode").toLowerCase();
91
+ const description = errorText(payload, "errorDescription").toLowerCase();
92
+ return (code === "error_zero_balance" ||
93
+ /(?:insufficient|zero|no|not enough)\s+(?:balance|funds|credit)/u.test(`${code} ${description}`));
94
+ }
95
+ function unavailableForPayload(payload, phase) {
96
+ return new ResolverVendorUnavailableError(TWOCAPTCHA_VENDOR_ID, isAllocationExhausted(payload) ? "allocation_exhausted" : "transport_failure", { phase });
97
+ }
98
+ async function postJson(fetchImpl, url, body, signal, phase) {
99
+ const response = await raceWithAbort(() => fetchImpl(url, {
100
+ method: "POST",
101
+ headers: { "content-type": "application/json" },
102
+ body: JSON.stringify(body),
103
+ signal,
104
+ redirect: "error",
105
+ }), signal, phase);
106
+ let responseText;
107
+ try {
108
+ responseText = await raceWithAbort(() => response.text(), signal, phase);
109
+ }
110
+ catch (error) {
111
+ if (error instanceof ResolverVendorUnavailableError)
112
+ throw error;
113
+ throw new ResolverVendorUnavailableError(TWOCAPTCHA_VENDOR_ID, "transport_failure", {
114
+ cause: error,
115
+ phase,
116
+ });
117
+ }
118
+ let payload;
119
+ try {
120
+ payload = JSON.parse(responseText);
121
+ }
122
+ catch {
123
+ // JSON parse errors may contain response-body excerpts, so do not retain them as causes.
124
+ throw new ResolverVendorUnavailableError(TWOCAPTCHA_VENDOR_ID, "transport_failure", {
125
+ phase,
126
+ });
127
+ }
128
+ if (!isJsonRecord(payload)) {
129
+ throw new ResolverVendorUnavailableError(TWOCAPTCHA_VENDOR_ID, "transport_failure", {
130
+ phase,
131
+ });
132
+ }
133
+ return { ok: response.ok, payload };
134
+ }
135
+ function taskIdFrom(payload) {
136
+ const taskId = payload.taskId;
137
+ return typeof taskId === "string" || typeof taskId === "number" ? taskId : undefined;
138
+ }
139
+ function tokenFrom(payload) {
140
+ const solution = payload.solution;
141
+ if (!isJsonRecord(solution))
142
+ return undefined;
143
+ if (typeof solution.gRecaptchaResponse === "string")
144
+ return solution.gRecaptchaResponse;
145
+ return typeof solution.token === "string" ? solution.token : undefined;
146
+ }
147
+ function endpoint(baseUrl, path) {
148
+ return `${baseUrl.replace(/\/+$/u, "")}/${path}`;
149
+ }
150
+ export function createTwoCaptchaResolverVendorAdapter(options) {
151
+ const fetchImpl = options.fetchImpl ?? globalThis.fetch;
152
+ const baseUrl = options.baseUrl ?? DEFAULT_TWOCAPTCHA_BASE_URL;
153
+ const pollIntervalMs = options.pollIntervalMs ?? DEFAULT_POLL_INTERVAL_MS;
154
+ const timeoutMs = options.timeoutMs ?? DEFAULT_TIMEOUT_MS;
155
+ const now = options.now ?? Date.now;
156
+ const delay = options.delay ?? abortableDelay;
157
+ return {
158
+ id: TWOCAPTCHA_VENDOR_ID,
159
+ supports(kind) {
160
+ return resolverVendorSupports(TWOCAPTCHA_VENDOR_ID, kind);
161
+ },
162
+ async solve(challenge, identity, callerSignal) {
163
+ const apiKey = options.apiKey?.trim();
164
+ if (!apiKey) {
165
+ throw new ResolverVendorUnavailableError(TWOCAPTCHA_VENDOR_ID, "missing_credentials", {
166
+ phase: "create_task",
167
+ });
168
+ }
169
+ if (!resolverVendorSupports(TWOCAPTCHA_VENDOR_ID, challenge.kind)) {
170
+ throw new TypeError(`2captcha resolver does not support ${challenge.kind}`);
171
+ }
172
+ if (challenge.kind !== "recaptcha_v2") {
173
+ // AWS WAF remains deferred because its challenge variant has no required site key.
174
+ throw new ResolverVendorUnavailableError(TWOCAPTCHA_VENDOR_ID, "not_implemented", {
175
+ phase: "create_task",
176
+ });
177
+ }
178
+ assertResolverHostAllowed(challenge.pageUrl, options.allowedHosts);
179
+ callerSignal.throwIfAborted();
180
+ const proxy = identity ? parseProxyConfiguration(identity.proxyUrl) : undefined;
181
+ if (identity && !proxy) {
182
+ throw new ResolverVendorUnavailableError(TWOCAPTCHA_VENDOR_ID, "transport_failure", {
183
+ phase: "create_task",
184
+ });
185
+ }
186
+ const solveController = new AbortController();
187
+ const onCallerAbort = () => solveController.abort(abortReason(callerSignal));
188
+ callerSignal.addEventListener("abort", onCallerAbort, { once: true });
189
+ const timeout = options.now
190
+ ? undefined
191
+ : setTimeout(() => solveController.abort(new TwoCaptchaSolveTimeoutError()), timeoutMs);
192
+ const startedAt = now();
193
+ let phase = "create_task";
194
+ try {
195
+ const createResult = await postJson(fetchImpl, endpoint(baseUrl, "createTask"), {
196
+ clientKey: apiKey,
197
+ task: {
198
+ type: proxy ? "RecaptchaV2Task" : "RecaptchaV2TaskProxyless",
199
+ websiteURL: challenge.pageUrl,
200
+ websiteKey: challenge.siteKey,
201
+ isInvisible: false,
202
+ ...(identity ? { userAgent: identity.userAgent } : {}),
203
+ ...(proxy ?? {}),
204
+ },
205
+ }, solveController.signal, phase);
206
+ const taskId = taskIdFrom(createResult.payload);
207
+ if (!createResult.ok || createResult.payload.errorId !== 0 || taskId === undefined) {
208
+ throw unavailableForPayload(createResult.payload, phase);
209
+ }
210
+ phase = "poll_result";
211
+ while (true) {
212
+ callerSignal.throwIfAborted();
213
+ const remainingMs = timeoutMs - (now() - startedAt);
214
+ if (remainingMs <= 0)
215
+ throw new TwoCaptchaSolveTimeoutError();
216
+ await delay(Math.min(pollIntervalMs, remainingMs), solveController.signal);
217
+ callerSignal.throwIfAborted();
218
+ if (now() - startedAt >= timeoutMs)
219
+ throw new TwoCaptchaSolveTimeoutError();
220
+ const pollResult = await postJson(fetchImpl, endpoint(baseUrl, "getTaskResult"), { clientKey: apiKey, taskId }, solveController.signal, phase);
221
+ if (!pollResult.ok || pollResult.payload.errorId !== 0) {
222
+ throw unavailableForPayload(pollResult.payload, phase);
223
+ }
224
+ if (pollResult.payload.status === "processing")
225
+ continue;
226
+ if (pollResult.payload.status !== "ready") {
227
+ throw new ResolverVendorUnavailableError(TWOCAPTCHA_VENDOR_ID, "transport_failure", {
228
+ phase,
229
+ });
230
+ }
231
+ const token = tokenFrom(pollResult.payload);
232
+ if (!token?.trim()) {
233
+ throw new ResolverVendorUnavailableError(TWOCAPTCHA_VENDOR_ID, "transport_failure", {
234
+ phase,
235
+ });
236
+ }
237
+ return { form: "token", token };
238
+ }
239
+ }
240
+ catch (error) {
241
+ if (callerSignal.aborted)
242
+ throw abortReason(callerSignal);
243
+ if (error instanceof TwoCaptchaSolveTimeoutError ||
244
+ solveController.signal.reason instanceof TwoCaptchaSolveTimeoutError) {
245
+ throw new ResolverVendorUnavailableError(TWOCAPTCHA_VENDOR_ID, "timeout", {
246
+ cause: error,
247
+ phase,
248
+ });
249
+ }
250
+ if (error instanceof ResolverVendorUnavailableError)
251
+ throw error;
252
+ throw new ResolverVendorUnavailableError(TWOCAPTCHA_VENDOR_ID, "transport_failure", {
253
+ cause: error,
254
+ phase,
255
+ });
256
+ }
257
+ finally {
258
+ if (timeout !== undefined)
259
+ clearTimeout(timeout);
260
+ callerSignal.removeEventListener("abort", onCallerAbort);
261
+ }
262
+ },
263
+ };
264
+ }
@@ -2,10 +2,10 @@ import type { ChallengeSolution, ProviderChallenge, ProviderChallengeKind, Provi
2
2
  import type { TraceRecorder } from "../trace.js";
3
3
  export declare const RESOLVER_VENDOR_CAPABILITIES: {
4
4
  readonly browser: readonly ["aws_waf", "cloudflare_interstitial"];
5
- readonly "2captcha": readonly ["turnstile", "recaptcha_v2", "recaptcha_v3", "hcaptcha", "cloudflare_interstitial", "aws_waf"];
5
+ readonly "2captcha": readonly ["turnstile", "recaptcha_v2", "recaptcha_v3", "hcaptcha", "cloudflare_interstitial", "aws_waf", "akamai_sec_cpt", "akamai_sensor"];
6
6
  readonly capsolver: readonly ["turnstile", "recaptcha_v2", "recaptcha_v3", "hcaptcha", "cloudflare_interstitial", "aws_waf"];
7
7
  readonly capmonster: readonly ["turnstile", "recaptcha_v2", "recaptcha_v3", "hcaptcha"];
8
- readonly custom: readonly ["turnstile", "recaptcha_v2", "recaptcha_v3", "hcaptcha", "cloudflare_interstitial", "aws_waf"];
8
+ readonly custom: readonly ["turnstile", "recaptcha_v2", "recaptcha_v3", "hcaptcha", "cloudflare_interstitial", "aws_waf", "akamai_sec_cpt", "akamai_sensor"];
9
9
  };
10
10
  export declare function resolverVendorSupports(vendor: ProviderResolverVendor, kind: ProviderChallengeKind): boolean;
11
11
  export interface ResolverIdentity {
@@ -17,21 +17,62 @@ export interface ResolverIssuingIdentity {
17
17
  readonly proxyUrl?: string;
18
18
  readonly userAgent: string;
19
19
  }
20
+ export interface ResolverVendorTransport {
21
+ /**
22
+ * Bound to the resolved proxy lease and client profile.
23
+ * Implementations MUST NOT follow redirects and MUST return the initial redirect response.
24
+ */
25
+ fetch(url: string, init: {
26
+ method: "GET" | "POST";
27
+ headers?: Readonly<Record<string, string>>;
28
+ body?: string;
29
+ signal: AbortSignal;
30
+ /** Implementations MUST honor manual redirect handling when the SDK guard sets it. */
31
+ redirect?: "manual";
32
+ }): Promise<{
33
+ readonly status: number;
34
+ readonly headers: Readonly<Record<string, string>>;
35
+ readonly body: string;
36
+ /** Cookies observed on the response, including cache-relevant attributes. */
37
+ readonly cookies: readonly {
38
+ readonly name: string;
39
+ readonly value: string;
40
+ /** Epoch seconds. A session cookie must be undefined, never CDP's -1 sentinel. */
41
+ readonly expires?: number;
42
+ readonly httpOnly: boolean;
43
+ readonly secure: boolean;
44
+ readonly domain?: string;
45
+ readonly path?: string;
46
+ readonly sameSite?: string;
47
+ }[];
48
+ }>;
49
+ }
20
50
  export interface ResolverVendorAdapter {
21
51
  readonly id: ProviderResolverVendor;
52
+ readonly requiresTransport?: boolean | ((kind: ProviderChallengeKind) => boolean);
22
53
  supports(kind: ProviderChallengeKind): boolean;
23
54
  /** Identity the adapter actually used, reported after a successful solve. */
24
55
  getIssuingIdentity?(solution: ChallengeSolution, requestedIdentity: ResolverIdentity | undefined, challenge: ProviderChallenge): ResolverIssuingIdentity | undefined;
25
- solve(challenge: ProviderChallenge, identity: ResolverIdentity | undefined, signal: AbortSignal, traceRecorder?: TraceRecorder): Promise<ChallengeSolution>;
56
+ solve(challenge: ProviderChallenge, identity: ResolverIdentity | undefined, signal: AbortSignal, traceRecorder?: TraceRecorder, transport?: ResolverVendorTransport): Promise<ChallengeSolution>;
26
57
  }
27
58
  export type ResolverVendorUnavailableReason = "missing_credentials" | "missing_transport" | "allocation_exhausted" | "transport_failure" | "timeout" | "not_implemented";
28
59
  export type ResolverChallengeVerdictReason = "human_puzzle";
29
60
  type ResolverErrorOptions = {
61
+ /** Raw cause; adapters must not place bodies, cookies, headers, credentials, or proxy URLs here. */
30
62
  readonly cause?: unknown;
63
+ /** Upstream hostname only; never a URL. */
64
+ readonly upstreamHost?: string;
65
+ /** Adapter-defined sensor-loop phase, such as fetch_script or post_sensor. */
66
+ readonly phase?: string;
67
+ /** One-based sensor-loop round when known. */
68
+ readonly round?: number;
31
69
  };
32
70
  export declare class ResolverVendorUnavailableError extends Error {
33
71
  readonly vendor: ProviderResolverVendor;
34
72
  readonly reason: ResolverVendorUnavailableReason;
73
+ readonly upstreamHost?: string;
74
+ readonly phase?: string;
75
+ readonly round?: number;
35
76
  constructor(vendor: ProviderResolverVendor, reason: ResolverVendorUnavailableReason, options?: ResolverErrorOptions);
36
77
  }
37
78
  export declare class ResolverChallengeVerdictError extends Error {
@@ -7,6 +7,8 @@ export const RESOLVER_VENDOR_CAPABILITIES = {
7
7
  "hcaptcha",
8
8
  "cloudflare_interstitial",
9
9
  "aws_waf",
10
+ "akamai_sec_cpt",
11
+ "akamai_sensor",
10
12
  ],
11
13
  capsolver: [
12
14
  "turnstile",
@@ -24,6 +26,8 @@ export const RESOLVER_VENDOR_CAPABILITIES = {
24
26
  "hcaptcha",
25
27
  "cloudflare_interstitial",
26
28
  "aws_waf",
29
+ "akamai_sec_cpt",
30
+ "akamai_sensor",
27
31
  ],
28
32
  };
29
33
  export function resolverVendorSupports(vendor, kind) {
@@ -32,6 +36,9 @@ export function resolverVendorSupports(vendor, kind) {
32
36
  export class ResolverVendorUnavailableError extends Error {
33
37
  vendor;
34
38
  reason;
39
+ upstreamHost;
40
+ phase;
41
+ round;
35
42
  constructor(vendor, reason, options = {}) {
36
43
  super(`Resolver vendor ${vendor} is unavailable: ${reason}`);
37
44
  this.vendor = vendor;
@@ -40,6 +47,9 @@ export class ResolverVendorUnavailableError extends Error {
40
47
  if (options.cause !== undefined) {
41
48
  this.cause = options.cause;
42
49
  }
50
+ this.upstreamHost = options.upstreamHost;
51
+ this.phase = options.phase;
52
+ this.round = options.round;
43
53
  }
44
54
  }
45
55
  export class ResolverChallengeVerdictError extends Error {
@@ -1,5 +1,5 @@
1
1
  import type { ChallengeSolution, ProviderCache, ProviderChallenge, ProviderChallengeKind, ProviderResolverConfig, ProviderResolverVendor, ResolverContext } from "../types.js";
2
- import { type ResolverIdentity, type ResolverVendorAdapter } from "./resolver-vendors/types.js";
2
+ import { type ResolverIdentity, type ResolverVendorAdapter, type ResolverVendorTransport } from "./resolver-vendors/types.js";
3
3
  import type { TraceRecorder } from "./trace.js";
4
4
  export declare const APIFUSE__RESOLVER__2CAPTCHA__API_KEY = "APIFUSE__RESOLVER__2CAPTCHA__API_KEY";
5
5
  export declare const APIFUSE__RESOLVER__CAPSOLVER__API_KEY = "APIFUSE__RESOLVER__CAPSOLVER__API_KEY";
@@ -16,14 +16,23 @@ export interface ResolverRuntimeOptions {
16
16
  readonly cache?: ProviderCache;
17
17
  /** Server-owned context/proxy scope used only for identity-bound cache entries. */
18
18
  readonly identityScope?: string;
19
+ /** SDK-owned transport already bound to the resolved proxy lease and client profile. */
20
+ readonly transport?: ResolverVendorTransport;
21
+ /** Creates an SDK-owned transport bound to the declared profile and server-owned scope. */
22
+ readonly createTransport?: (input: {
23
+ readonly clientProfile?: string;
24
+ /** Server-owned proxy/context scope; the SDK never accepts a caller-built identity. */
25
+ readonly identityScope?: string;
26
+ }) => ResolverVendorTransport;
19
27
  }
20
28
  export declare const RESOLVER_INSTRUMENTATION_METADATA: unique symbol;
21
29
  export type ResolverInstrumentationMetadata = {
22
30
  readonly target: ResolverContext;
23
31
  readonly traceRecorder: TraceRecorder;
24
32
  };
25
- type ResolverAdapterFactory = (configuration: string, timeoutMs: number, allowedHosts: readonly string[]) => ResolverVendorAdapter;
33
+ export type ResolverAdapterFactory = (configuration: string, timeoutMs: number, allowedHosts: readonly string[]) => ResolverVendorAdapter;
26
34
  export declare const RESOLVER_ADAPTER_REGISTRY: Partial<Readonly<Record<ProviderResolverVendor, ResolverAdapterFactory>>>;
35
+ export declare function swapResolverAdapterFactoryForTests(vendor: ProviderResolverVendor, factory: ResolverAdapterFactory | undefined): () => void;
27
36
  /** Remove the cached entry for the exact solution object returned by this resolver. */
28
37
  export declare function invalidateResolverSolution(resolver: ResolverContext, challenge: ProviderChallenge, solution: ChallengeSolution): Promise<void>;
29
38
  export declare function createResolverClient(options: {
@@ -32,8 +41,14 @@ export declare function createResolverClient(options: {
32
41
  readonly unavailableReason?: string;
33
42
  readonly cache?: ProviderCache;
34
43
  readonly identity?: ResolverIdentity;
44
+ readonly transport?: ResolverVendorTransport;
45
+ readonly createTransport?: ResolverRuntimeOptions["createTransport"];
46
+ readonly clientProfile?: string;
47
+ readonly allowedHosts?: readonly string[];
35
48
  }): ResolverChainClient;
36
49
  export declare function createUnsupportedResolverClient(reason?: string): ResolverContext;
37
50
  export declare function bindResolverSignal(resolver: ResolverContext, defaultSignal: AbortSignal | undefined): ResolverContext;
38
51
  export declare function createResolverClientFromEnv(config: ProviderResolverConfig | undefined, env?: EnvLike, options?: ResolverRuntimeOptions): ResolverContext;
52
+ /** Internal test seam; deliberately not re-exported from the package root. */
53
+ export declare function createResolverClientFromEnvForTests(config: ProviderResolverConfig | undefined, env: EnvLike, options: ResolverRuntimeOptions, adapterFactories: Partial<Readonly<Record<ProviderResolverVendor, ResolverAdapterFactory>>>): ResolverContext;
39
54
  export {};