@equinor/fusion-framework-module-widget 16.0.2 → 16.0.3
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 +43 -0
- package/dist/esm/Widget.js +13 -2
- package/dist/esm/Widget.js.map +1 -1
- package/dist/esm/WidgetManifestLoadError.js +42 -0
- package/dist/esm/WidgetManifestLoadError.js.map +1 -0
- package/dist/esm/WidgetModuleConfigurator.js +2 -0
- package/dist/esm/WidgetModuleConfigurator.js.map +1 -1
- package/dist/esm/WidgetModuleProvider.js +12 -3
- package/dist/esm/WidgetModuleProvider.js.map +1 -1
- package/dist/esm/enable-widget-module.js +1 -1
- package/dist/esm/enable-widget-module.js.map +1 -1
- package/dist/esm/errors/WidgetConfigLoadError.js +40 -0
- package/dist/esm/errors/WidgetConfigLoadError.js.map +1 -0
- package/dist/esm/errors/WidgetScriptModuleError.js +17 -0
- package/dist/esm/errors/WidgetScriptModuleError.js.map +1 -0
- package/dist/esm/module.js +2 -0
- package/dist/esm/module.js.map +1 -1
- package/dist/esm/state/actions.js +1 -1
- package/dist/esm/state/actions.js.map +1 -1
- package/dist/esm/state/create-reducer.js +5 -1
- package/dist/esm/state/create-reducer.js.map +1 -1
- package/dist/esm/state/flows.js +32 -7
- package/dist/esm/state/flows.js.map +1 -1
- package/dist/esm/utils.js +6 -1
- 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 +5 -1
- package/dist/types/WidgetManifestLoadError.d.ts +36 -0
- package/dist/types/WidgetModuleProvider.d.ts +2 -0
- package/dist/types/errors/WidgetConfigLoadError.d.ts +27 -0
- package/dist/types/errors/WidgetScriptModuleError.d.ts +13 -0
- package/dist/types/state/actions.d.ts +8 -8
- package/dist/types/state/create-reducer.d.ts +36 -36
- package/dist/types/version.d.ts +1 -1
- package/package.json +13 -13
- package/src/Widget.ts +13 -2
- package/src/WidgetManifestLoadError.ts +61 -0
- package/src/WidgetModuleConfigurator.ts +2 -0
- package/src/WidgetModuleProvider.ts +8 -1
- package/src/enable-widget-module.ts +1 -1
- package/src/errors/WidgetConfigLoadError.ts +51 -0
- package/src/errors/WidgetScriptModuleError.ts +20 -0
- package/src/module.ts +2 -0
- package/src/state/actions.ts +1 -1
- package/src/state/create-reducer.ts +3 -0
- package/src/state/flows.ts +47 -21
- package/src/types.ts +2 -2
- package/src/utils.ts +6 -1
- package/src/version.ts +1 -1
- package/dist/esm/errors.js +0 -93
- package/dist/esm/errors.js.map +0 -1
- package/dist/types/errors.d.ts +0 -73
- package/src/errors.ts +0 -125
package/src/state/flows.ts
CHANGED
|
@@ -20,6 +20,7 @@ import type WidgetModuleProvider from '../WidgetModuleProvider';
|
|
|
20
20
|
export const handleFetchManifest =
|
|
21
21
|
(provider: WidgetModuleProvider): Flow<Actions, WidgetState> =>
|
|
22
22
|
(action$) =>
|
|
23
|
+
// React only to `fetchManifest` actions
|
|
23
24
|
action$.pipe(
|
|
24
25
|
filter(actions.fetchManifest.match),
|
|
25
26
|
switchMap((action) => {
|
|
@@ -28,21 +29,30 @@ export const handleFetchManifest =
|
|
|
28
29
|
meta: { update },
|
|
29
30
|
} = action;
|
|
30
31
|
|
|
32
|
+
// Query the provider for the manifest, dropping falsy emissions, and share it
|
|
31
33
|
const subject = from(provider.getWidgetManifest(key, args)).pipe(
|
|
32
34
|
filter((x) => !!x),
|
|
33
35
|
share(),
|
|
34
36
|
);
|
|
35
|
-
return
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
37
|
+
return (
|
|
38
|
+
concat(
|
|
39
|
+
subject
|
|
40
|
+
// Emit an intermediate `setManifest` for every value the query produces
|
|
41
|
+
.pipe(map((manifest) => actions.setManifest(manifest, update))),
|
|
42
|
+
subject
|
|
43
|
+
// Wait for the final emission and report it as the successful result
|
|
44
|
+
.pipe(
|
|
45
|
+
last(),
|
|
46
|
+
map((manifest) => actions.fetchManifest.success(manifest)),
|
|
47
|
+
),
|
|
48
|
+
)
|
|
49
|
+
// Convert any error from the query/emission chain into a failure action
|
|
50
|
+
.pipe(
|
|
51
|
+
catchError((err) => {
|
|
52
|
+
console.error(err, action.payload);
|
|
53
|
+
return of(actions.fetchManifest.failure(err));
|
|
54
|
+
}),
|
|
55
|
+
)
|
|
46
56
|
);
|
|
47
57
|
}),
|
|
48
58
|
);
|
|
@@ -55,26 +65,38 @@ export const handleFetchManifest =
|
|
|
55
65
|
* @param provider - The widget module provider used for API queries.
|
|
56
66
|
* @returns A `Flow` function for the widget state machine.
|
|
57
67
|
*/
|
|
68
|
+
// Deliberately co-located with `handleFetchManifest` above
|
|
69
|
+
// fusion-lint-disable-next-line single-export-per-file
|
|
58
70
|
export const handleFetchConfig =
|
|
59
71
|
(provider: WidgetModuleProvider): Flow<Actions, WidgetState> =>
|
|
60
72
|
(action$) =>
|
|
73
|
+
// React only to `fetchConfig` actions
|
|
61
74
|
action$.pipe(
|
|
62
75
|
filter(actions.fetchConfig.match),
|
|
63
76
|
switchMap(({ payload: { key, args } }) => {
|
|
77
|
+
// Query the provider for the config, dropping falsy emissions, and share it
|
|
64
78
|
const subject = from(provider.getWidgetConfig(key, args)).pipe(
|
|
65
79
|
filter((x) => !!x),
|
|
66
80
|
share(),
|
|
67
81
|
);
|
|
68
|
-
return
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
82
|
+
return (
|
|
83
|
+
concat(
|
|
84
|
+
subject
|
|
85
|
+
// Emit an intermediate `setConfig` for every value the query produces
|
|
86
|
+
.pipe(map((manifest) => actions.setConfig(manifest))),
|
|
87
|
+
subject
|
|
88
|
+
// Wait for the final emission and report it as the successful result
|
|
89
|
+
.pipe(
|
|
90
|
+
last(),
|
|
91
|
+
map((manifest) => actions.fetchConfig.success(manifest)),
|
|
92
|
+
),
|
|
93
|
+
)
|
|
94
|
+
// Convert any error from the query/emission chain into a failure action
|
|
95
|
+
.pipe(
|
|
96
|
+
catchError((err) => {
|
|
97
|
+
return of(actions.fetchConfig.failure(err));
|
|
98
|
+
}),
|
|
99
|
+
)
|
|
78
100
|
);
|
|
79
101
|
}),
|
|
80
102
|
);
|
|
@@ -85,10 +107,14 @@ export const handleFetchConfig =
|
|
|
85
107
|
*
|
|
86
108
|
* @returns A `Flow` function for the widget state machine.
|
|
87
109
|
*/
|
|
110
|
+
// Deliberately co-located with the other flow handlers above
|
|
111
|
+
// fusion-lint-disable-next-line single-export-per-file
|
|
88
112
|
export const handleImportWidget = (): Flow<Actions, WidgetState> => (action$) =>
|
|
113
|
+
// React only to `importWidget` actions
|
|
89
114
|
action$.pipe(
|
|
90
115
|
filter(actions.importWidget.match),
|
|
91
116
|
switchMap(({ payload }) => {
|
|
117
|
+
// Dynamically import the widget's script entry point and report success/failure
|
|
92
118
|
return from(import(/* @vite-ignore */ payload)).pipe(
|
|
93
119
|
map(actions.importWidget.success),
|
|
94
120
|
catchError((err) => of(actions.importWidget.failure(err))),
|
package/src/types.ts
CHANGED
|
@@ -4,7 +4,7 @@ import type { HttpModule } from '@equinor/fusion-framework-module-http';
|
|
|
4
4
|
import type { ServiceDiscoveryModule } from '@equinor/fusion-framework-module-service-discovery';
|
|
5
5
|
import type { QueryCtorOptions } from '@equinor/fusion-query';
|
|
6
6
|
|
|
7
|
-
//
|
|
7
|
+
// biome-ignore lint/suspicious/noExplicitAny: `Fusion` is a placeholder widening type for the framework instance shape used across widget script modules
|
|
8
8
|
type Fusion = any;
|
|
9
9
|
|
|
10
10
|
/**
|
|
@@ -178,7 +178,7 @@ export type WidgetModulesInstance<TModules extends Array<AnyModule> | unknown =
|
|
|
178
178
|
*
|
|
179
179
|
* @template TModules - Custom module types.
|
|
180
180
|
*/
|
|
181
|
-
//
|
|
181
|
+
// biome-ignore lint/suspicious/noExplicitAny: default must be bivariant `any`, not `unknown` — `unknown` breaks assignability when a concrete `WidgetState<TModules>` is used where the default-typed generic is expected
|
|
182
182
|
export type WidgetState<TModules = any> = {
|
|
183
183
|
/** Widget name (lookup key). */
|
|
184
184
|
name: string;
|
package/src/utils.ts
CHANGED
|
@@ -15,6 +15,7 @@ export const defaultManifestEndpointBuilder =
|
|
|
15
15
|
(params: GetWidgetParameters) => {
|
|
16
16
|
const { widgetKey, args } = params;
|
|
17
17
|
const { type, value } = args ?? {};
|
|
18
|
+
// Route versioned/tagged lookups differently from the unversioned default
|
|
18
19
|
switch (type) {
|
|
19
20
|
case 'tag':
|
|
20
21
|
case 'version':
|
|
@@ -33,12 +34,14 @@ export const defaultManifestEndpointBuilder =
|
|
|
33
34
|
* @param apiVersion - API version string appended as a query parameter.
|
|
34
35
|
* @returns A function that maps {@link GetWidgetParameters} to a URL path.
|
|
35
36
|
*/
|
|
37
|
+
// Deliberately co-located with `defaultManifestEndpointBuilder` above
|
|
38
|
+
// fusion-lint-disable-next-line single-export-per-file
|
|
36
39
|
export const defaultConfigEndpointBuilder =
|
|
37
40
|
(apiVersion: string): WidgetEndpointBuilder =>
|
|
38
41
|
(params: GetWidgetParameters) => {
|
|
39
42
|
const { widgetKey, args } = params;
|
|
40
43
|
const { type, value } = args ?? {};
|
|
41
|
-
//
|
|
44
|
+
// TODO(#5099): Align endpoints with backend when its done!
|
|
42
45
|
switch (type) {
|
|
43
46
|
case 'tag':
|
|
44
47
|
case 'version':
|
|
@@ -59,6 +62,8 @@ export const defaultConfigEndpointBuilder =
|
|
|
59
62
|
* `apps` service-discovery key).
|
|
60
63
|
* @returns A fully configured `IClient`.
|
|
61
64
|
*/
|
|
65
|
+
// Deliberately co-located with the endpoint builders it composes
|
|
66
|
+
// fusion-lint-disable-next-line single-export-per-file
|
|
62
67
|
export const createDefaultClient = (httpClient: IHttpClient): IClient => {
|
|
63
68
|
const apiVersion = '1.0-preview';
|
|
64
69
|
return {
|
package/src/version.ts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
// Generated by genversion.
|
|
2
|
-
export const version = '16.0.
|
|
2
|
+
export const version = '16.0.3';
|
package/dist/esm/errors.js
DELETED
|
@@ -1,93 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Error thrown when a widget manifest cannot be loaded from the backend API.
|
|
3
|
-
*
|
|
4
|
-
* Use the static {@link fromHttpResponse} factory to create instances from
|
|
5
|
-
* HTTP responses with appropriate type mapping.
|
|
6
|
-
*/
|
|
7
|
-
export class WidgetManifestLoadError extends Error {
|
|
8
|
-
type;
|
|
9
|
-
/**
|
|
10
|
-
* Creates a `WidgetManifestLoadError` from an HTTP `Response`.
|
|
11
|
-
*
|
|
12
|
-
* Maps HTTP 401 to `'unauthorized'`, 404 to `'not_found'`, and all other
|
|
13
|
-
* status codes to `'unknown'`.
|
|
14
|
-
*
|
|
15
|
-
* @param response - The failing HTTP response.
|
|
16
|
-
* @param options - Standard `ErrorOptions` (e.g., `cause`).
|
|
17
|
-
* @returns A typed `WidgetManifestLoadError`.
|
|
18
|
-
*/
|
|
19
|
-
static fromHttpResponse(response, options) {
|
|
20
|
-
switch (response.status) {
|
|
21
|
-
case 401:
|
|
22
|
-
return new WidgetManifestLoadError('unauthorized', 'failed to load widget manifest, request not authorized', options);
|
|
23
|
-
case 404:
|
|
24
|
-
return new WidgetManifestLoadError('not_found', 'widget manifest not found', options);
|
|
25
|
-
}
|
|
26
|
-
return new WidgetManifestLoadError('unknown', `failed to load widget manifest, status code ${response.status}`, options);
|
|
27
|
-
}
|
|
28
|
-
/**
|
|
29
|
-
* @param type - Error category discriminator.
|
|
30
|
-
* @param message - Human-readable error description.
|
|
31
|
-
* @param options - Standard `ErrorOptions` (e.g., `cause`).
|
|
32
|
-
*/
|
|
33
|
-
constructor(type, message, options) {
|
|
34
|
-
super(message, options);
|
|
35
|
-
this.type = type;
|
|
36
|
-
this.name = 'GetWidgetLoadManifestErrors';
|
|
37
|
-
}
|
|
38
|
-
}
|
|
39
|
-
/**
|
|
40
|
-
* Error thrown when a widget configuration cannot be loaded from the backend API.
|
|
41
|
-
*
|
|
42
|
-
* Use the static {@link fromHttpResponse} factory to create instances from
|
|
43
|
-
* HTTP responses with appropriate type mapping.
|
|
44
|
-
*/
|
|
45
|
-
export class WidgetConfigLoadError extends Error {
|
|
46
|
-
type;
|
|
47
|
-
/**
|
|
48
|
-
* Creates a `WidgetConfigLoadError` from an HTTP `Response`.
|
|
49
|
-
*
|
|
50
|
-
* Maps HTTP 401 to `'unauthorized'`, 404 to `'not_found'`, and all other
|
|
51
|
-
* status codes to `'unknown'`.
|
|
52
|
-
*
|
|
53
|
-
* @param response - The failing HTTP response.
|
|
54
|
-
* @param options - Standard `ErrorOptions` (e.g., `cause`).
|
|
55
|
-
* @returns A typed `WidgetConfigLoadError`.
|
|
56
|
-
*/
|
|
57
|
-
static fromHttpResponse(response, options) {
|
|
58
|
-
switch (response.status) {
|
|
59
|
-
case 401:
|
|
60
|
-
return new WidgetConfigLoadError('unauthorized', 'failed to load widget config, request not authorized', options);
|
|
61
|
-
case 404:
|
|
62
|
-
return new WidgetConfigLoadError('not_found', 'widget config not found', options);
|
|
63
|
-
}
|
|
64
|
-
return new WidgetConfigLoadError('unknown', `failed to load widget config, status code ${response.status}`, options);
|
|
65
|
-
}
|
|
66
|
-
/**
|
|
67
|
-
* @param type - Error category discriminator.
|
|
68
|
-
* @param message - Human-readable error description.
|
|
69
|
-
* @param options - Standard `ErrorOptions` (e.g., `cause`).
|
|
70
|
-
*/
|
|
71
|
-
constructor(type, message, options) {
|
|
72
|
-
super(message, options);
|
|
73
|
-
this.type = type;
|
|
74
|
-
this.name = 'GetWidgetLoadConfigError';
|
|
75
|
-
}
|
|
76
|
-
}
|
|
77
|
-
/**
|
|
78
|
-
* Error thrown when a widget script module cannot be dynamically imported.
|
|
79
|
-
*/
|
|
80
|
-
export class WidgetScriptModuleError extends Error {
|
|
81
|
-
type;
|
|
82
|
-
/**
|
|
83
|
-
* @param type - Error category discriminator.
|
|
84
|
-
* @param message - Human-readable error description.
|
|
85
|
-
* @param options - Standard `ErrorOptions` (e.g., `cause`).
|
|
86
|
-
*/
|
|
87
|
-
constructor(type, message, options) {
|
|
88
|
-
super(message, options);
|
|
89
|
-
this.type = type;
|
|
90
|
-
this.name = 'WidgetScriptModuleError';
|
|
91
|
-
}
|
|
92
|
-
}
|
|
93
|
-
//# sourceMappingURL=errors.js.map
|
package/dist/esm/errors.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"errors.js","sourceRoot":"","sources":["../../src/errors.ts"],"names":[],"mappings":"AASA;;;;;GAKG;AACH,MAAM,OAAO,uBAAwB,SAAQ,KAAK;IAkC9B;IAjClB;;;;;;;;;OASG;IACH,MAAM,CAAC,gBAAgB,CAAC,QAAkB,EAAE,OAAsB;QAChE,QAAQ,QAAQ,CAAC,MAAM,EAAE,CAAC;YACxB,KAAK,GAAG;gBACN,OAAO,IAAI,uBAAuB,CAChC,cAAc,EACd,wDAAwD,EACxD,OAAO,CACR,CAAC;YACJ,KAAK,GAAG;gBACN,OAAO,IAAI,uBAAuB,CAAC,WAAW,EAAE,2BAA2B,EAAE,OAAO,CAAC,CAAC;QAC1F,CAAC;QACD,OAAO,IAAI,uBAAuB,CAChC,SAAS,EACT,+CAA+C,QAAQ,CAAC,MAAM,EAAE,EAChE,OAAO,CACR,CAAC;IACJ,CAAC;IACD;;;;OAIG;IACH,YACkB,IAAqB,EACrC,OAAgB,EAChB,OAAsB;QAEtB,KAAK,CAAC,OAAO,EAAE,OAAO,CAAC,CAAC;QAJR,SAAI,GAAJ,IAAI,CAAiB;QAKrC,IAAI,CAAC,IAAI,GAAG,6BAA6B,CAAC;IAC5C,CAAC;CACF;AAED;;;;;GAKG;AACH,MAAM,OAAO,qBAAsB,SAAQ,KAAK;IAkC5B;IAjClB;;;;;;;;;OASG;IACH,MAAM,CAAC,gBAAgB,CAAC,QAAkB,EAAE,OAAsB;QAChE,QAAQ,QAAQ,CAAC,MAAM,EAAE,CAAC;YACxB,KAAK,GAAG;gBACN,OAAO,IAAI,qBAAqB,CAC9B,cAAc,EACd,sDAAsD,EACtD,OAAO,CACR,CAAC;YACJ,KAAK,GAAG;gBACN,OAAO,IAAI,qBAAqB,CAAC,WAAW,EAAE,yBAAyB,EAAE,OAAO,CAAC,CAAC;QACtF,CAAC;QACD,OAAO,IAAI,qBAAqB,CAC9B,SAAS,EACT,6CAA6C,QAAQ,CAAC,MAAM,EAAE,EAC9D,OAAO,CACR,CAAC;IACJ,CAAC;IACD;;;;OAIG;IACH,YACkB,IAAqB,EACrC,OAAgB,EAChB,OAAsB;QAEtB,KAAK,CAAC,OAAO,EAAE,OAAO,CAAC,CAAC;QAJR,SAAI,GAAJ,IAAI,CAAiB;QAKrC,IAAI,CAAC,IAAI,GAAG,0BAA0B,CAAC;IACzC,CAAC;CACF;AAED;;GAEG;AACH,MAAM,OAAO,uBAAwB,SAAQ,KAAK;IAO9B;IANlB;;;;OAIG;IACH,YACkB,IAAqB,EACrC,OAAgB,EAChB,OAAsB;QAEtB,KAAK,CAAC,OAAO,EAAE,OAAO,CAAC,CAAC;QAJR,SAAI,GAAJ,IAAI,CAAiB;QAKrC,IAAI,CAAC,IAAI,GAAG,yBAAyB,CAAC;IACxC,CAAC;CACF"}
|
package/dist/types/errors.d.ts
DELETED
|
@@ -1,73 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Discriminator for categorizing widget HTTP errors.
|
|
3
|
-
*
|
|
4
|
-
* - `'not_found'` — HTTP 404
|
|
5
|
-
* - `'unauthorized'` — HTTP 401
|
|
6
|
-
* - `'unknown'` — any other error
|
|
7
|
-
*/
|
|
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
|
-
*/
|
|
15
|
-
export declare class WidgetManifestLoadError extends Error {
|
|
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
|
-
*/
|
|
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
|
-
*/
|
|
33
|
-
constructor(type: WidgetErrorType, message?: string, options?: ErrorOptions);
|
|
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
|
-
*/
|
|
41
|
-
export declare class WidgetConfigLoadError extends Error {
|
|
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
|
-
*/
|
|
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
|
-
*/
|
|
59
|
-
constructor(type: WidgetErrorType, message?: string, options?: ErrorOptions);
|
|
60
|
-
}
|
|
61
|
-
/**
|
|
62
|
-
* Error thrown when a widget script module cannot be dynamically imported.
|
|
63
|
-
*/
|
|
64
|
-
export declare class WidgetScriptModuleError extends Error {
|
|
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
|
-
*/
|
|
71
|
-
constructor(type: WidgetErrorType, message?: string, options?: ErrorOptions);
|
|
72
|
-
}
|
|
73
|
-
export {};
|
package/src/errors.ts
DELETED
|
@@ -1,125 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Discriminator for categorizing widget HTTP errors.
|
|
3
|
-
*
|
|
4
|
-
* - `'not_found'` — HTTP 404
|
|
5
|
-
* - `'unauthorized'` — HTTP 401
|
|
6
|
-
* - `'unknown'` — any other error
|
|
7
|
-
*/
|
|
8
|
-
type WidgetErrorType = 'not_found' | 'unauthorized' | 'unknown';
|
|
9
|
-
|
|
10
|
-
/**
|
|
11
|
-
* Error thrown when a widget manifest cannot be loaded from the backend API.
|
|
12
|
-
*
|
|
13
|
-
* Use the static {@link fromHttpResponse} factory to create instances from
|
|
14
|
-
* HTTP responses with appropriate type mapping.
|
|
15
|
-
*/
|
|
16
|
-
export class WidgetManifestLoadError extends Error {
|
|
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
|
-
*/
|
|
27
|
-
static fromHttpResponse(response: Response, options?: ErrorOptions) {
|
|
28
|
-
switch (response.status) {
|
|
29
|
-
case 401:
|
|
30
|
-
return new WidgetManifestLoadError(
|
|
31
|
-
'unauthorized',
|
|
32
|
-
'failed to load widget manifest, request not authorized',
|
|
33
|
-
options,
|
|
34
|
-
);
|
|
35
|
-
case 404:
|
|
36
|
-
return new WidgetManifestLoadError('not_found', 'widget manifest not found', options);
|
|
37
|
-
}
|
|
38
|
-
return new WidgetManifestLoadError(
|
|
39
|
-
'unknown',
|
|
40
|
-
`failed to load widget manifest, status code ${response.status}`,
|
|
41
|
-
options,
|
|
42
|
-
);
|
|
43
|
-
}
|
|
44
|
-
/**
|
|
45
|
-
* @param type - Error category discriminator.
|
|
46
|
-
* @param message - Human-readable error description.
|
|
47
|
-
* @param options - Standard `ErrorOptions` (e.g., `cause`).
|
|
48
|
-
*/
|
|
49
|
-
constructor(
|
|
50
|
-
public readonly type: WidgetErrorType,
|
|
51
|
-
message?: string,
|
|
52
|
-
options?: ErrorOptions,
|
|
53
|
-
) {
|
|
54
|
-
super(message, options);
|
|
55
|
-
this.name = 'GetWidgetLoadManifestErrors';
|
|
56
|
-
}
|
|
57
|
-
}
|
|
58
|
-
|
|
59
|
-
/**
|
|
60
|
-
* Error thrown when a widget configuration cannot be loaded from the backend API.
|
|
61
|
-
*
|
|
62
|
-
* Use the static {@link fromHttpResponse} factory to create instances from
|
|
63
|
-
* HTTP responses with appropriate type mapping.
|
|
64
|
-
*/
|
|
65
|
-
export class WidgetConfigLoadError extends Error {
|
|
66
|
-
/**
|
|
67
|
-
* Creates a `WidgetConfigLoadError` from an HTTP `Response`.
|
|
68
|
-
*
|
|
69
|
-
* Maps HTTP 401 to `'unauthorized'`, 404 to `'not_found'`, and all other
|
|
70
|
-
* status codes to `'unknown'`.
|
|
71
|
-
*
|
|
72
|
-
* @param response - The failing HTTP response.
|
|
73
|
-
* @param options - Standard `ErrorOptions` (e.g., `cause`).
|
|
74
|
-
* @returns A typed `WidgetConfigLoadError`.
|
|
75
|
-
*/
|
|
76
|
-
static fromHttpResponse(response: Response, options?: ErrorOptions) {
|
|
77
|
-
switch (response.status) {
|
|
78
|
-
case 401:
|
|
79
|
-
return new WidgetConfigLoadError(
|
|
80
|
-
'unauthorized',
|
|
81
|
-
'failed to load widget config, request not authorized',
|
|
82
|
-
options,
|
|
83
|
-
);
|
|
84
|
-
case 404:
|
|
85
|
-
return new WidgetConfigLoadError('not_found', 'widget config not found', options);
|
|
86
|
-
}
|
|
87
|
-
return new WidgetConfigLoadError(
|
|
88
|
-
'unknown',
|
|
89
|
-
`failed to load widget config, status code ${response.status}`,
|
|
90
|
-
options,
|
|
91
|
-
);
|
|
92
|
-
}
|
|
93
|
-
/**
|
|
94
|
-
* @param type - Error category discriminator.
|
|
95
|
-
* @param message - Human-readable error description.
|
|
96
|
-
* @param options - Standard `ErrorOptions` (e.g., `cause`).
|
|
97
|
-
*/
|
|
98
|
-
constructor(
|
|
99
|
-
public readonly type: WidgetErrorType,
|
|
100
|
-
message?: string,
|
|
101
|
-
options?: ErrorOptions,
|
|
102
|
-
) {
|
|
103
|
-
super(message, options);
|
|
104
|
-
this.name = 'GetWidgetLoadConfigError';
|
|
105
|
-
}
|
|
106
|
-
}
|
|
107
|
-
|
|
108
|
-
/**
|
|
109
|
-
* Error thrown when a widget script module cannot be dynamically imported.
|
|
110
|
-
*/
|
|
111
|
-
export class WidgetScriptModuleError extends Error {
|
|
112
|
-
/**
|
|
113
|
-
* @param type - Error category discriminator.
|
|
114
|
-
* @param message - Human-readable error description.
|
|
115
|
-
* @param options - Standard `ErrorOptions` (e.g., `cause`).
|
|
116
|
-
*/
|
|
117
|
-
constructor(
|
|
118
|
-
public readonly type: WidgetErrorType,
|
|
119
|
-
message?: string,
|
|
120
|
-
options?: ErrorOptions,
|
|
121
|
-
) {
|
|
122
|
-
super(message, options);
|
|
123
|
-
this.name = 'WidgetScriptModuleError';
|
|
124
|
-
}
|
|
125
|
-
}
|