@equinor/fusion-framework-module-widget 14.0.2-next.0 → 15.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 (60) hide show
  1. package/CHANGELOG.md +37 -23
  2. package/README.md +171 -0
  3. package/dist/esm/Widget.js +91 -27
  4. package/dist/esm/Widget.js.map +1 -1
  5. package/dist/esm/WidgetModuleConfigurator.js +31 -15
  6. package/dist/esm/WidgetModuleConfigurator.js.map +1 -1
  7. package/dist/esm/WidgetModuleProvider.js +52 -20
  8. package/dist/esm/WidgetModuleProvider.js.map +1 -1
  9. package/dist/esm/enable-widget-module.js +16 -2
  10. package/dist/esm/enable-widget-module.js.map +1 -1
  11. package/dist/esm/errors.js +50 -0
  12. package/dist/esm/errors.js.map +1 -1
  13. package/dist/esm/index.js +9 -0
  14. package/dist/esm/index.js.map +1 -1
  15. package/dist/esm/module.js +12 -0
  16. package/dist/esm/module.js.map +1 -1
  17. package/dist/esm/state/actions.js +18 -3
  18. package/dist/esm/state/actions.js.map +1 -1
  19. package/dist/esm/state/create-reducer.js +10 -0
  20. package/dist/esm/state/create-reducer.js.map +1 -1
  21. package/dist/esm/state/create-state.js +12 -0
  22. package/dist/esm/state/create-state.js.map +1 -1
  23. package/dist/esm/state/flows.js +22 -0
  24. package/dist/esm/state/flows.js.map +1 -1
  25. package/dist/esm/utils.js +29 -0
  26. package/dist/esm/utils.js.map +1 -1
  27. package/dist/esm/version.js +1 -1
  28. package/dist/esm/version.js.map +1 -1
  29. package/dist/tsconfig.tsbuildinfo +1 -1
  30. package/dist/types/Widget.d.ts +91 -25
  31. package/dist/types/WidgetModuleConfigurator.d.ts +44 -10
  32. package/dist/types/WidgetModuleProvider.d.ts +80 -20
  33. package/dist/types/enable-widget-module.d.ts +16 -2
  34. package/dist/types/errors.d.ts +57 -0
  35. package/dist/types/events.d.ts +37 -17
  36. package/dist/types/index.d.ts +11 -2
  37. package/dist/types/module.d.ts +21 -0
  38. package/dist/types/state/actions.d.ts +29 -4
  39. package/dist/types/state/create-reducer.d.ts +10 -0
  40. package/dist/types/state/create-state.d.ts +12 -0
  41. package/dist/types/state/flows.d.ts +22 -0
  42. package/dist/types/types.d.ts +82 -15
  43. package/dist/types/utils.d.ts +29 -0
  44. package/dist/types/version.d.ts +1 -1
  45. package/package.json +13 -13
  46. package/src/Widget.ts +94 -27
  47. package/src/WidgetModuleConfigurator.ts +44 -17
  48. package/src/WidgetModuleProvider.ts +82 -20
  49. package/src/enable-widget-module.ts +16 -2
  50. package/src/errors.ts +57 -0
  51. package/src/events.ts +36 -17
  52. package/src/index.ts +12 -2
  53. package/src/module.ts +21 -0
  54. package/src/state/actions.ts +21 -3
  55. package/src/state/create-reducer.ts +10 -0
  56. package/src/state/create-state.ts +12 -0
  57. package/src/state/flows.ts +22 -0
  58. package/src/types.ts +88 -16
  59. package/src/utils.ts +29 -0
  60. package/src/version.ts +1 -1
@@ -9,6 +9,14 @@ import type { Actions } from './actions';
9
9
  import type { WidgetState } from '../types';
10
10
  import type WidgetModuleProvider from '../WidgetModuleProvider';
11
11
 
12
+ /**
13
+ * RxJS flow that reacts to `fetchManifest` actions by querying the
14
+ * {@link WidgetModuleProvider} for the manifest, emitting intermediate
15
+ * `setManifest` actions, and completing with a success or failure action.
16
+ *
17
+ * @param provider - The widget module provider used for API queries.
18
+ * @returns A `Flow` function for the widget state machine.
19
+ */
12
20
  export const handleFetchManifest =
13
21
  (provider: WidgetModuleProvider): Flow<Actions, WidgetState> =>
14
22
  (action$) =>
@@ -39,6 +47,14 @@ export const handleFetchManifest =
39
47
  }),
40
48
  );
41
49
 
50
+ /**
51
+ * RxJS flow that reacts to `fetchConfig` actions by querying the
52
+ * {@link WidgetModuleProvider} for the widget config, emitting intermediate
53
+ * `setConfig` actions, and completing with a success or failure action.
54
+ *
55
+ * @param provider - The widget module provider used for API queries.
56
+ * @returns A `Flow` function for the widget state machine.
57
+ */
42
58
  export const handleFetchConfig =
43
59
  (provider: WidgetModuleProvider): Flow<Actions, WidgetState> =>
44
60
  (action$) =>
@@ -63,6 +79,12 @@ export const handleFetchConfig =
63
79
  }),
64
80
  );
65
81
 
82
+ /**
83
+ * RxJS flow that reacts to `importWidget` actions by dynamically importing
84
+ * the widget’s JavaScript entry point URL and emitting success or failure.
85
+ *
86
+ * @returns A `Flow` function for the widget state machine.
87
+ */
66
88
  export const handleImportWidget = (): Flow<Actions, WidgetState> => (action$) =>
67
89
  action$.pipe(
68
90
  filter(actions.importWidget.match),
package/src/types.ts CHANGED
@@ -8,70 +8,109 @@ import type { QueryCtorOptions } from '@equinor/fusion-query';
8
8
  type Fusion = any;
9
9
 
10
10
  /**
11
- * WidgetEnv type represents the environment configuration for a widget.
11
+ * Environment descriptor passed to widget render functions.
12
+ *
13
+ * @template TProps - Custom props type forwarded to the widget.
12
14
  */
13
15
  export type WidgetEnv<TProps = unknown> = {
16
+ /** Base URL path the widget should use for routing (if applicable). */
14
17
  basename?: string;
18
+ /** The resolved widget manifest. */
15
19
  manifest?: WidgetManifest;
20
+ /** Arbitrary props forwarded from the host application. */
16
21
  props?: TProps;
17
22
  };
18
23
 
19
24
  /**
20
- * IClient interface represents a client with properties and methods for widget-related operations.
25
+ * HTTP client abstraction used by the widget module to fetch manifests
26
+ * and configurations from the backend API.
21
27
  */
22
28
  export type IClient = {
29
+ /** API version string appended as a query parameter to widget endpoints. */
23
30
  apiVersion: string;
31
+ /** Base URL used to construct full import URLs for widget scripts. */
24
32
  baseImportUrl: string;
33
+ /** Query constructor options for fetching a {@link WidgetManifest}. */
25
34
  getWidgetManifest: QueryCtorOptions<WidgetManifest, GetWidgetParameters>;
35
+ /** Query constructor options for fetching a {@link WidgetConfig}. */
26
36
  getWidgetConfig: QueryCtorOptions<WidgetConfig, GetWidgetParameters>;
27
37
  };
28
38
 
29
39
  /**
30
- * ModuleDeps type represents a tuple of dependencies required for a module.
40
+ * Peer-dependency module tuple required by the widget module.
41
+ *
42
+ * Includes {@link HttpModule}, {@link ServiceDiscoveryModule}, and
43
+ * {@link EventModule} (the latter two are optional at runtime).
31
44
  */
32
45
  export type ModuleDeps = [HttpModule, ServiceDiscoveryModule, EventModule];
33
46
 
34
47
  /**
35
- * GetWidgetParameters type represents parameters for retrieving widget information.
48
+ * Parameters for fetching a widget manifest or configuration.
36
49
  */
37
50
  export type GetWidgetParameters = {
51
+ /** Unique key (name) identifying the widget. */
38
52
  widgetKey: string;
53
+ /** Optional version or tag selector for the widget. */
39
54
  args?: { type: 'version' | 'tag'; value: string };
40
55
  };
41
56
 
42
57
  /**
43
- * WidgetEndpointBuilder type represents a function for building widget endpoints based on GetWidgetParameters.
58
+ * Function that builds a widget API endpoint URL from {@link GetWidgetParameters}.
44
59
  */
45
60
  export type WidgetEndpointBuilder = (args: GetWidgetParameters) => string;
46
61
 
47
62
  /**
48
- * WidgetManifest type represents the manifest information of a widget.
63
+ * Metadata manifest describing a widget’s identity, version, and entry point.
64
+ *
65
+ * Fetched from the backend API during widget initialization.
49
66
  */
50
67
  export type WidgetManifest = {
68
+ /** Unique backend identifier for the widget. */
51
69
  id: string;
70
+ /** Human-readable widget name (also used as lookup key). */
52
71
  name: string;
72
+ /** Semantic version of the widget. */
53
73
  version: string;
74
+ /** Brief description of the widget’s purpose. */
54
75
  description: string;
76
+ /** Optional list of maintainer identifiers. */
55
77
  maintainers?: string[];
78
+ /** Relative path to the JavaScript entry point (e.g., `index.js`). */
56
79
  entryPoint: string;
80
+ /** Base path for widget assets (combined with `entryPoint` to build the import URL). */
57
81
  assetPath: string;
58
82
  };
59
83
 
60
84
  /**
61
- * Endpoint type represents an endpoint with properties like name, uri, and optional scopes.
85
+ * Describes a named endpoint with a URI and optional OAuth scopes.
62
86
  */
63
- export type Endpoint = { name: string; uri: string; scopes?: string[] };
87
+ export type Endpoint = {
88
+ /** Endpoint name. */
89
+ name: string;
90
+ /** Endpoint URI. */
91
+ uri: string;
92
+ /** Optional OAuth scopes required for the endpoint. */
93
+ scopes?: string[];
94
+ };
64
95
 
65
96
  /**
66
- * WidgetConfig type represents the configuration for a widget, including environment and endpoints.
97
+ * Runtime configuration for a widget, including environment variables and
98
+ * backend endpoint mappings.
99
+ *
100
+ * @template TEnvironment - Custom environment shape.
67
101
  */
68
102
  export type WidgetConfig<TEnvironment = unknown> = {
103
+ /** Widget-specific environment variables. */
69
104
  environment: TEnvironment;
105
+ /** Map of endpoint names to URIs or structured {@link Endpoint} objects. */
70
106
  endpoints: Record<string, string | Endpoint>;
71
107
  };
72
108
 
73
109
  /**
74
- * WidgetModules type represents a combination of modules related to events and service discovery.
110
+ * Combined module set available inside a widget, merging custom modules with
111
+ * the standard {@link EventModule} and {@link ServiceDiscoveryModule}.
112
+ *
113
+ * @template TModules - Additional modules to combine.
75
114
  */
76
115
  export type WidgetModules<TModules extends Array<AnyModule> | unknown = unknown> = CombinedModules<
77
116
  TModules,
@@ -79,12 +118,18 @@ export type WidgetModules<TModules extends Array<AnyModule> | unknown = unknown>
79
118
  >;
80
119
 
81
120
  /**
82
- * WidgetProps type represents widget properties as a record of PropertyKey to unknown.
121
+ * Generic property bag passed from the host application to a widget render
122
+ * function.
83
123
  */
84
124
  export type WidgetProps = Record<PropertyKey, unknown>;
85
125
 
86
126
  /**
87
- * WidgetRenderArgs type represents arguments for rendering a widget, including fusion, environment, and optional properties.
127
+ * Arguments passed to a widget’s render functions (`renderWidget`, `render`,
128
+ * `renderIcon`, and the default export).
129
+ *
130
+ * @template TFusion - Fusion instance type.
131
+ * @template TEnv - Environment descriptor type.
132
+ * @template TProps - Custom props type.
88
133
  */
89
134
 
90
135
  export type WidgetRenderArgs<
@@ -98,34 +143,61 @@ export type WidgetRenderArgs<
98
143
  };
99
144
 
100
145
  /**
101
- * WidgetScriptModule type represents a script module for a widget with functions for rendering, rendering icons, etc.
146
+ * Describes the interface a widget script module must export.
147
+ *
148
+ * A dynamically imported widget entry point is expected to expose render
149
+ * functions that mount the widget into a given DOM element and return a
150
+ * cleanup function.
151
+ *
152
+ * @template TProps - Custom props type.
102
153
  */
103
154
  export type WidgetScriptModule<TProps extends WidgetProps = WidgetProps> = {
155
+ /** Default render function (fallback entry point). */
104
156
  default: (el: HTMLElement, args: WidgetRenderArgs, props?: TProps) => VoidFunction;
157
+ /** Primary render function for the widget body. */
105
158
  renderWidget: (el: HTMLElement, args: WidgetRenderArgs, props?: TProps) => VoidFunction;
159
+ /** Render function for the widget’s icon representation. */
106
160
  renderIcon: (el: HTMLElement, args: WidgetRenderArgs, props?: TProps) => VoidFunction;
161
+ /** Generic render function. */
107
162
  render: (el: HTMLElement, args: WidgetRenderArgs, props?: TProps) => VoidFunction;
108
163
  };
109
164
 
110
165
  /**
111
- * WidgetModulesInstance type represents an instance of widget modules.
166
+ * Resolved module instances available inside a running widget.
167
+ *
168
+ * @template TModules - Additional custom modules.
112
169
  */
113
170
  export type WidgetModulesInstance<TModules extends Array<AnyModule> | unknown = unknown> =
114
171
  ModulesInstance<WidgetModules<TModules>>;
115
172
 
116
173
  /**
117
- * WidgetState type represents the state of a widget, including properties like name, status, config, manifest, modules, and instance.
174
+ * Internal state managed by a {@link Widget}’s `FlowSubject` state machine.
175
+ *
176
+ * Tracks manifest, config, imported script, framework module instances, and
177
+ * a set of in-flight status markers.
178
+ *
179
+ * @template TModules - Custom module types.
118
180
  */
119
181
  // eslint-disable-next-line @typescript-eslint/no-explicit-any
120
182
  export type WidgetState<TModules = any> = {
183
+ /** Widget name (lookup key). */
121
184
  name: string;
185
+ /** Set of in-flight action base types (e.g., `'fetch_manifest'`). */
122
186
  status: Set<string>;
187
+ /** Resolved widget configuration (when loaded). */
123
188
  config?: WidgetConfig;
189
+ /** Resolved widget manifest (when loaded). */
124
190
  manifest?: WidgetManifest;
191
+ /** Imported widget script module (when loaded). */
125
192
  modules?: WidgetScriptModule;
193
+ /** Framework module instances created for the widget. */
126
194
  instance?: WidgetModulesInstance<TModules>;
127
195
  };
196
+
128
197
  /**
129
- * WidgetStateInitial type represents an initial state of a widget, omitting the status property.
198
+ * Initial widget state shape passed to the `Widget` constructor.
199
+ *
200
+ * Same as {@link WidgetState} but without the `status` set, which is
201
+ * initialized internally by the reducer.
130
202
  */
131
203
  export type WidgetStateInitial = Omit<WidgetState, 'status'>;
package/src/utils.ts CHANGED
@@ -1,6 +1,15 @@
1
1
  import type { GetWidgetParameters, IClient, WidgetEndpointBuilder } from './types';
2
2
  import type { IHttpClient } from '@equinor/fusion-framework-module-http';
3
3
 
4
+ /**
5
+ * Creates a {@link WidgetEndpointBuilder} that produces manifest endpoint URLs.
6
+ *
7
+ * Routes versioned or tagged lookups to `/widgets/{key}/versions/{value}` and
8
+ * unversioned lookups to `/widgets/{key}`.
9
+ *
10
+ * @param apiVersion - API version string appended as a query parameter.
11
+ * @returns A function that maps {@link GetWidgetParameters} to a URL path.
12
+ */
4
13
  export const defaultManifestEndpointBuilder =
5
14
  (apiVersion: string): WidgetEndpointBuilder =>
6
15
  (params: GetWidgetParameters) => {
@@ -15,6 +24,15 @@ export const defaultManifestEndpointBuilder =
15
24
  }
16
25
  };
17
26
 
27
+ /**
28
+ * Creates a {@link WidgetEndpointBuilder} that produces config endpoint URLs.
29
+ *
30
+ * Routes versioned or tagged lookups to `/widgets/{key}/versions/{value}/config`
31
+ * and unversioned lookups to `/widgets/{key}/config`.
32
+ *
33
+ * @param apiVersion - API version string appended as a query parameter.
34
+ * @returns A function that maps {@link GetWidgetParameters} to a URL path.
35
+ */
18
36
  export const defaultConfigEndpointBuilder =
19
37
  (apiVersion: string): WidgetEndpointBuilder =>
20
38
  (params: GetWidgetParameters) => {
@@ -30,6 +48,17 @@ export const defaultConfigEndpointBuilder =
30
48
  }
31
49
  };
32
50
 
51
+ /**
52
+ * Creates the default {@link IClient} that uses the given HTTP client to
53
+ * fetch widget manifests and configurations.
54
+ *
55
+ * Uses `api-version=1.0-preview` and the default manifest/config endpoint
56
+ * builders.
57
+ *
58
+ * @param httpClient - An `IHttpClient` instance (typically resolved from the
59
+ * `apps` service-discovery key).
60
+ * @returns A fully configured `IClient`.
61
+ */
33
62
  export const createDefaultClient = (httpClient: IHttpClient): IClient => {
34
63
  const apiVersion = '1.0-preview';
35
64
  return {
package/src/version.ts CHANGED
@@ -1,2 +1,2 @@
1
1
  // Generated by genversion.
2
- export const version = '14.0.2-next.0';
2
+ export const version = '15.0.1';