@hcaptcha/react-hcaptcha 1.11.3 → 1.12.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/dist/esm/index.js +10 -37
- package/dist/index.js +9 -36
- package/package.json +2 -2
- package/src/index.js +6 -40
- package/dist/constants.js +0 -17
- package/dist/esm/constants.js +0 -11
- package/src/constants.js +0 -13
package/dist/esm/index.js
CHANGED
|
@@ -1,9 +1,8 @@
|
|
|
1
1
|
import _assertThisInitialized from "@babel/runtime/helpers/assertThisInitialized";
|
|
2
2
|
import _inheritsLoose from "@babel/runtime/helpers/inheritsLoose";
|
|
3
3
|
import * as React from 'react';
|
|
4
|
-
import { hCaptchaLoader
|
|
4
|
+
import { hCaptchaLoader } from '@hcaptcha/loader';
|
|
5
5
|
import { getFrame, getMountElement } from './utils.js';
|
|
6
|
-
import { breadcrumbMessages, scopeTag } from "./constants";
|
|
7
6
|
var HCaptcha = /*#__PURE__*/function (_React$Component) {
|
|
8
7
|
_inheritsLoose(HCaptcha, _React$Component);
|
|
9
8
|
function HCaptcha(props) {
|
|
@@ -53,11 +52,6 @@ var HCaptcha = /*#__PURE__*/function (_React$Component) {
|
|
|
53
52
|
var frame = getFrame(element);
|
|
54
53
|
this._hcaptcha = frame.window.hcaptcha || undefined;
|
|
55
54
|
var isApiReady = typeof this._hcaptcha !== 'undefined';
|
|
56
|
-
this.sentryHub = initSentry(this.props.sentry, scopeTag);
|
|
57
|
-
this.sentryHub.addBreadcrumb({
|
|
58
|
-
category: scopeTag.value,
|
|
59
|
-
message: breadcrumbMessages.mounted
|
|
60
|
-
});
|
|
61
55
|
|
|
62
56
|
/*
|
|
63
57
|
* Check if hCaptcha has already been loaded,
|
|
@@ -84,10 +78,6 @@ var HCaptcha = /*#__PURE__*/function (_React$Component) {
|
|
|
84
78
|
// Reset any stored variables / timers when unmounting
|
|
85
79
|
hcaptcha.reset(captchaId);
|
|
86
80
|
hcaptcha.remove(captchaId);
|
|
87
|
-
this.sentryHub.addBreadcrumb({
|
|
88
|
-
category: scopeTag.value,
|
|
89
|
-
message: breadcrumbMessages.unmounted
|
|
90
|
-
});
|
|
91
81
|
};
|
|
92
82
|
_proto.shouldComponentUpdate = function shouldComponentUpdate(nextProps, nextState) {
|
|
93
83
|
// Prevent component re-rendering when these internal state variables are updated
|
|
@@ -195,10 +185,6 @@ var HCaptcha = /*#__PURE__*/function (_React$Component) {
|
|
|
195
185
|
}
|
|
196
186
|
// Reset captcha state, removes stored token and unticks checkbox
|
|
197
187
|
hcaptcha.reset(captchaId);
|
|
198
|
-
this.sentryHub.addBreadcrumb({
|
|
199
|
-
category: scopeTag.value,
|
|
200
|
-
message: breadcrumbMessages.reset
|
|
201
|
-
});
|
|
202
188
|
};
|
|
203
189
|
_proto.removeCaptcha = function removeCaptcha(callback) {
|
|
204
190
|
var _this5 = this;
|
|
@@ -214,31 +200,23 @@ var HCaptcha = /*#__PURE__*/function (_React$Component) {
|
|
|
214
200
|
hcaptcha.remove(captchaId);
|
|
215
201
|
callback && callback();
|
|
216
202
|
});
|
|
217
|
-
this.sentryHub.addBreadcrumb({
|
|
218
|
-
category: scopeTag.value,
|
|
219
|
-
message: breadcrumbMessages.removed
|
|
220
|
-
});
|
|
221
203
|
};
|
|
222
204
|
_proto.handleOnLoad = function handleOnLoad() {
|
|
223
205
|
var _this6 = this;
|
|
224
206
|
this.setState({
|
|
225
207
|
isApiReady: true
|
|
226
208
|
}, function () {
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
_this6._hcaptcha = frame.window.hcaptcha;
|
|
209
|
+
var element = getMountElement(_this6.props.scriptLocation);
|
|
210
|
+
var frame = getFrame(element);
|
|
211
|
+
_this6._hcaptcha = frame.window.hcaptcha;
|
|
231
212
|
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
213
|
+
// render captcha and wait for captcha id
|
|
214
|
+
_this6.renderCaptcha(function () {
|
|
215
|
+
// trigger onLoad if it exists
|
|
235
216
|
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
} catch (error) {
|
|
240
|
-
_this6.sentryHub.captureException(error);
|
|
241
|
-
}
|
|
217
|
+
var onLoad = _this6.props.onLoad;
|
|
218
|
+
if (onLoad) onLoad();
|
|
219
|
+
});
|
|
242
220
|
});
|
|
243
221
|
};
|
|
244
222
|
_proto.handleSubmit = function handleSubmit(event) {
|
|
@@ -261,10 +239,6 @@ var HCaptcha = /*#__PURE__*/function (_React$Component) {
|
|
|
261
239
|
hcaptcha.reset(captchaId); // If hCaptcha runs into error, reset captcha - hCaptcha
|
|
262
240
|
|
|
263
241
|
if (onExpire) onExpire();
|
|
264
|
-
this.sentryHub.addBreadcrumb({
|
|
265
|
-
category: scopeTag.value,
|
|
266
|
-
message: breadcrumbMessages.expired
|
|
267
|
-
});
|
|
268
242
|
};
|
|
269
243
|
_proto.handleError = function handleError(event) {
|
|
270
244
|
var onError = this.props.onError;
|
|
@@ -329,7 +303,6 @@ var HCaptcha = /*#__PURE__*/function (_React$Component) {
|
|
|
329
303
|
}
|
|
330
304
|
return hcaptcha.execute(captchaId, opts);
|
|
331
305
|
} catch (error) {
|
|
332
|
-
this.sentryHub.captureException(error);
|
|
333
306
|
if (opts && opts.async) {
|
|
334
307
|
return Promise.reject(error);
|
|
335
308
|
}
|
package/dist/index.js
CHANGED
|
@@ -16,7 +16,6 @@ var _inherits2 = _interopRequireDefault(require("@babel/runtime/helpers/inherits
|
|
|
16
16
|
var React = _interopRequireWildcard(require("react"));
|
|
17
17
|
var _loader = require("@hcaptcha/loader");
|
|
18
18
|
var _utils = require("./utils.js");
|
|
19
|
-
var _constants = require("./constants");
|
|
20
19
|
function _getRequireWildcardCache(e) { if ("function" != typeof WeakMap) return null; var r = new WeakMap(), t = new WeakMap(); return (_getRequireWildcardCache = function _getRequireWildcardCache(e) { return e ? t : r; })(e); }
|
|
21
20
|
function _interopRequireWildcard(e, r) { if (!r && e && e.__esModule) return e; if (null === e || "object" != _typeof3(e) && "function" != typeof e) return { "default": e }; var t = _getRequireWildcardCache(r); if (t && t.has(e)) return t.get(e); var n = { __proto__: null }, a = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var u in e) if ("default" !== u && Object.prototype.hasOwnProperty.call(e, u)) { var i = a ? Object.getOwnPropertyDescriptor(e, u) : null; i && (i.get || i.set) ? Object.defineProperty(n, u, i) : n[u] = e[u]; } return n["default"] = e, t && t.set(e, n), n; }
|
|
22
21
|
function _callSuper(t, o, e) { return o = (0, _getPrototypeOf2["default"])(o), (0, _possibleConstructorReturn2["default"])(t, _isNativeReflectConstruct() ? Reflect.construct(o, e || [], (0, _getPrototypeOf2["default"])(t).constructor) : o.apply(t, e)); }
|
|
@@ -72,11 +71,6 @@ var HCaptcha = /*#__PURE__*/function (_React$Component) {
|
|
|
72
71
|
var frame = (0, _utils.getFrame)(element);
|
|
73
72
|
this._hcaptcha = frame.window.hcaptcha || undefined;
|
|
74
73
|
var isApiReady = typeof this._hcaptcha !== 'undefined';
|
|
75
|
-
this.sentryHub = (0, _loader.initSentry)(this.props.sentry, _constants.scopeTag);
|
|
76
|
-
this.sentryHub.addBreadcrumb({
|
|
77
|
-
category: _constants.scopeTag.value,
|
|
78
|
-
message: _constants.breadcrumbMessages.mounted
|
|
79
|
-
});
|
|
80
74
|
|
|
81
75
|
/*
|
|
82
76
|
* Check if hCaptcha has already been loaded,
|
|
@@ -105,10 +99,6 @@ var HCaptcha = /*#__PURE__*/function (_React$Component) {
|
|
|
105
99
|
// Reset any stored variables / timers when unmounting
|
|
106
100
|
hcaptcha.reset(captchaId);
|
|
107
101
|
hcaptcha.remove(captchaId);
|
|
108
|
-
this.sentryHub.addBreadcrumb({
|
|
109
|
-
category: _constants.scopeTag.value,
|
|
110
|
-
message: _constants.breadcrumbMessages.unmounted
|
|
111
|
-
});
|
|
112
102
|
}
|
|
113
103
|
}, {
|
|
114
104
|
key: "shouldComponentUpdate",
|
|
@@ -226,10 +216,6 @@ var HCaptcha = /*#__PURE__*/function (_React$Component) {
|
|
|
226
216
|
}
|
|
227
217
|
// Reset captcha state, removes stored token and unticks checkbox
|
|
228
218
|
hcaptcha.reset(captchaId);
|
|
229
|
-
this.sentryHub.addBreadcrumb({
|
|
230
|
-
category: _constants.scopeTag.value,
|
|
231
|
-
message: _constants.breadcrumbMessages.reset
|
|
232
|
-
});
|
|
233
219
|
}
|
|
234
220
|
}, {
|
|
235
221
|
key: "removeCaptcha",
|
|
@@ -247,10 +233,6 @@ var HCaptcha = /*#__PURE__*/function (_React$Component) {
|
|
|
247
233
|
hcaptcha.remove(captchaId);
|
|
248
234
|
callback && callback();
|
|
249
235
|
});
|
|
250
|
-
this.sentryHub.addBreadcrumb({
|
|
251
|
-
category: _constants.scopeTag.value,
|
|
252
|
-
message: _constants.breadcrumbMessages.removed
|
|
253
|
-
});
|
|
254
236
|
}
|
|
255
237
|
}, {
|
|
256
238
|
key: "handleOnLoad",
|
|
@@ -259,21 +241,17 @@ var HCaptcha = /*#__PURE__*/function (_React$Component) {
|
|
|
259
241
|
this.setState({
|
|
260
242
|
isApiReady: true
|
|
261
243
|
}, function () {
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
_this6._hcaptcha = frame.window.hcaptcha;
|
|
244
|
+
var element = (0, _utils.getMountElement)(_this6.props.scriptLocation);
|
|
245
|
+
var frame = (0, _utils.getFrame)(element);
|
|
246
|
+
_this6._hcaptcha = frame.window.hcaptcha;
|
|
266
247
|
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
248
|
+
// render captcha and wait for captcha id
|
|
249
|
+
_this6.renderCaptcha(function () {
|
|
250
|
+
// trigger onLoad if it exists
|
|
270
251
|
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
} catch (error) {
|
|
275
|
-
_this6.sentryHub.captureException(error);
|
|
276
|
-
}
|
|
252
|
+
var onLoad = _this6.props.onLoad;
|
|
253
|
+
if (onLoad) onLoad();
|
|
254
|
+
});
|
|
277
255
|
});
|
|
278
256
|
}
|
|
279
257
|
}, {
|
|
@@ -300,10 +278,6 @@ var HCaptcha = /*#__PURE__*/function (_React$Component) {
|
|
|
300
278
|
hcaptcha.reset(captchaId); // If hCaptcha runs into error, reset captcha - hCaptcha
|
|
301
279
|
|
|
302
280
|
if (onExpire) onExpire();
|
|
303
|
-
this.sentryHub.addBreadcrumb({
|
|
304
|
-
category: _constants.scopeTag.value,
|
|
305
|
-
message: _constants.breadcrumbMessages.expired
|
|
306
|
-
});
|
|
307
281
|
}
|
|
308
282
|
}, {
|
|
309
283
|
key: "handleError",
|
|
@@ -378,7 +352,6 @@ var HCaptcha = /*#__PURE__*/function (_React$Component) {
|
|
|
378
352
|
}
|
|
379
353
|
return hcaptcha.execute(captchaId, opts);
|
|
380
354
|
} catch (error) {
|
|
381
|
-
this.sentryHub.captureException(error);
|
|
382
355
|
if (opts && opts.async) {
|
|
383
356
|
return Promise.reject(error);
|
|
384
357
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@hcaptcha/react-hcaptcha",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.12.0",
|
|
4
4
|
"types": "types/index.d.ts",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"module": "dist/esm/index.js",
|
|
@@ -60,6 +60,6 @@
|
|
|
60
60
|
},
|
|
61
61
|
"dependencies": {
|
|
62
62
|
"@babel/runtime": "^7.17.9",
|
|
63
|
-
"@hcaptcha/loader": "^
|
|
63
|
+
"@hcaptcha/loader": "^2.0.0"
|
|
64
64
|
}
|
|
65
65
|
}
|
package/src/index.js
CHANGED
|
@@ -1,8 +1,7 @@
|
|
|
1
1
|
import * as React from 'react';
|
|
2
|
-
import { hCaptchaLoader
|
|
2
|
+
import { hCaptchaLoader } from '@hcaptcha/loader';
|
|
3
3
|
|
|
4
4
|
import { getFrame, getMountElement } from './utils.js';
|
|
5
|
-
import { breadcrumbMessages, scopeTag } from "./constants";
|
|
6
5
|
|
|
7
6
|
|
|
8
7
|
class HCaptcha extends React.Component {
|
|
@@ -53,13 +52,6 @@ class HCaptcha extends React.Component {
|
|
|
53
52
|
|
|
54
53
|
const isApiReady = typeof this._hcaptcha !== 'undefined';
|
|
55
54
|
|
|
56
|
-
this.sentryHub = initSentry(this.props.sentry, scopeTag);
|
|
57
|
-
|
|
58
|
-
this.sentryHub.addBreadcrumb({
|
|
59
|
-
category: scopeTag.value,
|
|
60
|
-
message: breadcrumbMessages.mounted,
|
|
61
|
-
});
|
|
62
|
-
|
|
63
55
|
/*
|
|
64
56
|
* Check if hCaptcha has already been loaded,
|
|
65
57
|
* If Yes, render the captcha
|
|
@@ -92,11 +84,6 @@ class HCaptcha extends React.Component {
|
|
|
92
84
|
// Reset any stored variables / timers when unmounting
|
|
93
85
|
hcaptcha.reset(captchaId);
|
|
94
86
|
hcaptcha.remove(captchaId);
|
|
95
|
-
|
|
96
|
-
this.sentryHub.addBreadcrumb({
|
|
97
|
-
category: scopeTag.value,
|
|
98
|
-
message: breadcrumbMessages.unmounted,
|
|
99
|
-
});
|
|
100
87
|
}
|
|
101
88
|
|
|
102
89
|
shouldComponentUpdate(nextProps, nextState) {
|
|
@@ -213,11 +200,6 @@ class HCaptcha extends React.Component {
|
|
|
213
200
|
}
|
|
214
201
|
// Reset captcha state, removes stored token and unticks checkbox
|
|
215
202
|
hcaptcha.reset(captchaId)
|
|
216
|
-
|
|
217
|
-
this.sentryHub.addBreadcrumb({
|
|
218
|
-
category: scopeTag.value,
|
|
219
|
-
message: breadcrumbMessages.reset,
|
|
220
|
-
});
|
|
221
203
|
}
|
|
222
204
|
|
|
223
205
|
removeCaptcha(callback) {
|
|
@@ -234,17 +216,10 @@ class HCaptcha extends React.Component {
|
|
|
234
216
|
hcaptcha.remove(captchaId);
|
|
235
217
|
callback && callback()
|
|
236
218
|
});
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
this.sentryHub.addBreadcrumb({
|
|
240
|
-
category: scopeTag.value,
|
|
241
|
-
message: breadcrumbMessages.removed,
|
|
242
|
-
});
|
|
243
219
|
}
|
|
244
220
|
|
|
245
221
|
handleOnLoad () {
|
|
246
222
|
this.setState({ isApiReady: true }, () => {
|
|
247
|
-
try {
|
|
248
223
|
const element = getMountElement(this.props.scriptLocation);
|
|
249
224
|
const frame = getFrame(element);
|
|
250
225
|
|
|
@@ -258,9 +233,6 @@ class HCaptcha extends React.Component {
|
|
|
258
233
|
const { onLoad } = this.props;
|
|
259
234
|
if (onLoad) onLoad();
|
|
260
235
|
});
|
|
261
|
-
} catch (error) {
|
|
262
|
-
this.sentryHub.captureException(error);
|
|
263
|
-
}
|
|
264
236
|
});
|
|
265
237
|
}
|
|
266
238
|
|
|
@@ -289,11 +261,6 @@ class HCaptcha extends React.Component {
|
|
|
289
261
|
hcaptcha.reset(captchaId) // If hCaptcha runs into error, reset captcha - hCaptcha
|
|
290
262
|
|
|
291
263
|
if (onExpire) onExpire();
|
|
292
|
-
|
|
293
|
-
this.sentryHub.addBreadcrumb({
|
|
294
|
-
category: scopeTag.value,
|
|
295
|
-
message: breadcrumbMessages.expired,
|
|
296
|
-
});
|
|
297
264
|
}
|
|
298
265
|
|
|
299
266
|
handleError (event) {
|
|
@@ -346,14 +313,14 @@ class HCaptcha extends React.Component {
|
|
|
346
313
|
try {
|
|
347
314
|
const hcaptcha = this._hcaptcha;
|
|
348
315
|
const captchaId = this.captchaId;
|
|
349
|
-
|
|
316
|
+
|
|
350
317
|
if (!this.isReady()) {
|
|
351
318
|
const onReady = new Promise((resolve, reject) => {
|
|
352
|
-
|
|
319
|
+
|
|
353
320
|
this._onReady = (id) => {
|
|
354
321
|
try {
|
|
355
322
|
const hcaptcha = this._hcaptcha;
|
|
356
|
-
|
|
323
|
+
|
|
357
324
|
if (opts && opts.async) {
|
|
358
325
|
hcaptcha.execute(id, opts).then(resolve).catch(reject);
|
|
359
326
|
} else {
|
|
@@ -364,13 +331,12 @@ class HCaptcha extends React.Component {
|
|
|
364
331
|
}
|
|
365
332
|
};
|
|
366
333
|
});
|
|
367
|
-
|
|
334
|
+
|
|
368
335
|
return opts?.async ? onReady : null;
|
|
369
336
|
}
|
|
370
|
-
|
|
337
|
+
|
|
371
338
|
return hcaptcha.execute(captchaId, opts);
|
|
372
339
|
} catch (error) {
|
|
373
|
-
this.sentryHub.captureException(error);
|
|
374
340
|
if (opts && opts.async) {
|
|
375
341
|
return Promise.reject(error);
|
|
376
342
|
}
|
package/dist/constants.js
DELETED
|
@@ -1,17 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
Object.defineProperty(exports, "__esModule", {
|
|
4
|
-
value: true
|
|
5
|
-
});
|
|
6
|
-
exports.scopeTag = exports.breadcrumbMessages = void 0;
|
|
7
|
-
var scopeTag = exports.scopeTag = {
|
|
8
|
-
key: 'source',
|
|
9
|
-
value: '@hCaptcha/react'
|
|
10
|
-
};
|
|
11
|
-
var breadcrumbMessages = exports.breadcrumbMessages = {
|
|
12
|
-
mounted: 'hCaptcha component mounted',
|
|
13
|
-
expired: 'hCaptcha expired',
|
|
14
|
-
unmounted: 'hCaptcha component unmounted',
|
|
15
|
-
reset: 'hCaptcha reset',
|
|
16
|
-
removed: 'hCaptcha removed'
|
|
17
|
-
};
|
package/dist/esm/constants.js
DELETED
|
@@ -1,11 +0,0 @@
|
|
|
1
|
-
export var scopeTag = {
|
|
2
|
-
key: 'source',
|
|
3
|
-
value: '@hCaptcha/react'
|
|
4
|
-
};
|
|
5
|
-
export var breadcrumbMessages = {
|
|
6
|
-
mounted: 'hCaptcha component mounted',
|
|
7
|
-
expired: 'hCaptcha expired',
|
|
8
|
-
unmounted: 'hCaptcha component unmounted',
|
|
9
|
-
reset: 'hCaptcha reset',
|
|
10
|
-
removed: 'hCaptcha removed'
|
|
11
|
-
};
|
package/src/constants.js
DELETED
|
@@ -1,13 +0,0 @@
|
|
|
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
|
-
}
|