@vite-hub/comments 0.1.0 → 0.3.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 (87) hide show
  1. package/README.md +79 -31
  2. package/dist/anchor.d.ts +7 -4
  3. package/dist/anchor.js +10 -5
  4. package/dist/client-diagnostics-CcFpkbAk.js +40 -0
  5. package/dist/client.d.ts +78 -3
  6. package/dist/client.js +198 -13
  7. package/dist/{console-BIz9t2cO.d.ts → console-h4KlhIik.d.ts} +97 -8
  8. package/dist/context-BqIsmYP1.js +61 -0
  9. package/dist/database/postgres.d.ts +738 -347
  10. package/dist/database/postgres.js +28 -7
  11. package/dist/{database-Cb2xjC1V.d.ts → database-CA1aHKN7.d.ts} +675 -276
  12. package/dist/database.d.ts +6 -98
  13. package/dist/database.js +2 -3
  14. package/dist/define-43mMR39K.js +89 -0
  15. package/dist/define-B3TF9zzn.d.ts +204 -0
  16. package/dist/errors-4gelGVmK.js +57 -0
  17. package/dist/errors-C6qptPoG.js +135 -0
  18. package/dist/errors-CyQyKAvy.d.ts +185 -0
  19. package/dist/fold-name-B7Zb3-MF.js +7 -0
  20. package/dist/{identity-3qtVC4rF.js → identity-CBOzgxSf.js} +7 -2
  21. package/dist/index-DNhy69Wt.d.ts +83 -0
  22. package/dist/index.d.ts +7 -7
  23. package/dist/index.js +196 -5
  24. package/dist/install-BcMPgPk_.js +1154 -0
  25. package/dist/install-W9ghhGoh.d.ts +36 -0
  26. package/dist/installed-B-PfERBU.js +30 -0
  27. package/dist/invariant-D8_xBqmZ.js +22 -0
  28. package/dist/migrate-B0k_0swk.d.ts +54 -0
  29. package/dist/migrate-BDQ8xqUs.js +289 -0
  30. package/dist/object-Da1zyPCR.js +11 -0
  31. package/dist/{operations-0B0QTVWX.d.ts → operations-D4A1Fcgf.d.ts} +37 -15
  32. package/dist/operations-DMMIfYPW.js +1159 -0
  33. package/dist/operations-GLeOqgMt.d.ts +257 -0
  34. package/dist/operations.d.ts +3 -7
  35. package/dist/operations.js +3 -2
  36. package/dist/overlay/client-DmsSMOzi.js +4 -0
  37. package/dist/overlay/dist-BoHMOFax.js +14 -0
  38. package/dist/overlay/dist-yIZmvSaU.js +1 -0
  39. package/dist/overlay/overlay.js +183 -177
  40. package/dist/page/loader.js +138 -18
  41. package/dist/{page-BuroSMXO.js → page-B41ozN63.js} +8 -6
  42. package/dist/{page-BtXADR6d.d.ts → page-DtbMOEMd.d.ts} +6 -5
  43. package/dist/page-tools-shared-NHUjKI8E.js +117 -0
  44. package/dist/path--zk6PEMz.js +18 -0
  45. package/dist/plugin-PS8PMYus.js +74 -0
  46. package/dist/realtime.d.ts +6 -12
  47. package/dist/realtime.js +23 -24
  48. package/dist/rpc-HBcWtg0T.d.ts +17 -0
  49. package/dist/rpc-RKPAusHp.js +153 -0
  50. package/dist/rpc.d.ts +2 -29
  51. package/dist/rpc.js +2 -75
  52. package/dist/runtime/auth.d.ts +5 -3
  53. package/dist/runtime/auth.js +8 -5
  54. package/dist/runtime/console.d.ts +1 -1
  55. package/dist/runtime/console.js +26 -21
  56. package/dist/runtime/index.d.ts +108 -60
  57. package/dist/runtime/index.js +684 -236
  58. package/dist/{server-BomGg3Gb.js → server-D8k-0GXe.js} +16 -7
  59. package/dist/server.d.ts +14 -88
  60. package/dist/server.js +7 -326
  61. package/dist/service-CFVm23k7.d.ts +158 -0
  62. package/dist/service-GHhhyQj4.js +609 -0
  63. package/dist/session-DVx-1Tym.d.ts +14 -0
  64. package/dist/session-EkudzUmm.js +503 -0
  65. package/dist/testing.d.ts +1 -1
  66. package/dist/testing.js +14 -2
  67. package/dist/tokens-DSbwkVSy.js +58 -0
  68. package/dist/types-BIS0hCEl.d.ts +124 -0
  69. package/dist/types-CZujrMFd.d.ts +322 -0
  70. package/dist/vite.d.ts +91 -87
  71. package/dist/vite.js +535 -796
  72. package/package.json +24 -27
  73. package/dist/database-BSnVrwHn.js +0 -60
  74. package/dist/database-C-ktS9Do.js +0 -95
  75. package/dist/define-BzW2Ychn.d.ts +0 -46
  76. package/dist/define-Cbhl6QVJ.js +0 -32
  77. package/dist/errors-BAQYcy3_.d.ts +0 -89
  78. package/dist/errors-DeD6wTCl.js +0 -77
  79. package/dist/h3-v1-request-DDGXJ9E7.js +0 -166
  80. package/dist/index-DklG2Etf.d.ts +0 -111
  81. package/dist/operations-NZG5dB8y.js +0 -732
  82. package/dist/page-tools-shared-D-amu6sx.js +0 -53
  83. package/dist/plugin-QElKQYkA.js +0 -725
  84. package/dist/request-DVc3M_AG.js +0 -14
  85. package/dist/src-CRTwnaEG.js +0 -1362
  86. package/dist/types-Cj8K7Vx7.d.ts +0 -176
  87. package/dist/types-Un2dcJWD.d.ts +0 -288
package/dist/realtime.js CHANGED
@@ -1,4 +1,6 @@
1
- import { r as text } from "./identity-3qtVC4rF.js";
1
+ import { o as normalizeCommentPage, t as commentRoom } from "./page-B41ozN63.js";
2
+ import { i as text } from "./identity-CBOzgxSf.js";
3
+ import { n as resolveCommentsPage, t as resolveCommentsIdentity } from "./session-EkudzUmm.js";
2
4
  //#region src/realtime.ts
3
5
  function toRealtimeUser(user) {
4
6
  const result = { id: user.id };
@@ -12,36 +14,33 @@ function toRealtimeUser(user) {
12
14
  }
13
15
  /**
14
16
  * The Realtime Definition of the page presence rooms: who is on a page and where their cursor is. Rooms hold no
15
- * document; threads stay in the Database. Connections are read-only, and the server binds account presence to the user
16
- * that Comments resolves. Guests name themselves in the browser. ViteHub adds it as the `comments` definition when the
17
- * host has a room authority.
17
+ * document; threads stay in the Database. The server binds account presence to the user that Comments resolves.
18
+ * Guests name themselves in the browser. ViteHub adds it as the `comments` definition when the host has a room
19
+ * authority.
18
20
  */
19
21
  function commentsRealtime(comments, options = {}) {
20
22
  const readers = /* @__PURE__ */ new WeakMap();
21
23
  return {
22
24
  async identify({ event }) {
23
- const consoleUser = await options.consoleSession?.(event).catch(() => false);
24
- if (consoleUser === false) {
25
- readers.set(event, false);
26
- return null;
27
- }
28
- const user = comments.options.identify ? await comments.options.identify({ event }) : options.consoleSession ? consoleUser : await options.session?.(event).catch(() => null);
29
- readers.set(event, await comments.can({
30
- user: user ?? null,
31
- action: "read"
32
- }));
33
- return user && (comments.options.identify || user.guest !== true) ? toRealtimeUser(user) : null;
25
+ const identity = await resolveCommentsIdentity(comments, event, options);
26
+ readers.set(event, identity);
27
+ if (!identity.user) return null;
28
+ return comments.options.identify || identity.user.guest !== true ? toRealtimeUser(identity.user) : null;
34
29
  },
35
- authorize: ({ event, mode }) => mode === "read" && readers.get(event) === true,
36
- document: {
37
- kind: "comments",
38
- load: async () => ({
39
- body: "",
40
- digest: null
41
- }),
42
- save: async () => ({ digest: "comments" })
30
+ async authorize({ event, mode, documentId, request }) {
31
+ const identity = readers.get(event);
32
+ if (mode !== "read" || identity === void 0) return false;
33
+ const page = new URL(request.url).searchParams.get("page");
34
+ if (!page) return false;
35
+ if (documentId !== commentRoom(normalizeCommentPage(page))) return false;
36
+ const { subject } = await resolveCommentsPage(comments, event, request, page);
37
+ return await comments.can({
38
+ user: identity.user,
39
+ action: "read",
40
+ subject
41
+ }, identity.gate);
43
42
  },
44
- persistence: false
43
+ document: false
45
44
  };
46
45
  }
47
46
  //#endregion
@@ -0,0 +1,17 @@
1
+ import { E as CommentsTransport } from "./types-CZujrMFd.js";
2
+ //#region src/operations-core/rpc.d.ts
3
+ interface RpcTransportOptions {
4
+ /** The app origin and mount, such as `https://app.example.com` or `/portal`. Defaults to the page origin. */
5
+ base?: string;
6
+ /** Replaces `fetch`, for tests. */
7
+ fetch?: typeof fetch;
8
+ }
9
+ /**
10
+ * A transport over the operations RPC at `POST /_vitehub/rpc`, one birpc call for each request, for development only.
11
+ * A browser cannot sign Console calls, so it works on a development server with `console: { auth: false }` or without
12
+ * the `console` option. Pages of a production app use `createRestTransport()` from `@vite-hub/comments/client`. It has
13
+ * no `subscribe`: the client refreshes when the window gets focus.
14
+ */
15
+ declare function createRpcTransport(options?: RpcTransportOptions): CommentsTransport;
16
+ //#endregion
17
+ export { createRpcTransport as n, RpcTransportOptions as t };
@@ -0,0 +1,153 @@
1
+ import { i as commentsUnansweredError, t as commentsAnswerError } from "./client-diagnostics-CcFpkbAk.js";
2
+ import { n as isRecordOrFunction, t as isRecord } from "./object-Da1zyPCR.js";
3
+ import { createBirpc } from "birpc";
4
+ //#region ../internal/src/operation-rpc.ts
5
+ /** Path of the operation RPC under the app. Dev servers and deployed apps serve it the same way, one birpc call per POST. */
6
+ const operationRpcPath = "/_vitehub/rpc";
7
+ function text(value) {
8
+ return String(value) === value && value ? value : void 0;
9
+ }
10
+ /** Read an untrusted failure body. It keeps only the diagnostic fields, so a stack never passes through. */
11
+ function readOperationRpcError(value) {
12
+ if (!isRecord(value)) return void 0;
13
+ const code = text(value.code);
14
+ const message = text(value.message);
15
+ const status = value.status;
16
+ if (!code || !message || !Number.isInteger(status)) return void 0;
17
+ const failure = {
18
+ code,
19
+ message,
20
+ status: Number(status)
21
+ };
22
+ if (text(value.fix)) failure.fix = text(value.fix);
23
+ if (text(value.docs)) failure.docs = text(value.docs);
24
+ if (isRecord(value.details)) failure.details = value.details;
25
+ return failure;
26
+ }
27
+ /** Read one response message. */
28
+ function readOperationRpcReply(value) {
29
+ if (!isRecord(value) || value.t !== "s") return void 0;
30
+ const id = text(value.i);
31
+ if (Object.hasOwn(value, "e")) {
32
+ const error = readOperationRpcError(value.e);
33
+ return error ? {
34
+ t: "s",
35
+ ...id ? { i: id } : {},
36
+ e: error
37
+ } : void 0;
38
+ }
39
+ return id ? {
40
+ t: "s",
41
+ i: id,
42
+ r: value.r
43
+ } : void 0;
44
+ }
45
+ /**
46
+ * Call one operation with birpc over a request and answer transport, such as one HTTP POST per call. `send` posts the
47
+ * JSON message and returns the parsed answer; its own failures, such as a network error or an abort, reject.
48
+ */
49
+ async function callOperationRpc(name, input, send) {
50
+ let receive;
51
+ let answer;
52
+ const notReply = /* @__PURE__ */ new Error("The answer is not a reply to the operation call.");
53
+ const rpc = createBirpc({}, {
54
+ on: (listener) => {
55
+ receive = listener;
56
+ },
57
+ post: async (message) => {
58
+ answer = await send(JSON.stringify(message));
59
+ const reply = readOperationRpcReply(answer.body);
60
+ if (!reply || reply.i !== void 0 && reply.i !== message.i) throw notReply;
61
+ await receive({
62
+ ...reply,
63
+ i: message.i
64
+ });
65
+ },
66
+ proxify: false,
67
+ timeout: -1
68
+ });
69
+ try {
70
+ return {
71
+ ok: true,
72
+ value: await rpc.$call(name, ...input === void 0 ? [] : [input]),
73
+ answer
74
+ };
75
+ } catch (error) {
76
+ if (!answer) throw error;
77
+ if (error === notReply) return {
78
+ ok: false,
79
+ error: void 0,
80
+ answer
81
+ };
82
+ return {
83
+ ok: false,
84
+ error: readOperationRpcError(error),
85
+ answer
86
+ };
87
+ }
88
+ }
89
+ //#endregion
90
+ //#region src/operations-core/rpc.ts
91
+ /**
92
+ * A transport over the operations RPC at `POST /_vitehub/rpc`, one birpc call for each request, for development only.
93
+ * A browser cannot sign Console calls, so it works on a development server with `console: { auth: false }` or without
94
+ * the `console` option. Pages of a production app use `createRestTransport()` from `@vite-hub/comments/client`. It has
95
+ * no `subscribe`: the client refreshes when the window gets focus.
96
+ */
97
+ function createRpcTransport(options = {}) {
98
+ const base = (options.base ?? "").replace(/\/+$/, "");
99
+ async function call(operation, input) {
100
+ const send = options.fetch ?? globalThis.fetch;
101
+ let outcome;
102
+ try {
103
+ outcome = await callOperationRpc(operation, input, async (body) => {
104
+ const response = await send(`${base}${operationRpcPath}`, {
105
+ body,
106
+ cache: "no-store",
107
+ credentials: "same-origin",
108
+ headers: {
109
+ "content-type": "application/json",
110
+ "x-vitehub-console": "1"
111
+ },
112
+ method: "POST"
113
+ });
114
+ return {
115
+ body: await response.json().catch(() => void 0),
116
+ response
117
+ };
118
+ });
119
+ } catch (cause) {
120
+ throw commentsUnansweredError(0, cause);
121
+ }
122
+ if (outcome.ok) return outcome.value;
123
+ if (outcome.error) {
124
+ const { message, ...failure } = outcome.error;
125
+ throw commentsAnswerError({
126
+ ...failure,
127
+ why: message
128
+ });
129
+ }
130
+ const { body, response } = outcome.answer;
131
+ if (!isRecordOrFunction(body) || typeof body.code !== "string" || typeof body.message !== "string") throw commentsUnansweredError(response.status);
132
+ throw commentsAnswerError({
133
+ code: body.code,
134
+ status: typeof body.status === "number" ? body.status : response.status,
135
+ why: body.message,
136
+ ...typeof body.fix === "string" ? { fix: body.fix } : {},
137
+ ...isRecordOrFunction(body.details) ? { details: body.details } : {}
138
+ });
139
+ }
140
+ return {
141
+ create: (input) => call("comments.create", input),
142
+ delete: (input) => call("comments.delete", input),
143
+ edit: (input) => call("comments.edit", input),
144
+ get: (input) => call("comments.get", input),
145
+ list: (query) => call("comments.list", query),
146
+ reopen: (input) => call("comments.reopen", input),
147
+ reply: (input) => call("comments.reply", input),
148
+ resolve: (input) => call("comments.resolve", input),
149
+ users: (input) => call("comments.users", input)
150
+ };
151
+ }
152
+ //#endregion
153
+ export { createRpcTransport as t };
package/dist/rpc.d.ts CHANGED
@@ -1,29 +1,2 @@
1
- import { y as CommentsTransport } from "./types-Cj8K7Vx7.js";
2
- //#region src/operations-core/rpc.d.ts
3
- export interface RpcTransportOptions {
4
- /** The app origin and mount, such as `https://app.example.com` or `/portal`. Defaults to the page origin. */
5
- base?: string;
6
- /** Replaces `fetch`, for tests. */
7
- fetch?: typeof fetch;
8
- }
9
- /** A failed operation, with the fields that every ViteHub surface reports. */
10
- export declare class CommentsRpcError extends Error {
11
- readonly code: string;
12
- readonly fix?: string;
13
- readonly status: number;
14
- readonly details?: Record<string, unknown>;
15
- constructor(failure: {
16
- code: string;
17
- details?: Record<string, unknown>;
18
- fix?: string;
19
- message: string;
20
- status: number;
21
- });
22
- }
23
- /**
24
- * A transport over the operations RPC at `/_vitehub/rpc/__call`. The browser sends its session cookie, and the server
25
- * runs `console.authorize` and the `authorize` of `server/comments.ts`. It has no `subscribe`: the client refreshes
26
- * when the window gets focus.
27
- */
28
- export declare function createRpcTransport(options?: RpcTransportOptions): CommentsTransport;
29
- //#endregion
1
+ import { n as createRpcTransport, t as RpcTransportOptions } from "./rpc-HBcWtg0T.js";
2
+ export { RpcTransportOptions, createRpcTransport };
package/dist/rpc.js CHANGED
@@ -1,75 +1,2 @@
1
- //#region src/operations-core/rpc.ts
2
- /** A failed operation, with the fields that every ViteHub surface reports. */
3
- var CommentsRpcError = class extends Error {
4
- code;
5
- fix;
6
- status;
7
- details;
8
- constructor(failure) {
9
- super(failure.message);
10
- this.name = "CommentsRpcError";
11
- this.code = failure.code;
12
- this.status = failure.status;
13
- if (failure.fix) this.fix = failure.fix;
14
- if (failure.details) this.details = failure.details;
15
- }
16
- };
17
- function isRecord(value) {
18
- return value !== null && Object(value) === value && !Array.isArray(value);
19
- }
20
- /**
21
- * A transport over the operations RPC at `/_vitehub/rpc/__call`. The browser sends its session cookie, and the server
22
- * runs `console.authorize` and the `authorize` of `server/comments.ts`. It has no `subscribe`: the client refreshes
23
- * when the window gets focus.
24
- */
25
- function createRpcTransport(options = {}) {
26
- const base = (options.base ?? "").replace(/\/+$/, "");
27
- async function call(operation, input) {
28
- const send = options.fetch ?? globalThis.fetch;
29
- let response;
30
- try {
31
- response = await send(`${base}/_vitehub/rpc/__call`, {
32
- body: JSON.stringify({
33
- operation,
34
- input
35
- }),
36
- cache: "no-store",
37
- credentials: "same-origin",
38
- headers: {
39
- "content-type": "application/json",
40
- "x-vitehub-console": "1"
41
- },
42
- method: "POST"
43
- });
44
- } catch (cause) {
45
- throw new CommentsRpcError({
46
- code: "COMMENTS_R0013",
47
- fix: "Check the connection and try again.",
48
- message: `The request failed: ${cause instanceof Error ? cause.message : String(cause)}`,
49
- status: 0
50
- });
51
- }
52
- const body = await response.json().catch(() => void 0);
53
- if (isRecord(body) && body.ok === true) return body.value;
54
- throw new CommentsRpcError({
55
- code: isRecord(body) && typeof body.code === "string" ? body.code : "COMMENTS_R0013",
56
- message: isRecord(body) && typeof body.message === "string" ? body.message : `The server answered with HTTP ${response.status}.`,
57
- status: isRecord(body) && typeof body.status === "number" ? body.status : response.status,
58
- ...isRecord(body) && typeof body.fix === "string" ? { fix: body.fix } : {},
59
- ...isRecord(body) && isRecord(body.details) ? { details: body.details } : {}
60
- });
61
- }
62
- return {
63
- create: (input) => call("comments.create", input),
64
- delete: (input) => call("comments.delete", input),
65
- edit: (input) => call("comments.edit", input),
66
- get: (input) => call("comments.get", input),
67
- list: (query) => call("comments.list", query),
68
- reopen: (input) => call("comments.reopen", input),
69
- reply: (input) => call("comments.reply", input),
70
- resolve: (input) => call("comments.resolve", input),
71
- users: (input) => call("comments.users", input)
72
- };
73
- }
74
- //#endregion
75
- export { CommentsRpcError, createRpcTransport };
1
+ import { t as createRpcTransport } from "./rpc-RKPAusHp.js";
2
+ export { createRpcTransport };
@@ -1,6 +1,8 @@
1
- import { x as CommentsUser } from "../types-Un2dcJWD.js";
2
- import { H3Event } from "h3";
1
+ import { d as CommentsPeople, g as CommentsUser } from "../define-B3TF9zzn.js";
2
+ import { s as CommentsRequestEvent } from "../types-BIS0hCEl.js";
3
3
  //#region src/runtime/auth.d.ts
4
4
  /** The ViteHub Auth user of a request, or null. Generated Comments files pass it as `session` when the app has Auth. */
5
- export declare function commentsAuthSession(event: H3Event): Promise<CommentsUser | null>;
5
+ export declare function commentsAuthSession(event: CommentsRequestEvent): Promise<CommentsUser | null>;
6
+ /** The users of ViteHub Auth, for `@` suggestions. Generated Comments files pass it as `users` when the app has Auth. */
7
+ export declare const commentsAuthUsers: CommentsPeople;
6
8
  //#endregion
@@ -1,15 +1,18 @@
1
- import { t as requestOf } from "../request-DVc3M_AG.js";
2
- import { getAuthForRequest } from "@vite-hub/auth/server";
1
+ import { n as createAuthUsers } from "../server-D8k-0GXe.js";
2
+ import { getStandardContext } from "@vite-hub/runtime/internal/h3";
3
3
  //#region src/runtime/auth.ts
4
+ const authServer = () => import("@vite-hub/auth/server");
4
5
  /** The ViteHub Auth user of a request, or null. Generated Comments files pass it as `session` when the app has Auth. */
5
6
  async function commentsAuthSession(event) {
6
- const request = requestOf(event);
7
- const user = (await getAuthForRequest(request, void 0, event).api.getSession({ headers: request.headers }))?.user;
7
+ const request = getStandardContext(event).req;
8
+ const user = (await (await authServer()).useAuth(event).api.getSession({ headers: request.headers }))?.user;
8
9
  if (!user || typeof user !== "object" || !("id" in user) || typeof user.id !== "string") return null;
9
10
  return {
10
11
  ...user,
11
12
  id: user.id
12
13
  };
13
14
  }
15
+ /** The users of ViteHub Auth, for `@` suggestions. Generated Comments files pass it as `users` when the app has Auth. */
16
+ const commentsAuthUsers = createAuthUsers(async () => (await authServer()).getAuth());
14
17
  //#endregion
15
- export { commentsAuthSession };
18
+ export { commentsAuthSession, commentsAuthUsers };
@@ -1,4 +1,4 @@
1
- import { n as ViteHubConsoleRecord } from "../console-BIz9t2cO.js";
1
+ import { n as ViteHubConsoleRecord } from "../console-h4KlhIik.js";
2
2
  //#region src/runtime/console.d.ts
3
3
  /** The threads of the app as Console records: open threads first, each group newest activity first. It runs on each Console request. */
4
4
  export declare function readCommentsConsoleRecords(): Promise<ViteHubConsoleRecord[]>;
@@ -1,6 +1,6 @@
1
- import { o as describeCommentContext } from "../src-CRTwnaEG.js";
2
- import { n as commentsPageScope } from "../page-BuroSMXO.js";
3
- import { n as installedComments } from "../plugin-QElKQYkA.js";
1
+ import { n as commentsPageScope } from "../page-B41ozN63.js";
2
+ import { t as describeCommentContext } from "../context-BqIsmYP1.js";
3
+ import { n as installedComments } from "../plugin-PS8PMYus.js";
4
4
  //#region src/runtime/console.ts
5
5
  function excerpt(text) {
6
6
  const line = text.replace(/\s+/g, " ").trim();
@@ -10,46 +10,51 @@ function excerpt(text) {
10
10
  async function readCommentsConsoleRecords() {
11
11
  const comments = installedComments();
12
12
  if (!comments) return [];
13
- const [error, threads] = await comments.list({
13
+ const [error, listed] = await comments.list({
14
14
  scope: commentsPageScope,
15
+ subjectKind: "page",
15
16
  limit: 500
16
17
  });
17
18
  if (error) return [];
18
- return [...threads.filter((thread) => thread.status === "open"), ...threads.filter((thread) => thread.status !== "open")].map((thread) => {
19
- const first = thread.comments[0];
20
- const author = (name, guest) => guest ? `${name} (guest)` : name;
19
+ const threads = listed.filter((thread) => thread.subject.kind === "page");
20
+ const ordered = [...threads.filter((thread) => thread.status === "open"), ...threads.filter((thread) => thread.status !== "open")];
21
+ const author = (person) => `${person.name ?? person.id}${person.guest ? " (guest)" : ""}`;
22
+ return ordered.map((thread) => {
23
+ const first = thread.messages[0];
24
+ const page = thread.subject.id;
25
+ const { anchor } = thread;
21
26
  return {
22
27
  id: thread.id,
23
28
  cells: {
24
29
  comment: first ? excerpt(first.body) : "",
25
- page: `\`${thread.page}\``,
26
- author: author(thread.createdBy.name, thread.createdBy.guest),
27
- replies: String(Math.max(0, thread.comments.length - 1)),
30
+ page: `\`${page}\``,
31
+ author: author(thread.author),
32
+ replies: String(Math.max(0, thread.messages.length - 1)),
28
33
  status: thread.status === "open" ? "Open" : "Resolved",
29
- updated: thread.updatedAt
34
+ updated: new Date(thread.updatedAt).toISOString()
30
35
  },
31
36
  link: {
32
- href: `${thread.page}?vitehub=comments#comment-${thread.id}`,
37
+ href: `${page}?comment=${thread.n}`,
33
38
  label: "Open on page"
34
39
  },
35
- activity: thread.comments.map((comment) => ({
36
- author: author(comment.author.name, comment.author.guest),
37
- at: comment.createdAt,
38
- text: comment.body
40
+ activity: thread.messages.map((message) => ({
41
+ author: author(message.author),
42
+ at: new Date(message.createdAt).toISOString(),
43
+ text: message.body
39
44
  })),
40
45
  fields: [
41
46
  {
42
47
  label: "Page",
43
- value: thread.page
48
+ value: page
44
49
  },
45
- ...thread.anchor ? [{
50
+ ...anchor.kind === "element" ? [{
46
51
  label: "Anchor",
47
- value: thread.anchor.field ? `Content field ${thread.anchor.field}` : thread.anchor.label
52
+ value: anchor.field ? `Content field ${anchor.field}` : anchor.label ?? anchor.selector
48
53
  }] : [],
49
- ...describeCommentContext(thread.context),
54
+ ...describeCommentContext(thread.context ?? null),
50
55
  ...thread.resolvedBy ? [{
51
56
  label: "Resolved by",
52
- value: thread.resolvedBy.name
57
+ value: author(thread.resolvedBy)
53
58
  }] : []
54
59
  ]
55
60
  };