@alineo-labs/opensandbox 0.3.0 → 0.3.1
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/index.d.mts +17 -13
- package/dist/index.mjs +19 -2
- package/package.json +4 -4
package/dist/index.d.mts
CHANGED
|
@@ -12,7 +12,7 @@ interface ImageSpec {
|
|
|
12
12
|
uri: string;
|
|
13
13
|
auth?: ImageAuth;
|
|
14
14
|
}
|
|
15
|
-
declare enum SandboxState {
|
|
15
|
+
export declare enum SandboxState {
|
|
16
16
|
Pending = "Pending",
|
|
17
17
|
Running = "Running",
|
|
18
18
|
Pausing = "Pausing",
|
|
@@ -87,7 +87,7 @@ interface ListSandboxesOptions {
|
|
|
87
87
|
limit?: number;
|
|
88
88
|
offset?: number;
|
|
89
89
|
}
|
|
90
|
-
declare enum SnapshotState {
|
|
90
|
+
export declare enum SnapshotState {
|
|
91
91
|
Pending = "Pending",
|
|
92
92
|
Committing = "Committing",
|
|
93
93
|
Pushing = "Pushing",
|
|
@@ -120,7 +120,7 @@ interface DiagnosticEvent {
|
|
|
120
120
|
type: string;
|
|
121
121
|
message: string;
|
|
122
122
|
}
|
|
123
|
-
declare enum SSEEventType {
|
|
123
|
+
export declare enum SSEEventType {
|
|
124
124
|
Init = "init",
|
|
125
125
|
Status = "status",
|
|
126
126
|
Stdout = "stdout",
|
|
@@ -145,7 +145,7 @@ interface SSEEvent {
|
|
|
145
145
|
execution_time?: number;
|
|
146
146
|
timestamp: number;
|
|
147
147
|
}
|
|
148
|
-
declare enum CodeLanguage {
|
|
148
|
+
export declare enum CodeLanguage {
|
|
149
149
|
Python = "python",
|
|
150
150
|
JavaScript = "javascript",
|
|
151
151
|
TypeScript = "typescript",
|
|
@@ -241,11 +241,15 @@ type PtyServerMessage = {
|
|
|
241
241
|
};
|
|
242
242
|
//#endregion
|
|
243
243
|
//#region src/control.d.ts
|
|
244
|
-
declare class OpenSandboxError extends Error {
|
|
244
|
+
export declare class OpenSandboxError extends Error {
|
|
245
245
|
readonly status: number;
|
|
246
|
-
|
|
246
|
+
/** OpenSandbox's error code, e.g. `DOCKER::SANDBOX_NOT_FOUND`, when the response carried one. */
|
|
247
|
+
readonly code?: string | undefined;
|
|
248
|
+
constructor(message: string, status: number,
|
|
249
|
+
/** OpenSandbox's error code, e.g. `DOCKER::SANDBOX_NOT_FOUND`, when the response carried one. */
|
|
250
|
+
code?: string | undefined);
|
|
247
251
|
}
|
|
248
|
-
declare class ControlClient {
|
|
252
|
+
export declare class ControlClient {
|
|
249
253
|
private baseUrl;
|
|
250
254
|
private apiKey;
|
|
251
255
|
private signal?;
|
|
@@ -275,7 +279,7 @@ declare class ControlClient {
|
|
|
275
279
|
//#endregion
|
|
276
280
|
//#region src/egress.d.ts
|
|
277
281
|
/** Thrown for a non-2xx response from the egress sidecar's policy API. */
|
|
278
|
-
declare class EgressClientError extends Error {
|
|
282
|
+
export declare class EgressClientError extends Error {
|
|
279
283
|
readonly status: number;
|
|
280
284
|
constructor(message: string, status: number);
|
|
281
285
|
}
|
|
@@ -309,7 +313,7 @@ interface EgressPolicyStatus {
|
|
|
309
313
|
* `resume()`d sandbox's still-live changes back into its boot policy from the ledger. (A
|
|
310
314
|
* `fork()` does not carry them.)
|
|
311
315
|
*/
|
|
312
|
-
declare class EgressClient {
|
|
316
|
+
export declare class EgressClient {
|
|
313
317
|
private readonly control;
|
|
314
318
|
private readonly useServerProxy?;
|
|
315
319
|
private static readonly PORT;
|
|
@@ -329,10 +333,10 @@ declare class EgressClient {
|
|
|
329
333
|
* wildcard domain, a bare IPv4/IPv6 address, or a CIDR block. Whitespace-only, URL-shaped
|
|
330
334
|
* (`http://…`), space-containing, or otherwise clearly-malformed strings return `false`.
|
|
331
335
|
*/
|
|
332
|
-
declare function isValidEgressTarget(target: string): boolean;
|
|
336
|
+
export declare function isValidEgressTarget(target: string): boolean;
|
|
333
337
|
//#endregion
|
|
334
338
|
//#region src/exec.d.ts
|
|
335
|
-
declare class ExecClient {
|
|
339
|
+
export declare class ExecClient {
|
|
336
340
|
private baseUrl;
|
|
337
341
|
private accessToken;
|
|
338
342
|
private signal?;
|
|
@@ -402,7 +406,7 @@ type PtyExitListener = (exitCode: number) => void;
|
|
|
402
406
|
* callbacks, `write()`/`resize()`/`signal()` send input, `close()` tears
|
|
403
407
|
* down the socket.
|
|
404
408
|
*/
|
|
405
|
-
declare class PtyClient {
|
|
409
|
+
export declare class PtyClient {
|
|
406
410
|
private readonly baseUrl;
|
|
407
411
|
private readonly accessToken;
|
|
408
412
|
private ws;
|
|
@@ -424,4 +428,4 @@ declare class PtyClient {
|
|
|
424
428
|
close(): void;
|
|
425
429
|
}
|
|
426
430
|
//#endregion
|
|
427
|
-
export {
|
|
431
|
+
export type { CodeContext, CommandStatus, CreatePtyOptions, CreatePtyResponse, CreateSandboxOptions, CreateSessionRequest, CreateSessionResponse, CredentialProxyConfig, DiagnosticEvent, DiagnosticLog, EgressPolicyStatus, ExecuteCodeOptions, ExecuteCommandOptions, FileInfo, FileReplacement, ImageAuth, ImageSpec, ListSandboxesOptions, ListSnapshotsOptions, Metrics, NetworkPolicy, NetworkRule, PtyClientMessage, PtyExitListener, PtyOutputListener, PtyServerMessage, Resources, RunInSessionRequest, SSEEvent, Sandbox, SandboxEndpoint, SandboxStatus, Snapshot };
|
package/dist/index.mjs
CHANGED
|
@@ -9,12 +9,29 @@ function flattenSnapshot(raw) {
|
|
|
9
9
|
}
|
|
10
10
|
var OpenSandboxError = class extends Error {
|
|
11
11
|
status;
|
|
12
|
-
|
|
12
|
+
code;
|
|
13
|
+
constructor(message, status, code) {
|
|
13
14
|
super(message);
|
|
14
15
|
this.status = status;
|
|
16
|
+
this.code = code;
|
|
15
17
|
this.name = "OpenSandboxError";
|
|
16
18
|
}
|
|
17
19
|
};
|
|
20
|
+
/**
|
|
21
|
+
* OpenSandbox answers an error with a JSON body, `{"code": "...", "message": "..."}`. Put the
|
|
22
|
+
* sentence in `message` (with the code after it), keep the code on `.code`, and fall back to the
|
|
23
|
+
* raw text when the body isn't that shape.
|
|
24
|
+
*/
|
|
25
|
+
function errorFromBody(text, status) {
|
|
26
|
+
try {
|
|
27
|
+
const body = JSON.parse(text);
|
|
28
|
+
if (typeof body?.message === "string" && body.message) {
|
|
29
|
+
const code = typeof body.code === "string" && body.code ? body.code : void 0;
|
|
30
|
+
return new OpenSandboxError(code ? `${body.message} (${code})` : body.message, status, code);
|
|
31
|
+
}
|
|
32
|
+
} catch {}
|
|
33
|
+
return new OpenSandboxError(text || "OpenSandbox API error", status);
|
|
34
|
+
}
|
|
18
35
|
var ControlClient = class ControlClient {
|
|
19
36
|
baseUrl;
|
|
20
37
|
apiKey;
|
|
@@ -42,7 +59,7 @@ var ControlClient = class ControlClient {
|
|
|
42
59
|
...body !== void 0 ? { body: JSON.stringify(body) } : {},
|
|
43
60
|
signal: this.signal
|
|
44
61
|
});
|
|
45
|
-
if (!res.ok) throw
|
|
62
|
+
if (!res.ok) throw errorFromBody(await res.text().catch(() => ""), res.status);
|
|
46
63
|
if (res.status === 204) return void 0;
|
|
47
64
|
return res.json();
|
|
48
65
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@alineo-labs/opensandbox",
|
|
3
|
-
"version": "0.3.
|
|
3
|
+
"version": "0.3.1",
|
|
4
4
|
"license": "Apache-2.0",
|
|
5
5
|
"repository": {
|
|
6
6
|
"type": "git",
|
|
@@ -30,9 +30,9 @@
|
|
|
30
30
|
"test:watch": "vitest"
|
|
31
31
|
},
|
|
32
32
|
"devDependencies": {
|
|
33
|
-
"bun-types": "1.
|
|
34
|
-
"tsdown": "0.
|
|
33
|
+
"bun-types": "1.4.2",
|
|
34
|
+
"tsdown": "0.23.0",
|
|
35
35
|
"typescript": "6.0.3",
|
|
36
|
-
"vitest": "
|
|
36
|
+
"vitest": "5.0.0"
|
|
37
37
|
}
|
|
38
38
|
}
|