UNPKG

@appzung/react-native-code-push

Version:

React Native plugin for the CodePush service

63 lines (62 loc) 2.69 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.shouldUpdateBeIgnored = shouldUpdateBeIgnored; var _LogLevelEnum = require("../enums/LogLevel.enum.js"); var _NativeRNAppZungCodePushModule = require("./NativeRNAppZungCodePushModule.js"); var _log = require("./utils/log.js"); const DEFAULT_ROLLBACK_RETRY_OPTIONS = { delayInHours: 24, maxRetryAttempts: 1 }; function validateLatestRollbackInfo(latestRollbackInfo, packageHash) { return latestRollbackInfo && latestRollbackInfo.time && latestRollbackInfo.count && latestRollbackInfo.packageHash && latestRollbackInfo.packageHash === packageHash; } function validateRollbackRetryOptions(rollbackRetryOptions) { if (typeof rollbackRetryOptions.delayInHours !== 'number') { (0, _log.log)(_LogLevelEnum.LogLevel.ERROR, "The 'delayInHours' rollback retry parameter must be a number."); return false; } if (typeof rollbackRetryOptions.maxRetryAttempts !== 'number') { (0, _log.log)(_LogLevelEnum.LogLevel.ERROR, "The 'maxRetryAttempts' rollback retry parameter must be a number."); return false; } if (rollbackRetryOptions.maxRetryAttempts < 1) { (0, _log.log)(_LogLevelEnum.LogLevel.ERROR, "The 'maxRetryAttempts' rollback retry parameter cannot be less then 1."); return false; } return true; } async function shouldUpdateBeIgnored(remotePackage, syncOptions) { const isFailedPackage = remotePackage && remotePackage.failedInstall; if (!isFailedPackage || !syncOptions.ignoreFailedUpdates) { return false; } if (!syncOptions.rollbackRetryOptions) { return true; } const rollbackRetryOptions = typeof syncOptions.rollbackRetryOptions === 'object' ? { ...DEFAULT_ROLLBACK_RETRY_OPTIONS, ...syncOptions.rollbackRetryOptions } : DEFAULT_ROLLBACK_RETRY_OPTIONS; if (!validateRollbackRetryOptions(rollbackRetryOptions)) { return true; } const latestRollbackInfo = await _NativeRNAppZungCodePushModule.NativeRNAppZungCodePushModule.getLatestRollbackInfo(); if (!validateLatestRollbackInfo(latestRollbackInfo, remotePackage.packageHash)) { (0, _log.log)(_LogLevelEnum.LogLevel.ERROR, 'The latest rollback info is not valid.'); return true; } const { delayInHours, maxRetryAttempts } = rollbackRetryOptions; const hoursSinceLatestRollback = (Date.now() - latestRollbackInfo.time) / (1000 * 60 * 60); if (hoursSinceLatestRollback >= delayInHours && maxRetryAttempts >= latestRollbackInfo.count) { (0, _log.log)(_LogLevelEnum.LogLevel.INFO, 'Previous rollback should be ignored due to rollback retry options.'); return false; } return true; } //# sourceMappingURL=shouldUpdateBeIgnored.js.map