@kvbox/server 0.5.39 → 0.5.41

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.
@@ -185,6 +185,7 @@ var PricingSchema = z.object({
185
185
  volumeGibHour: z.number().nonnegative().default(0),
186
186
  diskIncludedGib: z.number().int().nonnegative().default(0)
187
187
  });
188
+ var PriceListSchema = PricingSchema.extend({ welcomeCredit: z.number().nonnegative() });
188
189
  var HOUR_MS = 36e5;
189
190
  var round = (n, places) => Math.round(n * 10 ** places) / 10 ** places;
190
191
  function computeUsage(events, w) {
@@ -972,8 +973,11 @@ var VolumeEventsResponseSchema = z3.object({
972
973
  events: z3.array(VolumeEventRowSchema),
973
974
  next: z3.number().int()
974
975
  });
976
+ var API_ERROR_CODES = ["account-inactive", "org-inactive", "out-of-credit"];
977
+ var ApiErrorCodeSchema = z3.enum(API_ERROR_CODES);
975
978
  var ApiErrorSchema = z3.object({
976
- error: z3.string()
979
+ error: z3.string(),
980
+ code: ApiErrorCodeSchema.optional()
977
981
  });
978
982
  var ACTIVATED_BY = ["card", "admin"];
979
983
  var ActivatedBySchema = z3.enum(ACTIVATED_BY);
@@ -4471,7 +4475,7 @@ async function withTries(what, fn, signal) {
4471
4475
  }
4472
4476
 
4473
4477
  // src/core/relay.ts
4474
- import { chmod as chmod3, mkdir as mkdir8, rm as rm5, writeFile as writeFile7 } from "node:fs/promises";
4478
+ import { access as access2, chmod as chmod3, mkdir as mkdir8, rm as rm5, writeFile as writeFile7 } from "node:fs/promises";
4475
4479
 
4476
4480
  // ../shared/src/relay.ts
4477
4481
  import { z as z7 } from "zod";
@@ -4543,6 +4547,13 @@ async function useRelay(joinString, p = paths()) {
4543
4547
  await saveConfig({ ...cfg, relay }, p);
4544
4548
  return relay;
4545
4549
  }
4550
+ async function restoreRelay(p = paths()) {
4551
+ const cfg = await loadConfig(p);
4552
+ if (!cfg.relay) return null;
4553
+ await access2(p.relayConf);
4554
+ await netSetup(cfg, ["relay", "up", p.relayConf, String(cfg.controlPlane?.port ?? DEFAULT_HTTPS_PORT)]);
4555
+ return cfg.relay;
4556
+ }
4546
4557
  async function dropRelay(p = paths()) {
4547
4558
  const cfg = await loadConfig(p);
4548
4559
  const relay = cfg.relay;
@@ -4745,7 +4756,7 @@ function versionOf(srcFileUrl, injected) {
4745
4756
  }
4746
4757
 
4747
4758
  // src/version.ts
4748
- var VERSION = versionOf(import.meta.url, true ? "0.5.39" : void 0);
4759
+ var VERSION = versionOf(import.meta.url, true ? "0.5.41" : void 0);
4749
4760
 
4750
4761
  // src/caller.ts
4751
4762
  import { createHash as createHash2, timingSafeEqual } from "node:crypto";
@@ -5469,6 +5480,12 @@ program.command("start", { isDefault: true }).description("serve the API on the
5469
5480
  } catch (err) {
5470
5481
  console.error(`warning: host network not ready (${err.message}); run: kvbox-server net up`);
5471
5482
  }
5483
+ try {
5484
+ const relay = await restoreRelay(paths());
5485
+ if (relay) console.log(`relay ${relay.name}: the control plane may reach this host through the tunnel again`);
5486
+ } catch (err) {
5487
+ console.error(`warning: the control plane may not reach this host through its relay (${err.message}); run: kvbox server relay <join string>`);
5488
+ }
5472
5489
  let dnsWarned = false;
5473
5490
  const bindDns = () => {
5474
5491
  loadConfig(paths()).then(async (cfg) => {