@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.
- package/CHANGELOG.md +29 -6
- package/README.md +8 -1
- package/dist/esm/create-dev-server-config.js +39 -16
- package/dist/esm/create-dev-server-config.js.map +1 -1
- package/dist/esm/create-dev-server.js +33 -3
- package/dist/esm/create-dev-server.js.map +1 -1
- package/dist/esm/index.js +26 -0
- package/dist/esm/index.js.map +1 -1
- package/dist/esm/process-services.js +12 -9
- package/dist/esm/process-services.js.map +1 -1
- package/dist/esm/version.js +1 -1
- package/dist/esm/version.js.map +1 -1
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/dist/types/create-dev-server-config.d.ts +32 -16
- package/dist/types/create-dev-server.d.ts +33 -3
- package/dist/types/index.d.ts +28 -0
- package/dist/types/process-services.d.ts +12 -9
- package/dist/types/types.d.ts +44 -12
- package/dist/types/version.d.ts +1 -1
- package/package.json +9 -9
- package/src/create-dev-server-config.ts +39 -16
- package/src/create-dev-server.ts +33 -3
- package/src/index.ts +29 -0
- package/src/process-services.ts +12 -9
- package/src/types.ts +44 -12
- package/src/version.ts +1 -1
|
@@ -1,33 +1,49 @@
|
|
|
1
1
|
import { type UserConfig } from 'vite';
|
|
2
2
|
import type { DevServerOptions, TemplateEnv } from './types.js';
|
|
3
3
|
/**
|
|
4
|
-
*
|
|
4
|
+
* Build a Vite {@link import('vite').UserConfig | UserConfig} for a Fusion Framework dev server
|
|
5
|
+
* without starting the server.
|
|
5
6
|
*
|
|
6
|
-
*
|
|
7
|
-
*
|
|
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
|
-
*
|
|
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
|
-
* -
|
|
15
|
-
* -
|
|
16
|
-
* - The
|
|
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: {
|
|
25
|
-
*
|
|
26
|
-
*
|
|
27
|
-
*
|
|
28
|
-
*
|
|
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
|
-
*
|
|
4
|
+
* Create and return a fully configured Vite development server for a Fusion Framework application.
|
|
5
5
|
*
|
|
6
|
-
*
|
|
7
|
-
*
|
|
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;
|
package/dist/types/index.d.ts
CHANGED
|
@@ -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
|
-
*
|
|
5
|
-
* and
|
|
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
|
-
*
|
|
8
|
-
*
|
|
9
|
-
*
|
|
10
|
-
*
|
|
11
|
-
* @param
|
|
12
|
-
* @
|
|
13
|
-
* @
|
|
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
|
package/dist/types/types.d.ts
CHANGED
|
@@ -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
|
-
*
|
|
17
|
-
*
|
|
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
|
-
* @
|
|
20
|
-
*
|
|
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
|
-
* @
|
|
25
|
-
*
|
|
26
|
-
*
|
|
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
|
};
|
package/dist/types/version.d.ts
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export declare const version = "
|
|
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": "
|
|
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": "^
|
|
33
|
-
"@equinor/fusion-framework-vite-plugin-api-service": "
|
|
34
|
-
"@equinor/fusion-framework-vite-plugin-spa": "
|
|
35
|
-
"@equinor/fusion-log": "
|
|
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.
|
|
39
|
-
"vite": "^
|
|
40
|
-
"vitest": "^4.0
|
|
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
|
-
*
|
|
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
|
-
*
|
|
26
|
-
*
|
|
27
|
-
*
|
|
28
|
-
*
|
|
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
|
-
* @
|
|
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
|
-
* -
|
|
34
|
-
* -
|
|
35
|
-
* - The
|
|
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: {
|
|
44
|
-
*
|
|
45
|
-
*
|
|
46
|
-
*
|
|
47
|
-
*
|
|
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>>(
|
package/src/create-dev-server.ts
CHANGED
|
@@ -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
|
-
*
|
|
7
|
+
* Create and return a fully configured Vite development server for a Fusion Framework application.
|
|
8
8
|
*
|
|
9
|
-
*
|
|
10
|
-
*
|
|
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';
|
package/src/process-services.ts
CHANGED
|
@@ -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
|
-
*
|
|
6
|
-
* and
|
|
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
|
-
*
|
|
9
|
-
*
|
|
10
|
-
*
|
|
11
|
-
*
|
|
12
|
-
* @param
|
|
13
|
-
* @
|
|
14
|
-
* @
|
|
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
|
-
*
|
|
24
|
-
*
|
|
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
|
-
* @
|
|
27
|
-
*
|
|
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
|
-
* @
|
|
32
|
-
*
|
|
33
|
-
*
|
|
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 = '
|
|
2
|
+
export const version = '2.0.0';
|