Server helpers
Call provider APIs from your Node backend, configure credentials, inject a custom fetch, and handle errors.
Call provider APIs from your server
Server helpers call third-party providers — OneSignal, App Store / Google Play receipts, Branch, ChottuLink, and Firebase Dynamic Links — from your Node backend. Each helper returns a typed result you can await directly.
Never import @bdk/native/server or any @bdk/native/server/* subpath into a browser bundle — these modules read process.env and call provider APIs with secret keys. The browser-safe entry points are @bdk/native (root) and @bdk/native/browser.
Import a provider
Import the helper for the provider you need from its subpath. Requires Node 18+.
@bdk/native/server is a barrel that re-exports onesignal, iap, branch, chottulink, and firebase-dynamic-links. Prefer a specific subpath when you only need one provider.
Configure credentials
Pass credentials as function options, or set the matching environment variables and let each helper read them. Each row lists the option and the variables checked, in order.
| Provider | Option | Environment variables (in lookup order) |
|---|---|---|
| OneSignal | oneSignalAppId | BDK_ONESIGNAL_APP_ID, ONESIGNAL_APP_ID |
| OneSignal | oneSignalApiKey | BDK_ONESIGNAL_API_KEY, ONESIGNAL_API_KEY |
| IAP (Apple) | sharedSecret | BDK_IOS_INAPP_SHARED_SECRET, IOS_INAPP_SHARED_SECRET, APP_STORE_SHARED_SECRET |
| IAP (Google) | accessToken | BDK_GOOGLE_PLAY_ACCESS_TOKEN, GOOGLE_PLAY_ACCESS_TOKEN |
| IAP (Google) | serviceAccount | BDK_GOOGLE_PLAY_SERVICE_ACCOUNT_JSON, GOOGLE_PLAY_SERVICE_ACCOUNT_JSON, GOOGLE_APPLICATION_CREDENTIALS_JSON |
| Branch | branchKey | BDK_BRANCH_KEY, BRANCH_KEY, BRANCH_LIVE_KEY |
| Branch | branchLinkDomain | BDK_BRANCH_LINK_DOMAIN, BRANCH_LINK_DOMAIN |
| ChottuLink | apiKey | BDK_CHOTTULINK_API_KEY, CHOTTULINK_API_KEY |
| ChottuLink | domain | BDK_CHOTTULINK_DOMAIN, CHOTTULINK_DOMAIN, CHOTTULINK_LINK_DOMAIN |
| Firebase | firebaseWebApiKey | BDK_FIREBASE_WEB_API_KEY, FIREBASE_WEB_API_KEY, FIREBASE_DYNAMIC_LINKS_WEB_API_KEY |
| Firebase | domainUriPrefix | BDK_FIREBASE_DYNAMIC_LINK_DOMAIN_URI_PREFIX, FIREBASE_DYNAMIC_LINK_DOMAIN_URI_PREFIX |
| Firebase | iosBundleId | BDK_IOS_BUNDLE_ID, IOS_BUNDLE_ID |
| Firebase | iosAppStoreId | BDK_IOS_APPSTORE_ID, IOS_APPSTORE_ID, IOS_APP_STORE_ID |
| Firebase | androidPackageName | BDK_ANDROID_BUNDLE_ID, ANDROID_BUNDLE_ID, ANDROID_PACKAGE_NAME |
An explicit option always wins over the environment. A missing required value throws a ValidationError — except a missing Google Play credential (serviceAccount/accessToken), which surfaces as a ProviderError (BDK_PROVIDER_ERROR).
Use a custom fetch
Pass a fetch option to use your own HTTP client — for proxies, retries, or mocking in tests. It defaults to the global fetch on Node 18+, so you usually skip it. The type is FetchLike (typeof fetch).
If no fetch implementation can be resolved, the call throws a ProviderError. Any standard-fetch-compatible function (e.g. undici, node-fetch, or a test spy) is accepted.
Handle errors
Catch ProviderError when a provider returns a non-OK HTTP status, and ValidationError when a required option or env var is missing. Both extend BdkError and carry a typed code.
Inspect error.code rather than parsing message strings. For a ProviderError, error.details?.status and error.details?.response give you the upstream provider's status and body.