@insforge/instabox-sdk 0.8.0 → 0.9.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/dist/index.d.cts CHANGED
@@ -174,7 +174,7 @@ interface MachineList {
174
174
  interface Operation {
175
175
  id: string;
176
176
  machineId: string;
177
- type: 'create' | 'start' | 'stop' | 'suspend' | 'resume' | 'delete';
177
+ type: 'create' | 'start' | 'stop' | 'suspend' | 'resume' | 'resize' | 'delete';
178
178
  state: 'queued' | 'running' | 'succeeded' | 'failed';
179
179
  phase?: string;
180
180
  error: ApiError | null;
@@ -974,6 +974,11 @@ interface CreateSnapshotOpts {
974
974
  /** Save only the root disk; omit the persistent /data disk. */
975
975
  rootOnly?: boolean;
976
976
  }
977
+ /** One of the plan's sizes: `instabox whoami --json` lists them as `allowedSpecs`. */
978
+ interface ResizeOpts {
979
+ vcpus: number;
980
+ memMiB: number;
981
+ }
977
982
  /** One load sample of a sandbox, 30 s apart. Measured on the host; bytes throughout. */
978
983
  interface SandboxMetrics {
979
984
  timestamp: Date;
@@ -1094,6 +1099,14 @@ declare class Sandbox {
1094
1099
  * sends no request.
1095
1100
  */
1096
1101
  setTimeout(..._args: unknown[]): Promise<never>;
1102
+ /**
1103
+ * Gives the sandbox another of its plan's sizes (paid plans). A stopped sandbox takes it at its next
1104
+ * start. A running or paused one is stopped, resized and started again by one server operation: files
1105
+ * stay, running processes and paused memory do not. If it cannot start at the new size, the server
1106
+ * starts it again at the old one and this throws. A size the plan does not offer throws
1107
+ * `InstaboxQuotaError` (`spec_not_allowed`). Requires machines:write.
1108
+ */
1109
+ resize(opts: ResizeOpts): Promise<void>;
1097
1110
  /** Replaces the sandbox's metadata (`{}` clears it). */
1098
1111
  setMetadata(metadata: Record<string, string>): Promise<void>;
1099
1112
  /**
@@ -1149,4 +1162,4 @@ declare class Sandbox {
1149
1162
  private mutate;
1150
1163
  }
1151
1164
 
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 };
1165
+ 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, type ResizeOpts, 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
@@ -174,7 +174,7 @@ interface MachineList {
174
174
  interface Operation {
175
175
  id: string;
176
176
  machineId: string;
177
- type: 'create' | 'start' | 'stop' | 'suspend' | 'resume' | 'delete';
177
+ type: 'create' | 'start' | 'stop' | 'suspend' | 'resume' | 'resize' | 'delete';
178
178
  state: 'queued' | 'running' | 'succeeded' | 'failed';
179
179
  phase?: string;
180
180
  error: ApiError | null;
@@ -974,6 +974,11 @@ interface CreateSnapshotOpts {
974
974
  /** Save only the root disk; omit the persistent /data disk. */
975
975
  rootOnly?: boolean;
976
976
  }
977
+ /** One of the plan's sizes: `instabox whoami --json` lists them as `allowedSpecs`. */
978
+ interface ResizeOpts {
979
+ vcpus: number;
980
+ memMiB: number;
981
+ }
977
982
  /** One load sample of a sandbox, 30 s apart. Measured on the host; bytes throughout. */
978
983
  interface SandboxMetrics {
979
984
  timestamp: Date;
@@ -1094,6 +1099,14 @@ declare class Sandbox {
1094
1099
  * sends no request.
1095
1100
  */
1096
1101
  setTimeout(..._args: unknown[]): Promise<never>;
1102
+ /**
1103
+ * Gives the sandbox another of its plan's sizes (paid plans). A stopped sandbox takes it at its next
1104
+ * start. A running or paused one is stopped, resized and started again by one server operation: files
1105
+ * stay, running processes and paused memory do not. If it cannot start at the new size, the server
1106
+ * starts it again at the old one and this throws. A size the plan does not offer throws
1107
+ * `InstaboxQuotaError` (`spec_not_allowed`). Requires machines:write.
1108
+ */
1109
+ resize(opts: ResizeOpts): Promise<void>;
1097
1110
  /** Replaces the sandbox's metadata (`{}` clears it). */
1098
1111
  setMetadata(metadata: Record<string, string>): Promise<void>;
1099
1112
  /**
@@ -1149,4 +1162,4 @@ declare class Sandbox {
1149
1162
  private mutate;
1150
1163
  }
1151
1164
 
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 };
1165
+ 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, type ResizeOpts, 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
@@ -2548,6 +2548,12 @@ function toSeconds(ms, field) {
2548
2548
  }
2549
2549
  return s;
2550
2550
  }
2551
+ function wholeCount(field, n) {
2552
+ if (!Number.isInteger(n) || n < 1) {
2553
+ throw new InstaboxError(`${field} must be a whole number from 1; got ${n}`, { code: "bad_request" });
2554
+ }
2555
+ return n;
2556
+ }
2551
2557
  var METADATA_KEY = /^[A-Za-z0-9_.-]{1,64}$/;
2552
2558
  var enc4 = encodeURIComponent;
2553
2559
  var Sandbox = class _Sandbox {
@@ -2703,6 +2709,27 @@ var Sandbox = class _Sandbox {
2703
2709
  async setTimeout(..._args) {
2704
2710
  throw timeoutRemoved("setTimeout()", "Use setAutoSuspend(ms) to pause the sandbox once it has been idle that long");
2705
2711
  }
2712
+ /**
2713
+ * Gives the sandbox another of its plan's sizes (paid plans). A stopped sandbox takes it at its next
2714
+ * start. A running or paused one is stopped, resized and started again by one server operation: files
2715
+ * stay, running processes and paused memory do not. If it cannot start at the new size, the server
2716
+ * starts it again at the old one and this throws. A size the plan does not offer throws
2717
+ * `InstaboxQuotaError` (`spec_not_allowed`). Requires machines:write.
2718
+ */
2719
+ async resize(opts) {
2720
+ const vcpus = wholeCount("vcpus", opts.vcpus);
2721
+ const memMiB = wholeCount("memMiB", opts.memMiB);
2722
+ await this.settle();
2723
+ if (this.machine.spec.vcpus === vcpus && this.machine.spec.memMiB === memMiB) return;
2724
+ const body = { vcpus, memMiB };
2725
+ if (this.machine.state !== "stopped") body.apply = "restart";
2726
+ const r = await this.http.request("PATCH", `/v1/machines/${enc4(this.sandboxId)}`, { body });
2727
+ try {
2728
+ if ("machineId" in r) await this.http.waitForOperation(r);
2729
+ } finally {
2730
+ this.machine = await getMachine(this.http, this.sandboxId).catch(() => this.machine);
2731
+ }
2732
+ }
2706
2733
  /** Replaces the sandbox's metadata (`{}` clears it). */
2707
2734
  async setMetadata(metadata) {
2708
2735
  this.machine = await this.http.request("PATCH", `/v1/machines/${enc4(this.sandboxId)}`, {