@runlot/api 0.1.0-rc.15 → 0.1.0-rc.150
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.d.ts +857 -117
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +959 -118
- package/dist/index.js.map +1 -1
- package/dist/schema.d.ts +12680 -2777
- package/dist/schema.d.ts.map +1 -1
- package/package.json +5 -3
package/dist/index.js
CHANGED
|
@@ -1,5 +1,36 @@
|
|
|
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
|
+
export const API_SCOPES = [
|
|
20
|
+
"project:read",
|
|
21
|
+
"deploy",
|
|
22
|
+
"db:read",
|
|
23
|
+
"db:write",
|
|
24
|
+
"repo:read",
|
|
25
|
+
"repo:write",
|
|
26
|
+
"org:admin",
|
|
27
|
+
];
|
|
28
|
+
export const BUILTIN_AUTH_PROVIDERS = ["github", "google"];
|
|
29
|
+
export const RESERVED_AUTH_PROVIDER_IDS = ["github", "google", "runlot"];
|
|
30
|
+
/** The id pattern for an OIDC provider (`^[a-z][a-z0-9-]{1,30}$`). */
|
|
31
|
+
export const AUTH_PROVIDER_ID = /^[a-z][a-z0-9-]{1,30}$/;
|
|
32
|
+
export const AUTH_RUNLOT_METHODS = ["password", "google", "github", "passkey"];
|
|
33
|
+
/** The exception that carries the server's error envelope unchanged. */
|
|
3
34
|
export class ApiError extends Error {
|
|
4
35
|
status;
|
|
5
36
|
code;
|
|
@@ -14,10 +45,11 @@ export class ApiError extends Error {
|
|
|
14
45
|
}
|
|
15
46
|
}
|
|
16
47
|
/**
|
|
17
|
-
* cp-public
|
|
48
|
+
* The cp-public client.
|
|
18
49
|
*
|
|
19
|
-
* CLI
|
|
20
|
-
*
|
|
50
|
+
* The CLI and the dashboard use the same one. If each called fetch itself, their
|
|
51
|
+
* error handling would drift a little, and that difference shows up during an
|
|
52
|
+
* incident.
|
|
21
53
|
*/
|
|
22
54
|
function dbPath(org, name) {
|
|
23
55
|
return `/v1/orgs/${encodeURIComponent(org)}/projects/${encodeURIComponent(name)}/database`;
|
|
@@ -45,8 +77,21 @@ export class Client {
|
|
|
45
77
|
body = (await res.json());
|
|
46
78
|
}
|
|
47
79
|
catch {
|
|
48
|
-
//
|
|
49
|
-
//
|
|
80
|
+
// An error response that is not JSON (a 502 made by a proxy, for instance)
|
|
81
|
+
// is raised as the same exception — so the caller does not have to handle
|
|
82
|
+
// two shapes of failure.
|
|
83
|
+
}
|
|
84
|
+
if (body === undefined && res.status >= 502 && res.status <= 504) {
|
|
85
|
+
// The edge replaced the 5xx body with its own HTML. The code and reason
|
|
86
|
+
// the server wrote are not here — so say that, rather than "unknown". On
|
|
87
|
+
// 2026-09-10 a registrar rejection came out this way as
|
|
88
|
+
// "unknown: POST … → 502".
|
|
89
|
+
body = {
|
|
90
|
+
error: {
|
|
91
|
+
code: "edge_" + res.status,
|
|
92
|
+
message: "The server returned an error (" + res.status + "), and the error details could not be read. Try again shortly.",
|
|
93
|
+
},
|
|
94
|
+
};
|
|
50
95
|
}
|
|
51
96
|
throw new ApiError(res.status, body, `${method} ${path} → ${res.status}`);
|
|
52
97
|
}
|
|
@@ -54,6 +99,21 @@ export class Client {
|
|
|
54
99
|
return undefined;
|
|
55
100
|
return (await res.json());
|
|
56
101
|
}
|
|
102
|
+
/** A body that is not JSON (the raw mail). Error handling is the same as request. */
|
|
103
|
+
async text(method, path) {
|
|
104
|
+
const res = await fetch(new URL(path, this.opts.baseUrl), { method, headers: this.headers() });
|
|
105
|
+
if (!res.ok) {
|
|
106
|
+
let body;
|
|
107
|
+
try {
|
|
108
|
+
body = (await res.json());
|
|
109
|
+
}
|
|
110
|
+
catch {
|
|
111
|
+
// The same reason as in request
|
|
112
|
+
}
|
|
113
|
+
throw new ApiError(res.status, body, `${method} ${path} → ${res.status}`);
|
|
114
|
+
}
|
|
115
|
+
return await res.text();
|
|
116
|
+
}
|
|
57
117
|
json(method, path, body) {
|
|
58
118
|
if (body === undefined)
|
|
59
119
|
return this.request(method, path);
|
|
@@ -65,38 +125,205 @@ export class Client {
|
|
|
65
125
|
devLogin(subject) {
|
|
66
126
|
return this.json("POST", "/v1/auth/dev/login", { subject });
|
|
67
127
|
}
|
|
68
|
-
/**
|
|
69
|
-
|
|
70
|
-
|
|
128
|
+
/**
|
|
129
|
+
* Takes the sign-up and sends the confirmation mail. Neither a session nor a
|
|
130
|
+
* password is created here — the password is chosen in `verifyEmail` by
|
|
131
|
+
* whoever opens the mailbox.
|
|
132
|
+
*/
|
|
133
|
+
passwordSignUp(email, name) {
|
|
134
|
+
return this.json("POST", "/v1/auth/password/sign-up", {
|
|
135
|
+
email,
|
|
136
|
+
...(name === undefined ? {} : { name }),
|
|
137
|
+
});
|
|
138
|
+
}
|
|
139
|
+
passwordSignIn(email, password) {
|
|
140
|
+
return this.json("POST", "/v1/auth/password/sign-in", { email, password });
|
|
141
|
+
}
|
|
142
|
+
/** The same accepted response comes back whether or not the email exists. */
|
|
143
|
+
passwordForgot(email) {
|
|
144
|
+
return this.json("POST", "/v1/auth/password/forgot", { email });
|
|
145
|
+
}
|
|
146
|
+
passwordReset(token, password) {
|
|
147
|
+
return this.json("POST", "/v1/auth/password/reset", { token, password });
|
|
148
|
+
}
|
|
149
|
+
/** Uses the confirmation link and sets the account's first password. */
|
|
150
|
+
verifyEmail(token, password) {
|
|
151
|
+
return this.json("POST", "/v1/auth/email/verify", { token, password });
|
|
152
|
+
}
|
|
153
|
+
/**
|
|
154
|
+
* Finishes a sign-in that came back `{mfa:"totp"}`.
|
|
155
|
+
*
|
|
156
|
+
* Callable without a token: `pending` is the credential, and it is not a
|
|
157
|
+
* session — no other endpoint accepts it.
|
|
158
|
+
*/
|
|
159
|
+
completeTotpLogin(pending, factor) {
|
|
160
|
+
return this.json("POST", "/v1/auth/totp", { pending, ...factor });
|
|
161
|
+
}
|
|
162
|
+
/** This account's two-factor state, including which orgs require it. */
|
|
163
|
+
getTotp() {
|
|
164
|
+
return this.json("GET", "/v1/me/totp");
|
|
165
|
+
}
|
|
166
|
+
/**
|
|
167
|
+
* Draws a secret to scan. It does **not** turn the factor on — `confirmTotp`
|
|
168
|
+
* does, after the app has proved it can produce a code.
|
|
169
|
+
*/
|
|
170
|
+
enrollTotp() {
|
|
171
|
+
return this.json("POST", "/v1/me/totp/enroll");
|
|
172
|
+
}
|
|
173
|
+
/** Turns the factor on and hands back the ten recovery codes. They are shown once. */
|
|
174
|
+
confirmTotp(code) {
|
|
175
|
+
return this.json("POST", "/v1/me/totp/confirm", { code });
|
|
176
|
+
}
|
|
177
|
+
/** Turns it off. A code or a recovery code is required — the session alone is not. */
|
|
178
|
+
disableTotp(factor) {
|
|
179
|
+
return this.json("DELETE", "/v1/me/totp", factor);
|
|
71
180
|
}
|
|
72
181
|
/**
|
|
73
|
-
* GitHub OAuth
|
|
74
|
-
* `window.location`
|
|
182
|
+
* The GitHub OAuth start URL. It is a 302 the browser follows, so it goes into
|
|
183
|
+
* `window.location` rather than being called with fetch. `redirect` has to be
|
|
184
|
+
* on the server's allow-list.
|
|
75
185
|
*/
|
|
76
186
|
githubStartUrl(redirect) {
|
|
77
187
|
const u = new URL("/v1/auth/github/start", this.opts.baseUrl);
|
|
78
188
|
u.searchParams.set("redirect", redirect);
|
|
79
189
|
return u.toString();
|
|
80
190
|
}
|
|
191
|
+
/** The Google OAuth start URL. Uses the same dashboard callback shape as GitHub. */
|
|
192
|
+
googleStartUrl(redirect) {
|
|
193
|
+
const u = new URL("/v1/auth/google/start", this.opts.baseUrl);
|
|
194
|
+
u.searchParams.set("redirect", redirect);
|
|
195
|
+
return u.toString();
|
|
196
|
+
}
|
|
197
|
+
/**
|
|
198
|
+
* The generic OIDC start URL (docs/onprem-delivery.md §7.7). Same 302-and-fragment
|
|
199
|
+
* shape as the other two; which provider is behind it is the installation's choice.
|
|
200
|
+
*/
|
|
201
|
+
oidcStartUrl(redirect) {
|
|
202
|
+
const u = new URL("/v1/auth/oidc/start", this.opts.baseUrl);
|
|
203
|
+
u.searchParams.set("redirect", redirect);
|
|
204
|
+
return u.toString();
|
|
205
|
+
}
|
|
206
|
+
/**
|
|
207
|
+
* Does this deployment federate an identity provider?
|
|
208
|
+
*
|
|
209
|
+
* **There is no endpoint that answers "which logins are on"** — one existed and was
|
|
210
|
+
* deleted, because its only reader was the login screen and it put a round trip in
|
|
211
|
+
* front of every login button (cp/internal/public/public.go). This is not that
|
|
212
|
+
* endpoint coming back: cp-public **does not register** the two OIDC routes when no
|
|
213
|
+
* issuer is configured, so the mux's own 404 is the answer, and the probe is a HEAD
|
|
214
|
+
* that no handler runs.
|
|
215
|
+
*
|
|
216
|
+
* Any other status means the route is there — a 400 (this probe carries no
|
|
217
|
+
* `redirect`) or a 502 (the provider's discovery document could not be read) both say
|
|
218
|
+
* the handler exists, and a button that leads to a readable error beats no button.
|
|
219
|
+
* A network failure answers false: on SaaS, where the answer is false anyway, a dead
|
|
220
|
+
* API address must not draw a login that cannot work.
|
|
221
|
+
*/
|
|
222
|
+
async oidcAvailable() {
|
|
223
|
+
try {
|
|
224
|
+
const res = await fetch(new URL("/v1/auth/oidc/start", this.opts.baseUrl), { method: "HEAD" });
|
|
225
|
+
return res.status !== 404;
|
|
226
|
+
}
|
|
227
|
+
catch {
|
|
228
|
+
return false;
|
|
229
|
+
}
|
|
230
|
+
}
|
|
231
|
+
/**
|
|
232
|
+
* This installation's licence (docs/onprem-delivery.md §6.5). Readable by any
|
|
233
|
+
* signed-in user: the footer it feeds is on every page for everybody.
|
|
234
|
+
*
|
|
235
|
+
* On SaaS it answers `onPrem: false` rather than 404, so the caller has one shape to
|
|
236
|
+
* read and the surfaces draw nothing on the flag.
|
|
237
|
+
*/
|
|
238
|
+
license() {
|
|
239
|
+
return this.json("GET", "/v1/license");
|
|
240
|
+
}
|
|
241
|
+
/**
|
|
242
|
+
* The names of this deployment (app domain, docs address). Callable without auth.
|
|
243
|
+
*
|
|
244
|
+
* This exists so the dashboard does not hard-code a domain into the screen
|
|
245
|
+
* (docs/environments.md §3.2) — hard-coded, the dev screen tells people a
|
|
246
|
+
* production address, and because that address opens, nobody ever says it is
|
|
247
|
+
* wrong.
|
|
248
|
+
*/
|
|
249
|
+
siteConfig() {
|
|
250
|
+
return this.json("GET", "/v1/config");
|
|
251
|
+
}
|
|
81
252
|
me() {
|
|
82
253
|
return this.json("GET", "/v1/me");
|
|
83
254
|
}
|
|
84
255
|
listOrgs() {
|
|
85
256
|
return this.json("GET", "/v1/orgs");
|
|
86
257
|
}
|
|
258
|
+
/** Changes the display name only (admin). The slug is the name that becomes an address, so it is not on this surface. */
|
|
259
|
+
/**
|
|
260
|
+
* `requireTotp` is left out when it is not given, on purpose: the server reads
|
|
261
|
+
* an absent field as "leave it alone". Sending `false` by default would mean a
|
|
262
|
+
* rename silently switched the org's second-factor requirement off.
|
|
263
|
+
*/
|
|
264
|
+
updateOrg(org, name, requireTotp) {
|
|
265
|
+
return this.json("PATCH", `/v1/orgs/${encodeURIComponent(org)}`, {
|
|
266
|
+
name,
|
|
267
|
+
...(requireTotp === undefined ? {} : { requireTotp }),
|
|
268
|
+
});
|
|
269
|
+
}
|
|
270
|
+
/**
|
|
271
|
+
* Deletes the organization (admin). **This cannot be undone.**
|
|
272
|
+
*
|
|
273
|
+
* `confirm` has to be the organization slug exactly — the confirmation lives on
|
|
274
|
+
* the server because three places call this surface (the screen, the CLI, and
|
|
275
|
+
* scripts). If a live project, domain, repository, or DNS zone is left, it is a
|
|
276
|
+
* 409 `org_not_empty` and `details.holdings` says what is left — **projects
|
|
277
|
+
* already deleted are not counted.**
|
|
278
|
+
*
|
|
279
|
+
* The `purgeAfter` in the answer is when the rows actually disappear. By the
|
|
280
|
+
* moment it returns the organization is already gone from every surface; what
|
|
281
|
+
* remains is retention until that time.
|
|
282
|
+
*/
|
|
283
|
+
deleteOrg(org, confirm) {
|
|
284
|
+
return this.json("DELETE", `/v1/orgs/${encodeURIComponent(org)}`, { confirm });
|
|
285
|
+
}
|
|
87
286
|
createOrg(slug, name) {
|
|
88
287
|
return this.json("POST", "/v1/orgs", { slug, name });
|
|
89
288
|
}
|
|
90
289
|
/**
|
|
91
|
-
*
|
|
290
|
+
* The organization's recent notifications (docs/limits.md §3.4).
|
|
92
291
|
*
|
|
93
|
-
* `sentAt`
|
|
94
|
-
*
|
|
292
|
+
* A row with no `sentAt` is either still queued or has no email address to
|
|
293
|
+
* reach — and for the second, this list is the only channel, so the screen
|
|
294
|
+
* draws both states the same way.
|
|
95
295
|
*/
|
|
96
296
|
listNotifications(org, limit) {
|
|
97
297
|
const q = limit === undefined ? "" : `?limit=${limit}`;
|
|
98
298
|
return this.json("GET", `/v1/orgs/${encodeURIComponent(org)}/notifications${q}`);
|
|
99
299
|
}
|
|
300
|
+
/**
|
|
301
|
+
* The plan and billing state (docs/billing.md). If `enabled` is false, this
|
|
302
|
+
* deployment has no billing — the screen shows only a contact address.
|
|
303
|
+
*/
|
|
304
|
+
getBilling(org) {
|
|
305
|
+
return this.json("GET", `/v1/orgs/${encodeURIComponent(org)}/billing`);
|
|
306
|
+
}
|
|
307
|
+
/**
|
|
308
|
+
* A Pro checkout session. Send the browser to the `url` that comes back. Even
|
|
309
|
+
* once payment finishes, the thing that changes the plan is the webhook, so
|
|
310
|
+
* read `getBilling` again after the browser returns.
|
|
311
|
+
*/
|
|
312
|
+
createBillingCheckout(org, returnTo) {
|
|
313
|
+
return this.json("POST", `/v1/orgs/${encodeURIComponent(org)}/billing/checkout`, { returnTo });
|
|
314
|
+
}
|
|
315
|
+
/** A one-time `url` for the customer portal (payment method, receipts, cancellation). */
|
|
316
|
+
createBillingPortal(org, returnTo) {
|
|
317
|
+
return this.json("POST", `/v1/orgs/${encodeURIComponent(org)}/billing/portal`, { returnTo });
|
|
318
|
+
}
|
|
319
|
+
/** The customer session token for the payment-method embed (1 hour). An org with no payment history gets a 404. */
|
|
320
|
+
createBillingSession(org) {
|
|
321
|
+
return this.json("POST", `/v1/orgs/${encodeURIComponent(org)}/billing/session`, {});
|
|
322
|
+
}
|
|
323
|
+
/** Schedules cancellation at the end of the period (`cancel: true`), or undoes it. There is no immediate revocation. */
|
|
324
|
+
cancelBilling(org, body) {
|
|
325
|
+
return this.json("POST", `/v1/orgs/${encodeURIComponent(org)}/billing/cancel`, body);
|
|
326
|
+
}
|
|
100
327
|
listProjects(org) {
|
|
101
328
|
return this.json("GET", `/v1/orgs/${encodeURIComponent(org)}/projects`);
|
|
102
329
|
}
|
|
@@ -106,17 +333,210 @@ export class Client {
|
|
|
106
333
|
getProject(org, name) {
|
|
107
334
|
return this.json("GET", `/v1/orgs/${encodeURIComponent(org)}/projects/${encodeURIComponent(name)}`);
|
|
108
335
|
}
|
|
336
|
+
/**
|
|
337
|
+
* Renames the project (admin). **The default address moves with it and there is
|
|
338
|
+
* no alias** — which is why the response carries the new address. Unlike the
|
|
339
|
+
* org slug, this name can change because it is the inner label of the org
|
|
340
|
+
* wildcard certificate.
|
|
341
|
+
*/
|
|
342
|
+
updateProject(org, name, next) {
|
|
343
|
+
return this.json("PATCH", this.projectPath(org, name), { name: next });
|
|
344
|
+
}
|
|
345
|
+
/**
|
|
346
|
+
* Starts tearing the project down (admin). **This cannot be undone and leaves
|
|
347
|
+
* no recovery generation.** `confirm` has to be the project name exactly.
|
|
348
|
+
*/
|
|
349
|
+
deleteProject(org, name, confirm) {
|
|
350
|
+
return this.json("DELETE", this.projectPath(org, name), { confirm });
|
|
351
|
+
}
|
|
352
|
+
/**
|
|
353
|
+
* Disables a project (admin): it stops serving and taking new backups, and
|
|
354
|
+
* keeps everything it has. A project disabled for a year is deleted for good.
|
|
355
|
+
*/
|
|
356
|
+
disableProject(org, name) {
|
|
357
|
+
return this.json("POST", `${this.projectPath(org, name)}/disable`);
|
|
358
|
+
}
|
|
359
|
+
/** Enables a disabled project (admin). 409 `project_limit` when there is no room for it. */
|
|
360
|
+
enableProject(org, name) {
|
|
361
|
+
return this.json("POST", `${this.projectPath(org, name)}/enable`);
|
|
362
|
+
}
|
|
363
|
+
/** Watches the teardown operation to its end even after the project is gone. */
|
|
364
|
+
getOrgOperation(org, opId) {
|
|
365
|
+
return this.json("GET", `/v1/orgs/${encodeURIComponent(org)}/operations/${encodeURIComponent(opId)}`);
|
|
366
|
+
}
|
|
367
|
+
/** Everything the project's first screen takes in one call. Usage calls `getUsage` alongside it. */
|
|
368
|
+
getProjectOverview(org, name) {
|
|
369
|
+
return this.json("GET", `${this.projectPath(org, name)}/overview`);
|
|
370
|
+
}
|
|
109
371
|
listDeployments(org, name) {
|
|
110
372
|
return this.json("GET", `/v1/orgs/${encodeURIComponent(org)}/projects/${encodeURIComponent(name)}/deployments`);
|
|
111
373
|
}
|
|
112
|
-
/**
|
|
113
|
-
|
|
374
|
+
/**
|
|
375
|
+
* One deployment, with `migrations` when the control plane applied its
|
|
376
|
+
* `migrations/` — which today means a preview deployed with `db=branch`
|
|
377
|
+
* (docs/studio.md §6.6 step 2).
|
|
378
|
+
*
|
|
379
|
+
* A preview's deployment is read under **the parent project's name**, the name
|
|
380
|
+
* the caller deployed through: the preview is a project of its own, but the
|
|
381
|
+
* caller never learns its name.
|
|
382
|
+
*/
|
|
383
|
+
getDeployment(org, name, deploymentId) {
|
|
384
|
+
return this.json("GET", `${this.projectPath(org, name)}/deployments/${encodeURIComponent(deploymentId)}`);
|
|
385
|
+
}
|
|
386
|
+
/**
|
|
387
|
+
* Scheduled runs: what the live deployment declares, when each fires next, and
|
|
388
|
+
* the recent history (docs/cron.md §8). `limit` bounds the history rows only —
|
|
389
|
+
* the schedules and the per-schedule last run are never paged.
|
|
390
|
+
*/
|
|
391
|
+
getProjectCron(org, name, limit) {
|
|
392
|
+
const qs = limit ? `?limit=${limit}` : "";
|
|
393
|
+
return this.json("GET", `${this.projectPath(org, name)}/cron${qs}`);
|
|
394
|
+
}
|
|
395
|
+
/**
|
|
396
|
+
* Queues: what the live deployment declares, how deep each one is, and the
|
|
397
|
+
* recent batch history (docs/queues.md §6). The depth is read from the
|
|
398
|
+
* project's own database; `depthError` on the answer says when it could not be.
|
|
399
|
+
*/
|
|
400
|
+
getProjectQueues(org, name, limit) {
|
|
401
|
+
const qs = limit ? `?limit=${limit}` : "";
|
|
402
|
+
return this.json("GET", `${this.projectPath(org, name)}/queues${qs}`);
|
|
403
|
+
}
|
|
404
|
+
/**
|
|
405
|
+
* Durable Objects: how many this project has placed, against the two caps
|
|
406
|
+
* (docs/durable-objects.md).
|
|
407
|
+
*
|
|
408
|
+
* **It answers how much, never which.** There is no actor id in the response
|
|
409
|
+
* and none is coming — those name individual objects, and a list of them would
|
|
410
|
+
* be an object enumeration wearing a quota's name. `nodes` is keyed by node id
|
|
411
|
+
* because `nodeLimit` is a separate bound that can refuse a placement while
|
|
412
|
+
* the project-wide cap still has room.
|
|
413
|
+
*/
|
|
414
|
+
getProjectDurableObjects(org, name) {
|
|
415
|
+
return this.json("GET", `${this.projectPath(org, name)}/durable-objects`);
|
|
416
|
+
}
|
|
417
|
+
queuePath(org, name, queue) {
|
|
418
|
+
return `${this.projectPath(org, name)}/queues/${encodeURIComponent(queue)}`;
|
|
419
|
+
}
|
|
420
|
+
listQueueRuns(org, name, queue, limit) {
|
|
421
|
+
const qs = limit ? `?limit=${limit}` : "";
|
|
422
|
+
return this.json("GET", `${this.queuePath(org, name, queue)}/runs${qs}`);
|
|
423
|
+
}
|
|
424
|
+
/** The head of the queue without leasing it — looking cannot delay a delivery. */
|
|
425
|
+
peekQueue(org, name, queue, limit) {
|
|
426
|
+
const qs = limit ? `?limit=${limit}` : "";
|
|
427
|
+
return this.json("GET", `${this.queuePath(org, name, queue)}/messages${qs}`);
|
|
428
|
+
}
|
|
429
|
+
/** Irreversible. The confirmation is the caller's — the server holds none. */
|
|
430
|
+
purgeQueue(org, name, queue) {
|
|
431
|
+
return this.json("DELETE", `${this.queuePath(org, name, queue)}/messages`);
|
|
432
|
+
}
|
|
433
|
+
/**
|
|
434
|
+
* Moves a dead-letter queue's messages back. `to` is required only when the
|
|
435
|
+
* dead-letter queue belongs to more than one consumer, or to none.
|
|
436
|
+
*/
|
|
437
|
+
redriveQueue(org, name, queue, to) {
|
|
438
|
+
return this.json("POST", `${this.queuePath(org, name, queue)}/redrive`, to === undefined ? {} : { to });
|
|
439
|
+
}
|
|
440
|
+
/**
|
|
441
|
+
* The vector store: every namespace with its count and width, and the plan's
|
|
442
|
+
* bounds (docs/vectors.md §4). Read from the project's own database;
|
|
443
|
+
* `readError` on the answer says when it could not be.
|
|
444
|
+
*/
|
|
445
|
+
getProjectVectors(org, name) {
|
|
446
|
+
return this.json("GET", `${this.projectPath(org, name)}/vectors`);
|
|
447
|
+
}
|
|
448
|
+
/** Irreversible. The confirmation is the caller's — the server holds none. */
|
|
449
|
+
deleteVectorNamespace(org, name, namespace) {
|
|
450
|
+
return this.json("DELETE", `${this.projectPath(org, name)}/vectors/${encodeURIComponent(namespace)}`);
|
|
451
|
+
}
|
|
452
|
+
/** The body is the bundle. One digest covers all of the code and the assets. */
|
|
453
|
+
/**
|
|
454
|
+
* Uploads the bundle. `headers` carries the provenance headers
|
|
455
|
+
* (`X-Runlot-Git-*`, openapi createDeployment) — the body is the bundle
|
|
456
|
+
* itself, so the metadata can only travel in headers.
|
|
457
|
+
*/
|
|
458
|
+
deploy(org, name, bundle, headers = {}) {
|
|
114
459
|
return this.request("POST", `/v1/orgs/${encodeURIComponent(org)}/projects/${encodeURIComponent(name)}/deployments`, {
|
|
115
460
|
body: bundle,
|
|
116
|
-
headers: { "Content-Type": "application/gzip" },
|
|
461
|
+
headers: { ...headers, "Content-Type": "application/gzip" },
|
|
462
|
+
});
|
|
463
|
+
}
|
|
464
|
+
/**
|
|
465
|
+
* The same upload, aimed at a preview (docs/preview.md). **It does not move
|
|
466
|
+
* production's live pointer** — that is the whole difference, and it is why
|
|
467
|
+
* this is a named method rather than an optional argument on `deploy`: a
|
|
468
|
+
* caller that forgets the argument deploys to production.
|
|
469
|
+
*
|
|
470
|
+
* `db` picks what `env.db` points at (`branch` by default, `shared` at
|
|
471
|
+
* production's own database, `none` for no database), and `from` pours the
|
|
472
|
+
* branch from a named generation instead of the newest one.
|
|
473
|
+
*/
|
|
474
|
+
deployPreview(org, name, bundle,
|
|
475
|
+
// `| undefined` spelled out: under exactOptionalPropertyTypes a caller that
|
|
476
|
+
// forwards an unset flag is passing the property, not omitting it.
|
|
477
|
+
opts, headers = {}) {
|
|
478
|
+
const q = new URLSearchParams({ preview: opts.preview });
|
|
479
|
+
// Empty values are not carried: the server reads "absent" as its default, and
|
|
480
|
+
// `?db=` would be neither absent nor a member of the enum.
|
|
481
|
+
if (opts.db)
|
|
482
|
+
q.set("db", opts.db);
|
|
483
|
+
if (opts.from)
|
|
484
|
+
q.set("from", opts.from);
|
|
485
|
+
return this.request("POST", `${this.projectPath(org, name)}/deployments?${q.toString()}`, {
|
|
486
|
+
body: bundle,
|
|
487
|
+
headers: { ...headers, "Content-Type": "application/gzip" },
|
|
488
|
+
});
|
|
489
|
+
}
|
|
490
|
+
/** The parent's live previews (viewer). A deleted preview is not listed. */
|
|
491
|
+
listPreviews(org, name) {
|
|
492
|
+
return this.json("GET", `${this.projectPath(org, name)}/previews`);
|
|
493
|
+
}
|
|
494
|
+
/**
|
|
495
|
+
* Deletes a preview and its branch (member).
|
|
496
|
+
*
|
|
497
|
+
* No confirmation string, unlike `deleteProject`: a branch is a copy taken at a
|
|
498
|
+
* moment and nothing in it is the only copy of anything.
|
|
499
|
+
*/
|
|
500
|
+
deletePreview(org, name, preview) {
|
|
501
|
+
return this.json("DELETE", `${this.projectPath(org, name)}/previews/${encodeURIComponent(preview)}`);
|
|
502
|
+
}
|
|
503
|
+
/**
|
|
504
|
+
* Makes the preview's artifact the parent's live deployment (member).
|
|
505
|
+
*
|
|
506
|
+
* **The code, never the data** (docs/preview.md §7). The branch is not merged
|
|
507
|
+
* and production's database is not replaced. The preview stays alive.
|
|
508
|
+
*/
|
|
509
|
+
promotePreview(org, name, preview) {
|
|
510
|
+
return this.json("POST", `${this.projectPath(org, name)}/previews/${encodeURIComponent(preview)}/promote`);
|
|
511
|
+
}
|
|
512
|
+
/**
|
|
513
|
+
* The project's share link — `<label>.share.<app-domain>`, the one address
|
|
514
|
+
* Studio hands to somebody who is not a developer (docs/studio.md §6.9).
|
|
515
|
+
*
|
|
516
|
+
* 404 when the project has never been shared: a link is minted by
|
|
517
|
+
* `putShareLink`, never as a side effect of reading.
|
|
518
|
+
*/
|
|
519
|
+
getShareLink(org, name) {
|
|
520
|
+
return this.json("GET", `${this.projectPath(org, name)}/share`);
|
|
521
|
+
}
|
|
522
|
+
/**
|
|
523
|
+
* Points the share link at a preview, minting the label if there is none.
|
|
524
|
+
*
|
|
525
|
+
* Idempotent: the label is kept across shares, so somebody holding the link
|
|
526
|
+
* keeps working. `rotate` mints a new label and retires the old name in the
|
|
527
|
+
* same request ("링크 재발급"), so the project never has two live links.
|
|
528
|
+
*/
|
|
529
|
+
putShareLink(org, name, opts = {}) {
|
|
530
|
+
return this.json("PUT", `${this.projectPath(org, name)}/share`, {
|
|
531
|
+
...(opts.preview === undefined ? {} : { preview: opts.preview }),
|
|
532
|
+
...(opts.rotate === undefined ? {} : { rotate: opts.rotate }),
|
|
117
533
|
});
|
|
118
534
|
}
|
|
119
|
-
/**
|
|
535
|
+
/** Stops the link answering and forgets the label. The preview keeps running. */
|
|
536
|
+
deleteShareLink(org, name) {
|
|
537
|
+
return this.json("DELETE", `${this.projectPath(org, name)}/share`);
|
|
538
|
+
}
|
|
539
|
+
/** Idempotent. Called twice, the password is not rolled and the same connection details come back. */
|
|
120
540
|
createDatabase(org, name) {
|
|
121
541
|
return this.json("POST", `/v1/orgs/${encodeURIComponent(org)}/projects/${encodeURIComponent(name)}/database`);
|
|
122
542
|
}
|
|
@@ -124,17 +544,18 @@ export class Client {
|
|
|
124
544
|
return this.json("GET", `/v1/orgs/${encodeURIComponent(org)}/projects/${encodeURIComponent(name)}/database`);
|
|
125
545
|
}
|
|
126
546
|
/**
|
|
127
|
-
*
|
|
128
|
-
* viewer
|
|
547
|
+
* The connection credentials as well. The route is split from `getDatabase`
|
|
548
|
+
* because of roles — a viewer may know whether there is a database, but not
|
|
549
|
+
* the password (proto/openapi.yaml).
|
|
129
550
|
*/
|
|
130
551
|
getDatabaseConnect(org, name) {
|
|
131
552
|
return this.json("GET", `/v1/orgs/${encodeURIComponent(org)}/projects/${encodeURIComponent(name)}/database/connect`);
|
|
132
553
|
}
|
|
133
|
-
/**
|
|
554
|
+
/** The endpoint only — no credentials. A viewer gets it too. Used by `runlot port-forward`. */
|
|
134
555
|
getDatabaseEndpoint(org, name) {
|
|
135
556
|
return this.json("GET", `${dbPath(org, name)}/endpoint`);
|
|
136
557
|
}
|
|
137
|
-
/**
|
|
558
|
+
/** Issues a short-lived machine credential. The password is carried in this response and nowhere else. */
|
|
138
559
|
createDatabaseToken(org, name, ttlSeconds) {
|
|
139
560
|
return this.json("POST", `${dbPath(org, name)}/tokens`, ttlSeconds === undefined ? {} : { ttlSeconds });
|
|
140
561
|
}
|
|
@@ -145,52 +566,84 @@ export class Client {
|
|
|
145
566
|
return this.json("DELETE", `${dbPath(org, name)}/tokens/${encodeURIComponent(user)}`);
|
|
146
567
|
}
|
|
147
568
|
/**
|
|
148
|
-
*
|
|
569
|
+
* Makes one diagnostic image.
|
|
149
570
|
*
|
|
150
|
-
*
|
|
151
|
-
*
|
|
152
|
-
* (proto/openapi.yaml).
|
|
571
|
+
* **Not idempotent** — every call makes another image. And it is slow: the
|
|
572
|
+
* response comes after the dump finishes, and that project's actor is held
|
|
573
|
+
* for the whole of it (proto/openapi.yaml).
|
|
153
574
|
*/
|
|
154
575
|
exportDatabase(org, name) {
|
|
155
576
|
return this.json("POST", `/v1/orgs/${encodeURIComponent(org)}/projects/${encodeURIComponent(name)}/database/export`);
|
|
156
577
|
}
|
|
157
578
|
/**
|
|
158
|
-
*
|
|
159
|
-
*
|
|
579
|
+
* Every generation a restore can choose, newest first. `lastCheckedAt` is the
|
|
580
|
+
* heartbeat of the no-change skip — it is what tells "no new generations"
|
|
581
|
+
* apart from "the backup is dead".
|
|
160
582
|
*/
|
|
161
583
|
listGenerations(org, name) {
|
|
162
584
|
return this.json("GET", `${this.dbPath(org, name)}/generations`);
|
|
163
585
|
}
|
|
164
586
|
/**
|
|
165
|
-
*
|
|
587
|
+
* Runs one statement in the project's database (the dashboard console).
|
|
588
|
+
*
|
|
589
|
+
* `readOnly` is **omitted, not sent as false**, when the caller wants the safe
|
|
590
|
+
* mode: the server treats an absent field as read-only, so leaving it out is the
|
|
591
|
+
* one spelling that cannot be misread. Sending `false` is the explicit ask for
|
|
592
|
+
* write mode, and only then does the server run outside a transaction.
|
|
593
|
+
*
|
|
594
|
+
* SQL failures arrive as an `ApiError` whose body carries `details.sqlstate` —
|
|
595
|
+
* PostgreSQL's own code, which is what the error panel shows.
|
|
596
|
+
*/
|
|
597
|
+
executeSQL(org, name, sql, opts = {}) {
|
|
598
|
+
const body = { sql };
|
|
599
|
+
if (opts.readOnly === false)
|
|
600
|
+
body.readOnly = false;
|
|
601
|
+
if (opts.params !== undefined && opts.params.length > 0)
|
|
602
|
+
body.params = opts.params;
|
|
603
|
+
return this.json("POST", `${this.dbPath(org, name)}/execute`, body);
|
|
604
|
+
}
|
|
605
|
+
/**
|
|
606
|
+
* Rolls back to a generation. **Writes made since then are lost.**
|
|
166
607
|
*
|
|
167
|
-
*
|
|
168
|
-
* `getDatabaseOperation
|
|
169
|
-
*
|
|
608
|
+
* It ends at 202 — what comes back is an operation id, and progress is read
|
|
609
|
+
* through `getDatabaseOperation`. The server does not resolve `latest`: the
|
|
610
|
+
* `(epoch, seq)` chosen from the list is carried as-is (proto/openapi.yaml).
|
|
170
611
|
*/
|
|
171
612
|
restoreDatabase(org, name, epoch, seq) {
|
|
172
613
|
return this.json("POST", `${this.dbPath(org, name)}/restore`, { epoch, seq });
|
|
173
614
|
}
|
|
174
615
|
/**
|
|
175
|
-
*
|
|
176
|
-
*
|
|
616
|
+
* Rolls back to a restore point **inside** a backup (pg-feather docs/37):
|
|
617
|
+
* `txnId` is that commit, `at` is the last commit at or before that time. One
|
|
618
|
+
* backup carries the commits in between in order, so the place you can roll
|
|
619
|
+
* back to is not tied to a backup boundary. Everything else is as in
|
|
620
|
+
* restoreDatabase — 202, an operation id, and one safety backup before the
|
|
621
|
+
* rollback.
|
|
622
|
+
*/
|
|
623
|
+
restoreDatabaseTo(org, name, target) {
|
|
624
|
+
return this.json("POST", `${this.dbPath(org, name)}/restore`, target);
|
|
625
|
+
}
|
|
626
|
+
/**
|
|
627
|
+
* Removes the database. `confirm` has to match the project name **exactly**;
|
|
628
|
+
* if it does not, the server refuses with 400 `confirm_mismatch`.
|
|
177
629
|
*/
|
|
178
630
|
deleteDatabase(org, name, confirm) {
|
|
179
631
|
return this.json("POST", `${this.dbPath(org, name)}/delete`, { confirm });
|
|
180
632
|
}
|
|
181
|
-
/**
|
|
633
|
+
/** The progress of one operation. The operation id is not a credential; it lives under the project path. */
|
|
182
634
|
getDatabaseOperation(org, name, opId) {
|
|
183
635
|
return this.json("GET", `${this.dbPath(org, name)}/operations/${encodeURIComponent(opId)}`);
|
|
184
636
|
}
|
|
185
|
-
/**
|
|
637
|
+
/** Aborts an operation that has not yet reached a phase it cannot come back from. */
|
|
186
638
|
abortDatabaseOperation(org, name, opId) {
|
|
187
639
|
return this.json("POST", `${this.dbPath(org, name)}/operations/${encodeURIComponent(opId)}/abort`);
|
|
188
640
|
}
|
|
189
641
|
// ---- Phase 6 (docs/phase6.md) ----
|
|
190
642
|
/**
|
|
191
|
-
*
|
|
192
|
-
*
|
|
193
|
-
*
|
|
643
|
+
* A live tail of the logs. It is **a stream, not JSON**, so it does not go
|
|
644
|
+
* through `request` — what comes back is an async iterable of line-by-line
|
|
645
|
+
* `LogEvent`, and aborting `signal` closes the connection. An error response
|
|
646
|
+
* (4xx/5xx) is the same `ApiError` as in every other method.
|
|
194
647
|
*/
|
|
195
648
|
async *tailLogs(org, name, opts = {}) {
|
|
196
649
|
const q = new URLSearchParams();
|
|
@@ -210,7 +663,7 @@ export class Client {
|
|
|
210
663
|
body = (await res.json());
|
|
211
664
|
}
|
|
212
665
|
catch {
|
|
213
|
-
//
|
|
666
|
+
// The same reason as in request above.
|
|
214
667
|
}
|
|
215
668
|
throw new ApiError(res.status, body, `GET ${path} → ${res.status}`);
|
|
216
669
|
}
|
|
@@ -238,14 +691,35 @@ export class Client {
|
|
|
238
691
|
yield JSON.parse(rest);
|
|
239
692
|
}
|
|
240
693
|
finally {
|
|
241
|
-
//
|
|
694
|
+
// If the consumer ends early (break), the server's follow has to end too.
|
|
242
695
|
await reader.cancel().catch(() => { });
|
|
243
696
|
}
|
|
244
697
|
}
|
|
698
|
+
/**
|
|
699
|
+
* The stored lane (0062). It is a plain JSON page, not a stream: the history
|
|
700
|
+
* does not reach a node, so it answers for a project that is cold, parked, or
|
|
701
|
+
* has moved since the lines were written — every one of which is a 409 on
|
|
702
|
+
* `tailLogs`.
|
|
703
|
+
*
|
|
704
|
+
* `q` is a plain substring, matched case-insensitively. It is not a regular
|
|
705
|
+
* expression — `%` and `_` match themselves.
|
|
706
|
+
*
|
|
707
|
+
* Paging is keyset: pass the `cursor` from a page back to get the next, older
|
|
708
|
+
* one. A page with no `cursor` is the end of what is kept.
|
|
709
|
+
*/
|
|
710
|
+
getLogHistory(org, name, opts = {}) {
|
|
711
|
+
const params = new URLSearchParams();
|
|
712
|
+
for (const [k, v] of Object.entries(opts)) {
|
|
713
|
+
if (v !== undefined && v !== "")
|
|
714
|
+
params.set(k, String(v));
|
|
715
|
+
}
|
|
716
|
+
const qs = params.size ? `?${params}` : "";
|
|
717
|
+
return this.json("GET", `${this.projectPath(org, name)}/logs/history${qs}`);
|
|
718
|
+
}
|
|
245
719
|
listSecrets(org, name) {
|
|
246
720
|
return this.json("GET", `${this.projectPath(org, name)}/secrets`);
|
|
247
721
|
}
|
|
248
|
-
/**
|
|
722
|
+
/** The value travels in this call only. It is in no response at all. */
|
|
249
723
|
setSecret(org, name, secret, value) {
|
|
250
724
|
return this.json("PUT", `${this.projectPath(org, name)}/secrets/${encodeURIComponent(secret)}`, { value });
|
|
251
725
|
}
|
|
@@ -256,111 +730,339 @@ export class Client {
|
|
|
256
730
|
const q = hours === undefined ? "" : `?hours=${hours}`;
|
|
257
731
|
return this.json("GET", `${this.projectPath(org, name)}/usage${q}`);
|
|
258
732
|
}
|
|
259
|
-
// ----
|
|
260
|
-
/**
|
|
733
|
+
// ---- Object storage (docs/storage.md §8) ----
|
|
734
|
+
/** Grant, prefix, quota, usage. `usedBytes` lags by the node's reporting interval. */
|
|
261
735
|
getStorage(org, name) {
|
|
262
736
|
return this.json("GET", `${this.projectPath(org, name)}/storage`);
|
|
263
737
|
}
|
|
264
738
|
/**
|
|
265
|
-
*
|
|
266
|
-
*
|
|
267
|
-
*
|
|
739
|
+
* Grants storage. It is idempotent, so pressing twice leaves the prefix as it
|
|
740
|
+
* was. Taking neither the prefix nor the quota as an argument is the point —
|
|
741
|
+
* the prefix is the isolation boundary and the quota is set by the plan
|
|
742
|
+
* (proto/openapi.yaml).
|
|
268
743
|
*/
|
|
269
744
|
grantStorage(org, name) {
|
|
270
745
|
return this.json("POST", `${this.projectPath(org, name)}/storage`);
|
|
271
746
|
}
|
|
272
|
-
/**
|
|
747
|
+
/** Removes the grant. **The objects are not deleted** (docs/storage.md §7). */
|
|
273
748
|
revokeStorage(org, name) {
|
|
274
749
|
return this.json("DELETE", `${this.projectPath(org, name)}/storage`);
|
|
275
750
|
}
|
|
276
|
-
// ---- 최종 사용자 인증 (docs/auth.md §9) ----
|
|
277
751
|
/**
|
|
278
|
-
*
|
|
279
|
-
*
|
|
752
|
+
* The key prefixes this project serves unsigned (docs/storage.md §4.7).
|
|
753
|
+
*
|
|
754
|
+
* A prefix is stored normalized — `assets` becomes `assets/`, and `/` becomes
|
|
755
|
+
* the empty string, which means every key. The value that comes back is the
|
|
756
|
+
* value that governs, so a screen must render the response rather than what
|
|
757
|
+
* the user typed.
|
|
758
|
+
*/
|
|
759
|
+
listStoragePublic(org, name) {
|
|
760
|
+
return this.json("GET", `${this.projectPath(org, name)}/storage/public`);
|
|
761
|
+
}
|
|
762
|
+
/** Publishes a prefix. Idempotent. All three verbs answer with the whole list. */
|
|
763
|
+
addStoragePublic(org, name, prefix) {
|
|
764
|
+
return this.json("POST", `${this.projectPath(org, name)}/storage/public`, { prefix });
|
|
765
|
+
}
|
|
766
|
+
/**
|
|
767
|
+
* Unpublishes a prefix. Idempotent.
|
|
280
768
|
*
|
|
281
|
-
*
|
|
282
|
-
*
|
|
769
|
+
* **The world keeps reading for up to a minute.** The object front caches the
|
|
770
|
+
* list, so this call is not a revocation that takes effect at the instant it
|
|
771
|
+
* returns — a screen that says "no longer public" the moment this resolves is
|
|
772
|
+
* telling a small lie.
|
|
773
|
+
*/
|
|
774
|
+
removeStoragePublic(org, name, prefix) {
|
|
775
|
+
return this.json("DELETE", `${this.projectPath(org, name)}/storage/public`, { prefix });
|
|
776
|
+
}
|
|
777
|
+
// ---- Email (docs/email.md §5) ----
|
|
778
|
+
/** Grant, address, sender, limits, recent counts. The address comes back as a preview even without a grant. */
|
|
779
|
+
getEmail(org, name) {
|
|
780
|
+
return this.json("GET", `${this.projectPath(org, name)}/email`);
|
|
781
|
+
}
|
|
782
|
+
/** Turns it on. **Idempotent** — we choose the address. The deploy reads `"email": true` and calls this. */
|
|
783
|
+
grantEmail(org, name) {
|
|
784
|
+
return this.json("POST", `${this.projectPath(org, name)}/email`);
|
|
785
|
+
}
|
|
786
|
+
/** Turns it off. Mail arriving at that address now gets a 550. */
|
|
787
|
+
revokeEmail(org, name) {
|
|
788
|
+
return this.json("DELETE", `${this.projectPath(org, name)}/email`);
|
|
789
|
+
}
|
|
790
|
+
// ---- Custom sending domains (docs/email.md §2.4) ----
|
|
791
|
+
/** The project's own sending domains, each with the records to publish. */
|
|
792
|
+
listEmailDomains(org, name) {
|
|
793
|
+
return this.json("GET", `${this.projectPath(org, name)}/email/domains`);
|
|
794
|
+
}
|
|
795
|
+
/**
|
|
796
|
+
* Creates the provider identity and answers with the records to publish.
|
|
797
|
+
* `publish` writes them into the zone when we host one covering the domain.
|
|
798
|
+
*/
|
|
799
|
+
addEmailDomain(org, name, domain, publish = false) {
|
|
800
|
+
return this.json("POST", `${this.projectPath(org, name)}/email/domains`, { domain, publish });
|
|
801
|
+
}
|
|
802
|
+
/** Re-checks now. The background loop does the same once a minute while pending. */
|
|
803
|
+
verifyEmailDomain(org, name, domain) {
|
|
804
|
+
return this.json("POST", `${this.projectPath(org, name)}/email/domains/${encodeURIComponent(domain)}/verify`);
|
|
805
|
+
}
|
|
806
|
+
/** Deletes the identity and the row. Sending from it is refused from the next convergence. */
|
|
807
|
+
removeEmailDomain(org, name, domain) {
|
|
808
|
+
return this.json("DELETE", `${this.projectPath(org, name)}/email/domains/${encodeURIComponent(domain)}`);
|
|
809
|
+
}
|
|
810
|
+
// ---- AI (docs/ai.md §6) ----
|
|
811
|
+
/**
|
|
812
|
+
* The model catalogue. **Being logged in is enough to see it** — what you can
|
|
813
|
+
* buy is not an organization's secret, and this list is the price table.
|
|
814
|
+
*
|
|
815
|
+
* Prices are integer **micro-cents** per million tokens (1 µ¢ = 1e-8 USD).
|
|
816
|
+
* Not letting the server pick the decimal place is the point — a small call
|
|
817
|
+
* rounded to cents becomes 0.
|
|
818
|
+
*/
|
|
819
|
+
listAIModels() {
|
|
820
|
+
return this.json("GET", "/v1/ai/models");
|
|
821
|
+
}
|
|
822
|
+
/** Grant, limits, the org balance, 24 h usage. The limits come back as a preview even without a grant. */
|
|
823
|
+
getAI(org, name) {
|
|
824
|
+
return this.json("GET", `${this.projectPath(org, name)}/ai`);
|
|
825
|
+
}
|
|
826
|
+
/** Turns it on. **Idempotent.** The deploy reads `"ai": true` and calls this. */
|
|
827
|
+
grantAI(org, name) {
|
|
828
|
+
return this.json("POST", `${this.projectPath(org, name)}/ai`);
|
|
829
|
+
}
|
|
830
|
+
/**
|
|
831
|
+
* Lends the org's own Claude/Codex subscriptions to this project's
|
|
832
|
+
* `anthropic/*` and `openai/*` calls (docs/studio-byos-ai.md §3.1).
|
|
833
|
+
*
|
|
834
|
+
* **Omitting a field leaves it as it was**, so turning lending on does not
|
|
835
|
+
* clear a fallback that was already set. Admin only: the subscription that
|
|
836
|
+
* carries the vendor-terms risk belongs to a person, not to the org.
|
|
837
|
+
*/
|
|
838
|
+
patchAI(org, name, body) {
|
|
839
|
+
return this.json("PATCH", `${this.projectPath(org, name)}/ai`, body);
|
|
840
|
+
}
|
|
841
|
+
/** Turns it off. **The ledger and the balance are untouched** — the balance belongs to the org and the grant belongs to the project. */
|
|
842
|
+
revokeAI(org, name) {
|
|
843
|
+
return this.json("DELETE", `${this.projectPath(org, name)}/ai`);
|
|
844
|
+
}
|
|
845
|
+
/** The org's credit balance and its automatic top-up settings. The balance is in micro-cents and can be negative. */
|
|
846
|
+
getAICredit(org) {
|
|
847
|
+
return this.json("GET", `/v1/orgs/${encodeURIComponent(org)}/ai/credit`);
|
|
848
|
+
}
|
|
849
|
+
/** One page of the org ledger. The cursor is `ledger_id` — cutting on time splits the same millisecond. */
|
|
850
|
+
listAILedger(org, opts = {}) {
|
|
851
|
+
const q = new URLSearchParams();
|
|
852
|
+
if (opts.limit)
|
|
853
|
+
q.set("limit", String(opts.limit));
|
|
854
|
+
if (opts.before)
|
|
855
|
+
q.set("before", String(opts.before));
|
|
856
|
+
const qs = q.toString();
|
|
857
|
+
return this.json("GET", `/v1/orgs/${encodeURIComponent(org)}/ai/ledger${qs ? "?" + qs : ""}`);
|
|
858
|
+
}
|
|
859
|
+
/**
|
|
860
|
+
* The credit top-up checkout. **A browser coming back is not evidence** — the
|
|
861
|
+
* one thing that raises the balance is the `order.paid` webhook, and the
|
|
862
|
+
* screen polls the balance after the success event.
|
|
863
|
+
*/
|
|
864
|
+
createAICreditCheckout(org, microCents, returnTo) {
|
|
865
|
+
return this.json("POST", `/v1/orgs/${encodeURIComponent(org)}/ai/credit/checkout`, { microCents, returnTo });
|
|
866
|
+
}
|
|
867
|
+
/**
|
|
868
|
+
* Turns automatic top-up on or off. **Turning it on is explicit consent**
|
|
869
|
+
* (docs/ai.md §3.5) — the screen shows the charging terms verbatim and calls
|
|
870
|
+
* this only after the box is checked.
|
|
871
|
+
*/
|
|
872
|
+
setAIAutoTopup(org, body) {
|
|
873
|
+
return this.json("PUT", `/v1/orgs/${encodeURIComponent(org)}/ai/autotopup`, body);
|
|
874
|
+
}
|
|
875
|
+
/** One page of the mail log (docs/email.md §6.1). Newest first, cursor-paged. */
|
|
876
|
+
listMailLog(org, name, opts = {}) {
|
|
877
|
+
const q = new URLSearchParams();
|
|
878
|
+
if (opts.direction)
|
|
879
|
+
q.set("direction", opts.direction);
|
|
880
|
+
if (opts.cursor)
|
|
881
|
+
q.set("cursor", opts.cursor);
|
|
882
|
+
if (opts.limit)
|
|
883
|
+
q.set("limit", String(opts.limit));
|
|
884
|
+
const qs = q.toString();
|
|
885
|
+
return this.json("GET", `${this.projectPath(org, name)}/email/log${qs ? "?" + qs : ""}`);
|
|
886
|
+
}
|
|
887
|
+
/** The metadata of one message. */
|
|
888
|
+
getMailLog(org, name, mailId) {
|
|
889
|
+
return this.json("GET", `${this.projectPath(org, name)}/email/log/${encodeURIComponent(mailId)}`);
|
|
890
|
+
}
|
|
891
|
+
/** The URL of the raw message — the screen uses it as a download link (.eml). */
|
|
892
|
+
mailLogRawURL(org, name, mailId) {
|
|
893
|
+
return new URL(`${this.projectPath(org, name)}/email/log/${encodeURIComponent(mailId)}/raw`, this.opts.baseUrl).toString();
|
|
894
|
+
}
|
|
895
|
+
/** The raw text. What the detail view draws the headers and body from. */
|
|
896
|
+
getMailLogRaw(org, name, mailId) {
|
|
897
|
+
return this.text("GET", `${this.projectPath(org, name)}/email/log/${encodeURIComponent(mailId)}/raw`);
|
|
898
|
+
}
|
|
899
|
+
// ---- End-user authentication (docs/auth.md §9) ----
|
|
900
|
+
/**
|
|
901
|
+
* Grant, settings, providers, hosts. **The signed-up users do not come** —
|
|
902
|
+
* that table is inside the project DB (docs/auth.md §6) and only the worker's
|
|
903
|
+
* `env.auth` sees it.
|
|
904
|
+
*
|
|
905
|
+
* `providers` carries the client id only. The client secret is sealed and
|
|
906
|
+
* appears in no response.
|
|
283
907
|
*/
|
|
284
908
|
getAuth(org, name) {
|
|
285
909
|
return this.json("GET", `${this.projectPath(org, name)}/auth`);
|
|
286
910
|
}
|
|
287
911
|
/**
|
|
288
|
-
*
|
|
912
|
+
* Turns auth on (member). Idempotent.
|
|
289
913
|
*
|
|
290
|
-
*
|
|
291
|
-
*
|
|
292
|
-
*
|
|
914
|
+
* **With no database it is 409 `database_required`** — the user table lives
|
|
915
|
+
* inside the project DB, so standing up the grant alone leaves no table the
|
|
916
|
+
* moment the worker starts. The caller catches that code and points at the
|
|
917
|
+
* `"database": true` declaration — the deploy never sees this code, because
|
|
918
|
+
* its ordering rules it out.
|
|
293
919
|
*/
|
|
294
920
|
grantAuth(org, name) {
|
|
295
921
|
return this.json("POST", `${this.projectPath(org, name)}/auth`);
|
|
296
922
|
}
|
|
297
923
|
/**
|
|
298
|
-
*
|
|
299
|
-
*
|
|
300
|
-
*
|
|
924
|
+
* Changes the settings (member). **A partial update** — only the fields given
|
|
925
|
+
* change. Sending the whole thing on one switch means that when two people
|
|
926
|
+
* touch the same card, the later save overwrites the earlier one. With no
|
|
927
|
+
* grant it is 404 `not_granted`.
|
|
301
928
|
*/
|
|
302
929
|
updateAuthSettings(org, name, settings) {
|
|
303
930
|
return this.json("PATCH", `${this.projectPath(org, name)}/auth`, { settings });
|
|
304
931
|
}
|
|
305
932
|
/**
|
|
306
|
-
*
|
|
307
|
-
*
|
|
933
|
+
* Turns auth off (admin). **The signed-up users are not deleted** — the
|
|
934
|
+
* `runlot_auth` tables stay in the project DB, and turning it back on lets the
|
|
935
|
+
* same people log in unchanged.
|
|
308
936
|
*/
|
|
309
937
|
revokeAuth(org, name) {
|
|
310
938
|
return this.json("DELETE", `${this.projectPath(org, name)}/auth`);
|
|
311
939
|
}
|
|
312
940
|
/**
|
|
313
|
-
*
|
|
941
|
+
* Registers or replaces a social provider (admin). It is the same PUT, so it
|
|
942
|
+
* is idempotent.
|
|
943
|
+
*
|
|
944
|
+
* **`clientSecret` cannot be read back.** The callback URL is
|
|
945
|
+
* `https://<host>/__runlot/auth/callback/<provider>` for each host, and the
|
|
946
|
+
* list of hosts is in the response's `hosts`.
|
|
314
947
|
*
|
|
315
|
-
*
|
|
316
|
-
* `
|
|
317
|
-
*
|
|
948
|
+
* `issuer` is the base URL of your own GitHub Enterprise Server installation,
|
|
949
|
+
* and only `github` takes one. **This PUT is the whole row** — the same reason
|
|
950
|
+
* `clientSecret` has to be sent every time — so an empty string clears it and
|
|
951
|
+
* puts that provider back on github.com. The key is left out entirely when the
|
|
952
|
+
* argument is omitted, so a caller that does not know about issuers sends the
|
|
953
|
+
* body it always sent.
|
|
954
|
+
*/
|
|
955
|
+
setAuthProvider(org, name, provider, clientId, clientSecret, issuer) {
|
|
956
|
+
return this.json("PUT", `${this.projectPath(org, name)}/auth/providers/${encodeURIComponent(provider)}`, { clientId, clientSecret, ...(issuer === undefined ? {} : { issuer }) });
|
|
957
|
+
}
|
|
958
|
+
/**
|
|
959
|
+
* Turns on the Runlot provider (admin): "Continue with Runlot", with email,
|
|
960
|
+
* Google and GitHub at Runlot behind it and nothing to register. 409
|
|
961
|
+
* `runlot_unavailable` when this deployment has no sign-in broker.
|
|
962
|
+
*/
|
|
963
|
+
setRunlotAuthProvider(org, name) {
|
|
964
|
+
return this.json("PUT", `${this.projectPath(org, name)}/auth/providers/runlot`, { kind: "runlot" });
|
|
965
|
+
}
|
|
966
|
+
/**
|
|
967
|
+
* Registers or replaces a generic OIDC provider under a project-chosen id
|
|
968
|
+
* (admin). The CP reads `<issuer>/.well-known/openid-configuration` when
|
|
969
|
+
* saving; a failure is 400 `oidc_discovery_failed` quoting the provider.
|
|
970
|
+
*/
|
|
971
|
+
setOidcAuthProvider(org, name, id, body) {
|
|
972
|
+
return this.json("PUT", `${this.projectPath(org, name)}/auth/providers/${encodeURIComponent(id)}`, { kind: "oidc", ...body });
|
|
973
|
+
}
|
|
974
|
+
/**
|
|
975
|
+
* The statements that create the `runlot_auth` schema (member). 404 when
|
|
976
|
+
* login is not turned on for the project.
|
|
318
977
|
*/
|
|
319
|
-
|
|
320
|
-
return this.json("
|
|
978
|
+
getAuthSchema(org, name) {
|
|
979
|
+
return this.json("GET", `${this.projectPath(org, name)}/auth/schema`);
|
|
980
|
+
}
|
|
981
|
+
/** The project's sign-in branding with defaults filled (docs/custom-sign-in.md §12.3). */
|
|
982
|
+
getAuthBranding(org, name) {
|
|
983
|
+
return this.getAuthBrandingAnswer(org, name).then((a) => a.brand);
|
|
984
|
+
}
|
|
985
|
+
/** The GET answer whole: the filled brand plus the methods the chooser would draw now. */
|
|
986
|
+
getAuthBrandingAnswer(org, name) {
|
|
987
|
+
return this.json("GET", `${this.projectPath(org, name)}/auth/branding`);
|
|
321
988
|
}
|
|
322
989
|
/**
|
|
323
|
-
*
|
|
324
|
-
*
|
|
990
|
+
* Replaces the whole branding object (member). Validated server-side; a bad
|
|
991
|
+
* field is 400 `invalid_branding` with `fields: [{path, message}]`.
|
|
992
|
+
*/
|
|
993
|
+
putAuthBranding(org, name, branding) {
|
|
994
|
+
return this.json("PUT", `${this.projectPath(org, name)}/auth/branding`, branding)
|
|
995
|
+
.then((a) => a.brand);
|
|
996
|
+
}
|
|
997
|
+
/**
|
|
998
|
+
* The URL of the rendered chooser with (draft) branding (§12.4). A page, not
|
|
999
|
+
* JSON: the dashboard puts it in an iframe and the CLI opens it in a browser.
|
|
1000
|
+
* `draft` travels as base64url JSON.
|
|
1001
|
+
*/
|
|
1002
|
+
authBrandingPreviewUrl(org, name, opts = {}) {
|
|
1003
|
+
const u = new URL(`${this.projectPath(org, name)}/auth/branding/preview`, this.opts.baseUrl);
|
|
1004
|
+
if (opts.lang)
|
|
1005
|
+
u.searchParams.set("lang", opts.lang);
|
|
1006
|
+
if (opts.theme)
|
|
1007
|
+
u.searchParams.set("theme", opts.theme);
|
|
1008
|
+
if (opts.state)
|
|
1009
|
+
u.searchParams.set("state", opts.state);
|
|
1010
|
+
if (opts.draft)
|
|
1011
|
+
u.searchParams.set("draft", base64urlJson(opts.draft));
|
|
1012
|
+
return u.toString();
|
|
1013
|
+
}
|
|
1014
|
+
/** Sign-in funnel counters for the last `days` days (§9.4). No per-person data. */
|
|
1015
|
+
getAuthFunnel(org, name, days = 30) {
|
|
1016
|
+
return this.json("GET", `${this.projectPath(org, name)}/auth/funnel?days=${encodeURIComponent(String(days))}`);
|
|
1017
|
+
}
|
|
1018
|
+
/**
|
|
1019
|
+
* Removes a provider (admin). Someone who signed up only through that provider
|
|
1020
|
+
* loses their way in, but the user row stays — register it again and they come
|
|
1021
|
+
* back to the same account.
|
|
325
1022
|
*/
|
|
326
1023
|
deleteAuthProvider(org, name, provider) {
|
|
327
1024
|
return this.json("DELETE", `${this.projectPath(org, name)}/auth/providers/${encodeURIComponent(provider)}`);
|
|
328
1025
|
}
|
|
329
|
-
// ----
|
|
1026
|
+
// ---- Deployment access control (docs/access.md §7) ----
|
|
330
1027
|
/**
|
|
331
|
-
*
|
|
332
|
-
*
|
|
1028
|
+
* Who can reach this deployment. **No values** — both the password and the
|
|
1029
|
+
* bypass secret live only as hashes, and what comes back here is the fact that
|
|
1030
|
+
* there is one: `hasPassword` and `hasBypass`.
|
|
333
1031
|
*
|
|
334
|
-
*
|
|
335
|
-
*
|
|
1032
|
+
* A project that has never set a policy is `mode: "public"` with no
|
|
1033
|
+
* `updatedAt`. The screen tells those two apart for the reason in §7 — a
|
|
1034
|
+
* sentence about the state instead of an empty state.
|
|
336
1035
|
*/
|
|
337
1036
|
getAccess(org, name) {
|
|
338
1037
|
return this.json("GET", `${this.projectPath(org, name)}/access`);
|
|
339
1038
|
}
|
|
340
1039
|
/**
|
|
341
|
-
*
|
|
342
|
-
*
|
|
1040
|
+
* Changes the policy (admin). Without a `password`, **the existing password
|
|
1041
|
+
* stays** — if a save that only changes the mode wiped the password, coming
|
|
1042
|
+
* back to that mode would mean setting it again.
|
|
343
1043
|
*/
|
|
344
1044
|
setAccess(org, name, mode, password) {
|
|
345
1045
|
return this.json("PUT", `${this.projectPath(org, name)}/access`, { mode, password });
|
|
346
1046
|
}
|
|
347
1047
|
/**
|
|
348
|
-
*
|
|
349
|
-
*
|
|
1048
|
+
* Makes a bypass secret for automation (admin). **The value is in this answer
|
|
1049
|
+
* and nowhere else** — the screen shows it once on arrival and can never fetch
|
|
1050
|
+
* it again. Calling again kills the old value.
|
|
350
1051
|
*/
|
|
351
1052
|
newAccessBypass(org, name) {
|
|
352
1053
|
return this.json("POST", `${this.projectPath(org, name)}/access/bypass`);
|
|
353
1054
|
}
|
|
354
|
-
/**
|
|
1055
|
+
/** Removes the bypass (admin). Removing one that does not exist also succeeds. */
|
|
355
1056
|
revokeAccessBypass(org, name) {
|
|
356
1057
|
return this.json("DELETE", `${this.projectPath(org, name)}/access/bypass`);
|
|
357
1058
|
}
|
|
358
1059
|
/**
|
|
359
|
-
*
|
|
1060
|
+
* Gets a one-time address back into a protected deployment (docs/access.md §3.4-3).
|
|
360
1061
|
*
|
|
361
|
-
*
|
|
362
|
-
* (
|
|
363
|
-
*
|
|
1062
|
+
* It is **not** under the project path: all the calling screen knows is the
|
|
1063
|
+
* hostname (the original request went there), and the server derives the org
|
|
1064
|
+
* and project names from it. Doing `location.replace` with the `redirect` that
|
|
1065
|
+
* comes back is the caller's job.
|
|
364
1066
|
*/
|
|
365
1067
|
authorizeAccess(to, next) {
|
|
366
1068
|
return this.json("POST", "/v1/access/authorize", { to, next });
|
|
@@ -368,44 +1070,79 @@ export class Client {
|
|
|
368
1070
|
listMembers(org) {
|
|
369
1071
|
return this.json("GET", `/v1/orgs/${encodeURIComponent(org)}/members`);
|
|
370
1072
|
}
|
|
371
|
-
/**
|
|
1073
|
+
/** This is not an invite — the user must already have logged in once (404 `user_not_found`). */
|
|
372
1074
|
addMember(org, provider, subject, role) {
|
|
373
1075
|
return this.json("POST", `/v1/orgs/${encodeURIComponent(org)}/members`, { provider, subject, role });
|
|
374
1076
|
}
|
|
375
1077
|
setMemberRole(org, userId, role) {
|
|
376
1078
|
return this.json("PUT", `/v1/orgs/${encodeURIComponent(org)}/members/${encodeURIComponent(userId)}`, { role });
|
|
377
1079
|
}
|
|
1080
|
+
/**
|
|
1081
|
+
* Removing someone else is admin; **removing yourself is leaving**, which
|
|
1082
|
+
* anyone can do (docs/members.md). The last admin can do neither
|
|
1083
|
+
* (409 `last_admin`).
|
|
1084
|
+
*/
|
|
378
1085
|
removeMember(org, userId) {
|
|
379
1086
|
return this.json("DELETE", `/v1/orgs/${encodeURIComponent(org)}/members/${encodeURIComponent(userId)}`);
|
|
380
1087
|
}
|
|
1088
|
+
// --- Invites (docs/members.md) ---
|
|
1089
|
+
/** Pending and expired invites (admin). Accepted and revoked ones are history, so they do not come. */
|
|
1090
|
+
listInvites(org) {
|
|
1091
|
+
return this.json("GET", `/v1/orgs/${encodeURIComponent(org)}/invites`);
|
|
1092
|
+
}
|
|
1093
|
+
/**
|
|
1094
|
+
* Invites by email (admin). **Calling again with the same address is a
|
|
1095
|
+
* resend** — the same row is updated rather than a new one created, and the
|
|
1096
|
+
* server gives 200 instead of 201.
|
|
1097
|
+
*/
|
|
1098
|
+
createInvite(org, email, role) {
|
|
1099
|
+
return this.json("POST", `/v1/orgs/${encodeURIComponent(org)}/invites`, { email, role });
|
|
1100
|
+
}
|
|
1101
|
+
/** Revokes an invite (admin). Mail that has not gone out yet does not go out. */
|
|
1102
|
+
revokeInvite(org, inviteId) {
|
|
1103
|
+
return this.json("DELETE", `/v1/orgs/${encodeURIComponent(org)}/invites/${encodeURIComponent(inviteId)}`);
|
|
1104
|
+
}
|
|
1105
|
+
/**
|
|
1106
|
+
* A preview of the invite. **No session needed** — whoever got the link has
|
|
1107
|
+
* not logged in yet, and they need to know what they are accepting before
|
|
1108
|
+
* they do.
|
|
1109
|
+
*/
|
|
1110
|
+
getInvite(token) {
|
|
1111
|
+
return this.json("GET", `/v1/invites/${encodeURIComponent(token)}`);
|
|
1112
|
+
}
|
|
1113
|
+
/** Accepts (login required). If they are already a member the role does not change. */
|
|
1114
|
+
acceptInvite(token) {
|
|
1115
|
+
return this.json("POST", `/v1/invites/${encodeURIComponent(token)}/accept`);
|
|
1116
|
+
}
|
|
381
1117
|
// --- domains: D1 hostnames methods ---
|
|
382
|
-
/**
|
|
1118
|
+
/** The default hostname and the custom domains come together (viewer). */
|
|
383
1119
|
listHostnames(org, name) {
|
|
384
1120
|
return this.json("GET", `${this.projectPath(org, name)}/hostnames`);
|
|
385
1121
|
}
|
|
386
1122
|
/**
|
|
387
|
-
*
|
|
1123
|
+
* Attaches a custom domain (member).
|
|
388
1124
|
*
|
|
389
|
-
*
|
|
390
|
-
*
|
|
1125
|
+
* Idempotent — sending the same name again returns the existing row
|
|
1126
|
+
* unchanged. The response's `verify` is the CNAME and TXT the customer has to
|
|
1127
|
+
* add.
|
|
391
1128
|
*/
|
|
392
|
-
addHostname(org, name, hostname) {
|
|
393
|
-
return this.json("POST", `${this.projectPath(org, name)}/hostnames`, { hostname });
|
|
1129
|
+
addHostname(org, name, hostname, role) {
|
|
1130
|
+
return this.json("POST", `${this.projectPath(org, name)}/hostnames`, role === undefined ? { hostname } : { hostname, role });
|
|
394
1131
|
}
|
|
395
|
-
/**
|
|
1132
|
+
/** Runs the same check the background verifier makes, right now (member). */
|
|
396
1133
|
verifyHostname(org, name, host) {
|
|
397
1134
|
return this.json("POST", `${this.projectPath(org, name)}/hostnames/${encodeURIComponent(host)}/verify`);
|
|
398
1135
|
}
|
|
399
|
-
/**
|
|
1136
|
+
/** Detaches a custom domain (member). The default hostname gives a 400. */
|
|
400
1137
|
deleteHostname(org, name, host) {
|
|
401
1138
|
return this.json("DELETE", `${this.projectPath(org, name)}/hostnames/${encodeURIComponent(host)}`);
|
|
402
1139
|
}
|
|
403
1140
|
// --- domains: D2 dns methods ---
|
|
404
|
-
/**
|
|
1141
|
+
/** The organization's zones. No `rrsets` — those ride only on a single-zone lookup. */
|
|
405
1142
|
listZones(org) {
|
|
406
1143
|
return this.json("GET", this.dnsPath(org));
|
|
407
1144
|
}
|
|
408
|
-
/**
|
|
1145
|
+
/** Idempotent. A zone that already exists comes back unchanged. */
|
|
409
1146
|
createZone(org, name) {
|
|
410
1147
|
return this.json("POST", this.dnsPath(org), { name });
|
|
411
1148
|
}
|
|
@@ -416,8 +1153,9 @@ export class Client {
|
|
|
416
1153
|
return this.json("DELETE", `${this.dnsPath(org)}/${encodeURIComponent(zone)}`);
|
|
417
1154
|
}
|
|
418
1155
|
/**
|
|
419
|
-
*
|
|
420
|
-
*
|
|
1156
|
+
* Replaces one rrset **whole**. `records` is the complete new set for that
|
|
1157
|
+
* (name, type), so adding a single value means sending the current ones with
|
|
1158
|
+
* it.
|
|
421
1159
|
*/
|
|
422
1160
|
putRRset(org, zone, name, type, ttl, records) {
|
|
423
1161
|
return this.json("PUT", this.rrsetPath(org, zone, name, type), { ttl, records });
|
|
@@ -433,39 +1171,40 @@ export class Client {
|
|
|
433
1171
|
setZoneDS(org, zone, ds) {
|
|
434
1172
|
return this.json("PUT", `${this.dnsPath(org)}/${encodeURIComponent(zone)}/dnssec/ds`, { ds });
|
|
435
1173
|
}
|
|
436
|
-
/**
|
|
1174
|
+
/** The shared prefix of the DNS surface. */
|
|
437
1175
|
dnsPath(org) {
|
|
438
1176
|
return `/v1/orgs/${encodeURIComponent(org)}/dns/zones`;
|
|
439
1177
|
}
|
|
440
|
-
/** `@`
|
|
1178
|
+
/** Both `@` and `*` arrive as a name. Keeps the same string out of four places. */
|
|
441
1179
|
rrsetPath(org, zone, name, type) {
|
|
442
1180
|
return (`${this.dnsPath(org)}/${encodeURIComponent(zone)}` +
|
|
443
1181
|
`/rrsets/${encodeURIComponent(name)}/${encodeURIComponent(type)}`);
|
|
444
1182
|
}
|
|
445
1183
|
// --- domains: D3 domains methods ---
|
|
446
1184
|
/**
|
|
447
|
-
*
|
|
1185
|
+
* Looks a name up (member or above).
|
|
448
1186
|
*
|
|
449
|
-
* `priceCents`
|
|
450
|
-
*
|
|
451
|
-
*
|
|
1187
|
+
* `priceCents` is the first year of registration; `renewalCents` is one year
|
|
1188
|
+
* of renewal. They are separate because a first-year discount is common —
|
|
1189
|
+
* folded into one, the screen cannot say "buy it for $1, then $15 next year".
|
|
452
1190
|
*/
|
|
453
1191
|
checkDomains(org, names) {
|
|
454
1192
|
return this.json("POST", `${this.domainsPath(org)}/check`, { names });
|
|
455
1193
|
}
|
|
456
1194
|
/**
|
|
457
|
-
*
|
|
1195
|
+
* Buys a domain (admin — this spends money).
|
|
458
1196
|
*
|
|
459
|
-
* **ICANN
|
|
460
|
-
*
|
|
1197
|
+
* **The ICANN verification mail goes to `contact.email`.** The screen has to
|
|
1198
|
+
* say so before the purchase (docs/domains.md §5.5).
|
|
461
1199
|
*
|
|
462
|
-
*
|
|
463
|
-
*
|
|
1200
|
+
* Sending the same request again is safe — a finished domain comes back
|
|
1201
|
+
* unchanged, and a purchase that stopped part way resumes from where it
|
|
1202
|
+
* stopped.
|
|
464
1203
|
*/
|
|
465
1204
|
purchaseDomain(org, body) {
|
|
466
1205
|
return this.json("POST", this.domainsPath(org), body);
|
|
467
1206
|
}
|
|
468
|
-
/**
|
|
1207
|
+
/** Imports a domain you already own (admin). Creates the zone only; the registrar is not called. */
|
|
469
1208
|
importDomain(org, name) {
|
|
470
1209
|
return this.json("POST", `${this.domainsPath(org)}/import`, { name });
|
|
471
1210
|
}
|
|
@@ -479,11 +1218,11 @@ export class Client {
|
|
|
479
1218
|
return this.json("POST", `${this.domainPath(org, name)}/renew`, { years });
|
|
480
1219
|
}
|
|
481
1220
|
/**
|
|
482
|
-
*
|
|
1221
|
+
* Changes only the **intent** to auto-renew.
|
|
483
1222
|
*
|
|
484
|
-
*
|
|
485
|
-
*
|
|
486
|
-
*
|
|
1223
|
+
* Auto-renew at the registrar stays on — a domain is an asset you lose if you
|
|
1224
|
+
* are a day late, so we renew first and bill afterwards. The screen has to say
|
|
1225
|
+
* this alongside.
|
|
487
1226
|
*/
|
|
488
1227
|
setDomainAutoRenew(org, name, enabled) {
|
|
489
1228
|
return this.json("POST", `${this.domainPath(org, name)}/auto-renew`, { enabled });
|
|
@@ -491,29 +1230,131 @@ export class Client {
|
|
|
491
1230
|
setDomainLock(org, name, locked) {
|
|
492
1231
|
return this.json("POST", `${this.domainPath(org, name)}/lock`, { locked });
|
|
493
1232
|
}
|
|
494
|
-
/**
|
|
1233
|
+
/** The transfer auth code. The audit records that one was issued and **not the code itself**. */
|
|
495
1234
|
domainAuthCode(org, name) {
|
|
496
1235
|
return this.json("POST", `${this.domainPath(org, name)}/auth-code`);
|
|
497
1236
|
}
|
|
498
|
-
/**
|
|
1237
|
+
/** Re-reads from the registrar right now (member). */
|
|
499
1238
|
syncDomain(org, name) {
|
|
500
1239
|
return this.json("POST", `${this.domainPath(org, name)}/sync`);
|
|
501
1240
|
}
|
|
502
|
-
/**
|
|
1241
|
+
/** The shared prefix of the domain surface. Keeps the same string out of ten places. */
|
|
503
1242
|
domainsPath(org) {
|
|
504
1243
|
return `/v1/orgs/${encodeURIComponent(org)}/domains`;
|
|
505
1244
|
}
|
|
506
1245
|
domainPath(org, name) {
|
|
507
1246
|
return `${this.domainsPath(org)}/${encodeURIComponent(name)}`;
|
|
508
1247
|
}
|
|
509
|
-
/**
|
|
1248
|
+
/** The shared prefix of the project surface. */
|
|
510
1249
|
projectPath(org, name) {
|
|
511
1250
|
return `/v1/orgs/${encodeURIComponent(org)}/projects/${encodeURIComponent(name)}`;
|
|
512
1251
|
}
|
|
513
|
-
/**
|
|
1252
|
+
/** The shared prefix of the database surface. Keeps the same string out of five places. */
|
|
514
1253
|
dbPath(org, name) {
|
|
515
1254
|
return `/v1/orgs/${encodeURIComponent(org)}/projects/${encodeURIComponent(name)}/database`;
|
|
516
1255
|
}
|
|
1256
|
+
// ---- Self-hosted Git (docs/git-hosting.md §12.1, §19) ----
|
|
1257
|
+
//
|
|
1258
|
+
// **git does the repository work and we handle only the metadata.** That is
|
|
1259
|
+
// why there is nothing like `pushRepo` here — an API that wraps git either
|
|
1260
|
+
// reimplements every one of git's flags or boxes the user in.
|
|
1261
|
+
//
|
|
1262
|
+
// A repository **belongs to a project**. That is why every method starts with
|
|
1263
|
+
// (org, project) — the same shape as the database and the secrets.
|
|
1264
|
+
listRepos(org, project) {
|
|
1265
|
+
return this.json("GET", this.repoPath(org, project));
|
|
1266
|
+
}
|
|
1267
|
+
createRepo(org, project, body) {
|
|
1268
|
+
return this.json("POST", this.repoPath(org, project), body);
|
|
1269
|
+
}
|
|
1270
|
+
getRepo(org, project, name) {
|
|
1271
|
+
return this.json("GET", `${this.repoPath(org, project)}/${encodeURIComponent(name)}`);
|
|
1272
|
+
}
|
|
1273
|
+
updateRepo(org, project, name, body) {
|
|
1274
|
+
return this.json("PATCH", `${this.repoPath(org, project)}/${encodeURIComponent(name)}`, body);
|
|
1275
|
+
}
|
|
1276
|
+
deleteRepo(org, project, name) {
|
|
1277
|
+
return this.json("DELETE", `${this.repoPath(org, project)}/${encodeURIComponent(name)}`);
|
|
1278
|
+
}
|
|
1279
|
+
/** The ref history. The lead for recovering a commit lost to a force-push is here. */
|
|
1280
|
+
listRefUpdates(org, project, name) {
|
|
1281
|
+
return this.json("GET", `${this.repoPath(org, project)}/${encodeURIComponent(name)}/ref-updates`);
|
|
1282
|
+
}
|
|
1283
|
+
// Push-to-deploy (docs/code/push-to-deploy). The hook hangs off the
|
|
1284
|
+
// repository and the builds off the **project**, because a build outlives the
|
|
1285
|
+
// repository it came from.
|
|
1286
|
+
getDeployHook(org, project, name) {
|
|
1287
|
+
return this.json("GET", `${this.repoPath(org, project)}/${encodeURIComponent(name)}/deploy-hook`);
|
|
1288
|
+
}
|
|
1289
|
+
setDeployHook(org, project, name, body) {
|
|
1290
|
+
return this.json("PUT", `${this.repoPath(org, project)}/${encodeURIComponent(name)}/deploy-hook`, body);
|
|
1291
|
+
}
|
|
1292
|
+
deleteDeployHook(org, project, name) {
|
|
1293
|
+
return this.json("DELETE", `${this.repoPath(org, project)}/${encodeURIComponent(name)}/deploy-hook`);
|
|
1294
|
+
}
|
|
1295
|
+
/** Build a commit without pushing. Omit `commitSha` for the hooked branch's tip. */
|
|
1296
|
+
deployRepoNow(org, project, name, commitSha) {
|
|
1297
|
+
return this.json("POST", `${this.repoPath(org, project)}/${encodeURIComponent(name)}/deploy`, commitSha === undefined ? {} : { commitSha });
|
|
1298
|
+
}
|
|
1299
|
+
listBuilds(org, project, limit) {
|
|
1300
|
+
const q = limit === undefined ? "" : `?limit=${limit}`;
|
|
1301
|
+
return this.json("GET", `${this.projectPath(org, project)}/builds${q}`);
|
|
1302
|
+
}
|
|
1303
|
+
getBuild(org, project, buildId) {
|
|
1304
|
+
return this.json("GET", `${this.projectPath(org, project)}/builds/${encodeURIComponent(buildId)}`);
|
|
1305
|
+
}
|
|
1306
|
+
/**
|
|
1307
|
+
* A build's output. It comes back as **text**, not JSON — see the endpoint's
|
|
1308
|
+
* description. `json()` would try to parse it and fail on the first line.
|
|
1309
|
+
*/
|
|
1310
|
+
getBuildLog(org, project, buildId) {
|
|
1311
|
+
return this.text("GET", `${this.projectPath(org, project)}/builds/${encodeURIComponent(buildId)}/log`);
|
|
1312
|
+
}
|
|
1313
|
+
cancelBuild(org, project, buildId) {
|
|
1314
|
+
return this.json("POST", `${this.projectPath(org, project)}/builds/${encodeURIComponent(buildId)}/cancel`);
|
|
1315
|
+
}
|
|
1316
|
+
listSSHKeys() {
|
|
1317
|
+
return this.json("GET", "/v1/me/ssh-keys");
|
|
1318
|
+
}
|
|
1319
|
+
addSSHKey(publicKey, name) {
|
|
1320
|
+
return this.json("POST", "/v1/me/ssh-keys", { publicKey, name });
|
|
1321
|
+
}
|
|
1322
|
+
deleteSSHKey(keyId) {
|
|
1323
|
+
return this.json("DELETE", `/v1/me/ssh-keys/${encodeURIComponent(keyId)}`);
|
|
1324
|
+
}
|
|
1325
|
+
listAccessTokens() {
|
|
1326
|
+
return this.json("GET", "/v1/me/tokens");
|
|
1327
|
+
}
|
|
1328
|
+
/** The plaintext is carried in this response **once** and never again. */
|
|
1329
|
+
createAccessToken(body) {
|
|
1330
|
+
return this.json("POST", "/v1/me/tokens", body);
|
|
1331
|
+
}
|
|
1332
|
+
revokeAccessToken(tokenId) {
|
|
1333
|
+
return this.json("DELETE", `/v1/me/tokens/${encodeURIComponent(tokenId)}`);
|
|
1334
|
+
}
|
|
1335
|
+
// ---- Browsing (docs/git-hosting.md §12.2) ----
|
|
1336
|
+
getRepoRefs(org, project, name) {
|
|
1337
|
+
return this.json("GET", `${this.repoPath(org, project)}/${encodeURIComponent(name)}/refs`);
|
|
1338
|
+
}
|
|
1339
|
+
getRepoTree(org, project, name, ref = "", path = "") {
|
|
1340
|
+
return this.json("GET", `${this.repoPath(org, project)}/${encodeURIComponent(name)}/tree${gitQuery(ref, path)}`);
|
|
1341
|
+
}
|
|
1342
|
+
getRepoBlob(org, project, name, ref = "", path = "") {
|
|
1343
|
+
return this.json("GET", `${this.repoPath(org, project)}/${encodeURIComponent(name)}/blob${gitQuery(ref, path)}`);
|
|
1344
|
+
}
|
|
1345
|
+
getRepoCommits(org, project, name, ref = "", limit) {
|
|
1346
|
+
const q = new URLSearchParams();
|
|
1347
|
+
if (ref !== "")
|
|
1348
|
+
q.set("ref", ref);
|
|
1349
|
+
if (limit !== undefined)
|
|
1350
|
+
q.set("limit", String(limit));
|
|
1351
|
+
const qs = q.size > 0 ? `?${q.toString()}` : "";
|
|
1352
|
+
return this.json("GET", `${this.repoPath(org, project)}/${encodeURIComponent(name)}/commits${qs}`);
|
|
1353
|
+
}
|
|
1354
|
+
/** The shared prefix of the repository surface. It sits under the project (§19). */
|
|
1355
|
+
repoPath(org, project) {
|
|
1356
|
+
return `${this.projectPath(org, project)}/repos`;
|
|
1357
|
+
}
|
|
517
1358
|
rollback(org, name, version) {
|
|
518
1359
|
return this.json("POST", `/v1/orgs/${encodeURIComponent(org)}/projects/${encodeURIComponent(name)}/rollback`, { version });
|
|
519
1360
|
}
|