@equinor/fusion-framework-react 8.0.0-next.0 → 8.0.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.
Files changed (123) hide show
  1. package/CHANGELOG.md +60 -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 +12 -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 +26 -4
  11. package/dist/esm/app/useCurrentApp.js.map +1 -1
  12. package/dist/esm/app/useCurrentAppModule.js +26 -13
  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 +6 -16
  21. package/dist/esm/context.js.map +1 -1
  22. package/dist/esm/create-framework-provider.js +30 -9
  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 +16 -6
  29. package/dist/esm/feature-flag/useFeature.js.map +1 -1
  30. package/dist/esm/feature-flag/useFeatures.js +24 -6
  31. package/dist/esm/feature-flag/useFeatures.js.map +1 -1
  32. package/dist/esm/feature-flag/useFrameworkFeature.js +13 -5
  33. package/dist/esm/feature-flag/useFrameworkFeature.js.map +1 -1
  34. package/dist/esm/feature-flag/useFrameworkFeatures.js +12 -4
  35. package/dist/esm/feature-flag/useFrameworkFeatures.js.map +1 -1
  36. package/dist/esm/framework-provider.js +21 -0
  37. package/dist/esm/framework-provider.js.map +1 -0
  38. package/dist/esm/hooks/index.js +10 -2
  39. package/dist/esm/hooks/index.js.map +1 -1
  40. package/dist/esm/hooks/useCurrentUser.js +20 -0
  41. package/dist/esm/hooks/useCurrentUser.js.map +1 -0
  42. package/dist/esm/hooks/useHttpClient.js +28 -0
  43. package/dist/esm/hooks/useHttpClient.js.map +1 -0
  44. package/dist/esm/http/index.js +11 -1
  45. package/dist/esm/http/index.js.map +1 -1
  46. package/dist/esm/index.js +9 -1
  47. package/dist/esm/index.js.map +1 -1
  48. package/dist/esm/signalr/index.js +1 -31
  49. package/dist/esm/signalr/index.js.map +1 -1
  50. package/dist/esm/signalr/useSignalR.js +33 -0
  51. package/dist/esm/signalr/useSignalR.js.map +1 -0
  52. package/dist/esm/useFramework.js +18 -4
  53. package/dist/esm/useFramework.js.map +1 -1
  54. package/dist/esm/useFrameworkModule.js +16 -8
  55. package/dist/esm/useFrameworkModule.js.map +1 -1
  56. package/dist/esm/version.js +1 -1
  57. package/dist/esm/version.js.map +1 -1
  58. package/dist/tsconfig.tsbuildinfo +1 -1
  59. package/dist/types/Framework.d.ts +38 -1
  60. package/dist/types/app/index.d.ts +10 -0
  61. package/dist/types/app/useAppProvider.d.ts +12 -3
  62. package/dist/types/app/useApps.d.ts +17 -3
  63. package/dist/types/app/useCurrentApp.d.ts +25 -4
  64. package/dist/types/app/useCurrentAppModule.d.ts +13 -7
  65. package/dist/types/app/useCurrentAppModules.d.ts +14 -4
  66. package/dist/types/context/index.d.ts +10 -0
  67. package/dist/types/context/useCurrentContext.d.ts +16 -0
  68. package/dist/types/context.d.ts +1 -21
  69. package/dist/types/create-framework-provider.d.ts +29 -8
  70. package/dist/types/feature-flag/index.d.ts +10 -0
  71. package/dist/types/feature-flag/useCurrentAppFeatures.d.ts +12 -2
  72. package/dist/types/feature-flag/useFeature.d.ts +23 -6
  73. package/dist/types/feature-flag/useFeatures.d.ts +23 -6
  74. package/dist/types/feature-flag/useFrameworkFeature.d.ts +12 -5
  75. package/dist/types/feature-flag/useFrameworkFeatures.d.ts +11 -4
  76. package/dist/types/framework-provider.d.ts +19 -0
  77. package/dist/types/hooks/index.d.ts +10 -2
  78. package/dist/types/hooks/useCurrentUser.d.ts +16 -0
  79. package/dist/types/hooks/useHttpClient.d.ts +20 -0
  80. package/dist/types/http/index.d.ts +11 -1
  81. package/dist/types/index.d.ts +9 -1
  82. package/dist/types/signalr/index.d.ts +1 -24
  83. package/dist/types/signalr/useSignalR.d.ts +24 -0
  84. package/dist/types/useFramework.d.ts +16 -4
  85. package/dist/types/useFrameworkModule.d.ts +13 -6
  86. package/dist/types/version.d.ts +1 -1
  87. package/package.json +15 -14
  88. package/src/Framework.tsx +37 -0
  89. package/src/app/index.ts +10 -0
  90. package/src/app/useAppProvider.ts +12 -2
  91. package/src/app/useApps.ts +17 -3
  92. package/src/app/useCurrentApp.ts +26 -4
  93. package/src/app/useCurrentAppModule.ts +26 -14
  94. package/src/app/useCurrentAppModules.ts +14 -4
  95. package/src/context/index.ts +10 -0
  96. package/src/context/useCurrentContext.ts +16 -0
  97. package/src/context.ts +6 -17
  98. package/src/create-framework-provider.tsx +31 -10
  99. package/src/feature-flag/index.ts +10 -0
  100. package/src/feature-flag/useCurrentAppFeatures.ts +12 -2
  101. package/src/feature-flag/useFeature.ts +31 -7
  102. package/src/feature-flag/useFeatures.ts +33 -7
  103. package/src/feature-flag/useFrameworkFeature.ts +13 -5
  104. package/src/feature-flag/useFrameworkFeatures.ts +12 -4
  105. package/src/framework-provider.ts +21 -0
  106. package/src/hooks/index.ts +10 -2
  107. package/src/hooks/useCurrentUser.ts +21 -0
  108. package/src/hooks/useHttpClient.ts +36 -0
  109. package/src/http/index.ts +11 -1
  110. package/src/index.tsx +9 -1
  111. package/src/signalr/index.ts +1 -39
  112. package/src/signalr/useSignalR.ts +40 -0
  113. package/src/useFramework.ts +18 -4
  114. package/src/useFrameworkModule.ts +16 -8
  115. package/src/version.ts +1 -1
  116. package/dist/esm/hooks/use-current-user.js +0 -6
  117. package/dist/esm/hooks/use-current-user.js.map +0 -1
  118. package/dist/esm/hooks/use-http-client.js +0 -14
  119. package/dist/esm/hooks/use-http-client.js.map +0 -1
  120. package/dist/types/hooks/use-current-user.d.ts +0 -2
  121. package/dist/types/hooks/use-http-client.d.ts +0 -5
  122. package/src/hooks/use-current-user.ts +0 -7
  123. package/src/hooks/use-http-client.ts +0 -19
@@ -0,0 +1,24 @@
1
+ import { useProviderTopic } from '@equinor/fusion-framework-react-module-signalr';
2
+ /**
3
+ * hook for subscribing to a topic of a SignalR hub
4
+ *
5
+ * @example
6
+ ```ts
7
+ // config.ts
8
+ import {enableSignalR} from '@equinor/fusion-framework-react-module-signalr';
9
+ (configurator) => enableSignalR(configurator, 'notifications');
10
+
11
+ // myHook.ts
12
+ const myHook = () => {
13
+ const topic = useSignalR('notifications', 'foo');
14
+ return useObservableState(topic).next;
15
+ }
16
+ ```
17
+ *
18
+ * @see {@link [module signalr](https://equinor.github.io/fusion-framework/modules/signalr)}
19
+ *
20
+ * @param hubId identifier of connection hub (must be configured)
21
+ * @param topicId identifier of topic to connect to
22
+ * @returns Topic
23
+ */
24
+ export declare const useSignalR: <T>(hubId: string, topicId: string) => ReturnType<typeof useProviderTopic<T>>;
@@ -1,12 +1,24 @@
1
1
  import type { Fusion } from '@equinor/fusion-framework';
2
2
  import type { AnyModule } from '@equinor/fusion-framework-module';
3
3
  /**
4
+ * React hook that returns the current Fusion Framework instance from context.
5
+ *
6
+ * @remarks
7
+ * The hook first looks for a framework instance provided via
8
+ * {@link FrameworkProvider}. If none is found it falls back to the global
9
+ * `window.Fusion` object. A console warning / error is emitted when the
10
+ * framework cannot be resolved.
11
+ *
12
+ * @template TModules - Tuple of additional module types expected on the
13
+ * framework instance (used for type-narrowing only).
14
+ * @returns The active {@link Fusion} instance.
15
+ *
4
16
  * @example
5
17
  * ```ts
6
- * const useSometing = () => {
7
- * const fusion = useFramework();
8
- * return fusion.something;
9
- * }
18
+ * const useMyService = () => {
19
+ * const fusion = useFramework();
20
+ * return fusion.modules.http.createClient('my-service');
21
+ * };
10
22
  * ```
11
23
  */
12
24
  export declare const useFramework: <TModules extends Array<AnyModule> = []>() => Fusion<TModules>;
@@ -1,12 +1,19 @@
1
1
  import type { FusionModules, FusionModulesInstance } from '@equinor/fusion-framework';
2
2
  import type { AnyModule, ModuleKey, ModuleType, ModuleTypes } from '@equinor/fusion-framework-module';
3
3
  /**
4
- * Retrieves a module from the framework instance based on its name.
4
+ * React hook that retrieves a module from the Fusion Framework by name.
5
5
  *
6
- * @template TType - The type of the module to retrieve.
7
- * @template TKey - The type of the module name.
8
- * @param name - The name of the module to retrieve.
9
- * @returns The requested module from the framework instance.
10
- * @throws Error if the requested module is not included in the framework instance.
6
+ * @template TType - The expected module type (used for type-narrowing).
7
+ * @template TKey - The module key string.
8
+ * @param name - The registered name of the module to retrieve.
9
+ * @returns The resolved module instance, or `undefined` if the module is
10
+ * not registered.
11
+ *
12
+ * @example
13
+ * ```ts
14
+ * import type { HttpModule } from '@equinor/fusion-framework-module-http';
15
+ *
16
+ * const http = useFrameworkModule<HttpModule>('http');
17
+ * ```
11
18
  */
12
19
  export declare const useFrameworkModule: <TType extends AnyModule | unknown = unknown, TKey extends string = ModuleKey<ModuleTypes<FusionModules<[TType]>>>>(name: TKey) => TType extends AnyModule ? ModuleType<TType> | undefined : FusionModulesInstance[Extract<keyof FusionModulesInstance, TKey>] | undefined;
@@ -1 +1 @@
1
- export declare const version = "8.0.0-next.0";
1
+ export declare const version = "8.0.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.1",
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.11",
76
+ "@equinor/fusion-framework-react-module": "^4.0.2",
77
+ "@equinor/fusion-framework-react-module-http": "^11.0.1",
78
+ "@equinor/fusion-observable": "^9.1.1",
79
+ "@equinor/fusion-framework-module": "^6.1.1"
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": "^7.0.2",
87
+ "@equinor/fusion-framework-module-app": "^8.0.3",
88
+ "@equinor/fusion-framework-module-event": "^6.0.1",
89
+ "@equinor/fusion-framework-module-msal": "^10.0.2",
90
+ "@equinor/fusion-framework-react-module-context": "^7.0.2",
91
+ "@equinor/fusion-framework-module-feature-flag": "^2.0.2",
92
+ "@equinor/fusion-framework-react-module-signalr": "^4.0.3"
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-module-feature-flag": "^2.0.2",
99
+ "@equinor/fusion-framework-react-module-signalr": "^4.0.3"
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,11 +4,21 @@ 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;
21
+ // Fail fast when the AppModule has not been configured on the framework
12
22
  if (!provider) {
13
23
  throw Error('Current framework does not have AppModule configured');
14
24
  }
@@ -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> = [],
@@ -29,6 +50,7 @@ export const useCurrentApp = <
29
50
  error?: unknown;
30
51
  } => {
31
52
  const provider = useFramework<[AppModule]>().modules.app;
53
+ // Fail fast when the AppModule has not been configured on the framework
32
54
  if (!provider) {
33
55
  throw Error('Current framework does not have AppModule configured');
34
56
  }
@@ -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,
@@ -32,13 +38,19 @@ export const useCurrentAppModule = <
32
38
  complete: boolean;
33
39
  } => {
34
40
  const { modules, error, complete } = useCurrentAppModules();
35
- const module =
36
- modules === null
37
- ? null
38
- : modules === undefined
39
- ? undefined
40
- : // eslint-disable-next-line @typescript-eslint/no-explicit-any
41
- (modules[moduleKey as keyof typeof modules] as any);
41
+ const module = (() => {
42
+ // Preserve an explicit null (modules not applicable) distinct from undefined (not yet loaded)
43
+ if (modules === null) {
44
+ return null;
45
+ }
46
+ // Modules are still loading; propagate undefined rather than throwing
47
+ if (modules === undefined) {
48
+ return undefined;
49
+ }
50
+ // Module lookup by dynamic key can't be statically narrowed to the exact module type; cast to any.
51
+ // biome-ignore lint/suspicious/noExplicitAny: dynamic key lookup can't be statically narrowed to the exact module type
52
+ return modules[moduleKey as keyof typeof modules] as any;
53
+ })();
42
54
  return { module, error, complete };
43
55
  };
44
56
 
@@ -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,25 +1,14 @@
1
1
  import { createContext } from 'react';
2
2
  import type { Fusion } from '@equinor/fusion-framework';
3
3
 
4
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
5
- export const context = createContext<Fusion<any> | null>(null);
6
-
7
4
  /**
8
- * Component for providing framework.
5
+ * Internal React context that holds the current {@link Fusion} instance.
9
6
  *
10
7
  * @remarks
11
- * Should be created by {@link createFrameworkProvider}
8
+ * Consumers should not use this directly — prefer the {@link useFramework}
9
+ * hook or the {@link FrameworkProvider} component.
12
10
  *
13
- * @example
14
- * ```tsx
15
- * import {FrameworkProvider} from '@equinor/fusion-framework-react';
16
- * export const Component = (args: React.PropsWithChildren<{framework: Fusion}>) => {
17
- * return (
18
- * <FrameworkProvider value={args.framework}>
19
- * {args.children}
20
- * </FrameworkProvider>
21
- * );
22
- * }
23
- * ```
11
+ * @internal
24
12
  */
25
- export const FrameworkProvider = context.Provider;
13
+ // biome-ignore lint/suspicious/noExplicitAny: `Fusion<any>` widens the context to accept a Fusion instance with any concrete module set
14
+ export const context = createContext<Fusion<any> | null>(null);
@@ -3,32 +3,53 @@ import { lazy } from 'react';
3
3
  import initFusion from '@equinor/fusion-framework';
4
4
  import { FrameworkConfigurator } from '@equinor/fusion-framework';
5
5
 
6
- import { FrameworkProvider } from './context';
6
+ import { FrameworkProvider } from './framework-provider';
7
7
  import type { AnyModule, ModulesInstanceType } from '@equinor/fusion-framework-module';
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
  * ```
28
49
  */
29
50
  export const createFrameworkProvider = <
30
51
  TModules extends Array<AnyModule> = [],
31
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
52
+ // biome-ignore lint/suspicious/noExplicitAny: default must be bivariant `any`, not `unknown` \u2014 `unknown` breaks assignability when a concrete `TRef` is passed where the default-typed generic is expected
32
53
  TRef extends ModulesInstanceType<[AnyModule]> = any,
33
54
  >(
34
55
  cb: (configurator: FrameworkConfigurator<TModules>, ref?: TRef) => void | Promise<void>,
@@ -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,28 +11,52 @@ 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.
25
35
  *
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.
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.
41
+ *
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,
33
50
  key: string,
34
51
  ): UseFeatureResult<T> => {
35
- const feature$ = useMemo(() => provider.features$.pipe(findFeature<T>(key)), [provider, key]);
52
+ // Narrow the features stream down to just the one matching feature by key.
53
+ const feature$ = useMemo(
54
+ () =>
55
+ provider.features$
56
+ // Keep the observable scoped to the requested feature key.
57
+ .pipe(findFeature<T>(key)),
58
+ [provider, key],
59
+ );
36
60
  const { value: feature, error } = useObservableState(feature$ ?? EMPTY);
37
61
  const toggleFeature = useCallback(
38
62
  (enable?: boolean) => {