UNPKG

@hot-updater/react-native

Version:

React Native OTA solution for self-hosted

124 lines 4.39 kB
import type { UpdateStatus } from "@hot-updater/core"; import { HotUpdaterErrorCode, isHotUpdaterError } from "./error"; import { type UpdateBundleParams } from "./specs/NativeHotUpdater"; export { HotUpdaterErrorCode, isHotUpdaterError }; export declare const HotUpdaterConstants: { HOT_UPDATER_BUNDLE_ID: string; }; export type HotUpdaterEvent = { onProgress: { progress: number; }; }; export declare const addListener: <T extends keyof HotUpdaterEvent>(eventName: T, listener: (event: HotUpdaterEvent[T]) => void) => () => void; export type UpdateParams = UpdateBundleParams & { status: UpdateStatus; }; /** * Downloads files and applies them to the app. * * @param {UpdateParams} params - Parameters object required for bundle update * @returns {Promise<boolean>} Resolves with true if download was successful * @throws {Error} Rejects with error.code from HotUpdaterErrorCode enum and error.message */ export declare function updateBundle(params: UpdateParams): Promise<boolean>; /** * @deprecated Use updateBundle(params: UpdateBundleParamsWithStatus) instead */ export declare function updateBundle(bundleId: string, fileUrl: string | null): Promise<boolean>; /** * Fetches the current app version. */ export declare const getAppVersion: () => string | null; /** * Reloads the app. */ export declare const reload: () => Promise<void>; /** * Fetches the minimum bundle id, which represents the initial bundle of the app * since it is created at build time. * * @returns {string} Resolves with the minimum bundle id or null if not available. */ export declare const getMinBundleId: () => string; /** * Fetches the current bundle version id. * * @async * @returns {string} Resolves with the current version id or null if not available. */ export declare const getBundleId: () => string; /** * Fetches the channel for the app. * * @returns {string} Resolves with the channel or null if not available. */ export declare const getChannel: () => string; /** * Fetches the fingerprint for the app. * * @returns {string | null} Resolves with the fingerprint hash */ export declare const getFingerprintHash: () => string | null; /** * Result returned by notifyAppReady() */ export type NotifyAppReadyResult = { status: "PROMOTED" | "RECOVERED" | "STABLE"; crashedBundleId?: string; }; /** * Notifies the native side that the app has successfully started with the current bundle. * If the bundle matches the staging bundle, it promotes to stable. * * This function is called automatically when the module loads. * * @returns {NotifyAppReadyResult} Bundle state information * - `status: "PROMOTED"` - Staging bundle was promoted to stable (ACTIVE event) * - `status: "RECOVERED"` - App recovered from crash, rollback occurred (ROLLBACK event) * - `status: "STABLE"` - No changes, already stable * - `crashedBundleId` - Present only when status is "RECOVERED" * * @example * ```ts * const result = HotUpdater.notifyAppReady(); * * switch (result.status) { * case "PROMOTED": * // Send ACTIVE analytics event * analytics.track('bundle_active', { bundleId: HotUpdater.getBundleId() }); * break; * case "RECOVERED": * // Send ROLLBACK analytics event * analytics.track('bundle_rollback', { crashedBundleId: result.crashedBundleId }); * break; * case "STABLE": * // No special action needed * break; * } * ``` */ export declare const notifyAppReady: () => NotifyAppReadyResult; /** * Gets the list of bundle IDs that have been marked as crashed. * These bundles will be rejected if attempted to install again. * * @returns {string[]} Array of crashed bundle IDs */ export declare const getCrashHistory: () => string[]; /** * Clears the crashed bundle history, allowing previously crashed bundles * to be installed again. * * @returns {boolean} true if clearing was successful */ export declare const clearCrashHistory: () => boolean; /** * Gets the base URL for the current active bundle directory. * Returns the file:// URL to the bundle directory without trailing slash. * This is used for Expo DOM components to construct full asset paths. * * @returns {string | null} Base URL string (e.g., "file:///data/.../bundle-store/abc123") or null if not available */ export declare const getBaseURL: () => string | null; //# sourceMappingURL=native.d.ts.map