chore(backend): add pagination defaults and max limits enforcement across list endpoints#291
Merged
greatest0fallt1me merged 4 commits intoCalloraOrg:mainfrom Apr 24, 2026
Conversation
…ross list endpoints
Author
|
Hello @maintainer. |
Author
|
Hello @greatest0fallt1me I'm yet to receive my point for the issue fixed |
Author
|
Hello Maintainer, I'm still yet to get my point and this issue has been merged. Please can you explain what's happening |
Author
|
Hello Maintainer I'm yet to receive my point for the issue fixed |
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 #236
Summary
This PR addresses issue #236 by implementing consistent pagination defaults and maximum limit enforcement across all list endpoints in the
Callora-Backendrepository. This improves API consistency, performance, and protects against unbounded queries that could be used as an application-layer DoS vector.🧪 Implementation Details
src/lib/pagination.tsto support bothoffset/limitandpage/limitpagination structures seamlessly.DEFAULT_LIMITof20and aMAX_LIMITof100system-wide.src/app.ts,src/routes/admin.ts, andsrc/routes/developerRoutes.tsto use the sharedparsePaginationandpaginatedResponsehelpers consistently.UsageEventsRepository(both In-Memory and PostgreSQL implementations) to explicitly support pagination (limitandoffset).dataandmeta) and implemented a full public API listing forGET /api/apismapping to the backend repository logic.📋 Security and Data Integrity Notes
MAX_LIMITof 100, we prevent potentially expensive database queries that could return millions of rows, eliminating a common vector for application-layer Denial of Service attacks.1-100, offset>= 0). This ensures we drop invalid query states and prevents SQL injection via numeric parameters.parsePaginationas the Single Source of Truth guarantees that all current and future list endpoints behave identically.0) with a sensible limit (20), ensuring predictable API responses without overwhelming either backend performance or client memory limits.📁 Files Changed
src/lib/pagination.ts- Centralized validation & pagination logicsrc/lib/__tests__/pagination.test.ts- Extensive new unit tests for edge casessrc/app.ts- Refactored endpoints for consistent usagesrc/repositories/usageEventsRepository.ts- Type signature updatessrc/repositories/usageEventsRepository.pg.ts- Safe parameterized offset implementationsrc/routes/admin.ts- Admin metrics routessrc/routes/developerRoutes.ts- Developer analytics routes🚀 Test Results