@captchafox/react 1.8.0 → 1.10.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 +25 -4
- package/dist/index.js +25 -4
- package/package.json +2 -2
package/dist/index.cjs
CHANGED
|
@@ -127,13 +127,17 @@ var CaptchaFox = (0, import_react.forwardRef)(
|
|
|
127
127
|
onVerify,
|
|
128
128
|
onLoad,
|
|
129
129
|
onFail,
|
|
130
|
-
onClose
|
|
130
|
+
onClose,
|
|
131
|
+
onChallengeChange,
|
|
132
|
+
onChallengeOpen
|
|
131
133
|
}, ref) => {
|
|
132
134
|
const [containerRef, setContainerRef] = (0, import_react.useState)();
|
|
133
135
|
const [widgetId, setWidgetId] = (0, import_react.useState)();
|
|
134
136
|
const firstRendered = (0, import_react.useRef)(false);
|
|
135
137
|
const onReady = (0, import_react.useRef)();
|
|
136
138
|
const executeTimeout = (0, import_react.useRef)();
|
|
139
|
+
const scriptErrorListener = (0, import_react.useRef)();
|
|
140
|
+
const hasScriptError = (0, import_react.useRef)(false);
|
|
137
141
|
(0, import_react.useImperativeHandle)(
|
|
138
142
|
ref,
|
|
139
143
|
() => {
|
|
@@ -161,6 +165,9 @@ var CaptchaFox = (0, import_react.forwardRef)(
|
|
|
161
165
|
window.captchafox.remove(widgetId);
|
|
162
166
|
},
|
|
163
167
|
execute: () => __async(void 0, null, function* () {
|
|
168
|
+
if (hasScriptError.current) {
|
|
169
|
+
return Promise.reject(new RetryError());
|
|
170
|
+
}
|
|
164
171
|
if (!isApiReady() || !widgetId) {
|
|
165
172
|
return waitAndExecute();
|
|
166
173
|
}
|
|
@@ -182,7 +189,9 @@ var CaptchaFox = (0, import_react.forwardRef)(
|
|
|
182
189
|
}
|
|
183
190
|
}, [widgetId]);
|
|
184
191
|
(0, import_react.useEffect)(() => {
|
|
185
|
-
return () =>
|
|
192
|
+
return () => {
|
|
193
|
+
clearEvents();
|
|
194
|
+
};
|
|
186
195
|
}, []);
|
|
187
196
|
(0, import_react.useEffect)(() => {
|
|
188
197
|
if (!containerRef) return;
|
|
@@ -197,18 +206,28 @@ var CaptchaFox = (0, import_react.forwardRef)(
|
|
|
197
206
|
yield renderCaptcha();
|
|
198
207
|
}
|
|
199
208
|
})).catch((err) => {
|
|
209
|
+
var _a;
|
|
200
210
|
onError == null ? void 0 : onError(err);
|
|
211
|
+
hasScriptError.current = true;
|
|
212
|
+
(_a = scriptErrorListener.current) == null ? void 0 : _a.call(scriptErrorListener);
|
|
201
213
|
console.error("[CaptchaFox] Could not load script:", err);
|
|
202
214
|
});
|
|
203
215
|
}
|
|
204
216
|
}, [containerRef, sitekey, lang, mode]);
|
|
217
|
+
const clearEvents = () => {
|
|
218
|
+
clearTimeout(executeTimeout.current);
|
|
219
|
+
};
|
|
205
220
|
const waitAndExecute = () => {
|
|
206
221
|
return new Promise((resolve, reject) => {
|
|
222
|
+
scriptErrorListener.current = () => {
|
|
223
|
+
clearEvents();
|
|
224
|
+
reject(new RetryError());
|
|
225
|
+
};
|
|
207
226
|
executeTimeout.current = setTimeout(() => {
|
|
208
227
|
reject(new TimeoutError("Execute timed out"));
|
|
209
228
|
}, executeTimeoutSeconds * 1e3);
|
|
210
229
|
onReady.current = (id) => {
|
|
211
|
-
|
|
230
|
+
clearEvents();
|
|
212
231
|
window.captchafox.execute(id).then(resolve).catch((error) => {
|
|
213
232
|
const errorType = getErrorType(error);
|
|
214
233
|
reject(errorType);
|
|
@@ -235,7 +254,9 @@ var CaptchaFox = (0, import_react.forwardRef)(
|
|
|
235
254
|
onError,
|
|
236
255
|
onFail,
|
|
237
256
|
onClose,
|
|
238
|
-
onVerify
|
|
257
|
+
onVerify,
|
|
258
|
+
onChallengeChange,
|
|
259
|
+
onChallengeOpen
|
|
239
260
|
});
|
|
240
261
|
if (!newWidgetId) {
|
|
241
262
|
return;
|
package/dist/index.js
CHANGED
|
@@ -89,13 +89,17 @@ var CaptchaFox = forwardRef(
|
|
|
89
89
|
onVerify,
|
|
90
90
|
onLoad,
|
|
91
91
|
onFail,
|
|
92
|
-
onClose
|
|
92
|
+
onClose,
|
|
93
|
+
onChallengeChange,
|
|
94
|
+
onChallengeOpen
|
|
93
95
|
}, ref) => {
|
|
94
96
|
const [containerRef, setContainerRef] = useState();
|
|
95
97
|
const [widgetId, setWidgetId] = useState();
|
|
96
98
|
const firstRendered = useRef(false);
|
|
97
99
|
const onReady = useRef();
|
|
98
100
|
const executeTimeout = useRef();
|
|
101
|
+
const scriptErrorListener = useRef();
|
|
102
|
+
const hasScriptError = useRef(false);
|
|
99
103
|
useImperativeHandle(
|
|
100
104
|
ref,
|
|
101
105
|
() => {
|
|
@@ -123,6 +127,9 @@ var CaptchaFox = forwardRef(
|
|
|
123
127
|
window.captchafox.remove(widgetId);
|
|
124
128
|
},
|
|
125
129
|
execute: () => __async(void 0, null, function* () {
|
|
130
|
+
if (hasScriptError.current) {
|
|
131
|
+
return Promise.reject(new RetryError());
|
|
132
|
+
}
|
|
126
133
|
if (!isApiReady() || !widgetId) {
|
|
127
134
|
return waitAndExecute();
|
|
128
135
|
}
|
|
@@ -144,7 +151,9 @@ var CaptchaFox = forwardRef(
|
|
|
144
151
|
}
|
|
145
152
|
}, [widgetId]);
|
|
146
153
|
useEffect(() => {
|
|
147
|
-
return () =>
|
|
154
|
+
return () => {
|
|
155
|
+
clearEvents();
|
|
156
|
+
};
|
|
148
157
|
}, []);
|
|
149
158
|
useEffect(() => {
|
|
150
159
|
if (!containerRef) return;
|
|
@@ -159,18 +168,28 @@ var CaptchaFox = forwardRef(
|
|
|
159
168
|
yield renderCaptcha();
|
|
160
169
|
}
|
|
161
170
|
})).catch((err) => {
|
|
171
|
+
var _a;
|
|
162
172
|
onError == null ? void 0 : onError(err);
|
|
173
|
+
hasScriptError.current = true;
|
|
174
|
+
(_a = scriptErrorListener.current) == null ? void 0 : _a.call(scriptErrorListener);
|
|
163
175
|
console.error("[CaptchaFox] Could not load script:", err);
|
|
164
176
|
});
|
|
165
177
|
}
|
|
166
178
|
}, [containerRef, sitekey, lang, mode]);
|
|
179
|
+
const clearEvents = () => {
|
|
180
|
+
clearTimeout(executeTimeout.current);
|
|
181
|
+
};
|
|
167
182
|
const waitAndExecute = () => {
|
|
168
183
|
return new Promise((resolve, reject) => {
|
|
184
|
+
scriptErrorListener.current = () => {
|
|
185
|
+
clearEvents();
|
|
186
|
+
reject(new RetryError());
|
|
187
|
+
};
|
|
169
188
|
executeTimeout.current = setTimeout(() => {
|
|
170
189
|
reject(new TimeoutError("Execute timed out"));
|
|
171
190
|
}, executeTimeoutSeconds * 1e3);
|
|
172
191
|
onReady.current = (id) => {
|
|
173
|
-
|
|
192
|
+
clearEvents();
|
|
174
193
|
window.captchafox.execute(id).then(resolve).catch((error) => {
|
|
175
194
|
const errorType = getErrorType(error);
|
|
176
195
|
reject(errorType);
|
|
@@ -197,7 +216,9 @@ var CaptchaFox = forwardRef(
|
|
|
197
216
|
onError,
|
|
198
217
|
onFail,
|
|
199
218
|
onClose,
|
|
200
|
-
onVerify
|
|
219
|
+
onVerify,
|
|
220
|
+
onChallengeChange,
|
|
221
|
+
onChallengeOpen
|
|
201
222
|
});
|
|
202
223
|
if (!newWidgetId) {
|
|
203
224
|
return;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@captchafox/react",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.10.0",
|
|
4
4
|
"main": "./dist/index.cjs",
|
|
5
5
|
"module": "./dist/index.js",
|
|
6
6
|
"types": "./dist/index.d.ts",
|
|
@@ -35,7 +35,7 @@
|
|
|
35
35
|
"react-dom": ">=16.8.0"
|
|
36
36
|
},
|
|
37
37
|
"dependencies": {
|
|
38
|
-
"@captchafox/types": "^1.
|
|
38
|
+
"@captchafox/types": "^1.4.0"
|
|
39
39
|
},
|
|
40
40
|
"devDependencies": {
|
|
41
41
|
"@captchafox/tsconfig": "*",
|