@keyboxed/cli 0.2.3 → 0.2.4

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.
Files changed (2) hide show
  1. package/dist/keybox.js +28 -19
  2. package/package.json +1 -1
package/dist/keybox.js CHANGED
@@ -1890,7 +1890,7 @@ var VERSION;
1890
1890
  var init_version = __esm({
1891
1891
  "src/version.ts"() {
1892
1892
  "use strict";
1893
- VERSION = true ? "0.2.3" : "0.0.0-dev";
1893
+ VERSION = true ? "0.2.4" : "0.0.0-dev";
1894
1894
  }
1895
1895
  });
1896
1896
 
@@ -1898,6 +1898,7 @@ var init_version = __esm({
1898
1898
  var verify_exports = {};
1899
1899
  __export(verify_exports, {
1900
1900
  checks: () => checks,
1901
+ liveHealth: () => liveHealth,
1901
1902
  printChecks: () => printChecks,
1902
1903
  resolveAccount: () => resolveAccount,
1903
1904
  shippedWorkerHash: () => shippedWorkerHash,
@@ -1906,6 +1907,20 @@ __export(verify_exports, {
1906
1907
  });
1907
1908
  import { createHash } from "node:crypto";
1908
1909
  import { readFileSync as readFileSync4 } from "node:fs";
1910
+ async function liveHealth(url, want, seconds = 30) {
1911
+ let last = null;
1912
+ const until = Date.now() + seconds * 1e3;
1913
+ do {
1914
+ try {
1915
+ const r = await fetch(`${url}/_keybox/health?t=${Date.now()}`, { cache: "no-store" });
1916
+ if (r.ok) last = await r.json();
1917
+ } catch {
1918
+ }
1919
+ if (last?.configured && (!want || last.version === want)) return last;
1920
+ await new Promise((r) => setTimeout(r, 1500));
1921
+ } while (Date.now() < until);
1922
+ return last;
1923
+ }
1909
1924
  function parts(body, contentType) {
1910
1925
  const boundary = /boundary="?([^";]+)"?/.exec(contentType)?.[1];
1911
1926
  const out2 = /* @__PURE__ */ new Map();
@@ -1983,14 +1998,16 @@ async function checks(cfg) {
1983
1998
  out2.push(
1984
1999
  tails.length || s.logpush ? { ok: "warn", label: "Observers", detail: `${tails.length ? `tail workers: ${tails.map((t) => t.service).join(", ")}` : ""}${s.logpush ? " Logpush is on" : ""}`.trim() } : { ok: true, label: "Observers", detail: "no tail workers, no Logpush" }
1985
2000
  );
1986
- try {
1987
- const h = await (await fetch(`${cfg.url}/_keybox/health`)).json();
1988
- out2.push(
1989
- h.configured ? h.version === shippedWorkerVersion() ? { ok: true, label: "Live", detail: `answering as v${h.version}` } : { ok: out2[0]?.ok === true ? false : "warn", label: "Live", detail: `answering as v${h.version}, this CLI ships Worker v${shippedWorkerVersion()}${out2[0]?.ok === true ? ": the URL is served by a different Worker than the one checked above" : ""}` } : { ok: false, label: "Live", detail: "answering, but missing its encryption key or admin token" }
1990
- );
1991
- } catch {
1992
- out2.push({ ok: false, label: "Live", detail: `not reachable at ${cfg.url}` });
1993
- }
2001
+ const wantVersion = shippedWorkerVersion();
2002
+ const codeMatched = out2[0]?.ok === true;
2003
+ const h = await liveHealth(cfg.url, codeMatched ? wantVersion : void 0, codeMatched ? 45 : 0);
2004
+ out2.push(
2005
+ !h ? { ok: false, label: "Live", detail: `not reachable at ${cfg.url}` } : !h.configured ? { ok: false, label: "Live", detail: "answering, but missing its encryption key or admin token" } : h.version === wantVersion ? { ok: true, label: "Live", detail: `answering as v${h.version}` } : codeMatched ? {
2006
+ ok: false,
2007
+ label: "Live",
2008
+ detail: `still answering as v${h.version} after 45s (this CLI ships v${wantVersion}). Run keybox verify again in a minute; if it stays, ${cfg.url} is served by a different Worker than the one checked above`
2009
+ } : { ok: "warn", label: "Live", detail: `answering as v${h.version}, this CLI ships Worker v${wantVersion}` }
2010
+ );
1994
2011
  return out2;
1995
2012
  }
1996
2013
  function printChecks(list2) {
@@ -2095,16 +2112,8 @@ async function findDb(name) {
2095
2112
  return dbs.find((d) => d.name === name)?.uuid ?? null;
2096
2113
  }
2097
2114
  async function waitConfigured(url) {
2098
- for (let i = 0; i < 30; i++) {
2099
- try {
2100
- const r = await fetch(`${url}/_keybox/health`);
2101
- const h = await r.json();
2102
- if (r.ok && h.configured) return h.version;
2103
- } catch {
2104
- }
2105
- await new Promise((r) => setTimeout(r, 1e3));
2106
- }
2107
- return null;
2115
+ const h = await liveHealth(url, shippedWorkerVersion(), 45);
2116
+ return h?.configured ? h.version : null;
2108
2117
  }
2109
2118
  async function pickAccount(accounts, wanted) {
2110
2119
  if (wanted) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@keyboxed/cli",
3
- "version": "0.2.3",
3
+ "version": "0.2.4",
4
4
  "description": "Give AI agents access to your APIs without giving them your keys.",
5
5
  "homepage": "https://keybox.space",
6
6
  "license": "FSL-1.1-ALv2",