@algocare/react-native-code-push 9.0.0-beta.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/AlertAdapter.js +24 -0
- package/CONTRIBUTING.md +134 -0
- package/CodePush.js +778 -0
- package/CodePush.podspec +27 -0
- package/LICENSE.md +13 -0
- package/README.md +491 -0
- package/SECURITY.md +41 -0
- package/android/app/build.gradle +31 -0
- package/android/app/proguard-rules.pro +25 -0
- package/android/app/src/main/AndroidManifest.xml +6 -0
- package/android/app/src/main/java/com/microsoft/codepush/react/CodePush.java +441 -0
- package/android/app/src/main/java/com/microsoft/codepush/react/CodePushBuilder.java +37 -0
- package/android/app/src/main/java/com/microsoft/codepush/react/CodePushConstants.java +35 -0
- package/android/app/src/main/java/com/microsoft/codepush/react/CodePushDialog.java +102 -0
- package/android/app/src/main/java/com/microsoft/codepush/react/CodePushInstallMode.java +16 -0
- package/android/app/src/main/java/com/microsoft/codepush/react/CodePushInvalidPublicKeyException.java +12 -0
- package/android/app/src/main/java/com/microsoft/codepush/react/CodePushInvalidUpdateException.java +7 -0
- package/android/app/src/main/java/com/microsoft/codepush/react/CodePushMalformedDataException.java +12 -0
- package/android/app/src/main/java/com/microsoft/codepush/react/CodePushNativeModule.java +714 -0
- package/android/app/src/main/java/com/microsoft/codepush/react/CodePushNotInitializedException.java +12 -0
- package/android/app/src/main/java/com/microsoft/codepush/react/CodePushTelemetryManager.java +175 -0
- package/android/app/src/main/java/com/microsoft/codepush/react/CodePushUnknownException.java +12 -0
- package/android/app/src/main/java/com/microsoft/codepush/react/CodePushUpdateManager.java +383 -0
- package/android/app/src/main/java/com/microsoft/codepush/react/CodePushUpdateState.java +15 -0
- package/android/app/src/main/java/com/microsoft/codepush/react/CodePushUpdateUtils.java +268 -0
- package/android/app/src/main/java/com/microsoft/codepush/react/CodePushUtils.java +238 -0
- package/android/app/src/main/java/com/microsoft/codepush/react/DownloadProgress.java +30 -0
- package/android/app/src/main/java/com/microsoft/codepush/react/DownloadProgressCallback.java +5 -0
- package/android/app/src/main/java/com/microsoft/codepush/react/FileUtils.java +203 -0
- package/android/app/src/main/java/com/microsoft/codepush/react/ReactInstanceHolder.java +17 -0
- package/android/app/src/main/java/com/microsoft/codepush/react/SettingsManager.java +173 -0
- package/android/app/src/main/java/com/microsoft/codepush/react/TLSSocketFactory.java +72 -0
- package/android/build.gradle +21 -0
- package/android/codepush.gradle +162 -0
- package/android/gradle/wrapper/gradle-wrapper.jar +0 -0
- package/android/gradle/wrapper/gradle-wrapper.properties +5 -0
- package/android/gradle.properties +20 -0
- package/android/gradlew +164 -0
- package/android/gradlew.bat +90 -0
- package/android/settings.gradle +1 -0
- package/babel.config.js +3 -0
- package/cli/commands/bundleCommand/bundleCodePush.js +57 -0
- package/cli/commands/bundleCommand/index.js +29 -0
- package/cli/commands/createHistoryCommand/createReleaseHistory.js +53 -0
- package/cli/commands/createHistoryCommand/index.js +29 -0
- package/cli/commands/releaseCommand/addToReleaseHistory.js +75 -0
- package/cli/commands/releaseCommand/index.js +66 -0
- package/cli/commands/releaseCommand/release.js +109 -0
- package/cli/commands/showHistoryCommand/index.js +29 -0
- package/cli/commands/updateHistoryCommand/index.js +50 -0
- package/cli/commands/updateHistoryCommand/updateReleaseHistory.js +62 -0
- package/cli/constant.js +6 -0
- package/cli/functions/getReactTempDir.js +16 -0
- package/cli/functions/makeCodePushBundle.js +28 -0
- package/cli/functions/prepareToBundleJS.js +12 -0
- package/cli/functions/runHermesEmitBinaryCommand.js +213 -0
- package/cli/functions/runReactNativeBundleCommand.js +59 -0
- package/cli/index.js +43 -0
- package/cli/utils/file-utils.js +42 -0
- package/cli/utils/fsUtils.js +49 -0
- package/cli/utils/hash-utils.js +227 -0
- package/cli/utils/promisfied-fs.js +29 -0
- package/cli/utils/showLogo.js +23 -0
- package/cli/utils/zip.js +89 -0
- package/code-push.config.example.supabase.ts +114 -0
- package/docs/api-android.md +83 -0
- package/docs/api-ios.md +31 -0
- package/docs/api-js.md +592 -0
- package/docs/multi-deployment-testing-android.md +148 -0
- package/docs/multi-deployment-testing-ios.md +59 -0
- package/docs/setup-android.md +482 -0
- package/docs/setup-ios.md +280 -0
- package/eslint.config.mjs +32 -0
- package/ios/CodePush/Base64/Base64/MF_Base64Additions.h +34 -0
- package/ios/CodePush/Base64/Base64/MF_Base64Additions.m +252 -0
- package/ios/CodePush/Base64/README.md +47 -0
- package/ios/CodePush/CodePush.h +235 -0
- package/ios/CodePush/CodePush.m +1121 -0
- package/ios/CodePush/CodePushConfig.m +116 -0
- package/ios/CodePush/CodePushDownloadHandler.m +130 -0
- package/ios/CodePush/CodePushErrorUtils.m +20 -0
- package/ios/CodePush/CodePushPackage.m +602 -0
- package/ios/CodePush/CodePushTelemetryManager.m +175 -0
- package/ios/CodePush/CodePushUpdateUtils.m +376 -0
- package/ios/CodePush/CodePushUtils.m +9 -0
- package/ios/CodePush/JWT/Core/Algorithms/Base/JWTAlgorithm.h +69 -0
- package/ios/CodePush/JWT/Core/Algorithms/Base/JWTAlgorithmFactory.h +16 -0
- package/ios/CodePush/JWT/Core/Algorithms/Base/JWTAlgorithmFactory.m +51 -0
- package/ios/CodePush/JWT/Core/Algorithms/Base/JWTAlgorithmNone.h +15 -0
- package/ios/CodePush/JWT/Core/Algorithms/Base/JWTAlgorithmNone.m +55 -0
- package/ios/CodePush/JWT/Core/Algorithms/ESFamily/JWTAlgorithmESBase.h +24 -0
- package/ios/CodePush/JWT/Core/Algorithms/ESFamily/JWTAlgorithmESBase.m +41 -0
- package/ios/CodePush/JWT/Core/Algorithms/HSFamily/JWTAlgorithmHSBase.h +28 -0
- package/ios/CodePush/JWT/Core/Algorithms/HSFamily/JWTAlgorithmHSBase.m +205 -0
- package/ios/CodePush/JWT/Core/Algorithms/Holders/JWTAlgorithmDataHolder.h +103 -0
- package/ios/CodePush/JWT/Core/Algorithms/Holders/JWTAlgorithmDataHolder.m +322 -0
- package/ios/CodePush/JWT/Core/Algorithms/Holders/JWTAlgorithmDataHolderChain.h +37 -0
- package/ios/CodePush/JWT/Core/Algorithms/Holders/JWTAlgorithmDataHolderChain.m +145 -0
- package/ios/CodePush/JWT/Core/Algorithms/RSFamily/JWTAlgorithmRSBase.h +35 -0
- package/ios/CodePush/JWT/Core/Algorithms/RSFamily/JWTAlgorithmRSBase.m +551 -0
- package/ios/CodePush/JWT/Core/Algorithms/RSFamily/JWTRSAlgorithm.h +23 -0
- package/ios/CodePush/JWT/Core/Algorithms/RSFamily/RSKeys/JWTCryptoKey.h +43 -0
- package/ios/CodePush/JWT/Core/Algorithms/RSFamily/RSKeys/JWTCryptoKey.m +230 -0
- package/ios/CodePush/JWT/Core/Algorithms/RSFamily/RSKeys/JWTCryptoKeyExtractor.h +31 -0
- package/ios/CodePush/JWT/Core/Algorithms/RSFamily/RSKeys/JWTCryptoKeyExtractor.m +113 -0
- package/ios/CodePush/JWT/Core/Algorithms/RSFamily/RSKeys/JWTCryptoSecurity.h +38 -0
- package/ios/CodePush/JWT/Core/Algorithms/RSFamily/RSKeys/JWTCryptoSecurity.m +500 -0
- package/ios/CodePush/JWT/Core/ClaimSet/JWTClaim.h +18 -0
- package/ios/CodePush/JWT/Core/ClaimSet/JWTClaim.m +214 -0
- package/ios/CodePush/JWT/Core/ClaimSet/JWTClaimsSet.h +23 -0
- package/ios/CodePush/JWT/Core/ClaimSet/JWTClaimsSet.m +29 -0
- package/ios/CodePush/JWT/Core/ClaimSet/JWTClaimsSetSerializer.h +19 -0
- package/ios/CodePush/JWT/Core/ClaimSet/JWTClaimsSetSerializer.m +68 -0
- package/ios/CodePush/JWT/Core/ClaimSet/JWTClaimsSetVerifier.h +18 -0
- package/ios/CodePush/JWT/Core/ClaimSet/JWTClaimsSetVerifier.m +72 -0
- package/ios/CodePush/JWT/Core/Coding/JWTCoding+ResultTypes.h +67 -0
- package/ios/CodePush/JWT/Core/Coding/JWTCoding+ResultTypes.m +111 -0
- package/ios/CodePush/JWT/Core/Coding/JWTCoding+VersionOne.h +119 -0
- package/ios/CodePush/JWT/Core/Coding/JWTCoding+VersionOne.m +307 -0
- package/ios/CodePush/JWT/Core/Coding/JWTCoding+VersionThree.h +94 -0
- package/ios/CodePush/JWT/Core/Coding/JWTCoding+VersionThree.m +619 -0
- package/ios/CodePush/JWT/Core/Coding/JWTCoding+VersionTwo.h +164 -0
- package/ios/CodePush/JWT/Core/Coding/JWTCoding+VersionTwo.m +514 -0
- package/ios/CodePush/JWT/Core/Coding/JWTCoding.h +24 -0
- package/ios/CodePush/JWT/Core/Coding/JWTCoding.m +11 -0
- package/ios/CodePush/JWT/Core/FrameworkSupplement/JWT.h +52 -0
- package/ios/CodePush/JWT/Core/FrameworkSupplement/Map.modulemap +5 -0
- package/ios/CodePush/JWT/Core/Supplement/JWTBase64Coder.h +28 -0
- package/ios/CodePush/JWT/Core/Supplement/JWTBase64Coder.m +70 -0
- package/ios/CodePush/JWT/Core/Supplement/JWTDeprecations.h +22 -0
- package/ios/CodePush/JWT/Core/Supplement/JWTErrorDescription.h +34 -0
- package/ios/CodePush/JWT/Core/Supplement/JWTErrorDescription.m +73 -0
- package/ios/CodePush/JWT/LICENSE +19 -0
- package/ios/CodePush/JWT/README.md +489 -0
- package/ios/CodePush/RCTConvert+CodePushInstallMode.m +20 -0
- package/ios/CodePush/RCTConvert+CodePushUpdateState.m +20 -0
- package/ios/CodePush/SSZipArchive/Common.h +81 -0
- package/ios/CodePush/SSZipArchive/README.md +1 -0
- package/ios/CodePush/SSZipArchive/SSZipArchive.h +76 -0
- package/ios/CodePush/SSZipArchive/SSZipArchive.m +691 -0
- package/ios/CodePush/SSZipArchive/aes/aes.h +198 -0
- package/ios/CodePush/SSZipArchive/aes/aes_via_ace.h +541 -0
- package/ios/CodePush/SSZipArchive/aes/aescrypt.c +294 -0
- package/ios/CodePush/SSZipArchive/aes/aeskey.c +548 -0
- package/ios/CodePush/SSZipArchive/aes/aesopt.h +739 -0
- package/ios/CodePush/SSZipArchive/aes/aestab.c +391 -0
- package/ios/CodePush/SSZipArchive/aes/aestab.h +173 -0
- package/ios/CodePush/SSZipArchive/aes/brg_endian.h +126 -0
- package/ios/CodePush/SSZipArchive/aes/brg_types.h +219 -0
- package/ios/CodePush/SSZipArchive/aes/entropy.c +54 -0
- package/ios/CodePush/SSZipArchive/aes/entropy.h +16 -0
- package/ios/CodePush/SSZipArchive/aes/fileenc.c +144 -0
- package/ios/CodePush/SSZipArchive/aes/fileenc.h +121 -0
- package/ios/CodePush/SSZipArchive/aes/hmac.c +145 -0
- package/ios/CodePush/SSZipArchive/aes/hmac.h +103 -0
- package/ios/CodePush/SSZipArchive/aes/prng.c +155 -0
- package/ios/CodePush/SSZipArchive/aes/prng.h +82 -0
- package/ios/CodePush/SSZipArchive/aes/pwd2key.c +103 -0
- package/ios/CodePush/SSZipArchive/aes/pwd2key.h +57 -0
- package/ios/CodePush/SSZipArchive/aes/sha1.c +258 -0
- package/ios/CodePush/SSZipArchive/aes/sha1.h +73 -0
- package/ios/CodePush/SSZipArchive/minizip/crypt.h +130 -0
- package/ios/CodePush/SSZipArchive/minizip/ioapi.c +369 -0
- package/ios/CodePush/SSZipArchive/minizip/ioapi.h +175 -0
- package/ios/CodePush/SSZipArchive/minizip/mztools.c +284 -0
- package/ios/CodePush/SSZipArchive/minizip/mztools.h +31 -0
- package/ios/CodePush/SSZipArchive/minizip/unzip.c +1839 -0
- package/ios/CodePush/SSZipArchive/minizip/unzip.h +248 -0
- package/ios/CodePush/SSZipArchive/minizip/zip.c +1910 -0
- package/ios/CodePush/SSZipArchive/minizip/zip.h +202 -0
- package/ios/CodePush.xcodeproj/project.pbxproj +937 -0
- package/ios/CodePush.xcodeproj/project.xcworkspace/contents.xcworkspacedata +7 -0
- package/ios/CodePush.xcodeproj/project.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist +8 -0
- package/logging.js +6 -0
- package/package-mixins.js +61 -0
- package/package.json +84 -0
- package/react-native.config.js +12 -0
- package/scripts/generateBundledResourcesHash.js +125 -0
- package/scripts/getFilesInFolder.js +19 -0
- package/scripts/recordFilesBeforeBundleCommand.js +41 -0
- package/tsconfig.json +14 -0
- package/tslint.json +32 -0
- package/typings/react-native-code-push.d.ts +589 -0
- package/versioning/BaseVersioning.js +126 -0
- package/versioning/BaseVersioning.test.js +15 -0
- package/versioning/IncrementalVersioning.js +9 -0
- package/versioning/IncrementalVersioning.test.js +186 -0
- package/versioning/SemverVersioning.js +10 -0
- package/versioning/SemverVersioning.test.js +205 -0
- package/versioning/index.js +7 -0
package/CodePush.js
ADDED
|
@@ -0,0 +1,778 @@
|
|
|
1
|
+
import { Alert } from "./AlertAdapter";
|
|
2
|
+
import { AppState, Platform } from "react-native";
|
|
3
|
+
import log from "./logging";
|
|
4
|
+
import hoistStatics from 'hoist-non-react-statics';
|
|
5
|
+
import { SemverVersioning } from './versioning/SemverVersioning'
|
|
6
|
+
|
|
7
|
+
let NativeCodePush = require("react-native").NativeModules.CodePush;
|
|
8
|
+
const PackageMixins = require("./package-mixins")(NativeCodePush);
|
|
9
|
+
|
|
10
|
+
async function checkForUpdate(deploymentKey = null, handleBinaryVersionMismatchCallback = null) {
|
|
11
|
+
/*
|
|
12
|
+
* Before we ask the server if an update exists, we
|
|
13
|
+
* need to retrieve three pieces of information from the
|
|
14
|
+
* native side: deployment key, app version (e.g. 1.0.1)
|
|
15
|
+
* and the hash of the currently running update (if there is one).
|
|
16
|
+
* This allows the client to only receive updates which are targetted
|
|
17
|
+
* for their specific deployment and version and which are actually
|
|
18
|
+
* different from the CodePush update they have already installed.
|
|
19
|
+
*/
|
|
20
|
+
const nativeConfig = await getConfiguration();
|
|
21
|
+
/*
|
|
22
|
+
* If a deployment key was explicitly provided,
|
|
23
|
+
* then let's override the one we retrieved
|
|
24
|
+
* from the native-side of the app. This allows
|
|
25
|
+
* dynamically "redirecting" end-users at different
|
|
26
|
+
* deployments (e.g. an early access deployment for insiders).
|
|
27
|
+
*/
|
|
28
|
+
const config = deploymentKey ? { ...nativeConfig, ...{ deploymentKey } } : nativeConfig;
|
|
29
|
+
|
|
30
|
+
// Use dynamically overridden getCurrentPackage() during tests.
|
|
31
|
+
const localPackage = await module.exports.getCurrentPackage();
|
|
32
|
+
|
|
33
|
+
/*
|
|
34
|
+
* If the app has a previously installed update, and that update
|
|
35
|
+
* was targetted at the same app version that is currently running,
|
|
36
|
+
* then we want to use its package hash to determine whether a new
|
|
37
|
+
* release has been made on the server. Otherwise, we only need
|
|
38
|
+
* to send the app version to the server, since we are interested
|
|
39
|
+
* in any updates for current binary version, regardless of hash.
|
|
40
|
+
*/
|
|
41
|
+
let queryPackage;
|
|
42
|
+
if (localPackage) {
|
|
43
|
+
queryPackage = localPackage;
|
|
44
|
+
} else {
|
|
45
|
+
queryPackage = { appVersion: config.appVersion };
|
|
46
|
+
if (Platform.OS === "ios" && config.packageHash) {
|
|
47
|
+
queryPackage.packageHash = config.packageHash;
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
const update = await (async () => {
|
|
52
|
+
try {
|
|
53
|
+
// refer to `UpdateCheckRequest` type inside code-push SDK
|
|
54
|
+
const updateRequest = {
|
|
55
|
+
deployment_key: config.deploymentKey,
|
|
56
|
+
app_version: queryPackage.appVersion,
|
|
57
|
+
package_hash: queryPackage.packageHash,
|
|
58
|
+
is_companion: config.ignoreAppVersion,
|
|
59
|
+
label: queryPackage.label,
|
|
60
|
+
client_unique_id: config.clientUniqueId,
|
|
61
|
+
};
|
|
62
|
+
|
|
63
|
+
/**
|
|
64
|
+
* @type {updateChecker|undefined}
|
|
65
|
+
* @deprecated
|
|
66
|
+
*/
|
|
67
|
+
const updateChecker = sharedCodePushOptions.updateChecker;
|
|
68
|
+
if (updateChecker) {
|
|
69
|
+
const { update_info } = await updateChecker(updateRequest);
|
|
70
|
+
|
|
71
|
+
return mapToRemotePackageMetadata(update_info, config.deploymentKey);
|
|
72
|
+
} else {
|
|
73
|
+
/**
|
|
74
|
+
* `releaseHistory`
|
|
75
|
+
* @type {ReleaseHistoryInterface}
|
|
76
|
+
*/
|
|
77
|
+
const releaseHistory = await sharedCodePushOptions.releaseHistoryFetcher(updateRequest);
|
|
78
|
+
|
|
79
|
+
/**
|
|
80
|
+
* `runtimeVersion`
|
|
81
|
+
* The version of currently running CodePush update. (It can be undefined if the app is running without CodePush update.)
|
|
82
|
+
* @type {string|undefined}
|
|
83
|
+
*/
|
|
84
|
+
const runtimeVersion = updateRequest.label;
|
|
85
|
+
|
|
86
|
+
const versioning = new SemverVersioning(releaseHistory);
|
|
87
|
+
|
|
88
|
+
const shouldRollbackToBinary = versioning.shouldRollbackToBinary(runtimeVersion)
|
|
89
|
+
if (shouldRollbackToBinary) {
|
|
90
|
+
// Reset to latest major version and restart
|
|
91
|
+
CodePush.clearUpdates();
|
|
92
|
+
CodePush.allowRestart();
|
|
93
|
+
CodePush.restartApp();
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
const [latestVersion, latestReleaseInfo] = versioning.findLatestRelease();
|
|
97
|
+
const isMandatory = versioning.checkIsMandatory(runtimeVersion);
|
|
98
|
+
|
|
99
|
+
/**
|
|
100
|
+
* Convert the update information decided from `ReleaseHistoryInterface` to be passed to the library core (original CodePush library).
|
|
101
|
+
*
|
|
102
|
+
* @type {UpdateCheckResponse} the interface required by the original CodePush library.
|
|
103
|
+
*/
|
|
104
|
+
const updateInfo = {
|
|
105
|
+
download_url: latestReleaseInfo.downloadUrl,
|
|
106
|
+
// (`enabled` will always be true in the release information obtained from the previous process.)
|
|
107
|
+
is_available: latestReleaseInfo.enabled,
|
|
108
|
+
package_hash: latestReleaseInfo.packageHash,
|
|
109
|
+
is_mandatory: isMandatory,
|
|
110
|
+
// 이건 항상 현재 실행중인 바이너리 버전을 전달한다.
|
|
111
|
+
// 조회한 업데이트가 현재 바이너리를 타겟하는가? 를 API 서버에서 판단한 다음, 해당 된다면 런타임 바이너리 버전을 그대로 돌려주던 것임.
|
|
112
|
+
// 우리는 updateChecker 조회 결과가 넘어왔다면 해당 정보는 현재 런타임 바이너리에 호환됨을 전제로 하고있음.
|
|
113
|
+
target_binary_range: updateRequest.app_version,
|
|
114
|
+
/**
|
|
115
|
+
* Retrieve the update version from the ReleaseHistory and store it in the label.
|
|
116
|
+
* This information can be accessed at runtime through the CodePush bundle metadata.
|
|
117
|
+
*/
|
|
118
|
+
label: latestVersion,
|
|
119
|
+
// false 전달해야 정상 동작함
|
|
120
|
+
update_app_version: false,
|
|
121
|
+
// 그닥 쓸모 없음
|
|
122
|
+
description: '',
|
|
123
|
+
// 런타임에 안쓰임
|
|
124
|
+
is_disabled: false,
|
|
125
|
+
// 런타임에 안쓰임
|
|
126
|
+
package_size: 0,
|
|
127
|
+
// 런타임에 안쓰임
|
|
128
|
+
should_run_binary_version: false,
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
return mapToRemotePackageMetadata(updateInfo, config.deploymentKey);
|
|
132
|
+
}
|
|
133
|
+
} catch (error) {
|
|
134
|
+
log(`An error has occurred at update checker :`);
|
|
135
|
+
console.error(error)
|
|
136
|
+
// update will not happen
|
|
137
|
+
return undefined;
|
|
138
|
+
}
|
|
139
|
+
})();
|
|
140
|
+
|
|
141
|
+
/*
|
|
142
|
+
* There are four cases where checkForUpdate will resolve to null:
|
|
143
|
+
* ----------------------------------------------------------------
|
|
144
|
+
* 1) The server said there isn't an update. This is the most common case.
|
|
145
|
+
* 2) The server said there is an update but it requires a newer binary version.
|
|
146
|
+
* This would occur when end-users are running an older binary version than
|
|
147
|
+
* is available, and CodePush is making sure they don't get an update that
|
|
148
|
+
* potentially wouldn't be compatible with what they are running.
|
|
149
|
+
* 3) The server said there is an update, but the update's hash is the same as
|
|
150
|
+
* the currently running update. This should _never_ happen, unless there is a
|
|
151
|
+
* bug in the server, but we're adding this check just to double-check that the
|
|
152
|
+
* client app is resilient to a potential issue with the update check.
|
|
153
|
+
* 4) The server said there is an update, but the update's hash is the same as that
|
|
154
|
+
* of the binary's currently running version. This should only happen in Android -
|
|
155
|
+
* unlike iOS, we don't attach the binary's hash to the updateCheck request
|
|
156
|
+
* because we want to avoid having to install diff updates against the binary's
|
|
157
|
+
* version, which we can't do yet on Android.
|
|
158
|
+
*/
|
|
159
|
+
if (!update || update.updateAppVersion ||
|
|
160
|
+
localPackage && (update.packageHash === localPackage.packageHash) ||
|
|
161
|
+
(!localPackage || localPackage._isDebugOnly) && config.packageHash === update.packageHash) {
|
|
162
|
+
if (update && update.updateAppVersion) {
|
|
163
|
+
log("An update is available but it is not targeting the binary version of your app.");
|
|
164
|
+
if (handleBinaryVersionMismatchCallback && typeof handleBinaryVersionMismatchCallback === "function") {
|
|
165
|
+
handleBinaryVersionMismatchCallback(update)
|
|
166
|
+
}
|
|
167
|
+
}
|
|
168
|
+
|
|
169
|
+
return null;
|
|
170
|
+
} else {
|
|
171
|
+
const remotePackage = { ...update, ...PackageMixins.remote() };
|
|
172
|
+
remotePackage.failedInstall = await NativeCodePush.isFailedUpdate(remotePackage.packageHash);
|
|
173
|
+
remotePackage.deploymentKey = deploymentKey || nativeConfig.deploymentKey;
|
|
174
|
+
return remotePackage;
|
|
175
|
+
}
|
|
176
|
+
}
|
|
177
|
+
|
|
178
|
+
/**
|
|
179
|
+
* @param updateInfo {UpdateCheckResponse}
|
|
180
|
+
* @param deploymentKey {string}
|
|
181
|
+
* @return {RemotePackage | null}
|
|
182
|
+
*/
|
|
183
|
+
function mapToRemotePackageMetadata(updateInfo, deploymentKey) {
|
|
184
|
+
if (!updateInfo) {
|
|
185
|
+
return null;
|
|
186
|
+
} else if (!updateInfo.download_url) {
|
|
187
|
+
log("download_url is missed in the release history.");
|
|
188
|
+
return null;
|
|
189
|
+
} else if (!updateInfo.is_available) {
|
|
190
|
+
return null;
|
|
191
|
+
}
|
|
192
|
+
|
|
193
|
+
// refer to `RemotePackage` type inside code-push SDK
|
|
194
|
+
return {
|
|
195
|
+
deploymentKey: deploymentKey,
|
|
196
|
+
description: updateInfo.description ?? '',
|
|
197
|
+
label: updateInfo.label ?? '',
|
|
198
|
+
appVersion: updateInfo.target_binary_range ?? '',
|
|
199
|
+
isMandatory: updateInfo.is_mandatory ?? false,
|
|
200
|
+
packageHash: updateInfo.package_hash ?? '',
|
|
201
|
+
packageSize: updateInfo.package_size ?? 0,
|
|
202
|
+
downloadUrl: updateInfo.download_url ?? '',
|
|
203
|
+
};
|
|
204
|
+
}
|
|
205
|
+
|
|
206
|
+
const getConfiguration = (() => {
|
|
207
|
+
let config;
|
|
208
|
+
return async function getConfiguration() {
|
|
209
|
+
if (config) {
|
|
210
|
+
return config;
|
|
211
|
+
} else if (testConfig) {
|
|
212
|
+
return testConfig;
|
|
213
|
+
} else {
|
|
214
|
+
config = await NativeCodePush.getConfiguration();
|
|
215
|
+
return config;
|
|
216
|
+
}
|
|
217
|
+
}
|
|
218
|
+
})();
|
|
219
|
+
|
|
220
|
+
async function getCurrentPackage() {
|
|
221
|
+
return await getUpdateMetadata(CodePush.UpdateState.LATEST);
|
|
222
|
+
}
|
|
223
|
+
|
|
224
|
+
async function getUpdateMetadata(updateState) {
|
|
225
|
+
let updateMetadata = await NativeCodePush.getUpdateMetadata(updateState || CodePush.UpdateState.RUNNING);
|
|
226
|
+
if (updateMetadata) {
|
|
227
|
+
updateMetadata = {...PackageMixins.local, ...updateMetadata};
|
|
228
|
+
updateMetadata.failedInstall = await NativeCodePush.isFailedUpdate(updateMetadata.packageHash);
|
|
229
|
+
updateMetadata.isFirstRun = await NativeCodePush.isFirstRun(updateMetadata.packageHash);
|
|
230
|
+
}
|
|
231
|
+
return updateMetadata;
|
|
232
|
+
}
|
|
233
|
+
|
|
234
|
+
// This ensures that notifyApplicationReadyInternal is only called once
|
|
235
|
+
// in the lifetime of this module instance.
|
|
236
|
+
const notifyApplicationReady = (() => {
|
|
237
|
+
let notifyApplicationReadyPromise;
|
|
238
|
+
return () => {
|
|
239
|
+
if (!notifyApplicationReadyPromise) {
|
|
240
|
+
notifyApplicationReadyPromise = notifyApplicationReadyInternal();
|
|
241
|
+
}
|
|
242
|
+
|
|
243
|
+
return notifyApplicationReadyPromise;
|
|
244
|
+
};
|
|
245
|
+
})();
|
|
246
|
+
|
|
247
|
+
async function notifyApplicationReadyInternal() {
|
|
248
|
+
await NativeCodePush.notifyApplicationReady();
|
|
249
|
+
const statusReport = await NativeCodePush.getNewStatusReport();
|
|
250
|
+
statusReport && tryReportStatus(statusReport); // Don't wait for this to complete.
|
|
251
|
+
|
|
252
|
+
return statusReport;
|
|
253
|
+
}
|
|
254
|
+
|
|
255
|
+
async function tryReportStatus(statusReport, retryOnAppResume) {
|
|
256
|
+
const config = await getConfiguration();
|
|
257
|
+
|
|
258
|
+
try {
|
|
259
|
+
if (statusReport.appVersion) {
|
|
260
|
+
log(`Reporting binary update (${statusReport.appVersion})`);
|
|
261
|
+
|
|
262
|
+
if (!config.deploymentKey) {
|
|
263
|
+
throw new Error("Deployment key is missed");
|
|
264
|
+
}
|
|
265
|
+
} else {
|
|
266
|
+
const label = statusReport.package.label;
|
|
267
|
+
if (statusReport.status === "DeploymentSucceeded") {
|
|
268
|
+
log(`Reporting CodePush update success (${label})`);
|
|
269
|
+
} else {
|
|
270
|
+
log(`Reporting CodePush update rollback (${label})`);
|
|
271
|
+
await NativeCodePush.setLatestRollbackInfo(statusReport.package.packageHash);
|
|
272
|
+
}
|
|
273
|
+
}
|
|
274
|
+
|
|
275
|
+
NativeCodePush.recordStatusReported(statusReport);
|
|
276
|
+
retryOnAppResume && retryOnAppResume.remove();
|
|
277
|
+
} catch (e) {
|
|
278
|
+
log(`Report status failed: ${JSON.stringify(statusReport)}`);
|
|
279
|
+
NativeCodePush.saveStatusReportForRetry(statusReport);
|
|
280
|
+
// Try again when the app resumes
|
|
281
|
+
if (!retryOnAppResume) {
|
|
282
|
+
const resumeListener = AppState.addEventListener("change", async (newState) => {
|
|
283
|
+
if (newState !== "active") return;
|
|
284
|
+
const refreshedStatusReport = await NativeCodePush.getNewStatusReport();
|
|
285
|
+
if (refreshedStatusReport) {
|
|
286
|
+
tryReportStatus(refreshedStatusReport, resumeListener);
|
|
287
|
+
} else {
|
|
288
|
+
resumeListener && resumeListener.remove();
|
|
289
|
+
}
|
|
290
|
+
});
|
|
291
|
+
}
|
|
292
|
+
}
|
|
293
|
+
}
|
|
294
|
+
|
|
295
|
+
async function shouldUpdateBeIgnored(remotePackage, syncOptions) {
|
|
296
|
+
let { rollbackRetryOptions } = syncOptions;
|
|
297
|
+
|
|
298
|
+
const isFailedPackage = remotePackage && remotePackage.failedInstall;
|
|
299
|
+
if (!isFailedPackage || !syncOptions.ignoreFailedUpdates) {
|
|
300
|
+
return false;
|
|
301
|
+
}
|
|
302
|
+
|
|
303
|
+
if (!rollbackRetryOptions) {
|
|
304
|
+
return true;
|
|
305
|
+
}
|
|
306
|
+
|
|
307
|
+
if (typeof rollbackRetryOptions !== "object") {
|
|
308
|
+
rollbackRetryOptions = CodePush.DEFAULT_ROLLBACK_RETRY_OPTIONS;
|
|
309
|
+
} else {
|
|
310
|
+
rollbackRetryOptions = { ...CodePush.DEFAULT_ROLLBACK_RETRY_OPTIONS, ...rollbackRetryOptions };
|
|
311
|
+
}
|
|
312
|
+
|
|
313
|
+
if (!validateRollbackRetryOptions(rollbackRetryOptions)) {
|
|
314
|
+
return true;
|
|
315
|
+
}
|
|
316
|
+
|
|
317
|
+
const latestRollbackInfo = await NativeCodePush.getLatestRollbackInfo();
|
|
318
|
+
if (!validateLatestRollbackInfo(latestRollbackInfo, remotePackage.packageHash)) {
|
|
319
|
+
log("The latest rollback info is not valid.");
|
|
320
|
+
return true;
|
|
321
|
+
}
|
|
322
|
+
|
|
323
|
+
const { delayInHours, maxRetryAttempts } = rollbackRetryOptions;
|
|
324
|
+
const hoursSinceLatestRollback = (Date.now() - latestRollbackInfo.time) / (1000 * 60 * 60);
|
|
325
|
+
if (hoursSinceLatestRollback >= delayInHours && maxRetryAttempts >= latestRollbackInfo.count) {
|
|
326
|
+
log("Previous rollback should be ignored due to rollback retry options.");
|
|
327
|
+
return false;
|
|
328
|
+
}
|
|
329
|
+
|
|
330
|
+
return true;
|
|
331
|
+
}
|
|
332
|
+
|
|
333
|
+
function validateLatestRollbackInfo(latestRollbackInfo, packageHash) {
|
|
334
|
+
return latestRollbackInfo &&
|
|
335
|
+
latestRollbackInfo.time &&
|
|
336
|
+
latestRollbackInfo.count &&
|
|
337
|
+
latestRollbackInfo.packageHash &&
|
|
338
|
+
latestRollbackInfo.packageHash === packageHash;
|
|
339
|
+
}
|
|
340
|
+
|
|
341
|
+
function validateRollbackRetryOptions(rollbackRetryOptions) {
|
|
342
|
+
if (typeof rollbackRetryOptions.delayInHours !== "number") {
|
|
343
|
+
log("The 'delayInHours' rollback retry parameter must be a number.");
|
|
344
|
+
return false;
|
|
345
|
+
}
|
|
346
|
+
|
|
347
|
+
if (typeof rollbackRetryOptions.maxRetryAttempts !== "number") {
|
|
348
|
+
log("The 'maxRetryAttempts' rollback retry parameter must be a number.");
|
|
349
|
+
return false;
|
|
350
|
+
}
|
|
351
|
+
|
|
352
|
+
if (rollbackRetryOptions.maxRetryAttempts < 1) {
|
|
353
|
+
log("The 'maxRetryAttempts' rollback retry parameter cannot be less then 1.");
|
|
354
|
+
return false;
|
|
355
|
+
}
|
|
356
|
+
|
|
357
|
+
return true;
|
|
358
|
+
}
|
|
359
|
+
|
|
360
|
+
let testConfig;
|
|
361
|
+
|
|
362
|
+
// This function is only used for tests. Replaces the default SDK, configuration and native bridge
|
|
363
|
+
function setUpTestDependencies(testSdk, providedTestConfig, testNativeBridge) {
|
|
364
|
+
if (testSdk) module.exports.AcquisitionSdk = testSdk;
|
|
365
|
+
if (providedTestConfig) testConfig = providedTestConfig;
|
|
366
|
+
if (testNativeBridge) NativeCodePush = testNativeBridge;
|
|
367
|
+
}
|
|
368
|
+
|
|
369
|
+
async function restartApp(onlyIfUpdateIsPending = false) {
|
|
370
|
+
NativeCodePush.restartApp(onlyIfUpdateIsPending);
|
|
371
|
+
}
|
|
372
|
+
|
|
373
|
+
// This function allows only one syncInternal operation to proceed at any given time.
|
|
374
|
+
// Parallel calls to sync() while one is ongoing yields CodePush.SyncStatus.SYNC_IN_PROGRESS.
|
|
375
|
+
const sync = (() => {
|
|
376
|
+
let syncInProgress = false;
|
|
377
|
+
const setSyncCompleted = () => { syncInProgress = false; };
|
|
378
|
+
|
|
379
|
+
return (options = {}, syncStatusChangeCallback, downloadProgressCallback, handleBinaryVersionMismatchCallback) => {
|
|
380
|
+
let syncStatusCallbackWithTryCatch, downloadProgressCallbackWithTryCatch;
|
|
381
|
+
if (typeof syncStatusChangeCallback === "function") {
|
|
382
|
+
syncStatusCallbackWithTryCatch = (...args) => {
|
|
383
|
+
try {
|
|
384
|
+
syncStatusChangeCallback(...args);
|
|
385
|
+
} catch (error) {
|
|
386
|
+
log(`An error has occurred : ${error.stack}`);
|
|
387
|
+
}
|
|
388
|
+
}
|
|
389
|
+
}
|
|
390
|
+
|
|
391
|
+
if (typeof downloadProgressCallback === "function") {
|
|
392
|
+
downloadProgressCallbackWithTryCatch = (...args) => {
|
|
393
|
+
try {
|
|
394
|
+
downloadProgressCallback(...args);
|
|
395
|
+
} catch (error) {
|
|
396
|
+
log(`An error has occurred: ${error.stack}`);
|
|
397
|
+
}
|
|
398
|
+
}
|
|
399
|
+
}
|
|
400
|
+
|
|
401
|
+
if (syncInProgress) {
|
|
402
|
+
typeof syncStatusCallbackWithTryCatch === "function"
|
|
403
|
+
? syncStatusCallbackWithTryCatch(CodePush.SyncStatus.SYNC_IN_PROGRESS)
|
|
404
|
+
: log("Sync already in progress.");
|
|
405
|
+
return Promise.resolve(CodePush.SyncStatus.SYNC_IN_PROGRESS);
|
|
406
|
+
}
|
|
407
|
+
|
|
408
|
+
syncInProgress = true;
|
|
409
|
+
const syncPromise = syncInternal(options, syncStatusCallbackWithTryCatch, downloadProgressCallbackWithTryCatch, handleBinaryVersionMismatchCallback);
|
|
410
|
+
syncPromise
|
|
411
|
+
.then(setSyncCompleted)
|
|
412
|
+
.catch(setSyncCompleted);
|
|
413
|
+
|
|
414
|
+
return syncPromise;
|
|
415
|
+
};
|
|
416
|
+
})();
|
|
417
|
+
|
|
418
|
+
/*
|
|
419
|
+
* The syncInternal method provides a simple, one-line experience for
|
|
420
|
+
* incorporating the check, download and installation of an update.
|
|
421
|
+
*
|
|
422
|
+
* It simply composes the existing API methods together and adds additional
|
|
423
|
+
* support for respecting mandatory updates, ignoring previously failed
|
|
424
|
+
* releases, and displaying a standard confirmation UI to the end-user
|
|
425
|
+
* when an update is available.
|
|
426
|
+
*/
|
|
427
|
+
async function syncInternal(options = {}, syncStatusChangeCallback, downloadProgressCallback, handleBinaryVersionMismatchCallback) {
|
|
428
|
+
let resolvedInstallMode;
|
|
429
|
+
const syncOptions = {
|
|
430
|
+
deploymentKey: null,
|
|
431
|
+
ignoreFailedUpdates: true,
|
|
432
|
+
rollbackRetryOptions: null,
|
|
433
|
+
installMode: CodePush.InstallMode.ON_NEXT_RESTART,
|
|
434
|
+
mandatoryInstallMode: CodePush.InstallMode.IMMEDIATE,
|
|
435
|
+
minimumBackgroundDuration: 0,
|
|
436
|
+
updateDialog: null,
|
|
437
|
+
...options
|
|
438
|
+
};
|
|
439
|
+
|
|
440
|
+
syncStatusChangeCallback = typeof syncStatusChangeCallback === "function"
|
|
441
|
+
? syncStatusChangeCallback
|
|
442
|
+
: (syncStatus) => {
|
|
443
|
+
switch(syncStatus) {
|
|
444
|
+
case CodePush.SyncStatus.CHECKING_FOR_UPDATE:
|
|
445
|
+
log("Checking for update.");
|
|
446
|
+
break;
|
|
447
|
+
case CodePush.SyncStatus.AWAITING_USER_ACTION:
|
|
448
|
+
log("Awaiting user action.");
|
|
449
|
+
break;
|
|
450
|
+
case CodePush.SyncStatus.DOWNLOADING_PACKAGE:
|
|
451
|
+
log("Downloading package.");
|
|
452
|
+
break;
|
|
453
|
+
case CodePush.SyncStatus.INSTALLING_UPDATE:
|
|
454
|
+
log("Installing update.");
|
|
455
|
+
break;
|
|
456
|
+
case CodePush.SyncStatus.UP_TO_DATE:
|
|
457
|
+
log("App is up to date.");
|
|
458
|
+
break;
|
|
459
|
+
case CodePush.SyncStatus.UPDATE_IGNORED:
|
|
460
|
+
log("User cancelled the update.");
|
|
461
|
+
break;
|
|
462
|
+
case CodePush.SyncStatus.UPDATE_INSTALLED:
|
|
463
|
+
if (resolvedInstallMode == CodePush.InstallMode.ON_NEXT_RESTART) {
|
|
464
|
+
log("Update is installed and will be run on the next app restart.");
|
|
465
|
+
} else if (resolvedInstallMode == CodePush.InstallMode.ON_NEXT_RESUME) {
|
|
466
|
+
if (syncOptions.minimumBackgroundDuration > 0) {
|
|
467
|
+
log(`Update is installed and will be run after the app has been in the background for at least ${syncOptions.minimumBackgroundDuration} seconds.`);
|
|
468
|
+
} else {
|
|
469
|
+
log("Update is installed and will be run when the app next resumes.");
|
|
470
|
+
}
|
|
471
|
+
}
|
|
472
|
+
break;
|
|
473
|
+
case CodePush.SyncStatus.UNKNOWN_ERROR:
|
|
474
|
+
log("An unknown error occurred.");
|
|
475
|
+
break;
|
|
476
|
+
}
|
|
477
|
+
};
|
|
478
|
+
|
|
479
|
+
try {
|
|
480
|
+
await CodePush.notifyApplicationReady();
|
|
481
|
+
|
|
482
|
+
syncStatusChangeCallback(CodePush.SyncStatus.CHECKING_FOR_UPDATE);
|
|
483
|
+
const remotePackage = await checkForUpdate(syncOptions.deploymentKey, handleBinaryVersionMismatchCallback);
|
|
484
|
+
|
|
485
|
+
const doDownloadAndInstall = async () => {
|
|
486
|
+
syncStatusChangeCallback(CodePush.SyncStatus.DOWNLOADING_PACKAGE);
|
|
487
|
+
const localPackage = await remotePackage.download(downloadProgressCallback);
|
|
488
|
+
|
|
489
|
+
// Determine the correct install mode based on whether the update is mandatory or not.
|
|
490
|
+
resolvedInstallMode = localPackage.isMandatory ? syncOptions.mandatoryInstallMode : syncOptions.installMode;
|
|
491
|
+
|
|
492
|
+
syncStatusChangeCallback(CodePush.SyncStatus.INSTALLING_UPDATE);
|
|
493
|
+
await localPackage.install(resolvedInstallMode, syncOptions.minimumBackgroundDuration, () => {
|
|
494
|
+
syncStatusChangeCallback(CodePush.SyncStatus.UPDATE_INSTALLED);
|
|
495
|
+
});
|
|
496
|
+
|
|
497
|
+
return CodePush.SyncStatus.UPDATE_INSTALLED;
|
|
498
|
+
};
|
|
499
|
+
|
|
500
|
+
const updateShouldBeIgnored = await shouldUpdateBeIgnored(remotePackage, syncOptions);
|
|
501
|
+
|
|
502
|
+
if (!remotePackage || updateShouldBeIgnored) {
|
|
503
|
+
if (updateShouldBeIgnored) {
|
|
504
|
+
log("An update is available, but it is being ignored due to having been previously rolled back.");
|
|
505
|
+
}
|
|
506
|
+
|
|
507
|
+
const currentPackage = await CodePush.getCurrentPackage();
|
|
508
|
+
if (currentPackage && currentPackage.isPending) {
|
|
509
|
+
syncStatusChangeCallback(CodePush.SyncStatus.UPDATE_INSTALLED);
|
|
510
|
+
return CodePush.SyncStatus.UPDATE_INSTALLED;
|
|
511
|
+
} else {
|
|
512
|
+
syncStatusChangeCallback(CodePush.SyncStatus.UP_TO_DATE);
|
|
513
|
+
return CodePush.SyncStatus.UP_TO_DATE;
|
|
514
|
+
}
|
|
515
|
+
} else if (syncOptions.updateDialog) {
|
|
516
|
+
// updateDialog supports any truthy value (e.g. true, "goo", 12),
|
|
517
|
+
// but we should treat a non-object value as just the default dialog
|
|
518
|
+
if (typeof syncOptions.updateDialog !== "object") {
|
|
519
|
+
syncOptions.updateDialog = CodePush.DEFAULT_UPDATE_DIALOG;
|
|
520
|
+
} else {
|
|
521
|
+
syncOptions.updateDialog = { ...CodePush.DEFAULT_UPDATE_DIALOG, ...syncOptions.updateDialog };
|
|
522
|
+
}
|
|
523
|
+
|
|
524
|
+
return await new Promise((resolve, reject) => {
|
|
525
|
+
let message = null;
|
|
526
|
+
let installButtonText = null;
|
|
527
|
+
|
|
528
|
+
const dialogButtons = [];
|
|
529
|
+
|
|
530
|
+
if (remotePackage.isMandatory) {
|
|
531
|
+
message = syncOptions.updateDialog.mandatoryUpdateMessage;
|
|
532
|
+
installButtonText = syncOptions.updateDialog.mandatoryContinueButtonLabel;
|
|
533
|
+
} else {
|
|
534
|
+
message = syncOptions.updateDialog.optionalUpdateMessage;
|
|
535
|
+
installButtonText = syncOptions.updateDialog.optionalInstallButtonLabel;
|
|
536
|
+
// Since this is an optional update, add a button
|
|
537
|
+
// to allow the end-user to ignore it
|
|
538
|
+
dialogButtons.push({
|
|
539
|
+
text: syncOptions.updateDialog.optionalIgnoreButtonLabel,
|
|
540
|
+
onPress: () => {
|
|
541
|
+
syncStatusChangeCallback(CodePush.SyncStatus.UPDATE_IGNORED);
|
|
542
|
+
resolve(CodePush.SyncStatus.UPDATE_IGNORED);
|
|
543
|
+
}
|
|
544
|
+
});
|
|
545
|
+
}
|
|
546
|
+
|
|
547
|
+
// Since the install button should be placed to the
|
|
548
|
+
// right of any other button, add it last
|
|
549
|
+
dialogButtons.push({
|
|
550
|
+
text: installButtonText,
|
|
551
|
+
onPress:() => {
|
|
552
|
+
doDownloadAndInstall()
|
|
553
|
+
.then(resolve, reject);
|
|
554
|
+
}
|
|
555
|
+
})
|
|
556
|
+
|
|
557
|
+
// If the update has a description, and the developer
|
|
558
|
+
// explicitly chose to display it, then set that as the message
|
|
559
|
+
if (syncOptions.updateDialog.appendReleaseDescription && remotePackage.description) {
|
|
560
|
+
message += `${syncOptions.updateDialog.descriptionPrefix} ${remotePackage.description}`;
|
|
561
|
+
}
|
|
562
|
+
|
|
563
|
+
syncStatusChangeCallback(CodePush.SyncStatus.AWAITING_USER_ACTION);
|
|
564
|
+
Alert.alert(syncOptions.updateDialog.title, message, dialogButtons);
|
|
565
|
+
});
|
|
566
|
+
} else {
|
|
567
|
+
return await doDownloadAndInstall();
|
|
568
|
+
}
|
|
569
|
+
} catch (error) {
|
|
570
|
+
syncStatusChangeCallback(CodePush.SyncStatus.UNKNOWN_ERROR);
|
|
571
|
+
log(error.message);
|
|
572
|
+
throw error;
|
|
573
|
+
}
|
|
574
|
+
};
|
|
575
|
+
|
|
576
|
+
let CodePush;
|
|
577
|
+
|
|
578
|
+
/**
|
|
579
|
+
* @callback releaseHistoryFetcher
|
|
580
|
+
* @param {UpdateCheckRequest} updateRequest Current package information to check for updates.
|
|
581
|
+
* @returns {Promise<ReleaseHistoryInterface>} The release history of the updates deployed for a specific binary version.
|
|
582
|
+
*/
|
|
583
|
+
|
|
584
|
+
/**
|
|
585
|
+
* @callback updateChecker
|
|
586
|
+
* @param {UpdateCheckRequest} updateRequest Current package information to check for updates.
|
|
587
|
+
* @returns {Promise<{update_info: UpdateCheckResponse}>} The result of the update check. Follows the AppCenter API response interface.
|
|
588
|
+
*
|
|
589
|
+
* @deprecated It will be removed in the next major version.
|
|
590
|
+
*/
|
|
591
|
+
|
|
592
|
+
/**
|
|
593
|
+
* If you pass options once when calling `codePushify`, they will be shared with related functions.
|
|
594
|
+
* @type {{
|
|
595
|
+
* releaseHistoryFetcher: releaseHistoryFetcher | undefined,
|
|
596
|
+
* setReleaseHistoryFetcher(releaseHistoryFetcherFunction: releaseHistoryFetcher | undefined): void,
|
|
597
|
+
* updateChecker: updateChecker | undefined,
|
|
598
|
+
* setUpdateChecker(updateCheckerFunction: updateChecker | undefined): void,
|
|
599
|
+
* }}
|
|
600
|
+
*/
|
|
601
|
+
const sharedCodePushOptions = {
|
|
602
|
+
releaseHistoryFetcher: undefined,
|
|
603
|
+
setReleaseHistoryFetcher(releaseHistoryFetcherFunction) {
|
|
604
|
+
if (!releaseHistoryFetcherFunction || typeof releaseHistoryFetcherFunction !== 'function') throw new Error('Please implement the releaseHistoryFetcher function');
|
|
605
|
+
this.releaseHistoryFetcher = releaseHistoryFetcherFunction;
|
|
606
|
+
},
|
|
607
|
+
updateChecker: undefined,
|
|
608
|
+
setUpdateChecker(updateCheckerFunction) {
|
|
609
|
+
if (!updateCheckerFunction) return;
|
|
610
|
+
if (typeof updateCheckerFunction !== 'function') throw new Error('Please pass a function to updateChecker');
|
|
611
|
+
this.updateChecker = updateCheckerFunction;
|
|
612
|
+
},
|
|
613
|
+
}
|
|
614
|
+
|
|
615
|
+
function codePushify(options = {}) {
|
|
616
|
+
let React;
|
|
617
|
+
let ReactNative = require("react-native");
|
|
618
|
+
|
|
619
|
+
try { React = require("react"); } catch (e) { }
|
|
620
|
+
if (!React) {
|
|
621
|
+
try { React = ReactNative.React; } catch (e) { }
|
|
622
|
+
if (!React) {
|
|
623
|
+
throw new Error("Unable to find the 'React' module.");
|
|
624
|
+
}
|
|
625
|
+
}
|
|
626
|
+
|
|
627
|
+
if (!React.Component) {
|
|
628
|
+
throw new Error(
|
|
629
|
+
`Unable to find the "Component" class, please either:
|
|
630
|
+
1. Upgrade to a newer version of React Native that supports it, or
|
|
631
|
+
2. Call the codePush.sync API in your component instead of using the @codePush decorator`
|
|
632
|
+
);
|
|
633
|
+
}
|
|
634
|
+
|
|
635
|
+
if (options.updateChecker && !options.releaseHistoryFetcher) {
|
|
636
|
+
throw new Error('If you want to use `updateChecker`, pass a no-op function to releaseHistoryFetcher option. (e.g. `releaseHistoryFetcher: async () => ({})`)');
|
|
637
|
+
}
|
|
638
|
+
|
|
639
|
+
sharedCodePushOptions.setReleaseHistoryFetcher(options.releaseHistoryFetcher);
|
|
640
|
+
sharedCodePushOptions.setUpdateChecker(options.updateChecker);
|
|
641
|
+
|
|
642
|
+
const decorator = (RootComponent) => {
|
|
643
|
+
class CodePushComponent extends React.Component {
|
|
644
|
+
constructor(props) {
|
|
645
|
+
super(props);
|
|
646
|
+
this.rootComponentRef = React.createRef();
|
|
647
|
+
}
|
|
648
|
+
|
|
649
|
+
componentDidMount() {
|
|
650
|
+
if (options.checkFrequency === CodePush.CheckFrequency.MANUAL) {
|
|
651
|
+
CodePush.notifyAppReady();
|
|
652
|
+
} else {
|
|
653
|
+
const rootComponentInstance = this.rootComponentRef.current;
|
|
654
|
+
|
|
655
|
+
let syncStatusCallback;
|
|
656
|
+
if (rootComponentInstance && rootComponentInstance.codePushStatusDidChange) {
|
|
657
|
+
syncStatusCallback = rootComponentInstance.codePushStatusDidChange.bind(rootComponentInstance);
|
|
658
|
+
}
|
|
659
|
+
|
|
660
|
+
let downloadProgressCallback;
|
|
661
|
+
if (rootComponentInstance && rootComponentInstance.codePushDownloadDidProgress) {
|
|
662
|
+
downloadProgressCallback = rootComponentInstance.codePushDownloadDidProgress.bind(rootComponentInstance);
|
|
663
|
+
}
|
|
664
|
+
|
|
665
|
+
let handleBinaryVersionMismatchCallback;
|
|
666
|
+
if (rootComponentInstance && rootComponentInstance.codePushOnBinaryVersionMismatch) {
|
|
667
|
+
handleBinaryVersionMismatchCallback = rootComponentInstance.codePushOnBinaryVersionMismatch.bind(rootComponentInstance);
|
|
668
|
+
}
|
|
669
|
+
|
|
670
|
+
CodePush.sync(options, syncStatusCallback, downloadProgressCallback, handleBinaryVersionMismatchCallback);
|
|
671
|
+
|
|
672
|
+
if (options.checkFrequency === CodePush.CheckFrequency.ON_APP_RESUME) {
|
|
673
|
+
ReactNative.AppState.addEventListener("change", (newState) => {
|
|
674
|
+
if (newState === "active") {
|
|
675
|
+
CodePush.sync(options, syncStatusCallback, downloadProgressCallback);
|
|
676
|
+
}
|
|
677
|
+
});
|
|
678
|
+
}
|
|
679
|
+
}
|
|
680
|
+
}
|
|
681
|
+
|
|
682
|
+
render() {
|
|
683
|
+
const props = {...this.props};
|
|
684
|
+
|
|
685
|
+
// We can set ref property on class components only (not stateless)
|
|
686
|
+
// Check it by render method
|
|
687
|
+
if (RootComponent.prototype && RootComponent.prototype.render) {
|
|
688
|
+
props.ref = this.rootComponentRef;
|
|
689
|
+
}
|
|
690
|
+
|
|
691
|
+
return <RootComponent {...props} />
|
|
692
|
+
}
|
|
693
|
+
}
|
|
694
|
+
|
|
695
|
+
return hoistStatics(CodePushComponent, RootComponent);
|
|
696
|
+
}
|
|
697
|
+
|
|
698
|
+
if (typeof options === "function") {
|
|
699
|
+
// Infer that the root component was directly passed to us.
|
|
700
|
+
return decorator(options);
|
|
701
|
+
} else {
|
|
702
|
+
return decorator;
|
|
703
|
+
}
|
|
704
|
+
}
|
|
705
|
+
|
|
706
|
+
// If the "NativeCodePush" variable isn't defined, then
|
|
707
|
+
// the app didn't properly install the native module,
|
|
708
|
+
// and therefore, it doesn't make sense initializing
|
|
709
|
+
// the JS interface when it wouldn't work anyways.
|
|
710
|
+
if (NativeCodePush) {
|
|
711
|
+
CodePush = codePushify;
|
|
712
|
+
Object.assign(CodePush, {
|
|
713
|
+
checkForUpdate,
|
|
714
|
+
getConfiguration,
|
|
715
|
+
getCurrentPackage,
|
|
716
|
+
getUpdateMetadata,
|
|
717
|
+
log,
|
|
718
|
+
notifyAppReady: notifyApplicationReady,
|
|
719
|
+
notifyApplicationReady,
|
|
720
|
+
restartApp,
|
|
721
|
+
setUpTestDependencies,
|
|
722
|
+
sync,
|
|
723
|
+
disallowRestart: NativeCodePush.disallow,
|
|
724
|
+
allowRestart: NativeCodePush.allow,
|
|
725
|
+
clearUpdates: NativeCodePush.clearUpdates,
|
|
726
|
+
InstallMode: {
|
|
727
|
+
IMMEDIATE: NativeCodePush.codePushInstallModeImmediate, // Restart the app immediately
|
|
728
|
+
ON_NEXT_RESTART: NativeCodePush.codePushInstallModeOnNextRestart, // Don't artificially restart the app. Allow the update to be "picked up" on the next app restart
|
|
729
|
+
ON_NEXT_RESUME: NativeCodePush.codePushInstallModeOnNextResume, // Restart the app the next time it is resumed from the background
|
|
730
|
+
ON_NEXT_SUSPEND: NativeCodePush.codePushInstallModeOnNextSuspend // Restart the app _while_ it is in the background,
|
|
731
|
+
// but only after it has been in the background for "minimumBackgroundDuration" seconds (0 by default),
|
|
732
|
+
// so that user context isn't lost unless the app suspension is long enough to not matter
|
|
733
|
+
},
|
|
734
|
+
SyncStatus: {
|
|
735
|
+
UP_TO_DATE: 0, // The running app is up-to-date
|
|
736
|
+
UPDATE_INSTALLED: 1, // The app had an optional/mandatory update that was successfully downloaded and is about to be installed.
|
|
737
|
+
UPDATE_IGNORED: 2, // The app had an optional update and the end-user chose to ignore it
|
|
738
|
+
UNKNOWN_ERROR: 3,
|
|
739
|
+
SYNC_IN_PROGRESS: 4, // There is an ongoing "sync" operation in progress.
|
|
740
|
+
CHECKING_FOR_UPDATE: 5,
|
|
741
|
+
AWAITING_USER_ACTION: 6,
|
|
742
|
+
DOWNLOADING_PACKAGE: 7,
|
|
743
|
+
INSTALLING_UPDATE: 8
|
|
744
|
+
},
|
|
745
|
+
CheckFrequency: {
|
|
746
|
+
ON_APP_START: 0,
|
|
747
|
+
ON_APP_RESUME: 1,
|
|
748
|
+
MANUAL: 2
|
|
749
|
+
},
|
|
750
|
+
UpdateState: {
|
|
751
|
+
RUNNING: NativeCodePush.codePushUpdateStateRunning,
|
|
752
|
+
PENDING: NativeCodePush.codePushUpdateStatePending,
|
|
753
|
+
LATEST: NativeCodePush.codePushUpdateStateLatest
|
|
754
|
+
},
|
|
755
|
+
DeploymentStatus: {
|
|
756
|
+
FAILED: "DeploymentFailed",
|
|
757
|
+
SUCCEEDED: "DeploymentSucceeded",
|
|
758
|
+
},
|
|
759
|
+
DEFAULT_UPDATE_DIALOG: {
|
|
760
|
+
appendReleaseDescription: false,
|
|
761
|
+
descriptionPrefix: " Description: ",
|
|
762
|
+
mandatoryContinueButtonLabel: "Continue",
|
|
763
|
+
mandatoryUpdateMessage: "An update is available that must be installed.",
|
|
764
|
+
optionalIgnoreButtonLabel: "Ignore",
|
|
765
|
+
optionalInstallButtonLabel: "Install",
|
|
766
|
+
optionalUpdateMessage: "An update is available. Would you like to install it?",
|
|
767
|
+
title: "Update available"
|
|
768
|
+
},
|
|
769
|
+
DEFAULT_ROLLBACK_RETRY_OPTIONS: {
|
|
770
|
+
delayInHours: 24,
|
|
771
|
+
maxRetryAttempts: 1
|
|
772
|
+
},
|
|
773
|
+
});
|
|
774
|
+
} else {
|
|
775
|
+
log("The CodePush module doesn't appear to be properly installed. Please double-check that everything is setup correctly.");
|
|
776
|
+
}
|
|
777
|
+
|
|
778
|
+
module.exports = CodePush;
|