@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,6 @@
1
+ export declare class APIError extends Error {
2
+ err: string;
3
+ code: number;
4
+ constructor(err: string);
5
+ }
6
+ //# sourceMappingURL=2captchaError.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"2captchaError.d.ts","sourceRoot":"","sources":["../../src/structs/2captchaError.ts"],"names":[],"mappings":"AAAA,qBAAa,QAAS,SAAQ,KAAK;IAEZ,GAAG,EAAE,MAAM;IAD9B,IAAI,EAAE,MAAM,CAAA;gBACO,GAAG,EAAE,MAAM;CA+JjC"}
@@ -0,0 +1,275 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.APIError = void 0;
4
+ class APIError extends Error {
5
+ constructor(err) {
6
+ super(err);
7
+ this.err = err;
8
+ this.name = this.constructor.name;
9
+ switch (err) {
10
+ case "ERROR_CAPTCHA_UNSOLVABLE":
11
+ {
12
+ this.code = 1;
13
+ this.message = "Your captcha was unable to be solved after 3 attempts. You haven't been charged for this request.";
14
+ }
15
+ ;
16
+ break;
17
+ case "ERROR_WRONG_USER_KEY":
18
+ {
19
+ this.code = 2;
20
+ this.message = "You've specified an invalid key, please make sure it is 32 characters long.";
21
+ }
22
+ ;
23
+ break;
24
+ case "ERROR_KEY_DOES_NOT_EXIST":
25
+ {
26
+ this.code = 3;
27
+ this.message = "The key you've provided does not exist.";
28
+ }
29
+ ;
30
+ break;
31
+ case "ERROR_BAD_DUPLICATES":
32
+ {
33
+ this.code = 4;
34
+ this.message = "The max number of attempts for this captcha has been reached. Please validate.";
35
+ }
36
+ ;
37
+ break;
38
+ case "REPORT_NOT_RECORDED":
39
+ {
40
+ this.code = 5;
41
+ this.message = "You have submitted an invalid report. Either you've submitted over 40% of recent captchas, or the captcha was solved over 15 minutes ago.";
42
+ }
43
+ ;
44
+ break;
45
+ case "ERROR_DUPLICATE_REPORT":
46
+ {
47
+ this.code = 6;
48
+ this.message = "You have already reported this captcha!";
49
+ }
50
+ ;
51
+ break;
52
+ case "ERROR_IMAGE_TYPE_NOT_SUPPORTED":
53
+ {
54
+ this.code = 7;
55
+ this.message = "The image type is not supported. Please validate it's a valid image you're passing through.";
56
+ }
57
+ ;
58
+ break;
59
+ case "ERROR_ZERO_CAPTCHA_FILESIZE":
60
+ {
61
+ this.code = 8;
62
+ this.message = "The image has no size, and is not valid. Please verify it.";
63
+ }
64
+ ;
65
+ break;
66
+ case "ERROR_ZERO_BALANCE":
67
+ {
68
+ this.code = 9;
69
+ this.message = "There aren't enough funds in this account to complete the captcha.";
70
+ }
71
+ ;
72
+ break;
73
+ case "ERROR_PAGEURL":
74
+ {
75
+ this.code = 10;
76
+ this.message = "pageurl paramter is missing in the request.";
77
+ }
78
+ ;
79
+ break;
80
+ case "ERROR_NO_SLOT_AVAILABLE":
81
+ {
82
+ this.code = 11;
83
+ this.message = "Captcha Queue exceeded maximum capacity. Please wait a few moments before continuing, or update your settings at https://2captcha.com/setting";
84
+ }
85
+ ;
86
+ break;
87
+ case "ERROR_TOO_BIG_CAPTCHA_FILESIZE":
88
+ {
89
+ this.code = 12;
90
+ this.message = "The Image Filesize exceeds 100kb. Please check the image file.";
91
+ }
92
+ ;
93
+ break;
94
+ case "ERROR_WRONG_FILE_EXTENSION":
95
+ {
96
+ this.code = 13;
97
+ this.message = "Unsupported file extension. Accepted extensions: jpg, jpeg, gif, png.";
98
+ }
99
+ ;
100
+ break;
101
+ case "ERROR_UPLOAD":
102
+ {
103
+ this.code = 14;
104
+ this.message = "The Solve Request was malformed. Please make sure the image is valid. If it is, please open up a github issue detailing this event.";
105
+ }
106
+ ;
107
+ break;
108
+ case "ERROR_IP_NOT_ALLOWED":
109
+ {
110
+ this.code = 15;
111
+ this.message = "The request is sent from an IP that is not on the allowed list. Please configure it here https://2captcha.com/setting/iplist";
112
+ }
113
+ ;
114
+ break;
115
+ case "IP_BANNED":
116
+ {
117
+ this.code = 16;
118
+ this.message = "This IP address is banned due to frequent attempts to access the server via incorrect auth keys. Please try again in 5 minutes.";
119
+ }
120
+ ;
121
+ break;
122
+ case "ERROR_BAD_TOKEN_OR_PAGEURL":
123
+ {
124
+ this.code = 17;
125
+ this.message = "Please insure the googlekey and pageurl are correct for this reCaptcha request.";
126
+ }
127
+ ;
128
+ break;
129
+ case "ERROR_GOOGLEKEY":
130
+ {
131
+ this.code = 18;
132
+ this.message = "Please insure the sitekey provided is correct, and try again.";
133
+ }
134
+ ;
135
+ break;
136
+ case "ERROR_WRONG_GOOGLEKEY":
137
+ {
138
+ this.code = 19;
139
+ this.message = "The 'googlekey' parameter is missing or of an invalid format. Please make sure it is a valid string.";
140
+ }
141
+ ;
142
+ break;
143
+ case "ERROR_CAPTCHAIMAGE_BLOCKED":
144
+ {
145
+ this.code = 20;
146
+ this.message = "You've sent an image that is marked in our database as unrecognizable. Usually that happens if the website where you found the captcha stopped sending you captchas and started to send 'deny access' image.";
147
+ }
148
+ ;
149
+ break;
150
+ case "TOO_MANY_BAD_IMAGES":
151
+ {
152
+ this.code = 21;
153
+ this.message = "You're sending too many unrecognizable images. Please make sure the images are valid and understandable.";
154
+ }
155
+ ;
156
+ break;
157
+ case "MAX_USER_TURN":
158
+ {
159
+ this.code = 22;
160
+ this.message = "You've made more then 60 requests to in.php within 3 seconds. Please slow down requests, and wait 10 seconds for this restriction to be lifted.";
161
+ }
162
+ ;
163
+ break;
164
+ case "ERROR_BAD_PARAMETERS":
165
+ {
166
+ this.code = 23;
167
+ this.message = "Some parameters are missing in this request. If you're using a pre-provided function, please open up an issue on the GitHub";
168
+ }
169
+ ;
170
+ break;
171
+ case "ERROR_BAD_PROXY":
172
+ {
173
+ this.code = 24;
174
+ this.message = "The proxy provided did not work.";
175
+ }
176
+ ;
177
+ break;
178
+ case "ERROR_CAPTCHA_ID":
179
+ {
180
+ this.code = 250;
181
+ this.message = "One of the parameters is incorrect. If you are submitting GeeTest V4 captcha, then check that the \'captcha_id\' parameter is correct.";
182
+ }
183
+ ;
184
+ break;
185
+ // Start for Res.php errors
186
+ case "CAPCHA_NOT_READY":
187
+ {
188
+ this.code = 25;
189
+ this.message = "The captcha is not solved yet. If you see this error, Please open up an issue on the GitHub";
190
+ }
191
+ ;
192
+ break;
193
+ case "ERROR_WRONG_ID_FORMAT":
194
+ {
195
+ this.code = 26;
196
+ this.message = "You've provided a captcha ID in the wrong format. The ID can contain only numbers.";
197
+ }
198
+ ;
199
+ break;
200
+ case "ERROR_WRONG_CAPTCHA_ID":
201
+ {
202
+ this.code = 27;
203
+ this.message = "You've provided an incorrect captcha ID.";
204
+ }
205
+ ;
206
+ break;
207
+ case "ERROR_BAD_DUPLICATES":
208
+ {
209
+ this.code = 28;
210
+ this.message = "The number of attempts has been reached, but the minimum number of matches was not hit.";
211
+ }
212
+ ;
213
+ break;
214
+ case "ERROR_REPORT_NOT_RECORDED":
215
+ {
216
+ this.code = 29;
217
+ this.message = "You've submitted more then 40% reports, or are reporting a captcha older then 15 minutes. This report has been ignored.";
218
+ }
219
+ ;
220
+ break;
221
+ case "ERROR_DUPLICATE_REPORT":
222
+ {
223
+ this.code = 30;
224
+ this.message = "You've already reported this captcha. This report is ignored.";
225
+ }
226
+ ;
227
+ break;
228
+ case "ERROR_IP_ADDRES":
229
+ {
230
+ this.code = 31;
231
+ this.message = "The PingBack/CallBack IP did not match the source of this request.";
232
+ }
233
+ ;
234
+ break;
235
+ case "ERROR_TOKEN_EXPIRED":
236
+ {
237
+ this.code = 32;
238
+ this.message = "The 'challenge' value for the GeeTest Captcha has already expired.";
239
+ }
240
+ ;
241
+ break;
242
+ case "ERROR_EMPTY_ACTION":
243
+ {
244
+ this.code = 33;
245
+ this.message = "The ACtion parameter is missing. Please open an issue in the GitHub";
246
+ }
247
+ ;
248
+ break;
249
+ case "ERROR_PROXY_CONNECTION_FAILED":
250
+ {
251
+ this.code = 34;
252
+ this.message = "The proxy server was unable to load the captcha. This Proxy has been marked as bad, and will recieve an 'ERROR_BAD_PROXY' in future use.";
253
+ }
254
+ ;
255
+ break;
256
+ // @Victor, I hate you. Debugging this took a minute or two, but those two minutes were *very* irritating.
257
+ // It doesn't follow 2captcha's error codes, and it's not documented in the 'Error Handling' tab of your API docs! :P
258
+ case "https://2captcha.com/blog/google-search-recaptcha":
259
+ {
260
+ this.code = 35;
261
+ this.message = "This captcha appears to be a Google Service Captcha (A special captcha that Google uses to protect their websites). Please provide a 'data-s' attribute in the CaptchaExtras of this function. View https://2captcha.com/blog/google-search-recaptcha for more information.";
262
+ }
263
+ ;
264
+ break;
265
+ default:
266
+ {
267
+ console.log(err);
268
+ this.code = 0;
269
+ this.message = "An Unexpected Error has occured. Please submit an issue on GitHub detailing this event.";
270
+ }
271
+ ;
272
+ }
273
+ }
274
+ }
275
+ exports.APIError = APIError;
@@ -0,0 +1,36 @@
1
+ /// <reference types="node" />
2
+ import { EventEmitter } from "events";
3
+ import { paramsRecaptcha } from "./2captcha.js";
4
+ export interface ServerCaptchaResult {
5
+ data: string;
6
+ id: string;
7
+ }
8
+ export interface ServerEvents {
9
+ "recaptcha": (captcha: ServerCaptchaResult) => void;
10
+ "hcaptcha": (captcha: ServerCaptchaResult) => void;
11
+ }
12
+ export interface Server {
13
+ on<U extends keyof ServerEvents>(event: U, listener: ServerEvents[U]): this;
14
+ }
15
+ /**
16
+ * ! WIP
17
+ * This class will bind an http server to a specific port to allow for post requests from the 2captcha site, providing
18
+ * an alternative to manually polling each captcha. A feature 2captcha allows for massive solve requirements.
19
+ */
20
+ export declare class Server extends EventEmitter {
21
+ private _apikey;
22
+ private _headerACAO;
23
+ private _serverAddr;
24
+ private _serverPort;
25
+ private _pingbackString;
26
+ private _terminated;
27
+ constructor(apikey: string, serverAddr: string, serverPort: number, pingbackString: string, enableACAO?: boolean);
28
+ private server;
29
+ private get defaultPayload();
30
+ /**
31
+ * Termintes the running HTTP server.
32
+ */
33
+ terminate(): void;
34
+ requestRecaptcha(params: paramsRecaptcha): void;
35
+ }
36
+ //# sourceMappingURL=2captchaServer.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"2captchaServer.d.ts","sourceRoot":"","sources":["../../src/structs/2captchaServer.ts"],"names":[],"mappings":";AAAA,OAAO,EAAE,YAAY,EAAE,MAAM,QAAQ,CAAC;AACtC,OAAO,EAAE,eAAe,EAAE,MAAM,eAAe,CAAC;AAKhD,MAAM,WAAW,mBAAmB;IAChC,IAAI,EAAE,MAAM,CAAC;IACb,EAAE,EAAE,MAAM,CAAA;CACb;AAED,MAAM,WAAW,YAAY;IACzB,WAAW,EAAE,CAAC,OAAO,EAAE,mBAAmB,KAAK,IAAI,CAAC;IACpD,UAAU,EAAE,CAAC,OAAO,EAAE,mBAAmB,KAAK,IAAI,CAAC;CACtD;AAED,MAAM,WAAW,MAAM;IACnB,EAAE,CAAC,CAAC,SAAS,MAAM,YAAY,EAC3B,KAAK,EAAE,CAAC,EAAE,QAAQ,EAAE,YAAY,CAAC,CAAC,CAAC,GACpC,IAAI,CAAC;CACX;AAED;;;;GAIG;AACH,qBAAa,MAAO,SAAQ,YAAY;IACpC,OAAO,CAAC,OAAO,CAAS;IACxB,OAAO,CAAC,WAAW,CAAS;IAE5B,OAAO,CAAC,WAAW,CAAS;IAC5B,OAAO,CAAC,WAAW,CAAS;IAC5B,OAAO,CAAC,eAAe,CAAS;IAEhC,OAAO,CAAC,WAAW,CAAkB;gBAEzB,MAAM,EAAE,MAAM,EAAE,UAAU,EAAE,MAAM,EAAE,UAAU,EAAE,MAAM,EAAE,cAAc,EAAE,MAAM,EAAE,UAAU,GAAE,OAAc;YAWxG,MAAM;IA8BpB,OAAO,KAAK,cAAc,GAIzB;IAED;;OAEG;IACI,SAAS;IAGhB,gBAAgB,CAAC,MAAM,EAAE,eAAe;CAO3C"}
@@ -0,0 +1,91 @@
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
+ Object.defineProperty(exports, "__esModule", { value: true });
26
+ exports.Server = void 0;
27
+ const events_1 = require("events");
28
+ // For creating the server
29
+ const http = __importStar(require("http"));
30
+ /**
31
+ * ! WIP
32
+ * This class will bind an http server to a specific port to allow for post requests from the 2captcha site, providing
33
+ * an alternative to manually polling each captcha. A feature 2captcha allows for massive solve requirements.
34
+ */
35
+ class Server extends events_1.EventEmitter {
36
+ constructor(apikey, serverAddr, serverPort, pingbackString, enableACAO = true) {
37
+ super();
38
+ this._terminated = false;
39
+ this._apikey = apikey;
40
+ this._headerACAO = enableACAO ? 1 : 0;
41
+ this._serverAddr = serverAddr;
42
+ this._serverPort = serverPort;
43
+ this._pingbackString = pingbackString;
44
+ this.server();
45
+ }
46
+ async server() {
47
+ const server = http.createServer((req, res) => {
48
+ if (req.method == "POST") {
49
+ let body = '';
50
+ req.on('data', chunk => {
51
+ body += chunk.toString(); // convert Buffer to string
52
+ });
53
+ req.on('end', () => {
54
+ console.log(body);
55
+ res.end('ok');
56
+ });
57
+ }
58
+ if (req.method == "GET" && req.url == "/2captcha.txt") {
59
+ console.log("writing");
60
+ res.write(this._pingbackString, "utf8");
61
+ res.end();
62
+ }
63
+ });
64
+ server.listen(this._serverPort);
65
+ // let i = setInterval(() => {
66
+ // if (this._terminated == true) {
67
+ // clearInterval(i);
68
+ // server.close();
69
+ // }
70
+ // }, 100)
71
+ }
72
+ get defaultPayload() {
73
+ return {
74
+ key: this._apikey, json: 1, header_acao: this._headerACAO, soft_id: 4587
75
+ };
76
+ }
77
+ /**
78
+ * Termintes the running HTTP server.
79
+ */
80
+ terminate() {
81
+ this._terminated = true;
82
+ }
83
+ requestRecaptcha(params) {
84
+ const payload = {
85
+ ...params,
86
+ method: "userrecaptcha",
87
+ ...this.defaultPayload
88
+ };
89
+ }
90
+ }
91
+ exports.Server = Server;
@@ -0,0 +1,15 @@
1
+ declare const softId: number;
2
+ declare const supportedProviders: {
3
+ twoCaptcha: {
4
+ name: string;
5
+ in: string;
6
+ res: string;
7
+ };
8
+ ruCaptcha: {
9
+ name: string;
10
+ in: string;
11
+ res: string;
12
+ };
13
+ };
14
+ export { supportedProviders, softId };
15
+ //# sourceMappingURL=constants.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"constants.d.ts","sourceRoot":"","sources":["../../../src/structs/constants/constants.ts"],"names":[],"mappings":"AASA,QAAA,MAAM,MAAM,EAAE,MAAa,CAAA;AAE3B,QAAA,MAAM,kBAAkB;;;;;;;;;;;CAWvB,CAAA;AAED,OAAO,EAAE,kBAAkB,EAAE,MAAM,EAAE,CAAA"}
@@ -0,0 +1,25 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.softId = exports.supportedProviders = void 0;
4
+ const twoCaptchaName = '2captcha';
5
+ const twoCaptchaIn = 'https://2captcha.com/in.php';
6
+ const twoCaptchaRes = 'https://2captcha.com/res.php';
7
+ const ruCaptchaName = 'ruCaptcha';
8
+ const ruCaptchaIn = 'https://rucaptcha.com/in.php';
9
+ const ruCaptchaRes = 'https://rucaptcha.com/res.php';
10
+ // TODO: add the ability to specify softid in the constructor of the `Captcha` class
11
+ const softId = 4587;
12
+ exports.softId = softId;
13
+ const supportedProviders = {
14
+ twoCaptcha: {
15
+ name: twoCaptchaName,
16
+ in: twoCaptchaIn,
17
+ res: twoCaptchaRes
18
+ },
19
+ ruCaptcha: {
20
+ name: ruCaptchaName,
21
+ in: ruCaptchaIn,
22
+ res: ruCaptchaRes
23
+ }
24
+ };
25
+ exports.supportedProviders = supportedProviders;
@@ -0,0 +1,6 @@
1
+ export default function getProviderData(provider?: string): {
2
+ name: string;
3
+ in: string;
4
+ res: string;
5
+ };
6
+ //# sourceMappingURL=providers.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"providers.d.ts","sourceRoot":"","sources":["../../../src/structs/providers/providers.ts"],"names":[],"mappings":"AAIA,MAAM,CAAC,OAAO,UAAU,eAAe,CAAE,QAAQ,SAAkB;;;;EAiBlE"}
@@ -0,0 +1,20 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ const constants_1 = require("../constants/constants");
4
+ const defautlProvider = constants_1.supportedProviders.twoCaptcha.name;
5
+ function getProviderData(provider = defautlProvider) {
6
+ const currentProvider = provider;
7
+ let currentProviderData;
8
+ switch (currentProvider) {
9
+ case '2captcha':
10
+ currentProviderData = constants_1.supportedProviders.twoCaptcha;
11
+ break;
12
+ case 'ruCaptcha':
13
+ currentProviderData = constants_1.supportedProviders.ruCaptcha;
14
+ break;
15
+ default:
16
+ currentProviderData = constants_1.supportedProviders.twoCaptcha;
17
+ }
18
+ return currentProviderData;
19
+ }
20
+ exports.default = getProviderData;
@@ -0,0 +1,8 @@
1
+ /**
2
+ * @param { Object } params Captcha parameters that need to be checked.
3
+ * @returns true | false | Error
4
+ * @example
5
+ * checkCaptchaParams(params, 'userrecaptcha')
6
+ */
7
+ export default function checkCaptchaParams(params: Object, method: string): boolean | undefined;
8
+ //# sourceMappingURL=checkCaptchaParams.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"checkCaptchaParams.d.ts","sourceRoot":"","sources":["../../src/utils/checkCaptchaParams.ts"],"names":[],"mappings":"AAqFA;;;;;GAKG;AACH,MAAM,CAAC,OAAO,UAAU,kBAAkB,CAAC,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,uBAgCxE"}
@@ -0,0 +1,119 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ // Captcha methods for which parameter checking is available
4
+ const supportedMethods = ["userrecaptcha", "hcaptcha", "geetest", "geetest_v4", "yandex", "funcaptcha", "lemin", "amazon_waf",
5
+ "turnstile", "base64", "capy", "datadome", "cybersiara", "mt_captcha", "bounding_box", 'friendly_captcha'];
6
+ // Names of required fields that must be contained in the parameters captcha
7
+ const recaptchaRequiredFields = ['pageurl', 'googlekey'];
8
+ const hcaptchaRequiredFields = ['pageurl', 'sitekey'];
9
+ const geetestRequiredFields = ['pageurl', 'gt', 'challenge'];
10
+ const geetestV4RequiredFields = ['pageurl', 'captcha_id'];
11
+ const yandexSmartRequiredFields = ['pageurl', 'sitekey'];
12
+ const funCaptchaRequiredFields = ['pageurl', 'publickey'];
13
+ const leminRequiredFields = ['pageurl', 'div_id', 'captcha_id'];
14
+ const amazonWafRequiredFields = ['pageurl', 'context', 'iv', 'sitekey'];
15
+ const turnstileRequiredFields = ['pageurl', 'sitekey'];
16
+ // `base64RequiredFields` for Normal Captcha and Coordinates captcha
17
+ const base64RequiredFields = ['body'];
18
+ const capyPuzzleRequiredFields = ['captchakey'];
19
+ const dataDomeRequiredFields = ['pageurl', 'captcha_url', 'userAgent', 'proxy', 'proxytype'];
20
+ const сyberSiARARequiredFields = ['pageurl', 'master_url_id', 'userAgent'];
21
+ const mtСaptchaRequiredFields = ['pageurl', 'sitekey'];
22
+ const boundingBoxRequiredFields = ['image']; // and textinstructions or imginstructions
23
+ const friendlyCaptchaFields = ['pageurl', 'sitekey'];
24
+ /**
25
+ * Getting required arguments for a captcha.
26
+ *
27
+ * @param {string} method method for solving captcha.
28
+ * @returns {Array} An array containing the required arguments for this captcha
29
+ */
30
+ const getRequiredFildsArr = (method) => {
31
+ let requiredFieldsArr = ['pageurl'];
32
+ switch (method) {
33
+ case "userrecaptcha":
34
+ requiredFieldsArr = recaptchaRequiredFields;
35
+ break;
36
+ case "hcaptcha":
37
+ requiredFieldsArr = hcaptchaRequiredFields;
38
+ break;
39
+ case "geetest":
40
+ requiredFieldsArr = geetestRequiredFields;
41
+ break;
42
+ case "geetest_v4":
43
+ requiredFieldsArr = geetestV4RequiredFields;
44
+ break;
45
+ case "yandex":
46
+ requiredFieldsArr = yandexSmartRequiredFields;
47
+ break;
48
+ case "funcaptcha":
49
+ requiredFieldsArr = funCaptchaRequiredFields;
50
+ break;
51
+ case "lemin":
52
+ requiredFieldsArr = leminRequiredFields;
53
+ break;
54
+ case "amazon_waf":
55
+ requiredFieldsArr = amazonWafRequiredFields;
56
+ break;
57
+ case "turnstile":
58
+ requiredFieldsArr = turnstileRequiredFields;
59
+ break;
60
+ case "base64":
61
+ requiredFieldsArr = base64RequiredFields;
62
+ break;
63
+ case "capy":
64
+ requiredFieldsArr = capyPuzzleRequiredFields;
65
+ break;
66
+ case "datadome":
67
+ requiredFieldsArr = dataDomeRequiredFields;
68
+ break;
69
+ case "cybersiara":
70
+ requiredFieldsArr = сyberSiARARequiredFields;
71
+ break;
72
+ case "mt_captcha":
73
+ requiredFieldsArr = mtСaptchaRequiredFields;
74
+ break;
75
+ case "bounding_box":
76
+ requiredFieldsArr = boundingBoxRequiredFields;
77
+ break;
78
+ case "friendly_captcha":
79
+ requiredFieldsArr = friendlyCaptchaFields;
80
+ break;
81
+ }
82
+ return requiredFieldsArr;
83
+ };
84
+ /**
85
+ * @param { Object } params Captcha parameters that need to be checked.
86
+ * @returns true | false | Error
87
+ * @example
88
+ * checkCaptchaParams(params, 'userrecaptcha')
89
+ */
90
+ function checkCaptchaParams(params, method) {
91
+ let isCorrectCaptchaParams;
92
+ const isIncorrectCaptchaMethod = !supportedMethods.includes(method);
93
+ if (isIncorrectCaptchaMethod) {
94
+ isCorrectCaptchaParams = false;
95
+ throw new Error(`Error when check params captcha. \nNot found "${method}" method in the "supportedMethods" array. \nCheck if the method is written correctly `);
96
+ }
97
+ const requiredFields = getRequiredFildsArr(method);
98
+ requiredFields.forEach(fieldName => {
99
+ const isThisFieldNotAvailable = !params.hasOwnProperty(fieldName);
100
+ if (isThisFieldNotAvailable) {
101
+ isCorrectCaptchaParams = false;
102
+ throw new Error(`Error when check params captcha.\nNot found "${fieldName}" field in the Object. Field "${fieldName}" is required for "${method}" method. Please add field "${fieldName}" in object and try again.\nPlease correct your code for the "${method}" method according to the code examples`);
103
+ }
104
+ else {
105
+ isCorrectCaptchaParams = true;
106
+ }
107
+ });
108
+ if (method === "bounding_box") {
109
+ if (params.hasOwnProperty('textinstructions') || params.hasOwnProperty('imginstructions')) {
110
+ isCorrectCaptchaParams = true;
111
+ }
112
+ else {
113
+ isCorrectCaptchaParams = false;
114
+ throw new Error(`Error when check params captcha.\nNot found "textinstructions" or "imginstructions" field in the Object. One of this field is required for "bounding_box" method. Please add field "textinstructions" or "imginstructions" in object and try again.\nPlease correct your code for the "bounding_box" method according to the code examples`);
115
+ }
116
+ }
117
+ return isCorrectCaptchaParams;
118
+ }
119
+ exports.default = checkCaptchaParams;
@@ -0,0 +1,4 @@
1
+ import nodeFetch from 'node-fetch';
2
+ declare const _default: (((input: RequestInfo | URL, init?: RequestInit | undefined) => Promise<Response>) & typeof fetch) | typeof nodeFetch;
3
+ export = _default;
4
+ //# sourceMappingURL=fetch.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"fetch.d.ts","sourceRoot":"","sources":["../../src/utils/fetch.ts"],"names":[],"mappings":"AAAA,OAAO,SAAS,MAAM,YAAY,CAAC;;AAEnC,kBAA8E"}
@@ -0,0 +1,6 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ const node_fetch_1 = __importDefault(require("node-fetch"));
6
+ module.exports = typeof window === 'undefined' ? node_fetch_1.default : window.fetch.bind(window);
@@ -0,0 +1,21 @@
1
+ /**
2
+ * Changes 0 and 1 falsy/truthy values into a boolean.
3
+ * @private
4
+ * @param input boolean or number
5
+ */
6
+ export declare function castBool(input: boolean | number): 0 | 1;
7
+ /**
8
+ * Constructs uri parameters from an object
9
+ * @private
10
+ * @param input The input object
11
+ */
12
+ export declare function objectToURI(input: {
13
+ [key: string]: string | number | boolean;
14
+ } | any): string;
15
+ /**
16
+ * Returns a promise that resolves after x ms
17
+ * @private
18
+ * @param ms time to sleep for
19
+ */
20
+ export declare function sleep(ms: number): Promise<unknown>;
21
+ //# sourceMappingURL=generic.d.ts.map