@hot-updater/react-native
Version:
React Native OTA solution for self-hosted
63 lines (60 loc) • 1.83 kB
JavaScript
;
import { Platform } from "react-native";
import { HotUpdaterError } from "./error.js";
import { getAppVersion, getBundleId, getChannel, getFingerprintHash, getMinBundleId, updateBundle } from "./native.js";
// Internal type that includes resolver for use within index.ts
export async function checkForUpdate(options) {
if (__DEV__) {
return null;
}
if (!["ios", "android"].includes(Platform.OS)) {
options.onError?.(new HotUpdaterError("HotUpdater is only supported on iOS and Android"));
return null;
}
const currentAppVersion = getAppVersion();
const platform = Platform.OS;
const currentBundleId = getBundleId();
const minBundleId = getMinBundleId();
const channel = getChannel();
if (!currentAppVersion) {
options.onError?.(new HotUpdaterError("Failed to get app version"));
return null;
}
const fingerprintHash = getFingerprintHash();
if (!options.resolver?.checkUpdate) {
options.onError?.(new HotUpdaterError("Resolver is required but not configured"));
return null;
}
let updateInfo = null;
try {
updateInfo = await options.resolver.checkUpdate({
platform,
appVersion: currentAppVersion,
bundleId: currentBundleId,
minBundleId,
channel,
updateStrategy: options.updateStrategy,
fingerprintHash,
requestHeaders: options.requestHeaders,
requestTimeout: options.requestTimeout
});
} catch (error) {
options.onError?.(error);
return null;
}
if (!updateInfo) {
return null;
}
return {
...updateInfo,
updateBundle: async () => {
return updateBundle({
bundleId: updateInfo.id,
fileUrl: updateInfo.fileUrl,
fileHash: updateInfo.fileHash,
status: updateInfo.status
});
}
};
}
//# sourceMappingURL=checkForUpdate.js.map