@kvbox/server 0.6.1 → 0.6.2
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 +31 -6
- package/dist/kvbox-server.js.map +1 -1
- package/package.json +1 -1
package/dist/kvbox-server.js
CHANGED
|
@@ -209,7 +209,9 @@ var PricingSchema = z.object({
|
|
|
209
209
|
*/
|
|
210
210
|
storageHour: z.number().nonnegative().default(0),
|
|
211
211
|
storageGibHour: z.number().nonnegative().default(0),
|
|
212
|
-
storageIncludedGib: z.number().int().nonnegative().default(0)
|
|
212
|
+
storageIncludedGib: z.number().int().nonnegative().default(0),
|
|
213
|
+
/** The cron service (#190): an hour of one cron service existing, whatever it holds or fires. A price list from before it charges nothing. */
|
|
214
|
+
cronHour: z.number().nonnegative().default(0)
|
|
213
215
|
});
|
|
214
216
|
var PriceListSchema = PricingSchema.extend({ welcomeCredit: z.number().nonnegative() });
|
|
215
217
|
var HOUR_MS = 36e5;
|
|
@@ -1615,6 +1617,17 @@ var VolumeUsageSchema = z4.object({
|
|
|
1615
1617
|
cost: z4.object({ amount: z4.number(), currency: z4.string() }).optional(),
|
|
1616
1618
|
historyFrom: z4.string().nullable()
|
|
1617
1619
|
});
|
|
1620
|
+
var CronUsageSchema = z4.object({
|
|
1621
|
+
id: z4.string(),
|
|
1622
|
+
name: z4.string(),
|
|
1623
|
+
owner: z4.string(),
|
|
1624
|
+
ownerKind: z4.enum(["user", "org"]).optional(),
|
|
1625
|
+
status: z4.enum(["present", "removed"]),
|
|
1626
|
+
hours: z4.number(),
|
|
1627
|
+
cost: z4.object({ amount: z4.number(), currency: z4.string() }).optional(),
|
|
1628
|
+
/** When it was made. */
|
|
1629
|
+
historyFrom: z4.string().nullable()
|
|
1630
|
+
});
|
|
1618
1631
|
var UsageDayItemSchema = z4.object({
|
|
1619
1632
|
id: z4.string(),
|
|
1620
1633
|
name: z4.string(),
|
|
@@ -1633,7 +1646,9 @@ var UsageDaySchema = z4.object({
|
|
|
1633
1646
|
boxes: z4.array(UsageDayItemSchema),
|
|
1634
1647
|
volumes: z4.array(UsageDayItemSchema),
|
|
1635
1648
|
/** Object storage that existed that day (#182); absent on a day without any. */
|
|
1636
|
-
storage: z4.array(UsageDayItemSchema).optional()
|
|
1649
|
+
storage: z4.array(UsageDayItemSchema).optional(),
|
|
1650
|
+
/** Cron services that existed that day (#190); absent on a day without any. */
|
|
1651
|
+
cron: z4.array(UsageDayItemSchema).optional()
|
|
1637
1652
|
});
|
|
1638
1653
|
var UsageReportSchema = z4.object({
|
|
1639
1654
|
window: z4.object({ from: z4.string(), to: z4.string() }),
|
|
@@ -1646,6 +1661,8 @@ var UsageReportSchema = z4.object({
|
|
|
1646
1661
|
* included ones, `sizeGib` its whole size. Absent when there is none.
|
|
1647
1662
|
*/
|
|
1648
1663
|
storage: z4.array(VolumeUsageSchema).optional(),
|
|
1664
|
+
/** Cron services (#190, control plane only): one row per service a slug has or had. Absent when there is none. */
|
|
1665
|
+
cron: z4.array(CronUsageSchema).optional(),
|
|
1649
1666
|
/** With `?by=day` only, oldest day first. */
|
|
1650
1667
|
days: z4.array(UsageDaySchema).optional(),
|
|
1651
1668
|
totals: z4.object({
|
|
@@ -1655,7 +1672,7 @@ var UsageReportSchema = z4.object({
|
|
|
1655
1672
|
diskGibHours: z4.number(),
|
|
1656
1673
|
volumeHours: z4.number().optional(),
|
|
1657
1674
|
volumeGibHours: z4.number().optional(),
|
|
1658
|
-
/** Boxes, volumes
|
|
1675
|
+
/** Boxes, volumes, object storage and cron services together. */
|
|
1659
1676
|
cost: z4.object({ amount: z4.number(), currency: z4.string() }).optional()
|
|
1660
1677
|
})
|
|
1661
1678
|
});
|
|
@@ -5992,6 +6009,9 @@ var BOX_HTTP_PATH_RE = /^\/machines\/([^/]+)\/http\/(\d{1,5})\/?$/;
|
|
|
5992
6009
|
function edgeCredential(hostSecret) {
|
|
5993
6010
|
return createHmac2("sha256", hostSecret).update("kvbox-edge-v1").digest("base64url");
|
|
5994
6011
|
}
|
|
6012
|
+
function cronCredential(hostSecret) {
|
|
6013
|
+
return createHmac2("sha256", hostSecret).update("kvbox-cron-v1").digest("base64url");
|
|
6014
|
+
}
|
|
5995
6015
|
|
|
5996
6016
|
// src/app.ts
|
|
5997
6017
|
import { Hono as Hono11 } from "hono";
|
|
@@ -6009,7 +6029,7 @@ function versionOf(srcFileUrl, injected) {
|
|
|
6009
6029
|
}
|
|
6010
6030
|
|
|
6011
6031
|
// src/version.ts
|
|
6012
|
-
var VERSION = versionOf(import.meta.url, true ? "0.6.
|
|
6032
|
+
var VERSION = versionOf(import.meta.url, true ? "0.6.2" : void 0);
|
|
6013
6033
|
|
|
6014
6034
|
// src/caller.ts
|
|
6015
6035
|
import { createHash as createHash3, timingSafeEqual } from "node:crypto";
|
|
@@ -6026,9 +6046,10 @@ function resolveCaller(opts = {}) {
|
|
|
6026
6046
|
}
|
|
6027
6047
|
const authorized = secretCheck(cp);
|
|
6028
6048
|
const edge = edgeCheck(cp);
|
|
6049
|
+
const cron = cronCheck(cp);
|
|
6029
6050
|
return async (c, next) => {
|
|
6030
6051
|
const auth = c.req.header("authorization");
|
|
6031
|
-
if (!authorized(auth) && !(edge(auth) && BOX_HTTP_PATH_RE.test(c.req.path))) return c.json({ error: "not authorized" }, 401);
|
|
6052
|
+
if (!authorized(auth) && !((edge(auth) || cron(auth)) && BOX_HTTP_PATH_RE.test(c.req.path))) return c.json({ error: "not authorized" }, 401);
|
|
6032
6053
|
const user = c.req.header(OWNER_HEADER);
|
|
6033
6054
|
if (user === void 0) {
|
|
6034
6055
|
const path = c.req.path.replace(/\/$/, "");
|
|
@@ -6053,6 +6074,9 @@ function secretCheck(cp) {
|
|
|
6053
6074
|
function edgeCheck(cp) {
|
|
6054
6075
|
return bearerCheck(edgeCredential(cp.secret));
|
|
6055
6076
|
}
|
|
6077
|
+
function cronCheck(cp) {
|
|
6078
|
+
return bearerCheck(cronCredential(cp.secret));
|
|
6079
|
+
}
|
|
6056
6080
|
function bearerCheck(token) {
|
|
6057
6081
|
const expected = digest(token);
|
|
6058
6082
|
return (authorization) => {
|
|
@@ -6781,7 +6805,8 @@ async function listen(opts = {}) {
|
|
|
6781
6805
|
});
|
|
6782
6806
|
const secret = secretCheck(cp);
|
|
6783
6807
|
const edge = edgeCheck(cp);
|
|
6784
|
-
|
|
6808
|
+
const cron = cronCheck(cp);
|
|
6809
|
+
limitUntrusted(httpsServer, (req) => secret(req.headers.authorization) || edge(req.headers.authorization) || cron(req.headers.authorization));
|
|
6785
6810
|
httpsServer.on("upgrade", boxUpgradeHandler({ name: cp.name, secret: cp.secret }));
|
|
6786
6811
|
const port = opts.httpsPort ?? cp.port;
|
|
6787
6812
|
await new Promise((resolve3, reject) => {
|