@frontegg/react-hooks 7.0.0-alpha.2 → 7.0.0-alpha.4
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/FronteggProvider/FronteggProvider.js +3 -1
- package/auth/applications.d.ts +3 -0
- package/auth/applications.js +9 -0
- package/auth/entitlements.js +11 -24
- package/auth/index.d.ts +1 -0
- package/auth/index.js +2 -1
- package/auth/stepUp.d.ts +2 -2
- package/common/index.d.ts +1 -0
- package/index.js +1 -1
- package/node/FronteggProvider/FronteggProvider.js +3 -1
- package/node/auth/applications.js +17 -0
- package/node/auth/entitlements.js +10 -23
- package/node/auth/index.js +12 -0
- package/node/index.js +1 -1
- package/package.json +3 -3
|
@@ -73,7 +73,9 @@ const FronteggContent = ({
|
|
|
73
73
|
const loadingRef = useRef(undefined);
|
|
74
74
|
if (isLoading !== loadingRef.current && !isNextJS) {
|
|
75
75
|
loadingRef.current = isLoading;
|
|
76
|
-
|
|
76
|
+
setTimeout(() => {
|
|
77
|
+
setLoading(isLoading);
|
|
78
|
+
});
|
|
77
79
|
}
|
|
78
80
|
if (alwaysShowChildren) {
|
|
79
81
|
return /*#__PURE__*/_jsx(_Fragment, {
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { useStore } from '../FronteggStoreContext';
|
|
2
|
+
import { useSnapshot } from '../useSnapshot';
|
|
3
|
+
export function useApplicationsState() {
|
|
4
|
+
const state = useStore().store.auth.applicationsState;
|
|
5
|
+
return useSnapshot(state);
|
|
6
|
+
}
|
|
7
|
+
export const useApplicationsActions = () => {
|
|
8
|
+
return useStore().stateActions.auth.applicationsActions;
|
|
9
|
+
};
|
package/auth/entitlements.js
CHANGED
|
@@ -1,7 +1,6 @@
|
|
|
1
|
-
import { FeatureFlags, USE_ENTITLEMENTS_V2_ENDPOINT_FF } from '@frontegg/rest-api';
|
|
2
1
|
import { useAuthUserOrNull } from './hooks';
|
|
3
2
|
import { useMemo } from 'react';
|
|
4
|
-
import {
|
|
3
|
+
import { useShadowDom } from '../common';
|
|
5
4
|
import { useFeatureFlags } from '../flags';
|
|
6
5
|
import { useStore } from '../FronteggStoreContext';
|
|
7
6
|
import { useSnapshot } from '../useSnapshot';
|
|
@@ -25,23 +24,18 @@ const useUserState = () => {
|
|
|
25
24
|
|
|
26
25
|
/**
|
|
27
26
|
* @param customAttributes user attributes
|
|
28
|
-
* @returns is entitled query data including:
|
|
27
|
+
* @returns is entitled query data including: entitlements state and final attributes (consumer and frontegg)
|
|
29
28
|
*/
|
|
30
29
|
const useEntitlementsQueryData = customAttributes => {
|
|
31
30
|
const user = useUserState();
|
|
32
31
|
const entitlements = useEntitlementsState();
|
|
33
|
-
const {
|
|
34
|
-
appName
|
|
35
|
-
} = useRootState();
|
|
36
|
-
const [useEntitlementsV2] = FeatureFlags.getFeatureFlags([USE_ENTITLEMENTS_V2_ENDPOINT_FF], appName);
|
|
37
32
|
const attributes = {
|
|
38
33
|
custom: customAttributes,
|
|
39
34
|
jwt: user
|
|
40
35
|
};
|
|
41
36
|
return {
|
|
42
37
|
entitlements,
|
|
43
|
-
attributes
|
|
44
|
-
isV2: useEntitlementsV2
|
|
38
|
+
attributes
|
|
45
39
|
};
|
|
46
40
|
};
|
|
47
41
|
|
|
@@ -53,10 +47,9 @@ const useEntitlementsQueryData = customAttributes => {
|
|
|
53
47
|
export const useFeatureEntitlements = (key, customAttributes) => {
|
|
54
48
|
const {
|
|
55
49
|
entitlements,
|
|
56
|
-
attributes
|
|
57
|
-
isV2
|
|
50
|
+
attributes
|
|
58
51
|
} = useEntitlementsQueryData(customAttributes);
|
|
59
|
-
return getFeatureEntitlements(entitlements, key, attributes
|
|
52
|
+
return getFeatureEntitlements(entitlements, key, attributes);
|
|
60
53
|
};
|
|
61
54
|
|
|
62
55
|
/**
|
|
@@ -67,10 +60,9 @@ export const useFeatureEntitlements = (key, customAttributes) => {
|
|
|
67
60
|
export const usePermissionEntitlements = (key, customAttributes) => {
|
|
68
61
|
const {
|
|
69
62
|
entitlements,
|
|
70
|
-
attributes
|
|
71
|
-
isV2
|
|
63
|
+
attributes
|
|
72
64
|
} = useEntitlementsQueryData(customAttributes);
|
|
73
|
-
return getPermissionEntitlements(entitlements, key, attributes
|
|
65
|
+
return getPermissionEntitlements(entitlements, key, attributes);
|
|
74
66
|
};
|
|
75
67
|
|
|
76
68
|
/**
|
|
@@ -81,10 +73,9 @@ export const usePermissionEntitlements = (key, customAttributes) => {
|
|
|
81
73
|
export const useEntitlements = (options, customAttributes) => {
|
|
82
74
|
const {
|
|
83
75
|
entitlements,
|
|
84
|
-
attributes
|
|
85
|
-
isV2
|
|
76
|
+
attributes
|
|
86
77
|
} = useEntitlementsQueryData(customAttributes);
|
|
87
|
-
return getEntitlements(entitlements, options, attributes
|
|
78
|
+
return getEntitlements(entitlements, options, attributes);
|
|
88
79
|
};
|
|
89
80
|
|
|
90
81
|
/**
|
|
@@ -95,19 +86,15 @@ export const useEntitlementsActions = () => {
|
|
|
95
86
|
// this code is duplicated because React is yelling when using useEntitlementsQueryData inside the isEntitledTo function because it's not a hook
|
|
96
87
|
const user = useUserState();
|
|
97
88
|
const entitlements = useEntitlementsState();
|
|
98
|
-
const {
|
|
99
|
-
appName
|
|
100
|
-
} = useRootState();
|
|
101
|
-
const [useEntitlementsV2] = FeatureFlags.getFeatureFlags([USE_ENTITLEMENTS_V2_ENDPOINT_FF], appName);
|
|
102
89
|
return useMemo(() => ({
|
|
103
90
|
isEntitledTo: (options, customAttributes) => {
|
|
104
91
|
const attributes = {
|
|
105
92
|
custom: customAttributes,
|
|
106
93
|
jwt: user
|
|
107
94
|
};
|
|
108
|
-
return getEntitlements(entitlements, options, attributes
|
|
95
|
+
return getEntitlements(entitlements, options, attributes);
|
|
109
96
|
}
|
|
110
|
-
}), [user, entitlements
|
|
97
|
+
}), [user, entitlements]);
|
|
111
98
|
};
|
|
112
99
|
|
|
113
100
|
/**
|
package/auth/index.d.ts
CHANGED
package/auth/index.js
CHANGED
package/auth/stepUp.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { StepUpState, StepUpActions, IsSteppedUpOptions } from '@frontegg/redux-store';
|
|
1
|
+
import { StepUpState, StepUpActions, StepUpOptions, IsSteppedUpOptions } from '@frontegg/redux-store';
|
|
2
2
|
export declare function useStepUpState(): StepUpState;
|
|
3
3
|
export declare const useStepUpActions: () => StepUpActions;
|
|
4
4
|
/**
|
|
@@ -8,7 +8,7 @@ export declare const getMaxAgeFromQueryParam: () => number | undefined;
|
|
|
8
8
|
/**
|
|
9
9
|
* @returns step up function that redirects to the step up url with the max age param and set the redirect url in the local storage
|
|
10
10
|
*/
|
|
11
|
-
export declare const useStepUp: () =>
|
|
11
|
+
export declare const useStepUp: () => (options?: StepUpOptions | undefined) => void;
|
|
12
12
|
/**
|
|
13
13
|
* @param options.maxAge - max age of step up
|
|
14
14
|
* @returns true when the user is stepped up, false otherwise
|
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
|
@@ -80,7 +80,9 @@ const FronteggContent = ({
|
|
|
80
80
|
const loadingRef = (0, _react.useRef)(undefined);
|
|
81
81
|
if (isLoading !== loadingRef.current && !isNextJS) {
|
|
82
82
|
loadingRef.current = isLoading;
|
|
83
|
-
|
|
83
|
+
setTimeout(() => {
|
|
84
|
+
setLoading(isLoading);
|
|
85
|
+
});
|
|
84
86
|
}
|
|
85
87
|
if (alwaysShowChildren) {
|
|
86
88
|
return /*#__PURE__*/(0, _jsxRuntime.jsx)(_jsxRuntime.Fragment, {
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.useApplicationsActions = void 0;
|
|
7
|
+
exports.useApplicationsState = useApplicationsState;
|
|
8
|
+
var _FronteggStoreContext = require("../FronteggStoreContext");
|
|
9
|
+
var _useSnapshot = require("../useSnapshot");
|
|
10
|
+
function useApplicationsState() {
|
|
11
|
+
const state = (0, _FronteggStoreContext.useStore)().store.auth.applicationsState;
|
|
12
|
+
return (0, _useSnapshot.useSnapshot)(state);
|
|
13
|
+
}
|
|
14
|
+
const useApplicationsActions = () => {
|
|
15
|
+
return (0, _FronteggStoreContext.useStore)().stateActions.auth.applicationsActions;
|
|
16
|
+
};
|
|
17
|
+
exports.useApplicationsActions = useApplicationsActions;
|
|
@@ -4,7 +4,6 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
6
|
exports.usePermissionEntitlements = exports.useFeatureEntitlements = exports.useEntitlementsOptions = exports.useEntitlementsActions = exports.useEntitlements = void 0;
|
|
7
|
-
var _restApi = require("@frontegg/rest-api");
|
|
8
7
|
var _hooks = require("./hooks");
|
|
9
8
|
var _react = require("react");
|
|
10
9
|
var _common = require("../common");
|
|
@@ -30,23 +29,18 @@ const useUserState = () => {
|
|
|
30
29
|
|
|
31
30
|
/**
|
|
32
31
|
* @param customAttributes user attributes
|
|
33
|
-
* @returns is entitled query data including:
|
|
32
|
+
* @returns is entitled query data including: entitlements state and final attributes (consumer and frontegg)
|
|
34
33
|
*/
|
|
35
34
|
const useEntitlementsQueryData = customAttributes => {
|
|
36
35
|
const user = useUserState();
|
|
37
36
|
const entitlements = useEntitlementsState();
|
|
38
|
-
const {
|
|
39
|
-
appName
|
|
40
|
-
} = (0, _common.useRootState)();
|
|
41
|
-
const [useEntitlementsV2] = _restApi.FeatureFlags.getFeatureFlags([_restApi.USE_ENTITLEMENTS_V2_ENDPOINT_FF], appName);
|
|
42
37
|
const attributes = {
|
|
43
38
|
custom: customAttributes,
|
|
44
39
|
jwt: user
|
|
45
40
|
};
|
|
46
41
|
return {
|
|
47
42
|
entitlements,
|
|
48
|
-
attributes
|
|
49
|
-
isV2: useEntitlementsV2
|
|
43
|
+
attributes
|
|
50
44
|
};
|
|
51
45
|
};
|
|
52
46
|
|
|
@@ -58,10 +52,9 @@ const useEntitlementsQueryData = customAttributes => {
|
|
|
58
52
|
const useFeatureEntitlements = (key, customAttributes) => {
|
|
59
53
|
const {
|
|
60
54
|
entitlements,
|
|
61
|
-
attributes
|
|
62
|
-
isV2
|
|
55
|
+
attributes
|
|
63
56
|
} = useEntitlementsQueryData(customAttributes);
|
|
64
|
-
return (0, _reduxStore.getFeatureEntitlements)(entitlements, key, attributes
|
|
57
|
+
return (0, _reduxStore.getFeatureEntitlements)(entitlements, key, attributes);
|
|
65
58
|
};
|
|
66
59
|
|
|
67
60
|
/**
|
|
@@ -73,10 +66,9 @@ exports.useFeatureEntitlements = useFeatureEntitlements;
|
|
|
73
66
|
const usePermissionEntitlements = (key, customAttributes) => {
|
|
74
67
|
const {
|
|
75
68
|
entitlements,
|
|
76
|
-
attributes
|
|
77
|
-
isV2
|
|
69
|
+
attributes
|
|
78
70
|
} = useEntitlementsQueryData(customAttributes);
|
|
79
|
-
return (0, _reduxStore.getPermissionEntitlements)(entitlements, key, attributes
|
|
71
|
+
return (0, _reduxStore.getPermissionEntitlements)(entitlements, key, attributes);
|
|
80
72
|
};
|
|
81
73
|
|
|
82
74
|
/**
|
|
@@ -88,10 +80,9 @@ exports.usePermissionEntitlements = usePermissionEntitlements;
|
|
|
88
80
|
const useEntitlements = (options, customAttributes) => {
|
|
89
81
|
const {
|
|
90
82
|
entitlements,
|
|
91
|
-
attributes
|
|
92
|
-
isV2
|
|
83
|
+
attributes
|
|
93
84
|
} = useEntitlementsQueryData(customAttributes);
|
|
94
|
-
return (0, _reduxStore.getEntitlements)(entitlements, options, attributes
|
|
85
|
+
return (0, _reduxStore.getEntitlements)(entitlements, options, attributes);
|
|
95
86
|
};
|
|
96
87
|
|
|
97
88
|
/**
|
|
@@ -103,19 +94,15 @@ const useEntitlementsActions = () => {
|
|
|
103
94
|
// this code is duplicated because React is yelling when using useEntitlementsQueryData inside the isEntitledTo function because it's not a hook
|
|
104
95
|
const user = useUserState();
|
|
105
96
|
const entitlements = useEntitlementsState();
|
|
106
|
-
const {
|
|
107
|
-
appName
|
|
108
|
-
} = (0, _common.useRootState)();
|
|
109
|
-
const [useEntitlementsV2] = _restApi.FeatureFlags.getFeatureFlags([_restApi.USE_ENTITLEMENTS_V2_ENDPOINT_FF], appName);
|
|
110
97
|
return (0, _react.useMemo)(() => ({
|
|
111
98
|
isEntitledTo: (options, customAttributes) => {
|
|
112
99
|
const attributes = {
|
|
113
100
|
custom: customAttributes,
|
|
114
101
|
jwt: user
|
|
115
102
|
};
|
|
116
|
-
return (0, _reduxStore.getEntitlements)(entitlements, options, attributes
|
|
103
|
+
return (0, _reduxStore.getEntitlements)(entitlements, options, attributes);
|
|
117
104
|
}
|
|
118
|
-
}), [user, entitlements
|
|
105
|
+
}), [user, entitlements]);
|
|
119
106
|
};
|
|
120
107
|
|
|
121
108
|
/**
|
package/node/auth/index.js
CHANGED
|
@@ -375,4 +375,16 @@ Object.keys(_tenants).forEach(function (key) {
|
|
|
375
375
|
return _tenants[key];
|
|
376
376
|
}
|
|
377
377
|
});
|
|
378
|
+
});
|
|
379
|
+
var _applications = require("./applications");
|
|
380
|
+
Object.keys(_applications).forEach(function (key) {
|
|
381
|
+
if (key === "default" || key === "__esModule") return;
|
|
382
|
+
if (Object.prototype.hasOwnProperty.call(_exportNames, key)) return;
|
|
383
|
+
if (key in exports && exports[key] === _applications[key]) return;
|
|
384
|
+
Object.defineProperty(exports, key, {
|
|
385
|
+
enumerable: true,
|
|
386
|
+
get: function () {
|
|
387
|
+
return _applications[key];
|
|
388
|
+
}
|
|
389
|
+
});
|
|
378
390
|
});
|
package/node/index.js
CHANGED
package/package.json
CHANGED
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@frontegg/react-hooks",
|
|
3
|
-
"version": "7.0.0-alpha.
|
|
3
|
+
"version": "7.0.0-alpha.4",
|
|
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": "7.0.0-alpha.
|
|
10
|
-
"@frontegg/types": "7.0.0-alpha.
|
|
9
|
+
"@frontegg/redux-store": "7.0.0-alpha.4",
|
|
10
|
+
"@frontegg/types": "7.0.0-alpha.4",
|
|
11
11
|
"@types/react": "*",
|
|
12
12
|
"get-value": "^3.0.1",
|
|
13
13
|
"react-redux": "^7.x"
|