@hcaptcha/react-hcaptcha 1.11.2 → 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 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, initSentry } from '@hcaptcha/loader';
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,12 +185,9 @@ 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) {
190
+ var _this5 = this;
204
191
  var hcaptcha = this._hcaptcha;
205
192
  var captchaId = this.captchaId;
206
193
  if (!this.isReady()) {
@@ -209,34 +196,27 @@ var HCaptcha = /*#__PURE__*/function (_React$Component) {
209
196
  this.setState({
210
197
  isRemoved: true
211
198
  }, function () {
199
+ _this5.captchaId = '';
212
200
  hcaptcha.remove(captchaId);
213
201
  callback && callback();
214
202
  });
215
- this.sentryHub.addBreadcrumb({
216
- category: scopeTag.value,
217
- message: breadcrumbMessages.removed
218
- });
219
203
  };
220
204
  _proto.handleOnLoad = function handleOnLoad() {
221
- var _this5 = this;
205
+ var _this6 = this;
222
206
  this.setState({
223
207
  isApiReady: true
224
208
  }, function () {
225
- try {
226
- var element = getMountElement(_this5.props.scriptLocation);
227
- var frame = getFrame(element);
228
- _this5._hcaptcha = frame.window.hcaptcha;
209
+ var element = getMountElement(_this6.props.scriptLocation);
210
+ var frame = getFrame(element);
211
+ _this6._hcaptcha = frame.window.hcaptcha;
229
212
 
230
- // render captcha and wait for captcha id
231
- _this5.renderCaptcha(function () {
232
- // trigger onLoad if it exists
213
+ // render captcha and wait for captcha id
214
+ _this6.renderCaptcha(function () {
215
+ // trigger onLoad if it exists
233
216
 
234
- var onLoad = _this5.props.onLoad;
235
- if (onLoad) onLoad();
236
- });
237
- } catch (error) {
238
- _this5.sentryHub.captureException(error);
239
- }
217
+ var onLoad = _this6.props.onLoad;
218
+ if (onLoad) onLoad();
219
+ });
240
220
  });
241
221
  };
242
222
  _proto.handleSubmit = function handleSubmit(event) {
@@ -259,10 +239,6 @@ var HCaptcha = /*#__PURE__*/function (_React$Component) {
259
239
  hcaptcha.reset(captchaId); // If hCaptcha runs into error, reset captcha - hCaptcha
260
240
 
261
241
  if (onExpire) onExpire();
262
- this.sentryHub.addBreadcrumb({
263
- category: scopeTag.value,
264
- message: breadcrumbMessages.expired
265
- });
266
242
  };
267
243
  _proto.handleError = function handleError(event) {
268
244
  var onError = this.props.onError;
@@ -299,7 +275,7 @@ var HCaptcha = /*#__PURE__*/function (_React$Component) {
299
275
  this.props.onChalExpired();
300
276
  };
301
277
  _proto.execute = function execute(opts) {
302
- var _this6 = this;
278
+ var _this7 = this;
303
279
  if (opts === void 0) {
304
280
  opts = null;
305
281
  }
@@ -310,9 +286,9 @@ var HCaptcha = /*#__PURE__*/function (_React$Component) {
310
286
  if (!this.isReady()) {
311
287
  var _opts;
312
288
  var onReady = new Promise(function (resolve, reject) {
313
- _this6._onReady = function (id) {
289
+ _this7._onReady = function (id) {
314
290
  try {
315
- var _hcaptcha = _this6._hcaptcha;
291
+ var _hcaptcha = _this7._hcaptcha;
316
292
  if (opts && opts.async) {
317
293
  _hcaptcha.execute(id, opts).then(resolve)["catch"](reject);
318
294
  } else {
@@ -327,7 +303,6 @@ var HCaptcha = /*#__PURE__*/function (_React$Component) {
327
303
  }
328
304
  return hcaptcha.execute(captchaId, opts);
329
305
  } catch (error) {
330
- this.sentryHub.captureException(error);
331
306
  if (opts && opts.async) {
332
307
  return Promise.reject(error);
333
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,14 +216,11 @@ 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",
236
222
  value: function removeCaptcha(callback) {
223
+ var _this5 = this;
237
224
  var hcaptcha = this._hcaptcha;
238
225
  var captchaId = this.captchaId;
239
226
  if (!this.isReady()) {
@@ -242,36 +229,29 @@ var HCaptcha = /*#__PURE__*/function (_React$Component) {
242
229
  this.setState({
243
230
  isRemoved: true
244
231
  }, function () {
232
+ _this5.captchaId = '';
245
233
  hcaptcha.remove(captchaId);
246
234
  callback && callback();
247
235
  });
248
- this.sentryHub.addBreadcrumb({
249
- category: _constants.scopeTag.value,
250
- message: _constants.breadcrumbMessages.removed
251
- });
252
236
  }
253
237
  }, {
254
238
  key: "handleOnLoad",
255
239
  value: function handleOnLoad() {
256
- var _this5 = this;
240
+ var _this6 = this;
257
241
  this.setState({
258
242
  isApiReady: true
259
243
  }, function () {
260
- try {
261
- var element = (0, _utils.getMountElement)(_this5.props.scriptLocation);
262
- var frame = (0, _utils.getFrame)(element);
263
- _this5._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;
264
247
 
265
- // render captcha and wait for captcha id
266
- _this5.renderCaptcha(function () {
267
- // trigger onLoad if it exists
248
+ // render captcha and wait for captcha id
249
+ _this6.renderCaptcha(function () {
250
+ // trigger onLoad if it exists
268
251
 
269
- var onLoad = _this5.props.onLoad;
270
- if (onLoad) onLoad();
271
- });
272
- } catch (error) {
273
- _this5.sentryHub.captureException(error);
274
- }
252
+ var onLoad = _this6.props.onLoad;
253
+ if (onLoad) onLoad();
254
+ });
275
255
  });
276
256
  }
277
257
  }, {
@@ -298,10 +278,6 @@ var HCaptcha = /*#__PURE__*/function (_React$Component) {
298
278
  hcaptcha.reset(captchaId); // If hCaptcha runs into error, reset captcha - hCaptcha
299
279
 
300
280
  if (onExpire) onExpire();
301
- this.sentryHub.addBreadcrumb({
302
- category: _constants.scopeTag.value,
303
- message: _constants.breadcrumbMessages.expired
304
- });
305
281
  }
306
282
  }, {
307
283
  key: "handleError",
@@ -350,7 +326,7 @@ var HCaptcha = /*#__PURE__*/function (_React$Component) {
350
326
  }, {
351
327
  key: "execute",
352
328
  value: function execute() {
353
- var _this6 = this;
329
+ var _this7 = this;
354
330
  var opts = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : null;
355
331
  opts = (0, _typeof2["default"])(opts) === 'object' ? opts : null;
356
332
  try {
@@ -359,9 +335,9 @@ var HCaptcha = /*#__PURE__*/function (_React$Component) {
359
335
  if (!this.isReady()) {
360
336
  var _opts;
361
337
  var onReady = new Promise(function (resolve, reject) {
362
- _this6._onReady = function (id) {
338
+ _this7._onReady = function (id) {
363
339
  try {
364
- var _hcaptcha = _this6._hcaptcha;
340
+ var _hcaptcha = _this7._hcaptcha;
365
341
  if (opts && opts.async) {
366
342
  _hcaptcha.execute(id, opts).then(resolve)["catch"](reject);
367
343
  } else {
@@ -376,7 +352,6 @@ var HCaptcha = /*#__PURE__*/function (_React$Component) {
376
352
  }
377
353
  return hcaptcha.execute(captchaId, opts);
378
354
  } catch (error) {
379
- this.sentryHub.captureException(error);
380
355
  if (opts && opts.async) {
381
356
  return Promise.reject(error);
382
357
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@hcaptcha/react-hcaptcha",
3
- "version": "1.11.2",
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": "^1.2.1"
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, initSentry } from '@hcaptcha/loader';
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) {
@@ -229,20 +211,15 @@ class HCaptcha extends React.Component {
229
211
  }
230
212
 
231
213
  this.setState({ isRemoved: true }, () => {
214
+ this.captchaId = '';
215
+
232
216
  hcaptcha.remove(captchaId);
233
217
  callback && callback()
234
218
  });
235
-
236
-
237
- this.sentryHub.addBreadcrumb({
238
- category: scopeTag.value,
239
- message: breadcrumbMessages.removed,
240
- });
241
219
  }
242
220
 
243
221
  handleOnLoad () {
244
222
  this.setState({ isApiReady: true }, () => {
245
- try {
246
223
  const element = getMountElement(this.props.scriptLocation);
247
224
  const frame = getFrame(element);
248
225
 
@@ -256,9 +233,6 @@ class HCaptcha extends React.Component {
256
233
  const { onLoad } = this.props;
257
234
  if (onLoad) onLoad();
258
235
  });
259
- } catch (error) {
260
- this.sentryHub.captureException(error);
261
- }
262
236
  });
263
237
  }
264
238
 
@@ -287,11 +261,6 @@ class HCaptcha extends React.Component {
287
261
  hcaptcha.reset(captchaId) // If hCaptcha runs into error, reset captcha - hCaptcha
288
262
 
289
263
  if (onExpire) onExpire();
290
-
291
- this.sentryHub.addBreadcrumb({
292
- category: scopeTag.value,
293
- message: breadcrumbMessages.expired,
294
- });
295
264
  }
296
265
 
297
266
  handleError (event) {
@@ -344,14 +313,14 @@ class HCaptcha extends React.Component {
344
313
  try {
345
314
  const hcaptcha = this._hcaptcha;
346
315
  const captchaId = this.captchaId;
347
-
316
+
348
317
  if (!this.isReady()) {
349
318
  const onReady = new Promise((resolve, reject) => {
350
-
319
+
351
320
  this._onReady = (id) => {
352
321
  try {
353
322
  const hcaptcha = this._hcaptcha;
354
-
323
+
355
324
  if (opts && opts.async) {
356
325
  hcaptcha.execute(id, opts).then(resolve).catch(reject);
357
326
  } else {
@@ -362,13 +331,12 @@ class HCaptcha extends React.Component {
362
331
  }
363
332
  };
364
333
  });
365
-
334
+
366
335
  return opts?.async ? onReady : null;
367
336
  }
368
-
337
+
369
338
  return hcaptcha.execute(captchaId, opts);
370
339
  } catch (error) {
371
- this.sentryHub.captureException(error);
372
340
  if (opts && opts.async) {
373
341
  return Promise.reject(error);
374
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
- };
@@ -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
- }