@hcaptcha/react-hcaptcha 0.3.7 → 0.3.8

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
@@ -86,7 +86,7 @@ In these instances, you'll most likely want to use `ref` to handle the callbacks
86
86
 
87
87
  |Method|Description|
88
88
  |---|---|
89
- |`execute()`|Programmatically trigger a challenge request|
89
+ |`execute()`|Programmatically trigger a challenge request. Additionally, this method can be run asynchronously and returns a promise with the `token` and `eKey` when the challenge is completed.|
90
90
  |`resetCaptcha()`|Reset the current challenge|
91
91
 
92
92
 
package/dist/index.js CHANGED
@@ -1,33 +1,31 @@
1
1
  "use strict";
2
2
 
3
- function _typeof(obj) { "@babel/helpers - typeof"; if (typeof Symbol === "function" && typeof Symbol.iterator === "symbol") { _typeof = function _typeof(obj) { return typeof obj; }; } else { _typeof = function _typeof(obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }; } return _typeof(obj); }
3
+ var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
4
4
 
5
- function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); if (enumerableOnly) symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; }); keys.push.apply(keys, symbols); } return keys; }
5
+ var _typeof2 = _interopRequireDefault(require("@babel/runtime/helpers/typeof"));
6
6
 
7
- function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i] != null ? arguments[i] : {}; if (i % 2) { ownKeys(Object(source), true).forEach(function (key) { _defineProperty(target, key, source[key]); }); } else if (Object.getOwnPropertyDescriptors) { Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)); } else { ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } } return target; }
7
+ var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
8
8
 
9
- function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
9
+ var _classCallCheck2 = _interopRequireDefault(require("@babel/runtime/helpers/classCallCheck"));
10
10
 
11
- function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
11
+ var _createClass2 = _interopRequireDefault(require("@babel/runtime/helpers/createClass"));
12
12
 
13
- function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } }
13
+ var _assertThisInitialized2 = _interopRequireDefault(require("@babel/runtime/helpers/assertThisInitialized"));
14
14
 
15
- function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); return Constructor; }
15
+ var _inherits2 = _interopRequireDefault(require("@babel/runtime/helpers/inherits"));
16
16
 
17
- function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function"); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, writable: true, configurable: true } }); if (superClass) _setPrototypeOf(subClass, superClass); }
17
+ var _possibleConstructorReturn2 = _interopRequireDefault(require("@babel/runtime/helpers/possibleConstructorReturn"));
18
18
 
19
- function _setPrototypeOf(o, p) { _setPrototypeOf = Object.setPrototypeOf || function _setPrototypeOf(o, p) { o.__proto__ = p; return o; }; return _setPrototypeOf(o, p); }
19
+ var _getPrototypeOf2 = _interopRequireDefault(require("@babel/runtime/helpers/getPrototypeOf"));
20
20
 
21
- function _createSuper(Derived) { var hasNativeReflectConstruct = _isNativeReflectConstruct(); return function _createSuperInternal() { var Super = _getPrototypeOf(Derived), result; if (hasNativeReflectConstruct) { var NewTarget = _getPrototypeOf(this).constructor; result = Reflect.construct(Super, arguments, NewTarget); } else { result = Super.apply(this, arguments); } return _possibleConstructorReturn(this, result); }; }
21
+ function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); if (enumerableOnly) symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; }); keys.push.apply(keys, symbols); } return keys; }
22
22
 
23
- function _possibleConstructorReturn(self, call) { if (call && (_typeof(call) === "object" || typeof call === "function")) { return call; } return _assertThisInitialized(self); }
23
+ function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i] != null ? arguments[i] : {}; if (i % 2) { ownKeys(Object(source), true).forEach(function (key) { (0, _defineProperty2["default"])(target, key, source[key]); }); } else if (Object.getOwnPropertyDescriptors) { Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)); } else { ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } } return target; }
24
24
 
25
- function _assertThisInitialized(self) { if (self === void 0) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return self; }
25
+ function _createSuper(Derived) { var hasNativeReflectConstruct = _isNativeReflectConstruct(); return function _createSuperInternal() { var Super = (0, _getPrototypeOf2["default"])(Derived), result; if (hasNativeReflectConstruct) { var NewTarget = (0, _getPrototypeOf2["default"])(this).constructor; result = Reflect.construct(Super, arguments, NewTarget); } else { result = Super.apply(this, arguments); } return (0, _possibleConstructorReturn2["default"])(this, result); }; }
26
26
 
27
27
  function _isNativeReflectConstruct() { if (typeof Reflect === "undefined" || !Reflect.construct) return false; if (Reflect.construct.sham) return false; if (typeof Proxy === "function") return true; try { Date.prototype.toString.call(Reflect.construct(Date, [], function () {})); return true; } catch (e) { return false; } }
28
28
 
29
- function _getPrototypeOf(o) { _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf : function _getPrototypeOf(o) { return o.__proto__ || Object.getPrototypeOf(o); }; return _getPrototypeOf(o); }
30
-
31
29
  var React = require('react');
32
30
 
33
31
  var _require = require("./utils.js"),
@@ -60,25 +58,24 @@ var mountCaptchaScript = function mountCaptchaScript() {
60
58
  };
61
59
 
62
60
  var HCaptcha = /*#__PURE__*/function (_React$Component) {
63
- _inherits(HCaptcha, _React$Component);
61
+ (0, _inherits2["default"])(HCaptcha, _React$Component);
64
62
 
65
63
  var _super = _createSuper(HCaptcha);
66
64
 
67
65
  function HCaptcha(props) {
68
66
  var _this;
69
67
 
70
- _classCallCheck(this, HCaptcha);
71
-
68
+ (0, _classCallCheck2["default"])(this, HCaptcha);
72
69
  _this = _super.call(this, props); // API Methods
73
70
 
74
- _this.renderCaptcha = _this.renderCaptcha.bind(_assertThisInitialized(_this));
75
- _this.resetCaptcha = _this.resetCaptcha.bind(_assertThisInitialized(_this));
76
- _this.removeCaptcha = _this.removeCaptcha.bind(_assertThisInitialized(_this)); // Event Handlers
71
+ _this.renderCaptcha = _this.renderCaptcha.bind((0, _assertThisInitialized2["default"])(_this));
72
+ _this.resetCaptcha = _this.resetCaptcha.bind((0, _assertThisInitialized2["default"])(_this));
73
+ _this.removeCaptcha = _this.removeCaptcha.bind((0, _assertThisInitialized2["default"])(_this)); // Event Handlers
77
74
 
78
- _this.handleOnLoad = _this.handleOnLoad.bind(_assertThisInitialized(_this));
79
- _this.handleSubmit = _this.handleSubmit.bind(_assertThisInitialized(_this));
80
- _this.handleExpire = _this.handleExpire.bind(_assertThisInitialized(_this));
81
- _this.handleError = _this.handleError.bind(_assertThisInitialized(_this));
75
+ _this.handleOnLoad = _this.handleOnLoad.bind((0, _assertThisInitialized2["default"])(_this));
76
+ _this.handleSubmit = _this.handleSubmit.bind((0, _assertThisInitialized2["default"])(_this));
77
+ _this.handleExpire = _this.handleExpire.bind((0, _assertThisInitialized2["default"])(_this));
78
+ _this.handleError = _this.handleError.bind((0, _assertThisInitialized2["default"])(_this));
82
79
  var isApiReady = typeof hcaptcha !== 'undefined';
83
80
  _this.ref = React.createRef();
84
81
  _this.state = {
@@ -90,7 +87,7 @@ var HCaptcha = /*#__PURE__*/function (_React$Component) {
90
87
  return _this;
91
88
  }
92
89
 
93
- _createClass(HCaptcha, [{
90
+ (0, _createClass2["default"])(HCaptcha, [{
94
91
  key: "componentDidMount",
95
92
  value: function componentDidMount() {
96
93
  //Once captcha is mounted intialize hCaptcha - hCaptcha
@@ -271,12 +268,18 @@ var HCaptcha = /*#__PURE__*/function (_React$Component) {
271
268
  }, {
272
269
  key: "execute",
273
270
  value: function execute() {
271
+ var opts = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : null;
274
272
  var _this$state7 = this.state,
275
273
  isApiReady = _this$state7.isApiReady,
276
274
  isRemoved = _this$state7.isRemoved,
277
275
  captchaId = _this$state7.captchaId;
278
276
  if (!isApiReady || isRemoved) return;
279
- hcaptcha.execute(captchaId);
277
+
278
+ if (opts && (0, _typeof2["default"])(opts) !== "object") {
279
+ opts = null;
280
+ }
281
+
282
+ return hcaptcha.execute(captchaId, opts);
280
283
  }
281
284
  }, {
282
285
  key: "render",
@@ -288,7 +291,6 @@ var HCaptcha = /*#__PURE__*/function (_React$Component) {
288
291
  });
289
292
  }
290
293
  }]);
291
-
292
294
  return HCaptcha;
293
295
  }(React.Component);
294
296
 
package/dist/utils.js CHANGED
@@ -1,26 +1,18 @@
1
1
  "use strict";
2
2
 
3
- function _slicedToArray(arr, i) { return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _unsupportedIterableToArray(arr, i) || _nonIterableRest(); }
3
+ var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
4
4
 
5
- function _nonIterableRest() { throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }
6
-
7
- function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(o); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); }
8
-
9
- function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) { arr2[i] = arr[i]; } return arr2; }
10
-
11
- function _iterableToArrayLimit(arr, i) { if (typeof Symbol === "undefined" || !(Symbol.iterator in Object(arr))) return; var _arr = []; var _n = true; var _d = false; var _e = undefined; try { for (var _i = arr[Symbol.iterator](), _s; !(_n = (_s = _i.next()).done); _n = true) { _arr.push(_s.value); if (i && _arr.length === i) break; } } catch (err) { _d = true; _e = err; } finally { try { if (!_n && _i["return"] != null) _i["return"](); } finally { if (_d) throw _e; } } return _arr; }
12
-
13
- function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; }
5
+ var _slicedToArray2 = _interopRequireDefault(require("@babel/runtime/helpers/slicedToArray"));
14
6
 
15
7
  function generateQuery(params) {
16
8
  return Object.entries(params).filter(function (_ref) {
17
- var _ref2 = _slicedToArray(_ref, 2),
9
+ var _ref2 = (0, _slicedToArray2["default"])(_ref, 2),
18
10
  key = _ref2[0],
19
11
  value = _ref2[1];
20
12
 
21
13
  return value || value === false;
22
14
  }).map(function (_ref3) {
23
- var _ref4 = _slicedToArray(_ref3, 2),
15
+ var _ref4 = (0, _slicedToArray2["default"])(_ref3, 2),
24
16
  key = _ref4[0],
25
17
  value = _ref4[1];
26
18
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@hcaptcha/react-hcaptcha",
3
- "version": "0.3.7",
3
+ "version": "0.3.8",
4
4
  "types": "types/index.d.ts",
5
5
  "main": "dist/index.js",
6
6
  "files": [
@@ -12,6 +12,7 @@
12
12
  "scripts": {
13
13
  "start": "webpack-dev-server --config ./webpack.config.js --mode development",
14
14
  "test": "jest",
15
+ "watch": "babel src -d dist --copy-files --watch",
15
16
  "transpile": "babel src -d dist --copy-files",
16
17
  "build": "npm run transpile",
17
18
  "prepublishOnly": "npm run transpile"
@@ -31,6 +32,7 @@
31
32
  "devDependencies": {
32
33
  "@babel/cli": "^7.12.10",
33
34
  "@babel/core": "^7.12.10",
35
+ "@babel/plugin-transform-runtime": "^7.14.5",
34
36
  "@babel/preset-env": "^7.12.11",
35
37
  "@babel/preset-react": "^7.12.10",
36
38
  "babel-loader": "^8.2.2",
package/src/index.js CHANGED
@@ -127,9 +127,9 @@ class HCaptcha extends React.Component {
127
127
  const captchaId = hcaptcha.render(this.ref.current,
128
128
  {
129
129
  ...this.props,
130
- "error-callback" : this.handleError,
131
- "expired-callback": this.handleExpire,
132
- "callback" : this.handleSubmit
130
+ "error-callback" : this.handleError,
131
+ "expired-callback" : this.handleExpire,
132
+ "callback" : this.handleSubmit,
133
133
  });
134
134
 
135
135
  this.setState({ isRemoved: false, captchaId });
@@ -196,12 +196,16 @@ class HCaptcha extends React.Component {
196
196
  if (onError) onError(event);
197
197
  }
198
198
 
199
- execute () {
199
+ execute (opts = null) {
200
200
  const { isApiReady, isRemoved, captchaId } = this.state;
201
201
 
202
- if (!isApiReady || isRemoved) return
202
+ if (!isApiReady || isRemoved) return;
203
+
204
+ if (opts && typeof opts !== "object") {
205
+ opts = null;
206
+ }
203
207
 
204
- hcaptcha.execute(captchaId)
208
+ return hcaptcha.execute(captchaId, opts);
205
209
  }
206
210
 
207
211
  render () {
package/types/index.d.ts CHANGED
@@ -27,11 +27,18 @@ interface HCaptchaProps {
27
27
  reCaptchaCompat?: boolean;
28
28
  }
29
29
 
30
+ interface ExecuteResponse {
31
+ response: string;
32
+ key: string;
33
+ }
34
+
30
35
  declare class HCaptcha extends React.Component<HCaptchaProps, HCaptchaState> {
31
36
  resetCaptcha(): void;
32
37
  renderCaptcha(): void;
33
38
  removeCaptcha(): void;
34
- execute(): void;
39
+ execute(opts: { async: true }): Promise<ExecuteResponse>
40
+ execute(opts?: { async: false }): void;
41
+ execute(opts?: { async: boolean }): Promise<ExecuteResponse> | void;
35
42
  }
36
43
 
37
44
  export = HCaptcha;