feat: add Zod response-shape guard for analytics payloads - #720
Merged
Jagadeeshftw merged 2 commits intoJul 30, 2026
Merged
Conversation
Add a Zod schema (AnalyticsResponse) validating the outbound analytics payload shape in src/routes/analytics.ts. The guard runs .parse() on every request outside NODE_ENV=production, logging (not crashing) on mismatch. In production the parse is skipped for zero latency. Includes: - AnalyticsChartPoint and AnalyticsResponse schemas - assertAnalyticsResponseShape() guard with console.error logging - 5 new tests verifying schema acceptance, rejection, and prod no-op - docs/routes/analytics.md documenting the response shape and guard
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.
Closes #680
Adds a Zod schema (AnalyticsResponse) that validates the outbound analytics response shape on every request outside production. When NODE_ENV !== "production", the guard runs .parse() against the payload and logs any shape drift via console.error without crashing the request. In production the parse is skipped entirely for zero latency.
This catches silent contract drift (e.g., renamed or dropped fields) in CI and development before it reaches clients.
Changes: