@equinor/fusion-framework-react-app 9.0.9-next.0 → 10.0.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/CHANGELOG.md +80 -12
- package/README.md +176 -99
- package/dist/esm/ag-grid/useTheme.js +7 -0
- package/dist/esm/ag-grid/useTheme.js.map +1 -1
- package/dist/esm/analytics/index.js +8 -0
- package/dist/esm/analytics/index.js.map +1 -1
- package/dist/esm/analytics/useTrackFeature.js +17 -1
- package/dist/esm/analytics/useTrackFeature.js.map +1 -1
- package/dist/esm/apploader/index.js +8 -0
- package/dist/esm/apploader/index.js.map +1 -1
- package/dist/esm/bookmark/index.js +8 -0
- package/dist/esm/bookmark/index.js.map +1 -1
- package/dist/esm/context/index.js +8 -0
- package/dist/esm/context/index.js.map +1 -1
- package/dist/esm/context/useContextProvider.js +6 -0
- package/dist/esm/context/useContextProvider.js.map +1 -1
- package/dist/esm/context/useCurrentContext.js +14 -0
- package/dist/esm/context/useCurrentContext.js.map +1 -1
- package/dist/esm/create-legacy-app.js +13 -0
- package/dist/esm/create-legacy-app.js.map +1 -1
- package/dist/esm/feature-flag/index.js.map +1 -1
- package/dist/esm/feature-flag/useFeature.js +20 -4
- package/dist/esm/feature-flag/useFeature.js.map +1 -1
- package/dist/esm/framework/index.js +8 -1
- package/dist/esm/framework/index.js.map +1 -1
- package/dist/esm/framework/useFrameworkCurrentContext.js +9 -0
- package/dist/esm/framework/useFrameworkCurrentContext.js.map +1 -1
- package/dist/esm/help-center/useHelpCenter.js +12 -1
- package/dist/esm/help-center/useHelpCenter.js.map +1 -1
- package/dist/esm/http/index.js +9 -0
- package/dist/esm/http/index.js.map +1 -1
- package/dist/esm/http/selectors.js +8 -0
- package/dist/esm/http/selectors.js.map +1 -1
- package/dist/esm/index.js +15 -0
- package/dist/esm/index.js.map +1 -1
- package/dist/esm/make-component.js.map +1 -1
- package/dist/esm/msal/index.js +13 -0
- package/dist/esm/msal/index.js.map +1 -1
- package/dist/esm/msal/useAccessToken.js +15 -3
- package/dist/esm/msal/useAccessToken.js.map +1 -1
- package/dist/esm/msal/useCurrentAccount.js +12 -2
- package/dist/esm/msal/useCurrentAccount.js.map +1 -1
- package/dist/esm/msal/useToken.js +19 -3
- package/dist/esm/msal/useToken.js.map +1 -1
- package/dist/esm/navigation/index.js +8 -0
- package/dist/esm/navigation/index.js.map +1 -1
- package/dist/esm/navigation/useNavigationModule.js +6 -1
- package/dist/esm/navigation/useNavigationModule.js.map +1 -1
- package/dist/esm/navigation/useRouter.js +23 -4
- package/dist/esm/navigation/useRouter.js.map +1 -1
- package/dist/esm/render-app.js +19 -4
- package/dist/esm/render-app.js.map +1 -1
- package/dist/esm/render-component.js +16 -8
- package/dist/esm/render-component.js.map +1 -1
- package/dist/esm/settings/index.js +8 -0
- package/dist/esm/settings/index.js.map +1 -1
- package/dist/esm/useAppModule.js +13 -5
- package/dist/esm/useAppModule.js.map +1 -1
- package/dist/esm/useAppModules.js +9 -3
- package/dist/esm/useAppModules.js.map +1 -1
- package/dist/esm/version.js +1 -1
- package/dist/esm/version.js.map +1 -1
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/dist/types/ag-grid/useTheme.d.ts +7 -0
- package/dist/types/analytics/index.d.ts +8 -0
- package/dist/types/analytics/useTrackFeature.d.ts +17 -1
- package/dist/types/apploader/index.d.ts +8 -0
- package/dist/types/bookmark/index.d.ts +8 -0
- package/dist/types/context/index.d.ts +8 -0
- package/dist/types/context/useContextProvider.d.ts +6 -0
- package/dist/types/context/useCurrentContext.d.ts +14 -0
- package/dist/types/create-legacy-app.d.ts +13 -0
- package/dist/types/feature-flag/index.d.ts +8 -0
- package/dist/types/feature-flag/useFeature.d.ts +20 -4
- package/dist/types/framework/index.d.ts +8 -0
- package/dist/types/framework/useFrameworkCurrentContext.d.ts +9 -0
- package/dist/types/help-center/useHelpCenter.d.ts +12 -1
- package/dist/types/http/index.d.ts +9 -0
- package/dist/types/http/selectors.d.ts +8 -0
- package/dist/types/index.d.ts +15 -0
- package/dist/types/make-component.d.ts +15 -0
- package/dist/types/msal/index.d.ts +13 -0
- package/dist/types/msal/useAccessToken.d.ts +15 -3
- package/dist/types/msal/useCurrentAccount.d.ts +12 -2
- package/dist/types/msal/useToken.d.ts +19 -3
- package/dist/types/navigation/index.d.ts +8 -0
- package/dist/types/navigation/useNavigationModule.d.ts +6 -1
- package/dist/types/navigation/useRouter.d.ts +23 -4
- package/dist/types/render-app.d.ts +19 -4
- package/dist/types/render-component.d.ts +13 -4
- package/dist/types/settings/index.d.ts +8 -0
- package/dist/types/useAppModule.d.ts +13 -5
- package/dist/types/useAppModules.d.ts +9 -3
- package/dist/types/version.d.ts +1 -1
- package/package.json +22 -23
- package/src/ag-grid/useTheme.ts +7 -0
- package/src/analytics/index.ts +8 -0
- package/src/analytics/useTrackFeature.ts +17 -1
- package/src/apploader/index.ts +8 -0
- package/src/bookmark/index.ts +8 -0
- package/src/context/index.ts +8 -0
- package/src/context/useContextProvider.ts +6 -0
- package/src/context/useCurrentContext.ts +14 -0
- package/src/create-legacy-app.tsx +13 -0
- package/src/feature-flag/index.ts +8 -0
- package/src/feature-flag/useFeature.ts +20 -4
- package/src/framework/index.ts +8 -1
- package/src/framework/useFrameworkCurrentContext.ts +9 -0
- package/src/help-center/useHelpCenter.ts +12 -1
- package/src/http/index.ts +9 -0
- package/src/http/selectors.ts +8 -0
- package/src/index.ts +16 -0
- package/src/make-component.tsx +15 -0
- package/src/msal/index.ts +13 -0
- package/src/msal/useAccessToken.ts +15 -3
- package/src/msal/useCurrentAccount.ts +12 -2
- package/src/msal/useToken.ts +19 -3
- package/src/navigation/index.ts +8 -0
- package/src/navigation/useNavigationModule.ts +6 -1
- package/src/navigation/useRouter.ts +23 -4
- package/src/render-app.ts +19 -4
- package/src/render-component.tsx +20 -8
- package/src/settings/index.ts +8 -0
- package/src/useAppModule.ts +13 -5
- package/src/useAppModules.ts +9 -3
- package/src/version.ts +1 -1
- package/vitest.config.ts +4 -9
package/src/ag-grid/useTheme.ts
CHANGED
|
@@ -2,6 +2,13 @@ import { useAppModule } from '../useAppModule';
|
|
|
2
2
|
import type { AgGridModule } from '@equinor/fusion-framework-module-ag-grid';
|
|
3
3
|
import type { Theme } from '@equinor/fusion-framework-module-ag-grid/themes';
|
|
4
4
|
|
|
5
|
+
/**
|
|
6
|
+
* React hook that returns the current AG Grid theme from the application-scoped
|
|
7
|
+
* AG Grid module.
|
|
8
|
+
*
|
|
9
|
+
* @returns The active {@link Theme} object.
|
|
10
|
+
* @throws If the AG Grid module is not registered in the application.
|
|
11
|
+
*/
|
|
5
12
|
export const useTheme = (): Theme => {
|
|
6
13
|
const agGrid = useAppModule<AgGridModule>('agGrid');
|
|
7
14
|
|
package/src/analytics/index.ts
CHANGED
|
@@ -1 +1,9 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Analytics sub-path entry-point.
|
|
3
|
+
*
|
|
4
|
+
* Provides the {@link useTrackFeature} hook for tracking application-level
|
|
5
|
+
* analytics events through the Fusion analytics module.
|
|
6
|
+
*
|
|
7
|
+
* @packageDocumentation
|
|
8
|
+
*/
|
|
1
9
|
export { useTrackFeature } from './useTrackFeature';
|
|
@@ -4,7 +4,23 @@ import type { AnalyticsModule, AnyValueMap } from '@equinor/fusion-framework-mod
|
|
|
4
4
|
import { useCallback } from 'react';
|
|
5
5
|
|
|
6
6
|
/**
|
|
7
|
-
*
|
|
7
|
+
* React hook that returns a callback for tracking application feature usage
|
|
8
|
+
* via the Fusion analytics module.
|
|
9
|
+
*
|
|
10
|
+
* The tracked event includes the current app key and context (if available)
|
|
11
|
+
* as attributes, enabling downstream analytics dashboards to group events
|
|
12
|
+
* by application and context.
|
|
13
|
+
*
|
|
14
|
+
* @returns A `trackFeature` callback: `(name: string, data?: AnyValueMap) => void`.
|
|
15
|
+
*
|
|
16
|
+
* @example
|
|
17
|
+
* ```tsx
|
|
18
|
+
* const trackFeature = useTrackFeature();
|
|
19
|
+
*
|
|
20
|
+
* const handleClick = useCallback(() => {
|
|
21
|
+
* trackFeature('button-click', { section: 'header' });
|
|
22
|
+
* }, [trackFeature]);
|
|
23
|
+
* ```
|
|
8
24
|
*/
|
|
9
25
|
export const useTrackFeature = () => {
|
|
10
26
|
const analyticsProvider = useFrameworkModule<AnalyticsModule>('analytics');
|
package/src/apploader/index.ts
CHANGED
|
@@ -1,2 +1,10 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Apploader sub-path entry-point.
|
|
3
|
+
*
|
|
4
|
+
* Provides the {@link Apploader} component and {@link useApploader} hook
|
|
5
|
+
* for embedding Fusion child applications inside a parent Fusion application.
|
|
6
|
+
*
|
|
7
|
+
* @packageDocumentation
|
|
8
|
+
*/
|
|
1
9
|
export { Apploader, type ApploaderProps } from './Apploader';
|
|
2
10
|
export { useApploader } from './useApploader';
|
package/src/bookmark/index.ts
CHANGED
|
@@ -1,3 +1,11 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Bookmark sub-path entry-point.
|
|
3
|
+
*
|
|
4
|
+
* Provides helpers to enable and consume the Fusion bookmark module,
|
|
5
|
+
* allowing users to save and restore application state snapshots.
|
|
6
|
+
*
|
|
7
|
+
* @packageDocumentation
|
|
8
|
+
*/
|
|
1
9
|
export { enableBookmark } from '@equinor/fusion-framework-app/enable-bookmark';
|
|
2
10
|
|
|
3
11
|
export { useCurrentBookmark } from './useCurrentBookmark';
|
package/src/context/index.ts
CHANGED
|
@@ -1,3 +1,11 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Context sub-path entry-point.
|
|
3
|
+
*
|
|
4
|
+
* Provides hooks for reading and interacting with the Fusion context
|
|
5
|
+
* (project, facility, etc.) at both the application and framework level.
|
|
6
|
+
*
|
|
7
|
+
* @packageDocumentation
|
|
8
|
+
*/
|
|
1
9
|
export * from '@equinor/fusion-framework-react-module-context';
|
|
2
10
|
|
|
3
11
|
export { useContextProvider } from './useContextProvider';
|
|
@@ -1,6 +1,12 @@
|
|
|
1
1
|
import type { ContextModule } from '@equinor/fusion-framework-react-module-context';
|
|
2
2
|
import { useAppModule } from '../useAppModule';
|
|
3
3
|
|
|
4
|
+
/**
|
|
5
|
+
* React hook that resolves the application-scoped context module provider.
|
|
6
|
+
*
|
|
7
|
+
* @returns The context module provider instance.
|
|
8
|
+
* @throws If the context module is not registered in the application scope.
|
|
9
|
+
*/
|
|
4
10
|
export const useContextProvider = () => useAppModule<ContextModule>('context');
|
|
5
11
|
|
|
6
12
|
export default useContextProvider;
|
|
@@ -1,6 +1,20 @@
|
|
|
1
1
|
import { useCurrentContext as _useCurrentContext } from '@equinor/fusion-framework-react-module-context';
|
|
2
2
|
import useContextProvider from './useContextProvider';
|
|
3
3
|
|
|
4
|
+
/**
|
|
5
|
+
* React hook that returns the currently selected Fusion context from the
|
|
6
|
+
* **application-scoped** context module.
|
|
7
|
+
*
|
|
8
|
+
* @returns The current context object, or `undefined` if no context is selected.
|
|
9
|
+
*
|
|
10
|
+
* @example
|
|
11
|
+
* ```tsx
|
|
12
|
+
* const context = useCurrentContext();
|
|
13
|
+
* if (context) {
|
|
14
|
+
* console.log('Selected:', context.title);
|
|
15
|
+
* }
|
|
16
|
+
* ```
|
|
17
|
+
*/
|
|
4
18
|
export const useCurrentContext = () => _useCurrentContext(useContextProvider());
|
|
5
19
|
|
|
6
20
|
export default useCurrentContext;
|
|
@@ -8,6 +8,19 @@ import type { AppEnv, AppModuleInitiator } from '@equinor/fusion-framework-app';
|
|
|
8
8
|
import { createComponent } from './create-component';
|
|
9
9
|
import type { AppModule } from '@equinor/fusion-framework-module-app';
|
|
10
10
|
|
|
11
|
+
/**
|
|
12
|
+
* Creates a legacy wrapper component that bootstraps a Fusion React app within
|
|
13
|
+
* the older Fusion CLI hosting model.
|
|
14
|
+
*
|
|
15
|
+
* @deprecated Prefer {@link renderApp} for new applications. This helper exists
|
|
16
|
+
* only for backward-compatibility with apps that must run inside the legacy
|
|
17
|
+
* Fusion CLI.
|
|
18
|
+
*
|
|
19
|
+
* @template TModules - Array of additional module types to initialise.
|
|
20
|
+
* @param Component - The root React element to render.
|
|
21
|
+
* @param configure - Optional callback to configure application modules.
|
|
22
|
+
* @returns A React function component that initialises modules and renders the app.
|
|
23
|
+
*/
|
|
11
24
|
export const createLegacyApp = <TModules extends Array<AnyModule>>(
|
|
12
25
|
Component: ElementType,
|
|
13
26
|
configure?: AppModuleInitiator<TModules>,
|
|
@@ -1,3 +1,11 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Feature-flag sub-path entry-point.
|
|
3
|
+
*
|
|
4
|
+
* Provides the {@link enableFeatureFlag} configurator helper and the
|
|
5
|
+
* {@link useFeature} hook for reading and toggling feature flags at runtime.
|
|
6
|
+
*
|
|
7
|
+
* @packageDocumentation
|
|
8
|
+
*/
|
|
1
9
|
export {
|
|
2
10
|
IFeatureFlag,
|
|
3
11
|
IFeatureFlagProvider,
|
|
@@ -13,10 +13,26 @@ import { findFeature } from '@equinor/fusion-framework-module-feature-flag/selec
|
|
|
13
13
|
import { useAppModule } from '../useAppModule';
|
|
14
14
|
|
|
15
15
|
/**
|
|
16
|
-
*
|
|
17
|
-
*
|
|
18
|
-
*
|
|
19
|
-
*
|
|
16
|
+
* React hook for reading and toggling a single feature flag.
|
|
17
|
+
*
|
|
18
|
+
* Merges feature flags from both the framework and the application scope,
|
|
19
|
+
* so framework-level flags are visible alongside app-specific ones.
|
|
20
|
+
*
|
|
21
|
+
* @template T - The type of the feature flag's value payload.
|
|
22
|
+
* @param key - The unique key identifying the feature flag.
|
|
23
|
+
* @returns An object with:
|
|
24
|
+
* - `feature` – the resolved {@link IFeatureFlag}, or `undefined` if not found.
|
|
25
|
+
* - `toggleFeature` – callback to toggle the flag; pass `true`/`false` to
|
|
26
|
+
* set explicitly, or omit to invert the current state.
|
|
27
|
+
* - `error` – any error from the feature-flag observable.
|
|
28
|
+
*
|
|
29
|
+
* @example
|
|
30
|
+
* ```tsx
|
|
31
|
+
* const { feature, toggleFeature } = useFeature('dark-mode');
|
|
32
|
+
* return (
|
|
33
|
+
* <Switch checked={feature?.enabled} onChange={() => toggleFeature()} />
|
|
34
|
+
* );
|
|
35
|
+
* ```
|
|
20
36
|
*/
|
|
21
37
|
export const useFeature = <T = unknown>(
|
|
22
38
|
key: string,
|
package/src/framework/index.ts
CHANGED
|
@@ -1,6 +1,13 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Framework sub-path entry-point.
|
|
3
|
+
*
|
|
4
|
+
* Re-exports framework-level hooks (as opposed to application-scoped ones)
|
|
5
|
+
* for accessing the Fusion instance, current user, and HTTP clients.
|
|
6
|
+
*
|
|
7
|
+
* @packageDocumentation
|
|
8
|
+
*/
|
|
1
9
|
export { useFramework } from '@equinor/fusion-framework-react';
|
|
2
10
|
|
|
3
|
-
// TODO
|
|
4
11
|
export {
|
|
5
12
|
useCurrentUser,
|
|
6
13
|
useHttpClient as useFrameworkHttpClient,
|
|
@@ -1,6 +1,15 @@
|
|
|
1
1
|
import { useFramework } from '@equinor/fusion-framework-react';
|
|
2
2
|
import { useCurrentContext } from '@equinor/fusion-framework-react-module-context';
|
|
3
3
|
|
|
4
|
+
/**
|
|
5
|
+
* React hook that returns the currently selected context from the
|
|
6
|
+
* **framework-level** context module (as opposed to the application-scoped one).
|
|
7
|
+
*
|
|
8
|
+
* Use this when you need the portal/host context rather than the app's own
|
|
9
|
+
* context provider.
|
|
10
|
+
*
|
|
11
|
+
* @returns The current framework context, or `undefined` if none is selected.
|
|
12
|
+
*/
|
|
4
13
|
export const useFrameworkCurrentContext = () => useCurrentContext(useFramework().modules.context);
|
|
5
14
|
|
|
6
15
|
export default useFrameworkCurrentContext;
|
|
@@ -77,7 +77,18 @@ export interface HelpCenter {
|
|
|
77
77
|
}
|
|
78
78
|
|
|
79
79
|
/**
|
|
80
|
-
*
|
|
80
|
+
* React hook that returns an API for opening the portal help-center sidesheet.
|
|
81
|
+
*
|
|
82
|
+
* Each method dispatches a framework event that the portal shell listens for
|
|
83
|
+
* and opens the corresponding help page.
|
|
84
|
+
*
|
|
85
|
+
* @returns A {@link HelpCenter} object with methods to open specific help pages.
|
|
86
|
+
*
|
|
87
|
+
* @example
|
|
88
|
+
* ```tsx
|
|
89
|
+
* const helpCenter = useHelpCenter();
|
|
90
|
+
* <Button onClick={() => helpCenter.openFaqs()}>FAQs</Button>
|
|
91
|
+
* ```
|
|
81
92
|
*/
|
|
82
93
|
export const useHelpCenter = (): HelpCenter => {
|
|
83
94
|
const eventModule = useAppModule('event');
|
package/src/http/index.ts
CHANGED
|
@@ -1 +1,10 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* HTTP sub-path entry-point.
|
|
3
|
+
*
|
|
4
|
+
* Re-exports hooks from `@equinor/fusion-framework-react-module-http`,
|
|
5
|
+
* including {@link useHttpClient} for making authenticated HTTP requests
|
|
6
|
+
* from within a Fusion application.
|
|
7
|
+
*
|
|
8
|
+
* @packageDocumentation
|
|
9
|
+
*/
|
|
1
10
|
export * from '@equinor/fusion-framework-react-module-http';
|
package/src/http/selectors.ts
CHANGED
|
@@ -1 +1,9 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* HTTP selector utilities.
|
|
3
|
+
*
|
|
4
|
+
* Re-exports response-selector helpers (e.g. JSON, blob, text selectors)
|
|
5
|
+
* from `@equinor/fusion-framework-module-http/selectors`.
|
|
6
|
+
*
|
|
7
|
+
* @packageDocumentation
|
|
8
|
+
*/
|
|
1
9
|
export * from '@equinor/fusion-framework-module-http/selectors';
|
package/src/index.ts
CHANGED
|
@@ -1,3 +1,19 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @packageDocumentation
|
|
3
|
+
*
|
|
4
|
+
* React bindings for building Fusion Framework applications.
|
|
5
|
+
*
|
|
6
|
+
* Provides the main entry-point helpers (`renderApp`, `createComponent`, `makeComponent`)
|
|
7
|
+
* plus React hooks for accessing framework modules (HTTP, auth, context, navigation, etc.)
|
|
8
|
+
* from within a Fusion app.
|
|
9
|
+
*
|
|
10
|
+
* @remarks
|
|
11
|
+
* This is the primary package application developers depend on when building
|
|
12
|
+
* React-based Fusion apps. It re-exports core types from `@equinor/fusion-framework-app`
|
|
13
|
+
* and adds React-specific rendering, hooks, and sub-path entry-points for optional
|
|
14
|
+
* modules such as MSAL, feature flags, bookmarks, analytics, and settings.
|
|
15
|
+
*/
|
|
16
|
+
|
|
1
17
|
export type {
|
|
2
18
|
AppConfig,
|
|
3
19
|
AppEnv,
|
package/src/make-component.tsx
CHANGED
|
@@ -13,11 +13,26 @@ import type { FrameworkEvent, FrameworkEventInit } from '@equinor/fusion-framewo
|
|
|
13
13
|
|
|
14
14
|
import { ModuleProvider as AppModuleProvider } from '@equinor/fusion-framework-react-module';
|
|
15
15
|
|
|
16
|
+
/**
|
|
17
|
+
* Arguments supplied when rendering a Fusion app component.
|
|
18
|
+
*
|
|
19
|
+
* @template TFusion - The Fusion framework instance type.
|
|
20
|
+
* @template TEnv - The application environment type.
|
|
21
|
+
*/
|
|
16
22
|
export type ComponentRenderArgs<TFusion extends Fusion = Fusion, TEnv = AppEnv> = {
|
|
23
|
+
/** The Fusion framework instance. */
|
|
17
24
|
fusion: TFusion;
|
|
25
|
+
/** The application environment (manifest, config, basename, etc.). */
|
|
18
26
|
env: TEnv;
|
|
19
27
|
};
|
|
20
28
|
|
|
29
|
+
/**
|
|
30
|
+
* Factory function that receives a Fusion instance and environment and returns a
|
|
31
|
+
* lazy React component ready to be rendered.
|
|
32
|
+
*
|
|
33
|
+
* @template TFusion - The Fusion framework instance type.
|
|
34
|
+
* @template TEnv - The application environment type.
|
|
35
|
+
*/
|
|
21
36
|
export type ComponentRenderer<TFusion extends Fusion = Fusion, TEnv = AppEnv> = (
|
|
22
37
|
fusion: TFusion,
|
|
23
38
|
env: TEnv,
|
package/src/msal/index.ts
CHANGED
|
@@ -1,3 +1,16 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* MSAL authentication sub-path entry-point.
|
|
3
|
+
*
|
|
4
|
+
* Provides React hooks for accessing MSAL-based authentication state
|
|
5
|
+
* (current account, access tokens) from within a Fusion application.
|
|
6
|
+
*
|
|
7
|
+
* @remarks
|
|
8
|
+
* Requires `@equinor/fusion-framework-module-msal` to be installed and
|
|
9
|
+
* configured by the host/portal. Applications should **not** configure the
|
|
10
|
+
* MSAL module themselves.
|
|
11
|
+
*
|
|
12
|
+
* @packageDocumentation
|
|
13
|
+
*/
|
|
1
14
|
export { useCurrentAccount } from './useCurrentAccount';
|
|
2
15
|
export { useAccessToken } from './useAccessToken';
|
|
3
16
|
export { useToken } from './useToken';
|
|
@@ -1,10 +1,22 @@
|
|
|
1
1
|
import { useToken } from './useToken';
|
|
2
2
|
|
|
3
3
|
/**
|
|
4
|
-
*
|
|
4
|
+
* React hook that acquires an OAuth 2.0 access token string via MSAL.
|
|
5
5
|
*
|
|
6
|
-
* @
|
|
7
|
-
*
|
|
6
|
+
* This is a convenience wrapper around {@link useToken} that extracts the
|
|
7
|
+
* `accessToken` property from the full `AuthenticationResult`.
|
|
8
|
+
*
|
|
9
|
+
* @param req - The token request containing the `scopes` to acquire.
|
|
10
|
+
* @param req.scopes - Array of scope strings (e.g. `['User.Read']`).
|
|
11
|
+
* @returns An object with:
|
|
12
|
+
* - `token` – the access token string, or `undefined` while pending.
|
|
13
|
+
* - `pending` – `true` while the token is being acquired.
|
|
14
|
+
* - `error` – any error encountered during acquisition.
|
|
15
|
+
*
|
|
16
|
+
* @example
|
|
17
|
+
* ```tsx
|
|
18
|
+
* const { token, pending, error } = useAccessToken({ scopes: ['api://my-api/.default'] });
|
|
19
|
+
* ```
|
|
8
20
|
*/
|
|
9
21
|
export const useAccessToken = (req: {
|
|
10
22
|
scopes: string[];
|
|
@@ -2,8 +2,18 @@ import type { AccountInfo } from '@equinor/fusion-framework-module-msal';
|
|
|
2
2
|
import useAppModule from '../useAppModule';
|
|
3
3
|
|
|
4
4
|
/**
|
|
5
|
-
*
|
|
6
|
-
*
|
|
5
|
+
* React hook that returns the currently signed-in user's MSAL account info.
|
|
6
|
+
*
|
|
7
|
+
* @returns The {@link AccountInfo} for the active account, or `undefined` if
|
|
8
|
+
* no user is signed in.
|
|
9
|
+
*
|
|
10
|
+
* @example
|
|
11
|
+
* ```tsx
|
|
12
|
+
* const account = useCurrentAccount();
|
|
13
|
+
* if (account) {
|
|
14
|
+
* console.log('Signed in as', account.name);
|
|
15
|
+
* }
|
|
16
|
+
* ```
|
|
7
17
|
*/
|
|
8
18
|
export const useCurrentAccount = (): AccountInfo | undefined => {
|
|
9
19
|
const msalProvider = useAppModule('auth');
|
package/src/msal/useToken.ts
CHANGED
|
@@ -5,9 +5,25 @@ import type { AuthenticationResult } from '@equinor/fusion-framework-module-msal
|
|
|
5
5
|
import useAppModule from '../useAppModule';
|
|
6
6
|
|
|
7
7
|
/**
|
|
8
|
-
*
|
|
9
|
-
*
|
|
10
|
-
*
|
|
8
|
+
* React hook that acquires a full MSAL {@link AuthenticationResult} for the
|
|
9
|
+
* requested scopes.
|
|
10
|
+
*
|
|
11
|
+
* The hook attempts silent acquisition first and falls back to an interactive
|
|
12
|
+
* prompt when required by the MSAL provider.
|
|
13
|
+
*
|
|
14
|
+
* @param req - The token request containing the `scopes` to acquire.
|
|
15
|
+
* @param req.scopes - Array of scope strings (e.g. `['User.Read']`).
|
|
16
|
+
* @returns An object with:
|
|
17
|
+
* - `token` – the full {@link AuthenticationResult}, or `undefined` while pending.
|
|
18
|
+
* - `pending` – `true` while the token is being acquired.
|
|
19
|
+
* - `error` – any error encountered during acquisition.
|
|
20
|
+
*
|
|
21
|
+
* @example
|
|
22
|
+
* ```tsx
|
|
23
|
+
* const { token, pending } = useToken({ scopes: ['User.Read'] });
|
|
24
|
+
* if (pending) return <Spinner />;
|
|
25
|
+
* console.log('ID token:', token?.idToken);
|
|
26
|
+
* ```
|
|
11
27
|
*/
|
|
12
28
|
export const useToken = (req: {
|
|
13
29
|
scopes: string[];
|
package/src/navigation/index.ts
CHANGED
|
@@ -1,2 +1,10 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Navigation sub-path entry-point.
|
|
3
|
+
*
|
|
4
|
+
* Provides hooks for accessing the Fusion navigation module and creating
|
|
5
|
+
* client-side routers compatible with `react-router`.
|
|
6
|
+
*
|
|
7
|
+
* @packageDocumentation
|
|
8
|
+
*/
|
|
1
9
|
export { useNavigationModule } from './useNavigationModule';
|
|
2
10
|
export { useRouter } from './useRouter';
|
|
@@ -1,5 +1,10 @@
|
|
|
1
1
|
import useAppModule from '../useAppModule';
|
|
2
2
|
import type { INavigationProvider } from '@equinor/fusion-framework-module-navigation';
|
|
3
3
|
|
|
4
|
-
/**
|
|
4
|
+
/**
|
|
5
|
+
* React hook that resolves the application-scoped navigation module provider.
|
|
6
|
+
*
|
|
7
|
+
* @returns The navigation provider instance.
|
|
8
|
+
* @throws If the navigation module has not been enabled for the application.
|
|
9
|
+
*/
|
|
5
10
|
export const useNavigationModule = (): INavigationProvider => useAppModule('navigation');
|
|
@@ -3,10 +3,29 @@ import { useNavigationModule } from './useNavigationModule';
|
|
|
3
3
|
import type { INavigationProvider } from '@equinor/fusion-framework-module-navigation';
|
|
4
4
|
|
|
5
5
|
/**
|
|
6
|
-
*
|
|
7
|
-
*
|
|
8
|
-
*
|
|
9
|
-
*
|
|
6
|
+
* React hook that creates a router instance for client-side navigation.
|
|
7
|
+
*
|
|
8
|
+
* The `routes` argument **must** be static or memoised to avoid re-creating
|
|
9
|
+
* the router on every render.
|
|
10
|
+
*
|
|
11
|
+
* @param routes - An array of route objects compatible with
|
|
12
|
+
* `INavigationProvider.createRouter`.
|
|
13
|
+
* @returns A router instance to pass to `<RouterProvider>`.
|
|
14
|
+
*
|
|
15
|
+
* @see {@link https://equinor.github.io/fusion-framework/modules/navigation/ | Fusion navigation docs}
|
|
16
|
+
* @see {@link https://reactrouter.com/en/main/routers/create-browser-router | react-router docs}
|
|
17
|
+
*
|
|
18
|
+
* @example
|
|
19
|
+
* ```tsx
|
|
20
|
+
* import { useRouter } from '@equinor/fusion-framework-react-app/navigation';
|
|
21
|
+
* import { RouterProvider } from 'react-router-dom';
|
|
22
|
+
*
|
|
23
|
+
* const routes = [{ path: '/', element: <Home /> }];
|
|
24
|
+
* const App = () => {
|
|
25
|
+
* const router = useRouter(routes);
|
|
26
|
+
* return <RouterProvider router={router} />;
|
|
27
|
+
* };
|
|
28
|
+
* ```
|
|
10
29
|
*/
|
|
11
30
|
export const useRouter = (
|
|
12
31
|
routes: Parameters<INavigationProvider['createRouter']>[0],
|
package/src/render-app.ts
CHANGED
|
@@ -4,11 +4,26 @@ import { renderComponent, type RenderTeardown } from './render-component';
|
|
|
4
4
|
import type { ComponentRenderArgs } from './create-component';
|
|
5
5
|
|
|
6
6
|
/**
|
|
7
|
-
* Creates a render function for
|
|
8
|
-
* Uses React 18's createRoot API via renderComponent.
|
|
7
|
+
* Creates a render function for a Fusion React application.
|
|
9
8
|
*
|
|
10
|
-
* @
|
|
11
|
-
*
|
|
9
|
+
* Wraps {@link createComponent} and {@link renderComponent} into a single factory:
|
|
10
|
+
* call the returned function with an `HTMLElement` and `ComponentRenderArgs` to
|
|
11
|
+
* mount the app using React 18's `createRoot` API.
|
|
12
|
+
*
|
|
13
|
+
* @param componentArgs - Arguments forwarded to {@link createComponent} (the React
|
|
14
|
+
* component to render and an optional module-configuration callback).
|
|
15
|
+
* @returns A mount function that accepts a DOM element and render args, and returns
|
|
16
|
+
* a {@link RenderTeardown} callback to unmount the application.
|
|
17
|
+
*
|
|
18
|
+
* @example
|
|
19
|
+
* ```ts
|
|
20
|
+
* import { renderApp } from '@equinor/fusion-framework-react-app';
|
|
21
|
+
* import { App } from './App';
|
|
22
|
+
* import { configure } from './config';
|
|
23
|
+
*
|
|
24
|
+
* export const render = renderApp(App, configure);
|
|
25
|
+
* export default render;
|
|
26
|
+
* ```
|
|
12
27
|
*/
|
|
13
28
|
export const renderApp = (...componentArgs: Parameters<typeof createComponent>) => {
|
|
14
29
|
const renderer = renderComponent(createComponent(...componentArgs));
|
package/src/render-component.tsx
CHANGED
|
@@ -3,14 +3,21 @@ import type { FunctionComponent } from 'react';
|
|
|
3
3
|
import { createRoot, type Root } from 'react-dom/client';
|
|
4
4
|
import type { ComponentRenderArgs, ComponentRenderer } from './create-component';
|
|
5
5
|
|
|
6
|
+
/**
|
|
7
|
+
* Callback returned after mounting an application; invoke it to unmount and clean
|
|
8
|
+
* up the React root.
|
|
9
|
+
*/
|
|
6
10
|
export type RenderTeardown = VoidFunction;
|
|
7
11
|
|
|
8
12
|
/**
|
|
9
|
-
* Renders a React component into a DOM element using React 18's createRoot API.
|
|
13
|
+
* Renders a React component into a DOM element using React 18's `createRoot` API.
|
|
10
14
|
*
|
|
11
|
-
*
|
|
12
|
-
*
|
|
13
|
-
*
|
|
15
|
+
* The component is wrapped in `<StrictMode>` and `<Suspense>` with a basic
|
|
16
|
+
* loading fallback.
|
|
17
|
+
*
|
|
18
|
+
* @param el - The DOM element to render into.
|
|
19
|
+
* @param Component - The React function component to render.
|
|
20
|
+
* @returns A {@link RenderTeardown} callback that unmounts the component.
|
|
14
21
|
*/
|
|
15
22
|
const render = (el: Element, Component: FunctionComponent): RenderTeardown => {
|
|
16
23
|
const root: Root = createRoot(el);
|
|
@@ -27,11 +34,16 @@ const render = (el: Element, Component: FunctionComponent): RenderTeardown => {
|
|
|
27
34
|
};
|
|
28
35
|
|
|
29
36
|
/**
|
|
30
|
-
* Creates a
|
|
31
|
-
*
|
|
37
|
+
* Creates a mount function from a {@link ComponentRenderer}.
|
|
38
|
+
*
|
|
39
|
+
* The returned function accepts a target `HTMLElement` and
|
|
40
|
+
* {@link ComponentRenderArgs}, resolves the lazy component via the renderer,
|
|
41
|
+
* and mounts it with React 18's `createRoot`.
|
|
32
42
|
*
|
|
33
|
-
* @param renderer - A
|
|
34
|
-
*
|
|
43
|
+
* @param renderer - A {@link ComponentRenderer} that produces a lazy component
|
|
44
|
+
* from Fusion and environment arguments.
|
|
45
|
+
* @returns A function `(el, args) => RenderTeardown` that mounts the app and
|
|
46
|
+
* returns a teardown callback.
|
|
35
47
|
*/
|
|
36
48
|
export const renderComponent = (renderer: ComponentRenderer) => {
|
|
37
49
|
return (el: HTMLElement, args: ComponentRenderArgs): RenderTeardown => {
|
package/src/settings/index.ts
CHANGED
|
@@ -1,3 +1,11 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Settings sub-path entry-point.
|
|
3
|
+
*
|
|
4
|
+
* Provides hooks for reading and updating per-application user settings
|
|
5
|
+
* that are persisted by the Fusion platform.
|
|
6
|
+
*
|
|
7
|
+
* @packageDocumentation
|
|
8
|
+
*/
|
|
1
9
|
export { useAppSetting } from './useAppSetting';
|
|
2
10
|
export { useAppSettings } from './useAppSettings';
|
|
3
11
|
|
package/src/useAppModule.ts
CHANGED
|
@@ -9,12 +9,20 @@ import type {
|
|
|
9
9
|
import { useAppModules } from './useAppModules';
|
|
10
10
|
|
|
11
11
|
/**
|
|
12
|
-
*
|
|
12
|
+
* React hook that retrieves a single module instance from the application scope.
|
|
13
13
|
*
|
|
14
|
-
* @template TType - The
|
|
15
|
-
*
|
|
16
|
-
* @
|
|
17
|
-
* @
|
|
14
|
+
* @template TType - The concrete module type (e.g. `ContextModule`). Pass
|
|
15
|
+
* `unknown` to infer the type from the key.
|
|
16
|
+
* @template TKey - The string key used to look up the module.
|
|
17
|
+
* @param module - The key identifying the module to retrieve.
|
|
18
|
+
* @returns The resolved module instance.
|
|
19
|
+
* @throws If the requested module is not registered in the application scope.
|
|
20
|
+
*
|
|
21
|
+
* @example
|
|
22
|
+
* ```tsx
|
|
23
|
+
* const auth = useAppModule('auth');
|
|
24
|
+
* auth.acquireAccessToken().then(console.log);
|
|
25
|
+
* ```
|
|
18
26
|
*/
|
|
19
27
|
export function useAppModule<
|
|
20
28
|
TType extends AnyModule | unknown = unknown,
|
package/src/useAppModules.ts
CHANGED
|
@@ -3,10 +3,16 @@ import type { AnyModule } from '@equinor/fusion-framework-module';
|
|
|
3
3
|
import { useModules } from '@equinor/fusion-framework-react-module';
|
|
4
4
|
|
|
5
5
|
/**
|
|
6
|
-
*
|
|
6
|
+
* React hook that returns the full set of initialised application-scoped modules.
|
|
7
7
|
*
|
|
8
|
-
* @template T -
|
|
9
|
-
* @returns
|
|
8
|
+
* @template T - Optional array of additional module types beyond the defaults.
|
|
9
|
+
* @returns The {@link AppModulesInstance} containing all registered modules.
|
|
10
|
+
*
|
|
11
|
+
* @example
|
|
12
|
+
* ```tsx
|
|
13
|
+
* const modules = useAppModules();
|
|
14
|
+
* console.log(Object.keys(modules));
|
|
15
|
+
* ```
|
|
10
16
|
*/
|
|
11
17
|
export const useAppModules = <
|
|
12
18
|
T extends Array<AnyModule> | unknown = unknown,
|
package/src/version.ts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
// Generated by genversion.
|
|
2
|
-
export const version = '
|
|
2
|
+
export const version = '10.0.0';
|
package/vitest.config.ts
CHANGED
|
@@ -1,17 +1,12 @@
|
|
|
1
1
|
import { defineProject } from 'vitest/config';
|
|
2
|
-
import tsconfigPaths from 'vite-tsconfig-paths';
|
|
3
|
-
import { fileURLToPath } from 'node:url';
|
|
4
|
-
import { resolve } from 'node:path';
|
|
5
2
|
|
|
6
3
|
import { name, version } from './package.json';
|
|
7
4
|
|
|
8
5
|
export default defineProject({
|
|
9
|
-
|
|
10
|
-
tsconfigPaths
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
}),
|
|
14
|
-
],
|
|
6
|
+
resolve: {
|
|
7
|
+
// @ts-expect-error -- tsconfigPaths is a Vite 8 option; vitest 4.x ships Vite 7 types
|
|
8
|
+
tsconfigPaths: true,
|
|
9
|
+
},
|
|
15
10
|
test: {
|
|
16
11
|
include: ['src/__tests__/**'],
|
|
17
12
|
name: `${name}@${version}`,
|