@apifuse/provider-sdk 2.2.0-beta.24 → 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.
- package/AUTHORING.md +7 -6
- package/CHANGELOG.md +9 -1
- package/README.md +3 -3
- package/bin/apifuse-check.ts +62 -3
- package/bin/apifuse-pack-check.ts +8 -2
- package/bin/apifuse-pack-smoke.ts +43 -2
- package/bin/apifuse-pack-types.ts +58 -0
- package/bin/apifuse-submit-check.ts +15 -2
- package/dist/auth.js +29 -0
- package/dist/cli/templates/provider/README.md.tpl +4 -4
- package/dist/contract-serialization.d.ts +20 -1
- package/dist/contract-serialization.js +583 -8
- package/dist/contract.d.ts +2 -0
- package/dist/contract.js +9 -5
- package/dist/declaration-validation.d.ts +23 -0
- package/dist/declaration-validation.js +159 -0
- package/dist/define.d.ts +1 -1
- package/dist/define.js +13 -2
- package/dist/index.d.ts +4 -3
- package/dist/index.js +3 -3
- package/dist/lint.js +85 -3
- package/dist/provider.d.ts +1 -1
- package/dist/provider.js +1 -1
- package/dist/runtime/cache.d.ts +1 -0
- package/dist/runtime/cache.js +169 -15
- package/dist/runtime/resolver-vendors/bindings.d.ts +42 -2
- package/dist/runtime/resolver-vendors/bindings.js +31 -6
- package/dist/runtime/resolver-vendors/browser.d.ts +3 -7
- package/dist/runtime/resolver-vendors/browser.js +7 -22
- 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 +23 -0
- package/dist/runtime/resolver-vendors/twocaptcha.js +264 -0
- package/dist/runtime/resolver-vendors/types.d.ts +44 -3
- package/dist/runtime/resolver-vendors/types.js +10 -0
- package/dist/runtime/resolver.d.ts +17 -2
- package/dist/runtime/resolver.js +237 -15
- package/dist/runtime/stealth.d.ts +26 -4
- package/dist/runtime/stealth.js +224 -114
- package/dist/schema.d.ts +63 -0
- package/dist/schema.js +808 -8
- package/dist/server/serve.js +8 -0
- package/dist/stealth/profiles.js +16 -7
- package/dist/types.d.ts +37 -4
- package/package.json +2 -2
- package/src/auth.ts +40 -0
- package/src/cli/templates/provider/README.md.tpl +4 -4
- package/src/contract-serialization.ts +857 -8
- package/src/contract.ts +16 -5
- package/src/declaration-validation.ts +202 -0
- package/src/define.ts +23 -2
- package/src/index.ts +13 -0
- package/src/lint.ts +98 -3
- package/src/provider.ts +10 -0
- package/src/runtime/cache.ts +189 -14
- package/src/runtime/resolver-vendors/bindings.ts +40 -15
- package/src/runtime/resolver-vendors/browser.ts +9 -31
- package/src/runtime/resolver-vendors/hosts.ts +38 -0
- package/src/runtime/resolver-vendors/twocaptcha.ts +366 -0
- package/src/runtime/resolver-vendors/types.ts +54 -0
- package/src/runtime/resolver.ts +304 -24
- package/src/runtime/stealth.ts +317 -136
- package/src/schema.ts +1060 -9
- package/src/server/serve.ts +8 -0
- package/src/stealth/profiles.ts +17 -7
- package/src/types.ts +39 -6
|
@@ -0,0 +1,366 @@
|
|
|
1
|
+
import type { ChallengeSolution, ProviderChallenge } from "../../types.js";
|
|
2
|
+
import { assertResolverHostAllowed } from "./hosts.js";
|
|
3
|
+
import {
|
|
4
|
+
type ResolverIdentity,
|
|
5
|
+
type ResolverVendorAdapter,
|
|
6
|
+
ResolverVendorUnavailableError,
|
|
7
|
+
resolverVendorSupports,
|
|
8
|
+
} from "./types.js";
|
|
9
|
+
|
|
10
|
+
const TWOCAPTCHA_VENDOR_ID = "2captcha" as const;
|
|
11
|
+
const DEFAULT_TWOCAPTCHA_BASE_URL = "https://api.2captcha.com";
|
|
12
|
+
const DEFAULT_POLL_INTERVAL_MS = 3_000;
|
|
13
|
+
const DEFAULT_TIMEOUT_MS = 180_000;
|
|
14
|
+
|
|
15
|
+
type Delay = (ms: number, signal: AbortSignal) => Promise<void>;
|
|
16
|
+
type TwoCaptchaOperationPhase = "create_task" | "poll_result";
|
|
17
|
+
|
|
18
|
+
export interface TwoCaptchaResolverVendorOptions {
|
|
19
|
+
readonly apiKey?: string;
|
|
20
|
+
readonly timeoutMs?: number;
|
|
21
|
+
readonly pollIntervalMs?: number;
|
|
22
|
+
readonly allowedHosts: readonly string[];
|
|
23
|
+
readonly fetchImpl?: typeof fetch;
|
|
24
|
+
readonly baseUrl?: string;
|
|
25
|
+
/** Test-only clock override; supplying it disables the real-time deadline timer. */
|
|
26
|
+
readonly now?: () => number;
|
|
27
|
+
/** Test-only delay override used with `now` to exercise polling without sleeping. */
|
|
28
|
+
readonly delay?: Delay;
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
export interface TwoCaptchaResolverVendorAdapter extends ResolverVendorAdapter {
|
|
32
|
+
readonly id: "2captcha";
|
|
33
|
+
solve(
|
|
34
|
+
challenge: ProviderChallenge,
|
|
35
|
+
identity: ResolverIdentity | undefined,
|
|
36
|
+
signal: AbortSignal,
|
|
37
|
+
): Promise<Extract<ChallengeSolution, { readonly form: "token" }>>;
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
class TwoCaptchaSolveTimeoutError extends Error {
|
|
41
|
+
constructor() {
|
|
42
|
+
super("2captcha resolver solve budget elapsed");
|
|
43
|
+
this.name = "TwoCaptchaSolveTimeoutError";
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
type JsonRecord = Record<string, unknown>;
|
|
48
|
+
|
|
49
|
+
type ProxyConfiguration = {
|
|
50
|
+
readonly proxyType: "http" | "socks4" | "socks5";
|
|
51
|
+
readonly proxyAddress: string;
|
|
52
|
+
readonly proxyPort: number;
|
|
53
|
+
readonly proxyLogin?: string;
|
|
54
|
+
readonly proxyPassword?: string;
|
|
55
|
+
};
|
|
56
|
+
|
|
57
|
+
function isJsonRecord(value: unknown): value is JsonRecord {
|
|
58
|
+
return value !== null && typeof value === "object" && !Array.isArray(value);
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
function abortReason(signal: AbortSignal): unknown {
|
|
62
|
+
return signal.reason ?? new DOMException("The operation was aborted", "AbortError");
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
function raceWithAbort<T>(
|
|
66
|
+
operation: () => Promise<T>,
|
|
67
|
+
signal: AbortSignal,
|
|
68
|
+
phase?: TwoCaptchaOperationPhase,
|
|
69
|
+
): Promise<T> {
|
|
70
|
+
if (signal.aborted) return Promise.reject(abortReason(signal));
|
|
71
|
+
|
|
72
|
+
return new Promise<T>((resolve, reject) => {
|
|
73
|
+
const cleanup = () => signal.removeEventListener("abort", onAbort);
|
|
74
|
+
const onAbort = () => {
|
|
75
|
+
cleanup();
|
|
76
|
+
reject(abortReason(signal));
|
|
77
|
+
};
|
|
78
|
+
signal.addEventListener("abort", onAbort, { once: true });
|
|
79
|
+
operation().then(
|
|
80
|
+
(value) => {
|
|
81
|
+
cleanup();
|
|
82
|
+
resolve(value);
|
|
83
|
+
},
|
|
84
|
+
(error: unknown) => {
|
|
85
|
+
cleanup();
|
|
86
|
+
if (phase === undefined) {
|
|
87
|
+
reject(error);
|
|
88
|
+
return;
|
|
89
|
+
}
|
|
90
|
+
reject(
|
|
91
|
+
new ResolverVendorUnavailableError(TWOCAPTCHA_VENDOR_ID, "transport_failure", {
|
|
92
|
+
cause: error,
|
|
93
|
+
phase,
|
|
94
|
+
}),
|
|
95
|
+
);
|
|
96
|
+
},
|
|
97
|
+
);
|
|
98
|
+
});
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
async function abortableDelay(ms: number, signal: AbortSignal): Promise<void> {
|
|
102
|
+
let timer: ReturnType<typeof setTimeout> | undefined;
|
|
103
|
+
try {
|
|
104
|
+
await raceWithAbort(
|
|
105
|
+
() =>
|
|
106
|
+
new Promise<void>((resolve) => {
|
|
107
|
+
timer = setTimeout(resolve, ms);
|
|
108
|
+
}),
|
|
109
|
+
signal,
|
|
110
|
+
);
|
|
111
|
+
} finally {
|
|
112
|
+
if (timer !== undefined) clearTimeout(timer);
|
|
113
|
+
}
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
function parseProxyConfiguration(proxyUrl: string): ProxyConfiguration | undefined {
|
|
117
|
+
try {
|
|
118
|
+
const url = new URL(proxyUrl);
|
|
119
|
+
const protocol = url.protocol.slice(0, -1).toLowerCase();
|
|
120
|
+
const proxyType =
|
|
121
|
+
protocol === "socks4" || protocol === "socks5"
|
|
122
|
+
? protocol
|
|
123
|
+
: protocol === "http" || protocol === "https"
|
|
124
|
+
? "http"
|
|
125
|
+
: undefined;
|
|
126
|
+
const defaultPort = proxyType === "http" ? 80 : 1080;
|
|
127
|
+
const proxyPort = Number(url.port || defaultPort);
|
|
128
|
+
if (!proxyType || !url.hostname || !Number.isInteger(proxyPort) || proxyPort <= 0) {
|
|
129
|
+
return undefined;
|
|
130
|
+
}
|
|
131
|
+
const proxyLogin = url.username ? decodeURIComponent(url.username) : undefined;
|
|
132
|
+
const proxyPassword = url.password ? decodeURIComponent(url.password) : undefined;
|
|
133
|
+
return {
|
|
134
|
+
proxyType,
|
|
135
|
+
proxyAddress: url.hostname,
|
|
136
|
+
proxyPort,
|
|
137
|
+
...(proxyLogin ? { proxyLogin } : {}),
|
|
138
|
+
...(proxyPassword ? { proxyPassword } : {}),
|
|
139
|
+
};
|
|
140
|
+
} catch {
|
|
141
|
+
return undefined;
|
|
142
|
+
}
|
|
143
|
+
}
|
|
144
|
+
|
|
145
|
+
function errorText(payload: JsonRecord, key: "errorCode" | "errorDescription"): string {
|
|
146
|
+
const value = payload[key];
|
|
147
|
+
return typeof value === "string" ? value : "";
|
|
148
|
+
}
|
|
149
|
+
|
|
150
|
+
function isAllocationExhausted(payload: JsonRecord): boolean {
|
|
151
|
+
const code = errorText(payload, "errorCode").toLowerCase();
|
|
152
|
+
const description = errorText(payload, "errorDescription").toLowerCase();
|
|
153
|
+
return (
|
|
154
|
+
code === "error_zero_balance" ||
|
|
155
|
+
/(?:insufficient|zero|no|not enough)\s+(?:balance|funds|credit)/u.test(`${code} ${description}`)
|
|
156
|
+
);
|
|
157
|
+
}
|
|
158
|
+
|
|
159
|
+
function unavailableForPayload(
|
|
160
|
+
payload: JsonRecord,
|
|
161
|
+
phase: TwoCaptchaOperationPhase,
|
|
162
|
+
): ResolverVendorUnavailableError {
|
|
163
|
+
return new ResolverVendorUnavailableError(
|
|
164
|
+
TWOCAPTCHA_VENDOR_ID,
|
|
165
|
+
isAllocationExhausted(payload) ? "allocation_exhausted" : "transport_failure",
|
|
166
|
+
{ phase },
|
|
167
|
+
);
|
|
168
|
+
}
|
|
169
|
+
|
|
170
|
+
async function postJson(
|
|
171
|
+
fetchImpl: typeof fetch,
|
|
172
|
+
url: string,
|
|
173
|
+
body: JsonRecord,
|
|
174
|
+
signal: AbortSignal,
|
|
175
|
+
phase: TwoCaptchaOperationPhase,
|
|
176
|
+
): Promise<{ readonly ok: boolean; readonly payload: JsonRecord }> {
|
|
177
|
+
const response = await raceWithAbort(
|
|
178
|
+
() =>
|
|
179
|
+
fetchImpl(url, {
|
|
180
|
+
method: "POST",
|
|
181
|
+
headers: { "content-type": "application/json" },
|
|
182
|
+
body: JSON.stringify(body),
|
|
183
|
+
signal,
|
|
184
|
+
redirect: "error",
|
|
185
|
+
}),
|
|
186
|
+
signal,
|
|
187
|
+
phase,
|
|
188
|
+
);
|
|
189
|
+
|
|
190
|
+
let responseText: string;
|
|
191
|
+
try {
|
|
192
|
+
responseText = await raceWithAbort(() => response.text(), signal, phase);
|
|
193
|
+
} catch (error) {
|
|
194
|
+
if (error instanceof ResolverVendorUnavailableError) throw error;
|
|
195
|
+
throw new ResolverVendorUnavailableError(TWOCAPTCHA_VENDOR_ID, "transport_failure", {
|
|
196
|
+
cause: error,
|
|
197
|
+
phase,
|
|
198
|
+
});
|
|
199
|
+
}
|
|
200
|
+
|
|
201
|
+
let payload: unknown;
|
|
202
|
+
try {
|
|
203
|
+
payload = JSON.parse(responseText);
|
|
204
|
+
} catch {
|
|
205
|
+
// JSON parse errors may contain response-body excerpts, so do not retain them as causes.
|
|
206
|
+
throw new ResolverVendorUnavailableError(TWOCAPTCHA_VENDOR_ID, "transport_failure", {
|
|
207
|
+
phase,
|
|
208
|
+
});
|
|
209
|
+
}
|
|
210
|
+
if (!isJsonRecord(payload)) {
|
|
211
|
+
throw new ResolverVendorUnavailableError(TWOCAPTCHA_VENDOR_ID, "transport_failure", {
|
|
212
|
+
phase,
|
|
213
|
+
});
|
|
214
|
+
}
|
|
215
|
+
return { ok: response.ok, payload };
|
|
216
|
+
}
|
|
217
|
+
|
|
218
|
+
function taskIdFrom(payload: JsonRecord): string | number | undefined {
|
|
219
|
+
const taskId = payload.taskId;
|
|
220
|
+
return typeof taskId === "string" || typeof taskId === "number" ? taskId : undefined;
|
|
221
|
+
}
|
|
222
|
+
|
|
223
|
+
function tokenFrom(payload: JsonRecord): string | undefined {
|
|
224
|
+
const solution = payload.solution;
|
|
225
|
+
if (!isJsonRecord(solution)) return undefined;
|
|
226
|
+
if (typeof solution.gRecaptchaResponse === "string") return solution.gRecaptchaResponse;
|
|
227
|
+
return typeof solution.token === "string" ? solution.token : undefined;
|
|
228
|
+
}
|
|
229
|
+
|
|
230
|
+
function endpoint(baseUrl: string, path: string): string {
|
|
231
|
+
return `${baseUrl.replace(/\/+$/u, "")}/${path}`;
|
|
232
|
+
}
|
|
233
|
+
|
|
234
|
+
export function createTwoCaptchaResolverVendorAdapter(
|
|
235
|
+
options: TwoCaptchaResolverVendorOptions,
|
|
236
|
+
): TwoCaptchaResolverVendorAdapter {
|
|
237
|
+
const fetchImpl = options.fetchImpl ?? globalThis.fetch;
|
|
238
|
+
const baseUrl = options.baseUrl ?? DEFAULT_TWOCAPTCHA_BASE_URL;
|
|
239
|
+
const pollIntervalMs = options.pollIntervalMs ?? DEFAULT_POLL_INTERVAL_MS;
|
|
240
|
+
const timeoutMs = options.timeoutMs ?? DEFAULT_TIMEOUT_MS;
|
|
241
|
+
const now = options.now ?? Date.now;
|
|
242
|
+
const delay = options.delay ?? abortableDelay;
|
|
243
|
+
|
|
244
|
+
return {
|
|
245
|
+
id: TWOCAPTCHA_VENDOR_ID,
|
|
246
|
+
|
|
247
|
+
supports(kind) {
|
|
248
|
+
return resolverVendorSupports(TWOCAPTCHA_VENDOR_ID, kind);
|
|
249
|
+
},
|
|
250
|
+
|
|
251
|
+
async solve(challenge, identity, callerSignal) {
|
|
252
|
+
const apiKey = options.apiKey?.trim();
|
|
253
|
+
if (!apiKey) {
|
|
254
|
+
throw new ResolverVendorUnavailableError(TWOCAPTCHA_VENDOR_ID, "missing_credentials", {
|
|
255
|
+
phase: "create_task",
|
|
256
|
+
});
|
|
257
|
+
}
|
|
258
|
+
if (!resolverVendorSupports(TWOCAPTCHA_VENDOR_ID, challenge.kind)) {
|
|
259
|
+
throw new TypeError(`2captcha resolver does not support ${challenge.kind}`);
|
|
260
|
+
}
|
|
261
|
+
if (challenge.kind !== "recaptcha_v2") {
|
|
262
|
+
// AWS WAF remains deferred because its challenge variant has no required site key.
|
|
263
|
+
throw new ResolverVendorUnavailableError(TWOCAPTCHA_VENDOR_ID, "not_implemented", {
|
|
264
|
+
phase: "create_task",
|
|
265
|
+
});
|
|
266
|
+
}
|
|
267
|
+
|
|
268
|
+
assertResolverHostAllowed(challenge.pageUrl, options.allowedHosts);
|
|
269
|
+
callerSignal.throwIfAborted();
|
|
270
|
+
|
|
271
|
+
const proxy = identity ? parseProxyConfiguration(identity.proxyUrl) : undefined;
|
|
272
|
+
if (identity && !proxy) {
|
|
273
|
+
throw new ResolverVendorUnavailableError(TWOCAPTCHA_VENDOR_ID, "transport_failure", {
|
|
274
|
+
phase: "create_task",
|
|
275
|
+
});
|
|
276
|
+
}
|
|
277
|
+
|
|
278
|
+
const solveController = new AbortController();
|
|
279
|
+
const onCallerAbort = () => solveController.abort(abortReason(callerSignal));
|
|
280
|
+
callerSignal.addEventListener("abort", onCallerAbort, { once: true });
|
|
281
|
+
const timeout = options.now
|
|
282
|
+
? undefined
|
|
283
|
+
: setTimeout(() => solveController.abort(new TwoCaptchaSolveTimeoutError()), timeoutMs);
|
|
284
|
+
const startedAt = now();
|
|
285
|
+
let phase: TwoCaptchaOperationPhase = "create_task";
|
|
286
|
+
|
|
287
|
+
try {
|
|
288
|
+
const createResult = await postJson(
|
|
289
|
+
fetchImpl,
|
|
290
|
+
endpoint(baseUrl, "createTask"),
|
|
291
|
+
{
|
|
292
|
+
clientKey: apiKey,
|
|
293
|
+
task: {
|
|
294
|
+
type: proxy ? "RecaptchaV2Task" : "RecaptchaV2TaskProxyless",
|
|
295
|
+
websiteURL: challenge.pageUrl,
|
|
296
|
+
websiteKey: challenge.siteKey,
|
|
297
|
+
isInvisible: false,
|
|
298
|
+
...(identity ? { userAgent: identity.userAgent } : {}),
|
|
299
|
+
...(proxy ?? {}),
|
|
300
|
+
},
|
|
301
|
+
},
|
|
302
|
+
solveController.signal,
|
|
303
|
+
phase,
|
|
304
|
+
);
|
|
305
|
+
const taskId = taskIdFrom(createResult.payload);
|
|
306
|
+
if (!createResult.ok || createResult.payload.errorId !== 0 || taskId === undefined) {
|
|
307
|
+
throw unavailableForPayload(createResult.payload, phase);
|
|
308
|
+
}
|
|
309
|
+
|
|
310
|
+
phase = "poll_result";
|
|
311
|
+
while (true) {
|
|
312
|
+
callerSignal.throwIfAborted();
|
|
313
|
+
const remainingMs = timeoutMs - (now() - startedAt);
|
|
314
|
+
if (remainingMs <= 0) throw new TwoCaptchaSolveTimeoutError();
|
|
315
|
+
await delay(Math.min(pollIntervalMs, remainingMs), solveController.signal);
|
|
316
|
+
callerSignal.throwIfAborted();
|
|
317
|
+
if (now() - startedAt >= timeoutMs) throw new TwoCaptchaSolveTimeoutError();
|
|
318
|
+
|
|
319
|
+
const pollResult = await postJson(
|
|
320
|
+
fetchImpl,
|
|
321
|
+
endpoint(baseUrl, "getTaskResult"),
|
|
322
|
+
{ clientKey: apiKey, taskId },
|
|
323
|
+
solveController.signal,
|
|
324
|
+
phase,
|
|
325
|
+
);
|
|
326
|
+
if (!pollResult.ok || pollResult.payload.errorId !== 0) {
|
|
327
|
+
throw unavailableForPayload(pollResult.payload, phase);
|
|
328
|
+
}
|
|
329
|
+
if (pollResult.payload.status === "processing") continue;
|
|
330
|
+
if (pollResult.payload.status !== "ready") {
|
|
331
|
+
throw new ResolverVendorUnavailableError(TWOCAPTCHA_VENDOR_ID, "transport_failure", {
|
|
332
|
+
phase,
|
|
333
|
+
});
|
|
334
|
+
}
|
|
335
|
+
|
|
336
|
+
const token = tokenFrom(pollResult.payload);
|
|
337
|
+
if (!token?.trim()) {
|
|
338
|
+
throw new ResolverVendorUnavailableError(TWOCAPTCHA_VENDOR_ID, "transport_failure", {
|
|
339
|
+
phase,
|
|
340
|
+
});
|
|
341
|
+
}
|
|
342
|
+
return { form: "token", token };
|
|
343
|
+
}
|
|
344
|
+
} catch (error) {
|
|
345
|
+
if (callerSignal.aborted) throw abortReason(callerSignal);
|
|
346
|
+
if (
|
|
347
|
+
error instanceof TwoCaptchaSolveTimeoutError ||
|
|
348
|
+
solveController.signal.reason instanceof TwoCaptchaSolveTimeoutError
|
|
349
|
+
) {
|
|
350
|
+
throw new ResolverVendorUnavailableError(TWOCAPTCHA_VENDOR_ID, "timeout", {
|
|
351
|
+
cause: error,
|
|
352
|
+
phase,
|
|
353
|
+
});
|
|
354
|
+
}
|
|
355
|
+
if (error instanceof ResolverVendorUnavailableError) throw error;
|
|
356
|
+
throw new ResolverVendorUnavailableError(TWOCAPTCHA_VENDOR_ID, "transport_failure", {
|
|
357
|
+
cause: error,
|
|
358
|
+
phase,
|
|
359
|
+
});
|
|
360
|
+
} finally {
|
|
361
|
+
if (timeout !== undefined) clearTimeout(timeout);
|
|
362
|
+
callerSignal.removeEventListener("abort", onCallerAbort);
|
|
363
|
+
}
|
|
364
|
+
},
|
|
365
|
+
};
|
|
366
|
+
}
|
|
@@ -15,6 +15,8 @@ export const RESOLVER_VENDOR_CAPABILITIES = {
|
|
|
15
15
|
"hcaptcha",
|
|
16
16
|
"cloudflare_interstitial",
|
|
17
17
|
"aws_waf",
|
|
18
|
+
"akamai_sec_cpt",
|
|
19
|
+
"akamai_sensor",
|
|
18
20
|
],
|
|
19
21
|
capsolver: [
|
|
20
22
|
"turnstile",
|
|
@@ -32,6 +34,8 @@ export const RESOLVER_VENDOR_CAPABILITIES = {
|
|
|
32
34
|
"hcaptcha",
|
|
33
35
|
"cloudflare_interstitial",
|
|
34
36
|
"aws_waf",
|
|
37
|
+
"akamai_sec_cpt",
|
|
38
|
+
"akamai_sensor",
|
|
35
39
|
],
|
|
36
40
|
} as const satisfies Readonly<Record<ProviderResolverVendor, readonly ProviderChallengeKind[]>>;
|
|
37
41
|
|
|
@@ -53,8 +57,43 @@ export interface ResolverIssuingIdentity {
|
|
|
53
57
|
readonly userAgent: string;
|
|
54
58
|
}
|
|
55
59
|
|
|
60
|
+
export interface ResolverVendorTransport {
|
|
61
|
+
/**
|
|
62
|
+
* Bound to the resolved proxy lease and client profile.
|
|
63
|
+
* Implementations MUST NOT follow redirects and MUST return the initial redirect response.
|
|
64
|
+
*/
|
|
65
|
+
fetch(
|
|
66
|
+
url: string,
|
|
67
|
+
init: {
|
|
68
|
+
method: "GET" | "POST";
|
|
69
|
+
headers?: Readonly<Record<string, string>>;
|
|
70
|
+
body?: string;
|
|
71
|
+
signal: AbortSignal;
|
|
72
|
+
/** Implementations MUST honor manual redirect handling when the SDK guard sets it. */
|
|
73
|
+
redirect?: "manual";
|
|
74
|
+
},
|
|
75
|
+
): Promise<{
|
|
76
|
+
readonly status: number;
|
|
77
|
+
readonly headers: Readonly<Record<string, string>>;
|
|
78
|
+
readonly body: string;
|
|
79
|
+
/** Cookies observed on the response, including cache-relevant attributes. */
|
|
80
|
+
readonly cookies: readonly {
|
|
81
|
+
readonly name: string;
|
|
82
|
+
readonly value: string;
|
|
83
|
+
/** Epoch seconds. A session cookie must be undefined, never CDP's -1 sentinel. */
|
|
84
|
+
readonly expires?: number;
|
|
85
|
+
readonly httpOnly: boolean;
|
|
86
|
+
readonly secure: boolean;
|
|
87
|
+
readonly domain?: string;
|
|
88
|
+
readonly path?: string;
|
|
89
|
+
readonly sameSite?: string;
|
|
90
|
+
}[];
|
|
91
|
+
}>;
|
|
92
|
+
}
|
|
93
|
+
|
|
56
94
|
export interface ResolverVendorAdapter {
|
|
57
95
|
readonly id: ProviderResolverVendor;
|
|
96
|
+
readonly requiresTransport?: boolean | ((kind: ProviderChallengeKind) => boolean);
|
|
58
97
|
supports(kind: ProviderChallengeKind): boolean;
|
|
59
98
|
/** Identity the adapter actually used, reported after a successful solve. */
|
|
60
99
|
getIssuingIdentity?(
|
|
@@ -67,6 +106,7 @@ export interface ResolverVendorAdapter {
|
|
|
67
106
|
identity: ResolverIdentity | undefined,
|
|
68
107
|
signal: AbortSignal,
|
|
69
108
|
traceRecorder?: TraceRecorder,
|
|
109
|
+
transport?: ResolverVendorTransport,
|
|
70
110
|
): Promise<ChallengeSolution>;
|
|
71
111
|
}
|
|
72
112
|
|
|
@@ -81,10 +121,21 @@ export type ResolverVendorUnavailableReason =
|
|
|
81
121
|
export type ResolverChallengeVerdictReason = "human_puzzle";
|
|
82
122
|
|
|
83
123
|
type ResolverErrorOptions = {
|
|
124
|
+
/** Raw cause; adapters must not place bodies, cookies, headers, credentials, or proxy URLs here. */
|
|
84
125
|
readonly cause?: unknown;
|
|
126
|
+
/** Upstream hostname only; never a URL. */
|
|
127
|
+
readonly upstreamHost?: string;
|
|
128
|
+
/** Adapter-defined sensor-loop phase, such as fetch_script or post_sensor. */
|
|
129
|
+
readonly phase?: string;
|
|
130
|
+
/** One-based sensor-loop round when known. */
|
|
131
|
+
readonly round?: number;
|
|
85
132
|
};
|
|
86
133
|
|
|
87
134
|
export class ResolverVendorUnavailableError extends Error {
|
|
135
|
+
readonly upstreamHost?: string;
|
|
136
|
+
readonly phase?: string;
|
|
137
|
+
readonly round?: number;
|
|
138
|
+
|
|
88
139
|
constructor(
|
|
89
140
|
readonly vendor: ProviderResolverVendor,
|
|
90
141
|
readonly reason: ResolverVendorUnavailableReason,
|
|
@@ -95,6 +146,9 @@ export class ResolverVendorUnavailableError extends Error {
|
|
|
95
146
|
if (options.cause !== undefined) {
|
|
96
147
|
this.cause = options.cause;
|
|
97
148
|
}
|
|
149
|
+
this.upstreamHost = options.upstreamHost;
|
|
150
|
+
this.phase = options.phase;
|
|
151
|
+
this.round = options.round;
|
|
98
152
|
}
|
|
99
153
|
}
|
|
100
154
|
|