@reachfive/identity-ui 1.14.0 → 1.16.1

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
@@ -4070,11 +4070,12 @@ function multiViewWidget(_ref3) {
4070
4070
 
4071
4071
  /* Returns whether a form value has been set with a valid value.
4072
4072
  * If the user's input has been enriched as an object, raw input is expected
4073
- * to be in a `raw` field.
4073
+ * to be in a raw property field (named 'raw' by default).
4074
4074
  */
4075
4075
 
4076
4076
  function isValued(v) {
4077
- var unwrap = isObject(v) ? v.raw : v;
4077
+ var rawProperty = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 'raw';
4078
+ var unwrap = isObject(v) ? v[rawProperty] : v;
4078
4079
  return unwrap !== null && unwrap !== undefined && unwrap !== '' && !Number.isNaN(unwrap) && (Array.isArray(unwrap) ? unwrap.length > 0 : true);
4079
4080
  }
4080
4081
  function formatISO8601Date(year, month, day) {
@@ -8821,6 +8822,8 @@ var createField = function createField(_ref) {
8821
8822
  return !isEmpty(x) ? x : null;
8822
8823
  }
8823
8824
  } : _ref$format,
8825
+ _ref$rawProperty = _ref.rawProperty,
8826
+ rawProperty = _ref$rawProperty === void 0 ? 'raw' : _ref$rawProperty,
8824
8827
  component = _ref.component,
8825
8828
  _ref$extendedParams = _ref.extendedParams,
8826
8829
  extendedParams = _ref$extendedParams === void 0 ? {} : _ref$extendedParams;
@@ -8854,7 +8857,7 @@ var createField = function createField(_ref) {
8854
8857
  },
8855
8858
  initialize: function initialize(model) {
8856
8859
  var modelValue = mapping.bind(model);
8857
- var initValue = isValued(modelValue) ? modelValue : defaultValue;
8860
+ var initValue = isValued(modelValue, rawProperty) ? modelValue : defaultValue;
8858
8861
  return {
8859
8862
  value: format.bind(initValue),
8860
8863
  isDirty: false
@@ -9334,6 +9337,97 @@ function identifierField(props, config) {
9334
9337
  }));
9335
9338
  }
9336
9339
 
9340
+ var ReCaptcha = function ReCaptcha() {
9341
+ _classCallCheck(this, ReCaptcha);
9342
+ };
9343
+
9344
+ _defineProperty(ReCaptcha, "getRecaptchaToken", /*#__PURE__*/function () {
9345
+ var _ref = _asyncToGenerator( /*#__PURE__*/regeneratorRuntime.mark(function _callee(siteKey, action) {
9346
+ return regeneratorRuntime.wrap(function _callee$(_context) {
9347
+ while (1) {
9348
+ switch (_context.prev = _context.next) {
9349
+ case 0:
9350
+ _context.next = 2;
9351
+ return window.grecaptcha.execute(siteKey, {
9352
+ action: action
9353
+ });
9354
+
9355
+ case 2:
9356
+ return _context.abrupt("return", _context.sent);
9357
+
9358
+ case 3:
9359
+ case "end":
9360
+ return _context.stop();
9361
+ }
9362
+ }
9363
+ }, _callee);
9364
+ }));
9365
+
9366
+ return function (_x, _x2) {
9367
+ return _ref.apply(this, arguments);
9368
+ };
9369
+ }());
9370
+
9371
+ _defineProperty(ReCaptcha, "handle", /*#__PURE__*/function () {
9372
+ var _ref2 = _asyncToGenerator( /*#__PURE__*/regeneratorRuntime.mark(function _callee2(data, conf, callback, action) {
9373
+ var captchaToken;
9374
+ return regeneratorRuntime.wrap(function _callee2$(_context2) {
9375
+ while (1) {
9376
+ switch (_context2.prev = _context2.next) {
9377
+ case 0:
9378
+ if (!conf.recaptcha_enabled) {
9379
+ _context2.next = 13;
9380
+ break;
9381
+ }
9382
+
9383
+ _context2.prev = 1;
9384
+ _context2.next = 4;
9385
+ return ReCaptcha.getRecaptchaToken(conf.recaptcha_site_key, action);
9386
+
9387
+ case 4:
9388
+ captchaToken = _context2.sent;
9389
+ return _context2.abrupt("return", callback(_objectSpread2(_objectSpread2({}, data), {}, {
9390
+ captchaToken: captchaToken
9391
+ })));
9392
+
9393
+ case 8:
9394
+ _context2.prev = 8;
9395
+ _context2.t0 = _context2["catch"](1);
9396
+ return _context2.abrupt("return", Promise.reject({
9397
+ errorUserMsg: "Error recaptcha",
9398
+ errorMessageKey: "recaptcha.error"
9399
+ }));
9400
+
9401
+ case 11:
9402
+ _context2.next = 14;
9403
+ break;
9404
+
9405
+ case 13:
9406
+ return _context2.abrupt("return", callback(data));
9407
+
9408
+ case 14:
9409
+ case "end":
9410
+ return _context2.stop();
9411
+ }
9412
+ }
9413
+ }, _callee2, null, [[1, 8]]);
9414
+ }));
9415
+
9416
+ return function (_x3, _x4, _x5, _x6) {
9417
+ return _ref2.apply(this, arguments);
9418
+ };
9419
+ }());
9420
+ function importGoogleRecaptchaScript(site_key) {
9421
+ var script = document.createElement("script");
9422
+ script.src = "https://www.google.com/recaptcha/api.js?render=" + site_key;
9423
+ document.body.appendChild(script);
9424
+ }
9425
+ function extractCaptchaTokenFromData(data) {
9426
+ var token = data.captchaToken;
9427
+ delete data.captchaToken;
9428
+ return token;
9429
+ }
9430
+
9337
9431
  function _templateObject$7() {
9338
9432
  var data = _taggedTemplateLiteral(["\n margin-bottom: ", "px;\n text-align: right;\n ", ";\n"]);
9339
9433
 
@@ -9405,9 +9499,10 @@ var LoginView = /*#__PURE__*/function (_React$Component) {
9405
9499
 
9406
9500
  _this = _super.call.apply(_super, [this].concat(args));
9407
9501
 
9408
- _defineProperty(_assertThisInitialized(_this), "handleLogin", function (data) {
9502
+ _defineProperty(_assertThisInitialized(_this), "callback", function (data) {
9409
9503
  var specializedData = specializeIdentifierData(data);
9410
9504
  return _this.props.apiClient.loginWithPassword(_objectSpread2(_objectSpread2({}, specializedData), {}, {
9505
+ captchaToken: data.captchaToken,
9411
9506
  auth: _objectSpread2(_objectSpread2({}, specializedData.auth), _this.props.auth)
9412
9507
  }));
9413
9508
  });
@@ -9416,8 +9511,15 @@ var LoginView = /*#__PURE__*/function (_React$Component) {
9416
9511
  }
9417
9512
 
9418
9513
  _createClass(LoginView, [{
9514
+ key: "componentDidMount",
9515
+ value: function componentDidMount() {
9516
+ importGoogleRecaptchaScript(this.props.recaptcha_site_key);
9517
+ }
9518
+ }, {
9419
9519
  key: "render",
9420
9520
  value: function render() {
9521
+ var _this2 = this;
9522
+
9421
9523
  var _this$props = this.props,
9422
9524
  socialProviders = _this$props.socialProviders,
9423
9525
  _this$props$session = _this$props.session,
@@ -9436,7 +9538,9 @@ var LoginView = /*#__PURE__*/function (_React$Component) {
9436
9538
  showForgotPassword: this.props.allowForgotPassword,
9437
9539
  canShowPassword: this.props.canShowPassword,
9438
9540
  defaultIdentifier: defaultIdentifier,
9439
- handler: this.handleLogin,
9541
+ handler: function handler(data) {
9542
+ return ReCaptcha.handle(data, _this2.props, _this2.callback, "login");
9543
+ },
9440
9544
  config: this.props.config
9441
9545
  }), 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
9546
  target: "signup"
@@ -9782,9 +9886,10 @@ var LoginView$1 = /*#__PURE__*/function (_React$Component) {
9782
9886
 
9783
9887
  _this = _super.call.apply(_super, [this].concat(args));
9784
9888
 
9785
- _defineProperty(_assertThisInitialized(_this), "handleLogin", function (data) {
9889
+ _defineProperty(_assertThisInitialized(_this), "callback", function (data) {
9786
9890
  var specializedData = specializeIdentifierData(data);
9787
9891
  return _this.props.apiClient.loginWithPassword(_objectSpread2(_objectSpread2({}, specializedData), {}, {
9892
+ captchaToken: data.captchaToken,
9788
9893
  auth: _objectSpread2(_objectSpread2({}, specializedData.auth), _this.props.auth)
9789
9894
  }));
9790
9895
  });
@@ -9793,8 +9898,15 @@ var LoginView$1 = /*#__PURE__*/function (_React$Component) {
9793
9898
  }
9794
9899
 
9795
9900
  _createClass(LoginView, [{
9901
+ key: "componentDidMount",
9902
+ value: function componentDidMount() {
9903
+ importGoogleRecaptchaScript(this.props.recaptcha_site_key);
9904
+ }
9905
+ }, {
9796
9906
  key: "render",
9797
9907
  value: function render() {
9908
+ var _this2 = this;
9909
+
9798
9910
  var i18n = this.props.i18n;
9799
9911
  return /*#__PURE__*/React__default.createElement("div", null, /*#__PURE__*/React__default.createElement(Heading, null, i18n('login.title')), /*#__PURE__*/React__default.createElement(LoginWithPasswordForm, {
9800
9912
  username: this.props.username,
@@ -9802,7 +9914,9 @@ var LoginView$1 = /*#__PURE__*/function (_React$Component) {
9802
9914
  showRememberMe: this.props.showRememberMe,
9803
9915
  showForgotPassword: this.props.allowForgotPassword,
9804
9916
  canShowPassword: this.props.canShowPassword,
9805
- handler: this.handleLogin,
9917
+ handler: function handler(data) {
9918
+ return ReCaptcha.handle(data, _this2.props, _this2.callback, "login");
9919
+ },
9806
9920
  config: this.props.config
9807
9921
  }), /*#__PURE__*/React__default.createElement(Alternative, null, /*#__PURE__*/React__default.createElement(Link, {
9808
9922
  target: "login-with-web-authn"
@@ -11012,6 +11126,7 @@ function consentField(config) {
11012
11126
  }
11013
11127
  },
11014
11128
  validator: config.required ? checked : empty,
11129
+ rawProperty: 'granted',
11015
11130
  component: ConsentField
11016
11131
  }));
11017
11132
  }
@@ -11299,8 +11414,10 @@ var PasswordSignupForm = /*#__PURE__*/function (_React$Component) {
11299
11414
  blacklist: []
11300
11415
  });
11301
11416
 
11302
- _defineProperty(_assertThisInitialized(_this), "handleSignup", function (data) {
11417
+ _defineProperty(_assertThisInitialized(_this), "callback", function (data) {
11418
+ var captchaToken = extractCaptchaTokenFromData(data);
11303
11419
  return _this.props.apiClient.signup({
11420
+ captchaToken: captchaToken,
11304
11421
  data: snakeCaseProperties(data),
11305
11422
  auth: _this.props.auth,
11306
11423
  redirectUrl: _this.props && _this.props.redirectUrl,
@@ -11330,8 +11447,15 @@ var PasswordSignupForm = /*#__PURE__*/function (_React$Component) {
11330
11447
  }
11331
11448
 
11332
11449
  _createClass(PasswordSignupForm, [{
11450
+ key: "componentDidMount",
11451
+ value: function componentDidMount() {
11452
+ importGoogleRecaptchaScript(this.props.recaptcha_site_key);
11453
+ }
11454
+ }, {
11333
11455
  key: "render",
11334
11456
  value: function render() {
11457
+ var _this2 = this;
11458
+
11335
11459
  var _this$props = this.props,
11336
11460
  _this$props$beforeSig = _this$props.beforeSignup,
11337
11461
  beforeSignup = _this$props$beforeSig === void 0 ? function (x) {
@@ -11362,7 +11486,9 @@ var PasswordSignupForm = /*#__PURE__*/function (_React$Component) {
11362
11486
  beforeSubmit: beforeSignup,
11363
11487
  onFieldChange: this.refreshBlacklist,
11364
11488
  sharedProps: sharedProps,
11365
- handler: this.handleSignup
11489
+ handler: function handler(data) {
11490
+ return ReCaptcha.handle(data, _this2.props, _this2.callback, "signup");
11491
+ }
11366
11492
  });
11367
11493
  }
11368
11494
  }]);
@@ -11520,10 +11646,29 @@ var skipError = function skipError(err) {
11520
11646
  };
11521
11647
 
11522
11648
  var enhance = withHandlers({
11523
- handleSubmit: function handleSubmit(_ref) {
11649
+ callback: function callback(_ref) {
11524
11650
  var apiClient = _ref.apiClient,
11525
11651
  redirectUrl = _ref.redirectUrl,
11526
- returnToAfterPasswordReset = _ref.returnToAfterPasswordReset;
11652
+ returnToAfterPasswordReset = _ref.returnToAfterPasswordReset,
11653
+ recaptcha_enabled = _ref.recaptcha_enabled,
11654
+ recaptcha_site_key = _ref.recaptcha_site_key;
11655
+ return function (data) {
11656
+ return ReCaptcha.handle(_objectSpread2(_objectSpread2({}, data), {}, {
11657
+ redirectUrl: redirectUrl,
11658
+ returnToAfterPasswordReset: returnToAfterPasswordReset
11659
+ }), {
11660
+ apiClient: apiClient,
11661
+ redirectUrl: redirectUrl,
11662
+ returnToAfterPasswordReset: returnToAfterPasswordReset,
11663
+ recaptcha_enabled: recaptcha_enabled,
11664
+ recaptcha_site_key: recaptcha_site_key
11665
+ }, apiClient.requestPasswordReset, "forgot_password");
11666
+ };
11667
+ },
11668
+ handleSubmit: function handleSubmit(_ref2) {
11669
+ var apiClient = _ref2.apiClient,
11670
+ redirectUrl = _ref2.redirectUrl,
11671
+ returnToAfterPasswordReset = _ref2.returnToAfterPasswordReset;
11527
11672
  return function (data) {
11528
11673
  return apiClient.requestPasswordReset(_objectSpread2(_objectSpread2({}, data), {}, {
11529
11674
  redirectUrl: redirectUrl,
@@ -11532,17 +11677,18 @@ var enhance = withHandlers({
11532
11677
  };
11533
11678
  }
11534
11679
  });
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, {
11680
+ var ForgotPasswordView = enhance(function (_ref3) {
11681
+ var i18n = _ref3.i18n,
11682
+ goTo = _ref3.goTo,
11683
+ allowLogin = _ref3.allowLogin,
11684
+ callback = _ref3.callback,
11685
+ displaySafeErrorMessage = _ref3.displaySafeErrorMessage,
11686
+ showLabels = _ref3.showLabels,
11687
+ allowWebAuthnLogin = _ref3.allowWebAuthnLogin,
11688
+ recaptcha_site_key = _ref3.recaptcha_site_key;
11689
+ 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
11690
  showLabels: showLabels,
11545
- handler: handleSubmit,
11691
+ handler: callback,
11546
11692
  onSuccess: function onSuccess() {
11547
11693
  return goTo('forgot-password-success');
11548
11694
  },
@@ -11551,10 +11697,10 @@ var ForgotPasswordView = enhance(function (_ref2) {
11551
11697
  target: allowWebAuthnLogin ? 'login-with-web-authn' : 'login'
11552
11698
  }, i18n('forgotPassword.backToLoginLink'))));
11553
11699
  });
11554
- var ForgotPasswordSuccessView = function ForgotPasswordSuccessView(_ref3) {
11555
- var i18n = _ref3.i18n,
11556
- allowLogin = _ref3.allowLogin,
11557
- allowWebAuthnLogin = _ref3.allowWebAuthnLogin;
11700
+ var ForgotPasswordSuccessView = function ForgotPasswordSuccessView(_ref4) {
11701
+ var i18n = _ref4.i18n,
11702
+ allowLogin = _ref4.allowLogin,
11703
+ allowWebAuthnLogin = _ref4.allowWebAuthnLogin;
11558
11704
  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
11705
  target: allowWebAuthnLogin ? 'login-with-web-authn' : 'login'
11560
11706
  }, i18n('back'))));
@@ -12370,7 +12516,7 @@ var MainView$3 = /*#__PURE__*/function (_React$Component) {
12370
12516
 
12371
12517
  _this = _super.call.apply(_super, [this].concat(args));
12372
12518
 
12373
- _defineProperty(_assertThisInitialized(_this), "handleSubmit", function (data) {
12519
+ _defineProperty(_assertThisInitialized(_this), "callback", function (data) {
12374
12520
  return _this.props.apiClient.startPasswordless(data, _this.props.auth).then(function (_) {
12375
12521
  return data;
12376
12522
  });
@@ -12384,8 +12530,15 @@ var MainView$3 = /*#__PURE__*/function (_React$Component) {
12384
12530
  }
12385
12531
 
12386
12532
  _createClass(MainView, [{
12533
+ key: "componentDidMount",
12534
+ value: function componentDidMount() {
12535
+ importGoogleRecaptchaScript(this.props.recaptcha_site_key);
12536
+ }
12537
+ }, {
12387
12538
  key: "render",
12388
12539
  value: function render() {
12540
+ var _this2 = this;
12541
+
12389
12542
  var _this$props = this.props,
12390
12543
  i18n = _this$props.i18n,
12391
12544
  showSocialLogins = _this$props.showSocialLogins,
@@ -12400,10 +12553,14 @@ var MainView$3 = /*#__PURE__*/function (_React$Component) {
12400
12553
  }), showSocialLogins && socialProviders && socialProviders.length > 0 && /*#__PURE__*/React__default.createElement(Separator, {
12401
12554
  text: i18n('or')
12402
12555
  }), isEmail && showIntro && /*#__PURE__*/React__default.createElement(Intro, null, i18n('passwordless.intro')), isEmail && /*#__PURE__*/React__default.createElement(EmailInputForm, {
12403
- handler: this.handleSubmit,
12556
+ handler: function handler(data) {
12557
+ return ReCaptcha.handle(data, _this2.props, _this2.callback, "passwordless_email");
12558
+ },
12404
12559
  onSuccess: this.handleSuccess
12405
12560
  }), !isEmail && showIntro && /*#__PURE__*/React__default.createElement(Intro, null, i18n('passwordless.sms.intro')), !isEmail && /*#__PURE__*/React__default.createElement(PhoneNumberInputForm, {
12406
- handler: this.handleSubmit,
12561
+ handler: function handler(data) {
12562
+ return ReCaptcha.handle(data, _this2.props, _this2.callback, "passwordless_phone");
12563
+ },
12407
12564
  onSuccess: this.handleSuccess
12408
12565
  }));
12409
12566
  }
@@ -12418,7 +12575,7 @@ var VerificationCodeView$1 = /*#__PURE__*/function (_React$Component2) {
12418
12575
  var _super2 = _createSuper(VerificationCodeView);
12419
12576
 
12420
12577
  function VerificationCodeView() {
12421
- var _this2;
12578
+ var _this3;
12422
12579
 
12423
12580
  _classCallCheck(this, VerificationCodeView);
12424
12581
 
@@ -12426,26 +12583,30 @@ var VerificationCodeView$1 = /*#__PURE__*/function (_React$Component2) {
12426
12583
  args[_key2] = arguments[_key2];
12427
12584
  }
12428
12585
 
12429
- _this2 = _super2.call.apply(_super2, [this].concat(args));
12586
+ _this3 = _super2.call.apply(_super2, [this].concat(args));
12430
12587
 
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;
12588
+ _defineProperty(_assertThisInitialized(_this3), "handleSubmit", function (data) {
12589
+ var _this3$props = _this3.props,
12590
+ apiClient = _this3$props.apiClient,
12591
+ auth = _this3$props.auth,
12592
+ phoneNumber = _this3$props.phoneNumber;
12436
12593
  return apiClient.verifyPasswordless(_objectSpread2({
12437
12594
  phoneNumber: phoneNumber
12438
12595
  }, data), auth);
12439
12596
  });
12440
12597
 
12441
- return _this2;
12598
+ return _this3;
12442
12599
  }
12443
12600
 
12444
12601
  _createClass(VerificationCodeView, [{
12445
12602
  key: "render",
12446
12603
  value: function render() {
12604
+ var _this4 = this;
12605
+
12447
12606
  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
12607
+ handler: function handler(data) {
12608
+ return ReCaptcha.handle(data, _this4.props, _this4.handleSubmit, "verify_passwordless_sms");
12609
+ }
12449
12610
  }));
12450
12611
  }
12451
12612
  }]);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@reachfive/identity-ui",
3
- "version": "1.14.0",
3
+ "version": "1.16.1",
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.24.0",
23
23
  "@reachfive/zxcvbn": "1.0.0-alpha.2",
24
24
  "char-info": "0.3.2",
25
25
  "classnames": "2.2.6",