@vite-hub/comments 0.4.1 → 0.5.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.
Files changed (59) hide show
  1. package/README.md +19 -7
  2. package/dist/anchor.d.ts +2 -2
  3. package/dist/client.d.ts +424 -11
  4. package/dist/client.js +405 -5
  5. package/dist/{console-h4KlhIik.d.ts → console-D1lwNMZn.d.ts} +2 -0
  6. package/dist/{migrate-Bpw3xL5e.js → database-6hXRnqDE.js} +47 -2
  7. package/dist/database-CTo7mx6t.d.ts +575 -0
  8. package/dist/database.d.ts +2 -1
  9. package/dist/database.js +2 -2
  10. package/dist/{define-CX_Yr_hz.js → define-BMBSVbD9.js} +1 -1
  11. package/dist/{define-CHTWfHPo.d.ts → define-CmIFU96x.d.ts} +8 -4
  12. package/dist/{errors-4gelGVmK.js → errors-BJTZ9iyv.js} +24 -0
  13. package/dist/{errors-BHsVXlpd.js → errors-Dq4AHjza.js} +16 -0
  14. package/dist/{index-iPGlSAgj.d.ts → index-RiHzmV16.d.ts} +113 -11
  15. package/dist/index.d.ts +6 -7
  16. package/dist/index.js +21 -7
  17. package/dist/{install-96NXWnrw.d.ts → install-BGGQKbQ4.d.ts} +9 -3
  18. package/dist/{install-jRKmuLHK.js → install-DrAse1Fa.js} +844 -38
  19. package/dist/{installed-g6nDr5ac.js → installed-C3EoqJEY.js} +7 -6
  20. package/dist/{operations-D93EV10O.d.ts → operations-BKhUWYkb.d.ts} +9 -5
  21. package/dist/{operations-7ycAhDCw.d.ts → operations-VyyNZusz.d.ts} +8 -2
  22. package/dist/{operations-9tskoLsk.js → operations-lsVKE0GH.js} +294 -212
  23. package/dist/operations.d.ts +2 -2
  24. package/dist/operations.js +2 -2
  25. package/dist/overlay/{client-lZesR40x.js → client-DBmJ4C1M.js} +1 -1
  26. package/dist/overlay/overlay.js +36 -40
  27. package/dist/page/loader.js +39 -47
  28. package/dist/{page-CWwnmF3K.d.ts → page-Bzj0CszG.d.ts} +1 -10
  29. package/dist/{page-tools-shared-NHUjKI8E.js → page-tools-shared-BNnuPK93.js} +6 -3
  30. package/dist/{plugin-BNFd1zGz.js → plugin-DRsNaJaK.js} +14 -9
  31. package/dist/realtime.d.ts +2 -2
  32. package/dist/realtime.js +1 -1
  33. package/dist/request-log-Dj9Vw7qG.js +105 -0
  34. package/dist/request-origin-CFU0TQ7E.js +49 -0
  35. package/dist/{rpc-BZ1QNkCC.d.ts → rpc-CuJ5GLIz.d.ts} +1 -1
  36. package/dist/rpc.d.ts +1 -1
  37. package/dist/runtime/auth.d.ts +2 -2
  38. package/dist/runtime/auth.js +1 -1
  39. package/dist/runtime/console.d.ts +1 -1
  40. package/dist/runtime/console.js +1 -1
  41. package/dist/runtime/index.d.ts +11 -9
  42. package/dist/runtime/index.js +148 -14
  43. package/dist/{server-CqyzrqTI.js → server-Yk610niJ.js} +1 -1
  44. package/dist/server.d.ts +6 -5
  45. package/dist/server.js +5 -5
  46. package/dist/service-Bj-Mg63c.d.ts +73 -0
  47. package/dist/{service-C8ZgFWvy.js → service-DA5BwfPQ.js} +39 -11
  48. package/dist/{session-CKfW6DGE.d.ts → session-DUcEor2W.d.ts} +3 -3
  49. package/dist/{session-ByjMyTak.js → session-X_g9dnU5.js} +26 -29
  50. package/dist/{service-wC9kx9EX.d.ts → store-CsUNfC1w.d.ts} +2 -70
  51. package/dist/{table-names-DfiKUlOV.js → table-names-B9LlRC0B.js} +3 -1
  52. package/dist/testing.d.ts +1 -1
  53. package/dist/testing.js +2 -2
  54. package/dist/{types-C7LzhgRb.d.ts → types-BLaYh0_f.d.ts} +1 -1
  55. package/dist/{types-C1qzObs2.d.ts → types-C35INXIs.d.ts} +79 -4
  56. package/dist/vite.d.ts +22 -5
  57. package/dist/vite.js +140 -65
  58. package/package.json +8 -8
  59. package/dist/errors-BEChnUo7.d.ts +0 -197
package/dist/vite.js CHANGED
@@ -1,10 +1,10 @@
1
- import { t as commentsErrorDiagnostics } from "./errors-BHsVXlpd.js";
1
+ import { t as commentsErrorDiagnostics } from "./errors-Dq4AHjza.js";
2
2
  import { a as mountedCommentsRoute, i as commentsRoute, r as commentsRealtimeDefinition } from "./page-DRz_sDY4.js";
3
3
  import { n as isRecordOrFunction } from "./object-Da1zyPCR.js";
4
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";
5
+ import { c as validateCommentsDefinition } from "./define-BMBSVbD9.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-BNnuPK93.js";
7
+ import { n as commentsTableNames, t as commentSendsTableNames } from "./table-names-B9LlRC0B.js";
8
8
  import { formatDiagnostic } from "nostics";
9
9
  import { existsSync, mkdirSync, statSync, writeFileSync } from "node:fs";
10
10
  import { tmpdir } from "node:os";
@@ -184,7 +184,7 @@ function hasProjectRootDirectoryMarker(root) {
184
184
  for (const marker of projectRootDirectoryMarkers) try {
185
185
  if (statSync(resolve(root, ...marker)).isDirectory()) return true;
186
186
  } catch (error) {
187
- if (error.code !== "ENOENT") throw error;
187
+ if (!isMissingProjectMarker(error)) throw error;
188
188
  }
189
189
  return false;
190
190
  }
@@ -198,11 +198,15 @@ function hasProjectRootFileMarker(root, markers) {
198
198
  try {
199
199
  if (statSync(resolve(root, ...path)).isFile()) return true;
200
200
  } catch (error) {
201
- if (error.code !== "ENOENT") throw error;
201
+ if (!isMissingProjectMarker(error)) throw error;
202
202
  }
203
203
  }
204
204
  return false;
205
205
  }
206
+ function isMissingProjectMarker(error) {
207
+ const code = error.code;
208
+ return code === "ENOENT" || code === "ENOTDIR";
209
+ }
206
210
  //#endregion
207
211
  //#region ../internal/src/build/paths.ts
208
212
  function resolveRuntimeModule(packageDir, modulePath) {
@@ -253,10 +257,46 @@ function findContentEntry(projectRoot, serverDirs) {
253
257
  if (existsSync(file)) return file;
254
258
  }
255
259
  }
260
+ Object.freeze({ vitehubAuthAccess: "handler" });
261
+ /**
262
+ * The route meta of a generated handler that checks access on every request, even when the app adds no rule: a required
263
+ * `authorize` policy, an explicit `access` rule, a required access token, or a signature. Auth access routes still apply
264
+ * to it, so an app rule stays in force. `checksOwnAccess(event)` of `vite-hub/auth` reads it, so app middleware can skip
265
+ * the route. A route that can run without a check, such as a browser error sink, an optional `authorize`, or a webhook
266
+ * with `secret: false`, must not use it.
267
+ */
268
+ const ownAccessRouteMeta = Object.freeze({ vitehubOwnAccess: true });
269
+ function cloneArray(value) {
270
+ return Array.isArray(value) ? [...value] : [];
271
+ }
272
+ function sameHandler(left, right) {
273
+ return left.handler === right.handler && left.route === right.route && left.method === right.method && left.middleware === right.middleware;
274
+ }
275
+ /** Create a Nitro 3 configuration builder for generated ViteHub output. */
276
+ function createNitroServerKit(value = {}) {
277
+ const config = isRecordOrFunction(value) ? { ...value } : {};
278
+ const handlers = cloneArray(config.handlers);
279
+ const plugins = cloneArray(config.plugins);
280
+ config.handlers = handlers;
281
+ config.plugins = plugins;
282
+ return {
283
+ config,
284
+ addHandler(handler, position = "end") {
285
+ if (handlers.some((candidate) => isRecordOrFunction(candidate) && sameHandler(candidate, handler))) return;
286
+ if (position === "start") handlers.unshift({ ...handler });
287
+ else handlers.push({ ...handler });
288
+ },
289
+ addPlugin(plugin, position = "end") {
290
+ if (plugins.includes(plugin)) return;
291
+ if (position === "start") plugins.unshift(plugin);
292
+ else plugins.push(plugin);
293
+ }
294
+ };
295
+ }
256
296
  //#endregion
257
297
  //#region ../internal/src/build/page-tools.ts
258
298
  /**
259
- * Adds the session route `GET <mount>/_vitehub/page/session` and the loader script at
299
+ * Adds the session route `GET <mount>/_vitehub/page/tools` and the loader script at
260
300
  * `<mount>/_vitehub/page/assets/loader.js` to a Nitro configuration. Each owner package of a page tool calls it from its
261
301
  * Vite plugin, so the routes exist without the Console. The first owner wins: a later call keeps the route and the asset
262
302
  * that are already there, because the page tools registry is shared by every copy of this package.
@@ -267,6 +307,7 @@ function addViteHubPageToolRoutes(kit, options) {
267
307
  const assetsBase = `${mount}${viteHubPageToolsAssets}`;
268
308
  if (!(Array.isArray(kit.config.handlers) ? kit.config.handlers : []).some((handler) => Object(handler) === handler && Reflect.get(Object(handler), "route") === route)) kit.addHandler({
269
309
  handler: options.handler,
310
+ meta: { ...ownAccessRouteMeta },
270
311
  route
271
312
  });
272
313
  const assets = Array.isArray(kit.config.publicAssets) ? [...kit.config.publicAssets] : [];
@@ -570,35 +611,6 @@ function includedNitro(options = {}) {
570
611
  return plugins;
571
612
  }
572
613
  //#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
614
  //#region src/deployment-env.ts
603
615
  const owners = ["comments"];
604
616
  const githubLoginNames = {
@@ -734,57 +746,94 @@ const defaultImports = {
734
746
  contentClient: "@vite-hub/content/client",
735
747
  connect: "@vite-hub/comments/runtime/connect",
736
748
  blob: "@vite-hub/blob",
737
- rateLimit: "@vite-hub/rate-limit"
749
+ rateLimit: "@vite-hub/rate-limit",
750
+ webhooks: "@vite-hub/webhooks"
738
751
  };
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) {
752
+ function literalProperties(options) {
753
+ return objectProperties(options).flatMap((property) => {
754
+ if (property.node.type !== "SpreadElement") return [property];
755
+ const spread = unwrapExpression(property.node.argument);
756
+ return spread.type === "ObjectExpression" ? literalProperties(spread) : [property];
757
+ });
758
+ }
759
+ async function readDefinitionProperties(file) {
744
760
  const module = scanModule(await readFile(file, "utf8").catch(() => ""), file);
745
761
  if (module.errors.length) return;
746
762
  const bindings = /* @__PURE__ */ new Set();
747
763
  const factories = /* @__PURE__ */ new Set(["defineComments"]);
748
764
  let defaultCall;
765
+ let hasNamedExport = false;
749
766
  for (const statement of module.program.body) {
750
767
  if (statement.type === "ImportDeclaration" && statement.importKind !== "type" && ["vite-hub/comments", "@vite-hub/comments"].includes(statement.source.value)) for (const specifier of statement.specifiers) {
751
768
  if (specifier.type !== "ImportSpecifier" || specifier.importKind === "type") continue;
752
769
  if ((specifier.imported.type === "Identifier" ? specifier.imported.name : specifier.imported.value) === "defineComments") factories.add(specifier.local.name);
753
770
  }
754
771
  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;
772
+ defaultCall = unwrapExpression(statement.declaration);
758
773
  continue;
759
774
  }
760
- if (statement.type !== "ExportNamedDeclaration" || statement.source) continue;
775
+ if (statement.type !== "ExportNamedDeclaration" || statement.exportKind === "type") continue;
761
776
  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);
777
+ for (const declaration of statement.declaration.declarations) if (declaration.id.type === "Identifier" && declaration.id.name === "comments") {
778
+ hasNamedExport = true;
779
+ bindings.add(declaration.id.name);
780
+ }
781
+ }
782
+ for (const specifier of statement.specifiers) if ((specifier.exported.type === "Identifier" ? specifier.exported.name : specifier.exported.value) === "comments" && specifier.exportKind !== "type") {
783
+ hasNamedExport = true;
784
+ if (!statement.source && specifier.local.type === "Identifier") bindings.add(specifier.local.name);
763
785
  }
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
786
  }
766
- const databaseOf = (call) => {
787
+ const propertiesOf = (call) => {
767
788
  if (call.type !== "CallExpression" || call.callee.type !== "Identifier" || !factories.has(call.callee.name)) return;
789
+ if (call.arguments.length === 0) return [];
768
790
  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;
791
+ return options?.type === "ObjectExpression" ? literalProperties(options) : void 0;
777
792
  };
778
- if (defaultCall) return databaseOf(defaultCall);
793
+ if (!hasNamedExport && defaultCall) {
794
+ if (defaultCall.type !== "Identifier") return propertiesOf(defaultCall);
795
+ bindings.add(defaultCall.name);
796
+ }
779
797
  for (const statement of module.program.body) {
780
798
  const declaration = statement.type === "ExportNamedDeclaration" ? statement.declaration : statement;
781
799
  if (declaration?.type !== "VariableDeclaration") continue;
782
800
  for (const binding of declaration.declarations) {
783
801
  if (binding.id.type !== "Identifier" || !bindings.has(binding.id.name) || !binding.init) continue;
784
- return databaseOf(unwrapExpression(binding.init));
802
+ return propertiesOf(unwrapExpression(binding.init));
785
803
  }
786
804
  }
787
805
  }
806
+ function lastProperty(properties, key) {
807
+ const last = properties.findLastIndex((property) => property.key === key);
808
+ if (last === -1) return void 0;
809
+ const property = properties[last];
810
+ if (properties.slice(last + 1).some((later) => later.key === void 0)) return null;
811
+ if (property.node.type !== "Property" || property.node.kind !== "init" || property.node.method || !property.value) return null;
812
+ return { value: staticValue(property.value) };
813
+ }
814
+ /**
815
+ * The Database name in `defineComments({ database: "name" })`, read without running the file. Undefined means the
816
+ * default or only Database.
817
+ */
818
+ async function readCommentsDatabase(file) {
819
+ const properties = await readDefinitionProperties(file);
820
+ if (!properties) return;
821
+ const found = lastProperty(properties, "database");
822
+ if (found === void 0) return;
823
+ if (found === null || found.value !== void 0 && typeof found.value !== "string") throw commentsErrorDiagnostics.COMMENTS_B0004({ file });
824
+ return typeof found.value === "string" ? found.value : void 0;
825
+ }
826
+ /**
827
+ * Whether `defineComments({ send })` turns Send on, read without running the file: Send is on unless `send` is missing
828
+ * or `false`. A value known only at runtime counts as on, so the build adds the tables and the member endpoints.
829
+ */
830
+ async function readCommentsSend(file) {
831
+ const properties = await readDefinitionProperties(file);
832
+ if (!properties) return true;
833
+ const found = lastProperty(properties, "send");
834
+ if (found === void 0) return properties.some((property) => property.key === void 0);
835
+ return found === null || found.value !== false && found.value !== void 0 && found.value !== null;
836
+ }
788
837
  /** A directory of prebuilt browser scripts in this package. */
789
838
  function builtDirectory(name) {
790
839
  const here = dirname(fileURLToPath(import.meta.url));
@@ -955,6 +1004,7 @@ function renderCommentsPlugin(input) {
955
1004
  ...input.session?.blob ? ["attachments: blob"] : [],
956
1005
  ...input.session?.rateLimit ? ["rateLimit: checkRateLimit"] : [],
957
1006
  ...postgres ? ["dialect: \"postgresql\"", "tables: { commentCounters: schema.vitehubCommentCounters, commentMessages: schema.vitehubCommentMessages, commentThreads: schema.vitehubCommentThreads, commentForge: schema.vitehubCommentForge }"] : [],
1007
+ ...input.send ? [`webhooks: () => import(${JSON.stringify(input.imports.webhooks)})`] : [],
958
1008
  `development: ${input.development === true}`,
959
1009
  `overlay: ${overlay}`,
960
1010
  `base: ${JSON.stringify(input.base ?? "")}`
@@ -1195,6 +1245,7 @@ function hubComments$1(options = {}) {
1195
1245
  if (!definition && !options.enabled) return [];
1196
1246
  const database = options.database ?? (definition ? await readCommentsDatabase(definition) : void 0);
1197
1247
  const postgres = options.dialect === "postgresql";
1248
+ const send = !postgres && definition !== void 0 && await readCommentsSend(definition);
1198
1249
  return [{
1199
1250
  ...database ? { database } : {},
1200
1251
  definition: postgres ? {
@@ -1208,7 +1259,25 @@ function hubComments$1(options = {}) {
1208
1259
  tables: commentsTableNames,
1209
1260
  name: "comments",
1210
1261
  reason: definition ? "Stores the comment threads of `server/comments.ts`." : "Stores the comment threads of `vitehub({ comments })`."
1211
- }];
1262
+ }, ...send ? [{
1263
+ ...database ? { database } : {},
1264
+ definition: {
1265
+ export: "commentSendsSchema",
1266
+ module: imports.database
1267
+ },
1268
+ dialect: "sqlite",
1269
+ tables: commentSendsTableNames,
1270
+ name: "comment-sends",
1271
+ reason: "Keeps the sends and setup codes of `defineComments({ send })`."
1272
+ }] : []];
1273
+ },
1274
+ async webhooks(context) {
1275
+ if (options.standalone) return void 0;
1276
+ const definition = findCommentsEntry$2(projectRoot ?? context.projectRoot ?? context.root ?? process.cwd(), serverDirs ?? context.serverDirs?.slice());
1277
+ return definition && await readCommentsSend(definition) ? {
1278
+ memberEndpoints: true,
1279
+ reason: "Send hands each member's waiting comments to their own agent."
1280
+ } : void 0;
1212
1281
  }
1213
1282
  },
1214
1283
  enforce: "pre",
@@ -1233,7 +1302,7 @@ function hubComments$1(options = {}) {
1233
1302
  const definition = discover() ?? await writeDefaultDefinition(directory, imports);
1234
1303
  const handler = join(directory, "handler.mjs");
1235
1304
  const plugin = join(directory, "plugin.mjs");
1236
- const pageSession = join(directory, "page-session.mjs");
1305
+ const pageToolsRoute = join(directory, "page-tools-route.mjs");
1237
1306
  componentsFile = join(directory, "components.mjs");
1238
1307
  const build = await readCommentsBuild(projectRoot);
1239
1308
  const pluginInput = {
@@ -1243,7 +1312,8 @@ function hubComments$1(options = {}) {
1243
1312
  imports,
1244
1313
  build,
1245
1314
  base,
1246
- development
1315
+ development,
1316
+ send: !options.standalone && await readCommentsSend(definition)
1247
1317
  };
1248
1318
  await Promise.all([
1249
1319
  writeFile(handler, renderCommentsHandler({
@@ -1257,17 +1327,18 @@ function hubComments$1(options = {}) {
1257
1327
  })),
1258
1328
  writeComponents(),
1259
1329
  options.standalone ? void 0 : writeFile(plugin, renderCommentsPlugin(pluginInput)),
1260
- writeFile(pageSession, `export { viteHubPageSessionHandler as default } from ${JSON.stringify(imports.runtime)}\n`)
1330
+ writeFile(pageToolsRoute, `export { viteHubPageSessionHandler as default } from ${JSON.stringify(imports.runtime)}\n`)
1261
1331
  ]);
1262
1332
  const kit = createNitroServerKit(Reflect.get(config, "nitro"));
1263
1333
  kit.addHandler({
1264
1334
  handler,
1265
1335
  lazy: true,
1336
+ meta: { ...ownAccessRouteMeta },
1266
1337
  route: `${mount}${commentsRoute}/**`
1267
1338
  });
1268
1339
  kit.addPlugin(plugin);
1269
1340
  addViteHubPageToolRoutes(kit, {
1270
- handler: pageSession,
1341
+ handler: pageToolsRoute,
1271
1342
  loader: builtDirectory("page"),
1272
1343
  mount
1273
1344
  });
@@ -1716,6 +1787,10 @@ function hubComments(options = {}) {
1716
1787
  logLevel: "silent"
1717
1788
  });
1718
1789
  validateCommentsDefinition(module.comments ?? module.default, display);
1790
+ if (await readCommentsSend(entry)) {
1791
+ if (liveOptions.dialect === "postgresql") throw commentsErrorDiagnostics.COMMENTS_SEND_POSTGRES();
1792
+ if (!resolved.plugins.some((plugin) => plugin.name === "@vite-hub/webhooks/vite")) throw commentsErrorDiagnostics.COMMENTS_SEND_WEBHOOKS_OFF({ file: display });
1793
+ }
1719
1794
  },
1720
1795
  vitehub: {
1721
1796
  ...live.vitehub,
@@ -1731,4 +1806,4 @@ function hubComments(options = {}) {
1731
1806
  };
1732
1807
  }
1733
1808
  //#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 };
1809
+ 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.0",
4
4
  "description": "Comments and in-place edits on live ViteHub sites, with presence and Content drafts.",
5
5
  "keywords": [
6
6
  "annotations",
@@ -106,10 +106,10 @@
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.0",
110
+ "@vite-hub/forge": "0.5.0",
111
+ "@vite-hub/realtime": "0.5.0",
112
+ "@vite-hub/runtime": "0.5.0",
113
113
  "birpc": "^4.2.0",
114
114
  "confbox": "^0.3.1",
115
115
  "h3": "^2.0.8"
@@ -128,12 +128,12 @@
128
128
  "vitest": "^4.1.11",
129
129
  "vue": "3.5.44",
130
130
  "@libsql/client": "^0.18.0",
131
- "@vite-hub/database": "0.4.1",
131
+ "@vite-hub/database": "0.5.0",
132
132
  "vite": "^8.2.2",
133
133
  "drizzle-orm": "1.0.0-rc.5"
134
134
  },
135
135
  "peerDependencies": {
136
- "@vite-hub/database": "0.4.1",
136
+ "@vite-hub/database": "0.5.0",
137
137
  "nitro": "3.0.261102-rc || ^3.0.261103-rc",
138
138
  "vite": ">=8.0.0",
139
139
  "drizzle-orm": "1.0.0-rc.5 || ^1.0.0"
@@ -151,6 +151,6 @@
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/presence.browser.mjs test/browser/outbox.browser.mjs test/browser/send.browser.mjs"
155
155
  }
156
156
  }
@@ -1,197 +0,0 @@
1
- //#region src/operations-core/errors.d.ts
2
- declare const commentsErrorDiagnostics: import("nostics").Diagnostics<{
3
- readonly COMMENTS_R0002: {
4
- readonly why: ({ id }: {
5
- id: string;
6
- }) => string;
7
- readonly fix: "List the threads again, because someone may have deleted this one.";
8
- };
9
- readonly COMMENTS_R0003: {
10
- readonly why: ({ messageId }: {
11
- messageId: string;
12
- }) => string;
13
- readonly fix: "Read the thread again, because someone may have deleted the message.";
14
- };
15
- readonly COMMENTS_R0004: {
16
- readonly why: "Only the author of a message can edit or delete it.";
17
- readonly fix: "Sign in as the author, or ask them to change the message.";
18
- };
19
- readonly COMMENTS_R0005: {
20
- readonly why: "A comment needs some text.";
21
- readonly fix: "Write at least one character before you send.";
22
- };
23
- readonly COMMENTS_R0006: {
24
- readonly why: "server/comments.ts defines no authorize policy, so a production build lets in only people signed in with GitHub who can push to the repository, and people that the Console admits to its Comments section. Other signed-in people, such as users of ViteHub Auth or identify, get nothing.";
25
- readonly fix: "Pass authorize to defineComments({ authorize }) and return true for the people and Agents that may take the action. See https://vitehub.dev/docs/comments/configure#decide-who-can-comment";
26
- };
27
- readonly COMMENTS_R0007: {
28
- readonly why: ({ message }: {
29
- message: string;
30
- }) => string;
31
- readonly fix: "Mention only people that users() finds, and write @ and their name in the text.";
32
- };
33
- readonly COMMENTS_R0008: {
34
- readonly why: ({ kind }: {
35
- kind: string;
36
- }) => string;
37
- readonly fix: "Use page or content, or add defineCommentSubject({ kind, scope }) to defineComments({ subjects }).";
38
- };
39
- readonly COMMENTS_R0009: {
40
- readonly why: ({ action }: {
41
- action: string;
42
- }) => string;
43
- readonly fix: "Ask for access, or allow the action in defineComments({ authorize }).";
44
- };
45
- readonly COMMENTS_R0010: {
46
- readonly why: "The comments runtime is not installed.";
47
- readonly fix: "Add server/comments.ts and enable the Database with vitehub({ database: true }). `vite dev` and builds install the runtime for you.";
48
- };
49
- readonly COMMENTS_R0011: {
50
- readonly why: "The comment numbers of this scope are busy.";
51
- readonly fix: "Try again. Several people created a comment at the same moment.";
52
- };
53
- readonly COMMENTS_R0012: {
54
- readonly why: "Writing a comment needs a signed-in user.";
55
- readonly fix: "Sign in, then try again. Without ViteHub Auth or `identify`, sign in with GitHub so comments know who writes.";
56
- };
57
- readonly COMMENTS_R0014: {
58
- readonly why: "Comments has no place to store attachments: the app has no Blob store and no storeAttachment hook.";
59
- readonly fix: "Turn on Blob with vitehub({ blob: true }), or pass storeAttachment to defineComments().";
60
- };
61
- readonly COMMENTS_R0016: {
62
- readonly why: "The thread is resolved, so it takes no new replies.";
63
- readonly fix: "Reopen the thread first, or pass { allowResolved: true } to comments.reply() when your UI allows replies to resolved threads.";
64
- };
65
- readonly COMMENTS_R0017: {
66
- readonly why: ({ message }: {
67
- message: string;
68
- }) => string;
69
- readonly fix: "Attach an image, a PDF, or a text file of at most 5 MB.";
70
- };
71
- readonly COMMENTS_R0018: {
72
- readonly why: ({ message }: {
73
- message: string;
74
- }) => string;
75
- readonly fix: "Check the input against the limits of comments: https://vitehub.dev/docs/comments/limits-and-errors";
76
- };
77
- readonly COMMENTS_R0019: {
78
- readonly why: ({ state, missing }: {
79
- state: "empty" | "live" | "outdated";
80
- missing: readonly string[];
81
- }) => string;
82
- readonly fix: ({ state }: {
83
- state: "empty" | "live" | "outdated";
84
- }) => "Move the tables once in a custom migration: run vitehub database generate --custom --schema-snapshot --name comments_one_model, put the SQL of commentsMigrationSql({ from: \"live\" }) from vite-hub/comments/database in it, then run vitehub database migrate. See https://vitehub.dev/docs/comments/configure#upgrade-to-one-model" | "Run vitehub database generate and vitehub database migrate, so the Database gets the comment tables of this version. See https://vitehub.dev/docs/comments/configure#upgrade-to-one-model";
85
- };
86
- readonly COMMENTS_R0020: {
87
- readonly why: ({ key }: {
88
- key: string;
89
- }) => string;
90
- readonly fix: "Read the attachment through a message that lists its key, as a person who may read that thread.";
91
- };
92
- readonly COMMENTS_R0021: {
93
- readonly why: "Comments stores attachments with storeAttachment, but has no readAttachment to read them back.";
94
- readonly fix: "Pass readAttachment to defineComments(), next to storeAttachment, and return the file of the key as a Blob.";
95
- };
96
- readonly COMMENTS_R0022: {
97
- readonly why: "Another comment thread of this scope, or another reply in this thread, already uses this requestId: it has another author or another subject, or you may not read it.";
98
- readonly fix: "Send a new requestId, such as crypto.randomUUID(), for each new comment or reply. Send the same requestId again only to retry the same one.";
99
- };
100
- readonly COMMENTS_B0001: {
101
- readonly why: ({ file }: {
102
- file: string;
103
- }) => string;
104
- readonly fix: "Remove `database: false` from vitehub(), or set `database: true`. vitehub() turns the Database on for comments when the option is unset.";
105
- };
106
- readonly COMMENTS_B0002: {
107
- readonly why: ({ file }: {
108
- file: string;
109
- }) => string;
110
- readonly fix: "Write `export default defineComments({ authorize })` in server/comments.ts.";
111
- };
112
- readonly COMMENTS_B0003: {
113
- readonly why: "comments() from @vite-hub/comments/vite is for apps without vitehub(). In this app vitehub() owns the Comments configuration.";
114
- readonly fix: "Remove comments() from the plugins and set vitehub({ comments: true }), or add server/comments.ts. See https://vitehub.dev/docs/comments/configure#turn-comments-on-in-a-vitehub-app";
115
- };
116
- readonly COMMENTS_B0004: {
117
- readonly why: ({ file }: {
118
- file: string;
119
- }) => string;
120
- readonly fix: "Write the Database name as a string literal, such as `defineComments({ database: \"content\" })`, and put no spread after it. Remove the option to use the default or only Database.";
121
- };
122
- readonly COMMENTS_DATABASE_TOKEN_IN_BUILD: {
123
- readonly why: "The `database` option of `comments()` has an `authToken` in its URL, so the token ends up in the build output.";
124
- readonly fix: "Put the URL with its token in a variable, and pass the variable: `comments({ database: \"env:COMMENTS_DATABASE_URL\" })`.";
125
- };
126
- readonly COMMENTS_GITHUB_CREDENTIALS_MISSING: {
127
- readonly why: "Comments needs GitHub credentials to post to pull requests: VITEHUB_GITHUB_APP_ID with VITEHUB_GITHUB_PRIVATE_KEY, or VITEHUB_GITHUB_TOKEN.";
128
- readonly fix: "Set `VITEHUB_GITHUB_APP_ID` and `VITEHUB_GITHUB_PRIVATE_KEY` of a GitHub App that is installed on the repository, or set `VITEHUB_GITHUB_TOKEN`.";
129
- };
130
- readonly COMMENTS_GITHUB_REQUEST_FAILED: {
131
- readonly why: ({ path, status }: {
132
- path: string;
133
- status: number;
134
- }) => string;
135
- readonly fix: "Sign in with GitHub again, because a status of 401 means that the token expired. For other statuses, check that the GitHub OAuth app of the Comments login is active and that GitHub is reachable.";
136
- };
137
- readonly COMMENTS_GITHUB_SYNC_FAILED: {
138
- readonly why: ({ reason, request, status }: {
139
- reason: string;
140
- request: string;
141
- status: number;
142
- }) => string;
143
- readonly fix: "Check that the GitHub App or `VITEHUB_GITHUB_TOKEN` can write pull request comments in the repository. A retry helps for a 5xx status.";
144
- };
145
- readonly COMMENTS_GUEST_RATE_LIMITED: {
146
- readonly why: ({ retryAfter }: {
147
- retryAfter: number | undefined;
148
- }) => string;
149
- readonly fix: "Wait, then try again. Sign in to write without the guest limit of defineComments({ rateLimit }).";
150
- };
151
- readonly COMMENTS_MIGRATION_DATABASE_UNSUPPORTED: {
152
- readonly why: ({ dialect }: {
153
- dialect: "postgresql" | "sqlite";
154
- }) => "[vitehub] migrateComments() needs a Postgres Drizzle database with transaction()." | "[vitehub] migrateComments() needs a Drizzle database with batch() or transaction(), so a failure changes nothing.";
155
- readonly fix: "Pass `migrateComments()` the Drizzle database of `useDatabase()`, or of another driver with `transaction()` on Postgres, or `batch()` or `transaction()` on SQLite.";
156
- };
157
- readonly COMMENTS_MIGRATION_LIVE_POSTGRES: {
158
- readonly why: "[vitehub] The live-site comments model had no Postgres tables, so there is nothing to move.";
159
- readonly fix: "Use `from: \"outdated\"` for a Postgres Database. Only SQLite, libSQL, and D1 have tables of the live-site model.";
160
- };
161
- readonly COMMENTS_RATE_LIMIT_INVALID: {
162
- readonly why: ({ issue }: {
163
- issue: string;
164
- }) => string;
165
- readonly fix: "Pass rateLimit as { limit, window }, such as { limit: 5, window: \"1m\" }, or remove it to let guests write without a limit.";
166
- };
167
- readonly COMMENTS_SECRET_TOO_SHORT: {
168
- readonly why: ({ minimum }: {
169
- minimum: number;
170
- }) => string;
171
- readonly fix: "Set `VITEHUB_SECRET` to the output of `openssl rand -base64 32`, which has 44 characters.";
172
- };
173
- readonly COMMENTS_OUTBOX_ACCOUNT_CHANGED: {
174
- why: string;
175
- fix: string;
176
- };
177
- readonly COMMENTS_OUTBOX_SENDING: {
178
- why: string;
179
- fix: string;
180
- };
181
- readonly COMMENTS_R0001: {
182
- why: ({ target }: {
183
- target: string;
184
- }) => string;
185
- fix: string;
186
- };
187
- readonly COMMENTS_R0013: {
188
- why: string;
189
- fix: string;
190
- };
191
- readonly COMMENTS_R0015: {
192
- why: string;
193
- fix: string;
194
- };
195
- }, readonly import("nostics").AnyDiagnosticReporter[], import("nostics").InferCodesData>;
196
- //#endregion
197
- export { commentsErrorDiagnostics as t };