@vite-hub/comments 0.7.0 → 0.9.0
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 +4 -10
- package/dist/anchor.d.ts +2 -2
- package/dist/anchor.js +0 -1
- package/dist/{client-files-lC6X7XyS.js → client-files-CMPJEd21.js} +0 -1
- package/dist/client-request-B1DCz3a9.js +29 -0
- package/dist/client.d.ts +21 -241
- package/dist/client.js +4 -425
- package/dist/database.d.ts +1 -2
- package/dist/database.js +1 -1
- package/dist/{define-BqPcuDhf.js → define-hs9Z38io.js} +1 -2
- package/dist/{errors-C0VwRHiy.js → errors-C5utwZ5H.js} +0 -24
- package/dist/{errors-CBvIpwbo.js → errors-DeSEHzRf.js} +0 -12
- package/dist/hosted/hosted-comments/frame.js +4 -1
- package/dist/hosted/hosted-comments/tools.js +71 -77
- package/dist/hosted/hosted-comments.js +1 -1
- package/dist/{index-D1T7RJ4R.d.ts → index-CbXek64X.d.ts} +5 -113
- package/dist/index.d.ts +5 -6
- package/dist/index.js +6 -23
- package/dist/{install-CqBWFmU7.js → install--HecUN5c.js} +8 -789
- package/dist/{install-9L4ASzUC.d.ts → install-C3CW6Vvw.d.ts} +6 -12
- package/dist/{installed-wUYjqk_k.js → installed-BqQKo6WC.js} +2 -7
- package/dist/{database-BuSNVwTx.js → migrate-cxoJK4JQ.js} +2 -64
- package/dist/{operations-Qt8ASQqW.d.ts → operations-D0EO1pzL.d.ts} +36 -8
- package/dist/{operations-kMPw-Cyb.js → operations-DHXmbtb3.js} +47 -75
- package/dist/operations.d.ts +3 -3
- package/dist/operations.js +2 -2
- package/dist/overlay/client-BszZKIf8.js +4 -0
- package/dist/overlay/overlay.js +50 -43
- package/dist/page/loader.js +37 -30
- package/dist/{page-2NzFladc.js → page-CJz1K67L.js} +25 -2
- package/dist/page-DRM1j84-.d.ts +32 -0
- package/dist/{page-tools-shared-BNw-aWEH.js → page-tools-shared-BCdvqA4S.js} +40 -2
- package/dist/{path-8yqMd8zR.js → path-sv8kjq3i.js} +0 -4
- package/dist/{plugin-ChOHe7vq.js → plugin-DczA2K-y.js} +9 -9
- package/dist/realtime.d.ts +7 -9
- package/dist/realtime.js +2 -4
- package/dist/{rpc-kkxzQ3Qy.js → rpc-51X1TWKb.js} +1 -1
- package/dist/{rpc-D-eqtyfh.d.ts → rpc-DZB3yU0z.d.ts} +1 -1
- package/dist/rpc.d.ts +1 -1
- package/dist/rpc.js +1 -1
- package/dist/runtime/auth.d.ts +1 -2
- package/dist/runtime/auth.js +1 -1
- package/dist/runtime/client-request-plugin.d.ts +2 -0
- package/dist/runtime/client-request-plugin.js +21 -0
- package/dist/runtime/console.js +2 -2
- package/dist/runtime/index.d.ts +6 -9
- package/dist/runtime/index.js +25 -175
- package/dist/{server-8o9u8leM.js → server-CAMs6viR.js} +1 -1
- package/dist/server.d.ts +12 -8
- package/dist/server.js +8 -7
- package/dist/{service-XT2A8YEF.js → service-DFMwCr60.js} +34 -42
- package/dist/{store-DvNTDNgn.d.ts → service-qaMuJ7UX.d.ts} +68 -2
- package/dist/{session-DGdFKWDB.js → session-1SI3_wLJ.js} +212 -66
- package/dist/{session-CN4irEqf.d.ts → session-CK3Rnjto.d.ts} +2 -3
- package/dist/{table-names-BIHjuEFK.js → table-names-DUmWROM4.js} +1 -3
- package/dist/testing.d.ts +1 -1
- package/dist/testing.js +1 -2
- package/dist/{tokens-Bx4lZ0yt.js → tokens-WRh__ppm.js} +0 -1
- package/dist/{types-BX3vH18p.d.ts → types-BmzTyGt-.d.ts} +4 -0
- package/dist/{define-B1jLSPe9.d.ts → types-VSVs4jIw.d.ts} +157 -4
- package/dist/vite.d.ts +3 -20
- package/dist/vite.js +15 -82
- package/package.json +8 -8
- package/dist/database-CPua6Q6_.d.ts +0 -573
- package/dist/overlay/client-CrnKCZXc.js +0 -4
- package/dist/overlay/dist-yIZmvSaU.js +0 -1
- package/dist/page-DE71P_gQ.d.ts +0 -11
- package/dist/request-origin-B-CPVAVk.js +0 -53
- package/dist/service-IvgrI4XM.d.ts +0 -71
- package/dist/types-l6GOb_yc.d.ts +0 -206
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
1
|
+
import { a as viteHubPageSessionPath, c as viteHubPageToolsHintCookie, d as viteHubPageToolsLoader, f as viteHubPageToolsMarker, h as withViteHubBase, i as viteHubPageSessionHandoffScript, l as viteHubPageToolsInlineScript, m as viteHubPageToolsWanted, n as readViteHubPageSession, p as viteHubPageToolsQuery, r as viteHubBasePath, t as readViteHubPageAccount } from "./page-tools-shared-BCdvqA4S.js";
|
|
2
|
+
import { t as clientRequest } from "./client-request-B1DCz3a9.js";
|
|
3
|
+
import { p as normalizeCommentPage } from "./page-CJz1K67L.js";
|
|
4
4
|
import { getStandardContext } from "@vite-hub/runtime/internal/h3";
|
|
5
5
|
// ../internal/src/runtime/page-tools-html.ts
|
|
6
6
|
/** The effective script-element directive is shared by HTTP and HTML meta policies. */
|
|
@@ -30,12 +30,11 @@ function isGeneratedCheck(inline) {
|
|
|
30
30
|
try {
|
|
31
31
|
const path = JSON.parse(inline.slice(at + 7, -1));
|
|
32
32
|
const nonce = tagNonce(inline);
|
|
33
|
-
return typeof path === "string" && path.endsWith("/_vitehub/page/assets/loader.js?v=
|
|
33
|
+
return typeof path === "string" && path.endsWith("/_vitehub/page/assets/loader.js?v=28") && viteHubPageToolsInlineScript(path.slice(0, -36), nonce) === `${inline}<\/script>`;
|
|
34
34
|
} catch {
|
|
35
35
|
return false;
|
|
36
36
|
}
|
|
37
37
|
}
|
|
38
|
-
/** A tag ends at an unquoted `>`, so markup quoted in an attribute stays untouched. */
|
|
39
38
|
function tagEnd(text) {
|
|
40
39
|
let quote = "";
|
|
41
40
|
for (let index = 1; index < text.length; index++) {
|
|
@@ -47,8 +46,12 @@ function tagEnd(text) {
|
|
|
47
46
|
}
|
|
48
47
|
return -1;
|
|
49
48
|
}
|
|
50
|
-
/**
|
|
51
|
-
|
|
49
|
+
/**
|
|
50
|
+
* Scan HTML tokens across chunks; only active script elements can own the loader marker. `late` gives more markup for
|
|
51
|
+
* the end of the body, with the nonce of the loader tag. It is called once, when the transform reaches `</body>` or the
|
|
52
|
+
* end of the page, so it can give what became known while the page streamed.
|
|
53
|
+
*/
|
|
54
|
+
function pageToolsHtmlTransform(loader, late) {
|
|
52
55
|
const decoder = new TextDecoder();
|
|
53
56
|
const encoder = new TextEncoder();
|
|
54
57
|
let pending = "";
|
|
@@ -58,6 +61,7 @@ function pageToolsHtmlTransform(loader) {
|
|
|
58
61
|
let templates = 0;
|
|
59
62
|
let present = false;
|
|
60
63
|
let done = false;
|
|
64
|
+
const ending = () => late?.(tagNonce(loader)) ?? "";
|
|
61
65
|
return new TransformStream({
|
|
62
66
|
transform(chunk, controller) {
|
|
63
67
|
pending += decoder.decode(chunk, { stream: true });
|
|
@@ -139,6 +143,7 @@ function pageToolsHtmlTransform(loader) {
|
|
|
139
143
|
if (nonce) loader = loader.replace(` ${viteHubPageToolsMarker}`, ` nonce="${nonce}" ${viteHubPageToolsMarker}`);
|
|
140
144
|
}
|
|
141
145
|
if (name === "body" && closing && !templates) {
|
|
146
|
+
emit(ending());
|
|
142
147
|
if (!present) emit(loader);
|
|
143
148
|
done = true;
|
|
144
149
|
}
|
|
@@ -159,10 +164,53 @@ function pageToolsHtmlTransform(loader) {
|
|
|
159
164
|
},
|
|
160
165
|
flush(controller) {
|
|
161
166
|
const rest = inline + pending + decoder.decode();
|
|
162
|
-
controller.enqueue(encoder.encode(rest + (done || present ? "" : loader)));
|
|
167
|
+
controller.enqueue(encoder.encode(rest + (done ? "" : ending()) + (done || present ? "" : loader)));
|
|
163
168
|
}
|
|
164
169
|
});
|
|
165
170
|
}
|
|
171
|
+
// ../internal/src/runtime/request-origin.ts
|
|
172
|
+
function firstHeaderValue(headers, name) {
|
|
173
|
+
return headers.get(name)?.split(",", 1)[0]?.trim() || void 0;
|
|
174
|
+
}
|
|
175
|
+
const applicationOriginKey = Symbol.for("vitehub.request.application-origin");
|
|
176
|
+
const requestGlobals = globalThis;
|
|
177
|
+
function setApplicationRequestOrigin(request, origin) {
|
|
178
|
+
(requestGlobals[applicationOriginKey] ??= /* @__PURE__ */ new WeakMap()).set(request, origin);
|
|
179
|
+
}
|
|
180
|
+
function applicationRequestOrigin(request) {
|
|
181
|
+
return requestGlobals[applicationOriginKey]?.get(request) ?? forwardedRequestOrigin(request);
|
|
182
|
+
}
|
|
183
|
+
/**
|
|
184
|
+
* The origin that the client used for `request`. A TLS-terminating proxy sends the client scheme in
|
|
185
|
+
* `X-Forwarded-Proto` and the client host in `X-Forwarded-Host`. Each proxy appends its value, so the first value wins.
|
|
186
|
+
* Without these headers, or with values that are not valid, the result is the origin of `request.url`.
|
|
187
|
+
*/
|
|
188
|
+
function forwardedRequestOrigin(request) {
|
|
189
|
+
const url = new URL(request.url);
|
|
190
|
+
const forwardedProtocol = firstHeaderValue(request.headers, "x-forwarded-proto")?.toLowerCase();
|
|
191
|
+
const protocol = forwardedProtocol === "http" || forwardedProtocol === "https" ? forwardedProtocol : url.protocol.slice(0, -1);
|
|
192
|
+
const host = firstHeaderValue(request.headers, "x-forwarded-host") ?? url.host;
|
|
193
|
+
if (/[\u0000-\u001F\s/\\?#@]/.test(host)) return url.origin;
|
|
194
|
+
try {
|
|
195
|
+
return new URL(`${protocol}://${host}`).origin;
|
|
196
|
+
} catch {
|
|
197
|
+
return url.origin;
|
|
198
|
+
}
|
|
199
|
+
}
|
|
200
|
+
/**
|
|
201
|
+
* Whether a request came in on one of the public `origins` of the app, such as the origin of `vitehub({ publicUrl })`.
|
|
202
|
+
* It compares the host that the client used, so a proxy that does not forward the scheme still matches. A loopback
|
|
203
|
+
* host, such as `localhost:3000` for a preview or a proxy that does not forward the host, also matches: it cannot be a
|
|
204
|
+
* second public hostname. Every request matches when `origins` is empty.
|
|
205
|
+
*/
|
|
206
|
+
function matchesPublicOrigin(request, origins) {
|
|
207
|
+
if (origins.length === 0) return true;
|
|
208
|
+
const { host, hostname } = new URL(forwardedRequestOrigin(request));
|
|
209
|
+
return isLoopbackHostname(hostname) || origins.some((origin) => new URL(origin).host === host);
|
|
210
|
+
}
|
|
211
|
+
function isLoopbackHostname(hostname) {
|
|
212
|
+
return hostname === "localhost" || hostname === "[::1]" || /^127(?:\.\d{1,3}){3}$/.test(hostname);
|
|
213
|
+
}
|
|
166
214
|
// ../internal/src/runtime/page-tools.ts
|
|
167
215
|
const stateKey = Symbol.for("vitehub.page-tools");
|
|
168
216
|
const scope = globalThis;
|
|
@@ -187,15 +235,15 @@ function registerViteHubPageTool(nitroApp, tool) {
|
|
|
187
235
|
const grants = state().grants ??= /* @__PURE__ */ new Map();
|
|
188
236
|
for (const grant of tool.grants ?? []) grants.set(grant.id, grant);
|
|
189
237
|
}
|
|
190
|
-
/** The account of a visitor, or `undefined` without a reader, without a session, or when the reader fails. */
|
|
191
238
|
async function readAccount(nitroApp, request) {
|
|
192
239
|
const read = state().accounts?.get(nitroApp);
|
|
193
|
-
if (!read) return
|
|
240
|
+
if (!read) return {};
|
|
194
241
|
try {
|
|
195
|
-
|
|
242
|
+
const account = readViteHubPageAccount(await read({ request }));
|
|
243
|
+
return account ? { account } : {};
|
|
196
244
|
} catch (error) {
|
|
197
245
|
console.error("[vitehub] The page tools could not read the signed-in person. The pill shows no account for this request.", error);
|
|
198
|
-
return;
|
|
246
|
+
return { failed: true };
|
|
199
247
|
}
|
|
200
248
|
}
|
|
201
249
|
/**
|
|
@@ -209,25 +257,18 @@ function installViteHubSiteVisitor(reader) {
|
|
|
209
257
|
function viteHubSiteVisitorReader() {
|
|
210
258
|
return state().siteVisitor;
|
|
211
259
|
}
|
|
212
|
-
/** Whether the app serves its page tools on the origin of the request. Every origin counts for an app without `origins`. */
|
|
213
260
|
function servesOrigin(nitroApp, request) {
|
|
214
261
|
const origins = state().origins?.get(nitroApp) ?? [];
|
|
215
262
|
return matchesPublicOrigin(request, typeof origins === "function" ? origins() : origins);
|
|
216
263
|
}
|
|
217
|
-
/** The path of a URL below the app base. A path outside the base stays as it is. */
|
|
218
264
|
function pathBelow(base, pathname) {
|
|
219
265
|
return base && (pathname === base || pathname.startsWith(`${base}/`)) ? pathname.slice(base.length) || "/" : pathname;
|
|
220
266
|
}
|
|
221
|
-
/** Whether a URL is an app page that can get the page tools: inside the app base, and not under `/_vitehub` or `/api`. */
|
|
222
267
|
function isPagePath(url, base) {
|
|
223
268
|
if (base && url.pathname !== base && !url.pathname.startsWith(`${base}/`)) return false;
|
|
224
269
|
const path = pathBelow(base, url.pathname);
|
|
225
270
|
return !(path.startsWith("/_vitehub") || path === "/api" || path.startsWith("/api/"));
|
|
226
271
|
}
|
|
227
|
-
/**
|
|
228
|
-
* What ViteHub adds to the page of this request: the loader for a request with the hint, the bootstrap for any other
|
|
229
|
-
* page, or nothing when no tool is registered or the path is not a page.
|
|
230
|
-
*/
|
|
231
272
|
function pageAddition(nitroApp, request, base) {
|
|
232
273
|
const url = new URL(request.url);
|
|
233
274
|
if ((state().tools.get(nitroApp)?.size ?? 0) === 0 || !isPagePath(url, base)) return void 0;
|
|
@@ -237,12 +278,14 @@ function pageAddition(nitroApp, request, base) {
|
|
|
237
278
|
function loaderTag(base, nonce) {
|
|
238
279
|
return `<script type="module" src="${base}${viteHubPageToolsLoader}"${nonce ? ` nonce="${nonce}"` : ""} ${viteHubPageToolsMarker}><\/script>`;
|
|
239
280
|
}
|
|
281
|
+
const sessionCompleteHeader = "x-vitehub-page-session";
|
|
240
282
|
function sessionResponse(value, init = {}) {
|
|
241
283
|
const headers = new Headers({
|
|
242
284
|
"cache-control": "private, no-store",
|
|
243
285
|
"content-type": "application/json; charset=utf-8"
|
|
244
286
|
});
|
|
245
287
|
if (init.cookie) headers.append("set-cookie", init.cookie);
|
|
288
|
+
if (init.complete) headers.set(sessionCompleteHeader, "complete");
|
|
246
289
|
return new Response(JSON.stringify(value), {
|
|
247
290
|
headers,
|
|
248
291
|
status: init.status ?? 200
|
|
@@ -254,7 +297,8 @@ function sessionResponse(value, init = {}) {
|
|
|
254
297
|
* each tool `script` path gets it. When at least one tool is allowed, the answer also has the `account` of a signed-in
|
|
255
298
|
* visitor, from the reader of `registerViteHubPageAccount()`. An anonymous visitor never gets one. It sets the hint cookie to `1` when at least one tool is allowed, and to `0` when
|
|
256
299
|
* none is, so a signed-in person without access does not ask again on each page. A tool whose check throws is not
|
|
257
|
-
* allowed.
|
|
300
|
+
* allowed. The answer has `x-vitehub-page-session: complete` when every check and the account reader answered without
|
|
301
|
+
* throwing, so a denied tool or a missing account is the decision for this visitor and not a failure. Requests from other sites get 403 and run no check. An origin that the app does not serve its page tools on
|
|
258
302
|
* gets 404.
|
|
259
303
|
*/
|
|
260
304
|
async function respondViteHubPageSession(nitroApp, request) {
|
|
@@ -277,22 +321,30 @@ async function respondViteHubPageSession(nitroApp, request) {
|
|
|
277
321
|
return await tool.allowed({ request });
|
|
278
322
|
} catch (error) {
|
|
279
323
|
console.error(`[vitehub] The visitor check of the page tool "${tool.id}" failed. The tool stays off for this request.`, error);
|
|
280
|
-
return
|
|
324
|
+
return null;
|
|
281
325
|
}
|
|
282
326
|
}));
|
|
283
327
|
const pathname = new URL(request.url).pathname;
|
|
284
328
|
const at = pathname.lastIndexOf(viteHubPageSessionPath);
|
|
285
329
|
const base = at > 0 ? pathname.slice(0, at) : "";
|
|
286
|
-
const tools = registered.flatMap((
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
330
|
+
const tools = registered.flatMap((registeredTool, index) => {
|
|
331
|
+
const check = checks[index];
|
|
332
|
+
if (check !== true && check !== "lazy") return [];
|
|
333
|
+
const { allowed: _allowed, grants: _grants, ...tool } = registeredTool;
|
|
334
|
+
return [{
|
|
335
|
+
...tool,
|
|
336
|
+
...check === "lazy" ? { lazy: true } : {},
|
|
337
|
+
script: withViteHubBase(base, tool.script)
|
|
338
|
+
}];
|
|
339
|
+
});
|
|
340
|
+
const { account, failed } = tools.length > 0 ? await readAccount(nitroApp, request) : {};
|
|
292
341
|
return sessionResponse(account ? {
|
|
293
342
|
tools,
|
|
294
343
|
account
|
|
295
|
-
} : { tools }, {
|
|
344
|
+
} : { tools }, {
|
|
345
|
+
cookie: viteHubPageToolsHintCookie(tools.length > 0),
|
|
346
|
+
complete: !failed && !checks.includes(null)
|
|
347
|
+
});
|
|
296
348
|
}
|
|
297
349
|
/**
|
|
298
350
|
* The route of `GET /_vitehub/page/tools`: a Fetchable (https://fetchable.org). `installViteHubPageTools()` binds
|
|
@@ -313,25 +365,110 @@ const viteHubPageSessionHandler = { async fetch(request) {
|
|
|
313
365
|
function scriptNonce(headers) {
|
|
314
366
|
return scriptPolicyNonce(headers.get("content-security-policy") ?? "");
|
|
315
367
|
}
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
368
|
+
function attribute(value) {
|
|
369
|
+
return value.replaceAll("&", "&").replaceAll("\"", """).replaceAll("<", "<");
|
|
370
|
+
}
|
|
371
|
+
function handoffMarkup(handoff, nonce) {
|
|
372
|
+
const preloads = handoff.session.tools.filter((tool) => !tool.lazy).map((tool) => `<link rel="modulepreload" href="${attribute(tool.script)}"${nonce ? ` nonce="${nonce}"` : ""}>`);
|
|
373
|
+
return `${viteHubPageSessionHandoffScript(handoff, nonce)}${preloads.join("")}`;
|
|
374
|
+
}
|
|
375
|
+
const sharedCacheHeader = /^(?:(?:[a-z0-9-]+-)?cdn-cache-control|surrogate-control)$/;
|
|
376
|
+
const sharedCacheRules = [
|
|
377
|
+
"isr",
|
|
378
|
+
"swr",
|
|
379
|
+
"cache",
|
|
380
|
+
"prerender"
|
|
381
|
+
];
|
|
382
|
+
function sharedCacheMayStore(request, response) {
|
|
383
|
+
const control = response.headers.get("cache-control")?.toLowerCase() ?? "";
|
|
384
|
+
if (/(?:^|[\s,])(?:public|s-maxage)(?:[\s,=]|$)/.test(control)) return true;
|
|
385
|
+
for (const [name] of response.headers) if (sharedCacheHeader.test(name)) return true;
|
|
386
|
+
const context = Reflect.get(request, "context");
|
|
387
|
+
if (context === null || typeof context !== "object" || !Reflect.get(context, "nitro")) return true;
|
|
388
|
+
const rules = Reflect.get(context, "routeRules");
|
|
389
|
+
if (rules === void 0) return false;
|
|
390
|
+
if (rules === null || typeof rules !== "object") return true;
|
|
391
|
+
return sharedCacheRules.some((name) => {
|
|
392
|
+
const rule = Reflect.get(rules, name);
|
|
393
|
+
return rule !== void 0 && rule !== null && rule !== false;
|
|
394
|
+
});
|
|
395
|
+
}
|
|
396
|
+
function acceptsHtml(request) {
|
|
397
|
+
return request.headers.get("accept")?.split(",").some((range) => {
|
|
398
|
+
const [type, ...parameters] = range.split(";").map((part) => part.trim());
|
|
399
|
+
if (type?.toLowerCase() !== "text/html") return false;
|
|
400
|
+
const quality = parameters.find((part) => /^q\s*=/i.test(part))?.split("=")[1]?.trim();
|
|
401
|
+
return quality === void 0 || Number(quality) > 0 && Number(quality) <= 1;
|
|
402
|
+
}) === true;
|
|
403
|
+
}
|
|
404
|
+
function mayHandOffSession(request) {
|
|
405
|
+
return request.method === "GET" && !request.headers.has("x-nitro-prerender") && acceptsHtml(request) && (request.headers.has("cookie") || request.headers.has("authorization"));
|
|
406
|
+
}
|
|
407
|
+
function sessionRequestFor(request, base) {
|
|
408
|
+
const url = new URL(request.url);
|
|
409
|
+
const forwarded = request.headers.get("x-forwarded-proto")?.split(",", 1)[0]?.trim().toLowerCase();
|
|
410
|
+
if (forwarded && `${forwarded}:` !== url.protocol) return void 0;
|
|
411
|
+
const target = new URL(`${base}${viteHubPageSessionPath}`, url);
|
|
412
|
+
target.searchParams.set("page", url.pathname);
|
|
413
|
+
const activation = url.searchParams.get(viteHubPageToolsQuery);
|
|
414
|
+
if (activation) target.searchParams.set("open", activation);
|
|
415
|
+
const headers = new Headers(request.headers);
|
|
416
|
+
for (const name of [
|
|
417
|
+
...pageConditions,
|
|
418
|
+
"origin",
|
|
419
|
+
"content-length",
|
|
420
|
+
"content-type",
|
|
421
|
+
"upgrade-insecure-requests",
|
|
422
|
+
"sec-fetch-user"
|
|
423
|
+
]) headers.delete(name);
|
|
424
|
+
headers.set("accept", "application/json");
|
|
425
|
+
headers.set("sec-fetch-site", "same-origin");
|
|
426
|
+
headers.set("sec-fetch-mode", "cors");
|
|
427
|
+
headers.set("sec-fetch-dest", "empty");
|
|
428
|
+
const inner = new Request(target, { headers });
|
|
429
|
+
const runtime = Reflect.get(request, "runtime");
|
|
430
|
+
if (runtime !== null && typeof runtime === "object") Reflect.set(inner, "runtime", Object.fromEntries(Object.entries(runtime).filter(([key]) => key !== "node")));
|
|
431
|
+
for (const field of [
|
|
432
|
+
"ip",
|
|
433
|
+
"waitUntil",
|
|
434
|
+
"cf"
|
|
435
|
+
]) {
|
|
436
|
+
const value = Reflect.get(request, field);
|
|
437
|
+
if (value === void 0) continue;
|
|
438
|
+
try {
|
|
439
|
+
Object.defineProperty(inner, field, {
|
|
440
|
+
configurable: true,
|
|
441
|
+
enumerable: true,
|
|
442
|
+
value
|
|
443
|
+
});
|
|
444
|
+
} catch {}
|
|
445
|
+
if (Reflect.get(inner, field) !== value) return void 0;
|
|
446
|
+
}
|
|
447
|
+
setApplicationRequestOrigin(inner, applicationRequestOrigin(request));
|
|
448
|
+
return inner;
|
|
449
|
+
}
|
|
450
|
+
function startHandoff(send, request, base) {
|
|
451
|
+
const inner = sessionRequestFor(request, base);
|
|
452
|
+
if (!inner) return void 0;
|
|
453
|
+
const pending = {};
|
|
454
|
+
const route = `${base}${viteHubPageSessionPath}`;
|
|
455
|
+
const page = new URL(request.url).pathname;
|
|
456
|
+
(async () => {
|
|
457
|
+
try {
|
|
458
|
+
const response = await send(inner);
|
|
459
|
+
if (!(response instanceof Response) || response.status !== 200 || response.headers.get(sessionCompleteHeader) !== "complete") return;
|
|
460
|
+
const session = readViteHubPageSession(await response.json());
|
|
461
|
+
const open = new URL(inner.url).searchParams.get("open");
|
|
462
|
+
if (session.tools.length > 0) pending.current = {
|
|
463
|
+
route,
|
|
464
|
+
page,
|
|
465
|
+
...open ? { open } : {},
|
|
466
|
+
session
|
|
467
|
+
};
|
|
468
|
+
} catch {}
|
|
469
|
+
})();
|
|
470
|
+
return pending;
|
|
327
471
|
}
|
|
328
|
-
/**
|
|
329
|
-
* Inserts the page tools bootstrap, `viteHubPageToolsInlineScript()`, before `</body>` of an HTML page for a request
|
|
330
|
-
* without the hint, with the response policy's nonce when present. The bootstrap is the same for every visitor, so the
|
|
331
|
-
* page keeps its cache policy. Body validators are removed because they describe the upstream HTML. A page that
|
|
332
|
-
* already has a page tools script, such as a prerendered page, gets no second one. Other responses return unchanged,
|
|
333
|
-
* including compressed HTML and pages without an explicit UTF-8 charset.
|
|
334
|
-
*/
|
|
335
472
|
function injectPageToolsBootstrap(response, base = "", policyHeaders) {
|
|
336
473
|
return transformPage(response, () => viteHubPageToolsInlineScript(base, scriptNonce(policyHeaders ?? response.headers)), false);
|
|
337
474
|
}
|
|
@@ -344,17 +481,10 @@ const pageConditions = ["if-none-match", "if-modified-since"];
|
|
|
344
481
|
function hasPageConditions(request) {
|
|
345
482
|
return pageConditions.some((name) => request.headers.has(name));
|
|
346
483
|
}
|
|
347
|
-
/** Whether a request is a page navigation with validators, which must reach the app without them. */
|
|
348
484
|
function revalidatesPage(request) {
|
|
349
485
|
if (request.method !== "GET" && request.method !== "HEAD") return false;
|
|
350
|
-
return request
|
|
351
|
-
const [type, ...parameters] = range.split(";").map((part) => part.trim());
|
|
352
|
-
if (type?.toLowerCase() !== "text/html") return false;
|
|
353
|
-
const quality = parameters.find((part) => /^q\s*=/i.test(part))?.split("=")[1]?.trim();
|
|
354
|
-
return quality === void 0 || Number(quality) > 0 && Number(quality) <= 1;
|
|
355
|
-
}) === true && hasPageConditions(request);
|
|
486
|
+
return acceptsHtml(request) && hasPageConditions(request);
|
|
356
487
|
}
|
|
357
|
-
/** The headers of the Node.js request that srvx keeps under `runtime.node.req`, when there is one. */
|
|
358
488
|
function nodeRequestHeaders(request) {
|
|
359
489
|
const runtime = Reflect.get(request, "runtime");
|
|
360
490
|
if (typeof runtime !== "object" || runtime === null) return void 0;
|
|
@@ -380,11 +510,10 @@ function withoutPageConditions(request) {
|
|
|
380
510
|
function htmlCharset(type) {
|
|
381
511
|
return /;\s*charset\s*=\s*"?([^";]*)/i.exec(type)?.[1]?.trim();
|
|
382
512
|
}
|
|
383
|
-
/** Whether a response is an HTML page that can get a page tools script. It reads the status and type, not the body. */
|
|
384
513
|
function isHtmlPage(response) {
|
|
385
514
|
return response.status === 200 && (response.headers.get("content-type") ?? "").toLowerCase().startsWith("text/html");
|
|
386
515
|
}
|
|
387
|
-
function transformPage(response, tag, personal) {
|
|
516
|
+
function transformPage(response, tag, personal, late) {
|
|
388
517
|
if (!isHtmlPage(response) || !response.body) return response;
|
|
389
518
|
const type = response.headers.get("content-type") ?? "";
|
|
390
519
|
const encoding = response.headers.get("content-encoding");
|
|
@@ -394,7 +523,7 @@ function transformPage(response, tag, personal) {
|
|
|
394
523
|
const headers = new Headers(response.headers);
|
|
395
524
|
for (const name of pageBodyHeaders) headers.delete(name);
|
|
396
525
|
if (personal) headers.set("cache-control", "private, no-store");
|
|
397
|
-
return new Response(response.body.pipeThrough(pageToolsHtmlTransform(tag())), {
|
|
526
|
+
return new Response(response.body.pipeThrough(pageToolsHtmlTransform(tag(), late)), {
|
|
398
527
|
headers,
|
|
399
528
|
status: response.status,
|
|
400
529
|
statusText: response.statusText
|
|
@@ -410,12 +539,25 @@ function transformPage(response, tag, personal) {
|
|
|
410
539
|
* It wraps `nitroApp.fetch`, the Web entry that every preset and the prerenderer call. The tag uses `options.base`.
|
|
411
540
|
* It binds each request to the app in Nitro's `request` hook too, since another wrapper of `fetch` may pass a copy of
|
|
412
541
|
* the request inward, such as the `security` policy of `vite-hub` on Node.js.
|
|
542
|
+
*
|
|
543
|
+
* With `sessionHandoff` enabled, it asks the session route beside the render for a navigation with credentials and puts a
|
|
544
|
+
* complete answer with at least one tool in the page: every visitor check and the account reader answered without
|
|
545
|
+
* throwing, so the tools and the account that it leaves out are the decision for this visitor. A page that a shared cache may
|
|
546
|
+
* store gets none: its headers say so (`public`, `s-maxage`, `Surrogate-Control`, any `*CDN-Cache-Control`), or the
|
|
547
|
+
* route rules that Nitro set on `request.context` have `isr`, `swr`, `cache` or `prerender`, which some presets turn
|
|
548
|
+
* into CDN headers after this point. A request without Nitro's `context.nitro`, such as a copy that another wrapper
|
|
549
|
+
* passed inward, has unknown rules and gets none. The server's request keeps the credentials and the host's request
|
|
550
|
+
* context (`runtime` without the Node.js request, `ip`, `waitUntil`, Cloudflare's `cf`). An app must not opt in if a
|
|
551
|
+
* browser-only input can change the session, or if a CDN can override the private cache policy. A proxy scheme that
|
|
552
|
+
* differs from the URL is left to the loader, since a `trustProxy`
|
|
553
|
+
* hook changes the URL of a real Node.js request and not of a copy.
|
|
413
554
|
*/
|
|
414
555
|
function installViteHubPageTools(nitroApp, options = {}) {
|
|
415
556
|
if (nitroApp === null || typeof nitroApp !== "object") return;
|
|
416
557
|
const { installed, bases } = state();
|
|
417
558
|
if (options.base !== void 0) bases.set(nitroApp, viteHubBasePath(options.base));
|
|
418
559
|
if (options.origins !== void 0) (state().origins ??= /* @__PURE__ */ new WeakMap()).set(nitroApp, options.origins);
|
|
560
|
+
if (options.sessionHandoff === true) (state().sessionHandoffs ??= /* @__PURE__ */ new WeakSet()).add(nitroApp);
|
|
419
561
|
if (installed.has(nitroApp)) return;
|
|
420
562
|
installed.add(nitroApp);
|
|
421
563
|
const hooks = Reflect.get(nitroApp, "hooks");
|
|
@@ -428,23 +570,27 @@ function installViteHubPageTools(nitroApp, options = {}) {
|
|
|
428
570
|
Reflect.set(nitroApp, "fetch", async (request, ...rest) => {
|
|
429
571
|
const base = state().bases.get(nitroApp) ?? "";
|
|
430
572
|
const conditional = request instanceof Request && hasPageConditions(request);
|
|
431
|
-
const
|
|
573
|
+
const handing = state().sessionHandoffs?.has(nitroApp) === true && request instanceof Request && mayHandOffSession(request);
|
|
574
|
+
const early = conditional || handing ? pageAddition(nitroApp, request, base) : void 0;
|
|
575
|
+
const pending = handing && early === "loader" ? startHandoff(async (inner) => {
|
|
576
|
+
state().apps.set(inner, nitroApp);
|
|
577
|
+
return await Reflect.apply(fetch, nitroApp, [inner]);
|
|
578
|
+
}, request, base) : void 0;
|
|
432
579
|
if (early && revalidatesPage(request)) request = withoutPageConditions(request);
|
|
433
580
|
if (request instanceof Request) state().apps.set(request, nitroApp);
|
|
434
581
|
const response = await Reflect.apply(fetch, nitroApp, [request, ...rest]);
|
|
435
582
|
if (!(response instanceof Response) || !(request instanceof Request) || !isHtmlPage(response)) return response;
|
|
436
|
-
const addition = conditional ? early : pageAddition(nitroApp, request, base);
|
|
437
|
-
if (addition === "loader")
|
|
583
|
+
const addition = conditional || handing ? early : pageAddition(nitroApp, request, base);
|
|
584
|
+
if (addition === "loader") {
|
|
585
|
+
const handoff = pending && !sharedCacheMayStore(request, response) ? pending : void 0;
|
|
586
|
+
return transformPage(response, () => loaderTag(base, scriptNonce(response.headers)), true, handoff && ((nonce) => handoff.current ? handoffMarkup(handoff.current, nonce) : ""));
|
|
587
|
+
}
|
|
438
588
|
return addition === "bootstrap" ? injectPageToolsBootstrap(response, base) : response;
|
|
439
589
|
});
|
|
440
590
|
return;
|
|
441
591
|
}
|
|
442
592
|
}
|
|
443
593
|
// src/runtime/session.ts
|
|
444
|
-
/**
|
|
445
|
-
* The person that Site access in the ViteHub Console signed in to the app, with their roles in `role`, as
|
|
446
|
-
* `commentsRoleAllows()` reads them. A Console member has `comments-*` roles, a guest the roles of the invite.
|
|
447
|
-
*/
|
|
448
594
|
async function siteUser(event) {
|
|
449
595
|
const read = viteHubSiteVisitorReader();
|
|
450
596
|
if (!read) return null;
|
|
@@ -495,7 +641,7 @@ async function resolveCommentsPage(comments, event, request, path) {
|
|
|
495
641
|
} };
|
|
496
642
|
getStandardContext(event);
|
|
497
643
|
const mapped = await comments.options.page({
|
|
498
|
-
url: new URL(id, applicationRequestOrigin(request)),
|
|
644
|
+
url: new URL(id, applicationRequestOrigin(clientRequest(request))),
|
|
499
645
|
event
|
|
500
646
|
});
|
|
501
647
|
if (!mapped) return { subject: {
|
|
@@ -510,4 +656,4 @@ async function resolveCommentsPage(comments, event, request, path) {
|
|
|
510
656
|
...mapped.revision === void 0 ? {} : { revision: mapped.revision }
|
|
511
657
|
};
|
|
512
658
|
}
|
|
513
|
-
export { registerViteHubPageTool as a, installViteHubSiteVisitor as i, resolveCommentsPage as n, viteHubPageSessionHandler as o, installViteHubPageTools as r, resolveCommentsIdentity as t };
|
|
659
|
+
export { registerViteHubPageTool as a, installViteHubSiteVisitor as i, resolveCommentsPage as n, viteHubPageSessionHandler as o, installViteHubPageTools as r, applicationRequestOrigin as s, resolveCommentsIdentity as t };
|
|
@@ -1,6 +1,5 @@
|
|
|
1
|
-
import "./index-
|
|
2
|
-
import {
|
|
3
|
-
import { f as CommentsRequestEvent } from "./types-l6GOb_yc.js";
|
|
1
|
+
import "./index-CbXek64X.js";
|
|
2
|
+
import { j as CommentsUser, s as CommentsRequestEvent } from "./types-VSVs4jIw.js";
|
|
4
3
|
interface CommentsSessionOptions {
|
|
5
4
|
/** Reads the ViteHub Auth user only when no custom `identify` is configured. */
|
|
6
5
|
session?: (event: CommentsRequestEvent) => Promise<CommentsUser | null | undefined>;
|
|
@@ -10,6 +10,4 @@ const commentsTableNames = {
|
|
|
10
10
|
vitehubCommentCounters: "vitehub_comment_counters",
|
|
11
11
|
vitehubCommentForge: "vitehub_comment_forge"
|
|
12
12
|
};
|
|
13
|
-
|
|
14
|
-
const commentSendsTableNames = { commentSends: "vitehub_comment_sends" };
|
|
15
|
-
export { commentsTableNames as n, commentSendsTableNames as t };
|
|
13
|
+
export { commentsTableNames as t };
|
package/dist/testing.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { D as CommentUser, T as CommentThread, k as CommentsTransport, w as CommentSubject } from "./types-
|
|
1
|
+
import { D as CommentUser, T as CommentThread, k as CommentsTransport, w as CommentSubject } from "./types-BmzTyGt-.js";
|
|
2
2
|
export interface MemoryTransportOptions {
|
|
3
3
|
/** The signed-in user. Every call acts as this user. */
|
|
4
4
|
user: CommentUser;
|
package/dist/testing.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { t as replyMessageId } from "./reply-id-Cm9FGOBs.js";
|
|
2
|
-
import { t as commentsErrorDiagnostics } from "./errors-
|
|
2
|
+
import { t as commentsErrorDiagnostics } from "./errors-DeSEHzRf.js";
|
|
3
3
|
// src/operations-core/testing.ts
|
|
4
4
|
function checkOutboxAccount(input, user) {
|
|
5
5
|
if (input.outbox && input.outbox.account !== user.id) throw Object.assign(commentsErrorDiagnostics.COMMENTS_OUTBOX_ACCOUNT_CHANGED(), { status: 401 });
|
|
@@ -7,7 +7,6 @@ function checkOutboxAccount(input, user) {
|
|
|
7
7
|
function copy(value) {
|
|
8
8
|
return JSON.parse(JSON.stringify(value));
|
|
9
9
|
}
|
|
10
|
-
/** The attachment keys of a message: the keys that it names, then one made-up key for each file that it brings. */
|
|
11
10
|
function attachmentsOf(input) {
|
|
12
11
|
const files = (input.files ?? []).map((file) => `memory/${crypto.randomUUID()}/${file instanceof File ? file.name : "file"}`);
|
|
13
12
|
return [...input.attachments ?? [], ...files];
|
|
@@ -24,7 +24,6 @@ function getActiveCloudflareBinding(name) {
|
|
|
24
24
|
return env && Object.hasOwn(env, name) ? env[name] : void 0;
|
|
25
25
|
}
|
|
26
26
|
// src/forge/tokens.ts
|
|
27
|
-
/** How long the GitHub token of a person's last request stays usable for the pull request sync that it started. */
|
|
28
27
|
const tokenLifetime = 6e5;
|
|
29
28
|
const tokens = /* @__PURE__ */ new Map();
|
|
30
29
|
/**
|
|
@@ -16,6 +16,10 @@ interface CommentActor {
|
|
|
16
16
|
name?: string;
|
|
17
17
|
/** The agent's logo. */
|
|
18
18
|
image?: string;
|
|
19
|
+
/** The client the agent signed in through, such as `Executor` for Claude Code that replies through Executor. */
|
|
20
|
+
via?: string;
|
|
21
|
+
/** A link to the agent's session. Interfaces link it only when it is `http:` or `https:`. */
|
|
22
|
+
url?: string;
|
|
19
23
|
}
|
|
20
24
|
type CommentStatus = "open" | "resolved";
|
|
21
25
|
/** What a thread is about. `page` takes an app path as `id`. Other kinds, such as `content`, name their own ids. */
|