Skip to content

Component API

Documents @snap4id-sdk/app-embed 1.0.0

Entry points: @snap4id-sdk/app-embed (React Native), @snap4id-sdk/app-embed/dev (a ready-made fake store for simulators; development builds only), @snap4id-sdk/app-embed/testing (fakes for unit tests; never in a release app), and the Expo config plugin @snap4id-sdk/app-embed. Protocol types are re-exported from @snap4id-sdk/embed-protocol. Guides: quickstart and component details.

Creates the client: once per app process. Throws ConfigurationError (configuration_invalid) for an invalid config.

Parameter Type Required Description
partnerId string yes Your partner id from onboarding
purchases 'built-in' | AppPurchases yes The built-in store (expo-iap), or your own store code
onCompleted (completion) => Promise<void> | void yes Files of a paid job; at least once per job until it resolves
onError (error: ComponentError) => void { code, fatal, message?, paymentRef?, jobId?, transactionId? }, see error codes
onVerifyPurchase (receipt, { jobId, paymentRef, price? }) => Promise<void> Present ⇒ your backend checks receipts (your backend); bounded at 15 s
onBridgeMessage (entry) => void Redacted bridge traffic, for logs
namespace string Per signed-in user; default 'default'
theme, copy HostTheme, HostCopy Theme and text overrides
origin string Default https://snap4.id; leave unset in release builds
trustedOrigins string[] Extra exact HTTPS origins (pre-production Snap4ID only)
allowLocalOrigins boolean Test builds only. Lets a release build load http://127.0.0.1[:port] / http://10.0.2.2[:port] (a local Snap4ID or the fake page); default false. Development builds allow local origins without it
storage JsonStore Default: FileJsonStorage, JSON files via expo-file-system
devHooks DevHooks From ./testing; ignored outside development builds

AppPurchases = { onPurchaseRequest, onConfirmPurchase, getUnfinishedPurchases?, getPendingPurchases?, getPrice? }. overrides.builtInStore replaces the store behind 'built-in' (the fake store in development builds, from createDevFakeStore() in @snap4id-sdk/app-embed/dev; see fake store).

import { createSnap4IdClient } from '@snap4id-sdk/app-embed';
export const snap4id = createSnap4IdClient({
partnerId: 'your-partner-id',
purchases: 'built-in',
onCompleted: (completion) => snap4id.downloadArtifacts(completion),
onError: (error) => log.warn(error.code),
});

The product is the in-app purchase item you create in your store (App Store Connect, Google Play Console). You give its id to Snap4ID at onboarding, one per store; your app configures nothing. The page names the product and asks the component for its store price, which it shows on its order button:

  1. The page’s hello carries your ids from your partner configuration: { "ios": "pl.example.app.idphoto", "android": "pl.example.app.idphoto" }.

  2. The component answers the hello at once, then looks up the price of the id for its store (the built-in store through expo-iap; your own store code through getPrice) and sends it to the page (price.result):

    { "products": { "pl.example.app.idphoto": { "amount_minor": 1999, "currency": "PLN", "display_price": "19,99 zł" } } }

No price (an id missing for this store, a product the store does not know, a store error) ⇒ the page shows the order button without a price, and onError gets the non-fatal price_unavailable naming the id.

AppPurchases.getPrice(productId) (your own store code): Promise<ProductPrice | null>, ProductPrice = { display_price, amount_minor, currency }.

Member Returns Description
start() Promise<RecoveryReport> Store listeners + recovery; once per app start
stop() void Detach the listeners
recover() Promise<RecoveryReport> Run recovery again
purchaseUpdated(purchase) Promise<void> Your own store code: a purchase that resolved later (approved “Ask to Buy”)
downloadArtifacts(completion) Promise<void> Copy a completion’s files into app storage; rejects until all are stored
files object save(jobId, code), share(jobId, code): a job’s stored file (else a temporary copy of its link)
downloads object Files stored by downloadArtifacts: list() and forJob(jobId) return Promise<DownloadedFile[]>; subscribe(listener) calls listener(files) with the full, updated DownloadedFile[] after every change and returns an unsubscribe function. DownloadedFile = { jobId, code, title, mimeType, filename, localUri, bytes }
resumeQueue.subscribe(listener) unsubscribe function Job ids the component wants reopened
jobs(), deleteJob(jobId) The component’s job records

recover(config) (a separate export) runs start-up recovery headless, for a background task before any UI.

The full-screen flow. Render it under your own header.

Prop Type Required Description
client Snap4IdClient yes The client
onClose ({ reason: 'page' | 'fatal' | 'back' }) => void yes Close the screen
jobId string Reopen a job; omit for a new one
consent { statistics?: boolean } Absent ⇒ analytics off; marketing never
onStateChange ({ jobId?, step?, title?, canGoBack }) => void Header title and step
doneScreen 'all' | 'photo' | 'none' Default from your partner configuration, see done screen
capabilities { save?: boolean; share?: boolean } Default: both, where supported
theme, copy HostTheme, HostCopy Win over the client config per key / id
style, testID
// statisticsConsent: your app's own analytics consent (boolean | undefined); undefined ⇒ analytics off.
<Snap4IdFlow
client={snap4id}
consent={{ statistics: statisticsConsent }}
doneScreen="photo"
onStateChange={({ title }) => navigation.setOptions({ title })}
onClose={() => navigation.goBack()}
/>

Hidden WebViews that reopen queued jobs one at a time, so paid jobs are delivered after a kill. Mount once near the root.

Prop Type Required Description
client Snap4IdClient yes The client
jobIds string[] Jobs to reopen; default: the client’s resume queue
onSettled (jobId, end) => void A reopened job’s hidden session ended, with why

What onCompleted and downloadArtifacts receive.

Field Type Description
jobId string The paid job
orderCode string Six characters, for the user and support
artifacts[] { code, title, mimeType, filename, url, expiresAt } Every file; url expires at expiresAt (30 days)
plugins: [['@snap4id-sdk/app-embed', { cameraPermission, photosPermission, savePhotosPermission }], 'expo-iap'];
Option Writes
cameraPermission iOS NSCameraUsageDescription; Android android.permission.CAMERA
photosPermission iOS NSPhotoLibraryUsageDescription
savePhotosPermission iOS NSPhotoLibraryAddUsageDescription

The Android media permissions (READ_MEDIA_IMAGES, READ_MEDIA_VIDEO, READ_MEDIA_AUDIO, READ_MEDIA_VISUAL_USER_SELECTED, and the legacy storage ones) come from expo-media-library’s own config plugin, not from this one. The component only saves photos: to request images only, configure that plugin too, e.g. ['expo-media-library', { granularPermissions: ['photo'] }], and check what Google Play’s photo and video permissions policy asks of your app.

Peer dependencies (what npx expo install picks for Expo SDK 58): expo ^58, react-native ^0.88, react ^19.3, react-native-webview ^14, expo-iap ^6.4 (optional: only for purchases: 'built-in'), expo-file-system, expo-media-library, expo-sharing, expo-constants (all ^58). Development builds also need expo-dev-client.

Development builds only (import it behind __DEV__).

Export Description
createDevFakeStore(options?) A FakeStore with a native “Test purchase” alert (Buy / Pending / Fail / Cancel) and file storage. Options: dialog, store, blocksRebuyUntilFinished (default: true on Android, like Play)
alertPurchaseDialog That alert, as a FakePurchaseDialog
FakeStore new FakeStore(dialog, store, clock?, newId?, options?): dialog = { choose(request): Promise<'succeed' | 'pending' | 'fail' | 'cancel'> }, store = a JsonStore (e.g. new FileJsonStorage() from the main entry)

FakeStore, MemoryJsonStore, MemoryFileStore, RecordingMedia, RecordingSender, ManualClock, ScriptedDialog, FakeHostBackend, OneShotDevHooks, createTestClient. See fake store.