sandcovery 0.6.1 → 0.7.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,566 @@
1
+ import { $ as AutoTopUp, $t as Literals, A as CreatedKey, At as ProcessId, Bs as isSome, Bt as update, C as API_PREFIX, Cn as decodeUnknownSync, Ct as Forbidden, Dt as CiJobId, E as Offer, Et as ActivityList, F as FileList, Ft as getAndSet, G as CiInstallationList, It as getAndUpdate, J as GitHubId, K as CiJob, Ks as some, L as DetachedExec, Lt as increment, M as KeyList, Mt as SandboxId, Ns as fromNullishOr, Nt as UsageShareId, Ot as CredentialId, P as FileEntry, Pt as get, Q as ProviderBoardEntry, Qt as Literal, Rs as getOrUndefined, Rt as make, Sn as decodeUnknownOption, St as InvalidRequest, Tn as is, Tt as ConcurrencyLimitReached, U as ProviderCredential, Us as match, V as ExecResult, Vt as updateAndGet, W as ProviderCredentialList, Ws as none, X as ProviderCatalog, Xt as Int, Z as ProviderBoard, _ as Usage, _t as Sandbox, a as StatsShare, b as UsageTotals, bt as Snapshot, c as SharedUsage, cn as String$1, ct as Unauthorized, d as EstimateList, dt as ProviderError, et as AutoTopUpChange, ft as NotFound, gt as PortPreview, h as MonthlyCostList, ht as Port, i as Stats, j as Key, jt as Provider, kt as KeyId, l as UsageShare, ln as Struct, lt as SpendLimitReached, mn as Union, n as XAccountStatus, nn as NullOr, nt as Billing, ot as Pricing, p as LiveUsage, pt as NoProviderAvailable, q as CiJobList, r as SharedStats, rn as Number$1, rt as CreditCheckout, s as ShareToken, st as Unsupported, t as XAccountLink, u as UsageShareList, ut as RateLimited, vt as SandboxList, wn as fromJsonString, wt as Conflict, x as Process, xc as isNotNull, xt as SnapshotList, z as ExecEvent, zs as isNone, zt as set } from "./x-account-BSasf-z-.mjs";
2
+ // ../sandcovery-contract/src/errors/api-error.ts
3
+ const ApiError = Union([
4
+ ConcurrencyLimitReached,
5
+ Conflict,
6
+ Forbidden,
7
+ InvalidRequest,
8
+ NoProviderAvailable,
9
+ NotFound,
10
+ ProviderError,
11
+ RateLimited,
12
+ SpendLimitReached,
13
+ Unauthorized,
14
+ Unsupported
15
+ ]);
16
+ // ../sandcovery-contract/src/attach.ts
17
+ const ATTACH_PROTOCOL = "sandcovery-attach-v1";
18
+ const STDIN = 0;
19
+ const STDOUT = 1;
20
+ const STDERR = 2;
21
+ const HEADER_BYTES = 9;
22
+ const CHUNK_BYTES = 65536;
23
+ const UNACKNOWLEDGED_LIMIT_BYTES = 8388608;
24
+ const NORMAL_CLOSURE = 1e3;
25
+ const REPLACED = 4e3;
26
+ const RETRY_MS = [
27
+ 250,
28
+ 1e3,
29
+ 2e3,
30
+ 5e3
31
+ ];
32
+ const CHECK_MS = 15e3;
33
+ const LOST = "The sandbox ended before the process reported an exit, so its exit is unknown.";
34
+ const REPLACED_MESSAGE = "Another client attached to the process, which detached this one.";
35
+ const ABORTED = "The attach was aborted.";
36
+ const OUTPUT_NAMES = /* @__PURE__ */ new Map([[STDOUT, "stdout"], [STDERR, "stderr"]]);
37
+ const ProcessExit = Struct({
38
+ code: Int,
39
+ signal: NullOr(String$1)
40
+ });
41
+ const RelayMessageJson = fromJsonString(Union([
42
+ Struct({ type: Literals(["ready", "waiting"]) }),
43
+ Struct({
44
+ offset: Number$1,
45
+ stream: Literal("stdin"),
46
+ type: Literal("ack")
47
+ }),
48
+ Struct({
49
+ ...ProcessExit.fields,
50
+ type: Literal("exit")
51
+ })
52
+ ]));
53
+ const frame = (stream, offset, data) => {
54
+ const bytes = new Uint8Array(HEADER_BYTES + data.length);
55
+ const header = new DataView(bytes.buffer);
56
+ header.setUint8(0, stream);
57
+ header.setBigUint64(1, BigInt(offset));
58
+ bytes.set(data, HEADER_BYTES);
59
+ return bytes;
60
+ };
61
+ const attach = ({ check, credential, options, url }) => {
62
+ const done = Promise.withResolvers();
63
+ const listening = new AbortController();
64
+ const received = /* @__PURE__ */ new Map();
65
+ const sinks = /* @__PURE__ */ new Map([[STDOUT, options.stdout], [STDERR, options.stderr]]);
66
+ const drained = make([]);
67
+ const ended = make(false);
68
+ const finished = make(false);
69
+ const ready = make(false);
70
+ const resizeMessage = make(none());
71
+ const retries = make(0);
72
+ const signals = make([]);
73
+ const socket = make(null);
74
+ const stdinAcked = make(0);
75
+ const stdinEnd = make(0);
76
+ const synced = make(false);
77
+ const timer = make(none());
78
+ const unacknowledged = make([]);
79
+ const release = () => {
80
+ getAndSet(drained, []).forEach((waiting) => {
81
+ waiting.resolve(null);
82
+ });
83
+ };
84
+ const stop = () => {
85
+ set(finished, true);
86
+ set(ready, false);
87
+ clearTimeout(getOrUndefined(get(timer)));
88
+ listening.abort();
89
+ get(socket)?.close(NORMAL_CLOSURE);
90
+ set(socket, null);
91
+ release();
92
+ };
93
+ const fail = (error) => {
94
+ if (!get(finished)) {
95
+ stop();
96
+ done.reject(error);
97
+ }
98
+ };
99
+ const aborted = () => {
100
+ const reason = options.signal?.reason;
101
+ fail(reason instanceof Error ? reason : new Error(ABORTED, { cause: reason }));
102
+ };
103
+ const alive = async () => {
104
+ const [checked] = await Promise.allSettled([check()]);
105
+ if (checked.status === "fulfilled" && checked.value.status === "lost") fail(/* @__PURE__ */ new Error(LOST));
106
+ if (checked.status === "rejected") {
107
+ const reason = checked.reason;
108
+ if (reason instanceof Error && is(ApiError)(reason.cause)) fail(reason);
109
+ }
110
+ return !get(finished);
111
+ };
112
+ const watch = () => {
113
+ clearTimeout(getOrUndefined(get(timer)));
114
+ set(timer, some(setTimeout(() => {
115
+ (async () => {
116
+ if (await alive() && !get(ready) && get(socket) !== null) watch();
117
+ })();
118
+ }, CHECK_MS)));
119
+ };
120
+ const resend = () => {
121
+ const open = get(socket);
122
+ const size = get(resizeMessage);
123
+ get(unacknowledged).forEach(({ data, offset }) => {
124
+ open?.send(frame(STDIN, offset, data));
125
+ });
126
+ if (get(ended)) open?.send(JSON.stringify({
127
+ offset: get(stdinEnd),
128
+ stream: "stdin",
129
+ type: "eof"
130
+ }));
131
+ if (isSome(size)) open?.send(size.value);
132
+ getAndSet(signals, []).forEach((name) => {
133
+ open?.send(JSON.stringify({
134
+ name,
135
+ type: "signal"
136
+ }));
137
+ });
138
+ };
139
+ const receive = (event) => {
140
+ const data = event.data;
141
+ if (data instanceof ArrayBuffer) {
142
+ const bytes = new Uint8Array(data);
143
+ const stream = bytes[0] ?? STDIN;
144
+ const name = fromNullishOr(OUTPUT_NAMES.get(stream));
145
+ if (bytes.length < HEADER_BYTES || isNone(name)) return;
146
+ const offset = Number(new DataView(bytes.buffer, bytes.byteOffset).getBigUint64(1));
147
+ const known = received.get(stream) ?? offset;
148
+ if (offset > known) return;
149
+ const fresh = bytes.subarray(HEADER_BYTES + known - offset);
150
+ const acknowledged = known + fresh.length;
151
+ if (fresh.length > 0) {
152
+ received.set(stream, acknowledged);
153
+ sinks.get(stream)?.(fresh);
154
+ }
155
+ get(socket)?.send(JSON.stringify({
156
+ offset: acknowledged,
157
+ stream: name.value,
158
+ type: "ack"
159
+ }));
160
+ return;
161
+ }
162
+ const decoded = decodeUnknownOption(RelayMessageJson)(data);
163
+ if (isNone(decoded)) return;
164
+ const message = decoded.value;
165
+ switch (message.type) {
166
+ case "ready":
167
+ set(ready, true);
168
+ set(retries, 0);
169
+ clearTimeout(getOrUndefined(get(timer)));
170
+ if (get(synced)) resend();
171
+ break;
172
+ case "waiting":
173
+ set(ready, false);
174
+ watch();
175
+ break;
176
+ case "ack":
177
+ if (get(synced)) {
178
+ const acked = updateAndGet(stdinAcked, (current) => Math.max(current, message.offset));
179
+ update(unacknowledged, (chunks) => chunks.filter((chunk) => chunk.offset + chunk.data.length > acked));
180
+ if (get(stdinEnd) - acked <= UNACKNOWLEDGED_LIMIT_BYTES) release();
181
+ break;
182
+ }
183
+ set(synced, true);
184
+ set(stdinAcked, message.offset);
185
+ update(stdinEnd, (end) => end + message.offset);
186
+ update(unacknowledged, (chunks) => chunks.map((chunk) => ({
187
+ data: chunk.data,
188
+ offset: chunk.offset + message.offset
189
+ })));
190
+ if (get(ready)) resend();
191
+ break;
192
+ case "exit": if (!get(finished)) {
193
+ stop();
194
+ done.resolve({
195
+ code: message.code,
196
+ signal: message.signal
197
+ });
198
+ }
199
+ }
200
+ };
201
+ const connect = () => {
202
+ const opened = new WebSocket(url, [ATTACH_PROTOCOL, credential].filter(isNotNull));
203
+ const reconnect = async () => {
204
+ if (await alive() && get(socket) === null) connect();
205
+ };
206
+ opened.binaryType = "arraybuffer";
207
+ opened.addEventListener("message", receive);
208
+ opened.addEventListener("close", (event) => {
209
+ if (opened !== get(socket) || get(finished)) return;
210
+ set(socket, null);
211
+ set(ready, false);
212
+ if (event.code === REPLACED) {
213
+ fail(/* @__PURE__ */ new Error(REPLACED_MESSAGE));
214
+ return;
215
+ }
216
+ const delay = RETRY_MS[Math.min(get(retries), RETRY_MS.length - 1)];
217
+ increment(retries);
218
+ clearTimeout(getOrUndefined(get(timer)));
219
+ set(timer, some(setTimeout(() => {
220
+ reconnect();
221
+ }, delay)));
222
+ });
223
+ set(socket, opened);
224
+ watch();
225
+ };
226
+ if (options.signal?.aborted === true) aborted();
227
+ else {
228
+ options.signal?.addEventListener("abort", aborted, {
229
+ once: true,
230
+ signal: listening.signal
231
+ });
232
+ connect();
233
+ }
234
+ return {
235
+ endStdin: () => {
236
+ if (get(ended) || get(finished)) return;
237
+ set(ended, true);
238
+ if (get(ready) && get(synced)) get(socket)?.send(JSON.stringify({
239
+ offset: get(stdinEnd),
240
+ stream: "stdin",
241
+ type: "eof"
242
+ }));
243
+ },
244
+ get exit() {
245
+ return done.promise;
246
+ },
247
+ resize: (cols, rows) => {
248
+ const message = JSON.stringify({
249
+ cols,
250
+ rows,
251
+ type: "resize"
252
+ });
253
+ set(resizeMessage, some(message));
254
+ if (get(ready) && get(synced)) get(socket)?.send(message);
255
+ },
256
+ sendSignal: (name) => {
257
+ if (get(finished)) return;
258
+ if (get(ready) && get(synced)) get(socket)?.send(JSON.stringify({
259
+ name,
260
+ type: "signal"
261
+ }));
262
+ else update(signals, (names) => [...names, name]);
263
+ },
264
+ write: async (data) => {
265
+ if (get(ended) || get(finished)) return;
266
+ Array.from({ length: Math.ceil(data.length / CHUNK_BYTES) }, (_, index) => data.slice(index * CHUNK_BYTES, (index + 1) * CHUNK_BYTES)).forEach((chunk) => {
267
+ const offset = getAndUpdate(stdinEnd, (end) => end + chunk.length);
268
+ update(unacknowledged, (chunks) => [...chunks, {
269
+ data: chunk,
270
+ offset
271
+ }]);
272
+ if (get(ready) && get(synced)) get(socket)?.send(frame(STDIN, offset, chunk));
273
+ });
274
+ if (get(stdinEnd) - get(stdinAcked) > UNACKNOWLEDGED_LIMIT_BYTES) {
275
+ const waiting = Promise.withResolvers();
276
+ update(drained, (all) => [...all, waiting]);
277
+ await waiting.promise;
278
+ }
279
+ }
280
+ };
281
+ };
282
+ // src/index.ts
283
+ const STREAM_FAILURE_EVENT = "effect/http-api/stream/failure";
284
+ const X_ACCOUNT_PATH = "/x-account";
285
+ const AUTO_TOP_UP_PATH = "/billing/auto-top-up";
286
+ const DETACHED_OUTPUT = {
287
+ signal: null,
288
+ stderr: null,
289
+ stdout: null
290
+ };
291
+ const USAGE_SHARES_PATH = "/usage/shares";
292
+ const STATS_SHARE_PATH = "/stats/share";
293
+ var Sandcovery = class {
294
+ activity;
295
+ billing;
296
+ ci;
297
+ credentials;
298
+ keys;
299
+ pricing;
300
+ problems;
301
+ providers;
302
+ sandboxes;
303
+ stats;
304
+ usage;
305
+ xAccount;
306
+ constructor(options = {}) {
307
+ const configuredKey = options.apiKey ?? globalThis.process?.env.SANDCOVERY_API_KEY;
308
+ const apiKey = configuredKey === "" ? void 0 : configuredKey;
309
+ const baseUrl = options.baseUrl ?? "https://www.sandcovery.com";
310
+ const send = options.fetch ?? globalThis.fetch;
311
+ const call = async (method, path, { body, headers = {}, json, query = {}, signal } = {}) => {
312
+ const url = new URL(`${API_PREFIX}${path}`, baseUrl);
313
+ for (const [key, value] of Object.entries(query)) if (value !== void 0) url.searchParams.set(key, String(value));
314
+ const sent = new Headers(headers);
315
+ if (apiKey !== void 0) sent.set("authorization", `Bearer ${apiKey}`);
316
+ if (json !== void 0) sent.set("content-type", "application/json");
317
+ const response = await send(url, {
318
+ body: json === void 0 ? body : JSON.stringify(json),
319
+ headers: sent,
320
+ method,
321
+ signal
322
+ });
323
+ if (!response.ok) {
324
+ const text = await response.text();
325
+ throw match(decodeUnknownOption(fromJsonString(ApiError))(text), {
326
+ onNone: () => new Error(`Sandcovery answered ${response.status}`, { cause: {
327
+ body: text,
328
+ status: response.status
329
+ } }),
330
+ onSome: (answer) => new Error(answer.message, { cause: answer })
331
+ });
332
+ }
333
+ return response;
334
+ };
335
+ const read = async (schema, method, path, request) => {
336
+ const text = await (await call(method, path, request)).text();
337
+ return decodeUnknownSync(fromJsonString(schema))(text);
338
+ };
339
+ this.sandboxes = {
340
+ attachProcess: (sandboxId, processId, attachOptions = DETACHED_OUTPUT) => {
341
+ const path = `/sandboxes/${decodeUnknownSync(SandboxId)(sandboxId)}/processes/${decodeUnknownSync(ProcessId)(processId)}`;
342
+ const url = new URL(`${API_PREFIX}${path}/attach`, baseUrl);
343
+ url.protocol = url.protocol === "https:" ? "wss:" : "ws:";
344
+ return attach({
345
+ check: async () => await read(Process, "GET", path, { signal: attachOptions.signal }),
346
+ credential: apiKey ?? null,
347
+ options: attachOptions,
348
+ url
349
+ });
350
+ },
351
+ create: async (request, { idempotencyKey, signal } = {}) => await read(Sandbox, "POST", "/sandboxes", {
352
+ headers: idempotencyKey === void 0 ? {} : { "idempotency-key": idempotencyKey },
353
+ json: request,
354
+ signal
355
+ }),
356
+ destroy: async (sandboxId, { signal } = {}) => await read(Sandbox, "DELETE", `/sandboxes/${decodeUnknownSync(SandboxId)(sandboxId)}`, { signal }),
357
+ downloadFile: async (sandboxId, path, { signal } = {}) => {
358
+ const response = await call("GET", `/sandboxes/${decodeUnknownSync(SandboxId)(sandboxId)}/files/content`, {
359
+ query: { path },
360
+ signal
361
+ });
362
+ if (response.body === null) throw new Error("Sandcovery answered no file body", { cause: { status: response.status } });
363
+ return response.body;
364
+ },
365
+ exec: async (sandboxId, request, { signal } = {}) => await read(ExecResult, "POST", `/sandboxes/${decodeUnknownSync(SandboxId)(sandboxId)}/exec`, {
366
+ json: request,
367
+ signal
368
+ }),
369
+ execDetached: async (sandboxId, request, { signal } = {}) => await read(DetachedExec, "POST", `/sandboxes/${decodeUnknownSync(SandboxId)(sandboxId)}/exec/detached`, {
370
+ json: request,
371
+ signal
372
+ }),
373
+ async *execStream(sandboxId, request, { signal } = {}) {
374
+ const response = await call("POST", `/sandboxes/${decodeUnknownSync(SandboxId)(sandboxId)}/exec/stream`, {
375
+ headers: { accept: "text/event-stream" },
376
+ json: request,
377
+ signal
378
+ });
379
+ if (response.body === null) return;
380
+ const chunks = response.body.pipeThrough(new TextDecoderStream());
381
+ let pending = "";
382
+ for await (const chunk of chunks) {
383
+ const text = `${pending}${chunk}`;
384
+ const cut = text.endsWith("\r") ? text.length - 1 : text.length;
385
+ const blocks = text.slice(0, cut).replaceAll("\r\n", "\n").replaceAll("\r", "\n").split("\n\n");
386
+ pending = `${blocks.pop() ?? ""}${text.slice(cut)}`;
387
+ for (const block of blocks) {
388
+ const fields = block.split("\n").flatMap((line) => {
389
+ if (line.startsWith(":")) return [];
390
+ const colon = line.indexOf(":");
391
+ if (colon === -1) return [{
392
+ name: line,
393
+ value: ""
394
+ }];
395
+ const value = line.slice(colon + 1);
396
+ return [{
397
+ name: line.slice(0, colon),
398
+ value: value.startsWith(" ") ? value.slice(1) : value
399
+ }];
400
+ });
401
+ const data = fields.flatMap(({ name, value }) => name === "data" ? [value] : []);
402
+ if (data.length === 0) continue;
403
+ if (fields.findLast(({ name }) => name === "event")?.value === STREAM_FAILURE_EVENT) throw new Error("Sandcovery failed the stream", { cause: { body: data.join("\n") } });
404
+ yield decodeUnknownSync(fromJsonString(ExecEvent))(data.join("\n"));
405
+ }
406
+ }
407
+ },
408
+ get: async (sandboxId, { signal } = {}) => await read(Sandbox, "GET", `/sandboxes/${decodeUnknownSync(SandboxId)(sandboxId)}`, { signal }),
409
+ getProcess: async (sandboxId, processId, { signal } = {}) => await read(Process, "GET", `/sandboxes/${decodeUnknownSync(SandboxId)(sandboxId)}/processes/${decodeUnknownSync(ProcessId)(processId)}`, { signal }),
410
+ list: async (query = {}, { signal } = {}) => await read(SandboxList, "GET", "/sandboxes", {
411
+ query: { ...query },
412
+ signal
413
+ }),
414
+ listFiles: async (sandboxId, path, { signal } = {}) => await read(FileList, "GET", `/sandboxes/${decodeUnknownSync(SandboxId)(sandboxId)}/files`, {
415
+ query: { path },
416
+ signal
417
+ }),
418
+ listSnapshots: async ({ signal } = {}) => await read(SnapshotList, "GET", "/snapshots", { signal }),
419
+ pause: async (sandboxId, { signal } = {}) => await read(Sandbox, "POST", `/sandboxes/${decodeUnknownSync(SandboxId)(sandboxId)}/pause`, { signal }),
420
+ portPreview: async (sandboxId, port, { signal } = {}) => await read(PortPreview, "GET", `/sandboxes/${decodeUnknownSync(SandboxId)(sandboxId)}/ports/${String(decodeUnknownSync(Port)(port))}`, { signal }),
421
+ readFile: async (sandboxId, path, { signal } = {}) => {
422
+ const response = await call("GET", `/sandboxes/${decodeUnknownSync(SandboxId)(sandboxId)}/files/content`, {
423
+ query: { path },
424
+ signal
425
+ });
426
+ return new Uint8Array(await response.arrayBuffer());
427
+ },
428
+ resume: async (sandboxId, { signal } = {}) => await read(Sandbox, "POST", `/sandboxes/${decodeUnknownSync(SandboxId)(sandboxId)}/resume`, { signal }),
429
+ snapshot: async (sandboxId, { signal } = {}) => await read(Snapshot, "POST", `/sandboxes/${decodeUnknownSync(SandboxId)(sandboxId)}/snapshot`, { signal }),
430
+ startProcess: async (sandboxId, request, { signal } = {}) => await read(Process, "POST", `/sandboxes/${decodeUnknownSync(SandboxId)(sandboxId)}/processes`, {
431
+ json: request,
432
+ signal
433
+ }),
434
+ writeFile: async (sandboxId, path, content, { signal } = {}) => await read(FileEntry, "PUT", `/sandboxes/${decodeUnknownSync(SandboxId)(sandboxId)}/files/content`, {
435
+ body: content instanceof Uint8Array ? new Uint8Array(content) : content,
436
+ headers: { "content-type": "application/octet-stream" },
437
+ query: { path },
438
+ signal
439
+ })
440
+ };
441
+ this.keys = {
442
+ create: async (request, { signal } = {}) => await read(CreatedKey, "POST", "/keys", {
443
+ json: request,
444
+ signal
445
+ }),
446
+ get: async (keyId, { signal } = {}) => await read(Key, "GET", `/keys/${decodeUnknownSync(KeyId)(keyId)}`, { signal }),
447
+ list: async ({ signal } = {}) => await read(KeyList, "GET", "/keys", { signal }),
448
+ revoke: async (keyId, { signal } = {}) => await read(Key, "DELETE", `/keys/${decodeUnknownSync(KeyId)(keyId)}`, { signal }),
449
+ update: async (keyId, request, { signal } = {}) => await read(Key, "PATCH", `/keys/${decodeUnknownSync(KeyId)(keyId)}`, {
450
+ json: request,
451
+ signal
452
+ })
453
+ };
454
+ this.credentials = {
455
+ add: async (provider, fields, { signal } = {}) => await read(ProviderCredential, "POST", `/credentials/${decodeUnknownSync(Provider)(provider)}`, {
456
+ json: fields,
457
+ signal
458
+ }),
459
+ countXPost: async (request, { signal } = {}) => await read(Offer, "POST", "/offer/x-post", {
460
+ json: request,
461
+ signal
462
+ }),
463
+ delete: async (provider, { signal } = {}) => {
464
+ await call("DELETE", `/credentials/${decodeUnknownSync(Provider)(provider)}`, { signal });
465
+ },
466
+ deleteOne: async (provider, credentialId, { signal } = {}) => {
467
+ await call("DELETE", `/credentials/${decodeUnknownSync(Provider)(provider)}/${decodeUnknownSync(CredentialId)(credentialId)}`, { signal });
468
+ },
469
+ list: async ({ signal } = {}) => await read(ProviderCredentialList, "GET", "/credentials", { signal }),
470
+ offer: async ({ signal } = {}) => await read(Offer, "GET", "/offer", { signal }),
471
+ set: async (provider, fields, { signal } = {}) => await read(ProviderCredential, "PUT", `/credentials/${decodeUnknownSync(Provider)(provider)}`, {
472
+ json: fields,
473
+ signal
474
+ })
475
+ };
476
+ this.activity = { list: async (query = {}, { signal } = {}) => await read(ActivityList, "GET", "/activity", {
477
+ query: { ...query },
478
+ signal
479
+ }) };
480
+ this.billing = {
481
+ buyCredits: async (request, { signal } = {}) => await read(CreditCheckout, "POST", "/billing/credits", {
482
+ json: request,
483
+ signal
484
+ }),
485
+ get: async ({ signal } = {}) => await read(Billing, "GET", "/billing", { signal }),
486
+ setAutoTopUp: async (request, { signal } = {}) => await read(AutoTopUpChange, "PUT", AUTO_TOP_UP_PATH, {
487
+ json: request,
488
+ signal
489
+ }),
490
+ stopAutoTopUp: async ({ signal } = {}) => await read(AutoTopUp, "DELETE", AUTO_TOP_UP_PATH, { signal })
491
+ };
492
+ this.ci = {
493
+ getJob: async (jobId, { signal } = {}) => await read(CiJob, "GET", `/ci/jobs/${decodeUnknownSync(CiJobId)(jobId)}`, { signal }),
494
+ listInstallations: async ({ signal } = {}) => await read(CiInstallationList, "GET", "/ci/installations", { signal }),
495
+ listJobs: async (query = {}, { signal } = {}) => await read(CiJobList, "GET", "/ci/jobs", {
496
+ query: { ...query },
497
+ signal
498
+ }),
499
+ unlinkInstallation: async (installationId, { signal } = {}) => {
500
+ await call("DELETE", `/ci/installations/${String(decodeUnknownSync(GitHubId)(installationId))}`, { signal });
501
+ }
502
+ };
503
+ this.pricing = {
504
+ get: async ({ signal } = {}) => await read(Pricing, "GET", "/pricing", { signal }),
505
+ monthly: async (query, { signal } = {}) => await read(MonthlyCostList, "GET", "/pricing/monthly", {
506
+ query: { ...query },
507
+ signal
508
+ })
509
+ };
510
+ this.problems = { report: async (request, { signal } = {}) => {
511
+ await call("POST", "/problem-reports", {
512
+ json: request,
513
+ signal
514
+ });
515
+ } };
516
+ this.providers = {
517
+ catalog: async ({ signal } = {}) => await read(ProviderCatalog, "GET", "/catalog", { signal }),
518
+ get: async (provider, { signal } = {}) => await read(ProviderBoardEntry, "GET", `/providers/${decodeUnknownSync(Provider)(provider)}`, { signal }),
519
+ list: async ({ signal } = {}) => await read(ProviderBoard, "GET", "/providers", { signal })
520
+ };
521
+ this.stats = {
522
+ get: async ({ signal } = {}) => await read(Stats, "GET", "/stats", { signal }),
523
+ getShare: async ({ signal } = {}) => await read(StatsShare, "GET", STATS_SHARE_PATH, { signal }),
524
+ getShared: async (token, { signal } = {}) => await read(SharedStats, "GET", `/shared-stats/${decodeUnknownSync(ShareToken)(token)}`, { signal }),
525
+ share: async ({ signal } = {}) => await read(StatsShare, "PUT", STATS_SHARE_PATH, { signal }),
526
+ unshare: async ({ signal } = {}) => {
527
+ await call("DELETE", STATS_SHARE_PATH, { signal });
528
+ }
529
+ };
530
+ this.usage = {
531
+ estimate: async (request, { signal } = {}) => await read(EstimateList, "POST", "/estimates", {
532
+ json: request,
533
+ signal
534
+ }),
535
+ get: async (query, { signal } = {}) => await read(Usage, "GET", "/usage", {
536
+ query: { ...query },
537
+ signal
538
+ }),
539
+ getShared: async (token, { signal } = {}) => await read(SharedUsage, "GET", `/shared-usage/${decodeUnknownSync(ShareToken)(token)}`, { signal }),
540
+ listShares: async ({ signal } = {}) => await read(UsageShareList, "GET", USAGE_SHARES_PATH, { signal }),
541
+ live: async (query = {}, { signal } = {}) => await read(LiveUsage, "GET", "/usage/live", {
542
+ query: { ...query },
543
+ signal
544
+ }),
545
+ revokeShare: async (shareId, { signal } = {}) => {
546
+ await call("DELETE", `${USAGE_SHARES_PATH}/${decodeUnknownSync(UsageShareId)(shareId)}`, { signal });
547
+ },
548
+ share: async (request, { signal } = {}) => await read(UsageShare, "POST", USAGE_SHARES_PATH, {
549
+ json: request,
550
+ signal
551
+ }),
552
+ totals: async (query = {}, { signal } = {}) => await read(UsageTotals, "GET", "/usage/totals", {
553
+ query: { ...query },
554
+ signal
555
+ })
556
+ };
557
+ this.xAccount = {
558
+ get: async ({ signal } = {}) => await read(XAccountStatus, "GET", X_ACCOUNT_PATH, { signal }),
559
+ link: async ({ signal } = {}) => await read(XAccountLink, "POST", X_ACCOUNT_PATH, { signal }),
560
+ unlink: async ({ signal } = {}) => {
561
+ await call("DELETE", X_ACCOUNT_PATH, { signal });
562
+ }
563
+ };
564
+ }
565
+ };
566
+ export { Sandcovery as t };