Skip to content

feat(pos): add TypeScript types for pos.app.ready.data background target#4123

Draft
vctrchu wants to merge 7 commits into2026-04-rcfrom
vchu/bgx-types-pos-app-ready-data
Draft

feat(pos): add TypeScript types for pos.app.ready.data background target#4123
vctrchu wants to merge 7 commits into2026-04-rcfrom
vchu/bgx-types-pos-app-ready-data

Conversation

@vctrchu
Copy link
Copy Markdown
Contributor

@vctrchu vctrchu commented Mar 17, 2026

What

Add TypeScript types for the pos.app.ready.data persistent background extension target.

New types

  • DataTargetApi<T> — API surface for non-rendering data targets. Includes all non-UI APIs (cart, storage, session, locale, connectivity, device, product search) but excludes UI-presenting APIs (modals, toasts, scanners, pin pads).
  • ShopifyEventMap — Maps event names to their typed Event subclasses (transactioncomplete, cashtrackingsessionstart, cashtrackingsessioncomplete). Sourced from ui-api-design build output.
  • DataExtensionTargets — New target interface with pos.app.ready.data as a RunnableExtension<DataTargetApi, undefined>.
  • DataExtensionTarget — Type alias for data target keys.

Event types (from ui-api-design)

Event type definitions are copied from the ui-api-design build output (.d.ts files), following the same pattern checkout uses for syncing types from the private repo. Events are flat Event subclasses with readonly properties:

  • TransactionCompleteEventorderId (gid), transactionType (sale/return/exchange), customer?, grandTotal, executedAt
  • CashTrackingSessionStartEventid (UUID), openingTime
  • CashTrackingSessionCompleteEventid (UUID), openingTime, closingTime

WindowEventMap augmentation

POS host events are received via the standard window.addEventListener() Web API. ShopifyEventMap augments WindowEventMap so calls are fully type-safe.

shopify.extend("pos.app.ready.data", () => {
  window.addEventListener("transactioncomplete", (event) => {
    console.log(event.orderId, event.transactionType);
  });
});

Why

POS apps need a persistent background extension that starts when POS loads and runs for the session lifetime. This replaces the existing fire-and-forget .event.observe targets with a single long-lived target that receives events via window.addEventListener, aligning with web standards.

Related PRs

@github-actions
Copy link
Copy Markdown
Contributor

🚨🚨🚨 Docs migration in progress 🚨🚨🚨

We are actively migrating UI extension reference docs to MDX in the areas/platforms/shopify-dev zone of the monorepo. This impacts docs for the following surfaces:

During this migration, please be aware of the following:

.doc.ts files are being deprecated. Changes to .doc.ts files in this repo will not be reflected in the new MDX-based docs. If you need to update docs for a reference that has already been migrated, make your changes directly in the areas/platforms/shopify-dev zone of the monorepo instead.

Doc comments in .ts source files (the comment blocks above types and functions) are also affected. Generating docs from these comments currently requires a newer version of the @shopify/generate-docs library that isn't yet available. Updates to doc comments may not produce the expected output until the migration is complete.

Examples that previously lived in this repo are being moved to the areas/platforms/shopify-dev zone of the monorepo and should be authored there going forward.

What should I do?

  • If your PR includes changes to .doc.ts files, doc comments, or examples, please reach out to us in #devtools-proj-templated-refs so we can help ensure your updates are captured correctly.
  • If your PR is limited to source code changes (non-docs), you can ignore this notice.

Thanks for your patience while we complete the migration! 🙏

@vctrchu vctrchu self-assigned this Mar 17, 2026
@vctrchu vctrchu force-pushed the vchu/bgx-types-pos-app-ready-data branch from 1ac2792 to 405dc2b Compare March 17, 2026 23:23
@vctrchu vctrchu changed the base branch from 2026-04-rc to vchu/fix-doc-gen-world-path March 17, 2026 23:23
Copy link
Copy Markdown
Contributor Author

vctrchu commented Mar 17, 2026

Warning

This pull request is not mergeable via GitHub because a downstack PR is open. Once all requirements are satisfied, merge this PR as a stack on Graphite.
Learn more

This stack of pull requests is managed by Graphite. Learn more about stacking.

Copy link
Copy Markdown
Contributor

@NathanJolly NathanJolly left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This PR has the target definition and DataTargetApi, but it's missing two things that should ship together:

  1. addEventListener / removeEventListener — needs to be part of DataTargetApi (or the target's API surface). The generic types are defined in the TAG proposal (ui-api-design PR #1418), and the surface-specific PosEventMap with concrete event types + payloads should be defined here.

  2. PosEventMap — the typed event map with transaction_complete, cash_tracking_session_start, cash_tracking_session_complete and their payload interfaces. This is what makes addEventListener type-safe for POS.

Without these, extensions targeting pos.app.ready.data have no way to type-safely listen for events.

@vctrchu
Copy link
Copy Markdown
Contributor Author

vctrchu commented Mar 18, 2026

Added both. DataTargetApi now includes addEventListener and removeEventListener using the generic types from the TAG proposal (ui-api-design #1418). Also added PosEventMap with transaction_complete, cash_tracking_session_start, and cash_tracking_session_complete — no cart_update since that's state, not an event.

@vctrchu vctrchu changed the title Add TypeScript types for pos.app.ready.data background target feat(pos): add BGX types — pos.app.ready.data target + storage.keys subscribable Mar 27, 2026
@vctrchu vctrchu force-pushed the vchu/bgx-types-pos-app-ready-data branch from 8ce7778 to 06eeda4 Compare March 27, 2026 23:15
@vctrchu vctrchu changed the title feat(pos): add BGX types — pos.app.ready.data target + storage.keys subscribable feat(pos): add TypeScript types for pos.app.ready.data background target Mar 27, 2026
@vctrchu vctrchu force-pushed the vchu/bgx-types-pos-app-ready-data branch 2 times, most recently from e2c600a to e63759e Compare March 30, 2026 21:36
@vctrchu vctrchu marked this pull request as ready for review March 30, 2026 21:39
@vctrchu vctrchu changed the base branch from vchu/fix-doc-gen-world-path to 2026-04-rc March 30, 2026 21:56
@vctrchu vctrchu force-pushed the vchu/bgx-types-pos-app-ready-data branch 3 times, most recently from c9e53ce to 83610ef Compare March 30, 2026 22:07
@vctrchu
Copy link
Copy Markdown
Contributor Author

vctrchu commented Mar 30, 2026

/snapit

vctrchu and others added 4 commits March 30, 2026 15:14
Add DataTargetApi type and DataExtensionTargets interface for the new
persistent background extension target. DataTargetApi provides the full
POS API surface excluding UI-presenting APIs (Toast, Print, Camera,
PinPad). Background extensions that need UI should use companion targets.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
…o DataTargetApi

Adds type-safe event listener support for the pos.app.ready.data background
target. PosEventMap defines three discrete events: transaction_complete,
cash_tracking_session_start, cash_tracking_session_complete.

The generic AddEventListener/RemoveEventListener types follow the TAG
proposal (ui-api-design PR #1418) and match the existing Navigation API
pattern. Cart changes are intentionally excluded — they are state, not
events, and should use shopify.cart.current.subscribe() instead.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
…mentation

Remove addEventListener/removeEventListener from DataTargetApi. POS events
are received via the standard window.addEventListener() Web API. PosEventMap
augments WindowEventMap for type-safe event listening.
@vctrchu vctrchu force-pushed the vchu/bgx-types-pos-app-ready-data branch from 83610ef to 3b55663 Compare March 30, 2026 22:14
@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-20260330221356",
"@shopify/ui-extensions-tester": "0.0.0-snapshot-20260330221356"

vctrchu added 2 commits March 30, 2026 17:42
…consumers

Without this, PosEventMap never augments WindowEventMap for package
consumers — window.addEventListener('transaction_complete', ...) has
no type-safe autocomplete. Follows checkout surface precedent.
@vctrchu vctrchu force-pushed the vchu/bgx-types-pos-app-ready-data branch 2 times, most recently from 80a1547 to 93c4e1d Compare March 31, 2026 01:06
@vctrchu vctrchu force-pushed the vchu/bgx-types-pos-app-ready-data branch from 93c4e1d to 6edab18 Compare March 31, 2026 01:07
@vctrchu vctrchu requested review from a team and NathanJolly March 31, 2026 01:14
@vctrchu vctrchu marked this pull request as draft March 31, 2026 23:26
Copy .d.ts event type definitions from ui-api-design build output
instead of hand-writing PosEventMap. This follows the same pattern
checkout uses for syncing types from the private repo.

- Add events/events.d.ts (TransactionCompleteEvent, CashTracking* events)
- Add events/index.d.ts (ShopifyEventMap, WindowEventMap augmentation)
- Remove manual PosEventMap and old transaction data imports
- Export ShopifyEventMap and individual event types from api.ts
@vctrchu vctrchu force-pushed the vchu/bgx-types-pos-app-ready-data branch from 6edab18 to 5d0a28d Compare April 1, 2026 20:10
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.

2 participants