Skip to content

fix(rest/nodejs): express discount allocation path as a JSONPath - #157

Open
XiaolongZhang-TT wants to merge 1 commit into
Universal-Commerce-Protocol:mainfrom
XiaolongZhang-TT:fix/nodejs-discount-allocation-jsonpath
Open

fix(rest/nodejs): express discount allocation path as a JSONPath#157
XiaolongZhang-TT wants to merge 1 commit into
Universal-Commerce-Protocol:mainfrom
XiaolongZhang-TT:fix/nodejs-discount-allocation-jsonpath

Conversation

@XiaolongZhang-TT

Copy link
Copy Markdown
Contributor

Description

discount.json types allocation.path as a JSONPath (RFC 9535) pointing at the allocation target (e.g. "$.line_items[0]"). The Node.js sample emitted the bare label "subtotal" for every applied discount's allocation, which a platform cannot resolve as a path. The Python sample already emits "$.totals[?(@.type=='subtotal')]".

Root causerest/nodejs/src/api/checkout.ts, recalculateTotals: all three discount code branches (10OFF, WELCOME20, FIXED500) built allocations: [{ path: "subtotal", amount }].

Fix: emit "$.totals[?(@.type=='subtotal')]" instead — the same JSONPath the Python reference uses. totals is an array of { type, amount } objects, so the filter expression is the correct way to target the subtotal entry (a dot-path would be wrong). Allocation amounts are unchanged.

Category (Required)

  • Samples / Conformance: Maintaining samples and the conformance suite. (Requires Maintainer approval)

Related Issues

None — newly identified spec-compliance gap in the Node.js sample server.

Checklist

  • I have followed the Contributing Guide (Conventional Commits title requirements and ! for breaking changes).
  • I have updated the documentation (if applicable). — N/A, no documentation changes.
  • My changes pass all local linting and formatting checks. (tsc --noEmit clean; prettier clean.)
  • I have added tests that prove my fix is effective or that my feature works. (an applied discount's allocation path is a JSONPath — fails on the old "subtotal" value.)
  • New and existing unit tests pass locally with my changes. (Node.js suite: 30 passed.)
  • (For Core/Capability) I have included/updated the relevant JSON schemas. — N/A, no schema changes.
  • I have regenerated Python Pydantic models by running generate_models.sh under python_sdk. — N/A, no schema changes.

Screenshots / Logs (if applicable)

Before/after — an applied discount's allocations[0].path:

Before (bug):

"allocations": [{ "path": "subtotal", "amount": 100 }]

After (fix):

"allocations": [{ "path": "$.totals[?(@.type=='subtotal')]", "amount": 100 }]

Full Node.js suite:

# tests 30
# pass 30
# fail 0

discount.json types allocation.path as a JSONPath (RFC 9535) pointing at the
allocation target (e.g. "$.line_items[0]"). The Node.js sample emitted the
bare label "subtotal", which a platform cannot resolve. The Python sample
already emits "$.totals[?(@.type=='subtotal')]".

Use that same JSONPath in all three discount code branches of
recalculateTotals so the allocation target is resolvable, matching the
Python reference and the schema.

Adds a regression test asserting each applied discount's allocation path is
rooted at "$." (a JSONPath), which fails on the old "subtotal" value.
@damaz91 damaz91 added the status:needs-triage Signal that the PR is ready for human triage label Aug 3, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

status:needs-triage Signal that the PR is ready for human triage

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants