@equinor/fusion-framework-vite-plugin-spa 1.1.3 → 1.1.4
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 +34 -0
- package/README.md +41 -31
- package/dist/esm/html/bootstrap.js +87 -5
- package/dist/esm/html/bootstrap.js.map +1 -1
- package/dist/esm/html/register-service-worker.js +54 -11
- package/dist/esm/html/register-service-worker.js.map +1 -1
- package/dist/esm/version.js +1 -1
- package/dist/html/bootstrap.js +4336 -980
- package/dist/html/bootstrap.js.map +1 -1
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/dist/types/html/index.html.d.ts +1 -1
- package/dist/types/html/register-service-worker.d.ts +2 -1
- package/dist/types/types.d.ts +3 -0
- package/dist/types/version.d.ts +1 -1
- package/package.json +6 -5
- package/src/html/bootstrap.ts +109 -11
- package/src/html/register-service-worker.ts +87 -35
- package/src/types.ts +4 -0
- package/src/version.ts +1 -1
- package/tsconfig.json +3 -0
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,39 @@
|
|
|
1
1
|
# @equinor/fusion-framework-vite-plugin-spa
|
|
2
2
|
|
|
3
|
+
## 1.1.4
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- [#3490](https://github.com/equinor/fusion-framework/pull/3490) [`45954e5`](https://github.com/equinor/fusion-framework/commit/45954e5db471a2faa24e88e41fc6d6c18817d6d1) Thanks [@odinr](https://github.com/odinr)! - Remove logger level configuration from bootstrap template.
|
|
8
|
+
|
|
9
|
+
- Removed `configurator.logger.level` assignment from `bootstrap.ts`
|
|
10
|
+
- Logger level configuration should be handled elsewhere or is no longer needed
|
|
11
|
+
|
|
12
|
+
This cleans up the bootstrap template by removing unused logger configuration.
|
|
13
|
+
|
|
14
|
+
- [#3532](https://github.com/equinor/fusion-framework/pull/3532) [`63ecde5`](https://github.com/equinor/fusion-framework/commit/63ecde5c29e775b341c3fac0c1eeb7123db5e2db) Thanks [@dependabot](https://github.com/apps/dependabot)! - Bump vite from 7.1.8 to 7.1.9 across development tools and plugins.
|
|
15
|
+
|
|
16
|
+
This patch update fixes bugs and improves stability in the vite dependency.
|
|
17
|
+
|
|
18
|
+
- [#3521](https://github.com/equinor/fusion-framework/pull/3521) [`d1098f7`](https://github.com/equinor/fusion-framework/commit/d1098f7eeff04380c9e05e4a7a7d6b16e1d95884) Thanks [@odinr](https://github.com/odinr)! - Add comprehensive telemetry integration to SPA bootstrap and service worker.
|
|
19
|
+
|
|
20
|
+
- Enable telemetry in SPA bootstrap with ConsoleAdapter
|
|
21
|
+
- Add configurable console logging levels via FUSION_SPA_TELEMETRY_CONSOLE_LEVEL environment variable
|
|
22
|
+
- Track bootstrap performance for portal loading operations
|
|
23
|
+
- Monitor service worker registration and token acquisition
|
|
24
|
+
- Include user metadata and portal configuration in telemetry
|
|
25
|
+
- Track exceptions and errors throughout SPA lifecycle
|
|
26
|
+
- Fix console level filtering logic to properly respect environment variable settings
|
|
27
|
+
|
|
28
|
+
**Implementation Notes:**
|
|
29
|
+
|
|
30
|
+
- Console level filtering defaults to `TelemetryLevel.Information` (1) when env var not set
|
|
31
|
+
- Invalid env var values fallback to logging all telemetry (robust error handling)
|
|
32
|
+
- Backward compatible: existing behavior unchanged when no FUSION_SPA_TELEMETRY_CONSOLE_LEVEL specified
|
|
33
|
+
- Telemetry level mapping: 0=Debug, 1=Information, 2=Warning, 3=Error, 4=Critical
|
|
34
|
+
|
|
35
|
+
resolves: [#3487](https://github.com/equinor/fusion-framework/issues/3487)
|
|
36
|
+
|
|
3
37
|
## 1.1.3
|
|
4
38
|
|
|
5
39
|
### Patch Changes
|
package/README.md
CHANGED
|
@@ -40,36 +40,6 @@ A powerful Vite plugin for building Single Page Applications (SPAs) with the Fus
|
|
|
40
40
|
>
|
|
41
41
|
> The plugin is written in a modular fashion, allowing for easy customization and extension __IF__ the developer has a deep understanding of the Fusion Framework and its internals.
|
|
42
42
|
|
|
43
|
-
## Table of Contents
|
|
44
|
-
|
|
45
|
-
- [Fusion Framework Vite SPA Plugin](#fusion-framework-vite-spa-plugin)
|
|
46
|
-
- [Table of Contents](#table-of-contents)
|
|
47
|
-
- [What It Does](#what-it-does)
|
|
48
|
-
- [How the Plugin Works](#how-the-plugin-works)
|
|
49
|
-
- [Getting Started](#getting-started)
|
|
50
|
-
- [Configuration Options](#configuration-options)
|
|
51
|
-
- [Basic Configuration](#basic-configuration)
|
|
52
|
-
- [Service Discovery](#service-discovery)
|
|
53
|
-
- [MSAL](#msal)
|
|
54
|
-
- [Service Worker](#service-worker)
|
|
55
|
-
- [Configuring through `.env` File](#configuring-through-env-file)
|
|
56
|
-
- [How Environment Variables Work](#how-environment-variables-work)
|
|
57
|
-
- [Naming Convention](#naming-convention)
|
|
58
|
-
- [Example Conversion](#example-conversion)
|
|
59
|
-
- [Complete `.env` Example](#complete-env-example)
|
|
60
|
-
- [Advanced Customization](#advanced-customization)
|
|
61
|
-
- [Providing a Custom Template](#providing-a-custom-template)
|
|
62
|
-
- [Providing Custom Bootstrap](#providing-custom-bootstrap)
|
|
63
|
-
- [Examples](#examples)
|
|
64
|
-
- [Basic SPA Configuration](#basic-spa-configuration)
|
|
65
|
-
- [Using with API Service Plugin](#using-with-api-service-plugin)
|
|
66
|
-
- [Troubleshooting \& FAQ](#troubleshooting--faq)
|
|
67
|
-
- [Common Issues](#common-issues)
|
|
68
|
-
- [Known Issues](#known-issues)
|
|
69
|
-
- [Best Practices \& FAQ](#best-practices--faq)
|
|
70
|
-
- [Contributing](#contributing)
|
|
71
|
-
|
|
72
|
-
|
|
73
43
|
## What It Does
|
|
74
44
|
|
|
75
45
|
The plugin:
|
|
@@ -280,7 +250,41 @@ When the above `fetch` request is made, the following happens:
|
|
|
280
250
|
> The `url` path doesn't need to correspond to an actual endpoint—it's simply a pattern used for matching requests. This allows you to emulate proxy services in production environments without changing your application code.
|
|
281
251
|
|
|
282
252
|
> [!TIP]
|
|
283
|
-
> For enhanced development capabilities, consider using the `@equinor/fusion-framework-vite-plugin-api-service` plugin. This plugin creates a dynamic proxy service that can handle requests to the `/@fusion-api/app` path by intercepting them in the dev-server and routing them based on service discovery configuration.
|
|
253
|
+
> For enhanced development capabilities, consider using the `@equinor/fusion-framework-vite-plugin-api-service` plugin. This plugin creates a dynamic proxy service that can handle requests to the `/@fusion-api/app` path by intercepting them in the dev-server and routing them based on service discovery configuration.
|
|
254
|
+
|
|
255
|
+
## Telemetry
|
|
256
|
+
|
|
257
|
+
The Fusion Framework SPA plugin includes built-in telemetry configuration that automatically sets up console logging for development and debugging purposes. The plugin uses the `@equinor/fusion-framework-module-telemetry` module to provide structured logging with different severity levels.
|
|
258
|
+
|
|
259
|
+
### Telemetry Levels
|
|
260
|
+
|
|
261
|
+
The telemetry system supports the following severity levels (ordered from lowest to highest):
|
|
262
|
+
|
|
263
|
+
- **Debug** (0): Debugging information useful during development
|
|
264
|
+
- **Information** (1): General information about the system's operation
|
|
265
|
+
- **Warning** (2): Indicates a potential issue that is not critical
|
|
266
|
+
- **Error** (3): Represents an error that has occurred, but the system can continue running
|
|
267
|
+
- **Critical** (4): A severe error that may cause the system to stop functioning
|
|
268
|
+
|
|
269
|
+
### Console Logging
|
|
270
|
+
|
|
271
|
+
By default, the plugin enables console logging for all telemetry events. You can control the minimum log level displayed in the console using the `FUSION_SPA_TELEMETRY_CONSOLE_LEVEL` environment variable.
|
|
272
|
+
|
|
273
|
+
```typescript
|
|
274
|
+
// Environment variable configuration
|
|
275
|
+
FUSION_SPA_TELEMETRY_CONSOLE_LEVEL=2 // Only show Warning, Error, and Critical events
|
|
276
|
+
```
|
|
277
|
+
|
|
278
|
+
When set to a valid number, only telemetry items with a level **greater than or equal to** the specified value will be logged to the console. For example:
|
|
279
|
+
- `FUSION_SPA_TELEMETRY_CONSOLE_LEVEL=0` → Shows all telemetry events (Debug, Information, Warning, Error, Critical)
|
|
280
|
+
- `FUSION_SPA_TELEMETRY_CONSOLE_LEVEL=1` → Shows Information, Warning, Error, and Critical events
|
|
281
|
+
- `FUSION_SPA_TELEMETRY_CONSOLE_LEVEL=2` → Shows Warning, Error, and Critical events
|
|
282
|
+
|
|
283
|
+
If the environment variable is not set, the default is `FUSION_SPA_TELEMETRY_CONSOLE_LEVEL=1` (Information level and above). If the environment variable contains an invalid value, all telemetry events will be logged to the console.
|
|
284
|
+
|
|
285
|
+
### Custom Telemetry Configuration
|
|
286
|
+
|
|
287
|
+
For advanced telemetry setup (such as Application Insights integration), you can customize the telemetry configuration by providing a custom bootstrap file. See the [Providing Custom Bootstrap](#providing-custom-bootstrap) section for details.
|
|
284
288
|
|
|
285
289
|
## Configuring through `.env` File
|
|
286
290
|
|
|
@@ -337,6 +341,9 @@ FUSION_SPA_MSAL_CLIENT_ID=my-client-id
|
|
|
337
341
|
FUSION_SPA_MSAL_REDIRECT_URI=https://my-app.com/auth-callback
|
|
338
342
|
FUSION_SPA_MSAL_REQUIRES_AUTH=true
|
|
339
343
|
|
|
344
|
+
# Telemetry configuration
|
|
345
|
+
FUSION_SPA_TELEMETRY_CONSOLE_LEVEL=2 # Only log Warning, Error, and Critical events to console
|
|
346
|
+
|
|
340
347
|
# Service Worker configuration (as JSON string)
|
|
341
348
|
FUSION_SPA_SERVICE_WORKER_RESOURCES=[{"url":"/app-proxy","rewrite":"/@fusion-api/app","scopes":["xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx/.default"]}]
|
|
342
349
|
```
|
|
@@ -466,6 +473,9 @@ export default defineConfig({
|
|
|
466
473
|
redirectUri: 'http://localhost:3000/auth-callback',
|
|
467
474
|
requiresAuth: 'true',
|
|
468
475
|
},
|
|
476
|
+
telemetry: {
|
|
477
|
+
consoleLevel: 2, // Show Warning, Error, and Critical events
|
|
478
|
+
},
|
|
469
479
|
}),
|
|
470
480
|
}),
|
|
471
481
|
],
|
|
@@ -2,12 +2,14 @@ import { ModulesConfigurator } from '@equinor/fusion-framework-module';
|
|
|
2
2
|
import { configureHttpClient } from '@equinor/fusion-framework-module-http';
|
|
3
3
|
import { enableMSAL } from '@equinor/fusion-framework-module-msal';
|
|
4
4
|
import { enableServiceDiscovery, } from '@equinor/fusion-framework-module-service-discovery';
|
|
5
|
+
import { enableTelemetry, TelemetryLevel, } from '@equinor/fusion-framework-module-telemetry';
|
|
6
|
+
import { ConsoleAdapter } from '@equinor/fusion-framework-module-telemetry/console-adapter';
|
|
5
7
|
import { registerServiceWorker } from './register-service-worker.js';
|
|
8
|
+
import { version } from '../version.js';
|
|
6
9
|
// Allow dynamic import without vite
|
|
7
10
|
const importWithoutVite = (path) => import(/* @vite-ignore */ path);
|
|
8
11
|
// Create Fusion Framework configurator
|
|
9
12
|
const configurator = new ModulesConfigurator();
|
|
10
|
-
configurator.logger.level = import.meta.env.FUSION_SPA_LOG_LEVEL ?? 1;
|
|
11
13
|
const serviceDiscoveryUrl = new URL(import.meta.env.FUSION_SPA_SERVICE_DISCOVERY_URL, import.meta.env.FUSION_SPA_SERVICE_DISCOVERY_URL.startsWith('http')
|
|
12
14
|
? undefined
|
|
13
15
|
: window.location.origin);
|
|
@@ -29,18 +31,86 @@ enableMSAL(configurator, (builder) => {
|
|
|
29
31
|
});
|
|
30
32
|
builder.setRequiresAuth(Boolean(import.meta.env.FUSION_SPA_MSAL_REQUIRES_AUTH));
|
|
31
33
|
});
|
|
34
|
+
enableTelemetry(configurator, {
|
|
35
|
+
attachConfiguratorEvents: true,
|
|
36
|
+
configure: (builder) => {
|
|
37
|
+
const consoleLevel = Number(import.meta.env.FUSION_SPA_TELEMETRY_CONSOLE_LEVEL ?? TelemetryLevel.Information);
|
|
38
|
+
if (Number.isNaN(consoleLevel)) {
|
|
39
|
+
// If environment variable is set but invalid, log all telemetry
|
|
40
|
+
builder.setAdapter(new ConsoleAdapter());
|
|
41
|
+
}
|
|
42
|
+
else {
|
|
43
|
+
builder.setAdapter(new ConsoleAdapter({
|
|
44
|
+
filter: (item) => item.level >= consoleLevel,
|
|
45
|
+
}));
|
|
46
|
+
}
|
|
47
|
+
builder.setMetadata(({ modules }) => {
|
|
48
|
+
const metadata = {
|
|
49
|
+
fusion: {
|
|
50
|
+
spa: {
|
|
51
|
+
version,
|
|
52
|
+
},
|
|
53
|
+
},
|
|
54
|
+
// biome-ignore lint/suspicious/noExplicitAny: we need to use any here to allow dynamic properties
|
|
55
|
+
};
|
|
56
|
+
if (modules?.auth) {
|
|
57
|
+
metadata.fusion.user = {
|
|
58
|
+
id: modules.auth.defaultAccount?.homeAccountId,
|
|
59
|
+
name: modules.auth.defaultAccount?.name,
|
|
60
|
+
email: modules.auth.defaultAccount?.username,
|
|
61
|
+
};
|
|
62
|
+
}
|
|
63
|
+
return metadata;
|
|
64
|
+
});
|
|
65
|
+
},
|
|
66
|
+
});
|
|
32
67
|
(async () => {
|
|
33
68
|
// initialize the framework - this will create the framework instance and configure the modules
|
|
34
69
|
const ref = await configurator.initialize();
|
|
70
|
+
const telemetry = ref.telemetry;
|
|
35
71
|
// attach service discovery to the framework - append auth token to configured endpoints
|
|
36
|
-
|
|
72
|
+
using measurement = telemetry.measure({
|
|
73
|
+
name: 'bootstrap',
|
|
74
|
+
level: TelemetryLevel.Information,
|
|
75
|
+
});
|
|
76
|
+
await measurement.clone().resolve(registerServiceWorker(ref), {
|
|
77
|
+
data: {
|
|
78
|
+
level: TelemetryLevel.Debug,
|
|
79
|
+
name: 'bootstrap::registerServiceWorker',
|
|
80
|
+
},
|
|
81
|
+
});
|
|
37
82
|
// create a client for the portal service - this is used to fetch the portal manifest
|
|
38
83
|
const portalClient = await ref.serviceDiscovery.createClient('portal-config');
|
|
39
84
|
// fetch the portal manifest - this is used to load the portal template
|
|
40
85
|
const portalId = import.meta.env.FUSION_SPA_PORTAL_ID;
|
|
41
86
|
const portalTag = import.meta.env.FUSION_SPA_PORTAL_TAG ?? 'latest';
|
|
42
|
-
const portal_manifest = await
|
|
43
|
-
|
|
87
|
+
const portal_manifest = await measurement
|
|
88
|
+
.clone()
|
|
89
|
+
.resolve(portalClient.json(`/portals/${portalId}@${portalTag}`), {
|
|
90
|
+
data: (manifest) => ({
|
|
91
|
+
name: 'bootstrap::loadPortalManifest',
|
|
92
|
+
level: TelemetryLevel.Debug,
|
|
93
|
+
properties: {
|
|
94
|
+
portalId,
|
|
95
|
+
portalTag,
|
|
96
|
+
templateEntry: manifest.build.templateEntry,
|
|
97
|
+
manifestVersion: manifest.build.config?.version,
|
|
98
|
+
assetPath: manifest.build.assetPath,
|
|
99
|
+
},
|
|
100
|
+
}),
|
|
101
|
+
});
|
|
102
|
+
const portal_config = await measurement
|
|
103
|
+
.clone()
|
|
104
|
+
.resolve(portalClient.json(`/portals/${portalId}@${portalTag}/config`), {
|
|
105
|
+
data: {
|
|
106
|
+
name: 'bootstrap::loadPortalConfig',
|
|
107
|
+
level: TelemetryLevel.Debug,
|
|
108
|
+
properties: {
|
|
109
|
+
portalId,
|
|
110
|
+
portalTag,
|
|
111
|
+
},
|
|
112
|
+
},
|
|
113
|
+
});
|
|
44
114
|
// create a entrypoint for the portal - this is used to render the portal
|
|
45
115
|
const el = document.createElement('div');
|
|
46
116
|
document.body.innerHTML = '';
|
|
@@ -50,7 +120,19 @@ enableMSAL(configurator, (builder) => {
|
|
|
50
120
|
.join('/');
|
|
51
121
|
// @todo: should test if the entrypoint is external or internal
|
|
52
122
|
// @todo: add proper return type
|
|
53
|
-
const { render } = await
|
|
123
|
+
const { render } = await measurement
|
|
124
|
+
.clone()
|
|
125
|
+
.resolve(importWithoutVite(portalEntryPoint), {
|
|
126
|
+
data: {
|
|
127
|
+
name: 'bootstrap::loadPortalSourceCode',
|
|
128
|
+
level: TelemetryLevel.Debug,
|
|
129
|
+
properties: {
|
|
130
|
+
portalId,
|
|
131
|
+
portalTag,
|
|
132
|
+
entryPoint: portalEntryPoint,
|
|
133
|
+
},
|
|
134
|
+
},
|
|
135
|
+
});
|
|
54
136
|
// render the portal - this will load the portal template and render it
|
|
55
137
|
render(el, { ref, manifest: portal_manifest, config: portal_config });
|
|
56
138
|
})();
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"bootstrap.js","sourceRoot":"","sources":["../../../src/html/bootstrap.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,mBAAmB,EAAE,MAAM,kCAAkC,CAAC;AAEvE,OAAO,EAAE,mBAAmB,EAAmB,MAAM,uCAAuC,CAAC;AAC7F,OAAO,EAAE,UAAU,EAAmB,MAAM,uCAAuC,CAAC;AACpF,OAAO,EACL,sBAAsB,GAEvB,MAAM,oDAAoD,CAAC;
|
|
1
|
+
{"version":3,"file":"bootstrap.js","sourceRoot":"","sources":["../../../src/html/bootstrap.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,mBAAmB,EAAE,MAAM,kCAAkC,CAAC;AAEvE,OAAO,EAAE,mBAAmB,EAAmB,MAAM,uCAAuC,CAAC;AAC7F,OAAO,EAAE,UAAU,EAAmB,MAAM,uCAAuC,CAAC;AACpF,OAAO,EACL,sBAAsB,GAEvB,MAAM,oDAAoD,CAAC;AAE5D,OAAO,EACL,eAAe,EACf,cAAc,GAEf,MAAM,4CAA4C,CAAC;AACpD,OAAO,EAAE,cAAc,EAAE,MAAM,4DAA4D,CAAC;AAE5F,OAAO,EAAE,qBAAqB,EAAE,MAAM,8BAA8B,CAAC;AAErE,OAAO,EAAE,OAAO,EAAE,MAAM,eAAe,CAAC;AAWxC,oCAAoC;AACpC,MAAM,iBAAiB,GAAG,CAAI,IAAY,EAAc,EAAE,CAAC,MAAM,CAAC,kBAAkB,CAAC,IAAI,CAAC,CAAC;AAE3F,uCAAuC;AACvC,MAAM,YAAY,GAAG,IAAI,mBAAmB,EAAE,CAAC;AAE/C,MAAM,mBAAmB,GAAG,IAAI,GAAG,CACjC,MAAM,CAAC,IAAI,CAAC,GAAG,CAAC,gCAAgC,EAChD,MAAM,CAAC,IAAI,CAAC,GAAG,CAAC,gCAAgC,CAAC,UAAU,CAAC,MAAM,CAAC;IACjE,CAAC,CAAC,SAAS;IACX,CAAC,CAAC,MAAM,C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AM,gBAAgB,GAAG,CAAC,eAAe,CAAC,KAAK,CAAC,SAAS,EAAE,eAAe,CAAC,KAAK,CAAC,aAAa,CAAC;SAC5F,MAAM,CAAC,OAAO,CAAC;SACf,IAAI,CAAC,GAAG,CAAC,CAAC;IAEb,+DAA+D;IAC/D,gCAAgC;IAChC,MAAM,EAAE,MAAM,EAAE,GAAG,MAAM,WAAW;SACjC,KAAK,EAAE;SACP,OAAO,CACN,iBAAiB,CAAoD,gBAAgB,CAAC,EACtF;QACE,IAAI,EAAE;YACJ,IAAI,EAAE,iCAAiC;YACvC,KAAK,EAAE,cAAc,CAAC,KAAK;YAC3B,UAAU,EAAE;gBACV,QAAQ;gBACR,SAAS;gBACT,UAAU,EAAE,gBAAgB;aAC7B;SACF;KACF,CACF,CAAC;IAEJ,uEAAuE;IACvE,MAAM,CAAC,EAAE,EAAE,EAAE,GAAG,EAAE,QAAQ,EAAE,eAAe,EAAE,MAAM,EAAE,aAAa,EAAE,CAAC,CAAC;AACxE,CAAC,CAAC,EAAE,CAAC"}
|
|
@@ -1,12 +1,24 @@
|
|
|
1
|
+
import { TelemetryLevel } from '@equinor/fusion-framework-module-telemetry';
|
|
1
2
|
export async function registerServiceWorker(framework) {
|
|
3
|
+
const telemetry = framework.telemetry;
|
|
2
4
|
if ('serviceWorker' in navigator === false) {
|
|
3
|
-
|
|
4
|
-
|
|
5
|
+
const exception = new Error('Service workers are not supported in this browser.');
|
|
6
|
+
exception.name = 'ServiceWorkerNotSupported';
|
|
7
|
+
telemetry.trackException({
|
|
8
|
+
name: `registerServiceWorker.${exception.name}`,
|
|
9
|
+
exception,
|
|
10
|
+
});
|
|
11
|
+
throw exception;
|
|
5
12
|
}
|
|
6
13
|
const resourceConfigs = import.meta.env.FUSION_SPA_SERVICE_WORKER_RESOURCES;
|
|
7
14
|
if (!resourceConfigs) {
|
|
8
|
-
|
|
9
|
-
|
|
15
|
+
const exception = new Error('Service worker config is not defined.');
|
|
16
|
+
exception.name = 'ServiceWorkerConfigNotDefined';
|
|
17
|
+
telemetry.trackException({
|
|
18
|
+
name: `registerServiceWorker.${exception.name}`,
|
|
19
|
+
exception,
|
|
20
|
+
});
|
|
21
|
+
throw exception;
|
|
10
22
|
}
|
|
11
23
|
/**
|
|
12
24
|
* Helper function to send configuration to the service worker
|
|
@@ -27,12 +39,16 @@ export async function registerServiceWorker(framework) {
|
|
|
27
39
|
// extract scopes from the event data
|
|
28
40
|
const scopes = event.data.scopes;
|
|
29
41
|
if (!scopes || !Array.isArray(scopes)) {
|
|
30
|
-
|
|
42
|
+
const error = new Error('Invalid scopes provided');
|
|
43
|
+
error.name = 'InvalidScopesProvided';
|
|
44
|
+
throw error;
|
|
31
45
|
}
|
|
32
46
|
// request a token from the MSAL module
|
|
33
47
|
const token = await framework.auth.acquireToken({ scopes });
|
|
34
48
|
if (!token) {
|
|
35
|
-
|
|
49
|
+
const error = new Error('Failed to acquire token');
|
|
50
|
+
error.name = 'FailedToAcquireToken';
|
|
51
|
+
throw error;
|
|
36
52
|
}
|
|
37
53
|
// send the token back to the service worker
|
|
38
54
|
event.ports[0].postMessage({
|
|
@@ -41,19 +57,33 @@ export async function registerServiceWorker(framework) {
|
|
|
41
57
|
});
|
|
42
58
|
}
|
|
43
59
|
catch (error) {
|
|
60
|
+
const exception = error;
|
|
61
|
+
telemetry.trackException({
|
|
62
|
+
name: `serviceWorker.onMessage.${exception.name}`,
|
|
63
|
+
exception,
|
|
64
|
+
});
|
|
44
65
|
event.ports[0].postMessage({
|
|
45
66
|
error: error.message,
|
|
46
67
|
});
|
|
47
68
|
}
|
|
48
69
|
}
|
|
49
70
|
});
|
|
50
|
-
// register the service worker
|
|
71
|
+
// register the service worker with telemetry
|
|
51
72
|
// updateViaCache: 'none' ensures the service worker script is always fetched fresh
|
|
52
73
|
// This is important during development to pick up code changes
|
|
53
|
-
|
|
74
|
+
using measurement = telemetry.measure({
|
|
75
|
+
name: 'registerServiceWorker',
|
|
76
|
+
level: TelemetryLevel.Information,
|
|
77
|
+
});
|
|
78
|
+
const registration = await measurement.clone().resolve(navigator.serviceWorker.register('/@fusion-spa-sw.js', {
|
|
54
79
|
type: 'module',
|
|
55
80
|
scope: '/',
|
|
56
81
|
updateViaCache: 'none',
|
|
82
|
+
}), {
|
|
83
|
+
data: {
|
|
84
|
+
name: 'registerServiceWorker.register',
|
|
85
|
+
level: TelemetryLevel.Debug,
|
|
86
|
+
},
|
|
57
87
|
});
|
|
58
88
|
// Handle service worker updates/installations
|
|
59
89
|
// If there's a service worker waiting or installing, send config when it activates
|
|
@@ -75,7 +105,12 @@ export async function registerServiceWorker(framework) {
|
|
|
75
105
|
}
|
|
76
106
|
});
|
|
77
107
|
// wait for the service worker to be ready
|
|
78
|
-
const readyRegistration = await navigator.serviceWorker.ready
|
|
108
|
+
const readyRegistration = await measurement.clone().resolve(navigator.serviceWorker.ready, {
|
|
109
|
+
data: {
|
|
110
|
+
name: 'registerServiceWorker.ready',
|
|
111
|
+
level: TelemetryLevel.Debug,
|
|
112
|
+
},
|
|
113
|
+
});
|
|
79
114
|
// ensure we have an active service worker before sending config
|
|
80
115
|
const activeWorker = readyRegistration.active;
|
|
81
116
|
if (!activeWorker) {
|
|
@@ -85,7 +120,7 @@ export async function registerServiceWorker(framework) {
|
|
|
85
120
|
// CRITICAL: Wait for the service worker to become the controller
|
|
86
121
|
// This ensures the service worker can intercept fetch requests
|
|
87
122
|
if (!navigator.serviceWorker.controller) {
|
|
88
|
-
await new Promise((resolve) => {
|
|
123
|
+
await measurement.clone().resolve(new Promise((resolve) => {
|
|
89
124
|
let checkInterval;
|
|
90
125
|
const finish = () => {
|
|
91
126
|
clearInterval(checkInterval);
|
|
@@ -101,6 +136,11 @@ export async function registerServiceWorker(framework) {
|
|
|
101
136
|
finish();
|
|
102
137
|
}, 200);
|
|
103
138
|
setTimeout(finish, 5000);
|
|
139
|
+
}), {
|
|
140
|
+
data: {
|
|
141
|
+
name: 'registerServiceWorker.controllerWait',
|
|
142
|
+
level: TelemetryLevel.Debug,
|
|
143
|
+
},
|
|
104
144
|
});
|
|
105
145
|
}
|
|
106
146
|
// send the config to the active service worker
|
|
@@ -111,7 +151,10 @@ export async function registerServiceWorker(framework) {
|
|
|
111
151
|
}
|
|
112
152
|
}
|
|
113
153
|
catch (error) {
|
|
114
|
-
|
|
154
|
+
telemetry.trackException({
|
|
155
|
+
name: `registerServiceWorker.${error.name}`,
|
|
156
|
+
exception: error,
|
|
157
|
+
});
|
|
115
158
|
}
|
|
116
159
|
}
|
|
117
160
|
//# sourceMappingURL=register-service-worker.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"register-service-worker.js","sourceRoot":"","sources":["../../../src/html/register-service-worker.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"register-service-worker.js","sourceRoot":"","sources":["../../../src/html/register-service-worker.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,cAAc,EAAwB,MAAM,4CAA4C,CAAC;AAElG,MAAM,CAAC,KAAK,UAAU,qBAAqB,CACzC,SAAyD;IAEzD,MAAM,SAAS,GAAG,SAAS,CAAC,SAAS,CAAC;IACtC,IAAI,eAAe,IAAI,SAAS,KAAK,KAAK,EAAE,CAAC;QAC3C,MAAM,SAAS,GAAG,IAAI,KAAK,CAAC,oDAAoD,CAAC,CAAC;QAClF,SAAS,CAAC,IAAI,GAAG,2BAA2B,CAAC;QAC7C,SAAS,CAAC,cAAc,CAAC;YACvB,IAAI,EAAE,yBAAyB,SAAS,CAAC,IAAI,EAAE;YAC/C,SAAS;SACV,CAAC,CAAC;QACH,MAAM,SAAS,CAAC;IAClB,CAAC;IAED,MAAM,eAAe,GAAG,MAAM,CAAC,IAAI,CAAC,GAAG,CAAC,mCAAmC,CAAC;IAC5E,IAAI,CAAC,eAAe,EAAE,CAAC;QACrB,MAAM,SAAS,GAAG,IAAI,KAAK,CAAC,uCAAuC,CAAC,CAAC;QACrE,SAAS,CAAC,IAAI,GAAG,+BAA+B,CAAC;QACjD,SAAS,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