Skip to content

feat(metrics): validate query params, paginate stats breakdown, extract cursor helper - #409

Closed
thlpkee20-wq wants to merge 4 commits into
Agentpay-Org:mainfrom
thlpkee20-wq:feature/metrics-01-group
Closed

feat(metrics): validate query params, paginate stats breakdown, extract cursor helper#409
thlpkee20-wq wants to merge 4 commits into
Agentpay-Org:mainfrom
thlpkee20-wq:feature/metrics-01-group

Conversation

@thlpkee20-wq

Copy link
Copy Markdown
Contributor

Summary

Closes #391
Closes #390
Closes #389
Closes #388
Closes #387

Test plan

  • npm run build
  • npm run lint
  • npm test — targeted run of stats-breakdown.test.js,
    lifetime-metrics.test.js, metrics.test.js,
    settlement-metrics.test.js, etag-events-stats.test.js,
    routes/operational.test.js, health-deep.test.js,
    openapi-routes.test.js: 30/30 passing.

Note

Stacked on #406/#407/#408 for the reasons noted there; the metrics-group
change is src/routes/meta.ts (cursor-helper refactor only),
src/routes/metrics.ts, src/cursorPagination.ts, docs/metrics.md,
and the new test file.

The pr-404 merge left literal <<<<<<</=======/>>>>>>> markers in
devDependencies, producing invalid JSON and breaking npm install for
every contributor. Resolves to typescript@^6.0.3 with
typescript-eslint@^8.65.0: the currently published typescript-eslint
(8.65.0) only supports typescript <6.1.0, so pairing it with the
typescript@^7.0.2 side of the conflict leaves the dependency tree
unresolvable.
- Reject unknown query parameters on /health, /api/v1/health/ready, and
  /api/v1/health/deep with a structured 400 invalid_request.
- Add a checks array to /api/v1/health/deep exposing per-subsystem status
  (event log, usage/services/webhook/API-key stores, memory), with
  opaque-cursor pagination (limit default 10, max 50) matching the
  existing events-log cursor contract.
- Add docs/health.md covering all three routes, the new pagination
  contract, and error codes.
- Add src/health-deep.test.ts covering success, pagination, malformed
  cursor, and unknown-query-param rejection.
- Extract the since/type/limit/cursor parsing preamble in
  GET /api/v1/events into parseEventsListQuery(), a single entry point
  for the bounded query contract.
- Reject unknown query parameters on both /api/v1/events and
  /api/v1/events/summary with a structured 400 invalid_request, instead
  of silently ignoring typos.
- Expand docs/events.md into a full API contract doc: both routes,
  request/response examples, and an error-codes table.
- Add src/events-query-validation.test.ts covering the new rejection
  behavior and confirming documented parameters still work.

Cursor pagination on the events listing (GrantFox Agentpay-Org#392) was already
implemented prior to this change; this PR hardens and documents it
rather than re-adding it.
…ct cursor helper

- Extract the opaque-cursor pagination logic (previously duplicated
  inline in the health-checks handler) into a generic, reusable
  paginateByCursor() in src/cursorPagination.ts, and refactor the health
  route to use it.
- Reject unknown query parameters on /api/v1/metrics and /api/v1/stats
  with a structured 400 invalid_request.
- Add a cursor-paginated servicesBreakdown (per-service price and
  outstanding requests) to GET /api/v1/stats, using the same shared
  pagination helper (limit default 50, max 500).
- Document both routes in docs/metrics.md, including the new stats
  contract, an example response, and an error-codes table.
- Add src/stats-breakdown.test.ts covering pagination, malformed cursor,
  unknown-query-param rejection, and idempotent repeat requests.
@thlpkee20-wq

Copy link
Copy Markdown
Contributor Author

Closing to re-split into one PR per issue instead of one PR per group. Follow-up PRs each closing a single issue are incoming.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

1 participant