@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/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
- * Represents the environment configuration for a template.
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
- /** Document title */
52
+ /** HTML `<title>` for the generated page. */
16
53
  title: string;
17
- /** Template bootstrap file path */
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
- /** Id of the portal to load */
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 configuration */
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
- /** Service worker configuration */
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
- * A function type that generates a partial environment configuration for a template.
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 - The type of the environment configuration. Defaults to `TemplateEnv`.
54
- * @param configEnv - The configuration environment provided as input.
55
- * @returns A partial environment configuration of type `TEnv`, or `undefined` if no configuration is provided.
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,
@@ -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 for a Vite project based on the provided configuration and environment.
5
+ * Loads environment variables from `.env` files for the Fusion SPA plugin.
6
6
  *
7
- * @see {@link http://vite.dev/guide/env-and-mode.html#env-files}
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
- * @param config - The user configuration object, which includes properties such as `root` and `envDir`.
10
- * - `root`: The root directory of the project. Defaults to the current working directory if not specified.
11
- * - `envDir`: The directory containing environment files. If not specified, defaults to the root directory.
12
- * @param env - The environment configuration object.
13
- * - `mode`: The mode in which the application is running (e.g., 'development', 'production').
14
- * @returns A record of environment variables prefixed with `FUSION_SPA_`.
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
- * Converts a nested object into a flat object with keys in snake_case and uppercase.
3
- * Nested keys are prefixed with their parent keys, separated by underscores.
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
- * @param obj - The input object to be flattened and converted.
7
- * @param prefix - An optional prefix to prepend to the keys (default is an empty string).
8
- * @returns A flat object with snake_case, uppercase keys and stringified values.
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
- * @example
11
- * ```typescript
12
- * const input = {
13
- * someKey: "value",
14
- * nestedObject: {
15
- * anotherKey: 42,
16
- * deepNested: {
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
- * const result = objectToEnv(input);
23
- * console.log(result);
24
- * // Output:
25
- * // {
26
- * // SOME_KEY: "\"value\"",
27
- * // NESTED_OBJECT_ANOTHER_KEY: "42",
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 = '3.1.11';
2
+ export const version = '4.0.0';