@frontegg/react-hooks 6.147.0-alpha.6 → 6.147.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.
@@ -1,35 +1,31 @@
1
1
  import { Entitlement, EntitledToOptions } from '@frontegg/redux-store';
2
- import { CustomAttributes } from '@frontegg/entitlements-javascript-commons';
3
2
  /**
4
- @param key feature key
5
- @param customAttributes user attributes
6
- @returns if the user is entitled to the given feature and attributes. Attaching the justification if not
3
+ @param key
4
+ @returns if the user is entitled to the given feature. Attaching the justification if not
7
5
  */
8
- export declare const useFeatureEntitlements: (key: string, customAttributes?: Record<string, string | number | boolean | Date> | undefined) => Entitlement;
6
+ export declare const useFeatureEntitlements: (key: string) => Entitlement;
9
7
  /**
10
- @param key permission key
11
- @param customAttributes user attributes
12
- @returns if the user is entitled to the given permission and attributes. Attaching the justification if not
8
+ @param key
9
+ @returns if the user is entitled to the given permission. Attaching the justification if not
13
10
  */
14
- export declare const usePermissionEntitlements: (key: string, customAttributes?: Record<string, string | number | boolean | Date> | undefined) => Entitlement;
11
+ export declare const usePermissionEntitlements: (key: string) => Entitlement;
15
12
  /**
16
13
  @param entitledToOptions including permission or feature key
17
- @param customAttributes user attributes
18
- @returns if the user is entitled to the given feature or permission and attributes (check only one). Attaching the justification if not
14
+ @returns if the user is entitled to the given feature or permission (check only one). Attaching the justification if not
19
15
  */
20
- export declare const useEntitlements: (options: EntitledToOptions, customAttributes?: Record<string, string | number | boolean | Date> | undefined) => Entitlement;
16
+ export declare const useEntitlements: (options: EntitledToOptions) => Entitlement;
21
17
  /**
22
18
  @param entitledToOptions including permission or feature key
23
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
24
20
  */
25
21
  export declare const useEntitlementsActions: () => {
26
- isEntitledTo: (options: EntitledToOptions, customAttributes?: Record<string, string | number | boolean | Date> | undefined) => Entitlement;
22
+ isEntitledTo: (options: EntitledToOptions) => Entitlement;
27
23
  };
28
24
  /**
29
25
  @returns if the option to use entitlements is enabled
30
26
  */
31
27
  export declare const useEntitlementsOptions: () => {
32
28
  isEntitlementsEnabled: boolean;
33
- isEntitledTo: (options: EntitledToOptions, customAttributes?: Record<string, string | number | boolean | Date> | undefined) => Entitlement;
29
+ isEntitledTo: (options: EntitledToOptions) => Entitlement;
34
30
  verifyIsEntitledFF: boolean;
35
31
  };
@@ -1,8 +1,7 @@
1
1
  import { getPermissionEntitlements, getFeatureEntitlements, getEntitlements } from '@frontegg/redux-store';
2
- import { FeatureFlags, USE_ENTITLEMENTS_V2_ENDPOINT_FF } from '@frontegg/rest-api';
3
2
  import { useAuth } from './hooks';
4
3
  import { useMemo } from 'react';
5
- import { useRootState, useShadowDom } from '../common';
4
+ import { useShadowDom } from '../common';
6
5
  import { useFeatureFlags } from '../flags';
7
6
 
8
7
  /**
@@ -13,74 +12,30 @@ const useEntitlementsState = () => useAuth(({
13
12
  }) => user == null ? void 0 : user.entitlements);
14
13
 
15
14
  /**
16
- * @returns user state
17
- */
18
- const useUserState = () => useAuth(({
19
- user
20
- }) => user);
21
-
22
- /**
23
- * @param customAttributes user attributes
24
- * @returns is entitled query data including: entitltments state, final attributes (consumer and frontegg) and API version to use
25
- */
26
- const useEntitlementsQueryData = customAttributes => {
27
- const user = useUserState();
28
- const entitlements = useEntitlementsState();
29
- const {
30
- appName
31
- } = useRootState();
32
- const [useEntitlementsV2] = FeatureFlags.getFeatureFlags([USE_ENTITLEMENTS_V2_ENDPOINT_FF], appName);
33
- const attributes = {
34
- custom: customAttributes,
35
- frontegg: user
36
- };
37
- return {
38
- entitlements,
39
- attributes,
40
- isV2: useEntitlementsV2
41
- };
42
- };
43
-
44
- /**
45
- @param key feature key
46
- @param customAttributes user attributes
47
- @returns if the user is entitled to the given feature and attributes. Attaching the justification if not
15
+ @param key
16
+ @returns if the user is entitled to the given feature. Attaching the justification if not
48
17
  */
49
- export const useFeatureEntitlements = (key, customAttributes) => {
50
- const {
51
- entitlements,
52
- attributes,
53
- isV2
54
- } = useEntitlementsQueryData(customAttributes);
55
- return getFeatureEntitlements(entitlements, key, attributes, isV2);
18
+ export const useFeatureEntitlements = key => {
19
+ const entitlements = useEntitlementsState();
20
+ return getFeatureEntitlements(entitlements, key);
56
21
  };
57
22
 
58
23
  /**
59
- @param key permission key
60
- @param customAttributes user attributes
61
- @returns if the user is entitled to the given permission and attributes. Attaching the justification if not
24
+ @param key
25
+ @returns if the user is entitled to the given permission. Attaching the justification if not
62
26
  */
63
- export const usePermissionEntitlements = (key, customAttributes) => {
64
- const {
65
- entitlements,
66
- attributes,
67
- isV2
68
- } = useEntitlementsQueryData(customAttributes);
69
- return getPermissionEntitlements(entitlements, key, attributes, isV2);
27
+ export const usePermissionEntitlements = key => {
28
+ const entitlements = useEntitlementsState();
29
+ return getPermissionEntitlements(entitlements, key);
70
30
  };
71
31
 
72
32
  /**
73
33
  @param entitledToOptions including permission or feature key
74
- @param customAttributes user attributes
75
- @returns if the user is entitled to the given feature or permission and attributes (check only one). Attaching the justification if not
34
+ @returns if the user is entitled to the given feature or permission (check only one). Attaching the justification if not
76
35
  */
77
- export const useEntitlements = (options, customAttributes) => {
78
- const {
79
- entitlements,
80
- attributes,
81
- isV2
82
- } = useEntitlementsQueryData(customAttributes);
83
- return getEntitlements(entitlements, options, attributes, isV2);
36
+ export const useEntitlements = options => {
37
+ const entitlements = useEntitlementsState();
38
+ return getEntitlements(entitlements, options);
84
39
  };
85
40
 
86
41
  /**
@@ -88,16 +43,10 @@ export const useEntitlements = (options, customAttributes) => {
88
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
89
44
  */
90
45
  export const useEntitlementsActions = () => {
46
+ const entitlements = useEntitlementsState();
91
47
  return useMemo(() => ({
92
- isEntitledTo: (options, customAttributes) => {
93
- const {
94
- entitlements,
95
- attributes,
96
- isV2
97
- } = useEntitlementsQueryData(customAttributes);
98
- return getEntitlements(entitlements, options, attributes, isV2);
99
- }
100
- }), []);
48
+ isEntitledTo: options => getEntitlements(entitlements, options)
49
+ }), [entitlements]);
101
50
  };
102
51
 
103
52
  /**
package/index.js CHANGED
@@ -1,4 +1,4 @@
1
- /** @license Frontegg v6.147.0-alpha.6
1
+ /** @license Frontegg v6.147.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.
@@ -5,7 +5,6 @@ Object.defineProperty(exports, "__esModule", {
5
5
  });
6
6
  exports.usePermissionEntitlements = exports.useFeatureEntitlements = exports.useEntitlementsOptions = exports.useEntitlementsActions = exports.useEntitlements = void 0;
7
7
  var _reduxStore = require("@frontegg/redux-store");
8
- var _restApi = require("@frontegg/rest-api");
9
8
  var _hooks = require("./hooks");
10
9
  var _react = require("react");
11
10
  var _common = require("../common");
@@ -18,76 +17,32 @@ const useEntitlementsState = () => (0, _hooks.useAuth)(({
18
17
  }) => user == null ? void 0 : user.entitlements);
19
18
 
20
19
  /**
21
- * @returns user state
22
- */
23
- const useUserState = () => (0, _hooks.useAuth)(({
24
- user
25
- }) => user);
26
-
27
- /**
28
- * @param customAttributes user attributes
29
- * @returns is entitled query data including: entitltments state, final attributes (consumer and frontegg) and API version to use
30
- */
31
- const useEntitlementsQueryData = customAttributes => {
32
- const user = useUserState();
33
- const entitlements = useEntitlementsState();
34
- const {
35
- appName
36
- } = (0, _common.useRootState)();
37
- const [useEntitlementsV2] = _restApi.FeatureFlags.getFeatureFlags([_restApi.USE_ENTITLEMENTS_V2_ENDPOINT_FF], appName);
38
- const attributes = {
39
- custom: customAttributes,
40
- frontegg: user
41
- };
42
- return {
43
- entitlements,
44
- attributes,
45
- isV2: useEntitlementsV2
46
- };
47
- };
48
-
49
- /**
50
- @param key feature key
51
- @param customAttributes user attributes
52
- @returns if the user is entitled to the given feature and attributes. Attaching the justification if not
20
+ @param key
21
+ @returns if the user is entitled to the given feature. Attaching the justification if not
53
22
  */
54
- const useFeatureEntitlements = (key, customAttributes) => {
55
- const {
56
- entitlements,
57
- attributes,
58
- isV2
59
- } = useEntitlementsQueryData(customAttributes);
60
- return (0, _reduxStore.getFeatureEntitlements)(entitlements, key, attributes, isV2);
23
+ const useFeatureEntitlements = key => {
24
+ const entitlements = useEntitlementsState();
25
+ return (0, _reduxStore.getFeatureEntitlements)(entitlements, key);
61
26
  };
62
27
 
63
28
  /**
64
- @param key permission key
65
- @param customAttributes user attributes
66
- @returns if the user is entitled to the given permission and attributes. Attaching the justification if not
29
+ @param key
30
+ @returns if the user is entitled to the given permission. Attaching the justification if not
67
31
  */
68
32
  exports.useFeatureEntitlements = useFeatureEntitlements;
69
- const usePermissionEntitlements = (key, customAttributes) => {
70
- const {
71
- entitlements,
72
- attributes,
73
- isV2
74
- } = useEntitlementsQueryData(customAttributes);
75
- return (0, _reduxStore.getPermissionEntitlements)(entitlements, key, attributes, isV2);
33
+ const usePermissionEntitlements = key => {
34
+ const entitlements = useEntitlementsState();
35
+ return (0, _reduxStore.getPermissionEntitlements)(entitlements, key);
76
36
  };
77
37
 
78
38
  /**
79
39
  @param entitledToOptions including permission or feature key
80
- @param customAttributes user attributes
81
- @returns if the user is entitled to the given feature or permission and attributes (check only one). Attaching the justification if not
40
+ @returns if the user is entitled to the given feature or permission (check only one). Attaching the justification if not
82
41
  */
83
42
  exports.usePermissionEntitlements = usePermissionEntitlements;
84
- const useEntitlements = (options, customAttributes) => {
85
- const {
86
- entitlements,
87
- attributes,
88
- isV2
89
- } = useEntitlementsQueryData(customAttributes);
90
- return (0, _reduxStore.getEntitlements)(entitlements, options, attributes, isV2);
43
+ const useEntitlements = options => {
44
+ const entitlements = useEntitlementsState();
45
+ return (0, _reduxStore.getEntitlements)(entitlements, options);
91
46
  };
92
47
 
93
48
  /**
@@ -96,16 +51,10 @@ const useEntitlements = (options, customAttributes) => {
96
51
  */
97
52
  exports.useEntitlements = useEntitlements;
98
53
  const useEntitlementsActions = () => {
54
+ const entitlements = useEntitlementsState();
99
55
  return (0, _react.useMemo)(() => ({
100
- isEntitledTo: (options, customAttributes) => {
101
- const {
102
- entitlements,
103
- attributes,
104
- isV2
105
- } = useEntitlementsQueryData(customAttributes);
106
- return (0, _reduxStore.getEntitlements)(entitlements, options, attributes, isV2);
107
- }
108
- }), []);
56
+ isEntitledTo: options => (0, _reduxStore.getEntitlements)(entitlements, options)
57
+ }), [entitlements]);
109
58
  };
110
59
 
111
60
  /**
package/node/index.js CHANGED
@@ -1,4 +1,4 @@
1
- /** @license Frontegg v6.147.0-alpha.6
1
+ /** @license Frontegg v6.147.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.147.0-alpha.6",
3
+ "version": "6.147.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.147.0-alpha.6",
10
- "@frontegg/types": "6.147.0-alpha.6",
9
+ "@frontegg/redux-store": "6.147.0",
10
+ "@frontegg/types": "6.147.0",
11
11
  "@types/react": "*",
12
12
  "get-value": "^3.0.1",
13
13
  "react-redux": "^7.x"