@kvbox/cli 0.5.37 → 0.5.38

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/kvbox.js CHANGED
@@ -164,7 +164,7 @@ function versionOf(srcFileUrl, injected) {
164
164
  }
165
165
 
166
166
  // src/version.ts
167
- var VERSION = versionOf(import.meta.url, true ? "0.5.37" : void 0);
167
+ var VERSION = versionOf(import.meta.url, true ? "0.5.38" : void 0);
168
168
 
169
169
  // src/commands/vm/index.ts
170
170
  import { Command as Command37 } from "commander";
@@ -582,6 +582,11 @@ var MachineSchema = z2.object({
582
582
  ports: z2.array(PortForwardSchema).optional(),
583
583
  /** Whether the owner slug is a user or an org. Only the control plane knows; it fills it in on `GET /machines`. */
584
584
  ownerKind: z2.enum(["user", "org"]).optional(),
585
+ /**
586
+ * The name of the host the box runs on. Only the control plane fills it in, on `GET /machines`: a box
587
+ * links to, and a volume attaches to, only a box on the same host.
588
+ */
589
+ host: z2.string().optional(),
585
590
  /** Seconds without network traffic before the host hibernates the box (#47). Absent: never. */
586
591
  autoHibernateSec: z2.number().int().positive().optional(),
587
592
  /** A script inside the box that says it is idle (#102, exit 0): auto-hibernate asks it instead of watching the traffic. */
@@ -609,7 +614,9 @@ var VolumeSchema = z2.object({
609
614
  attachedTo: z2.string().nullable(),
610
615
  createdAt: z2.string(),
611
616
  /** Whether the owner slug is a user or an org. Only the control plane knows; it fills it in on `GET /volumes`. */
612
- ownerKind: z2.enum(["user", "org"]).optional()
617
+ ownerKind: z2.enum(["user", "org"]).optional(),
618
+ /** The name of the host the volume lives on; only the control plane fills it in. It attaches only to a box there. */
619
+ host: z2.string().optional()
613
620
  });
614
621
  var MAX_VOLUME_GIB = 4096;
615
622
  var VOLUME_NAME_RE = /^[a-z0-9][a-z0-9-]{0,11}$/;
@@ -758,6 +765,7 @@ var CapacitySchema = z2.object({
758
765
  */
759
766
  images: z2.array(z2.object({ name: z2.string(), version: z2.string() })).optional()
760
767
  });
768
+ var ImageSchema = z2.object({ name: z2.string(), version: z2.string().nullable() });
761
769
  var RecoveryReportSchema = z2.object({
762
770
  at: z2.string(),
763
771
  booted: z2.array(z2.string()),
@@ -1284,6 +1292,9 @@ var ServerClient = class {
1284
1292
  return this.call("DELETE", `/machines/${encodeURIComponent(name)}/links`, MachineSchema, req);
1285
1293
  }
1286
1294
  /** Backups, the control plane's only: a box's disk in object storage. Newest first. */
1295
+ listBackups() {
1296
+ return this.call("GET", "/backups", z3.array(BackupSchema));
1297
+ }
1287
1298
  boxBackups(name) {
1288
1299
  return this.call("GET", `/machines/${encodeURIComponent(name)}/backups`, z3.array(BackupSchema));
1289
1300
  }
@@ -2109,7 +2120,11 @@ function addressOf(b) {
2109
2120
  var lsCommand = new Command5("ls").description("list boxes with status and address (yours and your orgs'; --org <slug> for one org)").option("-a, --all", "every box on the platform (platform admins only)").option("--json", "print as JSON").action(async (opts, cmd) => {
2110
2121
  const client = await clientFor(cmd.optsWithGlobals());
2111
2122
  try {
2112
- const boxes = await spin("listing boxes\u2026", client.listMachines({ all: opts.all }));
2123
+ const cloud = client.target.kind === "cloud";
2124
+ const [boxes, admin] = await spin(
2125
+ "listing boxes\u2026",
2126
+ Promise.all([client.listMachines({ all: opts.all }), cloud && !opts.json ? client.me().then((u) => u.role === "admin", () => false) : Promise.resolve(false)])
2127
+ );
2113
2128
  if (opts.json) {
2114
2129
  json(boxes);
2115
2130
  return;
@@ -2120,7 +2135,7 @@ var lsCommand = new Command5("ls").description("list boxes with status and addre
2120
2135
  return;
2121
2136
  }
2122
2137
  if (org !== void 0) info(`boxes of ${org}`);
2123
- table(lsRows(boxes, client.target.kind === "cloud" ? { me: client.target.user } : void 0));
2138
+ table(lsRows(boxes, cloud ? { me: me(client), showHost: admin } : void 0));
2124
2139
  } finally {
2125
2140
  await client.close();
2126
2141
  }
@@ -2130,6 +2145,7 @@ function lsRows(boxes, cloud) {
2130
2145
  ...cloud ? { owner: ownerCell(b, cloud.me) } : {},
2131
2146
  name: boxName(b.name),
2132
2147
  status: status(b.status),
2148
+ ...cloud?.showHost ? { host: b.host ?? "-" } : {},
2133
2149
  address: addressOf(b),
2134
2150
  size: b.status === "unknown" ? "-" : `${shape(b.vcpu, b.memMib, b.diskBytes)} ${color.dim(`(${gbShort(b.diskUsedBytes)} used)`)}`,
2135
2151
  created: age(b.createdAt),
@@ -2690,7 +2706,7 @@ function sizeLine(b) {
2690
2706
  }
2691
2707
 
2692
2708
  // src/commands/vm/backup/create.ts
2693
- var createCommand2 = new Command22("create").description("back up a box's disk to the kvbox cloud (encrypted; memory and volumes not included)").argument("<box>", "box name").option("--no-wait", "start it and return; kvbox vm backup ls <box> shows when it is ready").option("--json", "print the backup as JSON").action(async (name, opts, cmd) => {
2709
+ var createCommand2 = new Command22("create").description("back up a box's disk to the kvbox cloud (encrypted; memory and volumes not included)").argument("<box>", "box name").option("--wait", "stay until the backup is ready (by default it runs in the background)").option("--json", "print the backup as JSON").action(async (name, opts, cmd) => {
2694
2710
  const client = await clientFor(cmd.optsWithGlobals(), { autoStart: false });
2695
2711
  try {
2696
2712
  requireCloud3(client);
@@ -2699,7 +2715,10 @@ var createCommand2 = new Command22("create").description("back up a box's disk t
2699
2715
  const started = await client.createBoxBackup(box);
2700
2716
  if (!opts.wait) {
2701
2717
  if (opts.json) json(started);
2702
- else info(`${color.green("\u2713")} backup ${started.id} of box ${color.bold(box)} started; kvbox vm backup ls ${box} shows when it is ready`);
2718
+ else {
2719
+ info(`${color.green("\u2713")} backup ${started.id} of box ${color.bold(box)} started; it runs in the background`);
2720
+ info(color.dim(` status: kvbox vm backup ls ${box}`));
2721
+ }
2703
2722
  return;
2704
2723
  }
2705
2724
  const done = await spin(`backing up ${box}\u2026`, untilDone(client, box, started.id));
@@ -2716,30 +2735,32 @@ var createCommand2 = new Command22("create").description("back up a box's disk t
2716
2735
 
2717
2736
  // src/commands/vm/backup/ls.ts
2718
2737
  import { Command as Command23 } from "commander";
2719
- var lsCommand4 = new Command23("ls").alias("list").description("list a box's backups").argument("<box>", "box name").option("--json", "print as JSON").action(async (name, opts, cmd) => {
2738
+ var lsCommand4 = new Command23("ls").alias("list").description("list backups: every box's, or one box's").argument("[box]", "box name (default: every box)").option("--json", "print as JSON").action(async (name, opts, cmd) => {
2720
2739
  const client = await clientFor(cmd.optsWithGlobals(), { autoStart: false });
2721
2740
  try {
2722
2741
  requireCloud3(client);
2723
- const box = displayName(await findBox(client, name), me(client));
2724
- const list = await client.boxBackups(box);
2742
+ const box = name === void 0 ? void 0 : displayName(await findBox(client, name), me(client));
2743
+ const list = box === void 0 ? await client.listBackups() : await client.boxBackups(box);
2725
2744
  if (opts.json) {
2726
2745
  json(list);
2727
2746
  return;
2728
2747
  }
2729
2748
  if (list.length === 0) {
2730
- info(`box ${box} has no backups; make one with: kvbox vm backup create ${box}`);
2749
+ info(box === void 0 ? "no backups yet; make one with: kvbox vm backup create <box>" : `box ${box} has no backups; make one with: kvbox vm backup create ${box}`);
2731
2750
  return;
2732
2751
  }
2752
+ const anyError = list.some((b) => b.error !== null);
2733
2753
  table(
2734
2754
  list.map((b) => ({
2735
2755
  id: b.id,
2756
+ ...box === void 0 ? { box: b.owner === me(client) ? b.box : `${b.owner}/${b.box}` } : {},
2736
2757
  status: b.status === "ready" ? color.green(b.status) : b.status === "failed" ? color.red(b.status) : color.yellow(b.status),
2737
2758
  data: b.dataBytes === null ? "-" : gbShort(b.dataBytes),
2738
2759
  uploaded: b.uploadedBytes === null ? "-" : gbShort(b.uploadedBytes),
2739
2760
  disk: b.diskBytes === null ? "-" : gbShort(b.diskBytes),
2740
2761
  by: b.createdBy ?? "-",
2741
2762
  taken: age(b.createdAt),
2742
- ...b.error !== null ? { error: b.error } : {}
2763
+ ...anyError ? { error: b.error ?? "" } : {}
2743
2764
  }))
2744
2765
  );
2745
2766
  } finally {