@zitadel/testing 0.1.0-alpha.18 → 0.1.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.
Files changed (43) hide show
  1. package/README.md +105 -30
  2. package/dist/app-runner.cjs +4 -3
  3. package/dist/app-runner.cjs.map +1 -1
  4. package/dist/app-runner.d.mts +1 -1
  5. package/dist/app-runner.mjs +4 -3
  6. package/dist/app-runner.mjs.map +1 -1
  7. package/dist/{handshake-ClzWvG8z.mjs → handshake-CwlxMjW0.mjs} +20 -4
  8. package/dist/handshake-CwlxMjW0.mjs.map +1 -0
  9. package/dist/{handshake-CRKcgkfN.cjs → handshake-D6MXSUcd.cjs} +20 -4
  10. package/dist/handshake-D6MXSUcd.cjs.map +1 -0
  11. package/dist/index.cjs +4 -2
  12. package/dist/index.d.mts +10 -16
  13. package/dist/index.d.mts.map +1 -1
  14. package/dist/index.mjs +3 -3
  15. package/dist/{orchestration-C640_1Lg.mjs → orchestration-Clldecyr.mjs} +1 -1
  16. package/dist/{orchestration-C640_1Lg.mjs.map → orchestration-Clldecyr.mjs.map} +1 -1
  17. package/dist/{orchestration-D7QBgQ0l.cjs → orchestration-gIDANMcF.cjs} +1 -1
  18. package/dist/{orchestration-D7QBgQ0l.cjs.map → orchestration-gIDANMcF.cjs.map} +1 -1
  19. package/dist/playwright.cjs +42 -17
  20. package/dist/playwright.cjs.map +1 -1
  21. package/dist/playwright.d.mts +60 -43
  22. package/dist/playwright.d.mts.map +1 -1
  23. package/dist/playwright.mjs +40 -18
  24. package/dist/playwright.mjs.map +1 -1
  25. package/dist/session-BrSkzPpy.d.mts +204 -0
  26. package/dist/session-BrSkzPpy.d.mts.map +1 -0
  27. package/dist/src-CUvV1OWp.cjs +4187 -0
  28. package/dist/src-CUvV1OWp.cjs.map +1 -0
  29. package/dist/{src-eTcdx-ZS.mjs → src-DKJ1hMV8.mjs} +43 -17
  30. package/dist/src-DKJ1hMV8.mjs.map +1 -0
  31. package/dist/supervisor.cjs +3 -3
  32. package/dist/supervisor.cjs.map +1 -1
  33. package/dist/supervisor.d.mts +1 -1
  34. package/dist/supervisor.mjs +3 -3
  35. package/dist/supervisor.mjs.map +1 -1
  36. package/package.json +13 -9
  37. package/dist/app-env-D3W0GYhA.d.mts +0 -122
  38. package/dist/app-env-D3W0GYhA.d.mts.map +0 -1
  39. package/dist/handshake-CRKcgkfN.cjs.map +0 -1
  40. package/dist/handshake-ClzWvG8z.mjs.map +0 -1
  41. package/dist/src-DirKLqi4.cjs +0 -2312
  42. package/dist/src-DirKLqi4.cjs.map +0 -1
  43. package/dist/src-eTcdx-ZS.mjs.map +0 -1
@@ -1,4 +1,4 @@
1
- import { a as nextAppEnv, i as applyAppEnvTemplate } from "./handshake-ClzWvG8z.mjs";
1
+ import { a as nextAppEnv, i as applyAppEnvTemplate } from "./handshake-CwlxMjW0.mjs";
2
2
  import { createRequire } from "node:module";
3
3
  import { createZitadelClient } from "@zitadel/api/client";
4
4
  import { DEFAULT_FLOW_SCHEMA_URI, getDefaultHumanUserSchema, getDefaultLoginFlow } from "@zitadel/config/defaults";
@@ -20,7 +20,10 @@ async function bootstrapProject(options) {
20
20
  const { baseUrl } = options;
21
21
  const project = await createZitadelClient({ baseUrl }).createProject({
22
22
  name: options.projectName ?? DEFAULT_PROJECT_NAME,
23
- preview_origins: options.appOrigins ?? [],
23
+ origins: (options.appOrigins ?? []).map((pattern) => ({
24
+ pattern,
25
+ kind: "preview"
26
+ })),
24
27
  seed_defaults: false
25
28
  });
26
29
  const projectId = requireString(project.id, "project id");
@@ -36,7 +39,6 @@ async function bootstrapProject(options) {
36
39
  });
37
40
  const schemaId = requireString((await client.createSchema(schemaBody, { project_id: projectId })).id, "schema id");
38
41
  const flowBody = getDefaultLoginFlow({
39
- userSchemaUrl: schemaId,
40
42
  preset: options.preset,
41
43
  useCase: options.useCase
42
44
  });
@@ -272,7 +274,9 @@ function failureDetail(result) {
272
274
  /**
273
275
  * A unique unused email + password. Nothing is created on the instance —
274
276
  * this is the input for registration-flow specs, which must prove the flow
275
- * creates the user.
277
+ * creates the user. It needs no instance either, so both entry points export
278
+ * it for specs that run without `withZitadel()`; `seed.identity()` and
279
+ * `zitadel.identity()` call this function.
276
280
  */
277
281
  function identity() {
278
282
  return {
@@ -282,8 +286,8 @@ function identity() {
282
286
  }
283
287
  /**
284
288
  * Create a user that can immediately complete the password login flow:
285
- * `POST /users` (the body must carry `$schema: <schema id>`) followed by
286
- * `PUT /users/{id}/password` with `is_change_required: false`.
289
+ * `POST /users` (the body carries `schema: <schema id>` and the schema-defined
290
+ * content under `attributes`) followed by `PUT /users/{id}/password`.
287
291
  *
288
292
  * Defaults mint a unique email per call (email is x-unique per project), which
289
293
  * is what makes per-test seeding parallel-safe on a shared instance.
@@ -293,14 +297,13 @@ async function seedUser(client, context, input = {}) {
293
297
  const email = input.email ?? fresh.email;
294
298
  const password = input.password ?? fresh.password;
295
299
  const id = requireString((await client.createUser({
296
- ...input.attributes,
297
- $schema: context.schemaId,
298
- email
300
+ schema: context.schemaId,
301
+ attributes: {
302
+ ...input.attributes,
303
+ email
304
+ }
299
305
  }, { project_id: context.projectId })).id, "user id");
300
- await client.setUserPassword(id, {
301
- password,
302
- is_change_required: false
303
- }, { project_id: context.projectId });
306
+ await client.setUserPassword(id, { password });
304
307
  return {
305
308
  id,
306
309
  email,
@@ -325,8 +328,30 @@ async function seedUsers(client, context, count, template = {}) {
325
328
  }
326
329
  //#endregion
327
330
  //#region src/session.ts
328
- /** Mirrors the server's session cookie (internal/api/session.go). */
331
+ /**
332
+ * Mirrors the server's session cookie (internal/api/session.go): the name a
333
+ * direct call to the server sends, and the one an app keeps behind a proxy that
334
+ * passes the server's cookie through, such as an SPA's in production.
335
+ */
329
336
  const SESSION_COOKIE_NAME = "__nextgen_session";
337
+ /**
338
+ * The cookie an app keeps its session in on its own origin behind a server SDK
339
+ * (Next.js, Nuxt, SvelteKit, SolidStart, TanStack Start, Qwik Router) or the dev
340
+ * proxy `zitadel setup` writes for an SPA: `__nextgen_session_<projectId>`. The
341
+ * proxy renames the server's cookie, so the apps and the Console on one host
342
+ * keep a session each (ADR 073).
343
+ *
344
+ * Mirrors `sessionCookieName` in `@zitadel/sdk-core`, including the
345
+ * percent-encoding of every byte outside `[A-Za-z0-9_-]`.
346
+ */
347
+ function sessionCookieName(projectId) {
348
+ let name = `${SESSION_COOKIE_NAME}_`;
349
+ for (const byte of new TextEncoder().encode(projectId)) {
350
+ const char = String.fromCharCode(byte);
351
+ name += /[A-Za-z0-9_-]/.test(char) ? char : `%${byte.toString(16).toUpperCase().padStart(2, "0")}`;
352
+ }
353
+ return name;
354
+ }
330
355
  const MAX_FLOW_STEPS = 6;
331
356
  /**
332
357
  * Drive the real login flow headlessly for a seeded password user and
@@ -463,7 +488,8 @@ function connectZitadel(handle) {
463
488
  identity,
464
489
  seedSession: async (input = {}) => {
465
490
  const { user: existing, flowDefinitionName, origin, ...userInput } = input;
466
- return mintSession(api, handle, context, existing ?? await seedUser(api, context, userInput), {
491
+ const user = existing ?? await seedUser(api, context, userInput);
492
+ return mintSession(api, handle, context, user, {
467
493
  flowDefinitionName,
468
494
  origin: origin ?? handle.appOrigin
469
495
  });
@@ -509,6 +535,6 @@ async function startLocalZitadel(options = {}) {
509
535
  };
510
536
  }
511
537
  //#endregion
512
- export { bootstrapProject as a, bootLocalServer as i, startLocalZitadel as n, SESSION_COOKIE_NAME as r, connectZitadel as t };
538
+ export { identity as a, sessionCookieName as i, startLocalZitadel as n, bootLocalServer as o, SESSION_COOKIE_NAME as r, bootstrapProject as s, connectZitadel as t };
513
539
 
514
- //# sourceMappingURL=src-eTcdx-ZS.mjs.map
540
+ //# sourceMappingURL=src-DKJ1hMV8.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"src-DKJ1hMV8.mjs","names":[],"sources":["../src/bootstrap.ts","../src/cli.ts","../src/envelope.ts","../src/ports.ts","../src/lifecycle.ts","../src/seed.ts","../src/session.ts","../src/index.ts"],"sourcesContent":["import { createZitadelClient, type ZitadelClient } from \"@zitadel/api/client\";\nimport {\n DEFAULT_FLOW_SCHEMA_URI,\n getDefaultHumanUserSchema,\n getDefaultLoginFlow,\n type SetupPreset,\n type SetupUseCase,\n} from \"@zitadel/config/defaults\";\n\nexport interface BootstrapProjectOptions {\n baseUrl: string;\n projectName?: string;\n /**\n * Origins of the apps that will proxy to this instance. The backend's\n * origin check rejects forwarded requests from unregistered origins.\n */\n appOrigins?: string[];\n preset?: SetupPreset;\n useCase?: SetupUseCase;\n}\n\nexport interface BootstrappedProject {\n projectId: string;\n projectSecret: string;\n previewSecret?: string;\n schemaId: string;\n flowId: string;\n}\n\nconst DEFAULT_PROJECT_NAME = \"zitadel-testing\";\n\n/**\n * Server-side half of `zitadel setup`, without any file scaffolding:\n * `POST /projects` is unauthenticated and mints the projectSecret used as the\n * bearer for everything else; the schema is uploaded without `$id` so the\n * server assigns an opaque id, which the flow must then reference.\n */\nexport async function bootstrapProject(\n options: BootstrapProjectOptions,\n): Promise<BootstrappedProject> {\n const { baseUrl } = options;\n const unauthenticated = createZitadelClient({ baseUrl });\n const project = (await unauthenticated.createProject({\n name: options.projectName ?? DEFAULT_PROJECT_NAME,\n origins: (options.appOrigins ?? []).map((pattern) => ({\n pattern,\n kind: \"preview\" as const,\n })),\n seed_defaults: false,\n } as Parameters<ZitadelClient[\"createProject\"]>[0])) as Record<string, unknown>;\n const projectId = requireString(project.id, \"project id\");\n const projectSecret = requireString(project.project_secret, \"project secret\");\n const previewSecret =\n typeof project.preview_secret === \"string\" ? project.preview_secret : undefined;\n\n const client = createZitadelClient({ baseUrl, token: projectSecret });\n\n const { $id: _templateId, ...schemaBody } = getDefaultHumanUserSchema({\n preset: options.preset,\n useCase: options.useCase,\n }) as { $id?: string } & Record<string, unknown>;\n void _templateId;\n const schema = (await client.createSchema(\n schemaBody as Parameters<ZitadelClient[\"createSchema\"]>[0],\n { project_id: projectId },\n )) as Record<string, unknown>;\n const schemaId = requireString(schema.id, \"schema id\");\n\n const flowBody = getDefaultLoginFlow({\n preset: options.preset,\n useCase: options.useCase,\n });\n const flow = (await client.createFlowDefinition({\n project_id: projectId,\n schema_uri: DEFAULT_FLOW_SCHEMA_URI,\n flow_definition: flowBody,\n } as Parameters<ZitadelClient[\"createFlowDefinition\"]>[0])) as Record<string, unknown>;\n const flowId = requireString(flow.id, \"flow definition id\");\n\n return { projectId, projectSecret, previewSecret, schemaId, flowId };\n}\n\nexport function requireString(value: unknown, label: string): string {\n if (typeof value === \"string\" && value.length > 0) {\n return value;\n }\n throw new Error(`Missing ${label} in server response.`);\n}\n","import { spawn } from \"node:child_process\";\nimport { createRequire } from \"node:module\";\nimport { dirname, join } from \"node:path\";\n\nexport interface RunCliOptions {\n args: string[];\n env?: NodeJS.ProcessEnv;\n /** Test seam / escape hatch: alternative CLI entry script. */\n bin?: string;\n timeoutMs?: number;\n}\n\nexport interface RunCliResult {\n exitCode: number;\n stdout: string;\n stderr: string;\n}\n\nconst DEFAULT_TIMEOUT_MS = 120_000;\n\nexport function resolveCliBin(): string {\n const require = createRequire(import.meta.url);\n const pkgPath = require.resolve(\"@zitadel/cli/package.json\");\n const pkg = require(pkgPath) as { bin?: Record<string, string> };\n const rel = pkg.bin?.zitadel;\n if (!rel) {\n throw new Error(\"@zitadel/cli does not declare a `zitadel` bin entry\");\n }\n return join(dirname(pkgPath), rel);\n}\n\nexport function runCli(options: RunCliOptions): Promise<RunCliResult> {\n const bin = options.bin ?? resolveCliBin();\n const timeoutMs = options.timeoutMs ?? DEFAULT_TIMEOUT_MS;\n return new Promise((resolve, reject) => {\n const child = spawn(process.execPath, [bin, ...options.args], {\n env: { ...process.env, ...options.env },\n stdio: [\"ignore\", \"pipe\", \"pipe\"],\n });\n let stdout = \"\";\n let stderr = \"\";\n child.stdout.setEncoding(\"utf8\");\n child.stdout.on(\"data\", (chunk: string) => {\n stdout += chunk;\n });\n child.stderr.setEncoding(\"utf8\");\n child.stderr.on(\"data\", (chunk: string) => {\n stderr += chunk;\n });\n const timer = setTimeout(() => {\n child.kill(\"SIGKILL\");\n reject(\n new Error(\n `zitadel ${options.args[0] ?? \"\"} timed out after ${timeoutMs}ms\\n${tail(stderr)}`,\n ),\n );\n }, timeoutMs);\n timer.unref();\n child.on(\"error\", (error) => {\n clearTimeout(timer);\n reject(error);\n });\n child.on(\"close\", (code) => {\n clearTimeout(timer);\n resolve({ exitCode: code ?? -1, stdout, stderr });\n });\n });\n}\n\nexport function tail(text: string, lines = 20): string {\n return text.split(\"\\n\").slice(-lines).join(\"\\n\").trim();\n}\n","export interface CliEnvelope<TData> {\n cli_version?: string;\n command?: string;\n source?: string;\n status: string;\n data: TData;\n warnings?: string[];\n /** Error envelopes (`status: \"error\"`) carry remediation guidance. */\n code?: string;\n message?: string;\n hint?: string;\n next_commands?: string[];\n}\n\n/**\n * Render an error envelope's remediation fields for humans — the CLI's\n * `hint`/`next_commands` are the actionable part of a failure (e.g. \"Reinstall\n * @zitadel/cli so npm can install @zitadel/server\"), so surface them instead\n * of a raw stdout dump. Returns undefined when the envelope has no message.\n */\nexport function describeEnvelopeError(envelope: CliEnvelope<unknown>): string | undefined {\n if (typeof envelope.message !== \"string\" || envelope.message.length === 0) {\n return undefined;\n }\n const lines = [envelope.code ? `${envelope.code}: ${envelope.message}` : envelope.message];\n if (envelope.hint) {\n lines.push(`hint: ${envelope.hint}`);\n }\n if (envelope.next_commands && envelope.next_commands.length > 0) {\n lines.push(`next: ${envelope.next_commands.join(\" | \")}`);\n }\n return lines.join(\"\\n\");\n}\n\nexport interface StartEnvelopeData {\n runtime: {\n backend: string;\n pid: number;\n port: number;\n data_dir: string;\n log_path: string;\n };\n urls: {\n api: string;\n console: string;\n login: string;\n };\n}\n\nexport function parseCliEnvelope<TData>(stdout: string, context: string): CliEnvelope<TData> {\n const start = stdout.indexOf(\"{\");\n const end = stdout.lastIndexOf(\"}\");\n if (start === -1 || end <= start) {\n throw new Error(\n `${context}: expected a JSON envelope on stdout, got:\\n${stdout.trim() || \"(empty)\"}`,\n );\n }\n let parsed: unknown;\n try {\n parsed = JSON.parse(stdout.slice(start, end + 1));\n } catch (error) {\n throw new Error(\n `${context}: failed to parse JSON envelope: ${(error as Error).message}\\n${stdout.trim()}`,\n { cause: error },\n );\n }\n if (\n typeof parsed !== \"object\" ||\n parsed === null ||\n typeof (parsed as { status?: unknown }).status !== \"string\"\n ) {\n throw new Error(`${context}: stdout JSON is not a CLI envelope:\\n${stdout.trim()}`);\n }\n return parsed as CliEnvelope<TData>;\n}\n","import { createServer } from \"node:net\";\n\n/**\n * Ask the OS for a free TCP port. The port is released before returning, so a\n * racing process could grab it; the CLI's own preflight surfaces that as\n * E_PORT_IN_USE, which is loud rather than corrupting.\n */\nexport function getFreePort(): Promise<number> {\n return new Promise((resolve, reject) => {\n const server = createServer();\n server.unref();\n server.on(\"error\", reject);\n server.listen(0, \"127.0.0.1\", () => {\n const address = server.address();\n if (address === null || typeof address === \"string\") {\n server.close();\n reject(new Error(\"could not determine a free port\"));\n return;\n }\n const { port } = address;\n server.close((err) => {\n if (err) {\n reject(err);\n return;\n }\n resolve(port);\n });\n });\n });\n}\n","import { mkdtemp, rm } from \"node:fs/promises\";\nimport { tmpdir } from \"node:os\";\nimport { join } from \"node:path\";\n\nimport { runCli, tail, type RunCliResult } from \"./cli\";\nimport {\n describeEnvelopeError,\n parseCliEnvelope,\n type CliEnvelope,\n type StartEnvelopeData,\n} from \"./envelope\";\nimport { getFreePort } from \"./ports\";\nimport type { LocalZitadelRuntime } from \"./types\";\n\nexport interface BootServerOptions {\n /** TCP port for the instance; defaults to an OS-assigned free port. */\n port?: number;\n /**\n * State directory. Defaults to a fresh temp dir that is removed on stop;\n * a caller-provided dir is never removed.\n */\n dir?: string;\n /** Forwarded as ZITADEL_SERVER_BINARY (in-repo runs use dist/server/nextgen). */\n serverBinary?: string;\n /** Keep the owned temp dir after stop (debugging). */\n keep?: boolean;\n /** Test seam: alternative CLI entry script. */\n cliBin?: string;\n timeoutMs?: number;\n}\n\nexport interface BootedServer {\n baseUrl: string;\n runtime: LocalZitadelRuntime;\n stop(): Promise<void>;\n}\n\n/**\n * Boot an ephemeral local server by shelling out to `zitadel start` and parse\n * its JSON envelope. The CLI owns the subtle parts (port preflight, health\n * wait, process-group stop), so this module stays a thin adapter; swapping it\n * for direct library calls later must not change the shape returned here.\n */\nexport async function bootLocalServer(options: BootServerOptions = {}): Promise<BootedServer> {\n const ownsDir = options.dir === undefined;\n const dir = options.dir ?? (await mkdtemp(join(tmpdir(), \"zitadel-testing-\")));\n const port = options.port ?? (await getFreePort());\n const env: NodeJS.ProcessEnv = {};\n if (options.serverBinary) {\n env.ZITADEL_SERVER_BINARY = options.serverBinary;\n }\n\n const result = await runCli({\n args: [\"start\", \"--port\", String(port), \"--non-interactive\", \"--json\", \"-c\", dir],\n bin: options.cliBin,\n env,\n timeoutMs: options.timeoutMs,\n });\n if (result.exitCode !== 0) {\n // Keep the dir on failure: server.log inside it is the diagnostic.\n throw new Error(\n `zitadel start exited with code ${result.exitCode}.\\n` +\n `${failureDetail(result)}\\n` +\n `state dir kept for inspection: ${dir}`,\n );\n }\n const stopViaCli = async (): Promise<void> => {\n const stopResult = await runCli({\n args: [\"stop\", \"--non-interactive\", \"--json\", \"-c\", dir],\n bin: options.cliBin,\n env,\n timeoutMs: options.timeoutMs,\n });\n if (stopResult.exitCode !== 0) {\n throw new Error(\n `zitadel stop exited with code ${stopResult.exitCode}.\\n` +\n `${failureDetail(stopResult)}\\n` +\n `state dir kept for inspection: ${dir}`,\n );\n }\n };\n\n let envelope: CliEnvelope<StartEnvelopeData>;\n try {\n envelope = parseCliEnvelope<StartEnvelopeData>(result.stdout, \"zitadel start\");\n if (envelope.status !== \"ok\") {\n throw new Error(\n `zitadel start reported status \"${envelope.status}\":\\n` +\n `${describeEnvelopeError(envelope) ?? tail(result.stdout)}`,\n );\n }\n } catch (error) {\n const startError = new Error(\n `zitadel start produced unusable output.\\n` +\n `reason: ${error instanceof Error ? error.message : String(error)}\\n` +\n `stdout: ${tail(result.stdout) || \"(empty)\"}\\n` +\n `stderr: ${tail(result.stderr) || \"(empty)\"}\\n` +\n `state dir kept for inspection: ${dir}`,\n { cause: error },\n );\n // start exited 0, so a server may well be running despite the unusable\n // output — stop it instead of orphaning it.\n try {\n await stopViaCli();\n } catch (stopError) {\n // Both errors are preserved in AggregateError.errors, which the rule\n // below cannot model.\n throw new AggregateError(\n [startError, stopError],\n `${startError.message}\\nStopping the possibly-running instance also failed: ${\n stopError instanceof Error ? stopError.message : String(stopError)\n }`,\n );\n }\n throw startError;\n }\n\n const { runtime, urls } = envelope.data;\n const runStop = async (): Promise<void> => {\n await stopViaCli();\n if (ownsDir && !options.keep) {\n await rm(dir, { recursive: true, force: true });\n }\n };\n // Memoize the in-flight stop so concurrent callers await the same cleanup,\n // and reset on failure so a failed stop can be retried instead of silently\n // leaving the server behind.\n let stopPromise: Promise<void> | undefined;\n const stop = (): Promise<void> => {\n stopPromise ??= runStop().catch((error: unknown) => {\n stopPromise = undefined;\n throw error;\n });\n return stopPromise;\n };\n\n return {\n baseUrl: urls.api,\n runtime: {\n port: runtime.port,\n pid: runtime.pid,\n dir,\n logPath: runtime.log_path,\n },\n stop,\n };\n}\n\n/**\n * A failed CLI run usually still prints an error envelope; its\n * message/hint/next_commands beat raw output tails (e.g. a fresh install\n * missing @zitadel/server gets \"Reinstall @zitadel/cli\" instead of a stack).\n */\nfunction failureDetail(result: RunCliResult): string {\n try {\n const described = describeEnvelopeError(parseCliEnvelope<unknown>(result.stdout, \"zitadel\"));\n if (described) {\n return described;\n }\n } catch {\n // stdout carried no envelope; fall back to the raw tails.\n }\n return `stdout: ${tail(result.stdout) || \"(empty)\"}\\nstderr: ${tail(result.stderr) || \"(empty)\"}`;\n}\n","import { randomUUID } from \"node:crypto\";\n\nimport type { ZitadelClient } from \"@zitadel/api/client\";\n\nimport { requireString } from \"./bootstrap\";\nimport type { Identity, SeededUser, SeedUserInput, SeedUsersTemplate } from \"./types\";\n\nexport interface SeedContext {\n projectId: string;\n schemaId: string;\n}\n\n/**\n * A unique unused email + password. Nothing is created on the instance —\n * this is the input for registration-flow specs, which must prove the flow\n * creates the user. It needs no instance either, so both entry points export\n * it for specs that run without `withZitadel()`; `seed.identity()` and\n * `zitadel.identity()` call this function.\n */\nexport function identity(): Identity {\n return {\n email: `e2e-${randomUUID().slice(0, 8)}@example.com`,\n password: `Pw!${randomUUID()}`,\n };\n}\n\n/**\n * Create a user that can immediately complete the password login flow:\n * `POST /users` (the body carries `schema: <schema id>` and the schema-defined\n * content under `attributes`) followed by `PUT /users/{id}/password`.\n *\n * Defaults mint a unique email per call (email is x-unique per project), which\n * is what makes per-test seeding parallel-safe on a shared instance.\n */\nexport async function seedUser(\n client: ZitadelClient,\n context: SeedContext,\n input: SeedUserInput = {},\n): Promise<SeededUser> {\n const fresh = identity();\n const email = input.email ?? fresh.email;\n const password = input.password ?? fresh.password;\n // `email` wins over the templated attributes: the returned SeededUser must\n // never disagree with what was actually created, since a silently overridden\n // email would yield credentials that cannot log in.\n const user = (await client.createUser(\n {\n schema: context.schemaId,\n attributes: { ...input.attributes, email },\n },\n { project_id: context.projectId },\n )) as Record<string, unknown>;\n const id = requireString(user.id, \"user id\");\n await client.setUserPassword(id, { password });\n return { id, email, password };\n}\n\n/**\n * Seed `count` users sequentially. The template makes fixture data\n * deterministic per index (stable emails/names keep screenshot diffs about\n * code, not reshuffled data — the `console:dev-real` pattern); untemplated\n * fields fall back to the unique defaults. Name-like attributes need a\n * schema that declares them (`useCase: \"consumer\"` or wider).\n */\nexport async function seedUsers(\n client: ZitadelClient,\n context: SeedContext,\n count: number,\n template: SeedUsersTemplate = {},\n): Promise<SeededUser[]> {\n const users: SeededUser[] = [];\n for (let index = 0; index < count; index += 1) {\n users.push(\n await seedUser(client, context, {\n email: template.email?.(index),\n password: template.password?.(index),\n attributes: template.attributes?.(index),\n }),\n );\n }\n return users;\n}\n","import type { ZitadelClient } from \"@zitadel/api/client\";\nimport type { CreateFlow201, CreateFlow201StepFieldsItem } from \"@zitadel/api/generated/model\";\n\nimport type { SeedContext } from \"./seed\";\nimport type { InstanceHandle, MintedSession, SeededUser } from \"./types\";\n\n/**\n * Mirrors the server's session cookie (internal/api/session.go): the name a\n * direct call to the server sends, and the one an app keeps behind a proxy that\n * passes the server's cookie through, such as an SPA's in production.\n */\nexport const SESSION_COOKIE_NAME = \"__nextgen_session\";\n\n/**\n * The cookie an app keeps its session in on its own origin behind a server SDK\n * (Next.js, Nuxt, SvelteKit, SolidStart, TanStack Start, Qwik Router) or the dev\n * proxy `zitadel setup` writes for an SPA: `__nextgen_session_<projectId>`. The\n * proxy renames the server's cookie, so the apps and the Console on one host\n * keep a session each (ADR 073).\n *\n * Mirrors `sessionCookieName` in `@zitadel/sdk-core`, including the\n * percent-encoding of every byte outside `[A-Za-z0-9_-]`.\n */\nexport function sessionCookieName(projectId: string): string {\n let name = `${SESSION_COOKIE_NAME}_`;\n for (const byte of new TextEncoder().encode(projectId)) {\n const char = String.fromCharCode(byte);\n name += /[A-Za-z0-9_-]/.test(char)\n ? char\n : `%${byte.toString(16).toUpperCase().padStart(2, \"0\")}`;\n }\n return name;\n}\n\nconst MAX_FLOW_STEPS = 6;\n\nexport interface MintSessionOptions {\n /** Forwarded to `POST /flow`; the project's default flow when omitted. */\n flowDefinitionName?: string;\n /** Origin header for flow calls (the project's origin check enforces it). */\n origin?: string;\n}\n\n/**\n * Drive the real login flow headlessly for a seeded password user and\n * exchange the terminal handoff for a session: exactly what `<zitadel-login>`\n * does, minus the rendering. Supports flows whose steps only ask for the\n * user's email and password (the shipped `password-first` presets); any step\n * demanding more — a challenge, an unknown field — fails loudly by design.\n *\n * Flow calls use raw fetch instead of the typed client because the flow is\n * stateless through the sealed `_zflow` cookie (internal/api/flow.go): every\n * response re-seals the flow state into Set-Cookie, and submits are rejected\n * without it. Browsers round-trip it implicitly; here a one-cookie jar does.\n */\nexport async function mintSession(\n client: ZitadelClient,\n handle: Pick<InstanceHandle, \"baseUrl\" | \"projectSecret\">,\n context: SeedContext,\n user: SeededUser,\n options: MintSessionOptions = {},\n): Promise<MintedSession> {\n const values: Record<string, string> = { email: user.email, password: user.password };\n const jar = new FlowCookieJar();\n const origin = options.origin;\n\n let response = await flowFetch(handle, jar, origin, \"/flow\", {\n project_id: context.projectId,\n purpose: \"login\",\n ...(options.flowDefinitionName ? { flow_definition_name: options.flowDefinitionName } : {}),\n });\n\n for (let hop = 0; hop < MAX_FLOW_STEPS; hop += 1) {\n if (response.handoff_token) {\n const exchanged = await client.exchangeHandoff(\n { handoff_token: response.handoff_token },\n { project_id: context.projectId },\n );\n return {\n user,\n sessionToken: exchanged.session_token,\n expiresAt: exchanged.session.expires_at,\n cookie: {\n name: SESSION_COOKIE_NAME,\n value: exchanged.session_token,\n httpOnly: true,\n secure: true,\n sameSite: \"Lax\",\n path: \"/\",\n },\n };\n }\n response = await flowFetch(\n handle,\n jar,\n origin,\n `/flow/${encodeURIComponent(response.id)}/submit`,\n {\n session_token: response.session_token,\n action: \"submit\",\n fields: collectFields(response, values),\n },\n );\n }\n\n throw new Error(\n `seed.session: flow did not complete within ${MAX_FLOW_STEPS} steps ` +\n `(last step: ${describeStep(response)}).`,\n );\n}\n\n/** One-cookie jar for the sealed `_zflow` flow-state cookie. */\nclass FlowCookieJar {\n private cookie: string | undefined;\n\n absorb(response: Response): void {\n for (const raw of response.headers.getSetCookie()) {\n const [pair] = raw.split(\";\", 1);\n if (pair?.startsWith(\"_zflow=\")) {\n this.cookie = pair;\n }\n }\n }\n\n header(): Record<string, string> {\n return this.cookie ? { cookie: this.cookie } : {};\n }\n}\n\nasync function flowFetch(\n handle: Pick<InstanceHandle, \"baseUrl\" | \"projectSecret\">,\n jar: FlowCookieJar,\n origin: string | undefined,\n path: string,\n body: Record<string, unknown>,\n): Promise<CreateFlow201> {\n const response = await fetch(`${handle.baseUrl}${path}`, {\n method: \"POST\",\n headers: {\n \"content-type\": \"application/json\",\n authorization: `Bearer ${handle.projectSecret}`,\n // The project's origin allowlist applies to flow calls; send the app\n // origin the way a browser request through the app would carry it.\n ...(origin ? { origin } : {}),\n ...jar.header(),\n },\n body: JSON.stringify(body),\n });\n jar.absorb(response);\n const parsed = (await response.json().catch(() => undefined)) as CreateFlow201 | undefined;\n if (!response.ok || !parsed) {\n const detail = parsed && typeof parsed === \"object\" ? ` — ${JSON.stringify(parsed)}` : \"\";\n // An origin-allowlist rejection without an Origin header is a\n // configuration gap, not a flow problem — say how to close it. (No eager\n // check: a project with an empty allowlist may accept originless calls.)\n const hint =\n !origin && /origin/i.test(detail)\n ? \"\\nNo Origin header was sent: pass `origin` to seedSession() (the Playwright \" +\n \"fixtures pass the suite's baseURL) or `appOrigins` to startLocalZitadel().\"\n : \"\";\n throw new Error(`seed.session: POST ${path} returned ${response.status}${detail}${hint}`);\n }\n return parsed;\n}\n\n/**\n * Fill exactly the fields the current step declares — the orchestrator's\n * convention — from the known email/password values. An unknown required\n * field means this flow needs more than a password login can provide.\n */\nfunction collectFields(\n response: CreateFlow201,\n values: Record<string, string>,\n): Record<string, string> {\n const fields: Record<string, string> = {};\n for (const field of response.step.fields ?? []) {\n const value = values[fieldKey(field)];\n if (value === undefined) {\n throw new Error(\n `seed.session supports password flows only; step ${describeStep(response)} ` +\n `declares field \"${field.name}\", which the kit cannot fill. ` +\n `Log in through the UI for flows with additional factors.`,\n );\n }\n fields[field.name] = value;\n }\n return fields;\n}\n\n/**\n * Steps name credential fields with schema pointers (e.g.\n * `x-auth-methods#password`); match on the trailing segment so the value map\n * stays the plain `{ email, password }` a caller thinks in.\n */\nfunction fieldKey(field: CreateFlow201StepFieldsItem): string {\n const name = field.name;\n const tail = name.split(/[#/.]/).at(-1) ?? name;\n return tail.toLowerCase();\n}\n\nfunction describeStep(response: CreateFlow201): string {\n const name = response.step.name ?? \"(unnamed)\";\n const declared = (response.step.fields ?? []).map((field) => field.name).join(\", \");\n return `\"${name}\"${declared ? ` [fields: ${declared}]` : \"\"}`;\n}\n","import { createZitadelClient } from \"@zitadel/api/client\";\n\nimport { applyAppEnvTemplate, nextAppEnv } from \"./app-env\";\nimport { bootstrapProject, type BootstrapProjectOptions } from \"./bootstrap\";\nimport { bootLocalServer, type BootServerOptions } from \"./lifecycle\";\nimport { identity, seedUser, seedUsers } from \"./seed\";\nimport { mintSession } from \"./session\";\nimport type { ConnectedZitadel, InstanceHandle, LocalZitadel } from \"./types\";\n\nexport type StartLocalZitadelOptions = BootServerOptions & Omit<BootstrapProjectOptions, \"baseUrl\">;\n\n/**\n * Attach to an already-bootstrapped instance/project. Lifecycle-free on\n * purpose: this is the entry point for Playwright workers (via the handshake\n * file) and, later, for seeding remote instances.\n */\nexport function connectZitadel(handle: InstanceHandle): ConnectedZitadel {\n const api = createZitadelClient({ baseUrl: handle.baseUrl, token: handle.projectSecret });\n const context = { projectId: handle.projectId, schemaId: handle.schemaId };\n const connected: ConnectedZitadel = {\n handle,\n api,\n // The Next-shaped convenience view; other frameworks apply their own\n // template to `handle` (see AppEnvTemplate).\n appEnv: applyAppEnvTemplate(nextAppEnv, handle),\n seedUser: (input) => seedUser(api, context, input),\n seedUsers: (count, template) => seedUsers(api, context, count, template),\n identity,\n seedSession: async (input = {}) => {\n const { user: existing, flowDefinitionName, origin, ...userInput } = input;\n const user = existing ?? (await seedUser(api, context, userInput));\n return mintSession(api, handle, context, user, {\n flowDefinitionName,\n origin: origin ?? handle.appOrigin,\n });\n },\n };\n return connected;\n}\n\n/**\n * Boot an ephemeral local instance (binary runtime + SQLite by default, no\n * Docker) and bootstrap a project + default schema + login flow on it. The\n * result can seed loginable password users immediately.\n */\nexport async function startLocalZitadel(\n options: StartLocalZitadelOptions = {},\n): Promise<LocalZitadel> {\n const server = await bootLocalServer(options);\n let bootstrapped: Awaited<ReturnType<typeof bootstrapProject>>;\n try {\n bootstrapped = await bootstrapProject({\n baseUrl: server.baseUrl,\n projectName: options.projectName,\n appOrigins: options.appOrigins,\n preset: options.preset,\n useCase: options.useCase,\n });\n } catch (error) {\n try {\n await server.stop();\n } catch (stopError) {\n // Both errors are preserved in AggregateError.errors, which the rule\n // below cannot model.\n throw new AggregateError(\n [error, stopError],\n \"bootstrap failed, and stopping the booted instance also failed\",\n );\n }\n throw error;\n }\n const handle: InstanceHandle = {\n baseUrl: server.baseUrl,\n projectId: bootstrapped.projectId,\n projectSecret: bootstrapped.projectSecret,\n schemaId: bootstrapped.schemaId,\n previewSecret: bootstrapped.previewSecret,\n appOrigin: options.appOrigins?.[0],\n };\n return {\n ...connectZitadel(handle),\n runtime: server.runtime,\n stop: server.stop,\n [Symbol.asyncDispose]: server.stop,\n };\n}\n\nexport { applyAppEnvTemplate, nextAppEnv } from \"./app-env\";\nexport type { AppEnvTemplate } from \"./app-env\";\nexport { bootstrapProject } from \"./bootstrap\";\nexport type { BootstrapProjectOptions, BootstrappedProject } from \"./bootstrap\";\nexport { readHandshakeSync, waitForHandshake, writeHandshake } from \"./handshake\";\nexport { bootLocalServer } from \"./lifecycle\";\nexport type { BootedServer, BootServerOptions } from \"./lifecycle\";\nexport { identity } from \"./seed\";\nexport { SESSION_COOKIE_NAME, sessionCookieName } from \"./session\";\nexport type {\n ConnectedZitadel,\n Identity,\n InstanceHandle,\n LocalZitadel,\n LocalZitadelRuntime,\n MintedSession,\n PlatformCredentials,\n SeededUser,\n SeedSessionInput,\n SeedUserInput,\n SeedUsersTemplate,\n SessionCookie,\n} from \"./types\";\n"],"mappings":";;;;;;;;;;;AA6BA,MAAM,uBAAuB;;;;;;;AAQ7B,eAAsB,iBACpB,SAC8B;CAC9B,MAAM,EAAE,YAAY;CAEpB,MAAM,UAAW,MADO,oBAAoB,EAAE,QAAQ,CACjB,CAAC,CAAC,cAAc;EACnD,MAAM,QAAQ,eAAe;EAC7B,UAAU,QAAQ,cAAc,CAAC,EAAA,CAAG,KAAK,aAAa;GACpD;GACA,MAAM;EACR,EAAE;EACF,eAAe;CACjB,CAAkD;CAClD,MAAM,YAAY,cAAc,QAAQ,IAAI,YAAY;CACxD,MAAM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SAAS,MAAM;IAC7C;IACA,QAAQ,UAAU,OAAO;GAC3B,CAAC;EACH;CAEa;AACjB;;;;;;AAOA,eAAsB,kBACpB,UAAoC,CAAC,GACd;CACvB,MAAM,SAAS,MAAM,gBAAgB,OAAO;CAC5C,IAAI;CACJ,IAAI;EACF,eAAe,MAAM,iBAAiB;GACpC,SAAS,OAAO;GAChB,aAAa,QAAQ;GACrB,YAAY,QAAQ;GACpB,QAAQ,QAAQ;GAChB,SAAS,QAAQ;EACnB,CAAC;CACH,SAAS,OAAO;EACd,IAAI;GACF,MAAM,OAAO,KAAK;EACpB,SAAS,WAAW;GAGlB,MAAM,IAAI,eACR,CAAC,OAAO,SAAS,GACjB,gEACF;EACF;EACA,MAAM;CACR;CASA,OAAO;EACL,GAAG,eAAe;GARlB,SAAS,OAAO;GAChB,WAAW,aAAa;GACxB,eAAe,aAAa;GAC5B,UAAU,aAAa;GACvB,eAAe,aAAa;GAC5B,WAAW,QAAQ,aAAa;EAGT,CAAC;EACxB,SAAS,OAAO;EAChB,MAAM,OAAO;GACZ,OAAO,eAAe,OAAO;CAChC;AACF"}
@@ -1,6 +1,6 @@
1
- const require_src = require("./src-DirKLqi4.cjs");
2
- const require_handshake = require("./handshake-CRKcgkfN.cjs");
3
- const require_orchestration = require("./orchestration-D7QBgQ0l.cjs");
1
+ const require_src = require("./src-CUvV1OWp.cjs");
2
+ const require_handshake = require("./handshake-D6MXSUcd.cjs");
3
+ const require_orchestration = require("./orchestration-gIDANMcF.cjs");
4
4
  let node_fs_promises = require("node:fs/promises");
5
5
  //#region src/supervisor.ts
6
6
  /**
@@ -1 +1 @@
1
- {"version":3,"file":"supervisor.cjs","names":["parseSupervisorConfig","SUPERVISOR_CONFIG_ENV","requireHandshakePath","startLocalZitadel","writeHandshake"],"sources":["../src/supervisor.ts"],"sourcesContent":["/**\n * Playwright webServer entry generated by `withZitadel()`: boots an ephemeral\n * seeded Zitadel and writes the handshake file that the app runner and the\n * test fixtures read. Stays in the foreground; SIGTERM/SIGINT stop the\n * instance. Configuration arrives as JSON in ZITADEL_TESTING_SUPERVISOR.\n */\nimport { access, rm } from \"node:fs/promises\";\n\nimport { writeHandshake } from \"./handshake\";\nimport { startLocalZitadel } from \"./index\";\nimport { parseSupervisorConfig, requireHandshakePath, SUPERVISOR_CONFIG_ENV } from \"./orchestration\";\nimport type { LocalZitadel } from \"./types\";\n\nconst LOG = \"[zitadel-testing]\";\n\nasync function main(): Promise<void> {\n const config = parseSupervisorConfig(process.env[SUPERVISOR_CONFIG_ENV]);\n const handshakePath = requireHandshakePath(process.env);\n\n if (config.serverBinary) {\n // In-repo platform packages ship no binary; fail fast with the fix.\n await access(config.serverBinary).catch(() => {\n console.error(\n `${LOG} server binary not found at ${config.serverBinary}` +\n (config.serverBinaryHint ? ` — ${config.serverBinaryHint}` : \"\"),\n );\n process.exit(1);\n });\n }\n\n // Signal handlers close over this binding before the asynchronous boot\n // assigns it.\n // oxlint-disable-next-line prefer-const\n let zitadel: LocalZitadel | undefined;\n let signalled = false;\n let finishing: Promise<void> | undefined;\n\n const finish = (code: number): Promise<void> => {\n finishing ??= (async () => {\n let exitCode = code;\n try {\n await zitadel?.stop();\n } catch (error) {\n console.error(`${LOG} stop failed: ${(error as Error).message}`);\n exitCode = 1;\n }\n await rm(handshakePath, { force: true }).catch(() => undefined);\n process.exit(exitCode);\n })();\n return finishing;\n };\n\n // Handlers are installed before the boot so a cancellation arriving while\n // the instance comes up (or before the handshake is written) still tears it\n // down.\n const onSignal = (signal: NodeJS.Signals): void => {\n signalled = true;\n console.log(\n `${LOG} ${signal} received${zitadel ? \", stopping instance\" : \" during boot; stopping once ready\"}`,\n );\n if (zitadel) {\n void finish(0);\n }\n };\n process.on(\"SIGTERM\", onSignal);\n process.on(\"SIGINT\", onSignal);\n\n await rm(handshakePath, { force: true });\n\n zitadel = await startLocalZitadel({\n port: config.port,\n appOrigins: config.appOrigins,\n serverBinary: config.serverBinary,\n dir: config.dir,\n keep: config.keep,\n projectName: config.projectName,\n preset: config.preset,\n useCase: config.useCase,\n timeoutMs: config.timeoutMs,\n });\n if (signalled) {\n await finish(0);\n return;\n }\n\n try {\n await writeHandshake(handshakePath, zitadel.handle);\n } catch (error) {\n console.error(`${LOG} failed to write handshake: ${(error as Error).message}`);\n await finish(1);\n return;\n }\n console.log(\n `${LOG} instance ready at ${zitadel.handle.baseUrl} (project ${zitadel.handle.projectId})`,\n );\n\n setInterval(() => {\n /* keep the event loop alive; Playwright owns this process's lifetime */\n }, 60_000);\n}\n\nmain().catch((error: unknown) => {\n console.error(`${LOG} ${error instanceof Error ? error.message : String(error)}`);\n process.exit(1);\n});\n"],"mappings":";;;;;;;;;;;AAaA,MAAM,MAAM;AAEZ,eAAe,OAAsB;CACnC,MAAM,SAASA,sBAAAA,sBAAsB,QAAQ,IAAIC,sBAAAA,uBAAuB;CACxE,MAAM,gBAAgBC,sBAAAA,qBAAqB,QAAQ,IAAI;AAEvD,KAAI,OAAO,aAET,QAAA,GAAA,iBAAA,QAAa,OAAO,aAAa,CAAC,YAAY;AAC5C,UAAQ,MACN,GAAG,IAAI,8BAA8B,OAAO,kBACzC,OAAO,mBAAmB,MAAM,OAAO,qBAAqB,IAChE;AACD,UAAQ,KAAK,EAAE;GACf;CAMJ,IAAI;CACJ,IAAI,YAAY;CAChB,IAAI;CAEJ,MAAM,UAAU,SAAgC;AAC9C,iBAAe,YAAY;GACzB,IAAI,WAAW;AACf,OAAI;AACF,UAAM,SAAS,MAAM;YACd,OAAO;AACd,YAAQ,MAAM,GAAG,IAAI,gBAAiB,MAAgB,UAAU;AAChE,eAAW;;AAEb,UAAA,GAAA,iBAAA,IAAS,eAAe,EAAE,OAAO,MAAM,CAAC,CAAC,YAAY,KAAA,EAAU;AAC/D,WAAQ,KAAK,SAAS;MACpB;AACJ,SAAO;;CAMT,MAAM,YAAY,WAAiC;AACjD,cAAY;AACZ,UAAQ,IACN,GAAG,IAAI,GAAG,OAAO,WAAW,UAAU,wBAAwB,sCAC/D;AACD,MAAI,QACG,QAAO,EAAE;;AAGlB,SAAQ,GAAG,WAAW,SAAS;AAC/B,SAAQ,GAAG,UAAU,SAAS;AAE9B,QAAA,GAAA,iBAAA,IAAS,eAAe,EAAE,OAAO,MAAM,CAAC;AAExC,WAAU,MAAMC,YAAAA,kBAAkB;EAChC,MAAM,OAAO;EACb,YAAY,OAAO;EACnB,cAAc,OAAO;EACrB,KAAK,OAAO;EACZ,MAAM,OAAO;EACb,aAAa,OAAO;EACpB,QAAQ,OAAO;EACf,SAAS,OAAO;EAChB,WAAW,OAAO;EACnB,CAAC;AACF,KAAI,WAAW;AACb,QAAM,OAAO,EAAE;AACf;;AAGF,KAAI;AACF,QAAMC,kBAAAA,eAAe,eAAe,QAAQ,OAAO;UAC5C,OAAO;AACd,UAAQ,MAAM,GAAG,IAAI,8BAA+B,MAAgB,UAAU;AAC9E,QAAM,OAAO,EAAE;AACf;;AAEF,SAAQ,IACN,GAAG,IAAI,qBAAqB,QAAQ,OAAO,QAAQ,YAAY,QAAQ,OAAO,UAAU,GACzF;AAED,mBAAkB,IAEf,IAAO;;AAGZ,MAAM,CAAC,OAAO,UAAmB;AAC/B,SAAQ,MAAM,GAAG,IAAI,GAAG,iBAAiB,QAAQ,MAAM,UAAU,OAAO,MAAM,GAAG;AACjF,SAAQ,KAAK,EAAE;EACf"}
1
+ {"version":3,"file":"supervisor.cjs","names":["parseSupervisorConfig","SUPERVISOR_CONFIG_ENV","requireHandshakePath","access","rm","startLocalZitadel","writeHandshake"],"sources":["../src/supervisor.ts"],"sourcesContent":["/**\n * Playwright webServer entry generated by `withZitadel()`: boots an ephemeral\n * seeded Zitadel and writes the handshake file that the app runner and the\n * test fixtures read. Stays in the foreground; SIGTERM/SIGINT stop the\n * instance. Configuration arrives as JSON in ZITADEL_TESTING_SUPERVISOR.\n */\nimport { access, rm } from \"node:fs/promises\";\n\nimport { writeHandshake } from \"./handshake\";\nimport { startLocalZitadel } from \"./index\";\nimport {\n parseSupervisorConfig,\n requireHandshakePath,\n SUPERVISOR_CONFIG_ENV,\n} from \"./orchestration\";\nimport type { LocalZitadel } from \"./types\";\n\nconst LOG = \"[zitadel-testing]\";\n\nasync function main(): Promise<void> {\n const config = parseSupervisorConfig(process.env[SUPERVISOR_CONFIG_ENV]);\n const handshakePath = requireHandshakePath(process.env);\n\n if (config.serverBinary) {\n // In-repo platform packages ship no binary; fail fast with the fix.\n await access(config.serverBinary).catch(() => {\n console.error(\n `${LOG} server binary not found at ${config.serverBinary}` +\n (config.serverBinaryHint ? ` — ${config.serverBinaryHint}` : \"\"),\n );\n process.exit(1);\n });\n }\n\n // Signal handlers close over this binding before the asynchronous boot\n // assigns it.\n let zitadel: LocalZitadel | undefined;\n let signalled = false;\n let finishing: Promise<void> | undefined;\n\n const finish = (code: number): Promise<void> => {\n finishing ??= (async () => {\n let exitCode = code;\n try {\n await zitadel?.stop();\n } catch (error) {\n console.error(`${LOG} stop failed: ${(error as Error).message}`);\n exitCode = 1;\n }\n await rm(handshakePath, { force: true }).catch(() => undefined);\n process.exit(exitCode);\n })();\n return finishing;\n };\n\n // Handlers are installed before the boot so a cancellation arriving while\n // the instance comes up (or before the handshake is written) still tears it\n // down.\n const onSignal = (signal: NodeJS.Signals): void => {\n signalled = true;\n console.log(\n `${LOG} ${signal} received${zitadel ? \", stopping instance\" : \" during boot; stopping once ready\"}`,\n );\n if (zitadel) {\n void finish(0);\n }\n };\n process.on(\"SIGTERM\", onSignal);\n process.on(\"SIGINT\", onSignal);\n\n await rm(handshakePath, { force: true });\n\n zitadel = await startLocalZitadel({\n port: config.port,\n appOrigins: config.appOrigins,\n serverBinary: config.serverBinary,\n dir: config.dir,\n keep: config.keep,\n projectName: config.projectName,\n preset: config.preset,\n useCase: config.useCase,\n timeoutMs: config.timeoutMs,\n });\n if (signalled) {\n await finish(0);\n return;\n }\n\n try {\n await writeHandshake(handshakePath, zitadel.handle);\n } catch (error) {\n console.error(`${LOG} failed to write handshake: ${(error as Error).message}`);\n await finish(1);\n return;\n }\n console.log(\n `${LOG} instance ready at ${zitadel.handle.baseUrl} (project ${zitadel.handle.projectId})`,\n );\n\n setInterval(() => {\n /* keep the event loop alive; Playwright owns this process's lifetime */\n }, 60_000);\n}\n\nmain().catch((error: unknown) => {\n console.error(`${LOG} ${error instanceof Error ? error.message : String(error)}`);\n process.exit(1);\n});\n"],"mappings":";;;;;;;;;;;AAiBA,MAAM,MAAM;AAEZ,eAAe,OAAsB;CACnC,MAAM,SAASA,sBAAAA,sBAAsB,QAAQ,IAAIC,sBAAAA,sBAAsB;CACvE,MAAM,gBAAgBC,sBAAAA,qBAAqB,QAAQ,GAAG;CAEtD,IAAI,OAAO,cAET,OAAA,GAAMC,iBAAAA,OAAAA,CAAO,OAAO,YAAY,CAAC,CAAC,YAAY;EAC5C,QAAQ,MACN,GAAG,IAAI,8BAA8B,OAAO,kBACzC,OAAO,mBAAmB,MAAM,OAAO,qBAAqB,GACjE;EACA,QAAQ,KAAK,CAAC;CAChB,CAAC;CAKH,IAAI;CACJ,IAAI,YAAY;CAChB,IAAI;CAEJ,MAAM,UAAU,SAAgC;EAC9C,eAAe,YAAY;GACzB,IAAI,WAAW;GACf,IAAI;IACF,MAAM,SAAS,KAAK;GACtB,SAAS,OAAO;IACd,QAAQ,MAAM,GAAG,IAAI,gBAAiB,MAAgB,SAAS;IAC/D,WAAW;GACb;GACA,OAAA,GAAMC,iBAAAA,GAAAA,CAAG,eAAe,EAAE,OAAO,KAAK,CAAC,CAAC,CAAC,YAAY,KAAA,CAAS;GAC9D,QAAQ,KAAK,QAAQ;EACvB,EAAA,CAAG;EACH,OAAO;CACT;CAKA,MAAM,YAAY,WAAiC;EACjD,YAAY;EACZ,QAAQ,IACN,GAAG,IAAI,GAAG,OAAO,WAAW,UAAU,wBAAwB,qCAChE;EACA,IAAI,SACF,OAAY,CAAC;CAEjB;CACA,QAAQ,GAAG,WAAW,QAAQ;CAC9B,QAAQ,GAAG,UAAU,QAAQ;CAE7B,OAAA,GAAMA,iBAAAA,GAAAA,CAAG,eAAe,EAAE,OAAO,KAAK,CAAC;CAEvC,UAAU,MAAMC,YAAAA,kBAAkB;EAChC,MAAM,OAAO;EACb,YAAY,OAAO;EACnB,cAAc,OAAO;EACrB,KAAK,OAAO;EACZ,MAAM,OAAO;EACb,aAAa,OAAO;EACpB,QAAQ,OAAO;EACf,SAAS,OAAO;EAChB,WAAW,OAAO;CACpB,CAAC;CACD,IAAI,WAAW;EACb,MAAM,OAAO,CAAC;EACd;CACF;CAEA,IAAI;EACF,MAAMC,kBAAAA,eAAe,eAAe,QAAQ,MAAM;CACpD,SAAS,OAAO;EACd,QAAQ,MAAM,GAAG,IAAI,8BAA+B,MAAgB,SAAS;EAC7E,MAAM,OAAO,CAAC;EACd;CACF;CACA,QAAQ,IACN,GAAG,IAAI,qBAAqB,QAAQ,OAAO,QAAQ,YAAY,QAAQ,OAAO,UAAU,EAC1F;CAEA,kBAAkB,CAElB,GAAG,GAAM;AACX;AAEA,KAAK,CAAC,CAAC,OAAO,UAAmB;CAC/B,QAAQ,MAAM,GAAG,IAAI,GAAG,iBAAiB,QAAQ,MAAM,UAAU,OAAO,KAAK,GAAG;CAChF,QAAQ,KAAK,CAAC;AAChB,CAAC"}
@@ -1 +1 @@
1
- export { };
1
+ export {}
@@ -1,6 +1,6 @@
1
- import { r as writeHandshake } from "./handshake-ClzWvG8z.mjs";
2
- import { n as startLocalZitadel } from "./src-eTcdx-ZS.mjs";
3
- import { a as parseSupervisorConfig, o as requireHandshakePath, r as SUPERVISOR_CONFIG_ENV } from "./orchestration-C640_1Lg.mjs";
1
+ import { r as writeHandshake } from "./handshake-CwlxMjW0.mjs";
2
+ import { n as startLocalZitadel } from "./src-DKJ1hMV8.mjs";
3
+ import { a as parseSupervisorConfig, o as requireHandshakePath, r as SUPERVISOR_CONFIG_ENV } from "./orchestration-Clldecyr.mjs";
4
4
  import { access, rm } from "node:fs/promises";
5
5
  //#region src/supervisor.ts
6
6
  /**
@@ -1 +1 @@
1
- {"version":3,"file":"supervisor.mjs","names":[],"sources":["../src/supervisor.ts"],"sourcesContent":["/**\n * Playwright webServer entry generated by `withZitadel()`: boots an ephemeral\n * seeded Zitadel and writes the handshake file that the app runner and the\n * test fixtures read. Stays in the foreground; SIGTERM/SIGINT stop the\n * instance. Configuration arrives as JSON in ZITADEL_TESTING_SUPERVISOR.\n */\nimport { access, rm } from \"node:fs/promises\";\n\nimport { writeHandshake } from \"./handshake\";\nimport { startLocalZitadel } from \"./index\";\nimport { parseSupervisorConfig, requireHandshakePath, SUPERVISOR_CONFIG_ENV } from \"./orchestration\";\nimport type { LocalZitadel } from \"./types\";\n\nconst LOG = \"[zitadel-testing]\";\n\nasync function main(): Promise<void> {\n const config = parseSupervisorConfig(process.env[SUPERVISOR_CONFIG_ENV]);\n const handshakePath = requireHandshakePath(process.env);\n\n if (config.serverBinary) {\n // In-repo platform packages ship no binary; fail fast with the fix.\n await access(config.serverBinary).catch(() => {\n console.error(\n `${LOG} server binary not found at ${config.serverBinary}` +\n (config.serverBinaryHint ? ` — ${config.serverBinaryHint}` : \"\"),\n );\n process.exit(1);\n });\n }\n\n // Signal handlers close over this binding before the asynchronous boot\n // assigns it.\n // oxlint-disable-next-line prefer-const\n let zitadel: LocalZitadel | undefined;\n let signalled = false;\n let finishing: Promise<void> | undefined;\n\n const finish = (code: number): Promise<void> => {\n finishing ??= (async () => {\n let exitCode = code;\n try {\n await zitadel?.stop();\n } catch (error) {\n console.error(`${LOG} stop failed: ${(error as Error).message}`);\n exitCode = 1;\n }\n await rm(handshakePath, { force: true }).catch(() => undefined);\n process.exit(exitCode);\n })();\n return finishing;\n };\n\n // Handlers are installed before the boot so a cancellation arriving while\n // the instance comes up (or before the handshake is written) still tears it\n // down.\n const onSignal = (signal: NodeJS.Signals): void => {\n signalled = true;\n console.log(\n `${LOG} ${signal} received${zitadel ? \", stopping instance\" : \" during boot; stopping once ready\"}`,\n );\n if (zitadel) {\n void finish(0);\n }\n };\n process.on(\"SIGTERM\", onSignal);\n process.on(\"SIGINT\", onSignal);\n\n await rm(handshakePath, { force: true });\n\n zitadel = await startLocalZitadel({\n port: config.port,\n appOrigins: config.appOrigins,\n serverBinary: config.serverBinary,\n dir: config.dir,\n keep: config.keep,\n projectName: config.projectName,\n preset: config.preset,\n useCase: config.useCase,\n timeoutMs: config.timeoutMs,\n });\n if (signalled) {\n await finish(0);\n return;\n }\n\n try {\n await writeHandshake(handshakePath, zitadel.handle);\n } catch (error) {\n console.error(`${LOG} failed to write handshake: ${(error as Error).message}`);\n await finish(1);\n return;\n }\n console.log(\n `${LOG} instance ready at ${zitadel.handle.baseUrl} (project ${zitadel.handle.projectId})`,\n );\n\n setInterval(() => {\n /* keep the event loop alive; Playwright owns this process's lifetime */\n }, 60_000);\n}\n\nmain().catch((error: unknown) => {\n console.error(`${LOG} ${error instanceof Error ? error.message : String(error)}`);\n process.exit(1);\n});\n"],"mappings":";;;;;;;;;;;AAaA,MAAM,MAAM;AAEZ,eAAe,OAAsB;CACnC,MAAM,SAAS,sBAAsB,QAAQ,IAAI,uBAAuB;CACxE,MAAM,gBAAgB,qBAAqB,QAAQ,IAAI;AAEvD,KAAI,OAAO,aAET,OAAM,OAAO,OAAO,aAAa,CAAC,YAAY;AAC5C,UAAQ,MACN,GAAG,IAAI,8BAA8B,OAAO,kBACzC,OAAO,mBAAmB,MAAM,OAAO,qBAAqB,IAChE;AACD,UAAQ,KAAK,EAAE;GACf;CAMJ,IAAI;CACJ,IAAI,YAAY;CAChB,IAAI;CAEJ,MAAM,UAAU,SAAgC;AAC9C,iBAAe,YAAY;GACzB,IAAI,WAAW;AACf,OAAI;AACF,UAAM,SAAS,MAAM;YACd,OAAO;AACd,YAAQ,MAAM,GAAG,IAAI,gBAAiB,MAAgB,UAAU;AAChE,eAAW;;AAEb,SAAM,GAAG,eAAe,EAAE,OAAO,MAAM,CAAC,CAAC,YAAY,KAAA,EAAU;AAC/D,WAAQ,KAAK,SAAS;MACpB;AACJ,SAAO;;CAMT,MAAM,YAAY,WAAiC;AACjD,cAAY;AACZ,UAAQ,IACN,GAAG,IAAI,GAAG,OAAO,WAAW,UAAU,wBAAwB,sCAC/D;AACD,MAAI,QACG,QAAO,EAAE;;AAGlB,SAAQ,GAAG,WAAW,SAAS;AAC/B,SAAQ,GAAG,UAAU,SAAS;AAE9B,OAAM,GAAG,eAAe,EAAE,OAAO,MAAM,CAAC;AAExC,WAAU,MAAM,kBAAkB;EAChC,MAAM,OAAO;EACb,YAAY,OAAO;EACnB,cAAc,OAAO;EACrB,KAAK,OAAO;EACZ,MAAM,OAAO;EACb,aAAa,OAAO;EACpB,QAAQ,OAAO;EACf,SAAS,OAAO;EAChB,WAAW,OAAO;EACnB,CAAC;AACF,KAAI,WAAW;AACb,QAAM,OAAO,EAAE;AACf;;AAGF,KAAI;AACF,QAAM,eAAe,eAAe,QAAQ,OAAO;UAC5C,OAAO;AACd,UAAQ,MAAM,GAAG,IAAI,8BAA+B,MAAgB,UAAU;AAC9E,QAAM,OAAO,EAAE;AACf;;AAEF,SAAQ,IACN,GAAG,IAAI,qBAAqB,QAAQ,OAAO,QAAQ,YAAY,QAAQ,OAAO,UAAU,GACzF;AAED,mBAAkB,IAEf,IAAO;;AAGZ,MAAM,CAAC,OAAO,UAAmB;AAC/B,SAAQ,MAAM,GAAG,IAAI,GAAG,iBAAiB,QAAQ,MAAM,UAAU,OAAO,MAAM,GAAG;AACjF,SAAQ,KAAK,EAAE;EACf"}
1
+ {"version":3,"file":"supervisor.mjs","names":[],"sources":["../src/supervisor.ts"],"sourcesContent":["/**\n * Playwright webServer entry generated by `withZitadel()`: boots an ephemeral\n * seeded Zitadel and writes the handshake file that the app runner and the\n * test fixtures read. Stays in the foreground; SIGTERM/SIGINT stop the\n * instance. Configuration arrives as JSON in ZITADEL_TESTING_SUPERVISOR.\n */\nimport { access, rm } from \"node:fs/promises\";\n\nimport { writeHandshake } from \"./handshake\";\nimport { startLocalZitadel } from \"./index\";\nimport {\n parseSupervisorConfig,\n requireHandshakePath,\n SUPERVISOR_CONFIG_ENV,\n} from \"./orchestration\";\nimport type { LocalZitadel } from \"./types\";\n\nconst LOG = \"[zitadel-testing]\";\n\nasync function main(): Promise<void> {\n const config = parseSupervisorConfig(process.env[SUPERVISOR_CONFIG_ENV]);\n const handshakePath = requireHandshakePath(process.env);\n\n if (config.serverBinary) {\n // In-repo platform packages ship no binary; fail fast with the fix.\n await access(config.serverBinary).catch(() => {\n console.error(\n `${LOG} server binary not found at ${config.serverBinary}` +\n (config.serverBinaryHint ? ` — ${config.serverBinaryHint}` : \"\"),\n );\n process.exit(1);\n });\n }\n\n // Signal handlers close over this binding before the asynchronous boot\n // assigns it.\n let zitadel: LocalZitadel | undefined;\n let signalled = false;\n let finishing: Promise<void> | undefined;\n\n const finish = (code: number): Promise<void> => {\n finishing ??= (async () => {\n let exitCode = code;\n try {\n await zitadel?.stop();\n } catch (error) {\n console.error(`${LOG} stop failed: ${(error as Error).message}`);\n exitCode = 1;\n }\n await rm(handshakePath, { force: true }).catch(() => undefined);\n process.exit(exitCode);\n })();\n return finishing;\n };\n\n // Handlers are installed before the boot so a cancellation arriving while\n // the instance comes up (or before the handshake is written) still tears it\n // down.\n const onSignal = (signal: NodeJS.Signals): void => {\n signalled = true;\n console.log(\n `${LOG} ${signal} received${zitadel ? \", stopping instance\" : \" during boot; stopping once ready\"}`,\n );\n if (zitadel) {\n void finish(0);\n }\n };\n process.on(\"SIGTERM\", onSignal);\n process.on(\"SIGINT\", onSignal);\n\n await rm(handshakePath, { force: true });\n\n zitadel = await startLocalZitadel({\n port: config.port,\n appOrigins: config.appOrigins,\n serverBinary: config.serverBinary,\n dir: config.dir,\n keep: config.keep,\n projectName: config.projectName,\n preset: config.preset,\n useCase: config.useCase,\n timeoutMs: config.timeoutMs,\n });\n if (signalled) {\n await finish(0);\n return;\n }\n\n try {\n await writeHandshake(handshakePath, zitadel.handle);\n } catch (error) {\n console.error(`${LOG} failed to write handshake: ${(error as Error).message}`);\n await finish(1);\n return;\n }\n console.log(\n `${LOG} instance ready at ${zitadel.handle.baseUrl} (project ${zitadel.handle.projectId})`,\n );\n\n setInterval(() => {\n /* keep the event loop alive; Playwright owns this process's lifetime */\n }, 60_000);\n}\n\nmain().catch((error: unknown) => {\n console.error(`${LOG} ${error instanceof Error ? error.message : String(error)}`);\n process.exit(1);\n});\n"],"mappings":";;;;;;;;;;;AAiBA,MAAM,MAAM;AAEZ,eAAe,OAAsB;CACnC,MAAM,SAAS,sBAAsB,QAAQ,IAAI,sBAAsB;CACvE,MAAM,gBAAgB,qBAAqB,QAAQ,GAAG;CAEtD,IAAI,OAAO,cAET,MAAM,OAAO,OAAO,YAAY,CAAC,CAAC,YAAY;EAC5C,QAAQ,MACN,GAAG,IAAI,8BAA8B,OAAO,kBACzC,OAAO,mBAAmB,MAAM,OAAO,qBAAqB,GACjE;EACA,QAAQ,KAAK,CAAC;CAChB,CAAC;CAKH,IAAI;CACJ,IAAI,YAAY;CAChB,IAAI;CAEJ,MAAM,UAAU,SAAgC;EAC9C,eAAe,YAAY;GACzB,IAAI,WAAW;GACf,IAAI;IACF,MAAM,SAAS,KAAK;GACtB,SAAS,OAAO;IACd,QAAQ,MAAM,GAAG,IAAI,gBAAiB,MAAgB,SAAS;IAC/D,WAAW;GACb;GACA,MAAM,GAAG,eAAe,EAAE,OAAO,KAAK,CAAC,CAAC,CAAC,YAAY,KAAA,CAAS;GAC9D,QAAQ,KAAK,QAAQ;EACvB,EAAA,CAAG;EACH,OAAO;CACT;CAKA,MAAM,YAAY,WAAiC;EACjD,YAAY;EACZ,QAAQ,IACN,GAAG,IAAI,GAAG,OAAO,WAAW,UAAU,wBAAwB,qCAChE;EACA,IAAI,SACF,OAAY,CAAC;CAEjB;CACA,QAAQ,GAAG,WAAW,QAAQ;CAC9B,QAAQ,GAAG,UAAU,QAAQ;CAE7B,MAAM,GAAG,eAAe,EAAE,OAAO,KAAK,CAAC;CAEvC,UAAU,MAAM,kBAAkB;EAChC,MAAM,OAAO;EACb,YAAY,OAAO;EACnB,cAAc,OAAO;EACrB,KAAK,OAAO;EACZ,MAAM,OAAO;EACb,aAAa,OAAO;EACpB,QAAQ,OAAO;EACf,SAAS,OAAO;EAChB,WAAW,OAAO;CACpB,CAAC;CACD,IAAI,WAAW;EACb,MAAM,OAAO,CAAC;EACd;CACF;CAEA,IAAI;EACF,MAAM,eAAe,eAAe,QAAQ,MAAM;CACpD,SAAS,OAAO;EACd,QAAQ,MAAM,GAAG,IAAI,8BAA+B,MAAgB,SAAS;EAC7E,MAAM,OAAO,CAAC;EACd;CACF;CACA,QAAQ,IACN,GAAG,IAAI,qBAAqB,QAAQ,OAAO,QAAQ,YAAY,QAAQ,OAAO,UAAU,EAC1F;CAEA,kBAAkB,CAElB,GAAG,GAAM;AACX;AAEA,KAAK,CAAC,CAAC,OAAO,UAAmB;CAC/B,QAAQ,MAAM,GAAG,IAAI,GAAG,iBAAiB,QAAQ,MAAM,UAAU,OAAO,KAAK,GAAG;CAChF,QAAQ,KAAK,CAAC;AAChB,CAAC"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@zitadel/testing",
3
- "version": "0.1.0-alpha.18",
3
+ "version": "0.1.0",
4
4
  "description": "Test-kit for seeded ephemeral local Zitadel instances",
5
5
  "homepage": "https://github.com/zitadel/nextgen/tree/main/packages/testing#readme",
6
6
  "bugs": {
@@ -37,9 +37,9 @@
37
37
  "./package.json": "./package.json"
38
38
  },
39
39
  "dependencies": {
40
- "@zitadel/api": "0.1.0-alpha.18",
41
- "@zitadel/config": "0.1.0-alpha.18",
42
- "@zitadel/cli": "0.1.0-alpha.18"
40
+ "@zitadel/api": "0.1.0",
41
+ "@zitadel/cli": "0.1.0",
42
+ "@zitadel/config": "0.1.0"
43
43
  },
44
44
  "peerDependencies": {
45
45
  "@playwright/test": ">=1.60"
@@ -51,16 +51,20 @@
51
51
  },
52
52
  "devDependencies": {
53
53
  "@playwright/test": "^1.60.0",
54
+ "@types/node": "^24.19.1",
54
55
  "msw": "^2.14.6",
55
- "tsdown": "^0.21.10",
56
+ "tsdown": "^0.23.0",
56
57
  "tslib": "^2.8.1",
57
- "vitest": "^4.1.9"
58
+ "typescript": "^6.0.3",
59
+ "vitest": "^4.1.11"
58
60
  },
59
61
  "scripts": {
60
62
  "build": "tsdown",
61
- "typecheck": "tsc --build tsconfig.json",
63
+ "typecheck": "tsc --noEmit -p tsconfig.lib.json && tsc --noEmit -p tsconfig.spec.json",
62
64
  "test": "vitest run",
63
- "test:integration": "vitest run --config vitest.integration.config.ts",
64
- "lint": "oxlint ."
65
+ "test:all": "pnpm run test",
66
+ "test:integration": "ZITADEL_SERVER_BINARY=${ZITADEL_SERVER_BINARY-$PWD/../../dist/server/nextgen} NEXTGEN_SERVER_LOGIN_ENABLED=${NEXTGEN_SERVER_LOGIN_ENABLED-false} NEXTGEN_SERVER_CONSOLE_ENABLED=${NEXTGEN_SERVER_CONSOLE_ENABLED-false} vitest run --config vitest.integration.config.ts",
67
+ "lint": "biome check .",
68
+ "build-release": "node ../../scripts/release-clean.mjs local-dist && pnpm run build"
65
69
  }
66
70
  }
@@ -1,122 +0,0 @@
1
- import { ZitadelClient } from "@zitadel/api/client";
2
-
3
- //#region src/types.d.ts
4
- /**
5
- * Serializable description of a bootstrapped instance + project. This is the
6
- * contract that crosses process boundaries (boot script -> Playwright workers).
7
- */
8
- interface InstanceHandle {
9
- baseUrl: string;
10
- projectId: string;
11
- projectSecret: string;
12
- /**
13
- * First registered app origin. Flow submissions enforce the project's
14
- * origin allowlist, so headless drivers (seedSession) send it as the
15
- * Origin header the way a browser request through the app would.
16
- */
17
- appOrigin?: string;
18
- /**
19
- * Server-assigned id of the seeded user schema. User documents must
20
- * reference it via their `$schema` field, so seeding needs it alongside the
21
- * project credential.
22
- */
23
- schemaId: string;
24
- previewSecret?: string;
25
- }
26
- interface SeedUserInput {
27
- email?: string;
28
- password?: string;
29
- /** Extra schema-defined user properties merged into the create body. */
30
- attributes?: Record<string, unknown>;
31
- }
32
- interface SeededUser {
33
- id: string;
34
- email: string;
35
- password: string;
36
- }
37
- /** An unused identity: seeded nowhere, ready for registration-flow specs. */
38
- interface Identity {
39
- email: string;
40
- password: string;
41
- }
42
- /** Injectable mirror of the server's session cookie (session.go). */
43
- interface SessionCookie {
44
- name: string;
45
- value: string;
46
- httpOnly: boolean;
47
- secure: boolean;
48
- sameSite: "Lax";
49
- path: string;
50
- }
51
- interface MintedSession {
52
- user: SeededUser;
53
- /** Bearer for session management APIs (e.g. `GET /sessions/me`). */
54
- sessionToken: string;
55
- expiresAt: string;
56
- cookie: SessionCookie;
57
- }
58
- interface SeedSessionInput extends SeedUserInput {
59
- /** Mint for an existing user instead of seeding a fresh one. */
60
- user?: SeededUser;
61
- /** Specific flow definition; the project default when omitted. */
62
- flowDefinitionName?: string;
63
- /**
64
- * Origin header for the flow calls (must be on the project's allowlist).
65
- * Defaults to the handle's registered app origin; the Playwright fixtures
66
- * pass the suite's baseURL.
67
- */
68
- origin?: string;
69
- }
70
- interface SeedUsersTemplate {
71
- email?: (index: number) => string;
72
- password?: (index: number) => string;
73
- attributes?: (index: number) => Record<string, unknown>;
74
- }
75
- interface ConnectedZitadel {
76
- handle: InstanceHandle;
77
- /** Authenticated platform API client (bearer = project secret). */
78
- api: ZitadelClient;
79
- /** Env vars an SDK-based app needs to talk to this instance/project. */
80
- appEnv: Record<string, string>;
81
- seedUser(input?: SeedUserInput): Promise<SeededUser>;
82
- /** Batch-seed users; the template makes fixture data deterministic. */
83
- seedUsers(count: number, template?: SeedUsersTemplate): Promise<SeededUser[]>;
84
- /** A unique unused email+password — nothing is created on the instance. */
85
- identity(): Identity;
86
- /**
87
- * Seed (or take) a user and drive the real login flow headlessly to a
88
- * session: tests inject `cookie` to start authenticated, backend tests use
89
- * `sessionToken` directly. Password flows only.
90
- */
91
- seedSession(input?: SeedSessionInput): Promise<MintedSession>;
92
- }
93
- interface LocalZitadelRuntime {
94
- port: number;
95
- pid: number;
96
- /** State directory holding `.zitadel/local/` (data dir, logs, runtime.json). */
97
- dir: string;
98
- logPath: string;
99
- }
100
- interface LocalZitadel extends ConnectedZitadel, AsyncDisposable {
101
- runtime: LocalZitadelRuntime;
102
- stop(): Promise<void>;
103
- }
104
- //#endregion
105
- //#region src/app-env.d.ts
106
- /**
107
- * Declarative mapping from an app's env var names to InstanceHandle fields.
108
- * A template (not a function) so it can cross process boundaries: the
109
- * Playwright config serializes it into the app-runner's environment, where it
110
- * is applied to the handle read from the handshake file.
111
- */
112
- type AppEnvTemplate = Record<string, keyof InstanceHandle>;
113
- /**
114
- * The env shape `@zitadel/sdk-next` apps read. Other frameworks pass their own
115
- * template — the console maps the same handle fields to `VITE_*`/`CONSOLE_*`
116
- * names, for example.
117
- */
118
- declare const nextAppEnv: AppEnvTemplate;
119
- declare function applyAppEnvTemplate(template: AppEnvTemplate, handle: InstanceHandle): Record<string, string>;
120
- //#endregion
121
- export { Identity as a, LocalZitadelRuntime as c, SeedUserInput as d, SeedUsersTemplate as f, ConnectedZitadel as i, MintedSession as l, SessionCookie as m, applyAppEnvTemplate as n, InstanceHandle as o, SeededUser as p, nextAppEnv as r, LocalZitadel as s, AppEnvTemplate as t, SeedSessionInput as u };
122
- //# sourceMappingURL=app-env-D3W0GYhA.d.mts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"app-env-D3W0GYhA.d.mts","names":[],"sources":["../src/types.ts","../src/app-env.ts"],"mappings":";;;;;AAMA;;UAAiB,cAAA;EACf,OAAA;EACA,SAAA;EACA,aAAA;EAAA;;;;;EAMA,SAAA;EAUe;;;;;EAJf,QAAA;EACA,aAAA;AAAA;AAAA,UAGe,aAAA;EACf,KAAA;EACA,QAAA;EAKyB;EAHzB,UAAA,GAAa,MAAA;AAAA;AAAA,UAGE,UAAA;EACf,EAAA;EACA,KAAA;EACA,QAAA;AAAA;AAIF;AAAA,UAAiB,QAAA;EACf,KAAA;EACA,QAAA;AAAA;AAIF;AAAA,UAAiB,aAAA;EACf,IAAA;EACA,KAAA;EACA,QAAA;EACA,MAAA;EACA,QAAA;EACA,IAAA;AAAA;AAAA,UAGe,aAAA;EACf,IAAA,EAAM,UAAA;EAJF;EAMJ,YAAA;EACA,SAAA;EACA,MAAA,EAAQ,aAAA;AAAA;AAAA,UAGO,gBAAA,SAAyB,aAAA;EAPlC;EASN,IAAA,GAAO,UAAA;EANP;EAQA,kBAAA;EAPQ;;;AAGV;;EAUE,MAAA;AAAA;AAAA,UAGe,iBAAA;EACf,KAAA,IAAS,KAAA;EACT,QAAA,IAAY,KAAA;EACZ,UAAA,IAAc,KAAA,aAAkB,MAAA;AAAA;AAAA,UAGjB,gBAAA;EACf,MAAA,EAAQ,cAAA;EAPO;EASf,GAAA,EAAK,aAAA;;EAEL,MAAA,EAAQ,MAAA;EACR,QAAA,CAAS,KAAA,GAAQ,aAAA,GAAgB,OAAA,CAAQ,UAAA;EAXhC;EAaT,SAAA,CAAU,KAAA,UAAe,QAAA,GAAW,iBAAA,GAAoB,OAAA,CAAQ,UAAA;EAZpD;EAcZ,QAAA,IAAY,QAAA;EAbE;;;;AAGhB;EAgBE,WAAA,CAAY,KAAA,GAAQ,gBAAA,GAAmB,OAAA,CAAQ,aAAA;AAAA;AAAA,UAGhC,mBAAA;EACf,IAAA;EACA,GAAA;EAfiB;EAiBjB,GAAA;EACA,OAAA;AAAA;AAAA,UAGe,YAAA,SAAqB,gBAAA,EAAkB,eAAA;EACtD,OAAA,EAAS,mBAAA;EACT,IAAA,IAAQ,OAAA;AAAA;;;;;AAxGV;;;;KCEY,cAAA,GAAiB,MAAA,eAAqB,cAAA;;;;;;cAOrC,UAAA,EAAY,cAAA;AAAA,iBAMT,mBAAA,CACd,QAAA,EAAU,cAAA,EACV,MAAA,EAAQ,cAAA,GACP,MAAA"}
@@ -1 +0,0 @@
1
- {"version":3,"file":"handshake-CRKcgkfN.cjs","names":[],"sources":["../src/app-env.ts","../src/handshake.ts"],"sourcesContent":["import type { InstanceHandle } from \"./types\";\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, keyof InstanceHandle>;\n\n/**\n * The env shape `@zitadel/sdk-next` apps read. Other frameworks pass their own\n * template — the console maps the same handle fields to `VITE_*`/`CONSOLE_*`\n * names, for example.\n */\nexport const nextAppEnv: AppEnvTemplate = {\n ZITADEL_URL: \"baseUrl\",\n NEXT_PUBLIC_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 } 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 return handle as InstanceHandle;\n}\n"],"mappings":";;;;;;;;;;AAeA,MAAa,aAA6B;CACxC,aAAa;CACb,gCAAgC;CAChC,wBAAwB;CACzB;AAED,SAAgB,oBACd,UACA,QACwB;CACxB,MAAM,MAA8B,EAAE;AACtC,MAAK,MAAM,CAAC,MAAM,UAAU,OAAO,QAAQ,SAAS,EAAE;EACpD,MAAM,QAAQ,OAAO;AACrB,MAAI,OAAO,UAAU,YAAY,MAAM,WAAW,EAGhD,OAAM,IAAI,MACR,0BAA0B,KAAK,qBAAqB,MAAM,6CAC3D;AAEH,MAAI,QAAQ;;AAEd,QAAO;;;;;;;;;ACzBT,eAAsB,eAAe,MAAc,QAAuC;AACxF,QAAA,GAAA,iBAAA,QAAA,GAAA,UAAA,SAAoB,KAAK,EAAE,EAAE,WAAW,MAAM,CAAC;AAC/C,QAAA,GAAA,iBAAA,WAAgB,MAAM,GAAG,KAAK,UAAU,QAAQ,MAAM,EAAE,CAAC,KAAK,EAAE,MAAM,KAAO,CAAC;;AAGhF,SAAgB,kBAAkB,MAA8B;CAC9D,MAAM,YAAA,GAAA,QAAA,cAAwB,MAAM,OAAO;CAC3C,IAAI;AACJ,KAAI;AACF,UAAQ,KAAK,MAAM,SAAS;UACrB,OAAO;AACd,QAAM,IAAI,MAAM,kBAAkB,KAAK,0BAA2B,MAAgB,WAAW,EAC3F,OAAO,OACR,CAAC;;AAEJ,QAAO,eAAe,OAAO,KAAK;;AAGpC,eAAsB,iBAAiB,MAAc,YAAY,KAAiC;CAChG,MAAM,WAAW,KAAK,KAAK,GAAG;AAC9B,SACE,KAAI;AACF,SAAO,eAAe,KAAK,MAAM,OAAA,GAAA,iBAAA,UAAe,MAAM,OAAO,CAAC,EAAE,KAAK;UAC9D,OAAO;AACd,MAAI,KAAK,KAAK,IAAI,SAChB,OAAM,IAAI,MACR,sCAAsC,UAAU,MAAM,KAAK,IAAK,MAAgB,QAAQ,IACxF,EAAE,OAAO,OAAO,CACjB;AAEH,SAAA,GAAA,qBAAA,YAAY,IAAI;;;AAKtB,SAAS,eAAe,OAAgB,QAAgC;AACtE,KAAI,OAAO,UAAU,YAAY,UAAU,QAAQ,MAAM,QAAQ,MAAM,CACrE,OAAM,IAAI,MAAM,kBAAkB,OAAO,mBAAmB;CAE9D,MAAM,SAAS;AACf,MAAK,MAAM,SAAS;EAAC;EAAW;EAAa;EAAiB;EAAW,CACvE,KAAI,OAAO,OAAO,WAAW,YAAY,OAAO,OAAO,WAAW,EAChE,OAAM,IAAI,MAAM,kBAAkB,OAAO,eAAe,MAAM,GAAG;AAGrE,KAAI,CAAC,IAAI,SAAS,OAAO,QAAkB,CACzC,OAAM,IAAI,MAAM,kBAAkB,OAAO,8BAA8B,OAAO,UAAU;AAE1F,QAAO"}
@@ -1 +0,0 @@
1
- {"version":3,"file":"handshake-ClzWvG8z.mjs","names":["sleep"],"sources":["../src/app-env.ts","../src/handshake.ts"],"sourcesContent":["import type { InstanceHandle } from \"./types\";\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, keyof InstanceHandle>;\n\n/**\n * The env shape `@zitadel/sdk-next` apps read. Other frameworks pass their own\n * template — the console maps the same handle fields to `VITE_*`/`CONSOLE_*`\n * names, for example.\n */\nexport const nextAppEnv: AppEnvTemplate = {\n ZITADEL_URL: \"baseUrl\",\n NEXT_PUBLIC_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 } 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 return handle as InstanceHandle;\n}\n"],"mappings":";;;;;;;;;;AAeA,MAAa,aAA6B;CACxC,aAAa;CACb,gCAAgC;CAChC,wBAAwB;CACzB;AAED,SAAgB,oBACd,UACA,QACwB;CACxB,MAAM,MAA8B,EAAE;AACtC,MAAK,MAAM,CAAC,MAAM,UAAU,OAAO,QAAQ,SAAS,EAAE;EACpD,MAAM,QAAQ,OAAO;AACrB,MAAI,OAAO,UAAU,YAAY,MAAM,WAAW,EAGhD,OAAM,IAAI,MACR,0BAA0B,KAAK,qBAAqB,MAAM,6CAC3D;AAEH,MAAI,QAAQ;;AAEd,QAAO;;;;;;;;;ACzBT,eAAsB,eAAe,MAAc,QAAuC;AACxF,OAAM,MAAM,QAAQ,KAAK,EAAE,EAAE,WAAW,MAAM,CAAC;AAC/C,OAAM,UAAU,MAAM,GAAG,KAAK,UAAU,QAAQ,MAAM,EAAE,CAAC,KAAK,EAAE,MAAM,KAAO,CAAC;;AAGhF,SAAgB,kBAAkB,MAA8B;CAC9D,MAAM,WAAW,aAAa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