@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
@@ -1,81 +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 { moduleKey } from './module';
5
- import type { AppConfig, AppManifest, ModuleDeps } from './types';
6
-
7
- export interface AppModuleConfig {
8
- getAppManifest: QueryCtorOptions<AppManifest, { appKey: string }>;
9
- // TODO: add filter
10
- getAppManifests: QueryCtorOptions<AppManifest[], void>;
11
- getAppConfig: QueryCtorOptions<AppConfig, { appKey: string; tag?: string }>;
12
- }
13
-
14
- export interface IAppConfigurator<TDeps extends Array<AnyModule>> {
15
- createConfig: (
16
- args: ModuleInitializerArgs<IAppConfigurator<TDeps>, TDeps>
17
- ) => Promise<AppModuleConfig>;
18
- processConfig: (config: AppModuleConfig) => AppModuleConfig;
19
- }
20
-
21
- export class AppConfigurator<TDeps extends ModuleDeps = ModuleDeps>
22
- implements IAppConfigurator<TDeps>
23
- {
24
- defaultExpireTime = 1 * 60 * 1000;
25
-
26
- /**
27
- * WARNING: this function will be remove in future
28
- */
29
- protected async _createHttpClient(
30
- init: ModuleInitializerArgs<IAppConfigurator<TDeps>, TDeps>
31
- ): Promise<IHttpClient> {
32
- const http = await init.requireInstance('http');
33
- /** check if the http provider has configure a client */
34
- if (http.hasClient(moduleKey)) {
35
- return http.createClient(moduleKey);
36
- } else {
37
- /** load service discovery module */
38
- const serviceDiscovery = await init.requireInstance('serviceDiscovery');
39
-
40
- // TODO - remove when refactor portal service!
41
- /** resolve and create a client from discovery */
42
- try {
43
- return await serviceDiscovery.createClient('app');
44
- } catch {
45
- return await serviceDiscovery.createClient('portal');
46
- }
47
- }
48
- }
49
-
50
- public async createConfig(
51
- args: ModuleInitializerArgs<IAppConfigurator<TDeps>, TDeps>
52
- ): Promise<AppModuleConfig> {
53
- const httpClient = await this._createHttpClient(args);
54
- const config: AppModuleConfig = {
55
- getAppManifest: {
56
- client: {
57
- fn: ({ appKey }) => httpClient.json$<AppManifest>(`/api/apps/${appKey}`),
58
- },
59
- key: ({ appKey }) => appKey,
60
- },
61
- getAppManifests: {
62
- client: {
63
- fn: () => httpClient.json$(`/api/apps`),
64
- },
65
- key: () => 'apps',
66
- },
67
- getAppConfig: {
68
- client: {
69
- fn: ({ appKey, tag }) =>
70
- httpClient.json$(`/api/apps/${appKey}/config${tag ? `?tag=${tag}` : ''}`),
71
- },
72
- key: (args) => JSON.stringify(args),
73
- },
74
- };
75
- return this.processConfig(config);
76
- }
77
-
78
- public processConfig(config: AppModuleConfig): AppModuleConfig {
79
- return config;
80
- }
81
- }