@captchafox/react 1.3.1 → 1.5.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/README.md +13 -11
- package/dist/index.cjs +20 -3
- package/dist/index.d.cts +1 -0
- package/dist/index.d.ts +1 -0
- package/dist/index.js +20 -3
- package/package.json +2 -2
package/README.md
CHANGED
|
@@ -34,17 +34,19 @@ function Example() {
|
|
|
34
34
|
|
|
35
35
|
### Props
|
|
36
36
|
|
|
37
|
-
| **Prop** | **Type**
|
|
38
|
-
| -------- |
|
|
39
|
-
| sitekey | `string`
|
|
40
|
-
| lang | `string`
|
|
41
|
-
| mode | `inline\|popup\|hidden`
|
|
42
|
-
| theme | `light`
|
|
43
|
-
|
|
|
44
|
-
|
|
|
45
|
-
|
|
|
46
|
-
|
|
|
47
|
-
|
|
|
37
|
+
| **Prop** | **Type** | **Description** | **Required** |
|
|
38
|
+
| -------- | -------------------------------------------------------------------------------------------------- | ------------------------------------------------------------------------------- | ------------ |
|
|
39
|
+
| sitekey | `string` | The sitekey for the widget | ✅ |
|
|
40
|
+
| lang | `string` | The language the widget should display. Defaults to automatically detecting it. | |
|
|
41
|
+
| mode | `inline\|popup\|hidden` | The mode the widget should be displayed in . | |
|
|
42
|
+
| theme | `light` | `dark` | [`ThemeDefinition`](https://docs.captchafox.com/theming#custom-theme) | The theme of the widget. Defaults to light. | |
|
|
43
|
+
| nonce | `string` | Randomly generated nonce . | |
|
|
44
|
+
| i18n | `object` | Custom i18n configuration. | |
|
|
45
|
+
| onVerify | `function` | Called with the response token after successful verification. | |
|
|
46
|
+
| onFail | `function` | Called after unsuccessful verification. | |
|
|
47
|
+
| onError | `function` | Called when an error occured. | |
|
|
48
|
+
| onExpire | `function` | Called when the challenge expires. | |
|
|
49
|
+
| onClose | `function` | Called when the challenge was closed. | |
|
|
48
50
|
|
|
49
51
|
### Using the verification callback
|
|
50
52
|
|
package/dist/index.cjs
CHANGED
|
@@ -66,7 +66,7 @@ var mountInstance = new Promise((resolve, reject) => {
|
|
|
66
66
|
var LOAD_FUNC_KEY = "captchaFoxOnLoad";
|
|
67
67
|
var SCRIPT_SRC = `https://cdn.captchafox.com/api.js?render=explicit&onload=${LOAD_FUNC_KEY}`;
|
|
68
68
|
function loadCaptchaScript() {
|
|
69
|
-
return __async(this,
|
|
69
|
+
return __async(this, arguments, function* ({ nonce } = {}) {
|
|
70
70
|
if (document.querySelector(`script[src="${SCRIPT_SRC}"]`))
|
|
71
71
|
return mountInstance;
|
|
72
72
|
window[LOAD_FUNC_KEY] = resolveFn;
|
|
@@ -75,6 +75,9 @@ function loadCaptchaScript() {
|
|
|
75
75
|
script.async = true;
|
|
76
76
|
script.defer = true;
|
|
77
77
|
script.onerror = rejectFn;
|
|
78
|
+
if (nonce) {
|
|
79
|
+
script.nonce = nonce;
|
|
80
|
+
}
|
|
78
81
|
document.body.appendChild(script);
|
|
79
82
|
return mountInstance;
|
|
80
83
|
});
|
|
@@ -84,7 +87,20 @@ var isApiReady = () => typeof (window == null ? void 0 : window.captchafox) !==
|
|
|
84
87
|
// src/CaptchaFox.tsx
|
|
85
88
|
var import_react = __toESM(require("react"), 1);
|
|
86
89
|
var CaptchaFox = (0, import_react.forwardRef)(
|
|
87
|
-
({
|
|
90
|
+
({
|
|
91
|
+
sitekey,
|
|
92
|
+
lang,
|
|
93
|
+
mode,
|
|
94
|
+
theme,
|
|
95
|
+
className,
|
|
96
|
+
nonce,
|
|
97
|
+
i18n,
|
|
98
|
+
onError,
|
|
99
|
+
onVerify,
|
|
100
|
+
onLoad,
|
|
101
|
+
onFail,
|
|
102
|
+
onClose
|
|
103
|
+
}, ref) => {
|
|
88
104
|
const [containerRef, setContainerRef] = (0, import_react.useState)();
|
|
89
105
|
const [widgetId, setWidgetId] = (0, import_react.useState)();
|
|
90
106
|
const firstRendered = (0, import_react.useRef)(false);
|
|
@@ -134,6 +150,7 @@ var CaptchaFox = (0, import_react.forwardRef)(
|
|
|
134
150
|
sitekey,
|
|
135
151
|
mode,
|
|
136
152
|
theme,
|
|
153
|
+
i18n,
|
|
137
154
|
onError,
|
|
138
155
|
onFail,
|
|
139
156
|
onClose,
|
|
@@ -150,7 +167,7 @@ var CaptchaFox = (0, import_react.forwardRef)(
|
|
|
150
167
|
renderCaptcha();
|
|
151
168
|
}
|
|
152
169
|
} else {
|
|
153
|
-
loadCaptchaScript().then(() => __async(void 0, null, function* () {
|
|
170
|
+
loadCaptchaScript({ nonce }).then(() => __async(void 0, null, function* () {
|
|
154
171
|
if (isApiReady()) {
|
|
155
172
|
firstRendered.current = true;
|
|
156
173
|
yield renderCaptcha();
|
package/dist/index.d.cts
CHANGED
|
@@ -6,6 +6,7 @@ declare const CaptchaFox: React.ForwardRefExoticComponent<WidgetOptions & {
|
|
|
6
6
|
/** Called after the widget has been loaded */
|
|
7
7
|
onLoad?: (() => void) | undefined;
|
|
8
8
|
className?: string | undefined;
|
|
9
|
+
nonce?: string | undefined;
|
|
9
10
|
} & React.RefAttributes<CaptchaFoxInstance>>;
|
|
10
11
|
|
|
11
12
|
declare const CAPTCHA_RESPONSE_KEY = "cf-captcha-response";
|
package/dist/index.d.ts
CHANGED
|
@@ -6,6 +6,7 @@ declare const CaptchaFox: React.ForwardRefExoticComponent<WidgetOptions & {
|
|
|
6
6
|
/** Called after the widget has been loaded */
|
|
7
7
|
onLoad?: (() => void) | undefined;
|
|
8
8
|
className?: string | undefined;
|
|
9
|
+
nonce?: string | undefined;
|
|
9
10
|
} & React.RefAttributes<CaptchaFoxInstance>>;
|
|
10
11
|
|
|
11
12
|
declare const CAPTCHA_RESPONSE_KEY = "cf-captcha-response";
|
package/dist/index.js
CHANGED
|
@@ -30,7 +30,7 @@ var mountInstance = new Promise((resolve, reject) => {
|
|
|
30
30
|
var LOAD_FUNC_KEY = "captchaFoxOnLoad";
|
|
31
31
|
var SCRIPT_SRC = `https://cdn.captchafox.com/api.js?render=explicit&onload=${LOAD_FUNC_KEY}`;
|
|
32
32
|
function loadCaptchaScript() {
|
|
33
|
-
return __async(this,
|
|
33
|
+
return __async(this, arguments, function* ({ nonce } = {}) {
|
|
34
34
|
if (document.querySelector(`script[src="${SCRIPT_SRC}"]`))
|
|
35
35
|
return mountInstance;
|
|
36
36
|
window[LOAD_FUNC_KEY] = resolveFn;
|
|
@@ -39,6 +39,9 @@ function loadCaptchaScript() {
|
|
|
39
39
|
script.async = true;
|
|
40
40
|
script.defer = true;
|
|
41
41
|
script.onerror = rejectFn;
|
|
42
|
+
if (nonce) {
|
|
43
|
+
script.nonce = nonce;
|
|
44
|
+
}
|
|
42
45
|
document.body.appendChild(script);
|
|
43
46
|
return mountInstance;
|
|
44
47
|
});
|
|
@@ -48,7 +51,20 @@ var isApiReady = () => typeof (window == null ? void 0 : window.captchafox) !==
|
|
|
48
51
|
// src/CaptchaFox.tsx
|
|
49
52
|
import React, { forwardRef, useEffect, useImperativeHandle, useRef, useState } from "react";
|
|
50
53
|
var CaptchaFox = forwardRef(
|
|
51
|
-
({
|
|
54
|
+
({
|
|
55
|
+
sitekey,
|
|
56
|
+
lang,
|
|
57
|
+
mode,
|
|
58
|
+
theme,
|
|
59
|
+
className,
|
|
60
|
+
nonce,
|
|
61
|
+
i18n,
|
|
62
|
+
onError,
|
|
63
|
+
onVerify,
|
|
64
|
+
onLoad,
|
|
65
|
+
onFail,
|
|
66
|
+
onClose
|
|
67
|
+
}, ref) => {
|
|
52
68
|
const [containerRef, setContainerRef] = useState();
|
|
53
69
|
const [widgetId, setWidgetId] = useState();
|
|
54
70
|
const firstRendered = useRef(false);
|
|
@@ -98,6 +114,7 @@ var CaptchaFox = forwardRef(
|
|
|
98
114
|
sitekey,
|
|
99
115
|
mode,
|
|
100
116
|
theme,
|
|
117
|
+
i18n,
|
|
101
118
|
onError,
|
|
102
119
|
onFail,
|
|
103
120
|
onClose,
|
|
@@ -114,7 +131,7 @@ var CaptchaFox = forwardRef(
|
|
|
114
131
|
renderCaptcha();
|
|
115
132
|
}
|
|
116
133
|
} else {
|
|
117
|
-
loadCaptchaScript().then(() => __async(void 0, null, function* () {
|
|
134
|
+
loadCaptchaScript({ nonce }).then(() => __async(void 0, null, function* () {
|
|
118
135
|
if (isApiReady()) {
|
|
119
136
|
firstRendered.current = true;
|
|
120
137
|
yield renderCaptcha();
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@captchafox/react",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.5.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.3.0"
|
|
39
39
|
},
|
|
40
40
|
"devDependencies": {
|
|
41
41
|
"@captchafox/tsconfig": "*",
|