@hyperbrowser/sdk 0.84.0 → 0.86.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.
- package/README.md +103 -0
- package/dist/client.d.ts +20 -2
- package/dist/client.js +12 -2
- package/dist/index.d.ts +2 -2
- package/dist/index.js +4 -3
- package/dist/sandbox/base.d.ts +28 -0
- package/dist/sandbox/base.js +242 -0
- package/dist/sandbox/files.d.ts +92 -0
- package/dist/sandbox/files.js +508 -0
- package/dist/sandbox/index.d.ts +4 -0
- package/dist/sandbox/index.js +15 -0
- package/dist/sandbox/process.d.ts +25 -0
- package/dist/sandbox/process.js +230 -0
- package/dist/sandbox/terminal.d.ts +45 -0
- package/dist/sandbox/terminal.js +217 -0
- package/dist/sandbox/ws.d.ts +18 -0
- package/dist/sandbox/ws.js +188 -0
- package/dist/services/base.js +43 -3
- package/dist/services/sandboxes.d.ts +59 -0
- package/dist/services/sandboxes.js +313 -0
- package/dist/types/config.d.ts +1 -0
- package/dist/types/index.d.ts +1 -0
- package/dist/types/sandbox.d.ts +314 -0
- package/dist/types/sandbox.js +2 -0
- package/package.json +9 -3
|
@@ -0,0 +1,508 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.SandboxFilesApi = exports.SandboxWatchDirHandle = void 0;
|
|
7
|
+
const buffer_1 = require("buffer");
|
|
8
|
+
const path_1 = __importDefault(require("path"));
|
|
9
|
+
const web_1 = require("node:stream/web");
|
|
10
|
+
const ws_1 = __importDefault(require("ws"));
|
|
11
|
+
const client_1 = require("../client");
|
|
12
|
+
const ws_2 = require("./ws");
|
|
13
|
+
const normalizeFileType = (value) => {
|
|
14
|
+
if (!value) {
|
|
15
|
+
return undefined;
|
|
16
|
+
}
|
|
17
|
+
return value === "dir" || value === "directory" ? "dir" : "file";
|
|
18
|
+
};
|
|
19
|
+
const normalizeFileInfo = (entry) => ({
|
|
20
|
+
path: entry.path,
|
|
21
|
+
name: entry.name,
|
|
22
|
+
type: normalizeFileType(entry.type) ?? "file",
|
|
23
|
+
size: entry.size,
|
|
24
|
+
mode: entry.mode,
|
|
25
|
+
permissions: entry.permissions,
|
|
26
|
+
owner: entry.owner,
|
|
27
|
+
group: entry.group,
|
|
28
|
+
modifiedTime: entry.modifiedTime === undefined ? undefined : new Date(entry.modifiedTime),
|
|
29
|
+
symlinkTarget: entry.symlinkTarget,
|
|
30
|
+
});
|
|
31
|
+
const normalizeWriteInfo = (entry) => ({
|
|
32
|
+
path: entry.path,
|
|
33
|
+
name: entry.name,
|
|
34
|
+
type: normalizeFileType(entry.type),
|
|
35
|
+
});
|
|
36
|
+
const normalizeEventType = (operation) => {
|
|
37
|
+
const lower = operation.toLowerCase();
|
|
38
|
+
if (lower.includes("chmod")) {
|
|
39
|
+
return "chmod";
|
|
40
|
+
}
|
|
41
|
+
if (lower.includes("create")) {
|
|
42
|
+
return "create";
|
|
43
|
+
}
|
|
44
|
+
if (lower.includes("remove") || lower.includes("delete")) {
|
|
45
|
+
return "remove";
|
|
46
|
+
}
|
|
47
|
+
if (lower.includes("rename")) {
|
|
48
|
+
return "rename";
|
|
49
|
+
}
|
|
50
|
+
if (lower.includes("write")) {
|
|
51
|
+
return "write";
|
|
52
|
+
}
|
|
53
|
+
return null;
|
|
54
|
+
};
|
|
55
|
+
const relativeWatchName = (root, absolutePath) => {
|
|
56
|
+
const relative = path_1.default.relative(root, absolutePath);
|
|
57
|
+
if (!relative || relative === ".") {
|
|
58
|
+
return path_1.default.basename(absolutePath);
|
|
59
|
+
}
|
|
60
|
+
return relative.split(path_1.default.sep).join("/");
|
|
61
|
+
};
|
|
62
|
+
const isReadableStreamLike = (value) => {
|
|
63
|
+
return (typeof value === "object" &&
|
|
64
|
+
value !== null &&
|
|
65
|
+
typeof value.getReader === "function");
|
|
66
|
+
};
|
|
67
|
+
const toReadableStream = (buffer) => {
|
|
68
|
+
return new web_1.ReadableStream({
|
|
69
|
+
start(controller) {
|
|
70
|
+
controller.enqueue(buffer);
|
|
71
|
+
controller.close();
|
|
72
|
+
},
|
|
73
|
+
});
|
|
74
|
+
};
|
|
75
|
+
const bufferFromReadableStream = async (stream) => {
|
|
76
|
+
const reader = stream.getReader();
|
|
77
|
+
const chunks = [];
|
|
78
|
+
while (true) {
|
|
79
|
+
const { done, value } = await reader.read();
|
|
80
|
+
if (done) {
|
|
81
|
+
break;
|
|
82
|
+
}
|
|
83
|
+
if (value) {
|
|
84
|
+
chunks.push(buffer_1.Buffer.from(value));
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
return buffer_1.Buffer.concat(chunks);
|
|
88
|
+
};
|
|
89
|
+
const encodeWriteData = async (data) => {
|
|
90
|
+
if (typeof data === "string") {
|
|
91
|
+
return {
|
|
92
|
+
data,
|
|
93
|
+
encoding: "utf8",
|
|
94
|
+
};
|
|
95
|
+
}
|
|
96
|
+
if (buffer_1.Buffer.isBuffer(data)) {
|
|
97
|
+
return {
|
|
98
|
+
data: data.toString("base64"),
|
|
99
|
+
encoding: "base64",
|
|
100
|
+
};
|
|
101
|
+
}
|
|
102
|
+
if (data instanceof Uint8Array) {
|
|
103
|
+
return {
|
|
104
|
+
data: buffer_1.Buffer.from(data).toString("base64"),
|
|
105
|
+
encoding: "base64",
|
|
106
|
+
};
|
|
107
|
+
}
|
|
108
|
+
if (data instanceof ArrayBuffer) {
|
|
109
|
+
return {
|
|
110
|
+
data: buffer_1.Buffer.from(data).toString("base64"),
|
|
111
|
+
encoding: "base64",
|
|
112
|
+
};
|
|
113
|
+
}
|
|
114
|
+
if (data instanceof buffer_1.Blob) {
|
|
115
|
+
return {
|
|
116
|
+
data: buffer_1.Buffer.from(await data.arrayBuffer()).toString("base64"),
|
|
117
|
+
encoding: "base64",
|
|
118
|
+
};
|
|
119
|
+
}
|
|
120
|
+
if (isReadableStreamLike(data)) {
|
|
121
|
+
return {
|
|
122
|
+
data: (await bufferFromReadableStream(data)).toString("base64"),
|
|
123
|
+
encoding: "base64",
|
|
124
|
+
};
|
|
125
|
+
}
|
|
126
|
+
throw new Error("Unsupported write data type");
|
|
127
|
+
};
|
|
128
|
+
class RuntimeFileWatchHandle {
|
|
129
|
+
constructor(transport, getConnectionInfo, status, runtimeProxyOverride) {
|
|
130
|
+
this.transport = transport;
|
|
131
|
+
this.getConnectionInfo = getConnectionInfo;
|
|
132
|
+
this.status = status;
|
|
133
|
+
this.runtimeProxyOverride = runtimeProxyOverride;
|
|
134
|
+
}
|
|
135
|
+
get id() {
|
|
136
|
+
return this.status.id;
|
|
137
|
+
}
|
|
138
|
+
get path() {
|
|
139
|
+
return this.status.path;
|
|
140
|
+
}
|
|
141
|
+
async stop() {
|
|
142
|
+
await this.transport.requestJSON(`/sandbox/files/watch/${this.status.id}`, {
|
|
143
|
+
method: "DELETE",
|
|
144
|
+
});
|
|
145
|
+
}
|
|
146
|
+
async *events(cursor) {
|
|
147
|
+
const connectionInfo = await this.getConnectionInfo();
|
|
148
|
+
const target = (0, ws_2.toWebSocketUrl)(connectionInfo.baseUrl, `/sandbox/files/watch/${this.status.id}/ws?sessionId=${encodeURIComponent(connectionInfo.sandboxId)}${cursor !== undefined ? `&cursor=${encodeURIComponent(String(cursor))}` : ""}`, this.runtimeProxyOverride);
|
|
149
|
+
const headers = {
|
|
150
|
+
Authorization: `Bearer ${connectionInfo.token}`,
|
|
151
|
+
};
|
|
152
|
+
if (target.hostHeader) {
|
|
153
|
+
headers.Host = target.hostHeader;
|
|
154
|
+
}
|
|
155
|
+
const ws = await (0, ws_2.openRuntimeWebSocket)(target, headers);
|
|
156
|
+
const queue = new ws_2.AsyncEventQueue();
|
|
157
|
+
ws.on("message", (data) => {
|
|
158
|
+
try {
|
|
159
|
+
const parsed = JSON.parse(data.toString());
|
|
160
|
+
if ("error" in parsed) {
|
|
161
|
+
queue.fail(new client_1.HyperbrowserError(parsed.error, {
|
|
162
|
+
statusCode: 410,
|
|
163
|
+
code: parsed.code,
|
|
164
|
+
retryable: false,
|
|
165
|
+
service: "runtime",
|
|
166
|
+
}));
|
|
167
|
+
return;
|
|
168
|
+
}
|
|
169
|
+
if (parsed.type === "event") {
|
|
170
|
+
queue.push(parsed.event);
|
|
171
|
+
return;
|
|
172
|
+
}
|
|
173
|
+
queue.close();
|
|
174
|
+
}
|
|
175
|
+
catch (error) {
|
|
176
|
+
queue.fail(error);
|
|
177
|
+
}
|
|
178
|
+
});
|
|
179
|
+
ws.on("close", () => queue.close());
|
|
180
|
+
ws.on("error", (error) => queue.fail(error));
|
|
181
|
+
try {
|
|
182
|
+
for await (const event of queue) {
|
|
183
|
+
yield event;
|
|
184
|
+
}
|
|
185
|
+
}
|
|
186
|
+
finally {
|
|
187
|
+
if (ws.readyState !== ws_1.default.CLOSING && ws.readyState !== ws_1.default.CLOSED) {
|
|
188
|
+
await new Promise((resolve) => {
|
|
189
|
+
ws.once("close", () => resolve());
|
|
190
|
+
ws.close();
|
|
191
|
+
});
|
|
192
|
+
}
|
|
193
|
+
}
|
|
194
|
+
}
|
|
195
|
+
}
|
|
196
|
+
class SandboxWatchDirHandle {
|
|
197
|
+
constructor(watch, onEvent, onExit, timeoutMs) {
|
|
198
|
+
this.watch = watch;
|
|
199
|
+
this.onExit = onExit;
|
|
200
|
+
this.stopRequested = false;
|
|
201
|
+
this.exitNotified = false;
|
|
202
|
+
if (timeoutMs !== undefined && timeoutMs > 0) {
|
|
203
|
+
this.timeout = setTimeout(() => {
|
|
204
|
+
void this.stop();
|
|
205
|
+
}, timeoutMs);
|
|
206
|
+
this.timeout.unref?.();
|
|
207
|
+
}
|
|
208
|
+
this.runPromise = this.run(onEvent);
|
|
209
|
+
}
|
|
210
|
+
async stop() {
|
|
211
|
+
if (this.stopRequested) {
|
|
212
|
+
return;
|
|
213
|
+
}
|
|
214
|
+
this.stopRequested = true;
|
|
215
|
+
if (this.timeout) {
|
|
216
|
+
clearTimeout(this.timeout);
|
|
217
|
+
this.timeout = undefined;
|
|
218
|
+
}
|
|
219
|
+
await this.watch.stop();
|
|
220
|
+
await this.runPromise.catch(() => undefined);
|
|
221
|
+
}
|
|
222
|
+
async run(onEvent) {
|
|
223
|
+
let exitError;
|
|
224
|
+
try {
|
|
225
|
+
for await (const event of this.watch.events()) {
|
|
226
|
+
const type = normalizeEventType(event.op);
|
|
227
|
+
if (!type) {
|
|
228
|
+
continue;
|
|
229
|
+
}
|
|
230
|
+
await onEvent({
|
|
231
|
+
type,
|
|
232
|
+
name: relativeWatchName(this.watch.path, event.path),
|
|
233
|
+
});
|
|
234
|
+
}
|
|
235
|
+
}
|
|
236
|
+
catch (error) {
|
|
237
|
+
exitError = error;
|
|
238
|
+
}
|
|
239
|
+
finally {
|
|
240
|
+
if (this.timeout) {
|
|
241
|
+
clearTimeout(this.timeout);
|
|
242
|
+
this.timeout = undefined;
|
|
243
|
+
}
|
|
244
|
+
if (!this.exitNotified) {
|
|
245
|
+
this.exitNotified = true;
|
|
246
|
+
await this.onExit?.(exitError);
|
|
247
|
+
}
|
|
248
|
+
}
|
|
249
|
+
}
|
|
250
|
+
}
|
|
251
|
+
exports.SandboxWatchDirHandle = SandboxWatchDirHandle;
|
|
252
|
+
class SandboxFilesApi {
|
|
253
|
+
constructor(transport, getConnectionInfo, runtimeProxyOverride) {
|
|
254
|
+
this.transport = transport;
|
|
255
|
+
this.getConnectionInfo = getConnectionInfo;
|
|
256
|
+
this.runtimeProxyOverride = runtimeProxyOverride;
|
|
257
|
+
}
|
|
258
|
+
async exists(path) {
|
|
259
|
+
try {
|
|
260
|
+
await this.getInfo(path);
|
|
261
|
+
return true;
|
|
262
|
+
}
|
|
263
|
+
catch (error) {
|
|
264
|
+
if (error instanceof client_1.HyperbrowserError && error.statusCode === 404) {
|
|
265
|
+
return false;
|
|
266
|
+
}
|
|
267
|
+
if (error instanceof Error && /not found|no such file|does not exist/i.test(error.message)) {
|
|
268
|
+
return false;
|
|
269
|
+
}
|
|
270
|
+
throw error;
|
|
271
|
+
}
|
|
272
|
+
}
|
|
273
|
+
async getInfo(path) {
|
|
274
|
+
const response = await this.transport.requestJSON("/sandbox/files/stat", undefined, { path });
|
|
275
|
+
return normalizeFileInfo(response.file);
|
|
276
|
+
}
|
|
277
|
+
async list(path, options = {}) {
|
|
278
|
+
if (options.depth !== undefined && options.depth < 1) {
|
|
279
|
+
throw new Error("depth should be at least one");
|
|
280
|
+
}
|
|
281
|
+
const response = await this.transport.requestJSON("/sandbox/files", undefined, {
|
|
282
|
+
path,
|
|
283
|
+
depth: options.depth ?? 1,
|
|
284
|
+
});
|
|
285
|
+
return response.entries.map(normalizeFileInfo);
|
|
286
|
+
}
|
|
287
|
+
async read(path, options = {}) {
|
|
288
|
+
const format = options.format ?? "text";
|
|
289
|
+
if (format === "text") {
|
|
290
|
+
const response = await this.readWire(path, options, "utf8");
|
|
291
|
+
return response.content;
|
|
292
|
+
}
|
|
293
|
+
const response = await this.readWire(path, options, "base64");
|
|
294
|
+
const bytes = buffer_1.Buffer.from(response.content, "base64");
|
|
295
|
+
if (format === "bytes") {
|
|
296
|
+
return bytes;
|
|
297
|
+
}
|
|
298
|
+
if (format === "blob") {
|
|
299
|
+
return new buffer_1.Blob([bytes], {
|
|
300
|
+
type: response.contentType || "application/octet-stream",
|
|
301
|
+
});
|
|
302
|
+
}
|
|
303
|
+
return toReadableStream(bytes);
|
|
304
|
+
}
|
|
305
|
+
async readText(path, options = {}) {
|
|
306
|
+
return this.read(path, { ...options, format: "text" });
|
|
307
|
+
}
|
|
308
|
+
async readBytes(path, options = {}) {
|
|
309
|
+
return this.read(path, { ...options, format: "bytes" });
|
|
310
|
+
}
|
|
311
|
+
async write(pathOrFiles, data) {
|
|
312
|
+
if (typeof pathOrFiles !== "string" && !Array.isArray(pathOrFiles)) {
|
|
313
|
+
throw new Error("Path or files are required");
|
|
314
|
+
}
|
|
315
|
+
if (typeof pathOrFiles === "string" && data === undefined) {
|
|
316
|
+
throw new Error("Path and data are required");
|
|
317
|
+
}
|
|
318
|
+
const files = typeof pathOrFiles === "string"
|
|
319
|
+
? [{ path: pathOrFiles, data: data }]
|
|
320
|
+
: pathOrFiles;
|
|
321
|
+
if (files.length === 0) {
|
|
322
|
+
return [];
|
|
323
|
+
}
|
|
324
|
+
const encodedFiles = await Promise.all(files.map(async (file) => {
|
|
325
|
+
if (!file || typeof file.path !== "string" || file.path.length === 0) {
|
|
326
|
+
throw new Error("Each write entry requires a path");
|
|
327
|
+
}
|
|
328
|
+
return {
|
|
329
|
+
path: file.path,
|
|
330
|
+
...(await encodeWriteData(file.data)),
|
|
331
|
+
};
|
|
332
|
+
}));
|
|
333
|
+
const response = await this.transport.requestJSON("/sandbox/files/write", {
|
|
334
|
+
method: "POST",
|
|
335
|
+
body: JSON.stringify({ files: encodedFiles }),
|
|
336
|
+
headers: {
|
|
337
|
+
"content-type": "application/json",
|
|
338
|
+
},
|
|
339
|
+
});
|
|
340
|
+
const results = response.files.map(normalizeWriteInfo);
|
|
341
|
+
return typeof pathOrFiles === "string" ? results[0] : results;
|
|
342
|
+
}
|
|
343
|
+
async writeText(path, data, options = {}) {
|
|
344
|
+
return this.writeSingle(path, data, "utf8", options);
|
|
345
|
+
}
|
|
346
|
+
async writeBytes(path, data, options = {}) {
|
|
347
|
+
return this.writeSingle(path, buffer_1.Buffer.from(data).toString("base64"), "base64", options);
|
|
348
|
+
}
|
|
349
|
+
async upload(path, data) {
|
|
350
|
+
const body = typeof data === "string" ? buffer_1.Buffer.from(data, "utf8") : buffer_1.Buffer.from(data);
|
|
351
|
+
const response = await this.transport.requestJSON("/sandbox/files/upload", {
|
|
352
|
+
method: "PUT",
|
|
353
|
+
body,
|
|
354
|
+
}, { path });
|
|
355
|
+
return {
|
|
356
|
+
path: response.path,
|
|
357
|
+
bytesWritten: response.bytesWritten,
|
|
358
|
+
};
|
|
359
|
+
}
|
|
360
|
+
async download(path) {
|
|
361
|
+
return this.transport.requestBuffer("/sandbox/files/download", undefined, {
|
|
362
|
+
path,
|
|
363
|
+
});
|
|
364
|
+
}
|
|
365
|
+
async makeDir(path, options = {}) {
|
|
366
|
+
const response = await this.transport.requestJSON("/sandbox/files/mkdir", {
|
|
367
|
+
method: "POST",
|
|
368
|
+
body: JSON.stringify({
|
|
369
|
+
path,
|
|
370
|
+
parents: options.parents,
|
|
371
|
+
mode: options.mode,
|
|
372
|
+
}),
|
|
373
|
+
headers: {
|
|
374
|
+
"content-type": "application/json",
|
|
375
|
+
},
|
|
376
|
+
});
|
|
377
|
+
return Boolean(response.created);
|
|
378
|
+
}
|
|
379
|
+
async rename(oldPath, newPath) {
|
|
380
|
+
const response = await this.transport.requestJSON("/sandbox/files/move", {
|
|
381
|
+
method: "POST",
|
|
382
|
+
body: JSON.stringify({
|
|
383
|
+
from: oldPath,
|
|
384
|
+
to: newPath,
|
|
385
|
+
}),
|
|
386
|
+
headers: {
|
|
387
|
+
"content-type": "application/json",
|
|
388
|
+
},
|
|
389
|
+
});
|
|
390
|
+
return normalizeFileInfo(response.entry);
|
|
391
|
+
}
|
|
392
|
+
async remove(path, options = {}) {
|
|
393
|
+
await this.transport.requestJSON("/sandbox/files/delete", {
|
|
394
|
+
method: "POST",
|
|
395
|
+
body: JSON.stringify({
|
|
396
|
+
path,
|
|
397
|
+
recursive: options.recursive,
|
|
398
|
+
}),
|
|
399
|
+
headers: {
|
|
400
|
+
"content-type": "application/json",
|
|
401
|
+
},
|
|
402
|
+
});
|
|
403
|
+
}
|
|
404
|
+
async copy(params) {
|
|
405
|
+
const response = await this.transport.requestJSON("/sandbox/files/copy", {
|
|
406
|
+
method: "POST",
|
|
407
|
+
body: JSON.stringify({
|
|
408
|
+
from: params.source,
|
|
409
|
+
to: params.destination,
|
|
410
|
+
recursive: params.recursive,
|
|
411
|
+
overwrite: params.overwrite,
|
|
412
|
+
}),
|
|
413
|
+
headers: {
|
|
414
|
+
"content-type": "application/json",
|
|
415
|
+
},
|
|
416
|
+
});
|
|
417
|
+
return normalizeFileInfo(response.entry);
|
|
418
|
+
}
|
|
419
|
+
async chmod(params) {
|
|
420
|
+
await this.transport.requestJSON("/sandbox/files/chmod", {
|
|
421
|
+
method: "POST",
|
|
422
|
+
body: JSON.stringify(params),
|
|
423
|
+
headers: {
|
|
424
|
+
"content-type": "application/json",
|
|
425
|
+
},
|
|
426
|
+
});
|
|
427
|
+
}
|
|
428
|
+
async chown(params) {
|
|
429
|
+
await this.transport.requestJSON("/sandbox/files/chown", {
|
|
430
|
+
method: "POST",
|
|
431
|
+
body: JSON.stringify(params),
|
|
432
|
+
headers: {
|
|
433
|
+
"content-type": "application/json",
|
|
434
|
+
},
|
|
435
|
+
});
|
|
436
|
+
}
|
|
437
|
+
async watchDir(path, onEvent, options = {}) {
|
|
438
|
+
const response = await this.transport.requestJSON("/sandbox/files/watch", {
|
|
439
|
+
method: "POST",
|
|
440
|
+
body: JSON.stringify({
|
|
441
|
+
path,
|
|
442
|
+
recursive: options.recursive,
|
|
443
|
+
}),
|
|
444
|
+
headers: {
|
|
445
|
+
"content-type": "application/json",
|
|
446
|
+
},
|
|
447
|
+
});
|
|
448
|
+
const watch = new RuntimeFileWatchHandle(this.transport, this.getConnectionInfo, response.watch, this.runtimeProxyOverride);
|
|
449
|
+
return new SandboxWatchDirHandle(watch, onEvent, options.onExit, options.timeoutMs);
|
|
450
|
+
}
|
|
451
|
+
async uploadUrl(path, options = {}) {
|
|
452
|
+
return this.transport.requestJSON("/sandbox/files/presign-upload", {
|
|
453
|
+
method: "POST",
|
|
454
|
+
body: JSON.stringify({
|
|
455
|
+
path,
|
|
456
|
+
expiresInSeconds: options.expiresInSeconds,
|
|
457
|
+
oneTime: options.oneTime,
|
|
458
|
+
}),
|
|
459
|
+
headers: {
|
|
460
|
+
"content-type": "application/json",
|
|
461
|
+
},
|
|
462
|
+
});
|
|
463
|
+
}
|
|
464
|
+
async downloadUrl(path, options = {}) {
|
|
465
|
+
return this.transport.requestJSON("/sandbox/files/presign-download", {
|
|
466
|
+
method: "POST",
|
|
467
|
+
body: JSON.stringify({
|
|
468
|
+
path,
|
|
469
|
+
expiresInSeconds: options.expiresInSeconds,
|
|
470
|
+
oneTime: options.oneTime,
|
|
471
|
+
}),
|
|
472
|
+
headers: {
|
|
473
|
+
"content-type": "application/json",
|
|
474
|
+
},
|
|
475
|
+
});
|
|
476
|
+
}
|
|
477
|
+
async readWire(path, options, encoding) {
|
|
478
|
+
return this.transport.requestJSON("/sandbox/files/read", {
|
|
479
|
+
method: "POST",
|
|
480
|
+
body: JSON.stringify({
|
|
481
|
+
path,
|
|
482
|
+
offset: options.offset,
|
|
483
|
+
length: options.length,
|
|
484
|
+
encoding,
|
|
485
|
+
}),
|
|
486
|
+
headers: {
|
|
487
|
+
"content-type": "application/json",
|
|
488
|
+
},
|
|
489
|
+
});
|
|
490
|
+
}
|
|
491
|
+
async writeSingle(path, data, encoding, options) {
|
|
492
|
+
const response = await this.transport.requestJSON("/sandbox/files/write", {
|
|
493
|
+
method: "POST",
|
|
494
|
+
body: JSON.stringify({
|
|
495
|
+
path,
|
|
496
|
+
data,
|
|
497
|
+
encoding,
|
|
498
|
+
append: options.append,
|
|
499
|
+
mode: options.mode,
|
|
500
|
+
}),
|
|
501
|
+
headers: {
|
|
502
|
+
"content-type": "application/json",
|
|
503
|
+
},
|
|
504
|
+
});
|
|
505
|
+
return normalizeWriteInfo(response.files[0]);
|
|
506
|
+
}
|
|
507
|
+
}
|
|
508
|
+
exports.SandboxFilesApi = SandboxFilesApi;
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
export { RuntimeTransport } from "./base";
|
|
2
|
+
export { SandboxProcessesApi, SandboxProcessHandle } from "./process";
|
|
3
|
+
export { SandboxFilesApi, SandboxWatchDirHandle } from "./files";
|
|
4
|
+
export { SandboxTerminalApi, SandboxTerminalConnection, SandboxTerminalHandle } from "./terminal";
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.SandboxTerminalHandle = exports.SandboxTerminalConnection = exports.SandboxTerminalApi = exports.SandboxWatchDirHandle = exports.SandboxFilesApi = exports.SandboxProcessHandle = exports.SandboxProcessesApi = exports.RuntimeTransport = void 0;
|
|
4
|
+
var base_1 = require("./base");
|
|
5
|
+
Object.defineProperty(exports, "RuntimeTransport", { enumerable: true, get: function () { return base_1.RuntimeTransport; } });
|
|
6
|
+
var process_1 = require("./process");
|
|
7
|
+
Object.defineProperty(exports, "SandboxProcessesApi", { enumerable: true, get: function () { return process_1.SandboxProcessesApi; } });
|
|
8
|
+
Object.defineProperty(exports, "SandboxProcessHandle", { enumerable: true, get: function () { return process_1.SandboxProcessHandle; } });
|
|
9
|
+
var files_1 = require("./files");
|
|
10
|
+
Object.defineProperty(exports, "SandboxFilesApi", { enumerable: true, get: function () { return files_1.SandboxFilesApi; } });
|
|
11
|
+
Object.defineProperty(exports, "SandboxWatchDirHandle", { enumerable: true, get: function () { return files_1.SandboxWatchDirHandle; } });
|
|
12
|
+
var terminal_1 = require("./terminal");
|
|
13
|
+
Object.defineProperty(exports, "SandboxTerminalApi", { enumerable: true, get: function () { return terminal_1.SandboxTerminalApi; } });
|
|
14
|
+
Object.defineProperty(exports, "SandboxTerminalConnection", { enumerable: true, get: function () { return terminal_1.SandboxTerminalConnection; } });
|
|
15
|
+
Object.defineProperty(exports, "SandboxTerminalHandle", { enumerable: true, get: function () { return terminal_1.SandboxTerminalHandle; } });
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import { RuntimeTransport } from "./base";
|
|
2
|
+
import { SandboxExecParams, SandboxProcessListParams, SandboxProcessListResponse, SandboxProcessResult, SandboxProcessSignal, SandboxProcessStdinParams, SandboxProcessStreamEvent, SandboxProcessSummary, SandboxProcessWaitParams } from "../types/sandbox";
|
|
3
|
+
export declare class SandboxProcessHandle {
|
|
4
|
+
private readonly transport;
|
|
5
|
+
private summary;
|
|
6
|
+
constructor(transport: RuntimeTransport, summary: SandboxProcessSummary);
|
|
7
|
+
get id(): string;
|
|
8
|
+
get status(): SandboxProcessSummary["status"];
|
|
9
|
+
toJSON(): SandboxProcessSummary;
|
|
10
|
+
refresh(): Promise<SandboxProcessHandle>;
|
|
11
|
+
wait(params?: SandboxProcessWaitParams): Promise<SandboxProcessResult>;
|
|
12
|
+
signal(signal: SandboxProcessSignal): Promise<void>;
|
|
13
|
+
kill(params?: SandboxProcessWaitParams): Promise<SandboxProcessResult>;
|
|
14
|
+
writeStdin(input: string | Uint8Array | SandboxProcessStdinParams): Promise<void>;
|
|
15
|
+
stream(fromSeq?: number): AsyncGenerator<SandboxProcessStreamEvent>;
|
|
16
|
+
result(): Promise<SandboxProcessResult>;
|
|
17
|
+
}
|
|
18
|
+
export declare class SandboxProcessesApi {
|
|
19
|
+
private readonly transport;
|
|
20
|
+
constructor(transport: RuntimeTransport);
|
|
21
|
+
exec(input: SandboxExecParams): Promise<SandboxProcessResult>;
|
|
22
|
+
start(input: SandboxExecParams): Promise<SandboxProcessHandle>;
|
|
23
|
+
get(processId: string): Promise<SandboxProcessHandle>;
|
|
24
|
+
list(params?: SandboxProcessListParams): Promise<SandboxProcessListResponse>;
|
|
25
|
+
}
|