@equinor/fusion-framework-module-app 2.2.0 → 2.4.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.
Files changed (41) hide show
  1. package/CHANGELOG.md +12 -0
  2. package/dist/esm/AppConfigBuilder.js +57 -0
  3. package/dist/esm/AppConfigBuilder.js.map +1 -0
  4. package/dist/esm/AppConfigurator.js +82 -0
  5. package/dist/esm/AppConfigurator.js.map +1 -0
  6. package/dist/esm/AppModuleProvider.js +9 -5
  7. package/dist/esm/AppModuleProvider.js.map +1 -1
  8. package/dist/esm/app/App.js +3 -2
  9. package/dist/esm/app/App.js.map +1 -1
  10. package/dist/esm/app/create-reducer.js +1 -1
  11. package/dist/esm/app/create-reducer.js.map +1 -1
  12. package/dist/esm/app/create-state.js +2 -2
  13. package/dist/esm/app/create-state.js.map +1 -1
  14. package/dist/esm/index.js +1 -1
  15. package/dist/esm/index.js.map +1 -1
  16. package/dist/esm/module.js +1 -1
  17. package/dist/esm/module.js.map +1 -1
  18. package/dist/tsconfig.tsbuildinfo +1 -1
  19. package/dist/types/AppConfigBuilder.d.ts +26 -0
  20. package/dist/types/AppConfigurator.d.ts +28 -0
  21. package/dist/types/AppModuleProvider.d.ts +4 -2
  22. package/dist/types/app/App.d.ts +2 -1
  23. package/dist/types/app/create-reducer.d.ts +2 -2
  24. package/dist/types/app/create-state.d.ts +2 -2
  25. package/dist/types/app/types.d.ts +1 -0
  26. package/dist/types/index.d.ts +1 -1
  27. package/dist/types/module.d.ts +2 -2
  28. package/package.json +2 -2
  29. package/src/AppConfigBuilder.ts +86 -0
  30. package/src/AppConfigurator.ts +101 -0
  31. package/src/AppModuleProvider.ts +15 -6
  32. package/src/app/App.ts +9 -4
  33. package/src/app/create-reducer.ts +3 -3
  34. package/src/app/create-state.ts +4 -4
  35. package/src/app/types.ts +5 -0
  36. package/src/index.ts +2 -1
  37. package/src/module.ts +3 -8
  38. package/dist/esm/configurator.js +0 -62
  39. package/dist/esm/configurator.js.map +0 -1
  40. package/dist/types/configurator.d.ts +0 -24
  41. package/src/configurator.ts +0 -81
@@ -0,0 +1,26 @@
1
+ import { ModuleInitializerArgs, Modules, ModuleType } from '@equinor/fusion-framework-module';
2
+ import { QueryFn, QueryCtorOptions } from '@equinor/fusion-query';
3
+ import { AppModuleConfig, IAppConfigurator } from './AppConfigurator';
4
+ import type { AppConfig, AppManifest, ModuleDeps } from './types';
5
+ export type AppConfigBuilderCallback = (builder: AppConfigBuilder<ModuleInitializerArgs<IAppConfigurator, any>>) => void | Promise<void>;
6
+ export declare class AppConfigBuilder<TInit extends ModuleInitializerArgs<IAppConfigurator, any> = ModuleInitializerArgs<IAppConfigurator, ModuleDeps>> {
7
+ #private;
8
+ config: Partial<AppModuleConfig>;
9
+ constructor(init: TInit, config?: Partial<AppModuleConfig>);
10
+ requireInstance<TKey extends string = Extract<keyof Modules, string>>(module: TKey): Promise<ModuleType<Modules[TKey]>>;
11
+ requireInstance<T>(module: string): Promise<T>;
12
+ setAppClient(client: {
13
+ getAppManifest: QueryFn<AppManifest, {
14
+ appKey: string;
15
+ }> | QueryCtorOptions<AppManifest, {
16
+ appKey: string;
17
+ }>;
18
+ getAppManifests: QueryFn<AppManifest[], void> | QueryCtorOptions<AppManifest[], void>;
19
+ getAppConfig: QueryFn<AppConfig, {
20
+ appKey: string;
21
+ }> | QueryCtorOptions<AppConfig, {
22
+ appKey: string;
23
+ tag?: string;
24
+ }>;
25
+ }, expire?: number): void;
26
+ }
@@ -0,0 +1,28 @@
1
+ import { ModuleInitializerArgs } from '@equinor/fusion-framework-module';
2
+ import { HttpModule, IHttpClient } from '@equinor/fusion-framework-module-http';
3
+ import { ServiceDiscoveryModule } from '@equinor/fusion-framework-module-service-discovery';
4
+ import { QueryCtorOptions } from '@equinor/fusion-query';
5
+ import { AppConfigBuilderCallback } from './AppConfigBuilder';
6
+ import type { AppConfig, AppManifest } from './types';
7
+ export interface AppModuleConfig {
8
+ client: {
9
+ getAppManifest: QueryCtorOptions<AppManifest, {
10
+ appKey: string;
11
+ }>;
12
+ getAppManifests: QueryCtorOptions<AppManifest[], void>;
13
+ getAppConfig: QueryCtorOptions<AppConfig, {
14
+ appKey: string;
15
+ tag?: string;
16
+ }>;
17
+ };
18
+ }
19
+ export interface IAppConfigurator {
20
+ addConfigBuilder: (init: AppConfigBuilderCallback) => void;
21
+ }
22
+ export declare class AppConfigurator implements IAppConfigurator {
23
+ #private;
24
+ defaultExpireTime: number;
25
+ addConfigBuilder(init: AppConfigBuilderCallback): void;
26
+ protected _createHttpClient(init: ModuleInitializerArgs<IAppConfigurator, [HttpModule, ServiceDiscoveryModule]>): Promise<IHttpClient>;
27
+ createConfig(init: ModuleInitializerArgs<IAppConfigurator, [HttpModule, ServiceDiscoveryModule]>): Promise<AppModuleConfig>;
28
+ }
@@ -4,7 +4,8 @@ import { Query } from '@equinor/fusion-query';
4
4
  import { EventModule } from '@equinor/fusion-framework-module-event';
5
5
  import type { AppConfig, AppManifest } from './types';
6
6
  import { App } from './app/App';
7
- import { AppModuleConfig } from './configurator';
7
+ import { AppModuleConfig } from './AppConfigurator';
8
+ import { AppBundleStateInitial } from 'app/types';
8
9
  export declare class AppModuleProvider {
9
10
  #private;
10
11
  static compareAppManifest<T extends AppManifest>(a?: T, b?: T): boolean;
@@ -20,7 +21,8 @@ export declare class AppModuleProvider {
20
21
  getAppManifest(appKey: string): Observable<AppManifest>;
21
22
  getAllAppManifests(): Observable<AppManifest[]>;
22
23
  getAppConfig<TType = unknown>(appKey: string, tag?: string): Observable<AppConfig<TType>>;
23
- setCurrentApp(appKey: string): void;
24
+ setCurrentApp(appKeyOrApp: string | App): void;
25
+ createApp(value: AppBundleStateInitial): App;
24
26
  dispose(): void;
25
27
  }
26
28
  export default AppModuleProvider;
@@ -4,6 +4,7 @@ import type { AppModuleProvider } from '../AppModuleProvider';
4
4
  import { OperatorFunction } from 'rxjs';
5
5
  import { EventModule } from '@equinor/fusion-framework-module-event';
6
6
  import { AnyModule, ModuleType } from '@equinor/fusion-framework-module';
7
+ import { AppBundleStateInitial } from './types';
7
8
  import '../events';
8
9
  export declare function filterEmpty<T>(): OperatorFunction<T | null | undefined, T>;
9
10
  export declare class App<TEnv = any, TModules extends Array<AnyModule> | unknown = unknown> {
@@ -16,7 +17,7 @@ export declare class App<TEnv = any, TModules extends Array<AnyModule> | unknown
16
17
  get manifest(): Promise<AppManifest>;
17
18
  get config(): Promise<AppConfig<TEnv>>;
18
19
  get instance(): AppModulesInstance<TModules> | undefined;
19
- constructor(appKey: string, args: {
20
+ constructor(value: AppBundleStateInitial, args: {
20
21
  provider: AppModuleProvider;
21
22
  event?: ModuleType<EventModule>;
22
23
  });
@@ -1,3 +1,3 @@
1
- import { AppBundleState } from './types';
2
- export declare const createReducer: (appKey: string) => import("@equinor/fusion-observable").ReducerWithInitialState<AppBundleState<any, any>, import("@equinor/fusion-observable").AnyAction>;
1
+ import { AppBundleState, AppBundleStateInitial } from './types';
2
+ export declare const createReducer: (value: AppBundleStateInitial) => import("@equinor/fusion-observable").ReducerWithInitialState<AppBundleState<any, any>, import("@equinor/fusion-observable").AnyAction>;
3
3
  export default createReducer;
@@ -1,5 +1,5 @@
1
1
  import { FlowSubject } from '@equinor/fusion-observable';
2
2
  import type { Actions } from './actions';
3
- import type { AppBundleState } from './types';
3
+ import type { AppBundleState, AppBundleStateInitial } from './types';
4
4
  import type { AppModuleProvider } from '../AppModuleProvider';
5
- export declare const createState: (appKey: string, provider: AppModuleProvider) => FlowSubject<AppBundleState, Actions>;
5
+ export declare const createState: (value: AppBundleStateInitial, provider: AppModuleProvider) => FlowSubject<AppBundleState, Actions>;
@@ -7,3 +7,4 @@ export type AppBundleState<TConfig = any, TModules = any> = {
7
7
  modules?: AppScriptModule;
8
8
  instance?: AppModulesInstance<TModules>;
9
9
  };
10
+ export type AppBundleStateInitial<TConfig = any, TModules = any> = Omit<AppBundleState<TConfig, TModules>, 'status'>;
@@ -1,4 +1,4 @@
1
- export { AppConfigurator, IAppConfigurator, AppModuleConfig as IAppModuleConfig, } from './configurator';
1
+ export { AppModuleConfig, AppConfigurator, IAppConfigurator, AppModuleConfig as IAppModuleConfig, } from './AppConfigurator';
2
2
  export { AppModuleProvider } from './AppModuleProvider';
3
3
  export { App } from './app/App';
4
4
  export * from './events';
@@ -1,9 +1,9 @@
1
1
  import { IModulesConfigurator, Module } from '@equinor/fusion-framework-module';
2
2
  import { ModuleDeps } from './types';
3
- import { IAppConfigurator } from './configurator';
3
+ import { IAppConfigurator } from './AppConfigurator';
4
4
  import { AppModuleProvider } from './AppModuleProvider';
5
5
  export declare const moduleKey = "app";
6
- export type AppModule = Module<typeof moduleKey, AppModuleProvider, IAppConfigurator<ModuleDeps>, ModuleDeps>;
6
+ export type AppModule = Module<typeof moduleKey, AppModuleProvider, IAppConfigurator, ModuleDeps>;
7
7
  export declare const module: AppModule;
8
8
  export declare const enableAppModule: (configurator: IModulesConfigurator) => void;
9
9
  export default module;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@equinor/fusion-framework-module-app",
3
- "version": "2.2.0",
3
+ "version": "2.4.0",
4
4
  "description": "",
5
5
  "main": "dist/esm/index.js",
6
6
  "exports": {
@@ -41,5 +41,5 @@
41
41
  "@equinor/fusion-framework-module-service-discovery": "^4.0.7",
42
42
  "typescript": "^4.9.3"
43
43
  },
44
- "gitHead": "acfc1533fae1e5a95f8463cc2d6e3a2ad94c252e"
44
+ "gitHead": "a37a5380c885ba37e6462429f4ebc501aee64bb9"
45
45
  }
@@ -0,0 +1,86 @@
1
+ import { ModuleInitializerArgs, Modules, ModuleType } from '@equinor/fusion-framework-module';
2
+ import { QueryFn, QueryCtorOptions } from '@equinor/fusion-query';
3
+
4
+ import { AppModuleConfig, IAppConfigurator } from './AppConfigurator';
5
+
6
+ import type { AppConfig, AppManifest, ModuleDeps } from './types';
7
+
8
+ export type AppConfigBuilderCallback = (
9
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
10
+ builder: AppConfigBuilder<ModuleInitializerArgs<IAppConfigurator, any>>
11
+ ) => void | Promise<void>;
12
+
13
+ export class AppConfigBuilder<
14
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
15
+ TInit extends ModuleInitializerArgs<IAppConfigurator, any> = ModuleInitializerArgs<
16
+ IAppConfigurator,
17
+ ModuleDeps
18
+ >
19
+ > {
20
+ #init: TInit;
21
+ constructor(init: TInit, public config: Partial<AppModuleConfig> = {}) {
22
+ this.#init = init;
23
+ }
24
+
25
+ requireInstance<TKey extends string = Extract<keyof Modules, string>>(
26
+ module: TKey
27
+ ): Promise<ModuleType<Modules[TKey]>>;
28
+
29
+ requireInstance<T>(module: string): Promise<T>;
30
+
31
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
32
+ requireInstance(module: string): Promise<any> {
33
+ return this.#init.requireInstance(module);
34
+ }
35
+
36
+ setAppClient(
37
+ client: {
38
+ getAppManifest:
39
+ | QueryFn<AppManifest, { appKey: string }>
40
+ | QueryCtorOptions<AppManifest, { appKey: string }>;
41
+ getAppManifests: QueryFn<AppManifest[], void> | QueryCtorOptions<AppManifest[], void>;
42
+ getAppConfig:
43
+ | QueryFn<AppConfig, { appKey: string }>
44
+ | QueryCtorOptions<AppConfig, { appKey: string; tag?: string }>;
45
+ },
46
+ expire = 1 * 60 * 1000
47
+ ) {
48
+ client;
49
+ expire;
50
+
51
+ this.config.client = {
52
+ getAppManifest:
53
+ typeof client.getAppManifest === 'function'
54
+ ? {
55
+ key: ({ appKey }) => appKey,
56
+ client: {
57
+ fn: client.getAppManifest,
58
+ },
59
+ expire,
60
+ }
61
+ : client.getAppManifest,
62
+ getAppManifests:
63
+ typeof client.getAppManifests === 'function'
64
+ ? {
65
+ // TODO - might cast to checksum
66
+ key: () => 'app_manifests',
67
+ client: {
68
+ fn: client.getAppManifests,
69
+ },
70
+ expire,
71
+ }
72
+ : client.getAppManifests,
73
+ getAppConfig:
74
+ typeof client.getAppConfig === 'function'
75
+ ? {
76
+ // TODO - might cast to checksum
77
+ key: (args) => JSON.stringify(args),
78
+ client: {
79
+ fn: client.getAppConfig,
80
+ },
81
+ expire,
82
+ }
83
+ : client.getAppConfig,
84
+ };
85
+ }
86
+ }
@@ -0,0 +1,101 @@
1
+ import { ModuleInitializerArgs } from '@equinor/fusion-framework-module';
2
+ import { HttpModule, IHttpClient } from '@equinor/fusion-framework-module-http';
3
+ import { ServiceDiscoveryModule } from '@equinor/fusion-framework-module-service-discovery';
4
+ import { QueryCtorOptions } from '@equinor/fusion-query';
5
+
6
+ import { AppConfigBuilder, AppConfigBuilderCallback } from './AppConfigBuilder';
7
+
8
+ import { moduleKey } from './module';
9
+
10
+ import type { AppConfig, AppManifest } from './types';
11
+
12
+ export interface AppModuleConfig {
13
+ client: {
14
+ getAppManifest: QueryCtorOptions<AppManifest, { appKey: string }>;
15
+ getAppManifests: QueryCtorOptions<AppManifest[], void>;
16
+ getAppConfig: QueryCtorOptions<AppConfig, { appKey: string; tag?: string }>;
17
+ };
18
+ }
19
+
20
+ export interface IAppConfigurator {
21
+ addConfigBuilder: (init: AppConfigBuilderCallback) => void;
22
+ }
23
+
24
+ export class AppConfigurator implements IAppConfigurator {
25
+ defaultExpireTime = 1 * 60 * 1000;
26
+
27
+ #configBuilders: Array<AppConfigBuilderCallback> = [];
28
+
29
+ addConfigBuilder(init: AppConfigBuilderCallback): void {
30
+ this.#configBuilders.push(init);
31
+ }
32
+
33
+ /**
34
+ * WARNING: this function will be remove in future
35
+ */
36
+ protected async _createHttpClient(
37
+ init: ModuleInitializerArgs<IAppConfigurator, [HttpModule, ServiceDiscoveryModule]>
38
+ ): Promise<IHttpClient> {
39
+ const http = await init.requireInstance('http');
40
+ /** check if the http provider has configure a client */
41
+ if (http.hasClient(moduleKey)) {
42
+ return http.createClient(moduleKey);
43
+ } else {
44
+ /** load service discovery module */
45
+ const serviceDiscovery = await init.requireInstance('serviceDiscovery');
46
+
47
+ // TODO - remove when refactor portal service!
48
+ /** resolve and create a client from discovery */
49
+ try {
50
+ return await serviceDiscovery.createClient('app');
51
+ } catch {
52
+ return await serviceDiscovery.createClient('portal');
53
+ }
54
+ }
55
+ }
56
+
57
+ public async createConfig(
58
+ init: ModuleInitializerArgs<IAppConfigurator, [HttpModule, ServiceDiscoveryModule]>
59
+ ): Promise<AppModuleConfig> {
60
+ const config = await this.#configBuilders.reduce(async (cur, cb) => {
61
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
62
+ const builder = new AppConfigBuilder(init, await cur);
63
+ await Promise.resolve(cb(builder));
64
+ return Object.assign(cur, builder.config);
65
+ }, Promise.resolve({} as Partial<AppModuleConfig>));
66
+
67
+ // TODO - make less lazy
68
+ config.client ??= await (async (): Promise<AppModuleConfig['client']> => {
69
+ const httpClient = await this._createHttpClient(init);
70
+ return {
71
+ getAppManifest: {
72
+ client: {
73
+ fn: ({ appKey }) => httpClient.json$<AppManifest>(`/api/apps/${appKey}`),
74
+ },
75
+ key: ({ appKey }) => appKey,
76
+ expire: this.defaultExpireTime,
77
+ },
78
+ getAppManifests: {
79
+ client: {
80
+ fn: () => httpClient.json$(`/api/apps`),
81
+ },
82
+ // TODO - might cast to checksum
83
+ key: (args) => JSON.stringify(args),
84
+ expire: this.defaultExpireTime,
85
+ },
86
+ getAppConfig: {
87
+ client: {
88
+ fn: ({ appKey, tag }) =>
89
+ httpClient.json$(
90
+ `/api/apps/${appKey}/config${tag ? `?tag=${tag}` : ''}`
91
+ ),
92
+ },
93
+ key: (args) => JSON.stringify(args),
94
+ expire: this.defaultExpireTime,
95
+ },
96
+ };
97
+ })();
98
+
99
+ return config as AppModuleConfig;
100
+ }
101
+ }
@@ -18,9 +18,10 @@ import { EventModule } from '@equinor/fusion-framework-module-event';
18
18
  import type { AppConfig, AppManifest } from './types';
19
19
 
20
20
  import { App, filterEmpty } from './app/App';
21
- import { AppModuleConfig } from './configurator';
21
+ import { AppModuleConfig } from './AppConfigurator';
22
22
  import { HttpResponseError } from '@equinor/fusion-framework-module-http';
23
23
  import { AppConfigError, AppManifestError } from './errors';
24
+ import { AppBundleStateInitial } from 'app/types';
24
25
 
25
26
  export class AppModuleProvider {
26
27
  static compareAppManifest<T extends AppManifest>(a?: T, b?: T): boolean {
@@ -57,9 +58,9 @@ export class AppModuleProvider {
57
58
 
58
59
  this.#current$ = new BehaviorSubject<App | undefined>(undefined);
59
60
 
60
- this.appClient = new Query(config.getAppManifest);
61
- this.#appsClient = new Query(config.getAppManifests);
62
- this.#configClient = new Query(config.getAppConfig);
61
+ this.appClient = new Query(config.client.getAppManifest);
62
+ this.#appsClient = new Query(config.client.getAppManifests);
63
+ this.#configClient = new Query(config.client.getAppConfig);
63
64
 
64
65
  this.#subscription.add(() => this.appClient.complete());
65
66
  this.#subscription.add(() => this.#appsClient.complete());
@@ -147,8 +148,16 @@ export class AppModuleProvider {
147
148
  * set the current application, will internally resolve manifest
148
149
  * @param appKey - application key
149
150
  */
150
- public setCurrentApp(appKey: string): void {
151
- this.#current$.next(new App(appKey, { provider: this, event: this.#event }));
151
+ public setCurrentApp(appKeyOrApp: string | App): void {
152
+ const app = typeof appKeyOrApp === 'string' ? this.createApp({ appKey: appKeyOrApp }) : App;
153
+ this.#current$.next(app as App);
154
+ }
155
+
156
+ /**
157
+ * This should not be used, only for legacy creation backdoor
158
+ */
159
+ public createApp(value: AppBundleStateInitial): App {
160
+ return new App(value, { provider: this, event: this.#event });
152
161
  }
153
162
 
154
163
  public dispose() {
package/src/app/App.ts CHANGED
@@ -16,7 +16,7 @@ import { EventModule } from '@equinor/fusion-framework-module-event';
16
16
  import { AnyModule, ModuleType } from '@equinor/fusion-framework-module';
17
17
  import { createState } from './create-state';
18
18
  import { actions, Actions } from './actions';
19
- import { AppBundleState } from './types';
19
+ import { AppBundleState, AppBundleStateInitial } from './types';
20
20
 
21
21
  import '../events';
22
22
 
@@ -78,10 +78,15 @@ export class App<TEnv = any, TModules extends Array<AnyModule> | unknown = unkno
78
78
  }
79
79
 
80
80
  constructor(
81
- appKey: string,
82
- args: { provider: AppModuleProvider; event?: ModuleType<EventModule> }
81
+ value: AppBundleStateInitial,
82
+ args: {
83
+ provider: AppModuleProvider;
84
+ event?: ModuleType<EventModule>;
85
+ }
83
86
  ) {
84
- this.#state = createState(appKey, args.provider);
87
+ this.#state = createState(value, args.provider);
88
+
89
+ const { appKey } = value;
85
90
 
86
91
  const subscriptions = new Subscription();
87
92
 
@@ -11,10 +11,10 @@ enableMapSet();
11
11
 
12
12
  import { actions } from './actions';
13
13
 
14
- import { AppBundleState } from './types';
14
+ import { AppBundleState, AppBundleStateInitial } from './types';
15
15
 
16
- export const createReducer = (appKey: string) =>
17
- makeReducer({ appKey, status: new Set() } as AppBundleState, (builder) =>
16
+ export const createReducer = (value: AppBundleStateInitial) =>
17
+ makeReducer({ ...value, status: new Set() } as AppBundleState, (builder) =>
18
18
  builder
19
19
  .addCase(actions.setManifest, (state, action) => {
20
20
  state.manifest = action.payload;
@@ -5,14 +5,14 @@ import { createReducer } from './create-reducer';
5
5
  import { handleFetchManifest, handleFetchConfig, handleImportApplication } from './flows';
6
6
 
7
7
  import type { Actions } from './actions';
8
- import type { AppBundleState } from './types';
8
+ import type { AppBundleState, AppBundleStateInitial } from './types';
9
9
  import type { AppModuleProvider } from '../AppModuleProvider';
10
10
 
11
11
  export const createState = (
12
- appKey: string,
13
- provider: AppModuleProvider
12
+ value: AppBundleStateInitial,
13
+ provider: AppModuleProvider,
14
14
  ): FlowSubject<AppBundleState, Actions> => {
15
- const reducer = createReducer(appKey);
15
+ const reducer = createReducer(value);
16
16
  const state = new FlowSubject<AppBundleState, Actions>(reducer);
17
17
  state.addFlow(handleFetchManifest(provider));
18
18
  state.addFlow(handleFetchConfig(provider));
package/src/app/types.ts CHANGED
@@ -9,3 +9,8 @@ export type AppBundleState<TConfig = any, TModules = any> = {
9
9
  modules?: AppScriptModule;
10
10
  instance?: AppModulesInstance<TModules>;
11
11
  };
12
+
13
+ export type AppBundleStateInitial<TConfig = any, TModules = any> = Omit<
14
+ AppBundleState<TConfig, TModules>,
15
+ 'status'
16
+ >;
package/src/index.ts CHANGED
@@ -1,8 +1,9 @@
1
1
  export {
2
+ AppModuleConfig,
2
3
  AppConfigurator,
3
4
  IAppConfigurator,
4
5
  AppModuleConfig as IAppModuleConfig,
5
- } from './configurator';
6
+ } from './AppConfigurator';
6
7
  export { AppModuleProvider } from './AppModuleProvider';
7
8
 
8
9
  export { App } from './app/App';
package/src/module.ts CHANGED
@@ -1,23 +1,18 @@
1
1
  import { IModulesConfigurator, Module } from '@equinor/fusion-framework-module';
2
2
  import { ModuleDeps } from './types';
3
3
 
4
- import { IAppConfigurator, AppConfigurator } from './configurator';
4
+ import { IAppConfigurator, AppConfigurator } from './AppConfigurator';
5
5
  import { AppModuleProvider } from './AppModuleProvider';
6
6
 
7
7
  export const moduleKey = 'app';
8
8
 
9
- export type AppModule = Module<
10
- typeof moduleKey,
11
- AppModuleProvider,
12
- IAppConfigurator<ModuleDeps>,
13
- ModuleDeps
14
- >;
9
+ export type AppModule = Module<typeof moduleKey, AppModuleProvider, IAppConfigurator, ModuleDeps>;
15
10
 
16
11
  export const module: AppModule = {
17
12
  name: moduleKey,
18
13
  configure: () => new AppConfigurator(),
19
14
  initialize: async (args) => {
20
- const config = await args.config.createConfig(args);
15
+ const config = await (args.config as AppConfigurator).createConfig(args);
21
16
  const event = await args.requireInstance('event').catch(() => undefined);
22
17
  return new AppModuleProvider({ config, event });
23
18
  },
@@ -1,62 +0,0 @@
1
- var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
2
- function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
3
- return new (P || (P = Promise))(function (resolve, reject) {
4
- function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
5
- function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
6
- function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
7
- step((generator = generator.apply(thisArg, _arguments || [])).next());
8
- });
9
- };
10
- import { moduleKey } from './module';
11
- export class AppConfigurator {
12
- constructor() {
13
- this.defaultExpireTime = 1 * 60 * 1000;
14
- }
15
- _createHttpClient(init) {
16
- return __awaiter(this, void 0, void 0, function* () {
17
- const http = yield init.requireInstance('http');
18
- if (http.hasClient(moduleKey)) {
19
- return http.createClient(moduleKey);
20
- }
21
- else {
22
- const serviceDiscovery = yield init.requireInstance('serviceDiscovery');
23
- try {
24
- return yield serviceDiscovery.createClient('app');
25
- }
26
- catch (_a) {
27
- return yield serviceDiscovery.createClient('portal');
28
- }
29
- }
30
- });
31
- }
32
- createConfig(args) {
33
- return __awaiter(this, void 0, void 0, function* () {
34
- const httpClient = yield this._createHttpClient(args);
35
- const config = {
36
- getAppManifest: {
37
- client: {
38
- fn: ({ appKey }) => httpClient.json$(`/api/apps/${appKey}`),
39
- },
40
- key: ({ appKey }) => appKey,
41
- },
42
- getAppManifests: {
43
- client: {
44
- fn: () => httpClient.json$(`/api/apps`),
45
- },
46
- key: () => 'apps',
47
- },
48
- getAppConfig: {
49
- client: {
50
- fn: ({ appKey, tag }) => httpClient.json$(`/api/apps/${appKey}/config${tag ? `?tag=${tag}` : ''}`),
51
- },
52
- key: (args) => JSON.stringify(args),
53
- },
54
- };
55
- return this.processConfig(config);
56
- });
57
- }
58
- processConfig(config) {
59
- return config;
60
- }
61
- }
62
- //# sourceMappingURL=configurator.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"configurator.js","sourceRoot":"","sources":["../../src/configurator.ts"],"names":[],"mappings":";;;;;;;;;AAGA,OAAO,EAAE,SAAS,EAAE,MAAM,UAAU,CAAC;AAiBrC,MAAM,OAAO,eAAe;IAA5B;QAGI,sBAAiB,GAAG,CAAC,GAAG,EAAE,GAAG,IAAI,CAAC;IAyDtC,CAAC;IApDmB,iBAAiB,CAC7B,IAA2D;;YAE3D,MAAM,IAAI,GAAG,MAAM,IAAI,CAAC,eAAe,CAAC,MAAM,CAAC,CAAC;YAEhD,IAAI,IAAI,CAAC,SAAS,CAAC,SAAS,CAAC,EAAE;gBAC3B,OAAO,IAAI,CAAC,YAAY,CAAC,SAAS,CAAC,CAAC;aACvC;iBAAM;gBAEH,MAAM,gBAAgB,GAAG,MAAM,IAAI,CAAC,eAAe,CAAC,kBAAkB,CAAC,CAAC;gBAIxE,IAAI;oBACA,OAAO,MAAM,gBAAgB,CAAC,YAAY,CAAC,KAAK,CAAC,CAAC;iBACrD;gBAAC,WAAM;oBACJ,OAAO,MAAM,gBAAgB,CAAC,YAAY,CAAC,QAAQ,CAAC,CAAC;iBACxD;aACJ;QACL,CAAC;KAAA;IAEY,YAAY,CACrB,IAA2D;;YAE3D,MAAM,UAAU,GAAG,MAAM,IAAI,CAAC,iBAAiB,CAAC,IAAI,CAAC,CAAC;YACtD,MAAM,MAAM,GAAoB;gBAC5B,cAAc,EAAE;oBACZ,MAAM,EAAE;wBACJ,EAAE,EAAE,CAAC,EAAE,MAAM,EAAE,EAAE,EAAE,CAAC,UAAU,CAAC,KAAK,CAAc,aAAa,MAAM,EAAE,CAAC;qBAC3E;oBACD,GAAG,EAAE,CAAC,EAAE,MAAM,EAAE,EAAE,EAAE,CAAC,MAAM;iBAC9B;gBACD,eAAe,EAAE;oBACb,MAAM,EAAE;wBACJ,EAAE,EAAE,GAAG,EAAE,CAAC,UAAU,CAAC,KAAK,CAAC,WAAW,CAAC;qBAC1C;oBACD,GAAG,EAAE,GAAG,EAAE,CAAC,MAAM;iBACpB;gBACD,YAAY,EAAE;oBACV,MAAM,EAAE;wBACJ,EAAE,EAAE,CAAC,EAAE,MAAM,EAAE,GAAG,EAAE,EAAE,EAAE,CACpB,UAAU,CAAC,KAAK,CAAC,aAAa,MAAM,UAAU,GAAG,CAAC,CAAC,CAAC,QAAQ,GAAG,EAAE,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC;qBAChF;oBACD,GAAG,EAAE,CAAC,IAAI,EAAE,EAAE,CAAC,IAAI,CAAC,SAAS,CAAC,IAAI,CAAC;iBACtC;aACJ,CAAC;YACF,OAAO,IAAI,CAAC,aAAa,CAAC,MAAM,CAAC,CAAC;QACtC,CAAC;KAAA;IAEM,aAAa,CAAC,MAAuB;QACxC,OAAO,MAAM,CAAC;IAClB,CAAC;CACJ"}
@@ -1,24 +0,0 @@
1
- import { AnyModule, ModuleInitializerArgs } from '@equinor/fusion-framework-module';
2
- import { IHttpClient } from '@equinor/fusion-framework-module-http';
3
- import { QueryCtorOptions } from '@equinor/fusion-query';
4
- import type { AppConfig, AppManifest, ModuleDeps } from './types';
5
- export interface AppModuleConfig {
6
- getAppManifest: QueryCtorOptions<AppManifest, {
7
- appKey: string;
8
- }>;
9
- getAppManifests: QueryCtorOptions<AppManifest[], void>;
10
- getAppConfig: QueryCtorOptions<AppConfig, {
11
- appKey: string;
12
- tag?: string;
13
- }>;
14
- }
15
- export interface IAppConfigurator<TDeps extends Array<AnyModule>> {
16
- createConfig: (args: ModuleInitializerArgs<IAppConfigurator<TDeps>, TDeps>) => Promise<AppModuleConfig>;
17
- processConfig: (config: AppModuleConfig) => AppModuleConfig;
18
- }
19
- export declare class AppConfigurator<TDeps extends ModuleDeps = ModuleDeps> implements IAppConfigurator<TDeps> {
20
- defaultExpireTime: number;
21
- protected _createHttpClient(init: ModuleInitializerArgs<IAppConfigurator<TDeps>, TDeps>): Promise<IHttpClient>;
22
- createConfig(args: ModuleInitializerArgs<IAppConfigurator<TDeps>, TDeps>): Promise<AppModuleConfig>;
23
- processConfig(config: AppModuleConfig): AppModuleConfig;
24
- }