Skip to content

refactor(ack-pay): extract timestamp schemas#104

Open
EfeDurmaz16 wants to merge 2 commits into
agentcommercekit:mainfrom
EfeDurmaz16:refactor/ack-pay-timestamp-schema
Open

refactor(ack-pay): extract timestamp schemas#104
EfeDurmaz16 wants to merge 2 commits into
agentcommercekit:mainfrom
EfeDurmaz16:refactor/ack-pay-timestamp-schema

Conversation

@EfeDurmaz16
Copy link
Copy Markdown

@EfeDurmaz16 EfeDurmaz16 commented May 25, 2026

Summary

  • extract the repeated payment request timestamp normalization into local timestampSchema helpers
  • reuse the helper from Valibot, Zod v3, and Zod v4 payment request schemas
  • keep behavior unchanged and avoid adding any new public API surface

Context

Split out from the review feedback on #96, where the timestamp schema extraction was identified as useful independently of the approval model proposal.

Verification

  • corepack pnpm install --frozen-lockfile
  • corepack pnpm --filter @agentcommercekit/ack-pay... build
  • corepack pnpm --filter @agentcommercekit/ack-pay test -- --run
  • corepack pnpm --filter @agentcommercekit/ack-pay check:types
  • corepack pnpm exec oxfmt --check packages/ack-pay/src/schemas/valibot.ts packages/ack-pay/src/schemas/zod/v3.ts packages/ack-pay/src/schemas/zod/v4.ts
  • git diff --check

Notes

  • The first targeted test/typecheck run failed before building workspace dependencies because local package exports resolve from built dist outputs. Building the ACK-Pay dependency graph fixed that, and the rerun passed.
  • No changeset is included because this is an internal refactor with no runtime behavior or exported API change.

AI Usage Disclosure

This contribution was AI-assisted using Codex CLI and the Codex app. AI assistance was used for repository/docs navigation, understanding ACK/Catena context, identifying relevant issues or contribution areas, and assisting with small edits/validation. I reviewed the final diff and take responsibility for the submitted changes.

Summary by CodeRabbit

  • Refactor

    • Consolidated timestamp validation across schema implementations for consistency.
  • Bug Fix

    • Validation now consistently rejects invalid timestamp inputs, preventing malformed dates.
  • Tests

    • Added cross-schema tests to ensure invalid expiry timestamps fail validation.

Review Change Stack

@coderabbitai
Copy link
Copy Markdown

coderabbitai Bot commented May 25, 2026

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: 54d09d4b-bdf2-40d4-8d2c-12cb1fca76a5

📥 Commits

Reviewing files that changed from the base of the PR and between b25481d and 224c426.

📒 Files selected for processing (4)
  • packages/ack-pay/src/schemas.test.ts
  • packages/ack-pay/src/schemas/valibot.ts
  • packages/ack-pay/src/schemas/zod/v3.ts
  • packages/ack-pay/src/schemas/zod/v4.ts
✅ Files skipped from review due to trivial changes (1)
  • packages/ack-pay/src/schemas.test.ts

Walkthrough

Extracts timestamp validation/normalization into module-local timestampSchema across valibot, Zod v3, and Zod v4, replaces inline union/transform logic in paymentRequestSchema.expiresAt with the shared schema, and adds a Vitest asserting invalid expiresAt is rejected by all three schemas.

Changes

Timestamp schema consolidation

Layer / File(s) Summary
Valibot timestamp schema
packages/ack-pay/src/schemas/valibot.ts
timestampSchema accepts Date or string, validates parsed date, transforms to ISO string; paymentRequestSchema.expiresAt now uses timestampSchema instead of inline union/transform.
Zod v3 timestamp schema
packages/ack-pay/src/schemas/zod/v3.ts
Adds timestampSchema for `Date
Zod v4 timestamp schema
packages/ack-pay/src/schemas/zod/v4.ts
Adds module-local timestampSchema that rejects invalid dates with a Zod issue and returns z.NEVER, transforms valid values to ISO string; paymentRequestSchema.expiresAt delegates to timestampSchema.optional().
Schemas validation tests
packages/ack-pay/src/schemas.test.ts
New Vitest suite constructs a payment request with an invalid expiresAt string and asserts validation fails for Valibot, Zod v3, and Zod v4 implementations.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

🚥 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 'refactor(ack-pay): extract timestamp schemas' accurately describes the main change: extracting repeated timestamp normalization logic into reusable schema helpers across three schema implementations.
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.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Warning

There were issues while running some tools. Please review the errors and either fix the tool's configuration or disable the tool if it's a critical failure.

🔧 ESLint

If the error stems from missing dependencies, add them to the package.json file. For unrecoverable errors (e.g., due to private dependencies), disable the tool in the CodeRabbit configuration.

ESLint skipped: no ESLint configuration detected in root package.json. To enable, add eslint to devDependencies.


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 and usage tips.

Copy link
Copy Markdown

@coderabbitai coderabbitai Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 3

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@packages/ack-pay/src/schemas/valibot.ts`:
- Around line 7-10: timestampSchema currently transforms a string/date by
calling new Date(input).toISOString(), which throws RangeError for invalid date
strings; change the schema to first validate that the input yields a valid Date
before transforming: within the v.pipe/v.union flow (timestampSchema) add a
refinement or pre-check (e.g., v.string().refine or a custom step) that parses
the input into a Date and checks !isNaN(date.getTime()), and only then call the
transform to toISOString(); ensure invalid inputs cause a validation error (via
refine failure) instead of allowing transform to throw.

In `@packages/ack-pay/src/schemas/zod/v3.ts`:
- Around line 7-9: The current timestampSchema uses .transform((val) => new
Date(val).toISOString()) which can throw RangeError for invalid strings; update
timestampSchema (the z.union of z.date() and z.string()) to first validate
inputs with a .refine() or .superRefine() that checks date validity (e.g., for
strings use Date.parse or new Date(val).getTime() and ensure it is not NaN, and
for Date objects ensure !isNaN(val.getTime())), and only then apply the
transform toISOString(), so the schema returns Zod validation errors instead of
throwing during the transform.

In `@packages/ack-pay/src/schemas/zod/v4.ts`:
- Around line 7-9: timestampSchema currently uses .transform((val) => new
Date(val).toISOString()) which can throw a RangeError for invalid date strings;
update the schema to validate the input before transforming by adding a
refinement (e.g., on the union of z.date() | z.string()) that checks the value
can be parsed to a valid Date (using Date.parse or isNaN(new
Date(...).getTime()) logic) and return a validation error if invalid, then
perform the .transform toISOString() only after the refinement succeeds; refer
to the timestampSchema, the .transform callback, and the z.union([z.date(),
z.string()]) as the locations to add the .refine()/.superRefine() check.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 04a95d74-16ec-4e29-8b25-b13fb9551f5d

📥 Commits

Reviewing files that changed from the base of the PR and between 6f65936 and b25481d.

📒 Files selected for processing (3)
  • packages/ack-pay/src/schemas/valibot.ts
  • packages/ack-pay/src/schemas/zod/v3.ts
  • packages/ack-pay/src/schemas/zod/v4.ts

Comment thread packages/ack-pay/src/schemas/valibot.ts
Comment thread packages/ack-pay/src/schemas/zod/v3.ts Outdated
Comment thread packages/ack-pay/src/schemas/zod/v4.ts Outdated
@EfeDurmaz16
Copy link
Copy Markdown
Author

Addressed the timestamp validation feedback in 224c426.

Changes:

  • validate timestamp inputs before ISO normalization in Valibot, Zod v3, and Zod v4 schemas
  • add a regression test covering invalid expiresAt strings across all three schema adapters

Verification:

  • corepack pnpm --filter @agentcommercekit/ack-pay test -- --run
  • corepack pnpm --filter @agentcommercekit/ack-pay check:types
  • corepack pnpm exec oxfmt --check packages/ack-pay/src/schemas/valibot.ts packages/ack-pay/src/schemas/zod/v3.ts packages/ack-pay/src/schemas/zod/v4.ts packages/ack-pay/src/schemas.test.ts
  • git diff --check

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