Skip to content

fix(zaps): clamp history pagination params - #294

Closed
sevencat2004 wants to merge 4 commits into
profullstack:masterfrom
sevencat2004:fix/zaps-history-pagination-bounds
Closed

fix(zaps): clamp history pagination params#294
sevencat2004 wants to merge 4 commits into
profullstack:masterfrom
sevencat2004:fix/zaps-history-pagination-bounds

Conversation

@sevencat2004

Copy link
Copy Markdown
Contributor

Summary

  • clamp zap history limit and offset before building the Supabase range
  • default invalid/non-positive limit to 50 and cap large limits at 100
  • default invalid/negative offset to 0
  • return early for empty zap result sets to avoid an unnecessary empty profile lookup
  • add route coverage for auth, invalid pagination, capped limits, valid values, and empty results

Fixes #293

Payment

  • Solana wallet: Dy4yMkjCfupxaURt6iTMUrxqSDEmAJPPkKF66QahxJZD

Test plan

  • corepack pnpm test -- src/app/api/zaps/history/route.test.ts

@greptile-apps

greptile-apps Bot commented May 29, 2026

Copy link
Copy Markdown

Greptile Summary

This PR hardens the zap history pagination endpoint by replacing raw parseInt calls with two validated helper functions (parsePositiveInt, parseNonNegativeInt) that clamp limit (1–100, default 50) and offset (≥0, default 0). It also fixes the early-return path to propagate the Supabase count value instead of hardcoding total: 0, and skips the profile lookup when the page is empty.

  • Pagination clamping: parsePositiveInt and parseNonNegativeInt replace bare parseInt, correctly rejecting zero, negative, and non-numeric inputs with safe fallbacks before the Supabase range() call.
  • Accurate total on empty pages: The early-return for empty result sets now uses count || 0 so pagination UIs that rely on total to compute page counts get the correct value even when the requested offset is past the end of the data.
  • Test coverage: Five new test cases cover the auth guard, invalid param clamping, large-limit capping, valid pass-through, and the empty-result path with a non-zero count.

Confidence Score: 5/5

Safe to merge — the changes are narrowly scoped to input validation and a one-line count fix, with new tests that verify each adjusted code path.

The logic changes are small and well-tested: the helper functions correctly handle all edge cases (null, empty string, zero, negative, float-like strings), the clamping math is verified by the test assertions, and the count propagation fix is directly exercised by the empty-result test case. No pre-existing behavior is altered beyond the targeted bug fixes.

No files require special attention.

Important Files Changed

Filename Overview
src/app/api/zaps/history/route.ts Adds two helper functions for safe integer parsing, clamps limit (1–100, default 50) and offset (≥0, default 0), and fixes the early-return to propagate the Supabase count instead of hardcoding 0.
src/app/api/zaps/history/route.test.ts New test file covering auth guard, invalid/clamped pagination values, and the empty-result path that verifies count is correctly propagated.

Flowchart

%%{init: {'theme': 'neutral'}}%%
flowchart TD
    A[GET /api/zaps/history] --> B{Auth?}
    B -- No --> C[401 Unauthorized]
    B -- Yes --> D["Parse limit via parsePositiveInt (default=50, cap=100)"]
    D --> E["Parse offset via parseNonNegativeInt (default=0)"]
    E --> F["Supabase: SELECT zaps with count=exact, range(offset..offset+limit-1)"]
    F --> G{"zaps null or empty?"}
    G -- Yes --> H["Return {zaps:[], total: count || 0} — skip profile lookup"]
    G -- No --> I["Collect unique sender/recipient IDs"]
    I --> J["Supabase: SELECT profiles IN ids"]
    J --> K["Enrich zaps with profile info"]
    K --> L["Return {zaps: enriched, total: count || 0}"]
Loading

Reviews (3): Last reviewed commit: "chore(zaps): normalize history route dif..." | Re-trigger Greptile

Comment thread src/app/api/zaps/history/route.ts
Comment thread src/app/api/zaps/history/route.test.ts Outdated
@sevencat2004

Copy link
Copy Markdown
Contributor Author

Submitted this PR for the ugig bug-fix/testing gig.\n\nThe PR is ready for review:\n- fixes #293\n- local route test passes\n- Socket checks are passing\n\nSolana wallet for bounty payout:\nDy4yMkjCfupxaURt6iTMUrxqSDEmAJPPkKF66QahxJZD

@greptile-apps

greptile-apps Bot commented May 29, 2026

Copy link
Copy Markdown

Want your agent to iterate on Greptile's feedback? Try greploops.

@sevencat2004

Copy link
Copy Markdown
Contributor Author

Follow-up completed after review feedback:

  • preserved the Supabase count for empty result pages so pagination totals stay correct
  • added coverage for an empty page with a non-zero total
  • cleaned up the route diff so only the real logic changes show
  • verified locally: node_modules\.bin\vitest.CMD run src/app/api/zaps/history/route.test.ts (5 tests passed)

@ralyodio ralyodio closed this May 29, 2026
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.

Zap history accepts invalid pagination ranges

2 participants