@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,314 @@
|
|
|
1
|
+
import type { Blob } from "buffer";
|
|
2
|
+
import type { ReadableStream } from "node:stream/web";
|
|
3
|
+
import { SessionRegion } from "./constants";
|
|
4
|
+
import { SessionLaunchState, SessionStatus } from "./session";
|
|
5
|
+
export type SandboxStatus = SessionStatus;
|
|
6
|
+
export interface SandboxRuntimeTarget {
|
|
7
|
+
transport: "regional_proxy";
|
|
8
|
+
host: string;
|
|
9
|
+
baseUrl: string;
|
|
10
|
+
}
|
|
11
|
+
export interface Sandbox {
|
|
12
|
+
id: string;
|
|
13
|
+
teamId: string;
|
|
14
|
+
status: SandboxStatus;
|
|
15
|
+
endTime?: number | null;
|
|
16
|
+
startTime?: number | null;
|
|
17
|
+
createdAt: string;
|
|
18
|
+
updatedAt: string;
|
|
19
|
+
closeReason?: string | null;
|
|
20
|
+
dataConsumed?: number;
|
|
21
|
+
proxyDataConsumed?: number;
|
|
22
|
+
usageType?: string;
|
|
23
|
+
jobId?: string | null;
|
|
24
|
+
launchState?: SessionLaunchState | null;
|
|
25
|
+
creditsUsed: number | null;
|
|
26
|
+
region: SessionRegion;
|
|
27
|
+
sessionUrl: string;
|
|
28
|
+
duration: number;
|
|
29
|
+
proxyBytesUsed: number;
|
|
30
|
+
runtime: SandboxRuntimeTarget;
|
|
31
|
+
}
|
|
32
|
+
export interface SandboxDetail extends Sandbox {
|
|
33
|
+
token: string | null;
|
|
34
|
+
tokenExpiresAt: string | null;
|
|
35
|
+
}
|
|
36
|
+
interface SandboxCreateCommonParams {
|
|
37
|
+
region?: SessionRegion;
|
|
38
|
+
enableRecording?: boolean;
|
|
39
|
+
timeoutMinutes?: number;
|
|
40
|
+
}
|
|
41
|
+
export type CreateSandboxParams = (SandboxCreateCommonParams & {
|
|
42
|
+
snapshotName: string;
|
|
43
|
+
snapshotId?: string;
|
|
44
|
+
imageName?: never;
|
|
45
|
+
imageId?: never;
|
|
46
|
+
}) | (SandboxCreateCommonParams & {
|
|
47
|
+
snapshotName?: never;
|
|
48
|
+
snapshotId?: never;
|
|
49
|
+
imageName: string;
|
|
50
|
+
imageId?: string;
|
|
51
|
+
});
|
|
52
|
+
export interface SandboxListParams {
|
|
53
|
+
status?: SandboxStatus;
|
|
54
|
+
page?: number;
|
|
55
|
+
limit?: number;
|
|
56
|
+
}
|
|
57
|
+
export interface SandboxListResponse {
|
|
58
|
+
sandboxes: Sandbox[];
|
|
59
|
+
totalCount: number;
|
|
60
|
+
page: number;
|
|
61
|
+
perPage: number;
|
|
62
|
+
}
|
|
63
|
+
export interface SandboxImageSummary {
|
|
64
|
+
id: string;
|
|
65
|
+
imageName: string;
|
|
66
|
+
namespace: string;
|
|
67
|
+
uploaded: boolean;
|
|
68
|
+
createdAt: string;
|
|
69
|
+
updatedAt: string;
|
|
70
|
+
}
|
|
71
|
+
export interface SandboxImageListResponse {
|
|
72
|
+
images: SandboxImageSummary[];
|
|
73
|
+
}
|
|
74
|
+
export type SandboxSnapshotStatus = "creating" | "created" | "failed";
|
|
75
|
+
export interface SandboxSnapshotSummary {
|
|
76
|
+
id: string;
|
|
77
|
+
snapshotName: string;
|
|
78
|
+
namespace: string;
|
|
79
|
+
imageNamespace: string;
|
|
80
|
+
imageName: string;
|
|
81
|
+
imageId: string;
|
|
82
|
+
status: SandboxSnapshotStatus;
|
|
83
|
+
compatibilityTag: string;
|
|
84
|
+
metadata: Record<string, unknown>;
|
|
85
|
+
uploaded: boolean;
|
|
86
|
+
createdAt: string;
|
|
87
|
+
updatedAt: string;
|
|
88
|
+
}
|
|
89
|
+
export interface SandboxSnapshotListParams {
|
|
90
|
+
status?: SandboxSnapshotStatus;
|
|
91
|
+
limit?: number;
|
|
92
|
+
}
|
|
93
|
+
export interface SandboxSnapshotListResponse {
|
|
94
|
+
snapshots: SandboxSnapshotSummary[];
|
|
95
|
+
}
|
|
96
|
+
export interface SandboxMemorySnapshotParams {
|
|
97
|
+
snapshotName?: string;
|
|
98
|
+
}
|
|
99
|
+
export interface SandboxMemorySnapshotResult {
|
|
100
|
+
snapshotName: string;
|
|
101
|
+
snapshotId: string;
|
|
102
|
+
namespace: string;
|
|
103
|
+
status: string;
|
|
104
|
+
imageName: string;
|
|
105
|
+
imageId: string;
|
|
106
|
+
imageNamespace: string;
|
|
107
|
+
}
|
|
108
|
+
export interface SandboxExposeParams {
|
|
109
|
+
port: number;
|
|
110
|
+
auth?: boolean;
|
|
111
|
+
}
|
|
112
|
+
export interface SandboxExposeResult {
|
|
113
|
+
port: number;
|
|
114
|
+
auth: boolean;
|
|
115
|
+
url: string;
|
|
116
|
+
}
|
|
117
|
+
export type SandboxProcessStatus = "queued" | "running" | "exited" | "failed" | "killed" | "timed_out";
|
|
118
|
+
export interface SandboxExecParams {
|
|
119
|
+
command: string;
|
|
120
|
+
args?: string[];
|
|
121
|
+
cwd?: string;
|
|
122
|
+
env?: Record<string, string>;
|
|
123
|
+
timeoutMs?: number;
|
|
124
|
+
timeoutSec?: number;
|
|
125
|
+
useShell?: boolean;
|
|
126
|
+
}
|
|
127
|
+
export interface SandboxProcessSummary {
|
|
128
|
+
id: string;
|
|
129
|
+
status: SandboxProcessStatus;
|
|
130
|
+
command: string;
|
|
131
|
+
args?: string[];
|
|
132
|
+
cwd: string;
|
|
133
|
+
pid?: number;
|
|
134
|
+
exitCode?: number | null;
|
|
135
|
+
startedAt: number;
|
|
136
|
+
completedAt?: number;
|
|
137
|
+
}
|
|
138
|
+
export interface SandboxProcessResult {
|
|
139
|
+
id: string;
|
|
140
|
+
status: SandboxProcessStatus;
|
|
141
|
+
exitCode?: number | null;
|
|
142
|
+
stdout: string;
|
|
143
|
+
stderr: string;
|
|
144
|
+
startedAt: number;
|
|
145
|
+
completedAt?: number;
|
|
146
|
+
error?: string;
|
|
147
|
+
}
|
|
148
|
+
export interface SandboxProcessListParams {
|
|
149
|
+
status?: SandboxProcessStatus | SandboxProcessStatus[];
|
|
150
|
+
limit?: number;
|
|
151
|
+
cursor?: string | number;
|
|
152
|
+
createdAfter?: number;
|
|
153
|
+
createdBefore?: number;
|
|
154
|
+
}
|
|
155
|
+
export interface SandboxProcessListResponse {
|
|
156
|
+
data: SandboxProcessSummary[];
|
|
157
|
+
nextCursor?: string;
|
|
158
|
+
}
|
|
159
|
+
export interface SandboxProcessWaitParams {
|
|
160
|
+
timeoutMs?: number;
|
|
161
|
+
timeoutSec?: number;
|
|
162
|
+
}
|
|
163
|
+
export type SandboxProcessSignal = "TERM" | "KILL" | "INT" | "HUP" | "QUIT" | string;
|
|
164
|
+
export interface SandboxProcessStdinParams {
|
|
165
|
+
data?: string | Uint8Array;
|
|
166
|
+
encoding?: "utf8" | "base64";
|
|
167
|
+
eof?: boolean;
|
|
168
|
+
}
|
|
169
|
+
export type SandboxProcessStreamEvent = {
|
|
170
|
+
type: "stdout" | "stderr" | "system";
|
|
171
|
+
seq: number;
|
|
172
|
+
data: string;
|
|
173
|
+
timestamp: number;
|
|
174
|
+
} | {
|
|
175
|
+
type: "exit";
|
|
176
|
+
result: SandboxProcessResult;
|
|
177
|
+
};
|
|
178
|
+
export type SandboxFileType = "file" | "dir";
|
|
179
|
+
export interface SandboxFileInfo {
|
|
180
|
+
path: string;
|
|
181
|
+
name: string;
|
|
182
|
+
type: SandboxFileType;
|
|
183
|
+
size: number;
|
|
184
|
+
mode: number;
|
|
185
|
+
permissions: string;
|
|
186
|
+
owner: string;
|
|
187
|
+
group: string;
|
|
188
|
+
modifiedTime?: Date;
|
|
189
|
+
symlinkTarget?: string;
|
|
190
|
+
}
|
|
191
|
+
export interface SandboxFileWriteInfo {
|
|
192
|
+
path: string;
|
|
193
|
+
name: string;
|
|
194
|
+
type?: SandboxFileType;
|
|
195
|
+
}
|
|
196
|
+
export interface SandboxFileListOptions {
|
|
197
|
+
depth?: number;
|
|
198
|
+
}
|
|
199
|
+
export type SandboxFileReadFormat = "text" | "bytes" | "blob" | "stream";
|
|
200
|
+
export interface SandboxFileReadOptions {
|
|
201
|
+
offset?: number;
|
|
202
|
+
length?: number;
|
|
203
|
+
format?: SandboxFileReadFormat;
|
|
204
|
+
}
|
|
205
|
+
export type SandboxFileWriteData = string | Uint8Array | Buffer | ArrayBuffer | Blob | ReadableStream<Uint8Array>;
|
|
206
|
+
export interface SandboxFileWriteEntry {
|
|
207
|
+
path: string;
|
|
208
|
+
data: SandboxFileWriteData;
|
|
209
|
+
}
|
|
210
|
+
export interface SandboxFileTextWriteOptions {
|
|
211
|
+
append?: boolean;
|
|
212
|
+
mode?: string;
|
|
213
|
+
}
|
|
214
|
+
export interface SandboxFileBytesWriteOptions {
|
|
215
|
+
append?: boolean;
|
|
216
|
+
mode?: string;
|
|
217
|
+
}
|
|
218
|
+
export interface SandboxFileRemoveOptions {
|
|
219
|
+
recursive?: boolean;
|
|
220
|
+
}
|
|
221
|
+
export interface SandboxFileMakeDirOptions {
|
|
222
|
+
parents?: boolean;
|
|
223
|
+
mode?: string;
|
|
224
|
+
}
|
|
225
|
+
export interface SandboxFileTransferResult {
|
|
226
|
+
path: string;
|
|
227
|
+
bytesWritten: number;
|
|
228
|
+
}
|
|
229
|
+
export interface SandboxFileCopyParams {
|
|
230
|
+
source: string;
|
|
231
|
+
destination: string;
|
|
232
|
+
recursive?: boolean;
|
|
233
|
+
overwrite?: boolean;
|
|
234
|
+
}
|
|
235
|
+
export interface SandboxFileChmodParams {
|
|
236
|
+
path: string;
|
|
237
|
+
mode: string;
|
|
238
|
+
recursive?: boolean;
|
|
239
|
+
}
|
|
240
|
+
export interface SandboxFileChownParams {
|
|
241
|
+
path: string;
|
|
242
|
+
uid?: number;
|
|
243
|
+
gid?: number;
|
|
244
|
+
recursive?: boolean;
|
|
245
|
+
}
|
|
246
|
+
export type SandboxFileSystemEventType = "chmod" | "create" | "remove" | "rename" | "write";
|
|
247
|
+
export interface SandboxFileSystemEvent {
|
|
248
|
+
name: string;
|
|
249
|
+
type: SandboxFileSystemEventType;
|
|
250
|
+
}
|
|
251
|
+
export interface SandboxWatchDirOptions {
|
|
252
|
+
recursive?: boolean;
|
|
253
|
+
timeoutMs?: number;
|
|
254
|
+
onExit?: (error?: Error) => void | Promise<void>;
|
|
255
|
+
}
|
|
256
|
+
export interface SandboxPresignFileParams {
|
|
257
|
+
path: string;
|
|
258
|
+
expiresInSeconds?: number;
|
|
259
|
+
oneTime?: boolean;
|
|
260
|
+
}
|
|
261
|
+
export interface SandboxPresignedUrl {
|
|
262
|
+
token: string;
|
|
263
|
+
path: string;
|
|
264
|
+
method: string;
|
|
265
|
+
expiresAt: number;
|
|
266
|
+
url: string;
|
|
267
|
+
}
|
|
268
|
+
export interface SandboxTerminalCreateParams {
|
|
269
|
+
command: string;
|
|
270
|
+
args?: string[];
|
|
271
|
+
cwd?: string;
|
|
272
|
+
env?: Record<string, string>;
|
|
273
|
+
useShell?: boolean;
|
|
274
|
+
rows?: number;
|
|
275
|
+
cols?: number;
|
|
276
|
+
timeoutMs?: number;
|
|
277
|
+
}
|
|
278
|
+
export interface SandboxTerminalOutputChunk {
|
|
279
|
+
seq: number;
|
|
280
|
+
data: string;
|
|
281
|
+
raw: Buffer;
|
|
282
|
+
timestamp: number;
|
|
283
|
+
}
|
|
284
|
+
export interface SandboxTerminalStatus {
|
|
285
|
+
id: string;
|
|
286
|
+
command: string;
|
|
287
|
+
args?: string[];
|
|
288
|
+
cwd: string;
|
|
289
|
+
pid?: number;
|
|
290
|
+
running: boolean;
|
|
291
|
+
exitCode?: number | null;
|
|
292
|
+
error?: string;
|
|
293
|
+
timedOut?: boolean;
|
|
294
|
+
rows: number;
|
|
295
|
+
cols: number;
|
|
296
|
+
startedAt: number;
|
|
297
|
+
finishedAt?: number;
|
|
298
|
+
output?: SandboxTerminalOutputChunk[];
|
|
299
|
+
}
|
|
300
|
+
export interface SandboxTerminalWaitParams {
|
|
301
|
+
timeoutMs?: number;
|
|
302
|
+
includeOutput?: boolean;
|
|
303
|
+
}
|
|
304
|
+
export interface SandboxTerminalKillParams {
|
|
305
|
+
signal?: string;
|
|
306
|
+
timeoutMs?: number;
|
|
307
|
+
}
|
|
308
|
+
export type SandboxTerminalEvent = ({
|
|
309
|
+
type: "output";
|
|
310
|
+
} & SandboxTerminalOutputChunk) | {
|
|
311
|
+
type: "exit";
|
|
312
|
+
status: SandboxTerminalStatus;
|
|
313
|
+
};
|
|
314
|
+
export {};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@hyperbrowser/sdk",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.86.0",
|
|
4
4
|
"description": "Node SDK for Hyperbrowser API",
|
|
5
5
|
"author": "",
|
|
6
6
|
"main": "dist/index.js",
|
|
@@ -11,7 +11,9 @@
|
|
|
11
11
|
"build": "tsc",
|
|
12
12
|
"lint": "eslint src/**/*.ts",
|
|
13
13
|
"prepare": "yarn build",
|
|
14
|
-
"test": "
|
|
14
|
+
"test": "vitest run",
|
|
15
|
+
"test:e2e": "vitest run tests/sandbox/e2e",
|
|
16
|
+
"test:watch": "vitest",
|
|
15
17
|
"format": "prettier --write 'src/**/*.ts'"
|
|
16
18
|
},
|
|
17
19
|
"files": [
|
|
@@ -32,19 +34,23 @@
|
|
|
32
34
|
"dependencies": {
|
|
33
35
|
"form-data": "^4.0.1",
|
|
34
36
|
"node-fetch": "2.7.0",
|
|
37
|
+
"ws": "^8.19.0",
|
|
35
38
|
"zod": "^4.1.12",
|
|
36
39
|
"zod-to-json-schema": "^3.25.0"
|
|
37
40
|
},
|
|
38
41
|
"devDependencies": {
|
|
39
42
|
"@types/node": "^22.9.1",
|
|
40
43
|
"@types/node-fetch": "^2.6.4",
|
|
44
|
+
"@types/ws": "^8.18.1",
|
|
41
45
|
"@typescript-eslint/eslint-plugin": "^8.15.0",
|
|
42
46
|
"@typescript-eslint/parser": "^8.15.0",
|
|
47
|
+
"dotenv": "^17.3.1",
|
|
43
48
|
"eslint": "^9.15.0",
|
|
44
49
|
"eslint-config-prettier": "^9.1.0",
|
|
45
50
|
"prettier": "^3.3.3",
|
|
46
51
|
"ts-node": "^10.9.2",
|
|
47
|
-
"typescript": "^5.6.3"
|
|
52
|
+
"typescript": "^5.6.3",
|
|
53
|
+
"vitest": "^4.0.18"
|
|
48
54
|
},
|
|
49
55
|
"exports": {
|
|
50
56
|
".": {
|