@appzung/react-native-code-push 5.7.1

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.
Files changed (191) hide show
  1. package/AlertAdapter.js +24 -0
  2. package/CONTRIBUTING.md +136 -0
  3. package/CodePush.js +666 -0
  4. package/CodePush.podspec +27 -0
  5. package/LICENSE.md +13 -0
  6. package/README.md +386 -0
  7. package/RestartManager.js +59 -0
  8. package/android/app/build.gradle +31 -0
  9. package/android/app/proguard-rules.pro +25 -0
  10. package/android/app/src/main/AndroidManifest.xml +10 -0
  11. package/android/app/src/main/java/com/microsoft/codepush/react/CodePush.java +395 -0
  12. package/android/app/src/main/java/com/microsoft/codepush/react/CodePushBuilder.java +37 -0
  13. package/android/app/src/main/java/com/microsoft/codepush/react/CodePushConstants.java +34 -0
  14. package/android/app/src/main/java/com/microsoft/codepush/react/CodePushDialog.java +102 -0
  15. package/android/app/src/main/java/com/microsoft/codepush/react/CodePushInstallMode.java +16 -0
  16. package/android/app/src/main/java/com/microsoft/codepush/react/CodePushInvalidPublicKeyException.java +12 -0
  17. package/android/app/src/main/java/com/microsoft/codepush/react/CodePushInvalidUpdateException.java +7 -0
  18. package/android/app/src/main/java/com/microsoft/codepush/react/CodePushMalformedDataException.java +12 -0
  19. package/android/app/src/main/java/com/microsoft/codepush/react/CodePushNativeModule.java +641 -0
  20. package/android/app/src/main/java/com/microsoft/codepush/react/CodePushNotInitializedException.java +12 -0
  21. package/android/app/src/main/java/com/microsoft/codepush/react/CodePushTelemetryManager.java +175 -0
  22. package/android/app/src/main/java/com/microsoft/codepush/react/CodePushUnknownException.java +12 -0
  23. package/android/app/src/main/java/com/microsoft/codepush/react/CodePushUpdateManager.java +369 -0
  24. package/android/app/src/main/java/com/microsoft/codepush/react/CodePushUpdateState.java +15 -0
  25. package/android/app/src/main/java/com/microsoft/codepush/react/CodePushUpdateUtils.java +267 -0
  26. package/android/app/src/main/java/com/microsoft/codepush/react/CodePushUtils.java +236 -0
  27. package/android/app/src/main/java/com/microsoft/codepush/react/DownloadProgress.java +30 -0
  28. package/android/app/src/main/java/com/microsoft/codepush/react/DownloadProgressCallback.java +5 -0
  29. package/android/app/src/main/java/com/microsoft/codepush/react/FileUtils.java +190 -0
  30. package/android/app/src/main/java/com/microsoft/codepush/react/ReactInstanceHolder.java +17 -0
  31. package/android/app/src/main/java/com/microsoft/codepush/react/SettingsManager.java +173 -0
  32. package/android/build.gradle +20 -0
  33. package/android/codepush.gradle +113 -0
  34. package/android/gradle/wrapper/gradle-wrapper.jar +0 -0
  35. package/android/gradle/wrapper/gradle-wrapper.properties +5 -0
  36. package/android/gradle.properties +20 -0
  37. package/android/gradlew +164 -0
  38. package/android/gradlew.bat +90 -0
  39. package/android/settings.gradle +1 -0
  40. package/docs/api-android.md +65 -0
  41. package/docs/api-ios.md +31 -0
  42. package/docs/api-js.md +592 -0
  43. package/docs/multi-deployment-testing-android.md +107 -0
  44. package/docs/multi-deployment-testing-ios.md +53 -0
  45. package/docs/setup-android.md +406 -0
  46. package/docs/setup-ios.md +229 -0
  47. package/docs/setup-windows.md +65 -0
  48. package/gulpfile.js +302 -0
  49. package/ios/CodePush/Base64/Base64/MF_Base64Additions.h +34 -0
  50. package/ios/CodePush/Base64/Base64/MF_Base64Additions.m +252 -0
  51. package/ios/CodePush/Base64/README.md +47 -0
  52. package/ios/CodePush/CodePush.h +235 -0
  53. package/ios/CodePush/CodePush.m +1041 -0
  54. package/ios/CodePush/CodePushConfig.m +116 -0
  55. package/ios/CodePush/CodePushDownloadHandler.m +130 -0
  56. package/ios/CodePush/CodePushErrorUtils.m +20 -0
  57. package/ios/CodePush/CodePushPackage.m +598 -0
  58. package/ios/CodePush/CodePushTelemetryManager.m +175 -0
  59. package/ios/CodePush/CodePushUpdateUtils.m +376 -0
  60. package/ios/CodePush/CodePushUtils.m +9 -0
  61. package/ios/CodePush/JWT/Core/Algorithms/Base/JWTAlgorithm.h +69 -0
  62. package/ios/CodePush/JWT/Core/Algorithms/Base/JWTAlgorithmFactory.h +16 -0
  63. package/ios/CodePush/JWT/Core/Algorithms/Base/JWTAlgorithmFactory.m +51 -0
  64. package/ios/CodePush/JWT/Core/Algorithms/Base/JWTAlgorithmNone.h +15 -0
  65. package/ios/CodePush/JWT/Core/Algorithms/Base/JWTAlgorithmNone.m +55 -0
  66. package/ios/CodePush/JWT/Core/Algorithms/ESFamily/JWTAlgorithmESBase.h +24 -0
  67. package/ios/CodePush/JWT/Core/Algorithms/ESFamily/JWTAlgorithmESBase.m +41 -0
  68. package/ios/CodePush/JWT/Core/Algorithms/HSFamily/JWTAlgorithmHSBase.h +28 -0
  69. package/ios/CodePush/JWT/Core/Algorithms/HSFamily/JWTAlgorithmHSBase.m +205 -0
  70. package/ios/CodePush/JWT/Core/Algorithms/Holders/JWTAlgorithmDataHolder.h +103 -0
  71. package/ios/CodePush/JWT/Core/Algorithms/Holders/JWTAlgorithmDataHolder.m +322 -0
  72. package/ios/CodePush/JWT/Core/Algorithms/Holders/JWTAlgorithmDataHolderChain.h +37 -0
  73. package/ios/CodePush/JWT/Core/Algorithms/Holders/JWTAlgorithmDataHolderChain.m +145 -0
  74. package/ios/CodePush/JWT/Core/Algorithms/RSFamily/JWTAlgorithmRSBase.h +35 -0
  75. package/ios/CodePush/JWT/Core/Algorithms/RSFamily/JWTAlgorithmRSBase.m +551 -0
  76. package/ios/CodePush/JWT/Core/Algorithms/RSFamily/JWTRSAlgorithm.h +23 -0
  77. package/ios/CodePush/JWT/Core/Algorithms/RSFamily/RSKeys/JWTCryptoKey.h +43 -0
  78. package/ios/CodePush/JWT/Core/Algorithms/RSFamily/RSKeys/JWTCryptoKey.m +230 -0
  79. package/ios/CodePush/JWT/Core/Algorithms/RSFamily/RSKeys/JWTCryptoKeyExtractor.h +31 -0
  80. package/ios/CodePush/JWT/Core/Algorithms/RSFamily/RSKeys/JWTCryptoKeyExtractor.m +113 -0
  81. package/ios/CodePush/JWT/Core/Algorithms/RSFamily/RSKeys/JWTCryptoSecurity.h +38 -0
  82. package/ios/CodePush/JWT/Core/Algorithms/RSFamily/RSKeys/JWTCryptoSecurity.m +500 -0
  83. package/ios/CodePush/JWT/Core/ClaimSet/JWTClaim.h +18 -0
  84. package/ios/CodePush/JWT/Core/ClaimSet/JWTClaim.m +214 -0
  85. package/ios/CodePush/JWT/Core/ClaimSet/JWTClaimsSet.h +23 -0
  86. package/ios/CodePush/JWT/Core/ClaimSet/JWTClaimsSet.m +29 -0
  87. package/ios/CodePush/JWT/Core/ClaimSet/JWTClaimsSetSerializer.h +19 -0
  88. package/ios/CodePush/JWT/Core/ClaimSet/JWTClaimsSetSerializer.m +68 -0
  89. package/ios/CodePush/JWT/Core/ClaimSet/JWTClaimsSetVerifier.h +18 -0
  90. package/ios/CodePush/JWT/Core/ClaimSet/JWTClaimsSetVerifier.m +72 -0
  91. package/ios/CodePush/JWT/Core/Coding/JWTCoding+ResultTypes.h +67 -0
  92. package/ios/CodePush/JWT/Core/Coding/JWTCoding+ResultTypes.m +111 -0
  93. package/ios/CodePush/JWT/Core/Coding/JWTCoding+VersionOne.h +119 -0
  94. package/ios/CodePush/JWT/Core/Coding/JWTCoding+VersionOne.m +307 -0
  95. package/ios/CodePush/JWT/Core/Coding/JWTCoding+VersionThree.h +94 -0
  96. package/ios/CodePush/JWT/Core/Coding/JWTCoding+VersionThree.m +619 -0
  97. package/ios/CodePush/JWT/Core/Coding/JWTCoding+VersionTwo.h +164 -0
  98. package/ios/CodePush/JWT/Core/Coding/JWTCoding+VersionTwo.m +514 -0
  99. package/ios/CodePush/JWT/Core/Coding/JWTCoding.h +24 -0
  100. package/ios/CodePush/JWT/Core/Coding/JWTCoding.m +11 -0
  101. package/ios/CodePush/JWT/Core/FrameworkSupplement/JWT.h +52 -0
  102. package/ios/CodePush/JWT/Core/FrameworkSupplement/Map.modulemap +5 -0
  103. package/ios/CodePush/JWT/Core/Supplement/JWTBase64Coder.h +28 -0
  104. package/ios/CodePush/JWT/Core/Supplement/JWTBase64Coder.m +70 -0
  105. package/ios/CodePush/JWT/Core/Supplement/JWTDeprecations.h +22 -0
  106. package/ios/CodePush/JWT/Core/Supplement/JWTErrorDescription.h +34 -0
  107. package/ios/CodePush/JWT/Core/Supplement/JWTErrorDescription.m +73 -0
  108. package/ios/CodePush/JWT/LICENSE +19 -0
  109. package/ios/CodePush/JWT/README.md +489 -0
  110. package/ios/CodePush/RCTConvert+CodePushInstallMode.m +20 -0
  111. package/ios/CodePush/RCTConvert+CodePushUpdateState.m +20 -0
  112. package/ios/CodePush/SSZipArchive/Common.h +81 -0
  113. package/ios/CodePush/SSZipArchive/README.md +1 -0
  114. package/ios/CodePush/SSZipArchive/SSZipArchive.h +76 -0
  115. package/ios/CodePush/SSZipArchive/SSZipArchive.m +691 -0
  116. package/ios/CodePush/SSZipArchive/aes/aes.h +198 -0
  117. package/ios/CodePush/SSZipArchive/aes/aes_via_ace.h +541 -0
  118. package/ios/CodePush/SSZipArchive/aes/aescrypt.c +294 -0
  119. package/ios/CodePush/SSZipArchive/aes/aeskey.c +548 -0
  120. package/ios/CodePush/SSZipArchive/aes/aesopt.h +739 -0
  121. package/ios/CodePush/SSZipArchive/aes/aestab.c +391 -0
  122. package/ios/CodePush/SSZipArchive/aes/aestab.h +173 -0
  123. package/ios/CodePush/SSZipArchive/aes/brg_endian.h +126 -0
  124. package/ios/CodePush/SSZipArchive/aes/brg_types.h +219 -0
  125. package/ios/CodePush/SSZipArchive/aes/entropy.c +54 -0
  126. package/ios/CodePush/SSZipArchive/aes/entropy.h +16 -0
  127. package/ios/CodePush/SSZipArchive/aes/fileenc.c +144 -0
  128. package/ios/CodePush/SSZipArchive/aes/fileenc.h +121 -0
  129. package/ios/CodePush/SSZipArchive/aes/hmac.c +145 -0
  130. package/ios/CodePush/SSZipArchive/aes/hmac.h +103 -0
  131. package/ios/CodePush/SSZipArchive/aes/prng.c +155 -0
  132. package/ios/CodePush/SSZipArchive/aes/prng.h +82 -0
  133. package/ios/CodePush/SSZipArchive/aes/pwd2key.c +103 -0
  134. package/ios/CodePush/SSZipArchive/aes/pwd2key.h +57 -0
  135. package/ios/CodePush/SSZipArchive/aes/sha1.c +258 -0
  136. package/ios/CodePush/SSZipArchive/aes/sha1.h +73 -0
  137. package/ios/CodePush/SSZipArchive/minizip/crypt.h +130 -0
  138. package/ios/CodePush/SSZipArchive/minizip/ioapi.c +369 -0
  139. package/ios/CodePush/SSZipArchive/minizip/ioapi.h +175 -0
  140. package/ios/CodePush/SSZipArchive/minizip/mztools.c +284 -0
  141. package/ios/CodePush/SSZipArchive/minizip/mztools.h +31 -0
  142. package/ios/CodePush/SSZipArchive/minizip/unzip.c +1839 -0
  143. package/ios/CodePush/SSZipArchive/minizip/unzip.h +248 -0
  144. package/ios/CodePush/SSZipArchive/minizip/zip.c +1910 -0
  145. package/ios/CodePush/SSZipArchive/minizip/zip.h +202 -0
  146. package/ios/CodePush.xcodeproj/project.pbxproj +937 -0
  147. package/ios/CodePush.xcodeproj/project.xcworkspace/contents.xcworkspacedata +7 -0
  148. package/ios/CodePush.xcodeproj/project.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist +8 -0
  149. package/logging.js +6 -0
  150. package/package-mixins.js +69 -0
  151. package/package.json +47 -0
  152. package/request-fetch-adapter.js +52 -0
  153. package/scripts/generateBundledResourcesHash.js +125 -0
  154. package/scripts/getFilesInFolder.js +19 -0
  155. package/scripts/postlink/android/postlink.js +87 -0
  156. package/scripts/postlink/ios/postlink.js +116 -0
  157. package/scripts/postlink/run.js +11 -0
  158. package/scripts/postunlink/android/postunlink.js +74 -0
  159. package/scripts/postunlink/ios/postunlink.js +87 -0
  160. package/scripts/postunlink/run.js +11 -0
  161. package/scripts/recordFilesBeforeBundleCommand.js +41 -0
  162. package/scripts/tools/linkToolsAndroid.js +57 -0
  163. package/scripts/tools/linkToolsIos.js +130 -0
  164. package/typings/react-native-code-push.d.ts +446 -0
  165. package/windows/CodePush/CodePush.csproj +128 -0
  166. package/windows/CodePush/CodePushUtils.cs +47 -0
  167. package/windows/CodePush/FileUtils.cs +40 -0
  168. package/windows/CodePush/Properties/AssemblyInfo.cs +29 -0
  169. package/windows/CodePush/Properties/CodePush.rd.xml +33 -0
  170. package/windows/CodePush/UpdateManager.cs +305 -0
  171. package/windows/CodePush/UpdateUtils.cs +46 -0
  172. package/windows/CodePush.Net46/Adapters/Http/HttpProgress.cs +28 -0
  173. package/windows/CodePush.Net46/Adapters/Storage/ApplicationDataContainer.cs +106 -0
  174. package/windows/CodePush.Net46/CodePush.Net46.csproj +103 -0
  175. package/windows/CodePush.Net46/CodePushUtils.cs +158 -0
  176. package/windows/CodePush.Net46/FileUtils.cs +55 -0
  177. package/windows/CodePush.Net46/Properties/AssemblyInfo.cs +36 -0
  178. package/windows/CodePush.Net46/UpdateManager.cs +330 -0
  179. package/windows/CodePush.Net46/UpdateUtils.cs +70 -0
  180. package/windows/CodePush.Net46/packages.config +5 -0
  181. package/windows/CodePush.Shared/CodePush.Shared.projitems +22 -0
  182. package/windows/CodePush.Shared/CodePush.Shared.shproj +13 -0
  183. package/windows/CodePush.Shared/CodePushConstants.cs +35 -0
  184. package/windows/CodePush.Shared/CodePushNativeModule.cs +329 -0
  185. package/windows/CodePush.Shared/CodePushReactPackage.cs +235 -0
  186. package/windows/CodePush.Shared/CodePushUtils.cs +70 -0
  187. package/windows/CodePush.Shared/InstallMode.cs +9 -0
  188. package/windows/CodePush.Shared/MinimumBackgroundListener.cs +44 -0
  189. package/windows/CodePush.Shared/SettingsManager.cs +148 -0
  190. package/windows/CodePush.Shared/TelemetryManager.cs +250 -0
  191. package/windows/CodePush.Shared/UpdateState.cs +9 -0
package/CodePush.js ADDED
@@ -0,0 +1,666 @@
1
+ import { AcquisitionManager as Sdk } from "code-push/script/acquisition-sdk";
2
+ import { Alert } from "./AlertAdapter";
3
+ import requestFetchAdapter from "./request-fetch-adapter";
4
+ import { AppState, Platform } from "react-native";
5
+ import RestartManager from "./RestartManager";
6
+ import log from "./logging";
7
+ import hoistStatics from 'hoist-non-react-statics';
8
+
9
+ let NativeCodePush = require("react-native").NativeModules.CodePush;
10
+ const PackageMixins = require("./package-mixins")(NativeCodePush);
11
+
12
+ async function checkForUpdate(deploymentKey = null, handleBinaryVersionMismatchCallback = null) {
13
+ /*
14
+ * Before we ask the server if an update exists, we
15
+ * need to retrieve three pieces of information from the
16
+ * native side: deployment key, app version (e.g. 1.0.1)
17
+ * and the hash of the currently running update (if there is one).
18
+ * This allows the client to only receive updates which are targetted
19
+ * for their specific deployment and version and which are actually
20
+ * different from the CodePush update they have already installed.
21
+ */
22
+ const nativeConfig = await getConfiguration();
23
+ /*
24
+ * If a deployment key was explicitly provided,
25
+ * then let's override the one we retrieved
26
+ * from the native-side of the app. This allows
27
+ * dynamically "redirecting" end-users at different
28
+ * deployments (e.g. an early access deployment for insiders).
29
+ */
30
+ const config = deploymentKey ? { ...nativeConfig, ...{ deploymentKey } } : nativeConfig;
31
+ const sdk = getPromisifiedSdk(requestFetchAdapter, config);
32
+
33
+ // Use dynamically overridden getCurrentPackage() during tests.
34
+ const localPackage = await module.exports.getCurrentPackage();
35
+
36
+ /*
37
+ * If the app has a previously installed update, and that update
38
+ * was targetted at the same app version that is currently running,
39
+ * then we want to use its package hash to determine whether a new
40
+ * release has been made on the server. Otherwise, we only need
41
+ * to send the app version to the server, since we are interested
42
+ * in any updates for current binary version, regardless of hash.
43
+ */
44
+ let queryPackage;
45
+ if (localPackage) {
46
+ queryPackage = localPackage;
47
+ } else {
48
+ queryPackage = { appVersion: config.appVersion };
49
+ if (Platform.OS === "ios" && config.packageHash) {
50
+ queryPackage.packageHash = config.packageHash;
51
+ }
52
+ }
53
+
54
+ const update = await sdk.queryUpdateWithCurrentPackage(queryPackage);
55
+
56
+ /*
57
+ * There are four cases where checkForUpdate will resolve to null:
58
+ * ----------------------------------------------------------------
59
+ * 1) The server said there isn't an update. This is the most common case.
60
+ * 2) The server said there is an update but it requires a newer binary version.
61
+ * This would occur when end-users are running an older binary version than
62
+ * is available, and CodePush is making sure they don't get an update that
63
+ * potentially wouldn't be compatible with what they are running.
64
+ * 3) The server said there is an update, but the update's hash is the same as
65
+ * the currently running update. This should _never_ happen, unless there is a
66
+ * bug in the server, but we're adding this check just to double-check that the
67
+ * client app is resilient to a potential issue with the update check.
68
+ * 4) The server said there is an update, but the update's hash is the same as that
69
+ * of the binary's currently running version. This should only happen in Android -
70
+ * unlike iOS, we don't attach the binary's hash to the updateCheck request
71
+ * because we want to avoid having to install diff updates against the binary's
72
+ * version, which we can't do yet on Android.
73
+ */
74
+ if (!update || update.updateAppVersion ||
75
+ localPackage && (update.packageHash === localPackage.packageHash) ||
76
+ (!localPackage || localPackage._isDebugOnly) && config.packageHash === update.packageHash) {
77
+ if (update && update.updateAppVersion) {
78
+ log("An update is available but it is not targeting the binary version of your app.");
79
+ if (handleBinaryVersionMismatchCallback && typeof handleBinaryVersionMismatchCallback === "function") {
80
+ handleBinaryVersionMismatchCallback(update)
81
+ }
82
+ }
83
+
84
+ return null;
85
+ } else {
86
+ const remotePackage = { ...update, ...PackageMixins.remote(sdk.reportStatusDownload) };
87
+ remotePackage.failedInstall = await NativeCodePush.isFailedUpdate(remotePackage.packageHash);
88
+ remotePackage.deploymentKey = deploymentKey || nativeConfig.deploymentKey;
89
+ return remotePackage;
90
+ }
91
+ }
92
+
93
+ const getConfiguration = (() => {
94
+ let config;
95
+ return async function getConfiguration() {
96
+ if (config) {
97
+ return config;
98
+ } else if (testConfig) {
99
+ return testConfig;
100
+ } else {
101
+ config = await NativeCodePush.getConfiguration();
102
+ return config;
103
+ }
104
+ }
105
+ })();
106
+
107
+ async function getCurrentPackage() {
108
+ return await getUpdateMetadata(CodePush.UpdateState.LATEST);
109
+ }
110
+
111
+ async function getUpdateMetadata(updateState) {
112
+ let updateMetadata = await NativeCodePush.getUpdateMetadata(updateState || CodePush.UpdateState.RUNNING);
113
+ if (updateMetadata) {
114
+ updateMetadata = {...PackageMixins.local, ...updateMetadata};
115
+ updateMetadata.failedInstall = await NativeCodePush.isFailedUpdate(updateMetadata.packageHash);
116
+ updateMetadata.isFirstRun = await NativeCodePush.isFirstRun(updateMetadata.packageHash);
117
+ }
118
+ return updateMetadata;
119
+ }
120
+
121
+ function getPromisifiedSdk(requestFetchAdapter, config) {
122
+ // Use dynamically overridden AcquisitionSdk during tests.
123
+ const sdk = new module.exports.AcquisitionSdk(requestFetchAdapter, config);
124
+ sdk.queryUpdateWithCurrentPackage = (queryPackage) => {
125
+ return new Promise((resolve, reject) => {
126
+ module.exports.AcquisitionSdk.prototype.queryUpdateWithCurrentPackage.call(sdk, queryPackage, (err, update) => {
127
+ if (err) {
128
+ reject(err);
129
+ } else {
130
+ resolve(update);
131
+ }
132
+ });
133
+ });
134
+ };
135
+
136
+ sdk.reportStatusDeploy = (deployedPackage, status, previousLabelOrAppVersion, previousDeploymentKey) => {
137
+ return new Promise((resolve, reject) => {
138
+ module.exports.AcquisitionSdk.prototype.reportStatusDeploy.call(sdk, deployedPackage, status, previousLabelOrAppVersion, previousDeploymentKey, (err) => {
139
+ if (err) {
140
+ reject(err);
141
+ } else {
142
+ resolve();
143
+ }
144
+ });
145
+ });
146
+ };
147
+
148
+ sdk.reportStatusDownload = (downloadedPackage) => {
149
+ return new Promise((resolve, reject) => {
150
+ module.exports.AcquisitionSdk.prototype.reportStatusDownload.call(sdk, downloadedPackage, (err) => {
151
+ if (err) {
152
+ reject(err);
153
+ } else {
154
+ resolve();
155
+ }
156
+ });
157
+ });
158
+ };
159
+
160
+ return sdk;
161
+ }
162
+
163
+ // This ensures that notifyApplicationReadyInternal is only called once
164
+ // in the lifetime of this module instance.
165
+ const notifyApplicationReady = (() => {
166
+ let notifyApplicationReadyPromise;
167
+ return () => {
168
+ if (!notifyApplicationReadyPromise) {
169
+ notifyApplicationReadyPromise = notifyApplicationReadyInternal();
170
+ }
171
+
172
+ return notifyApplicationReadyPromise;
173
+ };
174
+ })();
175
+
176
+ async function notifyApplicationReadyInternal() {
177
+ await NativeCodePush.notifyApplicationReady();
178
+ const statusReport = await NativeCodePush.getNewStatusReport();
179
+ statusReport && tryReportStatus(statusReport); // Don't wait for this to complete.
180
+
181
+ return statusReport;
182
+ }
183
+
184
+ async function tryReportStatus(statusReport, resumeListener) {
185
+ const config = await getConfiguration();
186
+ const previousLabelOrAppVersion = statusReport.previousLabelOrAppVersion;
187
+ const previousDeploymentKey = statusReport.previousDeploymentKey || config.deploymentKey;
188
+ try {
189
+ if (statusReport.appVersion) {
190
+ log(`Reporting binary update (${statusReport.appVersion})`);
191
+
192
+ const sdk = getPromisifiedSdk(requestFetchAdapter, config);
193
+ await sdk.reportStatusDeploy(/* deployedPackage */ null, /* status */ null, previousLabelOrAppVersion, previousDeploymentKey);
194
+ } else {
195
+ const label = statusReport.package.label;
196
+ if (statusReport.status === "DeploymentSucceeded") {
197
+ log(`Reporting CodePush update success (${label})`);
198
+ } else {
199
+ log(`Reporting CodePush update rollback (${label})`);
200
+ await NativeCodePush.setLatestRollbackInfo(statusReport.package.packageHash);
201
+ }
202
+
203
+ config.deploymentKey = statusReport.package.deploymentKey;
204
+ const sdk = getPromisifiedSdk(requestFetchAdapter, config);
205
+ await sdk.reportStatusDeploy(statusReport.package, statusReport.status, previousLabelOrAppVersion, previousDeploymentKey);
206
+ }
207
+
208
+ NativeCodePush.recordStatusReported(statusReport);
209
+ resumeListener && AppState.removeEventListener("change", resumeListener);
210
+ } catch (e) {
211
+ log(`Report status failed: ${JSON.stringify(statusReport)}`);
212
+ NativeCodePush.saveStatusReportForRetry(statusReport);
213
+ // Try again when the app resumes
214
+ if (!resumeListener) {
215
+ resumeListener = async (newState) => {
216
+ if (newState !== "active") return;
217
+ const refreshedStatusReport = await NativeCodePush.getNewStatusReport();
218
+ if (refreshedStatusReport) {
219
+ tryReportStatus(refreshedStatusReport, resumeListener);
220
+ } else {
221
+ AppState.removeEventListener("change", resumeListener);
222
+ }
223
+ };
224
+ AppState.addEventListener("change", resumeListener);
225
+ }
226
+ }
227
+ }
228
+
229
+ async function shouldUpdateBeIgnored(remotePackage, syncOptions) {
230
+ let { rollbackRetryOptions } = syncOptions;
231
+
232
+ const isFailedPackage = remotePackage && remotePackage.failedInstall;
233
+ if (!isFailedPackage || !syncOptions.ignoreFailedUpdates) {
234
+ return false;
235
+ }
236
+
237
+ if (!rollbackRetryOptions) {
238
+ return true;
239
+ }
240
+
241
+ if (typeof rollbackRetryOptions !== "object") {
242
+ rollbackRetryOptions = CodePush.DEFAULT_ROLLBACK_RETRY_OPTIONS;
243
+ } else {
244
+ rollbackRetryOptions = { ...CodePush.DEFAULT_ROLLBACK_RETRY_OPTIONS, ...rollbackRetryOptions };
245
+ }
246
+
247
+ if (!validateRollbackRetryOptions(rollbackRetryOptions)) {
248
+ return true;
249
+ }
250
+
251
+ const latestRollbackInfo = await NativeCodePush.getLatestRollbackInfo();
252
+ if (!validateLatestRollbackInfo(latestRollbackInfo, remotePackage.packageHash)) {
253
+ log("The latest rollback info is not valid.");
254
+ return true;
255
+ }
256
+
257
+ const { delayInHours, maxRetryAttempts } = rollbackRetryOptions;
258
+ const hoursSinceLatestRollback = (Date.now() - latestRollbackInfo.time) / (1000 * 60 * 60);
259
+ if (hoursSinceLatestRollback >= delayInHours && maxRetryAttempts >= latestRollbackInfo.count) {
260
+ log("Previous rollback should be ignored due to rollback retry options.");
261
+ return false;
262
+ }
263
+
264
+ return true;
265
+ }
266
+
267
+ function validateLatestRollbackInfo(latestRollbackInfo, packageHash) {
268
+ return latestRollbackInfo &&
269
+ latestRollbackInfo.time &&
270
+ latestRollbackInfo.count &&
271
+ latestRollbackInfo.packageHash &&
272
+ latestRollbackInfo.packageHash === packageHash;
273
+ }
274
+
275
+ function validateRollbackRetryOptions(rollbackRetryOptions) {
276
+ if (typeof rollbackRetryOptions.delayInHours !== "number") {
277
+ log("The 'delayInHours' rollback retry parameter must be a number.");
278
+ return false;
279
+ }
280
+
281
+ if (typeof rollbackRetryOptions.maxRetryAttempts !== "number") {
282
+ log("The 'maxRetryAttempts' rollback retry parameter must be a number.");
283
+ return false;
284
+ }
285
+
286
+ if (rollbackRetryOptions.maxRetryAttempts < 1) {
287
+ log("The 'maxRetryAttempts' rollback retry parameter cannot be less then 1.");
288
+ return false;
289
+ }
290
+
291
+ return true;
292
+ }
293
+
294
+ var testConfig;
295
+
296
+ // This function is only used for tests. Replaces the default SDK, configuration and native bridge
297
+ function setUpTestDependencies(testSdk, providedTestConfig, testNativeBridge) {
298
+ if (testSdk) module.exports.AcquisitionSdk = testSdk;
299
+ if (providedTestConfig) testConfig = providedTestConfig;
300
+ if (testNativeBridge) NativeCodePush = testNativeBridge;
301
+ }
302
+
303
+ // This function allows only one syncInternal operation to proceed at any given time.
304
+ // Parallel calls to sync() while one is ongoing yields CodePush.SyncStatus.SYNC_IN_PROGRESS.
305
+ const sync = (() => {
306
+ let syncInProgress = false;
307
+ const setSyncCompleted = () => { syncInProgress = false; };
308
+
309
+ return (options = {}, syncStatusChangeCallback, downloadProgressCallback, handleBinaryVersionMismatchCallback) => {
310
+ let syncStatusCallbackWithTryCatch, downloadProgressCallbackWithTryCatch;
311
+ if (typeof syncStatusChangeCallback === "function") {
312
+ syncStatusCallbackWithTryCatch = (...args) => {
313
+ try {
314
+ syncStatusChangeCallback(...args);
315
+ } catch (error) {
316
+ log(`An error has occurred : ${error.stack}`);
317
+ }
318
+ }
319
+ }
320
+
321
+ if (typeof downloadProgressCallback === "function") {
322
+ downloadProgressCallbackWithTryCatch = (...args) => {
323
+ try {
324
+ downloadProgressCallback(...args);
325
+ } catch (error) {
326
+ log(`An error has occurred: ${error.stack}`);
327
+ }
328
+ }
329
+ }
330
+
331
+ if (syncInProgress) {
332
+ typeof syncStatusCallbackWithTryCatch === "function"
333
+ ? syncStatusCallbackWithTryCatch(CodePush.SyncStatus.SYNC_IN_PROGRESS)
334
+ : log("Sync already in progress.");
335
+ return Promise.resolve(CodePush.SyncStatus.SYNC_IN_PROGRESS);
336
+ }
337
+
338
+ syncInProgress = true;
339
+ const syncPromise = syncInternal(options, syncStatusCallbackWithTryCatch, downloadProgressCallbackWithTryCatch, handleBinaryVersionMismatchCallback);
340
+ syncPromise
341
+ .then(setSyncCompleted)
342
+ .catch(setSyncCompleted);
343
+
344
+ return syncPromise;
345
+ };
346
+ })();
347
+
348
+ /*
349
+ * The syncInternal method provides a simple, one-line experience for
350
+ * incorporating the check, download and installation of an update.
351
+ *
352
+ * It simply composes the existing API methods together and adds additional
353
+ * support for respecting mandatory updates, ignoring previously failed
354
+ * releases, and displaying a standard confirmation UI to the end-user
355
+ * when an update is available.
356
+ */
357
+ async function syncInternal(options = {}, syncStatusChangeCallback, downloadProgressCallback, handleBinaryVersionMismatchCallback) {
358
+ let resolvedInstallMode;
359
+ const syncOptions = {
360
+ deploymentKey: null,
361
+ ignoreFailedUpdates: true,
362
+ rollbackRetryOptions: null,
363
+ installMode: CodePush.InstallMode.ON_NEXT_RESTART,
364
+ mandatoryInstallMode: CodePush.InstallMode.IMMEDIATE,
365
+ minimumBackgroundDuration: 0,
366
+ updateDialog: null,
367
+ ...options
368
+ };
369
+
370
+ syncStatusChangeCallback = typeof syncStatusChangeCallback === "function"
371
+ ? syncStatusChangeCallback
372
+ : (syncStatus) => {
373
+ switch(syncStatus) {
374
+ case CodePush.SyncStatus.CHECKING_FOR_UPDATE:
375
+ log("Checking for update.");
376
+ break;
377
+ case CodePush.SyncStatus.AWAITING_USER_ACTION:
378
+ log("Awaiting user action.");
379
+ break;
380
+ case CodePush.SyncStatus.DOWNLOADING_PACKAGE:
381
+ log("Downloading package.");
382
+ break;
383
+ case CodePush.SyncStatus.INSTALLING_UPDATE:
384
+ log("Installing update.");
385
+ break;
386
+ case CodePush.SyncStatus.UP_TO_DATE:
387
+ log("App is up to date.");
388
+ break;
389
+ case CodePush.SyncStatus.UPDATE_IGNORED:
390
+ log("User cancelled the update.");
391
+ break;
392
+ case CodePush.SyncStatus.UPDATE_INSTALLED:
393
+ if (resolvedInstallMode == CodePush.InstallMode.ON_NEXT_RESTART) {
394
+ log("Update is installed and will be run on the next app restart.");
395
+ } else if (resolvedInstallMode == CodePush.InstallMode.ON_NEXT_RESUME) {
396
+ if (syncOptions.minimumBackgroundDuration > 0) {
397
+ log(`Update is installed and will be run after the app has been in the background for at least ${syncOptions.minimumBackgroundDuration} seconds.`);
398
+ } else {
399
+ log("Update is installed and will be run when the app next resumes.");
400
+ }
401
+ }
402
+ break;
403
+ case CodePush.SyncStatus.UNKNOWN_ERROR:
404
+ log("An unknown error occurred.");
405
+ break;
406
+ }
407
+ };
408
+
409
+ try {
410
+ await CodePush.notifyApplicationReady();
411
+
412
+ syncStatusChangeCallback(CodePush.SyncStatus.CHECKING_FOR_UPDATE);
413
+ const remotePackage = await checkForUpdate(syncOptions.deploymentKey, handleBinaryVersionMismatchCallback);
414
+
415
+ const doDownloadAndInstall = async () => {
416
+ syncStatusChangeCallback(CodePush.SyncStatus.DOWNLOADING_PACKAGE);
417
+ const localPackage = await remotePackage.download(downloadProgressCallback);
418
+
419
+ // Determine the correct install mode based on whether the update is mandatory or not.
420
+ resolvedInstallMode = localPackage.isMandatory ? syncOptions.mandatoryInstallMode : syncOptions.installMode;
421
+
422
+ syncStatusChangeCallback(CodePush.SyncStatus.INSTALLING_UPDATE);
423
+ await localPackage.install(resolvedInstallMode, syncOptions.minimumBackgroundDuration, () => {
424
+ syncStatusChangeCallback(CodePush.SyncStatus.UPDATE_INSTALLED);
425
+ });
426
+
427
+ return CodePush.SyncStatus.UPDATE_INSTALLED;
428
+ };
429
+
430
+ const updateShouldBeIgnored = await shouldUpdateBeIgnored(remotePackage, syncOptions);
431
+
432
+ if (!remotePackage || updateShouldBeIgnored) {
433
+ if (updateShouldBeIgnored) {
434
+ log("An update is available, but it is being ignored due to having been previously rolled back.");
435
+ }
436
+
437
+ const currentPackage = await CodePush.getCurrentPackage();
438
+ if (currentPackage && currentPackage.isPending) {
439
+ syncStatusChangeCallback(CodePush.SyncStatus.UPDATE_INSTALLED);
440
+ return CodePush.SyncStatus.UPDATE_INSTALLED;
441
+ } else {
442
+ syncStatusChangeCallback(CodePush.SyncStatus.UP_TO_DATE);
443
+ return CodePush.SyncStatus.UP_TO_DATE;
444
+ }
445
+ } else if (syncOptions.updateDialog) {
446
+ // updateDialog supports any truthy value (e.g. true, "goo", 12),
447
+ // but we should treat a non-object value as just the default dialog
448
+ if (typeof syncOptions.updateDialog !== "object") {
449
+ syncOptions.updateDialog = CodePush.DEFAULT_UPDATE_DIALOG;
450
+ } else {
451
+ syncOptions.updateDialog = { ...CodePush.DEFAULT_UPDATE_DIALOG, ...syncOptions.updateDialog };
452
+ }
453
+
454
+ return await new Promise((resolve, reject) => {
455
+ let message = null;
456
+ let installButtonText = null;
457
+
458
+ const dialogButtons = [];
459
+
460
+ if (remotePackage.isMandatory) {
461
+ message = syncOptions.updateDialog.mandatoryUpdateMessage;
462
+ installButtonText = syncOptions.updateDialog.mandatoryContinueButtonLabel;
463
+ } else {
464
+ message = syncOptions.updateDialog.optionalUpdateMessage;
465
+ installButtonText = syncOptions.updateDialog.optionalInstallButtonLabel;
466
+ // Since this is an optional update, add a button
467
+ // to allow the end-user to ignore it
468
+ dialogButtons.push({
469
+ text: syncOptions.updateDialog.optionalIgnoreButtonLabel,
470
+ onPress: () => {
471
+ syncStatusChangeCallback(CodePush.SyncStatus.UPDATE_IGNORED);
472
+ resolve(CodePush.SyncStatus.UPDATE_IGNORED);
473
+ }
474
+ });
475
+ }
476
+
477
+ // Since the install button should be placed to the
478
+ // right of any other button, add it last
479
+ dialogButtons.push({
480
+ text: installButtonText,
481
+ onPress:() => {
482
+ doDownloadAndInstall()
483
+ .then(resolve, reject);
484
+ }
485
+ })
486
+
487
+ // If the update has a description, and the developer
488
+ // explicitly chose to display it, then set that as the message
489
+ if (syncOptions.updateDialog.appendReleaseDescription && remotePackage.description) {
490
+ message += `${syncOptions.updateDialog.descriptionPrefix} ${remotePackage.description}`;
491
+ }
492
+
493
+ syncStatusChangeCallback(CodePush.SyncStatus.AWAITING_USER_ACTION);
494
+ Alert.alert(syncOptions.updateDialog.title, message, dialogButtons);
495
+ });
496
+ } else {
497
+ return await doDownloadAndInstall();
498
+ }
499
+ } catch (error) {
500
+ syncStatusChangeCallback(CodePush.SyncStatus.UNKNOWN_ERROR);
501
+ log(error.message);
502
+ throw error;
503
+ }
504
+ };
505
+
506
+ let CodePush;
507
+
508
+ function codePushify(options = {}) {
509
+ let React;
510
+ let ReactNative = require("react-native");
511
+
512
+ try { React = require("react"); } catch (e) { }
513
+ if (!React) {
514
+ try { React = ReactNative.React; } catch (e) { }
515
+ if (!React) {
516
+ throw new Error("Unable to find the 'React' module.");
517
+ }
518
+ }
519
+
520
+ if (!React.Component) {
521
+ throw new Error(
522
+ `Unable to find the "Component" class, please either:
523
+ 1. Upgrade to a newer version of React Native that supports it, or
524
+ 2. Call the codePush.sync API in your component instead of using the @codePush decorator`
525
+ );
526
+ }
527
+
528
+ var decorator = (RootComponent) => {
529
+ const extended = class CodePushComponent extends React.Component {
530
+ componentDidMount() {
531
+ if (options.checkFrequency === CodePush.CheckFrequency.MANUAL) {
532
+ CodePush.notifyAppReady();
533
+ } else {
534
+ let rootComponentInstance = this.refs.rootComponent;
535
+
536
+ let syncStatusCallback;
537
+ if (rootComponentInstance && rootComponentInstance.codePushStatusDidChange) {
538
+ syncStatusCallback = rootComponentInstance.codePushStatusDidChange;
539
+ if (rootComponentInstance instanceof React.Component) {
540
+ syncStatusCallback = syncStatusCallback.bind(rootComponentInstance);
541
+ }
542
+ }
543
+
544
+ let downloadProgressCallback;
545
+ if (rootComponentInstance && rootComponentInstance.codePushDownloadDidProgress) {
546
+ downloadProgressCallback = rootComponentInstance.codePushDownloadDidProgress;
547
+ if (rootComponentInstance instanceof React.Component) {
548
+ downloadProgressCallback = downloadProgressCallback.bind(rootComponentInstance);
549
+ }
550
+ }
551
+
552
+ let handleBinaryVersionMismatchCallback;
553
+ if (rootComponentInstance && rootComponentInstance.codePushOnBinaryVersionMismatch) {
554
+ handleBinaryVersionMismatchCallback = rootComponentInstance.codePushOnBinaryVersionMismatch;
555
+ if (rootComponentInstance instanceof React.Component) {
556
+ handleBinaryVersionMismatchCallback = handleBinaryVersionMismatchCallback.bind(rootComponentInstance);
557
+ }
558
+ }
559
+
560
+ CodePush.sync(options, syncStatusCallback, downloadProgressCallback, handleBinaryVersionMismatchCallback);
561
+ if (options.checkFrequency === CodePush.CheckFrequency.ON_APP_RESUME) {
562
+ ReactNative.AppState.addEventListener("change", (newState) => {
563
+ newState === "active" && CodePush.sync(options, syncStatusCallback, downloadProgressCallback);
564
+ });
565
+ }
566
+ }
567
+ }
568
+
569
+ render() {
570
+ const props = {...this.props};
571
+
572
+ // we can set ref property on class components only (not stateless)
573
+ // check it by render method
574
+ if (RootComponent.prototype.render) {
575
+ props.ref = "rootComponent";
576
+ }
577
+
578
+ return <RootComponent {...props} />
579
+ }
580
+ }
581
+
582
+ return hoistStatics(extended, RootComponent);
583
+ }
584
+
585
+ if (typeof options === "function") {
586
+ // Infer that the root component was directly passed to us.
587
+ return decorator(options);
588
+ } else {
589
+ return decorator;
590
+ }
591
+ }
592
+
593
+ // If the "NativeCodePush" variable isn't defined, then
594
+ // the app didn't properly install the native module,
595
+ // and therefore, it doesn't make sense initializing
596
+ // the JS interface when it wouldn't work anyways.
597
+ if (NativeCodePush) {
598
+ CodePush = codePushify;
599
+ Object.assign(CodePush, {
600
+ AcquisitionSdk: Sdk,
601
+ checkForUpdate,
602
+ getConfiguration,
603
+ getCurrentPackage,
604
+ getUpdateMetadata,
605
+ log,
606
+ notifyAppReady: notifyApplicationReady,
607
+ notifyApplicationReady,
608
+ restartApp: RestartManager.restartApp,
609
+ setUpTestDependencies,
610
+ sync,
611
+ disallowRestart: RestartManager.disallow,
612
+ allowRestart: RestartManager.allow,
613
+ clearUpdates: NativeCodePush.clearUpdates,
614
+ InstallMode: {
615
+ IMMEDIATE: NativeCodePush.codePushInstallModeImmediate, // Restart the app immediately
616
+ ON_NEXT_RESTART: NativeCodePush.codePushInstallModeOnNextRestart, // Don't artificially restart the app. Allow the update to be "picked up" on the next app restart
617
+ ON_NEXT_RESUME: NativeCodePush.codePushInstallModeOnNextResume, // Restart the app the next time it is resumed from the background
618
+ ON_NEXT_SUSPEND: NativeCodePush.codePushInstallModeOnNextSuspend // Restart the app _while_ it is in the background,
619
+ // but only after it has been in the background for "minimumBackgroundDuration" seconds (0 by default),
620
+ // so that user context isn't lost unless the app suspension is long enough to not matter
621
+ },
622
+ SyncStatus: {
623
+ UP_TO_DATE: 0, // The running app is up-to-date
624
+ UPDATE_INSTALLED: 1, // The app had an optional/mandatory update that was successfully downloaded and is about to be installed.
625
+ UPDATE_IGNORED: 2, // The app had an optional update and the end-user chose to ignore it
626
+ UNKNOWN_ERROR: 3,
627
+ SYNC_IN_PROGRESS: 4, // There is an ongoing "sync" operation in progress.
628
+ CHECKING_FOR_UPDATE: 5,
629
+ AWAITING_USER_ACTION: 6,
630
+ DOWNLOADING_PACKAGE: 7,
631
+ INSTALLING_UPDATE: 8
632
+ },
633
+ CheckFrequency: {
634
+ ON_APP_START: 0,
635
+ ON_APP_RESUME: 1,
636
+ MANUAL: 2
637
+ },
638
+ UpdateState: {
639
+ RUNNING: NativeCodePush.codePushUpdateStateRunning,
640
+ PENDING: NativeCodePush.codePushUpdateStatePending,
641
+ LATEST: NativeCodePush.codePushUpdateStateLatest
642
+ },
643
+ DeploymentStatus: {
644
+ FAILED: "DeploymentFailed",
645
+ SUCCEEDED: "DeploymentSucceeded",
646
+ },
647
+ DEFAULT_UPDATE_DIALOG: {
648
+ appendReleaseDescription: false,
649
+ descriptionPrefix: " Description: ",
650
+ mandatoryContinueButtonLabel: "Continue",
651
+ mandatoryUpdateMessage: "An update is available that must be installed.",
652
+ optionalIgnoreButtonLabel: "Ignore",
653
+ optionalInstallButtonLabel: "Install",
654
+ optionalUpdateMessage: "An update is available. Would you like to install it?",
655
+ title: "Update available"
656
+ },
657
+ DEFAULT_ROLLBACK_RETRY_OPTIONS: {
658
+ delayInHours: 24,
659
+ maxRetryAttempts: 1
660
+ }
661
+ });
662
+ } else {
663
+ log("The CodePush module doesn't appear to be properly installed. Please double-check that everything is setup correctly.");
664
+ }
665
+
666
+ module.exports = CodePush;
@@ -0,0 +1,27 @@
1
+ require 'json'
2
+
3
+ package = JSON.parse(File.read(File.join(__dir__, 'package.json')))
4
+
5
+ Pod::Spec.new do |s|
6
+ s.name = 'CodePush'
7
+ s.version = package['version'].gsub(/v|-beta/, '')
8
+ s.summary = package['description']
9
+ s.author = package['author']
10
+ s.license = package['license']
11
+ s.homepage = package['homepage']
12
+ s.source = { :git => 'https://github.com/appzung/react-native-code-push.git', :tag => "v#{s.version}"}
13
+ s.ios.deployment_target = '7.0'
14
+ s.tvos.deployment_target = '9.0'
15
+ s.preserve_paths = '*.js'
16
+ s.library = 'z'
17
+ s.source_files = 'ios/CodePush/*.{h,m}'
18
+ s.public_header_files = ['ios/CodePush/CodePush.h']
19
+
20
+ # Note: Even though there are copy/pasted versions of some of these dependencies in the repo,
21
+ # we explicitly let CocoaPods pull in the versions below so all dependencies are resolved and
22
+ # linked properly at a parent workspace level.
23
+ s.dependency 'React'
24
+ s.dependency 'SSZipArchive', '~> 2.1'
25
+ s.dependency 'JWT', '~> 3.0.0-beta.7'
26
+ s.dependency 'Base64', '~> 1.1'
27
+ end