@equinor/fusion-framework-react-app 4.1.19 → 4.2.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.
@@ -0,0 +1 @@
1
+ export { useFeatureFlag, useFrameworkFeatureFlag, useFeatureFlags, useFrameworkFeatureFlags, } from './useFeatureFlags';
@@ -0,0 +1,21 @@
1
+ import { IFeatureFlag } from '@equinor/fusion-framework-module-feature-flag';
2
+ export declare const useFeatureFlag: (key: string) => {
3
+ feature: IFeatureFlag<unknown> | undefined;
4
+ error: unknown;
5
+ setFeatureEnabled: (key: string, enabled: boolean) => void;
6
+ };
7
+ export declare const useFeatureFlags: () => {
8
+ features: IFeatureFlag<unknown>[] | undefined;
9
+ error: unknown;
10
+ setFeatureEnabled: (key: string, enabled: boolean) => void;
11
+ };
12
+ export declare const useFrameworkFeatureFlag: (key: string) => {
13
+ feature: IFeatureFlag<unknown> | undefined;
14
+ error: unknown;
15
+ setFeatureEnabled: (key: string, enabled: boolean) => void;
16
+ };
17
+ export declare const useFrameworkFeatureFlags: () => {
18
+ features: IFeatureFlag<unknown>[] | undefined;
19
+ error: unknown;
20
+ setFeatureEnabled: (key: string, enabled: boolean) => void;
21
+ };
@@ -0,0 +1,3 @@
1
+ export { useCurrentAccount } from './useCurrentAccount';
2
+ export { useAccessToken } from './useAccessToken';
3
+ export { useToken } from './useToken';
@@ -0,0 +1,6 @@
1
+ import { AuthRequest } from '@equinor/fusion-framework-module-msal/client';
2
+ export declare const useAccessToken: (req: AuthRequest) => {
3
+ token?: string | undefined;
4
+ pending: boolean;
5
+ error: unknown;
6
+ };
@@ -0,0 +1,2 @@
1
+ import { AccountInfo } from '@equinor/fusion-framework-module-msal';
2
+ export declare const useCurrentAccount: () => AccountInfo | undefined;
@@ -0,0 +1,7 @@
1
+ import { AuthRequest, AuthenticationResult } from '@equinor/fusion-framework-module-msal/client';
2
+ export declare const useToken: (req: AuthRequest) => {
3
+ token?: AuthenticationResult | undefined;
4
+ pending: boolean;
5
+ error: unknown;
6
+ };
7
+ export default useToken;
@@ -1 +1 @@
1
- export declare const version = "4.1.19";
1
+ export declare const version = "4.2.1";
package/package.json CHANGED
@@ -1,33 +1,17 @@
1
1
  {
2
2
  "name": "@equinor/fusion-framework-react-app",
3
- "version": "4.1.19",
3
+ "version": "4.2.1",
4
4
  "description": "",
5
5
  "main": "dist/esm/index.js",
6
6
  "exports": {
7
- ".": {
8
- "import": "./dist/esm/index.js",
9
- "types": "./dist/types/index.d.ts"
10
- },
11
- "./bookmark": {
12
- "import": "./dist/esm/bookmark/index.js",
13
- "types": "./dist/types/bookmark/index.d.ts"
14
- },
15
- "./context": {
16
- "import": "./dist/esm/context/index.js",
17
- "types": "./dist/types/context/index.d.ts"
18
- },
19
- "./framework": {
20
- "import": "./dist/esm/framework/index.js",
21
- "types": "./dist/types/framework/index.d.ts"
22
- },
23
- "./http": {
24
- "import": "./dist/esm/http/index.js",
25
- "types": "./dist/types/http/index.d.ts"
26
- },
27
- "./navigation": {
28
- "import": "./dist/esm/navigation/index.js",
29
- "types": "./dist/types/navigation/index.d.ts"
30
- }
7
+ ".": "./dist/esm/index.js",
8
+ "./bookmark": "./dist/esm/bookmark/index.js",
9
+ "./context": "./dist/esm/context/index.js",
10
+ "./feature-flag": "./dist/esm/feature-flag/index.js",
11
+ "./framework": "./dist/esm/framework/index.js",
12
+ "./http": "./dist/esm/http/index.js",
13
+ "./msal": "./dist/esm/msal/index.js",
14
+ "./navigation": "./dist/esm/navigation/index.js"
31
15
  },
32
16
  "types": "./dist/types/index.d.ts",
33
17
  "typesVersions": {
@@ -38,12 +22,18 @@
38
22
  "context": [
39
23
  "dist/types/context/index.d.ts"
40
24
  ],
25
+ "feature-flag": [
26
+ "dist/types/feature-flag/index.d.ts"
27
+ ],
41
28
  "framework": [
42
29
  "dist/types/framework/index.d.ts"
43
30
  ],
44
31
  "http": [
45
32
  "dist/types/http/index.d.ts"
46
33
  ],
34
+ "msal": [
35
+ "dist/types/msal/index.d.ts"
36
+ ],
47
37
  "navigation": [
48
38
  "dist/types/navigation/index.d.ts"
49
39
  ]
@@ -61,28 +51,34 @@
61
51
  "directory": "packages/react"
62
52
  },
63
53
  "dependencies": {
64
- "@equinor/fusion-framework-app": "^7.1.14",
65
- "@equinor/fusion-framework-module-app": "^5.2.12",
54
+ "@equinor/fusion-framework-app": "^7.1.15",
66
55
  "@equinor/fusion-framework-module": "^4.2.6",
67
56
  "@equinor/fusion-framework-module-navigation": "^3.1.3",
68
- "@equinor/fusion-framework-react": "^5.3.7",
57
+ "@equinor/fusion-framework-react": "^5.3.9",
69
58
  "@equinor/fusion-framework-react-module": "^3.0.7",
70
- "@equinor/fusion-framework-react-module-http": "^4.0.4"
59
+ "@equinor/fusion-framework-module-app": "^5.2.12",
60
+ "@equinor/fusion-framework-react-module-http": "^4.0.5"
71
61
  },
72
62
  "devDependencies": {
73
63
  "@types/react": "^18.2.20",
74
64
  "@types/react-dom": "^18.2.7",
75
65
  "react": "^18.2.0",
76
66
  "react-dom": "^18.2.0",
67
+ "rxjs": "^7.8.1",
77
68
  "typescript": "^5.1.3",
78
69
  "@equinor/fusion-framework-module-event": "^4.0.7",
79
- "@equinor/fusion-framework-react-module-bookmark": "^2.0.26",
80
- "@equinor/fusion-framework-react-module-context": "^6.0.18"
70
+ "@equinor/fusion-framework-module-msal": "^3.0.9",
71
+ "@equinor/fusion-framework-module-feature-flag": "^0.0.1",
72
+ "@equinor/fusion-framework-react-module-context": "^6.0.18",
73
+ "@equinor/fusion-framework-react-module-bookmark": "^2.0.28",
74
+ "@equinor/fusion-observable": "^8.1.4"
81
75
  },
82
76
  "peerDependencies": {
83
77
  "@types/react": "^17.0.0 || ^18.0.0",
84
78
  "react": "^17.0.0 || ^18.0.0",
85
- "react-dom": "^17.0.0 || ^18.0.0"
79
+ "react-dom": "^17.0.0 || ^18.0.0",
80
+ "rxjs": "^7.8.1",
81
+ "@equinor/fusion-framework-module-msal": "^3.0.9"
86
82
  },
87
83
  "peerDependenciesMeta": {
88
84
  "@equinor/fusion-framework-react-module-context": {
@@ -94,11 +90,20 @@
94
90
  "@equinor/fusion-framework-react-module-bookmark": {
95
91
  "optional": true
96
92
  },
93
+ "@equinor/fusion-framework-module-feature-flag": {
94
+ "optional": true
95
+ },
96
+ "@equinor/fusion-observable": {
97
+ "optional": true
98
+ },
97
99
  "@types/react": {
98
100
  "optional": true
99
101
  },
100
102
  "react-dom": {
101
103
  "optional": true
104
+ },
105
+ "rxjs": {
106
+ "optional": true
102
107
  }
103
108
  },
104
109
  "scripts": {
@@ -0,0 +1,6 @@
1
+ export {
2
+ useFeatureFlag,
3
+ useFrameworkFeatureFlag,
4
+ useFeatureFlags,
5
+ useFrameworkFeatureFlags,
6
+ } from './useFeatureFlags';
@@ -0,0 +1,110 @@
1
+ import { useFramework } from '@equinor/fusion-framework-react';
2
+ import { useAppModule } from '../useAppModule';
3
+ import { useCallback, useMemo } from 'react';
4
+ import { useObservableState } from '@equinor/fusion-observable/react';
5
+ import {
6
+ FeatureFlagModule,
7
+ IFeatureFlagProvider,
8
+ IFeatureFlag,
9
+ } from '@equinor/fusion-framework-module-feature-flag';
10
+ import { EMPTY } from 'rxjs';
11
+
12
+ /**
13
+ * useFeatureflag
14
+ *
15
+ * Hook for getting single featureflag from app.
16
+ *
17
+ * @param key string
18
+ */
19
+ export const useFeatureFlag = (
20
+ key: string,
21
+ ): {
22
+ feature: IFeatureFlag<unknown> | undefined;
23
+ error: unknown;
24
+ setFeatureEnabled: (key: string, enabled: boolean) => void;
25
+ } => {
26
+ const provider = useAppModule<FeatureFlagModule>('featureFlag');
27
+ const { value: feature, error } = useObservableState(_useFeatureFlag(key, provider));
28
+ const setFeatureEnabled = _useSetFeatureflag(provider);
29
+ return { feature, error, setFeatureEnabled };
30
+ };
31
+
32
+ /**
33
+ * useFeatureflags
34
+ *
35
+ * Hook for getting all featureflags from app.
36
+ *
37
+ * @param key string
38
+ */
39
+ export const useFeatureFlags = (): {
40
+ features: IFeatureFlag<unknown>[] | undefined;
41
+ error: unknown;
42
+ setFeatureEnabled: (key: string, enabled: boolean) => void;
43
+ } => {
44
+ const provider = useAppModule<FeatureFlagModule>('featureFlag');
45
+ const { value: features, error } = useObservableState(_useFeatureFlags(provider));
46
+ const setFeatureEnabled = _useSetFeatureflag(provider);
47
+ return { features, error, setFeatureEnabled };
48
+ };
49
+
50
+ /**
51
+ * useFrameworkFeatureflag
52
+ *
53
+ * Hook for getting single featureflag from portal.
54
+ *
55
+ * @param key string
56
+ */
57
+ export const useFrameworkFeatureFlag = (
58
+ key: string,
59
+ ): {
60
+ feature: IFeatureFlag<unknown> | undefined;
61
+ error: unknown;
62
+ setFeatureEnabled: (key: string, enabled: boolean) => void;
63
+ } => {
64
+ const provider = useFramework<[FeatureFlagModule]>().modules.featureFlag;
65
+ const { value: feature, error } = useObservableState(_useFeatureFlag(key, provider));
66
+ const setFeatureEnabled = _useSetFeatureflag(provider);
67
+ return { feature, error, setFeatureEnabled };
68
+ };
69
+
70
+ /**
71
+ * useFrameworkFeatureflags
72
+ *
73
+ * Hook for getting all featureflags from portal.
74
+ *
75
+ * @param key string
76
+ */
77
+ export const useFrameworkFeatureFlags = (): {
78
+ features: IFeatureFlag<unknown>[] | undefined;
79
+ error: unknown;
80
+ setFeatureEnabled: (key: string, enabled: boolean) => void;
81
+ } => {
82
+ const provider = useFramework<[FeatureFlagModule]>().modules.featureFlag;
83
+ const { value: features, error } = useObservableState(_useFeatureFlags(provider));
84
+ const setFeatureEnabled = _useSetFeatureflag(provider);
85
+ return { features, error, setFeatureEnabled };
86
+ };
87
+
88
+ const _useFeatureFlag = (key: string, provider?: IFeatureFlagProvider) => {
89
+ return useMemo(() => {
90
+ return provider ? provider.getFeature(key) : EMPTY;
91
+ }, [provider, key]);
92
+ };
93
+
94
+ const _useFeatureFlags = (provider?: IFeatureFlagProvider) => {
95
+ return useMemo(() => {
96
+ return provider ? provider.getFeatures((_) => true) : EMPTY;
97
+ }, [provider]);
98
+ };
99
+
100
+ const _useSetFeatureflag = (provider?: IFeatureFlagProvider) => {
101
+ return useCallback(
102
+ (key: string, enabled: boolean) => {
103
+ if (!provider) {
104
+ throw new Error('Missing IFeatureFlagProvider.');
105
+ }
106
+ provider.toggleFeature({ key, enabled });
107
+ },
108
+ [provider],
109
+ );
110
+ };
@@ -0,0 +1,3 @@
1
+ export { useCurrentAccount } from './useCurrentAccount';
2
+ export { useAccessToken } from './useAccessToken';
3
+ export { useToken } from './useToken';
@@ -0,0 +1,15 @@
1
+ import { AuthRequest } from '@equinor/fusion-framework-module-msal/client';
2
+ import { useToken } from './useToken';
3
+
4
+ /**
5
+ * Custom hook that retrieves an access token for the specified authentication request.
6
+ *
7
+ * @param req - The authentication request.
8
+ * @returns An object containing the access token, pending state, and error.
9
+ */
10
+ export const useAccessToken = (
11
+ req: AuthRequest,
12
+ ): { token?: string; pending: boolean; error: unknown } => {
13
+ const { token, error, pending } = useToken(req);
14
+ return { token: token?.accessToken, pending, error };
15
+ };
@@ -0,0 +1,11 @@
1
+ import { AccountInfo } from '@equinor/fusion-framework-module-msal';
2
+ import useAppModule from '../useAppModule';
3
+
4
+ /**
5
+ * Retrieves the current account information from the MSAL provider.
6
+ * @returns The current account information or undefined if no account is available.
7
+ */
8
+ export const useCurrentAccount = (): AccountInfo | undefined => {
9
+ const msalProvider = useAppModule('auth');
10
+ return msalProvider.defaultAccount;
11
+ };
@@ -0,0 +1,29 @@
1
+ import { AuthRequest, AuthenticationResult } from '@equinor/fusion-framework-module-msal/client';
2
+ import useAppModule from '../useAppModule';
3
+ import { useEffect, useState } from 'react';
4
+
5
+ /**
6
+ * Custom hook for acquiring an authentication token using MSAL.
7
+ * @param req - The authentication request.
8
+ * @returns An object containing the acquired token, pending state, and error.
9
+ */
10
+ export const useToken = (
11
+ req: AuthRequest,
12
+ ): { token?: AuthenticationResult; pending: boolean; error: unknown } => {
13
+ const msalProvider = useAppModule('auth');
14
+ const [token, setToken] = useState<AuthenticationResult | undefined>(undefined);
15
+ const [pending, setPending] = useState<boolean>(false);
16
+ const [error, setError] = useState<unknown>(null);
17
+ useEffect(() => {
18
+ setPending(true);
19
+ setToken(undefined);
20
+ msalProvider
21
+ .acquireToken(req)
22
+ .then((token) => token && setToken(token))
23
+ .catch(setError)
24
+ .finally(() => setPending(false));
25
+ }, [msalProvider, req]);
26
+ return { token, pending, error };
27
+ };
28
+
29
+ export default useToken;
package/src/version.ts CHANGED
@@ -1,2 +1,2 @@
1
1
  // Generated by genversion.
2
- export const version = '4.1.19';
2
+ export const version = '4.2.1';