@promigence/sdk 0.1.0-beta.13 → 0.1.0-beta.15
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/cjs/client.d.ts +84 -14
- package/dist/cjs/client.js +126 -34
- package/dist/cjs/core.d.ts +1 -1
- package/dist/cjs/core.js +3 -1
- package/dist/cjs/http2.d.ts +1 -0
- package/dist/cjs/http2.js +194 -22
- package/dist/cjs/models.gen.d.ts +599 -36
- package/dist/cjs/pty.d.ts +11 -14
- package/dist/cjs/pty.js +15 -12
- package/dist/cjs/trace.d.ts +2 -0
- package/dist/cjs/trace.js +17 -0
- package/dist/cjs/transport-worker.js +72 -12
- package/dist/client.d.ts +84 -14
- package/dist/client.js +125 -33
- package/dist/core.d.ts +1 -1
- package/dist/core.js +3 -1
- package/dist/http2.d.ts +1 -0
- package/dist/http2.js +195 -23
- package/dist/models.gen.d.ts +599 -36
- package/dist/pty.d.ts +11 -14
- package/dist/pty.js +13 -11
- package/dist/trace.d.ts +2 -0
- package/dist/trace.js +16 -0
- package/dist/transport-worker.js +72 -12
- package/package.json +1 -1
package/dist/cjs/pty.d.ts
CHANGED
|
@@ -1,11 +1,14 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* Interactive terminals: `GET /v1/sandboxes/:id/pty` over a WebSocket (RFC 6455).
|
|
3
3
|
*
|
|
4
|
-
* The protocol:
|
|
4
|
+
* The protocol (`promigence.pty.v2`):
|
|
5
5
|
*
|
|
6
|
-
* client → server
|
|
6
|
+
* client → server first, one text frame `{"start":{"cmd"?,"secrets"?}}`: what to run and the secret
|
|
7
|
+
* names it gets, inside the connection, never in a header or the URL; then
|
|
8
|
+
* binary = keystrokes; text = `{"resize":{cols,rows}}` | `{"signal":N}` | `{"eof":true}`
|
|
7
9
|
* server → client binary = terminal output; text = `{"event":"open",…}` first and
|
|
8
|
-
* `{"event":"exit"|"error"|"closed",…}` last, then a Close frame
|
|
10
|
+
* `{"event":"exit"|"error"|"closed",…}` last, then a Close frame. A terminal that
|
|
11
|
+
* cannot open says so in its first frame: `{"event":"error","status",…}`, then Close.
|
|
9
12
|
*
|
|
10
13
|
* Zero dependencies, so this is a small client over `node:http` rather than the global
|
|
11
14
|
* `WebSocket`: that one cannot send an `Authorization` header, and a key in the query string is
|
|
@@ -32,26 +35,20 @@ export interface PtyExit {
|
|
|
32
35
|
message: string;
|
|
33
36
|
};
|
|
34
37
|
}
|
|
35
|
-
/** The
|
|
36
|
-
export declare const
|
|
37
|
-
/** The header the terminal's secret **names** travel in, base64 JSON. */
|
|
38
|
-
export declare const PTY_SECRETS_HEADER = "promigence-pty-secrets";
|
|
38
|
+
/** The WebSocket subprotocol a terminal speaks: its first message is `{"start": {"cmd"?, "secrets"?}}`. */
|
|
39
|
+
export declare const PTY_PROTOCOL = "promigence.pty.v2";
|
|
39
40
|
export interface PtyConnectOpts {
|
|
40
41
|
/** `http(s)://host[:port]/v1/sandboxes/<id>/pty?cols=&rows=` — dimensions only. */
|
|
41
42
|
url: string;
|
|
42
43
|
apiKey: string;
|
|
43
44
|
userAgent: string;
|
|
44
45
|
/**
|
|
45
|
-
* The command to run
|
|
46
|
-
*
|
|
47
|
-
* It used to be `?cmd=`, with `envs` composed into it as `export K=v;` — so a terminal opened
|
|
48
|
-
* with an API key in its environment wrote that key into the query string of every request,
|
|
49
|
-
* and therefore into every access log along the path. Names and values both stay out of the
|
|
50
|
-
* URL now.
|
|
46
|
+
* The command to run. Sent in the terminal's first message, inside the connection: never in a
|
|
47
|
+
* header or the URL, where a log on the way could keep it.
|
|
51
48
|
*/
|
|
52
49
|
command?: string;
|
|
53
50
|
/** Stored secret names (or `{name, as}` bindings), resolved server-side into the terminal's
|
|
54
|
-
* environment.
|
|
51
|
+
* environment. Sent in the first message with the command. */
|
|
55
52
|
secrets?: unknown[];
|
|
56
53
|
/** The `promigence-caller` label, when one is set (`setCaller`). */
|
|
57
54
|
caller?: string;
|
package/dist/cjs/pty.js
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.PTY_RESTART_CLOSED_EXIT = exports.PTY_RESTART_EXIT = exports.PTY_RECONNECT_MAX_WAIT_MS = exports.PTY_RECONNECT_FIRST_WAIT_MS = exports.PTY_RECONNECT_FOR_MS = exports.PTY_RECONNECT_CODE = exports.PtySession = exports.FrameReader = exports.
|
|
3
|
+
exports.PTY_RESTART_CLOSED_EXIT = exports.PTY_RESTART_EXIT = exports.PTY_RECONNECT_MAX_WAIT_MS = exports.PTY_RECONNECT_FIRST_WAIT_MS = exports.PTY_RECONNECT_FOR_MS = exports.PTY_RECONNECT_CODE = exports.PtySession = exports.FrameReader = exports.PTY_PROTOCOL = exports.PTY_RESUME_HEADER = exports.PTY_INPUT_KEEP = exports.PTY_INPUT_CHUNK = void 0;
|
|
4
|
+
exports.ptyStartMessage = ptyStartMessage;
|
|
4
5
|
exports.wsAccept = wsAccept;
|
|
5
6
|
exports.encodeFrame = encodeFrame;
|
|
6
7
|
exports.connectPty = connectPty;
|
|
@@ -11,8 +12,10 @@ exports.PTY_INPUT_CHUNK = 64 * 1024;
|
|
|
11
12
|
exports.PTY_INPUT_KEEP = 256 * 1024;
|
|
12
13
|
exports.PTY_RESUME_HEADER = "promigence-resume";
|
|
13
14
|
const WS_GUID = "258EAFA5-E914-47DA-95CA-C5AB0DC85B11";
|
|
14
|
-
exports.
|
|
15
|
-
|
|
15
|
+
exports.PTY_PROTOCOL = "promigence.pty.v2";
|
|
16
|
+
function ptyStartMessage(command, secrets) {
|
|
17
|
+
return JSON.stringify({ start: { ...(command ? { cmd: command } : {}), ...(secrets?.length ? { secrets } : {}) } });
|
|
18
|
+
}
|
|
16
19
|
function wsAccept(key) {
|
|
17
20
|
return (0, node_crypto_1.createHash)("sha1").update(key + WS_GUID).digest("base64");
|
|
18
21
|
}
|
|
@@ -258,15 +261,7 @@ function openLeg(opts, url, resume) {
|
|
|
258
261
|
authorization: `Bearer ${opts.apiKey}`,
|
|
259
262
|
"user-agent": opts.userAgent,
|
|
260
263
|
...(opts.caller ? { [caller_js_1.CALLER_HEADER]: opts.caller } : {}),
|
|
261
|
-
...(resume ? { [exports.PTY_RESUME_HEADER]: resume } : {}),
|
|
262
|
-
...(opts.command && !resume
|
|
263
|
-
? { [exports.PTY_COMMAND_HEADER]: Buffer.from(opts.command, "utf8").toString("base64") }
|
|
264
|
-
: {}),
|
|
265
|
-
...(opts.secrets?.length && !resume
|
|
266
|
-
? {
|
|
267
|
-
[exports.PTY_SECRETS_HEADER]: Buffer.from(JSON.stringify(opts.secrets), "utf8").toString("base64"),
|
|
268
|
-
}
|
|
269
|
-
: {}),
|
|
264
|
+
...(resume ? { [exports.PTY_RESUME_HEADER]: resume } : { "sec-websocket-protocol": exports.PTY_PROTOCOL }),
|
|
270
265
|
},
|
|
271
266
|
});
|
|
272
267
|
let resolveEnded;
|
|
@@ -299,6 +294,8 @@ function openLeg(opts, url, resume) {
|
|
|
299
294
|
return;
|
|
300
295
|
}
|
|
301
296
|
socket.setNoDelay(true);
|
|
297
|
+
if (!resume)
|
|
298
|
+
socket.write(encodeFrame(0x1, Buffer.from(ptyStartMessage(opts.command, opts.secrets), "utf8")));
|
|
302
299
|
const reader = new FrameReader();
|
|
303
300
|
let exit;
|
|
304
301
|
let closeCode;
|
|
@@ -336,6 +333,12 @@ function openLeg(opts, url, resume) {
|
|
|
336
333
|
...(typeof v["wall_ms"] === "number" ? { wallMs: v["wall_ms"] } : {}),
|
|
337
334
|
};
|
|
338
335
|
}
|
|
336
|
+
else if (v["event"] === "error" && !wasOpen && typeof v["status"] === "number") {
|
|
337
|
+
const e = (v["error"] && typeof v["error"] === "object" ? v["error"] : { code: v["code"], message: v["message"] });
|
|
338
|
+
fail(v["status"], JSON.stringify({ error: e }), typeof v["retry_after"] === "string" ? v["retry_after"] : undefined);
|
|
339
|
+
socket.destroy();
|
|
340
|
+
return;
|
|
341
|
+
}
|
|
339
342
|
else if (v["event"] === "error" || v["event"] === "closed") {
|
|
340
343
|
exit = {
|
|
341
344
|
exitCode: null, signal: null,
|
package/dist/cjs/trace.d.ts
CHANGED
|
@@ -31,3 +31,5 @@ export declare function mark(s: TraceStamp | undefined, phase: string): void;
|
|
|
31
31
|
export declare function traceEvent(name: string): void;
|
|
32
32
|
/** A process event that happened at `t` (`performance.now()` terms), recorded now: one another thread reported. */
|
|
33
33
|
export declare function traceEventAt(name: string, t: number): void;
|
|
34
|
+
/** `fn` runs once at exit, before the trace is written (tracing on only). */
|
|
35
|
+
export declare function onTraceFlush(fn: () => void): void;
|
package/dist/cjs/trace.js
CHANGED
|
@@ -6,6 +6,7 @@ exports.traceBegin = traceBegin;
|
|
|
6
6
|
exports.mark = mark;
|
|
7
7
|
exports.traceEvent = traceEvent;
|
|
8
8
|
exports.traceEventAt = traceEventAt;
|
|
9
|
+
exports.onTraceFlush = onTraceFlush;
|
|
9
10
|
const node_fs_1 = require("node:fs");
|
|
10
11
|
const core_js_1 = require("./core.js");
|
|
11
12
|
exports.TRACE_ON = (() => {
|
|
@@ -68,7 +69,23 @@ function modulePath() {
|
|
|
68
69
|
const m = /\((.*):\d+:\d+\)\s*$/.exec(frame) ?? /at (.*):\d+:\d+\s*$/.exec(frame);
|
|
69
70
|
return m?.[1] ?? "";
|
|
70
71
|
}
|
|
72
|
+
const beforeFlush = [];
|
|
73
|
+
function onTraceFlush(fn) {
|
|
74
|
+
if (!exports.TRACE_ON)
|
|
75
|
+
return;
|
|
76
|
+
beforeFlush.push(fn);
|
|
77
|
+
if (!hooked) {
|
|
78
|
+
hooked = true;
|
|
79
|
+
process.once("exit", flush);
|
|
80
|
+
}
|
|
81
|
+
}
|
|
71
82
|
function flush() {
|
|
83
|
+
for (const fn of beforeFlush.splice(0)) {
|
|
84
|
+
try {
|
|
85
|
+
fn();
|
|
86
|
+
}
|
|
87
|
+
catch { }
|
|
88
|
+
}
|
|
72
89
|
const head = {
|
|
73
90
|
trace: "promigence-sdk",
|
|
74
91
|
version: core_js_1.VERSION,
|
|
@@ -36,6 +36,11 @@ function start(init) {
|
|
|
36
36
|
}
|
|
37
37
|
catch { }
|
|
38
38
|
};
|
|
39
|
+
const ev = (n) => {
|
|
40
|
+
if (init.trace === true)
|
|
41
|
+
post({ t: "ev", n, hr: hrNow() });
|
|
42
|
+
};
|
|
43
|
+
ev("boot");
|
|
39
44
|
const live = () => sessions.filter((e) => !e.retired && !e.session.closed && !e.session.destroyed);
|
|
40
45
|
const end = (reason) => {
|
|
41
46
|
if (closed)
|
|
@@ -96,14 +101,14 @@ function start(init) {
|
|
|
96
101
|
catch {
|
|
97
102
|
context = undefined;
|
|
98
103
|
}
|
|
99
|
-
const connect = (address) => new Promise((resolve) => {
|
|
104
|
+
const connect = (address, k) => new Promise((resolve) => {
|
|
100
105
|
let done = false;
|
|
101
106
|
const finish = (e) => { if (!done) {
|
|
102
107
|
done = true;
|
|
103
108
|
clearTimeout(timer);
|
|
104
109
|
resolve(e);
|
|
105
110
|
} };
|
|
106
|
-
const timer = setTimeout(() => { try {
|
|
111
|
+
const timer = setTimeout(() => { ev(`timeout${k}`); try {
|
|
107
112
|
socket.destroy();
|
|
108
113
|
}
|
|
109
114
|
catch { } finish(null); }, init.connectTimeoutMs);
|
|
@@ -115,8 +120,11 @@ function start(init) {
|
|
|
115
120
|
checkServerIdentity: ca_guard_js_1.guardCertChain,
|
|
116
121
|
...(context === undefined ? {} : { secureContext: context }),
|
|
117
122
|
});
|
|
118
|
-
|
|
123
|
+
if (init.trace === true)
|
|
124
|
+
socket.once("connect", () => { ev(`tcp${k}`); });
|
|
125
|
+
socket.once("error", (e) => { ev(`fail${k} ${e?.code ?? "error"}`); finish(null); });
|
|
119
126
|
socket.once("secureConnect", () => {
|
|
127
|
+
ev(`tls${k}`);
|
|
120
128
|
if (socket.alpnProtocol !== "h2") {
|
|
121
129
|
socket.destroy();
|
|
122
130
|
finish(null);
|
|
@@ -169,14 +177,66 @@ function start(init) {
|
|
|
169
177
|
resolve(v4);
|
|
170
178
|
return;
|
|
171
179
|
}
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
+
const at = init.lookupAtMs.length > 0 ? init.lookupAtMs : [0];
|
|
181
|
+
const resolvers = [];
|
|
182
|
+
const timers = [];
|
|
183
|
+
let done = false;
|
|
184
|
+
let asked = 0;
|
|
185
|
+
let failed = 0;
|
|
186
|
+
const finish = (addrs) => {
|
|
187
|
+
if (done)
|
|
188
|
+
return;
|
|
189
|
+
done = true;
|
|
190
|
+
for (const t of timers)
|
|
191
|
+
clearTimeout(t);
|
|
192
|
+
for (const r of resolvers) {
|
|
193
|
+
try {
|
|
194
|
+
r.cancel();
|
|
195
|
+
}
|
|
196
|
+
catch { }
|
|
197
|
+
}
|
|
198
|
+
resolve(addrs);
|
|
199
|
+
};
|
|
200
|
+
const gaveUp = () => {
|
|
201
|
+
if (++failed < asked)
|
|
202
|
+
return;
|
|
203
|
+
if (asked < at.length)
|
|
204
|
+
ask();
|
|
205
|
+
else
|
|
206
|
+
finish([]);
|
|
207
|
+
};
|
|
208
|
+
const ask = () => {
|
|
209
|
+
if (done || asked >= at.length)
|
|
210
|
+
return;
|
|
211
|
+
const k = asked++;
|
|
212
|
+
try {
|
|
213
|
+
const r = new dns.Resolver({ timeout: init.lookupTimeoutMs, tries: init.lookupTries });
|
|
214
|
+
const list = Array.isArray(init.servers) && init.servers.length > 0 ? init.servers : r.getServers();
|
|
215
|
+
if (list.length > 0)
|
|
216
|
+
r.setServers(list.map((_, i) => list[(i + k) % list.length]));
|
|
217
|
+
resolvers.push(r);
|
|
218
|
+
ev(`lookup${k + 1}`);
|
|
219
|
+
r.resolve4(name, (err, addrs) => {
|
|
220
|
+
if (done)
|
|
221
|
+
return;
|
|
222
|
+
if (!err && Array.isArray(addrs) && addrs.length > 0) {
|
|
223
|
+
ev(`addrs${k + 1} ${addrs.length}`);
|
|
224
|
+
finish(addrs);
|
|
225
|
+
return;
|
|
226
|
+
}
|
|
227
|
+
ev(`nolookup${k + 1} ${err?.code ?? "empty"}`);
|
|
228
|
+
gaveUp();
|
|
229
|
+
});
|
|
230
|
+
}
|
|
231
|
+
catch {
|
|
232
|
+
gaveUp();
|
|
233
|
+
}
|
|
234
|
+
};
|
|
235
|
+
for (const ms of at) {
|
|
236
|
+
if (ms <= 0)
|
|
237
|
+
ask();
|
|
238
|
+
else
|
|
239
|
+
timers.push(setTimeout(ask, ms));
|
|
180
240
|
}
|
|
181
241
|
});
|
|
182
242
|
const limitOf = (e) => {
|
|
@@ -198,7 +258,7 @@ function start(init) {
|
|
|
198
258
|
}
|
|
199
259
|
const n = Math.max(1, init.sessions);
|
|
200
260
|
pendingConnects = n;
|
|
201
|
-
const tries = Array.from({ length: n }, (_, i) => connect(addrs[i % addrs.length]).then((e) => {
|
|
261
|
+
const tries = Array.from({ length: n }, (_, i) => connect(addrs[i % addrs.length], i).then((e) => {
|
|
202
262
|
pendingConnects--;
|
|
203
263
|
if (closed) {
|
|
204
264
|
if (e)
|
package/dist/client.d.ts
CHANGED
|
@@ -727,6 +727,10 @@ export interface OrgRecord {
|
|
|
727
727
|
projects: number;
|
|
728
728
|
members: number;
|
|
729
729
|
created_at: string;
|
|
730
|
+
/** Days command output is kept after a sandbox ends; `null` = the default, 7. */
|
|
731
|
+
output_retention_days?: number | null;
|
|
732
|
+
/** Keep a failed sandbox to reopen where it broke, when a run does not say; absent or `null` = the default. */
|
|
733
|
+
failure_captures?: boolean | null;
|
|
730
734
|
}
|
|
731
735
|
export interface ProjectRecord {
|
|
732
736
|
project_id: string;
|
|
@@ -736,8 +740,14 @@ export interface ProjectRecord {
|
|
|
736
740
|
keys: number;
|
|
737
741
|
/** The most the project may bill in a calendar month (UTC); `null` = no cap. */
|
|
738
742
|
monthly_cap_usd?: number | null;
|
|
743
|
+
/** Days this project's command output is kept after a sandbox ends; `null` = the organization's. */
|
|
744
|
+
output_retention_days?: number | null;
|
|
745
|
+
/** Keep this project's failed sandboxes to reopen, when a run does not say; absent or `null` = the organization's. */
|
|
746
|
+
failure_captures?: boolean | null;
|
|
739
747
|
created_at: string;
|
|
740
748
|
}
|
|
749
|
+
/** The longest command output may be kept after a sandbox ends, in days. */
|
|
750
|
+
export declare const OUTPUT_RETENTION_MAX_DAYS = 30;
|
|
741
751
|
export interface MemberRecord {
|
|
742
752
|
user_id: string;
|
|
743
753
|
email: string;
|
|
@@ -905,8 +915,10 @@ export interface PricingView {
|
|
|
905
915
|
invite_required: boolean;
|
|
906
916
|
};
|
|
907
917
|
monthly_fee_usd: number;
|
|
908
|
-
/**
|
|
918
|
+
/** Credits the plan adds each paid month, USD. */
|
|
909
919
|
included_credits_usd: number;
|
|
920
|
+
/** For how many paid months the plan adds `included_credits_usd`; `null` when it adds them every paid month. */
|
|
921
|
+
included_credits_promo_months?: number | null;
|
|
910
922
|
monthly_minimum_usd: number;
|
|
911
923
|
}
|
|
912
924
|
export interface BillingUsage {
|
|
@@ -957,6 +969,20 @@ export interface BillingUsage {
|
|
|
957
969
|
period_end?: string | null;
|
|
958
970
|
} | null;
|
|
959
971
|
upcoming_invoice_error?: string | null;
|
|
972
|
+
/** What the organization's credits can pay for: balance, held, available, the next to expire. */
|
|
973
|
+
credits?: M.BillingCredits;
|
|
974
|
+
/** Auto-reload: when available credits fall below `threshold_usd`, `amount_usd` is added from `card`. */
|
|
975
|
+
auto_reload?: M.AutoReload;
|
|
976
|
+
/** The plan in force, and a renewal payment in trouble. */
|
|
977
|
+
plan_status?: M.PlanStatus;
|
|
978
|
+
/** `credits` (paid from credits bought in advance) or `postpaid` (billed after use, until `switch.at`). */
|
|
979
|
+
model?: string;
|
|
980
|
+
/** For a `postpaid` organization: when it moves to credits, and the credits ready then. */
|
|
981
|
+
switch?: M.BillingSwitch | null;
|
|
982
|
+
/** What this organization can buy now. */
|
|
983
|
+
trust?: M.TrustLimits;
|
|
984
|
+
/** A hold that refuses new work, and the page that lifts it; `null` when there is none. */
|
|
985
|
+
hold?: M.BillingHold | null;
|
|
960
986
|
[extra: string]: unknown;
|
|
961
987
|
}
|
|
962
988
|
/** One row of `GET /billing/history`: a credit the organization received, or a payment. */
|
|
@@ -1150,7 +1176,7 @@ export interface SnapshotVerifyResponse {
|
|
|
1150
1176
|
state: string;
|
|
1151
1177
|
}>;
|
|
1152
1178
|
}
|
|
1153
|
-
/** `
|
|
1179
|
+
/** `POST /sandboxes/:id/files/stat`. */
|
|
1154
1180
|
export interface FileStat {
|
|
1155
1181
|
path: string;
|
|
1156
1182
|
size: number;
|
|
@@ -1178,7 +1204,7 @@ export interface DirEntry {
|
|
|
1178
1204
|
}
|
|
1179
1205
|
/** An opaque label of how a file request was answered, passed through for support. */
|
|
1180
1206
|
export type ServedBy = string;
|
|
1181
|
-
/** `
|
|
1207
|
+
/** `POST /sandboxes/:id/files/list`. */
|
|
1182
1208
|
export interface DirListing {
|
|
1183
1209
|
sandbox_id: string;
|
|
1184
1210
|
path: string;
|
|
@@ -1187,7 +1213,7 @@ export interface DirListing {
|
|
|
1187
1213
|
truncated: boolean;
|
|
1188
1214
|
served_by?: ServedBy;
|
|
1189
1215
|
}
|
|
1190
|
-
/**
|
|
1216
|
+
/** `recursive`, `depth`, `limit` and `hidden` on `files/list` (sent in the request body). */
|
|
1191
1217
|
export interface DirListOpts {
|
|
1192
1218
|
recursive?: boolean;
|
|
1193
1219
|
/** With `recursive`: how many levels below `path`. Unset = no bound. */
|
|
@@ -1207,7 +1233,7 @@ export interface FileInfo {
|
|
|
1207
1233
|
is_symlink: boolean;
|
|
1208
1234
|
served_by?: ServedBy;
|
|
1209
1235
|
}
|
|
1210
|
-
/** One hit of `
|
|
1236
|
+
/** One hit of `POST /sandboxes/:id/files/search`. `line`/`text` only for a `contains` search. */
|
|
1211
1237
|
export interface FileMatch {
|
|
1212
1238
|
path: string;
|
|
1213
1239
|
line?: number | null;
|
|
@@ -1906,6 +1932,8 @@ interface RequestOpts {
|
|
|
1906
1932
|
onHeaders?: (headers: Headers) => void;
|
|
1907
1933
|
/** Extra request headers (e.g. `promigence-replaced-by`). Never the authorization. */
|
|
1908
1934
|
headers?: Record<string, string>;
|
|
1935
|
+
/** A `POST` that changes nothing (a file read): safe to send twice, so it is retried as a `GET` is. */
|
|
1936
|
+
replayable?: boolean;
|
|
1909
1937
|
}
|
|
1910
1938
|
/** One answer's timing ([`PromigenceClient.lastTiming`]). */
|
|
1911
1939
|
export interface Timing {
|
|
@@ -2011,13 +2039,16 @@ export declare class PromigenceClient {
|
|
|
2011
2039
|
* artefact must not go through: it would corrupt binary and cost a second copy of a file that
|
|
2012
2040
|
* can be gigabytes. This reads the body as an `ArrayBuffer` and hands it back untouched.
|
|
2013
2041
|
* Errors still arrive as JSON, so a non-2xx answer is decoded and mapped the same way.
|
|
2042
|
+
*
|
|
2043
|
+
* `body` is sent as given with its content type (a JSON question, or a `files put` form).
|
|
2044
|
+
* `read`: the request changes nothing, so a refusal is sent again as a `GET` would be.
|
|
2014
2045
|
*/
|
|
2015
2046
|
private bytes;
|
|
2016
2047
|
/**
|
|
2017
|
-
*
|
|
2048
|
+
* Read a byte body **without holding it**: each chunk goes to `onChunk` as it arrives, and
|
|
2018
2049
|
* the next is not read until `onChunk` has finished with it, so a 10 GiB artefact costs one
|
|
2019
|
-
* chunk of memory.
|
|
2020
|
-
* as JSON and are mapped exactly as [`bytes`] maps them
|
|
2050
|
+
* chunk of memory. A read only (a `POST` carries its question as `body`), so a door refusal
|
|
2051
|
+
* is sent again. Errors arrive as JSON and are mapped exactly as [`bytes`] maps them.
|
|
2021
2052
|
*/
|
|
2022
2053
|
private stream;
|
|
2023
2054
|
/**
|
|
@@ -2075,7 +2106,7 @@ export declare class PromigenceClient {
|
|
|
2075
2106
|
signal?: AbortSignal;
|
|
2076
2107
|
}): Promise<Outcomes>;
|
|
2077
2108
|
readonly billing: {
|
|
2078
|
-
/** `GET /billing` — plan, card, period, usage, trial,
|
|
2109
|
+
/** `GET /billing` — plan, credits, auto-reload, card, period, usage, trial, the next plan invoice. */
|
|
2079
2110
|
usage: () => Promise<BillingUsage>;
|
|
2080
2111
|
/** `GET /me/ledger?limit=N` — the metered rows the month's total is the sum of (one page). */
|
|
2081
2112
|
ledger: (limit?: number) => Promise<LedgerEntry[]>;
|
|
@@ -2097,6 +2128,29 @@ export declare class PromigenceClient {
|
|
|
2097
2128
|
limit?: number;
|
|
2098
2129
|
cursor?: string;
|
|
2099
2130
|
}) => Promise<Page<BillingHistoryEntry>>;
|
|
2131
|
+
/** `GET /billing/holds` — what each running or paused sandbox holds of the organization's credits. */
|
|
2132
|
+
holds: () => Promise<M.CreditHolds>;
|
|
2133
|
+
/**
|
|
2134
|
+
* `POST /billing/credits` — a payment page to buy credits, from $5, in whole dollars. The credits are
|
|
2135
|
+
* added when the payment goes through: `settleCredits(session_id)` checks it. An owner's full-access key.
|
|
2136
|
+
*/
|
|
2137
|
+
buyCredits: (amountUsd: number) => Promise<M.PaymentPage>;
|
|
2138
|
+
/** `POST /billing/credits/:session_id/settle` — check a credits payment and add its credits if it went through. */
|
|
2139
|
+
settleCredits: (sessionId: string) => Promise<M.CreditsSettled>;
|
|
2140
|
+
/** `GET /billing/auto-reload` — the auto-reload settings, and the authorization turning it on asks for. */
|
|
2141
|
+
autoReload: () => Promise<M.AutoReload>;
|
|
2142
|
+
/**
|
|
2143
|
+
* `PUT /billing/auto-reload` — turn auto-reload on or off, or change it. Turning it on, or changing the level or
|
|
2144
|
+
* the amount, needs `authorizationVersion`: the version of the authorization the owner accepted.
|
|
2145
|
+
*/
|
|
2146
|
+
setAutoReload: (opts: {
|
|
2147
|
+
on: boolean;
|
|
2148
|
+
thresholdUsd?: number;
|
|
2149
|
+
amountUsd?: number;
|
|
2150
|
+
authorizationVersion?: string;
|
|
2151
|
+
}) => Promise<M.AutoReload>;
|
|
2152
|
+
/** `POST /billing/disputes/:dispute_id/repay` — a payment page to repay a disputed payment. */
|
|
2153
|
+
repayDispute: (disputeId: string) => Promise<M.PaymentPage>;
|
|
2100
2154
|
/** `POST /billing/checkout` — the hosted page that puts a card on file. */
|
|
2101
2155
|
checkout: () => Promise<{
|
|
2102
2156
|
url: string;
|
|
@@ -2109,7 +2163,7 @@ export declare class PromigenceClient {
|
|
|
2109
2163
|
}>;
|
|
2110
2164
|
/** `GET /referrals` — your code and its offer, your referrals by status, what they earned. */
|
|
2111
2165
|
referrals: () => Promise<ReferralStatus>;
|
|
2112
|
-
/** `POST /referrals/apply` — apply a referral code (an owner's key, before the first
|
|
2166
|
+
/** `POST /referrals/apply` — apply a referral code (an owner's key, before the first payment of at least the reward). */
|
|
2113
2167
|
applyReferral: (code: string) => Promise<ReferralApplied>;
|
|
2114
2168
|
};
|
|
2115
2169
|
private group_billing;
|
|
@@ -2173,6 +2227,15 @@ export declare class PromigenceClient {
|
|
|
2173
2227
|
create: (org: string, name: string) => Promise<ProjectRecord>;
|
|
2174
2228
|
/** `PATCH /orgs/:org/projects/:project {name}` — rename it (the `default` project keeps its name). */
|
|
2175
2229
|
rename: (org: string, project: string, name: string) => Promise<ProjectRecord>;
|
|
2230
|
+
/**
|
|
2231
|
+
* `PATCH /orgs/:org/projects/:project` — rename it, set how long its command output is kept, or
|
|
2232
|
+
* whether its failed sandboxes are kept to reopen (that one on its own). The settings need an owner signed in.
|
|
2233
|
+
*/
|
|
2234
|
+
update: (org: string, project: string, update: {
|
|
2235
|
+
name?: string;
|
|
2236
|
+
outputRetentionDays?: number | null;
|
|
2237
|
+
failureCaptures?: boolean | null;
|
|
2238
|
+
}) => Promise<ProjectRecord>;
|
|
2176
2239
|
};
|
|
2177
2240
|
};
|
|
2178
2241
|
private group_orgs;
|
|
@@ -2499,7 +2562,7 @@ export declare class PromigenceClient {
|
|
|
2499
2562
|
rows?: number;
|
|
2500
2563
|
cmd?: string;
|
|
2501
2564
|
/** Stored secret names, or `{name, as}` bindings, put into the terminal's environment
|
|
2502
|
-
* by the server. Names travel
|
|
2565
|
+
* by the server. Names travel inside the terminal's connection; values never leave the service. */
|
|
2503
2566
|
secrets?: SecretBinding[];
|
|
2504
2567
|
onData?: (data: Uint8Array) => void;
|
|
2505
2568
|
onExit?: (exit: PtyExit) => void;
|
|
@@ -2544,6 +2607,12 @@ export declare class PromigenceClient {
|
|
|
2544
2607
|
optimizeFor?: OptimizeFor;
|
|
2545
2608
|
spendCap?: number;
|
|
2546
2609
|
}) => Promise<ResumeResult>;
|
|
2610
|
+
/**
|
|
2611
|
+
* `POST /sandboxes/resume {paused_for: "credits"}` — resume every sandbox paused because credits
|
|
2612
|
+
* ran out. Each resume is checked like new work: the answer lists the sandboxes that resumed and
|
|
2613
|
+
* those that still need credits.
|
|
2614
|
+
*/
|
|
2615
|
+
resumePausedForCredits: () => Promise<M.SandboxesResumed>;
|
|
2547
2616
|
/**
|
|
2548
2617
|
* `POST /sandboxes/:id/snapshot` — photograph a running sandbox and keep it running.
|
|
2549
2618
|
*
|
|
@@ -2656,8 +2725,9 @@ export declare class PromigenceClient {
|
|
|
2656
2725
|
}) => Promise<SandboxPatchResponse>;
|
|
2657
2726
|
/**
|
|
2658
2727
|
* `get` streams: the body is handed back as bytes and never parsed, because an eval
|
|
2659
|
-
* artefact, a trace or a run log is exactly what this is for. `put` sends the file
|
|
2660
|
-
*
|
|
2728
|
+
* artefact, a trace or a run log is exactly what this is for. `put` sends the file's bytes
|
|
2729
|
+
* as they are rather than base64 inside JSON. A file's path, a name pattern and a search
|
|
2730
|
+
* text travel in the request body, never in the URL.
|
|
2661
2731
|
*/
|
|
2662
2732
|
files: {
|
|
2663
2733
|
/**
|
|
@@ -2744,7 +2814,7 @@ export declare class PromigenceClient {
|
|
|
2744
2814
|
/**
|
|
2745
2815
|
* Write a file of **any size**, in [`FILE_PUT_CHUNK_BYTES`] requests.
|
|
2746
2816
|
*
|
|
2747
|
-
* Chunk 0 goes without
|
|
2817
|
+
* Chunk 0 goes without an `offset`, which means "this is the file" (create, truncate);
|
|
2748
2818
|
* every later chunk carries one, which appends, so a file has no size limit here.
|
|
2749
2819
|
*
|
|
2750
2820
|
* A failure mid-loop leaves a **prefix** in the sandbox, not a corrupt file. Re-running the
|