Skip to content

Add zod input validation for /api/devices (#621) - #742

Merged
greatest0fallt1me merged 1 commit into
Predictify-org:mainfrom
ByteForce-Labs:feat/issue-621-devices-zod-validation
Jul 29, 2026
Merged

Add zod input validation for /api/devices (#621)#742
greatest0fallt1me merged 1 commit into
Predictify-org:mainfrom
ByteForce-Labs:feat/issue-621-devices-zod-validation

Conversation

@ByteForce-Labs

Copy link
Copy Markdown

Description

Adds Zod input validation for the /api/devices endpoints with structured 400 errors.

Changes

src/validators/devices.ts (new)

  • listDevicesQuerySchema — validates GET query params (empty, rejects unknown via .strict())
  • deviceIdParamSchema — validates POST :id path param as UUID
  • Exports inferred TypeScript types via z.infer<>

src/routes/devices.ts

  • Imports and validates req.query with listDevicesQuerySchema.safeParse(); throws ZodError on failure

src/routes/devicesRevoke.ts

  • Replaced inline paramsSchema with imported deviceIdParamSchema from validators
  • Changed validation error to throw parsed.error (ZodError) directly instead of RouteErrorFactory.validation(), producing consistent 400 with validation_error code

tests/devices.test.ts

  • Added test: rejects unknown query parameters (400 + validation_error)
  • Wired errorHandler middleware into test app

tests/devicesRevoke.test.ts

  • Wired errorHandler middleware into test app

Test coverage

All 6 devices tests pass (3 list, 3 revoke), including new validation coverage for unknown query params and malformed UUIDs.

Closes #621

- Create src/validators/devices.ts with listDevicesQuerySchema and
  deviceIdParamSchema, following existing validator patterns
- Add Zod query validation to GET /api/me/devices (rejects unknown params)
- Refactor POST /api/me/devices/:id/revoke to import schema from validators
  and throw ZodError directly for consistent 400 validation_error response
- Add tests for unknown query param rejection
- Wire errorHandler into test apps for proper error response handling
@drips-wave

drips-wave Bot commented Jul 29, 2026

Copy link
Copy Markdown

@ByteForce-Labs 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

@greatest0fallt1me

Copy link
Copy Markdown
Contributor

Closes #621

(auto-added on behalf of @ByteForce-Labs so the linked issue closes on merge)

@greatest0fallt1me
greatest0fallt1me merged commit a93b9a3 into Predictify-org:main Jul 29, 2026
1 check passed
@greatest0fallt1me

Copy link
Copy Markdown
Contributor

LGTM ✅ green CI, clean work — merging!

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.

Add zod input validation for /api/devices [b#047]

3 participants