@hyperbrowser/sdk 0.93.0 → 1.0.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 +190 -0
- package/dist/client.d.ts +2 -20
- package/dist/client.js +5 -17
- package/dist/error.d.ts +27 -0
- package/dist/error.js +32 -0
- package/dist/image-builds.d.ts +6 -0
- package/dist/image-builds.js +12 -0
- package/dist/index.d.ts +3 -0
- package/dist/index.js +12 -1
- package/dist/retry.d.ts +14 -0
- package/dist/retry.js +49 -0
- package/dist/sandbox/base.d.ts +27 -0
- package/dist/sandbox/base.js +298 -99
- package/dist/sandbox/files.d.ts +24 -25
- package/dist/sandbox/files.js +146 -37
- package/dist/sandbox/image-build/artifacts.d.ts +16 -0
- package/dist/sandbox/image-build/artifacts.js +16 -0
- package/dist/sandbox/image-build/blake2b.d.ts +2 -0
- package/dist/sandbox/image-build/blake2b.js +89 -0
- package/dist/sandbox/image-build/common.d.ts +19 -0
- package/dist/sandbox/image-build/common.js +109 -0
- package/dist/sandbox/image-build/context.d.ts +43 -0
- package/dist/sandbox/image-build/context.js +599 -0
- package/dist/sandbox/image-build/docker-image.d.ts +34 -0
- package/dist/sandbox/image-build/docker-image.js +472 -0
- package/dist/sandbox/image-build/dockerfile-analysis.d.ts +17 -0
- package/dist/sandbox/image-build/dockerfile-analysis.js +409 -0
- package/dist/sandbox/image-build/dockerignore.d.ts +18 -0
- package/dist/sandbox/image-build/dockerignore.js +275 -0
- package/dist/sandbox/image-build/gzip.d.ts +11 -0
- package/dist/sandbox/image-build/gzip.js +91 -0
- package/dist/sandbox/image-build/image-init.d.ts +5 -0
- package/dist/sandbox/image-build/image-init.js +97 -0
- package/dist/sandbox/image-build/index.d.ts +13 -0
- package/dist/sandbox/image-build/index.js +36 -0
- package/dist/sandbox/image-build/local-docker.d.ts +11 -0
- package/dist/sandbox/image-build/local-docker.js +72 -0
- package/dist/sandbox/image-build/resolution.d.ts +27 -0
- package/dist/sandbox/image-build/resolution.js +137 -0
- package/dist/sandbox/image-build/tar.d.ts +41 -0
- package/dist/sandbox/image-build/tar.js +378 -0
- package/dist/sandbox/image-build/upload.d.ts +10 -0
- package/dist/sandbox/image-build/upload.js +143 -0
- package/dist/sandbox/index.d.ts +2 -1
- package/dist/sandbox/index.js +4 -1
- package/dist/sandbox/process-output.d.ts +36 -0
- package/dist/sandbox/process-output.js +117 -0
- package/dist/sandbox/process.d.ts +25 -1
- package/dist/sandbox/process.js +197 -29
- package/dist/sandbox/terminal.js +9 -5
- package/dist/sandbox/ws.d.ts +4 -1
- package/dist/sandbox/ws.js +33 -7
- package/dist/services/base.d.ts +2 -0
- package/dist/services/base.js +46 -30
- package/dist/services/normalize.d.ts +3 -0
- package/dist/services/normalize.js +21 -0
- package/dist/services/sandboxes.d.ts +40 -3
- package/dist/services/sandboxes.js +569 -53
- package/dist/services/volumes.js +29 -14
- package/dist/types/index.d.ts +2 -1
- package/dist/types/sandbox.d.ts +246 -30
- package/dist/types/volume.d.ts +7 -7
- package/package.json +24 -5
package/dist/services/base.js
CHANGED
|
@@ -5,34 +5,38 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
6
|
exports.BaseService = void 0;
|
|
7
7
|
const node_fetch_1 = __importDefault(require("node-fetch"));
|
|
8
|
-
const
|
|
9
|
-
const
|
|
10
|
-
const RETRYABLE_NETWORK_CODES = new Set([
|
|
11
|
-
"ECONNRESET",
|
|
12
|
-
"ECONNREFUSED",
|
|
13
|
-
"EAI_AGAIN",
|
|
14
|
-
"ETIMEDOUT",
|
|
15
|
-
"ESOCKETTIMEDOUT",
|
|
16
|
-
]);
|
|
8
|
+
const error_1 = require("../error");
|
|
9
|
+
const retry_1 = require("../retry");
|
|
17
10
|
const getRequestId = (response) => {
|
|
18
11
|
return response.headers.get("x-request-id") || response.headers.get("request-id") || undefined;
|
|
19
12
|
};
|
|
20
|
-
const isRetryableNetworkError = (error) => {
|
|
21
|
-
if (!(error instanceof Error)) {
|
|
22
|
-
return false;
|
|
23
|
-
}
|
|
24
|
-
const networkError = error;
|
|
25
|
-
return (networkError.name === "AbortError" ||
|
|
26
|
-
networkError.type === "request-timeout" ||
|
|
27
|
-
(networkError.code ? RETRYABLE_NETWORK_CODES.has(networkError.code) : false));
|
|
28
|
-
};
|
|
29
13
|
class BaseService {
|
|
30
14
|
constructor(apiKey, baseUrl, timeout = 30000) {
|
|
31
15
|
this.apiKey = apiKey;
|
|
32
16
|
this.baseUrl = baseUrl;
|
|
33
17
|
this.timeout = timeout;
|
|
34
18
|
}
|
|
19
|
+
/** Transient GET failures (429/502/503/504, network errors) retry up to three attempts. */
|
|
35
20
|
async request(path, init, params, fullUrl = false) {
|
|
21
|
+
const method = (init?.method ?? "GET").toUpperCase();
|
|
22
|
+
let failedAttempt = 1;
|
|
23
|
+
for (;;) {
|
|
24
|
+
try {
|
|
25
|
+
return await this.requestOnce(path, init, params, fullUrl);
|
|
26
|
+
}
|
|
27
|
+
catch (error) {
|
|
28
|
+
if (init?.signal?.aborted ||
|
|
29
|
+
!(error instanceof error_1.HyperbrowserError) ||
|
|
30
|
+
!(0, retry_1.shouldRetryGet)(method, error, failedAttempt)) {
|
|
31
|
+
throw error;
|
|
32
|
+
}
|
|
33
|
+
await (0, retry_1.retryDelay)((0, retry_1.getRetryDelayMs)(failedAttempt), init?.signal ?? undefined);
|
|
34
|
+
failedAttempt += 1;
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
async requestOnce(path, init, params, fullUrl = false) {
|
|
39
|
+
let response;
|
|
36
40
|
try {
|
|
37
41
|
const url = new URL(fullUrl ? path : `${this.baseUrl}/api${path}`);
|
|
38
42
|
if (params) {
|
|
@@ -52,7 +56,7 @@ class BaseService {
|
|
|
52
56
|
const headerKeys = Object.keys(init?.headers || {});
|
|
53
57
|
const contentTypeKey = headerKeys.find((key) => key.toLowerCase() === "content-type");
|
|
54
58
|
const requestTimeout = init?.timeout ?? this.timeout;
|
|
55
|
-
|
|
59
|
+
response = await (0, node_fetch_1.default)(url.toString(), {
|
|
56
60
|
...init,
|
|
57
61
|
timeout: requestTimeout,
|
|
58
62
|
headers: {
|
|
@@ -74,41 +78,53 @@ class BaseService {
|
|
|
74
78
|
errorMessage =
|
|
75
79
|
errorData.message || errorData.error || `HTTP error! status: ${response.status}`;
|
|
76
80
|
}
|
|
77
|
-
catch {
|
|
81
|
+
catch (error) {
|
|
82
|
+
if (init?.signal?.aborted)
|
|
83
|
+
throw error;
|
|
78
84
|
errorMessage = `HTTP error! status: ${response.status}`;
|
|
79
85
|
}
|
|
80
|
-
throw new
|
|
86
|
+
throw new error_1.HyperbrowserError(errorMessage, {
|
|
81
87
|
statusCode: response.status,
|
|
82
88
|
code: errorCode,
|
|
83
89
|
requestId: getRequestId(response),
|
|
84
|
-
retryable: RETRYABLE_STATUS_CODES.has(response.status),
|
|
90
|
+
retryable: retry_1.RETRYABLE_STATUS_CODES.has(response.status),
|
|
85
91
|
service: "control",
|
|
86
92
|
details: errorDetails,
|
|
93
|
+
method: init?.method ?? "GET",
|
|
94
|
+
path: (0, error_1.errorRequestPath)(path),
|
|
87
95
|
});
|
|
88
96
|
}
|
|
89
|
-
|
|
97
|
+
const text = await response.text();
|
|
98
|
+
if (!text)
|
|
90
99
|
return {};
|
|
91
|
-
}
|
|
92
100
|
try {
|
|
93
|
-
return
|
|
101
|
+
return JSON.parse(text);
|
|
94
102
|
}
|
|
95
|
-
catch {
|
|
96
|
-
throw new
|
|
103
|
+
catch (cause) {
|
|
104
|
+
throw new error_1.HyperbrowserError("Failed to parse JSON response", {
|
|
97
105
|
statusCode: response.status,
|
|
98
106
|
requestId: getRequestId(response),
|
|
99
107
|
retryable: false,
|
|
100
108
|
service: "control",
|
|
109
|
+
cause,
|
|
110
|
+
method: init?.method ?? "GET",
|
|
111
|
+
path: (0, error_1.errorRequestPath)(path),
|
|
101
112
|
});
|
|
102
113
|
}
|
|
103
114
|
}
|
|
104
115
|
catch (error) {
|
|
105
|
-
if (error instanceof
|
|
116
|
+
if (error instanceof error_1.HyperbrowserError) {
|
|
106
117
|
throw error;
|
|
107
118
|
}
|
|
108
|
-
throw new
|
|
109
|
-
|
|
119
|
+
throw new error_1.HyperbrowserError((0, error_1.networkErrorMessage)(error, "Unknown error occurred"), {
|
|
120
|
+
code: init?.signal?.aborted ? "request_aborted" : undefined,
|
|
121
|
+
retryable: !init?.signal?.aborted && (0, retry_1.isRetryableNetworkError)(error),
|
|
122
|
+
method: init?.method ?? "GET",
|
|
123
|
+
path: (0, error_1.errorRequestPath)(path),
|
|
110
124
|
service: "control",
|
|
111
125
|
cause: error,
|
|
126
|
+
statusCode: response?.status,
|
|
127
|
+
requestId: response ? getRequestId(response) : undefined,
|
|
112
128
|
});
|
|
113
129
|
}
|
|
114
130
|
}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.optionalInteger = exports.optionalNumber = void 0;
|
|
4
|
+
const error_1 = require("../error");
|
|
5
|
+
/** Nullable numeric wire values used by sandbox and volume endpoints. */
|
|
6
|
+
const optionalNumber = (value, integer = false) => {
|
|
7
|
+
if (value === undefined || value === null)
|
|
8
|
+
return value;
|
|
9
|
+
if (typeof value === "string" && value.trim() === "")
|
|
10
|
+
return null;
|
|
11
|
+
const parsed = typeof value === "string" ? Number(value) : value;
|
|
12
|
+
if (typeof parsed !== "number" ||
|
|
13
|
+
!Number.isFinite(parsed) ||
|
|
14
|
+
(integer && !Number.isSafeInteger(parsed))) {
|
|
15
|
+
throw new error_1.HyperbrowserError("Invalid numeric value in API response", { service: "control" });
|
|
16
|
+
}
|
|
17
|
+
return parsed;
|
|
18
|
+
};
|
|
19
|
+
exports.optionalNumber = optionalNumber;
|
|
20
|
+
const optionalInteger = (value) => (0, exports.optionalNumber)(value, true);
|
|
21
|
+
exports.optionalInteger = optionalInteger;
|
|
@@ -2,7 +2,7 @@ import { SandboxFilesApi } from "../sandbox/files";
|
|
|
2
2
|
import { SandboxProcessHandle, SandboxProcessesApi } from "../sandbox/process";
|
|
3
3
|
import { SandboxTerminalApi } from "../sandbox/terminal";
|
|
4
4
|
import { BasicResponse } from "../types/session";
|
|
5
|
-
import { CompleteSandboxImageBuildParams, CreateSandboxImageBuildParams, CreateSandboxParams, SandboxDetail, SandboxExposeParams, SandboxExposeResult, SandboxExecParams, SandboxExecOptions, SandboxImageBuild, SandboxImageBuildCreateResult, SandboxImageBuildListParams, SandboxImageBuildListResponse, SandboxImageListParams, SandboxImageListResponse, SandboxListParams, SandboxListResponse, SandboxMemorySnapshotParams, SandboxMemorySnapshotResult, SandboxNetworkPolicyPatch, SandboxNetworkUpdateResult, SandboxProcessResult, SandboxImageDeleteResult, SandboxSnapshotDeleteResult, SandboxSnapshotListParams, SandboxSnapshotListResponse, SandboxSnapshotSummary, SandboxUnexposeResult } from "../types/sandbox";
|
|
5
|
+
import { BuildSandboxImageFromDockerImageOptions, BuildSandboxImageFromDockerfileOptions, CompleteSandboxImageBuildParams, CreateSandboxImageBuildParams, CreateSandboxParams, StartSandboxFromSnapshotParams, SandboxRuntimeSession, SandboxRuntimeTarget, GetOrBuildSandboxImageOptions, ReuseSandboxDockerImageParams, SandboxDockerImageReuseResult, SandboxImageBuildResolution, SandboxImageBuildWaitOptions, SandboxImageSummary, SandboxDetail, SandboxExposeParams, SandboxExposeResult, SandboxExecParams, SandboxExecOptions, SandboxImageBuild, SandboxImageBuildCreateResult, SandboxImageBuildListParams, SandboxImageBuildListResponse, SandboxImageListParams, SandboxImageListResponse, SandboxListParams, SandboxListResponse, SandboxMemorySnapshotParams, SandboxMemorySnapshotResult, SandboxNetworkPolicyPatch, SandboxNetworkUpdateResult, SandboxProcessResult, SandboxImageDeleteResult, SandboxSnapshotDeleteResult, SandboxSnapshotListParams, SandboxSnapshotListResponse, SandboxSnapshotSummary, SandboxUnexposeResult } from "../types/sandbox";
|
|
6
6
|
import { BaseService } from "./base";
|
|
7
7
|
export declare class SandboxHandle {
|
|
8
8
|
private readonly service;
|
|
@@ -44,6 +44,9 @@ export declare class SandboxHandle {
|
|
|
44
44
|
private resolveRuntimeConnection;
|
|
45
45
|
private resolveRuntimeSocketConnectionInfo;
|
|
46
46
|
private isRuntimeSessionExpiring;
|
|
47
|
+
createRuntimeSession(options?: {
|
|
48
|
+
forceRefresh?: boolean;
|
|
49
|
+
}): Promise<SandboxRuntimeSession>;
|
|
47
50
|
private ensureRuntimeSession;
|
|
48
51
|
private applyRuntimeSession;
|
|
49
52
|
private clearRuntimeSession;
|
|
@@ -55,6 +58,8 @@ export declare class SandboxesService extends BaseService {
|
|
|
55
58
|
readonly runtimeProxyOverride?: string;
|
|
56
59
|
constructor(apiKey: string, baseUrl: string, timeout: number, runtimeProxyOverride?: string);
|
|
57
60
|
create(params: CreateSandboxParams): Promise<SandboxHandle>;
|
|
61
|
+
startFromSnapshot(params: StartSandboxFromSnapshotParams): Promise<SandboxHandle>;
|
|
62
|
+
getRuntimeSession(id: string): Promise<SandboxRuntimeSession>;
|
|
58
63
|
get(id: string): Promise<SandboxHandle>;
|
|
59
64
|
connect(id: string): Promise<SandboxHandle>;
|
|
60
65
|
list(params?: SandboxListParams): Promise<SandboxListResponse>;
|
|
@@ -65,14 +70,46 @@ export declare class SandboxesService extends BaseService {
|
|
|
65
70
|
getDetail(id: string): Promise<SandboxDetail>;
|
|
66
71
|
attach(detail: SandboxDetail): SandboxHandle;
|
|
67
72
|
createMemorySnapshot(id: string, params?: SandboxMemorySnapshotParams): Promise<SandboxMemorySnapshotResult>;
|
|
68
|
-
expose(id: string, params: SandboxExposeParams): Promise<SandboxExposeResult>;
|
|
73
|
+
expose(id: string, params: SandboxExposeParams, runtime?: SandboxRuntimeTarget): Promise<SandboxExposeResult>;
|
|
69
74
|
getSnapshot(snapshot: string): Promise<SandboxSnapshotSummary>;
|
|
70
75
|
deleteSnapshot(snapshot: string): Promise<SandboxSnapshotDeleteResult>;
|
|
71
76
|
createImageBuild(params: CreateSandboxImageBuildParams): Promise<SandboxImageBuildCreateResult>;
|
|
72
|
-
getImageBuild(buildId: string
|
|
77
|
+
getImageBuild(buildId: string, options?: {
|
|
78
|
+
signal?: AbortSignal;
|
|
79
|
+
}): Promise<SandboxImageBuild>;
|
|
73
80
|
listImageBuilds(params?: SandboxImageBuildListParams): Promise<SandboxImageBuildListResponse>;
|
|
74
81
|
completeImageBuild(buildId: string, params: CompleteSandboxImageBuildParams): Promise<SandboxImageBuild>;
|
|
75
82
|
cancelImageBuild(buildId: string): Promise<SandboxImageBuild>;
|
|
83
|
+
reuseDockerImage(params: ReuseSandboxDockerImageParams): Promise<SandboxDockerImageReuseResult>;
|
|
84
|
+
/** Find an exact ready team image, including revisions awaiting backup. */
|
|
85
|
+
findReadyImage(imageName: string): Promise<SandboxImageSummary | null>;
|
|
86
|
+
/** Poll an image build until it completes, rejecting on failure or timeout. */
|
|
87
|
+
waitForImageBuild(buildId: string, options?: SandboxImageBuildWaitOptions): Promise<SandboxImageBuild>;
|
|
88
|
+
/** Import a local Docker image as reusable layers, reusing exact cached imports. */
|
|
89
|
+
buildImageFromDockerImage(options: BuildSandboxImageFromDockerImageOptions): Promise<SandboxImageBuild>;
|
|
90
|
+
/**
|
|
91
|
+
* Build a Dockerfile into a sandbox image.
|
|
92
|
+
*
|
|
93
|
+
* Remote builds (default) upload only the effective build context and build
|
|
94
|
+
* on Hyperbrowser. `remote: false` builds with local Docker and imports the
|
|
95
|
+
* resulting image instead.
|
|
96
|
+
*/
|
|
97
|
+
buildImageFromDockerfile(options: BuildSandboxImageFromDockerfileOptions): Promise<SandboxImageBuild>;
|
|
98
|
+
/**
|
|
99
|
+
* Reuse, join, or build content-derived remote Dockerfile/image inputs.
|
|
100
|
+
*
|
|
101
|
+
* Supply exactly one of `contextPath` or `dockerImage`. Names include source
|
|
102
|
+
* contents, platform and image initialization overrides. `forceBuild` skips
|
|
103
|
+
* ready-image lookup, but joins matching active builds and retains builder
|
|
104
|
+
* layer/artifact caches. Canceling polling never cancels the backend build.
|
|
105
|
+
* `waitTimeout` applies to this caller's polling, independently of uploads.
|
|
106
|
+
* This composes existing APIs; lookup plus creation is not server-atomic.
|
|
107
|
+
*/
|
|
108
|
+
getOrBuildImage(options: GetOrBuildSandboxImageOptions): Promise<SandboxImageBuildResolution>;
|
|
109
|
+
private buildImageFromRemoteDockerfile;
|
|
110
|
+
/** Create a build, upload requested artifacts, complete it, and optionally wait. */
|
|
111
|
+
private submitImageBuild;
|
|
112
|
+
private completeImageBuildResilient;
|
|
76
113
|
updateNetwork(id: string, policy: SandboxNetworkPolicyPatch): Promise<SandboxNetworkUpdateResult>;
|
|
77
114
|
unexpose(id: string, port: number): Promise<SandboxUnexposeResult>;
|
|
78
115
|
private createDetail;
|