@kvbox/cli 0.6.11 → 0.6.13
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 +1541 -1223
- package/dist/kvbox.js.map +1 -1
- package/package.json +1 -1
package/dist/kvbox.js
CHANGED
|
@@ -155,7 +155,7 @@ async function spin(message, work, opts = {}) {
|
|
|
155
155
|
}
|
|
156
156
|
|
|
157
157
|
// src/program.ts
|
|
158
|
-
import { Command as
|
|
158
|
+
import { Command as Command133 } from "commander";
|
|
159
159
|
|
|
160
160
|
// ../shared/src/version.ts
|
|
161
161
|
import { createRequire } from "module";
|
|
@@ -170,7 +170,7 @@ function versionOf(srcFileUrl, injected) {
|
|
|
170
170
|
}
|
|
171
171
|
|
|
172
172
|
// src/version.ts
|
|
173
|
-
var VERSION = versionOf(import.meta.url, true ? "0.6.
|
|
173
|
+
var VERSION = versionOf(import.meta.url, true ? "0.6.13" : void 0);
|
|
174
174
|
|
|
175
175
|
// src/commands/vm/index.ts
|
|
176
176
|
import { Command as Command39 } from "commander";
|
|
@@ -345,10 +345,92 @@ function volumeMountPath(volume2) {
|
|
|
345
345
|
|
|
346
346
|
// src/session.ts
|
|
347
347
|
import { chmod, mkdir, readFile, rm, writeFile } from "fs/promises";
|
|
348
|
-
import { z as
|
|
348
|
+
import { z as z3 } from "zod";
|
|
349
349
|
|
|
350
350
|
// ../shared/src/api.ts
|
|
351
|
+
import { z as z2 } from "zod";
|
|
352
|
+
|
|
353
|
+
// ../shared/src/integrations.ts
|
|
351
354
|
import { z } from "zod";
|
|
355
|
+
var INTEGRATION_IDS = ["github"];
|
|
356
|
+
var IntegrationIdSchema = z.enum(INTEGRATION_IDS);
|
|
357
|
+
var INTEGRATION_KINDS = ["oauth", "app", "api-key", "subscription"];
|
|
358
|
+
var IntegrationKindSchema = z.enum(INTEGRATION_KINDS);
|
|
359
|
+
var INTEGRATION_STATUSES = ["ok", "needs-reconnect"];
|
|
360
|
+
var IntegrationStatusSchema = z.enum(INTEGRATION_STATUSES);
|
|
361
|
+
var INTEGRATIONS_OFF = "off";
|
|
362
|
+
function parseIntegrationList(text2) {
|
|
363
|
+
const names2 = text2.split(",").map((n) => n.trim().toLowerCase()).filter(Boolean);
|
|
364
|
+
if (names2.length === 0 || names2.length === 1 && names2[0] === INTEGRATIONS_OFF) return [];
|
|
365
|
+
const unknown = names2.filter((n) => !INTEGRATION_IDS.includes(n));
|
|
366
|
+
if (unknown.length > 0) {
|
|
367
|
+
const what = unknown[0] === INTEGRATIONS_OFF ? `${INTEGRATIONS_OFF} goes alone, not in a list` : `unknown integration: ${unknown.join(", ")}`;
|
|
368
|
+
throw new KvboxError(`${what} (the integrations are: ${INTEGRATION_IDS.join(", ")}; ${INTEGRATIONS_OFF} for none)`);
|
|
369
|
+
}
|
|
370
|
+
return INTEGRATION_IDS.filter((id) => names2.includes(id));
|
|
371
|
+
}
|
|
372
|
+
var IntegrationListSchema = z.array(z.string().min(1).max(40)).max(20).transform((list) => [...new Set(list)]);
|
|
373
|
+
var IntegrationCatalogEntrySchema = z.object({
|
|
374
|
+
/** A plain string, like `integration` in a listing row: a reader may be older than the control plane. */
|
|
375
|
+
id: z.string(),
|
|
376
|
+
title: z.string(),
|
|
377
|
+
description: z.string(),
|
|
378
|
+
/** How Connect works: `oauth` sends the browser to the provider's consent screen. */
|
|
379
|
+
connect: z.enum(["oauth"]),
|
|
380
|
+
/** What a user's slug and an org's may hold; an empty list: that kind of slug cannot connect it yet. */
|
|
381
|
+
kinds: z.object({ user: z.array(IntegrationKindSchema), org: z.array(IntegrationKindSchema) }),
|
|
382
|
+
/** Whether this control plane is set up for it (a self-hosted one without a GitHub app is not). */
|
|
383
|
+
available: z.boolean(),
|
|
384
|
+
/** Its guide, as a URL. */
|
|
385
|
+
docs: z.string().optional(),
|
|
386
|
+
/** Where it is connected and disconnected: this control plane's web app, when it has one. */
|
|
387
|
+
page: z.string().optional()
|
|
388
|
+
});
|
|
389
|
+
var IntegrationSchema = z.object({
|
|
390
|
+
/** The slug it belongs to: a user's or an org's. */
|
|
391
|
+
owner: z.string(),
|
|
392
|
+
/**
|
|
393
|
+
* Which one (`github`). A plain string, not the ids above: this is an answer, read by every released CLI
|
|
394
|
+
* and SDK, and one from before a new integration must still read the listing that has it.
|
|
395
|
+
*/
|
|
396
|
+
integration: z.string(),
|
|
397
|
+
connected: z.boolean(),
|
|
398
|
+
/** The rest is null while not connected. */
|
|
399
|
+
kind: IntegrationKindSchema.nullable(),
|
|
400
|
+
/** Whose account, as shown: the GitHub login. Never a secret. */
|
|
401
|
+
account: z.string().nullable(),
|
|
402
|
+
status: IntegrationStatusSchema.nullable(),
|
|
403
|
+
connectedBy: z.string().nullable(),
|
|
404
|
+
connectedAt: z.string().nullable(),
|
|
405
|
+
/** The last time a box was handed the credential (to the minute). */
|
|
406
|
+
lastUsedAt: z.string().nullable(),
|
|
407
|
+
/** Whether the caller may connect or disconnect it: the slug's own user, an org's owners. */
|
|
408
|
+
canManage: z.boolean()
|
|
409
|
+
});
|
|
410
|
+
var IntegrationConnectSchema = z.object({ url: z.string() });
|
|
411
|
+
var IntegrationCompleteRequestSchema = z.object({ code: z.string().min(1), state: z.string().min(1) });
|
|
412
|
+
var IntegrationIdentitySchema = z.object({ name: z.string(), email: z.string() });
|
|
413
|
+
var CREDENTIAL_REFUSALS = ["off", "not-connected", "needs-reconnect", "unavailable"];
|
|
414
|
+
var CredentialAnswerSchema = z.discriminatedUnion("ok", [
|
|
415
|
+
z.object({
|
|
416
|
+
ok: z.literal(true),
|
|
417
|
+
kind: IntegrationKindSchema,
|
|
418
|
+
token: z.string(),
|
|
419
|
+
/** When the token ends (ISO), for one that does (a GitHub App's hour). */
|
|
420
|
+
expiresAt: z.string().optional(),
|
|
421
|
+
identity: IntegrationIdentitySchema.optional()
|
|
422
|
+
}),
|
|
423
|
+
z.object({
|
|
424
|
+
ok: z.literal(false),
|
|
425
|
+
code: z.enum(CREDENTIAL_REFUSALS),
|
|
426
|
+
message: z.string(),
|
|
427
|
+
/** With `off`: whether the slug has it connected, so the box can say how to turn it on. */
|
|
428
|
+
connected: z.boolean().optional()
|
|
429
|
+
})
|
|
430
|
+
]);
|
|
431
|
+
var HostCredentialRequestSchema = z.object({ owner: z.string().min(1), box: z.string().min(1), integration: IntegrationIdSchema, probe: z.boolean().optional() });
|
|
432
|
+
var ConnectedAnswerSchema = z.object({ connected: z.boolean(), identity: IntegrationIdentitySchema.optional() });
|
|
433
|
+
var GuestRequestSchema = z.object({ op: z.literal("credential"), integration: IntegrationIdSchema });
|
|
352
434
|
|
|
353
435
|
// ../shared/src/sizes.ts
|
|
354
436
|
var SIZES = {
|
|
@@ -368,1059 +450,1089 @@ function parseMib(text2) {
|
|
|
368
450
|
}
|
|
369
451
|
|
|
370
452
|
// ../shared/src/api.ts
|
|
371
|
-
var SizeSchema =
|
|
453
|
+
var SizeSchema = z2.enum(SIZE_NAMES);
|
|
372
454
|
var BOX_SSH_USER = "kvbox";
|
|
373
|
-
var BoxStatusSchema =
|
|
374
|
-
var PortProtoSchema =
|
|
455
|
+
var BoxStatusSchema = z2.enum(["running", "standby", "hibernated", "stopped", "unknown"]);
|
|
456
|
+
var PortProtoSchema = z2.enum(["tcp", "udp"]);
|
|
375
457
|
var MAX_BOX_PORTS = 16;
|
|
376
|
-
var PortForwardSchema =
|
|
377
|
-
guestPort:
|
|
378
|
-
hostPort:
|
|
458
|
+
var PortForwardSchema = z2.object({
|
|
459
|
+
guestPort: z2.number().int().min(1).max(65535),
|
|
460
|
+
hostPort: z2.number().int(),
|
|
379
461
|
proto: PortProtoSchema,
|
|
380
462
|
/** The host's public address; only the control plane fills it in, as for `ssh`. */
|
|
381
|
-
address:
|
|
463
|
+
address: z2.string().optional(),
|
|
382
464
|
/**
|
|
383
465
|
* Closed but kept (#173): nothing reaches the box through it, and the host port stays the box's, so
|
|
384
466
|
* publishing the same box port again opens the same number. Absent: open while the box runs.
|
|
385
467
|
*/
|
|
386
|
-
closed:
|
|
468
|
+
closed: z2.literal(true).optional()
|
|
387
469
|
});
|
|
388
|
-
var PortsRequest =
|
|
389
|
-
ports:
|
|
470
|
+
var PortsRequest = z2.object({
|
|
471
|
+
ports: z2.array(z2.object({ guestPort: z2.number().int().min(1).max(65535), proto: PortProtoSchema.optional() })).min(1).max(MAX_BOX_PORTS),
|
|
390
472
|
/** `DELETE` only (#173): close the ports but keep their host ports for the box (`closed`). */
|
|
391
|
-
keep:
|
|
392
|
-
});
|
|
393
|
-
var BoxPortSchema =
|
|
394
|
-
var BoxLinkSchema =
|
|
395
|
-
var LinkRequest =
|
|
396
|
-
var ClaimSubdomainRequest =
|
|
397
|
-
var SubdomainPortRequest =
|
|
398
|
-
var SubdomainRouteRequest =
|
|
399
|
-
var SubdomainSchema =
|
|
400
|
-
owner:
|
|
401
|
-
box:
|
|
402
|
-
subdomain:
|
|
473
|
+
keep: z2.boolean().optional()
|
|
474
|
+
});
|
|
475
|
+
var BoxPortSchema = z2.number().int().min(1).max(65535);
|
|
476
|
+
var BoxLinkSchema = z2.object({ from: z2.string(), port: BoxPortSchema });
|
|
477
|
+
var LinkRequest = z2.object({ from: z2.string().min(1), fromOwner: z2.string().optional(), port: BoxPortSchema });
|
|
478
|
+
var ClaimSubdomainRequest = z2.object({ name: z2.string(), port: BoxPortSchema });
|
|
479
|
+
var SubdomainPortRequest = z2.object({ port: BoxPortSchema });
|
|
480
|
+
var SubdomainRouteRequest = z2.object({ name: z2.string(), port: BoxPortSchema });
|
|
481
|
+
var SubdomainSchema = z2.object({
|
|
482
|
+
owner: z2.string(),
|
|
483
|
+
box: z2.string(),
|
|
484
|
+
subdomain: z2.string(),
|
|
403
485
|
port: BoxPortSchema,
|
|
404
|
-
url:
|
|
405
|
-
routes:
|
|
486
|
+
url: z2.string(),
|
|
487
|
+
routes: z2.array(z2.object({ name: z2.string(), port: BoxPortSchema, url: z2.string() }))
|
|
406
488
|
});
|
|
407
|
-
var AddDomainRequest =
|
|
408
|
-
var DomainSchema =
|
|
409
|
-
owner:
|
|
410
|
-
box:
|
|
411
|
-
domain:
|
|
489
|
+
var AddDomainRequest = z2.object({ domain: z2.string(), port: BoxPortSchema.optional() });
|
|
490
|
+
var DomainSchema = z2.object({
|
|
491
|
+
owner: z2.string(),
|
|
492
|
+
box: z2.string(),
|
|
493
|
+
domain: z2.string(),
|
|
412
494
|
port: BoxPortSchema,
|
|
413
|
-
status:
|
|
414
|
-
www:
|
|
415
|
-
url:
|
|
416
|
-
error:
|
|
417
|
-
records:
|
|
418
|
-
createdAt:
|
|
419
|
-
});
|
|
420
|
-
var WakeHookSchema =
|
|
421
|
-
id:
|
|
422
|
-
owner:
|
|
423
|
-
box:
|
|
424
|
-
url:
|
|
425
|
-
createdBy:
|
|
426
|
-
createdAt:
|
|
427
|
-
lastCalledAt:
|
|
428
|
-
});
|
|
429
|
-
var CreatedWakeHookSchema = WakeHookSchema.extend({ secret:
|
|
430
|
-
var WakeHookCallSchema =
|
|
431
|
-
box:
|
|
432
|
-
action:
|
|
433
|
-
reason:
|
|
495
|
+
status: z2.enum(["pending", "live"]),
|
|
496
|
+
www: z2.boolean(),
|
|
497
|
+
url: z2.string(),
|
|
498
|
+
error: z2.string().nullable(),
|
|
499
|
+
records: z2.array(z2.object({ type: z2.enum(["A", "TXT", "CNAME"]), name: z2.string(), value: z2.string() })),
|
|
500
|
+
createdAt: z2.string()
|
|
501
|
+
});
|
|
502
|
+
var WakeHookSchema = z2.object({
|
|
503
|
+
id: z2.string(),
|
|
504
|
+
owner: z2.string(),
|
|
505
|
+
box: z2.string(),
|
|
506
|
+
url: z2.string(),
|
|
507
|
+
createdBy: z2.string().nullable(),
|
|
508
|
+
createdAt: z2.string(),
|
|
509
|
+
lastCalledAt: z2.string().nullable()
|
|
510
|
+
});
|
|
511
|
+
var CreatedWakeHookSchema = WakeHookSchema.extend({ secret: z2.string() });
|
|
512
|
+
var WakeHookCallSchema = z2.object({
|
|
513
|
+
box: z2.string(),
|
|
514
|
+
action: z2.enum(["wake", "resume", "none"]),
|
|
515
|
+
reason: z2.string().optional()
|
|
434
516
|
});
|
|
435
517
|
var BACKUP_STATUSES = ["running", "ready", "failed"];
|
|
436
518
|
var BACKUP_KINDS = ["box", "volume"];
|
|
437
|
-
var BackupSchema =
|
|
438
|
-
id:
|
|
439
|
-
owner:
|
|
440
|
-
box:
|
|
441
|
-
|
|
519
|
+
var BackupSchema = z2.object({
|
|
520
|
+
id: z2.string(),
|
|
521
|
+
owner: z2.string(),
|
|
522
|
+
box: z2.string(),
|
|
523
|
+
/**
|
|
524
|
+
* The box it was taken of has been removed (#141): a box called `box` now is another box, which this backup
|
|
525
|
+
* never restores into; `kvbox new <name> --from-backup <id>` makes a box from it. Absent from a control plane
|
|
526
|
+
* before #141.
|
|
527
|
+
*/
|
|
528
|
+
boxRemoved: z2.boolean().optional(),
|
|
529
|
+
status: z2.enum(BACKUP_STATUSES),
|
|
442
530
|
/** Why it failed; null otherwise. */
|
|
443
|
-
error:
|
|
531
|
+
error: z2.string().nullable(),
|
|
444
532
|
/** The image version the disk stacks on (a restore needs it on the host), and the image (absent: base). */
|
|
445
|
-
base:
|
|
446
|
-
image:
|
|
447
|
-
vcpu:
|
|
448
|
-
memMib:
|
|
533
|
+
base: z2.string().nullable(),
|
|
534
|
+
image: z2.string().optional(),
|
|
535
|
+
vcpu: z2.number().int().nullable(),
|
|
536
|
+
memMib: z2.number().int().nullable(),
|
|
449
537
|
/** The disk's size. */
|
|
450
|
-
diskBytes:
|
|
538
|
+
diskBytes: z2.number().int().nullable(),
|
|
451
539
|
/** What it holds: the slots that are not all zeros. */
|
|
452
|
-
dataBytes:
|
|
540
|
+
dataBytes: z2.number().int().nullable(),
|
|
453
541
|
/** What this backup added to storage (encrypted, compressed): the chunks no earlier backup had. */
|
|
454
|
-
uploadedBytes:
|
|
455
|
-
createdBy:
|
|
456
|
-
createdAt:
|
|
457
|
-
finishedAt:
|
|
458
|
-
});
|
|
459
|
-
var BackupLimitSchema =
|
|
460
|
-
perDay:
|
|
461
|
-
used:
|
|
462
|
-
nextAt:
|
|
463
|
-
});
|
|
464
|
-
var NamedBackupLimitSchema = BackupLimitSchema.extend({ owner:
|
|
465
|
-
var HostBackupRequest =
|
|
466
|
-
var HostBackupManifestSchema =
|
|
467
|
-
id:
|
|
468
|
-
sizeBytes:
|
|
469
|
-
chunks:
|
|
470
|
-
env:
|
|
471
|
-
base:
|
|
472
|
-
image:
|
|
473
|
-
vcpu:
|
|
474
|
-
memMib:
|
|
475
|
-
|
|
476
|
-
|
|
477
|
-
|
|
478
|
-
var
|
|
542
|
+
uploadedBytes: z2.number().int().nullable(),
|
|
543
|
+
createdBy: z2.string().nullable(),
|
|
544
|
+
createdAt: z2.string(),
|
|
545
|
+
finishedAt: z2.string().nullable()
|
|
546
|
+
});
|
|
547
|
+
var BackupLimitSchema = z2.object({
|
|
548
|
+
perDay: z2.number().int(),
|
|
549
|
+
used: z2.number().int(),
|
|
550
|
+
nextAt: z2.string().nullable()
|
|
551
|
+
});
|
|
552
|
+
var NamedBackupLimitSchema = BackupLimitSchema.extend({ owner: z2.string(), name: z2.string() });
|
|
553
|
+
var HostBackupRequest = z2.object({ id: z2.string(), key: z2.string() });
|
|
554
|
+
var HostBackupManifestSchema = z2.object({
|
|
555
|
+
id: z2.string(),
|
|
556
|
+
sizeBytes: z2.number().int(),
|
|
557
|
+
chunks: z2.array(z2.string().nullable()),
|
|
558
|
+
env: z2.string().nullable(),
|
|
559
|
+
base: z2.string(),
|
|
560
|
+
image: z2.string().optional(),
|
|
561
|
+
vcpu: z2.number().int(),
|
|
562
|
+
memMib: z2.number().int(),
|
|
563
|
+
/** The box's integrations (#205), so a box made from the backup has them again. Absent: none, or an older host. */
|
|
564
|
+
integrations: z2.array(z2.string()).optional()
|
|
565
|
+
});
|
|
566
|
+
var HostUploadRequest = z2.object({ key: z2.string(), urls: z2.record(z2.string(), z2.string()), pin: z2.string().optional() });
|
|
567
|
+
var HostUploadResultSchema = z2.object({ chunks: z2.number().int(), bytes: z2.number().int(), sizes: z2.record(z2.string(), z2.number().int()) });
|
|
568
|
+
var HostRestoreRequest = z2.object({
|
|
479
569
|
/** The backup's id: its variables were sealed under it. */
|
|
480
|
-
id:
|
|
481
|
-
key:
|
|
482
|
-
sizeBytes:
|
|
483
|
-
base:
|
|
484
|
-
image:
|
|
485
|
-
env:
|
|
486
|
-
chunks:
|
|
570
|
+
id: z2.string(),
|
|
571
|
+
key: z2.string(),
|
|
572
|
+
sizeBytes: z2.number().int().positive(),
|
|
573
|
+
base: z2.string(),
|
|
574
|
+
image: z2.string().optional(),
|
|
575
|
+
env: z2.string().nullable(),
|
|
576
|
+
chunks: z2.array(z2.object({ index: z2.number().int().nonnegative(), hash: z2.string(), url: z2.string() })),
|
|
487
577
|
/** The certificate fingerprint of the store the URLs point at (see HostUploadRequest). */
|
|
488
|
-
pin:
|
|
578
|
+
pin: z2.string().optional()
|
|
489
579
|
});
|
|
490
|
-
var VolumeBackupSchema =
|
|
491
|
-
id:
|
|
492
|
-
owner:
|
|
493
|
-
volume:
|
|
494
|
-
status:
|
|
580
|
+
var VolumeBackupSchema = z2.object({
|
|
581
|
+
id: z2.string(),
|
|
582
|
+
owner: z2.string(),
|
|
583
|
+
volume: z2.string(),
|
|
584
|
+
status: z2.enum(BACKUP_STATUSES),
|
|
495
585
|
/** Why it failed; null otherwise. */
|
|
496
|
-
error:
|
|
586
|
+
error: z2.string().nullable(),
|
|
497
587
|
/** The volume's size when taken. */
|
|
498
|
-
diskBytes:
|
|
588
|
+
diskBytes: z2.number().int().nullable(),
|
|
499
589
|
/** What it holds: the slots that are not all zeros. */
|
|
500
|
-
dataBytes:
|
|
590
|
+
dataBytes: z2.number().int().nullable(),
|
|
501
591
|
/** What this backup added to storage (encrypted, compressed): the chunks no earlier backup had. */
|
|
502
|
-
uploadedBytes:
|
|
503
|
-
createdBy:
|
|
504
|
-
createdAt:
|
|
505
|
-
finishedAt:
|
|
592
|
+
uploadedBytes: z2.number().int().nullable(),
|
|
593
|
+
createdBy: z2.string().nullable(),
|
|
594
|
+
createdAt: z2.string(),
|
|
595
|
+
finishedAt: z2.string().nullable()
|
|
506
596
|
});
|
|
507
|
-
var BackupScheduleSchema =
|
|
508
|
-
enabled:
|
|
597
|
+
var BackupScheduleSchema = z2.object({
|
|
598
|
+
enabled: z2.boolean(),
|
|
509
599
|
/** 0-23, UTC. Kept while it is off, so turning it on again keeps the hour. */
|
|
510
|
-
hour:
|
|
511
|
-
nextAt:
|
|
512
|
-
lastAt:
|
|
513
|
-
lastBackup:
|
|
514
|
-
lastError:
|
|
515
|
-
});
|
|
516
|
-
var SetBackupScheduleRequest =
|
|
517
|
-
var HostVolumeBackupManifestSchema =
|
|
518
|
-
var HostVolumeRestoreRequest =
|
|
519
|
-
id:
|
|
520
|
-
key:
|
|
521
|
-
sizeBytes:
|
|
522
|
-
chunks:
|
|
523
|
-
pin:
|
|
524
|
-
});
|
|
525
|
-
var BackupStoreSetupRequest =
|
|
526
|
-
var BackupStoreStatusSchema =
|
|
527
|
-
path:
|
|
528
|
-
bucket:
|
|
529
|
-
accessKey:
|
|
600
|
+
hour: z2.number().int().min(0).max(23),
|
|
601
|
+
nextAt: z2.string().nullable(),
|
|
602
|
+
lastAt: z2.string().nullable(),
|
|
603
|
+
lastBackup: z2.string().nullable(),
|
|
604
|
+
lastError: z2.string().nullable()
|
|
605
|
+
});
|
|
606
|
+
var SetBackupScheduleRequest = z2.object({ enabled: z2.boolean().optional(), hour: z2.number().int().min(0).max(23).optional() });
|
|
607
|
+
var HostVolumeBackupManifestSchema = z2.object({ id: z2.string(), sizeBytes: z2.number().int(), chunks: z2.array(z2.string().nullable()) });
|
|
608
|
+
var HostVolumeRestoreRequest = z2.object({
|
|
609
|
+
id: z2.string(),
|
|
610
|
+
key: z2.string(),
|
|
611
|
+
sizeBytes: z2.number().int().positive(),
|
|
612
|
+
chunks: z2.array(z2.object({ index: z2.number().int().nonnegative(), hash: z2.string(), url: z2.string() })),
|
|
613
|
+
pin: z2.string().optional()
|
|
614
|
+
});
|
|
615
|
+
var BackupStoreSetupRequest = z2.object({ path: z2.string().min(1), force: z2.boolean().optional(), newStore: z2.boolean().optional() });
|
|
616
|
+
var BackupStoreStatusSchema = z2.object({
|
|
617
|
+
path: z2.string(),
|
|
618
|
+
bucket: z2.string(),
|
|
619
|
+
accessKey: z2.string(),
|
|
530
620
|
/** Whether Garage is running and can store. */
|
|
531
|
-
running:
|
|
621
|
+
running: z2.boolean(),
|
|
532
622
|
/** The filesystem the path is on. */
|
|
533
|
-
totalBytes:
|
|
534
|
-
freeBytes:
|
|
623
|
+
totalBytes: z2.number().int(),
|
|
624
|
+
freeBytes: z2.number().int(),
|
|
535
625
|
/** What the bucket holds, when Garage answers. */
|
|
536
|
-
objects:
|
|
537
|
-
storedBytes:
|
|
626
|
+
objects: z2.number().int().optional(),
|
|
627
|
+
storedBytes: z2.number().int().optional(),
|
|
538
628
|
/** Whether the control plane took the store's registration at setup. */
|
|
539
|
-
registered:
|
|
629
|
+
registered: z2.boolean().optional()
|
|
540
630
|
});
|
|
541
|
-
var BackupStoreRegistration =
|
|
542
|
-
var CloudBackupStoreSchema =
|
|
543
|
-
id:
|
|
631
|
+
var BackupStoreRegistration = z2.object({ bucket: z2.string().min(1), region: z2.string().min(1), accessKey: z2.string().min(1), secretKey: z2.string().min(1) });
|
|
632
|
+
var CloudBackupStoreSchema = z2.object({
|
|
633
|
+
id: z2.string(),
|
|
544
634
|
/** Null while no host serves it (its host left; it comes back when a host registers its key and secret again). */
|
|
545
|
-
host:
|
|
546
|
-
endpoint:
|
|
547
|
-
bucket:
|
|
548
|
-
accessKey:
|
|
549
|
-
createdAt:
|
|
635
|
+
host: z2.string().nullable(),
|
|
636
|
+
endpoint: z2.string().nullable(),
|
|
637
|
+
bucket: z2.string(),
|
|
638
|
+
accessKey: z2.string(),
|
|
639
|
+
createdAt: z2.string(),
|
|
550
640
|
/** The host answered a poll in the last minute and its Garage runs. */
|
|
551
|
-
live:
|
|
641
|
+
live: z2.boolean(),
|
|
552
642
|
/** From the host's last poll; null when it never reported a store. */
|
|
553
|
-
totalBytes:
|
|
554
|
-
freeBytes:
|
|
643
|
+
totalBytes: z2.number().int().nullable(),
|
|
644
|
+
freeBytes: z2.number().int().nullable(),
|
|
555
645
|
/** Ready backups kept here, and what their chunks take (encrypted, compressed). */
|
|
556
|
-
backups:
|
|
557
|
-
storedBytes:
|
|
646
|
+
backups: z2.number().int(),
|
|
647
|
+
storedBytes: z2.number().int(),
|
|
558
648
|
/** How many boxes have a ready backup here (a box and an earlier one of the same name count once), how many volumes (#168) and managed databases (#186). */
|
|
559
|
-
boxes:
|
|
560
|
-
volumes:
|
|
561
|
-
databases:
|
|
649
|
+
boxes: z2.number().int(),
|
|
650
|
+
volumes: z2.number().int(),
|
|
651
|
+
databases: z2.number().int(),
|
|
562
652
|
/** When the newest ready backup kept here finished; null when it keeps none. */
|
|
563
|
-
lastBackupAt:
|
|
653
|
+
lastBackupAt: z2.string().nullable()
|
|
564
654
|
});
|
|
565
|
-
var StoredItemSchema =
|
|
566
|
-
kind:
|
|
567
|
-
owner:
|
|
655
|
+
var StoredItemSchema = z2.object({
|
|
656
|
+
kind: z2.enum(BACKUP_KINDS),
|
|
657
|
+
owner: z2.string(),
|
|
568
658
|
/** The box's or volume's name; a managed database's (#186) for its hidden volume. */
|
|
569
|
-
name:
|
|
659
|
+
name: z2.string(),
|
|
570
660
|
/** The managed database's kind (`postgres`) when the volume is one's (#186); null otherwise. */
|
|
571
|
-
managed:
|
|
661
|
+
managed: z2.string().nullable(),
|
|
572
662
|
/** The host the box (or volume) is on now; null when it is gone (its backups stay). */
|
|
573
|
-
host:
|
|
663
|
+
host: z2.string().nullable(),
|
|
574
664
|
/** It is on the store's own host: losing that host loses it and its backups together. */
|
|
575
|
-
sameHost:
|
|
665
|
+
sameHost: z2.boolean(),
|
|
576
666
|
/** Ready backups kept here, and what they added to the store together (encrypted, compressed). */
|
|
577
|
-
backups:
|
|
578
|
-
uploadedBytes:
|
|
667
|
+
backups: z2.number().int(),
|
|
668
|
+
uploadedBytes: z2.number().int(),
|
|
579
669
|
/** The newest backup sent here, whatever became of it. */
|
|
580
|
-
latest:
|
|
670
|
+
latest: z2.object({ id: z2.string(), status: z2.enum(BACKUP_STATUSES), error: z2.string().nullable(), createdAt: z2.string() })
|
|
581
671
|
});
|
|
582
|
-
var FailedBackupSchema =
|
|
583
|
-
id:
|
|
584
|
-
owner:
|
|
672
|
+
var FailedBackupSchema = z2.object({
|
|
673
|
+
id: z2.string(),
|
|
674
|
+
owner: z2.string(),
|
|
585
675
|
/** What it was a backup of: a box or a volume (#168), and its name; a managed database's (#186) for its hidden volume. */
|
|
586
|
-
kind:
|
|
587
|
-
name:
|
|
676
|
+
kind: z2.enum(BACKUP_KINDS),
|
|
677
|
+
name: z2.string(),
|
|
588
678
|
/** The managed database's kind (`postgres`) when the volume is one's; null otherwise. */
|
|
589
|
-
managed:
|
|
590
|
-
error:
|
|
679
|
+
managed: z2.string().nullable(),
|
|
680
|
+
error: z2.string().nullable(),
|
|
591
681
|
/** The host that took it, and the host of the store it was going to; null when gone, or when it failed before a store was picked. */
|
|
592
|
-
host:
|
|
593
|
-
store:
|
|
594
|
-
createdAt:
|
|
682
|
+
host: z2.string().nullable(),
|
|
683
|
+
store: z2.string().nullable(),
|
|
684
|
+
createdAt: z2.string()
|
|
595
685
|
});
|
|
596
|
-
var MachineSchema =
|
|
686
|
+
var MachineSchema = z2.object({
|
|
597
687
|
/** Host-unique short id (the tap is `kv-<id>`). Missing only on a box made before ids that has not restarted since. */
|
|
598
|
-
id:
|
|
599
|
-
name:
|
|
688
|
+
id: z2.string(),
|
|
689
|
+
name: z2.string(),
|
|
600
690
|
/** Who the box belongs to; names are unique per owner. A bare name is local to the host, `user@control-plane` later. */
|
|
601
|
-
owner:
|
|
602
|
-
ip:
|
|
603
|
-
mac:
|
|
604
|
-
pid:
|
|
605
|
-
vcpu:
|
|
606
|
-
memMib:
|
|
607
|
-
diskBytes:
|
|
691
|
+
owner: z2.string(),
|
|
692
|
+
ip: z2.string(),
|
|
693
|
+
mac: z2.string(),
|
|
694
|
+
pid: z2.number().int().nullable(),
|
|
695
|
+
vcpu: z2.number().int(),
|
|
696
|
+
memMib: z2.number().int(),
|
|
697
|
+
diskBytes: z2.number().int(),
|
|
608
698
|
// the box's own writable disk, as the guest sees it
|
|
609
|
-
diskUsedBytes:
|
|
699
|
+
diskUsedBytes: z2.number().int(),
|
|
610
700
|
// what the box uses of it: the filesystem's own count, like the guest's `df` (#115)
|
|
611
701
|
/** What the disk's sparse file occupies on the host. Grows while the box runs, `kvbox stop` trims it back. Hosts before 0.5.42 do not send it. */
|
|
612
|
-
diskHostBytes:
|
|
613
|
-
base:
|
|
702
|
+
diskHostBytes: z2.number().int().optional(),
|
|
703
|
+
base: z2.string(),
|
|
614
704
|
// version of the image the box's overlay stacks on
|
|
615
705
|
/** The image (#87) when it is not the base one: `postgres`. `base` is then that image's version. */
|
|
616
|
-
image:
|
|
617
|
-
createdAt:
|
|
618
|
-
source:
|
|
619
|
-
// "base", "snapshot:<owner/name>"
|
|
706
|
+
image: z2.string().optional(),
|
|
707
|
+
createdAt: z2.string(),
|
|
708
|
+
source: z2.string(),
|
|
709
|
+
// "base", "snapshot:<owner/name>", "fork:<owner/name>" (#79) or "backup:<id>" (#141)
|
|
620
710
|
status: BoxStatusSchema,
|
|
621
711
|
/**
|
|
622
712
|
* Public TCP port on the host that reaches the box's SSH while it runs (#49). Only boxes made
|
|
623
713
|
* through a control plane have one; the control plane adds the host's address for `connect` (#21).
|
|
624
714
|
*/
|
|
625
|
-
sshPort:
|
|
715
|
+
sshPort: z2.number().int().optional(),
|
|
626
716
|
/**
|
|
627
717
|
* Where `ssh` reaches the box from outside: the host's public address and that port (#21). Only
|
|
628
718
|
* the control plane fills it in (a host does not know its own public address); absent for a box
|
|
629
719
|
* whose host reported no port or did not answer.
|
|
630
720
|
*/
|
|
631
|
-
ssh:
|
|
721
|
+
ssh: z2.object({ host: z2.string(), port: z2.number().int(), user: z2.string() }).optional(),
|
|
632
722
|
/** Box ports published on the host (#30). Absent: none. */
|
|
633
|
-
ports:
|
|
723
|
+
ports: z2.array(PortForwardSchema).optional(),
|
|
634
724
|
/** Whether the owner slug is a user or an org. Only the control plane knows; it fills it in on `GET /machines`. */
|
|
635
|
-
ownerKind:
|
|
725
|
+
ownerKind: z2.enum(["user", "org"]).optional(),
|
|
636
726
|
/**
|
|
637
727
|
* The name of the host the box runs on. Only the control plane fills it in, on `GET /machines`: a box
|
|
638
728
|
* links to, and a volume attaches to, only a box on the same host.
|
|
639
729
|
*/
|
|
640
|
-
host:
|
|
730
|
+
host: z2.string().optional(),
|
|
641
731
|
/** The country code of that host (`RO`, `US`), when its admin gave one. Only the control plane fills it in. */
|
|
642
|
-
country:
|
|
732
|
+
country: z2.string().optional(),
|
|
643
733
|
/**
|
|
644
734
|
* The kind of managed service the box runs (`postgres`, `redis`, `storage`). Only an admin's
|
|
645
735
|
* `GET /machines?all=1` lists such boxes, so a host's boxes add up; every other listing hides them.
|
|
646
736
|
*/
|
|
647
|
-
managed:
|
|
737
|
+
managed: z2.string().optional(),
|
|
648
738
|
/** Seconds without network traffic before the host hibernates the box (#47). Absent: never. */
|
|
649
|
-
autoHibernateSec:
|
|
739
|
+
autoHibernateSec: z2.number().int().positive().optional(),
|
|
650
740
|
/** A script inside the box that says it is idle (#102, exit 0): auto-hibernate asks it instead of watching the traffic. */
|
|
651
|
-
idleCheck:
|
|
741
|
+
idleCheck: z2.string().optional(),
|
|
652
742
|
/** Volumes attached to the box (#52), in drive order; each is mounted at `mountPath` while the box runs. Absent: none. */
|
|
653
|
-
volumes:
|
|
743
|
+
volumes: z2.array(z2.object({ name: z2.string(), sizeGib: z2.number().int(), mountPath: z2.string() })).optional(),
|
|
654
744
|
/** Boxes that may reach this one, each on one port (#98). Absent: none. */
|
|
655
|
-
links:
|
|
745
|
+
links: z2.array(BoxLinkSchema).optional(),
|
|
746
|
+
/**
|
|
747
|
+
* The integrations turned on for the box (#205, `github`): names only, the credential is fetched by the box
|
|
748
|
+
* each time it is needed. Absent: none. A host before integrations never sends it.
|
|
749
|
+
*/
|
|
750
|
+
integrations: z2.array(z2.string()).optional(),
|
|
656
751
|
/** How to reach what the box serves, its secrets masked (#87): `postgres://postgres:****@db.kvbox:5432/postgres`. */
|
|
657
|
-
url:
|
|
752
|
+
url: z2.string().optional(),
|
|
658
753
|
/**
|
|
659
754
|
* Only in what `POST /machines` answers, for an image that declares one (#87): how to reach what it
|
|
660
755
|
* serves, e.g. `postgres://postgres:<password>@db.kvbox:5432/postgres`. Holds the box's variables.
|
|
661
756
|
*/
|
|
662
|
-
connect:
|
|
757
|
+
connect: z2.string().optional()
|
|
663
758
|
});
|
|
664
|
-
var VolumeSchema =
|
|
759
|
+
var VolumeSchema = z2.object({
|
|
665
760
|
/** The host's 6-hex volume id (#91): the ledger's key, so a name removed and made again is two volumes. */
|
|
666
|
-
id:
|
|
667
|
-
name:
|
|
668
|
-
owner:
|
|
669
|
-
sizeGib:
|
|
761
|
+
id: z2.string(),
|
|
762
|
+
name: z2.string(),
|
|
763
|
+
owner: z2.string(),
|
|
764
|
+
sizeGib: z2.number().int(),
|
|
670
765
|
/** What the sparse file really occupies on the host. */
|
|
671
|
-
usedBytes:
|
|
672
|
-
attachedTo:
|
|
673
|
-
createdAt:
|
|
766
|
+
usedBytes: z2.number().int(),
|
|
767
|
+
attachedTo: z2.string().nullable(),
|
|
768
|
+
createdAt: z2.string(),
|
|
674
769
|
/** Whether the owner slug is a user or an org. Only the control plane knows; it fills it in on `GET /volumes`. */
|
|
675
|
-
ownerKind:
|
|
770
|
+
ownerKind: z2.enum(["user", "org"]).optional(),
|
|
676
771
|
/** The name of the host the volume lives on; only the control plane fills it in. It attaches only to a box there. */
|
|
677
|
-
host:
|
|
772
|
+
host: z2.string().optional()
|
|
678
773
|
});
|
|
679
774
|
var MAX_VOLUME_GIB = 4096;
|
|
680
775
|
var VOLUME_NAME_RE = /^[a-z0-9][a-z0-9-]{0,11}$/;
|
|
681
776
|
var VOLUME_NAME_RULE = "1-12 chars, lowercase letters, digits and '-', starting with a letter or digit";
|
|
682
|
-
var CreateVolumeRequest =
|
|
683
|
-
name:
|
|
684
|
-
sizeGib:
|
|
777
|
+
var CreateVolumeRequest = z2.object({
|
|
778
|
+
name: z2.string(),
|
|
779
|
+
sizeGib: z2.number().int().min(1).max(MAX_VOLUME_GIB),
|
|
685
780
|
/**
|
|
686
781
|
* Through a control plane (#91): the box this volume is for, so it is made on that box's host; the
|
|
687
782
|
* control plane requires it (a volume attaches only to a box on its own host, so one made for no box
|
|
688
783
|
* could never attach) and the CLI attaches right after. A host ignores it.
|
|
689
784
|
*/
|
|
690
|
-
box:
|
|
785
|
+
box: z2.string().optional()
|
|
691
786
|
});
|
|
692
|
-
var AttachVolumeRequest =
|
|
693
|
-
box:
|
|
787
|
+
var AttachVolumeRequest = z2.object({
|
|
788
|
+
box: z2.string()
|
|
694
789
|
});
|
|
695
|
-
var ResizeVolumeRequest =
|
|
696
|
-
sizeGib:
|
|
790
|
+
var ResizeVolumeRequest = z2.object({
|
|
791
|
+
sizeGib: z2.number().int().min(1).max(MAX_VOLUME_GIB)
|
|
697
792
|
});
|
|
698
|
-
var RunScriptRequest =
|
|
699
|
-
var ScriptOutputSchema =
|
|
793
|
+
var RunScriptRequest = z2.object({ input: z2.unknown().optional() });
|
|
794
|
+
var ScriptOutputSchema = z2.object({ output: z2.unknown() });
|
|
700
795
|
var BOX_RUN_ID_RE = /^[A-Za-z0-9_-]{1,64}$/;
|
|
701
|
-
var StartRunRequest =
|
|
702
|
-
id:
|
|
703
|
-
command:
|
|
796
|
+
var StartRunRequest = z2.object({
|
|
797
|
+
id: z2.string().regex(BOX_RUN_ID_RE),
|
|
798
|
+
command: z2.string().min(1).max(8192),
|
|
704
799
|
/** The command and everything it started are killed after this long. */
|
|
705
|
-
timeoutSec:
|
|
800
|
+
timeoutSec: z2.number().int().min(1).max(86400),
|
|
706
801
|
/**
|
|
707
802
|
* The caller will read the output back (`exec`, #188): the box's kvbox-agent must know `runOutput`
|
|
708
803
|
* (base v0.16.0+), which the host checks before the command starts, so an older box is `box-outdated`
|
|
709
804
|
* without having run anything.
|
|
710
805
|
*/
|
|
711
|
-
output:
|
|
806
|
+
output: z2.boolean().optional()
|
|
712
807
|
});
|
|
713
|
-
var StartRunAnswerSchema =
|
|
714
|
-
id:
|
|
808
|
+
var StartRunAnswerSchema = z2.object({
|
|
809
|
+
id: z2.string(),
|
|
715
810
|
/** False: a run of this id was already there. */
|
|
716
|
-
started:
|
|
811
|
+
started: z2.boolean(),
|
|
717
812
|
/** The box was asleep and this request woke it. */
|
|
718
|
-
woke:
|
|
813
|
+
woke: z2.boolean()
|
|
719
814
|
});
|
|
720
815
|
var BOX_RUN_STATES = ["running", "exited", "timeout", "unknown"];
|
|
721
|
-
var BoxRunSchema =
|
|
722
|
-
id:
|
|
723
|
-
state:
|
|
816
|
+
var BoxRunSchema = z2.object({
|
|
817
|
+
id: z2.string(),
|
|
818
|
+
state: z2.enum(BOX_RUN_STATES),
|
|
724
819
|
/** With `exited`; 128 + the signal for a command a signal ended. */
|
|
725
|
-
exitCode:
|
|
820
|
+
exitCode: z2.number().int().optional(),
|
|
726
821
|
/**
|
|
727
822
|
* With `exited` and `timeout`: how long the command itself ran, by the box's own clock (base v0.15.1
|
|
728
823
|
* and later). The asker learns of the end seconds late, so its own count is too long.
|
|
729
824
|
*/
|
|
730
|
-
durationMs:
|
|
825
|
+
durationMs: z2.number().int().nonnegative().optional()
|
|
731
826
|
});
|
|
732
|
-
var RunRefusalSchema =
|
|
827
|
+
var RunRefusalSchema = z2.object({ error: z2.string(), code: z2.string().optional() });
|
|
733
828
|
var RUN_OUTPUT_MAX_BYTES = 1 << 20;
|
|
734
829
|
var RUN_STREAMS = ["stdout", "stderr"];
|
|
735
|
-
var RunOutputSchema =
|
|
736
|
-
id:
|
|
737
|
-
stream:
|
|
738
|
-
offset:
|
|
739
|
-
size:
|
|
740
|
-
data:
|
|
830
|
+
var RunOutputSchema = z2.object({
|
|
831
|
+
id: z2.string(),
|
|
832
|
+
stream: z2.enum(RUN_STREAMS),
|
|
833
|
+
offset: z2.number().int().nonnegative(),
|
|
834
|
+
size: z2.number().int().nonnegative(),
|
|
835
|
+
data: z2.string()
|
|
741
836
|
});
|
|
742
837
|
var DEFAULT_EXEC_TIMEOUT_SEC = 600;
|
|
743
|
-
var ExecRequest =
|
|
744
|
-
command:
|
|
838
|
+
var ExecRequest = z2.object({
|
|
839
|
+
command: z2.string().min(1).max(8192),
|
|
745
840
|
/** The command and everything it started are killed after this long (default DEFAULT_EXEC_TIMEOUT_SEC). */
|
|
746
|
-
timeoutSec:
|
|
841
|
+
timeoutSec: z2.number().int().min(1).max(86400).optional()
|
|
747
842
|
});
|
|
748
|
-
var ExecStartSchema =
|
|
749
|
-
id:
|
|
843
|
+
var ExecStartSchema = z2.object({
|
|
844
|
+
id: z2.string(),
|
|
750
845
|
/** The box was asleep and this request woke it. */
|
|
751
|
-
woke:
|
|
846
|
+
woke: z2.boolean()
|
|
752
847
|
});
|
|
753
|
-
var ExecSchema =
|
|
754
|
-
id:
|
|
755
|
-
state:
|
|
848
|
+
var ExecSchema = z2.object({
|
|
849
|
+
id: z2.string(),
|
|
850
|
+
state: z2.enum(BOX_RUN_STATES),
|
|
756
851
|
/** With `exited`; 128 + the signal for a command a signal ended. */
|
|
757
|
-
exitCode:
|
|
852
|
+
exitCode: z2.number().int().optional(),
|
|
758
853
|
/** With `exited` and `timeout`: how long the command itself ran. */
|
|
759
|
-
durationMs:
|
|
760
|
-
stdout:
|
|
761
|
-
stderr:
|
|
762
|
-
stdoutBytes:
|
|
763
|
-
stderrBytes:
|
|
764
|
-
truncated:
|
|
765
|
-
});
|
|
766
|
-
var EnvVarSchema =
|
|
767
|
-
name:
|
|
768
|
-
value:
|
|
769
|
-
secret:
|
|
770
|
-
updatedAt:
|
|
771
|
-
});
|
|
772
|
-
var BoxEnvSchema =
|
|
773
|
-
box:
|
|
774
|
-
vars:
|
|
775
|
-
});
|
|
776
|
-
var BoxEnvChangeSchema =
|
|
777
|
-
box:
|
|
778
|
-
name:
|
|
854
|
+
durationMs: z2.number().int().nonnegative().optional(),
|
|
855
|
+
stdout: z2.string().optional(),
|
|
856
|
+
stderr: z2.string().optional(),
|
|
857
|
+
stdoutBytes: z2.number().int().nonnegative().optional(),
|
|
858
|
+
stderrBytes: z2.number().int().nonnegative().optional(),
|
|
859
|
+
truncated: z2.boolean().optional()
|
|
860
|
+
});
|
|
861
|
+
var EnvVarSchema = z2.object({
|
|
862
|
+
name: z2.string(),
|
|
863
|
+
value: z2.string().optional(),
|
|
864
|
+
secret: z2.boolean(),
|
|
865
|
+
updatedAt: z2.string()
|
|
866
|
+
});
|
|
867
|
+
var BoxEnvSchema = z2.object({
|
|
868
|
+
box: z2.string(),
|
|
869
|
+
vars: z2.array(EnvVarSchema)
|
|
870
|
+
});
|
|
871
|
+
var BoxEnvChangeSchema = z2.object({
|
|
872
|
+
box: z2.string(),
|
|
873
|
+
name: z2.string(),
|
|
779
874
|
/** Whether the box is running now: the change waits for its next start. */
|
|
780
|
-
running:
|
|
875
|
+
running: z2.boolean()
|
|
781
876
|
});
|
|
782
|
-
var SetEnvRequest =
|
|
783
|
-
value:
|
|
784
|
-
secret:
|
|
877
|
+
var SetEnvRequest = z2.object({
|
|
878
|
+
value: z2.string(),
|
|
879
|
+
secret: z2.boolean().optional()
|
|
785
880
|
});
|
|
786
|
-
var EnvChangeSchema =
|
|
787
|
-
owner:
|
|
788
|
-
name:
|
|
789
|
-
boxes:
|
|
881
|
+
var EnvChangeSchema = z2.object({
|
|
882
|
+
owner: z2.string(),
|
|
883
|
+
name: z2.string(),
|
|
884
|
+
boxes: z2.number().int()
|
|
790
885
|
});
|
|
791
|
-
var HostEnvRequest =
|
|
792
|
-
version:
|
|
793
|
-
vars:
|
|
886
|
+
var HostEnvRequest = z2.object({
|
|
887
|
+
version: z2.number().int().min(0),
|
|
888
|
+
vars: z2.array(z2.object({ name: z2.string(), value: z2.string() }))
|
|
794
889
|
});
|
|
795
|
-
var HostEnvVersionsSchema =
|
|
796
|
-
var CreateMachineRequest =
|
|
797
|
-
name:
|
|
890
|
+
var HostEnvVersionsSchema = z2.array(z2.object({ owner: z2.string(), version: z2.number().int() }));
|
|
891
|
+
var CreateMachineRequest = z2.object({
|
|
892
|
+
name: z2.string().optional(),
|
|
798
893
|
/** Ignored over the local socket (the caller is the host owner); the control plane sets it over HTTPS. */
|
|
799
|
-
owner:
|
|
894
|
+
owner: z2.string().optional(),
|
|
800
895
|
size: SizeSchema.optional(),
|
|
801
|
-
from:
|
|
802
|
-
force:
|
|
896
|
+
from: z2.string().optional(),
|
|
897
|
+
force: z2.boolean().optional(),
|
|
803
898
|
/**
|
|
804
899
|
* Extra authorized_keys lines for the box, on top of the host's own key: the control plane sends
|
|
805
900
|
* its SSH CA as one `cert-authority …` line (#51). Written into the box's authorized_keys at every
|
|
806
901
|
* boot (#49); a host older than that ignores them.
|
|
807
902
|
*/
|
|
808
|
-
sshKeys:
|
|
903
|
+
sshKeys: z2.array(z2.string()).optional(),
|
|
809
904
|
/** Seconds without network traffic before the box is hibernated (#47); 0: never. Absent: the host's default. */
|
|
810
|
-
autoHibernateSec:
|
|
905
|
+
autoHibernateSec: z2.number().int().min(0).optional(),
|
|
811
906
|
/**
|
|
812
907
|
* Place the box on the host of this box (#98, `kvbox new --near`), so the two can be linked. Only the
|
|
813
908
|
* control plane reads it; a host has one place to put a box.
|
|
814
909
|
*/
|
|
815
|
-
near:
|
|
910
|
+
near: z2.string().optional(),
|
|
816
911
|
/**
|
|
817
912
|
* Place the box on a host in this country (`kvbox new --country romania`): a code or an English name,
|
|
818
913
|
* `@kvbox/shared/country`. Only the control plane reads it.
|
|
819
914
|
*/
|
|
820
|
-
country:
|
|
915
|
+
country: z2.string().optional(),
|
|
821
916
|
/**
|
|
822
917
|
* Place the box on the host of this name and nowhere else (`kvbox new --host kvbox2`, a hidden flag):
|
|
823
918
|
* an admin's, to try a host out. Only the control plane reads it, and refuses it from anyone else.
|
|
824
919
|
*/
|
|
825
|
-
host:
|
|
920
|
+
host: z2.string().optional(),
|
|
826
921
|
/** The image to boot (#87, `kvbox new --base postgres`). Absent: the base image. */
|
|
827
|
-
image:
|
|
922
|
+
image: z2.string().optional(),
|
|
828
923
|
/** The box's own environment variables (#87, `kvbox new -e NAME=value`), over its owner's. */
|
|
829
|
-
env:
|
|
924
|
+
env: z2.array(z2.object({ name: z2.string(), value: z2.string() })).optional(),
|
|
925
|
+
/**
|
|
926
|
+
* Start the box on this backup's disk (#141, `kvbox new --from-backup <id>`), a removed box's too: its image,
|
|
927
|
+
* version and variables come from the backup, its size too unless given. Only the control plane reads it.
|
|
928
|
+
*/
|
|
929
|
+
fromBackup: z2.string().optional(),
|
|
930
|
+
/**
|
|
931
|
+
* The integrations turned on for the box (#205, `kvbox new --integration github`). Absent: none, or with
|
|
932
|
+
* `from` / `fromBackup` the list the snapshot or the backup was taken with.
|
|
933
|
+
*/
|
|
934
|
+
integrations: IntegrationListSchema.optional()
|
|
830
935
|
});
|
|
831
|
-
var
|
|
832
|
-
|
|
936
|
+
var HostFromBackupRequest = CreateMachineRequest.omit({ from: true, fromBackup: true, image: true, env: true }).extend({ backup: HostRestoreRequest });
|
|
937
|
+
var ForkMachineRequest = z2.object({
|
|
938
|
+
name: z2.string().optional(),
|
|
833
939
|
/**
|
|
834
940
|
* The new box's slug, bare (`acme`): the control plane sends the target of `--org` here; the host
|
|
835
941
|
* qualifies it with the caller's realm. Absent: the source's owner. A CLI leaves it out.
|
|
836
942
|
*/
|
|
837
|
-
owner:
|
|
943
|
+
owner: z2.string().optional(),
|
|
838
944
|
/** A cold fork only: a warm one keeps the source's vCPU and memory. */
|
|
839
945
|
size: SizeSchema.optional(),
|
|
840
|
-
force:
|
|
946
|
+
force: z2.boolean().optional(),
|
|
841
947
|
/** As in CreateMachineRequest: the control plane's CA line for the new box's owner. */
|
|
842
|
-
sshKeys:
|
|
843
|
-
autoHibernateSec:
|
|
948
|
+
sshKeys: z2.array(z2.string()).optional(),
|
|
949
|
+
autoHibernateSec: z2.number().int().min(0).optional()
|
|
844
950
|
});
|
|
845
|
-
var SetSshKeysRequest =
|
|
846
|
-
sshKeys:
|
|
951
|
+
var SetSshKeysRequest = z2.object({
|
|
952
|
+
sshKeys: z2.array(z2.string())
|
|
847
953
|
});
|
|
848
|
-
var RescaleMachineRequest =
|
|
954
|
+
var RescaleMachineRequest = z2.object({
|
|
849
955
|
size: SizeSchema.optional(),
|
|
850
|
-
vcpu:
|
|
851
|
-
memMib:
|
|
852
|
-
diskGib:
|
|
956
|
+
vcpu: z2.number().int().min(1).max(64).optional(),
|
|
957
|
+
memMib: z2.number().int().min(256).optional(),
|
|
958
|
+
diskGib: z2.number().int().min(1).optional(),
|
|
853
959
|
/** Skip the capacity guard when a running box grows (#37). */
|
|
854
|
-
force:
|
|
960
|
+
force: z2.boolean().optional()
|
|
855
961
|
});
|
|
856
|
-
var StartMachineRequest =
|
|
857
|
-
force:
|
|
962
|
+
var StartMachineRequest = z2.object({
|
|
963
|
+
force: z2.boolean().optional()
|
|
858
964
|
});
|
|
859
|
-
var SetMachineRequest =
|
|
965
|
+
var SetMachineRequest = z2.object({
|
|
860
966
|
/** Seconds without network traffic before the box is hibernated (#47); 0: never. */
|
|
861
|
-
autoHibernateSec:
|
|
967
|
+
autoHibernateSec: z2.number().int().min(0).optional(),
|
|
862
968
|
/** The box's idle check (#102): an absolute path to a script inside the box, exit 0 = idle; "": none, back to network traffic. */
|
|
863
|
-
idleCheck:
|
|
864
|
-
|
|
865
|
-
|
|
866
|
-
|
|
867
|
-
|
|
868
|
-
|
|
969
|
+
idleCheck: z2.union([z2.literal(""), z2.string().max(255).regex(/^\/[^\0\n]*$/, "an absolute path inside the box")]).optional(),
|
|
970
|
+
/** The box's integrations (#205), the whole list: `[]` turns every one off. Applies at once, in any state. */
|
|
971
|
+
integrations: IntegrationListSchema.optional()
|
|
972
|
+
});
|
|
973
|
+
var SnapshotSchema = z2.object({
|
|
974
|
+
name: z2.string(),
|
|
975
|
+
owner: z2.string(),
|
|
976
|
+
source: z2.string(),
|
|
869
977
|
// the box it was taken from, as owner/name
|
|
870
|
-
base:
|
|
978
|
+
base: z2.string(),
|
|
871
979
|
// version of the image the overlay stacks on; a restore needs the same one
|
|
872
980
|
/** As in MachineSchema: the image when it is not the base one (#87). */
|
|
873
|
-
image:
|
|
874
|
-
vcpu:
|
|
875
|
-
memMib:
|
|
876
|
-
sizeBytes:
|
|
981
|
+
image: z2.string().optional(),
|
|
982
|
+
vcpu: z2.number().int(),
|
|
983
|
+
memMib: z2.number().int(),
|
|
984
|
+
sizeBytes: z2.number().int(),
|
|
877
985
|
// what vmstate + mem + overlay really occupy on the host
|
|
878
|
-
createdAt:
|
|
986
|
+
createdAt: z2.string()
|
|
879
987
|
});
|
|
880
|
-
var CreateSnapshotRequest =
|
|
881
|
-
box:
|
|
882
|
-
name:
|
|
988
|
+
var CreateSnapshotRequest = z2.object({
|
|
989
|
+
box: z2.string(),
|
|
990
|
+
name: z2.string(),
|
|
883
991
|
/** Retake a snapshot under a name that exists (#83): the old one goes only once the new one is complete. */
|
|
884
|
-
replace:
|
|
885
|
-
});
|
|
886
|
-
var DiskCapacitySchema =
|
|
887
|
-
totalGib:
|
|
888
|
-
freeGib:
|
|
889
|
-
volumesGib:
|
|
890
|
-
volumesUsedGib:
|
|
891
|
-
headroomGib:
|
|
892
|
-
});
|
|
893
|
-
var CapacitySchema =
|
|
894
|
-
hostMemMib:
|
|
895
|
-
hostCores:
|
|
896
|
-
reservedMemMib:
|
|
897
|
-
reservedVcpu:
|
|
898
|
-
running:
|
|
992
|
+
replace: z2.boolean().optional()
|
|
993
|
+
});
|
|
994
|
+
var DiskCapacitySchema = z2.object({
|
|
995
|
+
totalGib: z2.number().int(),
|
|
996
|
+
freeGib: z2.number().int(),
|
|
997
|
+
volumesGib: z2.number().int(),
|
|
998
|
+
volumesUsedGib: z2.number().int(),
|
|
999
|
+
headroomGib: z2.number().int()
|
|
1000
|
+
});
|
|
1001
|
+
var CapacitySchema = z2.object({
|
|
1002
|
+
hostMemMib: z2.number().int(),
|
|
1003
|
+
hostCores: z2.number().int(),
|
|
1004
|
+
reservedMemMib: z2.number().int(),
|
|
1005
|
+
reservedVcpu: z2.number().int(),
|
|
1006
|
+
running: z2.number().int(),
|
|
899
1007
|
/**
|
|
900
1008
|
* MiB of RAM the host keeps back from its boxes (config.json `memHeadroomMib`). Absent on a kvbox-server
|
|
901
1009
|
* from before the setting, which keeps 2 GB (`OLD_HOST_MEM_HEADROOM_MIB`).
|
|
902
1010
|
*/
|
|
903
|
-
memHeadroomMib:
|
|
1011
|
+
memHeadroomMib: z2.number().int().optional(),
|
|
904
1012
|
/** Absent on a host from before volumes (#91): it cannot take one. */
|
|
905
1013
|
disk: DiskCapacitySchema.optional(),
|
|
906
1014
|
/**
|
|
907
1015
|
* The images a new box can be made from here (#87), with the version `new` uses; the base is `base`.
|
|
908
1016
|
* Absent on a host from before images: it has only the base.
|
|
909
1017
|
*/
|
|
910
|
-
images:
|
|
1018
|
+
images: z2.array(z2.object({ name: z2.string(), version: z2.string() })).optional(),
|
|
911
1019
|
/** kvbox-server's version, so the control plane's host list shows it without a call per host. Older servers omit it. */
|
|
912
|
-
version:
|
|
1020
|
+
version: z2.string().optional(),
|
|
913
1021
|
/** Present on a host set up as a backup store: the disk its Garage keeps chunks on, and whether Garage runs. */
|
|
914
|
-
backupStore:
|
|
1022
|
+
backupStore: z2.object({ totalBytes: z2.number().int(), freeBytes: z2.number().int(), running: z2.boolean() }).optional(),
|
|
915
1023
|
/** True on a kvbox-server that reaches a backup store by its certificate's `pin`; older ones omit it and cannot back up to a store. */
|
|
916
|
-
storeClient:
|
|
917
|
-
|
|
918
|
-
|
|
919
|
-
|
|
920
|
-
|
|
921
|
-
|
|
922
|
-
});
|
|
923
|
-
var
|
|
924
|
-
updatedAt:
|
|
1024
|
+
storeClient: z2.boolean().optional(),
|
|
1025
|
+
/** True on a kvbox-server with `POST /machines/from-backup` (#141, `kvbox new --from-backup`); older ones omit it. */
|
|
1026
|
+
fromBackup: z2.boolean().optional(),
|
|
1027
|
+
/** True on a kvbox-server that keeps a box's `integrations` (#205); an older one drops the field without a word. */
|
|
1028
|
+
integrations: z2.boolean().optional()
|
|
1029
|
+
});
|
|
1030
|
+
var ImageSchema = z2.object({ name: z2.string(), version: z2.string().nullable() });
|
|
1031
|
+
var ImageIndexSchema = z2.object({
|
|
1032
|
+
updatedAt: z2.string(),
|
|
1033
|
+
images: z2.record(z2.string(), z2.object({ version: z2.string().min(1), minServer: z2.string().min(1).optional() }))
|
|
1034
|
+
});
|
|
1035
|
+
var LatestImagesSchema = z2.object({
|
|
1036
|
+
updatedAt: z2.string().nullable(),
|
|
925
1037
|
images: ImageIndexSchema.shape.images,
|
|
926
|
-
checkedAt:
|
|
927
|
-
});
|
|
928
|
-
var RecoveryReportSchema =
|
|
929
|
-
at:
|
|
930
|
-
booted:
|
|
931
|
-
leftStopped:
|
|
932
|
-
failed:
|
|
933
|
-
});
|
|
934
|
-
var HostUpdateSchema =
|
|
935
|
-
state:
|
|
936
|
-
startedAt:
|
|
937
|
-
finishedAt:
|
|
1038
|
+
checkedAt: z2.string().nullable()
|
|
1039
|
+
});
|
|
1040
|
+
var RecoveryReportSchema = z2.object({
|
|
1041
|
+
at: z2.string(),
|
|
1042
|
+
booted: z2.array(z2.string()),
|
|
1043
|
+
leftStopped: z2.array(z2.string()),
|
|
1044
|
+
failed: z2.array(z2.object({ box: z2.string(), error: z2.string() }))
|
|
1045
|
+
});
|
|
1046
|
+
var HostUpdateSchema = z2.object({
|
|
1047
|
+
state: z2.enum(["running", "done", "failed"]),
|
|
1048
|
+
startedAt: z2.string(),
|
|
1049
|
+
finishedAt: z2.string().nullable(),
|
|
938
1050
|
/** kvbox-server's version when the update started, and when it ended (null while running or when it failed before). */
|
|
939
|
-
from:
|
|
940
|
-
to:
|
|
941
|
-
error:
|
|
942
|
-
needsManual:
|
|
943
|
-
});
|
|
944
|
-
var HealthSchema =
|
|
945
|
-
ok:
|
|
946
|
-
version:
|
|
947
|
-
pid:
|
|
1051
|
+
from: z2.string(),
|
|
1052
|
+
to: z2.string().nullable(),
|
|
1053
|
+
error: z2.string().nullable(),
|
|
1054
|
+
needsManual: z2.array(z2.string())
|
|
1055
|
+
});
|
|
1056
|
+
var HealthSchema = z2.object({
|
|
1057
|
+
ok: z2.literal(true),
|
|
1058
|
+
version: z2.string(),
|
|
1059
|
+
pid: z2.number().int(),
|
|
948
1060
|
/** Base image version new boxes get (null when the host has no usable base image yet). */
|
|
949
|
-
base:
|
|
1061
|
+
base: z2.string().nullable(),
|
|
950
1062
|
/** Owner that boxes made over the local socket get (the Unix user running the server). */
|
|
951
|
-
owner:
|
|
1063
|
+
owner: z2.string(),
|
|
952
1064
|
/** The control plane this host joined (null when none). */
|
|
953
|
-
controlPlane:
|
|
1065
|
+
controlPlane: z2.object({
|
|
954
1066
|
/** Realm name, e.g. kvbox.sh. */
|
|
955
|
-
name:
|
|
956
|
-
url:
|
|
1067
|
+
name: z2.string(),
|
|
1068
|
+
url: z2.string(),
|
|
957
1069
|
/** Where this host answers the control plane. */
|
|
958
|
-
hostUrl:
|
|
1070
|
+
hostUrl: z2.string()
|
|
959
1071
|
}).nullable(),
|
|
960
1072
|
/** The relay this host reaches the internet through (#50); null when it has its own public address. Older servers omit it. */
|
|
961
|
-
relay:
|
|
962
|
-
name:
|
|
1073
|
+
relay: z2.object({
|
|
1074
|
+
name: z2.string(),
|
|
963
1075
|
/** The public IP the relay owns for this host. */
|
|
964
|
-
publicIp:
|
|
1076
|
+
publicIp: z2.string(),
|
|
965
1077
|
/** The relay's WireGuard endpoint the tunnel dials. */
|
|
966
|
-
endpoint:
|
|
1078
|
+
endpoint: z2.string(),
|
|
967
1079
|
/** Times the server redialed the tunnel since it started, because the relay stopped answering. Older servers omit them. */
|
|
968
|
-
restarts:
|
|
969
|
-
lastRestartAt:
|
|
1080
|
+
restarts: z2.number().int().optional(),
|
|
1081
|
+
lastRestartAt: z2.string().nullable().optional()
|
|
970
1082
|
}).nullable().optional(),
|
|
971
1083
|
/** Boxes brought back at the server's last start; null when there were none or it is still at it. Older servers omit it. */
|
|
972
1084
|
recovery: RecoveryReportSchema.nullable().optional(),
|
|
973
1085
|
/** The last self-update; null when none ran. Older servers omit it. */
|
|
974
1086
|
update: HostUpdateSchema.nullable().optional()
|
|
975
1087
|
});
|
|
976
|
-
var MachineUsageSchema =
|
|
977
|
-
name:
|
|
978
|
-
owner:
|
|
1088
|
+
var MachineUsageSchema = z2.object({
|
|
1089
|
+
name: z2.string(),
|
|
1090
|
+
owner: z2.string(),
|
|
979
1091
|
status: BoxStatusSchema,
|
|
980
|
-
window:
|
|
981
|
-
seconds:
|
|
982
|
-
running:
|
|
983
|
-
standby:
|
|
984
|
-
hibernated:
|
|
985
|
-
stopped:
|
|
1092
|
+
window: z2.object({ from: z2.string(), to: z2.string() }),
|
|
1093
|
+
seconds: z2.object({
|
|
1094
|
+
running: z2.number().int(),
|
|
1095
|
+
standby: z2.number().int(),
|
|
1096
|
+
hibernated: z2.number().int(),
|
|
1097
|
+
stopped: z2.number().int()
|
|
986
1098
|
}),
|
|
987
|
-
vcpuHours:
|
|
988
|
-
ramGibHours:
|
|
989
|
-
diskGibHours:
|
|
990
|
-
cost:
|
|
1099
|
+
vcpuHours: z2.number(),
|
|
1100
|
+
ramGibHours: z2.number(),
|
|
1101
|
+
diskGibHours: z2.number(),
|
|
1102
|
+
cost: z2.object({ amount: z2.number(), currency: z2.string() }).optional(),
|
|
991
1103
|
/** Stops the server did not witness (Firecracker died, host rebooted) and dated to when it noticed. */
|
|
992
|
-
estimatedStops:
|
|
993
|
-
historyFrom:
|
|
1104
|
+
estimatedStops: z2.number().int(),
|
|
1105
|
+
historyFrom: z2.string().nullable()
|
|
994
1106
|
});
|
|
995
|
-
var GuestStatsSchema =
|
|
1107
|
+
var GuestStatsSchema = z2.object({
|
|
996
1108
|
/** Load average over 1, 5 and 15 minutes. */
|
|
997
|
-
load:
|
|
998
|
-
cpus:
|
|
999
|
-
memTotalMib:
|
|
1109
|
+
load: z2.tuple([z2.number(), z2.number(), z2.number()]),
|
|
1110
|
+
cpus: z2.number().int(),
|
|
1111
|
+
memTotalMib: z2.number().int(),
|
|
1000
1112
|
/** Total minus available: page cache counts as free. */
|
|
1001
|
-
memUsedMib:
|
|
1113
|
+
memUsedMib: z2.number().int(),
|
|
1002
1114
|
/** The box's root, which is its overlay disk: the box's own writes, not the shared base. */
|
|
1003
|
-
diskTotalBytes:
|
|
1004
|
-
diskUsedBytes:
|
|
1005
|
-
uptimeSec:
|
|
1115
|
+
diskTotalBytes: z2.number().int(),
|
|
1116
|
+
diskUsedBytes: z2.number().int(),
|
|
1117
|
+
uptimeSec: z2.number().int()
|
|
1006
1118
|
});
|
|
1007
|
-
var MachineStatsSchema =
|
|
1008
|
-
name:
|
|
1009
|
-
owner:
|
|
1119
|
+
var MachineStatsSchema = z2.object({
|
|
1120
|
+
name: z2.string(),
|
|
1121
|
+
owner: z2.string(),
|
|
1010
1122
|
stats: GuestStatsSchema.nullable()
|
|
1011
1123
|
});
|
|
1012
|
-
var UsageStatusSchema =
|
|
1124
|
+
var UsageStatusSchema = z2.enum([...BoxStatusSchema.options, "removed"]);
|
|
1013
1125
|
var BoxUsageSchema = MachineUsageSchema.omit({ window: true, status: true }).extend({
|
|
1014
1126
|
/** The host's box id; a name removed and recreated appears twice, with two ids. */
|
|
1015
|
-
id:
|
|
1127
|
+
id: z2.string(),
|
|
1016
1128
|
status: UsageStatusSchema,
|
|
1017
1129
|
/** Through a control plane: whether the owner slug is a user's or an org's (what `kvbox ls` shows). */
|
|
1018
|
-
ownerKind:
|
|
1130
|
+
ownerKind: z2.enum(["user", "org"]).optional(),
|
|
1019
1131
|
/**
|
|
1020
1132
|
* Through a control plane: the username that made the box (#60), absent when the box is gone from
|
|
1021
1133
|
* the index (removed), was found by reconcile, or its maker was deleted. The ledger does not record it.
|
|
1022
1134
|
*/
|
|
1023
|
-
createdBy:
|
|
1135
|
+
createdBy: z2.string().optional()
|
|
1024
1136
|
});
|
|
1025
|
-
var VolumeUsageSchema =
|
|
1137
|
+
var VolumeUsageSchema = z2.object({
|
|
1026
1138
|
/** The host's volume id; a name removed and made again appears twice, with two ids. */
|
|
1027
|
-
id:
|
|
1028
|
-
name:
|
|
1029
|
-
owner:
|
|
1030
|
-
ownerKind:
|
|
1139
|
+
id: z2.string(),
|
|
1140
|
+
name: z2.string(),
|
|
1141
|
+
owner: z2.string(),
|
|
1142
|
+
ownerKind: z2.enum(["user", "org"]).optional(),
|
|
1031
1143
|
/** The size at the end of the window (or when removed). */
|
|
1032
|
-
sizeGib:
|
|
1033
|
-
status:
|
|
1034
|
-
volumeHours:
|
|
1035
|
-
volumeGibHours:
|
|
1036
|
-
cost:
|
|
1037
|
-
historyFrom:
|
|
1038
|
-
});
|
|
1039
|
-
var CronUsageSchema =
|
|
1040
|
-
id:
|
|
1041
|
-
name:
|
|
1042
|
-
owner:
|
|
1043
|
-
ownerKind:
|
|
1044
|
-
status:
|
|
1045
|
-
hours:
|
|
1046
|
-
cost:
|
|
1144
|
+
sizeGib: z2.number().int(),
|
|
1145
|
+
status: z2.enum(["present", "removed"]),
|
|
1146
|
+
volumeHours: z2.number(),
|
|
1147
|
+
volumeGibHours: z2.number(),
|
|
1148
|
+
cost: z2.object({ amount: z2.number(), currency: z2.string() }).optional(),
|
|
1149
|
+
historyFrom: z2.string().nullable()
|
|
1150
|
+
});
|
|
1151
|
+
var CronUsageSchema = z2.object({
|
|
1152
|
+
id: z2.string(),
|
|
1153
|
+
name: z2.string(),
|
|
1154
|
+
owner: z2.string(),
|
|
1155
|
+
ownerKind: z2.enum(["user", "org"]).optional(),
|
|
1156
|
+
status: z2.enum(["present", "removed"]),
|
|
1157
|
+
hours: z2.number(),
|
|
1158
|
+
cost: z2.object({ amount: z2.number(), currency: z2.string() }).optional(),
|
|
1047
1159
|
/** When it was made. */
|
|
1048
|
-
historyFrom:
|
|
1049
|
-
});
|
|
1050
|
-
var BackupUsageSchema =
|
|
1051
|
-
id:
|
|
1052
|
-
kind:
|
|
1053
|
-
name:
|
|
1054
|
-
owner:
|
|
1055
|
-
ownerKind:
|
|
1160
|
+
historyFrom: z2.string().nullable()
|
|
1161
|
+
});
|
|
1162
|
+
var BackupUsageSchema = z2.object({
|
|
1163
|
+
id: z2.string(),
|
|
1164
|
+
kind: z2.string(),
|
|
1165
|
+
name: z2.string(),
|
|
1166
|
+
owner: z2.string(),
|
|
1167
|
+
ownerKind: z2.enum(["user", "org"]).optional(),
|
|
1056
1168
|
/** How many paid backups turned ready in the window. */
|
|
1057
|
-
count:
|
|
1058
|
-
cost:
|
|
1169
|
+
count: z2.number().int(),
|
|
1170
|
+
cost: z2.object({ amount: z2.number(), currency: z2.string() })
|
|
1059
1171
|
});
|
|
1060
|
-
var UsageDayItemSchema =
|
|
1061
|
-
id:
|
|
1062
|
-
name:
|
|
1063
|
-
owner:
|
|
1172
|
+
var UsageDayItemSchema = z2.object({
|
|
1173
|
+
id: z2.string(),
|
|
1174
|
+
name: z2.string(),
|
|
1175
|
+
owner: z2.string(),
|
|
1064
1176
|
/** Removed by the end of the report's window. */
|
|
1065
|
-
removed:
|
|
1066
|
-
cost:
|
|
1177
|
+
removed: z2.boolean(),
|
|
1178
|
+
cost: z2.number()
|
|
1067
1179
|
});
|
|
1068
|
-
var UsageDaySchema =
|
|
1180
|
+
var UsageDaySchema = z2.object({
|
|
1069
1181
|
/** `YYYY-MM-DD`, UTC. */
|
|
1070
|
-
date:
|
|
1071
|
-
from:
|
|
1072
|
-
to:
|
|
1073
|
-
cost:
|
|
1074
|
-
currency:
|
|
1075
|
-
boxes:
|
|
1076
|
-
volumes:
|
|
1182
|
+
date: z2.string(),
|
|
1183
|
+
from: z2.string(),
|
|
1184
|
+
to: z2.string(),
|
|
1185
|
+
cost: z2.number(),
|
|
1186
|
+
currency: z2.string(),
|
|
1187
|
+
boxes: z2.array(UsageDayItemSchema),
|
|
1188
|
+
volumes: z2.array(UsageDayItemSchema),
|
|
1077
1189
|
/** Object storage that existed that day (#182); absent on a day without any. */
|
|
1078
|
-
storage:
|
|
1190
|
+
storage: z2.array(UsageDayItemSchema).optional(),
|
|
1079
1191
|
/** Cron services that existed that day (#190); absent on a day without any. */
|
|
1080
|
-
cron:
|
|
1192
|
+
cron: z2.array(UsageDayItemSchema).optional(),
|
|
1081
1193
|
/** Paid backups that turned ready that day, summed per thing backed up (`id` is `<owner>/<kind>:<name>`); absent on a day without any. */
|
|
1082
|
-
backups:
|
|
1194
|
+
backups: z2.array(UsageDayItemSchema).optional()
|
|
1083
1195
|
});
|
|
1084
|
-
var UsageReportSchema =
|
|
1085
|
-
window:
|
|
1086
|
-
boxes:
|
|
1196
|
+
var UsageReportSchema = z2.object({
|
|
1197
|
+
window: z2.object({ from: z2.string(), to: z2.string() }),
|
|
1198
|
+
boxes: z2.array(BoxUsageSchema),
|
|
1087
1199
|
/** Absent from a side older than #91. */
|
|
1088
|
-
volumes:
|
|
1200
|
+
volumes: z2.array(VolumeUsageSchema).optional(),
|
|
1089
1201
|
/**
|
|
1090
1202
|
* Object storage (#182, control plane only): one row per storage a slug has or had, shaped like a
|
|
1091
1203
|
* volume's. `volumeHours` are the hours it existed, `volumeGibHours` those of the GiB beyond the
|
|
1092
1204
|
* included ones, `sizeGib` its whole size. Absent when there is none.
|
|
1093
1205
|
*/
|
|
1094
|
-
storage:
|
|
1206
|
+
storage: z2.array(VolumeUsageSchema).optional(),
|
|
1095
1207
|
/** Cron services (#190, control plane only): one row per service a slug has or had. Absent when there is none. */
|
|
1096
|
-
cron:
|
|
1208
|
+
cron: z2.array(CronUsageSchema).optional(),
|
|
1097
1209
|
/** Paid backups (control plane only): one row per box, volume or service backed up by hand in the window. Absent when there is none. */
|
|
1098
|
-
backups:
|
|
1210
|
+
backups: z2.array(BackupUsageSchema).optional(),
|
|
1099
1211
|
/** With `?by=day` only, oldest day first. */
|
|
1100
|
-
days:
|
|
1101
|
-
totals:
|
|
1212
|
+
days: z2.array(UsageDaySchema).optional(),
|
|
1213
|
+
totals: z2.object({
|
|
1102
1214
|
seconds: MachineUsageSchema.shape.seconds,
|
|
1103
|
-
vcpuHours:
|
|
1104
|
-
ramGibHours:
|
|
1105
|
-
diskGibHours:
|
|
1106
|
-
volumeHours:
|
|
1107
|
-
volumeGibHours:
|
|
1215
|
+
vcpuHours: z2.number(),
|
|
1216
|
+
ramGibHours: z2.number(),
|
|
1217
|
+
diskGibHours: z2.number(),
|
|
1218
|
+
volumeHours: z2.number().optional(),
|
|
1219
|
+
volumeGibHours: z2.number().optional(),
|
|
1108
1220
|
/** Boxes, volumes, object storage, cron services and paid backups together. */
|
|
1109
|
-
cost:
|
|
1221
|
+
cost: z2.object({ amount: z2.number(), currency: z2.string() }).optional()
|
|
1110
1222
|
})
|
|
1111
1223
|
});
|
|
1112
|
-
var UsageEventRowSchema =
|
|
1113
|
-
id:
|
|
1114
|
-
boxId:
|
|
1115
|
-
owner:
|
|
1116
|
-
name:
|
|
1117
|
-
at:
|
|
1118
|
-
state:
|
|
1119
|
-
vcpu:
|
|
1120
|
-
memMib:
|
|
1121
|
-
diskGib:
|
|
1122
|
-
by:
|
|
1123
|
-
});
|
|
1124
|
-
var UsageEventsResponseSchema =
|
|
1125
|
-
ledger:
|
|
1126
|
-
events:
|
|
1127
|
-
next:
|
|
1128
|
-
});
|
|
1129
|
-
var VolumeEventRowSchema =
|
|
1130
|
-
id:
|
|
1131
|
-
volumeId:
|
|
1132
|
-
owner:
|
|
1133
|
-
name:
|
|
1134
|
-
at:
|
|
1135
|
-
sizeGib:
|
|
1136
|
-
by:
|
|
1137
|
-
});
|
|
1138
|
-
var VolumeEventsResponseSchema =
|
|
1139
|
-
ledger:
|
|
1140
|
-
events:
|
|
1141
|
-
next:
|
|
1224
|
+
var UsageEventRowSchema = z2.object({
|
|
1225
|
+
id: z2.number().int(),
|
|
1226
|
+
boxId: z2.string(),
|
|
1227
|
+
owner: z2.string(),
|
|
1228
|
+
name: z2.string(),
|
|
1229
|
+
at: z2.string(),
|
|
1230
|
+
state: z2.enum(["running", "standby", "hibernated", "stopped"]),
|
|
1231
|
+
vcpu: z2.number().int(),
|
|
1232
|
+
memMib: z2.number().int(),
|
|
1233
|
+
diskGib: z2.number().int(),
|
|
1234
|
+
by: z2.string()
|
|
1235
|
+
});
|
|
1236
|
+
var UsageEventsResponseSchema = z2.object({
|
|
1237
|
+
ledger: z2.string().min(1),
|
|
1238
|
+
events: z2.array(UsageEventRowSchema),
|
|
1239
|
+
next: z2.number().int()
|
|
1240
|
+
});
|
|
1241
|
+
var VolumeEventRowSchema = z2.object({
|
|
1242
|
+
id: z2.number().int(),
|
|
1243
|
+
volumeId: z2.string(),
|
|
1244
|
+
owner: z2.string(),
|
|
1245
|
+
name: z2.string(),
|
|
1246
|
+
at: z2.string(),
|
|
1247
|
+
sizeGib: z2.number().int(),
|
|
1248
|
+
by: z2.enum(["create", "resize", "rm"])
|
|
1249
|
+
});
|
|
1250
|
+
var VolumeEventsResponseSchema = z2.object({
|
|
1251
|
+
ledger: z2.string().min(1),
|
|
1252
|
+
events: z2.array(VolumeEventRowSchema),
|
|
1253
|
+
next: z2.number().int()
|
|
1142
1254
|
});
|
|
1143
1255
|
var API_ERROR_CODES = ["account-inactive", "org-inactive", "out-of-credit", "box-outdated", "storage-outdated", "object-exists", "storage-waking"];
|
|
1144
|
-
var ApiErrorCodeSchema =
|
|
1145
|
-
var ApiErrorSchema =
|
|
1146
|
-
error:
|
|
1256
|
+
var ApiErrorCodeSchema = z2.enum(API_ERROR_CODES);
|
|
1257
|
+
var ApiErrorSchema = z2.object({
|
|
1258
|
+
error: z2.string(),
|
|
1147
1259
|
code: ApiErrorCodeSchema.optional()
|
|
1148
1260
|
});
|
|
1149
1261
|
var DEFAULT_CLOUD_URL = "https://api.kvbox.sh";
|
|
1150
1262
|
var ACTIVATED_BY = ["card", "admin"];
|
|
1151
|
-
var ActivatedBySchema =
|
|
1152
|
-
var CloudUserSchema =
|
|
1263
|
+
var ActivatedBySchema = z2.enum(ACTIVATED_BY);
|
|
1264
|
+
var CloudUserSchema = z2.object({
|
|
1153
1265
|
/** The handle: what hosts file boxes under (`<username>@<control plane>`). Lowercase, no `@` or `/`. */
|
|
1154
|
-
username:
|
|
1266
|
+
username: z2.string(),
|
|
1155
1267
|
/** Display name, free text ("Alexandru Ghiura"). */
|
|
1156
|
-
name:
|
|
1268
|
+
name: z2.string(),
|
|
1157
1269
|
/** Login identity, unique. */
|
|
1158
|
-
email:
|
|
1159
|
-
role:
|
|
1160
|
-
createdAt:
|
|
1270
|
+
email: z2.string(),
|
|
1271
|
+
role: z2.enum(["admin", "user"]),
|
|
1272
|
+
createdAt: z2.string(),
|
|
1161
1273
|
/**
|
|
1162
1274
|
* False until a card is on file or an admin activates the account (#74): then only `/me` and
|
|
1163
1275
|
* `/logout` answer. Admins are never gated. A control plane older than #74 does not send these and
|
|
1164
1276
|
* gates nobody, hence the defaults: a newer CLI must still parse its answers.
|
|
1165
1277
|
*/
|
|
1166
|
-
active:
|
|
1278
|
+
active: z2.boolean().default(true),
|
|
1167
1279
|
activatedBy: ActivatedBySchema.nullable().default(null),
|
|
1168
1280
|
/** When too many wrong passwords locked the account (#161); null when it is not locked. Older control planes omit it. */
|
|
1169
|
-
lockedAt:
|
|
1281
|
+
lockedAt: z2.string().nullable().default(null)
|
|
1170
1282
|
});
|
|
1171
1283
|
var ORG_ROLES = ["owner", "admin", "member"];
|
|
1172
|
-
var OrgRoleSchema =
|
|
1173
|
-
var CloudOrgSchema =
|
|
1174
|
-
slug:
|
|
1284
|
+
var OrgRoleSchema = z2.enum(ORG_ROLES);
|
|
1285
|
+
var CloudOrgSchema = z2.object({
|
|
1286
|
+
slug: z2.string(),
|
|
1175
1287
|
/** Display name; the slug never changes, this may. */
|
|
1176
|
-
name:
|
|
1177
|
-
createdAt:
|
|
1288
|
+
name: z2.string(),
|
|
1289
|
+
createdAt: z2.string(),
|
|
1178
1290
|
/** An org pays for itself (#74): off until it has a card or an admin activates it; its boxes are 402. Defaults as on CloudUser. */
|
|
1179
|
-
active:
|
|
1291
|
+
active: z2.boolean().default(true),
|
|
1180
1292
|
activatedBy: ActivatedBySchema.nullable().default(null)
|
|
1181
1293
|
});
|
|
1182
1294
|
var OrgMembershipSchema = CloudOrgSchema.extend({ role: OrgRoleSchema });
|
|
1183
|
-
var OrgMemberSchema =
|
|
1184
|
-
username:
|
|
1185
|
-
name:
|
|
1295
|
+
var OrgMemberSchema = z2.object({
|
|
1296
|
+
username: z2.string(),
|
|
1297
|
+
name: z2.string(),
|
|
1186
1298
|
role: OrgRoleSchema,
|
|
1187
|
-
addedAt:
|
|
1299
|
+
addedAt: z2.string()
|
|
1188
1300
|
});
|
|
1189
|
-
var OrgDetailSchema = CloudOrgSchema.extend({ members:
|
|
1190
|
-
var CreateOrgRequestSchema =
|
|
1191
|
-
slug:
|
|
1192
|
-
name:
|
|
1301
|
+
var OrgDetailSchema = CloudOrgSchema.extend({ members: z2.array(OrgMemberSchema) });
|
|
1302
|
+
var CreateOrgRequestSchema = z2.object({
|
|
1303
|
+
slug: z2.string().min(1),
|
|
1304
|
+
name: z2.string().min(1)
|
|
1193
1305
|
});
|
|
1194
|
-
var RenameOrgRequestSchema =
|
|
1195
|
-
var AddMemberRequestSchema =
|
|
1196
|
-
username:
|
|
1306
|
+
var RenameOrgRequestSchema = z2.object({ name: z2.string().min(1) });
|
|
1307
|
+
var AddMemberRequestSchema = z2.object({
|
|
1308
|
+
username: z2.string().min(1),
|
|
1197
1309
|
role: OrgRoleSchema.default("member")
|
|
1198
1310
|
});
|
|
1199
|
-
var SetRoleRequestSchema =
|
|
1200
|
-
var MeResponseSchema = CloudUserSchema.extend({ orgs:
|
|
1201
|
-
var BalanceSchema =
|
|
1202
|
-
slug:
|
|
1203
|
-
balance:
|
|
1204
|
-
currency:
|
|
1205
|
-
topUps:
|
|
1206
|
-
spent:
|
|
1311
|
+
var SetRoleRequestSchema = z2.object({ role: OrgRoleSchema });
|
|
1312
|
+
var MeResponseSchema = CloudUserSchema.extend({ orgs: z2.array(OrgMembershipSchema) });
|
|
1313
|
+
var BalanceSchema = z2.object({
|
|
1314
|
+
slug: z2.string(),
|
|
1315
|
+
balance: z2.number(),
|
|
1316
|
+
currency: z2.string(),
|
|
1317
|
+
topUps: z2.number(),
|
|
1318
|
+
spent: z2.number(),
|
|
1207
1319
|
/** The first moment usage counts from: the slug's first top-up or redeemed code; null when it has none. */
|
|
1208
|
-
since:
|
|
1320
|
+
since: z2.string().nullable(),
|
|
1209
1321
|
/** When the slug ran out and its boxes were hibernated (the `sweep-credit` job); null in good standing. Absent from a control plane older than this field. */
|
|
1210
|
-
suspendedAt:
|
|
1322
|
+
suspendedAt: z2.string().nullable().default(null),
|
|
1211
1323
|
/** Promo credit left (#163), already counted in `balance`; 0 with none. Absent from a control plane older than this field. */
|
|
1212
|
-
promo:
|
|
1324
|
+
promo: z2.number().default(0),
|
|
1213
1325
|
/** When the next promo credit expires; null with none left. */
|
|
1214
|
-
promoExpiresAt:
|
|
1326
|
+
promoExpiresAt: z2.string().nullable().default(null)
|
|
1215
1327
|
});
|
|
1216
|
-
var TopUpRequestSchema =
|
|
1217
|
-
slug:
|
|
1328
|
+
var TopUpRequestSchema = z2.object({
|
|
1329
|
+
slug: z2.string().min(1),
|
|
1218
1330
|
/** In the control plane's currency; negative corrects a mistake. */
|
|
1219
|
-
amount:
|
|
1220
|
-
note:
|
|
1221
|
-
});
|
|
1222
|
-
var TopUpSchema =
|
|
1223
|
-
id:
|
|
1224
|
-
slug:
|
|
1225
|
-
amount:
|
|
1226
|
-
currency:
|
|
1331
|
+
amount: z2.number().finite(),
|
|
1332
|
+
note: z2.string().max(200).optional()
|
|
1333
|
+
});
|
|
1334
|
+
var TopUpSchema = z2.object({
|
|
1335
|
+
id: z2.string(),
|
|
1336
|
+
slug: z2.string(),
|
|
1337
|
+
amount: z2.number(),
|
|
1338
|
+
currency: z2.string(),
|
|
1227
1339
|
/** `transfer` (#93): an owner moving credit to an org they own, a negative row on their slug and a positive one on the org's. */
|
|
1228
|
-
source:
|
|
1229
|
-
note:
|
|
1230
|
-
at:
|
|
1340
|
+
source: z2.enum(["admin", "card", "trial", "transfer"]),
|
|
1341
|
+
note: z2.string().nullable(),
|
|
1342
|
+
at: z2.string()
|
|
1231
1343
|
});
|
|
1232
|
-
var CreateCodeRequestSchema =
|
|
1344
|
+
var CreateCodeRequestSchema = z2.object({
|
|
1233
1345
|
/** In the control plane's currency, cents at most. */
|
|
1234
|
-
amount:
|
|
1346
|
+
amount: z2.number().positive().multipleOf(0.01, "amount is in cents at most"),
|
|
1235
1347
|
/** A day (`2026-12-11`, through the end of it, UTC) or an ISO time. The credit is gone then, and so is the code. */
|
|
1236
|
-
expiresAt:
|
|
1237
|
-
note:
|
|
1238
|
-
});
|
|
1239
|
-
var CreditCodeSchema =
|
|
1240
|
-
code:
|
|
1241
|
-
amount:
|
|
1242
|
-
currency:
|
|
1243
|
-
expiresAt:
|
|
1244
|
-
note:
|
|
1245
|
-
status:
|
|
1246
|
-
createdBy:
|
|
1247
|
-
createdAt:
|
|
1348
|
+
expiresAt: z2.string().min(1),
|
|
1349
|
+
note: z2.string().max(200).optional()
|
|
1350
|
+
});
|
|
1351
|
+
var CreditCodeSchema = z2.object({
|
|
1352
|
+
code: z2.string(),
|
|
1353
|
+
amount: z2.number(),
|
|
1354
|
+
currency: z2.string(),
|
|
1355
|
+
expiresAt: z2.string(),
|
|
1356
|
+
note: z2.string().nullable(),
|
|
1357
|
+
status: z2.enum(["unused", "redeemed", "expired", "revoked"]),
|
|
1358
|
+
createdBy: z2.string(),
|
|
1359
|
+
createdAt: z2.string(),
|
|
1248
1360
|
/** Who redeemed it and the slug the credit went to (their own, or an org they own). */
|
|
1249
|
-
redeemedBy:
|
|
1250
|
-
redeemedSlug:
|
|
1251
|
-
redeemedAt:
|
|
1252
|
-
revokedAt:
|
|
1253
|
-
});
|
|
1254
|
-
var RedeemRequestSchema =
|
|
1255
|
-
code:
|
|
1256
|
-
org:
|
|
1257
|
-
});
|
|
1258
|
-
var RedeemResponseSchema =
|
|
1259
|
-
slug:
|
|
1260
|
-
amount:
|
|
1261
|
-
currency:
|
|
1262
|
-
expiresAt:
|
|
1361
|
+
redeemedBy: z2.string().nullable(),
|
|
1362
|
+
redeemedSlug: z2.string().nullable(),
|
|
1363
|
+
redeemedAt: z2.string().nullable(),
|
|
1364
|
+
revokedAt: z2.string().nullable()
|
|
1365
|
+
});
|
|
1366
|
+
var RedeemRequestSchema = z2.object({
|
|
1367
|
+
code: z2.string().min(1).max(64),
|
|
1368
|
+
org: z2.string().min(1).optional()
|
|
1369
|
+
});
|
|
1370
|
+
var RedeemResponseSchema = z2.object({
|
|
1371
|
+
slug: z2.string(),
|
|
1372
|
+
amount: z2.number(),
|
|
1373
|
+
currency: z2.string(),
|
|
1374
|
+
expiresAt: z2.string(),
|
|
1263
1375
|
balance: BalanceSchema,
|
|
1264
1376
|
/** The slug was out of credit and this put it back above zero: it may start boxes again. */
|
|
1265
|
-
reinstated:
|
|
1377
|
+
reinstated: z2.boolean()
|
|
1266
1378
|
});
|
|
1267
1379
|
var TOP_UP_AMOUNTS = [10, 25, 50, 100];
|
|
1268
|
-
var BillingInfoSchema =
|
|
1269
|
-
card:
|
|
1270
|
-
cardInUse:
|
|
1380
|
+
var BillingInfoSchema = z2.object({
|
|
1381
|
+
card: z2.object({ brand: z2.string(), last4: z2.string() }).nullable(),
|
|
1382
|
+
cardInUse: z2.boolean(),
|
|
1271
1383
|
balance: BalanceSchema
|
|
1272
1384
|
});
|
|
1273
|
-
var BillingRedirectSchema =
|
|
1274
|
-
var TopUpCheckoutRequestSchema =
|
|
1275
|
-
amount:
|
|
1385
|
+
var BillingRedirectSchema = z2.object({ url: z2.string() });
|
|
1386
|
+
var TopUpCheckoutRequestSchema = z2.object({
|
|
1387
|
+
amount: z2.literal(TOP_UP_AMOUNTS)
|
|
1276
1388
|
});
|
|
1277
|
-
var TransferRequestSchema =
|
|
1278
|
-
org:
|
|
1279
|
-
amount:
|
|
1389
|
+
var TransferRequestSchema = z2.object({
|
|
1390
|
+
org: z2.string().min(1),
|
|
1391
|
+
amount: z2.number().positive().multipleOf(0.01, "amount is in cents at most")
|
|
1280
1392
|
});
|
|
1281
|
-
var TransferResponseSchema =
|
|
1282
|
-
var LoginRequestSchema =
|
|
1283
|
-
email:
|
|
1284
|
-
password:
|
|
1285
|
-
publicKey:
|
|
1393
|
+
var TransferResponseSchema = z2.object({ from: BalanceSchema, to: BalanceSchema, activated: z2.boolean() });
|
|
1394
|
+
var LoginRequestSchema = z2.object({
|
|
1395
|
+
email: z2.string().min(1),
|
|
1396
|
+
password: z2.string().min(1),
|
|
1397
|
+
publicKey: z2.string().optional()
|
|
1286
1398
|
});
|
|
1287
|
-
var SignupRequestSchema =
|
|
1288
|
-
username:
|
|
1289
|
-
name:
|
|
1290
|
-
email:
|
|
1291
|
-
password:
|
|
1399
|
+
var SignupRequestSchema = z2.object({
|
|
1400
|
+
username: z2.string().min(1),
|
|
1401
|
+
name: z2.string().min(1),
|
|
1402
|
+
email: z2.string().min(1),
|
|
1403
|
+
password: z2.string().min(1)
|
|
1292
1404
|
});
|
|
1293
|
-
var LoginResponseSchema =
|
|
1294
|
-
token:
|
|
1405
|
+
var LoginResponseSchema = z2.object({
|
|
1406
|
+
token: z2.string(),
|
|
1295
1407
|
user: CloudUserSchema,
|
|
1296
|
-
sshCert:
|
|
1297
|
-
sshCertExpires:
|
|
1408
|
+
sshCert: z2.string().optional(),
|
|
1409
|
+
sshCertExpires: z2.string().optional(),
|
|
1298
1410
|
/** Whose boxes the certificate opens: `<slug>@<realm>` for the user and each org they are in (orgs phase 4). */
|
|
1299
|
-
sshCertPrincipals:
|
|
1411
|
+
sshCertPrincipals: z2.array(z2.string()).optional()
|
|
1300
1412
|
});
|
|
1301
1413
|
var DEVICE_LOGIN_PICKUP_SEC = 60;
|
|
1302
|
-
var DeviceLoginRequestSchema =
|
|
1414
|
+
var DeviceLoginRequestSchema = z2.object({
|
|
1303
1415
|
// Capped: anyone may open a login, and the key is stored until it expires (an RSA-16384 key is ~2.8 KB).
|
|
1304
|
-
publicKey:
|
|
1305
|
-
hostname:
|
|
1306
|
-
});
|
|
1307
|
-
var DeviceLoginStartSchema =
|
|
1308
|
-
deviceCode:
|
|
1309
|
-
userCode:
|
|
1310
|
-
verifyUrl:
|
|
1311
|
-
expiresIn:
|
|
1312
|
-
interval:
|
|
1313
|
-
});
|
|
1314
|
-
var DeviceLoginPollRequestSchema =
|
|
1315
|
-
var DeviceLoginPollSchema =
|
|
1316
|
-
|
|
1317
|
-
LoginResponseSchema.extend({ status:
|
|
1416
|
+
publicKey: z2.string().max(16384).optional(),
|
|
1417
|
+
hostname: z2.string().max(255).optional()
|
|
1418
|
+
});
|
|
1419
|
+
var DeviceLoginStartSchema = z2.object({
|
|
1420
|
+
deviceCode: z2.string(),
|
|
1421
|
+
userCode: z2.string(),
|
|
1422
|
+
verifyUrl: z2.string(),
|
|
1423
|
+
expiresIn: z2.number(),
|
|
1424
|
+
interval: z2.number()
|
|
1425
|
+
});
|
|
1426
|
+
var DeviceLoginPollRequestSchema = z2.object({ deviceCode: z2.string().min(1) });
|
|
1427
|
+
var DeviceLoginPollSchema = z2.union([
|
|
1428
|
+
z2.object({ status: z2.enum(["pending", "slow_down", "refused", "expired"]) }),
|
|
1429
|
+
LoginResponseSchema.extend({ status: z2.literal("approved") })
|
|
1318
1430
|
]);
|
|
1319
|
-
var DeviceLoginInfoSchema =
|
|
1320
|
-
userCode:
|
|
1321
|
-
hostname:
|
|
1431
|
+
var DeviceLoginInfoSchema = z2.object({
|
|
1432
|
+
userCode: z2.string(),
|
|
1433
|
+
hostname: z2.string(),
|
|
1322
1434
|
/** The address the request came from; null when the control plane could not tell. */
|
|
1323
|
-
ip:
|
|
1324
|
-
createdAt:
|
|
1325
|
-
expiresAt:
|
|
1435
|
+
ip: z2.string().nullable(),
|
|
1436
|
+
createdAt: z2.string(),
|
|
1437
|
+
expiresAt: z2.string()
|
|
1326
1438
|
});
|
|
1327
1439
|
var DEFAULT_API_KEY_DAYS = 90;
|
|
1328
1440
|
var API_KEY_NAME_RE = /^[a-z0-9][a-z0-9._-]{0,31}$/;
|
|
1329
|
-
var ApiKeySchema =
|
|
1330
|
-
name:
|
|
1331
|
-
createdAt:
|
|
1441
|
+
var ApiKeySchema = z2.object({
|
|
1442
|
+
name: z2.string(),
|
|
1443
|
+
createdAt: z2.string(),
|
|
1332
1444
|
/** Last request made with it (ISO); null: never used. */
|
|
1333
|
-
lastUsedAt:
|
|
1445
|
+
lastUsedAt: z2.string().nullable(),
|
|
1334
1446
|
/** When it stops working (ISO); null: never. */
|
|
1335
|
-
expiresAt:
|
|
1447
|
+
expiresAt: z2.string().nullable()
|
|
1336
1448
|
});
|
|
1337
|
-
var CreateApiKeyRequestSchema =
|
|
1338
|
-
name:
|
|
1339
|
-
expiresAt:
|
|
1449
|
+
var CreateApiKeyRequestSchema = z2.object({
|
|
1450
|
+
name: z2.string().regex(API_KEY_NAME_RE, "a key's name is lowercase letters, digits, '.', '_' or '-' (up to 32 characters)"),
|
|
1451
|
+
expiresAt: z2.iso.datetime({ offset: true }).nullable().optional()
|
|
1340
1452
|
});
|
|
1341
|
-
var CreatedApiKeySchema = ApiKeySchema.extend({ key:
|
|
1342
|
-
var SshCertRequestSchema =
|
|
1343
|
-
publicKey:
|
|
1453
|
+
var CreatedApiKeySchema = ApiKeySchema.extend({ key: z2.string() });
|
|
1454
|
+
var SshCertRequestSchema = z2.object({
|
|
1455
|
+
publicKey: z2.string().min(1)
|
|
1344
1456
|
});
|
|
1345
|
-
var SshCertResponseSchema =
|
|
1346
|
-
cert:
|
|
1347
|
-
expires:
|
|
1348
|
-
principals:
|
|
1457
|
+
var SshCertResponseSchema = z2.object({
|
|
1458
|
+
cert: z2.string(),
|
|
1459
|
+
expires: z2.string(),
|
|
1460
|
+
principals: z2.array(z2.string())
|
|
1349
1461
|
});
|
|
1350
|
-
var SshCaResponseSchema =
|
|
1351
|
-
publicKey:
|
|
1462
|
+
var SshCaResponseSchema = z2.object({
|
|
1463
|
+
publicKey: z2.string(),
|
|
1352
1464
|
/** CAs replaced by `ca rotate` (#55), newest first; a box still holding one of these has not had `kvbox-server trust-ca` run on its host. */
|
|
1353
|
-
retired:
|
|
1465
|
+
retired: z2.array(z2.object({ publicKey: z2.string(), retiredAt: z2.string() })).optional()
|
|
1354
1466
|
});
|
|
1355
|
-
var HostSshCaResponseSchema =
|
|
1356
|
-
publicKey:
|
|
1467
|
+
var HostSshCaResponseSchema = z2.object({
|
|
1468
|
+
publicKey: z2.string()
|
|
1357
1469
|
});
|
|
1358
|
-
var CloudCaSchema =
|
|
1359
|
-
controlPlane:
|
|
1360
|
-
publicKey:
|
|
1361
|
-
fingerprint:
|
|
1470
|
+
var CloudCaSchema = z2.object({
|
|
1471
|
+
controlPlane: z2.string(),
|
|
1472
|
+
publicKey: z2.string(),
|
|
1473
|
+
fingerprint: z2.string()
|
|
1362
1474
|
});
|
|
1363
|
-
var TrustCaRequestSchema =
|
|
1364
|
-
publicKey:
|
|
1475
|
+
var TrustCaRequestSchema = z2.object({
|
|
1476
|
+
publicKey: z2.string().min(1)
|
|
1365
1477
|
});
|
|
1366
|
-
var SshKeysAppliedSchema =
|
|
1367
|
-
var TrustCaReportSchema =
|
|
1368
|
-
publicKey:
|
|
1369
|
-
fingerprint:
|
|
1478
|
+
var SshKeysAppliedSchema = z2.enum(["now", "start", "wake", "resume", "later"]);
|
|
1479
|
+
var TrustCaReportSchema = z2.object({
|
|
1480
|
+
publicKey: z2.string(),
|
|
1481
|
+
fingerprint: z2.string(),
|
|
1370
1482
|
/** The guest trusts the CA now. */
|
|
1371
|
-
updated:
|
|
1483
|
+
updated: z2.array(z2.string()),
|
|
1372
1484
|
/** meta.json has the line; the guest gets it at `when`. */
|
|
1373
|
-
pending:
|
|
1374
|
-
failed:
|
|
1485
|
+
pending: z2.array(z2.object({ box: z2.string(), when: SshKeysAppliedSchema, why: z2.string().optional() })),
|
|
1486
|
+
failed: z2.array(z2.object({ box: z2.string(), error: z2.string() })),
|
|
1375
1487
|
/** Local boxes, untouched: they trust the host's key only. */
|
|
1376
|
-
local:
|
|
1488
|
+
local: z2.number().int(),
|
|
1377
1489
|
/** Cloud boxes made without a CA line (a managed service's, #173), untouched: no certificate opens them. Absent from older servers. */
|
|
1378
|
-
skipped:
|
|
1379
|
-
});
|
|
1380
|
-
var HostJoinRequestSchema =
|
|
1381
|
-
token:
|
|
1382
|
-
name:
|
|
1383
|
-
url:
|
|
1384
|
-
fingerprint:
|
|
1385
|
-
publicAddress:
|
|
1490
|
+
skipped: z2.array(z2.string()).optional()
|
|
1491
|
+
});
|
|
1492
|
+
var HostJoinRequestSchema = z2.object({
|
|
1493
|
+
token: z2.string().min(1),
|
|
1494
|
+
name: z2.string().min(1),
|
|
1495
|
+
url: z2.string().url(),
|
|
1496
|
+
fingerprint: z2.string().regex(/^([0-9A-F]{2}:){31}[0-9A-F]{2}$/),
|
|
1497
|
+
publicAddress: z2.string().min(1),
|
|
1386
1498
|
/** Where the host is (`kvbox-server join --country`): a code or an English name. */
|
|
1387
|
-
country:
|
|
1388
|
-
});
|
|
1389
|
-
var HostJoinResponseSchema =
|
|
1390
|
-
hostSecret:
|
|
1391
|
-
controlPlane:
|
|
1392
|
-
});
|
|
1393
|
-
var CloudHostSchema =
|
|
1394
|
-
name:
|
|
1395
|
-
url:
|
|
1396
|
-
publicAddress:
|
|
1397
|
-
joinedAt:
|
|
1398
|
-
lastSeenAt:
|
|
1499
|
+
country: z2.string().optional()
|
|
1500
|
+
});
|
|
1501
|
+
var HostJoinResponseSchema = z2.object({
|
|
1502
|
+
hostSecret: z2.string(),
|
|
1503
|
+
controlPlane: z2.object({ name: z2.string() })
|
|
1504
|
+
});
|
|
1505
|
+
var CloudHostSchema = z2.object({
|
|
1506
|
+
name: z2.string(),
|
|
1507
|
+
url: z2.string(),
|
|
1508
|
+
publicAddress: z2.string(),
|
|
1509
|
+
joinedAt: z2.string(),
|
|
1510
|
+
lastSeenAt: z2.string().nullable(),
|
|
1399
1511
|
capacity: CapacitySchema.nullable(),
|
|
1400
1512
|
/** ISO 3166-1 alpha-2 code (`RO`), null when nobody said where the host is. */
|
|
1401
|
-
country:
|
|
1513
|
+
country: z2.string().nullable(),
|
|
1402
1514
|
/** The S3 region a storage made on this host answers to (`ro-west-1`); null: it takes no storage. */
|
|
1403
|
-
region:
|
|
1515
|
+
region: z2.string().nullable(),
|
|
1404
1516
|
/** kvbox-server's version as of the poller's last look (`capacity.version`); null before one, or for a server older than 0.5.45. */
|
|
1405
|
-
version:
|
|
1517
|
+
version: z2.string().nullable()
|
|
1406
1518
|
});
|
|
1407
|
-
var HostInfoSchema =
|
|
1519
|
+
var HostInfoSchema = z2.object({
|
|
1408
1520
|
host: CloudHostSchema,
|
|
1409
1521
|
health: HealthSchema.nullable(),
|
|
1410
|
-
error:
|
|
1522
|
+
error: z2.string().nullable()
|
|
1411
1523
|
});
|
|
1412
|
-
var HostPatchRequest =
|
|
1413
|
-
var CountrySchema =
|
|
1524
|
+
var HostPatchRequest = z2.object({ country: z2.string().nullable().optional(), region: z2.string().nullable().optional() }).refine((b) => b.country !== void 0 || b.region !== void 0, { message: "give country, region or both" });
|
|
1525
|
+
var CountrySchema = z2.object({ code: z2.string(), name: z2.string() });
|
|
1414
1526
|
|
|
1415
1527
|
// src/session.ts
|
|
1416
|
-
var SessionSchema =
|
|
1417
|
-
url:
|
|
1418
|
-
token:
|
|
1419
|
-
user:
|
|
1528
|
+
var SessionSchema = z3.object({
|
|
1529
|
+
url: z3.string(),
|
|
1530
|
+
token: z3.string(),
|
|
1531
|
+
user: z3.string(),
|
|
1420
1532
|
/** When the SSH certificate at paths().sshCert stops being accepted (ISO); absent before the first login with a key. */
|
|
1421
|
-
sshCertExpires:
|
|
1533
|
+
sshCertExpires: z3.string().optional(),
|
|
1422
1534
|
/** Whose boxes that certificate opens (`<slug>@<realm>`, the user and their orgs); absent with `sshCertExpires`. */
|
|
1423
|
-
sshCertPrincipals:
|
|
1535
|
+
sshCertPrincipals: z3.array(z3.string()).optional()
|
|
1424
1536
|
});
|
|
1425
1537
|
async function readSession(p = paths()) {
|
|
1426
1538
|
let text2;
|
|
@@ -1599,7 +1711,7 @@ import { setTimeout as sleep2 } from "timers/promises";
|
|
|
1599
1711
|
import { Agent, request } from "undici";
|
|
1600
1712
|
|
|
1601
1713
|
// ../sdk/src/machines.ts
|
|
1602
|
-
import { z as
|
|
1714
|
+
import { z as z4 } from "zod";
|
|
1603
1715
|
|
|
1604
1716
|
// ../sdk/src/errors.ts
|
|
1605
1717
|
var KvboxSdkError = class extends Error {
|
|
@@ -1696,6 +1808,7 @@ var FORK_TIMEOUT_MS = 66e4;
|
|
|
1696
1808
|
var listQuery = (opts) => opts.all ? "?all=1" : "";
|
|
1697
1809
|
var box = (name, rest = "") => `/machines/${encodeURIComponent(name)}${rest}`;
|
|
1698
1810
|
var sleep = (ms) => new Promise((resolve4) => setTimeout(resolve4, ms));
|
|
1811
|
+
var FROM_BACKUP_TIMEOUT_MS = 2 * 36e5;
|
|
1699
1812
|
var passing = (err) => err instanceof KvboxConnectionError || err instanceof KvboxTimeoutError || err instanceof KvboxApiError && [502, 503, 504].includes(err.status);
|
|
1700
1813
|
var Machines = class {
|
|
1701
1814
|
constructor(transport) {
|
|
@@ -1710,7 +1823,7 @@ var Machines = class {
|
|
|
1710
1823
|
ports;
|
|
1711
1824
|
/** Every box the caller can read (their own and their orgs'), sorted by owner then name. */
|
|
1712
1825
|
list(opts = {}) {
|
|
1713
|
-
return this.transport.request("GET", `/machines${listQuery(opts)}`,
|
|
1826
|
+
return this.transport.request("GET", `/machines${listQuery(opts)}`, z4.array(MachineSchema), { org: opts.org });
|
|
1714
1827
|
}
|
|
1715
1828
|
/**
|
|
1716
1829
|
* One box, found in the listing (the API has no route for a single box). `slug/name` looks in that
|
|
@@ -1724,7 +1837,7 @@ var Machines = class {
|
|
|
1724
1837
|
async find(name, orgOpt, timeoutMs) {
|
|
1725
1838
|
const slash = name.indexOf("/");
|
|
1726
1839
|
const [org, bare] = slash === -1 ? [orgOpt, name] : [name.slice(0, slash), name.slice(slash + 1)];
|
|
1727
|
-
const listing = await this.transport.request("GET", "/machines",
|
|
1840
|
+
const listing = await this.transport.request("GET", "/machines", z4.array(MachineSchema), { org, timeoutMs });
|
|
1728
1841
|
const named = listing.filter((m) => m.name === bare && (slash === -1 || slugOf2(m.owner) === org));
|
|
1729
1842
|
if (named.length <= 1) {
|
|
1730
1843
|
if (named[0] !== void 0) return named[0];
|
|
@@ -1739,13 +1852,26 @@ var Machines = class {
|
|
|
1739
1852
|
* system inside is still booting for a few seconds after (see `waitUntilReady`). A box from an
|
|
1740
1853
|
* image that serves something answers `connect` (its URL with the password) this once.
|
|
1741
1854
|
* `org` (this call's, else the client's): the new box goes to that org, else to the caller's own slug.
|
|
1855
|
+
* `fromBackup` (a backup's id, a removed box's too) starts it on that backup's disk, image and variables;
|
|
1856
|
+
* the answer then waits for the download, up to two hours.
|
|
1742
1857
|
*/
|
|
1743
|
-
create(req = {}, opts = {}) {
|
|
1744
|
-
|
|
1858
|
+
async create(req = {}, opts = {}) {
|
|
1859
|
+
const made = await this.transport.request("POST", "/machines", MachineSchema, { body: req, org: opts.org, ...req.fromBackup !== void 0 ? { timeoutMs: FROM_BACKUP_TIMEOUT_MS } : {} });
|
|
1860
|
+
if (req.fromBackup !== void 0 && !made.source.startsWith("backup:")) {
|
|
1861
|
+
throw new KvboxSdkError(`this API does not know fromBackup yet: box ${slugOf2(made.owner)}/${made.name} was made empty, not from backup ${req.fromBackup}; remove it`);
|
|
1862
|
+
}
|
|
1863
|
+
return made;
|
|
1864
|
+
}
|
|
1865
|
+
/**
|
|
1866
|
+
* Change a box's settings; anything left out stays as it is. `integrations` is the whole list of
|
|
1867
|
+
* integrations turned on for the box (`["github"]`, `[]` for none): it applies at once, with no restart.
|
|
1868
|
+
*/
|
|
1869
|
+
set(name, settings, opts = {}) {
|
|
1870
|
+
return this.transport.request("POST", box(name, "/set"), MachineSchema, { body: settings, org: opts.org });
|
|
1745
1871
|
}
|
|
1746
1872
|
/** Remove the box and its disk. */
|
|
1747
1873
|
async remove(name, opts = {}) {
|
|
1748
|
-
await this.transport.request("DELETE", box(name),
|
|
1874
|
+
await this.transport.request("DELETE", box(name), z4.undefined(), { org: opts.org });
|
|
1749
1875
|
}
|
|
1750
1876
|
/** Boot a stopped box. */
|
|
1751
1877
|
start(name, opts = {}) {
|
|
@@ -1895,7 +2021,7 @@ var slugOf2 = (owner) => {
|
|
|
1895
2021
|
};
|
|
1896
2022
|
|
|
1897
2023
|
// ../sdk/src/snapshots.ts
|
|
1898
|
-
import { z as
|
|
2024
|
+
import { z as z5 } from "zod";
|
|
1899
2025
|
var Snapshots = class {
|
|
1900
2026
|
constructor(transport) {
|
|
1901
2027
|
this.transport = transport;
|
|
@@ -1903,19 +2029,19 @@ var Snapshots = class {
|
|
|
1903
2029
|
transport;
|
|
1904
2030
|
/** Every snapshot the caller can read. */
|
|
1905
2031
|
list(opts = {}) {
|
|
1906
|
-
return this.transport.request("GET", `/snapshots${listQuery(opts)}`,
|
|
2032
|
+
return this.transport.request("GET", `/snapshots${listQuery(opts)}`, z5.array(SnapshotSchema), { org: opts.org });
|
|
1907
2033
|
}
|
|
1908
2034
|
/** Snapshot box `req.box` as `req.name` (`replace`: retake one that exists). The box is paused while it is taken. */
|
|
1909
2035
|
create(req, opts = {}) {
|
|
1910
2036
|
return this.transport.request("POST", "/snapshots", SnapshotSchema, { body: req, org: opts.org });
|
|
1911
2037
|
}
|
|
1912
2038
|
async remove(name, opts = {}) {
|
|
1913
|
-
await this.transport.request("DELETE", `/snapshots/${encodeURIComponent(name)}`,
|
|
2039
|
+
await this.transport.request("DELETE", `/snapshots/${encodeURIComponent(name)}`, z5.undefined(), { org: opts.org });
|
|
1914
2040
|
}
|
|
1915
2041
|
};
|
|
1916
2042
|
|
|
1917
2043
|
// ../sdk/src/transport.ts
|
|
1918
|
-
import { z as
|
|
2044
|
+
import { z as z6 } from "zod";
|
|
1919
2045
|
var Transport = class {
|
|
1920
2046
|
baseUrl;
|
|
1921
2047
|
org;
|
|
@@ -1989,7 +2115,7 @@ var Transport = class {
|
|
|
1989
2115
|
}
|
|
1990
2116
|
}
|
|
1991
2117
|
};
|
|
1992
|
-
var LooseApiErrorSchema =
|
|
2118
|
+
var LooseApiErrorSchema = z6.object({ error: z6.string(), code: z6.string().optional() });
|
|
1993
2119
|
function safeJson(text2) {
|
|
1994
2120
|
try {
|
|
1995
2121
|
return JSON.parse(text2);
|
|
@@ -2006,8 +2132,21 @@ function errorCode(err) {
|
|
|
2006
2132
|
return void 0;
|
|
2007
2133
|
}
|
|
2008
2134
|
|
|
2135
|
+
// ../sdk/src/integrations.ts
|
|
2136
|
+
import { z as z7 } from "zod";
|
|
2137
|
+
var Integrations = class {
|
|
2138
|
+
constructor(transport) {
|
|
2139
|
+
this.transport = transport;
|
|
2140
|
+
}
|
|
2141
|
+
transport;
|
|
2142
|
+
/** Each readable slug's state for each integration (`org`: one org's), connected or not; never a credential. */
|
|
2143
|
+
list(opts = {}) {
|
|
2144
|
+
return this.transport.request("GET", "/integrations", z7.array(IntegrationSchema), { org: opts.org });
|
|
2145
|
+
}
|
|
2146
|
+
};
|
|
2147
|
+
|
|
2009
2148
|
// ../sdk/src/volumes.ts
|
|
2010
|
-
import { z as
|
|
2149
|
+
import { z as z8 } from "zod";
|
|
2011
2150
|
var volume = (name, rest = "") => `/volumes/${encodeURIComponent(name)}${rest}`;
|
|
2012
2151
|
var Volumes = class {
|
|
2013
2152
|
constructor(transport) {
|
|
@@ -2015,7 +2154,7 @@ var Volumes = class {
|
|
|
2015
2154
|
}
|
|
2016
2155
|
transport;
|
|
2017
2156
|
list(opts = {}) {
|
|
2018
|
-
return this.transport.request("GET", `/volumes${listQuery(opts)}`,
|
|
2157
|
+
return this.transport.request("GET", `/volumes${listQuery(opts)}`, z8.array(VolumeSchema), { org: opts.org });
|
|
2019
2158
|
}
|
|
2020
2159
|
/**
|
|
2021
2160
|
* Make a volume of `sizeGib` GiB. Through the cloud `box` is required: the volume is made on that
|
|
@@ -2038,7 +2177,7 @@ var Volumes = class {
|
|
|
2038
2177
|
}
|
|
2039
2178
|
/** Remove the volume and its data; it must be detached first. */
|
|
2040
2179
|
async remove(name, opts = {}) {
|
|
2041
|
-
await this.transport.request("DELETE", volume(name),
|
|
2180
|
+
await this.transport.request("DELETE", volume(name), z8.undefined(), { org: opts.org });
|
|
2042
2181
|
}
|
|
2043
2182
|
};
|
|
2044
2183
|
|
|
@@ -2059,6 +2198,7 @@ var Kvbox = class {
|
|
|
2059
2198
|
machines;
|
|
2060
2199
|
snapshots;
|
|
2061
2200
|
volumes;
|
|
2201
|
+
integrations;
|
|
2062
2202
|
transport;
|
|
2063
2203
|
constructor(opts = {}) {
|
|
2064
2204
|
this.transport = new Transport({
|
|
@@ -2071,6 +2211,7 @@ var Kvbox = class {
|
|
|
2071
2211
|
this.machines = new Machines(this.transport);
|
|
2072
2212
|
this.snapshots = new Snapshots(this.transport);
|
|
2073
2213
|
this.volumes = new Volumes(this.transport);
|
|
2214
|
+
this.integrations = new Integrations(this.transport);
|
|
2074
2215
|
}
|
|
2075
2216
|
/** The API this client talks to, without a trailing slash. */
|
|
2076
2217
|
get baseUrl() {
|
|
@@ -2086,35 +2227,35 @@ var Kvbox = class {
|
|
|
2086
2227
|
};
|
|
2087
2228
|
|
|
2088
2229
|
// src/client.ts
|
|
2089
|
-
import { z as
|
|
2230
|
+
import { z as z13 } from "zod";
|
|
2090
2231
|
|
|
2091
2232
|
// ../shared/src/usage.ts
|
|
2092
|
-
import { z as
|
|
2093
|
-
var PricingSchema =
|
|
2094
|
-
currency:
|
|
2095
|
-
vcpuHour:
|
|
2096
|
-
ramGibHour:
|
|
2097
|
-
diskGibHour:
|
|
2098
|
-
volumeHour:
|
|
2099
|
-
volumeGibHour:
|
|
2100
|
-
diskIncludedGib:
|
|
2233
|
+
import { z as z9 } from "zod";
|
|
2234
|
+
var PricingSchema = z9.object({
|
|
2235
|
+
currency: z9.string().min(1),
|
|
2236
|
+
vcpuHour: z9.number().nonnegative(),
|
|
2237
|
+
ramGibHour: z9.number().nonnegative(),
|
|
2238
|
+
diskGibHour: z9.number().nonnegative(),
|
|
2239
|
+
volumeHour: z9.number().nonnegative().default(0),
|
|
2240
|
+
volumeGibHour: z9.number().nonnegative().default(0),
|
|
2241
|
+
diskIncludedGib: z9.number().int().nonnegative().default(0),
|
|
2101
2242
|
/**
|
|
2102
2243
|
* Object storage (#182): an hour of a slug's storage existing, whatever it holds, which covers its
|
|
2103
2244
|
* hidden box and the first `storageIncludedGib` of its size; each GiB above that is `storageGibHour`.
|
|
2104
2245
|
* A price list from before object storage charges nothing for it.
|
|
2105
2246
|
*/
|
|
2106
|
-
storageHour:
|
|
2107
|
-
storageGibHour:
|
|
2108
|
-
storageIncludedGib:
|
|
2247
|
+
storageHour: z9.number().nonnegative().default(0),
|
|
2248
|
+
storageGibHour: z9.number().nonnegative().default(0),
|
|
2249
|
+
storageIncludedGib: z9.number().int().nonnegative().default(0),
|
|
2109
2250
|
/** The cron service (#190): an hour of one cron service existing, whatever it holds or fires. A price list from before it charges nothing. */
|
|
2110
|
-
cronHour:
|
|
2251
|
+
cronHour: z9.number().nonnegative().default(0),
|
|
2111
2252
|
/**
|
|
2112
2253
|
* One backup a person starts, of anything, charged once it is ready (decision "A backup taken by hand
|
|
2113
2254
|
* costs a flat price…"); a failed one and a scheduled one cost nothing. A price list from before it charges nothing.
|
|
2114
2255
|
*/
|
|
2115
|
-
backup:
|
|
2256
|
+
backup: z9.number().nonnegative().default(0)
|
|
2116
2257
|
});
|
|
2117
|
-
var PriceListSchema = PricingSchema.extend({ welcomeCredit:
|
|
2258
|
+
var PriceListSchema = PricingSchema.extend({ welcomeCredit: z9.number().nonnegative() });
|
|
2118
2259
|
var HOUR_MS = 36e5;
|
|
2119
2260
|
var round = (n, places) => Math.round(n * 10 ** places) / 10 ** places;
|
|
2120
2261
|
function costOf(t, pricing) {
|
|
@@ -2142,86 +2283,86 @@ function sumUsage(items, pricing) {
|
|
|
2142
2283
|
var DAY_MS = 24 * HOUR_MS;
|
|
2143
2284
|
|
|
2144
2285
|
// ../shared/src/managed.ts
|
|
2145
|
-
import { z as
|
|
2146
|
-
var PriceSchema =
|
|
2147
|
-
var ManagedCatalogEntrySchema =
|
|
2286
|
+
import { z as z10 } from "zod";
|
|
2287
|
+
var PriceSchema = z10.object({ perMonth: z10.number(), storagePerMonth: z10.number(), currency: z10.string() });
|
|
2288
|
+
var ManagedCatalogEntrySchema = z10.object({
|
|
2148
2289
|
/** The kind, as in `/managed/<kind>`: `postgres`. */
|
|
2149
|
-
kind:
|
|
2290
|
+
kind: z10.string(),
|
|
2150
2291
|
/** The CLI command for it: `pg` (`kvbox pg create …`). */
|
|
2151
|
-
command:
|
|
2152
|
-
title:
|
|
2153
|
-
description:
|
|
2292
|
+
command: z10.string(),
|
|
2293
|
+
title: z10.string(),
|
|
2294
|
+
description: z10.string(),
|
|
2154
2295
|
/** The version a new one runs, as shown: `18`. */
|
|
2155
|
-
version:
|
|
2296
|
+
version: z10.string(),
|
|
2156
2297
|
/** The port a linked box reaches it on. */
|
|
2157
|
-
port:
|
|
2298
|
+
port: z10.number().int(),
|
|
2158
2299
|
/** The port `public on` opens behind a host port: `port` again unless the kind serves TLS on another. */
|
|
2159
|
-
publicPort:
|
|
2300
|
+
publicPort: z10.number().int(),
|
|
2160
2301
|
/** Its guide, as a URL. */
|
|
2161
|
-
docs:
|
|
2162
|
-
storage:
|
|
2302
|
+
docs: z10.string().optional(),
|
|
2303
|
+
storage: z10.object({ defaultGib: z10.number().int(), minGib: z10.number().int(), maxGib: z10.number().int() }),
|
|
2163
2304
|
/**
|
|
2164
2305
|
* What create takes of this kind alone, beside what every kind takes (name, password, storage, near): a
|
|
2165
2306
|
* flag and a form field each, all optional, `default` in words.
|
|
2166
2307
|
*/
|
|
2167
|
-
options:
|
|
2308
|
+
options: z10.array(z10.object({ name: z10.string(), title: z10.string(), description: z10.string(), default: z10.string() })),
|
|
2168
2309
|
/** A month of it running with the default storage, and each further GB of storage. */
|
|
2169
|
-
price: PriceSchema.extend({ storageGibPerMonth:
|
|
2310
|
+
price: PriceSchema.extend({ storageGibPerMonth: z10.number() }),
|
|
2170
2311
|
/** Whether a host answering now can run it. */
|
|
2171
|
-
available:
|
|
2312
|
+
available: z10.boolean()
|
|
2172
2313
|
});
|
|
2173
|
-
var CreateManagedRequest =
|
|
2174
|
-
name:
|
|
2314
|
+
var CreateManagedRequest = z10.object({
|
|
2315
|
+
name: z10.string(),
|
|
2175
2316
|
/** The kind's own options by name (its catalog entry lists them); the kind checks them. */
|
|
2176
|
-
options:
|
|
2177
|
-
password:
|
|
2178
|
-
storageGib:
|
|
2317
|
+
options: z10.record(z10.string(), z10.string()).optional(),
|
|
2318
|
+
password: z10.string().optional(),
|
|
2319
|
+
storageGib: z10.number().int().optional(),
|
|
2179
2320
|
/** Place it on the host of this box, so the box can be linked to it. */
|
|
2180
|
-
near:
|
|
2321
|
+
near: z10.string().optional(),
|
|
2181
2322
|
/**
|
|
2182
2323
|
* A backup of a database of the same kind and major version, of the same account (#186): the new
|
|
2183
2324
|
* service starts on its data, a removed service's included. Its settings (Postgres: database, user)
|
|
2184
2325
|
* are the backup's; the password is the new one.
|
|
2185
2326
|
*/
|
|
2186
|
-
fromBackup:
|
|
2327
|
+
fromBackup: z10.string().optional()
|
|
2187
2328
|
});
|
|
2188
|
-
var ManagedHealthSchema =
|
|
2329
|
+
var ManagedHealthSchema = z10.object({
|
|
2189
2330
|
/** Its first start has finished: it has set itself up on its storage. */
|
|
2190
|
-
ready:
|
|
2331
|
+
ready: z10.boolean(),
|
|
2191
2332
|
/** It accepts connections. */
|
|
2192
|
-
accepting:
|
|
2193
|
-
version:
|
|
2333
|
+
accepting: z10.boolean(),
|
|
2334
|
+
version: z10.string(),
|
|
2194
2335
|
/** The storage volume: what is used of it and its size. */
|
|
2195
|
-
storageUsedBytes:
|
|
2196
|
-
storageTotalBytes:
|
|
2336
|
+
storageUsedBytes: z10.number().optional(),
|
|
2337
|
+
storageTotalBytes: z10.number().optional(),
|
|
2197
2338
|
/** What else the kind reports, ready to show: `{title: "Connections", value: "3"}`. */
|
|
2198
|
-
facts:
|
|
2339
|
+
facts: z10.array(z10.object({ title: z10.string(), value: z10.string() }))
|
|
2199
2340
|
});
|
|
2200
|
-
var UrlsSchema =
|
|
2201
|
-
var ManagedSchema =
|
|
2202
|
-
kind:
|
|
2203
|
-
name:
|
|
2341
|
+
var UrlsSchema = z10.object({ private: z10.string(), public: z10.string().optional() });
|
|
2342
|
+
var ManagedSchema = z10.object({
|
|
2343
|
+
kind: z10.string(),
|
|
2344
|
+
name: z10.string(),
|
|
2204
2345
|
/** The owning slug, bare. */
|
|
2205
|
-
owner:
|
|
2206
|
-
ownerKind:
|
|
2346
|
+
owner: z10.string(),
|
|
2347
|
+
ownerKind: z10.enum(["user", "org"]),
|
|
2207
2348
|
/** `running`, `stopped` (storage only is charged), `hibernated` or `standby` (out of credit), `unknown` (its host does not answer). */
|
|
2208
2349
|
status: BoxStatusSchema,
|
|
2209
2350
|
/** The catalog version: `18`. */
|
|
2210
|
-
version:
|
|
2351
|
+
version: z10.string(),
|
|
2211
2352
|
/** What the kind keeps of its create options, defaults filled in: `{database, user}` for Postgres, `{}` for a kind with none. */
|
|
2212
|
-
settings:
|
|
2213
|
-
storageGib:
|
|
2353
|
+
settings: z10.record(z10.string(), z10.string()),
|
|
2354
|
+
storageGib: z10.number().int(),
|
|
2214
2355
|
/** Where a linked box reaches it: `<name>.<slug>.kvbox` (resolves from a box of any slug it is linked to) and the port. */
|
|
2215
|
-
private:
|
|
2356
|
+
private: z10.object({ host: z10.string(), port: z10.number().int() }),
|
|
2216
2357
|
/** Where the internet reaches it, null while it is not public. The port is its own for its whole life. */
|
|
2217
|
-
public:
|
|
2358
|
+
public: z10.object({ host: z10.string(), port: z10.number().int() }).nullable(),
|
|
2218
2359
|
/** The boxes linked to it, as the caller would name them. */
|
|
2219
|
-
links:
|
|
2360
|
+
links: z10.array(z10.string()),
|
|
2220
2361
|
/** The name of the host it runs on, for `--near` and links. */
|
|
2221
|
-
host:
|
|
2222
|
-
country:
|
|
2223
|
-
createdBy:
|
|
2224
|
-
createdAt:
|
|
2362
|
+
host: z10.string(),
|
|
2363
|
+
country: z10.string().optional(),
|
|
2364
|
+
createdBy: z10.string().nullable(),
|
|
2365
|
+
createdAt: z10.string(),
|
|
2225
2366
|
/** Connection strings with the password as `****`. */
|
|
2226
2367
|
urls: UrlsSchema,
|
|
2227
2368
|
price: PriceSchema,
|
|
@@ -2230,226 +2371,230 @@ var ManagedSchema = z8.object({
|
|
|
2230
2371
|
/** Only in `GET /managed/<kind>/<name>` (asked live): null when it is not running or did not answer. */
|
|
2231
2372
|
health: ManagedHealthSchema.nullable().optional()
|
|
2232
2373
|
});
|
|
2233
|
-
var ManagedSecretSchema =
|
|
2374
|
+
var ManagedSecretSchema = z10.object({ password: z10.string(), urls: UrlsSchema });
|
|
2234
2375
|
var CreatedManagedSchema = ManagedSchema.extend({
|
|
2235
2376
|
secret: ManagedSecretSchema,
|
|
2236
2377
|
/** The backup it was made from (`fromBackup`), when it was. */
|
|
2237
|
-
fromBackup:
|
|
2238
|
-
});
|
|
2239
|
-
var ResetPasswordRequest =
|
|
2240
|
-
var SetPublicRequest =
|
|
2241
|
-
var ManagedLinkRequest =
|
|
2242
|
-
var GrowManagedRequest =
|
|
2243
|
-
var ManagedBackupSchema =
|
|
2244
|
-
id:
|
|
2245
|
-
owner:
|
|
2246
|
-
kind:
|
|
2247
|
-
name:
|
|
2248
|
-
version:
|
|
2249
|
-
status:
|
|
2378
|
+
fromBackup: z10.string().optional()
|
|
2379
|
+
});
|
|
2380
|
+
var ResetPasswordRequest = z10.object({ password: z10.string().optional() });
|
|
2381
|
+
var SetPublicRequest = z10.object({ on: z10.boolean() });
|
|
2382
|
+
var ManagedLinkRequest = z10.object({ box: z10.string() });
|
|
2383
|
+
var GrowManagedRequest = z10.object({ storageGib: z10.number().int() });
|
|
2384
|
+
var ManagedBackupSchema = z10.object({
|
|
2385
|
+
id: z10.string(),
|
|
2386
|
+
owner: z10.string(),
|
|
2387
|
+
kind: z10.string(),
|
|
2388
|
+
name: z10.string(),
|
|
2389
|
+
version: z10.string(),
|
|
2390
|
+
status: z10.enum(BACKUP_STATUSES),
|
|
2250
2391
|
/** Why it failed; null otherwise. */
|
|
2251
|
-
error:
|
|
2392
|
+
error: z10.string().nullable(),
|
|
2252
2393
|
/** The service's storage when taken. */
|
|
2253
|
-
diskBytes:
|
|
2394
|
+
diskBytes: z10.number().int().nullable(),
|
|
2254
2395
|
/** What it holds: the slots that are not all zeros. */
|
|
2255
|
-
dataBytes:
|
|
2396
|
+
dataBytes: z10.number().int().nullable(),
|
|
2256
2397
|
/** What this backup added to storage (encrypted, compressed): the chunks no earlier backup had. */
|
|
2257
|
-
uploadedBytes:
|
|
2398
|
+
uploadedBytes: z10.number().int().nullable(),
|
|
2258
2399
|
/** Who asked for it; for a scheduled one, the database's creator. */
|
|
2259
|
-
createdBy:
|
|
2400
|
+
createdBy: z10.string().nullable(),
|
|
2260
2401
|
/** Started by the database's backup schedule, not by a person: it does not count toward the daily limit. */
|
|
2261
|
-
scheduled:
|
|
2262
|
-
createdAt:
|
|
2263
|
-
finishedAt:
|
|
2402
|
+
scheduled: z10.boolean().default(false),
|
|
2403
|
+
createdAt: z10.string(),
|
|
2404
|
+
finishedAt: z10.string().nullable()
|
|
2264
2405
|
});
|
|
2265
2406
|
|
|
2266
2407
|
// ../shared/src/cron.ts
|
|
2267
|
-
import { z as
|
|
2408
|
+
import { z as z11 } from "zod";
|
|
2268
2409
|
var DEFAULT_CRON_COMMAND_TIMEOUT_SEC = 600;
|
|
2269
2410
|
var MAX_CRON_COMMAND_TIMEOUT_SEC = 3600;
|
|
2270
2411
|
var CRON_RUN_LOG_DIR = "/var/log/kvbox/runs";
|
|
2271
2412
|
var CRON_METHODS = ["GET", "POST"];
|
|
2272
2413
|
var CRON_OUTCOMES = ["running", "ok", "failed", "timeout", "no-credit", "box-stopped", "host-down", "host-outdated", "lost", "still-running", "box-outdated"];
|
|
2273
|
-
var CronServiceSchema =
|
|
2274
|
-
owner:
|
|
2275
|
-
ownerKind:
|
|
2276
|
-
name:
|
|
2414
|
+
var CronServiceSchema = z11.object({
|
|
2415
|
+
owner: z11.string(),
|
|
2416
|
+
ownerKind: z11.enum(["user", "org"]),
|
|
2417
|
+
name: z11.string(),
|
|
2277
2418
|
/** Runs kept per trigger. */
|
|
2278
|
-
keepRuns:
|
|
2279
|
-
triggers:
|
|
2280
|
-
createdBy:
|
|
2281
|
-
createdAt:
|
|
2419
|
+
keepRuns: z11.number().int(),
|
|
2420
|
+
triggers: z11.number().int(),
|
|
2421
|
+
createdBy: z11.string().nullable(),
|
|
2422
|
+
createdAt: z11.string(),
|
|
2282
2423
|
/** What it costs while it exists; on the answer to `POST /cron` only. */
|
|
2283
|
-
price:
|
|
2424
|
+
price: z11.object({ perMonth: z11.number(), currency: z11.string() }).optional()
|
|
2284
2425
|
});
|
|
2285
2426
|
var triggerCommon = {
|
|
2286
|
-
id:
|
|
2287
|
-
service:
|
|
2288
|
-
owner:
|
|
2427
|
+
id: z11.string(),
|
|
2428
|
+
service: z11.string(),
|
|
2429
|
+
owner: z11.string(),
|
|
2289
2430
|
/** The box it acts on; a trigger is removed with its box. */
|
|
2290
|
-
box:
|
|
2431
|
+
box: z11.string(),
|
|
2291
2432
|
/** Five fields, `minute hour day-of-month month day-of-week`. */
|
|
2292
|
-
expr:
|
|
2433
|
+
expr: z11.string(),
|
|
2293
2434
|
/** An IANA zone (`Europe/Bucharest`) the expression is read in; `UTC` unless said. */
|
|
2294
|
-
timezone:
|
|
2435
|
+
timezone: z11.string(),
|
|
2295
2436
|
/** False: paused, it fires again when resumed. */
|
|
2296
|
-
enabled:
|
|
2437
|
+
enabled: z11.boolean(),
|
|
2297
2438
|
/** When it fires next (ISO); null while paused. */
|
|
2298
|
-
nextRunAt:
|
|
2299
|
-
lastRunAt:
|
|
2300
|
-
lastOutcome:
|
|
2301
|
-
createdBy:
|
|
2302
|
-
createdAt:
|
|
2439
|
+
nextRunAt: z11.string().nullable(),
|
|
2440
|
+
lastRunAt: z11.string().nullable(),
|
|
2441
|
+
lastOutcome: z11.enum(CRON_OUTCOMES).nullable(),
|
|
2442
|
+
createdBy: z11.string().nullable(),
|
|
2443
|
+
createdAt: z11.string()
|
|
2303
2444
|
};
|
|
2304
|
-
var CronHttpTriggerSchema =
|
|
2445
|
+
var CronHttpTriggerSchema = z11.object({
|
|
2305
2446
|
...triggerCommon,
|
|
2306
|
-
kind:
|
|
2307
|
-
method:
|
|
2308
|
-
port:
|
|
2447
|
+
kind: z11.literal("http"),
|
|
2448
|
+
method: z11.enum(CRON_METHODS),
|
|
2449
|
+
port: z11.number().int(),
|
|
2309
2450
|
/** Path and query, starting with `/`. */
|
|
2310
|
-
path:
|
|
2451
|
+
path: z11.string()
|
|
2311
2452
|
});
|
|
2312
|
-
var CronCommandTriggerSchema =
|
|
2453
|
+
var CronCommandTriggerSchema = z11.object({
|
|
2313
2454
|
...triggerCommon,
|
|
2314
|
-
kind:
|
|
2455
|
+
kind: z11.literal("command"),
|
|
2315
2456
|
/** Run by a login shell as the box's user, in its home. */
|
|
2316
|
-
command:
|
|
2457
|
+
command: z11.string(),
|
|
2317
2458
|
/** The command is stopped after this long. */
|
|
2318
|
-
timeoutSec:
|
|
2459
|
+
timeoutSec: z11.number().int()
|
|
2319
2460
|
});
|
|
2320
|
-
var CronTriggerSchema =
|
|
2321
|
-
var CronRunSchema =
|
|
2461
|
+
var CronTriggerSchema = z11.discriminatedUnion("kind", [CronHttpTriggerSchema, CronCommandTriggerSchema]);
|
|
2462
|
+
var CronRunSchema = z11.object({
|
|
2322
2463
|
/** The slot this run was for (ISO); a run asked for by hand has the moment it was asked. */
|
|
2323
|
-
scheduledFor:
|
|
2324
|
-
startedAt:
|
|
2464
|
+
scheduledFor: z11.string(),
|
|
2465
|
+
startedAt: z11.string(),
|
|
2325
2466
|
/** Null while `running`, and for a run that was never sent. */
|
|
2326
|
-
durationMs:
|
|
2467
|
+
durationMs: z11.number().int().nullable(),
|
|
2327
2468
|
/** The box's HTTP status; null when it never answered, and for a command. */
|
|
2328
|
-
status:
|
|
2469
|
+
status: z11.number().int().nullable(),
|
|
2329
2470
|
/** A command's exit code (128 + the signal when one ended it); null until it ends, and for a request. */
|
|
2330
|
-
exitCode:
|
|
2471
|
+
exitCode: z11.number().int().nullable(),
|
|
2331
2472
|
/** The files in the box that hold what a command printed (a shell pattern, `cron-<n>.*`); null for a request and for a command that never started. */
|
|
2332
|
-
output:
|
|
2333
|
-
outcome:
|
|
2473
|
+
output: z11.string().nullable(),
|
|
2474
|
+
outcome: z11.enum(CRON_OUTCOMES),
|
|
2334
2475
|
/** Why it did not end `ok`, in a line. */
|
|
2335
|
-
error:
|
|
2476
|
+
error: z11.string().nullable(),
|
|
2336
2477
|
/** The box was hibernated and this run woke it. */
|
|
2337
|
-
woke:
|
|
2478
|
+
woke: z11.boolean()
|
|
2338
2479
|
});
|
|
2339
|
-
var CronCatalogSchema =
|
|
2340
|
-
price:
|
|
2341
|
-
maxServices:
|
|
2342
|
-
maxTriggers:
|
|
2343
|
-
keepRuns:
|
|
2480
|
+
var CronCatalogSchema = z11.object({
|
|
2481
|
+
price: z11.object({ perMonth: z11.number(), currency: z11.string() }),
|
|
2482
|
+
maxServices: z11.number().int(),
|
|
2483
|
+
maxTriggers: z11.number().int(),
|
|
2484
|
+
keepRuns: z11.number().int(),
|
|
2344
2485
|
/** The shortest time between two runs of one trigger, in seconds. */
|
|
2345
|
-
minIntervalSeconds:
|
|
2486
|
+
minIntervalSeconds: z11.number().int(),
|
|
2346
2487
|
/** How long a box has to answer, in seconds. */
|
|
2347
|
-
timeoutSeconds:
|
|
2488
|
+
timeoutSeconds: z11.number().int(),
|
|
2348
2489
|
/** How long a command may run: unless the trigger says, and at most. */
|
|
2349
|
-
commandTimeoutSeconds:
|
|
2350
|
-
maxCommandTimeoutSeconds:
|
|
2351
|
-
docs:
|
|
2352
|
-
});
|
|
2353
|
-
var CreateCronServiceRequest =
|
|
2354
|
-
var CreateCronTriggerRequest =
|
|
2355
|
-
box:
|
|
2356
|
-
expr:
|
|
2357
|
-
timezone:
|
|
2490
|
+
commandTimeoutSeconds: z11.number().int(),
|
|
2491
|
+
maxCommandTimeoutSeconds: z11.number().int(),
|
|
2492
|
+
docs: z11.string().optional()
|
|
2493
|
+
});
|
|
2494
|
+
var CreateCronServiceRequest = z11.object({ name: z11.string() });
|
|
2495
|
+
var CreateCronTriggerRequest = z11.object({
|
|
2496
|
+
box: z11.string().min(1),
|
|
2497
|
+
expr: z11.string().min(1),
|
|
2498
|
+
timezone: z11.string().optional(),
|
|
2358
2499
|
/** A request: `port`, with `method` and `path`. */
|
|
2359
|
-
method:
|
|
2360
|
-
port:
|
|
2361
|
-
path:
|
|
2500
|
+
method: z11.enum(CRON_METHODS).optional(),
|
|
2501
|
+
port: z11.number().int().min(1).max(65535).optional(),
|
|
2502
|
+
path: z11.string().optional(),
|
|
2362
2503
|
/** Or a command, with `timeoutSec`; exactly one of `port` and `command`. */
|
|
2363
|
-
command:
|
|
2364
|
-
timeoutSec:
|
|
2504
|
+
command: z11.string().optional(),
|
|
2505
|
+
timeoutSec: z11.number().int().optional()
|
|
2365
2506
|
});
|
|
2366
|
-
var UpdateCronTriggerRequest =
|
|
2507
|
+
var UpdateCronTriggerRequest = z11.object({ enabled: z11.boolean() });
|
|
2367
2508
|
var cronTarget = (t) => t.kind === "command" ? `${t.box}$ ${t.command}` : `${t.method} ${t.box}:${t.port}${t.path}`;
|
|
2368
2509
|
|
|
2369
2510
|
// ../shared/src/storage.ts
|
|
2370
|
-
import { z as
|
|
2371
|
-
var RegionSchema =
|
|
2372
|
-
var
|
|
2373
|
-
|
|
2374
|
-
|
|
2511
|
+
import { z as z12 } from "zod";
|
|
2512
|
+
var RegionSchema = z12.object({ name: z12.string(), country: z12.string().nullable() });
|
|
2513
|
+
var MAX_PUBLIC_BUCKETS = 10;
|
|
2514
|
+
var STORAGE_BOX_SUBDOMAINS = MAX_PUBLIC_BUCKETS + 2;
|
|
2515
|
+
var ObjectStorageSchema = z12.object({
|
|
2516
|
+
owner: z12.string(),
|
|
2517
|
+
ownerKind: z12.enum(["user", "org"]),
|
|
2375
2518
|
/** `https://s3-<slug>.<domain>`: what an S3 client is given, with path-style addressing. Null while the address is not claimed. */
|
|
2376
|
-
endpoint:
|
|
2519
|
+
endpoint: z12.string().nullable(),
|
|
2377
2520
|
/** The S3 region every client of it signs with (`ro-west-1`): its host's when it was made. */
|
|
2378
|
-
region:
|
|
2521
|
+
region: z12.string(),
|
|
2379
2522
|
/** The most it may hold. */
|
|
2380
|
-
sizeGib:
|
|
2523
|
+
sizeGib: z12.number().int(),
|
|
2381
2524
|
/** `running` when it answers; `unknown` while its host is not heard from. */
|
|
2382
2525
|
status: BoxStatusSchema,
|
|
2383
2526
|
/** With `?live=1`, when the storage answered: what is on its disk, and the disk's real size. */
|
|
2384
|
-
usedBytes:
|
|
2385
|
-
totalBytes:
|
|
2527
|
+
usedBytes: z12.number().optional(),
|
|
2528
|
+
totalBytes: z12.number().optional(),
|
|
2386
2529
|
/** With `?live=1`, when the storage answered: what each bucket holds. */
|
|
2387
|
-
bucketUsage:
|
|
2388
|
-
host:
|
|
2389
|
-
country:
|
|
2390
|
-
buckets:
|
|
2391
|
-
price:
|
|
2392
|
-
createdAt:
|
|
2393
|
-
});
|
|
2394
|
-
var BucketSchema =
|
|
2395
|
-
name:
|
|
2396
|
-
owner:
|
|
2397
|
-
ownerKind:
|
|
2398
|
-
endpoint:
|
|
2399
|
-
|
|
2400
|
-
|
|
2401
|
-
|
|
2402
|
-
|
|
2403
|
-
|
|
2404
|
-
|
|
2405
|
-
|
|
2406
|
-
|
|
2407
|
-
|
|
2408
|
-
|
|
2409
|
-
|
|
2410
|
-
|
|
2411
|
-
|
|
2412
|
-
|
|
2530
|
+
bucketUsage: z12.array(z12.object({ name: z12.string(), objects: z12.number(), bytes: z12.number() })).optional(),
|
|
2531
|
+
host: z12.string(),
|
|
2532
|
+
country: z12.string().optional(),
|
|
2533
|
+
buckets: z12.number().int(),
|
|
2534
|
+
price: z12.object({ perMonth: z12.number(), currency: z12.string() }),
|
|
2535
|
+
createdAt: z12.string()
|
|
2536
|
+
});
|
|
2537
|
+
var BucketSchema = z12.object({
|
|
2538
|
+
name: z12.string(),
|
|
2539
|
+
owner: z12.string(),
|
|
2540
|
+
ownerKind: z12.enum(["user", "org"]),
|
|
2541
|
+
endpoint: z12.string().nullable(),
|
|
2542
|
+
publicUrl: z12.string().optional(),
|
|
2543
|
+
region: z12.string(),
|
|
2544
|
+
keys: z12.number().int(),
|
|
2545
|
+
objects: z12.number().optional(),
|
|
2546
|
+
bytes: z12.number().optional(),
|
|
2547
|
+
createdBy: z12.string().nullable(),
|
|
2548
|
+
createdAt: z12.string()
|
|
2549
|
+
});
|
|
2550
|
+
var CreateBucketRequest = z12.object({
|
|
2551
|
+
name: z12.string(),
|
|
2552
|
+
sizeGib: z12.number().int().optional(),
|
|
2553
|
+
near: z12.string().optional(),
|
|
2554
|
+
region: z12.string().optional()
|
|
2555
|
+
});
|
|
2556
|
+
var CreatedBucketSchema = BucketSchema.extend({ storage: ObjectStorageSchema, storageCreated: z12.boolean() });
|
|
2413
2557
|
var BucketInfoSchema = BucketSchema.extend({ storage: ObjectStorageSchema });
|
|
2414
|
-
var
|
|
2415
|
-
|
|
2416
|
-
|
|
2417
|
-
|
|
2418
|
-
|
|
2419
|
-
|
|
2420
|
-
|
|
2421
|
-
|
|
2422
|
-
|
|
2423
|
-
|
|
2424
|
-
var
|
|
2425
|
-
var
|
|
2426
|
-
var
|
|
2427
|
-
|
|
2428
|
-
|
|
2429
|
-
|
|
2558
|
+
var SetBucketPublicRequest = z12.object({ on: z12.boolean(), sub: z12.string().optional() });
|
|
2559
|
+
var BucketKeySchema = z12.object({
|
|
2560
|
+
id: z12.string(),
|
|
2561
|
+
name: z12.string(),
|
|
2562
|
+
bucket: z12.string(),
|
|
2563
|
+
owner: z12.string(),
|
|
2564
|
+
readOnly: z12.boolean(),
|
|
2565
|
+
createdBy: z12.string().nullable(),
|
|
2566
|
+
createdAt: z12.string()
|
|
2567
|
+
});
|
|
2568
|
+
var CreateBucketKeyRequest = z12.object({ name: z12.string().optional(), readOnly: z12.boolean().optional() });
|
|
2569
|
+
var CreatedBucketKeySchema = BucketKeySchema.extend({ secret: z12.string(), endpoint: z12.string().nullable(), region: z12.string() });
|
|
2570
|
+
var GrowStorageRequest = z12.object({ sizeGib: z12.number().int() });
|
|
2571
|
+
var StorageBackupSchema = z12.object({
|
|
2572
|
+
id: z12.string(),
|
|
2573
|
+
owner: z12.string(),
|
|
2574
|
+
status: z12.enum(BACKUP_STATUSES),
|
|
2430
2575
|
/** Why it failed; null otherwise. */
|
|
2431
|
-
error:
|
|
2576
|
+
error: z12.string().nullable(),
|
|
2432
2577
|
/** The storage's volume when taken. */
|
|
2433
|
-
diskBytes:
|
|
2578
|
+
diskBytes: z12.number().int().nullable(),
|
|
2434
2579
|
/** What it holds: the slots that are not all zeros. */
|
|
2435
|
-
dataBytes:
|
|
2580
|
+
dataBytes: z12.number().int().nullable(),
|
|
2436
2581
|
/** What this backup added to the backup store (encrypted, compressed). */
|
|
2437
|
-
uploadedBytes:
|
|
2582
|
+
uploadedBytes: z12.number().int().nullable(),
|
|
2438
2583
|
/** The buckets it holds, and how many access keys they had, as kvbox knew them when it was taken. */
|
|
2439
|
-
buckets:
|
|
2440
|
-
keys:
|
|
2441
|
-
createdBy:
|
|
2442
|
-
createdAt:
|
|
2443
|
-
finishedAt:
|
|
2444
|
-
});
|
|
2445
|
-
var RestoredKeySchema =
|
|
2446
|
-
var StorageRestoreSchema =
|
|
2447
|
-
backup:
|
|
2584
|
+
buckets: z12.array(z12.string()),
|
|
2585
|
+
keys: z12.number().int(),
|
|
2586
|
+
createdBy: z12.string().nullable(),
|
|
2587
|
+
createdAt: z12.string(),
|
|
2588
|
+
finishedAt: z12.string().nullable()
|
|
2589
|
+
});
|
|
2590
|
+
var RestoredKeySchema = z12.object({ bucket: z12.string(), id: z12.string(), name: z12.string() });
|
|
2591
|
+
var StorageRestoreSchema = z12.object({
|
|
2592
|
+
backup: z12.string(),
|
|
2448
2593
|
storage: ObjectStorageSchema,
|
|
2449
|
-
buckets:
|
|
2450
|
-
keys:
|
|
2451
|
-
checked:
|
|
2452
|
-
warnings:
|
|
2594
|
+
buckets: z12.object({ kept: z12.array(z12.string()), returned: z12.array(z12.string()), removed: z12.array(z12.string()) }),
|
|
2595
|
+
keys: z12.object({ dropped: z12.array(RestoredKeySchema), revoked: z12.array(RestoredKeySchema) }),
|
|
2596
|
+
checked: z12.boolean(),
|
|
2597
|
+
warnings: z12.array(z12.string())
|
|
2453
2598
|
});
|
|
2454
2599
|
var OBJECT_LIST_MAX = 1e3;
|
|
2455
2600
|
var SHARE_LINK_MAX_SEC = 7 * 24 * 3600;
|
|
@@ -2459,56 +2604,56 @@ var MULTIPART_PART_BYTES = 16 * 1024 * 1024;
|
|
|
2459
2604
|
var UPLOAD_MAX_BYTES = 50 * 1024 * 1024 * 1024;
|
|
2460
2605
|
var MOVE_MAX_BYTES = 5 * 1024 * 1024 * 1024;
|
|
2461
2606
|
var DELETE_PREFIXES_MAX = 100;
|
|
2462
|
-
var StoredObjectSchema =
|
|
2463
|
-
key:
|
|
2464
|
-
size:
|
|
2465
|
-
etag:
|
|
2607
|
+
var StoredObjectSchema = z12.object({
|
|
2608
|
+
key: z12.string(),
|
|
2609
|
+
size: z12.number(),
|
|
2610
|
+
etag: z12.string(),
|
|
2466
2611
|
/** ISO 8601. */
|
|
2467
|
-
modified:
|
|
2468
|
-
});
|
|
2469
|
-
var ObjectListingSchema =
|
|
2470
|
-
prefix:
|
|
2471
|
-
folders:
|
|
2472
|
-
objects:
|
|
2473
|
-
next:
|
|
2474
|
-
canWrite:
|
|
2475
|
-
});
|
|
2476
|
-
var ObjectInfoSchema = StoredObjectSchema.extend({ contentType:
|
|
2477
|
-
var ObjectCountSchema =
|
|
2478
|
-
var ObjectLinkRequest =
|
|
2479
|
-
key:
|
|
2480
|
-
expiresSec:
|
|
2612
|
+
modified: z12.string()
|
|
2613
|
+
});
|
|
2614
|
+
var ObjectListingSchema = z12.object({
|
|
2615
|
+
prefix: z12.string(),
|
|
2616
|
+
folders: z12.array(z12.string()),
|
|
2617
|
+
objects: z12.array(StoredObjectSchema),
|
|
2618
|
+
next: z12.string().optional(),
|
|
2619
|
+
canWrite: z12.boolean()
|
|
2620
|
+
});
|
|
2621
|
+
var ObjectInfoSchema = StoredObjectSchema.extend({ contentType: z12.string() });
|
|
2622
|
+
var ObjectCountSchema = z12.object({ objects: z12.number(), bytes: z12.number(), more: z12.boolean() });
|
|
2623
|
+
var ObjectLinkRequest = z12.object({
|
|
2624
|
+
key: z12.string(),
|
|
2625
|
+
expiresSec: z12.number().int().positive(),
|
|
2481
2626
|
/** Answer as a download (`Content-Disposition: attachment`) instead of showing it. */
|
|
2482
|
-
download:
|
|
2627
|
+
download: z12.boolean().optional(),
|
|
2483
2628
|
/**
|
|
2484
2629
|
* Let the browser keep what the link answers until the link expires (`Cache-Control: private`, `Expires`),
|
|
2485
2630
|
* so the same link shown twice is fetched once. Asked again within the hour, for the same file as it
|
|
2486
2631
|
* is, it is the same URL, and it lasts up to an hour longer than `expiresSec`. For the app's own previews.
|
|
2487
2632
|
* Only a fetch of the whole file is kept so: the storage answers a part of one (`Range`) without the two headers.
|
|
2488
2633
|
*/
|
|
2489
|
-
cached:
|
|
2634
|
+
cached: z12.boolean().optional()
|
|
2490
2635
|
});
|
|
2491
|
-
var ObjectLinkSchema =
|
|
2636
|
+
var ObjectLinkSchema = z12.object({ url: z12.string(), expiresAt: z12.string() });
|
|
2492
2637
|
var MEDIA_TYPE_RE = /^[\w.+-]+\/[\w.+-]+(?:\s*;[\x20-\x7e]*)?$/;
|
|
2493
|
-
var StartUploadRequest =
|
|
2494
|
-
var UploadPlanSchema =
|
|
2495
|
-
|
|
2496
|
-
|
|
2638
|
+
var StartUploadRequest = z12.object({ key: z12.string(), size: z12.number().int().nonnegative(), contentType: z12.string().max(200).regex(MEDIA_TYPE_RE, "not a media type like image/png").optional(), overwrite: z12.boolean().optional() });
|
|
2639
|
+
var UploadPlanSchema = z12.discriminatedUnion("kind", [
|
|
2640
|
+
z12.object({ kind: z12.literal("single"), url: z12.string() }),
|
|
2641
|
+
z12.object({ kind: z12.literal("multipart"), uploadId: z12.string(), partSize: z12.number(), urls: z12.array(z12.string()) })
|
|
2497
2642
|
]);
|
|
2498
|
-
var CompleteUploadRequest =
|
|
2499
|
-
key:
|
|
2500
|
-
uploadId:
|
|
2501
|
-
parts:
|
|
2643
|
+
var CompleteUploadRequest = z12.object({
|
|
2644
|
+
key: z12.string(),
|
|
2645
|
+
uploadId: z12.string(),
|
|
2646
|
+
parts: z12.array(z12.object({ part: z12.number().int().positive(), etag: z12.string() })).min(1)
|
|
2502
2647
|
});
|
|
2503
|
-
var AbortUploadRequest =
|
|
2504
|
-
var DeleteObjectsRequest =
|
|
2505
|
-
var DeletedObjectsSchema =
|
|
2506
|
-
deleted:
|
|
2507
|
-
more:
|
|
2508
|
-
errors:
|
|
2648
|
+
var AbortUploadRequest = z12.object({ key: z12.string(), uploadId: z12.string() });
|
|
2649
|
+
var DeleteObjectsRequest = z12.object({ keys: z12.array(z12.string()).max(OBJECT_LIST_MAX).optional(), prefixes: z12.array(z12.string()).max(DELETE_PREFIXES_MAX).optional() });
|
|
2650
|
+
var DeletedObjectsSchema = z12.object({
|
|
2651
|
+
deleted: z12.number(),
|
|
2652
|
+
more: z12.boolean(),
|
|
2653
|
+
errors: z12.array(z12.object({ key: z12.string(), message: z12.string() }))
|
|
2509
2654
|
});
|
|
2510
|
-
var MoveObjectRequest =
|
|
2511
|
-
var CreateFolderRequest =
|
|
2655
|
+
var MoveObjectRequest = z12.object({ from: z12.string(), to: z12.string(), overwrite: z12.boolean().optional() });
|
|
2656
|
+
var CreateFolderRequest = z12.object({ prefix: z12.string() });
|
|
2512
2657
|
|
|
2513
2658
|
// src/kvm.ts
|
|
2514
2659
|
import { accessSync, constants, readFileSync, statSync } from "fs";
|
|
@@ -2622,7 +2767,7 @@ var ServerClient = class {
|
|
|
2622
2767
|
startedOnce = false;
|
|
2623
2768
|
async call(method, path, schema, body, org = this.target.kind === "cloud" ? this.target.org : void 0, timeoutMs) {
|
|
2624
2769
|
try {
|
|
2625
|
-
return await this.sdk.request(method, path, schema, { body, org: this.target.kind === "cloud" ? org : void 0, timeoutMs });
|
|
2770
|
+
return await this.sdk.request(method, path, schema, { body, org: this.target.kind === "cloud" ? org ?? void 0 : void 0, timeoutMs });
|
|
2626
2771
|
} catch (err) {
|
|
2627
2772
|
return this.failed(err, () => this.call(method, path, schema, body, org, timeoutMs));
|
|
2628
2773
|
}
|
|
@@ -2678,10 +2823,10 @@ var ServerClient = class {
|
|
|
2678
2823
|
* `all`: every box on the platform (platform admins only, #78).
|
|
2679
2824
|
*/
|
|
2680
2825
|
listMachines(opts = {}) {
|
|
2681
|
-
return this.call("GET", `/machines${allQuery(opts)}`,
|
|
2826
|
+
return this.call("GET", `/machines${allQuery(opts)}`, z13.array(MachineSchema), void 0, opts.org);
|
|
2682
2827
|
}
|
|
2683
2828
|
createMachine(req) {
|
|
2684
|
-
return this.call("POST", "/machines", MachineSchema, req);
|
|
2829
|
+
return this.call("POST", "/machines", MachineSchema, req, void 0, req.fromBackup !== void 0 ? 2 * 36e5 : void 0);
|
|
2685
2830
|
}
|
|
2686
2831
|
/** `kvbox vm fork` (#79): `name` is the source; the copy goes to the `--org` slug, else the caller's own. */
|
|
2687
2832
|
forkMachine(name, req) {
|
|
@@ -2732,10 +2877,10 @@ var ServerClient = class {
|
|
|
2732
2877
|
}
|
|
2733
2878
|
/** Backups, the control plane's only: a box's disk in object storage. Newest first. */
|
|
2734
2879
|
listBackups() {
|
|
2735
|
-
return this.call("GET", "/backups",
|
|
2880
|
+
return this.call("GET", "/backups", z13.array(BackupSchema));
|
|
2736
2881
|
}
|
|
2737
2882
|
boxBackups(name) {
|
|
2738
|
-
return this.call("GET", `/machines/${encodeURIComponent(name)}/backups`,
|
|
2883
|
+
return this.call("GET", `/machines/${encodeURIComponent(name)}/backups`, z13.array(BackupSchema));
|
|
2739
2884
|
}
|
|
2740
2885
|
boxBackup(name, id) {
|
|
2741
2886
|
return this.call("GET", `/machines/${encodeURIComponent(name)}/backups/${encodeURIComponent(id)}`, BackupSchema);
|
|
@@ -2749,14 +2894,14 @@ var ServerClient = class {
|
|
|
2749
2894
|
* later. Works for a backup whose box, volume or database is gone too.
|
|
2750
2895
|
*/
|
|
2751
2896
|
removeBackup(id) {
|
|
2752
|
-
return this.call("DELETE", `/backups/${encodeURIComponent(id)}`,
|
|
2897
|
+
return this.call("DELETE", `/backups/${encodeURIComponent(id)}`, z13.undefined());
|
|
2753
2898
|
}
|
|
2754
2899
|
/** A volume's backups (#168): the same as a box's, of the volume's disk. Newest first. */
|
|
2755
2900
|
listVolumeBackups() {
|
|
2756
|
-
return this.call("GET", "/backups?kind=volume",
|
|
2901
|
+
return this.call("GET", "/backups?kind=volume", z13.array(VolumeBackupSchema));
|
|
2757
2902
|
}
|
|
2758
2903
|
volumeBackups(name) {
|
|
2759
|
-
return this.call("GET", `/volumes/${encodeURIComponent(name)}/backups`,
|
|
2904
|
+
return this.call("GET", `/volumes/${encodeURIComponent(name)}/backups`, z13.array(VolumeBackupSchema));
|
|
2760
2905
|
}
|
|
2761
2906
|
volumeBackup(name, id) {
|
|
2762
2907
|
return this.call("GET", `/volumes/${encodeURIComponent(name)}/backups/${encodeURIComponent(id)}`, VolumeBackupSchema);
|
|
@@ -2775,7 +2920,7 @@ var ServerClient = class {
|
|
|
2775
2920
|
}
|
|
2776
2921
|
/** Wake hooks (#101), the control plane's only: a URL and a secret that wake the box. */
|
|
2777
2922
|
boxHooks(name) {
|
|
2778
|
-
return this.call("GET", `/machines/${encodeURIComponent(name)}/hooks`,
|
|
2923
|
+
return this.call("GET", `/machines/${encodeURIComponent(name)}/hooks`, z13.array(WakeHookSchema));
|
|
2779
2924
|
}
|
|
2780
2925
|
createBoxHook(name) {
|
|
2781
2926
|
return this.call("POST", `/machines/${encodeURIComponent(name)}/hooks`, CreatedWakeHookSchema);
|
|
@@ -2803,7 +2948,7 @@ var ServerClient = class {
|
|
|
2803
2948
|
}
|
|
2804
2949
|
/** Every readable box's subdomains, one entry each. */
|
|
2805
2950
|
listSubdomains() {
|
|
2806
|
-
return this.call("GET", "/subdomains",
|
|
2951
|
+
return this.call("GET", "/subdomains", z13.array(SubdomainSchema));
|
|
2807
2952
|
}
|
|
2808
2953
|
/** Custom domains (#89), the control plane's only: serve the box at the user's own name. */
|
|
2809
2954
|
addDomain(name, req) {
|
|
@@ -2814,7 +2959,7 @@ var ServerClient = class {
|
|
|
2814
2959
|
}
|
|
2815
2960
|
/** Every readable box's custom domains. */
|
|
2816
2961
|
listDomains() {
|
|
2817
|
-
return this.call("GET", "/domains",
|
|
2962
|
+
return this.call("GET", "/domains", z13.array(DomainSchema));
|
|
2818
2963
|
}
|
|
2819
2964
|
/** A running box's own load, memory and disk, asked of its guest (#67). */
|
|
2820
2965
|
machineStats(name) {
|
|
@@ -2847,22 +2992,22 @@ var ServerClient = class {
|
|
|
2847
2992
|
return this.call("POST", "/billing/redeem", RedeemResponseSchema, { code });
|
|
2848
2993
|
}
|
|
2849
2994
|
deleteMachine(name) {
|
|
2850
|
-
return this.call("DELETE", `/machines/${encodeURIComponent(name)}`,
|
|
2995
|
+
return this.call("DELETE", `/machines/${encodeURIComponent(name)}`, z13.undefined());
|
|
2851
2996
|
}
|
|
2852
2997
|
/** Like `listMachines`, for snapshots. */
|
|
2853
2998
|
listSnapshots(opts = {}) {
|
|
2854
|
-
return this.call("GET", `/snapshots${allQuery(opts)}`,
|
|
2999
|
+
return this.call("GET", `/snapshots${allQuery(opts)}`, z13.array(SnapshotSchema), void 0, opts.org);
|
|
2855
3000
|
}
|
|
2856
3001
|
createSnapshot(req) {
|
|
2857
3002
|
return this.call("POST", "/snapshots", SnapshotSchema, req);
|
|
2858
3003
|
}
|
|
2859
3004
|
deleteSnapshot(name) {
|
|
2860
|
-
return this.call("DELETE", `/snapshots/${encodeURIComponent(name)}`,
|
|
3005
|
+
return this.call("DELETE", `/snapshots/${encodeURIComponent(name)}`, z13.undefined());
|
|
2861
3006
|
}
|
|
2862
3007
|
// ---- environment variables (#88), a control plane only: the caller's slug, or `--org`'s ----
|
|
2863
3008
|
/** `org`: that org's list instead of `--org`'s (or the caller's own). */
|
|
2864
3009
|
listEnv(org) {
|
|
2865
|
-
return this.call("GET", "/vars",
|
|
3010
|
+
return this.call("GET", "/vars", z13.array(EnvVarSchema), void 0, org);
|
|
2866
3011
|
}
|
|
2867
3012
|
setEnv(name, req) {
|
|
2868
3013
|
return this.call("PUT", `/vars/${encodeURIComponent(name)}`, EnvChangeSchema, req);
|
|
@@ -2882,13 +3027,13 @@ var ServerClient = class {
|
|
|
2882
3027
|
}
|
|
2883
3028
|
// ---- volumes (#52) ----
|
|
2884
3029
|
listVolumes(opts = {}) {
|
|
2885
|
-
return this.call("GET", `/volumes${allQuery(opts)}`,
|
|
3030
|
+
return this.call("GET", `/volumes${allQuery(opts)}`, z13.array(VolumeSchema), void 0, opts.org);
|
|
2886
3031
|
}
|
|
2887
3032
|
createVolume(req) {
|
|
2888
3033
|
return this.call("POST", "/volumes", VolumeSchema, req);
|
|
2889
3034
|
}
|
|
2890
3035
|
deleteVolume(name) {
|
|
2891
|
-
return this.call("DELETE", `/volumes/${encodeURIComponent(name)}`,
|
|
3036
|
+
return this.call("DELETE", `/volumes/${encodeURIComponent(name)}`, z13.undefined());
|
|
2892
3037
|
}
|
|
2893
3038
|
/** Both answer with the box as it is afterwards (restarted when it was running). */
|
|
2894
3039
|
attachVolume(name, req) {
|
|
@@ -2903,7 +3048,7 @@ var ServerClient = class {
|
|
|
2903
3048
|
}
|
|
2904
3049
|
// ---- cron service (#190): the control plane's alone ----
|
|
2905
3050
|
listCronServices(opts = {}) {
|
|
2906
|
-
return this.call("GET", `/cron${allQuery(opts)}`,
|
|
3051
|
+
return this.call("GET", `/cron${allQuery(opts)}`, z13.array(CronServiceSchema), void 0, opts.org);
|
|
2907
3052
|
}
|
|
2908
3053
|
createCronService(name) {
|
|
2909
3054
|
return this.call("POST", "/cron", CronServiceSchema, { name });
|
|
@@ -2912,10 +3057,10 @@ var ServerClient = class {
|
|
|
2912
3057
|
return this.call("GET", `/cron/${encodeURIComponent(name)}`, CronServiceSchema);
|
|
2913
3058
|
}
|
|
2914
3059
|
deleteCronService(name) {
|
|
2915
|
-
return this.call("DELETE", `/cron/${encodeURIComponent(name)}`,
|
|
3060
|
+
return this.call("DELETE", `/cron/${encodeURIComponent(name)}`, z13.undefined());
|
|
2916
3061
|
}
|
|
2917
3062
|
listCronTriggers(service) {
|
|
2918
|
-
return this.call("GET", `/cron/${encodeURIComponent(service)}/triggers`,
|
|
3063
|
+
return this.call("GET", `/cron/${encodeURIComponent(service)}/triggers`, z13.array(CronTriggerSchema));
|
|
2919
3064
|
}
|
|
2920
3065
|
addCronTrigger(service, req) {
|
|
2921
3066
|
return this.call("POST", `/cron/${encodeURIComponent(service)}/triggers`, CronTriggerSchema, req);
|
|
@@ -2925,18 +3070,18 @@ var ServerClient = class {
|
|
|
2925
3070
|
return this.call("PATCH", `/cron/${encodeURIComponent(service)}/triggers/${encodeURIComponent(id)}`, CronTriggerSchema, { enabled: enabled2 });
|
|
2926
3071
|
}
|
|
2927
3072
|
deleteCronTrigger(service, id) {
|
|
2928
|
-
return this.call("DELETE", `/cron/${encodeURIComponent(service)}/triggers/${encodeURIComponent(id)}`,
|
|
3073
|
+
return this.call("DELETE", `/cron/${encodeURIComponent(service)}/triggers/${encodeURIComponent(id)}`, z13.undefined());
|
|
2929
3074
|
}
|
|
2930
3075
|
/** Marks it due: kvbox-cron fires it within a few seconds. */
|
|
2931
3076
|
runCronTrigger(service, id) {
|
|
2932
3077
|
return this.call("POST", `/cron/${encodeURIComponent(service)}/triggers/${encodeURIComponent(id)}/run`, CronTriggerSchema);
|
|
2933
3078
|
}
|
|
2934
3079
|
listCronRuns(service, id, limit) {
|
|
2935
|
-
return this.call("GET", `/cron/${encodeURIComponent(service)}/triggers/${encodeURIComponent(id)}/runs${limit === void 0 ? "" : `?limit=${limit}`}`,
|
|
3080
|
+
return this.call("GET", `/cron/${encodeURIComponent(service)}/triggers/${encodeURIComponent(id)}/runs${limit === void 0 ? "" : `?limit=${limit}`}`, z13.array(CronRunSchema));
|
|
2936
3081
|
}
|
|
2937
3082
|
// ---- object storage (#182): the control plane's alone ----
|
|
2938
3083
|
listBuckets(opts = {}) {
|
|
2939
|
-
return this.call("GET", `/buckets${allQuery(opts)}`,
|
|
3084
|
+
return this.call("GET", `/buckets${allQuery(opts)}`, z13.array(BucketSchema), void 0, opts.org);
|
|
2940
3085
|
}
|
|
2941
3086
|
/** The first bucket of a slug also makes its storage: a box boots twice, so this may take a couple of minutes. */
|
|
2942
3087
|
createBucket(req) {
|
|
@@ -2945,27 +3090,31 @@ var ServerClient = class {
|
|
|
2945
3090
|
getBucket(name) {
|
|
2946
3091
|
return this.call("GET", `/buckets/${encodeURIComponent(name)}`, BucketInfoSchema);
|
|
2947
3092
|
}
|
|
3093
|
+
/** Make every object of the bucket readable by anyone at its own address (#191), or private again. */
|
|
3094
|
+
setBucketPublic(name, req) {
|
|
3095
|
+
return this.call("PUT", `/buckets/${encodeURIComponent(name)}/public`, BucketSchema, req);
|
|
3096
|
+
}
|
|
2948
3097
|
deleteBucket(name, force = false) {
|
|
2949
|
-
return this.call("DELETE", `/buckets/${encodeURIComponent(name)}${force ? "?force=1" : ""}`,
|
|
3098
|
+
return this.call("DELETE", `/buckets/${encodeURIComponent(name)}${force ? "?force=1" : ""}`, z13.undefined());
|
|
2950
3099
|
}
|
|
2951
3100
|
listBucketKeys(name) {
|
|
2952
|
-
return this.call("GET", `/buckets/${encodeURIComponent(name)}/keys`,
|
|
3101
|
+
return this.call("GET", `/buckets/${encodeURIComponent(name)}/keys`, z13.array(BucketKeySchema));
|
|
2953
3102
|
}
|
|
2954
3103
|
createBucketKey(name, req) {
|
|
2955
3104
|
return this.call("POST", `/buckets/${encodeURIComponent(name)}/keys`, CreatedBucketKeySchema, req);
|
|
2956
3105
|
}
|
|
2957
3106
|
deleteBucketKey(name, id) {
|
|
2958
|
-
return this.call("DELETE", `/buckets/${encodeURIComponent(name)}/keys/${encodeURIComponent(id)}`,
|
|
3107
|
+
return this.call("DELETE", `/buckets/${encodeURIComponent(name)}/keys/${encodeURIComponent(id)}`, z13.undefined());
|
|
2959
3108
|
}
|
|
2960
3109
|
listStorage(opts = {}) {
|
|
2961
|
-
return this.call("GET", `/storage${allQuery(opts)}`,
|
|
3110
|
+
return this.call("GET", `/storage${allQuery(opts)}`, z13.array(ObjectStorageSchema), void 0, opts.org);
|
|
2962
3111
|
}
|
|
2963
3112
|
growStorage(sizeGib) {
|
|
2964
3113
|
return this.call("POST", "/storage/grow", ObjectStorageSchema, { sizeGib });
|
|
2965
3114
|
}
|
|
2966
3115
|
/** Backups of the slug's whole object storage (#186 slice 3), newest first. */
|
|
2967
3116
|
storageBackups() {
|
|
2968
|
-
return this.call("GET", "/storage/backups",
|
|
3117
|
+
return this.call("GET", "/storage/backups", z13.array(StorageBackupSchema));
|
|
2969
3118
|
}
|
|
2970
3119
|
storageBackup(id) {
|
|
2971
3120
|
return this.call("GET", `/storage/backups/${encodeURIComponent(id)}`, StorageBackupSchema);
|
|
@@ -2986,11 +3135,11 @@ var ServerClient = class {
|
|
|
2986
3135
|
return `/managed/${encodeURIComponent(kind)}${name === void 0 ? "" : `/${encodeURIComponent(name)}`}${rest}`;
|
|
2987
3136
|
}
|
|
2988
3137
|
managedCatalog() {
|
|
2989
|
-
return this.call("GET", "/managed/catalog",
|
|
3138
|
+
return this.call("GET", "/managed/catalog", z13.array(ManagedCatalogEntrySchema));
|
|
2990
3139
|
}
|
|
2991
3140
|
/** One kind's services, or every kind's when `kind` is left out. */
|
|
2992
3141
|
listManaged(kind, opts = {}) {
|
|
2993
|
-
return this.call("GET", `${kind === void 0 ? "/managed" : this.managedPath(kind)}${allQuery(opts)}`,
|
|
3142
|
+
return this.call("GET", `${kind === void 0 ? "/managed" : this.managedPath(kind)}${allQuery(opts)}`, z13.array(ManagedSchema), void 0, opts.org);
|
|
2994
3143
|
}
|
|
2995
3144
|
/** From a backup (`fromBackup`) it waits for the restore too: the control plane gives its host 2 h for the download. */
|
|
2996
3145
|
createManaged(kind, req) {
|
|
@@ -3001,7 +3150,7 @@ var ServerClient = class {
|
|
|
3001
3150
|
return this.call("GET", this.managedPath(kind, name), ManagedSchema);
|
|
3002
3151
|
}
|
|
3003
3152
|
deleteManaged(kind, name) {
|
|
3004
|
-
return this.call("DELETE", this.managedPath(kind, name),
|
|
3153
|
+
return this.call("DELETE", this.managedPath(kind, name), z13.undefined());
|
|
3005
3154
|
}
|
|
3006
3155
|
managedPassword(kind, name) {
|
|
3007
3156
|
return this.call("GET", this.managedPath(kind, name, "/password"), ManagedSecretSchema);
|
|
@@ -3023,10 +3172,10 @@ var ServerClient = class {
|
|
|
3023
3172
|
}
|
|
3024
3173
|
/** A managed service's backups (#186): its storage's, by the volume backup engine. Every one of a kind, those of removed services too. */
|
|
3025
3174
|
listManagedBackups(kind) {
|
|
3026
|
-
return this.call("GET", `/backups?managed=${encodeURIComponent(kind)}`,
|
|
3175
|
+
return this.call("GET", `/backups?managed=${encodeURIComponent(kind)}`, z13.array(ManagedBackupSchema));
|
|
3027
3176
|
}
|
|
3028
3177
|
managedBackups(kind, name) {
|
|
3029
|
-
return this.call("GET", this.managedPath(kind, name, "/backups"),
|
|
3178
|
+
return this.call("GET", this.managedPath(kind, name, "/backups"), z13.array(ManagedBackupSchema));
|
|
3030
3179
|
}
|
|
3031
3180
|
managedBackup(kind, name, id) {
|
|
3032
3181
|
return this.call("GET", this.managedPath(kind, name, `/backups/${encodeURIComponent(id)}`), ManagedBackupSchema);
|
|
@@ -3068,24 +3217,36 @@ var ServerClient = class {
|
|
|
3068
3217
|
return this.call("POST", "/login/device/token", DeviceLoginPollSchema, { deviceCode });
|
|
3069
3218
|
}
|
|
3070
3219
|
logout() {
|
|
3071
|
-
return this.call("POST", "/logout",
|
|
3220
|
+
return this.call("POST", "/logout", z13.unknown()).then(() => void 0);
|
|
3072
3221
|
}
|
|
3073
3222
|
me() {
|
|
3074
3223
|
return this.call("GET", "/me", MeResponseSchema);
|
|
3075
3224
|
}
|
|
3225
|
+
// ---- Integrations (`kvbox integration ls`, #205) ----
|
|
3226
|
+
/**
|
|
3227
|
+
* What one org has connected (`org`, else the `--org` one), or without either each readable slug; never a
|
|
3228
|
+
* credential. Null: each readable slug whatever `--org` says, which is how the caller's own slug is read.
|
|
3229
|
+
*/
|
|
3230
|
+
listIntegrations(org) {
|
|
3231
|
+
return this.call("GET", "/integrations", z13.array(IntegrationSchema), void 0, org);
|
|
3232
|
+
}
|
|
3233
|
+
/** What can be connected on this control plane, and by which kind of slug. */
|
|
3234
|
+
integrationCatalog() {
|
|
3235
|
+
return this.call("GET", "/integrations/catalog", z13.array(IntegrationCatalogEntrySchema), void 0, null);
|
|
3236
|
+
}
|
|
3076
3237
|
// ---- API keys (`kvbox key …`, #189) ----
|
|
3077
3238
|
listApiKeys() {
|
|
3078
|
-
return this.call("GET", "/keys",
|
|
3239
|
+
return this.call("GET", "/keys", z13.array(ApiKeySchema));
|
|
3079
3240
|
}
|
|
3080
3241
|
createApiKey(req) {
|
|
3081
3242
|
return this.call("POST", "/keys", CreatedApiKeySchema, req);
|
|
3082
3243
|
}
|
|
3083
3244
|
deleteApiKey(name) {
|
|
3084
|
-
return this.call("DELETE", `/keys/${encodeURIComponent(name)}`,
|
|
3245
|
+
return this.call("DELETE", `/keys/${encodeURIComponent(name)}`, z13.unknown()).then(() => void 0);
|
|
3085
3246
|
}
|
|
3086
3247
|
// ---- orgs (`kvbox org …`) ----
|
|
3087
3248
|
listOrgs() {
|
|
3088
|
-
return this.call("GET", "/orgs",
|
|
3249
|
+
return this.call("GET", "/orgs", z13.array(OrgMembershipSchema));
|
|
3089
3250
|
}
|
|
3090
3251
|
createOrg(req) {
|
|
3091
3252
|
return this.call("POST", "/orgs", CloudOrgSchema, req);
|
|
@@ -3094,16 +3255,16 @@ var ServerClient = class {
|
|
|
3094
3255
|
return this.call("GET", `/orgs/${encodeURIComponent(slug)}`, OrgDetailSchema);
|
|
3095
3256
|
}
|
|
3096
3257
|
deleteOrg(slug) {
|
|
3097
|
-
return this.call("DELETE", `/orgs/${encodeURIComponent(slug)}`,
|
|
3258
|
+
return this.call("DELETE", `/orgs/${encodeURIComponent(slug)}`, z13.undefined());
|
|
3098
3259
|
}
|
|
3099
3260
|
addMember(slug, req) {
|
|
3100
|
-
return this.call("POST", `/orgs/${encodeURIComponent(slug)}/members`,
|
|
3261
|
+
return this.call("POST", `/orgs/${encodeURIComponent(slug)}/members`, z13.undefined(), req);
|
|
3101
3262
|
}
|
|
3102
3263
|
setRole(slug, username, role) {
|
|
3103
|
-
return this.call("PATCH", `/orgs/${encodeURIComponent(slug)}/members/${encodeURIComponent(username)}`,
|
|
3264
|
+
return this.call("PATCH", `/orgs/${encodeURIComponent(slug)}/members/${encodeURIComponent(username)}`, z13.unknown(), { role }).then(() => void 0);
|
|
3104
3265
|
}
|
|
3105
3266
|
removeMember(slug, username) {
|
|
3106
|
-
return this.call("DELETE", `/orgs/${encodeURIComponent(slug)}/members/${encodeURIComponent(username)}`,
|
|
3267
|
+
return this.call("DELETE", `/orgs/${encodeURIComponent(slug)}/members/${encodeURIComponent(username)}`, z13.undefined());
|
|
3107
3268
|
}
|
|
3108
3269
|
/** Sign this machine's key again (#51); the key must be one the user logged in with. */
|
|
3109
3270
|
sshCert(req) {
|
|
@@ -3535,13 +3696,58 @@ function parseDuration(text2) {
|
|
|
3535
3696
|
return sec;
|
|
3536
3697
|
}
|
|
3537
3698
|
|
|
3699
|
+
// src/commands/integration/shared.ts
|
|
3700
|
+
function whereToConnect(catalog, id) {
|
|
3701
|
+
const page = (catalog.find((e) => e.id === id) ?? catalog.find((e) => e.page !== void 0))?.page;
|
|
3702
|
+
return page === void 0 ? "in the web app" : `at ${page}`;
|
|
3703
|
+
}
|
|
3704
|
+
function integrationsKept(asked, box2) {
|
|
3705
|
+
if (asked === void 0) return true;
|
|
3706
|
+
const have = box2.integrations ?? [];
|
|
3707
|
+
return asked.length === have.length && asked.every((id) => have.includes(id));
|
|
3708
|
+
}
|
|
3709
|
+
var integrationsText = (list) => list?.length ? list.join(", ") : "none";
|
|
3710
|
+
function connectable(catalog, id, own) {
|
|
3711
|
+
const entry = catalog.find((e) => e.id === id);
|
|
3712
|
+
return entry === void 0 || entry.kinds[own ? "user" : "org"].length > 0;
|
|
3713
|
+
}
|
|
3714
|
+
var catalogOf = (client) => client.integrationCatalog().catch(() => []);
|
|
3715
|
+
async function noteNotConnected(client, box2, asked) {
|
|
3716
|
+
if (asked.length === 0 || client.target.kind !== "cloud") {
|
|
3717
|
+
if (asked.length > 0) warn(`box ${box2.name}: integrations need the kvbox cloud; a box made on this machine never gets a credential`);
|
|
3718
|
+
return;
|
|
3719
|
+
}
|
|
3720
|
+
const slug = slugOf(box2.owner);
|
|
3721
|
+
const [rows2, catalog] = await Promise.all([client.listIntegrations(null).catch(() => null), catalogOf(client)]);
|
|
3722
|
+
if (rows2 === null) return;
|
|
3723
|
+
for (const id of asked) {
|
|
3724
|
+
const row = rows2.find((r) => r.owner === slug && r.integration === id);
|
|
3725
|
+
if (row === void 0 || row.connected && row.status === "ok") continue;
|
|
3726
|
+
if (!row.connected && !connectable(catalog, id, slug === me(client))) {
|
|
3727
|
+
info(color.dim(` ${id} cannot be connected for an org yet: it is on for this box, which gets nothing from it until ${slug} can connect it`));
|
|
3728
|
+
continue;
|
|
3729
|
+
}
|
|
3730
|
+
const why = row.connected ? `${id} needs to be connected again for ${slug}` : `${id} is not connected for ${slug} yet`;
|
|
3731
|
+
info(color.dim(` ${why}: it is on for this box and works once connected ${whereToConnect(catalog, id)}`));
|
|
3732
|
+
}
|
|
3733
|
+
}
|
|
3734
|
+
|
|
3538
3735
|
// src/commands/vm/new.ts
|
|
3539
|
-
var newCommand = new Command("new").description("boot a new box from an image (the base one, or e.g. postgres) or a snapshot").argument("[name]", "box name (box1, box2, \u2026 when omitted)").addOption(new Option("-s, --size <size>", "box size (default: server config, s)").choices(SIZE_NAMES)).option("-b, --base <image>", "the image to boot: base (default) or one the host has, e.g. postgres").option("-e, --env <NAME=value>", "a variable of the box's own, over yours (repeatable; change later with kvbox env set --box)", collect, []).option("-f, --from <snapshot>", "start from a snapshot instead of an image").option("--near <box>", "put it on the same host as this box, so the two can be linked (kvbox vm link)").option("--country <country>", "put it on a host in this country, a name or a code, e.g. romania or US").addOption(new Option("--host <name>", "put it on this host and no other (admins only)").hideHelp()).option("--auto-hibernate <duration>", "hibernate the box after this long without network traffic (30m, 4h, 1d; off: never; default: server config, off)").option("--force", "skip the capacity guard").option("--json", "print the box as JSON").action(async (name, opts, cmd) => {
|
|
3736
|
+
var newCommand = new Command("new").description("boot a new box from an image (the base one, or e.g. postgres) or a snapshot").argument("[name]", "box name (box1, box2, \u2026 when omitted)").addOption(new Option("-s, --size <size>", "box size (default: server config, s)").choices(SIZE_NAMES)).option("-b, --base <image>", "the image to boot: base (default) or one the host has, e.g. postgres").option("-e, --env <NAME=value>", "a variable of the box's own, over yours (repeatable; change later with kvbox env set --box)", collect, []).option("-f, --from <snapshot>", "start from a snapshot instead of an image").option("--from-backup <id>", "start on a backup's disk, a removed box's too (kvbox vm backup ls); image, variables and size come from it").option("--near <box>", "put it on the same host as this box, so the two can be linked (kvbox vm link)").option("--country <country>", "put it on a host in this country, a name or a code, e.g. romania or US").addOption(new Option("--host <name>", "put it on this host and no other (admins only)").hideHelp()).option("--auto-hibernate <duration>", "hibernate the box after this long without network traffic (30m, 4h, 1d; off: never; default: server config, off)").option("--integration <list>", "turn integrations on for the box, e.g. github (connect the account in the web app; off: none)").option("--force", "skip the capacity guard").option("--json", "print the box as JSON").action(async (name, opts, cmd) => {
|
|
3540
3737
|
const autoHibernateSec = opts.autoHibernate === void 0 ? void 0 : parseIdleTimeout(opts.autoHibernate);
|
|
3541
3738
|
const env = parseEnvFlags(opts.env);
|
|
3739
|
+
const integrations = opts.integration === void 0 ? void 0 : parseIntegrationList(opts.integration);
|
|
3542
3740
|
const country = opts.country === void 0 ? void 0 : parseCountry(opts.country);
|
|
3543
3741
|
if (country !== void 0 && opts.from !== void 0) throw new KvboxError("--country cannot be given with --from: a snapshot is restored on its own host");
|
|
3742
|
+
if (opts.fromBackup !== void 0) {
|
|
3743
|
+
const clash = opts.from !== void 0 ? "--from" : opts.base !== void 0 ? "--base" : env.length > 0 ? "-e" : null;
|
|
3744
|
+
if (clash) throw new KvboxError(`a box from a backup takes its image and variables from the backup; ${clash} cannot be given with --from-backup`);
|
|
3745
|
+
}
|
|
3544
3746
|
const client = await clientFor(cmd.optsWithGlobals());
|
|
3747
|
+
if (opts.fromBackup !== void 0 && client.target.kind !== "cloud") {
|
|
3748
|
+
await client.close();
|
|
3749
|
+
throw new KvboxError("backups are kept by the control plane; this machine has none (kvbox login first)");
|
|
3750
|
+
}
|
|
3545
3751
|
if (country !== void 0 && client.target.kind !== "cloud") {
|
|
3546
3752
|
await client.close();
|
|
3547
3753
|
throw new KvboxError("--country picks a host through the control plane; this machine is the only host here (kvbox login first)");
|
|
@@ -3551,23 +3757,29 @@ var newCommand = new Command("new").description("boot a new box from an image (t
|
|
|
3551
3757
|
throw new KvboxError("--host picks a host through the control plane; this machine is the only host here (kvbox login first)");
|
|
3552
3758
|
}
|
|
3553
3759
|
try {
|
|
3554
|
-
const what = opts.from !== void 0 ? `restoring ${name ?? "a new box"} from snapshot ${opts.from}\u2026` : `booting ${name ?? "a new box"}${opts.base !== void 0 && opts.base !== "base" ? ` from image ${opts.base}` : ""}\u2026`;
|
|
3760
|
+
const what = opts.fromBackup !== void 0 ? `restoring ${name ?? "a new box"} from backup ${opts.fromBackup}\u2026` : opts.from !== void 0 ? `restoring ${name ?? "a new box"} from snapshot ${opts.from}\u2026` : `booting ${name ?? "a new box"}${opts.base !== void 0 && opts.base !== "base" ? ` from image ${opts.base}` : ""}\u2026`;
|
|
3555
3761
|
const box2 = await spin(what, client.createMachine({
|
|
3556
3762
|
...name !== void 0 ? { name } : {},
|
|
3557
3763
|
...opts.size !== void 0 ? { size: opts.size } : {},
|
|
3558
3764
|
...opts.from !== void 0 ? { from: opts.from } : {},
|
|
3765
|
+
...opts.fromBackup !== void 0 ? { fromBackup: opts.fromBackup } : {},
|
|
3559
3766
|
...opts.base !== void 0 ? { image: opts.base } : {},
|
|
3560
3767
|
...env.length > 0 ? { env } : {},
|
|
3561
3768
|
...opts.near !== void 0 ? { near: opts.near } : {},
|
|
3562
3769
|
...country !== void 0 ? { country } : {},
|
|
3563
3770
|
...opts.host !== void 0 ? { host: opts.host } : {},
|
|
3564
3771
|
...autoHibernateSec !== void 0 ? { autoHibernateSec } : {},
|
|
3772
|
+
...integrations !== void 0 ? { integrations } : {},
|
|
3565
3773
|
...opts.force ? { force: true } : {}
|
|
3566
3774
|
}));
|
|
3775
|
+
if (opts.fromBackup !== void 0 && !box2.source.startsWith("backup:")) {
|
|
3776
|
+
throw new KvboxError(`this control plane does not know --from-backup yet: box ${box2.name} was made empty, not from backup ${opts.fromBackup}; remove it with: kvbox rm ${displayName(box2, me(client))}`);
|
|
3777
|
+
}
|
|
3567
3778
|
if (autoHibernateSec && !box2.autoHibernateSec) warn(`box ${name ?? box2.name}: its host runs a kvbox-server too old for auto-hibernate; it will not hibernate on its own`);
|
|
3568
3779
|
if (opts.base !== void 0 && opts.base !== "base" && box2.image === void 0) {
|
|
3569
3780
|
warn(`box ${box2.name}: its host runs a kvbox-server too old for images; it booted the base image, not ${opts.base}`);
|
|
3570
3781
|
}
|
|
3782
|
+
if (integrations?.length && !integrationsKept(integrations, box2)) warn(`box ${box2.name}: its host runs a kvbox-server too old for integrations; it has none`);
|
|
3571
3783
|
if (env.length > 0) {
|
|
3572
3784
|
const kept = await keptVars(client, displayName(box2, me(client)), env.map((v) => v.name));
|
|
3573
3785
|
if (kept === "too old") warn(`box ${box2.name}: its host runs a kvbox-server too old for a box's own variables; it has none of the -e ones`);
|
|
@@ -3582,8 +3794,13 @@ var newCommand = new Command("new").description("boot a new box from an image (t
|
|
|
3582
3794
|
`);
|
|
3583
3795
|
info(`${color.green("\u2713")} ${describe(box2, user)}`);
|
|
3584
3796
|
if (opts.from !== void 0) info(` connect with: kvbox connect ${displayName(box2, user)} (already up: everything that ran in the snapshot is running)`);
|
|
3797
|
+
else if (opts.fromBackup !== void 0) info(` connect with: kvbox connect ${displayName(box2, user)} (booting on the backup's disk: SSH is up a couple of seconds after)`);
|
|
3585
3798
|
else info(` connect with: kvbox connect ${displayName(box2, user)} (SSH is up a couple of seconds after boot)`);
|
|
3586
3799
|
if (box2.autoHibernateSec) info(` it ${autoHibernateText(box2.autoHibernateSec, box2.idleCheck)}`);
|
|
3800
|
+
if (box2.integrations?.length) {
|
|
3801
|
+
info(` integrations: ${integrationsText(box2.integrations)}`);
|
|
3802
|
+
await noteNotConnected(client, box2, box2.integrations);
|
|
3803
|
+
}
|
|
3587
3804
|
if (box2.connect !== void 0) {
|
|
3588
3805
|
info(` reach it at: ${box2.connect}`);
|
|
3589
3806
|
info(` from another box once linked: kvbox vm link <box> ${displayName(box2, user)} --port <port>`);
|
|
@@ -3994,6 +4211,7 @@ function getRows(box2, subs, user) {
|
|
|
3994
4211
|
const quiet = box2.idleCheck === void 0 ? "without network traffic" : `idle by ${box2.idleCheck}`;
|
|
3995
4212
|
rows2.push(["auto-hibernate", box2.autoHibernateSec ? `after ${duration(box2.autoHibernateSec)} ${quiet}` : "off"]);
|
|
3996
4213
|
if (!box2.autoHibernateSec && box2.idleCheck !== void 0) rows2.push(["idle check", `${box2.idleCheck} ${color.dim("(used once auto-hibernate is on)")}`]);
|
|
4214
|
+
rows2.push(["integrations", box2.integrations?.length ? box2.integrations.join(", ") : "-"]);
|
|
3997
4215
|
rows2.push(["source", box2.source]);
|
|
3998
4216
|
rows2.push(["base", box2.image === void 0 ? box2.base : `${box2.image} ${box2.base}`]);
|
|
3999
4217
|
rows2.push(["created", `${age(box2.createdAt)} ${color.dim(`(${box2.createdAt})`)}`]);
|
|
@@ -4579,8 +4797,7 @@ var lsCommand4 = new Command25("ls").alias("list").description("list backups: ev
|
|
|
4579
4797
|
const client = await clientFor(cmd.optsWithGlobals(), { autoStart: false });
|
|
4580
4798
|
try {
|
|
4581
4799
|
requireCloud3(client);
|
|
4582
|
-
const
|
|
4583
|
-
const list = box2 === void 0 ? await client.listBackups() : await client.boxBackups(box2);
|
|
4800
|
+
const { box: box2, list } = await backupsOf(client, name);
|
|
4584
4801
|
if (opts.json) {
|
|
4585
4802
|
json(list);
|
|
4586
4803
|
return;
|
|
@@ -4590,10 +4807,12 @@ var lsCommand4 = new Command25("ls").alias("list").description("list backups: ev
|
|
|
4590
4807
|
return;
|
|
4591
4808
|
}
|
|
4592
4809
|
const anyError = list.some((b) => b.error !== null);
|
|
4810
|
+
const anyRemoved = list.some((b) => b.boxRemoved === true);
|
|
4811
|
+
const removed = (b) => b.boxRemoved === true ? color.dim(" (removed)") : "";
|
|
4593
4812
|
table(
|
|
4594
4813
|
list.map((b) => ({
|
|
4595
4814
|
id: b.id,
|
|
4596
|
-
...box2 === void 0 ? { box: b.owner === me(client) ? b.box : `${b.owner}/${b.box}` } : {},
|
|
4815
|
+
...box2 === void 0 ? { box: (b.owner === me(client) ? b.box : `${b.owner}/${b.box}`) + removed(b) } : anyRemoved ? { of: b.boxRemoved === true ? color.dim("removed box") : "this box" } : {},
|
|
4597
4816
|
status: b.status === "ready" ? color.green(b.status) : b.status === "failed" ? color.red(b.status) : color.yellow(b.status),
|
|
4598
4817
|
data: b.dataBytes === null ? "-" : gbShort(b.dataBytes),
|
|
4599
4818
|
uploaded: b.uploadedBytes === null ? "-" : gbShort(b.uploadedBytes),
|
|
@@ -4603,10 +4822,31 @@ var lsCommand4 = new Command25("ls").alias("list").description("list backups: ev
|
|
|
4603
4822
|
...anyError ? { error: b.error ?? "" } : {}
|
|
4604
4823
|
}))
|
|
4605
4824
|
);
|
|
4825
|
+
if (anyRemoved) {
|
|
4826
|
+
const orgs = [...new Set(list.filter((b) => b.boxRemoved === true && slugOf(b.owner) !== me(client)).map((b) => slugOf(b.owner)))];
|
|
4827
|
+
info(`a removed box's backup makes a new box: kvbox new <name>${orgs.length === 1 ? ` --org ${orgs[0]}` : orgs.length > 1 ? " --org <org>" : ""} --from-backup <id>`);
|
|
4828
|
+
}
|
|
4606
4829
|
} finally {
|
|
4607
4830
|
await client.close();
|
|
4608
4831
|
}
|
|
4609
4832
|
});
|
|
4833
|
+
async function backupsOf(client, name) {
|
|
4834
|
+
if (name === void 0) return { box: void 0, list: await client.listBackups() };
|
|
4835
|
+
const live = pickRef(await boxesFor(client, name), name, me(client));
|
|
4836
|
+
if (live) {
|
|
4837
|
+
const box2 = displayName(live, me(client));
|
|
4838
|
+
return { box: box2, list: await client.boxBackups(box2) };
|
|
4839
|
+
}
|
|
4840
|
+
const [owner, bare] = name.includes("/") ? name.split("/", 2) : [void 0, name];
|
|
4841
|
+
const named = (await client.listBackups()).filter((b) => b.box === bare && (owner === void 0 || slugOf(b.owner) === owner));
|
|
4842
|
+
if (named.length === 0) throw new KvboxError(`box ${name}: not found (kvbox ls)`);
|
|
4843
|
+
if (owner !== void 0) return { box: name, list: named };
|
|
4844
|
+
const mine = named.filter((b) => slugOf(b.owner) === me(client));
|
|
4845
|
+
if (mine.length > 0) return { box: name, list: mine };
|
|
4846
|
+
const owners = [...new Set(named.map((b) => slugOf(b.owner)))];
|
|
4847
|
+
if (owners.length > 1) throw new AmbiguousRefError("box", bare, owners);
|
|
4848
|
+
return { box: `${owners[0]}/${bare}`, list: named };
|
|
4849
|
+
}
|
|
4610
4850
|
|
|
4611
4851
|
// src/commands/vm/backup/restore.ts
|
|
4612
4852
|
import { Command as Command26 } from "commander";
|
|
@@ -4807,14 +5047,16 @@ function runSwap(ep, mib) {
|
|
|
4807
5047
|
}
|
|
4808
5048
|
|
|
4809
5049
|
// src/commands/vm/set.ts
|
|
4810
|
-
var setCommand = new Command32("set").description("change a box's settings, e.g. --auto-hibernate 30m (off: never), --idle-check /home/kvbox/idle.sh, --swap 2G").argument("<name>", "box name").option("--auto-hibernate <duration>", "hibernate the box after this long without network traffic (30m, 4h, 1d; off: never)").option("--idle-check <script>", "a script in the box that exits 0 when it is idle, asked instead of network traffic (off: none)").option("--swap <size>", "a swap file on the box's disk for memory spikes such as a build (2G, 512M; off: none)").option("--json", "print the box as JSON").action(async (name, opts, cmd) => {
|
|
4811
|
-
if (opts.autoHibernate === void 0 && opts.idleCheck === void 0 && opts.swap === void 0) {
|
|
4812
|
-
throw new KvboxError("nothing to change: give --auto-hibernate, --idle-check or --swap");
|
|
5050
|
+
var setCommand = new Command32("set").description("change a box's settings, e.g. --auto-hibernate 30m (off: never), --idle-check /home/kvbox/idle.sh, --integration github, --swap 2G").argument("<name>", "box name").option("--auto-hibernate <duration>", "hibernate the box after this long without network traffic (30m, 4h, 1d; off: never)").option("--idle-check <script>", "a script in the box that exits 0 when it is idle, asked instead of network traffic (off: none)").option("--integration <list>", "the integrations turned on for the box, replacing its list, e.g. github (off: none)").option("--swap <size>", "a swap file on the box's disk for memory spikes such as a build (2G, 512M; off: none)").option("--json", "print the box as JSON").action(async (name, opts, cmd) => {
|
|
5051
|
+
if (opts.autoHibernate === void 0 && opts.idleCheck === void 0 && opts.integration === void 0 && opts.swap === void 0) {
|
|
5052
|
+
throw new KvboxError("nothing to change: give --auto-hibernate, --idle-check, --integration or --swap");
|
|
4813
5053
|
}
|
|
5054
|
+
const integrations = opts.integration === void 0 ? void 0 : parseIntegrationList(opts.integration);
|
|
4814
5055
|
const autoHibernateSec = opts.autoHibernate === void 0 ? void 0 : parseIdleTimeout(opts.autoHibernate);
|
|
4815
5056
|
const idleCheck = opts.idleCheck === void 0 ? void 0 : parseIdleCheck(opts.idleCheck);
|
|
4816
5057
|
const swapMib = opts.swap === void 0 ? void 0 : parseSwap(opts.swap);
|
|
4817
|
-
const
|
|
5058
|
+
const idleSettings = autoHibernateSec !== void 0 || idleCheck !== void 0;
|
|
5059
|
+
const hostSettings = idleSettings || integrations !== void 0;
|
|
4818
5060
|
const client = await clientFor(cmd.optsWithGlobals());
|
|
4819
5061
|
try {
|
|
4820
5062
|
const found = pickRef(await boxesFor(client, name), name, me(client));
|
|
@@ -4822,7 +5064,10 @@ var setCommand = new Command32("set").description("change a box's settings, e.g.
|
|
|
4822
5064
|
if (swapMib !== void 0 && found.status === "stopped") throw new KvboxError(`box ${name} is stopped; --swap is set up inside the box (kvbox start ${name})`);
|
|
4823
5065
|
let box2 = found;
|
|
4824
5066
|
if (hostSettings) {
|
|
4825
|
-
box2 = await spin(`updating ${name}\u2026`, client.setMachine(displayName(found, me(client)), { ...autoHibernateSec !== void 0 ? { autoHibernateSec } : {}, ...idleCheck !== void 0 ? { idleCheck } : {} }));
|
|
5067
|
+
box2 = await spin(`updating ${name}\u2026`, client.setMachine(displayName(found, me(client)), { ...autoHibernateSec !== void 0 ? { autoHibernateSec } : {}, ...idleCheck !== void 0 ? { idleCheck } : {}, ...integrations !== void 0 ? { integrations } : {} }));
|
|
5068
|
+
if (!integrationsKept(integrations, box2)) {
|
|
5069
|
+
throw new KvboxError(`box ${name}: its host runs a kvbox-server too old for integrations; it needs updating first${idleSettings ? " (the other settings were applied)" : ""}`);
|
|
5070
|
+
}
|
|
4826
5071
|
if (!idleCheckKept(idleCheck, box2)) {
|
|
4827
5072
|
throw new KvboxError(`box ${name}: its host runs a kvbox-server too old for --idle-check; it needs updating first${autoHibernateSec !== void 0 ? " (--auto-hibernate was applied)" : ""}`);
|
|
4828
5073
|
}
|
|
@@ -4832,7 +5077,11 @@ var setCommand = new Command32("set").description("change a box's settings, e.g.
|
|
|
4832
5077
|
json(swap === void 0 ? box2 : { ...box2, swap });
|
|
4833
5078
|
return;
|
|
4834
5079
|
}
|
|
4835
|
-
if (
|
|
5080
|
+
if (idleSettings) info(`${color.green("\u2713")} box ${color.bold(name)}: ${autoHibernateText(box2.autoHibernateSec, box2.idleCheck)}`);
|
|
5081
|
+
if (integrations !== void 0) {
|
|
5082
|
+
info(`${color.green("\u2713")} box ${color.bold(name)}: integrations ${integrationsText(box2.integrations)}${integrations.length > 0 && box2.status !== "running" ? color.dim(` (used once it runs)`) : ""}`);
|
|
5083
|
+
await noteNotConnected(client, box2, integrations);
|
|
5084
|
+
}
|
|
4836
5085
|
if (idleCheck && !box2.autoHibernateSec) info(color.dim(` the idle check is used once auto-hibernate is on: kvbox vm set ${name} --auto-hibernate 10m`));
|
|
4837
5086
|
if (swap) info(`${color.green("\u2713")} box ${color.bold(name)}: ${swapText(swap)}`);
|
|
4838
5087
|
} finally {
|
|
@@ -5339,12 +5588,48 @@ var rmCommand5 = new Command45("rm").alias("remove").description("remove an API
|
|
|
5339
5588
|
// src/commands/key/index.ts
|
|
5340
5589
|
var keyCommand = new Command46("key").aliases(["keys"]).description("API keys: named tokens a program (CI, an agent, the SDK) uses as KVBOX_TOKEN in place of a login").addCommand(createCommand3).addCommand(lsCommand5).addCommand(rmCommand5);
|
|
5341
5590
|
|
|
5591
|
+
// src/commands/integration/index.ts
|
|
5592
|
+
import { Command as Command48 } from "commander";
|
|
5593
|
+
|
|
5594
|
+
// src/commands/integration/ls.ts
|
|
5595
|
+
import { Command as Command47 } from "commander";
|
|
5596
|
+
var lsCommand6 = new Command47("ls").alias("list").description("list the accounts connected for your boxes (GitHub), per slug; connect one in the web app").option("--json", "print as JSON").action(async (opts, cmd) => {
|
|
5597
|
+
const client = await clientFor(cmd.optsWithGlobals(), { autoStart: false });
|
|
5598
|
+
try {
|
|
5599
|
+
if (client.target.kind !== "cloud") throw new KvboxError("integrations belong to an account on the kvbox cloud: kvbox login first");
|
|
5600
|
+
const rows2 = await client.listIntegrations();
|
|
5601
|
+
if (opts.json) {
|
|
5602
|
+
json(rows2);
|
|
5603
|
+
return;
|
|
5604
|
+
}
|
|
5605
|
+
const catalog = await catalogOf(client);
|
|
5606
|
+
const open = (r) => r.connected || connectable(catalog, r.integration, r.owner === me(client));
|
|
5607
|
+
table(
|
|
5608
|
+
rows2.map((r) => ({
|
|
5609
|
+
slug: r.owner,
|
|
5610
|
+
integration: r.integration,
|
|
5611
|
+
state: !open(r) ? color.dim("not for orgs yet") : !r.connected ? color.dim("not connected") : r.status === "needs-reconnect" ? color.yellow("connect again") : color.green("connected"),
|
|
5612
|
+
account: r.account ?? "-",
|
|
5613
|
+
connected: r.connectedAt === null ? "-" : age(r.connectedAt),
|
|
5614
|
+
"last used": r.connected ? r.lastUsedAt === null ? "never" : age(r.lastUsedAt) : "-"
|
|
5615
|
+
}))
|
|
5616
|
+
);
|
|
5617
|
+
if (rows2.some((r) => open(r) && (!r.connected || r.status === "needs-reconnect"))) info(color.dim(`connect an account ${whereToConnect(catalog)}`));
|
|
5618
|
+
if (rows2.some((r) => r.connected)) info(color.dim("turn one on for a box with: kvbox vm set <box> --integration github"));
|
|
5619
|
+
} finally {
|
|
5620
|
+
await client.close();
|
|
5621
|
+
}
|
|
5622
|
+
});
|
|
5623
|
+
|
|
5624
|
+
// src/commands/integration/index.ts
|
|
5625
|
+
var integrationCommand = new Command48("integration").aliases(["integrations"]).description("integrations: accounts (GitHub) connected once in the web app and turned on per box with --integration").addCommand(lsCommand6);
|
|
5626
|
+
|
|
5342
5627
|
// src/commands/snapshots/index.ts
|
|
5343
|
-
import { Command as
|
|
5628
|
+
import { Command as Command52 } from "commander";
|
|
5344
5629
|
|
|
5345
5630
|
// src/commands/snapshots/ls.ts
|
|
5346
|
-
import { Command as
|
|
5347
|
-
var
|
|
5631
|
+
import { Command as Command49 } from "commander";
|
|
5632
|
+
var lsCommand7 = new Command49("ls").description("list snapshots (yours and your orgs'; --org <slug> for one org)").option("-a, --all", "every snapshot on the platform (platform admins only)").option("--json", "print as JSON").action(async (opts, cmd) => {
|
|
5348
5633
|
const client = await clientFor(cmd.optsWithGlobals());
|
|
5349
5634
|
try {
|
|
5350
5635
|
const cloud = client.target.kind === "cloud";
|
|
@@ -5375,8 +5660,8 @@ var lsCommand6 = new Command47("ls").description("list snapshots (yours and your
|
|
|
5375
5660
|
});
|
|
5376
5661
|
|
|
5377
5662
|
// src/commands/snapshots/new.ts
|
|
5378
|
-
import { Command as
|
|
5379
|
-
var newCommand2 = new
|
|
5663
|
+
import { Command as Command50 } from "commander";
|
|
5664
|
+
var newCommand2 = new Command50("new").description("freeze a running box (memory + disk) into a snapshot; the box keeps running").argument("<box>", "box name").argument("<name>", "snapshot name").option("--replace", "retake a snapshot that exists under this name; the old one stays until the new one is complete").option("--json", "print the snapshot as JSON").action(async (box2, name, opts, cmd) => {
|
|
5380
5665
|
const client = await clientFor(cmd.optsWithGlobals());
|
|
5381
5666
|
try {
|
|
5382
5667
|
const req = { box: box2, name, ...opts.replace ? { replace: true } : {} };
|
|
@@ -5389,8 +5674,8 @@ var newCommand2 = new Command48("new").description("freeze a running box (memory
|
|
|
5389
5674
|
});
|
|
5390
5675
|
|
|
5391
5676
|
// src/commands/snapshots/rm.ts
|
|
5392
|
-
import { Command as
|
|
5393
|
-
var rmCommand6 = new
|
|
5677
|
+
import { Command as Command51 } from "commander";
|
|
5678
|
+
var rmCommand6 = new Command51("rm").description("delete a snapshot (boxes made from it are not affected)").argument("<name>", "snapshot name").option("-y, --yes", "do not ask for confirmation").action(async (name, opts, cmd) => {
|
|
5394
5679
|
if (!await confirm(`Delete snapshot ${name}?`, opts.yes ?? false)) {
|
|
5395
5680
|
info("cancelled");
|
|
5396
5681
|
process.exitCode = 1;
|
|
@@ -5406,14 +5691,14 @@ var rmCommand6 = new Command49("rm").description("delete a snapshot (boxes made
|
|
|
5406
5691
|
});
|
|
5407
5692
|
|
|
5408
5693
|
// src/commands/snapshots/index.ts
|
|
5409
|
-
var snapshotsCommand = new
|
|
5694
|
+
var snapshotsCommand = new Command52("snapshots").aliases(["snapshot", "snap"]).description("freeze running boxes into snapshots and manage them").addCommand(newCommand2).addCommand(lsCommand7).addCommand(rmCommand6);
|
|
5410
5695
|
for (const cmd of snapshotsCommand.commands) cmd.option("--org <slug>", "act in this org (- for your personal boxes)");
|
|
5411
5696
|
|
|
5412
5697
|
// src/commands/org/index.ts
|
|
5413
|
-
import { Command as
|
|
5698
|
+
import { Command as Command58 } from "commander";
|
|
5414
5699
|
|
|
5415
5700
|
// src/commands/org/ls.ts
|
|
5416
|
-
import { Command as
|
|
5701
|
+
import { Command as Command53 } from "commander";
|
|
5417
5702
|
|
|
5418
5703
|
// src/commands/org/context.ts
|
|
5419
5704
|
var NOT_LOGGED_IN2 = "orgs live on the control plane: kvbox login first";
|
|
@@ -5433,7 +5718,7 @@ function orgFor(opts, target) {
|
|
|
5433
5718
|
}
|
|
5434
5719
|
|
|
5435
5720
|
// src/commands/org/ls.ts
|
|
5436
|
-
var
|
|
5721
|
+
var lsCommand8 = new Command53("ls").description("list the orgs you belong to and your role in each").option("--json", "print as JSON").action(async (opts, cmd) => {
|
|
5437
5722
|
const client = await cloudClientFor(cmd.optsWithGlobals());
|
|
5438
5723
|
try {
|
|
5439
5724
|
const orgs = await client.listOrgs();
|
|
@@ -5455,8 +5740,8 @@ function orgRows(orgs) {
|
|
|
5455
5740
|
}
|
|
5456
5741
|
|
|
5457
5742
|
// src/commands/org/members.ts
|
|
5458
|
-
import { Command as
|
|
5459
|
-
var
|
|
5743
|
+
import { Command as Command54, Option as Option4 } from "commander";
|
|
5744
|
+
var lsCommand9 = new Command54("ls").description("list an org's members and their roles").option("-o, --org <slug>", "the org (or --org before the command)").option("--json", "print as JSON").action(async (opts, cmd) => {
|
|
5460
5745
|
const client = await cloudClientFor(cmd.optsWithGlobals());
|
|
5461
5746
|
try {
|
|
5462
5747
|
const org = await client.getOrg(orgFor(opts, client.target));
|
|
@@ -5470,7 +5755,7 @@ var lsCommand8 = new Command52("ls").description("list an org's members and thei
|
|
|
5470
5755
|
await client.close();
|
|
5471
5756
|
}
|
|
5472
5757
|
});
|
|
5473
|
-
var addCommand2 = new
|
|
5758
|
+
var addCommand2 = new Command54("add").description("add a user to an org (admins and owners; only an owner can add an owner)").argument("<user>", "their username").addOption(new Option4("-r, --role <role>", "their role").choices(ORG_ROLES).default("member")).option("-o, --org <slug>", "the org (or --org before the command)").action(async (user, opts, cmd) => {
|
|
5474
5759
|
const client = await cloudClientFor(cmd.optsWithGlobals());
|
|
5475
5760
|
try {
|
|
5476
5761
|
const slug = orgFor(opts, client.target);
|
|
@@ -5480,7 +5765,7 @@ var addCommand2 = new Command52("add").description("add a user to an org (admins
|
|
|
5480
5765
|
await client.close();
|
|
5481
5766
|
}
|
|
5482
5767
|
});
|
|
5483
|
-
var rmCommand7 = new
|
|
5768
|
+
var rmCommand7 = new Command54("rm").description("remove a member (or leave: remove yourself)").argument("<user>", "their username").option("-o, --org <slug>", "the org (or --org before the command)").option("-y, --yes", "do not ask for confirmation").action(async (user, opts, cmd) => {
|
|
5484
5769
|
const client = await cloudClientFor(cmd.optsWithGlobals());
|
|
5485
5770
|
try {
|
|
5486
5771
|
const slug = orgFor(opts, client.target);
|
|
@@ -5496,11 +5781,11 @@ var rmCommand7 = new Command52("rm").description("remove a member (or leave: rem
|
|
|
5496
5781
|
await client.close();
|
|
5497
5782
|
}
|
|
5498
5783
|
});
|
|
5499
|
-
var membersCommand = new
|
|
5784
|
+
var membersCommand = new Command54("members").description("who is in an org and what they may do").addCommand(lsCommand9).addCommand(addCommand2).addCommand(rmCommand7);
|
|
5500
5785
|
|
|
5501
5786
|
// src/commands/org/new.ts
|
|
5502
|
-
import { Command as
|
|
5503
|
-
var newCommand3 = new
|
|
5787
|
+
import { Command as Command55 } from "commander";
|
|
5788
|
+
var newCommand3 = new Command55("new").description("create an org; you become its owner (the slug is permanent, the name is not)").argument("<slug>", "the org's slug: lowercase, like a username (acme)").option("-n, --name <name>", "display name (default: the slug)").option("--json", "print the org as JSON").action(async (slug, opts, cmd) => {
|
|
5504
5789
|
const client = await cloudClientFor(cmd.optsWithGlobals());
|
|
5505
5790
|
try {
|
|
5506
5791
|
const org = await client.createOrg({ slug, name: opts.name ?? slug });
|
|
@@ -5516,8 +5801,8 @@ var newCommand3 = new Command53("new").description("create an org; you become it
|
|
|
5516
5801
|
});
|
|
5517
5802
|
|
|
5518
5803
|
// src/commands/org/rm.ts
|
|
5519
|
-
import { Command as
|
|
5520
|
-
var rmCommand8 = new
|
|
5804
|
+
import { Command as Command56 } from "commander";
|
|
5805
|
+
var rmCommand8 = new Command56("rm").description("delete an org (owners only; remove its boxes and snapshots first)").argument("<slug>", "the org").option("-y, --yes", "do not ask for confirmation").action(async (slug, opts, cmd) => {
|
|
5521
5806
|
if (!await confirm(`Delete org ${slug}? Its members lose access; its slug stays taken.`, opts.yes ?? false)) {
|
|
5522
5807
|
info("cancelled");
|
|
5523
5808
|
process.exitCode = 1;
|
|
@@ -5533,8 +5818,8 @@ var rmCommand8 = new Command54("rm").description("delete an org (owners only; re
|
|
|
5533
5818
|
});
|
|
5534
5819
|
|
|
5535
5820
|
// src/commands/org/role.ts
|
|
5536
|
-
import { Argument, Command as
|
|
5537
|
-
var roleCommand = new
|
|
5821
|
+
import { Argument, Command as Command57 } from "commander";
|
|
5822
|
+
var roleCommand = new Command57("role").description("change a member's role (owners only)").argument("<user>", "their username").addArgument(new Argument("<role>", "owner, admin or member").choices(ORG_ROLES)).option("-o, --org <slug>", "the org (default: the current context)").action(async (user, role, opts, cmd) => {
|
|
5538
5823
|
const client = await cloudClientFor(cmd.optsWithGlobals());
|
|
5539
5824
|
try {
|
|
5540
5825
|
const slug = orgFor(opts, client.target);
|
|
@@ -5546,11 +5831,11 @@ var roleCommand = new Command55("role").description("change a member's role (own
|
|
|
5546
5831
|
});
|
|
5547
5832
|
|
|
5548
5833
|
// src/commands/org/index.ts
|
|
5549
|
-
var orgCommand = new
|
|
5834
|
+
var orgCommand = new Command58("org").description("orgs: shared slugs that own boxes, with owners, admins and members").addCommand(lsCommand8).addCommand(newCommand3).addCommand(membersCommand).addCommand(roleCommand).addCommand(rmCommand8);
|
|
5550
5835
|
|
|
5551
5836
|
// src/commands/usage.ts
|
|
5552
|
-
import { Command as
|
|
5553
|
-
var usageCommand2 = new
|
|
5837
|
+
import { Command as Command59 } from "commander";
|
|
5838
|
+
var usageCommand2 = new Command59("usage").description("what your boxes and volumes used this month (or --since/--until): running time, vCPU-h, RAM and disk GiB-h, cost").option("--since <date>", "count from this date, e.g. 2026-10-01 (default: the 1st of this month)").option("--until <date>", "count up to this date (default: now)").option("--org <slug>", "one org's boxes only").option("-a, --all", "every box on the platform (platform admins only)").option("--by-user", "one line per user who made the boxes (e.g. who spent what in --org)").option("--json", "print as JSON").action(async (opts, cmd) => {
|
|
5554
5839
|
for (const [name, value] of [
|
|
5555
5840
|
["since", opts.since],
|
|
5556
5841
|
["until", opts.until]
|
|
@@ -5747,8 +6032,8 @@ function userRows(r) {
|
|
|
5747
6032
|
}
|
|
5748
6033
|
|
|
5749
6034
|
// src/commands/credit.ts
|
|
5750
|
-
import { Command as
|
|
5751
|
-
var creditCommand = new
|
|
6035
|
+
import { Command as Command60 } from "commander";
|
|
6036
|
+
var creditCommand = new Command60("credit").description("the prepaid credit left on your account and on each of your orgs").option("--org <slug>", "one org only").option("--json", "print as JSON").action(async (opts, cmd) => {
|
|
5752
6037
|
const client = await clientFor(cmd.optsWithGlobals(), { autoStart: false });
|
|
5753
6038
|
try {
|
|
5754
6039
|
if (client.target.kind === "local") throw new KvboxError("credit lives on the control plane: kvbox login first");
|
|
@@ -5777,8 +6062,8 @@ function creditRow(b, me2) {
|
|
|
5777
6062
|
}
|
|
5778
6063
|
|
|
5779
6064
|
// src/commands/redeem.ts
|
|
5780
|
-
import { Command as
|
|
5781
|
-
var redeemCommand = new
|
|
6065
|
+
import { Command as Command61 } from "commander";
|
|
6066
|
+
var redeemCommand = new Command61("redeem").description("redeem a promo code for credit, on your account or (--org) an org you own").argument("<code>", "the code, like KV-7F3K-9QXM-2HBD").option("--org <slug>", "give the credit to this org, which you own; it cannot be moved later").option("--json", "print as JSON").action(async (code, opts, cmd) => {
|
|
5782
6067
|
const client = await clientFor(cmd.optsWithGlobals(), { autoStart: false });
|
|
5783
6068
|
try {
|
|
5784
6069
|
if (client.target.kind === "local") throw new KvboxError("codes are redeemed on the control plane: kvbox login first");
|
|
@@ -5798,12 +6083,12 @@ var redeemCommand = new Command59("redeem").description("redeem a promo code for
|
|
|
5798
6083
|
// src/commands/deploy/index.ts
|
|
5799
6084
|
import { access as access5, readFile as readFile7 } from "fs/promises";
|
|
5800
6085
|
import { basename as basename2, resolve as resolve3 } from "path";
|
|
5801
|
-
import { Command as
|
|
6086
|
+
import { Command as Command62, InvalidArgumentError as InvalidArgumentError2, Option as Option5 } from "commander";
|
|
5802
6087
|
|
|
5803
6088
|
// src/commands/deploy/config.ts
|
|
5804
6089
|
import { readFile as readFile5, writeFile as writeFile3 } from "fs/promises";
|
|
5805
6090
|
import { isAbsolute, join as join6, normalize, relative as relative2 } from "path";
|
|
5806
|
-
import { z as
|
|
6091
|
+
import { z as z14 } from "zod";
|
|
5807
6092
|
|
|
5808
6093
|
// src/commands/deploy/templates/docker.ts
|
|
5809
6094
|
import { readFile as readFile4 } from "fs/promises";
|
|
@@ -6227,21 +6512,21 @@ function detectTemplates(pkg, dir = NO_FACTS) {
|
|
|
6227
6512
|
var DEPLOY_AUTO_HIBERNATE_SEC = 3600;
|
|
6228
6513
|
var CONFIG_FILE = "kvbox.json";
|
|
6229
6514
|
var BOX_NAME_RE = /^[a-z0-9][a-z0-9-]{0,11}$/;
|
|
6230
|
-
var DeployConfigSchema =
|
|
6231
|
-
template:
|
|
6232
|
-
name:
|
|
6515
|
+
var DeployConfigSchema = z14.object({
|
|
6516
|
+
template: z14.enum(TEMPLATE_IDS),
|
|
6517
|
+
name: z14.string().regex(BOX_NAME_RE, "1-12 chars, lowercase letters, digits and '-', starting with a letter or digit"),
|
|
6233
6518
|
/** The org whose box it is; absent for the user's own. */
|
|
6234
|
-
org:
|
|
6519
|
+
org: z14.string().regex(ORG_SLUG_RE, "not an org slug").optional(),
|
|
6235
6520
|
/** The HTTPS name (`<subdomain>.kvbox.app`); absent when deploying to this machine's own host. */
|
|
6236
|
-
subdomain:
|
|
6521
|
+
subdomain: z14.string().check((ctx) => {
|
|
6237
6522
|
const problem = subdomainProblem(ctx.value);
|
|
6238
6523
|
if (problem) ctx.issues.push({ code: "custom", message: problem, input: ctx.value });
|
|
6239
6524
|
}).optional(),
|
|
6240
|
-
size:
|
|
6525
|
+
size: z14.enum(SIZE_NAMES).optional(),
|
|
6241
6526
|
/** The build output directory, relative to the app; the template's default when absent. */
|
|
6242
|
-
dist:
|
|
6527
|
+
dist: z14.string().optional(),
|
|
6243
6528
|
/** The port a Next.js app or Node server serves; the template's (3000) when absent. */
|
|
6244
|
-
port:
|
|
6529
|
+
port: z14.number().int().min(1).max(65535).optional()
|
|
6245
6530
|
});
|
|
6246
6531
|
var SERVICE_KEY_RE = /^[a-z][a-z0-9-]{0,19}$/;
|
|
6247
6532
|
var RESERVED_SERVICE_KEYS = ["app", "agent", "init", "volumes"];
|
|
@@ -6253,38 +6538,38 @@ var POSTGRES_PORT = 5432;
|
|
|
6253
6538
|
var POSTGRES_IMAGE = "postgres:17";
|
|
6254
6539
|
var POSTGRES_ENV = "DATABASE_URL";
|
|
6255
6540
|
var IMAGE_RE = /^[a-z0-9][a-z0-9._/:@-]*$/;
|
|
6256
|
-
var ServiceSchema =
|
|
6257
|
-
template:
|
|
6541
|
+
var ServiceSchema = z14.strictObject({
|
|
6542
|
+
template: z14.enum([...TEMPLATE_IDS, POSTGRES]),
|
|
6258
6543
|
/** The service's directory, relative to the one holding kvbox.json; every template but postgres has one. */
|
|
6259
|
-
dir:
|
|
6544
|
+
dir: z14.string().min(1).optional(),
|
|
6260
6545
|
/** A postgres service's image, `postgres:17` when absent (`pgvector/pgvector:pg17` for vectors). */
|
|
6261
|
-
image:
|
|
6546
|
+
image: z14.string().regex(IMAGE_RE, "an image name like postgres:17").optional(),
|
|
6262
6547
|
/** The volume (a key of `volumes`) a postgres service keeps its data on. */
|
|
6263
|
-
volume:
|
|
6548
|
+
volume: z14.string().optional(),
|
|
6264
6549
|
/** The box variable a postgres service's URL is written to, `DATABASE_URL` when absent. */
|
|
6265
|
-
env:
|
|
6550
|
+
env: z14.string().optional(),
|
|
6266
6551
|
/** 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`. */
|
|
6267
|
-
context:
|
|
6268
|
-
dist:
|
|
6552
|
+
context: z14.string().min(1).optional(),
|
|
6553
|
+
dist: z14.string().optional(),
|
|
6269
6554
|
/**
|
|
6270
6555
|
* A command run once per deploy in the service's new version (a docker service: in a container of
|
|
6271
6556
|
* the new image; node, nextjs: in the new source, installed and built), with the box's variables,
|
|
6272
6557
|
* before it replaces the running one. Migrations, mostly. A failing one stops that service's deploy.
|
|
6273
6558
|
*/
|
|
6274
|
-
release:
|
|
6559
|
+
release: z14.string().optional(),
|
|
6275
6560
|
/** The box port of a service with its own server; the template's (3000) when absent. */
|
|
6276
|
-
port:
|
|
6561
|
+
port: z14.number().int().min(1).max(65535).optional(),
|
|
6277
6562
|
/** The URL paths that go to this service, each with everything under it; the prefix is kept. */
|
|
6278
|
-
paths:
|
|
6563
|
+
paths: z14.array(z14.string().regex(ROUTE_RE, "a path like / or /api, no trailing slash")).min(1).optional()
|
|
6279
6564
|
});
|
|
6280
|
-
var StackConfigSchema =
|
|
6565
|
+
var StackConfigSchema = z14.strictObject({
|
|
6281
6566
|
name: DeployConfigSchema.shape.name.optional(),
|
|
6282
6567
|
org: DeployConfigSchema.shape.org,
|
|
6283
6568
|
subdomain: DeployConfigSchema.shape.subdomain,
|
|
6284
6569
|
size: DeployConfigSchema.shape.size,
|
|
6285
6570
|
/** The stack's volumes, name to size ("10GB"): made for its box and attached to it on the first deploy that needs one. */
|
|
6286
|
-
volumes:
|
|
6287
|
-
services:
|
|
6571
|
+
volumes: z14.record(z14.string(), z14.string()).optional(),
|
|
6572
|
+
services: z14.record(z14.string(), ServiceSchema)
|
|
6288
6573
|
});
|
|
6289
6574
|
function volumeGib(text2) {
|
|
6290
6575
|
const mib = parseMib(text2);
|
|
@@ -7063,7 +7348,7 @@ async function readPackageJson(dir) {
|
|
|
7063
7348
|
}
|
|
7064
7349
|
|
|
7065
7350
|
// src/commands/deploy/index.ts
|
|
7066
|
-
var deployCommand = new
|
|
7351
|
+
var deployCommand = new Command62("deploy").description("put the app in this directory (React, Next.js, a Node server, a Dockerfile or a static site) on a box with its own HTTPS address; redeploy by running it again").argument("[dir]", "the app's directory (default: the current one)").addOption(new Option5("-t, --template <template>", "what kind of app it is (detected from package.json and the directory when not given)").choices(TEMPLATE_IDS)).option("-n, --name <name>", "the box's name (default: the directory's name)").option("--sub <subdomain>", "its HTTPS name, https://<subdomain>.kvbox.app (default: the box's name)").addOption(new Option5("-s, --size <size>", "size of the box when it has to be made").choices(SIZE_NAMES)).option("--port <port>", "the box port of a Next.js app, Node server or container (default 3000; saved to kvbox.json)", parsePort).option("--only <service>", "with several services in kvbox.json: deploy this one only (repeatable)", (v, all) => [...all ?? [], v]).option("-y, --yes", "ask nothing: take the defaults for whatever the flags and kvbox.json leave open").option("--json", "print the result as JSON").option("--org <slug>", "deploy into this org's boxes (saved to kvbox.json)").action(async (dirArg, opts, cmd) => {
|
|
7067
7352
|
const dir = resolve3(dirArg ?? ".");
|
|
7068
7353
|
const pkg = await readPackageJson2(dir);
|
|
7069
7354
|
const facts = { indexHtml: await exists2(resolve3(dir, "index.html")), dockerfile: await exists2(resolve3(dir, "Dockerfile")) };
|
|
@@ -7220,15 +7505,15 @@ async function settle2(dir, pkg, facts, saved, opts, orgFlag, cloud) {
|
|
|
7220
7505
|
}
|
|
7221
7506
|
|
|
7222
7507
|
// src/commands/volume/index.ts
|
|
7223
|
-
import { Command as
|
|
7508
|
+
import { Command as Command74 } from "commander";
|
|
7224
7509
|
|
|
7225
7510
|
// src/commands/volume/attach.ts
|
|
7226
|
-
import { Command as
|
|
7511
|
+
import { Command as Command63 } from "commander";
|
|
7227
7512
|
function describeMount(machine, volume2, box2) {
|
|
7228
7513
|
const path = machine.volumes?.find((v) => volume2 === v.name || volume2.endsWith(`/${v.name}`))?.mountPath ?? volumeMountPath(volume2.slice(volume2.lastIndexOf("/") + 1));
|
|
7229
7514
|
return machine.status === "running" ? ` the box was restarted; the volume is at ${path} inside it` : ` box ${box2} is ${machine.status}; the volume is at ${path} once it runs`;
|
|
7230
7515
|
}
|
|
7231
|
-
var attachCommand = new
|
|
7516
|
+
var attachCommand = new Command63("attach").description("attach a volume to a box at /mnt/<volume> (a running box is restarted to take it)").argument("[volume]", "volume name (picked from a list when left out)").argument("[box]", "box name (picked from a list when left out)").option("--json", "print the box as JSON").action(async (volumeArg, boxArg, opts, cmd) => {
|
|
7232
7517
|
if (volumeArg === void 0 || boxArg === void 0) askOrUsage("give the volume and the box: kvbox volume attach <volume> <box>");
|
|
7233
7518
|
const client = await clientFor(cmd.optsWithGlobals());
|
|
7234
7519
|
try {
|
|
@@ -7247,11 +7532,11 @@ var attachCommand = new Command61("attach").description("attach a volume to a bo
|
|
|
7247
7532
|
});
|
|
7248
7533
|
|
|
7249
7534
|
// src/commands/volume/backup/index.ts
|
|
7250
|
-
import { Command as
|
|
7535
|
+
import { Command as Command68 } from "commander";
|
|
7251
7536
|
|
|
7252
7537
|
// src/commands/volume/backup/create.ts
|
|
7253
|
-
import { Command as
|
|
7254
|
-
var createCommand4 = new
|
|
7538
|
+
import { Command as Command64 } from "commander";
|
|
7539
|
+
var createCommand4 = new Command64("create").description("back up a volume's disk to the kvbox cloud (encrypted)").argument("<volume>", "volume name").option("--wait", "stay until the backup is ready (by default it runs in the background)").option("--json", "print the backup as JSON").action(async (volume2, opts, cmd) => {
|
|
7255
7540
|
const client = await clientFor(cmd.optsWithGlobals(), { autoStart: false });
|
|
7256
7541
|
try {
|
|
7257
7542
|
requireCloud3(client);
|
|
@@ -7278,8 +7563,8 @@ var createCommand4 = new Command62("create").description("back up a volume's dis
|
|
|
7278
7563
|
});
|
|
7279
7564
|
|
|
7280
7565
|
// src/commands/volume/backup/ls.ts
|
|
7281
|
-
import { Command as
|
|
7282
|
-
var
|
|
7566
|
+
import { Command as Command65 } from "commander";
|
|
7567
|
+
var lsCommand10 = new Command65("ls").alias("list").description("list volume backups: every volume's, or one volume's").argument("[volume]", "volume name (default: every volume)").option("--json", "print as JSON").action(async (volume2, opts, cmd) => {
|
|
7283
7568
|
const client = await clientFor(cmd.optsWithGlobals(), { autoStart: false });
|
|
7284
7569
|
try {
|
|
7285
7570
|
requireCloud3(client);
|
|
@@ -7312,8 +7597,8 @@ var lsCommand9 = new Command63("ls").alias("list").description("list volume back
|
|
|
7312
7597
|
});
|
|
7313
7598
|
|
|
7314
7599
|
// src/commands/volume/backup/restore.ts
|
|
7315
|
-
import { Command as
|
|
7316
|
-
var restoreCommand2 = new
|
|
7600
|
+
import { Command as Command66 } from "commander";
|
|
7601
|
+
var restoreCommand2 = new Command66("restore").description("put a backup back: the volume's data becomes the backup's (a running box holding it restarts)").argument("<volume>", "volume name").argument("<id>", "the backup's id (kvbox volume backup ls <volume>)").option("-y, --yes", "do not ask for confirmation").option("--json", "print the volume as JSON").action(async (volume2, id, opts, cmd) => {
|
|
7317
7602
|
const client = await clientFor(cmd.optsWithGlobals(), { autoStart: false });
|
|
7318
7603
|
try {
|
|
7319
7604
|
requireCloud3(client);
|
|
@@ -7336,8 +7621,8 @@ var restoreCommand2 = new Command64("restore").description("put a backup back: t
|
|
|
7336
7621
|
});
|
|
7337
7622
|
|
|
7338
7623
|
// src/commands/volume/backup/rm.ts
|
|
7339
|
-
import { Command as
|
|
7340
|
-
var rmCommand9 = new
|
|
7624
|
+
import { Command as Command67 } from "commander";
|
|
7625
|
+
var rmCommand9 = new Command67("rm").alias("remove").description("remove a backup for good (a volume's that is gone too)").argument("<volume>", "volume name").argument("<id>", "the backup's id (kvbox volume backup ls <volume>)").option("-y, --yes", "do not ask for confirmation").action(async (volume2, id, opts, cmd) => {
|
|
7341
7626
|
const client = await clientFor(cmd.optsWithGlobals(), { autoStart: false });
|
|
7342
7627
|
try {
|
|
7343
7628
|
requireCloud3(client);
|
|
@@ -7348,11 +7633,11 @@ var rmCommand9 = new Command65("rm").alias("remove").description("remove a backu
|
|
|
7348
7633
|
});
|
|
7349
7634
|
|
|
7350
7635
|
// src/commands/volume/backup/index.ts
|
|
7351
|
-
var backupCommand2 = new
|
|
7636
|
+
var backupCommand2 = new Command68("backup").description("back up a volume's disk to the kvbox cloud, list backups, restore or remove one").addCommand(createCommand4).addCommand(lsCommand10).addCommand(restoreCommand2).addCommand(rmCommand9);
|
|
7352
7637
|
for (const cmd of backupCommand2.commands) cmd.option("--org <slug>", "act in this org (- for your personal volumes)");
|
|
7353
7638
|
|
|
7354
7639
|
// src/commands/volume/create.ts
|
|
7355
|
-
import { Command as
|
|
7640
|
+
import { Command as Command69 } from "commander";
|
|
7356
7641
|
function parseGib2(text2, label = "--size") {
|
|
7357
7642
|
const mib = parseMib(text2);
|
|
7358
7643
|
if (mib === void 0 || mib % 1024 !== 0) throw new KvboxError(`${label} ${text2}: write whole GB, like 50 or 50GB`);
|
|
@@ -7368,7 +7653,7 @@ function sizeProblem(answer) {
|
|
|
7368
7653
|
return err instanceof KvboxError ? err.message.replace(/^--size \S+: /, "") : String(err);
|
|
7369
7654
|
}
|
|
7370
7655
|
}
|
|
7371
|
-
var createCommand5 = new
|
|
7656
|
+
var createCommand5 = new Command69("create").alias("new").description("create a volume for a box: an empty disk of its own at /mnt/<name> inside it (a running box is restarted)").argument("[name]", "volume name (1-12 chars; the box mounts it at /mnt/<name>; asked for when left out)").option("--size <gb>", "size in GB, like 50 or 50GB (whole GB; it only occupies what is written)").option("--box <box>", "the box it is for: made on that box's host and attached to it (required on kvbox.sh; optional with --local)").option("--json", "print the volume as JSON").action(async (nameArg, opts, cmd) => {
|
|
7372
7657
|
const ask = interactive();
|
|
7373
7658
|
if (nameArg === void 0 || opts.size === void 0) askOrUsage("give the name and the size: kvbox volume create <name> --size <gb> --box <box>");
|
|
7374
7659
|
const name = nameArg ?? await text("Volume name", { validate: (a) => VOLUME_NAME_RE.test(a) ? void 0 : VOLUME_NAME_RULE });
|
|
@@ -7401,8 +7686,8 @@ var createCommand5 = new Command67("create").alias("new").description("create a
|
|
|
7401
7686
|
});
|
|
7402
7687
|
|
|
7403
7688
|
// src/commands/volume/detach.ts
|
|
7404
|
-
import { Command as
|
|
7405
|
-
var detachCommand = new
|
|
7689
|
+
import { Command as Command70 } from "commander";
|
|
7690
|
+
var detachCommand = new Command70("detach").description("detach a volume from a box; its data is kept (a running box is restarted)").argument("[volume]", "volume name (picked from a list when left out)").argument("[box]", "box name (the one the volume is on when left out)").option("--json", "print the box as JSON").action(async (volumeArg, boxArg, opts, cmd) => {
|
|
7406
7691
|
if (volumeArg === void 0) askOrUsage("give the volume: kvbox volume detach <volume> [box]");
|
|
7407
7692
|
const client = await clientFor(cmd.optsWithGlobals());
|
|
7408
7693
|
try {
|
|
@@ -7427,8 +7712,8 @@ var detachCommand = new Command68("detach").description("detach a volume from a
|
|
|
7427
7712
|
});
|
|
7428
7713
|
|
|
7429
7714
|
// src/commands/volume/grow.ts
|
|
7430
|
-
import { Command as
|
|
7431
|
-
var growCommand = new
|
|
7715
|
+
import { Command as Command71 } from "commander";
|
|
7716
|
+
var growCommand = new Command71("grow").alias("resize").description("make a volume larger (a running box holding it is restarted once)").argument("<volume>", "volume name").argument("<GB>", "the new size in GB, larger than what it has").option("--json", "print the volume as JSON").action(async (name, size, opts, cmd) => {
|
|
7432
7717
|
const sizeGib = parseGib2(size, "size");
|
|
7433
7718
|
const client = await clientFor(cmd.optsWithGlobals());
|
|
7434
7719
|
try {
|
|
@@ -7441,8 +7726,8 @@ var growCommand = new Command69("grow").alias("resize").description("make a volu
|
|
|
7441
7726
|
});
|
|
7442
7727
|
|
|
7443
7728
|
// src/commands/volume/ls.ts
|
|
7444
|
-
import { Command as
|
|
7445
|
-
var
|
|
7729
|
+
import { Command as Command72 } from "commander";
|
|
7730
|
+
var lsCommand11 = new Command72("ls").alias("list").description("list volumes: size, what they occupy, which box has them").option("-a, --all", "every volume on the platform (platform admins only)").option("--json", "print as JSON").action(async (opts, cmd) => {
|
|
7446
7731
|
const client = await clientFor(cmd.optsWithGlobals());
|
|
7447
7732
|
try {
|
|
7448
7733
|
const cloud = client.target.kind === "cloud";
|
|
@@ -7473,8 +7758,8 @@ var lsCommand10 = new Command70("ls").alias("list").description("list volumes: s
|
|
|
7473
7758
|
});
|
|
7474
7759
|
|
|
7475
7760
|
// src/commands/volume/rm.ts
|
|
7476
|
-
import { Command as
|
|
7477
|
-
var rmCommand10 = new
|
|
7761
|
+
import { Command as Command73 } from "commander";
|
|
7762
|
+
var rmCommand10 = new Command73("rm").alias("remove").description("delete a volume and everything on it (detach it first)").argument("<name>", "volume name").option("-y, --yes", "do not ask for confirmation").action(async (name, opts, cmd) => {
|
|
7478
7763
|
if (!await confirm(`Delete volume ${name} and everything on it?`, opts.yes ?? false)) {
|
|
7479
7764
|
info("cancelled");
|
|
7480
7765
|
process.exitCode = 1;
|
|
@@ -7490,18 +7775,18 @@ var rmCommand10 = new Command71("rm").alias("remove").description("delete a volu
|
|
|
7490
7775
|
});
|
|
7491
7776
|
|
|
7492
7777
|
// src/commands/volume/index.ts
|
|
7493
|
-
var volumeCommand = new
|
|
7778
|
+
var volumeCommand = new Command74("volume").aliases(["volumes", "vol"]).description("disks of their own: create one, attach it to a box at /mnt/<name>, move it to another box later").addCommand(createCommand5).addCommand(lsCommand11).addCommand(attachCommand).addCommand(detachCommand).addCommand(growCommand).addCommand(rmCommand10);
|
|
7494
7779
|
for (const cmd of volumeCommand.commands) cmd.option("--org <slug>", "act in this org (- for your personal volumes)");
|
|
7495
7780
|
volumeCommand.addCommand(backupCommand2);
|
|
7496
7781
|
|
|
7497
7782
|
// src/commands/bucket/index.ts
|
|
7498
|
-
import { Command as
|
|
7783
|
+
import { Command as Command90 } from "commander";
|
|
7499
7784
|
|
|
7500
7785
|
// src/commands/bucket/backup/index.ts
|
|
7501
|
-
import { Command as
|
|
7786
|
+
import { Command as Command79 } from "commander";
|
|
7502
7787
|
|
|
7503
7788
|
// src/commands/bucket/backup/create.ts
|
|
7504
|
-
import { Command as
|
|
7789
|
+
import { Command as Command75 } from "commander";
|
|
7505
7790
|
|
|
7506
7791
|
// src/commands/bucket/shared.ts
|
|
7507
7792
|
async function bucketClient(cmd) {
|
|
@@ -7527,7 +7812,7 @@ function printRows(rows2) {
|
|
|
7527
7812
|
}
|
|
7528
7813
|
|
|
7529
7814
|
// src/commands/bucket/backup/create.ts
|
|
7530
|
-
var createCommand6 = new
|
|
7815
|
+
var createCommand6 = new Command75("create").description("back up your object storage (every bucket and key) to the kvbox cloud, encrypted").option("--wait", "stay until the backup is ready (by default it runs in the background)").option("--json", "print the backup as JSON").action(async (opts, cmd) => {
|
|
7531
7816
|
const client = await bucketClient(cmd);
|
|
7532
7817
|
const ls = "kvbox bucket backup ls";
|
|
7533
7818
|
try {
|
|
@@ -7555,8 +7840,8 @@ var createCommand6 = new Command73("create").description("back up your object st
|
|
|
7555
7840
|
});
|
|
7556
7841
|
|
|
7557
7842
|
// src/commands/bucket/backup/ls.ts
|
|
7558
|
-
import { Command as
|
|
7559
|
-
var
|
|
7843
|
+
import { Command as Command76 } from "commander";
|
|
7844
|
+
var lsCommand12 = new Command76("ls").alias("list").description("list the backups of your object storage").option("--json", "print as JSON").action(async (opts, cmd) => {
|
|
7560
7845
|
const client = await bucketClient(cmd);
|
|
7561
7846
|
try {
|
|
7562
7847
|
const list = await client.storageBackups();
|
|
@@ -7588,8 +7873,8 @@ var lsCommand11 = new Command74("ls").alias("list").description("list the backup
|
|
|
7588
7873
|
});
|
|
7589
7874
|
|
|
7590
7875
|
// src/commands/bucket/backup/restore.ts
|
|
7591
|
-
import { Command as
|
|
7592
|
-
var restoreCommand3 = new
|
|
7876
|
+
import { Command as Command77 } from "commander";
|
|
7877
|
+
var restoreCommand3 = new Command77("restore").description("put a backup back: every bucket and key becomes the backup's (the storage restarts)").argument("<id>", "the backup's id (kvbox bucket backup ls)").option("-y, --yes", "do not ask for confirmation").option("--json", "print what changed as JSON").action(async (id, opts, cmd) => {
|
|
7593
7878
|
const client = await bucketClient(cmd);
|
|
7594
7879
|
try {
|
|
7595
7880
|
const backup = await client.storageBackup(id);
|
|
@@ -7619,8 +7904,8 @@ var restoreCommand3 = new Command75("restore").description("put a backup back: e
|
|
|
7619
7904
|
});
|
|
7620
7905
|
|
|
7621
7906
|
// src/commands/bucket/backup/rm.ts
|
|
7622
|
-
import { Command as
|
|
7623
|
-
var rmCommand11 = new
|
|
7907
|
+
import { Command as Command78 } from "commander";
|
|
7908
|
+
var rmCommand11 = new Command78("rm").alias("remove").description("remove a backup of your object storage for good").argument("<id>", "the backup's id (kvbox bucket backup ls)").option("-y, --yes", "do not ask for confirmation").action(async (id, opts, cmd) => {
|
|
7624
7909
|
const client = await bucketClient(cmd);
|
|
7625
7910
|
try {
|
|
7626
7911
|
const backup = (await client.storageBackups()).find((b) => b.id === id);
|
|
@@ -7639,11 +7924,11 @@ var rmCommand11 = new Command76("rm").alias("remove").description("remove a back
|
|
|
7639
7924
|
});
|
|
7640
7925
|
|
|
7641
7926
|
// src/commands/bucket/backup/index.ts
|
|
7642
|
-
var backupCommand3 = new
|
|
7927
|
+
var backupCommand3 = new Command79("backup").aliases(["backups"]).description("back up your object storage to the kvbox cloud, list backups, restore or remove one").addCommand(createCommand6).addCommand(lsCommand12).addCommand(restoreCommand3).addCommand(rmCommand11);
|
|
7643
7928
|
|
|
7644
7929
|
// src/commands/bucket/create.ts
|
|
7645
|
-
import { Command as
|
|
7646
|
-
var createCommand7 = new
|
|
7930
|
+
import { Command as Command80 } from "commander";
|
|
7931
|
+
var createCommand7 = new Command80("create").description("make a bucket (the first one also makes your object storage)").argument("<name>", "bucket name: 3-63 lowercase letters, digits and '-'").option("--size <GB>", "how much your object storage may hold, when this is your first bucket (default 10)").option("--region <region>", "the S3 region of your object storage (ro-west-1, de-center-1), when this is your first bucket").option("--near <box>", "put the object storage on the host of this box, when this is your first bucket").option("--json", "print as JSON").action(async (name, opts, cmd) => {
|
|
7647
7932
|
const sizeGib = opts.size === void 0 ? void 0 : parseGib2(opts.size);
|
|
7648
7933
|
const client = await bucketClient(cmd);
|
|
7649
7934
|
try {
|
|
@@ -7663,8 +7948,8 @@ var createCommand7 = new Command78("create").description("make a bucket (the fir
|
|
|
7663
7948
|
});
|
|
7664
7949
|
|
|
7665
7950
|
// src/commands/bucket/grow.ts
|
|
7666
|
-
import { Command as
|
|
7667
|
-
var growCommand2 = new
|
|
7951
|
+
import { Command as Command81 } from "commander";
|
|
7952
|
+
var growCommand2 = new Command81("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) => {
|
|
7668
7953
|
const sizeGib = parseGib2(size, "size");
|
|
7669
7954
|
const client = await bucketClient(cmd);
|
|
7670
7955
|
try {
|
|
@@ -7677,8 +7962,8 @@ var growCommand2 = new Command79("grow").description("make your object storage l
|
|
|
7677
7962
|
});
|
|
7678
7963
|
|
|
7679
7964
|
// src/commands/bucket/info.ts
|
|
7680
|
-
import { Command as
|
|
7681
|
-
var infoCommand = new
|
|
7965
|
+
import { Command as Command82 } from "commander";
|
|
7966
|
+
var infoCommand = new Command82("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) => {
|
|
7682
7967
|
const client = await bucketClient(cmd);
|
|
7683
7968
|
try {
|
|
7684
7969
|
const b = await client.getBucket(name);
|
|
@@ -7692,6 +7977,7 @@ var infoCommand = new Command80("info").description("one bucket: its address, wh
|
|
|
7692
7977
|
["name", color.bold(shown)],
|
|
7693
7978
|
["endpoint", endpointText(b.endpoint)],
|
|
7694
7979
|
["region", `${b.region} ${color.dim("(path-style addressing)")}`],
|
|
7980
|
+
["public", b.publicUrl === void 0 ? color.dim(`no (kvbox bucket public ${shown} on)`) : `${b.publicUrl}/<key> ${color.dim("(anyone can read every object)")}`],
|
|
7695
7981
|
["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)}`],
|
|
7696
7982
|
["keys", b.keys === 0 ? color.dim(`none (kvbox bucket key create ${shown})`) : `${b.keys} ${color.dim(`(kvbox bucket key ls ${shown})`)}`],
|
|
7697
7983
|
["storage", `${fullness(s)}, ${s.buckets} ${s.buckets === 1 ? "bucket" : "buckets"}${nearlyFull(s) ? color.yellow(" almost full: kvbox bucket grow <GB>") : ""}`],
|
|
@@ -7707,11 +7993,11 @@ with the AWS CLI: aws s3 ls s3://${b.name} --endpoint-url ${b.endpoint}`));
|
|
|
7707
7993
|
});
|
|
7708
7994
|
|
|
7709
7995
|
// src/commands/bucket/key/index.ts
|
|
7710
|
-
import { Command as
|
|
7996
|
+
import { Command as Command86 } from "commander";
|
|
7711
7997
|
|
|
7712
7998
|
// src/commands/bucket/key/create.ts
|
|
7713
|
-
import { Command as
|
|
7714
|
-
var createCommand8 = new
|
|
7999
|
+
import { Command as Command83 } from "commander";
|
|
8000
|
+
var createCommand8 = new Command83("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) => {
|
|
7715
8001
|
const client = await bucketClient(cmd);
|
|
7716
8002
|
try {
|
|
7717
8003
|
const key = await client.createBucketKey(bucket, { ...opts.name !== void 0 ? { name: opts.name } : {}, ...opts.readOnly ? { readOnly: true } : {} });
|
|
@@ -7734,8 +8020,8 @@ var createCommand8 = new Command81("create").description("make an access key for
|
|
|
7734
8020
|
});
|
|
7735
8021
|
|
|
7736
8022
|
// src/commands/bucket/key/ls.ts
|
|
7737
|
-
import { Command as
|
|
7738
|
-
var
|
|
8023
|
+
import { Command as Command84 } from "commander";
|
|
8024
|
+
var lsCommand13 = new Command84("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) => {
|
|
7739
8025
|
const client = await bucketClient(cmd);
|
|
7740
8026
|
try {
|
|
7741
8027
|
const keys = await client.listBucketKeys(bucket);
|
|
@@ -7754,8 +8040,8 @@ var lsCommand12 = new Command82("ls").alias("list").description("list a bucket's
|
|
|
7754
8040
|
});
|
|
7755
8041
|
|
|
7756
8042
|
// src/commands/bucket/key/rm.ts
|
|
7757
|
-
import { Command as
|
|
7758
|
-
var rmCommand12 = new
|
|
8043
|
+
import { Command as Command85 } from "commander";
|
|
8044
|
+
var rmCommand12 = new Command85("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) => {
|
|
7759
8045
|
const client = await bucketClient(cmd);
|
|
7760
8046
|
try {
|
|
7761
8047
|
if (!await confirm(`Delete key ${id} of bucket ${bucket}? Whatever uses it stops working.`, opts.yes ?? false)) {
|
|
@@ -7771,11 +8057,11 @@ var rmCommand12 = new Command83("rm").alias("remove").description("delete an acc
|
|
|
7771
8057
|
});
|
|
7772
8058
|
|
|
7773
8059
|
// src/commands/bucket/key/index.ts
|
|
7774
|
-
var keyCommand2 = new
|
|
8060
|
+
var keyCommand2 = new Command86("key").aliases(["keys"]).description("access keys of a bucket: what your app signs in with").addCommand(createCommand8).addCommand(lsCommand13).addCommand(rmCommand12);
|
|
7775
8061
|
|
|
7776
8062
|
// src/commands/bucket/ls.ts
|
|
7777
|
-
import { Command as
|
|
7778
|
-
var
|
|
8063
|
+
import { Command as Command87 } from "commander";
|
|
8064
|
+
var lsCommand14 = new Command87("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) => {
|
|
7779
8065
|
const client = await bucketClient(cmd);
|
|
7780
8066
|
try {
|
|
7781
8067
|
const buckets = await client.listBuckets({ all: opts.all });
|
|
@@ -7793,6 +8079,7 @@ var lsCommand13 = new Command85("ls").alias("list").description("list buckets, a
|
|
|
7793
8079
|
owner: b.owner === me2 ? "private" : b.owner,
|
|
7794
8080
|
name: b.name,
|
|
7795
8081
|
keys: b.keys,
|
|
8082
|
+
public: b.publicUrl ?? "-",
|
|
7796
8083
|
created: age(b.createdAt)
|
|
7797
8084
|
}))
|
|
7798
8085
|
);
|
|
@@ -7804,9 +8091,38 @@ var lsCommand13 = new Command85("ls").alias("list").description("list buckets, a
|
|
|
7804
8091
|
}
|
|
7805
8092
|
});
|
|
7806
8093
|
|
|
8094
|
+
// src/commands/bucket/public.ts
|
|
8095
|
+
import { Command as Command88 } from "commander";
|
|
8096
|
+
var publicCommand = new Command88("public").description("let anyone read a bucket's files at its own HTTPS address (on), or make it private again (off)").argument("<name>", "bucket name").argument("<state>", "on (public) or off (private)").option("--sub <name>", "the address to use, <name>.kvbox.app (default: <bucket>-<account>)").option("--json", "print the bucket as JSON").action(async (name, state, opts, cmd) => {
|
|
8097
|
+
if (state !== "on" && state !== "off") throw new KvboxError(`"${state}": say on or off`);
|
|
8098
|
+
const on = state === "on";
|
|
8099
|
+
if (!on && opts.sub !== void 0) throw new KvboxError("--sub goes with on");
|
|
8100
|
+
if (opts.sub !== void 0) assertSubdomain(opts.sub.trim().toLowerCase());
|
|
8101
|
+
const client = await bucketClient(cmd);
|
|
8102
|
+
try {
|
|
8103
|
+
const b = await spin(
|
|
8104
|
+
on ? `making bucket ${name} public\u2026` : `making bucket ${name} private\u2026`,
|
|
8105
|
+
client.setBucketPublic(name, { on, ...opts.sub !== void 0 ? { sub: opts.sub } : {} })
|
|
8106
|
+
);
|
|
8107
|
+
if (opts.json) {
|
|
8108
|
+
json(b);
|
|
8109
|
+
return;
|
|
8110
|
+
}
|
|
8111
|
+
const shown = shownName(b, client);
|
|
8112
|
+
if (b.publicUrl === void 0) {
|
|
8113
|
+
info(`${color.green("\u2713")} bucket ${color.bold(shown)} is private: its files open only with a key or a signed link`);
|
|
8114
|
+
return;
|
|
8115
|
+
}
|
|
8116
|
+
info(`${color.green("\u2713")} anyone can now read the files of bucket ${color.bold(shown)} at ${color.bold(`${b.publicUrl}/<key>`)}`);
|
|
8117
|
+
info(color.dim(` e.g. ${b.publicUrl}/images/logo.png for the object images/logo.png. Files are never listed. Undo with: kvbox bucket public ${shown} off`));
|
|
8118
|
+
} finally {
|
|
8119
|
+
await client.close();
|
|
8120
|
+
}
|
|
8121
|
+
});
|
|
8122
|
+
|
|
7807
8123
|
// src/commands/bucket/rm.ts
|
|
7808
|
-
import { Command as
|
|
7809
|
-
var rmCommand13 = new
|
|
8124
|
+
import { Command as Command89 } from "commander";
|
|
8125
|
+
var rmCommand13 = new Command89("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) => {
|
|
7810
8126
|
const client = await bucketClient(cmd);
|
|
7811
8127
|
try {
|
|
7812
8128
|
const question = opts.force ? `Delete bucket ${name} with everything in it, and the object storage it is in?` : `Delete bucket ${name} and its keys?`;
|
|
@@ -7825,7 +8141,7 @@ var rmCommand13 = new Command86("rm").alias("remove").description("delete an emp
|
|
|
7825
8141
|
});
|
|
7826
8142
|
|
|
7827
8143
|
// src/commands/bucket/index.ts
|
|
7828
|
-
var bucketCommand = new
|
|
8144
|
+
var bucketCommand = new Command90("bucket").aliases(["buckets"]).description("object storage: S3 buckets for your files, and the access keys your apps use").addCommand(createCommand7).addCommand(lsCommand14).addCommand(infoCommand).addCommand(growCommand2).addCommand(publicCommand).addCommand(rmCommand13).addCommand(keyCommand2).addCommand(backupCommand3);
|
|
7829
8145
|
var withOrg = (cmd) => cmd.option("--org <slug>", "act in this org (- for your personal buckets)");
|
|
7830
8146
|
for (const cmd of bucketCommand.commands) {
|
|
7831
8147
|
if (cmd === keyCommand2 || cmd === backupCommand3) cmd.commands.forEach(withOrg);
|
|
@@ -7833,10 +8149,10 @@ for (const cmd of bucketCommand.commands) {
|
|
|
7833
8149
|
}
|
|
7834
8150
|
|
|
7835
8151
|
// src/commands/cron/index.ts
|
|
7836
|
-
import { Command as
|
|
8152
|
+
import { Command as Command103 } from "commander";
|
|
7837
8153
|
|
|
7838
8154
|
// src/commands/cron/create.ts
|
|
7839
|
-
import { Command as
|
|
8155
|
+
import { Command as Command91 } from "commander";
|
|
7840
8156
|
|
|
7841
8157
|
// src/commands/cron/shared.ts
|
|
7842
8158
|
async function cronClient(cmd) {
|
|
@@ -7897,7 +8213,7 @@ function printRows2(rows2) {
|
|
|
7897
8213
|
var noTriggers = (service) => info(`cron service ${service} has no triggers yet; add one with: kvbox cron trigger add ${service} <box> "0 6 * * *" --port 3000 (or --run "<command>")`);
|
|
7898
8214
|
|
|
7899
8215
|
// src/commands/cron/create.ts
|
|
7900
|
-
var createCommand9 = new
|
|
8216
|
+
var createCommand9 = new Command91("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) => {
|
|
7901
8217
|
const client = await cronClient(cmd);
|
|
7902
8218
|
try {
|
|
7903
8219
|
const service = await client.createCronService(name);
|
|
@@ -7914,8 +8230,8 @@ var createCommand9 = new Command88("create").description("make a cron service: a
|
|
|
7914
8230
|
});
|
|
7915
8231
|
|
|
7916
8232
|
// src/commands/cron/info.ts
|
|
7917
|
-
import { Command as
|
|
7918
|
-
var infoCommand2 = new
|
|
8233
|
+
import { Command as Command92 } from "commander";
|
|
8234
|
+
var infoCommand2 = new Command92("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) => {
|
|
7919
8235
|
const client = await cronClient(cmd);
|
|
7920
8236
|
try {
|
|
7921
8237
|
const service = await client.getCronService(name);
|
|
@@ -7939,8 +8255,8 @@ var infoCommand2 = new Command89("info").alias("get").description("show a cron s
|
|
|
7939
8255
|
});
|
|
7940
8256
|
|
|
7941
8257
|
// src/commands/cron/ls.ts
|
|
7942
|
-
import { Command as
|
|
7943
|
-
var
|
|
8258
|
+
import { Command as Command93 } from "commander";
|
|
8259
|
+
var lsCommand15 = new Command93("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) => {
|
|
7944
8260
|
const client = await cronClient(cmd);
|
|
7945
8261
|
try {
|
|
7946
8262
|
const services = await client.listCronServices({ all: opts.all });
|
|
@@ -7960,8 +8276,8 @@ var lsCommand14 = new Command90("ls").alias("list").description("list cron servi
|
|
|
7960
8276
|
});
|
|
7961
8277
|
|
|
7962
8278
|
// src/commands/cron/rm.ts
|
|
7963
|
-
import { Command as
|
|
7964
|
-
var rmCommand14 = new
|
|
8279
|
+
import { Command as Command94 } from "commander";
|
|
8280
|
+
var rmCommand14 = new Command94("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) => {
|
|
7965
8281
|
const client = await cronClient(cmd);
|
|
7966
8282
|
try {
|
|
7967
8283
|
if (!await confirm(`Delete cron service ${name}? Its triggers stop firing and their run history is deleted.`, opts.yes ?? false)) {
|
|
@@ -7977,10 +8293,10 @@ var rmCommand14 = new Command91("rm").alias("remove").description("delete a cron
|
|
|
7977
8293
|
});
|
|
7978
8294
|
|
|
7979
8295
|
// src/commands/cron/trigger/index.ts
|
|
7980
|
-
import { Command as
|
|
8296
|
+
import { Command as Command102 } from "commander";
|
|
7981
8297
|
|
|
7982
8298
|
// src/commands/cron/trigger/add.ts
|
|
7983
|
-
import { Command as
|
|
8299
|
+
import { Command as Command95 } from "commander";
|
|
7984
8300
|
function portOf(value) {
|
|
7985
8301
|
const n = Number(value);
|
|
7986
8302
|
if (!Number.isInteger(n) || n < 1 || n > 65535) throw new KvboxError(`--port ${value}: a port is a number from 1 to 65535`);
|
|
@@ -8000,7 +8316,7 @@ function timeoutOf(value) {
|
|
|
8000
8316
|
if (sec > MAX_CRON_COMMAND_TIMEOUT_SEC) throw new KvboxError(`--timeout ${value}: a command may run for ${MAX_CRON_COMMAND_TIMEOUT_SEC / 60} minutes at most`);
|
|
8001
8317
|
return sec;
|
|
8002
8318
|
}
|
|
8003
|
-
var addCommand3 = new
|
|
8319
|
+
var addCommand3 = new Command95("add").description("add a trigger: on a schedule, call a port of a box or run a command in it").argument("<service>", "cron service name").argument("<box>", "the box it acts on").argument("<expr>", 'cron expression in quotes, five fields: "0 6 * * *" is every day at 06:00').option("--port <n>", "call this port, the one your app listens on in the box").option("--path <path>", "with --port: path and query to request (default: /)").option("--method <method>", `with --port: HTTP method, ${CRON_METHODS.join(" or ")} (default: POST)`).option("--run <command>", 'or run this command in the box, in quotes: "node ~/app/embed.js"').option("--timeout <duration>", `with --run: stop the command after this long (90s, 10m, 1h; default: ${DEFAULT_CRON_COMMAND_TIMEOUT_SEC / 60}m)`).option("--tz <zone>", "time zone the schedule is read in, like Europe/Bucharest", "UTC").option("--json", "print as JSON").action(async (service, box2, expr, opts, cmd) => {
|
|
8004
8320
|
let action;
|
|
8005
8321
|
if (opts.run !== void 0) {
|
|
8006
8322
|
if (opts.port !== void 0 || opts.path !== void 0 || opts.method !== void 0) throw new KvboxError("a trigger runs a command or calls a port: use --run, or --port with --path and --method, not both");
|
|
@@ -8027,8 +8343,8 @@ var addCommand3 = new Command92("add").description("add a trigger: on a schedule
|
|
|
8027
8343
|
});
|
|
8028
8344
|
|
|
8029
8345
|
// src/commands/cron/trigger/ls.ts
|
|
8030
|
-
import { Command as
|
|
8031
|
-
var
|
|
8346
|
+
import { Command as Command96 } from "commander";
|
|
8347
|
+
var lsCommand16 = new Command96("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) => {
|
|
8032
8348
|
const client = await cronClient(cmd);
|
|
8033
8349
|
try {
|
|
8034
8350
|
const triggers = await client.listCronTriggers(service);
|
|
@@ -8044,8 +8360,8 @@ var lsCommand15 = new Command93("ls").alias("list").description("list a cron ser
|
|
|
8044
8360
|
});
|
|
8045
8361
|
|
|
8046
8362
|
// src/commands/cron/trigger/pause.ts
|
|
8047
|
-
import { Command as
|
|
8048
|
-
var pauseCommand2 = new
|
|
8363
|
+
import { Command as Command97 } from "commander";
|
|
8364
|
+
var pauseCommand2 = new Command97("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) => {
|
|
8049
8365
|
const client = await cronClient(cmd);
|
|
8050
8366
|
try {
|
|
8051
8367
|
const trigger = await client.setCronTriggerEnabled(service, id, false);
|
|
@@ -8060,8 +8376,8 @@ var pauseCommand2 = new Command94("pause").description("stop a trigger from firi
|
|
|
8060
8376
|
});
|
|
8061
8377
|
|
|
8062
8378
|
// src/commands/cron/trigger/resume.ts
|
|
8063
|
-
import { Command as
|
|
8064
|
-
var resumeCommand2 = new
|
|
8379
|
+
import { Command as Command98 } from "commander";
|
|
8380
|
+
var resumeCommand2 = new Command98("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) => {
|
|
8065
8381
|
const client = await cronClient(cmd);
|
|
8066
8382
|
try {
|
|
8067
8383
|
const trigger = await client.setCronTriggerEnabled(service, id, true);
|
|
@@ -8076,8 +8392,8 @@ var resumeCommand2 = new Command95("resume").description("let a paused trigger f
|
|
|
8076
8392
|
});
|
|
8077
8393
|
|
|
8078
8394
|
// src/commands/cron/trigger/rm.ts
|
|
8079
|
-
import { Command as
|
|
8080
|
-
var rmCommand15 = new
|
|
8395
|
+
import { Command as Command99 } from "commander";
|
|
8396
|
+
var rmCommand15 = new Command99("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) => {
|
|
8081
8397
|
const client = await cronClient(cmd);
|
|
8082
8398
|
try {
|
|
8083
8399
|
if (!await confirm(`Delete trigger ${id} of cron service ${service}? Its run history is deleted too.`, opts.yes ?? false)) {
|
|
@@ -8093,8 +8409,8 @@ var rmCommand15 = new Command96("rm").alias("remove").description("delete a trig
|
|
|
8093
8409
|
});
|
|
8094
8410
|
|
|
8095
8411
|
// src/commands/cron/trigger/run.ts
|
|
8096
|
-
import { Command as
|
|
8097
|
-
var runCommand = new
|
|
8412
|
+
import { Command as Command100 } from "commander";
|
|
8413
|
+
var runCommand = new Command100("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) => {
|
|
8098
8414
|
const client = await cronClient(cmd);
|
|
8099
8415
|
try {
|
|
8100
8416
|
const trigger = await client.runCronTrigger(service, id);
|
|
@@ -8110,13 +8426,13 @@ var runCommand = new Command97("run").description("fire a trigger now, once, bes
|
|
|
8110
8426
|
});
|
|
8111
8427
|
|
|
8112
8428
|
// src/commands/cron/trigger/runs.ts
|
|
8113
|
-
import { Command as
|
|
8429
|
+
import { Command as Command101 } from "commander";
|
|
8114
8430
|
function limitOf(value) {
|
|
8115
8431
|
const n = Number(value);
|
|
8116
8432
|
if (!Number.isInteger(n) || n < 1) throw new KvboxError(`-n ${value}: a number of runs, 1 or more`);
|
|
8117
8433
|
return n;
|
|
8118
8434
|
}
|
|
8119
|
-
var runsCommand = new
|
|
8435
|
+
var runsCommand = new Command101("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) => {
|
|
8120
8436
|
const limit = limitOf(opts.limit);
|
|
8121
8437
|
const client = await cronClient(cmd);
|
|
8122
8438
|
try {
|
|
@@ -8146,10 +8462,10 @@ var runsCommand = new Command98("runs").aliases(["logs"]).description("show how
|
|
|
8146
8462
|
});
|
|
8147
8463
|
|
|
8148
8464
|
// src/commands/cron/trigger/index.ts
|
|
8149
|
-
var triggerCommand = new
|
|
8465
|
+
var triggerCommand = new Command102("trigger").aliases(["triggers"]).description("a cron service's triggers: a schedule and the request it sends to a box").addCommand(addCommand3).addCommand(lsCommand16).addCommand(runsCommand).addCommand(runCommand).addCommand(pauseCommand2).addCommand(resumeCommand2).addCommand(rmCommand15);
|
|
8150
8466
|
|
|
8151
8467
|
// src/commands/cron/index.ts
|
|
8152
|
-
var cronCommand = new
|
|
8468
|
+
var cronCommand = new Command103("cron").description("cron: call a box on a schedule, waking it first if it sleeps").addCommand(createCommand9).addCommand(lsCommand15).addCommand(infoCommand2).addCommand(rmCommand14).addCommand(triggerCommand);
|
|
8153
8469
|
var withOrg2 = (cmd) => cmd.option("--org <slug>", "act in this org (- for your personal cron services)");
|
|
8154
8470
|
for (const cmd of cronCommand.commands) {
|
|
8155
8471
|
if (cmd === triggerCommand) cmd.commands.forEach(withOrg2);
|
|
@@ -8157,13 +8473,13 @@ for (const cmd of cronCommand.commands) {
|
|
|
8157
8473
|
}
|
|
8158
8474
|
|
|
8159
8475
|
// src/commands/managed/kind.ts
|
|
8160
|
-
import { Command as
|
|
8476
|
+
import { Command as Command122 } from "commander";
|
|
8161
8477
|
|
|
8162
8478
|
// src/commands/managed/backup/index.ts
|
|
8163
|
-
import { Command as
|
|
8479
|
+
import { Command as Command110 } from "commander";
|
|
8164
8480
|
|
|
8165
8481
|
// src/commands/managed/backup/create.ts
|
|
8166
|
-
import { Command as
|
|
8482
|
+
import { Command as Command105 } from "commander";
|
|
8167
8483
|
|
|
8168
8484
|
// src/commands/managed/shared.ts
|
|
8169
8485
|
import "commander";
|
|
@@ -8261,7 +8577,7 @@ function parseStorage(text2, flag) {
|
|
|
8261
8577
|
}
|
|
8262
8578
|
|
|
8263
8579
|
// src/commands/managed/backup/create.ts
|
|
8264
|
-
var createCommand10 = (spec) => new
|
|
8580
|
+
var createCommand10 = (spec) => new Command105("create").description("back up a database to the kvbox cloud (encrypted)").argument("<db>", "its name").option("--wait", "stay until the backup is ready (by default it runs in the background)").option("--json", "print the backup as JSON").action(async (name, opts, cmd) => {
|
|
8265
8581
|
const client = await managedClient(cmd);
|
|
8266
8582
|
const ls = `kvbox ${spec.command} backup ls ${name}`;
|
|
8267
8583
|
try {
|
|
@@ -8288,8 +8604,8 @@ var createCommand10 = (spec) => new Command102("create").description("back up a
|
|
|
8288
8604
|
});
|
|
8289
8605
|
|
|
8290
8606
|
// src/commands/managed/backup/ls.ts
|
|
8291
|
-
import { Command as
|
|
8292
|
-
var
|
|
8607
|
+
import { Command as Command106 } from "commander";
|
|
8608
|
+
var lsCommand17 = (spec) => {
|
|
8293
8609
|
const removedOnes = async (err, name, client) => {
|
|
8294
8610
|
if (!(err instanceof CallError && err.status === 404)) throw err;
|
|
8295
8611
|
const gone = (await client.listManagedBackups(spec.kind)).filter((b) => b.name === name || `${b.owner}/${b.name}` === name);
|
|
@@ -8297,7 +8613,7 @@ var lsCommand16 = (spec) => {
|
|
|
8297
8613
|
const own = name.includes("/") ? [] : gone.filter((b) => b.owner === me(client));
|
|
8298
8614
|
return own.length > 0 ? own : gone;
|
|
8299
8615
|
};
|
|
8300
|
-
return new
|
|
8616
|
+
return new Command106("ls").alias("list").description("list backups: every database's, or one database's").argument("[db]", "its name (default: every database)").option("--json", "print as JSON").action(async (name, opts, cmd) => {
|
|
8301
8617
|
const client = await managedClient(cmd);
|
|
8302
8618
|
try {
|
|
8303
8619
|
const list = name === void 0 ? await client.listManagedBackups(spec.kind) : await client.managedBackups(spec.kind, name).catch((err) => removedOnes(err, name, client));
|
|
@@ -8340,8 +8656,8 @@ var lsCommand16 = (spec) => {
|
|
|
8340
8656
|
};
|
|
8341
8657
|
|
|
8342
8658
|
// src/commands/managed/backup/restore.ts
|
|
8343
|
-
import { Command as
|
|
8344
|
-
var restoreCommand4 = (spec) => new
|
|
8659
|
+
import { Command as Command107 } from "commander";
|
|
8660
|
+
var restoreCommand4 = (spec) => new Command107("restore").description("put a backup back: the database's data becomes the backup's (it restarts)").argument("<db>", "its name").argument("<id>", `the backup's id (kvbox ${spec.command} backup ls <db>)`).option("-y, --yes", "do not ask for confirmation").option("--json", "print the database as JSON").action(async (name, id, opts, cmd) => {
|
|
8345
8661
|
const client = await managedClient(cmd);
|
|
8346
8662
|
try {
|
|
8347
8663
|
const backup = await client.managedBackup(spec.kind, name, id);
|
|
@@ -8363,8 +8679,8 @@ var restoreCommand4 = (spec) => new Command104("restore").description("put a bac
|
|
|
8363
8679
|
});
|
|
8364
8680
|
|
|
8365
8681
|
// src/commands/managed/backup/rm.ts
|
|
8366
|
-
import { Command as
|
|
8367
|
-
var rmCommand16 = (spec) => new
|
|
8682
|
+
import { Command as Command108 } from "commander";
|
|
8683
|
+
var rmCommand16 = (spec) => new Command108("rm").alias("remove").description("remove a backup for good (a database's that is gone too)").argument("<db>", "its name").argument("<id>", `the backup's id (kvbox ${spec.command} backup ls <db>)`).option("-y, --yes", "do not ask for confirmation").action(async (name, id, opts, cmd) => {
|
|
8368
8684
|
const client = await managedClient(cmd);
|
|
8369
8685
|
try {
|
|
8370
8686
|
await removeListed(client, await client.listManagedBackups(spec.kind), (b) => b.name, name, id, `database ${name}`, opts.yes ?? false);
|
|
@@ -8374,8 +8690,8 @@ var rmCommand16 = (spec) => new Command105("rm").alias("remove").description("re
|
|
|
8374
8690
|
});
|
|
8375
8691
|
|
|
8376
8692
|
// src/commands/managed/backup/schedule.ts
|
|
8377
|
-
import { Command as
|
|
8378
|
-
var scheduleCommand = (spec) => new
|
|
8693
|
+
import { Command as Command109 } from "commander";
|
|
8694
|
+
var scheduleCommand = (spec) => new Command109("schedule").description("show or change when a database is backed up on its own (daily, UTC)").argument("<db>", "its name").option("--at <hour>", "back it up daily at this hour, 0-23 UTC (turns it on)").option("--off", "stop backing it up on its own").option("--on", "back it up on its own again, at the hour it had").option("--json", "print the schedule as JSON").action(async (name, opts, cmd) => {
|
|
8379
8695
|
if (opts.off && (opts.on || opts.at !== void 0)) throw new KvboxError("--off takes neither --on nor --at");
|
|
8380
8696
|
const hour = opts.at === void 0 ? void 0 : parseHour(opts.at);
|
|
8381
8697
|
const client = await managedClient(cmd);
|
|
@@ -8405,18 +8721,18 @@ function parseHour(text2) {
|
|
|
8405
8721
|
|
|
8406
8722
|
// src/commands/managed/backup/index.ts
|
|
8407
8723
|
var backupCommand4 = (spec) => {
|
|
8408
|
-
const command = new
|
|
8409
|
-
for (const make of [createCommand10,
|
|
8724
|
+
const command = new Command110("backup").description("back up a database to the kvbox cloud, list backups, restore or remove one, or change its nightly schedule");
|
|
8725
|
+
for (const make of [createCommand10, lsCommand17, restoreCommand4, rmCommand16, scheduleCommand]) command.addCommand(make(spec).option("--org <slug>", "act in this org (- for your personal databases)"));
|
|
8410
8726
|
return command;
|
|
8411
8727
|
};
|
|
8412
8728
|
|
|
8413
8729
|
// src/commands/managed/create.ts
|
|
8414
|
-
import { Command as
|
|
8730
|
+
import { Command as Command111 } from "commander";
|
|
8415
8731
|
import { setTimeout as sleep5 } from "timers/promises";
|
|
8416
8732
|
var READY_WAIT_MS = 9e4;
|
|
8417
8733
|
var READY_STEP_MS = 2e3;
|
|
8418
8734
|
var createCommand11 = (spec) => {
|
|
8419
|
-
const command = new
|
|
8735
|
+
const command = new Command111("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");
|
|
8420
8736
|
for (const o of spec.options) command.option(`--${o.name} <${o.arg}>`, o.help);
|
|
8421
8737
|
return command.option("--password <password>", "its password (default: generated)").option("--storage <gb>", `storage for the data in GB (default: ${spec.storageGib}; it can grow later)`).option("--near <box>", "run it on the host of this box, so the box can be linked to it").option("--from-backup <id>", `start it on this backup's data, a removed database's too (kvbox ${spec.command} backup ls)`).option("--json", "print it as JSON, password included").action(async (name, opts, cmd) => {
|
|
8422
8738
|
const options = Object.fromEntries(spec.options.flatMap((o) => typeof opts[o.name] === "string" ? [[o.name, opts[o.name]]] : []));
|
|
@@ -8465,8 +8781,8 @@ var createCommand11 = (spec) => {
|
|
|
8465
8781
|
};
|
|
8466
8782
|
|
|
8467
8783
|
// src/commands/managed/grow.ts
|
|
8468
|
-
import { Command as
|
|
8469
|
-
var growCommand3 = (spec) => new
|
|
8784
|
+
import { Command as Command112 } from "commander";
|
|
8785
|
+
var growCommand3 = (spec) => new Command112("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) => {
|
|
8470
8786
|
const storageGib = parseStorage(size, "size");
|
|
8471
8787
|
const client = await managedClient(cmd);
|
|
8472
8788
|
try {
|
|
@@ -8479,8 +8795,8 @@ var growCommand3 = (spec) => new Command109("grow").description("give a database
|
|
|
8479
8795
|
});
|
|
8480
8796
|
|
|
8481
8797
|
// src/commands/managed/info.ts
|
|
8482
|
-
import { Command as
|
|
8483
|
-
var infoCommand3 = (spec) => new
|
|
8798
|
+
import { Command as Command113 } from "commander";
|
|
8799
|
+
var infoCommand3 = (spec) => new Command113("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) => {
|
|
8484
8800
|
const client = await managedClient(cmd);
|
|
8485
8801
|
try {
|
|
8486
8802
|
const m = await client.getManaged(spec.kind, name);
|
|
@@ -8492,8 +8808,8 @@ var infoCommand3 = (spec) => new Command110("info").alias("get").description("sh
|
|
|
8492
8808
|
});
|
|
8493
8809
|
|
|
8494
8810
|
// src/commands/managed/link.ts
|
|
8495
|
-
import { Command as
|
|
8496
|
-
var linkCommand2 = (spec) => new
|
|
8811
|
+
import { Command as Command114 } from "commander";
|
|
8812
|
+
var linkCommand2 = (spec) => new Command114("link").description("let a box reach a database privately (same host)").argument("<db>", "the database").argument("<box>", "the box that connects to it").option("--json", "print as JSON").action(async (name, box2, opts, cmd) => {
|
|
8497
8813
|
const client = await managedClient(cmd);
|
|
8498
8814
|
try {
|
|
8499
8815
|
const m = await spin(`linking ${box2} to ${name}\u2026`, client.linkManaged(spec.kind, name, box2));
|
|
@@ -8509,7 +8825,7 @@ var linkCommand2 = (spec) => new Command111("link").description("let a box reach
|
|
|
8509
8825
|
});
|
|
8510
8826
|
|
|
8511
8827
|
// src/commands/managed/ls.ts
|
|
8512
|
-
import { Command as
|
|
8828
|
+
import { Command as Command115 } from "commander";
|
|
8513
8829
|
function listRows(items, user, kindColumn) {
|
|
8514
8830
|
return items.map((m) => ({
|
|
8515
8831
|
owner: m.owner === user ? "private" : m.owner,
|
|
@@ -8523,7 +8839,7 @@ function listRows(items, user, kindColumn) {
|
|
|
8523
8839
|
created: age(m.createdAt)
|
|
8524
8840
|
}));
|
|
8525
8841
|
}
|
|
8526
|
-
var
|
|
8842
|
+
var lsCommand18 = (spec) => new Command115("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) => {
|
|
8527
8843
|
const client = await managedClient(cmd);
|
|
8528
8844
|
try {
|
|
8529
8845
|
const items = await client.listManaged(spec?.kind, { all: opts.all });
|
|
@@ -8543,8 +8859,8 @@ var lsCommand17 = (spec) => new Command112("ls").alias("list").description(spec
|
|
|
8543
8859
|
});
|
|
8544
8860
|
|
|
8545
8861
|
// src/commands/managed/password.ts
|
|
8546
|
-
import { Command as
|
|
8547
|
-
var passwordCommand = (spec) => new
|
|
8862
|
+
import { Command as Command116 } from "commander";
|
|
8863
|
+
var passwordCommand = (spec) => new Command116("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) => {
|
|
8548
8864
|
const client = await managedClient(cmd);
|
|
8549
8865
|
try {
|
|
8550
8866
|
const secret = opts.reset ? await spin(`setting a new password on ${name}\u2026`, client.resetManagedPassword(spec.kind, name)) : await client.managedPassword(spec.kind, name);
|
|
@@ -8560,8 +8876,8 @@ var passwordCommand = (spec) => new Command113("password").description("show a d
|
|
|
8560
8876
|
});
|
|
8561
8877
|
|
|
8562
8878
|
// src/commands/managed/public.ts
|
|
8563
|
-
import { Command as
|
|
8564
|
-
var
|
|
8879
|
+
import { Command as Command117 } from "commander";
|
|
8880
|
+
var publicCommand2 = (spec) => new Command117("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) => {
|
|
8565
8881
|
if (state !== "on" && state !== "off") throw new KvboxError(`write on or off: kvbox ${spec.command} public ${name} on`);
|
|
8566
8882
|
const client = await managedClient(cmd);
|
|
8567
8883
|
try {
|
|
@@ -8582,8 +8898,8 @@ var publicCommand = (spec) => new Command114("public").description("open a datab
|
|
|
8582
8898
|
});
|
|
8583
8899
|
|
|
8584
8900
|
// src/commands/managed/rm.ts
|
|
8585
|
-
import { Command as
|
|
8586
|
-
var rmCommand17 = (spec) => new
|
|
8901
|
+
import { Command as Command118 } from "commander";
|
|
8902
|
+
var rmCommand17 = (spec) => new Command118("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) => {
|
|
8587
8903
|
const client = await managedClient(cmd);
|
|
8588
8904
|
try {
|
|
8589
8905
|
if (!await confirm(`Delete database ${name} and all its data? There is no backup.`, opts.yes ?? false)) {
|
|
@@ -8599,8 +8915,8 @@ var rmCommand17 = (spec) => new Command115("rm").alias("remove").description("de
|
|
|
8599
8915
|
});
|
|
8600
8916
|
|
|
8601
8917
|
// src/commands/managed/start.ts
|
|
8602
|
-
import { Command as
|
|
8603
|
-
var startCommand2 = (spec) => new
|
|
8918
|
+
import { Command as Command119 } from "commander";
|
|
8919
|
+
var startCommand2 = (spec) => new Command119("start").description("run a stopped database again").argument("<db>", "its name").option("--json", "print as JSON").action(async (name, opts, cmd) => {
|
|
8604
8920
|
const client = await managedClient(cmd);
|
|
8605
8921
|
try {
|
|
8606
8922
|
const m = await spin(`starting ${name}\u2026`, client.startManaged(spec.kind, name));
|
|
@@ -8612,8 +8928,8 @@ var startCommand2 = (spec) => new Command116("start").description("run a stopped
|
|
|
8612
8928
|
});
|
|
8613
8929
|
|
|
8614
8930
|
// src/commands/managed/stop.ts
|
|
8615
|
-
import { Command as
|
|
8616
|
-
var stopCommand2 = (spec) => new
|
|
8931
|
+
import { Command as Command120 } from "commander";
|
|
8932
|
+
var stopCommand2 = (spec) => new Command120("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) => {
|
|
8617
8933
|
const client = await managedClient(cmd);
|
|
8618
8934
|
try {
|
|
8619
8935
|
const m = await spin(`stopping ${name}\u2026`, client.stopManaged(spec.kind, name));
|
|
@@ -8625,8 +8941,8 @@ var stopCommand2 = (spec) => new Command117("stop").description("shut a database
|
|
|
8625
8941
|
});
|
|
8626
8942
|
|
|
8627
8943
|
// src/commands/managed/unlink.ts
|
|
8628
|
-
import { Command as
|
|
8629
|
-
var unlinkCommand2 = (spec) => new
|
|
8944
|
+
import { Command as Command121 } from "commander";
|
|
8945
|
+
var unlinkCommand2 = (spec) => new Command121("unlink").description("stop a box from reaching a database").argument("<db>", "the database").argument("<box>", "the box that was linked to it").option("--json", "print as JSON").action(async (name, box2, opts, cmd) => {
|
|
8630
8946
|
const client = await managedClient(cmd);
|
|
8631
8947
|
try {
|
|
8632
8948
|
const m = await spin(`unlinking ${box2} from ${name}\u2026`, client.unlinkManaged(spec.kind, name, box2));
|
|
@@ -8639,8 +8955,8 @@ var unlinkCommand2 = (spec) => new Command118("unlink").description("stop a box
|
|
|
8639
8955
|
|
|
8640
8956
|
// src/commands/managed/kind.ts
|
|
8641
8957
|
function kindCommand(spec, description) {
|
|
8642
|
-
const command = new
|
|
8643
|
-
for (const make of [createCommand11,
|
|
8958
|
+
const command = new Command122(spec.command).aliases(spec.aliases).description(description);
|
|
8959
|
+
for (const make of [createCommand11, lsCommand18, infoCommand3, passwordCommand, publicCommand2, linkCommand2, unlinkCommand2, growCommand3, stopCommand2, startCommand2, rmCommand17]) {
|
|
8644
8960
|
command.addCommand(make(spec).option("--org <slug>", "act in this org (- for your personal databases)"));
|
|
8645
8961
|
}
|
|
8646
8962
|
command.addCommand(backupCommand4(spec));
|
|
@@ -8654,14 +8970,14 @@ var pgCommand = kindCommand(POSTGRES2, "managed PostgreSQL: a database kvbox run
|
|
|
8654
8970
|
var redisCommand = kindCommand(REDIS, "managed Redis (Valkey): a Redis kvbox runs for you, private until you link a box or make it public");
|
|
8655
8971
|
|
|
8656
8972
|
// src/commands/managed/index.ts
|
|
8657
|
-
import { Command as
|
|
8658
|
-
var managedCommand = new
|
|
8973
|
+
import { Command as Command123 } from "commander";
|
|
8974
|
+
var managedCommand = new Command123("managed").description(`databases kvbox runs for you, every kind together (${KINDS.map((k) => `${k.title}: kvbox ${k.command}`).join(", ")})`).addCommand(lsCommand18().option("--org <slug>", "act in this org (- for your personal databases)"));
|
|
8659
8975
|
|
|
8660
8976
|
// src/commands/env/index.ts
|
|
8661
|
-
import { Command as
|
|
8977
|
+
import { Command as Command127 } from "commander";
|
|
8662
8978
|
|
|
8663
8979
|
// src/commands/env/ls.ts
|
|
8664
|
-
import { Command as
|
|
8980
|
+
import { Command as Command124 } from "commander";
|
|
8665
8981
|
|
|
8666
8982
|
// src/commands/env/shared.ts
|
|
8667
8983
|
function requireCloud4(client) {
|
|
@@ -8688,7 +9004,7 @@ function firstBootHint(box2, name) {
|
|
|
8688
9004
|
}
|
|
8689
9005
|
|
|
8690
9006
|
// src/commands/env/ls.ts
|
|
8691
|
-
var
|
|
9007
|
+
var lsCommand19 = new Command124("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) => {
|
|
8692
9008
|
const client = await clientFor(cmd.optsWithGlobals(), { autoStart: false });
|
|
8693
9009
|
try {
|
|
8694
9010
|
if (opts.box !== void 0) {
|
|
@@ -8727,8 +9043,8 @@ var lsCommand18 = new Command121("ls").alias("list").description("list the varia
|
|
|
8727
9043
|
});
|
|
8728
9044
|
|
|
8729
9045
|
// src/commands/env/rm.ts
|
|
8730
|
-
import { Command as
|
|
8731
|
-
var rmCommand18 = new
|
|
9046
|
+
import { Command as Command125 } from "commander";
|
|
9047
|
+
var rmCommand18 = new Command125("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) => {
|
|
8732
9048
|
const client = await clientFor(cmd.optsWithGlobals(), { autoStart: false });
|
|
8733
9049
|
try {
|
|
8734
9050
|
const target = opts.box === void 0 ? void 0 : await findBox2(client, opts.box);
|
|
@@ -8765,8 +9081,8 @@ var rmCommand18 = new Command122("rm").alias("remove").description("remove varia
|
|
|
8765
9081
|
});
|
|
8766
9082
|
|
|
8767
9083
|
// src/commands/env/set.ts
|
|
8768
|
-
import { Command as
|
|
8769
|
-
var setCommand2 = new
|
|
9084
|
+
import { Command as Command126 } from "commander";
|
|
9085
|
+
var setCommand2 = new Command126("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) => {
|
|
8770
9086
|
const client = await clientFor(cmd.optsWithGlobals(), { autoStart: false });
|
|
8771
9087
|
try {
|
|
8772
9088
|
const owner = opts.box === void 0 ? requireCloud4(client) : void 0;
|
|
@@ -8803,14 +9119,14 @@ var setCommand2 = new Command123("set").description("add or change a variable; b
|
|
|
8803
9119
|
});
|
|
8804
9120
|
|
|
8805
9121
|
// src/commands/env/index.ts
|
|
8806
|
-
var envCommand = new
|
|
9122
|
+
var envCommand = new Command127("env").description("environment variables every box of yours gets when it starts (secrets too)").addCommand(lsCommand19, { isDefault: true }).addCommand(setCommand2).addCommand(rmCommand18);
|
|
8807
9123
|
for (const cmd of envCommand.commands) cmd.option("--org <slug>", "the org's variables instead of yours");
|
|
8808
9124
|
|
|
8809
9125
|
// src/commands/domain/index.ts
|
|
8810
|
-
import { Command as
|
|
9126
|
+
import { Command as Command131 } from "commander";
|
|
8811
9127
|
|
|
8812
9128
|
// src/commands/domain/add.ts
|
|
8813
|
-
import { Command as
|
|
9129
|
+
import { Command as Command128 } from "commander";
|
|
8814
9130
|
|
|
8815
9131
|
// src/commands/domain/shared.ts
|
|
8816
9132
|
function requireCloud5(client) {
|
|
@@ -8830,7 +9146,7 @@ function hostIn(name, zone) {
|
|
|
8830
9146
|
}
|
|
8831
9147
|
|
|
8832
9148
|
// src/commands/domain/add.ts
|
|
8833
|
-
var addCommand4 = new
|
|
9149
|
+
var addCommand4 = new Command128("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) => {
|
|
8834
9150
|
const domain = assertDomain(domainArg.trim().toLowerCase());
|
|
8835
9151
|
const port = opts.port === void 0 ? void 0 : parsePorts([opts.port])[0];
|
|
8836
9152
|
const client = await clientFor(cmd.optsWithGlobals());
|
|
@@ -8866,8 +9182,8 @@ kvbox checks every minute; ${domain} is served at ${d.url} once its records are
|
|
|
8866
9182
|
});
|
|
8867
9183
|
|
|
8868
9184
|
// src/commands/domain/ls.ts
|
|
8869
|
-
import { Command as
|
|
8870
|
-
var
|
|
9185
|
+
import { Command as Command129 } from "commander";
|
|
9186
|
+
var lsCommand20 = new Command129("ls").alias("list").description("list your custom domains and whether they are live").option("--json", "print as JSON").action(async (opts, cmd) => {
|
|
8871
9187
|
const client = await clientFor(cmd.optsWithGlobals());
|
|
8872
9188
|
try {
|
|
8873
9189
|
requireCloud5(client);
|
|
@@ -8896,8 +9212,8 @@ var lsCommand19 = new Command126("ls").alias("list").description("list your cust
|
|
|
8896
9212
|
});
|
|
8897
9213
|
|
|
8898
9214
|
// src/commands/domain/rm.ts
|
|
8899
|
-
import { Command as
|
|
8900
|
-
var rmCommand19 = new
|
|
9215
|
+
import { Command as Command130 } from "commander";
|
|
9216
|
+
var rmCommand19 = new Command130("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) => {
|
|
8901
9217
|
const domain = domainArg.trim().toLowerCase();
|
|
8902
9218
|
const client = await clientFor(cmd.optsWithGlobals());
|
|
8903
9219
|
try {
|
|
@@ -8918,7 +9234,7 @@ var rmCommand19 = new Command127("rm").alias("remove").description("stop serving
|
|
|
8918
9234
|
});
|
|
8919
9235
|
|
|
8920
9236
|
// src/commands/domain/index.ts
|
|
8921
|
-
var domainCommand = new
|
|
9237
|
+
var domainCommand = new Command131("domain").alias("domains").description("serve a box at a domain of your own").addCommand(addCommand4).addCommand(lsCommand20).addCommand(rmCommand19);
|
|
8922
9238
|
for (const cmd of domainCommand.commands) cmd.option("--org <slug>", "act in this org (- for your personal boxes)");
|
|
8923
9239
|
|
|
8924
9240
|
// src/commands/update.ts
|
|
@@ -8926,7 +9242,7 @@ import { spawn as spawn8 } from "child_process";
|
|
|
8926
9242
|
import { mkdtempSync, rmSync, writeFileSync as writeFileSync2 } from "fs";
|
|
8927
9243
|
import { tmpdir } from "os";
|
|
8928
9244
|
import { join as join9 } from "path";
|
|
8929
|
-
import { Command as
|
|
9245
|
+
import { Command as Command132 } from "commander";
|
|
8930
9246
|
|
|
8931
9247
|
// src/update.ts
|
|
8932
9248
|
import { mkdirSync, readFileSync as readFileSync3, writeFileSync } from "fs";
|
|
@@ -9045,7 +9361,7 @@ function run2(cmd, args) {
|
|
|
9045
9361
|
child.on("exit", (code, signal) => resolve4(code ?? (signal ? 1 : 0)));
|
|
9046
9362
|
});
|
|
9047
9363
|
}
|
|
9048
|
-
var selfUpdateCommand = new
|
|
9364
|
+
var selfUpdateCommand = new Command132("update").description("update kvbox to the latest version (reruns the installer from kvbox.sh, agent skill included)").action(async () => {
|
|
9049
9365
|
suppressUpdateNotice();
|
|
9050
9366
|
const inst = installerFor(process.platform, process.env["KVBOX_INSTALL_URL"] || INSTALL_BASE);
|
|
9051
9367
|
let code;
|
|
@@ -9116,6 +9432,7 @@ var HELP_GROUPS = [
|
|
|
9116
9432
|
["managed", "every managed database, whatever its kind"],
|
|
9117
9433
|
["cron", "call a box on a schedule, waking it first if it sleeps"],
|
|
9118
9434
|
["env", "environment variables and secrets every box of yours gets"],
|
|
9435
|
+
["integration", "accounts (GitHub) your boxes use once you turn them on"],
|
|
9119
9436
|
["domain", "serve a box at a domain of your own"]
|
|
9120
9437
|
]
|
|
9121
9438
|
},
|
|
@@ -9173,7 +9490,7 @@ function installRootHelp(program) {
|
|
|
9173
9490
|
|
|
9174
9491
|
// src/program.ts
|
|
9175
9492
|
function buildProgram() {
|
|
9176
|
-
const program = new
|
|
9493
|
+
const program = new Command133("kvbox").description("self-hosted Firecracker microVMs with Docker-like ergonomics").version(VERSION, "-v, --version").option("--local", "use this machine's kvbox-server over its socket, ignoring kvbox login and KVBOX_TOKEN").option("--org <slug>", "the org: where kvbox new creates, and which box a name means when it is not one of yours; before the command here, or after it").showHelpAfterError().enablePositionalOptions();
|
|
9177
9494
|
program.addCommand(vmCommand);
|
|
9178
9495
|
program.addCommand(snapshotsCommand);
|
|
9179
9496
|
program.addCommand(volumeCommand);
|
|
@@ -9188,6 +9505,7 @@ function buildProgram() {
|
|
|
9188
9505
|
program.addCommand(logoutCommand);
|
|
9189
9506
|
program.addCommand(whoamiCommand);
|
|
9190
9507
|
program.addCommand(keyCommand);
|
|
9508
|
+
program.addCommand(integrationCommand);
|
|
9191
9509
|
program.addCommand(orgCommand);
|
|
9192
9510
|
program.addCommand(usageCommand2);
|
|
9193
9511
|
program.addCommand(creditCommand);
|