@blakearoberts/visage 0.0.1-rc.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/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 Blake Roberts
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,128 @@
1
+ # Visage
2
+
3
+ Visage (`/vit·ɛdʒ/`) is a Vite plugin for local development with HMR and OIDC session cookie lifecycle semantics.
4
+
5
+ ## Getting Started
6
+
7
+ Install Visage from npm:
8
+
9
+ ```console
10
+ npm install @blakearoberts/visage@next
11
+ ```
12
+
13
+ Add the plugin to `vite.config.ts`:
14
+
15
+ ```ts
16
+ import { defineConfig } from 'vite';
17
+ import visage from '@blakearoberts/visage';
18
+
19
+ export default defineConfig({
20
+ plugins: [visage()],
21
+ });
22
+ ```
23
+
24
+ Then start Vite normally:
25
+
26
+ ```console
27
+ vite
28
+ ```
29
+
30
+ ## Configuration
31
+
32
+ Visage is configured through `visage(options?)` in `vite.config.ts`.
33
+
34
+ The top-level `host` and `port` configure the local Visage origin that the browser visits:
35
+
36
+ ```ts
37
+ visage({
38
+ host: 'localhost',
39
+ port: 9001,
40
+ });
41
+ ```
42
+
43
+ Services are Docker Compose services managed by the Vite dev-server lifecycle. Upstreams are proxy targets that Visage routes to, whether they are managed services or external systems.
44
+
45
+ ```ts
46
+ visage({
47
+ services: {
48
+ whoami: { image: 'traefik/whoami' },
49
+ },
50
+ upstreams: {
51
+ whoami: {
52
+ host: 'whoami',
53
+ port: 80,
54
+ locations: { '/whoami/': {} },
55
+ },
56
+ },
57
+ });
58
+ ```
59
+
60
+ See `VisageOptions` for the full option surface.
61
+
62
+ ## Expected Local URLs
63
+
64
+ The browser-facing Visage origin is `https://{host}:{port}`.
65
+
66
+ With the default configuration, open:
67
+
68
+ ```text
69
+ https://localhost:9001/
70
+ ```
71
+
72
+ When using the managed Dex flow, OAuth2 Proxy serves auth endpoints under `/oauth2/` and Dex serves OIDC endpoints under `/dex/`.
73
+
74
+ ## System Block Diagram
75
+
76
+ ```mermaid
77
+ flowchart LR
78
+ Browser
79
+ NGINX
80
+ Oauth2-Proxy
81
+ Vite
82
+ IDP["IdP (Dex)"]
83
+ ServicesUpstreams["Services / Upstreams"]
84
+
85
+ Browser --> NGINX
86
+ NGINX --> Oauth2-Proxy
87
+ Oauth2-Proxy --> IDP
88
+ NGINX --> Vite
89
+ NGINX --> ServicesUpstreams
90
+ ```
91
+
92
+ ## Required Tools
93
+
94
+ - [Docker](https://docs.docker.com/get-started/get-docker/) with Compose v2 support through `docker compose`.
95
+
96
+ ## Managed Tools
97
+
98
+ ### mkcert
99
+
100
+ Visage downloads [`mkcert`](https://github.com/FiloSottile/mkcert) from `dl.filippo.io` when the Vite dev server starts. Visage uses it to install a local certificate authority and generate HTTPS certificates for the local proxy.
101
+
102
+ ### Docker Images
103
+
104
+ Visage pulls these as needed based on configuration:
105
+
106
+ - [NGINX](https://nginx.org/): [`nginx:1.30.0-alpine`](https://hub.docker.com/_/nginx).
107
+ - [OAuth2 Proxy](https://oauth2-proxy.github.io/oauth2-proxy/): [`quay.io/oauth2-proxy/oauth2-proxy:v7.15.2`](https://quay.io/repository/oauth2-proxy/oauth2-proxy).
108
+ - [Dex](https://dexidp.io/): [`ghcr.io/dexidp/dex:v2.45.1`](https://github.com/dexidp/dex/pkgs/container/dex).
109
+
110
+ ## Security Notes
111
+
112
+ Visage is local-development tooling. It starts local auth infrastructure, terminates local HTTPS, and forwards authenticated identity or token material to configured upstreams.
113
+
114
+ Do not treat the managed Dex and OAuth2 Proxy defaults as production auth infrastructure.
115
+
116
+ ## Troubleshooting
117
+
118
+ - If startup fails immediately, confirm Docker is running and `docker compose` works.
119
+ - If NGINX cannot start, check whether the configured `port` is already in use.
120
+ - If the hostname cannot be resolved, Visage may need permission to update `/etc/hosts`.
121
+ - If the browser rejects the certificate, allow the local certificate authority prompt from `mkcert`.
122
+
123
+ ## TO-DO
124
+
125
+ - [ ] Promote a stable release.
126
+ - [ ] Support configuring [Dex connectors](https://dexidp.io/docs/connectors/).
127
+ - [ ] Support configuring Dex on a distinct subdomain, such as `auth.local.vite.app`.
128
+ - [ ] Support optional [HTTP mode without local TLS](docs/tls-http-mode.md).
@@ -0,0 +1,8 @@
1
+ type Options = {
2
+ bin: string;
3
+ certs: string;
4
+ hostname: string;
5
+ };
6
+ export declare function ensureCerts({ bin, certs, hostname, }: Options): Promise<void>;
7
+ export {};
8
+ //# sourceMappingURL=certs.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"certs.d.ts","sourceRoot":"","sources":["../src/certs.ts"],"names":[],"mappings":"AAMA,KAAK,OAAO,GAAG;IACb,GAAG,EAAE,MAAM,CAAC;IACZ,KAAK,EAAE,MAAM,CAAC;IACd,QAAQ,EAAE,MAAM,CAAC;CAClB,CAAC;AAEF,wBAAsB,WAAW,CAAC,EAChC,GAAG,EACH,KAAK,EACL,QAAQ,GACT,EAAE,OAAO,GAAG,OAAO,CAAC,IAAI,CAAC,CAiCzB"}
@@ -0,0 +1,4 @@
1
+ type StopCompose = () => void;
2
+ export declare function startCompose(file: string): StopCompose;
3
+ export {};
4
+ //# sourceMappingURL=compose.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"compose.d.ts","sourceRoot":"","sources":["../src/compose.ts"],"names":[],"mappings":"AAGA,KAAK,WAAW,GAAG,MAAM,IAAI,CAAC;AAI9B,wBAAgB,YAAY,CAAC,IAAI,EAAE,MAAM,GAAG,WAAW,CAoBtD"}
@@ -0,0 +1,76 @@
1
+ import type { ResolvedConfig } from 'vite';
2
+ import type { VisageDexExpiry, VisageDexUser, VisageOptions, VisageService, VisageUpstream } from './types';
3
+ type Volume = readonly [from: string, to: string];
4
+ type ResolvedCookiePolicy = {
5
+ readonly cookie_name: string;
6
+ readonly cookie_expire: string;
7
+ readonly cookie_refresh: string;
8
+ readonly cookie_domains?: readonly string[];
9
+ readonly cookie_path: string;
10
+ };
11
+ type ResolvedDexConfig = {
12
+ readonly expiry?: VisageDexExpiry;
13
+ readonly users: readonly Required<VisageDexUser>[];
14
+ };
15
+ type ResolvedIdpOption = {
16
+ readonly path: string;
17
+ readonly upstream: string;
18
+ readonly issuer?: string;
19
+ readonly authorizationEndpoint?: string;
20
+ readonly tokenEndpoint?: string;
21
+ readonly jwksEndpoint?: string;
22
+ } & ({
23
+ readonly kind: 'dex';
24
+ readonly dex: ResolvedDexConfig;
25
+ } | {
26
+ readonly kind: 'external';
27
+ });
28
+ type ResolvedIdp = {
29
+ readonly issuer: string;
30
+ readonly authorizationEndpoint: string;
31
+ readonly tokenEndpoint: string;
32
+ readonly jwksEndpoint: string;
33
+ readonly upstream: string;
34
+ } & ({
35
+ readonly kind: 'dex';
36
+ readonly dex: ResolvedDexConfig;
37
+ } | {
38
+ readonly kind: 'external';
39
+ });
40
+ type ResolvedOAuth2Client = {
41
+ readonly id: string;
42
+ readonly secret?: string;
43
+ readonly scopes: readonly string[];
44
+ readonly public: boolean;
45
+ };
46
+ type ResolvedVisageOptions = {
47
+ readonly host: string;
48
+ readonly port: number;
49
+ readonly cookie: ResolvedCookiePolicy;
50
+ readonly idp: ResolvedIdpOption;
51
+ readonly oauth2: ResolvedOAuth2Client;
52
+ readonly services?: Record<string, VisageService>;
53
+ readonly upstreams?: Record<string, VisageUpstream>;
54
+ };
55
+ export type VisageConfig = {
56
+ readonly host: string;
57
+ readonly port: number;
58
+ readonly cookie: ResolvedCookiePolicy;
59
+ readonly idp: ResolvedIdp;
60
+ readonly oauth2: ResolvedOAuth2Client;
61
+ readonly cache: string;
62
+ readonly files: {
63
+ readonly certs: Volume;
64
+ readonly compose: string;
65
+ readonly dex: Volume;
66
+ readonly nginx: Volume;
67
+ readonly oauth2Proxy: Volume;
68
+ readonly oauth2ProxyClientSecret: Volume;
69
+ };
70
+ readonly services: Readonly<Record<string, VisageService>>;
71
+ readonly upstreams: Readonly<Record<string, VisageUpstream>>;
72
+ };
73
+ export declare function resolveOptions(options: VisageOptions): ResolvedVisageOptions;
74
+ export declare function resolveConfig(options: ResolvedVisageOptions, config: ResolvedConfig, vitePort: number): VisageConfig;
75
+ export {};
76
+ //# sourceMappingURL=config.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"config.d.ts","sourceRoot":"","sources":["../src/config.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,MAAM,CAAC;AAE3C,OAAO,KAAK,EACV,eAAe,EAEf,aAAa,EAEb,aAAa,EAEb,aAAa,EACb,cAAc,EACf,MAAM,SAAS,CAAC;AAEjB,KAAK,MAAM,GAAG,SAAS,CAAC,IAAI,EAAE,MAAM,EAAE,EAAE,EAAE,MAAM,CAAC,CAAC;AAElD,KAAK,oBAAoB,GAAG;IAC1B,QAAQ,CAAC,WAAW,EAAE,MAAM,CAAC;IAC7B,QAAQ,CAAC,aAAa,EAAE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AAQ,CAAC,uBAAuB,EAAE,MAAM,CAAC;KAC1C,CAAC;IAEF,QAAQ,CAAC,QAAQ,EAAE,QAAQ,CAAC,MAAM,CAAC,MAAM,EAAE,aAAa,CAAC,CAAC,CAAC;IAC3D,QAAQ,CAAC,SAAS,EAAE,QAAQ,CAAC,MAAM,CAAC,MAAM,EAAE,cAAc,CAAC,CAAC,CAAC;CAC9D,CAAC;AA6GF,wBAAgB,cAAc,CAAC,OAAO,EAAE,aAAa,GAAG,qBAAqB,CAqC5E;AA6BD,wBAAgB,aAAa,CAC3B,OAAO,EAAE,qBAAqB,EAC9B,MAAM,EAAE,cAAc,EACtB,QAAQ,EAAE,MAAM,GACf,YAAY,CAiEd"}
@@ -0,0 +1,2 @@
1
+ export declare function ensureHostEntry(hostname: string): void;
2
+ //# sourceMappingURL=hosts.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"hosts.d.ts","sourceRoot":"","sources":["../src/hosts.ts"],"names":[],"mappings":"AAKA,wBAAgB,eAAe,CAAC,QAAQ,EAAE,MAAM,GAAG,IAAI,CAyDtD"}
@@ -0,0 +1,6 @@
1
+ import type { Plugin } from 'vite';
2
+ import type { VisageOptions } from './types';
3
+ export type { VisageCookiePolicy, VisageDexExpiry, VisageDexOptions, VisageDexUser, VisageIdpOptions, VisageOAuth2Client, VisageOptions, VisageProxyPolicy, VisageService, VisageUpstream, } from './types';
4
+ export declare function visage(options?: VisageOptions): Plugin;
5
+ export default visage;
6
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,MAAM,CAAC;AAOnC,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,SAAS,CAAC;AAE7C,YAAY,EACV,kBAAkB,EAClB,eAAe,EACf,gBAAgB,EAChB,aAAa,EACb,gBAAgB,EAChB,kBAAkB,EAClB,aAAa,EACb,iBAAiB,EACjB,aAAa,EACb,cAAc,GACf,MAAM,SAAS,CAAC;AAEjB,wBAAgB,MAAM,CAAC,OAAO,GAAE,aAAkB,GAAG,MAAM,CAmD1D;AAED,eAAe,MAAM,CAAC"}
package/dist/index.js ADDED
@@ -0,0 +1,621 @@
1
+ import { dirname, join } from 'node:path';
2
+ import { spawnSync } from 'node:child_process';
3
+ import { existsSync, mkdirSync, createWriteStream, chmodSync, readFileSync, appendFileSync, writeFileSync } from 'node:fs';
4
+ import { Readable } from 'node:stream';
5
+ import { pipeline } from 'node:stream/promises';
6
+ import { stringify } from 'yaml';
7
+ import { hashSync } from 'bcryptjs';
8
+ import { Eta } from 'eta';
9
+ import { createHash } from 'node:crypto';
10
+
11
+ let stopCompose;
12
+ function startCompose(file) {
13
+ stopCompose?.();
14
+ stopCompose = undefined;
15
+ const stop = () => {
16
+ if (stopCompose !== stop)
17
+ return;
18
+ stopCompose = undefined;
19
+ process.off('SIGINT', onSigInt);
20
+ process.off('SIGTERM', onSigTerm);
21
+ run(file, ['down'], 'Failed to stop Docker Compose');
22
+ };
23
+ run(file, ['up', '-d'], 'Failed to start Docker Compose');
24
+ stopCompose = stop;
25
+ process.off('SIGINT', onSigInt);
26
+ process.off('SIGTERM', onSigTerm);
27
+ process.once('SIGINT', onSigInt);
28
+ process.once('SIGTERM', onSigTerm);
29
+ return stop;
30
+ }
31
+ function run(file, args, message) {
32
+ const result = spawnSync('docker', ['compose', '-f', file, ...args], {
33
+ cwd: dirname(file),
34
+ stdio: 'inherit',
35
+ });
36
+ if (result.error)
37
+ throw result.error;
38
+ if (result.status !== 0)
39
+ throw new Error(message);
40
+ }
41
+ function onSigInt() {
42
+ try {
43
+ stopCompose?.();
44
+ }
45
+ finally {
46
+ process.exit(130);
47
+ }
48
+ }
49
+ function onSigTerm() {
50
+ try {
51
+ stopCompose?.();
52
+ }
53
+ finally {
54
+ process.exit(143);
55
+ }
56
+ }
57
+
58
+ async function ensureCerts({ bin, certs, hostname, }) {
59
+ const cert = join(certs, 'tls.crt');
60
+ const key = join(certs, 'tls.key');
61
+ if (existsSync(cert) && existsSync(key))
62
+ return;
63
+ const mkcert = await ensureMkCert(bin);
64
+ const env = {
65
+ ...process.env,
66
+ CAROOT: join(bin, 'ca'),
67
+ TRUST_STORES: process.env.TRUST_STORES ?? 'system',
68
+ };
69
+ // install CA
70
+ {
71
+ const result = spawnSync(mkcert, ['-install'], {
72
+ env,
73
+ stdio: [process.stdin.isTTY ? 'inherit' : 'ignore', 'inherit', 'inherit'],
74
+ });
75
+ if (result.error)
76
+ throw result.error;
77
+ if (result.status !== 0) {
78
+ throw new Error('Failed to install CA');
79
+ }
80
+ }
81
+ // generate certs
82
+ mkdirSync(certs, { recursive: true });
83
+ const names = [...new Set([hostname, 'localhost', '127.0.0.1', '::1'])];
84
+ const args = ['-cert-file', cert, '-key-file', key, ...names];
85
+ const result = spawnSync(mkcert, args, { env, stdio: 'inherit' });
86
+ if (result.error)
87
+ throw result.error;
88
+ if (result.status !== 0) {
89
+ throw new Error('Failed to generate TLS certificates');
90
+ }
91
+ }
92
+ async function ensureMkCert(bin) {
93
+ const file = join(bin, 'mkcert');
94
+ if (existsSync(file))
95
+ return file;
96
+ mkdirSync(bin, { recursive: true });
97
+ const base = 'https://dl.filippo.io/mkcert/latest';
98
+ const arch = process.arch === 'x64' ? 'amd64' : process.arch;
99
+ const params = `?for=${process.platform}/${arch}`;
100
+ const url = new URL(params, base);
101
+ const response = await fetch(url);
102
+ if (!response.ok || !response.body) {
103
+ throw new Error('Failed to download mkcert');
104
+ }
105
+ await pipeline(Readable.fromWeb(response.body), createWriteStream(file));
106
+ chmodSync(file, 0o755);
107
+ return file;
108
+ }
109
+
110
+ const HOSTS_FILE = '/etc/hosts';
111
+ function ensureHostEntry(hostname) {
112
+ if (!hostname ||
113
+ hostname.trim() !== hostname ||
114
+ hostname.includes('/') ||
115
+ hostname.includes(':')) {
116
+ throw new Error('Invalid hostname');
117
+ }
118
+ const contents = readFileSync(HOSTS_FILE, 'utf8');
119
+ for (const line of contents.split(/\r?\n/)) {
120
+ const uncommented = line.replace(/\s+#.*$/, '').trim();
121
+ if (!uncommented || uncommented.startsWith('#')) {
122
+ continue;
123
+ }
124
+ const [address, ...names] = uncommented.split(/\s+/);
125
+ if (!names.includes(hostname)) {
126
+ continue;
127
+ }
128
+ if (address === '127.0.0.1' || address === '::1') {
129
+ // Already configured to loopback, nothing to do.
130
+ return;
131
+ }
132
+ throw new Error('Hosts file contains a conflicting entry');
133
+ }
134
+ const prefix = contents.endsWith('\n') ? '' : '\n';
135
+ const entry = `${prefix}127.0.0.1\t${hostname} # visage\n`;
136
+ try {
137
+ appendFileSync(HOSTS_FILE, entry);
138
+ return;
139
+ }
140
+ catch {
141
+ // Fall through to sudo tee.
142
+ }
143
+ const result = spawnSync('sudo', [...(process.stdin.isTTY ? [] : ['-n']), 'tee', '-a', HOSTS_FILE], {
144
+ input: entry,
145
+ stdio: ['pipe', 'ignore', 'inherit'],
146
+ });
147
+ if (result.error) {
148
+ throw result.error;
149
+ }
150
+ if (result.status !== 0) {
151
+ throw new Error('Failed to add hosts entry');
152
+ }
153
+ }
154
+
155
+ function writeComposeConfig(config) {
156
+ const file = join(config.cache, config.files.compose);
157
+ const render = renderComposeConfig(config);
158
+ writeFileSync(file, render, 'utf-8');
159
+ }
160
+ function renderComposeConfig(config) {
161
+ const { dex, nginx, oauth2_proxy, ...services } = config.services;
162
+ return stringify({
163
+ services: {
164
+ ...(config.idp.kind === 'dex'
165
+ ? {
166
+ dex: {
167
+ ...config.services.dex,
168
+ volumes: [`${config.files.dex[0]}:${config.files.dex[1]}:ro`],
169
+ },
170
+ }
171
+ : {}),
172
+ nginx: {
173
+ ...config.services.nginx,
174
+ ports: [`${config.port}:${config.port}`],
175
+ volumes: [config.files.certs, config.files.nginx].map(([from, to]) => `${from}:${to}:ro`),
176
+ },
177
+ oauth2_proxy: {
178
+ ...config.services.oauth2_proxy,
179
+ volumes: [
180
+ `${config.files.oauth2Proxy[0]}:${config.files.oauth2Proxy[1]}:ro`,
181
+ ...(config.oauth2.public
182
+ ? [
183
+ `${config.files.oauth2ProxyClientSecret[0]}:${config.files.oauth2ProxyClientSecret[1]}:ro`,
184
+ ]
185
+ : []),
186
+ ],
187
+ },
188
+ ...services,
189
+ },
190
+ });
191
+ }
192
+
193
+ function writeDexConfig(config) {
194
+ const file = join(config.cache, config.files.dex[0]);
195
+ const render = renderDexConfig(config);
196
+ writeFileSync(file, render, 'utf-8');
197
+ }
198
+ function renderDexConfig(config) {
199
+ if (config.idp.kind !== 'dex') {
200
+ throw new Error('Dex config is required to render Dex');
201
+ }
202
+ const origin = `https://${config.host}:${config.port}`;
203
+ const redirect = `${origin}/oauth2/callback`;
204
+ const upstream = config.upstreams[config.idp.upstream];
205
+ return stringify({
206
+ issuer: config.idp.issuer,
207
+ storage: { type: 'memory' },
208
+ web: { http: `0.0.0.0:${upstream.port}` },
209
+ oauth2: { skipApprovalScreen: true },
210
+ staticClients: [
211
+ {
212
+ id: config.oauth2.id,
213
+ name: 'Visage',
214
+ ...(config.oauth2.secret === undefined
215
+ ? { public: true }
216
+ : { secret: config.oauth2.secret }),
217
+ redirectURIs: [redirect],
218
+ },
219
+ ],
220
+ enablePasswordDB: true,
221
+ ...(config.idp.dex.expiry === undefined
222
+ ? {}
223
+ : { expiry: config.idp.dex.expiry }),
224
+ staticPasswords: config.idp.dex.users.map(({ password, ...user }) => ({
225
+ ...user,
226
+ hash: hashSync(password, 10),
227
+ })),
228
+ });
229
+ }
230
+
231
+ const template = `
232
+ events {}
233
+
234
+ http {
235
+ # Allow WebSockets (Vite HMR).
236
+ map $http_upgrade $connection_upgrade {
237
+ default upgrade;
238
+ '' close;
239
+ }
240
+
241
+ <%_ for (const [name, upstream] of Object.entries(it.upstreams)) { %>
242
+ upstream <%~ name %> {
243
+ server <%~ upstream.host %>:<%~ upstream.port %>;
244
+ }
245
+
246
+ <%_ } %>
247
+ server {
248
+ listen <%~ it.port %> ssl;
249
+ server_name <%~ it.host %>;
250
+
251
+ ssl_certificate <%~ it.ssl.cert %>;
252
+ ssl_certificate_key <%~ it.ssl.key %>;
253
+
254
+ <%_ for (const [name, upstream] of Object.entries(it.upstreams)) { %>
255
+ <%_ for (const [path, location] of Object.entries(upstream.locations ?? {})) { %>
256
+ location <%~ path %> {
257
+ <%_ if (location.auth?.enabled) { %>
258
+ auth_request /oauth2/auth;
259
+ auth_request_set $access_token $upstream_http_x_auth_request_access_token;
260
+
261
+ <%_ if (location.auth.redirect) { %>
262
+ error_page 401 =302 /oauth2/start?rd=$scheme://$http_host$request_uri;
263
+ <%_ } %>
264
+ <%_ } %>
265
+ <%_ for (const [header, value] of Object.entries(location.headers ?? {})) { %>
266
+ proxy_set_header <%~ header %> <%~ value %>;
267
+ <%_ } %>
268
+ <%_ if (location.auth?.enabled && location.auth.forward) { %>
269
+ proxy_set_header Authorization "Bearer $access_token";
270
+ <%_ } %>
271
+ proxy_pass http://<%~ name %>;
272
+ }
273
+ <%_ } %>
274
+
275
+ <%_ } %>
276
+ }
277
+ }
278
+ `;
279
+ function writeNginxConfig(config) {
280
+ const file = join(config.cache, config.files.nginx[0]);
281
+ const render = renderNginxConfig(config);
282
+ writeFileSync(file, render, 'utf-8');
283
+ }
284
+ function renderNginxConfig(config) {
285
+ const data = {
286
+ host: config.host,
287
+ port: config.port,
288
+ ssl: {
289
+ cert: join(config.files.certs[1], 'tls.crt'),
290
+ key: join(config.files.certs[1], 'tls.key'),
291
+ },
292
+ upstreams: config.upstreams,
293
+ };
294
+ return new Eta({ autoTrim: false }).renderString(template, data);
295
+ }
296
+
297
+ function writeOauth2ProxyConfig(config) {
298
+ const file = join(config.cache, config.files.oauth2Proxy[0]);
299
+ const render = renderOauth2ProxyConfig(config);
300
+ writeFileSync(file, render, 'utf-8');
301
+ if (config.oauth2.public) {
302
+ writeFileSync(join(config.cache, config.files.oauth2ProxyClientSecret[0]), '');
303
+ }
304
+ }
305
+ function renderOauth2ProxyConfig(config) {
306
+ const data = {
307
+ http_address: `0.0.0.0:${config.upstreams.oauth2_proxy.port}`,
308
+ provider: 'oidc',
309
+ oidc_issuer_url: config.idp.issuer,
310
+ skip_oidc_discovery: true,
311
+ login_url: config.idp.authorizationEndpoint,
312
+ redeem_url: config.idp.tokenEndpoint,
313
+ oidc_jwks_url: config.idp.jwksEndpoint,
314
+ redirect_url: `https://${config.host}:${config.port}/oauth2/callback`,
315
+ client_id: config.oauth2.id,
316
+ ...(config.oauth2.secret === undefined
317
+ ? {
318
+ client_secret_file: config.files.oauth2ProxyClientSecret[1],
319
+ code_challenge_method: 'S256',
320
+ }
321
+ : { client_secret: config.oauth2.secret }),
322
+ cookie_secret: createHash('sha256')
323
+ .update('visage:cookie-secret\0')
324
+ .update(config.cache)
325
+ .digest('base64url'),
326
+ ...config.cookie,
327
+ cookie_httponly: true,
328
+ cookie_secure: true,
329
+ cookie_samesite: 'lax',
330
+ email_domains: ['*'],
331
+ scope: config.oauth2.scopes.join(' '),
332
+ upstreams: ['static://202'],
333
+ reverse_proxy: true,
334
+ set_xauthrequest: true,
335
+ pass_access_token: true,
336
+ pass_authorization_header: true,
337
+ skip_provider_button: true,
338
+ };
339
+ return `${Object.entries(data)
340
+ .map(([key, value]) => {
341
+ if (Array.isArray(value)) {
342
+ const values = value.map((item) => JSON.stringify(item)).join(', ');
343
+ return `${key} = [${values}]`;
344
+ }
345
+ if (typeof value === 'string') {
346
+ return `${key} = ${JSON.stringify(value)}`;
347
+ }
348
+ return `${key} = ${String(value)}`;
349
+ })
350
+ .join('\n')}\n`;
351
+ }
352
+
353
+ function render(config) {
354
+ writeComposeConfig(config);
355
+ if (config.idp.kind === 'dex') {
356
+ writeDexConfig(config);
357
+ }
358
+ writeNginxConfig(config);
359
+ writeOauth2ProxyConfig(config);
360
+ }
361
+
362
+ const BaseFiles = {
363
+ certs: ['./certs', '/etc/nginx/certs'],
364
+ compose: './compose.yaml',
365
+ dex: ['./dex.yml', '/etc/dex/dex.yml'],
366
+ nginx: ['./nginx.conf', '/etc/nginx/nginx.conf'],
367
+ oauth2ProxyClientSecret: [
368
+ './oauth2-client-secret',
369
+ '/etc/oauth2-proxy/client-secret',
370
+ ],
371
+ oauth2Proxy: ['./oauth2-proxy.yml', '/etc/oauth2-proxy/config.yml'],
372
+ };
373
+ const BaseServices = {
374
+ dex: {
375
+ image: 'ghcr.io/dexidp/dex:v2.45.1',
376
+ command: ['dex', 'serve', '/etc/dex/dex.yml'],
377
+ },
378
+ nginx: {
379
+ image: 'nginx:1.30.0-alpine',
380
+ depends_on: ['oauth2_proxy', 'dex'],
381
+ extra_hosts: ['host.docker.internal:host-gateway'],
382
+ },
383
+ oauth2_proxy: {
384
+ image: 'quay.io/oauth2-proxy/oauth2-proxy:v7.15.2',
385
+ command: ['--config', '/etc/oauth2-proxy/config.yml'],
386
+ depends_on: ['dex'],
387
+ extra_hosts: ['host.docker.internal:host-gateway'],
388
+ },
389
+ };
390
+ const BaseDexUpstream = {
391
+ host: 'dex',
392
+ port: 5556,
393
+ locations: { '/dex/': { auth: { enabled: false } } },
394
+ };
395
+ const BaseOauth2ProxyUpstream = {
396
+ host: 'oauth2_proxy',
397
+ port: 4180,
398
+ locations: {
399
+ '/oauth2/': {
400
+ auth: { enabled: false },
401
+ headers: {
402
+ Cookie: '$http_cookie',
403
+ Host: '$host',
404
+ 'X-Real-IP': '$remote_addr',
405
+ 'X-Forwarded-For': '$proxy_add_x_forwarded_for',
406
+ 'X-Forwarded-Proto': '$scheme',
407
+ 'X-Auth-Request-Redirect': '$request_uri',
408
+ },
409
+ },
410
+ },
411
+ };
412
+ const BaseViteUpstream = {
413
+ host: 'host.docker.internal',
414
+ locations: {
415
+ '/': {
416
+ auth: { forward: false, redirect: true },
417
+ headers: {
418
+ Upgrade: '$http_upgrade',
419
+ Connection: '$connection_upgrade',
420
+ },
421
+ },
422
+ },
423
+ };
424
+ const DefaultCookiePolicy = {
425
+ cookie_expire: '8h',
426
+ cookie_refresh: '15m',
427
+ cookie_path: '/',
428
+ };
429
+ const DefaultDexUsers = [
430
+ {
431
+ email: 'user@example.com',
432
+ password: 'pass',
433
+ },
434
+ ];
435
+ const DefaultIdpConfig = {
436
+ kind: 'dex',
437
+ path: '/dex',
438
+ upstream: 'dex',
439
+ };
440
+ const DefaultOAuth2Client = {
441
+ id: 'visage',
442
+ secret: 'visage-secret',
443
+ scopes: ['openid', 'email', 'profile']};
444
+ const DefaultProxyPolicy = {
445
+ auth: { enabled: true, forward: true, redirect: false },
446
+ headers: {
447
+ Cookie: '""', // Don't forward session cookie.
448
+ Host: '$host',
449
+ 'X-Real-IP': '$remote_addr',
450
+ 'X-Forwarded-For': '$proxy_add_x_forwarded_for',
451
+ 'X-Forwarded-Proto': '$scheme',
452
+ },
453
+ };
454
+ function resolveOptions(options) {
455
+ const cookie = options.cookie ?? {};
456
+ const cookieName = cookie.name ?? 'session';
457
+ const oauth2 = options.oauth2 ?? {};
458
+ const publicClient = oauth2.clientSecret === null;
459
+ return {
460
+ ...options,
461
+ host: options.host ?? 'local.vite.app',
462
+ port: options.port ?? 9001,
463
+ cookie: {
464
+ ...DefaultCookiePolicy,
465
+ cookie_name: cookie.domains === undefined
466
+ ? cookieName.startsWith('__HOST-')
467
+ ? cookieName
468
+ : `__HOST-${cookieName}`
469
+ : cookieName,
470
+ ...(cookie.expire === undefined ? {} : { cookie_expire: cookie.expire }),
471
+ ...(cookie.refresh === undefined
472
+ ? {}
473
+ : { cookie_refresh: cookie.refresh }),
474
+ ...(cookie.domains === undefined
475
+ ? {}
476
+ : { cookie_domains: cookie.domains }),
477
+ ...(cookie.path === undefined ? {} : { cookie_path: cookie.path }),
478
+ },
479
+ idp: resolveIdpOption(options.idp),
480
+ oauth2: {
481
+ id: oauth2.clientId ?? DefaultOAuth2Client.id,
482
+ ...(publicClient
483
+ ? {}
484
+ : { secret: oauth2.clientSecret ?? DefaultOAuth2Client.secret }),
485
+ scopes: oauth2.scopes ?? DefaultOAuth2Client.scopes,
486
+ public: publicClient,
487
+ },
488
+ };
489
+ }
490
+ function resolveIdpOption(idp) {
491
+ function normalizePath(path) {
492
+ const pathWithLeadingSlash = path.startsWith('/') ? path : `/${path}`;
493
+ return pathWithLeadingSlash.endsWith('/')
494
+ ? pathWithLeadingSlash.slice(0, -1)
495
+ : pathWithLeadingSlash;
496
+ }
497
+ if (idp?.kind === 'external') {
498
+ const { path = DefaultIdpConfig.path, ...external } = idp;
499
+ return { ...external, path: normalizePath(path) };
500
+ }
501
+ return {
502
+ ...DefaultIdpConfig,
503
+ dex: {
504
+ ...(idp?.expiry ? { expiry: idp.expiry } : {}),
505
+ users: (idp?.users ?? DefaultDexUsers).map((user) => ({
506
+ email: user.email,
507
+ password: user.password,
508
+ username: user.username ?? user.email.split('@', 1)[0],
509
+ userID: user.userID ?? user.email,
510
+ })),
511
+ },
512
+ };
513
+ }
514
+ function resolveConfig(options, config, vitePort) {
515
+ const upstreams = {
516
+ oauth2_proxy: BaseOauth2ProxyUpstream,
517
+ vite: { ...BaseViteUpstream, port: vitePort },
518
+ ...(options.idp.kind === 'dex' ? { dex: BaseDexUpstream } : {}),
519
+ ...options.upstreams,
520
+ };
521
+ const { host: idpHost, port: idpPort } = upstreams[options.idp.upstream];
522
+ const origin = `https://${options.host}:${options.port}`;
523
+ const idpOrigin = `http://${idpHost}:${idpPort}`;
524
+ const idpBase = {
525
+ upstream: options.idp.upstream,
526
+ issuer: options.idp.issuer ?? `${origin}${options.idp.path}`,
527
+ authorizationEndpoint: options.idp.authorizationEndpoint ?? `${origin}${options.idp.path}/auth`,
528
+ tokenEndpoint: options.idp.tokenEndpoint ?? `${idpOrigin}${options.idp.path}/token`,
529
+ jwksEndpoint: options.idp.jwksEndpoint ?? `${idpOrigin}${options.idp.path}/keys`,
530
+ };
531
+ return {
532
+ host: options.host,
533
+ port: options.port,
534
+ cookie: options.cookie,
535
+ idp: options.idp.kind === 'dex'
536
+ ? { ...idpBase, kind: 'dex', dex: options.idp.dex }
537
+ : { ...idpBase, kind: 'external' },
538
+ oauth2: options.oauth2,
539
+ cache: join(config.cacheDir, 'visage'),
540
+ files: { ...BaseFiles },
541
+ services: {
542
+ ...(options.idp.kind === 'dex'
543
+ ? BaseServices
544
+ : {
545
+ nginx: {
546
+ ...BaseServices.nginx,
547
+ depends_on: ['oauth2_proxy'],
548
+ },
549
+ oauth2_proxy: {
550
+ command: BaseServices.oauth2_proxy.command,
551
+ extra_hosts: BaseServices.oauth2_proxy.extra_hosts,
552
+ image: BaseServices.oauth2_proxy.image,
553
+ },
554
+ }),
555
+ ...options.services,
556
+ },
557
+ upstreams: Object.fromEntries(Object.entries(upstreams).map(([name, upstream]) => [
558
+ name,
559
+ {
560
+ ...upstream,
561
+ locations: Object.fromEntries(Object.entries(upstream.locations ?? {}).map(([path, policy]) => [
562
+ path,
563
+ {
564
+ auth: { ...DefaultProxyPolicy.auth, ...policy.auth },
565
+ headers: { ...DefaultProxyPolicy.headers, ...policy.headers },
566
+ },
567
+ ])),
568
+ },
569
+ ])),
570
+ };
571
+ }
572
+
573
+ function visage(options = {}) {
574
+ const resolvedOptions = resolveOptions(options);
575
+ let stop;
576
+ return {
577
+ name: 'visage',
578
+ apply: 'serve',
579
+ config() {
580
+ return {
581
+ server: {
582
+ hmr: {
583
+ protocol: 'wss',
584
+ host: resolvedOptions.host,
585
+ clientPort: resolvedOptions.port,
586
+ },
587
+ host: '0.0.0.0',
588
+ },
589
+ };
590
+ },
591
+ configureServer(server) {
592
+ async function startVisage(port) {
593
+ const config = resolveConfig(resolvedOptions, server.config, port);
594
+ await ensureCerts({
595
+ bin: join(config.cache, 'bin'),
596
+ certs: join(config.cache, config.files.certs[0]),
597
+ hostname: config.host,
598
+ });
599
+ ensureHostEntry(config.host);
600
+ render(config);
601
+ return startCompose(join(config.cache, config.files.compose));
602
+ }
603
+ const listen = server.listen.bind(server);
604
+ server.listen = async (port, isRestart) => {
605
+ const result = await listen(port, isRestart);
606
+ const address = server.httpServer?.address();
607
+ if (!address || typeof address === 'string') {
608
+ throw new Error('Failed to resolve port for Visage');
609
+ }
610
+ stop = await startVisage(address.port);
611
+ return result;
612
+ };
613
+ },
614
+ closeBundle() {
615
+ stop?.();
616
+ stop = undefined;
617
+ },
618
+ };
619
+ }
620
+
621
+ export { visage as default, visage };
@@ -0,0 +1,3 @@
1
+ import type { VisageConfig } from '../config';
2
+ export declare function writeComposeConfig(config: VisageConfig): void;
3
+ //# sourceMappingURL=compose.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"compose.d.ts","sourceRoot":"","sources":["../../src/render/compose.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,WAAW,CAAC;AAE9C,wBAAgB,kBAAkB,CAAC,MAAM,EAAE,YAAY,GAAG,IAAI,CAI7D"}
@@ -0,0 +1,3 @@
1
+ import type { VisageConfig } from '../config';
2
+ export declare function writeDexConfig(config: VisageConfig): void;
3
+ //# sourceMappingURL=dex.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"dex.d.ts","sourceRoot":"","sources":["../../src/render/dex.ts"],"names":[],"mappings":"AAKA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,WAAW,CAAC;AAE9C,wBAAgB,cAAc,CAAC,MAAM,EAAE,YAAY,GAAG,IAAI,CAIzD"}
@@ -0,0 +1,3 @@
1
+ import type { VisageConfig } from '../config';
2
+ export declare function render(config: VisageConfig): void;
3
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/render/index.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,WAAW,CAAC;AAM9C,wBAAgB,MAAM,CAAC,MAAM,EAAE,YAAY,GAAG,IAAI,CAOjD"}
@@ -0,0 +1,3 @@
1
+ import type { VisageConfig } from '../config';
2
+ export declare function writeNginxConfig(config: VisageConfig): void;
3
+ //# sourceMappingURL=nginx.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"nginx.d.ts","sourceRoot":"","sources":["../../src/render/nginx.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,WAAW,CAAC;AAmD9C,wBAAgB,gBAAgB,CAAC,MAAM,EAAE,YAAY,GAAG,IAAI,CAI3D"}
@@ -0,0 +1,3 @@
1
+ import type { VisageConfig } from '../config';
2
+ export declare function writeOauth2ProxyConfig(config: VisageConfig): void;
3
+ //# sourceMappingURL=oauth2-proxy.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"oauth2-proxy.d.ts","sourceRoot":"","sources":["../../src/render/oauth2-proxy.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,WAAW,CAAC;AAE9C,wBAAgB,sBAAsB,CAAC,MAAM,EAAE,YAAY,GAAG,IAAI,CAQjE"}
@@ -0,0 +1,85 @@
1
+ export type VisageOptions = {
2
+ readonly host?: string;
3
+ readonly port?: number;
4
+ readonly cookie?: VisageCookiePolicy;
5
+ readonly idp?: VisageDexOptions | VisageIdpOptions;
6
+ readonly oauth2?: VisageOAuth2Client;
7
+ readonly services?: Record<string, VisageService>;
8
+ readonly upstreams?: Record<string, VisageUpstream>;
9
+ };
10
+ export type VisageCookiePolicy = {
11
+ readonly name?: string;
12
+ readonly expire?: string;
13
+ readonly refresh?: string;
14
+ readonly domains?: readonly string[];
15
+ readonly path?: string;
16
+ };
17
+ export type VisageDexOptions = {
18
+ readonly kind?: 'dex';
19
+ readonly expiry?: VisageDexExpiry;
20
+ readonly users?: readonly VisageDexUser[];
21
+ };
22
+ /**
23
+ * Dex token expiration and rotation settings.
24
+ *
25
+ * @see {@link https://dexidp.io/docs/configuration/tokens/#expiration-and-rotation-settings}
26
+ */
27
+ export type VisageDexExpiry = {
28
+ readonly idTokens?: string;
29
+ readonly authRequests?: string;
30
+ readonly deviceRequests?: string;
31
+ readonly signingKeys?: string;
32
+ readonly refreshTokens?: {
33
+ readonly validIfNotUsedFor?: string;
34
+ readonly absoluteLifetime?: string;
35
+ readonly disableRotation?: boolean;
36
+ readonly reuseInterval?: string;
37
+ };
38
+ };
39
+ export type VisageDexUser = {
40
+ readonly email: string;
41
+ readonly password: string;
42
+ readonly username?: string;
43
+ readonly userID?: string;
44
+ };
45
+ export type VisageIdpOptions = {
46
+ readonly kind: 'external';
47
+ readonly upstream: string;
48
+ readonly path?: string;
49
+ readonly issuer?: string;
50
+ readonly authorizationEndpoint?: string;
51
+ readonly tokenEndpoint?: string;
52
+ readonly jwksEndpoint?: string;
53
+ };
54
+ export type VisageOAuth2Client = {
55
+ readonly clientId?: string;
56
+ /**
57
+ * Set to `null` to render a public Dex client and enable OAuth2 Proxy PKCE.
58
+ */
59
+ readonly clientSecret?: string | null;
60
+ readonly scopes?: readonly string[];
61
+ };
62
+ export type VisageService = {
63
+ readonly image: string;
64
+ readonly command?: readonly string[];
65
+ readonly depends_on?: readonly string[];
66
+ readonly extra_hosts?: readonly string[];
67
+ };
68
+ export type VisageUpstream = {
69
+ readonly host: string;
70
+ readonly port: number;
71
+ readonly locations?: {
72
+ readonly [path: string]: VisageProxyPolicy;
73
+ };
74
+ };
75
+ export type VisageProxyPolicy = {
76
+ readonly auth?: {
77
+ readonly enabled?: boolean;
78
+ readonly redirect?: boolean;
79
+ readonly forward?: boolean;
80
+ };
81
+ readonly headers?: {
82
+ readonly [key: string]: string;
83
+ };
84
+ };
85
+ //# sourceMappingURL=types.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAAA,MAAM,MAAM,aAAa,GAAG;IAC1B,QAAQ,CAAC,IAAI,CAAC,EAAE,MAAM,CAAC;IACvB,QAAQ,CAAC,IAAI,CAAC,EAAE,MAAM,CAAC;IACvB,QAAQ,CAAC,MAAM,CAAC,EAAE,kBAAkB,CAAC;IACrC,QAAQ,CAAC,GAAG,CAAC,EAAE,gBAAgB,GA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ACtB,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;IACtB,QAAQ,CAAC,SAAS,CAAC,EAAE;QAAE,QAAQ,EAAE,IAAI,EAAE,MAAM,GAAG,iBAAiB,CAAA;KAAE,CAAC;CACrE,CAAC;AAEF,MAAM,MAAM,iBAAiB,GAAG;IAC9B,QAAQ,CAAC,IAAI,CAAC,EAAE;QACd,QAAQ,CAAC,OAAO,CAAC,EAAE,OAAO,CAAC;QAC3B,QAAQ,CAAC,QAAQ,CAAC,EAAE,OAAO,CAAC;QAC5B,QAAQ,CAAC,OAAO,CAAC,EAAE,OAAO,CAAC;KAC5B,CAAC;IACF,QAAQ,CAAC,OAAO,CAAC,EAAE;QAAE,QAAQ,EAAE,GAAG,EAAE,MAAM,GAAG,MAAM,CAAA;KAAE,CAAC;CACvD,CAAC"}
package/package.json ADDED
@@ -0,0 +1,65 @@
1
+ {
2
+ "name": "@blakearoberts/visage",
3
+ "version": "0.0.1-rc.0",
4
+ "description": "Vite plugin for local development with HMR and OIDC session cookie lifecycle semantics.",
5
+ "type": "module",
6
+ "author": "Blake Roberts",
7
+ "license": "MIT",
8
+ "repository": {
9
+ "type": "git",
10
+ "url": "https://github.com/blakearoberts/visage.git"
11
+ },
12
+ "bugs": {
13
+ "url": "https://github.com/blakearoberts/visage/issues"
14
+ },
15
+ "homepage": "https://github.com/blakearoberts/visage#readme",
16
+ "keywords": [
17
+ "vite",
18
+ "plugin",
19
+ "oidc",
20
+ "hmr",
21
+ "session",
22
+ "cookie",
23
+ "lifecycle",
24
+ "development"
25
+ ],
26
+ "main": "dist/index.js",
27
+ "types": "dist/index.d.ts",
28
+ "exports": {
29
+ ".": {
30
+ "types": "./dist/index.d.ts",
31
+ "default": "./dist/index.js"
32
+ }
33
+ },
34
+ "files": [
35
+ "dist"
36
+ ],
37
+ "engines": {
38
+ "node": ">=20"
39
+ },
40
+ "publishConfig": {
41
+ "access": "public",
42
+ "registry": "https://registry.npmjs.org"
43
+ },
44
+ "scripts": {
45
+ "build": "npm run clean && rollup -c",
46
+ "clean": "node -e \"require('node:fs').rmSync('dist', { recursive: true, force: true })\"",
47
+ "test": "npm run test:unit",
48
+ "test:e2e": "playwright test test/e2e",
49
+ "test:unit": "node --experimental-strip-types --test test/unit/*.test.ts"
50
+ },
51
+ "devDependencies": {
52
+ "@playwright/test": "^1.59.1",
53
+ "@rollup/plugin-typescript": "^12.3.0",
54
+ "@types/node": "^25.6.2",
55
+ "rollup": "^4.60.3",
56
+ "tslib": "^2.8.1",
57
+ "typescript": "^5.9.3",
58
+ "vite": "^6.3.5"
59
+ },
60
+ "dependencies": {
61
+ "bcryptjs": "^3.0.3",
62
+ "eta": "^4.6.0",
63
+ "yaml": "^2.8.4"
64
+ }
65
+ }