@kvbox/cli 0.6.1 → 0.6.3

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 Command99 } 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.1" : void 0);
167
+ var VERSION = versionOf(import.meta.url, true ? "0.6.3" : void 0);
168
168
 
169
169
  // src/commands/vm/index.ts
170
170
  import { Command as Command37 } from "commander";
@@ -437,7 +437,7 @@ import { openSync } from "fs";
437
437
  import { mkdir as mkdir2, readFile as readFile3, stat } from "fs/promises";
438
438
  import { setTimeout as sleep } from "timers/promises";
439
439
  import { Agent, request } from "undici";
440
- import { z as z6 } from "zod";
440
+ import { z as z7 } from "zod";
441
441
 
442
442
  // ../shared/src/api.ts
443
443
  import { z as z2 } from "zod";
@@ -767,6 +767,28 @@ var ResizeVolumeRequest = z2.object({
767
767
  });
768
768
  var RunScriptRequest = z2.object({ input: z2.unknown().optional() });
769
769
  var ScriptOutputSchema = z2.object({ output: z2.unknown() });
770
+ var BOX_RUN_ID_RE = /^[A-Za-z0-9_-]{1,64}$/;
771
+ var StartRunRequest = z2.object({
772
+ id: z2.string().regex(BOX_RUN_ID_RE),
773
+ command: z2.string().min(1).max(8192),
774
+ /** The command and everything it started are killed after this long. */
775
+ timeoutSec: z2.number().int().min(1).max(86400)
776
+ });
777
+ var StartRunAnswerSchema = z2.object({
778
+ id: z2.string(),
779
+ /** False: a run of this id was already there. */
780
+ started: z2.boolean(),
781
+ /** The box was asleep and this request woke it. */
782
+ woke: z2.boolean()
783
+ });
784
+ var BOX_RUN_STATES = ["running", "exited", "timeout", "unknown"];
785
+ var BoxRunSchema = z2.object({
786
+ id: z2.string(),
787
+ state: z2.enum(BOX_RUN_STATES),
788
+ /** With `exited`; 128 + the signal for a command a signal ended. */
789
+ exitCode: z2.number().int().optional()
790
+ });
791
+ var RunRefusalSchema = z2.object({ error: z2.string(), code: z2.string().optional() });
770
792
  var EnvVarSchema = z2.object({
771
793
  name: z2.string(),
772
794
  value: z2.string().optional(),
@@ -1035,6 +1057,17 @@ var VolumeUsageSchema = z2.object({
1035
1057
  cost: z2.object({ amount: z2.number(), currency: z2.string() }).optional(),
1036
1058
  historyFrom: z2.string().nullable()
1037
1059
  });
1060
+ var CronUsageSchema = z2.object({
1061
+ id: z2.string(),
1062
+ name: z2.string(),
1063
+ owner: z2.string(),
1064
+ ownerKind: z2.enum(["user", "org"]).optional(),
1065
+ status: z2.enum(["present", "removed"]),
1066
+ hours: z2.number(),
1067
+ cost: z2.object({ amount: z2.number(), currency: z2.string() }).optional(),
1068
+ /** When it was made. */
1069
+ historyFrom: z2.string().nullable()
1070
+ });
1038
1071
  var UsageDayItemSchema = z2.object({
1039
1072
  id: z2.string(),
1040
1073
  name: z2.string(),
@@ -1053,7 +1086,9 @@ var UsageDaySchema = z2.object({
1053
1086
  boxes: z2.array(UsageDayItemSchema),
1054
1087
  volumes: z2.array(UsageDayItemSchema),
1055
1088
  /** Object storage that existed that day (#182); absent on a day without any. */
1056
- storage: z2.array(UsageDayItemSchema).optional()
1089
+ storage: z2.array(UsageDayItemSchema).optional(),
1090
+ /** Cron services that existed that day (#190); absent on a day without any. */
1091
+ cron: z2.array(UsageDayItemSchema).optional()
1057
1092
  });
1058
1093
  var UsageReportSchema = z2.object({
1059
1094
  window: z2.object({ from: z2.string(), to: z2.string() }),
@@ -1066,6 +1101,8 @@ var UsageReportSchema = z2.object({
1066
1101
  * included ones, `sizeGib` its whole size. Absent when there is none.
1067
1102
  */
1068
1103
  storage: z2.array(VolumeUsageSchema).optional(),
1104
+ /** Cron services (#190, control plane only): one row per service a slug has or had. Absent when there is none. */
1105
+ cron: z2.array(CronUsageSchema).optional(),
1069
1106
  /** With `?by=day` only, oldest day first. */
1070
1107
  days: z2.array(UsageDaySchema).optional(),
1071
1108
  totals: z2.object({
@@ -1075,7 +1112,7 @@ var UsageReportSchema = z2.object({
1075
1112
  diskGibHours: z2.number(),
1076
1113
  volumeHours: z2.number().optional(),
1077
1114
  volumeGibHours: z2.number().optional(),
1078
- /** Boxes, volumes and object storage together. */
1115
+ /** Boxes, volumes, object storage and cron services together. */
1079
1116
  cost: z2.object({ amount: z2.number(), currency: z2.string() }).optional()
1080
1117
  })
1081
1118
  });
@@ -1361,7 +1398,9 @@ var PricingSchema = z3.object({
1361
1398
  */
1362
1399
  storageHour: z3.number().nonnegative().default(0),
1363
1400
  storageGibHour: z3.number().nonnegative().default(0),
1364
- storageIncludedGib: z3.number().int().nonnegative().default(0)
1401
+ storageIncludedGib: z3.number().int().nonnegative().default(0),
1402
+ /** The cron service (#190): an hour of one cron service existing, whatever it holds or fires. A price list from before it charges nothing. */
1403
+ cronHour: z3.number().nonnegative().default(0)
1365
1404
  });
1366
1405
  var PriceListSchema = PricingSchema.extend({ welcomeCredit: z3.number().nonnegative() });
1367
1406
  var HOUR_MS = 36e5;
@@ -1477,61 +1516,164 @@ var SetPublicRequest = z4.object({ on: z4.boolean() });
1477
1516
  var ManagedLinkRequest = z4.object({ box: z4.string() });
1478
1517
  var GrowManagedRequest = z4.object({ storageGib: z4.number().int() });
1479
1518
 
1480
- // ../shared/src/storage.ts
1519
+ // ../shared/src/cron.ts
1481
1520
  import { z as z5 } from "zod";
1482
- var RegionSchema = z5.object({ name: z5.string(), country: z5.string().nullable() });
1483
- var ObjectStorageSchema = z5.object({
1521
+ var DEFAULT_CRON_COMMAND_TIMEOUT_SEC = 600;
1522
+ var MAX_CRON_COMMAND_TIMEOUT_SEC = 3600;
1523
+ var CRON_RUN_LOG_DIR = "/var/log/kvbox/runs";
1524
+ var CRON_METHODS = ["GET", "POST"];
1525
+ var CRON_OUTCOMES = ["running", "ok", "failed", "timeout", "no-credit", "box-stopped", "host-down", "host-outdated", "lost", "still-running", "box-outdated"];
1526
+ var CronServiceSchema = z5.object({
1484
1527
  owner: z5.string(),
1485
1528
  ownerKind: z5.enum(["user", "org"]),
1486
- /** `https://s3-<slug>.<domain>`: what an S3 client is given, with path-style addressing. Null while the address is not claimed. */
1487
- endpoint: z5.string().nullable(),
1488
- /** The S3 region every client of it signs with (`ro-west-1`): its host's when it was made. */
1489
- region: z5.string(),
1490
- /** The most it may hold. */
1491
- sizeGib: z5.number().int(),
1492
- /** `running` when it answers; `unknown` while its host is not heard from. */
1493
- status: BoxStatusSchema,
1494
- /** With `?live=1`, when the storage answered: what is on its disk, and the disk's real size. */
1495
- usedBytes: z5.number().optional(),
1496
- totalBytes: z5.number().optional(),
1497
- host: z5.string(),
1498
- country: z5.string().optional(),
1499
- buckets: z5.number().int(),
1500
- price: z5.object({ perMonth: z5.number(), currency: z5.string() }),
1501
- createdAt: z5.string()
1502
- });
1503
- var BucketSchema = z5.object({
1504
1529
  name: z5.string(),
1505
- owner: z5.string(),
1506
- ownerKind: z5.enum(["user", "org"]),
1507
- endpoint: z5.string().nullable(),
1508
- region: z5.string(),
1509
- keys: z5.number().int(),
1510
- objects: z5.number().optional(),
1511
- bytes: z5.number().optional(),
1530
+ /** Runs kept per trigger. */
1531
+ keepRuns: z5.number().int(),
1532
+ triggers: z5.number().int(),
1512
1533
  createdBy: z5.string().nullable(),
1513
- createdAt: z5.string()
1534
+ createdAt: z5.string(),
1535
+ /** What it costs while it exists; on the answer to `POST /cron` only. */
1536
+ price: z5.object({ perMonth: z5.number(), currency: z5.string() }).optional()
1514
1537
  });
1515
- var CreateBucketRequest = z5.object({
1516
- name: z5.string(),
1517
- sizeGib: z5.number().int().optional(),
1518
- near: z5.string().optional(),
1519
- region: z5.string().optional()
1520
- });
1521
- var CreatedBucketSchema = BucketSchema.extend({ storage: ObjectStorageSchema, storageCreated: z5.boolean() });
1522
- var BucketInfoSchema = BucketSchema.extend({ storage: ObjectStorageSchema });
1523
- var BucketKeySchema = z5.object({
1538
+ var triggerCommon = {
1524
1539
  id: z5.string(),
1525
- name: z5.string(),
1526
- bucket: z5.string(),
1540
+ service: z5.string(),
1527
1541
  owner: z5.string(),
1528
- readOnly: z5.boolean(),
1542
+ /** The box it acts on; a trigger is removed with its box. */
1543
+ box: z5.string(),
1544
+ /** Five fields, `minute hour day-of-month month day-of-week`. */
1545
+ expr: z5.string(),
1546
+ /** An IANA zone (`Europe/Bucharest`) the expression is read in; `UTC` unless said. */
1547
+ timezone: z5.string(),
1548
+ /** False: paused, it fires again when resumed. */
1549
+ enabled: z5.boolean(),
1550
+ /** When it fires next (ISO); null while paused. */
1551
+ nextRunAt: z5.string().nullable(),
1552
+ lastRunAt: z5.string().nullable(),
1553
+ lastOutcome: z5.enum(CRON_OUTCOMES).nullable(),
1529
1554
  createdBy: z5.string().nullable(),
1530
1555
  createdAt: z5.string()
1531
- });
1532
- var CreateBucketKeyRequest = z5.object({ name: z5.string().optional(), readOnly: z5.boolean().optional() });
1533
- var CreatedBucketKeySchema = BucketKeySchema.extend({ secret: z5.string(), endpoint: z5.string().nullable(), region: z5.string() });
1534
- var GrowStorageRequest = z5.object({ sizeGib: z5.number().int() });
1556
+ };
1557
+ var CronHttpTriggerSchema = z5.object({
1558
+ ...triggerCommon,
1559
+ kind: z5.literal("http"),
1560
+ method: z5.enum(CRON_METHODS),
1561
+ port: z5.number().int(),
1562
+ /** Path and query, starting with `/`. */
1563
+ path: z5.string()
1564
+ });
1565
+ var CronCommandTriggerSchema = z5.object({
1566
+ ...triggerCommon,
1567
+ kind: z5.literal("command"),
1568
+ /** Run by a login shell as the box's user, in its home. */
1569
+ command: z5.string(),
1570
+ /** The command is stopped after this long. */
1571
+ timeoutSec: z5.number().int()
1572
+ });
1573
+ var CronTriggerSchema = z5.discriminatedUnion("kind", [CronHttpTriggerSchema, CronCommandTriggerSchema]);
1574
+ var CronRunSchema = z5.object({
1575
+ /** The slot this run was for (ISO); a run asked for by hand has the moment it was asked. */
1576
+ scheduledFor: z5.string(),
1577
+ startedAt: z5.string(),
1578
+ /** Null while `running`, and for a run that was never sent. */
1579
+ durationMs: z5.number().int().nullable(),
1580
+ /** The box's HTTP status; null when it never answered, and for a command. */
1581
+ status: z5.number().int().nullable(),
1582
+ /** A command's exit code (128 + the signal when one ended it); null until it ends, and for a request. */
1583
+ exitCode: z5.number().int().nullable(),
1584
+ /** The file in the box that holds what a command printed; null for a request and for a command that never started. */
1585
+ output: z5.string().nullable(),
1586
+ outcome: z5.enum(CRON_OUTCOMES),
1587
+ /** Why it did not end `ok`, in a line. */
1588
+ error: z5.string().nullable(),
1589
+ /** The box was hibernated and this run woke it. */
1590
+ woke: z5.boolean()
1591
+ });
1592
+ var CronCatalogSchema = z5.object({
1593
+ price: z5.object({ perMonth: z5.number(), currency: z5.string() }),
1594
+ maxServices: z5.number().int(),
1595
+ maxTriggers: z5.number().int(),
1596
+ keepRuns: z5.number().int(),
1597
+ /** The shortest time between two runs of one trigger, in seconds. */
1598
+ minIntervalSeconds: z5.number().int(),
1599
+ /** How long a box has to answer, in seconds. */
1600
+ timeoutSeconds: z5.number().int(),
1601
+ /** How long a command may run: unless the trigger says, and at most. */
1602
+ commandTimeoutSeconds: z5.number().int(),
1603
+ maxCommandTimeoutSeconds: z5.number().int(),
1604
+ docs: z5.string().optional()
1605
+ });
1606
+ var CreateCronServiceRequest = z5.object({ name: z5.string() });
1607
+ var CreateCronTriggerRequest = z5.object({
1608
+ box: z5.string().min(1),
1609
+ expr: z5.string().min(1),
1610
+ timezone: z5.string().optional(),
1611
+ /** A request: `port`, with `method` and `path`. */
1612
+ method: z5.enum(CRON_METHODS).optional(),
1613
+ port: z5.number().int().min(1).max(65535).optional(),
1614
+ path: z5.string().optional(),
1615
+ /** Or a command, with `timeoutSec`; exactly one of `port` and `command`. */
1616
+ command: z5.string().optional(),
1617
+ timeoutSec: z5.number().int().optional()
1618
+ });
1619
+ var UpdateCronTriggerRequest = z5.object({ enabled: z5.boolean() });
1620
+ var cronTarget = (t) => t.kind === "command" ? `${t.box}$ ${t.command}` : `${t.method} ${t.box}:${t.port}${t.path}`;
1621
+
1622
+ // ../shared/src/storage.ts
1623
+ import { z as z6 } from "zod";
1624
+ var RegionSchema = z6.object({ name: z6.string(), country: z6.string().nullable() });
1625
+ var ObjectStorageSchema = z6.object({
1626
+ owner: z6.string(),
1627
+ ownerKind: z6.enum(["user", "org"]),
1628
+ /** `https://s3-<slug>.<domain>`: what an S3 client is given, with path-style addressing. Null while the address is not claimed. */
1629
+ endpoint: z6.string().nullable(),
1630
+ /** The S3 region every client of it signs with (`ro-west-1`): its host's when it was made. */
1631
+ region: z6.string(),
1632
+ /** The most it may hold. */
1633
+ sizeGib: z6.number().int(),
1634
+ /** `running` when it answers; `unknown` while its host is not heard from. */
1635
+ status: BoxStatusSchema,
1636
+ /** With `?live=1`, when the storage answered: what is on its disk, and the disk's real size. */
1637
+ usedBytes: z6.number().optional(),
1638
+ totalBytes: z6.number().optional(),
1639
+ host: z6.string(),
1640
+ country: z6.string().optional(),
1641
+ buckets: z6.number().int(),
1642
+ price: z6.object({ perMonth: z6.number(), currency: z6.string() }),
1643
+ createdAt: z6.string()
1644
+ });
1645
+ var BucketSchema = z6.object({
1646
+ name: z6.string(),
1647
+ owner: z6.string(),
1648
+ ownerKind: z6.enum(["user", "org"]),
1649
+ endpoint: z6.string().nullable(),
1650
+ region: z6.string(),
1651
+ keys: z6.number().int(),
1652
+ objects: z6.number().optional(),
1653
+ bytes: z6.number().optional(),
1654
+ createdBy: z6.string().nullable(),
1655
+ createdAt: z6.string()
1656
+ });
1657
+ var CreateBucketRequest = z6.object({
1658
+ name: z6.string(),
1659
+ sizeGib: z6.number().int().optional(),
1660
+ near: z6.string().optional(),
1661
+ region: z6.string().optional()
1662
+ });
1663
+ var CreatedBucketSchema = BucketSchema.extend({ storage: ObjectStorageSchema, storageCreated: z6.boolean() });
1664
+ var BucketInfoSchema = BucketSchema.extend({ storage: ObjectStorageSchema });
1665
+ var BucketKeySchema = z6.object({
1666
+ id: z6.string(),
1667
+ name: z6.string(),
1668
+ bucket: z6.string(),
1669
+ owner: z6.string(),
1670
+ readOnly: z6.boolean(),
1671
+ createdBy: z6.string().nullable(),
1672
+ createdAt: z6.string()
1673
+ });
1674
+ var CreateBucketKeyRequest = z6.object({ name: z6.string().optional(), readOnly: z6.boolean().optional() });
1675
+ var CreatedBucketKeySchema = BucketKeySchema.extend({ secret: z6.string(), endpoint: z6.string().nullable(), region: z6.string() });
1676
+ var GrowStorageRequest = z6.object({ sizeGib: z6.number().int() });
1535
1677
 
1536
1678
  // src/kvm.ts
1537
1679
  import { accessSync, constants, readFileSync, statSync } from "fs";
@@ -1687,7 +1829,7 @@ var ServerClient = class {
1687
1829
  * `all`: every box on the platform (platform admins only, #78).
1688
1830
  */
1689
1831
  listMachines(opts = {}) {
1690
- return this.call("GET", `/machines${allQuery(opts)}`, z6.array(MachineSchema), void 0, opts.org);
1832
+ return this.call("GET", `/machines${allQuery(opts)}`, z7.array(MachineSchema), void 0, opts.org);
1691
1833
  }
1692
1834
  createMachine(req) {
1693
1835
  return this.call("POST", "/machines", MachineSchema, req);
@@ -1741,10 +1883,10 @@ var ServerClient = class {
1741
1883
  }
1742
1884
  /** Backups, the control plane's only: a box's disk in object storage. Newest first. */
1743
1885
  listBackups() {
1744
- return this.call("GET", "/backups", z6.array(BackupSchema));
1886
+ return this.call("GET", "/backups", z7.array(BackupSchema));
1745
1887
  }
1746
1888
  boxBackups(name) {
1747
- return this.call("GET", `/machines/${encodeURIComponent(name)}/backups`, z6.array(BackupSchema));
1889
+ return this.call("GET", `/machines/${encodeURIComponent(name)}/backups`, z7.array(BackupSchema));
1748
1890
  }
1749
1891
  boxBackup(name, id) {
1750
1892
  return this.call("GET", `/machines/${encodeURIComponent(name)}/backups/${encodeURIComponent(id)}`, BackupSchema);
@@ -1755,10 +1897,10 @@ var ServerClient = class {
1755
1897
  }
1756
1898
  /** A volume's backups (#168): the same as a box's, of the volume's disk. Newest first. */
1757
1899
  listVolumeBackups() {
1758
- return this.call("GET", "/backups?kind=volume", z6.array(VolumeBackupSchema));
1900
+ return this.call("GET", "/backups?kind=volume", z7.array(VolumeBackupSchema));
1759
1901
  }
1760
1902
  volumeBackups(name) {
1761
- return this.call("GET", `/volumes/${encodeURIComponent(name)}/backups`, z6.array(VolumeBackupSchema));
1903
+ return this.call("GET", `/volumes/${encodeURIComponent(name)}/backups`, z7.array(VolumeBackupSchema));
1762
1904
  }
1763
1905
  volumeBackup(name, id) {
1764
1906
  return this.call("GET", `/volumes/${encodeURIComponent(name)}/backups/${encodeURIComponent(id)}`, VolumeBackupSchema);
@@ -1777,7 +1919,7 @@ var ServerClient = class {
1777
1919
  }
1778
1920
  /** Wake hooks (#101), the control plane's only: a URL and a secret that wake the box. */
1779
1921
  boxHooks(name) {
1780
- return this.call("GET", `/machines/${encodeURIComponent(name)}/hooks`, z6.array(WakeHookSchema));
1922
+ return this.call("GET", `/machines/${encodeURIComponent(name)}/hooks`, z7.array(WakeHookSchema));
1781
1923
  }
1782
1924
  createBoxHook(name) {
1783
1925
  return this.call("POST", `/machines/${encodeURIComponent(name)}/hooks`, CreatedWakeHookSchema);
@@ -1805,7 +1947,7 @@ var ServerClient = class {
1805
1947
  }
1806
1948
  /** Every readable box's subdomains, one entry each. */
1807
1949
  listSubdomains() {
1808
- return this.call("GET", "/subdomains", z6.array(SubdomainSchema));
1950
+ return this.call("GET", "/subdomains", z7.array(SubdomainSchema));
1809
1951
  }
1810
1952
  /** Custom domains (#89), the control plane's only: serve the box at the user's own name. */
1811
1953
  addDomain(name, req) {
@@ -1816,7 +1958,7 @@ var ServerClient = class {
1816
1958
  }
1817
1959
  /** Every readable box's custom domains. */
1818
1960
  listDomains() {
1819
- return this.call("GET", "/domains", z6.array(DomainSchema));
1961
+ return this.call("GET", "/domains", z7.array(DomainSchema));
1820
1962
  }
1821
1963
  /** A running box's own load, memory and disk, asked of its guest (#67). */
1822
1964
  machineStats(name) {
@@ -1828,11 +1970,11 @@ var ServerClient = class {
1828
1970
  return this.call("GET", `/machines/${encodeURIComponent(name)}/usage${query}`, MachineUsageSchema);
1829
1971
  }
1830
1972
  /** Every box of the caller over the window (#41 on a host, #42 through a control plane); dates as the user wrote them. */
1831
- usageReport(since, until, all = false) {
1973
+ usageReport(since, until2, all = false) {
1832
1974
  const q = new URLSearchParams();
1833
1975
  if (all) q.set("all", "1");
1834
1976
  if (since !== void 0) q.set("since", since);
1835
- if (until !== void 0) q.set("until", until);
1977
+ if (until2 !== void 0) q.set("until", until2);
1836
1978
  const query = q.size === 0 ? "" : `?${q.toString()}`;
1837
1979
  return this.call("GET", `/usage${query}`, UsageReportSchema);
1838
1980
  }
@@ -1845,22 +1987,22 @@ var ServerClient = class {
1845
1987
  return this.call("POST", "/billing/redeem", RedeemResponseSchema, { code });
1846
1988
  }
1847
1989
  deleteMachine(name) {
1848
- return this.call("DELETE", `/machines/${encodeURIComponent(name)}`, z6.undefined());
1990
+ return this.call("DELETE", `/machines/${encodeURIComponent(name)}`, z7.undefined());
1849
1991
  }
1850
1992
  /** Like `listMachines`, for snapshots. */
1851
1993
  listSnapshots(opts = {}) {
1852
- return this.call("GET", `/snapshots${allQuery(opts)}`, z6.array(SnapshotSchema), void 0, opts.org);
1994
+ return this.call("GET", `/snapshots${allQuery(opts)}`, z7.array(SnapshotSchema), void 0, opts.org);
1853
1995
  }
1854
1996
  createSnapshot(req) {
1855
1997
  return this.call("POST", "/snapshots", SnapshotSchema, req);
1856
1998
  }
1857
1999
  deleteSnapshot(name) {
1858
- return this.call("DELETE", `/snapshots/${encodeURIComponent(name)}`, z6.undefined());
2000
+ return this.call("DELETE", `/snapshots/${encodeURIComponent(name)}`, z7.undefined());
1859
2001
  }
1860
2002
  // ---- environment variables (#88), a control plane only: the caller's slug, or `--org`'s ----
1861
2003
  /** `org`: that org's list instead of `--org`'s (or the caller's own). */
1862
2004
  listEnv(org) {
1863
- return this.call("GET", "/vars", z6.array(EnvVarSchema), void 0, org);
2005
+ return this.call("GET", "/vars", z7.array(EnvVarSchema), void 0, org);
1864
2006
  }
1865
2007
  setEnv(name, req) {
1866
2008
  return this.call("PUT", `/vars/${encodeURIComponent(name)}`, EnvChangeSchema, req);
@@ -1880,13 +2022,13 @@ var ServerClient = class {
1880
2022
  }
1881
2023
  // ---- volumes (#52) ----
1882
2024
  listVolumes(opts = {}) {
1883
- return this.call("GET", `/volumes${allQuery(opts)}`, z6.array(VolumeSchema), void 0, opts.org);
2025
+ return this.call("GET", `/volumes${allQuery(opts)}`, z7.array(VolumeSchema), void 0, opts.org);
1884
2026
  }
1885
2027
  createVolume(req) {
1886
2028
  return this.call("POST", "/volumes", VolumeSchema, req);
1887
2029
  }
1888
2030
  deleteVolume(name) {
1889
- return this.call("DELETE", `/volumes/${encodeURIComponent(name)}`, z6.undefined());
2031
+ return this.call("DELETE", `/volumes/${encodeURIComponent(name)}`, z7.undefined());
1890
2032
  }
1891
2033
  /** Both answer with the box as it is afterwards (restarted when it was running). */
1892
2034
  attachVolume(name, req) {
@@ -1899,9 +2041,42 @@ var ServerClient = class {
1899
2041
  resizeVolume(name, sizeGib) {
1900
2042
  return this.call("POST", `/volumes/${encodeURIComponent(name)}/resize`, VolumeSchema, { sizeGib });
1901
2043
  }
2044
+ // ---- cron service (#190): the control plane's alone ----
2045
+ listCronServices(opts = {}) {
2046
+ return this.call("GET", `/cron${allQuery(opts)}`, z7.array(CronServiceSchema), void 0, opts.org);
2047
+ }
2048
+ createCronService(name) {
2049
+ return this.call("POST", "/cron", CronServiceSchema, { name });
2050
+ }
2051
+ getCronService(name) {
2052
+ return this.call("GET", `/cron/${encodeURIComponent(name)}`, CronServiceSchema);
2053
+ }
2054
+ deleteCronService(name) {
2055
+ return this.call("DELETE", `/cron/${encodeURIComponent(name)}`, z7.undefined());
2056
+ }
2057
+ listCronTriggers(service) {
2058
+ return this.call("GET", `/cron/${encodeURIComponent(service)}/triggers`, z7.array(CronTriggerSchema));
2059
+ }
2060
+ addCronTrigger(service, req) {
2061
+ return this.call("POST", `/cron/${encodeURIComponent(service)}/triggers`, CronTriggerSchema, req);
2062
+ }
2063
+ /** Pause (false) or resume (true). */
2064
+ setCronTriggerEnabled(service, id, enabled2) {
2065
+ return this.call("PATCH", `/cron/${encodeURIComponent(service)}/triggers/${encodeURIComponent(id)}`, CronTriggerSchema, { enabled: enabled2 });
2066
+ }
2067
+ deleteCronTrigger(service, id) {
2068
+ return this.call("DELETE", `/cron/${encodeURIComponent(service)}/triggers/${encodeURIComponent(id)}`, z7.undefined());
2069
+ }
2070
+ /** Marks it due: kvbox-cron fires it within a few seconds. */
2071
+ runCronTrigger(service, id) {
2072
+ return this.call("POST", `/cron/${encodeURIComponent(service)}/triggers/${encodeURIComponent(id)}/run`, CronTriggerSchema);
2073
+ }
2074
+ listCronRuns(service, id, limit) {
2075
+ return this.call("GET", `/cron/${encodeURIComponent(service)}/triggers/${encodeURIComponent(id)}/runs${limit === void 0 ? "" : `?limit=${limit}`}`, z7.array(CronRunSchema));
2076
+ }
1902
2077
  // ---- object storage (#182): the control plane's alone ----
1903
2078
  listBuckets(opts = {}) {
1904
- return this.call("GET", `/buckets${allQuery(opts)}`, z6.array(BucketSchema), void 0, opts.org);
2079
+ return this.call("GET", `/buckets${allQuery(opts)}`, z7.array(BucketSchema), void 0, opts.org);
1905
2080
  }
1906
2081
  /** The first bucket of a slug also makes its storage: a box boots twice, so this may take a couple of minutes. */
1907
2082
  createBucket(req) {
@@ -1911,19 +2086,19 @@ var ServerClient = class {
1911
2086
  return this.call("GET", `/buckets/${encodeURIComponent(name)}`, BucketInfoSchema);
1912
2087
  }
1913
2088
  deleteBucket(name, force = false) {
1914
- return this.call("DELETE", `/buckets/${encodeURIComponent(name)}${force ? "?force=1" : ""}`, z6.undefined());
2089
+ return this.call("DELETE", `/buckets/${encodeURIComponent(name)}${force ? "?force=1" : ""}`, z7.undefined());
1915
2090
  }
1916
2091
  listBucketKeys(name) {
1917
- return this.call("GET", `/buckets/${encodeURIComponent(name)}/keys`, z6.array(BucketKeySchema));
2092
+ return this.call("GET", `/buckets/${encodeURIComponent(name)}/keys`, z7.array(BucketKeySchema));
1918
2093
  }
1919
2094
  createBucketKey(name, req) {
1920
2095
  return this.call("POST", `/buckets/${encodeURIComponent(name)}/keys`, CreatedBucketKeySchema, req);
1921
2096
  }
1922
2097
  deleteBucketKey(name, id) {
1923
- return this.call("DELETE", `/buckets/${encodeURIComponent(name)}/keys/${encodeURIComponent(id)}`, z6.undefined());
2098
+ return this.call("DELETE", `/buckets/${encodeURIComponent(name)}/keys/${encodeURIComponent(id)}`, z7.undefined());
1924
2099
  }
1925
2100
  listStorage(opts = {}) {
1926
- return this.call("GET", `/storage${allQuery(opts)}`, z6.array(ObjectStorageSchema), void 0, opts.org);
2101
+ return this.call("GET", `/storage${allQuery(opts)}`, z7.array(ObjectStorageSchema), void 0, opts.org);
1927
2102
  }
1928
2103
  growStorage(sizeGib) {
1929
2104
  return this.call("POST", "/storage/grow", ObjectStorageSchema, { sizeGib });
@@ -1933,11 +2108,11 @@ var ServerClient = class {
1933
2108
  return `/managed/${encodeURIComponent(kind)}${name === void 0 ? "" : `/${encodeURIComponent(name)}`}${rest}`;
1934
2109
  }
1935
2110
  managedCatalog() {
1936
- return this.call("GET", "/managed/catalog", z6.array(ManagedCatalogEntrySchema));
2111
+ return this.call("GET", "/managed/catalog", z7.array(ManagedCatalogEntrySchema));
1937
2112
  }
1938
2113
  /** One kind's services, or every kind's when `kind` is left out. */
1939
2114
  listManaged(kind, opts = {}) {
1940
- return this.call("GET", `${kind === void 0 ? "/managed" : this.managedPath(kind)}${allQuery(opts)}`, z6.array(ManagedSchema), void 0, opts.org);
2115
+ return this.call("GET", `${kind === void 0 ? "/managed" : this.managedPath(kind)}${allQuery(opts)}`, z7.array(ManagedSchema), void 0, opts.org);
1941
2116
  }
1942
2117
  createManaged(kind, req) {
1943
2118
  return this.call("POST", this.managedPath(kind), CreatedManagedSchema, req);
@@ -1947,7 +2122,7 @@ var ServerClient = class {
1947
2122
  return this.call("GET", this.managedPath(kind, name), ManagedSchema);
1948
2123
  }
1949
2124
  deleteManaged(kind, name) {
1950
- return this.call("DELETE", this.managedPath(kind, name), z6.undefined());
2125
+ return this.call("DELETE", this.managedPath(kind, name), z7.undefined());
1951
2126
  }
1952
2127
  managedPassword(kind, name) {
1953
2128
  return this.call("GET", this.managedPath(kind, name, "/password"), ManagedSecretSchema);
@@ -1978,14 +2153,14 @@ var ServerClient = class {
1978
2153
  return this.call("POST", "/login", LoginResponseSchema, req);
1979
2154
  }
1980
2155
  logout() {
1981
- return this.call("POST", "/logout", z6.unknown()).then(() => void 0);
2156
+ return this.call("POST", "/logout", z7.unknown()).then(() => void 0);
1982
2157
  }
1983
2158
  me() {
1984
2159
  return this.call("GET", "/me", MeResponseSchema);
1985
2160
  }
1986
2161
  // ---- orgs (`kvbox org …`) ----
1987
2162
  listOrgs() {
1988
- return this.call("GET", "/orgs", z6.array(OrgMembershipSchema));
2163
+ return this.call("GET", "/orgs", z7.array(OrgMembershipSchema));
1989
2164
  }
1990
2165
  createOrg(req) {
1991
2166
  return this.call("POST", "/orgs", CloudOrgSchema, req);
@@ -1994,16 +2169,16 @@ var ServerClient = class {
1994
2169
  return this.call("GET", `/orgs/${encodeURIComponent(slug)}`, OrgDetailSchema);
1995
2170
  }
1996
2171
  deleteOrg(slug) {
1997
- return this.call("DELETE", `/orgs/${encodeURIComponent(slug)}`, z6.undefined());
2172
+ return this.call("DELETE", `/orgs/${encodeURIComponent(slug)}`, z7.undefined());
1998
2173
  }
1999
2174
  addMember(slug, req) {
2000
- return this.call("POST", `/orgs/${encodeURIComponent(slug)}/members`, z6.undefined(), req);
2175
+ return this.call("POST", `/orgs/${encodeURIComponent(slug)}/members`, z7.undefined(), req);
2001
2176
  }
2002
2177
  setRole(slug, username, role) {
2003
- return this.call("PATCH", `/orgs/${encodeURIComponent(slug)}/members/${encodeURIComponent(username)}`, z6.unknown(), { role }).then(() => void 0);
2178
+ return this.call("PATCH", `/orgs/${encodeURIComponent(slug)}/members/${encodeURIComponent(username)}`, z7.unknown(), { role }).then(() => void 0);
2004
2179
  }
2005
2180
  removeMember(slug, username) {
2006
- return this.call("DELETE", `/orgs/${encodeURIComponent(slug)}/members/${encodeURIComponent(username)}`, z6.undefined());
2181
+ return this.call("DELETE", `/orgs/${encodeURIComponent(slug)}/members/${encodeURIComponent(username)}`, z7.undefined());
2007
2182
  }
2008
2183
  /** Sign this machine's key again (#51); the key must be one the user logged in with. */
2009
2184
  sshCert(req) {
@@ -3291,7 +3466,7 @@ var WAIT_MS = 7 * 36e5;
3291
3466
  async function untilSettled(ask, what, id, where, opts = {}) {
3292
3467
  const { pollMs = POLL_MS, tries = POLL_TRIES, waitMs = WAIT_MS } = opts;
3293
3468
  const lostTrack = (why) => new KvboxError(`stopped waiting for backup ${id} of ${what} (${why}); it may still be running: ${where}`);
3294
- const until = Date.now() + waitMs;
3469
+ const until2 = Date.now() + waitMs;
3295
3470
  let failed = 0;
3296
3471
  for (; ; ) {
3297
3472
  try {
@@ -3302,7 +3477,7 @@ async function untilSettled(ask, what, id, where, opts = {}) {
3302
3477
  failed += 1;
3303
3478
  if (failed >= tries) throw lostTrack(`could not ask how it is doing: ${err.message}`);
3304
3479
  }
3305
- if (Date.now() >= until) throw lostTrack("it is taking longer than a backup is given");
3480
+ if (Date.now() >= until2) throw lostTrack("it is taking longer than a backup is given");
3306
3481
  await sleep2(pollMs);
3307
3482
  }
3308
3483
  }
@@ -4204,7 +4379,8 @@ var usageCommand2 = new Command51("usage").description("what your boxes and volu
4204
4379
  info(`${day2(report.window.from)} to ${day2(report.window.to)}`);
4205
4380
  const volumes = report.volumes ?? [];
4206
4381
  const storage = report.storage ?? [];
4207
- if (report.boxes.length === 0 && volumes.length === 0 && storage.length === 0) info("no usage in this window");
4382
+ const cron = report.cron ?? [];
4383
+ if (report.boxes.length === 0 && volumes.length === 0 && storage.length === 0 && cron.length === 0) info("no usage in this window");
4208
4384
  else if (report.boxes.length > 0) table(perUser ? userRows(perUser) : usageRows(report, cloud));
4209
4385
  if (volumes.length > 0) {
4210
4386
  info(volumes.length === 1 ? "1 volume" : `${volumes.length} volumes`);
@@ -4214,8 +4390,12 @@ var usageCommand2 = new Command51("usage").description("what your boxes and volu
4214
4390
  info("object storage");
4215
4391
  table(storageRows(report, cloud));
4216
4392
  }
4217
- if ((volumes.length > 0 || storage.length > 0) && report.totals.cost !== void 0) {
4218
- const what = ["boxes", ...volumes.length > 0 ? ["volumes"] : [], ...storage.length > 0 ? ["object storage"] : []];
4393
+ if (cron.length > 0) {
4394
+ info(cron.length === 1 ? "1 cron service" : `${cron.length} cron services`);
4395
+ table(cronRows(report, cloud));
4396
+ }
4397
+ if ((volumes.length > 0 || storage.length > 0 || cron.length > 0) && report.totals.cost !== void 0) {
4398
+ const what = ["boxes", ...volumes.length > 0 ? ["volumes"] : [], ...storage.length > 0 ? ["object storage"] : [], ...cron.length > 0 ? ["cron services"] : []];
4219
4399
  info(`total: ${money(report.totals.cost.amount, report.totals.cost.currency)} ${color.dim(`(${what.slice(0, -1).join(", ")} and ${what.at(-1)}, estimated)`)}`);
4220
4400
  }
4221
4401
  if (cloud) {
@@ -4307,6 +4487,17 @@ function storageRows(report, cloud) {
4307
4487
  ...priced ? { cost: money(s.cost?.amount ?? 0, currency) } : {}
4308
4488
  }));
4309
4489
  }
4490
+ function cronRows(report, cloud) {
4491
+ const priced = report.totals.cost !== void 0;
4492
+ const currency = report.totals.cost?.currency ?? "";
4493
+ return (report.cron ?? []).map((s) => ({
4494
+ name: s.name,
4495
+ ...cloud ? { owner: ownerCell2(s, cloud.me) } : {},
4496
+ status: s.status === "removed" ? color.dim("removed") : "present",
4497
+ hours: hours(s.hours),
4498
+ ...priced ? { cost: money(s.cost?.amount ?? 0, currency) } : {}
4499
+ }));
4500
+ }
4310
4501
  function byUser(report) {
4311
4502
  const groups = /* @__PURE__ */ new Map();
4312
4503
  for (const b of report.boxes) {
@@ -4323,7 +4514,7 @@ function byUser(report) {
4323
4514
  return u;
4324
4515
  });
4325
4516
  users.sort((a, b) => a.user === null ? 1 : b.user === null ? -1 : a.user.localeCompare(b.user));
4326
- return { window: report.window, users, ...report.volumes === void 0 ? {} : { volumes: report.volumes }, ...report.storage === void 0 ? {} : { storage: report.storage }, totals: report.totals };
4517
+ 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 };
4327
4518
  }
4328
4519
  function userRows(r) {
4329
4520
  const priced = r.totals.cost !== void 0;
@@ -4405,7 +4596,7 @@ import { Command as Command54, InvalidArgumentError as InvalidArgumentError2, Op
4405
4596
  // src/commands/deploy/config.ts
4406
4597
  import { readFile as readFile6, writeFile as writeFile4 } from "fs/promises";
4407
4598
  import { isAbsolute, join as join6, normalize, relative as relative2 } from "path";
4408
- import { z as z7 } from "zod";
4599
+ import { z as z8 } from "zod";
4409
4600
 
4410
4601
  // src/commands/deploy/templates/docker.ts
4411
4602
  import { readFile as readFile5 } from "fs/promises";
@@ -4829,21 +5020,21 @@ function detectTemplates(pkg, dir = NO_FACTS) {
4829
5020
  var DEPLOY_AUTO_HIBERNATE_SEC = 3600;
4830
5021
  var CONFIG_FILE = "kvbox.json";
4831
5022
  var BOX_NAME_RE = /^[a-z0-9][a-z0-9-]{0,11}$/;
4832
- var DeployConfigSchema = z7.object({
4833
- template: z7.enum(TEMPLATE_IDS),
4834
- name: z7.string().regex(BOX_NAME_RE, "1-12 chars, lowercase letters, digits and '-', starting with a letter or digit"),
5023
+ var DeployConfigSchema = z8.object({
5024
+ template: z8.enum(TEMPLATE_IDS),
5025
+ name: z8.string().regex(BOX_NAME_RE, "1-12 chars, lowercase letters, digits and '-', starting with a letter or digit"),
4835
5026
  /** The org whose box it is; absent for the user's own. */
4836
- org: z7.string().regex(ORG_SLUG_RE, "not an org slug").optional(),
5027
+ org: z8.string().regex(ORG_SLUG_RE, "not an org slug").optional(),
4837
5028
  /** The HTTPS name (`<subdomain>.kvbox.app`); absent when deploying to this machine's own host. */
4838
- subdomain: z7.string().check((ctx) => {
5029
+ subdomain: z8.string().check((ctx) => {
4839
5030
  const problem = subdomainProblem(ctx.value);
4840
5031
  if (problem) ctx.issues.push({ code: "custom", message: problem, input: ctx.value });
4841
5032
  }).optional(),
4842
- size: z7.enum(SIZE_NAMES).optional(),
5033
+ size: z8.enum(SIZE_NAMES).optional(),
4843
5034
  /** The build output directory, relative to the app; the template's default when absent. */
4844
- dist: z7.string().optional(),
5035
+ dist: z8.string().optional(),
4845
5036
  /** The port a Next.js app or Node server serves; the template's (3000) when absent. */
4846
- port: z7.number().int().min(1).max(65535).optional()
5037
+ port: z8.number().int().min(1).max(65535).optional()
4847
5038
  });
4848
5039
  var SERVICE_KEY_RE = /^[a-z][a-z0-9-]{0,19}$/;
4849
5040
  var RESERVED_SERVICE_KEYS = ["app", "agent", "init", "volumes"];
@@ -4855,38 +5046,38 @@ var POSTGRES_PORT = 5432;
4855
5046
  var POSTGRES_IMAGE = "postgres:17";
4856
5047
  var POSTGRES_ENV = "DATABASE_URL";
4857
5048
  var IMAGE_RE = /^[a-z0-9][a-z0-9._/:@-]*$/;
4858
- var ServiceSchema = z7.strictObject({
4859
- template: z7.enum([...TEMPLATE_IDS, POSTGRES]),
5049
+ var ServiceSchema = z8.strictObject({
5050
+ template: z8.enum([...TEMPLATE_IDS, POSTGRES]),
4860
5051
  /** The service's directory, relative to the one holding kvbox.json; every template but postgres has one. */
4861
- dir: z7.string().min(1).optional(),
5052
+ dir: z8.string().min(1).optional(),
4862
5053
  /** A postgres service's image, `postgres:17` when absent (`pgvector/pgvector:pg17` for vectors). */
4863
- image: z7.string().regex(IMAGE_RE, "an image name like postgres:17").optional(),
5054
+ image: z8.string().regex(IMAGE_RE, "an image name like postgres:17").optional(),
4864
5055
  /** The volume (a key of `volumes`) a postgres service keeps its data on. */
4865
- volume: z7.string().optional(),
5056
+ volume: z8.string().optional(),
4866
5057
  /** The box variable a postgres service's URL is written to, `DATABASE_URL` when absent. */
4867
- env: z7.string().optional(),
5058
+ env: z8.string().optional(),
4868
5059
  /** 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`. */
4869
- context: z7.string().min(1).optional(),
4870
- dist: z7.string().optional(),
5060
+ context: z8.string().min(1).optional(),
5061
+ dist: z8.string().optional(),
4871
5062
  /**
4872
5063
  * A command run once per deploy in the service's new version (a docker service: in a container of
4873
5064
  * the new image; node, nextjs: in the new source, installed and built), with the box's variables,
4874
5065
  * before it replaces the running one. Migrations, mostly. A failing one stops that service's deploy.
4875
5066
  */
4876
- release: z7.string().optional(),
5067
+ release: z8.string().optional(),
4877
5068
  /** The box port of a service with its own server; the template's (3000) when absent. */
4878
- port: z7.number().int().min(1).max(65535).optional(),
5069
+ port: z8.number().int().min(1).max(65535).optional(),
4879
5070
  /** The URL paths that go to this service, each with everything under it; the prefix is kept. */
4880
- paths: z7.array(z7.string().regex(ROUTE_RE, "a path like / or /api, no trailing slash")).min(1).optional()
5071
+ paths: z8.array(z8.string().regex(ROUTE_RE, "a path like / or /api, no trailing slash")).min(1).optional()
4881
5072
  });
4882
- var StackConfigSchema = z7.strictObject({
5073
+ var StackConfigSchema = z8.strictObject({
4883
5074
  name: DeployConfigSchema.shape.name.optional(),
4884
5075
  org: DeployConfigSchema.shape.org,
4885
5076
  subdomain: DeployConfigSchema.shape.subdomain,
4886
5077
  size: DeployConfigSchema.shape.size,
4887
5078
  /** The stack's volumes, name to size ("10GB"): made for its box and attached to it on the first deploy that needs one. */
4888
- volumes: z7.record(z7.string(), z7.string()).optional(),
4889
- services: z7.record(z7.string(), ServiceSchema)
5079
+ volumes: z8.record(z8.string(), z8.string()).optional(),
5080
+ services: z8.record(z8.string(), ServiceSchema)
4890
5081
  });
4891
5082
  function volumeGib(text2) {
4892
5083
  const mib = parseMib(text2);
@@ -5335,10 +5526,10 @@ async function deployStack(d) {
5335
5526
  const { dir, opts, client, cloud } = d;
5336
5527
  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}`);
5337
5528
  const exposed = await exposedPorts(dir, d.stack);
5338
- const portOf = (template) => templateById(template).port;
5339
- pick(stackServices(d.stack, portOf, exposed), opts.only);
5529
+ const portOf2 = (template) => templateById(template).port;
5530
+ pick(stackServices(d.stack, portOf2, exposed), opts.only);
5340
5531
  const config = await settle(d);
5341
- const services = stackServices(config, portOf, exposed);
5532
+ const services = stackServices(config, portOf2, exposed);
5342
5533
  const picked = pick(services, opts.only);
5343
5534
  if (cloud && config.subdomain !== void 0) await refuseOtherAddress(client, { ...config, name: config.name });
5344
5535
  let saved = config;
@@ -6301,11 +6492,335 @@ for (const cmd of bucketCommand.commands) {
6301
6492
  else withOrg(cmd);
6302
6493
  }
6303
6494
 
6304
- // src/commands/managed/kind.ts
6495
+ // src/commands/cron/index.ts
6305
6496
  import { Command as Command88 } from "commander";
6306
6497
 
6307
- // src/commands/managed/create.ts
6498
+ // src/commands/cron/create.ts
6499
+ import { Command as Command76 } from "commander";
6500
+
6501
+ // src/commands/cron/shared.ts
6502
+ async function cronClient(cmd) {
6503
+ const client = await clientFor(cmd.optsWithGlobals());
6504
+ if (client.target.kind !== "cloud") {
6505
+ await client.close();
6506
+ 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)");
6507
+ }
6508
+ return client;
6509
+ }
6510
+ function shownName2(s, client) {
6511
+ const context = client.target.kind === "cloud" ? client.target.org ?? client.target.user : void 0;
6512
+ return s.owner === context ? s.name : `${s.owner}/${s.name}`;
6513
+ }
6514
+ function refFor(name, client) {
6515
+ if (client.target.kind !== "cloud" || name.includes("/")) return name;
6516
+ const { org, user } = client.target;
6517
+ return org && org !== user ? `${org}/${name}` : name;
6518
+ }
6519
+ var scheduleText = (t) => t.timezone === "UTC" ? t.expr : `${t.expr} (${t.timezone})`;
6520
+ function until(iso, now = Date.now()) {
6521
+ const sec = Math.round((Date.parse(iso) - now) / 1e3);
6522
+ return sec <= 0 ? "now" : `in ${duration(sec)}`;
6523
+ }
6524
+ function outcomeText(outcome) {
6525
+ const words = {
6526
+ running: "running",
6527
+ ok: "ok",
6528
+ failed: "failed",
6529
+ timeout: "timed out",
6530
+ "no-credit": "skipped: no credit",
6531
+ "box-stopped": "skipped: box stopped",
6532
+ "host-down": "host unreachable",
6533
+ "host-outdated": "host needs an update",
6534
+ lost: "lost",
6535
+ "still-running": "skipped: still running",
6536
+ "box-outdated": "box image too old"
6537
+ };
6538
+ const text2 = words[outcome];
6539
+ return outcome === "ok" ? color.green(text2) : outcome === "running" ? color.dim(text2) : color.red(text2);
6540
+ }
6541
+ function printTriggers(triggers) {
6542
+ table(
6543
+ triggers.map((t) => ({
6544
+ id: t.id,
6545
+ schedule: scheduleText(t),
6546
+ action: cronTarget(t),
6547
+ next: t.enabled ? t.nextRunAt ? until(t.nextRunAt) : "never" : color.yellow("paused"),
6548
+ "last run": t.lastRunAt && t.lastOutcome ? `${outcomeText(t.lastOutcome)} ${color.dim(age(t.lastRunAt))}` : "-"
6549
+ }))
6550
+ );
6551
+ }
6552
+ function printRows2(rows2) {
6553
+ const width2 = Math.max(...rows2.map(([label]) => label.length));
6554
+ for (const [label, value] of rows2) process.stdout.write(`${color.dim(label.padEnd(width2))} ${value}
6555
+ `);
6556
+ }
6557
+ var noTriggers = (service) => info(`cron service ${service} has no triggers yet; add one with: kvbox cron trigger add ${service} <box> "0 6 * * *" --port 3000 (or --run "<command>")`);
6558
+
6559
+ // src/commands/cron/create.ts
6560
+ 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) => {
6561
+ const client = await cronClient(cmd);
6562
+ try {
6563
+ const service = await client.createCronService(name);
6564
+ if (opts.json) {
6565
+ json(service);
6566
+ return;
6567
+ }
6568
+ const shown = shownName2(service, client);
6569
+ 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` : ""}`);
6570
+ info(color.dim(`Add a trigger: kvbox cron trigger add ${refFor(shown, client)} <box> "0 6 * * *" --port 3000 --path /tasks/daily`));
6571
+ } finally {
6572
+ await client.close();
6573
+ }
6574
+ });
6575
+
6576
+ // src/commands/cron/info.ts
6308
6577
  import { Command as Command77 } from "commander";
6578
+ 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) => {
6579
+ const client = await cronClient(cmd);
6580
+ try {
6581
+ const service = await client.getCronService(name);
6582
+ const triggers = await client.listCronTriggers(name);
6583
+ if (opts.json) {
6584
+ json({ ...service, triggerList: triggers });
6585
+ return;
6586
+ }
6587
+ printRows2([
6588
+ ["name", shownName2(service, client)],
6589
+ ["triggers", String(service.triggers)],
6590
+ ["runs kept", `the last ${service.keepRuns} of each trigger`],
6591
+ ["made", `${age(service.createdAt)}${service.createdBy ? ` by ${service.createdBy}` : ""}`]
6592
+ ]);
6593
+ process.stdout.write("\n");
6594
+ if (triggers.length === 0) noTriggers(refFor(name, client));
6595
+ else printTriggers(triggers);
6596
+ } finally {
6597
+ await client.close();
6598
+ }
6599
+ });
6600
+
6601
+ // src/commands/cron/ls.ts
6602
+ import { Command as Command78 } from "commander";
6603
+ 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) => {
6604
+ const client = await cronClient(cmd);
6605
+ try {
6606
+ const services = await client.listCronServices({ all: opts.all });
6607
+ if (opts.json) {
6608
+ json(services);
6609
+ return;
6610
+ }
6611
+ if (services.length === 0) {
6612
+ info("no cron services yet; make one with: kvbox cron create <name>");
6613
+ return;
6614
+ }
6615
+ const me2 = client.target.kind === "cloud" ? client.target.user : void 0;
6616
+ 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) })));
6617
+ } finally {
6618
+ await client.close();
6619
+ }
6620
+ });
6621
+
6622
+ // src/commands/cron/rm.ts
6623
+ import { Command as Command79 } from "commander";
6624
+ 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) => {
6625
+ const client = await cronClient(cmd);
6626
+ try {
6627
+ if (!await confirm(`Delete cron service ${name}? Its triggers stop firing and their run history is deleted.`, opts.yes ?? false)) {
6628
+ info("cancelled");
6629
+ process.exitCode = 1;
6630
+ return;
6631
+ }
6632
+ await client.deleteCronService(name);
6633
+ info(`${color.green("\u2713")} cron service ${name} deleted`);
6634
+ } finally {
6635
+ await client.close();
6636
+ }
6637
+ });
6638
+
6639
+ // src/commands/cron/trigger/index.ts
6640
+ import { Command as Command87 } from "commander";
6641
+
6642
+ // src/commands/cron/trigger/add.ts
6643
+ import { Command as Command80 } from "commander";
6644
+ function portOf(value) {
6645
+ const n = Number(value);
6646
+ if (!Number.isInteger(n) || n < 1 || n > 65535) throw new KvboxError(`--port ${value}: a port is a number from 1 to 65535`);
6647
+ return n;
6648
+ }
6649
+ function methodOf(value) {
6650
+ const method = value.toUpperCase();
6651
+ if (!CRON_METHODS.includes(method)) throw new KvboxError(`--method ${value}: a trigger sends ${CRON_METHODS.join(" or ")}`);
6652
+ return method;
6653
+ }
6654
+ function timeoutOf(value) {
6655
+ const t = value.trim().toLowerCase();
6656
+ const units = { s: 1, m: 60, h: 3600 };
6657
+ let sec = 0;
6658
+ for (const [, n, unit] of t.matchAll(/(\d+)([smh])/g)) sec += Number(n) * units[unit];
6659
+ if (!/^(\d+[smh])+$/.test(t) || sec < 1) throw new KvboxError(`--timeout ${value}: give a duration like 90s, 10m or 1h`);
6660
+ if (sec > MAX_CRON_COMMAND_TIMEOUT_SEC) throw new KvboxError(`--timeout ${value}: a command may run for ${MAX_CRON_COMMAND_TIMEOUT_SEC / 60} minutes at most`);
6661
+ return sec;
6662
+ }
6663
+ var addCommand3 = new Command80("add").description("add a trigger: on a schedule, call a port of a box or run a command in it").argument("<service>", "cron service name").argument("<box>", "the box it acts on").argument("<expr>", 'cron expression in quotes, five fields: "0 6 * * *" is every day at 06:00').option("--port <n>", "call this port, the one your app listens on in the box").option("--path <path>", "with --port: path and query to request (default: /)").option("--method <method>", `with --port: HTTP method, ${CRON_METHODS.join(" or ")} (default: POST)`).option("--run <command>", 'or run this command in the box, in quotes: "node ~/app/embed.js"').option("--timeout <duration>", `with --run: stop the command after this long (90s, 10m, 1h; default: ${DEFAULT_CRON_COMMAND_TIMEOUT_SEC / 60}m)`).option("--tz <zone>", "time zone the schedule is read in, like Europe/Bucharest", "UTC").option("--json", "print as JSON").action(async (service, box, expr, opts, cmd) => {
6664
+ let action;
6665
+ if (opts.run !== void 0) {
6666
+ if (opts.port !== void 0 || opts.path !== void 0 || opts.method !== void 0) throw new KvboxError("a trigger runs a command or calls a port: use --run, or --port with --path and --method, not both");
6667
+ if (opts.run.trim() === "") throw new KvboxError('--run needs the command, in quotes: --run "node ~/app/embed.js"');
6668
+ action = { command: opts.run, ...opts.timeout === void 0 ? {} : { timeoutSec: timeoutOf(opts.timeout) } };
6669
+ } else {
6670
+ if (opts.timeout !== void 0) throw new KvboxError("--timeout is for --run; a request to a port has a fixed time to answer");
6671
+ if (opts.port === void 0) throw new KvboxError('say what the trigger does: --port 3000 to call your app in the box, or --run "<command>" to run a command in it');
6672
+ action = { port: portOf(opts.port), method: methodOf(opts.method ?? "POST"), path: opts.path ?? "/" };
6673
+ }
6674
+ const client = await cronClient(cmd);
6675
+ try {
6676
+ const trigger = await client.addCronTrigger(service, { box, expr, timezone: opts.tz, ...action });
6677
+ if (opts.json) {
6678
+ json(trigger);
6679
+ return;
6680
+ }
6681
+ info(`${color.green("\u2713")} trigger ${color.bold(trigger.id)} added: ${cronTarget(trigger)} on ${scheduleText(trigger)}`);
6682
+ if (trigger.kind === "command") info(color.dim(`Stopped after ${trigger.timeoutSec % 60 === 0 ? `${trigger.timeoutSec / 60} min` : `${trigger.timeoutSec} s`} if still going. What it prints stays in the box: ${CRON_RUN_LOG_DIR}/`));
6683
+ if (trigger.nextRunAt) info(color.dim(`First run ${until(trigger.nextRunAt)}. Try it now: kvbox cron trigger run ${refFor(service, client)} ${trigger.id}`));
6684
+ } finally {
6685
+ await client.close();
6686
+ }
6687
+ });
6688
+
6689
+ // src/commands/cron/trigger/ls.ts
6690
+ import { Command as Command81 } from "commander";
6691
+ 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) => {
6692
+ const client = await cronClient(cmd);
6693
+ try {
6694
+ const triggers = await client.listCronTriggers(service);
6695
+ if (opts.json) {
6696
+ json(triggers);
6697
+ return;
6698
+ }
6699
+ if (triggers.length === 0) noTriggers(refFor(service, client));
6700
+ else printTriggers(triggers);
6701
+ } finally {
6702
+ await client.close();
6703
+ }
6704
+ });
6705
+
6706
+ // src/commands/cron/trigger/pause.ts
6707
+ import { Command as Command82 } from "commander";
6708
+ 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) => {
6709
+ const client = await cronClient(cmd);
6710
+ try {
6711
+ const trigger = await client.setCronTriggerEnabled(service, id, false);
6712
+ if (opts.json) {
6713
+ json(trigger);
6714
+ return;
6715
+ }
6716
+ info(`${color.green("\u2713")} trigger ${id} paused; it fires again after: kvbox cron trigger resume ${refFor(service, client)} ${id}`);
6717
+ } finally {
6718
+ await client.close();
6719
+ }
6720
+ });
6721
+
6722
+ // src/commands/cron/trigger/resume.ts
6723
+ import { Command as Command83 } from "commander";
6724
+ 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) => {
6725
+ const client = await cronClient(cmd);
6726
+ try {
6727
+ const trigger = await client.setCronTriggerEnabled(service, id, true);
6728
+ if (opts.json) {
6729
+ json(trigger);
6730
+ return;
6731
+ }
6732
+ info(`${color.green("\u2713")} trigger ${id} resumed${trigger.nextRunAt ? `; next run ${until(trigger.nextRunAt)}` : ""}`);
6733
+ } finally {
6734
+ await client.close();
6735
+ }
6736
+ });
6737
+
6738
+ // src/commands/cron/trigger/rm.ts
6739
+ import { Command as Command84 } from "commander";
6740
+ 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) => {
6741
+ const client = await cronClient(cmd);
6742
+ try {
6743
+ if (!await confirm(`Delete trigger ${id} of cron service ${service}? Its run history is deleted too.`, opts.yes ?? false)) {
6744
+ info("cancelled");
6745
+ process.exitCode = 1;
6746
+ return;
6747
+ }
6748
+ await client.deleteCronTrigger(service, id);
6749
+ info(`${color.green("\u2713")} trigger ${id} deleted`);
6750
+ } finally {
6751
+ await client.close();
6752
+ }
6753
+ });
6754
+
6755
+ // src/commands/cron/trigger/run.ts
6756
+ import { Command as Command85 } from "commander";
6757
+ 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) => {
6758
+ const client = await cronClient(cmd);
6759
+ try {
6760
+ const trigger = await client.runCronTrigger(service, id);
6761
+ if (opts.json) {
6762
+ json(trigger);
6763
+ return;
6764
+ }
6765
+ info(`${color.green("\u2713")} trigger ${id} will fire in a few seconds`);
6766
+ info(color.dim(`See how it went: kvbox cron trigger runs ${refFor(service, client)} ${id}`));
6767
+ } finally {
6768
+ await client.close();
6769
+ }
6770
+ });
6771
+
6772
+ // src/commands/cron/trigger/runs.ts
6773
+ import { Command as Command86 } from "commander";
6774
+ function limitOf(value) {
6775
+ const n = Number(value);
6776
+ if (!Number.isInteger(n) || n < 1) throw new KvboxError(`-n ${value}: a number of runs, 1 or more`);
6777
+ return n;
6778
+ }
6779
+ 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) => {
6780
+ const limit = limitOf(opts.limit);
6781
+ const client = await cronClient(cmd);
6782
+ try {
6783
+ const runs = await client.listCronRuns(service, id, limit);
6784
+ if (opts.json) {
6785
+ json(runs);
6786
+ return;
6787
+ }
6788
+ if (runs.length === 0) {
6789
+ info(`trigger ${id} has not run yet; run it now with: kvbox cron trigger run ${refFor(service, client)} ${id}`);
6790
+ return;
6791
+ }
6792
+ table(
6793
+ runs.map((r) => ({
6794
+ when: age(r.startedAt),
6795
+ result: outcomeText(r.outcome),
6796
+ status: r.status ?? (r.exitCode === null ? "-" : `exit ${r.exitCode}`),
6797
+ took: r.durationMs === null ? "-" : r.durationMs < 1e3 ? `${r.durationMs} ms` : `${(r.durationMs / 1e3).toFixed(1)} s`,
6798
+ note: [r.woke ? "woke the box" : "", r.error ?? ""].filter(Boolean).join("; ") || color.dim("-")
6799
+ }))
6800
+ );
6801
+ const last = runs.find((r) => r.output !== null);
6802
+ if (last) info(color.dim(`A command's output stays in the box, one file per run; the newest: kvbox exec <box> -- cat ${last.output}`));
6803
+ } finally {
6804
+ await client.close();
6805
+ }
6806
+ });
6807
+
6808
+ // src/commands/cron/trigger/index.ts
6809
+ 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);
6810
+
6811
+ // src/commands/cron/index.ts
6812
+ 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);
6813
+ var withOrg2 = (cmd) => cmd.option("--org <slug>", "act in this org (- for your personal cron services)");
6814
+ for (const cmd of cronCommand.commands) {
6815
+ if (cmd === triggerCommand) cmd.commands.forEach(withOrg2);
6816
+ else withOrg2(cmd);
6817
+ }
6818
+
6819
+ // src/commands/managed/kind.ts
6820
+ import { Command as Command101 } from "commander";
6821
+
6822
+ // src/commands/managed/create.ts
6823
+ import { Command as Command90 } from "commander";
6309
6824
  import { setTimeout as sleep3 } from "timers/promises";
6310
6825
 
6311
6826
  // src/commands/managed/shared.ts
@@ -6338,7 +6853,7 @@ async function managedClient(cmd) {
6338
6853
  }
6339
6854
  return client;
6340
6855
  }
6341
- var shownName2 = (m, user) => m.owner === user ? m.name : `${m.owner}/${m.name}`;
6856
+ var shownName3 = (m, user) => m.owner === user ? m.name : `${m.owner}/${m.name}`;
6342
6857
  var storageText = (m) => m.health?.storageUsedBytes !== void 0 ? `${gb(m.health.storageUsedBytes)} of ${m.storageGib} GB used` : `${m.storageGib} GB`;
6343
6858
  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;
6344
6859
  function stateText(m) {
@@ -6349,7 +6864,7 @@ function stateText(m) {
6349
6864
  return `${status(m.status)}, ${m.health.accepting ? "accepting connections" : color.yellow("not accepting connections")}`;
6350
6865
  }
6351
6866
  function infoRows(spec, m, user) {
6352
- const name = shownName2(m, user);
6867
+ const name = shownName3(m, user);
6353
6868
  const rows2 = [
6354
6869
  ["name", color.bold(name)],
6355
6870
  ["status", stateText(m)],
@@ -6365,7 +6880,7 @@ function infoRows(spec, m, user) {
6365
6880
  rows2.push(["created", `${age(m.createdAt)}${m.createdBy ? ` by ${m.createdBy}` : ""}`]);
6366
6881
  return rows2;
6367
6882
  }
6368
- function printRows2(rows2) {
6883
+ function printRows3(rows2) {
6369
6884
  const width2 = Math.max(...rows2.map(([label]) => label.length));
6370
6885
  for (const [label, value] of rows2) process.stdout.write(`${color.dim(label.padEnd(width2))} ${value}
6371
6886
  `);
@@ -6391,8 +6906,8 @@ function parseStorage(text2, flag) {
6391
6906
  // src/commands/managed/create.ts
6392
6907
  var READY_WAIT_MS = 9e4;
6393
6908
  var READY_STEP_MS = 2e3;
6394
- var createCommand7 = (spec) => {
6395
- const command = new Command77("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");
6909
+ var createCommand8 = (spec) => {
6910
+ 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");
6396
6911
  for (const o of spec.options) command.option(`--${o.name} <${o.arg}>`, o.help);
6397
6912
  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) => {
6398
6913
  const options = Object.fromEntries(spec.options.flatMap((o) => typeof opts[o.name] === "string" ? [[o.name, opts[o.name]]] : []));
@@ -6406,9 +6921,9 @@ var createCommand7 = (spec) => {
6406
6921
  const client = await managedClient(cmd);
6407
6922
  try {
6408
6923
  const made = await spin(`creating ${spec.title} database ${name}\u2026`, client.createManaged(spec.kind, req));
6409
- const shown = shownName2(made, me(client));
6924
+ const shown = shownName3(made, me(client));
6410
6925
  const ready = await spin(`starting ${spec.title}\u2026`, async () => {
6411
- for (const until = Date.now() + READY_WAIT_MS; Date.now() < until; await sleep3(READY_STEP_MS)) {
6926
+ for (const until2 = Date.now() + READY_WAIT_MS; Date.now() < until2; await sleep3(READY_STEP_MS)) {
6412
6927
  const now = await client.getManaged(spec.kind, shown).catch(() => void 0);
6413
6928
  if (now?.health?.ready && now.health.accepting) return true;
6414
6929
  }
@@ -6419,7 +6934,7 @@ var createCommand7 = (spec) => {
6419
6934
  return;
6420
6935
  }
6421
6936
  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)`)}`);
6422
- printRows2([...settingRows(spec, made.settings), ...secretRows(made.secret)].map(([label, value]) => [` ${label}`, value]));
6937
+ printRows3([...settingRows(spec, made.settings), ...secretRows(made.secret)].map(([label, value]) => [` ${label}`, value]));
6423
6938
  info("");
6424
6939
  info("Nobody can reach it yet. To let something in:");
6425
6940
  info(` a box on the same host kvbox ${spec.command} link ${shown} <box> ${color.dim(`(a new one: kvbox new <box> --near ${shown})`)}`);
@@ -6433,8 +6948,8 @@ var createCommand7 = (spec) => {
6433
6948
  };
6434
6949
 
6435
6950
  // src/commands/managed/grow.ts
6436
- import { Command as Command78 } from "commander";
6437
- var growCommand3 = (spec) => new Command78("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) => {
6951
+ import { Command as Command91 } from "commander";
6952
+ 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) => {
6438
6953
  const storageGib = parseStorage(size, "size");
6439
6954
  const client = await managedClient(cmd);
6440
6955
  try {
@@ -6447,21 +6962,21 @@ var growCommand3 = (spec) => new Command78("grow").description("give a database
6447
6962
  });
6448
6963
 
6449
6964
  // src/commands/managed/info.ts
6450
- import { Command as Command79 } from "commander";
6451
- var infoCommand2 = (spec) => new Command79("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) => {
6965
+ import { Command as Command92 } from "commander";
6966
+ 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) => {
6452
6967
  const client = await managedClient(cmd);
6453
6968
  try {
6454
6969
  const m = await client.getManaged(spec.kind, name);
6455
6970
  if (opts.json) json(m);
6456
- else printRows2(infoRows(spec, m, me(client)));
6971
+ else printRows3(infoRows(spec, m, me(client)));
6457
6972
  } finally {
6458
6973
  await client.close();
6459
6974
  }
6460
6975
  });
6461
6976
 
6462
6977
  // src/commands/managed/link.ts
6463
- import { Command as Command80 } from "commander";
6464
- var linkCommand2 = (spec) => new Command80("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) => {
6978
+ import { Command as Command93 } from "commander";
6979
+ 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) => {
6465
6980
  const client = await managedClient(cmd);
6466
6981
  try {
6467
6982
  const m = await spin(`linking ${box} to ${name}\u2026`, client.linkManaged(spec.kind, name, box));
@@ -6477,7 +6992,7 @@ var linkCommand2 = (spec) => new Command80("link").description("let a box reach
6477
6992
  });
6478
6993
 
6479
6994
  // src/commands/managed/ls.ts
6480
- import { Command as Command81 } from "commander";
6995
+ import { Command as Command94 } from "commander";
6481
6996
  function listRows(items, user, kindColumn) {
6482
6997
  return items.map((m) => ({
6483
6998
  owner: m.owner === user ? "private" : m.owner,
@@ -6491,7 +7006,7 @@ function listRows(items, user, kindColumn) {
6491
7006
  created: age(m.createdAt)
6492
7007
  }));
6493
7008
  }
6494
- var lsCommand12 = (spec) => new Command81("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) => {
7009
+ 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) => {
6495
7010
  const client = await managedClient(cmd);
6496
7011
  try {
6497
7012
  const items = await client.listManaged(spec?.kind, { all: opts.all });
@@ -6511,8 +7026,8 @@ var lsCommand12 = (spec) => new Command81("ls").alias("list").description(spec ?
6511
7026
  });
6512
7027
 
6513
7028
  // src/commands/managed/password.ts
6514
- import { Command as Command82 } from "commander";
6515
- var passwordCommand = (spec) => new Command82("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) => {
7029
+ import { Command as Command95 } from "commander";
7030
+ 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) => {
6516
7031
  const client = await managedClient(cmd);
6517
7032
  try {
6518
7033
  const secret = opts.reset ? await spin(`setting a new password on ${name}\u2026`, client.resetManagedPassword(spec.kind, name)) : await client.managedPassword(spec.kind, name);
@@ -6521,15 +7036,15 @@ var passwordCommand = (spec) => new Command82("password").description("show a da
6521
7036
  return;
6522
7037
  }
6523
7038
  if (opts.reset) info(`${color.green("\u2713")} database ${name} has a new password; the old one no longer works`);
6524
- printRows2(secretRows(secret));
7039
+ printRows3(secretRows(secret));
6525
7040
  } finally {
6526
7041
  await client.close();
6527
7042
  }
6528
7043
  });
6529
7044
 
6530
7045
  // src/commands/managed/public.ts
6531
- import { Command as Command83 } from "commander";
6532
- var publicCommand = (spec) => new Command83("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) => {
7046
+ import { Command as Command96 } from "commander";
7047
+ 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) => {
6533
7048
  if (state !== "on" && state !== "off") throw new KvboxError(`write on or off: kvbox ${spec.command} public ${name} on`);
6534
7049
  const client = await managedClient(cmd);
6535
7050
  try {
@@ -6550,8 +7065,8 @@ var publicCommand = (spec) => new Command83("public").description("open a databa
6550
7065
  });
6551
7066
 
6552
7067
  // src/commands/managed/rm.ts
6553
- import { Command as Command84 } from "commander";
6554
- var rmCommand10 = (spec) => new Command84("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) => {
7068
+ import { Command as Command97 } from "commander";
7069
+ 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) => {
6555
7070
  const client = await managedClient(cmd);
6556
7071
  try {
6557
7072
  if (!await confirm(`Delete database ${name} and all its data? There is no backup.`, opts.yes ?? false)) {
@@ -6567,8 +7082,8 @@ var rmCommand10 = (spec) => new Command84("rm").alias("remove").description("del
6567
7082
  });
6568
7083
 
6569
7084
  // src/commands/managed/start.ts
6570
- import { Command as Command85 } from "commander";
6571
- var startCommand2 = (spec) => new Command85("start").description("run a stopped database again").argument("<db>", "its name").option("--json", "print as JSON").action(async (name, opts, cmd) => {
7085
+ import { Command as Command98 } from "commander";
7086
+ 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) => {
6572
7087
  const client = await managedClient(cmd);
6573
7088
  try {
6574
7089
  const m = await spin(`starting ${name}\u2026`, client.startManaged(spec.kind, name));
@@ -6580,8 +7095,8 @@ var startCommand2 = (spec) => new Command85("start").description("run a stopped
6580
7095
  });
6581
7096
 
6582
7097
  // src/commands/managed/stop.ts
6583
- import { Command as Command86 } from "commander";
6584
- var stopCommand2 = (spec) => new Command86("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) => {
7098
+ import { Command as Command99 } from "commander";
7099
+ 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) => {
6585
7100
  const client = await managedClient(cmd);
6586
7101
  try {
6587
7102
  const m = await spin(`stopping ${name}\u2026`, client.stopManaged(spec.kind, name));
@@ -6593,8 +7108,8 @@ var stopCommand2 = (spec) => new Command86("stop").description("shut a database
6593
7108
  });
6594
7109
 
6595
7110
  // src/commands/managed/unlink.ts
6596
- import { Command as Command87 } from "commander";
6597
- var unlinkCommand2 = (spec) => new Command87("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) => {
7111
+ import { Command as Command100 } from "commander";
7112
+ 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) => {
6598
7113
  const client = await managedClient(cmd);
6599
7114
  try {
6600
7115
  const m = await spin(`unlinking ${box} from ${name}\u2026`, client.unlinkManaged(spec.kind, name, box));
@@ -6607,8 +7122,8 @@ var unlinkCommand2 = (spec) => new Command87("unlink").description("stop a box f
6607
7122
 
6608
7123
  // src/commands/managed/kind.ts
6609
7124
  function kindCommand(spec, description) {
6610
- const command = new Command88(spec.command).aliases(spec.aliases).description(description);
6611
- for (const make of [createCommand7, lsCommand12, infoCommand2, passwordCommand, publicCommand, linkCommand2, unlinkCommand2, growCommand3, stopCommand2, startCommand2, rmCommand10]) {
7125
+ const command = new Command101(spec.command).aliases(spec.aliases).description(description);
7126
+ for (const make of [createCommand8, lsCommand14, infoCommand3, passwordCommand, publicCommand, linkCommand2, unlinkCommand2, growCommand3, stopCommand2, startCommand2, rmCommand12]) {
6612
7127
  command.addCommand(make(spec).option("--org <slug>", "act in this org (- for your personal databases)"));
6613
7128
  }
6614
7129
  return command;
@@ -6621,14 +7136,14 @@ var pgCommand = kindCommand(POSTGRES2, "managed PostgreSQL: a database kvbox run
6621
7136
  var redisCommand = kindCommand(REDIS, "managed Redis (Valkey): a Redis kvbox runs for you, private until you link a box or make it public");
6622
7137
 
6623
7138
  // src/commands/managed/index.ts
6624
- import { Command as Command89 } from "commander";
6625
- var managedCommand = new Command89("managed").description(`databases kvbox runs for you, every kind together (${KINDS.map((k) => `${k.title}: kvbox ${k.command}`).join(", ")})`).addCommand(lsCommand12().option("--org <slug>", "act in this org (- for your personal databases)"));
7139
+ import { Command as Command102 } from "commander";
7140
+ 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)"));
6626
7141
 
6627
7142
  // src/commands/env/index.ts
6628
- import { Command as Command93 } from "commander";
7143
+ import { Command as Command106 } from "commander";
6629
7144
 
6630
7145
  // src/commands/env/ls.ts
6631
- import { Command as Command90 } from "commander";
7146
+ import { Command as Command103 } from "commander";
6632
7147
 
6633
7148
  // src/commands/env/shared.ts
6634
7149
  function requireCloud4(client) {
@@ -6655,7 +7170,7 @@ function firstBootHint(box, name) {
6655
7170
  }
6656
7171
 
6657
7172
  // src/commands/env/ls.ts
6658
- var lsCommand13 = new Command90("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) => {
7173
+ 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) => {
6659
7174
  const client = await clientFor(cmd.optsWithGlobals(), { autoStart: false });
6660
7175
  try {
6661
7176
  if (opts.box !== void 0) {
@@ -6694,8 +7209,8 @@ var lsCommand13 = new Command90("ls").alias("list").description("list the variab
6694
7209
  });
6695
7210
 
6696
7211
  // src/commands/env/rm.ts
6697
- import { Command as Command91 } from "commander";
6698
- var rmCommand11 = new Command91("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) => {
7212
+ import { Command as Command104 } from "commander";
7213
+ 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) => {
6699
7214
  const client = await clientFor(cmd.optsWithGlobals(), { autoStart: false });
6700
7215
  try {
6701
7216
  const target = opts.box === void 0 ? void 0 : await findBox2(client, opts.box);
@@ -6732,8 +7247,8 @@ var rmCommand11 = new Command91("rm").alias("remove").description("remove variab
6732
7247
  });
6733
7248
 
6734
7249
  // src/commands/env/set.ts
6735
- import { Command as Command92 } from "commander";
6736
- var setCommand2 = new Command92("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) => {
7250
+ import { Command as Command105 } from "commander";
7251
+ 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) => {
6737
7252
  const client = await clientFor(cmd.optsWithGlobals(), { autoStart: false });
6738
7253
  try {
6739
7254
  const owner = opts.box === void 0 ? requireCloud4(client) : void 0;
@@ -6770,14 +7285,14 @@ var setCommand2 = new Command92("set").description("add or change a variable; bo
6770
7285
  });
6771
7286
 
6772
7287
  // src/commands/env/index.ts
6773
- var envCommand = new Command93("env").description("environment variables every box of yours gets when it starts (secrets too)").addCommand(lsCommand13, { isDefault: true }).addCommand(setCommand2).addCommand(rmCommand11);
7288
+ 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);
6774
7289
  for (const cmd of envCommand.commands) cmd.option("--org <slug>", "the org's variables instead of yours");
6775
7290
 
6776
7291
  // src/commands/domain/index.ts
6777
- import { Command as Command97 } from "commander";
7292
+ import { Command as Command110 } from "commander";
6778
7293
 
6779
7294
  // src/commands/domain/add.ts
6780
- import { Command as Command94 } from "commander";
7295
+ import { Command as Command107 } from "commander";
6781
7296
 
6782
7297
  // src/commands/domain/shared.ts
6783
7298
  function requireCloud5(client) {
@@ -6797,7 +7312,7 @@ function hostIn(name, zone) {
6797
7312
  }
6798
7313
 
6799
7314
  // src/commands/domain/add.ts
6800
- var addCommand3 = new Command94("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) => {
7315
+ 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) => {
6801
7316
  const domain = assertDomain(domainArg.trim().toLowerCase());
6802
7317
  const port = opts.port === void 0 ? void 0 : parsePorts([opts.port])[0];
6803
7318
  const client = await clientFor(cmd.optsWithGlobals());
@@ -6833,8 +7348,8 @@ kvbox checks every minute; ${domain} is served at ${d.url} once its records are
6833
7348
  });
6834
7349
 
6835
7350
  // src/commands/domain/ls.ts
6836
- import { Command as Command95 } from "commander";
6837
- var lsCommand14 = new Command95("ls").alias("list").description("list your custom domains and whether they are live").option("--json", "print as JSON").action(async (opts, cmd) => {
7351
+ import { Command as Command108 } from "commander";
7352
+ 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) => {
6838
7353
  const client = await clientFor(cmd.optsWithGlobals());
6839
7354
  try {
6840
7355
  requireCloud5(client);
@@ -6863,8 +7378,8 @@ var lsCommand14 = new Command95("ls").alias("list").description("list your custo
6863
7378
  });
6864
7379
 
6865
7380
  // src/commands/domain/rm.ts
6866
- import { Command as Command96 } from "commander";
6867
- var rmCommand12 = new Command96("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) => {
7381
+ import { Command as Command109 } from "commander";
7382
+ 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) => {
6868
7383
  const domain = domainArg.trim().toLowerCase();
6869
7384
  const client = await clientFor(cmd.optsWithGlobals());
6870
7385
  try {
@@ -6885,7 +7400,7 @@ var rmCommand12 = new Command96("rm").alias("remove").description("stop serving
6885
7400
  });
6886
7401
 
6887
7402
  // src/commands/domain/index.ts
6888
- var domainCommand = new Command97("domain").alias("domains").description("serve a box at a domain of your own").addCommand(addCommand3).addCommand(lsCommand14).addCommand(rmCommand12);
7403
+ var domainCommand = new Command110("domain").alias("domains").description("serve a box at a domain of your own").addCommand(addCommand4).addCommand(lsCommand16).addCommand(rmCommand14);
6889
7404
  for (const cmd of domainCommand.commands) cmd.option("--org <slug>", "act in this org (- for your personal boxes)");
6890
7405
 
6891
7406
  // src/commands/update.ts
@@ -6893,7 +7408,7 @@ import { spawn as spawn6 } from "child_process";
6893
7408
  import { mkdtempSync, rmSync, writeFileSync as writeFileSync2 } from "fs";
6894
7409
  import { tmpdir } from "os";
6895
7410
  import { join as join9 } from "path";
6896
- import { Command as Command98 } from "commander";
7411
+ import { Command as Command111 } from "commander";
6897
7412
 
6898
7413
  // src/update.ts
6899
7414
  import { mkdirSync, readFileSync as readFileSync3, writeFileSync } from "fs";
@@ -7012,7 +7527,7 @@ function run2(cmd, args) {
7012
7527
  child.on("exit", (code, signal) => resolve4(code ?? (signal ? 1 : 0)));
7013
7528
  });
7014
7529
  }
7015
- var selfUpdateCommand = new Command98("update").description("update kvbox to the latest version (reruns the installer from kvbox.sh, agent skill included)").action(async () => {
7530
+ var selfUpdateCommand = new Command111("update").description("update kvbox to the latest version (reruns the installer from kvbox.sh, agent skill included)").action(async () => {
7016
7531
  suppressUpdateNotice();
7017
7532
  const inst = installerFor(process.platform, process.env["KVBOX_INSTALL_URL"] || INSTALL_BASE);
7018
7533
  let code;
@@ -7080,6 +7595,7 @@ var HELP_GROUPS = [
7080
7595
  ["pg", "managed PostgreSQL: a database kvbox runs for you"],
7081
7596
  ["redis", "managed Redis (Valkey): a Redis kvbox runs for you"],
7082
7597
  ["managed", "every managed database, whatever its kind"],
7598
+ ["cron", "call a box on a schedule, waking it first if it sleeps"],
7083
7599
  ["env", "environment variables and secrets every box of yours gets"],
7084
7600
  ["domain", "serve a box at a domain of your own"]
7085
7601
  ]
@@ -7137,7 +7653,7 @@ function installRootHelp(program) {
7137
7653
 
7138
7654
  // src/program.ts
7139
7655
  function buildProgram() {
7140
- const program = new Command99("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();
7656
+ 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();
7141
7657
  program.addCommand(vmCommand);
7142
7658
  program.addCommand(snapshotsCommand);
7143
7659
  program.addCommand(volumeCommand);
@@ -7145,6 +7661,7 @@ function buildProgram() {
7145
7661
  program.addCommand(pgCommand);
7146
7662
  program.addCommand(redisCommand);
7147
7663
  program.addCommand(managedCommand);
7664
+ program.addCommand(cronCommand);
7148
7665
  program.addCommand(envCommand);
7149
7666
  program.addCommand(domainCommand);
7150
7667
  program.addCommand(loginCommand);