feat(routes-b): add trust-score history endpoint (#619)#666
Merged
davedumto merged 1 commit intodavedumto:mainfrom Apr 29, 2026
Merged
Conversation
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
|
@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. |
|
@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! 🚀 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
GET /api/routes-b/trust-score/history?days=30|90|365returning{ days, history: [{ date, score }] }in ascending date orderrecomputeTrustScoreafter each successful upsert, so the endpoint and the history stay in lock-stepdaysdefaults to 30 and rejects anything outside{30, 90, 365}withINVALID_RANGEso we don't expose buckets we never advertisedScope
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
/trust-score's contractTest plan
days=30 / 90 / 365filters return only entries within the windowisAllowedRangeaccepts only30 / 90 / 365dayswithINVALID_RANGEOut of scope
Closes #619