Skip to content
THE OTA MANUALReference
Updatedv0.1.0 ↗

TypeScript SDK API ​

Import the singleton updates API (or construct a custom instance with createOtaUpdates) from @getcortexlabs/ota-nativescript.

updates singleton ​

ts
import { updates, OtaError, OTA_ERROR_CODES } from '@getcortexlabs/ota-nativescript';

updates.markReady(): boolean ​

Confirms the currently booting release synchronously and offline. Promotes pendingLaunch to confirmedReleaseId in state.json and clears pendingLaunch.

  • Call once your first usable screen mounts.
  • Returns true if a pending OTA launch was promoted, false if already confirmed or booting embedded.

updates.getBootInfo(): NativeBootInfo | null ​

Returns live boot metadata from the native bootstrapper:

ts
interface NativeBootInfo {
  source: 'embedded' | 'ota';
  releaseId: string | null;
  bundlePath: string;
  binaryVersion: string;
  targetBuild: string;
  runtimeContract: string;
  pendingConfirmation: boolean;
  launchAttempts: number;
  lastRecovery: RecoveryInfo | null;
  v8SnapshotDetected?: boolean; // Android diagnostic
}

updates.getCurrentRelease(): string | null ​

Shorthand returning the active OTA releaseId, or null when running the embedded store bundle.

updates.check(options?: RequestOptions): Promise<CheckResult> ​

Queries the configured HTTPS endpoint (POST /check), verifies the Ed25519 directive signature, checks compatibility (appId, platform, targetBuild, runtimeContract) and monotonic directiveSeq.

Returns:

  • { status: 'none' }
  • { status: 'update', directive }
  • { status: 'rollback_to_embedded', directive }

updates.downloadAndStage(directive, options?): Promise<StageResult> ​

Downloads the signed manifest, verifies its Ed25519 signature and compatibility, reuses verified local files matching exact sha256 + size (APFS CoW on iOS; byte copy on Android), streams remaining files into isolated staging/<tmp-id>/app, verifies exact sizes and SHA-256 digests across the complete directory, rejects symlinks and extra files, moves atomically into releases/<releaseId>, updates state.json, and garbage-collects obsolete release directories.

Returns { status: 'staged', releaseId, bytesDownloaded, bytesReused, fileCount, reusedFileCount, durationMs } or { status: 'rollback_staged' }.

updates.checkAndStage(options?: DownloadAndStageOptions): Promise<CheckAndStageResult> ​

Convenience pipeline combining check() + downloadAndStage() with single-flight protection so concurrent calls share one in-flight operation.

ts
interface DownloadAndStageOptions {
  signal?: AbortSignal;
  timeoutMs?: number; // default 30_000 ms
  maxBundleBytes?: number; // default 100 MiB
  onProgress?: (progress: {
    filesCompleted: number;
    totalFiles: number;
    bytesReceived: number;
    totalBytes: number;
    currentFile: string;
    reused?: boolean;
    bytesDownloaded?: number;
    bytesReused?: number;
  }) => void;
}

updates.collectGarbage(): Promise<string[]> ​

Removes any release directories in releases/ not referenced by active, confirmedReleaseId, stagedReleaseId or pendingLaunch, returning deleted release IDs.

updates.onEvent(listener): () => void ​

Subscribes to structured OtaLifecycleEvent updates (download_completed, validation_failed, staged, startup_confirmed, recovered_fallback) and returns an unsubscribe function.

Error codes (OTA_ERROR_CODES) ​

All verification, compatibility, download and staging failures throw OtaError with a stable code:

  • Crypto & protocol: SIGNATURE_INVALID, KEY_NOT_FOUND, MANIFEST_INVALID, DIRECTIVE_INVALID, DIRECTIVE_RELEASE_MISMATCH, REPLAY_DETECTED, INSECURE_URL
  • Compatibility: PLATFORM_MISMATCH, APP_ID_MISMATCH, TARGET_BUILD_MISMATCH, RUNTIME_CONTRACT_MISMATCH, PROTOCOL_VERSION_UNSUPPORTED
  • Integrity & staging: HASH_MISMATCH, SIZE_MISMATCH, MISSING_FILE, UNEXPECTED_FILE, UNSAFE_PATH, BUNDLE_TOO_LARGE, DOWNLOAD_FAILED, STORAGE_IO_ERROR, RELEASE_BLOCKLISTED

Installation references and remote reports ​

Create one createOtaUpdates({ installId }) instance with a random app-scoped UUID persisted across launches, and use that instance for markReady() and checks. Operating Otto includes a NativeScript persistence example. The default singleton does not invent an installation identity.

The optional ID accompanies checks and lifecycle reports. Checks also report a timestamp and nullable confirmed/prepared release IDs. recovered_fallback.recoveredAt preserves the native recovery time, while its timestamp is the report time. Telemetry failure never blocks offline startup confirmation or recovery. A new SDK build is required for these optional observation fields; legacy reports stay valid and anonymous when no ID is supplied.

download_completed includes downloaded/reused bytes, file counts and staging duration. validation_failed carries a stable error code. staged identifies the prepared release/directive. startup_confirmed reports the actual boot source and release. recovered_fallback identifies the failed release and fallback destination. Download progress is the onProgress callback, not a separate lifecycle event.