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