@kvbox/cli 0.6.1 → 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 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.2" : 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";
@@ -1035,6 +1035,17 @@ var VolumeUsageSchema = z2.object({
1035
1035
  cost: z2.object({ amount: z2.number(), currency: z2.string() }).optional(),
1036
1036
  historyFrom: z2.string().nullable()
1037
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
+ });
1038
1049
  var UsageDayItemSchema = z2.object({
1039
1050
  id: z2.string(),
1040
1051
  name: z2.string(),
@@ -1053,7 +1064,9 @@ var UsageDaySchema = z2.object({
1053
1064
  boxes: z2.array(UsageDayItemSchema),
1054
1065
  volumes: z2.array(UsageDayItemSchema),
1055
1066
  /** Object storage that existed that day (#182); absent on a day without any. */
1056
- 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()
1057
1070
  });
1058
1071
  var UsageReportSchema = z2.object({
1059
1072
  window: z2.object({ from: z2.string(), to: z2.string() }),
@@ -1066,6 +1079,8 @@ var UsageReportSchema = z2.object({
1066
1079
  * included ones, `sizeGib` its whole size. Absent when there is none.
1067
1080
  */
1068
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(),
1069
1084
  /** With `?by=day` only, oldest day first. */
1070
1085
  days: z2.array(UsageDaySchema).optional(),
1071
1086
  totals: z2.object({
@@ -1075,7 +1090,7 @@ var UsageReportSchema = z2.object({
1075
1090
  diskGibHours: z2.number(),
1076
1091
  volumeHours: z2.number().optional(),
1077
1092
  volumeGibHours: z2.number().optional(),
1078
- /** Boxes, volumes and object storage together. */
1093
+ /** Boxes, volumes, object storage and cron services together. */
1079
1094
  cost: z2.object({ amount: z2.number(), currency: z2.string() }).optional()
1080
1095
  })
1081
1096
  });
@@ -1361,7 +1376,9 @@ var PricingSchema = z3.object({
1361
1376
  */
1362
1377
  storageHour: z3.number().nonnegative().default(0),
1363
1378
  storageGibHour: z3.number().nonnegative().default(0),
1364
- 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)
1365
1382
  });
1366
1383
  var PriceListSchema = PricingSchema.extend({ welcomeCredit: z3.number().nonnegative() });
1367
1384
  var HOUR_MS = 36e5;
@@ -1477,61 +1494,137 @@ var SetPublicRequest = z4.object({ on: z4.boolean() });
1477
1494
  var ManagedLinkRequest = z4.object({ box: z4.string() });
1478
1495
  var GrowManagedRequest = z4.object({ storageGib: z4.number().int() });
1479
1496
 
1480
- // ../shared/src/storage.ts
1497
+ // ../shared/src/cron.ts
1481
1498
  import { z as z5 } from "zod";
1482
- var RegionSchema = z5.object({ name: z5.string(), country: z5.string().nullable() });
1483
- 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({
1484
1502
  owner: z5.string(),
1485
1503
  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
1504
  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(),
1505
+ /** Runs kept per trigger. */
1506
+ keepRuns: z5.number().int(),
1507
+ triggers: z5.number().int(),
1512
1508
  createdBy: z5.string().nullable(),
1513
- createdAt: z5.string()
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()
1514
1512
  });
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({
1513
+ var CronTriggerSchema = z5.object({
1524
1514
  id: z5.string(),
1525
- name: z5.string(),
1526
- bucket: z5.string(),
1515
+ service: z5.string(),
1527
1516
  owner: z5.string(),
1528
- 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(),
1529
1533
  createdBy: z5.string().nullable(),
1530
1534
  createdAt: z5.string()
1531
1535
  });
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() });
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() });
1535
1628
 
1536
1629
  // src/kvm.ts
1537
1630
  import { accessSync, constants, readFileSync, statSync } from "fs";
@@ -1687,7 +1780,7 @@ var ServerClient = class {
1687
1780
  * `all`: every box on the platform (platform admins only, #78).
1688
1781
  */
1689
1782
  listMachines(opts = {}) {
1690
- 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);
1691
1784
  }
1692
1785
  createMachine(req) {
1693
1786
  return this.call("POST", "/machines", MachineSchema, req);
@@ -1741,10 +1834,10 @@ var ServerClient = class {
1741
1834
  }
1742
1835
  /** Backups, the control plane's only: a box's disk in object storage. Newest first. */
1743
1836
  listBackups() {
1744
- return this.call("GET", "/backups", z6.array(BackupSchema));
1837
+ return this.call("GET", "/backups", z7.array(BackupSchema));
1745
1838
  }
1746
1839
  boxBackups(name) {
1747
- return this.call("GET", `/machines/${encodeURIComponent(name)}/backups`, z6.array(BackupSchema));
1840
+ return this.call("GET", `/machines/${encodeURIComponent(name)}/backups`, z7.array(BackupSchema));
1748
1841
  }
1749
1842
  boxBackup(name, id) {
1750
1843
  return this.call("GET", `/machines/${encodeURIComponent(name)}/backups/${encodeURIComponent(id)}`, BackupSchema);
@@ -1755,10 +1848,10 @@ var ServerClient = class {
1755
1848
  }
1756
1849
  /** A volume's backups (#168): the same as a box's, of the volume's disk. Newest first. */
1757
1850
  listVolumeBackups() {
1758
- return this.call("GET", "/backups?kind=volume", z6.array(VolumeBackupSchema));
1851
+ return this.call("GET", "/backups?kind=volume", z7.array(VolumeBackupSchema));
1759
1852
  }
1760
1853
  volumeBackups(name) {
1761
- return this.call("GET", `/volumes/${encodeURIComponent(name)}/backups`, z6.array(VolumeBackupSchema));
1854
+ return this.call("GET", `/volumes/${encodeURIComponent(name)}/backups`, z7.array(VolumeBackupSchema));
1762
1855
  }
1763
1856
  volumeBackup(name, id) {
1764
1857
  return this.call("GET", `/volumes/${encodeURIComponent(name)}/backups/${encodeURIComponent(id)}`, VolumeBackupSchema);
@@ -1777,7 +1870,7 @@ var ServerClient = class {
1777
1870
  }
1778
1871
  /** Wake hooks (#101), the control plane's only: a URL and a secret that wake the box. */
1779
1872
  boxHooks(name) {
1780
- return this.call("GET", `/machines/${encodeURIComponent(name)}/hooks`, z6.array(WakeHookSchema));
1873
+ return this.call("GET", `/machines/${encodeURIComponent(name)}/hooks`, z7.array(WakeHookSchema));
1781
1874
  }
1782
1875
  createBoxHook(name) {
1783
1876
  return this.call("POST", `/machines/${encodeURIComponent(name)}/hooks`, CreatedWakeHookSchema);
@@ -1805,7 +1898,7 @@ var ServerClient = class {
1805
1898
  }
1806
1899
  /** Every readable box's subdomains, one entry each. */
1807
1900
  listSubdomains() {
1808
- return this.call("GET", "/subdomains", z6.array(SubdomainSchema));
1901
+ return this.call("GET", "/subdomains", z7.array(SubdomainSchema));
1809
1902
  }
1810
1903
  /** Custom domains (#89), the control plane's only: serve the box at the user's own name. */
1811
1904
  addDomain(name, req) {
@@ -1816,7 +1909,7 @@ var ServerClient = class {
1816
1909
  }
1817
1910
  /** Every readable box's custom domains. */
1818
1911
  listDomains() {
1819
- return this.call("GET", "/domains", z6.array(DomainSchema));
1912
+ return this.call("GET", "/domains", z7.array(DomainSchema));
1820
1913
  }
1821
1914
  /** A running box's own load, memory and disk, asked of its guest (#67). */
1822
1915
  machineStats(name) {
@@ -1828,11 +1921,11 @@ var ServerClient = class {
1828
1921
  return this.call("GET", `/machines/${encodeURIComponent(name)}/usage${query}`, MachineUsageSchema);
1829
1922
  }
1830
1923
  /** 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) {
1924
+ usageReport(since, until2, all = false) {
1832
1925
  const q = new URLSearchParams();
1833
1926
  if (all) q.set("all", "1");
1834
1927
  if (since !== void 0) q.set("since", since);
1835
- if (until !== void 0) q.set("until", until);
1928
+ if (until2 !== void 0) q.set("until", until2);
1836
1929
  const query = q.size === 0 ? "" : `?${q.toString()}`;
1837
1930
  return this.call("GET", `/usage${query}`, UsageReportSchema);
1838
1931
  }
@@ -1845,22 +1938,22 @@ var ServerClient = class {
1845
1938
  return this.call("POST", "/billing/redeem", RedeemResponseSchema, { code });
1846
1939
  }
1847
1940
  deleteMachine(name) {
1848
- return this.call("DELETE", `/machines/${encodeURIComponent(name)}`, z6.undefined());
1941
+ return this.call("DELETE", `/machines/${encodeURIComponent(name)}`, z7.undefined());
1849
1942
  }
1850
1943
  /** Like `listMachines`, for snapshots. */
1851
1944
  listSnapshots(opts = {}) {
1852
- 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);
1853
1946
  }
1854
1947
  createSnapshot(req) {
1855
1948
  return this.call("POST", "/snapshots", SnapshotSchema, req);
1856
1949
  }
1857
1950
  deleteSnapshot(name) {
1858
- return this.call("DELETE", `/snapshots/${encodeURIComponent(name)}`, z6.undefined());
1951
+ return this.call("DELETE", `/snapshots/${encodeURIComponent(name)}`, z7.undefined());
1859
1952
  }
1860
1953
  // ---- environment variables (#88), a control plane only: the caller's slug, or `--org`'s ----
1861
1954
  /** `org`: that org's list instead of `--org`'s (or the caller's own). */
1862
1955
  listEnv(org) {
1863
- return this.call("GET", "/vars", z6.array(EnvVarSchema), void 0, org);
1956
+ return this.call("GET", "/vars", z7.array(EnvVarSchema), void 0, org);
1864
1957
  }
1865
1958
  setEnv(name, req) {
1866
1959
  return this.call("PUT", `/vars/${encodeURIComponent(name)}`, EnvChangeSchema, req);
@@ -1880,13 +1973,13 @@ var ServerClient = class {
1880
1973
  }
1881
1974
  // ---- volumes (#52) ----
1882
1975
  listVolumes(opts = {}) {
1883
- 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);
1884
1977
  }
1885
1978
  createVolume(req) {
1886
1979
  return this.call("POST", "/volumes", VolumeSchema, req);
1887
1980
  }
1888
1981
  deleteVolume(name) {
1889
- return this.call("DELETE", `/volumes/${encodeURIComponent(name)}`, z6.undefined());
1982
+ return this.call("DELETE", `/volumes/${encodeURIComponent(name)}`, z7.undefined());
1890
1983
  }
1891
1984
  /** Both answer with the box as it is afterwards (restarted when it was running). */
1892
1985
  attachVolume(name, req) {
@@ -1899,9 +1992,42 @@ var ServerClient = class {
1899
1992
  resizeVolume(name, sizeGib) {
1900
1993
  return this.call("POST", `/volumes/${encodeURIComponent(name)}/resize`, VolumeSchema, { sizeGib });
1901
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
+ }
1902
2028
  // ---- object storage (#182): the control plane's alone ----
1903
2029
  listBuckets(opts = {}) {
1904
- 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);
1905
2031
  }
1906
2032
  /** The first bucket of a slug also makes its storage: a box boots twice, so this may take a couple of minutes. */
1907
2033
  createBucket(req) {
@@ -1911,19 +2037,19 @@ var ServerClient = class {
1911
2037
  return this.call("GET", `/buckets/${encodeURIComponent(name)}`, BucketInfoSchema);
1912
2038
  }
1913
2039
  deleteBucket(name, force = false) {
1914
- 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());
1915
2041
  }
1916
2042
  listBucketKeys(name) {
1917
- return this.call("GET", `/buckets/${encodeURIComponent(name)}/keys`, z6.array(BucketKeySchema));
2043
+ return this.call("GET", `/buckets/${encodeURIComponent(name)}/keys`, z7.array(BucketKeySchema));
1918
2044
  }
1919
2045
  createBucketKey(name, req) {
1920
2046
  return this.call("POST", `/buckets/${encodeURIComponent(name)}/keys`, CreatedBucketKeySchema, req);
1921
2047
  }
1922
2048
  deleteBucketKey(name, id) {
1923
- 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());
1924
2050
  }
1925
2051
  listStorage(opts = {}) {
1926
- 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);
1927
2053
  }
1928
2054
  growStorage(sizeGib) {
1929
2055
  return this.call("POST", "/storage/grow", ObjectStorageSchema, { sizeGib });
@@ -1933,11 +2059,11 @@ var ServerClient = class {
1933
2059
  return `/managed/${encodeURIComponent(kind)}${name === void 0 ? "" : `/${encodeURIComponent(name)}`}${rest}`;
1934
2060
  }
1935
2061
  managedCatalog() {
1936
- return this.call("GET", "/managed/catalog", z6.array(ManagedCatalogEntrySchema));
2062
+ return this.call("GET", "/managed/catalog", z7.array(ManagedCatalogEntrySchema));
1937
2063
  }
1938
2064
  /** One kind's services, or every kind's when `kind` is left out. */
1939
2065
  listManaged(kind, opts = {}) {
1940
- 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);
1941
2067
  }
1942
2068
  createManaged(kind, req) {
1943
2069
  return this.call("POST", this.managedPath(kind), CreatedManagedSchema, req);
@@ -1947,7 +2073,7 @@ var ServerClient = class {
1947
2073
  return this.call("GET", this.managedPath(kind, name), ManagedSchema);
1948
2074
  }
1949
2075
  deleteManaged(kind, name) {
1950
- return this.call("DELETE", this.managedPath(kind, name), z6.undefined());
2076
+ return this.call("DELETE", this.managedPath(kind, name), z7.undefined());
1951
2077
  }
1952
2078
  managedPassword(kind, name) {
1953
2079
  return this.call("GET", this.managedPath(kind, name, "/password"), ManagedSecretSchema);
@@ -1978,14 +2104,14 @@ var ServerClient = class {
1978
2104
  return this.call("POST", "/login", LoginResponseSchema, req);
1979
2105
  }
1980
2106
  logout() {
1981
- return this.call("POST", "/logout", z6.unknown()).then(() => void 0);
2107
+ return this.call("POST", "/logout", z7.unknown()).then(() => void 0);
1982
2108
  }
1983
2109
  me() {
1984
2110
  return this.call("GET", "/me", MeResponseSchema);
1985
2111
  }
1986
2112
  // ---- orgs (`kvbox org …`) ----
1987
2113
  listOrgs() {
1988
- return this.call("GET", "/orgs", z6.array(OrgMembershipSchema));
2114
+ return this.call("GET", "/orgs", z7.array(OrgMembershipSchema));
1989
2115
  }
1990
2116
  createOrg(req) {
1991
2117
  return this.call("POST", "/orgs", CloudOrgSchema, req);
@@ -1994,16 +2120,16 @@ var ServerClient = class {
1994
2120
  return this.call("GET", `/orgs/${encodeURIComponent(slug)}`, OrgDetailSchema);
1995
2121
  }
1996
2122
  deleteOrg(slug) {
1997
- return this.call("DELETE", `/orgs/${encodeURIComponent(slug)}`, z6.undefined());
2123
+ return this.call("DELETE", `/orgs/${encodeURIComponent(slug)}`, z7.undefined());
1998
2124
  }
1999
2125
  addMember(slug, req) {
2000
- return this.call("POST", `/orgs/${encodeURIComponent(slug)}/members`, z6.undefined(), req);
2126
+ return this.call("POST", `/orgs/${encodeURIComponent(slug)}/members`, z7.undefined(), req);
2001
2127
  }
2002
2128
  setRole(slug, username, role) {
2003
- 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);
2004
2130
  }
2005
2131
  removeMember(slug, username) {
2006
- 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());
2007
2133
  }
2008
2134
  /** Sign this machine's key again (#51); the key must be one the user logged in with. */
2009
2135
  sshCert(req) {
@@ -3291,7 +3417,7 @@ var WAIT_MS = 7 * 36e5;
3291
3417
  async function untilSettled(ask, what, id, where, opts = {}) {
3292
3418
  const { pollMs = POLL_MS, tries = POLL_TRIES, waitMs = WAIT_MS } = opts;
3293
3419
  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;
3420
+ const until2 = Date.now() + waitMs;
3295
3421
  let failed = 0;
3296
3422
  for (; ; ) {
3297
3423
  try {
@@ -3302,7 +3428,7 @@ async function untilSettled(ask, what, id, where, opts = {}) {
3302
3428
  failed += 1;
3303
3429
  if (failed >= tries) throw lostTrack(`could not ask how it is doing: ${err.message}`);
3304
3430
  }
3305
- if (Date.now() >= until) throw lostTrack("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");
3306
3432
  await sleep2(pollMs);
3307
3433
  }
3308
3434
  }
@@ -4204,7 +4330,8 @@ var usageCommand2 = new Command51("usage").description("what your boxes and volu
4204
4330
  info(`${day2(report.window.from)} to ${day2(report.window.to)}`);
4205
4331
  const volumes = report.volumes ?? [];
4206
4332
  const storage = report.storage ?? [];
4207
- 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");
4208
4335
  else if (report.boxes.length > 0) table(perUser ? userRows(perUser) : usageRows(report, cloud));
4209
4336
  if (volumes.length > 0) {
4210
4337
  info(volumes.length === 1 ? "1 volume" : `${volumes.length} volumes`);
@@ -4214,8 +4341,12 @@ var usageCommand2 = new Command51("usage").description("what your boxes and volu
4214
4341
  info("object storage");
4215
4342
  table(storageRows(report, cloud));
4216
4343
  }
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"] : []];
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"] : []];
4219
4350
  info(`total: ${money(report.totals.cost.amount, report.totals.cost.currency)} ${color.dim(`(${what.slice(0, -1).join(", ")} and ${what.at(-1)}, estimated)`)}`);
4220
4351
  }
4221
4352
  if (cloud) {
@@ -4307,6 +4438,17 @@ function storageRows(report, cloud) {
4307
4438
  ...priced ? { cost: money(s.cost?.amount ?? 0, currency) } : {}
4308
4439
  }));
4309
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
+ }
4310
4452
  function byUser(report) {
4311
4453
  const groups = /* @__PURE__ */ new Map();
4312
4454
  for (const b of report.boxes) {
@@ -4323,7 +4465,7 @@ function byUser(report) {
4323
4465
  return u;
4324
4466
  });
4325
4467
  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 };
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 };
4327
4469
  }
4328
4470
  function userRows(r) {
4329
4471
  const priced = r.totals.cost !== void 0;
@@ -4405,7 +4547,7 @@ import { Command as Command54, InvalidArgumentError as InvalidArgumentError2, Op
4405
4547
  // src/commands/deploy/config.ts
4406
4548
  import { readFile as readFile6, writeFile as writeFile4 } from "fs/promises";
4407
4549
  import { isAbsolute, join as join6, normalize, relative as relative2 } from "path";
4408
- import { z as z7 } from "zod";
4550
+ import { z as z8 } from "zod";
4409
4551
 
4410
4552
  // src/commands/deploy/templates/docker.ts
4411
4553
  import { readFile as readFile5 } from "fs/promises";
@@ -4829,21 +4971,21 @@ function detectTemplates(pkg, dir = NO_FACTS) {
4829
4971
  var DEPLOY_AUTO_HIBERNATE_SEC = 3600;
4830
4972
  var CONFIG_FILE = "kvbox.json";
4831
4973
  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"),
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"),
4835
4977
  /** 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(),
4978
+ org: z8.string().regex(ORG_SLUG_RE, "not an org slug").optional(),
4837
4979
  /** The HTTPS name (`<subdomain>.kvbox.app`); absent when deploying to this machine's own host. */
4838
- subdomain: z7.string().check((ctx) => {
4980
+ subdomain: z8.string().check((ctx) => {
4839
4981
  const problem = subdomainProblem(ctx.value);
4840
4982
  if (problem) ctx.issues.push({ code: "custom", message: problem, input: ctx.value });
4841
4983
  }).optional(),
4842
- size: z7.enum(SIZE_NAMES).optional(),
4984
+ size: z8.enum(SIZE_NAMES).optional(),
4843
4985
  /** The build output directory, relative to the app; the template's default when absent. */
4844
- dist: z7.string().optional(),
4986
+ dist: z8.string().optional(),
4845
4987
  /** 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()
4988
+ port: z8.number().int().min(1).max(65535).optional()
4847
4989
  });
4848
4990
  var SERVICE_KEY_RE = /^[a-z][a-z0-9-]{0,19}$/;
4849
4991
  var RESERVED_SERVICE_KEYS = ["app", "agent", "init", "volumes"];
@@ -4855,38 +4997,38 @@ var POSTGRES_PORT = 5432;
4855
4997
  var POSTGRES_IMAGE = "postgres:17";
4856
4998
  var POSTGRES_ENV = "DATABASE_URL";
4857
4999
  var IMAGE_RE = /^[a-z0-9][a-z0-9._/:@-]*$/;
4858
- var ServiceSchema = z7.strictObject({
4859
- template: z7.enum([...TEMPLATE_IDS, POSTGRES]),
5000
+ var ServiceSchema = z8.strictObject({
5001
+ template: z8.enum([...TEMPLATE_IDS, POSTGRES]),
4860
5002
  /** The service's directory, relative to the one holding kvbox.json; every template but postgres has one. */
4861
- dir: z7.string().min(1).optional(),
5003
+ dir: z8.string().min(1).optional(),
4862
5004
  /** 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(),
5005
+ image: z8.string().regex(IMAGE_RE, "an image name like postgres:17").optional(),
4864
5006
  /** The volume (a key of `volumes`) a postgres service keeps its data on. */
4865
- volume: z7.string().optional(),
5007
+ volume: z8.string().optional(),
4866
5008
  /** The box variable a postgres service's URL is written to, `DATABASE_URL` when absent. */
4867
- env: z7.string().optional(),
5009
+ env: z8.string().optional(),
4868
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`. */
4869
- context: z7.string().min(1).optional(),
4870
- dist: z7.string().optional(),
5011
+ context: z8.string().min(1).optional(),
5012
+ dist: z8.string().optional(),
4871
5013
  /**
4872
5014
  * A command run once per deploy in the service's new version (a docker service: in a container of
4873
5015
  * the new image; node, nextjs: in the new source, installed and built), with the box's variables,
4874
5016
  * before it replaces the running one. Migrations, mostly. A failing one stops that service's deploy.
4875
5017
  */
4876
- release: z7.string().optional(),
5018
+ release: z8.string().optional(),
4877
5019
  /** 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(),
5020
+ port: z8.number().int().min(1).max(65535).optional(),
4879
5021
  /** 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()
5022
+ paths: z8.array(z8.string().regex(ROUTE_RE, "a path like / or /api, no trailing slash")).min(1).optional()
4881
5023
  });
4882
- var StackConfigSchema = z7.strictObject({
5024
+ var StackConfigSchema = z8.strictObject({
4883
5025
  name: DeployConfigSchema.shape.name.optional(),
4884
5026
  org: DeployConfigSchema.shape.org,
4885
5027
  subdomain: DeployConfigSchema.shape.subdomain,
4886
5028
  size: DeployConfigSchema.shape.size,
4887
5029
  /** 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)
5030
+ volumes: z8.record(z8.string(), z8.string()).optional(),
5031
+ services: z8.record(z8.string(), ServiceSchema)
4890
5032
  });
4891
5033
  function volumeGib(text2) {
4892
5034
  const mib = parseMib(text2);
@@ -5335,10 +5477,10 @@ async function deployStack(d) {
5335
5477
  const { dir, opts, client, cloud } = d;
5336
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}`);
5337
5479
  const exposed = await exposedPorts(dir, d.stack);
5338
- const portOf = (template) => templateById(template).port;
5339
- pick(stackServices(d.stack, portOf, exposed), opts.only);
5480
+ const portOf2 = (template) => templateById(template).port;
5481
+ pick(stackServices(d.stack, portOf2, exposed), opts.only);
5340
5482
  const config = await settle(d);
5341
- const services = stackServices(config, portOf, exposed);
5483
+ const services = stackServices(config, portOf2, exposed);
5342
5484
  const picked = pick(services, opts.only);
5343
5485
  if (cloud && config.subdomain !== void 0) await refuseOtherAddress(client, { ...config, name: config.name });
5344
5486
  let saved = config;
@@ -6301,11 +6443,314 @@ for (const cmd of bucketCommand.commands) {
6301
6443
  else withOrg(cmd);
6302
6444
  }
6303
6445
 
6304
- // src/commands/managed/kind.ts
6446
+ // src/commands/cron/index.ts
6305
6447
  import { Command as Command88 } from "commander";
6306
6448
 
6307
- // src/commands/managed/create.ts
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
6308
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
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";
6751
+
6752
+ // src/commands/managed/create.ts
6753
+ import { Command as Command90 } from "commander";
6309
6754
  import { setTimeout as sleep3 } from "timers/promises";
6310
6755
 
6311
6756
  // src/commands/managed/shared.ts
@@ -6338,7 +6783,7 @@ async function managedClient(cmd) {
6338
6783
  }
6339
6784
  return client;
6340
6785
  }
6341
- 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}`;
6342
6787
  var storageText = (m) => m.health?.storageUsedBytes !== void 0 ? `${gb(m.health.storageUsedBytes)} of ${m.storageGib} GB used` : `${m.storageGib} GB`;
6343
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;
6344
6789
  function stateText(m) {
@@ -6349,7 +6794,7 @@ function stateText(m) {
6349
6794
  return `${status(m.status)}, ${m.health.accepting ? "accepting connections" : color.yellow("not accepting connections")}`;
6350
6795
  }
6351
6796
  function infoRows(spec, m, user) {
6352
- const name = shownName2(m, user);
6797
+ const name = shownName3(m, user);
6353
6798
  const rows2 = [
6354
6799
  ["name", color.bold(name)],
6355
6800
  ["status", stateText(m)],
@@ -6365,7 +6810,7 @@ function infoRows(spec, m, user) {
6365
6810
  rows2.push(["created", `${age(m.createdAt)}${m.createdBy ? ` by ${m.createdBy}` : ""}`]);
6366
6811
  return rows2;
6367
6812
  }
6368
- function printRows2(rows2) {
6813
+ function printRows3(rows2) {
6369
6814
  const width2 = Math.max(...rows2.map(([label]) => label.length));
6370
6815
  for (const [label, value] of rows2) process.stdout.write(`${color.dim(label.padEnd(width2))} ${value}
6371
6816
  `);
@@ -6391,8 +6836,8 @@ function parseStorage(text2, flag) {
6391
6836
  // src/commands/managed/create.ts
6392
6837
  var READY_WAIT_MS = 9e4;
6393
6838
  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");
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");
6396
6841
  for (const o of spec.options) command.option(`--${o.name} <${o.arg}>`, o.help);
6397
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) => {
6398
6843
  const options = Object.fromEntries(spec.options.flatMap((o) => typeof opts[o.name] === "string" ? [[o.name, opts[o.name]]] : []));
@@ -6406,9 +6851,9 @@ var createCommand7 = (spec) => {
6406
6851
  const client = await managedClient(cmd);
6407
6852
  try {
6408
6853
  const made = await spin(`creating ${spec.title} database ${name}\u2026`, client.createManaged(spec.kind, req));
6409
- const shown = shownName2(made, me(client));
6854
+ const shown = shownName3(made, me(client));
6410
6855
  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)) {
6856
+ for (const until2 = Date.now() + READY_WAIT_MS; Date.now() < until2; await sleep3(READY_STEP_MS)) {
6412
6857
  const now = await client.getManaged(spec.kind, shown).catch(() => void 0);
6413
6858
  if (now?.health?.ready && now.health.accepting) return true;
6414
6859
  }
@@ -6419,7 +6864,7 @@ var createCommand7 = (spec) => {
6419
6864
  return;
6420
6865
  }
6421
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)`)}`);
6422
- 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]));
6423
6868
  info("");
6424
6869
  info("Nobody can reach it yet. To let something in:");
6425
6870
  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 +6878,8 @@ var createCommand7 = (spec) => {
6433
6878
  };
6434
6879
 
6435
6880
  // 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) => {
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) => {
6438
6883
  const storageGib = parseStorage(size, "size");
6439
6884
  const client = await managedClient(cmd);
6440
6885
  try {
@@ -6447,21 +6892,21 @@ var growCommand3 = (spec) => new Command78("grow").description("give a database
6447
6892
  });
6448
6893
 
6449
6894
  // 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) => {
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) => {
6452
6897
  const client = await managedClient(cmd);
6453
6898
  try {
6454
6899
  const m = await client.getManaged(spec.kind, name);
6455
6900
  if (opts.json) json(m);
6456
- else printRows2(infoRows(spec, m, me(client)));
6901
+ else printRows3(infoRows(spec, m, me(client)));
6457
6902
  } finally {
6458
6903
  await client.close();
6459
6904
  }
6460
6905
  });
6461
6906
 
6462
6907
  // 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) => {
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) => {
6465
6910
  const client = await managedClient(cmd);
6466
6911
  try {
6467
6912
  const m = await spin(`linking ${box} to ${name}\u2026`, client.linkManaged(spec.kind, name, box));
@@ -6477,7 +6922,7 @@ var linkCommand2 = (spec) => new Command80("link").description("let a box reach
6477
6922
  });
6478
6923
 
6479
6924
  // src/commands/managed/ls.ts
6480
- import { Command as Command81 } from "commander";
6925
+ import { Command as Command94 } from "commander";
6481
6926
  function listRows(items, user, kindColumn) {
6482
6927
  return items.map((m) => ({
6483
6928
  owner: m.owner === user ? "private" : m.owner,
@@ -6491,7 +6936,7 @@ function listRows(items, user, kindColumn) {
6491
6936
  created: age(m.createdAt)
6492
6937
  }));
6493
6938
  }
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) => {
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) => {
6495
6940
  const client = await managedClient(cmd);
6496
6941
  try {
6497
6942
  const items = await client.listManaged(spec?.kind, { all: opts.all });
@@ -6511,8 +6956,8 @@ var lsCommand12 = (spec) => new Command81("ls").alias("list").description(spec ?
6511
6956
  });
6512
6957
 
6513
6958
  // 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) => {
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) => {
6516
6961
  const client = await managedClient(cmd);
6517
6962
  try {
6518
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);
@@ -6521,15 +6966,15 @@ var passwordCommand = (spec) => new Command82("password").description("show a da
6521
6966
  return;
6522
6967
  }
6523
6968
  if (opts.reset) info(`${color.green("\u2713")} database ${name} has a new password; the old one no longer works`);
6524
- printRows2(secretRows(secret));
6969
+ printRows3(secretRows(secret));
6525
6970
  } finally {
6526
6971
  await client.close();
6527
6972
  }
6528
6973
  });
6529
6974
 
6530
6975
  // 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) => {
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) => {
6533
6978
  if (state !== "on" && state !== "off") throw new KvboxError(`write on or off: kvbox ${spec.command} public ${name} on`);
6534
6979
  const client = await managedClient(cmd);
6535
6980
  try {
@@ -6550,8 +6995,8 @@ var publicCommand = (spec) => new Command83("public").description("open a databa
6550
6995
  });
6551
6996
 
6552
6997
  // 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) => {
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) => {
6555
7000
  const client = await managedClient(cmd);
6556
7001
  try {
6557
7002
  if (!await confirm(`Delete database ${name} and all its data? There is no backup.`, opts.yes ?? false)) {
@@ -6567,8 +7012,8 @@ var rmCommand10 = (spec) => new Command84("rm").alias("remove").description("del
6567
7012
  });
6568
7013
 
6569
7014
  // 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) => {
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) => {
6572
7017
  const client = await managedClient(cmd);
6573
7018
  try {
6574
7019
  const m = await spin(`starting ${name}\u2026`, client.startManaged(spec.kind, name));
@@ -6580,8 +7025,8 @@ var startCommand2 = (spec) => new Command85("start").description("run a stopped
6580
7025
  });
6581
7026
 
6582
7027
  // 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) => {
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) => {
6585
7030
  const client = await managedClient(cmd);
6586
7031
  try {
6587
7032
  const m = await spin(`stopping ${name}\u2026`, client.stopManaged(spec.kind, name));
@@ -6593,8 +7038,8 @@ var stopCommand2 = (spec) => new Command86("stop").description("shut a database
6593
7038
  });
6594
7039
 
6595
7040
  // 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) => {
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) => {
6598
7043
  const client = await managedClient(cmd);
6599
7044
  try {
6600
7045
  const m = await spin(`unlinking ${box} from ${name}\u2026`, client.unlinkManaged(spec.kind, name, box));
@@ -6607,8 +7052,8 @@ var unlinkCommand2 = (spec) => new Command87("unlink").description("stop a box f
6607
7052
 
6608
7053
  // src/commands/managed/kind.ts
6609
7054
  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]) {
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]) {
6612
7057
  command.addCommand(make(spec).option("--org <slug>", "act in this org (- for your personal databases)"));
6613
7058
  }
6614
7059
  return command;
@@ -6621,14 +7066,14 @@ var pgCommand = kindCommand(POSTGRES2, "managed PostgreSQL: a database kvbox run
6621
7066
  var redisCommand = kindCommand(REDIS, "managed Redis (Valkey): a Redis kvbox runs for you, private until you link a box or make it public");
6622
7067
 
6623
7068
  // 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)"));
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)"));
6626
7071
 
6627
7072
  // src/commands/env/index.ts
6628
- import { Command as Command93 } from "commander";
7073
+ import { Command as Command106 } from "commander";
6629
7074
 
6630
7075
  // src/commands/env/ls.ts
6631
- import { Command as Command90 } from "commander";
7076
+ import { Command as Command103 } from "commander";
6632
7077
 
6633
7078
  // src/commands/env/shared.ts
6634
7079
  function requireCloud4(client) {
@@ -6655,7 +7100,7 @@ function firstBootHint(box, name) {
6655
7100
  }
6656
7101
 
6657
7102
  // 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) => {
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) => {
6659
7104
  const client = await clientFor(cmd.optsWithGlobals(), { autoStart: false });
6660
7105
  try {
6661
7106
  if (opts.box !== void 0) {
@@ -6694,8 +7139,8 @@ var lsCommand13 = new Command90("ls").alias("list").description("list the variab
6694
7139
  });
6695
7140
 
6696
7141
  // 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) => {
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) => {
6699
7144
  const client = await clientFor(cmd.optsWithGlobals(), { autoStart: false });
6700
7145
  try {
6701
7146
  const target = opts.box === void 0 ? void 0 : await findBox2(client, opts.box);
@@ -6732,8 +7177,8 @@ var rmCommand11 = new Command91("rm").alias("remove").description("remove variab
6732
7177
  });
6733
7178
 
6734
7179
  // 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) => {
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) => {
6737
7182
  const client = await clientFor(cmd.optsWithGlobals(), { autoStart: false });
6738
7183
  try {
6739
7184
  const owner = opts.box === void 0 ? requireCloud4(client) : void 0;
@@ -6770,14 +7215,14 @@ var setCommand2 = new Command92("set").description("add or change a variable; bo
6770
7215
  });
6771
7216
 
6772
7217
  // 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);
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);
6774
7219
  for (const cmd of envCommand.commands) cmd.option("--org <slug>", "the org's variables instead of yours");
6775
7220
 
6776
7221
  // src/commands/domain/index.ts
6777
- import { Command as Command97 } from "commander";
7222
+ import { Command as Command110 } from "commander";
6778
7223
 
6779
7224
  // src/commands/domain/add.ts
6780
- import { Command as Command94 } from "commander";
7225
+ import { Command as Command107 } from "commander";
6781
7226
 
6782
7227
  // src/commands/domain/shared.ts
6783
7228
  function requireCloud5(client) {
@@ -6797,7 +7242,7 @@ function hostIn(name, zone) {
6797
7242
  }
6798
7243
 
6799
7244
  // 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) => {
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) => {
6801
7246
  const domain = assertDomain(domainArg.trim().toLowerCase());
6802
7247
  const port = opts.port === void 0 ? void 0 : parsePorts([opts.port])[0];
6803
7248
  const client = await clientFor(cmd.optsWithGlobals());
@@ -6833,8 +7278,8 @@ kvbox checks every minute; ${domain} is served at ${d.url} once its records are
6833
7278
  });
6834
7279
 
6835
7280
  // 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) => {
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) => {
6838
7283
  const client = await clientFor(cmd.optsWithGlobals());
6839
7284
  try {
6840
7285
  requireCloud5(client);
@@ -6863,8 +7308,8 @@ var lsCommand14 = new Command95("ls").alias("list").description("list your custo
6863
7308
  });
6864
7309
 
6865
7310
  // 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) => {
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) => {
6868
7313
  const domain = domainArg.trim().toLowerCase();
6869
7314
  const client = await clientFor(cmd.optsWithGlobals());
6870
7315
  try {
@@ -6885,7 +7330,7 @@ var rmCommand12 = new Command96("rm").alias("remove").description("stop serving
6885
7330
  });
6886
7331
 
6887
7332
  // 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);
7333
+ var domainCommand = new Command110("domain").alias("domains").description("serve a box at a domain of your own").addCommand(addCommand4).addCommand(lsCommand16).addCommand(rmCommand14);
6889
7334
  for (const cmd of domainCommand.commands) cmd.option("--org <slug>", "act in this org (- for your personal boxes)");
6890
7335
 
6891
7336
  // src/commands/update.ts
@@ -6893,7 +7338,7 @@ import { spawn as spawn6 } from "child_process";
6893
7338
  import { mkdtempSync, rmSync, writeFileSync as writeFileSync2 } from "fs";
6894
7339
  import { tmpdir } from "os";
6895
7340
  import { join as join9 } from "path";
6896
- import { Command as Command98 } from "commander";
7341
+ import { Command as Command111 } from "commander";
6897
7342
 
6898
7343
  // src/update.ts
6899
7344
  import { mkdirSync, readFileSync as readFileSync3, writeFileSync } from "fs";
@@ -7012,7 +7457,7 @@ function run2(cmd, args) {
7012
7457
  child.on("exit", (code, signal) => resolve4(code ?? (signal ? 1 : 0)));
7013
7458
  });
7014
7459
  }
7015
- var selfUpdateCommand = new Command98("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 () => {
7016
7461
  suppressUpdateNotice();
7017
7462
  const inst = installerFor(process.platform, process.env["KVBOX_INSTALL_URL"] || INSTALL_BASE);
7018
7463
  let code;
@@ -7080,6 +7525,7 @@ var HELP_GROUPS = [
7080
7525
  ["pg", "managed PostgreSQL: a database kvbox runs for you"],
7081
7526
  ["redis", "managed Redis (Valkey): a Redis kvbox runs for you"],
7082
7527
  ["managed", "every managed database, whatever its kind"],
7528
+ ["cron", "call a box on a schedule, waking it first if it sleeps"],
7083
7529
  ["env", "environment variables and secrets every box of yours gets"],
7084
7530
  ["domain", "serve a box at a domain of your own"]
7085
7531
  ]
@@ -7137,7 +7583,7 @@ function installRootHelp(program) {
7137
7583
 
7138
7584
  // src/program.ts
7139
7585
  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();
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();
7141
7587
  program.addCommand(vmCommand);
7142
7588
  program.addCommand(snapshotsCommand);
7143
7589
  program.addCommand(volumeCommand);
@@ -7145,6 +7591,7 @@ function buildProgram() {
7145
7591
  program.addCommand(pgCommand);
7146
7592
  program.addCommand(redisCommand);
7147
7593
  program.addCommand(managedCommand);
7594
+ program.addCommand(cronCommand);
7148
7595
  program.addCommand(envCommand);
7149
7596
  program.addCommand(domainCommand);
7150
7597
  program.addCommand(loginCommand);