@kvbox/cli 0.5.48 → 0.5.50
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 +541 -158
- package/dist/kvbox.js.map +1 -1
- package/package.json +1 -1
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
|
|
152
|
+
import { Command as Command95 } 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.5.
|
|
167
|
+
var VERSION = versionOf(import.meta.url, true ? "0.5.50" : void 0);
|
|
168
168
|
|
|
169
169
|
// src/commands/vm/index.ts
|
|
170
170
|
import { Command as Command37 } from "commander";
|
|
@@ -426,7 +426,7 @@ import { openSync } from "fs";
|
|
|
426
426
|
import { mkdir as mkdir2, readFile as readFile3, stat } from "fs/promises";
|
|
427
427
|
import { setTimeout as sleep } from "timers/promises";
|
|
428
428
|
import { Agent, request } from "undici";
|
|
429
|
-
import { z as
|
|
429
|
+
import { z as z6 } from "zod";
|
|
430
430
|
|
|
431
431
|
// ../shared/src/api.ts
|
|
432
432
|
import { z as z2 } from "zod";
|
|
@@ -802,6 +802,15 @@ var CapacitySchema = z2.object({
|
|
|
802
802
|
version: z2.string().optional()
|
|
803
803
|
});
|
|
804
804
|
var ImageSchema = z2.object({ name: z2.string(), version: z2.string().nullable() });
|
|
805
|
+
var ImageIndexSchema = z2.object({
|
|
806
|
+
updatedAt: z2.string(),
|
|
807
|
+
images: z2.record(z2.string(), z2.object({ version: z2.string().min(1), minServer: z2.string().min(1).optional() }))
|
|
808
|
+
});
|
|
809
|
+
var LatestImagesSchema = z2.object({
|
|
810
|
+
updatedAt: z2.string().nullable(),
|
|
811
|
+
images: ImageIndexSchema.shape.images,
|
|
812
|
+
checkedAt: z2.string().nullable()
|
|
813
|
+
});
|
|
805
814
|
var RecoveryReportSchema = z2.object({
|
|
806
815
|
at: z2.string(),
|
|
807
816
|
booted: z2.array(z2.string()),
|
|
@@ -929,13 +938,21 @@ var UsageDaySchema = z2.object({
|
|
|
929
938
|
cost: z2.number(),
|
|
930
939
|
currency: z2.string(),
|
|
931
940
|
boxes: z2.array(UsageDayItemSchema),
|
|
932
|
-
volumes: z2.array(UsageDayItemSchema)
|
|
941
|
+
volumes: z2.array(UsageDayItemSchema),
|
|
942
|
+
/** Object storage that existed that day (#182); absent on a day without any. */
|
|
943
|
+
storage: z2.array(UsageDayItemSchema).optional()
|
|
933
944
|
});
|
|
934
945
|
var UsageReportSchema = z2.object({
|
|
935
946
|
window: z2.object({ from: z2.string(), to: z2.string() }),
|
|
936
947
|
boxes: z2.array(BoxUsageSchema),
|
|
937
948
|
/** Absent from a side older than #91. */
|
|
938
949
|
volumes: z2.array(VolumeUsageSchema).optional(),
|
|
950
|
+
/**
|
|
951
|
+
* Object storage (#182, control plane only): one row per storage a slug has or had, shaped like a
|
|
952
|
+
* volume's. `volumeHours` are the hours it existed, `volumeGibHours` those of the GiB beyond the
|
|
953
|
+
* included ones, `sizeGib` its whole size. Absent when there is none.
|
|
954
|
+
*/
|
|
955
|
+
storage: z2.array(VolumeUsageSchema).optional(),
|
|
939
956
|
/** With `?by=day` only, oldest day first. */
|
|
940
957
|
days: z2.array(UsageDaySchema).optional(),
|
|
941
958
|
totals: z2.object({
|
|
@@ -945,7 +962,7 @@ var UsageReportSchema = z2.object({
|
|
|
945
962
|
diskGibHours: z2.number(),
|
|
946
963
|
volumeHours: z2.number().optional(),
|
|
947
964
|
volumeGibHours: z2.number().optional(),
|
|
948
|
-
/** Boxes and
|
|
965
|
+
/** Boxes, volumes and object storage together. */
|
|
949
966
|
cost: z2.object({ amount: z2.number(), currency: z2.string() }).optional()
|
|
950
967
|
})
|
|
951
968
|
});
|
|
@@ -1221,7 +1238,15 @@ var PricingSchema = z3.object({
|
|
|
1221
1238
|
diskGibHour: z3.number().nonnegative(),
|
|
1222
1239
|
volumeHour: z3.number().nonnegative().default(0),
|
|
1223
1240
|
volumeGibHour: z3.number().nonnegative().default(0),
|
|
1224
|
-
diskIncludedGib: z3.number().int().nonnegative().default(0)
|
|
1241
|
+
diskIncludedGib: z3.number().int().nonnegative().default(0),
|
|
1242
|
+
/**
|
|
1243
|
+
* Object storage (#182): an hour of a slug's storage existing, whatever it holds, which covers its
|
|
1244
|
+
* hidden box and the first `storageIncludedGib` of its size; each GiB above that is `storageGibHour`.
|
|
1245
|
+
* A price list from before object storage charges nothing for it.
|
|
1246
|
+
*/
|
|
1247
|
+
storageHour: z3.number().nonnegative().default(0),
|
|
1248
|
+
storageGibHour: z3.number().nonnegative().default(0),
|
|
1249
|
+
storageIncludedGib: z3.number().int().nonnegative().default(0)
|
|
1225
1250
|
});
|
|
1226
1251
|
var PriceListSchema = PricingSchema.extend({ welcomeCredit: z3.number().nonnegative() });
|
|
1227
1252
|
var HOUR_MS = 36e5;
|
|
@@ -1261,11 +1286,18 @@ var ManagedCatalogEntrySchema = z4.object({
|
|
|
1261
1286
|
description: z4.string(),
|
|
1262
1287
|
/** The version a new one runs, as shown: `18`. */
|
|
1263
1288
|
version: z4.string(),
|
|
1264
|
-
/** The port
|
|
1289
|
+
/** The port a linked box reaches it on. */
|
|
1265
1290
|
port: z4.number().int(),
|
|
1291
|
+
/** The port `public on` opens behind a host port: `port` again unless the kind serves TLS on another. */
|
|
1292
|
+
publicPort: z4.number().int(),
|
|
1293
|
+
/** Its guide, as a URL. */
|
|
1294
|
+
docs: z4.string().optional(),
|
|
1266
1295
|
storage: z4.object({ defaultGib: z4.number().int(), minGib: z4.number().int(), maxGib: z4.number().int() }),
|
|
1267
|
-
/**
|
|
1268
|
-
|
|
1296
|
+
/**
|
|
1297
|
+
* What create takes of this kind alone, beside what every kind takes (name, password, storage, near): a
|
|
1298
|
+
* flag and a form field each, all optional, `default` in words.
|
|
1299
|
+
*/
|
|
1300
|
+
options: z4.array(z4.object({ name: z4.string(), title: z4.string(), description: z4.string(), default: z4.string() })),
|
|
1269
1301
|
/** A month of it running with the default storage, and each further GB of storage. */
|
|
1270
1302
|
price: PriceSchema.extend({ storageGibPerMonth: z4.number() }),
|
|
1271
1303
|
/** Whether a host answering now can run it. */
|
|
@@ -1273,25 +1305,24 @@ var ManagedCatalogEntrySchema = z4.object({
|
|
|
1273
1305
|
});
|
|
1274
1306
|
var CreateManagedRequest = z4.object({
|
|
1275
1307
|
name: z4.string(),
|
|
1276
|
-
|
|
1277
|
-
|
|
1308
|
+
/** The kind's own options by name (its catalog entry lists them); the kind checks them. */
|
|
1309
|
+
options: z4.record(z4.string(), z4.string()).optional(),
|
|
1278
1310
|
password: z4.string().optional(),
|
|
1279
1311
|
storageGib: z4.number().int().optional(),
|
|
1280
1312
|
/** Place it on the host of this box, so the box can be linked to it. */
|
|
1281
1313
|
near: z4.string().optional()
|
|
1282
1314
|
});
|
|
1283
1315
|
var ManagedHealthSchema = z4.object({
|
|
1284
|
-
/** Its first start has finished:
|
|
1316
|
+
/** Its first start has finished: it has set itself up on its storage. */
|
|
1285
1317
|
ready: z4.boolean(),
|
|
1286
1318
|
/** It accepts connections. */
|
|
1287
1319
|
accepting: z4.boolean(),
|
|
1288
1320
|
version: z4.string(),
|
|
1289
|
-
connections: z4.number().int(),
|
|
1290
|
-
/** The size of the data itself. */
|
|
1291
|
-
dataBytes: z4.number().optional(),
|
|
1292
1321
|
/** The storage volume: what is used of it and its size. */
|
|
1293
1322
|
storageUsedBytes: z4.number().optional(),
|
|
1294
|
-
storageTotalBytes: z4.number().optional()
|
|
1323
|
+
storageTotalBytes: z4.number().optional(),
|
|
1324
|
+
/** What else the kind reports, ready to show: `{title: "Connections", value: "3"}`. */
|
|
1325
|
+
facts: z4.array(z4.object({ title: z4.string(), value: z4.string() }))
|
|
1295
1326
|
});
|
|
1296
1327
|
var UrlsSchema = z4.object({ private: z4.string(), public: z4.string().optional() });
|
|
1297
1328
|
var ManagedSchema = z4.object({
|
|
@@ -1304,8 +1335,8 @@ var ManagedSchema = z4.object({
|
|
|
1304
1335
|
status: BoxStatusSchema,
|
|
1305
1336
|
/** The catalog version: `18`. */
|
|
1306
1337
|
version: z4.string(),
|
|
1307
|
-
|
|
1308
|
-
|
|
1338
|
+
/** What the kind keeps of its create options, defaults filled in: `{database, user}` for Postgres, `{}` for a kind with none. */
|
|
1339
|
+
settings: z4.record(z4.string(), z4.string()),
|
|
1309
1340
|
storageGib: z4.number().int(),
|
|
1310
1341
|
/** Where a linked box reaches it: `<name>.<slug>.kvbox` (resolves from a box of any slug it is linked to) and the port. */
|
|
1311
1342
|
private: z4.object({ host: z4.string(), port: z4.number().int() }),
|
|
@@ -1324,13 +1355,66 @@ var ManagedSchema = z4.object({
|
|
|
1324
1355
|
/** Only in `GET /managed/<kind>/<name>` (asked live): null when it is not running or did not answer. */
|
|
1325
1356
|
health: ManagedHealthSchema.nullable().optional()
|
|
1326
1357
|
});
|
|
1327
|
-
var ManagedSecretSchema = z4.object({
|
|
1358
|
+
var ManagedSecretSchema = z4.object({ password: z4.string(), urls: UrlsSchema });
|
|
1328
1359
|
var CreatedManagedSchema = ManagedSchema.extend({ secret: ManagedSecretSchema });
|
|
1329
1360
|
var ResetPasswordRequest = z4.object({ password: z4.string().optional() });
|
|
1330
1361
|
var SetPublicRequest = z4.object({ on: z4.boolean() });
|
|
1331
1362
|
var ManagedLinkRequest = z4.object({ box: z4.string() });
|
|
1332
1363
|
var GrowManagedRequest = z4.object({ storageGib: z4.number().int() });
|
|
1333
1364
|
|
|
1365
|
+
// ../shared/src/storage.ts
|
|
1366
|
+
import { z as z5 } from "zod";
|
|
1367
|
+
var ObjectStorageSchema = z5.object({
|
|
1368
|
+
owner: z5.string(),
|
|
1369
|
+
ownerKind: z5.enum(["user", "org"]),
|
|
1370
|
+
/** `https://s3-<slug>.<domain>`: what an S3 client is given, with path-style addressing. Null while the address is not claimed. */
|
|
1371
|
+
endpoint: z5.string().nullable(),
|
|
1372
|
+
region: z5.string(),
|
|
1373
|
+
/** The most it may hold. */
|
|
1374
|
+
sizeGib: z5.number().int(),
|
|
1375
|
+
/** `running` when it answers; `unknown` while its host is not heard from. */
|
|
1376
|
+
status: BoxStatusSchema,
|
|
1377
|
+
/** With `?live=1`, when the storage answered: what is on its disk, and the disk's real size. */
|
|
1378
|
+
usedBytes: z5.number().optional(),
|
|
1379
|
+
totalBytes: z5.number().optional(),
|
|
1380
|
+
host: z5.string(),
|
|
1381
|
+
country: z5.string().optional(),
|
|
1382
|
+
buckets: z5.number().int(),
|
|
1383
|
+
price: z5.object({ perMonth: z5.number(), currency: z5.string() }),
|
|
1384
|
+
createdAt: z5.string()
|
|
1385
|
+
});
|
|
1386
|
+
var BucketSchema = z5.object({
|
|
1387
|
+
name: z5.string(),
|
|
1388
|
+
owner: z5.string(),
|
|
1389
|
+
ownerKind: z5.enum(["user", "org"]),
|
|
1390
|
+
endpoint: z5.string().nullable(),
|
|
1391
|
+
region: z5.string(),
|
|
1392
|
+
keys: z5.number().int(),
|
|
1393
|
+
objects: z5.number().optional(),
|
|
1394
|
+
bytes: z5.number().optional(),
|
|
1395
|
+
createdBy: z5.string().nullable(),
|
|
1396
|
+
createdAt: z5.string()
|
|
1397
|
+
});
|
|
1398
|
+
var CreateBucketRequest = z5.object({
|
|
1399
|
+
name: z5.string(),
|
|
1400
|
+
sizeGib: z5.number().int().optional(),
|
|
1401
|
+
near: z5.string().optional()
|
|
1402
|
+
});
|
|
1403
|
+
var CreatedBucketSchema = BucketSchema.extend({ storage: ObjectStorageSchema, storageCreated: z5.boolean() });
|
|
1404
|
+
var BucketInfoSchema = BucketSchema.extend({ storage: ObjectStorageSchema });
|
|
1405
|
+
var BucketKeySchema = z5.object({
|
|
1406
|
+
id: z5.string(),
|
|
1407
|
+
name: z5.string(),
|
|
1408
|
+
bucket: z5.string(),
|
|
1409
|
+
owner: z5.string(),
|
|
1410
|
+
readOnly: z5.boolean(),
|
|
1411
|
+
createdBy: z5.string().nullable(),
|
|
1412
|
+
createdAt: z5.string()
|
|
1413
|
+
});
|
|
1414
|
+
var CreateBucketKeyRequest = z5.object({ name: z5.string().optional(), readOnly: z5.boolean().optional() });
|
|
1415
|
+
var CreatedBucketKeySchema = BucketKeySchema.extend({ secret: z5.string(), endpoint: z5.string().nullable(), region: z5.string() });
|
|
1416
|
+
var GrowStorageRequest = z5.object({ sizeGib: z5.number().int() });
|
|
1417
|
+
|
|
1334
1418
|
// src/kvm.ts
|
|
1335
1419
|
import { accessSync, constants, readFileSync, statSync } from "fs";
|
|
1336
1420
|
import { userInfo } from "os";
|
|
@@ -1485,7 +1569,7 @@ var ServerClient = class {
|
|
|
1485
1569
|
* `all`: every box on the platform (platform admins only, #78).
|
|
1486
1570
|
*/
|
|
1487
1571
|
listMachines(opts = {}) {
|
|
1488
|
-
return this.call("GET", `/machines${allQuery(opts)}`,
|
|
1572
|
+
return this.call("GET", `/machines${allQuery(opts)}`, z6.array(MachineSchema), void 0, opts.org);
|
|
1489
1573
|
}
|
|
1490
1574
|
createMachine(req) {
|
|
1491
1575
|
return this.call("POST", "/machines", MachineSchema, req);
|
|
@@ -1539,10 +1623,10 @@ var ServerClient = class {
|
|
|
1539
1623
|
}
|
|
1540
1624
|
/** Backups, the control plane's only: a box's disk in object storage. Newest first. */
|
|
1541
1625
|
listBackups() {
|
|
1542
|
-
return this.call("GET", "/backups",
|
|
1626
|
+
return this.call("GET", "/backups", z6.array(BackupSchema));
|
|
1543
1627
|
}
|
|
1544
1628
|
boxBackups(name) {
|
|
1545
|
-
return this.call("GET", `/machines/${encodeURIComponent(name)}/backups`,
|
|
1629
|
+
return this.call("GET", `/machines/${encodeURIComponent(name)}/backups`, z6.array(BackupSchema));
|
|
1546
1630
|
}
|
|
1547
1631
|
boxBackup(name, id) {
|
|
1548
1632
|
return this.call("GET", `/machines/${encodeURIComponent(name)}/backups/${encodeURIComponent(id)}`, BackupSchema);
|
|
@@ -1557,7 +1641,7 @@ var ServerClient = class {
|
|
|
1557
1641
|
}
|
|
1558
1642
|
/** Wake hooks (#101), the control plane's only: a URL and a secret that wake the box. */
|
|
1559
1643
|
boxHooks(name) {
|
|
1560
|
-
return this.call("GET", `/machines/${encodeURIComponent(name)}/hooks`,
|
|
1644
|
+
return this.call("GET", `/machines/${encodeURIComponent(name)}/hooks`, z6.array(WakeHookSchema));
|
|
1561
1645
|
}
|
|
1562
1646
|
createBoxHook(name) {
|
|
1563
1647
|
return this.call("POST", `/machines/${encodeURIComponent(name)}/hooks`, CreatedWakeHookSchema);
|
|
@@ -1585,7 +1669,7 @@ var ServerClient = class {
|
|
|
1585
1669
|
}
|
|
1586
1670
|
/** Every readable box's subdomains, one entry each. */
|
|
1587
1671
|
listSubdomains() {
|
|
1588
|
-
return this.call("GET", "/subdomains",
|
|
1672
|
+
return this.call("GET", "/subdomains", z6.array(SubdomainSchema));
|
|
1589
1673
|
}
|
|
1590
1674
|
/** Custom domains (#89), the control plane's only: serve the box at the user's own name. */
|
|
1591
1675
|
addDomain(name, req) {
|
|
@@ -1596,7 +1680,7 @@ var ServerClient = class {
|
|
|
1596
1680
|
}
|
|
1597
1681
|
/** Every readable box's custom domains. */
|
|
1598
1682
|
listDomains() {
|
|
1599
|
-
return this.call("GET", "/domains",
|
|
1683
|
+
return this.call("GET", "/domains", z6.array(DomainSchema));
|
|
1600
1684
|
}
|
|
1601
1685
|
/** A running box's own load, memory and disk, asked of its guest (#67). */
|
|
1602
1686
|
machineStats(name) {
|
|
@@ -1625,22 +1709,22 @@ var ServerClient = class {
|
|
|
1625
1709
|
return this.call("POST", "/billing/redeem", RedeemResponseSchema, { code });
|
|
1626
1710
|
}
|
|
1627
1711
|
deleteMachine(name) {
|
|
1628
|
-
return this.call("DELETE", `/machines/${encodeURIComponent(name)}`,
|
|
1712
|
+
return this.call("DELETE", `/machines/${encodeURIComponent(name)}`, z6.undefined());
|
|
1629
1713
|
}
|
|
1630
1714
|
/** Like `listMachines`, for snapshots. */
|
|
1631
1715
|
listSnapshots(opts = {}) {
|
|
1632
|
-
return this.call("GET", `/snapshots${allQuery(opts)}`,
|
|
1716
|
+
return this.call("GET", `/snapshots${allQuery(opts)}`, z6.array(SnapshotSchema), void 0, opts.org);
|
|
1633
1717
|
}
|
|
1634
1718
|
createSnapshot(req) {
|
|
1635
1719
|
return this.call("POST", "/snapshots", SnapshotSchema, req);
|
|
1636
1720
|
}
|
|
1637
1721
|
deleteSnapshot(name) {
|
|
1638
|
-
return this.call("DELETE", `/snapshots/${encodeURIComponent(name)}`,
|
|
1722
|
+
return this.call("DELETE", `/snapshots/${encodeURIComponent(name)}`, z6.undefined());
|
|
1639
1723
|
}
|
|
1640
1724
|
// ---- environment variables (#88), a control plane only: the caller's slug, or `--org`'s ----
|
|
1641
1725
|
/** `org`: that org's list instead of `--org`'s (or the caller's own). */
|
|
1642
1726
|
listEnv(org) {
|
|
1643
|
-
return this.call("GET", "/vars",
|
|
1727
|
+
return this.call("GET", "/vars", z6.array(EnvVarSchema), void 0, org);
|
|
1644
1728
|
}
|
|
1645
1729
|
setEnv(name, req) {
|
|
1646
1730
|
return this.call("PUT", `/vars/${encodeURIComponent(name)}`, EnvChangeSchema, req);
|
|
@@ -1660,13 +1744,13 @@ var ServerClient = class {
|
|
|
1660
1744
|
}
|
|
1661
1745
|
// ---- volumes (#52) ----
|
|
1662
1746
|
listVolumes(opts = {}) {
|
|
1663
|
-
return this.call("GET", `/volumes${allQuery(opts)}`,
|
|
1747
|
+
return this.call("GET", `/volumes${allQuery(opts)}`, z6.array(VolumeSchema), void 0, opts.org);
|
|
1664
1748
|
}
|
|
1665
1749
|
createVolume(req) {
|
|
1666
1750
|
return this.call("POST", "/volumes", VolumeSchema, req);
|
|
1667
1751
|
}
|
|
1668
1752
|
deleteVolume(name) {
|
|
1669
|
-
return this.call("DELETE", `/volumes/${encodeURIComponent(name)}`,
|
|
1753
|
+
return this.call("DELETE", `/volumes/${encodeURIComponent(name)}`, z6.undefined());
|
|
1670
1754
|
}
|
|
1671
1755
|
/** Both answer with the box as it is afterwards (restarted when it was running). */
|
|
1672
1756
|
attachVolume(name, req) {
|
|
@@ -1679,16 +1763,45 @@ var ServerClient = class {
|
|
|
1679
1763
|
resizeVolume(name, sizeGib) {
|
|
1680
1764
|
return this.call("POST", `/volumes/${encodeURIComponent(name)}/resize`, VolumeSchema, { sizeGib });
|
|
1681
1765
|
}
|
|
1766
|
+
// ---- object storage (#182): the control plane's alone ----
|
|
1767
|
+
listBuckets(opts = {}) {
|
|
1768
|
+
return this.call("GET", `/buckets${allQuery(opts)}`, z6.array(BucketSchema), void 0, opts.org);
|
|
1769
|
+
}
|
|
1770
|
+
/** The first bucket of a slug also makes its storage: a box boots twice, so this may take a couple of minutes. */
|
|
1771
|
+
createBucket(req) {
|
|
1772
|
+
return this.call("POST", "/buckets", CreatedBucketSchema, req);
|
|
1773
|
+
}
|
|
1774
|
+
getBucket(name) {
|
|
1775
|
+
return this.call("GET", `/buckets/${encodeURIComponent(name)}`, BucketInfoSchema);
|
|
1776
|
+
}
|
|
1777
|
+
deleteBucket(name, force = false) {
|
|
1778
|
+
return this.call("DELETE", `/buckets/${encodeURIComponent(name)}${force ? "?force=1" : ""}`, z6.undefined());
|
|
1779
|
+
}
|
|
1780
|
+
listBucketKeys(name) {
|
|
1781
|
+
return this.call("GET", `/buckets/${encodeURIComponent(name)}/keys`, z6.array(BucketKeySchema));
|
|
1782
|
+
}
|
|
1783
|
+
createBucketKey(name, req) {
|
|
1784
|
+
return this.call("POST", `/buckets/${encodeURIComponent(name)}/keys`, CreatedBucketKeySchema, req);
|
|
1785
|
+
}
|
|
1786
|
+
deleteBucketKey(name, id) {
|
|
1787
|
+
return this.call("DELETE", `/buckets/${encodeURIComponent(name)}/keys/${encodeURIComponent(id)}`, z6.undefined());
|
|
1788
|
+
}
|
|
1789
|
+
listStorage(opts = {}) {
|
|
1790
|
+
return this.call("GET", `/storage${allQuery(opts)}`, z6.array(ObjectStorageSchema), void 0, opts.org);
|
|
1791
|
+
}
|
|
1792
|
+
growStorage(sizeGib) {
|
|
1793
|
+
return this.call("POST", "/storage/grow", ObjectStorageSchema, { sizeGib });
|
|
1794
|
+
}
|
|
1682
1795
|
// ---- managed services (#173): the control plane's alone ----
|
|
1683
1796
|
managedPath(kind, name, rest = "") {
|
|
1684
1797
|
return `/managed/${encodeURIComponent(kind)}${name === void 0 ? "" : `/${encodeURIComponent(name)}`}${rest}`;
|
|
1685
1798
|
}
|
|
1686
1799
|
managedCatalog() {
|
|
1687
|
-
return this.call("GET", "/managed/catalog",
|
|
1800
|
+
return this.call("GET", "/managed/catalog", z6.array(ManagedCatalogEntrySchema));
|
|
1688
1801
|
}
|
|
1689
1802
|
/** One kind's services, or every kind's when `kind` is left out. */
|
|
1690
1803
|
listManaged(kind, opts = {}) {
|
|
1691
|
-
return this.call("GET", `${kind === void 0 ? "/managed" : this.managedPath(kind)}${allQuery(opts)}`,
|
|
1804
|
+
return this.call("GET", `${kind === void 0 ? "/managed" : this.managedPath(kind)}${allQuery(opts)}`, z6.array(ManagedSchema), void 0, opts.org);
|
|
1692
1805
|
}
|
|
1693
1806
|
createManaged(kind, req) {
|
|
1694
1807
|
return this.call("POST", this.managedPath(kind), CreatedManagedSchema, req);
|
|
@@ -1698,7 +1811,7 @@ var ServerClient = class {
|
|
|
1698
1811
|
return this.call("GET", this.managedPath(kind, name), ManagedSchema);
|
|
1699
1812
|
}
|
|
1700
1813
|
deleteManaged(kind, name) {
|
|
1701
|
-
return this.call("DELETE", this.managedPath(kind, name),
|
|
1814
|
+
return this.call("DELETE", this.managedPath(kind, name), z6.undefined());
|
|
1702
1815
|
}
|
|
1703
1816
|
managedPassword(kind, name) {
|
|
1704
1817
|
return this.call("GET", this.managedPath(kind, name, "/password"), ManagedSecretSchema);
|
|
@@ -1729,14 +1842,14 @@ var ServerClient = class {
|
|
|
1729
1842
|
return this.call("POST", "/login", LoginResponseSchema, req);
|
|
1730
1843
|
}
|
|
1731
1844
|
logout() {
|
|
1732
|
-
return this.call("POST", "/logout",
|
|
1845
|
+
return this.call("POST", "/logout", z6.unknown()).then(() => void 0);
|
|
1733
1846
|
}
|
|
1734
1847
|
me() {
|
|
1735
1848
|
return this.call("GET", "/me", MeResponseSchema);
|
|
1736
1849
|
}
|
|
1737
1850
|
// ---- orgs (`kvbox org …`) ----
|
|
1738
1851
|
listOrgs() {
|
|
1739
|
-
return this.call("GET", "/orgs",
|
|
1852
|
+
return this.call("GET", "/orgs", z6.array(OrgMembershipSchema));
|
|
1740
1853
|
}
|
|
1741
1854
|
createOrg(req) {
|
|
1742
1855
|
return this.call("POST", "/orgs", CloudOrgSchema, req);
|
|
@@ -1745,16 +1858,16 @@ var ServerClient = class {
|
|
|
1745
1858
|
return this.call("GET", `/orgs/${encodeURIComponent(slug)}`, OrgDetailSchema);
|
|
1746
1859
|
}
|
|
1747
1860
|
deleteOrg(slug) {
|
|
1748
|
-
return this.call("DELETE", `/orgs/${encodeURIComponent(slug)}`,
|
|
1861
|
+
return this.call("DELETE", `/orgs/${encodeURIComponent(slug)}`, z6.undefined());
|
|
1749
1862
|
}
|
|
1750
1863
|
addMember(slug, req) {
|
|
1751
|
-
return this.call("POST", `/orgs/${encodeURIComponent(slug)}/members`,
|
|
1864
|
+
return this.call("POST", `/orgs/${encodeURIComponent(slug)}/members`, z6.undefined(), req);
|
|
1752
1865
|
}
|
|
1753
1866
|
setRole(slug, username, role) {
|
|
1754
|
-
return this.call("PATCH", `/orgs/${encodeURIComponent(slug)}/members/${encodeURIComponent(username)}`,
|
|
1867
|
+
return this.call("PATCH", `/orgs/${encodeURIComponent(slug)}/members/${encodeURIComponent(username)}`, z6.unknown(), { role }).then(() => void 0);
|
|
1755
1868
|
}
|
|
1756
1869
|
removeMember(slug, username) {
|
|
1757
|
-
return this.call("DELETE", `/orgs/${encodeURIComponent(slug)}/members/${encodeURIComponent(username)}`,
|
|
1870
|
+
return this.call("DELETE", `/orgs/${encodeURIComponent(slug)}/members/${encodeURIComponent(username)}`, z6.undefined());
|
|
1758
1871
|
}
|
|
1759
1872
|
/** Sign this machine's key again (#51); the key must be one the user logged in with. */
|
|
1760
1873
|
sshCert(req) {
|
|
@@ -3952,13 +4065,21 @@ var usageCommand2 = new Command51("usage").description("what your boxes and volu
|
|
|
3952
4065
|
const cloud = client.target.kind === "cloud" ? { me: client.target.user } : void 0;
|
|
3953
4066
|
info(`${day2(report.window.from)} to ${day2(report.window.to)}`);
|
|
3954
4067
|
const volumes = report.volumes ?? [];
|
|
3955
|
-
|
|
4068
|
+
const storage = report.storage ?? [];
|
|
4069
|
+
if (report.boxes.length === 0 && volumes.length === 0 && storage.length === 0) info("no usage in this window");
|
|
3956
4070
|
else if (report.boxes.length > 0) table(perUser ? userRows(perUser) : usageRows(report, cloud));
|
|
3957
4071
|
if (volumes.length > 0) {
|
|
3958
4072
|
info(volumes.length === 1 ? "1 volume" : `${volumes.length} volumes`);
|
|
3959
4073
|
table(volumeRows(report, cloud));
|
|
3960
4074
|
}
|
|
3961
|
-
if (
|
|
4075
|
+
if (storage.length > 0) {
|
|
4076
|
+
info("object storage");
|
|
4077
|
+
table(storageRows(report, cloud));
|
|
4078
|
+
}
|
|
4079
|
+
if ((volumes.length > 0 || storage.length > 0) && report.totals.cost !== void 0) {
|
|
4080
|
+
const what = ["boxes", ...volumes.length > 0 ? ["volumes"] : [], ...storage.length > 0 ? ["object storage"] : []];
|
|
4081
|
+
info(`total: ${money(report.totals.cost.amount, report.totals.cost.currency)} ${color.dim(`(${what.slice(0, -1).join(", ")} and ${what.at(-1)}, estimated)`)}`);
|
|
4082
|
+
}
|
|
3962
4083
|
if (cloud) {
|
|
3963
4084
|
const line = await creditLine(client, cloud.me);
|
|
3964
4085
|
if (line !== void 0) info(line);
|
|
@@ -4037,6 +4158,17 @@ function volumeRows(report, cloud) {
|
|
|
4037
4158
|
});
|
|
4038
4159
|
return rows2;
|
|
4039
4160
|
}
|
|
4161
|
+
function storageRows(report, cloud) {
|
|
4162
|
+
const priced = report.totals.cost !== void 0;
|
|
4163
|
+
const currency = report.totals.cost?.currency ?? "";
|
|
4164
|
+
return (report.storage ?? []).map((s) => ({
|
|
4165
|
+
...cloud ? { owner: ownerCell2(s, cloud.me) } : {},
|
|
4166
|
+
status: s.status === "removed" ? color.dim("removed") : "present",
|
|
4167
|
+
size: `${s.sizeGib}GB`,
|
|
4168
|
+
hours: hours(s.volumeHours),
|
|
4169
|
+
...priced ? { cost: money(s.cost?.amount ?? 0, currency) } : {}
|
|
4170
|
+
}));
|
|
4171
|
+
}
|
|
4040
4172
|
function byUser(report) {
|
|
4041
4173
|
const groups = /* @__PURE__ */ new Map();
|
|
4042
4174
|
for (const b of report.boxes) {
|
|
@@ -4053,7 +4185,7 @@ function byUser(report) {
|
|
|
4053
4185
|
return u;
|
|
4054
4186
|
});
|
|
4055
4187
|
users.sort((a, b) => a.user === null ? 1 : b.user === null ? -1 : a.user.localeCompare(b.user));
|
|
4056
|
-
return { window: report.window, users, ...report.volumes === void 0 ? {} : { volumes: report.volumes }, totals: report.totals };
|
|
4188
|
+
return { window: report.window, users, ...report.volumes === void 0 ? {} : { volumes: report.volumes }, ...report.storage === void 0 ? {} : { storage: report.storage }, totals: report.totals };
|
|
4057
4189
|
}
|
|
4058
4190
|
function userRows(r) {
|
|
4059
4191
|
const priced = r.totals.cost !== void 0;
|
|
@@ -4135,7 +4267,7 @@ import { Command as Command54, InvalidArgumentError as InvalidArgumentError2, Op
|
|
|
4135
4267
|
// src/commands/deploy/config.ts
|
|
4136
4268
|
import { readFile as readFile6, writeFile as writeFile4 } from "fs/promises";
|
|
4137
4269
|
import { isAbsolute, join as join6, normalize, relative as relative2 } from "path";
|
|
4138
|
-
import { z as
|
|
4270
|
+
import { z as z7 } from "zod";
|
|
4139
4271
|
|
|
4140
4272
|
// src/commands/deploy/templates/docker.ts
|
|
4141
4273
|
import { readFile as readFile5 } from "fs/promises";
|
|
@@ -4559,21 +4691,21 @@ function detectTemplates(pkg, dir = NO_FACTS) {
|
|
|
4559
4691
|
var DEPLOY_AUTO_HIBERNATE_SEC = 3600;
|
|
4560
4692
|
var CONFIG_FILE = "kvbox.json";
|
|
4561
4693
|
var BOX_NAME_RE = /^[a-z0-9][a-z0-9-]{0,11}$/;
|
|
4562
|
-
var DeployConfigSchema =
|
|
4563
|
-
template:
|
|
4564
|
-
name:
|
|
4694
|
+
var DeployConfigSchema = z7.object({
|
|
4695
|
+
template: z7.enum(TEMPLATE_IDS),
|
|
4696
|
+
name: z7.string().regex(BOX_NAME_RE, "1-12 chars, lowercase letters, digits and '-', starting with a letter or digit"),
|
|
4565
4697
|
/** The org whose box it is; absent for the user's own. */
|
|
4566
|
-
org:
|
|
4698
|
+
org: z7.string().regex(ORG_SLUG_RE, "not an org slug").optional(),
|
|
4567
4699
|
/** The HTTPS name (`<subdomain>.kvbox.app`); absent when deploying to this machine's own host. */
|
|
4568
|
-
subdomain:
|
|
4700
|
+
subdomain: z7.string().check((ctx) => {
|
|
4569
4701
|
const problem = subdomainProblem(ctx.value);
|
|
4570
4702
|
if (problem) ctx.issues.push({ code: "custom", message: problem, input: ctx.value });
|
|
4571
4703
|
}).optional(),
|
|
4572
|
-
size:
|
|
4704
|
+
size: z7.enum(SIZE_NAMES).optional(),
|
|
4573
4705
|
/** The build output directory, relative to the app; the template's default when absent. */
|
|
4574
|
-
dist:
|
|
4706
|
+
dist: z7.string().optional(),
|
|
4575
4707
|
/** The port a Next.js app or Node server serves; the template's (3000) when absent. */
|
|
4576
|
-
port:
|
|
4708
|
+
port: z7.number().int().min(1).max(65535).optional()
|
|
4577
4709
|
});
|
|
4578
4710
|
var SERVICE_KEY_RE = /^[a-z][a-z0-9-]{0,19}$/;
|
|
4579
4711
|
var RESERVED_SERVICE_KEYS = ["app", "agent", "init", "volumes"];
|
|
@@ -4585,38 +4717,38 @@ var POSTGRES_PORT = 5432;
|
|
|
4585
4717
|
var POSTGRES_IMAGE = "postgres:17";
|
|
4586
4718
|
var POSTGRES_ENV = "DATABASE_URL";
|
|
4587
4719
|
var IMAGE_RE = /^[a-z0-9][a-z0-9._/:@-]*$/;
|
|
4588
|
-
var ServiceSchema =
|
|
4589
|
-
template:
|
|
4720
|
+
var ServiceSchema = z7.strictObject({
|
|
4721
|
+
template: z7.enum([...TEMPLATE_IDS, POSTGRES]),
|
|
4590
4722
|
/** The service's directory, relative to the one holding kvbox.json; every template but postgres has one. */
|
|
4591
|
-
dir:
|
|
4723
|
+
dir: z7.string().min(1).optional(),
|
|
4592
4724
|
/** A postgres service's image, `postgres:17` when absent (`pgvector/pgvector:pg17` for vectors). */
|
|
4593
|
-
image:
|
|
4725
|
+
image: z7.string().regex(IMAGE_RE, "an image name like postgres:17").optional(),
|
|
4594
4726
|
/** The volume (a key of `volumes`) a postgres service keeps its data on. */
|
|
4595
|
-
volume:
|
|
4727
|
+
volume: z7.string().optional(),
|
|
4596
4728
|
/** The box variable a postgres service's URL is written to, `DATABASE_URL` when absent. */
|
|
4597
|
-
env:
|
|
4729
|
+
env: z7.string().optional(),
|
|
4598
4730
|
/** 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`. */
|
|
4599
|
-
context:
|
|
4600
|
-
dist:
|
|
4731
|
+
context: z7.string().min(1).optional(),
|
|
4732
|
+
dist: z7.string().optional(),
|
|
4601
4733
|
/**
|
|
4602
4734
|
* A command run once per deploy in the service's new version (a docker service: in a container of
|
|
4603
4735
|
* the new image; node, nextjs: in the new source, installed and built), with the box's variables,
|
|
4604
4736
|
* before it replaces the running one. Migrations, mostly. A failing one stops that service's deploy.
|
|
4605
4737
|
*/
|
|
4606
|
-
release:
|
|
4738
|
+
release: z7.string().optional(),
|
|
4607
4739
|
/** The box port of a service with its own server; the template's (3000) when absent. */
|
|
4608
|
-
port:
|
|
4740
|
+
port: z7.number().int().min(1).max(65535).optional(),
|
|
4609
4741
|
/** The URL paths that go to this service, each with everything under it; the prefix is kept. */
|
|
4610
|
-
paths:
|
|
4742
|
+
paths: z7.array(z7.string().regex(ROUTE_RE, "a path like / or /api, no trailing slash")).min(1).optional()
|
|
4611
4743
|
});
|
|
4612
|
-
var StackConfigSchema =
|
|
4744
|
+
var StackConfigSchema = z7.strictObject({
|
|
4613
4745
|
name: DeployConfigSchema.shape.name.optional(),
|
|
4614
4746
|
org: DeployConfigSchema.shape.org,
|
|
4615
4747
|
subdomain: DeployConfigSchema.shape.subdomain,
|
|
4616
4748
|
size: DeployConfigSchema.shape.size,
|
|
4617
4749
|
/** The stack's volumes, name to size ("10GB"): made for its box and attached to it on the first deploy that needs one. */
|
|
4618
|
-
volumes:
|
|
4619
|
-
services:
|
|
4750
|
+
volumes: z7.record(z7.string(), z7.string()).optional(),
|
|
4751
|
+
services: z7.record(z7.string(), ServiceSchema)
|
|
4620
4752
|
});
|
|
4621
4753
|
function volumeGib(text2) {
|
|
4622
4754
|
const mib = parseMib(text2);
|
|
@@ -5720,17 +5852,254 @@ var rmCommand7 = new Command60("rm").alias("remove").description("delete a volum
|
|
|
5720
5852
|
var volumeCommand = new Command61("volume").aliases(["volumes", "vol"]).description("disks of their own: create one, attach it to a box at /mnt/<name>, move it to another box later").addCommand(createCommand3).addCommand(lsCommand8).addCommand(attachCommand).addCommand(detachCommand).addCommand(growCommand).addCommand(rmCommand7);
|
|
5721
5853
|
for (const cmd of volumeCommand.commands) cmd.option("--org <slug>", "act in this org (- for your personal volumes)");
|
|
5722
5854
|
|
|
5855
|
+
// src/commands/bucket/index.ts
|
|
5856
|
+
import { Command as Command71 } from "commander";
|
|
5857
|
+
|
|
5858
|
+
// src/commands/bucket/create.ts
|
|
5859
|
+
import { Command as Command62 } from "commander";
|
|
5860
|
+
|
|
5861
|
+
// src/commands/bucket/shared.ts
|
|
5862
|
+
async function bucketClient(cmd) {
|
|
5863
|
+
const client = await clientFor(cmd.optsWithGlobals());
|
|
5864
|
+
if (client.target.kind !== "cloud") {
|
|
5865
|
+
await client.close();
|
|
5866
|
+
throw new KvboxError("object storage runs on the kvbox cloud: kvbox login first (this host's own socket has none)");
|
|
5867
|
+
}
|
|
5868
|
+
return client;
|
|
5869
|
+
}
|
|
5870
|
+
function shownName(b, client) {
|
|
5871
|
+
const context = client.target.kind === "cloud" ? client.target.org ?? client.target.user : void 0;
|
|
5872
|
+
return b.owner === context ? b.name : `${b.owner}/${b.name}`;
|
|
5873
|
+
}
|
|
5874
|
+
var fullness = (s) => s.usedBytes !== void 0 ? `${gb(s.usedBytes)} of ${s.sizeGib} GB used` : `${s.sizeGib} GB`;
|
|
5875
|
+
var nearlyFull = (s) => s.usedBytes !== void 0 && s.totalBytes !== void 0 && s.totalBytes > 0 && s.usedBytes / s.totalBytes >= 0.9;
|
|
5876
|
+
var priceText = (s) => `${money(s.price.perMonth, s.price.currency)} a month ${color.dim("(estimated)")}`;
|
|
5877
|
+
var endpointText = (endpoint) => endpoint ?? color.yellow("no address yet (asked for again at the next bucket create or info)");
|
|
5878
|
+
function printRows(rows2) {
|
|
5879
|
+
const width2 = Math.max(...rows2.map(([label]) => label.length));
|
|
5880
|
+
for (const [label, value] of rows2) process.stdout.write(`${color.dim(label.padEnd(width2))} ${value}
|
|
5881
|
+
`);
|
|
5882
|
+
}
|
|
5883
|
+
|
|
5884
|
+
// src/commands/bucket/create.ts
|
|
5885
|
+
var createCommand4 = new Command62("create").description("make a bucket (the first one also makes your object storage)").argument("<name>", "bucket name: 3-63 lowercase letters, digits and '-'").option("--size <GB>", "how much your object storage may hold, when this is your first bucket (default 10)").option("--near <box>", "put the object storage on the host of this box, when this is your first bucket").option("--json", "print as JSON").action(async (name, opts, cmd) => {
|
|
5886
|
+
const sizeGib = opts.size === void 0 ? void 0 : parseGib2(opts.size);
|
|
5887
|
+
const client = await bucketClient(cmd);
|
|
5888
|
+
try {
|
|
5889
|
+
const made = await spin(`making bucket ${name}\u2026`, client.createBucket({ name, ...sizeGib !== void 0 ? { sizeGib } : {}, ...opts.near !== void 0 ? { near: opts.near } : {} }));
|
|
5890
|
+
if (opts.json) {
|
|
5891
|
+
json(made);
|
|
5892
|
+
return;
|
|
5893
|
+
}
|
|
5894
|
+
const shown = shownName(made, client);
|
|
5895
|
+
info(`${color.green("\u2713")} bucket ${color.bold(shown)} made`);
|
|
5896
|
+
if (made.storageCreated) info(` object storage made for ${made.owner}: ${made.storage.sizeGib} GB for all its buckets, ${priceText(made.storage)}`);
|
|
5897
|
+
info(` endpoint: ${endpointText(made.endpoint)} ${color.dim(`region ${made.region}, path-style`)}`);
|
|
5898
|
+
info(color.dim(` next: kvbox bucket key create ${shown} (an access key for your app)`));
|
|
5899
|
+
} finally {
|
|
5900
|
+
await client.close();
|
|
5901
|
+
}
|
|
5902
|
+
});
|
|
5903
|
+
|
|
5904
|
+
// src/commands/bucket/grow.ts
|
|
5905
|
+
import { Command as Command63 } from "commander";
|
|
5906
|
+
var growCommand2 = new Command63("grow").description("make your object storage larger (all your buckets share it; it restarts once)").argument("<GB>", "the new size in GB, larger than what it has").option("--json", "print the object storage as JSON").action(async (size, opts, cmd) => {
|
|
5907
|
+
const sizeGib = parseGib2(size, "size");
|
|
5908
|
+
const client = await bucketClient(cmd);
|
|
5909
|
+
try {
|
|
5910
|
+
const s = await spin(`growing your object storage to ${sizeGib} GB\u2026`, client.growStorage(sizeGib));
|
|
5911
|
+
if (opts.json) json(s);
|
|
5912
|
+
else info(`${color.green("\u2713")} the object storage of ${s.owner} is ${s.sizeGib} GB, ${priceText(s)}`);
|
|
5913
|
+
} finally {
|
|
5914
|
+
await client.close();
|
|
5915
|
+
}
|
|
5916
|
+
});
|
|
5917
|
+
|
|
5918
|
+
// src/commands/bucket/info.ts
|
|
5919
|
+
import { Command as Command64 } from "commander";
|
|
5920
|
+
var infoCommand = new Command64("info").description("one bucket: its address, what it holds, how full your object storage is").argument("<name>", "bucket name").option("--json", "print as JSON").action(async (name, opts, cmd) => {
|
|
5921
|
+
const client = await bucketClient(cmd);
|
|
5922
|
+
try {
|
|
5923
|
+
const b = await client.getBucket(name);
|
|
5924
|
+
if (opts.json) {
|
|
5925
|
+
json(b);
|
|
5926
|
+
return;
|
|
5927
|
+
}
|
|
5928
|
+
const shown = shownName(b, client);
|
|
5929
|
+
const s = b.storage;
|
|
5930
|
+
const rows2 = [
|
|
5931
|
+
["name", color.bold(shown)],
|
|
5932
|
+
["endpoint", endpointText(b.endpoint)],
|
|
5933
|
+
["region", `${b.region} ${color.dim("(path-style addressing)")}`],
|
|
5934
|
+
["holds", b.objects === void 0 || b.bytes === void 0 ? color.dim(s.status === "running" ? "not answering yet" : `unknown (the storage is ${s.status})`) : `${b.objects} ${b.objects === 1 ? "object" : "objects"}, ${gb(b.bytes)}`],
|
|
5935
|
+
["keys", b.keys === 0 ? color.dim(`none (kvbox bucket key create ${shown})`) : `${b.keys} ${color.dim(`(kvbox bucket key ls ${shown})`)}`],
|
|
5936
|
+
["storage", `${fullness(s)}, ${s.buckets} ${s.buckets === 1 ? "bucket" : "buckets"}${nearlyFull(s) ? color.yellow(" almost full: kvbox bucket grow <GB>") : ""}`],
|
|
5937
|
+
["cost", `${priceText(s)} for the whole storage`],
|
|
5938
|
+
["created", `${age(b.createdAt)}${b.createdBy ? ` by ${b.createdBy}` : ""}`]
|
|
5939
|
+
];
|
|
5940
|
+
printRows(rows2);
|
|
5941
|
+
if (b.endpoint !== null) info(color.dim(`
|
|
5942
|
+
with the AWS CLI: aws s3 ls s3://${b.name} --endpoint-url ${b.endpoint}`));
|
|
5943
|
+
} finally {
|
|
5944
|
+
await client.close();
|
|
5945
|
+
}
|
|
5946
|
+
});
|
|
5947
|
+
|
|
5948
|
+
// src/commands/bucket/key/index.ts
|
|
5949
|
+
import { Command as Command68 } from "commander";
|
|
5950
|
+
|
|
5951
|
+
// src/commands/bucket/key/create.ts
|
|
5952
|
+
import { Command as Command65 } from "commander";
|
|
5953
|
+
var createCommand5 = new Command65("create").description("make an access key for a bucket (the secret is shown once)").argument("<bucket>", "bucket name").option("--name <label>", "what to call the key, to tell it from the others").option("--read-only", "the key reads the bucket but cannot write to it").option("--json", "print as JSON").action(async (bucket, opts, cmd) => {
|
|
5954
|
+
const client = await bucketClient(cmd);
|
|
5955
|
+
try {
|
|
5956
|
+
const key = await client.createBucketKey(bucket, { ...opts.name !== void 0 ? { name: opts.name } : {}, ...opts.readOnly ? { readOnly: true } : {} });
|
|
5957
|
+
if (opts.json) {
|
|
5958
|
+
json(key);
|
|
5959
|
+
return;
|
|
5960
|
+
}
|
|
5961
|
+
info(`${color.green("\u2713")} key ${color.bold(key.name)} ${key.readOnly ? "reads" : "reads and writes"} bucket ${color.bold(key.bucket)}`);
|
|
5962
|
+
printRows([
|
|
5963
|
+
["endpoint", endpointText(key.endpoint)],
|
|
5964
|
+
["region", key.region],
|
|
5965
|
+
["bucket", key.bucket],
|
|
5966
|
+
["access key", key.id],
|
|
5967
|
+
["secret key", key.secret]
|
|
5968
|
+
]);
|
|
5969
|
+
info(color.dim("\nThe secret key is shown only now. Clients must use path-style addressing (AWS SDKs: forcePathStyle)."));
|
|
5970
|
+
} finally {
|
|
5971
|
+
await client.close();
|
|
5972
|
+
}
|
|
5973
|
+
});
|
|
5974
|
+
|
|
5975
|
+
// src/commands/bucket/key/ls.ts
|
|
5976
|
+
import { Command as Command66 } from "commander";
|
|
5977
|
+
var lsCommand9 = new Command66("ls").alias("list").description("list a bucket's access keys (never their secrets)").argument("<bucket>", "bucket name").option("--json", "print as JSON").action(async (bucket, opts, cmd) => {
|
|
5978
|
+
const client = await bucketClient(cmd);
|
|
5979
|
+
try {
|
|
5980
|
+
const keys = await client.listBucketKeys(bucket);
|
|
5981
|
+
if (opts.json) {
|
|
5982
|
+
json(keys);
|
|
5983
|
+
return;
|
|
5984
|
+
}
|
|
5985
|
+
if (keys.length === 0) {
|
|
5986
|
+
info(`bucket ${bucket} has no keys yet; make one with: kvbox bucket key create ${bucket}`);
|
|
5987
|
+
return;
|
|
5988
|
+
}
|
|
5989
|
+
table(keys.map((k) => ({ "access key": k.id, name: k.name, access: k.readOnly ? "read only" : "read and write", "made by": k.createdBy ?? "-", created: age(k.createdAt) })));
|
|
5990
|
+
} finally {
|
|
5991
|
+
await client.close();
|
|
5992
|
+
}
|
|
5993
|
+
});
|
|
5994
|
+
|
|
5995
|
+
// src/commands/bucket/key/rm.ts
|
|
5996
|
+
import { Command as Command67 } from "commander";
|
|
5997
|
+
var rmCommand8 = new Command67("rm").alias("remove").description("delete an access key: whatever uses it stops reaching the bucket").argument("<bucket>", "bucket name").argument("<access-key>", "the access key id (kvbox bucket key ls)").option("-y, --yes", "do not ask for confirmation").action(async (bucket, id, opts, cmd) => {
|
|
5998
|
+
const client = await bucketClient(cmd);
|
|
5999
|
+
try {
|
|
6000
|
+
if (!await confirm(`Delete key ${id} of bucket ${bucket}? Whatever uses it stops working.`, opts.yes ?? false)) {
|
|
6001
|
+
info("cancelled");
|
|
6002
|
+
process.exitCode = 1;
|
|
6003
|
+
return;
|
|
6004
|
+
}
|
|
6005
|
+
await client.deleteBucketKey(bucket, id);
|
|
6006
|
+
info(`${color.green("\u2713")} key ${id} deleted`);
|
|
6007
|
+
} finally {
|
|
6008
|
+
await client.close();
|
|
6009
|
+
}
|
|
6010
|
+
});
|
|
6011
|
+
|
|
6012
|
+
// src/commands/bucket/key/index.ts
|
|
6013
|
+
var keyCommand = new Command68("key").aliases(["keys"]).description("access keys of a bucket: what your app signs in with").addCommand(createCommand5).addCommand(lsCommand9).addCommand(rmCommand8);
|
|
6014
|
+
|
|
6015
|
+
// src/commands/bucket/ls.ts
|
|
6016
|
+
import { Command as Command69 } from "commander";
|
|
6017
|
+
var lsCommand10 = new Command69("ls").alias("list").description("list buckets, and the object storage they are in").option("-a, --all", "every bucket on the platform (platform admins only)").option("--json", "print as JSON").action(async (opts, cmd) => {
|
|
6018
|
+
const client = await bucketClient(cmd);
|
|
6019
|
+
try {
|
|
6020
|
+
const buckets = await client.listBuckets({ all: opts.all });
|
|
6021
|
+
if (opts.json) {
|
|
6022
|
+
json(buckets);
|
|
6023
|
+
return;
|
|
6024
|
+
}
|
|
6025
|
+
if (buckets.length === 0) {
|
|
6026
|
+
info("no buckets yet; make one with: kvbox bucket create <name>");
|
|
6027
|
+
return;
|
|
6028
|
+
}
|
|
6029
|
+
const me2 = client.target.kind === "cloud" ? client.target.user : void 0;
|
|
6030
|
+
table(
|
|
6031
|
+
buckets.map((b) => ({
|
|
6032
|
+
owner: b.owner === me2 ? "private" : b.owner,
|
|
6033
|
+
name: b.name,
|
|
6034
|
+
keys: b.keys,
|
|
6035
|
+
created: age(b.createdAt)
|
|
6036
|
+
}))
|
|
6037
|
+
);
|
|
6038
|
+
for (const s of await client.listStorage({ all: opts.all })) {
|
|
6039
|
+
info(`${color.dim(s.owner === me2 ? "your object storage:" : `object storage of ${s.owner}:`)} ${endpointText(s.endpoint)} ${s.sizeGib} GB ${priceText(s)}`);
|
|
6040
|
+
}
|
|
6041
|
+
} finally {
|
|
6042
|
+
await client.close();
|
|
6043
|
+
}
|
|
6044
|
+
});
|
|
6045
|
+
|
|
6046
|
+
// src/commands/bucket/rm.ts
|
|
6047
|
+
import { Command as Command70 } from "commander";
|
|
6048
|
+
var rmCommand9 = new Command70("rm").alias("remove").description("delete an empty bucket and its keys (the last one takes your object storage with it)").argument("<name>", "bucket name").option("--force", "your last bucket only: delete it with everything in it").option("-y, --yes", "do not ask for confirmation").action(async (name, opts, cmd) => {
|
|
6049
|
+
const client = await bucketClient(cmd);
|
|
6050
|
+
try {
|
|
6051
|
+
const question = opts.force ? `Delete bucket ${name} with everything in it, and the object storage it is in?` : `Delete bucket ${name} and its keys?`;
|
|
6052
|
+
if (!await confirm(question, opts.yes ?? false)) {
|
|
6053
|
+
info("cancelled");
|
|
6054
|
+
process.exitCode = 1;
|
|
6055
|
+
return;
|
|
6056
|
+
}
|
|
6057
|
+
const before = (await client.listStorage()).length;
|
|
6058
|
+
await spin(`deleting bucket ${name}\u2026`, client.deleteBucket(name, opts.force ?? false));
|
|
6059
|
+
const gone = (await client.listStorage()).length < before;
|
|
6060
|
+
info(`${color.green("\u2713")} bucket ${name} deleted${gone ? color.dim(" (it was the last one: the object storage is removed and no longer charged)") : ""}`);
|
|
6061
|
+
} finally {
|
|
6062
|
+
await client.close();
|
|
6063
|
+
}
|
|
6064
|
+
});
|
|
6065
|
+
|
|
6066
|
+
// src/commands/bucket/index.ts
|
|
6067
|
+
var bucketCommand = new Command71("bucket").aliases(["buckets"]).description("object storage: S3 buckets for your files, and the access keys your apps use").addCommand(createCommand4).addCommand(lsCommand10).addCommand(infoCommand).addCommand(growCommand2).addCommand(rmCommand9).addCommand(keyCommand);
|
|
6068
|
+
var withOrg = (cmd) => cmd.option("--org <slug>", "act in this org (- for your personal buckets)");
|
|
6069
|
+
for (const cmd of bucketCommand.commands) {
|
|
6070
|
+
if (cmd === keyCommand) cmd.commands.forEach(withOrg);
|
|
6071
|
+
else withOrg(cmd);
|
|
6072
|
+
}
|
|
6073
|
+
|
|
5723
6074
|
// src/commands/managed/kind.ts
|
|
5724
|
-
import { Command as
|
|
6075
|
+
import { Command as Command84 } from "commander";
|
|
5725
6076
|
|
|
5726
6077
|
// src/commands/managed/create.ts
|
|
5727
|
-
import { Command as
|
|
6078
|
+
import { Command as Command73 } from "commander";
|
|
5728
6079
|
import { setTimeout as sleep3 } from "timers/promises";
|
|
5729
6080
|
|
|
5730
6081
|
// src/commands/managed/shared.ts
|
|
5731
6082
|
import "commander";
|
|
5732
|
-
var POSTGRES2 = {
|
|
5733
|
-
|
|
6083
|
+
var POSTGRES2 = {
|
|
6084
|
+
kind: "postgres",
|
|
6085
|
+
command: "pg",
|
|
6086
|
+
aliases: ["postgres"],
|
|
6087
|
+
title: "PostgreSQL",
|
|
6088
|
+
storageGib: 10,
|
|
6089
|
+
options: [
|
|
6090
|
+
{ name: "database", arg: "name", help: "the database created in it (default: the name)" },
|
|
6091
|
+
{ name: "user", arg: "name", help: "the user that owns it (default: the name)" }
|
|
6092
|
+
]
|
|
6093
|
+
};
|
|
6094
|
+
var REDIS = {
|
|
6095
|
+
kind: "redis",
|
|
6096
|
+
command: "redis",
|
|
6097
|
+
aliases: [],
|
|
6098
|
+
title: "Redis (Valkey)",
|
|
6099
|
+
storageGib: 5,
|
|
6100
|
+
options: []
|
|
6101
|
+
};
|
|
6102
|
+
var KINDS = [POSTGRES2, REDIS];
|
|
5734
6103
|
async function managedClient(cmd) {
|
|
5735
6104
|
const client = await clientFor(cmd.optsWithGlobals());
|
|
5736
6105
|
if (client.target.kind !== "cloud") {
|
|
@@ -5739,9 +6108,9 @@ async function managedClient(cmd) {
|
|
|
5739
6108
|
}
|
|
5740
6109
|
return client;
|
|
5741
6110
|
}
|
|
5742
|
-
var
|
|
6111
|
+
var shownName2 = (m, user) => m.owner === user ? m.name : `${m.owner}/${m.name}`;
|
|
5743
6112
|
var storageText = (m) => m.health?.storageUsedBytes !== void 0 ? `${gb(m.health.storageUsedBytes)} of ${m.storageGib} GB used` : `${m.storageGib} GB`;
|
|
5744
|
-
var
|
|
6113
|
+
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;
|
|
5745
6114
|
function stateText(m) {
|
|
5746
6115
|
if (m.status === "stopped") return `${status(m.status)} ${color.dim("(only its storage is charged)")}`;
|
|
5747
6116
|
if (m.status !== "running" || m.health === void 0) return status(m.status);
|
|
@@ -5750,30 +6119,34 @@ function stateText(m) {
|
|
|
5750
6119
|
return `${status(m.status)}, ${m.health.accepting ? "accepting connections" : color.yellow("not accepting connections")}`;
|
|
5751
6120
|
}
|
|
5752
6121
|
function infoRows(spec, m, user) {
|
|
5753
|
-
const name =
|
|
6122
|
+
const name = shownName2(m, user);
|
|
5754
6123
|
const rows2 = [
|
|
5755
6124
|
["name", color.bold(name)],
|
|
5756
6125
|
["status", stateText(m)],
|
|
5757
6126
|
["version", `${spec.title} ${m.health?.version ?? m.version}`]
|
|
5758
6127
|
];
|
|
5759
6128
|
if (user !== void 0 && m.owner !== user) rows2.push(["owner", m.owner]);
|
|
5760
|
-
|
|
5761
|
-
rows2.push(["storage", `${storageText(m)}${
|
|
5762
|
-
rows2.push(
|
|
6129
|
+
for (const fact of m.health?.facts ?? []) rows2.push([fact.title.toLowerCase(), fact.value]);
|
|
6130
|
+
rows2.push(["storage", `${storageText(m)}${nearlyFull2(m) ? color.yellow(` almost full: kvbox ${spec.command} grow ${name} <GB>`) : ""}`]);
|
|
6131
|
+
rows2.push(...settingRows(spec, m.settings), ["password", color.dim(`kvbox ${spec.command} password ${name}`)]);
|
|
5763
6132
|
rows2.push(["private", `${m.urls.private} ${color.dim(m.links.length > 0 ? `(from ${m.links.join(", ")})` : `(no box is linked: kvbox ${spec.command} link ${name} <box>)`)}`]);
|
|
5764
6133
|
rows2.push(["public", m.urls.public ?? color.dim(`off (kvbox ${spec.command} public ${name} on)`)]);
|
|
5765
6134
|
rows2.push(["cost", `${money(m.price.perMonth, m.price.currency)} a month while it runs, ${money(m.price.storagePerMonth, m.price.currency)} stopped ${color.dim("(estimated)")}`]);
|
|
5766
6135
|
rows2.push(["created", `${age(m.createdAt)}${m.createdBy ? ` by ${m.createdBy}` : ""}`]);
|
|
5767
6136
|
return rows2;
|
|
5768
6137
|
}
|
|
5769
|
-
function
|
|
6138
|
+
function printRows2(rows2) {
|
|
5770
6139
|
const width2 = Math.max(...rows2.map(([label]) => label.length));
|
|
5771
6140
|
for (const [label, value] of rows2) process.stdout.write(`${color.dim(label.padEnd(width2))} ${value}
|
|
5772
6141
|
`);
|
|
5773
6142
|
}
|
|
6143
|
+
function settingRows(spec, settings) {
|
|
6144
|
+
const order = spec.options.map((o) => o.name);
|
|
6145
|
+
const names2 = [...order.filter((name) => settings[name] !== void 0), ...Object.keys(settings).filter((name) => !order.includes(name))];
|
|
6146
|
+
return names2.map((name) => [name, settings[name]]);
|
|
6147
|
+
}
|
|
5774
6148
|
function secretRows(secret) {
|
|
5775
6149
|
return [
|
|
5776
|
-
["user", secret.user],
|
|
5777
6150
|
["password", secret.password],
|
|
5778
6151
|
["private", secret.urls.private],
|
|
5779
6152
|
...secret.urls.public ? [["public", secret.urls.public]] : []
|
|
@@ -5788,47 +6161,50 @@ function parseStorage(text2, flag) {
|
|
|
5788
6161
|
// src/commands/managed/create.ts
|
|
5789
6162
|
var READY_WAIT_MS = 9e4;
|
|
5790
6163
|
var READY_STEP_MS = 2e3;
|
|
5791
|
-
var
|
|
5792
|
-
const
|
|
5793
|
-
|
|
5794
|
-
|
|
5795
|
-
|
|
5796
|
-
|
|
5797
|
-
|
|
5798
|
-
|
|
5799
|
-
|
|
5800
|
-
|
|
5801
|
-
|
|
5802
|
-
|
|
5803
|
-
const
|
|
5804
|
-
|
|
5805
|
-
|
|
5806
|
-
|
|
5807
|
-
|
|
6164
|
+
var createCommand6 = (spec) => {
|
|
6165
|
+
const command = new Command73("create").alias("new").description(`create a ${spec.title} database: a name is all it needs`).argument("<name>", "its name (1-12 chars, lowercase letters, digits and '-'); a linked box reaches it at <name>.<account>.kvbox");
|
|
6166
|
+
for (const o of spec.options) command.option(`--${o.name} <${o.arg}>`, o.help);
|
|
6167
|
+
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) => {
|
|
6168
|
+
const options = Object.fromEntries(spec.options.flatMap((o) => typeof opts[o.name] === "string" ? [[o.name, opts[o.name]]] : []));
|
|
6169
|
+
const req = {
|
|
6170
|
+
name,
|
|
6171
|
+
...Object.keys(options).length > 0 ? { options } : {},
|
|
6172
|
+
...opts.password !== void 0 ? { password: opts.password } : {},
|
|
6173
|
+
...opts.storage !== void 0 ? { storageGib: parseStorage(opts.storage, "--storage") } : {},
|
|
6174
|
+
...opts.near !== void 0 ? { near: opts.near } : {}
|
|
6175
|
+
};
|
|
6176
|
+
const client = await managedClient(cmd);
|
|
6177
|
+
try {
|
|
6178
|
+
const made = await spin(`creating ${spec.title} database ${name}\u2026`, client.createManaged(spec.kind, req));
|
|
6179
|
+
const shown = shownName2(made, me(client));
|
|
6180
|
+
const ready = await spin(`starting ${spec.title}\u2026`, async () => {
|
|
6181
|
+
for (const until = Date.now() + READY_WAIT_MS; Date.now() < until; await sleep3(READY_STEP_MS)) {
|
|
6182
|
+
const now = await client.getManaged(spec.kind, shown).catch(() => void 0);
|
|
6183
|
+
if (now?.health?.ready && now.health.accepting) return true;
|
|
6184
|
+
}
|
|
6185
|
+
return false;
|
|
6186
|
+
});
|
|
6187
|
+
if (opts.json) {
|
|
6188
|
+
json({ ...made, ready });
|
|
6189
|
+
return;
|
|
5808
6190
|
}
|
|
5809
|
-
|
|
5810
|
-
|
|
5811
|
-
|
|
5812
|
-
|
|
5813
|
-
|
|
6191
|
+
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)`)}`);
|
|
6192
|
+
printRows2([...settingRows(spec, made.settings), ...secretRows(made.secret)].map(([label, value]) => [` ${label}`, value]));
|
|
6193
|
+
info("");
|
|
6194
|
+
info("Nobody can reach it yet. To let something in:");
|
|
6195
|
+
info(` a box on the same host kvbox ${spec.command} link ${shown} <box> ${color.dim(`(a new one: kvbox new <box> --near ${shown})`)}`);
|
|
6196
|
+
info(` the internet kvbox ${spec.command} public ${shown} on`);
|
|
6197
|
+
info(color.dim(`It costs about ${money(made.price.perMonth, made.price.currency)} a month while it runs, ${money(made.price.storagePerMonth, made.price.currency)} stopped. The password again: kvbox ${spec.command} password ${shown}`));
|
|
6198
|
+
if (!ready) info(color.dim(`It was not answering after ${READY_WAIT_MS / 1e3} s; see how it is with: kvbox ${spec.command} info ${shown}`));
|
|
6199
|
+
} finally {
|
|
6200
|
+
await client.close();
|
|
5814
6201
|
}
|
|
5815
|
-
|
|
5816
|
-
|
|
5817
|
-
printRows(rows2.map(([label, value]) => [` ${label}`, value]));
|
|
5818
|
-
info("");
|
|
5819
|
-
info("Nobody can reach it yet. To let something in:");
|
|
5820
|
-
info(` a box on the same host kvbox ${spec.command} link ${shown} <box> ${color.dim(`(a new one: kvbox new <box> --near ${shown})`)}`);
|
|
5821
|
-
info(` the internet kvbox ${spec.command} public ${shown} on`);
|
|
5822
|
-
info(color.dim(`It costs about ${money(made.price.perMonth, made.price.currency)} a month while it runs, ${money(made.price.storagePerMonth, made.price.currency)} stopped. The password again: kvbox ${spec.command} password ${shown}`));
|
|
5823
|
-
if (!ready) info(color.dim(`It was not answering after ${READY_WAIT_MS / 1e3} s; see how it is with: kvbox ${spec.command} info ${shown}`));
|
|
5824
|
-
} finally {
|
|
5825
|
-
await client.close();
|
|
5826
|
-
}
|
|
5827
|
-
});
|
|
6202
|
+
});
|
|
6203
|
+
};
|
|
5828
6204
|
|
|
5829
6205
|
// src/commands/managed/grow.ts
|
|
5830
|
-
import { Command as
|
|
5831
|
-
var
|
|
6206
|
+
import { Command as Command74 } from "commander";
|
|
6207
|
+
var growCommand3 = (spec) => new Command74("grow").description("give a database more storage (it restarts once)").argument("<db>", "its name").argument("<GB>", "the new size in GB, larger than what it has").option("--json", "print as JSON").action(async (name, size, opts, cmd) => {
|
|
5832
6208
|
const storageGib = parseStorage(size, "size");
|
|
5833
6209
|
const client = await managedClient(cmd);
|
|
5834
6210
|
try {
|
|
@@ -5841,21 +6217,21 @@ var growCommand2 = (spec) => new Command64("grow").description("give a database
|
|
|
5841
6217
|
});
|
|
5842
6218
|
|
|
5843
6219
|
// src/commands/managed/info.ts
|
|
5844
|
-
import { Command as
|
|
5845
|
-
var
|
|
6220
|
+
import { Command as Command75 } from "commander";
|
|
6221
|
+
var infoCommand2 = (spec) => new Command75("info").alias("get").description("show one database: status, storage used, how to connect").argument("<db>", "its name").option("--json", "print as JSON").action(async (name, opts, cmd) => {
|
|
5846
6222
|
const client = await managedClient(cmd);
|
|
5847
6223
|
try {
|
|
5848
6224
|
const m = await client.getManaged(spec.kind, name);
|
|
5849
6225
|
if (opts.json) json(m);
|
|
5850
|
-
else
|
|
6226
|
+
else printRows2(infoRows(spec, m, me(client)));
|
|
5851
6227
|
} finally {
|
|
5852
6228
|
await client.close();
|
|
5853
6229
|
}
|
|
5854
6230
|
});
|
|
5855
6231
|
|
|
5856
6232
|
// src/commands/managed/link.ts
|
|
5857
|
-
import { Command as
|
|
5858
|
-
var linkCommand2 = (spec) => new
|
|
6233
|
+
import { Command as Command76 } from "commander";
|
|
6234
|
+
var linkCommand2 = (spec) => new Command76("link").description("let a box reach a database privately (same host)").argument("<db>", "the database").argument("<box>", "the box that connects to it").option("--json", "print as JSON").action(async (name, box, opts, cmd) => {
|
|
5859
6235
|
const client = await managedClient(cmd);
|
|
5860
6236
|
try {
|
|
5861
6237
|
const m = await spin(`linking ${box} to ${name}\u2026`, client.linkManaged(spec.kind, name, box));
|
|
@@ -5871,7 +6247,7 @@ var linkCommand2 = (spec) => new Command66("link").description("let a box reach
|
|
|
5871
6247
|
});
|
|
5872
6248
|
|
|
5873
6249
|
// src/commands/managed/ls.ts
|
|
5874
|
-
import { Command as
|
|
6250
|
+
import { Command as Command77 } from "commander";
|
|
5875
6251
|
function listRows(items, user, kindColumn) {
|
|
5876
6252
|
return items.map((m) => ({
|
|
5877
6253
|
owner: m.owner === user ? "private" : m.owner,
|
|
@@ -5885,7 +6261,7 @@ function listRows(items, user, kindColumn) {
|
|
|
5885
6261
|
created: age(m.createdAt)
|
|
5886
6262
|
}));
|
|
5887
6263
|
}
|
|
5888
|
-
var
|
|
6264
|
+
var lsCommand11 = (spec) => new Command77("ls").alias("list").description(spec ? `list your ${spec.title} databases` : "list every managed database, whatever its kind").option("-a, --all", "every one on the platform (platform admins only)").option("--json", "print as JSON").action(async (opts, cmd) => {
|
|
5889
6265
|
const client = await managedClient(cmd);
|
|
5890
6266
|
try {
|
|
5891
6267
|
const items = await client.listManaged(spec?.kind, { all: opts.all });
|
|
@@ -5905,8 +6281,8 @@ var lsCommand9 = (spec) => new Command67("ls").alias("list").description(spec ?
|
|
|
5905
6281
|
});
|
|
5906
6282
|
|
|
5907
6283
|
// src/commands/managed/password.ts
|
|
5908
|
-
import { Command as
|
|
5909
|
-
var passwordCommand = (spec) => new
|
|
6284
|
+
import { Command as Command78 } from "commander";
|
|
6285
|
+
var passwordCommand = (spec) => new Command78("password").description("show a database's password, or set a new one with --reset").argument("<db>", "its name").option("--reset", "make a new password; the old one stops working").option("--json", "print as JSON").action(async (name, opts, cmd) => {
|
|
5910
6286
|
const client = await managedClient(cmd);
|
|
5911
6287
|
try {
|
|
5912
6288
|
const secret = opts.reset ? await spin(`setting a new password on ${name}\u2026`, client.resetManagedPassword(spec.kind, name)) : await client.managedPassword(spec.kind, name);
|
|
@@ -5915,15 +6291,15 @@ var passwordCommand = (spec) => new Command68("password").description("show a da
|
|
|
5915
6291
|
return;
|
|
5916
6292
|
}
|
|
5917
6293
|
if (opts.reset) info(`${color.green("\u2713")} database ${name} has a new password; the old one no longer works`);
|
|
5918
|
-
|
|
6294
|
+
printRows2(secretRows(secret));
|
|
5919
6295
|
} finally {
|
|
5920
6296
|
await client.close();
|
|
5921
6297
|
}
|
|
5922
6298
|
});
|
|
5923
6299
|
|
|
5924
6300
|
// src/commands/managed/public.ts
|
|
5925
|
-
import { Command as
|
|
5926
|
-
var publicCommand = (spec) => new
|
|
6301
|
+
import { Command as Command79 } from "commander";
|
|
6302
|
+
var publicCommand = (spec) => new Command79("public").description("open a database to the internet, or close it again").argument("<db>", "its name").argument("<state>", "on: reachable from anywhere with the password; off: only linked boxes").option("--json", "print as JSON").action(async (name, state, opts, cmd) => {
|
|
5927
6303
|
if (state !== "on" && state !== "off") throw new KvboxError(`write on or off: kvbox ${spec.command} public ${name} on`);
|
|
5928
6304
|
const client = await managedClient(cmd);
|
|
5929
6305
|
try {
|
|
@@ -5944,8 +6320,8 @@ var publicCommand = (spec) => new Command69("public").description("open a databa
|
|
|
5944
6320
|
});
|
|
5945
6321
|
|
|
5946
6322
|
// src/commands/managed/rm.ts
|
|
5947
|
-
import { Command as
|
|
5948
|
-
var
|
|
6323
|
+
import { Command as Command80 } from "commander";
|
|
6324
|
+
var rmCommand10 = (spec) => new Command80("rm").alias("remove").description("delete a database and all its data").argument("<db>", "its name").option("-y, --yes", "do not ask for confirmation").action(async (name, opts, cmd) => {
|
|
5949
6325
|
const client = await managedClient(cmd);
|
|
5950
6326
|
try {
|
|
5951
6327
|
if (!await confirm(`Delete database ${name} and all its data? There is no backup.`, opts.yes ?? false)) {
|
|
@@ -5961,8 +6337,8 @@ var rmCommand8 = (spec) => new Command70("rm").alias("remove").description("dele
|
|
|
5961
6337
|
});
|
|
5962
6338
|
|
|
5963
6339
|
// src/commands/managed/start.ts
|
|
5964
|
-
import { Command as
|
|
5965
|
-
var startCommand2 = (spec) => new
|
|
6340
|
+
import { Command as Command81 } from "commander";
|
|
6341
|
+
var startCommand2 = (spec) => new Command81("start").description("run a stopped database again").argument("<db>", "its name").option("--json", "print as JSON").action(async (name, opts, cmd) => {
|
|
5966
6342
|
const client = await managedClient(cmd);
|
|
5967
6343
|
try {
|
|
5968
6344
|
const m = await spin(`starting ${name}\u2026`, client.startManaged(spec.kind, name));
|
|
@@ -5974,8 +6350,8 @@ var startCommand2 = (spec) => new Command71("start").description("run a stopped
|
|
|
5974
6350
|
});
|
|
5975
6351
|
|
|
5976
6352
|
// src/commands/managed/stop.ts
|
|
5977
|
-
import { Command as
|
|
5978
|
-
var stopCommand2 = (spec) => new
|
|
6353
|
+
import { Command as Command82 } from "commander";
|
|
6354
|
+
var stopCommand2 = (spec) => new Command82("stop").description("shut a database down, keeping its data (only its storage is charged)").argument("<db>", "its name").option("--json", "print as JSON").action(async (name, opts, cmd) => {
|
|
5979
6355
|
const client = await managedClient(cmd);
|
|
5980
6356
|
try {
|
|
5981
6357
|
const m = await spin(`stopping ${name}\u2026`, client.stopManaged(spec.kind, name));
|
|
@@ -5987,8 +6363,8 @@ var stopCommand2 = (spec) => new Command72("stop").description("shut a database
|
|
|
5987
6363
|
});
|
|
5988
6364
|
|
|
5989
6365
|
// src/commands/managed/unlink.ts
|
|
5990
|
-
import { Command as
|
|
5991
|
-
var unlinkCommand2 = (spec) => new
|
|
6366
|
+
import { Command as Command83 } from "commander";
|
|
6367
|
+
var unlinkCommand2 = (spec) => new Command83("unlink").description("stop a box from reaching a database").argument("<db>", "the database").argument("<box>", "the box that was linked to it").option("--json", "print as JSON").action(async (name, box, opts, cmd) => {
|
|
5992
6368
|
const client = await managedClient(cmd);
|
|
5993
6369
|
try {
|
|
5994
6370
|
const m = await spin(`unlinking ${box} from ${name}\u2026`, client.unlinkManaged(spec.kind, name, box));
|
|
@@ -6001,8 +6377,8 @@ var unlinkCommand2 = (spec) => new Command73("unlink").description("stop a box f
|
|
|
6001
6377
|
|
|
6002
6378
|
// src/commands/managed/kind.ts
|
|
6003
6379
|
function kindCommand(spec, description) {
|
|
6004
|
-
const command = new
|
|
6005
|
-
for (const make of [
|
|
6380
|
+
const command = new Command84(spec.command).aliases(spec.aliases).description(description);
|
|
6381
|
+
for (const make of [createCommand6, lsCommand11, infoCommand2, passwordCommand, publicCommand, linkCommand2, unlinkCommand2, growCommand3, stopCommand2, startCommand2, rmCommand10]) {
|
|
6006
6382
|
command.addCommand(make(spec).option("--org <slug>", "act in this org (- for your personal databases)"));
|
|
6007
6383
|
}
|
|
6008
6384
|
return command;
|
|
@@ -6011,15 +6387,18 @@ function kindCommand(spec, description) {
|
|
|
6011
6387
|
// src/commands/pg/index.ts
|
|
6012
6388
|
var pgCommand = kindCommand(POSTGRES2, "managed PostgreSQL: a database kvbox runs for you, private until you link a box or make it public");
|
|
6013
6389
|
|
|
6390
|
+
// src/commands/redis/index.ts
|
|
6391
|
+
var redisCommand = kindCommand(REDIS, "managed Redis (Valkey): a Redis kvbox runs for you, private until you link a box or make it public");
|
|
6392
|
+
|
|
6014
6393
|
// src/commands/managed/index.ts
|
|
6015
|
-
import { Command as
|
|
6016
|
-
var managedCommand = new
|
|
6394
|
+
import { Command as Command85 } from "commander";
|
|
6395
|
+
var managedCommand = new Command85("managed").description(`databases kvbox runs for you, every kind together (${KINDS.map((k) => `${k.title}: kvbox ${k.command}`).join(", ")})`).addCommand(lsCommand11().option("--org <slug>", "act in this org (- for your personal databases)"));
|
|
6017
6396
|
|
|
6018
6397
|
// src/commands/env/index.ts
|
|
6019
|
-
import { Command as
|
|
6398
|
+
import { Command as Command89 } from "commander";
|
|
6020
6399
|
|
|
6021
6400
|
// src/commands/env/ls.ts
|
|
6022
|
-
import { Command as
|
|
6401
|
+
import { Command as Command86 } from "commander";
|
|
6023
6402
|
|
|
6024
6403
|
// src/commands/env/shared.ts
|
|
6025
6404
|
function requireCloud4(client) {
|
|
@@ -6046,7 +6425,7 @@ function firstBootHint(box, name) {
|
|
|
6046
6425
|
}
|
|
6047
6426
|
|
|
6048
6427
|
// src/commands/env/ls.ts
|
|
6049
|
-
var
|
|
6428
|
+
var lsCommand12 = new Command86("ls").alias("list").description("list the variables (a secret shows as (sealed))").option("--box <box>", "what this box gets: its own variables and the ones it inherits").option("--json", "print as JSON").action(async (opts, cmd) => {
|
|
6050
6429
|
const client = await clientFor(cmd.optsWithGlobals(), { autoStart: false });
|
|
6051
6430
|
try {
|
|
6052
6431
|
if (opts.box !== void 0) {
|
|
@@ -6085,8 +6464,8 @@ var lsCommand10 = new Command76("ls").alias("list").description("list the variab
|
|
|
6085
6464
|
});
|
|
6086
6465
|
|
|
6087
6466
|
// src/commands/env/rm.ts
|
|
6088
|
-
import { Command as
|
|
6089
|
-
var
|
|
6467
|
+
import { Command as Command87 } from "commander";
|
|
6468
|
+
var rmCommand11 = new Command87("rm").alias("remove").description("remove variables; boxes lose them when they next start").argument("<names...>", "variable names").option("-y, --yes", "do not ask for confirmation").option("--box <box>", "remove this box's own variables (yours, or the org's, of the same name come back)").option("--json", "print as JSON").action(async (names2, opts, cmd) => {
|
|
6090
6469
|
const client = await clientFor(cmd.optsWithGlobals(), { autoStart: false });
|
|
6091
6470
|
try {
|
|
6092
6471
|
const target = opts.box === void 0 ? void 0 : await findBox2(client, opts.box);
|
|
@@ -6123,8 +6502,8 @@ var rmCommand9 = new Command77("rm").alias("remove").description("remove variabl
|
|
|
6123
6502
|
});
|
|
6124
6503
|
|
|
6125
6504
|
// src/commands/env/set.ts
|
|
6126
|
-
import { Command as
|
|
6127
|
-
var setCommand2 = new
|
|
6505
|
+
import { Command as Command88 } from "commander";
|
|
6506
|
+
var setCommand2 = new Command88("set").description("add or change a variable; boxes get it when they next start").argument("[name]", "variable name, e.g. DATABASE_URL (asked for when left out)").argument("[value]", "its value (asked for when left out; hidden with --secret)").option("--secret", "write-only: the value is never shown again, by any command").option("--box <box>", "this box's own variable, over yours (or the org's) of the same name").option("--json", "print as JSON").action(async (nameArg, valueArg, opts, cmd) => {
|
|
6128
6507
|
const client = await clientFor(cmd.optsWithGlobals(), { autoStart: false });
|
|
6129
6508
|
try {
|
|
6130
6509
|
const owner = opts.box === void 0 ? requireCloud4(client) : void 0;
|
|
@@ -6161,14 +6540,14 @@ var setCommand2 = new Command78("set").description("add or change a variable; bo
|
|
|
6161
6540
|
});
|
|
6162
6541
|
|
|
6163
6542
|
// src/commands/env/index.ts
|
|
6164
|
-
var envCommand = new
|
|
6543
|
+
var envCommand = new Command89("env").description("environment variables every box of yours gets when it starts (secrets too)").addCommand(lsCommand12, { isDefault: true }).addCommand(setCommand2).addCommand(rmCommand11);
|
|
6165
6544
|
for (const cmd of envCommand.commands) cmd.option("--org <slug>", "the org's variables instead of yours");
|
|
6166
6545
|
|
|
6167
6546
|
// src/commands/domain/index.ts
|
|
6168
|
-
import { Command as
|
|
6547
|
+
import { Command as Command93 } from "commander";
|
|
6169
6548
|
|
|
6170
6549
|
// src/commands/domain/add.ts
|
|
6171
|
-
import { Command as
|
|
6550
|
+
import { Command as Command90 } from "commander";
|
|
6172
6551
|
|
|
6173
6552
|
// src/commands/domain/shared.ts
|
|
6174
6553
|
function requireCloud5(client) {
|
|
@@ -6188,7 +6567,7 @@ function hostIn(name, zone) {
|
|
|
6188
6567
|
}
|
|
6189
6568
|
|
|
6190
6569
|
// src/commands/domain/add.ts
|
|
6191
|
-
var addCommand3 = new
|
|
6570
|
+
var addCommand3 = new Command90("add").description("serve a box at a domain of your own, https://<domain>, with its certificate made for you").argument("<domain>", "a domain you control, like example.com or app.example.com").argument("<box>", "box name").option("--port <port>", "the box port the domain serves (default: the port of its kvbox.app address)").option("--json", "print the domain as JSON").action(async (domainArg, name, opts, cmd) => {
|
|
6192
6571
|
const domain = assertDomain(domainArg.trim().toLowerCase());
|
|
6193
6572
|
const port = opts.port === void 0 ? void 0 : parsePorts([opts.port])[0];
|
|
6194
6573
|
const client = await clientFor(cmd.optsWithGlobals());
|
|
@@ -6224,8 +6603,8 @@ kvbox checks every minute; ${domain} is served at ${d.url} once its records are
|
|
|
6224
6603
|
});
|
|
6225
6604
|
|
|
6226
6605
|
// src/commands/domain/ls.ts
|
|
6227
|
-
import { Command as
|
|
6228
|
-
var
|
|
6606
|
+
import { Command as Command91 } from "commander";
|
|
6607
|
+
var lsCommand13 = new Command91("ls").alias("list").description("list your custom domains and whether they are live").option("--json", "print as JSON").action(async (opts, cmd) => {
|
|
6229
6608
|
const client = await clientFor(cmd.optsWithGlobals());
|
|
6230
6609
|
try {
|
|
6231
6610
|
requireCloud5(client);
|
|
@@ -6254,8 +6633,8 @@ var lsCommand11 = new Command81("ls").alias("list").description("list your custo
|
|
|
6254
6633
|
});
|
|
6255
6634
|
|
|
6256
6635
|
// src/commands/domain/rm.ts
|
|
6257
|
-
import { Command as
|
|
6258
|
-
var
|
|
6636
|
+
import { Command as Command92 } from "commander";
|
|
6637
|
+
var rmCommand12 = new Command92("rm").alias("remove").description("stop serving a box at a custom domain").argument("<domain>", "the domain").option("-y, --yes", "do not ask for confirmation").action(async (domainArg, opts, cmd) => {
|
|
6259
6638
|
const domain = domainArg.trim().toLowerCase();
|
|
6260
6639
|
const client = await clientFor(cmd.optsWithGlobals());
|
|
6261
6640
|
try {
|
|
@@ -6276,7 +6655,7 @@ var rmCommand10 = new Command82("rm").alias("remove").description("stop serving
|
|
|
6276
6655
|
});
|
|
6277
6656
|
|
|
6278
6657
|
// src/commands/domain/index.ts
|
|
6279
|
-
var domainCommand = new
|
|
6658
|
+
var domainCommand = new Command93("domain").alias("domains").description("serve a box at a domain of your own").addCommand(addCommand3).addCommand(lsCommand13).addCommand(rmCommand12);
|
|
6280
6659
|
for (const cmd of domainCommand.commands) cmd.option("--org <slug>", "act in this org (- for your personal boxes)");
|
|
6281
6660
|
|
|
6282
6661
|
// src/commands/update.ts
|
|
@@ -6284,7 +6663,7 @@ import { spawn as spawn6 } from "child_process";
|
|
|
6284
6663
|
import { mkdtempSync, rmSync, writeFileSync as writeFileSync2 } from "fs";
|
|
6285
6664
|
import { tmpdir } from "os";
|
|
6286
6665
|
import { join as join9 } from "path";
|
|
6287
|
-
import { Command as
|
|
6666
|
+
import { Command as Command94 } from "commander";
|
|
6288
6667
|
|
|
6289
6668
|
// src/update.ts
|
|
6290
6669
|
import { mkdirSync, readFileSync as readFileSync3, writeFileSync } from "fs";
|
|
@@ -6403,7 +6782,7 @@ function run2(cmd, args) {
|
|
|
6403
6782
|
child.on("exit", (code, signal) => resolve4(code ?? (signal ? 1 : 0)));
|
|
6404
6783
|
});
|
|
6405
6784
|
}
|
|
6406
|
-
var selfUpdateCommand = new
|
|
6785
|
+
var selfUpdateCommand = new Command94("update").description("update kvbox to the latest version (reruns the installer from kvbox.sh, agent skill included)").action(async () => {
|
|
6407
6786
|
suppressUpdateNotice();
|
|
6408
6787
|
const inst = installerFor(process.platform, process.env["KVBOX_INSTALL_URL"] || INSTALL_BASE);
|
|
6409
6788
|
let code;
|
|
@@ -6467,7 +6846,9 @@ var HELP_GROUPS = [
|
|
|
6467
6846
|
["vm", "everything about boxes: fork, rescale, ports, hooks, backups"],
|
|
6468
6847
|
["snapshots", "freeze a running box into a snapshot, start new boxes from it"],
|
|
6469
6848
|
["volume", "disks of their own that move between boxes"],
|
|
6849
|
+
["bucket", "object storage: S3 buckets for your files"],
|
|
6470
6850
|
["pg", "managed PostgreSQL: a database kvbox runs for you"],
|
|
6851
|
+
["redis", "managed Redis (Valkey): a Redis kvbox runs for you"],
|
|
6471
6852
|
["managed", "every managed database, whatever its kind"],
|
|
6472
6853
|
["env", "environment variables and secrets every box of yours gets"],
|
|
6473
6854
|
["domain", "serve a box at a domain of your own"]
|
|
@@ -6526,11 +6907,13 @@ function installRootHelp(program) {
|
|
|
6526
6907
|
|
|
6527
6908
|
// src/program.ts
|
|
6528
6909
|
function buildProgram() {
|
|
6529
|
-
const program = new
|
|
6910
|
+
const program = new Command95("kvbox").description("self-hosted Firecracker microVMs with Docker-like ergonomics").version(VERSION, "-v, --version").option("--local", "use this machine's kvbox-server over its socket, ignoring kvbox login").option("--org <slug>", "the org: where kvbox new creates, and which box a name means when it is not one of yours; before the command here, or after it").showHelpAfterError().enablePositionalOptions();
|
|
6530
6911
|
program.addCommand(vmCommand);
|
|
6531
6912
|
program.addCommand(snapshotsCommand);
|
|
6532
6913
|
program.addCommand(volumeCommand);
|
|
6914
|
+
program.addCommand(bucketCommand);
|
|
6533
6915
|
program.addCommand(pgCommand);
|
|
6916
|
+
program.addCommand(redisCommand);
|
|
6534
6917
|
program.addCommand(managedCommand);
|
|
6535
6918
|
program.addCommand(envCommand);
|
|
6536
6919
|
program.addCommand(domainCommand);
|