@equinor/roma-nx-plugin 6.0.0-beta.10 → 6.0.0-beta.12
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 +19 -0
- package/migrations.json +6 -6
- package/package.json +2 -3
- package/src/executors/create-vite-config.js +1 -0
- package/src/executors/create-vite-config.js.map +1 -1
- package/src/executors/publish/manifest-model.d.ts +11 -0
- package/src/executors/publish/publish-script.js +78 -1
- package/src/executors/publish/publish-script.js.map +1 -1
- package/src/executors/publish/readme.md +83 -27
- package/src/executors/serve/server.js +8 -9
- package/src/executors/serve/server.js.map +1 -1
- package/src/executors/utils/load-services.js.map +1 -1
- package/src/executors/utils/logger.js +5 -2
- package/src/executors/utils/logger.js.map +1 -1
- package/src/executors/utils/read-manifest.js +4 -1
- package/src/executors/utils/read-manifest.js.map +1 -1
- package/src/executors/utils/verify-manifest.d.ts +2 -0
- package/src/executors/utils/verify-manifest.js +18 -0
- package/src/executors/utils/verify-manifest.js.map +1 -0
- package/src/generators/app/data/generated-dependencies.json +1 -1
- package/src/generators/skill/files/roma-app-development/SKILL.md +4 -0
- package/src/generators/skill/files/roma-app-development/fusion-modules.md +577 -0
- package/src/generators/skill/files/roma-app-development/roma-modules.md +409 -0
- package/src/generators/skill/files/roma-app-development/services.md +2 -23
- package/src/migrations/migrate-fusion-manifest/update-manifest.d.ts +2 -5
- package/src/migrations/migrate-fusion-manifest/update-manifest.js.map +1 -1
|
@@ -0,0 +1,577 @@
|
|
|
1
|
+
# Fusion Framework Modules
|
|
2
|
+
|
|
3
|
+
Reference for the Fusion Framework modules available to Roma applications. Each module follows the same pattern: enable in `config.ts`, access via provider or React hook.
|
|
4
|
+
|
|
5
|
+
---
|
|
6
|
+
|
|
7
|
+
## Event
|
|
8
|
+
|
|
9
|
+
**Package:** `@equinor/fusion-framework-module-event`
|
|
10
|
+
|
|
11
|
+
Async event dispatching for type-safe communication between modules. Modeled after DOM EventTarget with async support and RxJS observable streams.
|
|
12
|
+
|
|
13
|
+
### Key Exports
|
|
14
|
+
|
|
15
|
+
| Export | Kind | Description |
|
|
16
|
+
|--------|------|-------------|
|
|
17
|
+
| `FrameworkEvent` | Class | Base event class |
|
|
18
|
+
| `EventModuleProvider` | Class | Runtime provider |
|
|
19
|
+
| `addEventListener` | Method | Register a listener (returns teardown function) |
|
|
20
|
+
| `dispatchEvent` | Method | Emit an event (must `await`) |
|
|
21
|
+
| `event$` | Observable | RxJS stream of all events |
|
|
22
|
+
|
|
23
|
+
### Usage
|
|
24
|
+
|
|
25
|
+
The event module is available on the framework by default — no `enable*()` call is needed.
|
|
26
|
+
|
|
27
|
+
#### Dispatching events
|
|
28
|
+
|
|
29
|
+
```typescript
|
|
30
|
+
import { useFramework } from '@equinor/fusion-framework-react';
|
|
31
|
+
|
|
32
|
+
const { event } = useFramework().modules;
|
|
33
|
+
|
|
34
|
+
// Dispatch a custom event (must be awaited)
|
|
35
|
+
await event.dispatchEvent('onMyCustomEvent', {
|
|
36
|
+
detail: { someData: 'value' },
|
|
37
|
+
source: MyComponent,
|
|
38
|
+
});
|
|
39
|
+
```
|
|
40
|
+
|
|
41
|
+
#### Listening for events
|
|
42
|
+
|
|
43
|
+
```typescript
|
|
44
|
+
import { useFramework } from '@equinor/fusion-framework-react';
|
|
45
|
+
import { useEffect } from 'react';
|
|
46
|
+
|
|
47
|
+
const { event } = useFramework().modules;
|
|
48
|
+
|
|
49
|
+
useEffect(() => {
|
|
50
|
+
const sub = event.event$
|
|
51
|
+
.pipe(filter((e) => e.type === 'onDensityChanged'))
|
|
52
|
+
.subscribe((e) => {
|
|
53
|
+
setDensity(e.detail);
|
|
54
|
+
});
|
|
55
|
+
return () => sub.unsubscribe();
|
|
56
|
+
}, [event]);
|
|
57
|
+
```
|
|
58
|
+
|
|
59
|
+
#### Roma example: density toggling
|
|
60
|
+
|
|
61
|
+
From `libs/roma-framework/src/lib/dev-portal/HeaderMenu.tsx`:
|
|
62
|
+
|
|
63
|
+
```typescript
|
|
64
|
+
const { event } = useFramework().modules;
|
|
65
|
+
|
|
66
|
+
const toggleDensity = (newDensity: 'comfortable' | 'compact') => {
|
|
67
|
+
localStorage.setItem('roma__density', newDensity);
|
|
68
|
+
const e = new CustomEvent('onDensityChanged', { detail: newDensity });
|
|
69
|
+
event.dispatchEvent('onDensityChanged', e);
|
|
70
|
+
};
|
|
71
|
+
```
|
|
72
|
+
|
|
73
|
+
#### Roma example: app lifecycle
|
|
74
|
+
|
|
75
|
+
From `libs/roma-framework/src/lib/make-component.tsx`:
|
|
76
|
+
|
|
77
|
+
```typescript
|
|
78
|
+
import { EventModule } from '@equinor/fusion-framework-module-event';
|
|
79
|
+
|
|
80
|
+
// Dispatch when app loads
|
|
81
|
+
modules.event.dispatchEvent('onReactAppLoaded', {
|
|
82
|
+
detail: { modules, fusion },
|
|
83
|
+
source: Component,
|
|
84
|
+
});
|
|
85
|
+
```
|
|
86
|
+
|
|
87
|
+
---
|
|
88
|
+
|
|
89
|
+
## MSAL (Authentication)
|
|
90
|
+
|
|
91
|
+
**Package:** `@equinor/fusion-framework-module-msal`
|
|
92
|
+
|
|
93
|
+
Microsoft Authentication Library integration for Azure AD / Entra ID. Provides automatic token management, module hoisting for shared auth state, and SSO support.
|
|
94
|
+
|
|
95
|
+
### Key Exports
|
|
96
|
+
|
|
97
|
+
| Export | Kind | Description |
|
|
98
|
+
|--------|------|-------------|
|
|
99
|
+
| `enableMSAL` | Function | Module enabler |
|
|
100
|
+
| `MsalProvider` | Class | Runtime auth provider |
|
|
101
|
+
| `AccountInfo` | Type | User account information |
|
|
102
|
+
| `AuthenticationResult` | Type | Auth result with tokens |
|
|
103
|
+
|
|
104
|
+
### Configuration
|
|
105
|
+
|
|
106
|
+
MSAL is typically configured at the portal level — Roma apps inherit auth from the workbench framework. Apps rarely need to call `enableMSAL()` directly.
|
|
107
|
+
|
|
108
|
+
```typescript
|
|
109
|
+
// Portal-level configuration (for reference)
|
|
110
|
+
enableMSAL(configurator, (builder) => {
|
|
111
|
+
builder.setClientConfig({
|
|
112
|
+
auth: {
|
|
113
|
+
clientId: 'your-client-id',
|
|
114
|
+
tenantId: '3aa4a235-b6e2-48d5-9195-7fcf05b459b0',
|
|
115
|
+
redirectUri: 'https://roma.equinor.com/callback',
|
|
116
|
+
},
|
|
117
|
+
});
|
|
118
|
+
builder.setRequiresAuth(true);
|
|
119
|
+
});
|
|
120
|
+
```
|
|
121
|
+
|
|
122
|
+
### Accessing auth in components
|
|
123
|
+
|
|
124
|
+
#### Get current user account
|
|
125
|
+
|
|
126
|
+
```typescript
|
|
127
|
+
import { useFramework } from '@equinor/fusion-framework-react';
|
|
128
|
+
|
|
129
|
+
const { auth } = useFramework().modules;
|
|
130
|
+
const user = auth.defaultAccount;
|
|
131
|
+
const userId = user?.username.split('@')[0].toLowerCase();
|
|
132
|
+
```
|
|
133
|
+
|
|
134
|
+
#### Get user from app context
|
|
135
|
+
|
|
136
|
+
```typescript
|
|
137
|
+
import { useAppModules } from '@equinor/fusion-framework-react-app';
|
|
138
|
+
|
|
139
|
+
const auth = useAppModules().auth;
|
|
140
|
+
const username = auth?.account?.username.split('@')[0];
|
|
141
|
+
```
|
|
142
|
+
|
|
143
|
+
#### Acquire access token (for custom API calls)
|
|
144
|
+
|
|
145
|
+
```typescript
|
|
146
|
+
const token = await auth.acquireAccessToken({
|
|
147
|
+
request: {
|
|
148
|
+
scopes: ['api://my-api/.default'],
|
|
149
|
+
},
|
|
150
|
+
});
|
|
151
|
+
```
|
|
152
|
+
|
|
153
|
+
#### Roma example: user info in header
|
|
154
|
+
|
|
155
|
+
From `libs/roma-framework/src/lib/dev-portal/HeaderMenu.tsx`:
|
|
156
|
+
|
|
157
|
+
```typescript
|
|
158
|
+
import { AccountInfo } from '@equinor/fusion-framework-module-msal';
|
|
159
|
+
|
|
160
|
+
const { auth } = useFramework().modules;
|
|
161
|
+
const user = useMemo(() => {
|
|
162
|
+
return auth.account as AccountInfo & {
|
|
163
|
+
idTokenClaims: TokenClaims;
|
|
164
|
+
};
|
|
165
|
+
}, [auth]);
|
|
166
|
+
```
|
|
167
|
+
|
|
168
|
+
### Checking API roles
|
|
169
|
+
|
|
170
|
+
Roma provides convenience hooks for role-based access:
|
|
171
|
+
|
|
172
|
+
```typescript
|
|
173
|
+
import { useGetApiRoles, useHasApiRole } from '@equinor/roma-framework';
|
|
174
|
+
|
|
175
|
+
const roles = useGetApiRoles('ratscore');
|
|
176
|
+
const isAdmin = useHasApiRole('portal', 'Admin');
|
|
177
|
+
```
|
|
178
|
+
|
|
179
|
+
---
|
|
180
|
+
|
|
181
|
+
## Navigation
|
|
182
|
+
|
|
183
|
+
**Package:** `@equinor/fusion-framework-module-navigation`
|
|
184
|
+
|
|
185
|
+
Routing and navigation with observable state management, automatic basename localization, and support for browser, hash, and memory history types.
|
|
186
|
+
|
|
187
|
+
### Key Exports
|
|
188
|
+
|
|
189
|
+
| Export | Kind | Description |
|
|
190
|
+
|--------|------|-------------|
|
|
191
|
+
| `enableNavigation` | Function | Module enabler |
|
|
192
|
+
| `NavigationModule` | Type | Module type for generics |
|
|
193
|
+
| `NavigationProvider` | Class | Runtime provider |
|
|
194
|
+
| `navigator` | Property | History-like navigation API |
|
|
195
|
+
| `state$` | Observable | Navigation state changes |
|
|
196
|
+
|
|
197
|
+
### Configuration
|
|
198
|
+
|
|
199
|
+
Enable in your app's `config.ts`:
|
|
200
|
+
|
|
201
|
+
```typescript
|
|
202
|
+
import { enableNavigation } from '@equinor/fusion-framework-module-navigation';
|
|
203
|
+
import type { AppModuleInitiator } from '@equinor/fusion-framework-react-app';
|
|
204
|
+
|
|
205
|
+
export const configure: AppModuleInitiator = (configurator, env) => {
|
|
206
|
+
enableNavigation(configurator, '/apps/my-app');
|
|
207
|
+
};
|
|
208
|
+
```
|
|
209
|
+
|
|
210
|
+
### React hooks
|
|
211
|
+
|
|
212
|
+
#### Using `useNavigationModule()`
|
|
213
|
+
|
|
214
|
+
```typescript
|
|
215
|
+
import { useNavigationModule } from '@equinor/fusion-framework-react-app/navigation';
|
|
216
|
+
|
|
217
|
+
const { navigator } = useNavigationModule();
|
|
218
|
+
navigator.push('/apps/my-app/details/123');
|
|
219
|
+
```
|
|
220
|
+
|
|
221
|
+
#### Using `useAppModule()` with NavigationModule type
|
|
222
|
+
|
|
223
|
+
```typescript
|
|
224
|
+
import { useAppModule } from '@equinor/fusion-framework-react-app';
|
|
225
|
+
import { NavigationModule } from '@equinor/fusion-framework-module-navigation';
|
|
226
|
+
|
|
227
|
+
const module = useAppModule<NavigationModule>('navigation');
|
|
228
|
+
```
|
|
229
|
+
|
|
230
|
+
#### Creating a router
|
|
231
|
+
|
|
232
|
+
```typescript
|
|
233
|
+
import { useAppModule } from '@equinor/fusion-framework-react-app';
|
|
234
|
+
import { NavigationModule } from '@equinor/fusion-framework-module-navigation';
|
|
235
|
+
|
|
236
|
+
const module = useAppModule<NavigationModule>('navigation');
|
|
237
|
+
const router = module.createRouter([
|
|
238
|
+
{ path: '/', element: <Home /> },
|
|
239
|
+
{ path: '/details/:id', element: <Details /> },
|
|
240
|
+
]);
|
|
241
|
+
|
|
242
|
+
// In your component:
|
|
243
|
+
return <RouterProvider router={router} />;
|
|
244
|
+
```
|
|
245
|
+
|
|
246
|
+
### Roma examples
|
|
247
|
+
|
|
248
|
+
#### App config with navigation
|
|
249
|
+
|
|
250
|
+
From `apps/applications/administration/src/config.ts`:
|
|
251
|
+
|
|
252
|
+
```typescript
|
|
253
|
+
import { enableNavigation } from '@equinor/fusion-framework-module-navigation';
|
|
254
|
+
|
|
255
|
+
export const configure: AppModuleInitiator = (configurator, env) => {
|
|
256
|
+
enableNavigation(configurator, '/apps/administration');
|
|
257
|
+
};
|
|
258
|
+
```
|
|
259
|
+
|
|
260
|
+
#### Custom navigation hook
|
|
261
|
+
|
|
262
|
+
From `apps/applications/notifications/src/utils/useNavigate.tsx`:
|
|
263
|
+
|
|
264
|
+
```typescript
|
|
265
|
+
import { useFramework } from '@equinor/fusion-framework-react';
|
|
266
|
+
import { NavigationModule } from '@equinor/fusion-framework-module-navigation';
|
|
267
|
+
|
|
268
|
+
export const useNavigate = (path: string, toggleNotificationsOpen?: (open: boolean) => void) => {
|
|
269
|
+
const module = useFramework<[NavigationModule]>().modules.navigation;
|
|
270
|
+
return (event: MouseEvent<HTMLAnchorElement>) => {
|
|
271
|
+
event.preventDefault();
|
|
272
|
+
module.navigator.push(path);
|
|
273
|
+
toggleNotificationsOpen?.(false);
|
|
274
|
+
};
|
|
275
|
+
};
|
|
276
|
+
```
|
|
277
|
+
|
|
278
|
+
#### Framework-level navigation
|
|
279
|
+
|
|
280
|
+
From `apps/widgets/homepage/src/components/trading/columns.tsx`:
|
|
281
|
+
|
|
282
|
+
```typescript
|
|
283
|
+
import { useNavigationModule } from '@equinor/fusion-framework-react-app/navigation';
|
|
284
|
+
|
|
285
|
+
const { navigator } = useNavigationModule();
|
|
286
|
+
```
|
|
287
|
+
|
|
288
|
+
---
|
|
289
|
+
|
|
290
|
+
## Service Discovery
|
|
291
|
+
|
|
292
|
+
**Package:** `@equinor/fusion-framework-module-service-discovery`
|
|
293
|
+
|
|
294
|
+
Resolves service endpoint URIs and OAuth scopes from a central discovery API. Apps request services by name without hard-coding URLs.
|
|
295
|
+
|
|
296
|
+
### Key Exports
|
|
297
|
+
|
|
298
|
+
| Export | Kind | Description |
|
|
299
|
+
|--------|------|-------------|
|
|
300
|
+
| `enableServiceDiscovery` | Function | Module enabler |
|
|
301
|
+
| `ServiceDiscoveryProvider` | Class | Runtime provider |
|
|
302
|
+
| `resolveService` | Method | Get a service's endpoint and config |
|
|
303
|
+
| `createClient` | Method | Get a pre-configured HTTP client for a service |
|
|
304
|
+
|
|
305
|
+
### How it works in Roma
|
|
306
|
+
|
|
307
|
+
Service discovery is configured at the portal level. Roma apps use `configurator.useFrameworkServiceClient()` in their `config.ts` to register named HTTP clients that are resolved via service discovery:
|
|
308
|
+
|
|
309
|
+
```typescript
|
|
310
|
+
export const configure: AppModuleInitiator = (configurator, env) => {
|
|
311
|
+
// Each call registers a named HTTP client backed by the service's config
|
|
312
|
+
configurator.useFrameworkServiceClient('portal');
|
|
313
|
+
configurator.useFrameworkServiceClient('ratscore');
|
|
314
|
+
configurator.useFrameworkServiceClient('waterborne-cargo');
|
|
315
|
+
configurator.useFrameworkServiceClient('graph');
|
|
316
|
+
};
|
|
317
|
+
```
|
|
318
|
+
|
|
319
|
+
The services available are listed at `https://roma.equinor.com/_discovery/environments/current`.
|
|
320
|
+
|
|
321
|
+
### Portal-level configuration
|
|
322
|
+
|
|
323
|
+
From `libs/roma-framework/src/lib/dev-portal/config/config.ts`:
|
|
324
|
+
|
|
325
|
+
```typescript
|
|
326
|
+
import { enableServiceDiscovery } from '@equinor/fusion-framework-module-service-discovery';
|
|
327
|
+
|
|
328
|
+
enableServiceDiscovery(config, async (builder) => {
|
|
329
|
+
builder.setServiceDiscoveryClient(new ServiceDiscoveryClient());
|
|
330
|
+
});
|
|
331
|
+
```
|
|
332
|
+
|
|
333
|
+
### Custom service discovery client
|
|
334
|
+
|
|
335
|
+
From `libs/roma-framework/src/lib/dev-portal/config/ServiceDiscoveryClient.ts`:
|
|
336
|
+
|
|
337
|
+
```typescript
|
|
338
|
+
import { Service } from '@equinor/fusion-framework-module-service-discovery';
|
|
339
|
+
|
|
340
|
+
export class ServiceDiscoveryClient {
|
|
341
|
+
async resolveService(key: string): Promise<Service> {
|
|
342
|
+
return this.resolveServices().then(
|
|
343
|
+
(services) => services.find((s) => s.key === key)!
|
|
344
|
+
);
|
|
345
|
+
}
|
|
346
|
+
|
|
347
|
+
async resolveServices(): Promise<Array<Service>> {
|
|
348
|
+
return fetch('/_discovery/environments/current')
|
|
349
|
+
.then((r) => r.json())
|
|
350
|
+
.then((r) => {
|
|
351
|
+
const services = r.services.map((s) => ({
|
|
352
|
+
...s,
|
|
353
|
+
scopes: s.defaultScopes,
|
|
354
|
+
}));
|
|
355
|
+
return services;
|
|
356
|
+
});
|
|
357
|
+
}
|
|
358
|
+
}
|
|
359
|
+
```
|
|
360
|
+
|
|
361
|
+
### Resolving services programmatically
|
|
362
|
+
|
|
363
|
+
From `libs/modules/sse/src/lib/utils/configure-from-framework.ts`:
|
|
364
|
+
|
|
365
|
+
```typescript
|
|
366
|
+
import { ServiceDiscoveryModule } from '@equinor/fusion-framework-module-service-discovery';
|
|
367
|
+
|
|
368
|
+
const serviceDiscovery = await builder.requireInstance('serviceDiscovery');
|
|
369
|
+
const service = await serviceDiscovery.resolveService('activity');
|
|
370
|
+
```
|
|
371
|
+
|
|
372
|
+
---
|
|
373
|
+
|
|
374
|
+
## Feature Flag
|
|
375
|
+
|
|
376
|
+
**Package:** `@equinor/fusion-framework-module-feature-flag`
|
|
377
|
+
|
|
378
|
+
Plugin-based feature flag management with support for localStorage persistence, URL toggling, and remote API sources.
|
|
379
|
+
|
|
380
|
+
> **Note:** This module is not yet used in the Roma workbench but is available for adoption.
|
|
381
|
+
|
|
382
|
+
### Key Exports
|
|
383
|
+
|
|
384
|
+
| Export | Kind | Description |
|
|
385
|
+
|--------|------|-------------|
|
|
386
|
+
| `enableFeatureFlagging` | Function | Module enabler |
|
|
387
|
+
| `FeatureFlagProvider` | Class | Runtime provider |
|
|
388
|
+
| `createLocalStoragePlugin` | Factory | Persist flags to localStorage |
|
|
389
|
+
| `createUrlPlugin` | Factory | Toggle flags via URL params |
|
|
390
|
+
| `createApiPlugin` | Factory | Load flags from remote API |
|
|
391
|
+
| `features$` | Observable | All feature flags |
|
|
392
|
+
|
|
393
|
+
### Configuration
|
|
394
|
+
|
|
395
|
+
```typescript
|
|
396
|
+
import { enableFeatureFlagging } from '@equinor/fusion-framework-module-feature-flag';
|
|
397
|
+
import {
|
|
398
|
+
createLocalStoragePlugin,
|
|
399
|
+
createUrlPlugin,
|
|
400
|
+
} from '@equinor/fusion-framework-module-feature-flag/plugins';
|
|
401
|
+
|
|
402
|
+
export const configure: AppModuleInitiator = (configurator, env) => {
|
|
403
|
+
enableFeatureFlagging(configurator, (builder) => {
|
|
404
|
+
builder.addPlugin(
|
|
405
|
+
createLocalStoragePlugin([
|
|
406
|
+
{ key: 'dark-mode', title: 'Dark mode', enabled: false },
|
|
407
|
+
{ key: 'beta-search', title: 'Beta search', enabled: false },
|
|
408
|
+
{ key: 'new-dashboard', title: 'New dashboard', enabled: true },
|
|
409
|
+
])
|
|
410
|
+
);
|
|
411
|
+
// Allow toggling via URL: ?beta-search=true
|
|
412
|
+
builder.addPlugin(createUrlPlugin(['beta-search']));
|
|
413
|
+
});
|
|
414
|
+
};
|
|
415
|
+
```
|
|
416
|
+
|
|
417
|
+
### Usage in components
|
|
418
|
+
|
|
419
|
+
```typescript
|
|
420
|
+
// Get a specific feature flag
|
|
421
|
+
const darkMode = modules.featureFlag.getFeature('dark-mode');
|
|
422
|
+
|
|
423
|
+
// Toggle a feature flag
|
|
424
|
+
modules.featureFlag.toggleFeature({ key: 'dark-mode', enabled: true });
|
|
425
|
+
|
|
426
|
+
// Subscribe to all flags
|
|
427
|
+
modules.featureFlag.features$.subscribe((flags) => {
|
|
428
|
+
console.log('Current flags:', flags);
|
|
429
|
+
});
|
|
430
|
+
```
|
|
431
|
+
|
|
432
|
+
---
|
|
433
|
+
|
|
434
|
+
## Telemetry
|
|
435
|
+
|
|
436
|
+
**Package:** `@equinor/fusion-framework-module-telemetry`
|
|
437
|
+
|
|
438
|
+
Unified telemetry for tracking events, exceptions, metrics, and custom data. Supports pluggable adapters (Console, Application Insights) and hierarchical provider composition.
|
|
439
|
+
|
|
440
|
+
### Key Exports
|
|
441
|
+
|
|
442
|
+
| Export | Kind | Description |
|
|
443
|
+
|--------|------|-------------|
|
|
444
|
+
| `enableTelemetry` | Function | Module enabler |
|
|
445
|
+
| `ITelemetryProvider` | Interface | Provider for tracking |
|
|
446
|
+
| `Measurement` | Class | Duration tracking with `using` support |
|
|
447
|
+
| `TelemetryType` | Enum | `Event`, `Exception`, `Metric`, `Custom` |
|
|
448
|
+
| `TelemetryLevel` | Enum | `Debug`, `Information`, `Warning`, `Error`, `Critical` |
|
|
449
|
+
| `ConsoleAdapter` | Class | Console output adapter |
|
|
450
|
+
| `ApplicationInsightsAdapter` | Class | Azure Application Insights adapter |
|
|
451
|
+
|
|
452
|
+
### Sub-path exports
|
|
453
|
+
|
|
454
|
+
| Path | Key export | Description |
|
|
455
|
+
|------|-----------|-------------|
|
|
456
|
+
| `/adapter` | `BaseTelemetryAdapter` | Base class for custom adapters |
|
|
457
|
+
| `/console-adapter` | `ConsoleAdapter` | Console adapter with colour-coded output |
|
|
458
|
+
| `/application-insights-adapter` | `ApplicationInsightsAdapter` | Azure Application Insights adapter |
|
|
459
|
+
| `/schemas` | `parseTelemetryItem` | Zod schemas for telemetry items |
|
|
460
|
+
|
|
461
|
+
### Configuration
|
|
462
|
+
|
|
463
|
+
#### Basic setup with console adapter
|
|
464
|
+
|
|
465
|
+
```typescript
|
|
466
|
+
import { enableTelemetry } from '@equinor/fusion-framework-module-telemetry';
|
|
467
|
+
import { ConsoleAdapter } from '@equinor/fusion-framework-module-telemetry/console-adapter';
|
|
468
|
+
|
|
469
|
+
export const configure: AppModuleInitiator = (configurator, env) => {
|
|
470
|
+
enableTelemetry(configurator, {
|
|
471
|
+
attachConfiguratorEvents: true,
|
|
472
|
+
configure: (builder) => {
|
|
473
|
+
builder.setAdapter(
|
|
474
|
+
ConsoleAdapter.Identifier,
|
|
475
|
+
new ConsoleAdapter({ title: 'MyApp' })
|
|
476
|
+
);
|
|
477
|
+
builder.setMetadata(() => ({ appVersion: '1.0.0' }));
|
|
478
|
+
builder.setDefaultScope(['application']);
|
|
479
|
+
},
|
|
480
|
+
});
|
|
481
|
+
};
|
|
482
|
+
```
|
|
483
|
+
|
|
484
|
+
#### Application Insights adapter
|
|
485
|
+
|
|
486
|
+
```typescript
|
|
487
|
+
import { ApplicationInsightsAdapter } from '@equinor/fusion-framework-module-telemetry/application-insights-adapter';
|
|
488
|
+
|
|
489
|
+
enableTelemetry(configurator, {
|
|
490
|
+
configure: (builder) => {
|
|
491
|
+
builder.setAdapter(
|
|
492
|
+
ApplicationInsightsAdapter.Identifier,
|
|
493
|
+
new ApplicationInsightsAdapter({
|
|
494
|
+
snippet: { config: { connectionString: '...' } },
|
|
495
|
+
prefix: 'myApp',
|
|
496
|
+
})
|
|
497
|
+
);
|
|
498
|
+
},
|
|
499
|
+
});
|
|
500
|
+
```
|
|
501
|
+
|
|
502
|
+
#### Reusing the parent adapter (app-level)
|
|
503
|
+
|
|
504
|
+
```typescript
|
|
505
|
+
enableTelemetry(configurator, {
|
|
506
|
+
attachConfiguratorEvents: true,
|
|
507
|
+
configure: async (args) => {
|
|
508
|
+
// Reuse the Application Insights adapter from portal
|
|
509
|
+
const aiAdapter = args.ref.modules.telemetry.getAdapter(
|
|
510
|
+
ApplicationInsightsAdapter.Identifier
|
|
511
|
+
);
|
|
512
|
+
if (aiAdapter) {
|
|
513
|
+
args.config.setAdapter('application-insights', aiAdapter);
|
|
514
|
+
}
|
|
515
|
+
args.config.setMetadata({ app: { name: 'My App', version: '1.0.0' } });
|
|
516
|
+
args.config.setDefaultScope(['app']);
|
|
517
|
+
args.config.setParent(args.ref.modules.telemetry);
|
|
518
|
+
},
|
|
519
|
+
});
|
|
520
|
+
```
|
|
521
|
+
|
|
522
|
+
### Tracking events, exceptions, and metrics
|
|
523
|
+
|
|
524
|
+
```typescript
|
|
525
|
+
const telemetry = modules.telemetry;
|
|
526
|
+
|
|
527
|
+
// Track an event
|
|
528
|
+
telemetry.trackEvent({ name: 'button_click', properties: { id: 'save' } });
|
|
529
|
+
|
|
530
|
+
// Track an exception
|
|
531
|
+
telemetry.trackException({ name: 'api_error', exception: new Error('Not found') });
|
|
532
|
+
|
|
533
|
+
// Track a metric
|
|
534
|
+
telemetry.trackMetric({ name: 'response_time', value: 230 });
|
|
535
|
+
|
|
536
|
+
// Track a custom event
|
|
537
|
+
telemetry.trackCustom({ name: 'feature_flag', properties: { flag: 'dark-mode' } });
|
|
538
|
+
```
|
|
539
|
+
|
|
540
|
+
### Measuring performance
|
|
541
|
+
|
|
542
|
+
```typescript
|
|
543
|
+
// Manual measurement
|
|
544
|
+
const measurement = telemetry.measure({ name: 'data_load' });
|
|
545
|
+
await fetchData();
|
|
546
|
+
measurement.measure({ properties: { rows: 100 } }, { markAsMeasured: true });
|
|
547
|
+
|
|
548
|
+
// Automatic with `using` (explicit resource management)
|
|
549
|
+
{
|
|
550
|
+
using m = telemetry.measure({ name: 'render_time' });
|
|
551
|
+
renderComponent();
|
|
552
|
+
} // duration tracked automatically on scope exit
|
|
553
|
+
|
|
554
|
+
// Promise-based measurement
|
|
555
|
+
const result = await telemetry.measure({ name: 'api_call' }).resolve(fetch('/api/data'));
|
|
556
|
+
```
|
|
557
|
+
|
|
558
|
+
### Creating custom adapters
|
|
559
|
+
|
|
560
|
+
```typescript
|
|
561
|
+
import { BaseTelemetryAdapter } from '@equinor/fusion-framework-module-telemetry/adapter';
|
|
562
|
+
import type { TelemetryItem } from '@equinor/fusion-framework-module-telemetry';
|
|
563
|
+
|
|
564
|
+
class MyAdapter extends BaseTelemetryAdapter {
|
|
565
|
+
constructor() {
|
|
566
|
+
super('my-adapter');
|
|
567
|
+
}
|
|
568
|
+
|
|
569
|
+
protected async _initialize(): Promise<void> {
|
|
570
|
+
// Async setup (connections, config loading, etc.)
|
|
571
|
+
}
|
|
572
|
+
|
|
573
|
+
protected _processItem(item: TelemetryItem): void {
|
|
574
|
+
// Send to your backend
|
|
575
|
+
}
|
|
576
|
+
}
|
|
577
|
+
```
|