@appzung/react-native-code-push 10.0.0-rc1 → 10.0.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 (320) hide show
  1. package/CodePush.podspec +1 -0
  2. package/LICENSE.md +2 -2
  3. package/README.md +74 -95
  4. package/android/app/build.gradle +62 -18
  5. package/android/app/src/main/AndroidManifest.xml +2 -3
  6. package/android/app/src/main/AndroidManifestNew.xml +3 -0
  7. package/android/app/src/main/java/com/{microsoft → appzung}/codepush/react/CodePush.java +21 -89
  8. package/android/app/src/main/java/com/{microsoft → appzung}/codepush/react/CodePushNativeModule.java +32 -3
  9. package/android/app/src/main/java/com/{microsoft → appzung}/codepush/react/CodePushUpdateManager.java +2 -2
  10. package/android/build.gradle +1 -11
  11. package/android/gradle/wrapper/gradle-wrapper.properties +1 -1
  12. package/android/gradle.properties +4 -20
  13. package/docs/advanced-usage.md +2 -2
  14. package/docs/api-android.md +12 -10
  15. package/docs/api-ios.md +5 -5
  16. package/docs/api-js.md +180 -178
  17. package/docs/code-signing.md +62 -0
  18. package/docs/migrating-to-v10.md +31 -0
  19. package/docs/setup-android.md +52 -79
  20. package/docs/setup-ios.md +31 -28
  21. package/docs/setup-windows.md +1 -0
  22. package/ios/CodePush/CodePush.m +13 -57
  23. package/lib/commonjs/CodePush.js +90 -0
  24. package/lib/commonjs/CodePush.js.map +1 -0
  25. package/lib/commonjs/allowRestart.js +12 -0
  26. package/lib/commonjs/allowRestart.js.map +1 -0
  27. package/lib/commonjs/checkForUpdates.js +105 -0
  28. package/lib/commonjs/checkForUpdates.js.map +1 -0
  29. package/lib/commonjs/clearUpdates.js +15 -0
  30. package/lib/commonjs/clearUpdates.js.map +1 -0
  31. package/lib/commonjs/disallowRestart.js +12 -0
  32. package/lib/commonjs/disallowRestart.js.map +1 -0
  33. package/lib/commonjs/enums/CheckFrequency.enum.js +25 -0
  34. package/lib/commonjs/enums/CheckFrequency.enum.js.map +1 -0
  35. package/lib/commonjs/enums/DeploymentStatus.enum.js +21 -0
  36. package/lib/commonjs/enums/DeploymentStatus.enum.js.map +1 -0
  37. package/lib/commonjs/enums/InstallMode.enum.js +35 -0
  38. package/lib/commonjs/enums/InstallMode.enum.js.map +1 -0
  39. package/lib/commonjs/enums/SyncStatus.enum.js +53 -0
  40. package/lib/commonjs/enums/SyncStatus.enum.js.map +1 -0
  41. package/lib/commonjs/enums/UpdateState.enum.js +29 -0
  42. package/lib/commonjs/enums/UpdateState.enum.js.map +1 -0
  43. package/lib/commonjs/getUpdateMetadata.js +25 -0
  44. package/lib/commonjs/getUpdateMetadata.js.map +1 -0
  45. package/lib/commonjs/index.js +195 -0
  46. package/lib/commonjs/index.js.map +1 -0
  47. package/lib/commonjs/internals/AcquisitionSdk.js +9 -0
  48. package/lib/commonjs/internals/AcquisitionSdk.js.map +1 -0
  49. package/lib/commonjs/internals/LocalPackageImplementation.js +29 -0
  50. package/lib/commonjs/internals/LocalPackageImplementation.js.map +1 -0
  51. package/lib/commonjs/internals/NativeRNAppZungCodePushModule.js +8 -0
  52. package/lib/commonjs/internals/NativeRNAppZungCodePushModule.js.map +1 -0
  53. package/lib/commonjs/internals/RNAppZungCodePushModuleSpec.js +6 -0
  54. package/lib/commonjs/internals/RNAppZungCodePushModuleSpec.js.map +1 -0
  55. package/lib/commonjs/internals/RemotePackageImplementation.js +49 -0
  56. package/lib/commonjs/internals/RemotePackageImplementation.js.map +1 -0
  57. package/lib/commonjs/internals/getConfiguration.js +15 -0
  58. package/lib/commonjs/internals/getConfiguration.js.map +1 -0
  59. package/lib/commonjs/internals/getCurrentPackage.js +12 -0
  60. package/lib/commonjs/internals/getCurrentPackage.js.map +1 -0
  61. package/lib/commonjs/internals/getPromisifiedSdk.js +49 -0
  62. package/lib/commonjs/internals/getPromisifiedSdk.js.map +1 -0
  63. package/lib/commonjs/internals/shouldUpdateBeIgnored.js +62 -0
  64. package/lib/commonjs/internals/shouldUpdateBeIgnored.js.map +1 -0
  65. package/lib/commonjs/internals/types.js +6 -0
  66. package/lib/commonjs/internals/types.js.map +1 -0
  67. package/lib/commonjs/internals/utils/log.js +11 -0
  68. package/lib/commonjs/internals/utils/log.js.map +1 -0
  69. package/lib/commonjs/internals/utils/request-fetch-adapter.js +50 -0
  70. package/lib/commonjs/internals/utils/request-fetch-adapter.js.map +1 -0
  71. package/lib/commonjs/internals/version.js +9 -0
  72. package/lib/commonjs/internals/version.js.map +1 -0
  73. package/lib/commonjs/notifyAppReady.js +83 -0
  74. package/lib/commonjs/notifyAppReady.js.map +1 -0
  75. package/lib/commonjs/reactNative.d.js +2 -0
  76. package/lib/commonjs/reactNative.d.js.map +1 -0
  77. package/lib/commonjs/restartApp.js +16 -0
  78. package/lib/commonjs/restartApp.js.map +1 -0
  79. package/lib/commonjs/sync.js +219 -0
  80. package/lib/commonjs/sync.js.map +1 -0
  81. package/lib/commonjs/types.js +6 -0
  82. package/lib/commonjs/types.js.map +1 -0
  83. package/lib/module/CodePush.js +84 -0
  84. package/lib/module/CodePush.js.map +1 -0
  85. package/lib/module/allowRestart.js +9 -0
  86. package/lib/module/allowRestart.js.map +1 -0
  87. package/lib/module/checkForUpdates.js +101 -0
  88. package/lib/module/checkForUpdates.js.map +1 -0
  89. package/lib/module/clearUpdates.js +12 -0
  90. package/lib/module/clearUpdates.js.map +1 -0
  91. package/lib/module/disallowRestart.js +9 -0
  92. package/lib/module/disallowRestart.js.map +1 -0
  93. package/lib/module/enums/CheckFrequency.enum.js +21 -0
  94. package/lib/module/enums/CheckFrequency.enum.js.map +1 -0
  95. package/lib/module/enums/DeploymentStatus.enum.js +17 -0
  96. package/lib/module/enums/DeploymentStatus.enum.js.map +1 -0
  97. package/lib/module/enums/InstallMode.enum.js +32 -0
  98. package/lib/module/enums/InstallMode.enum.js.map +1 -0
  99. package/lib/module/enums/SyncStatus.enum.js +49 -0
  100. package/lib/module/enums/SyncStatus.enum.js.map +1 -0
  101. package/lib/module/enums/UpdateState.enum.js +26 -0
  102. package/lib/module/enums/UpdateState.enum.js.map +1 -0
  103. package/lib/module/getUpdateMetadata.js +21 -0
  104. package/lib/module/getUpdateMetadata.js.map +1 -0
  105. package/lib/module/index.js +19 -0
  106. package/lib/module/index.js.map +1 -0
  107. package/lib/module/internals/AcquisitionSdk.js +5 -0
  108. package/lib/module/internals/AcquisitionSdk.js.map +1 -0
  109. package/lib/module/internals/LocalPackageImplementation.js +24 -0
  110. package/lib/module/internals/LocalPackageImplementation.js.map +1 -0
  111. package/lib/module/internals/NativeRNAppZungCodePushModule.js +4 -0
  112. package/lib/module/internals/NativeRNAppZungCodePushModule.js.map +1 -0
  113. package/lib/module/internals/RNAppZungCodePushModuleSpec.js +4 -0
  114. package/lib/module/internals/RNAppZungCodePushModuleSpec.js.map +1 -0
  115. package/lib/module/internals/RemotePackageImplementation.js +44 -0
  116. package/lib/module/internals/RemotePackageImplementation.js.map +1 -0
  117. package/lib/module/internals/getConfiguration.js +11 -0
  118. package/lib/module/internals/getConfiguration.js.map +1 -0
  119. package/lib/module/internals/getCurrentPackage.js +8 -0
  120. package/lib/module/internals/getCurrentPackage.js.map +1 -0
  121. package/lib/module/internals/getPromisifiedSdk.js +45 -0
  122. package/lib/module/internals/getPromisifiedSdk.js.map +1 -0
  123. package/lib/module/internals/shouldUpdateBeIgnored.js +58 -0
  124. package/lib/module/internals/shouldUpdateBeIgnored.js.map +1 -0
  125. package/lib/module/internals/types.js +4 -0
  126. package/lib/module/internals/types.js.map +1 -0
  127. package/lib/module/internals/utils/log.js +7 -0
  128. package/lib/module/internals/utils/log.js.map +1 -0
  129. package/lib/module/internals/utils/request-fetch-adapter.js +46 -0
  130. package/lib/module/internals/utils/request-fetch-adapter.js.map +1 -0
  131. package/lib/module/internals/version.js +5 -0
  132. package/lib/module/internals/version.js.map +1 -0
  133. package/lib/module/notifyAppReady.js +79 -0
  134. package/lib/module/notifyAppReady.js.map +1 -0
  135. package/lib/module/reactNative.d.js +2 -0
  136. package/lib/module/reactNative.d.js.map +1 -0
  137. package/lib/module/restartApp.js +13 -0
  138. package/lib/module/restartApp.js.map +1 -0
  139. package/lib/module/sync.js +215 -0
  140. package/lib/module/sync.js.map +1 -0
  141. package/lib/module/types.js +4 -0
  142. package/lib/module/types.js.map +1 -0
  143. package/lib/typescript/commonjs/package.json +1 -0
  144. package/lib/typescript/commonjs/src/CodePush.d.ts +24 -0
  145. package/lib/typescript/commonjs/src/CodePush.d.ts.map +1 -0
  146. package/lib/typescript/commonjs/src/allowRestart.d.ts +5 -0
  147. package/lib/typescript/commonjs/src/allowRestart.d.ts.map +1 -0
  148. package/lib/typescript/commonjs/src/checkForUpdates.d.ts +9 -0
  149. package/lib/typescript/commonjs/src/checkForUpdates.d.ts.map +1 -0
  150. package/lib/typescript/commonjs/src/clearUpdates.d.ts +8 -0
  151. package/lib/typescript/commonjs/src/clearUpdates.d.ts.map +1 -0
  152. package/lib/typescript/commonjs/src/disallowRestart.d.ts +5 -0
  153. package/lib/typescript/commonjs/src/disallowRestart.d.ts.map +1 -0
  154. package/lib/typescript/commonjs/src/enums/CheckFrequency.enum.d.ts +18 -0
  155. package/lib/typescript/commonjs/src/enums/CheckFrequency.enum.d.ts.map +1 -0
  156. package/lib/typescript/commonjs/src/enums/DeploymentStatus.enum.d.ts +14 -0
  157. package/lib/typescript/commonjs/src/enums/DeploymentStatus.enum.d.ts.map +1 -0
  158. package/lib/typescript/commonjs/src/enums/InstallMode.enum.d.ts +27 -0
  159. package/lib/typescript/commonjs/src/enums/InstallMode.enum.d.ts.map +1 -0
  160. package/lib/typescript/commonjs/src/enums/SyncStatus.enum.d.ts +46 -0
  161. package/lib/typescript/commonjs/src/enums/SyncStatus.enum.d.ts.map +1 -0
  162. package/lib/typescript/commonjs/src/enums/UpdateState.enum.d.ts +21 -0
  163. package/lib/typescript/commonjs/src/enums/UpdateState.enum.d.ts.map +1 -0
  164. package/lib/typescript/commonjs/src/getUpdateMetadata.d.ts +9 -0
  165. package/lib/typescript/commonjs/src/getUpdateMetadata.d.ts.map +1 -0
  166. package/lib/typescript/commonjs/src/index.d.ts +17 -0
  167. package/lib/typescript/commonjs/src/index.d.ts.map +1 -0
  168. package/lib/typescript/commonjs/src/internals/AcquisitionSdk.d.ts +3 -0
  169. package/lib/typescript/commonjs/src/internals/AcquisitionSdk.d.ts.map +1 -0
  170. package/lib/typescript/commonjs/src/internals/LocalPackageImplementation.d.ts +17 -0
  171. package/lib/typescript/commonjs/src/internals/LocalPackageImplementation.d.ts.map +1 -0
  172. package/lib/typescript/commonjs/src/internals/NativeRNAppZungCodePushModule.d.ts +3 -0
  173. package/lib/typescript/commonjs/src/internals/NativeRNAppZungCodePushModule.d.ts.map +1 -0
  174. package/lib/typescript/commonjs/src/internals/RNAppZungCodePushModuleSpec.d.ts +36 -0
  175. package/lib/typescript/commonjs/src/internals/RNAppZungCodePushModuleSpec.d.ts.map +1 -0
  176. package/lib/typescript/commonjs/src/internals/RemotePackageImplementation.d.ts +18 -0
  177. package/lib/typescript/commonjs/src/internals/RemotePackageImplementation.d.ts.map +1 -0
  178. package/lib/typescript/commonjs/src/internals/getConfiguration.d.ts +3 -0
  179. package/lib/typescript/commonjs/src/internals/getConfiguration.d.ts.map +1 -0
  180. package/lib/typescript/commonjs/src/internals/getCurrentPackage.d.ts +2 -0
  181. package/lib/typescript/commonjs/src/internals/getCurrentPackage.d.ts.map +1 -0
  182. package/lib/typescript/commonjs/src/internals/getPromisifiedSdk.d.ts +13 -0
  183. package/lib/typescript/commonjs/src/internals/getPromisifiedSdk.d.ts.map +1 -0
  184. package/lib/typescript/commonjs/src/internals/shouldUpdateBeIgnored.d.ts +3 -0
  185. package/lib/typescript/commonjs/src/internals/shouldUpdateBeIgnored.d.ts.map +1 -0
  186. package/lib/typescript/commonjs/src/internals/types.d.ts +16 -0
  187. package/lib/typescript/commonjs/src/internals/types.d.ts.map +1 -0
  188. package/lib/typescript/commonjs/src/internals/utils/log.d.ts +2 -0
  189. package/lib/typescript/commonjs/src/internals/utils/log.d.ts.map +1 -0
  190. package/lib/typescript/commonjs/src/internals/utils/request-fetch-adapter.d.ts +3 -0
  191. package/lib/typescript/commonjs/src/internals/utils/request-fetch-adapter.d.ts.map +1 -0
  192. package/lib/typescript/commonjs/src/internals/version.d.ts +2 -0
  193. package/lib/typescript/commonjs/src/internals/version.d.ts.map +1 -0
  194. package/lib/typescript/commonjs/src/notifyAppReady.d.ts +6 -0
  195. package/lib/typescript/commonjs/src/notifyAppReady.d.ts.map +1 -0
  196. package/lib/typescript/commonjs/src/restartApp.d.ts +7 -0
  197. package/lib/typescript/commonjs/src/restartApp.d.ts.map +1 -0
  198. package/lib/typescript/commonjs/src/sync.d.ts +17 -0
  199. package/lib/typescript/commonjs/src/sync.d.ts.map +1 -0
  200. package/lib/typescript/commonjs/src/types.d.ts +196 -0
  201. package/lib/typescript/commonjs/src/types.d.ts.map +1 -0
  202. package/lib/typescript/module/package.json +1 -0
  203. package/lib/typescript/module/src/CodePush.d.ts +24 -0
  204. package/lib/typescript/module/src/CodePush.d.ts.map +1 -0
  205. package/lib/typescript/module/src/allowRestart.d.ts +5 -0
  206. package/lib/typescript/module/src/allowRestart.d.ts.map +1 -0
  207. package/lib/typescript/module/src/checkForUpdates.d.ts +9 -0
  208. package/lib/typescript/module/src/checkForUpdates.d.ts.map +1 -0
  209. package/lib/typescript/module/src/clearUpdates.d.ts +8 -0
  210. package/lib/typescript/module/src/clearUpdates.d.ts.map +1 -0
  211. package/lib/typescript/module/src/disallowRestart.d.ts +5 -0
  212. package/lib/typescript/module/src/disallowRestart.d.ts.map +1 -0
  213. package/lib/typescript/module/src/enums/CheckFrequency.enum.d.ts +18 -0
  214. package/lib/typescript/module/src/enums/CheckFrequency.enum.d.ts.map +1 -0
  215. package/lib/typescript/module/src/enums/DeploymentStatus.enum.d.ts +14 -0
  216. package/lib/typescript/module/src/enums/DeploymentStatus.enum.d.ts.map +1 -0
  217. package/lib/typescript/module/src/enums/InstallMode.enum.d.ts +27 -0
  218. package/lib/typescript/module/src/enums/InstallMode.enum.d.ts.map +1 -0
  219. package/lib/typescript/module/src/enums/SyncStatus.enum.d.ts +46 -0
  220. package/lib/typescript/module/src/enums/SyncStatus.enum.d.ts.map +1 -0
  221. package/lib/typescript/module/src/enums/UpdateState.enum.d.ts +21 -0
  222. package/lib/typescript/module/src/enums/UpdateState.enum.d.ts.map +1 -0
  223. package/lib/typescript/module/src/getUpdateMetadata.d.ts +9 -0
  224. package/lib/typescript/module/src/getUpdateMetadata.d.ts.map +1 -0
  225. package/lib/typescript/module/src/index.d.ts +17 -0
  226. package/lib/typescript/module/src/index.d.ts.map +1 -0
  227. package/lib/typescript/module/src/internals/AcquisitionSdk.d.ts +3 -0
  228. package/lib/typescript/module/src/internals/AcquisitionSdk.d.ts.map +1 -0
  229. package/lib/typescript/module/src/internals/LocalPackageImplementation.d.ts +17 -0
  230. package/lib/typescript/module/src/internals/LocalPackageImplementation.d.ts.map +1 -0
  231. package/lib/typescript/module/src/internals/NativeRNAppZungCodePushModule.d.ts +3 -0
  232. package/lib/typescript/module/src/internals/NativeRNAppZungCodePushModule.d.ts.map +1 -0
  233. package/lib/typescript/module/src/internals/RNAppZungCodePushModuleSpec.d.ts +36 -0
  234. package/lib/typescript/module/src/internals/RNAppZungCodePushModuleSpec.d.ts.map +1 -0
  235. package/lib/typescript/module/src/internals/RemotePackageImplementation.d.ts +18 -0
  236. package/lib/typescript/module/src/internals/RemotePackageImplementation.d.ts.map +1 -0
  237. package/lib/typescript/module/src/internals/getConfiguration.d.ts +3 -0
  238. package/lib/typescript/module/src/internals/getConfiguration.d.ts.map +1 -0
  239. package/lib/typescript/module/src/internals/getCurrentPackage.d.ts +2 -0
  240. package/lib/typescript/module/src/internals/getCurrentPackage.d.ts.map +1 -0
  241. package/lib/typescript/module/src/internals/getPromisifiedSdk.d.ts +13 -0
  242. package/lib/typescript/module/src/internals/getPromisifiedSdk.d.ts.map +1 -0
  243. package/lib/typescript/module/src/internals/shouldUpdateBeIgnored.d.ts +3 -0
  244. package/lib/typescript/module/src/internals/shouldUpdateBeIgnored.d.ts.map +1 -0
  245. package/lib/typescript/module/src/internals/types.d.ts +16 -0
  246. package/lib/typescript/module/src/internals/types.d.ts.map +1 -0
  247. package/lib/typescript/module/src/internals/utils/log.d.ts +2 -0
  248. package/lib/typescript/module/src/internals/utils/log.d.ts.map +1 -0
  249. package/lib/typescript/module/src/internals/utils/request-fetch-adapter.d.ts +3 -0
  250. package/lib/typescript/module/src/internals/utils/request-fetch-adapter.d.ts.map +1 -0
  251. package/lib/typescript/module/src/internals/version.d.ts +2 -0
  252. package/lib/typescript/module/src/internals/version.d.ts.map +1 -0
  253. package/lib/typescript/module/src/notifyAppReady.d.ts +6 -0
  254. package/lib/typescript/module/src/notifyAppReady.d.ts.map +1 -0
  255. package/lib/typescript/module/src/restartApp.d.ts +7 -0
  256. package/lib/typescript/module/src/restartApp.d.ts.map +1 -0
  257. package/lib/typescript/module/src/sync.d.ts +17 -0
  258. package/lib/typescript/module/src/sync.d.ts.map +1 -0
  259. package/lib/typescript/module/src/types.d.ts +196 -0
  260. package/lib/typescript/module/src/types.d.ts.map +1 -0
  261. package/package.json +58 -11
  262. package/react-native.config.js +8 -8
  263. package/src/CodePush.tsx +108 -0
  264. package/src/allowRestart.ts +6 -0
  265. package/src/checkForUpdates.ts +109 -0
  266. package/src/clearUpdates.ts +9 -0
  267. package/src/disallowRestart.ts +6 -0
  268. package/src/enums/CheckFrequency.enum.ts +19 -0
  269. package/src/enums/DeploymentStatus.enum.ts +14 -0
  270. package/src/enums/InstallMode.enum.ts +31 -0
  271. package/src/enums/SyncStatus.enum.ts +53 -0
  272. package/src/enums/UpdateState.enum.ts +24 -0
  273. package/src/getUpdateMetadata.ts +23 -0
  274. package/src/index.ts +18 -0
  275. package/src/internals/AcquisitionSdk.ts +3 -0
  276. package/src/internals/LocalPackageImplementation.ts +45 -0
  277. package/src/internals/NativeRNAppZungCodePushModule.ts +3 -0
  278. package/src/internals/RNAppZungCodePushModuleSpec.ts +54 -0
  279. package/src/internals/RemotePackageImplementation.ts +69 -0
  280. package/src/internals/getConfiguration.ts +12 -0
  281. package/src/internals/getCurrentPackage.ts +6 -0
  282. package/src/internals/getPromisifiedSdk.ts +72 -0
  283. package/src/internals/shouldUpdateBeIgnored.ts +76 -0
  284. package/src/internals/types.ts +18 -0
  285. package/{logging.js → src/internals/utils/log.ts} +1 -3
  286. package/src/internals/utils/request-fetch-adapter.ts +58 -0
  287. package/src/internals/version.ts +2 -0
  288. package/src/notifyAppReady.ts +94 -0
  289. package/src/reactNative.d.ts +34 -0
  290. package/src/restartApp.ts +10 -0
  291. package/src/sync.ts +272 -0
  292. package/src/types.ts +237 -0
  293. package/tsconfig.build.json +4 -0
  294. package/tsconfig.json +29 -12
  295. package/AlertAdapter.js +0 -24
  296. package/CONTRIBUTING.md +0 -134
  297. package/CodePush.js +0 -674
  298. package/android/app/src/main/java/com/microsoft/codepush/react/CodePushBuilder.java +0 -37
  299. package/android/app/src/main/java/com/microsoft/codepush/react/CodePushDialog.java +0 -102
  300. package/package-mixins.js +0 -68
  301. package/request-fetch-adapter.js +0 -52
  302. package/tslint.json +0 -32
  303. package/typings/react-native-code-push.d.ts +0 -455
  304. /package/android/app/src/main/java/com/{microsoft → appzung}/codepush/react/CodePushConstants.java +0 -0
  305. /package/android/app/src/main/java/com/{microsoft → appzung}/codepush/react/CodePushInstallMode.java +0 -0
  306. /package/android/app/src/main/java/com/{microsoft → appzung}/codepush/react/CodePushInvalidPublicKeyException.java +0 -0
  307. /package/android/app/src/main/java/com/{microsoft → appzung}/codepush/react/CodePushInvalidUpdateException.java +0 -0
  308. /package/android/app/src/main/java/com/{microsoft → appzung}/codepush/react/CodePushMalformedDataException.java +0 -0
  309. /package/android/app/src/main/java/com/{microsoft → appzung}/codepush/react/CodePushNotInitializedException.java +0 -0
  310. /package/android/app/src/main/java/com/{microsoft → appzung}/codepush/react/CodePushTelemetryManager.java +0 -0
  311. /package/android/app/src/main/java/com/{microsoft → appzung}/codepush/react/CodePushUnknownException.java +0 -0
  312. /package/android/app/src/main/java/com/{microsoft → appzung}/codepush/react/CodePushUpdateState.java +0 -0
  313. /package/android/app/src/main/java/com/{microsoft → appzung}/codepush/react/CodePushUpdateUtils.java +0 -0
  314. /package/android/app/src/main/java/com/{microsoft → appzung}/codepush/react/CodePushUtils.java +0 -0
  315. /package/android/app/src/main/java/com/{microsoft → appzung}/codepush/react/DownloadProgress.java +0 -0
  316. /package/android/app/src/main/java/com/{microsoft → appzung}/codepush/react/DownloadProgressCallback.java +0 -0
  317. /package/android/app/src/main/java/com/{microsoft → appzung}/codepush/react/FileUtils.java +0 -0
  318. /package/android/app/src/main/java/com/{microsoft → appzung}/codepush/react/ReactInstanceHolder.java +0 -0
  319. /package/android/app/src/main/java/com/{microsoft → appzung}/codepush/react/SettingsManager.java +0 -0
  320. /package/android/app/src/main/java/com/{microsoft → appzung}/codepush/react/TLSSocketFactory.java +0 -0
@@ -0,0 +1,72 @@
1
+ import type { Http, NativeUpdateNotification, Package, RemotePackage } from 'code-push/script/acquisition-sdk';
2
+ import { AcquisitionSdk } from './AcquisitionSdk';
3
+ import type { Configuration } from './types';
4
+
5
+ export type PromisifiedSdkQueryPackage = Pick<Package, 'appVersion'> & { packageHash?: string };
6
+
7
+ type PromisifiedSdk = {
8
+ queryUpdateWithCurrentPackage: (
9
+ queryPackage: PromisifiedSdkQueryPackage,
10
+ ) => Promise<RemotePackage | NativeUpdateNotification>;
11
+ reportStatusDeploy: (
12
+ deployedPackage?: Package,
13
+ status?: string,
14
+ previousLabelOrAppVersion?: string,
15
+ previousDeploymentKey?: string,
16
+ ) => Promise<void>;
17
+ reportStatusDownload: (downloadedPackage: Package) => Promise<void>;
18
+ };
19
+
20
+ export function getPromisifiedSdk(requestFetchAdapter: Http.Requester, config: Configuration): PromisifiedSdk {
21
+ // TODO MIGRATION Temporary retro-compat while we still use code-push module
22
+ config.deploymentKey = config.releaseChannelPublicId;
23
+
24
+ const sdk = new AcquisitionSdk(requestFetchAdapter, config);
25
+
26
+ return {
27
+ queryUpdateWithCurrentPackage: (queryPackage) => {
28
+ return new Promise<RemotePackage | NativeUpdateNotification>((resolve, reject) => {
29
+ // @ts-expect-error sdk typing is wrong
30
+ AcquisitionSdk.prototype.queryUpdateWithCurrentPackage.call(sdk, queryPackage, (err, update) => {
31
+ if (err) {
32
+ reject(err);
33
+ return;
34
+ }
35
+
36
+ resolve(update);
37
+ });
38
+ });
39
+ },
40
+ reportStatusDeploy: (deployedPackage, status, previousLabelOrAppVersion, previousReleaseChannelPublicId) => {
41
+ return new Promise<void>((resolve, reject) => {
42
+ AcquisitionSdk.prototype.reportStatusDeploy.call(
43
+ sdk,
44
+ deployedPackage,
45
+ status,
46
+ previousLabelOrAppVersion,
47
+ previousReleaseChannelPublicId,
48
+ (err) => {
49
+ if (err) {
50
+ reject(err);
51
+ return;
52
+ }
53
+
54
+ resolve();
55
+ },
56
+ );
57
+ });
58
+ },
59
+ reportStatusDownload: (downloadedPackage) => {
60
+ return new Promise<void>((resolve, reject) => {
61
+ AcquisitionSdk.prototype.reportStatusDownload.call(sdk, downloadedPackage, (err) => {
62
+ if (err) {
63
+ reject(err);
64
+ return;
65
+ }
66
+
67
+ resolve();
68
+ });
69
+ });
70
+ },
71
+ };
72
+ }
@@ -0,0 +1,76 @@
1
+ import type { RemotePackage, RollbackRetryOptions, SyncOptions } from '../types';
2
+ import { NativeRNAppZungCodePushModule } from './NativeRNAppZungCodePushModule';
3
+ import type { LatestRollbackInfo } from './types';
4
+ import { log } from './utils/log';
5
+
6
+ const DEFAULT_ROLLBACK_RETRY_OPTIONS = {
7
+ delayInHours: 24,
8
+ maxRetryAttempts: 1,
9
+ };
10
+
11
+ function validateLatestRollbackInfo(latestRollbackInfo: LatestRollbackInfo, packageHash: string) {
12
+ return (
13
+ latestRollbackInfo &&
14
+ latestRollbackInfo.time &&
15
+ latestRollbackInfo.count &&
16
+ latestRollbackInfo.packageHash &&
17
+ latestRollbackInfo.packageHash === packageHash
18
+ );
19
+ }
20
+
21
+ function validateRollbackRetryOptions(rollbackRetryOptions: RollbackRetryOptions) {
22
+ if (typeof rollbackRetryOptions.delayInHours !== 'number') {
23
+ log("The 'delayInHours' rollback retry parameter must be a number.");
24
+ return false;
25
+ }
26
+
27
+ if (typeof rollbackRetryOptions.maxRetryAttempts !== 'number') {
28
+ log("The 'maxRetryAttempts' rollback retry parameter must be a number.");
29
+ return false;
30
+ }
31
+
32
+ if (rollbackRetryOptions.maxRetryAttempts < 1) {
33
+ log("The 'maxRetryAttempts' rollback retry parameter cannot be less then 1.");
34
+ return false;
35
+ }
36
+
37
+ return true;
38
+ }
39
+
40
+ export async function shouldUpdateBeIgnored(remotePackage: RemotePackage | null | undefined, syncOptions: SyncOptions) {
41
+ const isFailedPackage = remotePackage && remotePackage.failedInstall;
42
+ if (!isFailedPackage || !syncOptions.ignoreFailedUpdates) {
43
+ return false;
44
+ }
45
+
46
+ if (!syncOptions.rollbackRetryOptions) {
47
+ return true;
48
+ }
49
+
50
+ const rollbackRetryOptions: Required<RollbackRetryOptions> =
51
+ typeof syncOptions.rollbackRetryOptions === 'object'
52
+ ? {
53
+ ...DEFAULT_ROLLBACK_RETRY_OPTIONS,
54
+ ...syncOptions.rollbackRetryOptions,
55
+ }
56
+ : DEFAULT_ROLLBACK_RETRY_OPTIONS;
57
+
58
+ if (!validateRollbackRetryOptions(rollbackRetryOptions)) {
59
+ return true;
60
+ }
61
+
62
+ const latestRollbackInfo = await NativeRNAppZungCodePushModule.getLatestRollbackInfo();
63
+ if (!validateLatestRollbackInfo(latestRollbackInfo, remotePackage.packageHash)) {
64
+ log('The latest rollback info is not valid.');
65
+ return true;
66
+ }
67
+
68
+ const { delayInHours, maxRetryAttempts } = rollbackRetryOptions;
69
+ const hoursSinceLatestRollback = (Date.now() - latestRollbackInfo.time) / (1000 * 60 * 60);
70
+ if (hoursSinceLatestRollback >= delayInHours && maxRetryAttempts >= latestRollbackInfo.count) {
71
+ log('Previous rollback should be ignored due to rollback retry options.');
72
+ return false;
73
+ }
74
+
75
+ return true;
76
+ }
@@ -0,0 +1,18 @@
1
+ import type { Configuration as BaseConfiguration } from 'code-push/script/acquisition-sdk';
2
+
3
+ export interface Configuration extends BaseConfiguration {
4
+ releaseChannelPublicId: string;
5
+ packageHash?: string;
6
+ }
7
+
8
+ export interface LatestRollbackInfo {
9
+ time: number;
10
+ count: number;
11
+ packageHash: string;
12
+ }
13
+
14
+ type FunctionPropertyNames<T> = {
15
+ [K in keyof T]: T[K] extends Function ? K : never;
16
+ }[keyof T];
17
+
18
+ export type OmitFunctions<T extends object> = Omit<T, FunctionPropertyNames<T>>;
@@ -1,6 +1,4 @@
1
1
  /* Logs messages to console with the [CodePush] prefix */
2
- function log(message) {
2
+ export function log(message: string): void {
3
3
  console.log(`[CodePush] ${message}`);
4
4
  }
5
-
6
- module.exports = log;
@@ -0,0 +1,58 @@
1
+ import { Http } from 'code-push/script/acquisition-sdk';
2
+ import { version } from '../version';
3
+
4
+ interface ResponseCallback {
5
+ (error: Error | null, response?: Http.Response): void;
6
+ }
7
+
8
+ export const requestFetchAdapter: Http.Requester = {
9
+ // @ts-expect-error SDK typing is wrong about error callback
10
+ async request(
11
+ verb: Http.Verb,
12
+ url: string,
13
+ requestBody: any | ResponseCallback,
14
+ callback?: ResponseCallback,
15
+ ): Promise<void> {
16
+ if (typeof requestBody === 'function') {
17
+ callback = requestBody;
18
+ requestBody = null;
19
+ }
20
+
21
+ const headers = {
22
+ Accept: 'application/json',
23
+ 'Content-Type': 'application/json',
24
+ 'X-CodePush-Plugin-Name': '@appzung/react-native-code-push',
25
+ 'X-CodePush-Plugin-Version': version,
26
+ };
27
+
28
+ if (requestBody && typeof requestBody === 'object') {
29
+ requestBody = JSON.stringify(requestBody);
30
+ }
31
+
32
+ try {
33
+ const response = await fetch(url, {
34
+ method: getHttpMethodName(verb),
35
+ headers: headers,
36
+ body: requestBody,
37
+ });
38
+
39
+ const statusCode = response.status;
40
+ const body = await response.text();
41
+ callback!(null, { statusCode, body });
42
+ } catch (err) {
43
+ callback!(err as Error);
44
+ }
45
+ },
46
+ };
47
+
48
+ function getHttpMethodName(verb: Http.Verb): string {
49
+ // Note: This should stay in sync with the enum definition in
50
+ // https://github.com/microsoft/code-push/blob/master/sdk/script/acquisition-sdk.ts#L6
51
+ const methodName = ['GET', 'HEAD', 'POST', 'PUT', 'DELETE', 'TRACE', 'OPTIONS', 'CONNECT', 'PATCH'][verb];
52
+
53
+ if (!methodName) {
54
+ throw new Error('Invalid method name verb');
55
+ }
56
+
57
+ return methodName;
58
+ }
@@ -0,0 +1,2 @@
1
+ // Generated by genversion.
2
+ export const version = '10.0.0';
@@ -0,0 +1,94 @@
1
+ import { AppState, type NativeEventSubscription } from 'react-native';
2
+ import { NativeRNAppZungCodePushModule } from './internals/NativeRNAppZungCodePushModule';
3
+ import { getConfiguration } from './internals/getConfiguration';
4
+ import { getPromisifiedSdk } from './internals/getPromisifiedSdk';
5
+ import { log } from './internals/utils/log';
6
+ import { requestFetchAdapter } from './internals/utils/request-fetch-adapter';
7
+ import type { StatusReport } from './types';
8
+
9
+ /**
10
+ * Notifies the CodePush runtime that an installed update is considered successful.
11
+ */
12
+ export const notifyAppReady = (() => {
13
+ // This ensures that notifyApplicationReadyInternal is only called once
14
+ // in the lifetime of this module instance.
15
+ let notifyApplicationReadyPromise: Promise<StatusReport | void> | undefined;
16
+
17
+ return () => {
18
+ if (!notifyApplicationReadyPromise) {
19
+ notifyApplicationReadyPromise = notifyApplicationReadyInternal();
20
+ }
21
+
22
+ return notifyApplicationReadyPromise;
23
+ };
24
+ })();
25
+
26
+ async function notifyApplicationReadyInternal() {
27
+ await NativeRNAppZungCodePushModule.notifyApplicationReady();
28
+ const statusReport = await NativeRNAppZungCodePushModule.getNewStatusReport();
29
+ statusReport && tryReportStatus(statusReport); // Don't wait for this to complete.
30
+
31
+ return statusReport;
32
+ }
33
+
34
+ async function tryReportStatus(statusReport: StatusReport, retryOnAppResume?: NativeEventSubscription) {
35
+ const config = await getConfiguration();
36
+ const previousLabelOrAppVersion = statusReport.previousLabelOrAppVersion;
37
+ const previousReleaseChannelPublicId = statusReport.previousReleaseChannelPublicId || config.releaseChannelPublicId;
38
+ try {
39
+ if (statusReport.appVersion) {
40
+ log(`Reporting binary update (${statusReport.appVersion})`);
41
+
42
+ if (!config.releaseChannelPublicId) {
43
+ throw new Error('Release channel is missing');
44
+ }
45
+
46
+ const sdk = getPromisifiedSdk(requestFetchAdapter, config);
47
+ await sdk.reportStatusDeploy(
48
+ /* deployedPackage */ undefined,
49
+ /* status */ undefined,
50
+ previousLabelOrAppVersion,
51
+ previousReleaseChannelPublicId,
52
+ );
53
+ } else {
54
+ if (!statusReport.package) {
55
+ throw new Error('Missing package in status report');
56
+ }
57
+
58
+ const label = statusReport.package.label;
59
+ if (statusReport.status === 'DeploymentSucceeded') {
60
+ log(`Reporting CodePush update success (${label})`);
61
+ } else {
62
+ log(`Reporting CodePush update rollback (${label})`);
63
+ await NativeRNAppZungCodePushModule.setLatestRollbackInfo(statusReport.package.packageHash);
64
+ }
65
+
66
+ config.releaseChannelPublicId = statusReport.package.releaseChannelPublicId;
67
+ const sdk = getPromisifiedSdk(requestFetchAdapter, config);
68
+ await sdk.reportStatusDeploy(
69
+ { ...statusReport.package, deploymentKey: statusReport.package.releaseChannelPublicId },
70
+ statusReport.status,
71
+ previousLabelOrAppVersion,
72
+ previousReleaseChannelPublicId,
73
+ );
74
+ }
75
+
76
+ NativeRNAppZungCodePushModule.recordStatusReported(statusReport);
77
+ retryOnAppResume && retryOnAppResume.remove();
78
+ } catch (e) {
79
+ log(`Report status failed: ${JSON.stringify(statusReport)}`);
80
+ NativeRNAppZungCodePushModule.saveStatusReportForRetry(statusReport);
81
+ // Try again when the app resumes
82
+ if (!retryOnAppResume) {
83
+ const resumeListener = AppState.addEventListener('change', async (newState) => {
84
+ if (newState !== 'active') return;
85
+ const refreshedStatusReport = await NativeRNAppZungCodePushModule.getNewStatusReport();
86
+ if (refreshedStatusReport) {
87
+ tryReportStatus(refreshedStatusReport, resumeListener);
88
+ } else {
89
+ resumeListener && resumeListener.remove();
90
+ }
91
+ });
92
+ }
93
+ }
94
+ }
@@ -0,0 +1,34 @@
1
+ declare module 'react-native' {
2
+ export type PlatformStatic = {
3
+ OS: 'ios' | 'android' | 'windows';
4
+ };
5
+ export const Platform: PlatformStatic;
6
+
7
+ export interface NativeEventSubscription {
8
+ remove(): void;
9
+ }
10
+ export class NativeEventEmitter {
11
+ constructor(nativeModule?: any);
12
+ addListener(eventType: string, listener: (event: any) => void, context?: Object): NativeEventSubscription;
13
+ }
14
+
15
+ type AppStateStatus = string;
16
+ export interface AppStateStatic {
17
+ currentState: AppStateStatus;
18
+ addEventListener(type: AppStateEvent, listener: (state: AppStateStatus) => void): NativeEventSubscription;
19
+ }
20
+ export const AppState: AppStateStatic;
21
+
22
+ export interface AlertButton {
23
+ text?: string;
24
+ onPress?: () => void;
25
+ }
26
+ interface AlertStatic {
27
+ alert(title: string, message?: string, buttons?: AlertButton[]): void;
28
+ }
29
+ export const Alert: AlertStatic;
30
+
31
+ export interface TurboModule {
32
+ getConstants?(): {};
33
+ }
34
+ }
@@ -0,0 +1,10 @@
1
+ import { NativeRNAppZungCodePushModule } from './internals/NativeRNAppZungCodePushModule';
2
+
3
+ /**
4
+ * Immediately restarts the app.
5
+ *
6
+ * @param onlyIfUpdateIsPending Indicates whether you want the restart to no-op if there isn't currently a pending update.
7
+ */
8
+ export async function restartApp(onlyIfUpdateIsPending = false) {
9
+ NativeRNAppZungCodePushModule.restartApp(onlyIfUpdateIsPending);
10
+ }
package/src/sync.ts ADDED
@@ -0,0 +1,272 @@
1
+ import { Alert, type AlertButton, Platform } from 'react-native';
2
+ import { checkForUpdate } from './checkForUpdates';
3
+ import { InstallMode } from './enums/InstallMode.enum';
4
+ import { SyncStatus } from './enums/SyncStatus.enum';
5
+ import { getCurrentPackage } from './internals/getCurrentPackage';
6
+ import { shouldUpdateBeIgnored } from './internals/shouldUpdateBeIgnored';
7
+ import { log } from './internals/utils/log';
8
+ import { notifyAppReady } from './notifyAppReady';
9
+ import type {
10
+ DownloadProgressCallback,
11
+ HandleBinaryVersionMismatchCallback,
12
+ SyncOptions,
13
+ SyncStatusChangedCallback,
14
+ UpdateDialog,
15
+ } from './types';
16
+
17
+ /**
18
+ * Represents the default settings that will be used by the sync method if
19
+ * an update dialog is configured to be displayed.
20
+ */
21
+ export const DEFAULT_UPDATE_DIALOG: UpdateDialog = {
22
+ appendReleaseDescription: false,
23
+ descriptionPrefix: ' Description: ',
24
+ mandatoryContinueButtonLabel: 'Continue',
25
+ mandatoryUpdateMessage: 'An update is available that must be installed.',
26
+ optionalIgnoreButtonLabel: 'Ignore',
27
+ optionalInstallButtonLabel: 'Install',
28
+ optionalUpdateMessage: 'An update is available. Would you like to install it?',
29
+ title: 'Update available',
30
+ };
31
+
32
+ /*
33
+ * The syncInternal method provides a simple, one-line experience for
34
+ * incorporating the check, download and installation of an update.
35
+ *
36
+ * It simply composes the existing API methods together and adds additional
37
+ * support for respecting mandatory updates, ignoring previously failed
38
+ * releases, and displaying a standard confirmation UI to the end-user
39
+ * when an update is available.
40
+ */
41
+ async function syncInternal(
42
+ options?: SyncOptions,
43
+ syncStatusChangeCallback?: SyncStatusChangedCallback,
44
+ downloadProgressCallback?: DownloadProgressCallback,
45
+ handleBinaryVersionMismatchCallback?: HandleBinaryVersionMismatchCallback,
46
+ ): Promise<SyncStatus> {
47
+ let resolvedInstallMode: InstallMode | undefined;
48
+ const syncOptions: SyncOptions = {
49
+ releaseChannelPublicId: undefined,
50
+ ignoreFailedUpdates: true,
51
+ rollbackRetryOptions: undefined,
52
+ installMode: InstallMode.ON_NEXT_RESTART,
53
+ mandatoryInstallMode: InstallMode.IMMEDIATE,
54
+ minimumBackgroundDuration: 0,
55
+ updateDialog: undefined,
56
+ ...options,
57
+ };
58
+
59
+ syncStatusChangeCallback =
60
+ typeof syncStatusChangeCallback === 'function'
61
+ ? syncStatusChangeCallback
62
+ : (syncStatus: SyncStatus) => {
63
+ switch (syncStatus) {
64
+ case SyncStatus.CHECKING_FOR_UPDATE:
65
+ log('Checking for update.');
66
+ break;
67
+ case SyncStatus.AWAITING_USER_ACTION:
68
+ log('Awaiting user action.');
69
+ break;
70
+ case SyncStatus.DOWNLOADING_PACKAGE:
71
+ log('Downloading package.');
72
+ break;
73
+ case SyncStatus.INSTALLING_UPDATE:
74
+ log('Installing update.');
75
+ break;
76
+ case SyncStatus.UP_TO_DATE:
77
+ log('App is up to date.');
78
+ break;
79
+ case SyncStatus.UPDATE_IGNORED:
80
+ log('User cancelled the update.');
81
+ break;
82
+ case SyncStatus.UPDATE_INSTALLED:
83
+ if (resolvedInstallMode == InstallMode.ON_NEXT_RESTART) {
84
+ log('Update is installed and will be run on the next app restart.');
85
+ } else if (resolvedInstallMode == InstallMode.ON_NEXT_RESUME) {
86
+ if (!!syncOptions.minimumBackgroundDuration) {
87
+ log(
88
+ `Update is installed and will be run after the app has been in the background for at least ${syncOptions.minimumBackgroundDuration} seconds.`,
89
+ );
90
+ } else {
91
+ log('Update is installed and will be run when the app next resumes.');
92
+ }
93
+ }
94
+ break;
95
+ case SyncStatus.UNKNOWN_ERROR:
96
+ log('An unknown error occurred.');
97
+ break;
98
+ }
99
+ };
100
+
101
+ try {
102
+ await notifyAppReady();
103
+
104
+ syncStatusChangeCallback(SyncStatus.CHECKING_FOR_UPDATE);
105
+ const remotePackage = await checkForUpdate(syncOptions.releaseChannelPublicId, handleBinaryVersionMismatchCallback);
106
+
107
+ const doDownloadAndInstall = async () => {
108
+ if (!remotePackage) {
109
+ throw new Error('remotePackage should be defined');
110
+ }
111
+
112
+ syncStatusChangeCallback(SyncStatus.DOWNLOADING_PACKAGE);
113
+ const localPackage = await remotePackage.download(downloadProgressCallback);
114
+
115
+ // Determine the correct install mode based on whether the update is mandatory or not.
116
+ resolvedInstallMode = localPackage.isMandatory ? syncOptions.mandatoryInstallMode : syncOptions.installMode;
117
+
118
+ syncStatusChangeCallback(SyncStatus.INSTALLING_UPDATE);
119
+ await localPackage.install(resolvedInstallMode, syncOptions.minimumBackgroundDuration, () => {
120
+ syncStatusChangeCallback(SyncStatus.UPDATE_INSTALLED);
121
+ });
122
+
123
+ return SyncStatus.UPDATE_INSTALLED;
124
+ };
125
+
126
+ const updateShouldBeIgnored = await shouldUpdateBeIgnored(remotePackage, syncOptions);
127
+
128
+ if (!remotePackage || updateShouldBeIgnored) {
129
+ if (updateShouldBeIgnored) {
130
+ log('An update is available, but it is being ignored due to having been previously rolled back.');
131
+ }
132
+
133
+ const currentPackage = await getCurrentPackage();
134
+ if (currentPackage && currentPackage.isPending) {
135
+ syncStatusChangeCallback(SyncStatus.UPDATE_INSTALLED);
136
+ return SyncStatus.UPDATE_INSTALLED;
137
+ } else {
138
+ syncStatusChangeCallback(SyncStatus.UP_TO_DATE);
139
+ return SyncStatus.UP_TO_DATE;
140
+ }
141
+ } else if (syncOptions.updateDialog) {
142
+ const updateDialogConfig =
143
+ typeof syncOptions.updateDialog !== 'object'
144
+ ? DEFAULT_UPDATE_DIALOG
145
+ : { ...DEFAULT_UPDATE_DIALOG, ...syncOptions.updateDialog };
146
+
147
+ return await new Promise((resolve, reject) => {
148
+ let message: string | undefined;
149
+ let installButtonText: string | undefined;
150
+
151
+ const dialogButtons: AlertButton[] = [];
152
+
153
+ if (remotePackage.isMandatory) {
154
+ message = updateDialogConfig.mandatoryUpdateMessage;
155
+ installButtonText = updateDialogConfig.mandatoryContinueButtonLabel;
156
+ } else {
157
+ message = updateDialogConfig.optionalUpdateMessage;
158
+ installButtonText = updateDialogConfig.optionalInstallButtonLabel;
159
+ // Since this is an optional update, add a button
160
+ // to allow the end-user to ignore it
161
+ dialogButtons.push({
162
+ text: updateDialogConfig.optionalIgnoreButtonLabel ?? '',
163
+ onPress: () => {
164
+ syncStatusChangeCallback(SyncStatus.UPDATE_IGNORED);
165
+ resolve(SyncStatus.UPDATE_IGNORED);
166
+ },
167
+ });
168
+ }
169
+
170
+ // Since the install button should be placed to the
171
+ // right of any other button, add it last
172
+ dialogButtons.push({
173
+ text: installButtonText ?? '',
174
+ onPress: () => {
175
+ doDownloadAndInstall().then(resolve, reject);
176
+ },
177
+ });
178
+
179
+ // If the update has a description, and the developer
180
+ // explicitly chose to display it, then set that as the message
181
+ if (updateDialogConfig.appendReleaseDescription && remotePackage.description) {
182
+ message += `${updateDialogConfig.descriptionPrefix} ${remotePackage.description}`;
183
+ }
184
+
185
+ syncStatusChangeCallback(SyncStatus.AWAITING_USER_ACTION);
186
+ Alert.alert(
187
+ updateDialogConfig.title || '',
188
+ message || '',
189
+ Platform.OS === 'android' ? [...dialogButtons.reverse()] : dialogButtons,
190
+ );
191
+ });
192
+ } else {
193
+ return await doDownloadAndInstall();
194
+ }
195
+ } catch (error) {
196
+ syncStatusChangeCallback(SyncStatus.UNKNOWN_ERROR);
197
+ log(
198
+ error != null && typeof error === 'object' && 'message' in error && typeof error.message === 'string'
199
+ ? error.message
200
+ : 'Unknown',
201
+ );
202
+ throw error;
203
+ }
204
+ }
205
+
206
+ /**
207
+ * Allows checking for an update, downloading it and installing it, all with a single call.
208
+ *
209
+ * @param options Options used to configure the end-user update experience (e.g. show a prompt?, install the update immediately?).
210
+ * @param syncStatusChangedCallback An optional callback that allows tracking the status of the sync operation, as opposed to simply checking the resolved state via the returned Promise.
211
+ * @param downloadProgressCallback An optional callback that allows tracking the progress of an update while it is being downloaded.
212
+ * @param handleBinaryVersionMismatchCallback An optional callback for handling target binary version mismatch
213
+ */
214
+ export const sync = (() => {
215
+ // This function allows only one syncInternal operation to proceed at any given time.
216
+ // Parallel calls to sync() while one is ongoing yields CodePush.SyncStatus.SYNC_IN_PROGRESS.
217
+
218
+ let syncInProgress = false;
219
+ const setSyncCompleted = () => {
220
+ syncInProgress = false;
221
+ };
222
+
223
+ return (
224
+ options?: SyncOptions,
225
+ syncStatusChangeCallback?: SyncStatusChangedCallback,
226
+ downloadProgressCallback?: DownloadProgressCallback,
227
+ handleBinaryVersionMismatchCallback?: HandleBinaryVersionMismatchCallback,
228
+ ): Promise<SyncStatus> => {
229
+ let syncStatusCallbackWithTryCatch: SyncStatusChangedCallback | undefined;
230
+ let downloadProgressCallbackWithTryCatch: DownloadProgressCallback | undefined;
231
+
232
+ if (typeof syncStatusChangeCallback === 'function') {
233
+ syncStatusCallbackWithTryCatch = (...args) => {
234
+ try {
235
+ syncStatusChangeCallback(...args);
236
+ } catch (error) {
237
+ log(`An error has occurred : ${error instanceof Error ? error.stack : 'unknown'}`);
238
+ }
239
+ };
240
+ }
241
+
242
+ if (typeof downloadProgressCallback === 'function') {
243
+ downloadProgressCallbackWithTryCatch = (...args) => {
244
+ try {
245
+ downloadProgressCallback(...args);
246
+ } catch (error) {
247
+ log(`An error has occurred: ${error instanceof Error ? error.stack : 'unknown'}`);
248
+ }
249
+ };
250
+ }
251
+
252
+ if (syncInProgress) {
253
+ typeof syncStatusCallbackWithTryCatch === 'function'
254
+ ? syncStatusCallbackWithTryCatch(SyncStatus.SYNC_IN_PROGRESS)
255
+ : log('Sync already in progress.');
256
+ return Promise.resolve(SyncStatus.SYNC_IN_PROGRESS);
257
+ }
258
+
259
+ syncInProgress = true;
260
+
261
+ const syncPromise = syncInternal(
262
+ options,
263
+ syncStatusCallbackWithTryCatch,
264
+ downloadProgressCallbackWithTryCatch,
265
+ handleBinaryVersionMismatchCallback,
266
+ );
267
+
268
+ syncPromise.then(setSyncCompleted).catch(setSyncCompleted);
269
+
270
+ return syncPromise;
271
+ };
272
+ })();