@zitadel/testing 0.5.0 → 0.7.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/README.md +92 -22
- package/dist/app-runner.cjs +3 -4
- package/dist/app-runner.mjs +3 -4
- package/dist/{handshake-D6MXSUcd.cjs → handshake-BEhxJx4Z.cjs} +21 -5
- package/dist/handshake-BEhxJx4Z.cjs.map +1 -0
- package/dist/{handshake-CwlxMjW0.mjs → handshake-CZWS5b2X.mjs} +17 -7
- package/dist/handshake-CZWS5b2X.mjs.map +1 -0
- package/dist/index-B9tztG3_.d.mts +73 -0
- package/dist/index.cjs +3 -2
- package/dist/index.d.mts +3 -81
- package/dist/index.mjs +3 -3
- package/dist/{orchestration-Clldecyr.mjs → orchestration-Cf4M8lil.mjs} +2 -3
- package/dist/{orchestration-Clldecyr.mjs.map → orchestration-Cf4M8lil.mjs.map} +1 -1
- package/dist/{orchestration-gIDANMcF.cjs → orchestration-SELq6dmD.cjs} +2 -3
- package/dist/{orchestration-gIDANMcF.cjs.map → orchestration-SELq6dmD.cjs.map} +1 -1
- package/dist/playwright.cjs +10 -13
- package/dist/playwright.cjs.map +1 -1
- package/dist/playwright.d.mts +3 -13
- package/dist/playwright.mjs +11 -15
- package/dist/playwright.mjs.map +1 -1
- package/dist/{session-B84nOEiv.d.mts → session-DueRCvrq.d.mts} +9 -10
- package/dist/{src-Ck7eLkah.mjs → src-DImgqUUu.mjs} +74 -27
- package/dist/src-DImgqUUu.mjs.map +1 -0
- package/dist/{src-DXVDJLrV.cjs → src-EogQCM5q.cjs} +4713 -2307
- package/dist/src-EogQCM5q.cjs.map +1 -0
- package/dist/supervisor.cjs +4 -5
- package/dist/supervisor.mjs +4 -5
- package/dist/vitest.d.mts +33 -0
- package/dist/vitest.mjs +65 -0
- package/dist/vitest.mjs.map +1 -0
- package/package.json +19 -11
- package/dist/handshake-CwlxMjW0.mjs.map +0 -1
- package/dist/handshake-D6MXSUcd.cjs.map +0 -1
- package/dist/src-Ck7eLkah.mjs.map +0 -1
- package/dist/src-DXVDJLrV.cjs.map +0 -1
package/README.md
CHANGED
|
@@ -29,10 +29,12 @@ The kit drives the `zitadel` CLI, which resolves the published
|
|
|
29
29
|
|
|
30
30
|
One instance per suite, seeded per test. `withZitadel()` generates the
|
|
31
31
|
`webServer` entries that boot the instance and run your app against it — no
|
|
32
|
-
wrapper scripts
|
|
32
|
+
wrapper scripts. Name the config `.mts`: it uses `import.meta.dirname`, which
|
|
33
|
+
a `.ts` config does not load in a package without `"type": "module"` (what
|
|
34
|
+
`zitadel setup` scaffolds for Next.js):
|
|
33
35
|
|
|
34
36
|
```ts
|
|
35
|
-
// playwright.config.
|
|
37
|
+
// playwright.config.mts
|
|
36
38
|
import { defineConfig } from "@playwright/test";
|
|
37
39
|
import { nextAppEnv, withZitadel } from "@zitadel/testing/playwright";
|
|
38
40
|
|
|
@@ -66,7 +68,9 @@ test("user signs in with password", async ({ page, seed }) => {
|
|
|
66
68
|
|
|
67
69
|
`app.env` is an `AppEnvTemplate`: a serializable mapping from your app's env
|
|
68
70
|
var names to `InstanceHandle` fields. `nextAppEnv` covers `@zitadel/sdk-next`
|
|
69
|
-
apps
|
|
71
|
+
apps, and `viteAppEnv` the React, Vue, Solid, Svelte and Qwik apps `zitadel setup`
|
|
72
|
+
wires through a Vite dev proxy; the console maps the same fields to
|
|
73
|
+
`VITE_*`/`CONSOLE_*` names instead.
|
|
70
74
|
The fixtures find the instance through `ZITADEL_TESTING_HANDSHAKE`, which
|
|
71
75
|
`withZitadel()` points at its handshake file.
|
|
72
76
|
|
|
@@ -123,7 +127,9 @@ another factor — fails with the step name; log in through the UI for those.
|
|
|
123
127
|
`seed.identity()` complements registration specs: an unused email+password
|
|
124
128
|
that creates nothing, so the flow under test must create the user. It needs
|
|
125
129
|
no instance, so a spec without `withZitadel()` — against an app you started
|
|
126
|
-
yourself — imports it as `identity()`.
|
|
130
|
+
yourself — imports it as `identity()`. For backend suites that need no browser
|
|
131
|
+
at all, the [Vitest entry](#quick-start-vitest-backend-tests) wires up the
|
|
132
|
+
instance lifecycle instead.
|
|
127
133
|
|
|
128
134
|
### Drive the login flow
|
|
129
135
|
|
|
@@ -186,7 +192,8 @@ login flows.
|
|
|
186
192
|
|
|
187
193
|
The two in-repo consumers are `e2e/demo-next/playwright.real.config.mts`
|
|
188
194
|
and `e2e/console/playwright.real.config.mts` — run them with
|
|
189
|
-
`
|
|
195
|
+
`turbo run demo-next-real --filter=@zitadel/e2e` /
|
|
196
|
+
`turbo run console-real --filter=@zitadel/e2e`.
|
|
190
197
|
|
|
191
198
|
### Composable pieces
|
|
192
199
|
|
|
@@ -194,10 +201,72 @@ and `e2e/console/playwright.real.config.mts` — run them with
|
|
|
194
201
|
that calls `startLocalZitadel()` + `writeHandshake()`, and an app-runner entry
|
|
195
202
|
that `waitForHandshake()`s and spawns the dev server with
|
|
196
203
|
`applyAppEnvTemplate(...)` applied. Suites with unusual topologies (or
|
|
197
|
-
|
|
204
|
+
runners other than Playwright and Vitest) compose those functions directly —
|
|
198
205
|
`apps/console/scripts/dev-real.mts` does, seeding a dev environment rather
|
|
199
206
|
than a test suite.
|
|
200
207
|
|
|
208
|
+
## Quick start (Vitest, backend tests)
|
|
209
|
+
|
|
210
|
+
For tests that call your own API with a real session and no browser:
|
|
211
|
+
|
|
212
|
+
```sh
|
|
213
|
+
npm i -D @zitadel/testing@latest vitest
|
|
214
|
+
```
|
|
215
|
+
|
|
216
|
+
A global setup boots an instance before the tests and stops it when the run
|
|
217
|
+
ends, or when it is interrupted with SIGINT or SIGTERM. It takes the same
|
|
218
|
+
options as `startLocalZitadel()`:
|
|
219
|
+
|
|
220
|
+
```ts
|
|
221
|
+
// zitadel.global-setup.ts
|
|
222
|
+
import { zitadelGlobalSetup } from "@zitadel/testing/vitest";
|
|
223
|
+
|
|
224
|
+
export default zitadelGlobalSetup({
|
|
225
|
+
appOrigins: ["http://localhost:3000"], // the origin your API sees on flow calls
|
|
226
|
+
});
|
|
227
|
+
```
|
|
228
|
+
|
|
229
|
+
```ts
|
|
230
|
+
// vitest.config.ts
|
|
231
|
+
import { defineConfig } from "vitest/config";
|
|
232
|
+
|
|
233
|
+
export default defineConfig({
|
|
234
|
+
test: {
|
|
235
|
+
globalSetup: ["./zitadel.global-setup.ts"],
|
|
236
|
+
},
|
|
237
|
+
});
|
|
238
|
+
```
|
|
239
|
+
|
|
240
|
+
Vitest runs a global setup once per project that lists it: with `projects`
|
|
241
|
+
and `extends: true`, a root `globalSetup` boots one instance for the root and
|
|
242
|
+
one for every project. List it on the one project whose tests need it.
|
|
243
|
+
|
|
244
|
+
`injectZitadel()` connects a test to that instance, with the same surface
|
|
245
|
+
`connectZitadel()` returns:
|
|
246
|
+
|
|
247
|
+
```ts
|
|
248
|
+
// me.test.ts
|
|
249
|
+
import { expect, it } from "vitest";
|
|
250
|
+
import { injectZitadel, sessionCookieName } from "@zitadel/testing/vitest";
|
|
251
|
+
|
|
252
|
+
const appUrl = "http://localhost:3000"; // your API, configured for this instance
|
|
253
|
+
|
|
254
|
+
it("returns the signed-in user", async () => {
|
|
255
|
+
const zitadel = injectZitadel();
|
|
256
|
+
const { user, sessionToken } = await zitadel.seedSession(); // fresh user, real login flow
|
|
257
|
+
// The cookie a server SDK reads on the app's own origin (see "Start tests
|
|
258
|
+
// authenticated" for the names).
|
|
259
|
+
const cookie = `${sessionCookieName(zitadel.handle.projectId, appUrl)}=${sessionToken}`;
|
|
260
|
+
const response = await fetch(`${appUrl}/api/me`, { headers: { cookie } });
|
|
261
|
+
expect(await response.json()).toMatchObject({ id: user.id });
|
|
262
|
+
});
|
|
263
|
+
```
|
|
264
|
+
|
|
265
|
+
The global setup hands the serializable `handle` to the test workers through
|
|
266
|
+
Vitest's own `provide`/`inject`. Your API has to talk to the same instance:
|
|
267
|
+
start it inside the test files (in a `beforeAll`, say), configured from
|
|
268
|
+
`zitadel.handle` or `zitadel.appEnv`. The entry is ESM only, as Vitest is.
|
|
269
|
+
|
|
201
270
|
## API
|
|
202
271
|
|
|
203
272
|
```ts
|
|
@@ -242,10 +311,10 @@ per test, `zitadel` per worker, `passkey` on demand), the flow ceremonies
|
|
|
242
311
|
(`flowAction`/`flowField`, `clickFlowAction`/`fillFlowField`), plus
|
|
243
312
|
`withZitadel(options)` returning `{ webServer }` for the config,
|
|
244
313
|
`enableVirtualPasskey(page)` for non-fixture pages, and
|
|
245
|
-
`nextAppEnv`/`applyAppEnvTemplate` for the env-template mechanism described
|
|
314
|
+
`nextAppEnv`/`viteAppEnv`/`applyAppEnvTemplate` for the env-template mechanism described
|
|
246
315
|
above. `identity()`, `SESSION_COOKIE_NAME`, `browserSessionCookieName` and
|
|
247
|
-
`sessionCookieName` are on
|
|
248
|
-
everything from
|
|
316
|
+
`sessionCookieName` are on every entry point, so a Playwright or Vitest spec
|
|
317
|
+
imports everything from its own one. Without a URL, the two functions name the cookies of
|
|
249
318
|
a loopback http dev server.
|
|
250
319
|
|
|
251
320
|
## How it works
|
|
@@ -295,7 +364,7 @@ provisioning contract the boot path drives — never a server flag, and never
|
|
|
295
364
|
direct database writes, which would bypass the provisioner and break seed
|
|
296
365
|
ops for `connectZitadel` targets.
|
|
297
366
|
|
|
298
|
-
The in-repo dev loop follows the same contract: `
|
|
367
|
+
The in-repo dev loop follows the same contract: `turbo run dev:real --filter=@zitadel/console`
|
|
299
368
|
boots, seeds, and uses `handle.projectSecret` itself to grant the dev user
|
|
300
369
|
access, then signs the console in with that user's session cookie — the
|
|
301
370
|
secret never reaches the dev proxy or the browser (#1300). `--seed-only`
|
|
@@ -307,7 +376,9 @@ or export.
|
|
|
307
376
|
**One instance per suite, one fresh user per test.** Emails are unique per
|
|
308
377
|
project, so per-test `seed.user()` calls are isolation enough for login-flow
|
|
309
378
|
tests, and tests run fully parallel against the shared instance
|
|
310
|
-
(demonstrated by `
|
|
379
|
+
(demonstrated by the `demo-next-real` lane, 2 workers). The Vitest entry
|
|
380
|
+
follows the same model: one instance per project that lists its global setup,
|
|
381
|
+
shared by that project's test files.
|
|
311
382
|
|
|
312
383
|
Typical timings with the SQLite local default (dated estimates from a July 2026 dev build — orders of magnitude, not a benchmark; remeasure locally before relying on them):
|
|
313
384
|
|
|
@@ -318,7 +389,7 @@ Typical timings with the SQLite local default (dated estimates from a July 2026
|
|
|
318
389
|
| Stop | typically under a second |
|
|
319
390
|
| Bootstrap (project + schema + flow) | ~100ms |
|
|
320
391
|
| Seed one user (create + password) | ~50ms |
|
|
321
|
-
| Full `
|
|
392
|
+
| Full `demo-next-real` suite (boot + Next dev + 2 browser tests) | ~25s |
|
|
322
393
|
|
|
323
394
|
**Instance-per-worker is not worth it for browser e2e**: the app dev server
|
|
324
395
|
boots once with one project's env, and every extra worker would pay the full
|
|
@@ -337,11 +408,11 @@ mutate project-wide state; revisit with warm-dir reuse if that need appears.
|
|
|
337
408
|
|
|
338
409
|
Customer installs get the published server binary through `@zitadel/server`'s
|
|
339
410
|
platform packages; the in-repo workspace carries no such binary, so the repo's
|
|
340
|
-
own suites run `
|
|
411
|
+
own suites run `turbo run build --filter=@zitadel/server` and point the kit at the result via
|
|
341
412
|
`ZITADEL_SERVER_BINARY` (the `withZitadel` option `zitadel.serverBinary` /
|
|
342
|
-
`serverBinaryHint` exists for this). Most in-repo
|
|
413
|
+
`serverBinaryHint` exists for this). Most in-repo e2e lanes set
|
|
343
414
|
`NEXTGEN_SERVER_CONSOLE_ENABLED=false` because they drive the app-embedded
|
|
344
|
-
login, not the server-hosted console; the exception is `
|
|
415
|
+
login, not the server-hosted console; the exception is `console-embedded`,
|
|
345
416
|
which keeps the console on and omits `app` — the binary-served console is its
|
|
346
417
|
subject. Customer installs need none of this.
|
|
347
418
|
|
|
@@ -368,12 +439,11 @@ on top, in intended order:
|
|
|
368
439
|
2. **Email/OTP capture.** `zitadel.email.waitForCode(address)` for
|
|
369
440
|
verification flows. Blocked on a server-side story (dev SMTP sink or
|
|
370
441
|
API-exposed codes); password-only flows don't hit this.
|
|
371
|
-
3. **Vitest surface.** Landed
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
directly.
|
|
442
|
+
3. **Vitest surface.** Landed: `withZitadel(config)` orchestration,
|
|
443
|
+
`AppEnvTemplate`/`nextAppEnv`, the session-mint seed-op (`seed.session()`
|
|
444
|
+
driving the real flow headlessly, `authenticatedPage` on top), and the
|
|
445
|
+
`@zitadel/testing/vitest` entry (`zitadelGlobalSetup()` + `injectZitadel()`)
|
|
446
|
+
for backend tests.
|
|
377
447
|
4. **Remote mode: ephemeral project on a persistent instance.** For app
|
|
378
448
|
deployments that cannot reach a local process (preview environments).
|
|
379
449
|
`bootstrapProject({ baseUrl })` + `connectZitadel(handle)` already compose
|
|
@@ -394,5 +464,5 @@ on top, in intended order:
|
|
|
394
464
|
Parked until server support exists: passkey *seeding* (pre-registered WebAuthn
|
|
395
465
|
credentials) — UI-driven passkey ceremonies are covered today by
|
|
396
466
|
`enableVirtualPasskey`. Independent refactor: extract
|
|
397
|
-
`apps/cli/src/lib/local
|
|
467
|
+
`apps/cli/src/lib/server/local` into a shared package and swap the lifecycle
|
|
398
468
|
shell-out for imports.
|
package/dist/app-runner.cjs
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
const require_handshake = require("./handshake-
|
|
2
|
-
const require_orchestration = require("./orchestration-
|
|
1
|
+
const require_handshake = require("./handshake-BEhxJx4Z.cjs");
|
|
2
|
+
const require_orchestration = require("./orchestration-SELq6dmD.cjs");
|
|
3
3
|
let node_child_process = require("node:child_process");
|
|
4
|
-
|
|
4
|
+
// src/app-runner.ts
|
|
5
5
|
/**
|
|
6
6
|
* Playwright webServer entry generated by `withZitadel()`: waits for the
|
|
7
7
|
* supervisor's handshake, then runs the app's dev server with the instance
|
|
@@ -32,6 +32,5 @@ main().catch((error) => {
|
|
|
32
32
|
console.error(`${LOG} ${error instanceof Error ? error.message : String(error)}`);
|
|
33
33
|
process.exit(1);
|
|
34
34
|
});
|
|
35
|
-
//#endregion
|
|
36
35
|
|
|
37
36
|
//# sourceMappingURL=app-runner.cjs.map
|
package/dist/app-runner.mjs
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import { i as applyAppEnvTemplate, n as waitForHandshake } from "./handshake-
|
|
2
|
-
import { i as parseAppRunnerConfig, o as requireHandshakePath, t as APP_RUNNER_CONFIG_ENV } from "./orchestration-
|
|
1
|
+
import { i as applyAppEnvTemplate, n as waitForHandshake } from "./handshake-CZWS5b2X.mjs";
|
|
2
|
+
import { i as parseAppRunnerConfig, o as requireHandshakePath, t as APP_RUNNER_CONFIG_ENV } from "./orchestration-Cf4M8lil.mjs";
|
|
3
3
|
import { spawn } from "node:child_process";
|
|
4
|
-
|
|
4
|
+
// src/app-runner.ts
|
|
5
5
|
/**
|
|
6
6
|
* Playwright webServer entry generated by `withZitadel()`: waits for the
|
|
7
7
|
* supervisor's handshake, then runs the app's dev server with the instance
|
|
@@ -32,7 +32,6 @@ main().catch((error) => {
|
|
|
32
32
|
console.error(`${LOG} ${error instanceof Error ? error.message : String(error)}`);
|
|
33
33
|
process.exit(1);
|
|
34
34
|
});
|
|
35
|
-
//#endregion
|
|
36
35
|
export {};
|
|
37
36
|
|
|
38
37
|
//# sourceMappingURL=app-runner.mjs.map
|
|
@@ -2,7 +2,7 @@ let node_fs = require("node:fs");
|
|
|
2
2
|
let node_fs_promises = require("node:fs/promises");
|
|
3
3
|
let node_path = require("node:path");
|
|
4
4
|
let node_timers_promises = require("node:timers/promises");
|
|
5
|
-
|
|
5
|
+
// src/app-env.ts
|
|
6
6
|
/**
|
|
7
7
|
* The env shape `@zitadel/sdk-next` apps read, as `zitadel setup` writes it.
|
|
8
8
|
* The server reads `ZITADEL_PROJECT_ID` to hold sessions to the project, the
|
|
@@ -16,6 +16,18 @@ const nextAppEnv = {
|
|
|
16
16
|
NEXT_PUBLIC_ZITADEL_PROJECT_ID: "projectId",
|
|
17
17
|
ZITADEL_PROJECT_SECRET: "projectSecret"
|
|
18
18
|
};
|
|
19
|
+
/**
|
|
20
|
+
* The env shape a Vite app reads — React, Vue, Solid, Svelte and Qwik — as
|
|
21
|
+
* `zitadel setup` writes it: its dev proxy reaches the server at `ZITADEL_URL`
|
|
22
|
+
* with the secret and names the session cookie after `ZITADEL_PROJECT_ID`,
|
|
23
|
+
* and the widgets read the public copy Vite exposes to the browser.
|
|
24
|
+
*/
|
|
25
|
+
const viteAppEnv = {
|
|
26
|
+
ZITADEL_URL: "baseUrl",
|
|
27
|
+
ZITADEL_PROJECT_ID: "projectId",
|
|
28
|
+
VITE_ZITADEL_PROJECT_ID: "projectId",
|
|
29
|
+
ZITADEL_PROJECT_SECRET: "projectSecret"
|
|
30
|
+
};
|
|
19
31
|
function applyAppEnvTemplate(template, handle) {
|
|
20
32
|
const env = {};
|
|
21
33
|
for (const [name, field] of Object.entries(template)) {
|
|
@@ -25,8 +37,7 @@ function applyAppEnvTemplate(template, handle) {
|
|
|
25
37
|
}
|
|
26
38
|
return env;
|
|
27
39
|
}
|
|
28
|
-
|
|
29
|
-
//#region src/handshake.ts
|
|
40
|
+
// src/handshake.ts
|
|
30
41
|
/**
|
|
31
42
|
* The handshake file carries an InstanceHandle across process boundaries:
|
|
32
43
|
* written by the script that boots + bootstraps the instance, read by
|
|
@@ -80,7 +91,6 @@ function validatePlatform(value, source) {
|
|
|
80
91
|
const platform = value;
|
|
81
92
|
for (const field of ["projectId", "publishableKey"]) if (typeof platform[field] !== "string" || platform[field].length === 0) fail(`"${field}" is required`);
|
|
82
93
|
}
|
|
83
|
-
//#endregion
|
|
84
94
|
Object.defineProperty(exports, "applyAppEnvTemplate", {
|
|
85
95
|
enumerable: true,
|
|
86
96
|
get: function() {
|
|
@@ -99,6 +109,12 @@ Object.defineProperty(exports, "readHandshakeSync", {
|
|
|
99
109
|
return readHandshakeSync;
|
|
100
110
|
}
|
|
101
111
|
});
|
|
112
|
+
Object.defineProperty(exports, "viteAppEnv", {
|
|
113
|
+
enumerable: true,
|
|
114
|
+
get: function() {
|
|
115
|
+
return viteAppEnv;
|
|
116
|
+
}
|
|
117
|
+
});
|
|
102
118
|
Object.defineProperty(exports, "waitForHandshake", {
|
|
103
119
|
enumerable: true,
|
|
104
120
|
get: function() {
|
|
@@ -112,4 +128,4 @@ Object.defineProperty(exports, "writeHandshake", {
|
|
|
112
128
|
}
|
|
113
129
|
});
|
|
114
130
|
|
|
115
|
-
//# sourceMappingURL=handshake-
|
|
131
|
+
//# sourceMappingURL=handshake-BEhxJx4Z.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"handshake-BEhxJx4Z.cjs","names":["mkdir","dirname","writeFile","readFileSync","readFile","sleep"],"sources":["../src/app-env.ts","../src/handshake.ts"],"sourcesContent":["import type { InstanceHandle } from \"./types\";\n\n/**\n * Handle fields a template may reference: the flat string facts. Structured\n * fields (e.g. `platform`) are not env-var material — consumers read those\n * from the handle directly.\n */\ntype StringHandleField = {\n [K in keyof InstanceHandle]-?: InstanceHandle[K] extends string | undefined ? K : never;\n}[keyof InstanceHandle];\n\n/**\n * Declarative mapping from an app's env var names to InstanceHandle fields.\n * A template (not a function) so it can cross process boundaries: the\n * Playwright config serializes it into the app-runner's environment, where it\n * is applied to the handle read from the handshake file.\n */\nexport type AppEnvTemplate = Record<string, StringHandleField>;\n\n/**\n * The env shape `@zitadel/sdk-next` apps read, as `zitadel setup` writes it.\n * The server reads `ZITADEL_PROJECT_ID` to hold sessions to the project, the\n * widgets the public copy. Other frameworks pass their own template — the\n * console maps the same handle fields to `VITE_*`/`CONSOLE_*` names, for\n * example.\n */\nexport const nextAppEnv: AppEnvTemplate = {\n ZITADEL_URL: \"baseUrl\",\n ZITADEL_PROJECT_ID: \"projectId\",\n NEXT_PUBLIC_ZITADEL_PROJECT_ID: \"projectId\",\n ZITADEL_PROJECT_SECRET: \"projectSecret\",\n};\n\n/**\n * The env shape a Vite app reads — React, Vue, Solid, Svelte and Qwik — as\n * `zitadel setup` writes it: its dev proxy reaches the server at `ZITADEL_URL`\n * with the secret and names the session cookie after `ZITADEL_PROJECT_ID`,\n * and the widgets read the public copy Vite exposes to the browser.\n */\nexport const viteAppEnv: AppEnvTemplate = {\n ZITADEL_URL: \"baseUrl\",\n ZITADEL_PROJECT_ID: \"projectId\",\n VITE_ZITADEL_PROJECT_ID: \"projectId\",\n ZITADEL_PROJECT_SECRET: \"projectSecret\",\n};\n\nexport function applyAppEnvTemplate(\n template: AppEnvTemplate,\n handle: InstanceHandle,\n): Record<string, string> {\n const env: Record<string, string> = {};\n for (const [name, field] of Object.entries(template)) {\n const value = handle[field];\n if (typeof value !== \"string\" || value.length === 0) {\n // Fail instead of silently dropping the var: an app booted without one\n // of its env vars produces a much harder-to-read failure downstream.\n throw new Error(\n `app env template maps \"${name}\" to handle field \"${field}\", which the instance handle does not carry`,\n );\n }\n env[name] = value;\n }\n return env;\n}\n","import { readFileSync } from \"node:fs\";\nimport { mkdir, readFile, writeFile } from \"node:fs/promises\";\nimport { dirname } from \"node:path\";\nimport { setTimeout as sleep } from \"node:timers/promises\";\n\nimport type { InstanceHandle, PlatformCredentials } from \"./types\";\n\n/**\n * The handshake file carries an InstanceHandle across process boundaries:\n * written by the script that boots + bootstraps the instance, read by\n * Playwright workers (fixtures) and the app dev-server wrapper.\n */\nexport async function writeHandshake(path: string, handle: InstanceHandle): Promise<void> {\n await mkdir(dirname(path), { recursive: true });\n await writeFile(path, `${JSON.stringify(handle, null, 2)}\\n`, { mode: 0o600 });\n}\n\nexport function readHandshakeSync(path: string): InstanceHandle {\n const contents = readFileSync(path, \"utf8\");\n let value: unknown;\n try {\n value = JSON.parse(contents);\n } catch (error) {\n throw new Error(`handshake file ${path} contains invalid JSON: ${(error as Error).message}`, {\n cause: error,\n });\n }\n return validateHandle(value, path);\n}\n\nexport async function waitForHandshake(path: string, timeoutMs = 60_000): Promise<InstanceHandle> {\n const deadline = Date.now() + timeoutMs;\n for (;;) {\n try {\n return validateHandle(JSON.parse(await readFile(path, \"utf8\")), path);\n } catch (error) {\n if (Date.now() >= deadline) {\n throw new Error(\n `handshake file not readable within ${timeoutMs}ms: ${path} (${(error as Error).message})`,\n { cause: error },\n );\n }\n await sleep(250);\n }\n }\n}\n\nfunction validateHandle(value: unknown, source: string): InstanceHandle {\n if (typeof value !== \"object\" || value === null || Array.isArray(value)) {\n throw new Error(`handshake file ${source} is not an object`);\n }\n const handle = value as Partial<InstanceHandle>;\n for (const field of [\"baseUrl\", \"projectId\", \"projectSecret\", \"schemaId\"] as const) {\n if (typeof handle[field] !== \"string\" || handle[field].length === 0) {\n throw new Error(`handshake file ${source} is missing \"${field}\"`);\n }\n }\n if (!URL.canParse(handle.baseUrl as string)) {\n throw new Error(`handshake file ${source} has a malformed \"baseUrl\": ${handle.baseUrl}`);\n }\n if (handle.platform !== undefined) {\n validatePlatform(handle.platform, source);\n }\n return handle as InstanceHandle;\n}\n\n/**\n * The handshake is the cross-process contract, so a malformed platform block\n * must fail here with the field name, not later with a less actionable error.\n */\nfunction validatePlatform(value: unknown, source: string): void {\n const fail = (detail: string): never => {\n throw new Error(`handshake file ${source} has a malformed \"platform\" block: ${detail}`);\n };\n if (typeof value !== \"object\" || value === null || Array.isArray(value)) {\n fail(\"not an object\");\n }\n const platform = value as Partial<PlatformCredentials>;\n for (const field of [\"projectId\", \"publishableKey\"] as const) {\n if (typeof platform[field] !== \"string\" || platform[field].length === 0) {\n fail(`\"${field}\" is required`);\n }\n }\n // Unknown extra fields pass through on purpose: future platform\n // credentials join additively, and an older reader must not reject a\n // newer producer's handle.\n}\n"],"mappings":";;;;;;;;;;;;AA0BA,MAAa,aAA6B;CACxC,aAAa;CACb,oBAAoB;CACpB,gCAAgC;CAChC,wBAAwB;AAC1B;;;;;;;AAQA,MAAa,aAA6B;CACxC,aAAa;CACb,oBAAoB;CACpB,yBAAyB;CACzB,wBAAwB;AAC1B;AAEA,SAAgB,oBACd,UACA,QACwB;CACxB,MAAM,MAA8B,CAAC;CACrC,KAAK,MAAM,CAAC,MAAM,UAAU,OAAO,QAAQ,QAAQ,GAAG;EACpD,MAAM,QAAQ,OAAO;EACrB,IAAI,OAAO,UAAU,YAAY,MAAM,WAAW,GAGhD,MAAM,IAAI,MACR,0BAA0B,KAAK,qBAAqB,MAAM,4CAC5D;EAEF,IAAI,QAAQ;CACd;CACA,OAAO;AACT;;;;;;;ACnDA,eAAsB,eAAe,MAAc,QAAuC;CACxF,OAAA,GAAMA,iBAAAA,MAAAA,EAAAA,GAAMC,UAAAA,QAAAA,CAAQ,IAAI,GAAG,EAAE,WAAW,KAAK,CAAC;CAC9C,OAAA,GAAMC,iBAAAA,UAAAA,CAAU,MAAM,GAAG,KAAK,UAAU,QAAQ,MAAM,CAAC,EAAE,KAAK,EAAE,MAAM,IAAM,CAAC;AAC/E;AAEA,SAAgB,kBAAkB,MAA8B;CAC9D,MAAM,YAAA,GAAWC,QAAAA,aAAAA,CAAa,MAAM,MAAM;CAC1C,IAAI;CACJ,IAAI;EACF,QAAQ,KAAK,MAAM,QAAQ;CAC7B,SAAS,OAAO;EACd,MAAM,IAAI,MAAM,kBAAkB,KAAK,0BAA2B,MAAgB,WAAW,EAC3F,OAAO,MACT,CAAC;CACH;CACA,OAAO,eAAe,OAAO,IAAI;AACnC;AAEA,eAAsB,iBAAiB,MAAc,YAAY,KAAiC;CAChG,MAAM,WAAW,KAAK,IAAI,IAAI;CAC9B,SACE,IAAI;EACF,OAAO,eAAe,KAAK,MAAM,OAAA,GAAMC,iBAAAA,SAAAA,CAAS,MAAM,MAAM,CAAC,GAAG,IAAI;CACtE,SAAS,OAAO;EACd,IAAI,KAAK,IAAI,KAAK,UAChB,MAAM,IAAI,MACR,sCAAsC,UAAU,MAAM,KAAK,IAAK,MAAgB,QAAQ,IACxF,EAAE,OAAO,MAAM,CACjB;EAEF,OAAA,GAAMC,qBAAAA,WAAAA,CAAM,GAAG;CACjB;AAEJ;AAEA,SAAS,eAAe,OAAgB,QAAgC;CACtE,IAAI,OAAO,UAAU,YAAY,UAAU,QAAQ,MAAM,QAAQ,KAAK,GACpE,MAAM,IAAI,MAAM,kBAAkB,OAAO,kBAAkB;CAE7D,MAAM,SAAS;CACf,KAAK,MAAM,SAAS;EAAC;EAAW;EAAa;EAAiB;CAAU,GACtE,IAAI,OAAO,OAAO,WAAW,YAAY,OAAO,MAAM,CAAC,WAAW,GAChE,MAAM,IAAI,MAAM,kBAAkB,OAAO,eAAe,MAAM,EAAE;CAGpE,IAAI,CAAC,IAAI,SAAS,OAAO,OAAiB,GACxC,MAAM,IAAI,MAAM,kBAAkB,OAAO,8BAA8B,OAAO,SAAS;CAEzF,IAAI,OAAO,aAAa,KAAA,GACtB,iBAAiB,OAAO,UAAU,MAAM;CAE1C,OAAO;AACT;;;;;AAMA,SAAS,iBAAiB,OAAgB,QAAsB;CAC9D,MAAM,QAAQ,WAA0B;EACtC,MAAM,IAAI,MAAM,kBAAkB,OAAO,qCAAqC,QAAQ;CACxF;CACA,IAAI,OAAO,UAAU,YAAY,UAAU,QAAQ,MAAM,QAAQ,KAAK,GACpE,KAAK,eAAe;CAEtB,MAAM,WAAW;CACjB,KAAK,MAAM,SAAS,CAAC,aAAa,gBAAgB,GAChD,IAAI,OAAO,SAAS,WAAW,YAAY,SAAS,MAAM,CAAC,WAAW,GACpE,KAAK,IAAI,MAAM,cAAc;AAMnC"}
|
|
@@ -1,8 +1,8 @@
|
|
|
1
|
+
import { readFileSync } from "node:fs";
|
|
1
2
|
import { mkdir, readFile, writeFile } from "node:fs/promises";
|
|
2
3
|
import { dirname } from "node:path";
|
|
3
|
-
import { readFileSync } from "node:fs";
|
|
4
4
|
import { setTimeout } from "node:timers/promises";
|
|
5
|
-
|
|
5
|
+
// src/app-env.ts
|
|
6
6
|
/**
|
|
7
7
|
* The env shape `@zitadel/sdk-next` apps read, as `zitadel setup` writes it.
|
|
8
8
|
* The server reads `ZITADEL_PROJECT_ID` to hold sessions to the project, the
|
|
@@ -16,6 +16,18 @@ const nextAppEnv = {
|
|
|
16
16
|
NEXT_PUBLIC_ZITADEL_PROJECT_ID: "projectId",
|
|
17
17
|
ZITADEL_PROJECT_SECRET: "projectSecret"
|
|
18
18
|
};
|
|
19
|
+
/**
|
|
20
|
+
* The env shape a Vite app reads — React, Vue, Solid, Svelte and Qwik — as
|
|
21
|
+
* `zitadel setup` writes it: its dev proxy reaches the server at `ZITADEL_URL`
|
|
22
|
+
* with the secret and names the session cookie after `ZITADEL_PROJECT_ID`,
|
|
23
|
+
* and the widgets read the public copy Vite exposes to the browser.
|
|
24
|
+
*/
|
|
25
|
+
const viteAppEnv = {
|
|
26
|
+
ZITADEL_URL: "baseUrl",
|
|
27
|
+
ZITADEL_PROJECT_ID: "projectId",
|
|
28
|
+
VITE_ZITADEL_PROJECT_ID: "projectId",
|
|
29
|
+
ZITADEL_PROJECT_SECRET: "projectSecret"
|
|
30
|
+
};
|
|
19
31
|
function applyAppEnvTemplate(template, handle) {
|
|
20
32
|
const env = {};
|
|
21
33
|
for (const [name, field] of Object.entries(template)) {
|
|
@@ -25,8 +37,7 @@ function applyAppEnvTemplate(template, handle) {
|
|
|
25
37
|
}
|
|
26
38
|
return env;
|
|
27
39
|
}
|
|
28
|
-
|
|
29
|
-
//#region src/handshake.ts
|
|
40
|
+
// src/handshake.ts
|
|
30
41
|
/**
|
|
31
42
|
* The handshake file carries an InstanceHandle across process boundaries:
|
|
32
43
|
* written by the script that boots + bootstraps the instance, read by
|
|
@@ -80,7 +91,6 @@ function validatePlatform(value, source) {
|
|
|
80
91
|
const platform = value;
|
|
81
92
|
for (const field of ["projectId", "publishableKey"]) if (typeof platform[field] !== "string" || platform[field].length === 0) fail(`"${field}" is required`);
|
|
82
93
|
}
|
|
83
|
-
|
|
84
|
-
export { nextAppEnv as a, applyAppEnvTemplate as i, waitForHandshake as n, writeHandshake as r, readHandshakeSync as t };
|
|
94
|
+
export { nextAppEnv as a, applyAppEnvTemplate as i, waitForHandshake as n, viteAppEnv as o, writeHandshake as r, readHandshakeSync as t };
|
|
85
95
|
|
|
86
|
-
//# sourceMappingURL=handshake-
|
|
96
|
+
//# sourceMappingURL=handshake-CZWS5b2X.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"handshake-CZWS5b2X.mjs","names":["sleep"],"sources":["../src/app-env.ts","../src/handshake.ts"],"sourcesContent":["import type { InstanceHandle } from \"./types\";\n\n/**\n * Handle fields a template may reference: the flat string facts. Structured\n * fields (e.g. `platform`) are not env-var material — consumers read those\n * from the handle directly.\n */\ntype StringHandleField = {\n [K in keyof InstanceHandle]-?: InstanceHandle[K] extends string | undefined ? K : never;\n}[keyof InstanceHandle];\n\n/**\n * Declarative mapping from an app's env var names to InstanceHandle fields.\n * A template (not a function) so it can cross process boundaries: the\n * Playwright config serializes it into the app-runner's environment, where it\n * is applied to the handle read from the handshake file.\n */\nexport type AppEnvTemplate = Record<string, StringHandleField>;\n\n/**\n * The env shape `@zitadel/sdk-next` apps read, as `zitadel setup` writes it.\n * The server reads `ZITADEL_PROJECT_ID` to hold sessions to the project, the\n * widgets the public copy. Other frameworks pass their own template — the\n * console maps the same handle fields to `VITE_*`/`CONSOLE_*` names, for\n * example.\n */\nexport const nextAppEnv: AppEnvTemplate = {\n ZITADEL_URL: \"baseUrl\",\n ZITADEL_PROJECT_ID: \"projectId\",\n NEXT_PUBLIC_ZITADEL_PROJECT_ID: \"projectId\",\n ZITADEL_PROJECT_SECRET: \"projectSecret\",\n};\n\n/**\n * The env shape a Vite app reads — React, Vue, Solid, Svelte and Qwik — as\n * `zitadel setup` writes it: its dev proxy reaches the server at `ZITADEL_URL`\n * with the secret and names the session cookie after `ZITADEL_PROJECT_ID`,\n * and the widgets read the public copy Vite exposes to the browser.\n */\nexport const viteAppEnv: AppEnvTemplate = {\n ZITADEL_URL: \"baseUrl\",\n ZITADEL_PROJECT_ID: \"projectId\",\n VITE_ZITADEL_PROJECT_ID: \"projectId\",\n ZITADEL_PROJECT_SECRET: \"projectSecret\",\n};\n\nexport function applyAppEnvTemplate(\n template: AppEnvTemplate,\n handle: InstanceHandle,\n): Record<string, string> {\n const env: Record<string, string> = {};\n for (const [name, field] of Object.entries(template)) {\n const value = handle[field];\n if (typeof value !== \"string\" || value.length === 0) {\n // Fail instead of silently dropping the var: an app booted without one\n // of its env vars produces a much harder-to-read failure downstream.\n throw new Error(\n `app env template maps \"${name}\" to handle field \"${field}\", which the instance handle does not carry`,\n );\n }\n env[name] = value;\n }\n return env;\n}\n","import { readFileSync } from \"node:fs\";\nimport { mkdir, readFile, writeFile } from \"node:fs/promises\";\nimport { dirname } from \"node:path\";\nimport { setTimeout as sleep } from \"node:timers/promises\";\n\nimport type { InstanceHandle, PlatformCredentials } from \"./types\";\n\n/**\n * The handshake file carries an InstanceHandle across process boundaries:\n * written by the script that boots + bootstraps the instance, read by\n * Playwright workers (fixtures) and the app dev-server wrapper.\n */\nexport async function writeHandshake(path: string, handle: InstanceHandle): Promise<void> {\n await mkdir(dirname(path), { recursive: true });\n await writeFile(path, `${JSON.stringify(handle, null, 2)}\\n`, { mode: 0o600 });\n}\n\nexport function readHandshakeSync(path: string): InstanceHandle {\n const contents = readFileSync(path, \"utf8\");\n let value: unknown;\n try {\n value = JSON.parse(contents);\n } catch (error) {\n throw new Error(`handshake file ${path} contains invalid JSON: ${(error as Error).message}`, {\n cause: error,\n });\n }\n return validateHandle(value, path);\n}\n\nexport async function waitForHandshake(path: string, timeoutMs = 60_000): Promise<InstanceHandle> {\n const deadline = Date.now() + timeoutMs;\n for (;;) {\n try {\n return validateHandle(JSON.parse(await readFile(path, \"utf8\")), path);\n } catch (error) {\n if (Date.now() >= deadline) {\n throw new Error(\n `handshake file not readable within ${timeoutMs}ms: ${path} (${(error as Error).message})`,\n { cause: error },\n );\n }\n await sleep(250);\n }\n }\n}\n\nfunction validateHandle(value: unknown, source: string): InstanceHandle {\n if (typeof value !== \"object\" || value === null || Array.isArray(value)) {\n throw new Error(`handshake file ${source} is not an object`);\n }\n const handle = value as Partial<InstanceHandle>;\n for (const field of [\"baseUrl\", \"projectId\", \"projectSecret\", \"schemaId\"] as const) {\n if (typeof handle[field] !== \"string\" || handle[field].length === 0) {\n throw new Error(`handshake file ${source} is missing \"${field}\"`);\n }\n }\n if (!URL.canParse(handle.baseUrl as string)) {\n throw new Error(`handshake file ${source} has a malformed \"baseUrl\": ${handle.baseUrl}`);\n }\n if (handle.platform !== undefined) {\n validatePlatform(handle.platform, source);\n }\n return handle as InstanceHandle;\n}\n\n/**\n * The handshake is the cross-process contract, so a malformed platform block\n * must fail here with the field name, not later with a less actionable error.\n */\nfunction validatePlatform(value: unknown, source: string): void {\n const fail = (detail: string): never => {\n throw new Error(`handshake file ${source} has a malformed \"platform\" block: ${detail}`);\n };\n if (typeof value !== \"object\" || value === null || Array.isArray(value)) {\n fail(\"not an object\");\n }\n const platform = value as Partial<PlatformCredentials>;\n for (const field of [\"projectId\", \"publishableKey\"] as const) {\n if (typeof platform[field] !== \"string\" || platform[field].length === 0) {\n fail(`\"${field}\" is required`);\n }\n }\n // Unknown extra fields pass through on purpose: future platform\n // credentials join additively, and an older reader must not reject a\n // newer producer's handle.\n}\n"],"mappings":";;;;;;;;;;;;AA0BA,MAAa,aAA6B;CACxC,aAAa;CACb,oBAAoB;CACpB,gCAAgC;CAChC,wBAAwB;AAC1B;;;;;;;AAQA,MAAa,aAA6B;CACxC,aAAa;CACb,oBAAoB;CACpB,yBAAyB;CACzB,wBAAwB;AAC1B;AAEA,SAAgB,oBACd,UACA,QACwB;CACxB,MAAM,MAA8B,CAAC;CACrC,KAAK,MAAM,CAAC,MAAM,UAAU,OAAO,QAAQ,QAAQ,GAAG;EACpD,MAAM,QAAQ,OAAO;EACrB,IAAI,OAAO,UAAU,YAAY,MAAM,WAAW,GAGhD,MAAM,IAAI,MACR,0BAA0B,KAAK,qBAAqB,MAAM,4CAC5D;EAEF,IAAI,QAAQ;CACd;CACA,OAAO;AACT;;;;;;;ACnDA,eAAsB,eAAe,MAAc,QAAuC;CACxF,MAAM,MAAM,QAAQ,IAAI,GAAG,EAAE,WAAW,KAAK,CAAC;CAC9C,MAAM,UAAU,MAAM,GAAG,KAAK,UAAU,QAAQ,MAAM,CAAC,EAAE,KAAK,EAAE,MAAM,IAAM,CAAC;AAC/E;AAEA,SAAgB,kBAAkB,MAA8B;CAC9D,MAAM,WAAW,aAAa,MAAM,MAAM;CAC1C,IAAI;CACJ,IAAI;EACF,QAAQ,KAAK,MAAM,QAAQ;CAC7B,SAAS,OAAO;EACd,MAAM,IAAI,MAAM,kBAAkB,KAAK,0BAA2B,MAAgB,WAAW,EAC3F,OAAO,MACT,CAAC;CACH;CACA,OAAO,eAAe,OAAO,IAAI;AACnC;AAEA,eAAsB,iBAAiB,MAAc,YAAY,KAAiC;CAChG,MAAM,WAAW,KAAK,IAAI,IAAI;CAC9B,SACE,IAAI;EACF,OAAO,eAAe,KAAK,MAAM,MAAM,SAAS,MAAM,MAAM,CAAC,GAAG,IAAI;CACtE,SAAS,OAAO;EACd,IAAI,KAAK,IAAI,KAAK,UAChB,MAAM,IAAI,MACR,sCAAsC,UAAU,MAAM,KAAK,IAAK,MAAgB,QAAQ,IACxF,EAAE,OAAO,MAAM,CACjB;EAEF,MAAMA,WAAM,GAAG;CACjB;AAEJ;AAEA,SAAS,eAAe,OAAgB,QAAgC;CACtE,IAAI,OAAO,UAAU,YAAY,UAAU,QAAQ,MAAM,QAAQ,KAAK,GACpE,MAAM,IAAI,MAAM,kBAAkB,OAAO,kBAAkB;CAE7D,MAAM,SAAS;CACf,KAAK,MAAM,SAAS;EAAC;EAAW;EAAa;EAAiB;CAAU,GACtE,IAAI,OAAO,OAAO,WAAW,YAAY,OAAO,MAAM,CAAC,WAAW,GAChE,MAAM,IAAI,MAAM,kBAAkB,OAAO,eAAe,MAAM,EAAE;CAGpE,IAAI,CAAC,IAAI,SAAS,OAAO,OAAiB,GACxC,MAAM,IAAI,MAAM,kBAAkB,OAAO,8BAA8B,OAAO,SAAS;CAEzF,IAAI,OAAO,aAAa,KAAA,GACtB,iBAAiB,OAAO,UAAU,MAAM;CAE1C,OAAO;AACT;;;;;AAMA,SAAS,iBAAiB,OAAgB,QAAsB;CAC9D,MAAM,QAAQ,WAA0B;EACtC,MAAM,IAAI,MAAM,kBAAkB,OAAO,qCAAqC,QAAQ;CACxF;CACA,IAAI,OAAO,UAAU,YAAY,UAAU,QAAQ,MAAM,QAAQ,KAAK,GACpE,KAAK,eAAe;CAEtB,MAAM,WAAW;CACjB,KAAK,MAAM,SAAS,CAAC,aAAa,gBAAgB,GAChD,IAAI,OAAO,SAAS,WAAW,YAAY,SAAS,MAAM,CAAC,WAAW,GACpE,KAAK,IAAI,MAAM,cAAc;AAMnC"}
|
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
import { d as InstanceHandle, f as LocalZitadel, l as ConnectedZitadel, p as LocalZitadelRuntime } from "./session-DueRCvrq.mjs";
|
|
2
|
+
import { SetupPreset, SetupUseCase } from "@zitadel/config/defaults";
|
|
3
|
+
interface BootstrapProjectOptions {
|
|
4
|
+
baseUrl: string;
|
|
5
|
+
projectName?: string;
|
|
6
|
+
/**
|
|
7
|
+
* Origins of the apps that will proxy to this instance. The backend's
|
|
8
|
+
* origin check rejects forwarded requests from unregistered origins.
|
|
9
|
+
*/
|
|
10
|
+
appOrigins?: string[];
|
|
11
|
+
preset?: SetupPreset;
|
|
12
|
+
useCase?: SetupUseCase;
|
|
13
|
+
}
|
|
14
|
+
interface BootstrappedProject {
|
|
15
|
+
projectId: string;
|
|
16
|
+
projectSecret: string;
|
|
17
|
+
/** The browser-plane credential the server issues with every project. */
|
|
18
|
+
previewSecret: string;
|
|
19
|
+
schemaId: string;
|
|
20
|
+
flowId: string;
|
|
21
|
+
}
|
|
22
|
+
declare function bootstrapProject(options: BootstrapProjectOptions): Promise<BootstrappedProject>;
|
|
23
|
+
interface BootServerOptions {
|
|
24
|
+
/** TCP port for the instance; defaults to an OS-assigned free port. */
|
|
25
|
+
port?: number;
|
|
26
|
+
/**
|
|
27
|
+
* State directory. Defaults to a fresh temp dir that is removed on stop;
|
|
28
|
+
* a caller-provided dir is never removed.
|
|
29
|
+
*/
|
|
30
|
+
dir?: string;
|
|
31
|
+
/** Forwarded as ZITADEL_SERVER_BINARY (in-repo runs use dist/server/nextgen). */
|
|
32
|
+
serverBinary?: string;
|
|
33
|
+
/** Keep the owned temp dir after stop (debugging). */
|
|
34
|
+
keep?: boolean;
|
|
35
|
+
/** Test seam: alternative CLI entry script. */
|
|
36
|
+
cliBin?: string;
|
|
37
|
+
timeoutMs?: number;
|
|
38
|
+
}
|
|
39
|
+
interface BootedServer {
|
|
40
|
+
baseUrl: string;
|
|
41
|
+
runtime: LocalZitadelRuntime;
|
|
42
|
+
stop(): Promise<void>;
|
|
43
|
+
}
|
|
44
|
+
/**
|
|
45
|
+
* Boot an ephemeral local server by shelling out to `zitadel start` and parse
|
|
46
|
+
* its JSON envelope. The CLI owns the subtle parts (port preflight, health
|
|
47
|
+
* wait, process-group stop), so this module stays a thin adapter; swapping it
|
|
48
|
+
* for direct library calls later must not change the shape returned here.
|
|
49
|
+
*/
|
|
50
|
+
declare function bootLocalServer(options?: BootServerOptions): Promise<BootedServer>;
|
|
51
|
+
/**
|
|
52
|
+
* The handshake file carries an InstanceHandle across process boundaries:
|
|
53
|
+
* written by the script that boots + bootstraps the instance, read by
|
|
54
|
+
* Playwright workers (fixtures) and the app dev-server wrapper.
|
|
55
|
+
*/
|
|
56
|
+
declare function writeHandshake(path: string, handle: InstanceHandle): Promise<void>;
|
|
57
|
+
declare function readHandshakeSync(path: string): InstanceHandle;
|
|
58
|
+
declare function waitForHandshake(path: string, timeoutMs?: number): Promise<InstanceHandle>;
|
|
59
|
+
type StartLocalZitadelOptions = BootServerOptions & Omit<BootstrapProjectOptions, "baseUrl">;
|
|
60
|
+
/**
|
|
61
|
+
* Attach to an already-bootstrapped instance/project. Lifecycle-free on
|
|
62
|
+
* purpose: this is the entry point for Playwright workers (via the handshake
|
|
63
|
+
* file) and, later, for seeding remote instances.
|
|
64
|
+
*/
|
|
65
|
+
declare function connectZitadel(handle: InstanceHandle): ConnectedZitadel;
|
|
66
|
+
/**
|
|
67
|
+
* Boot an ephemeral local instance (binary runtime + SQLite by default, no
|
|
68
|
+
* Docker) and bootstrap a project + default schema + login flow on it. The
|
|
69
|
+
* result can seed loginable password users immediately.
|
|
70
|
+
*/
|
|
71
|
+
declare function startLocalZitadel(options?: StartLocalZitadelOptions): Promise<LocalZitadel>;
|
|
72
|
+
export { waitForHandshake as a, BootedServer as c, BootstrappedProject as d, bootstrapProject as f, readHandshakeSync as i, bootLocalServer as l, connectZitadel as n, writeHandshake as o, startLocalZitadel as r, BootServerOptions as s, StartLocalZitadelOptions as t, BootstrapProjectOptions as u };
|
|
73
|
+
//# sourceMappingURL=index-B9tztG3_.d.mts.map
|
package/dist/index.cjs
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
2
|
-
const require_src = require("./src-
|
|
3
|
-
const require_handshake = require("./handshake-
|
|
2
|
+
const require_src = require("./src-EogQCM5q.cjs");
|
|
3
|
+
const require_handshake = require("./handshake-BEhxJx4Z.cjs");
|
|
4
4
|
exports.SESSION_COOKIE_NAME = require_src.SESSION_COOKIE_NAME;
|
|
5
5
|
exports.applyAppEnvTemplate = require_handshake.applyAppEnvTemplate;
|
|
6
6
|
exports.bootLocalServer = require_src.bootLocalServer;
|
|
@@ -12,5 +12,6 @@ exports.nextAppEnv = require_handshake.nextAppEnv;
|
|
|
12
12
|
exports.readHandshakeSync = require_handshake.readHandshakeSync;
|
|
13
13
|
exports.sessionCookieName = require_src.sessionCookieName;
|
|
14
14
|
exports.startLocalZitadel = require_src.startLocalZitadel;
|
|
15
|
+
exports.viteAppEnv = require_handshake.viteAppEnv;
|
|
15
16
|
exports.waitForHandshake = require_handshake.waitForHandshake;
|
|
16
17
|
exports.writeHandshake = require_handshake.writeHandshake;
|
package/dist/index.d.mts
CHANGED
|
@@ -1,81 +1,3 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
|
|
4
|
-
interface BootstrapProjectOptions {
|
|
5
|
-
baseUrl: string;
|
|
6
|
-
projectName?: string;
|
|
7
|
-
/**
|
|
8
|
-
* Origins of the apps that will proxy to this instance. The backend's
|
|
9
|
-
* origin check rejects forwarded requests from unregistered origins.
|
|
10
|
-
*/
|
|
11
|
-
appOrigins?: string[];
|
|
12
|
-
preset?: SetupPreset;
|
|
13
|
-
useCase?: SetupUseCase;
|
|
14
|
-
}
|
|
15
|
-
interface BootstrappedProject {
|
|
16
|
-
projectId: string;
|
|
17
|
-
projectSecret: string;
|
|
18
|
-
/** The browser-plane credential the server issues with every project. */
|
|
19
|
-
previewSecret: string;
|
|
20
|
-
schemaId: string;
|
|
21
|
-
flowId: string;
|
|
22
|
-
}
|
|
23
|
-
export declare function bootstrapProject(options: BootstrapProjectOptions): Promise<BootstrappedProject>;
|
|
24
|
-
//#endregion
|
|
25
|
-
//#region src/lifecycle.d.ts
|
|
26
|
-
interface BootServerOptions {
|
|
27
|
-
/** TCP port for the instance; defaults to an OS-assigned free port. */
|
|
28
|
-
port?: number;
|
|
29
|
-
/**
|
|
30
|
-
* State directory. Defaults to a fresh temp dir that is removed on stop;
|
|
31
|
-
* a caller-provided dir is never removed.
|
|
32
|
-
*/
|
|
33
|
-
dir?: string;
|
|
34
|
-
/** Forwarded as ZITADEL_SERVER_BINARY (in-repo runs use dist/server/nextgen). */
|
|
35
|
-
serverBinary?: string;
|
|
36
|
-
/** Keep the owned temp dir after stop (debugging). */
|
|
37
|
-
keep?: boolean;
|
|
38
|
-
/** Test seam: alternative CLI entry script. */
|
|
39
|
-
cliBin?: string;
|
|
40
|
-
timeoutMs?: number;
|
|
41
|
-
}
|
|
42
|
-
interface BootedServer {
|
|
43
|
-
baseUrl: string;
|
|
44
|
-
runtime: LocalZitadelRuntime;
|
|
45
|
-
stop(): Promise<void>;
|
|
46
|
-
}
|
|
47
|
-
/**
|
|
48
|
-
* Boot an ephemeral local server by shelling out to `zitadel start` and parse
|
|
49
|
-
* its JSON envelope. The CLI owns the subtle parts (port preflight, health
|
|
50
|
-
* wait, process-group stop), so this module stays a thin adapter; swapping it
|
|
51
|
-
* for direct library calls later must not change the shape returned here.
|
|
52
|
-
*/
|
|
53
|
-
export declare function bootLocalServer(options?: BootServerOptions): Promise<BootedServer>;
|
|
54
|
-
//#endregion
|
|
55
|
-
//#region src/handshake.d.ts
|
|
56
|
-
/**
|
|
57
|
-
* The handshake file carries an InstanceHandle across process boundaries:
|
|
58
|
-
* written by the script that boots + bootstraps the instance, read by
|
|
59
|
-
* Playwright workers (fixtures) and the app dev-server wrapper.
|
|
60
|
-
*/
|
|
61
|
-
export declare function writeHandshake(path: string, handle: InstanceHandle): Promise<void>;
|
|
62
|
-
export declare function readHandshakeSync(path: string): InstanceHandle;
|
|
63
|
-
export declare function waitForHandshake(path: string, timeoutMs?: number): Promise<InstanceHandle>;
|
|
64
|
-
//#endregion
|
|
65
|
-
//#region src/index.d.ts
|
|
66
|
-
export type StartLocalZitadelOptions = BootServerOptions & Omit<BootstrapProjectOptions, "baseUrl">;
|
|
67
|
-
/**
|
|
68
|
-
* Attach to an already-bootstrapped instance/project. Lifecycle-free on
|
|
69
|
-
* purpose: this is the entry point for Playwright workers (via the handshake
|
|
70
|
-
* file) and, later, for seeding remote instances.
|
|
71
|
-
*/
|
|
72
|
-
export declare function connectZitadel(handle: InstanceHandle): ConnectedZitadel;
|
|
73
|
-
/**
|
|
74
|
-
* Boot an ephemeral local instance (binary runtime + SQLite by default, no
|
|
75
|
-
* Docker) and bootstrap a project + default schema + login flow on it. The
|
|
76
|
-
* result can seed loginable password users immediately.
|
|
77
|
-
*/
|
|
78
|
-
export declare function startLocalZitadel(options?: StartLocalZitadelOptions): Promise<LocalZitadel>;
|
|
79
|
-
//#endregion
|
|
80
|
-
export { type AppEnvTemplate, type BootServerOptions, type BootedServer, type BootstrapProjectOptions, type BootstrappedProject, type ConnectedZitadel, type Identity, type InstanceHandle, type LocalZitadel, type LocalZitadelRuntime, type MintedSession, type PlatformCredentials, SESSION_COOKIE_NAME, type SeedSessionInput, type SeedUserInput, type SeedUsersTemplate, type SeededUser, type SessionCookie, applyAppEnvTemplate, browserSessionCookieName, identity, nextAppEnv, sessionCookieName };
|
|
81
|
-
//# sourceMappingURL=index.d.mts.map
|
|
1
|
+
import { a as waitForHandshake, c as BootedServer, d as BootstrappedProject, f as bootstrapProject, i as readHandshakeSync, l as bootLocalServer, n as connectZitadel, o as writeHandshake, r as startLocalZitadel, s as BootServerOptions, t as StartLocalZitadelOptions, u as BootstrapProjectOptions } from "./index-B9tztG3_.mjs";
|
|
2
|
+
import { _ as SeedUserInput, a as AppEnvTemplate, b as SessionCookie, c as viteAppEnv, d as InstanceHandle, f as LocalZitadel, g as SeedSessionInput, h as PlatformCredentials, i as identity, l as ConnectedZitadel, m as MintedSession, n as browserSessionCookieName, o as applyAppEnvTemplate, p as LocalZitadelRuntime, r as sessionCookieName, s as nextAppEnv, t as SESSION_COOKIE_NAME, u as Identity, v as SeedUsersTemplate, y as SeededUser } from "./session-DueRCvrq.mjs";
|
|
3
|
+
export { type AppEnvTemplate, type BootServerOptions, type BootedServer, type BootstrapProjectOptions, type BootstrappedProject, type ConnectedZitadel, type Identity, type InstanceHandle, type LocalZitadel, type LocalZitadelRuntime, type MintedSession, type PlatformCredentials, SESSION_COOKIE_NAME, type SeedSessionInput, type SeedUserInput, type SeedUsersTemplate, type SeededUser, type SessionCookie, StartLocalZitadelOptions, applyAppEnvTemplate, bootLocalServer, bootstrapProject, browserSessionCookieName, connectZitadel, identity, nextAppEnv, readHandshakeSync, sessionCookieName, startLocalZitadel, viteAppEnv, waitForHandshake, writeHandshake };
|
package/dist/index.mjs
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
import { a as nextAppEnv, i as applyAppEnvTemplate, n as waitForHandshake, r as writeHandshake, t as readHandshakeSync } from "./handshake-
|
|
2
|
-
import { c as bootLocalServer, i as browserSessionCookieName,
|
|
3
|
-
export { SESSION_COOKIE_NAME, applyAppEnvTemplate, bootLocalServer, bootstrapProject, browserSessionCookieName, connectZitadel, identity, nextAppEnv, readHandshakeSync, sessionCookieName, startLocalZitadel, waitForHandshake, writeHandshake };
|
|
1
|
+
import { a as nextAppEnv, i as applyAppEnvTemplate, n as waitForHandshake, o as viteAppEnv, r as writeHandshake, t as readHandshakeSync } from "./handshake-CZWS5b2X.mjs";
|
|
2
|
+
import { c as bootLocalServer, i as browserSessionCookieName, n as startLocalZitadel, o as sessionCookieName, r as SESSION_COOKIE_NAME, s as identity, t as connectZitadel, u as bootstrapProject } from "./src-DImgqUUu.mjs";
|
|
3
|
+
export { SESSION_COOKIE_NAME, applyAppEnvTemplate, bootLocalServer, bootstrapProject, browserSessionCookieName, connectZitadel, identity, nextAppEnv, readHandshakeSync, sessionCookieName, startLocalZitadel, viteAppEnv, waitForHandshake, writeHandshake };
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
|
|
1
|
+
// src/orchestration.ts
|
|
2
2
|
/**
|
|
3
3
|
* The contract between `withZitadel()` (evaluated in the Playwright config
|
|
4
4
|
* process) and the two executables it points webServer entries at. Options
|
|
@@ -32,7 +32,6 @@ function parseJsonEnv(raw, name) {
|
|
|
32
32
|
throw new Error(`${name} contains invalid JSON: ${error.message}`, { cause: error });
|
|
33
33
|
}
|
|
34
34
|
}
|
|
35
|
-
//#endregion
|
|
36
35
|
export { parseSupervisorConfig as a, parseAppRunnerConfig as i, HANDSHAKE_ENV as n, requireHandshakePath as o, SUPERVISOR_CONFIG_ENV as r, APP_RUNNER_CONFIG_ENV as t };
|
|
37
36
|
|
|
38
|
-
//# sourceMappingURL=orchestration-
|
|
37
|
+
//# sourceMappingURL=orchestration-Cf4M8lil.mjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"orchestration-
|
|
1
|
+
{"version":3,"file":"orchestration-Cf4M8lil.mjs","names":[],"sources":["../src/orchestration.ts"],"sourcesContent":["import type { SetupPreset, SetupUseCase } from \"@zitadel/config/defaults\";\n\nimport type { AppEnvTemplate } from \"./app-env\";\n\n/**\n * The contract between `withZitadel()` (evaluated in the Playwright config\n * process) and the two executables it points webServer entries at. Options\n * travel as JSON in these env vars because a webServer command is a plain\n * string — there is no richer channel.\n */\nexport const SUPERVISOR_CONFIG_ENV = \"ZITADEL_TESTING_SUPERVISOR\";\nexport const APP_RUNNER_CONFIG_ENV = \"ZITADEL_TESTING_APP_RUNNER\";\n/** Read by the executables and the Playwright fixtures alike. */\nexport const HANDSHAKE_ENV = \"ZITADEL_TESTING_HANDSHAKE\";\n\nexport interface SupervisorConfig {\n /** Fixed port: the config process must know the health URL up front. */\n port: number;\n appOrigins?: string[];\n serverBinary?: string;\n /** Appended to the missing-binary error, e.g. how to build it. */\n serverBinaryHint?: string;\n dir?: string;\n keep?: boolean;\n projectName?: string;\n preset?: SetupPreset;\n useCase?: SetupUseCase;\n timeoutMs?: number;\n}\n\nexport interface AppRunnerConfig {\n /** Spawn argv; executed without a shell. */\n command: string[];\n cwd?: string;\n env?: AppEnvTemplate;\n handshakeTimeoutMs?: number;\n}\n\nexport function parseSupervisorConfig(raw: string | undefined): SupervisorConfig {\n const value = parseJsonEnv(raw, SUPERVISOR_CONFIG_ENV) as Partial<SupervisorConfig>;\n if (typeof value.port !== \"number\" || !Number.isInteger(value.port) || value.port <= 0) {\n throw new Error(`${SUPERVISOR_CONFIG_ENV} must carry a positive integer \"port\"`);\n }\n return value as SupervisorConfig;\n}\n\nexport function parseAppRunnerConfig(raw: string | undefined): AppRunnerConfig {\n const value = parseJsonEnv(raw, APP_RUNNER_CONFIG_ENV) as Partial<AppRunnerConfig>;\n if (\n !Array.isArray(value.command) ||\n value.command.length === 0 ||\n value.command.some((part) => typeof part !== \"string\" || part.length === 0)\n ) {\n throw new Error(`${APP_RUNNER_CONFIG_ENV} must carry a non-empty string[] \"command\"`);\n }\n return value as AppRunnerConfig;\n}\n\nexport function requireHandshakePath(env: NodeJS.ProcessEnv): string {\n const path = env[HANDSHAKE_ENV];\n if (!path) {\n throw new Error(\n `${HANDSHAKE_ENV} is not set. These entry points are meant to be launched ` +\n `by the webServer entries that withZitadel() generates.`,\n );\n }\n return path;\n}\n\nfunction parseJsonEnv(raw: string | undefined, name: string): unknown {\n if (!raw) {\n throw new Error(\n `${name} is not set. This entry point is meant to be launched by the ` +\n `webServer entries that withZitadel() generates.`,\n );\n }\n try {\n return JSON.parse(raw);\n } catch (error) {\n throw new Error(`${name} contains invalid JSON: ${(error as Error).message}`, {\n cause: error,\n });\n }\n}\n"],"mappings":";;;;;;;AAUA,MAAa,wBAAwB;AACrC,MAAa,wBAAwB;;AAErC,MAAa,gBAAgB;AAyB7B,SAAgB,sBAAsB,KAA2C;CAC/E,MAAM,QAAQ,aAAa,KAAK,qBAAqB;CACrD,IAAI,OAAO,MAAM,SAAS,YAAY,CAAC,OAAO,UAAU,MAAM,IAAI,KAAK,MAAM,QAAQ,GACnF,MAAM,IAAI,MAAM,GAAG,sBAAsB,sCAAsC;CAEjF,OAAO;AACT;AAEA,SAAgB,qBAAqB,KAA0C;CAC7E,MAAM,QAAQ,aAAa,KAAK,qBAAqB;CACrD,IACE,CAAC,MAAM,QAAQ,MAAM,OAAO,KAC5B,MAAM,QAAQ,WAAW,KACzB,MAAM,QAAQ,MAAM,SAAS,OAAO,SAAS,YAAY,KAAK,WAAW,CAAC,GAE1E,MAAM,IAAI,MAAM,GAAG,sBAAsB,2CAA2C;CAEtF,OAAO;AACT;AAEA,SAAgB,qBAAqB,KAAgC;CACnE,MAAM,OAAO,IAAI;CACjB,IAAI,CAAC,MACH,MAAM,IAAI,MACR,GAAG,cAAc,gHAEnB;CAEF,OAAO;AACT;AAEA,SAAS,aAAa,KAAyB,MAAuB;CACpE,IAAI,CAAC,KACH,MAAM,IAAI,MACR,GAAG,KAAK,6GAEV;CAEF,IAAI;EACF,OAAO,KAAK,MAAM,GAAG;CACvB,SAAS,OAAO;EACd,MAAM,IAAI,MAAM,GAAG,KAAK,0BAA2B,MAAgB,WAAW,EAC5E,OAAO,MACT,CAAC;CACH;AACF"}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
|
|
1
|
+
// src/orchestration.ts
|
|
2
2
|
/**
|
|
3
3
|
* The contract between `withZitadel()` (evaluated in the Playwright config
|
|
4
4
|
* process) and the two executables it points webServer entries at. Options
|
|
@@ -32,7 +32,6 @@ function parseJsonEnv(raw, name) {
|
|
|
32
32
|
throw new Error(`${name} contains invalid JSON: ${error.message}`, { cause: error });
|
|
33
33
|
}
|
|
34
34
|
}
|
|
35
|
-
//#endregion
|
|
36
35
|
Object.defineProperty(exports, "APP_RUNNER_CONFIG_ENV", {
|
|
37
36
|
enumerable: true,
|
|
38
37
|
get: function() {
|
|
@@ -70,4 +69,4 @@ Object.defineProperty(exports, "requireHandshakePath", {
|
|
|
70
69
|
}
|
|
71
70
|
});
|
|
72
71
|
|
|
73
|
-
//# sourceMappingURL=orchestration-
|
|
72
|
+
//# sourceMappingURL=orchestration-SELq6dmD.cjs.map
|