Skip to content

fix(rest/nodejs): enforce integer and minimum bounds on line item quantity - #198

Closed
damaz91 wants to merge 1 commit into
Universal-Commerce-Protocol:mainfrom
damaz91:fix/nodejs-line-item-quantity
Closed

fix(rest/nodejs): enforce integer and minimum bounds on line item quantity#198
damaz91 wants to merge 1 commit into
Universal-Commerce-Protocol:mainfrom
damaz91:fix/nodejs-line-item-quantity

Conversation

@damaz91

@damaz91 damaz91 commented Aug 20, 2026

Copy link
Copy Markdown
Contributor

Description

In published @ucp-js/sdk packages (0.4.3 / 0.4.4), LineItemCreateRequestSchema and LineItemUpdateRequestSchema defined quantity as an unconstrained z.number(), omitting the integer (.int()) and minimum (.gte(1)) constraints specified in line_item.json.

Consequently, checkout creation and update requests with quantity <= 0 or non-integer floating values passed route schema validation, propagating invalid quantities into recalculateTotals and producing negative totals as well as incorrect inventory reservations.

This PR:

  • Extends LineItemCreateRequestSchema and LineItemUpdateRequestSchema to enforce quantity: z.number().int().gte(1) in rest/nodejs/src/models/index.ts.
  • Rebuilds CheckoutCreateRequestSchema, CheckoutUpdateRequestSchema, ExtendedCheckoutCreateRequestSchema, and ExtendedCheckoutUpdateRequestSchema to use these constrained line item schemas.
  • Adds regression unit test coverage in rest/nodejs/test/validation_flow.test.ts for checkout create and update with quantity 0, -1, and fractional numbers (1.5, 2.5), verifying they are rejected with HTTP 422.

Category (Required)

  • Core Protocol: Changes to the base communication layer, global context, or breaking refactors. (Requires Technical Council approval)
  • Governance/Contributing: Updates to GOVERNANCE.md, CONTRIBUTING.md, or CODEOWNERS. (Requires Governance Council approval)
  • Capability: New schemas (Discovery, Cart, etc.) or extensions. (Requires Maintainer approval)
  • Documentation: Updates to README, or documentations regarding schema or capabilities. (Requires Maintainer approval)
  • Infrastructure: CI/CD, Linters, or build scripts. (Requires DevOps Maintainer approval)
  • Maintenance: Version bumps, lockfile updates, or minor bug fixes. (Requires DevOps Maintainer approval)
  • SDK: Language-specific SDK updates and releases. (Requires DevOps Maintainer approval)
  • Samples / Conformance: Maintaining samples and the conformance suite. (Requires Maintainer approval)
  • UCP Schema: Changes to the ucp-schema tool (resolver, linter, validator). (Requires Maintainer approval)
  • Community Health (.github): Updates to templates, workflows, or org-level configs. (Requires DevOps Maintainer approval)

Related Issues

Fixes #194

Checklist

  • I have followed the Contributing Guide (including Conventional Commits title requirements and ! for breaking changes).
  • I have updated the documentation (if applicable).
  • My changes pass all local linting and formatting checks.
  • I have added tests that prove my fix is effective or that my feature works.
  • New and existing unit tests pass locally with my changes.
  • (For Core/Capability) I have included/updated the relevant JSON schemas.
  • I have regenerated Python Pydantic models by running generate_models.sh under python_sdk.

…ntity

- In the published @ucp-js/sdk (0.4.3 / 0.4.4), LineItemCreateRequestSchema and LineItemUpdateRequestSchema generated quantity as an unconstrained number without integer or minimum value checks.
- As a result, checkout creation and update requests with quantity <= 0 or floating-point numbers passed schema validation and produced negative checkout totals.
- Extend the line item and checkout request schemas in rest/nodejs models to enforce quantity as an integer >= 1 (matching line_item.json and the Python reference implementation).
- Add regression unit tests in validation_flow.test.ts covering 0, negative, and fractional quantities on checkout creation and updates.

Closes Universal-Commerce-Protocol#194
@damaz91 damaz91 closed this Aug 20, 2026
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.

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

1 participant