refactor(streak): introduced zod schema for API parameter validation#124
refactor(streak): introduced zod schema for API parameter validation#124Subhooo5 wants to merge 2 commits into
Conversation
|
@Subhooo5 is attempting to deploy a commit to the jhasourav07's projects Team on Vercel. A member of the Team first needs to authorize it. |
c827b62 to
d3a01fd
Compare
|
Hey @JhaSourav07 , please feel free to review the PR and merge the same. It satisfies all the acceptance criteria. Thank you 🚀🫂. |
|
@JhaSourav07 I accidentally named the branch on my fork as |
|
@Subhooo5 |
|
Can you please review this PR. |
d3a01fd to
42af8cb
Compare
All Done @JhaSourav07 🚀. Feel free to check and authorize. |
…EADME workflow description
87dd2d4 to
e98f260
Compare
Description
Fixes #67
Introduces zod for strict validation of incoming URL parameters across all three API routes, replacing scattered manual
searchParams.get()calls and if/else fallbacks with a single centralized schema.New file
lib/validations.ts:Defines
streakParamsSchema,githubParamsSchema, andogParamsSchemausingZod. Default values (theme: "dark", scale: "linear", speed: "8s") are handled via Zod's.default(). Invalid speed and scale values silently fall back to their defaults using.catch()to preserve existing behavior. The user and username fields are required and return a structured JSON error if missing.Changes in
app/api/streak/route.ts:Replaced all individual
searchParams.get()calls with a singlestreakParamsSchema.safeParse()call at the top of the handler. If parsing fails (e.g. missing user), the route returns a clean structured JSON 400 error immediately before any GitHub API call is made. All downstream logic remains identical.Changes in
app/api/github/route.ts:Replaced manual
searchParams.get('username')andif (!username)check withgithubParamsSchema.safeParse(). Returns a structured JSON 400 error if username is missing. All error handling and cache logic remains identical.Changes in
app/api/og/route.tsx:Replaced
searchParams.get('user')?? 'unknown' withogParamsSchema.parse(). Since user is optional with a default of 'unknown', this route never throws a validation error. All rendering logic remains identical.Added 4 additional optional properties —
radius,font,year, andrefresh{Other than the requested ones}.All Acceptance Criteria are met. 🚀
Pillar
Visual Preview
Checklist before requesting a review:
CONTRIBUTING.mdfile.localhost:3000/api/streak).npm run formatandnpm run lintlocally and resolved all errors.