Skip to content

feat(routes-b): add trust-score history endpoint (#619)#666

Merged
davedumto merged 1 commit intodavedumto:mainfrom
pragmaticAweds:issue-619-trust-score-history
Apr 29, 2026
Merged

feat(routes-b): add trust-score history endpoint (#619)#666
davedumto merged 1 commit intodavedumto:mainfrom
pragmaticAweds:issue-619-trust-score-history

Conversation

@pragmaticAweds
Copy link
Copy Markdown
Contributor

Summary

  • Adds GET /api/routes-b/trust-score/history?days=30|90|365 returning { days, history: [{ date, score }] } in ascending date order
  • Per-user in-memory ring buffer holds the last 365 daily snapshots, bounding memory across recompute frequency
  • Same-day recomputes overwrite the day's score (latest wins) so history is one entry per UTC day
  • Snapshot is recorded inside recomputeTrustScore after each successful upsert, so the endpoint and the history stay in lock-step
  • days defaults to 30 and rejects anything outside {30, 90, 365} with INVALID_RANGE so we don't expose buckets we never advertised

Scope

All changes live inside app/api/routes-b/:

  • app/api/routes-b/_lib/trust-score-history.ts (store + validators)
  • app/api/routes-b/trust-score/history/route.ts (new endpoint)
  • app/api/routes-b/trust-score/route.ts (snapshot hook in the recompute path)
  • app/api/routes-b/trust-score/__tests__/history.test.ts (tests)

Behavior / acceptance

  • Memory is bounded by the per-user 365-entry cap (oldest dropped first)
  • History is returned in ascending date order
  • 403 without a valid bearer token, matching /trust-score's contract

Test plan

  • Empty history before any snapshot
  • Same-day recompute overwrites the day's score (latest wins)
  • Builds up across multiple days in ascending order
  • 365-day retention cap drops oldest entries first
  • days=30 / 90 / 365 filters return only entries within the window
  • No history leaks across users
  • isAllowedRange accepts only 30 / 90 / 365
  • Endpoint rejects out-of-range days with INVALID_RANGE
  • Endpoint returns 403 without a valid token

Out of scope

  • Persistent (database-backed) history — issue explicitly defers this
  • Component-level history — separate issue

Closes #619

Adds GET /api/routes-b/trust-score/history?days=30|90|365 returning
[{ date, score }] for the authenticated user, in ascending date order.

- Per-user in-memory ring buffer keeps the last 365 daily snapshots,
  bounding memory regardless of recompute frequency
- Same-day recomputes overwrite the day's score (latest wins) so the
  history records one entry per UTC day
- Snapshot is recorded after each successful recompute in
  routes-b/trust-score/route.ts
- days defaults to 30; 60 / 180 / arbitrary values are rejected with
  INVALID_RANGE so we don't grow new buckets we never advertised

All work is contained in app/api/routes-b/. Helpers live in
app/api/routes-b/_lib/trust-score-history.ts.

Closes davedumto#619
@vercel
Copy link
Copy Markdown

vercel Bot commented Apr 29, 2026

@pragmaticAweds is attempting to deploy a commit to the david's projects Team on Vercel.

A member of the Team first needs to authorize it.

@drips-wave
Copy link
Copy Markdown

drips-wave Bot commented Apr 29, 2026

@pragmaticAweds Great news! 🎉 Based on an automated assessment of this PR, the linked Wave issue(s) no longer count against your application limits.

You can now already apply to more issues while waiting for a review of this PR. Keep up the great work! 🚀

Learn more about application limits

@davedumto davedumto merged commit 455b282 into davedumto:main Apr 29, 2026
1 of 3 checks passed
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.

Add trust-score history endpoint to routes-b

2 participants