Skip to content

feat(backend): add Zod validation to campaign endpoints#1190

Merged
Emmyt24 merged 1 commit into
nova-launch01:mainfrom
hman38705:feat/backend-campaign-zod-validation
May 28, 2026
Merged

feat(backend): add Zod validation to campaign endpoints#1190
Emmyt24 merged 1 commit into
nova-launch01:mainfrom
hman38705:feat/backend-campaign-zod-validation

Conversation

@hman38705

Copy link
Copy Markdown
Contributor

Summary

  • Introduces src/lib/validation/campaignSchemas.ts with typed Zod schemas for every campaign endpoint.
  • Replaces the express-validator middleware in campaigns.ts with the new Zod-backed validators.
  • All invalid requests receive a structured 400 with per-field error messages.
  • .strict() on the POST body schema strips unknown fields, preventing mass-assignment.

Schemas added

Schema Covers
CreateCampaignSchema POST /api/campaigns body
CampaignIdParamSchema /:campaignId route param
CampaignTokenParamSchema /token/:tokenId param
CampaignCreatorParamSchema /creator/:creator param (G-address)
CampaignExecutionQuerySchema limit (1–200), offset (≥ 0)

Validation rules (POST body)

  • tokenId — non-empty string
  • creator — valid Stellar G-address regex
  • type — enum BUYBACK | AIRDROP | LIQUIDITY
  • targetAmount — integer string > 0
  • startTime / endTime — ISO 8601; endTime must be after startTime
  • metadata — optional string ≤ 1 024 chars
  • Unknown fields rejected (.strict())

Test plan

  • Valid body accepted
  • Missing / invalid fields rejected with descriptive messages
  • endTime before startTime rejected
  • metadata > 1024 chars rejected
  • Unknown fields rejected
  • campaignId param, creator param, execution query params validated

Closes #1105

🤖 Generated with Claude Code

Introduces src/lib/validation/campaignSchemas.ts with typed Zod schemas
for every campaign endpoint:

- CreateCampaignSchema (POST body) — validates Stellar address, campaign
  type enum, positive integer targetAmount, ISO 8601 dates with
  endTime > startTime, 1 KB metadata cap, and strips unknown fields via
  .strict() to prevent mass-assignment.
- CampaignIdParamSchema (:campaignId route param)
- CampaignTokenParamSchema (:tokenId route param)
- CampaignCreatorParamSchema (:creator param — must be G-address)
- CampaignExecutionQuerySchema (limit 1-200, non-negative offset)

All invalid requests receive a structured 400 with per-field messages.
Removes the previous express-validator middleware from campaigns.ts and
replaces it with the new Zod-backed validateXxx helpers.

Closes nova-launch01#1105

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
@drips-wave

drips-wave Bot commented May 27, 2026

Copy link
Copy Markdown

@hman38705 Great news! 🎉 Based on an automated assessment of this PR, the linked Wave issue(s) no longer count against your application limits.

You can now already apply to more issues while waiting for a review of this PR. Keep up the great work! 🚀

Learn more about application limits

@Emmyt24 Emmyt24 merged commit 94655e4 into nova-launch01:main May 28, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Enforce schema validation on all campaign endpoints with Zod

2 participants