@equinor/fusion-framework-module-app 2.2.0 → 2.3.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 +6 -0
- package/dist/esm/AppConfigBuilder.js +57 -0
- package/dist/esm/AppConfigBuilder.js.map +1 -0
- package/dist/esm/AppConfigurator.js +82 -0
- package/dist/esm/AppConfigurator.js.map +1 -0
- package/dist/esm/AppModuleProvider.js +3 -3
- package/dist/esm/AppModuleProvider.js.map +1 -1
- package/dist/esm/index.js +1 -1
- package/dist/esm/index.js.map +1 -1
- package/dist/esm/module.js +1 -1
- package/dist/esm/module.js.map +1 -1
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/dist/types/AppConfigBuilder.d.ts +26 -0
- package/dist/types/AppConfigurator.d.ts +28 -0
- package/dist/types/AppModuleProvider.d.ts +1 -1
- package/dist/types/index.d.ts +1 -1
- package/dist/types/module.d.ts +2 -2
- package/package.json +2 -2
- package/src/AppConfigBuilder.ts +86 -0
- package/src/AppConfigurator.ts +101 -0
- package/src/AppModuleProvider.ts +4 -4
- package/src/index.ts +2 -1
- package/src/module.ts +3 -8
- package/dist/esm/configurator.js +0 -62
- package/dist/esm/configurator.js.map +0 -1
- package/dist/types/configurator.d.ts +0 -24
- 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,7 @@ 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 './
|
|
7
|
+
import { AppModuleConfig } from './AppConfigurator';
|
|
8
8
|
export declare class AppModuleProvider {
|
|
9
9
|
#private;
|
|
10
10
|
static compareAppManifest<T extends AppManifest>(a?: T, b?: T): boolean;
|
package/dist/types/index.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
export { AppConfigurator, IAppConfigurator, AppModuleConfig as IAppModuleConfig, } from './
|
|
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';
|
package/dist/types/module.d.ts
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
import { IModulesConfigurator, Module } from '@equinor/fusion-framework-module';
|
|
2
2
|
import { ModuleDeps } from './types';
|
|
3
|
-
import { IAppConfigurator } from './
|
|
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
|
|
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.
|
|
3
|
+
"version": "2.3.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": "
|
|
44
|
+
"gitHead": "4bc7a862d19921fc8801e5238d7013b8ece12917"
|
|
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
|
+
}
|
package/src/AppModuleProvider.ts
CHANGED
|
@@ -18,7 +18,7 @@ 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 './
|
|
21
|
+
import { AppModuleConfig } from './AppConfigurator';
|
|
22
22
|
import { HttpResponseError } from '@equinor/fusion-framework-module-http';
|
|
23
23
|
import { AppConfigError, AppManifestError } from './errors';
|
|
24
24
|
|
|
@@ -57,9 +57,9 @@ export class AppModuleProvider {
|
|
|
57
57
|
|
|
58
58
|
this.#current$ = new BehaviorSubject<App | undefined>(undefined);
|
|
59
59
|
|
|
60
|
-
this.appClient = new Query(config.getAppManifest);
|
|
61
|
-
this.#appsClient = new Query(config.getAppManifests);
|
|
62
|
-
this.#configClient = new Query(config.getAppConfig);
|
|
60
|
+
this.appClient = new Query(config.client.getAppManifest);
|
|
61
|
+
this.#appsClient = new Query(config.client.getAppManifests);
|
|
62
|
+
this.#configClient = new Query(config.client.getAppConfig);
|
|
63
63
|
|
|
64
64
|
this.#subscription.add(() => this.appClient.complete());
|
|
65
65
|
this.#subscription.add(() => this.#appsClient.complete());
|
package/src/index.ts
CHANGED
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 './
|
|
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
|
},
|
package/dist/esm/configurator.js
DELETED
|
@@ -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
|
-
}
|
package/src/configurator.ts
DELETED
|
@@ -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
|
-
}
|