@equinor/fusion-framework-dev-server 1.1.32-next.0 → 2.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.
@@ -1,33 +1,49 @@
1
1
  import { type UserConfig } from 'vite';
2
2
  import type { DevServerOptions, TemplateEnv } from './types.js';
3
3
  /**
4
- * Creates a development server configuration for a Fusion Framework application.
4
+ * Build a Vite {@link import('vite').UserConfig | UserConfig} for a Fusion Framework dev server
5
+ * without starting the server.
5
6
  *
6
- * @template TEnv - A type extending `Partial<TemplateEnv>` that represents the environment variables for the template.
7
- * @param options - The options for configuring the development server.
8
- * @param options.spa - Optional configuration for the Single Page Application (SPA), including template environment settings.
9
- * @param options.api - Configuration for the API, including service discovery URL, routes, and service processing logic.
7
+ * Use this function when you need control over the server lifecycle (e.g. to pass the config
8
+ * to another Vite tool). For a simpler create-and-listen workflow, use {@link createDevServer}.
10
9
  *
11
- * @returns A `UserConfig` object that defines the Vite development server configuration.
10
+ * The generated config includes:
11
+ * - `@vitejs/plugin-react` for React Fast Refresh / HMR
12
+ * - `@equinor/fusion-framework-vite-plugin-api-service` for service discovery proxying
13
+ * - `@equinor/fusion-framework-vite-plugin-spa` for template environment injection
14
+ * - CORS disabled so backend services handle OPTIONS with proper headers
15
+ *
16
+ * @template TEnv - Environment variable shape extending `Partial<TemplateEnv>`, used to type-check
17
+ * the SPA template environment object or factory function.
18
+ * @param options - Development server options containing SPA, API, and logging settings.
19
+ * @param overrides - Optional Vite config merged on top of the generated base config via
20
+ * {@link import('vite').mergeConfig | mergeConfig}.
21
+ * @returns A fully resolved Vite `UserConfig` ready for {@link import('vite').createServer | createServer}.
12
22
  *
13
23
  * @remarks
14
- * - The `spa.templateEnv` can either be a function or a partial object of type `TEnv`.
15
- * - The `api.processServices` defaults to `defaultProcessServices` if not provided.
16
- * - The server is configured to run on port 3000.
17
- * - Includes plugins for API service handling and SPA template environment generation.
18
- * - CORS is disabled to allow backend services to handle OPTIONS requests with proper headers.
24
+ * - `spa.templateEnv` accepts either a static object or a factory function returning the environment.
25
+ * - `api.processServices` defaults to the built-in {@link processServices} when omitted.
26
+ * - The default log level is `Info`; set `log.level` to `4` for debug output.
19
27
  *
20
28
  * @example
21
29
  * ```typescript
30
+ * import { createDevServerConfig } from '@equinor/fusion-framework-dev-server';
31
+ * import { createServer } from 'vite';
32
+ *
22
33
  * const config = createDevServerConfig({
23
34
  * spa: {
24
- * templateEnv: { API_URL: 'https://api.example.com' },
25
- * },
26
- * api: {
27
- * serviceDiscoveryUrl: 'https://discovery.example.com',
28
- * routes: ['/api'],
35
+ * templateEnv: {
36
+ * portal: { id: 'my-portal' },
37
+ * title: 'My App',
38
+ * serviceDiscovery: { url: 'https://discovery.example.com', scopes: [] },
39
+ * msal: { clientId: 'cid', tenantId: 'tid', redirectUri: '/auth/cb', requiresAuth: 'true' },
40
+ * },
29
41
  * },
42
+ * api: { serviceDiscoveryUrl: 'https://discovery.example.com' },
30
43
  * });
44
+ *
45
+ * const server = await createServer(config);
46
+ * await server.listen();
31
47
  * ```
32
48
  */
33
49
  export declare const createDevServerConfig: <TEnv extends Partial<TemplateEnv>>(options: DevServerOptions<TEnv>, overrides?: UserConfig) => UserConfig;
@@ -1,10 +1,40 @@
1
1
  import { type UserConfig } from 'vite';
2
2
  import type { DevServerOptions } from './types.js';
3
3
  /**
4
- * Asynchronously creates and configures a development server instance.
4
+ * Create and return a fully configured Vite development server for a Fusion Framework application.
5
5
  *
6
- * @param options - The options used to configure the development server.
7
- * @returns A promise that resolves to the created development server instance.
6
+ * Combines SPA template environment injection, service discovery proxying, and React HMR into
7
+ * a single ready-to-listen server instance. Use this function when you want the default
8
+ * development workflow; use {@link createDevServerConfig} instead if you only need the Vite
9
+ * configuration object without starting the server.
10
+ *
11
+ * @param options - Development server configuration including SPA template environment,
12
+ * API proxy settings, and optional logging overrides.
13
+ * @param overrides - Optional Vite {@link import('vite').UserConfig | UserConfig} merged on top
14
+ * of the generated configuration (e.g. custom port, extra plugins).
15
+ * @returns A promise that resolves to a Vite {@link import('vite').ViteDevServer | ViteDevServer}
16
+ * ready for {@link import('vite').ViteDevServer.listen | listen()} and
17
+ * {@link import('vite').ViteDevServer.printUrls | printUrls()}.
18
+ *
19
+ * @example
20
+ * ```typescript
21
+ * import { createDevServer } from '@equinor/fusion-framework-dev-server';
22
+ *
23
+ * const server = await createDevServer({
24
+ * spa: {
25
+ * templateEnv: {
26
+ * portal: { id: 'my-portal' },
27
+ * title: 'My App',
28
+ * serviceDiscovery: { url: 'https://discovery.example.com', scopes: [] },
29
+ * msal: { clientId: 'id', tenantId: 'tid', redirectUri: '/auth/callback', requiresAuth: 'true' },
30
+ * },
31
+ * },
32
+ * api: { serviceDiscoveryUrl: 'https://discovery.example.com' },
33
+ * });
34
+ *
35
+ * await server.listen();
36
+ * server.printUrls();
37
+ * ```
8
38
  */
9
39
  export declare const createDevServer: (options: DevServerOptions, overrides?: UserConfig) => Promise<import("vite").ViteDevServer>;
10
40
  export default createDevServer;
@@ -1,6 +1,34 @@
1
+ /**
2
+ * @packageDocumentation
3
+ *
4
+ * Development server for Fusion Framework applications.
5
+ *
6
+ * Provides a pre-configured Vite dev server with integrated service discovery proxying,
7
+ * SPA template environment injection, and React HMR support. Use this package when you
8
+ * need a local development environment that mirrors production Fusion portal behaviour.
9
+ *
10
+ * @remarks
11
+ * Main entry points:
12
+ * - {@link createDevServer} — create and start a fully configured Vite dev server
13
+ * - {@link createDevServerConfig} — build a Vite `UserConfig` without starting the server
14
+ * - {@link processServices} — remap Fusion service URIs to local proxy routes
15
+ *
16
+ * @example
17
+ * ```typescript
18
+ * import { createDevServer } from '@equinor/fusion-framework-dev-server';
19
+ *
20
+ * const server = await createDevServer({
21
+ * api: { serviceDiscoveryUrl: 'https://discovery.example.com' },
22
+ * });
23
+ * await server.listen();
24
+ * server.printUrls();
25
+ * ```
26
+ */
27
+ /** Re-export of Vite's {@link import('vite').UserConfig | UserConfig} for consumer convenience when passing overrides. */
1
28
  export type { UserConfig } from 'vite';
2
29
  export { processServices } from './process-services.js';
3
30
  export { default, createDevServer } from './create-dev-server.js';
4
31
  export { createDevServerConfig } from './create-dev-server-config.js';
32
+ /** Re-export of the SPA template environment type used to configure portal, MSAL, and service discovery settings. */
5
33
  export type { FusionTemplateEnv } from '@equinor/fusion-framework-vite-plugin-spa';
6
34
  export * from './types.js';
@@ -1,16 +1,19 @@
1
1
  import type { ApiDataProcessor } from '@equinor/fusion-framework-vite-plugin-api-service';
2
2
  import type { FusionService } from './types.js';
3
3
  /**
4
- * Processes an array of Fusion services, remapping their URIs to proxy through the development server
5
- * and generating corresponding proxy routes.
4
+ * Remap Fusion service discovery entries so their URIs point through the local dev server proxy,
5
+ * and generate matching Vite proxy routes for each service.
6
6
  *
7
- * @template T - The type of the input data, expected to be an array of `FusionService`.
8
- * @param data - The input array of Fusion services to process.
9
- * @param args - Additional arguments containing the route and request information.
10
- * @param args.route - The base route used to construct the proxy paths.
11
- * @param args.request - The HTTP request object, used to extract the referer header.
12
- * @returns An object containing the processed services and the generated proxy routes.
13
- * @throws {Error} If the input data is not an array.
7
+ * Use this as the default `api.processServices` handler in {@link DevServerOptions}, or call it
8
+ * inside a custom handler to get the base mapping before applying additional transformations
9
+ * (e.g. adding mock services or filtering environments).
10
+ *
11
+ * @param data - Array of {@link FusionService} entries returned by the service discovery endpoint.
12
+ * @param args - Context provided by the API service plugin.
13
+ * @param args.route - Base route path used to construct local proxy URLs (e.g. `'/services-proxy'`).
14
+ * @param args.request - Incoming HTTP request; the `referer` header is used to resolve the local origin.
15
+ * @returns An object with `data` (services with rewritten URIs) and `routes` (Vite proxy route configs).
16
+ * @throws {Error} When `data` is not an array, indicating an unexpected service discovery response.
14
17
  *
15
18
  * @example
16
19
  * ```typescript
@@ -1,32 +1,61 @@
1
1
  import type { ApiDataProcessor, ApiRoute } from '@equinor/fusion-framework-vite-plugin-api-service';
2
2
  import type { FusionTemplateEnv, TemplateEnvFn } from '@equinor/fusion-framework-vite-plugin-spa';
3
3
  import type { ConsoleLogger } from '@equinor/fusion-log';
4
+ /**
5
+ * A service entry returned by the Fusion service discovery endpoint.
6
+ *
7
+ * Each entry represents a single backend service that can be proxied
8
+ * through the development server via {@link processServices}.
9
+ */
4
10
  export type FusionService = {
11
+ /** Unique service identifier used as the proxy path segment (e.g. `'context'`, `'people'`). */
5
12
  key: string;
13
+ /** Absolute URL of the upstream service endpoint. */
6
14
  uri: string;
15
+ /** Human-readable display name of the service. */
7
16
  name: string;
8
17
  };
18
+ /**
19
+ * Re-export of {@link FusionTemplateEnv} under the local alias `TemplateEnv`.
20
+ *
21
+ * Describes the environment variables injected into the SPA HTML template
22
+ * (portal ID, service discovery URL, MSAL settings, telemetry level, etc.).
23
+ */
9
24
  export { FusionTemplateEnv as TemplateEnv, TemplateEnvFn, } from '@equinor/fusion-framework-vite-plugin-spa';
25
+ /**
26
+ * Alias for Vite's `UserConfig`, used as the optional overrides parameter
27
+ * of {@link createDevServer} and {@link createDevServerConfig}.
28
+ */
10
29
  export { UserConfig as DevServerOverrides } from 'vite';
11
30
  /**
12
- * Configuration options for the development server.
13
- *
14
- * @template TEnv - The type of the environment variables, extending Partial<FusionTemplateEnv>.
31
+ * Configuration options for the Fusion Framework development server.
15
32
  *
16
- * @property spa - Optional Single Page Application (SPA) specific options.
17
- * @property spa.templateEnv - The template environment configuration or a function returning it.
33
+ * Pass an instance of this type to {@link createDevServer} or {@link createDevServerConfig}
34
+ * to configure SPA template injection, API service discovery proxying, and server-side logging.
18
35
  *
19
- * @property api - API proxy configuration options.
20
- * @property api.serviceDiscoveryUrl - The URL of the service discovery proxy endpoint.
21
- * @property api.processServices - Optional route mapper for processing service discovery data.
22
- * @property api.routes - Optional additional routes for the API service proxy, used for overriding proxy responses and mocking services.
36
+ * @template TEnv - Shape of the SPA template environment variables, extending
37
+ * `Partial<FusionTemplateEnv>`. Defaults to `Partial<FusionTemplateEnv>`.
23
38
  *
24
- * @property log - Optional logging configuration.
25
- * @property log.level - Optional log level.
26
- * @property log.logger - Optional custom logger implementing the ConsoleLogger interface.
39
+ * @example
40
+ * ```typescript
41
+ * const opts: DevServerOptions = {
42
+ * spa: {
43
+ * templateEnv: {
44
+ * portal: { id: 'my-portal' },
45
+ * title: 'My App',
46
+ * serviceDiscovery: { url: 'https://discovery.example.com', scopes: [] },
47
+ * msal: { clientId: 'id', tenantId: 'tid', redirectUri: '/auth/cb', requiresAuth: 'true' },
48
+ * },
49
+ * },
50
+ * api: { serviceDiscoveryUrl: 'https://discovery.example.com' },
51
+ * log: { level: 3 },
52
+ * };
53
+ * ```
27
54
  */
28
55
  export type DevServerOptions<TEnv extends Partial<FusionTemplateEnv> = Partial<FusionTemplateEnv>> = {
56
+ /** SPA template settings. When provided, the dev server injects these values into the HTML template at serve time. */
29
57
  spa?: {
58
+ /** Static environment object or factory function that produces it on each request. */
30
59
  templateEnv: TEnv | TemplateEnvFn<TEnv>;
31
60
  };
32
61
  api: {
@@ -44,8 +73,11 @@ export type DevServerOptions<TEnv extends Partial<FusionTemplateEnv> = Partial<F
44
73
  */
45
74
  routes?: ApiRoute[];
46
75
  };
76
+ /** Server-side (CLI) logging configuration. */
47
77
  log?: {
78
+ /** Log verbosity: 0 = None, 1 = Error, 2 = Warning, 3 = Info, 4 = Debug. Defaults to Info (3). */
48
79
  level?: number;
80
+ /** Custom logger instance. When omitted a default {@link ConsoleLogger} is created. */
49
81
  logger?: ConsoleLogger;
50
82
  };
51
83
  };
@@ -1 +1 @@
1
- export declare const version = "1.1.32-next.0";
1
+ export declare const version = "2.0.0";
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@equinor/fusion-framework-dev-server",
3
- "version": "1.1.32-next.0",
3
+ "version": "2.0.0",
4
4
  "description": "Package for running a development server for fusion-framework",
5
5
  "type": "module",
6
6
  "exports": {
@@ -29,18 +29,18 @@
29
29
  "access": "public"
30
30
  },
31
31
  "dependencies": {
32
- "@vitejs/plugin-react": "^5.0.2",
33
- "@equinor/fusion-framework-vite-plugin-api-service": "1.2.6-next.0",
34
- "@equinor/fusion-framework-vite-plugin-spa": "3.1.12-next.0",
35
- "@equinor/fusion-log": "1.1.9-next.0"
32
+ "@vitejs/plugin-react": "^6.0.1",
33
+ "@equinor/fusion-framework-vite-plugin-api-service": "2.0.0",
34
+ "@equinor/fusion-framework-vite-plugin-spa": "4.0.0",
35
+ "@equinor/fusion-log": "2.0.0"
36
36
  },
37
37
  "devDependencies": {
38
- "typescript": "^5.8.2",
39
- "vite": "^7.1.12",
40
- "vitest": "^4.0.18"
38
+ "typescript": "^5.9.3",
39
+ "vite": "^8.0.0",
40
+ "vitest": "^4.1.0"
41
41
  },
42
42
  "peerDependencies": {
43
- "vite": "^7.0.0"
43
+ "vite": "^7.0.0 || ^8.0.0"
44
44
  },
45
45
  "scripts": {
46
46
  "build": "tsc -b",
@@ -13,6 +13,13 @@ import { processServices as defaultProcessServices } from './process-services.js
13
13
 
14
14
  import type { DevServerOptions, TemplateEnv, TemplateEnvFn } from './types.js';
15
15
 
16
+ /**
17
+ * Create a default {@link ConsoleLogger} instance for the dev server.
18
+ *
19
+ * @param lvl - Log verbosity level; defaults to {@link LogLevel.Info}.
20
+ * @param title - Logger title printed as a prefix in console output; defaults to `'dev-server'`.
21
+ * @returns A configured {@link ConsoleLogger} instance.
22
+ */
16
23
  const createDefaultLogger = (lvl: LogLevel = LogLevel.Info, title = 'dev-server') => {
17
24
  const logger = new ConsoleLogger(title);
18
25
  logger.level = lvl;
@@ -20,33 +27,49 @@ const createDefaultLogger = (lvl: LogLevel = LogLevel.Info, title = 'dev-server'
20
27
  };
21
28
 
22
29
  /**
23
- * Creates a development server configuration for a Fusion Framework application.
30
+ * Build a Vite {@link import('vite').UserConfig | UserConfig} for a Fusion Framework dev server
31
+ * without starting the server.
32
+ *
33
+ * Use this function when you need control over the server lifecycle (e.g. to pass the config
34
+ * to another Vite tool). For a simpler create-and-listen workflow, use {@link createDevServer}.
24
35
  *
25
- * @template TEnv - A type extending `Partial<TemplateEnv>` that represents the environment variables for the template.
26
- * @param options - The options for configuring the development server.
27
- * @param options.spa - Optional configuration for the Single Page Application (SPA), including template environment settings.
28
- * @param options.api - Configuration for the API, including service discovery URL, routes, and service processing logic.
36
+ * The generated config includes:
37
+ * - `@vitejs/plugin-react` for React Fast Refresh / HMR
38
+ * - `@equinor/fusion-framework-vite-plugin-api-service` for service discovery proxying
39
+ * - `@equinor/fusion-framework-vite-plugin-spa` for template environment injection
40
+ * - CORS disabled so backend services handle OPTIONS with proper headers
29
41
  *
30
- * @returns A `UserConfig` object that defines the Vite development server configuration.
42
+ * @template TEnv - Environment variable shape extending `Partial<TemplateEnv>`, used to type-check
43
+ * the SPA template environment object or factory function.
44
+ * @param options - Development server options containing SPA, API, and logging settings.
45
+ * @param overrides - Optional Vite config merged on top of the generated base config via
46
+ * {@link import('vite').mergeConfig | mergeConfig}.
47
+ * @returns A fully resolved Vite `UserConfig` ready for {@link import('vite').createServer | createServer}.
31
48
  *
32
49
  * @remarks
33
- * - The `spa.templateEnv` can either be a function or a partial object of type `TEnv`.
34
- * - The `api.processServices` defaults to `defaultProcessServices` if not provided.
35
- * - The server is configured to run on port 3000.
36
- * - Includes plugins for API service handling and SPA template environment generation.
37
- * - CORS is disabled to allow backend services to handle OPTIONS requests with proper headers.
50
+ * - `spa.templateEnv` accepts either a static object or a factory function returning the environment.
51
+ * - `api.processServices` defaults to the built-in {@link processServices} when omitted.
52
+ * - The default log level is `Info`; set `log.level` to `4` for debug output.
38
53
  *
39
54
  * @example
40
55
  * ```typescript
56
+ * import { createDevServerConfig } from '@equinor/fusion-framework-dev-server';
57
+ * import { createServer } from 'vite';
58
+ *
41
59
  * const config = createDevServerConfig({
42
60
  * spa: {
43
- * templateEnv: { API_URL: 'https://api.example.com' },
44
- * },
45
- * api: {
46
- * serviceDiscoveryUrl: 'https://discovery.example.com',
47
- * routes: ['/api'],
61
+ * templateEnv: {
62
+ * portal: { id: 'my-portal' },
63
+ * title: 'My App',
64
+ * serviceDiscovery: { url: 'https://discovery.example.com', scopes: [] },
65
+ * msal: { clientId: 'cid', tenantId: 'tid', redirectUri: '/auth/cb', requiresAuth: 'true' },
66
+ * },
48
67
  * },
68
+ * api: { serviceDiscoveryUrl: 'https://discovery.example.com' },
49
69
  * });
70
+ *
71
+ * const server = await createServer(config);
72
+ * await server.listen();
50
73
  * ```
51
74
  */
52
75
  export const createDevServerConfig = <TEnv extends Partial<TemplateEnv>>(
@@ -4,10 +4,40 @@ import { createDevServerConfig } from './create-dev-server-config.js';
4
4
  import type { DevServerOptions } from './types.js';
5
5
 
6
6
  /**
7
- * Asynchronously creates and configures a development server instance.
7
+ * Create and return a fully configured Vite development server for a Fusion Framework application.
8
8
  *
9
- * @param options - The options used to configure the development server.
10
- * @returns A promise that resolves to the created development server instance.
9
+ * Combines SPA template environment injection, service discovery proxying, and React HMR into
10
+ * a single ready-to-listen server instance. Use this function when you want the default
11
+ * development workflow; use {@link createDevServerConfig} instead if you only need the Vite
12
+ * configuration object without starting the server.
13
+ *
14
+ * @param options - Development server configuration including SPA template environment,
15
+ * API proxy settings, and optional logging overrides.
16
+ * @param overrides - Optional Vite {@link import('vite').UserConfig | UserConfig} merged on top
17
+ * of the generated configuration (e.g. custom port, extra plugins).
18
+ * @returns A promise that resolves to a Vite {@link import('vite').ViteDevServer | ViteDevServer}
19
+ * ready for {@link import('vite').ViteDevServer.listen | listen()} and
20
+ * {@link import('vite').ViteDevServer.printUrls | printUrls()}.
21
+ *
22
+ * @example
23
+ * ```typescript
24
+ * import { createDevServer } from '@equinor/fusion-framework-dev-server';
25
+ *
26
+ * const server = await createDevServer({
27
+ * spa: {
28
+ * templateEnv: {
29
+ * portal: { id: 'my-portal' },
30
+ * title: 'My App',
31
+ * serviceDiscovery: { url: 'https://discovery.example.com', scopes: [] },
32
+ * msal: { clientId: 'id', tenantId: 'tid', redirectUri: '/auth/callback', requiresAuth: 'true' },
33
+ * },
34
+ * },
35
+ * api: { serviceDiscoveryUrl: 'https://discovery.example.com' },
36
+ * });
37
+ *
38
+ * await server.listen();
39
+ * server.printUrls();
40
+ * ```
11
41
  */
12
42
  export const createDevServer = async (options: DevServerOptions, overrides?: UserConfig) => {
13
43
  const config = createDevServerConfig(options, overrides);
package/src/index.ts CHANGED
@@ -1,3 +1,31 @@
1
+ /**
2
+ * @packageDocumentation
3
+ *
4
+ * Development server for Fusion Framework applications.
5
+ *
6
+ * Provides a pre-configured Vite dev server with integrated service discovery proxying,
7
+ * SPA template environment injection, and React HMR support. Use this package when you
8
+ * need a local development environment that mirrors production Fusion portal behaviour.
9
+ *
10
+ * @remarks
11
+ * Main entry points:
12
+ * - {@link createDevServer} — create and start a fully configured Vite dev server
13
+ * - {@link createDevServerConfig} — build a Vite `UserConfig` without starting the server
14
+ * - {@link processServices} — remap Fusion service URIs to local proxy routes
15
+ *
16
+ * @example
17
+ * ```typescript
18
+ * import { createDevServer } from '@equinor/fusion-framework-dev-server';
19
+ *
20
+ * const server = await createDevServer({
21
+ * api: { serviceDiscoveryUrl: 'https://discovery.example.com' },
22
+ * });
23
+ * await server.listen();
24
+ * server.printUrls();
25
+ * ```
26
+ */
27
+
28
+ /** Re-export of Vite's {@link import('vite').UserConfig | UserConfig} for consumer convenience when passing overrides. */
1
29
  export type { UserConfig } from 'vite';
2
30
 
3
31
  export { processServices } from './process-services.js';
@@ -6,6 +34,7 @@ export { default, createDevServer } from './create-dev-server.js';
6
34
 
7
35
  export { createDevServerConfig } from './create-dev-server-config.js';
8
36
 
37
+ /** Re-export of the SPA template environment type used to configure portal, MSAL, and service discovery settings. */
9
38
  export type { FusionTemplateEnv } from '@equinor/fusion-framework-vite-plugin-spa';
10
39
 
11
40
  export * from './types.js';
@@ -2,16 +2,19 @@ import type { ApiDataProcessor, ApiRoute } from '@equinor/fusion-framework-vite-
2
2
  import type { FusionService } from './types.js';
3
3
 
4
4
  /**
5
- * Processes an array of Fusion services, remapping their URIs to proxy through the development server
6
- * and generating corresponding proxy routes.
5
+ * Remap Fusion service discovery entries so their URIs point through the local dev server proxy,
6
+ * and generate matching Vite proxy routes for each service.
7
7
  *
8
- * @template T - The type of the input data, expected to be an array of `FusionService`.
9
- * @param data - The input array of Fusion services to process.
10
- * @param args - Additional arguments containing the route and request information.
11
- * @param args.route - The base route used to construct the proxy paths.
12
- * @param args.request - The HTTP request object, used to extract the referer header.
13
- * @returns An object containing the processed services and the generated proxy routes.
14
- * @throws {Error} If the input data is not an array.
8
+ * Use this as the default `api.processServices` handler in {@link DevServerOptions}, or call it
9
+ * inside a custom handler to get the base mapping before applying additional transformations
10
+ * (e.g. adding mock services or filtering environments).
11
+ *
12
+ * @param data - Array of {@link FusionService} entries returned by the service discovery endpoint.
13
+ * @param args - Context provided by the API service plugin.
14
+ * @param args.route - Base route path used to construct local proxy URLs (e.g. `'/services-proxy'`).
15
+ * @param args.request - Incoming HTTP request; the `referer` header is used to resolve the local origin.
16
+ * @returns An object with `data` (services with rewritten URIs) and `routes` (Vite proxy route configs).
17
+ * @throws {Error} When `data` is not an array, indicating an unexpected service discovery response.
15
18
  *
16
19
  * @example
17
20
  * ```typescript
package/src/types.ts CHANGED
@@ -2,39 +2,68 @@ import type { ApiDataProcessor, ApiRoute } from '@equinor/fusion-framework-vite-
2
2
  import type { FusionTemplateEnv, TemplateEnvFn } from '@equinor/fusion-framework-vite-plugin-spa';
3
3
  import type { ConsoleLogger } from '@equinor/fusion-log';
4
4
 
5
+ /**
6
+ * A service entry returned by the Fusion service discovery endpoint.
7
+ *
8
+ * Each entry represents a single backend service that can be proxied
9
+ * through the development server via {@link processServices}.
10
+ */
5
11
  export type FusionService = {
12
+ /** Unique service identifier used as the proxy path segment (e.g. `'context'`, `'people'`). */
6
13
  key: string;
14
+ /** Absolute URL of the upstream service endpoint. */
7
15
  uri: string;
16
+ /** Human-readable display name of the service. */
8
17
  name: string;
9
18
  };
10
19
 
20
+ /**
21
+ * Re-export of {@link FusionTemplateEnv} under the local alias `TemplateEnv`.
22
+ *
23
+ * Describes the environment variables injected into the SPA HTML template
24
+ * (portal ID, service discovery URL, MSAL settings, telemetry level, etc.).
25
+ */
11
26
  export {
12
27
  FusionTemplateEnv as TemplateEnv,
13
28
  TemplateEnvFn,
14
29
  } from '@equinor/fusion-framework-vite-plugin-spa';
15
30
 
31
+ /**
32
+ * Alias for Vite's `UserConfig`, used as the optional overrides parameter
33
+ * of {@link createDevServer} and {@link createDevServerConfig}.
34
+ */
16
35
  export { UserConfig as DevServerOverrides } from 'vite';
17
36
 
18
37
  /**
19
- * Configuration options for the development server.
20
- *
21
- * @template TEnv - The type of the environment variables, extending Partial<FusionTemplateEnv>.
38
+ * Configuration options for the Fusion Framework development server.
22
39
  *
23
- * @property spa - Optional Single Page Application (SPA) specific options.
24
- * @property spa.templateEnv - The template environment configuration or a function returning it.
40
+ * Pass an instance of this type to {@link createDevServer} or {@link createDevServerConfig}
41
+ * to configure SPA template injection, API service discovery proxying, and server-side logging.
25
42
  *
26
- * @property api - API proxy configuration options.
27
- * @property api.serviceDiscoveryUrl - The URL of the service discovery proxy endpoint.
28
- * @property api.processServices - Optional route mapper for processing service discovery data.
29
- * @property api.routes - Optional additional routes for the API service proxy, used for overriding proxy responses and mocking services.
43
+ * @template TEnv - Shape of the SPA template environment variables, extending
44
+ * `Partial<FusionTemplateEnv>`. Defaults to `Partial<FusionTemplateEnv>`.
30
45
  *
31
- * @property log - Optional logging configuration.
32
- * @property log.level - Optional log level.
33
- * @property log.logger - Optional custom logger implementing the ConsoleLogger interface.
46
+ * @example
47
+ * ```typescript
48
+ * const opts: DevServerOptions = {
49
+ * spa: {
50
+ * templateEnv: {
51
+ * portal: { id: 'my-portal' },
52
+ * title: 'My App',
53
+ * serviceDiscovery: { url: 'https://discovery.example.com', scopes: [] },
54
+ * msal: { clientId: 'id', tenantId: 'tid', redirectUri: '/auth/cb', requiresAuth: 'true' },
55
+ * },
56
+ * },
57
+ * api: { serviceDiscoveryUrl: 'https://discovery.example.com' },
58
+ * log: { level: 3 },
59
+ * };
60
+ * ```
34
61
  */
35
62
  export type DevServerOptions<TEnv extends Partial<FusionTemplateEnv> = Partial<FusionTemplateEnv>> =
36
63
  {
64
+ /** SPA template settings. When provided, the dev server injects these values into the HTML template at serve time. */
37
65
  spa?: {
66
+ /** Static environment object or factory function that produces it on each request. */
38
67
  templateEnv: TEnv | TemplateEnvFn<TEnv>;
39
68
  };
40
69
  api: {
@@ -54,8 +83,11 @@ export type DevServerOptions<TEnv extends Partial<FusionTemplateEnv> = Partial<F
54
83
  */
55
84
  routes?: ApiRoute[];
56
85
  };
86
+ /** Server-side (CLI) logging configuration. */
57
87
  log?: {
88
+ /** Log verbosity: 0 = None, 1 = Error, 2 = Warning, 3 = Info, 4 = Debug. Defaults to Info (3). */
58
89
  level?: number;
90
+ /** Custom logger instance. When omitted a default {@link ConsoleLogger} is created. */
59
91
  logger?: ConsoleLogger;
60
92
  };
61
93
  };
package/src/version.ts CHANGED
@@ -1,2 +1,2 @@
1
1
  // Generated by genversion.
2
- export const version = '1.1.32-next.0';
2
+ export const version = '2.0.0';