@frontegg/react-hooks 6.144.0-alpha.2 → 6.144.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.
@@ -14,3 +14,18 @@ export declare const usePermissionEntitlements: (key: string) => Entitlement;
14
14
  @returns if the user is entitled to the given feature or permission (check only one). Attaching the justification if not
15
15
  */
16
16
  export declare const useEntitlements: (options: EntitledToOptions) => Entitlement;
17
+ /**
18
+ @param entitledToOptions including permission or feature key
19
+ @returns an action your can use to detect if the user is entitled to the given feature or permission (check only one). Attaching the justification if not
20
+ */
21
+ export declare const useEntitlementsActions: () => {
22
+ isEntitledTo: (options: EntitledToOptions) => Entitlement;
23
+ };
24
+ /**
25
+ @returns if the option to use entitlements is enabled
26
+ */
27
+ export declare const useEntitlementsOptions: () => {
28
+ isEntitlementsEnabled: boolean;
29
+ isEntitledTo: (options: EntitledToOptions) => Entitlement;
30
+ verifyIsEntitledFF: boolean;
31
+ };
@@ -1,5 +1,8 @@
1
1
  import { getPermissionEntitlements, getFeatureEntitlements, getEntitlements } from '@frontegg/redux-store';
2
2
  import { useAuth } from './hooks';
3
+ import { useMemo } from 'react';
4
+ import { useShadowDom } from '../common';
5
+ import { useFeatureFlags } from '../flags';
3
6
 
4
7
  /**
5
8
  * @returns entitlemenets state as stored in the user
@@ -33,4 +36,35 @@ export const usePermissionEntitlements = key => {
33
36
  export const useEntitlements = options => {
34
37
  const entitlements = useEntitlementsState();
35
38
  return getEntitlements(entitlements, options);
39
+ };
40
+
41
+ /**
42
+ @param entitledToOptions including permission or feature key
43
+ @returns an action your can use to detect if the user is entitled to the given feature or permission (check only one). Attaching the justification if not
44
+ */
45
+ export const useEntitlementsActions = () => {
46
+ const entitlements = useEntitlementsState();
47
+ return useMemo(() => ({
48
+ isEntitledTo: options => getEntitlements(entitlements, options)
49
+ }), [entitlements]);
50
+ };
51
+
52
+ /**
53
+ @returns if the option to use entitlements is enabled
54
+ */
55
+ export const useEntitlementsOptions = () => {
56
+ var _entitlementsOptions$;
57
+ const {
58
+ entitlementsOptions
59
+ } = useShadowDom();
60
+ const isEntitlementsEnabled = (_entitlementsOptions$ = entitlementsOptions == null ? void 0 : entitlementsOptions.enabled) != null ? _entitlementsOptions$ : false;
61
+ const {
62
+ isEntitledTo
63
+ } = useEntitlementsActions();
64
+ const [verifyIsEntitledFF] = useFeatureFlags(['admin-portal-use-is-entitled']);
65
+ return {
66
+ isEntitlementsEnabled,
67
+ isEntitledTo,
68
+ verifyIsEntitledFF
69
+ };
36
70
  };
package/auth/index.d.ts CHANGED
@@ -25,4 +25,3 @@ export * from './customLogin';
25
25
  export * from './MSP/allAccounts';
26
26
  export * from './entitlements';
27
27
  export * from './security/securityCenter';
28
- export * from './sms';
package/auth/index.js CHANGED
@@ -24,5 +24,4 @@ export * from './groups';
24
24
  export * from './customLogin';
25
25
  export * from './MSP/allAccounts';
26
26
  export * from './entitlements';
27
- export * from './security/securityCenter';
28
- export * from './sms';
27
+ export * from './security/securityCenter';
package/index.js CHANGED
@@ -1,4 +1,4 @@
1
- /** @license Frontegg v6.144.0-alpha.2
1
+ /** @license Frontegg v6.144.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.
@@ -3,9 +3,12 @@
3
3
  Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
- exports.usePermissionEntitlements = exports.useFeatureEntitlements = exports.useEntitlements = void 0;
6
+ exports.usePermissionEntitlements = exports.useFeatureEntitlements = exports.useEntitlementsOptions = exports.useEntitlementsActions = exports.useEntitlements = void 0;
7
7
  var _reduxStore = require("@frontegg/redux-store");
8
8
  var _hooks = require("./hooks");
9
+ var _react = require("react");
10
+ var _common = require("../common");
11
+ var _flags = require("../flags");
9
12
  /**
10
13
  * @returns entitlemenets state as stored in the user
11
14
  */
@@ -41,4 +44,37 @@ const useEntitlements = options => {
41
44
  const entitlements = useEntitlementsState();
42
45
  return (0, _reduxStore.getEntitlements)(entitlements, options);
43
46
  };
44
- exports.useEntitlements = useEntitlements;
47
+
48
+ /**
49
+ @param entitledToOptions including permission or feature key
50
+ @returns an action your can use to detect if the user is entitled to the given feature or permission (check only one). Attaching the justification if not
51
+ */
52
+ exports.useEntitlements = useEntitlements;
53
+ const useEntitlementsActions = () => {
54
+ const entitlements = useEntitlementsState();
55
+ return (0, _react.useMemo)(() => ({
56
+ isEntitledTo: options => (0, _reduxStore.getEntitlements)(entitlements, options)
57
+ }), [entitlements]);
58
+ };
59
+
60
+ /**
61
+ @returns if the option to use entitlements is enabled
62
+ */
63
+ exports.useEntitlementsActions = useEntitlementsActions;
64
+ const useEntitlementsOptions = () => {
65
+ var _entitlementsOptions$;
66
+ const {
67
+ entitlementsOptions
68
+ } = (0, _common.useShadowDom)();
69
+ const isEntitlementsEnabled = (_entitlementsOptions$ = entitlementsOptions == null ? void 0 : entitlementsOptions.enabled) != null ? _entitlementsOptions$ : false;
70
+ const {
71
+ isEntitledTo
72
+ } = useEntitlementsActions();
73
+ const [verifyIsEntitledFF] = (0, _flags.useFeatureFlags)(['admin-portal-use-is-entitled']);
74
+ return {
75
+ isEntitlementsEnabled,
76
+ isEntitledTo,
77
+ verifyIsEntitledFF
78
+ };
79
+ };
80
+ exports.useEntitlementsOptions = useEntitlementsOptions;
@@ -373,16 +373,4 @@ Object.keys(_securityCenter).forEach(function (key) {
373
373
  return _securityCenter[key];
374
374
  }
375
375
  });
376
- });
377
- var _sms = require("./sms");
378
- Object.keys(_sms).forEach(function (key) {
379
- if (key === "default" || key === "__esModule") return;
380
- if (Object.prototype.hasOwnProperty.call(_exportNames, key)) return;
381
- if (key in exports && exports[key] === _sms[key]) return;
382
- Object.defineProperty(exports, key, {
383
- enumerable: true,
384
- get: function () {
385
- return _sms[key];
386
- }
387
- });
388
376
  });
package/node/index.js CHANGED
@@ -1,4 +1,4 @@
1
- /** @license Frontegg v6.144.0-alpha.2
1
+ /** @license Frontegg v6.144.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.144.0-alpha.2",
3
+ "version": "6.144.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.144.0-alpha.2",
10
- "@frontegg/types": "6.144.0-alpha.2",
9
+ "@frontegg/redux-store": "6.144.0",
10
+ "@frontegg/types": "6.144.0",
11
11
  "@types/react": "*",
12
12
  "get-value": "^3.0.1",
13
13
  "react-redux": "^7.x"
package/auth/sms.d.ts DELETED
@@ -1,6 +0,0 @@
1
- import { SmsActions, SmsState } from '@frontegg/redux-store';
2
- declare type AuthSmsStateMapper<S> = (state: SmsState) => S;
3
- export declare function useSmsState(): SmsState;
4
- export declare function useSmsState<S>(stateMapper: AuthSmsStateMapper<S>): S;
5
- export declare const useSmsActions: () => SmsActions;
6
- export {};
package/auth/sms.js DELETED
@@ -1,7 +0,0 @@
1
- import { smsActions, smsReducers } from '@frontegg/redux-store';
2
- import { reducerActionsGenerator, stateHookGenerator } from './hooks';
3
- const defaultMapper = state => state;
4
- export function useSmsState(stateMapper = defaultMapper) {
5
- return stateHookGenerator(stateMapper, 'smsState');
6
- }
7
- export const useSmsActions = () => reducerActionsGenerator(smsActions, smsReducers);
package/node/auth/sms.js DELETED
@@ -1,15 +0,0 @@
1
- "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
6
- exports.useSmsActions = void 0;
7
- exports.useSmsState = useSmsState;
8
- var _reduxStore = require("@frontegg/redux-store");
9
- var _hooks = require("./hooks");
10
- const defaultMapper = state => state;
11
- function useSmsState(stateMapper = defaultMapper) {
12
- return (0, _hooks.stateHookGenerator)(stateMapper, 'smsState');
13
- }
14
- const useSmsActions = () => (0, _hooks.reducerActionsGenerator)(_reduxStore.smsActions, _reduxStore.smsReducers);
15
- exports.useSmsActions = useSmsActions;