@captchafox/react 1.5.1 → 1.6.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.cjs +38 -20
- package/dist/index.d.cts +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.js +38 -20
- package/package.json +2 -2
package/dist/index.cjs
CHANGED
|
@@ -57,31 +57,51 @@ __export(src_exports, {
|
|
|
57
57
|
module.exports = __toCommonJS(src_exports);
|
|
58
58
|
|
|
59
59
|
// ../internal/dist/index.mjs
|
|
60
|
-
var
|
|
61
|
-
var
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
60
|
+
var backoff = (retryCount) => Math.exp(retryCount) * 150;
|
|
61
|
+
var withRetry = (_0, ..._1) => __async(void 0, [_0, ..._1], function* (callback, { attempts = 4 } = {}) {
|
|
62
|
+
let error;
|
|
63
|
+
for (let i = 0; i < attempts; i++) {
|
|
64
|
+
try {
|
|
65
|
+
return yield callback();
|
|
66
|
+
} catch (err) {
|
|
67
|
+
error = err;
|
|
68
|
+
yield new Promise((r) => setTimeout(r, backoff(i)));
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
throw error != null ? error : new Error("Exhausted all retries");
|
|
65
72
|
});
|
|
73
|
+
var mountInstance;
|
|
66
74
|
var LOAD_FUNC_KEY = "captchaFoxOnLoad";
|
|
67
75
|
var SCRIPT_SRC = `https://cdn.captchafox.com/api.js?render=explicit&onload=${LOAD_FUNC_KEY}`;
|
|
68
|
-
function
|
|
76
|
+
function loadScript() {
|
|
69
77
|
return __async(this, arguments, function* ({ nonce } = {}) {
|
|
70
|
-
if (document.querySelector(`script[src="${SCRIPT_SRC}"]`))
|
|
78
|
+
if (mountInstance && document.querySelector(`script[src="${SCRIPT_SRC}"]`)) {
|
|
71
79
|
return mountInstance;
|
|
72
|
-
window[LOAD_FUNC_KEY] = resolveFn;
|
|
73
|
-
const script = document.createElement("script");
|
|
74
|
-
script.src = SCRIPT_SRC;
|
|
75
|
-
script.async = true;
|
|
76
|
-
script.defer = true;
|
|
77
|
-
script.onerror = rejectFn;
|
|
78
|
-
if (nonce) {
|
|
79
|
-
script.nonce = nonce;
|
|
80
80
|
}
|
|
81
|
-
|
|
81
|
+
mountInstance = new Promise((resolve, reject) => {
|
|
82
|
+
window[LOAD_FUNC_KEY] = resolve;
|
|
83
|
+
const script = document.createElement("script");
|
|
84
|
+
script.src = SCRIPT_SRC;
|
|
85
|
+
script.async = true;
|
|
86
|
+
script.defer = true;
|
|
87
|
+
script.onerror = (e) => {
|
|
88
|
+
script.remove();
|
|
89
|
+
mountInstance = void 0;
|
|
90
|
+
reject(e);
|
|
91
|
+
};
|
|
92
|
+
if (nonce) {
|
|
93
|
+
script.nonce = nonce;
|
|
94
|
+
}
|
|
95
|
+
document.body.appendChild(script);
|
|
96
|
+
});
|
|
82
97
|
return mountInstance;
|
|
83
98
|
});
|
|
84
99
|
}
|
|
100
|
+
function loadCaptchaScript() {
|
|
101
|
+
return __async(this, arguments, function* (props = {}) {
|
|
102
|
+
return withRetry(() => loadScript(props));
|
|
103
|
+
});
|
|
104
|
+
}
|
|
85
105
|
var isApiReady = () => typeof (window == null ? void 0 : window.captchafox) !== "undefined";
|
|
86
106
|
|
|
87
107
|
// src/CaptchaFox.tsx
|
|
@@ -148,8 +168,7 @@ var CaptchaFox = (0, import_react.forwardRef)(
|
|
|
148
168
|
const renderCaptcha = () => __async(void 0, null, function* () {
|
|
149
169
|
var _a, _b, _c;
|
|
150
170
|
(_a = window.captchafox) == null ? void 0 : _a.remove(widgetId);
|
|
151
|
-
if (!containerRef || ((_b = containerRef == null ? void 0 : containerRef.children) == null ? void 0 : _b.length) === 1)
|
|
152
|
-
return;
|
|
171
|
+
if (!containerRef || ((_b = containerRef == null ? void 0 : containerRef.children) == null ? void 0 : _b.length) === 1) return;
|
|
153
172
|
const newWidgetId = yield (_c = window.captchafox) == null ? void 0 : _c.render(containerRef, {
|
|
154
173
|
lang,
|
|
155
174
|
sitekey,
|
|
@@ -164,8 +183,7 @@ var CaptchaFox = (0, import_react.forwardRef)(
|
|
|
164
183
|
setWidgetId(newWidgetId);
|
|
165
184
|
});
|
|
166
185
|
(0, import_react.useEffect)(() => {
|
|
167
|
-
if (!containerRef)
|
|
168
|
-
return;
|
|
186
|
+
if (!containerRef) return;
|
|
169
187
|
if (firstRendered.current) {
|
|
170
188
|
if (isApiReady()) {
|
|
171
189
|
renderCaptcha();
|
package/dist/index.d.cts
CHANGED
|
@@ -11,4 +11,4 @@ declare const CaptchaFox: React.ForwardRefExoticComponent<WidgetOptions & {
|
|
|
11
11
|
|
|
12
12
|
declare const CAPTCHA_RESPONSE_KEY = "cf-captcha-response";
|
|
13
13
|
|
|
14
|
-
export { CAPTCHA_RESPONSE_KEY, CaptchaFox, CaptchaFoxInstance };
|
|
14
|
+
export { CAPTCHA_RESPONSE_KEY, CaptchaFox, type CaptchaFoxInstance };
|
package/dist/index.d.ts
CHANGED
|
@@ -11,4 +11,4 @@ declare const CaptchaFox: React.ForwardRefExoticComponent<WidgetOptions & {
|
|
|
11
11
|
|
|
12
12
|
declare const CAPTCHA_RESPONSE_KEY = "cf-captcha-response";
|
|
13
13
|
|
|
14
|
-
export { CAPTCHA_RESPONSE_KEY, CaptchaFox, CaptchaFoxInstance };
|
|
14
|
+
export { CAPTCHA_RESPONSE_KEY, CaptchaFox, type CaptchaFoxInstance };
|
package/dist/index.js
CHANGED
|
@@ -21,31 +21,51 @@ var __async = (__this, __arguments, generator) => {
|
|
|
21
21
|
};
|
|
22
22
|
|
|
23
23
|
// ../internal/dist/index.mjs
|
|
24
|
-
var
|
|
25
|
-
var
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
24
|
+
var backoff = (retryCount) => Math.exp(retryCount) * 150;
|
|
25
|
+
var withRetry = (_0, ..._1) => __async(void 0, [_0, ..._1], function* (callback, { attempts = 4 } = {}) {
|
|
26
|
+
let error;
|
|
27
|
+
for (let i = 0; i < attempts; i++) {
|
|
28
|
+
try {
|
|
29
|
+
return yield callback();
|
|
30
|
+
} catch (err) {
|
|
31
|
+
error = err;
|
|
32
|
+
yield new Promise((r) => setTimeout(r, backoff(i)));
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
throw error != null ? error : new Error("Exhausted all retries");
|
|
29
36
|
});
|
|
37
|
+
var mountInstance;
|
|
30
38
|
var LOAD_FUNC_KEY = "captchaFoxOnLoad";
|
|
31
39
|
var SCRIPT_SRC = `https://cdn.captchafox.com/api.js?render=explicit&onload=${LOAD_FUNC_KEY}`;
|
|
32
|
-
function
|
|
40
|
+
function loadScript() {
|
|
33
41
|
return __async(this, arguments, function* ({ nonce } = {}) {
|
|
34
|
-
if (document.querySelector(`script[src="${SCRIPT_SRC}"]`))
|
|
42
|
+
if (mountInstance && document.querySelector(`script[src="${SCRIPT_SRC}"]`)) {
|
|
35
43
|
return mountInstance;
|
|
36
|
-
window[LOAD_FUNC_KEY] = resolveFn;
|
|
37
|
-
const script = document.createElement("script");
|
|
38
|
-
script.src = SCRIPT_SRC;
|
|
39
|
-
script.async = true;
|
|
40
|
-
script.defer = true;
|
|
41
|
-
script.onerror = rejectFn;
|
|
42
|
-
if (nonce) {
|
|
43
|
-
script.nonce = nonce;
|
|
44
44
|
}
|
|
45
|
-
|
|
45
|
+
mountInstance = new Promise((resolve, reject) => {
|
|
46
|
+
window[LOAD_FUNC_KEY] = resolve;
|
|
47
|
+
const script = document.createElement("script");
|
|
48
|
+
script.src = SCRIPT_SRC;
|
|
49
|
+
script.async = true;
|
|
50
|
+
script.defer = true;
|
|
51
|
+
script.onerror = (e) => {
|
|
52
|
+
script.remove();
|
|
53
|
+
mountInstance = void 0;
|
|
54
|
+
reject(e);
|
|
55
|
+
};
|
|
56
|
+
if (nonce) {
|
|
57
|
+
script.nonce = nonce;
|
|
58
|
+
}
|
|
59
|
+
document.body.appendChild(script);
|
|
60
|
+
});
|
|
46
61
|
return mountInstance;
|
|
47
62
|
});
|
|
48
63
|
}
|
|
64
|
+
function loadCaptchaScript() {
|
|
65
|
+
return __async(this, arguments, function* (props = {}) {
|
|
66
|
+
return withRetry(() => loadScript(props));
|
|
67
|
+
});
|
|
68
|
+
}
|
|
49
69
|
var isApiReady = () => typeof (window == null ? void 0 : window.captchafox) !== "undefined";
|
|
50
70
|
|
|
51
71
|
// src/CaptchaFox.tsx
|
|
@@ -112,8 +132,7 @@ var CaptchaFox = forwardRef(
|
|
|
112
132
|
const renderCaptcha = () => __async(void 0, null, function* () {
|
|
113
133
|
var _a, _b, _c;
|
|
114
134
|
(_a = window.captchafox) == null ? void 0 : _a.remove(widgetId);
|
|
115
|
-
if (!containerRef || ((_b = containerRef == null ? void 0 : containerRef.children) == null ? void 0 : _b.length) === 1)
|
|
116
|
-
return;
|
|
135
|
+
if (!containerRef || ((_b = containerRef == null ? void 0 : containerRef.children) == null ? void 0 : _b.length) === 1) return;
|
|
117
136
|
const newWidgetId = yield (_c = window.captchafox) == null ? void 0 : _c.render(containerRef, {
|
|
118
137
|
lang,
|
|
119
138
|
sitekey,
|
|
@@ -128,8 +147,7 @@ var CaptchaFox = forwardRef(
|
|
|
128
147
|
setWidgetId(newWidgetId);
|
|
129
148
|
});
|
|
130
149
|
useEffect(() => {
|
|
131
|
-
if (!containerRef)
|
|
132
|
-
return;
|
|
150
|
+
if (!containerRef) return;
|
|
133
151
|
if (firstRendered.current) {
|
|
134
152
|
if (isApiReady()) {
|
|
135
153
|
renderCaptcha();
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@captchafox/react",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.6.0",
|
|
4
4
|
"main": "./dist/index.cjs",
|
|
5
5
|
"module": "./dist/index.js",
|
|
6
6
|
"types": "./dist/index.d.ts",
|
|
@@ -50,7 +50,7 @@
|
|
|
50
50
|
"jest": "^29.7.0",
|
|
51
51
|
"jest-environment-jsdom": "^29.7.0",
|
|
52
52
|
"react": "^18.2.0",
|
|
53
|
-
"tsup": "^
|
|
53
|
+
"tsup": "^8.3.5",
|
|
54
54
|
"ts-jest": "^29.1.1",
|
|
55
55
|
"typescript": "^5.0.2"
|
|
56
56
|
},
|