Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

react-turnstile

Package Overview
Dependencies
Maintainers
1
Versions
12
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

react-turnstile - npm Package Compare versions

Comparing version 1.1.1 to 1.1.2

8

dist/index.d.ts
import React from "react";
import { TurnstileObject, TurnstileOptions, SupportedLanguages } from "turnstile-types";
export default function Turnstile({ id, className, style, sitekey, action, cData, theme, language, tabIndex, responseField, responseFieldName, size, fixedSize, retry, retryInterval, refreshExpired, appearance, execution, userRef, onVerify, onLoad, onError, onExpire, onTimeout, }: TurnstileProps): JSX.Element;
export default function Turnstile({ id, className, style, sitekey, action, cData, theme, language, tabIndex, responseField, responseFieldName, size, fixedSize, retry, retryInterval, refreshExpired, appearance, execution, userRef, onVerify, onLoad, onError, onExpire, onTimeout, onAfterInteractive, onBeforeInteractive, onUnsupported, }: TurnstileProps): JSX.Element;
export interface TurnstileProps extends TurnstileCallbacks {

@@ -26,3 +26,3 @@ sitekey: string;

export interface TurnstileCallbacks {
onVerify: (token: string, boundTurnstile: BoundTurnstileObject) => void;
onVerify?: (token: string, boundTurnstile: BoundTurnstileObject) => void;
onLoad?: (widgetId: string, boundTurnstile: BoundTurnstileObject) => void;

@@ -32,2 +32,5 @@ onError?: (error?: Error | any, boundTurnstile?: BoundTurnstileObject) => void;

onTimeout?: (boundTurnstile: BoundTurnstileObject) => void;
onAfterInteractive?: (boundTurnstile: BoundTurnstileObject) => void;
onBeforeInteractive?: (boundTurnstile: BoundTurnstileObject) => void;
onUnsupported?: (boundTurnstile: BoundTurnstileObject) => void;
}

@@ -38,3 +41,4 @@ export interface BoundTurnstileObject {

getResponse: () => void;
isExpired: () => boolean;
}
export declare function useTurnstile(): TurnstileObject;

@@ -63,5 +63,14 @@ "use strict";

}
function Turnstile({ id, className, style, sitekey, action, cData, theme, language, tabIndex, responseField, responseFieldName, size, fixedSize, retry, retryInterval, refreshExpired, appearance, execution, userRef, onVerify, onLoad, onError, onExpire, onTimeout, }) {
function Turnstile({ id, className, style, sitekey, action, cData, theme, language, tabIndex, responseField, responseFieldName, size, fixedSize, retry, retryInterval, refreshExpired, appearance, execution, userRef, onVerify, onLoad, onError, onExpire, onTimeout, onAfterInteractive, onBeforeInteractive, onUnsupported, }) {
const ownRef = (0, react_1.useRef)(null);
const inplaceState = (0, react_1.useState)({ onVerify })[0];
const inplaceState = (0, react_1.useState)({
onVerify,
onLoad,
onError,
onExpire,
onTimeout,
onAfterInteractive,
onBeforeInteractive,
onUnsupported,
})[0];
const ref = userRef !== null && userRef !== void 0 ? userRef : ownRef;

@@ -72,3 +81,3 @@ (0, react_1.useEffect)(() => {

let cancelled = false;
let widgetId = "", timeoutId = 0;
let widgetId = "";
(async () => {

@@ -99,3 +108,3 @@ var _a, _b;

size,
retry: "never",
retry,
"retry-interval": retryInterval,

@@ -105,25 +114,9 @@ "refresh-expired": refreshExpired,

execution,
callback: (token) => inplaceState.onVerify(token, boundTurnstileObject),
"error-callback": (error) => {
var _a;
// we handle retry ourselves because turnstile does not properly
// reset its timeout when calling turnstile.remove, logging the
// following in the console:
// > [Cloudflare Turnstile] Nothing to reset found for provided container.
// refs:
// - https://github.com/Le0Developer/react-turnstile/issues/14
// - https://discord.com/channels/595317990191398933/1025131875397812224/1122137855368646717
// TODO: remove when fixed
if (!retry || retry === "auto") {
timeoutId = setTimeout(() => {
boundTurnstileObject.reset();
timeoutId = 0;
// no need to do bounds checks, turnstile already does them for us
// even though we have retry=never
}, 2000 + (retryInterval !== null && retryInterval !== void 0 ? retryInterval : 8000));
}
(_a = inplaceState.onError) === null || _a === void 0 ? void 0 : _a.call(inplaceState, error, boundTurnstileObject);
},
callback: (token) => { var _a; return (_a = inplaceState.onVerify) === null || _a === void 0 ? void 0 : _a.call(inplaceState, token, boundTurnstileObject); },
"error-callback": (error) => { var _a; return (_a = inplaceState.onError) === null || _a === void 0 ? void 0 : _a.call(inplaceState, error, boundTurnstileObject); },
"expired-callback": (token) => { var _a; return (_a = inplaceState.onExpire) === null || _a === void 0 ? void 0 : _a.call(inplaceState, token, boundTurnstileObject); },
"timeout-callback": () => { var _a; return (_a = inplaceState.onTimeout) === null || _a === void 0 ? void 0 : _a.call(inplaceState, boundTurnstileObject); },
"after-interactive-callback": () => { var _a; return (_a = inplaceState.onAfterInteractive) === null || _a === void 0 ? void 0 : _a.call(inplaceState, boundTurnstileObject); },
"before-interactive-callback": () => { var _a; return (_a = inplaceState.onBeforeInteractive) === null || _a === void 0 ? void 0 : _a.call(inplaceState, boundTurnstileObject); },
"unsupported-callback": () => { var _a; return (_a = inplaceState.onUnsupported) === null || _a === void 0 ? void 0 : _a.call(inplaceState, boundTurnstileObject); },
};

@@ -138,4 +131,2 @@ widgetId = window.turnstile.render(ref.current, turnstileOptions);

window.turnstile.remove(widgetId);
if (timeoutId)
clearTimeout(timeoutId);
};

@@ -164,3 +155,15 @@ }, [

inplaceState.onTimeout = onTimeout;
}, [onVerify, onLoad, onError, onExpire, onTimeout]);
inplaceState.onAfterInteractive = onAfterInteractive;
inplaceState.onBeforeInteractive = onBeforeInteractive;
inplaceState.onUnsupported = onUnsupported;
}, [
onVerify,
onLoad,
onError,
onExpire,
onTimeout,
onAfterInteractive,
onBeforeInteractive,
onUnsupported,
]);
return (react_1.default.createElement("div", { ref: ref, id: id, className: className, style: fixedSize

@@ -180,2 +183,3 @@ ? {

getResponse: () => window.turnstile.getResponse(widgetId),
isExpired: () => window.turnstile.isExpired(widgetId),
};

@@ -182,0 +186,0 @@ }

@@ -10,2 +10,20 @@ # Changelog

## [1.1.2] - 2023-09-18
### Added
- `onAfterInteractive`, `onBeforeInteractive`, `onUnsupported` callbacks
### Changed
- `onVerify` is no longer required
### Removed
- Custom `retry` logic (issue fixed upstream in Turnstile itself)
### Fixed
- Remount issue with certain callbacks (#15)
## [1.1.1] - 2023-06-25

@@ -106,3 +124,4 @@

[unreleased]: https://github.com/Le0Developer/react-turnstile/compare/v1.1.1...HEAD
[unreleased]: https://github.com/Le0Developer/react-turnstile/compare/v1.1.2...HEAD
[1.1.2]: https://github.com/le0developer/react-turnstile/compare/v1.1.1...v1.1.2
[1.1.1]: https://github.com/le0developer/react-turnstile/compare/v1.1.0...v1.1.1

@@ -109,0 +128,0 @@ [1.1.0]: https://github.com/le0developer/react-turnstile/compare/v1.0.6...v1.1.0

{
"name": "react-turnstile",
"version": "1.1.1",
"version": "1.1.2",
"description": "React library for Cloudflare's Turnstile CAPTCHA alternative",

@@ -30,5 +30,5 @@ "main": "dist/index.js",

"prettier": "^2.7.1",
"turnstile-types": "^1.1.2",
"turnstile-types": "^1.1.3",
"typescript": "^4.8.4"
}
}

@@ -98,9 +98,12 @@ # react-turnstile

| name | arguments | description |
| --------- | --------- | ------------------------------------------ |
| onVerify | token | called when challenge is passed (REQUIRED) |
| onLoad | widgetId | called when the widget is loaded |
| onError | error | called when an error occurs |
| onExpire | - | called when the token expires |
| onTimeout | token | called when the challenge expires |
| name | arguments | description |
| ------------------- | --------- | --------------------------------------------------- |
| onVerify | token | called when challenge is passed |
| onLoad | widgetId | called when the widget is loaded |
| onError | error | called when an error occurs |
| onExpire | - | called when the token expires |
| onTimeout | token | called when the challenge expires |
| onAfterInteractive | - | called when the challenge becomes interactive |
| onBeforeInteractive | - | called when the challenge no longer is interactive |
| onUnsupported | - | called when the browser is unsupported by Turnstile |

@@ -107,0 +110,0 @@ The callbacks also take an additional `BoundTurnstileObject` which exposes

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc