@alphapoint/apex-web 5.5.6 → 5.8.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.
Files changed (132) hide show
  1. package/lib/apex.integration.test.js +435 -0
  2. package/lib/apex.js +37 -1
  3. package/lib/apex.test.js +138 -0
  4. package/lib/components/2FA/PasskeyOption.js +126 -0
  5. package/lib/components/2FA/TwoFactorAuthComponent.js +24 -5
  6. package/lib/components/2FA/TwoFactorAuthComponent.test.js +94 -0
  7. package/lib/components/2FA/TwoFactorAuthContainer.js +139 -27
  8. package/lib/components/2FA/TwoFactorAuthContainer.test.js +627 -0
  9. package/lib/components/AccountsDropdown/AccountsDropdownComponent.css +6 -0
  10. package/lib/components/AccountsDropdown/AccountsDropdownComponent.js +6 -2
  11. package/lib/components/AccountsDropdown/AccountsDropdownComponent.test.js +43 -0
  12. package/lib/components/AccountsDropdown/AccountsDropdownContainer.js +3 -1
  13. package/lib/components/BalancesList/BalancesListContainer.js +4 -1
  14. package/lib/components/ConfirmBlockTradeModal/ConfirmBlockTradeModalContainer.js +34 -6
  15. package/lib/components/ConfirmBlockTradeModal/ConfirmBlockTradeModalContainer.test.js +298 -0
  16. package/lib/components/ConfirmOrderModal/ConfirmOrderModalComponent.js +26 -4
  17. package/lib/components/ConfirmOrderModal/ConfirmOrderModalContainer.js +4 -1
  18. package/lib/components/DigitalAssets/digitalAssetsPriceLabel.test.js +238 -0
  19. package/lib/components/EnableTwoFactorAuth/Disable2FAForm.js +22 -7
  20. package/lib/components/EnableTwoFactorAuth/Disable2FAModal.js +15 -5
  21. package/lib/components/EnableTwoFactorAuth/Disable2FAModal.test.js +460 -0
  22. package/lib/components/EnableTwoFactorAuth/Disable2FAModalContainer.js +108 -16
  23. package/lib/components/EnableTwoFactorAuth/EnableTwoFactorAuthComponent.js +7 -0
  24. package/lib/components/EnableTwoFactorAuth/EnableTwoFactorAuthComponent.test.js +105 -0
  25. package/lib/components/EnableTwoFactorAuth/EnableTwoFactorAuthContainerFactory.js +15 -3
  26. package/lib/components/FusionAuth/UnlinkOAuthIdentityModal.css +13 -0
  27. package/lib/components/FusionAuth/UnlinkOAuthIdentityModal.js +246 -0
  28. package/lib/components/FusionAuth/UnlinkOAuthIdentityModal.test.js +521 -0
  29. package/lib/components/InstrumentPositions/InstrumentPositionsContainer.js +4 -1
  30. package/lib/components/Login/LoginFormComponent.js +1 -1
  31. package/lib/components/MarginBalances/MarginDepositWithdraw/MarginDepositModal/MarginDepositFormContainer.js +2 -1
  32. package/lib/components/NoAccountBanner/NoAccountBanner.css +9 -0
  33. package/lib/components/NoAccountBanner/NoAccountBanner.js +58 -0
  34. package/lib/components/NoAccountBanner/index.js +16 -0
  35. package/lib/components/NoAccountPlaceholder/NoAccountPlaceholder.css +31 -0
  36. package/lib/components/NoAccountPlaceholder/NoAccountPlaceholder.js +33 -0
  37. package/lib/components/NoAccountPlaceholder/index.js +9 -0
  38. package/lib/components/OrderEntryComponents/advancedForm/AdvancedOrderFormContainer.js +2 -0
  39. package/lib/components/OrderEntryComponents/common/FormAmountFields.js +5 -0
  40. package/lib/components/OrderEntryComponents/common/TwapScheduleFields.js +98 -0
  41. package/lib/components/OrderEntryComponents/defaultForm/OrderEntryAnchoring.js +86 -39
  42. package/lib/components/OrderEntryComponents/defaultForm/OrderEntryAnchoring.test.js +326 -0
  43. package/lib/components/OrderEntryComponents/defaultForm/OrderEntryContainer.js +10 -2
  44. package/lib/components/OrderHistoryComponents/DepositsStatus/DepositsStatusComponent.js +1 -1
  45. package/lib/components/OrderHistoryComponents/DepositsStatus/DepositsStatusComponent.test.js +99 -0
  46. package/lib/components/OrderHistoryComponents/InactiveOrders/InactiveOrdersComponent.js +1 -1
  47. package/lib/components/OrderHistoryComponents/OpenOrders/OpenOrdersComponent.js +1 -1
  48. package/lib/components/OrderHistoryComponents/WithdrawStatus/WithdrawStatusComponent.js +1 -1
  49. package/lib/components/OrderHistoryComponents/WithdrawStatus/WithdrawStatusComponent.test.js +113 -0
  50. package/lib/components/Settings/ProfileAndSecurity/PasskeysSettingsCard/PasskeysSettingsCard.css +108 -0
  51. package/lib/components/Settings/ProfileAndSecurity/PasskeysSettingsCard/PasskeysSettingsCard.test.js +983 -0
  52. package/lib/components/Settings/ProfileAndSecurity/PasskeysSettingsCard/PasskeysSettingsCardComponent.js +500 -0
  53. package/lib/components/Settings/ProfileAndSecurity/PasskeysSettingsCard/index.js +9 -0
  54. package/lib/components/Settings/ProfileAndSecurity/ProfileSettingsCard/ProfileForm/SsoLinkRowComponent.css +4 -0
  55. package/lib/components/Settings/ProfileAndSecurity/ProfileSettingsCard/ProfileForm/SsoLinkRowComponent.js +29 -17
  56. package/lib/components/Settings/ProfileAndSecurity/ProfileSettingsCard/ProfileForm/SsoLinkRowComponent.test.js +135 -0
  57. package/lib/components/Settings/ProfileAndSecurity/TwoFactorAuthSettingsCard/EnableTwoFactorAuth/EnableTwoFactorAuthComponent.js +12 -4
  58. package/lib/components/Settings/ProfileAndSecurity/TwoFactorAuthSettingsCard/EnableTwoFactorAuth/EnableTwoFactorAuthComponent.test.js +268 -0
  59. package/lib/components/TwoFactorAuthForm/TwoFactorAuthForm.test.js +475 -0
  60. package/lib/components/TwoFactorAuthForm/TwoFactorAuthFormComponent.js +26 -5
  61. package/lib/components/TwoFactorAuthForm/TwoFactorAuthFormContainer.js +50 -32
  62. package/lib/components/common/APAutoTabInput/APAutoTabInput.js +5 -2
  63. package/lib/components/common/APSelect/APSelect.js +3 -1
  64. package/lib/components/common/ErrorBoundary/ErrorBoundary.css +35 -0
  65. package/lib/components/common/ErrorBoundary/ErrorBoundary.js +87 -0
  66. package/lib/config/CONFIG.md +4 -0
  67. package/lib/config/configDefault.json +2 -1
  68. package/lib/constants/sendOrder/orderEntryFormConstants.js +23 -4
  69. package/lib/constants/sendOrder/timeInForceConstants.js +3 -1
  70. package/lib/constants/sendOrder/twapRejectReasons.js +26 -0
  71. package/lib/helpers/errorTextFormatter.js +13 -4
  72. package/lib/helpers/errorTextFormatter.test.js +26 -0
  73. package/lib/helpers/orderHistoryHelper.js +13 -1
  74. package/lib/helpers/orderHistoryHelper.test.js +58 -13
  75. package/lib/helpers/passkeyApi.js +228 -0
  76. package/lib/helpers/passkeyApi.test.js +171 -0
  77. package/lib/helpers/placeOrderHelper.js +76 -61
  78. package/lib/helpers/placeOrderHelper.test.js +169 -10
  79. package/lib/helpers/recalculateOrderHelper.js +4 -1
  80. package/lib/helpers/recalculateOrderHelper.test.js +88 -2
  81. package/lib/helpers/twapOrderHelper.js +265 -0
  82. package/lib/helpers/twapOrderHelper.test.js +467 -0
  83. package/lib/helpers/twoFactorAuthCancellation.js +38 -0
  84. package/lib/helpers/webauthnHelper.js +300 -0
  85. package/lib/helpers/webauthnHelper.test.js +199 -0
  86. package/lib/hocs/forAccount.js +33 -0
  87. package/lib/hocs/forAccount.test.js +50 -0
  88. package/lib/hocs/forVerified.js +16 -2
  89. package/lib/hocs/withAuthentication.js +3 -1
  90. package/lib/hocs/withOneSubmission.js +168 -0
  91. package/lib/index.js +3 -2
  92. package/lib/layouts/HeaderLayout/HeaderLayout.js +2 -1
  93. package/lib/layouts/WalletsLayout/WalletsLayoutContainer.js +3 -1
  94. package/lib/layouts/WalletsLayout/WalletsLayoutContainer.test.js +84 -0
  95. package/lib/redux/actions/apiActions.js +77 -9
  96. package/lib/redux/actions/apiActions.test.js +233 -0
  97. package/lib/redux/actions/authActions.js +514 -198
  98. package/lib/redux/actions/authActions.test.js +627 -47
  99. package/lib/redux/actions/depositActions.js +1 -1
  100. package/lib/redux/actions/depositActions.test.js +100 -30
  101. package/lib/redux/actions/fusionAuthActions.test.js +265 -84
  102. package/lib/redux/actions/interestAccountActions.js +12 -3
  103. package/lib/redux/actions/interestAccountActions.test.js +73 -0
  104. package/lib/redux/actions/modalActions.js +1 -0
  105. package/lib/redux/actions/orderEntryActions.blockTrade.test.js +306 -0
  106. package/lib/redux/actions/orderEntryActions.js +74 -22
  107. package/lib/redux/actions/orderEntryActions.test.js +63 -11
  108. package/lib/redux/actions/orderHistoryActions.js +20 -8
  109. package/lib/redux/actions/orderHistoryActions.test.js +63 -0
  110. package/lib/redux/actions/userActions.js +379 -179
  111. package/lib/redux/actions/userActions.test.js +925 -234
  112. package/lib/redux/actions/withdrawActions.js +62 -29
  113. package/lib/redux/actions/withdrawActions.test.js +246 -73
  114. package/lib/redux/actions/withdrawActions.travelRule.test.js +17 -3
  115. package/lib/redux/margin/actions/marginActions.js +6 -3
  116. package/lib/redux/margin/actions/marginActions.test.js +166 -0
  117. package/lib/redux/middlewares/authMiddleware.js +5 -0
  118. package/lib/redux/middlewares/authMiddleware.test.js +88 -29
  119. package/lib/redux/reducers/authReducer.js +1 -0
  120. package/lib/redux/reducers/authReducer.test.js +38 -0
  121. package/lib/redux/reducers/userReducer.js +10 -0
  122. package/lib/redux/reducers/userReducer.test.js +29 -0
  123. package/lib/redux/selectors/orderEntrySelector.js +19 -8
  124. package/lib/redux/selectors/orderEntrySelector.test.js +209 -0
  125. package/lib/redux/selectors/orderTotalSelector.test.js +40 -1
  126. package/lib/redux/selectors/recentActivitySelector.js +8 -2
  127. package/lib/redux/selectors/recentActivitySelector.v2.test.js +33 -0
  128. package/lib/redux/selectors/userSelectors.js +6 -1
  129. package/lib/redux/selectors/userSelectors.test.js +28 -0
  130. package/lib/services/fms/fms.js +2 -0
  131. package/lib/services/fms/fms.test.js +35 -0
  132. package/package.json +4 -4
@@ -0,0 +1,105 @@
1
+ "use strict";
2
+
3
+ function _typeof(o) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (o) { return typeof o; } : function (o) { return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o; }, _typeof(o); }
4
+ var _react = _interopRequireWildcard(require("react"));
5
+ var _client = require("react-dom/client");
6
+ var _reactRedux = require("react-redux");
7
+ var _redux = require("redux");
8
+ var _reduxThunk = _interopRequireDefault(require("redux-thunk"));
9
+ var _reduxForm = require("redux-form");
10
+ var _EnableTwoFactorAuthContainerFactory = _interopRequireDefault(require("./EnableTwoFactorAuthContainerFactory"));
11
+ var _EnableTwoFactorAuthComponent = _interopRequireDefault(require("./EnableTwoFactorAuthComponent"));
12
+ function _interopRequireDefault(e) { return e && e.__esModule ? e : { "default": e }; }
13
+ function _interopRequireWildcard(e, t) { if ("function" == typeof WeakMap) var r = new WeakMap(), n = new WeakMap(); return (_interopRequireWildcard = function _interopRequireWildcard(e, t) { if (!t && e && e.__esModule) return e; var o, i, f = { __proto__: null, "default": e }; if (null === e || "object" != _typeof(e) && "function" != typeof e) return f; if (o = t ? n : r) { if (o.has(e)) return o.get(e); o.set(e, f); } for (var _t in e) "default" !== _t && {}.hasOwnProperty.call(e, _t) && ((i = (o = Object.defineProperty) && Object.getOwnPropertyDescriptor(e, _t)) && (i.get || i.set) ? o(f, _t, i) : f[_t] = e[_t]); return f; })(e, t); }
14
+ jest.mock('../../apex', function () {
15
+ return {
16
+ __esModule: true,
17
+ "default": {
18
+ connection: {
19
+ EnableGoogle2FA: jest.fn()
20
+ }
21
+ }
22
+ };
23
+ });
24
+ jest.mock('react-i18next', function () {
25
+ return {
26
+ useTranslation: function useTranslation() {
27
+ return {
28
+ t: function t(key) {
29
+ return key;
30
+ }
31
+ };
32
+ }
33
+ };
34
+ });
35
+
36
+ // the modals are not under test; they need the modal and QR code slices of a full store
37
+ jest.mock('./Enable2FAModalContainer', function () {
38
+ return function () {
39
+ return null;
40
+ };
41
+ });
42
+ jest.mock('./Disable2FAModalContainer', function () {
43
+ return function () {
44
+ return null;
45
+ };
46
+ });
47
+ global.IS_REACT_ACT_ENVIRONMENT = true;
48
+ var SSO_MESSAGE = 'Two-factor authentication for this account is managed by your single sign-on provider.';
49
+ var EnableTwoFactorAuthContainer = (0, _EnableTwoFactorAuthContainerFactory["default"])(_EnableTwoFactorAuthComponent["default"]);
50
+ var render = function render(userInfo) {
51
+ var store = (0, _redux.createStore)((0, _redux.combineReducers)({
52
+ form: _reduxForm.reducer,
53
+ user: function user() {
54
+ var state = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {
55
+ userInfo: userInfo,
56
+ userConfig: []
57
+ };
58
+ return state;
59
+ }
60
+ }), (0, _redux.applyMiddleware)(_reduxThunk["default"]));
61
+ var container = document.createElement('div');
62
+ document.body.appendChild(container);
63
+ (0, _react.act)(function () {
64
+ return (0, _client.createRoot)(container).render(/*#__PURE__*/_react["default"].createElement(_reactRedux.Provider, {
65
+ store: store
66
+ }, /*#__PURE__*/_react["default"].createElement(EnableTwoFactorAuthContainer, null)));
67
+ });
68
+ return {
69
+ toggle: function toggle() {
70
+ return container.querySelector('.ap-segmented-button__sb-container');
71
+ },
72
+ text: function text() {
73
+ return container.textContent;
74
+ }
75
+ };
76
+ };
77
+ describe('legacy user settings two-factor section', function () {
78
+ afterEach(function () {
79
+ document.body.innerHTML = '';
80
+ });
81
+ it('offers the 2FA toggle to a password user', function () {
82
+ var section = render({
83
+ Use2FA: false,
84
+ IsOAuthUser: false
85
+ });
86
+ expect(section.toggle()).not.toBeNull();
87
+ expect(section.text()).not.toContain(SSO_MESSAGE);
88
+ });
89
+ it('replaces the toggle with the SSO message for an SSO user', function () {
90
+ var section = render({
91
+ Use2FA: false,
92
+ IsOAuthUser: true
93
+ });
94
+ expect(section.toggle()).toBeNull();
95
+ expect(section.text()).toContain(SSO_MESSAGE);
96
+ });
97
+ it('keeps the toggle for an SSO user who already has local 2FA, so it can be turned off', function () {
98
+ var section = render({
99
+ Use2FA: true,
100
+ IsOAuthUser: true
101
+ });
102
+ expect(section.toggle()).not.toBeNull();
103
+ expect(section.text()).not.toContain(SSO_MESSAGE);
104
+ });
105
+ });
@@ -9,6 +9,7 @@ var _reduxForm = require("redux-form");
9
9
  var _modalActions = require("../../redux/actions/modalActions");
10
10
  var _userActions = require("../../redux/actions/userActions");
11
11
  var _userConfigConstants = require("../../constants/userConfigConstants");
12
+ var _passkeyApi = require("../../helpers/passkeyApi");
12
13
  function _regenerator() { /*! regenerator-runtime -- Copyright (c) 2014-present, Facebook, Inc. -- license (MIT): https://github.com/babel/babel/blob/main/packages/babel-helpers/LICENSE */ var e, t, r = "function" == typeof Symbol ? Symbol : {}, n = r.iterator || "@@iterator", o = r.toStringTag || "@@toStringTag"; function i(r, n, o, i) { var c = n && n.prototype instanceof Generator ? n : Generator, u = Object.create(c.prototype); return _regeneratorDefine2(u, "_invoke", function (r, n, o) { var i, c, u, f = 0, p = o || [], y = !1, G = { p: 0, n: 0, v: e, a: d, f: d.bind(e, 4), d: function d(t, r) { return i = t, c = 0, u = e, G.n = r, a; } }; function d(r, n) { for (c = r, u = n, t = 0; !y && f && !o && t < p.length; t++) { var o, i = p[t], d = G.p, l = i[2]; r > 3 ? (o = l === n) && (u = i[(c = i[4]) ? 5 : (c = 3, 3)], i[4] = i[5] = e) : i[0] <= d && ((o = r < 2 && d < i[1]) ? (c = 0, G.v = n, G.n = i[1]) : d < l && (o = r < 3 || i[0] > n || n > l) && (i[4] = r, i[5] = n, G.n = l, c = 0)); } if (o || r > 1) return a; throw y = !0, n; } return function (o, p, l) { if (f > 1) throw TypeError("Generator is already running"); for (y && 1 === p && d(p, l), c = p, u = l; (t = c < 2 ? e : u) || !y;) { i || (c ? c < 3 ? (c > 1 && (G.n = -1), d(c, u)) : G.n = u : G.v = u); try { if (f = 2, i) { if (c || (o = "next"), t = i[o]) { if (!(t = t.call(i, u))) throw TypeError("iterator result is not an object"); if (!t.done) return t; u = t.value, c < 2 && (c = 0); } else 1 === c && (t = i["return"]) && t.call(i), c < 2 && (u = TypeError("The iterator does not provide a '" + o + "' method"), c = 1); i = e; } else if ((t = (y = G.n < 0) ? u : r.call(n, G)) !== a) break; } catch (t) { i = e, c = 1, u = t; } finally { f = 1; } } return { value: t, done: y }; }; }(r, o, i), !0), u; } var a = {}; function Generator() {} function GeneratorFunction() {} function GeneratorFunctionPrototype() {} t = Object.getPrototypeOf; var c = [][n] ? t(t([][n]())) : (_regeneratorDefine2(t = {}, n, function () { return this; }), t), u = GeneratorFunctionPrototype.prototype = Generator.prototype = Object.create(c); function f(e) { return Object.setPrototypeOf ? Object.setPrototypeOf(e, GeneratorFunctionPrototype) : (e.__proto__ = GeneratorFunctionPrototype, _regeneratorDefine2(e, o, "GeneratorFunction")), e.prototype = Object.create(u), e; } return GeneratorFunction.prototype = GeneratorFunctionPrototype, _regeneratorDefine2(u, "constructor", GeneratorFunctionPrototype), _regeneratorDefine2(GeneratorFunctionPrototype, "constructor", GeneratorFunction), GeneratorFunction.displayName = "GeneratorFunction", _regeneratorDefine2(GeneratorFunctionPrototype, o, "GeneratorFunction"), _regeneratorDefine2(u), _regeneratorDefine2(u, o, "Generator"), _regeneratorDefine2(u, n, function () { return this; }), _regeneratorDefine2(u, "toString", function () { return "[object Generator]"; }), (_regenerator = function _regenerator() { return { w: i, m: f }; })(); }
13
14
  function _regeneratorDefine2(e, r, n, t) { var i = Object.defineProperty; try { i({}, "", {}); } catch (e) { i = 0; } _regeneratorDefine2 = function _regeneratorDefine(e, r, n, t) { function o(r, n) { _regeneratorDefine2(e, r, function (e) { return this._invoke(r, n, e); }); } r ? i ? i(e, r, { value: n, enumerable: !t, configurable: !t, writable: !t }) : e[r] = n : (o("next", 0), o("throw", 1), o("return", 2)); }, _regeneratorDefine2(e, r, n, t); }
14
15
  function asyncGeneratorStep(n, t, e, r, o, a, c) { try { var i = n[a](c), u = i.value; } catch (n) { return void e(n); } i.done ? t(u) : Promise.resolve(u).then(r, o); }
@@ -27,9 +28,12 @@ var mapStateToProps = function mapStateToProps(state) {
27
28
  },
28
29
  use2FA: selector(state, 'use2FA'),
29
30
  use2FAOriginal: state.user.userInfo.Use2FA,
31
+ // SSO users enrol their second factor at the identity provider and the gateway refuses
32
+ // Enable*2FA for them; a pre-existing local factor can still be disabled
33
+ ssoManagedTwoFactor: !!state.user.userInfo.IsOAuthUser && !state.user.userInfo.Use2FA,
30
34
  showRecoverySeed:
31
- // Original setting from server.
32
- state.user.userInfo.Use2FA && TwoFAType !== _userConfigConstants.TwoFaTypes.Yubico
35
+ // Original setting from server. GetGoogle2FARecoveryKey takes an authenticator code, which a passkey user has not got.
36
+ state.user.userInfo.Use2FA && TwoFAType !== _userConfigConstants.TwoFaTypes.Yubico && TwoFAType !== _passkeyApi.PASSKEY_TFA_TYPE
33
37
  };
34
38
  };
35
39
  var mapDispatchToProps = function mapDispatchToProps(dispatch) {
@@ -42,9 +46,17 @@ var mapDispatchToProps = function mapDispatchToProps(dispatch) {
42
46
  _context.n = 1;
43
47
  return dispatch((0, _userActions.getGoogleQrCode)());
44
48
  case 1:
49
+ if (_context.v) {
50
+ _context.n = 2;
51
+ break;
52
+ }
53
+ // refused: the switch flipped itself on click, put it back as cancelling the modal does
54
+ dispatch((0, _reduxForm.change)('enableTwoFactorAuth', 'use2FA', false));
55
+ return _context.a(2);
56
+ case 2:
45
57
  dispatch((0, _reduxForm.change)('enableTwoFactorAuth', 'use2FA', true));
46
58
  dispatch((0, _modalActions.openModal)(_modalActions.MODAL_TYPES.ENABLE_2FA));
47
- case 2:
59
+ case 3:
48
60
  return _context.a(2);
49
61
  }
50
62
  }, _callee);
@@ -0,0 +1,13 @@
1
+ .unlink-oauth-identity-modal__text {
2
+ font-size: 1.6rem;
3
+ line-height: 1.5;
4
+ color: var(--font__color-primary);
5
+ margin: 0 0 2.4rem;
6
+ }
7
+
8
+ .unlink-oauth-identity-modal__error {
9
+ font-size: 1.4rem;
10
+ line-height: 1.4;
11
+ color: var(--danger__color);
12
+ margin: -1.2rem 0 2rem;
13
+ }
@@ -0,0 +1,246 @@
1
+ "use strict";
2
+
3
+ function _typeof(o) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (o) { return typeof o; } : function (o) { return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o; }, _typeof(o); }
4
+ Object.defineProperty(exports, "__esModule", {
5
+ value: true
6
+ });
7
+ exports["default"] = exports.UnlinkOAuthIdentityModal = void 0;
8
+ var _react = _interopRequireWildcard(require("react"));
9
+ var _reactI18next = require("react-i18next");
10
+ var _propTypes = _interopRequireDefault(require("prop-types"));
11
+ var _reactRedux = require("react-redux");
12
+ var _Modal = _interopRequireDefault(require("../common/Modal/Modal"));
13
+ var _APButton = _interopRequireDefault(require("../common/APButton"));
14
+ var _APInput = require("../common/APInput/APInput");
15
+ var _modalDecorator = _interopRequireDefault(require("../../hocs/modalDecorator"));
16
+ var _modalActions = require("../../redux/actions/modalActions");
17
+ var _authActions = require("../../redux/actions/authActions");
18
+ var _commonComponent = require("../../propTypes/commonComponent");
19
+ require("./UnlinkOAuthIdentityModal.css");
20
+ function _interopRequireDefault(e) { return e && e.__esModule ? e : { "default": e }; }
21
+ function _interopRequireWildcard(e, t) { if ("function" == typeof WeakMap) var r = new WeakMap(), n = new WeakMap(); return (_interopRequireWildcard = function _interopRequireWildcard(e, t) { if (!t && e && e.__esModule) return e; var o, i, f = { __proto__: null, "default": e }; if (null === e || "object" != _typeof(e) && "function" != typeof e) return f; if (o = t ? n : r) { if (o.has(e)) return o.get(e); o.set(e, f); } for (var _t2 in e) "default" !== _t2 && {}.hasOwnProperty.call(e, _t2) && ((i = (o = Object.defineProperty) && Object.getOwnPropertyDescriptor(e, _t2)) && (i.get || i.set) ? o(f, _t2, i) : f[_t2] = e[_t2]); return f; })(e, t); }
22
+ function _regenerator() { /*! regenerator-runtime -- Copyright (c) 2014-present, Facebook, Inc. -- license (MIT): https://github.com/babel/babel/blob/main/packages/babel-helpers/LICENSE */ var e, t, r = "function" == typeof Symbol ? Symbol : {}, n = r.iterator || "@@iterator", o = r.toStringTag || "@@toStringTag"; function i(r, n, o, i) { var c = n && n.prototype instanceof Generator ? n : Generator, u = Object.create(c.prototype); return _regeneratorDefine2(u, "_invoke", function (r, n, o) { var i, c, u, f = 0, p = o || [], y = !1, G = { p: 0, n: 0, v: e, a: d, f: d.bind(e, 4), d: function d(t, r) { return i = t, c = 0, u = e, G.n = r, a; } }; function d(r, n) { for (c = r, u = n, t = 0; !y && f && !o && t < p.length; t++) { var o, i = p[t], d = G.p, l = i[2]; r > 3 ? (o = l === n) && (u = i[(c = i[4]) ? 5 : (c = 3, 3)], i[4] = i[5] = e) : i[0] <= d && ((o = r < 2 && d < i[1]) ? (c = 0, G.v = n, G.n = i[1]) : d < l && (o = r < 3 || i[0] > n || n > l) && (i[4] = r, i[5] = n, G.n = l, c = 0)); } if (o || r > 1) return a; throw y = !0, n; } return function (o, p, l) { if (f > 1) throw TypeError("Generator is already running"); for (y && 1 === p && d(p, l), c = p, u = l; (t = c < 2 ? e : u) || !y;) { i || (c ? c < 3 ? (c > 1 && (G.n = -1), d(c, u)) : G.n = u : G.v = u); try { if (f = 2, i) { if (c || (o = "next"), t = i[o]) { if (!(t = t.call(i, u))) throw TypeError("iterator result is not an object"); if (!t.done) return t; u = t.value, c < 2 && (c = 0); } else 1 === c && (t = i["return"]) && t.call(i), c < 2 && (u = TypeError("The iterator does not provide a '" + o + "' method"), c = 1); i = e; } else if ((t = (y = G.n < 0) ? u : r.call(n, G)) !== a) break; } catch (t) { i = e, c = 1, u = t; } finally { f = 1; } } return { value: t, done: y }; }; }(r, o, i), !0), u; } var a = {}; function Generator() {} function GeneratorFunction() {} function GeneratorFunctionPrototype() {} t = Object.getPrototypeOf; var c = [][n] ? t(t([][n]())) : (_regeneratorDefine2(t = {}, n, function () { return this; }), t), u = GeneratorFunctionPrototype.prototype = Generator.prototype = Object.create(c); function f(e) { return Object.setPrototypeOf ? Object.setPrototypeOf(e, GeneratorFunctionPrototype) : (e.__proto__ = GeneratorFunctionPrototype, _regeneratorDefine2(e, o, "GeneratorFunction")), e.prototype = Object.create(u), e; } return GeneratorFunction.prototype = GeneratorFunctionPrototype, _regeneratorDefine2(u, "constructor", GeneratorFunctionPrototype), _regeneratorDefine2(GeneratorFunctionPrototype, "constructor", GeneratorFunction), GeneratorFunction.displayName = "GeneratorFunction", _regeneratorDefine2(GeneratorFunctionPrototype, o, "GeneratorFunction"), _regeneratorDefine2(u), _regeneratorDefine2(u, o, "Generator"), _regeneratorDefine2(u, n, function () { return this; }), _regeneratorDefine2(u, "toString", function () { return "[object Generator]"; }), (_regenerator = function _regenerator() { return { w: i, m: f }; })(); }
23
+ function _regeneratorDefine2(e, r, n, t) { var i = Object.defineProperty; try { i({}, "", {}); } catch (e) { i = 0; } _regeneratorDefine2 = function _regeneratorDefine(e, r, n, t) { function o(r, n) { _regeneratorDefine2(e, r, function (e) { return this._invoke(r, n, e); }); } r ? i ? i(e, r, { value: n, enumerable: !t, configurable: !t, writable: !t }) : e[r] = n : (o("next", 0), o("throw", 1), o("return", 2)); }, _regeneratorDefine2(e, r, n, t); }
24
+ function asyncGeneratorStep(n, t, e, r, o, a, c) { try { var i = n[a](c), u = i.value; } catch (n) { return void e(n); } i.done ? t(u) : Promise.resolve(u).then(r, o); }
25
+ function _asyncToGenerator(n) { return function () { var t = this, e = arguments; return new Promise(function (r, o) { var a = n.apply(t, e); function _next(n) { asyncGeneratorStep(a, r, o, _next, _throw, "next", n); } function _throw(n) { asyncGeneratorStep(a, r, o, _next, _throw, "throw", n); } _next(void 0); }); }; }
26
+ function _slicedToArray(r, e) { return _arrayWithHoles(r) || _iterableToArrayLimit(r, e) || _unsupportedIterableToArray(r, e) || _nonIterableRest(); }
27
+ function _nonIterableRest() { throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }
28
+ function _unsupportedIterableToArray(r, a) { if (r) { if ("string" == typeof r) return _arrayLikeToArray(r, a); var t = {}.toString.call(r).slice(8, -1); return "Object" === t && r.constructor && (t = r.constructor.name), "Map" === t || "Set" === t ? Array.from(r) : "Arguments" === t || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(t) ? _arrayLikeToArray(r, a) : void 0; } }
29
+ function _arrayLikeToArray(r, a) { (null == a || a > r.length) && (a = r.length); for (var e = 0, n = Array(a); e < a; e++) n[e] = r[e]; return n; }
30
+ function _iterableToArrayLimit(r, l) { var t = null == r ? null : "undefined" != typeof Symbol && r[Symbol.iterator] || r["@@iterator"]; if (null != t) { var e, n, i, u, a = [], f = !0, o = !1; try { if (i = (t = t.call(r)).next, 0 === l) { if (Object(t) !== t) return; f = !1; } else for (; !(f = (e = i.call(t)).done) && (a.push(e.value), a.length !== l); f = !0); } catch (r) { o = !0, n = r; } finally { try { if (!f && null != t["return"] && (u = t["return"](), Object(u) !== u)) return; } finally { if (o) throw n; } } return a; } }
31
+ function _arrayWithHoles(r) { if (Array.isArray(r)) return r; }
32
+ var baseClass = 'unlink-oauth-identity-modal';
33
+
34
+ // Disable-SSO confirm dialog (Settings → Profile & Security → "Single Sign-On", linked state).
35
+ // The gateway wants two proofs: the current APEX password typed here, and a fresh forced sign-in
36
+ // as the linked identity, taken in the same popup linking uses. Each code is single use, so every
37
+ // submit opens a new popup. UnlinkOAuthIdentity clears the binding and ends every session of the
38
+ // user, so the dialog says up front that they will be signed out everywhere. The gateway's refusal
39
+ // text is shown verbatim under the field; a refusal leaves the user on the settings page.
40
+ var UnlinkOAuthIdentityModal = exports.UnlinkOAuthIdentityModal = function UnlinkOAuthIdentityModal(_ref) {
41
+ var isOpen = _ref.isOpen,
42
+ close = _ref.close,
43
+ confirmWithSso = _ref.confirmWithSso,
44
+ doUnlink = _ref.doUnlink;
45
+ var _useTranslation = (0, _reactI18next.useTranslation)('auth'),
46
+ t = _useTranslation.t;
47
+ var _useState = (0, _react.useState)(''),
48
+ _useState2 = _slicedToArray(_useState, 2),
49
+ password = _useState2[0],
50
+ setPassword = _useState2[1];
51
+ var _useState3 = (0, _react.useState)(''),
52
+ _useState4 = _slicedToArray(_useState3, 2),
53
+ errormsg = _useState4[0],
54
+ setErrormsg = _useState4[1];
55
+ var _useState5 = (0, _react.useState)(false),
56
+ _useState6 = _slicedToArray(_useState5, 2),
57
+ submitting = _useState6[0],
58
+ setSubmitting = _useState6[1];
59
+ // bumped on cancel so a popup or request still in flight cannot unlink, or write its refusal
60
+ // into the next open, after the user backed out
61
+ var attempt = (0, _react.useRef)(0);
62
+ // bumped on every submit, so an abandoned attempt can tell whether a newer one has started
63
+ var submits = (0, _react.useRef)(0);
64
+ var reset = function reset() {
65
+ setPassword('');
66
+ setErrormsg('');
67
+ setSubmitting(false);
68
+ };
69
+ var cancel = function cancel() {
70
+ attempt.current += 1;
71
+ reset();
72
+ close();
73
+ };
74
+ var submit = /*#__PURE__*/function () {
75
+ var _ref2 = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee(e) {
76
+ var thisAttempt, thisSubmit, ssoParams, result, _t;
77
+ return _regenerator().w(function (_context) {
78
+ while (1) switch (_context.n) {
79
+ case 0:
80
+ e.preventDefault();
81
+ if (!submitting) {
82
+ _context.n = 1;
83
+ break;
84
+ }
85
+ return _context.a(2);
86
+ case 1:
87
+ thisAttempt = attempt.current;
88
+ thisSubmit = ++submits.current;
89
+ setSubmitting(true);
90
+ setErrormsg('');
91
+ // called before any await: the popup must open while the click's user activation is live
92
+ _context.n = 2;
93
+ return confirmWithSso();
94
+ case 2:
95
+ ssoParams = _context.v;
96
+ if (!(thisAttempt !== attempt.current)) {
97
+ _context.n = 3;
98
+ break;
99
+ }
100
+ // Dialog cancelled while the popup was open: drop the code rather than spend it. Cancel
101
+ // leaves the popup open and a newer submit reuses that named window, so both attempts get
102
+ // the same callback; once a newer submit has started, the keys are its own, so leave them.
103
+ if (ssoParams && thisSubmit === submits.current) (0, _authActions.clearFusionAuthSessionKeys)();
104
+ return _context.a(2);
105
+ case 3:
106
+ if (!ssoParams) {
107
+ _context.n = 5;
108
+ break;
109
+ }
110
+ _context.n = 4;
111
+ return doUnlink(ssoParams, password);
112
+ case 4:
113
+ _t = _context.v;
114
+ _context.n = 6;
115
+ break;
116
+ case 5:
117
+ _t = {
118
+ Unlinked: false,
119
+ cancelled: true
120
+ };
121
+ case 6:
122
+ result = _t;
123
+ if (!(thisAttempt !== attempt.current)) {
124
+ _context.n = 7;
125
+ break;
126
+ }
127
+ return _context.a(2);
128
+ case 7:
129
+ if (!(result && result.Unlinked)) {
130
+ _context.n = 8;
131
+ break;
132
+ }
133
+ // logout() is already taking the window to /login; just tidy the dialog away
134
+ reset();
135
+ close();
136
+ return _context.a(2);
137
+ case 8:
138
+ setSubmitting(false);
139
+ if (!(result && result.cancelled)) {
140
+ _context.n = 9;
141
+ break;
142
+ }
143
+ setErrormsg(t('SSO confirmation was not completed. Please try again.'));
144
+ return _context.a(2);
145
+ case 9:
146
+ // Gateway refusals are translated in the default namespace, like the snack texts of the link flow:
147
+ // t("Disabling SSO is not enabled for this exchange.")
148
+ // t("Sign in with your SSO provider to confirm disabling SSO.")
149
+ // t("This sign-in does not match the SSO identity linked to this account.")
150
+ // t("Sign in again with your SSO provider to disable SSO.")
151
+ // t("Could not load your account. Please try again.")
152
+ // t("Enter your current password to disable SSO.")
153
+ // t("The password is incorrect. If you have never set a password for this account, reset it first.")
154
+ // t("This account is not linked to an SSO identity.")
155
+ // t("SSO unlinking requires an interactive session, not an API key.")
156
+ // t("SSO is not enabled.")
157
+ // t("The sign-in could not be verified. Please try again.")
158
+ // t("Disabling SSO yourself is only available with FusionAuth sign-on. Contact support to disable SSO.")
159
+ // t("Your SSO sign-in name is different from your username, so two-factor authentication would stop working without SSO. Contact support to disable SSO.")
160
+ // t("Could not remove the link. Please try again.")
161
+ setErrormsg(t(result && result.errormsg || _authActions.UNLINK_FAILED_MESSAGE, {
162
+ ns: 'translation'
163
+ }));
164
+ case 10:
165
+ return _context.a(2);
166
+ }
167
+ }, _callee);
168
+ }));
169
+ return function submit(_x) {
170
+ return _ref2.apply(this, arguments);
171
+ };
172
+ }();
173
+ return /*#__PURE__*/_react["default"].createElement(_Modal["default"], {
174
+ isOpen: isOpen,
175
+ title: t('Disable SSO'),
176
+ onCancel: cancel,
177
+ close: cancel,
178
+ customClass: baseClass
179
+ }, /*#__PURE__*/_react["default"].createElement("form", {
180
+ onSubmit: submit,
181
+ className: "".concat(baseClass, "__form"),
182
+ noValidate: true
183
+ }, /*#__PURE__*/_react["default"].createElement("p", {
184
+ className: "".concat(baseClass, "__text")
185
+ }, t('Enter your current password, then sign in with your SSO provider to confirm. Disabling SSO signs you out of all sessions. You will need to sign in again with your password.')), /*#__PURE__*/_react["default"].createElement(_APInput.InnerInput, {
186
+ name: "password",
187
+ type: "password",
188
+ label: t('Password'),
189
+ autoComplete: "current-password",
190
+ autoFocus: true,
191
+ disabled: submitting,
192
+ customClass: baseClass,
193
+ input: {
194
+ value: password,
195
+ onChange: function onChange(ev) {
196
+ return setPassword(ev.target.value);
197
+ }
198
+ }
199
+ }), errormsg && /*#__PURE__*/_react["default"].createElement("div", {
200
+ className: "".concat(baseClass, "__error"),
201
+ role: "alert"
202
+ }, errormsg), /*#__PURE__*/_react["default"].createElement(_APButton["default"], {
203
+ type: "submit",
204
+ name: "unlinkOAuthIdentity",
205
+ styleName: _commonComponent.styleNames.additive,
206
+ disabled: submitting
207
+ }, t('Disable SSO'))));
208
+ };
209
+ UnlinkOAuthIdentityModal.propTypes = {
210
+ isOpen: _propTypes["default"].bool,
211
+ close: _propTypes["default"].func.isRequired,
212
+ confirmWithSso: _propTypes["default"].func.isRequired,
213
+ doUnlink: _propTypes["default"].func.isRequired
214
+ };
215
+ var container = (0, _reactRedux.connect)(null, function (dispatch) {
216
+ return {
217
+ // resolves to the popup's callback params, or null when it was closed or blocked
218
+ confirmWithSso: function () {
219
+ var _confirmWithSso = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee2() {
220
+ var ssoParams;
221
+ return _regenerator().w(function (_context2) {
222
+ while (1) switch (_context2.n) {
223
+ case 0:
224
+ ssoParams = null;
225
+ _context2.n = 1;
226
+ return dispatch((0, _authActions.startFusionAuthPopupLink)(function (params) {
227
+ ssoParams = params;
228
+ }));
229
+ case 1:
230
+ return _context2.a(2, ssoParams);
231
+ }
232
+ }, _callee2);
233
+ }));
234
+ function confirmWithSso() {
235
+ return _confirmWithSso.apply(this, arguments);
236
+ }
237
+ return confirmWithSso;
238
+ }(),
239
+ doUnlink: function doUnlink(ssoParams, password) {
240
+ return dispatch((0, _authActions.unlinkOAuthIdentity)(ssoParams, password));
241
+ }
242
+ };
243
+ })(UnlinkOAuthIdentityModal);
244
+ var _default = exports["default"] = (0, _modalDecorator["default"])({
245
+ name: _modalActions.MODAL_TYPES.UNLINK_OAUTH_IDENTITY
246
+ })(container);