@equinor/fusion-framework 7.3.20 → 7.4.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +29 -0
- package/dist/esm/FrameworkConfigurator.js +170 -3
- package/dist/esm/FrameworkConfigurator.js.map +1 -1
- package/dist/esm/__tests__/FrameworkConfigurator.test.js +29 -0
- package/dist/esm/__tests__/FrameworkConfigurator.test.js.map +1 -0
- package/dist/esm/version.js +1 -1
- package/dist/esm/version.js.map +1 -1
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/dist/types/FrameworkConfigurator.d.ts +152 -1
- package/dist/types/__tests__/FrameworkConfigurator.test.d.ts +1 -0
- package/dist/types/index.d.ts +1 -1
- package/dist/types/init.d.ts +2 -2
- package/dist/types/types.d.ts +3 -1
- package/dist/types/version.d.ts +1 -1
- package/package.json +12 -9
- package/src/FrameworkConfigurator.ts +175 -4
- package/src/__tests__/FrameworkConfigurator.test.ts +35 -0
- package/src/index.ts +1 -1
- package/src/init.ts +2 -2
- package/src/types.ts +10 -1
- package/src/version.ts +1 -1
- package/tsconfig.json +3 -0
- package/vitest.config.ts +10 -0
|
@@ -2,7 +2,8 @@ import { type AnyModule, ModulesConfigurator } from '@equinor/fusion-framework-m
|
|
|
2
2
|
import { configureHttpClient, configureHttp, type HttpClientOptions } from '@equinor/fusion-framework-module-http';
|
|
3
3
|
import type { HttpClientMsal } from '@equinor/fusion-framework-module-http/client';
|
|
4
4
|
import { type AuthConfigFn } from '@equinor/fusion-framework-module-msal';
|
|
5
|
-
import
|
|
5
|
+
import { enableTelemetry } from '@equinor/fusion-framework-module-telemetry';
|
|
6
|
+
import type { FusionModules } from './types.js';
|
|
6
7
|
import type { AuthClientConfig } from '@equinor/fusion-framework-module-msal/v2';
|
|
7
8
|
/**
|
|
8
9
|
* Module configurator for Framework modules
|
|
@@ -10,12 +11,162 @@ import type { AuthClientConfig } from '@equinor/fusion-framework-module-msal/v2'
|
|
|
10
11
|
* @template TRef - usually undefined, optional references
|
|
11
12
|
*/
|
|
12
13
|
export declare class FrameworkConfigurator<TModules extends Array<AnyModule> = [], TRef = any> extends ModulesConfigurator<FusionModules<TModules>, TRef> {
|
|
14
|
+
/**
|
|
15
|
+
* Creates a new FrameworkConfigurator instance with default telemetry configuration.
|
|
16
|
+
*
|
|
17
|
+
* Initializes the framework with core modules (event, auth, http, service discovery,
|
|
18
|
+
* services, context, and telemetry) and sets up default telemetry that includes
|
|
19
|
+
* framework version metadata and 'framework' scope for all telemetry events.
|
|
20
|
+
*
|
|
21
|
+
* @example
|
|
22
|
+
* ```typescript
|
|
23
|
+
* const configurator = new FrameworkConfigurator();
|
|
24
|
+
* // Now ready to configure additional modules
|
|
25
|
+
* ```
|
|
26
|
+
*/
|
|
13
27
|
constructor();
|
|
28
|
+
/**
|
|
29
|
+
* Configures the global HTTP module settings such as base URLs, default headers,
|
|
30
|
+
* request/response interceptors, and timeout settings.
|
|
31
|
+
*
|
|
32
|
+
* This affects all HTTP requests made through the framework's HTTP module.
|
|
33
|
+
* Use this for application-wide HTTP configuration.
|
|
34
|
+
*
|
|
35
|
+
* @param args - HTTP module configuration arguments (same as configureHttp function)
|
|
36
|
+
*
|
|
37
|
+
* @example
|
|
38
|
+
* ```typescript
|
|
39
|
+
* configurator.configureHttp({
|
|
40
|
+
* baseUri: 'https://api.example.com',
|
|
41
|
+
* defaultHeaders: { 'X-App-Version': '1.0.0' }
|
|
42
|
+
* });
|
|
43
|
+
* ```
|
|
44
|
+
*/
|
|
14
45
|
configureHttp(...args: Parameters<typeof configureHttp>): void;
|
|
46
|
+
/**
|
|
47
|
+
* Configures a named HTTP client instance with specific settings.
|
|
48
|
+
*
|
|
49
|
+
* Unlike configureHttp which sets global HTTP settings, this creates a named client
|
|
50
|
+
* that can have its own base URL, headers, interceptors, and other HTTP-specific
|
|
51
|
+
* configuration. Useful for connecting to different APIs or services with different requirements.
|
|
52
|
+
*
|
|
53
|
+
* @param args - HTTP client configuration arguments: [name, clientOptions]
|
|
54
|
+
* where name is a string identifier and clientOptions contains HTTP settings
|
|
55
|
+
*
|
|
56
|
+
* @example
|
|
57
|
+
* ```typescript
|
|
58
|
+
* // Configure a client for external API
|
|
59
|
+
* configurator.configureHttpClient('external-api', {
|
|
60
|
+
* baseUri: 'https://external-api.com',
|
|
61
|
+
* defaultHeaders: { 'Authorization': 'Bearer token' }
|
|
62
|
+
* });
|
|
63
|
+
*
|
|
64
|
+
* // Configure a client for internal services
|
|
65
|
+
* configurator.configureHttpClient('internal', {
|
|
66
|
+
* baseUri: 'https://internal.company.com',
|
|
67
|
+
* timeout: 10000
|
|
68
|
+
* });
|
|
69
|
+
* ```
|
|
70
|
+
*/
|
|
15
71
|
configureHttpClient(...args: Parameters<typeof configureHttpClient>): void;
|
|
72
|
+
/**
|
|
73
|
+
* Configures Microsoft Authentication Library (MSAL) authentication for the framework.
|
|
74
|
+
*
|
|
75
|
+
* This sets up OAuth 2.0 / OpenID Connect authentication using Azure AD or other
|
|
76
|
+
* MSAL-compatible identity providers. The authentication module will handle token
|
|
77
|
+
* acquisition, refresh, and user session management.
|
|
78
|
+
*
|
|
79
|
+
* @param cb_or_config - Authentication configuration. Can be either:
|
|
80
|
+
* - A callback function that receives an auth builder for advanced configuration
|
|
81
|
+
* - A client configuration object with MSAL settings
|
|
82
|
+
* @param requiresAuth - Whether the application requires authentication to function.
|
|
83
|
+
* When true (default), unauthenticated users cannot access the app.
|
|
84
|
+
* When false, authentication is optional but available when needed.
|
|
85
|
+
*
|
|
86
|
+
* @example
|
|
87
|
+
* ```typescript
|
|
88
|
+
* // Simple configuration with client config object
|
|
89
|
+
* configurator.configureMsal({
|
|
90
|
+
* clientId: 'your-client-id',
|
|
91
|
+
* authority: 'https://login.microsoftonline.com/your-tenant-id'
|
|
92
|
+
* });
|
|
93
|
+
*
|
|
94
|
+
* // Advanced configuration with callback
|
|
95
|
+
* configurator.configureMsal((builder) => {
|
|
96
|
+
* builder.setClientConfig({
|
|
97
|
+
* clientId: 'your-client-id',
|
|
98
|
+
* authority: 'https://login.microsoftonline.com/your-tenant-id'
|
|
99
|
+
* });
|
|
100
|
+
* builder.setScopes(['User.Read', 'api://your-api/scope']);
|
|
101
|
+
* builder.setRequiresAuth(true);
|
|
102
|
+
* });
|
|
103
|
+
*
|
|
104
|
+
* // Optional authentication
|
|
105
|
+
* configurator.configureMsal(config, false);
|
|
106
|
+
* ```
|
|
107
|
+
*/
|
|
16
108
|
configureMsal(cb_or_config: AuthConfigFn | AuthClientConfig, requiresAuth?: boolean): void;
|
|
109
|
+
/**
|
|
110
|
+
* Configures the service discovery module to automatically find and connect to services.
|
|
111
|
+
*
|
|
112
|
+
* Service discovery allows the framework to dynamically locate microservices and APIs
|
|
113
|
+
* at runtime rather than hardcoding their URLs. This is essential in distributed systems
|
|
114
|
+
* where services may be deployed across multiple environments or scaled dynamically.
|
|
115
|
+
*
|
|
116
|
+
* @param args - Configuration object for service discovery
|
|
117
|
+
* @param args.client - HTTP client configuration used to communicate with the
|
|
118
|
+
* service discovery registry. Typically includes base URL,
|
|
119
|
+
* authentication, and timeout settings.
|
|
120
|
+
*
|
|
121
|
+
* @example
|
|
122
|
+
* ```typescript
|
|
123
|
+
* configurator.configureServiceDiscovery({
|
|
124
|
+
* client: {
|
|
125
|
+
* baseUri: 'https://service-registry.company.com',
|
|
126
|
+
* defaultHeaders: { 'Authorization': 'Bearer token' },
|
|
127
|
+
* timeout: 5000
|
|
128
|
+
* }
|
|
129
|
+
* });
|
|
130
|
+
* ```
|
|
131
|
+
*/
|
|
17
132
|
configureServiceDiscovery(args: {
|
|
18
133
|
client: HttpClientOptions<HttpClientMsal>;
|
|
19
134
|
}): void;
|
|
135
|
+
/**
|
|
136
|
+
* Configures application telemetry and observability settings.
|
|
137
|
+
*
|
|
138
|
+
* Telemetry enables tracking of application usage, performance metrics, errors,
|
|
139
|
+
* and custom events. This helps with monitoring, debugging, and understanding
|
|
140
|
+
* how your application is being used. The framework comes with default telemetry
|
|
141
|
+
* that includes framework version and scope information.
|
|
142
|
+
*
|
|
143
|
+
* @param cb - Configuration callback function that receives a telemetry builder.
|
|
144
|
+
* Use this to customize telemetry settings like event scopes, metadata,
|
|
145
|
+
* sampling rates, and custom instrumentation.
|
|
146
|
+
*
|
|
147
|
+
* @example
|
|
148
|
+
* ```typescript
|
|
149
|
+
* configurator.configureTelemetry((builder) => {
|
|
150
|
+
* // Add custom metadata to all telemetry events
|
|
151
|
+
* builder.setMetadata({
|
|
152
|
+
* application: 'my-app',
|
|
153
|
+
* environment: 'production',
|
|
154
|
+
* version: '1.2.3'
|
|
155
|
+
* });
|
|
156
|
+
*
|
|
157
|
+
* // Set custom scopes for filtering events
|
|
158
|
+
* builder.setDefaultScope(['app', 'performance']);
|
|
159
|
+
*
|
|
160
|
+
* // Configure sampling (only send 10% of events)
|
|
161
|
+
* builder.setSamplingRate(0.1);
|
|
162
|
+
*
|
|
163
|
+
* // Add custom instrumentation
|
|
164
|
+
* builder.addInstrumentation('custom-operation', (context) => {
|
|
165
|
+
* // Track custom metrics
|
|
166
|
+
* });
|
|
167
|
+
* });
|
|
168
|
+
* ```
|
|
169
|
+
*/
|
|
170
|
+
configureTelemetry(cb: Parameters<typeof enableTelemetry>[1]): void;
|
|
20
171
|
}
|
|
21
172
|
export default FrameworkConfigurator;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
package/dist/types/index.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import type { FrameworkEvent, FrameworkEventInit } from '@equinor/fusion-framework-module-event';
|
|
2
|
-
import type { Fusion } from './types';
|
|
2
|
+
import type { Fusion } from './types.js';
|
|
3
3
|
declare module '@equinor/fusion-framework-module-event' {
|
|
4
4
|
interface FrameworkEventMap {
|
|
5
5
|
onFrameworkLoaded: FrameworkEvent<FrameworkEventInit<Fusion>>;
|
package/dist/types/init.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import type { AnyModule } from '@equinor/fusion-framework-module';
|
|
2
|
-
import type { FrameworkConfigurator } from './FrameworkConfigurator';
|
|
3
|
-
import type { Fusion } from './types';
|
|
2
|
+
import type { FrameworkConfigurator } from './FrameworkConfigurator.js';
|
|
3
|
+
import type { Fusion } from './types.js';
|
|
4
4
|
/**
|
|
5
5
|
*
|
|
6
6
|
* @template TModules addition modules
|
package/dist/types/types.d.ts
CHANGED
|
@@ -6,6 +6,7 @@ import type { HttpModule } from '@equinor/fusion-framework-module-http';
|
|
|
6
6
|
import type { MsalModule } from '@equinor/fusion-framework-module-msal';
|
|
7
7
|
import type { ServiceDiscoveryModule } from '@equinor/fusion-framework-module-service-discovery';
|
|
8
8
|
import type { ServicesModule } from '@equinor/fusion-framework-module-services';
|
|
9
|
+
import type { TelemetryModule } from '@equinor/fusion-framework-module-telemetry';
|
|
9
10
|
/**
|
|
10
11
|
* interface of the modules provided by Fusion Framework
|
|
11
12
|
*/
|
|
@@ -15,7 +16,8 @@ export type FusionModules<TModules extends Array<AnyModule> | unknown = unknown>
|
|
|
15
16
|
HttpModule,
|
|
16
17
|
MsalModule,
|
|
17
18
|
ServicesModule,
|
|
18
|
-
ServiceDiscoveryModule
|
|
19
|
+
ServiceDiscoveryModule,
|
|
20
|
+
TelemetryModule
|
|
19
21
|
]>;
|
|
20
22
|
/**
|
|
21
23
|
* Blueprint of instance of framework modules
|
package/dist/types/version.d.ts
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export declare const version = "7.
|
|
1
|
+
export declare const version = "7.4.0";
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@equinor/fusion-framework",
|
|
3
|
-
"version": "7.
|
|
3
|
+
"version": "7.4.0",
|
|
4
4
|
"description": "",
|
|
5
5
|
"main": "dist/esm/index.js",
|
|
6
6
|
"types": "dist/types/index.d.ts",
|
|
@@ -32,18 +32,21 @@
|
|
|
32
32
|
},
|
|
33
33
|
"dependencies": {
|
|
34
34
|
"rxjs": "^7.8.1",
|
|
35
|
-
"@equinor/fusion-framework-module
|
|
36
|
-
"@equinor/fusion-framework-module": "^
|
|
37
|
-
"@equinor/fusion-framework-module-msal": "^5.0.1",
|
|
35
|
+
"@equinor/fusion-framework-module": "^5.0.3",
|
|
36
|
+
"@equinor/fusion-framework-module-context": "^7.0.1",
|
|
38
37
|
"@equinor/fusion-framework-module-event": "^4.3.7",
|
|
39
|
-
"@equinor/fusion-framework-module-http": "^7.0.
|
|
40
|
-
"@equinor/fusion-framework-module-
|
|
41
|
-
"@equinor/fusion-framework-module-
|
|
38
|
+
"@equinor/fusion-framework-module-http": "^7.0.2",
|
|
39
|
+
"@equinor/fusion-framework-module-msal": "^5.0.1",
|
|
40
|
+
"@equinor/fusion-framework-module-service-discovery": "^9.0.2",
|
|
41
|
+
"@equinor/fusion-framework-module-services": "^7.1.2",
|
|
42
|
+
"@equinor/fusion-framework-module-telemetry": "^4.2.0"
|
|
42
43
|
},
|
|
43
44
|
"devDependencies": {
|
|
44
|
-
"typescript": "^5.8.2"
|
|
45
|
+
"typescript": "^5.8.2",
|
|
46
|
+
"vitest": "^3.2.4"
|
|
45
47
|
},
|
|
46
48
|
"scripts": {
|
|
47
|
-
"build": "tsc -b"
|
|
49
|
+
"build": "tsc -b",
|
|
50
|
+
"test": "vitest --run"
|
|
48
51
|
}
|
|
49
52
|
}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import {
|
|
2
2
|
type AnyModule,
|
|
3
|
-
ModuleConsoleLogger,
|
|
4
3
|
ModulesConfigurator,
|
|
4
|
+
type ModuleEvent,
|
|
5
5
|
} from '@equinor/fusion-framework-module';
|
|
6
6
|
|
|
7
7
|
import event from '@equinor/fusion-framework-module-event';
|
|
@@ -19,9 +19,13 @@ import context from '@equinor/fusion-framework-module-context';
|
|
|
19
19
|
|
|
20
20
|
import disco from '@equinor/fusion-framework-module-service-discovery';
|
|
21
21
|
import services from '@equinor/fusion-framework-module-services';
|
|
22
|
+
import telemetry, { enableTelemetry } from '@equinor/fusion-framework-module-telemetry';
|
|
22
23
|
|
|
23
|
-
import type { FusionModules } from './types';
|
|
24
|
+
import type { FusionModules } from './types.js';
|
|
24
25
|
import type { AuthClientConfig } from '@equinor/fusion-framework-module-msal/v2';
|
|
26
|
+
import { version } from './version.js';
|
|
27
|
+
import { map } from 'rxjs/operators';
|
|
28
|
+
import type { Observable } from 'rxjs';
|
|
25
29
|
|
|
26
30
|
/**
|
|
27
31
|
* Module configurator for Framework modules
|
|
@@ -33,19 +37,124 @@ export class FrameworkConfigurator<
|
|
|
33
37
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
34
38
|
TRef = any,
|
|
35
39
|
> extends ModulesConfigurator<FusionModules<TModules>, TRef> {
|
|
40
|
+
/**
|
|
41
|
+
* Creates a new FrameworkConfigurator instance with default telemetry configuration.
|
|
42
|
+
*
|
|
43
|
+
* Initializes the framework with core modules (event, auth, http, service discovery,
|
|
44
|
+
* services, context, and telemetry) and sets up default telemetry that includes
|
|
45
|
+
* framework version metadata and 'framework' scope for all telemetry events.
|
|
46
|
+
*
|
|
47
|
+
* @example
|
|
48
|
+
* ```typescript
|
|
49
|
+
* const configurator = new FrameworkConfigurator();
|
|
50
|
+
* // Now ready to configure additional modules
|
|
51
|
+
* ```
|
|
52
|
+
*/
|
|
36
53
|
constructor() {
|
|
37
|
-
super([event, auth, http, disco, services, context]);
|
|
38
|
-
|
|
54
|
+
super([event, auth, http, disco, services, context, telemetry]);
|
|
55
|
+
|
|
56
|
+
// default configuration
|
|
57
|
+
enableTelemetry(this, {
|
|
58
|
+
configure: (builder) => {
|
|
59
|
+
builder.setMetadata({
|
|
60
|
+
fusion: {
|
|
61
|
+
type: 'framework-telemetry',
|
|
62
|
+
framework: {
|
|
63
|
+
version,
|
|
64
|
+
},
|
|
65
|
+
},
|
|
66
|
+
});
|
|
67
|
+
builder.setDefaultScope(['framework']);
|
|
68
|
+
},
|
|
69
|
+
});
|
|
39
70
|
}
|
|
40
71
|
|
|
72
|
+
/**
|
|
73
|
+
* Configures the global HTTP module settings such as base URLs, default headers,
|
|
74
|
+
* request/response interceptors, and timeout settings.
|
|
75
|
+
*
|
|
76
|
+
* This affects all HTTP requests made through the framework's HTTP module.
|
|
77
|
+
* Use this for application-wide HTTP configuration.
|
|
78
|
+
*
|
|
79
|
+
* @param args - HTTP module configuration arguments (same as configureHttp function)
|
|
80
|
+
*
|
|
81
|
+
* @example
|
|
82
|
+
* ```typescript
|
|
83
|
+
* configurator.configureHttp({
|
|
84
|
+
* baseUri: 'https://api.example.com',
|
|
85
|
+
* defaultHeaders: { 'X-App-Version': '1.0.0' }
|
|
86
|
+
* });
|
|
87
|
+
* ```
|
|
88
|
+
*/
|
|
41
89
|
public configureHttp(...args: Parameters<typeof configureHttp>) {
|
|
42
90
|
this.addConfig(configureHttp(...args));
|
|
43
91
|
}
|
|
44
92
|
|
|
93
|
+
/**
|
|
94
|
+
* Configures a named HTTP client instance with specific settings.
|
|
95
|
+
*
|
|
96
|
+
* Unlike configureHttp which sets global HTTP settings, this creates a named client
|
|
97
|
+
* that can have its own base URL, headers, interceptors, and other HTTP-specific
|
|
98
|
+
* configuration. Useful for connecting to different APIs or services with different requirements.
|
|
99
|
+
*
|
|
100
|
+
* @param args - HTTP client configuration arguments: [name, clientOptions]
|
|
101
|
+
* where name is a string identifier and clientOptions contains HTTP settings
|
|
102
|
+
*
|
|
103
|
+
* @example
|
|
104
|
+
* ```typescript
|
|
105
|
+
* // Configure a client for external API
|
|
106
|
+
* configurator.configureHttpClient('external-api', {
|
|
107
|
+
* baseUri: 'https://external-api.com',
|
|
108
|
+
* defaultHeaders: { 'Authorization': 'Bearer token' }
|
|
109
|
+
* });
|
|
110
|
+
*
|
|
111
|
+
* // Configure a client for internal services
|
|
112
|
+
* configurator.configureHttpClient('internal', {
|
|
113
|
+
* baseUri: 'https://internal.company.com',
|
|
114
|
+
* timeout: 10000
|
|
115
|
+
* });
|
|
116
|
+
* ```
|
|
117
|
+
*/
|
|
45
118
|
public configureHttpClient(...args: Parameters<typeof configureHttpClient>) {
|
|
46
119
|
this.addConfig(configureHttpClient(...args));
|
|
47
120
|
}
|
|
48
121
|
|
|
122
|
+
/**
|
|
123
|
+
* Configures Microsoft Authentication Library (MSAL) authentication for the framework.
|
|
124
|
+
*
|
|
125
|
+
* This sets up OAuth 2.0 / OpenID Connect authentication using Azure AD or other
|
|
126
|
+
* MSAL-compatible identity providers. The authentication module will handle token
|
|
127
|
+
* acquisition, refresh, and user session management.
|
|
128
|
+
*
|
|
129
|
+
* @param cb_or_config - Authentication configuration. Can be either:
|
|
130
|
+
* - A callback function that receives an auth builder for advanced configuration
|
|
131
|
+
* - A client configuration object with MSAL settings
|
|
132
|
+
* @param requiresAuth - Whether the application requires authentication to function.
|
|
133
|
+
* When true (default), unauthenticated users cannot access the app.
|
|
134
|
+
* When false, authentication is optional but available when needed.
|
|
135
|
+
*
|
|
136
|
+
* @example
|
|
137
|
+
* ```typescript
|
|
138
|
+
* // Simple configuration with client config object
|
|
139
|
+
* configurator.configureMsal({
|
|
140
|
+
* clientId: 'your-client-id',
|
|
141
|
+
* authority: 'https://login.microsoftonline.com/your-tenant-id'
|
|
142
|
+
* });
|
|
143
|
+
*
|
|
144
|
+
* // Advanced configuration with callback
|
|
145
|
+
* configurator.configureMsal((builder) => {
|
|
146
|
+
* builder.setClientConfig({
|
|
147
|
+
* clientId: 'your-client-id',
|
|
148
|
+
* authority: 'https://login.microsoftonline.com/your-tenant-id'
|
|
149
|
+
* });
|
|
150
|
+
* builder.setScopes(['User.Read', 'api://your-api/scope']);
|
|
151
|
+
* builder.setRequiresAuth(true);
|
|
152
|
+
* });
|
|
153
|
+
*
|
|
154
|
+
* // Optional authentication
|
|
155
|
+
* configurator.configureMsal(config, false);
|
|
156
|
+
* ```
|
|
157
|
+
*/
|
|
49
158
|
public configureMsal(cb_or_config: AuthConfigFn | AuthClientConfig, requiresAuth = true) {
|
|
50
159
|
this.addConfig({
|
|
51
160
|
module: auth,
|
|
@@ -63,9 +172,71 @@ export class FrameworkConfigurator<
|
|
|
63
172
|
});
|
|
64
173
|
}
|
|
65
174
|
|
|
175
|
+
/**
|
|
176
|
+
* Configures the service discovery module to automatically find and connect to services.
|
|
177
|
+
*
|
|
178
|
+
* Service discovery allows the framework to dynamically locate microservices and APIs
|
|
179
|
+
* at runtime rather than hardcoding their URLs. This is essential in distributed systems
|
|
180
|
+
* where services may be deployed across multiple environments or scaled dynamically.
|
|
181
|
+
*
|
|
182
|
+
* @param args - Configuration object for service discovery
|
|
183
|
+
* @param args.client - HTTP client configuration used to communicate with the
|
|
184
|
+
* service discovery registry. Typically includes base URL,
|
|
185
|
+
* authentication, and timeout settings.
|
|
186
|
+
*
|
|
187
|
+
* @example
|
|
188
|
+
* ```typescript
|
|
189
|
+
* configurator.configureServiceDiscovery({
|
|
190
|
+
* client: {
|
|
191
|
+
* baseUri: 'https://service-registry.company.com',
|
|
192
|
+
* defaultHeaders: { 'Authorization': 'Bearer token' },
|
|
193
|
+
* timeout: 5000
|
|
194
|
+
* }
|
|
195
|
+
* });
|
|
196
|
+
* ```
|
|
197
|
+
*/
|
|
66
198
|
public configureServiceDiscovery(args: { client: HttpClientOptions<HttpClientMsal> }) {
|
|
67
199
|
this.configureHttpClient('service_discovery', args.client);
|
|
68
200
|
}
|
|
201
|
+
|
|
202
|
+
/**
|
|
203
|
+
* Configures application telemetry and observability settings.
|
|
204
|
+
*
|
|
205
|
+
* Telemetry enables tracking of application usage, performance metrics, errors,
|
|
206
|
+
* and custom events. This helps with monitoring, debugging, and understanding
|
|
207
|
+
* how your application is being used. The framework comes with default telemetry
|
|
208
|
+
* that includes framework version and scope information.
|
|
209
|
+
*
|
|
210
|
+
* @param cb - Configuration callback function that receives a telemetry builder.
|
|
211
|
+
* Use this to customize telemetry settings like event scopes, metadata,
|
|
212
|
+
* sampling rates, and custom instrumentation.
|
|
213
|
+
*
|
|
214
|
+
* @example
|
|
215
|
+
* ```typescript
|
|
216
|
+
* configurator.configureTelemetry((builder) => {
|
|
217
|
+
* // Add custom metadata to all telemetry events
|
|
218
|
+
* builder.setMetadata({
|
|
219
|
+
* application: 'my-app',
|
|
220
|
+
* environment: 'production',
|
|
221
|
+
* version: '1.2.3'
|
|
222
|
+
* });
|
|
223
|
+
*
|
|
224
|
+
* // Set custom scopes for filtering events
|
|
225
|
+
* builder.setDefaultScope(['app', 'performance']);
|
|
226
|
+
*
|
|
227
|
+
* // Configure sampling (only send 10% of events)
|
|
228
|
+
* builder.setSamplingRate(0.1);
|
|
229
|
+
*
|
|
230
|
+
* // Add custom instrumentation
|
|
231
|
+
* builder.addInstrumentation('custom-operation', (context) => {
|
|
232
|
+
* // Track custom metrics
|
|
233
|
+
* });
|
|
234
|
+
* });
|
|
235
|
+
* ```
|
|
236
|
+
*/
|
|
237
|
+
public configureTelemetry(cb: Parameters<typeof enableTelemetry>[1]): void {
|
|
238
|
+
enableTelemetry(this, cb);
|
|
239
|
+
}
|
|
69
240
|
}
|
|
70
241
|
|
|
71
242
|
export default FrameworkConfigurator;
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import { describe, it, expect, beforeEach } from 'vitest';
|
|
2
|
+
import { firstValueFrom, take } from 'rxjs';
|
|
3
|
+
import { FrameworkConfigurator } from '../FrameworkConfigurator.js';
|
|
4
|
+
import type { AnyModule } from '@equinor/fusion-framework-module';
|
|
5
|
+
import { SemanticVersion } from '@equinor/fusion-framework-module';
|
|
6
|
+
|
|
7
|
+
describe('FrameworkConfigurator', () => {
|
|
8
|
+
let configurator: FrameworkConfigurator;
|
|
9
|
+
|
|
10
|
+
// Create a mock module for testing
|
|
11
|
+
const createMockModule = (name: string, version = '1.0.0'): AnyModule => ({
|
|
12
|
+
name,
|
|
13
|
+
version: new SemanticVersion(version),
|
|
14
|
+
initialize: () => ({ mockInstance: true }),
|
|
15
|
+
});
|
|
16
|
+
|
|
17
|
+
beforeEach(() => {
|
|
18
|
+
configurator = new FrameworkConfigurator();
|
|
19
|
+
});
|
|
20
|
+
|
|
21
|
+
describe('Event Name Prefixing', () => {
|
|
22
|
+
it('should prefix event names with "FrameworkConfigurator::"', async () => {
|
|
23
|
+
// Trigger event by adding a config
|
|
24
|
+
configurator.addConfig({
|
|
25
|
+
module: createMockModule('test', '1.0.0'),
|
|
26
|
+
configure: () => {},
|
|
27
|
+
});
|
|
28
|
+
|
|
29
|
+
// Wait for the first event to be emitted
|
|
30
|
+
const event = await firstValueFrom(configurator.event$.pipe(take(1)));
|
|
31
|
+
|
|
32
|
+
expect(event.name).toMatch(/^FrameworkConfigurator::/);
|
|
33
|
+
});
|
|
34
|
+
});
|
|
35
|
+
});
|
package/src/index.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import type { FrameworkEvent, FrameworkEventInit } from '@equinor/fusion-framework-module-event';
|
|
2
|
-
import type { Fusion } from './types';
|
|
2
|
+
import type { Fusion } from './types.js';
|
|
3
3
|
|
|
4
4
|
declare module '@equinor/fusion-framework-module-event' {
|
|
5
5
|
interface FrameworkEventMap {
|
package/src/init.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import type { AnyModule } from '@equinor/fusion-framework-module';
|
|
2
2
|
|
|
3
|
-
import type { FrameworkConfigurator } from './FrameworkConfigurator';
|
|
4
|
-
import type { Fusion, FusionModules } from './types';
|
|
3
|
+
import type { FrameworkConfigurator } from './FrameworkConfigurator.js';
|
|
4
|
+
import type { Fusion, FusionModules } from './types.js';
|
|
5
5
|
|
|
6
6
|
/**
|
|
7
7
|
*
|
package/src/types.ts
CHANGED
|
@@ -7,13 +7,22 @@ import type { HttpModule } from '@equinor/fusion-framework-module-http';
|
|
|
7
7
|
import type { MsalModule } from '@equinor/fusion-framework-module-msal';
|
|
8
8
|
import type { ServiceDiscoveryModule } from '@equinor/fusion-framework-module-service-discovery';
|
|
9
9
|
import type { ServicesModule } from '@equinor/fusion-framework-module-services';
|
|
10
|
+
import type { TelemetryModule } from '@equinor/fusion-framework-module-telemetry';
|
|
10
11
|
|
|
11
12
|
/**
|
|
12
13
|
* interface of the modules provided by Fusion Framework
|
|
13
14
|
*/
|
|
14
15
|
export type FusionModules<TModules extends Array<AnyModule> | unknown = unknown> = CombinedModules<
|
|
15
16
|
TModules,
|
|
16
|
-
[
|
|
17
|
+
[
|
|
18
|
+
ContextModule,
|
|
19
|
+
EventModule,
|
|
20
|
+
HttpModule,
|
|
21
|
+
MsalModule,
|
|
22
|
+
ServicesModule,
|
|
23
|
+
ServiceDiscoveryModule,
|
|
24
|
+
TelemetryModule,
|
|
25
|
+
]
|
|
17
26
|
>;
|
|
18
27
|
|
|
19
28
|
/**
|
package/src/version.ts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
// Generated by genversion.
|
|
2
|
-
export const version = '7.
|
|
2
|
+
export const version = '7.4.0';
|
package/tsconfig.json
CHANGED