@frontegg/react-hooks 6.185.0-alpha.2 → 6.185.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/auth/index.d.ts +0 -1
- package/auth/index.js +1 -2
- package/common/index.d.ts +0 -1
- package/index.js +1 -1
- package/node/auth/entitlements.js +10 -23
- package/node/auth/index.js +0 -12
- package/node/index.js +1 -1
- package/package.json +3 -3
- package/auth/applications.d.ts +0 -5
- package/auth/applications.js +0 -7
- package/node/auth/applications.js +0 -15
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/auth/index.d.ts
CHANGED
package/auth/index.js
CHANGED
package/common/index.d.ts
CHANGED
|
@@ -9,7 +9,6 @@ interface ShadowDomContextData extends FronteggAppOptions {
|
|
|
9
9
|
rootEl: HTMLElement;
|
|
10
10
|
staticRoute?: string;
|
|
11
11
|
setStaticRouteSetter?: (action: Dispatch<SetStateAction<string | undefined>>) => void;
|
|
12
|
-
isMultiApp?: boolean;
|
|
13
12
|
}
|
|
14
13
|
export interface DomContext extends ShadowDomContextData {
|
|
15
14
|
isShadowDom: boolean;
|
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/auth/index.js
CHANGED
|
@@ -404,16 +404,4 @@ Object.keys(_sms).forEach(function (key) {
|
|
|
404
404
|
return _sms[key];
|
|
405
405
|
}
|
|
406
406
|
});
|
|
407
|
-
});
|
|
408
|
-
var _applications = require("./applications");
|
|
409
|
-
Object.keys(_applications).forEach(function (key) {
|
|
410
|
-
if (key === "default" || key === "__esModule") return;
|
|
411
|
-
if (Object.prototype.hasOwnProperty.call(_exportNames, key)) return;
|
|
412
|
-
if (key in exports && exports[key] === _applications[key]) return;
|
|
413
|
-
Object.defineProperty(exports, key, {
|
|
414
|
-
enumerable: true,
|
|
415
|
-
get: function () {
|
|
416
|
-
return _applications[key];
|
|
417
|
-
}
|
|
418
|
-
});
|
|
419
407
|
});
|
package/node/index.js
CHANGED
package/package.json
CHANGED
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@frontegg/react-hooks",
|
|
3
|
-
"version": "6.185.0
|
|
3
|
+
"version": "6.185.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.185.0
|
|
10
|
-
"@frontegg/types": "6.185.0
|
|
9
|
+
"@frontegg/redux-store": "6.185.0",
|
|
10
|
+
"@frontegg/types": "6.185.0",
|
|
11
11
|
"@types/react": "*",
|
|
12
12
|
"get-value": "^3.0.1",
|
|
13
13
|
"react-redux": "^7.x"
|
package/auth/applications.d.ts
DELETED
|
@@ -1,5 +0,0 @@
|
|
|
1
|
-
import { ApplicationsActions, ApplicationsState } from '@frontegg/redux-store';
|
|
2
|
-
export declare type ApplicationsStateMapper<S> = (state: ApplicationsState) => S;
|
|
3
|
-
export declare function useApplicationsState(): ApplicationsState;
|
|
4
|
-
export declare function useApplicationsState<S>(stateMapper: ApplicationsStateMapper<S>): S;
|
|
5
|
-
export declare const useApplicationsActions: () => ApplicationsActions;
|
package/auth/applications.js
DELETED
|
@@ -1,7 +0,0 @@
|
|
|
1
|
-
import { applicationsActions, applicationsReducers } from '@frontegg/redux-store';
|
|
2
|
-
import { reducerActionsGenerator, stateHookGenerator } from './hooks';
|
|
3
|
-
const defaultMapper = state => state;
|
|
4
|
-
export function useApplicationsState(stateMapper = defaultMapper) {
|
|
5
|
-
return stateHookGenerator(stateMapper, 'applicationsState');
|
|
6
|
-
}
|
|
7
|
-
export const useApplicationsActions = () => reducerActionsGenerator(applicationsActions, applicationsReducers);
|
|
@@ -1,15 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
Object.defineProperty(exports, "__esModule", {
|
|
4
|
-
value: true
|
|
5
|
-
});
|
|
6
|
-
exports.useApplicationsActions = void 0;
|
|
7
|
-
exports.useApplicationsState = useApplicationsState;
|
|
8
|
-
var _reduxStore = require("@frontegg/redux-store");
|
|
9
|
-
var _hooks = require("./hooks");
|
|
10
|
-
const defaultMapper = state => state;
|
|
11
|
-
function useApplicationsState(stateMapper = defaultMapper) {
|
|
12
|
-
return (0, _hooks.stateHookGenerator)(stateMapper, 'applicationsState');
|
|
13
|
-
}
|
|
14
|
-
const useApplicationsActions = () => (0, _hooks.reducerActionsGenerator)(_reduxStore.applicationsActions, _reduxStore.applicationsReducers);
|
|
15
|
-
exports.useApplicationsActions = useApplicationsActions;
|