@equinor/fusion-framework-module-widget 14.0.1 → 15.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 +34 -7
- package/README.md +171 -0
- package/dist/esm/Widget.js +91 -27
- package/dist/esm/Widget.js.map +1 -1
- package/dist/esm/WidgetModuleConfigurator.js +31 -15
- package/dist/esm/WidgetModuleConfigurator.js.map +1 -1
- package/dist/esm/WidgetModuleProvider.js +52 -20
- package/dist/esm/WidgetModuleProvider.js.map +1 -1
- package/dist/esm/enable-widget-module.js +16 -2
- package/dist/esm/enable-widget-module.js.map +1 -1
- package/dist/esm/errors.js +50 -0
- package/dist/esm/errors.js.map +1 -1
- package/dist/esm/index.js +9 -0
- package/dist/esm/index.js.map +1 -1
- package/dist/esm/module.js +12 -0
- package/dist/esm/module.js.map +1 -1
- package/dist/esm/state/actions.js +18 -3
- package/dist/esm/state/actions.js.map +1 -1
- package/dist/esm/state/create-reducer.js +10 -0
- package/dist/esm/state/create-reducer.js.map +1 -1
- package/dist/esm/state/create-state.js +12 -0
- package/dist/esm/state/create-state.js.map +1 -1
- package/dist/esm/state/flows.js +22 -0
- package/dist/esm/state/flows.js.map +1 -1
- package/dist/esm/utils.js +29 -0
- package/dist/esm/utils.js.map +1 -1
- package/dist/esm/version.js +1 -1
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/dist/types/Widget.d.ts +91 -25
- package/dist/types/WidgetModuleConfigurator.d.ts +44 -10
- package/dist/types/WidgetModuleProvider.d.ts +80 -20
- package/dist/types/enable-widget-module.d.ts +16 -2
- package/dist/types/errors.d.ts +57 -0
- package/dist/types/events.d.ts +37 -17
- package/dist/types/index.d.ts +11 -2
- package/dist/types/module.d.ts +21 -0
- package/dist/types/state/actions.d.ts +29 -4
- package/dist/types/state/create-reducer.d.ts +10 -0
- package/dist/types/state/create-state.d.ts +12 -0
- package/dist/types/state/flows.d.ts +22 -0
- package/dist/types/types.d.ts +82 -15
- package/dist/types/utils.d.ts +29 -0
- package/dist/types/version.d.ts +1 -1
- package/package.json +13 -13
- package/src/Widget.ts +94 -27
- package/src/WidgetModuleConfigurator.ts +44 -17
- package/src/WidgetModuleProvider.ts +82 -20
- package/src/enable-widget-module.ts +16 -2
- package/src/errors.ts +57 -0
- package/src/events.ts +36 -17
- package/src/index.ts +12 -2
- package/src/module.ts +21 -0
- package/src/state/actions.ts +21 -3
- package/src/state/create-reducer.ts +10 -0
- package/src/state/create-state.ts +12 -0
- package/src/state/flows.ts +22 -0
- package/src/types.ts +88 -16
- package/src/utils.ts +29 -0
- package/src/version.ts +1 -1
package/dist/types/Widget.d.ts
CHANGED
|
@@ -5,16 +5,47 @@ import { Observable } from 'rxjs';
|
|
|
5
5
|
import type WidgetModuleProvider from './WidgetModuleProvider';
|
|
6
6
|
import type { WidgetModuleConfig } from './WidgetModuleConfigurator';
|
|
7
7
|
import './events';
|
|
8
|
+
/**
|
|
9
|
+
* Manages the full lifecycle of a single Fusion widget.
|
|
10
|
+
*
|
|
11
|
+
* A `Widget` encapsulates fetching its manifest, dynamically importing its
|
|
12
|
+
* script entry point, loading configuration, and emitting lifecycle events.
|
|
13
|
+
* Internally it uses an RxJS-based `FlowSubject` state machine driven by
|
|
14
|
+
* actions and flows defined in the `state/` directory.
|
|
15
|
+
*
|
|
16
|
+
* Create instances via {@link WidgetModuleProvider.getWidget} rather than
|
|
17
|
+
* constructing directly.
|
|
18
|
+
*
|
|
19
|
+
* @example
|
|
20
|
+
* ```typescript
|
|
21
|
+
* const widget = provider.getWidget('my-widget');
|
|
22
|
+
* widget.initialize().subscribe(({ manifest, script }) => {
|
|
23
|
+
* script.renderWidget(el, { fusion, env: { manifest } });
|
|
24
|
+
* });
|
|
25
|
+
* ```
|
|
26
|
+
*/
|
|
8
27
|
export declare class Widget {
|
|
9
28
|
#private;
|
|
29
|
+
/** Human-readable widget name used as the lookup key for manifest and config. */
|
|
10
30
|
name: string;
|
|
31
|
+
/** Module-level HTTP client configuration used to resolve asset URLs. */
|
|
11
32
|
config?: WidgetModuleConfig;
|
|
33
|
+
/** Optional version or tag parameters forwarded to manifest/config endpoints. */
|
|
12
34
|
widgetPrams?: GetWidgetParameters['args'];
|
|
35
|
+
/** Current snapshot of the widget's internal state (manifest, config, modules, status). */
|
|
13
36
|
get state(): WidgetState;
|
|
14
37
|
/**
|
|
15
|
-
* Constructs a new Widget instance.
|
|
16
|
-
*
|
|
17
|
-
*
|
|
38
|
+
* Constructs a new `Widget` instance.
|
|
39
|
+
*
|
|
40
|
+
* Prefer using {@link WidgetModuleProvider.getWidget} instead of calling
|
|
41
|
+
* this constructor directly.
|
|
42
|
+
*
|
|
43
|
+
* @param value - Initial widget state (at minimum, the widget `name`).
|
|
44
|
+
* @param args - Dependencies required by the widget.
|
|
45
|
+
* @param args.provider - The owning {@link WidgetModuleProvider}.
|
|
46
|
+
* @param args.config - Optional module-level HTTP client configuration.
|
|
47
|
+
* @param args.event - Optional event module for dispatching lifecycle events.
|
|
48
|
+
* @param args.widgetPrams - Optional version/tag selector for the widget.
|
|
18
49
|
*/
|
|
19
50
|
constructor(value: WidgetStateInitial, args: {
|
|
20
51
|
provider: WidgetModuleProvider;
|
|
@@ -23,36 +54,61 @@ export declare class Widget {
|
|
|
23
54
|
widgetPrams?: GetWidgetParameters['args'];
|
|
24
55
|
});
|
|
25
56
|
/**
|
|
26
|
-
* Retrieves the manifest
|
|
27
|
-
*
|
|
28
|
-
*
|
|
57
|
+
* Retrieves the widget manifest as an observable stream.
|
|
58
|
+
*
|
|
59
|
+
* If the manifest is already cached in state it is emitted immediately.
|
|
60
|
+
* When `force_refresh` is `true`, a new fetch is dispatched regardless of
|
|
61
|
+
* cache status.
|
|
62
|
+
*
|
|
63
|
+
* @param force_refresh - When `true`, re-fetches the manifest even if cached.
|
|
64
|
+
* @returns Observable that emits the {@link WidgetManifest} and completes.
|
|
65
|
+
* @throws {Error} When the manifest fetch fails (wraps the underlying cause).
|
|
29
66
|
*/
|
|
30
67
|
getManifest(force_refresh?: boolean): Observable<WidgetManifest>;
|
|
31
68
|
/**
|
|
32
|
-
* Retrieves the configuration
|
|
33
|
-
*
|
|
34
|
-
*
|
|
69
|
+
* Retrieves the widget configuration as an observable stream.
|
|
70
|
+
*
|
|
71
|
+
* Returns the cached config immediately when available. Set `force_refresh`
|
|
72
|
+
* to `true` to force a new fetch from the backend API.
|
|
73
|
+
*
|
|
74
|
+
* @param force_refresh - When `true`, re-fetches the config even if cached.
|
|
75
|
+
* @returns Observable that emits the {@link WidgetConfig} and completes.
|
|
76
|
+
* @throws {Error} When the config fetch fails (wraps the underlying cause).
|
|
35
77
|
*/
|
|
36
78
|
getConfig(force_refresh?: boolean): Observable<WidgetConfig>;
|
|
37
79
|
/**
|
|
38
|
-
*
|
|
39
|
-
*
|
|
80
|
+
* Dispatches a config fetch action into the state machine.
|
|
81
|
+
*
|
|
82
|
+
* @param update - When `true`, merges the fetched config with existing state
|
|
83
|
+
* instead of replacing it.
|
|
40
84
|
*/
|
|
41
85
|
loadConfig(update?: boolean): void;
|
|
42
86
|
/**
|
|
43
|
-
*
|
|
44
|
-
*
|
|
87
|
+
* Dispatches a manifest fetch action into the state machine.
|
|
88
|
+
*
|
|
89
|
+
* @param update - When `true`, merges the fetched manifest with existing
|
|
90
|
+
* state instead of replacing it.
|
|
45
91
|
*/
|
|
46
92
|
loadManifest(update?: boolean): void;
|
|
47
93
|
/**
|
|
48
|
-
* Retrieves the widget module as an observable stream.
|
|
49
|
-
*
|
|
50
|
-
*
|
|
94
|
+
* Retrieves the widget's script module as an observable stream.
|
|
95
|
+
*
|
|
96
|
+
* Resolves the manifest first, builds the full import URL from the asset
|
|
97
|
+
* path and entry point, then dynamically imports the script. The imported
|
|
98
|
+
* module is cached in state for subsequent calls.
|
|
99
|
+
*
|
|
100
|
+
* @param force_refresh - When `true`, re-imports the script even if cached.
|
|
101
|
+
* @returns Observable that emits the {@link WidgetScriptModule} and completes.
|
|
102
|
+
* @throws {Error} When the script import fails (wraps the underlying cause).
|
|
51
103
|
*/
|
|
52
104
|
getWidgetModule(force_refresh?: boolean): Observable<WidgetScriptModule>;
|
|
53
105
|
/**
|
|
54
|
-
* Initializes the widget
|
|
55
|
-
*
|
|
106
|
+
* Initializes the widget by loading the manifest, importing the script, and
|
|
107
|
+
* preparing configuration. Emits a combined result when all resources are ready.
|
|
108
|
+
*
|
|
109
|
+
* @returns Observable that emits `{ manifest, script, config }` and completes
|
|
110
|
+
* once all resources have been resolved.
|
|
111
|
+
* @throws {Error} When any initialization step fails.
|
|
56
112
|
*/
|
|
57
113
|
initialize(): Observable<{
|
|
58
114
|
manifest: WidgetManifest;
|
|
@@ -60,19 +116,29 @@ export declare class Widget {
|
|
|
60
116
|
config?: WidgetConfig;
|
|
61
117
|
}>;
|
|
62
118
|
/**
|
|
63
|
-
* Retrieves the widget module
|
|
64
|
-
*
|
|
65
|
-
*
|
|
119
|
+
* Retrieves the widget script module as a `Promise`.
|
|
120
|
+
*
|
|
121
|
+
* When `allow_cache` is `true` (default), resolves with the first emitted
|
|
122
|
+
* value (which may be cached). When `false`, waits for the last emission
|
|
123
|
+
* after a forced refresh.
|
|
124
|
+
*
|
|
125
|
+
* @param allow_cache - When `true`, uses `firstValueFrom`; when `false`,
|
|
126
|
+
* uses `lastValueFrom` after forcing a re-import.
|
|
127
|
+
* @returns Promise that resolves with the {@link WidgetScriptModule}.
|
|
66
128
|
*/
|
|
67
129
|
getWidgetModuleAsync(allow_cache?: boolean): Promise<WidgetScriptModule>;
|
|
68
130
|
/**
|
|
69
|
-
*
|
|
70
|
-
*
|
|
71
|
-
* @param
|
|
131
|
+
* Replaces or merges the widget manifest in state.
|
|
132
|
+
*
|
|
133
|
+
* @param manifest - The new or partial manifest to set.
|
|
134
|
+
* @param replace - When `false` (default), the new manifest is merged with
|
|
135
|
+
* the existing one. Pass explicit `false` to merge, or omit to merge.
|
|
72
136
|
*/
|
|
73
137
|
updateManifest(manifest: WidgetManifest, replace?: false): void;
|
|
74
138
|
/**
|
|
75
|
-
* Disposes of the widget by unsubscribing from
|
|
139
|
+
* Disposes of the widget by unsubscribing from all internal subscriptions.
|
|
140
|
+
*
|
|
141
|
+
* After disposal the widget instance should not be reused.
|
|
76
142
|
*/
|
|
77
143
|
dispose(): void;
|
|
78
144
|
}
|
|
@@ -1,29 +1,63 @@
|
|
|
1
1
|
import { BaseConfigBuilder, type ConfigBuilderCallback } from '@equinor/fusion-framework-module';
|
|
2
2
|
import type { ConfigBuilderCallbackArgs } from '@equinor/fusion-framework-module';
|
|
3
3
|
import type { IClient } from './types';
|
|
4
|
+
/**
|
|
5
|
+
* Resolved configuration produced by {@link WidgetModuleConfigurator}.
|
|
6
|
+
*
|
|
7
|
+
* Contains the {@link IClient} used to fetch widget manifests and configs
|
|
8
|
+
* from the backend API.
|
|
9
|
+
*/
|
|
4
10
|
export type WidgetModuleConfig = {
|
|
11
|
+
/** HTTP client abstraction for widget API calls. */
|
|
5
12
|
client: IClient;
|
|
6
13
|
};
|
|
14
|
+
/**
|
|
15
|
+
* Callback signature accepted by {@link enableWidgetModule} for customizing
|
|
16
|
+
* the widget module configuration.
|
|
17
|
+
*
|
|
18
|
+
* @param builder - The {@link WidgetModuleConfigurator} instance to configure.
|
|
19
|
+
*/
|
|
7
20
|
export type WidgetModuleConfigBuilderCallback = (builder: WidgetModuleConfigurator) => void | Promise<void>;
|
|
21
|
+
/**
|
|
22
|
+
* Configuration builder for the widget module.
|
|
23
|
+
*
|
|
24
|
+
* Extends `BaseConfigBuilder` to produce a {@link WidgetModuleConfig}. If no
|
|
25
|
+
* custom client is provided via {@link setClient}, a default HTTP client is
|
|
26
|
+
* created from the `apps` service-discovery endpoint.
|
|
27
|
+
*
|
|
28
|
+
* @example
|
|
29
|
+
* ```typescript
|
|
30
|
+
* enableWidgetModule(configurator, (builder) => {
|
|
31
|
+
* builder.setClient(async () => myCustomClient);
|
|
32
|
+
* });
|
|
33
|
+
* ```
|
|
34
|
+
*/
|
|
8
35
|
export declare class WidgetModuleConfigurator extends BaseConfigBuilder<WidgetModuleConfig> {
|
|
36
|
+
/** Default cache expiration time in milliseconds (1 minute). */
|
|
9
37
|
defaultExpireTime: number;
|
|
10
38
|
/**
|
|
11
|
-
*
|
|
12
|
-
*
|
|
39
|
+
* Registers a custom {@link IClient} factory for the widget module.
|
|
40
|
+
*
|
|
41
|
+
* @param cb - Callback that receives config-builder args and returns an
|
|
42
|
+
* `IClient` instance (or a `Promise` thereof).
|
|
13
43
|
*/
|
|
14
44
|
setClient(cb: ConfigBuilderCallback<IClient>): void;
|
|
15
45
|
/**
|
|
16
|
-
*
|
|
17
|
-
*
|
|
18
|
-
*
|
|
19
|
-
* @
|
|
46
|
+
* Creates an HTTP client by resolving the `apps` client from the HTTP module
|
|
47
|
+
* or falling back to service discovery.
|
|
48
|
+
*
|
|
49
|
+
* @param clientId - Registered HTTP client identifier (typically `'apps'`).
|
|
50
|
+
* @param init - Framework config-builder callback args providing module instances.
|
|
51
|
+
* @returns An `IHttpClient` instance for widget API calls.
|
|
20
52
|
*/
|
|
21
53
|
private _createHttpClient;
|
|
22
54
|
/**
|
|
23
|
-
*
|
|
24
|
-
*
|
|
25
|
-
*
|
|
26
|
-
* @
|
|
55
|
+
* Finalizes the configuration by creating the default HTTP client when no
|
|
56
|
+
* custom client has been set.
|
|
57
|
+
*
|
|
58
|
+
* @param config - Partial configuration accumulated by builder callbacks.
|
|
59
|
+
* @param _init - Framework config-builder callback args.
|
|
60
|
+
* @returns The fully resolved {@link WidgetModuleConfig}.
|
|
27
61
|
*/
|
|
28
62
|
protected _processConfig(config: Partial<WidgetModuleConfig>, _init: ConfigBuilderCallbackArgs): Promise<WidgetModuleConfig>;
|
|
29
63
|
}
|
|
@@ -4,56 +4,116 @@ import type { EventModule } from '@equinor/fusion-framework-module-event';
|
|
|
4
4
|
import type { GetWidgetParameters, WidgetConfig, WidgetManifest } from './types';
|
|
5
5
|
import type { WidgetModuleConfig } from './WidgetModuleConfigurator';
|
|
6
6
|
import { Widget } from './Widget';
|
|
7
|
+
/**
|
|
8
|
+
* Public interface for the widget module provider.
|
|
9
|
+
*
|
|
10
|
+
* Consumers depend on this interface rather than the concrete
|
|
11
|
+
* {@link WidgetModuleProvider} class, enabling testability and
|
|
12
|
+
* alternative implementations.
|
|
13
|
+
*/
|
|
7
14
|
export interface IWidgetModuleProvider {
|
|
15
|
+
/**
|
|
16
|
+
* Creates a {@link Widget} instance for the given widget key.
|
|
17
|
+
*
|
|
18
|
+
* @param widgetKey - Unique identifier (name) of the widget.
|
|
19
|
+
* @param args - Optional version or tag selector.
|
|
20
|
+
* @returns A new `Widget` ready for initialization.
|
|
21
|
+
*/
|
|
8
22
|
getWidget(widgetKey: GetWidgetParameters['widgetKey'], args?: GetWidgetParameters['args']): Widget;
|
|
23
|
+
/**
|
|
24
|
+
* Fetches the manifest for a widget as an observable stream.
|
|
25
|
+
*
|
|
26
|
+
* @param widgetKey - Unique identifier (name) of the widget.
|
|
27
|
+
* @param args - Optional version or tag selector.
|
|
28
|
+
* @returns Observable that emits the {@link WidgetManifest}.
|
|
29
|
+
*/
|
|
9
30
|
getWidgetManifest(widgetKey: GetWidgetParameters['widgetKey'], args?: GetWidgetParameters['args']): Observable<WidgetManifest>;
|
|
31
|
+
/**
|
|
32
|
+
* Fetches the configuration for a widget as an observable stream.
|
|
33
|
+
*
|
|
34
|
+
* @param widgetKey - Unique identifier (name) of the widget.
|
|
35
|
+
* @param args - Optional version or tag selector.
|
|
36
|
+
* @returns Observable that emits the {@link WidgetConfig}.
|
|
37
|
+
*/
|
|
10
38
|
getWidgetConfig(widgetKey: GetWidgetParameters['widgetKey'], args?: GetWidgetParameters['args']): Observable<WidgetConfig>;
|
|
11
39
|
}
|
|
12
40
|
/**
|
|
13
|
-
*
|
|
41
|
+
* Concrete provider that manages widget instances and performs API queries
|
|
42
|
+
* for widget manifests and configurations.
|
|
43
|
+
*
|
|
44
|
+
* Created automatically during module initialization; see {@link module} and
|
|
45
|
+
* {@link enableWidgetModule}.
|
|
46
|
+
*
|
|
47
|
+
* @example
|
|
48
|
+
* ```typescript
|
|
49
|
+
* const widget = provider.getWidget('my-widget');
|
|
50
|
+
* widget.initialize().subscribe(result => { ... });
|
|
51
|
+
* ```
|
|
14
52
|
*/
|
|
15
53
|
export declare class WidgetModuleProvider implements IWidgetModuleProvider {
|
|
16
54
|
#private;
|
|
17
55
|
/**
|
|
18
|
-
*
|
|
19
|
-
*
|
|
56
|
+
* Creates a new `WidgetModuleProvider`.
|
|
57
|
+
*
|
|
58
|
+
* @param args - Provider dependencies.
|
|
59
|
+
* @param args.config - Resolved {@link WidgetModuleConfig} with HTTP client.
|
|
60
|
+
* @param args.event - Optional event module for dispatching lifecycle events.
|
|
20
61
|
*/
|
|
21
62
|
constructor(args: {
|
|
22
63
|
config: WidgetModuleConfig;
|
|
23
64
|
event?: ModuleType<EventModule>;
|
|
24
65
|
});
|
|
25
66
|
/**
|
|
26
|
-
*
|
|
27
|
-
*
|
|
28
|
-
*
|
|
67
|
+
* Creates a new {@link Widget} instance for the given name.
|
|
68
|
+
*
|
|
69
|
+
* The returned widget has not been initialized yet — call
|
|
70
|
+
* {@link Widget.initialize} to start the lifecycle.
|
|
71
|
+
*
|
|
72
|
+
* @param name - Unique widget name (used as lookup key).
|
|
73
|
+
* @param widgetPrams - Optional version or tag selector.
|
|
29
74
|
* @returns A new `Widget` instance.
|
|
30
75
|
*/
|
|
31
76
|
getWidget(name: string, widgetPrams?: GetWidgetParameters['args']): Widget;
|
|
32
77
|
/**
|
|
33
|
-
*
|
|
34
|
-
*
|
|
35
|
-
* @param
|
|
36
|
-
* @
|
|
78
|
+
* Fetches the manifest for a widget via the configured HTTP client.
|
|
79
|
+
*
|
|
80
|
+
* @param name - Unique widget name.
|
|
81
|
+
* @param widgetPrams - Optional version or tag selector.
|
|
82
|
+
* @returns Observable that emits the {@link WidgetManifest} and completes.
|
|
83
|
+
* @throws {WidgetManifestLoadError} When the manifest request fails.
|
|
37
84
|
*/
|
|
38
85
|
getWidgetManifest(name: string, widgetPrams?: GetWidgetParameters['args']): Observable<WidgetManifest>;
|
|
39
86
|
/**
|
|
40
|
-
*
|
|
41
|
-
*
|
|
42
|
-
* @param
|
|
43
|
-
* @
|
|
87
|
+
* Fetches the configuration for a widget via the configured HTTP client.
|
|
88
|
+
*
|
|
89
|
+
* @param name - Unique widget name.
|
|
90
|
+
* @param widgetPrams - Optional version or tag selector.
|
|
91
|
+
* @returns Observable that emits the {@link WidgetConfig} and completes.
|
|
92
|
+
* @throws {WidgetConfigLoadError} When the config request fails.
|
|
44
93
|
*/
|
|
45
94
|
getWidgetConfig(name: string, widgetPrams?: GetWidgetParameters['args']): Observable<WidgetConfig>;
|
|
95
|
+
/**
|
|
96
|
+
* Internal: queries widget config from the API and maps HTTP errors to
|
|
97
|
+
* typed {@link WidgetConfigLoadError} instances.
|
|
98
|
+
*
|
|
99
|
+
* @param widgetKey - Widget identifier.
|
|
100
|
+
* @param args - Optional version or tag selector.
|
|
101
|
+
* @returns Observable emitting the {@link WidgetConfig}.
|
|
102
|
+
*/
|
|
46
103
|
protected _getWidgetConfig(widgetKey: GetWidgetParameters['widgetKey'], args?: GetWidgetParameters['args']): Observable<WidgetConfig>;
|
|
47
104
|
/**
|
|
48
|
-
*
|
|
49
|
-
* @
|
|
50
|
-
*
|
|
51
|
-
* @
|
|
52
|
-
* @
|
|
105
|
+
* Internal: queries widget manifest from the API and maps HTTP errors to
|
|
106
|
+
* typed {@link WidgetManifestLoadError} instances.
|
|
107
|
+
*
|
|
108
|
+
* @param widgetKey - Widget identifier.
|
|
109
|
+
* @param args - Optional version or tag selector.
|
|
110
|
+
* @returns Observable emitting the {@link WidgetManifest}.
|
|
53
111
|
*/
|
|
54
112
|
protected _getWidget(widgetKey: GetWidgetParameters['widgetKey'], args?: GetWidgetParameters['args']): Observable<WidgetManifest>;
|
|
55
113
|
/**
|
|
56
|
-
* Disposes
|
|
114
|
+
* Disposes all internal query subscriptions.
|
|
115
|
+
*
|
|
116
|
+
* After disposal the provider should not be reused.
|
|
57
117
|
*/
|
|
58
118
|
dispose(): void;
|
|
59
119
|
}
|
|
@@ -1,7 +1,21 @@
|
|
|
1
1
|
import type { IModulesConfigurator } from '@equinor/fusion-framework-module';
|
|
2
2
|
import type { WidgetModuleConfigBuilderCallback } from './WidgetModuleConfigurator';
|
|
3
3
|
/**
|
|
4
|
-
*
|
|
5
|
-
*
|
|
4
|
+
* Registers the widget module on a Fusion Framework configurator.
|
|
5
|
+
*
|
|
6
|
+
* Call this during framework setup to enable widget loading, manifest
|
|
7
|
+
* resolution, and script import capabilities.
|
|
8
|
+
*
|
|
9
|
+
* @param configurator - The framework modules configurator to register the
|
|
10
|
+
* widget module on.
|
|
11
|
+
* @param builder - Optional callback to customize the
|
|
12
|
+
* {@link WidgetModuleConfigurator} (e.g., set a custom HTTP client).
|
|
13
|
+
*
|
|
14
|
+
* @example
|
|
15
|
+
* ```typescript
|
|
16
|
+
* import { enableWidgetModule } from '@equinor/fusion-framework-module-widget';
|
|
17
|
+
*
|
|
18
|
+
* enableWidgetModule(configurator);
|
|
19
|
+
* ```
|
|
6
20
|
*/
|
|
7
21
|
export declare const enableWidgetModule: (configurator: IModulesConfigurator<any, any>, builder?: WidgetModuleConfigBuilderCallback) => void;
|
package/dist/types/errors.d.ts
CHANGED
|
@@ -1,16 +1,73 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Discriminator for categorizing widget HTTP errors.
|
|
3
|
+
*
|
|
4
|
+
* - `'not_found'` — HTTP 404
|
|
5
|
+
* - `'unauthorized'` — HTTP 401
|
|
6
|
+
* - `'unknown'` — any other error
|
|
7
|
+
*/
|
|
1
8
|
type WidgetErrorType = 'not_found' | 'unauthorized' | 'unknown';
|
|
9
|
+
/**
|
|
10
|
+
* Error thrown when a widget manifest cannot be loaded from the backend API.
|
|
11
|
+
*
|
|
12
|
+
* Use the static {@link fromHttpResponse} factory to create instances from
|
|
13
|
+
* HTTP responses with appropriate type mapping.
|
|
14
|
+
*/
|
|
2
15
|
export declare class WidgetManifestLoadError extends Error {
|
|
3
16
|
readonly type: WidgetErrorType;
|
|
17
|
+
/**
|
|
18
|
+
* Creates a `WidgetManifestLoadError` from an HTTP `Response`.
|
|
19
|
+
*
|
|
20
|
+
* Maps HTTP 401 to `'unauthorized'`, 404 to `'not_found'`, and all other
|
|
21
|
+
* status codes to `'unknown'`.
|
|
22
|
+
*
|
|
23
|
+
* @param response - The failing HTTP response.
|
|
24
|
+
* @param options - Standard `ErrorOptions` (e.g., `cause`).
|
|
25
|
+
* @returns A typed `WidgetManifestLoadError`.
|
|
26
|
+
*/
|
|
4
27
|
static fromHttpResponse(response: Response, options?: ErrorOptions): WidgetManifestLoadError;
|
|
28
|
+
/**
|
|
29
|
+
* @param type - Error category discriminator.
|
|
30
|
+
* @param message - Human-readable error description.
|
|
31
|
+
* @param options - Standard `ErrorOptions` (e.g., `cause`).
|
|
32
|
+
*/
|
|
5
33
|
constructor(type: WidgetErrorType, message?: string, options?: ErrorOptions);
|
|
6
34
|
}
|
|
35
|
+
/**
|
|
36
|
+
* Error thrown when a widget configuration cannot be loaded from the backend API.
|
|
37
|
+
*
|
|
38
|
+
* Use the static {@link fromHttpResponse} factory to create instances from
|
|
39
|
+
* HTTP responses with appropriate type mapping.
|
|
40
|
+
*/
|
|
7
41
|
export declare class WidgetConfigLoadError extends Error {
|
|
8
42
|
readonly type: WidgetErrorType;
|
|
43
|
+
/**
|
|
44
|
+
* Creates a `WidgetConfigLoadError` from an HTTP `Response`.
|
|
45
|
+
*
|
|
46
|
+
* Maps HTTP 401 to `'unauthorized'`, 404 to `'not_found'`, and all other
|
|
47
|
+
* status codes to `'unknown'`.
|
|
48
|
+
*
|
|
49
|
+
* @param response - The failing HTTP response.
|
|
50
|
+
* @param options - Standard `ErrorOptions` (e.g., `cause`).
|
|
51
|
+
* @returns A typed `WidgetConfigLoadError`.
|
|
52
|
+
*/
|
|
9
53
|
static fromHttpResponse(response: Response, options?: ErrorOptions): WidgetConfigLoadError;
|
|
54
|
+
/**
|
|
55
|
+
* @param type - Error category discriminator.
|
|
56
|
+
* @param message - Human-readable error description.
|
|
57
|
+
* @param options - Standard `ErrorOptions` (e.g., `cause`).
|
|
58
|
+
*/
|
|
10
59
|
constructor(type: WidgetErrorType, message?: string, options?: ErrorOptions);
|
|
11
60
|
}
|
|
61
|
+
/**
|
|
62
|
+
* Error thrown when a widget script module cannot be dynamically imported.
|
|
63
|
+
*/
|
|
12
64
|
export declare class WidgetScriptModuleError extends Error {
|
|
13
65
|
readonly type: WidgetErrorType;
|
|
66
|
+
/**
|
|
67
|
+
* @param type - Error category discriminator.
|
|
68
|
+
* @param message - Human-readable error description.
|
|
69
|
+
* @param options - Standard `ErrorOptions` (e.g., `cause`).
|
|
70
|
+
*/
|
|
14
71
|
constructor(type: WidgetErrorType, message?: string, options?: ErrorOptions);
|
|
15
72
|
}
|
|
16
73
|
export {};
|
package/dist/types/events.d.ts
CHANGED
|
@@ -1,54 +1,74 @@
|
|
|
1
1
|
import type { FrameworkEvent, FrameworkEventInit } from '@equinor/fusion-framework-module-event';
|
|
2
2
|
import type { Widget } from './Widget';
|
|
3
3
|
import type { WidgetConfig, WidgetManifest, WidgetModulesInstance, WidgetScriptModule } from './types';
|
|
4
|
-
/**
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
4
|
+
/**
|
|
5
|
+
* Base event-init shape for all widget lifecycle events.
|
|
6
|
+
*
|
|
7
|
+
* Extends `FrameworkEventInit` with a mandatory `name` field identifying
|
|
8
|
+
* the widget, and sets the event `source` to the originating {@link Widget}
|
|
9
|
+
* instance.
|
|
10
|
+
*
|
|
11
|
+
* @template TDetail - Additional detail properties merged with `{ name: string }`.
|
|
12
|
+
*/
|
|
13
|
+
export type WidgetEventInit<TDetail extends Record<string, unknown> | unknown = unknown> = FrameworkEventInit<TDetail & {
|
|
8
14
|
name: string;
|
|
9
|
-
},
|
|
10
|
-
/**
|
|
11
|
-
|
|
15
|
+
}, Widget>;
|
|
16
|
+
/**
|
|
17
|
+
* Concrete framework-event type for widget lifecycle events.
|
|
18
|
+
*
|
|
19
|
+
* @template TDetail - Additional detail properties.
|
|
20
|
+
*/
|
|
12
21
|
export type WidgetEvent<TDetail extends Record<string, unknown> | unknown = unknown> = FrameworkEvent<WidgetEventInit<TDetail>>;
|
|
22
|
+
/**
|
|
23
|
+
* Framework-event type for widget lifecycle failure events.
|
|
24
|
+
*
|
|
25
|
+
* Carries an `error` property in the event detail for error inspection.
|
|
26
|
+
*/
|
|
13
27
|
export type WidgetEventFailure = FrameworkEvent<WidgetEventInit<{
|
|
14
28
|
error: WidgetConfig;
|
|
15
29
|
}>>;
|
|
16
30
|
declare module '@equinor/fusion-framework-module-event' {
|
|
17
31
|
interface FrameworkEventMap {
|
|
18
|
-
/**
|
|
32
|
+
/** Fired when a widget has finished initializing its framework modules. */
|
|
19
33
|
onWidgetModulesLoaded: WidgetEvent<{
|
|
20
|
-
/**
|
|
34
|
+
/** The initialized module instances. */
|
|
21
35
|
modules: WidgetModulesInstance;
|
|
22
36
|
}>;
|
|
37
|
+
/** Fired when a widget manifest fetch starts. */
|
|
23
38
|
onWidgetManifestLoad: WidgetEvent;
|
|
24
|
-
/**
|
|
39
|
+
/** Fired when a widget manifest has been successfully loaded. */
|
|
25
40
|
onWidgetManifestLoaded: WidgetEvent<{
|
|
26
41
|
manifest: WidgetManifest;
|
|
27
42
|
}>;
|
|
43
|
+
/** Fired when a widget manifest fetch fails. */
|
|
28
44
|
onWidgetManifestFailure: WidgetEventFailure;
|
|
45
|
+
/** Fired when a widget config fetch starts. */
|
|
29
46
|
onWidgetConfigLoad: WidgetEvent;
|
|
30
|
-
/**
|
|
47
|
+
/** Fired when a widget config has been successfully loaded. */
|
|
31
48
|
onWidgetConfigLoaded: WidgetEvent<{
|
|
32
49
|
config: WidgetConfig;
|
|
33
50
|
}>;
|
|
51
|
+
/** Fired when a widget config fetch fails. */
|
|
34
52
|
onWidgetConfigFailure: WidgetEventFailure;
|
|
35
|
-
/**
|
|
53
|
+
/** Fired when a widget script import starts. */
|
|
36
54
|
onAWidgetScriptLoad: WidgetEvent;
|
|
55
|
+
/** Fired when a widget script has been successfully imported. */
|
|
37
56
|
onWidgetScriptLoaded: WidgetEvent<{
|
|
38
57
|
script: WidgetScriptModule;
|
|
39
58
|
}>;
|
|
59
|
+
/** Fired when a widget script import fails. */
|
|
40
60
|
onWidgetScriptFailure: WidgetEventFailure;
|
|
41
|
-
/**
|
|
61
|
+
/** Fired before the widget begins loading manifest, config, and script. */
|
|
42
62
|
onWidgetInitialize: WidgetEvent;
|
|
43
63
|
/**
|
|
44
|
-
*
|
|
64
|
+
* Fired after the widget has loaded manifest, config, and script.
|
|
45
65
|
*
|
|
46
|
-
*
|
|
66
|
+
* Not emitted until all loaders have settled (last emission).
|
|
47
67
|
*/
|
|
48
68
|
onWidgetInitialized: WidgetEvent;
|
|
49
|
-
/**
|
|
69
|
+
/** Fired when the widget fails to load manifest, config, or script. */
|
|
50
70
|
onWidgetInitializeFailure: WidgetEventFailure;
|
|
51
|
-
/**
|
|
71
|
+
/** Fired when the widget is disposed (unmounted from the DOM). */
|
|
52
72
|
onWidgetDispose: FrameworkEvent<WidgetEventInit>;
|
|
53
73
|
}
|
|
54
74
|
}
|
package/dist/types/index.d.ts
CHANGED
|
@@ -1,6 +1,15 @@
|
|
|
1
|
-
|
|
1
|
+
/**
|
|
2
|
+
* Fusion Framework Widget Module
|
|
3
|
+
*
|
|
4
|
+
* Provides runtime loading, configuration, and lifecycle management for
|
|
5
|
+
* remote widget micro-frontends. Widgets are dynamically fetched, imported,
|
|
6
|
+
* and mounted into a host application.
|
|
7
|
+
*
|
|
8
|
+
* @packageDocumentation
|
|
9
|
+
*/
|
|
10
|
+
export { WidgetModuleConfigurator, type WidgetModuleConfig } from './WidgetModuleConfigurator';
|
|
2
11
|
export { WidgetModuleProvider } from './WidgetModuleProvider';
|
|
3
12
|
export type { IWidgetModuleProvider } from './WidgetModuleProvider';
|
|
4
13
|
export * from './types';
|
|
5
14
|
export { enableWidgetModule } from './enable-widget-module';
|
|
6
|
-
export { default, WidgetModule, module, moduleKey } from './module';
|
|
15
|
+
export { default, type WidgetModule, module, moduleKey } from './module';
|
package/dist/types/module.d.ts
CHANGED
|
@@ -2,10 +2,31 @@ import type { Module } from '@equinor/fusion-framework-module';
|
|
|
2
2
|
import type { ModuleDeps } from './types';
|
|
3
3
|
import { WidgetModuleConfigurator } from './WidgetModuleConfigurator';
|
|
4
4
|
import { type IWidgetModuleProvider } from './WidgetModuleProvider';
|
|
5
|
+
/** Module registration key used in the Fusion Framework module map. */
|
|
5
6
|
export declare const moduleKey = "widget";
|
|
7
|
+
/**
|
|
8
|
+
* Module type definition binding the `'widget'` key to the
|
|
9
|
+
* {@link IWidgetModuleProvider} instance, {@link WidgetModuleConfigurator}
|
|
10
|
+
* configuration builder, and required {@link ModuleDeps}.
|
|
11
|
+
*/
|
|
6
12
|
export type WidgetModule = Module<typeof moduleKey, IWidgetModuleProvider, WidgetModuleConfigurator, ModuleDeps>;
|
|
13
|
+
/**
|
|
14
|
+
* Widget module descriptor.
|
|
15
|
+
*
|
|
16
|
+
* Defines how the widget module is configured, initialized, and disposed
|
|
17
|
+
* within the Fusion Framework module system.
|
|
18
|
+
*
|
|
19
|
+
* - `configure` — creates a fresh {@link WidgetModuleConfigurator}
|
|
20
|
+
* - `initialize` — resolves the config, optionally acquires the event module,
|
|
21
|
+
* and returns a {@link WidgetModuleProvider}
|
|
22
|
+
* - `dispose` — cleans up provider subscriptions
|
|
23
|
+
*/
|
|
7
24
|
export declare const module: WidgetModule;
|
|
8
25
|
export default module;
|
|
26
|
+
/**
|
|
27
|
+
* Augments the global Fusion Framework `Modules` interface so that
|
|
28
|
+
* `modules.widget` is typed as {@link WidgetModule}.
|
|
29
|
+
*/
|
|
9
30
|
declare module '@equinor/fusion-framework-module' {
|
|
10
31
|
interface Modules {
|
|
11
32
|
[moduleKey]: WidgetModule;
|