@frontegg/react-hooks 6.198.0-alpha.2 → 6.198.0-alpha.3

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.
@@ -93,7 +93,7 @@ const FronteggContent = ({
93
93
  });
94
94
  };
95
95
  export const FronteggStoreProvider = props => {
96
- var _app$options$contextO, _app$options3, _app$options$previewM, _app$options4, _app$options5, _app$options6, _app$name;
96
+ var _app$options$contextO, _app$options3, _app$options$previewM, _app$options4, _app$options5, _app$options6;
97
97
  const {
98
98
  children,
99
99
  app,
@@ -113,13 +113,12 @@ export const FronteggStoreProvider = props => {
113
113
  }) : {
114
114
  hostedLoginBox: app == null ? void 0 : (_app$options6 = app.options) == null ? void 0 : _app$options6.hostedLoginBox
115
115
  };
116
- const appName = (_app$name = app == null ? void 0 : app.name) != null ? _app$name : 'default';
117
- ContextHolder.for(appName).setContext(context);
116
+ ContextHolder.setContext(context);
118
117
  const store = useMemo(() => {
119
- var _app$options7;
118
+ var _app$name, _app$options7;
120
119
  return createFronteggStore({
121
120
  context,
122
- appName
121
+ appName: (_app$name = app == null ? void 0 : app.name) != null ? _app$name : 'default'
123
122
  }, app, previewMode, authOptions, undefined, false, app == null ? void 0 : (_app$options7 = app.options) == null ? void 0 : _app$options7.urlStrategy);
124
123
  }, [app, previewMode]);
125
124
  return /*#__PURE__*/_jsxs(Provider, {
@@ -1,7 +1,7 @@
1
1
  import { getPermissionEntitlements, getFeatureEntitlements, getEntitlements } from '@frontegg/redux-store';
2
2
  import { useAuth } from './hooks';
3
3
  import { useMemo } from 'react';
4
- import { useRootState, useShadowDom } from '../common';
4
+ import { useShadowDom } from '../common';
5
5
  import { useFeatureFlags } from '../flags';
6
6
 
7
7
  /**
@@ -45,10 +45,7 @@ export const useFeatureEntitlements = (key, customAttributes) => {
45
45
  entitlements,
46
46
  attributes
47
47
  } = useEntitlementsQueryData(customAttributes);
48
- const {
49
- appName
50
- } = useRootState();
51
- return getFeatureEntitlements(entitlements, key, attributes, undefined, appName);
48
+ return getFeatureEntitlements(entitlements, key, attributes);
52
49
  };
53
50
 
54
51
  /**
@@ -61,10 +58,7 @@ export const usePermissionEntitlements = (key, customAttributes) => {
61
58
  entitlements,
62
59
  attributes
63
60
  } = useEntitlementsQueryData(customAttributes);
64
- const {
65
- appName
66
- } = useRootState();
67
- return getPermissionEntitlements(entitlements, key, attributes, undefined, appName);
61
+ return getPermissionEntitlements(entitlements, key, attributes);
68
62
  };
69
63
 
70
64
  /**
@@ -77,10 +71,7 @@ export const useEntitlements = (options, customAttributes) => {
77
71
  entitlements,
78
72
  attributes
79
73
  } = useEntitlementsQueryData(customAttributes);
80
- const {
81
- appName
82
- } = useRootState();
83
- return getEntitlements(entitlements, options, attributes, undefined, appName);
74
+ return getEntitlements(entitlements, options, attributes);
84
75
  };
85
76
 
86
77
  /**
@@ -91,16 +82,13 @@ export const useEntitlementsActions = () => {
91
82
  // this code is duplicated because React is yelling when using useEntitlementsQueryData inside the isEntitledTo function because it's not a hook
92
83
  const user = useUserState();
93
84
  const entitlements = useEntitlementsState();
94
- const {
95
- appName
96
- } = useRootState();
97
85
  return useMemo(() => ({
98
86
  isEntitledTo: (options, customAttributes) => {
99
87
  const attributes = {
100
88
  custom: customAttributes,
101
89
  jwt: user
102
90
  };
103
- return getEntitlements(entitlements, options, attributes, undefined, appName);
91
+ return getEntitlements(entitlements, options, attributes);
104
92
  }
105
93
  }), [user, entitlements]);
106
94
  };
package/auth/hooks.js CHANGED
@@ -1,11 +1,11 @@
1
1
  import _extends from "@babel/runtime/helpers/esm/extends";
2
- import { useMemo } from 'react';
2
+ import { useContext, useMemo } from 'react';
3
3
  import { bindActionCreators } from '@frontegg/redux-store';
4
4
  import { authActions, authStoreName } from '@frontegg/redux-store';
5
5
  import { shallowEqual } from 'react-redux';
6
6
  import { useSelector, useDispatch } from '../FronteggStoreContext';
7
7
  import { ContextHolder } from '@frontegg/rest-api';
8
- import { useShadowDom } from '../common';
8
+ import { ShadowDomContext } from '../common';
9
9
  const defaultMapper = {
10
10
  state: state => state,
11
11
  actions: actions => actions
@@ -68,13 +68,9 @@ export const useAuthActions = () => {
68
68
  return useMemo(() => bindActionCreators(authActions, dispatch), [authActions]);
69
69
  };
70
70
  export const useOnRedirectTo = () => {
71
- const {
72
- onRedirectTo
73
- } = useAuth();
74
- const {
75
- appName
76
- } = useShadowDom();
77
- return onRedirectTo || ContextHolder.for(appName).onRedirectTo;
71
+ var _context$onRedirectTo;
72
+ const context = useContext(ShadowDomContext);
73
+ return (_context$onRedirectTo = context == null ? void 0 : context.onRedirectTo) != null ? _context$onRedirectTo : ContextHolder.onRedirectTo;
78
74
  };
79
75
  export const useAuthRoutes = () => useAuth(state => _extends({}, state.routes));
80
76
 
package/common/index.d.ts CHANGED
@@ -1,7 +1,6 @@
1
1
  import { Dispatch, SetStateAction } from 'react';
2
2
  import { FronteggAppInstance, FronteggAppOptions } from '@frontegg/types';
3
3
  import type { FronteggState } from '@frontegg/redux-store';
4
- import { FetchClient, FronteggApiClient } from '@frontegg/rest-api';
5
4
  interface ShadowDomContextData extends FronteggAppOptions {
6
5
  injector: FronteggAppInstance;
7
6
  iframeRendering: boolean;
@@ -14,9 +13,6 @@ interface ShadowDomContextData extends FronteggAppOptions {
14
13
  }
15
14
  export interface DomContext extends ShadowDomContextData {
16
15
  isShadowDom: boolean;
17
- fetchClient: FetchClient;
18
- apiClient: FronteggApiClient;
19
- appName: string;
20
16
  }
21
17
  export declare const ShadowDomContext: import("react").Context<ShadowDomContextData>;
22
18
  export declare const useShadowDom: () => DomContext;
package/common/index.js CHANGED
@@ -4,10 +4,8 @@ const _excluded = ["urlStrategy", "onRedirectTo", "renderByRoute", "customLoader
4
4
  import { createContext, useContext } from 'react';
5
5
  import { useSelector } from '../FronteggStoreContext';
6
6
  import { shallowEqual } from 'react-redux';
7
- import { FetchClient, createApiClient } from '@frontegg/rest-api';
8
7
  export const ShadowDomContext = /*#__PURE__*/createContext({});
9
8
  export const useShadowDom = () => {
10
- var _rest$injector$name, _rest$injector;
11
9
  const context = useContext(ShadowDomContext);
12
10
  const {
13
11
  urlStrategy = 'path',
@@ -18,7 +16,6 @@ export const useShadowDom = () => {
18
16
  contextOptions
19
17
  } = context,
20
18
  rest = _objectWithoutPropertiesLoose(context, _excluded);
21
- const appName = (_rest$injector$name = (_rest$injector = rest.injector) == null ? void 0 : _rest$injector.name) != null ? _rest$injector$name : 'default';
22
19
  return _extends({
23
20
  isShadowDom: true,
24
21
  onRedirectTo,
@@ -29,11 +26,7 @@ export const useShadowDom = () => {
29
26
  contextOptions: _extends({
30
27
  requestCredentials: 'include'
31
28
  }, contextOptions)
32
- }, rest, {
33
- appName,
34
- fetchClient: new FetchClient(appName),
35
- apiClient: createApiClient(appName)
36
- });
29
+ }, rest);
37
30
  };
38
31
  export const useRootState = () => {
39
32
  return useSelector(state => state.root, shallowEqual);
@@ -2,15 +2,15 @@ import { FeatureFlags } from '@frontegg/rest-api';
2
2
  import { useShadowDom } from '../common';
3
3
  export const useFeatureFlags = flags => {
4
4
  const {
5
- appName
5
+ injector
6
6
  } = useShadowDom();
7
- return FeatureFlags.getFeatureFlags(flags, appName);
7
+ return FeatureFlags.getFeatureFlags(flags, injector.name);
8
8
  };
9
9
  export const useFeatureFlagsChecker = () => {
10
10
  const {
11
- appName
11
+ injector
12
12
  } = useShadowDom();
13
13
  return flags => {
14
- return FeatureFlags.getFeatureFlags(flags, appName);
14
+ return FeatureFlags.getFeatureFlags(flags, injector.name);
15
15
  };
16
16
  };
package/index.js CHANGED
@@ -1,4 +1,4 @@
1
- /** @license Frontegg v6.198.0-alpha.2
1
+ /** @license Frontegg v6.198.0-alpha.3
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.
@@ -100,7 +100,7 @@ const FronteggContent = ({
100
100
  });
101
101
  };
102
102
  const FronteggStoreProvider = props => {
103
- var _app$options$contextO, _app$options3, _app$options$previewM, _app$options4, _app$options5, _app$options6, _app$name;
103
+ var _app$options$contextO, _app$options3, _app$options$previewM, _app$options4, _app$options5, _app$options6;
104
104
  const {
105
105
  children,
106
106
  app,
@@ -120,13 +120,12 @@ const FronteggStoreProvider = props => {
120
120
  }) : {
121
121
  hostedLoginBox: app == null ? void 0 : (_app$options6 = app.options) == null ? void 0 : _app$options6.hostedLoginBox
122
122
  };
123
- const appName = (_app$name = app == null ? void 0 : app.name) != null ? _app$name : 'default';
124
- _restApi.ContextHolder.for(appName).setContext(context);
123
+ _restApi.ContextHolder.setContext(context);
125
124
  const store = (0, _react.useMemo)(() => {
126
- var _app$options7;
125
+ var _app$name, _app$options7;
127
126
  return (0, _reduxStore.createFronteggStore)({
128
127
  context,
129
- appName
128
+ appName: (_app$name = app == null ? void 0 : app.name) != null ? _app$name : 'default'
130
129
  }, app, previewMode, authOptions, undefined, false, app == null ? void 0 : (_app$options7 = app.options) == null ? void 0 : _app$options7.urlStrategy);
131
130
  }, [app, previewMode]);
132
131
  return /*#__PURE__*/(0, _jsxRuntime.jsxs)(_FronteggStoreContext.Provider, {
@@ -50,10 +50,7 @@ const useFeatureEntitlements = (key, customAttributes) => {
50
50
  entitlements,
51
51
  attributes
52
52
  } = useEntitlementsQueryData(customAttributes);
53
- const {
54
- appName
55
- } = (0, _common.useRootState)();
56
- return (0, _reduxStore.getFeatureEntitlements)(entitlements, key, attributes, undefined, appName);
53
+ return (0, _reduxStore.getFeatureEntitlements)(entitlements, key, attributes);
57
54
  };
58
55
 
59
56
  /**
@@ -67,10 +64,7 @@ const usePermissionEntitlements = (key, customAttributes) => {
67
64
  entitlements,
68
65
  attributes
69
66
  } = useEntitlementsQueryData(customAttributes);
70
- const {
71
- appName
72
- } = (0, _common.useRootState)();
73
- return (0, _reduxStore.getPermissionEntitlements)(entitlements, key, attributes, undefined, appName);
67
+ return (0, _reduxStore.getPermissionEntitlements)(entitlements, key, attributes);
74
68
  };
75
69
 
76
70
  /**
@@ -84,10 +78,7 @@ const useEntitlements = (options, customAttributes) => {
84
78
  entitlements,
85
79
  attributes
86
80
  } = useEntitlementsQueryData(customAttributes);
87
- const {
88
- appName
89
- } = (0, _common.useRootState)();
90
- return (0, _reduxStore.getEntitlements)(entitlements, options, attributes, undefined, appName);
81
+ return (0, _reduxStore.getEntitlements)(entitlements, options, attributes);
91
82
  };
92
83
 
93
84
  /**
@@ -99,16 +90,13 @@ const useEntitlementsActions = () => {
99
90
  // this code is duplicated because React is yelling when using useEntitlementsQueryData inside the isEntitledTo function because it's not a hook
100
91
  const user = useUserState();
101
92
  const entitlements = useEntitlementsState();
102
- const {
103
- appName
104
- } = (0, _common.useRootState)();
105
93
  return (0, _react.useMemo)(() => ({
106
94
  isEntitledTo: (options, customAttributes) => {
107
95
  const attributes = {
108
96
  custom: customAttributes,
109
97
  jwt: user
110
98
  };
111
- return (0, _reduxStore.getEntitlements)(entitlements, options, attributes, undefined, appName);
99
+ return (0, _reduxStore.getEntitlements)(entitlements, options, attributes);
112
100
  }
113
101
  }), [user, entitlements]);
114
102
  };
@@ -79,13 +79,9 @@ const useAuthActions = () => {
79
79
  };
80
80
  exports.useAuthActions = useAuthActions;
81
81
  const useOnRedirectTo = () => {
82
- const {
83
- onRedirectTo
84
- } = useAuth();
85
- const {
86
- appName
87
- } = (0, _common.useShadowDom)();
88
- return onRedirectTo || _restApi.ContextHolder.for(appName).onRedirectTo;
82
+ var _context$onRedirectTo;
83
+ const context = (0, _react.useContext)(_common.ShadowDomContext);
84
+ return (_context$onRedirectTo = context == null ? void 0 : context.onRedirectTo) != null ? _context$onRedirectTo : _restApi.ContextHolder.onRedirectTo;
89
85
  };
90
86
  exports.useOnRedirectTo = useOnRedirectTo;
91
87
  const useAuthRoutes = () => useAuth(state => (0, _extends2.default)({}, state.routes));
@@ -15,7 +15,6 @@ var _objectWithoutPropertiesLoose2 = _interopRequireDefault(require("@babel/runt
15
15
  var _react = require("react");
16
16
  var _FronteggStoreContext = require("../FronteggStoreContext");
17
17
  var _reactRedux = require("react-redux");
18
- var _restApi = require("@frontegg/rest-api");
19
18
  var _CustomComponentHolder = require("./CustomComponentHolder");
20
19
  Object.keys(_CustomComponentHolder).forEach(function (key) {
21
20
  if (key === "default" || key === "__esModule") return;
@@ -32,7 +31,6 @@ const _excluded = ["urlStrategy", "onRedirectTo", "renderByRoute", "customLoader
32
31
  const ShadowDomContext = /*#__PURE__*/(0, _react.createContext)({});
33
32
  exports.ShadowDomContext = ShadowDomContext;
34
33
  const useShadowDom = () => {
35
- var _rest$injector$name, _rest$injector;
36
34
  const context = (0, _react.useContext)(ShadowDomContext);
37
35
  const {
38
36
  urlStrategy = 'path',
@@ -43,7 +41,6 @@ const useShadowDom = () => {
43
41
  contextOptions
44
42
  } = context,
45
43
  rest = (0, _objectWithoutPropertiesLoose2.default)(context, _excluded);
46
- const appName = (_rest$injector$name = (_rest$injector = rest.injector) == null ? void 0 : _rest$injector.name) != null ? _rest$injector$name : 'default';
47
44
  return (0, _extends2.default)({
48
45
  isShadowDom: true,
49
46
  onRedirectTo,
@@ -54,11 +51,7 @@ const useShadowDom = () => {
54
51
  contextOptions: (0, _extends2.default)({
55
52
  requestCredentials: 'include'
56
53
  }, contextOptions)
57
- }, rest, {
58
- appName,
59
- fetchClient: new _restApi.FetchClient(appName),
60
- apiClient: (0, _restApi.createApiClient)(appName)
61
- });
54
+ }, rest);
62
55
  };
63
56
  exports.useShadowDom = useShadowDom;
64
57
  const useRootState = () => {
@@ -8,17 +8,17 @@ var _restApi = require("@frontegg/rest-api");
8
8
  var _common = require("../common");
9
9
  const useFeatureFlags = flags => {
10
10
  const {
11
- appName
11
+ injector
12
12
  } = (0, _common.useShadowDom)();
13
- return _restApi.FeatureFlags.getFeatureFlags(flags, appName);
13
+ return _restApi.FeatureFlags.getFeatureFlags(flags, injector.name);
14
14
  };
15
15
  exports.useFeatureFlags = useFeatureFlags;
16
16
  const useFeatureFlagsChecker = () => {
17
17
  const {
18
- appName
18
+ injector
19
19
  } = (0, _common.useShadowDom)();
20
20
  return flags => {
21
- return _restApi.FeatureFlags.getFeatureFlags(flags, appName);
21
+ return _restApi.FeatureFlags.getFeatureFlags(flags, injector.name);
22
22
  };
23
23
  };
24
24
  exports.useFeatureFlagsChecker = useFeatureFlagsChecker;
package/node/index.js CHANGED
@@ -1,4 +1,4 @@
1
- /** @license Frontegg v6.198.0-alpha.2
1
+ /** @license Frontegg v6.198.0-alpha.3
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/react-hooks",
3
- "version": "6.198.0-alpha.2",
3
+ "version": "6.198.0-alpha.3",
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
- "@frontegg/redux-store": "6.198.0-alpha.2",
10
- "@frontegg/types": "6.198.0-alpha.2",
9
+ "@frontegg/redux-store": "6.198.0-alpha.3",
10
+ "@frontegg/types": "6.198.0-alpha.3",
11
11
  "@types/react": "*",
12
12
  "get-value": "^3.0.1",
13
13
  "react-redux": "^7.x"