withruntime 0.2.2 → 0.3.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +70 -4
- package/dist/cli.d.ts +9 -0
- package/dist/cli.js +1291 -0
- package/dist/client.d.ts +123 -0
- package/dist/client.js +160 -0
- package/dist/credentials.d.ts +44 -0
- package/dist/credentials.js +180 -0
- package/dist/errors.d.ts +58 -0
- package/dist/errors.js +106 -0
- package/dist/index.d.ts +37 -0
- package/dist/index.js +25 -0
- package/dist/login.d.ts +119 -0
- package/dist/login.js +367 -0
- package/dist/mcp.d.ts +15 -0
- package/dist/mcp.js +221 -0
- package/dist/page.d.ts +13 -0
- package/dist/page.js +39 -0
- package/dist/products/desktop.d.ts +103 -0
- package/dist/products/desktop.js +38 -0
- package/dist/products/images.d.ts +121 -0
- package/dist/products/images.js +64 -0
- package/dist/products/index.d.ts +31 -0
- package/dist/products/index.js +37 -0
- package/dist/products/interpreter.d.ts +88 -0
- package/dist/products/interpreter.js +81 -0
- package/dist/products/limits.d.ts +25 -0
- package/dist/products/limits.js +10 -0
- package/dist/products/network.d.ts +47 -0
- package/dist/products/network.js +19 -0
- package/dist/products/previews.d.ts +54 -0
- package/dist/products/previews.js +30 -0
- package/dist/products/referrals.d.ts +36 -0
- package/dist/products/referrals.js +8 -0
- package/dist/products/volumes.d.ts +47 -0
- package/dist/products/volumes.js +27 -0
- package/dist/sandbox.d.ts +192 -0
- package/dist/sandbox.js +628 -0
- package/dist/snapshots.d.ts +50 -0
- package/dist/snapshots.js +55 -0
- package/dist/tar.d.ts +3 -0
- package/dist/tar.js +116 -0
- package/dist/transport.d.ts +65 -0
- package/dist/transport.js +261 -0
- package/dist/types.d.ts +175 -0
- package/dist/types.js +1 -0
- package/package.json +54 -8
- package/cli.js +0 -7
|
@@ -0,0 +1,88 @@
|
|
|
1
|
+
import type { Sandbox } from "../sandbox.js";
|
|
2
|
+
import type { RequestOptions, Transport } from "../transport.js";
|
|
3
|
+
export type InterpreterLanguage = "python" | "javascript";
|
|
4
|
+
export type ResultRef = {
|
|
5
|
+
path: string;
|
|
6
|
+
bytes: number;
|
|
7
|
+
sha256: string;
|
|
8
|
+
};
|
|
9
|
+
/** One rich result: a MIME bundle (text/plain, text/html, image/png as base64,
|
|
10
|
+
* application/json, application/vnd.runtime.table+json for a DataFrame). */
|
|
11
|
+
export type ExecutionResult = {
|
|
12
|
+
main: boolean;
|
|
13
|
+
data: Record<string, unknown>;
|
|
14
|
+
refs: Record<string, ResultRef>;
|
|
15
|
+
};
|
|
16
|
+
export type Execution = {
|
|
17
|
+
id: string;
|
|
18
|
+
contextId: string;
|
|
19
|
+
language: InterpreterLanguage;
|
|
20
|
+
executionCount: number | null;
|
|
21
|
+
status: "ok" | "error" | "interrupted" | "timeout" | "lost";
|
|
22
|
+
stdout: string;
|
|
23
|
+
stderr: string;
|
|
24
|
+
results: ExecutionResult[];
|
|
25
|
+
error: {
|
|
26
|
+
name: string;
|
|
27
|
+
value: string;
|
|
28
|
+
traceback: string;
|
|
29
|
+
} | null;
|
|
30
|
+
overflow: {
|
|
31
|
+
stream: "stdout" | "stderr";
|
|
32
|
+
path: string | null;
|
|
33
|
+
bytes: number;
|
|
34
|
+
dropped: number;
|
|
35
|
+
}[];
|
|
36
|
+
durationMs: number;
|
|
37
|
+
contextStarted: boolean;
|
|
38
|
+
lostBytes: number;
|
|
39
|
+
};
|
|
40
|
+
export type InterpreterContext = {
|
|
41
|
+
id: string;
|
|
42
|
+
language: InterpreterLanguage;
|
|
43
|
+
processId: string;
|
|
44
|
+
cwd: string;
|
|
45
|
+
state: string;
|
|
46
|
+
startedAt: number;
|
|
47
|
+
};
|
|
48
|
+
export type RunOptions = RequestOptions & {
|
|
49
|
+
language?: InterpreterLanguage;
|
|
50
|
+
/** A context id; "python" and "javascript" are the defaults, started on first use. */
|
|
51
|
+
context?: string;
|
|
52
|
+
timeoutMs?: number;
|
|
53
|
+
onStdout?: (text: string) => void;
|
|
54
|
+
onStderr?: (text: string) => void;
|
|
55
|
+
onResult?: (result: ExecutionResult) => void;
|
|
56
|
+
onError?: (error: {
|
|
57
|
+
name: string;
|
|
58
|
+
value: string;
|
|
59
|
+
traceback: string;
|
|
60
|
+
}) => void;
|
|
61
|
+
};
|
|
62
|
+
/** A stateful Python and JavaScript interpreter in the sandbox:
|
|
63
|
+
* `await sbx.interpreter.run("import pandas as pd; pd.DataFrame({'a': [1]})")`.
|
|
64
|
+
* Variables persist between runs of the same context, like a notebook. */
|
|
65
|
+
export declare function sandboxInterpreter(t: Transport, sandbox: Sandbox): {
|
|
66
|
+
/** Run a cell. With any of the on* callbacks, output streams as it happens. */
|
|
67
|
+
run(code: string, options?: RunOptions): Promise<Execution>;
|
|
68
|
+
contexts: {
|
|
69
|
+
list: (options?: RequestOptions) => Promise<InterpreterContext[]>;
|
|
70
|
+
create: (input?: {
|
|
71
|
+
id?: string;
|
|
72
|
+
language?: InterpreterLanguage;
|
|
73
|
+
cwd?: string;
|
|
74
|
+
env?: Record<string, string>;
|
|
75
|
+
}, options?: RequestOptions) => Promise<InterpreterContext>;
|
|
76
|
+
restart: (id: string, options?: RequestOptions) => Promise<InterpreterContext>;
|
|
77
|
+
interrupt: (id: string, options?: RequestOptions) => Promise<{
|
|
78
|
+
interrupted: boolean;
|
|
79
|
+
}>;
|
|
80
|
+
remove: (id: string, options?: RequestOptions) => Promise<{
|
|
81
|
+
deleted: boolean;
|
|
82
|
+
}>;
|
|
83
|
+
};
|
|
84
|
+
/** The bytes of a result too large to travel inline (a `refs` entry). */
|
|
85
|
+
result(ref: ResultRef | {
|
|
86
|
+
path: string;
|
|
87
|
+
}, options?: RequestOptions): Promise<Uint8Array>;
|
|
88
|
+
};
|
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
/** A stateful Python and JavaScript interpreter in the sandbox:
|
|
2
|
+
* `await sbx.interpreter.run("import pandas as pd; pd.DataFrame({'a': [1]})")`.
|
|
3
|
+
* Variables persist between runs of the same context, like a notebook. */
|
|
4
|
+
export function sandboxInterpreter(t, sandbox) {
|
|
5
|
+
const base = () => `/v1/sandboxes/${encodeURIComponent(sandbox.id)}/interpreter`;
|
|
6
|
+
return {
|
|
7
|
+
/** Run a cell. With any of the on* callbacks, output streams as it happens. */
|
|
8
|
+
async run(code, options = {}) {
|
|
9
|
+
const { language, context, timeoutMs, onStdout, onStderr, onResult, onError, ...request } = options;
|
|
10
|
+
const body = {
|
|
11
|
+
code,
|
|
12
|
+
...(language ? { language } : {}),
|
|
13
|
+
...(context ? { context } : {}),
|
|
14
|
+
...(timeoutMs ? { timeoutMs } : {}),
|
|
15
|
+
};
|
|
16
|
+
if (!onStdout && !onStderr && !onResult && !onError)
|
|
17
|
+
return t.json({ method: "POST", path: `${base()}:run`, body, ...request });
|
|
18
|
+
for await (const event of t.events({
|
|
19
|
+
method: "POST",
|
|
20
|
+
path: `${base()}:run`,
|
|
21
|
+
body: { ...body, stream: true },
|
|
22
|
+
...request,
|
|
23
|
+
})) {
|
|
24
|
+
if (event.k === "stdout")
|
|
25
|
+
onStdout?.(event.text);
|
|
26
|
+
else if (event.k === "stderr")
|
|
27
|
+
onStderr?.(event.text);
|
|
28
|
+
else if (event.k === "result")
|
|
29
|
+
onResult?.({ main: event.main, data: event.data, refs: event.refs });
|
|
30
|
+
else if (event.k === "error")
|
|
31
|
+
onError?.(event);
|
|
32
|
+
else if (event.k === "execution")
|
|
33
|
+
return event.execution;
|
|
34
|
+
else if (event.k === "failure")
|
|
35
|
+
throw new Error(`${event.code}: ${event.message}`);
|
|
36
|
+
}
|
|
37
|
+
throw new Error("The interpreter stream ended without a result");
|
|
38
|
+
},
|
|
39
|
+
contexts: {
|
|
40
|
+
list: async (options) => (await t.json({
|
|
41
|
+
method: "GET",
|
|
42
|
+
path: `${base()}/contexts`,
|
|
43
|
+
...options,
|
|
44
|
+
})).data,
|
|
45
|
+
create: (input = {}, options) => t.json({
|
|
46
|
+
method: "POST",
|
|
47
|
+
path: `${base()}/contexts`,
|
|
48
|
+
body: input,
|
|
49
|
+
...options,
|
|
50
|
+
}),
|
|
51
|
+
restart: (id, options) => t.json({
|
|
52
|
+
method: "POST",
|
|
53
|
+
path: `${base()}/contexts/${encodeURIComponent(id)}:restart`,
|
|
54
|
+
body: {},
|
|
55
|
+
...options,
|
|
56
|
+
}),
|
|
57
|
+
interrupt: (id, options) => t.json({
|
|
58
|
+
method: "POST",
|
|
59
|
+
path: `${base()}/contexts/${encodeURIComponent(id)}:interrupt`,
|
|
60
|
+
body: {},
|
|
61
|
+
...options,
|
|
62
|
+
}),
|
|
63
|
+
remove: (id, options) => t.json({
|
|
64
|
+
method: "DELETE",
|
|
65
|
+
path: `${base()}/contexts/${encodeURIComponent(id)}`,
|
|
66
|
+
...options,
|
|
67
|
+
}),
|
|
68
|
+
},
|
|
69
|
+
/** The bytes of a result too large to travel inline (a `refs` entry). */
|
|
70
|
+
result(ref, options) {
|
|
71
|
+
const match = /^\/workspace\/\.runtime\/interpreter\/([a-z0-9][a-z0-9-]*)\/out\/([A-Za-z0-9][A-Za-z0-9_.-]*)$/.exec(ref.path);
|
|
72
|
+
if (!match)
|
|
73
|
+
throw new Error("Not an interpreter result path");
|
|
74
|
+
return t.bytes({
|
|
75
|
+
method: "GET",
|
|
76
|
+
path: `${base()}/contexts/${match[1]}/results/${match[2]}`,
|
|
77
|
+
...options,
|
|
78
|
+
});
|
|
79
|
+
},
|
|
80
|
+
};
|
|
81
|
+
}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import type { RequestOptions, Transport } from "../transport.js";
|
|
2
|
+
/** What this key may do, and the daily spending limit on its agent. Money is
|
|
3
|
+
* integer microdollars in strings (1,000,000 = $1). */
|
|
4
|
+
export type KeyLimits = {
|
|
5
|
+
/** full: every action. read: every read and nothing else (a read-only key).
|
|
6
|
+
* selected: the actions the key names. */
|
|
7
|
+
access: "full" | "read" | "selected" | null;
|
|
8
|
+
daily: {
|
|
9
|
+
/** The most this agent may commit in any 24 hours, or null for no limit. */
|
|
10
|
+
limitMicros: string | null;
|
|
11
|
+
/** Committed in the last 24 hours: charges settled plus money on hold. */
|
|
12
|
+
usedMicros: string;
|
|
13
|
+
/** What is left under the limit now, or null for no limit. */
|
|
14
|
+
remainingMicros: string | null;
|
|
15
|
+
window: "24h";
|
|
16
|
+
};
|
|
17
|
+
};
|
|
18
|
+
/** `runtime.limits.get()`: whether this key is read-only, and what its agent
|
|
19
|
+
* may still spend today. An owner sets the limit at
|
|
20
|
+
* https://withruntime.com/account/keys; a key can read it, never change it.
|
|
21
|
+
* Past it, a create, wake, extension or renewal fails with
|
|
22
|
+
* `spending_limit_reached` (HTTP 402). */
|
|
23
|
+
export declare function limits(t: Transport): {
|
|
24
|
+
get: (options?: RequestOptions) => Promise<KeyLimits>;
|
|
25
|
+
};
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
/** `runtime.limits.get()`: whether this key is read-only, and what its agent
|
|
2
|
+
* may still spend today. An owner sets the limit at
|
|
3
|
+
* https://withruntime.com/account/keys; a key can read it, never change it.
|
|
4
|
+
* Past it, a create, wake, extension or renewal fails with
|
|
5
|
+
* `spending_limit_reached` (HTTP 402). */
|
|
6
|
+
export function limits(t) {
|
|
7
|
+
return {
|
|
8
|
+
get: (options) => t.json({ method: "GET", path: "/v1/limits", ...options }),
|
|
9
|
+
};
|
|
10
|
+
}
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
import type { Sandbox } from "../sandbox.js";
|
|
2
|
+
import type { RequestOptions, Transport } from "../transport.js";
|
|
3
|
+
/** A sandbox's own network rules. */
|
|
4
|
+
export type NetworkRules = {
|
|
5
|
+
/** false refuses every outbound connection. */
|
|
6
|
+
internet: boolean;
|
|
7
|
+
/** When not empty, only these web destinations are reachable: `example.com`,
|
|
8
|
+
* `*.example.com` (subdomains, not the apex), an address or a CIDR range. */
|
|
9
|
+
allow?: string[];
|
|
10
|
+
/** Never reachable. Wins over everything. */
|
|
11
|
+
deny?: string[];
|
|
12
|
+
/** host:port pairs beyond ports 80 and 443, such as `db.example.com:5432` or
|
|
13
|
+
* `github.com:22`. Paid sandboxes of organizations with a paid purchase
|
|
14
|
+
* only. In the sandbox, `python3 /usr/local/lib/runtime/guest-egress.py
|
|
15
|
+
* forward 5432 db.example.com:5432` gives psql a local port. */
|
|
16
|
+
connect?: string[];
|
|
17
|
+
};
|
|
18
|
+
export type NetworkPolicy = Required<NetworkRules> & {
|
|
19
|
+
sandboxId: string;
|
|
20
|
+
version: number;
|
|
21
|
+
/** The sandbox's host confirmed it enforces this version. */
|
|
22
|
+
enforced: boolean;
|
|
23
|
+
enforcedVersion: number;
|
|
24
|
+
/** Ports reachable without a connect entry. */
|
|
25
|
+
ports: number[];
|
|
26
|
+
connectAllowed: boolean;
|
|
27
|
+
/** paid, granted, not_paid, revoked or suspended. */
|
|
28
|
+
connectReason: string;
|
|
29
|
+
forbiddenPorts: number[];
|
|
30
|
+
updatedAt: string | null;
|
|
31
|
+
};
|
|
32
|
+
/** `sbx.network`: turn the sandbox's internet off or on, narrow it to a list,
|
|
33
|
+
* refuse destinations, or open host:port pairs. Changes apply at once, to open
|
|
34
|
+
* connections too.
|
|
35
|
+
*
|
|
36
|
+
* await sbx.network.set({ internet: true, allow: ["registry.npmjs.org"] });
|
|
37
|
+
* await sbx.network.set({ internet: false });
|
|
38
|
+
*/
|
|
39
|
+
export declare function sandboxNetwork(t: Transport, sandbox: Sandbox): {
|
|
40
|
+
get: (options?: RequestOptions) => Promise<NetworkPolicy>;
|
|
41
|
+
/** Replaces the rules. */
|
|
42
|
+
set: (rules: NetworkRules, options?: RequestOptions) => Promise<NetworkPolicy>;
|
|
43
|
+
/** No outbound connections at all. */
|
|
44
|
+
off: (options?: RequestOptions) => Promise<NetworkPolicy>;
|
|
45
|
+
/** The host's public-web policy and nothing narrower. */
|
|
46
|
+
on: (options?: RequestOptions) => Promise<NetworkPolicy>;
|
|
47
|
+
};
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
/** `sbx.network`: turn the sandbox's internet off or on, narrow it to a list,
|
|
2
|
+
* refuse destinations, or open host:port pairs. Changes apply at once, to open
|
|
3
|
+
* connections too.
|
|
4
|
+
*
|
|
5
|
+
* await sbx.network.set({ internet: true, allow: ["registry.npmjs.org"] });
|
|
6
|
+
* await sbx.network.set({ internet: false });
|
|
7
|
+
*/
|
|
8
|
+
export function sandboxNetwork(t, sandbox) {
|
|
9
|
+
const path = () => `/v1/sandboxes/${encodeURIComponent(sandbox.id)}/network`;
|
|
10
|
+
return {
|
|
11
|
+
get: (options) => t.json({ method: "GET", path: path(), ...options }),
|
|
12
|
+
/** Replaces the rules. */
|
|
13
|
+
set: (rules, options) => t.json({ method: "PUT", path: path(), body: rules, ...options }),
|
|
14
|
+
/** No outbound connections at all. */
|
|
15
|
+
off: (options) => t.json({ method: "PUT", path: path(), body: { internet: false }, ...options }),
|
|
16
|
+
/** The host's public-web policy and nothing narrower. */
|
|
17
|
+
on: (options) => t.json({ method: "PUT", path: path(), body: { internet: true }, ...options }),
|
|
18
|
+
};
|
|
19
|
+
}
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
import type { Sandbox } from "../sandbox.js";
|
|
2
|
+
import type { RequestOptions, Transport } from "../transport.js";
|
|
3
|
+
/** A public HTTPS address for a port inside a sandbox. */
|
|
4
|
+
export type Preview = {
|
|
5
|
+
id: string;
|
|
6
|
+
sandboxId: string;
|
|
7
|
+
port: number;
|
|
8
|
+
visibility: "private" | "public";
|
|
9
|
+
/** `https://<port>-<sandbox>.<preview domain>/`. A private preview also
|
|
10
|
+
* needs the token. */
|
|
11
|
+
url: string;
|
|
12
|
+
/** Private previews: a fresh signed token. Send it as the
|
|
13
|
+
* `x-runtime-preview-token` header. */
|
|
14
|
+
token: string | null;
|
|
15
|
+
tokenExpiresAt: string | null;
|
|
16
|
+
/** Private previews: a link that carries the token once, for a browser. */
|
|
17
|
+
urlWithToken: string | null;
|
|
18
|
+
/** Turned off by Runtime after a report. */
|
|
19
|
+
disabled: boolean;
|
|
20
|
+
createdAt: string;
|
|
21
|
+
/** On create only: how to share the address, and the referral link that
|
|
22
|
+
* pays you both when someone you share it with signs up. */
|
|
23
|
+
hint?: string;
|
|
24
|
+
};
|
|
25
|
+
export type CreatePreview = {
|
|
26
|
+
/** private (default): a token is needed. public: anyone with the address;
|
|
27
|
+
* a browser sees a one-time warning page naming Runtime. */
|
|
28
|
+
visibility?: "private" | "public";
|
|
29
|
+
/** How long the returned token lasts, 60 s to 7 days (default 1 day). */
|
|
30
|
+
ttlSeconds?: number;
|
|
31
|
+
};
|
|
32
|
+
/** `sbx.previews`: share ports of this sandbox at public HTTPS addresses.
|
|
33
|
+
*
|
|
34
|
+
* const { url, token } = await sbx.previews.create(3000);
|
|
35
|
+
* await fetch(url, { headers: { "x-runtime-preview-token": token! } });
|
|
36
|
+
*
|
|
37
|
+
* WebSockets work. The server must listen on 0.0.0.0 or localhost. */
|
|
38
|
+
export declare function sandboxPreviews(t: Transport, sandbox: Sandbox): {
|
|
39
|
+
/** Shares `port`, or changes its visibility if it is shared already. */
|
|
40
|
+
create: (port: number, input?: CreatePreview, options?: RequestOptions) => Promise<Preview>;
|
|
41
|
+
/** Every shared port, each private one with a fresh token. */
|
|
42
|
+
list: (options?: RequestOptions) => Promise<Preview[]>;
|
|
43
|
+
/** One preview, with a fresh token of `ttlSeconds` if it is private. */
|
|
44
|
+
get: (port: number, ttlSeconds?: number, options?: RequestOptions) => Promise<Preview>;
|
|
45
|
+
/** Refuses every token issued for this port so far and returns a new one. */
|
|
46
|
+
rotate: (port: number, options?: RequestOptions) => Promise<Preview>;
|
|
47
|
+
/** Stops sharing `port`. Open connections close within seconds. */
|
|
48
|
+
delete: (port: number, options?: RequestOptions) => Promise<{
|
|
49
|
+
id: string;
|
|
50
|
+
sandboxId: string;
|
|
51
|
+
port: number;
|
|
52
|
+
deleted: true;
|
|
53
|
+
}>;
|
|
54
|
+
};
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
/** `sbx.previews`: share ports of this sandbox at public HTTPS addresses.
|
|
2
|
+
*
|
|
3
|
+
* const { url, token } = await sbx.previews.create(3000);
|
|
4
|
+
* await fetch(url, { headers: { "x-runtime-preview-token": token! } });
|
|
5
|
+
*
|
|
6
|
+
* WebSockets work. The server must listen on 0.0.0.0 or localhost. */
|
|
7
|
+
export function sandboxPreviews(t, sandbox) {
|
|
8
|
+
const base = () => `/v1/sandboxes/${encodeURIComponent(sandbox.id)}/previews`;
|
|
9
|
+
return {
|
|
10
|
+
/** Shares `port`, or changes its visibility if it is shared already. */
|
|
11
|
+
create: (port, input = {}, options) => t.json({ method: "POST", path: base(), body: { port, ...input }, ...options }),
|
|
12
|
+
/** Every shared port, each private one with a fresh token. */
|
|
13
|
+
list: async (options) => (await t.json({ method: "GET", path: base(), ...options })).data,
|
|
14
|
+
/** One preview, with a fresh token of `ttlSeconds` if it is private. */
|
|
15
|
+
get: (port, ttlSeconds, options) => t.json({
|
|
16
|
+
method: "GET",
|
|
17
|
+
path: `${base()}/${port}`,
|
|
18
|
+
...(ttlSeconds ? { query: { ttlSeconds } } : {}),
|
|
19
|
+
...options,
|
|
20
|
+
}),
|
|
21
|
+
/** Refuses every token issued for this port so far and returns a new one. */
|
|
22
|
+
rotate: (port, options) => t.json({ method: "POST", path: `${base()}/${port}:rotate`, ...options }),
|
|
23
|
+
/** Stops sharing `port`. Open connections close within seconds. */
|
|
24
|
+
delete: (port, options) => t.json({
|
|
25
|
+
method: "DELETE",
|
|
26
|
+
path: `${base()}/${port}`,
|
|
27
|
+
...options,
|
|
28
|
+
}),
|
|
29
|
+
};
|
|
30
|
+
}
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import type { RequestOptions, Transport } from "../transport.js";
|
|
2
|
+
/** Your organization's referral link and what it has earned. Money is integer
|
|
3
|
+
* microdollars in strings (1,000,000 = $1). */
|
|
4
|
+
export type ReferralSummary = {
|
|
5
|
+
code: string;
|
|
6
|
+
/** Share this: https://withruntime.com/r/<code>. */
|
|
7
|
+
link: string;
|
|
8
|
+
/** The least each side gets: a first top-up is matched, never below this. */
|
|
9
|
+
rewardMicros: string;
|
|
10
|
+
/** The most each side gets: a first top-up is matched up to this. */
|
|
11
|
+
maxRewardMicros: string;
|
|
12
|
+
/** The smallest first top-up that pays a referral. */
|
|
13
|
+
minPurchaseMicros: string;
|
|
14
|
+
/** The most referral credit you can earn in one calendar year (UTC). */
|
|
15
|
+
yearlyCapMicros: string;
|
|
16
|
+
enabled: boolean;
|
|
17
|
+
year: number;
|
|
18
|
+
signedUp: number;
|
|
19
|
+
pending: number;
|
|
20
|
+
paid: number;
|
|
21
|
+
capped: number;
|
|
22
|
+
reversed: number;
|
|
23
|
+
earnedMicros: string;
|
|
24
|
+
earnedThisYearMicros: string;
|
|
25
|
+
capRemainingMicros: string;
|
|
26
|
+
referredBy: {
|
|
27
|
+
status: "pending" | "paid" | "refused" | "reversed";
|
|
28
|
+
creditMicros: string;
|
|
29
|
+
} | null;
|
|
30
|
+
};
|
|
31
|
+
/** `runtime.referrals.get()`: when a company that signs up with your link makes
|
|
32
|
+
* its first top-up of at least $10, you and it each get credit equal to that
|
|
33
|
+
* top-up, at least $25 and at most $500. */
|
|
34
|
+
export declare function referrals(t: Transport): {
|
|
35
|
+
get: (options?: RequestOptions) => Promise<ReferralSummary>;
|
|
36
|
+
};
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
/** `runtime.referrals.get()`: when a company that signs up with your link makes
|
|
2
|
+
* its first top-up of at least $10, you and it each get credit equal to that
|
|
3
|
+
* top-up, at least $25 and at most $500. */
|
|
4
|
+
export function referrals(t) {
|
|
5
|
+
return {
|
|
6
|
+
get: (options) => t.json({ method: "GET", path: "/v1/referrals", ...options }),
|
|
7
|
+
};
|
|
8
|
+
}
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
import { Page } from "../page.js";
|
|
2
|
+
import type { RequestOptions, Transport } from "../transport.js";
|
|
3
|
+
export type VolumeState = "creating" | "ready" | "failed" | "deleting" | "deleted";
|
|
4
|
+
export type Volume = {
|
|
5
|
+
id: string;
|
|
6
|
+
kind: "volume";
|
|
7
|
+
status: string;
|
|
8
|
+
state: VolumeState;
|
|
9
|
+
name: string | null;
|
|
10
|
+
labels: Record<string, string>;
|
|
11
|
+
region: string;
|
|
12
|
+
sizeMiB: number;
|
|
13
|
+
filesystem: "ext4";
|
|
14
|
+
usedMiB: number | null;
|
|
15
|
+
measuredAt: string | null;
|
|
16
|
+
/** Always false: a volume lives on one host and is not copied off it. */
|
|
17
|
+
backedUp: false;
|
|
18
|
+
attachments: {
|
|
19
|
+
sandboxId: string;
|
|
20
|
+
mode: "rw" | "snapshot";
|
|
21
|
+
path: string;
|
|
22
|
+
attachedAt: string;
|
|
23
|
+
}[];
|
|
24
|
+
error: string | null;
|
|
25
|
+
createdAt: string;
|
|
26
|
+
readyAt: string | null;
|
|
27
|
+
};
|
|
28
|
+
export type CreateVolume = {
|
|
29
|
+
sizeMiB: number;
|
|
30
|
+
name?: string;
|
|
31
|
+
labels?: Record<string, string>;
|
|
32
|
+
region?: string;
|
|
33
|
+
};
|
|
34
|
+
/** Persistent disks: create once, attach when creating a sandbox with
|
|
35
|
+
* `volumes: [{ volumeId: v.id, path: "/data" }]`. Not backed up off its host. */
|
|
36
|
+
export declare function volumes(t: Transport): {
|
|
37
|
+
/** Create and wait (up to 10 s) until it is ready. */
|
|
38
|
+
create: (input: CreateVolume, options?: RequestOptions) => Promise<Volume>;
|
|
39
|
+
get: (id: string, options?: RequestOptions) => Promise<Volume>;
|
|
40
|
+
list: (query?: {
|
|
41
|
+
state?: VolumeState;
|
|
42
|
+
name?: string;
|
|
43
|
+
limit?: number;
|
|
44
|
+
cursor?: string;
|
|
45
|
+
}, options?: RequestOptions) => Promise<Page<Volume>>;
|
|
46
|
+
delete: (id: string, options?: RequestOptions) => Promise<Volume>;
|
|
47
|
+
};
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import { Page } from "../page.js";
|
|
2
|
+
/** Persistent disks: create once, attach when creating a sandbox with
|
|
3
|
+
* `volumes: [{ volumeId: v.id, path: "/data" }]`. Not backed up off its host. */
|
|
4
|
+
export function volumes(t) {
|
|
5
|
+
const get = (id, options) => t.json({ method: "GET", path: `/v1/volumes/${encodeURIComponent(id)}`, ...options });
|
|
6
|
+
const list = async (query = {}, options) => {
|
|
7
|
+
const page = await t.json({
|
|
8
|
+
method: "GET",
|
|
9
|
+
path: "/v1/volumes",
|
|
10
|
+
query,
|
|
11
|
+
...options,
|
|
12
|
+
});
|
|
13
|
+
return new Page(page.data, page.nextCursor, (cursor) => list({ ...query, cursor }, options));
|
|
14
|
+
};
|
|
15
|
+
return {
|
|
16
|
+
/** Create and wait (up to 10 s) until it is ready. */
|
|
17
|
+
create: (input, options) => t.json({ method: "POST", path: "/v1/volumes", body: input, wait: 10, ...options }),
|
|
18
|
+
get,
|
|
19
|
+
list,
|
|
20
|
+
delete: (id, options) => t.json({
|
|
21
|
+
method: "POST",
|
|
22
|
+
path: `/v1/volumes/${encodeURIComponent(id)}:delete`,
|
|
23
|
+
body: {},
|
|
24
|
+
...options,
|
|
25
|
+
}),
|
|
26
|
+
};
|
|
27
|
+
}
|