Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/payment-option-safe-integer-amount.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@agentcommercekit/ack-pay": patch
---

Reject unsafe integer numbers on the payment option amount number arm so valibot matches zod (and Number.isSafeInteger), keeping the string arm for amounts larger than the safe integer range.
7 changes: 7 additions & 0 deletions packages/ack-pay/src/schemas/payment-option.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,4 +34,11 @@ describe("paymentOptionSchema amount", () => {
expect(acceptsAmount(amount)).toEqual({ valibot: false, zod: false })
},
)

it.each([Number.MAX_SAFE_INTEGER + 1, 1e21])(
"rejects an unsafe integer number amount %s",
(amount) => {
expect(acceptsAmount(amount)).toEqual({ valibot: false, zod: false })
},
)
})
3 changes: 2 additions & 1 deletion packages/ack-pay/src/schemas/valibot.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,8 @@ const timestampSchema = v.pipe(
export const paymentOptionSchema = v.object({
id: v.string(),
amount: v.union([
v.pipe(v.number(), v.integer(), v.gtValue(0)),
// Unsafe integers are not exact; use the string arm for large amounts.
v.pipe(v.number(), v.safeInteger(), v.gtValue(0)),
positiveIntegerString,
]),
decimals: v.pipe(v.number(), v.integer(), v.toMinValue(0)),
Expand Down