Skip to content

feat(api): add v2 /notifications/[username] endpoint - #36

Open
rferrari wants to merge 8 commits into
SkateHive:mainfrom
rferrari:feat/v2-notifications
Open

feat(api): add v2 /notifications/[username] endpoint#36
rferrari wants to merge 8 commits into
SkateHive:mainfrom
rferrari:feat/v2-notifications

Conversation

@rferrari

@rferrari rferrari commented Jul 3, 2026

Copy link
Copy Markdown
Collaborator

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.

⚠️ Stacked on #35 (feat/v2-post-endpoint). It reuses the vitest runner and cacheHeaders helper introduced there. Until #35 merges, this PR's diff also shows #35's commits — it will slim automatically once #35 lands. Please review/merge #35 first.

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 + an account_history_api scan 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_notifications for the list (params: limit max 100, optional last_id pagination).
  • Read status derived from the last notify (setLastRead) custom_json, scanning account history in pages of 1000 ops up to 5 pages — mirrors the mobile app's findLastNotificationsReset (the gold standard; more robust than the webapp's single-pass scan).
  • Returns each notification with an isRead flag (matching mobile's HiveNotification shape) plus lastRead and an unread count.
  • Uses HiveClient (RPC), not HAFSQL — notifications are a computed bridge API, not in HAFSQL.
  • Edge-cached 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

  • Unit (tests/unit/notifications.route.test.ts, 7 tests, no live DB — HiveClient mocked): per-item isRead + unread, limit clamp, last_id passthrough, epoch default, recursive history-page walk, history-scan failure fallback, 500 path.
  • Smoke (tests/test-api-endpoints.sh): notifications + limit variant.
  • pnpm lint clean; pnpm build compiles 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

  • Additive only — no changes to existing routes, no webapp changes.

🤖 Generated with Claude Code

rferrari and others added 8 commits July 3, 2026 00:56
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>
@coderabbitai

coderabbitai Bot commented Jul 3, 2026

Copy link
Copy Markdown

Warning

Review limit reached

@rferrari, you've reached your PR review limit, so we couldn't start this review.

Next review available in: 49 minutes

Enable usage-based reviews in Billing to review now. Otherwise, wait until the next included review is available.
You're only billed for reviews past your plan's rate limits ($0.25/file).

How can I continue?

After more reviews become available, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

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 configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: 9e9c517e-3b8b-4cff-9ec5-70a8fd34738f

📥 Commits

Reviewing files that changed from the base of the PR and between 3bb3c8d and 49d15c4.

⛔ Files ignored due to path filters (1)
  • pnpm-lock.yaml is excluded by !**/pnpm-lock.yaml
📒 Files selected for processing (8)
  • package.json
  • src/app/api/v2/notifications/[username]/route.ts
  • src/app/api/v2/post/[author]/[permlink]/route.ts
  • src/lib/cache-headers.ts
  • tests/test-api-endpoints.sh
  • tests/unit/notifications.route.test.ts
  • tests/unit/post.route.test.ts
  • vitest.config.ts
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

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.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@rferrari

rferrari commented Jul 3, 2026

Copy link
Copy Markdown
Collaborator Author

Mobile-app follow-up tracked in SkateHive/mobileapp#17 — switch its notification reads to this endpoint once merged.

@rferrari

rferrari commented Jul 3, 2026

Copy link
Copy Markdown
Collaborator Author

Part of #38 (read-through-API tracking issue).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant