@equinor/fusion-framework-module-app 5.2.13 → 5.2.14

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/src/app/flows.ts CHANGED
@@ -8,20 +8,35 @@ import type { AppModuleProvider } from '../AppModuleProvider';
8
8
  import type { Actions } from './actions';
9
9
  import type { AppBundleState } from './types';
10
10
 
11
+ /**
12
+ * Handles the fetch manifest action by fetching the app manifest from the provider,
13
+ * dispatching success or failure actions based on the result.
14
+ *
15
+ * @param provider The AppModuleProvider used to fetch the app manifest.
16
+ * @returns A Flow function that takes an Observable of actions and returns an Observable of actions.
17
+ */
11
18
  export const handleFetchManifest =
12
19
  (provider: AppModuleProvider): Flow<Actions, AppBundleState> =>
13
20
  (action$) =>
14
21
  action$.pipe(
22
+ // only handle fetch manifest request actions
15
23
  filter(actions.fetchManifest.match),
24
+ // when request is received, abort any ongoing request and start new
16
25
  switchMap((action) => {
17
26
  const {
18
27
  payload: appKey,
19
28
  meta: { update },
20
29
  } = action;
30
+
31
+ // fetch manifest from provider
21
32
  const subject = from(provider.getAppManifest(appKey)).pipe(
33
+ // filter out null values
22
34
  filter((x) => !!x),
35
+ // allow multiple subscriptions
23
36
  share(),
24
37
  );
38
+
39
+ // first load manifest and then dispatch success action
25
40
  return concat(
26
41
  subject.pipe(map((manifest) => actions.setManifest(manifest, update))),
27
42
  subject.pipe(
@@ -29,6 +44,7 @@ export const handleFetchManifest =
29
44
  map((manifest) => actions.fetchManifest.success(manifest)),
30
45
  ),
31
46
  ).pipe(
47
+ // catch any error and dispatch failure action
32
48
  catchError((err) => {
33
49
  return of(actions.fetchManifest.failure(err));
34
50
  }),
@@ -36,16 +52,29 @@ export const handleFetchManifest =
36
52
  }),
37
53
  );
38
54
 
55
+ /**
56
+ * Handles the fetch config action by fetching the app configuration from the provider,
57
+ * filtering out null values, and dispatching success or failure actions accordingly.
58
+ *
59
+ * @param provider The AppModuleProvider used to fetch the app configuration.
60
+ * @returns A Flow function that takes an Observable of actions and returns an Observable of actions.
61
+ */
39
62
  export const handleFetchConfig =
40
63
  (provider: AppModuleProvider): Flow<Actions, AppBundleState> =>
41
64
  (action$) =>
42
65
  action$.pipe(
66
+ // only handle fetch config request actions
43
67
  filter(actions.fetchConfig.match),
68
+ // when request is received, abort any ongoing request and start new
44
69
  switchMap(({ payload: appKey }) => {
70
+ // fetch manifest from provider
45
71
  const subject = from(provider.getAppConfig(appKey)).pipe(
72
+ // filter out null values
46
73
  filter((x) => !!x),
74
+ // allow multiple subscriptions
47
75
  share(),
48
76
  );
77
+ // first load manifest and then dispatch success action
49
78
  return concat(
50
79
  subject.pipe(map((manifest) => actions.setConfig(manifest))),
51
80
  subject.pipe(
@@ -53,6 +82,7 @@ export const handleFetchConfig =
53
82
  map((manifest) => actions.fetchConfig.success(manifest)),
54
83
  ),
55
84
  ).pipe(
85
+ // catch any error and dispatch failure action
56
86
  catchError((err) => {
57
87
  return of(actions.fetchConfig.failure(err));
58
88
  }),
@@ -60,12 +90,21 @@ export const handleFetchConfig =
60
90
  }),
61
91
  );
62
92
 
93
+ /**
94
+ * Handles the import application flow.
95
+ * @returns A flow that takes in actions and returns an observable of AppBundleState.
96
+ */
63
97
  export const handleImportApplication = (): Flow<Actions, AppBundleState> => (action$) =>
64
98
  action$.pipe(
99
+ // only handle import script request actions
65
100
  filter(actions.importApp.match),
101
+ // when request is received, abort any ongoing request and start new
66
102
  switchMap(({ payload }) => {
103
+ // dynamically import the application script
67
104
  return from(import(payload)).pipe(
105
+ // dispatch success action
68
106
  map(actions.importApp.success),
107
+ // catch any error and dispatch failure action
69
108
  catchError((err) => of(actions.importApp.failure(err))),
70
109
  );
71
110
  }),
package/src/errors.ts CHANGED
@@ -1,6 +1,15 @@
1
1
  type AppErrorType = 'not_found' | 'unauthorized' | 'unknown';
2
2
 
3
+ /**
4
+ * Represents an error that occurs when loading an application manifest.
5
+ */
3
6
  export class AppManifestError extends Error {
7
+ /**
8
+ * Creates an instance of AppManifestError based on the HTTP response status.
9
+ * @param response The HTTP response.
10
+ * @param options Optional error options.
11
+ * @returns An instance of AppManifestError.
12
+ */
4
13
  static fromHttpResponse(response: Response, options?: ErrorOptions) {
5
14
  switch (response.status) {
6
15
  case 401:
@@ -18,6 +27,13 @@ export class AppManifestError extends Error {
18
27
  options,
19
28
  );
20
29
  }
30
+
31
+ /**
32
+ * Creates an instance of AppManifestError.
33
+ * @param type The type of the error.
34
+ * @param message The error message.
35
+ * @param options Optional error options.
36
+ */
21
37
  constructor(
22
38
  public readonly type: AppErrorType,
23
39
  message?: string,
@@ -27,8 +43,17 @@ export class AppManifestError extends Error {
27
43
  }
28
44
  }
29
45
 
46
+ /**
47
+ * Represents an error that occurs in the application configuration.
48
+ */
30
49
  export class AppConfigError extends Error {
31
- static fromHttpResponse(response: Response, options?: ErrorOptions) {
50
+ /**
51
+ * Creates an instance of `AppConfigError` based on the HTTP response status.
52
+ * @param response The HTTP response.
53
+ * @param options Additional error options.
54
+ * @returns An instance of `AppConfigError` based on the HTTP response status.
55
+ */
56
+ static fromHttpResponse(response: Response, options?: ErrorOptions): AppConfigError {
32
57
  switch (response.status) {
33
58
  case 401:
34
59
  return new AppConfigError(
@@ -45,6 +70,13 @@ export class AppConfigError extends Error {
45
70
  options,
46
71
  );
47
72
  }
73
+
74
+ /**
75
+ * Creates an instance of `AppConfigError`.
76
+ * @param type The type of the application error.
77
+ * @param message The error message.
78
+ * @param options Additional error options.
79
+ */
48
80
  constructor(
49
81
  public readonly type: AppErrorType,
50
82
  message?: string,
@@ -54,7 +86,16 @@ export class AppConfigError extends Error {
54
86
  }
55
87
  }
56
88
 
89
+ /**
90
+ * Represents an error that occurs when loading the application script.
91
+ */
57
92
  export class AppScriptModuleError extends Error {
93
+ /**
94
+ * Creates a new instance of the AppScriptModuleError class.
95
+ * @param type The type of the error.
96
+ * @param message The error message.
97
+ * @param options Additional options for the error.
98
+ */
58
99
  constructor(
59
100
  public readonly type: AppErrorType,
60
101
  message?: string,
package/src/helpers.ts CHANGED
@@ -1,4 +1,17 @@
1
1
  import { AppManifest } from './types';
2
2
 
3
- export const compareAppManifest = <T extends AppManifest>(a?: T, b?: T): boolean =>
4
- JSON.stringify(a) === JSON.stringify(b);
3
+ // manifest properties to compare
4
+ const compareKey: Array<keyof AppManifest> = ['key', 'version'];
5
+
6
+ /**
7
+ * Compares two app manifests for equality.
8
+ *
9
+ * @template T - The type of the app manifest.
10
+ * @param a - The first app manifest.
11
+ * @param b - The second app manifest.
12
+ * @returns True if the app manifests are equal, false otherwise.
13
+ */
14
+ export const compareAppManifest = <T extends AppManifest>(a?: T, b?: T): boolean => {
15
+ // use compareKey to compare only the keys that are important for equality
16
+ return compareKey.every((key) => a?.[key] === b?.[key]);
17
+ };
package/src/module.ts CHANGED
@@ -8,14 +8,35 @@ export const moduleKey = 'app';
8
8
 
9
9
  export type AppModule = Module<typeof moduleKey, AppModuleProvider, IAppConfigurator, ModuleDeps>;
10
10
 
11
+ /**
12
+ * Represents a module for handling applications.
13
+ * Responsible for loading applications, configurations and manifests.
14
+ * @public
15
+ */
11
16
  export const module: AppModule = {
17
+ /**
18
+ * The name of the module.
19
+ */
12
20
  name: moduleKey,
21
+ /**
22
+ * Configures the module.
23
+ * @returns An instance of AppConfigurator.
24
+ */
13
25
  configure: () => new AppConfigurator(),
26
+ /**
27
+ * Initializes the module.
28
+ * @param args - The initialization arguments.
29
+ * @returns A new instance of AppModuleProvider.
30
+ */
14
31
  initialize: async (args) => {
15
32
  const config = await (args.config as AppConfigurator).createConfig(args);
16
33
  const event = await args.requireInstance('event').catch(() => undefined);
17
34
  return new AppModuleProvider({ config, event });
18
35
  },
36
+ /**
37
+ * Disposes the module.
38
+ * @param args - The disposal arguments.
39
+ */
19
40
  dispose: (args) => {
20
41
  (args.instance as unknown as AppModuleProvider).dispose();
21
42
  },
package/src/version.ts CHANGED
@@ -1,2 +1,2 @@
1
1
  // Generated by genversion.
2
- export const version = '5.2.13';
2
+ export const version = '5.2.14';