@frontegg/react-hooks 6.7.0 → 6.8.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.
package/auth/index.d.ts CHANGED
@@ -16,3 +16,4 @@ export * from './tenants';
16
16
  export * from './roles';
17
17
  export * from './sessions';
18
18
  export * from './sessionsPolicy';
19
+ export * from './restrictions';
package/auth/index.js CHANGED
@@ -15,4 +15,5 @@ export * from './securityPolicy';
15
15
  export * from './tenants';
16
16
  export * from './roles';
17
17
  export * from './sessions';
18
- export * from './sessionsPolicy';
18
+ export * from './sessionsPolicy';
19
+ export * from './restrictions';
@@ -0,0 +1,17 @@
1
+ import { RestrictionsActions, RestrictionsState } from '@frontegg/redux-store';
2
+ export declare type RestrictionsStateMapper<S> = (state: RestrictionsState) => S;
3
+ export declare function useRestrictionsState(): RestrictionsState;
4
+ export declare function useRestrictionsState<S>(stateMapper: RestrictionsStateMapper<S>): S;
5
+ export declare const useRestrictionsActions: () => RestrictionsActions;
6
+ export declare const useIpRestrictions: (loadOnMount?: boolean) => {
7
+ loading: boolean;
8
+ saving: boolean | undefined;
9
+ error: any;
10
+ data: {
11
+ config: import("@frontegg/rest-api").IPRestrictionsConfig;
12
+ restrictions: import("@frontegg/rest-api").IpRestriction[];
13
+ } | undefined;
14
+ pagination: import("@frontegg/rest-api").GetIPRestrictionsParams;
15
+ totalPages: number;
16
+ userIpValid: boolean;
17
+ };
@@ -0,0 +1,36 @@
1
+ import { restrictionsReducers, restrictionsActions } from '@frontegg/redux-store';
2
+ import { useEffect } from 'react';
3
+ import { reducerActionsGenerator, stateHookGenerator } from './hooks';
4
+
5
+ const defaultMapper = state => state;
6
+
7
+ export function useRestrictionsState(stateMapper = defaultMapper) {
8
+ return stateHookGenerator(stateMapper, 'restrictionsState');
9
+ }
10
+ export const useRestrictionsActions = () => reducerActionsGenerator(restrictionsActions, restrictionsReducers);
11
+ export const useIpRestrictions = (loadOnMount = false) => {
12
+ const {
13
+ loading,
14
+ data,
15
+ saving,
16
+ error,
17
+ pagination,
18
+ totalPages,
19
+ userIpValid
20
+ } = useRestrictionsState(state => state.ipRestrictions);
21
+ const {
22
+ loadIpRestrictions
23
+ } = useRestrictionsActions();
24
+ useEffect(() => {
25
+ (loadOnMount || !data) && loadIpRestrictions(); // eslint-disable-next-line react-hooks/exhaustive-deps
26
+ }, [loadOnMount, loadIpRestrictions]);
27
+ return {
28
+ loading,
29
+ saving,
30
+ error,
31
+ data,
32
+ pagination,
33
+ totalPages,
34
+ userIpValid
35
+ };
36
+ };
package/index.js CHANGED
@@ -1,4 +1,4 @@
1
- /** @license Frontegg v6.7.0
1
+ /** @license Frontegg v6.8.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.
@@ -300,4 +300,18 @@ Object.keys(_sessionsPolicy).forEach(function (key) {
300
300
  return _sessionsPolicy[key];
301
301
  }
302
302
  });
303
+ });
304
+
305
+ var _restrictions = require("./restrictions");
306
+
307
+ Object.keys(_restrictions).forEach(function (key) {
308
+ if (key === "default" || key === "__esModule") return;
309
+ if (Object.prototype.hasOwnProperty.call(_exportNames, key)) return;
310
+ if (key in exports && exports[key] === _restrictions[key]) return;
311
+ Object.defineProperty(exports, key, {
312
+ enumerable: true,
313
+ get: function () {
314
+ return _restrictions[key];
315
+ }
316
+ });
303
317
  });
@@ -0,0 +1,52 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.useRestrictionsActions = exports.useIpRestrictions = void 0;
7
+ exports.useRestrictionsState = useRestrictionsState;
8
+
9
+ var _reduxStore = require("@frontegg/redux-store");
10
+
11
+ var _react = require("react");
12
+
13
+ var _hooks = require("./hooks");
14
+
15
+ const defaultMapper = state => state;
16
+
17
+ function useRestrictionsState(stateMapper = defaultMapper) {
18
+ return (0, _hooks.stateHookGenerator)(stateMapper, 'restrictionsState');
19
+ }
20
+
21
+ const useRestrictionsActions = () => (0, _hooks.reducerActionsGenerator)(_reduxStore.restrictionsActions, _reduxStore.restrictionsReducers);
22
+
23
+ exports.useRestrictionsActions = useRestrictionsActions;
24
+
25
+ const useIpRestrictions = (loadOnMount = false) => {
26
+ const {
27
+ loading,
28
+ data,
29
+ saving,
30
+ error,
31
+ pagination,
32
+ totalPages,
33
+ userIpValid
34
+ } = useRestrictionsState(state => state.ipRestrictions);
35
+ const {
36
+ loadIpRestrictions
37
+ } = useRestrictionsActions();
38
+ (0, _react.useEffect)(() => {
39
+ (loadOnMount || !data) && loadIpRestrictions(); // eslint-disable-next-line react-hooks/exhaustive-deps
40
+ }, [loadOnMount, loadIpRestrictions]);
41
+ return {
42
+ loading,
43
+ saving,
44
+ error,
45
+ data,
46
+ pagination,
47
+ totalPages,
48
+ userIpValid
49
+ };
50
+ };
51
+
52
+ exports.useIpRestrictions = useIpRestrictions;
package/node/index.js CHANGED
@@ -1,4 +1,4 @@
1
- /** @license Frontegg v6.7.0
1
+ /** @license Frontegg v6.8.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.7.0",
3
+ "version": "6.8.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.7.0",
10
- "@frontegg/types": "6.7.0",
9
+ "@frontegg/redux-store": "6.8.0",
10
+ "@frontegg/types": "6.8.0",
11
11
  "@types/react": "*",
12
12
  "react-redux": "^7.x"
13
13
  },