@captchafox/react 1.7.0 → 1.8.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 CHANGED
@@ -160,12 +160,18 @@ var CaptchaFox = (0, import_react.forwardRef)(
160
160
  setWidgetId(void 0);
161
161
  window.captchafox.remove(widgetId);
162
162
  },
163
- execute: () => {
163
+ execute: () => __async(void 0, null, function* () {
164
164
  if (!isApiReady() || !widgetId) {
165
165
  return waitAndExecute();
166
166
  }
167
- return window.captchafox.execute(widgetId);
168
- }
167
+ try {
168
+ const token = yield window.captchafox.execute(widgetId);
169
+ return token;
170
+ } catch (error) {
171
+ const errorType = getErrorType(error);
172
+ return Promise.reject(errorType);
173
+ }
174
+ })
169
175
  };
170
176
  },
171
177
  [widgetId]
@@ -203,10 +209,19 @@ var CaptchaFox = (0, import_react.forwardRef)(
203
209
  }, executeTimeoutSeconds * 1e3);
204
210
  onReady.current = (id) => {
205
211
  clearTimeout(executeTimeout.current);
206
- window.captchafox.execute(id).then(resolve).catch(reject);
212
+ window.captchafox.execute(id).then(resolve).catch((error) => {
213
+ const errorType = getErrorType(error);
214
+ reject(errorType);
215
+ });
207
216
  };
208
217
  });
209
218
  };
219
+ const getErrorType = (error) => {
220
+ if (error !== "challenge-aborted" && error !== "rate-limited") {
221
+ return new RetryError();
222
+ }
223
+ return error;
224
+ };
210
225
  const renderCaptcha = () => __async(void 0, null, function* () {
211
226
  var _a, _b, _c;
212
227
  (_a = window.captchafox) == null ? void 0 : _a.remove(widgetId);
package/dist/index.js CHANGED
@@ -122,12 +122,18 @@ var CaptchaFox = forwardRef(
122
122
  setWidgetId(void 0);
123
123
  window.captchafox.remove(widgetId);
124
124
  },
125
- execute: () => {
125
+ execute: () => __async(void 0, null, function* () {
126
126
  if (!isApiReady() || !widgetId) {
127
127
  return waitAndExecute();
128
128
  }
129
- return window.captchafox.execute(widgetId);
130
- }
129
+ try {
130
+ const token = yield window.captchafox.execute(widgetId);
131
+ return token;
132
+ } catch (error) {
133
+ const errorType = getErrorType(error);
134
+ return Promise.reject(errorType);
135
+ }
136
+ })
131
137
  };
132
138
  },
133
139
  [widgetId]
@@ -165,10 +171,19 @@ var CaptchaFox = forwardRef(
165
171
  }, executeTimeoutSeconds * 1e3);
166
172
  onReady.current = (id) => {
167
173
  clearTimeout(executeTimeout.current);
168
- window.captchafox.execute(id).then(resolve).catch(reject);
174
+ window.captchafox.execute(id).then(resolve).catch((error) => {
175
+ const errorType = getErrorType(error);
176
+ reject(errorType);
177
+ });
169
178
  };
170
179
  });
171
180
  };
181
+ const getErrorType = (error) => {
182
+ if (error !== "challenge-aborted" && error !== "rate-limited") {
183
+ return new RetryError();
184
+ }
185
+ return error;
186
+ };
172
187
  const renderCaptcha = () => __async(void 0, null, function* () {
173
188
  var _a, _b, _c;
174
189
  (_a = window.captchafox) == null ? void 0 : _a.remove(widgetId);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@captchafox/react",
3
- "version": "1.7.0",
3
+ "version": "1.8.0",
4
4
  "main": "./dist/index.cjs",
5
5
  "module": "./dist/index.js",
6
6
  "types": "./dist/index.d.ts",