fix(rest/nodejs): enforce integer and minimum bounds on line item quantity - #198
Closed
damaz91 wants to merge 1 commit into
Closed
fix(rest/nodejs): enforce integer and minimum bounds on line item quantity#198damaz91 wants to merge 1 commit into
damaz91 wants to merge 1 commit into
Conversation
…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
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
In published
@ucp-js/sdkpackages (0.4.3 / 0.4.4),LineItemCreateRequestSchemaandLineItemUpdateRequestSchemadefinedquantityas an unconstrainedz.number(), omitting the integer (.int()) and minimum (.gte(1)) constraints specified inline_item.json.Consequently, checkout creation and update requests with
quantity <= 0or non-integer floating values passed route schema validation, propagating invalid quantities intorecalculateTotalsand producing negative totals as well as incorrect inventory reservations.This PR:
LineItemCreateRequestSchemaandLineItemUpdateRequestSchemato enforcequantity: z.number().int().gte(1)inrest/nodejs/src/models/index.ts.CheckoutCreateRequestSchema,CheckoutUpdateRequestSchema,ExtendedCheckoutCreateRequestSchema, andExtendedCheckoutUpdateRequestSchemato use these constrained line item schemas.rest/nodejs/test/validation_flow.test.tsfor checkout create and update with quantity0,-1, and fractional numbers (1.5,2.5), verifying they are rejected with HTTP 422.Category (Required)
ucp-schematool (resolver, linter, validator). (Requires Maintainer approval)Related Issues
Fixes #194
Checklist
!for breaking changes).