@algocare/react-native-code-push 12.6.4 → 13.0.0-rc.0

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