@frontegg/react-hooks 6.197.0-alpha.0 → 6.198.0-alpha.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.
@@ -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;
96
+ var _app$options$contextO, _app$options3, _app$options$previewM, _app$options4, _app$options5, _app$options6, _app$name;
97
97
  const {
98
98
  children,
99
99
  app,
@@ -113,12 +113,13 @@ 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
- ContextHolder.setContext(context);
116
+ const appName = (_app$name = app == null ? void 0 : app.name) != null ? _app$name : 'default';
117
+ ContextHolder.for(appName).setContext(context);
117
118
  const store = useMemo(() => {
118
- var _app$name, _app$options7;
119
+ var _app$options7;
119
120
  return createFronteggStore({
120
121
  context,
121
- appName: (_app$name = app == null ? void 0 : app.name) != null ? _app$name : 'default'
122
+ appName
122
123
  }, app, previewMode, authOptions, undefined, false, app == null ? void 0 : (_app$options7 = app.options) == null ? void 0 : _app$options7.urlStrategy);
123
124
  }, [app, previewMode]);
124
125
  return /*#__PURE__*/_jsxs(Provider, {
package/auth/hooks.js CHANGED
@@ -1,11 +1,11 @@
1
1
  import _extends from "@babel/runtime/helpers/esm/extends";
2
- import { useContext, useMemo } from 'react';
2
+ import { 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 { ShadowDomContext } from '../common';
8
+ import { useShadowDom } from '../common';
9
9
  const defaultMapper = {
10
10
  state: state => state,
11
11
  actions: actions => actions
@@ -68,9 +68,13 @@ export const useAuthActions = () => {
68
68
  return useMemo(() => bindActionCreators(authActions, dispatch), [authActions]);
69
69
  };
70
70
  export const useOnRedirectTo = () => {
71
- var _context$onRedirectTo;
72
- const context = useContext(ShadowDomContext);
73
- return (_context$onRedirectTo = context == null ? void 0 : context.onRedirectTo) != null ? _context$onRedirectTo : ContextHolder.onRedirectTo;
71
+ const {
72
+ onRedirectTo
73
+ } = useAuth();
74
+ const {
75
+ appName
76
+ } = useShadowDom();
77
+ return onRedirectTo || ContextHolder.for(appName).onRedirectTo;
74
78
  };
75
79
  export const useAuthRoutes = () => useAuth(state => _extends({}, state.routes));
76
80
 
package/common/index.d.ts CHANGED
@@ -1,6 +1,7 @@
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';
4
5
  interface ShadowDomContextData extends FronteggAppOptions {
5
6
  injector: FronteggAppInstance;
6
7
  iframeRendering: boolean;
@@ -13,6 +14,9 @@ interface ShadowDomContextData extends FronteggAppOptions {
13
14
  }
14
15
  export interface DomContext extends ShadowDomContextData {
15
16
  isShadowDom: boolean;
17
+ fetchClient: FetchClient;
18
+ apiClient: FronteggApiClient;
19
+ appName: string;
16
20
  }
17
21
  export declare const ShadowDomContext: import("react").Context<ShadowDomContextData>;
18
22
  export declare const useShadowDom: () => DomContext;
package/common/index.js CHANGED
@@ -4,8 +4,10 @@ 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';
7
8
  export const ShadowDomContext = /*#__PURE__*/createContext({});
8
9
  export const useShadowDom = () => {
10
+ var _rest$injector$name, _rest$injector;
9
11
  const context = useContext(ShadowDomContext);
10
12
  const {
11
13
  urlStrategy = 'path',
@@ -16,6 +18,7 @@ export const useShadowDom = () => {
16
18
  contextOptions
17
19
  } = context,
18
20
  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';
19
22
  return _extends({
20
23
  isShadowDom: true,
21
24
  onRedirectTo,
@@ -26,7 +29,11 @@ export const useShadowDom = () => {
26
29
  contextOptions: _extends({
27
30
  requestCredentials: 'include'
28
31
  }, contextOptions)
29
- }, rest);
32
+ }, rest, {
33
+ appName,
34
+ fetchClient: new FetchClient(appName),
35
+ apiClient: createApiClient(appName)
36
+ });
30
37
  };
31
38
  export const useRootState = () => {
32
39
  return useSelector(state => state.root, shallowEqual);
package/index.js CHANGED
@@ -1,4 +1,4 @@
1
- /** @license Frontegg v6.197.0-alpha.0
1
+ /** @license Frontegg v6.198.0-alpha.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.
@@ -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;
103
+ var _app$options$contextO, _app$options3, _app$options$previewM, _app$options4, _app$options5, _app$options6, _app$name;
104
104
  const {
105
105
  children,
106
106
  app,
@@ -120,12 +120,13 @@ 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
- _restApi.ContextHolder.setContext(context);
123
+ const appName = (_app$name = app == null ? void 0 : app.name) != null ? _app$name : 'default';
124
+ _restApi.ContextHolder.for(appName).setContext(context);
124
125
  const store = (0, _react.useMemo)(() => {
125
- var _app$name, _app$options7;
126
+ var _app$options7;
126
127
  return (0, _reduxStore.createFronteggStore)({
127
128
  context,
128
- appName: (_app$name = app == null ? void 0 : app.name) != null ? _app$name : 'default'
129
+ appName
129
130
  }, app, previewMode, authOptions, undefined, false, app == null ? void 0 : (_app$options7 = app.options) == null ? void 0 : _app$options7.urlStrategy);
130
131
  }, [app, previewMode]);
131
132
  return /*#__PURE__*/(0, _jsxRuntime.jsxs)(_FronteggStoreContext.Provider, {
@@ -79,9 +79,13 @@ const useAuthActions = () => {
79
79
  };
80
80
  exports.useAuthActions = useAuthActions;
81
81
  const useOnRedirectTo = () => {
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;
82
+ const {
83
+ onRedirectTo
84
+ } = useAuth();
85
+ const {
86
+ appName
87
+ } = (0, _common.useShadowDom)();
88
+ return onRedirectTo || _restApi.ContextHolder.for(appName).onRedirectTo;
85
89
  };
86
90
  exports.useOnRedirectTo = useOnRedirectTo;
87
91
  const useAuthRoutes = () => useAuth(state => (0, _extends2.default)({}, state.routes));
@@ -15,6 +15,7 @@ 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");
18
19
  var _CustomComponentHolder = require("./CustomComponentHolder");
19
20
  Object.keys(_CustomComponentHolder).forEach(function (key) {
20
21
  if (key === "default" || key === "__esModule") return;
@@ -31,6 +32,7 @@ const _excluded = ["urlStrategy", "onRedirectTo", "renderByRoute", "customLoader
31
32
  const ShadowDomContext = /*#__PURE__*/(0, _react.createContext)({});
32
33
  exports.ShadowDomContext = ShadowDomContext;
33
34
  const useShadowDom = () => {
35
+ var _rest$injector$name, _rest$injector;
34
36
  const context = (0, _react.useContext)(ShadowDomContext);
35
37
  const {
36
38
  urlStrategy = 'path',
@@ -41,6 +43,7 @@ const useShadowDom = () => {
41
43
  contextOptions
42
44
  } = context,
43
45
  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';
44
47
  return (0, _extends2.default)({
45
48
  isShadowDom: true,
46
49
  onRedirectTo,
@@ -51,7 +54,11 @@ const useShadowDom = () => {
51
54
  contextOptions: (0, _extends2.default)({
52
55
  requestCredentials: 'include'
53
56
  }, contextOptions)
54
- }, rest);
57
+ }, rest, {
58
+ appName,
59
+ fetchClient: new _restApi.FetchClient(appName),
60
+ apiClient: (0, _restApi.createApiClient)(appName)
61
+ });
55
62
  };
56
63
  exports.useShadowDom = useShadowDom;
57
64
  const useRootState = () => {
package/node/index.js CHANGED
@@ -1,4 +1,4 @@
1
- /** @license Frontegg v6.197.0-alpha.0
1
+ /** @license Frontegg v6.198.0-alpha.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.
package/package.json CHANGED
@@ -1,13 +1,13 @@
1
1
  {
2
2
  "name": "@frontegg/react-hooks",
3
- "version": "6.197.0-alpha.0",
3
+ "version": "6.198.0-alpha.0",
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.197.0-alpha.0",
10
- "@frontegg/types": "6.197.0-alpha.0",
9
+ "@frontegg/redux-store": "6.198.0-alpha.0",
10
+ "@frontegg/types": "6.198.0-alpha.0",
11
11
  "@types/react": "*",
12
12
  "get-value": "^3.0.1",
13
13
  "react-redux": "^7.x"