@captchafox/react 1.8.0 → 1.9.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 +19 -2
- package/dist/index.js +19 -2
- package/package.json +1 -1
package/dist/index.cjs
CHANGED
|
@@ -134,6 +134,8 @@ var CaptchaFox = (0, import_react.forwardRef)(
|
|
|
134
134
|
const firstRendered = (0, import_react.useRef)(false);
|
|
135
135
|
const onReady = (0, import_react.useRef)();
|
|
136
136
|
const executeTimeout = (0, import_react.useRef)();
|
|
137
|
+
const scriptErrorListener = (0, import_react.useRef)();
|
|
138
|
+
const hasScriptError = (0, import_react.useRef)(false);
|
|
137
139
|
(0, import_react.useImperativeHandle)(
|
|
138
140
|
ref,
|
|
139
141
|
() => {
|
|
@@ -161,6 +163,9 @@ var CaptchaFox = (0, import_react.forwardRef)(
|
|
|
161
163
|
window.captchafox.remove(widgetId);
|
|
162
164
|
},
|
|
163
165
|
execute: () => __async(void 0, null, function* () {
|
|
166
|
+
if (hasScriptError.current) {
|
|
167
|
+
return Promise.reject(new RetryError());
|
|
168
|
+
}
|
|
164
169
|
if (!isApiReady() || !widgetId) {
|
|
165
170
|
return waitAndExecute();
|
|
166
171
|
}
|
|
@@ -182,7 +187,9 @@ var CaptchaFox = (0, import_react.forwardRef)(
|
|
|
182
187
|
}
|
|
183
188
|
}, [widgetId]);
|
|
184
189
|
(0, import_react.useEffect)(() => {
|
|
185
|
-
return () =>
|
|
190
|
+
return () => {
|
|
191
|
+
clearEvents();
|
|
192
|
+
};
|
|
186
193
|
}, []);
|
|
187
194
|
(0, import_react.useEffect)(() => {
|
|
188
195
|
if (!containerRef) return;
|
|
@@ -197,18 +204,28 @@ var CaptchaFox = (0, import_react.forwardRef)(
|
|
|
197
204
|
yield renderCaptcha();
|
|
198
205
|
}
|
|
199
206
|
})).catch((err) => {
|
|
207
|
+
var _a;
|
|
200
208
|
onError == null ? void 0 : onError(err);
|
|
209
|
+
hasScriptError.current = true;
|
|
210
|
+
(_a = scriptErrorListener.current) == null ? void 0 : _a.call(scriptErrorListener);
|
|
201
211
|
console.error("[CaptchaFox] Could not load script:", err);
|
|
202
212
|
});
|
|
203
213
|
}
|
|
204
214
|
}, [containerRef, sitekey, lang, mode]);
|
|
215
|
+
const clearEvents = () => {
|
|
216
|
+
clearTimeout(executeTimeout.current);
|
|
217
|
+
};
|
|
205
218
|
const waitAndExecute = () => {
|
|
206
219
|
return new Promise((resolve, reject) => {
|
|
220
|
+
scriptErrorListener.current = () => {
|
|
221
|
+
clearEvents();
|
|
222
|
+
reject(new RetryError());
|
|
223
|
+
};
|
|
207
224
|
executeTimeout.current = setTimeout(() => {
|
|
208
225
|
reject(new TimeoutError("Execute timed out"));
|
|
209
226
|
}, executeTimeoutSeconds * 1e3);
|
|
210
227
|
onReady.current = (id) => {
|
|
211
|
-
|
|
228
|
+
clearEvents();
|
|
212
229
|
window.captchafox.execute(id).then(resolve).catch((error) => {
|
|
213
230
|
const errorType = getErrorType(error);
|
|
214
231
|
reject(errorType);
|
package/dist/index.js
CHANGED
|
@@ -96,6 +96,8 @@ var CaptchaFox = forwardRef(
|
|
|
96
96
|
const firstRendered = useRef(false);
|
|
97
97
|
const onReady = useRef();
|
|
98
98
|
const executeTimeout = useRef();
|
|
99
|
+
const scriptErrorListener = useRef();
|
|
100
|
+
const hasScriptError = useRef(false);
|
|
99
101
|
useImperativeHandle(
|
|
100
102
|
ref,
|
|
101
103
|
() => {
|
|
@@ -123,6 +125,9 @@ var CaptchaFox = forwardRef(
|
|
|
123
125
|
window.captchafox.remove(widgetId);
|
|
124
126
|
},
|
|
125
127
|
execute: () => __async(void 0, null, function* () {
|
|
128
|
+
if (hasScriptError.current) {
|
|
129
|
+
return Promise.reject(new RetryError());
|
|
130
|
+
}
|
|
126
131
|
if (!isApiReady() || !widgetId) {
|
|
127
132
|
return waitAndExecute();
|
|
128
133
|
}
|
|
@@ -144,7 +149,9 @@ var CaptchaFox = forwardRef(
|
|
|
144
149
|
}
|
|
145
150
|
}, [widgetId]);
|
|
146
151
|
useEffect(() => {
|
|
147
|
-
return () =>
|
|
152
|
+
return () => {
|
|
153
|
+
clearEvents();
|
|
154
|
+
};
|
|
148
155
|
}, []);
|
|
149
156
|
useEffect(() => {
|
|
150
157
|
if (!containerRef) return;
|
|
@@ -159,18 +166,28 @@ var CaptchaFox = forwardRef(
|
|
|
159
166
|
yield renderCaptcha();
|
|
160
167
|
}
|
|
161
168
|
})).catch((err) => {
|
|
169
|
+
var _a;
|
|
162
170
|
onError == null ? void 0 : onError(err);
|
|
171
|
+
hasScriptError.current = true;
|
|
172
|
+
(_a = scriptErrorListener.current) == null ? void 0 : _a.call(scriptErrorListener);
|
|
163
173
|
console.error("[CaptchaFox] Could not load script:", err);
|
|
164
174
|
});
|
|
165
175
|
}
|
|
166
176
|
}, [containerRef, sitekey, lang, mode]);
|
|
177
|
+
const clearEvents = () => {
|
|
178
|
+
clearTimeout(executeTimeout.current);
|
|
179
|
+
};
|
|
167
180
|
const waitAndExecute = () => {
|
|
168
181
|
return new Promise((resolve, reject) => {
|
|
182
|
+
scriptErrorListener.current = () => {
|
|
183
|
+
clearEvents();
|
|
184
|
+
reject(new RetryError());
|
|
185
|
+
};
|
|
169
186
|
executeTimeout.current = setTimeout(() => {
|
|
170
187
|
reject(new TimeoutError("Execute timed out"));
|
|
171
188
|
}, executeTimeoutSeconds * 1e3);
|
|
172
189
|
onReady.current = (id) => {
|
|
173
|
-
|
|
190
|
+
clearEvents();
|
|
174
191
|
window.captchafox.execute(id).then(resolve).catch((error) => {
|
|
175
192
|
const errorType = getErrorType(error);
|
|
176
193
|
reject(errorType);
|