@frontegg/redux-store 7.130.0 → 7.131.0-alpha.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.
Files changed (37) hide show
  1. package/auth/ActivateAccountState/actions.js +6 -0
  2. package/auth/LoginState/actions/hostedLoginAuthorize.actions.d.ts +3 -1
  3. package/auth/LoginState/actions/hostedLoginAuthorize.actions.js +29 -6
  4. package/auth/LoginState/actions/index.d.ts +8 -1
  5. package/auth/LoginState/actions/index.js +172 -11
  6. package/auth/LoginState/actions/mfaWithAuthenticator.actions.js +3 -0
  7. package/auth/LoginState/actions/mfaWithEmailCode.actions.js +3 -0
  8. package/auth/LoginState/actions/mfaWithSMS.actions.js +3 -0
  9. package/auth/LoginState/actions/mfaWithWebAuthn.actions.js +3 -0
  10. package/auth/MfaState/actions.js +3 -0
  11. package/auth/SocialLoginState/actions.js +3 -0
  12. package/auth/StepUpState/actions/generateStepUpSession.actions.js +5 -0
  13. package/auth/StepUpState/helpers.d.ts +2 -1
  14. package/auth/StepUpState/helpers.js +3 -2
  15. package/auth/TenantsState/actions.js +8 -1
  16. package/auth/helpers.d.ts +15 -0
  17. package/auth/helpers.js +60 -2
  18. package/helpers/handlers.d.ts +4 -1
  19. package/helpers/handlers.js +4 -1
  20. package/index.js +1 -1
  21. package/mocks/auth-mocks/loginActions.mocks.d.ts +8 -1
  22. package/node/auth/ActivateAccountState/actions.js +6 -0
  23. package/node/auth/LoginState/actions/hostedLoginAuthorize.actions.js +27 -4
  24. package/node/auth/LoginState/actions/index.js +169 -8
  25. package/node/auth/LoginState/actions/mfaWithAuthenticator.actions.js +3 -0
  26. package/node/auth/LoginState/actions/mfaWithEmailCode.actions.js +3 -0
  27. package/node/auth/LoginState/actions/mfaWithSMS.actions.js +3 -0
  28. package/node/auth/LoginState/actions/mfaWithWebAuthn.actions.js +3 -0
  29. package/node/auth/MfaState/actions.js +3 -0
  30. package/node/auth/SocialLoginState/actions.js +3 -0
  31. package/node/auth/StepUpState/actions/generateStepUpSession.actions.js +5 -0
  32. package/node/auth/StepUpState/helpers.js +3 -2
  33. package/node/auth/TenantsState/actions.js +7 -0
  34. package/node/auth/helpers.js +66 -2
  35. package/node/helpers/handlers.js +5 -1
  36. package/node/index.js +1 -1
  37. package/package.json +2 -2
@@ -9,12 +9,15 @@ var _exportNames = {
9
9
  isResetPasswordRequired: true,
10
10
  mapMetaDataObjectToActions: true,
11
11
  getUri: true,
12
+ isOnOidcCallbackRoute: true,
13
+ restoreTabTenantUnlessSsoCallback: true,
12
14
  prepareIdentifiersForSignup: true,
15
+ isOnAuthPageRoute: true,
13
16
  isAuthRoute: true
14
17
  };
15
- exports.prepareIdentifiersForSignup = exports.mapMetaDataObjectToActions = exports.isResetPasswordRequired = exports.isMfaRequired = exports.isAuthRoute = exports.getUri = void 0;
16
- var _extends2 = _interopRequireDefault(require("@babel/runtime/helpers/extends"));
18
+ exports.restoreTabTenantUnlessSsoCallback = exports.prepareIdentifiersForSignup = exports.mapMetaDataObjectToActions = exports.isResetPasswordRequired = exports.isOnOidcCallbackRoute = exports.isOnAuthPageRoute = exports.isMfaRequired = exports.isAuthRoute = exports.getUri = void 0;
17
19
  var _objectWithoutPropertiesLoose2 = _interopRequireDefault(require("@babel/runtime/helpers/objectWithoutPropertiesLoose"));
20
+ var _extends2 = _interopRequireDefault(require("@babel/runtime/helpers/extends"));
18
21
  var _restApi = require("@frontegg/rest-api");
19
22
  var _consts = require("./LoginState/consts");
20
23
  var _helpers = require("./Entitlements/helpers");
@@ -104,7 +107,55 @@ const getUri = urlStrategy => {
104
107
  }
105
108
  }
106
109
  };
110
+
111
+ /**
112
+ * The route the app shows and the page's path. With hash routing they differ: the app's pages live in the hash, but
113
+ * SAML, OIDC, social and magic link callbacks come back on the path, which is where login matches them.
114
+ */
107
115
  exports.getUri = getUri;
116
+ const getCurrentRoutes = urlStrategy => {
117
+ const hashOrPathRoute = getUri(urlStrategy);
118
+ const {
119
+ pathname
120
+ } = window.location;
121
+ return hashOrPathRoute === pathname ? [pathname] : [hashOrPathRoute, pathname];
122
+ };
123
+
124
+ /**
125
+ * On the OIDC callback the page still has to finish the OIDC login with its code: a refresh refused before that is not
126
+ * a reason to go back to the IdP, which would send the user straight back here, forever.
127
+ */
128
+ const isOnOidcCallbackRoute = store => {
129
+ var _store$root$urlStrate;
130
+ const {
131
+ oidcRedirectUrl
132
+ } = (0, _extends2.default)({}, _consts.defaultFronteggRoutes, store.auth.routes);
133
+ return !!oidcRedirectUrl && getCurrentRoutes((_store$root$urlStrate = store.root.urlStrategy) != null ? _store$root$urlStrate : 'path').some(currentRoute => currentRoute.endsWith(oidcRedirectUrl));
134
+ };
135
+
136
+ /**
137
+ * After a switch refused for SSO the tab points at the SSO tenant. Its SSO login comes back on a callback route and
138
+ * keeps it; any other page load means the user didn't finish that login, so the tab goes back to its tenant.
139
+ */
140
+ exports.isOnOidcCallbackRoute = isOnOidcCallbackRoute;
141
+ const restoreTabTenantUnlessSsoCallback = store => {
142
+ var _store$root$urlStrate2;
143
+ if (!(0, _restApi.isEnforceSsoOnTenantAccessEnabled)(store.root.appName) || !_restApi.ContextHolder.for(store.root.appName).isSessionPerTenantEnabled()) {
144
+ return;
145
+ }
146
+ const {
147
+ samlCallbackUrl,
148
+ oidcRedirectUrl,
149
+ hostedLoginRedirectUrl
150
+ } = (0, _extends2.default)({}, _consts.defaultFronteggRoutes, store.auth.routes);
151
+ // matched like login matches its callback pages: endsWith, so a basename before the route still counts
152
+ const currentRoutes = getCurrentRoutes((_store$root$urlStrate2 = store.root.urlStrategy) != null ? _store$root$urlStrate2 : 'path');
153
+ const isSsoCallback = [samlCallbackUrl, oidcRedirectUrl, hostedLoginRedirectUrl].some(route => !!route && currentRoutes.some(currentRoute => currentRoute.endsWith(route)));
154
+ if (!isSsoCallback) {
155
+ (0, _restApi.restoreTabTenantBeforeSsoSwitch)();
156
+ }
157
+ };
158
+ exports.restoreTabTenantUnlessSsoCallback = restoreTabTenantUnlessSsoCallback;
108
159
  const prepareIdentifiersForSignup = payload => {
109
160
  const {
110
161
  phoneNumber,
@@ -129,7 +180,20 @@ const prepareIdentifiersForSignup = payload => {
129
180
  }
130
181
  return finalDto;
131
182
  };
183
+
184
+ // Pages the user lands on after login or sign-up: destinations, not auth pages.
132
185
  exports.prepareIdentifiersForSignup = prepareIdentifiersForSignup;
186
+ const AFTER_AUTH_DESTINATION_ROUTES = ['authenticatedUrl', 'signUpSuccessUrl', 'accountSignUpSuccessUrl', 'userSignUpSuccessUrl', 'customLoginAuthenticatedUrl'];
187
+
188
+ /**
189
+ * Whether the current route is an auth page (login, tenant chooser, social / magic link / SSO callback), not one to come
190
+ * back to. Unlike isAuthRoute: after-login / sign-up destinations don't count, and endsWith lets a basename prefix it.
191
+ */
192
+ const isOnAuthPageRoute = (urlStrategy, routes) => {
193
+ const currentRoutes = getCurrentRoutes(urlStrategy);
194
+ return Object.entries((0, _extends2.default)({}, _consts.defaultFronteggRoutes, routes)).some(([name, route]) => !AFTER_AUTH_DESTINATION_ROUTES.includes(name) && typeof route === 'string' && !!route && currentRoutes.some(currentRoute => currentRoute.endsWith(route)));
195
+ };
196
+ exports.isOnAuthPageRoute = isOnAuthPageRoute;
133
197
  const isAuthRoute = (path, routes) => {
134
198
  const _defaultFronteggRoute = (0, _extends2.default)({}, _consts.defaultFronteggRoutes, routes),
135
199
  authRoutes = (0, _objectWithoutPropertiesLoose2.default)(_defaultFronteggRoute, _excluded2);
@@ -3,10 +3,14 @@
3
3
  Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
- exports.isFronteggApiError = exports.isError = exports.errorHandler = void 0;
6
+ exports.isSsoEnforcementError = exports.isFronteggApiError = exports.isError = exports.errorHandler = void 0;
7
7
  var _restApi = require("@frontegg/rest-api");
8
8
  const isFronteggApiError = error => Boolean(error == null ? void 0 : error.statusCode);
9
+
10
+ // ER-01079 (disabled user / expired tenant) is not this: it still logs out
9
11
  exports.isFronteggApiError = isFronteggApiError;
12
+ const isSsoEnforcementError = error => isFronteggApiError(error) && error.errorCode === _restApi.SSO_REQUIRED_FOR_TENANT_ERROR_CODE;
13
+ exports.isSsoEnforcementError = isSsoEnforcementError;
10
14
  const isError = error => {
11
15
  if (error instanceof Error) {
12
16
  return true;
package/node/index.js CHANGED
@@ -1,4 +1,4 @@
1
- /** @license Frontegg v7.130.0
1
+ /** @license Frontegg v7.131.0-alpha.1
2
2
  *
3
3
  * This source code is licensed under the MIT license found in the
4
4
  * LICENSE file in the root directory of this source tree.
package/package.json CHANGED
@@ -1,13 +1,13 @@
1
1
  {
2
2
  "name": "@frontegg/redux-store",
3
- "version": "7.130.0",
3
+ "version": "7.131.0-alpha.1",
4
4
  "main": "./node/index.js",
5
5
  "license": "MIT",
6
6
  "author": "Frontegg LTD",
7
7
  "dependencies": {
8
8
  "@babel/runtime": "^7.18.6",
9
9
  "@frontegg/entitlements-javascript-commons": "1.1.2",
10
- "@frontegg/rest-api": "7.130.0",
10
+ "@frontegg/rest-api": "7.131.0-alpha.1",
11
11
  "fast-deep-equal": "3.1.3",
12
12
  "get-value": "^3.0.1",
13
13
  "proxy-compare": "^3.0.0",