@equinor/fusion-framework-module-app 2.1.6 → 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 +13 -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 +91 -0
- package/dist/esm/AppModuleProvider.js.map +1 -0
- package/dist/esm/app/App.js +172 -0
- package/dist/esm/app/App.js.map +1 -0
- package/dist/esm/app/actions.js +17 -0
- package/dist/esm/app/actions.js.map +1 -0
- package/dist/esm/app/create-reducer.js +25 -0
- package/dist/esm/app/create-reducer.js.map +1 -0
- package/dist/esm/app/create-state.js +12 -0
- package/dist/esm/app/create-state.js.map +1 -0
- package/dist/esm/app/flows.js +17 -0
- package/dist/esm/app/flows.js.map +1 -0
- package/dist/esm/app/types.js +2 -0
- package/dist/esm/app/types.js.map +1 -0
- package/dist/esm/errors.js +37 -0
- package/dist/esm/errors.js.map +1 -0
- package/dist/esm/events.js +7 -0
- package/dist/esm/events.js.map +1 -0
- package/dist/esm/index.js +4 -2
- package/dist/esm/index.js.map +1 -1
- package/dist/esm/module.js +6 -3
- 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 +26 -0
- package/dist/types/app/App.d.ts +34 -0
- package/dist/types/app/actions.d.ts +46 -0
- package/dist/types/app/create-reducer.d.ts +3 -0
- package/dist/types/app/create-state.d.ts +5 -0
- package/dist/types/app/flows.d.ts +7 -0
- package/dist/types/app/types.d.ts +9 -0
- package/dist/types/errors.d.ts +16 -0
- package/dist/types/events.d.ts +22 -0
- package/dist/types/index.d.ts +4 -2
- package/dist/types/module.d.ts +5 -4
- package/dist/types/types.d.ts +29 -1
- package/package.json +14 -6
- package/src/AppConfigBuilder.ts +86 -0
- package/src/AppConfigurator.ts +101 -0
- package/src/AppModuleProvider.ts +159 -0
- package/src/app/App.ts +243 -0
- package/src/app/actions.ts +51 -0
- package/src/app/create-reducer.ts +41 -0
- package/src/app/create-state.ts +21 -0
- package/src/app/flows.ts +61 -0
- package/src/app/types.ts +11 -0
- package/src/errors.ts +53 -0
- package/src/events.ts +34 -0
- package/src/index.ts +10 -2
- package/src/module.ts +11 -12
- package/src/types.ts +42 -1
- package/dist/esm/configurator.js +0 -62
- package/dist/esm/configurator.js.map +0 -1
- package/dist/esm/provider.js +0 -83
- package/dist/esm/provider.js.map +0 -1
- package/dist/types/configurator.d.ts +0 -24
- package/dist/types/provider.d.ts +0 -43
- package/src/configurator.ts +0 -81
- package/src/provider.ts +0 -181
|
@@ -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
|
+
}
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import { Observable } from 'rxjs';
|
|
2
|
+
import { ModuleType } from '@equinor/fusion-framework-module';
|
|
3
|
+
import { Query } from '@equinor/fusion-query';
|
|
4
|
+
import { EventModule } from '@equinor/fusion-framework-module-event';
|
|
5
|
+
import type { AppConfig, AppManifest } from './types';
|
|
6
|
+
import { App } from './app/App';
|
|
7
|
+
import { AppModuleConfig } from './AppConfigurator';
|
|
8
|
+
export declare class AppModuleProvider {
|
|
9
|
+
#private;
|
|
10
|
+
static compareAppManifest<T extends AppManifest>(a?: T, b?: T): boolean;
|
|
11
|
+
appClient: Query<AppManifest, {
|
|
12
|
+
appKey: string;
|
|
13
|
+
}>;
|
|
14
|
+
get current(): App | undefined;
|
|
15
|
+
get current$(): Observable<App>;
|
|
16
|
+
constructor(args: {
|
|
17
|
+
config: AppModuleConfig;
|
|
18
|
+
event?: ModuleType<EventModule>;
|
|
19
|
+
});
|
|
20
|
+
getAppManifest(appKey: string): Observable<AppManifest>;
|
|
21
|
+
getAllAppManifests(): Observable<AppManifest[]>;
|
|
22
|
+
getAppConfig<TType = unknown>(appKey: string, tag?: string): Observable<AppConfig<TType>>;
|
|
23
|
+
setCurrentApp(appKey: string): void;
|
|
24
|
+
dispose(): void;
|
|
25
|
+
}
|
|
26
|
+
export default AppModuleProvider;
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import { AppConfig, AppManifest, AppModulesInstance, AppScriptModule } from '../types';
|
|
2
|
+
import { Observable } from '@equinor/fusion-observable';
|
|
3
|
+
import type { AppModuleProvider } from '../AppModuleProvider';
|
|
4
|
+
import { OperatorFunction } from 'rxjs';
|
|
5
|
+
import { EventModule } from '@equinor/fusion-framework-module-event';
|
|
6
|
+
import { AnyModule, ModuleType } from '@equinor/fusion-framework-module';
|
|
7
|
+
import '../events';
|
|
8
|
+
export declare function filterEmpty<T>(): OperatorFunction<T | null | undefined, T>;
|
|
9
|
+
export declare class App<TEnv = any, TModules extends Array<AnyModule> | unknown = unknown> {
|
|
10
|
+
#private;
|
|
11
|
+
get manifest$(): Observable<AppManifest>;
|
|
12
|
+
get config$(): Observable<AppConfig<TEnv>>;
|
|
13
|
+
get modules$(): Observable<AppScriptModule>;
|
|
14
|
+
get instance$(): Observable<AppModulesInstance<TModules>>;
|
|
15
|
+
get appKey(): string;
|
|
16
|
+
get manifest(): Promise<AppManifest>;
|
|
17
|
+
get config(): Promise<AppConfig<TEnv>>;
|
|
18
|
+
get instance(): AppModulesInstance<TModules> | undefined;
|
|
19
|
+
constructor(appKey: string, args: {
|
|
20
|
+
provider: AppModuleProvider;
|
|
21
|
+
event?: ModuleType<EventModule>;
|
|
22
|
+
});
|
|
23
|
+
initialize(): Observable<[AppManifest, AppScriptModule, AppConfig]>;
|
|
24
|
+
loadConfig(): void;
|
|
25
|
+
loadManifest(): void;
|
|
26
|
+
loadAppModule(allow_cache?: boolean): Promise<void>;
|
|
27
|
+
getConfig(force_refresh?: boolean): Observable<AppConfig>;
|
|
28
|
+
getConfigAsync(allow_cache?: boolean): Promise<AppConfig>;
|
|
29
|
+
getManifest(force_refresh?: boolean): Observable<AppManifest>;
|
|
30
|
+
getManifestAsync(allow_cache?: boolean): Promise<AppManifest>;
|
|
31
|
+
getAppModule(force_refresh?: boolean): Observable<AppScriptModule>;
|
|
32
|
+
getAppModuleAsync(allow_cache?: boolean): Promise<AppScriptModule>;
|
|
33
|
+
dispose: VoidFunction;
|
|
34
|
+
}
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
import { ActionInstanceMap, ActionTypes } from '@equinor/fusion-observable';
|
|
2
|
+
import { AppConfig, AppManifest, AppModulesInstance, AppScriptModule } from '../types';
|
|
3
|
+
declare const createActions: () => {
|
|
4
|
+
setManifest: import("@equinor/fusion-observable/dist/types/create-action").ActionCreatorWithPreparedPayload<[manifest: AppManifest], AppManifest, "set_manifest", never, {
|
|
5
|
+
created: number;
|
|
6
|
+
}>;
|
|
7
|
+
fetchManifest: import("@equinor/fusion-observable/dist/types/create-action").ActionCreatorWithPreparedPayload<[key: string], string, "fetch_manifest::request", never, never> & {
|
|
8
|
+
success: import("@equinor/fusion-observable/dist/types/create-action").ActionCreatorWithPreparedPayload<[manifest: AppManifest], AppManifest, "fetch_manifest::success", never, never>;
|
|
9
|
+
failure: import("@equinor/fusion-observable/dist/types/create-action").ActionCreatorWithPreparedPayload<[error: unknown], unknown, "fetch_manifest::failure", never, never>;
|
|
10
|
+
};
|
|
11
|
+
setConfig: import("@equinor/fusion-observable/dist/types/create-action").ActionCreatorWithPreparedPayload<[config: AppConfig<unknown>], AppConfig<unknown>, "set_config", never, never>;
|
|
12
|
+
fetchConfig: import("@equinor/fusion-observable/dist/types/create-action").ActionCreatorWithPreparedPayload<[key: string], string, "fetch_config::request", never, never> & {
|
|
13
|
+
success: import("@equinor/fusion-observable/dist/types/create-action").ActionCreatorWithPreparedPayload<[config: AppConfig<unknown>], AppConfig<unknown>, "fetch_config::success", never, never>;
|
|
14
|
+
failure: import("@equinor/fusion-observable/dist/types/create-action").ActionCreatorWithPreparedPayload<[error: unknown], unknown, "fetch_config::failure", never, never>;
|
|
15
|
+
};
|
|
16
|
+
setModule: import("@equinor/fusion-observable/dist/types/create-action").ActionCreatorWithPreparedPayload<[module: any], any, "set_module", never, never>;
|
|
17
|
+
importApp: import("@equinor/fusion-observable/dist/types/create-action").ActionCreatorWithPreparedPayload<[entrypoint: string], string, "import_app::request", never, never> & {
|
|
18
|
+
success: import("@equinor/fusion-observable/dist/types/create-action").ActionCreatorWithPreparedPayload<[module: AppScriptModule], AppScriptModule, "import_app::success", never, never>;
|
|
19
|
+
failure: import("@equinor/fusion-observable/dist/types/create-action").ActionCreatorWithPreparedPayload<[error: unknown], unknown, "import_app::failure", never, never>;
|
|
20
|
+
};
|
|
21
|
+
setInstance: import("@equinor/fusion-observable/dist/types/create-action").ActionCreatorWithPreparedPayload<[instance: AppModulesInstance<unknown>], AppModulesInstance<unknown>, "set_instance", never, never>;
|
|
22
|
+
};
|
|
23
|
+
export declare const actions: {
|
|
24
|
+
setManifest: import("@equinor/fusion-observable/dist/types/create-action").ActionCreatorWithPreparedPayload<[manifest: AppManifest], AppManifest, "set_manifest", never, {
|
|
25
|
+
created: number;
|
|
26
|
+
}>;
|
|
27
|
+
fetchManifest: import("@equinor/fusion-observable/dist/types/create-action").ActionCreatorWithPreparedPayload<[key: string], string, "fetch_manifest::request", never, never> & {
|
|
28
|
+
success: import("@equinor/fusion-observable/dist/types/create-action").ActionCreatorWithPreparedPayload<[manifest: AppManifest], AppManifest, "fetch_manifest::success", never, never>;
|
|
29
|
+
failure: import("@equinor/fusion-observable/dist/types/create-action").ActionCreatorWithPreparedPayload<[error: unknown], unknown, "fetch_manifest::failure", never, never>;
|
|
30
|
+
};
|
|
31
|
+
setConfig: import("@equinor/fusion-observable/dist/types/create-action").ActionCreatorWithPreparedPayload<[config: AppConfig<unknown>], AppConfig<unknown>, "set_config", never, never>;
|
|
32
|
+
fetchConfig: import("@equinor/fusion-observable/dist/types/create-action").ActionCreatorWithPreparedPayload<[key: string], string, "fetch_config::request", never, never> & {
|
|
33
|
+
success: import("@equinor/fusion-observable/dist/types/create-action").ActionCreatorWithPreparedPayload<[config: AppConfig<unknown>], AppConfig<unknown>, "fetch_config::success", never, never>;
|
|
34
|
+
failure: import("@equinor/fusion-observable/dist/types/create-action").ActionCreatorWithPreparedPayload<[error: unknown], unknown, "fetch_config::failure", never, never>;
|
|
35
|
+
};
|
|
36
|
+
setModule: import("@equinor/fusion-observable/dist/types/create-action").ActionCreatorWithPreparedPayload<[module: any], any, "set_module", never, never>;
|
|
37
|
+
importApp: import("@equinor/fusion-observable/dist/types/create-action").ActionCreatorWithPreparedPayload<[entrypoint: string], string, "import_app::request", never, never> & {
|
|
38
|
+
success: import("@equinor/fusion-observable/dist/types/create-action").ActionCreatorWithPreparedPayload<[module: AppScriptModule], AppScriptModule, "import_app::success", never, never>;
|
|
39
|
+
failure: import("@equinor/fusion-observable/dist/types/create-action").ActionCreatorWithPreparedPayload<[error: unknown], unknown, "import_app::failure", never, never>;
|
|
40
|
+
};
|
|
41
|
+
setInstance: import("@equinor/fusion-observable/dist/types/create-action").ActionCreatorWithPreparedPayload<[instance: AppModulesInstance<unknown>], AppModulesInstance<unknown>, "set_instance", never, never>;
|
|
42
|
+
};
|
|
43
|
+
export type ActionBuilder = ReturnType<typeof createActions>;
|
|
44
|
+
export type ActionMap = ActionInstanceMap<ActionBuilder>;
|
|
45
|
+
export type Actions = ActionTypes<typeof actions>;
|
|
46
|
+
export {};
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import { FlowSubject } from '@equinor/fusion-observable';
|
|
2
|
+
import type { Actions } from './actions';
|
|
3
|
+
import type { AppBundleState } from './types';
|
|
4
|
+
import type { AppModuleProvider } from '../AppModuleProvider';
|
|
5
|
+
export declare const createState: (appKey: string, provider: AppModuleProvider) => FlowSubject<AppBundleState, Actions>;
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import type { Flow } from '@equinor/fusion-observable';
|
|
2
|
+
import type { AppModuleProvider } from '../AppModuleProvider';
|
|
3
|
+
import type { Actions } from './actions';
|
|
4
|
+
import { AppBundleState } from './types';
|
|
5
|
+
export declare const handleFetchManifest: (provider: AppModuleProvider) => Flow<Actions, AppBundleState>;
|
|
6
|
+
export declare const handleFetchConfig: (provider: AppModuleProvider) => Flow<Actions, AppBundleState>;
|
|
7
|
+
export declare const handleImportApplication: () => Flow<Actions, AppBundleState>;
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import type { AppConfig, AppManifest, AppModulesInstance, AppScriptModule } from '../types';
|
|
2
|
+
export type AppBundleState<TConfig = any, TModules = any> = {
|
|
3
|
+
appKey: string;
|
|
4
|
+
status: Set<string>;
|
|
5
|
+
manifest?: AppManifest;
|
|
6
|
+
config?: AppConfig<TConfig>;
|
|
7
|
+
modules?: AppScriptModule;
|
|
8
|
+
instance?: AppModulesInstance<TModules>;
|
|
9
|
+
};
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
type AppErrorType = 'not_found' | 'unauthorized' | 'unknown';
|
|
2
|
+
export declare class AppManifestError extends Error {
|
|
3
|
+
readonly type: AppErrorType;
|
|
4
|
+
static fromHttpResponse(response: Response, options?: ErrorOptions): AppManifestError;
|
|
5
|
+
constructor(type: AppErrorType, message?: string, options?: ErrorOptions);
|
|
6
|
+
}
|
|
7
|
+
export declare class AppConfigError extends Error {
|
|
8
|
+
readonly type: AppErrorType;
|
|
9
|
+
static fromHttpResponse(response: Response, options?: ErrorOptions): AppConfigError;
|
|
10
|
+
constructor(type: AppErrorType, message?: string, options?: ErrorOptions);
|
|
11
|
+
}
|
|
12
|
+
export declare class AppScriptModuleError extends Error {
|
|
13
|
+
readonly type: AppErrorType;
|
|
14
|
+
constructor(type: AppErrorType, message?: string, options?: ErrorOptions);
|
|
15
|
+
}
|
|
16
|
+
export {};
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import { AnyModule } from '@equinor/fusion-framework-module';
|
|
2
|
+
import { FrameworkEvent, FrameworkEventInit } from '@equinor/fusion-framework-module-event';
|
|
3
|
+
import { App } from 'app/App';
|
|
4
|
+
import AppModuleProvider from 'AppModuleProvider';
|
|
5
|
+
import { AppModulesInstance } from './types';
|
|
6
|
+
type AppModulesLoadedEventInit<TModules extends Array<AnyModule> | unknown = unknown> = FrameworkEventInit<{
|
|
7
|
+
appKey: string;
|
|
8
|
+
modules: AppModulesInstance<TModules>;
|
|
9
|
+
}>;
|
|
10
|
+
export declare class AppModulesLoadedEvent<TModules extends Array<AnyModule> | unknown = unknown> extends FrameworkEvent<AppModulesLoadedEventInit<TModules>> {
|
|
11
|
+
constructor(appKey: string, modules: AppModulesInstance<TModules>, init?: Omit<AppModulesLoadedEventInit<TModules>, 'detail'>);
|
|
12
|
+
}
|
|
13
|
+
declare module '@equinor/fusion-framework-module-event' {
|
|
14
|
+
interface FrameworkEventMap {
|
|
15
|
+
onAppModulesLoaded: AppModulesLoadedEvent;
|
|
16
|
+
onCurrentAppChanged: FrameworkEvent<FrameworkEventInit<{
|
|
17
|
+
next?: App;
|
|
18
|
+
previous?: App;
|
|
19
|
+
}, AppModuleProvider>>;
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
export {};
|
package/dist/types/index.d.ts
CHANGED
|
@@ -1,4 +1,6 @@
|
|
|
1
|
-
export { AppConfigurator, IAppConfigurator, IAppModuleConfig } from './
|
|
2
|
-
export {
|
|
1
|
+
export { AppModuleConfig, AppConfigurator, IAppConfigurator, AppModuleConfig as IAppModuleConfig, } from './AppConfigurator';
|
|
2
|
+
export { AppModuleProvider } from './AppModuleProvider';
|
|
3
|
+
export { App } from './app/App';
|
|
4
|
+
export * from './events';
|
|
3
5
|
export * from './types';
|
|
4
6
|
export { default, AppModule, module, moduleKey } from './module';
|
package/dist/types/module.d.ts
CHANGED
|
@@ -1,10 +1,11 @@
|
|
|
1
|
-
import { Module } from '@equinor/fusion-framework-module';
|
|
1
|
+
import { IModulesConfigurator, Module } from '@equinor/fusion-framework-module';
|
|
2
2
|
import { ModuleDeps } from './types';
|
|
3
|
-
import { IAppConfigurator } from './
|
|
4
|
-
import {
|
|
3
|
+
import { IAppConfigurator } from './AppConfigurator';
|
|
4
|
+
import { AppModuleProvider } from './AppModuleProvider';
|
|
5
5
|
export declare const moduleKey = "app";
|
|
6
|
-
export type AppModule = Module<typeof moduleKey,
|
|
6
|
+
export type AppModule = Module<typeof moduleKey, AppModuleProvider, IAppConfigurator, ModuleDeps>;
|
|
7
7
|
export declare const module: AppModule;
|
|
8
|
+
export declare const enableAppModule: (configurator: IModulesConfigurator) => void;
|
|
8
9
|
export default module;
|
|
9
10
|
declare module '@equinor/fusion-framework-module' {
|
|
10
11
|
interface Modules {
|
package/dist/types/types.d.ts
CHANGED
|
@@ -1,6 +1,15 @@
|
|
|
1
|
+
import { AnyModule, CombinedModules, ModulesInstance } from '@equinor/fusion-framework-module';
|
|
1
2
|
import type { EventModule } from '@equinor/fusion-framework-module-event';
|
|
2
3
|
import type { HttpModule } from '@equinor/fusion-framework-module-http';
|
|
4
|
+
import { MsalModule } from '@equinor/fusion-framework-module-msal';
|
|
3
5
|
import type { ServiceDiscoveryModule } from '@equinor/fusion-framework-module-service-discovery';
|
|
6
|
+
type Fusion = any;
|
|
7
|
+
export type AppEnv<TConfig = unknown, TProps = unknown> = {
|
|
8
|
+
basename?: string;
|
|
9
|
+
manifest?: AppManifest;
|
|
10
|
+
config?: AppConfig<TConfig>;
|
|
11
|
+
props?: TProps;
|
|
12
|
+
};
|
|
4
13
|
export type ModuleDeps = [HttpModule, ServiceDiscoveryModule, EventModule];
|
|
5
14
|
export type AppType = 'standalone' | 'report' | 'launcher';
|
|
6
15
|
export type AppAuth = {
|
|
@@ -14,7 +23,7 @@ type AppCategory = {
|
|
|
14
23
|
defaultIcon: string | null;
|
|
15
24
|
};
|
|
16
25
|
export type AppManifest = {
|
|
17
|
-
|
|
26
|
+
appKey: string;
|
|
18
27
|
name: string;
|
|
19
28
|
shortName: string;
|
|
20
29
|
version: string;
|
|
@@ -40,4 +49,23 @@ export type AppConfig<TEnvironment = unknown> = {
|
|
|
40
49
|
environment: TEnvironment;
|
|
41
50
|
endpoints: Record<string, string | Endpoint>;
|
|
42
51
|
};
|
|
52
|
+
export type AppBundle<TEnvironment = unknown, TModule = unknown> = {
|
|
53
|
+
manifest: AppManifest;
|
|
54
|
+
config: AppConfig<TEnvironment>;
|
|
55
|
+
module: TModule;
|
|
56
|
+
};
|
|
57
|
+
export type AppModules<TModules extends Array<AnyModule> | unknown = unknown> = CombinedModules<TModules, [
|
|
58
|
+
EventModule,
|
|
59
|
+
HttpModule,
|
|
60
|
+
MsalModule
|
|
61
|
+
]>;
|
|
62
|
+
export type ComponentRenderArgs<TFusion extends Fusion = Fusion, TEnv = AppEnv> = {
|
|
63
|
+
fusion: TFusion;
|
|
64
|
+
env: TEnv;
|
|
65
|
+
};
|
|
66
|
+
export type AppScriptModule = {
|
|
67
|
+
default: (el: HTMLElement, args: ComponentRenderArgs) => VoidFunction;
|
|
68
|
+
renderApp: (el: HTMLElement, args: ComponentRenderArgs) => VoidFunction;
|
|
69
|
+
};
|
|
70
|
+
export type AppModulesInstance<TModules extends Array<AnyModule> | unknown = unknown> = ModulesInstance<AppModules<TModules>>;
|
|
43
71
|
export {};
|
package/package.json
CHANGED
|
@@ -1,12 +1,20 @@
|
|
|
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": {
|
|
7
|
-
".": "./dist/esm/index.js"
|
|
7
|
+
".": "./dist/esm/index.js",
|
|
8
|
+
"./errors.js": "./dist/esm/errors.js"
|
|
8
9
|
},
|
|
9
10
|
"types": "dist/types/index.d.ts",
|
|
11
|
+
"typesVersions": {
|
|
12
|
+
"*": {
|
|
13
|
+
"errors.js": [
|
|
14
|
+
"dist/types/errors.d.ts"
|
|
15
|
+
]
|
|
16
|
+
}
|
|
17
|
+
},
|
|
10
18
|
"scripts": {
|
|
11
19
|
"build": "tsc -b",
|
|
12
20
|
"prepack": "yarn build"
|
|
@@ -23,15 +31,15 @@
|
|
|
23
31
|
"directory": "packages/module-app"
|
|
24
32
|
},
|
|
25
33
|
"dependencies": {
|
|
26
|
-
"@equinor/fusion-query": "^1.1.
|
|
34
|
+
"@equinor/fusion-query": "^1.1.2",
|
|
27
35
|
"rxjs": "^7.5.7"
|
|
28
36
|
},
|
|
29
37
|
"devDependencies": {
|
|
30
38
|
"@equinor/fusion-framework-module": "^1.2.10",
|
|
31
39
|
"@equinor/fusion-framework-module-event": "^1.2.0",
|
|
32
|
-
"@equinor/fusion-framework-module-http": "^2.2.
|
|
33
|
-
"@equinor/fusion-framework-module-service-discovery": "^4.0.
|
|
40
|
+
"@equinor/fusion-framework-module-http": "^2.2.1",
|
|
41
|
+
"@equinor/fusion-framework-module-service-discovery": "^4.0.7",
|
|
34
42
|
"typescript": "^4.9.3"
|
|
35
43
|
},
|
|
36
|
-
"gitHead": "
|
|
44
|
+
"gitHead": "4bc7a862d19921fc8801e5238d7013b8ece12917"
|
|
37
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
|
+
}
|