@kvbox/cli 0.5.50 → 0.6.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/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.50" : void 0);
167
+ var VERSION = versionOf(import.meta.url, true ? "0.6.0" : void 0);
168
168
 
169
169
  // src/commands/vm/index.ts
170
170
  import { Command as Command37 } from "commander";
@@ -220,6 +220,15 @@ function paths(home = kvboxHome()) {
220
220
  firecracker: join(home, "bin", "firecracker"),
221
221
  /** Firecracker's snapshot-editor, from the same release: merges a diff snapshot onto a full memory image. */
222
222
  snapshotEditor: join(home, "bin", "snapshot-editor"),
223
+ /** Garage, on a host that is a backup store (`kvbox-server backup setup` downloads it). */
224
+ garage: join(home, "bin", "garage"),
225
+ /** The store's Garage as this host runs it: its configuration, pid and log. The data is on the disk the operator named. */
226
+ backupStore: {
227
+ dir: join(home, "backup-store"),
228
+ conf: join(home, "backup-store", "garage.toml"),
229
+ pid: join(home, "backup-store", "garage.pid"),
230
+ log: join(home, "backup-store", "garage.log")
231
+ },
223
232
  assets: join(home, "assets"),
224
233
  kernel: join(home, "assets", "vmlinux"),
225
234
  /** Symlink to the current base image, assets/rootfs-<version>.ext4; boxes keep using the version they were made from. */
@@ -547,7 +556,7 @@ var HostBackupManifestSchema = z2.object({
547
556
  vcpu: z2.number().int(),
548
557
  memMib: z2.number().int()
549
558
  });
550
- var HostUploadRequest = z2.object({ key: z2.string(), urls: z2.record(z2.string(), z2.string()) });
559
+ var HostUploadRequest = z2.object({ key: z2.string(), urls: z2.record(z2.string(), z2.string()), pin: z2.string().optional() });
551
560
  var HostUploadResultSchema = z2.object({ chunks: z2.number().int(), bytes: z2.number().int(), sizes: z2.record(z2.string(), z2.number().int()) });
552
561
  var HostRestoreRequest = z2.object({
553
562
  /** The backup's id: its variables were sealed under it. */
@@ -557,7 +566,43 @@ var HostRestoreRequest = z2.object({
557
566
  base: z2.string(),
558
567
  image: z2.string().optional(),
559
568
  env: z2.string().nullable(),
560
- chunks: z2.array(z2.object({ index: z2.number().int().nonnegative(), hash: z2.string(), url: z2.string() }))
569
+ chunks: z2.array(z2.object({ index: z2.number().int().nonnegative(), hash: z2.string(), url: z2.string() })),
570
+ /** The certificate fingerprint of the store the URLs point at (see HostUploadRequest). */
571
+ pin: z2.string().optional()
572
+ });
573
+ var BackupStoreSetupRequest = z2.object({ path: z2.string().min(1), force: z2.boolean().optional(), newStore: z2.boolean().optional() });
574
+ var BackupStoreStatusSchema = z2.object({
575
+ path: z2.string(),
576
+ bucket: z2.string(),
577
+ accessKey: z2.string(),
578
+ /** Whether Garage is running and can store. */
579
+ running: z2.boolean(),
580
+ /** The filesystem the path is on. */
581
+ totalBytes: z2.number().int(),
582
+ freeBytes: z2.number().int(),
583
+ /** What the bucket holds, when Garage answers. */
584
+ objects: z2.number().int().optional(),
585
+ storedBytes: z2.number().int().optional(),
586
+ /** Whether the control plane took the store's registration at setup. */
587
+ registered: z2.boolean().optional()
588
+ });
589
+ var BackupStoreRegistration = z2.object({ bucket: z2.string().min(1), region: z2.string().min(1), accessKey: z2.string().min(1), secretKey: z2.string().min(1) });
590
+ var CloudBackupStoreSchema = z2.object({
591
+ id: z2.string(),
592
+ /** Null while no host serves it (its host left; it comes back when a host registers its key and secret again). */
593
+ host: z2.string().nullable(),
594
+ endpoint: z2.string().nullable(),
595
+ bucket: z2.string(),
596
+ accessKey: z2.string(),
597
+ createdAt: z2.string(),
598
+ /** The host answered a poll in the last minute and its Garage runs. */
599
+ live: z2.boolean(),
600
+ /** From the host's last poll; null when it never reported a store. */
601
+ totalBytes: z2.number().int().nullable(),
602
+ freeBytes: z2.number().int().nullable(),
603
+ /** Ready backups kept here, and what their chunks take (encrypted, compressed). */
604
+ backups: z2.number().int(),
605
+ storedBytes: z2.number().int()
561
606
  });
562
607
  var MachineSchema = z2.object({
563
608
  /** Host-unique short id (the tap is `kv-<id>`). Missing only on a box made before ids that has not restarted since. */
@@ -606,6 +651,11 @@ var MachineSchema = z2.object({
606
651
  host: z2.string().optional(),
607
652
  /** The country code of that host (`RO`, `US`), when its admin gave one. Only the control plane fills it in. */
608
653
  country: z2.string().optional(),
654
+ /**
655
+ * The kind of managed service the box runs (`postgres`, `redis`, `storage`). Only an admin's
656
+ * `GET /machines?all=1` lists such boxes, so a host's boxes add up; every other listing hides them.
657
+ */
658
+ managed: z2.string().optional(),
609
659
  /** Seconds without network traffic before the host hibernates the box (#47). Absent: never. */
610
660
  autoHibernateSec: z2.number().int().positive().optional(),
611
661
  /** A script inside the box that says it is idle (#102, exit 0): auto-hibernate asks it instead of watching the traffic. */
@@ -799,7 +849,11 @@ var CapacitySchema = z2.object({
799
849
  */
800
850
  images: z2.array(z2.object({ name: z2.string(), version: z2.string() })).optional(),
801
851
  /** kvbox-server's version, so the control plane's host list shows it without a call per host. Older servers omit it. */
802
- version: z2.string().optional()
852
+ version: z2.string().optional(),
853
+ /** Present on a host set up as a backup store: the disk its Garage keeps chunks on, and whether Garage runs. */
854
+ backupStore: z2.object({ totalBytes: z2.number().int(), freeBytes: z2.number().int(), running: z2.boolean() }).optional(),
855
+ /** True on a kvbox-server that reaches a backup store by its certificate's `pin`; older ones omit it and cannot back up to a store. */
856
+ storeClient: z2.boolean().optional()
803
857
  });
804
858
  var ImageSchema = z2.object({ name: z2.string(), version: z2.string().nullable() });
805
859
  var ImageIndexSchema = z2.object({
@@ -1215,6 +1269,8 @@ var CloudHostSchema = z2.object({
1215
1269
  capacity: CapacitySchema.nullable(),
1216
1270
  /** ISO 3166-1 alpha-2 code (`RO`), null when nobody said where the host is. */
1217
1271
  country: z2.string().nullable(),
1272
+ /** The S3 region a storage made on this host answers to (`ro-west-1`); null: it takes no storage. */
1273
+ region: z2.string().nullable(),
1218
1274
  /** kvbox-server's version as of the poller's last look (`capacity.version`); null before one, or for a server older than 0.5.45. */
1219
1275
  version: z2.string().nullable()
1220
1276
  });
@@ -1223,7 +1279,7 @@ var HostInfoSchema = z2.object({
1223
1279
  health: HealthSchema.nullable(),
1224
1280
  error: z2.string().nullable()
1225
1281
  });
1226
- var HostPatchRequest = z2.object({ country: z2.string().nullable() });
1282
+ var HostPatchRequest = z2.object({ country: z2.string().nullable().optional(), region: z2.string().nullable().optional() }).refine((b) => b.country !== void 0 || b.region !== void 0, { message: "give country, region or both" });
1227
1283
  var CountrySchema = z2.object({ code: z2.string(), name: z2.string() });
1228
1284
 
1229
1285
  // ../shared/src/managed.ts
@@ -1364,11 +1420,13 @@ var GrowManagedRequest = z4.object({ storageGib: z4.number().int() });
1364
1420
 
1365
1421
  // ../shared/src/storage.ts
1366
1422
  import { z as z5 } from "zod";
1423
+ var RegionSchema = z5.object({ name: z5.string(), country: z5.string().nullable() });
1367
1424
  var ObjectStorageSchema = z5.object({
1368
1425
  owner: z5.string(),
1369
1426
  ownerKind: z5.enum(["user", "org"]),
1370
1427
  /** `https://s3-<slug>.<domain>`: what an S3 client is given, with path-style addressing. Null while the address is not claimed. */
1371
1428
  endpoint: z5.string().nullable(),
1429
+ /** The S3 region every client of it signs with (`ro-west-1`): its host's when it was made. */
1372
1430
  region: z5.string(),
1373
1431
  /** The most it may hold. */
1374
1432
  sizeGib: z5.number().int(),
@@ -1398,7 +1456,8 @@ var BucketSchema = z5.object({
1398
1456
  var CreateBucketRequest = z5.object({
1399
1457
  name: z5.string(),
1400
1458
  sizeGib: z5.number().int().optional(),
1401
- near: z5.string().optional()
1459
+ near: z5.string().optional(),
1460
+ region: z5.string().optional()
1402
1461
  });
1403
1462
  var CreatedBucketSchema = BucketSchema.extend({ storage: ObjectStorageSchema, storageCreated: z5.boolean() });
1404
1463
  var BucketInfoSchema = BucketSchema.extend({ storage: ObjectStorageSchema });
@@ -2608,7 +2667,8 @@ var hostCell = (b) => b.host === void 0 ? "-" : b.country === void 0 ? b.host :
2608
2667
  function lsRows(boxes, cloud) {
2609
2668
  return boxes.map((b) => ({
2610
2669
  ...cloud ? { owner: ownerCell(b, cloud.me) } : {},
2611
- name: boxName(b.name),
2670
+ // a managed service's or storage's box, which only a platform admin's --all lists: `s3-1a2b3c (storage)`
2671
+ name: b.managed === void 0 ? boxName(b.name) : `${boxName(b.name)} ${color.dim(`(${b.managed})`)}`,
2612
2672
  status: status(b.status),
2613
2673
  ...cloud?.showHost ? { host: hostCell(b) } : {},
2614
2674
  address: addressOf(b),
@@ -5882,18 +5942,18 @@ function printRows(rows2) {
5882
5942
  }
5883
5943
 
5884
5944
  // src/commands/bucket/create.ts
5885
- var createCommand4 = new Command62("create").description("make a bucket (the first one also makes your object storage)").argument("<name>", "bucket name: 3-63 lowercase letters, digits and '-'").option("--size <GB>", "how much your object storage may hold, when this is your first bucket (default 10)").option("--near <box>", "put the object storage on the host of this box, when this is your first bucket").option("--json", "print as JSON").action(async (name, opts, cmd) => {
5945
+ var createCommand4 = new Command62("create").description("make a bucket (the first one also makes your object storage)").argument("<name>", "bucket name: 3-63 lowercase letters, digits and '-'").option("--size <GB>", "how much your object storage may hold, when this is your first bucket (default 10)").option("--region <region>", "the S3 region of your object storage (ro-west-1, de-center-1), when this is your first bucket").option("--near <box>", "put the object storage on the host of this box, when this is your first bucket").option("--json", "print as JSON").action(async (name, opts, cmd) => {
5886
5946
  const sizeGib = opts.size === void 0 ? void 0 : parseGib2(opts.size);
5887
5947
  const client = await bucketClient(cmd);
5888
5948
  try {
5889
- const made = await spin(`making bucket ${name}\u2026`, client.createBucket({ name, ...sizeGib !== void 0 ? { sizeGib } : {}, ...opts.near !== void 0 ? { near: opts.near } : {} }));
5949
+ const made = await spin(`making bucket ${name}\u2026`, client.createBucket({ name, ...sizeGib !== void 0 ? { sizeGib } : {}, ...opts.region !== void 0 ? { region: opts.region } : {}, ...opts.near !== void 0 ? { near: opts.near } : {} }));
5890
5950
  if (opts.json) {
5891
5951
  json(made);
5892
5952
  return;
5893
5953
  }
5894
5954
  const shown = shownName(made, client);
5895
5955
  info(`${color.green("\u2713")} bucket ${color.bold(shown)} made`);
5896
- if (made.storageCreated) info(` object storage made for ${made.owner}: ${made.storage.sizeGib} GB for all its buckets, ${priceText(made.storage)}`);
5956
+ if (made.storageCreated) info(` object storage made for ${made.owner} in ${made.storage.region}: ${made.storage.sizeGib} GB for all its buckets, ${priceText(made.storage)}`);
5897
5957
  info(` endpoint: ${endpointText(made.endpoint)} ${color.dim(`region ${made.region}, path-style`)}`);
5898
5958
  info(color.dim(` next: kvbox bucket key create ${shown} (an access key for your app)`));
5899
5959
  } finally {