Skip to content

feat: add Zod response-shape guard for analytics payloads - #720

Merged
Jagadeeshftw merged 2 commits into
Stellopay:mainfrom
alade-dev:feature/analytics-response-schema-guard
Jul 30, 2026
Merged

feat: add Zod response-shape guard for analytics payloads #720
Jagadeeshftw merged 2 commits into
Stellopay:mainfrom
alade-dev:feature/analytics-response-schema-guard

Conversation

@alade-dev

Copy link
Copy Markdown
Contributor

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:

  • src/routes/analytics.ts — AnalyticsChartPoint, AnalyticsResponse schemas and assertAnalyticsResponseShape() guard
  • src/routes/analytics.test.ts — 5 new tests covering acceptance, rejection, and production no-op
  • docs/routes/analytics.md — documents the response shape and guard behavior

Teslim Ibisomi and others added 2 commits July 30, 2026 09:50
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
@Jagadeeshftw
Jagadeeshftw merged commit 96fad6e into Stellopay:main Jul 30, 2026
1 check passed
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 response-shape assertions for aggregation payloads in src/routes/analytics.ts to catch contract drift outside production

2 participants