Skip to content

Add CSV/JSON revenue export endpoint for developers #375

@greatest0fallt1me

Description

@greatest0fallt1me

Description

GET /api/developers/revenue (src/routes/developerRoutes.ts:134-137, validated by the revenueQuerySchema Zod object at src/routes/developerRoutes.ts:38) returns a paginated JSON summary of settlements and aggregated earnings via res.json(...). Developers reconciling payouts for accounting have no machine-friendly bulk export and must page through JSON. This issue adds a downloadable export (CSV and full JSON) of a developer's settlement and revenue history.

Requirements and context

  • Add GET /api/developers/revenue/export (authenticated via the existing requireAuth middleware used in src/routes/developerRoutes.ts).
  • Support format=csv and format=json query params; reuse the same revenue aggregation/data source already feeding GET /api/developers/revenue so totals stay consistent (the route already computes "only positive amounts count" — see src/routes/developerRoutes.ts:176).
  • For CSV, set Content-Type: text/csv and a Content-Disposition: attachment filename; emit a stable header row (e.g. settlement id, amount_usdc, status, tx_hash, created_at, completed_at) drawn from the Settlement shape in src/types/developer.ts.
  • Validate format with a Zod schema via the shared validate(...) middleware (src/middleware/validate.ts), mirroring how revenueQuerySchema is applied at src/routes/developerRoutes.ts:137.
  • Non-functional: enforce a bounded maximum row count or date window to avoid unbounded responses; respect the per-user REST rate limiting already applied to developer traffic.

Acceptance criteria

  • GET /api/developers/revenue/export?format=csv returns text/csv with an attachment disposition and a deterministic header row.
  • GET /api/developers/revenue/export?format=json returns the full export as JSON.
  • Monetary values use the same smallest-unit/positive-amount semantics as GET /api/developers/revenue.
  • Invalid format values return the standard 400 validation envelope (code, message, details).
  • An unauthenticated request returns 401.
  • Tests cover CSV escaping (commas/quotes in fields), JSON output, and the auth/validation paths.

Suggested execution

1. Fork the repo and create a branch

git checkout -b feature/developer-revenue-export

2. Implement changes — add the export route and a small CSV serializer in src/routes/developerRoutes.ts (or a src/lib/ helper); add the format Zod schema.
3. Write/extend tests — extend src/__tests__/developerRevenue.test.ts and/or add a new *.test.ts (Jest + supertest).
4. Test and commit

npm run lint
npm run typecheck
npm test -- developerRevenue --runInBand

Example commit message

feat(developers): add CSV/JSON revenue export endpoint

Guidelines

Maintain the repo's 90%+ coverage target (README.md). Add JSDoc to the new route describing query params and response formats, and document the endpoint in README.md next to the existing developer endpoints. Timeframe: 96 hours.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions