@alphapoint/apex-web 5.7.0 → 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 (91) 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 +94 -16
  8. package/lib/components/2FA/TwoFactorAuthContainer.test.js +412 -0
  9. package/lib/components/ConfirmBlockTradeModal/ConfirmBlockTradeModalContainer.js +34 -6
  10. package/lib/components/ConfirmBlockTradeModal/ConfirmBlockTradeModalContainer.test.js +298 -0
  11. package/lib/components/ConfirmOrderModal/ConfirmOrderModalComponent.js +26 -4
  12. package/lib/components/ConfirmOrderModal/ConfirmOrderModalContainer.js +4 -1
  13. package/lib/components/EnableTwoFactorAuth/Disable2FAForm.js +22 -7
  14. package/lib/components/EnableTwoFactorAuth/Disable2FAModal.js +15 -5
  15. package/lib/components/EnableTwoFactorAuth/Disable2FAModal.test.js +460 -0
  16. package/lib/components/EnableTwoFactorAuth/Disable2FAModalContainer.js +108 -16
  17. package/lib/components/EnableTwoFactorAuth/EnableTwoFactorAuthContainerFactory.js +3 -2
  18. package/lib/components/FusionAuth/UnlinkOAuthIdentityModal.css +13 -0
  19. package/lib/components/FusionAuth/UnlinkOAuthIdentityModal.js +246 -0
  20. package/lib/components/FusionAuth/UnlinkOAuthIdentityModal.test.js +521 -0
  21. package/lib/components/Login/LoginFormComponent.js +1 -1
  22. package/lib/components/OrderEntryComponents/advancedForm/AdvancedOrderFormContainer.js +2 -0
  23. package/lib/components/OrderEntryComponents/common/FormAmountFields.js +5 -0
  24. package/lib/components/OrderEntryComponents/common/TwapScheduleFields.js +98 -0
  25. package/lib/components/OrderEntryComponents/defaultForm/OrderEntryAnchoring.js +86 -39
  26. package/lib/components/OrderEntryComponents/defaultForm/OrderEntryAnchoring.test.js +326 -0
  27. package/lib/components/OrderEntryComponents/defaultForm/OrderEntryContainer.js +10 -2
  28. package/lib/components/OrderHistoryComponents/DepositsStatus/DepositsStatusComponent.js +1 -1
  29. package/lib/components/OrderHistoryComponents/DepositsStatus/DepositsStatusComponent.test.js +99 -0
  30. package/lib/components/OrderHistoryComponents/InactiveOrders/InactiveOrdersComponent.js +1 -1
  31. package/lib/components/OrderHistoryComponents/OpenOrders/OpenOrdersComponent.js +1 -1
  32. package/lib/components/OrderHistoryComponents/WithdrawStatus/WithdrawStatusComponent.js +1 -1
  33. package/lib/components/OrderHistoryComponents/WithdrawStatus/WithdrawStatusComponent.test.js +113 -0
  34. package/lib/components/Settings/ProfileAndSecurity/PasskeysSettingsCard/PasskeysSettingsCard.css +108 -0
  35. package/lib/components/Settings/ProfileAndSecurity/PasskeysSettingsCard/PasskeysSettingsCard.test.js +983 -0
  36. package/lib/components/Settings/ProfileAndSecurity/PasskeysSettingsCard/PasskeysSettingsCardComponent.js +500 -0
  37. package/lib/components/Settings/ProfileAndSecurity/PasskeysSettingsCard/index.js +9 -0
  38. package/lib/components/Settings/ProfileAndSecurity/ProfileSettingsCard/ProfileForm/SsoLinkRowComponent.css +4 -0
  39. package/lib/components/Settings/ProfileAndSecurity/ProfileSettingsCard/ProfileForm/SsoLinkRowComponent.js +29 -17
  40. package/lib/components/Settings/ProfileAndSecurity/ProfileSettingsCard/ProfileForm/SsoLinkRowComponent.test.js +135 -0
  41. package/lib/components/Settings/ProfileAndSecurity/TwoFactorAuthSettingsCard/EnableTwoFactorAuth/EnableTwoFactorAuthComponent.test.js +23 -1
  42. package/lib/components/TwoFactorAuthForm/TwoFactorAuthForm.test.js +475 -0
  43. package/lib/components/TwoFactorAuthForm/TwoFactorAuthFormComponent.js +26 -5
  44. package/lib/components/TwoFactorAuthForm/TwoFactorAuthFormContainer.js +50 -32
  45. package/lib/components/common/APAutoTabInput/APAutoTabInput.js +5 -2
  46. package/lib/components/common/APSelect/APSelect.js +3 -1
  47. package/lib/config/CONFIG.md +4 -0
  48. package/lib/config/configDefault.json +2 -1
  49. package/lib/constants/sendOrder/orderEntryFormConstants.js +23 -4
  50. package/lib/constants/sendOrder/timeInForceConstants.js +3 -1
  51. package/lib/constants/sendOrder/twapRejectReasons.js +26 -0
  52. package/lib/helpers/orderHistoryHelper.js +13 -1
  53. package/lib/helpers/orderHistoryHelper.test.js +58 -13
  54. package/lib/helpers/passkeyApi.js +228 -0
  55. package/lib/helpers/passkeyApi.test.js +171 -0
  56. package/lib/helpers/placeOrderHelper.js +76 -61
  57. package/lib/helpers/placeOrderHelper.test.js +169 -10
  58. package/lib/helpers/recalculateOrderHelper.js +4 -1
  59. package/lib/helpers/recalculateOrderHelper.test.js +88 -2
  60. package/lib/helpers/twapOrderHelper.js +265 -0
  61. package/lib/helpers/twapOrderHelper.test.js +467 -0
  62. package/lib/helpers/webauthnHelper.js +300 -0
  63. package/lib/helpers/webauthnHelper.test.js +199 -0
  64. package/lib/hocs/withOneSubmission.js +168 -0
  65. package/lib/redux/actions/apiActions.js +52 -1
  66. package/lib/redux/actions/apiActions.test.js +135 -0
  67. package/lib/redux/actions/authActions.js +514 -198
  68. package/lib/redux/actions/authActions.test.js +627 -47
  69. package/lib/redux/actions/depositActions.js +1 -1
  70. package/lib/redux/actions/depositActions.test.js +100 -30
  71. package/lib/redux/actions/fusionAuthActions.test.js +265 -84
  72. package/lib/redux/actions/modalActions.js +1 -0
  73. package/lib/redux/actions/orderEntryActions.blockTrade.test.js +306 -0
  74. package/lib/redux/actions/orderEntryActions.js +74 -22
  75. package/lib/redux/actions/orderEntryActions.test.js +63 -11
  76. package/lib/redux/actions/orderHistoryActions.js +9 -4
  77. package/lib/redux/actions/orderHistoryActions.test.js +63 -0
  78. package/lib/redux/actions/userActions.js +314 -177
  79. package/lib/redux/actions/userActions.test.js +844 -268
  80. package/lib/redux/margin/actions/marginActions.js +6 -3
  81. package/lib/redux/margin/actions/marginActions.test.js +166 -0
  82. package/lib/redux/middlewares/authMiddleware.js +5 -0
  83. package/lib/redux/middlewares/authMiddleware.test.js +88 -29
  84. package/lib/redux/reducers/authReducer.js +1 -0
  85. package/lib/redux/reducers/authReducer.test.js +38 -0
  86. package/lib/redux/selectors/orderEntrySelector.js +19 -8
  87. package/lib/redux/selectors/orderEntrySelector.test.js +209 -0
  88. package/lib/redux/selectors/orderTotalSelector.test.js +40 -1
  89. package/lib/services/fms/fms.js +2 -0
  90. package/lib/services/fms/fms.test.js +35 -0
  91. package/package.json +4 -4
@@ -0,0 +1,168 @@
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.withdrawSubmission = exports.startSubmission = exports.promptThenSend = exports.endSubmission = exports["default"] = exports.answerOnce = void 0;
8
+ var _react = _interopRequireWildcard(require("react"));
9
+ 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); }
10
+ function _extends() { return _extends = Object.assign ? Object.assign.bind() : function (n) { for (var e = 1; e < arguments.length; e++) { var t = arguments[e]; for (var r in t) ({}).hasOwnProperty.call(t, r) && (n[r] = t[r]); } return n; }, _extends.apply(null, arguments); }
11
+ function _slicedToArray(r, e) { return _arrayWithHoles(r) || _iterableToArrayLimit(r, e) || _unsupportedIterableToArray(r, e) || _nonIterableRest(); }
12
+ 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."); }
13
+ 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; } }
14
+ 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; }
15
+ 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; } }
16
+ function _arrayWithHoles(r) { if (Array.isArray(r)) return r; }
17
+ 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 }; })(); }
18
+ 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); }
19
+ 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); }
20
+ 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); }); }; }
21
+ // One 2FA answer at a time, whether a code or a passkey: the answered action must not be sent twice. A `submission`
22
+ // is shared by both answers and outlives one showing of the form. `current` is the answer holding it, from a click on
23
+ // Use a passkey (browser prompt included) or a code's submit until the gateway replies; `sending` says the request is
24
+ // on its way. `onChange` tells the form to disable both answers while one holds it.
25
+ var startSubmission = exports.startSubmission = function startSubmission(submission) {
26
+ if (submission.current) return null;
27
+ var owner = {};
28
+ submission.current = owner;
29
+ if (submission.onChange) submission.onChange(true);
30
+ return owner;
31
+ };
32
+ var endSubmission = exports.endSubmission = function endSubmission(submission, owner) {
33
+ if (!owner || submission.current !== owner) return;
34
+ submission.current = null;
35
+ submission.sending = false;
36
+ if (submission.onChange) submission.onChange(false);
37
+ };
38
+
39
+ /** Runs `answer` only when no other answer holds `submission`, and lets go of it once `answer` settles. */
40
+ var answerOnce = exports.answerOnce = /*#__PURE__*/function () {
41
+ var _ref = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee(submission, answer) {
42
+ var owner;
43
+ return _regenerator().w(function (_context) {
44
+ while (1) switch (_context.p = _context.n) {
45
+ case 0:
46
+ owner = startSubmission(submission);
47
+ if (owner) {
48
+ _context.n = 1;
49
+ break;
50
+ }
51
+ return _context.a(2, undefined);
52
+ case 1:
53
+ _context.p = 1;
54
+ _context.n = 2;
55
+ return answer();
56
+ case 2:
57
+ return _context.a(2, _context.v);
58
+ case 3:
59
+ _context.p = 3;
60
+ endSubmission(submission, owner);
61
+ return _context.f(3);
62
+ case 4:
63
+ return _context.a(2);
64
+ }
65
+ }, _callee, null, [[1,, 3, 4]]);
66
+ }));
67
+ return function answerOnce(_x, _x2) {
68
+ return _ref.apply(this, arguments);
69
+ };
70
+ }();
71
+
72
+ /**
73
+ * A passkey answer: `prompt` asks the browser for it and `send` sends what the browser returned. It holds `submission`
74
+ * across both. Resolves to undefined, with nothing sent, when another answer holds the submission or when the answer
75
+ * was withdrawn while the browser prompt was open.
76
+ */
77
+ var promptThenSend = exports.promptThenSend = /*#__PURE__*/function () {
78
+ var _ref2 = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee2(submission, prompt, send) {
79
+ var owner, attempt, withdrawn, answer, _t;
80
+ return _regenerator().w(function (_context2) {
81
+ while (1) switch (_context2.p = _context2.n) {
82
+ case 0:
83
+ owner = startSubmission(submission);
84
+ if (owner) {
85
+ _context2.n = 1;
86
+ break;
87
+ }
88
+ return _context2.a(2, undefined);
89
+ case 1:
90
+ submission.attempt = (submission.attempt || 0) + 1;
91
+ attempt = submission.attempt;
92
+ withdrawn = function withdrawn() {
93
+ return attempt !== submission.attempt;
94
+ };
95
+ _context2.p = 2;
96
+ _context2.p = 3;
97
+ _context2.n = 4;
98
+ return prompt();
99
+ case 4:
100
+ answer = _context2.v;
101
+ _context2.n = 7;
102
+ break;
103
+ case 5:
104
+ _context2.p = 5;
105
+ _t = _context2.v;
106
+ if (!withdrawn()) {
107
+ _context2.n = 6;
108
+ break;
109
+ }
110
+ return _context2.a(2, undefined);
111
+ case 6:
112
+ throw _t;
113
+ case 7:
114
+ if (!withdrawn()) {
115
+ _context2.n = 8;
116
+ break;
117
+ }
118
+ return _context2.a(2, undefined);
119
+ case 8:
120
+ submission.sending = true;
121
+ _context2.n = 9;
122
+ return send(answer);
123
+ case 9:
124
+ return _context2.a(2, _context2.v);
125
+ case 10:
126
+ _context2.p = 10;
127
+ endSubmission(submission, owner);
128
+ return _context2.f(10);
129
+ case 11:
130
+ return _context2.a(2);
131
+ }
132
+ }, _callee2, null, [[3, 5], [2,, 10, 11]]);
133
+ }));
134
+ return function promptThenSend(_x3, _x4, _x5) {
135
+ return _ref2.apply(this, arguments);
136
+ };
137
+ }();
138
+
139
+ /**
140
+ * The form was closed. An answer still waiting on the browser prompt is withdrawn, so nothing is sent for it, and it
141
+ * lets go of the submission so the next opening of the form can answer. An answer already on its way keeps the
142
+ * submission until the gateway replies.
143
+ */
144
+ var withdrawSubmission = exports.withdrawSubmission = function withdrawSubmission(submission) {
145
+ submission.attempt = (submission.attempt || 0) + 1;
146
+ if (!submission.sending) endSubmission(submission, submission.current);
147
+ };
148
+
149
+ /**
150
+ * Wraps a redux-form form so that its onSubmit (through its props) and a passkey answer share one `submission`, and
151
+ * passes `answering` while one of them holds it.
152
+ */
153
+ var withOneSubmission = function withOneSubmission(Form) {
154
+ var WithOneSubmission = function WithOneSubmission(props) {
155
+ var submission = (0, _react.useRef)({}).current;
156
+ var _useState = (0, _react.useState)(false),
157
+ _useState2 = _slicedToArray(_useState, 2),
158
+ answering = _useState2[0],
159
+ setAnswering = _useState2[1];
160
+ submission.onChange = setAnswering;
161
+ return /*#__PURE__*/_react["default"].createElement(Form, _extends({}, props, {
162
+ submission: submission,
163
+ answering: answering
164
+ }));
165
+ };
166
+ return WithOneSubmission;
167
+ };
168
+ var _default = exports["default"] = withOneSubmission;
@@ -3,24 +3,68 @@
3
3
  Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
- exports.receiveValidate2FARequiredEndpoints = exports.getApiInfo = exports.callFMSAPI = exports.callAPI = exports.RECEIVE_VALIDATE_2FA_REQUIRED_ENDPOINTS = exports.GET_API_INFO = void 0;
6
+ exports.settleErrorFrame = exports.receiveValidate2FARequiredEndpoints = exports.isErrorFrame = exports.getApiInfo = exports.errorPayload = exports.callFMSAPI = exports.callAPI = exports.RECEIVE_VALIDATE_2FA_REQUIRED_ENDPOINTS = exports.GET_API_INFO = exports.ENDPOINT_NOT_FOUND = void 0;
7
7
  var _apex = _interopRequireDefault(require("../../apex"));
8
8
  var _fms = require("../../services/fms/fms");
9
9
  var _modalActions = require("./modalActions");
10
10
  var _twoFactorAuthCancellation = require("../../helpers/twoFactorAuthCancellation");
11
11
  function _interopRequireDefault(e) { return e && e.__esModule ? e : { "default": e }; }
12
+ 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); }
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); }
15
16
  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); }); }; }
17
+ function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
18
+ function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { _defineProperty(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
19
+ function _defineProperty(e, r, t) { return (r = _toPropertyKey(r)) in e ? Object.defineProperty(e, r, { value: t, enumerable: !0, configurable: !0, writable: !0 }) : e[r] = t, e; }
20
+ function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == _typeof(i) ? i : i + ""; }
21
+ function _toPrimitive(t, r) { if ("object" != _typeof(t) || !t) return t; var e = t[Symbol.toPrimitive]; if (void 0 !== e) { var i = e.call(t, r || "default"); if ("object" != _typeof(i)) return i; throw new TypeError("@@toPrimitive must return a primitive value."); } return ("string" === r ? String : Number)(t); }
16
22
  var GET_API_INFO = exports.GET_API_INFO = 'GET_API_INFO';
17
23
  var RECEIVE_VALIDATE_2FA_REQUIRED_ENDPOINTS = exports.RECEIVE_VALIDATE_2FA_REQUIRED_ENDPOINTS = 'RECEIVE_VALIDATE_2FA_REQUIRED_ENDPOINTS';
24
+ var ENDPOINT_NOT_FOUND = exports.ENDPOINT_NOT_FOUND = 'Endpoint Not Found';
18
25
  var receiveValidate2FARequiredEndpoints = exports.receiveValidate2FARequiredEndpoints = function receiveValidate2FARequiredEndpoints(payload) {
19
26
  return {
20
27
  type: RECEIVE_VALIDATE_2FA_REQUIRED_ENDPOINTS,
21
28
  payload: payload
22
29
  };
23
30
  };
31
+
32
+ /**
33
+ * True for the frame the connection rejects with when the gateway answers an
34
+ * RPC with an error (m === 5), e.g. "Endpoint Not Found" for a user whose
35
+ * session carries no permission for that endpoint.
36
+ */
37
+ var isErrorFrame = exports.isErrorFrame = function isErrorFrame(error) {
38
+ return !!error && error.m === 5;
39
+ };
40
+
41
+ /**
42
+ * The gateway's own error payloads look like { result: false, errormsg, errorcode, detail }
43
+ * and callers already check `result !== false` on them. A refusal is given the same shape for
44
+ * the callers that opt in via settleErrorFrame.
45
+ */
46
+ var errorPayload = exports.errorPayload = function errorPayload(errormsg, endpoint) {
47
+ return {
48
+ result: false,
49
+ errormsg: errormsg,
50
+ detail: endpoint
51
+ };
52
+ };
53
+
54
+ /**
55
+ * Turns a rejected error frame into the error payload above (plus Authenticated: false for the
56
+ * auth endpoints) and re-throws anything else. Usage: `dispatch(callAPI(...)).catch(settleErrorFrame)`
57
+ * or `apex.connection.Authenticate2FA(payload).catch(settleErrorFrame)`.
58
+ */
59
+ var settleErrorFrame = exports.settleErrorFrame = function settleErrorFrame(error) {
60
+ if (isErrorFrame(error)) {
61
+ console.error("".concat(error.n, " was refused by the gateway"), error.o);
62
+ return _objectSpread(_objectSpread({}, errorPayload(error.o || ENDPOINT_NOT_FOUND, error.n)), {}, {
63
+ Authenticated: false
64
+ });
65
+ }
66
+ throw error;
67
+ };
24
68
  var getApiInfo = exports.getApiInfo = function getApiInfo() {
25
69
  return /*#__PURE__*/function () {
26
70
  var _ref = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee(dispatch, getState) {
@@ -32,6 +76,9 @@ var getApiInfo = exports.getApiInfo = function getApiInfo() {
32
76
  _context.n = 1;
33
77
  return _apex["default"].connection.RPCPromise('GetValidate2FARequiredEndpoints', {
34
78
  OMSId: OMSId
79
+ })["catch"](function (e) {
80
+ console.error('getApiInfo action error', e);
81
+ return;
35
82
  });
36
83
  case 1:
37
84
  data = _context.v;
@@ -53,6 +100,10 @@ var getApiInfo = exports.getApiInfo = function getApiInfo() {
53
100
  * dismisses the 2FA modal. Off by default: most callers await callAPI with no catch, so for them a
54
101
  * dismissed modal leaves the call pending (the behaviour they were written against) instead of
55
102
  * surfacing an unhandled rejection. Callers that opt in must handle the cancellation.
103
+ *
104
+ * An error reply from the gateway (m === 5) rejects with the frame. Loaders that store the reply
105
+ * must not catch it (the store stays untouched, which is what they want); callers that report the
106
+ * refusal to the user chain `.catch(settleErrorFrame)` to get an error payload instead.
56
107
  */
57
108
  var callAPI = exports.callAPI = function callAPI(endpoint, apiPayload) {
58
109
  var _ref2 = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {},
@@ -95,4 +95,139 @@ describe('callAPI', function () {
95
95
  }
96
96
  }, _callee3);
97
97
  })));
98
+ });
99
+ describe('callAPI error replies', function () {
100
+ var apex = require('../../apex');
101
+ var _require = require('./apiActions'),
102
+ ENDPOINT_NOT_FOUND = _require.ENDPOINT_NOT_FOUND;
103
+ var store = mockStore({
104
+ api: {
105
+ validate2FARequiredEndpoints: {}
106
+ }
107
+ });
108
+ beforeEach(function () {
109
+ jest.spyOn(console, 'error').mockImplementation(function () {});
110
+ });
111
+ afterEach(function () {
112
+ console.error.mockRestore();
113
+ apex.connection.RPCPromise.mockImplementation(function () {
114
+ return Promise.resolve({
115
+ o: JSON.stringify({
116
+ result: true
117
+ })
118
+ });
119
+ });
120
+ });
121
+ it('rejects with the frame when the gateway answers with an error reply', /*#__PURE__*/_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee4() {
122
+ var frame;
123
+ return _regenerator().w(function (_context4) {
124
+ while (1) switch (_context4.n) {
125
+ case 0:
126
+ frame = {
127
+ m: 5,
128
+ i: 20,
129
+ n: 'GetUserInfo',
130
+ o: ENDPOINT_NOT_FOUND
131
+ };
132
+ apex.connection.RPCPromise.mockImplementationOnce(function () {
133
+ return Promise.reject(frame);
134
+ });
135
+ _context4.n = 1;
136
+ return expect(store.dispatch((0, _apiActions.callAPI)('GetUserInfo', {
137
+ UserId: 1
138
+ }))).rejects.toBe(frame);
139
+ case 1:
140
+ return _context4.a(2);
141
+ }
142
+ }, _callee4);
143
+ })));
144
+ it('lets a caller settle the rejection into an error payload', /*#__PURE__*/_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee5() {
145
+ var _require2, settleErrorFrame, result;
146
+ return _regenerator().w(function (_context5) {
147
+ while (1) switch (_context5.n) {
148
+ case 0:
149
+ _require2 = require('./apiActions'), settleErrorFrame = _require2.settleErrorFrame;
150
+ apex.connection.RPCPromise.mockImplementationOnce(function () {
151
+ return Promise.reject({
152
+ m: 5,
153
+ i: 2,
154
+ n: 'X',
155
+ o: 'Not Authorized'
156
+ });
157
+ });
158
+ _context5.n = 1;
159
+ return store.dispatch((0, _apiActions.callAPI)('X', {}))["catch"](settleErrorFrame);
160
+ case 1:
161
+ result = _context5.v;
162
+ expect(result).toMatchObject({
163
+ result: false,
164
+ errormsg: 'Not Authorized',
165
+ detail: 'X'
166
+ });
167
+ case 2:
168
+ return _context5.a(2);
169
+ }
170
+ }, _callee5);
171
+ })));
172
+ it('still rejects errors that are not gateway error replies', /*#__PURE__*/_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee6() {
173
+ return _regenerator().w(function (_context6) {
174
+ while (1) switch (_context6.n) {
175
+ case 0:
176
+ apex.connection.RPCPromise.mockImplementationOnce(function () {
177
+ return Promise.reject(new Error('socket closed'));
178
+ });
179
+ _context6.n = 1;
180
+ return expect(store.dispatch((0, _apiActions.callAPI)('GetUserInfo', {}))).rejects.toThrow('socket closed');
181
+ case 1:
182
+ return _context6.a(2);
183
+ }
184
+ }, _callee6);
185
+ })));
186
+ });
187
+ describe('settleErrorFrame', function () {
188
+ var _require3 = require('./apiActions'),
189
+ settleErrorFrame = _require3.settleErrorFrame,
190
+ ENDPOINT_NOT_FOUND = _require3.ENDPOINT_NOT_FOUND;
191
+ beforeEach(function () {
192
+ return jest.spyOn(console, 'error').mockImplementation(function () {});
193
+ });
194
+ afterEach(function () {
195
+ return console.error.mockRestore();
196
+ });
197
+ it('turns an error frame into an unauthenticated error payload', /*#__PURE__*/_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee7() {
198
+ var result;
199
+ return _regenerator().w(function (_context7) {
200
+ while (1) switch (_context7.n) {
201
+ case 0:
202
+ _context7.n = 1;
203
+ return Promise.reject({
204
+ m: 5,
205
+ i: 2,
206
+ n: 'Authenticate2FA',
207
+ o: ENDPOINT_NOT_FOUND
208
+ })["catch"](settleErrorFrame);
209
+ case 1:
210
+ result = _context7.v;
211
+ expect(result).toEqual({
212
+ result: false,
213
+ errormsg: ENDPOINT_NOT_FOUND,
214
+ detail: 'Authenticate2FA',
215
+ Authenticated: false
216
+ });
217
+ case 2:
218
+ return _context7.a(2);
219
+ }
220
+ }, _callee7);
221
+ })));
222
+ it('re-throws anything that is not an error frame', /*#__PURE__*/_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee8() {
223
+ return _regenerator().w(function (_context8) {
224
+ while (1) switch (_context8.n) {
225
+ case 0:
226
+ _context8.n = 1;
227
+ return expect(Promise.reject(new Error('socket closed'))["catch"](settleErrorFrame)).rejects.toThrow('socket closed');
228
+ case 1:
229
+ return _context8.a(2);
230
+ }
231
+ }, _callee8);
232
+ })));
98
233
  });