@zitadel/testing 0.1.0-alpha.19 → 0.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +84 -31
- package/dist/app-runner.cjs +4 -3
- package/dist/app-runner.cjs.map +1 -1
- package/dist/app-runner.d.mts +1 -1
- package/dist/app-runner.mjs +4 -3
- package/dist/app-runner.mjs.map +1 -1
- package/dist/{handshake-ClzWvG8z.mjs → handshake-CwlxMjW0.mjs} +20 -4
- package/dist/handshake-CwlxMjW0.mjs.map +1 -0
- package/dist/{handshake-CRKcgkfN.cjs → handshake-D6MXSUcd.cjs} +20 -4
- package/dist/handshake-D6MXSUcd.cjs.map +1 -0
- package/dist/index.cjs +4 -2
- package/dist/index.d.mts +10 -16
- package/dist/index.mjs +3 -3
- package/dist/{orchestration-C640_1Lg.mjs → orchestration-Clldecyr.mjs} +1 -1
- package/dist/{orchestration-C640_1Lg.mjs.map → orchestration-Clldecyr.mjs.map} +1 -1
- package/dist/{orchestration-D7QBgQ0l.cjs → orchestration-gIDANMcF.cjs} +1 -1
- package/dist/{orchestration-D7QBgQ0l.cjs.map → orchestration-gIDANMcF.cjs.map} +1 -1
- package/dist/playwright.cjs +15 -8
- package/dist/playwright.cjs.map +1 -1
- package/dist/playwright.d.mts +46 -45
- package/dist/playwright.mjs +13 -9
- package/dist/playwright.mjs.map +1 -1
- package/dist/session-BrSkzPpy.d.mts +204 -0
- package/dist/src-CaG3NNMx.cjs +4390 -0
- package/dist/src-CaG3NNMx.cjs.map +1 -0
- package/dist/{src-9dFjTIAw.mjs → src-DKJ1hMV8.mjs} +37 -14
- package/dist/src-DKJ1hMV8.mjs.map +1 -0
- package/dist/supervisor.cjs +3 -3
- package/dist/supervisor.cjs.map +1 -1
- package/dist/supervisor.d.mts +1 -1
- package/dist/supervisor.mjs +3 -3
- package/dist/supervisor.mjs.map +1 -1
- package/package.json +14 -10
- package/dist/app-env-Btmfcflb.d.mts +0 -122
- package/dist/app-env-Btmfcflb.d.mts.map +0 -1
- package/dist/handshake-CRKcgkfN.cjs.map +0 -1
- package/dist/handshake-ClzWvG8z.mjs.map +0 -1
- package/dist/index.d.mts.map +0 -1
- package/dist/playwright.d.mts.map +0 -1
- package/dist/src-9dFjTIAw.mjs.map +0 -1
- package/dist/src-I0KAh1zU.cjs +0 -2374
- package/dist/src-I0KAh1zU.cjs.map +0 -1
package/dist/src-I0KAh1zU.cjs
DELETED
|
@@ -1,2374 +0,0 @@
|
|
|
1
|
-
const require_handshake = require("./handshake-CRKcgkfN.cjs");
|
|
2
|
-
require("node:fs");
|
|
3
|
-
require("node:url");
|
|
4
|
-
let node_fs_promises = require("node:fs/promises");
|
|
5
|
-
let node_os = require("node:os");
|
|
6
|
-
let node_path = require("node:path");
|
|
7
|
-
let node_child_process = require("node:child_process");
|
|
8
|
-
let node_module = require("node:module");
|
|
9
|
-
let node_net = require("node:net");
|
|
10
|
-
let node_crypto = require("node:crypto");
|
|
11
|
-
//#region ../api/dist/runtime/base-url.mjs
|
|
12
|
-
let proxyPath = "";
|
|
13
|
-
function getProxyPath() {
|
|
14
|
-
return proxyPath;
|
|
15
|
-
}
|
|
16
|
-
function setProxyPath(path) {
|
|
17
|
-
proxyPath = path;
|
|
18
|
-
}
|
|
19
|
-
//#endregion
|
|
20
|
-
//#region ../api/dist/runtime/auth.mjs
|
|
21
|
-
/**
|
|
22
|
-
* Module-global bearer token used by the orval-generated client's
|
|
23
|
-
* custom fetch. Set once at command boot (the same lifecycle pattern
|
|
24
|
-
* as `base-url.ts`); every generated request reads from here.
|
|
25
|
-
*
|
|
26
|
-
* Keeping the token here means the CLI doesn't have to thread an
|
|
27
|
-
* `Authorization` header through every generated call site; orval's
|
|
28
|
-
* `mutator` wires `runtime/fetch.ts` in, and that file pulls the token
|
|
29
|
-
* from this module.
|
|
30
|
-
*/
|
|
31
|
-
let apiAuthToken;
|
|
32
|
-
function getApiAuthToken() {
|
|
33
|
-
return apiAuthToken;
|
|
34
|
-
}
|
|
35
|
-
function setApiAuthToken(token) {
|
|
36
|
-
apiAuthToken = token;
|
|
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
|
-
};
|
|
50
|
-
//#endregion
|
|
51
|
-
//#region ../api/dist/runtime/fetch.mjs
|
|
52
|
-
/**
|
|
53
|
-
* Framework-neutral failure type the orval-generated client throws on
|
|
54
|
-
* any non-2xx response. Carries the HTTP status, the parsed error body
|
|
55
|
-
* (the spec's `{code, message, details?}` envelope when the server
|
|
56
|
-
* returned one), and the request URL — enough for callers to map to
|
|
57
|
-
* their own error taxonomy without re-implementing the fetch layer.
|
|
58
|
-
*
|
|
59
|
-
* Callers that don't care about the distinction can catch `ApiError`
|
|
60
|
-
* generically; callers that do (the CLI's `toZitadelError`) read
|
|
61
|
-
* `status` and decide.
|
|
62
|
-
*/
|
|
63
|
-
var ApiError = class extends Error {
|
|
64
|
-
status;
|
|
65
|
-
url;
|
|
66
|
-
body;
|
|
67
|
-
constructor(status, url, body, message) {
|
|
68
|
-
super(message);
|
|
69
|
-
this.name = "ApiError";
|
|
70
|
-
this.status = status;
|
|
71
|
-
this.url = url;
|
|
72
|
-
this.body = body;
|
|
73
|
-
}
|
|
74
|
-
};
|
|
75
|
-
/**
|
|
76
|
-
* The orval `mutator` for the fetch client. Every generated operation
|
|
77
|
-
* routes its request through this function instead of the global
|
|
78
|
-
* `fetch`. We pin three concerns here so generated call sites stay
|
|
79
|
-
* focused on the shape of one HTTP call:
|
|
80
|
-
*
|
|
81
|
-
* - bearer auth — read from `runtime/auth.ts` and attached automatically;
|
|
82
|
-
* - non-2xx → throw — orval's stock client parses the body regardless
|
|
83
|
-
* of status, so callers would have to inspect every response. Throw
|
|
84
|
-
* `ApiError` on `!res.ok` so failures interrupt control flow;
|
|
85
|
-
* - body parsing — return the parsed JSON typed as `T` (the operation's
|
|
86
|
-
* return type, threaded through by orval), or `undefined` for the
|
|
87
|
-
* spec's `204`/`205`/`304` no-body responses.
|
|
88
|
-
*/
|
|
89
|
-
async function customFetch(url, options) {
|
|
90
|
-
const token = getApiAuthToken();
|
|
91
|
-
const headers = new Headers(options.headers);
|
|
92
|
-
if (token && !headers.has("authorization")) headers.set("authorization", `Bearer ${token}`);
|
|
93
|
-
const res = await fetch(url, {
|
|
94
|
-
...options,
|
|
95
|
-
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;
|
|
103
|
-
if (!res.ok) {
|
|
104
|
-
const message = `${options.method ?? "GET"} ${url} returned ${res.status}`;
|
|
105
|
-
throw new ApiError(res.status, url, parsed, message);
|
|
106
|
-
}
|
|
107
|
-
return parsed;
|
|
108
|
-
}
|
|
109
|
-
/**
|
|
110
|
-
* `JSON.parse` wrapped so a non-JSON body (e.g. an HTML 502 from a
|
|
111
|
-
* proxy) becomes `{ raw: "<text>" }` instead of throwing inside
|
|
112
|
-
* `customFetch`. The thrown `ApiError` then carries something useful
|
|
113
|
-
* for the user to see.
|
|
114
|
-
*/
|
|
115
|
-
function safeJsonParse(text) {
|
|
116
|
-
try {
|
|
117
|
-
return JSON.parse(text);
|
|
118
|
-
} catch {
|
|
119
|
-
return { raw: text };
|
|
120
|
-
}
|
|
121
|
-
}
|
|
122
|
-
//#endregion
|
|
123
|
-
//#region ../api/dist/generated/endpoints/zitadelNextGen.mjs
|
|
124
|
-
/**
|
|
125
|
-
* Generated by orval v8.10.0 🍺
|
|
126
|
-
* Do not edit manually.
|
|
127
|
-
* Zitadel NextGen
|
|
128
|
-
* This is the next generation of the Zitadel identity platform.
|
|
129
|
-
* OpenAPI spec version: 0.0.1
|
|
130
|
-
*/
|
|
131
|
-
var zitadelNextGen_exports = /* @__PURE__ */ __exportAll({
|
|
132
|
-
completeClaim: () => completeClaim,
|
|
133
|
-
createAuthAttempt: () => createAuthAttempt,
|
|
134
|
-
createBranding: () => createBranding,
|
|
135
|
-
createFlow: () => createFlow,
|
|
136
|
-
createFlowDefinition: () => createFlowDefinition,
|
|
137
|
-
createHandoff: () => createHandoff,
|
|
138
|
-
createProject: () => createProject,
|
|
139
|
-
createSchema: () => createSchema,
|
|
140
|
-
createSession: () => createSession,
|
|
141
|
-
createTeam: () => createTeam,
|
|
142
|
-
createUser: () => createUser,
|
|
143
|
-
deleteFlowDefinition: () => deleteFlowDefinition,
|
|
144
|
-
deleteTeam: () => deleteTeam,
|
|
145
|
-
deleteUserByID: () => deleteUserByID,
|
|
146
|
-
exchangeHandoff: () => exchangeHandoff,
|
|
147
|
-
getAuthAttempt: () => getAuthAttempt,
|
|
148
|
-
getBrandingById: () => getBrandingById,
|
|
149
|
-
getClaimStatus: () => getClaimStatus,
|
|
150
|
-
getCompleteClaimUrl: () => getCompleteClaimUrl,
|
|
151
|
-
getCreateAuthAttemptUrl: () => getCreateAuthAttemptUrl,
|
|
152
|
-
getCreateBrandingUrl: () => getCreateBrandingUrl,
|
|
153
|
-
getCreateFlowDefinitionUrl: () => getCreateFlowDefinitionUrl,
|
|
154
|
-
getCreateFlowUrl: () => getCreateFlowUrl,
|
|
155
|
-
getCreateHandoffUrl: () => getCreateHandoffUrl,
|
|
156
|
-
getCreateProjectUrl: () => getCreateProjectUrl,
|
|
157
|
-
getCreateSchemaUrl: () => getCreateSchemaUrl,
|
|
158
|
-
getCreateSessionUrl: () => getCreateSessionUrl,
|
|
159
|
-
getCreateTeamUrl: () => getCreateTeamUrl,
|
|
160
|
-
getCreateUserUrl: () => getCreateUserUrl,
|
|
161
|
-
getDeleteFlowDefinitionUrl: () => getDeleteFlowDefinitionUrl,
|
|
162
|
-
getDeleteTeamUrl: () => getDeleteTeamUrl,
|
|
163
|
-
getDeleteUserByIDUrl: () => getDeleteUserByIDUrl,
|
|
164
|
-
getEvent: () => getEvent,
|
|
165
|
-
getExchangeHandoffUrl: () => getExchangeHandoffUrl,
|
|
166
|
-
getFlowDefinition: () => getFlowDefinition,
|
|
167
|
-
getFlowStep: () => getFlowStep,
|
|
168
|
-
getGetAuthAttemptUrl: () => getGetAuthAttemptUrl,
|
|
169
|
-
getGetBrandingByIdUrl: () => getGetBrandingByIdUrl,
|
|
170
|
-
getGetClaimStatusUrl: () => getGetClaimStatusUrl,
|
|
171
|
-
getGetEventUrl: () => getGetEventUrl,
|
|
172
|
-
getGetFlowDefinitionUrl: () => getGetFlowDefinitionUrl,
|
|
173
|
-
getGetFlowStepUrl: () => getGetFlowStepUrl,
|
|
174
|
-
getGetHealthUrl: () => getGetHealthUrl,
|
|
175
|
-
getGetLiveUrl: () => getGetLiveUrl,
|
|
176
|
-
getGetMySessionUrl: () => getGetMySessionUrl,
|
|
177
|
-
getGetMyUserUrl: () => getGetMyUserUrl,
|
|
178
|
-
getGetProjectUrl: () => getGetProjectUrl,
|
|
179
|
-
getGetReadyUrl: () => getGetReadyUrl,
|
|
180
|
-
getGetSchemaByIdUrl: () => getGetSchemaByIdUrl,
|
|
181
|
-
getGetSessionUrl: () => getGetSessionUrl,
|
|
182
|
-
getGetTeamUrl: () => getGetTeamUrl,
|
|
183
|
-
getGetUserByIDUrl: () => getGetUserByIDUrl,
|
|
184
|
-
getHealth: () => getHealth,
|
|
185
|
-
getInitClaimUrl: () => getInitClaimUrl,
|
|
186
|
-
getIssueChallengeUrl: () => getIssueChallengeUrl,
|
|
187
|
-
getListBrandingUrl: () => getListBrandingUrl,
|
|
188
|
-
getListEventsUrl: () => getListEventsUrl,
|
|
189
|
-
getListFlowDefinitionsUrl: () => getListFlowDefinitionsUrl,
|
|
190
|
-
getListSchemasUrl: () => getListSchemasUrl,
|
|
191
|
-
getListUserPasskeysUrl: () => getListUserPasskeysUrl,
|
|
192
|
-
getListUserTeamsUrl: () => getListUserTeamsUrl,
|
|
193
|
-
getListUsersUrl: () => getListUsersUrl,
|
|
194
|
-
getLive: () => getLive,
|
|
195
|
-
getMySession: () => getMySession,
|
|
196
|
-
getMyUser: () => getMyUser,
|
|
197
|
-
getPatchProjectUrl: () => getPatchProjectUrl,
|
|
198
|
-
getProject: () => getProject,
|
|
199
|
-
getQueryProjectsUrl: () => getQueryProjectsUrl,
|
|
200
|
-
getQuerySessionsUrl: () => getQuerySessionsUrl,
|
|
201
|
-
getQueryTeamsUrl: () => getQueryTeamsUrl,
|
|
202
|
-
getReady: () => getReady,
|
|
203
|
-
getRevokeMySessionUrl: () => getRevokeMySessionUrl,
|
|
204
|
-
getRevokeSessionUrl: () => getRevokeSessionUrl,
|
|
205
|
-
getSchemaById: () => getSchemaById,
|
|
206
|
-
getSession: () => getSession,
|
|
207
|
-
getSetUserPasswordUrl: () => getSetUserPasswordUrl,
|
|
208
|
-
getSubmitFlowStepUrl: () => getSubmitFlowStepUrl,
|
|
209
|
-
getTeam: () => getTeam,
|
|
210
|
-
getUpdateFlowDefinitionUrl: () => getUpdateFlowDefinitionUrl,
|
|
211
|
-
getUpdateTeamUrl: () => getUpdateTeamUrl,
|
|
212
|
-
getUserByID: () => getUserByID,
|
|
213
|
-
getVerifyChallengeProofUrl: () => getVerifyChallengeProofUrl,
|
|
214
|
-
initClaim: () => initClaim,
|
|
215
|
-
issueChallenge: () => issueChallenge,
|
|
216
|
-
listBranding: () => listBranding,
|
|
217
|
-
listEvents: () => listEvents,
|
|
218
|
-
listFlowDefinitions: () => listFlowDefinitions,
|
|
219
|
-
listSchemas: () => listSchemas,
|
|
220
|
-
listUserPasskeys: () => listUserPasskeys,
|
|
221
|
-
listUserTeams: () => listUserTeams,
|
|
222
|
-
listUsers: () => listUsers,
|
|
223
|
-
patchProject: () => patchProject,
|
|
224
|
-
queryProjects: () => queryProjects,
|
|
225
|
-
querySessions: () => querySessions,
|
|
226
|
-
queryTeams: () => queryTeams,
|
|
227
|
-
revokeMySession: () => revokeMySession,
|
|
228
|
-
revokeSession: () => revokeSession,
|
|
229
|
-
setUserPassword: () => setUserPassword,
|
|
230
|
-
submitFlowStep: () => submitFlowStep,
|
|
231
|
-
updateFlowDefinition: () => updateFlowDefinition,
|
|
232
|
-
updateTeam: () => updateTeam,
|
|
233
|
-
verifyChallengeProof: () => verifyChallengeProof
|
|
234
|
-
});
|
|
235
|
-
const getGetHealthUrl = () => {
|
|
236
|
-
return `${getProxyPath()}/healthz`;
|
|
237
|
-
};
|
|
238
|
-
/**
|
|
239
|
-
* Check whether the server is healthy
|
|
240
|
-
* @summary Check server health
|
|
241
|
-
*/
|
|
242
|
-
const getHealth = async (options) => {
|
|
243
|
-
return customFetch(getGetHealthUrl(), {
|
|
244
|
-
...options,
|
|
245
|
-
method: "GET"
|
|
246
|
-
});
|
|
247
|
-
};
|
|
248
|
-
const getGetLiveUrl = () => {
|
|
249
|
-
return `${getProxyPath()}/livez`;
|
|
250
|
-
};
|
|
251
|
-
/**
|
|
252
|
-
* Check whether the server is started
|
|
253
|
-
* @summary Check server liveness
|
|
254
|
-
*/
|
|
255
|
-
const getLive = async (options) => {
|
|
256
|
-
return customFetch(getGetLiveUrl(), {
|
|
257
|
-
...options,
|
|
258
|
-
method: "GET"
|
|
259
|
-
});
|
|
260
|
-
};
|
|
261
|
-
const getGetReadyUrl = () => {
|
|
262
|
-
return `${getProxyPath()}/readyz`;
|
|
263
|
-
};
|
|
264
|
-
/**
|
|
265
|
-
* Check whether the server is ready to accept requests
|
|
266
|
-
* @summary Check server readiness
|
|
267
|
-
*/
|
|
268
|
-
const getReady = async (options) => {
|
|
269
|
-
return customFetch(getGetReadyUrl(), {
|
|
270
|
-
...options,
|
|
271
|
-
method: "GET"
|
|
272
|
-
});
|
|
273
|
-
};
|
|
274
|
-
const getCreateUserUrl = (params) => {
|
|
275
|
-
const normalizedParams = new URLSearchParams();
|
|
276
|
-
Object.entries(params || {}).forEach(([key, value]) => {
|
|
277
|
-
if (value !== void 0) normalizedParams.append(key, value === null ? "null" : value.toString());
|
|
278
|
-
});
|
|
279
|
-
const stringifiedParams = normalizedParams.toString();
|
|
280
|
-
return stringifiedParams.length > 0 ? `${getProxyPath()}/users?${stringifiedParams}` : `${getProxyPath()}/users`;
|
|
281
|
-
};
|
|
282
|
-
/**
|
|
283
|
-
* @summary Create user
|
|
284
|
-
*/
|
|
285
|
-
const createUser = async (createUserBody, params, options) => {
|
|
286
|
-
return customFetch(getCreateUserUrl(params), {
|
|
287
|
-
...options,
|
|
288
|
-
method: "POST",
|
|
289
|
-
headers: {
|
|
290
|
-
"Content-Type": "application/json",
|
|
291
|
-
...options?.headers
|
|
292
|
-
},
|
|
293
|
-
body: JSON.stringify(createUserBody)
|
|
294
|
-
});
|
|
295
|
-
};
|
|
296
|
-
const getListUsersUrl = (params) => {
|
|
297
|
-
const normalizedParams = new URLSearchParams();
|
|
298
|
-
Object.entries(params || {}).forEach(([key, value]) => {
|
|
299
|
-
if (value !== void 0) normalizedParams.append(key, value === null ? "null" : value.toString());
|
|
300
|
-
});
|
|
301
|
-
const stringifiedParams = normalizedParams.toString();
|
|
302
|
-
return stringifiedParams.length > 0 ? `${getProxyPath()}/users?${stringifiedParams}` : `${getProxyPath()}/users`;
|
|
303
|
-
};
|
|
304
|
-
/**
|
|
305
|
-
* @summary List users
|
|
306
|
-
*/
|
|
307
|
-
const listUsers = async (params, options) => {
|
|
308
|
-
return customFetch(getListUsersUrl(params), {
|
|
309
|
-
...options,
|
|
310
|
-
method: "GET"
|
|
311
|
-
});
|
|
312
|
-
};
|
|
313
|
-
const getGetUserByIDUrl = (userId, params) => {
|
|
314
|
-
const normalizedParams = new URLSearchParams();
|
|
315
|
-
Object.entries(params || {}).forEach(([key, value]) => {
|
|
316
|
-
if (value !== void 0) normalizedParams.append(key, value === null ? "null" : value.toString());
|
|
317
|
-
});
|
|
318
|
-
const stringifiedParams = normalizedParams.toString();
|
|
319
|
-
return stringifiedParams.length > 0 ? `${getProxyPath()}/users/${userId}?${stringifiedParams}` : `${getProxyPath()}/users/${userId}`;
|
|
320
|
-
};
|
|
321
|
-
/**
|
|
322
|
-
* @summary Get user by ID
|
|
323
|
-
*/
|
|
324
|
-
const getUserByID = async (userId, params, options) => {
|
|
325
|
-
return customFetch(getGetUserByIDUrl(userId, params), {
|
|
326
|
-
...options,
|
|
327
|
-
method: "GET"
|
|
328
|
-
});
|
|
329
|
-
};
|
|
330
|
-
const getDeleteUserByIDUrl = (userId) => {
|
|
331
|
-
return `${getProxyPath()}/users/${userId}`;
|
|
332
|
-
};
|
|
333
|
-
/**
|
|
334
|
-
* @summary Delete user by ID
|
|
335
|
-
*/
|
|
336
|
-
const deleteUserByID = async (userId, options) => {
|
|
337
|
-
return customFetch(getDeleteUserByIDUrl(userId), {
|
|
338
|
-
...options,
|
|
339
|
-
method: "DELETE"
|
|
340
|
-
});
|
|
341
|
-
};
|
|
342
|
-
const getListUserPasskeysUrl = (userId, params) => {
|
|
343
|
-
const normalizedParams = new URLSearchParams();
|
|
344
|
-
Object.entries(params || {}).forEach(([key, value]) => {
|
|
345
|
-
if (value !== void 0) normalizedParams.append(key, value === null ? "null" : value.toString());
|
|
346
|
-
});
|
|
347
|
-
const stringifiedParams = normalizedParams.toString();
|
|
348
|
-
return stringifiedParams.length > 0 ? `${getProxyPath()}/users/${userId}/passkeys?${stringifiedParams}` : `${getProxyPath()}/users/${userId}/passkeys`;
|
|
349
|
-
};
|
|
350
|
-
/**
|
|
351
|
-
* @summary List user passkeys
|
|
352
|
-
*/
|
|
353
|
-
const listUserPasskeys = async (userId, params, options) => {
|
|
354
|
-
return customFetch(getListUserPasskeysUrl(userId, params), {
|
|
355
|
-
...options,
|
|
356
|
-
method: "GET"
|
|
357
|
-
});
|
|
358
|
-
};
|
|
359
|
-
const getSetUserPasswordUrl = (userId) => {
|
|
360
|
-
return `${getProxyPath()}/users/${userId}/password`;
|
|
361
|
-
};
|
|
362
|
-
/**
|
|
363
|
-
* @summary Set user password
|
|
364
|
-
*/
|
|
365
|
-
const setUserPassword = async (userId, setUserPasswordBody, options) => {
|
|
366
|
-
return customFetch(getSetUserPasswordUrl(userId), {
|
|
367
|
-
...options,
|
|
368
|
-
method: "PUT",
|
|
369
|
-
headers: {
|
|
370
|
-
"Content-Type": "application/json",
|
|
371
|
-
...options?.headers
|
|
372
|
-
},
|
|
373
|
-
body: JSON.stringify(setUserPasswordBody)
|
|
374
|
-
});
|
|
375
|
-
};
|
|
376
|
-
const getListUserTeamsUrl = (userId, params) => {
|
|
377
|
-
const normalizedParams = new URLSearchParams();
|
|
378
|
-
Object.entries(params || {}).forEach(([key, value]) => {
|
|
379
|
-
if (value !== void 0) normalizedParams.append(key, value === null ? "null" : value.toString());
|
|
380
|
-
});
|
|
381
|
-
const stringifiedParams = normalizedParams.toString();
|
|
382
|
-
return stringifiedParams.length > 0 ? `${getProxyPath()}/users/${userId}/teams?${stringifiedParams}` : `${getProxyPath()}/users/${userId}/teams`;
|
|
383
|
-
};
|
|
384
|
-
/**
|
|
385
|
-
* The user's team roster, ordered by team name. Each entry carries the
|
|
386
|
-
team's name, so a client renders a page without resolving ids one by one.
|
|
387
|
-
|
|
388
|
-
This is the N:N roster and it is not lifecycle ownership: the single team
|
|
389
|
-
that owns the user's lifecycle is reported as `metadata.lifecycle_owner_team_id`
|
|
390
|
-
on the user read endpoints. Memberships the user was removed from are not
|
|
391
|
-
returned.
|
|
392
|
-
|
|
393
|
-
* @summary List the teams a user belongs to
|
|
394
|
-
*/
|
|
395
|
-
const listUserTeams = async (userId, params, options) => {
|
|
396
|
-
return customFetch(getListUserTeamsUrl(userId, params), {
|
|
397
|
-
...options,
|
|
398
|
-
method: "GET"
|
|
399
|
-
});
|
|
400
|
-
};
|
|
401
|
-
const getGetMyUserUrl = () => {
|
|
402
|
-
return `${getProxyPath()}/users/me`;
|
|
403
|
-
};
|
|
404
|
-
/**
|
|
405
|
-
* @summary Get my user information
|
|
406
|
-
*/
|
|
407
|
-
const getMyUser = async (options) => {
|
|
408
|
-
return customFetch(getGetMyUserUrl(), {
|
|
409
|
-
...options,
|
|
410
|
-
method: "GET"
|
|
411
|
-
});
|
|
412
|
-
};
|
|
413
|
-
const getCreateFlowUrl = () => {
|
|
414
|
-
return `${getProxyPath()}/flow`;
|
|
415
|
-
};
|
|
416
|
-
/**
|
|
417
|
-
* Resolves a flow definition based on purpose + audience context and returns
|
|
418
|
-
the first capability step. Creates a new session implicitly unless
|
|
419
|
-
`session_id` is provided (for step-up / reauth on an existing session).
|
|
420
|
-
|
|
421
|
-
The response contains an `id` field — the flow handle. Use it as the path
|
|
422
|
-
parameter for all subsequent `/flow/{id}/submit` calls.
|
|
423
|
-
|
|
424
|
-
The response also sets an encrypted `HttpOnly` cookie (`_zflow`) containing
|
|
425
|
-
the flow's orchestration state (current step, collected data, history).
|
|
426
|
-
The server is stateless between requests — all flow state lives in this
|
|
427
|
-
cookie. The browser sends it automatically on subsequent requests.
|
|
428
|
-
|
|
429
|
-
* @summary Start a new flow
|
|
430
|
-
*/
|
|
431
|
-
const createFlow = async (createFlowBody, options) => {
|
|
432
|
-
return customFetch(getCreateFlowUrl(), {
|
|
433
|
-
...options,
|
|
434
|
-
method: "POST",
|
|
435
|
-
headers: {
|
|
436
|
-
"Content-Type": "application/json",
|
|
437
|
-
...options?.headers
|
|
438
|
-
},
|
|
439
|
-
body: JSON.stringify(createFlowBody)
|
|
440
|
-
});
|
|
441
|
-
};
|
|
442
|
-
const getGetFlowStepUrl = (id) => {
|
|
443
|
-
return `${getProxyPath()}/flow/${id}`;
|
|
444
|
-
};
|
|
445
|
-
/**
|
|
446
|
-
* Returns the current capability step without advancing the state machine.
|
|
447
|
-
Useful for page reloads or re-rendering after a network error.
|
|
448
|
-
|
|
449
|
-
* @summary Get current step (re-render)
|
|
450
|
-
*/
|
|
451
|
-
const getFlowStep = async (id, options) => {
|
|
452
|
-
return customFetch(getGetFlowStepUrl(id), {
|
|
453
|
-
...options,
|
|
454
|
-
method: "GET"
|
|
455
|
-
});
|
|
456
|
-
};
|
|
457
|
-
const getSubmitFlowStepUrl = (id) => {
|
|
458
|
-
return `${getProxyPath()}/flow/${id}/submit`;
|
|
459
|
-
};
|
|
460
|
-
/**
|
|
461
|
-
* Submits user input for the current step. The server validates,
|
|
462
|
-
processes (e.g., verifies a credential), advances the state machine
|
|
463
|
-
through any invisible steps, and returns the next visible step.
|
|
464
|
-
|
|
465
|
-
The response sets an updated encrypted `HttpOnly` cookie (`_zflow`)
|
|
466
|
-
with the new flow state. The server is stateless — all orchestration
|
|
467
|
-
state is carried in this cookie between requests.
|
|
468
|
-
|
|
469
|
-
**Important:** The `id` in the response may differ from the `id` used in
|
|
470
|
-
the request. This happens when a flow pivots (pushes a new flow onto the
|
|
471
|
-
stack) or when a stacked flow completes (auto-pops to the parent flow).
|
|
472
|
-
Always use the `id` from the latest response for the next request.
|
|
473
|
-
|
|
474
|
-
## Flow completion
|
|
475
|
-
|
|
476
|
-
When `step.type` is `complete`, the flow is terminal. The `step.behavior`
|
|
477
|
-
field tells the frontend what to do:
|
|
478
|
-
|
|
479
|
-
| `behavior` | Action |
|
|
480
|
-
|------------- |------------------------------------------------------------|
|
|
481
|
-
| `redirect` | Navigate to `redirect_uri` (OIDC/SAML auth request done). |
|
|
482
|
-
| `show` | Render the step as a success screen (e.g., registration). |
|
|
483
|
-
|
|
484
|
-
A `complete` step is only returned when the **entire flow stack** is done.
|
|
485
|
-
If a stacked flow (e.g., recovery pivoted from login) finishes, the server
|
|
486
|
-
auto-pops to the parent flow and returns the parent's next step — the
|
|
487
|
-
frontend never sees a `complete` for intermediate flows.
|
|
488
|
-
|
|
489
|
-
* @summary Submit step data and advance
|
|
490
|
-
*/
|
|
491
|
-
const submitFlowStep = async (id, submitFlowStepBody, options) => {
|
|
492
|
-
return customFetch(getSubmitFlowStepUrl(id), {
|
|
493
|
-
...options,
|
|
494
|
-
method: "POST",
|
|
495
|
-
headers: {
|
|
496
|
-
"Content-Type": "application/json",
|
|
497
|
-
...options?.headers
|
|
498
|
-
},
|
|
499
|
-
body: JSON.stringify(submitFlowStepBody)
|
|
500
|
-
});
|
|
501
|
-
};
|
|
502
|
-
const getCreateAuthAttemptUrl = () => {
|
|
503
|
-
return `${getProxyPath()}/auth_attempts`;
|
|
504
|
-
};
|
|
505
|
-
/**
|
|
506
|
-
* Starts a new authentication attempt. This is the entry point for the auth_attempts state machine.
|
|
507
|
-
|
|
508
|
-
An attempt is an ephemeral (15-minute TTL) state machine that drives a single authentication round.
|
|
509
|
-
It accepts factor challenges, verifies proofs, and completes into a session or handoff token.
|
|
510
|
-
|
|
511
|
-
Accepts a project_id and challenge_nonce (from POST /bootstrap/challenge). For step-up re-auth,
|
|
512
|
-
also include session_id to add factors to an existing session.
|
|
513
|
-
|
|
514
|
-
* @summary Create a new authentication attempt
|
|
515
|
-
*/
|
|
516
|
-
const createAuthAttempt = async (createAuthAttemptBody, options) => {
|
|
517
|
-
return customFetch(getCreateAuthAttemptUrl(), {
|
|
518
|
-
...options,
|
|
519
|
-
method: "POST",
|
|
520
|
-
headers: {
|
|
521
|
-
"Content-Type": "application/json",
|
|
522
|
-
...options?.headers
|
|
523
|
-
},
|
|
524
|
-
body: JSON.stringify(createAuthAttemptBody)
|
|
525
|
-
});
|
|
526
|
-
};
|
|
527
|
-
const getGetAuthAttemptUrl = (attemptId) => {
|
|
528
|
-
return `${getProxyPath()}/auth_attempts/${attemptId}`;
|
|
529
|
-
};
|
|
530
|
-
/**
|
|
531
|
-
* Polls the current state of an authentication attempt.
|
|
532
|
-
|
|
533
|
-
Returns the attempt's state, available factors for the next challenge,
|
|
534
|
-
challenges issued so far, and any errors preventing progress.
|
|
535
|
-
|
|
536
|
-
Use this for polling during long-running factor verifications (e.g., waiting for
|
|
537
|
-
a federated IdP callback or a device flow).
|
|
538
|
-
|
|
539
|
-
* @summary Get authentication attempt state
|
|
540
|
-
*/
|
|
541
|
-
const getAuthAttempt = async (attemptId, options) => {
|
|
542
|
-
return customFetch(getGetAuthAttemptUrl(attemptId), {
|
|
543
|
-
...options,
|
|
544
|
-
method: "GET"
|
|
545
|
-
});
|
|
546
|
-
};
|
|
547
|
-
const getIssueChallengeUrl = (attemptId) => {
|
|
548
|
-
return `${getProxyPath()}/auth_attempts/${attemptId}/challenges`;
|
|
549
|
-
};
|
|
550
|
-
/**
|
|
551
|
-
* Issues a single-factor verification challenge within an auth attempt.
|
|
552
|
-
|
|
553
|
-
This advances the authentication state machine by requesting a specific factor method
|
|
554
|
-
(password, passkey, TOTP, OTP via SMS, etc.). The server responds with challenge details
|
|
555
|
-
including method, metadata, and any UI hints. The client then verifies the proof
|
|
556
|
-
by calling POST /auth_attempts/{attempt_id}/challenges/{challenge_id}/verify.
|
|
557
|
-
|
|
558
|
-
* @summary Issue a factor challenge
|
|
559
|
-
*/
|
|
560
|
-
const issueChallenge = async (attemptId, issueChallengeBody, options) => {
|
|
561
|
-
return customFetch(getIssueChallengeUrl(attemptId), {
|
|
562
|
-
...options,
|
|
563
|
-
method: "POST",
|
|
564
|
-
headers: {
|
|
565
|
-
"Content-Type": "application/json",
|
|
566
|
-
...options?.headers
|
|
567
|
-
},
|
|
568
|
-
body: JSON.stringify(issueChallengeBody)
|
|
569
|
-
});
|
|
570
|
-
};
|
|
571
|
-
const getVerifyChallengeProofUrl = (attemptId, challengeId) => {
|
|
572
|
-
return `${getProxyPath()}/auth_attempts/${attemptId}/challenges/${challengeId}/verify`;
|
|
573
|
-
};
|
|
574
|
-
/**
|
|
575
|
-
* Submits a proof (credential, code, assertion) to verify a factor challenge.
|
|
576
|
-
|
|
577
|
-
The proof format depends on the challenge method. For example:
|
|
578
|
-
- `password` method: { password: "…" }
|
|
579
|
-
- `totp` method: { totp: { code: "123456" } }
|
|
580
|
-
- `passkey` method: { passkey: { assertion: "…" } }
|
|
581
|
-
- `recovery_code` method: { recovery_code: "…" }
|
|
582
|
-
|
|
583
|
-
On successful verification, the factor is written to the auth attempt.
|
|
584
|
-
The attempt moves to the next pending challenge or completes if all required factors are verified.
|
|
585
|
-
|
|
586
|
-
* @summary Verify a factor proof
|
|
587
|
-
*/
|
|
588
|
-
const verifyChallengeProof = async (attemptId, challengeId, verifyChallengeProofBody, options) => {
|
|
589
|
-
return customFetch(getVerifyChallengeProofUrl(attemptId, challengeId), {
|
|
590
|
-
...options,
|
|
591
|
-
method: "POST",
|
|
592
|
-
headers: {
|
|
593
|
-
"Content-Type": "application/json",
|
|
594
|
-
...options?.headers
|
|
595
|
-
},
|
|
596
|
-
body: JSON.stringify(verifyChallengeProofBody)
|
|
597
|
-
});
|
|
598
|
-
};
|
|
599
|
-
const getCreateHandoffUrl = (attemptId) => {
|
|
600
|
-
return `${getProxyPath()}/auth_attempts/${attemptId}/handoff`;
|
|
601
|
-
};
|
|
602
|
-
/**
|
|
603
|
-
* Completes the authentication attempt and mints a `handoff_token`.
|
|
604
|
-
|
|
605
|
-
Call this after all required factors have been verified and the attempt is in `completed` state.
|
|
606
|
-
The handoff token is short-lived (≤60 seconds) and must be exchanged at
|
|
607
|
-
POST /sessions/exchange to receive the final session and session_token.
|
|
608
|
-
|
|
609
|
-
The handoff token is:
|
|
610
|
-
- Single-use (atomic exchange, no retry)
|
|
611
|
-
- Audience-bound (requires matching project key for exchange)
|
|
612
|
-
- Idempotency-safe within a 5-minute window (see conventions)
|
|
613
|
-
|
|
614
|
-
* @summary Complete authentication and create handoff token
|
|
615
|
-
*/
|
|
616
|
-
const createHandoff = async (attemptId, options) => {
|
|
617
|
-
return customFetch(getCreateHandoffUrl(attemptId), {
|
|
618
|
-
...options,
|
|
619
|
-
method: "POST"
|
|
620
|
-
});
|
|
621
|
-
};
|
|
622
|
-
const getCreateProjectUrl = () => {
|
|
623
|
-
return `${getProxyPath()}/projects`;
|
|
624
|
-
};
|
|
625
|
-
/**
|
|
626
|
-
* @summary Create project
|
|
627
|
-
*/
|
|
628
|
-
const createProject = async (createProjectBody, options) => {
|
|
629
|
-
return customFetch(getCreateProjectUrl(), {
|
|
630
|
-
...options,
|
|
631
|
-
method: "POST",
|
|
632
|
-
headers: {
|
|
633
|
-
"Content-Type": "application/json",
|
|
634
|
-
...options?.headers
|
|
635
|
-
},
|
|
636
|
-
body: JSON.stringify(createProjectBody)
|
|
637
|
-
});
|
|
638
|
-
};
|
|
639
|
-
const getQueryProjectsUrl = () => {
|
|
640
|
-
return `${getProxyPath()}/projects/query`;
|
|
641
|
-
};
|
|
642
|
-
/**
|
|
643
|
-
* @summary Query projects
|
|
644
|
-
*/
|
|
645
|
-
const queryProjects = async (queryProjectsBody, options) => {
|
|
646
|
-
return customFetch(getQueryProjectsUrl(), {
|
|
647
|
-
...options,
|
|
648
|
-
method: "POST",
|
|
649
|
-
headers: {
|
|
650
|
-
"Content-Type": "application/json",
|
|
651
|
-
...options?.headers
|
|
652
|
-
},
|
|
653
|
-
body: JSON.stringify(queryProjectsBody)
|
|
654
|
-
});
|
|
655
|
-
};
|
|
656
|
-
const getGetProjectUrl = (projectId) => {
|
|
657
|
-
return `${getProxyPath()}/projects/${projectId}`;
|
|
658
|
-
};
|
|
659
|
-
/**
|
|
660
|
-
* Returns the current state of a project.
|
|
661
|
-
|
|
662
|
-
* @summary Get project
|
|
663
|
-
*/
|
|
664
|
-
const getProject = async (projectId, options) => {
|
|
665
|
-
return customFetch(getGetProjectUrl(projectId), {
|
|
666
|
-
...options,
|
|
667
|
-
method: "GET"
|
|
668
|
-
});
|
|
669
|
-
};
|
|
670
|
-
const getPatchProjectUrl = (projectId) => {
|
|
671
|
-
return `${getProxyPath()}/projects/${projectId}`;
|
|
672
|
-
};
|
|
673
|
-
/**
|
|
674
|
-
* Updates the state of a project.
|
|
675
|
-
|
|
676
|
-
* @summary Update project
|
|
677
|
-
*/
|
|
678
|
-
const patchProject = async (projectId, patchProjectBody, options) => {
|
|
679
|
-
return customFetch(getPatchProjectUrl(projectId), {
|
|
680
|
-
...options,
|
|
681
|
-
method: "PATCH",
|
|
682
|
-
headers: {
|
|
683
|
-
"Content-Type": "application/json",
|
|
684
|
-
...options?.headers
|
|
685
|
-
},
|
|
686
|
-
body: JSON.stringify(patchProjectBody)
|
|
687
|
-
});
|
|
688
|
-
};
|
|
689
|
-
const getInitClaimUrl = (projectId) => {
|
|
690
|
-
return `${getProxyPath()}/projects/${projectId}/claim/init`;
|
|
691
|
-
};
|
|
692
|
-
/**
|
|
693
|
-
* Starts a claim challenge for an unclaimed project. Authenticated by the
|
|
694
|
-
project secret, this mints a single-use, short-lived challenge and returns
|
|
695
|
-
the `claim_url` the developer opens in a browser to complete the claim,
|
|
696
|
-
together with the `challenge_id` the CLI polls with. The exact expiry is
|
|
697
|
-
carried by `expires_at` on the response.
|
|
698
|
-
|
|
699
|
-
* @summary Initialize a project claim
|
|
700
|
-
*/
|
|
701
|
-
const initClaim = async (projectId, options) => {
|
|
702
|
-
return customFetch(getInitClaimUrl(projectId), {
|
|
703
|
-
...options,
|
|
704
|
-
method: "POST"
|
|
705
|
-
});
|
|
706
|
-
};
|
|
707
|
-
const getGetClaimStatusUrl = (projectId, params) => {
|
|
708
|
-
const normalizedParams = new URLSearchParams();
|
|
709
|
-
Object.entries(params || {}).forEach(([key, value]) => {
|
|
710
|
-
if (value !== void 0) normalizedParams.append(key, value === null ? "null" : value.toString());
|
|
711
|
-
});
|
|
712
|
-
const stringifiedParams = normalizedParams.toString();
|
|
713
|
-
return stringifiedParams.length > 0 ? `${getProxyPath()}/projects/${projectId}/claim/status?${stringifiedParams}` : `${getProxyPath()}/projects/${projectId}/claim/status`;
|
|
714
|
-
};
|
|
715
|
-
/**
|
|
716
|
-
* Polled by the CLI while a browser completes the claim. Authorized by the
|
|
717
|
-
project secret that initiated the challenge. Returns `pending`, or
|
|
718
|
-
`completed` with the owning team, the claim timestamp, and the dashboard
|
|
719
|
-
URL once the browser leg has finished.
|
|
720
|
-
|
|
721
|
-
* @summary Get claim status
|
|
722
|
-
*/
|
|
723
|
-
const getClaimStatus = async (projectId, params, options) => {
|
|
724
|
-
return customFetch(getGetClaimStatusUrl(projectId, params), {
|
|
725
|
-
...options,
|
|
726
|
-
method: "GET"
|
|
727
|
-
});
|
|
728
|
-
};
|
|
729
|
-
const getCompleteClaimUrl = (projectId) => {
|
|
730
|
-
return `${getProxyPath()}/projects/${projectId}/claim/complete`;
|
|
731
|
-
};
|
|
732
|
-
/**
|
|
733
|
-
* Called by the browser after the developer authenticates on the claim page.
|
|
734
|
-
Authenticated by the `__nextgen_session` cookie, it attaches the project to
|
|
735
|
-
the developer's personal team using the `challenge_id` from the claim URL as
|
|
736
|
-
its single-use, browser-safe authorization.
|
|
737
|
-
|
|
738
|
-
* @summary Complete a project claim
|
|
739
|
-
*/
|
|
740
|
-
const completeClaim = async (projectId, completeClaimBody, options) => {
|
|
741
|
-
return customFetch(getCompleteClaimUrl(projectId), {
|
|
742
|
-
...options,
|
|
743
|
-
method: "POST",
|
|
744
|
-
headers: {
|
|
745
|
-
"Content-Type": "application/json",
|
|
746
|
-
...options?.headers
|
|
747
|
-
},
|
|
748
|
-
body: JSON.stringify(completeClaimBody)
|
|
749
|
-
});
|
|
750
|
-
};
|
|
751
|
-
const getCreateSessionUrl = () => {
|
|
752
|
-
return `${getProxyPath()}/sessions`;
|
|
753
|
-
};
|
|
754
|
-
/**
|
|
755
|
-
* Creates an anonymous session shell with no user and no factors (`state: building`).
|
|
756
|
-
|
|
757
|
-
This is optional — an `auth_attempt` will create a session implicitly if none is provided.
|
|
758
|
-
Use this explicitly when you want to:
|
|
759
|
-
- Pre-allocate a `session_id` before the user is known, so device/telemetry signals
|
|
760
|
-
can be correlated with the eventual authenticated session from the start.
|
|
761
|
-
- Track anonymous state (bot detection, device fingerprint) that survives until authentication.
|
|
762
|
-
|
|
763
|
-
Creating a session is an app-plane operation on the project credential
|
|
764
|
-
(`session.write`). The returned `session_token` is a session credential for the
|
|
765
|
-
end-user client, not a management scope: it is delivered as the
|
|
766
|
-
`__nextgen_session` cookie and authorises the self-service operations
|
|
767
|
-
`GET /sessions/me` and `DELETE /sessions/me` (`nextgenSession` scheme). The
|
|
768
|
-
by-id operations `GET /sessions/{session_id}` and `DELETE /sessions/{session_id}`
|
|
769
|
-
are operator endpoints and require `session.read` / `session.delete` instead.
|
|
770
|
-
|
|
771
|
-
The `session_token` is superseded when a handoff exchange completes — clients must
|
|
772
|
-
replace it at that point.
|
|
773
|
-
|
|
774
|
-
Anonymous sessions expire aggressively (10-minute TTL). The TTL resets to the configured
|
|
775
|
-
full session TTL when the first authentication factor is written via a completing `auth_attempt`.
|
|
776
|
-
|
|
777
|
-
* @summary Create an anonymous session shell
|
|
778
|
-
*/
|
|
779
|
-
const createSession = async (createSessionBody, options) => {
|
|
780
|
-
return customFetch(getCreateSessionUrl(), {
|
|
781
|
-
...options,
|
|
782
|
-
method: "POST",
|
|
783
|
-
headers: {
|
|
784
|
-
"Content-Type": "application/json",
|
|
785
|
-
...options?.headers
|
|
786
|
-
},
|
|
787
|
-
body: JSON.stringify(createSessionBody)
|
|
788
|
-
});
|
|
789
|
-
};
|
|
790
|
-
const getQuerySessionsUrl = (params) => {
|
|
791
|
-
const normalizedParams = new URLSearchParams();
|
|
792
|
-
Object.entries(params || {}).forEach(([key, value]) => {
|
|
793
|
-
if (value !== void 0) normalizedParams.append(key, value === null ? "null" : value.toString());
|
|
794
|
-
});
|
|
795
|
-
const stringifiedParams = normalizedParams.toString();
|
|
796
|
-
return stringifiedParams.length > 0 ? `${getProxyPath()}/sessions/query?${stringifiedParams}` : `${getProxyPath()}/sessions/query`;
|
|
797
|
-
};
|
|
798
|
-
/**
|
|
799
|
-
* Returns the sessions of a project, paginated with a cursor.
|
|
800
|
-
Sessions of every lifecycle state are returned; each carries its `state`.
|
|
801
|
-
Requires `session.read` permission.
|
|
802
|
-
|
|
803
|
-
* @summary Query sessions
|
|
804
|
-
*/
|
|
805
|
-
const querySessions = async (querySessionsBody, params, options) => {
|
|
806
|
-
return customFetch(getQuerySessionsUrl(params), {
|
|
807
|
-
...options,
|
|
808
|
-
method: "POST",
|
|
809
|
-
headers: {
|
|
810
|
-
"Content-Type": "application/json",
|
|
811
|
-
...options?.headers
|
|
812
|
-
},
|
|
813
|
-
body: JSON.stringify(querySessionsBody)
|
|
814
|
-
});
|
|
815
|
-
};
|
|
816
|
-
const getExchangeHandoffUrl = (params) => {
|
|
817
|
-
const normalizedParams = new URLSearchParams();
|
|
818
|
-
Object.entries(params || {}).forEach(([key, value]) => {
|
|
819
|
-
if (value !== void 0) normalizedParams.append(key, value === null ? "null" : value.toString());
|
|
820
|
-
});
|
|
821
|
-
const stringifiedParams = normalizedParams.toString();
|
|
822
|
-
return stringifiedParams.length > 0 ? `${getProxyPath()}/sessions/exchange?${stringifiedParams}` : `${getProxyPath()}/sessions/exchange`;
|
|
823
|
-
};
|
|
824
|
-
/**
|
|
825
|
-
* Consumes a one-time `handoff_token` minted by `POST /auth_attempts/{id}/handoff`
|
|
826
|
-
and returns the resulting session and a `session_token`.
|
|
827
|
-
|
|
828
|
-
The server resolves the originating `auth_attempt` from the token and then:
|
|
829
|
-
|
|
830
|
-
| Originating auth_attempt | Outcome |
|
|
831
|
-
|---|---|
|
|
832
|
-
| No `session_id` | A new authenticated session is **created**. |
|
|
833
|
-
| `session_id` points to an anonymous shell | Existing session is **upgraded** — user and factors written in, TTL reset to full session TTL. |
|
|
834
|
-
| `session_id` points to an active session (step-up) | Existing session is **upgraded** — new factors merged, `assurance_levels[]` expanded. |
|
|
835
|
-
|
|
836
|
-
The response shape is identical in all three cases.
|
|
837
|
-
|
|
838
|
-
The `session_token` supersedes any previously issued `session_token` for the same session.
|
|
839
|
-
Clients must replace their stored token at this point.
|
|
840
|
-
|
|
841
|
-
Requires a project service key (OAuth2 client credentials).
|
|
842
|
-
|
|
843
|
-
* @summary Exchange handoff token for a session
|
|
844
|
-
*/
|
|
845
|
-
const exchangeHandoff = async (exchangeHandoffBody, params, options) => {
|
|
846
|
-
return customFetch(getExchangeHandoffUrl(params), {
|
|
847
|
-
...options,
|
|
848
|
-
method: "POST",
|
|
849
|
-
headers: {
|
|
850
|
-
"Content-Type": "application/json",
|
|
851
|
-
...options?.headers
|
|
852
|
-
},
|
|
853
|
-
body: JSON.stringify(exchangeHandoffBody)
|
|
854
|
-
});
|
|
855
|
-
};
|
|
856
|
-
const getGetSessionUrl = (sessionId) => {
|
|
857
|
-
return `${getProxyPath()}/sessions/${sessionId}`;
|
|
858
|
-
};
|
|
859
|
-
/**
|
|
860
|
-
* Returns the current state of a session including its factors and all currently
|
|
861
|
-
satisfied assurance levels.
|
|
862
|
-
|
|
863
|
-
`assurance_levels[]` may shrink over time as factor freshness windows expire,
|
|
864
|
-
without the session itself expiring. Use step-up authentication (a new `auth_attempt`
|
|
865
|
-
against the same `session_id`) to restore a dropped assurance level.
|
|
866
|
-
|
|
867
|
-
* @summary Get session state
|
|
868
|
-
*/
|
|
869
|
-
const getSession = async (sessionId, options) => {
|
|
870
|
-
return customFetch(getGetSessionUrl(sessionId), {
|
|
871
|
-
...options,
|
|
872
|
-
method: "GET"
|
|
873
|
-
});
|
|
874
|
-
};
|
|
875
|
-
const getRevokeSessionUrl = (sessionId) => {
|
|
876
|
-
return `${getProxyPath()}/sessions/${sessionId}`;
|
|
877
|
-
};
|
|
878
|
-
/**
|
|
879
|
-
* Permanently deletes the session, terminating it immediately.
|
|
880
|
-
|
|
881
|
-
This is the operator revoke path and requires the `session.delete` scope on a
|
|
882
|
-
project-bound credential. End-user logout with the `__nextgen_session` cookie is
|
|
883
|
-
`DELETE /sessions/me` (`nextgenSession` scheme).
|
|
884
|
-
|
|
885
|
-
Idempotent: deleting a session that does not exist (or was already deleted)
|
|
886
|
-
still returns 204. After deletion, any tokens derived from the session are
|
|
887
|
-
invalidated.
|
|
888
|
-
|
|
889
|
-
* @summary Revoke session
|
|
890
|
-
*/
|
|
891
|
-
const revokeSession = async (sessionId, options) => {
|
|
892
|
-
return customFetch(getRevokeSessionUrl(sessionId), {
|
|
893
|
-
...options,
|
|
894
|
-
method: "DELETE"
|
|
895
|
-
});
|
|
896
|
-
};
|
|
897
|
-
const getGetMySessionUrl = () => {
|
|
898
|
-
return `${getProxyPath()}/sessions/me`;
|
|
899
|
-
};
|
|
900
|
-
/**
|
|
901
|
-
* Returns the current state of the current session including its factors and all currently
|
|
902
|
-
satisfied assurance levels.
|
|
903
|
-
|
|
904
|
-
`assurance_levels[]` may shrink over time as factor freshness windows expire,
|
|
905
|
-
without the session itself expiring. Use step-up authentication (a new `auth_attempt`
|
|
906
|
-
against the same `session_id`) to restore a dropped assurance level.
|
|
907
|
-
|
|
908
|
-
* @summary Get my session state
|
|
909
|
-
*/
|
|
910
|
-
const getMySession = async (options) => {
|
|
911
|
-
return customFetch(getGetMySessionUrl(), {
|
|
912
|
-
...options,
|
|
913
|
-
method: "GET"
|
|
914
|
-
});
|
|
915
|
-
};
|
|
916
|
-
const getRevokeMySessionUrl = () => {
|
|
917
|
-
return `${getProxyPath()}/sessions/me`;
|
|
918
|
-
};
|
|
919
|
-
/**
|
|
920
|
-
* Logs out by permanently deleting the session.
|
|
921
|
-
|
|
922
|
-
The `__nextgen_session` cookie issued at creation (or superseded by a handoff
|
|
923
|
-
exchange) is required. Idempotent: if the session is already gone this still
|
|
924
|
-
returns 204. Any tokens derived from the session are invalidated, and the
|
|
925
|
-
cookie itself is cleared in the response.
|
|
926
|
-
|
|
927
|
-
* @summary Revoke my session
|
|
928
|
-
*/
|
|
929
|
-
const revokeMySession = async (options) => {
|
|
930
|
-
return customFetch(getRevokeMySessionUrl(), {
|
|
931
|
-
...options,
|
|
932
|
-
method: "DELETE"
|
|
933
|
-
});
|
|
934
|
-
};
|
|
935
|
-
const getCreateSchemaUrl = (params) => {
|
|
936
|
-
const normalizedParams = new URLSearchParams();
|
|
937
|
-
Object.entries(params || {}).forEach(([key, value]) => {
|
|
938
|
-
if (value !== void 0) normalizedParams.append(key, value === null ? "null" : value.toString());
|
|
939
|
-
});
|
|
940
|
-
const stringifiedParams = normalizedParams.toString();
|
|
941
|
-
return stringifiedParams.length > 0 ? `${getProxyPath()}/schemas?${stringifiedParams}` : `${getProxyPath()}/schemas`;
|
|
942
|
-
};
|
|
943
|
-
/**
|
|
944
|
-
* Create a new schema. The optional `$id` field is the JSON Schema document
|
|
945
|
-
URI used to identify the schema in future requests (GitOps-stable identity,
|
|
946
|
-
not a free-form resource primary key). When `$id` is omitted, the server
|
|
947
|
-
generates a `sch_*` URL. When provided, `$id` must be unique within the
|
|
948
|
-
project and should ideally be a valid URI pointing at where the schema can
|
|
949
|
-
be accessed.
|
|
950
|
-
|
|
951
|
-
The schema can either be a concrete schema, e.g. a user schema, or a
|
|
952
|
-
schema-url which will be resolved by the server.
|
|
953
|
-
|
|
954
|
-
* @summary Create new schema
|
|
955
|
-
*/
|
|
956
|
-
const createSchema = async (createSchemaBody, params, options) => {
|
|
957
|
-
return customFetch(getCreateSchemaUrl(params), {
|
|
958
|
-
...options,
|
|
959
|
-
method: "POST",
|
|
960
|
-
headers: {
|
|
961
|
-
"Content-Type": "application/json",
|
|
962
|
-
...options?.headers
|
|
963
|
-
},
|
|
964
|
-
body: JSON.stringify(createSchemaBody)
|
|
965
|
-
});
|
|
966
|
-
};
|
|
967
|
-
const getListSchemasUrl = (params) => {
|
|
968
|
-
const normalizedParams = new URLSearchParams();
|
|
969
|
-
Object.entries(params || {}).forEach(([key, value]) => {
|
|
970
|
-
if (value !== void 0) normalizedParams.append(key, value === null ? "null" : value.toString());
|
|
971
|
-
});
|
|
972
|
-
const stringifiedParams = normalizedParams.toString();
|
|
973
|
-
return stringifiedParams.length > 0 ? `${getProxyPath()}/schemas?${stringifiedParams}` : `${getProxyPath()}/schemas`;
|
|
974
|
-
};
|
|
975
|
-
/**
|
|
976
|
-
* Retrieve a list of all schemas available in the system. This endpoint
|
|
977
|
-
supports pagination and filtering based on schema attributes.
|
|
978
|
-
|
|
979
|
-
* @summary List all schemas
|
|
980
|
-
*/
|
|
981
|
-
const listSchemas = async (params, options) => {
|
|
982
|
-
return customFetch(getListSchemasUrl(params), {
|
|
983
|
-
...options,
|
|
984
|
-
method: "GET"
|
|
985
|
-
});
|
|
986
|
-
};
|
|
987
|
-
const getGetSchemaByIdUrl = (id, params) => {
|
|
988
|
-
const normalizedParams = new URLSearchParams();
|
|
989
|
-
Object.entries(params || {}).forEach(([key, value]) => {
|
|
990
|
-
if (value !== void 0) normalizedParams.append(key, value === null ? "null" : value.toString());
|
|
991
|
-
});
|
|
992
|
-
const stringifiedParams = normalizedParams.toString();
|
|
993
|
-
return stringifiedParams.length > 0 ? `${getProxyPath()}/schemas/${id}?${stringifiedParams}` : `${getProxyPath()}/schemas/${id}`;
|
|
994
|
-
};
|
|
995
|
-
/**
|
|
996
|
-
* Get a schema by its ID. This will return the default revision of the schema.
|
|
997
|
-
* @summary Get schema by ID
|
|
998
|
-
*/
|
|
999
|
-
const getSchemaById = async (id, params, options) => {
|
|
1000
|
-
return customFetch(getGetSchemaByIdUrl(id, params), {
|
|
1001
|
-
...options,
|
|
1002
|
-
method: "GET"
|
|
1003
|
-
});
|
|
1004
|
-
};
|
|
1005
|
-
const getCreateFlowDefinitionUrl = () => {
|
|
1006
|
-
return `${getProxyPath()}/flow_definitions`;
|
|
1007
|
-
};
|
|
1008
|
-
/**
|
|
1009
|
-
* Creates a new flow definition.
|
|
1010
|
-
Flow definitions are templates that define the sequence of steps (capabilities)
|
|
1011
|
-
for a particular user journey (e.g., registration, login, password reset).
|
|
1012
|
-
|
|
1013
|
-
Flow definitions are created based on the flow definition schema, which includes the flow's purpose, audience, and the steps involved.
|
|
1014
|
-
|
|
1015
|
-
* @summary Create a new flow definition
|
|
1016
|
-
*/
|
|
1017
|
-
const createFlowDefinition = async (createFlowDefinitionBody, options) => {
|
|
1018
|
-
return customFetch(getCreateFlowDefinitionUrl(), {
|
|
1019
|
-
...options,
|
|
1020
|
-
method: "POST",
|
|
1021
|
-
headers: {
|
|
1022
|
-
"Content-Type": "application/json",
|
|
1023
|
-
...options?.headers
|
|
1024
|
-
},
|
|
1025
|
-
body: JSON.stringify(createFlowDefinitionBody)
|
|
1026
|
-
});
|
|
1027
|
-
};
|
|
1028
|
-
const getListFlowDefinitionsUrl = (params) => {
|
|
1029
|
-
const normalizedParams = new URLSearchParams();
|
|
1030
|
-
Object.entries(params || {}).forEach(([key, value]) => {
|
|
1031
|
-
if (value !== void 0) normalizedParams.append(key, value === null ? "null" : value.toString());
|
|
1032
|
-
});
|
|
1033
|
-
const stringifiedParams = normalizedParams.toString();
|
|
1034
|
-
return stringifiedParams.length > 0 ? `${getProxyPath()}/flow_definitions?${stringifiedParams}` : `${getProxyPath()}/flow_definitions`;
|
|
1035
|
-
};
|
|
1036
|
-
/**
|
|
1037
|
-
* Retrieves a list of all flow definitions.
|
|
1038
|
-
This endpoint can be used to view existing flow definitions and their configurations.
|
|
1039
|
-
|
|
1040
|
-
* @summary List flow definitions
|
|
1041
|
-
*/
|
|
1042
|
-
const listFlowDefinitions = async (params, options) => {
|
|
1043
|
-
return customFetch(getListFlowDefinitionsUrl(params), {
|
|
1044
|
-
...options,
|
|
1045
|
-
method: "GET"
|
|
1046
|
-
});
|
|
1047
|
-
};
|
|
1048
|
-
const getGetFlowDefinitionUrl = (id) => {
|
|
1049
|
-
return `${getProxyPath()}/flow_definitions/${id}`;
|
|
1050
|
-
};
|
|
1051
|
-
/**
|
|
1052
|
-
* Get a flow definition by id
|
|
1053
|
-
* @summary Get a flow definition by id
|
|
1054
|
-
*/
|
|
1055
|
-
const getFlowDefinition = async (id, options) => {
|
|
1056
|
-
return customFetch(getGetFlowDefinitionUrl(id), {
|
|
1057
|
-
...options,
|
|
1058
|
-
method: "GET"
|
|
1059
|
-
});
|
|
1060
|
-
};
|
|
1061
|
-
const getUpdateFlowDefinitionUrl = (id) => {
|
|
1062
|
-
return `${getProxyPath()}/flow_definitions/${id}`;
|
|
1063
|
-
};
|
|
1064
|
-
/**
|
|
1065
|
-
* Update a flow definition by id. This endpoint replaces the existing flow definition.
|
|
1066
|
-
If `flow_definition.status` is omitted, the current status is preserved
|
|
1067
|
-
|
|
1068
|
-
* @summary Update a flow definition by id
|
|
1069
|
-
*/
|
|
1070
|
-
const updateFlowDefinition = async (id, updateFlowDefinitionBody, options) => {
|
|
1071
|
-
return customFetch(getUpdateFlowDefinitionUrl(id), {
|
|
1072
|
-
...options,
|
|
1073
|
-
method: "PUT",
|
|
1074
|
-
headers: {
|
|
1075
|
-
"Content-Type": "application/json",
|
|
1076
|
-
...options?.headers
|
|
1077
|
-
},
|
|
1078
|
-
body: JSON.stringify(updateFlowDefinitionBody)
|
|
1079
|
-
});
|
|
1080
|
-
};
|
|
1081
|
-
const getDeleteFlowDefinitionUrl = (id) => {
|
|
1082
|
-
return `${getProxyPath()}/flow_definitions/${id}`;
|
|
1083
|
-
};
|
|
1084
|
-
/**
|
|
1085
|
-
* Delete a flow definition by id.
|
|
1086
|
-
If the flow definition is currently being used by a flow, the deletion will fail.
|
|
1087
|
-
If the flow definition is the last active flow definition for a given purpose, the deletion will fail to prevent disruption of new flows being started for that purpose.
|
|
1088
|
-
|
|
1089
|
-
* @summary Delete a flow definition by id
|
|
1090
|
-
*/
|
|
1091
|
-
const deleteFlowDefinition = async (id, options) => {
|
|
1092
|
-
return customFetch(getDeleteFlowDefinitionUrl(id), {
|
|
1093
|
-
...options,
|
|
1094
|
-
method: "DELETE"
|
|
1095
|
-
});
|
|
1096
|
-
};
|
|
1097
|
-
const getCreateTeamUrl = (params) => {
|
|
1098
|
-
const normalizedParams = new URLSearchParams();
|
|
1099
|
-
Object.entries(params || {}).forEach(([key, value]) => {
|
|
1100
|
-
if (value !== void 0) normalizedParams.append(key, value === null ? "null" : value.toString());
|
|
1101
|
-
});
|
|
1102
|
-
const stringifiedParams = normalizedParams.toString();
|
|
1103
|
-
return stringifiedParams.length > 0 ? `${getProxyPath()}/teams?${stringifiedParams}` : `${getProxyPath()}/teams`;
|
|
1104
|
-
};
|
|
1105
|
-
/**
|
|
1106
|
-
* @summary Create team
|
|
1107
|
-
*/
|
|
1108
|
-
const createTeam = async (createTeamBody, params, options) => {
|
|
1109
|
-
return customFetch(getCreateTeamUrl(params), {
|
|
1110
|
-
...options,
|
|
1111
|
-
method: "POST",
|
|
1112
|
-
headers: {
|
|
1113
|
-
"Content-Type": "application/json",
|
|
1114
|
-
...options?.headers
|
|
1115
|
-
},
|
|
1116
|
-
body: JSON.stringify(createTeamBody)
|
|
1117
|
-
});
|
|
1118
|
-
};
|
|
1119
|
-
const getQueryTeamsUrl = (params) => {
|
|
1120
|
-
const normalizedParams = new URLSearchParams();
|
|
1121
|
-
Object.entries(params || {}).forEach(([key, value]) => {
|
|
1122
|
-
if (value !== void 0) normalizedParams.append(key, value === null ? "null" : value.toString());
|
|
1123
|
-
});
|
|
1124
|
-
const stringifiedParams = normalizedParams.toString();
|
|
1125
|
-
return stringifiedParams.length > 0 ? `${getProxyPath()}/teams/query?${stringifiedParams}` : `${getProxyPath()}/teams/query`;
|
|
1126
|
-
};
|
|
1127
|
-
/**
|
|
1128
|
-
* Returns the teams of a project, paginated with a cursor.
|
|
1129
|
-
|
|
1130
|
-
* @summary Query teams
|
|
1131
|
-
*/
|
|
1132
|
-
const queryTeams = async (queryTeamsBody, params, options) => {
|
|
1133
|
-
return customFetch(getQueryTeamsUrl(params), {
|
|
1134
|
-
...options,
|
|
1135
|
-
method: "POST",
|
|
1136
|
-
headers: {
|
|
1137
|
-
"Content-Type": "application/json",
|
|
1138
|
-
...options?.headers
|
|
1139
|
-
},
|
|
1140
|
-
body: JSON.stringify(queryTeamsBody)
|
|
1141
|
-
});
|
|
1142
|
-
};
|
|
1143
|
-
const getGetTeamUrl = (teamId) => {
|
|
1144
|
-
return `${getProxyPath()}/teams/${teamId}`;
|
|
1145
|
-
};
|
|
1146
|
-
/**
|
|
1147
|
-
* Returns a Team by its id.
|
|
1148
|
-
|
|
1149
|
-
* @summary Get team
|
|
1150
|
-
*/
|
|
1151
|
-
const getTeam = async (teamId, options) => {
|
|
1152
|
-
return customFetch(getGetTeamUrl(teamId), {
|
|
1153
|
-
...options,
|
|
1154
|
-
method: "GET"
|
|
1155
|
-
});
|
|
1156
|
-
};
|
|
1157
|
-
const getDeleteTeamUrl = (teamId) => {
|
|
1158
|
-
return `${getProxyPath()}/teams/${teamId}`;
|
|
1159
|
-
};
|
|
1160
|
-
/**
|
|
1161
|
-
* Deactivates the team.
|
|
1162
|
-
|
|
1163
|
-
The team is tombstoned rather than erased: it stays readable through
|
|
1164
|
-
getTeam with status `deactivated`. Its memberships are removed and the
|
|
1165
|
-
users whose lifecycle it owns are deactivated with it.
|
|
1166
|
-
|
|
1167
|
-
The request is idempotent. Deleting a team that is already deactivated
|
|
1168
|
-
or doesn't exist succeeds without changing anything.
|
|
1169
|
-
|
|
1170
|
-
* @summary Delete team
|
|
1171
|
-
*/
|
|
1172
|
-
const deleteTeam = async (teamId, options) => {
|
|
1173
|
-
return customFetch(getDeleteTeamUrl(teamId), {
|
|
1174
|
-
...options,
|
|
1175
|
-
method: "DELETE"
|
|
1176
|
-
});
|
|
1177
|
-
};
|
|
1178
|
-
const getUpdateTeamUrl = (teamId) => {
|
|
1179
|
-
return `${getProxyPath()}/teams/${teamId}`;
|
|
1180
|
-
};
|
|
1181
|
-
/**
|
|
1182
|
-
* Update team. Only active teams can be updated.
|
|
1183
|
-
|
|
1184
|
-
* @summary Update team
|
|
1185
|
-
*/
|
|
1186
|
-
const updateTeam = async (teamId, updateTeamBody, options) => {
|
|
1187
|
-
return customFetch(getUpdateTeamUrl(teamId), {
|
|
1188
|
-
...options,
|
|
1189
|
-
method: "PATCH",
|
|
1190
|
-
headers: {
|
|
1191
|
-
"Content-Type": "application/json",
|
|
1192
|
-
...options?.headers
|
|
1193
|
-
},
|
|
1194
|
-
body: JSON.stringify(updateTeamBody)
|
|
1195
|
-
});
|
|
1196
|
-
};
|
|
1197
|
-
const getCreateBrandingUrl = (params) => {
|
|
1198
|
-
const normalizedParams = new URLSearchParams();
|
|
1199
|
-
Object.entries(params || {}).forEach(([key, value]) => {
|
|
1200
|
-
if (value !== void 0) normalizedParams.append(key, value === null ? "null" : value.toString());
|
|
1201
|
-
});
|
|
1202
|
-
const stringifiedParams = normalizedParams.toString();
|
|
1203
|
-
return stringifiedParams.length > 0 ? `${getProxyPath()}/branding?${stringifiedParams}` : `${getProxyPath()}/branding`;
|
|
1204
|
-
};
|
|
1205
|
-
/**
|
|
1206
|
-
* Publishes a new immutable branding revision for the project. Branding
|
|
1207
|
-
revisions cannot be updated or deleted; every edit publishes a new
|
|
1208
|
-
revision, and flow responses resolve the latest revision per project
|
|
1209
|
-
(see ADR 040).
|
|
1210
|
-
|
|
1211
|
-
The `liquid_template` is validated lexically on save (size, encoding,
|
|
1212
|
-
banned patterns such as `<script>` tags, inline event handlers, and the
|
|
1213
|
-
`| raw` filter). Authoritative LiquidJS validation runs at authoring
|
|
1214
|
-
time via `zitadel plan` / `zitadel apply`.
|
|
1215
|
-
|
|
1216
|
-
* @summary Publish a new branding revision
|
|
1217
|
-
*/
|
|
1218
|
-
const createBranding = async (createBrandingBody, params, options) => {
|
|
1219
|
-
return customFetch(getCreateBrandingUrl(params), {
|
|
1220
|
-
...options,
|
|
1221
|
-
method: "POST",
|
|
1222
|
-
headers: {
|
|
1223
|
-
"Content-Type": "application/json",
|
|
1224
|
-
...options?.headers
|
|
1225
|
-
},
|
|
1226
|
-
body: JSON.stringify(createBrandingBody)
|
|
1227
|
-
});
|
|
1228
|
-
};
|
|
1229
|
-
const getListBrandingUrl = (params) => {
|
|
1230
|
-
const normalizedParams = new URLSearchParams();
|
|
1231
|
-
Object.entries(params || {}).forEach(([key, value]) => {
|
|
1232
|
-
if (value !== void 0) normalizedParams.append(key, value === null ? "null" : value.toString());
|
|
1233
|
-
});
|
|
1234
|
-
const stringifiedParams = normalizedParams.toString();
|
|
1235
|
-
return stringifiedParams.length > 0 ? `${getProxyPath()}/branding?${stringifiedParams}` : `${getProxyPath()}/branding`;
|
|
1236
|
-
};
|
|
1237
|
-
/**
|
|
1238
|
-
* Lists branding revisions for the project, newest first, capped at the
|
|
1239
|
-
100 most recent. The first entry is the revision flow responses
|
|
1240
|
-
currently resolve. Deliberately unpaginated in v1 — list endpoints
|
|
1241
|
-
gain a real query mechanism together (ADR 031); advertising pagination
|
|
1242
|
-
parameters the server ignores would be worse than none.
|
|
1243
|
-
|
|
1244
|
-
* @summary List branding revisions
|
|
1245
|
-
*/
|
|
1246
|
-
const listBranding = async (params, options) => {
|
|
1247
|
-
return customFetch(getListBrandingUrl(params), {
|
|
1248
|
-
...options,
|
|
1249
|
-
method: "GET"
|
|
1250
|
-
});
|
|
1251
|
-
};
|
|
1252
|
-
const getGetBrandingByIdUrl = (id) => {
|
|
1253
|
-
return `${getProxyPath()}/branding/${id}`;
|
|
1254
|
-
};
|
|
1255
|
-
/**
|
|
1256
|
-
* Retrieves a single branding revision, including its stored configuration.
|
|
1257
|
-
* @summary Get a branding revision by ID
|
|
1258
|
-
*/
|
|
1259
|
-
const getBrandingById = async (id, options) => {
|
|
1260
|
-
return customFetch(getGetBrandingByIdUrl(id), {
|
|
1261
|
-
...options,
|
|
1262
|
-
method: "GET"
|
|
1263
|
-
});
|
|
1264
|
-
};
|
|
1265
|
-
const getListEventsUrl = (params) => {
|
|
1266
|
-
const normalizedParams = new URLSearchParams();
|
|
1267
|
-
Object.entries(params || {}).forEach(([key, value]) => {
|
|
1268
|
-
if (Array.isArray(value) && ["category", "event_type"].includes(key)) {
|
|
1269
|
-
value.forEach((v) => {
|
|
1270
|
-
normalizedParams.append(key, v === null ? "null" : v.toString());
|
|
1271
|
-
});
|
|
1272
|
-
return;
|
|
1273
|
-
}
|
|
1274
|
-
if (value !== void 0) normalizedParams.append(key, value === null ? "null" : value.toString());
|
|
1275
|
-
});
|
|
1276
|
-
const stringifiedParams = normalizedParams.toString();
|
|
1277
|
-
return stringifiedParams.length > 0 ? `${getProxyPath()}/events?${stringifiedParams}` : `${getProxyPath()}/events`;
|
|
1278
|
-
};
|
|
1279
|
-
/**
|
|
1280
|
-
* Returns project-scoped audit events, newest-first by keyset on
|
|
1281
|
-
`(created_at, id)` (ADR 027 / ADR 049). Pass `order=asc` for oldest-first.
|
|
1282
|
-
Requires `events.read`.
|
|
1283
|
-
|
|
1284
|
-
Pre-claim projects return an empty list (events are stored but not
|
|
1285
|
-
visible until claim succeeds). Team-scoped credentials see only events
|
|
1286
|
-
whose emit-time `team_id` matches the credential team (enforced when
|
|
1287
|
-
team-scoped tokens exist).
|
|
1288
|
-
|
|
1289
|
-
Clients discriminate each item via `event_type` (OpenAPI Event oneOf) —
|
|
1290
|
-
see docs/design/api/events-catalog.md.
|
|
1291
|
-
|
|
1292
|
-
* @summary List events
|
|
1293
|
-
*/
|
|
1294
|
-
const listEvents = async (params, options) => {
|
|
1295
|
-
return customFetch(getListEventsUrl(params), {
|
|
1296
|
-
...options,
|
|
1297
|
-
method: "GET"
|
|
1298
|
-
});
|
|
1299
|
-
};
|
|
1300
|
-
const getGetEventUrl = (id, params) => {
|
|
1301
|
-
const normalizedParams = new URLSearchParams();
|
|
1302
|
-
Object.entries(params || {}).forEach(([key, value]) => {
|
|
1303
|
-
if (value !== void 0) normalizedParams.append(key, value === null ? "null" : value.toString());
|
|
1304
|
-
});
|
|
1305
|
-
const stringifiedParams = normalizedParams.toString();
|
|
1306
|
-
return stringifiedParams.length > 0 ? `${getProxyPath()}/events/${id}?${stringifiedParams}` : `${getProxyPath()}/events/${id}`;
|
|
1307
|
-
};
|
|
1308
|
-
/**
|
|
1309
|
-
* Loads a single event by `(project_id, id)`. Requires `events.read`.
|
|
1310
|
-
Events are not registered in `resource_scope_index`; project scope is
|
|
1311
|
-
required on the query (ADR 049). Misses and cross-project ids return 404.
|
|
1312
|
-
|
|
1313
|
-
Pre-claim projects return 404 (stored events stay invisible until claim).
|
|
1314
|
-
|
|
1315
|
-
* @summary Get event by ID
|
|
1316
|
-
*/
|
|
1317
|
-
const getEvent = async (id, params, options) => {
|
|
1318
|
-
return customFetch(getGetEventUrl(id, params), {
|
|
1319
|
-
...options,
|
|
1320
|
-
method: "GET"
|
|
1321
|
-
});
|
|
1322
|
-
};
|
|
1323
|
-
//#endregion
|
|
1324
|
-
//#region ../api/dist/runtime/api-factory.mjs
|
|
1325
|
-
/**
|
|
1326
|
-
* Factory for the typed Zitadel client every consumer reaches for.
|
|
1327
|
-
*
|
|
1328
|
-
* Wraps the orval-generated endpoints in a {@link Proxy} so each
|
|
1329
|
-
* generated function sees the right base URL and (optionally) the
|
|
1330
|
-
* right bearer token at call time — without the caller having to
|
|
1331
|
-
* thread either through every operation, and without exposing the
|
|
1332
|
-
* module-globals (`setProxyPath` / `setApiAuthToken`) as part of the
|
|
1333
|
-
* public API.
|
|
1334
|
-
*
|
|
1335
|
-
* Per-instance isolation: multiple clients can coexist in one process
|
|
1336
|
-
* (different servers, different tokens). Their Proxy `get` traps set
|
|
1337
|
-
* the globals synchronously before invoking the underlying generated
|
|
1338
|
-
* function, which reads them at the top of `customFetch` before any
|
|
1339
|
-
* `await`. Two clients running interleaved within a single JS turn
|
|
1340
|
-
* are safe; two clients running in parallel across awaits could
|
|
1341
|
-
* clobber each other — not a pattern any current consumer uses.
|
|
1342
|
-
*/
|
|
1343
|
-
/**
|
|
1344
|
-
* Build a typed Zitadel client pre-bound to a base URL and (optionally)
|
|
1345
|
-
* a bearer token. Every method on the returned object mirrors a
|
|
1346
|
-
* generated orval function:
|
|
1347
|
-
*
|
|
1348
|
-
* const client = createZitadelClient({ baseUrl, token });
|
|
1349
|
-
* await client.createProject({ preview_origins: [] });
|
|
1350
|
-
* await client.createSchema(body, { project_id });
|
|
1351
|
-
*/
|
|
1352
|
-
function createZitadelClient(opts) {
|
|
1353
|
-
let baseUrl = opts.baseUrl;
|
|
1354
|
-
while (baseUrl.endsWith("/")) baseUrl = baseUrl.slice(0, -1);
|
|
1355
|
-
return new Proxy(zitadelNextGen_exports, { get(target, prop, receiver) {
|
|
1356
|
-
const value = Reflect.get(target, prop, receiver);
|
|
1357
|
-
if (typeof value !== "function") return value;
|
|
1358
|
-
return (...args) => {
|
|
1359
|
-
setProxyPath(baseUrl);
|
|
1360
|
-
setApiAuthToken(opts.token);
|
|
1361
|
-
return value(...args);
|
|
1362
|
-
};
|
|
1363
|
-
} });
|
|
1364
|
-
}
|
|
1365
|
-
//#endregion
|
|
1366
|
-
//#region ../config/dist/defaults-eiGHyI5Y.mjs
|
|
1367
|
-
var default_human_user_default = {
|
|
1368
|
-
title: "DefaultHumanUserSchema",
|
|
1369
|
-
$schema: "https://json-schema.org/draft/2020-12/schema",
|
|
1370
|
-
metaSchema: "${SERVER_URL}/user-schema.json",
|
|
1371
|
-
$id: "${USER_SCHEMA_URL}",
|
|
1372
|
-
objectType: "human-user",
|
|
1373
|
-
kind: "user-schema",
|
|
1374
|
-
type: "object",
|
|
1375
|
-
description: "The default editable schema for human users.",
|
|
1376
|
-
"x-auth-methods": {
|
|
1377
|
-
"password": { "enabled": true },
|
|
1378
|
-
"passkey": { "enabled": true }
|
|
1379
|
-
},
|
|
1380
|
-
required: ["email"],
|
|
1381
|
-
properties: { "email": {
|
|
1382
|
-
"type": "string",
|
|
1383
|
-
"format": "email",
|
|
1384
|
-
"x-unique": "project",
|
|
1385
|
-
"description": "The user's email address."
|
|
1386
|
-
} }
|
|
1387
|
-
};
|
|
1388
|
-
var default_login_default = {
|
|
1389
|
-
$schema: "../meta/flow-definition.json",
|
|
1390
|
-
name: "default-login",
|
|
1391
|
-
status: "active",
|
|
1392
|
-
user_schema: "${USER_SCHEMA_URL}",
|
|
1393
|
-
purposes: {
|
|
1394
|
-
"login": "identifier",
|
|
1395
|
-
"register": "register"
|
|
1396
|
-
},
|
|
1397
|
-
steps: [
|
|
1398
|
-
{
|
|
1399
|
-
"name": "identifier",
|
|
1400
|
-
"fields": ["email"],
|
|
1401
|
-
"actions": [
|
|
1402
|
-
{
|
|
1403
|
-
"name": "submit",
|
|
1404
|
-
"kind": "submit",
|
|
1405
|
-
"primary": true,
|
|
1406
|
-
"text_key": "identifier.action.continue"
|
|
1407
|
-
},
|
|
1408
|
-
{
|
|
1409
|
-
"name": "passkey",
|
|
1410
|
-
"kind": "passkey",
|
|
1411
|
-
"primary": false,
|
|
1412
|
-
"text_key": "identifier.action.passkey"
|
|
1413
|
-
},
|
|
1414
|
-
{
|
|
1415
|
-
"name": "register",
|
|
1416
|
-
"kind": "navigate",
|
|
1417
|
-
"primary": false,
|
|
1418
|
-
"text_key": "identifier.action.register.link"
|
|
1419
|
-
}
|
|
1420
|
-
],
|
|
1421
|
-
"transitions": {
|
|
1422
|
-
"submit": { "target": "password" },
|
|
1423
|
-
"passkey": { "target": "done" },
|
|
1424
|
-
"user_not_found": { "target": "register" },
|
|
1425
|
-
"register": {
|
|
1426
|
-
"target": "register",
|
|
1427
|
-
"purpose": "register"
|
|
1428
|
-
}
|
|
1429
|
-
}
|
|
1430
|
-
},
|
|
1431
|
-
{
|
|
1432
|
-
"name": "password",
|
|
1433
|
-
"fields": ["x-auth-methods#password"],
|
|
1434
|
-
"actions": [{
|
|
1435
|
-
"name": "submit",
|
|
1436
|
-
"kind": "submit",
|
|
1437
|
-
"primary": true,
|
|
1438
|
-
"text_key": "password.action.signin"
|
|
1439
|
-
}, {
|
|
1440
|
-
"name": "passkey",
|
|
1441
|
-
"kind": "passkey",
|
|
1442
|
-
"primary": false,
|
|
1443
|
-
"text_key": "password.action.passkey"
|
|
1444
|
-
}],
|
|
1445
|
-
"transitions": {
|
|
1446
|
-
"submit": { "target": "done" },
|
|
1447
|
-
"passkey": { "target": "done" }
|
|
1448
|
-
}
|
|
1449
|
-
},
|
|
1450
|
-
{
|
|
1451
|
-
"name": "register",
|
|
1452
|
-
"fields": ["email"],
|
|
1453
|
-
"actions": [
|
|
1454
|
-
{
|
|
1455
|
-
"name": "submit",
|
|
1456
|
-
"kind": "submit",
|
|
1457
|
-
"primary": true,
|
|
1458
|
-
"text_key": "register.action.password"
|
|
1459
|
-
},
|
|
1460
|
-
{
|
|
1461
|
-
"name": "passkey_register",
|
|
1462
|
-
"kind": "passkey_register",
|
|
1463
|
-
"primary": false,
|
|
1464
|
-
"text_key": "register.action.passkey"
|
|
1465
|
-
},
|
|
1466
|
-
{
|
|
1467
|
-
"name": "sign_in",
|
|
1468
|
-
"kind": "navigate",
|
|
1469
|
-
"primary": false,
|
|
1470
|
-
"text_key": "register.action.sign_in.link"
|
|
1471
|
-
}
|
|
1472
|
-
],
|
|
1473
|
-
"transitions": {
|
|
1474
|
-
"submit": { "target": "register-password" },
|
|
1475
|
-
"passkey_register": { "target": "done" },
|
|
1476
|
-
"user_already_exists": { "target": "password" },
|
|
1477
|
-
"sign_in": {
|
|
1478
|
-
"target": "identifier",
|
|
1479
|
-
"purpose": "login"
|
|
1480
|
-
}
|
|
1481
|
-
}
|
|
1482
|
-
},
|
|
1483
|
-
{
|
|
1484
|
-
"name": "register-password",
|
|
1485
|
-
"fields": ["x-auth-methods#password"],
|
|
1486
|
-
"actions": [{
|
|
1487
|
-
"name": "submit",
|
|
1488
|
-
"kind": "submit",
|
|
1489
|
-
"primary": true,
|
|
1490
|
-
"text_key": "register-password.action.submit"
|
|
1491
|
-
}],
|
|
1492
|
-
"on_success": "create_user",
|
|
1493
|
-
"transitions": {
|
|
1494
|
-
"submit": { "target": "done" },
|
|
1495
|
-
"user_already_exists": { "target": "password" }
|
|
1496
|
-
}
|
|
1497
|
-
},
|
|
1498
|
-
{
|
|
1499
|
-
"name": "done",
|
|
1500
|
-
"complete": "show"
|
|
1501
|
-
}
|
|
1502
|
-
]
|
|
1503
|
-
};
|
|
1504
|
-
var human_user_default = {
|
|
1505
|
-
title: "DefaultHumanUserSchema",
|
|
1506
|
-
$schema: "https://json-schema.org/draft/2020-12/schema",
|
|
1507
|
-
metaSchema: "${SERVER_URL}/user-schema.json",
|
|
1508
|
-
$id: "${USER_SCHEMA_URL}",
|
|
1509
|
-
objectType: "human-user",
|
|
1510
|
-
kind: "user-schema",
|
|
1511
|
-
type: "object",
|
|
1512
|
-
description: "The default editable schema for human users (passkey-first sign-in).",
|
|
1513
|
-
"x-auth-methods": {
|
|
1514
|
-
"passkey": { "enabled": true },
|
|
1515
|
-
"password": { "enabled": true }
|
|
1516
|
-
},
|
|
1517
|
-
required: ["email"],
|
|
1518
|
-
properties: { "email": {
|
|
1519
|
-
"type": "string",
|
|
1520
|
-
"format": "email",
|
|
1521
|
-
"x-unique": "project",
|
|
1522
|
-
"description": "The user's email address."
|
|
1523
|
-
} }
|
|
1524
|
-
};
|
|
1525
|
-
var login_default = {
|
|
1526
|
-
$schema: "../meta/flow-definition.json",
|
|
1527
|
-
name: "default-login",
|
|
1528
|
-
status: "active",
|
|
1529
|
-
user_schema: "${USER_SCHEMA_URL}",
|
|
1530
|
-
purposes: {
|
|
1531
|
-
"login": "passkey-first",
|
|
1532
|
-
"register": "register"
|
|
1533
|
-
},
|
|
1534
|
-
steps: [
|
|
1535
|
-
{
|
|
1536
|
-
"name": "passkey-first",
|
|
1537
|
-
"fields": [],
|
|
1538
|
-
"actions": [
|
|
1539
|
-
{
|
|
1540
|
-
"name": "passkey",
|
|
1541
|
-
"kind": "passkey",
|
|
1542
|
-
"primary": true,
|
|
1543
|
-
"text_key": "passkey-first.action.passkey"
|
|
1544
|
-
},
|
|
1545
|
-
{
|
|
1546
|
-
"name": "email_fallback",
|
|
1547
|
-
"kind": "navigate",
|
|
1548
|
-
"primary": false,
|
|
1549
|
-
"text_key": "passkey-first.action.email_fallback"
|
|
1550
|
-
},
|
|
1551
|
-
{
|
|
1552
|
-
"name": "register",
|
|
1553
|
-
"kind": "navigate",
|
|
1554
|
-
"primary": false,
|
|
1555
|
-
"text_key": "identifier.action.register.link"
|
|
1556
|
-
}
|
|
1557
|
-
],
|
|
1558
|
-
"transitions": {
|
|
1559
|
-
"passkey": { "target": "done" },
|
|
1560
|
-
"email_fallback": { "target": "identifier" },
|
|
1561
|
-
"user_not_found": { "target": "register" },
|
|
1562
|
-
"register": {
|
|
1563
|
-
"target": "register",
|
|
1564
|
-
"purpose": "register"
|
|
1565
|
-
}
|
|
1566
|
-
}
|
|
1567
|
-
},
|
|
1568
|
-
{
|
|
1569
|
-
"name": "identifier",
|
|
1570
|
-
"fields": ["email"],
|
|
1571
|
-
"actions": [
|
|
1572
|
-
{
|
|
1573
|
-
"name": "submit",
|
|
1574
|
-
"kind": "submit",
|
|
1575
|
-
"primary": true,
|
|
1576
|
-
"text_key": "identifier.action.continue"
|
|
1577
|
-
},
|
|
1578
|
-
{
|
|
1579
|
-
"name": "passkey",
|
|
1580
|
-
"kind": "passkey",
|
|
1581
|
-
"primary": false,
|
|
1582
|
-
"text_key": "identifier.action.passkey"
|
|
1583
|
-
},
|
|
1584
|
-
{
|
|
1585
|
-
"name": "register",
|
|
1586
|
-
"kind": "navigate",
|
|
1587
|
-
"primary": false,
|
|
1588
|
-
"text_key": "identifier.action.register.link"
|
|
1589
|
-
}
|
|
1590
|
-
],
|
|
1591
|
-
"transitions": {
|
|
1592
|
-
"submit": { "target": "password" },
|
|
1593
|
-
"passkey": { "target": "done" },
|
|
1594
|
-
"user_not_found": { "target": "register" },
|
|
1595
|
-
"register": {
|
|
1596
|
-
"target": "register",
|
|
1597
|
-
"purpose": "register"
|
|
1598
|
-
}
|
|
1599
|
-
}
|
|
1600
|
-
},
|
|
1601
|
-
{
|
|
1602
|
-
"name": "password",
|
|
1603
|
-
"fields": ["x-auth-methods#password"],
|
|
1604
|
-
"actions": [{
|
|
1605
|
-
"name": "submit",
|
|
1606
|
-
"kind": "submit",
|
|
1607
|
-
"primary": true,
|
|
1608
|
-
"text_key": "password.action.signin"
|
|
1609
|
-
}, {
|
|
1610
|
-
"name": "passkey",
|
|
1611
|
-
"kind": "passkey",
|
|
1612
|
-
"primary": false,
|
|
1613
|
-
"text_key": "password.action.passkey"
|
|
1614
|
-
}],
|
|
1615
|
-
"transitions": {
|
|
1616
|
-
"submit": { "target": "done" },
|
|
1617
|
-
"passkey": { "target": "done" }
|
|
1618
|
-
}
|
|
1619
|
-
},
|
|
1620
|
-
{
|
|
1621
|
-
"name": "register",
|
|
1622
|
-
"fields": ["email"],
|
|
1623
|
-
"actions": [
|
|
1624
|
-
{
|
|
1625
|
-
"name": "passkey_register",
|
|
1626
|
-
"kind": "passkey_register",
|
|
1627
|
-
"primary": true,
|
|
1628
|
-
"text_key": "register.action.passkey"
|
|
1629
|
-
},
|
|
1630
|
-
{
|
|
1631
|
-
"name": "submit",
|
|
1632
|
-
"kind": "submit",
|
|
1633
|
-
"primary": false,
|
|
1634
|
-
"text_key": "register.action.password"
|
|
1635
|
-
},
|
|
1636
|
-
{
|
|
1637
|
-
"name": "sign_in",
|
|
1638
|
-
"kind": "navigate",
|
|
1639
|
-
"primary": false,
|
|
1640
|
-
"text_key": "register.action.sign_in.link"
|
|
1641
|
-
}
|
|
1642
|
-
],
|
|
1643
|
-
"transitions": {
|
|
1644
|
-
"passkey_register": { "target": "done" },
|
|
1645
|
-
"submit": { "target": "register-password" },
|
|
1646
|
-
"user_already_exists": { "target": "password" },
|
|
1647
|
-
"sign_in": {
|
|
1648
|
-
"target": "passkey-first",
|
|
1649
|
-
"purpose": "login"
|
|
1650
|
-
}
|
|
1651
|
-
}
|
|
1652
|
-
},
|
|
1653
|
-
{
|
|
1654
|
-
"name": "register-password",
|
|
1655
|
-
"fields": ["x-auth-methods#password"],
|
|
1656
|
-
"actions": [{
|
|
1657
|
-
"name": "submit",
|
|
1658
|
-
"kind": "submit",
|
|
1659
|
-
"primary": true,
|
|
1660
|
-
"text_key": "register-password.action.submit"
|
|
1661
|
-
}],
|
|
1662
|
-
"on_success": "create_user",
|
|
1663
|
-
"transitions": {
|
|
1664
|
-
"submit": { "target": "done" },
|
|
1665
|
-
"user_already_exists": { "target": "password" }
|
|
1666
|
-
}
|
|
1667
|
-
},
|
|
1668
|
-
{
|
|
1669
|
-
"name": "done",
|
|
1670
|
-
"complete": "show"
|
|
1671
|
-
}
|
|
1672
|
-
]
|
|
1673
|
-
};
|
|
1674
|
-
const DEFAULT_BUILTIN_SCHEMA_BASE = "https://nextgen.com/api/schemas";
|
|
1675
|
-
const DEFAULT_FLOW_SCHEMA_URI = "https://nextgen.com/flow-definition.json";
|
|
1676
|
-
/**
|
|
1677
|
-
* Named schema+flow bundles `zitadel setup` can scaffold (#448: the prompt
|
|
1678
|
-
* fires before any `.zitadel/` file is written; each preset maps to a
|
|
1679
|
-
* pre-defined bundle the CLI copies on first setup). `password-first` is
|
|
1680
|
-
* today's default; `passkey-first` puts a passkey ceremony on the login
|
|
1681
|
-
* entry step with an email→password fallback path.
|
|
1682
|
-
*/
|
|
1683
|
-
const SETUP_PRESETS = ["password-first", "passkey-first"];
|
|
1684
|
-
const PRESET_TEMPLATES = {
|
|
1685
|
-
"password-first": {
|
|
1686
|
-
schema: default_human_user_default,
|
|
1687
|
-
flow: default_login_default
|
|
1688
|
-
},
|
|
1689
|
-
"passkey-first": {
|
|
1690
|
-
schema: human_user_default,
|
|
1691
|
-
flow: login_default
|
|
1692
|
-
}
|
|
1693
|
-
};
|
|
1694
|
-
function presetTemplates(preset) {
|
|
1695
|
-
if (!Object.hasOwn(PRESET_TEMPLATES, preset)) throw new Error(`unknown setup preset ${JSON.stringify(preset)} (known presets: ${SETUP_PRESETS.join(", ")})`);
|
|
1696
|
-
return PRESET_TEMPLATES[preset];
|
|
1697
|
-
}
|
|
1698
|
-
/**
|
|
1699
|
-
* The second setup axis (#448): *who* signs in, orthogonal to the sign-in
|
|
1700
|
-
* preset (*how* they sign in). The sign-in preset owns the flow shape and
|
|
1701
|
-
* auth methods; the use case owns which profile fields the schema collects.
|
|
1702
|
-
* Composing the two keeps us at one field catalog + one flow-per-preset
|
|
1703
|
-
* instead of a bundle per (use case × preset) pair. `minimal` is the
|
|
1704
|
-
* default and never blocks non-interactive runs.
|
|
1705
|
-
*/
|
|
1706
|
-
const SETUP_USE_CASES = [
|
|
1707
|
-
"minimal",
|
|
1708
|
-
"consumer",
|
|
1709
|
-
"business"
|
|
1710
|
-
];
|
|
1711
|
-
/**
|
|
1712
|
-
* Fields each use case collects, in register/display order. `email` is
|
|
1713
|
-
* always first and stays the only required property; the rest are optional
|
|
1714
|
-
* profile attributes gathered on the flow's register step. `givenName`/
|
|
1715
|
-
* `familyName` are the attributes the backend reads for a user's identity
|
|
1716
|
-
* (`internal/domain/user.go`); `companyName` is stored as a plain user
|
|
1717
|
-
* attribute today — there is no org/team model behind it yet.
|
|
1718
|
-
*/
|
|
1719
|
-
const USE_CASE_FIELDS = {
|
|
1720
|
-
minimal: ["email"],
|
|
1721
|
-
consumer: [
|
|
1722
|
-
"email",
|
|
1723
|
-
"givenName",
|
|
1724
|
-
"familyName"
|
|
1725
|
-
],
|
|
1726
|
-
business: [
|
|
1727
|
-
"email",
|
|
1728
|
-
"givenName",
|
|
1729
|
-
"familyName",
|
|
1730
|
-
"companyName"
|
|
1731
|
-
]
|
|
1732
|
-
};
|
|
1733
|
-
/**
|
|
1734
|
-
* JSON-Schema bodies for the optional profile fields the CLI composes in per
|
|
1735
|
-
* use case. The shipped templates are an email-only baseline (shared verbatim
|
|
1736
|
-
* with the Go server fallback), so this catalog owns every field beyond
|
|
1737
|
-
* `email`. Authored in the templates' style — no `x-claim`, since the backend
|
|
1738
|
-
* maps identity by attribute name and the user-property meta-schema defines no
|
|
1739
|
-
* claim keyword. `givenName`/`familyName` are the attributes the backend reads
|
|
1740
|
-
* for a user's identity (`internal/domain/user.go`).
|
|
1741
|
-
*/
|
|
1742
|
-
const EXTRA_FIELD_BODIES = {
|
|
1743
|
-
givenName: {
|
|
1744
|
-
type: "string",
|
|
1745
|
-
maxLength: 50,
|
|
1746
|
-
description: "The user's given (first) name."
|
|
1747
|
-
},
|
|
1748
|
-
familyName: {
|
|
1749
|
-
type: "string",
|
|
1750
|
-
maxLength: 50,
|
|
1751
|
-
description: "The user's family (last) name."
|
|
1752
|
-
},
|
|
1753
|
-
companyName: {
|
|
1754
|
-
type: "string",
|
|
1755
|
-
maxLength: 200,
|
|
1756
|
-
description: "The user's company name."
|
|
1757
|
-
}
|
|
1758
|
-
};
|
|
1759
|
-
function useCaseFields(useCase) {
|
|
1760
|
-
if (!Object.hasOwn(USE_CASE_FIELDS, useCase)) throw new Error(`unknown setup use case ${JSON.stringify(useCase)} (known use cases: ${SETUP_USE_CASES.join(", ")})`);
|
|
1761
|
-
return USE_CASE_FIELDS[useCase];
|
|
1762
|
-
}
|
|
1763
|
-
/**
|
|
1764
|
-
* The body for one use-case field: reuse the template's authored body when it
|
|
1765
|
-
* has one (so composed schemas match the shipped defaults for shared fields),
|
|
1766
|
-
* else the extra catalog, else a generic editable string so composition stays
|
|
1767
|
-
* total for any field a future use case introduces.
|
|
1768
|
-
*/
|
|
1769
|
-
function fieldBody(field, templateProps) {
|
|
1770
|
-
if (Object.hasOwn(templateProps, field)) return { ...templateProps[field] };
|
|
1771
|
-
if (Object.hasOwn(EXTRA_FIELD_BODIES, field)) return { ...EXTRA_FIELD_BODIES[field] };
|
|
1772
|
-
return {
|
|
1773
|
-
type: "string",
|
|
1774
|
-
description: `The user's ${field}.`
|
|
1775
|
-
};
|
|
1776
|
-
}
|
|
1777
|
-
/**
|
|
1778
|
-
* Narrow a rendered schema to the chosen use case: keep the preset-owned
|
|
1779
|
-
* header and `x-auth-methods`, but replace `properties`/`required` with the
|
|
1780
|
-
* use case's field set. `email` is the sole required property.
|
|
1781
|
-
*/
|
|
1782
|
-
function applyUseCaseToSchema(schema, useCase) {
|
|
1783
|
-
const templateProps = schema.properties ?? {};
|
|
1784
|
-
const properties = {};
|
|
1785
|
-
for (const field of useCaseFields(useCase)) properties[field] = fieldBody(field, templateProps);
|
|
1786
|
-
return {
|
|
1787
|
-
...schema,
|
|
1788
|
-
required: ["email"],
|
|
1789
|
-
properties
|
|
1790
|
-
};
|
|
1791
|
-
}
|
|
1792
|
-
/**
|
|
1793
|
-
* Derive the flow's register-step fields from the use case rather than
|
|
1794
|
-
* copying a hard-coded list into every bundle (#448): the register step
|
|
1795
|
-
* collects exactly what the schema defines. Other steps are untouched.
|
|
1796
|
-
*/
|
|
1797
|
-
function applyUseCaseToFlow(flow, useCase) {
|
|
1798
|
-
const fields = [...useCaseFields(useCase)];
|
|
1799
|
-
const steps = flow.steps.map((step) => step.name === "register" ? {
|
|
1800
|
-
...step,
|
|
1801
|
-
fields
|
|
1802
|
-
} : step);
|
|
1803
|
-
return {
|
|
1804
|
-
...flow,
|
|
1805
|
-
steps
|
|
1806
|
-
};
|
|
1807
|
-
}
|
|
1808
|
-
function defaultHumanUserSchemaUrl(builtinSchemaBase = DEFAULT_BUILTIN_SCHEMA_BASE) {
|
|
1809
|
-
return `${trimTrailingSlash(builtinSchemaBase)}/default-human-user.json`;
|
|
1810
|
-
}
|
|
1811
|
-
function getDefaultHumanUserSchema(options = {}) {
|
|
1812
|
-
const builtinSchemaBase = trimTrailingSlash(options.builtinSchemaBase ?? "https://nextgen.com/api/schemas");
|
|
1813
|
-
return applyUseCaseToSchema(renderTemplate(presetTemplates(options.preset ?? "password-first").schema, {
|
|
1814
|
-
SERVER_URL: builtinSchemaBase,
|
|
1815
|
-
USER_SCHEMA_URL: options.userSchemaUrl ?? defaultHumanUserSchemaUrl(builtinSchemaBase)
|
|
1816
|
-
}), options.useCase ?? "minimal");
|
|
1817
|
-
}
|
|
1818
|
-
function getDefaultLoginFlow(options = {}) {
|
|
1819
|
-
const builtinSchemaBase = trimTrailingSlash(options.builtinSchemaBase ?? "https://nextgen.com/api/schemas");
|
|
1820
|
-
return applyUseCaseToFlow(renderTemplate(presetTemplates(options.preset ?? "password-first").flow, {
|
|
1821
|
-
SERVER_URL: builtinSchemaBase,
|
|
1822
|
-
USER_SCHEMA_URL: options.userSchemaUrl ?? defaultHumanUserSchemaUrl(builtinSchemaBase)
|
|
1823
|
-
}), options.useCase ?? "minimal");
|
|
1824
|
-
}
|
|
1825
|
-
function renderTemplate(value, replacements) {
|
|
1826
|
-
if (Array.isArray(value)) return value.map((item) => renderTemplate(item, replacements));
|
|
1827
|
-
if (value !== null && typeof value === "object") return Object.fromEntries(Object.entries(value).map(([key, item]) => [key, renderTemplate(item, replacements)]));
|
|
1828
|
-
if (typeof value === "string") return value.replaceAll(/\$\{([A-Z_]+)\}/g, (match, name) => {
|
|
1829
|
-
return replacements[name] ?? match;
|
|
1830
|
-
});
|
|
1831
|
-
return value;
|
|
1832
|
-
}
|
|
1833
|
-
function trimTrailingSlash(value) {
|
|
1834
|
-
let trimmed = value;
|
|
1835
|
-
while (trimmed.endsWith("/")) trimmed = trimmed.slice(0, -1);
|
|
1836
|
-
return trimmed;
|
|
1837
|
-
}
|
|
1838
|
-
//#endregion
|
|
1839
|
-
//#region src/bootstrap.ts
|
|
1840
|
-
const DEFAULT_PROJECT_NAME = "zitadel-testing";
|
|
1841
|
-
/**
|
|
1842
|
-
* Server-side half of `zitadel setup`, without any file scaffolding:
|
|
1843
|
-
* `POST /projects` is unauthenticated and mints the projectSecret used as the
|
|
1844
|
-
* bearer for everything else; the schema is uploaded without `$id` so the
|
|
1845
|
-
* server assigns an opaque id, which the flow must then reference.
|
|
1846
|
-
*/
|
|
1847
|
-
async function bootstrapProject(options) {
|
|
1848
|
-
const { baseUrl } = options;
|
|
1849
|
-
const project = await createZitadelClient({ baseUrl }).createProject({
|
|
1850
|
-
name: options.projectName ?? DEFAULT_PROJECT_NAME,
|
|
1851
|
-
preview_origins: options.appOrigins ?? [],
|
|
1852
|
-
seed_defaults: false
|
|
1853
|
-
});
|
|
1854
|
-
const projectId = requireString(project.id, "project id");
|
|
1855
|
-
const projectSecret = requireString(project.project_secret, "project secret");
|
|
1856
|
-
const previewSecret = typeof project.preview_secret === "string" ? project.preview_secret : void 0;
|
|
1857
|
-
const client = createZitadelClient({
|
|
1858
|
-
baseUrl,
|
|
1859
|
-
token: projectSecret
|
|
1860
|
-
});
|
|
1861
|
-
const { $id: _templateId, ...schemaBody } = getDefaultHumanUserSchema({
|
|
1862
|
-
preset: options.preset,
|
|
1863
|
-
useCase: options.useCase
|
|
1864
|
-
});
|
|
1865
|
-
const schemaId = requireString((await client.createSchema(schemaBody, { project_id: projectId })).id, "schema id");
|
|
1866
|
-
const flowBody = getDefaultLoginFlow({
|
|
1867
|
-
userSchemaUrl: schemaId,
|
|
1868
|
-
preset: options.preset,
|
|
1869
|
-
useCase: options.useCase
|
|
1870
|
-
});
|
|
1871
|
-
return {
|
|
1872
|
-
projectId,
|
|
1873
|
-
projectSecret,
|
|
1874
|
-
previewSecret,
|
|
1875
|
-
schemaId,
|
|
1876
|
-
flowId: requireString((await client.createFlowDefinition({
|
|
1877
|
-
project_id: projectId,
|
|
1878
|
-
schema_uri: DEFAULT_FLOW_SCHEMA_URI,
|
|
1879
|
-
flow_definition: flowBody
|
|
1880
|
-
})).id, "flow definition id")
|
|
1881
|
-
};
|
|
1882
|
-
}
|
|
1883
|
-
function requireString(value, label) {
|
|
1884
|
-
if (typeof value === "string" && value.length > 0) return value;
|
|
1885
|
-
throw new Error(`Missing ${label} in server response.`);
|
|
1886
|
-
}
|
|
1887
|
-
//#endregion
|
|
1888
|
-
//#region src/cli.ts
|
|
1889
|
-
const DEFAULT_TIMEOUT_MS = 12e4;
|
|
1890
|
-
function resolveCliBin() {
|
|
1891
|
-
const require = (0, node_module.createRequire)(require("url").pathToFileURL(__filename).href);
|
|
1892
|
-
const pkgPath = require.resolve("@zitadel/cli/package.json");
|
|
1893
|
-
const rel = require(pkgPath).bin?.zitadel;
|
|
1894
|
-
if (!rel) throw new Error("@zitadel/cli does not declare a `zitadel` bin entry");
|
|
1895
|
-
return (0, node_path.join)((0, node_path.dirname)(pkgPath), rel);
|
|
1896
|
-
}
|
|
1897
|
-
function runCli(options) {
|
|
1898
|
-
const bin = options.bin ?? resolveCliBin();
|
|
1899
|
-
const timeoutMs = options.timeoutMs ?? DEFAULT_TIMEOUT_MS;
|
|
1900
|
-
return new Promise((resolve, reject) => {
|
|
1901
|
-
const child = (0, node_child_process.spawn)(process.execPath, [bin, ...options.args], {
|
|
1902
|
-
env: {
|
|
1903
|
-
...process.env,
|
|
1904
|
-
...options.env
|
|
1905
|
-
},
|
|
1906
|
-
stdio: [
|
|
1907
|
-
"ignore",
|
|
1908
|
-
"pipe",
|
|
1909
|
-
"pipe"
|
|
1910
|
-
]
|
|
1911
|
-
});
|
|
1912
|
-
let stdout = "";
|
|
1913
|
-
let stderr = "";
|
|
1914
|
-
child.stdout.setEncoding("utf8");
|
|
1915
|
-
child.stdout.on("data", (chunk) => {
|
|
1916
|
-
stdout += chunk;
|
|
1917
|
-
});
|
|
1918
|
-
child.stderr.setEncoding("utf8");
|
|
1919
|
-
child.stderr.on("data", (chunk) => {
|
|
1920
|
-
stderr += chunk;
|
|
1921
|
-
});
|
|
1922
|
-
const timer = setTimeout(() => {
|
|
1923
|
-
child.kill("SIGKILL");
|
|
1924
|
-
reject(/* @__PURE__ */ new Error(`zitadel ${options.args[0] ?? ""} timed out after ${timeoutMs}ms\n${tail(stderr)}`));
|
|
1925
|
-
}, timeoutMs);
|
|
1926
|
-
timer.unref();
|
|
1927
|
-
child.on("error", (error) => {
|
|
1928
|
-
clearTimeout(timer);
|
|
1929
|
-
reject(error);
|
|
1930
|
-
});
|
|
1931
|
-
child.on("close", (code) => {
|
|
1932
|
-
clearTimeout(timer);
|
|
1933
|
-
resolve({
|
|
1934
|
-
exitCode: code ?? -1,
|
|
1935
|
-
stdout,
|
|
1936
|
-
stderr
|
|
1937
|
-
});
|
|
1938
|
-
});
|
|
1939
|
-
});
|
|
1940
|
-
}
|
|
1941
|
-
function tail(text, lines = 20) {
|
|
1942
|
-
return text.split("\n").slice(-lines).join("\n").trim();
|
|
1943
|
-
}
|
|
1944
|
-
//#endregion
|
|
1945
|
-
//#region src/envelope.ts
|
|
1946
|
-
/**
|
|
1947
|
-
* Render an error envelope's remediation fields for humans — the CLI's
|
|
1948
|
-
* `hint`/`next_commands` are the actionable part of a failure (e.g. "Reinstall
|
|
1949
|
-
* @zitadel/cli so npm can install @zitadel/server"), so surface them instead
|
|
1950
|
-
* of a raw stdout dump. Returns undefined when the envelope has no message.
|
|
1951
|
-
*/
|
|
1952
|
-
function describeEnvelopeError(envelope) {
|
|
1953
|
-
if (typeof envelope.message !== "string" || envelope.message.length === 0) return;
|
|
1954
|
-
const lines = [envelope.code ? `${envelope.code}: ${envelope.message}` : envelope.message];
|
|
1955
|
-
if (envelope.hint) lines.push(`hint: ${envelope.hint}`);
|
|
1956
|
-
if (envelope.next_commands && envelope.next_commands.length > 0) lines.push(`next: ${envelope.next_commands.join(" | ")}`);
|
|
1957
|
-
return lines.join("\n");
|
|
1958
|
-
}
|
|
1959
|
-
function parseCliEnvelope(stdout, context) {
|
|
1960
|
-
const start = stdout.indexOf("{");
|
|
1961
|
-
const end = stdout.lastIndexOf("}");
|
|
1962
|
-
if (start === -1 || end <= start) throw new Error(`${context}: expected a JSON envelope on stdout, got:\n${stdout.trim() || "(empty)"}`);
|
|
1963
|
-
let parsed;
|
|
1964
|
-
try {
|
|
1965
|
-
parsed = JSON.parse(stdout.slice(start, end + 1));
|
|
1966
|
-
} catch (error) {
|
|
1967
|
-
throw new Error(`${context}: failed to parse JSON envelope: ${error.message}\n${stdout.trim()}`, { cause: error });
|
|
1968
|
-
}
|
|
1969
|
-
if (typeof parsed !== "object" || parsed === null || typeof parsed.status !== "string") throw new Error(`${context}: stdout JSON is not a CLI envelope:\n${stdout.trim()}`);
|
|
1970
|
-
return parsed;
|
|
1971
|
-
}
|
|
1972
|
-
//#endregion
|
|
1973
|
-
//#region src/ports.ts
|
|
1974
|
-
/**
|
|
1975
|
-
* Ask the OS for a free TCP port. The port is released before returning, so a
|
|
1976
|
-
* racing process could grab it; the CLI's own preflight surfaces that as
|
|
1977
|
-
* E_PORT_IN_USE, which is loud rather than corrupting.
|
|
1978
|
-
*/
|
|
1979
|
-
function getFreePort() {
|
|
1980
|
-
return new Promise((resolve, reject) => {
|
|
1981
|
-
const server = (0, node_net.createServer)();
|
|
1982
|
-
server.unref();
|
|
1983
|
-
server.on("error", reject);
|
|
1984
|
-
server.listen(0, "127.0.0.1", () => {
|
|
1985
|
-
const address = server.address();
|
|
1986
|
-
if (address === null || typeof address === "string") {
|
|
1987
|
-
server.close();
|
|
1988
|
-
reject(/* @__PURE__ */ new Error("could not determine a free port"));
|
|
1989
|
-
return;
|
|
1990
|
-
}
|
|
1991
|
-
const { port } = address;
|
|
1992
|
-
server.close((err) => {
|
|
1993
|
-
if (err) {
|
|
1994
|
-
reject(err);
|
|
1995
|
-
return;
|
|
1996
|
-
}
|
|
1997
|
-
resolve(port);
|
|
1998
|
-
});
|
|
1999
|
-
});
|
|
2000
|
-
});
|
|
2001
|
-
}
|
|
2002
|
-
//#endregion
|
|
2003
|
-
//#region src/lifecycle.ts
|
|
2004
|
-
/**
|
|
2005
|
-
* Boot an ephemeral local server by shelling out to `zitadel start` and parse
|
|
2006
|
-
* its JSON envelope. The CLI owns the subtle parts (port preflight, health
|
|
2007
|
-
* wait, process-group stop), so this module stays a thin adapter; swapping it
|
|
2008
|
-
* for direct library calls later must not change the shape returned here.
|
|
2009
|
-
*/
|
|
2010
|
-
async function bootLocalServer(options = {}) {
|
|
2011
|
-
const ownsDir = options.dir === void 0;
|
|
2012
|
-
const dir = options.dir ?? await (0, node_fs_promises.mkdtemp)((0, node_path.join)((0, node_os.tmpdir)(), "zitadel-testing-"));
|
|
2013
|
-
const port = options.port ?? await getFreePort();
|
|
2014
|
-
const env = {};
|
|
2015
|
-
if (options.serverBinary) env.ZITADEL_SERVER_BINARY = options.serverBinary;
|
|
2016
|
-
const result = await runCli({
|
|
2017
|
-
args: [
|
|
2018
|
-
"start",
|
|
2019
|
-
"--port",
|
|
2020
|
-
String(port),
|
|
2021
|
-
"--non-interactive",
|
|
2022
|
-
"--json",
|
|
2023
|
-
"-c",
|
|
2024
|
-
dir
|
|
2025
|
-
],
|
|
2026
|
-
bin: options.cliBin,
|
|
2027
|
-
env,
|
|
2028
|
-
timeoutMs: options.timeoutMs
|
|
2029
|
-
});
|
|
2030
|
-
if (result.exitCode !== 0) throw new Error(`zitadel start exited with code ${result.exitCode}.\n${failureDetail(result)}\nstate dir kept for inspection: ${dir}`);
|
|
2031
|
-
const stopViaCli = async () => {
|
|
2032
|
-
const stopResult = await runCli({
|
|
2033
|
-
args: [
|
|
2034
|
-
"stop",
|
|
2035
|
-
"--non-interactive",
|
|
2036
|
-
"--json",
|
|
2037
|
-
"-c",
|
|
2038
|
-
dir
|
|
2039
|
-
],
|
|
2040
|
-
bin: options.cliBin,
|
|
2041
|
-
env,
|
|
2042
|
-
timeoutMs: options.timeoutMs
|
|
2043
|
-
});
|
|
2044
|
-
if (stopResult.exitCode !== 0) throw new Error(`zitadel stop exited with code ${stopResult.exitCode}.\n${failureDetail(stopResult)}\nstate dir kept for inspection: ${dir}`);
|
|
2045
|
-
};
|
|
2046
|
-
let envelope;
|
|
2047
|
-
try {
|
|
2048
|
-
envelope = parseCliEnvelope(result.stdout, "zitadel start");
|
|
2049
|
-
if (envelope.status !== "ok") throw new Error(`zitadel start reported status "${envelope.status}":\n${describeEnvelopeError(envelope) ?? tail(result.stdout)}`);
|
|
2050
|
-
} catch (error) {
|
|
2051
|
-
const startError = new Error(`zitadel start produced unusable output.\nreason: ${error instanceof Error ? error.message : String(error)}\nstdout: ${tail(result.stdout) || "(empty)"}\nstderr: ${tail(result.stderr) || "(empty)"}\nstate dir kept for inspection: ${dir}`, { cause: error });
|
|
2052
|
-
try {
|
|
2053
|
-
await stopViaCli();
|
|
2054
|
-
} catch (stopError) {
|
|
2055
|
-
throw new AggregateError([startError, stopError], `${startError.message}\nStopping the possibly-running instance also failed: ${stopError instanceof Error ? stopError.message : String(stopError)}`);
|
|
2056
|
-
}
|
|
2057
|
-
throw startError;
|
|
2058
|
-
}
|
|
2059
|
-
const { runtime, urls } = envelope.data;
|
|
2060
|
-
const runStop = async () => {
|
|
2061
|
-
await stopViaCli();
|
|
2062
|
-
if (ownsDir && !options.keep) await (0, node_fs_promises.rm)(dir, {
|
|
2063
|
-
recursive: true,
|
|
2064
|
-
force: true
|
|
2065
|
-
});
|
|
2066
|
-
};
|
|
2067
|
-
let stopPromise;
|
|
2068
|
-
const stop = () => {
|
|
2069
|
-
stopPromise ??= runStop().catch((error) => {
|
|
2070
|
-
stopPromise = void 0;
|
|
2071
|
-
throw error;
|
|
2072
|
-
});
|
|
2073
|
-
return stopPromise;
|
|
2074
|
-
};
|
|
2075
|
-
return {
|
|
2076
|
-
baseUrl: urls.api,
|
|
2077
|
-
runtime: {
|
|
2078
|
-
port: runtime.port,
|
|
2079
|
-
pid: runtime.pid,
|
|
2080
|
-
dir,
|
|
2081
|
-
logPath: runtime.log_path
|
|
2082
|
-
},
|
|
2083
|
-
stop
|
|
2084
|
-
};
|
|
2085
|
-
}
|
|
2086
|
-
/**
|
|
2087
|
-
* A failed CLI run usually still prints an error envelope; its
|
|
2088
|
-
* message/hint/next_commands beat raw output tails (e.g. a fresh install
|
|
2089
|
-
* missing @zitadel/server gets "Reinstall @zitadel/cli" instead of a stack).
|
|
2090
|
-
*/
|
|
2091
|
-
function failureDetail(result) {
|
|
2092
|
-
try {
|
|
2093
|
-
const described = describeEnvelopeError(parseCliEnvelope(result.stdout, "zitadel"));
|
|
2094
|
-
if (described) return described;
|
|
2095
|
-
} catch {}
|
|
2096
|
-
return `stdout: ${tail(result.stdout) || "(empty)"}\nstderr: ${tail(result.stderr) || "(empty)"}`;
|
|
2097
|
-
}
|
|
2098
|
-
//#endregion
|
|
2099
|
-
//#region src/seed.ts
|
|
2100
|
-
/**
|
|
2101
|
-
* A unique unused email + password. Nothing is created on the instance —
|
|
2102
|
-
* this is the input for registration-flow specs, which must prove the flow
|
|
2103
|
-
* creates the user.
|
|
2104
|
-
*/
|
|
2105
|
-
function identity() {
|
|
2106
|
-
return {
|
|
2107
|
-
email: `e2e-${(0, node_crypto.randomUUID)().slice(0, 8)}@example.com`,
|
|
2108
|
-
password: `Pw!${(0, node_crypto.randomUUID)()}`
|
|
2109
|
-
};
|
|
2110
|
-
}
|
|
2111
|
-
/**
|
|
2112
|
-
* Create a user that can immediately complete the password login flow:
|
|
2113
|
-
* `POST /users` (the body carries `schema: <schema id>` and the schema-defined
|
|
2114
|
-
* content under `attributes`) followed by `PUT /users/{id}/password` with
|
|
2115
|
-
* `is_change_required: false`.
|
|
2116
|
-
*
|
|
2117
|
-
* Defaults mint a unique email per call (email is x-unique per project), which
|
|
2118
|
-
* is what makes per-test seeding parallel-safe on a shared instance.
|
|
2119
|
-
*/
|
|
2120
|
-
async function seedUser(client, context, input = {}) {
|
|
2121
|
-
const fresh = identity();
|
|
2122
|
-
const email = input.email ?? fresh.email;
|
|
2123
|
-
const password = input.password ?? fresh.password;
|
|
2124
|
-
const id = requireString((await client.createUser({
|
|
2125
|
-
schema: context.schemaId,
|
|
2126
|
-
attributes: {
|
|
2127
|
-
...input.attributes,
|
|
2128
|
-
email
|
|
2129
|
-
}
|
|
2130
|
-
}, { project_id: context.projectId })).id, "user id");
|
|
2131
|
-
await client.setUserPassword(id, {
|
|
2132
|
-
password,
|
|
2133
|
-
is_change_required: false
|
|
2134
|
-
});
|
|
2135
|
-
return {
|
|
2136
|
-
id,
|
|
2137
|
-
email,
|
|
2138
|
-
password
|
|
2139
|
-
};
|
|
2140
|
-
}
|
|
2141
|
-
/**
|
|
2142
|
-
* Seed `count` users sequentially. The template makes fixture data
|
|
2143
|
-
* deterministic per index (stable emails/names keep screenshot diffs about
|
|
2144
|
-
* code, not reshuffled data — the `console:dev-real` pattern); untemplated
|
|
2145
|
-
* fields fall back to the unique defaults. Name-like attributes need a
|
|
2146
|
-
* schema that declares them (`useCase: "consumer"` or wider).
|
|
2147
|
-
*/
|
|
2148
|
-
async function seedUsers(client, context, count, template = {}) {
|
|
2149
|
-
const users = [];
|
|
2150
|
-
for (let index = 0; index < count; index += 1) users.push(await seedUser(client, context, {
|
|
2151
|
-
email: template.email?.(index),
|
|
2152
|
-
password: template.password?.(index),
|
|
2153
|
-
attributes: template.attributes?.(index)
|
|
2154
|
-
}));
|
|
2155
|
-
return users;
|
|
2156
|
-
}
|
|
2157
|
-
//#endregion
|
|
2158
|
-
//#region src/session.ts
|
|
2159
|
-
/** Mirrors the server's session cookie (internal/api/session.go). */
|
|
2160
|
-
const SESSION_COOKIE_NAME = "__nextgen_session";
|
|
2161
|
-
const MAX_FLOW_STEPS = 6;
|
|
2162
|
-
/**
|
|
2163
|
-
* Drive the real login flow headlessly for a seeded password user and
|
|
2164
|
-
* exchange the terminal handoff for a session: exactly what `<zitadel-login>`
|
|
2165
|
-
* does, minus the rendering. Supports flows whose steps only ask for the
|
|
2166
|
-
* user's email and password (the shipped `password-first` presets); any step
|
|
2167
|
-
* demanding more — a challenge, an unknown field — fails loudly by design.
|
|
2168
|
-
*
|
|
2169
|
-
* Flow calls use raw fetch instead of the typed client because the flow is
|
|
2170
|
-
* stateless through the sealed `_zflow` cookie (internal/api/flow.go): every
|
|
2171
|
-
* response re-seals the flow state into Set-Cookie, and submits are rejected
|
|
2172
|
-
* without it. Browsers round-trip it implicitly; here a one-cookie jar does.
|
|
2173
|
-
*/
|
|
2174
|
-
async function mintSession(client, handle, context, user, options = {}) {
|
|
2175
|
-
const values = {
|
|
2176
|
-
email: user.email,
|
|
2177
|
-
password: user.password
|
|
2178
|
-
};
|
|
2179
|
-
const jar = new FlowCookieJar();
|
|
2180
|
-
const origin = options.origin;
|
|
2181
|
-
let response = await flowFetch(handle, jar, origin, "/flow", {
|
|
2182
|
-
project_id: context.projectId,
|
|
2183
|
-
purpose: "login",
|
|
2184
|
-
...options.flowDefinitionName ? { flow_definition_name: options.flowDefinitionName } : {}
|
|
2185
|
-
});
|
|
2186
|
-
for (let hop = 0; hop < MAX_FLOW_STEPS; hop += 1) {
|
|
2187
|
-
if (response.handoff_token) {
|
|
2188
|
-
const exchanged = await client.exchangeHandoff({ handoff_token: response.handoff_token }, { project_id: context.projectId });
|
|
2189
|
-
return {
|
|
2190
|
-
user,
|
|
2191
|
-
sessionToken: exchanged.session_token,
|
|
2192
|
-
expiresAt: exchanged.session.expires_at,
|
|
2193
|
-
cookie: {
|
|
2194
|
-
name: SESSION_COOKIE_NAME,
|
|
2195
|
-
value: exchanged.session_token,
|
|
2196
|
-
httpOnly: true,
|
|
2197
|
-
secure: true,
|
|
2198
|
-
sameSite: "Lax",
|
|
2199
|
-
path: "/"
|
|
2200
|
-
}
|
|
2201
|
-
};
|
|
2202
|
-
}
|
|
2203
|
-
response = await flowFetch(handle, jar, origin, `/flow/${encodeURIComponent(response.id)}/submit`, {
|
|
2204
|
-
session_token: response.session_token,
|
|
2205
|
-
action: "submit",
|
|
2206
|
-
fields: collectFields(response, values)
|
|
2207
|
-
});
|
|
2208
|
-
}
|
|
2209
|
-
throw new Error(`seed.session: flow did not complete within ${MAX_FLOW_STEPS} steps (last step: ${describeStep(response)}).`);
|
|
2210
|
-
}
|
|
2211
|
-
/** One-cookie jar for the sealed `_zflow` flow-state cookie. */
|
|
2212
|
-
var FlowCookieJar = class {
|
|
2213
|
-
cookie;
|
|
2214
|
-
absorb(response) {
|
|
2215
|
-
for (const raw of response.headers.getSetCookie()) {
|
|
2216
|
-
const [pair] = raw.split(";", 1);
|
|
2217
|
-
if (pair?.startsWith("_zflow=")) this.cookie = pair;
|
|
2218
|
-
}
|
|
2219
|
-
}
|
|
2220
|
-
header() {
|
|
2221
|
-
return this.cookie ? { cookie: this.cookie } : {};
|
|
2222
|
-
}
|
|
2223
|
-
};
|
|
2224
|
-
async function flowFetch(handle, jar, origin, path, body) {
|
|
2225
|
-
const response = await fetch(`${handle.baseUrl}${path}`, {
|
|
2226
|
-
method: "POST",
|
|
2227
|
-
headers: {
|
|
2228
|
-
"content-type": "application/json",
|
|
2229
|
-
authorization: `Bearer ${handle.projectSecret}`,
|
|
2230
|
-
...origin ? { origin } : {},
|
|
2231
|
-
...jar.header()
|
|
2232
|
-
},
|
|
2233
|
-
body: JSON.stringify(body)
|
|
2234
|
-
});
|
|
2235
|
-
jar.absorb(response);
|
|
2236
|
-
const parsed = await response.json().catch(() => void 0);
|
|
2237
|
-
if (!response.ok || !parsed) {
|
|
2238
|
-
const detail = parsed && typeof parsed === "object" ? ` — ${JSON.stringify(parsed)}` : "";
|
|
2239
|
-
const hint = !origin && /origin/i.test(detail) ? "\nNo Origin header was sent: pass `origin` to seedSession() (the Playwright fixtures pass the suite's baseURL) or `appOrigins` to startLocalZitadel()." : "";
|
|
2240
|
-
throw new Error(`seed.session: POST ${path} returned ${response.status}${detail}${hint}`);
|
|
2241
|
-
}
|
|
2242
|
-
return parsed;
|
|
2243
|
-
}
|
|
2244
|
-
/**
|
|
2245
|
-
* Fill exactly the fields the current step declares — the orchestrator's
|
|
2246
|
-
* convention — from the known email/password values. An unknown required
|
|
2247
|
-
* field means this flow needs more than a password login can provide.
|
|
2248
|
-
*/
|
|
2249
|
-
function collectFields(response, values) {
|
|
2250
|
-
const fields = {};
|
|
2251
|
-
for (const field of response.step.fields ?? []) {
|
|
2252
|
-
const value = values[fieldKey(field)];
|
|
2253
|
-
if (value === void 0) throw new Error(`seed.session supports password flows only; step ${describeStep(response)} declares field "${field.name}", which the kit cannot fill. Log in through the UI for flows with additional factors.`);
|
|
2254
|
-
fields[field.name] = value;
|
|
2255
|
-
}
|
|
2256
|
-
return fields;
|
|
2257
|
-
}
|
|
2258
|
-
/**
|
|
2259
|
-
* Steps name credential fields with schema pointers (e.g.
|
|
2260
|
-
* `x-auth-methods#password`); match on the trailing segment so the value map
|
|
2261
|
-
* stays the plain `{ email, password }` a caller thinks in.
|
|
2262
|
-
*/
|
|
2263
|
-
function fieldKey(field) {
|
|
2264
|
-
const name = field.name;
|
|
2265
|
-
return (name.split(/[#/.]/).at(-1) ?? name).toLowerCase();
|
|
2266
|
-
}
|
|
2267
|
-
function describeStep(response) {
|
|
2268
|
-
const name = response.step.name ?? "(unnamed)";
|
|
2269
|
-
const declared = (response.step.fields ?? []).map((field) => field.name).join(", ");
|
|
2270
|
-
return `"${name}"${declared ? ` [fields: ${declared}]` : ""}`;
|
|
2271
|
-
}
|
|
2272
|
-
//#endregion
|
|
2273
|
-
//#region src/index.ts
|
|
2274
|
-
/**
|
|
2275
|
-
* Attach to an already-bootstrapped instance/project. Lifecycle-free on
|
|
2276
|
-
* purpose: this is the entry point for Playwright workers (via the handshake
|
|
2277
|
-
* file) and, later, for seeding remote instances.
|
|
2278
|
-
*/
|
|
2279
|
-
function connectZitadel(handle) {
|
|
2280
|
-
const api = createZitadelClient({
|
|
2281
|
-
baseUrl: handle.baseUrl,
|
|
2282
|
-
token: handle.projectSecret
|
|
2283
|
-
});
|
|
2284
|
-
const context = {
|
|
2285
|
-
projectId: handle.projectId,
|
|
2286
|
-
schemaId: handle.schemaId
|
|
2287
|
-
};
|
|
2288
|
-
return {
|
|
2289
|
-
handle,
|
|
2290
|
-
api,
|
|
2291
|
-
appEnv: require_handshake.applyAppEnvTemplate(require_handshake.nextAppEnv, handle),
|
|
2292
|
-
seedUser: (input) => seedUser(api, context, input),
|
|
2293
|
-
seedUsers: (count, template) => seedUsers(api, context, count, template),
|
|
2294
|
-
identity,
|
|
2295
|
-
seedSession: async (input = {}) => {
|
|
2296
|
-
const { user: existing, flowDefinitionName, origin, ...userInput } = input;
|
|
2297
|
-
return mintSession(api, handle, context, existing ?? await seedUser(api, context, userInput), {
|
|
2298
|
-
flowDefinitionName,
|
|
2299
|
-
origin: origin ?? handle.appOrigin
|
|
2300
|
-
});
|
|
2301
|
-
}
|
|
2302
|
-
};
|
|
2303
|
-
}
|
|
2304
|
-
/**
|
|
2305
|
-
* Boot an ephemeral local instance (binary runtime + SQLite by default, no
|
|
2306
|
-
* Docker) and bootstrap a project + default schema + login flow on it. The
|
|
2307
|
-
* result can seed loginable password users immediately.
|
|
2308
|
-
*/
|
|
2309
|
-
async function startLocalZitadel(options = {}) {
|
|
2310
|
-
const server = await bootLocalServer(options);
|
|
2311
|
-
let bootstrapped;
|
|
2312
|
-
try {
|
|
2313
|
-
bootstrapped = await bootstrapProject({
|
|
2314
|
-
baseUrl: server.baseUrl,
|
|
2315
|
-
projectName: options.projectName,
|
|
2316
|
-
appOrigins: options.appOrigins,
|
|
2317
|
-
preset: options.preset,
|
|
2318
|
-
useCase: options.useCase
|
|
2319
|
-
});
|
|
2320
|
-
} catch (error) {
|
|
2321
|
-
try {
|
|
2322
|
-
await server.stop();
|
|
2323
|
-
} catch (stopError) {
|
|
2324
|
-
throw new AggregateError([error, stopError], "bootstrap failed, and stopping the booted instance also failed");
|
|
2325
|
-
}
|
|
2326
|
-
throw error;
|
|
2327
|
-
}
|
|
2328
|
-
return {
|
|
2329
|
-
...connectZitadel({
|
|
2330
|
-
baseUrl: server.baseUrl,
|
|
2331
|
-
projectId: bootstrapped.projectId,
|
|
2332
|
-
projectSecret: bootstrapped.projectSecret,
|
|
2333
|
-
schemaId: bootstrapped.schemaId,
|
|
2334
|
-
previewSecret: bootstrapped.previewSecret,
|
|
2335
|
-
appOrigin: options.appOrigins?.[0]
|
|
2336
|
-
}),
|
|
2337
|
-
runtime: server.runtime,
|
|
2338
|
-
stop: server.stop,
|
|
2339
|
-
[Symbol.asyncDispose]: server.stop
|
|
2340
|
-
};
|
|
2341
|
-
}
|
|
2342
|
-
//#endregion
|
|
2343
|
-
Object.defineProperty(exports, "SESSION_COOKIE_NAME", {
|
|
2344
|
-
enumerable: true,
|
|
2345
|
-
get: function() {
|
|
2346
|
-
return SESSION_COOKIE_NAME;
|
|
2347
|
-
}
|
|
2348
|
-
});
|
|
2349
|
-
Object.defineProperty(exports, "bootLocalServer", {
|
|
2350
|
-
enumerable: true,
|
|
2351
|
-
get: function() {
|
|
2352
|
-
return bootLocalServer;
|
|
2353
|
-
}
|
|
2354
|
-
});
|
|
2355
|
-
Object.defineProperty(exports, "bootstrapProject", {
|
|
2356
|
-
enumerable: true,
|
|
2357
|
-
get: function() {
|
|
2358
|
-
return bootstrapProject;
|
|
2359
|
-
}
|
|
2360
|
-
});
|
|
2361
|
-
Object.defineProperty(exports, "connectZitadel", {
|
|
2362
|
-
enumerable: true,
|
|
2363
|
-
get: function() {
|
|
2364
|
-
return connectZitadel;
|
|
2365
|
-
}
|
|
2366
|
-
});
|
|
2367
|
-
Object.defineProperty(exports, "startLocalZitadel", {
|
|
2368
|
-
enumerable: true,
|
|
2369
|
-
get: function() {
|
|
2370
|
-
return startLocalZitadel;
|
|
2371
|
-
}
|
|
2372
|
-
});
|
|
2373
|
-
|
|
2374
|
-
//# sourceMappingURL=src-I0KAh1zU.cjs.map
|