Command palette

@yasinsensoy/native

React Native · APIs and utilities

OTA updates

Update operations that can be called individually.

9 exports

Import

import { Updates, useUpdates } from "@yasinsensoy/native/updates";

Updates

module

Update operations that can be called individually. Harmless without the native module (web, tests).

NameTypeDescription
isSupportedbooleanWhether the native module exists in this app.
getState() => Promise<UpdatesState>State on the device.
check() => Promise<UpdateCheckResult>Checks the server; does not download.
fetch() => Promise<UpdateFetchResult>Checks; if there is a new update, downloads, verifies and stages it for the next launch. To run it immediately, call Updates.reload afterwards.
reload() => voidReopens the app immediately with the pending update. On iOS the bundle is reloaded; on Android the process restarts (~1 s).
markReady() => voidReports that the running update is healthy. Even if you do not call it, it is marked automatically when readyTimeout (default 10 s) expires or the app goes to the background; calling it early shortens the rollback guard.
setChannel(channel: string | null) => Promise<void>Changes the channel for this device (e.g. moving test users to "beta"); null returns to the configured channel. Applies from the next check.
reset() => Promise<void>Drops the downloads; the embedded bundle runs on the next launch.

useUpdates

function

Connects the update state to a component: a "new version ready" banner, version info on a settings screen and so on. Optional; even without it updates download automatically on the native side and apply on the next launch.

useUpdates(options?: UseUpdatesOptions): UseUpdatesResult

Summary of an update in the manifest.

NameTypeDescription
idstringUpdate id.
createdAtstring | nullPublish time (ISO 8601).
messagestring | nullNote given when publishing (--message).
criticalbooleanMarked critical (--critical): the app may want to apply it immediately.
rollbackbooleanRollback manifest: returns to the embedded bundle.
extraRecord<string, unknown> | nullExtra data given when publishing (--extra).

UpdatesState

interface

Update state on the device.

NameTypeDescription
enabledbooleanWhether updates are enabled in this build (release build + config).
urlstringManifest server.
channelstringActive channel (may have been changed for this device).
runtimeVersionstringVersion of the native code; an update applies only to the same version.
platformstring"android" or "ios".
updateIdstring | nullThe running update; null if the embedded bundle is running.
isEmbeddedbooleanWhether the embedded (store) bundle is running.
pendingIdstring | nullDownloaded update that will run on the next launch ("embedded": return to the embedded one).
confirmedbooleanWhether the running update was marked healthy.
lastRollback{ id: string; reason: string; at: number; } | nullLast rollback: which update, why ("crash", "missing"), when (ms).
lastChecknumber | nullLast check time (ms).
lastErrorstring | nullLast check error.
manifestUpdateManifest | nullSummary of the running update.

Check result: none up to date, available a new update exists, rollback the server wants a return to the embedded bundle, excluded left out of a staged rollout, failed this update crashed on this device before, disabled updates are off (debug build or no config).

type UpdateCheckStatus = "none" | "available" | "rollback" | "excluded" | "failed" | "disabled"

Result of Updates.check.

NameTypeDescription
statusUpdateCheckStatusCheck result.
manifestUpdateManifest | nullManifest on the server (null if none).

Result of Updates.fetch; status is "downloaded" if it was downloaded.

NameTypeDescription
statusUpdateCheckStatus | "downloaded"Fetch result; "downloaded" if an update was downloaded.
manifestUpdateManifest | nullManifest of the update on the server (null if none).

useUpdates options.

NameTypeDefaultDescription
fetchOnMount?booleanfalseChecks and downloads when the component mounts. The native side already checks on launch (checkOnLaunch); this brings the result to the component.
checkOnForeground?booleanfalseChecks and downloads every time the app comes to the foreground.
minInterval?number300000` (5 min)Minimum time between foreground checks (ms).
applyCritical?booleanfalseApplies a critical update immediately once downloaded.

Return value of useUpdates.

NameTypeDescription
stateUpdatesState | nullState on the device (null until the first read).
phase"idle" | "fetching"What is happening right now.
downloadedUpdateManifest | nullDownloaded update waiting to be applied.
errorError | nullLast error.
fetch(): Promise<UpdateFetchResult>Checks and downloads.
apply(): voidApplies the pending update immediately.