Skip to content

Commit 405dc2b

Browse files
vctrchuclaude
andcommitted
feat(pos): add TypeScript types for pos.app.ready.data background target
Add BackgroundApi type and event definitions for the new persistent background extension target. Part of BGX (POS Background Extensions). Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
1 parent 12b3941 commit 405dc2b

4 files changed

Lines changed: 68 additions & 2 deletions

File tree

packages/ui-extensions/src/surfaces/point-of-sale/api.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -132,3 +132,9 @@ export type {
132132
PinPadActionType,
133133
PinValidationResult,
134134
} from './types/pin-pad';
135+
136+
export type {BackgroundApi} from './api/background-api/background-api';
137+
export type {
138+
BackgroundEventType,
139+
BackgroundEventDataMap,
140+
} from './api/background-api/events';
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
import type {SessionApi} from '../session-api/session-api';
2+
import type {StorageApi} from '../storage-api/storage-api';
3+
import type {LocaleApi} from '../locale-api/locale-api';
4+
import type {ConnectivityApi} from '../connectivity-api/connectivity-api';
5+
import type {DeviceApi} from '../device-api/device-api';
6+
7+
/**
8+
* The `BackgroundApi` provides APIs available to persistent background extensions
9+
* running on the `pos.app.ready.data` target. Background extensions observe POS events
10+
* via `shopify.addEventListener()` without rendering UI.
11+
*
12+
* This API surface includes session tokens for backend authentication, storage for
13+
* cross-target communication, and read-only device/connectivity/locale information.
14+
*/
15+
export type BackgroundApi<T> = {
16+
extensionPoint: T;
17+
} & SessionApi &
18+
StorageApi &
19+
LocaleApi &
20+
ConnectivityApi &
21+
DeviceApi;
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
/**
2+
* Event types that can be observed via `shopify.addEventListener()` in a
3+
* background extension running on `pos.app.ready.data`.
4+
*/
5+
export type BackgroundEventType =
6+
| 'transaction_complete'
7+
| 'cart_update'
8+
| 'cash_tracking_session_start'
9+
| 'cash_tracking_session_complete';
10+
11+
/**
12+
* Maps each background event type to the shape of data passed to the event
13+
* listener callback. Payload types use `unknown` until event schemas are
14+
* finalized and will be refined in a future release.
15+
*/
16+
export interface BackgroundEventDataMap {
17+
transaction_complete: {transaction: unknown};
18+
cart_update: {cart: unknown};
19+
cash_tracking_session_start: {session: unknown};
20+
cash_tracking_session_complete: {session: unknown};
21+
}

packages/ui-extensions/src/surfaces/point-of-sale/extension-targets.ts

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,8 @@ import {
66
import {TransactionCompleteData} from './event/data/TransactionCompleteData';
77
import {CartUpdateEventData} from './event/data/CartUpdateEventData';
88

9-
import type {RenderExtension} from '../../extension';
9+
import type {RenderExtension, RunnableExtension} from '../../extension';
10+
import type {BackgroundApi} from './api/background-api/background-api';
1011

1112
import type {
1213
StandardApi,
@@ -43,6 +44,21 @@ export interface EventExtensionTargets {
4344
) => Promise<BaseOutput>;
4445
}
4546

47+
export interface DataExtensionTargets {
48+
/**
49+
* A persistent background extension that starts when POS loads and runs for
50+
* the session's lifetime. Use this target for observing POS events like cart
51+
* updates and transaction completions without rendering UI.
52+
*
53+
* Register event listeners via `shopify.addEventListener()` and persist state
54+
* via `shopify.storage` for companion UI targets to read.
55+
*/
56+
'pos.app.ready.data': RunnableExtension<
57+
BackgroundApi<'pos.app.ready.data'>,
58+
undefined
59+
>;
60+
}
61+
4662
export interface RenderExtensionTargets {
4763
/**
4864
* Renders a single interactive tile component on the POS home screen's smart grid. The tile appears once during home screen initialization and remains persistent until navigation occurs. Use this target for high-frequency actions, status displays, or entry points to workflows that merchants need daily.
@@ -362,8 +378,10 @@ export interface RenderExtensionTargets {
362378

363379
export interface ExtensionTargets
364380
extends RenderExtensionTargets,
365-
EventExtensionTargets {}
381+
EventExtensionTargets,
382+
DataExtensionTargets {}
366383

367384
export type RenderExtensionTarget = keyof RenderExtensionTargets;
368385
export type EventExtensionTarget = keyof EventExtensionTargets;
386+
export type DataExtensionTarget = keyof DataExtensionTargets;
369387
export type ExtensionTarget = keyof ExtensionTargets;

0 commit comments

Comments
 (0)