@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/README.md +6 -0
- package/dist/client-entry.js +2 -1
- package/dist/client-entry.js.map +4 -4
- package/dist/http/client-bundle.d.ts +2 -0
- package/dist/http/fetch.d.ts +15 -6
- package/dist/http/landing-html.d.ts +2 -0
- package/dist/http/landing.d.ts +36 -0
- package/dist/index.core.d.ts +2 -1
- package/dist/index.js +107 -1
- package/dist/index.js.map +9 -6
- package/dist/serve-entry.js +111 -2
- package/dist/serve-entry.js.map +8 -5
- package/dist/types.d.ts +1 -0
- package/dist/worker-cf-entry.d.ts +4 -3
- package/dist/worker-cf-entry.js +115 -6
- package/dist/worker-cf-entry.js.map +11 -8
- package/package.json +3 -3
- package/src/http/client-bundle.ts +24 -0
- package/src/http/fetch.ts +32 -7
- package/src/http/landing-html.ts +23 -0
- package/src/http/landing.ts +195 -0
- package/src/index.core.ts +2 -1
- package/src/protocol/serializers/bind.ts +2 -0
- package/src/types.ts +4 -0
- package/src/worker-cf-entry.ts +9 -1
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
|
|
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
|
-
/**
|
|
39
|
-
* landing.html plus a JSON status document carrying this
|
|
40
|
-
* `GET /vgi-client.js` serves the browser client build the
|
|
41
|
-
* catalog with.
|
|
42
|
-
|
|
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
|
-
|
|
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
|
}
|