@zitadel/testing 1.0.0-alpha.23 → 1.0.0-alpha.25

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 (40) hide show
  1. package/README.md +6 -4
  2. package/dist/{app-env-DlrV_ePR.d.mts → app-env-CAfV3fk_.d.mts} +2 -3
  3. package/dist/app-env-CAfV3fk_.d.mts.map +1 -0
  4. package/dist/app-runner.cjs +4 -3
  5. package/dist/app-runner.cjs.map +1 -1
  6. package/dist/app-runner.d.mts +1 -1
  7. package/dist/app-runner.mjs +4 -3
  8. package/dist/app-runner.mjs.map +1 -1
  9. package/dist/{handshake-BnAPXC6s.mjs → handshake-BBrTG-5P.mjs} +1 -1
  10. package/dist/{handshake-BnAPXC6s.mjs.map → handshake-BBrTG-5P.mjs.map} +1 -1
  11. package/dist/{handshake-BOsVBPtn.cjs → handshake-Cds_mGAO.cjs} +1 -1
  12. package/dist/handshake-Cds_mGAO.cjs.map +1 -0
  13. package/dist/index.cjs +2 -2
  14. package/dist/index.d.mts +11 -12
  15. package/dist/index.d.mts.map +1 -1
  16. package/dist/index.mjs +2 -2
  17. package/dist/{orchestration-C640_1Lg.mjs → orchestration-Clldecyr.mjs} +1 -1
  18. package/dist/{orchestration-C640_1Lg.mjs.map → orchestration-Clldecyr.mjs.map} +1 -1
  19. package/dist/{orchestration-D7QBgQ0l.cjs → orchestration-gIDANMcF.cjs} +1 -1
  20. package/dist/{orchestration-D7QBgQ0l.cjs.map → orchestration-gIDANMcF.cjs.map} +1 -1
  21. package/dist/playwright.cjs +4 -4
  22. package/dist/playwright.cjs.map +1 -1
  23. package/dist/playwright.d.mts +37 -38
  24. package/dist/playwright.d.mts.map +1 -1
  25. package/dist/playwright.mjs +4 -4
  26. package/dist/playwright.mjs.map +1 -1
  27. package/dist/{src-CFX_ayWr.cjs → src-CXX_iT7z.cjs} +1147 -601
  28. package/dist/src-CXX_iT7z.cjs.map +1 -0
  29. package/dist/{src-Dkt0HHu8.mjs → src-DhQK55R7.mjs} +6 -9
  30. package/dist/src-DhQK55R7.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 +11 -9
  37. package/dist/app-env-DlrV_ePR.d.mts.map +0 -1
  38. package/dist/handshake-BOsVBPtn.cjs.map +0 -1
  39. package/dist/src-CFX_ayWr.cjs.map +0 -1
  40. package/dist/src-Dkt0HHu8.mjs.map +0 -1
@@ -1,4 +1,4 @@
1
- const require_handshake = require("./handshake-BOsVBPtn.cjs");
1
+ const require_handshake = require("./handshake-Cds_mGAO.cjs");
2
2
  require("node:fs");
3
3
  require("node:url");
4
4
  let node_fs_promises = require("node:fs/promises");
@@ -35,20 +35,55 @@ function getApiAuthToken() {
35
35
  function setApiAuthToken(token) {
36
36
  apiAuthToken = token;
37
37
  }
38
- //#endregion
39
- //#region ../api/dist/chunk-CfYAbeIz.mjs
40
- var __defProp = Object.defineProperty;
41
- var __exportAll = (all, no_symbols) => {
42
- let target = {};
43
- for (var name in all) __defProp(target, name, {
44
- get: all[name],
45
- enumerable: true
46
- });
47
- if (!no_symbols) __defProp(target, Symbol.toStringTag, { value: "Module" });
48
- return target;
49
- };
38
+ /**
39
+ * The CSRF token for the first-party browser surfaces (ADR 053 §5). A
40
+ * state-changing request that the `__nextgen_session` cookie authenticates must
41
+ * carry the session's token — `csrf_token` from `GET /sessions/me/csrf` — in the
42
+ * `X-Zitadel-CSRF` header. The app sets it once it has loaded its session;
43
+ * `runtime/fetch.ts` then adds the header to unsafe requests. Unset (every
44
+ * other caller), nothing is added.
45
+ *
46
+ * The token belongs to the server that issued it, so it is stored with that
47
+ * server's origin and only sent there: another client on the same page, with
48
+ * another base URL, never carries it to a different host. The origin defaults
49
+ * to the page's own, which is where a same-origin app's API lives; with no
50
+ * origin to go by (no page, or an unparsable request URL), nothing is sent.
51
+ *
52
+ * Unlike the bearer slot, the app sets this one rather than the client, so it
53
+ * lives on `globalThis` under a {@link Symbol.for} key, like the project slot in
54
+ * `config.ts`: a second copy of this module (an SDK pinning another version)
55
+ * must read the token the app's copy wrote.
56
+ */
57
+ const CSRF_SLOT = Symbol.for("@zitadel/api/auth:csrf");
58
+ function csrfSlot() {
59
+ const global = globalThis;
60
+ const existing = global[CSRF_SLOT];
61
+ if (existing) return existing;
62
+ const slot = {};
63
+ global[CSRF_SLOT] = slot;
64
+ return slot;
65
+ }
66
+ /** The token to send to `origin`, if it was issued there. */
67
+ function apiCsrfTokenFor(origin) {
68
+ const slot = csrfSlot();
69
+ return origin !== void 0 && slot.tokenOrigin === origin ? slot.token : void 0;
70
+ }
71
+ /** The rejection handler for a refusal from `origin`, if it was registered for it. */
72
+ function apiCsrfRejectionHandlerFor(origin) {
73
+ const slot = csrfSlot();
74
+ return origin !== void 0 && slot.handlerOrigin === origin ? slot.onRejected : void 0;
75
+ }
50
76
  //#endregion
51
77
  //#region ../api/dist/runtime/fetch.mjs
78
+ /** The header the session-bound CSRF token travels in (ADR 053 §5). */
79
+ const CSRF_HEADER = "X-Zitadel-CSRF";
80
+ const SAFE_METHODS = /* @__PURE__ */ new Set([
81
+ "GET",
82
+ "HEAD",
83
+ "OPTIONS"
84
+ ]);
85
+ /** The code the server answers a refused CSRF check with. */
86
+ const CSRF_INVALID = "auth.csrf_invalid";
52
87
  /**
53
88
  * Framework-neutral failure type the orval-generated client throws on
54
89
  * any non-2xx response. Carries the HTTP status, the parsed error body
@@ -73,39 +108,157 @@ var ApiError = class extends Error {
73
108
  }
74
109
  };
75
110
  /**
111
+ * Thrown when a request got no response at all: the connection was refused or
112
+ * reset, the host did not resolve, or the server accepted the connection but
113
+ * did not answer in time. The counterpart to {@link ApiError}, which is a
114
+ * response that came back with a failing status.
115
+ *
116
+ * `fetch` only rejects when no response arrived, so this is decided by the
117
+ * fact that it rejected, never by how a runtime words the failure. The
118
+ * runtime's own error stays on `cause` for debugging.
119
+ */
120
+ var NetworkError = class extends Error {
121
+ url;
122
+ /** `timeout` when a deadline cut the request off, `unreachable` otherwise. */
123
+ reason;
124
+ constructor(url, reason, message, options) {
125
+ super(message, options);
126
+ this.name = "NetworkError";
127
+ this.url = url;
128
+ this.reason = reason;
129
+ }
130
+ };
131
+ let requestPolicy = {};
132
+ function setRequestPolicy(policy) {
133
+ requestPolicy = policy;
134
+ }
135
+ /**
76
136
  * The orval `mutator` for the fetch client. Every generated operation
77
137
  * routes its request through this function instead of the global
78
138
  * `fetch`. We pin three concerns here so generated call sites stay
79
139
  * focused on the shape of one HTTP call:
80
140
  *
81
141
  * - bearer auth — read from `runtime/auth.ts` and attached automatically;
142
+ * - the CSRF header — the session-bound token from `runtime/auth.ts`, on
143
+ * unsafe methods to the origin it was issued for, when a first-party surface
144
+ * has set one; an unsafe request to that origin refused with
145
+ * `403 auth.csrf_invalid` asks the registered rejection handler for a fresh
146
+ * token and is retried once with it, only if the handler returns one (the
147
+ * session still belongs to the same person);
82
148
  * - non-2xx → throw — orval's stock client parses the body regardless
83
149
  * of status, so callers would have to inspect every response. Throw
84
150
  * `ApiError` on `!res.ok` so failures interrupt control flow;
85
151
  * - body parsing — return the parsed JSON typed as `T` (the operation's
86
152
  * return type, threaded through by orval), or `undefined` for the
87
- * spec's `204`/`205`/`304` no-body responses.
153
+ * spec's `204`/`205`/`304` no-body responses;
154
+ * - no response → throw {@link NetworkError}, or the abort reason when the
155
+ * caller cancelled (see {@link request}).
88
156
  */
89
157
  async function customFetch(url, options) {
158
+ const policy = requestPolicy;
90
159
  const token = getApiAuthToken();
91
160
  const headers = new Headers(options.headers);
92
161
  if (token && !headers.has("authorization")) headers.set("authorization", `Bearer ${token}`);
93
- const res = await fetch(url, {
162
+ const method = (options.method ?? "GET").toUpperCase();
163
+ const unsafe = !SAFE_METHODS.has(method) && !headers.has("X-Zitadel-CSRF");
164
+ const target = originOf(url);
165
+ const csrfToken = apiCsrfTokenFor(target);
166
+ if (unsafe && csrfToken) headers.set(CSRF_HEADER, csrfToken);
167
+ let { res, rawBody: parsed } = await request(url, {
94
168
  ...options,
95
169
  headers
96
- });
97
- const rawBody = [
98
- 204,
99
- 205,
100
- 304
101
- ].includes(res.status) ? "" : await res.text();
102
- const parsed = rawBody ? safeJsonParse(rawBody) : void 0;
170
+ }, policy, readBody);
171
+ const onRejected = apiCsrfRejectionHandlerFor(target);
172
+ if (unsafe && onRejected && res.status === 403 && apiErrorCode(parsed) === CSRF_INVALID && !isStream(options.body)) {
173
+ const fresh = await onRejected().catch(() => void 0);
174
+ if (fresh && fresh !== csrfToken) {
175
+ headers.set(CSRF_HEADER, fresh);
176
+ ({res, rawBody: parsed} = await request(url, {
177
+ ...options,
178
+ headers
179
+ }, policy, readBody));
180
+ }
181
+ }
103
182
  if (!res.ok) {
104
183
  const message = `${options.method ?? "GET"} ${url} returned ${res.status}`;
105
184
  throw new ApiError(res.status, url, parsed, message);
106
185
  }
107
186
  return parsed;
108
187
  }
188
+ /** The parsed body, or `undefined` for the spec's no-body responses. */
189
+ async function readBody(res) {
190
+ if ([
191
+ 204,
192
+ 205,
193
+ 304
194
+ ].includes(res.status)) return void 0;
195
+ const rawBody = await res.text();
196
+ return rawBody ? safeJsonParse(rawBody) : void 0;
197
+ }
198
+ /** The request's origin, resolved against the page for a relative URL. */
199
+ function originOf(url) {
200
+ try {
201
+ return new URL(url, globalThis.location?.href).origin;
202
+ } catch {
203
+ return;
204
+ }
205
+ }
206
+ function isStream(body) {
207
+ return typeof ReadableStream !== "undefined" && body instanceof ReadableStream;
208
+ }
209
+ /**
210
+ * `fetch` bound by a {@link RequestPolicy}, with its failures typed.
211
+ *
212
+ * The policy's signal, its deadline and any signal on `init` are combined, and
213
+ * `read` runs under them too, so a server that sends headers and then stalls
214
+ * mid-body is cut off as well. When the request does not complete:
215
+ *
216
+ * - a deadline fired → {@link NetworkError} with reason `timeout`;
217
+ * - any other abort → the signal's own reason, rethrown untouched, because a
218
+ * cancellation is the caller's decision and the caller knows what it means;
219
+ * - anything else → {@link NetworkError} with reason `unreachable`.
220
+ *
221
+ * Exported for the few callers that need the raw {@link Response} (a
222
+ * `Set-Cookie` header the generated client does not expose).
223
+ */
224
+ async function request(url, init, policy = {}, read) {
225
+ const signals = [init.signal, policy.signal].filter((signal) => signal != null);
226
+ if (policy.timeoutMs !== void 0) signals.push(AbortSignal.timeout(policy.timeoutMs));
227
+ const signal = signals.length > 0 ? AbortSignal.any(signals) : void 0;
228
+ const method = init.method ?? "GET";
229
+ try {
230
+ const res = await fetch(url, {
231
+ ...init,
232
+ signal
233
+ });
234
+ return {
235
+ res,
236
+ rawBody: read ? await read(res) : void 0
237
+ };
238
+ } catch (error) {
239
+ if (signal?.aborted) {
240
+ const reason = signal.reason;
241
+ if (reason instanceof DOMException && reason.name === "TimeoutError") throw new NetworkError(url, "timeout", `${method} ${url} timed out`, { cause: reason });
242
+ throw reason;
243
+ }
244
+ const code = errnoOf(error);
245
+ throw new NetworkError(url, "unreachable", `${method} ${url} got no response${code ? ` (${code})` : ""}`, { cause: error });
246
+ }
247
+ }
248
+ /**
249
+ * The errno a runtime attached to a failed request, if any, for the message.
250
+ * Undici nests it on `cause`, inside an `AggregateError` when it tried more
251
+ * than one address. Only ever used to describe the failure, never to decide
252
+ * that it was one.
253
+ */
254
+ function errnoOf(error) {
255
+ let node = error;
256
+ for (let depth = 0; depth < 4 && typeof node === "object" && node !== null; depth += 1) {
257
+ const { code, errors } = node;
258
+ if (typeof code === "string") return code;
259
+ node = Array.isArray(errors) ? errors[0] : node.cause;
260
+ }
261
+ }
109
262
  /**
110
263
  * `JSON.parse` wrapped so a non-JSON body (e.g. an HTML 502 from a
111
264
  * proxy) becomes `{ raw: "<text>" }` instead of throwing inside
@@ -119,10 +272,34 @@ function safeJsonParse(text) {
119
272
  return { raw: text };
120
273
  }
121
274
  }
275
+ /**
276
+ * The `code` of the server's `{code, message, details}` error envelope: from an
277
+ * {@link ApiError}, or from a parsed response body. `undefined` when there is
278
+ * none, e.g. an HTML error page from a proxy.
279
+ */
280
+ function apiErrorCode(errorOrBody) {
281
+ const body = errorOrBody instanceof ApiError ? errorOrBody.body : errorOrBody;
282
+ return isRecord(body) && typeof body.code === "string" ? body.code : void 0;
283
+ }
284
+ function isRecord(value) {
285
+ return typeof value === "object" && value !== null && !Array.isArray(value);
286
+ }
287
+ //#endregion
288
+ //#region ../api/dist/rolldown-runtime-D7D4PA-g.mjs
289
+ var __defProp = Object.defineProperty;
290
+ var __exportAll = (all, no_symbols) => {
291
+ let target = {};
292
+ for (var name in all) __defProp(target, name, {
293
+ get: all[name],
294
+ enumerable: true
295
+ });
296
+ if (!no_symbols) __defProp(target, Symbol.toStringTag, { value: "Module" });
297
+ return target;
298
+ };
122
299
  //#endregion
123
300
  //#region ../api/dist/generated/endpoints/zitadelNextGen.mjs
124
301
  /**
125
- * Generated by orval v8.10.0 🍺
302
+ * Generated by orval 🍺
126
303
  * Do not edit manually.
127
304
  * Zitadel NextGen
128
305
  * This is the next generation of the Zitadel identity platform.
@@ -133,6 +310,7 @@ var zitadelNextGen_exports = /* @__PURE__ */ __exportAll({
133
310
  completeClaim: () => completeClaim,
134
311
  createAuthAttempt: () => createAuthAttempt,
135
312
  createBranding: () => createBranding,
313
+ createDeployment: () => createDeployment,
136
314
  createFlow: () => createFlow,
137
315
  createFlowDefinition: () => createFlowDefinition,
138
316
  createGrant: () => createGrant,
@@ -158,6 +336,7 @@ var zitadelNextGen_exports = /* @__PURE__ */ __exportAll({
158
336
  getCompleteClaimUrl: () => getCompleteClaimUrl,
159
337
  getCreateAuthAttemptUrl: () => getCreateAuthAttemptUrl,
160
338
  getCreateBrandingUrl: () => getCreateBrandingUrl,
339
+ getCreateDeploymentUrl: () => getCreateDeploymentUrl,
161
340
  getCreateFlowDefinitionUrl: () => getCreateFlowDefinitionUrl,
162
341
  getCreateFlowUrl: () => getCreateFlowUrl,
163
342
  getCreateGrantUrl: () => getCreateGrantUrl,
@@ -173,6 +352,7 @@ var zitadelNextGen_exports = /* @__PURE__ */ __exportAll({
173
352
  getDeleteTeamUrl: () => getDeleteTeamUrl,
174
353
  getDeleteUserByIDUrl: () => getDeleteUserByIDUrl,
175
354
  getDeleteVariableUrl: () => getDeleteVariableUrl,
355
+ getDeploymentById: () => getDeploymentById,
176
356
  getEnvironmentByName: () => getEnvironmentByName,
177
357
  getEvent: () => getEvent,
178
358
  getExchangeHandoffUrl: () => getExchangeHandoffUrl,
@@ -183,6 +363,7 @@ var zitadelNextGen_exports = /* @__PURE__ */ __exportAll({
183
363
  getGetBrandingByIdUrl: () => getGetBrandingByIdUrl,
184
364
  getGetClaimStatusUrl: () => getGetClaimStatusUrl,
185
365
  getGetClaimWindowUrl: () => getGetClaimWindowUrl,
366
+ getGetDeploymentByIdUrl: () => getGetDeploymentByIdUrl,
186
367
  getGetEnvironmentByNameUrl: () => getGetEnvironmentByNameUrl,
187
368
  getGetEventUrl: () => getGetEventUrl,
188
369
  getGetFlowDefinitionUrl: () => getGetFlowDefinitionUrl,
@@ -192,6 +373,7 @@ var zitadelNextGen_exports = /* @__PURE__ */ __exportAll({
192
373
  getGetIdpByIdUrl: () => getGetIdpByIdUrl,
193
374
  getGetIdpRevisionByIdUrl: () => getGetIdpRevisionByIdUrl,
194
375
  getGetLiveUrl: () => getGetLiveUrl,
376
+ getGetMySessionCsrfTokenUrl: () => getGetMySessionCsrfTokenUrl,
195
377
  getGetMySessionUrl: () => getGetMySessionUrl,
196
378
  getGetMyUserUrl: () => getGetMyUserUrl,
197
379
  getGetProjectUrl: () => getGetProjectUrl,
@@ -210,6 +392,7 @@ var zitadelNextGen_exports = /* @__PURE__ */ __exportAll({
210
392
  getInitClaimUrl: () => getInitClaimUrl,
211
393
  getIssueChallengeUrl: () => getIssueChallengeUrl,
212
394
  getListBrandingUrl: () => getListBrandingUrl,
395
+ getListDeploymentsUrl: () => getListDeploymentsUrl,
213
396
  getListEnvironmentsUrl: () => getListEnvironmentsUrl,
214
397
  getListEventsUrl: () => getListEventsUrl,
215
398
  getListFlowDefinitionsUrl: () => getListFlowDefinitionsUrl,
@@ -221,6 +404,7 @@ var zitadelNextGen_exports = /* @__PURE__ */ __exportAll({
221
404
  getListUserTeamsUrl: () => getListUserTeamsUrl,
222
405
  getLive: () => getLive,
223
406
  getMySession: () => getMySession,
407
+ getMySessionCsrfToken: () => getMySessionCsrfToken,
224
408
  getMyUser: () => getMyUser,
225
409
  getPatchMyUserUrl: () => getPatchMyUserUrl,
226
410
  getPatchProjectUrl: () => getPatchProjectUrl,
@@ -250,6 +434,7 @@ var zitadelNextGen_exports = /* @__PURE__ */ __exportAll({
250
434
  initClaim: () => initClaim,
251
435
  issueChallenge: () => issueChallenge,
252
436
  listBranding: () => listBranding,
437
+ listDeployments: () => listDeployments,
253
438
  listEnvironments: () => listEnvironments,
254
439
  listEvents: () => listEvents,
255
440
  listFlowDefinitions: () => listFlowDefinitions,
@@ -318,7 +503,7 @@ const getReady = async (options) => {
318
503
  const getCreateUserUrl = (params) => {
319
504
  const normalizedParams = new URLSearchParams();
320
505
  Object.entries(params || {}).forEach(([key, value]) => {
321
- if (value !== void 0) normalizedParams.append(key, value === null ? "null" : value.toString());
506
+ if (value !== void 0) normalizedParams.append(key, value === null ? "null" : String(value));
322
507
  });
323
508
  const stringifiedParams = normalizedParams.toString();
324
509
  return stringifiedParams.length > 0 ? `${getProxyPath()}/users?${stringifiedParams}` : `${getProxyPath()}/users`;
@@ -327,40 +512,58 @@ const getCreateUserUrl = (params) => {
327
512
  * @summary Create user
328
513
  */
329
514
  const createUser = async (createUserBody, params, options) => {
515
+ const getHeaders = (h) => {
516
+ if (!h) return {};
517
+ if (h instanceof Headers) return Object.fromEntries(h.entries());
518
+ if (Symbol.iterator in h) return Object.fromEntries(Array.from(h, (entry) => Array.from(entry)));
519
+ const headers = {};
520
+ for (const [name, value] of Object.entries(h)) if (value !== void 0) headers[name] = value;
521
+ return headers;
522
+ };
330
523
  return customFetch(getCreateUserUrl(params), {
331
524
  ...options,
332
525
  method: "POST",
333
526
  headers: {
334
527
  "Content-Type": "application/json",
335
- ...options?.headers
528
+ ...getHeaders(options?.headers)
336
529
  },
337
530
  body: JSON.stringify(createUserBody)
338
531
  });
339
532
  };
340
- const getQueryUsersUrl = () => {
341
- return `${getProxyPath()}/users/query`;
533
+ const getQueryUsersUrl = (params) => {
534
+ const normalizedParams = new URLSearchParams();
535
+ Object.entries(params || {}).forEach(([key, value]) => {
536
+ if (value !== void 0) normalizedParams.append(key, value === null ? "null" : String(value));
537
+ });
538
+ const stringifiedParams = normalizedParams.toString();
539
+ return stringifiedParams.length > 0 ? `${getProxyPath()}/users/query?${stringifiedParams}` : `${getProxyPath()}/users/query`;
342
540
  };
343
541
  /**
344
542
  * Returns the users of a project, paginated with a cursor.
345
-
346
- The project comes from the credential, not from a parameter: the
347
- operation is bound to the credential's home project by construction
348
- (oauth2 secret or user-bound session). This is why it takes no
349
- `project_id`, unlike the other query endpoints.
350
-
351
- Accepts either a project secret (`oauth2`) or a user-bound Console
352
- session cookie (`nextgenSession`). CSRF/Origin for cookie mutations
353
- is a follow-up (#1140).
354
-
543
+ *
544
+ * `project_id` names the project to list; without it, the credential's own
545
+ * project is listed.
546
+ *
547
+ * Accepts either a project secret (`oauth2`) or a user-bound Console
548
+ * session cookie (`nextgenSession`). Cookie-authenticated requests
549
+ * follow the scheme's CSRF rules (`nextgenSession`).
355
550
  * @summary Query users
356
551
  */
357
- const queryUsers = async (queryUsersBody, options) => {
358
- return customFetch(getQueryUsersUrl(), {
552
+ const queryUsers = async (queryUsersBody, params, options) => {
553
+ const getHeaders = (h) => {
554
+ if (!h) return {};
555
+ if (h instanceof Headers) return Object.fromEntries(h.entries());
556
+ if (Symbol.iterator in h) return Object.fromEntries(Array.from(h, (entry) => Array.from(entry)));
557
+ const headers = {};
558
+ for (const [name, value] of Object.entries(h)) if (value !== void 0) headers[name] = value;
559
+ return headers;
560
+ };
561
+ return customFetch(getQueryUsersUrl(params), {
359
562
  ...options,
360
563
  method: "POST",
361
564
  headers: {
362
565
  "Content-Type": "application/json",
363
- ...options?.headers
566
+ ...getHeaders(options?.headers)
364
567
  },
365
568
  body: JSON.stringify(queryUsersBody)
366
569
  });
@@ -368,10 +571,10 @@ const queryUsers = async (queryUsersBody, options) => {
368
571
  const getGetUserByIDUrl = (userId, params) => {
369
572
  const normalizedParams = new URLSearchParams();
370
573
  Object.entries(params || {}).forEach(([key, value]) => {
371
- if (value !== void 0) normalizedParams.append(key, value === null ? "null" : value.toString());
574
+ if (value !== void 0) normalizedParams.append(key, value === null ? "null" : String(value));
372
575
  });
373
576
  const stringifiedParams = normalizedParams.toString();
374
- return stringifiedParams.length > 0 ? `${getProxyPath()}/users/${userId}?${stringifiedParams}` : `${getProxyPath()}/users/${userId}`;
577
+ return stringifiedParams.length > 0 ? `${getProxyPath()}/users/${encodeURIComponent(String(userId))}?${stringifiedParams}` : `${getProxyPath()}/users/${encodeURIComponent(String(userId))}`;
375
578
  };
376
579
  /**
377
580
  * @summary Get user by ID
@@ -383,29 +586,36 @@ const getUserByID = async (userId, params, options) => {
383
586
  });
384
587
  };
385
588
  const getPatchUserByIDUrl = (userId) => {
386
- return `${getProxyPath()}/users/${userId}`;
589
+ return `${getProxyPath()}/users/${encodeURIComponent(String(userId))}`;
387
590
  };
388
591
  /**
389
592
  * Partially updates a user's schema-defined attributes, and optionally
390
- moves the user to another registered schema. The merged result is
391
- validated against the schema before commit. Concurrent writes are
392
- last-write-wins.
393
-
593
+ * moves the user to another registered schema. The merged result is
594
+ * validated against the schema before commit. Concurrent writes are
595
+ * last-write-wins.
394
596
  * @summary Update user by ID
395
597
  */
396
598
  const patchUserByID = async (userId, patchUserByIDBody, options) => {
599
+ const getHeaders = (h) => {
600
+ if (!h) return {};
601
+ if (h instanceof Headers) return Object.fromEntries(h.entries());
602
+ if (Symbol.iterator in h) return Object.fromEntries(Array.from(h, (entry) => Array.from(entry)));
603
+ const headers = {};
604
+ for (const [name, value] of Object.entries(h)) if (value !== void 0) headers[name] = value;
605
+ return headers;
606
+ };
397
607
  return customFetch(getPatchUserByIDUrl(userId), {
398
608
  ...options,
399
609
  method: "PATCH",
400
610
  headers: {
401
611
  "Content-Type": "application/json",
402
- ...options?.headers
612
+ ...getHeaders(options?.headers)
403
613
  },
404
614
  body: JSON.stringify(patchUserByIDBody)
405
615
  });
406
616
  };
407
617
  const getDeleteUserByIDUrl = (userId) => {
408
- return `${getProxyPath()}/users/${userId}`;
618
+ return `${getProxyPath()}/users/${encodeURIComponent(String(userId))}`;
409
619
  };
410
620
  /**
411
621
  * @summary Delete user by ID
@@ -419,10 +629,10 @@ const deleteUserByID = async (userId, options) => {
419
629
  const getListUserPasskeysUrl = (userId, params) => {
420
630
  const normalizedParams = new URLSearchParams();
421
631
  Object.entries(params || {}).forEach(([key, value]) => {
422
- if (value !== void 0) normalizedParams.append(key, value === null ? "null" : value.toString());
632
+ if (value !== void 0) normalizedParams.append(key, value === null ? "null" : String(value));
423
633
  });
424
634
  const stringifiedParams = normalizedParams.toString();
425
- return stringifiedParams.length > 0 ? `${getProxyPath()}/users/${userId}/passkeys?${stringifiedParams}` : `${getProxyPath()}/users/${userId}/passkeys`;
635
+ return stringifiedParams.length > 0 ? `${getProxyPath()}/users/${encodeURIComponent(String(userId))}/passkeys?${stringifiedParams}` : `${getProxyPath()}/users/${encodeURIComponent(String(userId))}/passkeys`;
426
636
  };
427
637
  /**
428
638
  * @summary List user passkeys
@@ -434,65 +644,87 @@ const listUserPasskeys = async (userId, params, options) => {
434
644
  });
435
645
  };
436
646
  const getBeginUserPasskeyRegistrationUrl = (userId) => {
437
- return `${getProxyPath()}/users/${userId}/passkeys/registrations`;
647
+ return `${getProxyPath()}/users/${encodeURIComponent(String(userId))}/passkeys/registrations`;
438
648
  };
439
649
  /**
440
650
  * Starts a WebAuthn registration ceremony for the user and returns the
441
- creation options for `navigator.credentials.create()`. Complete the
442
- ceremony with `POST /users/{user_id}/passkeys/registrations/{registration_id}` within
443
- five minutes. Credentials already registered for the user are excluded
444
- automatically.
445
-
651
+ * creation options for `navigator.credentials.create()`. Complete the
652
+ * ceremony with `POST /users/{user_id}/passkeys/registrations/{registration_id}` within
653
+ * five minutes. Credentials already registered for the user are excluded
654
+ * automatically.
446
655
  * @summary Begin passkey registration
447
656
  */
448
657
  const beginUserPasskeyRegistration = async (userId, beginUserPasskeyRegistrationBody, options) => {
658
+ const getHeaders = (h) => {
659
+ if (!h) return {};
660
+ if (h instanceof Headers) return Object.fromEntries(h.entries());
661
+ if (Symbol.iterator in h) return Object.fromEntries(Array.from(h, (entry) => Array.from(entry)));
662
+ const headers = {};
663
+ for (const [name, value] of Object.entries(h)) if (value !== void 0) headers[name] = value;
664
+ return headers;
665
+ };
449
666
  return customFetch(getBeginUserPasskeyRegistrationUrl(userId), {
450
667
  ...options,
451
668
  method: "POST",
452
669
  headers: {
453
670
  "Content-Type": "application/json",
454
- ...options?.headers
671
+ ...getHeaders(options?.headers)
455
672
  },
456
673
  body: JSON.stringify(beginUserPasskeyRegistrationBody)
457
674
  });
458
675
  };
459
676
  const getFinishUserPasskeyRegistrationUrl = (userId, registrationId) => {
460
- return `${getProxyPath()}/users/${userId}/passkeys/registrations/${registrationId}`;
677
+ return `${getProxyPath()}/users/${encodeURIComponent(String(userId))}/passkeys/registrations/${encodeURIComponent(String(registrationId))}`;
461
678
  };
462
679
  /**
463
680
  * Verifies the attestation against the ceremony started by
464
- `POST /users/{user_id}/passkeys/registrations` and persists the new credential. A
465
- rejected attestation counts against the ceremony's failure budget and the
466
- ceremony stays open for a retry. An expired ceremony surfaces as
467
- `att.stale_challenge`; an unknown or already-consumed registration id
468
- surfaces as `att.not_found`.
469
-
681
+ * `POST /users/{user_id}/passkeys/registrations` and persists the new credential. A
682
+ * rejected attestation counts against the ceremony's failure budget and the
683
+ * ceremony stays open for a retry. An expired ceremony surfaces as
684
+ * `att.stale_challenge`; an unknown or already-consumed registration id
685
+ * surfaces as `att.not_found`.
470
686
  * @summary Finish passkey registration
471
687
  */
472
688
  const finishUserPasskeyRegistration = async (userId, registrationId, finishUserPasskeyRegistrationBody, options) => {
689
+ const getHeaders = (h) => {
690
+ if (!h) return {};
691
+ if (h instanceof Headers) return Object.fromEntries(h.entries());
692
+ if (Symbol.iterator in h) return Object.fromEntries(Array.from(h, (entry) => Array.from(entry)));
693
+ const headers = {};
694
+ for (const [name, value] of Object.entries(h)) if (value !== void 0) headers[name] = value;
695
+ return headers;
696
+ };
473
697
  return customFetch(getFinishUserPasskeyRegistrationUrl(userId, registrationId), {
474
698
  ...options,
475
699
  method: "POST",
476
700
  headers: {
477
701
  "Content-Type": "application/json",
478
- ...options?.headers
702
+ ...getHeaders(options?.headers)
479
703
  },
480
704
  body: JSON.stringify(finishUserPasskeyRegistrationBody)
481
705
  });
482
706
  };
483
707
  const getSetUserPasswordUrl = (userId) => {
484
- return `${getProxyPath()}/users/${userId}/password`;
708
+ return `${getProxyPath()}/users/${encodeURIComponent(String(userId))}/password`;
485
709
  };
486
710
  /**
487
711
  * @summary Set user password
488
712
  */
489
713
  const setUserPassword = async (userId, setUserPasswordBody, options) => {
714
+ const getHeaders = (h) => {
715
+ if (!h) return {};
716
+ if (h instanceof Headers) return Object.fromEntries(h.entries());
717
+ if (Symbol.iterator in h) return Object.fromEntries(Array.from(h, (entry) => Array.from(entry)));
718
+ const headers = {};
719
+ for (const [name, value] of Object.entries(h)) if (value !== void 0) headers[name] = value;
720
+ return headers;
721
+ };
490
722
  return customFetch(getSetUserPasswordUrl(userId), {
491
723
  ...options,
492
724
  method: "PUT",
493
725
  headers: {
494
726
  "Content-Type": "application/json",
495
- ...options?.headers
727
+ ...getHeaders(options?.headers)
496
728
  },
497
729
  body: JSON.stringify(setUserPasswordBody)
498
730
  });
@@ -500,20 +732,19 @@ const setUserPassword = async (userId, setUserPasswordBody, options) => {
500
732
  const getListUserTeamsUrl = (userId, params) => {
501
733
  const normalizedParams = new URLSearchParams();
502
734
  Object.entries(params || {}).forEach(([key, value]) => {
503
- if (value !== void 0) normalizedParams.append(key, value === null ? "null" : value.toString());
735
+ if (value !== void 0) normalizedParams.append(key, value === null ? "null" : String(value));
504
736
  });
505
737
  const stringifiedParams = normalizedParams.toString();
506
- return stringifiedParams.length > 0 ? `${getProxyPath()}/users/${userId}/teams?${stringifiedParams}` : `${getProxyPath()}/users/${userId}/teams`;
738
+ return stringifiedParams.length > 0 ? `${getProxyPath()}/users/${encodeURIComponent(String(userId))}/teams?${stringifiedParams}` : `${getProxyPath()}/users/${encodeURIComponent(String(userId))}/teams`;
507
739
  };
508
740
  /**
509
741
  * The user's team roster, ordered by team name. Each entry carries the
510
- team's name, so a client renders a page without resolving ids one by one.
511
-
512
- This is the N:N roster and it is not lifecycle ownership: the single team
513
- that owns the user's lifecycle is reported as `metadata.lifecycle_owner_team_id`
514
- on the user read endpoints. Memberships the user was removed from are not
515
- returned.
516
-
742
+ * team's name, so a client renders a page without resolving ids one by one.
743
+ *
744
+ * This is the N:N roster and it is not lifecycle ownership: the single team
745
+ * that owns the user's lifecycle is reported as `metadata.lifecycle_owner_team_id`
746
+ * on the user read endpoints. Memberships the user was removed from are not
747
+ * returned.
517
748
  * @summary List the teams a user belongs to
518
749
  */
519
750
  const listUserTeams = async (userId, params, options) => {
@@ -539,18 +770,25 @@ const getPatchMyUserUrl = () => {
539
770
  };
540
771
  /**
541
772
  * Partially updates the caller's own schema-defined attributes. The merged
542
- result is validated against the user's schema before commit. Concurrent
543
- writes are last-write-wins.
544
-
773
+ * result is validated against the user's schema before commit. Concurrent
774
+ * writes are last-write-wins.
545
775
  * @summary Update my user information
546
776
  */
547
777
  const patchMyUser = async (patchMyUserBody, options) => {
778
+ const getHeaders = (h) => {
779
+ if (!h) return {};
780
+ if (h instanceof Headers) return Object.fromEntries(h.entries());
781
+ if (Symbol.iterator in h) return Object.fromEntries(Array.from(h, (entry) => Array.from(entry)));
782
+ const headers = {};
783
+ for (const [name, value] of Object.entries(h)) if (value !== void 0) headers[name] = value;
784
+ return headers;
785
+ };
548
786
  return customFetch(getPatchMyUserUrl(), {
549
787
  ...options,
550
788
  method: "PATCH",
551
789
  headers: {
552
790
  "Content-Type": "application/json",
553
- ...options?.headers
791
+ ...getHeaders(options?.headers)
554
792
  },
555
793
  body: JSON.stringify(patchMyUserBody)
556
794
  });
@@ -558,20 +796,19 @@ const patchMyUser = async (patchMyUserBody, options) => {
558
796
  const getListMyProjectsUrl = (params) => {
559
797
  const normalizedParams = new URLSearchParams();
560
798
  Object.entries(params || {}).forEach(([key, value]) => {
561
- if (value !== void 0) normalizedParams.append(key, value === null ? "null" : value.toString());
799
+ if (value !== void 0) normalizedParams.append(key, value === null ? "null" : String(value));
562
800
  });
563
801
  const stringifiedParams = normalizedParams.toString();
564
802
  return stringifiedParams.length > 0 ? `${getProxyPath()}/users/me/projects?${stringifiedParams}` : `${getProxyPath()}/users/me/projects`;
565
803
  };
566
804
  /**
567
805
  * The projects the signed-in user holds an active grant on, either directly or
568
- through a team they are a member of. Ordered by project id and paged with an
569
- opaque cursor.
570
-
571
- This is not the same question as `queryProjects`, which answers with the one
572
- project the calling credential is bound to. Here the session is the caller
573
- and the grants are the answer, so the list spans projects.
574
-
806
+ * through a team they are a member of. Ordered by project id and paged with an
807
+ * opaque cursor.
808
+ *
809
+ * This is not the same question as `queryProjects`, which answers with the one
810
+ * project the calling credential is bound to. Here the session is the caller
811
+ * and the grants are the answer, so the list spans projects.
575
812
  * @summary List the projects I can act on
576
813
  */
577
814
  const listMyProjects = async (params, options) => {
@@ -585,37 +822,43 @@ const getCreateFlowUrl = () => {
585
822
  };
586
823
  /**
587
824
  * Resolves a flow definition based on purpose + audience context and returns
588
- the first capability step. Creates a new session implicitly unless
589
- `session_id` is provided (for step-up / reauth on an existing session).
590
-
591
- The response contains an `id` field — the flow handle. Use it as the path
592
- parameter for all subsequent `/flow/{id}/submit` calls.
593
-
594
- The response also sets an encrypted `HttpOnly` cookie (`_zflow`) containing
595
- the flow's orchestration state (current step, collected data, history).
596
- The server is stateless between requests — all flow state lives in this
597
- cookie. The browser sends it automatically on subsequent requests.
598
-
825
+ * the first capability step. Creates a new session implicitly unless
826
+ * `session_id` is provided (for step-up / reauth on an existing session).
827
+ *
828
+ * The response contains an `id` field — the flow handle. Use it as the path
829
+ * parameter for all subsequent `/flow/{id}/submit` calls.
830
+ *
831
+ * The response also sets an encrypted `HttpOnly` cookie (`_zflow`) containing
832
+ * the flow's orchestration state (current step, collected data, history).
833
+ * The server is stateless between requests — all flow state lives in this
834
+ * cookie. The browser sends it automatically on subsequent requests.
599
835
  * @summary Start a new flow
600
836
  */
601
837
  const createFlow = async (createFlowBody, options) => {
838
+ const getHeaders = (h) => {
839
+ if (!h) return {};
840
+ if (h instanceof Headers) return Object.fromEntries(h.entries());
841
+ if (Symbol.iterator in h) return Object.fromEntries(Array.from(h, (entry) => Array.from(entry)));
842
+ const headers = {};
843
+ for (const [name, value] of Object.entries(h)) if (value !== void 0) headers[name] = value;
844
+ return headers;
845
+ };
602
846
  return customFetch(getCreateFlowUrl(), {
603
847
  ...options,
604
848
  method: "POST",
605
849
  headers: {
606
850
  "Content-Type": "application/json",
607
- ...options?.headers
851
+ ...getHeaders(options?.headers)
608
852
  },
609
853
  body: JSON.stringify(createFlowBody)
610
854
  });
611
855
  };
612
856
  const getGetFlowStepUrl = (id) => {
613
- return `${getProxyPath()}/flow/${id}`;
857
+ return `${getProxyPath()}/flow/${encodeURIComponent(String(id))}`;
614
858
  };
615
859
  /**
616
860
  * Returns the current capability step without advancing the state machine.
617
- Useful for page reloads or re-rendering after a network error.
618
-
861
+ * Useful for page reloads or re-rendering after a network error.
619
862
  * @summary Get current step (re-render)
620
863
  */
621
864
  const getFlowStep = async (id, options) => {
@@ -625,46 +868,74 @@ const getFlowStep = async (id, options) => {
625
868
  });
626
869
  };
627
870
  const getSubmitFlowStepUrl = (id) => {
628
- return `${getProxyPath()}/flow/${id}/submit`;
871
+ return `${getProxyPath()}/flow/${encodeURIComponent(String(id))}/submit`;
629
872
  };
630
873
  /**
631
874
  * Submits user input for the current step. The server validates,
632
- processes (e.g., verifies a credential), advances the state machine
633
- through any invisible steps, and returns the next visible step.
634
-
635
- The response sets an updated encrypted `HttpOnly` cookie (`_zflow`)
636
- with the new flow state. The server is stateless — all orchestration
637
- state is carried in this cookie between requests.
638
-
639
- **Important:** The `id` in the response may differ from the `id` used in
640
- the request. This happens when a flow pivots (pushes a new flow onto the
641
- stack) or when a stacked flow completes (auto-pops to the parent flow).
642
- Always use the `id` from the latest response for the next request.
643
-
644
- ## Flow completion
645
-
646
- When `step.type` is `complete`, the flow is terminal. The `step.behavior`
647
- field tells the frontend what to do:
648
-
649
- | `behavior` | Action |
650
- |------------- |------------------------------------------------------------|
651
- | `redirect` | Navigate to `redirect_uri` (OIDC/SAML auth request done). |
652
- | `show` | Render the step as a success screen (e.g., registration). |
653
-
654
- A `complete` step is only returned when the **entire flow stack** is done.
655
- If a stacked flow (e.g., recovery pivoted from login) finishes, the server
656
- auto-pops to the parent flow and returns the parent's next step — the
657
- frontend never sees a `complete` for intermediate flows.
658
-
875
+ * processes (e.g., verifies a credential), advances the state machine
876
+ * through any invisible steps, and returns the next visible step.
877
+ *
878
+ * The response sets an updated encrypted `HttpOnly` cookie (`_zflow`)
879
+ * with the new flow state. The server is stateless — all orchestration
880
+ * state is carried in this cookie between requests.
881
+ *
882
+ * **Important:** The `id` in the response may differ from the `id` used in
883
+ * the request. This happens when a flow pivots (pushes a new flow onto the
884
+ * stack) or when a stacked flow completes (auto-pops to the parent flow).
885
+ * Always use the `id` from the latest response for the next request.
886
+ *
887
+ * ## Flow completion
888
+ *
889
+ * When `step.type` is `complete`, the flow is terminal. The `step.behavior`
890
+ * field tells the frontend what to do:
891
+ *
892
+ * | `behavior` | Action |
893
+ * |------------- |------------------------------------------------------------|
894
+ * | `redirect` | Navigate to `redirect_uri` (OIDC/SAML auth request done). |
895
+ * | `show` | Render the step as a success screen (e.g., registration). |
896
+ *
897
+ * A `complete` step is only returned when the **entire flow stack** is done.
898
+ * If a stacked flow (e.g., recovery pivoted from login) finishes, the server
899
+ * auto-pops to the parent flow and returns the parent's next step — the
900
+ * frontend never sees a `complete` for intermediate flows.
901
+ *
902
+ * ## External sign-in
903
+ *
904
+ * `{action: "sso", sso_provider_id, return_target}` on a step that offers
905
+ * `sso_providers` returns the engine-emitted `sso-redirect` step, whose
906
+ * `redirect_url` the frontend navigates to.
907
+ *
908
+ * - The flow state does not change, but `_zflow` is re-sealed like on
909
+ * every response, so its ten-minute window restarts at this submission;
910
+ * the external sign-in and the return must complete within it.
911
+ * - A second `Set-Cookie` line carries the browser-binding cookie the
912
+ * callback checks: `HttpOnly`, `Path=/`, `SameSite=Lax`.
913
+ * - On every host except http loopback it is `__Host-_zsso` with `Secure`.
914
+ * - When the request host is http loopback (local development, where
915
+ * Safari rejects `Secure`), it is `_zsso` with no `Secure`; the
916
+ * `__Host-` prefix is dropped because it requires `Secure`.
917
+ *
918
+ * A connection whose `client_id` is a `${{ NAME }}` reference has it filled
919
+ * from the project's variables. A provider the engine cannot start a
920
+ * sign-in with, including a reference with no variable behind it,
921
+ * re-renders the step with `error.sso_unavailable`.
659
922
  * @summary Submit step data and advance
660
923
  */
661
924
  const submitFlowStep = async (id, submitFlowStepBody, options) => {
925
+ const getHeaders = (h) => {
926
+ if (!h) return {};
927
+ if (h instanceof Headers) return Object.fromEntries(h.entries());
928
+ if (Symbol.iterator in h) return Object.fromEntries(Array.from(h, (entry) => Array.from(entry)));
929
+ const headers = {};
930
+ for (const [name, value] of Object.entries(h)) if (value !== void 0) headers[name] = value;
931
+ return headers;
932
+ };
662
933
  return customFetch(getSubmitFlowStepUrl(id), {
663
934
  ...options,
664
935
  method: "POST",
665
936
  headers: {
666
937
  "Content-Type": "application/json",
667
- ...options?.headers
938
+ ...getHeaders(options?.headers)
668
939
  },
669
940
  body: JSON.stringify(submitFlowStepBody)
670
941
  });
@@ -674,38 +945,44 @@ const getCreateAuthAttemptUrl = () => {
674
945
  };
675
946
  /**
676
947
  * Starts a new authentication attempt. This is the entry point for the auth_attempts state machine.
677
-
678
- An attempt is an ephemeral (15-minute TTL) state machine that drives a single authentication round.
679
- It accepts factor challenges, verifies proofs, and completes into a session or handoff token.
680
-
681
- Accepts a project_id and challenge_nonce (from POST /bootstrap/challenge). For step-up re-auth,
682
- also include session_id to add factors to an existing session.
683
-
948
+ *
949
+ * An attempt is an ephemeral (15-minute TTL) state machine that drives a single authentication round.
950
+ * It accepts factor challenges, verifies proofs, and completes into a session or handoff token.
951
+ *
952
+ * Accepts a project_id and challenge_nonce (from POST /bootstrap/challenge). For step-up re-auth,
953
+ * also include session_id to add factors to an existing session.
684
954
  * @summary Create a new authentication attempt
685
955
  */
686
956
  const createAuthAttempt = async (createAuthAttemptBody, options) => {
957
+ const getHeaders = (h) => {
958
+ if (!h) return {};
959
+ if (h instanceof Headers) return Object.fromEntries(h.entries());
960
+ if (Symbol.iterator in h) return Object.fromEntries(Array.from(h, (entry) => Array.from(entry)));
961
+ const headers = {};
962
+ for (const [name, value] of Object.entries(h)) if (value !== void 0) headers[name] = value;
963
+ return headers;
964
+ };
687
965
  return customFetch(getCreateAuthAttemptUrl(), {
688
966
  ...options,
689
967
  method: "POST",
690
968
  headers: {
691
969
  "Content-Type": "application/json",
692
- ...options?.headers
970
+ ...getHeaders(options?.headers)
693
971
  },
694
972
  body: JSON.stringify(createAuthAttemptBody)
695
973
  });
696
974
  };
697
975
  const getGetAuthAttemptUrl = (attemptId) => {
698
- return `${getProxyPath()}/auth_attempts/${attemptId}`;
976
+ return `${getProxyPath()}/auth_attempts/${encodeURIComponent(String(attemptId))}`;
699
977
  };
700
978
  /**
701
979
  * Polls the current state of an authentication attempt.
702
-
703
- Returns the attempt's state, available factors for the next challenge,
704
- challenges issued so far, and any errors preventing progress.
705
-
706
- Use this for polling during long-running factor verifications (e.g., waiting for
707
- a federated IdP callback or a device flow).
708
-
980
+ *
981
+ * Returns the attempt's state, available factors for the next challenge,
982
+ * challenges issued so far, and any errors preventing progress.
983
+ *
984
+ * Use this for polling during long-running factor verifications (e.g., waiting for
985
+ * a federated IdP callback or a device flow).
709
986
  * @summary Get authentication attempt state
710
987
  */
711
988
  const getAuthAttempt = async (attemptId, options) => {
@@ -715,72 +992,85 @@ const getAuthAttempt = async (attemptId, options) => {
715
992
  });
716
993
  };
717
994
  const getIssueChallengeUrl = (attemptId) => {
718
- return `${getProxyPath()}/auth_attempts/${attemptId}/challenges`;
995
+ return `${getProxyPath()}/auth_attempts/${encodeURIComponent(String(attemptId))}/challenges`;
719
996
  };
720
997
  /**
721
998
  * Issues a single-factor verification challenge within an auth attempt.
722
-
723
- This advances the authentication state machine by requesting a specific factor method
724
- (password, passkey, TOTP, OTP via SMS, etc.). The server responds with challenge details
725
- including method, metadata, and any UI hints. The client then verifies the proof
726
- by calling POST /auth_attempts/{attempt_id}/challenges/{challenge_id}/verify.
727
-
999
+ *
1000
+ * This advances the authentication state machine by requesting a specific factor method
1001
+ * (password, passkey, TOTP, OTP via SMS, etc.). The server responds with challenge details
1002
+ * including method, metadata, and any UI hints. The client then verifies the proof
1003
+ * by calling POST /auth_attempts/{attempt_id}/challenges/{challenge_id}/verify.
728
1004
  * @summary Issue a factor challenge
729
1005
  */
730
1006
  const issueChallenge = async (attemptId, issueChallengeBody, options) => {
1007
+ const getHeaders = (h) => {
1008
+ if (!h) return {};
1009
+ if (h instanceof Headers) return Object.fromEntries(h.entries());
1010
+ if (Symbol.iterator in h) return Object.fromEntries(Array.from(h, (entry) => Array.from(entry)));
1011
+ const headers = {};
1012
+ for (const [name, value] of Object.entries(h)) if (value !== void 0) headers[name] = value;
1013
+ return headers;
1014
+ };
731
1015
  return customFetch(getIssueChallengeUrl(attemptId), {
732
1016
  ...options,
733
1017
  method: "POST",
734
1018
  headers: {
735
1019
  "Content-Type": "application/json",
736
- ...options?.headers
1020
+ ...getHeaders(options?.headers)
737
1021
  },
738
1022
  body: JSON.stringify(issueChallengeBody)
739
1023
  });
740
1024
  };
741
1025
  const getVerifyChallengeProofUrl = (attemptId, challengeId) => {
742
- return `${getProxyPath()}/auth_attempts/${attemptId}/challenges/${challengeId}/verify`;
1026
+ return `${getProxyPath()}/auth_attempts/${encodeURIComponent(String(attemptId))}/challenges/${encodeURIComponent(String(challengeId))}/verify`;
743
1027
  };
744
1028
  /**
745
1029
  * Submits a proof (credential, code, assertion) to verify a factor challenge.
746
-
747
- The proof format depends on the challenge method. For example:
748
- - `password` method: { password: "…" }
749
- - `totp` method: { totp: { code: "123456" } }
750
- - `passkey` method: { passkey: { assertion: "…" } }
751
- - `recovery_code` method: { recovery_code: "…" }
752
-
753
- On successful verification, the factor is written to the auth attempt.
754
- The attempt moves to the next pending challenge or completes if all required factors are verified.
755
-
1030
+ *
1031
+ * The proof format depends on the challenge method. For example:
1032
+ * - `password` method: { password: "…" }
1033
+ * - `totp` method: { totp: { code: "123456" } }
1034
+ * - `passkey` method: { passkey: { assertion: "…" } }
1035
+ * - `recovery_code` method: { recovery_code: "…" }
1036
+ *
1037
+ * On successful verification, the factor is written to the auth attempt.
1038
+ * The attempt moves to the next pending challenge or completes if all required factors are verified.
756
1039
  * @summary Verify a factor proof
757
1040
  */
758
1041
  const verifyChallengeProof = async (attemptId, challengeId, verifyChallengeProofBody, options) => {
1042
+ const getHeaders = (h) => {
1043
+ if (!h) return {};
1044
+ if (h instanceof Headers) return Object.fromEntries(h.entries());
1045
+ if (Symbol.iterator in h) return Object.fromEntries(Array.from(h, (entry) => Array.from(entry)));
1046
+ const headers = {};
1047
+ for (const [name, value] of Object.entries(h)) if (value !== void 0) headers[name] = value;
1048
+ return headers;
1049
+ };
759
1050
  return customFetch(getVerifyChallengeProofUrl(attemptId, challengeId), {
760
1051
  ...options,
761
1052
  method: "POST",
762
1053
  headers: {
763
1054
  "Content-Type": "application/json",
764
- ...options?.headers
1055
+ ...getHeaders(options?.headers)
765
1056
  },
766
1057
  body: JSON.stringify(verifyChallengeProofBody)
767
1058
  });
768
1059
  };
769
1060
  const getCreateHandoffUrl = (attemptId) => {
770
- return `${getProxyPath()}/auth_attempts/${attemptId}/handoff`;
1061
+ return `${getProxyPath()}/auth_attempts/${encodeURIComponent(String(attemptId))}/handoff`;
771
1062
  };
772
1063
  /**
773
1064
  * Completes the authentication attempt and mints a `handoff_token`.
774
-
775
- Call this after all required factors have been verified and the attempt is in `completed` state.
776
- The handoff token is short-lived (≤60 seconds) and must be exchanged at
777
- POST /sessions/exchange to receive the final session and session_token.
778
-
779
- The handoff token is:
780
- - Single-use (atomic exchange, no retry)
781
- - Audience-bound (requires matching project key for exchange)
782
- - Idempotency-safe within a 5-minute window (see conventions)
783
-
1065
+ *
1066
+ * Call this after all required factors have been verified and the attempt is in `completed` state.
1067
+ * The handoff token is short-lived (≤60 seconds) and must be exchanged at
1068
+ * POST /sessions/exchange to receive the final session and session_token.
1069
+ *
1070
+ * The handoff token is:
1071
+ * - Single-use (atomic exchange, no retry)
1072
+ * - Audience-bound (requires matching project key for exchange)
1073
+ * - Idempotency-safe within a 5-minute window (see conventions)
784
1074
  * @summary Complete authentication and create handoff token
785
1075
  */
786
1076
  const createHandoff = async (attemptId, options) => {
@@ -796,12 +1086,20 @@ const getCreateProjectUrl = () => {
796
1086
  * @summary Create project
797
1087
  */
798
1088
  const createProject = async (createProjectBody, options) => {
1089
+ const getHeaders = (h) => {
1090
+ if (!h) return {};
1091
+ if (h instanceof Headers) return Object.fromEntries(h.entries());
1092
+ if (Symbol.iterator in h) return Object.fromEntries(Array.from(h, (entry) => Array.from(entry)));
1093
+ const headers = {};
1094
+ for (const [name, value] of Object.entries(h)) if (value !== void 0) headers[name] = value;
1095
+ return headers;
1096
+ };
799
1097
  return customFetch(getCreateProjectUrl(), {
800
1098
  ...options,
801
1099
  method: "POST",
802
1100
  headers: {
803
1101
  "Content-Type": "application/json",
804
- ...options?.headers
1102
+ ...getHeaders(options?.headers)
805
1103
  },
806
1104
  body: JSON.stringify(createProjectBody)
807
1105
  });
@@ -813,22 +1111,29 @@ const getQueryProjectsUrl = () => {
813
1111
  * @summary Query projects
814
1112
  */
815
1113
  const queryProjects = async (queryProjectsBody, options) => {
1114
+ const getHeaders = (h) => {
1115
+ if (!h) return {};
1116
+ if (h instanceof Headers) return Object.fromEntries(h.entries());
1117
+ if (Symbol.iterator in h) return Object.fromEntries(Array.from(h, (entry) => Array.from(entry)));
1118
+ const headers = {};
1119
+ for (const [name, value] of Object.entries(h)) if (value !== void 0) headers[name] = value;
1120
+ return headers;
1121
+ };
816
1122
  return customFetch(getQueryProjectsUrl(), {
817
1123
  ...options,
818
1124
  method: "POST",
819
1125
  headers: {
820
1126
  "Content-Type": "application/json",
821
- ...options?.headers
1127
+ ...getHeaders(options?.headers)
822
1128
  },
823
1129
  body: JSON.stringify(queryProjectsBody)
824
1130
  });
825
1131
  };
826
1132
  const getGetProjectUrl = (projectId) => {
827
- return `${getProxyPath()}/projects/${projectId}`;
1133
+ return `${getProxyPath()}/projects/${encodeURIComponent(String(projectId))}`;
828
1134
  };
829
1135
  /**
830
1136
  * Returns the current state of a project.
831
-
832
1137
  * @summary Get project
833
1138
  */
834
1139
  const getProject = async (projectId, options) => {
@@ -838,34 +1143,40 @@ const getProject = async (projectId, options) => {
838
1143
  });
839
1144
  };
840
1145
  const getPatchProjectUrl = (projectId) => {
841
- return `${getProxyPath()}/projects/${projectId}`;
1146
+ return `${getProxyPath()}/projects/${encodeURIComponent(String(projectId))}`;
842
1147
  };
843
1148
  /**
844
1149
  * Updates the state of a project.
845
-
846
1150
  * @summary Update project
847
1151
  */
848
1152
  const patchProject = async (projectId, patchProjectBody, options) => {
1153
+ const getHeaders = (h) => {
1154
+ if (!h) return {};
1155
+ if (h instanceof Headers) return Object.fromEntries(h.entries());
1156
+ if (Symbol.iterator in h) return Object.fromEntries(Array.from(h, (entry) => Array.from(entry)));
1157
+ const headers = {};
1158
+ for (const [name, value] of Object.entries(h)) if (value !== void 0) headers[name] = value;
1159
+ return headers;
1160
+ };
849
1161
  return customFetch(getPatchProjectUrl(projectId), {
850
1162
  ...options,
851
1163
  method: "PATCH",
852
1164
  headers: {
853
1165
  "Content-Type": "application/json",
854
- ...options?.headers
1166
+ ...getHeaders(options?.headers)
855
1167
  },
856
1168
  body: JSON.stringify(patchProjectBody)
857
1169
  });
858
1170
  };
859
1171
  const getInitClaimUrl = (projectId) => {
860
- return `${getProxyPath()}/projects/${projectId}/claim/init`;
1172
+ return `${getProxyPath()}/projects/${encodeURIComponent(String(projectId))}/claim/init`;
861
1173
  };
862
1174
  /**
863
1175
  * Starts a claim challenge for an unclaimed project. Authenticated by the
864
- project secret, this mints a single-use, short-lived challenge and returns
865
- the `claim_url` the developer opens in a browser to complete the claim,
866
- together with the `challenge_id` the CLI polls with. The exact expiry is
867
- carried by `expires_at` on the response.
868
-
1176
+ * project secret, this mints a single-use, short-lived challenge and returns
1177
+ * the `claim_url` the developer opens in a browser to complete the claim,
1178
+ * together with the `challenge_id` the CLI polls with. The exact expiry is
1179
+ * carried by `expires_at` on the response.
869
1180
  * @summary Initialize a project claim
870
1181
  */
871
1182
  const initClaim = async (projectId, options) => {
@@ -877,21 +1188,20 @@ const initClaim = async (projectId, options) => {
877
1188
  const getGetClaimStatusUrl = (projectId, params) => {
878
1189
  const normalizedParams = new URLSearchParams();
879
1190
  Object.entries(params || {}).forEach(([key, value]) => {
880
- if (value !== void 0) normalizedParams.append(key, value === null ? "null" : value.toString());
1191
+ if (value !== void 0) normalizedParams.append(key, value === null ? "null" : String(value));
881
1192
  });
882
1193
  const stringifiedParams = normalizedParams.toString();
883
- return stringifiedParams.length > 0 ? `${getProxyPath()}/projects/${projectId}/claim/status?${stringifiedParams}` : `${getProxyPath()}/projects/${projectId}/claim/status`;
1194
+ return stringifiedParams.length > 0 ? `${getProxyPath()}/projects/${encodeURIComponent(String(projectId))}/claim/status?${stringifiedParams}` : `${getProxyPath()}/projects/${encodeURIComponent(String(projectId))}/claim/status`;
884
1195
  };
885
1196
  /**
886
1197
  * Polled by the CLI while a browser completes the claim. Authorized by the
887
- project secret that initiated the challenge. Returns `pending`, or
888
- `completed` with the owning team, the claim timestamp, and the dashboard
889
- URL once the project is claimed. The claim grant, not the polled
890
- challenge, is the source of truth: a project claimed through another
891
- concurrent challenge also reports `completed`, and a completed claim
892
- keeps reporting `completed` past this challenge's expiry and past the
893
- project's claim window.
894
-
1198
+ * project secret that initiated the challenge. Returns `pending`, or
1199
+ * `completed` with the owning team, the claim timestamp, and the dashboard
1200
+ * URL once the project is claimed. The claim grant, not the polled
1201
+ * challenge, is the source of truth: a project claimed through another
1202
+ * concurrent challenge also reports `completed`, and a completed claim
1203
+ * keeps reporting `completed` past this challenge's expiry and past the
1204
+ * project's claim window.
895
1205
  * @summary Get claim status
896
1206
  */
897
1207
  const getClaimStatus = async (projectId, params, options) => {
@@ -901,23 +1211,30 @@ const getClaimStatus = async (projectId, params, options) => {
901
1211
  });
902
1212
  };
903
1213
  const getCompleteClaimUrl = (projectId) => {
904
- return `${getProxyPath()}/projects/${projectId}/claim/complete`;
1214
+ return `${getProxyPath()}/projects/${encodeURIComponent(String(projectId))}/claim/complete`;
905
1215
  };
906
1216
  /**
907
1217
  * Called by the browser after the developer authenticates on the claim page.
908
- Authenticated by the `__nextgen_session` cookie, it attaches the project to
909
- the developer's personal team using the `challenge_id` from the claim URL as
910
- its single-use, browser-safe authorization.
911
-
1218
+ * Authenticated by the `__nextgen_session` cookie, it attaches the project to
1219
+ * the developer's personal team using the `challenge_id` from the claim URL as
1220
+ * its single-use, browser-safe authorization.
912
1221
  * @summary Complete a project claim
913
1222
  */
914
1223
  const completeClaim = async (projectId, completeClaimBody, options) => {
1224
+ const getHeaders = (h) => {
1225
+ if (!h) return {};
1226
+ if (h instanceof Headers) return Object.fromEntries(h.entries());
1227
+ if (Symbol.iterator in h) return Object.fromEntries(Array.from(h, (entry) => Array.from(entry)));
1228
+ const headers = {};
1229
+ for (const [name, value] of Object.entries(h)) if (value !== void 0) headers[name] = value;
1230
+ return headers;
1231
+ };
915
1232
  return customFetch(getCompleteClaimUrl(projectId), {
916
1233
  ...options,
917
1234
  method: "POST",
918
1235
  headers: {
919
1236
  "Content-Type": "application/json",
920
- ...options?.headers
1237
+ ...getHeaders(options?.headers)
921
1238
  },
922
1239
  body: JSON.stringify(completeClaimBody)
923
1240
  });
@@ -925,19 +1242,18 @@ const completeClaim = async (projectId, completeClaimBody, options) => {
925
1242
  const getGetClaimWindowUrl = (projectId, params) => {
926
1243
  const normalizedParams = new URLSearchParams();
927
1244
  Object.entries(params || {}).forEach(([key, value]) => {
928
- if (value !== void 0) normalizedParams.append(key, value === null ? "null" : value.toString());
1245
+ if (value !== void 0) normalizedParams.append(key, value === null ? "null" : String(value));
929
1246
  });
930
1247
  const stringifiedParams = normalizedParams.toString();
931
- return stringifiedParams.length > 0 ? `${getProxyPath()}/projects/${projectId}/claim/window?${stringifiedParams}` : `${getProxyPath()}/projects/${projectId}/claim/window`;
1248
+ return stringifiedParams.length > 0 ? `${getProxyPath()}/projects/${encodeURIComponent(String(projectId))}/claim/window?${stringifiedParams}` : `${getProxyPath()}/projects/${encodeURIComponent(String(projectId))}/claim/window`;
932
1249
  };
933
1250
  /**
934
1251
  * Read by the claim page in the browser to show how long is left to claim the
935
- project. Unauthenticated by design: the claim page runs this before the
936
- developer has signed in, and holding the `challenge_id` from the claim URL
937
- is the authorization — the same capability `claim/complete` accepts. It
938
- reveals only the window, never the project itself, and unlike
939
- `claim/complete` it spends nothing, so a reload is free.
940
-
1252
+ * project. Unauthenticated by design: the claim page runs this before the
1253
+ * developer has signed in, and holding the `challenge_id` from the claim URL
1254
+ * is the authorization — the same capability `claim/complete` accepts. It
1255
+ * reveals only the window, never the project itself, and unlike
1256
+ * `claim/complete` it spends nothing, so a reload is free.
941
1257
  * @summary Get the claim window for a project
942
1258
  */
943
1259
  const getClaimWindow = async (projectId, params, options) => {
@@ -951,36 +1267,43 @@ const getCreateSessionUrl = () => {
951
1267
  };
952
1268
  /**
953
1269
  * Creates an anonymous session shell with no user and no factors (`state: building`).
954
-
955
- This is optional — an `auth_attempt` will create a session implicitly if none is provided.
956
- Use this explicitly when you want to:
957
- - Pre-allocate a `session_id` before the user is known, so device/telemetry signals
958
- can be correlated with the eventual authenticated session from the start.
959
- - Track anonymous state (bot detection, device fingerprint) that survives until authentication.
960
-
961
- Creating a session is an app-plane operation on the project credential
962
- (`session.write`). The returned `session_token` is a session credential for the
963
- end-user client, not a management scope: it is delivered as the
964
- `__nextgen_session` cookie and authorises the self-service operations
965
- `GET /sessions/me` and `DELETE /sessions/me` (`nextgenSession` scheme). The
966
- by-id operations `GET /sessions/{session_id}` and `DELETE /sessions/{session_id}`
967
- are operator endpoints and require `session.read` / `session.delete` instead.
968
-
969
- The `session_token` is superseded when a handoff exchange completes — clients must
970
- replace it at that point.
971
-
972
- Anonymous sessions expire aggressively (10-minute TTL). The TTL resets to the configured
973
- full session TTL when the first authentication factor is written via a completing `auth_attempt`.
974
-
1270
+ *
1271
+ * This is optional — an `auth_attempt` will create a session implicitly if none is provided.
1272
+ * Use this explicitly when you want to:
1273
+ * - Pre-allocate a `session_id` before the user is known, so device/telemetry signals
1274
+ * can be correlated with the eventual authenticated session from the start.
1275
+ * - Track anonymous state (bot detection, device fingerprint) that survives until authentication.
1276
+ *
1277
+ * Creating a session is an app-plane operation on the project credential
1278
+ * (`session.write`). The returned `session_token` is a session credential for the
1279
+ * end-user client, not a management scope: it is delivered as the
1280
+ * `__nextgen_session` cookie and authorises the self-service operations
1281
+ * `GET /sessions/me` and `DELETE /sessions/me` (`nextgenSession` scheme). The
1282
+ * by-id operations `GET /sessions/{session_id}` and `DELETE /sessions/{session_id}`
1283
+ * are operator endpoints and require `session.read` / `session.delete` instead.
1284
+ *
1285
+ * The `session_token` is superseded when a handoff exchange completes — clients must
1286
+ * replace it at that point.
1287
+ *
1288
+ * Anonymous sessions expire aggressively (10-minute TTL). The TTL resets to the configured
1289
+ * full session TTL when the first authentication factor is written via a completing `auth_attempt`.
975
1290
  * @summary Create an anonymous session shell
976
1291
  */
977
1292
  const createSession = async (createSessionBody, options) => {
1293
+ const getHeaders = (h) => {
1294
+ if (!h) return {};
1295
+ if (h instanceof Headers) return Object.fromEntries(h.entries());
1296
+ if (Symbol.iterator in h) return Object.fromEntries(Array.from(h, (entry) => Array.from(entry)));
1297
+ const headers = {};
1298
+ for (const [name, value] of Object.entries(h)) if (value !== void 0) headers[name] = value;
1299
+ return headers;
1300
+ };
978
1301
  return customFetch(getCreateSessionUrl(), {
979
1302
  ...options,
980
1303
  method: "POST",
981
1304
  headers: {
982
1305
  "Content-Type": "application/json",
983
- ...options?.headers
1306
+ ...getHeaders(options?.headers)
984
1307
  },
985
1308
  body: JSON.stringify(createSessionBody)
986
1309
  });
@@ -988,25 +1311,32 @@ const createSession = async (createSessionBody, options) => {
988
1311
  const getQuerySessionsUrl = (params) => {
989
1312
  const normalizedParams = new URLSearchParams();
990
1313
  Object.entries(params || {}).forEach(([key, value]) => {
991
- if (value !== void 0) normalizedParams.append(key, value === null ? "null" : value.toString());
1314
+ if (value !== void 0) normalizedParams.append(key, value === null ? "null" : String(value));
992
1315
  });
993
1316
  const stringifiedParams = normalizedParams.toString();
994
1317
  return stringifiedParams.length > 0 ? `${getProxyPath()}/sessions/query?${stringifiedParams}` : `${getProxyPath()}/sessions/query`;
995
1318
  };
996
1319
  /**
997
1320
  * Returns the sessions of a project, paginated with a cursor.
998
- Sessions of every lifecycle state are returned; each carries its `state`.
999
- Requires `session.read` permission.
1000
-
1321
+ * Sessions of every lifecycle state are returned; each carries its `state`.
1322
+ * Requires `session.read` permission.
1001
1323
  * @summary Query sessions
1002
1324
  */
1003
1325
  const querySessions = async (querySessionsBody, params, options) => {
1326
+ const getHeaders = (h) => {
1327
+ if (!h) return {};
1328
+ if (h instanceof Headers) return Object.fromEntries(h.entries());
1329
+ if (Symbol.iterator in h) return Object.fromEntries(Array.from(h, (entry) => Array.from(entry)));
1330
+ const headers = {};
1331
+ for (const [name, value] of Object.entries(h)) if (value !== void 0) headers[name] = value;
1332
+ return headers;
1333
+ };
1004
1334
  return customFetch(getQuerySessionsUrl(params), {
1005
1335
  ...options,
1006
1336
  method: "POST",
1007
1337
  headers: {
1008
1338
  "Content-Type": "application/json",
1009
- ...options?.headers
1339
+ ...getHeaders(options?.headers)
1010
1340
  },
1011
1341
  body: JSON.stringify(querySessionsBody)
1012
1342
  });
@@ -1014,54 +1344,60 @@ const querySessions = async (querySessionsBody, params, options) => {
1014
1344
  const getExchangeHandoffUrl = (params) => {
1015
1345
  const normalizedParams = new URLSearchParams();
1016
1346
  Object.entries(params || {}).forEach(([key, value]) => {
1017
- if (value !== void 0) normalizedParams.append(key, value === null ? "null" : value.toString());
1347
+ if (value !== void 0) normalizedParams.append(key, value === null ? "null" : String(value));
1018
1348
  });
1019
1349
  const stringifiedParams = normalizedParams.toString();
1020
1350
  return stringifiedParams.length > 0 ? `${getProxyPath()}/sessions/exchange?${stringifiedParams}` : `${getProxyPath()}/sessions/exchange`;
1021
1351
  };
1022
1352
  /**
1023
1353
  * Consumes a one-time `handoff_token` minted by `POST /auth_attempts/{id}/handoff`
1024
- and returns the resulting session and a `session_token`.
1025
-
1026
- The server resolves the originating `auth_attempt` from the token and then:
1027
-
1028
- | Originating auth_attempt | Outcome |
1029
- |---|---|
1030
- | No `session_id` | A new authenticated session is **created**. |
1031
- | `session_id` points to an anonymous shell | Existing session is **upgraded** — user and factors written in, TTL reset to full session TTL. |
1032
- | `session_id` points to an active session (step-up) | Existing session is **upgraded** — new factors merged, `assurance_levels[]` expanded. |
1033
-
1034
- The response shape is identical in all three cases.
1035
-
1036
- The `session_token` supersedes any previously issued `session_token` for the same session.
1037
- Clients must replace their stored token at this point.
1038
-
1039
- Requires a project service key (OAuth2 client credentials).
1040
-
1354
+ * and returns the resulting session and a `session_token`.
1355
+ *
1356
+ * The server resolves the originating `auth_attempt` from the token and then:
1357
+ *
1358
+ * | Originating auth_attempt | Outcome |
1359
+ * |---|---|
1360
+ * | No `session_id` | A new authenticated session is **created**. |
1361
+ * | `session_id` points to an anonymous shell | Existing session is **upgraded** — user and factors written in, TTL reset to full session TTL. |
1362
+ * | `session_id` points to an active session (step-up) | Existing session is **upgraded** — new factors merged, `assurance_levels[]` expanded. |
1363
+ *
1364
+ * The response shape is identical in all three cases.
1365
+ *
1366
+ * The `session_token` supersedes any previously issued `session_token` for the same session.
1367
+ * Clients must replace their stored token at this point.
1368
+ *
1369
+ * Requires a project service key (OAuth2 client credentials).
1041
1370
  * @summary Exchange handoff token for a session
1042
1371
  */
1043
1372
  const exchangeHandoff = async (exchangeHandoffBody, params, options) => {
1373
+ const getHeaders = (h) => {
1374
+ if (!h) return {};
1375
+ if (h instanceof Headers) return Object.fromEntries(h.entries());
1376
+ if (Symbol.iterator in h) return Object.fromEntries(Array.from(h, (entry) => Array.from(entry)));
1377
+ const headers = {};
1378
+ for (const [name, value] of Object.entries(h)) if (value !== void 0) headers[name] = value;
1379
+ return headers;
1380
+ };
1044
1381
  return customFetch(getExchangeHandoffUrl(params), {
1045
1382
  ...options,
1046
1383
  method: "POST",
1047
1384
  headers: {
1048
1385
  "Content-Type": "application/json",
1049
- ...options?.headers
1386
+ ...getHeaders(options?.headers)
1050
1387
  },
1051
1388
  body: JSON.stringify(exchangeHandoffBody)
1052
1389
  });
1053
1390
  };
1054
1391
  const getGetSessionUrl = (sessionId) => {
1055
- return `${getProxyPath()}/sessions/${sessionId}`;
1392
+ return `${getProxyPath()}/sessions/${encodeURIComponent(String(sessionId))}`;
1056
1393
  };
1057
1394
  /**
1058
1395
  * Returns the current state of a session including its factors and all currently
1059
- satisfied assurance levels.
1060
-
1061
- `assurance_levels[]` may shrink over time as factor freshness windows expire,
1062
- without the session itself expiring. Use step-up authentication (a new `auth_attempt`
1063
- against the same `session_id`) to restore a dropped assurance level.
1064
-
1396
+ * satisfied assurance levels.
1397
+ *
1398
+ * `assurance_levels[]` may shrink over time as factor freshness windows expire,
1399
+ * without the session itself expiring. Use step-up authentication (a new `auth_attempt`
1400
+ * against the same `session_id`) to restore a dropped assurance level.
1065
1401
  * @summary Get session state
1066
1402
  */
1067
1403
  const getSession = async (sessionId, options) => {
@@ -1071,19 +1407,18 @@ const getSession = async (sessionId, options) => {
1071
1407
  });
1072
1408
  };
1073
1409
  const getRevokeSessionUrl = (sessionId) => {
1074
- return `${getProxyPath()}/sessions/${sessionId}`;
1410
+ return `${getProxyPath()}/sessions/${encodeURIComponent(String(sessionId))}`;
1075
1411
  };
1076
1412
  /**
1077
1413
  * Permanently deletes the session, terminating it immediately.
1078
-
1079
- This is the operator revoke path and requires the `session.delete` scope on a
1080
- project-bound credential. End-user logout with the `__nextgen_session` cookie is
1081
- `DELETE /sessions/me` (`nextgenSession` scheme).
1082
-
1083
- Idempotent: deleting a session that does not exist (or was already deleted)
1084
- still returns 204. After deletion, any tokens derived from the session are
1085
- invalidated.
1086
-
1414
+ *
1415
+ * This is the operator revoke path and requires the `session.delete` scope on a
1416
+ * project-bound credential. End-user logout with the `__nextgen_session` cookie is
1417
+ * `DELETE /sessions/me` (`nextgenSession` scheme).
1418
+ *
1419
+ * Idempotent: deleting a session that does not exist (or was already deleted)
1420
+ * still returns 204. After deletion, any tokens derived from the session are
1421
+ * invalidated.
1087
1422
  * @summary Revoke session
1088
1423
  */
1089
1424
  const revokeSession = async (sessionId, options) => {
@@ -1097,12 +1432,11 @@ const getGetMySessionUrl = () => {
1097
1432
  };
1098
1433
  /**
1099
1434
  * Returns the current state of the current session including its factors and all currently
1100
- satisfied assurance levels.
1101
-
1102
- `assurance_levels[]` may shrink over time as factor freshness windows expire,
1103
- without the session itself expiring. Use step-up authentication (a new `auth_attempt`
1104
- against the same `session_id`) to restore a dropped assurance level.
1105
-
1435
+ * satisfied assurance levels.
1436
+ *
1437
+ * `assurance_levels[]` may shrink over time as factor freshness windows expire,
1438
+ * without the session itself expiring. Use step-up authentication (a new `auth_attempt`
1439
+ * against the same `session_id`) to restore a dropped assurance level.
1106
1440
  * @summary Get my session state
1107
1441
  */
1108
1442
  const getMySession = async (options) => {
@@ -1116,12 +1450,11 @@ const getRevokeMySessionUrl = () => {
1116
1450
  };
1117
1451
  /**
1118
1452
  * Logs out by permanently deleting the session.
1119
-
1120
- The `__nextgen_session` cookie issued at creation (or superseded by a handoff
1121
- exchange) is required. Idempotent: if the session is already gone this still
1122
- returns 204. Any tokens derived from the session are invalidated, and the
1123
- cookie itself is cleared in the response.
1124
-
1453
+ *
1454
+ * The `__nextgen_session` cookie issued at creation (or superseded by a handoff
1455
+ * exchange) is required. Idempotent: if the session is already gone this still
1456
+ * returns 204. Any tokens derived from the session are invalidated, and the
1457
+ * cookie itself is cleared in the response.
1125
1458
  * @summary Revoke my session
1126
1459
  */
1127
1460
  const revokeMySession = async (options) => {
@@ -1130,34 +1463,60 @@ const revokeMySession = async (options) => {
1130
1463
  method: "DELETE"
1131
1464
  });
1132
1465
  };
1466
+ const getGetMySessionCsrfTokenUrl = () => {
1467
+ return `${getProxyPath()}/sessions/me/csrf`;
1468
+ };
1469
+ /**
1470
+ * Returns the session-bound token for cross-site request forgery protection
1471
+ * (ADR 053 §5). Browser code sends it in the `X-Zitadel-CSRF` header on the
1472
+ * state-changing requests the session cookie authenticates that require it
1473
+ * — see the `nextgenSession` scheme. It authorizes nothing on its own: the
1474
+ * HttpOnly cookie is still the credential, and a cross-site page cannot
1475
+ * read this response. It stays the same for the life of the session, so a
1476
+ * client fetches it once per session.
1477
+ * @summary Get my session's CSRF token
1478
+ */
1479
+ const getMySessionCsrfToken = async (options) => {
1480
+ return customFetch(getGetMySessionCsrfTokenUrl(), {
1481
+ ...options,
1482
+ method: "GET"
1483
+ });
1484
+ };
1133
1485
  const getCreateSchemaUrl = (params) => {
1134
1486
  const normalizedParams = new URLSearchParams();
1135
1487
  Object.entries(params || {}).forEach(([key, value]) => {
1136
- if (value !== void 0) normalizedParams.append(key, value === null ? "null" : value.toString());
1488
+ if (value !== void 0) normalizedParams.append(key, value === null ? "null" : String(value));
1137
1489
  });
1138
1490
  const stringifiedParams = normalizedParams.toString();
1139
1491
  return stringifiedParams.length > 0 ? `${getProxyPath()}/schemas?${stringifiedParams}` : `${getProxyPath()}/schemas`;
1140
1492
  };
1141
1493
  /**
1142
1494
  * Create a new schema. The optional `$id` field is the JSON Schema document
1143
- URI used to identify the schema in future requests (GitOps-stable identity,
1144
- not a free-form resource primary key). When `$id` is omitted, the server
1145
- generates a `sch_*` URL. When provided, `$id` must be unique within the
1146
- project and should ideally be a valid URI pointing at where the schema can
1147
- be accessed.
1148
-
1149
- The schema can either be a concrete schema, e.g. a user schema, or a
1150
- schema-url which will be resolved by the server.
1151
-
1495
+ * URI used to identify the schema in future requests (GitOps-stable identity,
1496
+ * not a free-form resource primary key). When `$id` is omitted, the server
1497
+ * generates a `sch_*` URL. When provided, `$id` must be unique within the
1498
+ * project and should ideally be a valid URI pointing at where the schema can
1499
+ * be accessed.
1500
+ *
1501
+ * The schema can either be a concrete schema, e.g. a user schema, or a
1502
+ * schema-url which will be resolved by the server.
1152
1503
  * @summary Create new schema
1153
1504
  */
1154
1505
  const createSchema = async (createSchemaBody, params, options) => {
1506
+ const getHeaders = (h) => {
1507
+ if (!h) return {};
1508
+ if (h instanceof Headers) return Object.fromEntries(h.entries());
1509
+ if (Symbol.iterator in h) return Object.fromEntries(Array.from(h, (entry) => Array.from(entry)));
1510
+ const headers = {};
1511
+ for (const [name, value] of Object.entries(h)) if (value !== void 0) headers[name] = value;
1512
+ return headers;
1513
+ };
1155
1514
  return customFetch(getCreateSchemaUrl(params), {
1156
1515
  ...options,
1157
1516
  method: "POST",
1158
1517
  headers: {
1159
1518
  "Content-Type": "application/json",
1160
- ...options?.headers
1519
+ ...getHeaders(options?.headers)
1161
1520
  },
1162
1521
  body: JSON.stringify(createSchemaBody)
1163
1522
  });
@@ -1165,15 +1524,14 @@ const createSchema = async (createSchemaBody, params, options) => {
1165
1524
  const getListSchemasUrl = (params) => {
1166
1525
  const normalizedParams = new URLSearchParams();
1167
1526
  Object.entries(params || {}).forEach(([key, value]) => {
1168
- if (value !== void 0) normalizedParams.append(key, value === null ? "null" : value.toString());
1527
+ if (value !== void 0) normalizedParams.append(key, value === null ? "null" : String(value));
1169
1528
  });
1170
1529
  const stringifiedParams = normalizedParams.toString();
1171
1530
  return stringifiedParams.length > 0 ? `${getProxyPath()}/schemas?${stringifiedParams}` : `${getProxyPath()}/schemas`;
1172
1531
  };
1173
1532
  /**
1174
1533
  * Retrieve a list of all schemas available in the system. This endpoint
1175
- supports pagination and filtering based on schema attributes.
1176
-
1534
+ * supports pagination and filtering based on schema attributes.
1177
1535
  * @summary List all schemas
1178
1536
  */
1179
1537
  const listSchemas = async (params, options) => {
@@ -1185,16 +1543,22 @@ const listSchemas = async (params, options) => {
1185
1543
  const getGetSchemaByIdUrl = (id, params) => {
1186
1544
  const normalizedParams = new URLSearchParams();
1187
1545
  Object.entries(params || {}).forEach(([key, value]) => {
1188
- if (value !== void 0) normalizedParams.append(key, value === null ? "null" : value.toString());
1546
+ if (value !== void 0) normalizedParams.append(key, value === null ? "null" : String(value));
1189
1547
  });
1190
1548
  const stringifiedParams = normalizedParams.toString();
1191
- return stringifiedParams.length > 0 ? `${getProxyPath()}/schemas/${id}?${stringifiedParams}` : `${getProxyPath()}/schemas/${id}`;
1549
+ return stringifiedParams.length > 0 ? `${getProxyPath()}/schemas/${encodeURIComponent(String(id))}?${stringifiedParams}` : `${getProxyPath()}/schemas/${encodeURIComponent(String(id))}`;
1192
1550
  };
1193
1551
  /**
1194
1552
  * Get a schema by its ID. A schema ID identifies one immutable revision, so
1195
- this returns exactly that revision. To find the current revision of an
1196
- object type, list with `revisions=latest`.
1197
-
1553
+ * this returns exactly that revision. To find the current revision of an
1554
+ * object type, list with `revisions=latest`.
1555
+ *
1556
+ * Schema IDs are unique within a project, not across projects (the seeded
1557
+ * default schema carries the same `$id` in every project). A Console
1558
+ * session that manages more than one project names the project with
1559
+ * `project_id`; without it, the ID is resolved in the credential's own
1560
+ * project when it is ambiguous. A project secret always resolves in its
1561
+ * own project and ignores `project_id`.
1198
1562
  * @summary Get schema by ID
1199
1563
  */
1200
1564
  const getSchemaById = async (id, params, options) => {
@@ -1208,25 +1572,32 @@ const getCreateFlowDefinitionUrl = () => {
1208
1572
  };
1209
1573
  /**
1210
1574
  * Publishes a new flow definition revision.
1211
- Flow definitions are templates that define the sequence of steps (capabilities)
1212
- for a particular user journey (e.g., registration, login, password reset).
1213
-
1214
- Flow definitions are created based on the flow definition schema, which includes the flow's purpose, audience, and the steps involved.
1215
-
1216
- Every call allocates a new opaque id. Revisions of one flow share its
1217
- `name`; posting a definition under an existing `name` publishes a new
1218
- revision of that flow, it is not a conflict. List with `name` to see a
1219
- flow's revisions, newest by creation time first.
1220
-
1575
+ * Flow definitions are templates that define the sequence of steps (capabilities)
1576
+ * for a particular user journey (e.g., registration, login, password reset).
1577
+ *
1578
+ * Flow definitions are created based on the flow definition schema, which includes the flow's purpose, audience, and the steps involved.
1579
+ *
1580
+ * Every call allocates a new opaque id. Revisions of one flow share its
1581
+ * `name`; posting a definition under an existing `name` publishes a new
1582
+ * revision of that flow, it is not a conflict. List with `name` to see a
1583
+ * flow's revisions, newest by creation time first.
1221
1584
  * @summary Create a new flow definition
1222
1585
  */
1223
1586
  const createFlowDefinition = async (createFlowDefinitionBody, options) => {
1587
+ const getHeaders = (h) => {
1588
+ if (!h) return {};
1589
+ if (h instanceof Headers) return Object.fromEntries(h.entries());
1590
+ if (Symbol.iterator in h) return Object.fromEntries(Array.from(h, (entry) => Array.from(entry)));
1591
+ const headers = {};
1592
+ for (const [name, value] of Object.entries(h)) if (value !== void 0) headers[name] = value;
1593
+ return headers;
1594
+ };
1224
1595
  return customFetch(getCreateFlowDefinitionUrl(), {
1225
1596
  ...options,
1226
1597
  method: "POST",
1227
1598
  headers: {
1228
1599
  "Content-Type": "application/json",
1229
- ...options?.headers
1600
+ ...getHeaders(options?.headers)
1230
1601
  },
1231
1602
  body: JSON.stringify(createFlowDefinitionBody)
1232
1603
  });
@@ -1234,16 +1605,21 @@ const createFlowDefinition = async (createFlowDefinitionBody, options) => {
1234
1605
  const getListFlowDefinitionsUrl = (params) => {
1235
1606
  const normalizedParams = new URLSearchParams();
1236
1607
  Object.entries(params || {}).forEach(([key, value]) => {
1237
- if (value !== void 0) normalizedParams.append(key, value === null ? "null" : value.toString());
1608
+ if (Array.isArray(value) && ["expand"].includes(key)) {
1609
+ value.forEach((v) => {
1610
+ normalizedParams.append(key, v === null ? "null" : String(v));
1611
+ });
1612
+ return;
1613
+ }
1614
+ if (value !== void 0) normalizedParams.append(key, value === null ? "null" : String(value));
1238
1615
  });
1239
1616
  const stringifiedParams = normalizedParams.toString();
1240
1617
  return stringifiedParams.length > 0 ? `${getProxyPath()}/flow_definitions?${stringifiedParams}` : `${getProxyPath()}/flow_definitions`;
1241
1618
  };
1242
1619
  /**
1243
1620
  * Retrieves a list of all flow definitions, newest by creation time first.
1244
- This endpoint can be used to view existing flow definitions and their configurations.
1245
- Filter by `name` to list the revisions of one flow.
1246
-
1621
+ * This endpoint can be used to view existing flow definitions and their configurations.
1622
+ * Filter by `name` to list the revisions of one flow.
1247
1623
  * @summary List flow definitions
1248
1624
  */
1249
1625
  const listFlowDefinitions = async (params, options) => {
@@ -1253,7 +1629,7 @@ const listFlowDefinitions = async (params, options) => {
1253
1629
  });
1254
1630
  };
1255
1631
  const getGetFlowDefinitionUrl = (id) => {
1256
- return `${getProxyPath()}/flow_definitions/${id}`;
1632
+ return `${getProxyPath()}/flow_definitions/${encodeURIComponent(String(id))}`;
1257
1633
  };
1258
1634
  /**
1259
1635
  * Get a flow definition by id
@@ -1268,7 +1644,7 @@ const getFlowDefinition = async (id, options) => {
1268
1644
  const getCreateTeamUrl = (params) => {
1269
1645
  const normalizedParams = new URLSearchParams();
1270
1646
  Object.entries(params || {}).forEach(([key, value]) => {
1271
- if (value !== void 0) normalizedParams.append(key, value === null ? "null" : value.toString());
1647
+ if (value !== void 0) normalizedParams.append(key, value === null ? "null" : String(value));
1272
1648
  });
1273
1649
  const stringifiedParams = normalizedParams.toString();
1274
1650
  return stringifiedParams.length > 0 ? `${getProxyPath()}/teams?${stringifiedParams}` : `${getProxyPath()}/teams`;
@@ -1277,12 +1653,20 @@ const getCreateTeamUrl = (params) => {
1277
1653
  * @summary Create team
1278
1654
  */
1279
1655
  const createTeam = async (createTeamBody, params, options) => {
1656
+ const getHeaders = (h) => {
1657
+ if (!h) return {};
1658
+ if (h instanceof Headers) return Object.fromEntries(h.entries());
1659
+ if (Symbol.iterator in h) return Object.fromEntries(Array.from(h, (entry) => Array.from(entry)));
1660
+ const headers = {};
1661
+ for (const [name, value] of Object.entries(h)) if (value !== void 0) headers[name] = value;
1662
+ return headers;
1663
+ };
1280
1664
  return customFetch(getCreateTeamUrl(params), {
1281
1665
  ...options,
1282
1666
  method: "POST",
1283
1667
  headers: {
1284
1668
  "Content-Type": "application/json",
1285
- ...options?.headers
1669
+ ...getHeaders(options?.headers)
1286
1670
  },
1287
1671
  body: JSON.stringify(createTeamBody)
1288
1672
  });
@@ -1290,33 +1674,39 @@ const createTeam = async (createTeamBody, params, options) => {
1290
1674
  const getQueryTeamsUrl = (params) => {
1291
1675
  const normalizedParams = new URLSearchParams();
1292
1676
  Object.entries(params || {}).forEach(([key, value]) => {
1293
- if (value !== void 0) normalizedParams.append(key, value === null ? "null" : value.toString());
1677
+ if (value !== void 0) normalizedParams.append(key, value === null ? "null" : String(value));
1294
1678
  });
1295
1679
  const stringifiedParams = normalizedParams.toString();
1296
1680
  return stringifiedParams.length > 0 ? `${getProxyPath()}/teams/query?${stringifiedParams}` : `${getProxyPath()}/teams/query`;
1297
1681
  };
1298
1682
  /**
1299
1683
  * Returns the teams of a project, paginated with a cursor.
1300
-
1301
1684
  * @summary Query teams
1302
1685
  */
1303
1686
  const queryTeams = async (queryTeamsBody, params, options) => {
1687
+ const getHeaders = (h) => {
1688
+ if (!h) return {};
1689
+ if (h instanceof Headers) return Object.fromEntries(h.entries());
1690
+ if (Symbol.iterator in h) return Object.fromEntries(Array.from(h, (entry) => Array.from(entry)));
1691
+ const headers = {};
1692
+ for (const [name, value] of Object.entries(h)) if (value !== void 0) headers[name] = value;
1693
+ return headers;
1694
+ };
1304
1695
  return customFetch(getQueryTeamsUrl(params), {
1305
1696
  ...options,
1306
1697
  method: "POST",
1307
1698
  headers: {
1308
1699
  "Content-Type": "application/json",
1309
- ...options?.headers
1700
+ ...getHeaders(options?.headers)
1310
1701
  },
1311
1702
  body: JSON.stringify(queryTeamsBody)
1312
1703
  });
1313
1704
  };
1314
1705
  const getGetTeamUrl = (teamId) => {
1315
- return `${getProxyPath()}/teams/${teamId}`;
1706
+ return `${getProxyPath()}/teams/${encodeURIComponent(String(teamId))}`;
1316
1707
  };
1317
1708
  /**
1318
1709
  * Returns a Team by its id.
1319
-
1320
1710
  * @summary Get team
1321
1711
  */
1322
1712
  const getTeam = async (teamId, options) => {
@@ -1326,23 +1716,22 @@ const getTeam = async (teamId, options) => {
1326
1716
  });
1327
1717
  };
1328
1718
  const getDeleteTeamUrl = (teamId) => {
1329
- return `${getProxyPath()}/teams/${teamId}`;
1719
+ return `${getProxyPath()}/teams/${encodeURIComponent(String(teamId))}`;
1330
1720
  };
1331
1721
  /**
1332
1722
  * Deactivates the team.
1333
-
1334
- The team is tombstoned rather than erased: it stays readable through
1335
- getTeam with status `deactivated`. Its memberships are removed and the
1336
- users whose lifecycle it owns are deactivated with it.
1337
-
1338
- The request is idempotent. Deleting a team that is already deactivated
1339
- or doesn't exist succeeds without changing anything.
1340
-
1341
- A team that still owns a project is refused with `409
1342
- team.owns_project`: deactivating it would leave the project owned by a
1343
- dead team and so unmanageable. No endpoint releases that ownership yet,
1344
- so such a team cannot currently be deactivated through the API.
1345
-
1723
+ *
1724
+ * The team is tombstoned rather than erased: it stays readable through
1725
+ * getTeam with status `deactivated`. Its memberships are removed and the
1726
+ * users whose lifecycle it owns are deactivated with it.
1727
+ *
1728
+ * The request is idempotent. Deleting a team that is already deactivated
1729
+ * or doesn't exist succeeds without changing anything.
1730
+ *
1731
+ * A team that still owns a project is refused with `409
1732
+ * team.owns_project`: deactivating it would leave the project owned by a
1733
+ * dead team and so unmanageable. No endpoint releases that ownership yet,
1734
+ * so such a team cannot currently be deactivated through the API.
1346
1735
  * @summary Delete team
1347
1736
  */
1348
1737
  const deleteTeam = async (teamId, options) => {
@@ -1352,20 +1741,27 @@ const deleteTeam = async (teamId, options) => {
1352
1741
  });
1353
1742
  };
1354
1743
  const getUpdateTeamUrl = (teamId) => {
1355
- return `${getProxyPath()}/teams/${teamId}`;
1744
+ return `${getProxyPath()}/teams/${encodeURIComponent(String(teamId))}`;
1356
1745
  };
1357
1746
  /**
1358
1747
  * Update team. Only active teams can be updated.
1359
-
1360
1748
  * @summary Update team
1361
1749
  */
1362
1750
  const updateTeam = async (teamId, updateTeamBody, options) => {
1751
+ const getHeaders = (h) => {
1752
+ if (!h) return {};
1753
+ if (h instanceof Headers) return Object.fromEntries(h.entries());
1754
+ if (Symbol.iterator in h) return Object.fromEntries(Array.from(h, (entry) => Array.from(entry)));
1755
+ const headers = {};
1756
+ for (const [name, value] of Object.entries(h)) if (value !== void 0) headers[name] = value;
1757
+ return headers;
1758
+ };
1363
1759
  return customFetch(getUpdateTeamUrl(teamId), {
1364
1760
  ...options,
1365
1761
  method: "PATCH",
1366
1762
  headers: {
1367
1763
  "Content-Type": "application/json",
1368
- ...options?.headers
1764
+ ...getHeaders(options?.headers)
1369
1765
  },
1370
1766
  body: JSON.stringify(updateTeamBody)
1371
1767
  });
@@ -1373,14 +1769,13 @@ const updateTeam = async (teamId, updateTeamBody, options) => {
1373
1769
  const getListEnvironmentsUrl = (params) => {
1374
1770
  const normalizedParams = new URLSearchParams();
1375
1771
  Object.entries(params || {}).forEach(([key, value]) => {
1376
- if (value !== void 0) normalizedParams.append(key, value === null ? "null" : value.toString());
1772
+ if (value !== void 0) normalizedParams.append(key, value === null ? "null" : String(value));
1377
1773
  });
1378
1774
  const stringifiedParams = normalizedParams.toString();
1379
1775
  return stringifiedParams.length > 0 ? `${getProxyPath()}/environments?${stringifiedParams}` : `${getProxyPath()}/environments`;
1380
1776
  };
1381
1777
  /**
1382
1778
  * Lists the project's environments ordered by name.
1383
-
1384
1779
  * @summary List environments
1385
1780
  */
1386
1781
  const listEnvironments = async (params, options) => {
@@ -1392,17 +1787,16 @@ const listEnvironments = async (params, options) => {
1392
1787
  const getGetEnvironmentByNameUrl = (name, params) => {
1393
1788
  const normalizedParams = new URLSearchParams();
1394
1789
  Object.entries(params || {}).forEach(([key, value]) => {
1395
- if (value !== void 0) normalizedParams.append(key, value === null ? "null" : value.toString());
1790
+ if (value !== void 0) normalizedParams.append(key, value === null ? "null" : String(value));
1396
1791
  });
1397
1792
  const stringifiedParams = normalizedParams.toString();
1398
- return stringifiedParams.length > 0 ? `${getProxyPath()}/environments/${name}?${stringifiedParams}` : `${getProxyPath()}/environments/${name}`;
1793
+ return stringifiedParams.length > 0 ? `${getProxyPath()}/environments/${encodeURIComponent(String(name))}?${stringifiedParams}` : `${getProxyPath()}/environments/${encodeURIComponent(String(name))}`;
1399
1794
  };
1400
1795
  /**
1401
1796
  * Reads one environment of the project by its name.
1402
-
1403
- The lookup is scoped to the project in `project_id`: a name that exists in
1404
- another project answers `env.not_found` exactly as an unused name does.
1405
-
1797
+ *
1798
+ * The lookup is scoped to the project in `project_id`: a name that exists in
1799
+ * another project answers `env.not_found` exactly as an unused name does.
1406
1800
  * @summary Get an environment by name
1407
1801
  */
1408
1802
  const getEnvironmentByName = async (name, params, options) => {
@@ -1414,30 +1808,37 @@ const getEnvironmentByName = async (name, params, options) => {
1414
1808
  const getCreateBrandingUrl = (params) => {
1415
1809
  const normalizedParams = new URLSearchParams();
1416
1810
  Object.entries(params || {}).forEach(([key, value]) => {
1417
- if (value !== void 0) normalizedParams.append(key, value === null ? "null" : value.toString());
1811
+ if (value !== void 0) normalizedParams.append(key, value === null ? "null" : String(value));
1418
1812
  });
1419
1813
  const stringifiedParams = normalizedParams.toString();
1420
1814
  return stringifiedParams.length > 0 ? `${getProxyPath()}/branding?${stringifiedParams}` : `${getProxyPath()}/branding`;
1421
1815
  };
1422
1816
  /**
1423
1817
  * Publishes a new immutable branding revision for the project. Branding
1424
- revisions cannot be updated or deleted; every edit publishes a new
1425
- revision, and flow responses resolve the latest revision per project.
1426
-
1427
- The `liquid_template` is validated lexically on save (size, encoding,
1428
- banned patterns such as `<script>` tags, inline event handlers, and the
1429
- `| raw` filter). Authoritative LiquidJS validation runs at authoring
1430
- time via `zitadel plan` / `zitadel apply`.
1431
-
1818
+ * revisions cannot be updated or deleted; every edit publishes a new
1819
+ * revision, and flow responses resolve the latest revision per project.
1820
+ *
1821
+ * The `liquid_template` is validated lexically on save (size, encoding,
1822
+ * banned patterns such as `<script>` tags, inline event handlers, and the
1823
+ * `| raw` filter). Authoritative LiquidJS validation runs at authoring
1824
+ * time via `zitadel plan` / `zitadel apply`.
1432
1825
  * @summary Publish a new branding revision
1433
1826
  */
1434
1827
  const createBranding = async (createBrandingBody, params, options) => {
1828
+ const getHeaders = (h) => {
1829
+ if (!h) return {};
1830
+ if (h instanceof Headers) return Object.fromEntries(h.entries());
1831
+ if (Symbol.iterator in h) return Object.fromEntries(Array.from(h, (entry) => Array.from(entry)));
1832
+ const headers = {};
1833
+ for (const [name, value] of Object.entries(h)) if (value !== void 0) headers[name] = value;
1834
+ return headers;
1835
+ };
1435
1836
  return customFetch(getCreateBrandingUrl(params), {
1436
1837
  ...options,
1437
1838
  method: "POST",
1438
1839
  headers: {
1439
1840
  "Content-Type": "application/json",
1440
- ...options?.headers
1841
+ ...getHeaders(options?.headers)
1441
1842
  },
1442
1843
  body: JSON.stringify(createBrandingBody)
1443
1844
  });
@@ -1445,18 +1846,17 @@ const createBranding = async (createBrandingBody, params, options) => {
1445
1846
  const getListBrandingUrl = (params) => {
1446
1847
  const normalizedParams = new URLSearchParams();
1447
1848
  Object.entries(params || {}).forEach(([key, value]) => {
1448
- if (value !== void 0) normalizedParams.append(key, value === null ? "null" : value.toString());
1849
+ if (value !== void 0) normalizedParams.append(key, value === null ? "null" : String(value));
1449
1850
  });
1450
1851
  const stringifiedParams = normalizedParams.toString();
1451
1852
  return stringifiedParams.length > 0 ? `${getProxyPath()}/branding?${stringifiedParams}` : `${getProxyPath()}/branding`;
1452
1853
  };
1453
1854
  /**
1454
1855
  * Lists branding revisions for the project, newest first, capped at the
1455
- 100 most recent. The first entry is the revision flow responses
1456
- currently resolve. Deliberately unpaginated in v1 — list endpoints gain a
1457
- real query mechanism together; advertising pagination parameters the
1458
- server ignores would be worse than none.
1459
-
1856
+ * 100 most recent. The first entry is the revision flow responses
1857
+ * currently resolve. Deliberately unpaginated in v1 — list endpoints gain a
1858
+ * real query mechanism together; advertising pagination parameters the
1859
+ * server ignores would be worse than none.
1460
1860
  * @summary List branding revisions
1461
1861
  */
1462
1862
  const listBranding = async (params, options) => {
@@ -1466,7 +1866,7 @@ const listBranding = async (params, options) => {
1466
1866
  });
1467
1867
  };
1468
1868
  const getGetBrandingByIdUrl = (id) => {
1469
- return `${getProxyPath()}/branding/${id}`;
1869
+ return `${getProxyPath()}/branding/${encodeURIComponent(String(id))}`;
1470
1870
  };
1471
1871
  /**
1472
1872
  * Retrieves a single branding revision, including its stored configuration.
@@ -1481,44 +1881,51 @@ const getBrandingById = async (id, options) => {
1481
1881
  const getCreateIdpUrl = (params) => {
1482
1882
  const normalizedParams = new URLSearchParams();
1483
1883
  Object.entries(params || {}).forEach(([key, value]) => {
1484
- if (value !== void 0) normalizedParams.append(key, value === null ? "null" : value.toString());
1884
+ if (value !== void 0) normalizedParams.append(key, value === null ? "null" : String(value));
1485
1885
  });
1486
1886
  const stringifiedParams = normalizedParams.toString();
1487
1887
  return stringifiedParams.length > 0 ? `${getProxyPath()}/idps?${stringifiedParams}` : `${getProxyPath()}/idps`;
1488
1888
  };
1489
1889
  /**
1490
1890
  * Creates or revises a connection document. If the slug does not already
1491
- exist, a new connection is created. If a connection with that slug already
1492
- exists, a revision is created.
1493
-
1494
- A revision gets a new `revision_id` and does not modify the connection
1495
- `id`, so identity links that reference the connection keep resolving while
1496
- releases and auth attempts stay pinned to the revision they captured.
1497
-
1498
- Identity fields are fixed for the life of the connection and a revision
1499
- that changes one is rejected: `protocol`, `subject_claim`, and the
1500
- endpoints that name the authority (`issuer` for OIDC, `token_endpoint`
1501
- and `userinfo_endpoint` for OAuth 2.0). Their values decide which provider
1502
- account a stored subject belongs to, so changing one would silently
1503
- repoint existing identities at a different provider.
1504
-
1505
- `subject_claim` is optional for OIDC and required for OAuth 2.0. For an
1506
- OIDC connection, `sub` is used as the default value. If a revision updates
1507
- `subject_claim` to a different value than the one set during creation, the
1508
- request is rejected.
1509
-
1510
- The document is validated against the `idp-connection.json` schema before
1511
- anything is stored.
1512
-
1891
+ * exist, a new connection is created. If a connection with that slug already
1892
+ * exists, a revision is created.
1893
+ *
1894
+ * A revision gets a new `revision_id` and does not modify the connection
1895
+ * `id`, so identity links that reference the connection keep resolving while
1896
+ * releases and auth attempts stay pinned to the revision they captured.
1897
+ *
1898
+ * Identity fields are fixed for the life of the connection and a revision
1899
+ * that changes one is rejected: `protocol`, `subject_claim`, and the
1900
+ * endpoints that name the authority (`issuer` for OIDC, `token_endpoint`
1901
+ * and `userinfo_endpoint` for OAuth 2.0). Their values decide which provider
1902
+ * account a stored subject belongs to, so changing one would silently
1903
+ * repoint existing identities at a different provider.
1904
+ *
1905
+ * `subject_claim` is optional for OIDC and required for OAuth 2.0. For an
1906
+ * OIDC connection, `sub` is used as the default value. If a revision updates
1907
+ * `subject_claim` to a different value than the one set during creation, the
1908
+ * request is rejected.
1909
+ *
1910
+ * The document is validated against the `idp-connection.json` schema before
1911
+ * anything is stored.
1513
1912
  * @summary Create or revise an identity provider connection
1514
1913
  */
1515
1914
  const createIdp = async (createIdpBody, params, options) => {
1915
+ const getHeaders = (h) => {
1916
+ if (!h) return {};
1917
+ if (h instanceof Headers) return Object.fromEntries(h.entries());
1918
+ if (Symbol.iterator in h) return Object.fromEntries(Array.from(h, (entry) => Array.from(entry)));
1919
+ const headers = {};
1920
+ for (const [name, value] of Object.entries(h)) if (value !== void 0) headers[name] = value;
1921
+ return headers;
1922
+ };
1516
1923
  return customFetch(getCreateIdpUrl(params), {
1517
1924
  ...options,
1518
1925
  method: "POST",
1519
1926
  headers: {
1520
1927
  "Content-Type": "application/json",
1521
- ...options?.headers
1928
+ ...getHeaders(options?.headers)
1522
1929
  },
1523
1930
  body: JSON.stringify(createIdpBody)
1524
1931
  });
@@ -1526,24 +1933,31 @@ const createIdp = async (createIdpBody, params, options) => {
1526
1933
  const getQueryIdpsUrl = (params) => {
1527
1934
  const normalizedParams = new URLSearchParams();
1528
1935
  Object.entries(params || {}).forEach(([key, value]) => {
1529
- if (value !== void 0) normalizedParams.append(key, value === null ? "null" : value.toString());
1936
+ if (value !== void 0) normalizedParams.append(key, value === null ? "null" : String(value));
1530
1937
  });
1531
1938
  const stringifiedParams = normalizedParams.toString();
1532
1939
  return stringifiedParams.length > 0 ? `${getProxyPath()}/idps/query?${stringifiedParams}` : `${getProxyPath()}/idps/query`;
1533
1940
  };
1534
1941
  /**
1535
1942
  * Returns the identity provider connections of a project, paginated with a
1536
- cursor. One row per connection, carrying its newest revision.
1537
-
1943
+ * cursor. One row per connection, carrying its newest revision.
1538
1944
  * @summary Query identity provider connections
1539
1945
  */
1540
1946
  const queryIdps = async (queryIdpsBody, params, options) => {
1947
+ const getHeaders = (h) => {
1948
+ if (!h) return {};
1949
+ if (h instanceof Headers) return Object.fromEntries(h.entries());
1950
+ if (Symbol.iterator in h) return Object.fromEntries(Array.from(h, (entry) => Array.from(entry)));
1951
+ const headers = {};
1952
+ for (const [name, value] of Object.entries(h)) if (value !== void 0) headers[name] = value;
1953
+ return headers;
1954
+ };
1541
1955
  return customFetch(getQueryIdpsUrl(params), {
1542
1956
  ...options,
1543
1957
  method: "POST",
1544
1958
  headers: {
1545
1959
  "Content-Type": "application/json",
1546
- ...options?.headers
1960
+ ...getHeaders(options?.headers)
1547
1961
  },
1548
1962
  body: JSON.stringify(queryIdpsBody)
1549
1963
  });
@@ -1551,17 +1965,16 @@ const queryIdps = async (queryIdpsBody, params, options) => {
1551
1965
  const getGetIdpByIdUrl = (id, params) => {
1552
1966
  const normalizedParams = new URLSearchParams();
1553
1967
  Object.entries(params || {}).forEach(([key, value]) => {
1554
- if (value !== void 0) normalizedParams.append(key, value === null ? "null" : value.toString());
1968
+ if (value !== void 0) normalizedParams.append(key, value === null ? "null" : String(value));
1555
1969
  });
1556
1970
  const stringifiedParams = normalizedParams.toString();
1557
- return stringifiedParams.length > 0 ? `${getProxyPath()}/idps/${id}?${stringifiedParams}` : `${getProxyPath()}/idps/${id}`;
1971
+ return stringifiedParams.length > 0 ? `${getProxyPath()}/idps/${encodeURIComponent(String(id))}?${stringifiedParams}` : `${getProxyPath()}/idps/${encodeURIComponent(String(id))}`;
1558
1972
  };
1559
1973
  /**
1560
1974
  * Reads a connection by its id, at its newest revision.
1561
- `GET /idps/{id}/revisions` lists every revision of the connection.
1562
-
1563
- The lookup is scoped to the project in `project_id`.
1564
-
1975
+ * `GET /idps/{id}/revisions` lists every revision of the connection.
1976
+ *
1977
+ * The lookup is scoped to the project in `project_id`.
1565
1978
  * @summary Get an identity provider connection by id
1566
1979
  */
1567
1980
  const getIdpById = async (id, params, options) => {
@@ -1573,17 +1986,16 @@ const getIdpById = async (id, params, options) => {
1573
1986
  const getListIdpRevisionsUrl = (id, params) => {
1574
1987
  const normalizedParams = new URLSearchParams();
1575
1988
  Object.entries(params || {}).forEach(([key, value]) => {
1576
- if (value !== void 0) normalizedParams.append(key, value === null ? "null" : value.toString());
1989
+ if (value !== void 0) normalizedParams.append(key, value === null ? "null" : String(value));
1577
1990
  });
1578
1991
  const stringifiedParams = normalizedParams.toString();
1579
- return stringifiedParams.length > 0 ? `${getProxyPath()}/idps/${id}/revisions?${stringifiedParams}` : `${getProxyPath()}/idps/${id}/revisions`;
1992
+ return stringifiedParams.length > 0 ? `${getProxyPath()}/idps/${encodeURIComponent(String(id))}/revisions?${stringifiedParams}` : `${getProxyPath()}/idps/${encodeURIComponent(String(id))}/revisions`;
1580
1993
  };
1581
1994
  /**
1582
1995
  * Returns every revision of one connection, newest first, paginated with a
1583
- cursor. The order is fixed, so there is no `sorting`.
1584
-
1585
- The lookup is scoped to the project in `project_id`.
1586
-
1996
+ * cursor. The order is fixed, so there is no `sorting`.
1997
+ *
1998
+ * The lookup is scoped to the project in `project_id`.
1587
1999
  * @summary List the revisions of an identity provider connection
1588
2000
  */
1589
2001
  const listIdpRevisions = async (id, params, options) => {
@@ -1595,17 +2007,16 @@ const listIdpRevisions = async (id, params, options) => {
1595
2007
  const getGetIdpRevisionByIdUrl = (revisionId, params) => {
1596
2008
  const normalizedParams = new URLSearchParams();
1597
2009
  Object.entries(params || {}).forEach(([key, value]) => {
1598
- if (value !== void 0) normalizedParams.append(key, value === null ? "null" : value.toString());
2010
+ if (value !== void 0) normalizedParams.append(key, value === null ? "null" : String(value));
1599
2011
  });
1600
2012
  const stringifiedParams = normalizedParams.toString();
1601
- return stringifiedParams.length > 0 ? `${getProxyPath()}/idps/revisions/${revisionId}?${stringifiedParams}` : `${getProxyPath()}/idps/revisions/${revisionId}`;
2013
+ return stringifiedParams.length > 0 ? `${getProxyPath()}/idps/revisions/${encodeURIComponent(String(revisionId))}?${stringifiedParams}` : `${getProxyPath()}/idps/revisions/${encodeURIComponent(String(revisionId))}`;
1602
2014
  };
1603
2015
  /**
1604
2016
  * Reads one revision of a connection by its `revision_id`, the value an auth
1605
- attempt or a release pins.
1606
-
1607
- The lookup is scoped to the project in `project_id`.
1608
-
2017
+ * attempt or a release pins.
2018
+ *
2019
+ * The lookup is scoped to the project in `project_id`.
1609
2020
  * @summary Get one revision of an identity provider connection
1610
2021
  */
1611
2022
  const getIdpRevisionById = async (revisionId, params, options) => {
@@ -1617,37 +2028,44 @@ const getIdpRevisionById = async (revisionId, params, options) => {
1617
2028
  const getCreateReleaseUrl = (params) => {
1618
2029
  const normalizedParams = new URLSearchParams();
1619
2030
  Object.entries(params || {}).forEach(([key, value]) => {
1620
- if (value !== void 0) normalizedParams.append(key, value === null ? "null" : value.toString());
2031
+ if (value !== void 0) normalizedParams.append(key, value === null ? "null" : String(value));
1621
2032
  });
1622
2033
  const stringifiedParams = normalizedParams.toString();
1623
2034
  return stringifiedParams.length > 0 ? `${getProxyPath()}/releases?${stringifiedParams}` : `${getProxyPath()}/releases`;
1624
2035
  };
1625
2036
  /**
1626
2037
  * Bundles a release from revisions that already exist, supplied as
1627
- `(kind, revision_id)` pairs. No new revisions are allocated — use the
1628
- per-kind create endpoints for that, then pin the ids here.
1629
-
1630
- Every referenced `revision_id` must exist in the project. Each one's handle
1631
- is read from the revision itself and recorded on the release, so a resource
1632
- is always pinned under the identity it declares.
1633
-
1634
- Creating a release does not deploy it. A release is environment-agnostic
1635
- and the same release can later be deployed to any number of environments
1636
- unchanged.
1637
-
1638
- Idempotent on the pinned set: metadata is excluded from the comparison, so
1639
- re-submitting the same revisions with a different `message` returns the
1640
- release that already pins them rather than creating a second one.
1641
-
2038
+ * `(kind, revision_id)` pairs. No new revisions are allocated — use the
2039
+ * per-kind create endpoints for that, then pin the ids here.
2040
+ *
2041
+ * Every referenced `revision_id` must exist in the project. Each one's handle
2042
+ * is read from the revision itself and recorded on the release, so a resource
2043
+ * is always pinned under the identity it declares.
2044
+ *
2045
+ * Creating a release does not deploy it. A release is environment-agnostic
2046
+ * and the same release can later be deployed to any number of environments
2047
+ * unchanged.
2048
+ *
2049
+ * Idempotent on the pinned set: metadata is excluded from the comparison, so
2050
+ * re-submitting the same revisions with a different `message` returns the
2051
+ * release that already pins them rather than creating a second one.
1642
2052
  * @summary Create a release
1643
2053
  */
1644
2054
  const createRelease = async (createReleaseBody, params, options) => {
2055
+ const getHeaders = (h) => {
2056
+ if (!h) return {};
2057
+ if (h instanceof Headers) return Object.fromEntries(h.entries());
2058
+ if (Symbol.iterator in h) return Object.fromEntries(Array.from(h, (entry) => Array.from(entry)));
2059
+ const headers = {};
2060
+ for (const [name, value] of Object.entries(h)) if (value !== void 0) headers[name] = value;
2061
+ return headers;
2062
+ };
1645
2063
  return customFetch(getCreateReleaseUrl(params), {
1646
2064
  ...options,
1647
2065
  method: "POST",
1648
2066
  headers: {
1649
2067
  "Content-Type": "application/json",
1650
- ...options?.headers
2068
+ ...getHeaders(options?.headers)
1651
2069
  },
1652
2070
  body: JSON.stringify(createReleaseBody)
1653
2071
  });
@@ -1655,17 +2073,16 @@ const createRelease = async (createReleaseBody, params, options) => {
1655
2073
  const getListReleasesUrl = (params) => {
1656
2074
  const normalizedParams = new URLSearchParams();
1657
2075
  Object.entries(params || {}).forEach(([key, value]) => {
1658
- if (value !== void 0) normalizedParams.append(key, value === null ? "null" : value.toString());
2076
+ if (value !== void 0) normalizedParams.append(key, value === null ? "null" : String(value));
1659
2077
  });
1660
2078
  const stringifiedParams = normalizedParams.toString();
1661
2079
  return stringifiedParams.length > 0 ? `${getProxyPath()}/releases?${stringifiedParams}` : `${getProxyPath()}/releases`;
1662
2080
  };
1663
2081
  /**
1664
2082
  * Lists the project's releases, newest first.
1665
-
1666
- Entries carry metadata only — the pinned set is omitted. Read one release
1667
- with `GET /releases/{release_id}` to get its pointers.
1668
-
2083
+ *
2084
+ * Entries carry metadata only — the pinned set is omitted. Read one release
2085
+ * with `GET /releases/{release_id}` to get its pointers.
1669
2086
  * @summary List releases
1670
2087
  */
1671
2088
  const listReleases = async (params, options) => {
@@ -1677,23 +2094,22 @@ const listReleases = async (params, options) => {
1677
2094
  const getGetReleaseByIdUrl = (releaseId, params) => {
1678
2095
  const normalizedParams = new URLSearchParams();
1679
2096
  Object.entries(params || {}).forEach(([key, value]) => {
1680
- if (value !== void 0) normalizedParams.append(key, value === null ? "null" : value.toString());
2097
+ if (value !== void 0) normalizedParams.append(key, value === null ? "null" : String(value));
1681
2098
  });
1682
2099
  const stringifiedParams = normalizedParams.toString();
1683
- return stringifiedParams.length > 0 ? `${getProxyPath()}/releases/${releaseId}?${stringifiedParams}` : `${getProxyPath()}/releases/${releaseId}`;
2100
+ return stringifiedParams.length > 0 ? `${getProxyPath()}/releases/${encodeURIComponent(String(releaseId))}?${stringifiedParams}` : `${getProxyPath()}/releases/${encodeURIComponent(String(releaseId))}`;
1684
2101
  };
1685
2102
  /**
1686
2103
  * Reads one release: its metadata and the `(kind, handle, revision_id)`
1687
- tuples it pins.
1688
-
1689
- Does not embed resource content. Resolve each `revision_id` through the
1690
- per-kind read endpoints when the bytes are needed.
1691
-
1692
- The lookup is scoped to the project in `project_id`: a release id belonging
1693
- to another project answers not found exactly as an unknown id does, so the
1694
- endpoint cannot be used to probe for releases in projects the caller cannot
1695
- read.
1696
-
2104
+ * tuples it pins.
2105
+ *
2106
+ * Does not embed resource content. Resolve each `revision_id` through the
2107
+ * per-kind read endpoints when the bytes are needed.
2108
+ *
2109
+ * The lookup is scoped to the project in `project_id`: a release id belonging
2110
+ * to another project answers not found exactly as an unknown id does, so the
2111
+ * endpoint cannot be used to probe for releases in projects the caller cannot
2112
+ * read.
1697
2113
  * @summary Get a release by id
1698
2114
  */
1699
2115
  const getReleaseById = async (releaseId, params, options) => {
@@ -1705,41 +2121,48 @@ const getReleaseById = async (releaseId, params, options) => {
1705
2121
  const getCreateGrantUrl = (params) => {
1706
2122
  const normalizedParams = new URLSearchParams();
1707
2123
  Object.entries(params || {}).forEach(([key, value]) => {
1708
- if (value !== void 0) normalizedParams.append(key, value === null ? "null" : value.toString());
2124
+ if (value !== void 0) normalizedParams.append(key, value === null ? "null" : String(value));
1709
2125
  });
1710
2126
  const stringifiedParams = normalizedParams.toString();
1711
2127
  return stringifiedParams.length > 0 ? `${getProxyPath()}/grants?${stringifiedParams}` : `${getProxyPath()}/grants`;
1712
2128
  };
1713
2129
  /**
1714
2130
  * Bind a user or team to `project.viewer`, `project.editor`, or
1715
- `project.admin` on the project identified by the `project-id` header.
1716
- Name the principal with `user` (`user_id` or `identifier`) or `team`
1717
- (`team_id` or `name`). IDs are `asgn_<opaque>`. Owning-team
1718
- (`project.team`) grants are not created here — claim owns that path. An
1719
- unrevoked grant with the same principal and relation occupies the unique
1720
- key even after `expires_at`; DELETE it before re-creating.
1721
- Create does not accept `expand`. The `user_id` and team locators
1722
- return 201, whose `user` / `team` carry only `user_id` / `team_id`,
1723
- and still 404 / 409 when the principal is missing or the tuple
1724
- already exists. Creating by `user.identifier` answers 202 with no
1725
- body on every outcome. Granting the session caller's own user is
1726
- `grant.invalid` on either user locator. Read the grant back for
1727
- identifier and display.
1728
-
1729
- Accepts either a project secret (`oauth2`) or a user-bound Console
1730
- session cookie (`nextgenSession`). Session callers are authorized as
1731
- the human against the target project (home may differ). CSRF/Origin
1732
- for cookie mutations is a follow-up (#1140).
1733
-
2131
+ * `project.admin` on the project identified by the `project-id` header.
2132
+ * Name the principal with `user` (`user_id` or `identifier`) or `team`
2133
+ * (`team_id` or `name`). IDs are `asgn_<opaque>`. Owning-team
2134
+ * (`project.team`) grants are not created here — claim owns that path. An
2135
+ * unrevoked grant with the same principal and relation occupies the unique
2136
+ * key even after `expires_at`; DELETE it before re-creating.
2137
+ * Create does not accept `expand`. The `user_id` and team locators
2138
+ * return 201, whose `user` / `team` carry only `user_id` / `team_id`,
2139
+ * and still 404 / 409 when the principal is missing or the tuple
2140
+ * already exists. Creating by `user.identifier` answers 202 with no
2141
+ * body on every outcome. Granting the session caller's own user is
2142
+ * `grant.invalid` on either user locator. Read the grant back for
2143
+ * identifier and display.
2144
+ *
2145
+ * Accepts either a project secret (`oauth2`) or a user-bound Console
2146
+ * session cookie (`nextgenSession`). Session callers are authorized as
2147
+ * the human against the target project (home may differ). Cookie-authenticated
2148
+ * requests follow the scheme's CSRF rules (`nextgenSession`).
1734
2149
  * @summary Create grant
1735
2150
  */
1736
2151
  const createGrant = async (createGrantBody, params, options) => {
2152
+ const getHeaders = (h) => {
2153
+ if (!h) return {};
2154
+ if (h instanceof Headers) return Object.fromEntries(h.entries());
2155
+ if (Symbol.iterator in h) return Object.fromEntries(Array.from(h, (entry) => Array.from(entry)));
2156
+ const headers = {};
2157
+ for (const [name, value] of Object.entries(h)) if (value !== void 0) headers[name] = value;
2158
+ return headers;
2159
+ };
1737
2160
  return customFetch(getCreateGrantUrl(params), {
1738
2161
  ...options,
1739
2162
  method: "POST",
1740
2163
  headers: {
1741
2164
  "Content-Type": "application/json",
1742
- ...options?.headers
2165
+ ...getHeaders(options?.headers)
1743
2166
  },
1744
2167
  body: JSON.stringify(createGrantBody)
1745
2168
  });
@@ -1747,38 +2170,45 @@ const createGrant = async (createGrantBody, params, options) => {
1747
2170
  const getQueryGrantsUrl = (params) => {
1748
2171
  const normalizedParams = new URLSearchParams();
1749
2172
  Object.entries(params || {}).forEach(([key, value]) => {
1750
- if (value !== void 0) normalizedParams.append(key, value === null ? "null" : value.toString());
2173
+ if (value !== void 0) normalizedParams.append(key, value === null ? "null" : String(value));
1751
2174
  });
1752
2175
  const stringifiedParams = normalizedParams.toString();
1753
2176
  return stringifiedParams.length > 0 ? `${getProxyPath()}/grants/query?${stringifiedParams}` : `${getProxyPath()}/grants/query`;
1754
2177
  };
1755
2178
  /**
1756
2179
  * Returns the collaboration grants of a project, paginated with a cursor.
1757
- Only unrevoked grants this API manages are listed (user or team bound to
1758
- viewer, editor, or admin), including expired grants so a client can
1759
- DELETE before re-granting. Project-secret setup (`sk_proj`) and
1760
- owning-team (`relation=team`) rows are not returned. Grants are not in
1761
- `resource_scope_index`; project scope is required on the query (same as
1762
- get). Requires `project.read`. `expand: ["principal"]` adds envelope
1763
- fields on `user` / `team` and additionally requires `user.read` and
1764
- `team.read` for project secrets (documented on the expand enum; those
1765
- scopes cannot be ANDed onto this security block because they are
1766
- body-conditional). A user-bound Console session that already passed
1767
- the project Check may expand without those scopes.
1768
-
1769
- Accepts either a project secret (`oauth2`) or a user-bound Console
1770
- session cookie (`nextgenSession`). CSRF/Origin for cookie mutations
1771
- is a follow-up (#1140).
1772
-
2180
+ * Only unrevoked grants this API manages are listed (user or team bound to
2181
+ * viewer, editor, or admin), including expired grants so a client can
2182
+ * DELETE before re-granting. Project-secret setup (`sk_proj`) and
2183
+ * owning-team (`relation=team`) rows are not returned. Grants are not in
2184
+ * `resource_scope_index`; project scope is required on the query (same as
2185
+ * get). Requires `project.read`. `expand: ["principal"]` adds envelope
2186
+ * fields on `user` / `team` and additionally requires `user.read` and
2187
+ * `team.read` for project secrets (documented on the expand enum; those
2188
+ * scopes cannot be ANDed onto this security block because they are
2189
+ * body-conditional). A user-bound Console session that already passed
2190
+ * the project Check may expand without those scopes.
2191
+ *
2192
+ * Accepts either a project secret (`oauth2`) or a user-bound Console
2193
+ * session cookie (`nextgenSession`). Cookie-authenticated requests
2194
+ * follow the scheme's CSRF rules (`nextgenSession`).
1773
2195
  * @summary Query grants
1774
2196
  */
1775
2197
  const queryGrants = async (queryGrantsBody, params, options) => {
2198
+ const getHeaders = (h) => {
2199
+ if (!h) return {};
2200
+ if (h instanceof Headers) return Object.fromEntries(h.entries());
2201
+ if (Symbol.iterator in h) return Object.fromEntries(Array.from(h, (entry) => Array.from(entry)));
2202
+ const headers = {};
2203
+ for (const [name, value] of Object.entries(h)) if (value !== void 0) headers[name] = value;
2204
+ return headers;
2205
+ };
1776
2206
  return customFetch(getQueryGrantsUrl(params), {
1777
2207
  ...options,
1778
2208
  method: "POST",
1779
2209
  headers: {
1780
2210
  "Content-Type": "application/json",
1781
- ...options?.headers
2211
+ ...getHeaders(options?.headers)
1782
2212
  },
1783
2213
  body: JSON.stringify(queryGrantsBody)
1784
2214
  });
@@ -1786,29 +2216,34 @@ const queryGrants = async (queryGrantsBody, params, options) => {
1786
2216
  const getGetGrantUrl = (id, params) => {
1787
2217
  const normalizedParams = new URLSearchParams();
1788
2218
  Object.entries(params || {}).forEach(([key, value]) => {
1789
- if (value !== void 0) normalizedParams.append(key, value === null ? "null" : value.toString());
2219
+ if (Array.isArray(value) && ["expand"].includes(key)) {
2220
+ value.forEach((v) => {
2221
+ normalizedParams.append(key, v === null ? "null" : String(v));
2222
+ });
2223
+ return;
2224
+ }
2225
+ if (value !== void 0) normalizedParams.append(key, value === null ? "null" : String(value));
1790
2226
  });
1791
2227
  const stringifiedParams = normalizedParams.toString();
1792
- return stringifiedParams.length > 0 ? `${getProxyPath()}/grants/${id}?${stringifiedParams}` : `${getProxyPath()}/grants/${id}`;
2228
+ return stringifiedParams.length > 0 ? `${getProxyPath()}/grants/${encodeURIComponent(String(id))}?${stringifiedParams}` : `${getProxyPath()}/grants/${encodeURIComponent(String(id))}`;
1793
2229
  };
1794
2230
  /**
1795
2231
  * Loads a grant by `(project_id, id)` that this API manages (user or team
1796
- bound to viewer, editor, or admin) and that has not been revoked.
1797
- "Active" here means not revoked: expired grants stay visible so the
1798
- client can DELETE before re-granting the same binding. Authorization
1799
- still ignores expired grants. Grants are not registered in
1800
- `resource_scope_index`; project scope is required on the query (same as
1801
- events). Misses, revoked rows, project-secret setup (`sk_proj`),
1802
- owning-team (`relation=team`) rows, and cross-project ids return 404.
1803
- `expand=principal` adds envelope fields on `user` or `team` and requires
1804
- `user.read` and `team.read` in addition to `project.read` for project
1805
- secrets. A user-bound Console session that already passed the project
1806
- Check may expand without those scopes.
1807
-
1808
- Accepts either a project secret (`oauth2`) or a user-bound Console
1809
- session cookie (`nextgenSession`). CSRF/Origin for cookie mutations
1810
- is a follow-up (#1140).
1811
-
2232
+ * bound to viewer, editor, or admin) and that has not been revoked.
2233
+ * "Active" here means not revoked: expired grants stay visible so the
2234
+ * client can DELETE before re-granting the same binding. Authorization
2235
+ * still ignores expired grants. Grants are not registered in
2236
+ * `resource_scope_index`; project scope is required on the query (same as
2237
+ * events). Misses, revoked rows, project-secret setup (`sk_proj`),
2238
+ * owning-team (`relation=team`) rows, and cross-project ids return 404.
2239
+ * `expand=principal` adds envelope fields on `user` or `team` and requires
2240
+ * `user.read` and `team.read` in addition to `project.read` for project
2241
+ * secrets. A user-bound Console session that already passed the project
2242
+ * Check may expand without those scopes.
2243
+ *
2244
+ * Accepts either a project secret (`oauth2`) or a user-bound Console
2245
+ * session cookie (`nextgenSession`). Cookie-authenticated requests
2246
+ * follow the scheme's CSRF rules (`nextgenSession`).
1812
2247
  * @summary Get grant
1813
2248
  */
1814
2249
  const getGrant = async (id, params, options) => {
@@ -1820,21 +2255,20 @@ const getGrant = async (id, params, options) => {
1820
2255
  const getDeleteGrantUrl = (id, params) => {
1821
2256
  const normalizedParams = new URLSearchParams();
1822
2257
  Object.entries(params || {}).forEach(([key, value]) => {
1823
- if (value !== void 0) normalizedParams.append(key, value === null ? "null" : value.toString());
2258
+ if (value !== void 0) normalizedParams.append(key, value === null ? "null" : String(value));
1824
2259
  });
1825
2260
  const stringifiedParams = normalizedParams.toString();
1826
- return stringifiedParams.length > 0 ? `${getProxyPath()}/grants/${id}?${stringifiedParams}` : `${getProxyPath()}/grants/${id}`;
2261
+ return stringifiedParams.length > 0 ? `${getProxyPath()}/grants/${encodeURIComponent(String(id))}?${stringifiedParams}` : `${getProxyPath()}/grants/${encodeURIComponent(String(id))}`;
1827
2262
  };
1828
2263
  /**
1829
2264
  * Soft-revokes a grant this API manages and emits `authz.revoked`.
1830
- Already-revoked, missing, project-secret setup, and owning-team grants
1831
- return 404. The row is not un-revoked. Expired grants can still be
1832
- revoked so the unique binding can be reused.
1833
-
1834
- Accepts either a project secret (`oauth2`) or a user-bound Console
1835
- session cookie (`nextgenSession`). CSRF/Origin for cookie mutations
1836
- is a follow-up (#1140).
1837
-
2265
+ * Already-revoked, missing, project-secret setup, and owning-team grants
2266
+ * return 404. The row is not un-revoked. Expired grants can still be
2267
+ * revoked so the unique binding can be reused.
2268
+ *
2269
+ * Accepts either a project secret (`oauth2`) or a user-bound Console
2270
+ * session cookie (`nextgenSession`). Cookie-authenticated requests
2271
+ * follow the scheme's CSRF rules (`nextgenSession`).
1838
2272
  * @summary Revoke grant
1839
2273
  */
1840
2274
  const deleteGrant = async (id, params, options) => {
@@ -1848,28 +2282,27 @@ const getListEventsUrl = (params) => {
1848
2282
  Object.entries(params || {}).forEach(([key, value]) => {
1849
2283
  if (Array.isArray(value) && ["category", "event_type"].includes(key)) {
1850
2284
  value.forEach((v) => {
1851
- normalizedParams.append(key, v === null ? "null" : v.toString());
2285
+ normalizedParams.append(key, v === null ? "null" : String(v));
1852
2286
  });
1853
2287
  return;
1854
2288
  }
1855
- if (value !== void 0) normalizedParams.append(key, value === null ? "null" : value.toString());
2289
+ if (value !== void 0) normalizedParams.append(key, value === null ? "null" : String(value));
1856
2290
  });
1857
2291
  const stringifiedParams = normalizedParams.toString();
1858
2292
  return stringifiedParams.length > 0 ? `${getProxyPath()}/events?${stringifiedParams}` : `${getProxyPath()}/events`;
1859
2293
  };
1860
2294
  /**
1861
2295
  * Returns project-scoped audit events, newest-first by keyset on
1862
- `(created_at, id)` (ADR 027 / ADR 049). Pass `order=asc` for oldest-first.
1863
- Requires `events.read`.
1864
-
1865
- Pre-claim projects return an empty list (events are stored but not
1866
- visible until claim succeeds). Team-scoped credentials see only events
1867
- whose emit-time `team_id` matches the credential team (enforced when
1868
- team-scoped tokens exist).
1869
-
1870
- Clients discriminate each item via `event_type` (OpenAPI Event oneOf) —
1871
- see docs/design/api/events-catalog.md.
1872
-
2296
+ * `(created_at, id)` (ADR 027 / ADR 049). Pass `order=asc` for oldest-first.
2297
+ * Requires `events.read`.
2298
+ *
2299
+ * Pre-claim projects return an empty list (events are stored but not
2300
+ * visible until claim succeeds). Team-scoped credentials see only events
2301
+ * whose emit-time `team_id` matches the credential team (enforced when
2302
+ * team-scoped tokens exist).
2303
+ *
2304
+ * Clients discriminate each item via `event_type` (OpenAPI Event oneOf) —
2305
+ * see docs/design/api/events-catalog.md.
1873
2306
  * @summary List events
1874
2307
  */
1875
2308
  const listEvents = async (params, options) => {
@@ -1881,18 +2314,17 @@ const listEvents = async (params, options) => {
1881
2314
  const getGetEventUrl = (id, params) => {
1882
2315
  const normalizedParams = new URLSearchParams();
1883
2316
  Object.entries(params || {}).forEach(([key, value]) => {
1884
- if (value !== void 0) normalizedParams.append(key, value === null ? "null" : value.toString());
2317
+ if (value !== void 0) normalizedParams.append(key, value === null ? "null" : String(value));
1885
2318
  });
1886
2319
  const stringifiedParams = normalizedParams.toString();
1887
- return stringifiedParams.length > 0 ? `${getProxyPath()}/events/${id}?${stringifiedParams}` : `${getProxyPath()}/events/${id}`;
2320
+ return stringifiedParams.length > 0 ? `${getProxyPath()}/events/${encodeURIComponent(String(id))}?${stringifiedParams}` : `${getProxyPath()}/events/${encodeURIComponent(String(id))}`;
1888
2321
  };
1889
2322
  /**
1890
2323
  * Loads a single event by `(project_id, id)`. Requires `events.read`.
1891
- Events are not registered in `resource_scope_index`; project scope is
1892
- required on the query (ADR 049). Misses and cross-project ids return 404.
1893
-
1894
- Pre-claim projects return 404 (stored events stay invisible until claim).
1895
-
2324
+ * Events are not registered in `resource_scope_index`; project scope is
2325
+ * required on the query (ADR 049). Misses and cross-project ids return 404.
2326
+ *
2327
+ * Pre-claim projects return 404 (stored events stay invisible until claim).
1896
2328
  * @summary Get event by ID
1897
2329
  */
1898
2330
  const getEvent = async (id, params, options) => {
@@ -1904,23 +2336,22 @@ const getEvent = async (id, params, options) => {
1904
2336
  const getGetVariablesUrl = (params) => {
1905
2337
  const normalizedParams = new URLSearchParams();
1906
2338
  Object.entries(params || {}).forEach(([key, value]) => {
1907
- if (value !== void 0) normalizedParams.append(key, value === null ? "null" : value.toString());
2339
+ if (value !== void 0) normalizedParams.append(key, value === null ? "null" : String(value));
1908
2340
  });
1909
2341
  const stringifiedParams = normalizedParams.toString();
1910
2342
  return stringifiedParams.length > 0 ? `${getProxyPath()}/variables?${stringifiedParams}` : `${getProxyPath()}/variables`;
1911
2343
  };
1912
2344
  /**
1913
2345
  * Returns the variables entered at the owner this request addresses, keyed by
1914
- name — one environment of the project with `environment_name`, the project
1915
- level itself without it.
1916
-
1917
- Owners are separate, not a ladder: an environment does not inherit the
1918
- project's variables and the project does not see its environments'. Reading
1919
- everything a project holds therefore means reading each owner in turn.
1920
-
1921
- Secret values are not returned. A secret appears as `{"secret": true}`,
1922
- which says a value is held without disclosing it.
1923
-
2346
+ * name — one environment of the project with `environment_name`, the project
2347
+ * level itself without it.
2348
+ *
2349
+ * Owners are separate, not a ladder: an environment does not inherit the
2350
+ * project's variables and the project does not see its environments'. Reading
2351
+ * everything a project holds therefore means reading each owner in turn.
2352
+ *
2353
+ * Secret values are not returned. A secret appears as `{"secret": true}`,
2354
+ * which says a value is held without disclosing it.
1924
2355
  * @summary Get variables
1925
2356
  */
1926
2357
  const getVariables = async (params, options) => {
@@ -1932,39 +2363,46 @@ const getVariables = async (params, options) => {
1932
2363
  const getUpdateVariablesUrl = (params) => {
1933
2364
  const normalizedParams = new URLSearchParams();
1934
2365
  Object.entries(params || {}).forEach(([key, value]) => {
1935
- if (value !== void 0) normalizedParams.append(key, value === null ? "null" : value.toString());
2366
+ if (value !== void 0) normalizedParams.append(key, value === null ? "null" : String(value));
1936
2367
  });
1937
2368
  const stringifiedParams = normalizedParams.toString();
1938
2369
  return stringifiedParams.length > 0 ? `${getProxyPath()}/variables?${stringifiedParams}` : `${getProxyPath()}/variables`;
1939
2370
  };
1940
2371
  /**
1941
2372
  * Enters, replaces and removes variables at the owner this request
1942
- addresses.
1943
-
1944
- Every name in the body is applied at exactly that owner — the project, or
1945
- the environment named by `environment_name` — and reaches no other. Names
1946
- not in the body are untouched.
1947
-
1948
- A bare scalar enters a non-secret value. `{"value": …, "secret": true}`
1949
- stores the value encrypted under the project's active `secret` key, after
1950
- which it can be referenced but not read back. `null` removes the name from
1951
- this owner (RFC 7386), which is how several variables are removed in one
1952
- request; removing a name this owner does not hold is a no-op rather than an
1953
- error.
1954
-
1955
- The body is applied whole or not at all, so a rejected request leaves the
1956
- owner exactly as it was. Writing the same name and owner twice replaces the
1957
- value rather than duplicating it, which makes a retry safe.
1958
-
2373
+ * addresses.
2374
+ *
2375
+ * Every name in the body is applied at exactly that owner — the project, or
2376
+ * the environment named by `environment_name` — and reaches no other. Names
2377
+ * not in the body are untouched.
2378
+ *
2379
+ * A bare scalar enters a non-secret value. `{"value": …, "secret": true}`
2380
+ * stores the value encrypted under the project's active `secret` key, after
2381
+ * which it can be referenced but not read back. `null` removes the name from
2382
+ * this owner (RFC 7386), which is how several variables are removed in one
2383
+ * request; removing a name this owner does not hold is a no-op rather than an
2384
+ * error.
2385
+ *
2386
+ * The body is applied whole or not at all, so a rejected request leaves the
2387
+ * owner exactly as it was. Writing the same name and owner twice replaces the
2388
+ * value rather than duplicating it, which makes a retry safe.
1959
2389
  * @summary Update variables
1960
2390
  */
1961
2391
  const updateVariables = async (updateVariablesBody, params, options) => {
2392
+ const getHeaders = (h) => {
2393
+ if (!h) return {};
2394
+ if (h instanceof Headers) return Object.fromEntries(h.entries());
2395
+ if (Symbol.iterator in h) return Object.fromEntries(Array.from(h, (entry) => Array.from(entry)));
2396
+ const headers = {};
2397
+ for (const [name, value] of Object.entries(h)) if (value !== void 0) headers[name] = value;
2398
+ return headers;
2399
+ };
1962
2400
  return customFetch(getUpdateVariablesUrl(params), {
1963
2401
  ...options,
1964
2402
  method: "PATCH",
1965
2403
  headers: {
1966
2404
  "Content-Type": "application/json",
1967
- ...options?.headers
2405
+ ...getHeaders(options?.headers)
1968
2406
  },
1969
2407
  body: JSON.stringify(updateVariablesBody)
1970
2408
  });
@@ -1972,20 +2410,19 @@ const updateVariables = async (updateVariablesBody, params, options) => {
1972
2410
  const getGetVariableUrl = (variableName, params) => {
1973
2411
  const normalizedParams = new URLSearchParams();
1974
2412
  Object.entries(params || {}).forEach(([key, value]) => {
1975
- if (value !== void 0) normalizedParams.append(key, value === null ? "null" : value.toString());
2413
+ if (value !== void 0) normalizedParams.append(key, value === null ? "null" : String(value));
1976
2414
  });
1977
2415
  const stringifiedParams = normalizedParams.toString();
1978
- return stringifiedParams.length > 0 ? `${getProxyPath()}/variables/${variableName}?${stringifiedParams}` : `${getProxyPath()}/variables/${variableName}`;
2416
+ return stringifiedParams.length > 0 ? `${getProxyPath()}/variables/${encodeURIComponent(String(variableName))}?${stringifiedParams}` : `${getProxyPath()}/variables/${encodeURIComponent(String(variableName))}`;
1979
2417
  };
1980
2418
  /**
1981
2419
  * Reads one variable by name from the owner this request addresses — one
1982
- environment of the project with `environment_name`, the project level
1983
- itself without it.
1984
-
1985
- A name that owner has not entered answers `var.not_found`, even when
1986
- another owner of the same project holds it: nothing is inherited. A secret
1987
- is found but not disclosed: the response is `{"secret": true}`.
1988
-
2420
+ * environment of the project with `environment_name`, the project level
2421
+ * itself without it.
2422
+ *
2423
+ * A name that owner has not entered answers `var.not_found`, even when
2424
+ * another owner of the same project holds it: nothing is inherited. A secret
2425
+ * is found but not disclosed: the response is `{"secret": true}`.
1989
2426
  * @summary Get a variable
1990
2427
  */
1991
2428
  const getVariable = async (variableName, params, options) => {
@@ -1997,18 +2434,17 @@ const getVariable = async (variableName, params, options) => {
1997
2434
  const getDeleteVariableUrl = (variableName, params) => {
1998
2435
  const normalizedParams = new URLSearchParams();
1999
2436
  Object.entries(params || {}).forEach(([key, value]) => {
2000
- if (value !== void 0) normalizedParams.append(key, value === null ? "null" : value.toString());
2437
+ if (value !== void 0) normalizedParams.append(key, value === null ? "null" : String(value));
2001
2438
  });
2002
2439
  const stringifiedParams = normalizedParams.toString();
2003
- return stringifiedParams.length > 0 ? `${getProxyPath()}/variables/${variableName}?${stringifiedParams}` : `${getProxyPath()}/variables/${variableName}`;
2440
+ return stringifiedParams.length > 0 ? `${getProxyPath()}/variables/${encodeURIComponent(String(variableName))}?${stringifiedParams}` : `${getProxyPath()}/variables/${encodeURIComponent(String(variableName))}`;
2004
2441
  };
2005
2442
  /**
2006
2443
  * Removes the variable this owner entered under this name.
2007
-
2008
- A variable is deletable only by the owner that entered it. Deleting a name
2009
- another owner of the same project holds answers `var.not_found` and leaves
2010
- that owner's value standing.
2011
-
2444
+ *
2445
+ * A variable is deletable only by the owner that entered it. Deleting a name
2446
+ * another owner of the same project holds answers `var.not_found` and leaves
2447
+ * that owner's value standing.
2012
2448
  * @summary Delete a variable
2013
2449
  */
2014
2450
  const deleteVariable = async (variableName, params, options) => {
@@ -2017,6 +2453,115 @@ const deleteVariable = async (variableName, params, options) => {
2017
2453
  method: "DELETE"
2018
2454
  });
2019
2455
  };
2456
+ const getCreateDeploymentUrl = (params) => {
2457
+ const normalizedParams = new URLSearchParams();
2458
+ Object.entries(params || {}).forEach(([key, value]) => {
2459
+ if (value !== void 0) normalizedParams.append(key, value === null ? "null" : String(value));
2460
+ });
2461
+ const stringifiedParams = normalizedParams.toString();
2462
+ return stringifiedParams.length > 0 ? `${getProxyPath()}/deployments?${stringifiedParams}` : `${getProxyPath()}/deployments`;
2463
+ };
2464
+ /**
2465
+ * Makes a release live on an environment by recording a deployment. The two
2466
+ * happen atomically: when the call returns, the environment runs the named
2467
+ * release and the record exists; on any failure the environment keeps
2468
+ * running what it ran and no record is written.
2469
+ *
2470
+ * Deploying, promoting and rolling back are all this call — `reason` says
2471
+ * which. None of them assembles a release: the release must already exist,
2472
+ * and rolling back means deploying a release the environment ran earlier,
2473
+ * chosen from its deployment history.
2474
+ *
2475
+ * Idempotent on the running release: deploying the release the environment
2476
+ * already runs changes nothing and answers `200` with the deployment that
2477
+ * made it live, so a re-run of `zitadel deploy` on unchanged content is a
2478
+ * no-op end to end — matching `POST /releases`, which resolves the same
2479
+ * content to the same release first. Anything else writes a new record,
2480
+ * including the same release returning after something else ran in between:
2481
+ * the log is append-only, and each row is one act of making a release live.
2482
+ *
2483
+ * `expected_current_deployment_id` guards against racing another deploy:
2484
+ * when present, the swap only happens if the environment's current
2485
+ * deployment still is the one named, and a mismatch answers `409` with the
2486
+ * actual `current_deployment_id` and `current_release_id` in the details.
2487
+ * @summary Create a deployment
2488
+ */
2489
+ const createDeployment = async (createDeploymentBody, params, options) => {
2490
+ const getHeaders = (h) => {
2491
+ if (!h) return {};
2492
+ if (h instanceof Headers) return Object.fromEntries(h.entries());
2493
+ if (Symbol.iterator in h) return Object.fromEntries(Array.from(h, (entry) => Array.from(entry)));
2494
+ const headers = {};
2495
+ for (const [name, value] of Object.entries(h)) if (value !== void 0) headers[name] = value;
2496
+ return headers;
2497
+ };
2498
+ return customFetch(getCreateDeploymentUrl(params), {
2499
+ ...options,
2500
+ method: "POST",
2501
+ headers: {
2502
+ "Content-Type": "application/json",
2503
+ ...getHeaders(options?.headers)
2504
+ },
2505
+ body: JSON.stringify(createDeploymentBody)
2506
+ });
2507
+ };
2508
+ const getListDeploymentsUrl = (params) => {
2509
+ const normalizedParams = new URLSearchParams();
2510
+ Object.entries(params || {}).forEach(([key, value]) => {
2511
+ if (Array.isArray(value) && ["expand"].includes(key)) {
2512
+ value.forEach((v) => {
2513
+ normalizedParams.append(key, v === null ? "null" : String(v));
2514
+ });
2515
+ return;
2516
+ }
2517
+ if (value !== void 0) normalizedParams.append(key, value === null ? "null" : String(value));
2518
+ });
2519
+ const stringifiedParams = normalizedParams.toString();
2520
+ return stringifiedParams.length > 0 ? `${getProxyPath()}/deployments?${stringifiedParams}` : `${getProxyPath()}/deployments`;
2521
+ };
2522
+ /**
2523
+ * Lists deployments newest first: what ran where, and when.
2524
+ *
2525
+ * With `environment_name`, the list is that environment's history and its
2526
+ * first row is the environment's current deployment. Without it, the list
2527
+ * interleaves every environment of the project — a project-wide audit view
2528
+ * in which the first row is only the most recent deployment anywhere.
2529
+ *
2530
+ * `expand: ["release"]` embeds the release each deployment made live, so a
2531
+ * history renders with each entry's content without resolving `release_id`
2532
+ * one by one. Expanding requires `release.read` and does not affect the
2533
+ * ordering or the page tokens.
2534
+ * @summary List deployments
2535
+ */
2536
+ const listDeployments = async (params, options) => {
2537
+ return customFetch(getListDeploymentsUrl(params), {
2538
+ ...options,
2539
+ method: "GET"
2540
+ });
2541
+ };
2542
+ const getGetDeploymentByIdUrl = (deploymentId, params) => {
2543
+ const normalizedParams = new URLSearchParams();
2544
+ Object.entries(params || {}).forEach(([key, value]) => {
2545
+ if (value !== void 0) normalizedParams.append(key, value === null ? "null" : String(value));
2546
+ });
2547
+ const stringifiedParams = normalizedParams.toString();
2548
+ return stringifiedParams.length > 0 ? `${getProxyPath()}/deployments/${encodeURIComponent(String(deploymentId))}?${stringifiedParams}` : `${getProxyPath()}/deployments/${encodeURIComponent(String(deploymentId))}`;
2549
+ };
2550
+ /**
2551
+ * Reads one deployment record.
2552
+ *
2553
+ * The lookup is scoped to the project in `project_id`: a deployment id
2554
+ * belonging to another project answers not found exactly as an unknown id
2555
+ * does, so the endpoint cannot be used to probe for deployments in projects
2556
+ * the caller cannot read.
2557
+ * @summary Get a deployment by id
2558
+ */
2559
+ const getDeploymentById = async (deploymentId, params, options) => {
2560
+ return customFetch(getGetDeploymentByIdUrl(deploymentId, params), {
2561
+ ...options,
2562
+ method: "GET"
2563
+ });
2564
+ };
2020
2565
  //#endregion
2021
2566
  //#region ../api/dist/runtime/api-factory.mjs
2022
2567
  /**
@@ -2055,12 +2600,16 @@ function createZitadelClient(opts) {
2055
2600
  return (...args) => {
2056
2601
  setProxyPath(baseUrl);
2057
2602
  setApiAuthToken(opts.token);
2603
+ setRequestPolicy({
2604
+ signal: opts.signal,
2605
+ timeoutMs: opts.timeoutMs
2606
+ });
2058
2607
  return value(...args);
2059
2608
  };
2060
2609
  } });
2061
2610
  }
2062
2611
  //#endregion
2063
- //#region ../config/dist/defaults-DV6hY2KT.mjs
2612
+ //#region ../config/dist/defaults-COLBFU3S.mjs
2064
2613
  var default_human_user_default = {
2065
2614
  title: "DefaultHumanUserSchema",
2066
2615
  $schema: "https://json-schema.org/draft/2020-12/schema",
@@ -2559,9 +3108,9 @@ function requireString(value, label) {
2559
3108
  //#region src/cli.ts
2560
3109
  const DEFAULT_TIMEOUT_MS = 12e4;
2561
3110
  function resolveCliBin() {
2562
- const require = (0, node_module.createRequire)(require("url").pathToFileURL(__filename).href);
2563
- const pkgPath = require.resolve("@zitadel/cli/package.json");
2564
- const rel = require(pkgPath).bin?.zitadel;
3111
+ const require$1 = (0, node_module.createRequire)(require("url").pathToFileURL(__filename).href);
3112
+ const pkgPath = require$1.resolve("@zitadel/cli/package.json");
3113
+ const rel = require$1(pkgPath).bin?.zitadel;
2565
3114
  if (!rel) throw new Error("@zitadel/cli does not declare a `zitadel` bin entry");
2566
3115
  return (0, node_path.join)((0, node_path.dirname)(pkgPath), rel);
2567
3116
  }
@@ -2782,8 +3331,7 @@ function identity() {
2782
3331
  /**
2783
3332
  * Create a user that can immediately complete the password login flow:
2784
3333
  * `POST /users` (the body carries `schema: <schema id>` and the schema-defined
2785
- * content under `attributes`) followed by `PUT /users/{id}/password` with
2786
- * `is_change_required: false`.
3334
+ * content under `attributes`) followed by `PUT /users/{id}/password`.
2787
3335
  *
2788
3336
  * Defaults mint a unique email per call (email is x-unique per project), which
2789
3337
  * is what makes per-test seeding parallel-safe on a shared instance.
@@ -2799,10 +3347,7 @@ async function seedUser(client, context, input = {}) {
2799
3347
  email
2800
3348
  }
2801
3349
  }, { project_id: context.projectId })).id, "user id");
2802
- await client.setUserPassword(id, {
2803
- password,
2804
- is_change_required: false
2805
- });
3350
+ await client.setUserPassword(id, { password });
2806
3351
  return {
2807
3352
  id,
2808
3353
  email,
@@ -2965,7 +3510,8 @@ function connectZitadel(handle) {
2965
3510
  identity,
2966
3511
  seedSession: async (input = {}) => {
2967
3512
  const { user: existing, flowDefinitionName, origin, ...userInput } = input;
2968
- return mintSession(api, handle, context, existing ?? await seedUser(api, context, userInput), {
3513
+ const user = existing ?? await seedUser(api, context, userInput);
3514
+ return mintSession(api, handle, context, user, {
2969
3515
  flowDefinitionName,
2970
3516
  origin: origin ?? handle.appOrigin
2971
3517
  });
@@ -3042,4 +3588,4 @@ Object.defineProperty(exports, "startLocalZitadel", {
3042
3588
  }
3043
3589
  });
3044
3590
 
3045
- //# sourceMappingURL=src-CFX_ayWr.cjs.map
3591
+ //# sourceMappingURL=src-CXX_iT7z.cjs.map