Task/webhooks validate v7#540
Merged
greatest0fallt1me merged 3 commits intoJul 26, 2026
Merged
Conversation
- Add Zod schemas in src/validators/webhooks.ts for: - listWebhooksQuerySchema (GET /api/webhooks) - dlqQuerySchema (GET /api/admin/webhooks/dlq) - dlqReplayParamsSchema (POST /api/admin/webhooks/dlq/:id/replay) - Refactor src/routes/webhooks.ts to use centralized validator - Add structured logging and Zod validation to adminWebhooks.ts - Fix broken webhooksRouter import in src/index.ts - Fix missing accessLog import in src/routes/predictions.ts
- 38 tests covering schema unit tests and integration tests - Tests for listWebhooksQuerySchema, dlqQuerySchema, dlqReplayParamsSchema - Integration tests for auth, validation errors, pagination, requestId
|
@Paranoa-dev 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! 🚀 |
Contributor
|
Merged via direct push to main (admin) |
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.
feat: input validation /api/webhooks
Summary
Adds Zod-validated input schemas for all
/api/webhooksendpoints, replacing inline ad-hoc validation with centralized, reusable validators. Follows the established pattern fromsrc/validators/markets.tsandsrc/validators/predictions.ts.Changes
New file:
src/validators/webhooks.tslistWebhooksQuerySchema-- validatesGET /api/webhooksquery params (cursor,limit). Uses.strict()to reject unknown params. Coerces string limits to integers with range 1-100.dlqQuerySchema-- validatesGET /api/admin/webhooks/dlqquery params (same shape as above).dlqReplayParamsSchema-- validatesPOST /api/admin/webhooks/dlq/:id/replayroute params using Zod's.uuid()validator.Modified:
src/routes/webhooks.tswebhooksQuerySchema(regex-based string limit validation).listWebhooksQuerySchemafrom centralized validators.z.coerce.number()for type-safe limit parsing with proper integer and range validation.Modified:
src/routes/adminWebhooks.tsGET /dlqquery params viadlqQuerySchema(previously rawreq.querywith no validation).POST /dlq/:id/replayparams viadlqReplayParamsSchema(replaced manual UUID regex)./* eslint-disable @typescript-eslint/no-explicit-any */and replacedanycast with typedReplayResultinterface.Bugfixes (pre-existing)
src/index.ts-- Fixed brokenwebhooksRouterimport (exportedcreateWebhooksRouter, notwebhooksRouter). Router is now conditionally created via factory whenoptions.webhooksis provided.src/routes/predictions.ts-- Added missingaccessLogmiddleware import that blocked all tests usingcreateApp.Tests
New file:
tests/webhooksValidation.test.ts38 tests, all passing:
Schema unit tests (19):
listWebhooksQuerySchema-- valid inputs, empty cursor, zero/negative/non-integer/max limit, unknown paramsdlqQuerySchema-- empty query, valid params, unknown params, zero/max limitdlqReplayParamsSchema-- valid UUID, invalid format, empty string, wrong length, non-hex charsIntegration tests (19):
GET /api/webhooks-- auth (403 without/with non-admin), validation (400 for bad limit/cursor/unknown params), success (200 with valid params, pagination, requestId in errors)GET /api/admin/webhooks/dlq-- auth, validation for limit and unknown paramsPOST /api/admin/webhooks/dlq/:id/replay-- auth, 400 for invalid UUID, 404 for non-existent rowValidation Behavior
All endpoints now return a standardized error envelope on invalid input:
{ "error": { "code": "validation_error", "message": "<specific Zod error message>", "requestId": "<correlation ID>" } }Unknown query parameters are rejected (
.strict()mode) to keep route boundaries explicit and avoid silently ignoring malformed input.Files Changed
src/validators/webhooks.tssrc/routes/webhooks.tssrc/routes/adminWebhooks.tssrc/routes/predictions.tssrc/index.tstests/webhooksValidation.test.tsChecklist
Closes #433