@hot-updater/react-native
Version:
React Native OTA solution for self-hosted
203 lines • 7.25 kB
TypeScript
import { type CheckForUpdateOptions } from "./checkForUpdate";
import { type UpdateParams } from "./native";
import { type HotUpdaterOptions } from "./wrap";
export type { HotUpdaterEvent, NotifyAppReadyResult } from "./native";
export * from "./store";
export { extractSignatureFailure, type HotUpdaterResolver, isSignatureVerificationError, type ResolverCheckUpdateParams, type ResolverNotifyAppReadyParams, type SignatureVerificationFailure, } from "./types";
export type { HotUpdaterOptions, RunUpdateProcessResponse } from "./wrap";
export declare const HotUpdater: {
/**
* `HotUpdater.wrap` checks for updates at the entry point, and if there is a bundle to update, it downloads the bundle and applies the update strategy.
*
* @param {object} options - Configuration options
* @param {string} options.source - Update server URL
* @param {object} [options.requestHeaders] - Request headers
* @param {React.ComponentType} [options.fallbackComponent] - Component to display during updates
* @param {boolean} [options.reloadOnForceUpdate=true] - Whether to automatically reload the app on force updates
* @param {Function} [options.onUpdateProcessCompleted] - Callback after update process completes
* @param {Function} [options.onProgress] - Callback to track bundle download progress
* @returns {Function} Higher-order component that wraps the app component
*
* @example
* ```tsx
* export default HotUpdater.wrap({
* baseURL: "<your-update-server-url>",
* updateStrategy: "appVersion",
* updateMode: "auto",
* requestHeaders: {
* "Authorization": "Bearer <your-access-token>",
* },
* })(App);
* ```
*/
wrap: (options: HotUpdaterOptions) => (WrappedComponent: import("react").ComponentType<object>) => import("react").ComponentType<object>;
/**
* Reloads the app.
*/
reload: () => Promise<void>;
/**
* Returns whether an update has finished downloading in this app session.
*
* When it returns true, calling `HotUpdater.reload()` (or restarting the app)
* will apply the downloaded update bundle.
*
* - Derived from `progress` reaching 1.0
* - Resets to false when a new download starts (progress < 1)
*
* @returns {boolean} True if a downloaded update is ready to apply
* @example
* ```ts
* if (HotUpdater.isUpdateDownloaded()) {
* await HotUpdater.reload();
* }
* ```
*/
isUpdateDownloaded: () => boolean;
/**
* Fetches the current app version.
*/
getAppVersion: () => string | null;
/**
* Fetches the current bundle ID of the app.
*/
getBundleId: () => string;
/**
* Retrieves the initial bundle ID based on the build time of the native app.
*/
getMinBundleId: () => string;
/**
* Fetches the current channel of the app.
*
* If no channel is specified, the app is assigned to the 'production' channel.
*
* @returns {string} The current release channel of the app
* @default "production"
* @example
* ```ts
* const channel = HotUpdater.getChannel();
* console.log(`Current channel: ${channel}`);
* ```
*/
getChannel: () => string;
/**
* Adds a listener to HotUpdater events.
*
* @param {keyof HotUpdaterEvent} eventName - The name of the event to listen for
* @param {(event: HotUpdaterEvent[T]) => void} listener - The callback function to handle the event
* @returns {() => void} A cleanup function that removes the event listener
*
* @example
* ```ts
* const unsubscribe = HotUpdater.addListener("onProgress", ({ progress }) => {
* console.log(`Update progress: ${progress * 100}%`);
* });
*
* // Unsubscribe when no longer needed
* unsubscribe();
* ```
*/
addListener: <T extends keyof import("./native").HotUpdaterEvent>(eventName: T, listener: (event: import("./native").HotUpdaterEvent[T]) => void) => () => void;
/**
* Manually checks for updates.
*
* @param {Object} config - Update check configuration
* @param {string} config.source - Update server URL
* @param {Record<string, string>} [config.requestHeaders] - Request headers
*
* @returns {Promise<UpdateInfo | null>} Update information or null if up to date
*
* @example
* ```ts
* const updateInfo = await HotUpdater.checkForUpdate({
* source: "<your-update-server-url>",
* requestHeaders: {
* Authorization: "Bearer <your-access-token>",
* },
* });
*
* if (!updateInfo) {
* console.log("App is up to date");
* return;
* }
*
* await HotUpdater.updateBundle(updateInfo.id, updateInfo.fileUrl);
* if (updateInfo.shouldForceUpdate) {
* await HotUpdater.reload();
* }
* ```
*/
checkForUpdate: (config: CheckForUpdateOptions) => Promise<import("./checkForUpdate").CheckForUpdateResult | null>;
/**
* Updates the bundle of the app.
*
* @param {UpdateBundleParams} params - Parameters object required for bundle update
* @param {string} params.bundleId - The bundle ID of the app
* @param {string|null} params.fileUrl - The URL of the zip file
*
* @returns {Promise<boolean>} Whether the update was successful
*
* @example
* ```ts
* const updateInfo = await HotUpdater.checkForUpdate({
* source: "<your-update-server-url>",
* requestHeaders: {
* Authorization: "Bearer <your-access-token>",
* },
* });
*
* if (!updateInfo) {
* return {
* status: "UP_TO_DATE",
* };
* }
*
* await HotUpdater.updateBundle({
* bundleId: updateInfo.id,
* fileUrl: updateInfo.fileUrl
* });
* if (updateInfo.shouldForceUpdate) {
* await HotUpdater.reload();
* }
* ```
*/
updateBundle: (params: UpdateParams) => Promise<boolean>;
/**
* Fetches the fingerprint of the app.
*
* @returns {string} The fingerprint of the app
*
* @example
* ```ts
* const fingerprint = HotUpdater.getFingerprintHash();
* console.log(`Fingerprint: ${fingerprint}`);
* ```
*/
getFingerprintHash: () => string | null;
/**
* 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
*
* @example
* ```ts
* const crashedBundles = HotUpdater.getCrashHistory();
* console.log("Crashed bundles:", crashedBundles);
* ```
*/
getCrashHistory: () => string[];
/**
* Clears the crashed bundle history, allowing previously crashed bundles
* to be installed again.
*
* @returns {boolean} true if clearing was successful
*
* @example
* ```ts
* // Clear crash history to allow retrying a previously failed bundle
* HotUpdater.clearCrashHistory();
* ```
*/
clearCrashHistory: () => boolean;
};
//# sourceMappingURL=index.d.ts.map