Skip to content

refactor(ack-pay): extract and harden expiresAt timestamp schema#120

Open
EfeDurmaz16 wants to merge 1 commit into
agentcommercekit:mainfrom
EfeDurmaz16:fix/dedupe-timestamp-schema
Open

refactor(ack-pay): extract and harden expiresAt timestamp schema#120
EfeDurmaz16 wants to merge 1 commit into
agentcommercekit:mainfrom
EfeDurmaz16:fix/dedupe-timestamp-schema

Conversation

@EfeDurmaz16

@EfeDurmaz16 EfeDurmaz16 commented Jul 1, 2026

Copy link
Copy Markdown
Contributor

Summary

Revives #104 (closed after #116 changed the schema layout), rescoped to the current valibot.ts + zod.ts layout — @venables invited a fresh PR against the new layout.

  • Extract a shared timestampSchema for paymentRequestSchema.expiresAt
  • Reject unparseable dates instead of throwing: previously expiresAt transformed via new Date(input).toISOString() directly, so a value like "invalid-date" threw a RangeError out of safeParse rather than producing a validation error
  • Keep valibot and zod in accept/reject parity
  • Add schemas.test.ts covering 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 a RangeError. Callers using safeParse expect a { success: false } result, not an exception. The shared schema validates the date is parseable before normalizing.

Verification

  • pnpm run build
  • pnpm run check (build + format + type-aware lint + typecheck + test) — all green, lint 0/0
  • pnpm --filter @agentcommercekit/ack-pay test — 36 passing (incl. new schemas.test.ts)

Notes

Kept the permissive new Date() parse check rather than valibot's isoTimestamp / zod's .datetime() — narrowing the accepted expiresAt set 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 validates expiresAt is 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

  • Bug Fixes
    • Invalid expiresAt values now fail validation cleanly instead of causing runtime errors.
    • Date inputs are now handled consistently, with valid values converted to ISO timestamps and invalid ones rejected.
  • Tests
    • Added coverage for both schema implementations to verify invalid dates are rejected and valid dates are normalized correctly.
  • Documentation
    • Added a release note entry describing the schema behavior update.

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>
@coderabbitai

coderabbitai Bot commented Jul 1, 2026

Copy link
Copy Markdown

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 36ab67e9-1344-40ba-b179-0db5b9c4ad45

📥 Commits

Reviewing files that changed from the base of the PR and between 30bc515 and c03092c.

📒 Files selected for processing (4)
  • .changeset/dedupe-timestamp-schema.md
  • packages/ack-pay/src/schemas.test.ts
  • packages/ack-pay/src/schemas/valibot.ts
  • packages/ack-pay/src/schemas/zod.ts

Walkthrough

Introduces a shared timestampSchema in both valibot and zod implementations of paymentRequestSchema to validate expiresAt values, causing invalid dates to fail validation instead of throwing a RangeError. Adds corresponding tests and a changeset for @agentcommercekit/ack-pay.

Changes

Shared Timestamp Schema Validation Fix

Layer / File(s) Summary
Valibot timestampSchema
packages/ack-pay/src/schemas/valibot.ts
Adds an internal timestampSchema validating parseable dates before transforming to ISO string, replacing the inline union/transform used for expiresAt.
Zod timestampSchema
packages/ack-pay/src/schemas/zod.ts
Adds a timestampSchema that transforms Date/string inputs to ISO strings, raising a custom Zod issue and returning z.NEVER on invalid dates, and reuses it for expiresAt.
Tests and changeset
packages/ack-pay/src/schemas.test.ts, .changeset/dedupe-timestamp-schema.md
Adds Vitest coverage confirming both schema variants reject invalid expiresAt via safeParse and normalize valid inputs to ISO strings, plus a changeset documenting the patch-level behavior change.

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,
Now timestampSchema puts out the fire,
Valibot and Zod both agree,
Invalid dates fail gracefully,
Tests confirm — no more RangeError ire!

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly summarizes the main change: extracting and hardening the expiresAt timestamp schema in ack-pay.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

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.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

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.

1 participant