feat(backend): standardize pagination and cursor validation across list endpoints#753
Merged
Calebux merged 1 commit intoMay 28, 2026
Merged
Conversation
…st endpoints (Calebux#641) - Create shared pagination helpers in src/utils/pagination.ts - Add validateCursor, validateLimit, encodeCursor, PaginationError utilities - Add cursorPaginationSchema for Zod validation - Update subscription-service to use shared cursor validation - Update subscriptions, merchants, audit, gift-card-ledger routes to use helpers - Add comprehensive tests for pagination utilities - Update SUBSCRIPTION_API.md with cursor pagination documentation Error codes: INVALID_CURSOR, MALFORMED_CURSOR, INVALID_LIMIT
|
@Belzabeem 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.
Closes #641
Summary
This PR implements shared pagination helpers that enforce consistent cursor validation and error responses across all list endpoints, bringing them in line with the rigor already present in subscription services.
Changes
backend/src/utils/pagination.ts (new) - Shared pagination utilities
validateCursor()- Validates base64-encoded cursor with created_at field, throwsMALFORMED_CURSORorINVALID_CURSORerrorsvalidateLimit()- Validates limit parameter (1-100 range), throwsINVALID_LIMITerrorencodeCursor()- Encodes cursor data to base64PaginationError- Custom error class with error codescursorPaginationSchema- Zod schema for cursor-based pagination validationbackend/src/schemas/common.ts - Added
cursorPaginationSchemafor reusable validationbackend/src/services/subscription-service.ts - Updated to use shared
validateCursorandencodeCursorhelpersbackend/src/routes/subscriptions.ts - Uses shared pagination validation with proper error handling
backend/src/routes/merchants.ts - Added
PaginationErrorhandling for consistent error responsesbackend/src/routes/audit.ts - Added
PaginationErrorhandling for consistent error responsesbackend/src/routes/gift-card-ledger.ts - Uses
validateLimitfor limit validationbackend/tests/pagination.test.ts (new) - 28 tests covering all pagination utilities
backend/tests/subscription-service.test.ts - Updated tests for cursor-based pagination
backend/SUBSCRIPTION_API.md - Updated documentation with cursor pagination semantics
Error Codes
All pagination errors now return consistent structured responses:
INVALID_CURSOR- The cursor is malformed or cannot be decodedMALFORMED_CURSOR- The cursor is missing requiredcreated_atfieldINVALID_LIMIT- The limit parameter is out of range or not a valid integerTests
All 35 pagination-related tests pass:
Checklist