@vite-hub/comments 0.4.1 → 0.5.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.
Files changed (87) hide show
  1. package/README.md +23 -7
  2. package/dist/anchor.d.ts +3 -5
  3. package/dist/anchor.js +1 -2
  4. package/dist/{client-diagnostics-Bubm7Shd.js → client-diagnostics-CvfTW5d4.js} +1 -2
  5. package/dist/{client-files-CJZl5Kc4.js → client-files-lC6X7XyS.js} +1 -2
  6. package/dist/client.d.ts +430 -24
  7. package/dist/client.js +413 -20
  8. package/dist/{console-h4KlhIik.d.ts → console-CK2F53QP.d.ts} +2 -4
  9. package/dist/{context-BqIsmYP1.js → context-DbkBjITZ.js} +1 -2
  10. package/dist/database/postgres.d.ts +1 -3
  11. package/dist/database/postgres.js +1 -2
  12. package/dist/{migrate-Bpw3xL5e.js → database-BkPoOdZr.js} +116 -59
  13. package/dist/database-CPua6Q6_.d.ts +573 -0
  14. package/dist/{database-CA1aHKN7.d.ts → database-DUs3c2al.d.ts} +625 -73
  15. package/dist/database.d.ts +4 -5
  16. package/dist/database.js +1 -2
  17. package/dist/{define-CX_Yr_hz.js → define-9uMM3Ewc.js} +2 -3
  18. package/dist/{define-CHTWfHPo.d.ts → define-B1jLSPe9.d.ts} +8 -6
  19. package/dist/{errors-4gelGVmK.js → errors-C0VwRHiy.js} +25 -2
  20. package/dist/{errors-BHsVXlpd.js → errors-DFNiJg67.js} +26 -3
  21. package/dist/{fold-name-B7Zb3-MF.js → fold-name-g-xg0mQk.js} +1 -2
  22. package/dist/hosted/hosted-comments/client-B3dlmmQd.js +4 -0
  23. package/dist/{overlay/dist-BoHMOFax.js → hosted/hosted-comments/dist-DyVmH21U.js} +1 -1
  24. package/dist/hosted/hosted-comments/frame.js +1 -0
  25. package/dist/hosted/hosted-comments/overlay-4-mWX4Uz.js +170 -0
  26. package/dist/hosted/hosted-comments/protocol-BHvtQKte.js +1 -0
  27. package/dist/hosted/hosted-comments/rest-transport-D-9_pNqZ.js +1 -0
  28. package/dist/hosted/hosted-comments/tools-CdwnUCOr.js +126 -0
  29. package/dist/hosted/hosted-comments.js +9 -0
  30. package/dist/{identity-CBOzgxSf.js → identity-CT7-UGmS.js} +1 -2
  31. package/dist/{index-iPGlSAgj.d.ts → index-BEnHTj2Z.d.ts} +109 -15
  32. package/dist/index.d.ts +6 -7
  33. package/dist/index.js +23 -10
  34. package/dist/{install-96NXWnrw.d.ts → install-B-FQpi47.d.ts} +24 -7
  35. package/dist/{install-jRKmuLHK.js → install-BUXxryut.js} +950 -55
  36. package/dist/{installed-g6nDr5ac.js → installed-C9SkldMi.js} +8 -8
  37. package/dist/{invariant-D8_xBqmZ.js → invariant-CmdvZ3vp.js} +1 -2
  38. package/dist/{migrate-B0k_0swk.d.ts → migrate-XjFeQppf.d.ts} +2 -2
  39. package/dist/{object-Da1zyPCR.js → object-CAK6UYR5.js} +1 -2
  40. package/dist/{operations-7ycAhDCw.d.ts → operations-8hqTi0DH.d.ts} +8 -4
  41. package/dist/{operations-9tskoLsk.js → operations-CKC_lMG_.js} +309 -229
  42. package/dist/{operations-D93EV10O.d.ts → operations-Cic9A9e_.d.ts} +9 -7
  43. package/dist/operations.d.ts +2 -2
  44. package/dist/operations.js +2 -2
  45. package/dist/overlay/{client-lZesR40x.js → client-CerbVjTz.js} +3 -3
  46. package/dist/overlay/dist-DyVmH21U.js +14 -0
  47. package/dist/overlay/overlay.js +36 -40
  48. package/dist/page/loader.js +45 -52
  49. package/dist/page-DE71P_gQ.d.ts +11 -0
  50. package/dist/{page-tools-shared-NHUjKI8E.js → page-tools-shared-fvmJQCrP.js} +8 -5
  51. package/dist/{page-DRz_sDY4.js → page-xzgZ6DGm.js} +2 -3
  52. package/dist/{path--zk6PEMz.js → path-8yqMd8zR.js} +0 -1
  53. package/dist/{plugin-BNFd1zGz.js → plugin-B2hETRii.js} +16 -13
  54. package/dist/realtime.d.ts +3 -5
  55. package/dist/realtime.js +4 -5
  56. package/dist/{reply-id-P_bSuEng.js → reply-id-Cm9FGOBs.js} +1 -2
  57. package/dist/request-log-DllKQXj7.js +104 -0
  58. package/dist/request-origin-YPzfE2eh.js +48 -0
  59. package/dist/{rpc-BQqYx8kb.js → rpc-BKY7XRlR.js} +5 -7
  60. package/dist/{rpc-BZ1QNkCC.d.ts → rpc-D-eqtyfh.d.ts} +1 -3
  61. package/dist/rpc.d.ts +1 -1
  62. package/dist/rpc.js +1 -2
  63. package/dist/runtime/auth.d.ts +3 -5
  64. package/dist/runtime/auth.js +2 -3
  65. package/dist/runtime/console.d.ts +2 -4
  66. package/dist/runtime/console.js +4 -5
  67. package/dist/runtime/index.d.ts +12 -27
  68. package/dist/runtime/index.js +160 -31
  69. package/dist/{server-CqyzrqTI.js → server-BGbD7H5s.js} +2 -3
  70. package/dist/server.d.ts +6 -7
  71. package/dist/server.js +6 -6
  72. package/dist/service-CPiWPoiY.d.ts +69 -0
  73. package/dist/{service-C8ZgFWvy.js → service-DDD4Ubxd.js} +44 -18
  74. package/dist/{session-ByjMyTak.js → session-BGN6Vlm6.js} +31 -37
  75. package/dist/{session-CKfW6DGE.d.ts → session-CTh9nisq.d.ts} +3 -5
  76. package/dist/{service-wC9kx9EX.d.ts → store-DvNTDNgn.d.ts} +3 -73
  77. package/dist/{table-names-DfiKUlOV.js → table-names-BIHjuEFK.js} +4 -3
  78. package/dist/testing.d.ts +2 -4
  79. package/dist/testing.js +4 -5
  80. package/dist/{tokens-DSbwkVSy.js → tokens-Bx4lZ0yt.js} +3 -6
  81. package/dist/{types-C7LzhgRb.d.ts → types-BX3vH18p.d.ts} +1 -3
  82. package/dist/{types-C1qzObs2.d.ts → types-l6GOb_yc.d.ts} +79 -6
  83. package/dist/vite.d.ts +22 -21
  84. package/dist/vite.js +161 -104
  85. package/package.json +19 -19
  86. package/dist/errors-BEChnUo7.d.ts +0 -197
  87. package/dist/page-CWwnmF3K.d.ts +0 -22
package/dist/vite.js CHANGED
@@ -1,10 +1,10 @@
1
- import { t as commentsErrorDiagnostics } from "./errors-BHsVXlpd.js";
2
- import { a as mountedCommentsRoute, i as commentsRoute, r as commentsRealtimeDefinition } from "./page-DRz_sDY4.js";
3
- import { n as isRecordOrFunction } from "./object-Da1zyPCR.js";
4
- import { t as invariant } from "./invariant-D8_xBqmZ.js";
5
- import { c as validateCommentsDefinition } from "./define-CX_Yr_hz.js";
6
- import { a as viteHubPageToolsCookie, d as viteHubPageToolsQuery, i as viteHubPageToolsAssets, n as viteHubBasePath, r as viteHubPageSessionPath, s as viteHubPageToolsInlineScript } from "./page-tools-shared-NHUjKI8E.js";
7
- import { t as commentsTableNames } from "./table-names-DfiKUlOV.js";
1
+ import { t as invariant } from "./invariant-CmdvZ3vp.js";
2
+ import { c as validateCommentsDefinition } from "./define-9uMM3Ewc.js";
3
+ import { t as commentsErrorDiagnostics } from "./errors-DFNiJg67.js";
4
+ import { a as viteHubPageToolsCookie, d as viteHubPageToolsQuery, i as viteHubPageToolsAssets, n as viteHubBasePath, r as viteHubPageSessionPath, s as viteHubPageToolsInlineScript } from "./page-tools-shared-fvmJQCrP.js";
5
+ import { n as isRecordOrFunction } from "./object-CAK6UYR5.js";
6
+ import { a as mountedCommentsRoute, i as commentsRoute, r as commentsRealtimeDefinition } from "./page-xzgZ6DGm.js";
7
+ import { n as commentsTableNames, t as commentSendsTableNames } from "./table-names-BIHjuEFK.js";
8
8
  import { formatDiagnostic } from "nostics";
9
9
  import { existsSync, mkdirSync, statSync, writeFileSync } from "node:fs";
10
10
  import { tmpdir } from "node:os";
@@ -16,7 +16,7 @@ import { nitro } from "nitro/vite";
16
16
  import { parseDatabaseLocation } from "@vite-hub/database/config";
17
17
  import { githubRepository, readForgeBuild } from "@vite-hub/forge/build/node";
18
18
  import { parseJSONC, parseTOML } from "confbox";
19
- //#region ../../node_modules/.pnpm/pathe@2.0.3/node_modules/pathe/dist/shared/pathe.M-eThtNZ.mjs
19
+ // ../../node_modules/.pnpm/pathe@2.0.3/node_modules/pathe/dist/shared/pathe.M-eThtNZ.mjs
20
20
  const _DRIVE_LETTER_START_RE = /^[A-Za-z]:\//;
21
21
  function normalizeWindowsPath(input = "") {
22
22
  if (!input) return input;
@@ -113,16 +113,14 @@ const dirname$1 = function(p) {
113
113
  if (segments.length === 1 && _DRIVE_LETTER_RE.test(segments[0])) segments[0] += "/";
114
114
  return segments.join("/") || (isAbsolute(p) ? "/" : ".");
115
115
  };
116
- //#endregion
117
- //#region ../internal/src/inspect.ts
116
+ // ../internal/src/inspect.ts
118
117
  function relativeDefinitionFile(projectRoot, file) {
119
118
  return relative$1(projectRoot, file).replaceAll("\\", "/");
120
119
  }
121
120
  const secretKeyPattern = /secret|token|passw(?:or)?d|credential|api[-_\s]?key|private[-_\s]?key|authorization|cookie|signature|dsn|connection[-_\s]?string/i;
122
121
  new RegExp(String.raw`\b([\w-]*authorization[\w-]*["']?\s*[:=]\s*)(?!\[redacted\](?=$|[\s,;}&]))(?:"(?:\\[^\r\n]|[^"\\\r\n])*"|'(?:\\[^\r\n]|[^'\\\r\n])*'|[^\r\n]+?(?=\s*(?:[,;])?\s*(?:${secretKeyPattern.source})[\w-]*\s*[:=]|\s+rejected\b|$))`, "gi");
123
122
  new RegExp(String.raw`\b([\w-]*(?:${secretKeyPattern.source})[\w-]*["']?\s*[:=]\s*)(?!\[redacted\](?=$|[\s,;}&]))(?:"(?:\\[^\r\n]|[^"\\\r\n])*"|'(?:\\[^\r\n]|[^'\\\r\n])*'|[^\s,;&#&]+)`, "gi");
124
- //#endregion
125
- //#region ../internal/src/build/vite.ts
123
+ // ../internal/src/build/vite.ts
126
124
  const projectRootDirectoryMarkers = [
127
125
  ["server", "agents"],
128
126
  ["server", "channels"],
@@ -184,7 +182,7 @@ function hasProjectRootDirectoryMarker(root) {
184
182
  for (const marker of projectRootDirectoryMarkers) try {
185
183
  if (statSync(resolve(root, ...marker)).isDirectory()) return true;
186
184
  } catch (error) {
187
- if (error.code !== "ENOENT") throw error;
185
+ if (!isMissingProjectMarker(error)) throw error;
188
186
  }
189
187
  return false;
190
188
  }
@@ -198,13 +196,16 @@ function hasProjectRootFileMarker(root, markers) {
198
196
  try {
199
197
  if (statSync(resolve(root, ...path)).isFile()) return true;
200
198
  } catch (error) {
201
- if (error.code !== "ENOENT") throw error;
199
+ if (!isMissingProjectMarker(error)) throw error;
202
200
  }
203
201
  }
204
202
  return false;
205
203
  }
206
- //#endregion
207
- //#region ../internal/src/build/paths.ts
204
+ function isMissingProjectMarker(error) {
205
+ const code = error.code;
206
+ return code === "ENOENT" || code === "ENOTDIR";
207
+ }
208
+ // ../internal/src/build/paths.ts
208
209
  function resolveRuntimeModule(packageDir, modulePath) {
209
210
  const distFile = resolve$1(packageDir, "dist", `${modulePath}.js`);
210
211
  return existsSync(distFile) ? distFile : resolve$1(packageDir, "src", `${modulePath}.ts`);
@@ -231,8 +232,7 @@ function findPackageDir(file) {
231
232
  function ownModule(importMetaUrl, modulePath) {
232
233
  return resolveRuntimeModule(findPackageDir(fileURLToPath(importMetaUrl)), modulePath);
233
234
  }
234
- //#endregion
235
- //#region src/entry.ts
235
+ // src/entry.ts
236
236
  const extensions = [
237
237
  ".ts",
238
238
  ".mts",
@@ -253,10 +253,45 @@ function findContentEntry(projectRoot, serverDirs) {
253
253
  if (existsSync(file)) return file;
254
254
  }
255
255
  }
256
- //#endregion
257
- //#region ../internal/src/build/page-tools.ts
256
+ Object.freeze({ vitehubAuthAccess: "handler" });
257
+ /**
258
+ * The route meta of a generated handler that checks access on every request, even when the app adds no rule: a required
259
+ * `authorize` policy, an explicit `access` rule, a required access token, or a signature. Auth access routes still apply
260
+ * to it, so an app rule stays in force. `checksOwnAccess(event)` of `vite-hub/auth` reads it, so app middleware can skip
261
+ * the route. A route that can run without a check, such as a browser error sink, an optional `authorize`, or a webhook
262
+ * with `secret: false`, must not use it.
263
+ */
264
+ const ownAccessRouteMeta = Object.freeze({ vitehubOwnAccess: true });
265
+ function cloneArray(value) {
266
+ return Array.isArray(value) ? [...value] : [];
267
+ }
268
+ function sameHandler(left, right) {
269
+ return left.handler === right.handler && left.route === right.route && left.method === right.method && left.middleware === right.middleware;
270
+ }
271
+ /** Create a Nitro 3 configuration builder for generated ViteHub output. */
272
+ function createNitroServerKit(value = {}) {
273
+ const config = isRecordOrFunction(value) ? { ...value } : {};
274
+ const handlers = cloneArray(config.handlers);
275
+ const plugins = cloneArray(config.plugins);
276
+ config.handlers = handlers;
277
+ config.plugins = plugins;
278
+ return {
279
+ config,
280
+ addHandler(handler, position = "end") {
281
+ if (handlers.some((candidate) => isRecordOrFunction(candidate) && sameHandler(candidate, handler))) return;
282
+ if (position === "start") handlers.unshift({ ...handler });
283
+ else handlers.push({ ...handler });
284
+ },
285
+ addPlugin(plugin, position = "end") {
286
+ if (plugins.includes(plugin)) return;
287
+ if (position === "start") plugins.unshift(plugin);
288
+ else plugins.push(plugin);
289
+ }
290
+ };
291
+ }
292
+ // ../internal/src/build/page-tools.ts
258
293
  /**
259
- * Adds the session route `GET <mount>/_vitehub/page/session` and the loader script at
294
+ * Adds the session route `GET <mount>/_vitehub/page/tools` and the loader script at
260
295
  * `<mount>/_vitehub/page/assets/loader.js` to a Nitro configuration. Each owner package of a page tool calls it from its
261
296
  * Vite plugin, so the routes exist without the Console. The first owner wins: a later call keeps the route and the asset
262
297
  * that are already there, because the page tools registry is shared by every copy of this package.
@@ -267,6 +302,7 @@ function addViteHubPageToolRoutes(kit, options) {
267
302
  const assetsBase = `${mount}${viteHubPageToolsAssets}`;
268
303
  if (!(Array.isArray(kit.config.handlers) ? kit.config.handlers : []).some((handler) => Object(handler) === handler && Reflect.get(Object(handler), "route") === route)) kit.addHandler({
269
304
  handler: options.handler,
305
+ meta: { ...ownAccessRouteMeta },
270
306
  route
271
307
  });
272
308
  const assets = Array.isArray(kit.config.publicAssets) ? [...kit.config.publicAssets] : [];
@@ -316,8 +352,7 @@ function viteHubPageToolsIndexHtml(html, base) {
316
352
  const index = html.search(/<\/body\s*>/i);
317
353
  return index === -1 ? `${html}${script}` : `${html.slice(0, index)}${script}${html.slice(index)}`;
318
354
  }
319
- //#endregion
320
- //#region ../internal/src/build/ast-walk.ts
355
+ // ../internal/src/build/ast-walk.ts
321
356
  /** The oxc parser grammar for a file, from its extension. Defaults to TypeScript. */
322
357
  function moduleLanguage(file) {
323
358
  if (/\.(?:c|m)?tsx$/i.test(file)) return "tsx";
@@ -325,8 +360,7 @@ function moduleLanguage(file) {
325
360
  if (/\.(?:c|m)?js$/i.test(file)) return "js";
326
361
  return "ts";
327
362
  }
328
- //#endregion
329
- //#region ../internal/src/build/scan-module.ts
363
+ // ../internal/src/build/scan-module.ts
330
364
  /**
331
365
  * Reads facts from JavaScript and TypeScript modules at build and dev time. The scanner parses each module once with
332
366
  * the oxc parser that Vite ships through Rolldown, and never runs it. Values that are not static literals read as
@@ -446,8 +480,7 @@ function staticValue(node) {
446
480
  default: return dynamic;
447
481
  }
448
482
  }
449
- //#endregion
450
- //#region ../internal/src/hints.ts
483
+ // ../internal/src/hints.ts
451
484
  /**
452
485
  * The file that lists the hints of the last build or dev server, relative to the project root. A hint is a warning
453
486
  * about something that works now and fails later, such as counts that stay in one server's memory. Agents and CI read
@@ -525,8 +558,7 @@ function startViteHubHints(config, owner = config) {
525
558
  started.add(owner);
526
559
  write(startRun(config));
527
560
  }
528
- //#endregion
529
- //#region ../internal/src/build/included-nitro-registry.ts
561
+ // ../internal/src/build/included-nitro-registry.ts
530
562
  const includedKey = Symbol.for("vitehub.included-nitro");
531
563
  const scope = globalThis;
532
564
  const includedNitroPlugins = scope[includedKey] ??= /* @__PURE__ */ new WeakSet();
@@ -541,8 +573,7 @@ function markIncludedNitroPlugin(plugin) {
541
573
  function isIncludedNitroPlugin(plugin) {
542
574
  return includedNitroPlugins.has(plugin);
543
575
  }
544
- //#endregion
545
- //#region ../internal/src/build/included-nitro.ts
576
+ // ../internal/src/build/included-nitro.ts
546
577
  function flattenPlugins(option) {
547
578
  if (Array.isArray(option)) return option.flatMap(flattenPlugins);
548
579
  return option && typeof option === "object" && "name" in option ? [option] : [];
@@ -569,37 +600,7 @@ function includedNitro(options = {}) {
569
600
  }
570
601
  return plugins;
571
602
  }
572
- //#endregion
573
- //#region ../internal/src/nitro-kit.ts
574
- function cloneArray(value) {
575
- return Array.isArray(value) ? [...value] : [];
576
- }
577
- function sameHandler(left, right) {
578
- return left.handler === right.handler && left.route === right.route && left.method === right.method && left.middleware === right.middleware;
579
- }
580
- /** Create a Nitro 3 configuration builder for generated ViteHub output. */
581
- function createNitroServerKit(value = {}) {
582
- const config = isRecordOrFunction(value) ? { ...value } : {};
583
- const handlers = cloneArray(config.handlers);
584
- const plugins = cloneArray(config.plugins);
585
- config.handlers = handlers;
586
- config.plugins = plugins;
587
- return {
588
- config,
589
- addHandler(handler, position = "end") {
590
- if (handlers.some((candidate) => isRecordOrFunction(candidate) && sameHandler(candidate, handler))) return;
591
- if (position === "start") handlers.unshift({ ...handler });
592
- else handlers.push({ ...handler });
593
- },
594
- addPlugin(plugin, position = "end") {
595
- if (plugins.includes(plugin)) return;
596
- if (position === "start") plugins.unshift(plugin);
597
- else plugins.push(plugin);
598
- }
599
- };
600
- }
601
- //#endregion
602
- //#region src/deployment-env.ts
603
+ // src/deployment-env.ts
603
604
  const owners = ["comments"];
604
605
  const githubLoginNames = {
605
606
  clientId: "VITEHUB_GITHUB_CLIENT_ID",
@@ -674,8 +675,7 @@ function commentsDeploymentEnv(options, context) {
674
675
  ...options.standalone ? standaloneDatabaseEntries(options.standalone.database || void 0, context.host) : []
675
676
  ];
676
677
  }
677
- //#endregion
678
- //#region src/console.ts
678
+ // src/console.ts
679
679
  /**
680
680
  * Console section for Comments: every thread with its first comment, page, author, replies, and status, open threads
681
681
  * first. People reply and resolve on the page itself, where the context is; each record links there. The
@@ -723,8 +723,7 @@ const commentsConsoleSection = {
723
723
  notice: "People comment, reply, and resolve on the site's pages. Open threads come first. Server code reads the same threads with `comments.list()`."
724
724
  }
725
725
  };
726
- //#endregion
727
- //#region src/live-vite.ts
726
+ // src/live-vite.ts
728
727
  const defaultImports = {
729
728
  runtime: "@vite-hub/comments/runtime",
730
729
  realtime: "@vite-hub/comments/realtime",
@@ -734,57 +733,94 @@ const defaultImports = {
734
733
  contentClient: "@vite-hub/content/client",
735
734
  connect: "@vite-hub/comments/runtime/connect",
736
735
  blob: "@vite-hub/blob",
737
- rateLimit: "@vite-hub/rate-limit"
736
+ rateLimit: "@vite-hub/rate-limit",
737
+ webhooks: "@vite-hub/webhooks"
738
738
  };
739
- /**
740
- * The Database name in `defineComments({ database: "name" })`, read without running the file. Undefined means the
741
- * default or only Database.
742
- */
743
- async function readCommentsDatabase(file) {
739
+ function literalProperties(options) {
740
+ return objectProperties(options).flatMap((property) => {
741
+ if (property.node.type !== "SpreadElement") return [property];
742
+ const spread = unwrapExpression(property.node.argument);
743
+ return spread.type === "ObjectExpression" ? literalProperties(spread) : [property];
744
+ });
745
+ }
746
+ async function readDefinitionProperties(file) {
744
747
  const module = scanModule(await readFile(file, "utf8").catch(() => ""), file);
745
748
  if (module.errors.length) return;
746
749
  const bindings = /* @__PURE__ */ new Set();
747
750
  const factories = /* @__PURE__ */ new Set(["defineComments"]);
748
751
  let defaultCall;
752
+ let hasNamedExport = false;
749
753
  for (const statement of module.program.body) {
750
754
  if (statement.type === "ImportDeclaration" && statement.importKind !== "type" && ["vite-hub/comments", "@vite-hub/comments"].includes(statement.source.value)) for (const specifier of statement.specifiers) {
751
755
  if (specifier.type !== "ImportSpecifier" || specifier.importKind === "type") continue;
752
756
  if ((specifier.imported.type === "Identifier" ? specifier.imported.name : specifier.imported.value) === "defineComments") factories.add(specifier.local.name);
753
757
  }
754
758
  if (statement.type === "ExportDefaultDeclaration") {
755
- const value = unwrapExpression(statement.declaration);
756
- if (value.type === "Identifier") bindings.add(value.name);
757
- else if (value.type === "CallExpression" && value.callee.type === "Identifier") defaultCall = value;
759
+ defaultCall = unwrapExpression(statement.declaration);
758
760
  continue;
759
761
  }
760
- if (statement.type !== "ExportNamedDeclaration" || statement.source) continue;
762
+ if (statement.type !== "ExportNamedDeclaration" || statement.exportKind === "type") continue;
761
763
  if (statement.declaration?.type === "VariableDeclaration") {
762
- for (const declaration of statement.declaration.declarations) if (declaration.id.type === "Identifier" && declaration.id.name === "comments") bindings.add(declaration.id.name);
764
+ for (const declaration of statement.declaration.declarations) if (declaration.id.type === "Identifier" && declaration.id.name === "comments") {
765
+ hasNamedExport = true;
766
+ bindings.add(declaration.id.name);
767
+ }
768
+ }
769
+ for (const specifier of statement.specifiers) if ((specifier.exported.type === "Identifier" ? specifier.exported.name : specifier.exported.value) === "comments" && specifier.exportKind !== "type") {
770
+ hasNamedExport = true;
771
+ if (!statement.source && specifier.local.type === "Identifier") bindings.add(specifier.local.name);
763
772
  }
764
- for (const specifier of statement.specifiers) if ((specifier.exported.type === "Identifier" ? specifier.exported.name : specifier.exported.value) === "comments" && specifier.local.type === "Identifier") bindings.add(specifier.local.name);
765
773
  }
766
- const databaseOf = (call) => {
774
+ const propertiesOf = (call) => {
767
775
  if (call.type !== "CallExpression" || call.callee.type !== "Identifier" || !factories.has(call.callee.name)) return;
776
+ if (call.arguments.length === 0) return [];
768
777
  const options = argumentExpression(call.arguments[0]);
769
- if (options?.type !== "ObjectExpression") return;
770
- const properties = objectProperties(options);
771
- const last = properties.findLastIndex((property) => property.key === "database");
772
- if (last === -1) return;
773
- const property = properties[last];
774
- const name = property.node.type === "Property" && property.node.kind === "init" && !property.node.method && property.value ? staticValue(property.value) : null;
775
- if (properties.slice(last + 1).some((later) => later.key === void 0) || name !== void 0 && typeof name !== "string") throw commentsErrorDiagnostics.COMMENTS_B0004({ file });
776
- return name;
778
+ return options?.type === "ObjectExpression" ? literalProperties(options) : void 0;
777
779
  };
778
- if (defaultCall) return databaseOf(defaultCall);
780
+ if (!hasNamedExport && defaultCall) {
781
+ if (defaultCall.type !== "Identifier") return propertiesOf(defaultCall);
782
+ bindings.add(defaultCall.name);
783
+ }
779
784
  for (const statement of module.program.body) {
780
785
  const declaration = statement.type === "ExportNamedDeclaration" ? statement.declaration : statement;
781
786
  if (declaration?.type !== "VariableDeclaration") continue;
782
787
  for (const binding of declaration.declarations) {
783
788
  if (binding.id.type !== "Identifier" || !bindings.has(binding.id.name) || !binding.init) continue;
784
- return databaseOf(unwrapExpression(binding.init));
789
+ return propertiesOf(unwrapExpression(binding.init));
785
790
  }
786
791
  }
787
792
  }
793
+ function lastProperty(properties, key) {
794
+ const last = properties.findLastIndex((property) => property.key === key);
795
+ if (last === -1) return void 0;
796
+ const property = properties[last];
797
+ if (properties.slice(last + 1).some((later) => later.key === void 0)) return null;
798
+ if (property.node.type !== "Property" || property.node.kind !== "init" || property.node.method || !property.value) return null;
799
+ return { value: staticValue(property.value) };
800
+ }
801
+ /**
802
+ * The Database name in `defineComments({ database: "name" })`, read without running the file. Undefined means the
803
+ * default or only Database.
804
+ */
805
+ async function readCommentsDatabase(file) {
806
+ const properties = await readDefinitionProperties(file);
807
+ if (!properties) return;
808
+ const found = lastProperty(properties, "database");
809
+ if (found === void 0) return;
810
+ if (found === null || found.value !== void 0 && typeof found.value !== "string") throw commentsErrorDiagnostics.COMMENTS_B0004({ file });
811
+ return typeof found.value === "string" ? found.value : void 0;
812
+ }
813
+ /**
814
+ * Whether `defineComments({ send })` turns Send on, read without running the file: Send is on unless `send` is missing
815
+ * or `false`. A value known only at runtime counts as on, so the build adds the tables and the member endpoints.
816
+ */
817
+ async function readCommentsSend(file) {
818
+ const properties = await readDefinitionProperties(file);
819
+ if (!properties) return true;
820
+ const found = lastProperty(properties, "send");
821
+ if (found === void 0) return properties.some((property) => property.key === void 0);
822
+ return found === null || found.value !== false && found.value !== void 0 && found.value !== null;
823
+ }
788
824
  /** A directory of prebuilt browser scripts in this package. */
789
825
  function builtDirectory(name) {
790
826
  const here = dirname(fileURLToPath(import.meta.url));
@@ -955,6 +991,7 @@ function renderCommentsPlugin(input) {
955
991
  ...input.session?.blob ? ["attachments: blob"] : [],
956
992
  ...input.session?.rateLimit ? ["rateLimit: checkRateLimit"] : [],
957
993
  ...postgres ? ["dialect: \"postgresql\"", "tables: { commentCounters: schema.vitehubCommentCounters, commentMessages: schema.vitehubCommentMessages, commentThreads: schema.vitehubCommentThreads, commentForge: schema.vitehubCommentForge }"] : [],
994
+ ...input.send ? [`webhooks: () => import(${JSON.stringify(input.imports.webhooks)})`] : [],
958
995
  `development: ${input.development === true}`,
959
996
  `overlay: ${overlay}`,
960
997
  `base: ${JSON.stringify(input.base ?? "")}`
@@ -1195,6 +1232,7 @@ function hubComments$1(options = {}) {
1195
1232
  if (!definition && !options.enabled) return [];
1196
1233
  const database = options.database ?? (definition ? await readCommentsDatabase(definition) : void 0);
1197
1234
  const postgres = options.dialect === "postgresql";
1235
+ const send = !postgres && definition !== void 0 && await readCommentsSend(definition);
1198
1236
  return [{
1199
1237
  ...database ? { database } : {},
1200
1238
  definition: postgres ? {
@@ -1208,7 +1246,25 @@ function hubComments$1(options = {}) {
1208
1246
  tables: commentsTableNames,
1209
1247
  name: "comments",
1210
1248
  reason: definition ? "Stores the comment threads of `server/comments.ts`." : "Stores the comment threads of `vitehub({ comments })`."
1211
- }];
1249
+ }, ...send ? [{
1250
+ ...database ? { database } : {},
1251
+ definition: {
1252
+ export: "commentSendsSchema",
1253
+ module: imports.database
1254
+ },
1255
+ dialect: "sqlite",
1256
+ tables: commentSendsTableNames,
1257
+ name: "comment-sends",
1258
+ reason: "Keeps the sends and setup codes of `defineComments({ send })`."
1259
+ }] : []];
1260
+ },
1261
+ async webhooks(context) {
1262
+ if (options.standalone) return void 0;
1263
+ const definition = findCommentsEntry$2(projectRoot ?? context.projectRoot ?? context.root ?? process.cwd(), serverDirs ?? context.serverDirs?.slice());
1264
+ return definition && await readCommentsSend(definition) ? {
1265
+ memberEndpoints: true,
1266
+ reason: "Send hands each member's waiting comments to their own agent."
1267
+ } : void 0;
1212
1268
  }
1213
1269
  },
1214
1270
  enforce: "pre",
@@ -1233,7 +1289,7 @@ function hubComments$1(options = {}) {
1233
1289
  const definition = discover() ?? await writeDefaultDefinition(directory, imports);
1234
1290
  const handler = join(directory, "handler.mjs");
1235
1291
  const plugin = join(directory, "plugin.mjs");
1236
- const pageSession = join(directory, "page-session.mjs");
1292
+ const pageToolsRoute = join(directory, "page-tools-route.mjs");
1237
1293
  componentsFile = join(directory, "components.mjs");
1238
1294
  const build = await readCommentsBuild(projectRoot);
1239
1295
  const pluginInput = {
@@ -1243,7 +1299,8 @@ function hubComments$1(options = {}) {
1243
1299
  imports,
1244
1300
  build,
1245
1301
  base,
1246
- development
1302
+ development,
1303
+ send: !options.standalone && await readCommentsSend(definition)
1247
1304
  };
1248
1305
  await Promise.all([
1249
1306
  writeFile(handler, renderCommentsHandler({
@@ -1257,17 +1314,18 @@ function hubComments$1(options = {}) {
1257
1314
  })),
1258
1315
  writeComponents(),
1259
1316
  options.standalone ? void 0 : writeFile(plugin, renderCommentsPlugin(pluginInput)),
1260
- writeFile(pageSession, `export { viteHubPageSessionHandler as default } from ${JSON.stringify(imports.runtime)}\n`)
1317
+ writeFile(pageToolsRoute, `export { viteHubPageSessionHandler as default } from ${JSON.stringify(imports.runtime)}\n`)
1261
1318
  ]);
1262
1319
  const kit = createNitroServerKit(Reflect.get(config, "nitro"));
1263
1320
  kit.addHandler({
1264
1321
  handler,
1265
1322
  lazy: true,
1323
+ meta: { ...ownAccessRouteMeta },
1266
1324
  route: `${mount}${commentsRoute}/**`
1267
1325
  });
1268
1326
  kit.addPlugin(plugin);
1269
1327
  addViteHubPageToolRoutes(kit, {
1270
- handler: pageSession,
1328
+ handler: pageToolsRoute,
1271
1329
  loader: builtDirectory("page"),
1272
1330
  mount
1273
1331
  });
@@ -1298,8 +1356,7 @@ function hubComments$1(options = {}) {
1298
1356
  } };
1299
1357
  return integration;
1300
1358
  }
1301
- //#endregion
1302
- //#region src/operations-core/console.ts
1359
+ // src/operations-core/console.ts
1303
1360
  /**
1304
1361
  * Console section for the comment inbox. It lists the result of `comments.list`, called with the Console user, so
1305
1362
  * `authorize` applies to each thread. A page thread links to `<page>?comment=<n>`.
@@ -1391,8 +1448,7 @@ const commentsConsoleSection$1 = {
1391
1448
  }
1392
1449
  }
1393
1450
  };
1394
- //#endregion
1395
- //#region src/operations-core/vite.ts
1451
+ // src/operations-core/vite.ts
1396
1452
  const COMMENTS_VITE_PLUGIN_NAME = "@vite-hub/comments/vite";
1397
1453
  function candidates(projectRoot, serverDirs) {
1398
1454
  return (serverDirs === void 0 ? [resolve(projectRoot, "server")] : serverDirs.map((directory) => resolve(projectRoot, directory))).flatMap((directory) => [
@@ -1410,8 +1466,7 @@ function findCommentsEntry$1(options) {
1410
1466
  function usesComments(options) {
1411
1467
  return findCommentsEntry$1(options) !== void 0;
1412
1468
  }
1413
- //#endregion
1414
- //#region src/overlay.ts
1469
+ // src/overlay.ts
1415
1470
  /** Where the loader and overlay are served, below the app mount: the assets folder of the Comments API route. */
1416
1471
  const overlayRoute = "/_vitehub/comments/assets";
1417
1472
  /** The path the app is mounted at: `""` for the root, `"/portal"` below it. A relative or empty Vite base is the root. */
@@ -1667,8 +1722,7 @@ function renderOverlayMiddleware(url) {
1667
1722
  ""
1668
1723
  ].join("\n");
1669
1724
  }
1670
- //#endregion
1671
- //#region src/vite.ts
1725
+ // src/vite.ts
1672
1726
  function findCommentsEntry(options, serverDirs) {
1673
1727
  return typeof options === "string" ? findCommentsEntry$2(options, serverDirs) : findCommentsEntry$1(options);
1674
1728
  }
@@ -1716,6 +1770,10 @@ function hubComments(options = {}) {
1716
1770
  logLevel: "silent"
1717
1771
  });
1718
1772
  validateCommentsDefinition(module.comments ?? module.default, display);
1773
+ if (await readCommentsSend(entry)) {
1774
+ if (liveOptions.dialect === "postgresql") throw commentsErrorDiagnostics.COMMENTS_SEND_POSTGRES();
1775
+ if (!resolved.plugins.some((plugin) => plugin.name === "@vite-hub/webhooks/vite")) throw commentsErrorDiagnostics.COMMENTS_SEND_WEBHOOKS_OFF({ file: display });
1776
+ }
1719
1777
  },
1720
1778
  vitehub: {
1721
1779
  ...live.vitehub,
@@ -1730,5 +1788,4 @@ function hubComments(options = {}) {
1730
1788
  }
1731
1789
  };
1732
1790
  }
1733
- //#endregion
1734
- export { COMMENTS_VITE_PLUGIN_NAME, comments, comments as default, commentsConsoleSection, commentsConsoleSection$1 as commentsOperationsConsoleSection, commentsOverlayDirectory, componentNames, findCommentsEntry, githubRepository, hubComments, injectLoader, loaderTag, loaderUrl, mountPath, mountedCommentsRoute, overlayRoute, readCommentsBuild, readCommentsComponents, readCommentsDatabase, renderCommentsHandler, renderCommentsPlugin, renderOverlayMiddleware, scriptNonce, usesComments };
1791
+ export { COMMENTS_VITE_PLUGIN_NAME, comments, comments as default, commentsConsoleSection, commentsConsoleSection$1 as commentsOperationsConsoleSection, commentsOverlayDirectory, componentNames, findCommentsEntry, githubRepository, hubComments, injectLoader, loaderTag, loaderUrl, mountPath, mountedCommentsRoute, overlayRoute, readCommentsBuild, readCommentsComponents, readCommentsDatabase, readCommentsSend, renderCommentsHandler, renderCommentsPlugin, renderOverlayMiddleware, scriptNonce, usesComments };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@vite-hub/comments",
3
- "version": "0.4.1",
3
+ "version": "0.5.1",
4
4
  "description": "Comments and in-place edits on live ViteHub sites, with presence and Content drafts.",
5
5
  "keywords": [
6
6
  "annotations",
@@ -106,37 +106,37 @@
106
106
  "@valibot/to-json-schema": "^1.8.0",
107
107
  "nostics": "1.4.0",
108
108
  "valibot": "^1.5.0",
109
- "@vite-hub/auth": "0.4.1",
110
- "@vite-hub/forge": "0.4.1",
111
- "@vite-hub/realtime": "0.4.1",
112
- "@vite-hub/runtime": "0.4.1",
109
+ "@vite-hub/auth": "0.5.1",
110
+ "@vite-hub/forge": "0.5.1",
111
+ "@vite-hub/realtime": "0.5.1",
112
+ "@vite-hub/runtime": "0.5.1",
113
113
  "birpc": "^4.2.0",
114
- "confbox": "^0.3.1",
114
+ "confbox": "^0.3.2",
115
115
  "h3": "^2.0.8"
116
116
  },
117
117
  "devDependencies": {
118
- "@types/node": "^24.19.1",
118
+ "@types/node": "^24.19.2",
119
119
  "@vite-hub/internal": "0.0.1",
120
- "happy-dom": "21.0.3",
120
+ "happy-dom": "21.0.4",
121
121
  "marked": "17.0.6",
122
122
  "modern-screenshot": "4.7.0",
123
123
  "nitro": "^3.0.261103-rc",
124
- "playwright-core": "^1.63.0",
124
+ "playwright-core": "^1.65.1",
125
125
  "publint": "^0.3.25",
126
126
  "typescript": "^6.0.3",
127
- "vite-plus": "^0.3.3",
128
- "vitest": "^4.1.11",
129
- "vue": "3.5.44",
127
+ "vite-plus": "^1.7.0",
128
+ "vitest": "5.1.0",
129
+ "vue": "3.5.46",
130
130
  "@libsql/client": "^0.18.0",
131
- "@vite-hub/database": "0.4.1",
132
- "vite": "^8.2.2",
133
- "drizzle-orm": "1.0.0-rc.5"
131
+ "@vite-hub/database": "0.5.1",
132
+ "vite": "^8.3.8",
133
+ "drizzle-orm": "1.0.0-rc.6"
134
134
  },
135
135
  "peerDependencies": {
136
- "@vite-hub/database": "0.4.1",
136
+ "@vite-hub/database": "0.5.1",
137
137
  "nitro": "3.0.261102-rc || ^3.0.261103-rc",
138
138
  "vite": ">=8.0.0",
139
- "drizzle-orm": "1.0.0-rc.5 || ^1.0.0"
139
+ "drizzle-orm": "1.0.0-rc.5 || 1.0.0-rc.6 || ^1.0.0"
140
140
  },
141
141
  "peerDependenciesMeta": {
142
142
  "vite": {
@@ -147,10 +147,10 @@
147
147
  "node": ">=24.15.0"
148
148
  },
149
149
  "scripts": {
150
- "build": "vp pack && vp build --config overlay.vite.config.ts",
150
+ "build": "vp pack && vp build --config overlay.vite.config.ts && vp build --config hosted.vite.config.ts",
151
151
  "dev": "vp pack && vp build --config overlay.vite.config.ts && vp pack --watch --no-clean",
152
152
  "typecheck": "vp run --cache -t @vite-hub/comments#build && node ../../test/package-typecheck.mjs --noEmit -p ./tsconfig.json",
153
153
  "test": "vp run --cache -t @vite-hub/comments#build && vp test",
154
- "test:browser": "vp run --cache -t @vite-hub/comments#build && node --test test/browser/overlay.browser.mjs test/browser/presence.browser.mjs test/browser/outbox.browser.mjs"
154
+ "test:browser": "vp run --cache -t @vite-hub/comments#build && node --test test/browser/overlay.browser.mjs test/browser/hosted.browser.mjs test/browser/presence.browser.mjs test/browser/outbox.browser.mjs test/browser/send.browser.mjs"
155
155
  }
156
156
  }