✨ Validate book store write endpoints with zod schemas#1260
Merged
Conversation
Contributor
There was a problem hiding this comment.
Pull request overview
This PR introduces Zod-based request validation for LikeNFT book store write endpoints, replacing bespoke validation helpers and adding a reusable Express validation middleware.
Changes:
- Added Zod schemas for NFT book store write request bodies (prices, listing settings, image upload).
- Added
validateBody/validateQuery/validateParamsmiddleware to enforce schemas and return structured validation errors. - Removed legacy
validatePrice/validatePriceshelpers and wired routes to schema validation.
Reviewed changes
Copilot reviewed 5 out of 6 changed files in this pull request and generated 3 comments.
Show a summary per file
| File | Description |
|---|---|
| src/util/api/likernft/book/schemas.ts | New Zod schemas for bookstore write endpoints (prices/listing/settings/image upload). |
| src/util/api/likernft/book/index.ts | Removes legacy manual price validation helpers. |
| src/routes/likernft/book/store.ts | Applies validateBody(...) to write endpoints and adjusts logic accordingly. |
| src/middleware/validate.ts | New generic Zod validation middleware producing ValidationError('INVALID_INPUT') with issue details. |
| package.json | Adds zod dependency. |
| package-lock.json | Locks zod dependency. |
| hideAudio: z.boolean().optional(), | ||
| hideUpsell: z.boolean().optional(), | ||
| enableCustomMessagePage: z.boolean().optional(), | ||
| tableOfContents: z.unknown().optional(), |
Comment on lines
+15
to
+19
| function makeValidator(target: Target) { | ||
| return <T>(schema: ZodSchema<T>): RequestHandler => (req, _res, next) => { | ||
| const result = schema.safeParse(req[target]); | ||
| if (!result.success) { | ||
| next(new ValidationError('INVALID_INPUT', 400, { |
Comment on lines
+41
to
+45
| const ConnectedWalletsSchema = z.record(z.string(), z.number()); | ||
|
|
||
| export const ListingSettingsBodySchema = z.object({ | ||
| moderatorWallets: z.array(z.string()).optional(), | ||
| connectedWallets: ConnectedWalletsSchema.optional(), |
Adds validateBody/validateQuery/validateParams middleware that bridges
zod parse errors into the existing ValidationError contract, and wires
it into every /likernft/book/store write endpoint that book-press calls
(new listing, settings update, price create/update/reorder, image
upload). validatePrice and validatePrices in util/api/likernft/book now
delegate to the new schemas, keeping the helper signatures intact.
Failures from migrated endpoints emit a generic INVALID_INPUT code with
a structured payload { target, issues: [{ path, code, message }] }
instead of the previous per-field codes (INVALID_PRICE,
INVALID_PRICE_STOCK, INVALID_PRICE_NAME, PRICES_ARE_EMPTY, etc.).
Clients should read error payload.issues for the failing field path.
nwingt
approved these changes
May 20, 2026
Comment on lines
+15
to
+23
| function makeValidator(target: Target) { | ||
| return <T>(schema: ZodSchema<T>): RequestHandler => (req, _res, next) => { | ||
| const result = schema.safeParse(req[target]); | ||
| if (!result.success) { | ||
| next(new ValidationError('INVALID_INPUT', 400, { | ||
| target, | ||
| issues: formatIssues(result.error.issues), | ||
| })); | ||
| return; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
No description provided.