App Bridge
App Bridge is the postMessage-based SDK that brokers communication between your app’s iframe and the LaunchMyStore host page — whether that host is the admin (the admin), the checkout, or the post-purchase / order-status page. It speaks one wire protocol everywhere; what changes is which actions the host happens to wire up. The SDK package is@launchmystore/app-bridge (vanilla TS) with a thin
React adapter at @launchmystore/app-bridge-react.
Installation
The SDK ships as CJS + ESM only (
dist/index.js and dist/index.mjs).
There is no public CDN build — if you need an inline build, build the
SDK locally and serve the bundle yourself.Quick Start
dispatch does nothing and logs one
console warning, and dispatchAndWait rejects with its timeout.
Core API
TheApp instance returned by createApp() exposes four methods:
dispatch()
dispatchAndWait()
- Resolves with the host’s response payload (the bare payload — not
wrapped in another
payloadkey). - Rejects with
Error('App Bridge: timeout waiting for <action> response')when the host does not answer within 10 seconds. Change the limit per call withdispatchAndWait(action, payload, { timeout: ms });0,nullorInfinitywaits indefinitely. - The timeout only catches a host that never answers (an action the host
does not wire, a typo, no host). Requests that wait on the merchant —
RESOURCE_PICKER_OPEN,MODAL_OPEN,SCANNER_OPEN/SCAN,PRINT,SHARE,INTENT_LAUNCH,CLIPBOARD_READ_REQUEST— are acknowledged by the admin straight away (APP_BRIDGE_ACK), which stops the timer, so the promise waits for as long as the merchant takes. - Rejects if the host returns an
errorstring — the SDK rejects withnew Error(error), i.e. the host’s error message verbatim (noApp Bridge: <action> failed:prefix).
subscribe()
getSessionToken()
app.getSessionToken() is not cached — it issues a fresh
SESSION_TOKEN_REQUEST on every call. Caching (return the cached token
while more than 30s from expiry, otherwise refresh) lives in the
SessionToken action class and the useSessionToken React hook. Use those
if you want caching. See Sessions & Authentication.
Action Surface
Action names are screaming-snake-case verbs, not object types. The SDK exports helper classes for the actions below in@launchmystore/app-bridge/actions — but whether an action does anything
on a given page depends on what that host has wired. The per-host
pages linked from the Hosts table are the authoritative source
of truth.
SDK-exposed action families
The admin host also handles
USER_FETCH, CONFIG_FETCH,
CONFIG_GET, ENVIRONMENT_FETCH, FEATURES_QUERY, PRINT, SHARE,
SCANNER_OPEN/SCANNER_CLOSE (and SCAN, the promise form),
FULLSCREEN_ENTER/EXIT/TOGGLE, INTENT_LAUNCH,
EXTENSION_CONTEXT_GET, LIFECYCLE_MOUNT/LIFECYCLE_UNMOUNT and
APP_BRIDGE_READY, and pushes EXTENSION_CONTEXT and I18N_UPDATE. These
work only in admin contexts — dispatching them from a checkout or
post-purchase iframe times out after 10 seconds. Note the SDK’s
Features class is a local capability check and never round-trips;
use raw dispatchAndWait('FEATURES_QUERY') if you want the host’s own
answer.- Actions Reference — payload shapes per action.
- App Bridge for Checkout — cart / discount / note / attribute mutators and the buyer-journey intercept.
Wire Format
The protocol is small enough to implement without the SDK if you need to. The iframe posts:action. The admin names round-trip replies <ACTION>_RESPONSE
(SESSION_TOKEN_RESPONSE, CLIPBOARD_READ_RESPONSE,
FEATURES_QUERY_RESPONSE, …), or after the event that settled the request
(RESOURCE_PICKER_SELECTION / RESOURCE_PICKER_CANCEL for a picker,
MODAL_CLOSE for a modal, TOAST_SHOW for a toast); the checkout and
post-purchase hosts echo the request’s action.
Host-initiated events (EXTENSION_CONTEXT, I18N_UPDATE, APP_FOCUS,
MODAL_PRIMARY_ACTION, TITLE_BAR_PRIMARY_ACTION,
CONTEXTUAL_SAVE_BAR_SAVE, …) use the same APP_BRIDGE_RESPONSE envelope
with the event name in action; app.subscribe(action, cb) receives them.
For requests that wait on the merchant (resource picker, modal, scanner,
print, share, intent launch, clipboard read) the admin first sends an
acknowledgement, then the real reply when the merchant acts:
Resize clamps depend on the host. Admin blocks: default 200, max 2000.
Admin Action modals: default 400, max 800. The admin applies a resize to
the iframe that sent it; a message from a nested frame is accepted only
when it carries that extension’s id (the
?extensionId= query param the
host appends, also in your context as extensionId) and comes from the
extension’s origin — so always include extensionId. Checkout extension
slots: clamped to 60–2000 (see App Bridge for Checkout).React Integration
The React adapter wraps the same SDK in a context provider plus a hook for every action family.useAppBridge, useToast,
useModal, useConfirmationModal, useResourcePicker,
useProductPicker, useCollectionPicker, useCustomerPicker,
useFilePicker, useContextualSaveBar, useDirtyState, useTitleBar,
useNavigationMenu, useSessionToken, useAuthenticatedFetch,
useAppQuery, useAppMutation, useRedirect, useLoading,
useAppSubscription, useAppDispatch, useAppDispatchAndWait,
useUser, useConfig, useEnvironment, useFeatures, useFullscreen,
useLeaveConfirmation, useUnsavedChanges, usePrint, useShare,
useClipboard, useCopyToClipboard, useHistory, useLifecycle
(useOnFocus, useOnBlur, useOnVisible, useOnHidden), useI18n,
useRestApi, useIntents, useApi, useCart.
Full list with signatures: React Hooks Reference.
Resource Picker
The picker action handles the ten entity types your app might want to let merchants choose from.selectionFormat: 'object' each selection entry is a handle string
(the original wire shape). The ResourcePicker class and the React hooks
ask for objects by default. The fields per type are listed under
Selection items. The admin
acknowledges picker requests, so the promise waits for as long as the
merchant takes; an unsupported type rejects with an error message.
Or via the helper class for non-promise flows:
Supported resourceType values
Plural spellings (
products, collections, …) are accepted too.
Metaobject is not available: the picker rejects it with an error rather
than opening.
Session Tokens
exp = iat + 86400). The SessionToken class
and the useSessionToken / useRestApi hooks refresh automatically when
the cached token is within 30s of expiry. The admin mints every token
server-side, so your client secret never reaches the browser. A session
token authenticates requests to your app’s backend only — it is not
accepted by the Admin REST API (/api/v1/...), which takes the store’s
OAuth access token. Verify tokens on your backend with jsonwebtoken.verify(token, clientSecret, { audience, issuer: 'https://launchmystore.io' }) — the
issuer is the full URL, and the per-token id claim is sid (not jti).
See Sessions & Authentication for the full
claim set and the verification recipe.
Hosts
App Bridge is the same SDK regardless of where your iframe is mounted — but the wired action set differs per host:
Actions not wired on a host time out after 10s rather than throwing
synchronously — so if a checkout iframe dispatches
RESOURCE_PICKER_OPEN,
the promise rejects ten seconds later with the timeout message.
Identifying the shop and user
The host pushes anEXTENSION_CONTEXT payload to every iframe on mount
(triggered by APP_BRIDGE_READY, and on demand via
EXTENSION_CONTEXT_GET). In React, read it via useApi().data; in vanilla
JS, subscribe to the EXTENSION_CONTEXT action, call
app.subscribeExtensionContext(cb) / app.getExtensionContext(), or read
window.__LMS_EXTENSION_CONTEXT__ once the SDK has populated it.
The context is per iframe: when several extensions render on the same
page, each one receives its own extensionId, extensionHandle, target
and app, plus the resource of the page it is on. The admin fills shop
and user from the signed-in merchant’s account.
Tenant + auth
shop (mirrors app.shop)
user (mirrors app.staffMember)
app + slot context
domainSlug + shop.storeId are the two fields you should persist data
against. domainSlug can change if a merchant re-keys their store;
shop.storeId is immutable.Security
Origin checked on both sides
Origin checked on both sides
The SDK only accepts messages from the host origin it resolved from
config.host. The admin only accepts messages from its own origin and
from the origins of the extensions it mounted on that page (an
allow-list per slot — anything else is ignored). Every extension iframe
is registered with the slot that rendered it, so its messages and
context stay with that extension, and a session token is minted only
for the app that iframe belongs to: a request carrying another app’s
apiKey is rejected.Never embed your client secret
Never embed your client secret
Session tokens are signed on the host’s server using your app’s
client secret. The iframe only ever sees the signed JWT — never the
secret. The merchant’s own admin session (
adminToken) is given to
first-party extensions only, never to an app’s iframe.Iframes are sandboxed
Iframes are sandboxed
Admin blocks, admin action modals and App Bridge modals are mounted
with
sandbox="allow-scripts allow-same-origin allow-forms allow-popups allow-popups-to-escape-sandbox allow-modals allow-downloads"
and allow="clipboard-write; web-share": confirm() / alert(),
downloads and pop-ups work, and a window you open (for example a
print window) is not sandboxed. Your app’s home page (the full-page
embed) is not sandboxed and gets
allow="clipboard-read; clipboard-write; web-share". Either way your
iframe has its own origin: no access to the admin’s DOM or cookies —
only the postMessage channel.Validate user input server-side
Validate user input server-side
Anything posted from the iframe is in the user’s browser. Always
re-validate on your backend before persisting.
See Also
- Actions Reference — exhaustive payload shapes.
- App Bridge for Checkout — cart, discount, note, attribute mutations.
- Error Handling — timeouts, host errors and per-action failure modes.
- React Hooks — hook-by-hook reference.
- Sessions & Authentication — JWT verification.