@frontegg/react-hooks 5.59.1 → 6.0.1-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.
Files changed (107) hide show
  1. package/FronteggProvider.d.ts +11 -10
  2. package/FronteggProvider.js +137 -0
  3. package/FronteggStoreContext.d.ts +8 -8
  4. package/FronteggStoreContext.js +13 -0
  5. package/audits/auditLogs.d.ts +5 -5
  6. package/audits/auditLogs.js +4 -0
  7. package/audits/auditsMetadata.d.ts +5 -5
  8. package/audits/auditsMetadata.js +4 -0
  9. package/audits/hooks.d.ts +12 -12
  10. package/audits/hooks.js +35 -0
  11. package/audits/index.d.ts +3 -3
  12. package/audits/index.js +3 -5
  13. package/auth/acceptInvitation.d.ts +5 -5
  14. package/auth/acceptInvitation.js +4 -0
  15. package/auth/activateAccount.d.ts +5 -5
  16. package/auth/activateAccount.js +4 -0
  17. package/auth/apiTokens.d.ts +5 -5
  18. package/auth/apiTokens.js +4 -0
  19. package/auth/forgotPassword.d.ts +5 -5
  20. package/auth/forgotPassword.js +4 -0
  21. package/auth/hooks.d.ts +62 -62
  22. package/auth/hooks.js +79 -0
  23. package/auth/index.d.ts +16 -16
  24. package/auth/index.js +16 -7
  25. package/auth/login.d.ts +5 -5
  26. package/auth/login.js +4 -0
  27. package/auth/mfa.d.ts +4 -4
  28. package/auth/mfa.js +4 -0
  29. package/auth/profile.d.ts +6 -6
  30. package/auth/profile.js +16 -0
  31. package/auth/resetPhoneNumber.d.ts +5 -5
  32. package/auth/resetPhoneNumber.js +4 -0
  33. package/auth/roles.d.ts +5 -5
  34. package/auth/roles.js +4 -0
  35. package/auth/securityPolicy.d.ts +11 -11
  36. package/auth/securityPolicy.js +25 -0
  37. package/auth/signup.d.ts +5 -5
  38. package/auth/signup.js +4 -0
  39. package/auth/socialLogin.d.ts +5 -5
  40. package/auth/socialLogin.js +4 -0
  41. package/auth/sso.d.ts +4 -4
  42. package/auth/sso.js +4 -0
  43. package/auth/team.d.ts +5 -5
  44. package/auth/team.js +4 -0
  45. package/auth/tenants.d.ts +5 -5
  46. package/auth/tenants.js +4 -0
  47. package/common/index.d.ts +17 -17
  48. package/common/index.js +30 -0
  49. package/common/package.json +6 -0
  50. package/connectivity/hooks.d.ts +5 -5
  51. package/connectivity/hooks.js +15 -0
  52. package/connectivity/index.d.ts +1 -1
  53. package/connectivity/index.js +1 -5
  54. package/index.d.ts +8 -8
  55. package/index.js +13 -93
  56. package/node/FronteggProvider.js +160 -0
  57. package/node/FronteggStoreContext.js +49 -0
  58. package/node/audits/auditLogs.js +18 -0
  59. package/node/audits/auditsMetadata.js +18 -0
  60. package/node/audits/hooks.js +62 -0
  61. package/node/audits/index.js +46 -13
  62. package/node/auth/acceptInvitation.js +18 -0
  63. package/node/auth/activateAccount.js +18 -0
  64. package/node/auth/apiTokens.js +18 -0
  65. package/node/auth/forgotPassword.js +18 -0
  66. package/node/auth/hooks.js +127 -0
  67. package/node/auth/index.js +275 -54
  68. package/node/auth/login.js +18 -0
  69. package/node/auth/mfa.js +18 -0
  70. package/node/auth/profile.js +34 -0
  71. package/node/auth/resetPhoneNumber.js +18 -0
  72. package/node/auth/roles.js +18 -0
  73. package/node/auth/securityPolicy.js +43 -0
  74. package/node/auth/signup.js +18 -0
  75. package/node/auth/socialLogin.js +18 -0
  76. package/node/auth/sso.js +18 -0
  77. package/node/auth/team.js +18 -0
  78. package/node/auth/tenants.js +18 -0
  79. package/node/common/index.js +44 -0
  80. package/node/connectivity/hooks.js +31 -0
  81. package/node/connectivity/index.js +17 -12
  82. package/node/index.js +111 -187
  83. package/node/subscriptions/hooks.js +131 -0
  84. package/node/subscriptions/index.js +15 -27
  85. package/node/vendor/hooks.js +31 -0
  86. package/node/vendor/index.js +17 -12
  87. package/package.json +12 -7
  88. package/subscriptions/hooks.d.ts +19 -19
  89. package/subscriptions/hooks.js +69 -0
  90. package/subscriptions/index.d.ts +1 -1
  91. package/subscriptions/index.js +1 -5
  92. package/vendor/hooks.d.ts +5 -5
  93. package/vendor/hooks.js +15 -0
  94. package/vendor/index.d.ts +1 -1
  95. package/vendor/index.js +1 -5
  96. package/FronteggStoreContext-d6c3b684.js +0 -9
  97. package/auditsMetadata-9ab88593.js +0 -35
  98. package/hooks-6400e233.js +0 -14
  99. package/hooks-7fc5d634.js +0 -64
  100. package/hooks-eaf879c9.js +0 -14
  101. package/node/FronteggStoreContext-6cfac56c.js +0 -18
  102. package/node/auditsMetadata-d15799a1.js +0 -42
  103. package/node/hooks-429ffd3a.js +0 -83
  104. package/node/hooks-5d5a445e.js +0 -17
  105. package/node/hooks-cf739b27.js +0 -17
  106. package/node/roles-f45dbc50.js +0 -215
  107. package/roles-f87bc6a0.js +0 -172
@@ -0,0 +1,160 @@
1
+ "use strict";
2
+
3
+ var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
4
+
5
+ Object.defineProperty(exports, "__esModule", {
6
+ value: true
7
+ });
8
+ exports.FronteggStoreProvider = void 0;
9
+
10
+ var _objectWithoutPropertiesLoose2 = _interopRequireDefault(require("@babel/runtime/helpers/objectWithoutPropertiesLoose"));
11
+
12
+ var _react = _interopRequireWildcard(require("react"));
13
+
14
+ var _reactRedux = require("react-redux");
15
+
16
+ var _reduxStore = require("@frontegg/redux-store");
17
+
18
+ var _restApi = require("@frontegg/rest-api");
19
+
20
+ var _auth = require("./auth");
21
+
22
+ var _FronteggStoreContext = require("./FronteggStoreContext");
23
+
24
+ var _jsxRuntime = require("react/jsx-runtime");
25
+
26
+ const _excluded = ["authenticatedUrl", "signUpSuccessUrl"];
27
+
28
+ function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function (nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); }
29
+
30
+ function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || typeof obj !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
31
+
32
+ const setLoading = loading => {
33
+ const isSSR = typeof document === 'undefined' || typeof window === 'undefined';
34
+
35
+ if (!isSSR) {
36
+ if (loading) {
37
+ document.body.classList.add('frontegg-loading');
38
+ } else {
39
+ document.body.classList.remove('frontegg-loading');
40
+ }
41
+ }
42
+ };
43
+
44
+ const HideChildrenIfFronteggRoutes = ({
45
+ children,
46
+ basename
47
+ }) => {
48
+ const routes = (0, _auth.useAuthRoutes)();
49
+ const uriRef = (0, _react.useRef)(window.location.pathname);
50
+ const animationFrameRef = (0, _react.useRef)(0);
51
+ const [uri, setUri] = (0, _react.useState)(window.location.pathname);
52
+
53
+ const checker = () => {
54
+ if (uriRef.current !== window.location.pathname) {
55
+ uriRef.current = window.location.pathname;
56
+ setUri(document.location.pathname);
57
+ }
58
+
59
+ animationFrameRef.current = window.requestAnimationFrame(checker);
60
+ };
61
+
62
+ (0, _react.useEffect)(() => {
63
+ document.addEventListener('frontegg_onRedirectTo_fired', () => {
64
+ if (uriRef.current !== window.location.pathname) {
65
+ uriRef.current = window.location.pathname;
66
+ setUri(document.location.pathname);
67
+ }
68
+ });
69
+ window.addEventListener('popstate', () => {
70
+ if (uriRef.current !== window.location.pathname) {
71
+ uriRef.current = window.location.pathname;
72
+ setUri(document.location.pathname);
73
+ }
74
+ });
75
+ animationFrameRef.current = window.requestAnimationFrame(checker);
76
+ return () => {
77
+ window.cancelAnimationFrame(animationFrameRef.current);
78
+ };
79
+ }, [setUri]);
80
+ const calculatedBasename = basename ? basename.endsWith('/') ? basename.substring(0, basename.length - 1) : '' : '';
81
+ const checkRoutes = (0, _objectWithoutPropertiesLoose2.default)(routes, _excluded);
82
+
83
+ if (Object.values(checkRoutes).map(url => `${calculatedBasename}${url}`).indexOf(uri) !== -1) {
84
+ return null;
85
+ }
86
+
87
+ return (0, _jsxRuntime.jsx)(_jsxRuntime.Fragment, {
88
+ children: children
89
+ });
90
+ };
91
+
92
+ const FronteggContent = ({
93
+ children,
94
+ app,
95
+ setLoading
96
+ }) => {
97
+ var _app$options, _app$options2, _app$options3;
98
+
99
+ const {
100
+ isLoading
101
+ } = (0, _auth.useAuth)(({
102
+ isLoading
103
+ }) => ({
104
+ isLoading
105
+ }));
106
+ const customLoginBox = !app || (app == null ? void 0 : (_app$options = app.options) == null ? void 0 : _app$options.customLoginBox) === true;
107
+ const alwaysShowChildren = customLoginBox || (app == null ? void 0 : (_app$options2 = app.options) == null ? void 0 : _app$options2.hostedLoginBox) === true && (app == null ? void 0 : (_app$options3 = app.options) == null ? void 0 : _app$options3.framework) === 'nextjs';
108
+ const loadingRef = (0, _react.useRef)(undefined);
109
+
110
+ if (isLoading !== loadingRef.current) {
111
+ loadingRef.current = isLoading;
112
+ setLoading(isLoading);
113
+ }
114
+
115
+ if (isLoading) {
116
+ return null;
117
+ }
118
+
119
+ if (alwaysShowChildren) {
120
+ return (0, _jsxRuntime.jsx)(_jsxRuntime.Fragment, {
121
+ children: children
122
+ });
123
+ }
124
+
125
+ return (0, _jsxRuntime.jsx)(HideChildrenIfFronteggRoutes, {
126
+ basename: app == null ? void 0 : app.options.basename,
127
+ children: children
128
+ });
129
+ };
130
+
131
+ const FronteggStoreProvider = props => {
132
+ var _app$options$contextO, _app$options4, _app$options$previewM, _app$options5, _app$options$authOpti, _app$options6;
133
+
134
+ const {
135
+ children,
136
+ app,
137
+ contextOptions,
138
+ setLoading: setLoadingProps
139
+ } = props;
140
+ const context = (_app$options$contextO = app == null ? void 0 : (_app$options4 = app.options) == null ? void 0 : _app$options4.contextOptions) != null ? _app$options$contextO : contextOptions;
141
+ const previewMode = (_app$options$previewM = app == null ? void 0 : (_app$options5 = app.options) == null ? void 0 : _app$options5.previewMode) != null ? _app$options$previewM : false;
142
+ const authOptions = (_app$options$authOpti = app == null ? void 0 : (_app$options6 = app.options) == null ? void 0 : _app$options6.authOptions) != null ? _app$options$authOpti : {};
143
+
144
+ _restApi.ContextHolder.setContext(context);
145
+
146
+ const store = (0, _react.useMemo)(() => (0, _reduxStore.createFronteggStore)({
147
+ context: context
148
+ }, app, previewMode, authOptions), [app, previewMode]);
149
+ return (0, _jsxRuntime.jsx)(_reactRedux.Provider, {
150
+ context: _FronteggStoreContext.FronteggStoreContext,
151
+ store: store,
152
+ children: (0, _jsxRuntime.jsx)(FronteggContent, {
153
+ setLoading: setLoadingProps != null ? setLoadingProps : setLoading,
154
+ app: app,
155
+ children: children
156
+ })
157
+ });
158
+ };
159
+
160
+ exports.FronteggStoreProvider = FronteggStoreProvider;
@@ -0,0 +1,49 @@
1
+ "use strict";
2
+
3
+ var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
4
+
5
+ Object.defineProperty(exports, "__esModule", {
6
+ value: true
7
+ });
8
+ exports.FronteggStoreContext = void 0;
9
+ Object.defineProperty(exports, "Provider", {
10
+ enumerable: true,
11
+ get: function () {
12
+ return _reactRedux.Provider;
13
+ }
14
+ });
15
+ Object.defineProperty(exports, "connectAdvanced", {
16
+ enumerable: true,
17
+ get: function () {
18
+ return _reactRedux.connectAdvanced;
19
+ }
20
+ });
21
+ exports.default = void 0;
22
+ Object.defineProperty(exports, "shallowEqual", {
23
+ enumerable: true,
24
+ get: function () {
25
+ return _reactRedux.shallowEqual;
26
+ }
27
+ });
28
+ exports.useStore = exports.useSelector = exports.useDispatch = void 0;
29
+
30
+ var _react = _interopRequireDefault(require("react"));
31
+
32
+ var _reactRedux = require("react-redux");
33
+
34
+ const FronteggStoreContext = _react.default.createContext(null);
35
+
36
+ exports.FronteggStoreContext = FronteggStoreContext;
37
+
38
+ if (process.env.NODE_ENV !== 'production') {
39
+ FronteggStoreContext.displayName = 'FronteggStoreContext';
40
+ }
41
+
42
+ const useSelector = (0, _reactRedux.createSelectorHook)(FronteggStoreContext);
43
+ exports.useSelector = useSelector;
44
+ const useDispatch = (0, _reactRedux.createDispatchHook)(FronteggStoreContext);
45
+ exports.useDispatch = useDispatch;
46
+ const useStore = (0, _reactRedux.createStoreHook)(FronteggStoreContext);
47
+ exports.useStore = useStore;
48
+ var _default = FronteggStoreContext;
49
+ exports.default = _default;
@@ -0,0 +1,18 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.useAuditLogsState = exports.useAuditLogsActions = void 0;
7
+
8
+ var _hooks = require("./hooks");
9
+
10
+ var _reduxStore = require("@frontegg/redux-store");
11
+
12
+ const useAuditLogsState = stateMapper => (0, _hooks.stateHookGenerator)(stateMapper, 'auditLogsState');
13
+
14
+ exports.useAuditLogsState = useAuditLogsState;
15
+
16
+ const useAuditLogsActions = () => (0, _hooks.reducerActionsGenerator)(_reduxStore.auditLogsActions, _reduxStore.auditLogsReducers);
17
+
18
+ exports.useAuditLogsActions = useAuditLogsActions;
@@ -0,0 +1,18 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.useAuditsMetadataState = exports.useAuditsMetadataActions = void 0;
7
+
8
+ var _hooks = require("./hooks");
9
+
10
+ var _reduxStore = require("@frontegg/redux-store");
11
+
12
+ const useAuditsMetadataState = stateMapper => (0, _hooks.stateHookGenerator)(stateMapper, 'auditsMetadataState');
13
+
14
+ exports.useAuditsMetadataState = useAuditsMetadataState;
15
+
16
+ const useAuditsMetadataActions = () => (0, _hooks.reducerActionsGenerator)(_reduxStore.auditsMetadataActions, _reduxStore.auditsMetadataReducers);
17
+
18
+ exports.useAuditsMetadataActions = useAuditsMetadataActions;
@@ -0,0 +1,62 @@
1
+ "use strict";
2
+
3
+ var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
4
+
5
+ Object.defineProperty(exports, "__esModule", {
6
+ value: true
7
+ });
8
+ exports.useAuditsState = exports.useAuditsActions = exports.stateHookGenerator = exports.sliceReducerActionsBy = exports.reducerActionsGenerator = void 0;
9
+
10
+ var _extends2 = _interopRequireDefault(require("@babel/runtime/helpers/extends"));
11
+
12
+ var _react = require("react");
13
+
14
+ var _reduxStore = require("@frontegg/redux-store");
15
+
16
+ var _reactRedux = require("react-redux");
17
+
18
+ var _FronteggStoreContext = require("../FronteggStoreContext");
19
+
20
+ const useAuditsState = stateMapper => {
21
+ return (0, _FronteggStoreContext.useSelector)(state => {
22
+ var _stateMapper;
23
+
24
+ return (_stateMapper = stateMapper == null ? void 0 : stateMapper(state[_reduxStore.auditsStoreName])) != null ? _stateMapper : state[_reduxStore.auditsStoreName];
25
+ }, _reactRedux.shallowEqual);
26
+ };
27
+
28
+ exports.useAuditsState = useAuditsState;
29
+
30
+ const useAuditsActions = () => {
31
+ const dispatch = (0, _FronteggStoreContext.useDispatch)();
32
+ return (0, _react.useMemo)(() => (0, _reduxStore.bindActionCreators)(_reduxStore.auditsActions, dispatch), [_reduxStore.auditsActions]);
33
+ };
34
+
35
+ exports.useAuditsActions = useAuditsActions;
36
+
37
+ const sliceReducerActionsBy = reducer => {
38
+ const reducerKeys = Object.keys(reducer);
39
+ const reducerActions = reducerKeys.map(key => ({
40
+ [key]: _reduxStore.auditsActions[key]
41
+ }));
42
+ return reducerActions.reduce((p, n) => (0, _extends2.default)({}, p, n), {});
43
+ };
44
+
45
+ exports.sliceReducerActionsBy = sliceReducerActionsBy;
46
+
47
+ const stateHookGenerator = (stateMapper, subState) => {
48
+ return (0, _FronteggStoreContext.useSelector)(state => {
49
+ var _stateMapper2;
50
+
51
+ return (_stateMapper2 = stateMapper == null ? void 0 : stateMapper(state[_reduxStore.auditsStoreName][subState])) != null ? _stateMapper2 : state[_reduxStore.auditsStoreName][subState];
52
+ }, _reactRedux.shallowEqual);
53
+ };
54
+
55
+ exports.stateHookGenerator = stateHookGenerator;
56
+
57
+ const reducerActionsGenerator = (actions, reducers) => {
58
+ const dispatch = (0, _FronteggStoreContext.useDispatch)();
59
+ return (0, _react.useMemo)(() => (0, _reduxStore.bindActionCreators)((0, _extends2.default)({}, actions, sliceReducerActionsBy(reducers)), dispatch), [dispatch]);
60
+ };
61
+
62
+ exports.reducerActionsGenerator = reducerActionsGenerator;
@@ -1,18 +1,51 @@
1
- 'use strict';
1
+ "use strict";
2
2
 
3
- Object.defineProperty(exports, '__esModule', { value: true });
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ var _exportNames = {
7
+ useAuditsState: true,
8
+ useAuditsActions: true
9
+ };
10
+ Object.defineProperty(exports, "useAuditsActions", {
11
+ enumerable: true,
12
+ get: function () {
13
+ return _hooks.useAuditsActions;
14
+ }
15
+ });
16
+ Object.defineProperty(exports, "useAuditsState", {
17
+ enumerable: true,
18
+ get: function () {
19
+ return _hooks.useAuditsState;
20
+ }
21
+ });
4
22
 
5
- var auditsMetadata = require('../auditsMetadata-d15799a1.js');
6
- require('@frontegg/redux-store');
7
- require('react');
8
- require('react-redux');
9
- require('../FronteggStoreContext-6cfac56c.js');
23
+ var _hooks = require("./hooks");
10
24
 
25
+ var _auditLogs = require("./auditLogs");
11
26
 
27
+ Object.keys(_auditLogs).forEach(function (key) {
28
+ if (key === "default" || key === "__esModule") return;
29
+ if (Object.prototype.hasOwnProperty.call(_exportNames, key)) return;
30
+ if (key in exports && exports[key] === _auditLogs[key]) return;
31
+ Object.defineProperty(exports, key, {
32
+ enumerable: true,
33
+ get: function () {
34
+ return _auditLogs[key];
35
+ }
36
+ });
37
+ });
12
38
 
13
- exports.useAuditLogsActions = auditsMetadata.useAuditLogsActions;
14
- exports.useAuditLogsState = auditsMetadata.useAuditLogsState;
15
- exports.useAuditsActions = auditsMetadata.useAuditsActions;
16
- exports.useAuditsMetadataActions = auditsMetadata.useAuditsMetadataActions;
17
- exports.useAuditsMetadataState = auditsMetadata.useAuditsMetadataState;
18
- exports.useAuditsState = auditsMetadata.useAuditsState;
39
+ var _auditsMetadata = require("./auditsMetadata");
40
+
41
+ Object.keys(_auditsMetadata).forEach(function (key) {
42
+ if (key === "default" || key === "__esModule") return;
43
+ if (Object.prototype.hasOwnProperty.call(_exportNames, key)) return;
44
+ if (key in exports && exports[key] === _auditsMetadata[key]) return;
45
+ Object.defineProperty(exports, key, {
46
+ enumerable: true,
47
+ get: function () {
48
+ return _auditsMetadata[key];
49
+ }
50
+ });
51
+ });
@@ -0,0 +1,18 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.useAcceptInvitationState = exports.useAcceptInvitationActions = void 0;
7
+
8
+ var _reduxStore = require("@frontegg/redux-store");
9
+
10
+ var _hooks = require("./hooks");
11
+
12
+ const useAcceptInvitationState = stateMapper => (0, _hooks.stateHookGenerator)(stateMapper, 'acceptInvitationState');
13
+
14
+ exports.useAcceptInvitationState = useAcceptInvitationState;
15
+
16
+ const useAcceptInvitationActions = () => (0, _hooks.reducerActionsGenerator)(_reduxStore.acceptInvitationActions, _reduxStore.acceptInvitationReducers);
17
+
18
+ exports.useAcceptInvitationActions = useAcceptInvitationActions;
@@ -0,0 +1,18 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.useActivateAccountState = exports.useActivateAccountActions = void 0;
7
+
8
+ var _reduxStore = require("@frontegg/redux-store");
9
+
10
+ var _hooks = require("./hooks");
11
+
12
+ const useActivateAccountState = stateMapper => (0, _hooks.stateHookGenerator)(stateMapper, 'activateState');
13
+
14
+ exports.useActivateAccountState = useActivateAccountState;
15
+
16
+ const useActivateAccountActions = () => (0, _hooks.reducerActionsGenerator)(_reduxStore.activateAccountActions, _reduxStore.activateAccountReducers);
17
+
18
+ exports.useActivateAccountActions = useActivateAccountActions;
@@ -0,0 +1,18 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.useApiTokensState = exports.useApiTokensActions = void 0;
7
+
8
+ var _reduxStore = require("@frontegg/redux-store");
9
+
10
+ var _hooks = require("./hooks");
11
+
12
+ const useApiTokensState = stateMapper => (0, _hooks.stateHookGenerator)(stateMapper, 'apiTokensState');
13
+
14
+ exports.useApiTokensState = useApiTokensState;
15
+
16
+ const useApiTokensActions = () => (0, _hooks.reducerActionsGenerator)(_reduxStore.apiTokensActions, _reduxStore.apiTokensReducers);
17
+
18
+ exports.useApiTokensActions = useApiTokensActions;
@@ -0,0 +1,18 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.useForgotPasswordState = exports.useForgotPasswordActions = void 0;
7
+
8
+ var _reduxStore = require("@frontegg/redux-store");
9
+
10
+ var _hooks = require("./hooks");
11
+
12
+ const useForgotPasswordState = stateMapper => (0, _hooks.stateHookGenerator)(stateMapper, 'forgotPasswordState');
13
+
14
+ exports.useForgotPasswordState = useForgotPasswordState;
15
+
16
+ const useForgotPasswordActions = () => (0, _hooks.reducerActionsGenerator)(_reduxStore.forgotPasswordActions, _reduxStore.forgotPasswordReducers);
17
+
18
+ exports.useForgotPasswordActions = useForgotPasswordActions;
@@ -0,0 +1,127 @@
1
+ "use strict";
2
+
3
+ var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
4
+
5
+ Object.defineProperty(exports, "__esModule", {
6
+ value: true
7
+ });
8
+ exports.useOnRedirectTo = exports.useLoginWithRedirect = exports.useIsAuthenticated = exports.useAuthUserOrNull = exports.useAuthUser = exports.useAuthRoutes = exports.useAuthActions = exports.useAuth = exports.stateHookGenerator = exports.sliceReducerActionsBy = exports.reducerActionsGenerator = void 0;
9
+
10
+ var _extends2 = _interopRequireDefault(require("@babel/runtime/helpers/extends"));
11
+
12
+ var _react = require("react");
13
+
14
+ var _reduxStore = require("@frontegg/redux-store");
15
+
16
+ var _reactRedux = require("react-redux");
17
+
18
+ var _FronteggStoreContext = require("../FronteggStoreContext");
19
+
20
+ var _restApi = require("@frontegg/rest-api");
21
+
22
+ var _common = require("../common");
23
+
24
+ const defaultMapper = {
25
+ state: state => state,
26
+ actions: actions => actions
27
+ };
28
+
29
+ const useAuth = (stateMapper = defaultMapper.state) => {
30
+ return (0, _FronteggStoreContext.useSelector)(state => stateMapper(state[_reduxStore.authStoreName]), _reactRedux.shallowEqual);
31
+ };
32
+
33
+ exports.useAuth = useAuth;
34
+
35
+ const useLoginWithRedirect = () => {
36
+ const dispatch = (0, _FronteggStoreContext.useDispatch)();
37
+ return (0, _react.useMemo)(() => (0, _reduxStore.bindActionCreators)(_reduxStore.authActions.requestHostedLoginAuthorize, dispatch), [_reduxStore.authActions.requestHostedLoginAuthorize]);
38
+ };
39
+
40
+ exports.useLoginWithRedirect = useLoginWithRedirect;
41
+
42
+ const useAuthActions = () => {
43
+ const dispatch = (0, _FronteggStoreContext.useDispatch)();
44
+ return (0, _react.useMemo)(() => (0, _reduxStore.bindActionCreators)(_reduxStore.authActions, dispatch), [_reduxStore.authActions]);
45
+ };
46
+
47
+ exports.useAuthActions = useAuthActions;
48
+
49
+ const useOnRedirectTo = () => {
50
+ var _context$onRedirectTo;
51
+
52
+ const context = (0, _react.useContext)(_common.ShadowDomContext);
53
+ return (_context$onRedirectTo = context == null ? void 0 : context.onRedirectTo) != null ? _context$onRedirectTo : _restApi.ContextHolder.onRedirectTo;
54
+ };
55
+
56
+ exports.useOnRedirectTo = useOnRedirectTo;
57
+
58
+ const useAuthRoutes = () => useAuth(state => (0, _extends2.default)({}, state.routes));
59
+
60
+ exports.useAuthRoutes = useAuthRoutes;
61
+
62
+ const useIsAuthenticated = () => (0, _FronteggStoreContext.useSelector)(({
63
+ [_reduxStore.authStoreName]: {
64
+ isAuthenticated
65
+ }
66
+ }) => isAuthenticated, _reactRedux.shallowEqual);
67
+
68
+ exports.useIsAuthenticated = useIsAuthenticated;
69
+
70
+ const useAuthUser = () => {
71
+ const routes = useAuthRoutes();
72
+ const onRedirectTo = useOnRedirectTo();
73
+ const user = useAuthUserOrNull();
74
+
75
+ if (user == null) {
76
+ onRedirectTo(routes.loginUrl, {
77
+ refresh: true
78
+ });
79
+ return {};
80
+ }
81
+
82
+ return user;
83
+ };
84
+
85
+ exports.useAuthUser = useAuthUser;
86
+
87
+ const useAuthUserOrNull = () => {
88
+ const {
89
+ user
90
+ } = (0, _FronteggStoreContext.useSelector)(({
91
+ [_reduxStore.authStoreName]: {
92
+ user
93
+ }
94
+ }) => ({
95
+ user
96
+ }), _reactRedux.shallowEqual);
97
+ return user || null;
98
+ };
99
+
100
+ exports.useAuthUserOrNull = useAuthUserOrNull;
101
+
102
+ const sliceReducerActionsBy = reducer => {
103
+ const reducerKeys = Object.keys(reducer);
104
+ const reducerActions = reducerKeys.map(key => ({
105
+ [key]: _reduxStore.authActions[key]
106
+ }));
107
+ return reducerActions.reduce((p, n) => (0, _extends2.default)({}, p, n), {});
108
+ };
109
+
110
+ exports.sliceReducerActionsBy = sliceReducerActionsBy;
111
+
112
+ const stateHookGenerator = (stateMapper, subState) => {
113
+ return (0, _FronteggStoreContext.useSelector)(state => {
114
+ var _stateMapper;
115
+
116
+ return (_stateMapper = stateMapper == null ? void 0 : stateMapper(state[_reduxStore.authStoreName][subState])) != null ? _stateMapper : state[_reduxStore.authStoreName][subState];
117
+ }, _reactRedux.shallowEqual);
118
+ };
119
+
120
+ exports.stateHookGenerator = stateHookGenerator;
121
+
122
+ const reducerActionsGenerator = (actions, reducers) => {
123
+ const dispatch = (0, _FronteggStoreContext.useDispatch)();
124
+ return (0, _react.useMemo)(() => (0, _reduxStore.bindActionCreators)((0, _extends2.default)({}, actions, sliceReducerActionsBy(reducers)), dispatch), [dispatch]);
125
+ };
126
+
127
+ exports.reducerActionsGenerator = reducerActionsGenerator;