@query-farm/vgi 0.25.4 → 0.26.1

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/src/http/fetch.ts CHANGED
@@ -13,7 +13,7 @@
13
13
  import { createHttpHandler, unpackStateToken, type Protocol } from "@query-farm/vgi-rpc";
14
14
  import { arrowStateSerializer } from "../protocol/state-serializer.js";
15
15
  import { buildVgiProtocol, type ProtocolConfig } from "../protocol/dispatch.js";
16
- import type { LandingInfo } from "@query-farm/vgi-rpc";
16
+ import { createLandingRoutes, type LandingInfo } from "./landing.js";
17
17
 
18
18
  export interface VgiFetchOptions {
19
19
  /** Wire-protocol config (registry + catalogInterface). */
@@ -35,11 +35,20 @@ export interface VgiFetchOptions {
35
35
  corsOrigins?: string;
36
36
  /** Public source-repository URL, surfaced on the landing page. */
37
37
  repositoryUrl?: string;
38
- /** Enables the standardized VGI landing surface: `GET /` serves the shared
39
- * landing.html plus a JSON status document carrying this identity, and
40
- * `GET /vgi-client.js` serves the browser client build the page reads the
41
- * catalog with. */
42
- landingInfo?: LandingInfo;
38
+ /** Worker identity for the standardized VGI landing surface: `GET /` serves
39
+ * the shared landing.html plus a JSON status document carrying this
40
+ * identity, and `GET /vgi-client.js` serves the browser client build the
41
+ * page reads the catalog with.
42
+ *
43
+ * Required, and deliberately so. It used to be optional, and omitting it
44
+ * silently downgraded `GET /` to vgi-rpc's generic "this is an RPC
45
+ * endpoint" placeholder while `GET /vgi-client.js` 404'd — a worker that
46
+ * looked deployed but had no catalog tree, no Cupola link, and no ATTACH
47
+ * snippet. Nothing failed loudly, so the only way to notice was to open the
48
+ * page. `serveVgiWorker` never had the problem because it builds this from
49
+ * its required name/doc/version; the CF entry had to remember, and
50
+ * vgi-open-meteo shipped for weeks without it. */
51
+ landingInfo: LandingInfo;
43
52
  }
44
53
 
45
54
  /**
@@ -49,6 +58,17 @@ export interface VgiFetchOptions {
49
58
  * round-trips through the signed state token created here.
50
59
  */
51
60
  export function createVgiFetch(opts: VgiFetchOptions): (req: Request) => Promise<Response> {
61
+ // The type makes this required, but a plain-JS caller (or one that predates
62
+ // the change) reaches here with it undefined, and the failure mode this
63
+ // guards is silent: a worker that serves a placeholder page forever. Fail
64
+ // at construction, where the stack points at the caller.
65
+ if (!opts.landingInfo) {
66
+ throw new Error(
67
+ "createVgiFetch requires `landingInfo` ({ name, doc, version }). Without it " +
68
+ "GET / serves vgi-rpc's generic placeholder instead of the VGI landing page " +
69
+ "and GET /vgi-client.js 404s.",
70
+ );
71
+ }
52
72
  const tokenTtl = opts.tokenTtl ?? 3600;
53
73
  // `?? "/vgi"` and not `|| "/vgi"`: an explicit "" means "mount at root".
54
74
  const prefix = opts.prefix ?? "/vgi";
@@ -74,7 +94,12 @@ export function createVgiFetch(opts: VgiFetchOptions): (req: Request) => Promise
74
94
  stateSerializer: arrowStateSerializer,
75
95
  corsOrigins: opts.corsOrigins,
76
96
  repositoryUrl: opts.repositoryUrl,
77
- landingInfo: opts.landingInfo,
97
+ // The landing surface is ours, contributed into vgi-rpc's routing rather
98
+ // than built there. `enableLandingPage: false` drops vgi-rpc's generic
99
+ // "this is an RPC endpoint" page, which would otherwise sit behind ours for
100
+ // no reason — a VGI worker always has the real thing.
101
+ extraRoutes: createLandingRoutes(opts.landingInfo),
102
+ enableLandingPage: false,
78
103
  });
79
104
  return async (req: Request) => handler(req);
80
105
  }