@kvbox/server 0.5.49 → 0.5.50
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/kvbox-server.js +53 -23
- package/dist/kvbox-server.js.map +1 -1
- package/package.json +1 -1
package/dist/kvbox-server.js
CHANGED
|
@@ -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;
|
|
@@ -1474,13 +1482,21 @@ var UsageDaySchema = z4.object({
|
|
|
1474
1482
|
cost: z4.number(),
|
|
1475
1483
|
currency: z4.string(),
|
|
1476
1484
|
boxes: z4.array(UsageDayItemSchema),
|
|
1477
|
-
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()
|
|
1478
1488
|
});
|
|
1479
1489
|
var UsageReportSchema = z4.object({
|
|
1480
1490
|
window: z4.object({ from: z4.string(), to: z4.string() }),
|
|
1481
1491
|
boxes: z4.array(BoxUsageSchema),
|
|
1482
1492
|
/** Absent from a side older than #91. */
|
|
1483
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(),
|
|
1484
1500
|
/** With `?by=day` only, oldest day first. */
|
|
1485
1501
|
days: z4.array(UsageDaySchema).optional(),
|
|
1486
1502
|
totals: z4.object({
|
|
@@ -1490,7 +1506,7 @@ var UsageReportSchema = z4.object({
|
|
|
1490
1506
|
diskGibHours: z4.number(),
|
|
1491
1507
|
volumeHours: z4.number().optional(),
|
|
1492
1508
|
volumeGibHours: z4.number().optional(),
|
|
1493
|
-
/** Boxes and
|
|
1509
|
+
/** Boxes, volumes and object storage together. */
|
|
1494
1510
|
cost: z4.object({ amount: z4.number(), currency: z4.string() }).optional()
|
|
1495
1511
|
})
|
|
1496
1512
|
});
|
|
@@ -5276,6 +5292,23 @@ import { readFile as readFile11, rm as rm6, writeFile as writeFile9 } from "node
|
|
|
5276
5292
|
import { createServer as createHttpsServer } from "node:https";
|
|
5277
5293
|
import { createAdaptorServer } from "@hono/node-server";
|
|
5278
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
|
+
|
|
5279
5312
|
// src/app.ts
|
|
5280
5313
|
import { Hono as Hono10 } from "hono";
|
|
5281
5314
|
|
|
@@ -5292,28 +5325,10 @@ function versionOf(srcFileUrl, injected) {
|
|
|
5292
5325
|
}
|
|
5293
5326
|
|
|
5294
5327
|
// src/version.ts
|
|
5295
|
-
var VERSION = versionOf(import.meta.url, true ? "0.5.
|
|
5328
|
+
var VERSION = versionOf(import.meta.url, true ? "0.5.50" : void 0);
|
|
5296
5329
|
|
|
5297
5330
|
// src/caller.ts
|
|
5298
5331
|
import { createHash as createHash2, timingSafeEqual } from "node:crypto";
|
|
5299
|
-
|
|
5300
|
-
// ../shared/src/names.ts
|
|
5301
|
-
import { createHmac as createHmac2 } from "node:crypto";
|
|
5302
|
-
var PROXY_ERROR_HEADER = "x-kvbox-proxy-error";
|
|
5303
|
-
var PROXIED_HEADER = "x-kvbox-proxied";
|
|
5304
|
-
var VISITOR_PATH_HEADER = "x-kvbox-path";
|
|
5305
|
-
var WAKE_HEADER = "x-kvbox-wake";
|
|
5306
|
-
var WAKE_WAIT_MS = 3e4;
|
|
5307
|
-
var WOKE_HEADER = "x-kvbox-woke";
|
|
5308
|
-
var VISITOR_AUTH_HEADER = "x-kvbox-authorization";
|
|
5309
|
-
var NOT_FORWARDED = /* @__PURE__ */ new Set(["expect"]);
|
|
5310
|
-
var HOP_BY_HOP = /* @__PURE__ */ new Set(["connection", "keep-alive", "proxy-authenticate", "proxy-authorization", "proxy-connection", "te", "trailer", "transfer-encoding", "upgrade"]);
|
|
5311
|
-
var BOX_HTTP_PATH_RE = /^\/machines\/([^/]+)\/http\/(\d{1,5})\/?$/;
|
|
5312
|
-
function edgeCredential(hostSecret) {
|
|
5313
|
-
return createHmac2("sha256", hostSecret).update("kvbox-edge-v1").digest("base64url");
|
|
5314
|
-
}
|
|
5315
|
-
|
|
5316
|
-
// src/caller.ts
|
|
5317
5332
|
var OWNER_HEADER = "x-kvbox-owner";
|
|
5318
5333
|
function resolveCaller(opts = {}) {
|
|
5319
5334
|
const cp = opts.controlPlane;
|
|
@@ -6038,8 +6053,12 @@ async function listen(opts = {}) {
|
|
|
6038
6053
|
httpsServer = createAdaptorServer({
|
|
6039
6054
|
fetch: createApp({ controlPlane: { name: cp.name, secret: cp.secret } }).fetch,
|
|
6040
6055
|
createServer: createHttpsServer,
|
|
6041
|
-
|
|
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 }
|
|
6042
6058
|
});
|
|
6059
|
+
const secret = secretCheck(cp);
|
|
6060
|
+
const edge = edgeCheck(cp);
|
|
6061
|
+
limitUntrusted(httpsServer, (req) => secret(req.headers.authorization) || edge(req.headers.authorization));
|
|
6043
6062
|
httpsServer.on("upgrade", boxUpgradeHandler({ name: cp.name, secret: cp.secret }));
|
|
6044
6063
|
const port = opts.httpsPort ?? cp.port;
|
|
6045
6064
|
await new Promise((resolve2, reject) => {
|
|
@@ -6074,6 +6093,17 @@ async function listen(opts = {}) {
|
|
|
6074
6093
|
process.once("SIGTERM", () => void shutdown2());
|
|
6075
6094
|
return https ? { socketPath, server, https, close } : { socketPath, server, close };
|
|
6076
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
|
+
}
|
|
6077
6107
|
|
|
6078
6108
|
// src/commands/start.ts
|
|
6079
6109
|
var daemon = false;
|