@frontegg/react-hooks 6.184.0-alpha.1 → 6.185.0-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.
- package/auth/entitlements.js +11 -24
- package/index.js +1 -1
- package/node/auth/entitlements.js +10 -23
- package/node/index.js +1 -1
- package/package.json +3 -3
package/auth/entitlements.js
CHANGED
|
@@ -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 {
|
|
4
|
+
import { useShadowDom } from '../common';
|
|
6
5
|
import { useFeatureFlags } from '../flags';
|
|
7
6
|
|
|
8
7
|
/**
|
|
@@ -21,23 +20,18 @@ const useUserState = () => useAuth(({
|
|
|
21
20
|
|
|
22
21
|
/**
|
|
23
22
|
* @param customAttributes user attributes
|
|
24
|
-
* @returns is entitled query data including:
|
|
23
|
+
* @returns is entitled query data including: entitlements state and final attributes (consumer and frontegg)
|
|
25
24
|
*/
|
|
26
25
|
const useEntitlementsQueryData = customAttributes => {
|
|
27
26
|
const user = useUserState();
|
|
28
27
|
const entitlements = useEntitlementsState();
|
|
29
|
-
const {
|
|
30
|
-
appName
|
|
31
|
-
} = useRootState();
|
|
32
|
-
const [useEntitlementsV2] = FeatureFlags.getFeatureFlags([USE_ENTITLEMENTS_V2_ENDPOINT_FF], appName);
|
|
33
28
|
const attributes = {
|
|
34
29
|
custom: customAttributes,
|
|
35
30
|
jwt: user
|
|
36
31
|
};
|
|
37
32
|
return {
|
|
38
33
|
entitlements,
|
|
39
|
-
attributes
|
|
40
|
-
isV2: useEntitlementsV2
|
|
34
|
+
attributes
|
|
41
35
|
};
|
|
42
36
|
};
|
|
43
37
|
|
|
@@ -49,10 +43,9 @@ const useEntitlementsQueryData = customAttributes => {
|
|
|
49
43
|
export const useFeatureEntitlements = (key, customAttributes) => {
|
|
50
44
|
const {
|
|
51
45
|
entitlements,
|
|
52
|
-
attributes
|
|
53
|
-
isV2
|
|
46
|
+
attributes
|
|
54
47
|
} = useEntitlementsQueryData(customAttributes);
|
|
55
|
-
return getFeatureEntitlements(entitlements, key, attributes
|
|
48
|
+
return getFeatureEntitlements(entitlements, key, attributes);
|
|
56
49
|
};
|
|
57
50
|
|
|
58
51
|
/**
|
|
@@ -63,10 +56,9 @@ export const useFeatureEntitlements = (key, customAttributes) => {
|
|
|
63
56
|
export const usePermissionEntitlements = (key, customAttributes) => {
|
|
64
57
|
const {
|
|
65
58
|
entitlements,
|
|
66
|
-
attributes
|
|
67
|
-
isV2
|
|
59
|
+
attributes
|
|
68
60
|
} = useEntitlementsQueryData(customAttributes);
|
|
69
|
-
return getPermissionEntitlements(entitlements, key, attributes
|
|
61
|
+
return getPermissionEntitlements(entitlements, key, attributes);
|
|
70
62
|
};
|
|
71
63
|
|
|
72
64
|
/**
|
|
@@ -77,10 +69,9 @@ export const usePermissionEntitlements = (key, customAttributes) => {
|
|
|
77
69
|
export const useEntitlements = (options, customAttributes) => {
|
|
78
70
|
const {
|
|
79
71
|
entitlements,
|
|
80
|
-
attributes
|
|
81
|
-
isV2
|
|
72
|
+
attributes
|
|
82
73
|
} = useEntitlementsQueryData(customAttributes);
|
|
83
|
-
return getEntitlements(entitlements, options, attributes
|
|
74
|
+
return getEntitlements(entitlements, options, attributes);
|
|
84
75
|
};
|
|
85
76
|
|
|
86
77
|
/**
|
|
@@ -91,19 +82,15 @@ export const useEntitlementsActions = () => {
|
|
|
91
82
|
// this code is duplicated because React is yelling when using useEntitlementsQueryData inside the isEntitledTo function because it's not a hook
|
|
92
83
|
const user = useUserState();
|
|
93
84
|
const entitlements = useEntitlementsState();
|
|
94
|
-
const {
|
|
95
|
-
appName
|
|
96
|
-
} = useRootState();
|
|
97
|
-
const [useEntitlementsV2] = FeatureFlags.getFeatureFlags([USE_ENTITLEMENTS_V2_ENDPOINT_FF], appName);
|
|
98
85
|
return useMemo(() => ({
|
|
99
86
|
isEntitledTo: (options, customAttributes) => {
|
|
100
87
|
const attributes = {
|
|
101
88
|
custom: customAttributes,
|
|
102
89
|
jwt: user
|
|
103
90
|
};
|
|
104
|
-
return getEntitlements(entitlements, options, attributes
|
|
91
|
+
return getEntitlements(entitlements, options, attributes);
|
|
105
92
|
}
|
|
106
|
-
}), [user, entitlements
|
|
93
|
+
}), [user, entitlements]);
|
|
107
94
|
};
|
|
108
95
|
|
|
109
96
|
/**
|
package/index.js
CHANGED
|
@@ -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");
|
|
@@ -26,23 +25,18 @@ const useUserState = () => (0, _hooks.useAuth)(({
|
|
|
26
25
|
|
|
27
26
|
/**
|
|
28
27
|
* @param customAttributes user attributes
|
|
29
|
-
* @returns is entitled query data including:
|
|
28
|
+
* @returns is entitled query data including: entitlements state and final attributes (consumer and frontegg)
|
|
30
29
|
*/
|
|
31
30
|
const useEntitlementsQueryData = customAttributes => {
|
|
32
31
|
const user = useUserState();
|
|
33
32
|
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
33
|
const attributes = {
|
|
39
34
|
custom: customAttributes,
|
|
40
35
|
jwt: user
|
|
41
36
|
};
|
|
42
37
|
return {
|
|
43
38
|
entitlements,
|
|
44
|
-
attributes
|
|
45
|
-
isV2: useEntitlementsV2
|
|
39
|
+
attributes
|
|
46
40
|
};
|
|
47
41
|
};
|
|
48
42
|
|
|
@@ -54,10 +48,9 @@ const useEntitlementsQueryData = customAttributes => {
|
|
|
54
48
|
const useFeatureEntitlements = (key, customAttributes) => {
|
|
55
49
|
const {
|
|
56
50
|
entitlements,
|
|
57
|
-
attributes
|
|
58
|
-
isV2
|
|
51
|
+
attributes
|
|
59
52
|
} = useEntitlementsQueryData(customAttributes);
|
|
60
|
-
return (0, _reduxStore.getFeatureEntitlements)(entitlements, key, attributes
|
|
53
|
+
return (0, _reduxStore.getFeatureEntitlements)(entitlements, key, attributes);
|
|
61
54
|
};
|
|
62
55
|
|
|
63
56
|
/**
|
|
@@ -69,10 +62,9 @@ exports.useFeatureEntitlements = useFeatureEntitlements;
|
|
|
69
62
|
const usePermissionEntitlements = (key, customAttributes) => {
|
|
70
63
|
const {
|
|
71
64
|
entitlements,
|
|
72
|
-
attributes
|
|
73
|
-
isV2
|
|
65
|
+
attributes
|
|
74
66
|
} = useEntitlementsQueryData(customAttributes);
|
|
75
|
-
return (0, _reduxStore.getPermissionEntitlements)(entitlements, key, attributes
|
|
67
|
+
return (0, _reduxStore.getPermissionEntitlements)(entitlements, key, attributes);
|
|
76
68
|
};
|
|
77
69
|
|
|
78
70
|
/**
|
|
@@ -84,10 +76,9 @@ exports.usePermissionEntitlements = usePermissionEntitlements;
|
|
|
84
76
|
const useEntitlements = (options, customAttributes) => {
|
|
85
77
|
const {
|
|
86
78
|
entitlements,
|
|
87
|
-
attributes
|
|
88
|
-
isV2
|
|
79
|
+
attributes
|
|
89
80
|
} = useEntitlementsQueryData(customAttributes);
|
|
90
|
-
return (0, _reduxStore.getEntitlements)(entitlements, options, attributes
|
|
81
|
+
return (0, _reduxStore.getEntitlements)(entitlements, options, attributes);
|
|
91
82
|
};
|
|
92
83
|
|
|
93
84
|
/**
|
|
@@ -99,19 +90,15 @@ const useEntitlementsActions = () => {
|
|
|
99
90
|
// this code is duplicated because React is yelling when using useEntitlementsQueryData inside the isEntitledTo function because it's not a hook
|
|
100
91
|
const user = useUserState();
|
|
101
92
|
const entitlements = useEntitlementsState();
|
|
102
|
-
const {
|
|
103
|
-
appName
|
|
104
|
-
} = (0, _common.useRootState)();
|
|
105
|
-
const [useEntitlementsV2] = _restApi.FeatureFlags.getFeatureFlags([_restApi.USE_ENTITLEMENTS_V2_ENDPOINT_FF], appName);
|
|
106
93
|
return (0, _react.useMemo)(() => ({
|
|
107
94
|
isEntitledTo: (options, customAttributes) => {
|
|
108
95
|
const attributes = {
|
|
109
96
|
custom: customAttributes,
|
|
110
97
|
jwt: user
|
|
111
98
|
};
|
|
112
|
-
return (0, _reduxStore.getEntitlements)(entitlements, options, attributes
|
|
99
|
+
return (0, _reduxStore.getEntitlements)(entitlements, options, attributes);
|
|
113
100
|
}
|
|
114
|
-
}), [user, entitlements
|
|
101
|
+
}), [user, entitlements]);
|
|
115
102
|
};
|
|
116
103
|
|
|
117
104
|
/**
|
package/node/index.js
CHANGED
package/package.json
CHANGED
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@frontegg/react-hooks",
|
|
3
|
-
"version": "6.
|
|
3
|
+
"version": "6.185.0-alpha.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.
|
|
10
|
-
"@frontegg/types": "6.
|
|
9
|
+
"@frontegg/redux-store": "6.185.0-alpha.0",
|
|
10
|
+
"@frontegg/types": "6.185.0-alpha.0",
|
|
11
11
|
"@types/react": "*",
|
|
12
12
|
"get-value": "^3.0.1",
|
|
13
13
|
"react-redux": "^7.x"
|