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