@frontegg/react-hooks 7.0.0-alpha.7 → 7.0.0-alpha.8

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.
@@ -91,7 +91,7 @@ const FronteggContent = ({
91
91
  });
92
92
  };
93
93
  export const FronteggStoreProvider = props => {
94
- var _app$options$contextO, _app$options3, _app$options$previewM, _app$options4, _app$options$builderM, _app$options5, _app$options6, _app$options7, _app$options8;
94
+ var _app$options$contextO, _app$options3, _app$options$previewM, _app$options4, _app$options$builderM, _app$options5, _app$options6, _app$options7, _app$options8, _app$name;
95
95
  const {
96
96
  children,
97
97
  app,
@@ -113,11 +113,12 @@ export const FronteggStoreProvider = props => {
113
113
  }) : {
114
114
  hostedLoginBox: app == null ? void 0 : (_app$options8 = app.options) == null ? void 0 : _app$options8.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$store, _app$name, _app$options9;
119
+ var _app$store, _app$options9;
119
120
  return (_app$store = app == null ? void 0 : app.store) != null ? _app$store : createStore({
120
- name: (_app$name = app == null ? void 0 : app.name) != null ? _app$name : 'default',
121
+ name: appName,
121
122
  context,
122
123
  previewMode,
123
124
  builderMode,
package/auth/hooks.js CHANGED
@@ -2,6 +2,7 @@ import { useContext } from 'react';
2
2
  import { ContextHolder } from '@frontegg/rest-api';
3
3
  import { FronteggStoreContext, useStore } from '../FronteggStoreContext';
4
4
  import { useSnapshot } from '../useSnapshot';
5
+ import { useShadowDom } from '../common';
5
6
  const defaultMapper = {
6
7
  state: state => state,
7
8
  actions: actions => actions
@@ -76,7 +77,10 @@ export const useOnRedirectTo = () => {
76
77
  const {
77
78
  onRedirectTo
78
79
  } = useAuth();
79
- return onRedirectTo || ContextHolder.onRedirectTo;
80
+ const {
81
+ appName
82
+ } = useShadowDom();
83
+ return onRedirectTo || ContextHolder.for(appName).onRedirectTo;
80
84
  };
81
85
  export const useAuthRoutes = () => useAuthState().routes;
82
86
 
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 { useStore } from '../FronteggStoreContext';
6
6
  import { useSnapshot } from '../useSnapshot';
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 useSnapshot(useStore().store.root);
package/index.js CHANGED
@@ -1,4 +1,4 @@
1
- /** @license Frontegg v7.0.0-alpha.7
1
+ /** @license Frontegg v7.0.0-alpha.8
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.
@@ -98,7 +98,7 @@ const FronteggContent = ({
98
98
  });
99
99
  };
100
100
  const FronteggStoreProvider = props => {
101
- var _app$options$contextO, _app$options3, _app$options$previewM, _app$options4, _app$options$builderM, _app$options5, _app$options6, _app$options7, _app$options8;
101
+ var _app$options$contextO, _app$options3, _app$options$previewM, _app$options4, _app$options$builderM, _app$options5, _app$options6, _app$options7, _app$options8, _app$name;
102
102
  const {
103
103
  children,
104
104
  app,
@@ -120,11 +120,12 @@ const FronteggStoreProvider = props => {
120
120
  }) : {
121
121
  hostedLoginBox: app == null ? void 0 : (_app$options8 = app.options) == null ? void 0 : _app$options8.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$store, _app$name, _app$options9;
126
+ var _app$store, _app$options9;
126
127
  return (_app$store = app == null ? void 0 : app.store) != null ? _app$store : (0, _reduxStore.createStore)({
127
- name: (_app$name = app == null ? void 0 : app.name) != null ? _app$name : 'default',
128
+ name: appName,
128
129
  context,
129
130
  previewMode,
130
131
  builderMode,
@@ -11,6 +11,7 @@ var _react = require("react");
11
11
  var _restApi = require("@frontegg/rest-api");
12
12
  var _FronteggStoreContext = require("../FronteggStoreContext");
13
13
  var _useSnapshot = require("../useSnapshot");
14
+ var _common = require("../common");
14
15
  const defaultMapper = {
15
16
  state: state => state,
16
17
  actions: actions => actions
@@ -88,7 +89,10 @@ const useOnRedirectTo = () => {
88
89
  const {
89
90
  onRedirectTo
90
91
  } = useAuth();
91
- return onRedirectTo || _restApi.ContextHolder.onRedirectTo;
92
+ const {
93
+ appName
94
+ } = (0, _common.useShadowDom)();
95
+ return onRedirectTo || _restApi.ContextHolder.for(appName).onRedirectTo;
92
96
  };
93
97
  exports.useOnRedirectTo = useOnRedirectTo;
94
98
  const useAuthRoutes = () => useAuthState().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 _useSnapshot = require("../useSnapshot");
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 v7.0.0-alpha.7
1
+ /** @license Frontegg v7.0.0-alpha.8
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": "7.0.0-alpha.7",
3
+ "version": "7.0.0-alpha.8",
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": "7.0.0-alpha.7",
10
- "@frontegg/types": "7.0.0-alpha.7",
9
+ "@frontegg/redux-store": "7.0.0-alpha.8",
10
+ "@frontegg/types": "7.0.0-alpha.8",
11
11
  "@types/react": "*",
12
12
  "get-value": "^3.0.1"
13
13
  },