Skip to content

Add types for POS intercept ValidationAdd target values - #4634

Merged
vctrchu merged 6 commits into
2026-10-rcfrom
vchu/pos-validation-target-grammar
Aug 18, 2026
Merged

Add types for POS intercept ValidationAdd target values#4634
vctrchu merged 6 commits into
2026-10-rcfrom
vchu/pos-validation-target-grammar

Conversation

@vctrchu

@vctrchu vctrchu commented Aug 17, 2026

Copy link
Copy Markdown
Contributor

Background

https://github.com/shop/issues-retail/issues/33533

The POS intercept API (#4520) shipped ValidationAdd.target as a bare string documented 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. Bare string can 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:

Event Field Target value
cartvalidations cart $.cart
cartvalidations line item $.cart.lineItems['<uuid>']
paymentvalidations payment attempt $.payment
  • ValidationTarget union of CartValidationTarget / PaymentValidationTarget; wire format stays a plain string, and unions can widen later (never narrow).

  • ValidationTargetFor<TEvent> narrows interceptor returns per event: a cartvalidations interceptor cannot return $.payment (compile error), and vice versa. InterceptResult / Operation / ValidationAdd gain 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:

    target: `$.cart.lineItems['${lineItem.uuid}']`  // checked char-for-char
    target: `$.cart.lineItems[${idx}]`              // compile error
  • 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

  1. Keep target?: string — ❌ can never be narrowed without a breaking change; typos and unsupported targets compile silently.
  2. JSONPath filter $.cart.lineItems[?(@.uuid=='<uuid>')] — ❌ buys spec-valid JSONPath semantics the Functions token model doesn't have (its own table hardcodes deliveryGroups[0] against multi-group carts), at the cost of syntax hostile to extension developers.
  3. Positional $.cart.lineItems[2] — ❌ cannot carry stable identity; .filter().map((li, i)) silently targets the wrong line.
  4. Structured object / sibling uuid field — ❌ breaks the single-string target contract shared with Functions.

🎩

Checklist

  • I have 🎩'd these changes
  • I have updated relevant documentation

@vctrchu
vctrchu force-pushed the vchu/pos-validation-target-grammar branch from c151ea6 to a503242 Compare August 17, 2026 23:09
@vctrchu vctrchu changed the title Pin POS intercept validation target grammar Add types for POS intercept ValidationAdd target values Aug 17, 2026
@vctrchu
vctrchu marked this pull request as ready for review August 17, 2026 23:16
@vctrchu
vctrchu force-pushed the vchu/pos-validation-target-grammar branch from a503242 to 7d7c075 Compare August 17, 2026 23:18
@vctrchu

vctrchu commented Aug 17, 2026

Copy link
Copy Markdown
Contributor Author

CI notes: lint failure was prettier indentation in my change — fixed and pushed. The test job failure is pre-existing on 2026-10-rc (checkout testing example: api_version "2026-10" does not match @shopify/ui-extensions-tester ("2027-00")) — same failure on the branch tip before this PR (#4625's CI run). Not addressed here since this PR is point-of-sale types only.

@vctrchu

vctrchu commented Aug 17, 2026

Copy link
Copy Markdown
Contributor Author

/snapshot

Comment thread packages/ui-extensions/src/surfaces/point-of-sale/events.ts Outdated
Comment thread packages/ui-extensions/src/surfaces/point-of-sale/events.ts
Comment thread packages/ui-extensions/src/surfaces/point-of-sale/events.ts Outdated
@vctrchu

vctrchu commented Aug 18, 2026

Copy link
Copy Markdown
Contributor Author

/snapit

Assisted-By: devx/60256637-da58-4f80-9e3a-977e038d8a71
Assisted-By: devx/b501e5b3-28c0-4a4d-a1e9-b05fd7759da3
@vctrchu
vctrchu force-pushed the vchu/pos-validation-target-grammar branch from 9d4ce89 to 42a934f Compare August 18, 2026 00:09
@shopify-github-actions-access

Copy link
Copy Markdown
Contributor

🫰✨ Thanks @vctrchu! Your snapshots have been published to npm.

Test the snapshots by updating your package.json with the newly published versions:

"@shopify/ui-extensions": "0.0.0-snapshot-20260818000939",
"@shopify/ui-extensions-tester": "0.0.0-snapshot-20260818000939"

Comment thread packages/ui-extensions/src/surfaces/point-of-sale/events.ts
@vctrchu
vctrchu merged commit 2ff93b3 into 2026-10-rc Aug 18, 2026
6 checks passed
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.

3 participants