@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.
- package/CHANGELOG.md +48 -12
- package/README.md +164 -31
- package/dist/esm/Framework.js +32 -0
- package/dist/esm/Framework.js.map +1 -1
- package/dist/esm/app/index.js.map +1 -1
- package/dist/esm/app/useAppProvider.js +11 -2
- package/dist/esm/app/useAppProvider.js.map +1 -1
- package/dist/esm/app/useApps.js +17 -3
- package/dist/esm/app/useApps.js.map +1 -1
- package/dist/esm/app/useCurrentApp.js +25 -4
- package/dist/esm/app/useCurrentApp.js.map +1 -1
- package/dist/esm/app/useCurrentAppModule.js +13 -7
- package/dist/esm/app/useCurrentAppModule.js.map +1 -1
- package/dist/esm/app/useCurrentAppModules.js +14 -4
- package/dist/esm/app/useCurrentAppModules.js.map +1 -1
- package/dist/esm/context/index.js +10 -0
- package/dist/esm/context/index.js.map +1 -1
- package/dist/esm/context/useCurrentContext.js +16 -0
- package/dist/esm/context/useCurrentContext.js.map +1 -1
- package/dist/esm/context.js +9 -0
- package/dist/esm/context.js.map +1 -1
- package/dist/esm/create-framework-provider.js +29 -8
- package/dist/esm/create-framework-provider.js.map +1 -1
- package/dist/esm/feature-flag/index.js +10 -0
- package/dist/esm/feature-flag/index.js.map +1 -1
- package/dist/esm/feature-flag/useCurrentAppFeatures.js +12 -2
- package/dist/esm/feature-flag/useCurrentAppFeatures.js.map +1 -1
- package/dist/esm/feature-flag/useFeature.js +12 -5
- package/dist/esm/feature-flag/useFeature.js.map +1 -1
- package/dist/esm/feature-flag/useFeatures.js +14 -5
- package/dist/esm/feature-flag/useFeatures.js.map +1 -1
- package/dist/esm/feature-flag/useFrameworkFeature.js +12 -5
- package/dist/esm/feature-flag/useFrameworkFeature.js.map +1 -1
- package/dist/esm/feature-flag/useFrameworkFeatures.js +11 -4
- package/dist/esm/feature-flag/useFrameworkFeatures.js.map +1 -1
- package/dist/esm/hooks/index.js +8 -0
- package/dist/esm/hooks/index.js.map +1 -1
- package/dist/esm/hooks/use-current-user.js +14 -0
- package/dist/esm/hooks/use-current-user.js.map +1 -1
- package/dist/esm/hooks/use-http-client.js +13 -0
- package/dist/esm/hooks/use-http-client.js.map +1 -1
- package/dist/esm/http/index.js +10 -0
- package/dist/esm/http/index.js.map +1 -1
- package/dist/esm/index.js +8 -0
- package/dist/esm/index.js.map +1 -1
- package/dist/esm/useFramework.js +16 -4
- package/dist/esm/useFramework.js.map +1 -1
- package/dist/esm/useFrameworkModule.js +13 -6
- package/dist/esm/useFrameworkModule.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/Framework.d.ts +37 -0
- package/dist/types/app/index.d.ts +10 -0
- package/dist/types/app/useAppProvider.d.ts +11 -2
- package/dist/types/app/useApps.d.ts +17 -3
- package/dist/types/app/useCurrentApp.d.ts +25 -4
- package/dist/types/app/useCurrentAppModule.d.ts +13 -7
- package/dist/types/app/useCurrentAppModules.d.ts +14 -4
- package/dist/types/context/index.d.ts +10 -0
- package/dist/types/context/useCurrentContext.d.ts +16 -0
- package/dist/types/context.d.ts +0 -1
- package/dist/types/create-framework-provider.d.ts +29 -8
- package/dist/types/feature-flag/index.d.ts +10 -0
- package/dist/types/feature-flag/useCurrentAppFeatures.d.ts +12 -2
- package/dist/types/feature-flag/useFeature.d.ts +23 -6
- package/dist/types/feature-flag/useFeatures.d.ts +23 -6
- package/dist/types/feature-flag/useFrameworkFeature.d.ts +12 -5
- package/dist/types/feature-flag/useFrameworkFeatures.d.ts +11 -4
- package/dist/types/hooks/index.d.ts +8 -0
- package/dist/types/hooks/use-current-user.d.ts +14 -0
- package/dist/types/hooks/use-http-client.d.ts +15 -0
- package/dist/types/http/index.d.ts +10 -0
- package/dist/types/index.d.ts +8 -0
- package/dist/types/useFramework.d.ts +16 -4
- package/dist/types/useFrameworkModule.d.ts +13 -6
- package/dist/types/version.d.ts +1 -1
- package/package.json +15 -14
- package/src/Framework.tsx +37 -0
- package/src/app/index.ts +10 -0
- package/src/app/useAppProvider.ts +11 -2
- package/src/app/useApps.ts +17 -3
- package/src/app/useCurrentApp.ts +25 -4
- package/src/app/useCurrentAppModule.ts +13 -7
- package/src/app/useCurrentAppModules.ts +14 -4
- package/src/context/index.ts +10 -0
- package/src/context/useCurrentContext.ts +16 -0
- package/src/context.ts +9 -0
- package/src/create-framework-provider.tsx +29 -8
- package/src/feature-flag/index.ts +10 -0
- package/src/feature-flag/useCurrentAppFeatures.ts +12 -2
- package/src/feature-flag/useFeature.ts +23 -6
- package/src/feature-flag/useFeatures.ts +23 -6
- package/src/feature-flag/useFrameworkFeature.ts +12 -5
- package/src/feature-flag/useFrameworkFeatures.ts +11 -4
- package/src/hooks/index.ts +8 -0
- package/src/hooks/use-current-user.ts +14 -0
- package/src/hooks/use-http-client.ts +16 -0
- package/src/http/index.ts +10 -0
- package/src/index.tsx +8 -0
- package/src/useFramework.ts +16 -4
- package/src/useFrameworkModule.ts +13 -6
- package/src/version.ts +1 -1
|
@@ -1,7 +1,44 @@
|
|
|
1
1
|
import type { FrameworkConfigurator } from '@equinor/fusion-framework';
|
|
2
2
|
import { type PropsWithChildren, type ReactNode } from 'react';
|
|
3
3
|
import type { ModulesInstance } from '@equinor/fusion-framework-module';
|
|
4
|
+
/**
|
|
5
|
+
* Callback invoked during framework initialisation to configure modules.
|
|
6
|
+
*
|
|
7
|
+
* @param configurator - The framework configurator instance to apply settings to.
|
|
8
|
+
*/
|
|
4
9
|
type ConfigureCallback = (configurator: FrameworkConfigurator) => void;
|
|
10
|
+
/**
|
|
11
|
+
* Declarative React component that initialises a Fusion Framework instance
|
|
12
|
+
* and provides it to descendant components via context.
|
|
13
|
+
*
|
|
14
|
+
* @remarks
|
|
15
|
+
* Internally calls {@link createFrameworkProvider} and wraps the lazy-loaded
|
|
16
|
+
* provider in a `<Suspense>` boundary. This is the recommended high-level
|
|
17
|
+
* component for portal / host applications that need to bootstrap the
|
|
18
|
+
* framework inside a React tree.
|
|
19
|
+
*
|
|
20
|
+
* @param props.configure - Callback that receives a {@link FrameworkConfigurator}
|
|
21
|
+
* for registering modules and configuration.
|
|
22
|
+
* @param props.fallback - React node shown while the framework is initialising.
|
|
23
|
+
* @param props.parent - Optional parent module instance to inherit configuration from.
|
|
24
|
+
* @param props.children - Application content rendered after initialisation.
|
|
25
|
+
*
|
|
26
|
+
* @example
|
|
27
|
+
* ```tsx
|
|
28
|
+
* import { Framework } from '@equinor/fusion-framework-react';
|
|
29
|
+
*
|
|
30
|
+
* const App = () => (
|
|
31
|
+
* <Framework
|
|
32
|
+
* configure={(configurator) => {
|
|
33
|
+
* configurator.http.configureClient('my-api', { baseUri: 'https://api.example.com' });
|
|
34
|
+
* }}
|
|
35
|
+
* fallback={<span>Loading…</span>}
|
|
36
|
+
* >
|
|
37
|
+
* <MyApp />
|
|
38
|
+
* </Framework>
|
|
39
|
+
* );
|
|
40
|
+
* ```
|
|
41
|
+
*/
|
|
5
42
|
export declare const Framework: (props: PropsWithChildren<{
|
|
6
43
|
readonly configure: ConfigureCallback;
|
|
7
44
|
readonly fallback: NonNullable<ReactNode> | null;
|
|
@@ -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
|
export { useCurrentApp } from './useCurrentApp';
|
|
3
13
|
export { useCurrentAppModule } from './useCurrentAppModule';
|
|
@@ -1,8 +1,17 @@
|
|
|
1
1
|
import type { FusionModulesInstance } from '@equinor/fusion-framework';
|
|
2
2
|
import type { AppModule } from '@equinor/fusion-framework-module-app';
|
|
3
3
|
/**
|
|
4
|
-
* React
|
|
5
|
-
*
|
|
4
|
+
* React hook that returns the App module provider from the framework.
|
|
5
|
+
*
|
|
6
|
+
* @returns The app module instance (`AppModule`) for querying and managing
|
|
7
|
+
* application manifests and the currently active app.
|
|
8
|
+
* @throws {Error} If the `AppModule` is not configured in the framework.
|
|
9
|
+
*
|
|
10
|
+
* @example
|
|
11
|
+
* ```ts
|
|
12
|
+
* const provider = useAppProvider();
|
|
13
|
+
* provider.getAppManifests().subscribe(console.log);
|
|
14
|
+
* ```
|
|
6
15
|
*/
|
|
7
16
|
export declare const useAppProvider: () => FusionModulesInstance<[AppModule]>["app"];
|
|
8
17
|
export default useAppProvider;
|
|
@@ -5,9 +5,23 @@ type UseAppsArgs = {
|
|
|
5
5
|
filterByCurrentUser?: boolean;
|
|
6
6
|
};
|
|
7
7
|
/**
|
|
8
|
-
* React
|
|
9
|
-
*
|
|
10
|
-
* @
|
|
8
|
+
* React hook that retrieves available application manifests from the framework.
|
|
9
|
+
*
|
|
10
|
+
* @param args - Optional filtering options.
|
|
11
|
+
* @param args.filterByCurrentUser - When `true`, only apps accessible to the
|
|
12
|
+
* current user are returned.
|
|
13
|
+
* @returns An object containing:
|
|
14
|
+
* - `apps` — Array of {@link AppManifest} objects, or `undefined` while loading.
|
|
15
|
+
* - `isLoading` — `true` until the observable completes.
|
|
16
|
+
* - `error` — Any error emitted by the underlying observable.
|
|
17
|
+
*
|
|
18
|
+
* @example
|
|
19
|
+
* ```tsx
|
|
20
|
+
* const { apps, isLoading, error } = useApps({ filterByCurrentUser: true });
|
|
21
|
+
* if (isLoading) return <Spinner />;
|
|
22
|
+
* return <AppList apps={apps} />;
|
|
23
|
+
* ```
|
|
24
|
+
*
|
|
11
25
|
* @since 7.1.1
|
|
12
26
|
*/
|
|
13
27
|
export declare const useApps: (args?: UseAppsArgs) => {
|
|
@@ -1,12 +1,33 @@
|
|
|
1
1
|
import type { AnyModule } from '@equinor/fusion-framework-module';
|
|
2
2
|
import type { ConfigEnvironment, CurrentApp } from '@equinor/fusion-framework-module-app';
|
|
3
3
|
/**
|
|
4
|
-
*
|
|
4
|
+
* React hook that observes and returns the currently active application.
|
|
5
5
|
*
|
|
6
|
-
*
|
|
6
|
+
* @remarks
|
|
7
|
+
* Subscribes to the `current$` stream on the App module and returns the
|
|
8
|
+
* latest value together with helpers to change or clear the active app.
|
|
7
9
|
*
|
|
8
|
-
*
|
|
9
|
-
*
|
|
10
|
+
* **Warning:** The template parameters are compile-time hints only — the
|
|
11
|
+
* hook does not validate that the specified modules are actually enabled.
|
|
12
|
+
*
|
|
13
|
+
* @template TModules - Tuple of module types the current app is expected to
|
|
14
|
+
* have configured (type-hint only).
|
|
15
|
+
* @template TEnv - Expected environment configuration shape (type-hint only).
|
|
16
|
+
*
|
|
17
|
+
* @returns An object containing:
|
|
18
|
+
* - `currentApp` — The current {@link CurrentApp} instance, `null` when
|
|
19
|
+
* explicitly cleared, or `undefined` while loading.
|
|
20
|
+
* - `setCurrentApp(appKey)` — Sets the active app by its key.
|
|
21
|
+
* - `clearCurrentApp()` — Clears the currently active app.
|
|
22
|
+
* - `error` — Any error emitted by the observable.
|
|
23
|
+
*
|
|
24
|
+
* @throws {Error} If the `AppModule` is not configured in the framework.
|
|
25
|
+
*
|
|
26
|
+
* @example
|
|
27
|
+
* ```tsx
|
|
28
|
+
* const { currentApp, setCurrentApp } = useCurrentApp();
|
|
29
|
+
* return <button onClick={() => setCurrentApp('my-app')}>{currentApp?.manifest?.name}</button>;
|
|
30
|
+
* ```
|
|
10
31
|
*/
|
|
11
32
|
export declare const useCurrentApp: <TModules extends Array<AnyModule> = [], TEnv extends ConfigEnvironment = ConfigEnvironment>() => {
|
|
12
33
|
currentApp?: CurrentApp<TModules, TEnv> | null;
|
|
@@ -1,14 +1,20 @@
|
|
|
1
1
|
import type { AppModules, AppModulesInstance } from '@equinor/fusion-framework-module-app';
|
|
2
2
|
import type { ModuleKey, AnyModule, ModuleTypes, ModuleType } from '@equinor/fusion-framework-module';
|
|
3
3
|
/**
|
|
4
|
-
*
|
|
5
|
-
*
|
|
6
|
-
* @template
|
|
7
|
-
* @
|
|
8
|
-
* @
|
|
4
|
+
* React hook that retrieves a specific module from the current application.
|
|
5
|
+
*
|
|
6
|
+
* @template TType - The expected module type.
|
|
7
|
+
* @template TKey - The module key used for look-up.
|
|
8
|
+
* @param moduleKey - The key of the module to retrieve.
|
|
9
|
+
* @returns An object containing:
|
|
10
|
+
* - `module` — The resolved module instance, `null` when no app is
|
|
11
|
+
* selected, or `undefined` if the app does not enable the requested module.
|
|
12
|
+
* - `error` — Any error emitted during initialisation.
|
|
13
|
+
* - `complete` — `true` when the observable has completed.
|
|
14
|
+
*
|
|
9
15
|
* @remarks
|
|
10
|
-
*
|
|
11
|
-
*
|
|
16
|
+
* - A `null` value means no application is currently selected.
|
|
17
|
+
* - An `undefined` value means the application has not enabled the requested module.
|
|
12
18
|
*/
|
|
13
19
|
export declare const useCurrentAppModule: <TType extends AnyModule | unknown = unknown, TKey extends string = ModuleKey<ModuleTypes<AppModules<[TType]>>>>(moduleKey: TKey) => {
|
|
14
20
|
module?: (TType extends AnyModule ? ModuleType<TType> : AppModulesInstance[Extract<keyof AppModulesInstance, TKey>]) | null;
|
|
@@ -1,12 +1,22 @@
|
|
|
1
1
|
import type { AppModulesInstance } from '@equinor/fusion-framework-module-app';
|
|
2
2
|
import type { AnyModule } from '@equinor/fusion-framework-module';
|
|
3
3
|
/**
|
|
4
|
-
*
|
|
4
|
+
* React hook that observes the initialised modules of the current application.
|
|
5
5
|
*
|
|
6
|
-
*
|
|
6
|
+
* @remarks
|
|
7
|
+
* Subscribes to the `instance$` stream of the current app and returns the
|
|
8
|
+
* resolved module instances.
|
|
7
9
|
*
|
|
8
|
-
*
|
|
9
|
-
*
|
|
10
|
+
* **Warning:** The template parameter is a compile-time hint only — the
|
|
11
|
+
* hook does not validate that the specified modules are actually enabled.
|
|
12
|
+
*
|
|
13
|
+
* @template TModules - Tuple of module types expected on the current app
|
|
14
|
+
* (type-hint only).
|
|
15
|
+
* @returns An object containing:
|
|
16
|
+
* - `modules` — The initialised {@link AppModulesInstance}, `null` when no
|
|
17
|
+
* app is selected, or `undefined` while loading.
|
|
18
|
+
* - `error` — Any error emitted during initialisation.
|
|
19
|
+
* - `complete` — `true` when the observable has completed.
|
|
10
20
|
*/
|
|
11
21
|
export declare const useCurrentAppModules: <TModules extends Array<AnyModule> = []>() => {
|
|
12
22
|
modules?: AppModulesInstance<TModules> | null;
|
|
@@ -1,2 +1,12 @@
|
|
|
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
|
export { useCurrentContext } from './useCurrentContext';
|
|
@@ -1,3 +1,19 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* React hook that returns the currently selected Fusion context.
|
|
3
|
+
*
|
|
4
|
+
* @remarks
|
|
5
|
+
* This is a convenience wrapper that resolves the context module from the
|
|
6
|
+
* framework instance and delegates to the underlying
|
|
7
|
+
* `useCurrentContext` hook from `@equinor/fusion-framework-react-module-context`.
|
|
8
|
+
*
|
|
9
|
+
* @returns The current context state as defined by the context module.
|
|
10
|
+
*
|
|
11
|
+
* @example
|
|
12
|
+
* ```ts
|
|
13
|
+
* const { currentContext } = useCurrentContext();
|
|
14
|
+
* console.log(currentContext?.id);
|
|
15
|
+
* ```
|
|
16
|
+
*/
|
|
1
17
|
export declare const useCurrentContext: () => {
|
|
2
18
|
currentContext: import("@equinor/fusion-framework-module-context").ContextItem | null | undefined;
|
|
3
19
|
setCurrentContext: (entry?: import("@equinor/fusion-framework-module-context").ContextItem | string | null) => void | Promise<import("@equinor/fusion-framework-module-context").ContextItem<Record<string, unknown>> | null>;
|
package/dist/types/context.d.ts
CHANGED
|
@@ -2,20 +2,41 @@ import type React from 'react';
|
|
|
2
2
|
import { FrameworkConfigurator } from '@equinor/fusion-framework';
|
|
3
3
|
import type { AnyModule, ModulesInstanceType } from '@equinor/fusion-framework-module';
|
|
4
4
|
/**
|
|
5
|
-
*
|
|
5
|
+
* Creates a lazy-loaded React component that initialises a Fusion Framework
|
|
6
|
+
* instance and exposes it via context providers.
|
|
6
7
|
*
|
|
7
|
-
*
|
|
8
|
+
* @remarks
|
|
9
|
+
* This is the low-level factory used by the {@link Framework} component.
|
|
10
|
+
* Call it when you need fine-grained control over memoisation or when you
|
|
11
|
+
* want to embed the provider in a custom `<Suspense>` boundary.
|
|
12
|
+
*
|
|
13
|
+
* The returned component is created with `React.lazy`, so it **must** be
|
|
14
|
+
* rendered inside a `<Suspense>` boundary.
|
|
15
|
+
*
|
|
16
|
+
* @template TModules - Tuple of additional module types to register.
|
|
17
|
+
* @template TRef - Type of the optional parent module-instance reference.
|
|
18
|
+
*
|
|
19
|
+
* @param cb - Callback that receives a {@link FrameworkConfigurator} (and an
|
|
20
|
+
* optional parent ref) for registering modules and configuration.
|
|
21
|
+
* @param ref - Optional parent module instance to inherit configuration from.
|
|
22
|
+
* @returns A `React.lazy` component that provides the initialised framework
|
|
23
|
+
* to its children.
|
|
8
24
|
*
|
|
9
|
-
* @param configurator - callback for configuring modules
|
|
10
25
|
* @example
|
|
11
26
|
* ```tsx
|
|
12
|
-
*
|
|
27
|
+
* import { createFrameworkProvider } from '@equinor/fusion-framework-react';
|
|
28
|
+
*
|
|
13
29
|
* const Portal = () => {
|
|
14
|
-
* const
|
|
30
|
+
* const FrameworkProvider = createFrameworkProvider((config) => {
|
|
31
|
+
* config.http.configureClient('my-api', { baseUri: 'https://api.example.com' });
|
|
32
|
+
* });
|
|
33
|
+
*
|
|
15
34
|
* return (
|
|
16
|
-
*
|
|
17
|
-
*
|
|
18
|
-
*
|
|
35
|
+
* <Suspense fallback={<span>Loading…</span>}>
|
|
36
|
+
* <FrameworkProvider>
|
|
37
|
+
* <App />
|
|
38
|
+
* </FrameworkProvider>
|
|
39
|
+
* </Suspense>
|
|
19
40
|
* );
|
|
20
41
|
* };
|
|
21
42
|
* ```
|
|
@@ -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';
|
|
@@ -1,6 +1,16 @@
|
|
|
1
1
|
import { type UseFeaturesResult } from './useFeatures';
|
|
2
2
|
/**
|
|
3
|
-
*
|
|
4
|
-
*
|
|
3
|
+
* React hook that returns feature flags registered on the current application.
|
|
4
|
+
*
|
|
5
|
+
* @returns A {@link UseFeaturesResult} containing:
|
|
6
|
+
* - `features` — Array of feature flags for the current app.
|
|
7
|
+
* - `toggleFeature(key, enable?)` — Toggles a feature flag on or off.
|
|
8
|
+
* - `error` — Any error from the feature-flag or app-module streams.
|
|
9
|
+
*
|
|
10
|
+
* @example
|
|
11
|
+
* ```ts
|
|
12
|
+
* const { features, toggleFeature } = useCurrentAppFeatures();
|
|
13
|
+
* toggleFeature('dark-mode', true);
|
|
14
|
+
* ```
|
|
5
15
|
*/
|
|
6
16
|
export declare const useCurrentAppFeatures: () => UseFeaturesResult;
|
|
@@ -1,19 +1,36 @@
|
|
|
1
1
|
import type { IFeatureFlag, IFeatureFlagProvider } from '@equinor/fusion-framework-module-feature-flag';
|
|
2
|
+
/**
|
|
3
|
+
* Return type of the {@link useFeature} hook.
|
|
4
|
+
*
|
|
5
|
+
* @template T - Value type carried by the feature flag.
|
|
6
|
+
*/
|
|
2
7
|
export interface UseFeatureResult<T> {
|
|
8
|
+
/** The resolved feature flag, or `undefined` while loading. */
|
|
3
9
|
feature?: IFeatureFlag<T>;
|
|
10
|
+
/** Any error emitted by the feature-flag observable. */
|
|
4
11
|
error?: unknown;
|
|
5
12
|
/**
|
|
6
|
-
*
|
|
13
|
+
* Toggles the feature flag.
|
|
14
|
+
*
|
|
15
|
+
* @param enable - Explicit enabled state. When omitted the current state
|
|
16
|
+
* is inverted.
|
|
7
17
|
*/
|
|
8
18
|
toggleFeature: (enable?: boolean) => void;
|
|
9
19
|
}
|
|
10
20
|
/**
|
|
11
|
-
*
|
|
21
|
+
* React hook that retrieves and manages a single feature flag.
|
|
22
|
+
*
|
|
23
|
+
* @template T - Value type carried by the feature flag.
|
|
24
|
+
* @param provider - The feature-flag provider instance.
|
|
25
|
+
* @param key - Unique key identifying the feature flag.
|
|
26
|
+
* @returns A {@link UseFeatureResult} with the flag value, toggle helper,
|
|
27
|
+
* and any error.
|
|
12
28
|
*
|
|
13
|
-
* @
|
|
14
|
-
*
|
|
15
|
-
*
|
|
16
|
-
*
|
|
29
|
+
* @example
|
|
30
|
+
* ```ts
|
|
31
|
+
* const { feature, toggleFeature } = useFeature(provider, 'dark-mode');
|
|
32
|
+
* console.log(feature?.enabled);
|
|
33
|
+
* ```
|
|
17
34
|
*/
|
|
18
35
|
export declare const useFeature: <T = unknown>(provider: IFeatureFlagProvider, key: string) => UseFeatureResult<T>;
|
|
19
36
|
export default useFeature;
|
|
@@ -1,21 +1,38 @@
|
|
|
1
1
|
import type { IFeatureFlagProvider, IFeatureFlag } from '@equinor/fusion-framework-module-feature-flag';
|
|
2
2
|
import type { FeatureSelectorFn } from '@equinor/fusion-framework-module-feature-flag/selectors';
|
|
3
|
+
/**
|
|
4
|
+
* Return type of the {@link useFeatures} hook.
|
|
5
|
+
*/
|
|
3
6
|
export interface UseFeaturesResult {
|
|
7
|
+
/** Array of all resolved feature flags. */
|
|
4
8
|
features: IFeatureFlag[];
|
|
9
|
+
/** Any error emitted by the feature-flag observable. */
|
|
5
10
|
error: unknown;
|
|
6
11
|
/**
|
|
12
|
+
* Toggles a feature flag by key.
|
|
13
|
+
*
|
|
7
14
|
* @param key - The key of the feature flag.
|
|
8
|
-
* @param enable -
|
|
15
|
+
* @param enable - Explicit enabled state. When omitted the current state
|
|
16
|
+
* is inverted.
|
|
9
17
|
*/
|
|
10
18
|
toggleFeature: (key: string, enable?: boolean) => void;
|
|
11
19
|
}
|
|
12
20
|
/**
|
|
13
|
-
*
|
|
21
|
+
* React hook that returns all feature flags from a provider, with optional
|
|
22
|
+
* filtering.
|
|
23
|
+
*
|
|
24
|
+
* @param provider - The feature-flag provider instance, or `null`/`undefined`
|
|
25
|
+
* when not yet available.
|
|
26
|
+
* @param selector - Optional predicate to filter the feature flags.
|
|
27
|
+
* @returns A {@link UseFeaturesResult} with the flags, a toggle helper,
|
|
28
|
+
* and any error.
|
|
29
|
+
* @throws {Error} If `toggleFeature` is called when the provider is missing.
|
|
14
30
|
*
|
|
15
|
-
* @
|
|
16
|
-
*
|
|
17
|
-
*
|
|
18
|
-
*
|
|
31
|
+
* @example
|
|
32
|
+
* ```ts
|
|
33
|
+
* const { features, toggleFeature } = useFeatures(provider);
|
|
34
|
+
* toggleFeature('beta', true);
|
|
35
|
+
* ```
|
|
19
36
|
*/
|
|
20
37
|
export declare const useFeatures: (provider?: IFeatureFlagProvider | null, selector?: FeatureSelectorFn) => UseFeaturesResult;
|
|
21
38
|
export default useFeatures;
|
|
@@ -1,11 +1,18 @@
|
|
|
1
1
|
import { useFeature } from './useFeature';
|
|
2
2
|
/**
|
|
3
|
-
*
|
|
3
|
+
* React hook that retrieves a single feature flag from the **framework-level**
|
|
4
|
+
* feature-flag provider.
|
|
4
5
|
*
|
|
5
|
-
* @template T -
|
|
6
|
-
* @param
|
|
7
|
-
* @returns {
|
|
8
|
-
*
|
|
6
|
+
* @template T - Value type carried by the feature flag.
|
|
7
|
+
* @param key - Unique key identifying the feature flag.
|
|
8
|
+
* @returns A {@link UseFeatureResult} with the flag value, toggle helper,
|
|
9
|
+
* and any error.
|
|
10
|
+
* @throws {Error} If the `FeatureFlagModule` is not enabled in the framework.
|
|
11
|
+
*
|
|
12
|
+
* @example
|
|
13
|
+
* ```ts
|
|
14
|
+
* const { feature, toggleFeature } = useFrameworkFeature('experimental-ui');
|
|
15
|
+
* ```
|
|
9
16
|
*/
|
|
10
17
|
export declare const useFrameworkFeature: <T>(key: string) => ReturnType<typeof useFeature<T>>;
|
|
11
18
|
export default useFrameworkFeature;
|
|
@@ -1,9 +1,16 @@
|
|
|
1
1
|
import { useFeatures } from './useFeatures';
|
|
2
2
|
/**
|
|
3
|
-
*
|
|
4
|
-
*
|
|
5
|
-
*
|
|
6
|
-
* @
|
|
3
|
+
* React hook that returns all feature flags from the **framework-level**
|
|
4
|
+
* feature-flag provider.
|
|
5
|
+
*
|
|
6
|
+
* @returns A {@link UseFeaturesResult} containing all framework feature flags,
|
|
7
|
+
* a toggle helper, and any error.
|
|
8
|
+
* @throws {Error} If the `FeatureFlagModule` is not enabled in the framework.
|
|
9
|
+
*
|
|
10
|
+
* @example
|
|
11
|
+
* ```ts
|
|
12
|
+
* const { features, toggleFeature } = useFrameworkFeatures();
|
|
13
|
+
* ```
|
|
7
14
|
*/
|
|
8
15
|
export declare const useFrameworkFeatures: () => ReturnType<typeof useFeatures>;
|
|
9
16
|
export default useFrameworkFeatures;
|
|
@@ -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,2 +1,16 @@
|
|
|
1
1
|
import type { AccountInfo } from '@equinor/fusion-framework-module-msal';
|
|
2
|
+
/**
|
|
3
|
+
* React hook that returns the currently authenticated user's account info.
|
|
4
|
+
*
|
|
5
|
+
* @returns The {@link AccountInfo} of the signed-in user, or `undefined` if
|
|
6
|
+
* no user is authenticated.
|
|
7
|
+
*
|
|
8
|
+
* @example
|
|
9
|
+
* ```tsx
|
|
10
|
+
* const UserGreeting = () => {
|
|
11
|
+
* const user = useCurrentUser();
|
|
12
|
+
* return <span>Hello, {user?.name ?? 'Guest'}</span>;
|
|
13
|
+
* };
|
|
14
|
+
* ```
|
|
15
|
+
*/
|
|
2
16
|
export declare const useCurrentUser: () => AccountInfo | undefined;
|
|
@@ -1,5 +1,20 @@
|
|
|
1
1
|
import type { Fusion } from '@equinor/fusion-framework';
|
|
2
|
+
/** Resolved HTTP client instance returned by the framework HTTP module. */
|
|
2
3
|
type HttpClient = ReturnType<Fusion['modules']['http']['createClient']>;
|
|
4
|
+
/** Well-known HTTP client keys pre-configured by the framework. */
|
|
3
5
|
type FrameworkHttpClient = 'portal' | 'people';
|
|
6
|
+
/**
|
|
7
|
+
* React hook that returns a pre-configured HTTP client from the framework.
|
|
8
|
+
*
|
|
9
|
+
* @param name - Key of the HTTP client to retrieve (e.g. `'portal'` or `'people'`).
|
|
10
|
+
* @returns The resolved {@link HttpClient} instance.
|
|
11
|
+
* @throws {Error} If no client is configured for the given key.
|
|
12
|
+
*
|
|
13
|
+
* @example
|
|
14
|
+
* ```ts
|
|
15
|
+
* const client = useHttpClient('portal');
|
|
16
|
+
* client.fetch('/api/data').subscribe(console.log);
|
|
17
|
+
* ```
|
|
18
|
+
*/
|
|
4
19
|
export declare const useHttpClient: (name: FrameworkHttpClient) => HttpClient;
|
|
5
20
|
export {};
|
|
@@ -1,2 +1,12 @@
|
|
|
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
|
export * from '@equinor/fusion-framework-react-module-http';
|
package/dist/types/index.d.ts
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
|
*/
|
|
@@ -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
|
|
7
|
-
*
|
|
8
|
-
*
|
|
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
|
-
*
|
|
4
|
+
* React hook that retrieves a module from the Fusion Framework by name.
|
|
5
5
|
*
|
|
6
|
-
* @template TType - The
|
|
7
|
-
* @template TKey - The
|
|
8
|
-
* @param name - The name of the module to retrieve.
|
|
9
|
-
* @returns The
|
|
10
|
-
*
|
|
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;
|
package/dist/types/version.d.ts
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export declare const version = "8.0.0
|
|
1
|
+
export declare const version = "8.0.0";
|