Skip to content

feat: input validation usage - #1050

Merged
greatest0fallt1me merged 1 commit into
CalloraOrg:mainfrom
fredericklamar342-prog:task/usage-validate
Jul 29, 2026
Merged

feat: input validation usage#1050
greatest0fallt1me merged 1 commit into
CalloraOrg:mainfrom
fredericklamar342-prog:task/usage-validate

Conversation

@fredericklamar342-prog

Copy link
Copy Markdown
Contributor

Description

Implements Zod-validated input schema for usage (Issue #651 — GrantFox FWC26 campaign, buffer #14).

Changes

  • src/validators/usage.ts — New validator module with exported UsageQuerySchema (Zod schema) and inferred UsageQueryInput type. Schema validates:

    • from / to: ISO-8601 datetime strings (optional, with cross-field check that from <= to)
    • apiId: optional filter string
    • groupBy: "day" | "week" | "month" (optional)
    • limit: coerced integer, 1–100, default 20
    • cursor / after / before: cursor pagination tokens (optional)
    • offset: coerced non-negative integer (optional)
  • src/routes/usage.ts — Removed inline UsageQuerySchema, now imports from ../validators/usage.js. Removed unused z import.

  • src/validators/usage.test.ts — 30 focused unit tests covering:

    • Default values (limit defaults to 20)
    • limit bounds (0 rejected, 1–100 accepted, decimals/non-integers rejected)
    • offset validation (zero accepted, negative rejected)
    • from/to date ordering (from after to rejected)
    • groupBy enum (valid values accepted, invalid rejected)
    • apiId handling
    • cursor/after/before acceptance
    • All-fields-together smoke test
    • Empty-object defaults

Testing

  • All existing usage route tests (src/routes/__tests__/usage.test.ts) pass
  • New validator unit tests pass
  • TypeScript compilation clean (no type errors)
  • Follows project conventions: co-located validator, safeParse usage, standardized error envelope

Closes #651

@drips-wave

drips-wave Bot commented Jul 29, 2026

Copy link
Copy Markdown

@fredericklamar342-prog 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
greatest0fallt1me merged commit 13a56e1 into CalloraOrg:main Jul 29, 2026
1 check passed
@greatest0fallt1me

Copy link
Copy Markdown
Contributor

LGTM ✅ solid work — thanks for taking this on!

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 input validation for usage (buffer #14)

2 participants