Description
app/api/streams/route.ts and app/api/v2/streams/route.ts only check that recipient, rate, and schedule are present, then store them as raw strings — no Stellar address validation, no numeric/precision validation on rate, no allowed-values check on schedule. Add strict server-side schema validation so malformed streams cannot be created. This is a backend input-validation task.
Requirements and Context
- Validate
recipient as a Stellar public key using isValidStellarPublicKey from app/lib/wallet-link.ts.
- Validate
rate against the money/precision rules in app/lib/amount.ts (positive, bounded decimals).
- Validate
schedule against the supported set in app/lib/schedules.ts.
- Return
422 VALIDATION_ERROR with per-field detail; share validation between v1 and v2 handlers.
- Must be secure, tested, and documented
- Should be efficient and easy to review
Suggested Execution
- Fork the repo and create a branch
git checkout -b task/streams-create-validation
- Implement changes
app/api/streams/route.ts, app/api/v2/streams/route.ts
app/lib/stream-validation.ts (new) — shared validator using amount.ts, schedules.ts, wallet-link.ts
- Test and commit
npm test -- app/api/streams
- Cover edge cases: bad public key, negative/over-precision rate, unknown schedule
- Include test output and notes in the PR
Example commit message
task: add strict schema validation to stream creation
Acceptance Criteria
Guidelines
- Minimum 90% test coverage including each invalid-field case
- Clear documentation and inline comments
- Timeframe: 96 hours
Description
app/api/streams/route.tsandapp/api/v2/streams/route.tsonly check thatrecipient,rate, andscheduleare present, then store them as raw strings — no Stellar address validation, no numeric/precision validation onrate, no allowed-values check onschedule. Add strict server-side schema validation so malformed streams cannot be created. This is a backend input-validation task.Requirements and Context
recipientas a Stellar public key usingisValidStellarPublicKeyfromapp/lib/wallet-link.ts.rateagainst the money/precision rules inapp/lib/amount.ts(positive, bounded decimals).scheduleagainst the supported set inapp/lib/schedules.ts.422 VALIDATION_ERRORwith per-field detail; share validation between v1 and v2 handlers.Suggested Execution
app/api/streams/route.ts,app/api/v2/streams/route.tsapp/lib/stream-validation.ts(new) — shared validator usingamount.ts,schedules.ts,wallet-link.tsnpm test -- app/api/streamsExample commit message
Acceptance Criteria
422Guidelines