@kvbox/server 0.6.22 → 0.6.24
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-server.js +70 -8
- package/dist/kvbox-server.js.map +1 -1
- package/package.json +1 -1
package/dist/kvbox-server.js
CHANGED
|
@@ -230,7 +230,12 @@ var PricingSchema = z.object({
|
|
|
230
230
|
* backup you switch on is charged…"): their switch is off until someone turns it on. A managed database's
|
|
231
231
|
* nightly backup, on from its creation, is included in its price. A price list from before it charges nothing.
|
|
232
232
|
*/
|
|
233
|
-
scheduledBackup: z.number().nonnegative().default(0)
|
|
233
|
+
scheduledBackup: z.number().nonnegative().default(0),
|
|
234
|
+
/**
|
|
235
|
+
* A Kubernetes cluster (#222): an hour of one existing, on top of its boxes. A cluster is priced as the
|
|
236
|
+
* boxes it is (its master and its nodes), so this is 0 until a flat fee is wanted.
|
|
237
|
+
*/
|
|
238
|
+
clusterHour: z.number().nonnegative().default(0)
|
|
234
239
|
});
|
|
235
240
|
var PriceListSchema = PricingSchema.extend({ welcomeCredit: z.number().nonnegative() });
|
|
236
241
|
var HOUR_MS = 36e5;
|
|
@@ -2362,6 +2367,14 @@ var MachineSchema = z6.object({
|
|
|
2362
2367
|
* each time it is needed. Absent: none. A host before integrations never sends it.
|
|
2363
2368
|
*/
|
|
2364
2369
|
integrations: z6.array(z6.string()).optional(),
|
|
2370
|
+
/** The id of the cluster the box is a part of on its host (#215), as the host keeps it. Absent: none, or a host from before it said so. */
|
|
2371
|
+
clusterId: z6.string().optional(),
|
|
2372
|
+
/**
|
|
2373
|
+
* The Kubernetes cluster the box is a node of, and its pool (#218). Only the control plane fills it in, on
|
|
2374
|
+
* `GET /machines`. Such a box is opened like any other, but what would change it is its pool's to do
|
|
2375
|
+
* (`kvbox k8s pool`): the control plane refuses it on the box.
|
|
2376
|
+
*/
|
|
2377
|
+
cluster: z6.object({ name: z6.string(), pool: z6.string() }).optional(),
|
|
2365
2378
|
/** How to reach what the box serves, its secrets masked (#87): `postgres://postgres:****@db.kvbox:5432/postgres`. */
|
|
2366
2379
|
url: z6.string().optional(),
|
|
2367
2380
|
/**
|
|
@@ -2536,8 +2549,11 @@ var CreateMachineRequest = z6.object({
|
|
|
2536
2549
|
host: z6.string().optional(),
|
|
2537
2550
|
/** The image to boot (#87, `kvbox new --base postgres`). Absent: the base image. */
|
|
2538
2551
|
image: z6.string().optional(),
|
|
2539
|
-
/**
|
|
2540
|
-
|
|
2552
|
+
/**
|
|
2553
|
+
* The box's own environment variables (#87, `kvbox new -e NAME=value`), over its owner's. `secret`: kept as a
|
|
2554
|
+
* secret, whose value no route answers with (a cluster's join token, #216); a host from before it keeps it plain.
|
|
2555
|
+
*/
|
|
2556
|
+
env: z6.array(z6.object({ name: z6.string(), value: z6.string(), secret: z6.boolean().optional() })).optional(),
|
|
2541
2557
|
/**
|
|
2542
2558
|
* Start the box on this backup's disk (#141, `kvbox new --from-backup <id>`), a removed box's too: its image,
|
|
2543
2559
|
* version and variables come from the backup, its size too unless given. Only the control plane reads it.
|
|
@@ -2788,6 +2804,32 @@ var CronUsageSchema = z6.object({
|
|
|
2788
2804
|
/** When it was made. */
|
|
2789
2805
|
historyFrom: z6.string().nullable()
|
|
2790
2806
|
});
|
|
2807
|
+
var ClusterUsageSchema = z6.object({
|
|
2808
|
+
id: z6.string(),
|
|
2809
|
+
name: z6.string(),
|
|
2810
|
+
owner: z6.string(),
|
|
2811
|
+
ownerKind: z6.enum(["user", "org"]).optional(),
|
|
2812
|
+
/** `removed` once its master is. */
|
|
2813
|
+
status: z6.enum(["present", "removed"]),
|
|
2814
|
+
/** The hours its master existed in the window, running or not. */
|
|
2815
|
+
hours: z6.number(),
|
|
2816
|
+
master: z6.object({
|
|
2817
|
+
seconds: MachineUsageSchema.shape.seconds,
|
|
2818
|
+
vcpuHours: z6.number(),
|
|
2819
|
+
ramGibHours: z6.number(),
|
|
2820
|
+
diskGibHours: z6.number(),
|
|
2821
|
+
volumeHours: z6.number(),
|
|
2822
|
+
volumeGibHours: z6.number(),
|
|
2823
|
+
cost: z6.object({ amount: z6.number(), currency: z6.string() }).optional()
|
|
2824
|
+
}),
|
|
2825
|
+
nodes: z6.array(BoxUsageSchema.extend({
|
|
2826
|
+
/** The pool it is, or was, a node of. */
|
|
2827
|
+
pool: z6.string().optional()
|
|
2828
|
+
})),
|
|
2829
|
+
fee: z6.object({ amount: z6.number(), currency: z6.string() }).optional(),
|
|
2830
|
+
cost: z6.object({ amount: z6.number(), currency: z6.string() }).optional(),
|
|
2831
|
+
historyFrom: z6.string().nullable()
|
|
2832
|
+
});
|
|
2791
2833
|
var BackupUsageSchema = z6.object({
|
|
2792
2834
|
id: z6.string(),
|
|
2793
2835
|
kind: z6.string(),
|
|
@@ -2821,6 +2863,8 @@ var UsageDaySchema = z6.object({
|
|
|
2821
2863
|
storage: z6.array(UsageDayItemSchema).optional(),
|
|
2822
2864
|
/** Cron services that existed that day (#190); absent on a day without any. */
|
|
2823
2865
|
cron: z6.array(UsageDayItemSchema).optional(),
|
|
2866
|
+
/** Kubernetes clusters that existed that day (#222), each with its master and nodes together; absent on a day without any. */
|
|
2867
|
+
clusters: z6.array(UsageDayItemSchema).optional(),
|
|
2824
2868
|
/** Paid backups that turned ready that day, summed per thing backed up (`id` is `<owner>/<kind>:<name>`); absent on a day without any. */
|
|
2825
2869
|
backups: z6.array(UsageDayItemSchema).optional()
|
|
2826
2870
|
});
|
|
@@ -2837,6 +2881,11 @@ var UsageReportSchema = z6.object({
|
|
|
2837
2881
|
storage: z6.array(VolumeUsageSchema).optional(),
|
|
2838
2882
|
/** Cron services (#190, control plane only): one row per service a slug has or had. Absent when there is none. */
|
|
2839
2883
|
cron: z6.array(CronUsageSchema).optional(),
|
|
2884
|
+
/**
|
|
2885
|
+
* Kubernetes clusters (#222, control plane only): one row per cluster a slug has or had, with its master
|
|
2886
|
+
* and its nodes; those boxes are in no other list. Absent when there is none.
|
|
2887
|
+
*/
|
|
2888
|
+
clusters: z6.array(ClusterUsageSchema).optional(),
|
|
2840
2889
|
/** Paid backups (control plane only): one row per box, volume or service backed up by hand in the window. Absent when there is none. */
|
|
2841
2890
|
backups: z6.array(BackupUsageSchema).optional(),
|
|
2842
2891
|
/** With `?by=day` only, oldest day first. */
|
|
@@ -2848,7 +2897,7 @@ var UsageReportSchema = z6.object({
|
|
|
2848
2897
|
diskGibHours: z6.number(),
|
|
2849
2898
|
volumeHours: z6.number().optional(),
|
|
2850
2899
|
volumeGibHours: z6.number().optional(),
|
|
2851
|
-
/** Boxes, volumes, object storage, cron services and paid backups together. */
|
|
2900
|
+
/** Boxes, volumes, object storage, cron services, Kubernetes clusters and paid backups together; the hours above are those of `boxes` and `volumes` alone. */
|
|
2852
2901
|
cost: z6.object({ amount: z6.number(), currency: z6.string() }).optional()
|
|
2853
2902
|
})
|
|
2854
2903
|
});
|
|
@@ -2883,7 +2932,7 @@ var VolumeEventsResponseSchema = z6.object({
|
|
|
2883
2932
|
events: z6.array(VolumeEventRowSchema),
|
|
2884
2933
|
next: z6.number().int()
|
|
2885
2934
|
});
|
|
2886
|
-
var API_ERROR_CODES = ["account-inactive", "org-inactive", "out-of-credit", "box-outdated", "storage-outdated", "object-exists", "storage-waking"];
|
|
2935
|
+
var API_ERROR_CODES = ["account-inactive", "org-inactive", "out-of-credit", "box-outdated", "storage-outdated", "object-exists", "storage-waking", "cluster-busy", "node-has-data"];
|
|
2887
2936
|
var ApiErrorCodeSchema = z6.enum(API_ERROR_CODES);
|
|
2888
2937
|
var ApiErrorSchema = z6.object({
|
|
2889
2938
|
error: z6.string(),
|
|
@@ -3052,6 +3101,16 @@ var LoginResponseSchema = z6.object({
|
|
|
3052
3101
|
/** Whose boxes the certificate opens: `<slug>@<realm>` for the user and each org they are in (orgs phase 4). */
|
|
3053
3102
|
sshCertPrincipals: z6.array(z6.string()).optional()
|
|
3054
3103
|
});
|
|
3104
|
+
var PasswordResetRequestSchema = z6.object({
|
|
3105
|
+
email: z6.string().min(1).max(320)
|
|
3106
|
+
});
|
|
3107
|
+
var PasswordResetCheckSchema = z6.object({
|
|
3108
|
+
token: z6.string().min(1).max(200)
|
|
3109
|
+
});
|
|
3110
|
+
var PasswordResetConfirmSchema = z6.object({
|
|
3111
|
+
token: z6.string().min(1).max(200),
|
|
3112
|
+
password: z6.string().min(1)
|
|
3113
|
+
});
|
|
3055
3114
|
var DeviceLoginRequestSchema = z6.object({
|
|
3056
3115
|
// Capped: anyone may open a login, and the key is stored until it expires (an RSA-16384 key is ~2.8 KB).
|
|
3057
3116
|
publicKey: z6.string().max(16384).optional(),
|
|
@@ -3936,7 +3995,7 @@ async function mergeBoxEnv(box, given, p = paths()) {
|
|
|
3936
3995
|
const names2 = new Set(given.map((v) => v.name));
|
|
3937
3996
|
const now = (/* @__PURE__ */ new Date()).toISOString();
|
|
3938
3997
|
const kept = (await readBoxEnv(box, p)).filter((v) => !names2.has(v.name));
|
|
3939
|
-
await writeBoxEnv(box, [...kept, ...given.map((v) => ({
|
|
3998
|
+
await writeBoxEnv(box, [...kept, ...given.map((v) => ({ name: v.name, value: v.value, secret: v.secret === true, updatedAt: now }))], p);
|
|
3940
3999
|
}
|
|
3941
4000
|
async function copyBoxEnv(from, to) {
|
|
3942
4001
|
if (!existsSync7(from)) return;
|
|
@@ -4580,6 +4639,7 @@ function toMachine(meta, p = paths()) {
|
|
|
4580
4639
|
...meta.autoHibernateSec ? { autoHibernateSec: meta.autoHibernateSec } : {},
|
|
4581
4640
|
...meta.idleCheck !== void 0 ? { idleCheck: meta.idleCheck } : {},
|
|
4582
4641
|
...meta.integrations?.length ? { integrations: [...meta.integrations] } : {},
|
|
4642
|
+
...meta.cluster !== void 0 ? { clusterId: meta.cluster } : {},
|
|
4583
4643
|
...meta.volumes?.length ? { volumes: volumeSummaries(meta, p) } : {},
|
|
4584
4644
|
...linksOf(meta)
|
|
4585
4645
|
};
|
|
@@ -5657,6 +5717,7 @@ var updateMachine = locked(async function updateMachine2(ref, p = paths()) {
|
|
|
5657
5717
|
assertAssets(cfg);
|
|
5658
5718
|
const base = await currentImage(meta.image, cfg, p);
|
|
5659
5719
|
if (base.version === meta.base) return toMachine(meta, p);
|
|
5720
|
+
if (meta.cluster !== void 0) throw new KvboxError(`box ${shown(ref)} is part of a cluster and keeps its cluster's version; it is not updated alone`);
|
|
5660
5721
|
await assertOverlayCapable(base.file, meta.image, base.version);
|
|
5661
5722
|
return applyAtNextBoot(meta, { base: base.version }, "update", cfg, p);
|
|
5662
5723
|
});
|
|
@@ -5815,7 +5876,8 @@ async function createMachine(req, owner, p = paths(), from) {
|
|
|
5815
5876
|
const env = from ? null : imageEnv(manifest, name, req.env ?? [], (await readOwnerEnv(owner, p).catch(() => null))?.vars ?? []);
|
|
5816
5877
|
const now = (/* @__PURE__ */ new Date()).toISOString();
|
|
5817
5878
|
const autoHibernateSec = cluster === void 0 ? autoHibernateFor(req, cfg, manifest) : void 0;
|
|
5818
|
-
const
|
|
5879
|
+
const secret = /* @__PURE__ */ new Set([...env?.secrets ?? [], ...(req.env ?? []).filter((v) => v.secret === true).map((v) => v.name)]);
|
|
5880
|
+
const vars = env === null ? from?.vars ?? [] : env.vars.map((v) => ({ name: v.name, value: v.value, secret: secret.has(v.name), updatedAt: now }));
|
|
5819
5881
|
const machine = await bootInto(
|
|
5820
5882
|
{ id, name, owner, ip, mac, vcpu: size2.vcpu, memMib: size2.memMib, base: base.version, image, sshKeys },
|
|
5821
5883
|
// The image is shared read-only by every box; only the box's own writes land in its overlay.
|
|
@@ -7891,7 +7953,7 @@ function versionOf(srcFileUrl, injected) {
|
|
|
7891
7953
|
}
|
|
7892
7954
|
|
|
7893
7955
|
// src/version.ts
|
|
7894
|
-
var VERSION = versionOf(import.meta.url, true ? "0.6.
|
|
7956
|
+
var VERSION = versionOf(import.meta.url, true ? "0.6.24" : void 0);
|
|
7895
7957
|
|
|
7896
7958
|
// src/caller.ts
|
|
7897
7959
|
import { createHash as createHash5, timingSafeEqual as timingSafeEqual2 } from "node:crypto";
|