Launch Week Day 5: Introducing Reachability for PHP.Learn More
Socket
Book a DemoSign in
Socket

@captchafox/react

Package Overview
Dependencies
Maintainers
2
Versions
19
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@captchafox/react - npm Package Compare versions

Comparing version
1.6.0
to
1.7.0
+54
-21
dist/index.cjs

@@ -55,3 +55,5 @@ "use client";

CAPTCHA_RESPONSE_KEY: () => CAPTCHA_RESPONSE_KEY,
CaptchaFox: () => CaptchaFox
CaptchaFox: () => CaptchaFox,
RetryError: () => RetryError,
TimeoutError: () => TimeoutError
});

@@ -61,4 +63,9 @@ module.exports = __toCommonJS(src_exports);

// ../internal/dist/index.mjs
var RetryError = class extends Error {
};
var TimeoutError = class extends Error {
};
var backoff = (retryCount) => Math.exp(retryCount) * 150;
var withRetry = (_0, ..._1) => __async(void 0, [_0, ..._1], function* (callback, { attempts = 4 } = {}) {
var _a;
let error;

@@ -73,3 +80,3 @@ for (let i = 0; i < attempts; i++) {

}
throw error != null ? error : new Error("Exhausted all retries");
throw new RetryError((_a = error == null ? void 0 : error.message) != null ? _a : "Exhausted all retries");
});

@@ -114,2 +121,3 @@ var mountInstance;

({
executeTimeoutSeconds = 30,
sitekey,

@@ -131,2 +139,4 @@ lang,

const firstRendered = (0, import_react.useRef)(false);
const onReady = (0, import_react.useRef)();
const executeTimeout = (0, import_react.useRef)();
(0, import_react.useImperativeHandle)(

@@ -160,3 +170,3 @@ ref,

if (!isApiReady() || !widgetId) {
return Promise.reject("[CaptchaFox] Widget has not been loaded");
return waitAndExecute();
}

@@ -174,20 +184,6 @@ return window.captchafox.execute(widgetId);

}, [widgetId]);
const renderCaptcha = () => __async(void 0, null, function* () {
var _a, _b, _c;
(_a = window.captchafox) == null ? void 0 : _a.remove(widgetId);
if (!containerRef || ((_b = containerRef == null ? void 0 : containerRef.children) == null ? void 0 : _b.length) === 1) return;
const newWidgetId = yield (_c = window.captchafox) == null ? void 0 : _c.render(containerRef, {
lang,
sitekey,
mode,
theme,
i18n,
onError,
onFail,
onClose,
onVerify
});
setWidgetId(newWidgetId);
});
(0, import_react.useEffect)(() => {
return () => clearTimeout(executeTimeout.current);
}, []);
(0, import_react.useEffect)(() => {
if (!containerRef) return;

@@ -210,2 +206,37 @@ if (firstRendered.current) {

}, [containerRef, sitekey, lang, mode]);
const waitAndExecute = () => {
return new Promise((resolve, reject) => {
executeTimeout.current = setTimeout(() => {
reject(new TimeoutError("Execute timed out"));
}, executeTimeoutSeconds * 1e3);
onReady.current = (id) => {
clearTimeout(executeTimeout.current);
window.captchafox.execute(id).then(resolve).catch(reject);
};
});
};
const renderCaptcha = () => __async(void 0, null, function* () {
var _a, _b, _c;
(_a = window.captchafox) == null ? void 0 : _a.remove(widgetId);
if (!containerRef || ((_b = containerRef == null ? void 0 : containerRef.children) == null ? void 0 : _b.length) === 1) return;
const newWidgetId = yield (_c = window.captchafox) == null ? void 0 : _c.render(containerRef, {
lang,
sitekey,
mode,
theme,
i18n,
onError,
onFail,
onClose,
onVerify
});
if (!newWidgetId) {
return;
}
setWidgetId(newWidgetId);
if (onReady.current) {
onReady.current(newWidgetId);
onReady.current = void 0;
}
});
return /* @__PURE__ */ import_react.default.createElement("div", { ref: setContainerRef, id: widgetId, className });

@@ -221,3 +252,5 @@ }

CAPTCHA_RESPONSE_KEY,
CaptchaFox
CaptchaFox,
RetryError,
TimeoutError
});
import { WidgetApi, WidgetOptions } from '@captchafox/types';
import React from 'react';
declare class RetryError extends Error {
}
declare class TimeoutError extends Error {
}
type CaptchaFoxInstance = Omit<WidgetApi, 'render'>;

@@ -10,2 +15,3 @@ declare const CaptchaFox: React.ForwardRefExoticComponent<WidgetOptions & {

nonce?: string | undefined;
executeTimeoutSeconds?: number | undefined;
} & React.RefAttributes<CaptchaFoxInstance>>;

@@ -15,2 +21,2 @@

export { CAPTCHA_RESPONSE_KEY, CaptchaFox, type CaptchaFoxInstance };
export { CAPTCHA_RESPONSE_KEY, CaptchaFox, type CaptchaFoxInstance, RetryError, TimeoutError };
import { WidgetApi, WidgetOptions } from '@captchafox/types';
import React from 'react';
declare class RetryError extends Error {
}
declare class TimeoutError extends Error {
}
type CaptchaFoxInstance = Omit<WidgetApi, 'render'>;

@@ -10,2 +15,3 @@ declare const CaptchaFox: React.ForwardRefExoticComponent<WidgetOptions & {

nonce?: string | undefined;
executeTimeoutSeconds?: number | undefined;
} & React.RefAttributes<CaptchaFoxInstance>>;

@@ -15,2 +21,2 @@

export { CAPTCHA_RESPONSE_KEY, CaptchaFox, type CaptchaFoxInstance };
export { CAPTCHA_RESPONSE_KEY, CaptchaFox, type CaptchaFoxInstance, RetryError, TimeoutError };

@@ -24,4 +24,9 @@ "use client";

// ../internal/dist/index.mjs
var RetryError = class extends Error {
};
var TimeoutError = class extends Error {
};
var backoff = (retryCount) => Math.exp(retryCount) * 150;
var withRetry = (_0, ..._1) => __async(void 0, [_0, ..._1], function* (callback, { attempts = 4 } = {}) {
var _a;
let error;

@@ -36,3 +41,3 @@ for (let i = 0; i < attempts; i++) {

}
throw error != null ? error : new Error("Exhausted all retries");
throw new RetryError((_a = error == null ? void 0 : error.message) != null ? _a : "Exhausted all retries");
});

@@ -77,2 +82,3 @@ var mountInstance;

({
executeTimeoutSeconds = 30,
sitekey,

@@ -94,2 +100,4 @@ lang,

const firstRendered = useRef(false);
const onReady = useRef();
const executeTimeout = useRef();
useImperativeHandle(

@@ -123,3 +131,3 @@ ref,

if (!isApiReady() || !widgetId) {
return Promise.reject("[CaptchaFox] Widget has not been loaded");
return waitAndExecute();
}

@@ -137,20 +145,6 @@ return window.captchafox.execute(widgetId);

}, [widgetId]);
const renderCaptcha = () => __async(void 0, null, function* () {
var _a, _b, _c;
(_a = window.captchafox) == null ? void 0 : _a.remove(widgetId);
if (!containerRef || ((_b = containerRef == null ? void 0 : containerRef.children) == null ? void 0 : _b.length) === 1) return;
const newWidgetId = yield (_c = window.captchafox) == null ? void 0 : _c.render(containerRef, {
lang,
sitekey,
mode,
theme,
i18n,
onError,
onFail,
onClose,
onVerify
});
setWidgetId(newWidgetId);
});
useEffect(() => {
return () => clearTimeout(executeTimeout.current);
}, []);
useEffect(() => {
if (!containerRef) return;

@@ -173,2 +167,37 @@ if (firstRendered.current) {

}, [containerRef, sitekey, lang, mode]);
const waitAndExecute = () => {
return new Promise((resolve, reject) => {
executeTimeout.current = setTimeout(() => {
reject(new TimeoutError("Execute timed out"));
}, executeTimeoutSeconds * 1e3);
onReady.current = (id) => {
clearTimeout(executeTimeout.current);
window.captchafox.execute(id).then(resolve).catch(reject);
};
});
};
const renderCaptcha = () => __async(void 0, null, function* () {
var _a, _b, _c;
(_a = window.captchafox) == null ? void 0 : _a.remove(widgetId);
if (!containerRef || ((_b = containerRef == null ? void 0 : containerRef.children) == null ? void 0 : _b.length) === 1) return;
const newWidgetId = yield (_c = window.captchafox) == null ? void 0 : _c.render(containerRef, {
lang,
sitekey,
mode,
theme,
i18n,
onError,
onFail,
onClose,
onVerify
});
if (!newWidgetId) {
return;
}
setWidgetId(newWidgetId);
if (onReady.current) {
onReady.current(newWidgetId);
onReady.current = void 0;
}
});
return /* @__PURE__ */ React.createElement("div", { ref: setContainerRef, id: widgetId, className });

@@ -183,3 +212,5 @@ }

CAPTCHA_RESPONSE_KEY,
CaptchaFox
CaptchaFox,
RetryError,
TimeoutError
};
{
"name": "@captchafox/react",
"version": "1.6.0",
"version": "1.7.0",
"main": "./dist/index.cjs",

@@ -5,0 +5,0 @@ "module": "./dist/index.js",