create-feedbax 0.2.0 → 0.2.2

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 (143) hide show
  1. package/README.md +17 -5
  2. package/dist/cli.js +2610 -291
  3. package/dist/index.js +2375 -200
  4. package/package.json +7 -7
  5. package/template/.feedbax-template.sha256 +1 -1
  6. package/template/.gitignore.template +1 -0
  7. package/template/.npmignore.template +1 -0
  8. package/template/.nvmrc +1 -0
  9. package/template/AGENTS.md +13 -0
  10. package/template/CONNECTED.md +418 -0
  11. package/template/README.md +97 -0
  12. package/template/components.json +1 -1
  13. package/template/eslint.config.mjs +23 -0
  14. package/template/feedbax-vite.ts +79 -0
  15. package/template/migrations/0001_connected.sql +6 -0
  16. package/template/migrations/0002_participation.sql +8 -0
  17. package/template/migrations/0003_images.sql +3 -0
  18. package/template/migrations/0004_followed_status.sql +9 -0
  19. package/template/migrations/0005_github.sql +4 -0
  20. package/template/migrations/0006_integration.sql +3 -0
  21. package/template/migrations/0007_ownership.sql +2 -0
  22. package/template/migrations/0008_integration_recovery.sql +5 -0
  23. package/template/migrations/0009_observed_history.sql +3 -0
  24. package/template/package.json +39 -34
  25. package/template/src/authorized-draft-post.tsx +1 -0
  26. package/template/src/changelog-page.tsx +63 -54
  27. package/template/src/changelog-runtime.ts +2 -1
  28. package/template/src/cloudflare-workers.d.ts +9 -0
  29. package/template/src/comment-creation.test.tsx +95 -7
  30. package/template/src/comment-thread-page.ts +11 -1
  31. package/template/src/components/command-palette.tsx +59 -30
  32. package/template/src/components/connected-identity-provider.tsx +135 -0
  33. package/template/src/components/device-profile-provider.tsx +41 -26
  34. package/template/src/components/follow-post-button.tsx +78 -0
  35. package/template/src/components/header.tsx +2 -0
  36. package/template/src/components/image-attachments.tsx +187 -0
  37. package/template/src/components/loader.tsx +48 -5
  38. package/template/src/components/notification-inbox.tsx +232 -0
  39. package/template/src/components/portal-footer.tsx +14 -0
  40. package/template/src/components/post-history.tsx +101 -0
  41. package/template/src/components/profile-menu.tsx +37 -0
  42. package/template/src/components/ui/components/command.tsx +30 -29
  43. package/template/src/components/ui/components/message-scroller.tsx +2 -2
  44. package/template/src/components/ui/components/scroll-area.tsx +0 -1
  45. package/template/src/components/ui/components/switch.tsx +29 -0
  46. package/template/src/components/ui/styles/globals.css +1 -1
  47. package/template/src/configured-feedback.test.ts +82 -0
  48. package/template/src/configured-feedback.ts +61 -0
  49. package/template/src/connected-identity.test.ts +148 -0
  50. package/template/src/connected-identity.ts +127 -0
  51. package/template/src/connected-participation.test.tsx +67 -0
  52. package/template/src/connected-runtime.test.ts +244 -0
  53. package/template/src/connected-runtime.ts +176 -0
  54. package/template/src/connected-social.test.tsx +158 -0
  55. package/template/src/feedback-cache-invalidation.ts +3 -0
  56. package/template/src/feedback-runtime.ts +123 -13
  57. package/template/src/feedbax/changelog/index.test.ts +35 -0
  58. package/template/src/feedbax/changelog/index.ts +5 -1
  59. package/template/src/feedbax/changelog/notion-changelog.test.ts +1 -1
  60. package/template/src/feedbax/changelog/notion-changelog.ts +1 -1
  61. package/template/src/feedbax/config/index.test.ts +73 -1
  62. package/template/src/feedbax/config/index.ts +205 -9
  63. package/template/src/feedbax/feedback/comment-storage.ts +38 -0
  64. package/template/src/feedbax/feedback/connected-feedback.ts +235 -0
  65. package/template/src/feedbax/feedback/connected.test.ts +272 -0
  66. package/template/src/feedbax/feedback/connected.ts +225 -0
  67. package/template/src/feedbax/feedback/email-delivery.test.ts +65 -0
  68. package/template/src/feedbax/feedback/email-delivery.ts +66 -0
  69. package/template/src/feedbax/feedback/feedback-storage.ts +1 -0
  70. package/template/src/feedbax/feedback/github-comments.ts +390 -0
  71. package/template/src/feedbax/feedback/github-feedback.test.ts +1138 -0
  72. package/template/src/feedbax/feedback/github-feedback.ts +581 -0
  73. package/template/src/feedbax/feedback/github-request.ts +120 -0
  74. package/template/src/feedbax/feedback/github-service-client.ts +56 -0
  75. package/template/src/feedbax/feedback/identity-handoff.test.ts +81 -0
  76. package/template/src/feedbax/feedback/identity-handoff.ts +119 -0
  77. package/template/src/feedbax/feedback/image-feedback.ts +114 -0
  78. package/template/src/feedbax/feedback/images.test.ts +223 -0
  79. package/template/src/feedbax/feedback/images.ts +350 -0
  80. package/template/src/feedbax/feedback/index.ts +226 -16
  81. package/template/src/feedbax/feedback/integration-auth.ts +138 -0
  82. package/template/src/feedbax/feedback/notion-comments.ts +2 -35
  83. package/template/src/feedbax/feedback/notion-image-review.ts +55 -0
  84. package/template/src/feedbax/feedback/observed-history.test.ts +150 -0
  85. package/template/src/feedbax/feedback/observed-history.ts +219 -0
  86. package/template/src/feedbax/feedback/ownership.ts +170 -0
  87. package/template/src/feedbax/feedback/participation.test.ts +653 -0
  88. package/template/src/feedbax/feedback/participation.ts +502 -0
  89. package/template/src/history-runtime.test.ts +80 -0
  90. package/template/src/history-runtime.ts +37 -0
  91. package/template/src/images-runtime.test.ts +133 -0
  92. package/template/src/images-runtime.ts +125 -0
  93. package/template/src/index.css +103 -440
  94. package/template/src/integration-runtime.test.ts +365 -0
  95. package/template/src/integration-runtime.ts +289 -0
  96. package/template/src/lazy-post-detail-overlay.tsx +13 -2
  97. package/template/src/my-feedback-page.test.tsx +152 -0
  98. package/template/src/my-feedback-page.tsx +398 -0
  99. package/template/src/my-feedback-runtime.test.ts +93 -0
  100. package/template/src/my-feedback-runtime.ts +154 -0
  101. package/template/src/overlay-post-detail.test.tsx +59 -8
  102. package/template/src/overlay-post-detail.tsx +20 -69
  103. package/template/src/participation-client.ts +63 -0
  104. package/template/src/participation-runtime.test.ts +35 -0
  105. package/template/src/participation-runtime.ts +255 -0
  106. package/template/src/portal-comments.ts +35 -5
  107. package/template/src/portal-feedback-form.tsx +29 -6
  108. package/template/src/portal-feedback-runtime.ts +3 -0
  109. package/template/src/portal-feedback-server-function.ts +6 -3
  110. package/template/src/portal-feedback-submission.ts +19 -0
  111. package/template/src/portal-server-entry.ts +13 -0
  112. package/template/src/post-creation-flow.tsx +2 -2
  113. package/template/src/post-detail-content.test.tsx +233 -0
  114. package/template/src/post-detail-content.tsx +162 -0
  115. package/template/src/post-detail-query.ts +34 -0
  116. package/template/src/post-results.tsx +1 -1
  117. package/template/src/public-cache-policy.test.ts +11 -4
  118. package/template/src/public-cache-policy.ts +1 -1
  119. package/template/src/public-feedback-index.tsx +9 -39
  120. package/template/src/public-feedback-page.test.tsx +65 -0
  121. package/template/src/public-feedback-page.ts +12 -1
  122. package/template/src/public-portal-error.tsx +1 -1
  123. package/template/src/public-post-detail-skeleton.tsx +54 -0
  124. package/template/src/public-post-detail.tsx +437 -271
  125. package/template/src/public-post-route.test.tsx +39 -3
  126. package/template/src/public-post-route.tsx +15 -28
  127. package/template/src/public-release-links.test.ts +120 -0
  128. package/template/src/public-release-links.ts +130 -0
  129. package/template/src/public-roadmap-route.test.tsx +38 -2
  130. package/template/src/public-roadmap-view.tsx +56 -23
  131. package/template/src/public-shell.test.tsx +26 -0
  132. package/template/src/routeTree.gen.ts +70 -3
  133. package/template/src/router.tsx +2 -0
  134. package/template/src/routes/__root.tsx +3 -5
  135. package/template/src/routes/email-preferences.tsx +77 -0
  136. package/template/src/routes/my-feedback.tsx +16 -0
  137. package/template/src/routes/submit.tsx +1 -1
  138. package/template/src/safe-public-failure.ts +3 -1
  139. package/template/src/server.ts +87 -2
  140. package/template/src/submission-intent.ts +26 -0
  141. package/template/src/trusted-feedback-handler.test.ts +1 -1
  142. package/template/src/vote-toggle.tsx +42 -9
  143. package/template/vite.config.ts +2 -0
@@ -0,0 +1,235 @@
1
+ import { createHash } from "node:crypto";
2
+ import {
3
+ type FeedbackModule,
4
+ type PublicPost,
5
+ PublicPostCursorError,
6
+ VoteEligibilityError,
7
+ recoverableComment,
8
+ CommentValidationError,
9
+ roadmapStatuses,
10
+ type PublicPostRoadmap,
11
+ } from "./index";
12
+ import type { ConnectedStore, VerifiedParticipant } from "./connected";
13
+
14
+ export function createConnectedFeedbackModule(
15
+ base: FeedbackModule,
16
+ store: ConnectedStore,
17
+ participant?: VerifiedParticipant,
18
+ ): FeedbackModule {
19
+ const enrich = async (post: PublicPost): Promise<PublicPost> => ({
20
+ ...post,
21
+ ...(post.voteCount !== undefined
22
+ ? { voteCount: (await store.voteState(post.slug)).voteCount }
23
+ : {}),
24
+ });
25
+ const enrichPage = async (posts: PublicPost[]) => {
26
+ const counts = await store.voteCounts(
27
+ posts
28
+ .filter((post) => post.voteCount !== undefined)
29
+ .map((post) => post.slug),
30
+ );
31
+ return posts.map((post) => ({
32
+ ...post,
33
+ ...(post.voteCount !== undefined
34
+ ? { voteCount: counts.get(post.slug) ?? 0 }
35
+ : {}),
36
+ }));
37
+ };
38
+ const authorizeComment = async (commentId: string) => {
39
+ const identity = requireParticipant();
40
+ const subject = await store.commentSubject(commentId);
41
+ if (subject && subject !== identity.subject)
42
+ throw new Error("This Comment belongs to another Participant.");
43
+ };
44
+ const requireParticipant = () => {
45
+ if (!participant) throw new Error("Sign in to participate.");
46
+ return participant;
47
+ };
48
+ const create = async (
49
+ input: Parameters<FeedbackModule["createComment"]>[0] & {
50
+ discussionId?: string;
51
+ },
52
+ ) => {
53
+ const identity = requireParticipant();
54
+ if (
55
+ input.submissionKey !== undefined &&
56
+ !/^[A-Za-z0-9_-]{43}$/.test(input.submissionKey)
57
+ )
58
+ throw new CommentValidationError("Comment intent is invalid.");
59
+ const command = {
60
+ ...input,
61
+ displayName: identity.displayName,
62
+ ...(input.submissionKey
63
+ ? {
64
+ submissionKey: createHash("sha256")
65
+ .update(
66
+ JSON.stringify([
67
+ "feedbax-verified-comment-v1",
68
+ identity.subject,
69
+ input.submissionKey,
70
+ ]),
71
+ )
72
+ .digest("base64url"),
73
+ }
74
+ : {}),
75
+ };
76
+ const comment = input.discussionId
77
+ ? await base.replyToCommentThread({
78
+ ...command,
79
+ discussionId: input.discussionId,
80
+ })
81
+ : await base.createComment(command);
82
+ // Stable provider intents retain their record for attribution recovery. Older adapters compensate best-effort; verification is returned only after the private write.
83
+ try {
84
+ await store.attributeComment(comment.id, identity);
85
+ } catch (error) {
86
+ if (!comment[recoverableComment])
87
+ await base
88
+ .deleteComment({ commentId: comment.id })
89
+ .catch(() => undefined);
90
+ throw error;
91
+ }
92
+ return Object.defineProperty(
93
+ {
94
+ ...comment,
95
+ author: {
96
+ kind: "participant" as const,
97
+ displayName: identity.displayName,
98
+ verified: true,
99
+ },
100
+ },
101
+ recoverableComment,
102
+ { value: comment[recoverableComment] },
103
+ );
104
+ };
105
+ const listPublicRoadmapPosts: FeedbackModule["listPublicRoadmapPosts"] =
106
+ async (query) => {
107
+ const page = await base.listPublicRoadmapPosts(query);
108
+ return { ...page, items: await enrichPage(page.items) };
109
+ };
110
+ return {
111
+ ...base,
112
+ async getPublicPost(slug) {
113
+ const post = await base.getPublicPost(slug);
114
+ return post ? enrich(post) : undefined;
115
+ },
116
+ async listPublicPosts(query = {}) {
117
+ if (query.sort === "new") {
118
+ const page = await base.listPublicPosts(query);
119
+ return { ...page, items: await enrichPage(page.items) };
120
+ }
121
+ // Rank the complete eligible set, not an already paginated Notion counter projection.
122
+ const { cursor, ...filters } = query;
123
+ const fingerprint = JSON.stringify(filters);
124
+ let offset = 0;
125
+ if (cursor) {
126
+ try {
127
+ const value = JSON.parse(Buffer.from(cursor, "base64url").toString());
128
+ if (
129
+ value.query !== fingerprint ||
130
+ !Number.isSafeInteger(value.offset) ||
131
+ value.offset < 0
132
+ )
133
+ throw new Error();
134
+ offset = value.offset;
135
+ } catch {
136
+ throw new PublicPostCursorError();
137
+ }
138
+ }
139
+ const all: PublicPost[] = [];
140
+ let next: string | undefined;
141
+ do {
142
+ const page = await base.listPublicPosts({
143
+ ...filters,
144
+ sort: "new",
145
+ cursor: next,
146
+ });
147
+ all.push(...(await enrichPage(page.items)));
148
+ next = page.nextCursor;
149
+ } while (next);
150
+ all.sort(
151
+ (a, b) =>
152
+ (b.voteCount ?? 0) - (a.voteCount ?? 0) ||
153
+ b.createdAt.getTime() - a.createdAt.getTime() ||
154
+ b.slug.localeCompare(a.slug),
155
+ );
156
+ return {
157
+ items: all.slice(offset, offset + 25),
158
+ ...(offset + 25 < all.length
159
+ ? {
160
+ nextCursor: Buffer.from(
161
+ JSON.stringify({ query: fingerprint, offset: offset + 25 }),
162
+ ).toString("base64url"),
163
+ }
164
+ : {}),
165
+ };
166
+ },
167
+ listPublicRoadmapPosts,
168
+ async getPublicPostRoadmap() {
169
+ return Object.fromEntries(
170
+ await Promise.all(
171
+ roadmapStatuses.map(async (status) => [
172
+ status,
173
+ await listPublicRoadmapPosts({ status }),
174
+ ]),
175
+ ),
176
+ ) as PublicPostRoadmap;
177
+ },
178
+ async changeVote(input) {
179
+ const identity = requireParticipant();
180
+ const post = await base.getPublicPost(input.slug);
181
+ if (!post || post.voteCount === undefined)
182
+ throw new VoteEligibilityError();
183
+ await store.setVote(
184
+ input.slug,
185
+ identity.subject,
186
+ input.intention === "add",
187
+ );
188
+ return {
189
+ slug: input.slug,
190
+ ...(await store.voteState(input.slug, identity.subject)),
191
+ };
192
+ },
193
+ async editComment(input) {
194
+ await authorizeComment(input.commentId);
195
+ const comment = await base.editComment(input);
196
+ return {
197
+ ...comment,
198
+ author: (await store.commentAuthor(comment.id)) ?? comment.author,
199
+ };
200
+ },
201
+ async deleteComment(input) {
202
+ await authorizeComment(input.commentId);
203
+ await base.deleteComment(input);
204
+ },
205
+ createComment: create,
206
+ replyToCommentThread: create,
207
+ async listCommentThreads(input) {
208
+ const page = await base.listCommentThreads(input);
209
+ const authors = await store.commentAuthors(
210
+ page.items.flatMap((thread) =>
211
+ thread.comments
212
+ .filter((comment) => comment.author.kind !== "product-team")
213
+ .map((comment) => comment.id),
214
+ ),
215
+ );
216
+ return {
217
+ ...page,
218
+ items: await Promise.all(
219
+ page.items.map(async (thread) => ({
220
+ ...thread,
221
+ comments: await Promise.all(
222
+ thread.comments.map(async (comment) => ({
223
+ ...comment,
224
+ author:
225
+ comment.author.kind === "product-team"
226
+ ? comment.author
227
+ : (authors.get(comment.id) ?? comment.author),
228
+ })),
229
+ ),
230
+ })),
231
+ ),
232
+ };
233
+ },
234
+ };
235
+ }
@@ -0,0 +1,272 @@
1
+ import { afterEach, expect, it } from "vitest";
2
+ import { Miniflare } from "miniflare";
3
+ import { existsSync } from "node:fs";
4
+ import { readFile } from "node:fs/promises";
5
+ import { createConnectedStore } from "./connected";
6
+
7
+ let runtime: Miniflare | undefined;
8
+ afterEach(async () => {
9
+ await runtime?.dispose();
10
+ });
11
+ async function migratedDatabase() {
12
+ runtime = new Miniflare({
13
+ modules: true,
14
+ script: "export default {fetch(){return new Response('ok')}}",
15
+ compatibilityDate: "2026-07-30",
16
+ d1Databases: ["DB"],
17
+ });
18
+ const binding = await runtime.getD1Database("DB");
19
+ await binding.exec(
20
+ (await readFile(
21
+ existsSync("apps/portal/migrations/0001_connected.sql")
22
+ ? "apps/portal/migrations/0001_connected.sql"
23
+ : "migrations/0001_connected.sql",
24
+ "utf8",
25
+ )) +
26
+ "\n" +
27
+ (await readFile(
28
+ existsSync("apps/portal/migrations/0002_participation.sql")
29
+ ? "apps/portal/migrations/0002_participation.sql"
30
+ : "migrations/0002_participation.sql",
31
+ "utf8",
32
+ )),
33
+ );
34
+ return binding;
35
+ }
36
+
37
+ it("persists one Vote per verified Participant across concurrent retries and browsers", async () => {
38
+ const binding = await migratedDatabase();
39
+ const store = createConnectedStore(binding);
40
+ await store.acceptIdentity({
41
+ subject: "alice",
42
+ displayName: "Alice",
43
+ nonce: "once",
44
+ sessionHash: "session",
45
+ expiresAt: Date.now() + 60000,
46
+ });
47
+ await Promise.all(
48
+ Array.from({ length: 8 }, () => store.setVote("post-1", "alice", true)),
49
+ );
50
+ expect(await store.voteState("post-1", "alice")).toEqual({
51
+ voteCount: 1,
52
+ voted: true,
53
+ });
54
+ const secondBrowser = createConnectedStore(binding);
55
+ expect(await secondBrowser.voteState("post-1", "alice")).toEqual({
56
+ voteCount: 1,
57
+ voted: true,
58
+ });
59
+ await secondBrowser.setVote("post-1", "alice", false);
60
+ await secondBrowser.setVote("post-1", "alice", false);
61
+ expect(await store.voteState("post-1", "alice")).toEqual({
62
+ voteCount: 0,
63
+ voted: false,
64
+ });
65
+ });
66
+ it("rejects replayed handoffs without replacing an existing Participant or creating a session", async () => {
67
+ const binding = await migratedDatabase();
68
+ const store = createConnectedStore(binding);
69
+ const input = {
70
+ subject: "alice",
71
+ displayName: "Alice",
72
+ nonce: "once",
73
+ sessionHash: "session",
74
+ expiresAt: 2000,
75
+ };
76
+ await store.acceptIdentity(input);
77
+ await expect(
78
+ store.acceptIdentity({
79
+ ...input,
80
+ displayName: "Changed",
81
+ sessionHash: "replay",
82
+ }),
83
+ ).rejects.toThrow();
84
+ expect(await store.session("session", 1500)).toEqual({
85
+ subject: "alice",
86
+ displayName: "Alice",
87
+ });
88
+ expect(await store.session("replay", 1500)).toBeUndefined();
89
+ expect(await store.session("session", 2000)).toBeUndefined();
90
+ await store.logout("session");
91
+ expect(await store.session("session", 1500)).toBeUndefined();
92
+ });
93
+
94
+ it("ranks by verified Votes and attributes only Comments with identity evidence", async () => {
95
+ const binding = await migratedDatabase();
96
+ const store = createConnectedStore(binding);
97
+ const alice = { subject: "alice", displayName: "Alice" };
98
+ await store.acceptIdentity({
99
+ ...alice,
100
+ nonce: "a",
101
+ sessionHash: "a",
102
+ expiresAt: Date.now() + 60000,
103
+ });
104
+ const { createFeedbackModule, createConnectedFeedbackModule } =
105
+ await import("./index");
106
+ const base = createFeedbackModule({
107
+ initialItems: [
108
+ {
109
+ id: "p1",
110
+ slug: "old-popular",
111
+ title: "Old",
112
+ description: "Old",
113
+ type: "Feature Request",
114
+ status: "Planned",
115
+ published: true,
116
+ createdAt: new Date(1000),
117
+ updatedAt: new Date(1000),
118
+ voteCount: 500,
119
+ },
120
+ {
121
+ id: "p2",
122
+ slug: "new",
123
+ title: "New",
124
+ description: "New",
125
+ type: "Feature Request",
126
+ status: "Planned",
127
+ published: true,
128
+ createdAt: new Date(2000),
129
+ updatedAt: new Date(2000),
130
+ voteCount: 0,
131
+ },
132
+ {
133
+ id: "private",
134
+ slug: "private",
135
+ title: "Private",
136
+ description: "Private",
137
+ type: "Feature Request",
138
+ status: "New",
139
+ published: false,
140
+ createdAt: new Date(2000),
141
+ updatedAt: new Date(2000),
142
+ voteCount: 0,
143
+ },
144
+ ],
145
+ initialComments: [
146
+ {
147
+ id: "old",
148
+ postId: "p1",
149
+ discussionId: "thread",
150
+ body: "Old",
151
+ author: { kind: "participant", displayName: "Unverified Alice" },
152
+ createdAt: new Date(1000),
153
+ resolved: false,
154
+ },
155
+ {
156
+ id: "team",
157
+ postId: "p1",
158
+ discussionId: "thread",
159
+ body: "Team",
160
+ author: { kind: "product-team", displayName: "Product Team" },
161
+ createdAt: new Date(2000),
162
+ resolved: false,
163
+ },
164
+ {
165
+ id: "resolved",
166
+ postId: "p1",
167
+ discussionId: "resolved",
168
+ body: "Hidden",
169
+ author: { kind: "product-team", displayName: "Product Team" },
170
+ createdAt: new Date(2000),
171
+ resolved: true,
172
+ },
173
+ ],
174
+ });
175
+ const signedIn = createConnectedFeedbackModule(base, store, alice);
176
+ const publicRead = createConnectedFeedbackModule(base, store);
177
+ expect((await publicRead.getPublicPost("old-popular"))?.voteCount).toBe(0);
178
+ await signedIn.changeVote({ slug: "old-popular", intention: "add" });
179
+ expect(
180
+ (await publicRead.listPublicPosts({ sort: "top" })).items.map(
181
+ (p) => p.slug,
182
+ ),
183
+ ).toEqual(["old-popular", "new"]);
184
+ expect(
185
+ (await publicRead.listPublicPosts({ sort: "new" })).items.map(
186
+ (p) => p.slug,
187
+ ),
188
+ ).toEqual(["new", "old-popular"]);
189
+ await expect(
190
+ signedIn.changeVote({ slug: "private", intention: "add" }),
191
+ ).rejects.toThrow();
192
+ await expect(
193
+ publicRead.changeVote({ slug: "new", intention: "add" }),
194
+ ).rejects.toThrow("Sign in");
195
+ const comment = await signedIn.createComment({
196
+ slug: "old-popular",
197
+ body: "Hello",
198
+ displayName: "Spoofed Admin",
199
+ });
200
+ expect(comment.author).toEqual({
201
+ kind: "participant",
202
+ displayName: "Alice",
203
+ verified: true,
204
+ });
205
+ const comments = (
206
+ await publicRead.listCommentThreads({ slug: "old-popular" })
207
+ ).items.flatMap((t) => t.comments);
208
+ expect(comments.find((c) => c.id === "old")?.author).toEqual({
209
+ kind: "participant",
210
+ displayName: "Unverified Alice",
211
+ });
212
+ expect(comments.find((c) => c.id === "team")?.author).toEqual({
213
+ kind: "product-team",
214
+ displayName: "Product Team",
215
+ });
216
+ expect(comments.some((c) => c.id === "resolved")).toBe(false);
217
+ expect(comments.find((c) => c.id === comment.id)?.author).toEqual(
218
+ comment.author,
219
+ );
220
+ expect(JSON.stringify(comments)).not.toContain('"subject"');
221
+ expect(
222
+ (await signedIn.editComment({ commentId: comment.id, body: "Edited" }))
223
+ .author,
224
+ ).toEqual(comment.author);
225
+ const other = createConnectedFeedbackModule(base, store, {
226
+ subject: "bob",
227
+ displayName: "Bob",
228
+ });
229
+ await expect(
230
+ other.editComment({ commentId: comment.id, body: "Impersonated" }),
231
+ ).rejects.toThrow();
232
+ });
233
+
234
+ it("keeps Top pagination at 25 Posts and binds cursors to their filters", async () => {
235
+ const store = createConnectedStore(await migratedDatabase());
236
+ const { createFeedbackModule, createConnectedFeedbackModule } =
237
+ await import("./index");
238
+ const base = createFeedbackModule({
239
+ initialItems: Array.from({ length: 26 }, (_, i) => ({
240
+ id: `id-${i}`,
241
+ slug: `post-${i}`,
242
+ title: `Post ${i}`,
243
+ description: "Description",
244
+ type: "Feature Request",
245
+ status: "Planned",
246
+ published: true,
247
+ createdAt: new Date(i * 1000),
248
+ updatedAt: new Date(i * 1000),
249
+ voteCount: 0,
250
+ })),
251
+ });
252
+ const feedback = createConnectedFeedbackModule(base, store);
253
+ const first = await feedback.listPublicPosts({ sort: "top" });
254
+ expect(first.items).toHaveLength(25);
255
+ expect(first.nextCursor).toBeTruthy();
256
+ const second = await feedback.listPublicPosts({
257
+ sort: "top",
258
+ cursor: first.nextCursor,
259
+ });
260
+ expect(second.items).toHaveLength(1);
261
+ expect(second.nextCursor).toBeUndefined();
262
+ expect(
263
+ new Set([...first.items, ...second.items].map((post) => post.slug)).size,
264
+ ).toBe(26);
265
+ await expect(
266
+ feedback.listPublicPosts({
267
+ sort: "top",
268
+ type: "Bug Report",
269
+ cursor: first.nextCursor,
270
+ }),
271
+ ).rejects.toThrow();
272
+ });