@equinor/fusion-framework-module-app 7.4.2-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 (66) hide show
  1. package/CHANGELOG.md +58 -5
  2. package/README.md +118 -11
  3. package/dist/esm/AppClient.js +16 -3
  4. package/dist/esm/AppClient.js.map +1 -1
  5. package/dist/esm/AppConfig.js +7 -1
  6. package/dist/esm/AppConfig.js.map +1 -1
  7. package/dist/esm/AppConfigurator.js +7 -0
  8. package/dist/esm/AppConfigurator.js.map +1 -1
  9. package/dist/esm/AppModuleProvider.js +80 -17
  10. package/dist/esm/AppModuleProvider.js.map +1 -1
  11. package/dist/esm/app/App.js +17 -1
  12. package/dist/esm/app/App.js.map +1 -1
  13. package/dist/esm/app/actions.js +13 -0
  14. package/dist/esm/app/actions.js.map +1 -1
  15. package/dist/esm/app/create-reducer.js +9 -0
  16. package/dist/esm/app/create-reducer.js.map +1 -1
  17. package/dist/esm/app/create-state.js +11 -0
  18. package/dist/esm/app/create-state.js.map +1 -1
  19. package/dist/esm/app/flows.js +3 -2
  20. package/dist/esm/app/flows.js.map +1 -1
  21. package/dist/esm/app/index.js +7 -0
  22. package/dist/esm/app/index.js.map +1 -1
  23. package/dist/esm/enable-app-module.js +19 -2
  24. package/dist/esm/enable-app-module.js.map +1 -1
  25. package/dist/esm/errors.js.map +1 -1
  26. package/dist/esm/index.js +18 -0
  27. package/dist/esm/index.js.map +1 -1
  28. package/dist/esm/module.js +1 -0
  29. package/dist/esm/module.js.map +1 -1
  30. package/dist/esm/version.js +1 -1
  31. package/dist/esm/version.js.map +1 -1
  32. package/dist/tsconfig.tsbuildinfo +1 -1
  33. package/dist/types/AppClient.d.ts +52 -10
  34. package/dist/types/AppConfig.d.ts +8 -0
  35. package/dist/types/AppConfigurator.d.ts +32 -0
  36. package/dist/types/AppModuleProvider.d.ts +80 -17
  37. package/dist/types/app/App.d.ts +28 -3
  38. package/dist/types/app/actions.d.ts +16 -0
  39. package/dist/types/app/create-reducer.d.ts +9 -0
  40. package/dist/types/app/create-state.d.ts +11 -0
  41. package/dist/types/app/events.d.ts +17 -1
  42. package/dist/types/app/index.d.ts +7 -0
  43. package/dist/types/enable-app-module.d.ts +19 -2
  44. package/dist/types/errors.d.ts +8 -0
  45. package/dist/types/index.d.ts +18 -0
  46. package/dist/types/module.d.ts +6 -0
  47. package/dist/types/types.d.ts +78 -3
  48. package/dist/types/version.d.ts +1 -1
  49. package/package.json +11 -11
  50. package/src/AppClient.ts +54 -11
  51. package/src/AppConfig.ts +15 -1
  52. package/src/AppConfigurator.ts +33 -1
  53. package/src/AppModuleProvider.ts +80 -17
  54. package/src/app/App.ts +29 -4
  55. package/src/app/actions.ts +16 -0
  56. package/src/app/create-reducer.ts +9 -0
  57. package/src/app/create-state.ts +11 -0
  58. package/src/app/events.ts +17 -1
  59. package/src/app/flows.ts +6 -2
  60. package/src/app/index.ts +7 -0
  61. package/src/enable-app-module.ts +19 -2
  62. package/src/errors.ts +8 -0
  63. package/src/index.ts +19 -0
  64. package/src/module.ts +6 -0
  65. package/src/types.ts +78 -5
  66. package/src/version.ts +1 -1
@@ -13,6 +13,15 @@ import { type Actions, actions } from './actions';
13
13
 
14
14
  import type { AppBundleState, AppBundleStateInitial } from './types';
15
15
 
16
+ /**
17
+ * Creates the Immer-powered reducer for the {@link App} state machine.
18
+ *
19
+ * Handles synchronous state updates (set manifest, config, settings, module, instance)
20
+ * and tracks in-progress async operations via a `status` set.
21
+ *
22
+ * @param value - Initial state values (appKey, tag, and any pre-loaded data).
23
+ * @returns A reducer function compatible with {@link FlowSubject}.
24
+ */
16
25
  export const createReducer = (value: AppBundleStateInitial) =>
17
26
  makeReducer<AppBundleState, Actions>(
18
27
  { ...value, status: new Set() } as AppBundleState,
@@ -14,6 +14,17 @@ import type { Actions } from './actions';
14
14
  import type { AppBundleState, AppBundleStateInitial } from './types';
15
15
  import type { AppModuleProvider } from '../AppModuleProvider';
16
16
 
17
+ /**
18
+ * Creates and configures the reactive state machine ({@link FlowSubject}) for
19
+ * an {@link App} instance.
20
+ *
21
+ * Registers flows for fetching manifests, configs, settings, and importing
22
+ * the application script module.
23
+ *
24
+ * @param value - Initial state values (appKey, tag, and any pre-loaded data).
25
+ * @param provider - The {@link AppModuleProvider} used by flows to fetch data.
26
+ * @returns A configured `FlowSubject` ready for use by the App class.
27
+ */
17
28
  export const createState = (
18
29
  value: AppBundleStateInitial,
19
30
  provider: AppModuleProvider,
package/src/app/events.ts CHANGED
@@ -10,7 +10,14 @@ import type {
10
10
  AppSettings,
11
11
  } from '../types';
12
12
 
13
- /** base event type for applications */
13
+ /**
14
+ * Base event initialization type for application lifecycle events.
15
+ *
16
+ * Extends {@link FrameworkEventInit} with a mandatory `appKey` field and
17
+ * the {@link App} as the event source.
18
+ *
19
+ * @template TDetail - Additional detail properties carried by the event.
20
+ */
14
21
  export type AppEventEventInit<TDetail extends Record<string, unknown> | unknown = unknown> =
15
22
  FrameworkEventInit<
16
23
  /** additional event details and key of target event */
@@ -19,10 +26,19 @@ export type AppEventEventInit<TDetail extends Record<string, unknown> | unknown
19
26
  App
20
27
  >;
21
28
 
29
+ /**
30
+ * Framework event carrying application-scoped detail and an {@link App} source.
31
+ *
32
+ * @template TDetail - Additional detail properties carried by the event.
33
+ */
22
34
  export type AppEvent<TDetail extends Record<string, unknown> | unknown = unknown> = FrameworkEvent<
23
35
  AppEventEventInit<TDetail>
24
36
  >;
25
37
 
38
+ /**
39
+ * Framework event emitted when an application lifecycle operation fails.
40
+ * The `error` detail carries the underlying failure.
41
+ */
26
42
  export type AppEventFailure = FrameworkEvent<
27
43
  AppEventEventInit<{
28
44
  error: AppConfig;
package/src/app/flows.ts CHANGED
@@ -173,9 +173,13 @@ export const handleImportApplication =
173
173
  filter(actions.importApp.match),
174
174
  // when request is received, abort any ongoing request and start new
175
175
  switchMap(({ payload }) => {
176
- const endpoint = [provider.assetUri, payload].join('/').replace(/\/{2,}/g, '/');
177
176
  // dynamically import the application script
178
- return from(import(/* @vite-ignore */ /* webpackIgnore: true */ endpoint)).pipe(
177
+ return from(
178
+ import(
179
+ /* @vite-ignore */ /* webpackIgnore: true */
180
+ [provider.assetUri, payload].join('/').replace(/\/{2,}/g, '/')
181
+ ),
182
+ ).pipe(
179
183
  // dispatch success action
180
184
  map(actions.importApp.success),
181
185
  // catch any error and dispatch failure action
package/src/app/index.ts CHANGED
@@ -1,3 +1,10 @@
1
+ /**
2
+ * Re-exports for the app sub-module.
3
+ *
4
+ * - {@link App} – Concrete application class managing reactive state.
5
+ * - {@link IApp} – Public interface for an application instance.
6
+ * - {@link AppInitializeResult} – Shape emitted by `App.initialize()`.
7
+ */
1
8
  export { App, IApp, type AppInitializeResult } from './App';
2
9
 
3
10
  export { default } from './App';
@@ -3,8 +3,25 @@ import { module } from './module';
3
3
  import type { AppConfigurator } from './AppConfigurator';
4
4
 
5
5
  /**
6
- * Method for enabling the Service module
7
- * @param configurator - configuration object
6
+ * Registers the app module with a framework configurator.
7
+ *
8
+ * Call this during framework setup to enable application loading, manifest fetching,
9
+ * configuration resolution, and per-user settings management.
10
+ *
11
+ * @param configurator - The framework modules configurator to register the app module with.
12
+ * @param callback - Optional callback to customize the {@link AppConfigurator} before initialization
13
+ * (e.g., override the HTTP client or set a custom asset URI).
14
+ *
15
+ * @example
16
+ * ```ts
17
+ * import { enableAppModule } from '@equinor/fusion-framework-module-app';
18
+ *
19
+ * export const configure = async (configurator: FrameworkConfigurator) => {
20
+ * enableAppModule(configurator, (builder) => {
21
+ * builder.setAssetUri('/custom-proxy');
22
+ * });
23
+ * };
24
+ * ```
8
25
  */
9
26
  export const enableAppModule = (
10
27
  // eslint-disable-next-line @typescript-eslint/no-explicit-any
package/src/errors.ts CHANGED
@@ -1,3 +1,11 @@
1
+ /**
2
+ * Discriminant for application-related errors.
3
+ *
4
+ * - `'not_found'` – The requested resource does not exist (HTTP 404).
5
+ * - `'unauthorized'` – The request lacks valid credentials (HTTP 401).
6
+ * - `'deleted'` – The resource has been removed (HTTP 410).
7
+ * - `'unknown'` – An unexpected failure occurred.
8
+ */
1
9
  type AppErrorType = 'not_found' | 'unauthorized' | 'unknown' | 'deleted';
2
10
 
3
11
  /**
package/src/index.ts CHANGED
@@ -1,3 +1,22 @@
1
+ /**
2
+ * @packageDocumentation
3
+ *
4
+ * Framework module for loading, configuring, and managing Fusion applications at runtime.
5
+ *
6
+ * Use {@link enableAppModule} to register the module with a framework configurator.
7
+ * Once initialized, {@link AppModuleProvider} exposes methods for fetching app manifests,
8
+ * configurations, user settings, and for setting the current active application.
9
+ *
10
+ * @example
11
+ * ```ts
12
+ * import { enableAppModule } from '@equinor/fusion-framework-module-app';
13
+ *
14
+ * export const configure = async (configurator: FrameworkConfigurator) => {
15
+ * enableAppModule(configurator);
16
+ * };
17
+ * ```
18
+ */
19
+
1
20
  export {
2
21
  AppModuleConfig,
3
22
  AppConfigurator,
package/src/module.ts CHANGED
@@ -4,8 +4,14 @@ import type { ModuleDeps } from './types';
4
4
  import { AppConfigurator } from './AppConfigurator';
5
5
  import { AppModuleProvider } from './AppModuleProvider';
6
6
 
7
+ /** Module key used to register and look up the app module in the framework. */
7
8
  export const moduleKey = 'app';
8
9
 
10
+ /**
11
+ * Type alias for the app module definition, binding the module key,
12
+ * provider type ({@link AppModuleProvider}), configurator type
13
+ * ({@link AppConfigurator}), and required module dependencies.
14
+ */
9
15
  export type AppModule = Module<typeof moduleKey, AppModuleProvider, AppConfigurator, ModuleDeps>;
10
16
 
11
17
  /**
package/src/types.ts CHANGED
@@ -6,12 +6,22 @@ import type { ServiceDiscoveryModule } from '@equinor/fusion-framework-module-se
6
6
  import type { AppConfig } from './AppConfig';
7
7
  import type IApp from './app';
8
8
 
9
+ /**
10
+ * Re-export of {@link ConfigEnvironment} from AppConfig.
11
+ */
9
12
  export type ConfigEnvironment = Record<string, unknown>;
10
13
  export type { AppConfig } from './AppConfig';
11
14
 
12
15
  // biome-ignore lint/suspicious/noExplicitAny: TODO - needs proper type definition
13
16
  type Fusion = any;
14
17
 
18
+ /**
19
+ * Environment bindings passed to an application at render time,
20
+ * including its manifest, configuration, base path, and custom props.
21
+ *
22
+ * @template TEnv - Shape of the environment configuration record.
23
+ * @template TProps - Shape of custom properties passed to the app.
24
+ */
15
25
  export type AppEnv<TEnv extends ConfigEnvironment = ConfigEnvironment, TProps = unknown> = {
16
26
  basename?: string;
17
27
  manifest?: AppManifest;
@@ -20,21 +30,38 @@ export type AppEnv<TEnv extends ConfigEnvironment = ConfigEnvironment, TProps =
20
30
  };
21
31
 
22
32
  /**
23
- * Reference to an app, used to fetch app manifest from app service
33
+ * Reference to an application, used to fetch the app manifest from the app service.
34
+ * The `tag` defaults to `'latest'` when omitted.
24
35
  */
25
36
  export type AppReference = {
26
37
  appKey: string;
27
38
  tag?: string; // defaults to 'latest'
28
39
  };
29
40
 
30
- // TODO: change to module-services when new app service is created
41
+ /**
42
+ * Required module dependencies for the app module.
43
+ *
44
+ * The app module depends on HTTP (for API calls), service discovery
45
+ * (for resolving the apps service URL), and events (for lifecycle notifications).
46
+ */
31
47
  export type ModuleDeps = [HttpModule, ServiceDiscoveryModule, EventModule];
32
48
 
49
+ /**
50
+ * Per-user application settings, stored as an arbitrary key-value record.
51
+ * Read via `getAppSettings` and written via `updateAppSettings` on the provider.
52
+ */
33
53
  export interface AppSettings {
34
54
  [key: string]: unknown;
35
55
  }
36
56
 
37
- // TODO: remove `report` and `launcher` when legacy apps are removed
57
+ /**
58
+ * Discriminant union of supported application types.
59
+ *
60
+ * - `'standalone'` – A full standalone application.
61
+ * - `'template'` / `'template-app'` – Template-based apps.
62
+ * - `'landing-page'` – Portal landing pages.
63
+ * - `'report'` / `'launcher'` – Legacy types (will be removed).
64
+ */
38
65
  export type AppType =
39
66
  | 'standalone'
40
67
  | 'report'
@@ -43,6 +70,13 @@ export type AppType =
43
70
  | 'template-app'
44
71
  | 'landing-page';
45
72
 
73
+ /**
74
+ * The currently active application, or `null` when cleared, or `undefined`
75
+ * when no application has been set yet.
76
+ *
77
+ * @template TModules - Additional framework modules the app depends on.
78
+ * @template TEnv - Shape of the environment configuration record.
79
+ */
46
80
  export type CurrentApp<
47
81
  TModules extends Array<AnyModule> = [],
48
82
  TEnv extends ConfigEnvironment = ConfigEnvironment,
@@ -50,6 +84,9 @@ export type CurrentApp<
50
84
 
51
85
  type Nullable<T> = T | null | undefined;
52
86
 
87
+ /**
88
+ * Represents a person associated with an application (admin or owner).
89
+ */
53
90
  type AppPerson = {
54
91
  id: string;
55
92
  azureUniqueId: string;
@@ -61,8 +98,10 @@ type AppPerson = {
61
98
  isExpired?: Nullable<boolean>;
62
99
  };
63
100
 
101
+ /** An application administrator. */
64
102
  export type AppAdmin = AppPerson;
65
103
 
104
+ /** An application owner. */
66
105
  export type AppOwner = AppPerson;
67
106
 
68
107
  /**
@@ -78,6 +117,10 @@ export type RouteSchemaEntry = [
78
117
  },
79
118
  ];
80
119
 
120
+ /**
121
+ * Build metadata returned by the app service for a specific application version.
122
+ * Contains the script entry point, asset path, tags, and optional CI metadata.
123
+ */
81
124
  export type AppBuildManifest = {
82
125
  version: string;
83
126
  entryPoint: string;
@@ -94,6 +137,10 @@ export type AppBuildManifest = {
94
137
  uploadedBy?: Nullable<AppOwner>;
95
138
  };
96
139
 
140
+ /**
141
+ * Full manifest describing a registered Fusion application, including
142
+ * display metadata, category, admins/owners, build info, and optional route schemas.
143
+ */
97
144
  export interface AppManifest {
98
145
  /** @deprecated will be removed, use appKey */
99
146
  key?: string;
@@ -127,8 +174,10 @@ export interface AppManifest {
127
174
  }
128
175
 
129
176
  /**
130
- * @template TEnvironment - name of hosted environment
131
- * @template TModule - ES module type (import return type)
177
+ * A loaded application bundle containing its manifest, config, and imported script module.
178
+ *
179
+ * @template TEnvironment - Shape of the environment config record.
180
+ * @template TModule - Type of the dynamically imported ES module.
132
181
  */
133
182
  export type AppBundle<
134
183
  TEnvironment extends ConfigEnvironment = ConfigEnvironment,
@@ -139,20 +188,44 @@ export type AppBundle<
139
188
  module: TModule;
140
189
  };
141
190
 
191
+ /**
192
+ * Combined module type merging the app's own modules with base framework modules
193
+ * (Event, HTTP, MSAL).
194
+ *
195
+ * @template TModules - Additional modules contributed by the application.
196
+ */
142
197
  export type AppModules<TModules extends Array<AnyModule> | unknown = unknown> = CombinedModules<
143
198
  TModules,
144
199
  [EventModule, HttpModule, MsalModule]
145
200
  >;
146
201
 
202
+ /**
203
+ * Arguments passed to an application's `renderApp` or default export function
204
+ * when mounting the application into a DOM element.
205
+ *
206
+ * @template TFusion - Type of the Fusion framework instance.
207
+ * @template TEnv - Type of the environment bindings.
208
+ */
147
209
  export type ComponentRenderArgs<TFusion extends Fusion = Fusion, TEnv = AppEnv> = {
148
210
  fusion: TFusion;
149
211
  env: TEnv;
150
212
  };
151
213
 
214
+ /**
215
+ * Shape of the ES module exported by an application's script bundle.
216
+ *
217
+ * Must expose either a `default` export or a `renderApp` function (or both)
218
+ * that mounts the application into a host DOM element.
219
+ */
152
220
  export type AppScriptModule = {
153
221
  default: (el: HTMLElement, args: ComponentRenderArgs) => VoidFunction;
154
222
  renderApp: (el: HTMLElement, args: ComponentRenderArgs) => VoidFunction;
155
223
  };
156
224
 
225
+ /**
226
+ * Instantiated module collection for a running application.
227
+ *
228
+ * @template TModules - Additional modules contributed by the application.
229
+ */
157
230
  export type AppModulesInstance<TModules extends Array<AnyModule> | unknown = unknown> =
158
231
  ModulesInstance<AppModules<TModules>>;
package/src/version.ts CHANGED
@@ -1,2 +1,2 @@
1
1
  // Generated by genversion.
2
- export const version = '7.4.2-next.0';
2
+ export const version = '8.0.1';