@equinor/fusion-framework-app 0.0.0-context-error-20240131144633
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 +833 -0
- package/LICENSE +21 -0
- package/README.md +38 -0
- package/dist/esm/AppConfigurator.js +81 -0
- package/dist/esm/AppConfigurator.js.map +1 -0
- package/dist/esm/configure-modules.js +26 -0
- package/dist/esm/configure-modules.js.map +1 -0
- package/dist/esm/index.js +5 -0
- package/dist/esm/index.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/AppConfigurator.d.ts +29 -0
- package/dist/types/configure-modules.d.ts +8 -0
- package/dist/types/index.d.ts +4 -0
- package/dist/types/types.d.ts +19 -0
- package/dist/types/version.d.ts +1 -0
- package/package.json +53 -0
- package/src/AppConfigurator.ts +192 -0
- package/src/configure-modules.ts +61 -0
- package/src/index.ts +8 -0
- package/src/types.ts +64 -0
- package/src/version.ts +2 -0
- package/tsconfig.json +39 -0
package/package.json
ADDED
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@equinor/fusion-framework-app",
|
|
3
|
+
"version": "0.0.0-context-error-20240131144633",
|
|
4
|
+
"description": "",
|
|
5
|
+
"main": "dist/esm/index.js",
|
|
6
|
+
"exports": {
|
|
7
|
+
".": "./dist/esm/index.js"
|
|
8
|
+
},
|
|
9
|
+
"types": "./dist/types/index.d.ts",
|
|
10
|
+
"keywords": [
|
|
11
|
+
"fusion",
|
|
12
|
+
"fusion-framework",
|
|
13
|
+
"utility"
|
|
14
|
+
],
|
|
15
|
+
"homepage": "https://equinor.github.io/fusion-framework/",
|
|
16
|
+
"author": {
|
|
17
|
+
"name": "Odin thomas Rochmann",
|
|
18
|
+
"email": "oroc@equinor.com",
|
|
19
|
+
"url": "https://github.com/odinr"
|
|
20
|
+
},
|
|
21
|
+
"license": "ISC",
|
|
22
|
+
"publishConfig": {
|
|
23
|
+
"access": "public"
|
|
24
|
+
},
|
|
25
|
+
"repository": {
|
|
26
|
+
"type": "git",
|
|
27
|
+
"url": "git+https://github.com/equinor/fusion-framework.git",
|
|
28
|
+
"directory": "packages/app"
|
|
29
|
+
},
|
|
30
|
+
"dependencies": {
|
|
31
|
+
"@equinor/fusion-framework": "^0.0.0-context-error-20240131144633",
|
|
32
|
+
"@equinor/fusion-framework-module": "^4.2.6",
|
|
33
|
+
"@equinor/fusion-framework-module-app": "^5.2.12",
|
|
34
|
+
"@equinor/fusion-framework-module-event": "^4.0.7",
|
|
35
|
+
"@equinor/fusion-framework-module-http": "^5.1.5",
|
|
36
|
+
"@equinor/fusion-framework-module-msal": "^3.0.9"
|
|
37
|
+
},
|
|
38
|
+
"devDependencies": {
|
|
39
|
+
"typescript": "^5.1.3",
|
|
40
|
+
"@equinor/fusion-framework-module-feature-flag": "^1.0.0"
|
|
41
|
+
},
|
|
42
|
+
"peerDependencies": {
|
|
43
|
+
"@equinor/fusion-framework-module-feature-flag": "^1.0.0"
|
|
44
|
+
},
|
|
45
|
+
"peerDependenciesMeta": {
|
|
46
|
+
"@equinor/fusion-framework-module-feature-flag": {
|
|
47
|
+
"optional": true
|
|
48
|
+
}
|
|
49
|
+
},
|
|
50
|
+
"scripts": {
|
|
51
|
+
"build": "tsc -b"
|
|
52
|
+
}
|
|
53
|
+
}
|
|
@@ -0,0 +1,192 @@
|
|
|
1
|
+
import { type FusionModulesInstance } from '@equinor/fusion-framework';
|
|
2
|
+
|
|
3
|
+
import {
|
|
4
|
+
type AnyModule,
|
|
5
|
+
type IModulesConfigurator,
|
|
6
|
+
ModuleConsoleLogger,
|
|
7
|
+
ModulesConfigurator,
|
|
8
|
+
} from '@equinor/fusion-framework-module';
|
|
9
|
+
|
|
10
|
+
import event from '@equinor/fusion-framework-module-event';
|
|
11
|
+
|
|
12
|
+
import http, {
|
|
13
|
+
configureHttpClient,
|
|
14
|
+
configureHttp,
|
|
15
|
+
type HttpClientOptions,
|
|
16
|
+
} from '@equinor/fusion-framework-module-http';
|
|
17
|
+
|
|
18
|
+
import auth, { configureMsal } from '@equinor/fusion-framework-module-msal';
|
|
19
|
+
|
|
20
|
+
import {
|
|
21
|
+
enableFeatureFlagging,
|
|
22
|
+
type IFeatureFlag,
|
|
23
|
+
type FeatureFlagBuilderCallback,
|
|
24
|
+
} from '@equinor/fusion-framework-module-feature-flag';
|
|
25
|
+
import {
|
|
26
|
+
createLocalStoragePlugin,
|
|
27
|
+
createUrlPlugin,
|
|
28
|
+
} from '@equinor/fusion-framework-module-feature-flag/plugins';
|
|
29
|
+
|
|
30
|
+
import { AppEnv, AppModules } from './types';
|
|
31
|
+
|
|
32
|
+
/**
|
|
33
|
+
* Configurator for configuring application modules
|
|
34
|
+
*
|
|
35
|
+
* @template TModules Addition modules
|
|
36
|
+
* @template TRef usually undefined, optional references
|
|
37
|
+
*/
|
|
38
|
+
export interface IAppConfigurator<
|
|
39
|
+
TModules extends Array<AnyModule> | unknown = unknown,
|
|
40
|
+
TRef extends FusionModulesInstance = FusionModulesInstance,
|
|
41
|
+
> extends IModulesConfigurator<AppModules<TModules>, TRef> {
|
|
42
|
+
/**
|
|
43
|
+
* [optional]
|
|
44
|
+
* enable/configure the http module
|
|
45
|
+
*/
|
|
46
|
+
configureHttp(...args: Parameters<typeof configureHttp>): void;
|
|
47
|
+
|
|
48
|
+
/**
|
|
49
|
+
* [optional]
|
|
50
|
+
* Configure a named http client.
|
|
51
|
+
* @example
|
|
52
|
+
* ```ts
|
|
53
|
+
configurator.configureHttpClient(
|
|
54
|
+
'myClient',
|
|
55
|
+
{
|
|
56
|
+
baseUri: 'https://foo.bar',
|
|
57
|
+
defaultScopes: ['client-id/.default']
|
|
58
|
+
}
|
|
59
|
+
);
|
|
60
|
+
* ```
|
|
61
|
+
*/
|
|
62
|
+
configureHttpClient(...args: Parameters<typeof configureHttpClient>): void;
|
|
63
|
+
|
|
64
|
+
/**
|
|
65
|
+
* [required]
|
|
66
|
+
* Setup of MSAL auth module
|
|
67
|
+
* @example
|
|
68
|
+
* ```ts
|
|
69
|
+
configurator.configureMsal(
|
|
70
|
+
{
|
|
71
|
+
tenantId: '{TENANT_ID}',
|
|
72
|
+
clientId: '{CLIENT_ID}',
|
|
73
|
+
redirectUri: '/authentication/login-callback',
|
|
74
|
+
},
|
|
75
|
+
{ requiresAuth: true }
|
|
76
|
+
);
|
|
77
|
+
* ```
|
|
78
|
+
*/
|
|
79
|
+
configureMsal(...args: Parameters<typeof configureMsal>): void;
|
|
80
|
+
|
|
81
|
+
/**
|
|
82
|
+
* [optional]
|
|
83
|
+
*
|
|
84
|
+
* configure a http client which is resolved by service discovery
|
|
85
|
+
*
|
|
86
|
+
* @param serviceName - name of the service to use
|
|
87
|
+
*/
|
|
88
|
+
// TODO - rename
|
|
89
|
+
useFrameworkServiceClient(serviceName: string): void;
|
|
90
|
+
|
|
91
|
+
/**
|
|
92
|
+
* enable feature flagging with predefined flags
|
|
93
|
+
* @param flags array of flags
|
|
94
|
+
* @remarks
|
|
95
|
+
* this will store defined flags in local storage
|
|
96
|
+
*/
|
|
97
|
+
useFeatureFlags(flags: Array<IFeatureFlag & { allowUrl?: boolean }>): void;
|
|
98
|
+
|
|
99
|
+
/**
|
|
100
|
+
* enable feature flagging with callback
|
|
101
|
+
* @param cb callback for configuring module
|
|
102
|
+
*/
|
|
103
|
+
useFeatureFlags(cb: FeatureFlagBuilderCallback): void;
|
|
104
|
+
|
|
105
|
+
/**
|
|
106
|
+
* enable feature flags
|
|
107
|
+
* @remarks
|
|
108
|
+
* this function does nothing atm since api is not implemented yet
|
|
109
|
+
*/
|
|
110
|
+
useFeatureFlags(): void;
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
export class AppConfigurator<
|
|
114
|
+
TModules extends Array<AnyModule> | unknown = unknown,
|
|
115
|
+
TRef extends FusionModulesInstance = FusionModulesInstance,
|
|
116
|
+
TEnv extends AppEnv = AppEnv,
|
|
117
|
+
>
|
|
118
|
+
extends ModulesConfigurator<AppModules<TModules>, TRef>
|
|
119
|
+
implements IAppConfigurator<TModules, TRef>
|
|
120
|
+
{
|
|
121
|
+
constructor(public readonly env: TEnv) {
|
|
122
|
+
super([event, http, auth]);
|
|
123
|
+
this.logger = new ModuleConsoleLogger('AppConfigurator');
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
public configureHttp(...args: Parameters<typeof configureHttp>) {
|
|
127
|
+
this.addConfig(configureHttp(...args));
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
public configureHttpClient(...args: Parameters<typeof configureHttpClient>) {
|
|
131
|
+
this.addConfig(configureHttpClient(...args));
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
public useFrameworkServiceClient(
|
|
135
|
+
serviceName: string,
|
|
136
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
137
|
+
options?: Omit<HttpClientOptions<any>, 'baseUri' | 'defaultScopes'>,
|
|
138
|
+
): void {
|
|
139
|
+
this.addConfig({
|
|
140
|
+
module: http,
|
|
141
|
+
configure: async (config, ref) => {
|
|
142
|
+
const service = await ref?.serviceDiscovery.resolveService(serviceName);
|
|
143
|
+
if (!service) {
|
|
144
|
+
throw Error(`failed to configure service [${serviceName}]`);
|
|
145
|
+
}
|
|
146
|
+
config.configureClient(serviceName, {
|
|
147
|
+
...options,
|
|
148
|
+
baseUri: service.uri,
|
|
149
|
+
defaultScopes: service.defaultScopes,
|
|
150
|
+
});
|
|
151
|
+
},
|
|
152
|
+
});
|
|
153
|
+
}
|
|
154
|
+
|
|
155
|
+
public configureMsal(...args: Parameters<typeof configureMsal>) {
|
|
156
|
+
this.addConfig(configureMsal(...args));
|
|
157
|
+
}
|
|
158
|
+
|
|
159
|
+
useFeatureFlags(
|
|
160
|
+
flags_cb?:
|
|
161
|
+
| Array<IFeatureFlag<unknown> & { allowUrl?: boolean | undefined }>
|
|
162
|
+
| FeatureFlagBuilderCallback,
|
|
163
|
+
): void {
|
|
164
|
+
switch (typeof flags_cb) {
|
|
165
|
+
case 'function': {
|
|
166
|
+
enableFeatureFlagging(this, flags_cb);
|
|
167
|
+
break;
|
|
168
|
+
}
|
|
169
|
+
case 'object': {
|
|
170
|
+
const urlFlags: IFeatureFlag[] = [];
|
|
171
|
+
const localFlags = (flags_cb ?? []).map((flag) => {
|
|
172
|
+
const { allowUrl, ...localFlag } = flag;
|
|
173
|
+
if (allowUrl) {
|
|
174
|
+
urlFlags.push(flag);
|
|
175
|
+
}
|
|
176
|
+
return localFlag;
|
|
177
|
+
});
|
|
178
|
+
enableFeatureFlagging(this, async (builder) => {
|
|
179
|
+
builder.addPlugin(
|
|
180
|
+
createLocalStoragePlugin(localFlags, {
|
|
181
|
+
name: this.env.manifest.key,
|
|
182
|
+
}),
|
|
183
|
+
);
|
|
184
|
+
builder.addPlugin(createUrlPlugin(urlFlags));
|
|
185
|
+
});
|
|
186
|
+
break;
|
|
187
|
+
}
|
|
188
|
+
}
|
|
189
|
+
}
|
|
190
|
+
}
|
|
191
|
+
|
|
192
|
+
export default AppConfigurator;
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
import { Fusion } from '@equinor/fusion-framework';
|
|
2
|
+
import type { AnyModule } from '@equinor/fusion-framework-module';
|
|
3
|
+
|
|
4
|
+
import { AppConfigurator } from './AppConfigurator';
|
|
5
|
+
import type { AppModulesInstance, AppModuleInitiator, AppEnv } from './types';
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
*
|
|
9
|
+
* Creates a callback for initializing configuration of application modules
|
|
10
|
+
*
|
|
11
|
+
* @example
|
|
12
|
+
```ts
|
|
13
|
+
const initialize = configureModules((configurator, args) => {
|
|
14
|
+
configurator.configure(someModule);
|
|
15
|
+
});
|
|
16
|
+
await initialize({ fusion, { manifest, config }});
|
|
17
|
+
```
|
|
18
|
+
* @template TModules Addition modules
|
|
19
|
+
* @template TRef usually undefined, optional references
|
|
20
|
+
* @template TEnv environment object for configuring modules
|
|
21
|
+
*
|
|
22
|
+
* @param cb configuration callback
|
|
23
|
+
*
|
|
24
|
+
* @returns initialize function, executes configurator
|
|
25
|
+
*/
|
|
26
|
+
export const configureModules =
|
|
27
|
+
<
|
|
28
|
+
TModules extends Array<AnyModule> | never,
|
|
29
|
+
TRef extends Fusion = Fusion,
|
|
30
|
+
TEnv extends AppEnv = AppEnv,
|
|
31
|
+
>(
|
|
32
|
+
cb?: AppModuleInitiator<TModules, TRef, TEnv>,
|
|
33
|
+
): ((args: { fusion: TRef; env: TEnv }) => Promise<AppModulesInstance<TModules>>) =>
|
|
34
|
+
/**
|
|
35
|
+
*
|
|
36
|
+
* Callback for initializing application modules
|
|
37
|
+
*
|
|
38
|
+
* @param args - Fusion and application environments (manifest, config ...)
|
|
39
|
+
* @returns initialized app modules
|
|
40
|
+
*/
|
|
41
|
+
async (args: { fusion: TRef; env: TEnv }): Promise<AppModulesInstance<TModules>> => {
|
|
42
|
+
const configurator = new AppConfigurator<TModules, TRef['modules'], TEnv>(args.env);
|
|
43
|
+
if (cb) {
|
|
44
|
+
await Promise.resolve(cb(configurator, args));
|
|
45
|
+
}
|
|
46
|
+
const modules = (await configurator.initialize(
|
|
47
|
+
args.fusion.modules,
|
|
48
|
+
// TODO
|
|
49
|
+
)) as unknown as AppModulesInstance<TModules>;
|
|
50
|
+
|
|
51
|
+
// @eikeland
|
|
52
|
+
// TODO - remove check after fusion-cli is updated (app module is not enabled in fusion-cli)
|
|
53
|
+
if (args.env.manifest?.key) {
|
|
54
|
+
modules.event.dispatchEvent('onAppModulesLoaded', {
|
|
55
|
+
detail: { appKey: args.env.manifest.key, modules },
|
|
56
|
+
});
|
|
57
|
+
}
|
|
58
|
+
return modules;
|
|
59
|
+
};
|
|
60
|
+
|
|
61
|
+
export default configureModules;
|
package/src/index.ts
ADDED
package/src/types.ts
ADDED
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
import type { Fusion } from '@equinor/fusion-framework';
|
|
2
|
+
|
|
3
|
+
import type { AnyModule } from '@equinor/fusion-framework-module';
|
|
4
|
+
|
|
5
|
+
import type {
|
|
6
|
+
AppConfig,
|
|
7
|
+
AppManifest,
|
|
8
|
+
AppModulesInstance,
|
|
9
|
+
} from '@equinor/fusion-framework-module-app';
|
|
10
|
+
|
|
11
|
+
import type { IAppConfigurator } from './AppConfigurator';
|
|
12
|
+
|
|
13
|
+
export type {
|
|
14
|
+
AppModules,
|
|
15
|
+
AppManifest,
|
|
16
|
+
AppConfig,
|
|
17
|
+
AppModulesInstance,
|
|
18
|
+
} from '@equinor/fusion-framework-module-app';
|
|
19
|
+
|
|
20
|
+
/**
|
|
21
|
+
* Application environment args
|
|
22
|
+
* Arguments provided when initializing/configuring application modules
|
|
23
|
+
*
|
|
24
|
+
* @template TConfig config value type
|
|
25
|
+
* @template TProps [__not in use__] properties for application component
|
|
26
|
+
*/
|
|
27
|
+
export type AppEnv<TConfig = unknown, TProps = unknown> = {
|
|
28
|
+
/** base routing path of the application */
|
|
29
|
+
basename?: string;
|
|
30
|
+
manifest: AppManifest;
|
|
31
|
+
config?: AppConfig<TConfig>;
|
|
32
|
+
props?: TProps;
|
|
33
|
+
};
|
|
34
|
+
|
|
35
|
+
/**
|
|
36
|
+
* Blueprint for initializing application modules
|
|
37
|
+
*
|
|
38
|
+
* @template TModules Addition modules
|
|
39
|
+
* @template TRef usually undefined, optional references
|
|
40
|
+
* @template TEnv environment object for configuring modules
|
|
41
|
+
*/
|
|
42
|
+
export type AppModuleInitiator<
|
|
43
|
+
TModules extends Array<AnyModule> | unknown = unknown,
|
|
44
|
+
TRef extends Fusion = Fusion,
|
|
45
|
+
TEnv = AppEnv,
|
|
46
|
+
> = (
|
|
47
|
+
configurator: IAppConfigurator<TModules, TRef['modules']>,
|
|
48
|
+
args: { fusion: TRef; env: TEnv },
|
|
49
|
+
) => void | Promise<void>;
|
|
50
|
+
|
|
51
|
+
/**
|
|
52
|
+
* Blueprint for creating application initialization
|
|
53
|
+
*
|
|
54
|
+
* @template TModules Addition modules
|
|
55
|
+
* @template TRef usually undefined, optional references
|
|
56
|
+
* @template TEnv environment object for configuring modules
|
|
57
|
+
*/
|
|
58
|
+
export type AppModuleInit<
|
|
59
|
+
TModules extends Array<AnyModule> | unknown,
|
|
60
|
+
TRef extends Fusion = Fusion,
|
|
61
|
+
TEnv = AppEnv,
|
|
62
|
+
> = (
|
|
63
|
+
cb: AppModuleInitiator<TModules, TRef, TEnv>,
|
|
64
|
+
) => (args: { fusion: TRef; env: TEnv }) => Promise<AppModulesInstance<TModules>>;
|
package/src/version.ts
ADDED
package/tsconfig.json
ADDED
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
{
|
|
2
|
+
"extends": "../../tsconfig.base.json",
|
|
3
|
+
"compilerOptions": {
|
|
4
|
+
"outDir": "dist/esm",
|
|
5
|
+
"rootDir": "src",
|
|
6
|
+
"declarationDir": "./dist/types",
|
|
7
|
+
|
|
8
|
+
},
|
|
9
|
+
"references": [
|
|
10
|
+
{
|
|
11
|
+
"path": "../modules/module"
|
|
12
|
+
},
|
|
13
|
+
{
|
|
14
|
+
"path": "../modules/http"
|
|
15
|
+
},
|
|
16
|
+
{
|
|
17
|
+
"path": "../modules/msal"
|
|
18
|
+
},
|
|
19
|
+
{
|
|
20
|
+
"path": "../modules/event"
|
|
21
|
+
},
|
|
22
|
+
{
|
|
23
|
+
"path": "../modules/app"
|
|
24
|
+
},
|
|
25
|
+
{
|
|
26
|
+
"path": "../modules/feature-flag"
|
|
27
|
+
},
|
|
28
|
+
{
|
|
29
|
+
"path": "../framework"
|
|
30
|
+
},
|
|
31
|
+
],
|
|
32
|
+
"include": [
|
|
33
|
+
"src/**/*"
|
|
34
|
+
],
|
|
35
|
+
"exclude": [
|
|
36
|
+
"node_modules",
|
|
37
|
+
"lib"
|
|
38
|
+
]
|
|
39
|
+
}
|