Skip to content

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;
}

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, streams all files into isolated staging/<releaseId>, verifies exact sizes and SHA-256 digests, rejects symlinks and extra files, moves atomically into releases/<releaseId>, updates state.json, and garbage-collects obsolete release directories.

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 50 MiB
  onProgress?: (progress: {
    completedFiles: number;
    totalFiles: number;
    bytesDownloaded: number;
    totalBytes: 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 (check_started, download_progress, staged, boot_confirmed, recovery_triggered, error) 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