@captchafox/node 1.4.0 → 1.5.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.js CHANGED
@@ -80,7 +80,8 @@ async function verifyRequest(secret, token, sitekey, remoteIp) {
80
80
  method: "POST",
81
81
  headers: {
82
82
  "content-type": "application/x-www-form-urlencoded",
83
- "content-length": Buffer.byteLength(data)
83
+ "content-length": Buffer.byteLength(data),
84
+ "x-spark": `nj-${"1.5.0"}`
84
85
  }
85
86
  };
86
87
  const apiRequest = (0, import_https.request)(options, (response) => {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@captchafox/node",
3
- "version": "1.4.0",
3
+ "version": "1.5.0",
4
4
  "main": "./dist/index.js",
5
5
  "module": "./dist/index.mjs",
6
6
  "types": "./dist/index.d.ts",
@@ -22,7 +22,7 @@
22
22
  }
23
23
  },
24
24
  "scripts": {
25
- "build": "tsup src/index.ts --format esm,cjs --dts",
25
+ "build": "tsup src/index.ts",
26
26
  "dev": "tsup src/index.ts --format esm,cjs --watch --dts",
27
27
  "lint": "TIMING=1 eslint \"src/**/*.ts*\"",
28
28
  "clean": "rm -rf .turbo && rm -rf node_modules && rm -rf dist",
package/dist/index.d.mts DELETED
@@ -1,42 +0,0 @@
1
- type ParseErrorProps = {
2
- code?: number;
3
- message: string;
4
- body: string;
5
- };
6
- declare class ParseError extends Error {
7
- code: number | undefined;
8
- body: string;
9
- constructor({ code, message, body }: ParseErrorProps);
10
- }
11
-
12
- /**
13
- * The response returned from the /siteverify
14
- * endpoint used for verifying the challenge token.
15
- */
16
- type VerifyResponse = {
17
- /** Whether verification succeeded or not */
18
- success: boolean;
19
- /**
20
- * ISO timestamp of the challenge (yyyy-MM-dd'T'HH:mm:ssZZ).
21
- * Only included on success.
22
- */
23
- challenge_ts?: string;
24
- /** Hostname of the site where the challenge was solved. Optional */
25
- hostname?: string;
26
- /** List of error codes. Only included if success is false */
27
- 'error-codes'?: string[];
28
- };
29
- type OptionalProps = {
30
- /** (Optional) The sitekey that was used to issue the token */
31
- sitekey?: string;
32
- /** (Optional) The IP address of the requesting user */
33
- remoteIp?: string;
34
- retry?: {
35
- attempts?: number;
36
- };
37
- };
38
- declare function verify(secret: string, token: string, options?: OptionalProps): Promise<VerifyResponse>;
39
-
40
- declare const CAPTCHA_RESPONSE_KEY = "cf-captcha-response";
41
-
42
- export { CAPTCHA_RESPONSE_KEY, ParseError, type VerifyResponse, verify };
package/dist/index.d.ts DELETED
@@ -1,42 +0,0 @@
1
- type ParseErrorProps = {
2
- code?: number;
3
- message: string;
4
- body: string;
5
- };
6
- declare class ParseError extends Error {
7
- code: number | undefined;
8
- body: string;
9
- constructor({ code, message, body }: ParseErrorProps);
10
- }
11
-
12
- /**
13
- * The response returned from the /siteverify
14
- * endpoint used for verifying the challenge token.
15
- */
16
- type VerifyResponse = {
17
- /** Whether verification succeeded or not */
18
- success: boolean;
19
- /**
20
- * ISO timestamp of the challenge (yyyy-MM-dd'T'HH:mm:ssZZ).
21
- * Only included on success.
22
- */
23
- challenge_ts?: string;
24
- /** Hostname of the site where the challenge was solved. Optional */
25
- hostname?: string;
26
- /** List of error codes. Only included if success is false */
27
- 'error-codes'?: string[];
28
- };
29
- type OptionalProps = {
30
- /** (Optional) The sitekey that was used to issue the token */
31
- sitekey?: string;
32
- /** (Optional) The IP address of the requesting user */
33
- remoteIp?: string;
34
- retry?: {
35
- attempts?: number;
36
- };
37
- };
38
- declare function verify(secret: string, token: string, options?: OptionalProps): Promise<VerifyResponse>;
39
-
40
- declare const CAPTCHA_RESPONSE_KEY = "cf-captcha-response";
41
-
42
- export { CAPTCHA_RESPONSE_KEY, ParseError, type VerifyResponse, verify };
package/dist/index.mjs DELETED
@@ -1,100 +0,0 @@
1
- // src/errors/ParseError.ts
2
- var ParseError = class extends Error {
3
- code;
4
- body;
5
- constructor({ code, message, body }) {
6
- super(message);
7
- this.code = code;
8
- this.body = body;
9
- }
10
- };
11
-
12
- // src/verify.ts
13
- import { request } from "https";
14
- import { stringify } from "querystring";
15
-
16
- // src/withRetry.ts
17
- var backoff = (retryCount) => Math.exp(retryCount) * 100;
18
- var withRetry = async (callback, { attempts = 4 } = {}) => {
19
- let res;
20
- let error;
21
- for (let i = 0; i < attempts; i++) {
22
- try {
23
- res = await callback();
24
- break;
25
- } catch (err) {
26
- error = err;
27
- await new Promise((r) => setTimeout(r, backoff(i)));
28
- }
29
- }
30
- if (!res) {
31
- throw error ?? new Error("Exhausted all retries");
32
- }
33
- return res;
34
- };
35
-
36
- // src/verify.ts
37
- var HOST = "api.captchafox.com";
38
- var API_PATH = "/siteverify";
39
- async function verifyRequest(secret, token, sitekey, remoteIp) {
40
- return new Promise(function verifyPromise(resolve, reject) {
41
- const payload = { secret, response: token };
42
- if (sitekey) {
43
- payload.sitekey = sitekey;
44
- }
45
- if (remoteIp) {
46
- payload.remoteIp = remoteIp;
47
- }
48
- const data = stringify(payload);
49
- const options = {
50
- host: HOST,
51
- path: API_PATH,
52
- method: "POST",
53
- headers: {
54
- "content-type": "application/x-www-form-urlencoded",
55
- "content-length": Buffer.byteLength(data)
56
- }
57
- };
58
- const apiRequest = request(options, (response) => {
59
- response.setEncoding("utf8");
60
- let responseBuffer = "";
61
- response.on("error", (error) => {
62
- reject(error);
63
- }).on("data", (chunk) => responseBuffer += chunk).on("end", () => {
64
- try {
65
- const json = JSON.parse(responseBuffer);
66
- resolve(json);
67
- } catch (error) {
68
- if (error instanceof SyntaxError) {
69
- const errorResponse = new ParseError({
70
- code: response.statusCode,
71
- message: error.message,
72
- body: responseBuffer
73
- });
74
- reject(errorResponse);
75
- return;
76
- }
77
- reject(error);
78
- }
79
- });
80
- });
81
- apiRequest.on("error", (error) => {
82
- reject(error);
83
- });
84
- apiRequest.write(data);
85
- apiRequest.end();
86
- });
87
- }
88
- async function verify(secret, token, options) {
89
- return withRetry(() => {
90
- return verifyRequest(secret, token, options == null ? void 0 : options.sitekey, options == null ? void 0 : options.remoteIp);
91
- }, options == null ? void 0 : options.retry);
92
- }
93
-
94
- // src/index.ts
95
- var CAPTCHA_RESPONSE_KEY = "cf-captcha-response";
96
- export {
97
- CAPTCHA_RESPONSE_KEY,
98
- ParseError,
99
- verify
100
- };