@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.
Files changed (70) hide show
  1. package/README.md +4 -10
  2. package/dist/anchor.d.ts +2 -2
  3. package/dist/anchor.js +0 -1
  4. package/dist/{client-files-lC6X7XyS.js → client-files-CMPJEd21.js} +0 -1
  5. package/dist/client-request-B1DCz3a9.js +29 -0
  6. package/dist/client.d.ts +21 -241
  7. package/dist/client.js +4 -425
  8. package/dist/database.d.ts +1 -2
  9. package/dist/database.js +1 -1
  10. package/dist/{define-BqPcuDhf.js → define-hs9Z38io.js} +1 -2
  11. package/dist/{errors-C0VwRHiy.js → errors-C5utwZ5H.js} +0 -24
  12. package/dist/{errors-CBvIpwbo.js → errors-DeSEHzRf.js} +0 -12
  13. package/dist/hosted/hosted-comments/frame.js +4 -1
  14. package/dist/hosted/hosted-comments/tools.js +71 -77
  15. package/dist/hosted/hosted-comments.js +1 -1
  16. package/dist/{index-D1T7RJ4R.d.ts → index-CbXek64X.d.ts} +5 -113
  17. package/dist/index.d.ts +5 -6
  18. package/dist/index.js +6 -23
  19. package/dist/{install-CqBWFmU7.js → install--HecUN5c.js} +8 -789
  20. package/dist/{install-9L4ASzUC.d.ts → install-C3CW6Vvw.d.ts} +6 -12
  21. package/dist/{installed-wUYjqk_k.js → installed-BqQKo6WC.js} +2 -7
  22. package/dist/{database-BuSNVwTx.js → migrate-cxoJK4JQ.js} +2 -64
  23. package/dist/{operations-Qt8ASQqW.d.ts → operations-D0EO1pzL.d.ts} +36 -8
  24. package/dist/{operations-kMPw-Cyb.js → operations-DHXmbtb3.js} +47 -75
  25. package/dist/operations.d.ts +3 -3
  26. package/dist/operations.js +2 -2
  27. package/dist/overlay/client-BszZKIf8.js +4 -0
  28. package/dist/overlay/overlay.js +50 -43
  29. package/dist/page/loader.js +37 -30
  30. package/dist/{page-2NzFladc.js → page-CJz1K67L.js} +25 -2
  31. package/dist/page-DRM1j84-.d.ts +32 -0
  32. package/dist/{page-tools-shared-BNw-aWEH.js → page-tools-shared-BCdvqA4S.js} +40 -2
  33. package/dist/{path-8yqMd8zR.js → path-sv8kjq3i.js} +0 -4
  34. package/dist/{plugin-ChOHe7vq.js → plugin-DczA2K-y.js} +9 -9
  35. package/dist/realtime.d.ts +7 -9
  36. package/dist/realtime.js +2 -4
  37. package/dist/{rpc-kkxzQ3Qy.js → rpc-51X1TWKb.js} +1 -1
  38. package/dist/{rpc-D-eqtyfh.d.ts → rpc-DZB3yU0z.d.ts} +1 -1
  39. package/dist/rpc.d.ts +1 -1
  40. package/dist/rpc.js +1 -1
  41. package/dist/runtime/auth.d.ts +1 -2
  42. package/dist/runtime/auth.js +1 -1
  43. package/dist/runtime/client-request-plugin.d.ts +2 -0
  44. package/dist/runtime/client-request-plugin.js +21 -0
  45. package/dist/runtime/console.js +2 -2
  46. package/dist/runtime/index.d.ts +6 -9
  47. package/dist/runtime/index.js +25 -175
  48. package/dist/{server-8o9u8leM.js → server-CAMs6viR.js} +1 -1
  49. package/dist/server.d.ts +12 -8
  50. package/dist/server.js +8 -7
  51. package/dist/{service-XT2A8YEF.js → service-DFMwCr60.js} +34 -42
  52. package/dist/{store-DvNTDNgn.d.ts → service-qaMuJ7UX.d.ts} +68 -2
  53. package/dist/{session-DGdFKWDB.js → session-1SI3_wLJ.js} +212 -66
  54. package/dist/{session-CN4irEqf.d.ts → session-CK3Rnjto.d.ts} +2 -3
  55. package/dist/{table-names-BIHjuEFK.js → table-names-DUmWROM4.js} +1 -3
  56. package/dist/testing.d.ts +1 -1
  57. package/dist/testing.js +1 -2
  58. package/dist/{tokens-Bx4lZ0yt.js → tokens-WRh__ppm.js} +0 -1
  59. package/dist/{types-BX3vH18p.d.ts → types-BmzTyGt-.d.ts} +4 -0
  60. package/dist/{define-B1jLSPe9.d.ts → types-VSVs4jIw.d.ts} +157 -4
  61. package/dist/vite.d.ts +3 -20
  62. package/dist/vite.js +15 -82
  63. package/package.json +8 -8
  64. package/dist/database-CPua6Q6_.d.ts +0 -573
  65. package/dist/overlay/client-CrnKCZXc.js +0 -4
  66. package/dist/overlay/dist-yIZmvSaU.js +0 -1
  67. package/dist/page-DE71P_gQ.d.ts +0 -11
  68. package/dist/request-origin-B-CPVAVk.js +0 -53
  69. package/dist/service-IvgrI4XM.d.ts +0 -71
  70. package/dist/types-l6GOb_yc.d.ts +0 -206
@@ -1,4 +1,5 @@
1
- import { D as CommentUser, T as CommentThread, b as CommentMetadata, n as CommentActor, w as CommentSubject, y as CommentMessage } from "./types-BX3vH18p.js";
1
+ import { D as CommentUser, S as CommentStatus, T as CommentThread, _ as CommentListCursor, b as CommentMetadata, n as CommentActor, r as CommentAnchor, s as CommentContext, w as CommentSubject, y as CommentMessage } from "./types-BmzTyGt-.js";
2
+ import { ViteHubContext } from "@vite-hub/runtime";
2
3
  /**
3
4
  * - `read`: see threads, join the presence room of a page, and get `@` suggestions.
4
5
  * - `write`: start threads and reply. Signed-in authors also edit and delete their own messages.
@@ -78,10 +79,19 @@ interface CommentsPeople {
78
79
  * People whose name contains `query`, with the fields that `canMention` reads. Comments returns only their `id`,
79
80
  * `name`, and `image`.
80
81
  */
81
- search: (query: string, limit: number) => Promise<CommentUser[]> | CommentUser[];
82
+ search: (query: string, limit: number, context: CommentsPeopleSearchContext) => Promise<CommentUser[]> | CommentUser[];
82
83
  /** The people with these ids, including fields that `authorize` reads. An id that is not a person is left out. */
83
84
  byIds: (ids: readonly string[]) => Promise<CommentUser[]> | CommentUser[];
84
85
  }
86
+ /** Where the person who types `@` writes, so `people.search` can look first among the people of that thread or subject. */
87
+ interface CommentsPeopleSearchContext {
88
+ /** The person who writes the message. */
89
+ user: CommentsUser | null;
90
+ /** The thread of the message. Not set for a new thread. */
91
+ thread?: CommentThread;
92
+ /** The subject of the thread, or of the new thread. */
93
+ subject?: CommentSubject;
94
+ }
85
95
  interface CommentsCanMentionContext {
86
96
  /** The person who writes the message. */
87
97
  user: CommentsUser | null;
@@ -105,6 +115,11 @@ interface CommentMessageEvent {
105
115
  message: CommentMessage;
106
116
  /** The people that the message mentions. */
107
117
  mentions: CommentUser[];
118
+ /**
119
+ * Keeps `promise` running after the answer, so slow work such as a webhook does not make the writer wait. It uses
120
+ * the host's `waitUntil` where there is one. A rejection is logged and never fails the comment.
121
+ */
122
+ waitUntil: (promise: Promise<unknown>) => void;
108
123
  }
109
124
  /** A file to attach, after Comments checked its size and type. */
110
125
  interface CommentsAttachmentFile {
@@ -153,7 +168,10 @@ interface CommentsDefinition {
153
168
  * answer, through `waitUntil` where the host has it. A failure is logged and never fails the comment.
154
169
  */
155
170
  onMention?: (event: CommentMentionEvent) => void | Promise<void>;
156
- /** Runs after each new thread and each reply saves, before the answer. Errors are logged, not returned. */
171
+ /**
172
+ * Runs after each new thread and each reply saves, before the answer. Give slow work to `event.waitUntil()` so the
173
+ * answer does not wait for it. Errors are logged, not returned.
174
+ */
157
175
  onComment?: (event: CommentMessageEvent) => void | Promise<void>;
158
176
  /**
159
177
  * Stores an uploaded file and returns its key, which messages keep in `attachments`. Without it, Comments stores the
@@ -203,4 +221,139 @@ declare function commentsRoleAllows(user: CommentsUser | null, action: CommentAc
203
221
  * who may, because any visitor may be able to sign up. On the page, only people signed in with GitHub get in.
204
222
  */
205
223
  declare function defaultPolicy(user: CommentsUser | null, gate?: CommentsPolicyGate, action?: CommentAction): boolean;
206
- export { commentsRoleAllows as _, CommentsAttachmentFile as a, validateCommentsDefinition as b, CommentsCanMentionContext as c, CommentsPeople as d, CommentsPolicyGate as f, CommentsUser as g, CommentsStoreAttachmentContext as h, CommentSubjectDefinition as i, CommentsDefinition as l, CommentsReadAttachmentContext as m, CommentMentionEvent as n, CommentsAuthorize as o, CommentsRateLimit as p, CommentMessageEvent as r, CommentsAuthorizeContext as s, CommentAction as t, CommentsGitHubAccess as u, defaultPolicy as v, defineCommentSubject as y };
224
+ interface CommentsForgeTarget {
225
+ repository: string;
226
+ pullRequest: number;
227
+ }
228
+ /**
229
+ * Posts each thread to the pull request of the build that served its page: one comment per message, and one summary
230
+ * comment that lists every thread. Credentials come from Server Env: a GitHub App (`VITEHUB_GITHUB_APP_ID` with
231
+ * `VITEHUB_GITHUB_PRIVATE_KEY`), else `VITEHUB_GITHUB_TOKEN`.
232
+ */
233
+ interface CommentsForgeOptions {
234
+ /** Only GitHub for now. */
235
+ provider: "github";
236
+ /** `owner/name`. Default: the repository of the build that served the thread's page. */
237
+ repository?: string;
238
+ /**
239
+ * The pull request of a thread. Default: the one the build names, else the open pull request whose head is the
240
+ * build's branch. Return `undefined` to keep the thread off GitHub.
241
+ */
242
+ pullRequest?: (thread: CommentThread) => number | undefined | Promise<number | undefined>;
243
+ /**
244
+ * The GitHub token of the person who wrote a message, such as the user token of their GitHub sign-in, so the
245
+ * comment posts as them. Without one, the GitHub App posts it with their name.
246
+ */
247
+ token?: (author: CommentUser) => string | undefined | Promise<string | undefined>;
248
+ /** The heading of the summary comment. Default `"Preview comments"`. */
249
+ title?: string;
250
+ /** GitHub Enterprise API base. Default `https://api.github.com`. */
251
+ apiUrl?: string;
252
+ fetch?: typeof fetch;
253
+ }
254
+ /**
255
+ * The request event of a Comments call: the Request of the Comments API, or the server event of an operation call.
256
+ * Read the request, its cookies, and the platform bindings from `event["~standard"]`. `context` is the H3 event
257
+ * context, when the call came through an H3 event.
258
+ */
259
+ type CommentsRequestEvent = ViteHubContext<{
260
+ context?: Record<string, unknown>;
261
+ }>;
262
+ interface CommentsIdentifyContext {
263
+ event: CommentsRequestEvent;
264
+ }
265
+ interface CommentsPageContext {
266
+ /** The page URL: the origin of the request and the normalized path, without query and hash. */
267
+ url: URL;
268
+ event: CommentsRequestEvent;
269
+ }
270
+ /** The subject of a page, and the version of the subject that new threads start on. */
271
+ interface CommentsPageSubject extends CommentSubject {
272
+ revision?: number;
273
+ }
274
+ interface DefineCommentsOptions extends CommentsDefinition {
275
+ /**
276
+ * Race the page tools session against rendering. Enable only if all tools and the account reader get equivalent
277
+ * inputs on the navigation and browser session request, and the host never caches the personalized HTML publicly.
278
+ * Default: false.
279
+ */
280
+ pageToolsSessionHandoff?: boolean;
281
+ /** Resolves the user of a request. Without it, Comments reads the ViteHub Auth session. Return `null` for anonymous. */
282
+ identify?: (context: CommentsIdentifyContext) => CommentsUser | null | undefined | Promise<CommentsUser | null | undefined>;
283
+ /** Name of the Database that stores comments. Defaults to the `default` Database, or the only one. */
284
+ database?: string;
285
+ /** Posts threads to the pull request that the page previews. */
286
+ forge?: CommentsForgeOptions;
287
+ /**
288
+ * The subject that the overlay comments on for a page, such as `{ kind: "drop", id, revision }`. The server decides:
289
+ * the overlay reads the subject from `/session`, and a new thread from the overlay must be on it. `authorize` still
290
+ * runs on the subject. Return `null` or `undefined` for the default, `{ kind: "page", id: url.pathname }`.
291
+ */
292
+ page?: (context: CommentsPageContext) => CommentsPageSubject | null | undefined | Promise<CommentsPageSubject | null | undefined>;
293
+ }
294
+ interface ListCommentThreadsOptions {
295
+ subject?: CommentSubject;
296
+ /** Only threads about this kind of subject, across all its ids. */
297
+ subjectKind?: string;
298
+ /** An app path. The same as a `page` subject. */
299
+ page?: string;
300
+ /** Only the threads of this numbering scope, such as `site`. */
301
+ scope?: string;
302
+ status?: CommentStatus;
303
+ /** Only threads started on this version of the subject or an earlier one. */
304
+ revision?: {
305
+ lte: number;
306
+ };
307
+ /** Newest activity first. Default 200, at most 500. */
308
+ limit?: number;
309
+ /** Where the next page starts: the `updatedAt` and `id` of the last thread of the page before. */
310
+ before?: CommentListCursor;
311
+ }
312
+ interface CreateCommentThreadInput {
313
+ /** What the thread is about. Or set `page`. */
314
+ subject?: CommentSubject;
315
+ /** An app path, for a thread on a page. The same as `subject: { kind: "page", id: page }`. */
316
+ page?: string;
317
+ /** Default `{ kind: "page" }`. */
318
+ anchor?: CommentAnchor;
319
+ context?: CommentContext;
320
+ metadata?: CommentMetadata;
321
+ /** The version of the subject, such as a document version. */
322
+ revision?: number;
323
+ /** A retry key. A second create with the same key and author in the same scope returns the first thread. */
324
+ requestId?: string;
325
+ body: string;
326
+ author: CommentUser;
327
+ /** Ids of the people that `body` names with `@`. */
328
+ mentions?: string[];
329
+ attachments?: string[];
330
+ }
331
+ interface EditCommentInput {
332
+ body: string;
333
+ /** Replaces the mentions. Default: none. */
334
+ mentions?: string[];
335
+ }
336
+ interface ReplyInput {
337
+ body: string;
338
+ author: CommentUser;
339
+ /** The agent replying on behalf of the author. */
340
+ actor?: CommentActor;
341
+ mentions?: string[];
342
+ attachments?: string[];
343
+ /** A retry key. A second reply with the same key and author in the same thread returns the first message. */
344
+ requestId?: string;
345
+ }
346
+ interface FindCommentThreadInput {
347
+ /** The subject that the create named. Or set `page`. */
348
+ subject?: CommentSubject;
349
+ /** An app path, for a thread on a page. */
350
+ page?: string;
351
+ requestId: string;
352
+ }
353
+ interface ReplyOptions {
354
+ /** Reply to a resolved thread, and keep it resolved. Default `false`: the reply fails with `COMMENTS_RESOLVED`. */
355
+ allowResolved?: boolean;
356
+ }
357
+ /** Codes of the errors that Comments methods return in the `[error, data]` tuple. */
358
+ type CommentsErrorCode = "COMMENTS_NOT_INSTALLED" | "COMMENTS_NOT_FOUND" | "COMMENTS_INVALID_INPUT" | "COMMENTS_FORBIDDEN" | "COMMENTS_POLICY_MISSING" | "COMMENTS_RESOLVED" | "COMMENTS_CONTENT_MISSING" | "COMMENTS_FIELD_INVALID" | "COMMENTS_FIELD_NOT_EDITABLE" | "COMMENTS_FIELD_FORBIDDEN" | "COMMENTS_FIELD_CONFLICT" | "COMMENTS_FIELD_LOCKED";
359
+ export { CommentsStoreAttachmentContext as A, CommentsDefinition as C, CommentsPolicyGate as D, CommentsPeopleSearchContext as E, validateCommentsDefinition as F, commentsRoleAllows as M, defaultPolicy as N, CommentsRateLimit as O, defineCommentSubject as P, CommentsCanMentionContext as S, CommentsPeople as T, CommentMessageEvent as _, CommentsPageContext as a, CommentsAuthorize as b, CreateCommentThreadInput as c, FindCommentThreadInput as d, ListCommentThreadsOptions as f, CommentMentionEvent as g, CommentAction as h, CommentsIdentifyContext as i, CommentsUser as j, CommentsReadAttachmentContext as k, DefineCommentsOptions as l, ReplyOptions as m, CommentsForgeOptions as n, CommentsPageSubject as o, ReplyInput as p, CommentsForgeTarget as r, CommentsRequestEvent as s, CommentsErrorCode as t, EditCommentInput as u, CommentSubjectDefinition as v, CommentsGitHubAccess as w, CommentsAuthorizeContext as x, CommentsAttachmentFile as y };
package/dist/vite.d.ts CHANGED
@@ -1,8 +1,8 @@
1
- import { a as CommentBuild } from "./types-BX3vH18p.js";
1
+ import { a as CommentBuild } from "./types-BmzTyGt-.js";
2
2
  import { n as OperationContributions } from "./operations-DFLer1fR.js";
3
3
  import { i as ViteHubInspectionPluginMetadata, r as ViteHubConsoleRuntimeRecordTableSection, t as ViteHubConsoleOperationSection } from "./console-CCLX_eIk.js";
4
- import "./types-l6GOb_yc.js";
5
- import { n as mountedCommentsRoute } from "./page-DE71P_gQ.js";
4
+ import "./types-VSVs4jIw.js";
5
+ import { s as mountedCommentsRoute } from "./page-DRM1j84-.js";
6
6
  import { Plugin, PluginOption } from "vite";
7
7
  import { githubRepository } from "@vite-hub/forge/build/node";
8
8
  import { DatabaseContributionContext, DatabaseContributionEntry } from "@vite-hub/database/vite";
@@ -68,8 +68,6 @@ interface CommentsImports {
68
68
  blob: string;
69
69
  /** Exports `checkRateLimit`, which counts guest writes when Rate Limit counts in a shared KV store. */
70
70
  rateLimit: string;
71
- /** `@vite-hub/webhooks`: the member endpoints that `defineComments({ send })` delivers to. */
72
- webhooks: string;
73
71
  }
74
72
  /** Options of `comments()`, for apps that use Comments without `vite-hub`. */
75
73
  interface CommentsOptions {
@@ -172,15 +170,6 @@ type CommentsVitePlugin$1 = Plugin & {
172
170
  };
173
171
  vitehub: ViteHubInspectionPluginMetadata & {
174
172
  databases: (context: DatabaseContributionContext) => Promise<DatabaseContributionEntry[]>;
175
- /** Turns on the member endpoints of Webhooks while `defineComments({ send })` is on. */
176
- webhooks: (context: {
177
- root?: string;
178
- projectRoot?: string;
179
- serverDirs?: readonly string[];
180
- }) => Promise<{
181
- memberEndpoints: true;
182
- reason: string;
183
- } | undefined>;
184
173
  };
185
174
  };
186
175
  /**
@@ -188,11 +177,6 @@ type CommentsVitePlugin$1 = Plugin & {
188
177
  * default or only Database.
189
178
  */
190
179
  export declare function readCommentsDatabase(file: string): Promise<string | undefined>;
191
- /**
192
- * Whether `defineComments({ send })` turns Send on, read without running the file: Send is on unless `send` is missing
193
- * or `false`. A value known only at runtime counts as on, so the build adds the tables and the member endpoints.
194
- */
195
- export declare function readCommentsSend(file: string): Promise<boolean>;
196
180
  /** The directory of the prebuilt overlay script in this package. */
197
181
  export declare function commentsOverlayDirectory(): string;
198
182
  /**
@@ -229,7 +213,6 @@ export declare function renderCommentsPlugin(input: {
229
213
  development?: boolean;
230
214
  build?: CommentBuild;
231
215
  base?: string;
232
- send?: boolean;
233
216
  realtime?: boolean;
234
217
  }): string;
235
218
  /**
package/dist/vite.js CHANGED
@@ -1,10 +1,10 @@
1
1
  import { t as invariant } from "./invariant-CmdvZ3vp.js";
2
- import { c as validateCommentsDefinition } from "./define-BqPcuDhf.js";
3
- import { t as commentsErrorDiagnostics } from "./errors-CBvIpwbo.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-BNw-aWEH.js";
2
+ import { c as validateCommentsDefinition } from "./define-hs9Z38io.js";
3
+ import { t as commentsErrorDiagnostics } from "./errors-DeSEHzRf.js";
4
+ import { a as viteHubPageSessionPath, l as viteHubPageToolsInlineScript, o as viteHubPageToolsAssets, p as viteHubPageToolsQuery, r as viteHubBasePath, s as viteHubPageToolsCookie } from "./page-tools-shared-BCdvqA4S.js";
5
5
  import { n as isRecordOrFunction } from "./object-CAK6UYR5.js";
6
- import { a as commentsRealtimeDefinition, o as commentsRoute, r as commentsNoticeDefinition, s as mountedCommentsRoute } from "./page-2NzFladc.js";
7
- import { n as commentsTableNames, t as commentSendsTableNames } from "./table-names-BIHjuEFK.js";
6
+ import { f as mountedCommentsRoute, i as commentsNoticeDefinition, o as commentsRealtimeDefinition, s as commentsRoute } from "./page-CJz1K67L.js";
7
+ import { t as commentsTableNames } from "./table-names-DUmWROM4.js";
8
8
  import { formatDiagnostic } from "nostics";
9
9
  import { existsSync, mkdirSync, statSync, writeFileSync } from "node:fs";
10
10
  import { tmpdir } from "node:os";
@@ -313,7 +313,7 @@ function addViteHubPageToolRoutes(kit, options) {
313
313
  });
314
314
  kit.config.publicAssets = assets;
315
315
  }
316
- function readString(value, key) {
316
+ function readStringField(value, key) {
317
317
  const field = value !== null && typeof value === "object" ? Reflect.get(value, key) : void 0;
318
318
  return typeof field === "string" ? field : void 0;
319
319
  }
@@ -324,16 +324,16 @@ function readString(value, key) {
324
324
  * `nitro.baseURL`, else `NITRO_APP_BASE_URL`.
325
325
  */
326
326
  function viteHubPageToolsBase(config, env = process.env) {
327
- const defined = readString(config !== null && typeof config === "object" ? Reflect.get(config, "define") : void 0, "__VITEHUB_APP_BASE_URL__");
328
- const viteBase = readString(config, "base");
327
+ const defined = readStringField(config !== null && typeof config === "object" ? Reflect.get(config, "define") : void 0, "__VITEHUB_APP_BASE_URL__");
328
+ const viteBase = readStringField(config, "base");
329
329
  let appBase = viteBase?.startsWith("/") && !viteBase.startsWith("//") ? viteBase : void 0;
330
330
  if (defined) try {
331
331
  const value = JSON.parse(defined);
332
332
  if (typeof value === "string") appBase = value;
333
333
  } catch {}
334
- const base = viteHubBasePath(readString(config, "__vitehubAppBaseURL") ?? appBase);
334
+ const base = viteHubBasePath(readStringField(config, "__vitehubAppBaseURL") ?? appBase);
335
335
  const nitro = config !== null && typeof config === "object" ? Reflect.get(config, "nitro") : void 0;
336
- const nitroBase = viteHubBasePath(readString(nitro, "baseURL") ?? env.NITRO_APP_BASE_URL);
336
+ const nitroBase = viteHubBasePath(readStringField(nitro, "baseURL") ?? env.NITRO_APP_BASE_URL);
337
337
  return {
338
338
  base,
339
339
  mount: nitroBase && (base === nitroBase || base.startsWith(`${nitroBase}/`)) ? base.slice(nitroBase.length) : base
@@ -413,16 +413,11 @@ function objectProperties(object) {
413
413
  value: unwrapExpression(node.value)
414
414
  });
415
415
  }
416
- /** The value of a template literal without substitutions. */
417
416
  function staticTemplate(node) {
418
417
  if (node.expressions.length) return dynamic;
419
418
  return node.quasis[0]?.value.cooked ?? dynamic;
420
419
  }
421
420
  const escapePattern = /\\(u\{[^}]*\}?|u[\s\S]{0,4}|x[\s\S]{0,2}|0\d|[\s\S])/g;
422
- /**
423
- * True when a string literal has an escape that strict mode code rejects. The parser recovers from some bad escapes
424
- * and accepts legacy octal escapes, so the scanner checks them again.
425
- */
426
421
  function hasInvalidEscape(raw) {
427
422
  for (const [, escape = ""] of raw.matchAll(escapePattern)) if (escape.startsWith("u{")) {
428
423
  const code = escape.slice(2, -1);
@@ -494,10 +489,6 @@ const runs = shared[runsKey] ??= /* @__PURE__ */ new Map();
494
489
  const startedKey = Symbol.for("vitehub.hints.started");
495
490
  const startedShared = globalThis;
496
491
  const started = startedShared[startedKey] ??= /* @__PURE__ */ new WeakSet();
497
- /**
498
- * The report of the ViteHub project root, where the other generated files go. A Nuxt app with `srcDir: "app"` has its
499
- * Vite root in `app/`, one folder below.
500
- */
501
492
  function hintsFile(config) {
502
493
  const projectRoot = Reflect.get(config, VITEHUB_PROJECT_ROOT);
503
494
  return resolve(typeof projectRoot === "string" ? projectRoot : resolveViteHubProjectRoot(config.root), viteHubHintsFile);
@@ -578,7 +569,6 @@ function flattenPlugins(option) {
578
569
  if (Array.isArray(option)) return option.flatMap(flattenPlugins);
579
570
  return option && typeof option === "object" && "name" in option ? [option] : [];
580
571
  }
581
- /** Whether the app added `nitro()` itself. Nitro plugins that a ViteHub package included do not count. */
582
572
  function findAppNitro(value) {
583
573
  if (Array.isArray(value)) return value.some(findAppNitro);
584
574
  return value !== null && typeof value === "object" && !isIncludedNitroPlugin(value) && Reflect.get(value, "name") === "nitro:main";
@@ -637,7 +627,6 @@ const forgeNames = [
637
627
  }
638
628
  ];
639
629
  const defaultDatabaseUrls = ["DATABASE_URL", "TURSO_DATABASE_URL"];
640
- /** `TURSO_DATABASE_URL` → `TURSO_AUTH_TOKEN`, as `authTokenVariable()` in `@vite-hub/database/connect`. */
641
630
  function databaseAuthTokenVariable(urlVariable) {
642
631
  const name = urlVariable.replace(/(?:_DATABASE)?_URL$/, "_AUTH_TOKEN");
643
632
  return name === urlVariable ? `${urlVariable}_AUTH_TOKEN` : name;
@@ -651,7 +640,6 @@ function entry(names, required, secret) {
651
640
  owners
652
641
  };
653
642
  }
654
- /** The database of `comments({ database })`: an `env:` variable and its token, or the default URL variables. */
655
643
  function standaloneDatabaseEntries(where, host) {
656
644
  const location = parseDatabaseLocation(where, "comments");
657
645
  if (location.kind === "env") return [entry([location.name], true, true), entry([databaseAuthTokenVariable(location.name)], false, true)];
@@ -733,8 +721,7 @@ const defaultImports = {
733
721
  contentClient: "@vite-hub/content/client",
734
722
  connect: "@vite-hub/comments/runtime/connect",
735
723
  blob: "@vite-hub/blob",
736
- rateLimit: "@vite-hub/rate-limit",
737
- webhooks: "@vite-hub/webhooks"
724
+ rateLimit: "@vite-hub/rate-limit"
738
725
  };
739
726
  function literalProperties(options) {
740
727
  return objectProperties(options).flatMap((property) => {
@@ -810,18 +797,6 @@ async function readCommentsDatabase(file) {
810
797
  if (found === null || found.value !== void 0 && typeof found.value !== "string") throw commentsErrorDiagnostics.COMMENTS_B0004({ file });
811
798
  return typeof found.value === "string" ? found.value : void 0;
812
799
  }
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
- }
824
- /** A directory of prebuilt browser scripts in this package. */
825
800
  function builtDirectory(name) {
826
801
  const here = dirname(fileURLToPath(import.meta.url));
827
802
  return here.endsWith("src") ? resolve(here, `../dist/${name}`) : resolve(here, name);
@@ -894,7 +869,6 @@ async function readCommentsComponents(root, limit = 5e3, resolvedComponents = []
894
869
  return components;
895
870
  }
896
871
  const version = "4";
897
- /** Generated lines that read the definition of `server/comments.ts`: its `comments` export, else its default export. */
898
872
  function definitionLines(definition, runtime) {
899
873
  return [
900
874
  `import * as definitionModule from ${JSON.stringify(pathToFileURL(definition).href)}`,
@@ -902,7 +876,6 @@ function definitionLines(definition, runtime) {
902
876
  `const comments = commentsDefinitionOf(definitionModule, ${JSON.stringify(definition)})`
903
877
  ];
904
878
  }
905
- /** Generated session reader: the ViteHub Auth user of a request. */
906
879
  function sessionLines(options, imports) {
907
880
  return options.auth ? {
908
881
  imports: [`import { commentsAuthSession } from ${JSON.stringify(imports.auth)}`],
@@ -912,7 +885,6 @@ function sessionLines(options, imports) {
912
885
  value: "undefined"
913
886
  };
914
887
  }
915
- /** The session reader of presence and MCP: the Auth user, else `githubLogin`, the person signed in with GitHub. */
916
888
  function sessionWithGitHubLines(options, imports, repository, base) {
917
889
  if (options.auth) return sessionLines(options, imports);
918
890
  const route = mountedCommentsRoute(base);
@@ -996,7 +968,6 @@ function renderCommentsPlugin(input) {
996
968
  ...input.session?.blob ? ["attachments: blob"] : [],
997
969
  ...input.session?.rateLimit ? ["rateLimit: checkRateLimit"] : [],
998
970
  ...postgres ? ["dialect: \"postgresql\"", "tables: { commentCounters: schema.vitehubCommentCounters, commentMessages: schema.vitehubCommentMessages, commentThreads: schema.vitehubCommentThreads, commentForge: schema.vitehubCommentForge }"] : [],
999
- ...input.send ? [`webhooks: () => import(${JSON.stringify(input.imports.webhooks)})`] : [],
1000
971
  ...realtime ? [realtime] : [],
1001
972
  `development: ${input.development === true}`,
1002
973
  `overlay: ${overlay}`,
@@ -1014,11 +985,9 @@ function pillSegmentLines(segments) {
1014
985
  value: `[${segments.map((segment, index) => `(nitroApp, context) => pillSegment${index}(nitroApp, { ...context, ...${JSON.stringify(segment.options ?? {})} })`).join(", ")}]`
1015
986
  };
1016
987
  }
1017
- /** The generated directory of Comments in a project. */
1018
988
  function generatedDirectory(projectRoot) {
1019
989
  return resolve(projectRoot, ".vitehub/nitro/comments");
1020
990
  }
1021
- /** `server/comments.ts` for an app without one: Comments with its defaults. */
1022
991
  async function writeDefaultDefinition(directory, imports) {
1023
992
  const file = join(directory, "definition.mjs");
1024
993
  const index = imports.runtime.replace(/\/runtime$/, "");
@@ -1032,11 +1001,6 @@ async function writeDefaultDefinition(directory, imports) {
1032
1001
  ].join("\n"));
1033
1002
  return file;
1034
1003
  }
1035
- /**
1036
- * The storage of `comments()`. A build connects to the `database` option, else to what it finds at runtime. The
1037
- * development server uses `.vitehub/data/comments.sqlite`, unless the option is a file, or a variable that is set. In
1038
- * workerd, which cannot open files, it uses the option, else a D1 binding that Miniflare keeps in `.wrangler/state`.
1039
- */
1040
1004
  async function standaloneDatabase(projectRoot, options, command, workerd) {
1041
1005
  const where = options.database || void 0;
1042
1006
  const location = parseDatabaseLocation(where, "comments", { node: command !== "serve" || !workerd });
@@ -1066,10 +1030,6 @@ async function standaloneDatabase(projectRoot, options, command, workerd) {
1066
1030
  node: true
1067
1031
  };
1068
1032
  }
1069
- /**
1070
- * Adds the D1 binding of `database: "d1:NAME"` to the Wrangler config of the build, unless the app's Wrangler file has
1071
- * it. Without an id, `wrangler deploy` creates the database.
1072
- */
1073
1033
  async function addD1Binding(projectRoot, nitro, where) {
1074
1034
  if (!where?.startsWith("d1:")) return;
1075
1035
  const binding = where.slice(3);
@@ -1100,7 +1060,6 @@ async function addD1Binding(projectRoot, nitro, where) {
1100
1060
  }
1101
1061
  };
1102
1062
  }
1103
- /** Whether `vite-hub` is in the app, so Comments runs through `vitehub()` and not `comments()`. */
1104
1063
  function hasViteHubComments(config) {
1105
1064
  const find = (value) => {
1106
1065
  if (Array.isArray(value)) return value.some(find);
@@ -1260,7 +1219,6 @@ function hubComments$1(options = {}) {
1260
1219
  if (!definition && !options.enabled) return [];
1261
1220
  const database = options.database ?? (definition ? await readCommentsDatabase(definition) : void 0);
1262
1221
  const postgres = options.dialect === "postgresql";
1263
- const send = !postgres && definition !== void 0 && await readCommentsSend(definition);
1264
1222
  return [{
1265
1223
  ...database ? { database } : {},
1266
1224
  definition: postgres ? {
@@ -1274,25 +1232,7 @@ function hubComments$1(options = {}) {
1274
1232
  tables: commentsTableNames,
1275
1233
  name: "comments",
1276
1234
  reason: definition ? "Stores the comment threads of `server/comments.ts`." : "Stores the comment threads of `vitehub({ comments })`."
1277
- }, ...send ? [{
1278
- ...database ? { database } : {},
1279
- definition: {
1280
- export: "commentSendsSchema",
1281
- module: imports.database
1282
- },
1283
- dialect: "sqlite",
1284
- tables: commentSendsTableNames,
1285
- name: "comment-sends",
1286
- reason: "Keeps the sends and setup codes of `defineComments({ send })`."
1287
- }] : []];
1288
- },
1289
- async webhooks(context) {
1290
- if (options.standalone) return void 0;
1291
- const definition = findCommentsEntry$2(projectRoot ?? context.projectRoot ?? context.root ?? process.cwd(), serverDirs ?? context.serverDirs?.slice());
1292
- return definition && await readCommentsSend(definition) ? {
1293
- memberEndpoints: true,
1294
- reason: "Send hands each member's waiting comments to their own agent."
1295
- } : void 0;
1235
+ }];
1296
1236
  }
1297
1237
  },
1298
1238
  enforce: "pre",
@@ -1332,8 +1272,7 @@ function hubComments$1(options = {}) {
1332
1272
  build,
1333
1273
  base,
1334
1274
  development,
1335
- realtime,
1336
- send: !options.standalone && await readCommentsSend(definition)
1275
+ realtime
1337
1276
  };
1338
1277
  await Promise.all([
1339
1278
  writeFile(handler, renderCommentsHandler({
@@ -1356,6 +1295,7 @@ function hubComments$1(options = {}) {
1356
1295
  meta: { ...ownAccessRouteMeta },
1357
1296
  route: `${mount}${commentsRoute}/**`
1358
1297
  });
1298
+ kit.addPlugin(ownModule(import.meta.url, "runtime/client-request-plugin"), "start");
1359
1299
  kit.addPlugin(plugin);
1360
1300
  addViteHubPageToolRoutes(kit, {
1361
1301
  handler: pageToolsRoute,
@@ -1522,7 +1462,6 @@ function loaderUrl(mount, assets, options = {}) {
1522
1462
  }))}` : "";
1523
1463
  return `${mount}${overlayRoute}/${assets.loader}?f=${encodeURIComponent(assets.overlay)}${options.edit ? "&e=1" : ""}${options.session ? `&s=${options.session}` : ""}${filter}`;
1524
1464
  }
1525
- /** A nonce is base64 or base64url. Anything else is not put in a tag. */
1526
1465
  const safeNonce = /^[\w+/=-]+$/;
1527
1466
  function loaderTag(url, nonce) {
1528
1467
  return `<script type="module"${nonce && safeNonce.test(nonce) ? ` nonce="${nonce}"` : ""} src="${url.replaceAll("&", "&amp;").replaceAll("\"", "&quot;")}"><\/script>`;
@@ -1534,7 +1473,6 @@ function scriptNonce(policy) {
1534
1473
  const nonce = (directives.find(([name]) => name?.toLowerCase() === "script-src-elem") ?? directives.find(([name]) => name?.toLowerCase() === "script-src") ?? directives.find(([name]) => name?.toLowerCase() === "default-src"))?.map((source) => /^'nonce-([^']+)'$/.exec(source)?.[1]).find(Boolean);
1535
1474
  return nonce && safeNonce.test(nonce) ? nonce : void 0;
1536
1475
  }
1537
- /** Attribute values and their offsets in a complete tag, including unquoted values. Also serialized below. */
1538
1476
  function htmlAttributes(tag) {
1539
1477
  const start = /^<\/?[a-z][\w:-]*/i.exec(tag)?.[0].length ?? tag.length;
1540
1478
  const pattern = /([^\s"'<>/=]+)(?:\s*=\s*(?:"([^"]*)"|'([^']*)'|([^\s>]+)))?/g;
@@ -1549,7 +1487,6 @@ function htmlAttributes(tag) {
1549
1487
  });
1550
1488
  return attributes;
1551
1489
  }
1552
- /** Self-contained apart from htmlAttributes, so both can be serialized into the generated middleware. */
1553
1490
  function createHtmlScanner() {
1554
1491
  let raw = "";
1555
1492
  let comment = false;
@@ -1803,10 +1740,6 @@ function hubComments(options = {}) {
1803
1740
  logLevel: "silent"
1804
1741
  });
1805
1742
  validateCommentsDefinition(module.comments ?? module.default, display);
1806
- if (await readCommentsSend(entry)) {
1807
- if (liveOptions.dialect === "postgresql") throw commentsErrorDiagnostics.COMMENTS_SEND_POSTGRES();
1808
- if (!resolved.plugins.some((plugin) => plugin.name === "@vite-hub/webhooks/vite")) throw commentsErrorDiagnostics.COMMENTS_SEND_WEBHOOKS_OFF({ file: display });
1809
- }
1810
1743
  },
1811
1744
  vitehub: {
1812
1745
  ...live.vitehub,
@@ -1821,4 +1754,4 @@ function hubComments(options = {}) {
1821
1754
  }
1822
1755
  };
1823
1756
  }
1824
- 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 };
1757
+ 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 };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@vite-hub/comments",
3
- "version": "0.7.0",
3
+ "version": "0.9.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.7.0",
110
- "@vite-hub/forge": "0.7.0",
111
- "@vite-hub/realtime": "0.7.0",
112
- "@vite-hub/runtime": "0.7.0",
109
+ "@vite-hub/auth": "0.9.0",
110
+ "@vite-hub/forge": "0.9.0",
111
+ "@vite-hub/realtime": "0.9.0",
112
+ "@vite-hub/runtime": "0.9.0",
113
113
  "birpc": "^4.2.0",
114
114
  "confbox": "^0.3.2",
115
115
  "h3": "^2.0.8"
@@ -129,12 +129,12 @@
129
129
  "vitest": "5.1.0",
130
130
  "vue": "3.5.46",
131
131
  "@libsql/client": "^0.18.0",
132
- "@vite-hub/database": "0.7.0",
132
+ "@vite-hub/database": "0.9.0",
133
133
  "vite": "^8.3.8",
134
134
  "drizzle-orm": "1.0.0-rc.6"
135
135
  },
136
136
  "peerDependencies": {
137
- "@vite-hub/database": "0.7.0",
137
+ "@vite-hub/database": "0.9.0",
138
138
  "nitro": "3.0.261102-rc || ^3.0.261103-rc",
139
139
  "vite": ">=8.0.0",
140
140
  "drizzle-orm": "1.0.0-rc.5 || 1.0.0-rc.6 || ^1.0.0"
@@ -152,6 +152,6 @@
152
152
  "dev": "vp pack && vp build --config overlay.vite.config.ts && vp pack --watch --no-clean",
153
153
  "typecheck": "vp run --cache -t @vite-hub/comments#build && node ../../test/package-typecheck.mjs --noEmit -p ./tsconfig.json",
154
154
  "test": "vp run --cache -t @vite-hub/comments#build && vp test",
155
- "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 test/browser/controls.browser.mjs"
155
+ "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/controls.browser.mjs"
156
156
  }
157
157
  }