@2captcha/captcha-solver 1.3.0 → 1.3.1

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.
@@ -1,1620 +1,1874 @@
1
- "use strict";
2
- var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
- if (k2 === undefined) k2 = k;
4
- var desc = Object.getOwnPropertyDescriptor(m, k);
5
- if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
- desc = { enumerable: true, get: function() { return m[k]; } };
7
- }
8
- Object.defineProperty(o, k2, desc);
9
- }) : (function(o, m, k, k2) {
10
- if (k2 === undefined) k2 = k;
11
- o[k2] = m[k];
12
- }));
13
- var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
- Object.defineProperty(o, "default", { enumerable: true, value: v });
15
- }) : function(o, v) {
16
- o["default"] = v;
17
- });
18
- var __importStar = (this && this.__importStar) || function (mod) {
19
- if (mod && mod.__esModule) return mod;
20
- var result = {};
21
- if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
22
- __setModuleDefault(result, mod);
23
- return result;
24
- };
25
- var __importDefault = (this && this.__importDefault) || function (mod) {
26
- return (mod && mod.__esModule) ? mod : { "default": mod };
27
- };
28
- Object.defineProperty(exports, "__esModule", { value: true });
29
- exports.Solver = void 0;
30
- const fetch_1 = __importDefault(require("../utils/fetch"));
31
- const _2captchaError_1 = require("./2captchaError");
32
- const utils = __importStar(require("../utils/generic"));
33
- const providers_1 = __importDefault(require("./providers/providers"));
34
- const constants_1 = require("./constants/constants");
35
- const checkCaptchaParams_1 = __importDefault(require("../utils/checkCaptchaParams"));
36
- const renameParams_1 = __importDefault(require("../utils/renameParams"));
37
- const provider = (0, providers_1.default)();
38
- /**
39
- * The main 2captcha class, housing all API calls and api interactions.
40
- *
41
- */
42
- class Solver {
43
- /**
44
- * The constructor for the 2captcha Solver class.
45
- *
46
- * @param {string} apikey The API key to use
47
- * @param {number} pollingFrequency The frequency to poll for requests
48
- *
49
- */
50
- constructor(apikey, pollingFrequency = 5000, enableACAO = true) {
51
- this._apikey = apikey;
52
- this._pollingFrequency = pollingFrequency;
53
- this._headerACAO = enableACAO ? 1 : 0;
54
- }
55
- /** The API key this instance is using */
56
- get apikey() { return this._apikey; }
57
- /** Frequency the instance polls for updates */
58
- get pollingFrequency() { return this._pollingFrequency; }
59
- /** Set the API key for this instance */
60
- set apikey(update) { this._apikey = update; }
61
- get in() { return provider.in; }
62
- get res() { return provider.res; }
63
- get defaultPayload() { return { key: this.apikey, json: 1, header_acao: this._headerACAO, soft_id: constants_1.softId }; }
64
- /**
65
- * Returns the remaining account balance.
66
- *
67
- * @return {Promise<Number>} Remaining balance
68
- * @throws APIError
69
- * @example
70
- * solver.balance()
71
- * .then((res) => {
72
- * console.log(res)
73
- * })
74
- */
75
- async balance() {
76
- const res = await (0, fetch_1.default)(this.res + utils.objectToURI({
77
- ...this.defaultPayload,
78
- action: "getbalance"
79
- }));
80
- const result = await res.text();
81
- try {
82
- const data = JSON.parse(result);
83
- if (data.status == 1) {
84
- return parseFloat(data.request);
85
- }
86
- throw new _2captchaError_1.APIError(data.request);
87
- }
88
- catch {
89
- throw new _2captchaError_1.APIError(result);
90
- }
91
- }
92
- /**
93
- * @private
94
- *
95
- * Polls for a captcha, finding out if it's been completed
96
- * @param {string} id Captcha ID
97
- *
98
- * @returns {Promise<CaptchaAnswer>}
99
- * @throws APIError
100
- */
101
- async pollResponse(id) {
102
- const payload = {
103
- ...this.defaultPayload,
104
- action: "get",
105
- id: id
106
- };
107
- await utils.sleep(this.pollingFrequency);
108
- const res = await (0, fetch_1.default)(this.res + utils.objectToURI(payload));
109
- const result = await res.text();
110
- let data;
111
- try {
112
- data = JSON.parse(result);
113
- if (data.status == 1) {
114
- let dataJSON = { ...data, data: data.request, id: id };
115
- delete dataJSON.request;
116
- return dataJSON;
117
- }
118
- }
119
- catch {
120
- throw new _2captchaError_1.APIError(result);
121
- }
122
- switch (data.request) {
123
- case "CAPCHA_NOT_READY":
124
- return this.pollResponse(id);
125
- default: {
126
- throw new _2captchaError_1.APIError(data.request);
127
- }
128
- }
129
- }
130
- /**
131
- * ### Solves a google reCAPTCHA V2 | V3.
132
- *
133
- * [Read more about other reCAPTCHA parameters](https://2captcha.com/2captcha-api#solving_recaptchav2_new).
134
- *
135
- * @param {{pageurl, googlekey, cookies, proxy, proxytype, userAgent, invisible, datas, pingback, action, enterprise, min_score, version, domain}} params Object
136
- * @param {string} params.pageurl The URL the captcha appears on.
137
- * @param {string} params.googlekey Value of `k` or `data-sitekey` parameter you found on page.
138
- * @param {string} params.cookies Your cookies that will be passed to our worker who solve the captha.
139
- * @param {string} params.proxy Format: `login:password@123.123.123.123:3128`. You can find more info about proxies [here](https://2captcha.com/2captcha-api#proxies).
140
- * @param {string} params.proxytype Type of your proxy: `HTTP`, `HTTPS`, `SOCKS4`, `SOCKS5`.
141
- * @param {string} params.userAgent Your `userAgent` that will be passed to our worker and used to solve the captcha.
142
- * @param {number} params.invisible `1` - means that reCAPTCHA is invisible. `0` - normal reCAPTCHA.
143
- * @param {string} params.datas Value of `data-s` parameter you found on page. Curenttly applicable for Google Search and other Google services.
144
- * @param {string} params.pingback URL for pingback (callback) response that will be sent when captcha is solved. URL should be registered on the server. [More info here](https://2captcha.com/2captcha-api#pingback).
145
- * @param {string} params.action Value of `action` parameter you found on page.
146
- * @param {number} params.enterprise `1` - defines that you're sending reCAPTCHA Enterpise.
147
- * @param {number} params.min_score The score needed for resolution reCAPTCHA V3. Currently it's almost impossible to get token with score higher than `0.3`
148
- * @param {string} params.version `v2` — defines that you're sending a reCAPTCHA V2. `v3` — defines that you're sending a reCAPTCHA V3.
149
- * @param {string} params.domain Domain used to load the captcha: `google.com` or `recaptcha.net`
150
- *
151
- * @returns {Promise<CaptchaAnswer>} The result from the solve.
152
- * @throws APIError
153
- * @example
154
- * solver.recaptcha({
155
- * pageurl: 'https://2captcha.com/demo/recaptcha-v2',
156
- * googlekey: '6LfD3PIbAAAAAJs_eEHvoOl75_83eXSqpPSRFJ_u'
157
- * })
158
- * .then((res) => {
159
- * console.log(res);
160
- * })
161
- * .catch((err) => {
162
- * console.log(err);
163
- * })
164
- */
165
- async recaptcha(params) {
166
- (0, checkCaptchaParams_1.default)(params, "userrecaptcha");
167
- const payload = {
168
- ...params,
169
- method: "userrecaptcha",
170
- ...this.defaultPayload
171
- };
172
- const response = await (0, fetch_1.default)(this.in + utils.objectToURI(payload));
173
- const result = await response.text();
174
- let data;
175
- try {
176
- data = JSON.parse(result);
177
- }
178
- catch {
179
- throw new _2captchaError_1.APIError(result);
180
- }
181
- if (data.status == 1) {
182
- return this.pollResponse(data.request);
183
- }
184
- else {
185
- throw new _2captchaError_1.APIError(data.request);
186
- }
187
- }
188
- /**
189
- * ### Solves a hCaptcha
190
- *
191
- * [Read more about other hCaptcha parameters](https://2captcha.com/2captcha-api#solving_hcaptcha).
192
- *
193
- * @param {{sitekey, pageurl, data, userAgent, invisible, pingback, proxy, proxytype, domain}} params Object
194
- * @param {string} params.sitekey The hcaptcha site key. Value of `k` or `data-sitekey` parameter you found on page.
195
- * @param {string} params.pageurl The URL the captcha appears on.
196
- * @param {string} params.data Custom `data` that is used in some implementations of hCaptcha, mostly with `invisible=1`. In most cases you see it as `rqdata` inside network requests. IMPORTANT: you MUST provide `userAgent` if you submit captcha with `data` paramater. The value should match the User-Agent you use when interacting with the target website.
197
- * @param {string} params.userAgent Your userAgent that will be passed to our worker and used to solve the captcha. Required for hCaptcha with `data` parameter.
198
- * @param {number} params.invisible Use `1` for invisible version of hcaptcha. Currently it is a very rare case.
199
- * @param {string} params.pingback URL for pingback (callback) response that will be sent when captcha is solved. URL should be registered on the server. More info [here](https://2captcha.com/2captcha-api#pingback).
200
- * @param {string} params.proxy Format: `login:password@123.123.123.123:3128` You can find more info about proxies [here](https://2captcha.com/2captcha-api#proxies).
201
- * @param {string} params.proxytype Type of your proxy: `HTTP`, `HTTPS`, `SOCKS4`, `SOCKS5`.
202
- * @param {string} params.domain Domain used to load the captcha: `hcaptcha.com` or `js.hcaptcha.com`
203
- *
204
- * @returns {Promise<CaptchaAnswer>} The result from the solve
205
- * @throws APIError
206
- * @example
207
- * solver.hcaptcha({
208
- * pageurl: "https://2captcha.com/demo/hcaptcha",
209
- * sitekey: "b76cd927-d266-4cfb-a328-3b03ae07ded6"
210
- * .then((res) => {
211
- * console.log(res);
212
- * })
213
- * .catch((err) => {
214
- * console.log(err);
215
- * })
216
- */
217
- async hcaptcha(params) {
218
- (0, checkCaptchaParams_1.default)(params, "hcaptcha");
219
- const payload = {
220
- ...params,
221
- method: "hcaptcha",
222
- ...this.defaultPayload
223
- };
224
- const response = await (0, fetch_1.default)(this.in + utils.objectToURI(payload));
225
- const result = await response.text();
226
- let data;
227
- try {
228
- data = JSON.parse(result);
229
- }
230
- catch {
231
- throw new _2captchaError_1.APIError(result);
232
- }
233
- if (data.status == 1) {
234
- return this.pollResponse(data.request);
235
- }
236
- else {
237
- throw new _2captchaError_1.APIError(data.request);
238
- }
239
- }
240
- /**
241
- * ### Solves a GeeTest Captcha.
242
- *
243
- * [Read more about parameters and solving for Geetest captcha](https://2captcha.com/2captcha-api#solving_geetest).
244
- *
245
- * @param {{ gt, challenge, api_server, offline, new_captcha,
246
- * pageurl, pingback, proxy, proxytype, userAgent }} params
247
- * @param {string} params.gt Value of gt parameter found on site
248
- * @param {string} params.challenge Value of challenge parameter found on site
249
- * @param {string} params.pageurl The URL the captcha appears on
250
- * @param {string} params.api_server The URL of the api_server (recommended)
251
- * @param {number} params.offline In rare cases `initGeetest` can be called with `offline` parameter on the target page. If the call uses offline: true, set the value to `1`.
252
- * @param {number} params.new_captcha In rare cases `initGeetest` can be called with `new_captcha` parameter. If the call uses `new_captcha: true`, set the value to `1`. Mostly used with offline parameter.
253
- * @param {string} params.pingback URL for `pingback` (callback) response that will be sent when captcha is solved. [More info here](https://2captcha.com/2captcha-api#pingback).
254
- * @param {string} params.proxy Format: `login:password@123.123.123.123:3128`. You can find more info about proxies [here](https://2captcha.com/2captcha-api#proxies).
255
- * @param {string} params.proxytype Type of your proxy: `HTTP`, `HTTPS`, `SOCKS4`, `SOCKS5`.
256
- * @param {string} params.userAgent Your `userAgent` that will be passed to our worker and used to solve the captcha.
257
- *
258
- * @returns {Promise<CaptchaAnswer>} The result from the solve.
259
- * @throws APIError
260
- * @example
261
- * ;(async () => {
262
- *
263
- * // Warning: Attention, the `challenge` value is not static but dynamic.
264
- * // You need to find the queries that makes the captcha on the page to API.
265
- * // Then you need to make request to this API and get new `challenge`.
266
- *
267
- * // For page https://rucaptcha.com/demo/geetest, api address is https://rucaptcha.com/api/v1/captcha-demo/gee-test/init-params?t=${t}
268
- * // Also note that when make request to API, the request uses the dynamic parameter `t`
269
- *
270
- * // You can read more about sending GeeTest here https://2captcha.com/2captcha-api#solving_geetest, or here https://2captcha.com/p/geetest
271
- * // In this example I solve GeeTest from page https://2captcha.com/demo/geetest
272
- *
273
- * const t = new Date().getTime()
274
- * // below i make a request to get a new `challenge`.
275
- * const response = await fetch(`https://2captcha.com/api/v1/captcha-demo/gee-test/init-params?t=${t}`)
276
- * const data = await response.json()
277
- *
278
- * const params = {
279
- * pageurl: 'https://rucaptcha.com/demo/geetest',
280
- * gt: data.gt,
281
- * challenge: data.challenge
282
- * }
283
- *
284
- * const res = await solver.geetest(params)
285
- * try {
286
- * console.log(res)
287
- * } catch (error) {
288
- * console.error(error);
289
- * }
290
- * })()
291
- */
292
- async geetest(params) {
293
- (0, checkCaptchaParams_1.default)(params, "geetest");
294
- const payload = {
295
- ...params,
296
- method: "geetest",
297
- ...this.defaultPayload
298
- };
299
- const response = await (0, fetch_1.default)(this.in + utils.objectToURI(payload));
300
- const result = await response.text();
301
- let data;
302
- try {
303
- data = JSON.parse(result);
304
- }
305
- catch {
306
- throw new _2captchaError_1.APIError(result);
307
- }
308
- if (data.status == 1) {
309
- return this.pollResponse(data.request);
310
- }
311
- else {
312
- throw new _2captchaError_1.APIError(data.request);
313
- }
314
- }
315
- /**
316
- * ### Solves a GeeTest V4 Captcha.
317
- *
318
- * This method accepts an object with the following fields: `pageurl`, `captcha_id`, `pingback`, `proxy`, `proxytype`, `userAgent`.
319
- * The `pageurl` and `captcha_id` fields are required.
320
- *
321
- * @param {{pageurl, captcha_id, pingback, proxy, proxytype, userAgent}} params The method geetestV4 takes arguments as an object.
322
- * @param {string} params.pageurl Full URL of the page where you see Geetest V4 captcha.
323
- * @param {string} params.captcha_id Required parameter. Value of `captcha_id` parameter you found on target website.
324
- * @param {string} params.pingback An optional param. [More info here](https://2captcha.com/2captcha-api#pingback).
325
- * @param {string} params.proxy An optional param. Format: `login:password@123.123.123.123:3128`. You can find more info about proxies [here](https://2captcha.com/2captcha-api#proxies).
326
- * @param {string} params.proxytype An optional param. Type of your proxy: `HTTP`, `HTTPS`, `SOCKS4`, `SOCKS5`.
327
- * @param {string} params.userAgent An optional param. Your `userAgent` that will be passed to our worker and used to solve the captcha.
328
- *
329
- * @returns {Promise<CaptchaAnswer>} The result from the solve.
330
- * @throws APIError
331
- * @example
332
- * solver.geetestV4({
333
- * pageurl: 'https://2captcha.com/demo/geetest-v4',
334
- * captcha_id: 'e392e1d7fd421dc63325744d5a2b9c73'
335
- * })
336
- * .then((res) => {
337
- * console.log(res)
338
- * })
339
- * .catch((err) => {
340
- * console.log(err);
341
- * })
342
- */
343
- async geetestV4(params) {
344
- (0, checkCaptchaParams_1.default)(params, "geetest_v4");
345
- const payload = {
346
- ...params,
347
- method: "geetest_v4",
348
- ...this.defaultPayload
349
- };
350
- const response = await (0, fetch_1.default)(this.in + utils.objectToURI(payload));
351
- const result = await response.text();
352
- let data;
353
- try {
354
- data = JSON.parse(result);
355
- }
356
- catch {
357
- throw new _2captchaError_1.APIError(result);
358
- }
359
- if (data.status == 1) {
360
- return this.pollResponse(data.request);
361
- }
362
- else {
363
- throw new _2captchaError_1.APIError(data.request);
364
- }
365
- }
366
- /**
367
- * ### Method for sending Yandex Smart Captcha.
368
- *
369
- * This method accepts an object with the following fields: `pageurl`, `sitekey`, `pingback`, `proxy`, `proxytype`.
370
- * The `pageurl` and `sitekey` fields are required.
371
- *
372
- * @param {{pageurl, sitekey, pingback, proxy, proxytype, userAgent}} params The method takes arguments as an object.
373
- * @param {string} params.pageurl Required parameter. URL of the page where the captcha is located.
374
- * @param {string} params.sitekey Required parameter. The `sitekey` value you found on the captcha page.
375
- * @param {string} params.pingback An optional param.
376
- * @param {string} params.proxy An optional param. Format: `login:password@123.123.123.123:3128`.
377
- * @param {string} params.proxytype An optional param. Type of your proxy: `HTTP`, `HTTPS`, `SOCKS4`, `SOCKS5`.
378
- * @param {string} params.userAgent An optional param. Your `userAgent` that will be passed to our worker and used to solve the captcha.
379
- *
380
- * @returns {Promise<CaptchaAnswer>} The result from the solve.
381
- * @throws APIError
382
- * @example
383
- * solver.yandexSmart({
384
- * pageurl: "https://captcha-api.yandex.ru/demo",
385
- * sitekey: "FEXfAbHQsToo97VidNVk3j4dC74nGW1DgdxjtNB9"
386
- * })
387
- * .then((res) => {
388
- * console.log(res)
389
- * })
390
- * .catch((err) => {
391
- * console.log(err);
392
- * })
393
- */
394
- async yandexSmart(params) {
395
- (0, checkCaptchaParams_1.default)(params, "yandex");
396
- const payload = {
397
- ...params,
398
- method: "yandex",
399
- ...this.defaultPayload
400
- };
401
- const response = await (0, fetch_1.default)(this.in + utils.objectToURI(payload));
402
- const result = await response.text();
403
- let data;
404
- try {
405
- data = JSON.parse(result);
406
- }
407
- catch {
408
- throw new _2captchaError_1.APIError(result);
409
- }
410
- if (data.status == 1) {
411
- return this.pollResponse(data.request);
412
- }
413
- else {
414
- throw new _2captchaError_1.APIError(data.request);
415
- }
416
- }
417
- /**
418
- * ### Solves a image-based captcha.
419
- *
420
- * [Read more about parameters for image captcha](https://2captcha.com/2captcha-api#solving_normal_captcha).
421
- *
422
- * @param {{ body,
423
- * phrase,
424
- * regsense,
425
- * numeric,
426
- * calc,
427
- * min_len,
428
- * max_len,
429
- * language,
430
- * lang,
431
- * textinstructions,
432
- * pingback }} params Extra properties to pass to 2captcha.
433
- * @param {string} params.body Base64 image data for the captcha.
434
- * @param {number} params.phrase Captcha contains two or more words? `1` - Yes. `0` - No.
435
- * @param {number} params.regsense Captcha is case sensitive? `1` - Yes. `0` - No.
436
- * @param {number} params.numeric `0` - not specified. `1` - captcha contains only numbers. `2` - captcha contains only letters. `3` - captcha contains only numbers OR only letters. `4` - captcha MUST contain both numbers AND letters.
437
- * @param {number} params.calc Does captcha require calculations? (e.g. type the result 4 + 8 = ) `1` - Yes. `0` - No.
438
- * @param {number} params.min_len `1..20` - minimal number of symbols in captcha. `0` - not specified.
439
- * @param {number} params.max_len `1..20` - maximal number of symbols in captcha. `0` - not specified.
440
- * @param {number} params.language `0` - not specified. `1` - Cyrillic captcha. `2` - Latin captcha
441
- * @param {string} params.lang Language code. [See the list of supported languages](https://2captcha.com/2captcha-api#language).
442
- * @param {string} params.textinstructions Text will be shown to worker to help him to solve the captcha correctly. For example: type red symbols only.
443
- * @param {string} params.pingback URL for `pingback` (callback) response that will be sent when captcha is solved. [More info here](https://2captcha.com/2captcha-api#pingback).
444
- *
445
- * @returns {Promise<CaptchaAnswer>} The result from the solve
446
- * @throws APIError
447
- * @example
448
- * const imageBase64 = fs.readFileSync("./tests/media/imageCaptcha_6e584.png", "base64")
449
- *
450
- * solver.imageCaptcha({
451
- * body: imageBase64,
452
- * numeric: 4,
453
- * min_len: 5,
454
- * max_len: 5
455
- * })
456
- * .then((res) => {
457
- * console.log(res);
458
- * })
459
- * .catch((err) => {
460
- * console.log(err);
461
- * })
462
- */
463
- async imageCaptcha(params) {
464
- (0, checkCaptchaParams_1.default)(params, "base64");
465
- const payload = {
466
- ...params,
467
- ...this.defaultPayload,
468
- method: "base64"
469
- };
470
- const URL = this.in;
471
- const response = await (0, fetch_1.default)(URL, {
472
- body: JSON.stringify(payload),
473
- method: "post",
474
- headers: { 'Content-Type': 'application/json' }
475
- });
476
- const result = await response.text();
477
- let data;
478
- try {
479
- data = JSON.parse(result);
480
- }
481
- catch {
482
- throw new _2captchaError_1.APIError(result);
483
- }
484
- if (data.status == 1) {
485
- return this.pollResponse(data.request);
486
- }
487
- else {
488
- throw new _2captchaError_1.APIError(data.request);
489
- }
490
- }
491
- /**
492
- * ### Solves Arkose Labs FunCaptcha.
493
- *
494
- * [Read more](https://2captcha.com/2captcha-api#solving_funcaptcha_new) about other solving and other parameters for Arkose Labs FunCaptcha.
495
- *
496
- * @param {{pageurl, publicKey, surl, data, pingback, proxy, proxytype, userAgent}} params Object
497
- * @param {string} params.publicKey The FunCaptcha Public Key
498
- * @param {string} params.pageurl The URL to the website the captcha is seen on
499
- * @param {string} params.surl The FunCaptcha Service URL (recommended)
500
- * @param {string} params.data Custom data to pass to FunCaptcha. For example: `'data': '{"blob": "foo"}'`.
501
- * @param {string} params.pingback URL for pingback (callback) response that will be sent when captcha is solved. URL should be registered on the server. [More info here](https://2captcha.com/2captcha-api#pingback).
502
- * @param {string} params.proxy Format: `login:password@123.123.123.123:3128` You can find more info about proxies [here](https://2captcha.com/2captcha-api#proxies).
503
- * @param {string} params.proxytype Type of your proxy: `HTTP`, `HTTPS`, `SOCKS4`, `SOCKS5`.
504
- * @param {string} params.userAgent Your `userAgent` that will be passed to our worker and used to solve the captcha.
505
- *
506
- * @returns {Promise<CaptchaAnswer>} The result from the solve
507
- * @throws APIError
508
- *
509
- * @example
510
- * solver.funCaptcha({
511
- * pageurl: "https://funcaptcha.com/tile-game-lite-mode/fc/api/nojs/?pkey=804380F4-6844-FFA1-ED4E-5877CA1F1EA4&lang=en",
512
- * publickey: "804380F4-6844-FFA1-ED4E-5877CA1F1EA4"
513
- * })
514
- * .then((res) => {
515
- * console.log(res);
516
- * })
517
- * .catch((err) => {
518
- * console.log(err);
519
- * })
520
- */
521
- async funCaptcha(params) {
522
- (0, checkCaptchaParams_1.default)(params, "funcaptcha");
523
- const payload = {
524
- ...params,
525
- method: "funcaptcha",
526
- ...this.defaultPayload,
527
- };
528
- const response = await (0, fetch_1.default)(this.in + utils.objectToURI(payload));
529
- const result = await response.text();
530
- let data;
531
- try {
532
- data = JSON.parse(result);
533
- }
534
- catch {
535
- throw new _2captchaError_1.APIError(result);
536
- }
537
- if (data.status == 1) {
538
- return this.pollResponse(data.request);
539
- }
540
- else {
541
- throw new _2captchaError_1.APIError(data.request);
542
- }
543
- }
544
- /**
545
- *
546
- * ### Solves a Lemin captcha
547
- *
548
- * [Read more about other Lemin captcha parameters](https://2captcha.com/2captcha-api#lemin).
549
- *
550
- * @param {{ pageurl, captcha_id, div_id, api_server, pingback, proxy, proxytype}} params Object
551
- * @param {string} params.pageurl The URL the captcha appears on.
552
- * @param {string} params.captcha_id Value of `captcha_id` parameter you found on page.
553
- * @param {string} params.div_id Value `id` of captcha pareent `<div></div>` element.
554
- * @param {string} params.api_server The domain part of script URL you found on page. Default value: `https://api.leminnow.com/`
555
- * @param {string} params.pingback URL for pingback (callback) response that will be sent when captcha is solved. URL should be registered on the server. [More info here](https://2captcha.com/2captcha-api#pingback).
556
- * @param {string} params.proxy Format: `login:password@123.123.123.123:3128` You can find more info about proxies [here](https://2captcha.com/2captcha-api#proxies).
557
- * @param {string} params.proxytype Type of your proxy: `HTTP`, `HTTPS`, `SOCKS4`, `SOCKS5`.
558
- *
559
- * @example
560
- * solver.lemin({
561
- * pageurl:'https://2captcha.com/demo/lemin',
562
- * captcha_id: 'CROPPED_3dfdd5c_d1872b526b794d83ba3b365eb15a200b',
563
- * div_id: 'lemin-cropped-captcha',
564
- * api_server: 'api.leminnow.com'
565
- * })
566
- * .then((res) => {
567
- * console.log(res);
568
- * })
569
- * .catch((err) => {
570
- * console.log(err);
571
- * })
572
- */
573
- async lemin(params) {
574
- (0, checkCaptchaParams_1.default)(params, "lemin");
575
- const payload = {
576
- ...params,
577
- method: "lemin",
578
- ...this.defaultPayload,
579
- };
580
- const response = await (0, fetch_1.default)(this.in + utils.objectToURI(payload));
581
- const result = await response.text();
582
- let data;
583
- try {
584
- data = JSON.parse(result);
585
- }
586
- catch {
587
- throw new _2captchaError_1.APIError(result);
588
- }
589
- if (data.status == 1) {
590
- return this.pollResponse(data.request);
591
- }
592
- else {
593
- throw new _2captchaError_1.APIError(data.request);
594
- }
595
- }
596
- /**
597
- *
598
- * ### Solves Amazon WAF captcha
599
- *
600
- * [Read more about "Amazon WAF" captcha](https://2captcha.com/2captcha-api#amazon-waf).
601
- *
602
- * @param {{ pageurl, sitekey, iv, context, challenge_script, captcha_script, pingback, proxy, proxytype}} params The `amazonWaf` method takes arguments as an object. Thus, the `pageurl`, `sitekey`, `iv`, `context` fields in the passed object are mandatory.
603
- * @param {string} params.pageurl Is the full `URL` of page where you were challenged by the captcha.
604
- * @param {string} params.sitekey Is a value of `key` parameter in the page source.
605
- * @param {string} params.iv Is a value of `iv` parameter in the page source.
606
- * @param {string} params.context Is a value of `context` parameter in the page source.
607
- * @param {string} params.challenge_script The source URL of `challenge.js` script on the page.
608
- * @param {string} params.captcha_script The source URL of `captcha.js` script on the page.
609
- * @param {string} params.pingback URL for pingback (callback) response that will be sent when captcha is solved. URL should be registered on the server. [More info here](https://2captcha.com/2captcha-api#pingback).
610
- * @param {string} params.proxy Format: `login:password@123.123.123.123:3128` You can find more info about proxies [here](https://2captcha.com/2captcha-api#proxies).
611
- * @param {string} params.proxytype Type of your proxy: `HTTP`, `HTTPS`, `SOCKS4`, `SOCKS5`.
612
- *
613
- * @example
614
- * solver.amazonWaf({
615
- * pageurl: "https://non-existent-example.execute-api.us-east-1.amazonaws.com/latest",
616
- * sitekey: "AQIDAHjcYu/GjX+QlghicBgQ/7bFaQZ+m5FKCMDnO+vTbNg96AHMDLodoefdvyOnsHMRtEKQAAAAfjB8BgkqhkiG9w0BBwagbzBtAgEAMGgGCSqGSIb3DQEHATAeBglghkgBZQMEAS4wEQQMUX+ZqwwuANRnZujSAgEQgDvHSxUQmVBuyUtumoW2n4ccTG7xQN1r3X/zz41qmQaYv9SSSvQrjIoDXKaUQ23tVb4ii8+uljuRdz/HPA==",
617
- * context: "9BUgmlm48F92WUoqv97a49ZuEJJ50TCk9MVr3C7WMtQ0X6flVbufM4n8mjFLmbLVAPgaQ1Jydeaja94iAS49ljb+sUNLoukWedAQZKrlY4RdbOOzvcFqmD/ZepQFS9N5w15Exr4VwnVq+HIxTsDJwRviElWCdzKDebN/mk8/eX2n7qJi5G3Riq0tdQw9+C4diFZU5E97RSeahejOAAJTDqduqW6uLw9NsjJBkDRBlRjxjn5CaMMo5pYOxYbGrM8Un1JH5DMOLeXbq1xWbC17YSEoM1cRFfTgOoc+VpCe36Ai9Kc=",
618
- * iv: "CgAHbCe2GgAAAAAj",
619
- * })
620
- * .then((res) => {
621
- * console.log(res);
622
- * })
623
- * .catch((err) => {
624
- * console.log(err);
625
- * })
626
- */
627
- async amazonWaf(params) {
628
- (0, checkCaptchaParams_1.default)(params, "amazon_waf");
629
- const payload = {
630
- ...params,
631
- method: "amazon_waf",
632
- ...this.defaultPayload,
633
- };
634
- const response = await (0, fetch_1.default)(this.in + utils.objectToURI(payload));
635
- const result = await response.text();
636
- let data;
637
- try {
638
- data = JSON.parse(result);
639
- }
640
- catch {
641
- throw new _2captchaError_1.APIError(result);
642
- }
643
- if (data.status == 1) {
644
- return this.pollResponse(data.request);
645
- }
646
- else {
647
- throw new _2captchaError_1.APIError(data.request);
648
- }
649
- }
650
- /**
651
- *
652
- * ### Solves Cloudflare Turnstile captcha
653
- *
654
- * [Read more about Cloudflare Turnstile captcha](https://2captcha.com/2captcha-api#turnstile).
655
- *
656
- * @param {{ pageurl, sitekey, action, data, pingback, proxy, proxytype}} params The `cloudflareTurnstile` method takes arguments as an object. Thus, the `pageurl`, `sitekey` fields in the passed object are mandatory.
657
- * @param {string} params.pageurl Full `URL` of the page where you see the captcha.
658
- * @param {string} params.sitekey Is a value of `sitekey` parameter in the page source.
659
- * @param {string} params.action Value of optional `action` parameter you found on page.
660
- * @param {string} params.data Value of optional `data` parameter you found on page.
661
- * @param {string} params.pingback URL for pingback (callback) response that will be sent when captcha is solved. URL should be registered on the server. [More info here](https://2captcha.com/2captcha-api#pingback).
662
- * @param {string} params.proxy Format: `login:password@123.123.123.123:3128` You can find more info about proxies [here](https://2captcha.com/2captcha-api#proxies).
663
- * @param {string} params.proxytype Type of your proxy: `HTTP`, `HTTPS`, `SOCKS4`, `SOCKS5`.
664
- *
665
- * @example
666
- * solver.cloudflareTurnstile({
667
- * pageurl: "https://app.nodecraft.com/login",
668
- * sitekey: "0x4AAAAAAAAkg0s3VIOD10y4"
669
- * })
670
- * .then((res) => {
671
- * console.log(res);
672
- * })
673
- * .catch((err) => {
674
- * console.log(err);
675
- * })
676
- */
677
- async cloudflareTurnstile(params) {
678
- (0, checkCaptchaParams_1.default)(params, "turnstile");
679
- const payload = {
680
- ...params,
681
- method: "turnstile",
682
- ...this.defaultPayload,
683
- };
684
- const response = await (0, fetch_1.default)(this.in + utils.objectToURI(payload));
685
- const result = await response.text();
686
- let data;
687
- try {
688
- data = JSON.parse(result);
689
- }
690
- catch {
691
- throw new _2captchaError_1.APIError(result);
692
- }
693
- if (data.status == 1) {
694
- return this.pollResponse(data.request);
695
- }
696
- else {
697
- throw new _2captchaError_1.APIError(data.request);
698
- }
699
- }
700
- /**
701
- * ### Solves a Coordinates captcha.
702
- *
703
- * @param {{ body, imginstructions, textinstructions, language, lang, pingback }} params parameters Coordinates Captcha as an object.
704
- * @param {string} params.body Base64-encoded captcha image.
705
- * @param {string} params.imginstructions Base64-encoded image with instruction for solving captcha.
706
- * @param {string} params.textinstructions Text will be shown to worker to help him to solve the captcha correctly. For example: click on all objects in red color.
707
- * @param {number} params.language `0` - not specified. `1` - Cyrillic captcha. `2` - Latin captcha
708
- * @param {string} params.lang Language code. [See the list of supported languages](https://2captcha.com/2captcha-api#language).
709
- * @param {string} params.pingback URL for `pingback` (callback) response that will be sent when captcha is solved. [More info here](https://2captcha.com/2captcha-api#pingback).
710
- *
711
- * @returns {Promise<CaptchaAnswer>} The result from the solve
712
- *
713
- * @example
714
- * const imageBase64 = fs.readFileSync("./tests/media/hCaptchaImage.jpg", "base64")
715
- *
716
- * solver.coordinates({
717
- * body: imageBase64,
718
- * textinstructions: 'Select all photos containing the boat'
719
- * })
720
- * .then((res) => {
721
- * console.log(res);
722
- * })
723
- * .catch((err) => {
724
- * console.log(err);
725
- * })
726
- */
727
- async coordinates(params) {
728
- (0, checkCaptchaParams_1.default)(params, "base64");
729
- const payload = {
730
- ...params,
731
- method: "base64",
732
- coordinatescaptcha: 1,
733
- ...this.defaultPayload,
734
- };
735
- const URL = this.in;
736
- const response = await (0, fetch_1.default)(URL, {
737
- method: 'post',
738
- body: JSON.stringify(payload),
739
- headers: { 'Content-Type': 'application/json' }
740
- });
741
- const result = await response.text();
742
- let data;
743
- try {
744
- data = JSON.parse(result);
745
- }
746
- catch {
747
- throw new _2captchaError_1.APIError(result);
748
- }
749
- if (data.status == 1) {
750
- return this.pollResponse(data.request);
751
- }
752
- else {
753
- throw new _2captchaError_1.APIError(data.request);
754
- }
755
- }
756
- /**
757
- * ### Solves Capy Puzzle captcha
758
- *
759
- * @param {{ pageurl, captchakey, api_server, version, pingback, proxy, proxytype}} params Parameters Capy Puzzle Captcha as an object.
760
- * @param {string} params.pageurl Full `URL`of the page where you see the captcha.
761
- * @param {string} params.captchakey Value of `captchakey` parameter you found on page.
762
- * @param {string} params.api_server The domain part of script URL you found on page. Default value: `https://jp.api.capy.me/`.
763
- * @param {string} params.version The version of captcha task: `puzzle` (assemble a puzzle) or `avatar` (drag an object)..
764
- * @param {string} params.pingback URL for pingback (callback) response that will be sent when captcha is solved. URL should be registered on the server. [More info here](https://2captcha.com/2captcha-api#pingback).
765
- * @param {string} params.proxy Format: `login:password@123.123.123.123:3128` You can find more info about proxies [here](https://2captcha.com/2captcha-api#proxies).
766
- * @param {string} params.proxytype Type of your proxy: `HTTP`, `HTTPS`, `SOCKS4`, `SOCKS5`.
767
- *
768
- * @example
769
- * solver.capyPuzzle({
770
- * pageurl: "https://www.capy.me/account/register/",
771
- * captchakey: "PUZZLE_Cme4hZLjuZRMYC3uh14C52D3uNms5w"
772
- * })
773
- * .then((res) => {
774
- * console.log(res);
775
- * })
776
- * .catch((err) => {
777
- * console.log(err);
778
- * })
779
- */
780
- async capyPuzzle(params) {
781
- (0, checkCaptchaParams_1.default)(params, "capy");
782
- const payload = {
783
- ...params,
784
- method: "capy",
785
- ...this.defaultPayload,
786
- };
787
- const response = await (0, fetch_1.default)(this.in + utils.objectToURI(payload));
788
- const result = await response.text();
789
- let data;
790
- try {
791
- data = JSON.parse(result);
792
- }
793
- catch {
794
- throw new _2captchaError_1.APIError(result);
795
- }
796
- if (data.status == 1) {
797
- return this.pollResponse(data.request);
798
- }
799
- else {
800
- throw new _2captchaError_1.APIError(data.request);
801
- }
802
- }
803
- /**
804
- * ### Solves DataDome captcha
805
- *
806
- * @param {{ pageurl, captcha_url, userAgent, pingback, proxy, proxytype}} params Parameters DataDome Captcha as an object.
807
- * @param {string} params.pageurl Full `URL` of the page where you see the captcha.
808
- * @param {string} params.captcha_url The value of the `src` parameter for the `iframe` element containing the captcha on the page.
809
- * @param {string} params.userAgent ser-Agent of your MODERN browser
810
- * @param {string} params.pingback URL for pingback (callback) response that will be sent when captcha is solved. URL should be registered on the server. [More info here](https://2captcha.com/2captcha-api#pingback).
811
- * @param {string} params.proxy Format: `login:password@123.123.123.123:3128` You can find more info about proxies [here](https://2captcha.com/2captcha-api#proxies).
812
- * @param {string} params.proxytype Type of your proxy: `HTTP`, `HTTPS`, `SOCKS4`, `SOCKS5`.
813
- *
814
- * @example
815
- * solver.dataDome({
816
- * pageurl: "https://rendezvousparis.hermes.com/client/register",
817
- * captcha_url: "https://geo.captcha-delivery.com/captcha/?initialCid=AHrlqAAAAAMAEuQtkf4k1c0ABZhYZA%3D%3D&hash=789361B674144528D0B7EE76B35826&cid=mY4z7GNmh7Nt1lAFwpbNHAOcWPhyPgjHD2K1Pm~Od1iEKYLUnK3t7N2ZGUj8OqDK65cnwJHtHwd~t902vlwpSBA5l4ZHbS1Qszv~jEuEUJNQ_jMAjar2Kj3kq20MRJYh&t=fe&referer=https%3A%2F%2Frendezvousparis.hermes.com%2Fclient%2Fregister&s=40119&e=67fef144ac1a54dbd7507776367d2f9d5e36ec3add17fa22f3cb881db8385838",
818
- * userAgent: "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/118.0.0.0 Safari/537.36",
819
- * proxy: "1.2.3.4:8888:user:password",
820
- * proxytype: "http"
821
- * })
822
- * .then((res) => {
823
- * console.log(res);
824
- * })
825
- * .catch((err) => {
826
- * console.log(err);
827
- * })
828
- */
829
- async dataDome(params) {
830
- (0, checkCaptchaParams_1.default)(params, "datadome");
831
- const payload = {
832
- ...params,
833
- method: "datadome",
834
- ...this.defaultPayload,
835
- };
836
- const response = await (0, fetch_1.default)(this.in + utils.objectToURI(payload));
837
- const result = await response.text();
838
- let data;
839
- try {
840
- data = JSON.parse(result);
841
- }
842
- catch {
843
- throw new _2captchaError_1.APIError(result);
844
- }
845
- if (data.status == 1) {
846
- return this.pollResponse(data.request);
847
- }
848
- else {
849
- throw new _2captchaError_1.APIError(data.request);
850
- }
851
- }
852
- /**
853
- * ### Solves CyberSiARA captcha
854
- *
855
- * @param {{ pageurl, master_url_id, userAgent, pingback, proxy, proxytype}} params Parameters CyberSiARA Captcha as an object.
856
- * @param {string} params.pageurl Full `URL` of the page where you see the captcha.
857
- * @param {string} params.master_url_id The value of `MasterUrlId` parameter obtained from the request to the endpoint `API/CyberSiara/GetCyberSiara`.
858
- * @param {string} params.userAgent ser-Agent of your MODERN browser
859
- * @param {string} params.pingback URL for pingback (callback) response that will be sent when captcha is solved. URL should be registered on the server. [More info here](https://2captcha.com/2captcha-api#pingback).
860
- * @param {string} params.proxy Format: `login:password@123.123.123.123:3128` You can find more info about proxies [here](https://2captcha.com/2captcha-api#proxies).
861
- * @param {string} params.proxytype Type of your proxy: `HTTP`, `HTTPS`, `SOCKS4`, `SOCKS5`.
862
- *
863
- * @example
864
- * solver.cyberSiARA({
865
- * pageurl: "https://www.cybersiara.com/book-a-demo",
866
- * master_url_id: "OXR2LVNvCuXykkZbB8KZIfh162sNT8S2",
867
- * userAgent: "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/118.0.0.0 Safari/537.36"
868
- * })
869
- * .then((res) => {
870
- * console.log(res);
871
- * })
872
- * .catch((err) => {
873
- * console.log(err);
874
- * })
875
- */
876
- async cyberSiARA(params) {
877
- (0, checkCaptchaParams_1.default)(params, "cybersiara");
878
- const payload = {
879
- ...params,
880
- method: "cybersiara",
881
- ...this.defaultPayload,
882
- };
883
- const response = await (0, fetch_1.default)(this.in + utils.objectToURI(payload));
884
- const result = await response.text();
885
- let data;
886
- try {
887
- data = JSON.parse(result);
888
- }
889
- catch {
890
- throw new _2captchaError_1.APIError(result);
891
- }
892
- if (data.status == 1) {
893
- return this.pollResponse(data.request);
894
- }
895
- else {
896
- throw new _2captchaError_1.APIError(data.request);
897
- }
898
- }
899
- /**
900
- * ### Solves MTCaptcha
901
- *
902
- * @param {{ pageurl, sitekey, userAgent, pingback, proxy, proxytype}} params Parameters MTCaptcha as an object.
903
- * @param {string} params.pageurl Full `URL` of the page where you see the captcha.
904
- * @param {string} params.sitekey TThe value of `sitekey` parameter found on the page.
905
- * @param {string} params.pingback URL for pingback (callback) response that will be sent when captcha is solved. URL should be registered on the server. [More info here](https://2captcha.com/2captcha-api#pingback).
906
- * @param {string} params.proxy Format: `login:password@123.123.123.123:3128` You can find more info about proxies [here](https://2captcha.com/2captcha-api#proxies).
907
- * @param {string} params.proxytype Type of your proxy: `HTTP`, `HTTPS`, `SOCKS4`, `SOCKS5`.
908
- *
909
- * @example
910
- * solver.mtCaptcha({
911
- * pageurl: "https://service.mtcaptcha.com/mtcv1/demo/index.html",
912
- * sitekey: "MTPublic-DemoKey9M"
913
- * })
914
- * .then((res) => {
915
- * console.log(res);
916
- * })
917
- * .catch((err) => {
918
- * console.log(err);
919
- * })
920
- */
921
- async mtCaptcha(params) {
922
- (0, checkCaptchaParams_1.default)(params, "mt_captcha");
923
- const payload = {
924
- ...params,
925
- method: "mt_captcha",
926
- ...this.defaultPayload,
927
- };
928
- const response = await (0, fetch_1.default)(this.in + utils.objectToURI(payload));
929
- const result = await response.text();
930
- let data;
931
- try {
932
- data = JSON.parse(result);
933
- }
934
- catch {
935
- throw new _2captchaError_1.APIError(result);
936
- }
937
- if (data.status == 1) {
938
- return this.pollResponse(data.request);
939
- }
940
- else {
941
- throw new _2captchaError_1.APIError(data.request);
942
- }
943
- }
944
- /**
945
- * ### Solves a Cutcaptcha.
946
- *
947
- * Use this method to solve Cutcaptcha. Returns the response in JSON.
948
- * [Read more about Cutcaptcha Method](https://2captcha.com/2captcha-api#cutcaptcha).
949
- *
950
- * @param {{ pageurl, miseryKey, apiKey, pingback, proxy, proxytype }} params Parameters for solving Cutcaptcha as an object.
951
- * @param {string} params.pageurl The URL where the captcha is located.
952
- * @param {string} params.miseryKey The value of `CUTCAPTCHA_MISERY_KEY` variable defined on page.
953
- * @param {string} params.apiKey The value of `data-apikey` attribute of iframe's body. Also the name of javascript file included on the page
954
- * @param {string} [params.pingback] Optional param. URL for pingback (callback) response when captcha is solved.
955
- * @param {string} [params.proxy] Optional param. Proxy to use while solving the captcha. Format: `login:password@123.123.123.123:3128`.
956
- * @param {string} [params.proxytype] Optional param. Type of your proxy: `HTTP`, `HTTPS`, `SOCKS4`, `SOCKS5`.
957
- *
958
- * @returns {Promise<CaptchaAnswer>} The result from the solve.
959
- * @throws APIError
960
- *
961
- * @example
962
- * solver.cutCaptcha({
963
- * pageurl: "https://mysite.com/page/with/cutcaptcha",
964
- * miseryKey: "098e6a849af406142e3150dbf4e6d0538db2b51f",
965
- * apiKey: "SAs61IAI",
966
- * })
967
- * .then((res) => {
968
- * console.log(res);
969
- * })
970
- * .catch((err) => {
971
- * console.log(err);
972
- * })
973
- */
974
- async cutCaptcha(params) {
975
- params = (0, renameParams_1.default)(params);
976
- (0, checkCaptchaParams_1.default)(params, "cutcaptcha");
977
- const payload = {
978
- ...params,
979
- method: "cutcaptcha",
980
- ...this.defaultPayload,
981
- };
982
- const URL = this.in;
983
- const response = await (0, fetch_1.default)(URL, {
984
- body: JSON.stringify(payload),
985
- method: "post",
986
- headers: { 'Content-Type': 'application/json' }
987
- });
988
- const result = await response.text();
989
- let data;
990
- try {
991
- data = JSON.parse(result);
992
- }
993
- catch {
994
- throw new _2captchaError_1.APIError(result);
995
- }
996
- if (data.status == 1) {
997
- return this.pollResponse(data.request);
998
- }
999
- else {
1000
- throw new _2captchaError_1.APIError(data.request);
1001
- }
1002
- }
1003
- /**
1004
- * ### Solves Friendly Captcha
1005
- *
1006
- * @param {{ pageurl, sitekey, pingback, proxy, proxytype}} params Parameters Friendly Captcha as an object.
1007
- * @param {string} params.pageurl Full `URL` of the page where you see the captcha.
1008
- * @param {string} params.sitekey The value of `data-apikey` or `data-sitekey` parameter found on the page.
1009
- * @param {string} params.pingback URL for pingback (callback) response that will be sent when captcha is solved. URL should be registered on the server. [More info here](https://2captcha.com/2captcha-api#pingback).
1010
- * @param {string} params.proxy Format: `login:password@123.123.123.123:3128` You can find more info about proxies [here](https://2captcha.com/2captcha-api#proxies).
1011
- * @param {string} params.proxytype Type of your proxy: `HTTP`, `HTTPS`, `SOCKS4`, `SOCKS5`.
1012
- *
1013
- * @example
1014
- * solver.friendlyCaptcha({
1015
- * pageurl: "https://geizhals.de/?liftban=1&from=/455973138?fsean=5901747021356",
1016
- * sitekey: "FCMST5VUMCBOCGQ9"
1017
- * })
1018
- * .then((res) => {
1019
- * console.log(res);
1020
- * })
1021
- * .catch((err) => {
1022
- * console.log(err);
1023
- * })
1024
- */
1025
- async friendlyCaptcha(params) {
1026
- (0, checkCaptchaParams_1.default)(params, "friendly_captcha");
1027
- const payload = {
1028
- ...params,
1029
- method: "friendly_captcha",
1030
- ...this.defaultPayload,
1031
- };
1032
- const response = await (0, fetch_1.default)(this.in + utils.objectToURI(payload));
1033
- const result = await response.text();
1034
- let data;
1035
- try {
1036
- data = JSON.parse(result);
1037
- }
1038
- catch {
1039
- throw new _2captchaError_1.APIError(result);
1040
- }
1041
- if (data.status == 1) {
1042
- return this.pollResponse(data.request);
1043
- }
1044
- else {
1045
- throw new _2captchaError_1.APIError(data.request);
1046
- }
1047
- }
1048
- /**
1049
- * ### Bounding Box Method
1050
- *
1051
- * @param {{ image, textinstructions, imginstructions }} params Parameters Bounding Box Method as an object.
1052
- * @param {string} params.image Image containing data for markup. The image must be encoded in `Base64` format.
1053
- * @param {string} params.textinstructions Text will be shown to worker to help him to select object on the image correctly. For example: "*Select cars in the image*". **Optional parameter**, if the instruction already exists in the form of the `imginstructions`.
1054
- * @param {string} params.imginstructions Image with instruction for worker to help him to select object on the image correctly. The image must be encoded in `Base64` format. **Optional parameter**, if the instruction already exists in the form of the `textinstructions`.
1055
- *
1056
- * @example
1057
- * solver.boundingBox({
1058
- * image: "data:image/jpeg;base64,/9j/4AAQSkZJRgABAQAAAQABAAD/2wBDAAgG...",
1059
- * textinstructions: "Select cars in the image"
1060
- * })
1061
- * .then((res) => {
1062
- * console.log(res);
1063
- * })
1064
- * .catch((err) => {
1065
- * console.log(err);
1066
- * })
1067
- */
1068
- async boundingBox(params) {
1069
- (0, checkCaptchaParams_1.default)(params, "bounding_box");
1070
- const payload = {
1071
- ...params,
1072
- method: "bounding_box",
1073
- ...this.defaultPayload,
1074
- };
1075
- const URL = this.in;
1076
- const response = await (0, fetch_1.default)(URL, {
1077
- body: JSON.stringify(payload),
1078
- method: "post",
1079
- headers: { 'Content-Type': 'application/json' }
1080
- });
1081
- const result = await response.text();
1082
- let data;
1083
- try {
1084
- data = JSON.parse(result);
1085
- }
1086
- catch {
1087
- throw new _2captchaError_1.APIError(result);
1088
- }
1089
- if (data.status == 1) {
1090
- return this.pollResponse(data.request);
1091
- }
1092
- else {
1093
- throw new _2captchaError_1.APIError(data.request);
1094
- }
1095
- }
1096
- /**
1097
- * ### Grid method
1098
- *
1099
- * The method can be used to bypass tasks where a grid is applied to an image and you need to click on grid tiles, like reCAPTCHA or hCaptcha images.
1100
- *
1101
- * @param {{ body, textinstructions, imginstructions, rows, cols, minClicks, maxClicks, imgType, previousId, canSkip, lang, pingback}} params Parameters Grid Method as an object.
1102
- * @param {string} params.body `Base64`- encoded captcha image.
1103
- * @param {string} params.textinstructions Text will be shown to worker to help him to select object on the image correctly. For example: "*Select cars in the image*". **Optional parameter**, if the instruction already exists in the form of the `imginstructions`.
1104
- * @param {string} params.imginstructions Image with instruction for worker to help him to select object on the image correctly. The image must be encoded in `Base64` format. **Optional parameter**, if the instruction already exists in the form of the `textinstructions`.
1105
- * @param {number} params.rows Number of rows in grid captcha.
1106
- * @param {number} params.cols Number of columns in grid captcdha.
1107
- * @param {number} params.minClicks The minimum number of tiles that must be selected. Can't be more than `rows` * `cols`.
1108
- * @param {number} params.maxClicks The maximum number of tiles that can be selected on the image.
1109
- * @param {string} params.imgType The image will be recognized using Computer Vision. Supported value options: `recaptcha`, `hcaptcha`, `funcaptcha`, `funcaptcha_compare`. [More info here](https://2captcha.com/2captcha-api#grid).
1110
- * @param {string} params.previousId Id of your previous request with the same captcha challenge.
1111
- * @param {number} params.canSkip Set the value to `1` only if it's possible that there's no images matching to the instruction. We'll provide a button "No matching images" to worker and you will receive `No_matching_images` as answer.
1112
- * @param {string} params.lang Language code. [See the list of supported languages](https://2captcha.com/2captcha-api#language).
1113
- * @param {string} params.pingback params.pingback URL for pingback (callback) response that will be sent when captcha is solved. URL should be registered on the server. [More info here](https://2captcha.com/2captcha-api#pingback).
1114
- *
1115
- * @example
1116
- * solver.grid({
1117
- * body: 'iVBORw0KGgoAAAANSUhEUgAAAcIA...',
1118
- * textinstructions: "Select cars in the image",
1119
- * imginstructions: '/9j/4AAQSkZJRgABAQEA...'
1120
- * })
1121
- * .then((res) => {
1122
- * console.log(res);
1123
- * })
1124
- * .catch((err) => {
1125
- * console.log(err);
1126
- * })
1127
- */
1128
- async grid(params) {
1129
- (0, checkCaptchaParams_1.default)(params, "grid");
1130
- params = await (0, renameParams_1.default)(params);
1131
- const payload = {
1132
- ...params,
1133
- method: "base64",
1134
- recaptcha: 1,
1135
- ...this.defaultPayload,
1136
- };
1137
- const URL = this.in;
1138
- const response = await (0, fetch_1.default)(URL, {
1139
- body: JSON.stringify(payload),
1140
- method: "post",
1141
- headers: { 'Content-Type': 'application/json' }
1142
- });
1143
- const result = await response.text();
1144
- let data;
1145
- try {
1146
- data = JSON.parse(result);
1147
- }
1148
- catch {
1149
- throw new _2captchaError_1.APIError(result);
1150
- }
1151
- if (data.status == 1) {
1152
- return this.pollResponse(data.request);
1153
- }
1154
- else {
1155
- throw new _2captchaError_1.APIError(data.request);
1156
- }
1157
- }
1158
- /**
1159
- * ### Text Captcha method
1160
- *
1161
- * Text Captcha is a type of captcha that is represented as text and doesn't contain images. Usually you have to answer a question to pass the verification. For example: "If tomorrow is Saturday, what day is today?".
1162
- * [Read more about Text Captcha Method](https://2captcha.com/2captcha-api#text-captcha).
1163
- *
1164
- * @param {{ textcaptcha, lang, pingback}} params Parameters Text Captcha Method as an object.
1165
- * @param {string} params.textcaptcha Text Captcha is a type of captcha that is represented as text and doesn't contain images. Usually you have to answer a question to pass the verification.
1166
- * @param {string} params.lang Language code. [See the list of supported languages](https://2captcha.com/2captcha-api#language).
1167
- * @param {string} params.pingback params.pingback URL for pingback (callback) response that will be sent when captcha is solved. URL should be registered on the server. [More info here](https://2captcha.com/2captcha-api#pingback).
1168
- *
1169
- * @example
1170
- * solver.text({
1171
- * textcaptcha: "If tomorrow is Saturday, what day is today?",
1172
- * lang: 'en'
1173
- * })
1174
- * .then((res) => {
1175
- * console.log(res);
1176
- * })
1177
- * .catch((err) => {
1178
- * console.log(err);
1179
- * })
1180
- */
1181
- async text(params) {
1182
- (0, checkCaptchaParams_1.default)(params, "textcaptcha");
1183
- params = await (0, renameParams_1.default)(params);
1184
- const payload = {
1185
- ...params,
1186
- ...this.defaultPayload,
1187
- };
1188
- const URL = this.in;
1189
- const response = await (0, fetch_1.default)(URL, {
1190
- body: JSON.stringify(payload),
1191
- method: "post",
1192
- headers: { 'Content-Type': 'application/json' }
1193
- });
1194
- const result = await response.text();
1195
- let data;
1196
- try {
1197
- data = JSON.parse(result);
1198
- }
1199
- catch {
1200
- throw new _2captchaError_1.APIError(result);
1201
- }
1202
- if (data.status == 1) {
1203
- return this.pollResponse(data.request);
1204
- }
1205
- else {
1206
- throw new _2captchaError_1.APIError(data.request);
1207
- }
1208
- }
1209
- /**
1210
- * ### Canvas method
1211
- *
1212
- * This method can be used to bypass tasks in which you need to circle an object or line in an image.
1213
- * [Read more about Canvas Method](https://2captcha.com/2captcha-api#canvas).
1214
- *
1215
- * @param {{ body, textinstructions, imginstructions, canSkip, lang, pingback}} params Parameters Canvas as an object.
1216
- * @param {string} params.body `Base64`- encoded captcha image.
1217
- * @param {string} params.textinstructions Text will be shown to worker to help him to select object on the image correctly. For example: "*Select cars in the image*". **Optional parameter**, if the instruction already exists in the form of the `imginstructions`.
1218
- * @param {string} params.imginstructions Image with instruction for worker to help him to select object on the image correctly. The image must be encoded in `Base64` format. **Optional parameter**, if the instruction already exists in the form of the `textinstructions`.
1219
- * @param {number} params.canSkip Set the value to `1` only if it's possible that there's no images matching to the instruction. We'll provide a button "No matching images" to worker and you will receive `No_matching_images` as answer.
1220
- * @param {string} params.lang Language code. [See the list of supported languages](https://2captcha.com/2captcha-api#language).
1221
- * @param {string} params.pingback params.pingback URL for pingback (callback) response that will be sent when captcha is solved. URL should be registered on the server. [More info here](https://2captcha.com/2captcha-api#pingback).
1222
- *
1223
- * @example
1224
- * solver.canvas({
1225
- * body: 'iVBORw0KGgoAAAANSgAAAcIA...',
1226
- * imginstructions: '/9j/4AAQSkZJRgABAQEA...',
1227
- * textinstructions: 'Highlight the red CIRCLE'
1228
- * })
1229
- * .then((res) => {
1230
- * console.log(res);
1231
- * })
1232
- * .catch((err) => {
1233
- * console.log(err);
1234
- * })
1235
- */
1236
- async canvas(params) {
1237
- (0, checkCaptchaParams_1.default)(params, "canvas");
1238
- params = await (0, renameParams_1.default)(params);
1239
- const payload = {
1240
- ...params,
1241
- recaptcha: 1,
1242
- canvas: 1,
1243
- method: "base64",
1244
- ...this.defaultPayload,
1245
- };
1246
- const URL = this.in;
1247
- const response = await (0, fetch_1.default)(URL, {
1248
- body: JSON.stringify(payload),
1249
- method: "post",
1250
- headers: { 'Content-Type': 'application/json' }
1251
- });
1252
- const result = await response.text();
1253
- let data;
1254
- try {
1255
- data = JSON.parse(result);
1256
- }
1257
- catch {
1258
- throw new _2captchaError_1.APIError(result);
1259
- }
1260
- if (data.status == 1) {
1261
- return this.pollResponse(data.request);
1262
- }
1263
- else {
1264
- throw new _2captchaError_1.APIError(data.request);
1265
- }
1266
- }
1267
- /**
1268
- * ### Rotate method
1269
- *
1270
- * This method can be used to solve a captcha that asks to rotate an object. It is mostly used to bypass FunCaptcha. Returns the rotation angle.
1271
- * [Read more about Rotate Method](https://2captcha.com/2captcha-api#solving_rotatecaptcha).
1272
- *
1273
- * @param {{ body, angle, pingback, lang, textinstructions, imginstructions }} params Parameters for solving Rotate Captcha as an object.
1274
- * @param {string} params.body Base64-encoded image of the captcha that needs to be rotated.
1275
- * @param {number} params.angle Angle to which the captcha needs to be rotated to solve it correctly. Value between `0` to `360`.
1276
- * @param {string} params.textinstructions Optional param. Text instruction that will be shown to worker to help solve the captcha correctly.
1277
- * @param {string} params.imginstructions Optional param. Base64-encoded image instruction that will be shown to worker to help solve the captcha correctly.
1278
- * @param {string} params.lang Optional param. Language code for worker to use while solving the captcha.
1279
- * @param {string} params.pingback Optional param. URL for pingback (callback) response when captcha is solved.
1280
- *
1281
- * @returns {Promise<CaptchaAnswer>} The result from the solve.
1282
- * @throws APIError
1283
- *
1284
- * @example
1285
- * solver.rotate({
1286
- * body: "iVBORw0KGgoAAAANSUhEUgAAAcIA...",
1287
- * angle: 15,
1288
- * textinstructions: "Rotate the object to the correct position"
1289
- * })
1290
- * .then((res) => {
1291
- * console.log(res);
1292
- * })
1293
- * .catch((err) => {
1294
- * console.log(err);
1295
- * })
1296
- */
1297
- async rotate(params) {
1298
- (0, checkCaptchaParams_1.default)(params, "rotatecaptcha");
1299
- const payload = {
1300
- ...params,
1301
- method: "rotatecaptcha",
1302
- ...this.defaultPayload,
1303
- };
1304
- const URL = this.in;
1305
- const response = await (0, fetch_1.default)(URL, {
1306
- body: JSON.stringify(payload),
1307
- method: "post",
1308
- headers: { 'Content-Type': 'application/json' }
1309
- });
1310
- const result = await response.text();
1311
- let data;
1312
- try {
1313
- data = JSON.parse(result);
1314
- }
1315
- catch {
1316
- throw new _2captchaError_1.APIError(result);
1317
- }
1318
- if (data.status == 1) {
1319
- return this.pollResponse(data.request);
1320
- }
1321
- else {
1322
- throw new _2captchaError_1.APIError(data.request);
1323
- }
1324
- }
1325
- /**
1326
- * ### Solves a KeyCaptcha.
1327
- *
1328
- * This method can be used to solve a KeyCaptcha. It is mostly used to bypass captchas that use KeyCaptcha technology.
1329
- * [Read more about KeyCaptcha Method](https://2captcha.com/2captcha-api#solving_keycaptcha).
1330
- *
1331
- * @param {{ pageurl, userId, sessionId, webServerSign, webServerSign2, pingback, proxy, proxytype }} params Parameters for solving KeyCaptcha as an object.
1332
- * @param {string} params.pageurl The URL where the captcha is located.
1333
- * @param {string} params.userId Value of `s_s_c_user_id` parameter you found on page.
1334
- * @param {string} params.sessionId Value of `s_s_c_session_id` parameter you found on page.
1335
- * @param {string} params.webServerSign Value of `s_s_c_web_server_sign` parameter you found on page.
1336
- * @param {string} params.webServerSign2 Value of `s_s_c_web_server_sign2` parameter you found on page.
1337
- * @param {string} [params.pingback] Optional param. URL for pingback (callback) response when captcha is solved.
1338
- * @param {string} [params.proxy] Optional param. Proxy to use while solving the captcha. Format: `login:password@123.123.123.123:3128`.
1339
- * @param {string} [params.proxytype] Optional param. Type of your proxy: `HTTP`, `HTTPS`, `SOCKS4`, `SOCKS5`.
1340
- *
1341
- * @returns {Promise<CaptchaAnswer>} The result from the solve.
1342
- * @throws APIError
1343
- *
1344
- * @example
1345
- * solver.keyCaptcha({
1346
- * pageurl: "https://2captcha.com/demo/keycaptcha",
1347
- * userId: "184015",
1348
- * sessionId: "11975dc265ce9174a54edb1619af15b7",
1349
- * webServerSign: "73ef77fd3cf0ce02947d9088bdc8412a",
1350
- * webServerSign2: "93836d9e7007f38f072ce07d89bb7e2b"
1351
- * })
1352
- * .then((res) => {
1353
- * console.log(res);
1354
- * })
1355
- * .catch((err) => {
1356
- * console.log(err);
1357
- * })
1358
- */
1359
- async keyCaptcha(params) {
1360
- params = await (0, renameParams_1.default)(params);
1361
- (0, checkCaptchaParams_1.default)(params, "keycaptcha");
1362
- const payload = {
1363
- ...params,
1364
- method: "keycaptcha",
1365
- ...this.defaultPayload,
1366
- };
1367
- const URL = this.in;
1368
- const response = await (0, fetch_1.default)(URL, {
1369
- body: JSON.stringify(payload),
1370
- method: "post",
1371
- headers: { 'Content-Type': 'application/json' }
1372
- });
1373
- const result = await response.text();
1374
- let data;
1375
- try {
1376
- data = JSON.parse(result);
1377
- }
1378
- catch {
1379
- throw new _2captchaError_1.APIError(result);
1380
- }
1381
- if (data.status == 1) {
1382
- return this.pollResponse(data.request);
1383
- }
1384
- else {
1385
- throw new _2captchaError_1.APIError(data.request);
1386
- }
1387
- }
1388
- /**
1389
- * ### Solves a Tencent.
1390
- *
1391
- * Use this method to solve Tencent captcha. Returns a token.
1392
- * [Read more about Tencent Method](https://2captcha.com/2captcha-api#tencent).
1393
- *
1394
- * @param {{ pageurl, appId, pingback, proxy, proxytype }} params Parameters for solving Tencent as an object.
1395
- * @param {string} params.pageurl The URL where the captcha is located.
1396
- * @param {string} params.appId The value of `appId` parameter in the website source code.
1397
- * @param {string} [params.pingback] Optional param. URL for pingback (callback) response when captcha is solved.
1398
- * @param {string} [params.proxy] Optional param. Proxy to use while solving the captcha. Format: `login:password@123.123.123.123:3128`.
1399
- * @param {string} [params.proxytype] Optional param. Type of your proxy: `HTTP`, `HTTPS`, `SOCKS4`, `SOCKS5`.
1400
- *
1401
- * @returns {Promise<CaptchaAnswer>} The result from the solve.
1402
- * @throws APIError
1403
- *
1404
- * @example
1405
- * solver.tencent({
1406
- * pageurl: "https://mysite.com/page/with/tencent",
1407
- * appId: "189956587"
1408
- * })
1409
- * .then((res) => {
1410
- * console.log(res);
1411
- * })
1412
- * .catch((err) => {
1413
- * console.log(err);
1414
- * })
1415
- */
1416
- async tencent(params) {
1417
- params = await (0, renameParams_1.default)(params);
1418
- (0, checkCaptchaParams_1.default)(params, "tencent");
1419
- const payload = {
1420
- ...params,
1421
- method: "tencent",
1422
- ...this.defaultPayload,
1423
- };
1424
- const URL = this.in;
1425
- const response = await (0, fetch_1.default)(URL, {
1426
- body: JSON.stringify(payload),
1427
- method: "post",
1428
- headers: { 'Content-Type': 'application/json' }
1429
- });
1430
- const result = await response.text();
1431
- let data;
1432
- try {
1433
- data = JSON.parse(result);
1434
- }
1435
- catch {
1436
- throw new _2captchaError_1.APIError(result);
1437
- }
1438
- if (data.status == 1) {
1439
- return this.pollResponse(data.request);
1440
- }
1441
- else {
1442
- throw new _2captchaError_1.APIError(data.request);
1443
- }
1444
- }
1445
- /**
1446
- * ### Solves a atbCAPTCHA.
1447
- *
1448
- * Use this method to solve atbCAPTCHA captcha. Returns a token.
1449
- * [Read more about atbCAPTCHA Method](https://2captcha.com/2captcha-api#atb-captcha).
1450
- *
1451
- * @param {{ pageurl, appId, apiServer, pingback, proxy, proxytype }} params Parameters for solving atbCAPTCHA as an object.
1452
- * @param {string} params.pageurl The URL where the captcha is located.
1453
- * @param {string} params.appId The value of `appId` parameter in the website source code.
1454
- * @param {string} params.apiServer The value of `apiServer` parameter in the website source code.
1455
- * @param {string} [params.pingback] Optional param. URL for pingback (callback) response when captcha is solved.
1456
- * @param {string} [params.proxy] Optional param. Proxy to use while solving the captcha. Format: `login:password@123.123.123.123:3128`.
1457
- * @param {string} [params.proxytype] Optional param. Type of your proxy: `HTTP`, `HTTPS`, `SOCKS4`, `SOCKS5`.
1458
- *
1459
- * @returns {Promise<CaptchaAnswer>} The result from the solve.
1460
- * @throws APIError
1461
- *
1462
- * @example
1463
- * solver.atbCaptcha({
1464
- * pageurl: "https://mysite.com/page/with/tencent",
1465
- * appId: "af25e409b33d722a95e56a230ff8771c",
1466
- apiServer: "https://cap.aisecurius.com"
1467
- * })
1468
- * .then((res) => {
1469
- * console.log(res);
1470
- * })
1471
- * .catch((err) => {
1472
- * console.log(err);
1473
- * })
1474
- */
1475
- async atbCaptcha(params) {
1476
- params = await (0, renameParams_1.default)(params);
1477
- (0, checkCaptchaParams_1.default)(params, "atb_captcha");
1478
- const payload = {
1479
- ...params,
1480
- method: "atb_captcha",
1481
- ...this.defaultPayload,
1482
- };
1483
- const URL = this.in;
1484
- const response = await (0, fetch_1.default)(URL, {
1485
- body: JSON.stringify(payload),
1486
- method: "post",
1487
- headers: { 'Content-Type': 'application/json' }
1488
- });
1489
- const result = await response.text();
1490
- let data;
1491
- try {
1492
- data = JSON.parse(result);
1493
- }
1494
- catch {
1495
- throw new _2captchaError_1.APIError(result);
1496
- }
1497
- if (data.status == 1) {
1498
- return this.pollResponse(data.request);
1499
- }
1500
- else {
1501
- throw new _2captchaError_1.APIError(data.request);
1502
- }
1503
- }
1504
- /**
1505
- * ### Method for solving Audio captcha.
1506
- *
1507
- * Use the following method to bypass an audio captcha (`mp3` formats only). You must provide the language as `lang = 'en'`. Supported languages are "en", "ru", "de", "el", "pt", "fr".
1508
- * [Read more about Audio recognition Method](https://2captcha.com/2captcha-api#audio-recognition).
1509
- *
1510
- * @param {{ body, lang, pingback }} params Object containing parameters for the audio captcha.
1511
- * @param {string} params.body Base64 encoded audio file in `mp3` format. Max file size: 1 MB.
1512
- * @param {string} params.lang The language of audio record. Supported languages are: "en", "ru", "de", "el", "pt", "fr".
1513
- * @param {string} [params.pingback] URL for pingback response once captcha is solved.
1514
- *
1515
- * @returns {Promise<CaptchaAnswer>} The result from solving the audio captcha.
1516
- * @throws APIError
1517
- * @example
1518
- * solver.audio({
1519
- * body: "SUQzBAAAAAAAHFRTU0UAAAA...",
1520
- * lang: "en"
1521
- * })
1522
- * .then((res) => {
1523
- * console.log(res);
1524
- * })
1525
- * .catch((err) => {
1526
- * console.log(err);
1527
- * })
1528
- */
1529
- async audio(params) {
1530
- (0, checkCaptchaParams_1.default)(params, "audio");
1531
- const payload = {
1532
- ...params,
1533
- method: "audio",
1534
- ...this.defaultPayload
1535
- };
1536
- const response = await (0, fetch_1.default)(this.in, {
1537
- method: 'post',
1538
- body: JSON.stringify(payload),
1539
- headers: { 'Content-Type': 'application/json' }
1540
- });
1541
- const result = await response.text();
1542
- let data;
1543
- try {
1544
- data = JSON.parse(result);
1545
- }
1546
- catch {
1547
- throw new _2captchaError_1.APIError(result);
1548
- }
1549
- if (data.status == 1) {
1550
- return this.pollResponse(data.request);
1551
- }
1552
- else {
1553
- throw new _2captchaError_1.APIError(data.request);
1554
- }
1555
- }
1556
- /**
1557
- * Reports a captcha as correctly solved.
1558
- *
1559
- * @param {string} id The ID of the captcha
1560
- * @throws APIError
1561
- * @example
1562
- * solver.goodReport("7031854546")
1563
- *
1564
- */
1565
- async goodReport(id) {
1566
- const payload = {
1567
- id: id,
1568
- action: "reportgood",
1569
- ...this.defaultPayload
1570
- };
1571
- const response = await (0, fetch_1.default)(this.res + utils.objectToURI(payload));
1572
- const result = await response.text();
1573
- let data;
1574
- try {
1575
- data = JSON.parse(result);
1576
- }
1577
- catch {
1578
- throw new _2captchaError_1.APIError(result);
1579
- }
1580
- if (data.request == "OK_REPORT_RECORDED") {
1581
- return data.request;
1582
- }
1583
- else {
1584
- throw new _2captchaError_1.APIError(data.request);
1585
- }
1586
- }
1587
- /**
1588
- * Report an unsuccessful solve
1589
- *
1590
- * @param {string} id The id of the captcha solve
1591
- *
1592
- * @returns {Promise<void>} Resolves on completion
1593
- * @throws APIError
1594
- * @example
1595
- * solver.badReport("7031854546")
1596
- */
1597
- async badReport(id) {
1598
- const payload = {
1599
- id: id,
1600
- action: "reportbad",
1601
- ...this.defaultPayload
1602
- };
1603
- const response = await (0, fetch_1.default)(this.res + utils.objectToURI(payload));
1604
- const result = await response.text();
1605
- let data;
1606
- try {
1607
- data = JSON.parse(result);
1608
- }
1609
- catch {
1610
- throw new _2captchaError_1.APIError(result);
1611
- }
1612
- if (data.request == "OK_REPORT_RECORDED" || data.request == "ERROR_DUPLICATE_REPORT") {
1613
- return data.request;
1614
- }
1615
- else {
1616
- throw new _2captchaError_1.APIError(data.request);
1617
- }
1618
- }
1619
- }
1620
- exports.Solver = Solver;
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
15
+ }) : function(o, v) {
16
+ o["default"] = v;
17
+ });
18
+ var __importStar = (this && this.__importStar) || function (mod) {
19
+ if (mod && mod.__esModule) return mod;
20
+ var result = {};
21
+ if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
22
+ __setModuleDefault(result, mod);
23
+ return result;
24
+ };
25
+ var __importDefault = (this && this.__importDefault) || function (mod) {
26
+ return (mod && mod.__esModule) ? mod : { "default": mod };
27
+ };
28
+ Object.defineProperty(exports, "__esModule", { value: true });
29
+ exports.Solver = void 0;
30
+ const fetch_1 = __importDefault(require("../utils/fetch"));
31
+ const _2captchaError_1 = require("./2captchaError");
32
+ const utils = __importStar(require("../utils/generic"));
33
+ const providers_1 = __importDefault(require("./providers/providers"));
34
+ const constants_1 = require("./constants/constants");
35
+ const checkCaptchaParams_1 = __importDefault(require("../utils/checkCaptchaParams"));
36
+ const renameParams_1 = __importDefault(require("../utils/renameParams"));
37
+ const provider = (0, providers_1.default)();
38
+ /**
39
+ * The main 2captcha class, housing all API calls and api interactions.
40
+ *
41
+ */
42
+ class Solver {
43
+ /**
44
+ * The constructor for the 2captcha Solver class.
45
+ *
46
+ * @param {string} apikey The API key to use
47
+ * @param {number} pollingFrequency The frequency to poll for requests
48
+ *
49
+ */
50
+ constructor(apikey, pollingFrequency = 5000, enableACAO = true) {
51
+ this._apikey = apikey;
52
+ this._pollingFrequency = pollingFrequency;
53
+ this._headerACAO = enableACAO ? 1 : 0;
54
+ }
55
+ /** The API key this instance is using */
56
+ get apikey() { return this._apikey; }
57
+ /** Frequency the instance polls for updates */
58
+ get pollingFrequency() { return this._pollingFrequency; }
59
+ /** Set the API key for this instance */
60
+ set apikey(update) { this._apikey = update; }
61
+ get in() { return provider.in; }
62
+ get res() { return provider.res; }
63
+ get defaultPayload() { return { key: this.apikey, json: 1, header_acao: this._headerACAO, soft_id: constants_1.softId }; }
64
+ /**
65
+ * Returns the remaining account balance.
66
+ *
67
+ * @return {Promise<Number>} Remaining balance
68
+ * @throws APIError
69
+ * @example
70
+ * solver.balance()
71
+ * .then((res) => {
72
+ * console.log(res)
73
+ * })
74
+ */
75
+ async balance() {
76
+ const res = await (0, fetch_1.default)(this.res + utils.objectToURI({
77
+ ...this.defaultPayload,
78
+ action: "getbalance"
79
+ }));
80
+ const result = await res.text();
81
+ try {
82
+ const data = JSON.parse(result);
83
+ if (data.status == 1) {
84
+ return parseFloat(data.request);
85
+ }
86
+ throw new _2captchaError_1.APIError(data.request);
87
+ }
88
+ catch {
89
+ throw new _2captchaError_1.APIError(result);
90
+ }
91
+ }
92
+ /**
93
+ * @private
94
+ *
95
+ * Polls for a captcha, finding out if it's been completed
96
+ * @param {string} id Captcha ID
97
+ *
98
+ * @returns {Promise<CaptchaAnswer>}
99
+ * @throws APIError
100
+ */
101
+ async pollResponse(id) {
102
+ const payload = {
103
+ ...this.defaultPayload,
104
+ action: "get",
105
+ id: id
106
+ };
107
+ await utils.sleep(this.pollingFrequency);
108
+ const res = await (0, fetch_1.default)(this.res + utils.objectToURI(payload));
109
+ const result = await res.text();
110
+ let data;
111
+ try {
112
+ data = JSON.parse(result);
113
+ if (data.status == 1) {
114
+ let dataJSON = { ...data, data: data.request, id: id };
115
+ delete dataJSON.request;
116
+ return dataJSON;
117
+ }
118
+ }
119
+ catch {
120
+ throw new _2captchaError_1.APIError(result);
121
+ }
122
+ switch (data.request) {
123
+ case "CAPCHA_NOT_READY":
124
+ return this.pollResponse(id);
125
+ default: {
126
+ throw new _2captchaError_1.APIError(data.request);
127
+ }
128
+ }
129
+ }
130
+ /**
131
+ * ### Solves a google reCAPTCHA V2 | V3.
132
+ *
133
+ * [Read more about other reCAPTCHA parameters](https://2captcha.com/2captcha-api#solving_recaptchav2_new).
134
+ *
135
+ * @param {{pageurl, googlekey, cookies, proxy, proxytype, userAgent, invisible, datas, pingback, action, enterprise, min_score, version, domain}} params Object
136
+ * @param {string} params.pageurl The URL the captcha appears on.
137
+ * @param {string} params.googlekey Value of `k` or `data-sitekey` parameter you found on page.
138
+ * @param {string} params.cookies Your cookies that will be passed to our worker who solve the captha.
139
+ * @param {string} params.proxy Format: `login:password@123.123.123.123:3128`. You can find more info about proxies [here](https://2captcha.com/2captcha-api#proxies).
140
+ * @param {string} params.proxytype Type of your proxy: `HTTP`, `HTTPS`, `SOCKS4`, `SOCKS5`.
141
+ * @param {string} params.userAgent Your `userAgent` that will be passed to our worker and used to solve the captcha.
142
+ * @param {number} params.invisible `1` - means that reCAPTCHA is invisible. `0` - normal reCAPTCHA.
143
+ * @param {string} params.datas Value of `data-s` parameter you found on page. Curenttly applicable for Google Search and other Google services.
144
+ * @param {string} params.pingback URL for pingback (callback) response that will be sent when captcha is solved. URL should be registered on the server. [More info here](https://2captcha.com/2captcha-api#pingback).
145
+ * @param {string} params.action Value of `action` parameter you found on page.
146
+ * @param {number} params.enterprise `1` - defines that you're sending reCAPTCHA Enterpise.
147
+ * @param {number} params.min_score The score needed for resolution reCAPTCHA V3. Currently it's almost impossible to get token with score higher than `0.3`
148
+ * @param {string} params.version `v2` — defines that you're sending a reCAPTCHA V2. `v3` — defines that you're sending a reCAPTCHA V3.
149
+ * @param {string} params.domain Domain used to load the captcha: `google.com` or `recaptcha.net`
150
+ *
151
+ * @returns {Promise<CaptchaAnswer>} The result from the solve.
152
+ * @throws APIError
153
+ * @example
154
+ * solver.recaptcha({
155
+ * pageurl: 'https://2captcha.com/demo/recaptcha-v2',
156
+ * googlekey: '6LfD3PIbAAAAAJs_eEHvoOl75_83eXSqpPSRFJ_u'
157
+ * })
158
+ * .then((res) => {
159
+ * console.log(res);
160
+ * })
161
+ * .catch((err) => {
162
+ * console.log(err);
163
+ * })
164
+ */
165
+ async recaptcha(params) {
166
+ (0, checkCaptchaParams_1.default)(params, "userrecaptcha");
167
+ const payload = {
168
+ ...this.defaultPayload,
169
+ ...params,
170
+ method: "userrecaptcha"
171
+ };
172
+ const response = await (0, fetch_1.default)(this.in + utils.objectToURI(payload));
173
+ const result = await response.text();
174
+ let data;
175
+ try {
176
+ data = JSON.parse(result);
177
+ }
178
+ catch {
179
+ throw new _2captchaError_1.APIError(result);
180
+ }
181
+ if (data.status == 1) {
182
+ return this.pollResponse(data.request);
183
+ }
184
+ else {
185
+ throw new _2captchaError_1.APIError(data.request);
186
+ }
187
+ }
188
+ /**
189
+ * ### Solves a hCaptcha
190
+ *
191
+ * [Read more about other hCaptcha parameters](https://2captcha.com/2captcha-api#solving_hcaptcha).
192
+ *
193
+ * @param {{sitekey, pageurl, data, userAgent, invisible, pingback, proxy, proxytype, domain}} params Object
194
+ * @param {string} params.sitekey The hcaptcha site key. Value of `k` or `data-sitekey` parameter you found on page.
195
+ * @param {string} params.pageurl The URL the captcha appears on.
196
+ * @param {string} params.data Custom `data` that is used in some implementations of hCaptcha, mostly with `invisible=1`. In most cases you see it as `rqdata` inside network requests. IMPORTANT: you MUST provide `userAgent` if you submit captcha with `data` paramater. The value should match the User-Agent you use when interacting with the target website.
197
+ * @param {string} params.userAgent Your userAgent that will be passed to our worker and used to solve the captcha. Required for hCaptcha with `data` parameter.
198
+ * @param {number} params.invisible Use `1` for invisible version of hcaptcha. Currently it is a very rare case.
199
+ * @param {string} params.pingback URL for pingback (callback) response that will be sent when captcha is solved. URL should be registered on the server. More info [here](https://2captcha.com/2captcha-api#pingback).
200
+ * @param {string} params.proxy Format: `login:password@123.123.123.123:3128` You can find more info about proxies [here](https://2captcha.com/2captcha-api#proxies).
201
+ * @param {string} params.proxytype Type of your proxy: `HTTP`, `HTTPS`, `SOCKS4`, `SOCKS5`.
202
+ * @param {string} params.domain Domain used to load the captcha: `hcaptcha.com` or `js.hcaptcha.com`
203
+ *
204
+ * @returns {Promise<CaptchaAnswer>} The result from the solve
205
+ * @throws APIError
206
+ * @example
207
+ * solver.hcaptcha({
208
+ * pageurl: "https://2captcha.com/demo/hcaptcha",
209
+ * sitekey: "b76cd927-d266-4cfb-a328-3b03ae07ded6"
210
+ * .then((res) => {
211
+ * console.log(res);
212
+ * })
213
+ * .catch((err) => {
214
+ * console.log(err);
215
+ * })
216
+ */
217
+ async hcaptcha(params) {
218
+ (0, checkCaptchaParams_1.default)(params, "hcaptcha");
219
+ const payload = {
220
+ ...this.defaultPayload,
221
+ ...params,
222
+ method: "hcaptcha"
223
+ };
224
+ const response = await (0, fetch_1.default)(this.in + utils.objectToURI(payload));
225
+ const result = await response.text();
226
+ let data;
227
+ try {
228
+ data = JSON.parse(result);
229
+ }
230
+ catch {
231
+ throw new _2captchaError_1.APIError(result);
232
+ }
233
+ if (data.status == 1) {
234
+ return this.pollResponse(data.request);
235
+ }
236
+ else {
237
+ throw new _2captchaError_1.APIError(data.request);
238
+ }
239
+ }
240
+ /**
241
+ * ### Solves a GeeTest Captcha.
242
+ *
243
+ * [Read more about parameters and solving for Geetest captcha](https://2captcha.com/2captcha-api#solving_geetest).
244
+ *
245
+ * @param {{ gt, challenge, api_server, offline, new_captcha,
246
+ * pageurl, pingback, proxy, proxytype, userAgent }} params
247
+ * @param {string} params.gt Value of gt parameter found on site
248
+ * @param {string} params.challenge Value of challenge parameter found on site
249
+ * @param {string} params.pageurl The URL the captcha appears on
250
+ * @param {string} params.api_server The URL of the api_server (recommended)
251
+ * @param {number} params.offline In rare cases `initGeetest` can be called with `offline` parameter on the target page. If the call uses offline: true, set the value to `1`.
252
+ * @param {number} params.new_captcha In rare cases `initGeetest` can be called with `new_captcha` parameter. If the call uses `new_captcha: true`, set the value to `1`. Mostly used with offline parameter.
253
+ * @param {string} params.pingback URL for `pingback` (callback) response that will be sent when captcha is solved. [More info here](https://2captcha.com/2captcha-api#pingback).
254
+ * @param {string} params.proxy Format: `login:password@123.123.123.123:3128`. You can find more info about proxies [here](https://2captcha.com/2captcha-api#proxies).
255
+ * @param {string} params.proxytype Type of your proxy: `HTTP`, `HTTPS`, `SOCKS4`, `SOCKS5`.
256
+ * @param {string} params.userAgent Your `userAgent` that will be passed to our worker and used to solve the captcha.
257
+ *
258
+ * @returns {Promise<CaptchaAnswer>} The result from the solve.
259
+ * @throws APIError
260
+ * @example
261
+ * ;(async () => {
262
+ *
263
+ * // Warning: Attention, the `challenge` value is not static but dynamic.
264
+ * // You need to find the queries that makes the captcha on the page to API.
265
+ * // Then you need to make request to this API and get new `challenge`.
266
+ *
267
+ * // For page https://rucaptcha.com/demo/geetest, api address is https://rucaptcha.com/api/v1/captcha-demo/gee-test/init-params?t=${t}
268
+ * // Also note that when make request to API, the request uses the dynamic parameter `t`
269
+ *
270
+ * // You can read more about sending GeeTest here https://2captcha.com/2captcha-api#solving_geetest, or here https://2captcha.com/p/geetest
271
+ * // In this example I solve GeeTest from page https://2captcha.com/demo/geetest
272
+ *
273
+ * const t = new Date().getTime()
274
+ * // below i make a request to get a new `challenge`.
275
+ * const response = await fetch(`https://2captcha.com/api/v1/captcha-demo/gee-test/init-params?t=${t}`)
276
+ * const data = await response.json()
277
+ *
278
+ * const params = {
279
+ * pageurl: 'https://rucaptcha.com/demo/geetest',
280
+ * gt: data.gt,
281
+ * challenge: data.challenge
282
+ * }
283
+ *
284
+ * const res = await solver.geetest(params)
285
+ * try {
286
+ * console.log(res)
287
+ * } catch (error) {
288
+ * console.error(error);
289
+ * }
290
+ * })()
291
+ */
292
+ async geetest(params) {
293
+ (0, checkCaptchaParams_1.default)(params, "geetest");
294
+ const payload = {
295
+ ...this.defaultPayload,
296
+ ...params,
297
+ method: "geetest"
298
+ };
299
+ const response = await (0, fetch_1.default)(this.in + utils.objectToURI(payload));
300
+ const result = await response.text();
301
+ let data;
302
+ try {
303
+ data = JSON.parse(result);
304
+ }
305
+ catch {
306
+ throw new _2captchaError_1.APIError(result);
307
+ }
308
+ if (data.status == 1) {
309
+ return this.pollResponse(data.request);
310
+ }
311
+ else {
312
+ throw new _2captchaError_1.APIError(data.request);
313
+ }
314
+ }
315
+ /**
316
+ * ### Solves a GeeTest V4 Captcha.
317
+ *
318
+ * This method accepts an object with the following fields: `pageurl`, `captcha_id`, `pingback`, `proxy`, `proxytype`, `userAgent`.
319
+ * The `pageurl` and `captcha_id` fields are required.
320
+ *
321
+ * @param {{pageurl, captcha_id, pingback, proxy, proxytype, userAgent}} params The method geetestV4 takes arguments as an object.
322
+ * @param {string} params.pageurl Full URL of the page where you see Geetest V4 captcha.
323
+ * @param {string} params.captcha_id Required parameter. Value of `captcha_id` parameter you found on target website.
324
+ * @param {string} params.pingback An optional param. [More info here](https://2captcha.com/2captcha-api#pingback).
325
+ * @param {string} params.proxy An optional param. Format: `login:password@123.123.123.123:3128`. You can find more info about proxies [here](https://2captcha.com/2captcha-api#proxies).
326
+ * @param {string} params.proxytype An optional param. Type of your proxy: `HTTP`, `HTTPS`, `SOCKS4`, `SOCKS5`.
327
+ * @param {string} params.userAgent An optional param. Your `userAgent` that will be passed to our worker and used to solve the captcha.
328
+ *
329
+ * @returns {Promise<CaptchaAnswer>} The result from the solve.
330
+ * @throws APIError
331
+ * @example
332
+ * solver.geetestV4({
333
+ * pageurl: 'https://2captcha.com/demo/geetest-v4',
334
+ * captcha_id: 'e392e1d7fd421dc63325744d5a2b9c73'
335
+ * })
336
+ * .then((res) => {
337
+ * console.log(res)
338
+ * })
339
+ * .catch((err) => {
340
+ * console.log(err);
341
+ * })
342
+ */
343
+ async geetestV4(params) {
344
+ (0, checkCaptchaParams_1.default)(params, "geetest_v4");
345
+ const payload = {
346
+ ...params,
347
+ method: "geetest_v4",
348
+ ...this.defaultPayload
349
+ };
350
+ const response = await (0, fetch_1.default)(this.in + utils.objectToURI(payload));
351
+ const result = await response.text();
352
+ let data;
353
+ try {
354
+ data = JSON.parse(result);
355
+ }
356
+ catch {
357
+ throw new _2captchaError_1.APIError(result);
358
+ }
359
+ if (data.status == 1) {
360
+ return this.pollResponse(data.request);
361
+ }
362
+ else {
363
+ throw new _2captchaError_1.APIError(data.request);
364
+ }
365
+ }
366
+ /**
367
+ * ### Method for sending Yandex Smart Captcha.
368
+ *
369
+ * This method accepts an object with the following fields: `pageurl`, `sitekey`, `pingback`, `proxy`, `proxytype`.
370
+ * The `pageurl` and `sitekey` fields are required.
371
+ *
372
+ * @param {{pageurl, sitekey, pingback, proxy, proxytype, userAgent}} params The method takes arguments as an object.
373
+ * @param {string} params.pageurl Required parameter. URL of the page where the captcha is located.
374
+ * @param {string} params.sitekey Required parameter. The `sitekey` value you found on the captcha page.
375
+ * @param {string} params.pingback An optional param.
376
+ * @param {string} params.proxy An optional param. Format: `login:password@123.123.123.123:3128`.
377
+ * @param {string} params.proxytype An optional param. Type of your proxy: `HTTP`, `HTTPS`, `SOCKS4`, `SOCKS5`.
378
+ * @param {string} params.userAgent An optional param. Your `userAgent` that will be passed to our worker and used to solve the captcha.
379
+ *
380
+ * @returns {Promise<CaptchaAnswer>} The result from the solve.
381
+ * @throws APIError
382
+ * @example
383
+ * solver.yandexSmart({
384
+ * pageurl: "https://captcha-api.yandex.ru/demo",
385
+ * sitekey: "FEXfAbHQsToo97VidNVk3j4dC74nGW1DgdxjtNB9"
386
+ * })
387
+ * .then((res) => {
388
+ * console.log(res)
389
+ * })
390
+ * .catch((err) => {
391
+ * console.log(err);
392
+ * })
393
+ */
394
+ async yandexSmart(params) {
395
+ (0, checkCaptchaParams_1.default)(params, "yandex");
396
+ const payload = {
397
+ ...params,
398
+ method: "yandex",
399
+ ...this.defaultPayload
400
+ };
401
+ const response = await (0, fetch_1.default)(this.in + utils.objectToURI(payload));
402
+ const result = await response.text();
403
+ let data;
404
+ try {
405
+ data = JSON.parse(result);
406
+ }
407
+ catch {
408
+ throw new _2captchaError_1.APIError(result);
409
+ }
410
+ if (data.status == 1) {
411
+ return this.pollResponse(data.request);
412
+ }
413
+ else {
414
+ throw new _2captchaError_1.APIError(data.request);
415
+ }
416
+ }
417
+ /**
418
+ * ### Solves a image-based captcha.
419
+ *
420
+ * [Read more about parameters for image captcha](https://2captcha.com/2captcha-api#solving_normal_captcha).
421
+ *
422
+ * @param {{ body,
423
+ * phrase,
424
+ * regsense,
425
+ * numeric,
426
+ * calc,
427
+ * min_len,
428
+ * max_len,
429
+ * language,
430
+ * lang,
431
+ * textinstructions,
432
+ * pingback }} params Extra properties to pass to 2captcha.
433
+ * @param {string} params.body Base64 image data for the captcha.
434
+ * @param {number} params.phrase Captcha contains two or more words? `1` - Yes. `0` - No.
435
+ * @param {number} params.regsense Captcha is case sensitive? `1` - Yes. `0` - No.
436
+ * @param {number} params.numeric `0` - not specified. `1` - captcha contains only numbers. `2` - captcha contains only letters. `3` - captcha contains only numbers OR only letters. `4` - captcha MUST contain both numbers AND letters.
437
+ * @param {number} params.calc Does captcha require calculations? (e.g. type the result 4 + 8 = ) `1` - Yes. `0` - No.
438
+ * @param {number} params.min_len `1..20` - minimal number of symbols in captcha. `0` - not specified.
439
+ * @param {number} params.max_len `1..20` - maximal number of symbols in captcha. `0` - not specified.
440
+ * @param {number} params.language `0` - not specified. `1` - Cyrillic captcha. `2` - Latin captcha
441
+ * @param {string} params.lang Language code. [See the list of supported languages](https://2captcha.com/2captcha-api#language).
442
+ * @param {string} params.textinstructions Text will be shown to worker to help him to solve the captcha correctly. For example: type red symbols only.
443
+ * @param {string} params.pingback URL for `pingback` (callback) response that will be sent when captcha is solved. [More info here](https://2captcha.com/2captcha-api#pingback).
444
+ *
445
+ * @returns {Promise<CaptchaAnswer>} The result from the solve
446
+ * @throws APIError
447
+ * @example
448
+ * const imageBase64 = fs.readFileSync("./tests/media/imageCaptcha_6e584.png", "base64")
449
+ *
450
+ * solver.imageCaptcha({
451
+ * body: imageBase64,
452
+ * numeric: 4,
453
+ * min_len: 5,
454
+ * max_len: 5
455
+ * })
456
+ * .then((res) => {
457
+ * console.log(res);
458
+ * })
459
+ * .catch((err) => {
460
+ * console.log(err);
461
+ * })
462
+ */
463
+ async imageCaptcha(params) {
464
+ (0, checkCaptchaParams_1.default)(params, "base64");
465
+ const payload = {
466
+ ...this.defaultPayload,
467
+ ...params,
468
+ method: "base64"
469
+ };
470
+ const URL = this.in;
471
+ const response = await (0, fetch_1.default)(URL, {
472
+ body: JSON.stringify(payload),
473
+ method: "post",
474
+ headers: { 'Content-Type': 'application/json' }
475
+ });
476
+ const result = await response.text();
477
+ let data;
478
+ try {
479
+ data = JSON.parse(result);
480
+ }
481
+ catch {
482
+ throw new _2captchaError_1.APIError(result);
483
+ }
484
+ if (data.status == 1) {
485
+ return this.pollResponse(data.request);
486
+ }
487
+ else {
488
+ throw new _2captchaError_1.APIError(data.request);
489
+ }
490
+ }
491
+ /**
492
+ * ### Solves Arkose Labs FunCaptcha.
493
+ *
494
+ * [Read more](https://2captcha.com/2captcha-api#solving_funcaptcha_new) about other solving and other parameters for Arkose Labs FunCaptcha.
495
+ *
496
+ * @param {{pageurl, publicKey, surl, data, pingback, proxy, proxytype, userAgent}} params Object
497
+ * @param {string} params.publicKey The FunCaptcha Public Key
498
+ * @param {string} params.pageurl The URL to the website the captcha is seen on
499
+ * @param {string} params.surl The FunCaptcha Service URL (recommended)
500
+ * @param {string} params.data Custom data to pass to FunCaptcha. For example: `'data': '{"blob": "foo"}'`.
501
+ * @param {string} params.pingback URL for pingback (callback) response that will be sent when captcha is solved. URL should be registered on the server. [More info here](https://2captcha.com/2captcha-api#pingback).
502
+ * @param {string} params.proxy Format: `login:password@123.123.123.123:3128` You can find more info about proxies [here](https://2captcha.com/2captcha-api#proxies).
503
+ * @param {string} params.proxytype Type of your proxy: `HTTP`, `HTTPS`, `SOCKS4`, `SOCKS5`.
504
+ * @param {string} params.userAgent Your `userAgent` that will be passed to our worker and used to solve the captcha.
505
+ *
506
+ * @returns {Promise<CaptchaAnswer>} The result from the solve
507
+ * @throws APIError
508
+ *
509
+ * @example
510
+ * solver.funCaptcha({
511
+ * pageurl: "https://funcaptcha.com/tile-game-lite-mode/fc/api/nojs/?pkey=804380F4-6844-FFA1-ED4E-5877CA1F1EA4&lang=en",
512
+ * publickey: "804380F4-6844-FFA1-ED4E-5877CA1F1EA4"
513
+ * })
514
+ * .then((res) => {
515
+ * console.log(res);
516
+ * })
517
+ * .catch((err) => {
518
+ * console.log(err);
519
+ * })
520
+ */
521
+ async funCaptcha(params) {
522
+ (0, checkCaptchaParams_1.default)(params, "funcaptcha");
523
+ const payload = {
524
+ ...this.defaultPayload,
525
+ ...params,
526
+ method: "funcaptcha",
527
+ };
528
+ const response = await (0, fetch_1.default)(this.in + utils.objectToURI(payload));
529
+ const result = await response.text();
530
+ let data;
531
+ try {
532
+ data = JSON.parse(result);
533
+ }
534
+ catch {
535
+ throw new _2captchaError_1.APIError(result);
536
+ }
537
+ if (data.status == 1) {
538
+ return this.pollResponse(data.request);
539
+ }
540
+ else {
541
+ throw new _2captchaError_1.APIError(data.request);
542
+ }
543
+ }
544
+ /**
545
+ *
546
+ * ### Solves a Lemin captcha
547
+ *
548
+ * [Read more about other Lemin captcha parameters](https://2captcha.com/2captcha-api#lemin).
549
+ *
550
+ * @param {{ pageurl, captcha_id, div_id, api_server, pingback, proxy, proxytype}} params Object
551
+ * @param {string} params.pageurl The URL the captcha appears on.
552
+ * @param {string} params.captcha_id Value of `captcha_id` parameter you found on page.
553
+ * @param {string} params.div_id Value `id` of captcha pareent `<div></div>` element.
554
+ * @param {string} params.api_server The domain part of script URL you found on page. Default value: `https://api.leminnow.com/`
555
+ * @param {string} params.pingback URL for pingback (callback) response that will be sent when captcha is solved. URL should be registered on the server. [More info here](https://2captcha.com/2captcha-api#pingback).
556
+ * @param {string} params.proxy Format: `login:password@123.123.123.123:3128` You can find more info about proxies [here](https://2captcha.com/2captcha-api#proxies).
557
+ * @param {string} params.proxytype Type of your proxy: `HTTP`, `HTTPS`, `SOCKS4`, `SOCKS5`.
558
+ *
559
+ * @example
560
+ * solver.lemin({
561
+ * pageurl:'https://2captcha.com/demo/lemin',
562
+ * captcha_id: 'CROPPED_3dfdd5c_d1872b526b794d83ba3b365eb15a200b',
563
+ * div_id: 'lemin-cropped-captcha',
564
+ * api_server: 'api.leminnow.com'
565
+ * })
566
+ * .then((res) => {
567
+ * console.log(res);
568
+ * })
569
+ * .catch((err) => {
570
+ * console.log(err);
571
+ * })
572
+ */
573
+ async lemin(params) {
574
+ (0, checkCaptchaParams_1.default)(params, "lemin");
575
+ const payload = {
576
+ ...this.defaultPayload,
577
+ ...params,
578
+ method: "lemin",
579
+ };
580
+ const response = await (0, fetch_1.default)(this.in + utils.objectToURI(payload));
581
+ const result = await response.text();
582
+ let data;
583
+ try {
584
+ data = JSON.parse(result);
585
+ }
586
+ catch {
587
+ throw new _2captchaError_1.APIError(result);
588
+ }
589
+ if (data.status == 1) {
590
+ return this.pollResponse(data.request);
591
+ }
592
+ else {
593
+ throw new _2captchaError_1.APIError(data.request);
594
+ }
595
+ }
596
+ /**
597
+ *
598
+ * ### Solves Amazon WAF captcha
599
+ *
600
+ * [Read more about "Amazon WAF" captcha](https://2captcha.com/2captcha-api#amazon-waf).
601
+ *
602
+ * @param {{ pageurl, sitekey, iv, context, challenge_script, captcha_script, pingback, proxy, proxytype}} params The `amazonWaf` method takes arguments as an object. Thus, the `pageurl`, `sitekey`, `iv`, `context` fields in the passed object are mandatory.
603
+ * @param {string} params.pageurl Is the full `URL` of page where you were challenged by the captcha.
604
+ * @param {string} params.sitekey Is a value of `key` parameter in the page source.
605
+ * @param {string} params.iv Is a value of `iv` parameter in the page source.
606
+ * @param {string} params.context Is a value of `context` parameter in the page source.
607
+ * @param {string} params.challenge_script The source URL of `challenge.js` script on the page.
608
+ * @param {string} params.captcha_script The source URL of `captcha.js` script on the page.
609
+ * @param {string} params.pingback URL for pingback (callback) response that will be sent when captcha is solved. URL should be registered on the server. [More info here](https://2captcha.com/2captcha-api#pingback).
610
+ * @param {string} params.proxy Format: `login:password@123.123.123.123:3128` You can find more info about proxies [here](https://2captcha.com/2captcha-api#proxies).
611
+ * @param {string} params.proxytype Type of your proxy: `HTTP`, `HTTPS`, `SOCKS4`, `SOCKS5`.
612
+ *
613
+ * @example
614
+ * solver.amazonWaf({
615
+ * pageurl: "https://non-existent-example.execute-api.us-east-1.amazonaws.com/latest",
616
+ * sitekey: "AQIDAHjcYu/GjX+QlghicBgQ/7bFaQZ+m5FKCMDnO+vTbNg96AHMDLodoefdvyOnsHMRtEKQAAAAfjB8BgkqhkiG9w0BBwagbzBtAgEAMGgGCSqGSIb3DQEHATAeBglghkgBZQMEAS4wEQQMUX+ZqwwuANRnZujSAgEQgDvHSxUQmVBuyUtumoW2n4ccTG7xQN1r3X/zz41qmQaYv9SSSvQrjIoDXKaUQ23tVb4ii8+uljuRdz/HPA==",
617
+ * context: "9BUgmlm48F92WUoqv97a49ZuEJJ50TCk9MVr3C7WMtQ0X6flVbufM4n8mjFLmbLVAPgaQ1Jydeaja94iAS49ljb+sUNLoukWedAQZKrlY4RdbOOzvcFqmD/ZepQFS9N5w15Exr4VwnVq+HIxTsDJwRviElWCdzKDebN/mk8/eX2n7qJi5G3Riq0tdQw9+C4diFZU5E97RSeahejOAAJTDqduqW6uLw9NsjJBkDRBlRjxjn5CaMMo5pYOxYbGrM8Un1JH5DMOLeXbq1xWbC17YSEoM1cRFfTgOoc+VpCe36Ai9Kc=",
618
+ * iv: "CgAHbCe2GgAAAAAj",
619
+ * })
620
+ * .then((res) => {
621
+ * console.log(res);
622
+ * })
623
+ * .catch((err) => {
624
+ * console.log(err);
625
+ * })
626
+ */
627
+ async amazonWaf(params) {
628
+ (0, checkCaptchaParams_1.default)(params, "amazon_waf");
629
+ const payload = {
630
+ ...this.defaultPayload,
631
+ ...params,
632
+ method: "amazon_waf",
633
+ };
634
+ const response = await (0, fetch_1.default)(this.in + utils.objectToURI(payload));
635
+ const result = await response.text();
636
+ let data;
637
+ try {
638
+ data = JSON.parse(result);
639
+ }
640
+ catch {
641
+ throw new _2captchaError_1.APIError(result);
642
+ }
643
+ if (data.status == 1) {
644
+ return this.pollResponse(data.request);
645
+ }
646
+ else {
647
+ throw new _2captchaError_1.APIError(data.request);
648
+ }
649
+ }
650
+ /**
651
+ *
652
+ * ### Solves Cloudflare Turnstile captcha
653
+ *
654
+ * [Read more about Cloudflare Turnstile captcha](https://2captcha.com/2captcha-api#turnstile).
655
+ *
656
+ * @param {{ pageurl, sitekey, action, data, pingback, proxy, proxytype}} params The `cloudflareTurnstile` method takes arguments as an object. Thus, the `pageurl`, `sitekey` fields in the passed object are mandatory.
657
+ * @param {string} params.pageurl Full `URL` of the page where you see the captcha.
658
+ * @param {string} params.sitekey Is a value of `sitekey` parameter in the page source.
659
+ * @param {string} params.action Value of optional `action` parameter you found on page.
660
+ * @param {string} params.data Value of optional `data` parameter you found on page.
661
+ * @param {string} params.pingback URL for pingback (callback) response that will be sent when captcha is solved. URL should be registered on the server. [More info here](https://2captcha.com/2captcha-api#pingback).
662
+ * @param {string} params.proxy Format: `login:password@123.123.123.123:3128` You can find more info about proxies [here](https://2captcha.com/2captcha-api#proxies).
663
+ * @param {string} params.proxytype Type of your proxy: `HTTP`, `HTTPS`, `SOCKS4`, `SOCKS5`.
664
+ *
665
+ * @example
666
+ * solver.cloudflareTurnstile({
667
+ * pageurl: "https://app.nodecraft.com/login",
668
+ * sitekey: "0x4AAAAAAAAkg0s3VIOD10y4"
669
+ * })
670
+ * .then((res) => {
671
+ * console.log(res);
672
+ * })
673
+ * .catch((err) => {
674
+ * console.log(err);
675
+ * })
676
+ */
677
+ async cloudflareTurnstile(params) {
678
+ (0, checkCaptchaParams_1.default)(params, "turnstile");
679
+ const payload = {
680
+ ...this.defaultPayload,
681
+ ...params,
682
+ method: "turnstile",
683
+ };
684
+ const response = await (0, fetch_1.default)(this.in + utils.objectToURI(payload));
685
+ const result = await response.text();
686
+ let data;
687
+ try {
688
+ data = JSON.parse(result);
689
+ }
690
+ catch {
691
+ throw new _2captchaError_1.APIError(result);
692
+ }
693
+ if (data.status == 1) {
694
+ return this.pollResponse(data.request);
695
+ }
696
+ else {
697
+ throw new _2captchaError_1.APIError(data.request);
698
+ }
699
+ }
700
+ /**
701
+ * ### Solves a Coordinates captcha.
702
+ *
703
+ * @param {{ body, imginstructions, textinstructions, language, lang, pingback }} params parameters Coordinates Captcha as an object.
704
+ * @param {string} params.body Base64-encoded captcha image.
705
+ * @param {string} params.imginstructions Base64-encoded image with instruction for solving captcha.
706
+ * @param {string} params.textinstructions Text will be shown to worker to help him to solve the captcha correctly. For example: click on all objects in red color.
707
+ * @param {number} params.language `0` - not specified. `1` - Cyrillic captcha. `2` - Latin captcha
708
+ * @param {string} params.lang Language code. [See the list of supported languages](https://2captcha.com/2captcha-api#language).
709
+ * @param {string} params.pingback URL for `pingback` (callback) response that will be sent when captcha is solved. [More info here](https://2captcha.com/2captcha-api#pingback).
710
+ *
711
+ * @returns {Promise<CaptchaAnswer>} The result from the solve
712
+ *
713
+ * @example
714
+ * const imageBase64 = fs.readFileSync("./tests/media/hCaptchaImage.jpg", "base64")
715
+ *
716
+ * solver.coordinates({
717
+ * body: imageBase64,
718
+ * textinstructions: 'Select all photos containing the boat'
719
+ * })
720
+ * .then((res) => {
721
+ * console.log(res);
722
+ * })
723
+ * .catch((err) => {
724
+ * console.log(err);
725
+ * })
726
+ */
727
+ async coordinates(params) {
728
+ (0, checkCaptchaParams_1.default)(params, "base64");
729
+ const payload = {
730
+ ...this.defaultPayload,
731
+ ...params,
732
+ method: "base64",
733
+ coordinatescaptcha: 1,
734
+ };
735
+ const URL = this.in;
736
+ const response = await (0, fetch_1.default)(URL, {
737
+ method: 'post',
738
+ body: JSON.stringify(payload),
739
+ headers: { 'Content-Type': 'application/json' }
740
+ });
741
+ const result = await response.text();
742
+ let data;
743
+ try {
744
+ data = JSON.parse(result);
745
+ }
746
+ catch {
747
+ throw new _2captchaError_1.APIError(result);
748
+ }
749
+ if (data.status == 1) {
750
+ return this.pollResponse(data.request);
751
+ }
752
+ else {
753
+ throw new _2captchaError_1.APIError(data.request);
754
+ }
755
+ }
756
+ /**
757
+ * ### Solves Capy Puzzle captcha
758
+ *
759
+ * @param {{ pageurl, captchakey, api_server, version, pingback, proxy, proxytype}} params Parameters Capy Puzzle Captcha as an object.
760
+ * @param {string} params.pageurl Full `URL`of the page where you see the captcha.
761
+ * @param {string} params.captchakey Value of `captchakey` parameter you found on page.
762
+ * @param {string} params.api_server The domain part of script URL you found on page. Default value: `https://jp.api.capy.me/`.
763
+ * @param {string} params.version The version of captcha task: `puzzle` (assemble a puzzle) or `avatar` (drag an object)..
764
+ * @param {string} params.pingback URL for pingback (callback) response that will be sent when captcha is solved. URL should be registered on the server. [More info here](https://2captcha.com/2captcha-api#pingback).
765
+ * @param {string} params.proxy Format: `login:password@123.123.123.123:3128` You can find more info about proxies [here](https://2captcha.com/2captcha-api#proxies).
766
+ * @param {string} params.proxytype Type of your proxy: `HTTP`, `HTTPS`, `SOCKS4`, `SOCKS5`.
767
+ *
768
+ * @example
769
+ * solver.capyPuzzle({
770
+ * pageurl: "https://www.capy.me/account/register/",
771
+ * captchakey: "PUZZLE_Cme4hZLjuZRMYC3uh14C52D3uNms5w"
772
+ * })
773
+ * .then((res) => {
774
+ * console.log(res);
775
+ * })
776
+ * .catch((err) => {
777
+ * console.log(err);
778
+ * })
779
+ */
780
+ async capyPuzzle(params) {
781
+ (0, checkCaptchaParams_1.default)(params, "capy");
782
+ const payload = {
783
+ ...this.defaultPayload,
784
+ ...params,
785
+ method: "capy",
786
+ };
787
+ const response = await (0, fetch_1.default)(this.in + utils.objectToURI(payload));
788
+ const result = await response.text();
789
+ let data;
790
+ try {
791
+ data = JSON.parse(result);
792
+ }
793
+ catch {
794
+ throw new _2captchaError_1.APIError(result);
795
+ }
796
+ if (data.status == 1) {
797
+ return this.pollResponse(data.request);
798
+ }
799
+ else {
800
+ throw new _2captchaError_1.APIError(data.request);
801
+ }
802
+ }
803
+ /**
804
+ * ### Solves DataDome captcha
805
+ *
806
+ * @param {{ pageurl, captcha_url, userAgent, pingback, proxy, proxytype}} params Parameters DataDome Captcha as an object.
807
+ * @param {string} params.pageurl Full `URL` of the page where you see the captcha.
808
+ * @param {string} params.captcha_url The value of the `src` parameter for the `iframe` element containing the captcha on the page.
809
+ * @param {string} params.userAgent ser-Agent of your MODERN browser
810
+ * @param {string} params.pingback URL for pingback (callback) response that will be sent when captcha is solved. URL should be registered on the server. [More info here](https://2captcha.com/2captcha-api#pingback).
811
+ * @param {string} params.proxy Format: `login:password@123.123.123.123:3128` You can find more info about proxies [here](https://2captcha.com/2captcha-api#proxies).
812
+ * @param {string} params.proxytype Type of your proxy: `HTTP`, `HTTPS`, `SOCKS4`, `SOCKS5`.
813
+ *
814
+ * @example
815
+ * solver.dataDome({
816
+ * pageurl: "https://rendezvousparis.hermes.com/client/register",
817
+ * captcha_url: "https://geo.captcha-delivery.com/captcha/?initialCid=AHrlqAAAAAMAEuQtkf4k1c0ABZhYZA%3D%3D&hash=789361B674144528D0B7EE76B35826&cid=mY4z7GNmh7Nt1lAFwpbNHAOcWPhyPgjHD2K1Pm~Od1iEKYLUnK3t7N2ZGUj8OqDK65cnwJHtHwd~t902vlwpSBA5l4ZHbS1Qszv~jEuEUJNQ_jMAjar2Kj3kq20MRJYh&t=fe&referer=https%3A%2F%2Frendezvousparis.hermes.com%2Fclient%2Fregister&s=40119&e=67fef144ac1a54dbd7507776367d2f9d5e36ec3add17fa22f3cb881db8385838",
818
+ * userAgent: "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/118.0.0.0 Safari/537.36",
819
+ * proxy: "1.2.3.4:8888:user:password",
820
+ * proxytype: "http"
821
+ * })
822
+ * .then((res) => {
823
+ * console.log(res);
824
+ * })
825
+ * .catch((err) => {
826
+ * console.log(err);
827
+ * })
828
+ */
829
+ async dataDome(params) {
830
+ (0, checkCaptchaParams_1.default)(params, "datadome");
831
+ const payload = {
832
+ ...params,
833
+ method: "datadome",
834
+ ...this.defaultPayload,
835
+ };
836
+ const response = await (0, fetch_1.default)(this.in + utils.objectToURI(payload));
837
+ const result = await response.text();
838
+ let data;
839
+ try {
840
+ data = JSON.parse(result);
841
+ }
842
+ catch {
843
+ throw new _2captchaError_1.APIError(result);
844
+ }
845
+ if (data.status == 1) {
846
+ return this.pollResponse(data.request);
847
+ }
848
+ else {
849
+ throw new _2captchaError_1.APIError(data.request);
850
+ }
851
+ }
852
+ /**
853
+ * ### Solves CyberSiARA captcha
854
+ *
855
+ * @param {{ pageurl, master_url_id, userAgent, pingback, proxy, proxytype}} params Parameters CyberSiARA Captcha as an object.
856
+ * @param {string} params.pageurl Full `URL` of the page where you see the captcha.
857
+ * @param {string} params.master_url_id The value of `MasterUrlId` parameter obtained from the request to the endpoint `API/CyberSiara/GetCyberSiara`.
858
+ * @param {string} params.userAgent ser-Agent of your MODERN browser
859
+ * @param {string} params.pingback URL for pingback (callback) response that will be sent when captcha is solved. URL should be registered on the server. [More info here](https://2captcha.com/2captcha-api#pingback).
860
+ * @param {string} params.proxy Format: `login:password@123.123.123.123:3128` You can find more info about proxies [here](https://2captcha.com/2captcha-api#proxies).
861
+ * @param {string} params.proxytype Type of your proxy: `HTTP`, `HTTPS`, `SOCKS4`, `SOCKS5`.
862
+ *
863
+ * @example
864
+ * solver.cyberSiARA({
865
+ * pageurl: "https://www.cybersiara.com/book-a-demo",
866
+ * master_url_id: "OXR2LVNvCuXykkZbB8KZIfh162sNT8S2",
867
+ * userAgent: "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/118.0.0.0 Safari/537.36"
868
+ * })
869
+ * .then((res) => {
870
+ * console.log(res);
871
+ * })
872
+ * .catch((err) => {
873
+ * console.log(err);
874
+ * })
875
+ */
876
+ async cyberSiARA(params) {
877
+ (0, checkCaptchaParams_1.default)(params, "cybersiara");
878
+ const payload = {
879
+ ...this.defaultPayload,
880
+ ...params,
881
+ method: "cybersiara",
882
+ };
883
+ const response = await (0, fetch_1.default)(this.in + utils.objectToURI(payload));
884
+ const result = await response.text();
885
+ let data;
886
+ try {
887
+ data = JSON.parse(result);
888
+ }
889
+ catch {
890
+ throw new _2captchaError_1.APIError(result);
891
+ }
892
+ if (data.status == 1) {
893
+ return this.pollResponse(data.request);
894
+ }
895
+ else {
896
+ throw new _2captchaError_1.APIError(data.request);
897
+ }
898
+ }
899
+ /**
900
+ * ### Solves MTCaptcha
901
+ *
902
+ * @param {{ pageurl, sitekey, userAgent, pingback, proxy, proxytype}} params Parameters MTCaptcha as an object.
903
+ * @param {string} params.pageurl Full `URL` of the page where you see the captcha.
904
+ * @param {string} params.sitekey TThe value of `sitekey` parameter found on the page.
905
+ * @param {string} params.pingback URL for pingback (callback) response that will be sent when captcha is solved. URL should be registered on the server. [More info here](https://2captcha.com/2captcha-api#pingback).
906
+ * @param {string} params.proxy Format: `login:password@123.123.123.123:3128` You can find more info about proxies [here](https://2captcha.com/2captcha-api#proxies).
907
+ * @param {string} params.proxytype Type of your proxy: `HTTP`, `HTTPS`, `SOCKS4`, `SOCKS5`.
908
+ *
909
+ * @example
910
+ * solver.mtCaptcha({
911
+ * pageurl: "https://service.mtcaptcha.com/mtcv1/demo/index.html",
912
+ * sitekey: "MTPublic-DemoKey9M"
913
+ * })
914
+ * .then((res) => {
915
+ * console.log(res);
916
+ * })
917
+ * .catch((err) => {
918
+ * console.log(err);
919
+ * })
920
+ */
921
+ async mtCaptcha(params) {
922
+ (0, checkCaptchaParams_1.default)(params, "mt_captcha");
923
+ const payload = {
924
+ ...this.defaultPayload,
925
+ ...params,
926
+ method: "mt_captcha",
927
+ };
928
+ const response = await (0, fetch_1.default)(this.in + utils.objectToURI(payload));
929
+ const result = await response.text();
930
+ let data;
931
+ try {
932
+ data = JSON.parse(result);
933
+ }
934
+ catch {
935
+ throw new _2captchaError_1.APIError(result);
936
+ }
937
+ if (data.status == 1) {
938
+ return this.pollResponse(data.request);
939
+ }
940
+ else {
941
+ throw new _2captchaError_1.APIError(data.request);
942
+ }
943
+ }
944
+ /**
945
+ * ### Solves a Cutcaptcha.
946
+ *
947
+ * Use this method to solve Cutcaptcha. Returns the response in JSON.
948
+ * [Read more about Cutcaptcha Method](https://2captcha.com/2captcha-api#cutcaptcha).
949
+ *
950
+ * @param {{ pageurl, miseryKey, apiKey, pingback, proxy, proxytype }} params Parameters for solving Cutcaptcha as an object.
951
+ * @param {string} params.pageurl The URL where the captcha is located.
952
+ * @param {string} params.miseryKey The value of `CUTCAPTCHA_MISERY_KEY` variable defined on page.
953
+ * @param {string} params.apiKey The value of `data-apikey` attribute of iframe's body. Also the name of javascript file included on the page
954
+ * @param {string} [params.pingback] Optional param. URL for pingback (callback) response when captcha is solved.
955
+ * @param {string} [params.proxy] Optional param. Proxy to use while solving the captcha. Format: `login:password@123.123.123.123:3128`.
956
+ * @param {string} [params.proxytype] Optional param. Type of your proxy: `HTTP`, `HTTPS`, `SOCKS4`, `SOCKS5`.
957
+ *
958
+ * @returns {Promise<CaptchaAnswer>} The result from the solve.
959
+ * @throws APIError
960
+ *
961
+ * @example
962
+ * solver.cutCaptcha({
963
+ * pageurl: "https://mysite.com/page/with/cutcaptcha",
964
+ * miseryKey: "098e6a849af406142e3150dbf4e6d0538db2b51f",
965
+ * apiKey: "SAs61IAI",
966
+ * })
967
+ * .then((res) => {
968
+ * console.log(res);
969
+ * })
970
+ * .catch((err) => {
971
+ * console.log(err);
972
+ * })
973
+ */
974
+ async cutCaptcha(params) {
975
+ params = (0, renameParams_1.default)(params);
976
+ (0, checkCaptchaParams_1.default)(params, "cutcaptcha");
977
+ const payload = {
978
+ ...this.defaultPayload,
979
+ ...params,
980
+ method: "cutcaptcha",
981
+ };
982
+ const URL = this.in;
983
+ const response = await (0, fetch_1.default)(URL, {
984
+ body: JSON.stringify(payload),
985
+ method: "post",
986
+ headers: { 'Content-Type': 'application/json' }
987
+ });
988
+ const result = await response.text();
989
+ let data;
990
+ try {
991
+ data = JSON.parse(result);
992
+ }
993
+ catch {
994
+ throw new _2captchaError_1.APIError(result);
995
+ }
996
+ if (data.status == 1) {
997
+ return this.pollResponse(data.request);
998
+ }
999
+ else {
1000
+ throw new _2captchaError_1.APIError(data.request);
1001
+ }
1002
+ }
1003
+ /**
1004
+ * ### Solves Friendly Captcha
1005
+ *
1006
+ * @param {{ pageurl, sitekey, pingback, proxy, proxytype}} params Parameters Friendly Captcha as an object.
1007
+ * @param {string} params.pageurl Full `URL` of the page where you see the captcha.
1008
+ * @param {string} params.sitekey The value of `data-apikey` or `data-sitekey` parameter found on the page.
1009
+ * @param {string} params.pingback URL for pingback (callback) response that will be sent when captcha is solved. URL should be registered on the server. [More info here](https://2captcha.com/2captcha-api#pingback).
1010
+ * @param {string} params.proxy Format: `login:password@123.123.123.123:3128` You can find more info about proxies [here](https://2captcha.com/2captcha-api#proxies).
1011
+ * @param {string} params.proxytype Type of your proxy: `HTTP`, `HTTPS`, `SOCKS4`, `SOCKS5`.
1012
+ *
1013
+ * @example
1014
+ * solver.friendlyCaptcha({
1015
+ * pageurl: "https://geizhals.de/?liftban=1&from=/455973138?fsean=5901747021356",
1016
+ * sitekey: "FCMST5VUMCBOCGQ9"
1017
+ * })
1018
+ * .then((res) => {
1019
+ * console.log(res);
1020
+ * })
1021
+ * .catch((err) => {
1022
+ * console.log(err);
1023
+ * })
1024
+ */
1025
+ async friendlyCaptcha(params) {
1026
+ (0, checkCaptchaParams_1.default)(params, "friendly_captcha");
1027
+ const payload = {
1028
+ ...this.defaultPayload,
1029
+ ...params,
1030
+ method: "friendly_captcha",
1031
+ };
1032
+ const response = await (0, fetch_1.default)(this.in + utils.objectToURI(payload));
1033
+ const result = await response.text();
1034
+ let data;
1035
+ try {
1036
+ data = JSON.parse(result);
1037
+ }
1038
+ catch {
1039
+ throw new _2captchaError_1.APIError(result);
1040
+ }
1041
+ if (data.status == 1) {
1042
+ return this.pollResponse(data.request);
1043
+ }
1044
+ else {
1045
+ throw new _2captchaError_1.APIError(data.request);
1046
+ }
1047
+ }
1048
+ /**
1049
+ * ### Bounding Box Method
1050
+ *
1051
+ * @param {{ image, textinstructions, imginstructions }} params Parameters Bounding Box Method as an object.
1052
+ * @param {string} params.image Image containing data for markup. The image must be encoded in `Base64` format.
1053
+ * @param {string} params.textinstructions Text will be shown to worker to help him to select object on the image correctly. For example: "*Select cars in the image*". **Optional parameter**, if the instruction already exists in the form of the `imginstructions`.
1054
+ * @param {string} params.imginstructions Image with instruction for worker to help him to select object on the image correctly. The image must be encoded in `Base64` format. **Optional parameter**, if the instruction already exists in the form of the `textinstructions`.
1055
+ *
1056
+ * @example
1057
+ * solver.boundingBox({
1058
+ * image: "data:image/jpeg;base64,/9j/4AAQSkZJRgABAQAAAQABAAD/2wBDAAgG...",
1059
+ * textinstructions: "Select cars in the image"
1060
+ * })
1061
+ * .then((res) => {
1062
+ * console.log(res);
1063
+ * })
1064
+ * .catch((err) => {
1065
+ * console.log(err);
1066
+ * })
1067
+ */
1068
+ async boundingBox(params) {
1069
+ (0, checkCaptchaParams_1.default)(params, "bounding_box");
1070
+ const payload = {
1071
+ ...this.defaultPayload,
1072
+ ...params,
1073
+ method: "bounding_box",
1074
+ };
1075
+ const URL = this.in;
1076
+ const response = await (0, fetch_1.default)(URL, {
1077
+ body: JSON.stringify(payload),
1078
+ method: "post",
1079
+ headers: { 'Content-Type': 'application/json' }
1080
+ });
1081
+ const result = await response.text();
1082
+ let data;
1083
+ try {
1084
+ data = JSON.parse(result);
1085
+ }
1086
+ catch {
1087
+ throw new _2captchaError_1.APIError(result);
1088
+ }
1089
+ if (data.status == 1) {
1090
+ return this.pollResponse(data.request);
1091
+ }
1092
+ else {
1093
+ throw new _2captchaError_1.APIError(data.request);
1094
+ }
1095
+ }
1096
+ /**
1097
+ * ### Grid method
1098
+ *
1099
+ * The method can be used to bypass tasks where a grid is applied to an image and you need to click on grid tiles, like reCAPTCHA or hCaptcha images.
1100
+ *
1101
+ * @param {{ body, textinstructions, imginstructions, rows, cols, minClicks, maxClicks, imgType, previousId, canSkip, lang, pingback}} params Parameters Grid Method as an object.
1102
+ * @param {string} params.body `Base64`- encoded captcha image.
1103
+ * @param {string} params.textinstructions Text will be shown to worker to help him to select object on the image correctly. For example: "*Select cars in the image*". **Optional parameter**, if the instruction already exists in the form of the `imginstructions`.
1104
+ * @param {string} params.imginstructions Image with instruction for worker to help him to select object on the image correctly. The image must be encoded in `Base64` format. **Optional parameter**, if the instruction already exists in the form of the `textinstructions`.
1105
+ * @param {number} params.rows Number of rows in grid captcha.
1106
+ * @param {number} params.cols Number of columns in grid captcdha.
1107
+ * @param {number} params.minClicks The minimum number of tiles that must be selected. Can't be more than `rows` * `cols`.
1108
+ * @param {number} params.maxClicks The maximum number of tiles that can be selected on the image.
1109
+ * @param {string} params.imgType The image will be recognized using Computer Vision. Supported value options: `recaptcha`, `hcaptcha`, `funcaptcha`, `funcaptcha_compare`. [More info here](https://2captcha.com/2captcha-api#grid).
1110
+ * @param {string} params.previousId Id of your previous request with the same captcha challenge.
1111
+ * @param {number} params.canSkip Set the value to `1` only if it's possible that there's no images matching to the instruction. We'll provide a button "No matching images" to worker and you will receive `No_matching_images` as answer.
1112
+ * @param {string} params.lang Language code. [See the list of supported languages](https://2captcha.com/2captcha-api#language).
1113
+ * @param {string} params.pingback params.pingback URL for pingback (callback) response that will be sent when captcha is solved. URL should be registered on the server. [More info here](https://2captcha.com/2captcha-api#pingback).
1114
+ *
1115
+ * @example
1116
+ * solver.grid({
1117
+ * body: 'iVBORw0KGgoAAAANSUhEUgAAAcIA...',
1118
+ * textinstructions: "Select cars in the image",
1119
+ * imginstructions: '/9j/4AAQSkZJRgABAQEA...'
1120
+ * })
1121
+ * .then((res) => {
1122
+ * console.log(res);
1123
+ * })
1124
+ * .catch((err) => {
1125
+ * console.log(err);
1126
+ * })
1127
+ */
1128
+ async grid(params) {
1129
+ (0, checkCaptchaParams_1.default)(params, "grid");
1130
+ params = await (0, renameParams_1.default)(params);
1131
+ const payload = {
1132
+ ...this.defaultPayload,
1133
+ ...params,
1134
+ method: "base64",
1135
+ recaptcha: 1,
1136
+ };
1137
+ const URL = this.in;
1138
+ const response = await (0, fetch_1.default)(URL, {
1139
+ body: JSON.stringify(payload),
1140
+ method: "post",
1141
+ headers: { 'Content-Type': 'application/json' }
1142
+ });
1143
+ const result = await response.text();
1144
+ let data;
1145
+ try {
1146
+ data = JSON.parse(result);
1147
+ }
1148
+ catch {
1149
+ throw new _2captchaError_1.APIError(result);
1150
+ }
1151
+ if (data.status == 1) {
1152
+ return this.pollResponse(data.request);
1153
+ }
1154
+ else {
1155
+ throw new _2captchaError_1.APIError(data.request);
1156
+ }
1157
+ }
1158
+ /**
1159
+ * ### Text Captcha method
1160
+ *
1161
+ * Text Captcha is a type of captcha that is represented as text and doesn't contain images. Usually you have to answer a question to pass the verification. For example: "If tomorrow is Saturday, what day is today?".
1162
+ * [Read more about Text Captcha Method](https://2captcha.com/2captcha-api#text-captcha).
1163
+ *
1164
+ * @param {{ textcaptcha, lang, pingback}} params Parameters Text Captcha Method as an object.
1165
+ * @param {string} params.textcaptcha Text Captcha is a type of captcha that is represented as text and doesn't contain images. Usually you have to answer a question to pass the verification.
1166
+ * @param {string} params.lang Language code. [See the list of supported languages](https://2captcha.com/2captcha-api#language).
1167
+ * @param {string} params.pingback params.pingback URL for pingback (callback) response that will be sent when captcha is solved. URL should be registered on the server. [More info here](https://2captcha.com/2captcha-api#pingback).
1168
+ *
1169
+ * @example
1170
+ * solver.text({
1171
+ * textcaptcha: "If tomorrow is Saturday, what day is today?",
1172
+ * lang: 'en'
1173
+ * })
1174
+ * .then((res) => {
1175
+ * console.log(res);
1176
+ * })
1177
+ * .catch((err) => {
1178
+ * console.log(err);
1179
+ * })
1180
+ */
1181
+ async text(params) {
1182
+ (0, checkCaptchaParams_1.default)(params, "textcaptcha");
1183
+ params = await (0, renameParams_1.default)(params);
1184
+ const payload = {
1185
+ ...this.defaultPayload,
1186
+ ...params,
1187
+ };
1188
+ const URL = this.in;
1189
+ const response = await (0, fetch_1.default)(URL, {
1190
+ body: JSON.stringify(payload),
1191
+ method: "post",
1192
+ headers: { 'Content-Type': 'application/json' }
1193
+ });
1194
+ const result = await response.text();
1195
+ let data;
1196
+ try {
1197
+ data = JSON.parse(result);
1198
+ }
1199
+ catch {
1200
+ throw new _2captchaError_1.APIError(result);
1201
+ }
1202
+ if (data.status == 1) {
1203
+ return this.pollResponse(data.request);
1204
+ }
1205
+ else {
1206
+ throw new _2captchaError_1.APIError(data.request);
1207
+ }
1208
+ }
1209
+ /**
1210
+ * ### Canvas method
1211
+ *
1212
+ * This method can be used to bypass tasks in which you need to circle an object or line in an image.
1213
+ * [Read more about Canvas Method](https://2captcha.com/2captcha-api#canvas).
1214
+ *
1215
+ * @param {{ body, textinstructions, imginstructions, canSkip, lang, pingback}} params Parameters Canvas as an object.
1216
+ * @param {string} params.body `Base64`- encoded captcha image.
1217
+ * @param {string} params.textinstructions Text will be shown to worker to help him to select object on the image correctly. For example: "*Select cars in the image*". **Optional parameter**, if the instruction already exists in the form of the `imginstructions`.
1218
+ * @param {string} params.imginstructions Image with instruction for worker to help him to select object on the image correctly. The image must be encoded in `Base64` format. **Optional parameter**, if the instruction already exists in the form of the `textinstructions`.
1219
+ * @param {number} params.canSkip Set the value to `1` only if it's possible that there's no images matching to the instruction. We'll provide a button "No matching images" to worker and you will receive `No_matching_images` as answer.
1220
+ * @param {string} params.lang Language code. [See the list of supported languages](https://2captcha.com/2captcha-api#language).
1221
+ * @param {string} params.pingback params.pingback URL for pingback (callback) response that will be sent when captcha is solved. URL should be registered on the server. [More info here](https://2captcha.com/2captcha-api#pingback).
1222
+ *
1223
+ * @example
1224
+ * solver.canvas({
1225
+ * body: 'iVBORw0KGgoAAAANSgAAAcIA...',
1226
+ * imginstructions: '/9j/4AAQSkZJRgABAQEA...',
1227
+ * textinstructions: 'Highlight the red CIRCLE'
1228
+ * })
1229
+ * .then((res) => {
1230
+ * console.log(res);
1231
+ * })
1232
+ * .catch((err) => {
1233
+ * console.log(err);
1234
+ * })
1235
+ */
1236
+ async canvas(params) {
1237
+ (0, checkCaptchaParams_1.default)(params, "canvas");
1238
+ params = await (0, renameParams_1.default)(params);
1239
+ const payload = {
1240
+ ...this.defaultPayload,
1241
+ ...params,
1242
+ recaptcha: 1,
1243
+ canvas: 1,
1244
+ method: "base64",
1245
+ };
1246
+ const URL = this.in;
1247
+ const response = await (0, fetch_1.default)(URL, {
1248
+ body: JSON.stringify(payload),
1249
+ method: "post",
1250
+ headers: { 'Content-Type': 'application/json' }
1251
+ });
1252
+ const result = await response.text();
1253
+ let data;
1254
+ try {
1255
+ data = JSON.parse(result);
1256
+ }
1257
+ catch {
1258
+ throw new _2captchaError_1.APIError(result);
1259
+ }
1260
+ if (data.status == 1) {
1261
+ return this.pollResponse(data.request);
1262
+ }
1263
+ else {
1264
+ throw new _2captchaError_1.APIError(data.request);
1265
+ }
1266
+ }
1267
+ /**
1268
+ * ### Rotate method
1269
+ *
1270
+ * This method can be used to solve a captcha that asks to rotate an object. It is mostly used to bypass FunCaptcha. Returns the rotation angle.
1271
+ * [Read more about Rotate Method](https://2captcha.com/2captcha-api#solving_rotatecaptcha).
1272
+ *
1273
+ * @param {{ body, angle, pingback, lang, textinstructions, imginstructions }} params Parameters for solving Rotate Captcha as an object.
1274
+ * @param {string} params.body Base64-encoded image of the captcha that needs to be rotated.
1275
+ * @param {number} params.angle Angle to which the captcha needs to be rotated to solve it correctly. Value between `0` to `360`.
1276
+ * @param {string} params.textinstructions Optional param. Text instruction that will be shown to worker to help solve the captcha correctly.
1277
+ * @param {string} params.imginstructions Optional param. Base64-encoded image instruction that will be shown to worker to help solve the captcha correctly.
1278
+ * @param {string} params.lang Optional param. Language code for worker to use while solving the captcha.
1279
+ * @param {string} params.pingback Optional param. URL for pingback (callback) response when captcha is solved.
1280
+ *
1281
+ * @returns {Promise<CaptchaAnswer>} The result from the solve.
1282
+ * @throws APIError
1283
+ *
1284
+ * @example
1285
+ * solver.rotate({
1286
+ * body: "iVBORw0KGgoAAAANSUhEUgAAAcIA...",
1287
+ * angle: 15,
1288
+ * textinstructions: "Rotate the object to the correct position"
1289
+ * })
1290
+ * .then((res) => {
1291
+ * console.log(res);
1292
+ * })
1293
+ * .catch((err) => {
1294
+ * console.log(err);
1295
+ * })
1296
+ */
1297
+ async rotate(params) {
1298
+ (0, checkCaptchaParams_1.default)(params, "rotatecaptcha");
1299
+ const payload = {
1300
+ ...this.defaultPayload,
1301
+ ...params,
1302
+ method: "rotatecaptcha",
1303
+ };
1304
+ const URL = this.in;
1305
+ const response = await (0, fetch_1.default)(URL, {
1306
+ body: JSON.stringify(payload),
1307
+ method: "post",
1308
+ headers: { 'Content-Type': 'application/json' }
1309
+ });
1310
+ const result = await response.text();
1311
+ let data;
1312
+ try {
1313
+ data = JSON.parse(result);
1314
+ }
1315
+ catch {
1316
+ throw new _2captchaError_1.APIError(result);
1317
+ }
1318
+ if (data.status == 1) {
1319
+ return this.pollResponse(data.request);
1320
+ }
1321
+ else {
1322
+ throw new _2captchaError_1.APIError(data.request);
1323
+ }
1324
+ }
1325
+ /**
1326
+ * ### Solves a KeyCaptcha.
1327
+ *
1328
+ * This method can be used to solve a KeyCaptcha. It is mostly used to bypass captchas that use KeyCaptcha technology.
1329
+ * [Read more about KeyCaptcha Method](https://2captcha.com/2captcha-api#solving_keycaptcha).
1330
+ *
1331
+ * @param {{ pageurl, userId, sessionId, webServerSign, webServerSign2, pingback, proxy, proxytype }} params Parameters for solving KeyCaptcha as an object.
1332
+ * @param {string} params.pageurl The URL where the captcha is located.
1333
+ * @param {string} params.userId Value of `s_s_c_user_id` parameter you found on page.
1334
+ * @param {string} params.sessionId Value of `s_s_c_session_id` parameter you found on page.
1335
+ * @param {string} params.webServerSign Value of `s_s_c_web_server_sign` parameter you found on page.
1336
+ * @param {string} params.webServerSign2 Value of `s_s_c_web_server_sign2` parameter you found on page.
1337
+ * @param {string} [params.pingback] Optional param. URL for pingback (callback) response when captcha is solved.
1338
+ * @param {string} [params.proxy] Optional param. Proxy to use while solving the captcha. Format: `login:password@123.123.123.123:3128`.
1339
+ * @param {string} [params.proxytype] Optional param. Type of your proxy: `HTTP`, `HTTPS`, `SOCKS4`, `SOCKS5`.
1340
+ *
1341
+ * @returns {Promise<CaptchaAnswer>} The result from the solve.
1342
+ * @throws APIError
1343
+ *
1344
+ * @example
1345
+ * solver.keyCaptcha({
1346
+ * pageurl: "https://2captcha.com/demo/keycaptcha",
1347
+ * userId: "184015",
1348
+ * sessionId: "11975dc265ce9174a54edb1619af15b7",
1349
+ * webServerSign: "73ef77fd3cf0ce02947d9088bdc8412a",
1350
+ * webServerSign2: "93836d9e7007f38f072ce07d89bb7e2b"
1351
+ * })
1352
+ * .then((res) => {
1353
+ * console.log(res);
1354
+ * })
1355
+ * .catch((err) => {
1356
+ * console.log(err);
1357
+ * })
1358
+ */
1359
+ async keyCaptcha(params) {
1360
+ params = await (0, renameParams_1.default)(params);
1361
+ (0, checkCaptchaParams_1.default)(params, "keycaptcha");
1362
+ const payload = {
1363
+ ...params,
1364
+ method: "keycaptcha",
1365
+ ...this.defaultPayload,
1366
+ };
1367
+ const URL = this.in;
1368
+ const response = await (0, fetch_1.default)(URL, {
1369
+ body: JSON.stringify(payload),
1370
+ method: "post",
1371
+ headers: { 'Content-Type': 'application/json' }
1372
+ });
1373
+ const result = await response.text();
1374
+ let data;
1375
+ try {
1376
+ data = JSON.parse(result);
1377
+ }
1378
+ catch {
1379
+ throw new _2captchaError_1.APIError(result);
1380
+ }
1381
+ if (data.status == 1) {
1382
+ return this.pollResponse(data.request);
1383
+ }
1384
+ else {
1385
+ throw new _2captchaError_1.APIError(data.request);
1386
+ }
1387
+ }
1388
+ /**
1389
+ * ### Solves a Tencent.
1390
+ *
1391
+ * Use this method to solve Tencent captcha. Returns a token.
1392
+ * [Read more about Tencent Method](https://2captcha.com/2captcha-api#tencent).
1393
+ *
1394
+ * @param {{ pageurl, appId, pingback, proxy, proxytype }} params Parameters for solving Tencent as an object.
1395
+ * @param {string} params.pageurl The URL where the captcha is located.
1396
+ * @param {string} params.appId The value of `appId` parameter in the website source code.
1397
+ * @param {string} [params.pingback] Optional param. URL for pingback (callback) response when captcha is solved.
1398
+ * @param {string} [params.proxy] Optional param. Proxy to use while solving the captcha. Format: `login:password@123.123.123.123:3128`.
1399
+ * @param {string} [params.proxytype] Optional param. Type of your proxy: `HTTP`, `HTTPS`, `SOCKS4`, `SOCKS5`.
1400
+ *
1401
+ * @returns {Promise<CaptchaAnswer>} The result from the solve.
1402
+ * @throws APIError
1403
+ *
1404
+ * @example
1405
+ * solver.tencent({
1406
+ * pageurl: "https://mysite.com/page/with/tencent",
1407
+ * appId: "189956587"
1408
+ * })
1409
+ * .then((res) => {
1410
+ * console.log(res);
1411
+ * })
1412
+ * .catch((err) => {
1413
+ * console.log(err);
1414
+ * })
1415
+ */
1416
+ async tencent(params) {
1417
+ params = await (0, renameParams_1.default)(params);
1418
+ (0, checkCaptchaParams_1.default)(params, "tencent");
1419
+ const payload = {
1420
+ ...this.defaultPayload,
1421
+ ...params,
1422
+ method: "tencent",
1423
+ };
1424
+ const URL = this.in;
1425
+ const response = await (0, fetch_1.default)(URL, {
1426
+ body: JSON.stringify(payload),
1427
+ method: "post",
1428
+ headers: { 'Content-Type': 'application/json' }
1429
+ });
1430
+ const result = await response.text();
1431
+ let data;
1432
+ try {
1433
+ data = JSON.parse(result);
1434
+ }
1435
+ catch {
1436
+ throw new _2captchaError_1.APIError(result);
1437
+ }
1438
+ if (data.status == 1) {
1439
+ return this.pollResponse(data.request);
1440
+ }
1441
+ else {
1442
+ throw new _2captchaError_1.APIError(data.request);
1443
+ }
1444
+ }
1445
+ /**
1446
+ * ### Solves a atbCAPTCHA.
1447
+ *
1448
+ * Use this method to solve atbCAPTCHA captcha. Returns a token.
1449
+ * [Read more about atbCAPTCHA Method](https://2captcha.com/2captcha-api#atb-captcha).
1450
+ *
1451
+ * @param {{ pageurl, appId, apiServer, pingback, proxy, proxytype }} params Parameters for solving atbCAPTCHA as an object.
1452
+ * @param {string} params.pageurl The URL where the captcha is located.
1453
+ * @param {string} params.appId The value of `appId` parameter in the website source code.
1454
+ * @param {string} params.apiServer The value of `apiServer` parameter in the website source code.
1455
+ * @param {string} [params.pingback] Optional param. URL for pingback (callback) response when captcha is solved.
1456
+ * @param {string} [params.proxy] Optional param. Proxy to use while solving the captcha. Format: `login:password@123.123.123.123:3128`.
1457
+ * @param {string} [params.proxytype] Optional param. Type of your proxy: `HTTP`, `HTTPS`, `SOCKS4`, `SOCKS5`.
1458
+ *
1459
+ * @returns {Promise<CaptchaAnswer>} The result from the solve.
1460
+ * @throws APIError
1461
+ *
1462
+ * @example
1463
+ * solver.atbCaptcha({
1464
+ * pageurl: "https://mysite.com/page/with/tencent",
1465
+ * appId: "af25e409b33d722a95e56a230ff8771c",
1466
+ apiServer: "https://cap.aisecurius.com"
1467
+ * })
1468
+ * .then((res) => {
1469
+ * console.log(res);
1470
+ * })
1471
+ * .catch((err) => {
1472
+ * console.log(err);
1473
+ * })
1474
+ */
1475
+ async atbCaptcha(params) {
1476
+ params = await (0, renameParams_1.default)(params);
1477
+ (0, checkCaptchaParams_1.default)(params, "atb_captcha");
1478
+ const payload = {
1479
+ ...this.defaultPayload,
1480
+ ...params,
1481
+ method: "atb_captcha",
1482
+ };
1483
+ const URL = this.in;
1484
+ const response = await (0, fetch_1.default)(URL, {
1485
+ body: JSON.stringify(payload),
1486
+ method: "post",
1487
+ headers: { 'Content-Type': 'application/json' }
1488
+ });
1489
+ const result = await response.text();
1490
+ let data;
1491
+ try {
1492
+ data = JSON.parse(result);
1493
+ }
1494
+ catch {
1495
+ throw new _2captchaError_1.APIError(result);
1496
+ }
1497
+ if (data.status == 1) {
1498
+ return this.pollResponse(data.request);
1499
+ }
1500
+ else {
1501
+ throw new _2captchaError_1.APIError(data.request);
1502
+ }
1503
+ }
1504
+ /**
1505
+ * ### Solves Prosopo
1506
+ *
1507
+ * Use this method to solve Prosopo. Returns a token.
1508
+ * [Read more about Prosopo Method](https://2captcha.com/2captcha-api#prosopo-procaptcha).
1509
+ *
1510
+ * @param {{ pageurl, sitekey, proxy, proxytype}} params Parameters Prosopo as an object.
1511
+ * @param {string} params.pageurl Full `URL` of the page where you see the captcha.
1512
+ * @param {string} params.sitekey The value of `data-apikey` or `data-sitekey` parameter found on the page.
1513
+ * @param {string} params.proxy Optional param. Format: `login:password@123.123.123.123:3128` You can find more info about proxies [here](https://2captcha.com/2captcha-api#proxies).
1514
+ * @param {string} params.proxytype Optional param. Type of your proxy: `HTTP`, `HTTPS`, `SOCKS4`, `SOCKS5`.
1515
+ *
1516
+ * @example
1517
+ * solver.prosopo({
1518
+ * pageurl: "https://geizhals.de/?liftban=1&from=/455973138?fsean=5901747021356",
1519
+ * sitekey: "FCMST5VUMCBOCGQ9"
1520
+ * })
1521
+ * .then((res) => {
1522
+ * console.log(res);
1523
+ * })
1524
+ * .catch((err) => {
1525
+ * console.log(err);
1526
+ * })
1527
+ */
1528
+ async prosopo(params) {
1529
+ (0, checkCaptchaParams_1.default)(params, "prosopo");
1530
+ const payload = {
1531
+ ...this.defaultPayload,
1532
+ ...params,
1533
+ method: "prosopo",
1534
+ };
1535
+ const response = await (0, fetch_1.default)(this.in + utils.objectToURI(payload));
1536
+ const result = await response.text();
1537
+ let data;
1538
+ try {
1539
+ data = JSON.parse(result);
1540
+ }
1541
+ catch {
1542
+ throw new _2captchaError_1.APIError(result);
1543
+ }
1544
+ if (data.status == 1) {
1545
+ return this.pollResponse(data.request);
1546
+ }
1547
+ else {
1548
+ throw new _2captchaError_1.APIError(data.request);
1549
+ }
1550
+ }
1551
+ /**
1552
+ * ### Solves CaptchaFox
1553
+ *
1554
+ * Use this method to solve CaptchaFox. Returns a token.
1555
+ * [Read more about CaptchaFox Method](https://2captcha.com/2captcha-api#captchafox).
1556
+ *
1557
+ * @param {{ pageurl, sitekey, userAgent, proxy, proxytype}} params Parameters CaptchaFox as an object.
1558
+ * @param {string} params.pageurl Full `URL` of the page where you see the captcha.
1559
+ * @param {string} params.sitekey The value of `sitekey` parameter found on the page.
1560
+ * @param {string} params.userAgent User-Agent of your MODERN browser
1561
+ * @param {string} params.proxy Format: `login:password@123.123.123.123:3128` You can find more info about proxies [here](https://2captcha.com/2captcha-api#proxies).
1562
+ * @param {string} params.proxytype Type of your proxy: `HTTP`, `HTTPS`, `SOCKS4`, `SOCKS5`.
1563
+ *
1564
+ * @example
1565
+ * solver.captchaFox({
1566
+ * pageurl: "https://mysite.com/page/with/captchafox",
1567
+ * sitekey: "sk_ILKWN...",
1568
+ * userAgent: "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit...",
1569
+ * proxy: "login:password@1.2.3.4:8888",
1570
+ * proxytype: "HTTP"
1571
+ * })
1572
+ * .then((res) => {
1573
+ * console.log(res);
1574
+ * })
1575
+ * .catch((err) => {
1576
+ * console.log(err);
1577
+ * })
1578
+ */
1579
+ async captchaFox(params) {
1580
+ (0, checkCaptchaParams_1.default)(params, "captchafox");
1581
+ const payload = {
1582
+ ...this.defaultPayload,
1583
+ ...params,
1584
+ method: "captchafox",
1585
+ };
1586
+ const response = await (0, fetch_1.default)(this.in + utils.objectToURI(payload));
1587
+ const result = await response.text();
1588
+ let data;
1589
+ try {
1590
+ data = JSON.parse(result);
1591
+ }
1592
+ catch {
1593
+ throw new _2captchaError_1.APIError(result);
1594
+ }
1595
+ if (data.status == 1) {
1596
+ return this.pollResponse(data.request);
1597
+ }
1598
+ else {
1599
+ throw new _2captchaError_1.APIError(data.request);
1600
+ }
1601
+ }
1602
+ /**
1603
+ * ### VkImage method
1604
+ *
1605
+ * This method can be used to solve a captcha VkImage. Returns the number of steps and solution value in the target site's API format.
1606
+ * [Read more about VkImage Method](https://2captcha.com/2captcha-api#vkcaptcha).
1607
+ *
1608
+ * @param {{ body, steps }} params Parameters for solving VkImage Captcha.
1609
+ * @param {string} params.body Captcha image as a base64 string.
1610
+ * @param {string} params.steps Array of steps.
1611
+ *
1612
+ * @returns {Promise<CaptchaAnswer>} The result from the solve.
1613
+ * @throws APIError
1614
+ *
1615
+ * @example
1616
+ * solver.vkimage({
1617
+ * body: "iVBORw0KGgoAAAANSUhEUgAAAcIA...",
1618
+ * steps: "[5,19,4,3,23,8,20,4,18,10,6,10,5,12,13,18,9,14,9,15,12,19,3,12,...]",
1619
+ * })
1620
+ * .then((res) => {
1621
+ * console.log(res);
1622
+ * })
1623
+ * .catch((err) => {
1624
+ * console.log(err);
1625
+ * })
1626
+ */
1627
+ async vkimage(params) {
1628
+ (0, checkCaptchaParams_1.default)(params, "vkimage");
1629
+ const payload = {
1630
+ ...this.defaultPayload,
1631
+ ...params,
1632
+ method: "vkimage",
1633
+ };
1634
+ const URL = this.in;
1635
+ const response = await (0, fetch_1.default)(URL, {
1636
+ body: JSON.stringify(payload),
1637
+ method: "post",
1638
+ headers: { 'Content-Type': 'application/json' }
1639
+ });
1640
+ const result = await response.text();
1641
+ let data;
1642
+ try {
1643
+ data = JSON.parse(result);
1644
+ }
1645
+ catch {
1646
+ throw new _2captchaError_1.APIError(result);
1647
+ }
1648
+ if (data.status == 1) {
1649
+ return this.pollResponse(data.request);
1650
+ }
1651
+ else {
1652
+ throw new _2captchaError_1.APIError(data.request);
1653
+ }
1654
+ }
1655
+ /**
1656
+ * ### Solves VkCaptcha
1657
+ *
1658
+ * This method can be used to solve VK Captcha using a token. Returns a token.
1659
+ * [Read more about VkCaptcha Method](https://2captcha.com/2captcha-api#vkcaptcha).
1660
+ *
1661
+ * @param {{ redirect_uri, userAgent, proxy, proxytype}} params Parameters VkCaptcha as an object.
1662
+ * @param {string} params.redirect_uri The URL that is returned for requests to the captchas API.
1663
+ * @param {string} params.userAgent User-Agent of your MODERN browser
1664
+ * @param {string} params.proxy Format: `login:password@123.123.123.123:3128` You can find more info about proxies [here](https://2captcha.com/2captcha-api#proxies).
1665
+ * @param {string} params.proxytype Type of your proxy: `HTTP`, `HTTPS`, `SOCKS4`, `SOCKS5`.
1666
+ *
1667
+ * @example
1668
+ * solver.vkcaptcha({
1669
+ * redirect_uri: "https://id.vk.com/not_robot_captcha?domain=vk.com&session_token=eyJhbGciOiJBM...",
1670
+ * userAgent: "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit...",
1671
+ * proxy: "login:password@1.2.3.4:8888",
1672
+ * proxytype: "HTTP"
1673
+ * })
1674
+ * .then((res) => {
1675
+ * console.log(res);
1676
+ * })
1677
+ * .catch((err) => {
1678
+ * console.log(err);
1679
+ * })
1680
+ */
1681
+ async vkcaptcha(params) {
1682
+ (0, checkCaptchaParams_1.default)(params, "vkcaptcha");
1683
+ const payload = {
1684
+ ...this.defaultPayload,
1685
+ ...params,
1686
+ method: "vkcaptcha",
1687
+ };
1688
+ const response = await (0, fetch_1.default)(this.in + utils.objectToURI(payload));
1689
+ const result = await response.text();
1690
+ let data;
1691
+ try {
1692
+ data = JSON.parse(result);
1693
+ }
1694
+ catch {
1695
+ throw new _2captchaError_1.APIError(result);
1696
+ }
1697
+ if (data.status == 1) {
1698
+ return this.pollResponse(data.request);
1699
+ }
1700
+ else {
1701
+ throw new _2captchaError_1.APIError(data.request);
1702
+ }
1703
+ }
1704
+ /**
1705
+ * ### Solves Temu
1706
+ *
1707
+ * This method can be used to solve Temu captcha. Returns a coordinates.
1708
+ * [Read more about Temu Method](https://2captcha.com/2captcha-api#temucaptcha).
1709
+ *
1710
+ * @param {{ body, part1, part2, part3}} params Parameters Temu as an object.
1711
+ * @param {string} params.body Main captcha image as a base64 string.
1712
+ * @param {string} params.part1 Tile element as a base64 string.
1713
+ * @param {string} params.part2 Tile element as a base64 string.
1714
+ * @param {string} params.part3 Tile element as a base64 string.
1715
+ *
1716
+ * @example
1717
+ * solver.temu({
1718
+ * body: "data:image/png;base64,iVBORw0KG...",
1719
+ * part1: "data:image/png;base64,iVBORw0KG...",
1720
+ * part2: "data:image/png;base64,iVBORw0KG...",
1721
+ * part3: "data:image/png;base64,iVBORw0KG..."
1722
+ * })
1723
+ * .then((res) => {
1724
+ * console.log(res);
1725
+ * })
1726
+ * .catch((err) => {
1727
+ * console.log(err);
1728
+ * })
1729
+ */
1730
+ async temu(params) {
1731
+ (0, checkCaptchaParams_1.default)(params, "temu");
1732
+ const payload = {
1733
+ ...this.defaultPayload,
1734
+ ...params,
1735
+ method: "temuimage",
1736
+ };
1737
+ const URL = this.in;
1738
+ const response = await (0, fetch_1.default)(URL, {
1739
+ body: JSON.stringify(payload),
1740
+ method: "post",
1741
+ headers: { 'Content-Type': 'application/json' }
1742
+ });
1743
+ const result = await response.text();
1744
+ let data;
1745
+ try {
1746
+ data = JSON.parse(result);
1747
+ }
1748
+ catch {
1749
+ throw new _2captchaError_1.APIError(result);
1750
+ }
1751
+ if (data.status == 1) {
1752
+ return this.pollResponse(data.request);
1753
+ }
1754
+ else {
1755
+ throw new _2captchaError_1.APIError(data.request);
1756
+ }
1757
+ }
1758
+ /**
1759
+ * ### Method for solving Audio captcha.
1760
+ *
1761
+ * Use the following method to bypass an audio captcha (`mp3` formats only). You must provide the language as `lang = 'en'`. Supported languages are "en", "ru", "de", "el", "pt", "fr".
1762
+ * [Read more about Audio recognition Method](https://2captcha.com/2captcha-api#audio-recognition).
1763
+ *
1764
+ * @param {{ body, lang, pingback }} params Object containing parameters for the audio captcha.
1765
+ * @param {string} params.body Base64 encoded audio file in `mp3` format. Max file size: 1 MB.
1766
+ * @param {string} params.lang The language of audio record. Supported languages are: "en", "ru", "de", "el", "pt", "fr".
1767
+ * @param {string} [params.pingback] URL for pingback response once captcha is solved.
1768
+ *
1769
+ * @returns {Promise<CaptchaAnswer>} The result from solving the audio captcha.
1770
+ * @throws APIError
1771
+ * @example
1772
+ * solver.audio({
1773
+ * body: "SUQzBAAAAAAAHFRTU0UAAAA...",
1774
+ * lang: "en"
1775
+ * })
1776
+ * .then((res) => {
1777
+ * console.log(res);
1778
+ * })
1779
+ * .catch((err) => {
1780
+ * console.log(err);
1781
+ * })
1782
+ */
1783
+ async audio(params) {
1784
+ (0, checkCaptchaParams_1.default)(params, "audio");
1785
+ const payload = {
1786
+ ...this.defaultPayload,
1787
+ ...params,
1788
+ method: "audio",
1789
+ };
1790
+ const response = await (0, fetch_1.default)(this.in, {
1791
+ method: 'post',
1792
+ body: JSON.stringify(payload),
1793
+ headers: { 'Content-Type': 'application/json' }
1794
+ });
1795
+ const result = await response.text();
1796
+ let data;
1797
+ try {
1798
+ data = JSON.parse(result);
1799
+ }
1800
+ catch {
1801
+ throw new _2captchaError_1.APIError(result);
1802
+ }
1803
+ if (data.status == 1) {
1804
+ return this.pollResponse(data.request);
1805
+ }
1806
+ else {
1807
+ throw new _2captchaError_1.APIError(data.request);
1808
+ }
1809
+ }
1810
+ /**
1811
+ * Reports a captcha as correctly solved.
1812
+ *
1813
+ * @param {string} id The ID of the captcha
1814
+ * @throws APIError
1815
+ * @example
1816
+ * solver.goodReport("7031854546")
1817
+ *
1818
+ */
1819
+ async goodReport(id) {
1820
+ const payload = {
1821
+ id: id,
1822
+ action: "reportgood",
1823
+ ...this.defaultPayload
1824
+ };
1825
+ const response = await (0, fetch_1.default)(this.res + utils.objectToURI(payload));
1826
+ const result = await response.text();
1827
+ let data;
1828
+ try {
1829
+ data = JSON.parse(result);
1830
+ }
1831
+ catch {
1832
+ throw new _2captchaError_1.APIError(result);
1833
+ }
1834
+ if (data.request == "OK_REPORT_RECORDED") {
1835
+ return data.request;
1836
+ }
1837
+ else {
1838
+ throw new _2captchaError_1.APIError(data.request);
1839
+ }
1840
+ }
1841
+ /**
1842
+ * Report an unsuccessful solve
1843
+ *
1844
+ * @param {string} id The id of the captcha solve
1845
+ *
1846
+ * @returns {Promise<void>} Resolves on completion
1847
+ * @throws APIError
1848
+ * @example
1849
+ * solver.badReport("7031854546")
1850
+ */
1851
+ async badReport(id) {
1852
+ const payload = {
1853
+ id: id,
1854
+ action: "reportbad",
1855
+ ...this.defaultPayload
1856
+ };
1857
+ const response = await (0, fetch_1.default)(this.res + utils.objectToURI(payload));
1858
+ const result = await response.text();
1859
+ let data;
1860
+ try {
1861
+ data = JSON.parse(result);
1862
+ }
1863
+ catch {
1864
+ throw new _2captchaError_1.APIError(result);
1865
+ }
1866
+ if (data.request == "OK_REPORT_RECORDED" || data.request == "ERROR_DUPLICATE_REPORT") {
1867
+ return data.request;
1868
+ }
1869
+ else {
1870
+ throw new _2captchaError_1.APIError(data.request);
1871
+ }
1872
+ }
1873
+ }
1874
+ exports.Solver = Solver;