feat(api): add v2 /notifications/[username] endpoint - #36
Conversation
Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Fetches a single post from HAFSQL with the same column shape, children count and vote aggregation as the feed, then runs it through dealiasSoftPosts so lite-user (@skateuser) identity is preserved. Serves edge-cached (s-maxage=300) so post pages, OG images and Farcaster frames stop hitting Hive RPC directly. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Covers the happy path (single post by author/permlink) and the 404 (nonexistent permlink) in the existing status-code smoke suite. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Introduces vitest (+ test/test:watch scripts and a config that mirrors the '@/*' tsconfig alias) as the unit-test framework for API routes. Unit tests live in tests/unit/ so route folders with literal-bracket segments (e.g. [author]) don't break glob includes. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Covers 200 (normalized shape + 300s edge-cache headers), query parameterization, soft-post de-alias delegation, 404 (short cache), and 500 (no cache). HAFSQL and dealiasSoftPosts are mocked so the suite runs with no live DB. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Fetches a user's notifications from bridge.account_notifications and derives read status from the last `notify` (setLastRead) custom_json, scanning account history in pages of 1000 ops (up to 5 pages) like the mobile app does. Returns each notification with an isRead flag plus the lastRead date and an unread count. Supports limit (max 100) and last_id pagination. Edge-cached at s-maxage=30. Unifies notification-reading logic currently duplicated across the web server/client helpers and the mobile app, moving it behind one edge-cached endpoint. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Covers per-item isRead + unread computation, limit clamping, last_id pagination, epoch default, recursive history-page walk, history-scan failure fallback, and the 500 path. HiveClient is mocked (no RPC). Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
|
Warning Review limit reached
Next review available in: 49 minutes Enable usage-based reviews in Billing to review now. Otherwise, wait until the next included review is available. How can I continue?After more reviews become available, a review can be triggered using the To avoid repeated limits, reduce automatic review volume by pausing incremental auto-reviews earlier, using label-based review opt-in, excluding WIP or generated PR titles, or requesting reviews manually when the PR is ready. If your team needs uninterrupted high-volume reviews, an organization admin can enable usage-based reviews. How do review limits work?CodeRabbit enforces per-developer PR review limits for each organization. Most developers receive the normal plan review availability. For paid Pro and Pro+ PR reviews, CodeRabbit uses adaptive limits for sustained high-volume activity. When a developer's recent PR review activity reaches the 95th percentile or higher among CodeRabbit users, additional reviews become available more gradually as earlier reviews age out of the rolling window. Please refer docs for additional details. Review details⚙️ Run configurationConfiguration used: defaults Review profile: CHILL Plan: Pro Run ID: ⛔ Files ignored due to path filters (1)
📒 Files selected for processing (8)
✨ Finishing Touches🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
|
Mobile-app follow-up tracked in SkateHive/mobileapp#17 — switch its notification reads to this endpoint once merged. |
|
Part of #38 (read-through-API tracking issue). |
What
Adds
GET /api/v2/notifications/[username]— an edge-cached read for a user's Hive notifications with read status.Second in the series of small PRs closing API read gaps for the "read-through-API" migration.
Why
Notification reading is currently reimplemented in three places — the webapp server helpers, the webapp client helpers, and the mobile app (
lib/hive-utils.ts) — each hitting Hive RPC directly (bridge.account_notifications+ anaccount_history_apiscan for the last read). This endpoint unifies that behind one edge-cached read so all clients can drop their duplicated RPC logic.How
bridge.account_notificationsfor the list (params:limitmax 100, optionallast_idpagination).notify(setLastRead) custom_json, scanning account history in pages of 1000 ops up to 5 pages — mirrors the mobile app'sfindLastNotificationsReset(the gold standard; more robust than the webapp's single-pass scan).isReadflag (matching mobile'sHiveNotificationshape) pluslastReadand anunreadcount.HiveClient(RPC), not HAFSQL — notifications are a computed bridge API, not in HAFSQL.s-maxage=30, stale-while-revalidate=15(short, since unread reflects a user action).Response shape
{ "success": true, "data": { "notifications": [{ "id": 1, "type": "reply", "score": 40, "date": "...", "msg": "...", "url": "...", "isRead": false }], "lastRead": "2026-07-03T03:00:00", "unread": 2 } }Testing
tests/unit/notifications.route.test.ts, 7 tests, no live DB —HiveClientmocked): per-itemisRead+ unread, limit clamp,last_idpassthrough, epoch default, recursive history-page walk, history-scan failure fallback, 500 path.tests/test-api-endpoints.sh): notifications + limit variant.pnpm lintclean;pnpm buildcompiles the route as dynamic.Follow-up
Once this lands, the mobile app can switch its notification reads to this endpoint (tracked in a mobileapp issue).
Notes
🤖 Generated with Claude Code