@kvbox/server 0.5.48 → 0.5.50

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -190,7 +190,15 @@ var PricingSchema = z.object({
190
190
  diskGibHour: z.number().nonnegative(),
191
191
  volumeHour: z.number().nonnegative().default(0),
192
192
  volumeGibHour: z.number().nonnegative().default(0),
193
- diskIncludedGib: z.number().int().nonnegative().default(0)
193
+ diskIncludedGib: z.number().int().nonnegative().default(0),
194
+ /**
195
+ * Object storage (#182): an hour of a slug's storage existing, whatever it holds, which covers its
196
+ * hidden box and the first `storageIncludedGib` of its size; each GiB above that is `storageGibHour`.
197
+ * A price list from before object storage charges nothing for it.
198
+ */
199
+ storageHour: z.number().nonnegative().default(0),
200
+ storageGibHour: z.number().nonnegative().default(0),
201
+ storageIncludedGib: z.number().int().nonnegative().default(0)
194
202
  });
195
203
  var PriceListSchema = PricingSchema.extend({ welcomeCredit: z.number().nonnegative() });
196
204
  var HOUR_MS = 36e5;
@@ -1338,6 +1346,15 @@ var CapacitySchema = z4.object({
1338
1346
  version: z4.string().optional()
1339
1347
  });
1340
1348
  var ImageSchema = z4.object({ name: z4.string(), version: z4.string().nullable() });
1349
+ var ImageIndexSchema = z4.object({
1350
+ updatedAt: z4.string(),
1351
+ images: z4.record(z4.string(), z4.object({ version: z4.string().min(1), minServer: z4.string().min(1).optional() }))
1352
+ });
1353
+ var LatestImagesSchema = z4.object({
1354
+ updatedAt: z4.string().nullable(),
1355
+ images: ImageIndexSchema.shape.images,
1356
+ checkedAt: z4.string().nullable()
1357
+ });
1341
1358
  var RecoveryReportSchema = z4.object({
1342
1359
  at: z4.string(),
1343
1360
  booted: z4.array(z4.string()),
@@ -1465,13 +1482,21 @@ var UsageDaySchema = z4.object({
1465
1482
  cost: z4.number(),
1466
1483
  currency: z4.string(),
1467
1484
  boxes: z4.array(UsageDayItemSchema),
1468
- volumes: z4.array(UsageDayItemSchema)
1485
+ volumes: z4.array(UsageDayItemSchema),
1486
+ /** Object storage that existed that day (#182); absent on a day without any. */
1487
+ storage: z4.array(UsageDayItemSchema).optional()
1469
1488
  });
1470
1489
  var UsageReportSchema = z4.object({
1471
1490
  window: z4.object({ from: z4.string(), to: z4.string() }),
1472
1491
  boxes: z4.array(BoxUsageSchema),
1473
1492
  /** Absent from a side older than #91. */
1474
1493
  volumes: z4.array(VolumeUsageSchema).optional(),
1494
+ /**
1495
+ * Object storage (#182, control plane only): one row per storage a slug has or had, shaped like a
1496
+ * volume's. `volumeHours` are the hours it existed, `volumeGibHours` those of the GiB beyond the
1497
+ * included ones, `sizeGib` its whole size. Absent when there is none.
1498
+ */
1499
+ storage: z4.array(VolumeUsageSchema).optional(),
1475
1500
  /** With `?by=day` only, oldest day first. */
1476
1501
  days: z4.array(UsageDaySchema).optional(),
1477
1502
  totals: z4.object({
@@ -1481,7 +1506,7 @@ var UsageReportSchema = z4.object({
1481
1506
  diskGibHours: z4.number(),
1482
1507
  volumeHours: z4.number().optional(),
1483
1508
  volumeGibHours: z4.number().optional(),
1484
- /** Boxes and volumes together. */
1509
+ /** Boxes, volumes and object storage together. */
1485
1510
  cost: z4.object({ amount: z4.number(), currency: z4.string() }).optional()
1486
1511
  })
1487
1512
  });
@@ -5267,6 +5292,23 @@ import { readFile as readFile11, rm as rm6, writeFile as writeFile9 } from "node
5267
5292
  import { createServer as createHttpsServer } from "node:https";
5268
5293
  import { createAdaptorServer } from "@hono/node-server";
5269
5294
 
5295
+ // ../shared/src/names.ts
5296
+ import { createHmac as createHmac2 } from "node:crypto";
5297
+ var PROXY_ERROR_HEADER = "x-kvbox-proxy-error";
5298
+ var PROXIED_HEADER = "x-kvbox-proxied";
5299
+ var VISITOR_PATH_HEADER = "x-kvbox-path";
5300
+ var WAKE_HEADER = "x-kvbox-wake";
5301
+ var WAKE_WAIT_MS = 3e4;
5302
+ var REQUEST_TIMEOUT_MS = 36e5;
5303
+ var WOKE_HEADER = "x-kvbox-woke";
5304
+ var VISITOR_AUTH_HEADER = "x-kvbox-authorization";
5305
+ var NOT_FORWARDED = /* @__PURE__ */ new Set(["expect"]);
5306
+ var HOP_BY_HOP = /* @__PURE__ */ new Set(["connection", "keep-alive", "proxy-authenticate", "proxy-authorization", "proxy-connection", "te", "trailer", "transfer-encoding", "upgrade"]);
5307
+ var BOX_HTTP_PATH_RE = /^\/machines\/([^/]+)\/http\/(\d{1,5})\/?$/;
5308
+ function edgeCredential(hostSecret) {
5309
+ return createHmac2("sha256", hostSecret).update("kvbox-edge-v1").digest("base64url");
5310
+ }
5311
+
5270
5312
  // src/app.ts
5271
5313
  import { Hono as Hono10 } from "hono";
5272
5314
 
@@ -5283,28 +5325,10 @@ function versionOf(srcFileUrl, injected) {
5283
5325
  }
5284
5326
 
5285
5327
  // src/version.ts
5286
- var VERSION = versionOf(import.meta.url, true ? "0.5.48" : void 0);
5328
+ var VERSION = versionOf(import.meta.url, true ? "0.5.50" : void 0);
5287
5329
 
5288
5330
  // src/caller.ts
5289
5331
  import { createHash as createHash2, timingSafeEqual } from "node:crypto";
5290
-
5291
- // ../shared/src/names.ts
5292
- import { createHmac as createHmac2 } from "node:crypto";
5293
- var PROXY_ERROR_HEADER = "x-kvbox-proxy-error";
5294
- var PROXIED_HEADER = "x-kvbox-proxied";
5295
- var VISITOR_PATH_HEADER = "x-kvbox-path";
5296
- var WAKE_HEADER = "x-kvbox-wake";
5297
- var WAKE_WAIT_MS = 3e4;
5298
- var WOKE_HEADER = "x-kvbox-woke";
5299
- var VISITOR_AUTH_HEADER = "x-kvbox-authorization";
5300
- var NOT_FORWARDED = /* @__PURE__ */ new Set(["expect"]);
5301
- var HOP_BY_HOP = /* @__PURE__ */ new Set(["connection", "keep-alive", "proxy-authenticate", "proxy-authorization", "proxy-connection", "te", "trailer", "transfer-encoding", "upgrade"]);
5302
- var BOX_HTTP_PATH_RE = /^\/machines\/([^/]+)\/http\/(\d{1,5})\/?$/;
5303
- function edgeCredential(hostSecret) {
5304
- return createHmac2("sha256", hostSecret).update("kvbox-edge-v1").digest("base64url");
5305
- }
5306
-
5307
- // src/caller.ts
5308
5332
  var OWNER_HEADER = "x-kvbox-owner";
5309
5333
  function resolveCaller(opts = {}) {
5310
5334
  const cp = opts.controlPlane;
@@ -6029,8 +6053,12 @@ async function listen(opts = {}) {
6029
6053
  httpsServer = createAdaptorServer({
6030
6054
  fetch: createApp({ controlPlane: { name: cp.name, secret: cp.secret } }).fetch,
6031
6055
  createServer: createHttpsServer,
6032
- serverOptions: { key, cert }
6056
+ // A body forwarded to a box may take long to arrive (a large upload through the edge, #182).
6057
+ serverOptions: { key, cert, requestTimeout: REQUEST_TIMEOUT_MS }
6033
6058
  });
6059
+ const secret = secretCheck(cp);
6060
+ const edge = edgeCheck(cp);
6061
+ limitUntrusted(httpsServer, (req) => secret(req.headers.authorization) || edge(req.headers.authorization));
6034
6062
  httpsServer.on("upgrade", boxUpgradeHandler({ name: cp.name, secret: cp.secret }));
6035
6063
  const port = opts.httpsPort ?? cp.port;
6036
6064
  await new Promise((resolve2, reject) => {
@@ -6065,6 +6093,17 @@ async function listen(opts = {}) {
6065
6093
  process.once("SIGTERM", () => void shutdown2());
6066
6094
  return https ? { socketPath, server, https, close } : { socketPath, server, close };
6067
6095
  }
6096
+ var UNTRUSTED_REQUEST_MS = 3e5;
6097
+ function limitUntrusted(server, trusted, ms = UNTRUSTED_REQUEST_MS) {
6098
+ server.on("request", (req) => {
6099
+ if (trusted(req)) return;
6100
+ const timer = setTimeout(() => req.socket.destroy(), ms);
6101
+ timer.unref();
6102
+ const done = () => clearTimeout(timer);
6103
+ req.once("end", done);
6104
+ req.once("close", done);
6105
+ });
6106
+ }
6068
6107
 
6069
6108
  // src/commands/start.ts
6070
6109
  var daemon = false;