@kvbox/cli 0.6.8 → 0.6.10

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
@@ -9,6 +9,12 @@ var KvboxError = class extends Error {
9
9
  }
10
10
  exitCode;
11
11
  };
12
+ var NotFoundError = class extends KvboxError {
13
+ constructor(what) {
14
+ super(`${what}: not found`, 1);
15
+ this.name = "NotFoundError";
16
+ }
17
+ };
12
18
  var AmbiguousRefError = class extends KvboxError {
13
19
  /** `orgFlag` false: `--org` names something else on this command (a fork's target), so only `slug/name` is offered. */
14
20
  constructor(kind, name, slugs, orgFlag = true) {
@@ -149,7 +155,7 @@ async function spin(message, work, opts = {}) {
149
155
  }
150
156
 
151
157
  // src/program.ts
152
- import { Command as Command116 } from "commander";
158
+ import { Command as Command129 } from "commander";
153
159
 
154
160
  // ../shared/src/version.ts
155
161
  import { createRequire } from "module";
@@ -164,10 +170,10 @@ function versionOf(srcFileUrl, injected) {
164
170
  }
165
171
 
166
172
  // src/version.ts
167
- var VERSION = versionOf(import.meta.url, true ? "0.6.8" : void 0);
173
+ var VERSION = versionOf(import.meta.url, true ? "0.6.10" : void 0);
168
174
 
169
175
  // src/commands/vm/index.ts
170
- import { Command as Command37 } from "commander";
176
+ import { Command as Command38 } from "commander";
171
177
 
172
178
  // src/commands/vm/connect.ts
173
179
  import { spawnSync as spawnSync3 } from "child_process";
@@ -234,6 +240,8 @@ function paths(home = kvboxHome()) {
234
240
  },
235
241
  assets: join(home, "assets"),
236
242
  kernel: join(home, "assets", "vmlinux"),
243
+ /** A kernel an image asks for by name in its image.json (`"kernel": "android"`): assets/vmlinux-<name>, put there by install-server.sh. */
244
+ namedKernel: (name) => join(home, "assets", `vmlinux-${name}`),
237
245
  /** Symlink to the current base image, assets/rootfs-<version>.ext4; boxes keep using the version they were made from. */
238
246
  rootfs: join(home, "assets", "rootfs.ext4"),
239
247
  baseImage: (version) => join(home, "assets", `rootfs-${version}.ext4`),
@@ -448,6 +456,12 @@ var BackupSchema = z.object({
448
456
  createdAt: z.string(),
449
457
  finishedAt: z.string().nullable()
450
458
  });
459
+ var BackupLimitSchema = z.object({
460
+ perDay: z.number().int(),
461
+ used: z.number().int(),
462
+ nextAt: z.string().nullable()
463
+ });
464
+ var NamedBackupLimitSchema = BackupLimitSchema.extend({ owner: z.string(), name: z.string() });
451
465
  var HostBackupRequest = z.object({ id: z.string(), key: z.string() });
452
466
  var HostBackupManifestSchema = z.object({
453
467
  id: z.string(),
@@ -490,6 +504,16 @@ var VolumeBackupSchema = z.object({
490
504
  createdAt: z.string(),
491
505
  finishedAt: z.string().nullable()
492
506
  });
507
+ var BackupScheduleSchema = z.object({
508
+ enabled: z.boolean(),
509
+ /** 0-23, UTC. Kept while it is off, so turning it on again keeps the hour. */
510
+ hour: z.number().int().min(0).max(23),
511
+ nextAt: z.string().nullable(),
512
+ lastAt: z.string().nullable(),
513
+ lastBackup: z.string().nullable(),
514
+ lastError: z.string().nullable()
515
+ });
516
+ var SetBackupScheduleRequest = z.object({ enabled: z.boolean().optional(), hour: z.number().int().min(0).max(23).optional() });
493
517
  var HostVolumeBackupManifestSchema = z.object({ id: z.string(), sizeBytes: z.number().int(), chunks: z.array(z.string().nullable()) });
494
518
  var HostVolumeRestoreRequest = z.object({
495
519
  id: z.string(),
@@ -531,16 +555,20 @@ var CloudBackupStoreSchema = z.object({
531
555
  /** Ready backups kept here, and what their chunks take (encrypted, compressed). */
532
556
  backups: z.number().int(),
533
557
  storedBytes: z.number().int(),
534
- /** How many boxes have a ready backup here (a box and an earlier one of the same name count once), and how many volumes (#168). */
558
+ /** How many boxes have a ready backup here (a box and an earlier one of the same name count once), how many volumes (#168) and managed databases (#186). */
535
559
  boxes: z.number().int(),
536
560
  volumes: z.number().int(),
561
+ databases: z.number().int(),
537
562
  /** When the newest ready backup kept here finished; null when it keeps none. */
538
563
  lastBackupAt: z.string().nullable()
539
564
  });
540
565
  var StoredItemSchema = z.object({
541
566
  kind: z.enum(BACKUP_KINDS),
542
567
  owner: z.string(),
568
+ /** The box's or volume's name; a managed database's (#186) for its hidden volume. */
543
569
  name: z.string(),
570
+ /** The managed database's kind (`postgres`) when the volume is one's (#186); null otherwise. */
571
+ managed: z.string().nullable(),
544
572
  /** The host the box (or volume) is on now; null when it is gone (its backups stay). */
545
573
  host: z.string().nullable(),
546
574
  /** It is on the store's own host: losing that host loses it and its backups together. */
@@ -554,9 +582,11 @@ var StoredItemSchema = z.object({
554
582
  var FailedBackupSchema = z.object({
555
583
  id: z.string(),
556
584
  owner: z.string(),
557
- /** What it was a backup of: a box or a volume (#168), and its name. */
585
+ /** What it was a backup of: a box or a volume (#168), and its name; a managed database's (#186) for its hidden volume. */
558
586
  kind: z.enum(BACKUP_KINDS),
559
587
  name: z.string(),
588
+ /** The managed database's kind (`postgres`) when the volume is one's; null otherwise. */
589
+ managed: z.string().nullable(),
560
590
  error: z.string().nullable(),
561
591
  /** The host that took it, and the host of the store it was going to; null when gone, or when it failed before a store was picked. */
562
592
  host: z.string().nullable(),
@@ -1012,6 +1042,16 @@ var CronUsageSchema = z.object({
1012
1042
  /** When it was made. */
1013
1043
  historyFrom: z.string().nullable()
1014
1044
  });
1045
+ var BackupUsageSchema = z.object({
1046
+ id: z.string(),
1047
+ kind: z.string(),
1048
+ name: z.string(),
1049
+ owner: z.string(),
1050
+ ownerKind: z.enum(["user", "org"]).optional(),
1051
+ /** How many paid backups turned ready in the window. */
1052
+ count: z.number().int(),
1053
+ cost: z.object({ amount: z.number(), currency: z.string() })
1054
+ });
1015
1055
  var UsageDayItemSchema = z.object({
1016
1056
  id: z.string(),
1017
1057
  name: z.string(),
@@ -1032,7 +1072,9 @@ var UsageDaySchema = z.object({
1032
1072
  /** Object storage that existed that day (#182); absent on a day without any. */
1033
1073
  storage: z.array(UsageDayItemSchema).optional(),
1034
1074
  /** Cron services that existed that day (#190); absent on a day without any. */
1035
- cron: z.array(UsageDayItemSchema).optional()
1075
+ cron: z.array(UsageDayItemSchema).optional(),
1076
+ /** Paid backups that turned ready that day, summed per thing backed up (`id` is `<owner>/<kind>:<name>`); absent on a day without any. */
1077
+ backups: z.array(UsageDayItemSchema).optional()
1036
1078
  });
1037
1079
  var UsageReportSchema = z.object({
1038
1080
  window: z.object({ from: z.string(), to: z.string() }),
@@ -1047,6 +1089,8 @@ var UsageReportSchema = z.object({
1047
1089
  storage: z.array(VolumeUsageSchema).optional(),
1048
1090
  /** Cron services (#190, control plane only): one row per service a slug has or had. Absent when there is none. */
1049
1091
  cron: z.array(CronUsageSchema).optional(),
1092
+ /** Paid backups (control plane only): one row per box, volume or service backed up by hand in the window. Absent when there is none. */
1093
+ backups: z.array(BackupUsageSchema).optional(),
1050
1094
  /** With `?by=day` only, oldest day first. */
1051
1095
  days: z.array(UsageDaySchema).optional(),
1052
1096
  totals: z.object({
@@ -1056,7 +1100,7 @@ var UsageReportSchema = z.object({
1056
1100
  diskGibHours: z.number(),
1057
1101
  volumeHours: z.number().optional(),
1058
1102
  volumeGibHours: z.number().optional(),
1059
- /** Boxes, volumes, object storage and cron services together. */
1103
+ /** Boxes, volumes, object storage, cron services and paid backups together. */
1060
1104
  cost: z.object({ amount: z.number(), currency: z.string() }).optional()
1061
1105
  })
1062
1106
  });
@@ -1091,7 +1135,7 @@ var VolumeEventsResponseSchema = z.object({
1091
1135
  events: z.array(VolumeEventRowSchema),
1092
1136
  next: z.number().int()
1093
1137
  });
1094
- var API_ERROR_CODES = ["account-inactive", "org-inactive", "out-of-credit", "box-outdated"];
1138
+ var API_ERROR_CODES = ["account-inactive", "org-inactive", "out-of-credit", "box-outdated", "storage-outdated", "object-exists", "storage-waking"];
1095
1139
  var ApiErrorCodeSchema = z.enum(API_ERROR_CODES);
1096
1140
  var ApiErrorSchema = z.object({
1097
1141
  error: z.string(),
@@ -1583,7 +1627,7 @@ var PaymentRequiredError = class extends KvboxApiError {
1583
1627
  this.name = "PaymentRequiredError";
1584
1628
  }
1585
1629
  };
1586
- var NotFoundError = class extends KvboxApiError {
1630
+ var NotFoundError2 = class extends KvboxApiError {
1587
1631
  constructor(status2, message, opts = {}) {
1588
1632
  super(status2, message, opts);
1589
1633
  this.name = "NotFoundError";
@@ -1608,7 +1652,7 @@ function apiError(status2, message, opts = {}) {
1608
1652
  case 402:
1609
1653
  return new PaymentRequiredError(status2, message, opts);
1610
1654
  case 404:
1611
- return new NotFoundError(status2, message, opts);
1655
+ return new NotFoundError2(status2, message, opts);
1612
1656
  case 409:
1613
1657
  return opts.code === "box-outdated" ? new BoxOutdatedError(status2, message, opts) : new ConflictError(status2, message, opts);
1614
1658
  default:
@@ -1679,7 +1723,7 @@ var Machines = class {
1679
1723
  const named = listing.filter((m) => m.name === bare && (slash === -1 || slugOf2(m.owner) === org));
1680
1724
  if (named.length <= 1) {
1681
1725
  if (named[0] !== void 0) return named[0];
1682
- throw new NotFoundError(404, `box ${name}: not found`);
1726
+ throw new NotFoundError2(404, `box ${name}: not found`);
1683
1727
  }
1684
1728
  const own = named.filter((m) => m.ownerKind === "user");
1685
1729
  if (own.length === 1) return own[0];
@@ -2039,9 +2083,6 @@ var Kvbox = class {
2039
2083
  // src/client.ts
2040
2084
  import { z as z11 } from "zod";
2041
2085
 
2042
- // ../shared/src/managed.ts
2043
- import { z as z8 } from "zod";
2044
-
2045
2086
  // ../shared/src/usage.ts
2046
2087
  import { z as z7 } from "zod";
2047
2088
  var PricingSchema = z7.object({
@@ -2061,7 +2102,12 @@ var PricingSchema = z7.object({
2061
2102
  storageGibHour: z7.number().nonnegative().default(0),
2062
2103
  storageIncludedGib: z7.number().int().nonnegative().default(0),
2063
2104
  /** The cron service (#190): an hour of one cron service existing, whatever it holds or fires. A price list from before it charges nothing. */
2064
- cronHour: z7.number().nonnegative().default(0)
2105
+ cronHour: z7.number().nonnegative().default(0),
2106
+ /**
2107
+ * One backup a person starts, of anything, charged once it is ready (decision "A backup taken by hand
2108
+ * costs a flat price…"); a failed one and a scheduled one cost nothing. A price list from before it charges nothing.
2109
+ */
2110
+ backup: z7.number().nonnegative().default(0)
2065
2111
  });
2066
2112
  var PriceListSchema = PricingSchema.extend({ welcomeCredit: z7.number().nonnegative() });
2067
2113
  var HOUR_MS = 36e5;
@@ -2091,6 +2137,7 @@ function sumUsage(items, pricing) {
2091
2137
  var DAY_MS = 24 * HOUR_MS;
2092
2138
 
2093
2139
  // ../shared/src/managed.ts
2140
+ import { z as z8 } from "zod";
2094
2141
  var PriceSchema = z8.object({ perMonth: z8.number(), storagePerMonth: z8.number(), currency: z8.string() });
2095
2142
  var ManagedCatalogEntrySchema = z8.object({
2096
2143
  /** The kind, as in `/managed/<kind>`: `postgres`. */
@@ -2125,7 +2172,13 @@ var CreateManagedRequest = z8.object({
2125
2172
  password: z8.string().optional(),
2126
2173
  storageGib: z8.number().int().optional(),
2127
2174
  /** Place it on the host of this box, so the box can be linked to it. */
2128
- near: z8.string().optional()
2175
+ near: z8.string().optional(),
2176
+ /**
2177
+ * A backup of a database of the same kind and major version, of the same account (#186): the new
2178
+ * service starts on its data, a removed service's included. Its settings (Postgres: database, user)
2179
+ * are the backup's; the password is the new one.
2180
+ */
2181
+ fromBackup: z8.string().optional()
2129
2182
  });
2130
2183
  var ManagedHealthSchema = z8.object({
2131
2184
  /** Its first start has finished: it has set itself up on its storage. */
@@ -2167,15 +2220,43 @@ var ManagedSchema = z8.object({
2167
2220
  /** Connection strings with the password as `****`. */
2168
2221
  urls: UrlsSchema,
2169
2222
  price: PriceSchema,
2223
+ /** Its nightly backup (#186 slice 4): on from creation, `kvbox <kind> backup schedule` changes it. Null for a control plane from before schedules. */
2224
+ backupSchedule: BackupScheduleSchema.nullable().default(null),
2170
2225
  /** Only in `GET /managed/<kind>/<name>` (asked live): null when it is not running or did not answer. */
2171
2226
  health: ManagedHealthSchema.nullable().optional()
2172
2227
  });
2173
2228
  var ManagedSecretSchema = z8.object({ password: z8.string(), urls: UrlsSchema });
2174
- var CreatedManagedSchema = ManagedSchema.extend({ secret: ManagedSecretSchema });
2229
+ var CreatedManagedSchema = ManagedSchema.extend({
2230
+ secret: ManagedSecretSchema,
2231
+ /** The backup it was made from (`fromBackup`), when it was. */
2232
+ fromBackup: z8.string().optional()
2233
+ });
2175
2234
  var ResetPasswordRequest = z8.object({ password: z8.string().optional() });
2176
2235
  var SetPublicRequest = z8.object({ on: z8.boolean() });
2177
2236
  var ManagedLinkRequest = z8.object({ box: z8.string() });
2178
2237
  var GrowManagedRequest = z8.object({ storageGib: z8.number().int() });
2238
+ var ManagedBackupSchema = z8.object({
2239
+ id: z8.string(),
2240
+ owner: z8.string(),
2241
+ kind: z8.string(),
2242
+ name: z8.string(),
2243
+ version: z8.string(),
2244
+ status: z8.enum(BACKUP_STATUSES),
2245
+ /** Why it failed; null otherwise. */
2246
+ error: z8.string().nullable(),
2247
+ /** The service's storage when taken. */
2248
+ diskBytes: z8.number().int().nullable(),
2249
+ /** What it holds: the slots that are not all zeros. */
2250
+ dataBytes: z8.number().int().nullable(),
2251
+ /** What this backup added to storage (encrypted, compressed): the chunks no earlier backup had. */
2252
+ uploadedBytes: z8.number().int().nullable(),
2253
+ /** Who asked for it; for a scheduled one, the database's creator. */
2254
+ createdBy: z8.string().nullable(),
2255
+ /** Started by the database's backup schedule, not by a person: it does not count toward the daily limit. */
2256
+ scheduled: z8.boolean().default(false),
2257
+ createdAt: z8.string(),
2258
+ finishedAt: z8.string().nullable()
2259
+ });
2179
2260
 
2180
2261
  // ../shared/src/cron.ts
2181
2262
  import { z as z9 } from "zod";
@@ -2297,6 +2378,8 @@ var ObjectStorageSchema = z10.object({
2297
2378
  /** With `?live=1`, when the storage answered: what is on its disk, and the disk's real size. */
2298
2379
  usedBytes: z10.number().optional(),
2299
2380
  totalBytes: z10.number().optional(),
2381
+ /** With `?live=1`, when the storage answered: what each bucket holds. */
2382
+ bucketUsage: z10.array(z10.object({ name: z10.string(), objects: z10.number(), bytes: z10.number() })).optional(),
2300
2383
  host: z10.string(),
2301
2384
  country: z10.string().optional(),
2302
2385
  buckets: z10.number().int(),
@@ -2335,6 +2418,92 @@ var BucketKeySchema = z10.object({
2335
2418
  var CreateBucketKeyRequest = z10.object({ name: z10.string().optional(), readOnly: z10.boolean().optional() });
2336
2419
  var CreatedBucketKeySchema = BucketKeySchema.extend({ secret: z10.string(), endpoint: z10.string().nullable(), region: z10.string() });
2337
2420
  var GrowStorageRequest = z10.object({ sizeGib: z10.number().int() });
2421
+ var StorageBackupSchema = z10.object({
2422
+ id: z10.string(),
2423
+ owner: z10.string(),
2424
+ status: z10.enum(BACKUP_STATUSES),
2425
+ /** Why it failed; null otherwise. */
2426
+ error: z10.string().nullable(),
2427
+ /** The storage's volume when taken. */
2428
+ diskBytes: z10.number().int().nullable(),
2429
+ /** What it holds: the slots that are not all zeros. */
2430
+ dataBytes: z10.number().int().nullable(),
2431
+ /** What this backup added to the backup store (encrypted, compressed). */
2432
+ uploadedBytes: z10.number().int().nullable(),
2433
+ /** The buckets it holds, and how many access keys they had, as kvbox knew them when it was taken. */
2434
+ buckets: z10.array(z10.string()),
2435
+ keys: z10.number().int(),
2436
+ createdBy: z10.string().nullable(),
2437
+ createdAt: z10.string(),
2438
+ finishedAt: z10.string().nullable()
2439
+ });
2440
+ var RestoredKeySchema = z10.object({ bucket: z10.string(), id: z10.string(), name: z10.string() });
2441
+ var StorageRestoreSchema = z10.object({
2442
+ backup: z10.string(),
2443
+ storage: ObjectStorageSchema,
2444
+ buckets: z10.object({ kept: z10.array(z10.string()), returned: z10.array(z10.string()), removed: z10.array(z10.string()) }),
2445
+ keys: z10.object({ dropped: z10.array(RestoredKeySchema), revoked: z10.array(RestoredKeySchema) }),
2446
+ checked: z10.boolean(),
2447
+ warnings: z10.array(z10.string())
2448
+ });
2449
+ var OBJECT_LIST_MAX = 1e3;
2450
+ var SHARE_LINK_MAX_SEC = 7 * 24 * 3600;
2451
+ var UPLOAD_URL_SEC = 12 * 3600;
2452
+ var MULTIPART_THRESHOLD_BYTES = 64 * 1024 * 1024;
2453
+ var MULTIPART_PART_BYTES = 16 * 1024 * 1024;
2454
+ var UPLOAD_MAX_BYTES = 50 * 1024 * 1024 * 1024;
2455
+ var MOVE_MAX_BYTES = 5 * 1024 * 1024 * 1024;
2456
+ var DELETE_PREFIXES_MAX = 100;
2457
+ var StoredObjectSchema = z10.object({
2458
+ key: z10.string(),
2459
+ size: z10.number(),
2460
+ etag: z10.string(),
2461
+ /** ISO 8601. */
2462
+ modified: z10.string()
2463
+ });
2464
+ var ObjectListingSchema = z10.object({
2465
+ prefix: z10.string(),
2466
+ folders: z10.array(z10.string()),
2467
+ objects: z10.array(StoredObjectSchema),
2468
+ next: z10.string().optional(),
2469
+ canWrite: z10.boolean()
2470
+ });
2471
+ var ObjectInfoSchema = StoredObjectSchema.extend({ contentType: z10.string() });
2472
+ var ObjectCountSchema = z10.object({ objects: z10.number(), bytes: z10.number(), more: z10.boolean() });
2473
+ var ObjectLinkRequest = z10.object({
2474
+ key: z10.string(),
2475
+ expiresSec: z10.number().int().positive(),
2476
+ /** Answer as a download (`Content-Disposition: attachment`) instead of showing it. */
2477
+ download: z10.boolean().optional(),
2478
+ /**
2479
+ * Let the browser keep what the link answers until the link expires (`Cache-Control: private`, `Expires`),
2480
+ * so the same link shown twice is fetched once. Asked again within the hour, for the same file as it
2481
+ * is, it is the same URL, and it lasts up to an hour longer than `expiresSec`. For the app's own previews.
2482
+ * Only a fetch of the whole file is kept so: the storage answers a part of one (`Range`) without the two headers.
2483
+ */
2484
+ cached: z10.boolean().optional()
2485
+ });
2486
+ var ObjectLinkSchema = z10.object({ url: z10.string(), expiresAt: z10.string() });
2487
+ var MEDIA_TYPE_RE = /^[\w.+-]+\/[\w.+-]+(?:\s*;[\x20-\x7e]*)?$/;
2488
+ var StartUploadRequest = z10.object({ key: z10.string(), size: z10.number().int().nonnegative(), contentType: z10.string().max(200).regex(MEDIA_TYPE_RE, "not a media type like image/png").optional(), overwrite: z10.boolean().optional() });
2489
+ var UploadPlanSchema = z10.discriminatedUnion("kind", [
2490
+ z10.object({ kind: z10.literal("single"), url: z10.string() }),
2491
+ z10.object({ kind: z10.literal("multipart"), uploadId: z10.string(), partSize: z10.number(), urls: z10.array(z10.string()) })
2492
+ ]);
2493
+ var CompleteUploadRequest = z10.object({
2494
+ key: z10.string(),
2495
+ uploadId: z10.string(),
2496
+ parts: z10.array(z10.object({ part: z10.number().int().positive(), etag: z10.string() })).min(1)
2497
+ });
2498
+ var AbortUploadRequest = z10.object({ key: z10.string(), uploadId: z10.string() });
2499
+ var DeleteObjectsRequest = z10.object({ keys: z10.array(z10.string()).max(OBJECT_LIST_MAX).optional(), prefixes: z10.array(z10.string()).max(DELETE_PREFIXES_MAX).optional() });
2500
+ var DeletedObjectsSchema = z10.object({
2501
+ deleted: z10.number(),
2502
+ more: z10.boolean(),
2503
+ errors: z10.array(z10.object({ key: z10.string(), message: z10.string() }))
2504
+ });
2505
+ var MoveObjectRequest = z10.object({ from: z10.string(), to: z10.string(), overwrite: z10.boolean().optional() });
2506
+ var CreateFolderRequest = z10.object({ prefix: z10.string() });
2338
2507
 
2339
2508
  // src/kvm.ts
2340
2509
  import { accessSync, constants, readFileSync, statSync } from "fs";
@@ -2570,6 +2739,13 @@ var ServerClient = class {
2570
2739
  createBoxBackup(name) {
2571
2740
  return this.call("POST", `/machines/${encodeURIComponent(name)}/backups`, BackupSchema);
2572
2741
  }
2742
+ /**
2743
+ * Remove a backup of any kind by its id (#111): gone from every listing at once, its storage freed a day
2744
+ * later. Works for a backup whose box, volume or database is gone too.
2745
+ */
2746
+ removeBackup(id) {
2747
+ return this.call("DELETE", `/backups/${encodeURIComponent(id)}`, z11.undefined());
2748
+ }
2573
2749
  /** A volume's backups (#168): the same as a box's, of the volume's disk. Newest first. */
2574
2750
  listVolumeBackups() {
2575
2751
  return this.call("GET", "/backups?kind=volume", z11.array(VolumeBackupSchema));
@@ -2657,6 +2833,10 @@ var ServerClient = class {
2657
2833
  balance(org) {
2658
2834
  return this.call("GET", "/billing/balance", BalanceSchema, void 0, org);
2659
2835
  }
2836
+ /** The control plane's price list (`GET /pricing`); a control plane only. */
2837
+ priceList() {
2838
+ return this.call("GET", "/pricing", PriceListSchema);
2839
+ }
2660
2840
  /** Redeem a promo code (#163) for the caller's slug, or for `--org`'s org, which they own; a control plane only. */
2661
2841
  redeem(code) {
2662
2842
  return this.call("POST", "/billing/redeem", RedeemResponseSchema, { code });
@@ -2778,6 +2958,24 @@ var ServerClient = class {
2778
2958
  growStorage(sizeGib) {
2779
2959
  return this.call("POST", "/storage/grow", ObjectStorageSchema, { sizeGib });
2780
2960
  }
2961
+ /** Backups of the slug's whole object storage (#186 slice 3), newest first. */
2962
+ storageBackups() {
2963
+ return this.call("GET", "/storage/backups", z11.array(StorageBackupSchema));
2964
+ }
2965
+ storageBackup(id) {
2966
+ return this.call("GET", `/storage/backups/${encodeURIComponent(id)}`, StorageBackupSchema);
2967
+ }
2968
+ /** Starts one; it runs in the background (`running`), `storageBackup` says how it ended. */
2969
+ createStorageBackup() {
2970
+ return this.call("POST", "/storage/backups", StorageBackupSchema);
2971
+ }
2972
+ /**
2973
+ * Every bucket and key goes back to the backup's; the storage restarts. Waits for the whole download
2974
+ * (the control plane gives its host 2 h) and for the storage to answer again, so 2 h 10 min.
2975
+ */
2976
+ restoreStorageBackup(id) {
2977
+ return this.call("POST", `/storage/backups/${encodeURIComponent(id)}/restore`, StorageRestoreSchema, {}, void 0, 2 * 36e5 + 10 * 6e4);
2978
+ }
2781
2979
  // ---- managed services (#173): the control plane's alone ----
2782
2980
  managedPath(kind, name, rest = "") {
2783
2981
  return `/managed/${encodeURIComponent(kind)}${name === void 0 ? "" : `/${encodeURIComponent(name)}`}${rest}`;
@@ -2789,8 +2987,9 @@ var ServerClient = class {
2789
2987
  listManaged(kind, opts = {}) {
2790
2988
  return this.call("GET", `${kind === void 0 ? "/managed" : this.managedPath(kind)}${allQuery(opts)}`, z11.array(ManagedSchema), void 0, opts.org);
2791
2989
  }
2990
+ /** From a backup (`fromBackup`) it waits for the restore too: the control plane gives its host 2 h for the download. */
2792
2991
  createManaged(kind, req) {
2793
- return this.call("POST", this.managedPath(kind), CreatedManagedSchema, req);
2992
+ return this.call("POST", this.managedPath(kind), CreatedManagedSchema, req, void 0, req.fromBackup === void 0 ? void 0 : 2 * 36e5 + 10 * 6e4);
2794
2993
  }
2795
2994
  /** With `health`, asked of the service itself. */
2796
2995
  getManaged(kind, name) {
@@ -2817,6 +3016,35 @@ var ServerClient = class {
2817
3016
  growManaged(kind, name, storageGib) {
2818
3017
  return this.call("POST", this.managedPath(kind, name, "/grow"), ManagedSchema, { storageGib });
2819
3018
  }
3019
+ /** A managed service's backups (#186): its storage's, by the volume backup engine. Every one of a kind, those of removed services too. */
3020
+ listManagedBackups(kind) {
3021
+ return this.call("GET", `/backups?managed=${encodeURIComponent(kind)}`, z11.array(ManagedBackupSchema));
3022
+ }
3023
+ managedBackups(kind, name) {
3024
+ return this.call("GET", this.managedPath(kind, name, "/backups"), z11.array(ManagedBackupSchema));
3025
+ }
3026
+ managedBackup(kind, name, id) {
3027
+ return this.call("GET", this.managedPath(kind, name, `/backups/${encodeURIComponent(id)}`), ManagedBackupSchema);
3028
+ }
3029
+ /** When the service is backed up on its own (#186 slice 4): nightly from its creation. */
3030
+ managedBackupSchedule(kind, name) {
3031
+ return this.call("GET", this.managedPath(kind, name, "/backup-schedule"), BackupScheduleSchema);
3032
+ }
3033
+ /** On or off, or another hour (UTC, which turns it on). */
3034
+ setManagedBackupSchedule(kind, name, change) {
3035
+ return this.call("PUT", this.managedPath(kind, name, "/backup-schedule"), BackupScheduleSchema, change);
3036
+ }
3037
+ /** Starts one; it runs in the background (`running`), `managedBackup` says how it ended. */
3038
+ createManagedBackup(kind, name) {
3039
+ return this.call("POST", this.managedPath(kind, name, "/backups"), ManagedBackupSchema);
3040
+ }
3041
+ /**
3042
+ * The service's data becomes the backup's; it restarts. Waits for the whole download (the control
3043
+ * plane gives its host 2 h) and for the password to be set again (up to 3 min more), so 2 h 10 min.
3044
+ */
3045
+ restoreManagedBackup(kind, name, id) {
3046
+ return this.call("POST", this.managedPath(kind, name, `/backups/${encodeURIComponent(id)}/restore`), ManagedSchema, {}, void 0, 2 * 36e5 + 10 * 6e4);
3047
+ }
2820
3048
  stopManaged(kind, name) {
2821
3049
  return this.call("POST", this.managedPath(kind, name, "/stop"), ManagedSchema);
2822
3050
  }
@@ -4144,19 +4372,76 @@ var hookCommand = new Command21("hook").description("URLs that wake a box when c
4144
4372
  for (const cmd of hookCommand.commands) cmd.option("--org <slug>", "act in this org (- for your personal boxes)");
4145
4373
 
4146
4374
  // src/commands/vm/backup/index.ts
4147
- import { Command as Command25 } from "commander";
4375
+ import { Command as Command27 } from "commander";
4148
4376
 
4149
4377
  // src/commands/vm/backup/create.ts
4150
- import { Command as Command22 } from "commander";
4378
+ import { Command as Command23 } from "commander";
4151
4379
 
4152
4380
  // src/commands/vm/backup/shared.ts
4153
4381
  import { setTimeout as sleep3 } from "timers/promises";
4382
+
4383
+ // src/commands/vm/usage.ts
4384
+ import { Command as Command22 } from "commander";
4385
+ var usageCommand = new Command22("usage").description("how long a box ran, slept and sat stopped, as vCPU-hours, RAM and disk GiB-hours (and cost, when the host prices them)").argument("<name>", "box name").option("--since <date>", "count from this date instead of the box's creation, e.g. 2026-10-01").option("--json", "print as JSON").action(async (name, opts, cmd) => {
4386
+ let since;
4387
+ if (opts.since !== void 0) {
4388
+ const t = Date.parse(opts.since);
4389
+ if (Number.isNaN(t)) throw new KvboxError(`--since ${opts.since}: not a date; write it like 2026-10-19 or 2026-10-19T08:00:00Z`);
4390
+ since = new Date(t).toISOString();
4391
+ }
4392
+ const client = await clientFor(cmd.optsWithGlobals());
4393
+ try {
4394
+ const u = await client.machineUsage(name, since);
4395
+ if (opts.json) json(u);
4396
+ else process.stdout.write(block(u));
4397
+ } finally {
4398
+ await client.close();
4399
+ }
4400
+ });
4401
+ var day = (iso) => iso.slice(0, 10);
4402
+ var SYMBOLS = { EUR: "\u20AC", USD: "$", GBP: "\xA3" };
4403
+ function money(amount, currency) {
4404
+ const sign = amount < 0 ? "-" : "";
4405
+ const n = Math.abs(amount).toFixed(2);
4406
+ const sym = SYMBOLS[currency.toUpperCase()];
4407
+ return sym === void 0 ? `${sign}${n} ${currency}` : `${sign}${sym}${n}`;
4408
+ }
4409
+ function block(u) {
4410
+ const estimated = u.estimatedStops === 0 ? "" : color.dim(` (${u.estimatedStops} stop time${u.estimatedStops === 1 ? "" : "s"} estimated)`);
4411
+ const rows2 = [
4412
+ ["name", boxName(u.name)],
4413
+ ["status", status(u.status)],
4414
+ ["window", `${day(u.window.from)} to ${day(u.window.to)}`],
4415
+ ["running", duration(u.seconds.running) + estimated],
4416
+ ["standby", duration(u.seconds.standby)],
4417
+ ["hibernated", duration(u.seconds.hibernated)],
4418
+ ["stopped", duration(u.seconds.stopped)],
4419
+ ["vcpu-h", hours(u.vcpuHours)],
4420
+ ["ram GiB-h", hours(u.ramGibHours)],
4421
+ ["disk GiB-h", hours(u.diskGibHours)]
4422
+ ];
4423
+ if (u.cost !== void 0) rows2.push(["cost", `${money(u.cost.amount, u.cost.currency)} ${color.dim("(estimated)")}`]);
4424
+ if (u.historyFrom !== null && u.historyFrom > u.window.from) {
4425
+ rows2.push(["history", color.dim(`from ${u.historyFrom.slice(0, 16).replace("T", " ")} UTC; the box is older, but its time before that was not recorded`)]);
4426
+ }
4427
+ const w = Math.max(...rows2.map(([k]) => k.length));
4428
+ return rows2.map(([k, v]) => `${" ".repeat(w - k.length)}${k}: ${v}`).join("\n") + "\n";
4429
+ }
4430
+
4431
+ // src/commands/vm/backup/shared.ts
4154
4432
  function requireCloud3(client) {
4155
4433
  if (client.target.kind !== "cloud") throw new KvboxError("backups need the kvbox cloud: kvbox login (this host's own socket has none)");
4156
4434
  }
4157
4435
  var POLL_MS = 2e3;
4158
4436
  var POLL_TRIES = 30;
4159
4437
  var WAIT_MS = 7 * 36e5;
4438
+ async function printCost(client, done, nightly = false) {
4439
+ const prices = await client.priceList().catch(() => void 0);
4440
+ if (!prices || prices.backup <= 0) return;
4441
+ const price = money(prices.backup, prices.currency);
4442
+ const included = nightly ? "; the nightly backup is included" : "";
4443
+ info(color.dim(done ? ` cost: ${price}${included}` : ` costs ${price} once it is ready, nothing if it fails${included}`));
4444
+ }
4160
4445
  async function untilSettled(ask, what, id, where, opts = {}) {
4161
4446
  const { pollMs = POLL_MS, tries = POLL_TRIES, waitMs = WAIT_MS } = opts;
4162
4447
  const lostTrack = (why) => new KvboxError(`stopped waiting for backup ${id} of ${what} (${why}); it may still be running: ${where}`);
@@ -4183,9 +4468,21 @@ function sizeLine(b) {
4183
4468
  const added = b.uploadedBytes === null ? "" : `, ${gb(b.uploadedBytes)} uploaded`;
4184
4469
  return `${data} of data${added}`;
4185
4470
  }
4471
+ async function removeListed(client, listed, nameOf, name, id, what, yes) {
4472
+ const backup = listed.find((b) => b.id === id && (nameOf(b) === name || `${b.owner}/${nameOf(b)}` === name));
4473
+ if (!backup) throw new NotFoundError(`backup ${id} of ${what}`);
4474
+ const question = `Remove backup ${backup.id} of ${what} (${age(backup.createdAt)} ago, ${backup.status === "ready" ? sizeLine(backup) : backup.status})? It cannot be restored after this.`;
4475
+ if (!await confirm(question, yes)) {
4476
+ info("cancelled");
4477
+ process.exitCode = 1;
4478
+ return;
4479
+ }
4480
+ await client.removeBackup(backup.id);
4481
+ info(`${color.green("\u2713")} backup ${backup.id} of ${what} removed`);
4482
+ }
4186
4483
 
4187
4484
  // src/commands/vm/backup/create.ts
4188
- 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) => {
4485
+ var createCommand2 = new Command23("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) => {
4189
4486
  const client = await clientFor(cmd.optsWithGlobals(), { autoStart: false });
4190
4487
  try {
4191
4488
  requireCloud3(client);
@@ -4197,6 +4494,7 @@ var createCommand2 = new Command22("create").description("back up a box's disk t
4197
4494
  else {
4198
4495
  info(`${color.green("\u2713")} backup ${started.id} of box ${color.bold(box2)} started; it runs in the background`);
4199
4496
  info(color.dim(` status: kvbox vm backup ls ${box2}`));
4497
+ await printCost(client, false);
4200
4498
  }
4201
4499
  return;
4202
4500
  }
@@ -4207,14 +4505,15 @@ var createCommand2 = new Command22("create").description("back up a box's disk t
4207
4505
  info(`${color.green("\u2713")} backup ${done.id} of box ${color.bold(box2)}: ${sizeLine(done)}`);
4208
4506
  if ((found.volumes?.length ?? 0) > 0) info(color.dim(` not included: volume${found.volumes.length > 1 ? "s" : ""} ${found.volumes.map((v) => v.name).join(", ")}`));
4209
4507
  info(color.dim(` restore with: kvbox vm backup restore ${box2} ${done.id}`));
4508
+ await printCost(client, true);
4210
4509
  } finally {
4211
4510
  await client.close();
4212
4511
  }
4213
4512
  });
4214
4513
 
4215
4514
  // src/commands/vm/backup/ls.ts
4216
- import { Command as Command23 } from "commander";
4217
- 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) => {
4515
+ import { Command as Command24 } from "commander";
4516
+ var lsCommand4 = new Command24("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) => {
4218
4517
  const client = await clientFor(cmd.optsWithGlobals(), { autoStart: false });
4219
4518
  try {
4220
4519
  requireCloud3(client);
@@ -4248,8 +4547,8 @@ var lsCommand4 = new Command23("ls").alias("list").description("list backups: ev
4248
4547
  });
4249
4548
 
4250
4549
  // src/commands/vm/backup/restore.ts
4251
- import { Command as Command24 } from "commander";
4252
- var restoreCommand = new Command24("restore").description("put a backup back: the box's disk becomes the backup's (a running box restarts)").argument("<box>", "box name").argument("<id>", "the backup's id (kvbox vm backup ls <box>)").option("-y, --yes", "do not ask for confirmation").option("--json", "print the box as JSON").action(async (name, id, opts, cmd) => {
4550
+ import { Command as Command25 } from "commander";
4551
+ var restoreCommand = new Command25("restore").description("put a backup back: the box's disk becomes the backup's (a running box restarts)").argument("<box>", "box name").argument("<id>", "the backup's id (kvbox vm backup ls <box>)").option("-y, --yes", "do not ask for confirmation").option("--json", "print the box as JSON").action(async (name, id, opts, cmd) => {
4253
4552
  const client = await clientFor(cmd.optsWithGlobals(), { autoStart: false });
4254
4553
  try {
4255
4554
  requireCloud3(client);
@@ -4272,13 +4571,25 @@ var restoreCommand = new Command24("restore").description("put a backup back: th
4272
4571
  }
4273
4572
  });
4274
4573
 
4574
+ // src/commands/vm/backup/rm.ts
4575
+ import { Command as Command26 } from "commander";
4576
+ var rmCommand3 = new Command26("rm").alias("remove").description("remove a backup for good (a box's that is gone too)").argument("<box>", "box name").argument("<id>", "the backup's id (kvbox vm backup ls <box>)").option("-y, --yes", "do not ask for confirmation").action(async (box2, id, opts, cmd) => {
4577
+ const client = await clientFor(cmd.optsWithGlobals(), { autoStart: false });
4578
+ try {
4579
+ requireCloud3(client);
4580
+ await removeListed(client, await client.listBackups(), (b) => b.box, box2, id, `box ${box2}`, opts.yes ?? false);
4581
+ } finally {
4582
+ await client.close();
4583
+ }
4584
+ });
4585
+
4275
4586
  // src/commands/vm/backup/index.ts
4276
- var backupCommand = new Command25("backup").description("back up a box's disk to the kvbox cloud, list backups, restore one").addCommand(createCommand2).addCommand(lsCommand4).addCommand(restoreCommand);
4587
+ var backupCommand = new Command27("backup").description("back up a box's disk to the kvbox cloud, list backups, restore or remove one").addCommand(createCommand2).addCommand(lsCommand4).addCommand(restoreCommand).addCommand(rmCommand3);
4277
4588
  for (const cmd of backupCommand.commands) cmd.option("--org <slug>", "act in this org (- for your personal boxes)");
4278
4589
 
4279
4590
  // src/commands/vm/rescale.ts
4280
- import { Command as Command26, Option as Option3 } from "commander";
4281
- var rescaleCommand = new Command26("rescale").description("change a box's vCPUs, memory or disk (e.g. --vcpu 4 --mem 16GB); a running box restarts").argument("<name>", "box name").addOption(new Option3("-s, --size <size>", "a preset to start from").choices(SIZE_NAMES)).option("--vcpu <n>", "number of vCPUs").option("--mem <size>", "memory, e.g. 16GB or 4096MB").option("--disk <size>", "disk size, e.g. 32GB (grow only)").option("--force", "skip the capacity guard when a running box grows").option("--json", "print the box as JSON").action(async (name, opts, cmd) => {
4591
+ import { Command as Command28, Option as Option3 } from "commander";
4592
+ var rescaleCommand = new Command28("rescale").description("change a box's vCPUs, memory or disk (e.g. --vcpu 4 --mem 16GB); a running box restarts").argument("<name>", "box name").addOption(new Option3("-s, --size <size>", "a preset to start from").choices(SIZE_NAMES)).option("--vcpu <n>", "number of vCPUs").option("--mem <size>", "memory, e.g. 16GB or 4096MB").option("--disk <size>", "disk size, e.g. 32GB (grow only)").option("--force", "skip the capacity guard when a running box grows").option("--json", "print the box as JSON").action(async (name, opts, cmd) => {
4282
4593
  const req = {
4283
4594
  ...opts.size !== void 0 ? { size: opts.size } : {},
4284
4595
  ...opts.vcpu !== void 0 ? { vcpu: parseCount(opts.vcpu) } : {},
@@ -4324,8 +4635,8 @@ function parseGib(flag, text2) {
4324
4635
  }
4325
4636
 
4326
4637
  // src/commands/vm/resume.ts
4327
- import { Command as Command27 } from "commander";
4328
- var resumeCommand = new Command27("resume").description("continue a box that is in standby (kvbox pause)").argument("<name>", "box name").option("--json", "print the box as JSON").action(async (name, opts, cmd) => {
4638
+ import { Command as Command29 } from "commander";
4639
+ var resumeCommand = new Command29("resume").description("continue a box that is in standby (kvbox pause)").argument("<name>", "box name").option("--json", "print the box as JSON").action(async (name, opts, cmd) => {
4329
4640
  const client = await clientFor(cmd.optsWithGlobals());
4330
4641
  try {
4331
4642
  const box2 = await spin(`resuming ${name}\u2026`, client.resumeMachine(name));
@@ -4337,8 +4648,8 @@ var resumeCommand = new Command27("resume").description("continue a box that is
4337
4648
  });
4338
4649
 
4339
4650
  // src/commands/vm/rm.ts
4340
- import { Command as Command28 } from "commander";
4341
- var rmCommand3 = new Command28("rm").description("destroy a box (its disk is deleted; snapshots are kept)").argument("<name>", "box name").option("-y, --yes", "do not ask for confirmation").action(async (name, opts, cmd) => {
4651
+ import { Command as Command30 } from "commander";
4652
+ var rmCommand4 = new Command30("rm").description("destroy a box (its disk is deleted; snapshots are kept)").argument("<name>", "box name").option("-y, --yes", "do not ask for confirmation").action(async (name, opts, cmd) => {
4342
4653
  const client = await clientFor(cmd.optsWithGlobals());
4343
4654
  try {
4344
4655
  const box2 = pickRef(await boxesFor(client, name), name, me(client));
@@ -4358,7 +4669,7 @@ var rmCommand3 = new Command28("rm").description("destroy a box (its disk is del
4358
4669
  });
4359
4670
 
4360
4671
  // src/commands/vm/set.ts
4361
- import { Command as Command29 } from "commander";
4672
+ import { Command as Command31 } from "commander";
4362
4673
 
4363
4674
  // src/swap.ts
4364
4675
  import { spawn as spawn3 } from "child_process";
@@ -4434,7 +4745,7 @@ function runSwap(ep, mib) {
4434
4745
  }
4435
4746
 
4436
4747
  // src/commands/vm/set.ts
4437
- var setCommand = new Command29("set").description("change a box's settings, e.g. --auto-hibernate 30m (off: never), --idle-check /home/kvbox/idle.sh, --swap 2G").argument("<name>", "box name").option("--auto-hibernate <duration>", "hibernate the box after this long without network traffic (30m, 4h, 1d; off: never)").option("--idle-check <script>", "a script in the box that exits 0 when it is idle, asked instead of network traffic (off: none)").option("--swap <size>", "a swap file on the box's disk for memory spikes such as a build (2G, 512M; off: none)").option("--json", "print the box as JSON").action(async (name, opts, cmd) => {
4748
+ var setCommand = new Command31("set").description("change a box's settings, e.g. --auto-hibernate 30m (off: never), --idle-check /home/kvbox/idle.sh, --swap 2G").argument("<name>", "box name").option("--auto-hibernate <duration>", "hibernate the box after this long without network traffic (30m, 4h, 1d; off: never)").option("--idle-check <script>", "a script in the box that exits 0 when it is idle, asked instead of network traffic (off: none)").option("--swap <size>", "a swap file on the box's disk for memory spikes such as a build (2G, 512M; off: none)").option("--json", "print the box as JSON").action(async (name, opts, cmd) => {
4438
4749
  if (opts.autoHibernate === void 0 && opts.idleCheck === void 0 && opts.swap === void 0) {
4439
4750
  throw new KvboxError("nothing to change: give --auto-hibernate, --idle-check or --swap");
4440
4751
  }
@@ -4503,8 +4814,8 @@ function parseIdleCheck(text2) {
4503
4814
  }
4504
4815
 
4505
4816
  // src/commands/vm/start.ts
4506
- import { Command as Command30 } from "commander";
4507
- var startCommand = new Command30("start").description("boot a stopped box again (same name, IP and disk)").argument("<name>", "box name").option("--force", "skip the capacity guard").option("--json", "print the box as JSON").action(async (name, opts, cmd) => {
4817
+ import { Command as Command32 } from "commander";
4818
+ var startCommand = new Command32("start").description("boot a stopped box again (same name, IP and disk)").argument("<name>", "box name").option("--force", "skip the capacity guard").option("--json", "print the box as JSON").action(async (name, opts, cmd) => {
4508
4819
  const client = await clientFor(cmd.optsWithGlobals());
4509
4820
  try {
4510
4821
  const box2 = await spin(`booting ${name}\u2026`, client.startMachine(name, opts.force ?? false));
@@ -4516,8 +4827,8 @@ var startCommand = new Command30("start").description("boot a stopped box again
4516
4827
  });
4517
4828
 
4518
4829
  // src/commands/vm/stop.ts
4519
- import { Command as Command31 } from "commander";
4520
- var stopCommand = new Command31("stop").description("shut a box down (its disk is kept; start it again with kvbox start)").argument("<name>", "box name").option("--json", "print the box as JSON").action(async (name, opts, cmd) => {
4830
+ import { Command as Command33 } from "commander";
4831
+ var stopCommand = new Command33("stop").description("shut a box down (its disk is kept; start it again with kvbox start)").argument("<name>", "box name").option("--json", "print the box as JSON").action(async (name, opts, cmd) => {
4521
4832
  const client = await clientFor(cmd.optsWithGlobals());
4522
4833
  try {
4523
4834
  const box2 = await spin(`shutting ${name} down\u2026`, client.stopMachine(name));
@@ -4529,8 +4840,8 @@ var stopCommand = new Command31("stop").description("shut a box down (its disk i
4529
4840
  });
4530
4841
 
4531
4842
  // src/commands/vm/top.ts
4532
- import { Command as Command32 } from "commander";
4533
- var topCommand = new Command32("top").description("load, memory and disk of each running box, as the box itself sees them").option("-a, --all", "every running box on the platform (platform admins only)").option("--json", "print as JSON").action(async (opts, cmd) => {
4843
+ import { Command as Command34 } from "commander";
4844
+ var topCommand = new Command34("top").description("load, memory and disk of each running box, as the box itself sees them").option("-a, --all", "every running box on the platform (platform admins only)").option("--json", "print as JSON").action(async (opts, cmd) => {
4534
4845
  const client = await clientFor(cmd.optsWithGlobals());
4535
4846
  try {
4536
4847
  const running = (await client.listMachines({ all: opts.all })).filter((b) => b.status === "running");
@@ -4590,8 +4901,8 @@ function topRows(entries, cloud) {
4590
4901
  }
4591
4902
 
4592
4903
  // src/commands/vm/unlink.ts
4593
- import { Command as Command33 } from "commander";
4594
- var unlinkCommand = new Command33("unlink").description("take a link away (kvbox vm link)").argument("<from>", "the box that connects").argument("<box>", "the box it reaches").requiredOption("-p, --port <port>", "the port in <box>").option("-y, --yes", "do not ask for confirmation").option("--json", "print the removed link as JSON").action(async (from, name, opts, cmd) => {
4904
+ import { Command as Command35 } from "commander";
4905
+ var unlinkCommand = new Command35("unlink").description("take a link away (kvbox vm link)").argument("<from>", "the box that connects").argument("<box>", "the box it reaches").requiredOption("-p, --port <port>", "the port in <box>").option("-y, --yes", "do not ask for confirmation").option("--json", "print the removed link as JSON").action(async (from, name, opts, cmd) => {
4595
4906
  const port = parseLinkPort(opts.port);
4596
4907
  if (!await confirm(`Cut box ${from} off from box ${name} port ${port}? Its open connections close too.`, opts.yes ?? false)) {
4597
4908
  info("cancelled");
@@ -4612,8 +4923,8 @@ var unlinkCommand = new Command33("unlink").description("take a link away (kvbox
4612
4923
  });
4613
4924
 
4614
4925
  // src/commands/vm/update.ts
4615
- import { Command as Command34 } from "commander";
4616
- var updateCommand = new Command34("update").description("move a box onto the current base image (its files stay; a running box restarts)").argument("<name>", "box name").option("--json", "print the box as JSON").action(async (name, opts, cmd) => {
4926
+ import { Command as Command36 } from "commander";
4927
+ var updateCommand = new Command36("update").description("move a box onto the current base image (its files stay; a running box restarts)").argument("<name>", "box name").option("--json", "print the box as JSON").action(async (name, opts, cmd) => {
4617
4928
  const client = await clientFor(cmd.optsWithGlobals());
4618
4929
  try {
4619
4930
  const before = pickRef(await boxesFor(client, name), name, me(client));
@@ -4634,57 +4945,9 @@ var updateCommand = new Command34("update").description("move a box onto the cur
4634
4945
  }
4635
4946
  });
4636
4947
 
4637
- // src/commands/vm/usage.ts
4638
- import { Command as Command35 } from "commander";
4639
- var usageCommand = new Command35("usage").description("how long a box ran, slept and sat stopped, as vCPU-hours, RAM and disk GiB-hours (and cost, when the host prices them)").argument("<name>", "box name").option("--since <date>", "count from this date instead of the box's creation, e.g. 2026-10-01").option("--json", "print as JSON").action(async (name, opts, cmd) => {
4640
- let since;
4641
- if (opts.since !== void 0) {
4642
- const t = Date.parse(opts.since);
4643
- if (Number.isNaN(t)) throw new KvboxError(`--since ${opts.since}: not a date; write it like 2026-10-19 or 2026-10-19T08:00:00Z`);
4644
- since = new Date(t).toISOString();
4645
- }
4646
- const client = await clientFor(cmd.optsWithGlobals());
4647
- try {
4648
- const u = await client.machineUsage(name, since);
4649
- if (opts.json) json(u);
4650
- else process.stdout.write(block(u));
4651
- } finally {
4652
- await client.close();
4653
- }
4654
- });
4655
- var day = (iso) => iso.slice(0, 10);
4656
- var SYMBOLS = { EUR: "\u20AC", USD: "$", GBP: "\xA3" };
4657
- function money(amount, currency) {
4658
- const sign = amount < 0 ? "-" : "";
4659
- const n = Math.abs(amount).toFixed(2);
4660
- const sym = SYMBOLS[currency.toUpperCase()];
4661
- return sym === void 0 ? `${sign}${n} ${currency}` : `${sign}${sym}${n}`;
4662
- }
4663
- function block(u) {
4664
- const estimated = u.estimatedStops === 0 ? "" : color.dim(` (${u.estimatedStops} stop time${u.estimatedStops === 1 ? "" : "s"} estimated)`);
4665
- const rows2 = [
4666
- ["name", boxName(u.name)],
4667
- ["status", status(u.status)],
4668
- ["window", `${day(u.window.from)} to ${day(u.window.to)}`],
4669
- ["running", duration(u.seconds.running) + estimated],
4670
- ["standby", duration(u.seconds.standby)],
4671
- ["hibernated", duration(u.seconds.hibernated)],
4672
- ["stopped", duration(u.seconds.stopped)],
4673
- ["vcpu-h", hours(u.vcpuHours)],
4674
- ["ram GiB-h", hours(u.ramGibHours)],
4675
- ["disk GiB-h", hours(u.diskGibHours)]
4676
- ];
4677
- if (u.cost !== void 0) rows2.push(["cost", `${money(u.cost.amount, u.cost.currency)} ${color.dim("(estimated)")}`]);
4678
- if (u.historyFrom !== null && u.historyFrom > u.window.from) {
4679
- rows2.push(["history", color.dim(`from ${u.historyFrom.slice(0, 16).replace("T", " ")} UTC; the box is older, but its time before that was not recorded`)]);
4680
- }
4681
- const w = Math.max(...rows2.map(([k]) => k.length));
4682
- return rows2.map(([k, v]) => `${" ".repeat(w - k.length)}${k}: ${v}`).join("\n") + "\n";
4683
- }
4684
-
4685
4948
  // src/commands/vm/wake.ts
4686
- import { Command as Command36 } from "commander";
4687
- var wakeCommand = new Command36("wake").description("continue a hibernated box where it left off (same name, IP and disk)").argument("<name>", "box name").option("--force", "skip the capacity guard").option("--json", "print the box as JSON").action(async (name, opts, cmd) => {
4949
+ import { Command as Command37 } from "commander";
4950
+ var wakeCommand = new Command37("wake").description("continue a hibernated box where it left off (same name, IP and disk)").argument("<name>", "box name").option("--force", "skip the capacity guard").option("--json", "print the box as JSON").action(async (name, opts, cmd) => {
4688
4951
  const client = await clientFor(cmd.optsWithGlobals());
4689
4952
  try {
4690
4953
  const box2 = await spin(`waking ${name} (loading its memory from disk)\u2026`, client.wakeMachine(name, opts.force ?? false));
@@ -4696,16 +4959,16 @@ var wakeCommand = new Command36("wake").description("continue a hibernated box w
4696
4959
  });
4697
4960
 
4698
4961
  // src/commands/vm/index.ts
4699
- var vmCommand = new Command37("vm").enablePositionalOptions().description("manage boxes (each one is a Firecracker microVM)").addCommand(newCommand).addCommand(forkCommand).addCommand(lsCommand).addCommand(getCommand).addCommand(connectCommand).addCommand(execCommand).addCommand(stopCommand).addCommand(startCommand).addCommand(pauseCommand).addCommand(resumeCommand).addCommand(hibernateCommand).addCommand(wakeCommand).addCommand(updateCommand).addCommand(rescaleCommand).addCommand(setCommand).addCommand(usageCommand).addCommand(topCommand).addCommand(proxyCommand).addCommand(hookCommand).addCommand(backupCommand).addCommand(linkCommand).addCommand(unlinkCommand).addCommand(linksCommand).addCommand(rmCommand3);
4962
+ var vmCommand = new Command38("vm").enablePositionalOptions().description("manage boxes (each one is a Firecracker microVM)").addCommand(newCommand).addCommand(forkCommand).addCommand(lsCommand).addCommand(getCommand).addCommand(connectCommand).addCommand(execCommand).addCommand(stopCommand).addCommand(startCommand).addCommand(pauseCommand).addCommand(resumeCommand).addCommand(hibernateCommand).addCommand(wakeCommand).addCommand(updateCommand).addCommand(rescaleCommand).addCommand(setCommand).addCommand(usageCommand).addCommand(topCommand).addCommand(proxyCommand).addCommand(hookCommand).addCommand(backupCommand).addCommand(linkCommand).addCommand(unlinkCommand).addCommand(linksCommand).addCommand(rmCommand4);
4700
4963
  for (const cmd of vmCommand.commands) if (cmd !== proxyCommand && cmd !== hookCommand && cmd !== backupCommand) cmd.option("--org <slug>", "act in this org (- for your personal boxes)");
4701
- var vmAliases = [newCommand, lsCommand, getCommand, connectCommand, execCommand, stopCommand, startCommand, pauseCommand, resumeCommand, hibernateCommand, wakeCommand, rmCommand3, claimCommand];
4964
+ var vmAliases = [newCommand, lsCommand, getCommand, connectCommand, execCommand, stopCommand, startCommand, pauseCommand, resumeCommand, hibernateCommand, wakeCommand, rmCommand4, claimCommand];
4702
4965
 
4703
4966
  // src/commands/login.ts
4704
4967
  import { hostname as osHostname2 } from "os";
4705
4968
  import { createInterface as createInterface2 } from "readline/promises";
4706
4969
  import { setTimeout as sleep4 } from "timers/promises";
4707
4970
  import { Writable } from "stream";
4708
- import { Command as Command38 } from "commander";
4971
+ import { Command as Command39 } from "commander";
4709
4972
 
4710
4973
  // src/browser.ts
4711
4974
  import { spawn as spawn4 } from "child_process";
@@ -4742,7 +5005,7 @@ function openBrowser(url) {
4742
5005
  }
4743
5006
 
4744
5007
  // src/commands/login.ts
4745
- var loginCommand = new Command38("login").description("log in to the kvbox cloud (or your own control plane) and target it from now on").argument("[url]", `control plane URL (default: ${DEFAULT_CLOUD_URL})`).option("--password", "log in with email and password instead of approving a code in the web app").option("-e, --email <email>", "account email, for a password login (prompted otherwise)").option("--password-stdin", "read the password from the first line of stdin (for scripts)").action(async (urlArg, opts) => {
5008
+ var loginCommand = new Command39("login").description("log in to the kvbox cloud (or your own control plane) and target it from now on").argument("[url]", `control plane URL (default: ${DEFAULT_CLOUD_URL})`).option("--password", "log in with email and password instead of approving a code in the web app").option("-e, --email <email>", "account email, for a password login (prompted otherwise)").option("--password-stdin", "read the password from the first line of stdin (for scripts)").action(async (urlArg, opts) => {
4746
5009
  const url = normalizeUrl(urlArg ?? DEFAULT_CLOUD_URL);
4747
5010
  const byPassword = opts.password === true || opts.passwordStdin === true || opts.email !== void 0;
4748
5011
  const session = byPassword ? await runLogin(url, await readCredentials(opts), paths()) : await runDeviceLogin(url, paths());
@@ -4852,8 +5115,8 @@ async function firstLine(stream) {
4852
5115
  }
4853
5116
 
4854
5117
  // src/commands/logout.ts
4855
- import { Command as Command39 } from "commander";
4856
- var logoutCommand = new Command39("logout").description("log out of the control plane; commands target this machine's kvbox-server again").action(async () => {
5118
+ import { Command as Command40 } from "commander";
5119
+ var logoutCommand = new Command40("logout").description("log out of the control plane; commands target this machine's kvbox-server again").action(async () => {
4857
5120
  const p = paths();
4858
5121
  const session = await readSession(p).catch(() => null);
4859
5122
  switch (await runLogout(p)) {
@@ -4891,8 +5154,8 @@ async function runLogout(p = paths()) {
4891
5154
  }
4892
5155
 
4893
5156
  // src/commands/whoami.ts
4894
- import { Command as Command40 } from "commander";
4895
- var whoamiCommand = new Command40("whoami").description("show which account and control plane commands target (or local mode)").option("--json", "print as JSON").action(async (opts, cmd) => {
5157
+ import { Command as Command41 } from "commander";
5158
+ var whoamiCommand = new Command41("whoami").description("show which account and control plane commands target (or local mode)").option("--json", "print as JSON").action(async (opts, cmd) => {
4896
5159
  if (!cmd.optsWithGlobals().local && envLogin()) {
4897
5160
  const target = await resolveTarget({});
4898
5161
  if (target.kind !== "cloud") return;
@@ -4917,10 +5180,10 @@ function describeSession(session) {
4917
5180
  }
4918
5181
 
4919
5182
  // src/commands/key/index.ts
4920
- import { Command as Command44 } from "commander";
5183
+ import { Command as Command45 } from "commander";
4921
5184
 
4922
5185
  // src/commands/key/create.ts
4923
- import { Command as Command41 } from "commander";
5186
+ import { Command as Command42 } from "commander";
4924
5187
 
4925
5188
  // src/commands/key/shared.ts
4926
5189
  async function keyClient(cmd) {
@@ -4957,7 +5220,7 @@ function expiryText(expiresAt, now = Date.now()) {
4957
5220
  }
4958
5221
 
4959
5222
  // src/commands/key/create.ts
4960
- var createCommand3 = new Command41("create").description("make an API key for a program: CI, an agent, the SDK (the key is shown once)").argument("<name>", "what to call the key: lowercase letters, digits, '.', '_' or '-'").option("--expires <when>", `when it stops working: a duration (30d, 12h; m is minutes), a day (2027-01-31), or never; ${DEFAULT_API_KEY_DAYS}d by default`).option("--json", "print as JSON").action(async (name, opts, cmd) => {
5223
+ var createCommand3 = new Command42("create").description("make an API key for a program: CI, an agent, the SDK (the key is shown once)").argument("<name>", "what to call the key: lowercase letters, digits, '.', '_' or '-'").option("--expires <when>", `when it stops working: a duration (30d, 12h; m is minutes), a day (2027-01-31), or never; ${DEFAULT_API_KEY_DAYS}d by default`).option("--json", "print as JSON").action(async (name, opts, cmd) => {
4961
5224
  const expiresAt = opts.expires === void 0 ? void 0 : parseExpires(opts.expires);
4962
5225
  const client = await keyClient(cmd);
4963
5226
  try {
@@ -4975,8 +5238,8 @@ var createCommand3 = new Command41("create").description("make an API key for a
4975
5238
  });
4976
5239
 
4977
5240
  // src/commands/key/ls.ts
4978
- import { Command as Command42 } from "commander";
4979
- var lsCommand5 = new Command42("ls").alias("list").description("list your API keys (never the keys themselves)").option("--json", "print as JSON").action(async (opts, cmd) => {
5241
+ import { Command as Command43 } from "commander";
5242
+ var lsCommand5 = new Command43("ls").alias("list").description("list your API keys (never the keys themselves)").option("--json", "print as JSON").action(async (opts, cmd) => {
4980
5243
  const client = await keyClient(cmd);
4981
5244
  try {
4982
5245
  const keys = await client.listApiKeys();
@@ -4995,8 +5258,8 @@ var lsCommand5 = new Command42("ls").alias("list").description("list your API ke
4995
5258
  });
4996
5259
 
4997
5260
  // src/commands/key/rm.ts
4998
- import { Command as Command43 } from "commander";
4999
- var rmCommand4 = new Command43("rm").alias("remove").description("remove an API key: whatever uses it stops working").argument("<name>", "the key's name (kvbox key ls)").option("-y, --yes", "do not ask for confirmation").action(async (name, opts, cmd) => {
5261
+ import { Command as Command44 } from "commander";
5262
+ var rmCommand5 = new Command44("rm").alias("remove").description("remove an API key: whatever uses it stops working").argument("<name>", "the key's name (kvbox key ls)").option("-y, --yes", "do not ask for confirmation").action(async (name, opts, cmd) => {
5000
5263
  const client = await keyClient(cmd);
5001
5264
  try {
5002
5265
  if (!await confirm(`Remove API key ${name}? Whatever uses it stops working.`, opts.yes ?? false)) {
@@ -5012,14 +5275,14 @@ var rmCommand4 = new Command43("rm").alias("remove").description("remove an API
5012
5275
  });
5013
5276
 
5014
5277
  // src/commands/key/index.ts
5015
- var keyCommand = new Command44("key").aliases(["keys"]).description("API keys: named tokens a program (CI, an agent, the SDK) uses as KVBOX_TOKEN in place of a login").addCommand(createCommand3).addCommand(lsCommand5).addCommand(rmCommand4);
5278
+ var keyCommand = new Command45("key").aliases(["keys"]).description("API keys: named tokens a program (CI, an agent, the SDK) uses as KVBOX_TOKEN in place of a login").addCommand(createCommand3).addCommand(lsCommand5).addCommand(rmCommand5);
5016
5279
 
5017
5280
  // src/commands/snapshots/index.ts
5018
- import { Command as Command48 } from "commander";
5281
+ import { Command as Command49 } from "commander";
5019
5282
 
5020
5283
  // src/commands/snapshots/ls.ts
5021
- import { Command as Command45 } from "commander";
5022
- var lsCommand6 = new Command45("ls").description("list snapshots (yours and your orgs'; --org <slug> for one org)").option("-a, --all", "every snapshot on the platform (platform admins only)").option("--json", "print as JSON").action(async (opts, cmd) => {
5284
+ import { Command as Command46 } from "commander";
5285
+ var lsCommand6 = new Command46("ls").description("list snapshots (yours and your orgs'; --org <slug> for one org)").option("-a, --all", "every snapshot on the platform (platform admins only)").option("--json", "print as JSON").action(async (opts, cmd) => {
5023
5286
  const client = await clientFor(cmd.optsWithGlobals());
5024
5287
  try {
5025
5288
  const cloud = client.target.kind === "cloud";
@@ -5050,8 +5313,8 @@ var lsCommand6 = new Command45("ls").description("list snapshots (yours and your
5050
5313
  });
5051
5314
 
5052
5315
  // src/commands/snapshots/new.ts
5053
- import { Command as Command46 } from "commander";
5054
- var newCommand2 = new Command46("new").description("freeze a running box (memory + disk) into a snapshot; the box keeps running").argument("<box>", "box name").argument("<name>", "snapshot name").option("--replace", "retake a snapshot that exists under this name; the old one stays until the new one is complete").option("--json", "print the snapshot as JSON").action(async (box2, name, opts, cmd) => {
5316
+ import { Command as Command47 } from "commander";
5317
+ var newCommand2 = new Command47("new").description("freeze a running box (memory + disk) into a snapshot; the box keeps running").argument("<box>", "box name").argument("<name>", "snapshot name").option("--replace", "retake a snapshot that exists under this name; the old one stays until the new one is complete").option("--json", "print the snapshot as JSON").action(async (box2, name, opts, cmd) => {
5055
5318
  const client = await clientFor(cmd.optsWithGlobals());
5056
5319
  try {
5057
5320
  const req = { box: box2, name, ...opts.replace ? { replace: true } : {} };
@@ -5064,8 +5327,8 @@ var newCommand2 = new Command46("new").description("freeze a running box (memory
5064
5327
  });
5065
5328
 
5066
5329
  // src/commands/snapshots/rm.ts
5067
- import { Command as Command47 } from "commander";
5068
- var rmCommand5 = new Command47("rm").description("delete a snapshot (boxes made from it are not affected)").argument("<name>", "snapshot name").option("-y, --yes", "do not ask for confirmation").action(async (name, opts, cmd) => {
5330
+ import { Command as Command48 } from "commander";
5331
+ var rmCommand6 = new Command48("rm").description("delete a snapshot (boxes made from it are not affected)").argument("<name>", "snapshot name").option("-y, --yes", "do not ask for confirmation").action(async (name, opts, cmd) => {
5069
5332
  if (!await confirm(`Delete snapshot ${name}?`, opts.yes ?? false)) {
5070
5333
  info("cancelled");
5071
5334
  process.exitCode = 1;
@@ -5081,14 +5344,14 @@ var rmCommand5 = new Command47("rm").description("delete a snapshot (boxes made
5081
5344
  });
5082
5345
 
5083
5346
  // src/commands/snapshots/index.ts
5084
- var snapshotsCommand = new Command48("snapshots").aliases(["snapshot", "snap"]).description("freeze running boxes into snapshots and manage them").addCommand(newCommand2).addCommand(lsCommand6).addCommand(rmCommand5);
5347
+ var snapshotsCommand = new Command49("snapshots").aliases(["snapshot", "snap"]).description("freeze running boxes into snapshots and manage them").addCommand(newCommand2).addCommand(lsCommand6).addCommand(rmCommand6);
5085
5348
  for (const cmd of snapshotsCommand.commands) cmd.option("--org <slug>", "act in this org (- for your personal boxes)");
5086
5349
 
5087
5350
  // src/commands/org/index.ts
5088
- import { Command as Command54 } from "commander";
5351
+ import { Command as Command55 } from "commander";
5089
5352
 
5090
5353
  // src/commands/org/ls.ts
5091
- import { Command as Command49 } from "commander";
5354
+ import { Command as Command50 } from "commander";
5092
5355
 
5093
5356
  // src/commands/org/context.ts
5094
5357
  var NOT_LOGGED_IN2 = "orgs live on the control plane: kvbox login first";
@@ -5108,7 +5371,7 @@ function orgFor(opts, target) {
5108
5371
  }
5109
5372
 
5110
5373
  // src/commands/org/ls.ts
5111
- var lsCommand7 = new Command49("ls").description("list the orgs you belong to and your role in each").option("--json", "print as JSON").action(async (opts, cmd) => {
5374
+ var lsCommand7 = new Command50("ls").description("list the orgs you belong to and your role in each").option("--json", "print as JSON").action(async (opts, cmd) => {
5112
5375
  const client = await cloudClientFor(cmd.optsWithGlobals());
5113
5376
  try {
5114
5377
  const orgs = await client.listOrgs();
@@ -5130,8 +5393,8 @@ function orgRows(orgs) {
5130
5393
  }
5131
5394
 
5132
5395
  // src/commands/org/members.ts
5133
- import { Command as Command50, Option as Option4 } from "commander";
5134
- var lsCommand8 = new Command50("ls").description("list an org's members and their roles").option("-o, --org <slug>", "the org (or --org before the command)").option("--json", "print as JSON").action(async (opts, cmd) => {
5396
+ import { Command as Command51, Option as Option4 } from "commander";
5397
+ var lsCommand8 = new Command51("ls").description("list an org's members and their roles").option("-o, --org <slug>", "the org (or --org before the command)").option("--json", "print as JSON").action(async (opts, cmd) => {
5135
5398
  const client = await cloudClientFor(cmd.optsWithGlobals());
5136
5399
  try {
5137
5400
  const org = await client.getOrg(orgFor(opts, client.target));
@@ -5145,7 +5408,7 @@ var lsCommand8 = new Command50("ls").description("list an org's members and thei
5145
5408
  await client.close();
5146
5409
  }
5147
5410
  });
5148
- var addCommand2 = new Command50("add").description("add a user to an org (admins and owners; only an owner can add an owner)").argument("<user>", "their username").addOption(new Option4("-r, --role <role>", "their role").choices(ORG_ROLES).default("member")).option("-o, --org <slug>", "the org (or --org before the command)").action(async (user, opts, cmd) => {
5411
+ var addCommand2 = new Command51("add").description("add a user to an org (admins and owners; only an owner can add an owner)").argument("<user>", "their username").addOption(new Option4("-r, --role <role>", "their role").choices(ORG_ROLES).default("member")).option("-o, --org <slug>", "the org (or --org before the command)").action(async (user, opts, cmd) => {
5149
5412
  const client = await cloudClientFor(cmd.optsWithGlobals());
5150
5413
  try {
5151
5414
  const slug = orgFor(opts, client.target);
@@ -5155,7 +5418,7 @@ var addCommand2 = new Command50("add").description("add a user to an org (admins
5155
5418
  await client.close();
5156
5419
  }
5157
5420
  });
5158
- var rmCommand6 = new Command50("rm").description("remove a member (or leave: remove yourself)").argument("<user>", "their username").option("-o, --org <slug>", "the org (or --org before the command)").option("-y, --yes", "do not ask for confirmation").action(async (user, opts, cmd) => {
5421
+ var rmCommand7 = new Command51("rm").description("remove a member (or leave: remove yourself)").argument("<user>", "their username").option("-o, --org <slug>", "the org (or --org before the command)").option("-y, --yes", "do not ask for confirmation").action(async (user, opts, cmd) => {
5159
5422
  const client = await cloudClientFor(cmd.optsWithGlobals());
5160
5423
  try {
5161
5424
  const slug = orgFor(opts, client.target);
@@ -5171,11 +5434,11 @@ var rmCommand6 = new Command50("rm").description("remove a member (or leave: rem
5171
5434
  await client.close();
5172
5435
  }
5173
5436
  });
5174
- var membersCommand = new Command50("members").description("who is in an org and what they may do").addCommand(lsCommand8).addCommand(addCommand2).addCommand(rmCommand6);
5437
+ var membersCommand = new Command51("members").description("who is in an org and what they may do").addCommand(lsCommand8).addCommand(addCommand2).addCommand(rmCommand7);
5175
5438
 
5176
5439
  // src/commands/org/new.ts
5177
- import { Command as Command51 } from "commander";
5178
- var newCommand3 = new Command51("new").description("create an org; you become its owner (the slug is permanent, the name is not)").argument("<slug>", "the org's slug: lowercase, like a username (acme)").option("-n, --name <name>", "display name (default: the slug)").option("--json", "print the org as JSON").action(async (slug, opts, cmd) => {
5440
+ import { Command as Command52 } from "commander";
5441
+ var newCommand3 = new Command52("new").description("create an org; you become its owner (the slug is permanent, the name is not)").argument("<slug>", "the org's slug: lowercase, like a username (acme)").option("-n, --name <name>", "display name (default: the slug)").option("--json", "print the org as JSON").action(async (slug, opts, cmd) => {
5179
5442
  const client = await cloudClientFor(cmd.optsWithGlobals());
5180
5443
  try {
5181
5444
  const org = await client.createOrg({ slug, name: opts.name ?? slug });
@@ -5191,8 +5454,8 @@ var newCommand3 = new Command51("new").description("create an org; you become it
5191
5454
  });
5192
5455
 
5193
5456
  // src/commands/org/rm.ts
5194
- import { Command as Command52 } from "commander";
5195
- var rmCommand7 = new Command52("rm").description("delete an org (owners only; remove its boxes and snapshots first)").argument("<slug>", "the org").option("-y, --yes", "do not ask for confirmation").action(async (slug, opts, cmd) => {
5457
+ import { Command as Command53 } from "commander";
5458
+ var rmCommand8 = new Command53("rm").description("delete an org (owners only; remove its boxes and snapshots first)").argument("<slug>", "the org").option("-y, --yes", "do not ask for confirmation").action(async (slug, opts, cmd) => {
5196
5459
  if (!await confirm(`Delete org ${slug}? Its members lose access; its slug stays taken.`, opts.yes ?? false)) {
5197
5460
  info("cancelled");
5198
5461
  process.exitCode = 1;
@@ -5208,8 +5471,8 @@ var rmCommand7 = new Command52("rm").description("delete an org (owners only; re
5208
5471
  });
5209
5472
 
5210
5473
  // src/commands/org/role.ts
5211
- import { Argument, Command as Command53 } from "commander";
5212
- var roleCommand = new Command53("role").description("change a member's role (owners only)").argument("<user>", "their username").addArgument(new Argument("<role>", "owner, admin or member").choices(ORG_ROLES)).option("-o, --org <slug>", "the org (default: the current context)").action(async (user, role, opts, cmd) => {
5474
+ import { Argument, Command as Command54 } from "commander";
5475
+ var roleCommand = new Command54("role").description("change a member's role (owners only)").argument("<user>", "their username").addArgument(new Argument("<role>", "owner, admin or member").choices(ORG_ROLES)).option("-o, --org <slug>", "the org (default: the current context)").action(async (user, role, opts, cmd) => {
5213
5476
  const client = await cloudClientFor(cmd.optsWithGlobals());
5214
5477
  try {
5215
5478
  const slug = orgFor(opts, client.target);
@@ -5221,11 +5484,11 @@ var roleCommand = new Command53("role").description("change a member's role (own
5221
5484
  });
5222
5485
 
5223
5486
  // src/commands/org/index.ts
5224
- var orgCommand = new Command54("org").description("orgs: shared slugs that own boxes, with owners, admins and members").addCommand(lsCommand7).addCommand(newCommand3).addCommand(membersCommand).addCommand(roleCommand).addCommand(rmCommand7);
5487
+ var orgCommand = new Command55("org").description("orgs: shared slugs that own boxes, with owners, admins and members").addCommand(lsCommand7).addCommand(newCommand3).addCommand(membersCommand).addCommand(roleCommand).addCommand(rmCommand8);
5225
5488
 
5226
5489
  // src/commands/usage.ts
5227
- import { Command as Command55 } from "commander";
5228
- var usageCommand2 = new Command55("usage").description("what your boxes and volumes used this month (or --since/--until): running time, vCPU-h, RAM and disk GiB-h, cost").option("--since <date>", "count from this date, e.g. 2026-10-01 (default: the 1st of this month)").option("--until <date>", "count up to this date (default: now)").option("--org <slug>", "one org's boxes only").option("-a, --all", "every box on the platform (platform admins only)").option("--by-user", "one line per user who made the boxes (e.g. who spent what in --org)").option("--json", "print as JSON").action(async (opts, cmd) => {
5490
+ import { Command as Command56 } from "commander";
5491
+ var usageCommand2 = new Command56("usage").description("what your boxes and volumes used this month (or --since/--until): running time, vCPU-h, RAM and disk GiB-h, cost").option("--since <date>", "count from this date, e.g. 2026-10-01 (default: the 1st of this month)").option("--until <date>", "count up to this date (default: now)").option("--org <slug>", "one org's boxes only").option("-a, --all", "every box on the platform (platform admins only)").option("--by-user", "one line per user who made the boxes (e.g. who spent what in --org)").option("--json", "print as JSON").action(async (opts, cmd) => {
5229
5492
  for (const [name, value] of [
5230
5493
  ["since", opts.since],
5231
5494
  ["until", opts.until]
@@ -5247,7 +5510,8 @@ var usageCommand2 = new Command55("usage").description("what your boxes and volu
5247
5510
  const volumes = report.volumes ?? [];
5248
5511
  const storage = report.storage ?? [];
5249
5512
  const cron = report.cron ?? [];
5250
- if (report.boxes.length === 0 && volumes.length === 0 && storage.length === 0 && cron.length === 0) info("no usage in this window");
5513
+ const backups = report.backups ?? [];
5514
+ if (report.boxes.length === 0 && volumes.length === 0 && storage.length === 0 && cron.length === 0 && backups.length === 0) info("no usage in this window");
5251
5515
  else if (report.boxes.length > 0) table(perUser ? userRows(perUser) : usageRows(report, cloud));
5252
5516
  if (volumes.length > 0) {
5253
5517
  info(volumes.length === 1 ? "1 volume" : `${volumes.length} volumes`);
@@ -5261,8 +5525,13 @@ var usageCommand2 = new Command55("usage").description("what your boxes and volu
5261
5525
  info(cron.length === 1 ? "1 cron service" : `${cron.length} cron services`);
5262
5526
  table(cronRows(report, cloud));
5263
5527
  }
5264
- if ((volumes.length > 0 || storage.length > 0 || cron.length > 0) && report.totals.cost !== void 0) {
5265
- const what = ["boxes", ...volumes.length > 0 ? ["volumes"] : [], ...storage.length > 0 ? ["object storage"] : [], ...cron.length > 0 ? ["cron services"] : []];
5528
+ if (backups.length > 0) {
5529
+ const taken = backups.reduce((n, b) => n + b.count, 0);
5530
+ info(taken === 1 ? "1 backup taken by hand" : `${taken} backups taken by hand`);
5531
+ table(backupRows(report, cloud));
5532
+ }
5533
+ if ((volumes.length > 0 || storage.length > 0 || cron.length > 0 || backups.length > 0) && report.totals.cost !== void 0) {
5534
+ const what = ["boxes", ...volumes.length > 0 ? ["volumes"] : [], ...storage.length > 0 ? ["object storage"] : [], ...cron.length > 0 ? ["cron services"] : [], ...backups.length > 0 ? ["backups"] : []];
5266
5535
  info(`total: ${money(report.totals.cost.amount, report.totals.cost.currency)} ${color.dim(`(${what.slice(0, -1).join(", ")} and ${what.at(-1)}, estimated)`)}`);
5267
5536
  }
5268
5537
  if (cloud) {
@@ -5365,6 +5634,15 @@ function cronRows(report, cloud) {
5365
5634
  ...priced ? { cost: money(s.cost?.amount ?? 0, currency) } : {}
5366
5635
  }));
5367
5636
  }
5637
+ function backupRows(report, cloud) {
5638
+ return (report.backups ?? []).map((b) => ({
5639
+ name: b.kind === "storage" ? "object storage" : b.name,
5640
+ kind: b.kind,
5641
+ ...cloud ? { owner: ownerCell2(b, cloud.me) } : {},
5642
+ backups: String(b.count),
5643
+ cost: money(b.cost.amount, b.cost.currency)
5644
+ }));
5645
+ }
5368
5646
  function byUser(report) {
5369
5647
  const groups = /* @__PURE__ */ new Map();
5370
5648
  for (const b of report.boxes) {
@@ -5381,7 +5659,7 @@ function byUser(report) {
5381
5659
  return u;
5382
5660
  });
5383
5661
  users.sort((a, b) => a.user === null ? 1 : b.user === null ? -1 : a.user.localeCompare(b.user));
5384
- return { window: report.window, users, ...report.volumes === void 0 ? {} : { volumes: report.volumes }, ...report.storage === void 0 ? {} : { storage: report.storage }, ...report.cron === void 0 ? {} : { cron: report.cron }, totals: report.totals };
5662
+ return { window: report.window, users, ...report.volumes === void 0 ? {} : { volumes: report.volumes }, ...report.storage === void 0 ? {} : { storage: report.storage }, ...report.cron === void 0 ? {} : { cron: report.cron }, ...report.backups === void 0 ? {} : { backups: report.backups }, totals: report.totals };
5385
5663
  }
5386
5664
  function userRows(r) {
5387
5665
  const priced = r.totals.cost !== void 0;
@@ -5407,8 +5685,8 @@ function userRows(r) {
5407
5685
  }
5408
5686
 
5409
5687
  // src/commands/credit.ts
5410
- import { Command as Command56 } from "commander";
5411
- var creditCommand = new Command56("credit").description("the prepaid credit left on your account and on each of your orgs").option("--org <slug>", "one org only").option("--json", "print as JSON").action(async (opts, cmd) => {
5688
+ import { Command as Command57 } from "commander";
5689
+ var creditCommand = new Command57("credit").description("the prepaid credit left on your account and on each of your orgs").option("--org <slug>", "one org only").option("--json", "print as JSON").action(async (opts, cmd) => {
5412
5690
  const client = await clientFor(cmd.optsWithGlobals(), { autoStart: false });
5413
5691
  try {
5414
5692
  if (client.target.kind === "local") throw new KvboxError("credit lives on the control plane: kvbox login first");
@@ -5437,8 +5715,8 @@ function creditRow(b, me2) {
5437
5715
  }
5438
5716
 
5439
5717
  // src/commands/redeem.ts
5440
- import { Command as Command57 } from "commander";
5441
- var redeemCommand = new Command57("redeem").description("redeem a promo code for credit, on your account or (--org) an org you own").argument("<code>", "the code, like KV-7F3K-9QXM-2HBD").option("--org <slug>", "give the credit to this org, which you own; it cannot be moved later").option("--json", "print as JSON").action(async (code, opts, cmd) => {
5718
+ import { Command as Command58 } from "commander";
5719
+ var redeemCommand = new Command58("redeem").description("redeem a promo code for credit, on your account or (--org) an org you own").argument("<code>", "the code, like KV-7F3K-9QXM-2HBD").option("--org <slug>", "give the credit to this org, which you own; it cannot be moved later").option("--json", "print as JSON").action(async (code, opts, cmd) => {
5442
5720
  const client = await clientFor(cmd.optsWithGlobals(), { autoStart: false });
5443
5721
  try {
5444
5722
  if (client.target.kind === "local") throw new KvboxError("codes are redeemed on the control plane: kvbox login first");
@@ -5458,7 +5736,7 @@ var redeemCommand = new Command57("redeem").description("redeem a promo code for
5458
5736
  // src/commands/deploy/index.ts
5459
5737
  import { access as access5, readFile as readFile7 } from "fs/promises";
5460
5738
  import { basename as basename2, resolve as resolve3 } from "path";
5461
- import { Command as Command58, InvalidArgumentError as InvalidArgumentError2, Option as Option5 } from "commander";
5739
+ import { Command as Command59, InvalidArgumentError as InvalidArgumentError2, Option as Option5 } from "commander";
5462
5740
 
5463
5741
  // src/commands/deploy/config.ts
5464
5742
  import { readFile as readFile5, writeFile as writeFile3 } from "fs/promises";
@@ -6723,7 +7001,7 @@ async function readPackageJson(dir) {
6723
7001
  }
6724
7002
 
6725
7003
  // src/commands/deploy/index.ts
6726
- var deployCommand = new Command58("deploy").description("put the app in this directory (React, Next.js, a Node server, a Dockerfile or a static site) on a box with its own HTTPS address; redeploy by running it again").argument("[dir]", "the app's directory (default: the current one)").addOption(new Option5("-t, --template <template>", "what kind of app it is (detected from package.json and the directory when not given)").choices(TEMPLATE_IDS)).option("-n, --name <name>", "the box's name (default: the directory's name)").option("--sub <subdomain>", "its HTTPS name, https://<subdomain>.kvbox.app (default: the box's name)").addOption(new Option5("-s, --size <size>", "size of the box when it has to be made").choices(SIZE_NAMES)).option("--port <port>", "the box port of a Next.js app, Node server or container (default 3000; saved to kvbox.json)", parsePort).option("--only <service>", "with several services in kvbox.json: deploy this one only (repeatable)", (v, all) => [...all ?? [], v]).option("-y, --yes", "ask nothing: take the defaults for whatever the flags and kvbox.json leave open").option("--json", "print the result as JSON").option("--org <slug>", "deploy into this org's boxes (saved to kvbox.json)").action(async (dirArg, opts, cmd) => {
7004
+ var deployCommand = new Command59("deploy").description("put the app in this directory (React, Next.js, a Node server, a Dockerfile or a static site) on a box with its own HTTPS address; redeploy by running it again").argument("[dir]", "the app's directory (default: the current one)").addOption(new Option5("-t, --template <template>", "what kind of app it is (detected from package.json and the directory when not given)").choices(TEMPLATE_IDS)).option("-n, --name <name>", "the box's name (default: the directory's name)").option("--sub <subdomain>", "its HTTPS name, https://<subdomain>.kvbox.app (default: the box's name)").addOption(new Option5("-s, --size <size>", "size of the box when it has to be made").choices(SIZE_NAMES)).option("--port <port>", "the box port of a Next.js app, Node server or container (default 3000; saved to kvbox.json)", parsePort).option("--only <service>", "with several services in kvbox.json: deploy this one only (repeatable)", (v, all) => [...all ?? [], v]).option("-y, --yes", "ask nothing: take the defaults for whatever the flags and kvbox.json leave open").option("--json", "print the result as JSON").option("--org <slug>", "deploy into this org's boxes (saved to kvbox.json)").action(async (dirArg, opts, cmd) => {
6727
7005
  const dir = resolve3(dirArg ?? ".");
6728
7006
  const pkg = await readPackageJson2(dir);
6729
7007
  const facts = { indexHtml: await exists2(resolve3(dir, "index.html")), dockerfile: await exists2(resolve3(dir, "Dockerfile")) };
@@ -6880,15 +7158,15 @@ async function settle2(dir, pkg, facts, saved, opts, orgFlag, cloud) {
6880
7158
  }
6881
7159
 
6882
7160
  // src/commands/volume/index.ts
6883
- import { Command as Command69 } from "commander";
7161
+ import { Command as Command71 } from "commander";
6884
7162
 
6885
7163
  // src/commands/volume/attach.ts
6886
- import { Command as Command59 } from "commander";
7164
+ import { Command as Command60 } from "commander";
6887
7165
  function describeMount(machine, volume2, box2) {
6888
7166
  const path = machine.volumes?.find((v) => volume2 === v.name || volume2.endsWith(`/${v.name}`))?.mountPath ?? volumeMountPath(volume2.slice(volume2.lastIndexOf("/") + 1));
6889
7167
  return machine.status === "running" ? ` the box was restarted; the volume is at ${path} inside it` : ` box ${box2} is ${machine.status}; the volume is at ${path} once it runs`;
6890
7168
  }
6891
- var attachCommand = new Command59("attach").description("attach a volume to a box at /mnt/<volume> (a running box is restarted to take it)").argument("[volume]", "volume name (picked from a list when left out)").argument("[box]", "box name (picked from a list when left out)").option("--json", "print the box as JSON").action(async (volumeArg, boxArg, opts, cmd) => {
7169
+ var attachCommand = new Command60("attach").description("attach a volume to a box at /mnt/<volume> (a running box is restarted to take it)").argument("[volume]", "volume name (picked from a list when left out)").argument("[box]", "box name (picked from a list when left out)").option("--json", "print the box as JSON").action(async (volumeArg, boxArg, opts, cmd) => {
6892
7170
  if (volumeArg === void 0 || boxArg === void 0) askOrUsage("give the volume and the box: kvbox volume attach <volume> <box>");
6893
7171
  const client = await clientFor(cmd.optsWithGlobals());
6894
7172
  try {
@@ -6907,11 +7185,11 @@ var attachCommand = new Command59("attach").description("attach a volume to a bo
6907
7185
  });
6908
7186
 
6909
7187
  // src/commands/volume/backup/index.ts
6910
- import { Command as Command63 } from "commander";
7188
+ import { Command as Command65 } from "commander";
6911
7189
 
6912
7190
  // src/commands/volume/backup/create.ts
6913
- import { Command as Command60 } from "commander";
6914
- var createCommand4 = new Command60("create").description("back up a volume's disk to the kvbox cloud (encrypted)").argument("<volume>", "volume 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 (volume2, opts, cmd) => {
7191
+ import { Command as Command61 } from "commander";
7192
+ var createCommand4 = new Command61("create").description("back up a volume's disk to the kvbox cloud (encrypted)").argument("<volume>", "volume 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 (volume2, opts, cmd) => {
6915
7193
  const client = await clientFor(cmd.optsWithGlobals(), { autoStart: false });
6916
7194
  try {
6917
7195
  requireCloud3(client);
@@ -6921,6 +7199,7 @@ var createCommand4 = new Command60("create").description("back up a volume's dis
6921
7199
  else {
6922
7200
  info(`${color.green("\u2713")} backup ${started.id} of volume ${color.bold(volume2)} started; it runs in the background`);
6923
7201
  info(color.dim(` status: kvbox volume backup ls ${volume2}`));
7202
+ await printCost(client, false);
6924
7203
  }
6925
7204
  return;
6926
7205
  }
@@ -6930,14 +7209,15 @@ var createCommand4 = new Command60("create").description("back up a volume's dis
6930
7209
  if (opts.json) return;
6931
7210
  info(`${color.green("\u2713")} backup ${done.id} of volume ${color.bold(volume2)}: ${sizeLine(done)}`);
6932
7211
  info(color.dim(` restore with: kvbox volume backup restore ${volume2} ${done.id}`));
7212
+ await printCost(client, true);
6933
7213
  } finally {
6934
7214
  await client.close();
6935
7215
  }
6936
7216
  });
6937
7217
 
6938
7218
  // src/commands/volume/backup/ls.ts
6939
- import { Command as Command61 } from "commander";
6940
- var lsCommand9 = new Command61("ls").alias("list").description("list volume backups: every volume's, or one volume's").argument("[volume]", "volume name (default: every volume)").option("--json", "print as JSON").action(async (volume2, opts, cmd) => {
7219
+ import { Command as Command62 } from "commander";
7220
+ var lsCommand9 = new Command62("ls").alias("list").description("list volume backups: every volume's, or one volume's").argument("[volume]", "volume name (default: every volume)").option("--json", "print as JSON").action(async (volume2, opts, cmd) => {
6941
7221
  const client = await clientFor(cmd.optsWithGlobals(), { autoStart: false });
6942
7222
  try {
6943
7223
  requireCloud3(client);
@@ -6970,8 +7250,8 @@ var lsCommand9 = new Command61("ls").alias("list").description("list volume back
6970
7250
  });
6971
7251
 
6972
7252
  // src/commands/volume/backup/restore.ts
6973
- import { Command as Command62 } from "commander";
6974
- var restoreCommand2 = new Command62("restore").description("put a backup back: the volume's data becomes the backup's (a running box holding it restarts)").argument("<volume>", "volume name").argument("<id>", "the backup's id (kvbox volume backup ls <volume>)").option("-y, --yes", "do not ask for confirmation").option("--json", "print the volume as JSON").action(async (volume2, id, opts, cmd) => {
7253
+ import { Command as Command63 } from "commander";
7254
+ var restoreCommand2 = new Command63("restore").description("put a backup back: the volume's data becomes the backup's (a running box holding it restarts)").argument("<volume>", "volume name").argument("<id>", "the backup's id (kvbox volume backup ls <volume>)").option("-y, --yes", "do not ask for confirmation").option("--json", "print the volume as JSON").action(async (volume2, id, opts, cmd) => {
6975
7255
  const client = await clientFor(cmd.optsWithGlobals(), { autoStart: false });
6976
7256
  try {
6977
7257
  requireCloud3(client);
@@ -6993,12 +7273,24 @@ var restoreCommand2 = new Command62("restore").description("put a backup back: t
6993
7273
  }
6994
7274
  });
6995
7275
 
7276
+ // src/commands/volume/backup/rm.ts
7277
+ import { Command as Command64 } from "commander";
7278
+ var rmCommand9 = new Command64("rm").alias("remove").description("remove a backup for good (a volume's that is gone too)").argument("<volume>", "volume name").argument("<id>", "the backup's id (kvbox volume backup ls <volume>)").option("-y, --yes", "do not ask for confirmation").action(async (volume2, id, opts, cmd) => {
7279
+ const client = await clientFor(cmd.optsWithGlobals(), { autoStart: false });
7280
+ try {
7281
+ requireCloud3(client);
7282
+ await removeListed(client, await client.listVolumeBackups(), (b) => b.volume, volume2, id, `volume ${volume2}`, opts.yes ?? false);
7283
+ } finally {
7284
+ await client.close();
7285
+ }
7286
+ });
7287
+
6996
7288
  // src/commands/volume/backup/index.ts
6997
- var backupCommand2 = new Command63("backup").description("back up a volume's disk to the kvbox cloud, list backups, restore one").addCommand(createCommand4).addCommand(lsCommand9).addCommand(restoreCommand2);
7289
+ var backupCommand2 = new Command65("backup").description("back up a volume's disk to the kvbox cloud, list backups, restore or remove one").addCommand(createCommand4).addCommand(lsCommand9).addCommand(restoreCommand2).addCommand(rmCommand9);
6998
7290
  for (const cmd of backupCommand2.commands) cmd.option("--org <slug>", "act in this org (- for your personal volumes)");
6999
7291
 
7000
7292
  // src/commands/volume/create.ts
7001
- import { Command as Command64 } from "commander";
7293
+ import { Command as Command66 } from "commander";
7002
7294
  function parseGib2(text2, label = "--size") {
7003
7295
  const mib = parseMib(text2);
7004
7296
  if (mib === void 0 || mib % 1024 !== 0) throw new KvboxError(`${label} ${text2}: write whole GB, like 50 or 50GB`);
@@ -7014,7 +7306,7 @@ function sizeProblem(answer) {
7014
7306
  return err instanceof KvboxError ? err.message.replace(/^--size \S+: /, "") : String(err);
7015
7307
  }
7016
7308
  }
7017
- var createCommand5 = new Command64("create").alias("new").description("create a volume for a box: an empty disk of its own at /mnt/<name> inside it (a running box is restarted)").argument("[name]", "volume name (1-12 chars; the box mounts it at /mnt/<name>; asked for when left out)").option("--size <gb>", "size in GB, like 50 or 50GB (whole GB; it only occupies what is written)").option("--box <box>", "the box it is for: made on that box's host and attached to it (required on kvbox.sh; optional with --local)").option("--json", "print the volume as JSON").action(async (nameArg, opts, cmd) => {
7309
+ var createCommand5 = new Command66("create").alias("new").description("create a volume for a box: an empty disk of its own at /mnt/<name> inside it (a running box is restarted)").argument("[name]", "volume name (1-12 chars; the box mounts it at /mnt/<name>; asked for when left out)").option("--size <gb>", "size in GB, like 50 or 50GB (whole GB; it only occupies what is written)").option("--box <box>", "the box it is for: made on that box's host and attached to it (required on kvbox.sh; optional with --local)").option("--json", "print the volume as JSON").action(async (nameArg, opts, cmd) => {
7018
7310
  const ask = interactive();
7019
7311
  if (nameArg === void 0 || opts.size === void 0) askOrUsage("give the name and the size: kvbox volume create <name> --size <gb> --box <box>");
7020
7312
  const name = nameArg ?? await text("Volume name", { validate: (a) => VOLUME_NAME_RE.test(a) ? void 0 : VOLUME_NAME_RULE });
@@ -7047,8 +7339,8 @@ var createCommand5 = new Command64("create").alias("new").description("create a
7047
7339
  });
7048
7340
 
7049
7341
  // src/commands/volume/detach.ts
7050
- import { Command as Command65 } from "commander";
7051
- var detachCommand = new Command65("detach").description("detach a volume from a box; its data is kept (a running box is restarted)").argument("[volume]", "volume name (picked from a list when left out)").argument("[box]", "box name (the one the volume is on when left out)").option("--json", "print the box as JSON").action(async (volumeArg, boxArg, opts, cmd) => {
7342
+ import { Command as Command67 } from "commander";
7343
+ var detachCommand = new Command67("detach").description("detach a volume from a box; its data is kept (a running box is restarted)").argument("[volume]", "volume name (picked from a list when left out)").argument("[box]", "box name (the one the volume is on when left out)").option("--json", "print the box as JSON").action(async (volumeArg, boxArg, opts, cmd) => {
7052
7344
  if (volumeArg === void 0) askOrUsage("give the volume: kvbox volume detach <volume> [box]");
7053
7345
  const client = await clientFor(cmd.optsWithGlobals());
7054
7346
  try {
@@ -7073,8 +7365,8 @@ var detachCommand = new Command65("detach").description("detach a volume from a
7073
7365
  });
7074
7366
 
7075
7367
  // src/commands/volume/grow.ts
7076
- import { Command as Command66 } from "commander";
7077
- var growCommand = new Command66("grow").alias("resize").description("make a volume larger (a running box holding it is restarted once)").argument("<volume>", "volume name").argument("<GB>", "the new size in GB, larger than what it has").option("--json", "print the volume as JSON").action(async (name, size, opts, cmd) => {
7368
+ import { Command as Command68 } from "commander";
7369
+ var growCommand = new Command68("grow").alias("resize").description("make a volume larger (a running box holding it is restarted once)").argument("<volume>", "volume name").argument("<GB>", "the new size in GB, larger than what it has").option("--json", "print the volume as JSON").action(async (name, size, opts, cmd) => {
7078
7370
  const sizeGib = parseGib2(size, "size");
7079
7371
  const client = await clientFor(cmd.optsWithGlobals());
7080
7372
  try {
@@ -7087,8 +7379,8 @@ var growCommand = new Command66("grow").alias("resize").description("make a volu
7087
7379
  });
7088
7380
 
7089
7381
  // src/commands/volume/ls.ts
7090
- import { Command as Command67 } from "commander";
7091
- var lsCommand10 = new Command67("ls").alias("list").description("list volumes: size, what they occupy, which box has them").option("-a, --all", "every volume on the platform (platform admins only)").option("--json", "print as JSON").action(async (opts, cmd) => {
7382
+ import { Command as Command69 } from "commander";
7383
+ var lsCommand10 = new Command69("ls").alias("list").description("list volumes: size, what they occupy, which box has them").option("-a, --all", "every volume on the platform (platform admins only)").option("--json", "print as JSON").action(async (opts, cmd) => {
7092
7384
  const client = await clientFor(cmd.optsWithGlobals());
7093
7385
  try {
7094
7386
  const cloud = client.target.kind === "cloud";
@@ -7119,8 +7411,8 @@ var lsCommand10 = new Command67("ls").alias("list").description("list volumes: s
7119
7411
  });
7120
7412
 
7121
7413
  // src/commands/volume/rm.ts
7122
- import { Command as Command68 } from "commander";
7123
- var rmCommand8 = new Command68("rm").alias("remove").description("delete a volume and everything on it (detach it first)").argument("<name>", "volume name").option("-y, --yes", "do not ask for confirmation").action(async (name, opts, cmd) => {
7414
+ import { Command as Command70 } from "commander";
7415
+ var rmCommand10 = new Command70("rm").alias("remove").description("delete a volume and everything on it (detach it first)").argument("<name>", "volume name").option("-y, --yes", "do not ask for confirmation").action(async (name, opts, cmd) => {
7124
7416
  if (!await confirm(`Delete volume ${name} and everything on it?`, opts.yes ?? false)) {
7125
7417
  info("cancelled");
7126
7418
  process.exitCode = 1;
@@ -7136,15 +7428,18 @@ var rmCommand8 = new Command68("rm").alias("remove").description("delete a volum
7136
7428
  });
7137
7429
 
7138
7430
  // src/commands/volume/index.ts
7139
- var volumeCommand = new Command69("volume").aliases(["volumes", "vol"]).description("disks of their own: create one, attach it to a box at /mnt/<name>, move it to another box later").addCommand(createCommand5).addCommand(lsCommand10).addCommand(attachCommand).addCommand(detachCommand).addCommand(growCommand).addCommand(rmCommand8);
7431
+ var volumeCommand = new Command71("volume").aliases(["volumes", "vol"]).description("disks of their own: create one, attach it to a box at /mnt/<name>, move it to another box later").addCommand(createCommand5).addCommand(lsCommand10).addCommand(attachCommand).addCommand(detachCommand).addCommand(growCommand).addCommand(rmCommand10);
7140
7432
  for (const cmd of volumeCommand.commands) cmd.option("--org <slug>", "act in this org (- for your personal volumes)");
7141
7433
  volumeCommand.addCommand(backupCommand2);
7142
7434
 
7143
7435
  // src/commands/bucket/index.ts
7144
- import { Command as Command79 } from "commander";
7436
+ import { Command as Command86 } from "commander";
7145
7437
 
7146
- // src/commands/bucket/create.ts
7147
- import { Command as Command70 } from "commander";
7438
+ // src/commands/bucket/backup/index.ts
7439
+ import { Command as Command76 } from "commander";
7440
+
7441
+ // src/commands/bucket/backup/create.ts
7442
+ import { Command as Command72 } from "commander";
7148
7443
 
7149
7444
  // src/commands/bucket/shared.ts
7150
7445
  async function bucketClient(cmd) {
@@ -7169,8 +7464,124 @@ function printRows(rows2) {
7169
7464
  `);
7170
7465
  }
7171
7466
 
7467
+ // src/commands/bucket/backup/create.ts
7468
+ var createCommand6 = new Command72("create").description("back up your object storage (every bucket and key) to the kvbox cloud, encrypted").option("--wait", "stay until the backup is ready (by default it runs in the background)").option("--json", "print the backup as JSON").action(async (opts, cmd) => {
7469
+ const client = await bucketClient(cmd);
7470
+ const ls = "kvbox bucket backup ls";
7471
+ try {
7472
+ const started = await client.createStorageBackup();
7473
+ const what = `the object storage of ${started.owner}`;
7474
+ if (!opts.wait) {
7475
+ if (opts.json) json(started);
7476
+ else {
7477
+ info(`${color.green("\u2713")} backup ${started.id} of ${what} started (${started.buckets.length} ${started.buckets.length === 1 ? "bucket" : "buckets"}); it runs in the background`);
7478
+ info(color.dim(` status: ${ls}`));
7479
+ await printCost(client, false);
7480
+ }
7481
+ return;
7482
+ }
7483
+ const done = await spin(`backing up ${what}\u2026`, untilSettled(() => client.storageBackup(started.id), what, started.id, ls));
7484
+ if (opts.json) json(done);
7485
+ if (done.status === "failed") throw new KvboxError(`backup ${done.id} of ${what} failed: ${done.error ?? "no reason given"}`);
7486
+ if (opts.json) return;
7487
+ info(`${color.green("\u2713")} backup ${done.id} of ${what}: ${done.buckets.join(", ")}; ${sizeLine(done)}`);
7488
+ info(color.dim(` restore with: kvbox bucket backup restore ${done.id}`));
7489
+ await printCost(client, true);
7490
+ } finally {
7491
+ await client.close();
7492
+ }
7493
+ });
7494
+
7495
+ // src/commands/bucket/backup/ls.ts
7496
+ import { Command as Command73 } from "commander";
7497
+ var lsCommand11 = new Command73("ls").alias("list").description("list the backups of your object storage").option("--json", "print as JSON").action(async (opts, cmd) => {
7498
+ const client = await bucketClient(cmd);
7499
+ try {
7500
+ const list = await client.storageBackups();
7501
+ if (opts.json) {
7502
+ json(list);
7503
+ return;
7504
+ }
7505
+ if (list.length === 0) {
7506
+ info("no backups yet; make one with: kvbox bucket backup create");
7507
+ return;
7508
+ }
7509
+ const anyError = list.some((b) => b.error !== null);
7510
+ table(
7511
+ list.map((b) => ({
7512
+ id: b.id,
7513
+ status: b.status === "ready" ? color.green(b.status) : b.status === "failed" ? color.red(b.status) : color.yellow(b.status),
7514
+ buckets: b.buckets.join(","),
7515
+ keys: b.keys,
7516
+ data: b.dataBytes === null ? "-" : gbShort(b.dataBytes),
7517
+ uploaded: b.uploadedBytes === null ? "-" : gbShort(b.uploadedBytes),
7518
+ by: b.createdBy ?? "-",
7519
+ taken: age(b.createdAt),
7520
+ ...anyError ? { error: b.error ?? "" } : {}
7521
+ }))
7522
+ );
7523
+ } finally {
7524
+ await client.close();
7525
+ }
7526
+ });
7527
+
7528
+ // src/commands/bucket/backup/restore.ts
7529
+ import { Command as Command74 } from "commander";
7530
+ var restoreCommand3 = new Command74("restore").description("put a backup back: every bucket and key becomes the backup's (the storage restarts)").argument("<id>", "the backup's id (kvbox bucket backup ls)").option("-y, --yes", "do not ask for confirmation").option("--json", "print what changed as JSON").action(async (id, opts, cmd) => {
7531
+ const client = await bucketClient(cmd);
7532
+ try {
7533
+ const backup = await client.storageBackup(id);
7534
+ const what = `the object storage of ${backup.owner}`;
7535
+ const question = `Restore ${what} from backup ${backup.id} (${age(backup.createdAt)} ago, ${sizeLine(backup)}; buckets ${backup.buckets.join(", ")})? Everything written since is lost: buckets made since are removed with their files, and access keys made since stop working. It restarts.`;
7536
+ if (!await confirm(question, opts.yes ?? false)) {
7537
+ info("cancelled");
7538
+ process.exitCode = 1;
7539
+ return;
7540
+ }
7541
+ const done = await spin(`restoring ${what} from ${backup.id}\u2026`, client.restoreStorageBackup(id));
7542
+ if (opts.json) {
7543
+ json(done);
7544
+ return;
7545
+ }
7546
+ info(`${color.green("\u2713")} ${what} restored from backup ${backup.id}`);
7547
+ const list = (names2) => names2.join(", ");
7548
+ if (done.buckets.kept.length > 0) info(` buckets as they were then: ${list(done.buckets.kept)}`);
7549
+ if (done.buckets.returned.length > 0) info(` buckets back (removed since; no keys, make new ones): ${list(done.buckets.returned)}`);
7550
+ if (done.buckets.removed.length > 0) warn(` buckets gone (made since): ${list(done.buckets.removed)}`);
7551
+ if (done.keys.dropped.length > 0) warn(` keys that no longer work (made since): ${list(done.keys.dropped.map((k) => `${k.id} (${k.bucket}/${k.name})`))}`);
7552
+ if (done.keys.revoked.length > 0) info(` keys removed since stay removed: ${list(done.keys.revoked.map((k) => k.id))}`);
7553
+ for (const w of done.warnings) warn(` ${w}`);
7554
+ } finally {
7555
+ await client.close();
7556
+ }
7557
+ });
7558
+
7559
+ // src/commands/bucket/backup/rm.ts
7560
+ import { Command as Command75 } from "commander";
7561
+ var rmCommand11 = new Command75("rm").alias("remove").description("remove a backup of your object storage for good").argument("<id>", "the backup's id (kvbox bucket backup ls)").option("-y, --yes", "do not ask for confirmation").action(async (id, opts, cmd) => {
7562
+ const client = await bucketClient(cmd);
7563
+ try {
7564
+ const backup = (await client.storageBackups()).find((b) => b.id === id);
7565
+ if (!backup) throw new NotFoundError(`backup ${id} of your object storage`);
7566
+ const question = `Remove backup ${backup.id} of the object storage of ${backup.owner} (${age(backup.createdAt)} ago, ${backup.status === "ready" ? sizeLine(backup) : backup.status})? It cannot be restored after this.`;
7567
+ if (!await confirm(question, opts.yes ?? false)) {
7568
+ info("cancelled");
7569
+ process.exitCode = 1;
7570
+ return;
7571
+ }
7572
+ await client.removeBackup(backup.id);
7573
+ info(`${color.green("\u2713")} backup ${backup.id} of the object storage of ${backup.owner} removed`);
7574
+ } finally {
7575
+ await client.close();
7576
+ }
7577
+ });
7578
+
7579
+ // src/commands/bucket/backup/index.ts
7580
+ var backupCommand3 = new Command76("backup").aliases(["backups"]).description("back up your object storage to the kvbox cloud, list backups, restore or remove one").addCommand(createCommand6).addCommand(lsCommand11).addCommand(restoreCommand3).addCommand(rmCommand11);
7581
+
7172
7582
  // src/commands/bucket/create.ts
7173
- var createCommand6 = new Command70("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) => {
7583
+ import { Command as Command77 } from "commander";
7584
+ var createCommand7 = new Command77("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) => {
7174
7585
  const sizeGib = opts.size === void 0 ? void 0 : parseGib2(opts.size);
7175
7586
  const client = await bucketClient(cmd);
7176
7587
  try {
@@ -7190,8 +7601,8 @@ var createCommand6 = new Command70("create").description("make a bucket (the fir
7190
7601
  });
7191
7602
 
7192
7603
  // src/commands/bucket/grow.ts
7193
- import { Command as Command71 } from "commander";
7194
- var growCommand2 = new Command71("grow").description("make your object storage larger (all your buckets share it; it restarts once)").argument("<GB>", "the new size in GB, larger than what it has").option("--json", "print the object storage as JSON").action(async (size, opts, cmd) => {
7604
+ import { Command as Command78 } from "commander";
7605
+ var growCommand2 = new Command78("grow").description("make your object storage larger (all your buckets share it; it restarts once)").argument("<GB>", "the new size in GB, larger than what it has").option("--json", "print the object storage as JSON").action(async (size, opts, cmd) => {
7195
7606
  const sizeGib = parseGib2(size, "size");
7196
7607
  const client = await bucketClient(cmd);
7197
7608
  try {
@@ -7204,8 +7615,8 @@ var growCommand2 = new Command71("grow").description("make your object storage l
7204
7615
  });
7205
7616
 
7206
7617
  // src/commands/bucket/info.ts
7207
- import { Command as Command72 } from "commander";
7208
- var infoCommand = new Command72("info").description("one bucket: its address, what it holds, how full your object storage is").argument("<name>", "bucket name").option("--json", "print as JSON").action(async (name, opts, cmd) => {
7618
+ import { Command as Command79 } from "commander";
7619
+ var infoCommand = new Command79("info").description("one bucket: its address, what it holds, how full your object storage is").argument("<name>", "bucket name").option("--json", "print as JSON").action(async (name, opts, cmd) => {
7209
7620
  const client = await bucketClient(cmd);
7210
7621
  try {
7211
7622
  const b = await client.getBucket(name);
@@ -7234,11 +7645,11 @@ with the AWS CLI: aws s3 ls s3://${b.name} --endpoint-url ${b.endpoint}`));
7234
7645
  });
7235
7646
 
7236
7647
  // src/commands/bucket/key/index.ts
7237
- import { Command as Command76 } from "commander";
7648
+ import { Command as Command83 } from "commander";
7238
7649
 
7239
7650
  // src/commands/bucket/key/create.ts
7240
- import { Command as Command73 } from "commander";
7241
- var createCommand7 = new Command73("create").description("make an access key for a bucket (the secret is shown once)").argument("<bucket>", "bucket name").option("--name <label>", "what to call the key, to tell it from the others").option("--read-only", "the key reads the bucket but cannot write to it").option("--json", "print as JSON").action(async (bucket, opts, cmd) => {
7651
+ import { Command as Command80 } from "commander";
7652
+ var createCommand8 = new Command80("create").description("make an access key for a bucket (the secret is shown once)").argument("<bucket>", "bucket name").option("--name <label>", "what to call the key, to tell it from the others").option("--read-only", "the key reads the bucket but cannot write to it").option("--json", "print as JSON").action(async (bucket, opts, cmd) => {
7242
7653
  const client = await bucketClient(cmd);
7243
7654
  try {
7244
7655
  const key = await client.createBucketKey(bucket, { ...opts.name !== void 0 ? { name: opts.name } : {}, ...opts.readOnly ? { readOnly: true } : {} });
@@ -7261,8 +7672,8 @@ var createCommand7 = new Command73("create").description("make an access key for
7261
7672
  });
7262
7673
 
7263
7674
  // src/commands/bucket/key/ls.ts
7264
- import { Command as Command74 } from "commander";
7265
- var lsCommand11 = new Command74("ls").alias("list").description("list a bucket's access keys (never their secrets)").argument("<bucket>", "bucket name").option("--json", "print as JSON").action(async (bucket, opts, cmd) => {
7675
+ import { Command as Command81 } from "commander";
7676
+ var lsCommand12 = new Command81("ls").alias("list").description("list a bucket's access keys (never their secrets)").argument("<bucket>", "bucket name").option("--json", "print as JSON").action(async (bucket, opts, cmd) => {
7266
7677
  const client = await bucketClient(cmd);
7267
7678
  try {
7268
7679
  const keys = await client.listBucketKeys(bucket);
@@ -7281,8 +7692,8 @@ var lsCommand11 = new Command74("ls").alias("list").description("list a bucket's
7281
7692
  });
7282
7693
 
7283
7694
  // src/commands/bucket/key/rm.ts
7284
- import { Command as Command75 } from "commander";
7285
- var rmCommand9 = new Command75("rm").alias("remove").description("delete an access key: whatever uses it stops reaching the bucket").argument("<bucket>", "bucket name").argument("<access-key>", "the access key id (kvbox bucket key ls)").option("-y, --yes", "do not ask for confirmation").action(async (bucket, id, opts, cmd) => {
7695
+ import { Command as Command82 } from "commander";
7696
+ var rmCommand12 = new Command82("rm").alias("remove").description("delete an access key: whatever uses it stops reaching the bucket").argument("<bucket>", "bucket name").argument("<access-key>", "the access key id (kvbox bucket key ls)").option("-y, --yes", "do not ask for confirmation").action(async (bucket, id, opts, cmd) => {
7286
7697
  const client = await bucketClient(cmd);
7287
7698
  try {
7288
7699
  if (!await confirm(`Delete key ${id} of bucket ${bucket}? Whatever uses it stops working.`, opts.yes ?? false)) {
@@ -7298,11 +7709,11 @@ var rmCommand9 = new Command75("rm").alias("remove").description("delete an acce
7298
7709
  });
7299
7710
 
7300
7711
  // src/commands/bucket/key/index.ts
7301
- var keyCommand2 = new Command76("key").aliases(["keys"]).description("access keys of a bucket: what your app signs in with").addCommand(createCommand7).addCommand(lsCommand11).addCommand(rmCommand9);
7712
+ var keyCommand2 = new Command83("key").aliases(["keys"]).description("access keys of a bucket: what your app signs in with").addCommand(createCommand8).addCommand(lsCommand12).addCommand(rmCommand12);
7302
7713
 
7303
7714
  // src/commands/bucket/ls.ts
7304
- import { Command as Command77 } from "commander";
7305
- var lsCommand12 = new Command77("ls").alias("list").description("list buckets, and the object storage they are in").option("-a, --all", "every bucket on the platform (platform admins only)").option("--json", "print as JSON").action(async (opts, cmd) => {
7715
+ import { Command as Command84 } from "commander";
7716
+ var lsCommand13 = new Command84("ls").alias("list").description("list buckets, and the object storage they are in").option("-a, --all", "every bucket on the platform (platform admins only)").option("--json", "print as JSON").action(async (opts, cmd) => {
7306
7717
  const client = await bucketClient(cmd);
7307
7718
  try {
7308
7719
  const buckets = await client.listBuckets({ all: opts.all });
@@ -7332,8 +7743,8 @@ var lsCommand12 = new Command77("ls").alias("list").description("list buckets, a
7332
7743
  });
7333
7744
 
7334
7745
  // src/commands/bucket/rm.ts
7335
- import { Command as Command78 } from "commander";
7336
- var rmCommand10 = new Command78("rm").alias("remove").description("delete an empty bucket and its keys (the last one takes your object storage with it)").argument("<name>", "bucket name").option("--force", "your last bucket only: delete it with everything in it").option("-y, --yes", "do not ask for confirmation").action(async (name, opts, cmd) => {
7746
+ import { Command as Command85 } from "commander";
7747
+ var rmCommand13 = new Command85("rm").alias("remove").description("delete an empty bucket and its keys (the last one takes your object storage with it)").argument("<name>", "bucket name").option("--force", "your last bucket only: delete it with everything in it").option("-y, --yes", "do not ask for confirmation").action(async (name, opts, cmd) => {
7337
7748
  const client = await bucketClient(cmd);
7338
7749
  try {
7339
7750
  const question = opts.force ? `Delete bucket ${name} with everything in it, and the object storage it is in?` : `Delete bucket ${name} and its keys?`;
@@ -7352,18 +7763,18 @@ var rmCommand10 = new Command78("rm").alias("remove").description("delete an emp
7352
7763
  });
7353
7764
 
7354
7765
  // src/commands/bucket/index.ts
7355
- var bucketCommand = new Command79("bucket").aliases(["buckets"]).description("object storage: S3 buckets for your files, and the access keys your apps use").addCommand(createCommand6).addCommand(lsCommand12).addCommand(infoCommand).addCommand(growCommand2).addCommand(rmCommand10).addCommand(keyCommand2);
7766
+ var bucketCommand = new Command86("bucket").aliases(["buckets"]).description("object storage: S3 buckets for your files, and the access keys your apps use").addCommand(createCommand7).addCommand(lsCommand13).addCommand(infoCommand).addCommand(growCommand2).addCommand(rmCommand13).addCommand(keyCommand2).addCommand(backupCommand3);
7356
7767
  var withOrg = (cmd) => cmd.option("--org <slug>", "act in this org (- for your personal buckets)");
7357
7768
  for (const cmd of bucketCommand.commands) {
7358
- if (cmd === keyCommand2) cmd.commands.forEach(withOrg);
7769
+ if (cmd === keyCommand2 || cmd === backupCommand3) cmd.commands.forEach(withOrg);
7359
7770
  else withOrg(cmd);
7360
7771
  }
7361
7772
 
7362
7773
  // src/commands/cron/index.ts
7363
- import { Command as Command92 } from "commander";
7774
+ import { Command as Command99 } from "commander";
7364
7775
 
7365
7776
  // src/commands/cron/create.ts
7366
- import { Command as Command80 } from "commander";
7777
+ import { Command as Command87 } from "commander";
7367
7778
 
7368
7779
  // src/commands/cron/shared.ts
7369
7780
  async function cronClient(cmd) {
@@ -7424,7 +7835,7 @@ function printRows2(rows2) {
7424
7835
  var noTriggers = (service) => info(`cron service ${service} has no triggers yet; add one with: kvbox cron trigger add ${service} <box> "0 6 * * *" --port 3000 (or --run "<command>")`);
7425
7836
 
7426
7837
  // src/commands/cron/create.ts
7427
- var createCommand8 = new Command80("create").description("make a cron service: a named set of triggers").argument("<name>", "what to call it (lowercase letters, digits and '-')").option("--json", "print as JSON").action(async (name, opts, cmd) => {
7838
+ var createCommand9 = new Command87("create").description("make a cron service: a named set of triggers").argument("<name>", "what to call it (lowercase letters, digits and '-')").option("--json", "print as JSON").action(async (name, opts, cmd) => {
7428
7839
  const client = await cronClient(cmd);
7429
7840
  try {
7430
7841
  const service = await client.createCronService(name);
@@ -7441,8 +7852,8 @@ var createCommand8 = new Command80("create").description("make a cron service: a
7441
7852
  });
7442
7853
 
7443
7854
  // src/commands/cron/info.ts
7444
- import { Command as Command81 } from "commander";
7445
- var infoCommand2 = new Command81("info").alias("get").description("show a cron service and its triggers").argument("<name>", "cron service name").option("--json", "print as JSON").action(async (name, opts, cmd) => {
7855
+ import { Command as Command88 } from "commander";
7856
+ var infoCommand2 = new Command88("info").alias("get").description("show a cron service and its triggers").argument("<name>", "cron service name").option("--json", "print as JSON").action(async (name, opts, cmd) => {
7446
7857
  const client = await cronClient(cmd);
7447
7858
  try {
7448
7859
  const service = await client.getCronService(name);
@@ -7466,8 +7877,8 @@ var infoCommand2 = new Command81("info").alias("get").description("show a cron s
7466
7877
  });
7467
7878
 
7468
7879
  // src/commands/cron/ls.ts
7469
- import { Command as Command82 } from "commander";
7470
- var lsCommand13 = new Command82("ls").alias("list").description("list cron services").option("-a, --all", "every cron service on the platform (platform admins only)").option("--json", "print as JSON").action(async (opts, cmd) => {
7880
+ import { Command as Command89 } from "commander";
7881
+ var lsCommand14 = new Command89("ls").alias("list").description("list cron services").option("-a, --all", "every cron service on the platform (platform admins only)").option("--json", "print as JSON").action(async (opts, cmd) => {
7471
7882
  const client = await cronClient(cmd);
7472
7883
  try {
7473
7884
  const services = await client.listCronServices({ all: opts.all });
@@ -7487,8 +7898,8 @@ var lsCommand13 = new Command82("ls").alias("list").description("list cron servi
7487
7898
  });
7488
7899
 
7489
7900
  // src/commands/cron/rm.ts
7490
- import { Command as Command83 } from "commander";
7491
- var rmCommand11 = new Command83("rm").alias("remove").description("delete a cron service, its triggers and their run history").argument("<name>", "cron service name").option("-y, --yes", "do not ask for confirmation").action(async (name, opts, cmd) => {
7901
+ import { Command as Command90 } from "commander";
7902
+ var rmCommand14 = new Command90("rm").alias("remove").description("delete a cron service, its triggers and their run history").argument("<name>", "cron service name").option("-y, --yes", "do not ask for confirmation").action(async (name, opts, cmd) => {
7492
7903
  const client = await cronClient(cmd);
7493
7904
  try {
7494
7905
  if (!await confirm(`Delete cron service ${name}? Its triggers stop firing and their run history is deleted.`, opts.yes ?? false)) {
@@ -7504,10 +7915,10 @@ var rmCommand11 = new Command83("rm").alias("remove").description("delete a cron
7504
7915
  });
7505
7916
 
7506
7917
  // src/commands/cron/trigger/index.ts
7507
- import { Command as Command91 } from "commander";
7918
+ import { Command as Command98 } from "commander";
7508
7919
 
7509
7920
  // src/commands/cron/trigger/add.ts
7510
- import { Command as Command84 } from "commander";
7921
+ import { Command as Command91 } from "commander";
7511
7922
  function portOf(value) {
7512
7923
  const n = Number(value);
7513
7924
  if (!Number.isInteger(n) || n < 1 || n > 65535) throw new KvboxError(`--port ${value}: a port is a number from 1 to 65535`);
@@ -7527,7 +7938,7 @@ function timeoutOf(value) {
7527
7938
  if (sec > MAX_CRON_COMMAND_TIMEOUT_SEC) throw new KvboxError(`--timeout ${value}: a command may run for ${MAX_CRON_COMMAND_TIMEOUT_SEC / 60} minutes at most`);
7528
7939
  return sec;
7529
7940
  }
7530
- var addCommand3 = new Command84("add").description("add a trigger: on a schedule, call a port of a box or run a command in it").argument("<service>", "cron service name").argument("<box>", "the box it acts on").argument("<expr>", 'cron expression in quotes, five fields: "0 6 * * *" is every day at 06:00').option("--port <n>", "call this port, the one your app listens on in the box").option("--path <path>", "with --port: path and query to request (default: /)").option("--method <method>", `with --port: HTTP method, ${CRON_METHODS.join(" or ")} (default: POST)`).option("--run <command>", 'or run this command in the box, in quotes: "node ~/app/embed.js"').option("--timeout <duration>", `with --run: stop the command after this long (90s, 10m, 1h; default: ${DEFAULT_CRON_COMMAND_TIMEOUT_SEC / 60}m)`).option("--tz <zone>", "time zone the schedule is read in, like Europe/Bucharest", "UTC").option("--json", "print as JSON").action(async (service, box2, expr, opts, cmd) => {
7941
+ var addCommand3 = new Command91("add").description("add a trigger: on a schedule, call a port of a box or run a command in it").argument("<service>", "cron service name").argument("<box>", "the box it acts on").argument("<expr>", 'cron expression in quotes, five fields: "0 6 * * *" is every day at 06:00').option("--port <n>", "call this port, the one your app listens on in the box").option("--path <path>", "with --port: path and query to request (default: /)").option("--method <method>", `with --port: HTTP method, ${CRON_METHODS.join(" or ")} (default: POST)`).option("--run <command>", 'or run this command in the box, in quotes: "node ~/app/embed.js"').option("--timeout <duration>", `with --run: stop the command after this long (90s, 10m, 1h; default: ${DEFAULT_CRON_COMMAND_TIMEOUT_SEC / 60}m)`).option("--tz <zone>", "time zone the schedule is read in, like Europe/Bucharest", "UTC").option("--json", "print as JSON").action(async (service, box2, expr, opts, cmd) => {
7531
7942
  let action;
7532
7943
  if (opts.run !== void 0) {
7533
7944
  if (opts.port !== void 0 || opts.path !== void 0 || opts.method !== void 0) throw new KvboxError("a trigger runs a command or calls a port: use --run, or --port with --path and --method, not both");
@@ -7554,8 +7965,8 @@ var addCommand3 = new Command84("add").description("add a trigger: on a schedule
7554
7965
  });
7555
7966
 
7556
7967
  // src/commands/cron/trigger/ls.ts
7557
- import { Command as Command85 } from "commander";
7558
- var lsCommand14 = new Command85("ls").alias("list").description("list a cron service's triggers").argument("<service>", "cron service name").option("--json", "print as JSON").action(async (service, opts, cmd) => {
7968
+ import { Command as Command92 } from "commander";
7969
+ var lsCommand15 = new Command92("ls").alias("list").description("list a cron service's triggers").argument("<service>", "cron service name").option("--json", "print as JSON").action(async (service, opts, cmd) => {
7559
7970
  const client = await cronClient(cmd);
7560
7971
  try {
7561
7972
  const triggers = await client.listCronTriggers(service);
@@ -7571,8 +7982,8 @@ var lsCommand14 = new Command85("ls").alias("list").description("list a cron ser
7571
7982
  });
7572
7983
 
7573
7984
  // src/commands/cron/trigger/pause.ts
7574
- import { Command as Command86 } from "commander";
7575
- var pauseCommand2 = new Command86("pause").description("stop a trigger from firing until it is resumed").argument("<service>", "cron service name").argument("<id>", "trigger id (kvbox cron trigger ls)").option("--json", "print as JSON").action(async (service, id, opts, cmd) => {
7985
+ import { Command as Command93 } from "commander";
7986
+ var pauseCommand2 = new Command93("pause").description("stop a trigger from firing until it is resumed").argument("<service>", "cron service name").argument("<id>", "trigger id (kvbox cron trigger ls)").option("--json", "print as JSON").action(async (service, id, opts, cmd) => {
7576
7987
  const client = await cronClient(cmd);
7577
7988
  try {
7578
7989
  const trigger = await client.setCronTriggerEnabled(service, id, false);
@@ -7587,8 +7998,8 @@ var pauseCommand2 = new Command86("pause").description("stop a trigger from firi
7587
7998
  });
7588
7999
 
7589
8000
  // src/commands/cron/trigger/resume.ts
7590
- import { Command as Command87 } from "commander";
7591
- var resumeCommand2 = new Command87("resume").description("let a paused trigger fire again").argument("<service>", "cron service name").argument("<id>", "trigger id (kvbox cron trigger ls)").option("--json", "print as JSON").action(async (service, id, opts, cmd) => {
8001
+ import { Command as Command94 } from "commander";
8002
+ var resumeCommand2 = new Command94("resume").description("let a paused trigger fire again").argument("<service>", "cron service name").argument("<id>", "trigger id (kvbox cron trigger ls)").option("--json", "print as JSON").action(async (service, id, opts, cmd) => {
7592
8003
  const client = await cronClient(cmd);
7593
8004
  try {
7594
8005
  const trigger = await client.setCronTriggerEnabled(service, id, true);
@@ -7603,8 +8014,8 @@ var resumeCommand2 = new Command87("resume").description("let a paused trigger f
7603
8014
  });
7604
8015
 
7605
8016
  // src/commands/cron/trigger/rm.ts
7606
- import { Command as Command88 } from "commander";
7607
- var rmCommand12 = new Command88("rm").alias("remove").description("delete a trigger and its run history").argument("<service>", "cron service name").argument("<id>", "trigger id (kvbox cron trigger ls)").option("-y, --yes", "do not ask for confirmation").action(async (service, id, opts, cmd) => {
8017
+ import { Command as Command95 } from "commander";
8018
+ var rmCommand15 = new Command95("rm").alias("remove").description("delete a trigger and its run history").argument("<service>", "cron service name").argument("<id>", "trigger id (kvbox cron trigger ls)").option("-y, --yes", "do not ask for confirmation").action(async (service, id, opts, cmd) => {
7608
8019
  const client = await cronClient(cmd);
7609
8020
  try {
7610
8021
  if (!await confirm(`Delete trigger ${id} of cron service ${service}? Its run history is deleted too.`, opts.yes ?? false)) {
@@ -7620,8 +8031,8 @@ var rmCommand12 = new Command88("rm").alias("remove").description("delete a trig
7620
8031
  });
7621
8032
 
7622
8033
  // src/commands/cron/trigger/run.ts
7623
- import { Command as Command89 } from "commander";
7624
- var runCommand = new Command89("run").description("fire a trigger now, once, besides its schedule").argument("<service>", "cron service name").argument("<id>", "trigger id (kvbox cron trigger ls)").option("--json", "print as JSON").action(async (service, id, opts, cmd) => {
8034
+ import { Command as Command96 } from "commander";
8035
+ var runCommand = new Command96("run").description("fire a trigger now, once, besides its schedule").argument("<service>", "cron service name").argument("<id>", "trigger id (kvbox cron trigger ls)").option("--json", "print as JSON").action(async (service, id, opts, cmd) => {
7625
8036
  const client = await cronClient(cmd);
7626
8037
  try {
7627
8038
  const trigger = await client.runCronTrigger(service, id);
@@ -7637,13 +8048,13 @@ var runCommand = new Command89("run").description("fire a trigger now, once, bes
7637
8048
  });
7638
8049
 
7639
8050
  // src/commands/cron/trigger/runs.ts
7640
- import { Command as Command90 } from "commander";
8051
+ import { Command as Command97 } from "commander";
7641
8052
  function limitOf(value) {
7642
8053
  const n = Number(value);
7643
8054
  if (!Number.isInteger(n) || n < 1) throw new KvboxError(`-n ${value}: a number of runs, 1 or more`);
7644
8055
  return n;
7645
8056
  }
7646
- var runsCommand = new Command90("runs").aliases(["logs"]).description("show how a trigger's last runs ended").argument("<service>", "cron service name").argument("<id>", "trigger id (kvbox cron trigger ls)").option("-n, --limit <count>", "how many runs to show", "20").option("--json", "print as JSON").action(async (service, id, opts, cmd) => {
8057
+ var runsCommand = new Command97("runs").aliases(["logs"]).description("show how a trigger's last runs ended").argument("<service>", "cron service name").argument("<id>", "trigger id (kvbox cron trigger ls)").option("-n, --limit <count>", "how many runs to show", "20").option("--json", "print as JSON").action(async (service, id, opts, cmd) => {
7647
8058
  const limit = limitOf(opts.limit);
7648
8059
  const client = await cronClient(cmd);
7649
8060
  try {
@@ -7673,10 +8084,10 @@ var runsCommand = new Command90("runs").aliases(["logs"]).description("show how
7673
8084
  });
7674
8085
 
7675
8086
  // src/commands/cron/trigger/index.ts
7676
- var triggerCommand = new Command91("trigger").aliases(["triggers"]).description("a cron service's triggers: a schedule and the request it sends to a box").addCommand(addCommand3).addCommand(lsCommand14).addCommand(runsCommand).addCommand(runCommand).addCommand(pauseCommand2).addCommand(resumeCommand2).addCommand(rmCommand12);
8087
+ var triggerCommand = new Command98("trigger").aliases(["triggers"]).description("a cron service's triggers: a schedule and the request it sends to a box").addCommand(addCommand3).addCommand(lsCommand15).addCommand(runsCommand).addCommand(runCommand).addCommand(pauseCommand2).addCommand(resumeCommand2).addCommand(rmCommand15);
7677
8088
 
7678
8089
  // src/commands/cron/index.ts
7679
- var cronCommand = new Command92("cron").description("cron: call a box on a schedule, waking it first if it sleeps").addCommand(createCommand8).addCommand(lsCommand13).addCommand(infoCommand2).addCommand(rmCommand11).addCommand(triggerCommand);
8090
+ var cronCommand = new Command99("cron").description("cron: call a box on a schedule, waking it first if it sleeps").addCommand(createCommand9).addCommand(lsCommand14).addCommand(infoCommand2).addCommand(rmCommand14).addCommand(triggerCommand);
7680
8091
  var withOrg2 = (cmd) => cmd.option("--org <slug>", "act in this org (- for your personal cron services)");
7681
8092
  for (const cmd of cronCommand.commands) {
7682
8093
  if (cmd === triggerCommand) cmd.commands.forEach(withOrg2);
@@ -7684,11 +8095,13 @@ for (const cmd of cronCommand.commands) {
7684
8095
  }
7685
8096
 
7686
8097
  // src/commands/managed/kind.ts
7687
- import { Command as Command105 } from "commander";
8098
+ import { Command as Command118 } from "commander";
7688
8099
 
7689
- // src/commands/managed/create.ts
7690
- import { Command as Command94 } from "commander";
7691
- import { setTimeout as sleep5 } from "timers/promises";
8100
+ // src/commands/managed/backup/index.ts
8101
+ import { Command as Command106 } from "commander";
8102
+
8103
+ // src/commands/managed/backup/create.ts
8104
+ import { Command as Command101 } from "commander";
7692
8105
 
7693
8106
  // src/commands/managed/shared.ts
7694
8107
  import "commander";
@@ -7743,10 +8156,25 @@ function infoRows(spec, m, user) {
7743
8156
  rows2.push(...settingRows(spec, m.settings), ["password", color.dim(`kvbox ${spec.command} password ${name}`)]);
7744
8157
  rows2.push(["private", `${m.urls.private} ${color.dim(m.links.length > 0 ? `(from ${m.links.join(", ")})` : `(no box is linked: kvbox ${spec.command} link ${name} <box>)`)}`]);
7745
8158
  rows2.push(["public", m.urls.public ?? color.dim(`off (kvbox ${spec.command} public ${name} on)`)]);
8159
+ if (m.backupSchedule !== null) rows2.push(["backups", scheduleText2(spec, name, m.backupSchedule)]);
7746
8160
  rows2.push(["cost", `${money(m.price.perMonth, m.price.currency)} a month while it runs, ${money(m.price.storagePerMonth, m.price.currency)} stopped ${color.dim("(estimated)")}`]);
7747
8161
  rows2.push(["created", `${age(m.createdAt)}${m.createdBy ? ` by ${m.createdBy}` : ""}`]);
7748
8162
  return rows2;
7749
8163
  }
8164
+ function scheduleText2(spec, name, s, now = Date.now()) {
8165
+ const at = `${String(s.hour).padStart(2, "0")}:00 UTC`;
8166
+ if (!s.enabled) return color.dim(`not on their own (kvbox ${spec.command} backup schedule ${name} --on, at ${at})`);
8167
+ const nextMs = s.nextAt === null ? null : Date.parse(s.nextAt) - now;
8168
+ const next = s.nextAt === null || nextMs === null ? "" : nextMs > -6e4 ? `, next in ${inHours(nextMs)}` : `, ${color.yellow(`due since ${s.nextAt.slice(0, 16).replace("T", " ")} UTC, waiting for the backup job`)}`;
8169
+ const failed = s.lastError !== null ? color.yellow(` last one failed: ${s.lastError}`) : "";
8170
+ return `daily at ${at}${next}${failed}`;
8171
+ }
8172
+ function inHours(ms) {
8173
+ const min = Math.max(0, Math.round(ms / 6e4));
8174
+ if (min < 60) return `${min}m`;
8175
+ const h = Math.floor(min / 60);
8176
+ return h < 24 ? `${h}h ${min % 60}m` : `${Math.floor(h / 24)}d ${h % 24}h`;
8177
+ }
7750
8178
  function printRows3(rows2) {
7751
8179
  const width2 = Math.max(...rows2.map(([label]) => label.length));
7752
8180
  for (const [label, value] of rows2) process.stdout.write(`${color.dim(label.padEnd(width2))} ${value}
@@ -7770,25 +8198,184 @@ function parseStorage(text2, flag) {
7770
8198
  return Number(m[1]);
7771
8199
  }
7772
8200
 
8201
+ // src/commands/managed/backup/create.ts
8202
+ var createCommand10 = (spec) => new Command101("create").description("back up a database to the kvbox cloud (encrypted)").argument("<db>", "its 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) => {
8203
+ const client = await managedClient(cmd);
8204
+ const ls = `kvbox ${spec.command} backup ls ${name}`;
8205
+ try {
8206
+ const started = await client.createManagedBackup(spec.kind, name);
8207
+ if (!opts.wait) {
8208
+ if (opts.json) json(started);
8209
+ else {
8210
+ info(`${color.green("\u2713")} backup ${started.id} of database ${color.bold(name)} started; it runs in the background`);
8211
+ info(color.dim(` status: ${ls}`));
8212
+ await printCost(client, false, true);
8213
+ }
8214
+ return;
8215
+ }
8216
+ const done = await spin(`backing up database ${name}\u2026`, untilSettled(() => client.managedBackup(spec.kind, name, started.id), `database ${name}`, started.id, ls));
8217
+ if (opts.json) json(done);
8218
+ if (done.status === "failed") throw new KvboxError(`backup ${done.id} of database ${name} failed: ${done.error ?? "no reason given"}`);
8219
+ if (opts.json) return;
8220
+ info(`${color.green("\u2713")} backup ${done.id} of database ${color.bold(name)}: ${sizeLine(done)}`);
8221
+ info(color.dim(` restore with: kvbox ${spec.command} backup restore ${name} ${done.id}`));
8222
+ await printCost(client, true, true);
8223
+ } finally {
8224
+ await client.close();
8225
+ }
8226
+ });
8227
+
8228
+ // src/commands/managed/backup/ls.ts
8229
+ import { Command as Command102 } from "commander";
8230
+ var lsCommand16 = (spec) => {
8231
+ const removedOnes = async (err, name, client) => {
8232
+ if (!(err instanceof CallError && err.status === 404)) throw err;
8233
+ const gone = (await client.listManagedBackups(spec.kind)).filter((b) => b.name === name || `${b.owner}/${b.name}` === name);
8234
+ if (gone.length === 0) throw err;
8235
+ const own = name.includes("/") ? [] : gone.filter((b) => b.owner === me(client));
8236
+ return own.length > 0 ? own : gone;
8237
+ };
8238
+ return new Command102("ls").alias("list").description("list backups: every database's, or one database's").argument("[db]", "its name (default: every database)").option("--json", "print as JSON").action(async (name, opts, cmd) => {
8239
+ const client = await managedClient(cmd);
8240
+ try {
8241
+ const list = name === void 0 ? await client.listManagedBackups(spec.kind) : await client.managedBackups(spec.kind, name).catch((err) => removedOnes(err, name, client));
8242
+ if (opts.json) {
8243
+ json(list);
8244
+ return;
8245
+ }
8246
+ const schedule = name === void 0 ? null : await client.managedBackupSchedule(spec.kind, name).catch(() => null);
8247
+ const footer = () => {
8248
+ if (schedule !== null) info(`${color.dim("on its own:")} ${scheduleText2(spec, name, schedule)}`);
8249
+ };
8250
+ if (list.length === 0) {
8251
+ info(name === void 0 ? `no backups yet; make one with: kvbox ${spec.command} backup create <db>` : `database ${name} has no backups; make one with: kvbox ${spec.command} backup create ${name}`);
8252
+ footer();
8253
+ return;
8254
+ }
8255
+ const anyError = list.some((b) => b.error !== null);
8256
+ const others = [...new Set(list.filter((b) => b.owner !== me(client)).map((b) => b.owner))];
8257
+ table(
8258
+ list.map((b) => ({
8259
+ id: b.id,
8260
+ ...name === void 0 || others.length > 0 ? { database: b.owner === me(client) ? b.name : `${b.owner}/${b.name}` } : {},
8261
+ status: b.status === "ready" ? color.green(b.status) : b.status === "failed" ? color.red(b.status) : color.yellow(b.status),
8262
+ version: b.version,
8263
+ data: b.dataBytes === null ? "-" : gbShort(b.dataBytes),
8264
+ uploaded: b.uploadedBytes === null ? "-" : gbShort(b.uploadedBytes),
8265
+ by: b.scheduled ? color.dim("schedule") : b.createdBy ?? "-",
8266
+ taken: age(b.createdAt),
8267
+ ...anyError ? { error: b.error ?? "" } : {}
8268
+ }))
8269
+ );
8270
+ footer();
8271
+ if (name !== void 0 && others.length > 0) {
8272
+ info(color.dim(`A backup of ${others.join(", ")} makes a database there: kvbox ${spec.command} create <name> --from-backup <id> --org ${others[0]}`));
8273
+ }
8274
+ } finally {
8275
+ await client.close();
8276
+ }
8277
+ });
8278
+ };
8279
+
8280
+ // src/commands/managed/backup/restore.ts
8281
+ import { Command as Command103 } from "commander";
8282
+ var restoreCommand4 = (spec) => new Command103("restore").description("put a backup back: the database's data becomes the backup's (it restarts)").argument("<db>", "its name").argument("<id>", `the backup's id (kvbox ${spec.command} backup ls <db>)`).option("-y, --yes", "do not ask for confirmation").option("--json", "print the database as JSON").action(async (name, id, opts, cmd) => {
8283
+ const client = await managedClient(cmd);
8284
+ try {
8285
+ const backup = await client.managedBackup(spec.kind, name, id);
8286
+ const question = `Restore database ${name} from backup ${backup.id} (${age(backup.createdAt)} ago, ${sizeLine(backup)})? Everything written to it since is lost, and it restarts.`;
8287
+ if (!await confirm(question, opts.yes ?? false)) {
8288
+ info("cancelled");
8289
+ process.exitCode = 1;
8290
+ return;
8291
+ }
8292
+ const restored = await spin(`restoring database ${name} from ${backup.id}\u2026`, client.restoreManagedBackup(spec.kind, name, id));
8293
+ if (opts.json) {
8294
+ json(restored);
8295
+ return;
8296
+ }
8297
+ info(`${color.green("\u2713")} database ${color.bold(name)} restored from backup ${backup.id}; its password is the one it had before the restore`);
8298
+ } finally {
8299
+ await client.close();
8300
+ }
8301
+ });
8302
+
8303
+ // src/commands/managed/backup/rm.ts
8304
+ import { Command as Command104 } from "commander";
8305
+ var rmCommand16 = (spec) => new Command104("rm").alias("remove").description("remove a backup for good (a database's that is gone too)").argument("<db>", "its name").argument("<id>", `the backup's id (kvbox ${spec.command} backup ls <db>)`).option("-y, --yes", "do not ask for confirmation").action(async (name, id, opts, cmd) => {
8306
+ const client = await managedClient(cmd);
8307
+ try {
8308
+ await removeListed(client, await client.listManagedBackups(spec.kind), (b) => b.name, name, id, `database ${name}`, opts.yes ?? false);
8309
+ } finally {
8310
+ await client.close();
8311
+ }
8312
+ });
8313
+
8314
+ // src/commands/managed/backup/schedule.ts
8315
+ import { Command as Command105 } from "commander";
8316
+ var scheduleCommand = (spec) => new Command105("schedule").description("show or change when a database is backed up on its own (daily, UTC)").argument("<db>", "its name").option("--at <hour>", "back it up daily at this hour, 0-23 UTC (turns it on)").option("--off", "stop backing it up on its own").option("--on", "back it up on its own again, at the hour it had").option("--json", "print the schedule as JSON").action(async (name, opts, cmd) => {
8317
+ if (opts.off && (opts.on || opts.at !== void 0)) throw new KvboxError("--off takes neither --on nor --at");
8318
+ const hour = opts.at === void 0 ? void 0 : parseHour(opts.at);
8319
+ const client = await managedClient(cmd);
8320
+ try {
8321
+ const change = { ...opts.off ? { enabled: false } : opts.on ? { enabled: true } : {}, ...hour !== void 0 ? { hour } : {} };
8322
+ const changed = Object.keys(change).length > 0;
8323
+ const schedule = changed ? await client.setManagedBackupSchedule(spec.kind, name, change) : await client.managedBackupSchedule(spec.kind, name);
8324
+ if (opts.json) {
8325
+ json(schedule);
8326
+ return;
8327
+ }
8328
+ info(`${changed ? `${color.green("\u2713")} ` : ""}database ${color.bold(name)}: ${scheduleText2(spec, name, schedule)}`);
8329
+ if (schedule.lastAt !== null) {
8330
+ const last = schedule.lastError !== null ? color.red(`failed: ${schedule.lastError}`) : schedule.lastBackup !== null ? `backup ${schedule.lastBackup}` : "starting a backup";
8331
+ info(color.dim(` last turn ${schedule.lastAt.slice(0, 16).replace("T", " ")} UTC: `) + last);
8332
+ }
8333
+ } finally {
8334
+ await client.close();
8335
+ }
8336
+ });
8337
+ function parseHour(text2) {
8338
+ const m = /^(\d{1,2})(?::00)?$/.exec(text2.trim());
8339
+ const hour = m ? Number(m[1]) : NaN;
8340
+ if (!Number.isInteger(hour) || hour < 0 || hour > 23) throw new KvboxError(`--at ${text2}: an hour of the day, 0-23 (UTC), like 3 or 03:00`);
8341
+ return hour;
8342
+ }
8343
+
8344
+ // src/commands/managed/backup/index.ts
8345
+ var backupCommand4 = (spec) => {
8346
+ const command = new Command106("backup").description("back up a database to the kvbox cloud, list backups, restore or remove one, or change its nightly schedule");
8347
+ for (const make of [createCommand10, lsCommand16, restoreCommand4, rmCommand16, scheduleCommand]) command.addCommand(make(spec).option("--org <slug>", "act in this org (- for your personal databases)"));
8348
+ return command;
8349
+ };
8350
+
7773
8351
  // src/commands/managed/create.ts
8352
+ import { Command as Command107 } from "commander";
8353
+ import { setTimeout as sleep5 } from "timers/promises";
7774
8354
  var READY_WAIT_MS = 9e4;
7775
8355
  var READY_STEP_MS = 2e3;
7776
- var createCommand9 = (spec) => {
7777
- const command = new Command94("create").alias("new").description(`create a ${spec.title} database: a name is all it needs`).argument("<name>", "its name (1-12 chars, lowercase letters, digits and '-'); a linked box reaches it at <name>.<account>.kvbox");
8356
+ var createCommand11 = (spec) => {
8357
+ const command = new Command107("create").alias("new").description(`create a ${spec.title} database: a name is all it needs`).argument("<name>", "its name (1-12 chars, lowercase letters, digits and '-'); a linked box reaches it at <name>.<account>.kvbox");
7778
8358
  for (const o of spec.options) command.option(`--${o.name} <${o.arg}>`, o.help);
7779
- return command.option("--password <password>", "its password (default: generated)").option("--storage <gb>", `storage for the data in GB (default: ${spec.storageGib}; it can grow later)`).option("--near <box>", "run it on the host of this box, so the box can be linked to it").option("--json", "print it as JSON, password included").action(async (name, opts, cmd) => {
8359
+ return command.option("--password <password>", "its password (default: generated)").option("--storage <gb>", `storage for the data in GB (default: ${spec.storageGib}; it can grow later)`).option("--near <box>", "run it on the host of this box, so the box can be linked to it").option("--from-backup <id>", `start it on this backup's data, a removed database's too (kvbox ${spec.command} backup ls)`).option("--json", "print it as JSON, password included").action(async (name, opts, cmd) => {
7780
8360
  const options = Object.fromEntries(spec.options.flatMap((o) => typeof opts[o.name] === "string" ? [[o.name, opts[o.name]]] : []));
7781
8361
  const req = {
7782
8362
  name,
7783
8363
  ...Object.keys(options).length > 0 ? { options } : {},
7784
8364
  ...opts.password !== void 0 ? { password: opts.password } : {},
7785
8365
  ...opts.storage !== void 0 ? { storageGib: parseStorage(opts.storage, "--storage") } : {},
7786
- ...opts.near !== void 0 ? { near: opts.near } : {}
8366
+ ...opts.near !== void 0 ? { near: opts.near } : {},
8367
+ ...opts.fromBackup !== void 0 ? { fromBackup: opts.fromBackup } : {}
7787
8368
  };
7788
8369
  const client = await managedClient(cmd);
7789
8370
  try {
7790
- const made = await spin(`creating ${spec.title} database ${name}\u2026`, client.createManaged(spec.kind, req));
8371
+ const doing = opts.fromBackup === void 0 ? `creating ${spec.title} database ${name}\u2026` : `creating ${spec.title} database ${name} from backup ${opts.fromBackup}\u2026`;
8372
+ const made = await spin(doing, client.createManaged(spec.kind, req));
7791
8373
  const shown = shownName3(made, me(client));
8374
+ if (opts.fromBackup !== void 0 && made.fromBackup === void 0) {
8375
+ throw new KvboxError(
8376
+ `this control plane does not know --from-backup yet: database ${shown} was made empty, not from backup ${opts.fromBackup}; remove it with: kvbox ${spec.command} rm ${shown}`
8377
+ );
8378
+ }
7792
8379
  const ready = await spin(`starting ${spec.title}\u2026`, async () => {
7793
8380
  for (const until2 = Date.now() + READY_WAIT_MS; Date.now() < until2; await sleep5(READY_STEP_MS)) {
7794
8381
  const now = await client.getManaged(spec.kind, shown).catch(() => void 0);
@@ -7800,7 +8387,8 @@ var createCommand9 = (spec) => {
7800
8387
  json({ ...made, ready });
7801
8388
  return;
7802
8389
  }
7803
- info(`${color.green("\u2713")} database ${color.bold(shown)} ${ready ? "is ready" : "is created and still starting"} ${color.dim(`(${spec.title} ${made.version}, ${made.storageGib} GB of storage)`)}`);
8390
+ const restored = made.fromBackup === void 0 ? "" : `, the data of backup ${made.fromBackup}`;
8391
+ info(`${color.green("\u2713")} database ${color.bold(shown)} ${ready ? "is ready" : "is created and still starting"} ${color.dim(`(${spec.title} ${made.version}, ${made.storageGib} GB of storage${restored})`)}`);
7804
8392
  printRows3([...settingRows(spec, made.settings), ...secretRows(made.secret)].map(([label, value]) => [` ${label}`, value]));
7805
8393
  info("");
7806
8394
  info("Nobody can reach it yet. To let something in:");
@@ -7815,8 +8403,8 @@ var createCommand9 = (spec) => {
7815
8403
  };
7816
8404
 
7817
8405
  // src/commands/managed/grow.ts
7818
- import { Command as Command95 } from "commander";
7819
- var growCommand3 = (spec) => new Command95("grow").description("give a database more storage (it restarts once)").argument("<db>", "its name").argument("<GB>", "the new size in GB, larger than what it has").option("--json", "print as JSON").action(async (name, size, opts, cmd) => {
8406
+ import { Command as Command108 } from "commander";
8407
+ var growCommand3 = (spec) => new Command108("grow").description("give a database more storage (it restarts once)").argument("<db>", "its name").argument("<GB>", "the new size in GB, larger than what it has").option("--json", "print as JSON").action(async (name, size, opts, cmd) => {
7820
8408
  const storageGib = parseStorage(size, "size");
7821
8409
  const client = await managedClient(cmd);
7822
8410
  try {
@@ -7829,8 +8417,8 @@ var growCommand3 = (spec) => new Command95("grow").description("give a database
7829
8417
  });
7830
8418
 
7831
8419
  // src/commands/managed/info.ts
7832
- import { Command as Command96 } from "commander";
7833
- var infoCommand3 = (spec) => new Command96("info").alias("get").description("show one database: status, storage used, how to connect").argument("<db>", "its name").option("--json", "print as JSON").action(async (name, opts, cmd) => {
8420
+ import { Command as Command109 } from "commander";
8421
+ var infoCommand3 = (spec) => new Command109("info").alias("get").description("show one database: status, storage used, how to connect").argument("<db>", "its name").option("--json", "print as JSON").action(async (name, opts, cmd) => {
7834
8422
  const client = await managedClient(cmd);
7835
8423
  try {
7836
8424
  const m = await client.getManaged(spec.kind, name);
@@ -7842,8 +8430,8 @@ var infoCommand3 = (spec) => new Command96("info").alias("get").description("sho
7842
8430
  });
7843
8431
 
7844
8432
  // src/commands/managed/link.ts
7845
- import { Command as Command97 } from "commander";
7846
- var linkCommand2 = (spec) => new Command97("link").description("let a box reach a database privately (same host)").argument("<db>", "the database").argument("<box>", "the box that connects to it").option("--json", "print as JSON").action(async (name, box2, opts, cmd) => {
8433
+ import { Command as Command110 } from "commander";
8434
+ var linkCommand2 = (spec) => new Command110("link").description("let a box reach a database privately (same host)").argument("<db>", "the database").argument("<box>", "the box that connects to it").option("--json", "print as JSON").action(async (name, box2, opts, cmd) => {
7847
8435
  const client = await managedClient(cmd);
7848
8436
  try {
7849
8437
  const m = await spin(`linking ${box2} to ${name}\u2026`, client.linkManaged(spec.kind, name, box2));
@@ -7859,7 +8447,7 @@ var linkCommand2 = (spec) => new Command97("link").description("let a box reach
7859
8447
  });
7860
8448
 
7861
8449
  // src/commands/managed/ls.ts
7862
- import { Command as Command98 } from "commander";
8450
+ import { Command as Command111 } from "commander";
7863
8451
  function listRows(items, user, kindColumn) {
7864
8452
  return items.map((m) => ({
7865
8453
  owner: m.owner === user ? "private" : m.owner,
@@ -7873,7 +8461,7 @@ function listRows(items, user, kindColumn) {
7873
8461
  created: age(m.createdAt)
7874
8462
  }));
7875
8463
  }
7876
- var lsCommand15 = (spec) => new Command98("ls").alias("list").description(spec ? `list your ${spec.title} databases` : "list every managed database, whatever its kind").option("-a, --all", "every one on the platform (platform admins only)").option("--json", "print as JSON").action(async (opts, cmd) => {
8464
+ var lsCommand17 = (spec) => new Command111("ls").alias("list").description(spec ? `list your ${spec.title} databases` : "list every managed database, whatever its kind").option("-a, --all", "every one on the platform (platform admins only)").option("--json", "print as JSON").action(async (opts, cmd) => {
7877
8465
  const client = await managedClient(cmd);
7878
8466
  try {
7879
8467
  const items = await client.listManaged(spec?.kind, { all: opts.all });
@@ -7893,8 +8481,8 @@ var lsCommand15 = (spec) => new Command98("ls").alias("list").description(spec ?
7893
8481
  });
7894
8482
 
7895
8483
  // src/commands/managed/password.ts
7896
- import { Command as Command99 } from "commander";
7897
- var passwordCommand = (spec) => new Command99("password").description("show a database's password, or set a new one with --reset").argument("<db>", "its name").option("--reset", "make a new password; the old one stops working").option("--json", "print as JSON").action(async (name, opts, cmd) => {
8484
+ import { Command as Command112 } from "commander";
8485
+ var passwordCommand = (spec) => new Command112("password").description("show a database's password, or set a new one with --reset").argument("<db>", "its name").option("--reset", "make a new password; the old one stops working").option("--json", "print as JSON").action(async (name, opts, cmd) => {
7898
8486
  const client = await managedClient(cmd);
7899
8487
  try {
7900
8488
  const secret = opts.reset ? await spin(`setting a new password on ${name}\u2026`, client.resetManagedPassword(spec.kind, name)) : await client.managedPassword(spec.kind, name);
@@ -7910,8 +8498,8 @@ var passwordCommand = (spec) => new Command99("password").description("show a da
7910
8498
  });
7911
8499
 
7912
8500
  // src/commands/managed/public.ts
7913
- import { Command as Command100 } from "commander";
7914
- var publicCommand = (spec) => new Command100("public").description("open a database to the internet, or close it again").argument("<db>", "its name").argument("<state>", "on: reachable from anywhere with the password; off: only linked boxes").option("--json", "print as JSON").action(async (name, state, opts, cmd) => {
8501
+ import { Command as Command113 } from "commander";
8502
+ var publicCommand = (spec) => new Command113("public").description("open a database to the internet, or close it again").argument("<db>", "its name").argument("<state>", "on: reachable from anywhere with the password; off: only linked boxes").option("--json", "print as JSON").action(async (name, state, opts, cmd) => {
7915
8503
  if (state !== "on" && state !== "off") throw new KvboxError(`write on or off: kvbox ${spec.command} public ${name} on`);
7916
8504
  const client = await managedClient(cmd);
7917
8505
  try {
@@ -7932,8 +8520,8 @@ var publicCommand = (spec) => new Command100("public").description("open a datab
7932
8520
  });
7933
8521
 
7934
8522
  // src/commands/managed/rm.ts
7935
- import { Command as Command101 } from "commander";
7936
- var rmCommand13 = (spec) => new Command101("rm").alias("remove").description("delete a database and all its data").argument("<db>", "its name").option("-y, --yes", "do not ask for confirmation").action(async (name, opts, cmd) => {
8523
+ import { Command as Command114 } from "commander";
8524
+ var rmCommand17 = (spec) => new Command114("rm").alias("remove").description("delete a database and all its data").argument("<db>", "its name").option("-y, --yes", "do not ask for confirmation").action(async (name, opts, cmd) => {
7937
8525
  const client = await managedClient(cmd);
7938
8526
  try {
7939
8527
  if (!await confirm(`Delete database ${name} and all its data? There is no backup.`, opts.yes ?? false)) {
@@ -7949,8 +8537,8 @@ var rmCommand13 = (spec) => new Command101("rm").alias("remove").description("de
7949
8537
  });
7950
8538
 
7951
8539
  // src/commands/managed/start.ts
7952
- import { Command as Command102 } from "commander";
7953
- var startCommand2 = (spec) => new Command102("start").description("run a stopped database again").argument("<db>", "its name").option("--json", "print as JSON").action(async (name, opts, cmd) => {
8540
+ import { Command as Command115 } from "commander";
8541
+ var startCommand2 = (spec) => new Command115("start").description("run a stopped database again").argument("<db>", "its name").option("--json", "print as JSON").action(async (name, opts, cmd) => {
7954
8542
  const client = await managedClient(cmd);
7955
8543
  try {
7956
8544
  const m = await spin(`starting ${name}\u2026`, client.startManaged(spec.kind, name));
@@ -7962,8 +8550,8 @@ var startCommand2 = (spec) => new Command102("start").description("run a stopped
7962
8550
  });
7963
8551
 
7964
8552
  // src/commands/managed/stop.ts
7965
- import { Command as Command103 } from "commander";
7966
- var stopCommand2 = (spec) => new Command103("stop").description("shut a database down, keeping its data (only its storage is charged)").argument("<db>", "its name").option("--json", "print as JSON").action(async (name, opts, cmd) => {
8553
+ import { Command as Command116 } from "commander";
8554
+ var stopCommand2 = (spec) => new Command116("stop").description("shut a database down, keeping its data (only its storage is charged)").argument("<db>", "its name").option("--json", "print as JSON").action(async (name, opts, cmd) => {
7967
8555
  const client = await managedClient(cmd);
7968
8556
  try {
7969
8557
  const m = await spin(`stopping ${name}\u2026`, client.stopManaged(spec.kind, name));
@@ -7975,8 +8563,8 @@ var stopCommand2 = (spec) => new Command103("stop").description("shut a database
7975
8563
  });
7976
8564
 
7977
8565
  // src/commands/managed/unlink.ts
7978
- import { Command as Command104 } from "commander";
7979
- var unlinkCommand2 = (spec) => new Command104("unlink").description("stop a box from reaching a database").argument("<db>", "the database").argument("<box>", "the box that was linked to it").option("--json", "print as JSON").action(async (name, box2, opts, cmd) => {
8566
+ import { Command as Command117 } from "commander";
8567
+ var unlinkCommand2 = (spec) => new Command117("unlink").description("stop a box from reaching a database").argument("<db>", "the database").argument("<box>", "the box that was linked to it").option("--json", "print as JSON").action(async (name, box2, opts, cmd) => {
7980
8568
  const client = await managedClient(cmd);
7981
8569
  try {
7982
8570
  const m = await spin(`unlinking ${box2} from ${name}\u2026`, client.unlinkManaged(spec.kind, name, box2));
@@ -7989,10 +8577,11 @@ var unlinkCommand2 = (spec) => new Command104("unlink").description("stop a box
7989
8577
 
7990
8578
  // src/commands/managed/kind.ts
7991
8579
  function kindCommand(spec, description) {
7992
- const command = new Command105(spec.command).aliases(spec.aliases).description(description);
7993
- for (const make of [createCommand9, lsCommand15, infoCommand3, passwordCommand, publicCommand, linkCommand2, unlinkCommand2, growCommand3, stopCommand2, startCommand2, rmCommand13]) {
8580
+ const command = new Command118(spec.command).aliases(spec.aliases).description(description);
8581
+ for (const make of [createCommand11, lsCommand17, infoCommand3, passwordCommand, publicCommand, linkCommand2, unlinkCommand2, growCommand3, stopCommand2, startCommand2, rmCommand17]) {
7994
8582
  command.addCommand(make(spec).option("--org <slug>", "act in this org (- for your personal databases)"));
7995
8583
  }
8584
+ command.addCommand(backupCommand4(spec));
7996
8585
  return command;
7997
8586
  }
7998
8587
 
@@ -8003,14 +8592,14 @@ var pgCommand = kindCommand(POSTGRES2, "managed PostgreSQL: a database kvbox run
8003
8592
  var redisCommand = kindCommand(REDIS, "managed Redis (Valkey): a Redis kvbox runs for you, private until you link a box or make it public");
8004
8593
 
8005
8594
  // src/commands/managed/index.ts
8006
- import { Command as Command106 } from "commander";
8007
- var managedCommand = new Command106("managed").description(`databases kvbox runs for you, every kind together (${KINDS.map((k) => `${k.title}: kvbox ${k.command}`).join(", ")})`).addCommand(lsCommand15().option("--org <slug>", "act in this org (- for your personal databases)"));
8595
+ import { Command as Command119 } from "commander";
8596
+ var managedCommand = new Command119("managed").description(`databases kvbox runs for you, every kind together (${KINDS.map((k) => `${k.title}: kvbox ${k.command}`).join(", ")})`).addCommand(lsCommand17().option("--org <slug>", "act in this org (- for your personal databases)"));
8008
8597
 
8009
8598
  // src/commands/env/index.ts
8010
- import { Command as Command110 } from "commander";
8599
+ import { Command as Command123 } from "commander";
8011
8600
 
8012
8601
  // src/commands/env/ls.ts
8013
- import { Command as Command107 } from "commander";
8602
+ import { Command as Command120 } from "commander";
8014
8603
 
8015
8604
  // src/commands/env/shared.ts
8016
8605
  function requireCloud4(client) {
@@ -8037,7 +8626,7 @@ function firstBootHint(box2, name) {
8037
8626
  }
8038
8627
 
8039
8628
  // src/commands/env/ls.ts
8040
- var lsCommand16 = new Command107("ls").alias("list").description("list the variables (a secret shows as (sealed))").option("--box <box>", "what this box gets: its own variables and the ones it inherits").option("--json", "print as JSON").action(async (opts, cmd) => {
8629
+ var lsCommand18 = new Command120("ls").alias("list").description("list the variables (a secret shows as (sealed))").option("--box <box>", "what this box gets: its own variables and the ones it inherits").option("--json", "print as JSON").action(async (opts, cmd) => {
8041
8630
  const client = await clientFor(cmd.optsWithGlobals(), { autoStart: false });
8042
8631
  try {
8043
8632
  if (opts.box !== void 0) {
@@ -8076,8 +8665,8 @@ var lsCommand16 = new Command107("ls").alias("list").description("list the varia
8076
8665
  });
8077
8666
 
8078
8667
  // src/commands/env/rm.ts
8079
- import { Command as Command108 } from "commander";
8080
- var rmCommand14 = new Command108("rm").alias("remove").description("remove variables; boxes lose them when they next start").argument("<names...>", "variable names").option("-y, --yes", "do not ask for confirmation").option("--box <box>", "remove this box's own variables (yours, or the org's, of the same name come back)").option("--json", "print as JSON").action(async (names2, opts, cmd) => {
8668
+ import { Command as Command121 } from "commander";
8669
+ var rmCommand18 = new Command121("rm").alias("remove").description("remove variables; boxes lose them when they next start").argument("<names...>", "variable names").option("-y, --yes", "do not ask for confirmation").option("--box <box>", "remove this box's own variables (yours, or the org's, of the same name come back)").option("--json", "print as JSON").action(async (names2, opts, cmd) => {
8081
8670
  const client = await clientFor(cmd.optsWithGlobals(), { autoStart: false });
8082
8671
  try {
8083
8672
  const target = opts.box === void 0 ? void 0 : await findBox2(client, opts.box);
@@ -8114,8 +8703,8 @@ var rmCommand14 = new Command108("rm").alias("remove").description("remove varia
8114
8703
  });
8115
8704
 
8116
8705
  // src/commands/env/set.ts
8117
- import { Command as Command109 } from "commander";
8118
- var setCommand2 = new Command109("set").description("add or change a variable; boxes get it when they next start").argument("[name]", "variable name, e.g. DATABASE_URL (asked for when left out)").argument("[value]", "its value (asked for when left out; hidden with --secret)").option("--secret", "write-only: the value is never shown again, by any command").option("--box <box>", "this box's own variable, over yours (or the org's) of the same name").option("--json", "print as JSON").action(async (nameArg, valueArg, opts, cmd) => {
8706
+ import { Command as Command122 } from "commander";
8707
+ var setCommand2 = new Command122("set").description("add or change a variable; boxes get it when they next start").argument("[name]", "variable name, e.g. DATABASE_URL (asked for when left out)").argument("[value]", "its value (asked for when left out; hidden with --secret)").option("--secret", "write-only: the value is never shown again, by any command").option("--box <box>", "this box's own variable, over yours (or the org's) of the same name").option("--json", "print as JSON").action(async (nameArg, valueArg, opts, cmd) => {
8119
8708
  const client = await clientFor(cmd.optsWithGlobals(), { autoStart: false });
8120
8709
  try {
8121
8710
  const owner = opts.box === void 0 ? requireCloud4(client) : void 0;
@@ -8152,14 +8741,14 @@ var setCommand2 = new Command109("set").description("add or change a variable; b
8152
8741
  });
8153
8742
 
8154
8743
  // src/commands/env/index.ts
8155
- var envCommand = new Command110("env").description("environment variables every box of yours gets when it starts (secrets too)").addCommand(lsCommand16, { isDefault: true }).addCommand(setCommand2).addCommand(rmCommand14);
8744
+ var envCommand = new Command123("env").description("environment variables every box of yours gets when it starts (secrets too)").addCommand(lsCommand18, { isDefault: true }).addCommand(setCommand2).addCommand(rmCommand18);
8156
8745
  for (const cmd of envCommand.commands) cmd.option("--org <slug>", "the org's variables instead of yours");
8157
8746
 
8158
8747
  // src/commands/domain/index.ts
8159
- import { Command as Command114 } from "commander";
8748
+ import { Command as Command127 } from "commander";
8160
8749
 
8161
8750
  // src/commands/domain/add.ts
8162
- import { Command as Command111 } from "commander";
8751
+ import { Command as Command124 } from "commander";
8163
8752
 
8164
8753
  // src/commands/domain/shared.ts
8165
8754
  function requireCloud5(client) {
@@ -8179,7 +8768,7 @@ function hostIn(name, zone) {
8179
8768
  }
8180
8769
 
8181
8770
  // src/commands/domain/add.ts
8182
- var addCommand4 = new Command111("add").description("serve a box at a domain of your own, https://<domain>, with its certificate made for you").argument("<domain>", "a domain you control, like example.com or app.example.com").argument("<box>", "box name").option("--port <port>", "the box port the domain serves (default: the port of its kvbox.app address)").option("--json", "print the domain as JSON").action(async (domainArg, name, opts, cmd) => {
8771
+ var addCommand4 = new Command124("add").description("serve a box at a domain of your own, https://<domain>, with its certificate made for you").argument("<domain>", "a domain you control, like example.com or app.example.com").argument("<box>", "box name").option("--port <port>", "the box port the domain serves (default: the port of its kvbox.app address)").option("--json", "print the domain as JSON").action(async (domainArg, name, opts, cmd) => {
8183
8772
  const domain = assertDomain(domainArg.trim().toLowerCase());
8184
8773
  const port = opts.port === void 0 ? void 0 : parsePorts([opts.port])[0];
8185
8774
  const client = await clientFor(cmd.optsWithGlobals());
@@ -8215,8 +8804,8 @@ kvbox checks every minute; ${domain} is served at ${d.url} once its records are
8215
8804
  });
8216
8805
 
8217
8806
  // src/commands/domain/ls.ts
8218
- import { Command as Command112 } from "commander";
8219
- var lsCommand17 = new Command112("ls").alias("list").description("list your custom domains and whether they are live").option("--json", "print as JSON").action(async (opts, cmd) => {
8807
+ import { Command as Command125 } from "commander";
8808
+ var lsCommand19 = new Command125("ls").alias("list").description("list your custom domains and whether they are live").option("--json", "print as JSON").action(async (opts, cmd) => {
8220
8809
  const client = await clientFor(cmd.optsWithGlobals());
8221
8810
  try {
8222
8811
  requireCloud5(client);
@@ -8245,8 +8834,8 @@ var lsCommand17 = new Command112("ls").alias("list").description("list your cust
8245
8834
  });
8246
8835
 
8247
8836
  // src/commands/domain/rm.ts
8248
- import { Command as Command113 } from "commander";
8249
- var rmCommand15 = new Command113("rm").alias("remove").description("stop serving a box at a custom domain").argument("<domain>", "the domain").option("-y, --yes", "do not ask for confirmation").action(async (domainArg, opts, cmd) => {
8837
+ import { Command as Command126 } from "commander";
8838
+ var rmCommand19 = new Command126("rm").alias("remove").description("stop serving a box at a custom domain").argument("<domain>", "the domain").option("-y, --yes", "do not ask for confirmation").action(async (domainArg, opts, cmd) => {
8250
8839
  const domain = domainArg.trim().toLowerCase();
8251
8840
  const client = await clientFor(cmd.optsWithGlobals());
8252
8841
  try {
@@ -8267,7 +8856,7 @@ var rmCommand15 = new Command113("rm").alias("remove").description("stop serving
8267
8856
  });
8268
8857
 
8269
8858
  // src/commands/domain/index.ts
8270
- var domainCommand = new Command114("domain").alias("domains").description("serve a box at a domain of your own").addCommand(addCommand4).addCommand(lsCommand17).addCommand(rmCommand15);
8859
+ var domainCommand = new Command127("domain").alias("domains").description("serve a box at a domain of your own").addCommand(addCommand4).addCommand(lsCommand19).addCommand(rmCommand19);
8271
8860
  for (const cmd of domainCommand.commands) cmd.option("--org <slug>", "act in this org (- for your personal boxes)");
8272
8861
 
8273
8862
  // src/commands/update.ts
@@ -8275,7 +8864,7 @@ import { spawn as spawn7 } from "child_process";
8275
8864
  import { mkdtempSync, rmSync, writeFileSync as writeFileSync2 } from "fs";
8276
8865
  import { tmpdir } from "os";
8277
8866
  import { join as join9 } from "path";
8278
- import { Command as Command115 } from "commander";
8867
+ import { Command as Command128 } from "commander";
8279
8868
 
8280
8869
  // src/update.ts
8281
8870
  import { mkdirSync, readFileSync as readFileSync3, writeFileSync } from "fs";
@@ -8394,7 +8983,7 @@ function run2(cmd, args) {
8394
8983
  child.on("exit", (code, signal) => resolve4(code ?? (signal ? 1 : 0)));
8395
8984
  });
8396
8985
  }
8397
- var selfUpdateCommand = new Command115("update").description("update kvbox to the latest version (reruns the installer from kvbox.sh, agent skill included)").action(async () => {
8986
+ var selfUpdateCommand = new Command128("update").description("update kvbox to the latest version (reruns the installer from kvbox.sh, agent skill included)").action(async () => {
8398
8987
  suppressUpdateNotice();
8399
8988
  const inst = installerFor(process.platform, process.env["KVBOX_INSTALL_URL"] || INSTALL_BASE);
8400
8989
  let code;
@@ -8521,7 +9110,7 @@ function installRootHelp(program) {
8521
9110
 
8522
9111
  // src/program.ts
8523
9112
  function buildProgram() {
8524
- const program = new Command116("kvbox").description("self-hosted Firecracker microVMs with Docker-like ergonomics").version(VERSION, "-v, --version").option("--local", "use this machine's kvbox-server over its socket, ignoring kvbox login and KVBOX_TOKEN").option("--org <slug>", "the org: where kvbox new creates, and which box a name means when it is not one of yours; before the command here, or after it").showHelpAfterError().enablePositionalOptions();
9113
+ const program = new Command129("kvbox").description("self-hosted Firecracker microVMs with Docker-like ergonomics").version(VERSION, "-v, --version").option("--local", "use this machine's kvbox-server over its socket, ignoring kvbox login and KVBOX_TOKEN").option("--org <slug>", "the org: where kvbox new creates, and which box a name means when it is not one of yours; before the command here, or after it").showHelpAfterError().enablePositionalOptions();
8525
9114
  program.addCommand(vmCommand);
8526
9115
  program.addCommand(snapshotsCommand);
8527
9116
  program.addCommand(volumeCommand);