@equinor/fusion-framework-vite-plugin-spa 4.0.17 → 4.1.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.
@@ -15,5 +15,5 @@
15
15
  * @constant
16
16
  * @type {string}
17
17
  */
18
- export declare const html = "\n <!DOCTYPE html>\n <html>\n <head>\n <title>%FUSION_SPA_TITLE%</title>\n <meta name=\"mode\" content=\"%MODE%\">\n <meta name=\"fusion-spa-plugin-version\" content=\"4.0.17\">\n <link rel=\"stylesheet\" href=\"https://cdn.eds.equinor.com/font/equinor-font.css\" />\n <script type=\"module\" src=\"%FUSION_SPA_BOOTSTRAP%\"></script>\n <script>\n // Set AG Grid license key globally if provided\n window.FUSION_AG_GRID_KEY = '%FUSION_SPA_AG_GRID_KEY%';\n \n // suppress console error for custom elements already defined. \n // WebComponents should be added by the portal, but not removed from application\n const _customElementsDefine = window.customElements.define;\n window.customElements.define = (name, cl, conf) => {\n if (!customElements.get(name)) {\n _customElementsDefine.call(window.customElements, name, cl, conf);\n }\n };\n </script>\n <style>\n html, body {\n margin: 0;\n padding: 0;\n height: 100%;\n font-family: 'EquinorFont', sans-serif;\n }\n </style>\n </head>\n <body></body>\n </html>\n";
18
+ export declare const html = "\n <!DOCTYPE html>\n <html>\n <head>\n <title>%FUSION_SPA_TITLE%</title>\n <meta name=\"mode\" content=\"%MODE%\">\n <meta name=\"fusion-spa-plugin-version\" content=\"4.1.0\">\n <link rel=\"stylesheet\" href=\"https://cdn.eds.equinor.com/font/equinor-font.css\" />\n <script type=\"module\" src=\"%FUSION_SPA_BOOTSTRAP%\"></script>\n <script>\n // Set AG Grid license key globally if provided\n window.FUSION_AG_GRID_KEY = '%FUSION_SPA_AG_GRID_KEY%';\n \n // suppress console error for custom elements already defined. \n // WebComponents should be added by the portal, but not removed from application\n const _customElementsDefine = window.customElements.define;\n window.customElements.define = (name, cl, conf) => {\n if (!customElements.get(name)) {\n _customElementsDefine.call(window.customElements, name, cl, conf);\n }\n };\n </script>\n <style>\n html, body {\n margin: 0;\n padding: 0;\n height: 100%;\n font-family: 'EquinorFont', sans-serif;\n }\n </style>\n </head>\n <body></body>\n </html>\n";
19
19
  export default html;
@@ -0,0 +1,7 @@
1
+ /**
2
+ * Resolves a Vite environment toggle that may arrive as a parsed boolean or raw string.
3
+ *
4
+ * @param value - Environment value supplied through plugin configuration or a custom Vite define.
5
+ * @returns `true` only for the boolean `true` or the string `'true'`.
6
+ */
7
+ export declare function isEnabledEnvValue(value: unknown): boolean;
@@ -111,6 +111,18 @@ export type FusionTemplateEnv = {
111
111
  * on initial load.
112
112
  */
113
113
  requiresAuth: string;
114
+ /**
115
+ * When `'true'`, authentication is served by an in-process mock client
116
+ * instead of Entra ID — no credentials, redirects, or network calls.
117
+ * Intended for CI/Playwright runs against the dev server.
118
+ */
119
+ mock?: string | boolean;
120
+ /**
121
+ * A mock JWT (e.g. from `createMockToken`) whose payload claims (`name`,
122
+ * `preferred_username`, `oid`, `tid`, `scp`) become the signed-in mock
123
+ * user. Only read when {@link mock} is set; ignored otherwise.
124
+ */
125
+ mockToken?: string;
114
126
  };
115
127
  /** Service worker resource interception configuration. */
116
128
  serviceWorker: {
@@ -1 +1 @@
1
- export declare const version = "4.0.17";
1
+ export declare const version = "4.1.0";
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@equinor/fusion-framework-vite-plugin-spa",
3
- "version": "4.0.17",
3
+ "version": "4.1.0",
4
4
  "description": "Vite plugin for SPA development",
5
5
  "type": "module",
6
6
  "types": "dist/types/index.d.ts",
@@ -37,11 +37,11 @@
37
37
  "access": "public"
38
38
  },
39
39
  "dependencies": {
40
- "@equinor/fusion-framework-module-http": "8.0.5",
41
- "@equinor/fusion-framework-module-service-discovery": "10.0.2",
42
- "@equinor/fusion-framework-module-msal": "10.0.2",
43
- "@equinor/fusion-framework-module": "6.1.2",
44
- "@equinor/fusion-framework-module-telemetry": "7.0.3"
40
+ "@equinor/fusion-framework-module": "6.1.3",
41
+ "@equinor/fusion-framework-module-msal": "11.0.0",
42
+ "@equinor/fusion-framework-module-http": "8.1.0",
43
+ "@equinor/fusion-framework-module-telemetry": "7.1.0",
44
+ "@equinor/fusion-framework-module-service-discovery": "10.1.0"
45
45
  },
46
46
  "devDependencies": {
47
47
  "@rollup/plugin-commonjs": "^29.0.0",
@@ -15,6 +15,7 @@ import {
15
15
  import { ConsoleAdapter } from '@equinor/fusion-framework-module-telemetry/console-adapter';
16
16
 
17
17
  import { createPortalEntryPoint } from './create-portal-entry-point.js';
18
+ import { isEnabledEnvValue } from './is-enabled-env-value.js';
18
19
  import { registerServiceWorker } from './register-service-worker.js';
19
20
 
20
21
  import { version } from '../version.js';
@@ -54,18 +55,31 @@ enableServiceDiscovery(configurator, async (builder) => {
54
55
  builder.configureServiceDiscoveryClientByClientKey('service_discovery');
55
56
  });
56
57
 
57
- // setup authentication
58
- enableMSAL(configurator, (builder) => {
59
- builder.setClientConfig({
60
- auth: {
61
- clientId: import.meta.env.FUSION_SPA_MSAL_CLIENT_ID,
62
- tenantId: import.meta.env.FUSION_SPA_MSAL_TENANT_ID,
63
- redirectUri: import.meta.env.FUSION_SPA_MSAL_REDIRECT_URI,
64
- },
58
+ // Avoid interactive Entra ID authentication when the SPA runs in CI or Playwright.
59
+ if (isEnabledEnvValue(import.meta.env.FUSION_SPA_MSAL_MOCK)) {
60
+ const { enableMsalMock } = await import('@equinor/fusion-framework-module-msal/mock');
61
+
62
+ const mockToken = import.meta.env.FUSION_SPA_MSAL_MOCK_TOKEN;
63
+
64
+ enableMsalMock(configurator, (builder) => {
65
+ // Preserve the mock client's default identity when no backend-specific token is configured.
66
+ if (!mockToken) return;
67
+
68
+ builder.setToken(mockToken);
65
69
  });
70
+ } else {
71
+ enableMSAL(configurator, (builder) => {
72
+ builder.setClientConfig({
73
+ auth: {
74
+ clientId: import.meta.env.FUSION_SPA_MSAL_CLIENT_ID,
75
+ tenantId: import.meta.env.FUSION_SPA_MSAL_TENANT_ID,
76
+ redirectUri: import.meta.env.FUSION_SPA_MSAL_REDIRECT_URI,
77
+ },
78
+ });
66
79
 
67
- builder.setRequiresAuth(Boolean(import.meta.env.FUSION_SPA_MSAL_REQUIRES_AUTH));
68
- });
80
+ builder.setRequiresAuth(isEnabledEnvValue(import.meta.env.FUSION_SPA_MSAL_REQUIRES_AUTH));
81
+ });
82
+ }
69
83
 
70
84
  enableTelemetry(configurator, {
71
85
  attachConfiguratorEvents: true,
@@ -0,0 +1,9 @@
1
+ /**
2
+ * Resolves a Vite environment toggle that may arrive as a parsed boolean or raw string.
3
+ *
4
+ * @param value - Environment value supplied through plugin configuration or a custom Vite define.
5
+ * @returns `true` only for the boolean `true` or the string `'true'`.
6
+ */
7
+ export function isEnabledEnvValue(value: unknown): boolean {
8
+ return value === true || value === 'true';
9
+ }
package/src/types.ts CHANGED
@@ -119,6 +119,18 @@ export type FusionTemplateEnv = {
119
119
  * on initial load.
120
120
  */
121
121
  requiresAuth: string;
122
+ /**
123
+ * When `'true'`, authentication is served by an in-process mock client
124
+ * instead of Entra ID — no credentials, redirects, or network calls.
125
+ * Intended for CI/Playwright runs against the dev server.
126
+ */
127
+ mock?: string | boolean;
128
+ /**
129
+ * A mock JWT (e.g. from `createMockToken`) whose payload claims (`name`,
130
+ * `preferred_username`, `oid`, `tid`, `scp`) become the signed-in mock
131
+ * user. Only read when {@link mock} is set; ignored otherwise.
132
+ */
133
+ mockToken?: string;
122
134
  };
123
135
 
124
136
  /** Service worker resource interception configuration. */
package/src/version.ts CHANGED
@@ -1,2 +1,2 @@
1
1
  // Generated by genversion.
2
- export const version = '4.0.17';
2
+ export const version = '4.1.0';
@@ -0,0 +1,13 @@
1
+ import { describe, expect, it } from 'vitest';
2
+
3
+ import { isEnabledEnvValue } from '../src/html/is-enabled-env-value';
4
+
5
+ describe('isEnabledEnvValue', () => {
6
+ it.each([true, 'true'])('enables the toggle for %j', (value) => {
7
+ expect(isEnabledEnvValue(value)).toBe(true);
8
+ });
9
+
10
+ it.each([false, 'false', undefined, '', 1])('keeps the toggle disabled for %j', (value) => {
11
+ expect(isEnabledEnvValue(value)).toBe(false);
12
+ });
13
+ });
package/vitest.config.ts CHANGED
@@ -1,6 +1,6 @@
1
1
  import { defineProject } from 'vitest/config';
2
2
 
3
- import { name, version } from './package.json';
3
+ import { name, version } from './package.json' with { type: 'json' };
4
4
 
5
5
  export default defineProject({
6
6
  test: {