Skip to content

fix(rest/nodejs): validate line item quantity on create and update - #243

Closed
yuhuayang-google wants to merge 1 commit into
Universal-Commerce-Protocol:mainfrom
yuhuayang-google:fix/node-quantity-validation
Closed

yuhuayang-google wants to merge 1 commit into
Universal-Commerce-Protocol:mainfrom
yuhuayang-google:fix/node-quantity-validation

Conversation

@yuhuayang-google

Copy link
Copy Markdown

Summary

Fixes #194

In rest/nodejs, checkout creation and update previously accepted quantity: 0 and negative quantities because @ucp-js/sdk generated schemas in current published packages declare quantity as a bare z.number(). This allowed invalid quantities to flow through to totals math and create negative totals.

This change:

  1. Enforces that line item quantity is an integer >= 1 in both createCheckout and updateCheckout.
  2. Returns a standard UCP error envelope with code: "INVALID_REQUEST" and status 400 when an invalid quantity (negative, zero, or non-integer) is provided.
  3. Adds integration test coverage in rest/nodejs/test/validation_flow.test.ts verifying that checkout create and update reject zero, negative, and fractional quantities.

Testing

  • Ran npm test in rest/nodejs (all 165 tests pass).
  • Ran npm run build (tsc) in rest/nodejs to ensure TypeScript compiles without error.

Validate that line item quantity is an integer >= 1 on both checkout create and update requests, rejecting non-positive or non-integer values with an INVALID_REQUEST error envelope instead of allowing them to flow into totals math.

Fixes Universal-Commerce-Protocol#194
@damaz91 damaz91 added the status:needs-triage Signal that the PR is ready for human triage label Sep 29, 2026
@damaz91 damaz91 added status:under-review and removed status:needs-triage Signal that the PR is ready for human triage labels Oct 15, 2026
@damaz91

damaz91 commented Oct 15, 2026

Copy link
Copy Markdown
Contributor

Thank you so much for putting this together and adding thorough test coverage, @yuhuayang-google! 🙏

Issue #194 was recently resolved upstream at the Zod schema boundary via #199, which bumped @ucp-js/sdk to 0.4.5 (where LineItemCreateRequestSchema and LineItemUpdateRequestSchema enforce z.number().int().gte(1) and reject invalid quantities with 422 INVALID_REQUEST via prettyValidation, matching the Python reference implementation) and added regression coverage in rest/nodejs/test/quantity_bounds.test.ts.

Since the schema validation middleware now catches zero, negative, and non-integer quantities before reaching CheckoutService, I'll go ahead and close this PR as superseded by #199. Thanks again for contributing to UCP!

@damaz91 damaz91 closed this Oct 15, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Node checkout accepts quantity 0 and negative quantity, producing negative checkout totals

2 participants