@equinor/fusion-framework-module-app 0.0.0-next-20230915111233
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/.turbo/turbo-build.log +4 -0
- package/CHANGELOG.md +555 -0
- package/LICENSE +21 -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 +104 -0
- package/dist/esm/AppModuleProvider.js.map +1 -0
- package/dist/esm/app/App.js +250 -0
- package/dist/esm/app/App.js.map +1 -0
- package/dist/esm/app/actions.js +21 -0
- package/dist/esm/app/actions.js.map +1 -0
- package/dist/esm/app/create-reducer.js +30 -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/events.js +2 -0
- package/dist/esm/app/events.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/index.js +3 -0
- package/dist/esm/app/index.js.map +1 -0
- package/dist/esm/app/types.js +2 -0
- package/dist/esm/app/types.js.map +1 -0
- package/dist/esm/enable-app-module.js +10 -0
- package/dist/esm/enable-app-module.js.map +1 -0
- package/dist/esm/errors.js +37 -0
- package/dist/esm/errors.js.map +1 -0
- package/dist/esm/events.js +2 -0
- package/dist/esm/events.js.map +1 -0
- package/dist/esm/helpers.js +2 -0
- package/dist/esm/helpers.js.map +1 -0
- package/dist/esm/index.js +7 -0
- package/dist/esm/index.js.map +1 -0
- package/dist/esm/module.js +26 -0
- package/dist/esm/module.js.map +1 -0
- package/dist/esm/types.js +2 -0
- package/dist/esm/types.js.map +1 -0
- package/dist/esm/version.js +2 -0
- package/dist/esm/version.js.map +1 -0
- package/dist/tsconfig.tsbuildinfo +1 -0
- package/dist/types/AppConfigBuilder.d.ts +26 -0
- package/dist/types/AppConfigurator.d.ts +28 -0
- package/dist/types/AppModuleProvider.d.ts +29 -0
- package/dist/types/app/App.d.ts +70 -0
- package/dist/types/app/actions.d.ts +60 -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/events.d.ts +28 -0
- package/dist/types/app/flows.d.ts +7 -0
- package/dist/types/app/index.d.ts +2 -0
- package/dist/types/app/types.d.ts +10 -0
- package/dist/types/enable-app-module.d.ts +3 -0
- package/dist/types/errors.d.ts +16 -0
- package/dist/types/events.d.ts +11 -0
- package/dist/types/helpers.d.ts +2 -0
- package/dist/types/index.d.ts +7 -0
- package/dist/types/module.d.ts +13 -0
- package/dist/types/types.d.ts +73 -0
- package/dist/types/version.d.ts +1 -0
- package/package.json +50 -0
- package/src/AppConfigBuilder.ts +89 -0
- package/src/AppConfigurator.ts +104 -0
- package/src/AppModuleProvider.ts +181 -0
- package/src/app/App.ts +399 -0
- package/src/app/actions.ts +63 -0
- package/src/app/create-reducer.ts +45 -0
- package/src/app/create-state.ts +21 -0
- package/src/app/events.ts +67 -0
- package/src/app/flows.ts +61 -0
- package/src/app/index.ts +3 -0
- package/src/app/types.ts +17 -0
- package/src/enable-app-module.ts +21 -0
- package/src/errors.ts +65 -0
- package/src/events.ts +18 -0
- package/src/helpers.ts +4 -0
- package/src/index.ts +16 -0
- package/src/module.ts +30 -0
- package/src/types.ts +95 -0
- package/src/version.ts +2 -0
- package/tsconfig.json +33 -0
|
@@ -0,0 +1,70 @@
|
|
|
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 { AppBundleState, AppBundleStateInitial } from './types';
|
|
8
|
+
import './events';
|
|
9
|
+
export declare function filterEmpty<T>(): OperatorFunction<T | null | undefined, T>;
|
|
10
|
+
export interface IApp<TEnv = any, TModules extends Array<AnyModule> | unknown = unknown> {
|
|
11
|
+
get manifest$(): Observable<AppManifest>;
|
|
12
|
+
get config$(): Observable<AppConfig<TEnv>>;
|
|
13
|
+
get modules$(): Observable<AppScriptModule>;
|
|
14
|
+
get instance$(): Observable<AppModulesInstance<TModules>>;
|
|
15
|
+
get state(): AppBundleState;
|
|
16
|
+
get appKey(): string;
|
|
17
|
+
get manifest(): AppManifest | undefined;
|
|
18
|
+
get manifestAsync(): Promise<AppManifest>;
|
|
19
|
+
get config(): AppConfig<TEnv> | undefined;
|
|
20
|
+
get instance(): AppModulesInstance<TModules> | undefined;
|
|
21
|
+
initialize(): Observable<{
|
|
22
|
+
manifest: AppManifest;
|
|
23
|
+
script: AppScriptModule;
|
|
24
|
+
config: AppConfig;
|
|
25
|
+
}>;
|
|
26
|
+
loadConfig(): void;
|
|
27
|
+
loadManifest(): void;
|
|
28
|
+
loadAppModule(allow_cache?: boolean): void;
|
|
29
|
+
getConfig(force_refresh?: boolean): Observable<AppConfig>;
|
|
30
|
+
getConfigAsync(allow_cache?: boolean): Promise<AppConfig>;
|
|
31
|
+
getManifest(force_refresh?: boolean): Observable<AppManifest>;
|
|
32
|
+
getManifestAsync(allow_cache?: boolean): Promise<AppManifest>;
|
|
33
|
+
getAppModule(force_refresh?: boolean): Observable<AppScriptModule>;
|
|
34
|
+
getAppModuleAsync(allow_cache?: boolean): Promise<AppScriptModule>;
|
|
35
|
+
}
|
|
36
|
+
export declare class App<TEnv = any, TModules extends Array<AnyModule> | unknown = unknown> implements IApp<TEnv, TModules> {
|
|
37
|
+
#private;
|
|
38
|
+
get manifest$(): Observable<AppManifest>;
|
|
39
|
+
get config$(): Observable<AppConfig<TEnv>>;
|
|
40
|
+
get modules$(): Observable<AppScriptModule>;
|
|
41
|
+
get instance$(): Observable<AppModulesInstance<TModules>>;
|
|
42
|
+
get state(): AppBundleState;
|
|
43
|
+
get appKey(): string;
|
|
44
|
+
get manifest(): AppManifest | undefined;
|
|
45
|
+
get manifestAsync(): Promise<AppManifest>;
|
|
46
|
+
get config(): AppConfig<TEnv> | undefined;
|
|
47
|
+
get configAsync(): Promise<AppConfig<TEnv>>;
|
|
48
|
+
get instance(): AppModulesInstance<TModules> | undefined;
|
|
49
|
+
constructor(value: AppBundleStateInitial, args: {
|
|
50
|
+
provider: AppModuleProvider;
|
|
51
|
+
event?: ModuleType<EventModule>;
|
|
52
|
+
});
|
|
53
|
+
initialize(): Observable<{
|
|
54
|
+
manifest: AppManifest;
|
|
55
|
+
script: AppScriptModule;
|
|
56
|
+
config: AppConfig;
|
|
57
|
+
}>;
|
|
58
|
+
loadConfig(): void;
|
|
59
|
+
loadManifest(update?: boolean): void;
|
|
60
|
+
updateManifest(manifest: AppManifest, replace?: false): void;
|
|
61
|
+
loadAppModule(allow_cache?: boolean): Promise<void>;
|
|
62
|
+
getConfig(force_refresh?: boolean): Observable<AppConfig>;
|
|
63
|
+
getConfigAsync(allow_cache?: boolean): Promise<AppConfig>;
|
|
64
|
+
getManifest(force_refresh?: boolean): Observable<AppManifest>;
|
|
65
|
+
getManifestAsync(allow_cache?: boolean): Promise<AppManifest>;
|
|
66
|
+
getAppModule(force_refresh?: boolean): Observable<AppScriptModule>;
|
|
67
|
+
getAppModuleAsync(allow_cache?: boolean): Promise<AppScriptModule>;
|
|
68
|
+
dispose: VoidFunction;
|
|
69
|
+
}
|
|
70
|
+
export default App;
|
|
@@ -0,0 +1,60 @@
|
|
|
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").ActionCreatorWithPreparedPayload<[manifest: AppManifest, update?: boolean | undefined], AppManifest, "set_manifest", never, {
|
|
5
|
+
created: number;
|
|
6
|
+
update: boolean | undefined;
|
|
7
|
+
}>;
|
|
8
|
+
fetchManifest: import("@equinor/fusion-observable").ActionCreatorWithPreparedPayload<[key: string, update?: boolean | undefined], string, "fetch_manifest::request", never, {
|
|
9
|
+
update: boolean | undefined;
|
|
10
|
+
}> & {
|
|
11
|
+
success: import("@equinor/fusion-observable").ActionCreatorWithPreparedPayload<[manifest: AppManifest], AppManifest, "fetch_manifest::success", never, never>;
|
|
12
|
+
failure: import("@equinor/fusion-observable").ActionCreatorWithPreparedPayload<[error: unknown], unknown, "fetch_manifest::failure", never, never>;
|
|
13
|
+
};
|
|
14
|
+
setConfig: import("@equinor/fusion-observable").ActionCreatorWithPreparedPayload<[config: AppConfig], AppConfig, "set_config", never, never>;
|
|
15
|
+
fetchConfig: import("@equinor/fusion-observable").ActionCreatorWithPreparedPayload<[key: string], string, "fetch_config::request", never, never> & {
|
|
16
|
+
success: import("@equinor/fusion-observable").ActionCreatorWithPreparedPayload<[config: AppConfig], AppConfig, "fetch_config::success", never, never>;
|
|
17
|
+
failure: import("@equinor/fusion-observable").ActionCreatorWithPreparedPayload<[error: unknown], unknown, "fetch_config::failure", never, never>;
|
|
18
|
+
};
|
|
19
|
+
setModule: import("@equinor/fusion-observable").ActionCreatorWithPreparedPayload<[module: any], any, "set_module", never, never>;
|
|
20
|
+
importApp: import("@equinor/fusion-observable").ActionCreatorWithPreparedPayload<[entrypoint: string], string, "import_app::request", never, never> & {
|
|
21
|
+
success: import("@equinor/fusion-observable").ActionCreatorWithPreparedPayload<[module: AppScriptModule], AppScriptModule, "import_app::success", never, never>;
|
|
22
|
+
failure: import("@equinor/fusion-observable").ActionCreatorWithPreparedPayload<[error: unknown], unknown, "import_app::failure", never, never>;
|
|
23
|
+
};
|
|
24
|
+
setInstance: import("@equinor/fusion-observable").ActionCreatorWithPreparedPayload<[instance: AppModulesInstance], AppModulesInstance, "set_instance", never, never>;
|
|
25
|
+
initialize: import("@equinor/fusion-observable").ActionCreatorWithPreparedPayload<[], null, "initialize_app::request", never, never> & {
|
|
26
|
+
success: import("@equinor/fusion-observable").ActionCreatorWithPreparedPayload<[], null, "initialize_app::success", never, never>;
|
|
27
|
+
failure: import("@equinor/fusion-observable").ActionCreatorWithPreparedPayload<[error: unknown], unknown, "initialize_app::failure", never, never>;
|
|
28
|
+
};
|
|
29
|
+
};
|
|
30
|
+
export declare const actions: {
|
|
31
|
+
setManifest: import("@equinor/fusion-observable").ActionCreatorWithPreparedPayload<[manifest: AppManifest, update?: boolean | undefined], AppManifest, "set_manifest", never, {
|
|
32
|
+
created: number;
|
|
33
|
+
update: boolean | undefined;
|
|
34
|
+
}>;
|
|
35
|
+
fetchManifest: import("@equinor/fusion-observable").ActionCreatorWithPreparedPayload<[key: string, update?: boolean | undefined], string, "fetch_manifest::request", never, {
|
|
36
|
+
update: boolean | undefined;
|
|
37
|
+
}> & {
|
|
38
|
+
success: import("@equinor/fusion-observable").ActionCreatorWithPreparedPayload<[manifest: AppManifest], AppManifest, "fetch_manifest::success", never, never>;
|
|
39
|
+
failure: import("@equinor/fusion-observable").ActionCreatorWithPreparedPayload<[error: unknown], unknown, "fetch_manifest::failure", never, never>;
|
|
40
|
+
};
|
|
41
|
+
setConfig: import("@equinor/fusion-observable").ActionCreatorWithPreparedPayload<[config: AppConfig], AppConfig, "set_config", never, never>;
|
|
42
|
+
fetchConfig: import("@equinor/fusion-observable").ActionCreatorWithPreparedPayload<[key: string], string, "fetch_config::request", never, never> & {
|
|
43
|
+
success: import("@equinor/fusion-observable").ActionCreatorWithPreparedPayload<[config: AppConfig], AppConfig, "fetch_config::success", never, never>;
|
|
44
|
+
failure: import("@equinor/fusion-observable").ActionCreatorWithPreparedPayload<[error: unknown], unknown, "fetch_config::failure", never, never>;
|
|
45
|
+
};
|
|
46
|
+
setModule: import("@equinor/fusion-observable").ActionCreatorWithPreparedPayload<[module: any], any, "set_module", never, never>;
|
|
47
|
+
importApp: import("@equinor/fusion-observable").ActionCreatorWithPreparedPayload<[entrypoint: string], string, "import_app::request", never, never> & {
|
|
48
|
+
success: import("@equinor/fusion-observable").ActionCreatorWithPreparedPayload<[module: AppScriptModule], AppScriptModule, "import_app::success", never, never>;
|
|
49
|
+
failure: import("@equinor/fusion-observable").ActionCreatorWithPreparedPayload<[error: unknown], unknown, "import_app::failure", never, never>;
|
|
50
|
+
};
|
|
51
|
+
setInstance: import("@equinor/fusion-observable").ActionCreatorWithPreparedPayload<[instance: AppModulesInstance], AppModulesInstance, "set_instance", never, never>;
|
|
52
|
+
initialize: import("@equinor/fusion-observable").ActionCreatorWithPreparedPayload<[], null, "initialize_app::request", never, never> & {
|
|
53
|
+
success: import("@equinor/fusion-observable").ActionCreatorWithPreparedPayload<[], null, "initialize_app::success", never, never>;
|
|
54
|
+
failure: import("@equinor/fusion-observable").ActionCreatorWithPreparedPayload<[error: unknown], unknown, "initialize_app::failure", never, never>;
|
|
55
|
+
};
|
|
56
|
+
};
|
|
57
|
+
export type ActionBuilder = ReturnType<typeof createActions>;
|
|
58
|
+
export type ActionMap = ActionInstanceMap<ActionBuilder>;
|
|
59
|
+
export type Actions = ActionTypes<typeof actions>;
|
|
60
|
+
export {};
|
|
@@ -0,0 +1,3 @@
|
|
|
1
|
+
import { AppBundleState, AppBundleStateInitial } from './types';
|
|
2
|
+
export declare const createReducer: (value: AppBundleStateInitial) => import("@equinor/fusion-observable").ReducerWithInitialState<AppBundleState, import("@equinor/fusion-observable").AnyAction>;
|
|
3
|
+
export default createReducer;
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import { FlowSubject } from '@equinor/fusion-observable';
|
|
2
|
+
import type { Actions } from './actions';
|
|
3
|
+
import type { AppBundleState, AppBundleStateInitial } from './types';
|
|
4
|
+
import type { AppModuleProvider } from '../AppModuleProvider';
|
|
5
|
+
export declare const createState: (value: AppBundleStateInitial, provider: AppModuleProvider) => FlowSubject<AppBundleState, Actions>;
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import type { FrameworkEvent, FrameworkEventInit } from '@equinor/fusion-framework-module-event';
|
|
2
|
+
import type { App } from './App';
|
|
3
|
+
import type { AppConfig, AppManifest, AppModulesInstance } from '../types';
|
|
4
|
+
export type AppEventEventInit<TDetail extends Record<string, unknown> | unknown = unknown> = FrameworkEventInit<TDetail & {
|
|
5
|
+
appKey: string;
|
|
6
|
+
}, App>;
|
|
7
|
+
declare module '@equinor/fusion-framework-module-event' {
|
|
8
|
+
interface FrameworkEventMap {
|
|
9
|
+
onAppModulesLoaded: FrameworkEvent<AppEventEventInit<{
|
|
10
|
+
modules: AppModulesInstance;
|
|
11
|
+
}>>;
|
|
12
|
+
onAppManifestLoaded: FrameworkEvent<AppEventEventInit<{
|
|
13
|
+
manifest: AppManifest;
|
|
14
|
+
}>>;
|
|
15
|
+
onAppConfigLoaded: FrameworkEvent<AppEventEventInit<{
|
|
16
|
+
config: AppConfig;
|
|
17
|
+
}>>;
|
|
18
|
+
onAppScriptLoaded: FrameworkEvent<AppEventEventInit<{
|
|
19
|
+
manifest: AppManifest;
|
|
20
|
+
}>>;
|
|
21
|
+
onAppInitialize: FrameworkEvent<AppEventEventInit>;
|
|
22
|
+
onAppInitialized: FrameworkEvent<AppEventEventInit>;
|
|
23
|
+
onAppInitializeFailed: FrameworkEvent<AppEventEventInit<{
|
|
24
|
+
error: unknown;
|
|
25
|
+
}>>;
|
|
26
|
+
onAppDispose: FrameworkEvent<AppEventEventInit>;
|
|
27
|
+
}
|
|
28
|
+
}
|
|
@@ -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 type { 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,10 @@
|
|
|
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
|
+
};
|
|
10
|
+
export type AppBundleStateInitial<TConfig = any, TModules = any> = Omit<AppBundleState<TConfig, TModules>, 'status'>;
|
|
@@ -0,0 +1,3 @@
|
|
|
1
|
+
import type { IModulesConfigurator } from '@equinor/fusion-framework-module';
|
|
2
|
+
import type { AppConfigBuilderCallback } from './AppConfigBuilder';
|
|
3
|
+
export declare const enableAppModule: (configurator: IModulesConfigurator<any, any>, builder?: AppConfigBuilderCallback) => void;
|
|
@@ -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,11 @@
|
|
|
1
|
+
import { FrameworkEvent, FrameworkEventInit } from '@equinor/fusion-framework-module-event';
|
|
2
|
+
import { App } from './app/App';
|
|
3
|
+
import './app/events';
|
|
4
|
+
declare module '@equinor/fusion-framework-module-event' {
|
|
5
|
+
interface FrameworkEventMap {
|
|
6
|
+
onCurrentAppChanged: FrameworkEvent<FrameworkEventInit<{
|
|
7
|
+
next?: App;
|
|
8
|
+
previous?: App;
|
|
9
|
+
}>>;
|
|
10
|
+
}
|
|
11
|
+
}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
export { AppModuleConfig, AppConfigurator, IAppConfigurator, AppModuleConfig as IAppModuleConfig, } from './AppConfigurator';
|
|
2
|
+
export { AppModuleProvider } from './AppModuleProvider';
|
|
3
|
+
export { IApp } from './app/App';
|
|
4
|
+
export * from './events';
|
|
5
|
+
export * from './types';
|
|
6
|
+
export { enableAppModule } from './enable-app-module';
|
|
7
|
+
export { default, AppModule, module, moduleKey } from './module';
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { Module } from '@equinor/fusion-framework-module';
|
|
2
|
+
import { ModuleDeps } from './types';
|
|
3
|
+
import { IAppConfigurator } from './AppConfigurator';
|
|
4
|
+
import { AppModuleProvider } from './AppModuleProvider';
|
|
5
|
+
export declare const moduleKey = "app";
|
|
6
|
+
export type AppModule = Module<typeof moduleKey, AppModuleProvider, IAppConfigurator, ModuleDeps>;
|
|
7
|
+
export declare const module: AppModule;
|
|
8
|
+
export default module;
|
|
9
|
+
declare module '@equinor/fusion-framework-module' {
|
|
10
|
+
interface Modules {
|
|
11
|
+
app: AppModule;
|
|
12
|
+
}
|
|
13
|
+
}
|
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
import { AnyModule, CombinedModules, ModulesInstance } from '@equinor/fusion-framework-module';
|
|
2
|
+
import type { EventModule } from '@equinor/fusion-framework-module-event';
|
|
3
|
+
import type { HttpModule } from '@equinor/fusion-framework-module-http';
|
|
4
|
+
import type { MsalModule } from '@equinor/fusion-framework-module-msal';
|
|
5
|
+
import type { ServiceDiscoveryModule } from '@equinor/fusion-framework-module-service-discovery';
|
|
6
|
+
import IApp from './app';
|
|
7
|
+
type Fusion = any;
|
|
8
|
+
export type AppEnv<TConfig = unknown, TProps = unknown> = {
|
|
9
|
+
basename?: string;
|
|
10
|
+
manifest?: AppManifest;
|
|
11
|
+
config?: AppConfig<TConfig>;
|
|
12
|
+
props?: TProps;
|
|
13
|
+
};
|
|
14
|
+
export type ModuleDeps = [HttpModule, ServiceDiscoveryModule, EventModule];
|
|
15
|
+
export type AppType = 'standalone' | 'report' | 'launcher';
|
|
16
|
+
export type CurrentApp<TModules extends Array<AnyModule> = [], TEnv = any> = IApp<TEnv, TModules> | null | undefined;
|
|
17
|
+
export type AppAuth = {
|
|
18
|
+
clientId: string;
|
|
19
|
+
resources: string[];
|
|
20
|
+
};
|
|
21
|
+
type AppCategory = {
|
|
22
|
+
id?: string;
|
|
23
|
+
name: string | null;
|
|
24
|
+
color: string | null;
|
|
25
|
+
defaultIcon: string | null;
|
|
26
|
+
};
|
|
27
|
+
export type AppManifest = {
|
|
28
|
+
key: string;
|
|
29
|
+
name: string;
|
|
30
|
+
entry: string;
|
|
31
|
+
version: string;
|
|
32
|
+
shortName?: string;
|
|
33
|
+
description?: string;
|
|
34
|
+
type?: AppType;
|
|
35
|
+
tags?: string[];
|
|
36
|
+
auth?: AppAuth[];
|
|
37
|
+
icon?: string;
|
|
38
|
+
order?: number;
|
|
39
|
+
publishedDate?: Date;
|
|
40
|
+
accentColor?: string;
|
|
41
|
+
categoryId?: string;
|
|
42
|
+
category?: AppCategory;
|
|
43
|
+
hide?: boolean;
|
|
44
|
+
};
|
|
45
|
+
export type Endpoint = {
|
|
46
|
+
name: string;
|
|
47
|
+
uri: string;
|
|
48
|
+
scopes?: string[];
|
|
49
|
+
};
|
|
50
|
+
export type AppConfig<TEnvironment = unknown> = {
|
|
51
|
+
environment: TEnvironment;
|
|
52
|
+
endpoints: Record<string, string | Endpoint>;
|
|
53
|
+
};
|
|
54
|
+
export type AppBundle<TEnvironment = unknown, TModule = unknown> = {
|
|
55
|
+
manifest: AppManifest;
|
|
56
|
+
config: AppConfig<TEnvironment>;
|
|
57
|
+
module: TModule;
|
|
58
|
+
};
|
|
59
|
+
export type AppModules<TModules extends Array<AnyModule> | unknown = unknown> = CombinedModules<TModules, [
|
|
60
|
+
EventModule,
|
|
61
|
+
HttpModule,
|
|
62
|
+
MsalModule
|
|
63
|
+
]>;
|
|
64
|
+
export type ComponentRenderArgs<TFusion extends Fusion = Fusion, TEnv = AppEnv> = {
|
|
65
|
+
fusion: TFusion;
|
|
66
|
+
env: TEnv;
|
|
67
|
+
};
|
|
68
|
+
export type AppScriptModule = {
|
|
69
|
+
default: (el: HTMLElement, args: ComponentRenderArgs) => VoidFunction;
|
|
70
|
+
renderApp: (el: HTMLElement, args: ComponentRenderArgs) => VoidFunction;
|
|
71
|
+
};
|
|
72
|
+
export type AppModulesInstance<TModules extends Array<AnyModule> | unknown = unknown> = ModulesInstance<AppModules<TModules>>;
|
|
73
|
+
export {};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare const version = "5.2.4";
|
package/package.json
ADDED
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@equinor/fusion-framework-module-app",
|
|
3
|
+
"version": "0.0.0-next-20230915111233",
|
|
4
|
+
"description": "",
|
|
5
|
+
"main": "dist/esm/index.js",
|
|
6
|
+
"exports": {
|
|
7
|
+
".": "./dist/esm/index.js",
|
|
8
|
+
"./errors.js": "./dist/esm/errors.js",
|
|
9
|
+
"./app": "./dist/esm/app/index.js"
|
|
10
|
+
},
|
|
11
|
+
"types": "dist/types/index.d.ts",
|
|
12
|
+
"typesVersions": {
|
|
13
|
+
"*": {
|
|
14
|
+
"errors.js": [
|
|
15
|
+
"dist/types/errors.d.ts"
|
|
16
|
+
],
|
|
17
|
+
"app": [
|
|
18
|
+
"dist/types/app/index.d.ts"
|
|
19
|
+
]
|
|
20
|
+
}
|
|
21
|
+
},
|
|
22
|
+
"keywords": [],
|
|
23
|
+
"author": "",
|
|
24
|
+
"license": "ISC",
|
|
25
|
+
"publishConfig": {
|
|
26
|
+
"access": "public"
|
|
27
|
+
},
|
|
28
|
+
"repository": {
|
|
29
|
+
"type": "git",
|
|
30
|
+
"url": "git+https://github.com/equinor/fusion-framework.git",
|
|
31
|
+
"directory": "packages/modules/app"
|
|
32
|
+
},
|
|
33
|
+
"dependencies": {
|
|
34
|
+
"immer": "^9.0.16",
|
|
35
|
+
"rxjs": "^7.8.1",
|
|
36
|
+
"@equinor/fusion-observable": "^8.1.1",
|
|
37
|
+
"@equinor/fusion-query": "^0.0.0-next-20230915111233"
|
|
38
|
+
},
|
|
39
|
+
"devDependencies": {
|
|
40
|
+
"typescript": "^5.1.3",
|
|
41
|
+
"@equinor/fusion-framework-module-event": "^4.0.5",
|
|
42
|
+
"@equinor/fusion-framework-module-http": "^0.0.0-next-20230915111233",
|
|
43
|
+
"@equinor/fusion-framework-module-msal": "^3.0.6",
|
|
44
|
+
"@equinor/fusion-framework-module": "^4.2.4",
|
|
45
|
+
"@equinor/fusion-framework-module-service-discovery": "^0.0.0-next-20230915111233"
|
|
46
|
+
},
|
|
47
|
+
"scripts": {
|
|
48
|
+
"build": "tsc -b"
|
|
49
|
+
}
|
|
50
|
+
}
|
|
@@ -0,0 +1,89 @@
|
|
|
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(
|
|
22
|
+
init: TInit,
|
|
23
|
+
public config: Partial<AppModuleConfig> = {},
|
|
24
|
+
) {
|
|
25
|
+
this.#init = init;
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
requireInstance<TKey extends string = Extract<keyof Modules, string>>(
|
|
29
|
+
module: TKey,
|
|
30
|
+
): Promise<ModuleType<Modules[TKey]>>;
|
|
31
|
+
|
|
32
|
+
requireInstance<T>(module: string): Promise<T>;
|
|
33
|
+
|
|
34
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
35
|
+
requireInstance(module: string): Promise<any> {
|
|
36
|
+
return this.#init.requireInstance(module);
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
setAppClient(
|
|
40
|
+
client: {
|
|
41
|
+
getAppManifest:
|
|
42
|
+
| QueryFn<AppManifest, { appKey: string }>
|
|
43
|
+
| QueryCtorOptions<AppManifest, { appKey: string }>;
|
|
44
|
+
getAppManifests: QueryFn<AppManifest[], void> | QueryCtorOptions<AppManifest[], void>;
|
|
45
|
+
getAppConfig:
|
|
46
|
+
| QueryFn<AppConfig, { appKey: string }>
|
|
47
|
+
| QueryCtorOptions<AppConfig, { appKey: string; tag?: string }>;
|
|
48
|
+
},
|
|
49
|
+
expire = 1 * 60 * 1000,
|
|
50
|
+
) {
|
|
51
|
+
client;
|
|
52
|
+
expire;
|
|
53
|
+
|
|
54
|
+
this.config.client = {
|
|
55
|
+
getAppManifest:
|
|
56
|
+
typeof client.getAppManifest === 'function'
|
|
57
|
+
? {
|
|
58
|
+
key: ({ appKey }) => appKey,
|
|
59
|
+
client: {
|
|
60
|
+
fn: client.getAppManifest,
|
|
61
|
+
},
|
|
62
|
+
expire,
|
|
63
|
+
}
|
|
64
|
+
: client.getAppManifest,
|
|
65
|
+
getAppManifests:
|
|
66
|
+
typeof client.getAppManifests === 'function'
|
|
67
|
+
? {
|
|
68
|
+
// TODO - might cast to checksum
|
|
69
|
+
key: () => 'app_manifests',
|
|
70
|
+
client: {
|
|
71
|
+
fn: client.getAppManifests,
|
|
72
|
+
},
|
|
73
|
+
expire,
|
|
74
|
+
}
|
|
75
|
+
: client.getAppManifests,
|
|
76
|
+
getAppConfig:
|
|
77
|
+
typeof client.getAppConfig === 'function'
|
|
78
|
+
? {
|
|
79
|
+
// TODO - might cast to checksum
|
|
80
|
+
key: (args) => JSON.stringify(args),
|
|
81
|
+
client: {
|
|
82
|
+
fn: client.getAppConfig,
|
|
83
|
+
},
|
|
84
|
+
expire,
|
|
85
|
+
}
|
|
86
|
+
: client.getAppConfig,
|
|
87
|
+
};
|
|
88
|
+
}
|
|
89
|
+
}
|
|
@@ -0,0 +1,104 @@
|
|
|
1
|
+
import type { ModuleInitializerArgs } from '@equinor/fusion-framework-module';
|
|
2
|
+
import type { HttpModule, IHttpClient } from '@equinor/fusion-framework-module-http';
|
|
3
|
+
import type { ServiceDiscoveryModule } from '@equinor/fusion-framework-module-service-discovery';
|
|
4
|
+
import type { 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(
|
|
61
|
+
async (cur, cb) => {
|
|
62
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
63
|
+
const builder = new AppConfigBuilder(init, await cur);
|
|
64
|
+
await Promise.resolve(cb(builder));
|
|
65
|
+
return Object.assign(cur, builder.config);
|
|
66
|
+
},
|
|
67
|
+
Promise.resolve({} as Partial<AppModuleConfig>),
|
|
68
|
+
);
|
|
69
|
+
|
|
70
|
+
// TODO - make less lazy
|
|
71
|
+
config.client ??= await (async (): Promise<AppModuleConfig['client']> => {
|
|
72
|
+
const httpClient = await this._createHttpClient(init);
|
|
73
|
+
return {
|
|
74
|
+
getAppManifest: {
|
|
75
|
+
client: {
|
|
76
|
+
fn: ({ appKey }) => httpClient.json$<AppManifest>(`/api/apps/${appKey}`),
|
|
77
|
+
},
|
|
78
|
+
key: ({ appKey }) => appKey,
|
|
79
|
+
expire: this.defaultExpireTime,
|
|
80
|
+
},
|
|
81
|
+
getAppManifests: {
|
|
82
|
+
client: {
|
|
83
|
+
fn: () => httpClient.json$(`/api/apps`),
|
|
84
|
+
},
|
|
85
|
+
// TODO - might cast to checksum
|
|
86
|
+
key: () => 'manifests',
|
|
87
|
+
expire: this.defaultExpireTime,
|
|
88
|
+
},
|
|
89
|
+
getAppConfig: {
|
|
90
|
+
client: {
|
|
91
|
+
fn: ({ appKey, tag }) =>
|
|
92
|
+
httpClient.json$(
|
|
93
|
+
`/api/apps/${appKey}/config${tag ? `?tag=${tag}` : ''}`,
|
|
94
|
+
),
|
|
95
|
+
},
|
|
96
|
+
key: (args) => JSON.stringify(args),
|
|
97
|
+
expire: this.defaultExpireTime,
|
|
98
|
+
},
|
|
99
|
+
};
|
|
100
|
+
})();
|
|
101
|
+
|
|
102
|
+
return config as AppModuleConfig;
|
|
103
|
+
}
|
|
104
|
+
}
|