API Reference
This page lists all functions, callbacks, package objects, events, and enums for @d11/dota. For configuration options, see Options & Configuration. It favors quick scanning over exhaustive prose and avoids duplicated code.
DOTA API Reference
- sync
- checkForUpdate
- getUpdateMetadata
- notifyAppReady
- restartApp
- allowRestart
- disallowRestart
- clearUpdates
sync
Synchronizes your app's JavaScript bundle and image assets with the latest release to the configured deployment. Unlike the checkForUpdate method, which simply checks for the presence of an update, and let's you control what to do next, sync handles the update check, download and installation experience for you.
function sync(
options?: SyncOptions,
syncStatusChangeCallback?: (status: SyncStatus) => void,
downloadProgressCallback?: (progress: DownloadProgress) => void,
handleBinaryVersionMismatchCallback?: (update: RemotePackage) => void,
): Promise<SyncStatus>;
Examples:
- Silent
- Interactive
- Hooks
Silently keeps the app up-to-date; installs on the next restart.
codePush.sync(); // keep in sync silently; install on next restart
Prompts the user, then installs immediately after download.
codePush.sync({ updateDialog: true, installMode: codePush.InstallMode.IMMEDIATE });
Subscribe to status changes and download progress to drive your own UI.
codePush.sync(
{},
(status) => { /* see SyncStatus below */ },
({ receivedBytes, totalBytes }) => { /* show progress */ },
);
SyncOptions
sync accepts the same configuration as CodePushOptions, except checkFrequency (not applicable to a one‑off call). Use it to override defaults for a specific run:
deploymentKey(string) – see Deployment Keys.installMode(codePush.InstallMode) – see Install Modes.mandatoryInstallMode(codePush.InstallMode) – see Mandatory Install Mode.minimumBackgroundDuration(number) – see Install Modes.updateDialog(UpdateDialogOptions) – see Update Dialog.
Option examples:
// Use a specific deployment key for this call
codePush.sync({ deploymentKey: 'KEY' });
// Install on next resume, only if app was backgrounded for ≥ 5 minutes
codePush.sync({
installMode: codePush.InstallMode.ON_NEXT_RESUME,
minimumBackgroundDuration: 60 * 5,
});
// Install mandatory updates on next resume (optionals follow installMode)
codePush.sync({ mandatoryInstallMode: codePush.InstallMode.ON_NEXT_RESUME });
// Customize the interactive dialog and install immediately if accepted
codePush.sync({
updateDialog: {
title: 'An update is available!',
appendReleaseDescription: true,
descriptionPrefix: '\n\nChange log:\n',
},
installMode: codePush.InstallMode.IMMEDIATE,
});
Callbacks
Optionally subscribe to the lifecycle of sync to drive UI.
syncStatusChangeCallback
Fires when the sync process moves between stages. Use it to show "checking", "downloading", or "installing" UI, or to react when an update installs.
SyncStatus values: see the full table in Enums → SyncStatus.
Example:
codePush.sync(
{ updateDialog: true },
(status) => {
switch (status) {
case codePush.SyncStatus.DOWNLOADING_PACKAGE:
// show downloading UI
break;
case codePush.SyncStatus.INSTALLING_UPDATE:
// hide downloading UI
break;
}
}
);
downloadProgressCallback(progress)
Called periodically while downloading. Use receivedBytes and totalBytes to update a progress bar or percentage.
codePush.sync(
{},
undefined,
({ receivedBytes, totalBytes }) => {
const percent = Math.floor((receivedBytes / totalBytes) * 100);
// update progress UI with percent
}
);
handleBinaryVersionMismatchCallback(update)
Called when the available update targets a different binary app version (e.g., native upgrade required). Typically, you would direct the user to update from the store, or handle it with your own messaging. See also checkForUpdate.
Return value
Resolves to a SyncStatus code indicating why sync succeeded:
UP_TO_DATE– app is already up‑to‑date.UPDATE_INSTALLED– update installed (applies per install mode).UPDATE_IGNORED– optional update was ignored (only withupdateDialog).SYNC_IN_PROGRESS– another sync is already running.
allowRestart
codePush.allowRestart(): void;
- Purpose: Re‑enable programmatic restarts previously blocked via
disallowRestart. - Effect: Immediately performs a queued restart if one was requested while restarts were disallowed.
- Pairs with:
disallowRestart,restartApp.
Triggers an immediate restart now if, during the disallowed period, any of the below occurred:
- An update installed with
InstallMode.IMMEDIATE - An update installed with
InstallMode.ON_NEXT_RESUMEand the app resumed (respectingminimumBackgroundDuration) - Your code called
restartApp()
No restart occurs if:
- No updates were installed since
disallowRestart() - A pending update used
InstallMode.ON_NEXT_RESTART(no programmatic restart needed) - A pending update used
InstallMode.ON_NEXT_RESUMEbut the app hasn’t been backgrounded/resumed yet - No
restartApp()calls happened during the disallowed window
This ensures calling allowRestart() only restarts when a restart was explicitly requested while restarts were disabled. Conceptually similar to restartApp(true), except it only restarts if a queued restart exists.
See disallowRestart for a usage example.
checkForUpdate
function checkForUpdate(
deploymentKey?: string | null,
handleBinaryVersionMismatchCallback?: (update: RemotePackage) => void,
): Promise<RemotePackage | null>;
- Purpose: Check if the configured deployment has an update available.
- Default: Uses deployment key from native config; override with the
deploymentKeyparam. - Returns:
RemotePackage | null. - See also: Deployment Keys, Package objects → RemotePackage.
Parameters:
deploymentKey(string | null) – override the native deployment key for this call (e.g., early access toggles).handleBinaryVersionMismatchCallback(update: RemotePackage)– invoked if the latest release targets a different binary version; use to inform users a store update is required.
Queries DOTA to see if the configured deployment has an update available. By default, uses the deployment key from native config (iOS Info.plist, Android strings.xml / app). Pass deploymentKey to override (e.g., early‑access toggles).
Binary version mismatch callback:
handleBinaryVersionMismatchCallback (optional) fires when the latest release targets a different binary version than the one currently installed. In this case, DOTA will ignore the code update (it cannot apply against your current native binaries).
- Example: the device runs binary 1.0.1 (label
v1). A new release targets binary 1.0.2 (native changes).checkForUpdatewill NOT return that code update for 1.0.1. Instead, this callback receives theRemotePackageso you can inform the user that a store update is required.
Avoid gating features with forced alerts or interactions inside this callback. App Store guidelines disallow forcing users to rate/review/download other apps or take similar actions to access functionality.
Returns:
nullwhen no update is applicable. Common reasons:- No releases in the deployment
- Latest release targets a different binary version
- The device already has the latest release
- Latest release is disabled
- Release is in an active rollout and the device is outside the rollout percentage
RemotePackagewhen an update is available – see Package objects → RemotePackage
Example:
codePush.checkForUpdate()
.then((update) => {
if (!update) {
console.log('The app is up to date!');
} else {
console.log('An update is available! Should we download it?');
}
});
disallowRestart
codePush.disallowRestart(): void;
- Purpose: Prevent programmatic restarts during critical flows (e.g., onboarding, checkout).
- Effect: Restarts are queued until
allowRestart()is called. - Pairs with:
allowRestart,restartApp, Install Modes.
Blocks restarts triggered by:
InstallMode.IMMEDIATEInstallMode.ON_NEXT_RESUMEwhen the app resumes (subject tominimumBackgroundDuration)- Explicit calls to
restartApp()
Behavior:
- Updates can still be checked, downloaded, and installed.
- Any restart attempts are queued and only applied after
allowRestart().
When to use:
- Onboarding, authentication, payments, or any flow where interruptions are unacceptable.
Use InstallMode.ON_NEXT_RESTART on sync() to avoid programmatic restarts altogether, and call restartApp() yourself at safe points.
Example:
import React, { useEffect } from 'react';
import codePush from '@d11/dota';
function OnboardingProcess() {
useEffect(() => {
// Prevent restarts while onboarding is visible
codePush.disallowRestart();
return () => {
// Re‑allow restarts (and flush any queued restart)
codePush.allowRestart();
};
}, []);
return null;
}
getUpdateMetadata
function getUpdateMetadata(
updateState?: UpdateState, // default: UpdateState.RUNNING
): Promise<LocalPackage | null>;
- Purpose: Retrieve metadata (e.g., description, mandatory, label) for a running or pending DOTA update.
- Default: Without args, returns the currently running update (if any).
- See also: UpdateState, LocalPackage.
Retrieves metadata for an installed update whose state matches updateState. Useful for displaying a “What’s new?” dialog after activation or checking whether an update is pending (awaiting resume/restart).
Returns:
nullif no update for the requested state exists. Common cases:- No DOTA updates have ever been installed on this device
- A store (binary) update was installed, which clears previous DOTA updates
UpdateState.RUNNINGrequested but the app is currently running the binary bundle (no DOTA update active)UpdateState.PENDINGrequested but there is no pending update
LocalPackagewith metadata for the requested update
Examples:
// Running update: attach label to analytics / show What's new
const running = await codePush.getUpdateMetadata(); // default: RUNNING
if (running) {
console.log('Running DOTA update label:', running.label);
}
// Pending update: decide whether to restart now
const pending = await codePush.getUpdateMetadata(codePush.UpdateState.PENDING);
if (pending) {
// e.g., prompt user or programmatically restart when safe
}
notifyAppReady
function notifyAppReady(): Promise<void>;
- Purpose: Mark the freshly installed update as successful so it won’t auto‑rollback.
- Required when: You manage install flow yourself (not using
syncat app start). - Not needed when: You use
syncduring app start — it calls this for you.
Notifies DOTA that the current update launched successfully. If you don’t call this for a newly installed update (and aren’t using sync at startup), the runtime will assume the update failed and automatically roll back on next launch — protecting users from a broken update.
await codePush.notifyAppReady();
Alias: notifyApplicationReady (backwards compatibility).
restartApp
function restartApp(onlyIfUpdateIsPending?: boolean): void;
- Purpose: Programmatically restart the app.
- Guard:
onlyIfUpdateIsPending = truerestarts only when an update is pending. - Pairs with: Install Modes,
disallowRestart,allowRestart.
When to use
- You install updates with
ON_NEXT_RESTARTorON_NEXT_RESUMEand want to apply them at a specific, low‑impact moment (e.g., user returned to Home). - You want to avoid waiting for the OS/user restart/resume but still control timing.
Examples
// Restart immediately (regardless of pending updates)
codePush.restartApp();
// Restart only if an update is pending
codePush.restartApp(true);
clearUpdates
function clearUpdates(): void;
Clears all downloaded DOTA updates. Useful when switching to a different deployment which may have an older release than the current package.
Avoid using this outside of deployment switching. DOTA clears updates automatically when needed; forcing it elsewhere can lead to unpredictable behavior.
Package objects
Some methods return "package" objects which represent a DOTA code update and its metadata.
LocalPackage
Represents a downloaded update that is already running, or installed and pending restart. Produced by getUpdateMetadata or by RemotePackage.download().
Properties:
appVersion(string) – binary app version this update depends ondeploymentKey(string) – key used to download this updatedescription(string) – release notes/description from the releasefailedInstall(boolean) – this update was previously installed and rolled backisFirstRun(boolean) – first launch after installing this updateisMandatory(boolean) – release marked as mandatoryisPending(boolean) – installed but not yet activated (awaiting resume/restart)label(string) – DOTA label likev5unique within the deploymentpackageHash(string) – SHA hash of the updatepackageSize(number) – size in bytes
Methods:
install(
installMode?: typeof codePush.InstallMode[keyof typeof codePush.InstallMode],
minimumBackgroundDuration?: number,
): Promise<void>
Parameters:
- installMode: when to apply the update. Default:
ON_NEXT_RESTART. - minimumBackgroundDuration: used with
ON_NEXT_RESUME; seconds the app must stay in background before applying.
RemotePackage
Represents an available update on the DOTA server that hasn't been downloaded yet. Produced by checkForUpdate.
Inherits all LocalPackage properties and adds:
downloadUrl(string) – direct URL for the update payload (usually not needed)
Methods:
download(
downloadProgressCallback?: (progress: { totalBytes: number; receivedBytes: number }) => void,
): Promise<LocalPackage>
Parameters:
- downloadProgressCallback: optional callback to receive download progress as
{ totalBytes, receivedBytes }.
Returns:
LocalPackagewith the downloaded update.
DOTA Events
Use these callbacks to track update lifecycle and download progress. Pass them to sync to be notified of state changes and bytes downloaded. See Enums → SyncStatus for status details. Helpful for analytics and monitoring major DOTA events.
codePushStatusDidChange(status: SyncStatus)– stage changes (checking, downloading, installing, etc.)codePushDownloadDidProgress({ totalBytes, receivedBytes })– download progress
Enums
SyncStatus
| Value | Code | Description |
|---|---|---|
| UP_TO_DATE | 0 | App is fully up‑to‑date with the configured deployment |
| UPDATE_INSTALLED | 1 | Update installed; activation depends on install mode |
| UPDATE_IGNORED | 2 | Optional update ignored by user (only with updateDialog) |
| UNKNOWN_ERROR | 3 | Unknown error occurred |
| SYNC_IN_PROGRESS | 4 | Another sync is already running |
| CHECKING_FOR_UPDATE | 5 | Contacting the DOTA server for an update |
| AWAITING_USER_ACTION | 6 | Awaiting dialog interaction (only with updateDialog) |
| DOWNLOADING_PACKAGE | 7 | Downloading the update from the server |
| INSTALLING_UPDATE | 8 | Installing downloaded update |
| UPDATE_IGNORED_ROLLBACK | 9 | Update ignored due to previous rollback |
| UPDATE_AVAILABLE | 10 | Update available and about to download |
| PATCH_APPLIED_SUCCESS | 11 | Patch bundle applied successfully |
| DOWNLOAD_REQUEST_SUCCESS | 12 | Update downloaded successfully |
| UNZIPPED_SUCCESS | 13 | Update unzipped successfully |
| DECOMPRESSED_SUCCESS | 14 | Update decompressed successfully |
UpdateState
| Value | Description |
|---|---|
| RUNNING | Update currently running |
| PENDING | Installed, awaiting resume/restart |
| LATEST | Latest available (running or pending) |