@equinor/fusion-framework-react 8.0.0-next.0 → 8.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.
Files changed (103) hide show
  1. package/CHANGELOG.md +48 -12
  2. package/README.md +164 -31
  3. package/dist/esm/Framework.js +32 -0
  4. package/dist/esm/Framework.js.map +1 -1
  5. package/dist/esm/app/index.js.map +1 -1
  6. package/dist/esm/app/useAppProvider.js +11 -2
  7. package/dist/esm/app/useAppProvider.js.map +1 -1
  8. package/dist/esm/app/useApps.js +17 -3
  9. package/dist/esm/app/useApps.js.map +1 -1
  10. package/dist/esm/app/useCurrentApp.js +25 -4
  11. package/dist/esm/app/useCurrentApp.js.map +1 -1
  12. package/dist/esm/app/useCurrentAppModule.js +13 -7
  13. package/dist/esm/app/useCurrentAppModule.js.map +1 -1
  14. package/dist/esm/app/useCurrentAppModules.js +14 -4
  15. package/dist/esm/app/useCurrentAppModules.js.map +1 -1
  16. package/dist/esm/context/index.js +10 -0
  17. package/dist/esm/context/index.js.map +1 -1
  18. package/dist/esm/context/useCurrentContext.js +16 -0
  19. package/dist/esm/context/useCurrentContext.js.map +1 -1
  20. package/dist/esm/context.js +9 -0
  21. package/dist/esm/context.js.map +1 -1
  22. package/dist/esm/create-framework-provider.js +29 -8
  23. package/dist/esm/create-framework-provider.js.map +1 -1
  24. package/dist/esm/feature-flag/index.js +10 -0
  25. package/dist/esm/feature-flag/index.js.map +1 -1
  26. package/dist/esm/feature-flag/useCurrentAppFeatures.js +12 -2
  27. package/dist/esm/feature-flag/useCurrentAppFeatures.js.map +1 -1
  28. package/dist/esm/feature-flag/useFeature.js +12 -5
  29. package/dist/esm/feature-flag/useFeature.js.map +1 -1
  30. package/dist/esm/feature-flag/useFeatures.js +14 -5
  31. package/dist/esm/feature-flag/useFeatures.js.map +1 -1
  32. package/dist/esm/feature-flag/useFrameworkFeature.js +12 -5
  33. package/dist/esm/feature-flag/useFrameworkFeature.js.map +1 -1
  34. package/dist/esm/feature-flag/useFrameworkFeatures.js +11 -4
  35. package/dist/esm/feature-flag/useFrameworkFeatures.js.map +1 -1
  36. package/dist/esm/hooks/index.js +8 -0
  37. package/dist/esm/hooks/index.js.map +1 -1
  38. package/dist/esm/hooks/use-current-user.js +14 -0
  39. package/dist/esm/hooks/use-current-user.js.map +1 -1
  40. package/dist/esm/hooks/use-http-client.js +13 -0
  41. package/dist/esm/hooks/use-http-client.js.map +1 -1
  42. package/dist/esm/http/index.js +10 -0
  43. package/dist/esm/http/index.js.map +1 -1
  44. package/dist/esm/index.js +8 -0
  45. package/dist/esm/index.js.map +1 -1
  46. package/dist/esm/useFramework.js +16 -4
  47. package/dist/esm/useFramework.js.map +1 -1
  48. package/dist/esm/useFrameworkModule.js +13 -6
  49. package/dist/esm/useFrameworkModule.js.map +1 -1
  50. package/dist/esm/version.js +1 -1
  51. package/dist/esm/version.js.map +1 -1
  52. package/dist/tsconfig.tsbuildinfo +1 -1
  53. package/dist/types/Framework.d.ts +37 -0
  54. package/dist/types/app/index.d.ts +10 -0
  55. package/dist/types/app/useAppProvider.d.ts +11 -2
  56. package/dist/types/app/useApps.d.ts +17 -3
  57. package/dist/types/app/useCurrentApp.d.ts +25 -4
  58. package/dist/types/app/useCurrentAppModule.d.ts +13 -7
  59. package/dist/types/app/useCurrentAppModules.d.ts +14 -4
  60. package/dist/types/context/index.d.ts +10 -0
  61. package/dist/types/context/useCurrentContext.d.ts +16 -0
  62. package/dist/types/context.d.ts +0 -1
  63. package/dist/types/create-framework-provider.d.ts +29 -8
  64. package/dist/types/feature-flag/index.d.ts +10 -0
  65. package/dist/types/feature-flag/useCurrentAppFeatures.d.ts +12 -2
  66. package/dist/types/feature-flag/useFeature.d.ts +23 -6
  67. package/dist/types/feature-flag/useFeatures.d.ts +23 -6
  68. package/dist/types/feature-flag/useFrameworkFeature.d.ts +12 -5
  69. package/dist/types/feature-flag/useFrameworkFeatures.d.ts +11 -4
  70. package/dist/types/hooks/index.d.ts +8 -0
  71. package/dist/types/hooks/use-current-user.d.ts +14 -0
  72. package/dist/types/hooks/use-http-client.d.ts +15 -0
  73. package/dist/types/http/index.d.ts +10 -0
  74. package/dist/types/index.d.ts +8 -0
  75. package/dist/types/useFramework.d.ts +16 -4
  76. package/dist/types/useFrameworkModule.d.ts +13 -6
  77. package/dist/types/version.d.ts +1 -1
  78. package/package.json +15 -14
  79. package/src/Framework.tsx +37 -0
  80. package/src/app/index.ts +10 -0
  81. package/src/app/useAppProvider.ts +11 -2
  82. package/src/app/useApps.ts +17 -3
  83. package/src/app/useCurrentApp.ts +25 -4
  84. package/src/app/useCurrentAppModule.ts +13 -7
  85. package/src/app/useCurrentAppModules.ts +14 -4
  86. package/src/context/index.ts +10 -0
  87. package/src/context/useCurrentContext.ts +16 -0
  88. package/src/context.ts +9 -0
  89. package/src/create-framework-provider.tsx +29 -8
  90. package/src/feature-flag/index.ts +10 -0
  91. package/src/feature-flag/useCurrentAppFeatures.ts +12 -2
  92. package/src/feature-flag/useFeature.ts +23 -6
  93. package/src/feature-flag/useFeatures.ts +23 -6
  94. package/src/feature-flag/useFrameworkFeature.ts +12 -5
  95. package/src/feature-flag/useFrameworkFeatures.ts +11 -4
  96. package/src/hooks/index.ts +8 -0
  97. package/src/hooks/use-current-user.ts +14 -0
  98. package/src/hooks/use-http-client.ts +16 -0
  99. package/src/http/index.ts +10 -0
  100. package/src/index.tsx +8 -0
  101. package/src/useFramework.ts +16 -4
  102. package/src/useFrameworkModule.ts +13 -6
  103. package/src/version.ts +1 -1
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@equinor/fusion-framework-react",
3
- "version": "8.0.0-next.0",
3
+ "version": "8.0.0",
4
4
  "description": "",
5
5
  "main": "dist/esm/index.js",
6
6
  "types": "dist/types/index.d.ts",
@@ -72,30 +72,31 @@
72
72
  },
73
73
  "dependencies": {
74
74
  "rxjs": "^7.8.1",
75
- "@equinor/fusion-framework": "^7.4.3-next.0",
76
- "@equinor/fusion-framework-react-module": "^4.0.0-next.0",
77
- "@equinor/fusion-framework-module": "^5.0.6-next.0",
78
- "@equinor/fusion-observable": "^9.0.0-next.0",
79
- "@equinor/fusion-framework-react-module-http": "^11.0.0-next.0"
75
+ "@equinor/fusion-framework": "^8.0.0",
76
+ "@equinor/fusion-framework-module": "^6.0.0",
77
+ "@equinor/fusion-framework-react-module-http": "^11.0.0",
78
+ "@equinor/fusion-framework-react-module": "^4.0.0",
79
+ "@equinor/fusion-observable": "^9.0.0"
80
80
  },
81
81
  "devDependencies": {
82
82
  "@types/react": "^19.2.7",
83
83
  "@types/react-dom": "^19.2.3",
84
84
  "react": "^19.2.1",
85
85
  "react-dom": "^19.2.1",
86
- "typescript": "^5.8.2",
87
- "@equinor/fusion-framework-module-feature-flag": "^2.0.0-next.0",
88
- "@equinor/fusion-framework-module-app": "^7.2.0-next.0",
89
- "@equinor/fusion-framework-module-msal": "^7.0.0-next.0",
90
- "@equinor/fusion-framework-react-module-context": "^7.0.0-next.0",
91
- "@equinor/fusion-framework-module-event": "^4.4.1-next.0"
86
+ "typescript": "^5.9.3",
87
+ "@equinor/fusion-framework-module-app": "^8.0.0",
88
+ "@equinor/fusion-framework-module-event": "^6.0.0",
89
+ "@equinor/fusion-framework-module-feature-flag": "^2.0.0",
90
+ "@equinor/fusion-framework-module-msal": "^8.0.0",
91
+ "@equinor/fusion-framework-react-module-context": "^7.0.0",
92
+ "@equinor/fusion-framework-react-module-signalr": "^4.0.0"
92
93
  },
93
94
  "peerDependencies": {
94
95
  "@types/react": "^18.0.0 || ^19.0.0",
95
96
  "react": "^18.0.0 || ^19.0.0",
96
97
  "react-dom": "^18.0.0 || ^19.0.0",
97
- "@equinor/fusion-framework-module-feature-flag": "^2.0.0-next.0",
98
- "@equinor/fusion-framework-react-module-signalr": "^4.0.0-next.0"
98
+ "@equinor/fusion-framework-react-module-signalr": "^4.0.0",
99
+ "@equinor/fusion-framework-module-feature-flag": "^2.0.0"
99
100
  },
100
101
  "peerDependenciesMeta": {
101
102
  "@equinor/fusion-framework-module-event": {
package/src/Framework.tsx CHANGED
@@ -4,8 +4,45 @@ import { type PropsWithChildren, type ReactNode, Suspense, useMemo } from 'react
4
4
  import { useModules } from '@equinor/fusion-framework-react-module';
5
5
  import type { ModulesInstance } from '@equinor/fusion-framework-module';
6
6
 
7
+ /**
8
+ * Callback invoked during framework initialisation to configure modules.
9
+ *
10
+ * @param configurator - The framework configurator instance to apply settings to.
11
+ */
7
12
  type ConfigureCallback = (configurator: FrameworkConfigurator) => void;
8
13
 
14
+ /**
15
+ * Declarative React component that initialises a Fusion Framework instance
16
+ * and provides it to descendant components via context.
17
+ *
18
+ * @remarks
19
+ * Internally calls {@link createFrameworkProvider} and wraps the lazy-loaded
20
+ * provider in a `<Suspense>` boundary. This is the recommended high-level
21
+ * component for portal / host applications that need to bootstrap the
22
+ * framework inside a React tree.
23
+ *
24
+ * @param props.configure - Callback that receives a {@link FrameworkConfigurator}
25
+ * for registering modules and configuration.
26
+ * @param props.fallback - React node shown while the framework is initialising.
27
+ * @param props.parent - Optional parent module instance to inherit configuration from.
28
+ * @param props.children - Application content rendered after initialisation.
29
+ *
30
+ * @example
31
+ * ```tsx
32
+ * import { Framework } from '@equinor/fusion-framework-react';
33
+ *
34
+ * const App = () => (
35
+ * <Framework
36
+ * configure={(configurator) => {
37
+ * configurator.http.configureClient('my-api', { baseUri: 'https://api.example.com' });
38
+ * }}
39
+ * fallback={<span>Loading…</span>}
40
+ * >
41
+ * <MyApp />
42
+ * </Framework>
43
+ * );
44
+ * ```
45
+ */
9
46
  export const Framework = (
10
47
  props: PropsWithChildren<{
11
48
  readonly configure: ConfigureCallback;
package/src/app/index.ts CHANGED
@@ -1,3 +1,13 @@
1
+ /**
2
+ * Application React hooks.
3
+ *
4
+ * @remarks
5
+ * Available via the `@equinor/fusion-framework-react/app` sub-entry-point.
6
+ * Provides hooks and types for querying application manifests, observing
7
+ * the currently active app, and accessing app-level modules.
8
+ *
9
+ * @module
10
+ */
1
11
  export type { AppConfig, AppManifest, AppType, IApp } from '@equinor/fusion-framework-module-app';
2
12
 
3
13
  export { useCurrentApp } from './useCurrentApp';
@@ -4,8 +4,17 @@ import type { AppModule } from '@equinor/fusion-framework-module-app';
4
4
  import { useFramework } from '../useFramework';
5
5
 
6
6
  /**
7
- * React Hook - get appProvider interface
8
- * @returns framework AppModule
7
+ * React hook that returns the App module provider from the framework.
8
+ *
9
+ * @returns The app module instance (`AppModule`) for querying and managing
10
+ * application manifests and the currently active app.
11
+ * @throws {Error} If the `AppModule` is not configured in the framework.
12
+ *
13
+ * @example
14
+ * ```ts
15
+ * const provider = useAppProvider();
16
+ * provider.getAppManifests().subscribe(console.log);
17
+ * ```
9
18
  */
10
19
  export const useAppProvider = (): FusionModulesInstance<[AppModule]>['app'] => {
11
20
  const provider = useFramework<[AppModule]>().modules.app;
@@ -12,9 +12,23 @@ type UseAppsArgs = {
12
12
  };
13
13
 
14
14
  /**
15
- * React Hook - Get apps from framework
16
- * @param args Object with filterByCurrentUser: boolean
17
- * @returns Object {apps, isLoading, error} where apps is Array of ApplicationManifest, isLoading is a boolean on observable complete
15
+ * React hook that retrieves available application manifests from the framework.
16
+ *
17
+ * @param args - Optional filtering options.
18
+ * @param args.filterByCurrentUser - When `true`, only apps accessible to the
19
+ * current user are returned.
20
+ * @returns An object containing:
21
+ * - `apps` — Array of {@link AppManifest} objects, or `undefined` while loading.
22
+ * - `isLoading` — `true` until the observable completes.
23
+ * - `error` — Any error emitted by the underlying observable.
24
+ *
25
+ * @example
26
+ * ```tsx
27
+ * const { apps, isLoading, error } = useApps({ filterByCurrentUser: true });
28
+ * if (isLoading) return <Spinner />;
29
+ * return <AppList apps={apps} />;
30
+ * ```
31
+ *
18
32
  * @since 7.1.1
19
33
  */
20
34
  export const useApps = (
@@ -12,12 +12,33 @@ import type {
12
12
  import { useFramework } from '../useFramework';
13
13
 
14
14
  /**
15
- * Observers the stream of current app and return the latest application
15
+ * React hook that observes and returns the currently active application.
16
16
  *
17
- * __Warning:__ type hint templates are only hints, this does not check if the modules are actually enabled!
17
+ * @remarks
18
+ * Subscribes to the `current$` stream on the App module and returns the
19
+ * latest value together with helpers to change or clear the active app.
18
20
  *
19
- * @template TModule type hint modules which the application has configured
20
- * @template TEnv type hint what kind of environment config the application has
21
+ * **Warning:** The template parameters are compile-time hints only the
22
+ * hook does not validate that the specified modules are actually enabled.
23
+ *
24
+ * @template TModules - Tuple of module types the current app is expected to
25
+ * have configured (type-hint only).
26
+ * @template TEnv - Expected environment configuration shape (type-hint only).
27
+ *
28
+ * @returns An object containing:
29
+ * - `currentApp` — The current {@link CurrentApp} instance, `null` when
30
+ * explicitly cleared, or `undefined` while loading.
31
+ * - `setCurrentApp(appKey)` — Sets the active app by its key.
32
+ * - `clearCurrentApp()` — Clears the currently active app.
33
+ * - `error` — Any error emitted by the observable.
34
+ *
35
+ * @throws {Error} If the `AppModule` is not configured in the framework.
36
+ *
37
+ * @example
38
+ * ```tsx
39
+ * const { currentApp, setCurrentApp } = useCurrentApp();
40
+ * return <button onClick={() => setCurrentApp('my-app')}>{currentApp?.manifest?.name}</button>;
41
+ * ```
21
42
  */
22
43
  export const useCurrentApp = <
23
44
  TModules extends Array<AnyModule> = [],
@@ -8,14 +8,20 @@ import type {
8
8
  import useCurrentAppModules from './useCurrentAppModules';
9
9
 
10
10
  /**
11
- * Retrieves the current app module based on the provided module key.
12
- * @template TType - The type of the module.
13
- * @template TKey - The type of the module key.
14
- * @param {TKey} moduleKey - The key of the module to retrieve.
15
- * @returns {AnyModule | null | undefined} - The current app module or null if not found.
11
+ * React hook that retrieves a specific module from the current application.
12
+ *
13
+ * @template TType - The expected module type.
14
+ * @template TKey - The module key used for look-up.
15
+ * @param moduleKey - The key of the module to retrieve.
16
+ * @returns An object containing:
17
+ * - `module` — The resolved module instance, `null` when no app is
18
+ * selected, or `undefined` if the app does not enable the requested module.
19
+ * - `error` — Any error emitted during initialisation.
20
+ * - `complete` — `true` when the observable has completed.
21
+ *
16
22
  * @remarks
17
- * - when module is null, there are no current selected application
18
- * - when undefined is, the application has not enabled the requested module
23
+ * - A `null` value means no application is currently selected.
24
+ * - An `undefined` value means the application has not enabled the requested module.
19
25
  */
20
26
  export const useCurrentAppModule = <
21
27
  TType extends AnyModule | unknown = unknown,
@@ -7,12 +7,22 @@ import type { AnyModule } from '@equinor/fusion-framework-module';
7
7
  import { useObservableState } from '@equinor/fusion-observable/react';
8
8
 
9
9
  /**
10
- * Observers the stream of current app initialized modules
10
+ * React hook that observes the initialised modules of the current application.
11
11
  *
12
- * __Warning:__ type hint templates are only hints, this does not check if the modules are actually enabled!
12
+ * @remarks
13
+ * Subscribes to the `instance$` stream of the current app and returns the
14
+ * resolved module instances.
13
15
  *
14
- * @template TModule type hint modules which the application has configured
15
- * @returns the observable instance of initialized modules of the application
16
+ * **Warning:** The template parameter is a compile-time hint only the
17
+ * hook does not validate that the specified modules are actually enabled.
18
+ *
19
+ * @template TModules - Tuple of module types expected on the current app
20
+ * (type-hint only).
21
+ * @returns An object containing:
22
+ * - `modules` — The initialised {@link AppModulesInstance}, `null` when no
23
+ * app is selected, or `undefined` while loading.
24
+ * - `error` — Any error emitted during initialisation.
25
+ * - `complete` — `true` when the observable has completed.
16
26
  */
17
27
  export const useCurrentAppModules = <TModules extends Array<AnyModule> = []>(): {
18
28
  modules?: AppModulesInstance<TModules> | null;
@@ -1,3 +1,13 @@
1
+ /**
2
+ * Context React hooks.
3
+ *
4
+ * @remarks
5
+ * Available via the `@equinor/fusion-framework-react/context` sub-entry-point.
6
+ * Re-exports the context module’s React API and adds a convenience
7
+ * `useCurrentContext` hook that resolves the module from the framework.
8
+ *
9
+ * @module
10
+ */
1
11
  export * from '@equinor/fusion-framework-react-module-context';
2
12
 
3
13
  export { useCurrentContext } from './useCurrentContext';
@@ -1,6 +1,22 @@
1
1
  import { useCurrentContext as _useCurrentContext } from '@equinor/fusion-framework-react-module-context';
2
2
  import { useFramework } from '../useFramework';
3
3
 
4
+ /**
5
+ * React hook that returns the currently selected Fusion context.
6
+ *
7
+ * @remarks
8
+ * This is a convenience wrapper that resolves the context module from the
9
+ * framework instance and delegates to the underlying
10
+ * `useCurrentContext` hook from `@equinor/fusion-framework-react-module-context`.
11
+ *
12
+ * @returns The current context state as defined by the context module.
13
+ *
14
+ * @example
15
+ * ```ts
16
+ * const { currentContext } = useCurrentContext();
17
+ * console.log(currentContext?.id);
18
+ * ```
19
+ */
4
20
  export const useCurrentContext = () => _useCurrentContext(useFramework().modules.context);
5
21
 
6
22
  export default useCurrentContext;
package/src/context.ts CHANGED
@@ -1,6 +1,15 @@
1
1
  import { createContext } from 'react';
2
2
  import type { Fusion } from '@equinor/fusion-framework';
3
3
 
4
+ /**
5
+ * Internal React context that holds the current {@link Fusion} instance.
6
+ *
7
+ * @remarks
8
+ * Consumers should not use this directly — prefer the {@link useFramework}
9
+ * hook or the {@link FrameworkProvider} component.
10
+ *
11
+ * @internal
12
+ */
4
13
  // eslint-disable-next-line @typescript-eslint/no-explicit-any
5
14
  export const context = createContext<Fusion<any> | null>(null);
6
15
 
@@ -8,20 +8,41 @@ import type { AnyModule, ModulesInstanceType } from '@equinor/fusion-framework-m
8
8
  import { ModuleProvider } from '@equinor/fusion-framework-react-module';
9
9
 
10
10
  /**
11
- * Create a framework provider for react.
11
+ * Creates a lazy-loaded React component that initialises a Fusion Framework
12
+ * instance and exposes it via context providers.
12
13
  *
13
- * This function is for providers of framework, like a portal.
14
+ * @remarks
15
+ * This is the low-level factory used by the {@link Framework} component.
16
+ * Call it when you need fine-grained control over memoisation or when you
17
+ * want to embed the provider in a custom `<Suspense>` boundary.
18
+ *
19
+ * The returned component is created with `React.lazy`, so it **must** be
20
+ * rendered inside a `<Suspense>` boundary.
21
+ *
22
+ * @template TModules - Tuple of additional module types to register.
23
+ * @template TRef - Type of the optional parent module-instance reference.
24
+ *
25
+ * @param cb - Callback that receives a {@link FrameworkConfigurator} (and an
26
+ * optional parent ref) for registering modules and configuration.
27
+ * @param ref - Optional parent module instance to inherit configuration from.
28
+ * @returns A `React.lazy` component that provides the initialised framework
29
+ * to its children.
14
30
  *
15
- * @param configurator - callback for configuring modules
16
31
  * @example
17
32
  * ```tsx
18
- * const config: FrameworkConfigurator = (config) => {}
33
+ * import { createFrameworkProvider } from '@equinor/fusion-framework-react';
34
+ *
19
35
  * const Portal = () => {
20
- * const Framework = createFrameworkProvider(config);
36
+ * const FrameworkProvider = createFrameworkProvider((config) => {
37
+ * config.http.configureClient('my-api', { baseUri: 'https://api.example.com' });
38
+ * });
39
+ *
21
40
  * return (
22
- * <Suspense fallback={<span>loading...</span>}>
23
- * <Framework>{children}</Framework>
24
- * </Suspense>
41
+ * <Suspense fallback={<span>Loading…</span>}>
42
+ * <FrameworkProvider>
43
+ * <App />
44
+ * </FrameworkProvider>
45
+ * </Suspense>
25
46
  * );
26
47
  * };
27
48
  * ```
@@ -1,3 +1,13 @@
1
+ /**
2
+ * Feature-flag React hooks.
3
+ *
4
+ * @remarks
5
+ * Available via the `@equinor/fusion-framework-react/feature-flag` sub-entry-point.
6
+ * Provides hooks to read, toggle, and observe feature flags at the
7
+ * framework or application level.
8
+ *
9
+ * @module
10
+ */
1
11
  export { useFeature } from './useFeature';
2
12
  export { useFeatures } from './useFeatures';
3
13
  export { useCurrentAppFeatures } from './useCurrentAppFeatures';
@@ -3,8 +3,18 @@ import { useCurrentAppModule } from '../app';
3
3
  import { useFeatures, type UseFeaturesResult } from './useFeatures';
4
4
 
5
5
  /**
6
- * Custom hook that returns the current app features and provides a function to toggle a feature.
7
- * @returns An object containing the current app features, a function to toggle a feature, and any error that occurred.
6
+ * React hook that returns feature flags registered on the current application.
7
+ *
8
+ * @returns A {@link UseFeaturesResult} containing:
9
+ * - `features` — Array of feature flags for the current app.
10
+ * - `toggleFeature(key, enable?)` — Toggles a feature flag on or off.
11
+ * - `error` — Any error from the feature-flag or app-module streams.
12
+ *
13
+ * @example
14
+ * ```ts
15
+ * const { features, toggleFeature } = useCurrentAppFeatures();
16
+ * toggleFeature('dark-mode', true);
17
+ * ```
8
18
  */
9
19
  export const useCurrentAppFeatures = (): UseFeaturesResult => {
10
20
  const { module, error: moduleError } = useCurrentAppModule<FeatureFlagModule>('featureFlag');
@@ -11,22 +11,39 @@ import { useObservableState } from '@equinor/fusion-observable/react';
11
11
 
12
12
  import { findFeature } from '@equinor/fusion-framework-module-feature-flag/selectors';
13
13
 
14
+ /**
15
+ * Return type of the {@link useFeature} hook.
16
+ *
17
+ * @template T - Value type carried by the feature flag.
18
+ */
14
19
  export interface UseFeatureResult<T> {
20
+ /** The resolved feature flag, or `undefined` while loading. */
15
21
  feature?: IFeatureFlag<T>;
22
+ /** Any error emitted by the feature-flag observable. */
16
23
  error?: unknown;
17
24
  /**
18
- * @param enable - Optional provide new enabled state of the feature flag. _Defaults to inversion of current feature flag state_
25
+ * Toggles the feature flag.
26
+ *
27
+ * @param enable - Explicit enabled state. When omitted the current state
28
+ * is inverted.
19
29
  */
20
30
  toggleFeature: (enable?: boolean) => void;
21
31
  }
22
32
 
23
33
  /**
24
- * Custom hook that retrieves a feature flag from a feature flag provider.
34
+ * React hook that retrieves and manages a single feature flag.
35
+ *
36
+ * @template T - Value type carried by the feature flag.
37
+ * @param provider - The feature-flag provider instance.
38
+ * @param key - Unique key identifying the feature flag.
39
+ * @returns A {@link UseFeatureResult} with the flag value, toggle helper,
40
+ * and any error.
25
41
  *
26
- * @template T - The type of the feature flag value.
27
- * @param {IFeatureFlagProvider} provider - The feature flag provider.
28
- * @param {string} key - The key of the feature flag.
29
- * @returns {UseFeatureResult<T>} - An object containing the feature flag value, a function to toggle the feature flag, and any error that occurred.
42
+ * @example
43
+ * ```ts
44
+ * const { feature, toggleFeature } = useFeature(provider, 'dark-mode');
45
+ * console.log(feature?.enabled);
46
+ * ```
30
47
  */
31
48
  export const useFeature = <T = unknown>(
32
49
  provider: IFeatureFlagProvider,
@@ -12,23 +12,40 @@ import type { FeatureSelectorFn } from '@equinor/fusion-framework-module-feature
12
12
 
13
13
  import { useObservableState } from '@equinor/fusion-observable/react';
14
14
 
15
+ /**
16
+ * Return type of the {@link useFeatures} hook.
17
+ */
15
18
  export interface UseFeaturesResult {
19
+ /** Array of all resolved feature flags. */
16
20
  features: IFeatureFlag[];
21
+ /** Any error emitted by the feature-flag observable. */
17
22
  error: unknown;
18
23
  /**
24
+ * Toggles a feature flag by key.
25
+ *
19
26
  * @param key - The key of the feature flag.
20
- * @param enable - Optional provide new enabled state of the feature flag. _Defaults to inversion of current feature flag state_
27
+ * @param enable - Explicit enabled state. When omitted the current state
28
+ * is inverted.
21
29
  */
22
30
  toggleFeature: (key: string, enable?: boolean) => void;
23
31
  }
24
32
 
25
33
  /**
26
- * Custom hook that provides access to the feature flags and their values.
34
+ * React hook that returns all feature flags from a provider, with optional
35
+ * filtering.
36
+ *
37
+ * @param provider - The feature-flag provider instance, or `null`/`undefined`
38
+ * when not yet available.
39
+ * @param selector - Optional predicate to filter the feature flags.
40
+ * @returns A {@link UseFeaturesResult} with the flags, a toggle helper,
41
+ * and any error.
42
+ * @throws {Error} If `toggleFeature` is called when the provider is missing.
27
43
  *
28
- * @param provider - The feature flag provider.
29
- * @param selector - Optional function to filter the feature flags.
30
- * @returns An object containing the features, any error that occurred while retrieving them, and a function to set the enabled state of a feature flag.
31
- * @throws Error if the feature flag provider is missing.
44
+ * @example
45
+ * ```ts
46
+ * const { features, toggleFeature } = useFeatures(provider);
47
+ * toggleFeature('beta', true);
48
+ * ```
32
49
  */
33
50
  export const useFeatures = (
34
51
  provider?: IFeatureFlagProvider | null,
@@ -4,12 +4,19 @@ import { useFrameworkModule } from '../useFrameworkModule';
4
4
  import { useFeature } from './useFeature';
5
5
 
6
6
  /**
7
- * Custom hook that allows accessing a framework feature based on a given feature flag key.
7
+ * React hook that retrieves a single feature flag from the **framework-level**
8
+ * feature-flag provider.
8
9
  *
9
- * @template T - The type of the feature.
10
- * @param {string} key - The feature flag key.
11
- * @returns {ReturnType<typeof useFeature<T>>} - The result of the feature hook.
12
- * @throws {Error} - If feature flagging is not enabled in the framework.
10
+ * @template T - Value type carried by the feature flag.
11
+ * @param key - Unique key identifying the feature flag.
12
+ * @returns A {@link UseFeatureResult} with the flag value, toggle helper,
13
+ * and any error.
14
+ * @throws {Error} If the `FeatureFlagModule` is not enabled in the framework.
15
+ *
16
+ * @example
17
+ * ```ts
18
+ * const { feature, toggleFeature } = useFrameworkFeature('experimental-ui');
19
+ * ```
13
20
  */
14
21
  export const useFrameworkFeature = <T>(key: string): ReturnType<typeof useFeature<T>> => {
15
22
  const provider = useFrameworkModule<FeatureFlagModule>('featureFlag');
@@ -4,10 +4,17 @@ import { useFrameworkModule } from '../useFrameworkModule';
4
4
  import { useFeatures } from './useFeatures';
5
5
 
6
6
  /**
7
- * Custom hook that provides access to framework-specific feature flags.
8
- * It returns the result of the `useFeatures` hook from the `featureFlag` module.
9
- * @returns The result of the `useFeatures` hook.
10
- * @throws Error if feature flagging is not enabled in the framework.
7
+ * React hook that returns all feature flags from the **framework-level**
8
+ * feature-flag provider.
9
+ *
10
+ * @returns A {@link UseFeaturesResult} containing all framework feature flags,
11
+ * a toggle helper, and any error.
12
+ * @throws {Error} If the `FeatureFlagModule` is not enabled in the framework.
13
+ *
14
+ * @example
15
+ * ```ts
16
+ * const { features, toggleFeature } = useFrameworkFeatures();
17
+ * ```
11
18
  */
12
19
  export const useFrameworkFeatures = (): ReturnType<typeof useFeatures> => {
13
20
  const provider = useFrameworkModule<FeatureFlagModule>('featureFlag');
@@ -1,2 +1,10 @@
1
+ /**
2
+ * Convenience hooks for common framework operations.
3
+ *
4
+ * @remarks
5
+ * Available via the `@equinor/fusion-framework-react/hooks` sub-entry-point.
6
+ *
7
+ * @module
8
+ */
1
9
  export { useCurrentUser } from './use-current-user';
2
10
  export { useHttpClient } from './use-http-client';
@@ -1,6 +1,20 @@
1
1
  import type { AccountInfo } from '@equinor/fusion-framework-module-msal';
2
2
  import { useFramework } from '../useFramework';
3
3
 
4
+ /**
5
+ * React hook that returns the currently authenticated user's account info.
6
+ *
7
+ * @returns The {@link AccountInfo} of the signed-in user, or `undefined` if
8
+ * no user is authenticated.
9
+ *
10
+ * @example
11
+ * ```tsx
12
+ * const UserGreeting = () => {
13
+ * const user = useCurrentUser();
14
+ * return <span>Hello, {user?.name ?? 'Guest'}</span>;
15
+ * };
16
+ * ```
17
+ */
4
18
  export const useCurrentUser = (): AccountInfo | undefined => {
5
19
  const framework = useFramework();
6
20
  return framework.modules.auth.account || undefined;
@@ -2,9 +2,25 @@ import { useMemo } from 'react';
2
2
  import type { Fusion } from '@equinor/fusion-framework';
3
3
  import { useFramework } from '../useFramework';
4
4
 
5
+ /** Resolved HTTP client instance returned by the framework HTTP module. */
5
6
  type HttpClient = ReturnType<Fusion['modules']['http']['createClient']>;
7
+
8
+ /** Well-known HTTP client keys pre-configured by the framework. */
6
9
  type FrameworkHttpClient = 'portal' | 'people';
7
10
 
11
+ /**
12
+ * React hook that returns a pre-configured HTTP client from the framework.
13
+ *
14
+ * @param name - Key of the HTTP client to retrieve (e.g. `'portal'` or `'people'`).
15
+ * @returns The resolved {@link HttpClient} instance.
16
+ * @throws {Error} If no client is configured for the given key.
17
+ *
18
+ * @example
19
+ * ```ts
20
+ * const client = useHttpClient('portal');
21
+ * client.fetch('/api/data').subscribe(console.log);
22
+ * ```
23
+ */
8
24
  export const useHttpClient = (name: FrameworkHttpClient): HttpClient => {
9
25
  const framework = useFramework();
10
26
 
package/src/http/index.ts CHANGED
@@ -1,3 +1,13 @@
1
+ /**
2
+ * HTTP sub-entry-point (`@equinor/fusion-framework-react/http`).
3
+ *
4
+ * @remarks
5
+ * Re-exports the framework-level {@link useHttpClient} hook as
6
+ * `useFrameworkHttpClient` together with all exports from the
7
+ * standalone HTTP React module.
8
+ *
9
+ * @module
10
+ */
1
11
  export { useHttpClient as useFrameworkHttpClient } from '../hooks/use-http-client';
2
12
 
3
13
  export * from '@equinor/fusion-framework-react-module-http';
package/src/index.tsx CHANGED
@@ -1,4 +1,12 @@
1
1
  /**
2
+ * React bindings for the Fusion Framework.
3
+ *
4
+ * @remarks
5
+ * This package provides React components, context providers, and hooks for
6
+ * initialising and consuming a Fusion Framework instance inside a React
7
+ * application tree. It is the main entry-point for portals and host
8
+ * applications that need to bootstrap the framework with React.
9
+ *
2
10
  * [[include:framework-react/README.MD]]
3
11
  * @module
4
12
  */