@frontegg/redux-store 6.124.0 → 6.125.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.
@@ -17,23 +17,14 @@ export declare function handleFetchedEntitlements(newEntitlementsResponse: UserE
17
17
  payload: Partial<UserEntitlementsResponse>;
18
18
  type: string;
19
19
  }>, void, UserEntitlementsResponse>;
20
- /**
21
- * Load entitlements data (exposed by frontegg app)
22
- * Don't update entitlements data in the store when data is equal (deep check) to the existing store data
23
- * @param callback called on request completed with true if succeeded, false if failed
24
- */
25
- export declare function loadEntitlementsOnDemand(callback?: LoadEntitlementsActionPayload['callback']): Generator<Generator<import("redux-saga/effects").SelectEffect | import("redux-saga/effects").PutEffect<{
26
- payload: Partial<UserEntitlementsResponse>;
27
- type: string;
28
- }>, void, UserEntitlementsResponse> | import("redux-saga/effects").CallEffect<UserEntitlementsResponse>, void, UserEntitlementsResponse>;
29
20
  /**
30
21
  * Load entitlements data for saga action
31
22
  * Don't update entitlements data in the store when data is equal (deep check) to the existing store data
32
23
  * @param payloadAction saga payload action including a payload with/out a callback
33
24
  * The callback will be called on request completed with true if succeeded, false if failed
34
25
  */
35
- export declare function loadEntitlements({ payload }: PayloadAction<LoadEntitlementsActionPayload>): Generator<Generator<Generator<import("redux-saga/effects").SelectEffect | import("redux-saga/effects").PutEffect<{
26
+ export declare function loadEntitlements({ payload }: PayloadAction<LoadEntitlementsActionPayload>): Generator<Generator<import("redux-saga/effects").SelectEffect | import("redux-saga/effects").PutEffect<{
36
27
  payload: Partial<UserEntitlementsResponse>;
37
28
  type: string;
38
- }>, void, UserEntitlementsResponse> | import("redux-saga/effects").CallEffect<UserEntitlementsResponse>, void, UserEntitlementsResponse>, void, unknown>;
29
+ }>, void, UserEntitlementsResponse> | import("redux-saga/effects").CallEffect<UserEntitlementsResponse>, void, UserEntitlementsResponse>;
39
30
  export declare function entitlementsSagas(): Generator<import("redux-saga/effects").ForkEffect<never>, void, unknown>;
@@ -29,11 +29,15 @@ export function* handleFetchedEntitlements(newEntitlementsResponse) {
29
29
  }
30
30
 
31
31
  /**
32
- * Load entitlements data (exposed by frontegg app)
32
+ * Load entitlements data for saga action
33
33
  * Don't update entitlements data in the store when data is equal (deep check) to the existing store data
34
- * @param callback called on request completed with true if succeeded, false if failed
34
+ * @param payloadAction saga payload action including a payload with/out a callback
35
+ * The callback will be called on request completed with true if succeeded, false if failed
35
36
  */
36
- export function* loadEntitlementsOnDemand(callback) {
37
+ export function* loadEntitlements({
38
+ payload
39
+ }) {
40
+ const callback = payload == null ? void 0 : payload.callback;
37
41
  try {
38
42
  const entitlements = yield call(api.entitlements.loadEntitlements);
39
43
  yield handleFetchedEntitlements(entitlements);
@@ -42,18 +46,6 @@ export function* loadEntitlementsOnDemand(callback) {
42
46
  callback == null ? void 0 : callback(false);
43
47
  } finally {}
44
48
  }
45
-
46
- /**
47
- * Load entitlements data for saga action
48
- * Don't update entitlements data in the store when data is equal (deep check) to the existing store data
49
- * @param payloadAction saga payload action including a payload with/out a callback
50
- * The callback will be called on request completed with true if succeeded, false if failed
51
- */
52
- export function* loadEntitlements({
53
- payload
54
- }) {
55
- yield loadEntitlementsOnDemand(payload == null ? void 0 : payload.callback);
56
- }
57
49
  export function* entitlementsSagas() {
58
50
  yield takeLeading(actions.loadEntitlements, loadEntitlements);
59
51
  }
@@ -7,7 +7,7 @@ export declare function afterAuthenticationStateUpdate({ user, tenants, activeTe
7
7
  payload: Partial<AuthState>;
8
8
  type: string;
9
9
  }>, void, AuthState>;
10
- export declare function afterAuthNavigation(): Generator<Promise<unknown> | import("redux-saga/effects").SelectEffect | CallEffect<void>, void, {
10
+ export declare function afterAuthNavigation(): Generator<import("redux-saga/effects").SelectEffect | Promise<unknown> | CallEffect<void>, void, {
11
11
  routes: any;
12
12
  includeQueryParam: any;
13
13
  enforceRedirectToSameSite?: false | undefined;
@@ -460,13 +460,20 @@ function* loadCustomLoginRoutes() {
460
460
  try {
461
461
  var _ContextHolder$getCon3, _ContextHolder$getCon4;
462
462
  if ((_ContextHolder$getCon3 = ContextHolder.getContext()) != null && (_ContextHolder$getCon4 = _ContextHolder$getCon3.tenantResolver) != null && _ContextHolder$getCon4.call(_ContextHolder$getCon3)) {
463
+ const {
464
+ getSettings,
465
+ getPublicSettings
466
+ } = api.accountSettings;
467
+ const isAuthenticated = yield select(({
468
+ auth
469
+ }) => auth.isAuthenticated);
463
470
  const {
464
471
  routes
465
472
  } = yield select(state => state.auth);
466
473
  const {
467
474
  applicationUrl,
468
475
  loginUrl
469
- } = yield call(api.accountSettings.getPublicSettings);
476
+ } = yield call(isAuthenticated ? getSettings : getPublicSettings);
470
477
  if (applicationUrl && loginUrl) {
471
478
  var _getSearchParamsFromU;
472
479
  const searchParams = (_getSearchParamsFromU = getSearchParamsFromUrl(applicationUrl)) != null ? _getSearchParamsFromU : '';
@@ -483,7 +490,19 @@ function* loadCustomLoginRoutes() {
483
490
  function* requestAuthorize({
484
491
  payload: firstTime
485
492
  }) {
493
+ var _ContextHolder$getCon5;
486
494
  const calls = [];
495
+ const hasTenantResolver = !!((_ContextHolder$getCon5 = ContextHolder.getContext()) != null && _ContextHolder$getCon5.tenantResolver);
496
+ if (hasTenantResolver) {
497
+ /*
498
+ // waiting for refreshToken to be loaded is only necessary for custom login
499
+ // but doing this will degrade the loading performance in around 500 ms
500
+ // so we will wait for the refreshToken only if there is tenantResolver
501
+ */
502
+ yield call(refreshToken);
503
+ } else {
504
+ calls.push(call(refreshToken));
505
+ }
487
506
  if (firstTime) {
488
507
  yield put(actions.setState({
489
508
  isLoading: true
@@ -496,7 +515,6 @@ function* requestAuthorize({
496
515
  calls.push(call(refreshMetadata));
497
516
  calls.push(call(loadCustomLoginRoutes));
498
517
  }
499
- calls.push(call(refreshToken));
500
518
  yield all(calls);
501
519
  yield put(actions.setState({
502
520
  isLoading: false
@@ -582,8 +600,8 @@ function* refreshOrRequestHostedLoginAuthorize({
582
600
  }
583
601
  function* getCustomLoginSearchParam() {
584
602
  try {
585
- var _ContextHolder$getCon5, _ContextHolder$getCon6;
586
- if ((_ContextHolder$getCon5 = ContextHolder.getContext()) != null && (_ContextHolder$getCon6 = _ContextHolder$getCon5.tenantResolver) != null && _ContextHolder$getCon6.call(_ContextHolder$getCon5)) {
603
+ var _ContextHolder$getCon6, _ContextHolder$getCon7;
604
+ if ((_ContextHolder$getCon6 = ContextHolder.getContext()) != null && (_ContextHolder$getCon7 = _ContextHolder$getCon6.tenantResolver) != null && _ContextHolder$getCon7.call(_ContextHolder$getCon6)) {
587
605
  yield call(loadCustomLoginRoutes);
588
606
  const customLoginAuthenticatedUrl = yield select(state => state.auth.routes.customLoginAuthenticatedUrl);
589
607
  if (customLoginAuthenticatedUrl) {
@@ -1,11 +1,12 @@
1
1
  import { IVendorConfig } from '@frontegg/rest-api';
2
2
  import { IAuthStrategiesConfig } from '@frontegg/rest-api';
3
- export declare function loadPublicSecurityPolicy(): Generator<import("redux-saga/effects").CallEffect<IVendorConfig> | import("redux-saga/effects").CallEffect<IAuthStrategiesConfig> | import("redux-saga/effects").CallEffect<boolean[]> | import("redux-saga/effects").PutEffect<{
3
+ export declare function loadPublicSecurityPolicy(): Generator<import("redux-saga/effects").PutEffect<{
4
4
  payload: Partial<import("../../interfaces").WithStatus & {
5
5
  policy?: IVendorConfig | undefined;
6
6
  }>;
7
7
  type: string;
8
- }>, void, IVendorConfig & boolean[] & IAuthStrategiesConfig>;
8
+ }> | import("redux-saga/effects").CallEffect<IVendorConfig> | import("redux-saga/effects").CallEffect<boolean[]> | import("redux-saga/effects").CallEffect<IAuthStrategiesConfig>, void, IVendorConfig & boolean[] & IAuthStrategiesConfig>;
9
+ export declare function getAuthStrategy(): Generator<import("redux-saga/effects").SelectEffect | import("redux-saga/effects").CallEffect<IAuthStrategiesConfig>, IAuthStrategiesConfig, (false & IAuthStrategiesConfig) | (true & IAuthStrategiesConfig)>;
9
10
  export declare function loadPublicAuthStrategiesPolicy(): Generator<import("redux-saga/effects").CallEffect<IAuthStrategiesConfig> | import("redux-saga/effects").PutEffect<{
10
11
  payload: Partial<import("../../interfaces").WithStatus & {
11
12
  policy?: IAuthStrategiesConfig | undefined;
@@ -6,7 +6,7 @@ const _excluded = ["callback"],
6
6
  _excluded4 = ["callback"],
7
7
  _excluded5 = ["callback"],
8
8
  _excluded6 = ["callback"];
9
- import { call, put, takeEvery, takeLeading } from 'redux-saga/effects';
9
+ import { call, put, select, takeEvery, takeLeading } from 'redux-saga/effects';
10
10
  import { api } from '@frontegg/rest-api';
11
11
  import { actions } from '../reducer';
12
12
  import { delay } from '../utils';
@@ -63,13 +63,25 @@ export function* loadPublicSecurityPolicy() {
63
63
  }));
64
64
  }
65
65
  }
66
+ export function* getAuthStrategy() {
67
+ const isAuthenticated = yield select(({
68
+ auth
69
+ }) => auth.isAuthenticated);
70
+ let policy;
71
+ if (isAuthenticated) {
72
+ policy = yield call(api.auth.getPublicAuthStrategiesConfigForAuthenticatedUser);
73
+ } else {
74
+ policy = yield call(api.auth.getVendorPublicAuthStrategiesConfig);
75
+ }
76
+ return policy;
77
+ }
66
78
  export function* loadPublicAuthStrategiesPolicy() {
67
79
  yield put(actions.setSecurityPolicyAuthStrategyPublicState({
68
80
  loading: true,
69
81
  error: null
70
82
  }));
71
83
  try {
72
- const policy = yield call(api.auth.getVendorPublicAuthStrategiesConfig);
84
+ const policy = yield call(getAuthStrategy);
73
85
  yield put(actions.setSecurityPolicyAuthStrategyPublicState({
74
86
  policy,
75
87
  loading: false
@@ -3,18 +3,18 @@ import { IAuthStrategiesConfig, ISignUpResponse, IVendorConfig } from '@frontegg
3
3
  import { ISignUpUserPayload } from './interfaces';
4
4
  import { AuthState } from '../interfaces';
5
5
  export declare function loadAllowSignUps(): Generator<import("redux-saga/effects").PutEffect<{
6
- payload: Partial<import("./interfaces").SignUpState>;
7
- type: string;
8
- }> | import("redux-saga/effects").CallEffect<IVendorConfig> | import("redux-saga/effects").CallEffect<IAuthStrategiesConfig> | import("redux-saga/effects").CallEffect<boolean[]> | import("redux-saga/effects").PutEffect<{
9
6
  payload: Partial<import("../../interfaces").WithStatus & {
10
7
  policy?: IVendorConfig | undefined;
11
8
  }>;
12
9
  type: string;
13
- }>, void, IVendorConfig & IAuthStrategiesConfig & boolean[]>;
14
- export declare function signUpUser({ payload: { events, url, ...payload } }: PayloadAction<ISignUpUserPayload>): Generator<import("redux-saga/effects").PutEffect<{
10
+ }> | import("redux-saga/effects").CallEffect<IVendorConfig> | import("redux-saga/effects").CallEffect<boolean[]> | import("redux-saga/effects").CallEffect<IAuthStrategiesConfig> | import("redux-saga/effects").PutEffect<{
15
11
  payload: Partial<import("./interfaces").SignUpState>;
16
12
  type: string;
17
- }> | import("redux-saga/effects").SelectEffect | import("redux-saga/effects").CallEffect<ISignUpResponse> | Generator<import("redux-saga/effects").SelectEffect | import("redux-saga/effects").CallEffect<import("@frontegg/rest-api").IAllowedToRememberMfaDevice>, {
13
+ }>, void, IVendorConfig & boolean[] & IAuthStrategiesConfig>;
14
+ export declare function signUpUser({ payload: { events, url, ...payload } }: PayloadAction<ISignUpUserPayload>): Generator<import("redux-saga/effects").SelectEffect | import("redux-saga/effects").PutEffect<{
15
+ payload: Partial<import("./interfaces").SignUpState>;
16
+ type: string;
17
+ }> | import("redux-saga/effects").CallEffect<ISignUpResponse> | Generator<import("redux-saga/effects").SelectEffect | import("redux-saga/effects").CallEffect<import("@frontegg/rest-api").IAllowedToRememberMfaDevice>, {
18
18
  user: undefined;
19
19
  isAuthenticated: boolean;
20
20
  mfaState: Partial<import("..").MFAState>;
@@ -49,12 +49,12 @@ export declare function signUpUser({ payload: { events, url, ...payload } }: Pay
49
49
  routes: any;
50
50
  onRedirectTo: any;
51
51
  } & ISignUpResponse & Partial<AuthState> & AuthState>;
52
- export declare function resetSignUpStateSoft(): Generator<import("redux-saga/effects").PutEffect<{
53
- payload: Partial<import("./interfaces").SignUpState>;
54
- type: string;
55
- }> | import("redux-saga/effects").SelectEffect | import("redux-saga/effects").PutEffect<{
52
+ export declare function resetSignUpStateSoft(): Generator<import("redux-saga/effects").SelectEffect | import("redux-saga/effects").PutEffect<{
56
53
  payload: undefined;
57
54
  type: string;
55
+ }> | import("redux-saga/effects").PutEffect<{
56
+ payload: Partial<import("./interfaces").SignUpState>;
57
+ type: string;
58
58
  }>, void, {
59
59
  allowSignUps: any;
60
60
  allowNotVerifiedUsersLogin: any;
@@ -10,16 +10,16 @@ import { getMfaRequiredState } from '../LoginState/saga';
10
10
  import { getFeatureFlags } from '../../helpers';
11
11
  import { errorHandler } from '../../utils';
12
12
  import { isMfaRequired } from '../LoginState/utils';
13
+ import { getAuthStrategy } from '../SecurityPolicyState/saga';
13
14
  export function* loadAllowSignUps() {
14
15
  yield put(actions.setSignUpState({
15
16
  loading: true
16
17
  }));
17
18
  try {
18
19
  const policy = yield call(api.auth.getVendorConfig);
19
- const authStrategies = yield call(api.auth.getVendorPublicAuthStrategiesConfig);
20
20
  const [withLoginPerTenant] = yield call(getFeatureFlags, ['admin_portal_login_per_tenant']);
21
21
  if (withLoginPerTenant) {
22
- const authStrategies = yield call(api.auth.getVendorPublicAuthStrategiesConfig);
22
+ const authStrategies = yield call(getAuthStrategy);
23
23
  if (authStrategies.mainAuthStrategies.length > 0) {
24
24
  policy.authStrategy = authStrategies.mainAuthStrategies[0].strategy;
25
25
  }
@@ -3,6 +3,7 @@ export declare function loadSocialLoginsConfigurations(): Generator<import("redu
3
3
  payload: Partial<import("./interfaces").SocialLoginState>;
4
4
  type: string;
5
5
  }> | import("redux-saga/effects").CallEffect<ISocialLoginProviderConfiguration[]>, void, ISocialLoginProviderConfiguration[]>;
6
+ export declare function getSocialLoginsConfigurationsV2(): Generator<import("redux-saga/effects").SelectEffect | import("redux-saga/effects").CallEffect<ISocialLoginProviderConfigurationV2[]>, ISocialLoginProviderConfigurationV2[], (false & ISocialLoginProviderConfigurationV2[]) | (true & ISocialLoginProviderConfigurationV2[])>;
6
7
  export declare function loadSocialLoginsConfigurationsV2(): Generator<import("redux-saga/effects").SelectEffect | import("redux-saga/effects").PutEffect<{
7
8
  payload: Partial<import("./interfaces").SocialLoginState>;
8
9
  type: string;
@@ -28,13 +28,25 @@ export function* loadSocialLoginsConfigurations() {
28
28
  }));
29
29
  }
30
30
  }
31
+ export function* getSocialLoginsConfigurationsV2() {
32
+ const isAuthenticated = yield select(({
33
+ auth
34
+ }) => auth.isAuthenticated);
35
+ let socialLoginsConfigV2;
36
+ if (isAuthenticated) {
37
+ socialLoginsConfigV2 = yield call(api.auth.getSocialLoginProvidersV2ForAuthenticatedUser);
38
+ } else {
39
+ socialLoginsConfigV2 = yield call(api.auth.getSocialLoginProvidersV2);
40
+ }
41
+ return socialLoginsConfigV2;
42
+ }
31
43
  export function* loadSocialLoginsConfigurationsV2() {
32
44
  try {
33
45
  const context = yield select(state => state.root.context);
34
46
  yield put(actions.setSocialLoginsState({
35
47
  loading: true
36
48
  }));
37
- const socialLoginsConfigV2 = yield call(api.auth.getSocialLoginProvidersV2);
49
+ const socialLoginsConfigV2 = yield call(getSocialLoginsConfigurationsV2);
38
50
  const {
39
51
  providers: customSocialLoginsConfig
40
52
  } = yield call(api.auth.getCustomSocialLoginProvidersV1);
@@ -0,0 +1,28 @@
1
+ import { RootState } from './toolkit/interfaces';
2
+ import { AuthState } from './auth/interfaces';
3
+ import { AuditsState } from './audits/interfaces';
4
+ import { IConnectivityState } from './connectivity/interfaces';
5
+ import { SubscriptionsState } from './subscriptions/interfaces';
6
+ import { VendorState } from './vendor/interfaces';
7
+ import { OldAuditsState } from './audits/backward-compatibility';
8
+ import { Unsubscribe } from '@reduxjs/toolkit';
9
+ export declare type FronteggState = {
10
+ root: RootState;
11
+ auth: AuthState;
12
+ auditLogs: AuditsState;
13
+ audits: OldAuditsState;
14
+ connectivity: IConnectivityState;
15
+ subscriptions: SubscriptionsState;
16
+ vendor: VendorState;
17
+ /**
18
+ * Using redux store subscribe causes unpredictable callback calls: https://redux.js.org/api/store#subscribelistener
19
+ *
20
+ * This function aim to prevent unnecessary update by calling the callback with the updated frontegg state only on state reference change.
21
+ * This function protect from redux unnecessary updates by reference comparison
22
+ * Developed for vanilla js SDK
23
+ *
24
+ * @param callback called with the updated frontegg state for every store refresh
25
+ * @returns redux unsubscribe function
26
+ */
27
+ subscribeStateChanged: (callback: (state: FronteggState) => void) => Unsubscribe;
28
+ };
@@ -0,0 +1 @@
1
+ export {};
package/index.d.ts CHANGED
@@ -1,10 +1,3 @@
1
- import { RootState } from './toolkit';
2
- import { AuthState } from './auth/interfaces';
3
- import { AuditsState } from './audits/interfaces';
4
- import { IConnectivityState } from './connectivity/interfaces';
5
- import { SubscriptionsState } from './subscriptions/interfaces';
6
- import { VendorState } from './vendor/interfaces';
7
- import { OldAuditsState } from './audits/backward-compatibility';
8
1
  export { default as auth } from './auth';
9
2
  export { default as audits } from './audits';
10
3
  export { default as connectivity } from './connectivity';
@@ -21,12 +14,4 @@ export * from './helpers';
21
14
  export * from './utils';
22
15
  export type { WithCallback, WithSilentLoad, CallbackMethod } from './interfaces';
23
16
  export type { NotEntitledReason } from '@frontegg/rest-api';
24
- export declare type FronteggState = {
25
- root: RootState;
26
- auth: AuthState;
27
- auditLogs: AuditsState;
28
- audits: OldAuditsState;
29
- connectivity: IConnectivityState;
30
- subscriptions: SubscriptionsState;
31
- vendor: VendorState;
32
- };
17
+ export type { FronteggState } from './fronteggState';
package/index.js CHANGED
@@ -1,4 +1,4 @@
1
- /** @license Frontegg v6.124.0
1
+ /** @license Frontegg v6.125.0
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.
@@ -8,7 +8,6 @@ exports.entitlementsSagas = entitlementsSagas;
8
8
  exports.handleFetchedEntitlements = handleFetchedEntitlements;
9
9
  exports.isEntitlementsChanged = isEntitlementsChanged;
10
10
  exports.loadEntitlements = loadEntitlements;
11
- exports.loadEntitlementsOnDemand = loadEntitlementsOnDemand;
12
11
  var _fastDeepEqual = _interopRequireDefault(require("fast-deep-equal"));
13
12
  var _effects = require("redux-saga/effects");
14
13
  var _restApi = require("@frontegg/rest-api");
@@ -40,11 +39,15 @@ function* handleFetchedEntitlements(newEntitlementsResponse) {
40
39
  }
41
40
 
42
41
  /**
43
- * Load entitlements data (exposed by frontegg app)
42
+ * Load entitlements data for saga action
44
43
  * Don't update entitlements data in the store when data is equal (deep check) to the existing store data
45
- * @param callback called on request completed with true if succeeded, false if failed
44
+ * @param payloadAction saga payload action including a payload with/out a callback
45
+ * The callback will be called on request completed with true if succeeded, false if failed
46
46
  */
47
- function* loadEntitlementsOnDemand(callback) {
47
+ function* loadEntitlements({
48
+ payload
49
+ }) {
50
+ const callback = payload == null ? void 0 : payload.callback;
48
51
  try {
49
52
  const entitlements = yield (0, _effects.call)(_restApi.api.entitlements.loadEntitlements);
50
53
  yield handleFetchedEntitlements(entitlements);
@@ -53,18 +56,6 @@ function* loadEntitlementsOnDemand(callback) {
53
56
  callback == null ? void 0 : callback(false);
54
57
  } finally {}
55
58
  }
56
-
57
- /**
58
- * Load entitlements data for saga action
59
- * Don't update entitlements data in the store when data is equal (deep check) to the existing store data
60
- * @param payloadAction saga payload action including a payload with/out a callback
61
- * The callback will be called on request completed with true if succeeded, false if failed
62
- */
63
- function* loadEntitlements({
64
- payload
65
- }) {
66
- yield loadEntitlementsOnDemand(payload == null ? void 0 : payload.callback);
67
- }
68
59
  function* entitlementsSagas() {
69
60
  yield (0, _effects.takeLeading)(_reducer.actions.loadEntitlements, loadEntitlements);
70
61
  }
@@ -475,13 +475,20 @@ function* loadCustomLoginRoutes() {
475
475
  try {
476
476
  var _ContextHolder$getCon3, _ContextHolder$getCon4;
477
477
  if ((_ContextHolder$getCon3 = _restApi.ContextHolder.getContext()) != null && (_ContextHolder$getCon4 = _ContextHolder$getCon3.tenantResolver) != null && _ContextHolder$getCon4.call(_ContextHolder$getCon3)) {
478
+ const {
479
+ getSettings,
480
+ getPublicSettings
481
+ } = _restApi.api.accountSettings;
482
+ const isAuthenticated = yield (0, _effects.select)(({
483
+ auth
484
+ }) => auth.isAuthenticated);
478
485
  const {
479
486
  routes
480
487
  } = yield (0, _effects.select)(state => state.auth);
481
488
  const {
482
489
  applicationUrl,
483
490
  loginUrl
484
- } = yield (0, _effects.call)(_restApi.api.accountSettings.getPublicSettings);
491
+ } = yield (0, _effects.call)(isAuthenticated ? getSettings : getPublicSettings);
485
492
  if (applicationUrl && loginUrl) {
486
493
  var _getSearchParamsFromU;
487
494
  const searchParams = (_getSearchParamsFromU = (0, _utils2.getSearchParamsFromUrl)(applicationUrl)) != null ? _getSearchParamsFromU : '';
@@ -498,7 +505,19 @@ function* loadCustomLoginRoutes() {
498
505
  function* requestAuthorize({
499
506
  payload: firstTime
500
507
  }) {
508
+ var _ContextHolder$getCon5;
501
509
  const calls = [];
510
+ const hasTenantResolver = !!((_ContextHolder$getCon5 = _restApi.ContextHolder.getContext()) != null && _ContextHolder$getCon5.tenantResolver);
511
+ if (hasTenantResolver) {
512
+ /*
513
+ // waiting for refreshToken to be loaded is only necessary for custom login
514
+ // but doing this will degrade the loading performance in around 500 ms
515
+ // so we will wait for the refreshToken only if there is tenantResolver
516
+ */
517
+ yield (0, _effects.call)(refreshToken);
518
+ } else {
519
+ calls.push((0, _effects.call)(refreshToken));
520
+ }
502
521
  if (firstTime) {
503
522
  yield (0, _effects.put)(_reducer.actions.setState({
504
523
  isLoading: true
@@ -511,7 +530,6 @@ function* requestAuthorize({
511
530
  calls.push((0, _effects.call)(refreshMetadata));
512
531
  calls.push((0, _effects.call)(loadCustomLoginRoutes));
513
532
  }
514
- calls.push((0, _effects.call)(refreshToken));
515
533
  yield (0, _effects.all)(calls);
516
534
  yield (0, _effects.put)(_reducer.actions.setState({
517
535
  isLoading: false
@@ -597,8 +615,8 @@ function* refreshOrRequestHostedLoginAuthorize({
597
615
  }
598
616
  function* getCustomLoginSearchParam() {
599
617
  try {
600
- var _ContextHolder$getCon5, _ContextHolder$getCon6;
601
- if ((_ContextHolder$getCon5 = _restApi.ContextHolder.getContext()) != null && (_ContextHolder$getCon6 = _ContextHolder$getCon5.tenantResolver) != null && _ContextHolder$getCon6.call(_ContextHolder$getCon5)) {
618
+ var _ContextHolder$getCon6, _ContextHolder$getCon7;
619
+ if ((_ContextHolder$getCon6 = _restApi.ContextHolder.getContext()) != null && (_ContextHolder$getCon7 = _ContextHolder$getCon6.tenantResolver) != null && _ContextHolder$getCon7.call(_ContextHolder$getCon6)) {
602
620
  yield (0, _effects.call)(loadCustomLoginRoutes);
603
621
  const customLoginAuthenticatedUrl = yield (0, _effects.select)(state => state.auth.routes.customLoginAuthenticatedUrl);
604
622
  if (customLoginAuthenticatedUrl) {
@@ -4,6 +4,7 @@ var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefau
4
4
  Object.defineProperty(exports, "__esModule", {
5
5
  value: true
6
6
  });
7
+ exports.getAuthStrategy = getAuthStrategy;
7
8
  exports.loadPublicAuthStrategiesPolicy = loadPublicAuthStrategiesPolicy;
8
9
  exports.loadPublicSecurityPolicy = loadPublicSecurityPolicy;
9
10
  exports.loadPublicSecurityPolicyMock = loadPublicSecurityPolicyMock;
@@ -74,13 +75,25 @@ function* loadPublicSecurityPolicy() {
74
75
  }));
75
76
  }
76
77
  }
78
+ function* getAuthStrategy() {
79
+ const isAuthenticated = yield (0, _effects.select)(({
80
+ auth
81
+ }) => auth.isAuthenticated);
82
+ let policy;
83
+ if (isAuthenticated) {
84
+ policy = yield (0, _effects.call)(_restApi.api.auth.getPublicAuthStrategiesConfigForAuthenticatedUser);
85
+ } else {
86
+ policy = yield (0, _effects.call)(_restApi.api.auth.getVendorPublicAuthStrategiesConfig);
87
+ }
88
+ return policy;
89
+ }
77
90
  function* loadPublicAuthStrategiesPolicy() {
78
91
  yield (0, _effects.put)(_reducer.actions.setSecurityPolicyAuthStrategyPublicState({
79
92
  loading: true,
80
93
  error: null
81
94
  }));
82
95
  try {
83
- const policy = yield (0, _effects.call)(_restApi.api.auth.getVendorPublicAuthStrategiesConfig);
96
+ const policy = yield (0, _effects.call)(getAuthStrategy);
84
97
  yield (0, _effects.put)(_reducer.actions.setSecurityPolicyAuthStrategyPublicState({
85
98
  policy,
86
99
  loading: false
@@ -19,6 +19,7 @@ var _saga = require("../LoginState/saga");
19
19
  var _helpers = require("../../helpers");
20
20
  var _utils = require("../../utils");
21
21
  var _utils2 = require("../LoginState/utils");
22
+ var _saga2 = require("../SecurityPolicyState/saga");
22
23
  const _excluded = ["events", "url"];
23
24
  function* loadAllowSignUps() {
24
25
  yield (0, _effects.put)(_reducer.actions.setSignUpState({
@@ -26,10 +27,9 @@ function* loadAllowSignUps() {
26
27
  }));
27
28
  try {
28
29
  const policy = yield (0, _effects.call)(_restApi.api.auth.getVendorConfig);
29
- const authStrategies = yield (0, _effects.call)(_restApi.api.auth.getVendorPublicAuthStrategiesConfig);
30
30
  const [withLoginPerTenant] = yield (0, _effects.call)(_helpers.getFeatureFlags, ['admin_portal_login_per_tenant']);
31
31
  if (withLoginPerTenant) {
32
- const authStrategies = yield (0, _effects.call)(_restApi.api.auth.getVendorPublicAuthStrategiesConfig);
32
+ const authStrategies = yield (0, _effects.call)(_saga2.getAuthStrategy);
33
33
  if (authStrategies.mainAuthStrategies.length > 0) {
34
34
  policy.authStrategy = authStrategies.mainAuthStrategies[0].strategy;
35
35
  }
@@ -4,6 +4,7 @@ var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefau
4
4
  Object.defineProperty(exports, "__esModule", {
5
5
  value: true
6
6
  });
7
+ exports.getSocialLoginsConfigurationsV2 = getSocialLoginsConfigurationsV2;
7
8
  exports.loadSocialLoginsConfigurations = loadSocialLoginsConfigurations;
8
9
  exports.loadSocialLoginsConfigurationsV2 = loadSocialLoginsConfigurationsV2;
9
10
  exports.socialLoginsSaga = socialLoginsSaga;
@@ -37,13 +38,25 @@ function* loadSocialLoginsConfigurations() {
37
38
  }));
38
39
  }
39
40
  }
41
+ function* getSocialLoginsConfigurationsV2() {
42
+ const isAuthenticated = yield (0, _effects.select)(({
43
+ auth
44
+ }) => auth.isAuthenticated);
45
+ let socialLoginsConfigV2;
46
+ if (isAuthenticated) {
47
+ socialLoginsConfigV2 = yield (0, _effects.call)(_restApi.api.auth.getSocialLoginProvidersV2ForAuthenticatedUser);
48
+ } else {
49
+ socialLoginsConfigV2 = yield (0, _effects.call)(_restApi.api.auth.getSocialLoginProvidersV2);
50
+ }
51
+ return socialLoginsConfigV2;
52
+ }
40
53
  function* loadSocialLoginsConfigurationsV2() {
41
54
  try {
42
55
  const context = yield (0, _effects.select)(state => state.root.context);
43
56
  yield (0, _effects.put)(_reducer.actions.setSocialLoginsState({
44
57
  loading: true
45
58
  }));
46
- const socialLoginsConfigV2 = yield (0, _effects.call)(_restApi.api.auth.getSocialLoginProvidersV2);
59
+ const socialLoginsConfigV2 = yield (0, _effects.call)(getSocialLoginsConfigurationsV2);
47
60
  const {
48
61
  providers: customSocialLoginsConfig
49
62
  } = yield (0, _effects.call)(_restApi.api.auth.getCustomSocialLoginProvidersV1);
@@ -0,0 +1,5 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
package/node/index.js CHANGED
@@ -1,4 +1,4 @@
1
- /** @license Frontegg v6.124.0
1
+ /** @license Frontegg v6.125.0
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.
@@ -140,6 +140,27 @@ const createFronteggStore = (rootInitialState, storeHolder, previewMode = false,
140
140
  } else {
141
141
  holder.store.destroy = sagaMiddleware.run(rootSaga).cancel;
142
142
  }
143
+
144
+ /**
145
+ * Using redux store subscribe causes unpredictable callback calls: https://redux.js.org/api/store#subscribelistener
146
+ *
147
+ * This function aim to prevent unnecessary update by calling the callback with the updated frontegg state only on state reference change.
148
+ * This function protect from redux unnecessary updates by reference comparison
149
+ * Developed for vanilla js SDK
150
+ *
151
+ * @param callback called with the updated frontegg state for every store refresh
152
+ * @returns redux unsubscribe function
153
+ */
154
+ holder.store.subscribeStateChanged = callback => {
155
+ let lastStoreState = holder.store.getState();
156
+ return holder.store.subscribe(() => {
157
+ const updatedState = holder.store.getState();
158
+ if (lastStoreState != updatedState) {
159
+ lastStoreState = updatedState;
160
+ callback(updatedState);
161
+ }
162
+ });
163
+ };
143
164
  }
144
165
  return holder.store;
145
166
  };
@@ -0,0 +1,5 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@frontegg/redux-store",
3
- "version": "6.124.0",
3
+ "version": "6.125.0",
4
4
  "main": "./node/index.js",
5
5
  "license": "MIT",
6
6
  "author": "Frontegg LTD",
@@ -11,13 +11,8 @@ declare type InitialState = {
11
11
  };
12
12
  export { bindActionCreators } from '@reduxjs/toolkit';
13
13
  export type { CaseReducerActions, SliceCaseReducers } from '@reduxjs/toolkit';
14
- export interface RootState {
15
- context?: ContextOptions;
16
- urlStrategy: 'hash' | 'path';
17
- previewMode?: boolean;
18
- appName: string;
19
- }
20
- export declare const createFronteggStore: (rootInitialState: InitialState, storeHolder?: any, previewMode?: boolean, authInitialState?: (Partial<Pick<AuthState, "user" | "error" | "onRedirectTo" | "isAuthenticated" | "userIp" | "isLoading" | "keepSessionAlive" | "isSSOAuth" | "ssoACS" | "includeQueryParam" | "loginState" | "activateState" | "acceptInvitationState" | "forgotPasswordState" | "resetPhoneNumberState" | "ssoState" | "profileState" | "mfaState" | "teamState" | "groupsState" | "groupsDialogsState" | "socialLoginState" | "signUpState" | "apiTokensState" | "securityPolicyState" | "restrictionsState" | "provisioningState" | "accountSettingsState" | "tenantsState" | "rolesState" | "sessionsState" | "hostedLoginBox" | "disableSilentRefresh" | "sessionsPolicyState" | "impersonateState" | "passkeysState" | "customLoginState" | "allAccountsState" | "allAccountsDialogsState" | "securityCenterState" | "header" | "loaderComponent">> & {
14
+ export type { RootState } from './interfaces';
15
+ export declare const createFronteggStore: (rootInitialState: InitialState, storeHolder?: any, previewMode?: boolean, authInitialState?: (Partial<Pick<AuthState, "user" | "error" | "isLoading" | "onRedirectTo" | "isAuthenticated" | "userIp" | "keepSessionAlive" | "isSSOAuth" | "ssoACS" | "includeQueryParam" | "loginState" | "activateState" | "acceptInvitationState" | "forgotPasswordState" | "resetPhoneNumberState" | "ssoState" | "profileState" | "mfaState" | "teamState" | "groupsState" | "groupsDialogsState" | "socialLoginState" | "signUpState" | "apiTokensState" | "securityPolicyState" | "restrictionsState" | "provisioningState" | "accountSettingsState" | "tenantsState" | "rolesState" | "sessionsState" | "hostedLoginBox" | "disableSilentRefresh" | "sessionsPolicyState" | "impersonateState" | "passkeysState" | "customLoginState" | "allAccountsState" | "allAccountsDialogsState" | "securityCenterState" | "header" | "loaderComponent">> & {
21
16
  routes?: Partial<AuthPageRoutes> | undefined;
22
17
  }) | undefined, overrideInitialState?: Partial<{
23
18
  auth: Partial<Omit<AuthState, 'routes'>> & {
package/toolkit/index.js CHANGED
@@ -102,6 +102,27 @@ export const createFronteggStore = (rootInitialState, storeHolder, previewMode =
102
102
  } else {
103
103
  holder.store.destroy = sagaMiddleware.run(rootSaga).cancel;
104
104
  }
105
+
106
+ /**
107
+ * Using redux store subscribe causes unpredictable callback calls: https://redux.js.org/api/store#subscribelistener
108
+ *
109
+ * This function aim to prevent unnecessary update by calling the callback with the updated frontegg state only on state reference change.
110
+ * This function protect from redux unnecessary updates by reference comparison
111
+ * Developed for vanilla js SDK
112
+ *
113
+ * @param callback called with the updated frontegg state for every store refresh
114
+ * @returns redux unsubscribe function
115
+ */
116
+ holder.store.subscribeStateChanged = callback => {
117
+ let lastStoreState = holder.store.getState();
118
+ return holder.store.subscribe(() => {
119
+ const updatedState = holder.store.getState();
120
+ if (lastStoreState != updatedState) {
121
+ lastStoreState = updatedState;
122
+ callback(updatedState);
123
+ }
124
+ });
125
+ };
105
126
  }
106
127
  return holder.store;
107
128
  };
@@ -0,0 +1,7 @@
1
+ import { ContextOptions } from '@frontegg/rest-api';
2
+ export interface RootState {
3
+ context?: ContextOptions;
4
+ urlStrategy: 'hash' | 'path';
5
+ previewMode?: boolean;
6
+ appName: string;
7
+ }
@@ -0,0 +1 @@
1
+ export {};