@hcaptcha/react-hcaptcha 1.8.0 → 1.9.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 +1 -0
- package/dist/constants.js +19 -0
- package/dist/esm/constants.js +11 -0
- package/dist/esm/index.js +105 -161
- package/dist/esm/utils.js +2 -18
- package/dist/index.js +104 -149
- package/dist/utils.js +1 -26
- package/package.json +3 -2
- package/src/constants.js +13 -0
- package/src/index.js +84 -78
- package/src/utils.js +8 -16
- package/types/index.d.ts +2 -0
package/dist/index.js
CHANGED
|
@@ -1,108 +1,47 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
|
|
3
3
|
var _interopRequireWildcard = require("@babel/runtime/helpers/interopRequireWildcard");
|
|
4
|
-
|
|
5
4
|
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
|
|
6
|
-
|
|
7
5
|
Object.defineProperty(exports, "__esModule", {
|
|
8
6
|
value: true
|
|
9
7
|
});
|
|
10
8
|
exports["default"] = void 0;
|
|
11
|
-
|
|
12
9
|
var _typeof2 = _interopRequireDefault(require("@babel/runtime/helpers/typeof"));
|
|
13
|
-
|
|
14
10
|
var _classCallCheck2 = _interopRequireDefault(require("@babel/runtime/helpers/classCallCheck"));
|
|
15
|
-
|
|
16
11
|
var _createClass2 = _interopRequireDefault(require("@babel/runtime/helpers/createClass"));
|
|
17
|
-
|
|
18
12
|
var _assertThisInitialized2 = _interopRequireDefault(require("@babel/runtime/helpers/assertThisInitialized"));
|
|
19
|
-
|
|
20
13
|
var _inherits2 = _interopRequireDefault(require("@babel/runtime/helpers/inherits"));
|
|
21
|
-
|
|
22
14
|
var _possibleConstructorReturn2 = _interopRequireDefault(require("@babel/runtime/helpers/possibleConstructorReturn"));
|
|
23
|
-
|
|
24
15
|
var _getPrototypeOf2 = _interopRequireDefault(require("@babel/runtime/helpers/getPrototypeOf"));
|
|
25
|
-
|
|
26
16
|
var React = _interopRequireWildcard(require("react"));
|
|
27
|
-
|
|
17
|
+
var _loader = require("@hcaptcha/loader");
|
|
28
18
|
var _utils = require("./utils.js");
|
|
29
|
-
|
|
19
|
+
var _constants = require("./constants");
|
|
30
20
|
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); }; }
|
|
31
|
-
|
|
32
21
|
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; } }
|
|
33
|
-
|
|
34
|
-
var SCRIPT_ID = 'hcaptcha-api-script-id';
|
|
35
|
-
var HCAPTCHA_LOAD_FN_NAME = 'hcaptchaOnLoad'; // Prevent loading API script multiple times
|
|
36
|
-
|
|
37
|
-
var scripts = []; // Generate hCaptcha API script
|
|
38
|
-
|
|
39
|
-
var mountCaptchaScript = function mountCaptchaScript() {
|
|
40
|
-
var params = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
|
|
41
|
-
var element = (0, _utils.getMountElement)(params.scriptLocation);
|
|
42
|
-
delete params.scriptLocation;
|
|
43
|
-
var frame = (0, _utils.getFrame)(element);
|
|
44
|
-
var script = scripts.find(function (_ref) {
|
|
45
|
-
var scope = _ref.scope;
|
|
46
|
-
return scope === frame.window;
|
|
47
|
-
});
|
|
48
|
-
|
|
49
|
-
if (frame.document.getElementById(SCRIPT_ID) && script) {
|
|
50
|
-
// API was already requested
|
|
51
|
-
return script.promise;
|
|
52
|
-
}
|
|
53
|
-
|
|
54
|
-
var promise = new Promise(function (resolve, reject) {
|
|
55
|
-
// Create global onload callback
|
|
56
|
-
frame.window[HCAPTCHA_LOAD_FN_NAME] = resolve;
|
|
57
|
-
var domain = params.apihost || "https://js.hcaptcha.com";
|
|
58
|
-
delete params.apihost;
|
|
59
|
-
var script = frame.document.createElement("script");
|
|
60
|
-
script.id = SCRIPT_ID;
|
|
61
|
-
script.src = "".concat(domain, "/1/api.js?render=explicit&onload=").concat(HCAPTCHA_LOAD_FN_NAME);
|
|
62
|
-
script.async = params.loadAsync !== undefined ? params.loadAsync : true;
|
|
63
|
-
delete params.loadAsync;
|
|
64
|
-
|
|
65
|
-
script.onerror = function (event) {
|
|
66
|
-
return reject('script-error');
|
|
67
|
-
};
|
|
68
|
-
|
|
69
|
-
var query = (0, _utils.generateQuery)(params);
|
|
70
|
-
script.src += query !== "" ? "&".concat(query) : "";
|
|
71
|
-
element.appendChild(script);
|
|
72
|
-
});
|
|
73
|
-
scripts.push({
|
|
74
|
-
promise: promise,
|
|
75
|
-
scope: frame.window
|
|
76
|
-
});
|
|
77
|
-
return promise;
|
|
78
|
-
};
|
|
79
|
-
|
|
80
22
|
var HCaptcha = /*#__PURE__*/function (_React$Component) {
|
|
81
23
|
(0, _inherits2["default"])(HCaptcha, _React$Component);
|
|
82
|
-
|
|
83
24
|
var _super = _createSuper(HCaptcha);
|
|
84
|
-
|
|
85
25
|
function HCaptcha(props) {
|
|
86
26
|
var _this;
|
|
87
|
-
|
|
88
27
|
(0, _classCallCheck2["default"])(this, HCaptcha);
|
|
89
28
|
_this = _super.call(this, props);
|
|
90
|
-
|
|
91
|
-
var frame = (0, _utils.getFrame)(element);
|
|
29
|
+
|
|
92
30
|
/**
|
|
93
31
|
* Internal reference to track hCaptcha API
|
|
94
32
|
*
|
|
95
33
|
* Required as window is relative to initialization in application
|
|
96
34
|
* not where the script and iFrames have been loaded.
|
|
97
35
|
*/
|
|
36
|
+
_this._hcaptcha = undefined;
|
|
98
37
|
|
|
99
|
-
|
|
100
|
-
|
|
38
|
+
// API Methods
|
|
101
39
|
_this.renderCaptcha = _this.renderCaptcha.bind((0, _assertThisInitialized2["default"])(_this));
|
|
102
40
|
_this.resetCaptcha = _this.resetCaptcha.bind((0, _assertThisInitialized2["default"])(_this));
|
|
103
41
|
_this.removeCaptcha = _this.removeCaptcha.bind((0, _assertThisInitialized2["default"])(_this));
|
|
104
|
-
_this.isReady = _this.isReady.bind((0, _assertThisInitialized2["default"])(_this));
|
|
42
|
+
_this.isReady = _this.isReady.bind((0, _assertThisInitialized2["default"])(_this));
|
|
105
43
|
|
|
44
|
+
// Event Handlers
|
|
106
45
|
_this.loadCaptcha = _this.loadCaptcha.bind((0, _assertThisInitialized2["default"])(_this));
|
|
107
46
|
_this.handleOnLoad = _this.handleOnLoad.bind((0, _assertThisInitialized2["default"])(_this));
|
|
108
47
|
_this.handleSubmit = _this.handleSubmit.bind((0, _assertThisInitialized2["default"])(_this));
|
|
@@ -111,34 +50,45 @@ var HCaptcha = /*#__PURE__*/function (_React$Component) {
|
|
|
111
50
|
_this.handleOpen = _this.handleOpen.bind((0, _assertThisInitialized2["default"])(_this));
|
|
112
51
|
_this.handleClose = _this.handleClose.bind((0, _assertThisInitialized2["default"])(_this));
|
|
113
52
|
_this.handleChallengeExpired = _this.handleChallengeExpired.bind((0, _assertThisInitialized2["default"])(_this));
|
|
114
|
-
var isApiReady = typeof _this._hcaptcha !== 'undefined';
|
|
115
53
|
_this.ref = /*#__PURE__*/React.createRef();
|
|
116
54
|
_this.apiScriptRequested = false;
|
|
55
|
+
_this.sentryHub = null;
|
|
117
56
|
_this.state = {
|
|
118
|
-
isApiReady:
|
|
57
|
+
isApiReady: false,
|
|
119
58
|
isRemoved: false,
|
|
120
59
|
elementId: props.id,
|
|
121
60
|
captchaId: ''
|
|
122
61
|
};
|
|
123
62
|
return _this;
|
|
124
63
|
}
|
|
125
|
-
|
|
126
64
|
(0, _createClass2["default"])(HCaptcha, [{
|
|
127
65
|
key: "componentDidMount",
|
|
128
66
|
value: function componentDidMount() {
|
|
67
|
+
var _this2 = this;
|
|
129
68
|
// Once captcha is mounted intialize hCaptcha - hCaptcha
|
|
130
|
-
var
|
|
69
|
+
var element = (0, _utils.getMountElement)(this.props.scriptLocation);
|
|
70
|
+
var frame = (0, _utils.getFrame)(element);
|
|
71
|
+
this._hcaptcha = frame.window.hcaptcha || undefined;
|
|
72
|
+
var isApiReady = typeof this._hcaptcha !== 'undefined';
|
|
73
|
+
this.sentryHub = (0, _loader.initSentry)(this.props.sentry, _constants.scopeTag);
|
|
74
|
+
this.sentryHub.addBreadcrumb({
|
|
75
|
+
category: _constants.scopeTag.value,
|
|
76
|
+
message: _constants.breadcrumbMessages.mounted
|
|
77
|
+
});
|
|
78
|
+
|
|
131
79
|
/*
|
|
132
80
|
* Check if hCaptcha has already been loaded,
|
|
133
81
|
* If Yes, render the captcha
|
|
134
82
|
* If No, create script tag and wait to render the captcha
|
|
135
83
|
*/
|
|
136
|
-
|
|
137
84
|
if (isApiReady) {
|
|
138
|
-
this.
|
|
85
|
+
this.setState({
|
|
86
|
+
isApiReady: true
|
|
87
|
+
}, function () {
|
|
88
|
+
_this2.renderCaptcha();
|
|
89
|
+
});
|
|
139
90
|
return;
|
|
140
91
|
}
|
|
141
|
-
|
|
142
92
|
this.loadCaptcha();
|
|
143
93
|
}
|
|
144
94
|
}, {
|
|
@@ -146,14 +96,17 @@ var HCaptcha = /*#__PURE__*/function (_React$Component) {
|
|
|
146
96
|
value: function componentWillUnmount() {
|
|
147
97
|
var captchaId = this.state.captchaId;
|
|
148
98
|
var hcaptcha = this._hcaptcha;
|
|
149
|
-
|
|
150
99
|
if (!this.isReady()) {
|
|
151
100
|
return;
|
|
152
|
-
}
|
|
153
|
-
|
|
101
|
+
}
|
|
154
102
|
|
|
103
|
+
// Reset any stored variables / timers when unmounting
|
|
155
104
|
hcaptcha.reset(captchaId);
|
|
156
105
|
hcaptcha.remove(captchaId);
|
|
106
|
+
this.sentryHub.addBreadcrumb({
|
|
107
|
+
category: _constants.scopeTag.value,
|
|
108
|
+
message: _constants.breadcrumbMessages.unmounted
|
|
109
|
+
});
|
|
157
110
|
}
|
|
158
111
|
}, {
|
|
159
112
|
key: "shouldComponentUpdate",
|
|
@@ -162,24 +115,23 @@ var HCaptcha = /*#__PURE__*/function (_React$Component) {
|
|
|
162
115
|
if (this.state.isApiReady !== nextState.isApiReady || this.state.isRemoved !== nextState.isRemoved) {
|
|
163
116
|
return false;
|
|
164
117
|
}
|
|
165
|
-
|
|
166
118
|
return true;
|
|
167
119
|
}
|
|
168
120
|
}, {
|
|
169
121
|
key: "componentDidUpdate",
|
|
170
122
|
value: function componentDidUpdate(prevProps) {
|
|
171
|
-
var
|
|
172
|
-
|
|
123
|
+
var _this3 = this;
|
|
173
124
|
// Prop Keys that could change
|
|
174
|
-
var keys = ['sitekey', 'size', 'theme', 'tabindex', 'languageOverride', 'endpoint'];
|
|
175
|
-
|
|
125
|
+
var keys = ['sitekey', 'size', 'theme', 'tabindex', 'languageOverride', 'endpoint'];
|
|
126
|
+
// See if any props changed during component update
|
|
176
127
|
var match = keys.every(function (key) {
|
|
177
|
-
return prevProps[key] ===
|
|
178
|
-
});
|
|
128
|
+
return prevProps[key] === _this3.props[key];
|
|
129
|
+
});
|
|
179
130
|
|
|
131
|
+
// If they have changed, remove current captcha and render a new one
|
|
180
132
|
if (!match) {
|
|
181
133
|
this.removeCaptcha(function () {
|
|
182
|
-
|
|
134
|
+
_this3.renderCaptcha();
|
|
183
135
|
});
|
|
184
136
|
}
|
|
185
137
|
}
|
|
@@ -189,35 +141,38 @@ var HCaptcha = /*#__PURE__*/function (_React$Component) {
|
|
|
189
141
|
if (this.apiScriptRequested) {
|
|
190
142
|
return;
|
|
191
143
|
}
|
|
192
|
-
|
|
193
144
|
var _this$props = this.props,
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
145
|
+
apihost = _this$props.apihost,
|
|
146
|
+
assethost = _this$props.assethost,
|
|
147
|
+
endpoint = _this$props.endpoint,
|
|
148
|
+
host = _this$props.host,
|
|
149
|
+
imghost = _this$props.imghost,
|
|
150
|
+
hl = _this$props.languageOverride,
|
|
151
|
+
reCaptchaCompat = _this$props.reCaptchaCompat,
|
|
152
|
+
reportapi = _this$props.reportapi,
|
|
153
|
+
sentry = _this$props.sentry,
|
|
154
|
+
custom = _this$props.custom,
|
|
155
|
+
loadAsync = _this$props.loadAsync,
|
|
156
|
+
scriptLocation = _this$props.scriptLocation,
|
|
157
|
+
_this$props$cleanup = _this$props.cleanup,
|
|
158
|
+
cleanup = _this$props$cleanup === void 0 ? true : _this$props$cleanup;
|
|
206
159
|
var mountParams = {
|
|
160
|
+
render: 'explicit',
|
|
207
161
|
apihost: apihost,
|
|
208
162
|
assethost: assethost,
|
|
209
163
|
endpoint: endpoint,
|
|
210
164
|
hl: hl,
|
|
211
165
|
host: host,
|
|
212
166
|
imghost: imghost,
|
|
213
|
-
recaptchacompat: reCaptchaCompat === false ?
|
|
167
|
+
recaptchacompat: reCaptchaCompat === false ? 'off' : null,
|
|
214
168
|
reportapi: reportapi,
|
|
215
169
|
sentry: sentry,
|
|
216
170
|
custom: custom,
|
|
217
171
|
loadAsync: loadAsync,
|
|
218
|
-
scriptLocation: scriptLocation
|
|
172
|
+
scriptLocation: scriptLocation,
|
|
173
|
+
cleanup: cleanup
|
|
219
174
|
};
|
|
220
|
-
|
|
175
|
+
(0, _loader.hCaptchaLoader)(mountParams).then(this.handleOnLoad, this.handleError)["catch"](this.handleError);
|
|
221
176
|
this.apiScriptRequested = true;
|
|
222
177
|
}
|
|
223
178
|
}, {
|
|
@@ -236,8 +191,8 @@ var HCaptcha = /*#__PURE__*/function (_React$Component) {
|
|
|
236
191
|
hl: this.props.hl || this.props.languageOverride,
|
|
237
192
|
languageOverride: undefined
|
|
238
193
|
});
|
|
239
|
-
var hcaptcha = this._hcaptcha;
|
|
240
|
-
|
|
194
|
+
var hcaptcha = this._hcaptcha;
|
|
195
|
+
//Render hCaptcha widget and provide necessary callbacks - hCaptcha
|
|
241
196
|
var captchaId = hcaptcha.render(this.ref.current, renderParams);
|
|
242
197
|
this.setState({
|
|
243
198
|
isRemoved: false,
|
|
@@ -251,48 +206,56 @@ var HCaptcha = /*#__PURE__*/function (_React$Component) {
|
|
|
251
206
|
value: function resetCaptcha() {
|
|
252
207
|
var captchaId = this.state.captchaId;
|
|
253
208
|
var hcaptcha = this._hcaptcha;
|
|
254
|
-
|
|
255
209
|
if (!this.isReady()) {
|
|
256
210
|
return;
|
|
257
|
-
}
|
|
258
|
-
|
|
259
|
-
|
|
211
|
+
}
|
|
212
|
+
// Reset captcha state, removes stored token and unticks checkbox
|
|
260
213
|
hcaptcha.reset(captchaId);
|
|
214
|
+
this.sentryHub.addBreadcrumb({
|
|
215
|
+
category: _constants.scopeTag.value,
|
|
216
|
+
message: _constants.breadcrumbMessages.reset
|
|
217
|
+
});
|
|
261
218
|
}
|
|
262
219
|
}, {
|
|
263
220
|
key: "removeCaptcha",
|
|
264
221
|
value: function removeCaptcha(callback) {
|
|
265
222
|
var captchaId = this.state.captchaId;
|
|
266
223
|
var hcaptcha = this._hcaptcha;
|
|
267
|
-
|
|
268
224
|
if (!this.isReady()) {
|
|
269
225
|
return;
|
|
270
226
|
}
|
|
271
|
-
|
|
272
227
|
this.setState({
|
|
273
228
|
isRemoved: true
|
|
274
229
|
}, function () {
|
|
275
230
|
hcaptcha.remove(captchaId);
|
|
276
231
|
callback && callback();
|
|
277
232
|
});
|
|
233
|
+
this.sentryHub.addBreadcrumb({
|
|
234
|
+
category: _constants.scopeTag.value,
|
|
235
|
+
message: _constants.breadcrumbMessages.removed
|
|
236
|
+
});
|
|
278
237
|
}
|
|
279
238
|
}, {
|
|
280
239
|
key: "handleOnLoad",
|
|
281
240
|
value: function handleOnLoad() {
|
|
282
|
-
var
|
|
283
|
-
|
|
241
|
+
var _this4 = this;
|
|
284
242
|
this.setState({
|
|
285
243
|
isApiReady: true
|
|
286
244
|
}, function () {
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
//
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
245
|
+
try {
|
|
246
|
+
var element = (0, _utils.getMountElement)(_this4.props.scriptLocation);
|
|
247
|
+
var frame = (0, _utils.getFrame)(element);
|
|
248
|
+
_this4._hcaptcha = frame.window.hcaptcha;
|
|
249
|
+
|
|
250
|
+
// render captcha and wait for captcha id
|
|
251
|
+
_this4.renderCaptcha(function () {
|
|
252
|
+
// trigger onLoad if it exists
|
|
253
|
+
var onLoad = _this4.props.onLoad;
|
|
254
|
+
if (onLoad) onLoad();
|
|
255
|
+
});
|
|
256
|
+
} catch (error) {
|
|
257
|
+
_this4.sentryHub.captureException(error);
|
|
258
|
+
}
|
|
296
259
|
});
|
|
297
260
|
}
|
|
298
261
|
}, {
|
|
@@ -300,14 +263,12 @@ var HCaptcha = /*#__PURE__*/function (_React$Component) {
|
|
|
300
263
|
value: function handleSubmit(event) {
|
|
301
264
|
var onVerify = this.props.onVerify;
|
|
302
265
|
var _this$state = this.state,
|
|
303
|
-
|
|
304
|
-
|
|
266
|
+
isRemoved = _this$state.isRemoved,
|
|
267
|
+
captchaId = _this$state.captchaId;
|
|
305
268
|
var hcaptcha = this._hcaptcha;
|
|
306
269
|
if (typeof hcaptcha === 'undefined' || isRemoved) return;
|
|
307
270
|
var token = hcaptcha.getResponse(captchaId); //Get response token from hCaptcha widget
|
|
308
|
-
|
|
309
271
|
var ekey = hcaptcha.getRespKey(captchaId); //Get current challenge session id from hCaptcha widget
|
|
310
|
-
|
|
311
272
|
if (onVerify) onVerify(token, ekey); //Dispatch event to verify user response
|
|
312
273
|
}
|
|
313
274
|
}, {
|
|
@@ -316,14 +277,16 @@ var HCaptcha = /*#__PURE__*/function (_React$Component) {
|
|
|
316
277
|
var onExpire = this.props.onExpire;
|
|
317
278
|
var captchaId = this.state.captchaId;
|
|
318
279
|
var hcaptcha = this._hcaptcha;
|
|
319
|
-
|
|
320
280
|
if (!this.isReady()) {
|
|
321
281
|
return;
|
|
322
282
|
}
|
|
323
|
-
|
|
324
283
|
hcaptcha.reset(captchaId); // If hCaptcha runs into error, reset captcha - hCaptcha
|
|
325
284
|
|
|
326
285
|
if (onExpire) onExpire();
|
|
286
|
+
this.sentryHub.addBreadcrumb({
|
|
287
|
+
category: _constants.scopeTag.value,
|
|
288
|
+
message: _constants.breadcrumbMessages.expired
|
|
289
|
+
});
|
|
327
290
|
}
|
|
328
291
|
}, {
|
|
329
292
|
key: "handleError",
|
|
@@ -331,20 +294,18 @@ var HCaptcha = /*#__PURE__*/function (_React$Component) {
|
|
|
331
294
|
var onError = this.props.onError;
|
|
332
295
|
var captchaId = this.state.captchaId;
|
|
333
296
|
var hcaptcha = this._hcaptcha;
|
|
334
|
-
|
|
335
297
|
if (this.isReady()) {
|
|
336
298
|
// If hCaptcha runs into error, reset captcha - hCaptcha
|
|
337
299
|
hcaptcha.reset(captchaId);
|
|
338
300
|
}
|
|
339
|
-
|
|
340
301
|
if (onError) onError(event);
|
|
341
302
|
}
|
|
342
303
|
}, {
|
|
343
304
|
key: "isReady",
|
|
344
305
|
value: function isReady() {
|
|
345
306
|
var _this$state2 = this.state,
|
|
346
|
-
|
|
347
|
-
|
|
307
|
+
isApiReady = _this$state2.isApiReady,
|
|
308
|
+
isRemoved = _this$state2.isRemoved;
|
|
348
309
|
return isApiReady && !isRemoved;
|
|
349
310
|
}
|
|
350
311
|
}, {
|
|
@@ -353,7 +314,6 @@ var HCaptcha = /*#__PURE__*/function (_React$Component) {
|
|
|
353
314
|
if (!this.isReady() || !this.props.onOpen) {
|
|
354
315
|
return;
|
|
355
316
|
}
|
|
356
|
-
|
|
357
317
|
this.props.onOpen();
|
|
358
318
|
}
|
|
359
319
|
}, {
|
|
@@ -362,7 +322,6 @@ var HCaptcha = /*#__PURE__*/function (_React$Component) {
|
|
|
362
322
|
if (!this.isReady() || !this.props.onClose) {
|
|
363
323
|
return;
|
|
364
324
|
}
|
|
365
|
-
|
|
366
325
|
this.props.onClose();
|
|
367
326
|
}
|
|
368
327
|
}, {
|
|
@@ -371,40 +330,37 @@ var HCaptcha = /*#__PURE__*/function (_React$Component) {
|
|
|
371
330
|
if (!this.isReady() || !this.props.onChalExpired) {
|
|
372
331
|
return;
|
|
373
332
|
}
|
|
374
|
-
|
|
375
333
|
this.props.onChalExpired();
|
|
376
334
|
}
|
|
377
335
|
}, {
|
|
378
336
|
key: "execute",
|
|
379
337
|
value: function execute() {
|
|
380
338
|
var opts = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : null;
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
|
|
339
|
+
try {
|
|
340
|
+
var captchaId = this.state.captchaId;
|
|
341
|
+
var hcaptcha = this._hcaptcha;
|
|
342
|
+
if (!this.isReady()) {
|
|
343
|
+
return;
|
|
344
|
+
}
|
|
345
|
+
if (opts && (0, _typeof2["default"])(opts) !== "object") {
|
|
346
|
+
opts = null;
|
|
347
|
+
}
|
|
348
|
+
return hcaptcha.execute(captchaId, opts);
|
|
349
|
+
} catch (error) {
|
|
350
|
+
this.sentryHub.captureException(error);
|
|
390
351
|
}
|
|
391
|
-
|
|
392
|
-
return hcaptcha.execute(captchaId, opts);
|
|
393
352
|
}
|
|
394
353
|
}, {
|
|
395
354
|
key: "setData",
|
|
396
355
|
value: function setData(data) {
|
|
397
356
|
var captchaId = this.state.captchaId;
|
|
398
357
|
var hcaptcha = this._hcaptcha;
|
|
399
|
-
|
|
400
358
|
if (!this.isReady()) {
|
|
401
359
|
return;
|
|
402
360
|
}
|
|
403
|
-
|
|
404
361
|
if (data && (0, _typeof2["default"])(data) !== "object") {
|
|
405
362
|
data = null;
|
|
406
363
|
}
|
|
407
|
-
|
|
408
364
|
hcaptcha.setData(captchaId, data);
|
|
409
365
|
}
|
|
410
366
|
}, {
|
|
@@ -431,7 +387,6 @@ var HCaptcha = /*#__PURE__*/function (_React$Component) {
|
|
|
431
387
|
}]);
|
|
432
388
|
return HCaptcha;
|
|
433
389
|
}(React.Component);
|
|
434
|
-
|
|
435
390
|
var _default = HCaptcha;
|
|
436
391
|
exports["default"] = _default;
|
|
437
392
|
module.exports = exports.default;
|
package/dist/utils.js
CHANGED
|
@@ -1,43 +1,18 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
|
|
3
|
-
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
|
|
4
|
-
|
|
5
3
|
Object.defineProperty(exports, "__esModule", {
|
|
6
4
|
value: true
|
|
7
5
|
});
|
|
8
|
-
exports.generateQuery = generateQuery;
|
|
9
6
|
exports.getFrame = getFrame;
|
|
10
7
|
exports.getMountElement = getMountElement;
|
|
11
|
-
|
|
12
|
-
var _slicedToArray2 = _interopRequireDefault(require("@babel/runtime/helpers/slicedToArray"));
|
|
13
|
-
|
|
14
|
-
function generateQuery(params) {
|
|
15
|
-
return Object.entries(params).filter(function (_ref) {
|
|
16
|
-
var _ref2 = (0, _slicedToArray2["default"])(_ref, 2),
|
|
17
|
-
key = _ref2[0],
|
|
18
|
-
value = _ref2[1];
|
|
19
|
-
|
|
20
|
-
return value || value === false;
|
|
21
|
-
}).map(function (_ref3) {
|
|
22
|
-
var _ref4 = (0, _slicedToArray2["default"])(_ref3, 2),
|
|
23
|
-
key = _ref4[0],
|
|
24
|
-
value = _ref4[1];
|
|
25
|
-
|
|
26
|
-
return "".concat(encodeURIComponent(key), "=").concat(encodeURIComponent(value));
|
|
27
|
-
}).join("&");
|
|
28
|
-
}
|
|
29
|
-
|
|
30
|
-
;
|
|
31
|
-
|
|
32
8
|
function getFrame(element) {
|
|
33
9
|
var doc = element && element.ownerDocument || document;
|
|
34
|
-
var win = doc.defaultView || doc.parentWindow;
|
|
10
|
+
var win = doc.defaultView || doc.parentWindow || window;
|
|
35
11
|
return {
|
|
36
12
|
document: doc,
|
|
37
13
|
window: win
|
|
38
14
|
};
|
|
39
15
|
}
|
|
40
|
-
|
|
41
16
|
function getMountElement(element) {
|
|
42
17
|
return element || document.head;
|
|
43
18
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@hcaptcha/react-hcaptcha",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.9.0",
|
|
4
4
|
"types": "types/index.d.ts",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"module": "dist/esm/index.js",
|
|
@@ -58,6 +58,7 @@
|
|
|
58
58
|
"webpack-dev-server": "^4.13.1"
|
|
59
59
|
},
|
|
60
60
|
"dependencies": {
|
|
61
|
-
"@babel/runtime": "^7.17.9"
|
|
61
|
+
"@babel/runtime": "^7.17.9",
|
|
62
|
+
"@hcaptcha/loader": "^1.0.8"
|
|
62
63
|
}
|
|
63
64
|
}
|
package/src/constants.js
ADDED
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
export const scopeTag = {
|
|
2
|
+
key: 'source',
|
|
3
|
+
value: '@hCaptcha/react'
|
|
4
|
+
}
|
|
5
|
+
|
|
6
|
+
export const breadcrumbMessages = {
|
|
7
|
+
mounted: 'hCaptcha component mounted',
|
|
8
|
+
expired: 'hCaptcha expired',
|
|
9
|
+
unmounted: 'hCaptcha component unmounted',
|
|
10
|
+
reset: 'hCaptcha reset',
|
|
11
|
+
removed: 'hCaptcha removed'
|
|
12
|
+
|
|
13
|
+
}
|