@2captcha/captcha-solver 1.0.2 → 1.0.4

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.
@@ -0,0 +1,1150 @@
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 provider = (0, providers_1.default)();
37
+ /**
38
+ * The main 2captcha class, housing all API calls and api interactions.
39
+ *
40
+ */
41
+ class Solver {
42
+ /**
43
+ * The constructor for the 2captcha Solver class.
44
+ *
45
+ * @param {string} apikey The API key to use
46
+ * @param {number} pollingFrequency The frequency to poll for requests
47
+ *
48
+ */
49
+ constructor(apikey, pollingFrequency = 5000, enableACAO = true) {
50
+ this._apikey = apikey;
51
+ this._pollingFrequency = pollingFrequency;
52
+ this._headerACAO = enableACAO ? 1 : 0;
53
+ }
54
+ /** The API key this instance is using */
55
+ get apikey() { return this._apikey; }
56
+ /** Frequency the instance polls for updates */
57
+ get pollingFrequency() { return this._pollingFrequency; }
58
+ /** Set the API key for this instance */
59
+ set apikey(update) { this._apikey = update; }
60
+ get in() { return provider.in; }
61
+ get res() { return provider.res; }
62
+ get defaultPayload() { return { key: this.apikey, json: 1, header_acao: this._headerACAO, soft_id: constants_1.softId }; }
63
+ /**
64
+ * Returns the remaining account balance.
65
+ *
66
+ * @return {Promise<Number>} Remaining balance
67
+ * @throws APIError
68
+ * @example
69
+ * solver.balance()
70
+ * .then((res) => {
71
+ * console.log(res)
72
+ * })
73
+ */
74
+ async balance() {
75
+ const res = await (0, fetch_1.default)(this.res + utils.objectToURI({
76
+ ...this.defaultPayload,
77
+ action: "getbalance"
78
+ }));
79
+ const result = await res.text();
80
+ try {
81
+ const data = JSON.parse(result);
82
+ if (data.status == 1) {
83
+ return parseFloat(data.request);
84
+ }
85
+ throw new _2captchaError_1.APIError(data.request);
86
+ }
87
+ catch {
88
+ throw new _2captchaError_1.APIError(result);
89
+ }
90
+ }
91
+ /**
92
+ * @private
93
+ *
94
+ * Polls for a captcha, finding out if it's been completed
95
+ * @param {string} id Captcha ID
96
+ *
97
+ * @returns {Promise<CaptchaAnswer>}
98
+ * @throws APIError
99
+ */
100
+ async pollResponse(id) {
101
+ const payload = {
102
+ ...this.defaultPayload,
103
+ action: "get",
104
+ id: id
105
+ };
106
+ await utils.sleep(this.pollingFrequency);
107
+ const res = await (0, fetch_1.default)(this.res + utils.objectToURI(payload));
108
+ const result = await res.text();
109
+ let data;
110
+ try {
111
+ data = JSON.parse(result);
112
+ if (data.status == 1) {
113
+ return { data: data.request, id: id };
114
+ }
115
+ }
116
+ catch {
117
+ throw new _2captchaError_1.APIError(result);
118
+ }
119
+ switch (data.request) {
120
+ case "CAPCHA_NOT_READY":
121
+ // console.log('CAPCHA_NOT_READY')
122
+ return this.pollResponse(id);
123
+ default: {
124
+ throw new _2captchaError_1.APIError(data.request);
125
+ }
126
+ }
127
+ }
128
+ /**
129
+ * ### Solves a google reCAPTCHA V2 | V3.
130
+ *
131
+ * [Read more about other reCAPTCHA parameters](https://2captcha.com/2captcha-api#solving_recaptchav2_new).
132
+ *
133
+ * @param {{pageurl, googlekey, cookies, proxy, proxytype, userAgent, invisible, datas, pingback, action, enterprise, min_score, version, domain}} params Object
134
+ * @param {string} params.pageurl The URL the captcha appears on.
135
+ * @param {string} params.googlekey Value of `k` or `data-sitekey` parameter you found on page.
136
+ * @param {string} params.cookies Your cookies that will be passed to our worker who solve the captha.
137
+ * @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).
138
+ * @param {string} params.proxytype Type of your proxy: `HTTP`, `HTTPS`, `SOCKS4`, `SOCKS5`.
139
+ * @param {string} params.userAgent Your `userAgent` that will be passed to our worker and used to solve the captcha.
140
+ * @param {number} params.invisible `1` - means that reCAPTCHA is invisible. `0` - normal reCAPTCHA.
141
+ * @param {string} params.datas Value of `data-s` parameter you found on page. Curenttly applicable for Google Search and other Google services.
142
+ * @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).
143
+ * @param {string} params.action Value of `action` parameter you found on page.
144
+ * @param {string} params.enterprise `1` - defines that you're sending reCAPTCHA Enterpise.
145
+ * @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`
146
+ * @param {string} params.version `v2` — defines that you're sending a reCAPTCHA V2. `v3` — defines that you're sending a reCAPTCHA V3.
147
+ * @param {string} params.domain Domain used to load the captcha: `google.com` or `recaptcha.net`
148
+ *
149
+ * @returns {Promise<CaptchaAnswer>} The result from the solve.
150
+ * @throws APIError
151
+ * @example
152
+ * solver.recaptcha({
153
+ * pageurl: 'https://2captcha.com/demo/recaptcha-v2',
154
+ * googlekey: '6LfD3PIbAAAAAJs_eEHvoOl75_83eXSqpPSRFJ_u'
155
+ * })
156
+ * .then((res) => {
157
+ * console.log(res);
158
+ * })
159
+ * .catch((err) => {
160
+ * console.log(err);
161
+ * })
162
+ */
163
+ async recaptcha(params) {
164
+ (0, checkCaptchaParams_1.default)(params, "userrecaptcha");
165
+ const payload = {
166
+ ...params,
167
+ method: "userrecaptcha",
168
+ ...this.defaultPayload
169
+ };
170
+ const response = await (0, fetch_1.default)(this.in + utils.objectToURI(payload));
171
+ const result = await response.text();
172
+ let data;
173
+ try {
174
+ data = JSON.parse(result);
175
+ }
176
+ catch {
177
+ throw new _2captchaError_1.APIError(result);
178
+ }
179
+ if (data.status == 1) {
180
+ return this.pollResponse(data.request);
181
+ }
182
+ else {
183
+ throw new _2captchaError_1.APIError(data.request);
184
+ }
185
+ }
186
+ /**
187
+ * Solves a hCaptcha, returning the result as a string.
188
+ *
189
+ * [Read more about other hCaptcha parameters](https://2captcha.com/2captcha-api#solving_hcaptcha).
190
+ *
191
+ * @param {{sitekey, pageurl, data, userAgent, invisible, pingback, proxy, proxytype, domain}} params Object
192
+ * @param {string} params.sitekey The hcaptcha site key. Value of `k` or `data-sitekey` parameter you found on page.
193
+ * @param {string} params.pageurl The URL the captcha appears on.
194
+ * @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.
195
+ * @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.
196
+ * @param {number} params.invisible Use `1` for invisible version of hcaptcha. Currently it is a very rare case.
197
+ * @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).
198
+ * @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).
199
+ * @param {string} params.proxytype Type of your proxy: `HTTP`, `HTTPS`, `SOCKS4`, `SOCKS5`.
200
+ * @param {string} params.domain Domain used to load the captcha: `hcaptcha.com` or `js.hcaptcha.com`
201
+ *
202
+ * @returns {Promise<CaptchaAnswer>} The result from the solve
203
+ * @throws APIError
204
+ * @example
205
+ * solver.hcaptcha({
206
+ * pageurl: "https://2captcha.com/demo/hcaptcha",
207
+ * sitekey: "b76cd927-d266-4cfb-a328-3b03ae07ded6"
208
+ * .then((res) => {
209
+ * console.log(res);
210
+ * })
211
+ * .catch((err) => {
212
+ * console.log(err);
213
+ * })
214
+ */
215
+ async hcaptcha(params) {
216
+ (0, checkCaptchaParams_1.default)(params, "hcaptcha");
217
+ const payload = {
218
+ ...params,
219
+ method: "hcaptcha",
220
+ ...this.defaultPayload
221
+ };
222
+ const response = await (0, fetch_1.default)(this.in + utils.objectToURI(payload));
223
+ const result = await response.text();
224
+ let data;
225
+ try {
226
+ data = JSON.parse(result);
227
+ }
228
+ catch {
229
+ throw new _2captchaError_1.APIError(result);
230
+ }
231
+ if (data.status == 1) {
232
+ return this.pollResponse(data.request);
233
+ }
234
+ else {
235
+ throw new _2captchaError_1.APIError(data.request);
236
+ }
237
+ }
238
+ /**
239
+ * Solves a GeeTest Captcha. [Read more about parameters and solving for Geetest captcha](https://2captcha.com/2captcha-api#solving_geetest).
240
+ *
241
+ * @param {{ gt, challenge, api_server, offline, new_captcha,
242
+ * pageurl, pingback, proxy, proxytype, userAgent }} params
243
+ * @param {string} params.gt Value of gt parameter found on site
244
+ * @param {string} params.challenge Value of challenge parameter found on site
245
+ * @param {string} params.pageurl The URL the captcha appears on
246
+ * @param {string} params.api_server The URL of the api_server (recommended)
247
+ * @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`.
248
+ * @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.
249
+ * @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).
250
+ * @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).
251
+ * @param {string} params.proxytype Type of your proxy: `HTTP`, `HTTPS`, `SOCKS4`, `SOCKS5`.
252
+ * @param {string} params.userAgent Your `userAgent` that will be passed to our worker and used to solve the captcha.
253
+ *
254
+ * @returns {Promise<CaptchaAnswer>} The result from the solve.
255
+ * @throws APIError
256
+ * @example
257
+ * ;(async () => {
258
+ *
259
+ * // Warning: Attention, the `challenge` value is not static but dynamic.
260
+ * // You need to find the queries that makes the captcha on the page to API.
261
+ * // Then you need to make request to this API and get new `challenge`.
262
+ *
263
+ * // For page https://rucaptcha.com/demo/geetest, api address is https://rucaptcha.com/api/v1/captcha-demo/gee-test/init-params?t=${t}
264
+ * // Also note that when make request to API, the request uses the dynamic parameter `t`
265
+ *
266
+ * // You can read more about sending GeeTest here https://2captcha.com/2captcha-api#solving_geetest, or here https://2captcha.com/p/geetest
267
+ * // In this example I solve GeeTest from page https://2captcha.com/demo/geetest
268
+ *
269
+ * const t = new Date().getTime()
270
+ * // below i make a request to get a new `challenge`.
271
+ * const response = await fetch(`https://2captcha.com/api/v1/captcha-demo/gee-test/init-params?t=${t}`)
272
+ * const data = await response.json()
273
+ *
274
+ * const params = {
275
+ * pageurl: 'https://rucaptcha.com/demo/geetest',
276
+ * gt: data.gt,
277
+ * challenge: data.challenge
278
+ * }
279
+ *
280
+ * const res = await solver.geetest(params)
281
+ * try {
282
+ * console.log(res)
283
+ * } catch (error) {
284
+ * console.error(error);
285
+ * }
286
+ * })()
287
+ */
288
+ async geetest(params) {
289
+ (0, checkCaptchaParams_1.default)(params, "geetest");
290
+ const payload = {
291
+ ...params,
292
+ method: "geetest",
293
+ ...this.defaultPayload
294
+ };
295
+ const response = await (0, fetch_1.default)(this.in + utils.objectToURI(payload));
296
+ const result = await response.text();
297
+ let data;
298
+ try {
299
+ data = JSON.parse(result);
300
+ }
301
+ catch {
302
+ throw new _2captchaError_1.APIError(result);
303
+ }
304
+ if (data.status == 1) {
305
+ return this.pollResponse(data.request);
306
+ }
307
+ else {
308
+ throw new _2captchaError_1.APIError(data.request);
309
+ }
310
+ }
311
+ /**
312
+ * ### Solves a GeeTest V4 Captcha.
313
+ *
314
+ *
315
+ * This method accepts an object with the following fields: `pageurl`, `captcha_id`, `pingback`, `proxy`, `proxytype`, `userAgent`.
316
+ * The `pageurl` and `captcha_id` fields are required.
317
+ *
318
+ * @param {{pageurl, captcha_id, pingback, proxy, proxytype, userAgent}} params The method geetestV4 takes arguments as an object.
319
+ * @param {string} params.pageurl Full URL of the page where you see Geetest V4 captcha.
320
+ * @param {string} params.captcha_id Required parameter. Value of `captcha_id` parameter you found on target website.
321
+ * @param {string} params.pingback An optional param. [More info here](https://2captcha.com/2captcha-api#pingback).
322
+ * @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).
323
+ * @param {string} params.proxytype An optional param. Type of your proxy: `HTTP`, `HTTPS`, `SOCKS4`, `SOCKS5`.
324
+ * @param {string} params.userAgent An optional param. Your `userAgent` that will be passed to our worker and used to solve the captcha.
325
+ *
326
+ * @returns {Promise<CaptchaAnswer>} The result from the solve.
327
+ * @throws APIError
328
+ * @example
329
+ * solver.geetestV4({
330
+ * pageurl: 'https://2captcha.com/demo/geetest-v4',
331
+ * captcha_id: 'e392e1d7fd421dc63325744d5a2b9c73'
332
+ * })
333
+ * .then((res) => {
334
+ * console.log(res)
335
+ * })
336
+ * .catch((err) => {
337
+ * console.log(err);
338
+ * })
339
+ */
340
+ async geetestV4(params) {
341
+ (0, checkCaptchaParams_1.default)(params, "geetest_v4");
342
+ const payload = {
343
+ ...params,
344
+ method: "geetest_v4",
345
+ ...this.defaultPayload
346
+ };
347
+ const response = await (0, fetch_1.default)(this.in + utils.objectToURI(payload));
348
+ const result = await response.text();
349
+ let data;
350
+ try {
351
+ data = JSON.parse(result);
352
+ }
353
+ catch {
354
+ throw new _2captchaError_1.APIError(result);
355
+ }
356
+ if (data.status == 1) {
357
+ return this.pollResponse(data.request);
358
+ }
359
+ else {
360
+ throw new _2captchaError_1.APIError(data.request);
361
+ }
362
+ }
363
+ /**
364
+ * Method for sending Yandex Smart Captcha.
365
+ * This method accepts an object with the following fields: `pageurl`, `sitekey`, `pingback`, `proxy`, `proxytype`.
366
+ * The `pageurl` and `sitekey` fields are required.
367
+ *
368
+ * @param {{pageurl, sitekey, pingback, proxy, proxytype, userAgent}} params The method takes arguments as an object.
369
+ * @param {string} params.pageurl Required parameter. URL of the page where the captcha is located.
370
+ * @param {string} params.sitekey Required parameter. The `sitekey` value you found on the captcha page.
371
+ * @param {string} params.pingback An optional param.
372
+ * @param {string} params.proxy An optional param. Format: `login:password@123.123.123.123:3128`.
373
+ * @param {string} params.proxytype An optional param. Type of your proxy: `HTTP`, `HTTPS`, `SOCKS4`, `SOCKS5`.
374
+ * @param {string} params.userAgent An optional param. Your `userAgent` that will be passed to our worker and used to solve the captcha.
375
+ *
376
+ * @returns {Promise<CaptchaAnswer>} The result from the solve.
377
+ * @throws APIError
378
+ * @example
379
+ * solver.yandexSmart({
380
+ * pageurl: "https://captcha-api.yandex.ru/demo",
381
+ * sitekey: "FEXfAbHQsToo97VidNVk3j4dC74nGW1DgdxjtNB9"
382
+ * })
383
+ * .then((res) => {
384
+ * console.log(res)
385
+ * })
386
+ * .catch((err) => {
387
+ * console.log(err);
388
+ * })
389
+ */
390
+ async yandexSmart(params) {
391
+ (0, checkCaptchaParams_1.default)(params, "yandex");
392
+ const payload = {
393
+ ...params,
394
+ method: "yandex",
395
+ ...this.defaultPayload
396
+ };
397
+ const response = await (0, fetch_1.default)(this.in + utils.objectToURI(payload));
398
+ const result = await response.text();
399
+ let data;
400
+ try {
401
+ data = JSON.parse(result);
402
+ }
403
+ catch {
404
+ throw new _2captchaError_1.APIError(result);
405
+ }
406
+ if (data.status == 1) {
407
+ return this.pollResponse(data.request);
408
+ }
409
+ else {
410
+ throw new _2captchaError_1.APIError(data.request);
411
+ }
412
+ }
413
+ /**
414
+ * Solves a image-based captcha. [Read more about parameters for image captcha](https://2captcha.com/2captcha-api#solving_normal_captcha).
415
+ *
416
+ * @param {{ body,
417
+ * phrase,
418
+ * regsense,
419
+ * numeric,
420
+ * calc,
421
+ * min_len,
422
+ * max_len,
423
+ * language,
424
+ * lang,
425
+ * textinstructions,
426
+ * pingback }} params Extra properties to pass to 2captcha.
427
+ * @param {number} params.body Base64 image data for the captcha.
428
+ * @param {number} params.phrase Captcha contains two or more words? `1` - Yes. `0` - No.
429
+ * @param {number} params.regsense Captcha is case sensitive? `1` - Yes. `0` - No.
430
+ * @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.
431
+ * @param {number} params.calc Does captcha require calculations? (e.g. type the result 4 + 8 = ) `1` - Yes. `0` - No.
432
+ * @param {number} params.min_len `1..20` - minimal number of symbols in captcha. `0` - not specified.
433
+ * @param {number} params.max_len `1..20` - maximal number of symbols in captcha. `0` - not specified.
434
+ * @param {number} params.language `0` - not specified. `1` - Cyrillic captcha. `2` - Latin captcha
435
+ * @param {string} params.lang Language code. [See the list of supported languages](https://2captcha.com/2captcha-api#language).
436
+ * @param {string} params.textinstructions Text will be shown to worker to help him to solve the captcha correctly. For example: type red symbols only.
437
+ * @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).
438
+ *
439
+ * @returns {Promise<CaptchaAnswer>} The result from the solve
440
+ * @throws APIError
441
+ * @example
442
+ * const imageBase64 = fs.readFileSync("./tests/media/imageCaptcha_6e584.png", "base64")
443
+ *
444
+ * solver.imageCaptcha({
445
+ * body: imageBase64,
446
+ * numeric: 4,
447
+ * min_len: 5,
448
+ * max_len: 5
449
+ * })
450
+ * .then((res) => {
451
+ * console.log(res);
452
+ * })
453
+ * .catch((err) => {
454
+ * console.log(err);
455
+ * })
456
+ */
457
+ async imageCaptcha(params) {
458
+ (0, checkCaptchaParams_1.default)(params, "base64");
459
+ const payload = {
460
+ ...params,
461
+ ...this.defaultPayload,
462
+ method: "base64"
463
+ };
464
+ const URL = this.in;
465
+ const response = await (0, fetch_1.default)(URL, {
466
+ body: JSON.stringify(payload),
467
+ method: "post",
468
+ headers: { 'Content-Type': 'application/json' }
469
+ });
470
+ const result = await response.text();
471
+ let data;
472
+ try {
473
+ data = JSON.parse(result);
474
+ }
475
+ catch {
476
+ throw new _2captchaError_1.APIError(result);
477
+ }
478
+ if (data.status == 1) {
479
+ return this.pollResponse(data.request);
480
+ }
481
+ else {
482
+ throw new _2captchaError_1.APIError(data.request);
483
+ }
484
+ }
485
+ /**
486
+ * ### Solves Arkose Labs FunCaptcha.
487
+ *
488
+ * [Read more](https://2captcha.com/2captcha-api#solving_funcaptcha_new) about other solving and other parameters for Arkose Labs FunCaptcha.
489
+ *
490
+ * @param {{pageurl, publicKey, surl, data, pingback, proxy, proxytype, userAgent}} params Object
491
+ * @param {string} params.publicKey The FunCaptcha Public Key
492
+ * @param {string} params.pageurl The URL to the website the captcha is seen on
493
+ * @param {string} params.surl The FunCaptcha Service URL (recommended)
494
+ * @param {string} params.data Custom data to pass to FunCaptcha. For example: `'data': '{"blob": "foo"}'`.
495
+ * @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).
496
+ * @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).
497
+ * @param {string} params.proxytype Type of your proxy: `HTTP`, `HTTPS`, `SOCKS4`, `SOCKS5`.
498
+ * @param {string} params.userAgent Your `userAgent` that will be passed to our worker and used to solve the captcha.
499
+ *
500
+ * @returns {Promise<CaptchaAnswer>} The result from the solve
501
+ * @throws APIError
502
+ *
503
+ * @example
504
+ * solver.funCaptcha({
505
+ * pageurl: "https://funcaptcha.com/tile-game-lite-mode/fc/api/nojs/?pkey=804380F4-6844-FFA1-ED4E-5877CA1F1EA4&lang=en",
506
+ * publickey: "804380F4-6844-FFA1-ED4E-5877CA1F1EA4"
507
+ * })
508
+ * .then((res) => {
509
+ * console.log(res);
510
+ * })
511
+ * .catch((err) => {
512
+ * console.log(err);
513
+ * })
514
+ */
515
+ async funCaptcha(params) {
516
+ (0, checkCaptchaParams_1.default)(params, "funcaptcha");
517
+ const payload = {
518
+ ...params,
519
+ method: "funcaptcha",
520
+ ...this.defaultPayload,
521
+ };
522
+ const response = await (0, fetch_1.default)(this.in + utils.objectToURI(payload));
523
+ const result = await response.text();
524
+ let data;
525
+ try {
526
+ data = JSON.parse(result);
527
+ }
528
+ catch {
529
+ throw new _2captchaError_1.APIError(result);
530
+ }
531
+ if (data.status == 1) {
532
+ return this.pollResponse(data.request);
533
+ }
534
+ else {
535
+ throw new _2captchaError_1.APIError(data.request);
536
+ }
537
+ }
538
+ /**
539
+ *
540
+ * ### Solves a Lemin captcha
541
+ *
542
+ * [Read more about other Lemin captcha parameters](https://2captcha.com/2captcha-api#lemin).
543
+ *
544
+ * @param {{ pageurl, captcha_id, div_id, api_server, pingback, proxy, proxytype}} params Object
545
+ * @param {string} params.pageurl The URL the captcha appears on.
546
+ * @param {string} params.captcha_id Value of `captcha_id` parameter you found on page.
547
+ * @param {string} params.div_id Value `id` of captcha pareent `<div></div>` element.
548
+ * @param {string} params.api_server The domain part of script URL you found on page. Default value: `https://api.leminnow.com/`
549
+ * @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).
550
+ * @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).
551
+ * @param {string} params.proxytype Type of your proxy: `HTTP`, `HTTPS`, `SOCKS4`, `SOCKS5`.
552
+ *
553
+ * @example
554
+ * solver.lemin({
555
+ * pageurl:'https://2captcha.com/demo/lemin',
556
+ * captcha_id: 'CROPPED_3dfdd5c_d1872b526b794d83ba3b365eb15a200b',
557
+ * div_id: 'lemin-cropped-captcha',
558
+ * api_server: 'api.leminnow.com'
559
+ * })
560
+ * .then((res) => {
561
+ * console.log(res);
562
+ * })
563
+ * .catch((err) => {
564
+ * console.log(err);
565
+ * })
566
+ */
567
+ async lemin(params) {
568
+ (0, checkCaptchaParams_1.default)(params, "lemin");
569
+ const payload = {
570
+ ...params,
571
+ method: "lemin",
572
+ ...this.defaultPayload,
573
+ };
574
+ const response = await (0, fetch_1.default)(this.in + utils.objectToURI(payload));
575
+ const result = await response.text();
576
+ let data;
577
+ try {
578
+ data = JSON.parse(result);
579
+ }
580
+ catch {
581
+ throw new _2captchaError_1.APIError(result);
582
+ }
583
+ if (data.status == 1) {
584
+ return this.pollResponse(data.request);
585
+ }
586
+ else {
587
+ throw new _2captchaError_1.APIError(data.request);
588
+ }
589
+ }
590
+ /**
591
+ *
592
+ * ### Solves Amazon WAF captcha
593
+ *
594
+ * [Read more about "Amazon WAF" captcha](https://2captcha.com/2captcha-api#amazon-waf).
595
+ *
596
+ * @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.
597
+ * @param {string} params.pageurl Is the full `URL` of page where you were challenged by the captcha.
598
+ * @param {string} params.sitekey Is a value of `key` parameter in the page source.
599
+ * @param {string} params.iv Is a value of `iv` parameter in the page source.
600
+ * @param {string} params.context Is a value of `context` parameter in the page source.
601
+ * @param {string} params.challenge_script The source URL of `challenge.js` script on the page.
602
+ * @param {string} params.captcha_script The source URL of `captcha.js` script on the page.
603
+ * @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).
604
+ * @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).
605
+ * @param {string} params.proxytype Type of your proxy: `HTTP`, `HTTPS`, `SOCKS4`, `SOCKS5`.
606
+ *
607
+ * @example
608
+ * solver.amazonWaf({
609
+ * pageurl: "https://non-existent-example.execute-api.us-east-1.amazonaws.com/latest",
610
+ * sitekey: "AQIDAHjcYu/GjX+QlghicBgQ/7bFaQZ+m5FKCMDnO+vTbNg96AHMDLodoefdvyOnsHMRtEKQAAAAfjB8BgkqhkiG9w0BBwagbzBtAgEAMGgGCSqGSIb3DQEHATAeBglghkgBZQMEAS4wEQQMUX+ZqwwuANRnZujSAgEQgDvHSxUQmVBuyUtumoW2n4ccTG7xQN1r3X/zz41qmQaYv9SSSvQrjIoDXKaUQ23tVb4ii8+uljuRdz/HPA==",
611
+ * context: "9BUgmlm48F92WUoqv97a49ZuEJJ50TCk9MVr3C7WMtQ0X6flVbufM4n8mjFLmbLVAPgaQ1Jydeaja94iAS49ljb+sUNLoukWedAQZKrlY4RdbOOzvcFqmD/ZepQFS9N5w15Exr4VwnVq+HIxTsDJwRviElWCdzKDebN/mk8/eX2n7qJi5G3Riq0tdQw9+C4diFZU5E97RSeahejOAAJTDqduqW6uLw9NsjJBkDRBlRjxjn5CaMMo5pYOxYbGrM8Un1JH5DMOLeXbq1xWbC17YSEoM1cRFfTgOoc+VpCe36Ai9Kc=",
612
+ * iv: "CgAHbCe2GgAAAAAj",
613
+ * })
614
+ * .then((res) => {
615
+ * console.log(res);
616
+ * })
617
+ * .catch((err) => {
618
+ * console.log(err);
619
+ * })
620
+ */
621
+ async amazonWaf(params) {
622
+ (0, checkCaptchaParams_1.default)(params, "amazon_waf");
623
+ const payload = {
624
+ ...params,
625
+ method: "amazon_waf",
626
+ ...this.defaultPayload,
627
+ };
628
+ const response = await (0, fetch_1.default)(this.in + utils.objectToURI(payload));
629
+ const result = await response.text();
630
+ let data;
631
+ try {
632
+ data = JSON.parse(result);
633
+ }
634
+ catch {
635
+ throw new _2captchaError_1.APIError(result);
636
+ }
637
+ if (data.status == 1) {
638
+ return this.pollResponse(data.request);
639
+ }
640
+ else {
641
+ throw new _2captchaError_1.APIError(data.request);
642
+ }
643
+ }
644
+ /**
645
+ *
646
+ * ### Solves Cloudflare Turnstile captcha
647
+ *
648
+ * [Read more about Cloudflare Turnstile captcha](https://2captcha.com/2captcha-api#turnstile).
649
+ *
650
+ * @param {{ pageurl, sitekey, action, data, pingback, proxy, proxytype}} params The `сloudflareTurnstile` method takes arguments as an object. Thus, the `pageurl`, `sitekey` fields in the passed object are mandatory.
651
+ * @param {string} params.pageurl Full `URL` of the page where you see the captcha.
652
+ * @param {string} params.sitekey Is a value of `sitekey` parameter in the page source.
653
+ * @param {string} params.action Value of optional `action` parameter you found on page.
654
+ * @param {string} params.data Value of optional `data` parameter you found on page.
655
+ * @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).
656
+ * @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).
657
+ * @param {string} params.proxytype Type of your proxy: `HTTP`, `HTTPS`, `SOCKS4`, `SOCKS5`.
658
+ *
659
+ * @example
660
+ * solver.cloudflareTurnstile({
661
+ * pageurl: "https://app.nodecraft.com/login",
662
+ * sitekey: "0x4AAAAAAAAkg0s3VIOD10y4"
663
+ * })
664
+ * .then((res) => {
665
+ * console.log(res);
666
+ * })
667
+ * .catch((err) => {
668
+ * console.log(err);
669
+ * })
670
+ */
671
+ async cloudflareTurnstile(params) {
672
+ (0, checkCaptchaParams_1.default)(params, "turnstile");
673
+ const payload = {
674
+ ...params,
675
+ method: "turnstile",
676
+ ...this.defaultPayload,
677
+ };
678
+ const response = await (0, fetch_1.default)(this.in + utils.objectToURI(payload));
679
+ const result = await response.text();
680
+ let data;
681
+ try {
682
+ data = JSON.parse(result);
683
+ }
684
+ catch {
685
+ throw new _2captchaError_1.APIError(result);
686
+ }
687
+ if (data.status == 1) {
688
+ return this.pollResponse(data.request);
689
+ }
690
+ else {
691
+ throw new _2captchaError_1.APIError(data.request);
692
+ }
693
+ }
694
+ /**
695
+ * ### Solves a Coordinates captcha.
696
+ *
697
+ * @param {{ body, imginstructions, textinstructions, language, lang, pingback }} params parameters Сoordinates Captcha as an object.
698
+ * @param {string} params.body Base64-encoded captcha image.
699
+ * @param {string} params.imginstructions Base64-encoded image with instruction for solving captcha.
700
+ * @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.
701
+ * @param {number} params.language `0` - not specified. `1` - Cyrillic captcha. `2` - Latin captcha
702
+ * @param {string} params.lang Language code. [See the list of supported languages](https://2captcha.com/2captcha-api#language).
703
+ * @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).
704
+ *
705
+ * @returns {Promise<CaptchaAnswer>} The result from the solve
706
+ *
707
+ * @example
708
+ * const imageBase64 = fs.readFileSync("./tests/media/hCaptchaImage.jpg", "base64")
709
+ *
710
+ * solver.coordinates({
711
+ * body: imageBase64,
712
+ * textinstructions: 'Select all photos containing the boat'
713
+ * })
714
+ * .then((res) => {
715
+ * console.log(res);
716
+ * })
717
+ * .catch((err) => {
718
+ * console.log(err);
719
+ * })
720
+ */
721
+ async coordinates(params) {
722
+ (0, checkCaptchaParams_1.default)(params, "base64");
723
+ const payload = {
724
+ ...params,
725
+ method: "base64",
726
+ coordinatescaptcha: 1,
727
+ ...this.defaultPayload,
728
+ };
729
+ const URL = this.in;
730
+ const response = await (0, fetch_1.default)(URL, {
731
+ method: 'post',
732
+ body: JSON.stringify(payload),
733
+ headers: { 'Content-Type': 'application/json' }
734
+ });
735
+ const result = await response.text();
736
+ let data;
737
+ try {
738
+ data = JSON.parse(result);
739
+ }
740
+ catch {
741
+ throw new _2captchaError_1.APIError(result);
742
+ }
743
+ if (data.status == 1) {
744
+ return this.pollResponse(data.request);
745
+ }
746
+ else {
747
+ throw new _2captchaError_1.APIError(data.request);
748
+ }
749
+ }
750
+ /**
751
+ * pageurl: string,
752
+ captchakey: string,
753
+ api_server?: string,
754
+ version?: string,
755
+ header_acao?: boolean,
756
+ pingback?: string,
757
+ proxy?: string,
758
+ proxytype?: string,
759
+ */
760
+ /**
761
+ * ### Solves Capy Puzzle captcha
762
+ *
763
+ * @param {{ pageurl, captchakey, api_server, version, pingback, proxy, proxytype}} params Parameters Capy Puzzle Captcha as an object.
764
+ * @param {string} params.pageurl Full `URL`of the page where you see the captcha.
765
+ * @param {string} params.captchakey Value of `captchakey` parameter you found on page.
766
+ * @param {string} params.api_server The domain part of script URL you found on page. Default value: `https://jp.api.capy.me/`.
767
+ * @param {string} params.version The version of captcha task: `puzzle` (assemble a puzzle) or `avatar` (drag an object)..
768
+ * @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).
769
+ * @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).
770
+ * @param {string} params.proxytype Type of your proxy: `HTTP`, `HTTPS`, `SOCKS4`, `SOCKS5`.
771
+ *
772
+ * @example
773
+ * solver.capyPuzzle({
774
+ * pageurl: "https://www.capy.me/account/register/",
775
+ * captchakey: "PUZZLE_Cme4hZLjuZRMYC3uh14C52D3uNms5w"
776
+ * })
777
+ * .then((res) => {
778
+ * console.log(res);
779
+ * })
780
+ * .catch((err) => {
781
+ * console.log(err);
782
+ * })
783
+ */
784
+ async capyPuzzle(params) {
785
+ (0, checkCaptchaParams_1.default)(params, "capy");
786
+ const payload = {
787
+ ...params,
788
+ method: "capy",
789
+ ...this.defaultPayload,
790
+ };
791
+ const response = await (0, fetch_1.default)(this.in + utils.objectToURI(payload));
792
+ const result = await response.text();
793
+ let data;
794
+ try {
795
+ data = JSON.parse(result);
796
+ }
797
+ catch {
798
+ throw new _2captchaError_1.APIError(result);
799
+ }
800
+ if (data.status == 1) {
801
+ return this.pollResponse(data.request);
802
+ }
803
+ else {
804
+ throw new _2captchaError_1.APIError(data.request);
805
+ }
806
+ }
807
+ /**
808
+ * ### Solves DataDome captcha
809
+ *
810
+ * @param {{ pageurl, captcha_url, userAgent, pingback, proxy, proxytype}} params Parameters DataDome Captcha as an object.
811
+ * @param {string} params.pageurl Full `URL` of the page where you see the captcha.
812
+ * @param {string} params.captcha_url The value of the `src` parameter for the `iframe` element containing the captcha on the page.
813
+ * @param {string} params.userAgent ser-Agent of your MODERN browser
814
+ * @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).
815
+ * @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).
816
+ * @param {string} params.proxytype Type of your proxy: `HTTP`, `HTTPS`, `SOCKS4`, `SOCKS5`.
817
+ *
818
+ * @example
819
+ * solver.dataDome({
820
+ * pageurl: "https://rendezvousparis.hermes.com/client/register",
821
+ * 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",
822
+ * userAgent: "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/118.0.0.0 Safari/537.36",
823
+ * proxy: "1.2.3.4:8888:user:password",
824
+ * proxytype: "http"
825
+ * })
826
+ * .then((res) => {
827
+ * console.log(res);
828
+ * })
829
+ * .catch((err) => {
830
+ * console.log(err);
831
+ * })
832
+ */
833
+ async dataDome(params) {
834
+ (0, checkCaptchaParams_1.default)(params, "datadome");
835
+ const payload = {
836
+ ...params,
837
+ method: "datadome",
838
+ ...this.defaultPayload,
839
+ };
840
+ const response = await (0, fetch_1.default)(this.in + utils.objectToURI(payload));
841
+ const result = await response.text();
842
+ let data;
843
+ try {
844
+ data = JSON.parse(result);
845
+ }
846
+ catch {
847
+ throw new _2captchaError_1.APIError(result);
848
+ }
849
+ if (data.status == 1) {
850
+ return this.pollResponse(data.request);
851
+ }
852
+ else {
853
+ throw new _2captchaError_1.APIError(data.request);
854
+ }
855
+ }
856
+ /**
857
+ * ### Solves CyberSiARA captcha
858
+ *
859
+ * @param {{ pageurl, master_url_id, userAgent, pingback, proxy, proxytype}} params Parameters CyberSiARA Captcha as an object.
860
+ * @param {string} params.pageurl Full `URL` of the page where you see the captcha.
861
+ * @param {string} params.master_url_id The value of `MasterUrlId` parameter obtained from the request to the endpoint `API/CyberSiara/GetCyberSiara`.
862
+ * @param {string} params.userAgent ser-Agent of your MODERN browser
863
+ * @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).
864
+ * @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).
865
+ * @param {string} params.proxytype Type of your proxy: `HTTP`, `HTTPS`, `SOCKS4`, `SOCKS5`.
866
+ *
867
+ * @example
868
+ * solver.cyberSiARA({
869
+ * pageurl: "https://www.cybersiara.com/book-a-demo",
870
+ * master_url_id: "OXR2LVNvCuXykkZbB8KZIfh162sNT8S2",
871
+ * userAgent: "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/118.0.0.0 Safari/537.36"
872
+ * })
873
+ * .then((res) => {
874
+ * console.log(res);
875
+ * })
876
+ * .catch((err) => {
877
+ * console.log(err);
878
+ * })
879
+ */
880
+ async cyberSiARA(params) {
881
+ (0, checkCaptchaParams_1.default)(params, "cybersiara");
882
+ const payload = {
883
+ ...params,
884
+ method: "cybersiara",
885
+ ...this.defaultPayload,
886
+ };
887
+ const response = await (0, fetch_1.default)(this.in + utils.objectToURI(payload));
888
+ const result = await response.text();
889
+ let data;
890
+ try {
891
+ data = JSON.parse(result);
892
+ }
893
+ catch {
894
+ throw new _2captchaError_1.APIError(result);
895
+ }
896
+ if (data.status == 1) {
897
+ return this.pollResponse(data.request);
898
+ }
899
+ else {
900
+ throw new _2captchaError_1.APIError(data.request);
901
+ }
902
+ }
903
+ /**
904
+ * ### Solves MTCaptcha
905
+ *
906
+ * @param {{ pageurl, sitekey, userAgent, pingback, proxy, proxytype}} params Parameters MTCaptcha as an object.
907
+ * @param {string} params.pageurl Full `URL` of the page where you see the captcha.
908
+ * @param {string} params.sitekey TThe value of `sitekey` parameter found on the page.
909
+ * @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).
910
+ * @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).
911
+ * @param {string} params.proxytype Type of your proxy: `HTTP`, `HTTPS`, `SOCKS4`, `SOCKS5`.
912
+ *
913
+ * @example
914
+ * solver.mtCaptcha({
915
+ * pageurl: "https://service.mtcaptcha.com/mtcv1/demo/index.html",
916
+ * sitekey: "MTPublic-DemoKey9M"
917
+ * })
918
+ * .then((res) => {
919
+ * console.log(res);
920
+ * })
921
+ * .catch((err) => {
922
+ * console.log(err);
923
+ * })
924
+ */
925
+ async mtCaptcha(params) {
926
+ (0, checkCaptchaParams_1.default)(params, "mt_captcha");
927
+ const payload = {
928
+ ...params,
929
+ method: "mt_captcha",
930
+ ...this.defaultPayload,
931
+ };
932
+ const response = await (0, fetch_1.default)(this.in + utils.objectToURI(payload));
933
+ const result = await response.text();
934
+ let data;
935
+ try {
936
+ data = JSON.parse(result);
937
+ }
938
+ catch {
939
+ throw new _2captchaError_1.APIError(result);
940
+ }
941
+ if (data.status == 1) {
942
+ return this.pollResponse(data.request);
943
+ }
944
+ else {
945
+ throw new _2captchaError_1.APIError(data.request);
946
+ }
947
+ }
948
+ /**
949
+ * ### Solves Cutcaptcha
950
+ *
951
+ * @param {{ pageurl, sitekey, userAgent, pingback, proxy, proxytype}} params Parameters MTCaptcha as an object.
952
+ * @param {string} params.pageurl Full `URL` of the page where you see the captcha.
953
+ * @param {string} params.sitekey TThe value of `sitekey` parameter found on the page.
954
+ * @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).
955
+ * @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).
956
+ * @param {string} params.proxytype Type of your proxy: `HTTP`, `HTTPS`, `SOCKS4`, `SOCKS5`.
957
+ *
958
+ * @example
959
+ * solver.cutCaptcha({
960
+ * pageurl: "https://service.mtcaptcha.com/mtcv1/demo/index.html",
961
+ * sitekey: "MTPublic-DemoKey9M"
962
+ * })
963
+ * .then((res) => {
964
+ * console.log(res);
965
+ * })
966
+ * .catch((err) => {
967
+ * console.log(err);
968
+ * })
969
+ */
970
+ async cutCaptcha(params) {
971
+ (0, checkCaptchaParams_1.default)(params, "mt_captcha");
972
+ const payload = {
973
+ ...params,
974
+ method: "mt_captcha",
975
+ ...this.defaultPayload,
976
+ };
977
+ const response = await (0, fetch_1.default)(this.in + utils.objectToURI(payload));
978
+ const result = await response.text();
979
+ let data;
980
+ try {
981
+ data = JSON.parse(result);
982
+ }
983
+ catch {
984
+ throw new _2captchaError_1.APIError(result);
985
+ }
986
+ if (data.status == 1) {
987
+ return this.pollResponse(data.request);
988
+ }
989
+ else {
990
+ throw new _2captchaError_1.APIError(data.request);
991
+ }
992
+ }
993
+ /**
994
+ * ### Solves Friendly Captcha
995
+ *
996
+ * @param {{ pageurl, sitekey, pingback, proxy, proxytype}} params Parameters Friendly Captcha as an object.
997
+ * @param {string} params.pageurl Full `URL` of the page where you see the captcha.
998
+ * @param {string} params.sitekey The value of `data-apikey` or `data-sitekey` parameter found on the page.
999
+ * @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).
1000
+ * @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).
1001
+ * @param {string} params.proxytype Type of your proxy: `HTTP`, `HTTPS`, `SOCKS4`, `SOCKS5`.
1002
+ *
1003
+ * @example
1004
+ * solver.friendlyCaptcha({
1005
+ * pageurl: "https://geizhals.de/?liftban=1&from=/455973138?fsean=5901747021356",
1006
+ * sitekey: "FCMST5VUMCBOCGQ9"
1007
+ * })
1008
+ * .then((res) => {
1009
+ * console.log(res);
1010
+ * })
1011
+ * .catch((err) => {
1012
+ * console.log(err);
1013
+ * })
1014
+ */
1015
+ async friendlyCaptcha(params) {
1016
+ (0, checkCaptchaParams_1.default)(params, "friendly_captcha");
1017
+ const payload = {
1018
+ ...params,
1019
+ method: "friendly_captcha",
1020
+ ...this.defaultPayload,
1021
+ };
1022
+ const response = await (0, fetch_1.default)(this.in + utils.objectToURI(payload));
1023
+ const result = await response.text();
1024
+ let data;
1025
+ try {
1026
+ data = JSON.parse(result);
1027
+ }
1028
+ catch {
1029
+ throw new _2captchaError_1.APIError(result);
1030
+ }
1031
+ if (data.status == 1) {
1032
+ return this.pollResponse(data.request);
1033
+ }
1034
+ else {
1035
+ throw new _2captchaError_1.APIError(data.request);
1036
+ }
1037
+ }
1038
+ /**
1039
+ * ### Bounding Box Method
1040
+ *
1041
+ * @param {{ image, textinstructions, imginstructions }} params Parameters Bounding Box Method as an object.
1042
+ * @param {image} params.image Image containing data for markup. The image must be encoded in `Base64` format.
1043
+ * @param {textinstructions} 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`.
1044
+ * @param {imginstructions} 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`.
1045
+ *
1046
+ * @example
1047
+ * solver.boundingBox({
1048
+ * image: "data:image/jpeg;base64,/9j/4AAQSkZJRgABAQAAAQABAAD/2wBDAAgG...",
1049
+ * textinstructions: "Select cars in the image"
1050
+ * })
1051
+ * .then((res) => {
1052
+ * console.log(res);
1053
+ * })
1054
+ * .catch((err) => {
1055
+ * console.log(err);
1056
+ * })
1057
+ */
1058
+ async boundingBox(params) {
1059
+ (0, checkCaptchaParams_1.default)(params, "bounding_box");
1060
+ const payload = {
1061
+ ...params,
1062
+ method: "bounding_box",
1063
+ ...this.defaultPayload,
1064
+ };
1065
+ const URL = this.in;
1066
+ const response = await (0, fetch_1.default)(URL, {
1067
+ body: JSON.stringify(payload),
1068
+ method: "post",
1069
+ headers: { 'Content-Type': 'application/json' }
1070
+ });
1071
+ const result = await response.text();
1072
+ let data;
1073
+ try {
1074
+ data = JSON.parse(result);
1075
+ }
1076
+ catch {
1077
+ throw new _2captchaError_1.APIError(result);
1078
+ }
1079
+ if (data.status == 1) {
1080
+ return this.pollResponse(data.request);
1081
+ }
1082
+ else {
1083
+ throw new _2captchaError_1.APIError(data.request);
1084
+ }
1085
+ }
1086
+ /**
1087
+ * Reports a captcha as correctly solved.
1088
+ *
1089
+ * @param {string} id The ID of the captcha
1090
+ * @throws APIError
1091
+ * @example
1092
+ * solver.goodReport("7031854546")
1093
+ *
1094
+ */
1095
+ async goodReport(id) {
1096
+ const payload = {
1097
+ id: id,
1098
+ action: "reportgood",
1099
+ ...this.defaultPayload
1100
+ };
1101
+ const response = await (0, fetch_1.default)(this.res + utils.objectToURI(payload));
1102
+ const result = await response.text();
1103
+ let data;
1104
+ try {
1105
+ data = JSON.parse(result);
1106
+ }
1107
+ catch {
1108
+ throw new _2captchaError_1.APIError(result);
1109
+ }
1110
+ if (data.request == "OK_REPORT_RECORDED") {
1111
+ return data.request;
1112
+ }
1113
+ else {
1114
+ throw new _2captchaError_1.APIError(data.request);
1115
+ }
1116
+ }
1117
+ /**
1118
+ * Report an unsuccessful solve
1119
+ *
1120
+ * @param {string} id The id of the captcha solve
1121
+ *
1122
+ * @returns {Promise<void>} Resolves on completion
1123
+ * @throws APIError
1124
+ * @example
1125
+ * solver.badReport("7031854546")
1126
+ */
1127
+ async badReport(id) {
1128
+ const payload = {
1129
+ id: id,
1130
+ action: "reportbad",
1131
+ ...this.defaultPayload
1132
+ };
1133
+ const response = await (0, fetch_1.default)(this.res + utils.objectToURI(payload));
1134
+ const result = await response.text();
1135
+ let data;
1136
+ try {
1137
+ data = JSON.parse(result);
1138
+ }
1139
+ catch {
1140
+ throw new _2captchaError_1.APIError(result);
1141
+ }
1142
+ if (data.request == "OK_REPORT_RECORDED" || data.request == "ERROR_DUPLICATE_REPORT") {
1143
+ return data.request;
1144
+ }
1145
+ else {
1146
+ throw new _2captchaError_1.APIError(data.request);
1147
+ }
1148
+ }
1149
+ }
1150
+ exports.Solver = Solver;