@kvbox/cli 0.6.0 → 0.6.2

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
@@ -149,7 +149,7 @@ async function spin(message, work, opts = {}) {
149
149
  }
150
150
 
151
151
  // src/program.ts
152
- import { Command as Command95 } from "commander";
152
+ import { Command as Command112 } from "commander";
153
153
 
154
154
  // ../shared/src/version.ts
155
155
  import { createRequire } from "module";
@@ -164,7 +164,7 @@ function versionOf(srcFileUrl, injected) {
164
164
  }
165
165
 
166
166
  // src/version.ts
167
- var VERSION = versionOf(import.meta.url, true ? "0.6.0" : void 0);
167
+ var VERSION = versionOf(import.meta.url, true ? "0.6.2" : void 0);
168
168
 
169
169
  // src/commands/vm/index.ts
170
170
  import { Command as Command37 } from "commander";
@@ -292,7 +292,9 @@ function paths(home = kvboxHome()) {
292
292
  dir,
293
293
  meta: join(dir, "meta.json"),
294
294
  /** The volume itself: a sparse ext4 the guest sees as a whole disk. */
295
- disk: join(dir, "disk.ext4")
295
+ disk: join(dir, "disk.ext4"),
296
+ /** A restore's disk while it downloads (a backup's chunks), renamed over `disk` once complete. */
297
+ restoring: join(dir, "disk.ext4.restore")
296
298
  };
297
299
  },
298
300
  /** Each owner's environment variables as the control plane last sent them (#88): env/<owner>.json, mode 600. */
@@ -435,7 +437,7 @@ import { openSync } from "fs";
435
437
  import { mkdir as mkdir2, readFile as readFile3, stat } from "fs/promises";
436
438
  import { setTimeout as sleep } from "timers/promises";
437
439
  import { Agent, request } from "undici";
438
- import { z as z6 } from "zod";
440
+ import { z as z7 } from "zod";
439
441
 
440
442
  // ../shared/src/api.ts
441
443
  import { z as z2 } from "zod";
@@ -523,6 +525,7 @@ var WakeHookCallSchema = z2.object({
523
525
  reason: z2.string().optional()
524
526
  });
525
527
  var BACKUP_STATUSES = ["running", "ready", "failed"];
528
+ var BACKUP_KINDS = ["box", "volume"];
526
529
  var BackupSchema = z2.object({
527
530
  id: z2.string(),
528
531
  owner: z2.string(),
@@ -570,6 +573,31 @@ var HostRestoreRequest = z2.object({
570
573
  /** The certificate fingerprint of the store the URLs point at (see HostUploadRequest). */
571
574
  pin: z2.string().optional()
572
575
  });
576
+ var VolumeBackupSchema = z2.object({
577
+ id: z2.string(),
578
+ owner: z2.string(),
579
+ volume: z2.string(),
580
+ status: z2.enum(BACKUP_STATUSES),
581
+ /** Why it failed; null otherwise. */
582
+ error: z2.string().nullable(),
583
+ /** The volume's size when taken. */
584
+ diskBytes: z2.number().int().nullable(),
585
+ /** What it holds: the slots that are not all zeros. */
586
+ dataBytes: z2.number().int().nullable(),
587
+ /** What this backup added to storage (encrypted, compressed): the chunks no earlier backup had. */
588
+ uploadedBytes: z2.number().int().nullable(),
589
+ createdBy: z2.string().nullable(),
590
+ createdAt: z2.string(),
591
+ finishedAt: z2.string().nullable()
592
+ });
593
+ var HostVolumeBackupManifestSchema = z2.object({ id: z2.string(), sizeBytes: z2.number().int(), chunks: z2.array(z2.string().nullable()) });
594
+ var HostVolumeRestoreRequest = z2.object({
595
+ id: z2.string(),
596
+ key: z2.string(),
597
+ sizeBytes: z2.number().int().positive(),
598
+ chunks: z2.array(z2.object({ index: z2.number().int().nonnegative(), hash: z2.string(), url: z2.string() })),
599
+ pin: z2.string().optional()
600
+ });
573
601
  var BackupStoreSetupRequest = z2.object({ path: z2.string().min(1), force: z2.boolean().optional(), newStore: z2.boolean().optional() });
574
602
  var BackupStoreStatusSchema = z2.object({
575
603
  path: z2.string(),
@@ -602,7 +630,38 @@ var CloudBackupStoreSchema = z2.object({
602
630
  freeBytes: z2.number().int().nullable(),
603
631
  /** Ready backups kept here, and what their chunks take (encrypted, compressed). */
604
632
  backups: z2.number().int(),
605
- storedBytes: z2.number().int()
633
+ storedBytes: z2.number().int(),
634
+ /** 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). */
635
+ boxes: z2.number().int(),
636
+ volumes: z2.number().int(),
637
+ /** When the newest ready backup kept here finished; null when it keeps none. */
638
+ lastBackupAt: z2.string().nullable()
639
+ });
640
+ var StoredItemSchema = z2.object({
641
+ kind: z2.enum(BACKUP_KINDS),
642
+ owner: z2.string(),
643
+ name: z2.string(),
644
+ /** The host the box (or volume) is on now; null when it is gone (its backups stay). */
645
+ host: z2.string().nullable(),
646
+ /** It is on the store's own host: losing that host loses it and its backups together. */
647
+ sameHost: z2.boolean(),
648
+ /** Ready backups kept here, and what they added to the store together (encrypted, compressed). */
649
+ backups: z2.number().int(),
650
+ uploadedBytes: z2.number().int(),
651
+ /** The newest backup sent here, whatever became of it. */
652
+ latest: z2.object({ id: z2.string(), status: z2.enum(BACKUP_STATUSES), error: z2.string().nullable(), createdAt: z2.string() })
653
+ });
654
+ var FailedBackupSchema = z2.object({
655
+ id: z2.string(),
656
+ owner: z2.string(),
657
+ /** What it was a backup of: a box or a volume (#168), and its name. */
658
+ kind: z2.enum(BACKUP_KINDS),
659
+ name: z2.string(),
660
+ error: z2.string().nullable(),
661
+ /** 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. */
662
+ host: z2.string().nullable(),
663
+ store: z2.string().nullable(),
664
+ createdAt: z2.string()
606
665
  });
607
666
  var MachineSchema = z2.object({
608
667
  /** Host-unique short id (the tap is `kv-<id>`). Missing only on a box made before ids that has not restarted since. */
@@ -976,6 +1035,17 @@ var VolumeUsageSchema = z2.object({
976
1035
  cost: z2.object({ amount: z2.number(), currency: z2.string() }).optional(),
977
1036
  historyFrom: z2.string().nullable()
978
1037
  });
1038
+ var CronUsageSchema = z2.object({
1039
+ id: z2.string(),
1040
+ name: z2.string(),
1041
+ owner: z2.string(),
1042
+ ownerKind: z2.enum(["user", "org"]).optional(),
1043
+ status: z2.enum(["present", "removed"]),
1044
+ hours: z2.number(),
1045
+ cost: z2.object({ amount: z2.number(), currency: z2.string() }).optional(),
1046
+ /** When it was made. */
1047
+ historyFrom: z2.string().nullable()
1048
+ });
979
1049
  var UsageDayItemSchema = z2.object({
980
1050
  id: z2.string(),
981
1051
  name: z2.string(),
@@ -994,7 +1064,9 @@ var UsageDaySchema = z2.object({
994
1064
  boxes: z2.array(UsageDayItemSchema),
995
1065
  volumes: z2.array(UsageDayItemSchema),
996
1066
  /** Object storage that existed that day (#182); absent on a day without any. */
997
- storage: z2.array(UsageDayItemSchema).optional()
1067
+ storage: z2.array(UsageDayItemSchema).optional(),
1068
+ /** Cron services that existed that day (#190); absent on a day without any. */
1069
+ cron: z2.array(UsageDayItemSchema).optional()
998
1070
  });
999
1071
  var UsageReportSchema = z2.object({
1000
1072
  window: z2.object({ from: z2.string(), to: z2.string() }),
@@ -1007,6 +1079,8 @@ var UsageReportSchema = z2.object({
1007
1079
  * included ones, `sizeGib` its whole size. Absent when there is none.
1008
1080
  */
1009
1081
  storage: z2.array(VolumeUsageSchema).optional(),
1082
+ /** Cron services (#190, control plane only): one row per service a slug has or had. Absent when there is none. */
1083
+ cron: z2.array(CronUsageSchema).optional(),
1010
1084
  /** With `?by=day` only, oldest day first. */
1011
1085
  days: z2.array(UsageDaySchema).optional(),
1012
1086
  totals: z2.object({
@@ -1016,7 +1090,7 @@ var UsageReportSchema = z2.object({
1016
1090
  diskGibHours: z2.number(),
1017
1091
  volumeHours: z2.number().optional(),
1018
1092
  volumeGibHours: z2.number().optional(),
1019
- /** Boxes, volumes and object storage together. */
1093
+ /** Boxes, volumes, object storage and cron services together. */
1020
1094
  cost: z2.object({ amount: z2.number(), currency: z2.string() }).optional()
1021
1095
  })
1022
1096
  });
@@ -1302,7 +1376,9 @@ var PricingSchema = z3.object({
1302
1376
  */
1303
1377
  storageHour: z3.number().nonnegative().default(0),
1304
1378
  storageGibHour: z3.number().nonnegative().default(0),
1305
- storageIncludedGib: z3.number().int().nonnegative().default(0)
1379
+ storageIncludedGib: z3.number().int().nonnegative().default(0),
1380
+ /** The cron service (#190): an hour of one cron service existing, whatever it holds or fires. A price list from before it charges nothing. */
1381
+ cronHour: z3.number().nonnegative().default(0)
1306
1382
  });
1307
1383
  var PriceListSchema = PricingSchema.extend({ welcomeCredit: z3.number().nonnegative() });
1308
1384
  var HOUR_MS = 36e5;
@@ -1418,61 +1494,137 @@ var SetPublicRequest = z4.object({ on: z4.boolean() });
1418
1494
  var ManagedLinkRequest = z4.object({ box: z4.string() });
1419
1495
  var GrowManagedRequest = z4.object({ storageGib: z4.number().int() });
1420
1496
 
1421
- // ../shared/src/storage.ts
1497
+ // ../shared/src/cron.ts
1422
1498
  import { z as z5 } from "zod";
1423
- var RegionSchema = z5.object({ name: z5.string(), country: z5.string().nullable() });
1424
- var ObjectStorageSchema = z5.object({
1499
+ var CRON_METHODS = ["GET", "POST"];
1500
+ var CRON_OUTCOMES = ["running", "ok", "failed", "timeout", "no-credit", "box-stopped", "host-down", "host-outdated", "lost"];
1501
+ var CronServiceSchema = z5.object({
1425
1502
  owner: z5.string(),
1426
1503
  ownerKind: z5.enum(["user", "org"]),
1427
- /** `https://s3-<slug>.<domain>`: what an S3 client is given, with path-style addressing. Null while the address is not claimed. */
1428
- endpoint: z5.string().nullable(),
1429
- /** The S3 region every client of it signs with (`ro-west-1`): its host's when it was made. */
1430
- region: z5.string(),
1431
- /** The most it may hold. */
1432
- sizeGib: z5.number().int(),
1433
- /** `running` when it answers; `unknown` while its host is not heard from. */
1434
- status: BoxStatusSchema,
1435
- /** With `?live=1`, when the storage answered: what is on its disk, and the disk's real size. */
1436
- usedBytes: z5.number().optional(),
1437
- totalBytes: z5.number().optional(),
1438
- host: z5.string(),
1439
- country: z5.string().optional(),
1440
- buckets: z5.number().int(),
1441
- price: z5.object({ perMonth: z5.number(), currency: z5.string() }),
1442
- createdAt: z5.string()
1443
- });
1444
- var BucketSchema = z5.object({
1445
1504
  name: z5.string(),
1446
- owner: z5.string(),
1447
- ownerKind: z5.enum(["user", "org"]),
1448
- endpoint: z5.string().nullable(),
1449
- region: z5.string(),
1450
- keys: z5.number().int(),
1451
- objects: z5.number().optional(),
1452
- bytes: z5.number().optional(),
1505
+ /** Runs kept per trigger. */
1506
+ keepRuns: z5.number().int(),
1507
+ triggers: z5.number().int(),
1453
1508
  createdBy: z5.string().nullable(),
1454
- createdAt: z5.string()
1455
- });
1456
- var CreateBucketRequest = z5.object({
1457
- name: z5.string(),
1458
- sizeGib: z5.number().int().optional(),
1459
- near: z5.string().optional(),
1460
- region: z5.string().optional()
1509
+ createdAt: z5.string(),
1510
+ /** What it costs while it exists; on the answer to `POST /cron` only. */
1511
+ price: z5.object({ perMonth: z5.number(), currency: z5.string() }).optional()
1461
1512
  });
1462
- var CreatedBucketSchema = BucketSchema.extend({ storage: ObjectStorageSchema, storageCreated: z5.boolean() });
1463
- var BucketInfoSchema = BucketSchema.extend({ storage: ObjectStorageSchema });
1464
- var BucketKeySchema = z5.object({
1513
+ var CronTriggerSchema = z5.object({
1465
1514
  id: z5.string(),
1466
- name: z5.string(),
1467
- bucket: z5.string(),
1515
+ service: z5.string(),
1468
1516
  owner: z5.string(),
1469
- readOnly: z5.boolean(),
1517
+ /** The box the request goes to; a trigger is removed with its box. */
1518
+ box: z5.string(),
1519
+ /** Five fields, `minute hour day-of-month month day-of-week`. */
1520
+ expr: z5.string(),
1521
+ /** An IANA zone (`Europe/Bucharest`) the expression is read in; `UTC` unless said. */
1522
+ timezone: z5.string(),
1523
+ method: z5.enum(CRON_METHODS),
1524
+ port: z5.number().int(),
1525
+ /** Path and query, starting with `/`. */
1526
+ path: z5.string(),
1527
+ /** False: paused, it fires again when resumed. */
1528
+ enabled: z5.boolean(),
1529
+ /** When it fires next (ISO); null while paused. */
1530
+ nextRunAt: z5.string().nullable(),
1531
+ lastRunAt: z5.string().nullable(),
1532
+ lastOutcome: z5.enum(CRON_OUTCOMES).nullable(),
1470
1533
  createdBy: z5.string().nullable(),
1471
1534
  createdAt: z5.string()
1472
1535
  });
1473
- var CreateBucketKeyRequest = z5.object({ name: z5.string().optional(), readOnly: z5.boolean().optional() });
1474
- var CreatedBucketKeySchema = BucketKeySchema.extend({ secret: z5.string(), endpoint: z5.string().nullable(), region: z5.string() });
1475
- var GrowStorageRequest = z5.object({ sizeGib: z5.number().int() });
1536
+ var CronRunSchema = z5.object({
1537
+ /** The slot this run was for (ISO); a run asked for by hand has the moment it was asked. */
1538
+ scheduledFor: z5.string(),
1539
+ startedAt: z5.string(),
1540
+ /** Null while `running`, and for a run that was never sent. */
1541
+ durationMs: z5.number().int().nullable(),
1542
+ /** The box's HTTP status; null when it never answered. */
1543
+ status: z5.number().int().nullable(),
1544
+ outcome: z5.enum(CRON_OUTCOMES),
1545
+ /** Why it did not end `ok`, in a line. */
1546
+ error: z5.string().nullable(),
1547
+ /** The box was hibernated and this run woke it. */
1548
+ woke: z5.boolean()
1549
+ });
1550
+ var CronCatalogSchema = z5.object({
1551
+ price: z5.object({ perMonth: z5.number(), currency: z5.string() }),
1552
+ maxServices: z5.number().int(),
1553
+ maxTriggers: z5.number().int(),
1554
+ keepRuns: z5.number().int(),
1555
+ /** The shortest time between two runs of one trigger, in seconds. */
1556
+ minIntervalSeconds: z5.number().int(),
1557
+ /** How long a box has to answer, in seconds. */
1558
+ timeoutSeconds: z5.number().int(),
1559
+ docs: z5.string().optional()
1560
+ });
1561
+ var CreateCronServiceRequest = z5.object({ name: z5.string() });
1562
+ var CreateCronTriggerRequest = z5.object({
1563
+ box: z5.string().min(1),
1564
+ expr: z5.string().min(1),
1565
+ timezone: z5.string().optional(),
1566
+ method: z5.enum(CRON_METHODS).optional(),
1567
+ port: z5.number().int().min(1).max(65535),
1568
+ path: z5.string().optional()
1569
+ });
1570
+ var UpdateCronTriggerRequest = z5.object({ enabled: z5.boolean() });
1571
+ var cronTarget = (t) => `${t.method} ${t.box}:${t.port}${t.path}`;
1572
+
1573
+ // ../shared/src/storage.ts
1574
+ import { z as z6 } from "zod";
1575
+ var RegionSchema = z6.object({ name: z6.string(), country: z6.string().nullable() });
1576
+ var ObjectStorageSchema = z6.object({
1577
+ owner: z6.string(),
1578
+ ownerKind: z6.enum(["user", "org"]),
1579
+ /** `https://s3-<slug>.<domain>`: what an S3 client is given, with path-style addressing. Null while the address is not claimed. */
1580
+ endpoint: z6.string().nullable(),
1581
+ /** The S3 region every client of it signs with (`ro-west-1`): its host's when it was made. */
1582
+ region: z6.string(),
1583
+ /** The most it may hold. */
1584
+ sizeGib: z6.number().int(),
1585
+ /** `running` when it answers; `unknown` while its host is not heard from. */
1586
+ status: BoxStatusSchema,
1587
+ /** With `?live=1`, when the storage answered: what is on its disk, and the disk's real size. */
1588
+ usedBytes: z6.number().optional(),
1589
+ totalBytes: z6.number().optional(),
1590
+ host: z6.string(),
1591
+ country: z6.string().optional(),
1592
+ buckets: z6.number().int(),
1593
+ price: z6.object({ perMonth: z6.number(), currency: z6.string() }),
1594
+ createdAt: z6.string()
1595
+ });
1596
+ var BucketSchema = z6.object({
1597
+ name: z6.string(),
1598
+ owner: z6.string(),
1599
+ ownerKind: z6.enum(["user", "org"]),
1600
+ endpoint: z6.string().nullable(),
1601
+ region: z6.string(),
1602
+ keys: z6.number().int(),
1603
+ objects: z6.number().optional(),
1604
+ bytes: z6.number().optional(),
1605
+ createdBy: z6.string().nullable(),
1606
+ createdAt: z6.string()
1607
+ });
1608
+ var CreateBucketRequest = z6.object({
1609
+ name: z6.string(),
1610
+ sizeGib: z6.number().int().optional(),
1611
+ near: z6.string().optional(),
1612
+ region: z6.string().optional()
1613
+ });
1614
+ var CreatedBucketSchema = BucketSchema.extend({ storage: ObjectStorageSchema, storageCreated: z6.boolean() });
1615
+ var BucketInfoSchema = BucketSchema.extend({ storage: ObjectStorageSchema });
1616
+ var BucketKeySchema = z6.object({
1617
+ id: z6.string(),
1618
+ name: z6.string(),
1619
+ bucket: z6.string(),
1620
+ owner: z6.string(),
1621
+ readOnly: z6.boolean(),
1622
+ createdBy: z6.string().nullable(),
1623
+ createdAt: z6.string()
1624
+ });
1625
+ var CreateBucketKeyRequest = z6.object({ name: z6.string().optional(), readOnly: z6.boolean().optional() });
1626
+ var CreatedBucketKeySchema = BucketKeySchema.extend({ secret: z6.string(), endpoint: z6.string().nullable(), region: z6.string() });
1627
+ var GrowStorageRequest = z6.object({ sizeGib: z6.number().int() });
1476
1628
 
1477
1629
  // src/kvm.ts
1478
1630
  import { accessSync, constants, readFileSync, statSync } from "fs";
@@ -1628,7 +1780,7 @@ var ServerClient = class {
1628
1780
  * `all`: every box on the platform (platform admins only, #78).
1629
1781
  */
1630
1782
  listMachines(opts = {}) {
1631
- return this.call("GET", `/machines${allQuery(opts)}`, z6.array(MachineSchema), void 0, opts.org);
1783
+ return this.call("GET", `/machines${allQuery(opts)}`, z7.array(MachineSchema), void 0, opts.org);
1632
1784
  }
1633
1785
  createMachine(req) {
1634
1786
  return this.call("POST", "/machines", MachineSchema, req);
@@ -1682,10 +1834,10 @@ var ServerClient = class {
1682
1834
  }
1683
1835
  /** Backups, the control plane's only: a box's disk in object storage. Newest first. */
1684
1836
  listBackups() {
1685
- return this.call("GET", "/backups", z6.array(BackupSchema));
1837
+ return this.call("GET", "/backups", z7.array(BackupSchema));
1686
1838
  }
1687
1839
  boxBackups(name) {
1688
- return this.call("GET", `/machines/${encodeURIComponent(name)}/backups`, z6.array(BackupSchema));
1840
+ return this.call("GET", `/machines/${encodeURIComponent(name)}/backups`, z7.array(BackupSchema));
1689
1841
  }
1690
1842
  boxBackup(name, id) {
1691
1843
  return this.call("GET", `/machines/${encodeURIComponent(name)}/backups/${encodeURIComponent(id)}`, BackupSchema);
@@ -1694,13 +1846,31 @@ var ServerClient = class {
1694
1846
  createBoxBackup(name) {
1695
1847
  return this.call("POST", `/machines/${encodeURIComponent(name)}/backups`, BackupSchema);
1696
1848
  }
1849
+ /** A volume's backups (#168): the same as a box's, of the volume's disk. Newest first. */
1850
+ listVolumeBackups() {
1851
+ return this.call("GET", "/backups?kind=volume", z7.array(VolumeBackupSchema));
1852
+ }
1853
+ volumeBackups(name) {
1854
+ return this.call("GET", `/volumes/${encodeURIComponent(name)}/backups`, z7.array(VolumeBackupSchema));
1855
+ }
1856
+ volumeBackup(name, id) {
1857
+ return this.call("GET", `/volumes/${encodeURIComponent(name)}/backups/${encodeURIComponent(id)}`, VolumeBackupSchema);
1858
+ }
1859
+ /** Starts one; it runs in the background (`running`), `volumeBackup` says how it ended. */
1860
+ createVolumeBackup(name) {
1861
+ return this.call("POST", `/volumes/${encodeURIComponent(name)}/backups`, VolumeBackupSchema);
1862
+ }
1863
+ /** The volume's disk becomes the backup's; a running box that holds it restarts. Waits for the whole download. */
1864
+ restoreVolumeBackup(name, id) {
1865
+ return this.call("POST", `/volumes/${encodeURIComponent(name)}/backups/${encodeURIComponent(id)}/restore`, VolumeSchema, {}, void 0, 2 * 36e5);
1866
+ }
1697
1867
  /** The box's disk becomes the backup's; a running box restarts. Waits for the whole download. */
1698
1868
  restoreBoxBackup(name, id) {
1699
1869
  return this.call("POST", `/machines/${encodeURIComponent(name)}/backups/${encodeURIComponent(id)}/restore`, MachineSchema, {}, void 0, 2 * 36e5);
1700
1870
  }
1701
1871
  /** Wake hooks (#101), the control plane's only: a URL and a secret that wake the box. */
1702
1872
  boxHooks(name) {
1703
- return this.call("GET", `/machines/${encodeURIComponent(name)}/hooks`, z6.array(WakeHookSchema));
1873
+ return this.call("GET", `/machines/${encodeURIComponent(name)}/hooks`, z7.array(WakeHookSchema));
1704
1874
  }
1705
1875
  createBoxHook(name) {
1706
1876
  return this.call("POST", `/machines/${encodeURIComponent(name)}/hooks`, CreatedWakeHookSchema);
@@ -1728,7 +1898,7 @@ var ServerClient = class {
1728
1898
  }
1729
1899
  /** Every readable box's subdomains, one entry each. */
1730
1900
  listSubdomains() {
1731
- return this.call("GET", "/subdomains", z6.array(SubdomainSchema));
1901
+ return this.call("GET", "/subdomains", z7.array(SubdomainSchema));
1732
1902
  }
1733
1903
  /** Custom domains (#89), the control plane's only: serve the box at the user's own name. */
1734
1904
  addDomain(name, req) {
@@ -1739,7 +1909,7 @@ var ServerClient = class {
1739
1909
  }
1740
1910
  /** Every readable box's custom domains. */
1741
1911
  listDomains() {
1742
- return this.call("GET", "/domains", z6.array(DomainSchema));
1912
+ return this.call("GET", "/domains", z7.array(DomainSchema));
1743
1913
  }
1744
1914
  /** A running box's own load, memory and disk, asked of its guest (#67). */
1745
1915
  machineStats(name) {
@@ -1751,11 +1921,11 @@ var ServerClient = class {
1751
1921
  return this.call("GET", `/machines/${encodeURIComponent(name)}/usage${query}`, MachineUsageSchema);
1752
1922
  }
1753
1923
  /** Every box of the caller over the window (#41 on a host, #42 through a control plane); dates as the user wrote them. */
1754
- usageReport(since, until, all = false) {
1924
+ usageReport(since, until2, all = false) {
1755
1925
  const q = new URLSearchParams();
1756
1926
  if (all) q.set("all", "1");
1757
1927
  if (since !== void 0) q.set("since", since);
1758
- if (until !== void 0) q.set("until", until);
1928
+ if (until2 !== void 0) q.set("until", until2);
1759
1929
  const query = q.size === 0 ? "" : `?${q.toString()}`;
1760
1930
  return this.call("GET", `/usage${query}`, UsageReportSchema);
1761
1931
  }
@@ -1768,22 +1938,22 @@ var ServerClient = class {
1768
1938
  return this.call("POST", "/billing/redeem", RedeemResponseSchema, { code });
1769
1939
  }
1770
1940
  deleteMachine(name) {
1771
- return this.call("DELETE", `/machines/${encodeURIComponent(name)}`, z6.undefined());
1941
+ return this.call("DELETE", `/machines/${encodeURIComponent(name)}`, z7.undefined());
1772
1942
  }
1773
1943
  /** Like `listMachines`, for snapshots. */
1774
1944
  listSnapshots(opts = {}) {
1775
- return this.call("GET", `/snapshots${allQuery(opts)}`, z6.array(SnapshotSchema), void 0, opts.org);
1945
+ return this.call("GET", `/snapshots${allQuery(opts)}`, z7.array(SnapshotSchema), void 0, opts.org);
1776
1946
  }
1777
1947
  createSnapshot(req) {
1778
1948
  return this.call("POST", "/snapshots", SnapshotSchema, req);
1779
1949
  }
1780
1950
  deleteSnapshot(name) {
1781
- return this.call("DELETE", `/snapshots/${encodeURIComponent(name)}`, z6.undefined());
1951
+ return this.call("DELETE", `/snapshots/${encodeURIComponent(name)}`, z7.undefined());
1782
1952
  }
1783
1953
  // ---- environment variables (#88), a control plane only: the caller's slug, or `--org`'s ----
1784
1954
  /** `org`: that org's list instead of `--org`'s (or the caller's own). */
1785
1955
  listEnv(org) {
1786
- return this.call("GET", "/vars", z6.array(EnvVarSchema), void 0, org);
1956
+ return this.call("GET", "/vars", z7.array(EnvVarSchema), void 0, org);
1787
1957
  }
1788
1958
  setEnv(name, req) {
1789
1959
  return this.call("PUT", `/vars/${encodeURIComponent(name)}`, EnvChangeSchema, req);
@@ -1803,13 +1973,13 @@ var ServerClient = class {
1803
1973
  }
1804
1974
  // ---- volumes (#52) ----
1805
1975
  listVolumes(opts = {}) {
1806
- return this.call("GET", `/volumes${allQuery(opts)}`, z6.array(VolumeSchema), void 0, opts.org);
1976
+ return this.call("GET", `/volumes${allQuery(opts)}`, z7.array(VolumeSchema), void 0, opts.org);
1807
1977
  }
1808
1978
  createVolume(req) {
1809
1979
  return this.call("POST", "/volumes", VolumeSchema, req);
1810
1980
  }
1811
1981
  deleteVolume(name) {
1812
- return this.call("DELETE", `/volumes/${encodeURIComponent(name)}`, z6.undefined());
1982
+ return this.call("DELETE", `/volumes/${encodeURIComponent(name)}`, z7.undefined());
1813
1983
  }
1814
1984
  /** Both answer with the box as it is afterwards (restarted when it was running). */
1815
1985
  attachVolume(name, req) {
@@ -1822,9 +1992,42 @@ var ServerClient = class {
1822
1992
  resizeVolume(name, sizeGib) {
1823
1993
  return this.call("POST", `/volumes/${encodeURIComponent(name)}/resize`, VolumeSchema, { sizeGib });
1824
1994
  }
1995
+ // ---- cron service (#190): the control plane's alone ----
1996
+ listCronServices(opts = {}) {
1997
+ return this.call("GET", `/cron${allQuery(opts)}`, z7.array(CronServiceSchema), void 0, opts.org);
1998
+ }
1999
+ createCronService(name) {
2000
+ return this.call("POST", "/cron", CronServiceSchema, { name });
2001
+ }
2002
+ getCronService(name) {
2003
+ return this.call("GET", `/cron/${encodeURIComponent(name)}`, CronServiceSchema);
2004
+ }
2005
+ deleteCronService(name) {
2006
+ return this.call("DELETE", `/cron/${encodeURIComponent(name)}`, z7.undefined());
2007
+ }
2008
+ listCronTriggers(service) {
2009
+ return this.call("GET", `/cron/${encodeURIComponent(service)}/triggers`, z7.array(CronTriggerSchema));
2010
+ }
2011
+ addCronTrigger(service, req) {
2012
+ return this.call("POST", `/cron/${encodeURIComponent(service)}/triggers`, CronTriggerSchema, req);
2013
+ }
2014
+ /** Pause (false) or resume (true). */
2015
+ setCronTriggerEnabled(service, id, enabled2) {
2016
+ return this.call("PATCH", `/cron/${encodeURIComponent(service)}/triggers/${encodeURIComponent(id)}`, CronTriggerSchema, { enabled: enabled2 });
2017
+ }
2018
+ deleteCronTrigger(service, id) {
2019
+ return this.call("DELETE", `/cron/${encodeURIComponent(service)}/triggers/${encodeURIComponent(id)}`, z7.undefined());
2020
+ }
2021
+ /** Marks it due: kvbox-cron fires it within a few seconds. */
2022
+ runCronTrigger(service, id) {
2023
+ return this.call("POST", `/cron/${encodeURIComponent(service)}/triggers/${encodeURIComponent(id)}/run`, CronTriggerSchema);
2024
+ }
2025
+ listCronRuns(service, id, limit) {
2026
+ return this.call("GET", `/cron/${encodeURIComponent(service)}/triggers/${encodeURIComponent(id)}/runs${limit === void 0 ? "" : `?limit=${limit}`}`, z7.array(CronRunSchema));
2027
+ }
1825
2028
  // ---- object storage (#182): the control plane's alone ----
1826
2029
  listBuckets(opts = {}) {
1827
- return this.call("GET", `/buckets${allQuery(opts)}`, z6.array(BucketSchema), void 0, opts.org);
2030
+ return this.call("GET", `/buckets${allQuery(opts)}`, z7.array(BucketSchema), void 0, opts.org);
1828
2031
  }
1829
2032
  /** The first bucket of a slug also makes its storage: a box boots twice, so this may take a couple of minutes. */
1830
2033
  createBucket(req) {
@@ -1834,19 +2037,19 @@ var ServerClient = class {
1834
2037
  return this.call("GET", `/buckets/${encodeURIComponent(name)}`, BucketInfoSchema);
1835
2038
  }
1836
2039
  deleteBucket(name, force = false) {
1837
- return this.call("DELETE", `/buckets/${encodeURIComponent(name)}${force ? "?force=1" : ""}`, z6.undefined());
2040
+ return this.call("DELETE", `/buckets/${encodeURIComponent(name)}${force ? "?force=1" : ""}`, z7.undefined());
1838
2041
  }
1839
2042
  listBucketKeys(name) {
1840
- return this.call("GET", `/buckets/${encodeURIComponent(name)}/keys`, z6.array(BucketKeySchema));
2043
+ return this.call("GET", `/buckets/${encodeURIComponent(name)}/keys`, z7.array(BucketKeySchema));
1841
2044
  }
1842
2045
  createBucketKey(name, req) {
1843
2046
  return this.call("POST", `/buckets/${encodeURIComponent(name)}/keys`, CreatedBucketKeySchema, req);
1844
2047
  }
1845
2048
  deleteBucketKey(name, id) {
1846
- return this.call("DELETE", `/buckets/${encodeURIComponent(name)}/keys/${encodeURIComponent(id)}`, z6.undefined());
2049
+ return this.call("DELETE", `/buckets/${encodeURIComponent(name)}/keys/${encodeURIComponent(id)}`, z7.undefined());
1847
2050
  }
1848
2051
  listStorage(opts = {}) {
1849
- return this.call("GET", `/storage${allQuery(opts)}`, z6.array(ObjectStorageSchema), void 0, opts.org);
2052
+ return this.call("GET", `/storage${allQuery(opts)}`, z7.array(ObjectStorageSchema), void 0, opts.org);
1850
2053
  }
1851
2054
  growStorage(sizeGib) {
1852
2055
  return this.call("POST", "/storage/grow", ObjectStorageSchema, { sizeGib });
@@ -1856,11 +2059,11 @@ var ServerClient = class {
1856
2059
  return `/managed/${encodeURIComponent(kind)}${name === void 0 ? "" : `/${encodeURIComponent(name)}`}${rest}`;
1857
2060
  }
1858
2061
  managedCatalog() {
1859
- return this.call("GET", "/managed/catalog", z6.array(ManagedCatalogEntrySchema));
2062
+ return this.call("GET", "/managed/catalog", z7.array(ManagedCatalogEntrySchema));
1860
2063
  }
1861
2064
  /** One kind's services, or every kind's when `kind` is left out. */
1862
2065
  listManaged(kind, opts = {}) {
1863
- return this.call("GET", `${kind === void 0 ? "/managed" : this.managedPath(kind)}${allQuery(opts)}`, z6.array(ManagedSchema), void 0, opts.org);
2066
+ return this.call("GET", `${kind === void 0 ? "/managed" : this.managedPath(kind)}${allQuery(opts)}`, z7.array(ManagedSchema), void 0, opts.org);
1864
2067
  }
1865
2068
  createManaged(kind, req) {
1866
2069
  return this.call("POST", this.managedPath(kind), CreatedManagedSchema, req);
@@ -1870,7 +2073,7 @@ var ServerClient = class {
1870
2073
  return this.call("GET", this.managedPath(kind, name), ManagedSchema);
1871
2074
  }
1872
2075
  deleteManaged(kind, name) {
1873
- return this.call("DELETE", this.managedPath(kind, name), z6.undefined());
2076
+ return this.call("DELETE", this.managedPath(kind, name), z7.undefined());
1874
2077
  }
1875
2078
  managedPassword(kind, name) {
1876
2079
  return this.call("GET", this.managedPath(kind, name, "/password"), ManagedSecretSchema);
@@ -1901,14 +2104,14 @@ var ServerClient = class {
1901
2104
  return this.call("POST", "/login", LoginResponseSchema, req);
1902
2105
  }
1903
2106
  logout() {
1904
- return this.call("POST", "/logout", z6.unknown()).then(() => void 0);
2107
+ return this.call("POST", "/logout", z7.unknown()).then(() => void 0);
1905
2108
  }
1906
2109
  me() {
1907
2110
  return this.call("GET", "/me", MeResponseSchema);
1908
2111
  }
1909
2112
  // ---- orgs (`kvbox org …`) ----
1910
2113
  listOrgs() {
1911
- return this.call("GET", "/orgs", z6.array(OrgMembershipSchema));
2114
+ return this.call("GET", "/orgs", z7.array(OrgMembershipSchema));
1912
2115
  }
1913
2116
  createOrg(req) {
1914
2117
  return this.call("POST", "/orgs", CloudOrgSchema, req);
@@ -1917,16 +2120,16 @@ var ServerClient = class {
1917
2120
  return this.call("GET", `/orgs/${encodeURIComponent(slug)}`, OrgDetailSchema);
1918
2121
  }
1919
2122
  deleteOrg(slug) {
1920
- return this.call("DELETE", `/orgs/${encodeURIComponent(slug)}`, z6.undefined());
2123
+ return this.call("DELETE", `/orgs/${encodeURIComponent(slug)}`, z7.undefined());
1921
2124
  }
1922
2125
  addMember(slug, req) {
1923
- return this.call("POST", `/orgs/${encodeURIComponent(slug)}/members`, z6.undefined(), req);
2126
+ return this.call("POST", `/orgs/${encodeURIComponent(slug)}/members`, z7.undefined(), req);
1924
2127
  }
1925
2128
  setRole(slug, username, role) {
1926
- return this.call("PATCH", `/orgs/${encodeURIComponent(slug)}/members/${encodeURIComponent(username)}`, z6.unknown(), { role }).then(() => void 0);
2129
+ return this.call("PATCH", `/orgs/${encodeURIComponent(slug)}/members/${encodeURIComponent(username)}`, z7.unknown(), { role }).then(() => void 0);
1927
2130
  }
1928
2131
  removeMember(slug, username) {
1929
- return this.call("DELETE", `/orgs/${encodeURIComponent(slug)}/members/${encodeURIComponent(username)}`, z6.undefined());
2132
+ return this.call("DELETE", `/orgs/${encodeURIComponent(slug)}/members/${encodeURIComponent(username)}`, z7.undefined());
1930
2133
  }
1931
2134
  /** Sign this machine's key again (#51); the key must be one the user logged in with. */
1932
2135
  sshCert(req) {
@@ -3211,25 +3414,26 @@ function requireCloud3(client) {
3211
3414
  var POLL_MS = 2e3;
3212
3415
  var POLL_TRIES = 30;
3213
3416
  var WAIT_MS = 7 * 36e5;
3214
- async function untilDone(client, box, id, opts = {}) {
3417
+ async function untilSettled(ask, what, id, where, opts = {}) {
3215
3418
  const { pollMs = POLL_MS, tries = POLL_TRIES, waitMs = WAIT_MS } = opts;
3216
- const until = Date.now() + waitMs;
3419
+ const lostTrack = (why) => new KvboxError(`stopped waiting for backup ${id} of ${what} (${why}); it may still be running: ${where}`);
3420
+ const until2 = Date.now() + waitMs;
3217
3421
  let failed = 0;
3218
3422
  for (; ; ) {
3219
3423
  try {
3220
- const b = await client.boxBackup(box, id);
3424
+ const b = await ask();
3221
3425
  if (b.status !== "running") return b;
3222
3426
  failed = 0;
3223
3427
  } catch (err) {
3224
3428
  failed += 1;
3225
- if (failed >= tries) throw lostTrack(box, id, `could not ask how it is doing: ${err.message}`);
3429
+ if (failed >= tries) throw lostTrack(`could not ask how it is doing: ${err.message}`);
3226
3430
  }
3227
- if (Date.now() >= until) throw lostTrack(box, id, "it is taking longer than a backup is given");
3431
+ if (Date.now() >= until2) throw lostTrack("it is taking longer than a backup is given");
3228
3432
  await sleep2(pollMs);
3229
3433
  }
3230
3434
  }
3231
- function lostTrack(box, id, why) {
3232
- return new KvboxError(`stopped waiting for backup ${id} of box ${box} (${why}); it may still be running: kvbox vm backup ls ${box}`);
3435
+ function untilDone(client, box, id, opts = {}) {
3436
+ return untilSettled(() => client.boxBackup(box, id), `box ${box}`, id, `kvbox vm backup ls ${box}`, opts);
3233
3437
  }
3234
3438
  function sizeLine(b) {
3235
3439
  const data = b.dataBytes === null ? "?" : gb(b.dataBytes);
@@ -4126,7 +4330,8 @@ var usageCommand2 = new Command51("usage").description("what your boxes and volu
4126
4330
  info(`${day2(report.window.from)} to ${day2(report.window.to)}`);
4127
4331
  const volumes = report.volumes ?? [];
4128
4332
  const storage = report.storage ?? [];
4129
- if (report.boxes.length === 0 && volumes.length === 0 && storage.length === 0) info("no usage in this window");
4333
+ const cron = report.cron ?? [];
4334
+ if (report.boxes.length === 0 && volumes.length === 0 && storage.length === 0 && cron.length === 0) info("no usage in this window");
4130
4335
  else if (report.boxes.length > 0) table(perUser ? userRows(perUser) : usageRows(report, cloud));
4131
4336
  if (volumes.length > 0) {
4132
4337
  info(volumes.length === 1 ? "1 volume" : `${volumes.length} volumes`);
@@ -4136,8 +4341,12 @@ var usageCommand2 = new Command51("usage").description("what your boxes and volu
4136
4341
  info("object storage");
4137
4342
  table(storageRows(report, cloud));
4138
4343
  }
4139
- if ((volumes.length > 0 || storage.length > 0) && report.totals.cost !== void 0) {
4140
- const what = ["boxes", ...volumes.length > 0 ? ["volumes"] : [], ...storage.length > 0 ? ["object storage"] : []];
4344
+ if (cron.length > 0) {
4345
+ info(cron.length === 1 ? "1 cron service" : `${cron.length} cron services`);
4346
+ table(cronRows(report, cloud));
4347
+ }
4348
+ if ((volumes.length > 0 || storage.length > 0 || cron.length > 0) && report.totals.cost !== void 0) {
4349
+ const what = ["boxes", ...volumes.length > 0 ? ["volumes"] : [], ...storage.length > 0 ? ["object storage"] : [], ...cron.length > 0 ? ["cron services"] : []];
4141
4350
  info(`total: ${money(report.totals.cost.amount, report.totals.cost.currency)} ${color.dim(`(${what.slice(0, -1).join(", ")} and ${what.at(-1)}, estimated)`)}`);
4142
4351
  }
4143
4352
  if (cloud) {
@@ -4229,6 +4438,17 @@ function storageRows(report, cloud) {
4229
4438
  ...priced ? { cost: money(s.cost?.amount ?? 0, currency) } : {}
4230
4439
  }));
4231
4440
  }
4441
+ function cronRows(report, cloud) {
4442
+ const priced = report.totals.cost !== void 0;
4443
+ const currency = report.totals.cost?.currency ?? "";
4444
+ return (report.cron ?? []).map((s) => ({
4445
+ name: s.name,
4446
+ ...cloud ? { owner: ownerCell2(s, cloud.me) } : {},
4447
+ status: s.status === "removed" ? color.dim("removed") : "present",
4448
+ hours: hours(s.hours),
4449
+ ...priced ? { cost: money(s.cost?.amount ?? 0, currency) } : {}
4450
+ }));
4451
+ }
4232
4452
  function byUser(report) {
4233
4453
  const groups = /* @__PURE__ */ new Map();
4234
4454
  for (const b of report.boxes) {
@@ -4245,7 +4465,7 @@ function byUser(report) {
4245
4465
  return u;
4246
4466
  });
4247
4467
  users.sort((a, b) => a.user === null ? 1 : b.user === null ? -1 : a.user.localeCompare(b.user));
4248
- return { window: report.window, users, ...report.volumes === void 0 ? {} : { volumes: report.volumes }, ...report.storage === void 0 ? {} : { storage: report.storage }, totals: report.totals };
4468
+ 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 };
4249
4469
  }
4250
4470
  function userRows(r) {
4251
4471
  const priced = r.totals.cost !== void 0;
@@ -4327,7 +4547,7 @@ import { Command as Command54, InvalidArgumentError as InvalidArgumentError2, Op
4327
4547
  // src/commands/deploy/config.ts
4328
4548
  import { readFile as readFile6, writeFile as writeFile4 } from "fs/promises";
4329
4549
  import { isAbsolute, join as join6, normalize, relative as relative2 } from "path";
4330
- import { z as z7 } from "zod";
4550
+ import { z as z8 } from "zod";
4331
4551
 
4332
4552
  // src/commands/deploy/templates/docker.ts
4333
4553
  import { readFile as readFile5 } from "fs/promises";
@@ -4751,21 +4971,21 @@ function detectTemplates(pkg, dir = NO_FACTS) {
4751
4971
  var DEPLOY_AUTO_HIBERNATE_SEC = 3600;
4752
4972
  var CONFIG_FILE = "kvbox.json";
4753
4973
  var BOX_NAME_RE = /^[a-z0-9][a-z0-9-]{0,11}$/;
4754
- var DeployConfigSchema = z7.object({
4755
- template: z7.enum(TEMPLATE_IDS),
4756
- name: z7.string().regex(BOX_NAME_RE, "1-12 chars, lowercase letters, digits and '-', starting with a letter or digit"),
4974
+ var DeployConfigSchema = z8.object({
4975
+ template: z8.enum(TEMPLATE_IDS),
4976
+ name: z8.string().regex(BOX_NAME_RE, "1-12 chars, lowercase letters, digits and '-', starting with a letter or digit"),
4757
4977
  /** The org whose box it is; absent for the user's own. */
4758
- org: z7.string().regex(ORG_SLUG_RE, "not an org slug").optional(),
4978
+ org: z8.string().regex(ORG_SLUG_RE, "not an org slug").optional(),
4759
4979
  /** The HTTPS name (`<subdomain>.kvbox.app`); absent when deploying to this machine's own host. */
4760
- subdomain: z7.string().check((ctx) => {
4980
+ subdomain: z8.string().check((ctx) => {
4761
4981
  const problem = subdomainProblem(ctx.value);
4762
4982
  if (problem) ctx.issues.push({ code: "custom", message: problem, input: ctx.value });
4763
4983
  }).optional(),
4764
- size: z7.enum(SIZE_NAMES).optional(),
4984
+ size: z8.enum(SIZE_NAMES).optional(),
4765
4985
  /** The build output directory, relative to the app; the template's default when absent. */
4766
- dist: z7.string().optional(),
4986
+ dist: z8.string().optional(),
4767
4987
  /** The port a Next.js app or Node server serves; the template's (3000) when absent. */
4768
- port: z7.number().int().min(1).max(65535).optional()
4988
+ port: z8.number().int().min(1).max(65535).optional()
4769
4989
  });
4770
4990
  var SERVICE_KEY_RE = /^[a-z][a-z0-9-]{0,19}$/;
4771
4991
  var RESERVED_SERVICE_KEYS = ["app", "agent", "init", "volumes"];
@@ -4777,38 +4997,38 @@ var POSTGRES_PORT = 5432;
4777
4997
  var POSTGRES_IMAGE = "postgres:17";
4778
4998
  var POSTGRES_ENV = "DATABASE_URL";
4779
4999
  var IMAGE_RE = /^[a-z0-9][a-z0-9._/:@-]*$/;
4780
- var ServiceSchema = z7.strictObject({
4781
- template: z7.enum([...TEMPLATE_IDS, POSTGRES]),
5000
+ var ServiceSchema = z8.strictObject({
5001
+ template: z8.enum([...TEMPLATE_IDS, POSTGRES]),
4782
5002
  /** The service's directory, relative to the one holding kvbox.json; every template but postgres has one. */
4783
- dir: z7.string().min(1).optional(),
5003
+ dir: z8.string().min(1).optional(),
4784
5004
  /** A postgres service's image, `postgres:17` when absent (`pgvector/pgvector:pg17` for vectors). */
4785
- image: z7.string().regex(IMAGE_RE, "an image name like postgres:17").optional(),
5005
+ image: z8.string().regex(IMAGE_RE, "an image name like postgres:17").optional(),
4786
5006
  /** The volume (a key of `volumes`) a postgres service keeps its data on. */
4787
- volume: z7.string().optional(),
5007
+ volume: z8.string().optional(),
4788
5008
  /** The box variable a postgres service's URL is written to, `DATABASE_URL` when absent. */
4789
- env: z7.string().optional(),
5009
+ env: z8.string().optional(),
4790
5010
  /** A docker service's build context, relative to kvbox.json, when it is not `dir` (a monorepo built from its root); the Dockerfile stays in `dir`. */
4791
- context: z7.string().min(1).optional(),
4792
- dist: z7.string().optional(),
5011
+ context: z8.string().min(1).optional(),
5012
+ dist: z8.string().optional(),
4793
5013
  /**
4794
5014
  * A command run once per deploy in the service's new version (a docker service: in a container of
4795
5015
  * the new image; node, nextjs: in the new source, installed and built), with the box's variables,
4796
5016
  * before it replaces the running one. Migrations, mostly. A failing one stops that service's deploy.
4797
5017
  */
4798
- release: z7.string().optional(),
5018
+ release: z8.string().optional(),
4799
5019
  /** The box port of a service with its own server; the template's (3000) when absent. */
4800
- port: z7.number().int().min(1).max(65535).optional(),
5020
+ port: z8.number().int().min(1).max(65535).optional(),
4801
5021
  /** The URL paths that go to this service, each with everything under it; the prefix is kept. */
4802
- paths: z7.array(z7.string().regex(ROUTE_RE, "a path like / or /api, no trailing slash")).min(1).optional()
5022
+ paths: z8.array(z8.string().regex(ROUTE_RE, "a path like / or /api, no trailing slash")).min(1).optional()
4803
5023
  });
4804
- var StackConfigSchema = z7.strictObject({
5024
+ var StackConfigSchema = z8.strictObject({
4805
5025
  name: DeployConfigSchema.shape.name.optional(),
4806
5026
  org: DeployConfigSchema.shape.org,
4807
5027
  subdomain: DeployConfigSchema.shape.subdomain,
4808
5028
  size: DeployConfigSchema.shape.size,
4809
5029
  /** The stack's volumes, name to size ("10GB"): made for its box and attached to it on the first deploy that needs one. */
4810
- volumes: z7.record(z7.string(), z7.string()).optional(),
4811
- services: z7.record(z7.string(), ServiceSchema)
5030
+ volumes: z8.record(z8.string(), z8.string()).optional(),
5031
+ services: z8.record(z8.string(), ServiceSchema)
4812
5032
  });
4813
5033
  function volumeGib(text2) {
4814
5034
  const mib = parseMib(text2);
@@ -5257,10 +5477,10 @@ async function deployStack(d) {
5257
5477
  const { dir, opts, client, cloud } = d;
5258
5478
  if (opts.template !== void 0 || opts.port !== void 0) throw new KvboxError(`--template and --port are one app's; with several services each says its own in ${CONFIG_FILE}`);
5259
5479
  const exposed = await exposedPorts(dir, d.stack);
5260
- const portOf = (template) => templateById(template).port;
5261
- pick(stackServices(d.stack, portOf, exposed), opts.only);
5480
+ const portOf2 = (template) => templateById(template).port;
5481
+ pick(stackServices(d.stack, portOf2, exposed), opts.only);
5262
5482
  const config = await settle(d);
5263
- const services = stackServices(config, portOf, exposed);
5483
+ const services = stackServices(config, portOf2, exposed);
5264
5484
  const picked = pick(services, opts.only);
5265
5485
  if (cloud && config.subdomain !== void 0) await refuseOtherAddress(client, { ...config, name: config.name });
5266
5486
  let saved = config;
@@ -5744,7 +5964,7 @@ async function settle2(dir, pkg, facts, saved, opts, orgFlag, cloud) {
5744
5964
  }
5745
5965
 
5746
5966
  // src/commands/volume/index.ts
5747
- import { Command as Command61 } from "commander";
5967
+ import { Command as Command65 } from "commander";
5748
5968
 
5749
5969
  // src/commands/volume/attach.ts
5750
5970
  import { Command as Command55 } from "commander";
@@ -5770,8 +5990,99 @@ var attachCommand = new Command55("attach").description("attach a volume to a bo
5770
5990
  }
5771
5991
  });
5772
5992
 
5773
- // src/commands/volume/create.ts
5993
+ // src/commands/volume/backup/index.ts
5994
+ import { Command as Command59 } from "commander";
5995
+
5996
+ // src/commands/volume/backup/create.ts
5774
5997
  import { Command as Command56 } from "commander";
5998
+ var createCommand3 = new Command56("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 (volume, opts, cmd) => {
5999
+ const client = await clientFor(cmd.optsWithGlobals(), { autoStart: false });
6000
+ try {
6001
+ requireCloud3(client);
6002
+ const started = await client.createVolumeBackup(volume);
6003
+ if (!opts.wait) {
6004
+ if (opts.json) json(started);
6005
+ else {
6006
+ info(`${color.green("\u2713")} backup ${started.id} of volume ${color.bold(volume)} started; it runs in the background`);
6007
+ info(color.dim(` status: kvbox volume backup ls ${volume}`));
6008
+ }
6009
+ return;
6010
+ }
6011
+ const done = await spin(`backing up volume ${volume}\u2026`, untilSettled(() => client.volumeBackup(volume, started.id), `volume ${volume}`, started.id, `kvbox volume backup ls ${volume}`));
6012
+ if (opts.json) json(done);
6013
+ if (done.status === "failed") throw new KvboxError(`backup ${done.id} of volume ${volume} failed: ${done.error ?? "no reason given"}`);
6014
+ if (opts.json) return;
6015
+ info(`${color.green("\u2713")} backup ${done.id} of volume ${color.bold(volume)}: ${sizeLine(done)}`);
6016
+ info(color.dim(` restore with: kvbox volume backup restore ${volume} ${done.id}`));
6017
+ } finally {
6018
+ await client.close();
6019
+ }
6020
+ });
6021
+
6022
+ // src/commands/volume/backup/ls.ts
6023
+ import { Command as Command57 } from "commander";
6024
+ var lsCommand8 = new Command57("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 (volume, opts, cmd) => {
6025
+ const client = await clientFor(cmd.optsWithGlobals(), { autoStart: false });
6026
+ try {
6027
+ requireCloud3(client);
6028
+ const list = volume === void 0 ? await client.listVolumeBackups() : await client.volumeBackups(volume);
6029
+ if (opts.json) {
6030
+ json(list);
6031
+ return;
6032
+ }
6033
+ if (list.length === 0) {
6034
+ info(volume === void 0 ? "no volume backups yet; make one with: kvbox volume backup create <volume>" : `volume ${volume} has no backups; make one with: kvbox volume backup create ${volume}`);
6035
+ return;
6036
+ }
6037
+ const anyError = list.some((b) => b.error !== null);
6038
+ table(
6039
+ list.map((b) => ({
6040
+ id: b.id,
6041
+ ...volume === void 0 ? { volume: b.owner === me(client) ? b.volume : `${b.owner}/${b.volume}` } : {},
6042
+ status: b.status === "ready" ? color.green(b.status) : b.status === "failed" ? color.red(b.status) : color.yellow(b.status),
6043
+ data: b.dataBytes === null ? "-" : gbShort(b.dataBytes),
6044
+ uploaded: b.uploadedBytes === null ? "-" : gbShort(b.uploadedBytes),
6045
+ size: b.diskBytes === null ? "-" : gbShort(b.diskBytes),
6046
+ by: b.createdBy ?? "-",
6047
+ taken: age(b.createdAt),
6048
+ ...anyError ? { error: b.error ?? "" } : {}
6049
+ }))
6050
+ );
6051
+ } finally {
6052
+ await client.close();
6053
+ }
6054
+ });
6055
+
6056
+ // src/commands/volume/backup/restore.ts
6057
+ import { Command as Command58 } from "commander";
6058
+ var restoreCommand2 = new Command58("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 (volume, id, opts, cmd) => {
6059
+ const client = await clientFor(cmd.optsWithGlobals(), { autoStart: false });
6060
+ try {
6061
+ requireCloud3(client);
6062
+ const backup = await client.volumeBackup(volume, id);
6063
+ const question = `Restore volume ${volume} from backup ${backup.id} (${age(backup.createdAt)} ago, ${sizeLine(backup)})? Everything written to it since is lost, and a running box that holds it restarts.`;
6064
+ if (!await confirm(question, opts.yes ?? false)) {
6065
+ info("cancelled");
6066
+ process.exitCode = 1;
6067
+ return;
6068
+ }
6069
+ const restored = await spin(`restoring volume ${volume} from ${backup.id}\u2026`, client.restoreVolumeBackup(volume, id));
6070
+ if (opts.json) {
6071
+ json(restored);
6072
+ return;
6073
+ }
6074
+ info(`${color.green("\u2713")} volume ${color.bold(volume)} restored from backup ${backup.id}${restored.attachedTo ? color.dim(` (box ${restored.attachedTo} was restarted if it was running)`) : ""}`);
6075
+ } finally {
6076
+ await client.close();
6077
+ }
6078
+ });
6079
+
6080
+ // src/commands/volume/backup/index.ts
6081
+ var backupCommand2 = new Command59("backup").description("back up a volume's disk to the kvbox cloud, list backups, restore one").addCommand(createCommand3).addCommand(lsCommand8).addCommand(restoreCommand2);
6082
+ for (const cmd of backupCommand2.commands) cmd.option("--org <slug>", "act in this org (- for your personal volumes)");
6083
+
6084
+ // src/commands/volume/create.ts
6085
+ import { Command as Command60 } from "commander";
5775
6086
  function parseGib2(text2, label = "--size") {
5776
6087
  const mib = parseMib(text2);
5777
6088
  if (mib === void 0 || mib % 1024 !== 0) throw new KvboxError(`${label} ${text2}: write whole GB, like 50 or 50GB`);
@@ -5787,7 +6098,7 @@ function sizeProblem(answer) {
5787
6098
  return err instanceof KvboxError ? err.message.replace(/^--size \S+: /, "") : String(err);
5788
6099
  }
5789
6100
  }
5790
- var createCommand3 = new Command56("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) => {
6101
+ var createCommand4 = new Command60("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) => {
5791
6102
  const ask = interactive();
5792
6103
  if (nameArg === void 0 || opts.size === void 0) askOrUsage("give the name and the size: kvbox volume create <name> --size <gb> --box <box>");
5793
6104
  const name = nameArg ?? await text("Volume name", { validate: (a) => VOLUME_NAME_RE.test(a) ? void 0 : VOLUME_NAME_RULE });
@@ -5820,8 +6131,8 @@ var createCommand3 = new Command56("create").alias("new").description("create a
5820
6131
  });
5821
6132
 
5822
6133
  // src/commands/volume/detach.ts
5823
- import { Command as Command57 } from "commander";
5824
- var detachCommand = new Command57("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) => {
6134
+ import { Command as Command61 } from "commander";
6135
+ var detachCommand = new Command61("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) => {
5825
6136
  if (volumeArg === void 0) askOrUsage("give the volume: kvbox volume detach <volume> [box]");
5826
6137
  const client = await clientFor(cmd.optsWithGlobals());
5827
6138
  try {
@@ -5846,8 +6157,8 @@ var detachCommand = new Command57("detach").description("detach a volume from a
5846
6157
  });
5847
6158
 
5848
6159
  // src/commands/volume/grow.ts
5849
- import { Command as Command58 } from "commander";
5850
- var growCommand = new Command58("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) => {
6160
+ import { Command as Command62 } from "commander";
6161
+ var growCommand = new Command62("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) => {
5851
6162
  const sizeGib = parseGib2(size, "size");
5852
6163
  const client = await clientFor(cmd.optsWithGlobals());
5853
6164
  try {
@@ -5860,8 +6171,8 @@ var growCommand = new Command58("grow").alias("resize").description("make a volu
5860
6171
  });
5861
6172
 
5862
6173
  // src/commands/volume/ls.ts
5863
- import { Command as Command59 } from "commander";
5864
- var lsCommand8 = new Command59("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) => {
6174
+ import { Command as Command63 } from "commander";
6175
+ var lsCommand9 = new Command63("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) => {
5865
6176
  const client = await clientFor(cmd.optsWithGlobals());
5866
6177
  try {
5867
6178
  const cloud = client.target.kind === "cloud";
@@ -5892,8 +6203,8 @@ var lsCommand8 = new Command59("ls").alias("list").description("list volumes: si
5892
6203
  });
5893
6204
 
5894
6205
  // src/commands/volume/rm.ts
5895
- import { Command as Command60 } from "commander";
5896
- var rmCommand7 = new Command60("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) => {
6206
+ import { Command as Command64 } from "commander";
6207
+ var rmCommand7 = new Command64("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) => {
5897
6208
  if (!await confirm(`Delete volume ${name} and everything on it?`, opts.yes ?? false)) {
5898
6209
  info("cancelled");
5899
6210
  process.exitCode = 1;
@@ -5909,14 +6220,15 @@ var rmCommand7 = new Command60("rm").alias("remove").description("delete a volum
5909
6220
  });
5910
6221
 
5911
6222
  // src/commands/volume/index.ts
5912
- var volumeCommand = new Command61("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(createCommand3).addCommand(lsCommand8).addCommand(attachCommand).addCommand(detachCommand).addCommand(growCommand).addCommand(rmCommand7);
6223
+ var volumeCommand = new Command65("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(createCommand4).addCommand(lsCommand9).addCommand(attachCommand).addCommand(detachCommand).addCommand(growCommand).addCommand(rmCommand7);
5913
6224
  for (const cmd of volumeCommand.commands) cmd.option("--org <slug>", "act in this org (- for your personal volumes)");
6225
+ volumeCommand.addCommand(backupCommand2);
5914
6226
 
5915
6227
  // src/commands/bucket/index.ts
5916
- import { Command as Command71 } from "commander";
6228
+ import { Command as Command75 } from "commander";
5917
6229
 
5918
6230
  // src/commands/bucket/create.ts
5919
- import { Command as Command62 } from "commander";
6231
+ import { Command as Command66 } from "commander";
5920
6232
 
5921
6233
  // src/commands/bucket/shared.ts
5922
6234
  async function bucketClient(cmd) {
@@ -5942,7 +6254,7 @@ function printRows(rows2) {
5942
6254
  }
5943
6255
 
5944
6256
  // src/commands/bucket/create.ts
5945
- var createCommand4 = new Command62("create").description("make a bucket (the first one also makes your object storage)").argument("<name>", "bucket name: 3-63 lowercase letters, digits and '-'").option("--size <GB>", "how much your object storage may hold, when this is your first bucket (default 10)").option("--region <region>", "the S3 region of your object storage (ro-west-1, de-center-1), when this is your first bucket").option("--near <box>", "put the object storage on the host of this box, when this is your first bucket").option("--json", "print as JSON").action(async (name, opts, cmd) => {
6257
+ var createCommand5 = new Command66("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) => {
5946
6258
  const sizeGib = opts.size === void 0 ? void 0 : parseGib2(opts.size);
5947
6259
  const client = await bucketClient(cmd);
5948
6260
  try {
@@ -5962,8 +6274,8 @@ var createCommand4 = new Command62("create").description("make a bucket (the fir
5962
6274
  });
5963
6275
 
5964
6276
  // src/commands/bucket/grow.ts
5965
- import { Command as Command63 } from "commander";
5966
- var growCommand2 = new Command63("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) => {
6277
+ import { Command as Command67 } from "commander";
6278
+ var growCommand2 = new Command67("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) => {
5967
6279
  const sizeGib = parseGib2(size, "size");
5968
6280
  const client = await bucketClient(cmd);
5969
6281
  try {
@@ -5976,8 +6288,8 @@ var growCommand2 = new Command63("grow").description("make your object storage l
5976
6288
  });
5977
6289
 
5978
6290
  // src/commands/bucket/info.ts
5979
- import { Command as Command64 } from "commander";
5980
- var infoCommand = new Command64("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) => {
6291
+ import { Command as Command68 } from "commander";
6292
+ var infoCommand = new Command68("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) => {
5981
6293
  const client = await bucketClient(cmd);
5982
6294
  try {
5983
6295
  const b = await client.getBucket(name);
@@ -6006,11 +6318,11 @@ with the AWS CLI: aws s3 ls s3://${b.name} --endpoint-url ${b.endpoint}`));
6006
6318
  });
6007
6319
 
6008
6320
  // src/commands/bucket/key/index.ts
6009
- import { Command as Command68 } from "commander";
6321
+ import { Command as Command72 } from "commander";
6010
6322
 
6011
6323
  // src/commands/bucket/key/create.ts
6012
- import { Command as Command65 } from "commander";
6013
- var createCommand5 = new Command65("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) => {
6324
+ import { Command as Command69 } from "commander";
6325
+ var createCommand6 = new Command69("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) => {
6014
6326
  const client = await bucketClient(cmd);
6015
6327
  try {
6016
6328
  const key = await client.createBucketKey(bucket, { ...opts.name !== void 0 ? { name: opts.name } : {}, ...opts.readOnly ? { readOnly: true } : {} });
@@ -6033,8 +6345,8 @@ var createCommand5 = new Command65("create").description("make an access key for
6033
6345
  });
6034
6346
 
6035
6347
  // src/commands/bucket/key/ls.ts
6036
- import { Command as Command66 } from "commander";
6037
- var lsCommand9 = new Command66("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) => {
6348
+ import { Command as Command70 } from "commander";
6349
+ var lsCommand10 = new Command70("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) => {
6038
6350
  const client = await bucketClient(cmd);
6039
6351
  try {
6040
6352
  const keys = await client.listBucketKeys(bucket);
@@ -6053,8 +6365,8 @@ var lsCommand9 = new Command66("ls").alias("list").description("list a bucket's
6053
6365
  });
6054
6366
 
6055
6367
  // src/commands/bucket/key/rm.ts
6056
- import { Command as Command67 } from "commander";
6057
- var rmCommand8 = new Command67("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) => {
6368
+ import { Command as Command71 } from "commander";
6369
+ var rmCommand8 = new Command71("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) => {
6058
6370
  const client = await bucketClient(cmd);
6059
6371
  try {
6060
6372
  if (!await confirm(`Delete key ${id} of bucket ${bucket}? Whatever uses it stops working.`, opts.yes ?? false)) {
@@ -6070,11 +6382,11 @@ var rmCommand8 = new Command67("rm").alias("remove").description("delete an acce
6070
6382
  });
6071
6383
 
6072
6384
  // src/commands/bucket/key/index.ts
6073
- var keyCommand = new Command68("key").aliases(["keys"]).description("access keys of a bucket: what your app signs in with").addCommand(createCommand5).addCommand(lsCommand9).addCommand(rmCommand8);
6385
+ var keyCommand = new Command72("key").aliases(["keys"]).description("access keys of a bucket: what your app signs in with").addCommand(createCommand6).addCommand(lsCommand10).addCommand(rmCommand8);
6074
6386
 
6075
6387
  // src/commands/bucket/ls.ts
6076
- import { Command as Command69 } from "commander";
6077
- var lsCommand10 = new Command69("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) => {
6388
+ import { Command as Command73 } from "commander";
6389
+ var lsCommand11 = new Command73("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) => {
6078
6390
  const client = await bucketClient(cmd);
6079
6391
  try {
6080
6392
  const buckets = await client.listBuckets({ all: opts.all });
@@ -6104,8 +6416,8 @@ var lsCommand10 = new Command69("ls").alias("list").description("list buckets, a
6104
6416
  });
6105
6417
 
6106
6418
  // src/commands/bucket/rm.ts
6107
- import { Command as Command70 } from "commander";
6108
- var rmCommand9 = new Command70("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) => {
6419
+ import { Command as Command74 } from "commander";
6420
+ var rmCommand9 = new Command74("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) => {
6109
6421
  const client = await bucketClient(cmd);
6110
6422
  try {
6111
6423
  const question = opts.force ? `Delete bucket ${name} with everything in it, and the object storage it is in?` : `Delete bucket ${name} and its keys?`;
@@ -6124,18 +6436,321 @@ var rmCommand9 = new Command70("rm").alias("remove").description("delete an empt
6124
6436
  });
6125
6437
 
6126
6438
  // src/commands/bucket/index.ts
6127
- var bucketCommand = new Command71("bucket").aliases(["buckets"]).description("object storage: S3 buckets for your files, and the access keys your apps use").addCommand(createCommand4).addCommand(lsCommand10).addCommand(infoCommand).addCommand(growCommand2).addCommand(rmCommand9).addCommand(keyCommand);
6439
+ var bucketCommand = new Command75("bucket").aliases(["buckets"]).description("object storage: S3 buckets for your files, and the access keys your apps use").addCommand(createCommand5).addCommand(lsCommand11).addCommand(infoCommand).addCommand(growCommand2).addCommand(rmCommand9).addCommand(keyCommand);
6128
6440
  var withOrg = (cmd) => cmd.option("--org <slug>", "act in this org (- for your personal buckets)");
6129
6441
  for (const cmd of bucketCommand.commands) {
6130
6442
  if (cmd === keyCommand) cmd.commands.forEach(withOrg);
6131
6443
  else withOrg(cmd);
6132
6444
  }
6133
6445
 
6134
- // src/commands/managed/kind.ts
6446
+ // src/commands/cron/index.ts
6447
+ import { Command as Command88 } from "commander";
6448
+
6449
+ // src/commands/cron/create.ts
6450
+ import { Command as Command76 } from "commander";
6451
+
6452
+ // src/commands/cron/shared.ts
6453
+ async function cronClient(cmd) {
6454
+ const client = await clientFor(cmd.optsWithGlobals());
6455
+ if (client.target.kind !== "cloud") {
6456
+ await client.close();
6457
+ throw new KvboxError("the cron service runs on the kvbox cloud: kvbox login first (on this host's own socket, use the box's own crontab)");
6458
+ }
6459
+ return client;
6460
+ }
6461
+ function shownName2(s, client) {
6462
+ const context = client.target.kind === "cloud" ? client.target.org ?? client.target.user : void 0;
6463
+ return s.owner === context ? s.name : `${s.owner}/${s.name}`;
6464
+ }
6465
+ function refFor(name, client) {
6466
+ if (client.target.kind !== "cloud" || name.includes("/")) return name;
6467
+ const { org, user } = client.target;
6468
+ return org && org !== user ? `${org}/${name}` : name;
6469
+ }
6470
+ var scheduleText = (t) => t.timezone === "UTC" ? t.expr : `${t.expr} (${t.timezone})`;
6471
+ function until(iso, now = Date.now()) {
6472
+ const sec = Math.round((Date.parse(iso) - now) / 1e3);
6473
+ return sec <= 0 ? "now" : `in ${duration(sec)}`;
6474
+ }
6475
+ function outcomeText(outcome) {
6476
+ const words = {
6477
+ running: "running",
6478
+ ok: "ok",
6479
+ failed: "failed",
6480
+ timeout: "timed out",
6481
+ "no-credit": "skipped: no credit",
6482
+ "box-stopped": "skipped: box stopped",
6483
+ "host-down": "host unreachable",
6484
+ "host-outdated": "host needs an update",
6485
+ lost: "lost"
6486
+ };
6487
+ const text2 = words[outcome];
6488
+ return outcome === "ok" ? color.green(text2) : outcome === "running" ? color.dim(text2) : color.red(text2);
6489
+ }
6490
+ function printTriggers(triggers) {
6491
+ table(
6492
+ triggers.map((t) => ({
6493
+ id: t.id,
6494
+ schedule: scheduleText(t),
6495
+ request: cronTarget(t),
6496
+ next: t.enabled ? t.nextRunAt ? until(t.nextRunAt) : "never" : color.yellow("paused"),
6497
+ "last run": t.lastRunAt && t.lastOutcome ? `${outcomeText(t.lastOutcome)} ${color.dim(age(t.lastRunAt))}` : "-"
6498
+ }))
6499
+ );
6500
+ }
6501
+ function printRows2(rows2) {
6502
+ const width2 = Math.max(...rows2.map(([label]) => label.length));
6503
+ for (const [label, value] of rows2) process.stdout.write(`${color.dim(label.padEnd(width2))} ${value}
6504
+ `);
6505
+ }
6506
+ var noTriggers = (service) => info(`cron service ${service} has no triggers yet; add one with: kvbox cron trigger add ${service} <box> "0 6 * * *" --port 3000`);
6507
+
6508
+ // src/commands/cron/create.ts
6509
+ var createCommand7 = new Command76("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) => {
6510
+ const client = await cronClient(cmd);
6511
+ try {
6512
+ const service = await client.createCronService(name);
6513
+ if (opts.json) {
6514
+ json(service);
6515
+ return;
6516
+ }
6517
+ const shown = shownName2(service, client);
6518
+ info(`${color.green("\u2713")} cron service ${color.bold(shown)} made; it keeps the last ${service.keepRuns} runs of each trigger${service.price && service.price.perMonth > 0 ? `, ${money(service.price.perMonth, service.price.currency)} a month` : ""}`);
6519
+ info(color.dim(`Add a trigger: kvbox cron trigger add ${refFor(shown, client)} <box> "0 6 * * *" --port 3000 --path /tasks/daily`));
6520
+ } finally {
6521
+ await client.close();
6522
+ }
6523
+ });
6524
+
6525
+ // src/commands/cron/info.ts
6526
+ import { Command as Command77 } from "commander";
6527
+ var infoCommand2 = new Command77("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) => {
6528
+ const client = await cronClient(cmd);
6529
+ try {
6530
+ const service = await client.getCronService(name);
6531
+ const triggers = await client.listCronTriggers(name);
6532
+ if (opts.json) {
6533
+ json({ ...service, triggerList: triggers });
6534
+ return;
6535
+ }
6536
+ printRows2([
6537
+ ["name", shownName2(service, client)],
6538
+ ["triggers", String(service.triggers)],
6539
+ ["runs kept", `the last ${service.keepRuns} of each trigger`],
6540
+ ["made", `${age(service.createdAt)}${service.createdBy ? ` by ${service.createdBy}` : ""}`]
6541
+ ]);
6542
+ process.stdout.write("\n");
6543
+ if (triggers.length === 0) noTriggers(refFor(name, client));
6544
+ else printTriggers(triggers);
6545
+ } finally {
6546
+ await client.close();
6547
+ }
6548
+ });
6549
+
6550
+ // src/commands/cron/ls.ts
6551
+ import { Command as Command78 } from "commander";
6552
+ var lsCommand12 = new Command78("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) => {
6553
+ const client = await cronClient(cmd);
6554
+ try {
6555
+ const services = await client.listCronServices({ all: opts.all });
6556
+ if (opts.json) {
6557
+ json(services);
6558
+ return;
6559
+ }
6560
+ if (services.length === 0) {
6561
+ info("no cron services yet; make one with: kvbox cron create <name>");
6562
+ return;
6563
+ }
6564
+ const me2 = client.target.kind === "cloud" ? client.target.user : void 0;
6565
+ table(services.map((s) => ({ owner: s.owner === me2 ? "private" : s.owner, name: s.name, triggers: s.triggers, "runs kept": s.keepRuns, created: age(s.createdAt) })));
6566
+ } finally {
6567
+ await client.close();
6568
+ }
6569
+ });
6570
+
6571
+ // src/commands/cron/rm.ts
6572
+ import { Command as Command79 } from "commander";
6573
+ var rmCommand10 = new Command79("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) => {
6574
+ const client = await cronClient(cmd);
6575
+ try {
6576
+ if (!await confirm(`Delete cron service ${name}? Its triggers stop firing and their run history is deleted.`, opts.yes ?? false)) {
6577
+ info("cancelled");
6578
+ process.exitCode = 1;
6579
+ return;
6580
+ }
6581
+ await client.deleteCronService(name);
6582
+ info(`${color.green("\u2713")} cron service ${name} deleted`);
6583
+ } finally {
6584
+ await client.close();
6585
+ }
6586
+ });
6587
+
6588
+ // src/commands/cron/trigger/index.ts
6589
+ import { Command as Command87 } from "commander";
6590
+
6591
+ // src/commands/cron/trigger/add.ts
6592
+ import { Command as Command80 } from "commander";
6593
+ function portOf(value) {
6594
+ if (value === void 0) throw new KvboxError("say which port your app listens on in the box: --port 3000");
6595
+ const n = Number(value);
6596
+ if (!Number.isInteger(n) || n < 1 || n > 65535) throw new KvboxError(`--port ${value}: a port is a number from 1 to 65535`);
6597
+ return n;
6598
+ }
6599
+ function methodOf(value) {
6600
+ const method = value.toUpperCase();
6601
+ if (!CRON_METHODS.includes(method)) throw new KvboxError(`--method ${value}: a trigger sends ${CRON_METHODS.join(" or ")}`);
6602
+ return method;
6603
+ }
6604
+ var addCommand3 = new Command80("add").description("add a trigger: on a schedule, send a request to a port of a box").argument("<service>", "cron service name").argument("<box>", "the box the request goes to").argument("<expr>", 'cron expression in quotes, five fields: "0 6 * * *" is every day at 06:00').option("--port <n>", "the port your app listens on in the box (required)").option("--path <path>", "path and query to request", "/").option("--method <method>", `HTTP method: ${CRON_METHODS.join(" or ")}`, "POST").option("--tz <zone>", "time zone the schedule is read in, like Europe/Bucharest", "UTC").option("--json", "print as JSON").action(async (service, box, expr, opts, cmd) => {
6605
+ const port = portOf(opts.port);
6606
+ const method = methodOf(opts.method);
6607
+ const client = await cronClient(cmd);
6608
+ try {
6609
+ const trigger = await client.addCronTrigger(service, { box, expr, timezone: opts.tz, method, port, path: opts.path });
6610
+ if (opts.json) {
6611
+ json(trigger);
6612
+ return;
6613
+ }
6614
+ info(`${color.green("\u2713")} trigger ${color.bold(trigger.id)} added: ${cronTarget(trigger)} on ${scheduleText(trigger)}`);
6615
+ if (trigger.nextRunAt) info(color.dim(`First run ${until(trigger.nextRunAt)}. Try it now: kvbox cron trigger run ${refFor(service, client)} ${trigger.id}`));
6616
+ } finally {
6617
+ await client.close();
6618
+ }
6619
+ });
6620
+
6621
+ // src/commands/cron/trigger/ls.ts
6622
+ import { Command as Command81 } from "commander";
6623
+ var lsCommand13 = new Command81("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) => {
6624
+ const client = await cronClient(cmd);
6625
+ try {
6626
+ const triggers = await client.listCronTriggers(service);
6627
+ if (opts.json) {
6628
+ json(triggers);
6629
+ return;
6630
+ }
6631
+ if (triggers.length === 0) noTriggers(refFor(service, client));
6632
+ else printTriggers(triggers);
6633
+ } finally {
6634
+ await client.close();
6635
+ }
6636
+ });
6637
+
6638
+ // src/commands/cron/trigger/pause.ts
6639
+ import { Command as Command82 } from "commander";
6640
+ var pauseCommand2 = new Command82("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) => {
6641
+ const client = await cronClient(cmd);
6642
+ try {
6643
+ const trigger = await client.setCronTriggerEnabled(service, id, false);
6644
+ if (opts.json) {
6645
+ json(trigger);
6646
+ return;
6647
+ }
6648
+ info(`${color.green("\u2713")} trigger ${id} paused; it fires again after: kvbox cron trigger resume ${refFor(service, client)} ${id}`);
6649
+ } finally {
6650
+ await client.close();
6651
+ }
6652
+ });
6653
+
6654
+ // src/commands/cron/trigger/resume.ts
6655
+ import { Command as Command83 } from "commander";
6656
+ var resumeCommand2 = new Command83("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) => {
6657
+ const client = await cronClient(cmd);
6658
+ try {
6659
+ const trigger = await client.setCronTriggerEnabled(service, id, true);
6660
+ if (opts.json) {
6661
+ json(trigger);
6662
+ return;
6663
+ }
6664
+ info(`${color.green("\u2713")} trigger ${id} resumed${trigger.nextRunAt ? `; next run ${until(trigger.nextRunAt)}` : ""}`);
6665
+ } finally {
6666
+ await client.close();
6667
+ }
6668
+ });
6669
+
6670
+ // src/commands/cron/trigger/rm.ts
6135
6671
  import { Command as Command84 } from "commander";
6672
+ var rmCommand11 = new Command84("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) => {
6673
+ const client = await cronClient(cmd);
6674
+ try {
6675
+ if (!await confirm(`Delete trigger ${id} of cron service ${service}? Its run history is deleted too.`, opts.yes ?? false)) {
6676
+ info("cancelled");
6677
+ process.exitCode = 1;
6678
+ return;
6679
+ }
6680
+ await client.deleteCronTrigger(service, id);
6681
+ info(`${color.green("\u2713")} trigger ${id} deleted`);
6682
+ } finally {
6683
+ await client.close();
6684
+ }
6685
+ });
6686
+
6687
+ // src/commands/cron/trigger/run.ts
6688
+ import { Command as Command85 } from "commander";
6689
+ var runCommand = new Command85("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) => {
6690
+ const client = await cronClient(cmd);
6691
+ try {
6692
+ const trigger = await client.runCronTrigger(service, id);
6693
+ if (opts.json) {
6694
+ json(trigger);
6695
+ return;
6696
+ }
6697
+ info(`${color.green("\u2713")} trigger ${id} will fire in a few seconds`);
6698
+ info(color.dim(`See how it went: kvbox cron trigger runs ${refFor(service, client)} ${id}`));
6699
+ } finally {
6700
+ await client.close();
6701
+ }
6702
+ });
6703
+
6704
+ // src/commands/cron/trigger/runs.ts
6705
+ import { Command as Command86 } from "commander";
6706
+ function limitOf(value) {
6707
+ const n = Number(value);
6708
+ if (!Number.isInteger(n) || n < 1) throw new KvboxError(`-n ${value}: a number of runs, 1 or more`);
6709
+ return n;
6710
+ }
6711
+ var runsCommand = new Command86("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) => {
6712
+ const limit = limitOf(opts.limit);
6713
+ const client = await cronClient(cmd);
6714
+ try {
6715
+ const runs = await client.listCronRuns(service, id, limit);
6716
+ if (opts.json) {
6717
+ json(runs);
6718
+ return;
6719
+ }
6720
+ if (runs.length === 0) {
6721
+ info(`trigger ${id} has not run yet; run it now with: kvbox cron trigger run ${refFor(service, client)} ${id}`);
6722
+ return;
6723
+ }
6724
+ table(
6725
+ runs.map((r) => ({
6726
+ when: age(r.startedAt),
6727
+ result: outcomeText(r.outcome),
6728
+ status: r.status ?? "-",
6729
+ took: r.durationMs === null ? "-" : r.durationMs < 1e3 ? `${r.durationMs} ms` : `${(r.durationMs / 1e3).toFixed(1)} s`,
6730
+ note: [r.woke ? "woke the box" : "", r.error ?? ""].filter(Boolean).join("; ") || color.dim("-")
6731
+ }))
6732
+ );
6733
+ } finally {
6734
+ await client.close();
6735
+ }
6736
+ });
6737
+
6738
+ // src/commands/cron/trigger/index.ts
6739
+ var triggerCommand = new Command87("trigger").aliases(["triggers"]).description("a cron service's triggers: a schedule and the request it sends to a box").addCommand(addCommand3).addCommand(lsCommand13).addCommand(runsCommand).addCommand(runCommand).addCommand(pauseCommand2).addCommand(resumeCommand2).addCommand(rmCommand11);
6740
+
6741
+ // src/commands/cron/index.ts
6742
+ var cronCommand = new Command88("cron").description("cron: call a box on a schedule, waking it first if it sleeps").addCommand(createCommand7).addCommand(lsCommand12).addCommand(infoCommand2).addCommand(rmCommand10).addCommand(triggerCommand);
6743
+ var withOrg2 = (cmd) => cmd.option("--org <slug>", "act in this org (- for your personal cron services)");
6744
+ for (const cmd of cronCommand.commands) {
6745
+ if (cmd === triggerCommand) cmd.commands.forEach(withOrg2);
6746
+ else withOrg2(cmd);
6747
+ }
6748
+
6749
+ // src/commands/managed/kind.ts
6750
+ import { Command as Command101 } from "commander";
6136
6751
 
6137
6752
  // src/commands/managed/create.ts
6138
- import { Command as Command73 } from "commander";
6753
+ import { Command as Command90 } from "commander";
6139
6754
  import { setTimeout as sleep3 } from "timers/promises";
6140
6755
 
6141
6756
  // src/commands/managed/shared.ts
@@ -6168,7 +6783,7 @@ async function managedClient(cmd) {
6168
6783
  }
6169
6784
  return client;
6170
6785
  }
6171
- var shownName2 = (m, user) => m.owner === user ? m.name : `${m.owner}/${m.name}`;
6786
+ var shownName3 = (m, user) => m.owner === user ? m.name : `${m.owner}/${m.name}`;
6172
6787
  var storageText = (m) => m.health?.storageUsedBytes !== void 0 ? `${gb(m.health.storageUsedBytes)} of ${m.storageGib} GB used` : `${m.storageGib} GB`;
6173
6788
  var nearlyFull2 = (m) => m.health?.storageUsedBytes !== void 0 && m.health.storageTotalBytes !== void 0 && m.health.storageTotalBytes > 0 && m.health.storageUsedBytes / m.health.storageTotalBytes >= 0.9;
6174
6789
  function stateText(m) {
@@ -6179,7 +6794,7 @@ function stateText(m) {
6179
6794
  return `${status(m.status)}, ${m.health.accepting ? "accepting connections" : color.yellow("not accepting connections")}`;
6180
6795
  }
6181
6796
  function infoRows(spec, m, user) {
6182
- const name = shownName2(m, user);
6797
+ const name = shownName3(m, user);
6183
6798
  const rows2 = [
6184
6799
  ["name", color.bold(name)],
6185
6800
  ["status", stateText(m)],
@@ -6195,7 +6810,7 @@ function infoRows(spec, m, user) {
6195
6810
  rows2.push(["created", `${age(m.createdAt)}${m.createdBy ? ` by ${m.createdBy}` : ""}`]);
6196
6811
  return rows2;
6197
6812
  }
6198
- function printRows2(rows2) {
6813
+ function printRows3(rows2) {
6199
6814
  const width2 = Math.max(...rows2.map(([label]) => label.length));
6200
6815
  for (const [label, value] of rows2) process.stdout.write(`${color.dim(label.padEnd(width2))} ${value}
6201
6816
  `);
@@ -6221,8 +6836,8 @@ function parseStorage(text2, flag) {
6221
6836
  // src/commands/managed/create.ts
6222
6837
  var READY_WAIT_MS = 9e4;
6223
6838
  var READY_STEP_MS = 2e3;
6224
- var createCommand6 = (spec) => {
6225
- const command = new Command73("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");
6839
+ var createCommand8 = (spec) => {
6840
+ const command = new Command90("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");
6226
6841
  for (const o of spec.options) command.option(`--${o.name} <${o.arg}>`, o.help);
6227
6842
  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) => {
6228
6843
  const options = Object.fromEntries(spec.options.flatMap((o) => typeof opts[o.name] === "string" ? [[o.name, opts[o.name]]] : []));
@@ -6236,9 +6851,9 @@ var createCommand6 = (spec) => {
6236
6851
  const client = await managedClient(cmd);
6237
6852
  try {
6238
6853
  const made = await spin(`creating ${spec.title} database ${name}\u2026`, client.createManaged(spec.kind, req));
6239
- const shown = shownName2(made, me(client));
6854
+ const shown = shownName3(made, me(client));
6240
6855
  const ready = await spin(`starting ${spec.title}\u2026`, async () => {
6241
- for (const until = Date.now() + READY_WAIT_MS; Date.now() < until; await sleep3(READY_STEP_MS)) {
6856
+ for (const until2 = Date.now() + READY_WAIT_MS; Date.now() < until2; await sleep3(READY_STEP_MS)) {
6242
6857
  const now = await client.getManaged(spec.kind, shown).catch(() => void 0);
6243
6858
  if (now?.health?.ready && now.health.accepting) return true;
6244
6859
  }
@@ -6249,7 +6864,7 @@ var createCommand6 = (spec) => {
6249
6864
  return;
6250
6865
  }
6251
6866
  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)`)}`);
6252
- printRows2([...settingRows(spec, made.settings), ...secretRows(made.secret)].map(([label, value]) => [` ${label}`, value]));
6867
+ printRows3([...settingRows(spec, made.settings), ...secretRows(made.secret)].map(([label, value]) => [` ${label}`, value]));
6253
6868
  info("");
6254
6869
  info("Nobody can reach it yet. To let something in:");
6255
6870
  info(` a box on the same host kvbox ${spec.command} link ${shown} <box> ${color.dim(`(a new one: kvbox new <box> --near ${shown})`)}`);
@@ -6263,8 +6878,8 @@ var createCommand6 = (spec) => {
6263
6878
  };
6264
6879
 
6265
6880
  // src/commands/managed/grow.ts
6266
- import { Command as Command74 } from "commander";
6267
- var growCommand3 = (spec) => new Command74("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) => {
6881
+ import { Command as Command91 } from "commander";
6882
+ var growCommand3 = (spec) => new Command91("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) => {
6268
6883
  const storageGib = parseStorage(size, "size");
6269
6884
  const client = await managedClient(cmd);
6270
6885
  try {
@@ -6277,21 +6892,21 @@ var growCommand3 = (spec) => new Command74("grow").description("give a database
6277
6892
  });
6278
6893
 
6279
6894
  // src/commands/managed/info.ts
6280
- import { Command as Command75 } from "commander";
6281
- var infoCommand2 = (spec) => new Command75("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) => {
6895
+ import { Command as Command92 } from "commander";
6896
+ var infoCommand3 = (spec) => new Command92("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) => {
6282
6897
  const client = await managedClient(cmd);
6283
6898
  try {
6284
6899
  const m = await client.getManaged(spec.kind, name);
6285
6900
  if (opts.json) json(m);
6286
- else printRows2(infoRows(spec, m, me(client)));
6901
+ else printRows3(infoRows(spec, m, me(client)));
6287
6902
  } finally {
6288
6903
  await client.close();
6289
6904
  }
6290
6905
  });
6291
6906
 
6292
6907
  // src/commands/managed/link.ts
6293
- import { Command as Command76 } from "commander";
6294
- var linkCommand2 = (spec) => new Command76("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, box, opts, cmd) => {
6908
+ import { Command as Command93 } from "commander";
6909
+ var linkCommand2 = (spec) => new Command93("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, box, opts, cmd) => {
6295
6910
  const client = await managedClient(cmd);
6296
6911
  try {
6297
6912
  const m = await spin(`linking ${box} to ${name}\u2026`, client.linkManaged(spec.kind, name, box));
@@ -6307,7 +6922,7 @@ var linkCommand2 = (spec) => new Command76("link").description("let a box reach
6307
6922
  });
6308
6923
 
6309
6924
  // src/commands/managed/ls.ts
6310
- import { Command as Command77 } from "commander";
6925
+ import { Command as Command94 } from "commander";
6311
6926
  function listRows(items, user, kindColumn) {
6312
6927
  return items.map((m) => ({
6313
6928
  owner: m.owner === user ? "private" : m.owner,
@@ -6321,7 +6936,7 @@ function listRows(items, user, kindColumn) {
6321
6936
  created: age(m.createdAt)
6322
6937
  }));
6323
6938
  }
6324
- var lsCommand11 = (spec) => new Command77("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) => {
6939
+ var lsCommand14 = (spec) => new Command94("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) => {
6325
6940
  const client = await managedClient(cmd);
6326
6941
  try {
6327
6942
  const items = await client.listManaged(spec?.kind, { all: opts.all });
@@ -6341,8 +6956,8 @@ var lsCommand11 = (spec) => new Command77("ls").alias("list").description(spec ?
6341
6956
  });
6342
6957
 
6343
6958
  // src/commands/managed/password.ts
6344
- import { Command as Command78 } from "commander";
6345
- var passwordCommand = (spec) => new Command78("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) => {
6959
+ import { Command as Command95 } from "commander";
6960
+ var passwordCommand = (spec) => new Command95("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) => {
6346
6961
  const client = await managedClient(cmd);
6347
6962
  try {
6348
6963
  const secret = opts.reset ? await spin(`setting a new password on ${name}\u2026`, client.resetManagedPassword(spec.kind, name)) : await client.managedPassword(spec.kind, name);
@@ -6351,15 +6966,15 @@ var passwordCommand = (spec) => new Command78("password").description("show a da
6351
6966
  return;
6352
6967
  }
6353
6968
  if (opts.reset) info(`${color.green("\u2713")} database ${name} has a new password; the old one no longer works`);
6354
- printRows2(secretRows(secret));
6969
+ printRows3(secretRows(secret));
6355
6970
  } finally {
6356
6971
  await client.close();
6357
6972
  }
6358
6973
  });
6359
6974
 
6360
6975
  // src/commands/managed/public.ts
6361
- import { Command as Command79 } from "commander";
6362
- var publicCommand = (spec) => new Command79("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) => {
6976
+ import { Command as Command96 } from "commander";
6977
+ var publicCommand = (spec) => new Command96("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) => {
6363
6978
  if (state !== "on" && state !== "off") throw new KvboxError(`write on or off: kvbox ${spec.command} public ${name} on`);
6364
6979
  const client = await managedClient(cmd);
6365
6980
  try {
@@ -6380,8 +6995,8 @@ var publicCommand = (spec) => new Command79("public").description("open a databa
6380
6995
  });
6381
6996
 
6382
6997
  // src/commands/managed/rm.ts
6383
- import { Command as Command80 } from "commander";
6384
- var rmCommand10 = (spec) => new Command80("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) => {
6998
+ import { Command as Command97 } from "commander";
6999
+ var rmCommand12 = (spec) => new Command97("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) => {
6385
7000
  const client = await managedClient(cmd);
6386
7001
  try {
6387
7002
  if (!await confirm(`Delete database ${name} and all its data? There is no backup.`, opts.yes ?? false)) {
@@ -6397,8 +7012,8 @@ var rmCommand10 = (spec) => new Command80("rm").alias("remove").description("del
6397
7012
  });
6398
7013
 
6399
7014
  // src/commands/managed/start.ts
6400
- import { Command as Command81 } from "commander";
6401
- var startCommand2 = (spec) => new Command81("start").description("run a stopped database again").argument("<db>", "its name").option("--json", "print as JSON").action(async (name, opts, cmd) => {
7015
+ import { Command as Command98 } from "commander";
7016
+ var startCommand2 = (spec) => new Command98("start").description("run a stopped database again").argument("<db>", "its name").option("--json", "print as JSON").action(async (name, opts, cmd) => {
6402
7017
  const client = await managedClient(cmd);
6403
7018
  try {
6404
7019
  const m = await spin(`starting ${name}\u2026`, client.startManaged(spec.kind, name));
@@ -6410,8 +7025,8 @@ var startCommand2 = (spec) => new Command81("start").description("run a stopped
6410
7025
  });
6411
7026
 
6412
7027
  // src/commands/managed/stop.ts
6413
- import { Command as Command82 } from "commander";
6414
- var stopCommand2 = (spec) => new Command82("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) => {
7028
+ import { Command as Command99 } from "commander";
7029
+ var stopCommand2 = (spec) => new Command99("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) => {
6415
7030
  const client = await managedClient(cmd);
6416
7031
  try {
6417
7032
  const m = await spin(`stopping ${name}\u2026`, client.stopManaged(spec.kind, name));
@@ -6423,8 +7038,8 @@ var stopCommand2 = (spec) => new Command82("stop").description("shut a database
6423
7038
  });
6424
7039
 
6425
7040
  // src/commands/managed/unlink.ts
6426
- import { Command as Command83 } from "commander";
6427
- var unlinkCommand2 = (spec) => new Command83("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, box, opts, cmd) => {
7041
+ import { Command as Command100 } from "commander";
7042
+ var unlinkCommand2 = (spec) => new Command100("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, box, opts, cmd) => {
6428
7043
  const client = await managedClient(cmd);
6429
7044
  try {
6430
7045
  const m = await spin(`unlinking ${box} from ${name}\u2026`, client.unlinkManaged(spec.kind, name, box));
@@ -6437,8 +7052,8 @@ var unlinkCommand2 = (spec) => new Command83("unlink").description("stop a box f
6437
7052
 
6438
7053
  // src/commands/managed/kind.ts
6439
7054
  function kindCommand(spec, description) {
6440
- const command = new Command84(spec.command).aliases(spec.aliases).description(description);
6441
- for (const make of [createCommand6, lsCommand11, infoCommand2, passwordCommand, publicCommand, linkCommand2, unlinkCommand2, growCommand3, stopCommand2, startCommand2, rmCommand10]) {
7055
+ const command = new Command101(spec.command).aliases(spec.aliases).description(description);
7056
+ for (const make of [createCommand8, lsCommand14, infoCommand3, passwordCommand, publicCommand, linkCommand2, unlinkCommand2, growCommand3, stopCommand2, startCommand2, rmCommand12]) {
6442
7057
  command.addCommand(make(spec).option("--org <slug>", "act in this org (- for your personal databases)"));
6443
7058
  }
6444
7059
  return command;
@@ -6451,14 +7066,14 @@ var pgCommand = kindCommand(POSTGRES2, "managed PostgreSQL: a database kvbox run
6451
7066
  var redisCommand = kindCommand(REDIS, "managed Redis (Valkey): a Redis kvbox runs for you, private until you link a box or make it public");
6452
7067
 
6453
7068
  // src/commands/managed/index.ts
6454
- import { Command as Command85 } from "commander";
6455
- var managedCommand = new Command85("managed").description(`databases kvbox runs for you, every kind together (${KINDS.map((k) => `${k.title}: kvbox ${k.command}`).join(", ")})`).addCommand(lsCommand11().option("--org <slug>", "act in this org (- for your personal databases)"));
7069
+ import { Command as Command102 } from "commander";
7070
+ var managedCommand = new Command102("managed").description(`databases kvbox runs for you, every kind together (${KINDS.map((k) => `${k.title}: kvbox ${k.command}`).join(", ")})`).addCommand(lsCommand14().option("--org <slug>", "act in this org (- for your personal databases)"));
6456
7071
 
6457
7072
  // src/commands/env/index.ts
6458
- import { Command as Command89 } from "commander";
7073
+ import { Command as Command106 } from "commander";
6459
7074
 
6460
7075
  // src/commands/env/ls.ts
6461
- import { Command as Command86 } from "commander";
7076
+ import { Command as Command103 } from "commander";
6462
7077
 
6463
7078
  // src/commands/env/shared.ts
6464
7079
  function requireCloud4(client) {
@@ -6485,7 +7100,7 @@ function firstBootHint(box, name) {
6485
7100
  }
6486
7101
 
6487
7102
  // src/commands/env/ls.ts
6488
- var lsCommand12 = new Command86("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) => {
7103
+ var lsCommand15 = new Command103("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) => {
6489
7104
  const client = await clientFor(cmd.optsWithGlobals(), { autoStart: false });
6490
7105
  try {
6491
7106
  if (opts.box !== void 0) {
@@ -6524,8 +7139,8 @@ var lsCommand12 = new Command86("ls").alias("list").description("list the variab
6524
7139
  });
6525
7140
 
6526
7141
  // src/commands/env/rm.ts
6527
- import { Command as Command87 } from "commander";
6528
- var rmCommand11 = new Command87("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) => {
7142
+ import { Command as Command104 } from "commander";
7143
+ var rmCommand13 = new Command104("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) => {
6529
7144
  const client = await clientFor(cmd.optsWithGlobals(), { autoStart: false });
6530
7145
  try {
6531
7146
  const target = opts.box === void 0 ? void 0 : await findBox2(client, opts.box);
@@ -6562,8 +7177,8 @@ var rmCommand11 = new Command87("rm").alias("remove").description("remove variab
6562
7177
  });
6563
7178
 
6564
7179
  // src/commands/env/set.ts
6565
- import { Command as Command88 } from "commander";
6566
- var setCommand2 = new Command88("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) => {
7180
+ import { Command as Command105 } from "commander";
7181
+ var setCommand2 = new Command105("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) => {
6567
7182
  const client = await clientFor(cmd.optsWithGlobals(), { autoStart: false });
6568
7183
  try {
6569
7184
  const owner = opts.box === void 0 ? requireCloud4(client) : void 0;
@@ -6600,14 +7215,14 @@ var setCommand2 = new Command88("set").description("add or change a variable; bo
6600
7215
  });
6601
7216
 
6602
7217
  // src/commands/env/index.ts
6603
- var envCommand = new Command89("env").description("environment variables every box of yours gets when it starts (secrets too)").addCommand(lsCommand12, { isDefault: true }).addCommand(setCommand2).addCommand(rmCommand11);
7218
+ var envCommand = new Command106("env").description("environment variables every box of yours gets when it starts (secrets too)").addCommand(lsCommand15, { isDefault: true }).addCommand(setCommand2).addCommand(rmCommand13);
6604
7219
  for (const cmd of envCommand.commands) cmd.option("--org <slug>", "the org's variables instead of yours");
6605
7220
 
6606
7221
  // src/commands/domain/index.ts
6607
- import { Command as Command93 } from "commander";
7222
+ import { Command as Command110 } from "commander";
6608
7223
 
6609
7224
  // src/commands/domain/add.ts
6610
- import { Command as Command90 } from "commander";
7225
+ import { Command as Command107 } from "commander";
6611
7226
 
6612
7227
  // src/commands/domain/shared.ts
6613
7228
  function requireCloud5(client) {
@@ -6627,7 +7242,7 @@ function hostIn(name, zone) {
6627
7242
  }
6628
7243
 
6629
7244
  // src/commands/domain/add.ts
6630
- var addCommand3 = new Command90("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) => {
7245
+ var addCommand4 = new Command107("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) => {
6631
7246
  const domain = assertDomain(domainArg.trim().toLowerCase());
6632
7247
  const port = opts.port === void 0 ? void 0 : parsePorts([opts.port])[0];
6633
7248
  const client = await clientFor(cmd.optsWithGlobals());
@@ -6663,8 +7278,8 @@ kvbox checks every minute; ${domain} is served at ${d.url} once its records are
6663
7278
  });
6664
7279
 
6665
7280
  // src/commands/domain/ls.ts
6666
- import { Command as Command91 } from "commander";
6667
- var lsCommand13 = new Command91("ls").alias("list").description("list your custom domains and whether they are live").option("--json", "print as JSON").action(async (opts, cmd) => {
7281
+ import { Command as Command108 } from "commander";
7282
+ var lsCommand16 = new Command108("ls").alias("list").description("list your custom domains and whether they are live").option("--json", "print as JSON").action(async (opts, cmd) => {
6668
7283
  const client = await clientFor(cmd.optsWithGlobals());
6669
7284
  try {
6670
7285
  requireCloud5(client);
@@ -6693,8 +7308,8 @@ var lsCommand13 = new Command91("ls").alias("list").description("list your custo
6693
7308
  });
6694
7309
 
6695
7310
  // src/commands/domain/rm.ts
6696
- import { Command as Command92 } from "commander";
6697
- var rmCommand12 = new Command92("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) => {
7311
+ import { Command as Command109 } from "commander";
7312
+ var rmCommand14 = new Command109("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) => {
6698
7313
  const domain = domainArg.trim().toLowerCase();
6699
7314
  const client = await clientFor(cmd.optsWithGlobals());
6700
7315
  try {
@@ -6715,7 +7330,7 @@ var rmCommand12 = new Command92("rm").alias("remove").description("stop serving
6715
7330
  });
6716
7331
 
6717
7332
  // src/commands/domain/index.ts
6718
- var domainCommand = new Command93("domain").alias("domains").description("serve a box at a domain of your own").addCommand(addCommand3).addCommand(lsCommand13).addCommand(rmCommand12);
7333
+ var domainCommand = new Command110("domain").alias("domains").description("serve a box at a domain of your own").addCommand(addCommand4).addCommand(lsCommand16).addCommand(rmCommand14);
6719
7334
  for (const cmd of domainCommand.commands) cmd.option("--org <slug>", "act in this org (- for your personal boxes)");
6720
7335
 
6721
7336
  // src/commands/update.ts
@@ -6723,7 +7338,7 @@ import { spawn as spawn6 } from "child_process";
6723
7338
  import { mkdtempSync, rmSync, writeFileSync as writeFileSync2 } from "fs";
6724
7339
  import { tmpdir } from "os";
6725
7340
  import { join as join9 } from "path";
6726
- import { Command as Command94 } from "commander";
7341
+ import { Command as Command111 } from "commander";
6727
7342
 
6728
7343
  // src/update.ts
6729
7344
  import { mkdirSync, readFileSync as readFileSync3, writeFileSync } from "fs";
@@ -6842,7 +7457,7 @@ function run2(cmd, args) {
6842
7457
  child.on("exit", (code, signal) => resolve4(code ?? (signal ? 1 : 0)));
6843
7458
  });
6844
7459
  }
6845
- var selfUpdateCommand = new Command94("update").description("update kvbox to the latest version (reruns the installer from kvbox.sh, agent skill included)").action(async () => {
7460
+ var selfUpdateCommand = new Command111("update").description("update kvbox to the latest version (reruns the installer from kvbox.sh, agent skill included)").action(async () => {
6846
7461
  suppressUpdateNotice();
6847
7462
  const inst = installerFor(process.platform, process.env["KVBOX_INSTALL_URL"] || INSTALL_BASE);
6848
7463
  let code;
@@ -6910,6 +7525,7 @@ var HELP_GROUPS = [
6910
7525
  ["pg", "managed PostgreSQL: a database kvbox runs for you"],
6911
7526
  ["redis", "managed Redis (Valkey): a Redis kvbox runs for you"],
6912
7527
  ["managed", "every managed database, whatever its kind"],
7528
+ ["cron", "call a box on a schedule, waking it first if it sleeps"],
6913
7529
  ["env", "environment variables and secrets every box of yours gets"],
6914
7530
  ["domain", "serve a box at a domain of your own"]
6915
7531
  ]
@@ -6967,7 +7583,7 @@ function installRootHelp(program) {
6967
7583
 
6968
7584
  // src/program.ts
6969
7585
  function buildProgram() {
6970
- const program = new Command95("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").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();
7586
+ const program = new Command112("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").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();
6971
7587
  program.addCommand(vmCommand);
6972
7588
  program.addCommand(snapshotsCommand);
6973
7589
  program.addCommand(volumeCommand);
@@ -6975,6 +7591,7 @@ function buildProgram() {
6975
7591
  program.addCommand(pgCommand);
6976
7592
  program.addCommand(redisCommand);
6977
7593
  program.addCommand(managedCommand);
7594
+ program.addCommand(cronCommand);
6978
7595
  program.addCommand(envCommand);
6979
7596
  program.addCommand(domainCommand);
6980
7597
  program.addCommand(loginCommand);