fix(zaps): clamp history pagination ranges - #310
Conversation
Greptile SummaryThis PR hardens the zap history pagination endpoint by clamping user-supplied
Confidence Score: 5/5Safe to merge — changes are narrowly scoped to input clamping and an empty-results guard with no behavioral regressions on the happy path. All touched logic is defensive: the parseInt radix fix, Number.isFinite guards, Math.min/max clamping, and the corrected empty-page early return are all straightforward and correct. No auth changes, no schema changes, and no new external calls are introduced. No files require special attention. Important Files Changed
Sequence DiagramsequenceDiagram
participant Client
participant Route as GET /api/zaps/history
participant Supabase
Client->>Route: "?limit=X&offset=Y&direction=Z"
Route->>Route: "parse & clamp limit → [1,100]"
Route->>Route: "parse & clamp offset → [0,∞)"
Route->>Supabase: "SELECT zaps WHERE user_id=... RANGE(offset, offset+limit-1) COUNT exact"
Supabase-->>Route: "{ data, count }"
alt data is null or empty
Route-->>Client: "{ zaps: [], total: count || 0 }"
else data has rows
Route->>Supabase: SELECT profiles WHERE id IN (otherIds)
Supabase-->>Route: profiles[]
Route->>Route: enrich zaps with profile info
Route-->>Client: "{ zaps: enriched[], total: count || 0 }"
end
Reviews (2): Last reviewed commit: "fix(zaps): preserve count for empty hist..." | Re-trigger Greptile |
Fixes #293.
This clamps
limitandoffsetbefore passing them into Supabase.range(...):limitfalls back into a safe 1..100 rangeoffsetfalls back to 0Verification: inspected the route and kept the change scoped to query parsing plus the empty-results guard. Full test suite was not run because this workspace does not have a full dependency checkout.