@equinor/fusion-framework-app 10.4.9 → 11.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.
@@ -3,41 +3,92 @@ import { type AnyModule, type IModulesConfigurator, ModulesConfigurator } from '
3
3
  import { configureHttpClient, configureHttp, type HttpClientOptions } from '@equinor/fusion-framework-module-http';
4
4
  import type { AppEnv, AppModules } from './types';
5
5
  /**
6
- * Configurator for configuring application modules
6
+ * Contract for configuring Fusion application modules.
7
7
  *
8
- * @template TModules Addition modules
9
- * @template TRef usually undefined, optional references
8
+ * `IAppConfigurator` extends the base module configurator with application-specific
9
+ * methods for setting up HTTP clients and integrating with Fusion service discovery.
10
+ * Use this interface when typing configuration callbacks that receive the configurator.
11
+ *
12
+ * @template TModules - Additional application-specific modules to register beyond the defaults.
13
+ * @template TRef - The resolved Fusion modules instance used as a reference during initialization.
14
+ *
15
+ * @example
16
+ * ```ts
17
+ * import type { IAppConfigurator } from '@equinor/fusion-framework-app';
18
+ *
19
+ * const configure = (configurator: IAppConfigurator) => {
20
+ * configurator.configureHttpClient('myApi', {
21
+ * baseUri: 'https://api.example.com',
22
+ * defaultScopes: ['api://client-id/.default'],
23
+ * });
24
+ * };
25
+ * ```
10
26
  */
11
27
  export interface IAppConfigurator<TModules extends Array<AnyModule> | unknown = unknown, TRef extends FusionModulesInstance = FusionModulesInstance> extends IModulesConfigurator<AppModules<TModules>, TRef> {
12
28
  /**
13
- * [optional]
14
- * enable/configure the http module
29
+ * Configure the HTTP module with custom settings.
30
+ *
31
+ * Delegates to the framework `configureHttp` helper. Use this when you need
32
+ * low-level control over the HTTP module configuration. For most applications,
33
+ * prefer {@link IAppConfigurator.configureHttpClient | configureHttpClient} instead.
34
+ *
35
+ * @param args - Arguments forwarded to the framework `configureHttp` function.
15
36
  */
16
37
  configureHttp(...args: Parameters<typeof configureHttp>): void;
17
38
  /**
18
- * [optional]
19
- * Configure a named http client.
20
- * @example
21
- * ```ts
22
- configurator.configureHttpClient(
23
- 'myClient',
24
- {
25
- baseUri: 'https://foo.bar',
26
- defaultScopes: ['client-id/.default']
27
- }
28
- );
29
- * ```
30
- */
39
+ * Register a named HTTP client with explicit base URI and authentication scopes.
40
+ *
41
+ * Use this method when the application needs to call a specific API endpoint
42
+ * that is not provided through Fusion service discovery.
43
+ *
44
+ * @param args - Arguments forwarded to the framework `configureHttpClient` function.
45
+ *
46
+ * @example
47
+ * ```ts
48
+ * configurator.configureHttpClient('myClient', {
49
+ * baseUri: 'https://foo.bar',
50
+ * defaultScopes: ['api://client-id/.default'],
51
+ * });
52
+ * ```
53
+ */
31
54
  configureHttpClient(...args: Parameters<typeof configureHttpClient>): void;
32
55
  /**
33
- * [optional]
56
+ * Register a named HTTP client resolved through Fusion service discovery.
34
57
  *
35
- * configure a http client which is resolved by service discovery
58
+ * The `serviceName` is looked up in the portal’s service-discovery registry at
59
+ * initialization time. Base URI and default scopes are resolved automatically.
60
+ * Use this instead of {@link IAppConfigurator.configureHttpClient | configureHttpClient}
61
+ * when the service is registered with the Fusion portal.
36
62
  *
37
- * @param serviceName - name of the service to use
63
+ * @param serviceName - Registered name of the service in Fusion service discovery.
64
+ * @param options - Optional HTTP client overrides (headers, interceptors, etc.).
65
+ * `baseUri` and `defaultScopes` are excluded because they are
66
+ * resolved from service discovery.
38
67
  */
39
68
  useFrameworkServiceClient(serviceName: string, options?: Omit<HttpClientOptions<any>, 'baseUri' | 'defaultScopes'>): void;
40
69
  }
70
+ /**
71
+ * Configurator that bootstraps default Fusion application modules and provides
72
+ * helper methods for HTTP client and service-discovery setup.
73
+ *
74
+ * `AppConfigurator` is created internally by {@link configureModules}. It registers
75
+ * the `event`, `http`, and `msal` (auth) modules by default and reads any HTTP
76
+ * endpoints declared in the application’s environment config.
77
+ *
78
+ * @template TModules - Additional application-specific modules beyond the defaults.
79
+ * @template TRef - The resolved Fusion modules instance used as an initialization reference.
80
+ * @template TEnv - The application environment descriptor (manifest, config, basename).
81
+ *
82
+ * @example
83
+ * ```ts
84
+ * // Typically used indirectly via configureModules:
85
+ * import { configureModules } from '@equinor/fusion-framework-app';
86
+ *
87
+ * const initialize = configureModules((configurator) => {
88
+ * configurator.useFrameworkServiceClient('my-service');
89
+ * });
90
+ * ```
91
+ */
41
92
  export declare class AppConfigurator<TModules extends Array<AnyModule> | unknown = unknown, TRef extends FusionModulesInstance = FusionModulesInstance, TEnv extends AppEnv = AppEnv> extends ModulesConfigurator<AppModules<TModules>, TRef> implements IAppConfigurator<TModules, TRef> {
42
93
  readonly env: TEnv;
43
94
  /**
@@ -45,26 +96,49 @@ export declare class AppConfigurator<TModules extends Array<AnyModule> | unknown
45
96
  * the name is preserved through compilation and minification.
46
97
  */
47
98
  static readonly className: string;
99
+ /**
100
+ * Create an application configurator with default modules and environment.
101
+ *
102
+ * Registers the `event`, `http`, and `msal` modules and pre-configures any
103
+ * HTTP clients declared in `env.config.endpoints`.
104
+ *
105
+ * @param env - The application environment containing manifest, config, and optional basename.
106
+ */
48
107
  constructor(env: TEnv);
49
108
  /**
50
- * Reads app config's endpoints and configure the endpoints as httpClients
109
+ * Read HTTP endpoint definitions from the application config and register each
110
+ * one as a named HTTP client.
111
+ *
112
+ * Iterates over `env.config.endpoints` and calls
113
+ * {@link IAppConfigurator.configureHttpClient | configureHttpClient} for each entry.
51
114
  */
52
115
  protected _configureHttpClientsFromAppConfig(): void;
116
+ /** {@inheritDoc IAppConfigurator.configureHttp} */
53
117
  configureHttp(...args: Parameters<typeof configureHttp>): void;
118
+ /** {@inheritDoc IAppConfigurator.configureHttpClient} */
54
119
  configureHttpClient(...args: Parameters<typeof configureHttpClient>): void;
55
120
  /**
56
- * Configures a http client for the service `serviceName`.
57
- * The serviceName is looked up in ServiceDiscovery.
58
- * User can override url and scopes with session values.
59
- * App can override url and scopes with app config.
121
+ * Register a named HTTP client whose base URI and scopes are resolved via
122
+ * Fusion service discovery.
123
+ *
124
+ * Resolution priority (highest wins):
125
+ * 1. Session overrides (user-specific URL / scopes)
126
+ * 2. Application config (`env.config.endpoints`)
127
+ * 3. Service-discovery registry
128
+ *
129
+ * If a client with the same `serviceName` is already registered (e.g. from
130
+ * app config) and the service has **not** been overridden at session level,
131
+ * a warning is logged and the existing configuration is kept.
60
132
  *
61
- * Priority:
62
- * 1. Session overrides
63
- * 2. AppConfig
64
- * 3. ServiceDiscovery
133
+ * @param serviceName - Registered name of the service in Fusion service discovery.
134
+ * @param options - Optional HTTP client overrides. `baseUri` and `defaultScopes`
135
+ * are excluded because they come from service discovery.
136
+ * @throws {Error} When the service cannot be resolved from service discovery.
65
137
  *
66
- * @see modules/service-discovery/src/client.ts
67
- * @see configureHttpClientsFromAppConfig()
138
+ * @example
139
+ * ```ts
140
+ * configurator.useFrameworkServiceClient('my-backend-service');
141
+ * ```
68
142
  */
69
143
  useFrameworkServiceClient(serviceName: string, options?: Omit<HttpClientOptions<any>, 'baseUri' | 'defaultScopes'>): void;
70
144
  }
@@ -2,23 +2,37 @@ import type { Fusion } from '@equinor/fusion-framework';
2
2
  import type { AnyModule } from '@equinor/fusion-framework-module';
3
3
  import type { AppModulesInstance, AppModuleInitiator, AppEnv } from './types';
4
4
  /**
5
+ * Create an application module initializer for a Fusion application.
5
6
  *
6
- * Creates a callback for initializing configuration of application modules
7
+ * `configureModules` is the primary entry point for setting up an application’s
8
+ * module pipeline. It returns an async function that, when called with the Fusion
9
+ * instance and the application environment, will:
10
+ *
11
+ * 1. Create an {@link AppConfigurator} with the provided environment.
12
+ * 2. Wire up telemetry scoped to the application.
13
+ * 3. Invoke the optional user-supplied configuration callback.
14
+ * 4. Initialize all registered modules and dispatch an `onAppModulesLoaded` event.
15
+ *
16
+ * @template TModules - Additional application-specific modules to register.
17
+ * @template TRef - The Fusion instance type, used as a configuration reference.
18
+ * @template TEnv - The application environment descriptor (manifest, config, basename).
19
+ *
20
+ * @param cb - Optional configuration callback invoked before modules are initialized.
21
+ * Use this to register HTTP clients, enable bookmarks, or add custom modules.
22
+ * @returns An async initializer function that accepts `{ fusion, env }` and resolves
23
+ * with the fully initialized application module instance.
7
24
  *
8
25
  * @example
9
- ```ts
10
- const initialize = configureModules((configurator, args) => {
11
- configurator.configure(someModule);
12
- });
13
- await initialize({ fusion, { manifest, config }});
14
- ```
15
- * @template TModules Addition modules
16
- * @template TRef usually undefined, optional references
17
- * @template TEnv environment object for configuring modules
26
+ * ```ts
27
+ * import { configureModules } from '@equinor/fusion-framework-app';
18
28
  *
19
- * @param cb configuration callback
29
+ * const initialize = configureModules((configurator, { fusion, env }) => {
30
+ * configurator.useFrameworkServiceClient('my-service');
31
+ * });
20
32
  *
21
- * @returns initialize function, executes configurator
33
+ * // Later, during app bootstrap:
34
+ * const modules = await initialize({ fusion, env });
35
+ * ```
22
36
  */
23
37
  export declare const configureModules: <TModules extends Array<AnyModule> | never, TRef extends Fusion = Fusion, TEnv extends AppEnv = AppEnv>(cb?: AppModuleInitiator<TModules, TRef, TEnv>) => ((args: {
24
38
  fusion: TRef;
@@ -1,12 +1,32 @@
1
1
  import type { IAppConfigurator } from './AppConfigurator';
2
2
  /**
3
- * When enabling bookmarks for applications, we will for now only provide the portals bookmark provider.
3
+ * Enable the bookmark module for a Fusion application.
4
4
  *
5
- * This function will add the portals bookmark provider to the applications modules.
6
- * When adding a payload generator to the bookmark provider, we will intercept the teardown function and add it to a cleanup set.
5
+ * Adds bookmark support by wiring the portal’s bookmark provider into the
6
+ * application’s module set. Payload generators registered by the application
7
+ * are automatically cleaned up when the module is disposed, preventing memory
8
+ * leaks across application load/unload cycles.
9
+ *
10
+ * Import this function from `@equinor/fusion-framework-app/enable-bookmark` or, for
11
+ * React apps, from `@equinor/fusion-framework-react-app/bookmark`.
7
12
  *
8
13
  * @remarks
9
- * The cleanup function will be called when the module is disposed.
10
- * There are no guarantees that the dispose function will be called, incase of weird behavior.
14
+ * - The portal must expose a bookmark provider on `ref.bookmark`; if it is
15
+ * missing, an error is logged and the module initializes as a no-op.
16
+ * - The `@equinor/fusion-framework-module-bookmark` package must be installed,
17
+ * but do **not** call its `enableBookmark` directly in app code — use this
18
+ * app-level enabler instead.
19
+ *
20
+ * @param config - The application configurator to register the bookmark module on.
21
+ *
22
+ * @example
23
+ * ```ts
24
+ * import { configureModules } from '@equinor/fusion-framework-app';
25
+ * import { enableBookmark } from '@equinor/fusion-framework-app/enable-bookmark';
26
+ *
27
+ * const initialize = configureModules((configurator) => {
28
+ * enableBookmark(configurator);
29
+ * });
30
+ * ```
11
31
  */
12
32
  export declare const enableBookmark: (config: IAppConfigurator) => void;
@@ -1,4 +1,24 @@
1
+ /**
2
+ * @packageDocumentation
3
+ *
4
+ * `@equinor/fusion-framework-app` provides the configuration and initialization
5
+ * layer for Fusion applications. Use this package to set up application modules,
6
+ * configure HTTP clients, enable bookmarks, and integrate with telemetry and
7
+ * service discovery.
8
+ *
9
+ * The main entry points are:
10
+ *
11
+ * - {@link configureModules} — factory that creates an application initializer
12
+ * - {@link AppConfigurator} / {@link IAppConfigurator} — configurator for registering modules and HTTP clients
13
+ * - Type aliases such as {@link AppModuleInitiator}, {@link AppEnv}, and {@link AppRenderFn}
14
+ *
15
+ * Bookmark support is available via the `@equinor/fusion-framework-app/enable-bookmark`
16
+ * sub-path export.
17
+ */
1
18
  export { AppConfigurator, IAppConfigurator } from './AppConfigurator';
2
19
  export * from './types';
3
20
  export { configureModules, default } from './configure-modules';
21
+ /**
22
+ * @deprecated Use {@link configureModules} instead. This alias will be removed in a future major version.
23
+ */
4
24
  export { configureModules as initAppModules } from './configure-modules';
@@ -3,58 +3,110 @@ import type { AnyModule } from '@equinor/fusion-framework-module';
3
3
  import type { AppConfig, AppManifest, AppModulesInstance, ComponentRenderArgs } from '@equinor/fusion-framework-module-app';
4
4
  import type { IAppConfigurator } from './AppConfigurator';
5
5
  import type { ConfigEnvironment } from '@equinor/fusion-framework-module-app';
6
+ /**
7
+ * Re-exported application module types from `@equinor/fusion-framework-module-app`.
8
+ *
9
+ * - `AppModules` — union of default application modules
10
+ * - `AppManifest` — application manifest metadata (app key, version, etc.)
11
+ * - `AppConfig` — environment-specific application configuration
12
+ * - `AppModulesInstance` — resolved module instances after initialization
13
+ */
6
14
  export type { AppModules, AppManifest, AppConfig, AppModulesInstance, } from '@equinor/fusion-framework-module-app';
7
15
  /**
8
- * Application environment args
9
- * Arguments provided when initializing/configuring application modules
16
+ * Environment descriptor passed to the application during module initialization.
10
17
  *
11
- * @template TConfig config value type
12
- * @template TProps [__not in use__] properties for application component
18
+ * Contains the application manifest, optional config (with endpoint definitions),
19
+ * an optional base path for routing, and optional component props.
20
+ *
21
+ * @template TConfig - Shape of the environment-specific configuration object.
22
+ * @template TProps - Additional properties forwarded to the application component (currently unused).
13
23
  */
14
24
  export type AppEnv<TConfig extends ConfigEnvironment = ConfigEnvironment, TProps = unknown> = {
15
- /** base routing path of the application */
25
+ /** Base routing path of the application (e.g. `/apps/my-app`). */
16
26
  basename?: string;
27
+ /** Application manifest describing the app key, version, and build metadata. */
17
28
  manifest: AppManifest;
29
+ /** Environment-specific configuration with optional endpoint definitions. */
18
30
  config?: AppConfig<TConfig>;
31
+ /** Optional properties forwarded to the application component. */
19
32
  props?: TProps;
20
33
  };
21
34
  /**
22
- * Blueprint for initializing application modules
35
+ * Configuration callback for setting up application modules.
36
+ *
37
+ * This is the function signature accepted by {@link configureModules}. Implement
38
+ * this callback to register HTTP clients, enable bookmarks, and add custom modules
39
+ * to the application’s module pipeline.
40
+ *
41
+ * @template TModules - Additional modules registered by the application.
42
+ * @template TRef - The Fusion instance type used as a configuration reference.
43
+ * @template TEnv - The application environment descriptor.
44
+ *
45
+ * @param configurator - The application configurator with HTTP and module helpers.
46
+ * @param args - Object containing the Fusion instance and the application environment.
47
+ * @returns `void` or a `Promise<void>` for async configuration steps.
48
+ *
49
+ * @example
50
+ * ```ts
51
+ * import type { AppModuleInitiator } from '@equinor/fusion-framework-app';
23
52
  *
24
- * @template TModules Addition modules
25
- * @template TRef usually undefined, optional references
26
- * @template TEnv environment object for configuring modules
53
+ * const configure: AppModuleInitiator = (configurator, { fusion, env }) => {
54
+ * configurator.useFrameworkServiceClient('portal-api');
55
+ * };
56
+ * ```
27
57
  */
28
58
  export type AppModuleInitiator<TModules extends Array<AnyModule> | unknown = unknown, TRef extends Fusion = Fusion, TEnv = AppEnv> = (configurator: IAppConfigurator<TModules, TRef['modules']>, args: {
29
59
  fusion: TRef;
30
60
  env: TEnv;
31
61
  }) => void | Promise<void>;
32
62
  /**
33
- * Blueprint for creating application initialization
63
+ * Factory type that wraps {@link AppModuleInitiator} into a complete initializer.
64
+ *
65
+ * Accepts a configuration callback and returns an async function that, given the
66
+ * Fusion instance and environment, produces the initialized module instance.
67
+ * This is the signature of the {@link configureModules} function itself.
34
68
  *
35
- * @template TModules Addition modules
36
- * @template TRef usually undefined, optional references
37
- * @template TEnv environment object for configuring modules
69
+ * @template TModules - Additional modules registered by the application.
70
+ * @template TRef - The Fusion instance type used as a configuration reference.
71
+ * @template TEnv - The application environment descriptor.
38
72
  */
39
73
  export type AppModuleInit<TModules extends Array<AnyModule> | unknown = [], TRef extends Fusion = Fusion, TEnv = AppEnv> = (cb: AppModuleInitiator<TModules, TRef, TEnv>) => (args: AppModuleInitArgs<TRef, TEnv>) => Promise<AppModulesInstance<TModules>>;
74
+ /**
75
+ * Arguments passed to the async initializer returned by {@link configureModules}.
76
+ *
77
+ * @template TRef - The Fusion instance type.
78
+ * @template TEnv - The application environment descriptor.
79
+ */
40
80
  export type AppModuleInitArgs<TRef extends Fusion = Fusion, TEnv = AppEnv> = {
41
81
  fusion: TRef;
42
82
  env: TEnv;
43
83
  };
44
84
  /**
45
- * Type definition for AppRenderFn.
46
- * This type is responsible for rendering the application within a given environment.
47
- * It takes a generic `TFusion` type parameter extending `Fusion` for the Fusion instance,
48
- * and an optional `TEnv` type parameter for the application environment, defaulting to `AppEnv`.
85
+ * Render function signature for mounting a Fusion application into the DOM.
86
+ *
87
+ * Called by the Fusion portal or dev-server to render the application. The
88
+ * function receives the root element and render arguments (Fusion instance,
89
+ * environment, and modules) and optionally returns a cleanup function that
90
+ * is invoked when the application is unmounted.
49
91
  *
50
- * @param el - The root document element where the application will be rendered.
51
- * @param args - An object containing arguments required for component rendering, including the Fusion instance and environment-specific configurations.
52
- * @returns A function that can be invoked to perform cleanup operations, or `void` if no cleanup is necessary.
92
+ * @template TFusion - The Fusion instance type providing framework modules.
93
+ * @template TEnv - The application environment descriptor.
94
+ *
95
+ * @param el - The root HTML element where the application will be rendered.
96
+ * @param args - Render arguments including the Fusion instance, environment,
97
+ * and resolved modules.
98
+ * @returns A cleanup / teardown function, or `void` if no cleanup is needed.
53
99
  *
54
100
  * @example
55
- * const renderMyApp: AppRenderFn = (el, args) => {
56
- * // Implementation for rendering the application
57
- * // Optionally return a cleanup function
101
+ * ```ts
102
+ * import type { AppRenderFn } from '@equinor/fusion-framework-app';
103
+ * import { createRoot } from 'react-dom/client';
104
+ *
105
+ * export const renderApp: AppRenderFn = (el, args) => {
106
+ * const root = createRoot(el);
107
+ * root.render(<App />);
108
+ * return () => root.unmount();
58
109
  * };
110
+ * ```
59
111
  */
60
112
  export type AppRenderFn<TFusion extends Fusion = Fusion, TEnv = AppEnv> = (el: HTMLHtmlElement, args: ComponentRenderArgs<TFusion, TEnv>) => VoidFunction | void;
@@ -1 +1 @@
1
- export declare const version = "10.4.9";
1
+ export declare const version = "11.0.0";
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@equinor/fusion-framework-app",
3
- "version": "10.4.9",
3
+ "version": "11.0.0",
4
4
  "description": "",
5
5
  "main": "dist/esm/index.js",
6
6
  "types": "./dist/types/index.d.ts",
@@ -46,20 +46,20 @@
46
46
  },
47
47
  "dependencies": {
48
48
  "rxjs": "^7.8.1",
49
- "@equinor/fusion-framework": "7.4.13",
50
- "@equinor/fusion-framework-module-app": "7.4.1",
51
- "@equinor/fusion-framework-module-event": "5.0.1",
52
- "@equinor/fusion-framework-module": "5.0.6",
53
- "@equinor/fusion-framework-module-http": "7.0.8",
54
- "@equinor/fusion-framework-module-msal": "7.3.1",
55
- "@equinor/fusion-framework-module-telemetry": "4.6.4"
49
+ "@equinor/fusion-framework": "8.0.0",
50
+ "@equinor/fusion-framework-module-app": "8.0.0",
51
+ "@equinor/fusion-framework-module-event": "6.0.0",
52
+ "@equinor/fusion-framework-module": "6.0.0",
53
+ "@equinor/fusion-framework-module-http": "8.0.0",
54
+ "@equinor/fusion-framework-module-msal": "8.0.0",
55
+ "@equinor/fusion-framework-module-telemetry": "5.0.0"
56
56
  },
57
57
  "devDependencies": {
58
- "typescript": "^5.8.2",
59
- "@equinor/fusion-framework-module-bookmark": "^3.0.6"
58
+ "typescript": "^5.9.3",
59
+ "@equinor/fusion-framework-module-bookmark": "^4.0.0"
60
60
  },
61
61
  "peerDependencies": {
62
- "@equinor/fusion-framework-module-bookmark": "^3.0.6"
62
+ "@equinor/fusion-framework-module-bookmark": "^4.0.0"
63
63
  },
64
64
  "peerDependenciesMeta": {
65
65
  "@equinor/fusion-framework-module-bookmark": {