@runlot/api 0.1.0-rc.20 → 0.1.0-rc.201

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/dist/index.js CHANGED
@@ -1,5 +1,65 @@
1
1
  export const API_VERSION = "v1";
2
- /** 서버가 돌려준 오류 봉투를 그대로 들고 있는 예외. */
2
+ /** The shared query for browsing. Empty values are not carried — the server reads "empty means default". */
3
+ /** base64url of the UTF-8 JSON, no padding — the `draft` parameter's encoding. */
4
+ export function base64urlJson(v) {
5
+ const bytes = new TextEncoder().encode(JSON.stringify(v));
6
+ let bin = "";
7
+ for (const b of bytes)
8
+ bin += String.fromCharCode(b);
9
+ return btoa(bin).replace(/\+/g, "-").replace(/\//g, "_").replace(/=+$/, "");
10
+ }
11
+ function gitQuery(ref, path) {
12
+ const q = new URLSearchParams();
13
+ if (ref !== "")
14
+ q.set("ref", ref);
15
+ if (path !== "")
16
+ q.set("path", path);
17
+ return q.size > 0 ? `?${q.toString()}` : "";
18
+ }
19
+ function obsProfileQS(q = {}) {
20
+ const p = new URLSearchParams();
21
+ for (const [k, v] of Object.entries(q)) {
22
+ if (v !== undefined && v !== "")
23
+ p.set(k, String(v));
24
+ }
25
+ const s = p.toString();
26
+ return s ? `?${s}` : "";
27
+ }
28
+ export const API_SCOPES = [
29
+ "project:read",
30
+ "deploy",
31
+ "db:read",
32
+ "db:write",
33
+ "repo:read",
34
+ "repo:write",
35
+ "org:admin",
36
+ ];
37
+ export const BUILTIN_AUTH_PROVIDERS = ["github", "google"];
38
+ export const RESERVED_AUTH_PROVIDER_IDS = ["github", "google", "runlot"];
39
+ /** The id pattern for an OIDC provider (`^[a-z][a-z0-9-]{1,30}$`). */
40
+ export const AUTH_PROVIDER_ID = /^[a-z][a-z0-9-]{1,30}$/;
41
+ export const AUTH_RUNLOT_METHODS = ["password", "google", "github", "passkey"];
42
+ /**
43
+ * A purchase or renewal answers with the domain once it is paid and done, or with
44
+ * the charge while payment is still on its way (a checkout to pay in, or a charge
45
+ * settling). The charge is the one with a `chargeId`.
46
+ */
47
+ export function isDomainCharge(v) {
48
+ return "chargeId" in v;
49
+ }
50
+ /**
51
+ * A status the edge in front of cp-public can produce on its own: 502–504, and
52
+ * Cloudflare's 520–527 (524 is its 100 s origin timeout). With no JSON body these
53
+ * are the edge's words, not the server's, and are raised as `edge_<status>`.
54
+ */
55
+ export function isEdgeStatus(status) {
56
+ return (status >= 502 && status <= 504) || (status >= 520 && status <= 527);
57
+ }
58
+ /** True for the `edge_<status>` ApiError `isEdgeStatus` produces. */
59
+ export function isEdgeError(err) {
60
+ return err instanceof ApiError && err.code.startsWith("edge_");
61
+ }
62
+ /** The exception that carries the server's error envelope unchanged. */
3
63
  export class ApiError extends Error {
4
64
  status;
5
65
  code;
@@ -14,14 +74,25 @@ export class ApiError extends Error {
14
74
  }
15
75
  }
16
76
  /**
17
- * cp-public 클라이언트.
77
+ * The cp-public client.
18
78
  *
19
- * CLI와 대시보드가 같은 것을 쓴다. 각자 fetch를 부르면 오류 해석이 조금씩
20
- * 달라지고, 그 차이는 장애 중에 드러난다.
79
+ * The CLI and the dashboard use the same one. If each called fetch itself, their
80
+ * error handling would drift a little, and that difference shows up during an
81
+ * incident.
21
82
  */
22
83
  function dbPath(org, name) {
23
84
  return `/v1/orgs/${encodeURIComponent(org)}/projects/${encodeURIComponent(name)}/database`;
24
85
  }
86
+ function previewQuery(opts) {
87
+ const q = new URLSearchParams({ preview: opts.preview });
88
+ // Empty values are not carried: the server reads "absent" as its default, and
89
+ // `?db=` would be neither absent nor a member of the enum.
90
+ if (opts.db)
91
+ q.set("db", opts.db);
92
+ if (opts.from)
93
+ q.set("from", opts.from);
94
+ return q.toString();
95
+ }
25
96
  export class Client {
26
97
  opts;
27
98
  constructor(opts) {
@@ -33,7 +104,25 @@ export class Client {
33
104
  h["Authorization"] = `Bearer ${this.opts.token}`;
34
105
  return h;
35
106
  }
36
- async request(method, path, init) {
107
+ /** Runs one attempt again under `opts.retry`, for a safe method only. */
108
+ async retrying(method, once) {
109
+ const r = this.opts.retry;
110
+ const safe = method === "GET" || method === "HEAD";
111
+ for (let attempt = 0;; attempt += 1) {
112
+ try {
113
+ return await once();
114
+ }
115
+ catch (err) {
116
+ if (r === undefined || !safe || attempt >= r.attempts || !(isEdgeError(err) || r.transport(err)))
117
+ throw err;
118
+ await new Promise((done) => setTimeout(done, r.backoffMs * 2 ** attempt));
119
+ }
120
+ }
121
+ }
122
+ request(method, path, init) {
123
+ return this.retrying(method, () => this.requestOnce(method, path, init));
124
+ }
125
+ async requestOnce(method, path, init) {
37
126
  const res = await fetch(new URL(path, this.opts.baseUrl), {
38
127
  ...init,
39
128
  method,
@@ -45,8 +134,21 @@ export class Client {
45
134
  body = (await res.json());
46
135
  }
47
136
  catch {
48
- // 오류 응답이 JSON이 아닌 경우(프록시가 만든 502 등)도 같은 예외로
49
- // 올린다 — 호출부가 두 가지 실패 모양을 다루지 않게.
137
+ // An error response that is not JSON (a 502 made by a proxy, for instance)
138
+ // is raised as the same exception — so the caller does not have to handle
139
+ // two shapes of failure.
140
+ }
141
+ if (body === undefined && isEdgeStatus(res.status)) {
142
+ // The edge replaced the 5xx body with its own HTML. The code and reason
143
+ // the server wrote are not here — so say that, rather than "unknown". On
144
+ // 2026-09-10 a registrar rejection came out this way as
145
+ // "unknown: POST … → 502".
146
+ body = {
147
+ error: {
148
+ code: "edge_" + res.status,
149
+ message: "The server returned an error (" + res.status + "), and the error details could not be read. Try again shortly.",
150
+ },
151
+ };
50
152
  }
51
153
  throw new ApiError(res.status, body, `${method} ${path} → ${res.status}`);
52
154
  }
@@ -54,6 +156,24 @@ export class Client {
54
156
  return undefined;
55
157
  return (await res.json());
56
158
  }
159
+ /** A body that is not JSON (the raw mail). Error handling is the same as request. */
160
+ text(method, path) {
161
+ return this.retrying(method, () => this.textOnce(method, path));
162
+ }
163
+ async textOnce(method, path) {
164
+ const res = await fetch(new URL(path, this.opts.baseUrl), { method, headers: this.headers() });
165
+ if (!res.ok) {
166
+ let body;
167
+ try {
168
+ body = (await res.json());
169
+ }
170
+ catch {
171
+ // The same reason as in request
172
+ }
173
+ throw new ApiError(res.status, body, `${method} ${path} → ${res.status}`);
174
+ }
175
+ return await res.text();
176
+ }
57
177
  json(method, path, body) {
58
178
  if (body === undefined)
59
179
  return this.request(method, path);
@@ -65,38 +185,205 @@ export class Client {
65
185
  devLogin(subject) {
66
186
  return this.json("POST", "/v1/auth/dev/login", { subject });
67
187
  }
68
- /** 켜진 로그인 방식. 로그인 화면이 버튼을 그리는 데 쓴다. */
69
- authProviders() {
70
- return this.json("GET", "/v1/auth/providers");
188
+ /**
189
+ * Takes the sign-up and sends the confirmation mail. Neither a session nor a
190
+ * password is created here — the password is chosen in `verifyEmail` by
191
+ * whoever opens the mailbox.
192
+ */
193
+ passwordSignUp(email, name) {
194
+ return this.json("POST", "/v1/auth/password/sign-up", {
195
+ email,
196
+ ...(name === undefined ? {} : { name }),
197
+ });
198
+ }
199
+ passwordSignIn(email, password) {
200
+ return this.json("POST", "/v1/auth/password/sign-in", { email, password });
201
+ }
202
+ /** The same accepted response comes back whether or not the email exists. */
203
+ passwordForgot(email) {
204
+ return this.json("POST", "/v1/auth/password/forgot", { email });
205
+ }
206
+ passwordReset(token, password) {
207
+ return this.json("POST", "/v1/auth/password/reset", { token, password });
208
+ }
209
+ /** Uses the confirmation link and sets the account's first password. */
210
+ verifyEmail(token, password) {
211
+ return this.json("POST", "/v1/auth/email/verify", { token, password });
212
+ }
213
+ /**
214
+ * Finishes a sign-in that came back `{mfa:"totp"}`.
215
+ *
216
+ * Callable without a token: `pending` is the credential, and it is not a
217
+ * session — no other endpoint accepts it.
218
+ */
219
+ completeTotpLogin(pending, factor) {
220
+ return this.json("POST", "/v1/auth/totp", { pending, ...factor });
221
+ }
222
+ /** This account's two-factor state, including which orgs require it. */
223
+ getTotp() {
224
+ return this.json("GET", "/v1/me/totp");
225
+ }
226
+ /**
227
+ * Draws a secret to scan. It does **not** turn the factor on — `confirmTotp`
228
+ * does, after the app has proved it can produce a code.
229
+ */
230
+ enrollTotp() {
231
+ return this.json("POST", "/v1/me/totp/enroll");
232
+ }
233
+ /** Turns the factor on and hands back the ten recovery codes. They are shown once. */
234
+ confirmTotp(code) {
235
+ return this.json("POST", "/v1/me/totp/confirm", { code });
236
+ }
237
+ /** Turns it off. A code or a recovery code is required — the session alone is not. */
238
+ disableTotp(factor) {
239
+ return this.json("DELETE", "/v1/me/totp", factor);
71
240
  }
72
241
  /**
73
- * GitHub OAuth 시작 URL. 브라우저가 따라가는 302 라 fetch 로 부르지 않고
74
- * `window.location` 에 넣는다. `redirect` 는 서버 허용 목록에 있어야 한다.
242
+ * The GitHub OAuth start URL. It is a 302 the browser follows, so it goes into
243
+ * `window.location` rather than being called with fetch. `redirect` has to be
244
+ * on the server's allow-list.
75
245
  */
76
246
  githubStartUrl(redirect) {
77
247
  const u = new URL("/v1/auth/github/start", this.opts.baseUrl);
78
248
  u.searchParams.set("redirect", redirect);
79
249
  return u.toString();
80
250
  }
251
+ /** The Google OAuth start URL. Uses the same dashboard callback shape as GitHub. */
252
+ googleStartUrl(redirect) {
253
+ const u = new URL("/v1/auth/google/start", this.opts.baseUrl);
254
+ u.searchParams.set("redirect", redirect);
255
+ return u.toString();
256
+ }
257
+ /**
258
+ * The generic OIDC start URL (docs/onprem-delivery.md §7.7). Same 302-and-fragment
259
+ * shape as the other two; which provider is behind it is the installation's choice.
260
+ */
261
+ oidcStartUrl(redirect) {
262
+ const u = new URL("/v1/auth/oidc/start", this.opts.baseUrl);
263
+ u.searchParams.set("redirect", redirect);
264
+ return u.toString();
265
+ }
266
+ /**
267
+ * Does this deployment federate an identity provider?
268
+ *
269
+ * **There is no endpoint that answers "which logins are on"** — one existed and was
270
+ * deleted, because its only reader was the login screen and it put a round trip in
271
+ * front of every login button (cp/internal/public/public.go). This is not that
272
+ * endpoint coming back: cp-public **does not register** the two OIDC routes when no
273
+ * issuer is configured, so the mux's own 404 is the answer, and the probe is a HEAD
274
+ * that no handler runs.
275
+ *
276
+ * Any other status means the route is there — a 400 (this probe carries no
277
+ * `redirect`) or a 502 (the provider's discovery document could not be read) both say
278
+ * the handler exists, and a button that leads to a readable error beats no button.
279
+ * A network failure answers false: on SaaS, where the answer is false anyway, a dead
280
+ * API address must not draw a login that cannot work.
281
+ */
282
+ async oidcAvailable() {
283
+ try {
284
+ const res = await fetch(new URL("/v1/auth/oidc/start", this.opts.baseUrl), { method: "HEAD" });
285
+ return res.status !== 404;
286
+ }
287
+ catch {
288
+ return false;
289
+ }
290
+ }
291
+ /**
292
+ * This installation's licence (docs/onprem-delivery.md §6.5). Readable by any
293
+ * signed-in user: the footer it feeds is on every page for everybody.
294
+ *
295
+ * On SaaS it answers `onPrem: false` rather than 404, so the caller has one shape to
296
+ * read and the surfaces draw nothing on the flag.
297
+ */
298
+ license() {
299
+ return this.json("GET", "/v1/license");
300
+ }
301
+ /**
302
+ * The names of this deployment (app domain, docs address). Callable without auth.
303
+ *
304
+ * This exists so the dashboard does not hard-code a domain into the screen
305
+ * (docs/environments.md §3.2) — hard-coded, the dev screen tells people a
306
+ * production address, and because that address opens, nobody ever says it is
307
+ * wrong.
308
+ */
309
+ siteConfig() {
310
+ return this.json("GET", "/v1/config");
311
+ }
81
312
  me() {
82
313
  return this.json("GET", "/v1/me");
83
314
  }
84
315
  listOrgs() {
85
316
  return this.json("GET", "/v1/orgs");
86
317
  }
318
+ /** Changes the display name only (admin). The slug is the name that becomes an address, so it is not on this surface. */
319
+ /**
320
+ * `requireTotp` is left out when it is not given, on purpose: the server reads
321
+ * an absent field as "leave it alone". Sending `false` by default would mean a
322
+ * rename silently switched the org's second-factor requirement off.
323
+ */
324
+ updateOrg(org, name, requireTotp) {
325
+ return this.json("PATCH", `/v1/orgs/${encodeURIComponent(org)}`, {
326
+ name,
327
+ ...(requireTotp === undefined ? {} : { requireTotp }),
328
+ });
329
+ }
330
+ /**
331
+ * Deletes the organization (admin). **This cannot be undone.**
332
+ *
333
+ * `confirm` has to be the organization slug exactly — the confirmation lives on
334
+ * the server because three places call this surface (the screen, the CLI, and
335
+ * scripts). If a live project, domain, repository, or DNS zone is left, it is a
336
+ * 409 `org_not_empty` and `details.holdings` says what is left — **projects
337
+ * already deleted are not counted.**
338
+ *
339
+ * The `purgeAfter` in the answer is when the rows actually disappear. By the
340
+ * moment it returns the organization is already gone from every surface; what
341
+ * remains is retention until that time.
342
+ */
343
+ deleteOrg(org, confirm) {
344
+ return this.json("DELETE", `/v1/orgs/${encodeURIComponent(org)}`, { confirm });
345
+ }
87
346
  createOrg(slug, name) {
88
347
  return this.json("POST", "/v1/orgs", { slug, name });
89
348
  }
90
349
  /**
91
- * org 의 최근 알림 (docs/limits.md §3.4).
350
+ * The organization's recent notifications (docs/limits.md §3.4).
92
351
  *
93
- * `sentAt` 이 없는 행은 아직 큐에 있거나 받을 이메일이 없는 것이다 — 후자에게
94
- * 이 목록이 유일한 통로라, 화면은 두 상태를 같게 그린다.
352
+ * A row with no `sentAt` is either still queued or has no email address to
353
+ * reach — and for the second, this list is the only channel, so the screen
354
+ * draws both states the same way.
95
355
  */
96
356
  listNotifications(org, limit) {
97
357
  const q = limit === undefined ? "" : `?limit=${limit}`;
98
358
  return this.json("GET", `/v1/orgs/${encodeURIComponent(org)}/notifications${q}`);
99
359
  }
360
+ /**
361
+ * The plan and billing state (docs/billing.md). If `enabled` is false, this
362
+ * deployment has no billing — the screen shows only a contact address.
363
+ */
364
+ getBilling(org) {
365
+ return this.json("GET", `/v1/orgs/${encodeURIComponent(org)}/billing`);
366
+ }
367
+ /**
368
+ * A Pro checkout session. Send the browser to the `url` that comes back. Even
369
+ * once payment finishes, the thing that changes the plan is the webhook, so
370
+ * read `getBilling` again after the browser returns.
371
+ */
372
+ createBillingCheckout(org, returnTo) {
373
+ return this.json("POST", `/v1/orgs/${encodeURIComponent(org)}/billing/checkout`, { returnTo });
374
+ }
375
+ /** A one-time `url` for the customer portal (payment method, receipts, cancellation). */
376
+ createBillingPortal(org, returnTo) {
377
+ return this.json("POST", `/v1/orgs/${encodeURIComponent(org)}/billing/portal`, { returnTo });
378
+ }
379
+ /** The customer session token for the payment-method embed (1 hour). An org with no payment history gets a 404. */
380
+ createBillingSession(org) {
381
+ return this.json("POST", `/v1/orgs/${encodeURIComponent(org)}/billing/session`, {});
382
+ }
383
+ /** Schedules cancellation at the end of the period (`cancel: true`), or undoes it. There is no immediate revocation. */
384
+ cancelBilling(org, body) {
385
+ return this.json("POST", `/v1/orgs/${encodeURIComponent(org)}/billing/cancel`, body);
386
+ }
100
387
  listProjects(org) {
101
388
  return this.json("GET", `/v1/orgs/${encodeURIComponent(org)}/projects`);
102
389
  }
@@ -106,17 +393,859 @@ export class Client {
106
393
  getProject(org, name) {
107
394
  return this.json("GET", `/v1/orgs/${encodeURIComponent(org)}/projects/${encodeURIComponent(name)}`);
108
395
  }
396
+ /**
397
+ * Renames the project (admin). **The default address moves with it and there is
398
+ * no alias** — which is why the response carries the new address. Unlike the
399
+ * org slug, this name can change because it is the inner label of the org
400
+ * wildcard certificate.
401
+ */
402
+ updateProject(org, name, next) {
403
+ return this.json("PATCH", this.projectPath(org, name), { name: next });
404
+ }
405
+ /**
406
+ * Starts tearing the project down (admin). **This cannot be undone and leaves
407
+ * no recovery generation.** `confirm` has to be the project name exactly.
408
+ */
409
+ deleteProject(org, name, confirm) {
410
+ return this.json("DELETE", this.projectPath(org, name), { confirm });
411
+ }
412
+ /**
413
+ * Disables a project (admin): it stops serving and taking new backups, and
414
+ * keeps everything it has. A project disabled for a year is deleted for good.
415
+ */
416
+ disableProject(org, name) {
417
+ return this.json("POST", `${this.projectPath(org, name)}/disable`);
418
+ }
419
+ /** Enables a disabled project (admin). 409 `project_limit` when there is no room for it. */
420
+ enableProject(org, name) {
421
+ return this.json("POST", `${this.projectPath(org, name)}/enable`);
422
+ }
423
+ /** Watches the teardown operation to its end even after the project is gone. */
424
+ getOrgOperation(org, opId) {
425
+ return this.json("GET", `/v1/orgs/${encodeURIComponent(org)}/operations/${encodeURIComponent(opId)}`);
426
+ }
427
+ /** Everything the project's first screen takes in one call. Usage calls `getUsage` alongside it. */
428
+ getProjectOverview(org, name) {
429
+ return this.json("GET", `${this.projectPath(org, name)}/overview`);
430
+ }
109
431
  listDeployments(org, name) {
110
432
  return this.json("GET", `/v1/orgs/${encodeURIComponent(org)}/projects/${encodeURIComponent(name)}/deployments`);
111
433
  }
112
- /** 본문이 곧 번들이다. 다이제스트 하나가 코드와 자산 전부를 덮는다. */
113
- deploy(org, name, bundle) {
434
+ /**
435
+ * One deployment, with `migrations` when the control plane applied its
436
+ * `migrations/` — which today means a preview deployed with `db=branch`
437
+ * (docs/studio.md §6.6 step 2).
438
+ *
439
+ * A preview's deployment is read under **the parent project's name**, the name
440
+ * the caller deployed through: the preview is a project of its own, but the
441
+ * caller never learns its name.
442
+ */
443
+ getDeployment(org, name, deploymentId) {
444
+ return this.json("GET", `${this.projectPath(org, name)}/deployments/${encodeURIComponent(deploymentId)}`);
445
+ }
446
+ /** Completed-front HTTP outcomes only; native crash-free health is unknown. */
447
+ getReleaseHealth(org, name) {
448
+ return this.json("GET", `${this.projectPath(org, name)}/error-releases`);
449
+ }
450
+ /** Historical first transition per issue; never substitutes a latest occurrence. */
451
+ listReleaseIssues(org, name, version, opts) {
452
+ const q = new URLSearchParams({ kind: opts.kind, windowStart: opts.windowStart, windowEnd: opts.windowEnd });
453
+ if (opts.cursor !== undefined)
454
+ q.set("cursor", opts.cursor);
455
+ return this.json("GET", `${this.projectPath(org, name)}/error-releases/${encodeURIComponent(String(version))}/issues?${q}`);
456
+ }
457
+ /** Runlot Errors: the issue stream (docs/customer-error-tracking.md). */
458
+ listErrorIssues(org, name, opts = {}) {
459
+ const q = new URLSearchParams();
460
+ if (opts.status)
461
+ q.set("status", opts.status);
462
+ if (opts.query)
463
+ q.set("query", opts.query);
464
+ if (opts.cursor)
465
+ q.set("cursor", opts.cursor);
466
+ if (opts.limit !== undefined)
467
+ q.set("limit", String(opts.limit));
468
+ const qs = q.size > 0 ? `?${q}` : "";
469
+ return this.json("GET", `${this.projectPath(org, name)}/errors${qs}`);
470
+ }
471
+ getErrorIssue(org, name, issueId) {
472
+ return this.json("GET", `${this.projectPath(org, name)}/errors/${encodeURIComponent(issueId)}`);
473
+ }
474
+ updateErrorIssue(org, name, issueId, update) {
475
+ return this.json("PATCH", `${this.projectPath(org, name)}/errors/${encodeURIComponent(issueId)}`, update);
476
+ }
477
+ /** Source context, suspects and owners for the selected stored occurrence, or latest when omitted. */
478
+ async getErrorInsights(org, name, issueId, opts = {}) {
479
+ const eventId = opts.eventId;
480
+ const q = new URLSearchParams();
481
+ if (eventId !== undefined)
482
+ q.set("eventId", eventId);
483
+ const qs = q.size > 0 ? `?${q}` : "";
484
+ const out = await this.json("GET", `${this.projectPath(org, name)}/errors/${encodeURIComponent(issueId)}/insights${qs}`);
485
+ if (eventId !== undefined && (eventId === "" || out.eventId !== eventId)) {
486
+ throw new Error("Code insights did not identify the requested occurrence; this server may not support event selection.");
487
+ }
488
+ return out;
489
+ }
490
+ listErrorEvents(org, name, issueId, opts = {}) {
491
+ const q = new URLSearchParams();
492
+ if (opts.cursor)
493
+ q.set("cursor", opts.cursor);
494
+ if (opts.limit !== undefined)
495
+ q.set("limit", String(opts.limit));
496
+ const qs = q.size > 0 ? `?${q}` : "";
497
+ return this.json("GET", `${this.projectPath(org, name)}/errors/${encodeURIComponent(issueId)}/events${qs}`);
498
+ }
499
+ getErrorEvent(org, name, issueId, eventId) {
500
+ return this.json("GET", `${this.projectPath(org, name)}/errors/${encodeURIComponent(issueId)}/events/${encodeURIComponent(eventId)}`);
501
+ }
502
+ /**
503
+ * Other events of the project joined to this one by front's request ID or a
504
+ * browser-minted trace ID (§12). Correlation only: issues are never merged.
505
+ */
506
+ getRelatedErrorEvents(org, name, issueId, eventId) {
507
+ return this.json("GET", `${this.projectPath(org, name)}/errors/${encodeURIComponent(issueId)}/events/${encodeURIComponent(eventId)}/related`);
508
+ }
509
+ /** An issue's hourly history from the ClickHouse store; `available: false` where there is none. */
510
+ getErrorHistory(org, name, issueId, days) {
511
+ const qs = days !== undefined ? `?days=${encodeURIComponent(String(days))}` : "";
512
+ return this.json("GET", `${this.projectPath(org, name)}/errors/${encodeURIComponent(issueId)}/history${qs}`);
513
+ }
514
+ /** Assign an issue to an org member, or clear it with null. */
515
+ assignErrorIssue(org, name, issueId, userId) {
516
+ return this.json("PUT", `${this.projectPath(org, name)}/errors/${encodeURIComponent(issueId)}/assignee`, { userId });
517
+ }
518
+ listErrorComments(org, name, issueId) {
519
+ return this.json("GET", `${this.projectPath(org, name)}/errors/${encodeURIComponent(issueId)}/comments`);
520
+ }
521
+ /** Plain text, at most 4000 characters; the author is the signed-in user. */
522
+ addErrorComment(org, name, issueId, body) {
523
+ return this.json("POST", `${this.projectPath(org, name)}/errors/${encodeURIComponent(issueId)}/comments`, { body });
524
+ }
525
+ /** Merge up to ten issues of the same origin into `targetIssueId`. */
526
+ mergeErrorIssues(org, name, targetIssueId, sourceIssueIds) {
527
+ return this.json("POST", `${this.projectPath(org, name)}/errors/${encodeURIComponent(targetIssueId)}/merge`, {
528
+ sourceIssueIds,
529
+ });
530
+ }
531
+ /** Take a merged source back out of the issue it was merged into. */
532
+ unmergeErrorIssue(org, name, issueId) {
533
+ return this.json("POST", `${this.projectPath(org, name)}/errors/${encodeURIComponent(issueId)}/unmerge`);
534
+ }
535
+ /** Shared stack hints: frame overlap, never a merge or a causal claim. */
536
+ similarErrorIssues(org, name, issueId) {
537
+ return this.json("GET", `${this.projectPath(org, name)}/errors/${encodeURIComponent(issueId)}/similar`);
538
+ }
539
+ getErrorFingerprintRules(org, name) {
540
+ return this.json("GET", `${this.projectPath(org, name)}/errors-fingerprint-rules`);
541
+ }
542
+ putErrorFingerprintRules(org, name, rules) {
543
+ return this.json("PUT", `${this.projectPath(org, name)}/errors-fingerprint-rules`, { rules });
544
+ }
545
+ getErrorAlerts(org, name) { return this.json("GET", `${this.projectPath(org, name)}/error-alerts`); }
546
+ putErrorAlertRule(org, name, id, rule) { return this.json("PUT", `${this.projectPath(org, name)}/error-alerts/rules/${encodeURIComponent(id)}`, rule); }
547
+ deleteErrorAlertRule(org, name, id) { return this.json("DELETE", `${this.projectPath(org, name)}/error-alerts/rules/${encodeURIComponent(id)}`); }
548
+ putErrorAlertDestination(org, name, id, input) { return this.json("PUT", `${this.projectPath(org, name)}/error-alerts/destinations/${encodeURIComponent(id)}`, input); }
549
+ deleteErrorAlertDestination(org, name, id) { return this.json("DELETE", `${this.projectPath(org, name)}/error-alerts/destinations/${encodeURIComponent(id)}`); }
550
+ getErrorAlertMail(org, name) { return this.json("GET", `${this.projectPath(org, name)}/error-alerts/mail`); }
551
+ putErrorAlertMail(org, name, preference) { return this.json("PUT", `${this.projectPath(org, name)}/error-alerts/mail`, preference); }
552
+ listErrorAlertDeliveries(org, name) { return this.json("GET", `${this.projectPath(org, name)}/error-alerts/deliveries`); }
553
+ // Monitors, downtimes and SLOs (docs/customer-observability.md §17.8, §17.9).
554
+ // Destinations are the error-alert destinations above, shared by both.
555
+ listMonitors(org, name) { return this.json("GET", `${this.projectPath(org, name)}/observability/monitors`); }
556
+ exportMonitors(org, name) { return this.json("GET", `${this.projectPath(org, name)}/observability/monitors/export`); }
557
+ getMonitor(org, name, id) { return this.json("GET", `${this.projectPath(org, name)}/observability/monitors/${encodeURIComponent(id)}`); }
558
+ putMonitor(org, name, id, monitor) { return this.json("PUT", `${this.projectPath(org, name)}/observability/monitors/${encodeURIComponent(id)}`, monitor); }
559
+ deleteMonitor(org, name, id) { return this.json("DELETE", `${this.projectPath(org, name)}/observability/monitors/${encodeURIComponent(id)}`); }
560
+ getMonitorHistory(org, name, id, limit) {
561
+ const q = limit ? `?limit=${encodeURIComponent(String(limit))}` : "";
562
+ return this.json("GET", `${this.projectPath(org, name)}/observability/monitors/${encodeURIComponent(id)}/history${q}`);
563
+ }
564
+ testMonitor(org, name, id) { return this.json("POST", `${this.projectPath(org, name)}/observability/monitors/${encodeURIComponent(id)}/test`); }
565
+ listDowntimes(org, name) { return this.json("GET", `${this.projectPath(org, name)}/observability/downtimes`); }
566
+ putDowntime(org, name, id, downtime) { return this.json("PUT", `${this.projectPath(org, name)}/observability/downtimes/${encodeURIComponent(id)}`, downtime); }
567
+ deleteDowntime(org, name, id) { return this.json("DELETE", `${this.projectPath(org, name)}/observability/downtimes/${encodeURIComponent(id)}`); }
568
+ listSLOs(org, name) { return this.json("GET", `${this.projectPath(org, name)}/observability/slos`); }
569
+ getSLO(org, name, id) { return this.json("GET", `${this.projectPath(org, name)}/observability/slos/${encodeURIComponent(id)}`); }
570
+ putSLO(org, name, id, slo) { return this.json("PUT", `${this.projectPath(org, name)}/observability/slos/${encodeURIComponent(id)}`, slo); }
571
+ deleteSLO(org, name, id) { return this.json("DELETE", `${this.projectPath(org, name)}/observability/slos/${encodeURIComponent(id)}`); }
572
+ /**
573
+ * Observability access and governance (customer-observability.md §12, §16, §17.15):
574
+ * the caller's grants, per-project role overrides, the audit trail, the data page,
575
+ * caps, export destinations and rehydration.
576
+ */
577
+ getObservabilityPermissions(org, name) {
578
+ return this.json("GET", `${this.projectPath(org, name)}/observability/permissions`);
579
+ }
580
+ listObservabilityRoles(org, name) {
581
+ return this.json("GET", `${this.projectPath(org, name)}/observability/roles`);
582
+ }
583
+ putObservabilityRole(org, name, userId, grants) {
584
+ return this.json("PUT", `${this.projectPath(org, name)}/observability/roles/${encodeURIComponent(userId)}`, { grants });
585
+ }
586
+ deleteObservabilityRole(org, name, userId) {
587
+ return this.json("DELETE", `${this.projectPath(org, name)}/observability/roles/${encodeURIComponent(userId)}`);
588
+ }
589
+ listObservabilityAudit(org, name, opts = {}) {
590
+ const q = new URLSearchParams();
591
+ if (opts.limit !== undefined)
592
+ q.set("limit", String(opts.limit));
593
+ if (opts.before !== undefined)
594
+ q.set("before", opts.before);
595
+ const qs = q.size > 0 ? `?${q.toString()}` : "";
596
+ return this.json("GET", `${this.projectPath(org, name)}/observability/audit${qs}`);
597
+ }
598
+ getObservabilityData(org, name) {
599
+ return this.json("GET", `${this.projectPath(org, name)}/observability/data`);
600
+ }
601
+ getObservabilityCaps(org, name) {
602
+ return this.json("GET", `${this.projectPath(org, name)}/observability/caps`);
603
+ }
604
+ /** Named meters only: a number, -1 (no cap, Pro) or null (the plan's included amount). */
605
+ putObservabilityCaps(org, name, caps) {
606
+ return this.json("PUT", `${this.projectPath(org, name)}/observability/caps`, caps);
607
+ }
608
+ listObservabilityExports(org, name) {
609
+ return this.json("GET", `${this.projectPath(org, name)}/observability/exports`);
610
+ }
611
+ getObservabilityExport(org, name, exportId) {
612
+ return this.json("GET", `${this.projectPath(org, name)}/observability/exports/${encodeURIComponent(exportId)}`);
613
+ }
614
+ createObservabilityExport(org, name, input) {
615
+ return this.json("POST", `${this.projectPath(org, name)}/observability/exports`, input);
616
+ }
617
+ updateObservabilityExport(org, name, exportId, input) {
618
+ return this.json("PATCH", `${this.projectPath(org, name)}/observability/exports/${encodeURIComponent(exportId)}`, input);
619
+ }
620
+ deleteObservabilityExport(org, name, exportId) {
621
+ return this.json("DELETE", `${this.projectPath(org, name)}/observability/exports/${encodeURIComponent(exportId)}`);
622
+ }
623
+ listObservabilityRehydrations(org, name) {
624
+ return this.json("GET", `${this.projectPath(org, name)}/observability/rehydrations`);
625
+ }
626
+ getObservabilityRehydration(org, name, jobId) {
627
+ return this.json("GET", `${this.projectPath(org, name)}/observability/rehydrations/${encodeURIComponent(jobId)}`);
628
+ }
629
+ /** Loads an archived range back for seven days; the answer is the queued job. */
630
+ createObservabilityRehydration(org, name, input) {
631
+ return this.json("POST", `${this.projectPath(org, name)}/observability/rehydrations`, input);
632
+ }
633
+ /** `runlot bug-report` (customer-observability.md §14): the CP snapshots what the references name. */
634
+ createBugReport(org, input) {
635
+ return this.json("POST", `/v1/orgs/${encodeURIComponent(org)}/bug-reports`, input);
636
+ }
637
+ listBugReports(org) {
638
+ return this.json("GET", `/v1/orgs/${encodeURIComponent(org)}/bug-reports`);
639
+ }
640
+ getBugReport(org, reportId, opts = {}) {
641
+ const qs = opts.snapshot === false ? "?snapshot=0" : "";
642
+ return this.json("GET", `/v1/orgs/${encodeURIComponent(org)}/bug-reports/${encodeURIComponent(reportId)}${qs}`);
643
+ }
644
+ deleteBugReport(org, reportId) {
645
+ return this.json("DELETE", `/v1/orgs/${encodeURIComponent(org)}/bug-reports/${encodeURIComponent(reportId)}`);
646
+ }
647
+ /** Synthetic HTTP checks of the project's own addresses (customer-observability.md §17.11). */
648
+ listUptimeChecks(org, name) {
649
+ return this.json("GET", `${this.projectPath(org, name)}/uptime-checks`);
650
+ }
651
+ putUptimeCheck(org, name, id, input) {
652
+ return this.json("PUT", `${this.projectPath(org, name)}/uptime-checks/${encodeURIComponent(id)}`, input);
653
+ }
654
+ deleteUptimeCheck(org, name, id) {
655
+ return this.json("DELETE", `${this.projectPath(org, name)}/uptime-checks/${encodeURIComponent(id)}`);
656
+ }
657
+ listUptimeRuns(org, name, id, limit) {
658
+ const qs = limit !== undefined ? `?limit=${encodeURIComponent(String(limit))}` : "";
659
+ return this.json("GET", `${this.projectPath(org, name)}/uptime-checks/${encodeURIComponent(id)}/runs${qs}`);
660
+ }
661
+ /** Dashboards (customer-observability.md §17.7). A built-in's id is `builtin:<key>`. */
662
+ listDashboards(org, name) {
663
+ return this.json("GET", `${this.projectPath(org, name)}/observability/dashboards`);
664
+ }
665
+ createDashboard(org, name, input) {
666
+ return this.json("POST", `${this.projectPath(org, name)}/observability/dashboards`, input);
667
+ }
668
+ getDashboard(org, name, id) {
669
+ return this.json("GET", `${this.projectPath(org, name)}/observability/dashboards/${encodeURIComponent(id)}`);
670
+ }
671
+ putDashboard(org, name, id, input) {
672
+ return this.json("PUT", `${this.projectPath(org, name)}/observability/dashboards/${encodeURIComponent(id)}`, input);
673
+ }
674
+ deleteDashboard(org, name, id) {
675
+ return this.json("DELETE", `${this.projectPath(org, name)}/observability/dashboards/${encodeURIComponent(id)}`);
676
+ }
677
+ /** The `.runlot/dashboards/<key>.json` form of a dashboard. */
678
+ exportDashboard(org, name, id) {
679
+ return this.json("GET", `${this.projectPath(org, name)}/observability/dashboards/${encodeURIComponent(id)}/export`);
680
+ }
681
+ /** Make (or rotate) the public link; the token is shown once. */
682
+ shareDashboard(org, name, id, isPublic = true) {
683
+ return this.json("POST", `${this.projectPath(org, name)}/observability/dashboards/${encodeURIComponent(id)}/share`, { public: isPublic });
684
+ }
685
+ unshareDashboard(org, name, id) {
686
+ return this.json("DELETE", `${this.projectPath(org, name)}/observability/dashboards/${encodeURIComponent(id)}/share`);
687
+ }
688
+ getDashboardWidgetData(org, name, id, widgetId, req = {}) {
689
+ return this.json("POST", `${this.projectPath(org, name)}/observability/dashboards/${encodeURIComponent(id)}/widgets/${encodeURIComponent(widgetId)}/data`, req);
690
+ }
691
+ getDashboardSettings(org, name) {
692
+ return this.json("GET", `${this.projectPath(org, name)}/observability/dashboard-settings`);
693
+ }
694
+ putDashboardSettings(org, name, settings) {
695
+ return this.json("PUT", `${this.projectPath(org, name)}/observability/dashboard-settings`, settings);
696
+ }
697
+ /** Deploy and OOM markers for every time series. */
698
+ getObservabilityMarkers(org, name, range = {}) {
699
+ const q = new URLSearchParams();
700
+ if (range.from)
701
+ q.set("from", range.from);
702
+ if (range.to)
703
+ q.set("to", range.to);
704
+ const qs = q.toString();
705
+ return this.json("GET", `${this.projectPath(org, name)}/observability/markers${qs ? `?${qs}` : ""}`);
706
+ }
707
+ /** Watchdog insights (§17.10). Free: deploy regressions only. */
708
+ listInsights(org, name, opts = {}) {
709
+ const q = new URLSearchParams();
710
+ if (opts.state)
711
+ q.set("state", opts.state);
712
+ if (opts.limit !== undefined)
713
+ q.set("limit", String(opts.limit));
714
+ const qs = q.toString();
715
+ return this.json("GET", `${this.projectPath(org, name)}/observability/insights${qs ? `?${qs}` : ""}`);
716
+ }
717
+ resolveInsight(org, name, id) {
718
+ return this.json("POST", `${this.projectPath(org, name)}/observability/insights/${encodeURIComponent(id)}/resolve`);
719
+ }
720
+ /** Synthetic checks (§17.11): the uptime checks, including multi-step API checks. */
721
+ listSynthetics(org, name) {
722
+ return this.json("GET", `${this.projectPath(org, name)}/synthetics`);
723
+ }
724
+ putSynthetic(org, name, id, input) {
725
+ return this.json("PUT", `${this.projectPath(org, name)}/synthetics/${encodeURIComponent(id)}`, input);
726
+ }
727
+ deleteSynthetic(org, name, id) {
728
+ return this.json("DELETE", `${this.projectPath(org, name)}/synthetics/${encodeURIComponent(id)}`);
729
+ }
730
+ listSyntheticRuns(org, name, id, limit) {
731
+ const qs = limit !== undefined ? `?limit=${encodeURIComponent(String(limit))}` : "";
732
+ return this.json("GET", `${this.projectPath(org, name)}/synthetics/${encodeURIComponent(id)}/runs${qs}`);
733
+ }
734
+ /** A public dashboard link. Needs no credential. */
735
+ getSharedDashboard(token) {
736
+ return this.json("GET", `/v1/shared/dashboards/${encodeURIComponent(token)}`);
737
+ }
738
+ getSharedDashboardWidgetData(token, widgetId, req = {}) {
739
+ return this.json("POST", `/v1/shared/dashboards/${encodeURIComponent(token)}/widgets/${encodeURIComponent(widgetId)}/data`, req);
740
+ }
741
+ // Customer observability, APM read side (docs/customer-observability.md §8, §17.2–§17.4,
742
+ // §17.6). Range options are RFC 3339 times; `step` is seconds or a duration ("5m").
743
+ obsApmPath(org, name, sub, q) {
744
+ const qs = new URLSearchParams();
745
+ for (const [k, v] of Object.entries(q ?? {}))
746
+ if (v !== undefined && v !== "")
747
+ qs.set(k, String(v));
748
+ const tail = qs.size > 0 ? `?${qs}` : "";
749
+ return `${this.projectPath(org, name)}/observability/${sub}${tail}`;
750
+ }
751
+ getObsMetricsOverview(org, name, opts = {}) {
752
+ return this.json("GET", this.obsApmPath(org, name, "metrics/overview", opts));
753
+ }
754
+ getObsMetricsMemory(org, name, opts = {}) {
755
+ return this.json("GET", this.obsApmPath(org, name, "metrics/memory", opts));
756
+ }
757
+ getObsMetricsInfrastructure(org, name, opts = {}) {
758
+ return this.json("GET", this.obsApmPath(org, name, "metrics/infrastructure", opts));
759
+ }
760
+ getObsMetricsCustom(org, name, opts) {
761
+ return this.json("GET", this.obsApmPath(org, name, "metrics/custom", opts));
762
+ }
763
+ getObsMetricsCustomNames(org, name) {
764
+ return this.json("GET", this.obsApmPath(org, name, "metrics/custom/names"));
765
+ }
766
+ listObsRoutes(org, name) {
767
+ return this.json("GET", this.obsApmPath(org, name, "routes"));
768
+ }
769
+ putObsRoute(org, name, input) {
770
+ return this.json("PUT", this.obsApmPath(org, name, "routes"), input);
771
+ }
772
+ getObsAPMRoutes(org, name, opts = {}) {
773
+ return this.json("GET", this.obsApmPath(org, name, "apm/routes", opts));
774
+ }
775
+ getObsAPMBreakdown(org, name, route, opts = {}) {
776
+ return this.json("GET", this.obsApmPath(org, name, `apm/routes/${encodeURIComponent(route)}/breakdown`, opts));
777
+ }
778
+ getObsAPMServiceMap(org, name, opts = {}) {
779
+ return this.json("GET", this.obsApmPath(org, name, "apm/service-map", opts));
780
+ }
781
+ getObsAPMCompare(org, name, a, b, opts = {}) {
782
+ return this.json("GET", this.obsApmPath(org, name, "apm/compare", { ...opts, a, b }));
783
+ }
784
+ listObsAPMTraces(org, name, opts = {}) {
785
+ return this.json("GET", this.obsApmPath(org, name, "apm/traces", opts));
786
+ }
787
+ getObsAPMTrace(org, name, traceId) {
788
+ return this.json("GET", this.obsApmPath(org, name, `apm/traces/${encodeURIComponent(traceId)}`));
789
+ }
790
+ listObsTraceFilters(org, name) {
791
+ return this.json("GET", this.obsApmPath(org, name, "trace-filters"));
792
+ }
793
+ createObsTraceFilter(org, name, input) {
794
+ return this.json("POST", this.obsApmPath(org, name, "trace-filters"), input);
795
+ }
796
+ updateObsTraceFilter(org, name, id, input) {
797
+ return this.json("PUT", this.obsApmPath(org, name, `trace-filters/${encodeURIComponent(id)}`), input);
798
+ }
799
+ deleteObsTraceFilter(org, name, id) {
800
+ return this.json("DELETE", this.obsApmPath(org, name, `trace-filters/${encodeURIComponent(id)}`));
801
+ }
802
+ listObsDBQueries(org, name, opts = {}) {
803
+ return this.json("GET", this.obsApmPath(org, name, "database/queries", opts));
804
+ }
805
+ getObsDBQuery(org, name, fingerprint, opts = {}) {
806
+ return this.json("GET", this.obsApmPath(org, name, `database/queries/${encodeURIComponent(fingerprint)}`, opts));
807
+ }
808
+ getObsDBHealth(org, name) {
809
+ return this.json("GET", this.obsApmPath(org, name, "database/health"));
810
+ }
811
+ /** The continuous profiler's switch (customer-observability.md §17.13). */
812
+ getObsProfilerSettings(org, name) {
813
+ return this.json("GET", `${this.projectPath(org, name)}/observability/profiler`);
814
+ }
815
+ /** On, off, or null for the default. Applies from the next deployment or restart. Admin. */
816
+ putObsProfilerSettings(org, name, enabled) {
817
+ return this.json("PUT", `${this.projectPath(org, name)}/observability/profiler`, { enabled });
818
+ }
819
+ /** The logs/traces sampling override; a null field is the manifest's. */
820
+ getObsSampling(org, name) {
821
+ return this.json("GET", `${this.projectPath(org, name)}/observability/sampling`);
822
+ }
823
+ /** Replaces the override (null = the manifest's). Admin. */
824
+ putObsSampling(org, name, body) {
825
+ return this.json("PUT", `${this.projectPath(org, name)}/observability/sampling`, body);
826
+ }
827
+ listObsProfiles(org, name, q = {}) {
828
+ return this.json("GET", `${this.projectPath(org, name)}/observability/profiles${obsProfileQS({ ...q })}`);
829
+ }
830
+ /** The windows within a minute of `ts` — the profile of a slow trace's minute. */
831
+ nearObsProfiles(org, name, ts) {
832
+ return this.json("GET", `${this.projectPath(org, name)}/observability/profiles/near${obsProfileQS({ ts })}`);
833
+ }
834
+ getObsFlamegraph(org, name, q = {}) {
835
+ return this.json("GET", `${this.projectPath(org, name)}/observability/profiles/flamegraph${obsProfileQS({ ...q })}`);
836
+ }
837
+ getObsProfileTop(org, name, q = {}) {
838
+ return this.json("GET", `${this.projectPath(org, name)}/observability/profiles/top${obsProfileQS({ ...q })}`);
839
+ }
840
+ /** Self-time share per function, version a against version b. */
841
+ compareObsProfiles(org, name, a, b, q = {}) {
842
+ return this.json("GET", `${this.projectPath(org, name)}/observability/profiles/compare${obsProfileQS({ a, b, ...q })}`);
843
+ }
844
+ /** RUM: page views, sessions and p75 vitals over time (Pro). */
845
+ getObsRUMOverview(org, name, q = {}) {
846
+ return this.json("GET", `${this.projectPath(org, name)}/observability/rum/overview${obsProfileQS({ ...q })}`);
847
+ }
848
+ /** RUM by page template, with vitals, long tasks and resource/fetch timings (Pro). */
849
+ listObsRUMPages(org, name, q = {}) {
850
+ return this.json("GET", `${this.projectPath(org, name)}/observability/rum/pages${obsProfileQS({ ...q })}`);
851
+ }
852
+ /** RUM by device class (Pro). */
853
+ listObsRUMDevices(org, name, q = {}) {
854
+ return this.json("GET", `${this.projectPath(org, name)}/observability/rum/devices${obsProfileQS({ ...q })}`);
855
+ }
856
+ /** RUM page views, newest (or slowest LCP) first (Pro). */
857
+ listObsRUMViews(org, name, q = {}) {
858
+ return this.json("GET", `${this.projectPath(org, name)}/observability/rum/views${obsProfileQS({ ...q })}`);
859
+ }
860
+ /** One page view and the server requests it caused (Pro). */
861
+ getObsRUMView(org, name, viewId) {
862
+ return this.json("GET", `${this.projectPath(org, name)}/observability/rum/views/${encodeURIComponent(viewId)}`);
863
+ }
864
+ /** Starts one heap snapshot (Pro, admin; pauses the app while taken). Poll the list. */
865
+ createObsHeapSnapshot(org, name) {
866
+ return this.json("POST", `${this.projectPath(org, name)}/observability/heap-snapshots`, {});
867
+ }
868
+ listObsHeapSnapshots(org, name) {
869
+ return this.json("GET", `${this.projectPath(org, name)}/observability/heap-snapshots`);
870
+ }
871
+ /** The download URL of a ready snapshot (a `.heapsnapshot` file). */
872
+ obsHeapSnapshotURL(org, name, snapshotId) {
873
+ return new URL(`${this.projectPath(org, name)}/observability/heap-snapshots/${encodeURIComponent(snapshotId)}`, this.opts.baseUrl).toString();
874
+ }
875
+ /** A ready snapshot's text (Chrome DevTools heap snapshot JSON). */
876
+ downloadObsHeapSnapshot(org, name, snapshotId) {
877
+ return this.text("GET", `${this.projectPath(org, name)}/observability/heap-snapshots/${encodeURIComponent(snapshotId)}`);
878
+ }
879
+ getErrorOwnership(org, name) {
880
+ return this.json("GET", `${this.projectPath(org, name)}/errors-ownership`);
881
+ }
882
+ createErrorOwnershipPin(org, name, input) {
883
+ return this.json("POST", `${this.projectPath(org, name)}/errors-ownership/pins`, input);
884
+ }
885
+ revokeErrorOwnershipPin(org, name, deploymentId, selector) {
886
+ return this.json("DELETE", `${this.projectPath(org, name)}/errors-ownership/pins/${encodeURIComponent(deploymentId)}/${encodeURIComponent(selector)}`);
887
+ }
888
+ getErrorCapturePolicy(org, name) {
889
+ return this.json("GET", `${this.projectPath(org, name)}/errors-capture-policy`);
890
+ }
891
+ putErrorCapturePolicy(org, name, policy, acknowledgePII = false) {
892
+ return this.json("PUT", `${this.projectPath(org, name)}/errors-capture-policy`, { policy, acknowledgePII });
893
+ }
894
+ // ---- Observability (docs/customer-observability.md §7, §17.5) ----
895
+ obsPath(org, name) {
896
+ return `${this.projectPath(org, name)}/observability`;
897
+ }
898
+ getObservabilityCapabilities(org, name) {
899
+ return this.json("GET", `${this.obsPath(org, name)}/capabilities`);
900
+ }
901
+ /** Runs a query; `{ available: false }` where there is no event store. */
902
+ queryObservability(org, name, query) {
903
+ return this.json("POST", `${this.obsPath(org, name)}/query`, query);
904
+ }
905
+ listObservabilityKeys(org, name, opts = {}) {
906
+ return this.json("GET", `${this.obsPath(org, name)}/keys${obsQS(opts)}`);
907
+ }
908
+ listObservabilityValues(org, name, key, opts = {}) {
909
+ return this.json("GET", `${this.obsPath(org, name)}/values${obsQS({ ...opts, key })}`);
910
+ }
911
+ listObservabilityPatterns(org, name, opts = {}) {
912
+ return this.json("GET", `${this.obsPath(org, name)}/patterns${obsQS(opts)}`);
913
+ }
914
+ getObservabilityRequest(org, name, requestId) {
915
+ return this.json("GET", `${this.obsPath(org, name)}/requests/${encodeURIComponent(requestId)}`);
916
+ }
917
+ listSavedQueries(org, name) {
918
+ return this.json("GET", `${this.obsPath(org, name)}/saved-queries`);
919
+ }
920
+ getSavedQuery(org, name, queryId) {
921
+ return this.json("GET", `${this.obsPath(org, name)}/saved-queries/${encodeURIComponent(queryId)}`);
922
+ }
923
+ createSavedQuery(org, name, input) {
924
+ return this.json("POST", `${this.obsPath(org, name)}/saved-queries`, input);
925
+ }
926
+ updateSavedQuery(org, name, queryId, input) {
927
+ return this.json("PUT", `${this.obsPath(org, name)}/saved-queries/${encodeURIComponent(queryId)}`, input);
928
+ }
929
+ deleteSavedQuery(org, name, queryId) {
930
+ return this.json("DELETE", `${this.obsPath(org, name)}/saved-queries/${encodeURIComponent(queryId)}`);
931
+ }
932
+ starSavedQuery(org, name, queryId) {
933
+ return this.json("PUT", `${this.obsPath(org, name)}/saved-queries/${encodeURIComponent(queryId)}/star`);
934
+ }
935
+ unstarSavedQuery(org, name, queryId) {
936
+ return this.json("DELETE", `${this.obsPath(org, name)}/saved-queries/${encodeURIComponent(queryId)}/star`);
937
+ }
938
+ getObservabilityPipeline(org, name) {
939
+ return this.json("GET", `${this.obsPath(org, name)}/pipeline`);
940
+ }
941
+ putObservabilityPipeline(org, name, processors) {
942
+ return this.json("PUT", `${this.obsPath(org, name)}/pipeline`, { processors });
943
+ }
944
+ getObservabilityScanner(org, name) {
945
+ return this.json("GET", `${this.obsPath(org, name)}/scanner`);
946
+ }
947
+ putObservabilityScanner(org, name, scanner) {
948
+ return this.json("PUT", `${this.obsPath(org, name)}/scanner`, scanner);
949
+ }
950
+ /** Runs a scanner (the project's, or `scanner`) over a sample; nothing is stored. */
951
+ testObservabilityScanner(org, name, text, scanner) {
952
+ return this.json("POST", `${this.obsPath(org, name)}/scanner/test`, scanner ? { text, scanner } : { text });
953
+ }
954
+ /** The whole ingest configuration, shaped as `.runlot/logs.json`. */
955
+ exportObservabilityLogsConfig(org, name) {
956
+ return this.json("GET", `${this.obsPath(org, name)}/logs-config`);
957
+ }
958
+ listObservabilityLogMetrics(org, name) {
959
+ return this.json("GET", `${this.obsPath(org, name)}/log-metrics`);
960
+ }
961
+ putObservabilityLogMetric(org, name, metric, def) {
962
+ return this.json("PUT", `${this.obsPath(org, name)}/log-metrics/${encodeURIComponent(metric)}`, def);
963
+ }
964
+ deleteObservabilityLogMetric(org, name, metric) {
965
+ return this.json("DELETE", `${this.obsPath(org, name)}/log-metrics/${encodeURIComponent(metric)}`);
966
+ }
967
+ getErrorEventPII(org, name, issueId, eventId) {
968
+ return this.json("GET", `${this.projectPath(org, name)}/errors/${encodeURIComponent(issueId)}/events/${encodeURIComponent(eventId)}?includePII=true`);
969
+ }
970
+ getErrorSettings(org, name) {
971
+ return this.json("GET", `${this.projectPath(org, name)}/errors-settings`);
972
+ }
973
+ putErrorSettings(org, name,
974
+ /** Omitted writable fields preserve their values; ownership assignment defaults off. */
975
+ settings) {
976
+ return this.json("PUT", `${this.projectPath(org, name)}/errors-settings`, settings);
977
+ }
978
+ /**
979
+ * One AI diagnosis of an issue, billed to the org's AI credit. There is no
980
+ * prompt to pass: the control plane builds it from the issue's stored event.
981
+ * The same `idempotencyKey` again returns the stored answer without a second
982
+ * charge, so a caller retrying after a timeout must reuse its key.
983
+ */
984
+ diagnoseErrorIssue(org, name, issueId, body) {
985
+ return this.json("POST", `${this.projectPath(org, name)}/errors/${encodeURIComponent(issueId)}/diagnoses`, body);
986
+ }
987
+ listErrorDiagnoses(org, name, issueId) {
988
+ return this.json("GET", `${this.projectPath(org, name)}/errors/${encodeURIComponent(issueId)}/diagnoses`);
989
+ }
990
+ fixPath(org, name, issueId) {
991
+ return `${this.projectPath(org, name)}/errors/${encodeURIComponent(issueId)}/fix-proposals`;
992
+ }
993
+ /**
994
+ * Ask a model to propose a fix for an issue. Billed to the org's AI credit and
995
+ * writes nothing: the repository, base commit and files are chosen by the control
996
+ * plane. Reuse `idempotencyKey` on a retry so it is not charged twice.
997
+ */
998
+ proposeErrorFix(org, name, issueId, body) {
999
+ return this.json("POST", this.fixPath(org, name, issueId), body);
1000
+ }
1001
+ listErrorFixProposals(org, name, issueId) {
1002
+ return this.json("GET", this.fixPath(org, name, issueId));
1003
+ }
1004
+ getErrorFixProposal(org, name, issueId, proposalId) {
1005
+ return this.json("GET", `${this.fixPath(org, name, issueId)}/${encodeURIComponent(proposalId)}`);
1006
+ }
1007
+ /**
1008
+ * Write a ready proposal as one commit on its own `runlot/autofix/` branch. It
1009
+ * builds, deploys and merges nothing. `proposalSha` must be the proposal's exactly.
1010
+ */
1011
+ applyErrorFix(org, name, issueId, proposalId, proposalSha) {
1012
+ return this.json("POST", `${this.fixPath(org, name, issueId)}/${encodeURIComponent(proposalId)}/apply`, {
1013
+ proposalSha,
1014
+ acknowledgeUnreviewedCode: true,
1015
+ });
1016
+ }
1017
+ lookupErrorFixProposal(org, name, issueId, key) {
1018
+ return this.request("GET", `${this.fixPath(org, name, issueId)}/lookup`, { headers: { "Idempotency-Key": key } });
1019
+ }
1020
+ lookupErrorFixPreview(org, name, issueId, proposalId, key) {
1021
+ return this.request("GET", `${this.fixPath(org, name, issueId)}/${encodeURIComponent(proposalId)}/previews/lookup`, { headers: { "Idempotency-Key": key } });
1022
+ }
1023
+ lookupErrorFixVerification(org, name, issueId, proposalId, jobId, key) {
1024
+ return this.request("GET", `${this.fixPath(org, name, issueId)}/${encodeURIComponent(proposalId)}/previews/${encodeURIComponent(jobId)}/verify/lookup`, { headers: { "Idempotency-Key": key } });
1025
+ }
1026
+ approveErrorFixPreview(org, name, issueId, proposalId, body) {
1027
+ return this.json("POST", `${this.fixPath(org, name, issueId)}/${encodeURIComponent(proposalId)}/previews`, body);
1028
+ }
1029
+ getErrorFixPreview(org, name, issueId, proposalId, jobId) {
1030
+ return this.json("GET", `${this.fixPath(org, name, issueId)}/${encodeURIComponent(proposalId)}/previews/${encodeURIComponent(jobId)}`);
1031
+ }
1032
+ approveErrorFixPreviewVerification(org, name, issueId, proposalId, jobId, body) {
1033
+ return this.json("POST", `${this.fixPath(org, name, issueId)}/${encodeURIComponent(proposalId)}/previews/${encodeURIComponent(jobId)}/verify`, body);
1034
+ }
1035
+ /** Erase captured issue data, after explicit review. Admin; unmerge first. */
1036
+ deleteErrorIssue(org, name, issueId) {
1037
+ return this.json("DELETE", `${this.projectPath(org, name)}/errors/${encodeURIComponent(issueId)}`);
1038
+ }
1039
+ /** Erase an exact application user ID; anonymous aggregates remain. Admin. */
1040
+ eraseErrorUser(org, name, userId) {
1041
+ return this.json("POST", `${this.projectPath(org, name)}/errors-erasure`, { userId });
1042
+ }
1043
+ /** Untrusted browser histograms and technical-fuse counters, not billed usage. Viewer. */
1044
+ getBrowserTelemetry(org, name) {
1045
+ return this.json("GET", `${this.projectPath(org, name)}/browser-telemetry`);
1046
+ }
1047
+ /** Unverified feedback whose exact browser error anchor belongs to this issue. Never includes email. */
1048
+ listBrowserFeedback(org, name, issueId) {
1049
+ return this.json("GET", `${this.projectPath(org, name)}/errors/${encodeURIComponent(issueId)}/feedback`);
1050
+ }
1051
+ /** Explicit sensitive read. Admin + errors:pii; optional unverified email only while feedback-email retention is on. */
1052
+ listBrowserFeedbackWithPII(org, name, issueId) {
1053
+ return this.json("GET", `${this.projectPath(org, name)}/errors/${encodeURIComponent(issueId)}/feedback?includePII=true`);
1054
+ }
1055
+ /** The masked structural replay switch, cap and this month's count. Viewer. */
1056
+ getErrorReplaySettings(org, name) {
1057
+ return this.json("GET", `${this.projectPath(org, name)}/errors-replay-settings`);
1058
+ }
1059
+ /**
1060
+ * Both fields are required: `monthlyCap` null is the plan's amount, `0` stops collection,
1061
+ * `-1` removes the cap (Pro). Admin.
1062
+ */
1063
+ putErrorReplaySettings(org, name, settings) {
1064
+ return this.json("PUT", `${this.projectPath(org, name)}/errors-replay-settings`, settings);
1065
+ }
1066
+ /** An issue's complete masked structural replays. Admin, until a granular PII scope exists. */
1067
+ listErrorReplays(org, name, issueId) {
1068
+ return this.json("GET", `${this.projectPath(org, name)}/errors/${encodeURIComponent(issueId)}/replays`);
1069
+ }
1070
+ /** One replay and its re-validated batches, for the sandboxed player. Admin. */
1071
+ getErrorReplay(org, name, issueId, replayId) {
1072
+ return this.json("GET", `${this.projectPath(org, name)}/errors/${encodeURIComponent(issueId)}/replays/${encodeURIComponent(replayId)}`);
1073
+ }
1074
+ /**
1075
+ * Scheduled runs: what the live deployment declares, when each fires next, and
1076
+ * the recent history (docs/cron.md §8). `limit` bounds the history rows only —
1077
+ * the schedules and the per-schedule last run are never paged.
1078
+ */
1079
+ getProjectCron(org, name, limit) {
1080
+ const qs = limit ? `?limit=${limit}` : "";
1081
+ return this.json("GET", `${this.projectPath(org, name)}/cron${qs}`);
1082
+ }
1083
+ /**
1084
+ * Queues: what the live deployment declares, how deep each one is, and the
1085
+ * recent batch history (docs/queues.md §6). The depth is read from the
1086
+ * project's own database; `depthError` on the answer says when it could not be.
1087
+ */
1088
+ getProjectQueues(org, name, limit) {
1089
+ const qs = limit ? `?limit=${limit}` : "";
1090
+ return this.json("GET", `${this.projectPath(org, name)}/queues${qs}`);
1091
+ }
1092
+ /**
1093
+ * Durable Objects: how many this project has placed, against the two caps
1094
+ * (docs/durable-objects.md).
1095
+ *
1096
+ * **It answers how much, never which.** There is no actor id in the response
1097
+ * and none is coming — those name individual objects, and a list of them would
1098
+ * be an object enumeration wearing a quota's name. `nodes` is keyed by node id
1099
+ * because `nodeLimit` is a separate bound that can refuse a placement while
1100
+ * the project-wide cap still has room.
1101
+ */
1102
+ getProjectDurableObjects(org, name) {
1103
+ return this.json("GET", `${this.projectPath(org, name)}/durable-objects`);
1104
+ }
1105
+ queuePath(org, name, queue) {
1106
+ return `${this.projectPath(org, name)}/queues/${encodeURIComponent(queue)}`;
1107
+ }
1108
+ listQueueRuns(org, name, queue, limit) {
1109
+ const qs = limit ? `?limit=${limit}` : "";
1110
+ return this.json("GET", `${this.queuePath(org, name, queue)}/runs${qs}`);
1111
+ }
1112
+ /** The head of the queue without leasing it — looking cannot delay a delivery. */
1113
+ peekQueue(org, name, queue, limit) {
1114
+ const qs = limit ? `?limit=${limit}` : "";
1115
+ return this.json("GET", `${this.queuePath(org, name, queue)}/messages${qs}`);
1116
+ }
1117
+ /** Irreversible. The confirmation is the caller's — the server holds none. */
1118
+ purgeQueue(org, name, queue) {
1119
+ return this.json("DELETE", `${this.queuePath(org, name, queue)}/messages`);
1120
+ }
1121
+ /**
1122
+ * Moves a dead-letter queue's messages back. `to` is required only when the
1123
+ * dead-letter queue belongs to more than one consumer, or to none.
1124
+ */
1125
+ redriveQueue(org, name, queue, to) {
1126
+ return this.json("POST", `${this.queuePath(org, name, queue)}/redrive`, to === undefined ? {} : { to });
1127
+ }
1128
+ /**
1129
+ * The vector store: every namespace with its count and width, and the plan's
1130
+ * bounds (docs/vectors.md §4). Read from the project's own database;
1131
+ * `readError` on the answer says when it could not be.
1132
+ */
1133
+ getProjectVectors(org, name) {
1134
+ return this.json("GET", `${this.projectPath(org, name)}/vectors`);
1135
+ }
1136
+ /** Irreversible. The confirmation is the caller's — the server holds none. */
1137
+ deleteVectorNamespace(org, name, namespace) {
1138
+ return this.json("DELETE", `${this.projectPath(org, name)}/vectors/${encodeURIComponent(namespace)}`);
1139
+ }
1140
+ /** The body is the bundle. One digest covers all of the code and the assets. */
1141
+ /**
1142
+ * Uploads the bundle. `headers` carries the provenance headers
1143
+ * (`X-Runlot-Git-*`, openapi createDeployment) — the body is the bundle
1144
+ * itself, so the metadata can only travel in headers.
1145
+ */
1146
+ deploy(org, name, bundle, headers = {}) {
114
1147
  return this.request("POST", `/v1/orgs/${encodeURIComponent(org)}/projects/${encodeURIComponent(name)}/deployments`, {
115
1148
  body: bundle,
1149
+ headers: { ...headers, "Content-Type": "application/gzip" },
1150
+ });
1151
+ }
1152
+ /**
1153
+ * The same upload, aimed at a preview (docs/preview.md). **It does not move
1154
+ * production's live pointer** — that is the whole difference, and it is why
1155
+ * this is a named method rather than an optional argument on `deploy`: a
1156
+ * caller that forgets the argument deploys to production.
1157
+ *
1158
+ * `db` picks what `env.db` points at (`branch` by default, `shared` at
1159
+ * production's own database, `none` for no database), and `from` pours the
1160
+ * branch from a named generation instead of the newest one.
1161
+ */
1162
+ deployPreview(org, name, bundle,
1163
+ // `| undefined` spelled out: under exactOptionalPropertyTypes a caller that
1164
+ // forwards an unset flag is passing the property, not omitting it.
1165
+ opts, headers = {}) {
1166
+ return this.request("POST", `${this.projectPath(org, name)}/deployments?${previewQuery(opts)}`, {
1167
+ body: bundle,
1168
+ headers: { ...headers, "Content-Type": "application/gzip" },
1169
+ });
1170
+ }
1171
+ /**
1172
+ * Opens an incremental upload (docs/incremental-deploy-upload.md §1.1). `files` is
1173
+ * the bundle's entry list in tar order; the answer names the hashes to upload.
1174
+ * An older CP answers 404 here — the caller falls back to `deploy`.
1175
+ */
1176
+ createDeploymentUpload(org, name, files, preview) {
1177
+ let path = `${this.projectPath(org, name)}/deployments/uploads`;
1178
+ if (preview)
1179
+ path += `?${previewQuery(preview)}`;
1180
+ return this.json("POST", path, { files });
1181
+ }
1182
+ /** One batch: a gzip tar whose entries are named by their content's sha256 (§1.2). */
1183
+ uploadDeploymentBlobs(org, name, uploadId, batch) {
1184
+ return this.request("POST", `${this.projectPath(org, name)}/deployments/uploads/${encodeURIComponent(uploadId)}/blobs`, {
1185
+ body: batch,
116
1186
  headers: { "Content-Type": "application/gzip" },
117
1187
  });
118
1188
  }
119
- /** 멱등이다. 두 번 불러도 비밀번호는 굴지 않고 같은 접속 정보가 온다. */
1189
+ /**
1190
+ * Assembles and deploys the session (§1.3). The answer is `createDeployment`'s
1191
+ * (with `preview` for a preview session). Idempotent per session, so a retry
1192
+ * after an edge timeout returns the same deployment.
1193
+ */
1194
+ commitDeploymentUpload(org, name, uploadId, headers = {}) {
1195
+ return this.request("POST", `${this.projectPath(org, name)}/deployments/uploads/${encodeURIComponent(uploadId)}/commit`, {
1196
+ headers,
1197
+ });
1198
+ }
1199
+ /** The parent's live previews (viewer). A deleted preview is not listed. */
1200
+ listPreviews(org, name) {
1201
+ return this.json("GET", `${this.projectPath(org, name)}/previews`);
1202
+ }
1203
+ /**
1204
+ * Deletes a preview and its branch (member).
1205
+ *
1206
+ * No confirmation string, unlike `deleteProject`: a branch is a copy taken at a
1207
+ * moment and nothing in it is the only copy of anything.
1208
+ */
1209
+ deletePreview(org, name, preview) {
1210
+ return this.json("DELETE", `${this.projectPath(org, name)}/previews/${encodeURIComponent(preview)}`);
1211
+ }
1212
+ /**
1213
+ * Makes the preview's artifact the parent's live deployment (member).
1214
+ *
1215
+ * **The code, never the data** (docs/preview.md §7). The branch is not merged
1216
+ * and production's database is not replaced. The preview stays alive.
1217
+ */
1218
+ promotePreview(org, name, preview) {
1219
+ return this.json("POST", `${this.projectPath(org, name)}/previews/${encodeURIComponent(preview)}/promote`);
1220
+ }
1221
+ /**
1222
+ * The project's share link — `<label>.share.<app-domain>`, the one address
1223
+ * Studio hands to somebody who is not a developer (docs/studio.md §6.9).
1224
+ *
1225
+ * 404 when the project has never been shared: a link is minted by
1226
+ * `putShareLink`, never as a side effect of reading.
1227
+ */
1228
+ getShareLink(org, name) {
1229
+ return this.json("GET", `${this.projectPath(org, name)}/share`);
1230
+ }
1231
+ /**
1232
+ * Points the share link at a preview, minting the label if there is none.
1233
+ *
1234
+ * Idempotent: the label is kept across shares, so somebody holding the link
1235
+ * keeps working. `rotate` mints a new label and retires the old name in the
1236
+ * same request ("링크 재발급"), so the project never has two live links.
1237
+ */
1238
+ putShareLink(org, name, opts = {}) {
1239
+ return this.json("PUT", `${this.projectPath(org, name)}/share`, {
1240
+ ...(opts.preview === undefined ? {} : { preview: opts.preview }),
1241
+ ...(opts.rotate === undefined ? {} : { rotate: opts.rotate }),
1242
+ });
1243
+ }
1244
+ /** Stops the link answering and forgets the label. The preview keeps running. */
1245
+ deleteShareLink(org, name) {
1246
+ return this.json("DELETE", `${this.projectPath(org, name)}/share`);
1247
+ }
1248
+ /** Idempotent. Called twice, the password is not rolled and the same connection details come back. */
120
1249
  createDatabase(org, name) {
121
1250
  return this.json("POST", `/v1/orgs/${encodeURIComponent(org)}/projects/${encodeURIComponent(name)}/database`);
122
1251
  }
@@ -124,17 +1253,18 @@ export class Client {
124
1253
  return this.json("GET", `/v1/orgs/${encodeURIComponent(org)}/projects/${encodeURIComponent(name)}/database`);
125
1254
  }
126
1255
  /**
127
- * 접속 자격까지. `getDatabase` 와 라우트가 갈린 것은 역할 때문이다 —
128
- * viewer 는 여부를 알아도 되지만 비밀번호는 아니다 (proto/openapi.yaml).
1256
+ * The connection credentials as well. The route is split from `getDatabase`
1257
+ * because of roles — a viewer may know whether there is a database, but not
1258
+ * the password (proto/openapi.yaml).
129
1259
  */
130
1260
  getDatabaseConnect(org, name) {
131
1261
  return this.json("GET", `/v1/orgs/${encodeURIComponent(org)}/projects/${encodeURIComponent(name)}/database/connect`);
132
1262
  }
133
- /** 접속 끝점만 — 자격 없음. viewer 도 받는다. `runlot port-forward` 가 쓴다. */
1263
+ /** The endpoint only — no credentials. A viewer gets it too. Used by `runlot port-forward`. */
134
1264
  getDatabaseEndpoint(org, name) {
135
1265
  return this.json("GET", `${dbPath(org, name)}/endpoint`);
136
1266
  }
137
- /** 단기 기계 자격 발급. 비밀번호는 이 응답에만 실린다. */
1267
+ /** Issues a short-lived machine credential. The password is carried in this response and nowhere else. */
138
1268
  createDatabaseToken(org, name, ttlSeconds) {
139
1269
  return this.json("POST", `${dbPath(org, name)}/tokens`, ttlSeconds === undefined ? {} : { ttlSeconds });
140
1270
  }
@@ -145,59 +1275,111 @@ export class Client {
145
1275
  return this.json("DELETE", `${dbPath(org, name)}/tokens/${encodeURIComponent(user)}`);
146
1276
  }
147
1277
  /**
148
- * 진단 이미지를 하나 만든다.
1278
+ * Makes one diagnostic image.
149
1279
  *
150
- * **멱등이 아니다** — 부를 때마다 이미지가 하나 생긴다. 그리고 느리다:
151
- * 응답은 덤프가 끝난 뒤에 오고, 그동안 그 프로젝트의 액터는 붙잡혀 있다
152
- * (proto/openapi.yaml).
1280
+ * **Not idempotent** — every call makes another image. And it is slow: the
1281
+ * response comes after the dump finishes, and that project's actor is held
1282
+ * for the whole of it (proto/openapi.yaml).
153
1283
  */
154
1284
  exportDatabase(org, name) {
155
1285
  return this.json("POST", `/v1/orgs/${encodeURIComponent(org)}/projects/${encodeURIComponent(name)}/database/export`);
156
1286
  }
157
1287
  /**
158
- * 복원이 고를 수 있는 세대 전부. 최신 순이고, `lastCheckedAt` 은 무변경
159
- * 스킵의 하트비트다 — 세대가 늘지 않는 것과 백업이 죽은 것을 가른다.
1288
+ * Every generation a restore can choose, newest first. `lastCheckedAt` is the
1289
+ * heartbeat of the no-change skip — it is what tells "no new generations"
1290
+ * apart from "the backup is dead".
160
1291
  */
161
1292
  listGenerations(org, name) {
162
1293
  return this.json("GET", `${this.dbPath(org, name)}/generations`);
163
1294
  }
164
1295
  /**
165
- * 세대로 되돌린다. **그 사이의 쓰기는 사라진다.**
1296
+ * Runs one statement in the project's database (the dashboard console).
1297
+ *
1298
+ * `readOnly` is **omitted, not sent as false**, when the caller wants the safe
1299
+ * mode: the server treats an absent field as read-only, so leaving it out is the
1300
+ * one spelling that cannot be misread. Sending `false` is the explicit ask for
1301
+ * write mode, and only then does the server run outside a transaction.
166
1302
  *
167
- * 202 로 끝난다 — 돌아오는 것은 연산 id 이고, 진행은
168
- * `getDatabaseOperation` 으로 본다. `latest` 는 서버가 풀지 않는다:
169
- * 목록에서 고른 `(epoch, seq)` 를 그대로 싣는다 (proto/openapi.yaml).
1303
+ * SQL failures arrive as an `ApiError` whose body carries `details.sqlstate` —
1304
+ * PostgreSQL's own code, which is what the error panel shows.
1305
+ */
1306
+ executeSQL(org, name, sql, opts = {}) {
1307
+ const body = { sql };
1308
+ if (opts.readOnly === false)
1309
+ body.readOnly = false;
1310
+ if (opts.params !== undefined && opts.params.length > 0)
1311
+ body.params = opts.params;
1312
+ return this.json("POST", `${this.dbPath(org, name)}/execute`, body);
1313
+ }
1314
+ /**
1315
+ * Rolls back to a generation. **Writes made since then are lost.**
1316
+ *
1317
+ * It ends at 202 — what comes back is an operation id, and progress is read
1318
+ * through `getDatabaseOperation`. The server does not resolve `latest`: the
1319
+ * `(epoch, seq)` chosen from the list is carried as-is (proto/openapi.yaml).
170
1320
  */
171
1321
  restoreDatabase(org, name, epoch, seq) {
172
1322
  return this.json("POST", `${this.dbPath(org, name)}/restore`, { epoch, seq });
173
1323
  }
174
1324
  /**
175
- * 데이터베이스를 없앤다. `confirm` 은 프로젝트 이름과 **정확히** 같아야
176
- * 하고, 다르면 서버가 400 `confirm_mismatch` 로 거절한다.
1325
+ * Rolls back to a restore point **inside** a backup (pg-feather docs/37):
1326
+ * `txnId` is that commit, `at` is the last commit at or before that time. One
1327
+ * backup carries the commits in between in order, so the place you can roll
1328
+ * back to is not tied to a backup boundary. Everything else is as in
1329
+ * restoreDatabase — 202, an operation id, and one safety backup before the
1330
+ * rollback.
1331
+ */
1332
+ restoreDatabaseTo(org, name, target) {
1333
+ return this.json("POST", `${this.dbPath(org, name)}/restore`, target);
1334
+ }
1335
+ /**
1336
+ * Removes the database. `confirm` has to match the project name **exactly**;
1337
+ * if it does not, the server refuses with 400 `confirm_mismatch`.
177
1338
  */
178
1339
  deleteDatabase(org, name, confirm) {
179
1340
  return this.json("POST", `${this.dbPath(org, name)}/delete`, { confirm });
180
1341
  }
181
- /** 연산 하나의 진행. 연산 id 는 자격이 아니라 프로젝트 경로 아래에 있다. */
1342
+ /** The progress of one operation. The operation id is not a credential; it lives under the project path. */
182
1343
  getDatabaseOperation(org, name, opId) {
183
1344
  return this.json("GET", `${this.dbPath(org, name)}/operations/${encodeURIComponent(opId)}`);
184
1345
  }
185
- /** 되돌릴 수 없는 phase 앞의 연산을 중단한다. */
1346
+ /** Aborts an operation that has not yet reached a phase it cannot come back from. */
186
1347
  abortDatabaseOperation(org, name, opId) {
187
1348
  return this.json("POST", `${this.dbPath(org, name)}/operations/${encodeURIComponent(opId)}/abort`);
188
1349
  }
189
1350
  // ---- Phase 6 (docs/phase6.md) ----
190
1351
  /**
191
- * 로그 라이브 테일. **JSON 이 아니라 스트림**이라 `request` 를 안 지난다 —
192
- * 돌려주는 것은 줄 단위 `LogEvent` 의 async iterable 이고, `signal` 을 abort
193
- * 하면 연결이 끊긴다. 오류 응답(4xx/5xx)은 다른 메서드와 같은 `ApiError` 다.
1352
+ * A live tail of the logs. It is **a stream, not JSON**, so it does not go
1353
+ * through `request` — what comes back is an async iterable of line-by-line
1354
+ * `LogEvent`, and aborting `signal` closes the connection. An error response
1355
+ * (4xx/5xx) is the same `ApiError` as in every other method.
194
1356
  */
195
1357
  async *tailLogs(org, name, opts = {}) {
1358
+ yield* this.tailStream(org, name, opts, undefined);
1359
+ }
1360
+ /**
1361
+ * The live tail as `LogRecord`s — the stored event's shape (`--format json`).
1362
+ * Pings and the end event still arrive as `LogEvent`s.
1363
+ */
1364
+ async *tailLogRecords(org, name, opts = {}) {
1365
+ yield* this.tailStream(org, name, opts, "json");
1366
+ }
1367
+ async *tailStream(org, name, opts, format) {
196
1368
  const q = new URLSearchParams();
197
1369
  if (opts.tail !== undefined)
198
1370
  q.set("tail", String(opts.tail));
199
1371
  if (opts.follow !== undefined)
200
1372
  q.set("follow", String(opts.follow));
1373
+ if (opts.level)
1374
+ q.set("level", opts.level);
1375
+ if (opts.source)
1376
+ q.set("source", opts.source);
1377
+ if (opts.q)
1378
+ q.set("q", opts.q);
1379
+ if (opts.requestId)
1380
+ q.set("requestId", opts.requestId);
1381
+ if (format)
1382
+ q.set("format", format);
201
1383
  const path = `${this.projectPath(org, name)}/logs${q.size ? `?${q}` : ""}`;
202
1384
  const res = await fetch(new URL(path, this.opts.baseUrl), {
203
1385
  method: "GET",
@@ -210,7 +1392,7 @@ export class Client {
210
1392
  body = (await res.json());
211
1393
  }
212
1394
  catch {
213
- // 위의 request 와 같은 이유.
1395
+ // The same reason as in request above.
214
1396
  }
215
1397
  throw new ApiError(res.status, body, `GET ${path} → ${res.status}`);
216
1398
  }
@@ -238,14 +1420,35 @@ export class Client {
238
1420
  yield JSON.parse(rest);
239
1421
  }
240
1422
  finally {
241
- // 소비자가 일찍 끝내면(break) 서버 쪽 follow 도 끝나야 한다.
1423
+ // If the consumer ends early (break), the server's follow has to end too.
242
1424
  await reader.cancel().catch(() => { });
243
1425
  }
244
1426
  }
1427
+ /**
1428
+ * The stored lane (0062). It is a plain JSON page, not a stream: the history
1429
+ * does not reach a node, so it answers for a project that is cold, parked, or
1430
+ * has moved since the lines were written — every one of which is a 409 on
1431
+ * `tailLogs`.
1432
+ *
1433
+ * `q` is a plain substring, matched case-insensitively. It is not a regular
1434
+ * expression — `%` and `_` match themselves.
1435
+ *
1436
+ * Paging is keyset: pass the `cursor` from a page back to get the next, older
1437
+ * one. A page with no `cursor` is the end of what is kept.
1438
+ */
1439
+ getLogHistory(org, name, opts = {}) {
1440
+ const params = new URLSearchParams();
1441
+ for (const [k, v] of Object.entries(opts)) {
1442
+ if (v !== undefined && v !== "")
1443
+ params.set(k, String(v));
1444
+ }
1445
+ const qs = params.size ? `?${params}` : "";
1446
+ return this.json("GET", `${this.projectPath(org, name)}/logs/history${qs}`);
1447
+ }
245
1448
  listSecrets(org, name) {
246
1449
  return this.json("GET", `${this.projectPath(org, name)}/secrets`);
247
1450
  }
248
- /** 값은 이 호출로만 나간다. 어떤 응답에도 값은 없다. */
1451
+ /** The value travels in this call only. It is in no response at all. */
249
1452
  setSecret(org, name, secret, value) {
250
1453
  return this.json("PUT", `${this.projectPath(org, name)}/secrets/${encodeURIComponent(secret)}`, { value });
251
1454
  }
@@ -256,111 +1459,438 @@ export class Client {
256
1459
  const q = hours === undefined ? "" : `?hours=${hours}`;
257
1460
  return this.json("GET", `${this.projectPath(org, name)}/usage${q}`);
258
1461
  }
259
- // ---- 오브젝트 스토리지 (docs/storage.md §8) ----
260
- /** 부여 여부·접두·쿼터·사용량. `usedBytes` 는 노드 보고 주기만큼 늦다. */
1462
+ // ---- Object storage (docs/storage.md §8) ----
1463
+ /** Grant, prefix, quota, usage. `usedBytes` lags by the node's reporting interval. */
261
1464
  getStorage(org, name) {
262
1465
  return this.json("GET", `${this.projectPath(org, name)}/storage`);
263
1466
  }
264
1467
  /**
265
- * 스토리지를 부여한다. 멱등이라 두 번 눌러도 접두는 그대로다. 접두·쿼터를
266
- * 인자로 받지 않는 것이 요점이다 — 접두는 격리의 경계이고 쿼터는 요금제가
267
- * 정한다 (proto/openapi.yaml).
1468
+ * Grants storage. It is idempotent, so pressing twice leaves the prefix as it
1469
+ * was. Taking neither the prefix nor the quota as an argument is the point —
1470
+ * the prefix is the isolation boundary and the quota is set by the plan
1471
+ * (proto/openapi.yaml).
268
1472
  */
269
1473
  grantStorage(org, name) {
270
1474
  return this.json("POST", `${this.projectPath(org, name)}/storage`);
271
1475
  }
272
- /** 부여를 뗀다. **객체는 지워지지 않는다** (docs/storage.md §7). */
1476
+ /** Removes the grant. **The objects are not deleted** (docs/storage.md §7). */
273
1477
  revokeStorage(org, name) {
274
1478
  return this.json("DELETE", `${this.projectPath(org, name)}/storage`);
275
1479
  }
276
- // ---- 최종 사용자 인증 (docs/auth.md §9) ----
277
1480
  /**
278
- * 부여 여부·설정·프로바이더·호스트. **가입자는 안 온다** — 그 표는 프로젝트
279
- * DB 안이고 (docs/auth.md §6) 워커의 `env.auth` 만 본다.
1481
+ * The key prefixes this project serves unsigned (docs/storage.md §4.7).
1482
+ *
1483
+ * A prefix is stored normalized — `assets` becomes `assets/`, and `/` becomes
1484
+ * the empty string, which means every key. The value that comes back is the
1485
+ * value that governs, so a screen must render the response rather than what
1486
+ * the user typed.
1487
+ */
1488
+ listStoragePublic(org, name) {
1489
+ return this.json("GET", `${this.projectPath(org, name)}/storage/public`);
1490
+ }
1491
+ /** Publishes a prefix. Idempotent. All three verbs answer with the whole list. */
1492
+ addStoragePublic(org, name, prefix) {
1493
+ return this.json("POST", `${this.projectPath(org, name)}/storage/public`, { prefix });
1494
+ }
1495
+ /**
1496
+ * Unpublishes a prefix. Idempotent.
280
1497
  *
281
- * `providers` 에는 client id 만 있다. 클라이언트 시크릿은 봉인돼 어느
282
- * 응답에도 안 나온다.
1498
+ * **The world keeps reading for up to a minute.** The object front caches the
1499
+ * list, so this call is not a revocation that takes effect at the instant it
1500
+ * returns — a screen that says "no longer public" the moment this resolves is
1501
+ * telling a small lie.
1502
+ */
1503
+ removeStoragePublic(org, name, prefix) {
1504
+ return this.json("DELETE", `${this.projectPath(org, name)}/storage/public`, { prefix });
1505
+ }
1506
+ /**
1507
+ * One page of objects grouped by `/` (`runlot storage ls`). `prefixes` are the
1508
+ * folders one level down; feed `cursor` back unchanged, its absence is the end.
1509
+ */
1510
+ listStorageObjects(org, name, opts = {}) {
1511
+ const q = new URLSearchParams();
1512
+ if (opts.prefix)
1513
+ q.set("prefix", opts.prefix);
1514
+ if (opts.cursor)
1515
+ q.set("cursor", opts.cursor);
1516
+ if (opts.limit)
1517
+ q.set("limit", String(opts.limit));
1518
+ const qs = q.toString();
1519
+ return this.json("GET", `${this.projectPath(org, name)}/storage/objects${qs ? "?" + qs : ""}`);
1520
+ }
1521
+ /**
1522
+ * A five-minute signed GET for one object (`runlot storage download`). The key's
1523
+ * `/` segments stay in the path; each segment is encoded on its own.
1524
+ */
1525
+ signStorageObject(org, name, key) {
1526
+ const path = key.split("/").map(encodeURIComponent).join("/");
1527
+ return this.json("GET", `${this.projectPath(org, name)}/storage/objects/${path}`);
1528
+ }
1529
+ // ---- Email (docs/email.md §5) ----
1530
+ /** Grant, address, sender, limits, recent counts. The address comes back as a preview even without a grant. */
1531
+ getEmail(org, name) {
1532
+ return this.json("GET", `${this.projectPath(org, name)}/email`);
1533
+ }
1534
+ /** Turns it on. **Idempotent** — we choose the address. The deploy reads `"email": true` and calls this. */
1535
+ grantEmail(org, name) {
1536
+ return this.json("POST", `${this.projectPath(org, name)}/email`);
1537
+ }
1538
+ /** Turns it off. Mail arriving at that address now gets a 550. */
1539
+ revokeEmail(org, name) {
1540
+ return this.json("DELETE", `${this.projectPath(org, name)}/email`);
1541
+ }
1542
+ // ---- Custom sending domains (docs/email.md §2.4) ----
1543
+ /** The project's own sending domains, each with the records to publish. */
1544
+ listEmailDomains(org, name) {
1545
+ return this.json("GET", `${this.projectPath(org, name)}/email/domains`);
1546
+ }
1547
+ /**
1548
+ * Creates the provider identity and answers with the records to publish.
1549
+ * `publish` writes them into the zone when we host one covering the domain.
1550
+ */
1551
+ addEmailDomain(org, name, domain, publish = false) {
1552
+ return this.json("POST", `${this.projectPath(org, name)}/email/domains`, { domain, publish });
1553
+ }
1554
+ /** Re-checks now. The background loop does the same once a minute while pending. */
1555
+ verifyEmailDomain(org, name, domain) {
1556
+ return this.json("POST", `${this.projectPath(org, name)}/email/domains/${encodeURIComponent(domain)}/verify`);
1557
+ }
1558
+ /** Deletes the identity and the row. Sending from it is refused from the next convergence. */
1559
+ removeEmailDomain(org, name, domain) {
1560
+ return this.json("DELETE", `${this.projectPath(org, name)}/email/domains/${encodeURIComponent(domain)}`);
1561
+ }
1562
+ // ---- AI (docs/ai.md §6) ----
1563
+ /**
1564
+ * The model catalogue. **Being logged in is enough to see it** — what you can
1565
+ * buy is not an organization's secret, and this list is the price table.
1566
+ *
1567
+ * Prices are integer **micro-cents** per million tokens (1 µ¢ = 1e-8 USD).
1568
+ * Not letting the server pick the decimal place is the point — a small call
1569
+ * rounded to cents becomes 0.
1570
+ */
1571
+ listAIModels() {
1572
+ return this.json("GET", "/v1/ai/models");
1573
+ }
1574
+ /** Grant, limits, the org balance, 24 h usage. The limits come back as a preview even without a grant. */
1575
+ getAI(org, name) {
1576
+ return this.json("GET", `${this.projectPath(org, name)}/ai`);
1577
+ }
1578
+ /** Turns it on. **Idempotent.** The deploy reads `"ai": true` and calls this. */
1579
+ grantAI(org, name) {
1580
+ return this.json("POST", `${this.projectPath(org, name)}/ai`);
1581
+ }
1582
+ /**
1583
+ * Lends the org's own Claude/Codex subscriptions to this project's
1584
+ * `anthropic/*` and `openai/*` calls (docs/studio-byos-ai.md §3.1).
1585
+ *
1586
+ * **Omitting a field leaves it as it was**, so turning lending on does not
1587
+ * clear a fallback that was already set. Admin only: the subscription that
1588
+ * carries the vendor-terms risk belongs to a person, not to the org.
1589
+ */
1590
+ patchAI(org, name, body) {
1591
+ return this.json("PATCH", `${this.projectPath(org, name)}/ai`, body);
1592
+ }
1593
+ /** Turns it off. **The ledger and the balance are untouched** — the balance belongs to the org and the grant belongs to the project. */
1594
+ revokeAI(org, name) {
1595
+ return this.json("DELETE", `${this.projectPath(org, name)}/ai`);
1596
+ }
1597
+ /** The org's credit balance and its automatic top-up settings. The balance is in micro-cents and can be negative. */
1598
+ getAICredit(org) {
1599
+ return this.json("GET", `/v1/orgs/${encodeURIComponent(org)}/ai/credit`);
1600
+ }
1601
+ /**
1602
+ * One page of this project's AI calls, newest first (docs/ai-observability.md §6.1).
1603
+ * `before` is the previous page's opaque `nextBefore`.
1604
+ */
1605
+ listAICalls(org, name, opts = {}) {
1606
+ const q = new URLSearchParams();
1607
+ for (const [k, v] of Object.entries(opts)) {
1608
+ if (v !== undefined && v !== "")
1609
+ q.set(k, String(v));
1610
+ }
1611
+ const qs = q.toString();
1612
+ return this.json("GET", `${this.projectPath(org, name)}/ai/calls${qs ? "?" + qs : ""}`);
1613
+ }
1614
+ /** One AI call; the input and output ride only for a reader with observability:pii. */
1615
+ getAICall(org, name, callId) {
1616
+ return this.json("GET", `${this.projectPath(org, name)}/ai/calls/${encodeURIComponent(callId)}`);
1617
+ }
1618
+ /** AI calls over time, by model, and the reasons lending did not serve (§6.3). */
1619
+ getAISummary(org, name, opts = {}) {
1620
+ const q = new URLSearchParams();
1621
+ if (opts.from)
1622
+ q.set("from", opts.from);
1623
+ if (opts.to)
1624
+ q.set("to", opts.to);
1625
+ const qs = q.toString();
1626
+ return this.json("GET", `${this.projectPath(org, name)}/ai/summary${qs ? "?" + qs : ""}`);
1627
+ }
1628
+ /** AI calls grouped by the app's `metadata.sessionId` (§6.4). */
1629
+ listAISessions(org, name, opts = {}) {
1630
+ const q = new URLSearchParams();
1631
+ for (const [k, v] of Object.entries(opts)) {
1632
+ if (v !== undefined && v !== "")
1633
+ q.set(k, String(v));
1634
+ }
1635
+ const qs = q.toString();
1636
+ return this.json("GET", `${this.projectPath(org, name)}/ai/sessions${qs ? "?" + qs : ""}`);
1637
+ }
1638
+ /** The org members' desktops that can lend to this project right now (§6.5). */
1639
+ getAILenders(org, name) {
1640
+ return this.json("GET", `${this.projectPath(org, name)}/ai/lenders`);
1641
+ }
1642
+ /** Whether this project records prompts and answers (§5). */
1643
+ getAICapture(org, name) {
1644
+ return this.json("GET", `${this.projectPath(org, name)}/ai/capture`);
1645
+ }
1646
+ /** Turns prompt capture on or off. observability:admin; audited. */
1647
+ setAICapture(org, name, captureBodies) {
1648
+ return this.json("PUT", `${this.projectPath(org, name)}/ai/capture`, { captureBodies });
1649
+ }
1650
+ /** One page of the org ledger. The cursor is `ledger_id` — cutting on time splits the same millisecond. */
1651
+ listAILedger(org, opts = {}) {
1652
+ const q = new URLSearchParams();
1653
+ if (opts.limit)
1654
+ q.set("limit", String(opts.limit));
1655
+ if (opts.before)
1656
+ q.set("before", String(opts.before));
1657
+ if (opts.kind)
1658
+ q.set("kind", opts.kind);
1659
+ if (opts.since)
1660
+ q.set("since", opts.since);
1661
+ const qs = q.toString();
1662
+ return this.json("GET", `/v1/orgs/${encodeURIComponent(org)}/ai/ledger${qs ? "?" + qs : ""}`);
1663
+ }
1664
+ /**
1665
+ * The credit top-up checkout. **A browser coming back is not evidence** — the
1666
+ * one thing that raises the balance is the `order.paid` webhook, and the
1667
+ * screen polls the balance after the success event.
1668
+ */
1669
+ createAICreditCheckout(org, microCents, returnTo) {
1670
+ return this.json("POST", `/v1/orgs/${encodeURIComponent(org)}/ai/credit/checkout`, { microCents, returnTo });
1671
+ }
1672
+ /**
1673
+ * Turns automatic top-up on or off. **Turning it on is explicit consent**
1674
+ * (docs/ai.md §3.5) — the screen shows the charging terms verbatim and calls
1675
+ * this only after the box is checked.
1676
+ */
1677
+ setAIAutoTopup(org, body) {
1678
+ return this.json("PUT", `/v1/orgs/${encodeURIComponent(org)}/ai/autotopup`, body);
1679
+ }
1680
+ /** One page of the mail log (docs/email.md §6.1). Newest first, cursor-paged. */
1681
+ listMailLog(org, name, opts = {}) {
1682
+ const q = new URLSearchParams();
1683
+ if (opts.direction)
1684
+ q.set("direction", opts.direction);
1685
+ if (opts.cursor)
1686
+ q.set("cursor", opts.cursor);
1687
+ if (opts.limit)
1688
+ q.set("limit", String(opts.limit));
1689
+ const qs = q.toString();
1690
+ return this.json("GET", `${this.projectPath(org, name)}/email/log${qs ? "?" + qs : ""}`);
1691
+ }
1692
+ /** The metadata of one message. */
1693
+ getMailLog(org, name, mailId) {
1694
+ return this.json("GET", `${this.projectPath(org, name)}/email/log/${encodeURIComponent(mailId)}`);
1695
+ }
1696
+ /** The URL of the raw message — the screen uses it as a download link (.eml). */
1697
+ mailLogRawURL(org, name, mailId) {
1698
+ return new URL(`${this.projectPath(org, name)}/email/log/${encodeURIComponent(mailId)}/raw`, this.opts.baseUrl).toString();
1699
+ }
1700
+ /** The raw text. What the detail view draws the headers and body from. */
1701
+ getMailLogRaw(org, name, mailId) {
1702
+ return this.text("GET", `${this.projectPath(org, name)}/email/log/${encodeURIComponent(mailId)}/raw`);
1703
+ }
1704
+ // ---- End-user authentication (docs/auth.md §9) ----
1705
+ /**
1706
+ * Grant, settings, providers, hosts. **The signed-up users do not come** —
1707
+ * that table is inside the project DB (docs/auth.md §6) and only the worker's
1708
+ * `env.auth` sees it.
1709
+ *
1710
+ * `providers` carries the client id only. The client secret is sealed and
1711
+ * appears in no response.
283
1712
  */
284
1713
  getAuth(org, name) {
285
1714
  return this.json("GET", `${this.projectPath(org, name)}/auth`);
286
1715
  }
287
1716
  /**
288
- * 인증을 켠다 (member). 멱등이다.
1717
+ * Turns auth on (member). Idempotent.
289
1718
  *
290
- * **데이터베이스가 없으면 409 `database_required`** 다 — 가입자 표가
291
- * 프로젝트 DB 안이라 부여만 세우면 워커가 뜨는 순간 표가 없다. 부르는 쪽은
292
- * 그 코드를 잡아 `runlot pg create` 를 안내한다.
1719
+ * **With no database it is 409 `database_required`** — the user table lives
1720
+ * inside the project DB, so standing up the grant alone leaves no table the
1721
+ * moment the worker starts. The caller catches that code and points at the
1722
+ * `"database": true` declaration — the deploy never sees this code, because
1723
+ * its ordering rules it out.
293
1724
  */
294
1725
  grantAuth(org, name) {
295
1726
  return this.json("POST", `${this.projectPath(org, name)}/auth`);
296
1727
  }
297
1728
  /**
298
- * 설정을 바꾼다 (member). **부분 갱신이다** — 준 칸만 바뀐다. 스위치 하나에
299
- * 전체를 실어 보내면 두 사람이 같은 카드를 만질 때 나중 저장이 앞 저장을
300
- * 덮는다. 부여가 없으면 404 `not_granted`.
1729
+ * The app's end users, newest first (`runlot auth users`). Read-only, and read
1730
+ * from the project's own database — a parked or unreachable one answers 502/504.
1731
+ * Feed `cursor` back unchanged; its absence is the end.
1732
+ */
1733
+ listAppUsers(org, name, opts = {}) {
1734
+ const q = new URLSearchParams();
1735
+ if (opts.search)
1736
+ q.set("search", opts.search);
1737
+ if (opts.cursor)
1738
+ q.set("cursor", opts.cursor);
1739
+ if (opts.limit)
1740
+ q.set("limit", String(opts.limit));
1741
+ const qs = q.toString();
1742
+ return this.json("GET", `${this.projectPath(org, name)}/auth/users${qs ? "?" + qs : ""}`);
1743
+ }
1744
+ /**
1745
+ * One `env.ai.run` on the development lane: catalog models, the free plan's caps,
1746
+ * the org's credit, recorded as `lane = dev`. One JSON answer, no streaming.
1747
+ */
1748
+ devAIRun(org, name, body) {
1749
+ return this.json("POST", `${this.projectPath(org, name)}/ai/dev/run`, body);
1750
+ }
1751
+ /**
1752
+ * Changes the settings (member). **A partial update** — only the fields given
1753
+ * change. Sending the whole thing on one switch means that when two people
1754
+ * touch the same card, the later save overwrites the earlier one. With no
1755
+ * grant it is 404 `not_granted`.
301
1756
  */
302
1757
  updateAuthSettings(org, name, settings) {
303
1758
  return this.json("PATCH", `${this.projectPath(org, name)}/auth`, { settings });
304
1759
  }
305
1760
  /**
306
- * 인증을 해제한다 (admin). **가입자는 안 지워진다** — `runlot_auth` 의 표는
307
- * 프로젝트 DB 에 남고, 다시 켜면 같은 사람들이 그대로 로그인한다.
1761
+ * Turns auth off (admin). **The signed-up users are not deleted** — the
1762
+ * `runlot_auth` tables stay in the project DB, and turning it back on lets the
1763
+ * same people log in unchanged.
308
1764
  */
309
1765
  revokeAuth(org, name) {
310
1766
  return this.json("DELETE", `${this.projectPath(org, name)}/auth`);
311
1767
  }
312
1768
  /**
313
- * 소셜 프로바이더를 등록하거나 교체한다 (admin). 같은 PUT 이라 멱등이다.
1769
+ * Registers or replaces a social provider (admin). It is the same PUT, so it
1770
+ * is idempotent.
314
1771
  *
315
- * **`clientSecret` 은 다시 볼 수 없다.** 콜백 URL 은 호스트마다
316
- * `https://<host>/__runlot/auth/callback/<provider>` 이고, 호스트 목록은
317
- * 응답의 `hosts` 에 있다.
1772
+ * **`clientSecret` cannot be read back.** The callback URL is
1773
+ * `https://<host>/__runlot/auth/callback/<provider>` for each host, and the
1774
+ * list of hosts is in the response's `hosts`.
1775
+ *
1776
+ * `issuer` is the base URL of your own GitHub Enterprise Server installation,
1777
+ * and only `github` takes one. **This PUT is the whole row** — the same reason
1778
+ * `clientSecret` has to be sent every time — so an empty string clears it and
1779
+ * puts that provider back on github.com. The key is left out entirely when the
1780
+ * argument is omitted, so a caller that does not know about issuers sends the
1781
+ * body it always sent.
1782
+ */
1783
+ setAuthProvider(org, name, provider, clientId, clientSecret, issuer) {
1784
+ return this.json("PUT", `${this.projectPath(org, name)}/auth/providers/${encodeURIComponent(provider)}`, { clientId, clientSecret, ...(issuer === undefined ? {} : { issuer }) });
1785
+ }
1786
+ /**
1787
+ * Turns on the Runlot provider (admin): "Continue with Runlot", with email,
1788
+ * Google and GitHub at Runlot behind it and nothing to register. 409
1789
+ * `runlot_unavailable` when this deployment has no sign-in broker.
1790
+ */
1791
+ setRunlotAuthProvider(org, name) {
1792
+ return this.json("PUT", `${this.projectPath(org, name)}/auth/providers/runlot`, { kind: "runlot" });
1793
+ }
1794
+ /**
1795
+ * Registers or replaces a generic OIDC provider under a project-chosen id
1796
+ * (admin). The CP reads `<issuer>/.well-known/openid-configuration` when
1797
+ * saving; a failure is 400 `oidc_discovery_failed` quoting the provider.
1798
+ */
1799
+ setOidcAuthProvider(org, name, id, body) {
1800
+ return this.json("PUT", `${this.projectPath(org, name)}/auth/providers/${encodeURIComponent(id)}`, { kind: "oidc", ...body });
1801
+ }
1802
+ /**
1803
+ * The statements that create the `runlot_auth` schema (member). 404 when
1804
+ * login is not turned on for the project.
318
1805
  */
319
- setAuthProvider(org, name, provider, clientId, clientSecret) {
320
- return this.json("PUT", `${this.projectPath(org, name)}/auth/providers/${encodeURIComponent(provider)}`, { clientId, clientSecret });
1806
+ getAuthSchema(org, name) {
1807
+ return this.json("GET", `${this.projectPath(org, name)}/auth/schema`);
1808
+ }
1809
+ /** The project's sign-in branding with defaults filled (docs/custom-sign-in.md §12.3). */
1810
+ getAuthBranding(org, name) {
1811
+ return this.getAuthBrandingAnswer(org, name).then((a) => a.brand);
1812
+ }
1813
+ /** The GET answer whole: the filled brand plus the methods the chooser would draw now. */
1814
+ getAuthBrandingAnswer(org, name) {
1815
+ return this.json("GET", `${this.projectPath(org, name)}/auth/branding`);
1816
+ }
1817
+ /**
1818
+ * Replaces the whole branding object (member). Validated server-side; a bad
1819
+ * field is 400 `invalid_branding` with `fields: [{path, message}]`.
1820
+ */
1821
+ putAuthBranding(org, name, branding) {
1822
+ return this.json("PUT", `${this.projectPath(org, name)}/auth/branding`, branding)
1823
+ .then((a) => a.brand);
1824
+ }
1825
+ /**
1826
+ * The URL of the rendered chooser with (draft) branding (§12.4). A page, not
1827
+ * JSON: the dashboard puts it in an iframe and the CLI opens it in a browser.
1828
+ * `draft` travels as base64url JSON.
1829
+ */
1830
+ authBrandingPreviewUrl(org, name, opts = {}) {
1831
+ const u = new URL(`${this.projectPath(org, name)}/auth/branding/preview`, this.opts.baseUrl);
1832
+ if (opts.lang)
1833
+ u.searchParams.set("lang", opts.lang);
1834
+ if (opts.theme)
1835
+ u.searchParams.set("theme", opts.theme);
1836
+ if (opts.state)
1837
+ u.searchParams.set("state", opts.state);
1838
+ if (opts.draft)
1839
+ u.searchParams.set("draft", base64urlJson(opts.draft));
1840
+ return u.toString();
1841
+ }
1842
+ /** Sign-in funnel counters for the last `days` days (§9.4). No per-person data. */
1843
+ getAuthFunnel(org, name, days = 30) {
1844
+ return this.json("GET", `${this.projectPath(org, name)}/auth/funnel?days=${encodeURIComponent(String(days))}`);
321
1845
  }
322
1846
  /**
323
- * 프로바이더를 뗀다 (admin). 그 프로바이더로만 가입한 사람은 로그인할 길을
324
- * 잃지만 사용자 행은 남는다 — 다시 등록하면 같은 계정으로 돌아온다.
1847
+ * Removes a provider (admin). Someone who signed up only through that provider
1848
+ * loses their way in, but the user row stays — register it again and they come
1849
+ * back to the same account.
325
1850
  */
326
1851
  deleteAuthProvider(org, name, provider) {
327
1852
  return this.json("DELETE", `${this.projectPath(org, name)}/auth/providers/${encodeURIComponent(provider)}`);
328
1853
  }
329
- // ---- 배포 접근 제어 (docs/access.md §7) ----
1854
+ // ---- Deployment access control (docs/access.md §7) ----
330
1855
  /**
331
- * 이 배포에 누가 닿을 수 있는가. **값은 없다** — 비밀번호도 우회 시크릿도
332
- * 해시로만 살고, 여기 오는 것은 `hasPassword`·`hasBypass` 라는 사실이다.
1856
+ * Who can reach this deployment. **No values** — both the password and the
1857
+ * bypass secret live only as hashes, and what comes back here is the fact that
1858
+ * there is one: `hasPassword` and `hasBypass`.
333
1859
  *
334
- * 정책을 한 번도 안 정한 프로젝트는 `mode: "public"` 에 `updatedAt` 이
335
- * 없다. 화면이 그 둘을 가르는 이유는 §7 — 빈 상태 대신 상태 문장이다.
1860
+ * A project that has never set a policy is `mode: "public"` with no
1861
+ * `updatedAt`. The screen tells those two apart for the reason in §7 — a
1862
+ * sentence about the state instead of an empty state.
336
1863
  */
337
1864
  getAccess(org, name) {
338
1865
  return this.json("GET", `${this.projectPath(org, name)}/access`);
339
1866
  }
340
1867
  /**
341
- * 정책을 바꾼다 (admin). `password` 를 안 보내면 **있던 비밀번호가 남는다** —
342
- * 모드만 바꾸는 저장이 비밀번호를 지우면 되돌아왔을 때 다시 정해야 한다.
1868
+ * Changes the policy (admin). Without a `password`, **the existing password
1869
+ * stays** — if a save that only changes the mode wiped the password, coming
1870
+ * back to that mode would mean setting it again.
343
1871
  */
344
1872
  setAccess(org, name, mode, password) {
345
1873
  return this.json("PUT", `${this.projectPath(org, name)}/access`, { mode, password });
346
1874
  }
347
1875
  /**
348
- * 자동화 우회 시크릿을 만든다 (admin). **값은 이 답에만 있다** — 화면은
349
- * 받은 즉시 한 번 보여주고 다시 못 가져온다. 다시 부르면 옛 값이 죽는다.
1876
+ * Makes a bypass secret for automation (admin). **The value is in this answer
1877
+ * and nowhere else** — the screen shows it once on arrival and can never fetch
1878
+ * it again. Calling again kills the old value.
350
1879
  */
351
1880
  newAccessBypass(org, name) {
352
1881
  return this.json("POST", `${this.projectPath(org, name)}/access/bypass`);
353
1882
  }
354
- /** 우회를 뗀다 (admin). 없는 우회를 떼는 것도 성공이다. */
1883
+ /** Removes the bypass (admin). Removing one that does not exist also succeeds. */
355
1884
  revokeAccessBypass(org, name) {
356
1885
  return this.json("DELETE", `${this.projectPath(org, name)}/access/bypass`);
357
1886
  }
358
1887
  /**
359
- * 보호된 배포로 돌아가는 1 회용 주소를 받는다 (docs/access.md §3.4-3).
1888
+ * Gets a one-time address back into a protected deployment (docs/access.md §3.4-3).
360
1889
  *
361
- * 프로젝트 경로 아래가 **아니다**: 부르는 화면이 아는 것은 호스트네임뿐이고
362
- * (원 요청이 그리로 갔다), org·프로젝트 이름은 서버가 그것에서 유도한다.
363
- * 받은 `redirect` 로 `location.replace` 하는 것이 호출부의 일이다.
1890
+ * It is **not** under the project path: all the calling screen knows is the
1891
+ * hostname (the original request went there), and the server derives the org
1892
+ * and project names from it. Doing `location.replace` with the `redirect` that
1893
+ * comes back is the caller's job.
364
1894
  */
365
1895
  authorizeAccess(to, next) {
366
1896
  return this.json("POST", "/v1/access/authorize", { to, next });
@@ -368,44 +1898,79 @@ export class Client {
368
1898
  listMembers(org) {
369
1899
  return this.json("GET", `/v1/orgs/${encodeURIComponent(org)}/members`);
370
1900
  }
371
- /** 초대가 아니다 — 사용자는 이미 한 번 로그인해 있어야 한다 (404 `user_not_found`). */
1901
+ /** This is not an invite — the user must already have logged in once (404 `user_not_found`). */
372
1902
  addMember(org, provider, subject, role) {
373
1903
  return this.json("POST", `/v1/orgs/${encodeURIComponent(org)}/members`, { provider, subject, role });
374
1904
  }
375
1905
  setMemberRole(org, userId, role) {
376
1906
  return this.json("PUT", `/v1/orgs/${encodeURIComponent(org)}/members/${encodeURIComponent(userId)}`, { role });
377
1907
  }
1908
+ /**
1909
+ * Removing someone else is admin; **removing yourself is leaving**, which
1910
+ * anyone can do (docs/members.md). The last admin can do neither
1911
+ * (409 `last_admin`).
1912
+ */
378
1913
  removeMember(org, userId) {
379
1914
  return this.json("DELETE", `/v1/orgs/${encodeURIComponent(org)}/members/${encodeURIComponent(userId)}`);
380
1915
  }
1916
+ // --- Invites (docs/members.md) ---
1917
+ /** Pending and expired invites (admin). Accepted and revoked ones are history, so they do not come. */
1918
+ listInvites(org) {
1919
+ return this.json("GET", `/v1/orgs/${encodeURIComponent(org)}/invites`);
1920
+ }
1921
+ /**
1922
+ * Invites by email (admin). **Calling again with the same address is a
1923
+ * resend** — the same row is updated rather than a new one created, and the
1924
+ * server gives 200 instead of 201.
1925
+ */
1926
+ createInvite(org, email, role) {
1927
+ return this.json("POST", `/v1/orgs/${encodeURIComponent(org)}/invites`, { email, role });
1928
+ }
1929
+ /** Revokes an invite (admin). Mail that has not gone out yet does not go out. */
1930
+ revokeInvite(org, inviteId) {
1931
+ return this.json("DELETE", `/v1/orgs/${encodeURIComponent(org)}/invites/${encodeURIComponent(inviteId)}`);
1932
+ }
1933
+ /**
1934
+ * A preview of the invite. **No session needed** — whoever got the link has
1935
+ * not logged in yet, and they need to know what they are accepting before
1936
+ * they do.
1937
+ */
1938
+ getInvite(token) {
1939
+ return this.json("GET", `/v1/invites/${encodeURIComponent(token)}`);
1940
+ }
1941
+ /** Accepts (login required). If they are already a member the role does not change. */
1942
+ acceptInvite(token) {
1943
+ return this.json("POST", `/v1/invites/${encodeURIComponent(token)}/accept`);
1944
+ }
381
1945
  // --- domains: D1 hostnames methods ---
382
- /** 기본 호스트네임과 커스텀 도메인이 함께 온다 (viewer). */
1946
+ /** The default hostname and the custom domains come together (viewer). */
383
1947
  listHostnames(org, name) {
384
1948
  return this.json("GET", `${this.projectPath(org, name)}/hostnames`);
385
1949
  }
386
1950
  /**
387
- * 커스텀 도메인을 건다 (member).
1951
+ * Attaches a custom domain (member).
388
1952
  *
389
- * 멱등이다 — 같은 이름을 다시 보내면 있던 행이 그대로 온다. 응답의 `verify`
390
- * 가 고객이 넣어야 하는 CNAME·TXT 다.
1953
+ * Idempotent — sending the same name again returns the existing row
1954
+ * unchanged. The response's `verify` is the CNAME and TXT the customer has to
1955
+ * add.
391
1956
  */
392
- addHostname(org, name, hostname) {
393
- return this.json("POST", `${this.projectPath(org, name)}/hostnames`, { hostname });
1957
+ addHostname(org, name, hostname, role) {
1958
+ return this.json("POST", `${this.projectPath(org, name)}/hostnames`, role === undefined ? { hostname } : { hostname, role });
394
1959
  }
395
- /** 배경 검증과 같은 판정을 즉시 부른다 (member). */
1960
+ /** Runs the same check the background verifier makes, right now (member). */
396
1961
  verifyHostname(org, name, host) {
397
1962
  return this.json("POST", `${this.projectPath(org, name)}/hostnames/${encodeURIComponent(host)}/verify`);
398
1963
  }
399
- /** 커스텀 도메인을 뗀다 (member). 기본 호스트네임은 400 이다. */
1964
+ /** Detaches a custom domain (member). The default hostname gives a 400. */
400
1965
  deleteHostname(org, name, host) {
401
1966
  return this.json("DELETE", `${this.projectPath(org, name)}/hostnames/${encodeURIComponent(host)}`);
402
1967
  }
403
1968
  // --- domains: D2 dns methods ---
404
- /** 이 조직의 존 목록. `rrsets` 는 없다 — 단건 조회에만 실려요. */
1969
+ /** The organization's zones. No `rrsets` — those ride only on a single-zone lookup. */
405
1970
  listZones(org) {
406
1971
  return this.json("GET", this.dnsPath(org));
407
1972
  }
408
- /** 멱등이에요. 이미 있는 존은 그대로 돌아와요. */
1973
+ /** Idempotent. A zone that already exists comes back unchanged. */
409
1974
  createZone(org, name) {
410
1975
  return this.json("POST", this.dnsPath(org), { name });
411
1976
  }
@@ -416,8 +1981,9 @@ export class Client {
416
1981
  return this.json("DELETE", `${this.dnsPath(org)}/${encodeURIComponent(zone)}`);
417
1982
  }
418
1983
  /**
419
- * rrset 하나를 **통째로** 바꿔요. `records` 가 그 (이름, 타입) 의 새 전부라,
420
- * 값 하나를 더하려면 지금 값을 함께 보내야 해요.
1984
+ * Replaces one rrset **whole**. `records` is the complete new set for that
1985
+ * (name, type), so adding a single value means sending the current ones with
1986
+ * it.
421
1987
  */
422
1988
  putRRset(org, zone, name, type, ttl, records) {
423
1989
  return this.json("PUT", this.rrsetPath(org, zone, name, type), { ttl, records });
@@ -433,39 +1999,49 @@ export class Client {
433
1999
  setZoneDS(org, zone, ds) {
434
2000
  return this.json("PUT", `${this.dnsPath(org)}/${encodeURIComponent(zone)}/dnssec/ds`, { ds });
435
2001
  }
436
- /** DNS 표면의 공통 접두. */
2002
+ /** The shared prefix of the DNS surface. */
437
2003
  dnsPath(org) {
438
2004
  return `/v1/orgs/${encodeURIComponent(org)}/dns/zones`;
439
2005
  }
440
- /** `@` 도 `*` 도 이름으로 와요. 네 군데에 같은 문자열을 적지 않아요. */
2006
+ /** Both `@` and `*` arrive as a name. Keeps the same string out of four places. */
441
2007
  rrsetPath(org, zone, name, type) {
442
2008
  return (`${this.dnsPath(org)}/${encodeURIComponent(zone)}` +
443
2009
  `/rrsets/${encodeURIComponent(name)}/${encodeURIComponent(type)}`);
444
2010
  }
445
2011
  // --- domains: D3 domains methods ---
446
2012
  /**
447
- * 이름을 찾아본다 (member 이상).
2013
+ * Looks a name up (member or above).
448
2014
  *
449
- * `priceCents` 는 첫 등록 1 년, `renewalCents` 는 갱신 1 년이다. 둘이
450
- * 나뉘어 있는 이유는 첫해 할인이 흔해서다 — 하나로 접으면 "1 달러에 사서
451
- * 다음 해 15 달러" 를 화면이 말할 수 없다.
2015
+ * `priceCents` is the first year of registration; `renewalCents` is one year
2016
+ * of renewal. They are separate because a first-year discount is common —
2017
+ * folded into one, the screen cannot say "buy it for $1, then $15 next year".
452
2018
  */
453
2019
  checkDomains(org, names) {
454
2020
  return this.json("POST", `${this.domainsPath(org)}/check`, { names });
455
2021
  }
456
2022
  /**
457
- * 도메인을 산다 (admin — 돈을 써요).
2023
+ * Buys a domain (admin — this spends money).
458
2024
  *
459
- * **ICANN 검증 메일이 `contact.email` 로 가요.** 화면은 사기 전에 그
460
- * 사실을 알려야 해요 (docs/domains.md §5.5).
2025
+ * **Payment comes first** (docs/domains.md §5.8). With a saved payment method
2026
+ * the answer is the registered domain; otherwise a `DomainCharge` whose
2027
+ * `checkoutUrl` is where to pay — follow it with `getDomainCharge`. Paying also
2028
+ * agrees to the automatic yearly renewal charge.
461
2029
  *
462
- * 같은 요청을 다시 보내는 것이 안전해요 — 끝난 도메인이면 그대로 오고,
463
- * 중간에 멈춘 구매면 그 자리에서 이어 가요.
2030
+ * **The ICANN verification mail goes to `contact.email`.** The screen has to
2031
+ * say so before the purchase (docs/domains.md §5.5).
464
2032
  */
465
2033
  purchaseDomain(org, body) {
466
2034
  return this.json("POST", this.domainsPath(org), body);
467
2035
  }
468
- /** 이미 가진 도메인을 가져와요 (admin). 등록기관을 부르지 않고 존만 만들어요. */
2036
+ /** One domain payment — how a `DomainCharge` from purchase or renewal is followed. */
2037
+ getDomainCharge(org, chargeId) {
2038
+ return this.json("GET", `/v1/orgs/${encodeURIComponent(org)}/domain-charges/${encodeURIComponent(chargeId)}`);
2039
+ }
2040
+ /** Domain payments, newest first. */
2041
+ listDomainCharges(org) {
2042
+ return this.json("GET", `/v1/orgs/${encodeURIComponent(org)}/domain-charges`);
2043
+ }
2044
+ /** Imports a domain you already own (admin). Creates the zone only; the registrar is not called. */
469
2045
  importDomain(org, name) {
470
2046
  return this.json("POST", `${this.domainsPath(org)}/import`, { name });
471
2047
  }
@@ -475,15 +2051,13 @@ export class Client {
475
2051
  getDomain(org, name) {
476
2052
  return this.json("GET", this.domainPath(org, name));
477
2053
  }
478
- renewDomain(org, name, years) {
479
- return this.json("POST", `${this.domainPath(org, name)}/renew`, { years });
2054
+ /** Renews now, paid the same way as a purchase. */
2055
+ renewDomain(org, name, years, pay = {}) {
2056
+ return this.json("POST", `${this.domainPath(org, name)}/renew`, { years, ...pay });
480
2057
  }
481
2058
  /**
482
- * 자동 갱신 **의사**만 바꿔요.
483
- *
484
- * 등록기관 쪽 자동 갱신은 그대로 켜져 있어요 — 도메인은 하루 늦으면 잃는
485
- * 자산이라 우리가 먼저 갱신하고 뒤에 청구해요. 화면은 이 사실을 함께
486
- * 말해야 해요.
2059
+ * Turns automatic renewal on or off. On: one year is charged 30 days before
2060
+ * expiry. Off: nothing is charged and the domain lapses at expiry.
487
2061
  */
488
2062
  setDomainAutoRenew(org, name, enabled) {
489
2063
  return this.json("POST", `${this.domainPath(org, name)}/auto-renew`, { enabled });
@@ -491,31 +2065,141 @@ export class Client {
491
2065
  setDomainLock(org, name, locked) {
492
2066
  return this.json("POST", `${this.domainPath(org, name)}/lock`, { locked });
493
2067
  }
494
- /** 이전 코드예요. 감사에 발급 사실이 남고 **코드는 남지 않아요**. */
2068
+ /** The transfer auth code. The audit records that one was issued and **not the code itself**. */
495
2069
  domainAuthCode(org, name) {
496
2070
  return this.json("POST", `${this.domainPath(org, name)}/auth-code`);
497
2071
  }
498
- /** 지금 등록기관에서 다시 읽어요 (member). */
2072
+ /** Re-reads from the registrar right now (member). */
499
2073
  syncDomain(org, name) {
500
2074
  return this.json("POST", `${this.domainPath(org, name)}/sync`);
501
2075
  }
502
- /** 도메인 표면의 공통 접두. 열 군데에 같은 문자열을 적지 않아요. */
2076
+ /** The shared prefix of the domain surface. Keeps the same string out of ten places. */
503
2077
  domainsPath(org) {
504
2078
  return `/v1/orgs/${encodeURIComponent(org)}/domains`;
505
2079
  }
506
2080
  domainPath(org, name) {
507
2081
  return `${this.domainsPath(org)}/${encodeURIComponent(name)}`;
508
2082
  }
509
- /** 프로젝트 표면의 공통 접두다. */
2083
+ /** The shared prefix of the project surface. */
510
2084
  projectPath(org, name) {
511
2085
  return `/v1/orgs/${encodeURIComponent(org)}/projects/${encodeURIComponent(name)}`;
512
2086
  }
513
- /** 데이터베이스 표면의 공통 접두다. 다섯 군데에 같은 문자열을 적지 않는다. */
2087
+ /** The shared prefix of the database surface. Keeps the same string out of five places. */
514
2088
  dbPath(org, name) {
515
2089
  return `/v1/orgs/${encodeURIComponent(org)}/projects/${encodeURIComponent(name)}/database`;
516
2090
  }
2091
+ // ---- Self-hosted Git (docs/git-hosting.md §12.1, §19) ----
2092
+ //
2093
+ // **git does the repository work and we handle only the metadata.** That is
2094
+ // why there is nothing like `pushRepo` here — an API that wraps git either
2095
+ // reimplements every one of git's flags or boxes the user in.
2096
+ //
2097
+ // A repository **belongs to a project**. That is why every method starts with
2098
+ // (org, project) — the same shape as the database and the secrets.
2099
+ listRepos(org, project) {
2100
+ return this.json("GET", this.repoPath(org, project));
2101
+ }
2102
+ createRepo(org, project, body) {
2103
+ return this.json("POST", this.repoPath(org, project), body);
2104
+ }
2105
+ getRepo(org, project, name) {
2106
+ return this.json("GET", `${this.repoPath(org, project)}/${encodeURIComponent(name)}`);
2107
+ }
2108
+ updateRepo(org, project, name, body) {
2109
+ return this.json("PATCH", `${this.repoPath(org, project)}/${encodeURIComponent(name)}`, body);
2110
+ }
2111
+ deleteRepo(org, project, name) {
2112
+ return this.json("DELETE", `${this.repoPath(org, project)}/${encodeURIComponent(name)}`);
2113
+ }
2114
+ /** The ref history. The lead for recovering a commit lost to a force-push is here. */
2115
+ listRefUpdates(org, project, name) {
2116
+ return this.json("GET", `${this.repoPath(org, project)}/${encodeURIComponent(name)}/ref-updates`);
2117
+ }
2118
+ // Push-to-deploy (docs/code/push-to-deploy). The hook hangs off the
2119
+ // repository and the builds off the **project**, because a build outlives the
2120
+ // repository it came from.
2121
+ getDeployHook(org, project, name) {
2122
+ return this.json("GET", `${this.repoPath(org, project)}/${encodeURIComponent(name)}/deploy-hook`);
2123
+ }
2124
+ setDeployHook(org, project, name, body) {
2125
+ return this.json("PUT", `${this.repoPath(org, project)}/${encodeURIComponent(name)}/deploy-hook`, body);
2126
+ }
2127
+ deleteDeployHook(org, project, name) {
2128
+ return this.json("DELETE", `${this.repoPath(org, project)}/${encodeURIComponent(name)}/deploy-hook`);
2129
+ }
2130
+ /** Build a commit without pushing. Omit `commitSha` for the hooked branch's tip. */
2131
+ deployRepoNow(org, project, name, commitSha) {
2132
+ return this.json("POST", `${this.repoPath(org, project)}/${encodeURIComponent(name)}/deploy`, commitSha === undefined ? {} : { commitSha });
2133
+ }
2134
+ listBuilds(org, project, limit) {
2135
+ const q = limit === undefined ? "" : `?limit=${limit}`;
2136
+ return this.json("GET", `${this.projectPath(org, project)}/builds${q}`);
2137
+ }
2138
+ getBuild(org, project, buildId) {
2139
+ return this.json("GET", `${this.projectPath(org, project)}/builds/${encodeURIComponent(buildId)}`);
2140
+ }
2141
+ /**
2142
+ * A build's output. It comes back as **text**, not JSON — see the endpoint's
2143
+ * description. `json()` would try to parse it and fail on the first line.
2144
+ */
2145
+ getBuildLog(org, project, buildId) {
2146
+ return this.text("GET", `${this.projectPath(org, project)}/builds/${encodeURIComponent(buildId)}/log`);
2147
+ }
2148
+ cancelBuild(org, project, buildId) {
2149
+ return this.json("POST", `${this.projectPath(org, project)}/builds/${encodeURIComponent(buildId)}/cancel`);
2150
+ }
2151
+ listSSHKeys() {
2152
+ return this.json("GET", "/v1/me/ssh-keys");
2153
+ }
2154
+ addSSHKey(publicKey, name) {
2155
+ return this.json("POST", "/v1/me/ssh-keys", { publicKey, name });
2156
+ }
2157
+ deleteSSHKey(keyId) {
2158
+ return this.json("DELETE", `/v1/me/ssh-keys/${encodeURIComponent(keyId)}`);
2159
+ }
2160
+ listAccessTokens() {
2161
+ return this.json("GET", "/v1/me/tokens");
2162
+ }
2163
+ /** The plaintext is carried in this response **once** and never again. */
2164
+ createAccessToken(body) {
2165
+ return this.json("POST", "/v1/me/tokens", body);
2166
+ }
2167
+ revokeAccessToken(tokenId) {
2168
+ return this.json("DELETE", `/v1/me/tokens/${encodeURIComponent(tokenId)}`);
2169
+ }
2170
+ // ---- Browsing (docs/git-hosting.md §12.2) ----
2171
+ getRepoRefs(org, project, name) {
2172
+ return this.json("GET", `${this.repoPath(org, project)}/${encodeURIComponent(name)}/refs`);
2173
+ }
2174
+ getRepoTree(org, project, name, ref = "", path = "") {
2175
+ return this.json("GET", `${this.repoPath(org, project)}/${encodeURIComponent(name)}/tree${gitQuery(ref, path)}`);
2176
+ }
2177
+ getRepoBlob(org, project, name, ref = "", path = "") {
2178
+ return this.json("GET", `${this.repoPath(org, project)}/${encodeURIComponent(name)}/blob${gitQuery(ref, path)}`);
2179
+ }
2180
+ getRepoCommits(org, project, name, ref = "", limit) {
2181
+ const q = new URLSearchParams();
2182
+ if (ref !== "")
2183
+ q.set("ref", ref);
2184
+ if (limit !== undefined)
2185
+ q.set("limit", String(limit));
2186
+ const qs = q.size > 0 ? `?${q.toString()}` : "";
2187
+ return this.json("GET", `${this.repoPath(org, project)}/${encodeURIComponent(name)}/commits${qs}`);
2188
+ }
2189
+ /** The shared prefix of the repository surface. It sits under the project (§19). */
2190
+ repoPath(org, project) {
2191
+ return `${this.projectPath(org, project)}/repos`;
2192
+ }
517
2193
  rollback(org, name, version) {
518
2194
  return this.json("POST", `/v1/orgs/${encodeURIComponent(org)}/projects/${encodeURIComponent(name)}/rollback`, { version });
519
2195
  }
520
2196
  }
2197
+ /** A query string from the defined, non-empty options. */
2198
+ function obsQS(opts) {
2199
+ const q = new URLSearchParams();
2200
+ for (const [k, v] of Object.entries(opts))
2201
+ if (v)
2202
+ q.set(k, v);
2203
+ return q.size ? `?${q}` : "";
2204
+ }
521
2205
  //# sourceMappingURL=index.js.map