Skip to content

Add pagination and a total count to the api-keys and webhooks list endpoints #146

Description

@mikewheeleer

Enhance the api-keys and webhooks listings with limit/offset pagination

Description

GET /api/v1/api-keys and GET /api/v1/webhooks in src/index.ts both materialise the entire store with Array.from(...).map(...) and return every item unbounded — unlike GET /api/v1/services and GET /api/v1/agents, which clamp with a ?limit. A deployment with thousands of keys or webhooks returns a single huge payload and offers no way to page. This issue adds consistent pagination to bring these listings in line with the rest of the API.

Requirements and context

  • Repository scope: Agentpay-Org/Agentpay-backend only.
  • Add ?limit (default 200, max 1000, matching the services convention) and ?offset (default 0) to both list endpoints, clamping robustly.
  • Wrap the response with a total count so clients can page deterministically (e.g. { items, total }), keeping the per-item shape (prefix-only for keys, full record for webhooks) unchanged.
  • Preserve the existing security property that the api-keys list never returns the full key.
  • Keep ordering stable across pages (e.g. by createdAt then id).

Suggested execution

  • Fork the repo and create a branch
  • git checkout -b enhancement/api-71-paginate-keys-webhooks
  • Implement changes
    • Write code in: the GET /api/v1/api-keys and GET /api/v1/webhooks handlers in src/index.ts.
    • Write comprehensive tests in: new src/list-pagination.test.ts — limit/offset paging, total accuracy, prefix-only keys preserved, stable order across pages.
    • Add documentation: document the pagination params in README.md.
    • Add TSDoc on the handlers.
    • Validate security assumptions: api-key secrets never returned; pagination cannot exceed the max.
  • Test and commit

Test and commit

  • Run npm test and npm run lint.
  • Cover edge cases: empty store, offset past the end, limit clamp, single page.
  • Include the full npm test output in the PR description.

Example commit message

feat: paginate the api-keys and webhooks list endpoints

Guidelines

  • Minimum 95 percent test coverage for impacted modules.
  • Clear, reviewer-focused documentation.
  • Timeframe: 96 hours.

Community & contribution rewards

  • 💬 Join the AgentPay community on Discord for questions, reviews, and faster merges: https://discord.gg/eXvRKkgcv
  • ⭐ This is a GrantFox OSS / Official Campaign task and may be rewarded. When your PR is merged you'll be prompted to rate the project — if this issue and the maintainers helped you ship, we'd be grateful for a 5-star rating. Clear questions in Discord and tidy, well-tested PRs are the fastest path to a merge and a reward.

Metadata

Metadata

Assignees

No one assigned
    No fields configured for Feature.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions