refactor(ack-pay): extract and harden expiresAt timestamp schema#120
refactor(ack-pay): extract and harden expiresAt timestamp schema#120EfeDurmaz16 wants to merge 1 commit into
Conversation
The expiresAt transform called new Date(input).toISOString() directly, so an unparseable value threw a RangeError out of safeParse instead of producing a validation error. Extract a shared timestampSchema that rejects unparseable dates before normalizing to ISO, keeping valibot and zod in accept/reject parity. Revives agentcommercekit#104 (closed after agentcommercekit#116 changed the schema layout), rescoped to the current valibot.ts + zod.ts layout per maintainer request. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Organization UI Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (4)
WalkthroughIntroduces a shared ChangesShared Timestamp Schema Validation Fix
Estimated code review effort: 2 (Simple) | ~10 minutes Related PRs: None identified. Suggested labels: patch, ack-pay, bug-fix Suggested reviewers: None identified. 🐰 A date once caused a crash so dire, 🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✨ Finishing Touches🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
Summary
Revives #104 (closed after #116 changed the schema layout), rescoped to the current
valibot.ts+zod.tslayout — @venables invited a fresh PR against the new layout.timestampSchemaforpaymentRequestSchema.expiresAtexpiresAttransformed vianew Date(input).toISOString()directly, so a value like"invalid-date"threw aRangeErrorout ofsafeParserather than producing a validation errorschemas.test.tscovering both the rejection path and the happy-path normalization to ISO across both schemas (the load-bearing transform, per @venables' request on refactor(ack-pay): extract timestamp schemas #104)Why
new Date("invalid").toISOString()throws aRangeError. Callers usingsafeParseexpect a{ success: false }result, not an exception. The shared schema validates the date is parseable before normalizing.Verification
pnpm run buildpnpm run check(build + format + type-aware lint + typecheck + test) — all green, lint 0/0pnpm --filter @agentcommercekit/ack-pay test— 36 passing (incl. newschemas.test.ts)Notes
Kept the permissive
new Date()parse check rather than valibot'sisoTimestamp/ zod's.datetime()— narrowing the acceptedexpiresAtset to ISO-only is a deliberate contract change and out of scope for this dedup, same rationale as on #104. Happy to follow up with a stricter, parity-matched version if preferred.AI Usage Disclosure
This contribution was AI-assisted using Claude Code (Claude Opus). AI assistance was used to port the original #104 change onto the new schema layout, adapt the test to the two-schema (valibot + zod) structure, and run verification (
pnpm run check). I reviewed the final diff and understand what it does — it validatesexpiresAtis a parseable date before normalizing to an ISO string, keeping valibot and zod in parity — and take responsibility for the submitted changes.Summary by CodeRabbit
expiresAtvalues now fail validation cleanly instead of causing runtime errors.