@equinor/fusion-framework-vite-plugin-spa 3.1.11 → 4.0.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 +38 -35
- package/README.md +145 -138
- package/dist/esm/html/index.js +9 -0
- package/dist/esm/html/index.js.map +1 -1
- package/dist/esm/html/register-service-worker.js +30 -0
- package/dist/esm/html/register-service-worker.js.map +1 -1
- package/dist/esm/index.js +31 -0
- package/dist/esm/index.js.map +1 -1
- package/dist/esm/plugin.js +36 -1
- package/dist/esm/plugin.js.map +1 -1
- package/dist/esm/util/load-env.js +14 -8
- package/dist/esm/util/load-env.js.map +1 -1
- package/dist/esm/util/object-to-env.js +19 -25
- package/dist/esm/util/object-to-env.js.map +1 -1
- package/dist/esm/version.js +1 -1
- package/dist/esm/version.js.map +1 -1
- package/dist/html/bootstrap.js +865 -420
- package/dist/html/bootstrap.js.map +1 -1
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/dist/types/html/index.d.ts +9 -0
- package/dist/types/html/index.html.d.ts +1 -1
- package/dist/types/html/register-service-worker.d.ts +30 -0
- package/dist/types/index.d.ts +31 -0
- package/dist/types/plugin.d.ts +75 -7
- package/dist/types/types.d.ts +98 -11
- package/dist/types/util/load-env.d.ts +14 -8
- package/dist/types/util/object-to-env.d.ts +19 -25
- package/dist/types/version.d.ts +1 -1
- package/package.json +9 -9
- package/src/html/index.ts +9 -0
- package/src/html/register-service-worker.ts +30 -0
- package/src/index.ts +31 -0
- package/src/plugin.ts +80 -8
- package/src/types.ts +100 -11
- package/src/util/load-env.ts +14 -8
- package/src/util/object-to-env.ts +19 -25
- package/src/version.ts +1 -1
package/src/types.ts
CHANGED
|
@@ -1,58 +1,147 @@
|
|
|
1
1
|
import type { ConfigEnv } from 'vite';
|
|
2
2
|
|
|
3
|
+
/**
|
|
4
|
+
* Base type for template environment variables.
|
|
5
|
+
*
|
|
6
|
+
* @remarks
|
|
7
|
+
* A loose record that can hold any key-value pairs later flattened into
|
|
8
|
+
* `FUSION_SPA_*` environment variables by {@link objectToEnv}.
|
|
9
|
+
* Extend this type (or use {@link FusionTemplateEnv}) when you need a
|
|
10
|
+
* strongly-typed environment shape.
|
|
11
|
+
*/
|
|
3
12
|
export type TemplateEnv = Record<string, unknown>;
|
|
4
13
|
|
|
14
|
+
/**
|
|
15
|
+
* Describes a single resource that the SPA service worker should intercept.
|
|
16
|
+
*
|
|
17
|
+
* When the service worker sees a fetch request whose URL starts with {@link url},
|
|
18
|
+
* it optionally rewrites the path and attaches an OAuth Bearer token obtained
|
|
19
|
+
* from the MSAL module for the specified {@link scopes}.
|
|
20
|
+
*
|
|
21
|
+
* @example
|
|
22
|
+
* ```ts
|
|
23
|
+
* const resource: ResourceConfiguration = {
|
|
24
|
+
* url: '/app-proxy',
|
|
25
|
+
* rewrite: '/@fusion-api/app',
|
|
26
|
+
* scopes: ['api://backend/.default'],
|
|
27
|
+
* };
|
|
28
|
+
* ```
|
|
29
|
+
*/
|
|
5
30
|
export type ResourceConfiguration = {
|
|
31
|
+
/** URL path prefix to match against outgoing fetch requests. */
|
|
6
32
|
url: string;
|
|
33
|
+
/** OAuth scopes used to acquire a Bearer token for matched requests. */
|
|
7
34
|
scopes?: string[];
|
|
35
|
+
/** Replacement path prefix; the matched {@link url} segment is swapped for this value. */
|
|
8
36
|
rewrite?: string;
|
|
9
37
|
};
|
|
10
38
|
|
|
11
39
|
/**
|
|
12
|
-
*
|
|
40
|
+
* Strongly-typed environment configuration consumed by the default SPA
|
|
41
|
+
* HTML template and bootstrap script.
|
|
42
|
+
*
|
|
43
|
+
* @remarks
|
|
44
|
+
* Values are flattened to `FUSION_SPA_*` environment variables at build time
|
|
45
|
+
* and injected into the HTML template via Vite's
|
|
46
|
+
* {@link https://vite.dev/guide/env-and-mode.html#html-constant-replacement | constant replacement}.
|
|
47
|
+
* They can also be overridden through a `.env` file.
|
|
48
|
+
*
|
|
49
|
+
* @see {@link PluginOptions.generateTemplateEnv} for how to supply these values.
|
|
13
50
|
*/
|
|
14
51
|
export type FusionTemplateEnv = {
|
|
15
|
-
/**
|
|
52
|
+
/** HTML `<title>` for the generated page. */
|
|
16
53
|
title: string;
|
|
17
|
-
|
|
54
|
+
|
|
55
|
+
/**
|
|
56
|
+
* Path to the bootstrap module loaded by the HTML template.
|
|
57
|
+
*
|
|
58
|
+
* @defaultValue `'/@fusion-spa-bootstrap.js'`
|
|
59
|
+
*/
|
|
18
60
|
bootstrap: string;
|
|
19
61
|
|
|
62
|
+
/** Optional telemetry configuration. */
|
|
20
63
|
telemetry?: {
|
|
64
|
+
/**
|
|
65
|
+
* Minimum severity level for console telemetry output.
|
|
66
|
+
*
|
|
67
|
+
* @remarks
|
|
68
|
+
* Maps to `TelemetryLevel` values: Debug (0), Information (1),
|
|
69
|
+
* Warning (2), Error (3), Critical (4).
|
|
70
|
+
*
|
|
71
|
+
* @defaultValue `1` (Information)
|
|
72
|
+
*/
|
|
21
73
|
consoleLevel?: number;
|
|
22
74
|
};
|
|
23
75
|
|
|
24
|
-
/**
|
|
76
|
+
/**
|
|
77
|
+
* Portal to load and render inside the SPA shell.
|
|
78
|
+
*
|
|
79
|
+
* @remarks
|
|
80
|
+
* The `id` can reference:
|
|
81
|
+
* - A local npm package (e.g. `@equinor/fusion-framework-dev-portal`)
|
|
82
|
+
* - A portal identifier from the Fusion Portal Service
|
|
83
|
+
* - Any custom portal implementation
|
|
84
|
+
*/
|
|
25
85
|
portal: {
|
|
86
|
+
/** Portal identifier used to fetch the portal manifest. */
|
|
26
87
|
id: string;
|
|
88
|
+
/**
|
|
89
|
+
* Version tag for the portal manifest.
|
|
90
|
+
* @defaultValue `'latest'`
|
|
91
|
+
*/
|
|
27
92
|
tag?: string;
|
|
93
|
+
/**
|
|
94
|
+
* When `true`, portal entry point requests are prefixed with `/portal-proxy`
|
|
95
|
+
* so they can be intercepted by a proxy server.
|
|
96
|
+
* @defaultValue `false`
|
|
97
|
+
*/
|
|
28
98
|
proxy?: boolean;
|
|
29
99
|
};
|
|
30
100
|
|
|
31
|
-
/** Service discovery
|
|
101
|
+
/** Service discovery endpoint and authentication scopes. */
|
|
32
102
|
serviceDiscovery: {
|
|
103
|
+
/** URL of the Fusion service discovery endpoint. */
|
|
33
104
|
url: string;
|
|
105
|
+
/** OAuth scopes required to authenticate service discovery requests. */
|
|
34
106
|
scopes: string[];
|
|
35
107
|
};
|
|
36
108
|
|
|
37
|
-
/** MSAL configuration */
|
|
109
|
+
/** Microsoft Authentication Library (MSAL) configuration for Azure AD. */
|
|
38
110
|
msal: {
|
|
111
|
+
/** Azure AD tenant identifier. */
|
|
39
112
|
tenantId: string;
|
|
113
|
+
/** Application (client) identifier registered in Azure AD. */
|
|
40
114
|
clientId: string;
|
|
115
|
+
/** Redirect URI for the authentication callback. */
|
|
41
116
|
redirectUri: string;
|
|
117
|
+
/**
|
|
118
|
+
* When `'true'`, the application automatically prompts for login
|
|
119
|
+
* on initial load.
|
|
120
|
+
*/
|
|
42
121
|
requiresAuth: string;
|
|
43
122
|
};
|
|
44
|
-
|
|
123
|
+
|
|
124
|
+
/** Service worker resource interception configuration. */
|
|
45
125
|
serviceWorker: {
|
|
126
|
+
/**
|
|
127
|
+
* Array of resource configurations the service worker will manage.
|
|
128
|
+
* @see {@link ResourceConfiguration}
|
|
129
|
+
*/
|
|
46
130
|
resources: ResourceConfiguration[];
|
|
47
131
|
};
|
|
48
132
|
};
|
|
49
133
|
|
|
50
134
|
/**
|
|
51
|
-
*
|
|
135
|
+
* Factory function that produces a partial template environment from the
|
|
136
|
+
* current Vite {@link ConfigEnv} (mode, command, etc.).
|
|
137
|
+
*
|
|
138
|
+
* @remarks
|
|
139
|
+
* Returned values are merged with defaults and flattened into
|
|
140
|
+
* `FUSION_SPA_*` environment variables.
|
|
52
141
|
*
|
|
53
|
-
* @template TEnv -
|
|
54
|
-
* @param configEnv -
|
|
55
|
-
* @returns A partial environment
|
|
142
|
+
* @template TEnv - Shape of the environment configuration. Defaults to {@link TemplateEnv}.
|
|
143
|
+
* @param configEnv - Vite configuration environment containing `mode` and `command`.
|
|
144
|
+
* @returns A partial environment object, or `undefined` to use defaults only.
|
|
56
145
|
*/
|
|
57
146
|
export type TemplateEnvFn<TEnv extends TemplateEnv> = (
|
|
58
147
|
configEnv: ConfigEnv,
|
package/src/util/load-env.ts
CHANGED
|
@@ -2,16 +2,22 @@ import { type ConfigEnv, loadEnv, type UserConfig } from 'vite';
|
|
|
2
2
|
import { resolve } from 'node:path';
|
|
3
3
|
|
|
4
4
|
/**
|
|
5
|
-
* Loads environment variables
|
|
5
|
+
* Loads environment variables from `.env` files for the Fusion SPA plugin.
|
|
6
6
|
*
|
|
7
|
-
* @
|
|
7
|
+
* @remarks
|
|
8
|
+
* Delegates to Vite's {@link https://vite.dev/guide/env-and-mode.html#env-files | loadEnv}
|
|
9
|
+
* using the resolved project root and env directory. Only variables whose
|
|
10
|
+
* name starts with {@link namespace} are returned.
|
|
8
11
|
*
|
|
9
|
-
*
|
|
10
|
-
*
|
|
11
|
-
*
|
|
12
|
-
* @param
|
|
13
|
-
*
|
|
14
|
-
* @
|
|
12
|
+
* Values loaded here override any matching keys produced by
|
|
13
|
+
* {@link PluginOptions.generateTemplateEnv}.
|
|
14
|
+
*
|
|
15
|
+
* @param config - Vite user configuration (`root`, `envDir`).
|
|
16
|
+
* @param env - Vite configuration environment containing the current `mode`.
|
|
17
|
+
* @param namespace - Variable name prefix to filter on.
|
|
18
|
+
* @returns A flat record of matching environment variable names to their string values.
|
|
19
|
+
*
|
|
20
|
+
* @defaultValue namespace — `'FUSION_SPA_'`
|
|
15
21
|
*/
|
|
16
22
|
export function loadEnvironment(
|
|
17
23
|
config: UserConfig,
|
|
@@ -1,32 +1,26 @@
|
|
|
1
1
|
/**
|
|
2
|
-
*
|
|
3
|
-
*
|
|
4
|
-
* Non-object values are stringified.
|
|
2
|
+
* Flattens a nested object into a single-level record with
|
|
3
|
+
* `UPPER_SNAKE_CASE` keys suitable for Vite's `config.define`.
|
|
5
4
|
*
|
|
6
|
-
* @
|
|
7
|
-
*
|
|
8
|
-
*
|
|
5
|
+
* @remarks
|
|
6
|
+
* Used internally by the Fusion SPA plugin to convert the object
|
|
7
|
+
* returned by {@link PluginOptions.generateTemplateEnv} into
|
|
8
|
+
* `import.meta.env.*` defines.
|
|
9
9
|
*
|
|
10
|
-
*
|
|
11
|
-
*
|
|
12
|
-
*
|
|
13
|
-
*
|
|
14
|
-
*
|
|
15
|
-
*
|
|
16
|
-
*
|
|
17
|
-
* finalKey: true
|
|
18
|
-
* }
|
|
19
|
-
* }
|
|
20
|
-
* };
|
|
10
|
+
* - camelCase keys are converted to UPPER_SNAKE_CASE.
|
|
11
|
+
* - Nested objects are recursively flattened with `_` separators.
|
|
12
|
+
* - Arrays and primitives are JSON-stringified.
|
|
13
|
+
*
|
|
14
|
+
* @param obj - The object to flatten.
|
|
15
|
+
* @param prefix - Key prefix prepended to every output key.
|
|
16
|
+
* @returns A flat record mapping `PREFIX_KEY` strings to JSON-stringified values.
|
|
21
17
|
*
|
|
22
|
-
*
|
|
23
|
-
*
|
|
24
|
-
*
|
|
25
|
-
*
|
|
26
|
-
*
|
|
27
|
-
* //
|
|
28
|
-
* // NESTED_OBJECT_DEEP_NESTED_FINAL_KEY: "true"
|
|
29
|
-
* // }
|
|
18
|
+
* @defaultValue prefix — `'FUSION_SPA'`
|
|
19
|
+
*
|
|
20
|
+
* @example
|
|
21
|
+
* ```ts
|
|
22
|
+
* objectToEnv({ portal: { id: 'my-portal' } }, 'FUSION_SPA');
|
|
23
|
+
* // => { FUSION_SPA_PORTAL_ID: '"my-portal"' }
|
|
30
24
|
* ```
|
|
31
25
|
*/
|
|
32
26
|
export function objectToEnv(obj: object, prefix = 'FUSION_SPA'): Record<string, string> {
|
package/src/version.ts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
// Generated by genversion.
|
|
2
|
-
export const version = '
|
|
2
|
+
export const version = '4.0.0';
|