Description
src/api/v1/streams.ts exposes GET /, GET /:id, GET /:id/accrual-preview, and PATCH /:id, but there is no POST / to create a stream — even though docs/ARCHITECTURE.md and the OpenAPI description advertise stream creation. The router also references AuditService (line 11), accrualService (line 47), and UpdateStreamParams (line 86) without importing them, so the file does not compile. This issue adds a validated creation endpoint and fixes the missing imports.
Requirements and context
- Import
AuditService from ../../services/auditService, accrualService from ../../services/accrualService, and UpdateStreamParams from ../../repositories/streamRepository.
- Add a
createStreamSchema to src/validation/schemas.ts (Zod) covering payer, recipient, ratePerSecond (positive decimal string), startTime, optional endTime, totalAmount, optional labels/offChainMemo.
- Add
POST / to streams.ts guarded by the existing validate(...) middleware, persisting via a new StreamRepository.create(...) (or db.insert) and returning 201 with the created stream including accruedEstimate.
- Record an audit entry via
AuditService on creation, consistent with auditActionEnum (stream_create).
- Non-functional: reject invalid/extra fields with
400; do not trust client-supplied id, status, or timestamps for invariants.
Acceptance criteria
Suggested execution
1. Fork the repo and create a branch — git checkout -b feature/create-stream-endpoint.
2. Implement changes — add the schema in src/validation/schemas.ts, the POST / handler in src/api/v1/streams.ts, and a repository create method.
3. Write/extend tests — this repo uses Jest + Supertest. Add cases to src/api/v1/streams.test.ts covering success (201), validation failure (400), and audit-log invocation using a mocked repository/service.
4. Test and commit —
npm run lint -- --max-warnings 0
npm run build
npm test
Example commit message
feat(api): add validated POST /api/v1/streams and fix router imports
Guidelines
Target >=90% coverage on new handler/validation code (repo standard 95% per jest.config.js). Update README.md and the OpenAPI spec. Timeframe: 96 hours.
Description
src/api/v1/streams.tsexposesGET /,GET /:id,GET /:id/accrual-preview, andPATCH /:id, but there is noPOST /to create a stream — even thoughdocs/ARCHITECTURE.mdand the OpenAPI description advertise stream creation. The router also referencesAuditService(line 11),accrualService(line 47), andUpdateStreamParams(line 86) without importing them, so the file does not compile. This issue adds a validated creation endpoint and fixes the missing imports.Requirements and context
AuditServicefrom../../services/auditService,accrualServicefrom../../services/accrualService, andUpdateStreamParamsfrom../../repositories/streamRepository.createStreamSchematosrc/validation/schemas.ts(Zod) coveringpayer,recipient,ratePerSecond(positive decimal string),startTime, optionalendTime,totalAmount, optionallabels/offChainMemo.POST /tostreams.tsguarded by the existingvalidate(...)middleware, persisting via a newStreamRepository.create(...)(ordb.insert) and returning201with the created stream includingaccruedEstimate.AuditServiceon creation, consistent withauditActionEnum(stream_create).400; do not trust client-suppliedid,status, or timestamps for invariants.Acceptance criteria
streams.tsimports resolve and the file compiles.POST /api/v1/streamswith a valid body returns201and the persisted stream.ratePerSecond, bad addresses) return400with Zod issues.stream_createaudit log entry is written on success.npm run buildandnpm testpass.src/api/v1/openapi.ts) documents the new endpoint.Suggested execution
1. Fork the repo and create a branch —
git checkout -b feature/create-stream-endpoint.2. Implement changes — add the schema in
src/validation/schemas.ts, thePOST /handler insrc/api/v1/streams.ts, and a repositorycreatemethod.3. Write/extend tests — this repo uses Jest + Supertest. Add cases to
src/api/v1/streams.test.tscovering success (201), validation failure (400), and audit-log invocation using a mocked repository/service.4. Test and commit —
npm run lint -- --max-warnings 0 npm run build npm testExample commit message
Guidelines
Target >=90% coverage on new handler/validation code (repo standard 95% per
jest.config.js). UpdateREADME.mdand the OpenAPI spec. Timeframe: 96 hours.