@insforge/instabox-sdk 0.7.1 → 0.8.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 +31 -9
- package/dist/index.cjs +83 -16
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +49 -1
- package/dist/index.d.ts +49 -1
- package/dist/index.js +83 -16
- package/dist/index.js.map +1 -1
- package/package.json +2 -2
- package/skills/instabox/SKILL.md +10 -8
package/dist/index.d.cts
CHANGED
|
@@ -851,6 +851,52 @@ declare class Desktop {
|
|
|
851
851
|
private run;
|
|
852
852
|
}
|
|
853
853
|
|
|
854
|
+
/** `public`: anyone with the URL reaches it. `private`: only requests that carry the port's token. */
|
|
855
|
+
type PortAccess = 'public' | 'private';
|
|
856
|
+
/** A sandbox port published at a URL. */
|
|
857
|
+
interface PublicPort {
|
|
858
|
+
port: number;
|
|
859
|
+
/** Shown on the dashboard: `Port <n>` unless one was given. */
|
|
860
|
+
name: string;
|
|
861
|
+
/** `http`, or `tcp` for a raw TCP port published with `instabox port publish --tcp`. */
|
|
862
|
+
protocol: 'http' | 'tcp';
|
|
863
|
+
/** `https://<port>-<id>.<domain>` (`tls://<host>:<port>` for tcp), on the server's own domain. */
|
|
864
|
+
url: string;
|
|
865
|
+
access: PortAccess;
|
|
866
|
+
/** A private port's token (`ibp_...`), returned only by the publish that created or rotated it. */
|
|
867
|
+
token?: string;
|
|
868
|
+
/** `url` with the token as its `_token` query parameter: the link to share. Set with `token`. */
|
|
869
|
+
tokenUrl?: string;
|
|
870
|
+
createdAt: Date;
|
|
871
|
+
}
|
|
872
|
+
interface PublishPortOpts {
|
|
873
|
+
/** Name shown on the dashboard. Omitted: `Port <n>` for a new port, the current name otherwise. */
|
|
874
|
+
name?: string;
|
|
875
|
+
/** Omitted: public for a new port, the current access otherwise. */
|
|
876
|
+
access?: PortAccess;
|
|
877
|
+
/** Give a private port a new token: the old one stops working and its connections close. */
|
|
878
|
+
rotateToken?: boolean;
|
|
879
|
+
}
|
|
880
|
+
/** URLs for servers listening in the sandbox, as `instabox port publish` makes them. */
|
|
881
|
+
declare class Ports {
|
|
882
|
+
private readonly http;
|
|
883
|
+
private readonly sandboxId;
|
|
884
|
+
/** @internal */
|
|
885
|
+
constructor(http: HttpClient, sandboxId: string);
|
|
886
|
+
/**
|
|
887
|
+
* Publishes `port` (1024-65535) until `unpublish()`; publishing it again keeps its URL. The URL answers
|
|
888
|
+
* while the sandbox runs, WebSockets included. Requires machines:write.
|
|
889
|
+
*/
|
|
890
|
+
publish(port: number, opts?: PublishPortOpts): Promise<PublicPort>;
|
|
891
|
+
/** The sandbox's published ports. Tokens are not included. Requires machines:read. */
|
|
892
|
+
list(): Promise<PublicPort[]>;
|
|
893
|
+
/**
|
|
894
|
+
* Removes the port's URL and closes its open connections. Returns false if the port was not published.
|
|
895
|
+
* Requires machines:write.
|
|
896
|
+
*/
|
|
897
|
+
unpublish(port: number): Promise<boolean>;
|
|
898
|
+
}
|
|
899
|
+
|
|
854
900
|
declare const DEFAULT_TEMPLATE = "agent-browser";
|
|
855
901
|
/** The default when a server does not offer `DEFAULT_TEMPLATE` (an older or self-hosted one). */
|
|
856
902
|
declare const FALLBACK_TEMPLATE = "universal";
|
|
@@ -993,6 +1039,8 @@ declare class Sandbox {
|
|
|
993
1039
|
readonly files: Files;
|
|
994
1040
|
/** See and control the sandbox's graphical desktop (screenshots, mouse, keyboard, a link to watch it). */
|
|
995
1041
|
readonly desktop: Desktop;
|
|
1042
|
+
/** Publish a port at an HTTPS URL, list published ports, unpublish them. */
|
|
1043
|
+
readonly ports: Ports;
|
|
996
1044
|
private machine;
|
|
997
1045
|
private constructor();
|
|
998
1046
|
/**
|
|
@@ -1101,4 +1149,4 @@ declare class Sandbox {
|
|
|
1101
1149
|
private mutate;
|
|
1102
1150
|
}
|
|
1103
1151
|
|
|
1104
|
-
export { type ApiError, CommandExitError, type CommandHandle, type CommandOptions, type CommandResult, type CommandWaitOptions, Commands, type Connection, type ConnectionOptions, type CreateSnapshotOpts, DEFAULT_API_URL, DEFAULT_TEMPLATE, DESKTOP_DISPLAY, Desktop, type DesktopStatus, type DesktopStream, type DownloadInfo, type DownloadOptions, type EntryInfo, type ExecResponse, FALLBACK_TEMPLATE, type FileStream, Files, type HostTrust, InstaboxAuthError, InstaboxError, type InstaboxErrorInit, InstaboxNotUtf8Error, InstaboxQuotaError, InstaboxTimeoutError, LIMIT_CODES, MAX_FILE_BYTES, MAX_STDIN_BYTES, MAX_UPLOAD_BYTES, type Machine, type MachineList, type MachineMetric, type MachineMetrics, type MachineSpec, type MachineState, type MachineUsage, type MachineVault, type MachineVaultItem, type MouseButton, type Operation, type ReadStreamOptions, Sandbox, type SandboxConnectOpts, type SandboxInfo, type SandboxListOpts, type SandboxMetrics, type SandboxMetricsOpts, type SandboxOpts, type SandboxUsage, type SandboxUsageOpts, type ScrollDirection, type Snapshot, type SnapshotList, type SshCredentials, type Template, type TemplateRef, type UploadInfo, type UploadOptions, type Usage, type UsageCost, type UsageLimits, type UsageMachineStorage, type UsageStorage, type VaultApplied, type VaultFile, type VaultKept, type WriteData, type WriteInfo, type WriteOptions, isLimitCode };
|
|
1152
|
+
export { type ApiError, CommandExitError, type CommandHandle, type CommandOptions, type CommandResult, type CommandWaitOptions, Commands, type Connection, type ConnectionOptions, type CreateSnapshotOpts, DEFAULT_API_URL, DEFAULT_TEMPLATE, DESKTOP_DISPLAY, Desktop, type DesktopStatus, type DesktopStream, type DownloadInfo, type DownloadOptions, type EntryInfo, type ExecResponse, FALLBACK_TEMPLATE, type FileStream, Files, type HostTrust, InstaboxAuthError, InstaboxError, type InstaboxErrorInit, InstaboxNotUtf8Error, InstaboxQuotaError, InstaboxTimeoutError, LIMIT_CODES, MAX_FILE_BYTES, MAX_STDIN_BYTES, MAX_UPLOAD_BYTES, type Machine, type MachineList, type MachineMetric, type MachineMetrics, type MachineSpec, type MachineState, type MachineUsage, type MachineVault, type MachineVaultItem, type MouseButton, type Operation, type PortAccess, Ports, type PublicPort, type PublishPortOpts, type ReadStreamOptions, Sandbox, type SandboxConnectOpts, type SandboxInfo, type SandboxListOpts, type SandboxMetrics, type SandboxMetricsOpts, type SandboxOpts, type SandboxUsage, type SandboxUsageOpts, type ScrollDirection, type Snapshot, type SnapshotList, type SshCredentials, type Template, type TemplateRef, type UploadInfo, type UploadOptions, type Usage, type UsageCost, type UsageLimits, type UsageMachineStorage, type UsageStorage, type VaultApplied, type VaultFile, type VaultKept, type WriteData, type WriteInfo, type WriteOptions, isLimitCode };
|
package/dist/index.d.ts
CHANGED
|
@@ -851,6 +851,52 @@ declare class Desktop {
|
|
|
851
851
|
private run;
|
|
852
852
|
}
|
|
853
853
|
|
|
854
|
+
/** `public`: anyone with the URL reaches it. `private`: only requests that carry the port's token. */
|
|
855
|
+
type PortAccess = 'public' | 'private';
|
|
856
|
+
/** A sandbox port published at a URL. */
|
|
857
|
+
interface PublicPort {
|
|
858
|
+
port: number;
|
|
859
|
+
/** Shown on the dashboard: `Port <n>` unless one was given. */
|
|
860
|
+
name: string;
|
|
861
|
+
/** `http`, or `tcp` for a raw TCP port published with `instabox port publish --tcp`. */
|
|
862
|
+
protocol: 'http' | 'tcp';
|
|
863
|
+
/** `https://<port>-<id>.<domain>` (`tls://<host>:<port>` for tcp), on the server's own domain. */
|
|
864
|
+
url: string;
|
|
865
|
+
access: PortAccess;
|
|
866
|
+
/** A private port's token (`ibp_...`), returned only by the publish that created or rotated it. */
|
|
867
|
+
token?: string;
|
|
868
|
+
/** `url` with the token as its `_token` query parameter: the link to share. Set with `token`. */
|
|
869
|
+
tokenUrl?: string;
|
|
870
|
+
createdAt: Date;
|
|
871
|
+
}
|
|
872
|
+
interface PublishPortOpts {
|
|
873
|
+
/** Name shown on the dashboard. Omitted: `Port <n>` for a new port, the current name otherwise. */
|
|
874
|
+
name?: string;
|
|
875
|
+
/** Omitted: public for a new port, the current access otherwise. */
|
|
876
|
+
access?: PortAccess;
|
|
877
|
+
/** Give a private port a new token: the old one stops working and its connections close. */
|
|
878
|
+
rotateToken?: boolean;
|
|
879
|
+
}
|
|
880
|
+
/** URLs for servers listening in the sandbox, as `instabox port publish` makes them. */
|
|
881
|
+
declare class Ports {
|
|
882
|
+
private readonly http;
|
|
883
|
+
private readonly sandboxId;
|
|
884
|
+
/** @internal */
|
|
885
|
+
constructor(http: HttpClient, sandboxId: string);
|
|
886
|
+
/**
|
|
887
|
+
* Publishes `port` (1024-65535) until `unpublish()`; publishing it again keeps its URL. The URL answers
|
|
888
|
+
* while the sandbox runs, WebSockets included. Requires machines:write.
|
|
889
|
+
*/
|
|
890
|
+
publish(port: number, opts?: PublishPortOpts): Promise<PublicPort>;
|
|
891
|
+
/** The sandbox's published ports. Tokens are not included. Requires machines:read. */
|
|
892
|
+
list(): Promise<PublicPort[]>;
|
|
893
|
+
/**
|
|
894
|
+
* Removes the port's URL and closes its open connections. Returns false if the port was not published.
|
|
895
|
+
* Requires machines:write.
|
|
896
|
+
*/
|
|
897
|
+
unpublish(port: number): Promise<boolean>;
|
|
898
|
+
}
|
|
899
|
+
|
|
854
900
|
declare const DEFAULT_TEMPLATE = "agent-browser";
|
|
855
901
|
/** The default when a server does not offer `DEFAULT_TEMPLATE` (an older or self-hosted one). */
|
|
856
902
|
declare const FALLBACK_TEMPLATE = "universal";
|
|
@@ -993,6 +1039,8 @@ declare class Sandbox {
|
|
|
993
1039
|
readonly files: Files;
|
|
994
1040
|
/** See and control the sandbox's graphical desktop (screenshots, mouse, keyboard, a link to watch it). */
|
|
995
1041
|
readonly desktop: Desktop;
|
|
1042
|
+
/** Publish a port at an HTTPS URL, list published ports, unpublish them. */
|
|
1043
|
+
readonly ports: Ports;
|
|
996
1044
|
private machine;
|
|
997
1045
|
private constructor();
|
|
998
1046
|
/**
|
|
@@ -1101,4 +1149,4 @@ declare class Sandbox {
|
|
|
1101
1149
|
private mutate;
|
|
1102
1150
|
}
|
|
1103
1151
|
|
|
1104
|
-
export { type ApiError, CommandExitError, type CommandHandle, type CommandOptions, type CommandResult, type CommandWaitOptions, Commands, type Connection, type ConnectionOptions, type CreateSnapshotOpts, DEFAULT_API_URL, DEFAULT_TEMPLATE, DESKTOP_DISPLAY, Desktop, type DesktopStatus, type DesktopStream, type DownloadInfo, type DownloadOptions, type EntryInfo, type ExecResponse, FALLBACK_TEMPLATE, type FileStream, Files, type HostTrust, InstaboxAuthError, InstaboxError, type InstaboxErrorInit, InstaboxNotUtf8Error, InstaboxQuotaError, InstaboxTimeoutError, LIMIT_CODES, MAX_FILE_BYTES, MAX_STDIN_BYTES, MAX_UPLOAD_BYTES, type Machine, type MachineList, type MachineMetric, type MachineMetrics, type MachineSpec, type MachineState, type MachineUsage, type MachineVault, type MachineVaultItem, type MouseButton, type Operation, type ReadStreamOptions, Sandbox, type SandboxConnectOpts, type SandboxInfo, type SandboxListOpts, type SandboxMetrics, type SandboxMetricsOpts, type SandboxOpts, type SandboxUsage, type SandboxUsageOpts, type ScrollDirection, type Snapshot, type SnapshotList, type SshCredentials, type Template, type TemplateRef, type UploadInfo, type UploadOptions, type Usage, type UsageCost, type UsageLimits, type UsageMachineStorage, type UsageStorage, type VaultApplied, type VaultFile, type VaultKept, type WriteData, type WriteInfo, type WriteOptions, isLimitCode };
|
|
1152
|
+
export { type ApiError, CommandExitError, type CommandHandle, type CommandOptions, type CommandResult, type CommandWaitOptions, Commands, type Connection, type ConnectionOptions, type CreateSnapshotOpts, DEFAULT_API_URL, DEFAULT_TEMPLATE, DESKTOP_DISPLAY, Desktop, type DesktopStatus, type DesktopStream, type DownloadInfo, type DownloadOptions, type EntryInfo, type ExecResponse, FALLBACK_TEMPLATE, type FileStream, Files, type HostTrust, InstaboxAuthError, InstaboxError, type InstaboxErrorInit, InstaboxNotUtf8Error, InstaboxQuotaError, InstaboxTimeoutError, LIMIT_CODES, MAX_FILE_BYTES, MAX_STDIN_BYTES, MAX_UPLOAD_BYTES, type Machine, type MachineList, type MachineMetric, type MachineMetrics, type MachineSpec, type MachineState, type MachineUsage, type MachineVault, type MachineVaultItem, type MouseButton, type Operation, type PortAccess, Ports, type PublicPort, type PublishPortOpts, type ReadStreamOptions, Sandbox, type SandboxConnectOpts, type SandboxInfo, type SandboxListOpts, type SandboxMetrics, type SandboxMetricsOpts, type SandboxOpts, type SandboxUsage, type SandboxUsageOpts, type ScrollDirection, type Snapshot, type SnapshotList, type SshCredentials, type Template, type TemplateRef, type UploadInfo, type UploadOptions, type Usage, type UsageCost, type UsageLimits, type UsageMachineStorage, type UsageStorage, type VaultApplied, type VaultFile, type VaultKept, type WriteData, type WriteInfo, type WriteOptions, isLimitCode };
|
package/dist/index.js
CHANGED
|
@@ -2441,6 +2441,69 @@ var HttpClient = class {
|
|
|
2441
2441
|
}
|
|
2442
2442
|
};
|
|
2443
2443
|
|
|
2444
|
+
// src/ports.ts
|
|
2445
|
+
var enc3 = encodeURIComponent;
|
|
2446
|
+
function checkPort(port) {
|
|
2447
|
+
if (!Number.isInteger(port)) {
|
|
2448
|
+
throw new InstaboxError(`port must be a whole number; got ${port}`, { code: "bad_request" });
|
|
2449
|
+
}
|
|
2450
|
+
return port;
|
|
2451
|
+
}
|
|
2452
|
+
function fromServer(p) {
|
|
2453
|
+
const out = {
|
|
2454
|
+
port: p.port,
|
|
2455
|
+
name: p.name,
|
|
2456
|
+
protocol: p.protocol,
|
|
2457
|
+
url: p.url,
|
|
2458
|
+
access: p.access,
|
|
2459
|
+
createdAt: new Date(p.createdAt)
|
|
2460
|
+
};
|
|
2461
|
+
if (p.token) {
|
|
2462
|
+
out.token = p.token;
|
|
2463
|
+
out.tokenUrl = p.tokenUrl;
|
|
2464
|
+
}
|
|
2465
|
+
return out;
|
|
2466
|
+
}
|
|
2467
|
+
var Ports = class {
|
|
2468
|
+
/** @internal */
|
|
2469
|
+
constructor(http, sandboxId) {
|
|
2470
|
+
this.http = http;
|
|
2471
|
+
this.sandboxId = sandboxId;
|
|
2472
|
+
}
|
|
2473
|
+
http;
|
|
2474
|
+
sandboxId;
|
|
2475
|
+
/**
|
|
2476
|
+
* Publishes `port` (1024-65535) until `unpublish()`; publishing it again keeps its URL. The URL answers
|
|
2477
|
+
* while the sandbox runs, WebSockets included. Requires machines:write.
|
|
2478
|
+
*/
|
|
2479
|
+
async publish(port, opts = {}) {
|
|
2480
|
+
const body = { port: checkPort(port) };
|
|
2481
|
+
if (opts.name !== void 0) body.name = opts.name;
|
|
2482
|
+
if (opts.access !== void 0) body.access = opts.access;
|
|
2483
|
+
if (opts.rotateToken) body.rotateToken = true;
|
|
2484
|
+
const r = await this.http.request("POST", `/v1/machines/${enc3(this.sandboxId)}/ports`, { body });
|
|
2485
|
+
return fromServer(r);
|
|
2486
|
+
}
|
|
2487
|
+
/** The sandbox's published ports. Tokens are not included. Requires machines:read. */
|
|
2488
|
+
async list() {
|
|
2489
|
+
const r = await this.http.request("GET", `/v1/machines/${enc3(this.sandboxId)}/ports`);
|
|
2490
|
+
return r.ports.map(fromServer);
|
|
2491
|
+
}
|
|
2492
|
+
/**
|
|
2493
|
+
* Removes the port's URL and closes its open connections. Returns false if the port was not published.
|
|
2494
|
+
* Requires machines:write.
|
|
2495
|
+
*/
|
|
2496
|
+
async unpublish(port) {
|
|
2497
|
+
try {
|
|
2498
|
+
await this.http.request("DELETE", `/v1/machines/${enc3(this.sandboxId)}/ports/${checkPort(port)}`);
|
|
2499
|
+
return true;
|
|
2500
|
+
} catch (err) {
|
|
2501
|
+
if (err instanceof InstaboxError && err.status === 404 && err.code === "not_found") return false;
|
|
2502
|
+
throw err;
|
|
2503
|
+
}
|
|
2504
|
+
}
|
|
2505
|
+
};
|
|
2506
|
+
|
|
2444
2507
|
// src/sandbox.ts
|
|
2445
2508
|
var DEFAULT_TEMPLATE = "agent-browser";
|
|
2446
2509
|
var FALLBACK_TEMPLATE = "universal";
|
|
@@ -2486,7 +2549,7 @@ function toSeconds(ms, field) {
|
|
|
2486
2549
|
return s;
|
|
2487
2550
|
}
|
|
2488
2551
|
var METADATA_KEY = /^[A-Za-z0-9_.-]{1,64}$/;
|
|
2489
|
-
var
|
|
2552
|
+
var enc4 = encodeURIComponent;
|
|
2490
2553
|
var Sandbox = class _Sandbox {
|
|
2491
2554
|
constructor(http, machine, opts = {}) {
|
|
2492
2555
|
this.http = http;
|
|
@@ -2496,6 +2559,7 @@ var Sandbox = class _Sandbox {
|
|
|
2496
2559
|
this.files = new Files(this.commands, http, machine.id);
|
|
2497
2560
|
this.commands.stageStdin = (bytes, signal) => this.files.stageStdin(bytes, signal);
|
|
2498
2561
|
this.desktop = new Desktop(http, machine.id, this.commands, this.files);
|
|
2562
|
+
this.ports = new Ports(http, machine.id);
|
|
2499
2563
|
}
|
|
2500
2564
|
http;
|
|
2501
2565
|
/** The machine ID (`m_...`). */
|
|
@@ -2506,6 +2570,8 @@ var Sandbox = class _Sandbox {
|
|
|
2506
2570
|
files;
|
|
2507
2571
|
/** See and control the sandbox's graphical desktop (screenshots, mouse, keyboard, a link to watch it). */
|
|
2508
2572
|
desktop;
|
|
2573
|
+
/** Publish a port at an HTTPS URL, list published ports, unpublish them. */
|
|
2574
|
+
ports;
|
|
2509
2575
|
machine;
|
|
2510
2576
|
static async create(a, b) {
|
|
2511
2577
|
const opts = (typeof a === "string" ? b : a) ?? {};
|
|
@@ -2585,12 +2651,12 @@ var Sandbox = class _Sandbox {
|
|
|
2585
2651
|
}
|
|
2586
2652
|
/** Fetches a snapshot by ID. Requires images:read. */
|
|
2587
2653
|
static async getSnapshot(snapshotId, opts = {}) {
|
|
2588
|
-
return new HttpClient(opts).request("GET", `/v1/snapshots/${
|
|
2654
|
+
return new HttpClient(opts).request("GET", `/v1/snapshots/${enc4(snapshotId)}`);
|
|
2589
2655
|
}
|
|
2590
2656
|
/** Deletes a snapshot. Returns false if absent. Requires images:delete. */
|
|
2591
2657
|
static async deleteSnapshot(snapshotId, opts = {}) {
|
|
2592
2658
|
try {
|
|
2593
|
-
await new HttpClient(opts).request("DELETE", `/v1/snapshots/${
|
|
2659
|
+
await new HttpClient(opts).request("DELETE", `/v1/snapshots/${enc4(snapshotId)}`);
|
|
2594
2660
|
return true;
|
|
2595
2661
|
} catch (err) {
|
|
2596
2662
|
if (err instanceof InstaboxError && err.status === 404 && err.code === "not_found") return false;
|
|
@@ -2605,7 +2671,7 @@ var Sandbox = class _Sandbox {
|
|
|
2605
2671
|
async createSnapshot(opts) {
|
|
2606
2672
|
await this.settle();
|
|
2607
2673
|
await this.untilSynced();
|
|
2608
|
-
return this.http.request("POST", `/v1/machines/${
|
|
2674
|
+
return this.http.request("POST", `/v1/machines/${enc4(this.sandboxId)}/snapshots`, { body: opts });
|
|
2609
2675
|
}
|
|
2610
2676
|
/** This sandbox's recent CPU and memory samples; see `Sandbox.getMetrics`. */
|
|
2611
2677
|
async getMetrics(opts = {}) {
|
|
@@ -2625,7 +2691,7 @@ var Sandbox = class _Sandbox {
|
|
|
2625
2691
|
* pause off. The setting stays across pause and resume.
|
|
2626
2692
|
*/
|
|
2627
2693
|
async setAutoSuspend(idleMs) {
|
|
2628
|
-
this.machine = await this.http.request("PATCH", `/v1/machines/${
|
|
2694
|
+
this.machine = await this.http.request("PATCH", `/v1/machines/${enc4(this.sandboxId)}`, {
|
|
2629
2695
|
body: { autoSuspendAfterSeconds: toIdleSeconds(idleMs) }
|
|
2630
2696
|
});
|
|
2631
2697
|
}
|
|
@@ -2639,7 +2705,7 @@ var Sandbox = class _Sandbox {
|
|
|
2639
2705
|
}
|
|
2640
2706
|
/** Replaces the sandbox's metadata (`{}` clears it). */
|
|
2641
2707
|
async setMetadata(metadata) {
|
|
2642
|
-
this.machine = await this.http.request("PATCH", `/v1/machines/${
|
|
2708
|
+
this.machine = await this.http.request("PATCH", `/v1/machines/${enc4(this.sandboxId)}`, {
|
|
2643
2709
|
body: { metadata }
|
|
2644
2710
|
});
|
|
2645
2711
|
}
|
|
@@ -2649,21 +2715,21 @@ var Sandbox = class _Sandbox {
|
|
|
2649
2715
|
* Throws `not_found` on a server without the Vault.
|
|
2650
2716
|
*/
|
|
2651
2717
|
async vault() {
|
|
2652
|
-
return this.http.request("GET", `/v1/machines/${
|
|
2718
|
+
return this.http.request("GET", `/v1/machines/${enc4(this.sandboxId)}/vault`);
|
|
2653
2719
|
}
|
|
2654
2720
|
/**
|
|
2655
2721
|
* Writes the account's current Vault items into the running sandbox now, the same write as after a boot,
|
|
2656
2722
|
* and returns its record (`error` set when the guest refused it). Requires machines:write.
|
|
2657
2723
|
*/
|
|
2658
2724
|
async pushVault() {
|
|
2659
|
-
return this.http.request("POST", `/v1/machines/${
|
|
2725
|
+
return this.http.request("POST", `/v1/machines/${enc4(this.sandboxId)}/vault`);
|
|
2660
2726
|
}
|
|
2661
2727
|
/**
|
|
2662
2728
|
* Turns the Vault off for this sandbox, for good, in any state: its next boot, resume or push removes
|
|
2663
2729
|
* what the Vault wrote and nothing is written again. Requires machines:write.
|
|
2664
2730
|
*/
|
|
2665
2731
|
async disableVault() {
|
|
2666
|
-
this.machine = await this.http.request("PATCH", `/v1/machines/${
|
|
2732
|
+
this.machine = await this.http.request("PATCH", `/v1/machines/${enc4(this.sandboxId)}`, {
|
|
2667
2733
|
body: { vault: false }
|
|
2668
2734
|
});
|
|
2669
2735
|
}
|
|
@@ -2710,7 +2776,7 @@ var Sandbox = class _Sandbox {
|
|
|
2710
2776
|
}
|
|
2711
2777
|
body.ttlSeconds = opts.ttlSeconds;
|
|
2712
2778
|
}
|
|
2713
|
-
const c = await this.http.request("POST", `/v1/machines/${
|
|
2779
|
+
const c = await this.http.request("POST", `/v1/machines/${enc4(this.sandboxId)}/connections`, { body });
|
|
2714
2780
|
return {
|
|
2715
2781
|
host: c.host,
|
|
2716
2782
|
port: c.port,
|
|
@@ -2729,7 +2795,7 @@ var Sandbox = class _Sandbox {
|
|
|
2729
2795
|
async settle(refresh = true) {
|
|
2730
2796
|
if (refresh) this.machine = await getMachine(this.http, this.sandboxId);
|
|
2731
2797
|
if (this.machine.operationId) {
|
|
2732
|
-
const op = await this.http.request("GET", `/v1/operations/${
|
|
2798
|
+
const op = await this.http.request("GET", `/v1/operations/${enc4(this.machine.operationId)}`);
|
|
2733
2799
|
await this.http.waitForOperation(op).catch(() => {
|
|
2734
2800
|
});
|
|
2735
2801
|
this.machine = await getMachine(this.http, this.sandboxId);
|
|
@@ -2757,29 +2823,29 @@ var Sandbox = class _Sandbox {
|
|
|
2757
2823
|
}
|
|
2758
2824
|
}
|
|
2759
2825
|
async mutate(method, action) {
|
|
2760
|
-
const op = await this.http.request(method, `/v1/machines/${
|
|
2826
|
+
const op = await this.http.request(method, `/v1/machines/${enc4(this.sandboxId)}/${action}`);
|
|
2761
2827
|
await this.http.waitForOperation(op);
|
|
2762
2828
|
this.machine = await getMachine(this.http, this.sandboxId);
|
|
2763
2829
|
}
|
|
2764
2830
|
};
|
|
2765
2831
|
async function getMachine(http, id) {
|
|
2766
|
-
return http.request("GET", `/v1/machines/${
|
|
2832
|
+
return http.request("GET", `/v1/machines/${enc4(id)}`);
|
|
2767
2833
|
}
|
|
2768
2834
|
async function getMetrics(http, id, opts) {
|
|
2769
|
-
const out = await http.request("GET", `/v1/machines/${
|
|
2835
|
+
const out = await http.request("GET", `/v1/machines/${enc4(id)}/metrics`, {
|
|
2770
2836
|
query: { since: opts.since?.toISOString() }
|
|
2771
2837
|
});
|
|
2772
2838
|
return out.metrics.map((s) => ({ ...s, timestamp: new Date(s.timestamp) }));
|
|
2773
2839
|
}
|
|
2774
2840
|
async function getUsage(http, id, opts) {
|
|
2775
|
-
const u = await http.request("GET", `/v1/machines/${
|
|
2841
|
+
const u = await http.request("GET", `/v1/machines/${enc4(id)}/usage`, {
|
|
2776
2842
|
query: { from: opts.from?.toISOString(), to: opts.to?.toISOString() }
|
|
2777
2843
|
});
|
|
2778
2844
|
return { ...u, from: new Date(u.from), to: new Date(u.to) };
|
|
2779
2845
|
}
|
|
2780
2846
|
async function killMachine(http, id) {
|
|
2781
2847
|
try {
|
|
2782
|
-
const op = await http.request("DELETE", `/v1/machines/${
|
|
2848
|
+
const op = await http.request("DELETE", `/v1/machines/${enc4(id)}`, {
|
|
2783
2849
|
headers: { "X-Confirm-Delete": id }
|
|
2784
2850
|
});
|
|
2785
2851
|
await http.waitForOperation(op);
|
|
@@ -2843,6 +2909,7 @@ export {
|
|
|
2843
2909
|
MAX_FILE_BYTES,
|
|
2844
2910
|
MAX_STDIN_BYTES,
|
|
2845
2911
|
MAX_UPLOAD_BYTES,
|
|
2912
|
+
Ports,
|
|
2846
2913
|
Sandbox,
|
|
2847
2914
|
isLimitCode
|
|
2848
2915
|
};
|