@reachfive/identity-ui 1.14.0 → 1.15.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/es/identity-ui.js CHANGED
@@ -9334,6 +9334,97 @@ function identifierField(props, config) {
9334
9334
  }));
9335
9335
  }
9336
9336
 
9337
+ var ReCaptcha = function ReCaptcha() {
9338
+ _classCallCheck(this, ReCaptcha);
9339
+ };
9340
+
9341
+ _defineProperty(ReCaptcha, "getRecaptchaToken", /*#__PURE__*/function () {
9342
+ var _ref = _asyncToGenerator( /*#__PURE__*/regeneratorRuntime.mark(function _callee(siteKey, action) {
9343
+ return regeneratorRuntime.wrap(function _callee$(_context) {
9344
+ while (1) {
9345
+ switch (_context.prev = _context.next) {
9346
+ case 0:
9347
+ _context.next = 2;
9348
+ return window.grecaptcha.execute(siteKey, {
9349
+ action: action
9350
+ });
9351
+
9352
+ case 2:
9353
+ return _context.abrupt("return", _context.sent);
9354
+
9355
+ case 3:
9356
+ case "end":
9357
+ return _context.stop();
9358
+ }
9359
+ }
9360
+ }, _callee);
9361
+ }));
9362
+
9363
+ return function (_x, _x2) {
9364
+ return _ref.apply(this, arguments);
9365
+ };
9366
+ }());
9367
+
9368
+ _defineProperty(ReCaptcha, "handle", /*#__PURE__*/function () {
9369
+ var _ref2 = _asyncToGenerator( /*#__PURE__*/regeneratorRuntime.mark(function _callee2(data, conf, callback, action) {
9370
+ var captchaToken;
9371
+ return regeneratorRuntime.wrap(function _callee2$(_context2) {
9372
+ while (1) {
9373
+ switch (_context2.prev = _context2.next) {
9374
+ case 0:
9375
+ if (!conf.recaptcha_enabled) {
9376
+ _context2.next = 13;
9377
+ break;
9378
+ }
9379
+
9380
+ _context2.prev = 1;
9381
+ _context2.next = 4;
9382
+ return ReCaptcha.getRecaptchaToken(conf.recaptcha_site_key, action);
9383
+
9384
+ case 4:
9385
+ captchaToken = _context2.sent;
9386
+ return _context2.abrupt("return", callback(_objectSpread2(_objectSpread2({}, data), {}, {
9387
+ captchaToken: captchaToken
9388
+ })));
9389
+
9390
+ case 8:
9391
+ _context2.prev = 8;
9392
+ _context2.t0 = _context2["catch"](1);
9393
+ return _context2.abrupt("return", Promise.reject({
9394
+ errorUserMsg: "Error recaptcha",
9395
+ errorMessageKey: "recaptcha.error"
9396
+ }));
9397
+
9398
+ case 11:
9399
+ _context2.next = 14;
9400
+ break;
9401
+
9402
+ case 13:
9403
+ return _context2.abrupt("return", callback(data));
9404
+
9405
+ case 14:
9406
+ case "end":
9407
+ return _context2.stop();
9408
+ }
9409
+ }
9410
+ }, _callee2, null, [[1, 8]]);
9411
+ }));
9412
+
9413
+ return function (_x3, _x4, _x5, _x6) {
9414
+ return _ref2.apply(this, arguments);
9415
+ };
9416
+ }());
9417
+ function importGoogleRecaptchaScript(site_key) {
9418
+ var script = document.createElement("script");
9419
+ script.src = "https://www.google.com/recaptcha/api.js?render=" + site_key;
9420
+ document.body.appendChild(script);
9421
+ }
9422
+ function extractCaptchaTokenFromData(data) {
9423
+ var token = data.captchaToken;
9424
+ delete data.captchaToken;
9425
+ return token;
9426
+ }
9427
+
9337
9428
  function _templateObject$7() {
9338
9429
  var data = _taggedTemplateLiteral(["\n margin-bottom: ", "px;\n text-align: right;\n ", ";\n"]);
9339
9430
 
@@ -9405,9 +9496,10 @@ var LoginView = /*#__PURE__*/function (_React$Component) {
9405
9496
 
9406
9497
  _this = _super.call.apply(_super, [this].concat(args));
9407
9498
 
9408
- _defineProperty(_assertThisInitialized(_this), "handleLogin", function (data) {
9499
+ _defineProperty(_assertThisInitialized(_this), "callback", function (data) {
9409
9500
  var specializedData = specializeIdentifierData(data);
9410
9501
  return _this.props.apiClient.loginWithPassword(_objectSpread2(_objectSpread2({}, specializedData), {}, {
9502
+ captchaToken: data.captchaToken,
9411
9503
  auth: _objectSpread2(_objectSpread2({}, specializedData.auth), _this.props.auth)
9412
9504
  }));
9413
9505
  });
@@ -9416,8 +9508,15 @@ var LoginView = /*#__PURE__*/function (_React$Component) {
9416
9508
  }
9417
9509
 
9418
9510
  _createClass(LoginView, [{
9511
+ key: "componentDidMount",
9512
+ value: function componentDidMount() {
9513
+ importGoogleRecaptchaScript(this.props.recaptcha_site_key);
9514
+ }
9515
+ }, {
9419
9516
  key: "render",
9420
9517
  value: function render() {
9518
+ var _this2 = this;
9519
+
9421
9520
  var _this$props = this.props,
9422
9521
  socialProviders = _this$props.socialProviders,
9423
9522
  _this$props$session = _this$props.session,
@@ -9436,7 +9535,9 @@ var LoginView = /*#__PURE__*/function (_React$Component) {
9436
9535
  showForgotPassword: this.props.allowForgotPassword,
9437
9536
  canShowPassword: this.props.canShowPassword,
9438
9537
  defaultIdentifier: defaultIdentifier,
9439
- handler: this.handleLogin,
9538
+ handler: function handler(data) {
9539
+ return ReCaptcha.handle(data, _this2.props, _this2.callback, "login");
9540
+ },
9440
9541
  config: this.props.config
9441
9542
  }), this.props.allowSignup && /*#__PURE__*/React__default.createElement(Alternative, null, /*#__PURE__*/React__default.createElement("span", null, i18n('login.signupLinkPrefix')), "\xA0", /*#__PURE__*/React__default.createElement(Link, {
9442
9543
  target: "signup"
@@ -9782,9 +9883,10 @@ var LoginView$1 = /*#__PURE__*/function (_React$Component) {
9782
9883
 
9783
9884
  _this = _super.call.apply(_super, [this].concat(args));
9784
9885
 
9785
- _defineProperty(_assertThisInitialized(_this), "handleLogin", function (data) {
9886
+ _defineProperty(_assertThisInitialized(_this), "callback", function (data) {
9786
9887
  var specializedData = specializeIdentifierData(data);
9787
9888
  return _this.props.apiClient.loginWithPassword(_objectSpread2(_objectSpread2({}, specializedData), {}, {
9889
+ captchaToken: data.captchaToken,
9788
9890
  auth: _objectSpread2(_objectSpread2({}, specializedData.auth), _this.props.auth)
9789
9891
  }));
9790
9892
  });
@@ -9793,8 +9895,15 @@ var LoginView$1 = /*#__PURE__*/function (_React$Component) {
9793
9895
  }
9794
9896
 
9795
9897
  _createClass(LoginView, [{
9898
+ key: "componentDidMount",
9899
+ value: function componentDidMount() {
9900
+ importGoogleRecaptchaScript(this.props.recaptcha_site_key);
9901
+ }
9902
+ }, {
9796
9903
  key: "render",
9797
9904
  value: function render() {
9905
+ var _this2 = this;
9906
+
9798
9907
  var i18n = this.props.i18n;
9799
9908
  return /*#__PURE__*/React__default.createElement("div", null, /*#__PURE__*/React__default.createElement(Heading, null, i18n('login.title')), /*#__PURE__*/React__default.createElement(LoginWithPasswordForm, {
9800
9909
  username: this.props.username,
@@ -9802,7 +9911,9 @@ var LoginView$1 = /*#__PURE__*/function (_React$Component) {
9802
9911
  showRememberMe: this.props.showRememberMe,
9803
9912
  showForgotPassword: this.props.allowForgotPassword,
9804
9913
  canShowPassword: this.props.canShowPassword,
9805
- handler: this.handleLogin,
9914
+ handler: function handler(data) {
9915
+ return ReCaptcha.handle(data, _this2.props, _this2.callback, "login");
9916
+ },
9806
9917
  config: this.props.config
9807
9918
  }), /*#__PURE__*/React__default.createElement(Alternative, null, /*#__PURE__*/React__default.createElement(Link, {
9808
9919
  target: "login-with-web-authn"
@@ -11299,8 +11410,10 @@ var PasswordSignupForm = /*#__PURE__*/function (_React$Component) {
11299
11410
  blacklist: []
11300
11411
  });
11301
11412
 
11302
- _defineProperty(_assertThisInitialized(_this), "handleSignup", function (data) {
11413
+ _defineProperty(_assertThisInitialized(_this), "callback", function (data) {
11414
+ var captchaToken = extractCaptchaTokenFromData(data);
11303
11415
  return _this.props.apiClient.signup({
11416
+ captchaToken: captchaToken,
11304
11417
  data: snakeCaseProperties(data),
11305
11418
  auth: _this.props.auth,
11306
11419
  redirectUrl: _this.props && _this.props.redirectUrl,
@@ -11330,8 +11443,15 @@ var PasswordSignupForm = /*#__PURE__*/function (_React$Component) {
11330
11443
  }
11331
11444
 
11332
11445
  _createClass(PasswordSignupForm, [{
11446
+ key: "componentDidMount",
11447
+ value: function componentDidMount() {
11448
+ importGoogleRecaptchaScript(this.props.recaptcha_site_key);
11449
+ }
11450
+ }, {
11333
11451
  key: "render",
11334
11452
  value: function render() {
11453
+ var _this2 = this;
11454
+
11335
11455
  var _this$props = this.props,
11336
11456
  _this$props$beforeSig = _this$props.beforeSignup,
11337
11457
  beforeSignup = _this$props$beforeSig === void 0 ? function (x) {
@@ -11362,7 +11482,9 @@ var PasswordSignupForm = /*#__PURE__*/function (_React$Component) {
11362
11482
  beforeSubmit: beforeSignup,
11363
11483
  onFieldChange: this.refreshBlacklist,
11364
11484
  sharedProps: sharedProps,
11365
- handler: this.handleSignup
11485
+ handler: function handler(data) {
11486
+ return ReCaptcha.handle(data, _this2.props, _this2.callback, "signup");
11487
+ }
11366
11488
  });
11367
11489
  }
11368
11490
  }]);
@@ -11520,10 +11642,29 @@ var skipError = function skipError(err) {
11520
11642
  };
11521
11643
 
11522
11644
  var enhance = withHandlers({
11523
- handleSubmit: function handleSubmit(_ref) {
11645
+ callback: function callback(_ref) {
11524
11646
  var apiClient = _ref.apiClient,
11525
11647
  redirectUrl = _ref.redirectUrl,
11526
- returnToAfterPasswordReset = _ref.returnToAfterPasswordReset;
11648
+ returnToAfterPasswordReset = _ref.returnToAfterPasswordReset,
11649
+ recaptcha_enabled = _ref.recaptcha_enabled,
11650
+ recaptcha_site_key = _ref.recaptcha_site_key;
11651
+ return function (data) {
11652
+ return ReCaptcha.handle(_objectSpread2(_objectSpread2({}, data), {}, {
11653
+ redirectUrl: redirectUrl,
11654
+ returnToAfterPasswordReset: returnToAfterPasswordReset
11655
+ }), {
11656
+ apiClient: apiClient,
11657
+ redirectUrl: redirectUrl,
11658
+ returnToAfterPasswordReset: returnToAfterPasswordReset,
11659
+ recaptcha_enabled: recaptcha_enabled,
11660
+ recaptcha_site_key: recaptcha_site_key
11661
+ }, apiClient.requestPasswordReset, "forgot_password");
11662
+ };
11663
+ },
11664
+ handleSubmit: function handleSubmit(_ref2) {
11665
+ var apiClient = _ref2.apiClient,
11666
+ redirectUrl = _ref2.redirectUrl,
11667
+ returnToAfterPasswordReset = _ref2.returnToAfterPasswordReset;
11527
11668
  return function (data) {
11528
11669
  return apiClient.requestPasswordReset(_objectSpread2(_objectSpread2({}, data), {}, {
11529
11670
  redirectUrl: redirectUrl,
@@ -11532,17 +11673,18 @@ var enhance = withHandlers({
11532
11673
  };
11533
11674
  }
11534
11675
  });
11535
- var ForgotPasswordView = enhance(function (_ref2) {
11536
- var i18n = _ref2.i18n,
11537
- goTo = _ref2.goTo,
11538
- allowLogin = _ref2.allowLogin,
11539
- handleSubmit = _ref2.handleSubmit,
11540
- displaySafeErrorMessage = _ref2.displaySafeErrorMessage,
11541
- showLabels = _ref2.showLabels,
11542
- allowWebAuthnLogin = _ref2.allowWebAuthnLogin;
11543
- return /*#__PURE__*/React__default.createElement("div", null, /*#__PURE__*/React__default.createElement(Heading, null, i18n('forgotPassword.title')), /*#__PURE__*/React__default.createElement(Intro, null, i18n('forgotPassword.prompt')), /*#__PURE__*/React__default.createElement(ForgotPasswordForm, {
11676
+ var ForgotPasswordView = enhance(function (_ref3) {
11677
+ var i18n = _ref3.i18n,
11678
+ goTo = _ref3.goTo,
11679
+ allowLogin = _ref3.allowLogin,
11680
+ callback = _ref3.callback,
11681
+ displaySafeErrorMessage = _ref3.displaySafeErrorMessage,
11682
+ showLabels = _ref3.showLabels,
11683
+ allowWebAuthnLogin = _ref3.allowWebAuthnLogin,
11684
+ recaptcha_site_key = _ref3.recaptcha_site_key;
11685
+ return /*#__PURE__*/React__default.createElement("div", null, importGoogleRecaptchaScript(recaptcha_site_key), /*#__PURE__*/React__default.createElement(Heading, null, i18n('forgotPassword.title')), /*#__PURE__*/React__default.createElement(Intro, null, i18n('forgotPassword.prompt')), /*#__PURE__*/React__default.createElement(ForgotPasswordForm, {
11544
11686
  showLabels: showLabels,
11545
- handler: handleSubmit,
11687
+ handler: callback,
11546
11688
  onSuccess: function onSuccess() {
11547
11689
  return goTo('forgot-password-success');
11548
11690
  },
@@ -11551,10 +11693,10 @@ var ForgotPasswordView = enhance(function (_ref2) {
11551
11693
  target: allowWebAuthnLogin ? 'login-with-web-authn' : 'login'
11552
11694
  }, i18n('forgotPassword.backToLoginLink'))));
11553
11695
  });
11554
- var ForgotPasswordSuccessView = function ForgotPasswordSuccessView(_ref3) {
11555
- var i18n = _ref3.i18n,
11556
- allowLogin = _ref3.allowLogin,
11557
- allowWebAuthnLogin = _ref3.allowWebAuthnLogin;
11696
+ var ForgotPasswordSuccessView = function ForgotPasswordSuccessView(_ref4) {
11697
+ var i18n = _ref4.i18n,
11698
+ allowLogin = _ref4.allowLogin,
11699
+ allowWebAuthnLogin = _ref4.allowWebAuthnLogin;
11558
11700
  return /*#__PURE__*/React__default.createElement("div", null, /*#__PURE__*/React__default.createElement(Heading, null, i18n('forgotPassword.title')), /*#__PURE__*/React__default.createElement(Info, null, i18n('forgotPassword.successMessage')), allowLogin && /*#__PURE__*/React__default.createElement(Alternative, null, /*#__PURE__*/React__default.createElement(Link, {
11559
11701
  target: allowWebAuthnLogin ? 'login-with-web-authn' : 'login'
11560
11702
  }, i18n('back'))));
@@ -12370,7 +12512,7 @@ var MainView$3 = /*#__PURE__*/function (_React$Component) {
12370
12512
 
12371
12513
  _this = _super.call.apply(_super, [this].concat(args));
12372
12514
 
12373
- _defineProperty(_assertThisInitialized(_this), "handleSubmit", function (data) {
12515
+ _defineProperty(_assertThisInitialized(_this), "callback", function (data) {
12374
12516
  return _this.props.apiClient.startPasswordless(data, _this.props.auth).then(function (_) {
12375
12517
  return data;
12376
12518
  });
@@ -12384,8 +12526,15 @@ var MainView$3 = /*#__PURE__*/function (_React$Component) {
12384
12526
  }
12385
12527
 
12386
12528
  _createClass(MainView, [{
12529
+ key: "componentDidMount",
12530
+ value: function componentDidMount() {
12531
+ importGoogleRecaptchaScript(this.props.recaptcha_site_key);
12532
+ }
12533
+ }, {
12387
12534
  key: "render",
12388
12535
  value: function render() {
12536
+ var _this2 = this;
12537
+
12389
12538
  var _this$props = this.props,
12390
12539
  i18n = _this$props.i18n,
12391
12540
  showSocialLogins = _this$props.showSocialLogins,
@@ -12400,10 +12549,14 @@ var MainView$3 = /*#__PURE__*/function (_React$Component) {
12400
12549
  }), showSocialLogins && socialProviders && socialProviders.length > 0 && /*#__PURE__*/React__default.createElement(Separator, {
12401
12550
  text: i18n('or')
12402
12551
  }), isEmail && showIntro && /*#__PURE__*/React__default.createElement(Intro, null, i18n('passwordless.intro')), isEmail && /*#__PURE__*/React__default.createElement(EmailInputForm, {
12403
- handler: this.handleSubmit,
12552
+ handler: function handler(data) {
12553
+ return ReCaptcha.handle(data, _this2.props, _this2.callback, "passwordless_email");
12554
+ },
12404
12555
  onSuccess: this.handleSuccess
12405
12556
  }), !isEmail && showIntro && /*#__PURE__*/React__default.createElement(Intro, null, i18n('passwordless.sms.intro')), !isEmail && /*#__PURE__*/React__default.createElement(PhoneNumberInputForm, {
12406
- handler: this.handleSubmit,
12557
+ handler: function handler(data) {
12558
+ return ReCaptcha.handle(data, _this2.props, _this2.callback, "passwordless_phone");
12559
+ },
12407
12560
  onSuccess: this.handleSuccess
12408
12561
  }));
12409
12562
  }
@@ -12418,7 +12571,7 @@ var VerificationCodeView$1 = /*#__PURE__*/function (_React$Component2) {
12418
12571
  var _super2 = _createSuper(VerificationCodeView);
12419
12572
 
12420
12573
  function VerificationCodeView() {
12421
- var _this2;
12574
+ var _this3;
12422
12575
 
12423
12576
  _classCallCheck(this, VerificationCodeView);
12424
12577
 
@@ -12426,26 +12579,30 @@ var VerificationCodeView$1 = /*#__PURE__*/function (_React$Component2) {
12426
12579
  args[_key2] = arguments[_key2];
12427
12580
  }
12428
12581
 
12429
- _this2 = _super2.call.apply(_super2, [this].concat(args));
12582
+ _this3 = _super2.call.apply(_super2, [this].concat(args));
12430
12583
 
12431
- _defineProperty(_assertThisInitialized(_this2), "handleSubmit", function (data) {
12432
- var _this2$props = _this2.props,
12433
- apiClient = _this2$props.apiClient,
12434
- auth = _this2$props.auth,
12435
- phoneNumber = _this2$props.phoneNumber;
12584
+ _defineProperty(_assertThisInitialized(_this3), "handleSubmit", function (data) {
12585
+ var _this3$props = _this3.props,
12586
+ apiClient = _this3$props.apiClient,
12587
+ auth = _this3$props.auth,
12588
+ phoneNumber = _this3$props.phoneNumber;
12436
12589
  return apiClient.verifyPasswordless(_objectSpread2({
12437
12590
  phoneNumber: phoneNumber
12438
12591
  }, data), auth);
12439
12592
  });
12440
12593
 
12441
- return _this2;
12594
+ return _this3;
12442
12595
  }
12443
12596
 
12444
12597
  _createClass(VerificationCodeView, [{
12445
12598
  key: "render",
12446
12599
  value: function render() {
12600
+ var _this4 = this;
12601
+
12447
12602
  return /*#__PURE__*/React__default.createElement("div", null, /*#__PURE__*/React__default.createElement(Info, null, this.props.i18n('passwordless.sms.verification.intro')), /*#__PURE__*/React__default.createElement(VerificationCodeInputForm$1, {
12448
- handler: this.handleSubmit
12603
+ handler: function handler(data) {
12604
+ return ReCaptcha.handle(data, _this4.props, _this4.callback, "verify_passwordless_sms");
12605
+ }
12449
12606
  }));
12450
12607
  }
12451
12608
  }]);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@reachfive/identity-ui",
3
- "version": "1.14.0",
3
+ "version": "1.15.0",
4
4
  "description": "ReachFive Identity Web UI SDK",
5
5
  "author": "ReachFive",
6
6
  "repository": {
@@ -19,7 +19,7 @@
19
19
  },
20
20
  "dependencies": {
21
21
  "@hypnosphi/recompose": "0.30.5",
22
- "@reachfive/identity-core": "1.21.0",
22
+ "@reachfive/identity-core": "1.22.0",
23
23
  "@reachfive/zxcvbn": "1.0.0-alpha.2",
24
24
  "char-info": "0.3.2",
25
25
  "classnames": "2.2.6",