create-feedbax 0.1.0 → 0.2.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (251) hide show
  1. package/LICENSE +201 -21
  2. package/README.md +11 -1
  3. package/dist/cli.js +3283 -22
  4. package/dist/index.js +3394 -160
  5. package/package.json +40 -14
  6. package/template/.feedbax-template.sha256 +1 -0
  7. package/template/.gitignore.template +6 -0
  8. package/template/.npmignore.template +5 -0
  9. package/template/.prettierignore.template +4 -0
  10. package/template/AGENTS.md +13 -0
  11. package/template/CONNECTED.md +404 -0
  12. package/template/LICENSE +201 -0
  13. package/template/README.md +56 -5
  14. package/template/components.json +25 -0
  15. package/template/eslint.config.mjs +48 -0
  16. package/template/migrations/0001_connected.sql +6 -0
  17. package/template/migrations/0002_participation.sql +8 -0
  18. package/template/migrations/0003_images.sql +3 -0
  19. package/template/migrations/0004_followed_status.sql +9 -0
  20. package/template/package.json +74 -14
  21. package/template/public/feedbax-mark.svg +4 -0
  22. package/template/public/robots.txt +3 -0
  23. package/template/src/authorized-draft-post.test.tsx +212 -0
  24. package/template/src/authorized-draft-post.tsx +205 -0
  25. package/template/src/authorized-draft-query.ts +74 -0
  26. package/template/src/browser-post-state.test.ts +120 -0
  27. package/template/src/browser-post-state.ts +134 -0
  28. package/template/src/browser-vote-state.test.ts +14 -0
  29. package/template/src/browser-vote-state.ts +27 -0
  30. package/template/src/capability-authorization-error.ts +3 -0
  31. package/template/src/changelog-page.test.tsx +139 -0
  32. package/template/src/changelog-page.tsx +228 -0
  33. package/template/src/changelog-query.ts +13 -0
  34. package/template/src/changelog-runtime.ts +27 -0
  35. package/template/src/cloudflare-turnstile.ts +31 -0
  36. package/template/src/cloudflare-workers-test.ts +3 -0
  37. package/template/src/cloudflare-workers.d.ts +24 -0
  38. package/template/src/comment-creation.test.tsx +311 -0
  39. package/template/src/comment-profile.ts +5 -0
  40. package/template/src/comment-thread-page.ts +28 -0
  41. package/template/src/components/command-palette-context.tsx +71 -0
  42. package/template/src/components/command-palette.tsx +275 -0
  43. package/template/src/components/connected-identity-provider.tsx +108 -0
  44. package/template/src/components/create-post-trigger.tsx +44 -0
  45. package/template/src/components/device-profile-provider.tsx +324 -0
  46. package/template/src/components/follow-post-button.tsx +89 -0
  47. package/template/src/components/header.tsx +97 -0
  48. package/template/src/components/image-attachments.tsx +187 -0
  49. package/template/src/components/loader.tsx +53 -0
  50. package/template/src/components/notification-inbox.tsx +232 -0
  51. package/template/src/components/portal-footer.tsx +14 -0
  52. package/template/src/components/profile-menu.tsx +119 -0
  53. package/template/src/components/ui/components/alert-dialog.tsx +185 -0
  54. package/template/src/components/ui/components/attachment.tsx +207 -0
  55. package/template/src/components/ui/components/avatar.tsx +107 -0
  56. package/template/src/components/ui/components/badge.tsx +52 -0
  57. package/template/src/components/ui/components/bubble.tsx +128 -0
  58. package/template/src/components/ui/components/button-group.tsx +87 -0
  59. package/template/src/components/ui/components/button.tsx +56 -0
  60. package/template/src/components/ui/components/card.tsx +103 -0
  61. package/template/src/components/ui/components/checkbox.tsx +26 -0
  62. package/template/src/components/ui/components/command.tsx +195 -0
  63. package/template/src/components/ui/components/dialog.tsx +154 -0
  64. package/template/src/components/ui/components/drawer.tsx +229 -0
  65. package/template/src/components/ui/components/dropdown-menu.tsx +270 -0
  66. package/template/src/components/ui/components/empty.tsx +101 -0
  67. package/template/src/components/ui/components/field.tsx +236 -0
  68. package/template/src/components/ui/components/input-group.tsx +155 -0
  69. package/template/src/components/ui/components/input.tsx +20 -0
  70. package/template/src/components/ui/components/item.tsx +201 -0
  71. package/template/src/components/ui/components/kbd.tsx +26 -0
  72. package/template/src/components/ui/components/label.tsx +18 -0
  73. package/template/src/components/ui/components/marker.tsx +71 -0
  74. package/template/src/components/ui/components/message-scroller.tsx +128 -0
  75. package/template/src/components/ui/components/message.tsx +92 -0
  76. package/template/src/components/ui/components/native-select.tsx +65 -0
  77. package/template/src/components/ui/components/popover.tsx +88 -0
  78. package/template/src/components/ui/components/portal-primitives.test.tsx +85 -0
  79. package/template/src/components/ui/components/radio-group.tsx +36 -0
  80. package/template/src/components/ui/components/scroll-area.tsx +51 -0
  81. package/template/src/components/ui/components/secondary-form-actions.test.tsx +23 -0
  82. package/template/src/components/ui/components/select.tsx +199 -0
  83. package/template/src/components/ui/components/separator.tsx +23 -0
  84. package/template/src/components/ui/components/sheet.tsx +135 -0
  85. package/template/src/components/ui/components/skeleton.tsx +13 -0
  86. package/template/src/components/ui/components/sonner.tsx +43 -0
  87. package/template/src/components/ui/components/spinner.tsx +16 -0
  88. package/template/src/components/ui/components/switch.tsx +29 -0
  89. package/template/src/components/ui/components/tabs.tsx +80 -0
  90. package/template/src/components/ui/components/textarea.tsx +18 -0
  91. package/template/src/components/ui/components/tooltip.tsx +64 -0
  92. package/template/src/components/ui/hooks/.gitkeep +0 -0
  93. package/template/src/components/ui/lib/utils.ts +6 -0
  94. package/template/src/components/ui/styles/globals.css +151 -0
  95. package/template/src/connected-identity.test.ts +144 -0
  96. package/template/src/connected-identity.ts +122 -0
  97. package/template/src/connected-participation.test.tsx +67 -0
  98. package/template/src/connected-runtime.test.ts +241 -0
  99. package/template/src/connected-runtime.ts +176 -0
  100. package/template/src/connected-social.test.tsx +158 -0
  101. package/template/src/create-post-overlay.tsx +82 -0
  102. package/template/src/draft-post-list.tsx +39 -0
  103. package/template/src/feedback-cache-invalidation.test.ts +185 -0
  104. package/template/src/feedback-cache-invalidation.ts +98 -0
  105. package/template/src/feedback-runtime.ts +105 -0
  106. package/template/src/feedbax/changelog/index.test.ts +156 -0
  107. package/template/src/feedbax/changelog/index.ts +206 -0
  108. package/template/src/feedbax/changelog/notion-changelog.test.ts +395 -0
  109. package/template/src/feedbax/changelog/notion-changelog.ts +400 -0
  110. package/template/src/feedbax/config/index.test.ts +139 -0
  111. package/template/src/feedbax/config/index.ts +364 -0
  112. package/template/src/feedbax/feedback/connected-feedback.ts +206 -0
  113. package/template/src/feedbax/feedback/connected.test.ts +272 -0
  114. package/template/src/feedbax/feedback/connected.ts +215 -0
  115. package/template/src/feedbax/feedback/email-delivery.test.ts +65 -0
  116. package/template/src/feedbax/feedback/email-delivery.ts +66 -0
  117. package/template/src/feedbax/feedback/feedback-storage.ts +43 -0
  118. package/template/src/feedbax/feedback/identity-handoff.test.ts +81 -0
  119. package/template/src/feedbax/feedback/identity-handoff.ts +119 -0
  120. package/template/src/feedbax/feedback/image-feedback.ts +101 -0
  121. package/template/src/feedbax/feedback/images.test.ts +223 -0
  122. package/template/src/feedbax/feedback/images.ts +324 -0
  123. package/template/src/feedbax/feedback/index.test.ts +900 -0
  124. package/template/src/feedbax/feedback/index.ts +996 -0
  125. package/template/src/feedbax/feedback/notion-comments.test.ts +171 -0
  126. package/template/src/feedbax/feedback/notion-comments.ts +231 -0
  127. package/template/src/feedbax/feedback/notion-data-source.test.ts +364 -0
  128. package/template/src/feedbax/feedback/notion-data-source.ts +458 -0
  129. package/template/src/feedbax/feedback/notion-feedback.test.ts +998 -0
  130. package/template/src/feedbax/feedback/notion-feedback.ts +651 -0
  131. package/template/src/feedbax/feedback/notion-image-review.ts +55 -0
  132. package/template/src/feedbax/feedback/notion-request.ts +74 -0
  133. package/template/src/feedbax/feedback/participation.test.ts +653 -0
  134. package/template/src/feedbax/feedback/participation.ts +502 -0
  135. package/template/src/feedbax.test-fixture.ts +64 -0
  136. package/template/src/feedbax.ts +69 -0
  137. package/template/src/images-runtime.test.ts +133 -0
  138. package/template/src/images-runtime.ts +125 -0
  139. package/template/src/index.css +1795 -0
  140. package/template/src/lazy-create-post-overlay.tsx +6 -0
  141. package/template/src/lazy-post-detail-overlay.tsx +21 -0
  142. package/template/src/masked-post-link.tsx +27 -0
  143. package/template/src/overlay-post-detail.test.tsx +181 -0
  144. package/template/src/overlay-post-detail.tsx +43 -0
  145. package/template/src/participation-client.ts +63 -0
  146. package/template/src/participation-runtime.test.ts +35 -0
  147. package/template/src/participation-runtime.ts +255 -0
  148. package/template/src/portal-comments.test.ts +375 -0
  149. package/template/src/portal-comments.ts +403 -0
  150. package/template/src/portal-features.test.tsx +150 -0
  151. package/template/src/portal-feedback-form.tsx +530 -0
  152. package/template/src/portal-feedback-runtime.test.ts +32 -0
  153. package/template/src/portal-feedback-runtime.ts +58 -0
  154. package/template/src/portal-feedback-server-function.ts +96 -0
  155. package/template/src/portal-feedback-submission.test.ts +307 -0
  156. package/template/src/portal-feedback-submission.ts +224 -0
  157. package/template/src/portal-head.ts +58 -0
  158. package/template/src/portal-server-entry.ts +68 -0
  159. package/template/src/portal-voting.test.ts +106 -0
  160. package/template/src/portal-voting.ts +149 -0
  161. package/template/src/post-badges.tsx +27 -0
  162. package/template/src/post-creation-flow.test.tsx +230 -0
  163. package/template/src/post-creation-flow.tsx +88 -0
  164. package/template/src/post-detail-content.test.tsx +233 -0
  165. package/template/src/post-detail-content.tsx +162 -0
  166. package/template/src/post-detail-overlay.test.tsx +114 -0
  167. package/template/src/post-detail-overlay.tsx +67 -0
  168. package/template/src/post-detail-query.ts +34 -0
  169. package/template/src/post-feed-controls.test.tsx +239 -0
  170. package/template/src/post-feed-controls.tsx +298 -0
  171. package/template/src/post-presentation.ts +37 -0
  172. package/template/src/post-queries.test.ts +158 -0
  173. package/template/src/post-queries.ts +26 -0
  174. package/template/src/post-results.tsx +165 -0
  175. package/template/src/public-cache-policy.test.ts +148 -0
  176. package/template/src/public-cache-policy.ts +119 -0
  177. package/template/src/public-cache-tags.ts +7 -0
  178. package/template/src/public-changelog-page.ts +15 -0
  179. package/template/src/public-changelog-server-function.ts +27 -0
  180. package/template/src/public-date.ts +11 -0
  181. package/template/src/public-failure-state.test.tsx +69 -0
  182. package/template/src/public-feedback-index.tsx +94 -0
  183. package/template/src/public-feedback-page.test.tsx +355 -0
  184. package/template/src/public-feedback-page.ts +86 -0
  185. package/template/src/public-feedback-server-function.ts +22 -0
  186. package/template/src/public-portal-error.tsx +27 -0
  187. package/template/src/public-post-detail-skeleton.tsx +54 -0
  188. package/template/src/public-post-detail.tsx +772 -0
  189. package/template/src/public-post-page.test.tsx +173 -0
  190. package/template/src/public-post-page.ts +15 -0
  191. package/template/src/public-post-route.test.tsx +250 -0
  192. package/template/src/public-post-route.tsx +158 -0
  193. package/template/src/public-post-server-function.ts +48 -0
  194. package/template/src/public-post-unavailable.tsx +10 -0
  195. package/template/src/public-roadmap-page.test.tsx +139 -0
  196. package/template/src/public-roadmap-page.ts +24 -0
  197. package/template/src/public-roadmap-route.test.tsx +254 -0
  198. package/template/src/public-roadmap-route.tsx +50 -0
  199. package/template/src/public-roadmap-server-function.ts +44 -0
  200. package/template/src/public-roadmap-view.tsx +411 -0
  201. package/template/src/public-shell.test.tsx +544 -0
  202. package/template/src/roadmap-query.ts +21 -0
  203. package/template/src/root-branding.test.ts +53 -0
  204. package/template/src/routeTree.gen.ts +177 -0
  205. package/template/src/routed-post-creation-form.tsx +28 -0
  206. package/template/src/router.tsx +27 -0
  207. package/template/src/routes/__root.tsx +114 -0
  208. package/template/src/routes/changelog.tsx +39 -0
  209. package/template/src/routes/email-preferences.tsx +77 -0
  210. package/template/src/routes/index.tsx +61 -0
  211. package/template/src/routes/p.$slug.tsx +16 -0
  212. package/template/src/routes/roadmap.tsx +11 -0
  213. package/template/src/routes/submit.tsx +28 -0
  214. package/template/src/safe-public-failure.ts +47 -0
  215. package/template/src/server.ts +151 -0
  216. package/template/src/similar-posts.tsx +45 -0
  217. package/template/src/submit-route.test.tsx +134 -0
  218. package/template/src/trusted-feedback-handler.test.ts +425 -0
  219. package/template/src/trusted-feedback-handler.ts +181 -0
  220. package/template/src/trusted-feedback-runtime.ts +17 -0
  221. package/template/src/turnstile-configuration.test.ts +37 -0
  222. package/template/src/turnstile-configuration.ts +19 -0
  223. package/template/src/use-media-query.ts +17 -0
  224. package/template/src/vote-toggle.test.tsx +171 -0
  225. package/template/src/vote-toggle.tsx +244 -0
  226. package/template/tsconfig.json +45 -0
  227. package/template/vite.config.ts +20 -0
  228. package/template/vitest.config.ts +4 -0
  229. package/template/vitest.setup.ts +3 -0
  230. package/template/wrangler.jsonc +35 -0
  231. package/dist/cli.d.ts +0 -3
  232. package/dist/cli.d.ts.map +0 -1
  233. package/dist/cli.js.map +0 -1
  234. package/dist/index.d.ts +0 -21
  235. package/dist/index.d.ts.map +0 -1
  236. package/dist/index.js.map +0 -1
  237. package/template/.env.example +0 -4
  238. package/template/apps/portal/components.json +0 -20
  239. package/template/apps/portal/package.json +0 -31
  240. package/template/apps/portal/src/lib/utils.ts +0 -6
  241. package/template/apps/portal/src/routeTree.gen.ts +0 -59
  242. package/template/apps/portal/src/router.tsx +0 -10
  243. package/template/apps/portal/src/routes/__root.tsx +0 -31
  244. package/template/apps/portal/src/routes/index.tsx +0 -35
  245. package/template/apps/portal/src/styles.css +0 -91
  246. package/template/apps/portal/tsconfig.json +0 -15
  247. package/template/apps/portal/vite.config.ts +0 -13
  248. package/template/feedbax.config.ts +0 -13
  249. package/template/feedbax.jsonc +0 -11
  250. package/template/pnpm-workspace.yaml +0 -3
  251. package/template/turbo.json +0 -8
@@ -0,0 +1,151 @@
1
+ @import "tailwindcss";
2
+ @import "tw-animate-css";
3
+ @import "shadcn/tailwind.css";
4
+ @import "@fontsource-variable/geist";
5
+ @source "../../../**/*.{ts,tsx}";
6
+ @source "../**/*.{ts,tsx}";
7
+
8
+ @custom-variant dark (&:is(.dark *));
9
+
10
+ :root {
11
+ --background: oklch(1 0 0);
12
+ --foreground: oklch(0.145 0 0);
13
+ --card: oklch(1 0 0);
14
+ --card-foreground: oklch(0.145 0 0);
15
+ --popover: oklch(1 0 0);
16
+ --popover-foreground: oklch(0.145 0 0);
17
+ --primary: oklch(0.205 0 0);
18
+ --primary-foreground: oklch(0.985 0 0);
19
+ --secondary: oklch(0.97 0 0);
20
+ --secondary-foreground: oklch(0.205 0 0);
21
+ --muted: oklch(0.97 0 0);
22
+ --muted-foreground: oklch(0.556 0 0);
23
+ --accent: oklch(0.97 0 0);
24
+ --accent-foreground: oklch(0.205 0 0);
25
+ --destructive: oklch(0.577 0.245 27.325);
26
+ --border: oklch(0.922 0 0);
27
+ --input: oklch(0.922 0 0);
28
+ --ring: oklch(0.708 0 0);
29
+ --chart-1: oklch(0.87 0 0);
30
+ --chart-2: oklch(0.556 0 0);
31
+ --chart-3: oklch(0.439 0 0);
32
+ --chart-4: oklch(0.371 0 0);
33
+ --chart-5: oklch(0.269 0 0);
34
+ --status-planned: oklch(0.606 0.25 292.7);
35
+ --status-in-progress: oklch(0.623 0.214 259.8);
36
+ --status-shipped: oklch(0.723 0.219 149.6);
37
+ --changelog-new: oklch(0.55 0.17 255);
38
+ --changelog-improved: oklch(0.58 0.16 80);
39
+ --radius: 0.625rem;
40
+ --sidebar: oklch(0.985 0 0);
41
+ --sidebar-foreground: oklch(0.145 0 0);
42
+ --sidebar-primary: oklch(0.205 0 0);
43
+ --sidebar-primary-foreground: oklch(0.985 0 0);
44
+ --sidebar-accent: oklch(0.97 0 0);
45
+ --sidebar-accent-foreground: oklch(0.205 0 0);
46
+ --sidebar-border: oklch(0.922 0 0);
47
+ --sidebar-ring: oklch(0.708 0 0);
48
+ }
49
+
50
+ .dark {
51
+ --background: oklch(0.16 0.009 258);
52
+ --foreground: oklch(0.985 0 0);
53
+ --card: oklch(0.205 0.011 258);
54
+ --card-foreground: oklch(0.985 0 0);
55
+ --popover: oklch(0.205 0.011 258);
56
+ --popover-foreground: oklch(0.985 0 0);
57
+ --primary: oklch(0.97 0 0);
58
+ --primary-foreground: oklch(0.205 0.011 258);
59
+ --secondary: oklch(0.269 0.011 258);
60
+ --secondary-foreground: oklch(0.985 0 0);
61
+ --muted: oklch(0.269 0.011 258);
62
+ --muted-foreground: oklch(0.708 0.008 258);
63
+ --accent: oklch(0.269 0.011 258);
64
+ --accent-foreground: oklch(0.985 0 0);
65
+ --destructive: oklch(0.704 0.191 22.216);
66
+ --border: oklch(1 0 0 / 10%);
67
+ --input: oklch(1 0 0 / 15%);
68
+ --ring: oklch(0.556 0 0);
69
+ --chart-1: oklch(0.87 0 0);
70
+ --chart-2: oklch(0.556 0 0);
71
+ --chart-3: oklch(0.439 0 0);
72
+ --chart-4: oklch(0.371 0 0);
73
+ --chart-5: oklch(0.269 0 0);
74
+ --status-planned: oklch(0.606 0.25 292.7);
75
+ --status-in-progress: oklch(0.623 0.214 259.8);
76
+ --status-shipped: oklch(0.723 0.219 149.6);
77
+ --changelog-new: oklch(0.72 0.15 255);
78
+ --changelog-improved: oklch(0.8 0.16 80);
79
+ --sidebar: oklch(0.205 0.011 258);
80
+ --sidebar-foreground: oklch(0.985 0 0);
81
+ --sidebar-primary: oklch(0.488 0.243 264.376);
82
+ --sidebar-primary-foreground: oklch(0.985 0 0);
83
+ --sidebar-accent: oklch(0.269 0.011 258);
84
+ --sidebar-accent-foreground: oklch(0.985 0 0);
85
+ --sidebar-border: oklch(1 0 0 / 10%);
86
+ --sidebar-ring: oklch(0.556 0 0);
87
+ }
88
+
89
+ @theme inline {
90
+ --font-sans: "Geist Variable", sans-serif;
91
+ --color-sidebar-ring: var(--sidebar-ring);
92
+ --color-sidebar-border: var(--sidebar-border);
93
+ --color-sidebar-accent-foreground: var(--sidebar-accent-foreground);
94
+ --color-sidebar-accent: var(--sidebar-accent);
95
+ --color-sidebar-primary-foreground: var(--sidebar-primary-foreground);
96
+ --color-sidebar-primary: var(--sidebar-primary);
97
+ --color-sidebar-foreground: var(--sidebar-foreground);
98
+ --color-sidebar: var(--sidebar);
99
+ --color-chart-5: var(--chart-5);
100
+ --color-status-planned: var(--status-planned);
101
+ --color-status-in-progress: var(--status-in-progress);
102
+ --color-status-shipped: var(--status-shipped);
103
+ --color-changelog-new: var(--changelog-new);
104
+ --color-changelog-improved: var(--changelog-improved);
105
+ --color-chart-4: var(--chart-4);
106
+ --color-chart-3: var(--chart-3);
107
+ --color-chart-2: var(--chart-2);
108
+ --color-chart-1: var(--chart-1);
109
+ --color-ring: var(--ring);
110
+ --color-input: var(--input);
111
+ --color-border: var(--border);
112
+ --color-destructive: var(--destructive);
113
+ --color-accent-foreground: var(--accent-foreground);
114
+ --color-accent: var(--accent);
115
+ --color-muted-foreground: var(--muted-foreground);
116
+ --color-muted: var(--muted);
117
+ --color-secondary-foreground: var(--secondary-foreground);
118
+ --color-secondary: var(--secondary);
119
+ --color-primary-foreground: var(--primary-foreground);
120
+ --color-primary: var(--primary);
121
+ --color-popover-foreground: var(--popover-foreground);
122
+ --color-popover: var(--popover);
123
+ --color-card-foreground: var(--card-foreground);
124
+ --color-card: var(--card);
125
+ --color-foreground: var(--foreground);
126
+ --color-background: var(--background);
127
+ --radius-sm: calc(var(--radius) - 4px);
128
+ --radius-md: calc(var(--radius) - 2px);
129
+ --radius-lg: var(--radius);
130
+ --radius-xl: calc(var(--radius) + 4px);
131
+ --radius-2xl: calc(var(--radius) + 8px);
132
+ --radius-3xl: calc(var(--radius) + 12px);
133
+ --radius-4xl: calc(var(--radius) + 16px);
134
+ --font-heading: var(--font-sans);
135
+ }
136
+
137
+ @layer base {
138
+ * {
139
+ @apply border-border outline-ring/50;
140
+ }
141
+ body {
142
+ @apply font-sans bg-background text-foreground;
143
+ }
144
+ html {
145
+ @apply font-sans;
146
+ color-scheme: light;
147
+ }
148
+ html.dark {
149
+ color-scheme: dark;
150
+ }
151
+ }
@@ -0,0 +1,144 @@
1
+ import { expect, it } from "vitest";
2
+ import { createConnectedIdentityHandler } from "./connected-identity";
3
+
4
+ it("starts sign-in with a secure browser challenge and never accepts a return URL", async () => {
5
+ const handler = createConnectedIdentityHandler({
6
+ siteUrl: "https://feedback.example",
7
+ loginUrl: "https://app.example/feedback-login",
8
+ issuer: "https://app.example",
9
+ secret: "identity-test-secret-at-least-32-characters",
10
+ store: undefined!,
11
+ });
12
+ const response = await handler(
13
+ new Request(
14
+ "https://feedback.example/internal/identity/start?returnTo=https://evil.example",
15
+ ),
16
+ );
17
+ expect(response.status).toBe(303);
18
+ const target = new URL(response.headers.get("location")!);
19
+ expect(target.origin).toBe("https://app.example");
20
+ expect(target.searchParams.get("state")?.length).toBeGreaterThan(30);
21
+ expect(target.searchParams.get("callback")).toBe(
22
+ "https://feedback.example/internal/identity/callback",
23
+ );
24
+ expect(response.headers.get("set-cookie")).toContain(
25
+ "HttpOnly; Secure; SameSite=None",
26
+ );
27
+ expect(response.headers.get("cache-control")).toBe("no-store");
28
+ });
29
+
30
+ it("exchanges a browser-bound handoff once, keeps identity private, and revokes sessions on logout", async () => {
31
+ const { Miniflare } = await import("miniflare");
32
+ const { readFile } = await import("node:fs/promises");
33
+ const { existsSync } = await import("node:fs");
34
+ const { createConnectedStore, signIdentityHandoff } =
35
+ await import("@feedbax/feedback");
36
+ const runtime = new Miniflare({
37
+ modules: true,
38
+ script: "export default {fetch(){return new Response('ok')}}",
39
+ compatibilityDate: "2026-07-30",
40
+ d1Databases: ["DB"],
41
+ });
42
+ try {
43
+ const db = await runtime.getD1Database("DB");
44
+ await db.exec(
45
+ (await readFile(
46
+ existsSync("apps/portal/migrations/0001_connected.sql")
47
+ ? "apps/portal/migrations/0001_connected.sql"
48
+ : "migrations/0001_connected.sql",
49
+ "utf8",
50
+ )) +
51
+ "\n" +
52
+ (await readFile(
53
+ existsSync("apps/portal/migrations/0002_participation.sql")
54
+ ? "apps/portal/migrations/0002_participation.sql"
55
+ : "migrations/0002_participation.sql",
56
+ "utf8",
57
+ )),
58
+ );
59
+ const secret = "identity-test-secret-at-least-32-characters";
60
+ const handler = createConnectedIdentityHandler({
61
+ siteUrl: "https://feedback.example",
62
+ loginUrl: "https://app.example/login",
63
+ issuer: "https://app.example",
64
+ secret,
65
+ store: createConnectedStore(db),
66
+ now: () => 1000000,
67
+ });
68
+ const started = await handler(
69
+ new Request("https://feedback.example/internal/identity/start"),
70
+ );
71
+ const challenge = started.headers.get("set-cookie")!.split(";")[0]!;
72
+ const state = new URL(started.headers.get("location")!).searchParams.get(
73
+ "state",
74
+ )!;
75
+ const token = signIdentityHandoff(
76
+ {
77
+ subject: "private-subject",
78
+ displayName: "Alice",
79
+ audience: "https://feedback.example",
80
+ issuer: "https://app.example",
81
+ state,
82
+ nonce: "nonce",
83
+ issuedAt: 1000,
84
+ expiresAt: 1100,
85
+ },
86
+ secret,
87
+ );
88
+ const callback = (cookie: string, origin = "https://app.example") =>
89
+ new Request("https://feedback.example/internal/identity/callback", {
90
+ method: "POST",
91
+ headers: {
92
+ Origin: origin,
93
+ Cookie: cookie,
94
+ "Content-Type": "application/x-www-form-urlencoded",
95
+ },
96
+ body: new URLSearchParams({ token }),
97
+ });
98
+ expect((await handler(callback(""))).status).toBe(401);
99
+ expect(
100
+ (await handler(callback(challenge, "https://evil.example"))).status,
101
+ ).toBe(403);
102
+ const signedIn = await handler(callback(challenge));
103
+ expect(signedIn.status).toBe(303);
104
+ expect((await handler(callback(challenge))).status).toBe(401);
105
+ const session = signedIn.headers
106
+ .getSetCookie()
107
+ .find((c) => c.startsWith("__Host-feedbax-session="))!
108
+ .split(";")[0]!;
109
+ const sessionRequest = () =>
110
+ new Request("https://feedback.example/internal/identity/session", {
111
+ headers: { Cookie: session },
112
+ });
113
+ const response = await handler(sessionRequest());
114
+ expect(response.headers.get("cache-control")).toBe("no-store");
115
+ expect(await response.json()).toEqual({
116
+ participant: { displayName: "Alice" },
117
+ });
118
+ expect(
119
+ (
120
+ await handler(
121
+ new Request("https://feedback.example/internal/identity/logout", {
122
+ method: "POST",
123
+ headers: { Cookie: session, Origin: "https://evil.example" },
124
+ }),
125
+ )
126
+ ).status,
127
+ ).toBe(403);
128
+ expect(
129
+ (
130
+ await handler(
131
+ new Request("https://feedback.example/internal/identity/logout", {
132
+ method: "POST",
133
+ headers: { Cookie: session, Origin: "https://feedback.example" },
134
+ }),
135
+ )
136
+ ).status,
137
+ ).toBe(200);
138
+ expect(await (await handler(sessionRequest())).json()).toEqual({
139
+ participant: null,
140
+ });
141
+ } finally {
142
+ await runtime.dispose();
143
+ }
144
+ });
@@ -0,0 +1,122 @@
1
+ import { createHash, randomBytes } from "node:crypto";
2
+ import { verifyIdentityHandoff, type ConnectedStore } from "@feedbax/feedback";
3
+
4
+ const challengeCookie = "__Host-feedbax-handoff";
5
+ const sessionCookie = "__Host-feedbax-session";
6
+ export const sessionHash = (token: string) =>
7
+ createHash("sha256").update(token).digest("hex");
8
+ export function readSessionToken(request: Request) {
9
+ return cookie(request, sessionCookie);
10
+ }
11
+ export function sameOrigin(request: Request, siteUrl: string) {
12
+ return request.headers.get("origin") === new URL(siteUrl).origin;
13
+ }
14
+ export function createConnectedIdentityHandler(options: {
15
+ siteUrl: string;
16
+ loginUrl: string;
17
+ issuer: string;
18
+ secret: string;
19
+ store: ConnectedStore;
20
+ now?: () => number;
21
+ }) {
22
+ const origin = new URL(options.siteUrl).origin;
23
+ return async (request: Request): Promise<Response> => {
24
+ const path = new URL(request.url).pathname;
25
+ const headers = new Headers({
26
+ "Cache-Control": "no-store",
27
+ "Referrer-Policy": "no-referrer",
28
+ });
29
+ const json = (value: unknown, status = 200) =>
30
+ Response.json(value, { status, headers });
31
+ try {
32
+ if (path === "/internal/identity/start" && request.method === "GET") {
33
+ const state = randomBytes(32).toString("base64url");
34
+ const target = new URL(options.loginUrl);
35
+ target.searchParams.set("state", state);
36
+ target.searchParams.set(
37
+ "callback",
38
+ `${origin}/internal/identity/callback`,
39
+ );
40
+ headers.set(
41
+ "Set-Cookie",
42
+ `${challengeCookie}=${state}; Path=/; Max-Age=300; HttpOnly; Secure; SameSite=None`,
43
+ );
44
+ headers.set("Location", target.toString());
45
+ return new Response(null, { status: 303, headers });
46
+ }
47
+ if (path === "/internal/identity/callback" && request.method === "POST") {
48
+ if (request.headers.get("origin") !== new URL(options.loginUrl).origin)
49
+ return json({ error: "Sign-in origin is invalid." }, 403);
50
+ const body = await request.text();
51
+ if (body.length > 12000)
52
+ return json({ error: "Sign-in request is too large." }, 413);
53
+ const form = new URLSearchParams(body);
54
+ const now = options.now?.() ?? Date.now();
55
+ const identity = verifyIdentityHandoff(
56
+ form.get("token") ?? "",
57
+ options.secret,
58
+ {
59
+ audience: origin,
60
+ issuer: options.issuer,
61
+ state: cookie(request, challengeCookie) ?? "",
62
+ now: Math.floor(now / 1000),
63
+ },
64
+ );
65
+ const token = randomBytes(32).toString("base64url");
66
+ await options.store.acceptIdentity({
67
+ ...identity,
68
+ subject: JSON.stringify([identity.issuer, identity.subject]),
69
+ nonce: identity.nonce,
70
+ challenge: identity.state,
71
+ sessionHash: sessionHash(token),
72
+ expiresAt: now + 7 * 86400000,
73
+ });
74
+ headers.append(
75
+ "Set-Cookie",
76
+ `${sessionCookie}=${token}; Path=/; Max-Age=604800; HttpOnly; Secure; SameSite=Lax`,
77
+ );
78
+ headers.append(
79
+ "Set-Cookie",
80
+ `${challengeCookie}=; Path=/; Max-Age=0; HttpOnly; Secure; SameSite=None`,
81
+ );
82
+ headers.set("Location", origin);
83
+ return new Response(null, { status: 303, headers });
84
+ }
85
+ if (path === "/internal/identity/session" && request.method === "GET") {
86
+ const token = readSessionToken(request);
87
+ const participant = token
88
+ ? await options.store.session(sessionHash(token), options.now?.())
89
+ : undefined;
90
+ return json({
91
+ participant: participant
92
+ ? { displayName: participant.displayName }
93
+ : null,
94
+ });
95
+ }
96
+ if (path === "/internal/identity/logout" && request.method === "POST") {
97
+ if (!sameOrigin(request, origin))
98
+ return json({ error: "Request origin is invalid." }, 403);
99
+ const token = readSessionToken(request);
100
+ if (token) await options.store.logout(sessionHash(token));
101
+ headers.set(
102
+ "Set-Cookie",
103
+ `${sessionCookie}=; Path=/; Max-Age=0; HttpOnly; Secure; SameSite=Lax`,
104
+ );
105
+ return json({ signedOut: true });
106
+ }
107
+ return json({ error: "Not found." }, 404);
108
+ } catch {
109
+ return json(
110
+ { error: "Sign-in could not be completed. Start sign-in again." },
111
+ 401,
112
+ );
113
+ }
114
+ };
115
+ }
116
+ function cookie(request: Request, name: string): string | undefined {
117
+ const pairs = (request.headers.get("cookie") ?? "")
118
+ .split(";")
119
+ .map((v) => v.trim())
120
+ .filter((v) => v.startsWith(`${name}=`));
121
+ return pairs.length === 1 ? pairs[0]!.slice(name.length + 1) : undefined;
122
+ }
@@ -0,0 +1,67 @@
1
+ // @vitest-environment jsdom
2
+ import { afterEach, expect, it, vi } from "vitest";
3
+ import {
4
+ cleanup,
5
+ fireEvent,
6
+ render,
7
+ screen,
8
+ waitFor,
9
+ } from "@testing-library/react";
10
+ import { ConnectedIdentityProvider } from "./components/connected-identity-provider";
11
+ import { VoteToggle } from "./vote-toggle";
12
+ vi.mock("./feedbax", async (importOriginal) => {
13
+ const actual = await importOriginal<typeof import("./feedbax")>();
14
+ return {
15
+ default: {
16
+ ...actual.default,
17
+ connected: {
18
+ issuer: "https://app.example",
19
+ loginUrl: "https://app.example/login",
20
+ },
21
+ },
22
+ };
23
+ });
24
+ afterEach(() => {
25
+ cleanup();
26
+ vi.unstubAllGlobals();
27
+ localStorage.clear();
28
+ sessionStorage.clear();
29
+ });
30
+ it("restores a signed-in Participant's Vote from the server instead of device storage", async () => {
31
+ const request = vi.fn<typeof fetch>().mockImplementation(async (input) => {
32
+ const url = String(input);
33
+ if (url === "/internal/identity/session")
34
+ return Response.json({ participant: { displayName: "Alice" } });
35
+ if (url.startsWith("/internal/connected/votes?"))
36
+ return Response.json({ voted: true, voteCount: 4 });
37
+ return Response.json({ slug: "post", voteCount: 3, voted: false });
38
+ });
39
+ vi.stubGlobal("fetch", request);
40
+ render(
41
+ <ConnectedIdentityProvider>
42
+ <VoteToggle
43
+ post={{
44
+ slug: "post",
45
+ title: "Post",
46
+ description: "Description",
47
+ type: "Feature Request",
48
+ status: "Planned",
49
+ createdAt: new Date(),
50
+ updatedAt: new Date(),
51
+ voteCount: 4,
52
+ }}
53
+ />
54
+ </ConnectedIdentityProvider>,
55
+ );
56
+ const button = await screen.findByRole("button", {
57
+ name: "Remove Vote, 4 Votes",
58
+ });
59
+ expect(button.getAttribute("aria-pressed")).toBe("true");
60
+ fireEvent.click(button);
61
+ await waitFor(() =>
62
+ expect(
63
+ screen.getByRole("button", { name: "Add Vote, 3 Votes" }),
64
+ ).toBeTruthy(),
65
+ );
66
+ expect(localStorage.length).toBe(0);
67
+ });