@captchafox/react 1.3.1 → 1.4.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 CHANGED
@@ -34,17 +34,18 @@ function Example() {
34
34
 
35
35
  ### Props
36
36
 
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
- | onVerify | `function` | Called with the response token after successful verification. | |
44
- | onFail | `function` | Called after unsuccessful verification. | |
45
- | onError | `function` | Called when an error occured. | |
46
- | onExpire | `function` | Called when the challenge expires. | |
47
- | onClose | `function` | Called when the challenge was closed. | |
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
+ | onVerify | `function` | Called with the response token after successful verification. | |
45
+ | onFail | `function` | Called after unsuccessful verification. | |
46
+ | onError | `function` | Called when an error occured. | |
47
+ | onExpire | `function` | Called when the challenge expires. | |
48
+ | onClose | `function` | Called when the challenge was closed. | |
48
49
 
49
50
  ### Using the verification callback
50
51
 
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, null, function* () {
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,7 @@ 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
- ({ sitekey, lang, mode, theme, className, onError, onVerify, onLoad, onFail, onClose }, ref) => {
90
+ ({ sitekey, lang, mode, theme, className, nonce, onError, onVerify, onLoad, onFail, onClose }, ref) => {
88
91
  const [containerRef, setContainerRef] = (0, import_react.useState)();
89
92
  const [widgetId, setWidgetId] = (0, import_react.useState)();
90
93
  const firstRendered = (0, import_react.useRef)(false);
@@ -150,7 +153,7 @@ var CaptchaFox = (0, import_react.forwardRef)(
150
153
  renderCaptcha();
151
154
  }
152
155
  } else {
153
- loadCaptchaScript().then(() => __async(void 0, null, function* () {
156
+ loadCaptchaScript({ nonce }).then(() => __async(void 0, null, function* () {
154
157
  if (isApiReady()) {
155
158
  firstRendered.current = true;
156
159
  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, null, function* () {
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,7 @@ 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
- ({ sitekey, lang, mode, theme, className, onError, onVerify, onLoad, onFail, onClose }, ref) => {
54
+ ({ sitekey, lang, mode, theme, className, nonce, onError, onVerify, onLoad, onFail, onClose }, ref) => {
52
55
  const [containerRef, setContainerRef] = useState();
53
56
  const [widgetId, setWidgetId] = useState();
54
57
  const firstRendered = useRef(false);
@@ -114,7 +117,7 @@ var CaptchaFox = forwardRef(
114
117
  renderCaptcha();
115
118
  }
116
119
  } else {
117
- loadCaptchaScript().then(() => __async(void 0, null, function* () {
120
+ loadCaptchaScript({ nonce }).then(() => __async(void 0, null, function* () {
118
121
  if (isApiReady()) {
119
122
  firstRendered.current = true;
120
123
  yield renderCaptcha();
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@captchafox/react",
3
- "version": "1.3.1",
3
+ "version": "1.4.0",
4
4
  "main": "./dist/index.cjs",
5
5
  "module": "./dist/index.js",
6
6
  "types": "./dist/index.d.ts",