Add types for POS intercept ValidationAdd target values - #4634
Merged
Conversation
vctrchu
force-pushed
the
vchu/pos-validation-target-grammar
branch
from
August 17, 2026 23:09
c151ea6 to
a503242
Compare
vctrchu
marked this pull request as ready for review
August 17, 2026 23:16
vctrchu
force-pushed
the
vchu/pos-validation-target-grammar
branch
from
August 17, 2026 23:18
a503242 to
7d7c075
Compare
Contributor
Author
|
CI notes: lint failure was prettier indentation in my change — fixed and pushed. The |
Contributor
Author
|
/snapshot |
henryStelle
reviewed
Aug 17, 2026
Contributor
Author
|
/snapit |
Assisted-By: devx/60256637-da58-4f80-9e3a-977e038d8a71
Assisted-By: devx/b501e5b3-28c0-4a4d-a1e9-b05fd7759da3
vctrchu
force-pushed
the
vchu/pos-validation-target-grammar
branch
from
August 18, 2026 00:09
9d4ce89 to
42a934f
Compare
Contributor
|
🫰✨ Thanks @vctrchu! Your snapshots have been published to npm. Test the snapshots by updating your "@shopify/ui-extensions": "0.0.0-snapshot-20260818000939",
"@shopify/ui-extensions-tester": "0.0.0-snapshot-20260818000939" |
henryStelle
approved these changes
Aug 18, 2026
aaronschubert0
approved these changes
Aug 18, 2026
Assisted-By: devx/dd2a89f5-3570-4e4c-8f23-528ac5964ead
Assisted-By: devx/dd2a89f5-3570-4e4c-8f23-528ac5964ead
Assisted-By: devx/dd2a89f5-3570-4e4c-8f23-528ac5964ead
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.
Background
https://github.com/shop/issues-retail/issues/33533
The POS intercept API (#4520) shipped
ValidationAdd.targetas a barestringdocumented as a "JSON-path locator". The target contract we're keeping is the Functions validation target model: an enumerated token table, string-matched, never evaluated as JSON paths. Barestringcan never be narrowed later without a breaking change, and it silently accepts targets no host honors.Solution
Pin the grammar as template literal types while the intercept API is still
@private, narrowed per intercepted event:cartvalidations$.cartcartvalidations$.cart.lineItems['<uuid>']paymentvalidations$.paymentValidationTargetunion ofCartValidationTarget/PaymentValidationTarget; wire format stays a plain string, and unions can widen later (never narrow).ValidationTargetFor<TEvent>narrows interceptor returns per event: acartvalidationsinterceptor cannot return$.payment(compile error), and vice versa.InterceptResult/Operation/ValidationAddgain a defaulted type parameter, so existing structural consumers compile unchanged.Devs write the line target inline — TS contextually checks template expressions against template literal types:
JSDoc pins the semantics: targets are data locators (host decides rendering, falls back to the event's root scope); line item uuids must be echoed from the same event's cart snapshot, not cached across events; bundle components target their parent line; unrecognized targets degrade to root scope rather than dropping the validation; handles are namespaced per extension and may repeat across targets.
Alternatives Considered
target?: string— ❌ can never be narrowed without a breaking change; typos and unsupported targets compile silently.$.cart.lineItems[?(@.uuid=='<uuid>')]— ❌ buys spec-valid JSONPath semantics the Functions token model doesn't have (its own table hardcodesdeliveryGroups[0]against multi-group carts), at the cost of syntax hostile to extension developers.$.cart.lineItems[2]— ❌ cannot carry stable identity;.filter().map((li, i))silently targets the wrong line.🎩
@privateAPI, no runtime change beyond the type declarations).yarn type-checkpasses.@ts-expect-errorconsumed.Checklist