feat(feedback): save feedback in the database, with an admin API to list, reply and import
Feedback from the dashboard's Feedback button is now saved in the database before anything is emailed, so it isn't lost when the email fails, and it can be listed and answered from our own tools. Same design as split-pro-cloud #50, adapted to useSend.
What changed
- New
FeedbackandFeedbackReplytables. The migration only adds tables, enums, indexes and foreign keys; nothing existing changes. Feedback status isOPEN,REPLIEDorCLOSED, and it records the team the sender was using. feedback.sendsaves the feedback (email and name read from the locked user row), then emails the founder in the background, with the same "Product feedback from {team}" subject plus the feedback id.- The dialog sends one key per draft, so a double click or retry saves it once.
- Duplicates and abuse:
- The same key and text returns the saved feedback; the same key with different text is a
CONFLICT. - The same message from the same person within 24 hours counts as a resend.
- Each person's submissions are serialised.
- More than 10 in an hour is refused.
- The same key and text returns the saved feedback; the same key with different text is a
Admin API (/api/admin/*, off unless ADMIN_API_TOKEN is set; then needs Authorization: Bearer <token>, compared in constant time; bodies are read only after auth and capped while streaming)
GET /api/admin/feedback?status=&since=&limit=&cursor=: newest first, with replies.PATCH /api/admin/feedback/{id}: change the status.POST /api/admin/feedback/{id}/replywith{ message, idempotencyKey }: emails the sender.POST /api/admin/feedback/import: copies the old feedback emails in. Only existing accounts are matched; anything older than 30 days is imported as closed. Safe to run again.
This is also the base for the Guard's admin API (pending applications, team stats, pause), which will be added as more routes on the same wrapper.
Replies (same safety model as SplitPro's)
- A reply is claimed as
SENDINGunder its key with a fresh attempt id, then emailed outside any transaction. Only the attempt holding it can record the outcome. - Sent: the reply is
SENTand the feedbackREPLIED. Certainly not sent (the API refused it before sending):FAILED, and the same key can be retried. - Unknown (timeout, dropped connection, server error): it stays
SENDINGand is never resent automatically. After checking whether it arrived, settle it withPATCH /api/admin/feedback/{id}/reply/{replyId}and{ "deliveryStatus": "SENT" | "FAILED" }. That's allowed only fromSENDINGand once the attempt is at least 10 minutes old. - A key stands for one message: the same key with a different message is a 409.
- The send also carries useSend's
Idempotency-Key, as extra protection only. - Known limit: settling a reply as
FAILEDassumes the original send has stopped. The 10-minute wait makes that very likely but doesn't prove it, so check delivery first. A late success never overrides a manual settle.
Config
- New optional
ADMIN_API_TOKEN(at least 32 characters). Without it, the admin API answers 404 and nothing else changes. - Replies need
UNSEND_API_KEYandFOUNDER_EMAIL, which cloud already has.
Verification
- Typecheck clean. Tests: 344 unit, 23 tRPC, 49 API, all passing.
- New tests cover token checks, saving and dedupe, the rate limit, the race on a shared key, reply claiming, uncertain sends never resent, settling, the streamed body cap, and error codes read through the real SDK with HTTP mocked (the vitest config now points
usesend-jsat the SDK source, so tests don't need a built package), import, and the route's 404/401/400 answers.
Migration notes
20261110130000_add_feedback adds tables only. It's safe to deploy before or after #495.
Summary by CodeRabbit
- New Features
- Added feedback submission with duplicate protection and limits on repeated submissions.
- Added administrative tools to review, filter, update, and import feedback, and to send replies and track delivery status.
- Added optional token protection for administrative feedback access; the feature remains unavailable when the setting is empty.
Ask Polylane for an impact assessment of this pull request: