- Updated
src/lib/pagination.tsto support bothoffset/limitandpage/limitpagination. - Enforced a
DEFAULT_LIMITof 20 and aMAX_LIMITof 100 across all endpoints. - Normalized invalid inputs (NaN, negative, zero) to safe defaults.
- Refactored
src/app.tsto use the sharedparsePaginationhelper consistently, replacing ad-hoc parsing. - Improved consistency of API responses by using
paginatedResponsefor/api/apisand/api/developers/apis. - Implemented full public API listing in
GET /api/apis(previously returned empty array). - Updated
UsageEventsRepository(both In-Memory and PG implementations) to support pagination (limit and offset). - Updated
developerRoutes.tsto supportpageparameter in revenue analytics. - Updated
admin.tsto supportpageparameter in user listing. - Added comprehensive unit tests in
src/lib/__tests__/pagination.test.tscovering edge cases and new functionality.
- DoS Protection: By enforcing a
MAX_LIMITof 100, we prevent potentially expensive database queries that could return thousands of rows, which could be used as a DoS vector. - Input Sanitization: All pagination parameters are parsed as integers and clamped to safe ranges (limit 1-100, offset >= 0). This prevents SQL injection through pagination parameters (especially in the PG repository where they are passed as parameters anyway).
- Consistency: Using a single source of truth (
parsePagination) ensures that all list endpoints behave identically regarding pagination, reducing developer error when adding new endpoints. - Default Behavior: If no pagination parameters are provided, the system defaults to the first page (offset 0) with a limit of 20, ensuring stable and predictable API responses.
- Ran unit tests for pagination logic:
32 tests passed. - Verified type safety (ignoring environment-specific missing type definitions for jest/node).
- Manually reviewed all modified routes to ensure they correctly use the returned
limitandoffset.