@hyperbrowser/sdk 0.88.0 → 0.88.2

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 CHANGED
@@ -159,11 +159,15 @@ const main = async () => {
159
159
  const sandbox = await client.sandboxes.create({
160
160
  imageName: "ubuntu-24-node",
161
161
  region: "us-west",
162
+ cpu: 4,
163
+ memoryMiB: 4096,
164
+ diskMiB: 8192,
162
165
  });
163
166
 
164
167
  // Provide exactly one launch source:
165
168
  // snapshotName or imageName.
166
169
  // snapshotId requires snapshotName and imageId requires imageName.
170
+ // cpu, memoryMiB, and diskMiB are only available for image launches.
167
171
 
168
172
  const version = await sandbox.exec("node -v");
169
173
  console.log(version.stdout.trim());
@@ -240,6 +244,9 @@ Create a sandbox with pre-exposed ports:
240
244
  ```typescript
241
245
  const sandbox = await client.sandboxes.create({
242
246
  imageName: "node",
247
+ cpu: 2,
248
+ memoryMiB: 2048,
249
+ diskMiB: 8192,
243
250
  exposedPorts: [{ port: 3000, auth: true }],
244
251
  });
245
252
 
@@ -20,6 +20,9 @@ export declare class SandboxHandle {
20
20
  get runtime(): SandboxDetail["runtime"];
21
21
  get tokenExpiresAt(): string | null;
22
22
  get sessionUrl(): string;
23
+ get cpu(): number | null | undefined;
24
+ get memoryMiB(): number | null | undefined;
25
+ get diskMiB(): number | null | undefined;
23
26
  get exposedPorts(): SandboxExposeResult[];
24
27
  toJSON(): SandboxDetail;
25
28
  info(): Promise<SandboxDetail>;
@@ -8,6 +8,67 @@ const process_1 = require("../sandbox/process");
8
8
  const terminal_1 = require("../sandbox/terminal");
9
9
  const base_2 = require("./base");
10
10
  const RUNTIME_SESSION_REFRESH_BUFFER_MS = 60000;
11
+ const validateOptionalPositiveInteger = (value, fieldName) => {
12
+ if (value === undefined) {
13
+ return;
14
+ }
15
+ if (!Number.isInteger(value) || value < 1) {
16
+ throw new client_1.HyperbrowserError(`${fieldName} must be a positive integer`, undefined);
17
+ }
18
+ };
19
+ const normalizeSandbox = (sandbox) => {
20
+ const { vcpus, memMiB, diskSizeMiB, ...rest } = sandbox;
21
+ return {
22
+ ...rest,
23
+ cpu: vcpus,
24
+ memoryMiB: memMiB,
25
+ diskMiB: diskSizeMiB,
26
+ };
27
+ };
28
+ const normalizeSandboxDetail = (detail) => {
29
+ const { token, tokenExpiresAt, ...sandbox } = detail;
30
+ return {
31
+ ...normalizeSandbox(sandbox),
32
+ token,
33
+ tokenExpiresAt,
34
+ };
35
+ };
36
+ const normalizeSandboxListResponse = (response) => ({
37
+ ...response,
38
+ sandboxes: response.sandboxes.map(normalizeSandbox),
39
+ });
40
+ const serializeCreateSandboxParams = (params) => {
41
+ if ("imageName" in params) {
42
+ validateOptionalPositiveInteger(params.cpu, "cpu");
43
+ validateOptionalPositiveInteger(params.memoryMiB, "memoryMiB");
44
+ validateOptionalPositiveInteger(params.diskMiB, "diskMiB");
45
+ return {
46
+ imageName: params.imageName,
47
+ imageId: params.imageId,
48
+ region: params.region,
49
+ enableRecording: params.enableRecording,
50
+ exposedPorts: params.exposedPorts,
51
+ timeoutMinutes: params.timeoutMinutes,
52
+ vcpus: params.cpu,
53
+ memMiB: params.memoryMiB,
54
+ diskSizeMiB: params.diskMiB,
55
+ };
56
+ }
57
+ const snapshotParams = params;
58
+ if (snapshotParams.cpu !== undefined ||
59
+ snapshotParams.memoryMiB !== undefined ||
60
+ snapshotParams.diskMiB !== undefined) {
61
+ throw new client_1.HyperbrowserError("cpu, memoryMiB, and diskMiB are only supported for image launches", undefined);
62
+ }
63
+ return {
64
+ snapshotName: snapshotParams.snapshotName,
65
+ snapshotId: snapshotParams.snapshotId,
66
+ region: snapshotParams.region,
67
+ enableRecording: snapshotParams.enableRecording,
68
+ exposedPorts: snapshotParams.exposedPorts,
69
+ timeoutMinutes: snapshotParams.timeoutMinutes,
70
+ };
71
+ };
11
72
  const buildSandboxExposedUrl = (runtime, port) => {
12
73
  const baseUrl = new URL(runtime.baseUrl);
13
74
  const authority = baseUrl.port
@@ -45,6 +106,15 @@ class SandboxHandle {
45
106
  get sessionUrl() {
46
107
  return this.detail.sessionUrl;
47
108
  }
109
+ get cpu() {
110
+ return this.detail.cpu;
111
+ }
112
+ get memoryMiB() {
113
+ return this.detail.memoryMiB;
114
+ }
115
+ get diskMiB() {
116
+ return this.detail.diskMiB;
117
+ }
48
118
  get exposedPorts() {
49
119
  return (this.detail.exposedPorts ?? []).map((entry) => ({ ...entry }));
50
120
  }
@@ -215,7 +285,7 @@ class SandboxesService extends base_2.BaseService {
215
285
  }
216
286
  async list(params = {}) {
217
287
  try {
218
- return await this.request("/sandboxes", undefined, {
288
+ const response = await this.request("/sandboxes", undefined, {
219
289
  status: params.status,
220
290
  start: params.start,
221
291
  end: params.end,
@@ -223,6 +293,7 @@ class SandboxesService extends base_2.BaseService {
223
293
  page: params.page,
224
294
  limit: params.limit,
225
295
  });
296
+ return normalizeSandboxListResponse(response);
226
297
  }
227
298
  catch (error) {
228
299
  if (error instanceof client_1.HyperbrowserError) {
@@ -272,7 +343,8 @@ class SandboxesService extends base_2.BaseService {
272
343
  }
273
344
  async getDetail(id) {
274
345
  try {
275
- return await this.request(`/sandbox/${id}`);
346
+ const detail = await this.request(`/sandbox/${id}`);
347
+ return normalizeSandboxDetail(detail);
276
348
  }
277
349
  catch (error) {
278
350
  if (error instanceof client_1.HyperbrowserError) {
@@ -328,10 +400,11 @@ class SandboxesService extends base_2.BaseService {
328
400
  }
329
401
  async createDetail(params) {
330
402
  try {
331
- return await this.request("/sandbox", {
403
+ const detail = await this.request("/sandbox", {
332
404
  method: "POST",
333
- body: JSON.stringify(params),
405
+ body: JSON.stringify(serializeCreateSandboxParams(params)),
334
406
  });
407
+ return normalizeSandboxDetail(detail);
335
408
  }
336
409
  catch (error) {
337
410
  if (error instanceof client_1.HyperbrowserError) {
@@ -27,6 +27,9 @@ export interface Sandbox {
27
27
  sessionUrl: string;
28
28
  duration: number;
29
29
  proxyBytesUsed: number;
30
+ cpu?: number | null;
31
+ memoryMiB?: number | null;
32
+ diskMiB?: number | null;
30
33
  runtime: SandboxRuntimeTarget;
31
34
  exposedPorts: SandboxExposeResult[];
32
35
  }
@@ -45,11 +48,17 @@ export type CreateSandboxParams = (SandboxCreateCommonParams & {
45
48
  snapshotId?: string;
46
49
  imageName?: never;
47
50
  imageId?: never;
51
+ cpu?: never;
52
+ memoryMiB?: never;
53
+ diskMiB?: never;
48
54
  }) | (SandboxCreateCommonParams & {
49
55
  snapshotName?: never;
50
56
  snapshotId?: never;
51
57
  imageName: string;
52
58
  imageId?: string;
59
+ cpu?: number;
60
+ memoryMiB?: number;
61
+ diskMiB?: number;
53
62
  });
54
63
  export interface SandboxListParams {
55
64
  status?: SandboxStatus;
package/package.json CHANGED
@@ -1,8 +1,16 @@
1
1
  {
2
2
  "name": "@hyperbrowser/sdk",
3
- "version": "0.88.0",
3
+ "version": "0.88.2",
4
4
  "description": "Node SDK for Hyperbrowser API",
5
5
  "author": "",
6
+ "repository": {
7
+ "type": "git",
8
+ "url": "https://github.com/hyperbrowserai/node-sdk"
9
+ },
10
+ "homepage": "https://github.com/hyperbrowserai/node-sdk#readme",
11
+ "bugs": {
12
+ "url": "https://github.com/hyperbrowserai/node-sdk/issues"
13
+ },
6
14
  "main": "dist/index.js",
7
15
  "types": "dist/index.d.ts",
8
16
  "type": "commonjs",