@frontegg/react-hooks 6.148.0-alpha.0 → 6.148.0-alpha.1
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.d.ts +10 -14
- package/auth/entitlements.js +17 -74
- package/index.js +1 -1
- package/node/auth/entitlements.js +16 -73
- package/node/index.js +1 -1
- package/package.json +3 -3
package/auth/entitlements.d.ts
CHANGED
|
@@ -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
|
|
5
|
-
@
|
|
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
|
|
6
|
+
export declare const useFeatureEntitlements: (key: string) => Entitlement;
|
|
9
7
|
/**
|
|
10
|
-
@param key
|
|
11
|
-
@
|
|
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
|
|
11
|
+
export declare const usePermissionEntitlements: (key: string) => Entitlement;
|
|
15
12
|
/**
|
|
16
13
|
@param entitledToOptions including permission or feature key
|
|
17
|
-
@
|
|
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
|
|
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
|
|
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
|
|
29
|
+
isEntitledTo: (options: EntitledToOptions) => Entitlement;
|
|
34
30
|
verifyIsEntitledFF: boolean;
|
|
35
31
|
};
|
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
|
/**
|
|
@@ -13,74 +12,30 @@ const useEntitlementsState = () => useAuth(({
|
|
|
13
12
|
}) => user == null ? void 0 : user.entitlements);
|
|
14
13
|
|
|
15
14
|
/**
|
|
16
|
-
|
|
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
|
-
jwt: 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 =
|
|
50
|
-
const
|
|
51
|
-
|
|
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
|
|
60
|
-
@
|
|
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 =
|
|
64
|
-
const
|
|
65
|
-
|
|
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
|
-
@
|
|
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 =
|
|
78
|
-
const
|
|
79
|
-
|
|
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,22 +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 = () => {
|
|
91
|
-
// this code is duplicated because React is yelling when using useEntitlementsQueryData inside the isEntitledTo function because it's not a hook
|
|
92
|
-
const user = useUserState();
|
|
93
46
|
const entitlements = useEntitlementsState();
|
|
94
|
-
const {
|
|
95
|
-
appName
|
|
96
|
-
} = useRootState();
|
|
97
|
-
const [useEntitlementsV2] = FeatureFlags.getFeatureFlags([USE_ENTITLEMENTS_V2_ENDPOINT_FF], appName);
|
|
98
47
|
return useMemo(() => ({
|
|
99
|
-
isEntitledTo: (
|
|
100
|
-
|
|
101
|
-
custom: customAttributes,
|
|
102
|
-
jwt: user
|
|
103
|
-
};
|
|
104
|
-
return getEntitlements(entitlements, options, attributes, useEntitlementsV2);
|
|
105
|
-
}
|
|
106
|
-
}), [user, entitlements, useEntitlementsV2]);
|
|
48
|
+
isEntitledTo: options => getEntitlements(entitlements, options)
|
|
49
|
+
}), [entitlements]);
|
|
107
50
|
};
|
|
108
51
|
|
|
109
52
|
/**
|
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");
|
|
@@ -18,76 +17,32 @@ const useEntitlementsState = () => (0, _hooks.useAuth)(({
|
|
|
18
17
|
}) => user == null ? void 0 : user.entitlements);
|
|
19
18
|
|
|
20
19
|
/**
|
|
21
|
-
|
|
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
|
-
jwt: 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 =
|
|
55
|
-
const
|
|
56
|
-
|
|
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
|
|
65
|
-
@
|
|
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 =
|
|
70
|
-
const
|
|
71
|
-
|
|
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
|
-
@
|
|
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 =
|
|
85
|
-
const
|
|
86
|
-
|
|
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,22 +51,10 @@ const useEntitlements = (options, customAttributes) => {
|
|
|
96
51
|
*/
|
|
97
52
|
exports.useEntitlements = useEntitlements;
|
|
98
53
|
const useEntitlementsActions = () => {
|
|
99
|
-
// this code is duplicated because React is yelling when using useEntitlementsQueryData inside the isEntitledTo function because it's not a hook
|
|
100
|
-
const user = useUserState();
|
|
101
54
|
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
55
|
return (0, _react.useMemo)(() => ({
|
|
107
|
-
isEntitledTo: (
|
|
108
|
-
|
|
109
|
-
custom: customAttributes,
|
|
110
|
-
jwt: user
|
|
111
|
-
};
|
|
112
|
-
return (0, _reduxStore.getEntitlements)(entitlements, options, attributes, useEntitlementsV2);
|
|
113
|
-
}
|
|
114
|
-
}), [user, entitlements, useEntitlementsV2]);
|
|
56
|
+
isEntitledTo: options => (0, _reduxStore.getEntitlements)(entitlements, options)
|
|
57
|
+
}), [entitlements]);
|
|
115
58
|
};
|
|
116
59
|
|
|
117
60
|
/**
|
package/node/index.js
CHANGED
package/package.json
CHANGED
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@frontegg/react-hooks",
|
|
3
|
-
"version": "6.148.0-alpha.
|
|
3
|
+
"version": "6.148.0-alpha.1",
|
|
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.148.0-alpha.
|
|
10
|
-
"@frontegg/types": "6.148.0-alpha.
|
|
9
|
+
"@frontegg/redux-store": "6.148.0-alpha.1",
|
|
10
|
+
"@frontegg/types": "6.148.0-alpha.1",
|
|
11
11
|
"@types/react": "*",
|
|
12
12
|
"get-value": "^3.0.1",
|
|
13
13
|
"react-redux": "^7.x"
|