UNPKG

@hot-updater/react-native

Version:

React Native OTA solution for self-hosted

66 lines (64 loc) 1.97 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.checkForUpdate = checkForUpdate; var _reactNative = require("react-native"); var _error = require("./error.js"); var _native = require("./native.js"); // Internal type that includes resolver for use within index.ts async function checkForUpdate(options) { if (__DEV__) { return null; } if (!["ios", "android"].includes(_reactNative.Platform.OS)) { options.onError?.(new _error.HotUpdaterError("HotUpdater is only supported on iOS and Android")); return null; } const currentAppVersion = (0, _native.getAppVersion)(); const platform = _reactNative.Platform.OS; const currentBundleId = (0, _native.getBundleId)(); const minBundleId = (0, _native.getMinBundleId)(); const channel = (0, _native.getChannel)(); if (!currentAppVersion) { options.onError?.(new _error.HotUpdaterError("Failed to get app version")); return null; } const fingerprintHash = (0, _native.getFingerprintHash)(); if (!options.resolver?.checkUpdate) { options.onError?.(new _error.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 (0, _native.updateBundle)({ bundleId: updateInfo.id, fileUrl: updateInfo.fileUrl, fileHash: updateInfo.fileHash, status: updateInfo.status }); } }; } //# sourceMappingURL=checkForUpdate.js.map