@hot-updater/react-native 1.0.0-rc.15 → 1.0.0-rc.17

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 (302) hide show
  1. package/android/src/main/java/com/hotupdater/BundleFileStorageService.kt +491 -388
  2. package/android/src/main/java/com/hotupdater/BundleMetadata.kt +5 -11
  3. package/android/src/main/java/com/hotupdater/FileManagerService.kt +45 -0
  4. package/android/src/main/java/com/hotupdater/HotUpdaterException.kt +290 -12
  5. package/android/src/main/java/com/hotupdater/HotUpdaterImpl.kt +35 -19
  6. package/android/src/main/java/com/hotupdater/InstallIdentityService.kt +37 -0
  7. package/android/src/main/java/com/hotupdater/KeyValueStorageService.kt +86 -0
  8. package/android/src/main/java/com/hotupdater/NetworkState.kt +31 -0
  9. package/android/src/main/java/com/hotupdater/NoBackupStorage.kt +17 -0
  10. package/android/src/main/java/com/hotupdater/OkHttpDownloadService.kt +110 -52
  11. package/android/src/main/java/com/hotupdater/PreviousProcessExit.kt +89 -0
  12. package/android/src/main/java/com/hotupdater/ReactNativeValueConverters.kt +34 -0
  13. package/android/src/newarch/HotUpdaterModule.kt +74 -69
  14. package/android/src/oldarch/HotUpdaterModule.kt +63 -59
  15. package/android/src/oldarch/HotUpdaterSpec.kt +4 -6
  16. package/android/src/test/java/com/hotupdater/BsdiffPatchTest.kt +1 -1
  17. package/android/src/test/java/com/hotupdater/BundleFileStorageServiceTest.kt +446 -61
  18. package/android/src/test/java/com/hotupdater/HotUpdaterExceptionTest.kt +220 -0
  19. package/android/src/test/java/com/hotupdater/HotUpdaterImplTest.kt +19 -27
  20. package/android/src/test/java/com/hotupdater/InstallIdentityServiceTest.kt +71 -0
  21. package/android/src/test/java/com/hotupdater/KeyValueStorageServiceTest.kt +106 -0
  22. package/android/src/test/java/com/hotupdater/NoBackupContext.kt +11 -0
  23. package/android/src/test/java/com/hotupdater/OkHttpDownloadServiceTest.kt +309 -23
  24. package/android/src/test/java/com/hotupdater/PreviousProcessExitTest.kt +57 -0
  25. package/ios/HotUpdater/Internal/BundleFileStorageService.swift +238 -157
  26. package/ios/HotUpdater/Internal/BundleMetadata.swift +3 -53
  27. package/ios/HotUpdater/Internal/FileManagerService.swift +48 -0
  28. package/ios/HotUpdater/Internal/HotUpdater.mm +8 -18
  29. package/ios/HotUpdater/Internal/HotUpdaterImpl.swift +48 -29
  30. package/ios/HotUpdater/Internal/KeyValueStorageService.swift +71 -0
  31. package/ios/HotUpdater/Internal/URLSessionDownloadService.swift +108 -1
  32. package/ios/HotUpdater/Internal/UpdateFailure.swift +390 -0
  33. package/lib/commonjs/appReady.js +111 -0
  34. package/lib/commonjs/appReady.js.map +1 -0
  35. package/lib/commonjs/appReady.spec.js +360 -0
  36. package/lib/commonjs/appReady.spec.js.map +1 -0
  37. package/lib/commonjs/{notifyAppReadyInsights.test-utils.js → appReady.test-utils.js} +4 -3
  38. package/lib/commonjs/appReady.test-utils.js.map +1 -0
  39. package/lib/commonjs/baseURL.js +16 -0
  40. package/lib/commonjs/baseURL.js.map +1 -0
  41. package/lib/commonjs/checkForUpdate.js +104 -56
  42. package/lib/commonjs/checkForUpdate.js.map +1 -1
  43. package/lib/commonjs/checkForUpdate.releaseCatalog.spec.js +337 -74
  44. package/lib/commonjs/checkForUpdate.releaseCatalog.spec.js.map +1 -1
  45. package/lib/commonjs/clientPlugin.js +49 -0
  46. package/lib/commonjs/clientPlugin.js.map +1 -0
  47. package/lib/commonjs/entryImportGraph.spec.js +50 -0
  48. package/lib/commonjs/entryImportGraph.spec.js.map +1 -0
  49. package/lib/commonjs/fetchJSON.js +2 -6
  50. package/lib/commonjs/fetchJSON.js.map +1 -1
  51. package/lib/commonjs/httpClient.js +15 -67
  52. package/lib/commonjs/httpClient.js.map +1 -1
  53. package/lib/commonjs/httpClient.spec.js +26 -9
  54. package/lib/commonjs/httpClient.spec.js.map +1 -1
  55. package/lib/commonjs/index.js +49 -25
  56. package/lib/commonjs/index.js.map +1 -1
  57. package/lib/commonjs/index.spec.js +126 -40
  58. package/lib/commonjs/index.spec.js.map +1 -1
  59. package/lib/commonjs/native.js +67 -48
  60. package/lib/commonjs/native.js.map +1 -1
  61. package/lib/commonjs/native.spec.js +80 -58
  62. package/lib/commonjs/native.spec.js.map +1 -1
  63. package/lib/commonjs/pluginHost.js +208 -0
  64. package/lib/commonjs/pluginHost.js.map +1 -0
  65. package/lib/commonjs/pluginHost.spec.js +292 -0
  66. package/lib/commonjs/pluginHost.spec.js.map +1 -0
  67. package/lib/commonjs/plugins/insights/eventId.js +129 -0
  68. package/lib/commonjs/plugins/insights/eventId.js.map +1 -0
  69. package/lib/commonjs/plugins/insights/eventId.spec.js +47 -0
  70. package/lib/commonjs/plugins/insights/eventId.spec.js.map +1 -0
  71. package/lib/commonjs/plugins/insights/index.js +272 -0
  72. package/lib/commonjs/plugins/insights/index.js.map +1 -0
  73. package/lib/commonjs/plugins/insights/insights.spec.js +640 -0
  74. package/lib/commonjs/plugins/insights/insights.spec.js.map +1 -0
  75. package/lib/commonjs/plugins/insights/sender.js +128 -0
  76. package/lib/commonjs/plugins/insights/sender.js.map +1 -0
  77. package/lib/commonjs/plugins/insights/sender.spec.js +265 -0
  78. package/lib/commonjs/plugins/insights/sender.spec.js.map +1 -0
  79. package/lib/commonjs/plugins/insights/state.js +145 -0
  80. package/lib/commonjs/plugins/insights/state.js.map +1 -0
  81. package/lib/commonjs/releaseCatalogCache.js +13 -2
  82. package/lib/commonjs/releaseCatalogCache.js.map +1 -1
  83. package/lib/commonjs/releaseCatalogCache.spec.js +18 -0
  84. package/lib/commonjs/releaseCatalogCache.spec.js.map +1 -1
  85. package/lib/commonjs/sdkVersion.js +1 -1
  86. package/lib/commonjs/specs/NativeHotUpdater.js.map +1 -1
  87. package/lib/commonjs/updateError.js +132 -0
  88. package/lib/commonjs/updateError.js.map +1 -0
  89. package/lib/commonjs/updateError.spec.js +149 -0
  90. package/lib/commonjs/updateError.spec.js.map +1 -0
  91. package/lib/commonjs/wrap.js +43 -25
  92. package/lib/commonjs/wrap.js.map +1 -1
  93. package/lib/commonjs/wrap.progress.spec.js +195 -0
  94. package/lib/commonjs/wrap.progress.spec.js.map +1 -0
  95. package/lib/commonjs/wrap.spec.js +94 -230
  96. package/lib/commonjs/wrap.spec.js.map +1 -1
  97. package/lib/module/appReady.js +103 -0
  98. package/lib/module/appReady.js.map +1 -0
  99. package/lib/module/appReady.spec.js +359 -0
  100. package/lib/module/appReady.spec.js.map +1 -0
  101. package/lib/module/{notifyAppReadyInsights.test-utils.js → appReady.test-utils.js} +4 -3
  102. package/lib/module/appReady.test-utils.js.map +1 -0
  103. package/lib/module/baseURL.js +11 -0
  104. package/lib/module/baseURL.js.map +1 -0
  105. package/lib/module/checkForUpdate.js +103 -57
  106. package/lib/module/checkForUpdate.js.map +1 -1
  107. package/lib/module/checkForUpdate.releaseCatalog.spec.js +337 -74
  108. package/lib/module/checkForUpdate.releaseCatalog.spec.js.map +1 -1
  109. package/lib/module/clientPlugin.js +44 -0
  110. package/lib/module/clientPlugin.js.map +1 -0
  111. package/lib/module/entryImportGraph.spec.js +50 -0
  112. package/lib/module/entryImportGraph.spec.js.map +1 -0
  113. package/lib/module/fetchJSON.js +2 -6
  114. package/lib/module/fetchJSON.js.map +1 -1
  115. package/lib/module/httpClient.js +14 -66
  116. package/lib/module/httpClient.js.map +1 -1
  117. package/lib/module/httpClient.spec.js +26 -9
  118. package/lib/module/httpClient.spec.js.map +1 -1
  119. package/lib/module/index.js +44 -27
  120. package/lib/module/index.js.map +1 -1
  121. package/lib/module/index.spec.js +127 -41
  122. package/lib/module/index.spec.js.map +1 -1
  123. package/lib/module/native.js +63 -44
  124. package/lib/module/native.js.map +1 -1
  125. package/lib/module/native.spec.js +80 -58
  126. package/lib/module/native.spec.js.map +1 -1
  127. package/lib/module/pluginHost.js +200 -0
  128. package/lib/module/pluginHost.js.map +1 -0
  129. package/lib/module/pluginHost.spec.js +291 -0
  130. package/lib/module/pluginHost.spec.js.map +1 -0
  131. package/lib/module/plugins/insights/eventId.js +122 -0
  132. package/lib/module/plugins/insights/eventId.js.map +1 -0
  133. package/lib/module/plugins/insights/eventId.spec.js +47 -0
  134. package/lib/module/plugins/insights/eventId.spec.js.map +1 -0
  135. package/lib/module/plugins/insights/index.js +268 -0
  136. package/lib/module/plugins/insights/index.js.map +1 -0
  137. package/lib/module/plugins/insights/insights.spec.js +639 -0
  138. package/lib/module/plugins/insights/insights.spec.js.map +1 -0
  139. package/lib/module/plugins/insights/sender.js +123 -0
  140. package/lib/module/plugins/insights/sender.js.map +1 -0
  141. package/lib/module/plugins/insights/sender.spec.js +265 -0
  142. package/lib/module/plugins/insights/sender.spec.js.map +1 -0
  143. package/lib/module/plugins/insights/state.js +139 -0
  144. package/lib/module/plugins/insights/state.js.map +1 -0
  145. package/lib/module/releaseCatalogCache.js +13 -2
  146. package/lib/module/releaseCatalogCache.js.map +1 -1
  147. package/lib/module/releaseCatalogCache.spec.js +18 -0
  148. package/lib/module/releaseCatalogCache.spec.js.map +1 -1
  149. package/lib/module/sdkVersion.js +1 -1
  150. package/lib/module/specs/NativeHotUpdater.js.map +1 -1
  151. package/lib/module/updateError.js +126 -0
  152. package/lib/module/updateError.js.map +1 -0
  153. package/lib/module/updateError.spec.js +149 -0
  154. package/lib/module/updateError.spec.js.map +1 -0
  155. package/lib/module/wrap.js +43 -25
  156. package/lib/module/wrap.js.map +1 -1
  157. package/lib/module/wrap.progress.spec.js +196 -0
  158. package/lib/module/wrap.progress.spec.js.map +1 -0
  159. package/lib/module/wrap.spec.js +93 -229
  160. package/lib/module/wrap.spec.js.map +1 -1
  161. package/lib/typescript/commonjs/appReady.d.ts +23 -0
  162. package/lib/typescript/commonjs/appReady.d.ts.map +1 -0
  163. package/lib/typescript/commonjs/appReady.test-utils.d.ts +9 -0
  164. package/lib/typescript/commonjs/appReady.test-utils.d.ts.map +1 -0
  165. package/lib/typescript/commonjs/baseURL.d.ts +4 -0
  166. package/lib/typescript/commonjs/baseURL.d.ts.map +1 -0
  167. package/lib/typescript/commonjs/checkForUpdate.d.ts +15 -2
  168. package/lib/typescript/commonjs/checkForUpdate.d.ts.map +1 -1
  169. package/lib/typescript/commonjs/clientPlugin.d.ts +185 -0
  170. package/lib/typescript/commonjs/clientPlugin.d.ts.map +1 -0
  171. package/lib/typescript/commonjs/fetchJSON.d.ts +2 -3
  172. package/lib/typescript/commonjs/fetchJSON.d.ts.map +1 -1
  173. package/lib/typescript/commonjs/httpClient.d.ts +2 -30
  174. package/lib/typescript/commonjs/httpClient.d.ts.map +1 -1
  175. package/lib/typescript/commonjs/index.d.ts +3 -6
  176. package/lib/typescript/commonjs/index.d.ts.map +1 -1
  177. package/lib/typescript/commonjs/native.d.ts +29 -15
  178. package/lib/typescript/commonjs/native.d.ts.map +1 -1
  179. package/lib/typescript/commonjs/pluginHost.d.ts +29 -0
  180. package/lib/typescript/commonjs/pluginHost.d.ts.map +1 -0
  181. package/lib/typescript/commonjs/plugins/insights/eventId.d.ts +18 -0
  182. package/lib/typescript/commonjs/plugins/insights/eventId.d.ts.map +1 -0
  183. package/lib/typescript/commonjs/plugins/insights/index.d.ts +40 -0
  184. package/lib/typescript/commonjs/plugins/insights/index.d.ts.map +1 -0
  185. package/lib/typescript/commonjs/plugins/insights/sender.d.ts +74 -0
  186. package/lib/typescript/commonjs/plugins/insights/sender.d.ts.map +1 -0
  187. package/lib/typescript/commonjs/plugins/insights/state.d.ts +46 -0
  188. package/lib/typescript/commonjs/plugins/insights/state.d.ts.map +1 -0
  189. package/lib/typescript/commonjs/releaseCatalogCache.d.ts +5 -1
  190. package/lib/typescript/commonjs/releaseCatalogCache.d.ts.map +1 -1
  191. package/lib/typescript/commonjs/sdkVersion.d.ts +1 -1
  192. package/lib/typescript/commonjs/specs/NativeHotUpdater.d.ts +34 -12
  193. package/lib/typescript/commonjs/specs/NativeHotUpdater.d.ts.map +1 -1
  194. package/lib/typescript/commonjs/updateError.d.ts +26 -0
  195. package/lib/typescript/commonjs/updateError.d.ts.map +1 -0
  196. package/lib/typescript/commonjs/wrap.d.ts.map +1 -1
  197. package/lib/typescript/commonjs/wrap.types.d.ts +6 -5
  198. package/lib/typescript/commonjs/wrap.types.d.ts.map +1 -1
  199. package/lib/typescript/module/appReady.d.ts +23 -0
  200. package/lib/typescript/module/appReady.d.ts.map +1 -0
  201. package/lib/typescript/module/appReady.test-utils.d.ts +9 -0
  202. package/lib/typescript/module/appReady.test-utils.d.ts.map +1 -0
  203. package/lib/typescript/module/baseURL.d.ts +4 -0
  204. package/lib/typescript/module/baseURL.d.ts.map +1 -0
  205. package/lib/typescript/module/checkForUpdate.d.ts +15 -2
  206. package/lib/typescript/module/checkForUpdate.d.ts.map +1 -1
  207. package/lib/typescript/module/clientPlugin.d.ts +185 -0
  208. package/lib/typescript/module/clientPlugin.d.ts.map +1 -0
  209. package/lib/typescript/module/fetchJSON.d.ts +2 -3
  210. package/lib/typescript/module/fetchJSON.d.ts.map +1 -1
  211. package/lib/typescript/module/httpClient.d.ts +2 -30
  212. package/lib/typescript/module/httpClient.d.ts.map +1 -1
  213. package/lib/typescript/module/index.d.ts +3 -6
  214. package/lib/typescript/module/index.d.ts.map +1 -1
  215. package/lib/typescript/module/native.d.ts +29 -15
  216. package/lib/typescript/module/native.d.ts.map +1 -1
  217. package/lib/typescript/module/pluginHost.d.ts +29 -0
  218. package/lib/typescript/module/pluginHost.d.ts.map +1 -0
  219. package/lib/typescript/module/plugins/insights/eventId.d.ts +18 -0
  220. package/lib/typescript/module/plugins/insights/eventId.d.ts.map +1 -0
  221. package/lib/typescript/module/plugins/insights/index.d.ts +40 -0
  222. package/lib/typescript/module/plugins/insights/index.d.ts.map +1 -0
  223. package/lib/typescript/module/plugins/insights/sender.d.ts +74 -0
  224. package/lib/typescript/module/plugins/insights/sender.d.ts.map +1 -0
  225. package/lib/typescript/module/plugins/insights/state.d.ts +46 -0
  226. package/lib/typescript/module/plugins/insights/state.d.ts.map +1 -0
  227. package/lib/typescript/module/releaseCatalogCache.d.ts +5 -1
  228. package/lib/typescript/module/releaseCatalogCache.d.ts.map +1 -1
  229. package/lib/typescript/module/sdkVersion.d.ts +1 -1
  230. package/lib/typescript/module/specs/NativeHotUpdater.d.ts +34 -12
  231. package/lib/typescript/module/specs/NativeHotUpdater.d.ts.map +1 -1
  232. package/lib/typescript/module/updateError.d.ts +26 -0
  233. package/lib/typescript/module/updateError.d.ts.map +1 -0
  234. package/lib/typescript/module/wrap.d.ts.map +1 -1
  235. package/lib/typescript/module/wrap.types.d.ts +6 -5
  236. package/lib/typescript/module/wrap.types.d.ts.map +1 -1
  237. package/package.json +14 -2
  238. package/plugins/insights/package.json +8 -0
  239. package/src/appReady.spec.ts +393 -0
  240. package/src/{notifyAppReadyInsights.test-utils.ts → appReady.test-utils.ts} +7 -7
  241. package/src/appReady.ts +149 -0
  242. package/src/baseURL.ts +15 -0
  243. package/src/checkForUpdate.releaseCatalog.spec.ts +370 -76
  244. package/src/checkForUpdate.ts +135 -80
  245. package/src/clientPlugin.ts +231 -0
  246. package/src/entryImportGraph.spec.ts +65 -0
  247. package/src/fetchJSON.ts +3 -10
  248. package/src/httpClient.spec.ts +28 -9
  249. package/src/httpClient.ts +16 -109
  250. package/src/index.spec.ts +129 -36
  251. package/src/index.ts +67 -37
  252. package/src/native.spec.ts +98 -72
  253. package/src/native.ts +93 -77
  254. package/src/pluginHost.spec.ts +297 -0
  255. package/src/pluginHost.ts +262 -0
  256. package/src/plugins/insights/eventId.spec.ts +60 -0
  257. package/src/plugins/insights/eventId.ts +171 -0
  258. package/src/plugins/insights/index.ts +367 -0
  259. package/src/plugins/insights/insights.spec.ts +732 -0
  260. package/src/plugins/insights/sender.spec.ts +287 -0
  261. package/src/plugins/insights/sender.ts +221 -0
  262. package/src/plugins/insights/state.ts +184 -0
  263. package/src/releaseCatalogCache.spec.ts +22 -0
  264. package/src/releaseCatalogCache.ts +19 -4
  265. package/src/sdkVersion.ts +1 -1
  266. package/src/specs/NativeHotUpdater.ts +34 -13
  267. package/src/updateError.spec.ts +144 -0
  268. package/src/updateError.ts +153 -0
  269. package/src/wrap.progress.spec.ts +232 -0
  270. package/src/wrap.spec.ts +100 -283
  271. package/src/wrap.tsx +57 -26
  272. package/src/wrap.types.ts +6 -5
  273. package/lib/commonjs/notifyAppReadyInsights.boundary.spec.js +0 -225
  274. package/lib/commonjs/notifyAppReadyInsights.boundary.spec.js.map +0 -1
  275. package/lib/commonjs/notifyAppReadyInsights.js +0 -188
  276. package/lib/commonjs/notifyAppReadyInsights.js.map +0 -1
  277. package/lib/commonjs/notifyAppReadyInsights.spec.js +0 -378
  278. package/lib/commonjs/notifyAppReadyInsights.spec.js.map +0 -1
  279. package/lib/commonjs/notifyAppReadyInsights.test-utils.js.map +0 -1
  280. package/lib/commonjs/notifyAppReadyInsights.transport.spec.js +0 -124
  281. package/lib/commonjs/notifyAppReadyInsights.transport.spec.js.map +0 -1
  282. package/lib/module/notifyAppReadyInsights.boundary.spec.js +0 -224
  283. package/lib/module/notifyAppReadyInsights.boundary.spec.js.map +0 -1
  284. package/lib/module/notifyAppReadyInsights.js +0 -181
  285. package/lib/module/notifyAppReadyInsights.js.map +0 -1
  286. package/lib/module/notifyAppReadyInsights.spec.js +0 -377
  287. package/lib/module/notifyAppReadyInsights.spec.js.map +0 -1
  288. package/lib/module/notifyAppReadyInsights.test-utils.js.map +0 -1
  289. package/lib/module/notifyAppReadyInsights.transport.spec.js +0 -123
  290. package/lib/module/notifyAppReadyInsights.transport.spec.js.map +0 -1
  291. package/lib/typescript/commonjs/notifyAppReadyInsights.d.ts +0 -25
  292. package/lib/typescript/commonjs/notifyAppReadyInsights.d.ts.map +0 -1
  293. package/lib/typescript/commonjs/notifyAppReadyInsights.test-utils.d.ts +0 -8
  294. package/lib/typescript/commonjs/notifyAppReadyInsights.test-utils.d.ts.map +0 -1
  295. package/lib/typescript/module/notifyAppReadyInsights.d.ts +0 -25
  296. package/lib/typescript/module/notifyAppReadyInsights.d.ts.map +0 -1
  297. package/lib/typescript/module/notifyAppReadyInsights.test-utils.d.ts +0 -8
  298. package/lib/typescript/module/notifyAppReadyInsights.test-utils.d.ts.map +0 -1
  299. package/src/notifyAppReadyInsights.boundary.spec.ts +0 -242
  300. package/src/notifyAppReadyInsights.spec.ts +0 -362
  301. package/src/notifyAppReadyInsights.transport.spec.ts +0 -138
  302. package/src/notifyAppReadyInsights.ts +0 -293
@@ -1,242 +0,0 @@
1
- import { beforeEach, describe, expect, it, vi } from "vitest";
2
-
3
- import type {
4
- ActiveUpdateState,
5
- NotifyAppReadyInsightsEvent,
6
- NotifyAppReadyResult,
7
- } from "./native";
8
- import {
9
- createNotifyReadResult,
10
- stubNotifyFrame,
11
- } from "./notifyAppReadyInsights.test-utils";
12
-
13
- const platformState = vi.hoisted((): { OS: "ios" | "android" } => ({
14
- OS: "ios",
15
- }));
16
-
17
- vi.mock("react-native", () => ({
18
- NativeEventEmitter: class {},
19
- Platform: platformState,
20
- }));
21
-
22
- const nativePersistence = vi.hoisted(() => {
23
- let persistedInstallId = "install-persisted";
24
-
25
- return {
26
- getConstants: vi.fn(() => ({
27
- APP_VERSION: "1.0.0",
28
- CHANNEL: "production",
29
- DEFAULT_CHANNEL: "production",
30
- FINGERPRINT_HASH: null,
31
- MIN_BUNDLE_ID: "min-bundle-id",
32
- })),
33
- getInstallId: vi.fn(() => persistedInstallId),
34
- setPersistedInstallId: (installId: string) => {
35
- persistedInstallId = installId;
36
- },
37
- };
38
- });
39
-
40
- const mocks = vi.hoisted(() => ({
41
- addListener: vi.fn(() => () => {}),
42
- checkForUpdate: vi.fn(),
43
- getAppVersion: vi.fn<() => string | undefined>(() => "1.0.0"),
44
- getBundleId: vi.fn<() => string | undefined>(() => "bundle-id"),
45
- getChannel: vi.fn(() => "production"),
46
- getActiveUpdateState: vi.fn<() => ActiveUpdateState>(),
47
- getCohort: vi.fn(() => "123"),
48
- getFingerprintHash: vi.fn(() => "fingerprint-hash"),
49
- getInstallId: vi.fn<() => string | undefined>(() => "install-id"),
50
- getPersistedUserIdentity: vi.fn(() => ({})),
51
- readNotifyAppReady: vi.fn<
52
- () => {
53
- insightsEvent: NotifyAppReadyInsightsEvent | null;
54
- pending: boolean;
55
- result: NotifyAppReadyResult;
56
- }
57
- >(() => createNotifyReadResult()),
58
- reload: vi.fn(),
59
- }));
60
-
61
- vi.mock("./checkForUpdate", () => ({
62
- checkForUpdate: mocks.checkForUpdate,
63
- }));
64
-
65
- vi.mock("./native", () => ({
66
- addListener: mocks.addListener,
67
- getAppVersion: mocks.getAppVersion,
68
- getBundleId: mocks.getBundleId,
69
- getChannel: mocks.getChannel,
70
- getActiveUpdateState: mocks.getActiveUpdateState,
71
- getCohort: mocks.getCohort,
72
- getFingerprintHash: mocks.getFingerprintHash,
73
- getInstallId: mocks.getInstallId,
74
- getPersistedUserIdentity: mocks.getPersistedUserIdentity,
75
- readNotifyAppReady: mocks.readNotifyAppReady,
76
- reload: mocks.reload,
77
- }));
78
-
79
- vi.mock("./specs/NativeHotUpdater", () => ({
80
- default: nativePersistence,
81
- }));
82
-
83
- const createClient = () => {
84
- const sendInsightsEvent = vi.fn().mockResolvedValue(undefined);
85
- return {
86
- client: {
87
- createSession: vi.fn(async () => ({
88
- fetchReleaseCatalog: vi.fn(),
89
- resolveArtifact: vi.fn(),
90
- sendInsightsEvent,
91
- })),
92
- },
93
- sendInsightsEvent,
94
- };
95
- };
96
-
97
- describe("automatic notifyAppReady insights boundaries", () => {
98
- beforeEach(() => {
99
- vi.resetModules();
100
- vi.unstubAllGlobals();
101
- vi.useRealTimers();
102
- platformState.OS = "ios";
103
-
104
- for (const mock of Object.values(mocks)) {
105
- mock.mockReset();
106
- }
107
-
108
- mocks.addListener.mockReturnValue(() => {});
109
- mocks.getAppVersion.mockReturnValue("1.0.0");
110
- mocks.getBundleId.mockReturnValue("bundle-id");
111
- mocks.getChannel.mockReturnValue("production");
112
- mocks.getActiveUpdateState.mockReturnValue({
113
- activeSelection: null,
114
- stableSelection: null,
115
- verificationPending: false,
116
- });
117
- mocks.getCohort.mockReturnValue("123");
118
- mocks.getFingerprintHash.mockReturnValue("fingerprint-hash");
119
- mocks.getInstallId.mockReturnValue("install-id");
120
- mocks.getPersistedUserIdentity.mockReturnValue({});
121
- mocks.readNotifyAppReady.mockReturnValue(createNotifyReadResult());
122
- nativePersistence.getConstants.mockClear();
123
- nativePersistence.getInstallId.mockClear();
124
- nativePersistence.setPersistedInstallId("install-persisted");
125
- });
126
-
127
- it("warns when the private HTTP session fails and preserves readiness", async () => {
128
- stubNotifyFrame();
129
- const warn = vi.spyOn(console, "warn").mockImplementation(() => {});
130
- const onError = vi.fn();
131
- const onNotifyAppReady = vi.fn();
132
- const { init } = await import("./wrap");
133
-
134
- init({
135
- insights: true,
136
- client: {
137
- createSession: vi.fn(async () => {
138
- throw new Error("baseURL unavailable");
139
- }),
140
- },
141
- onError,
142
- onNotifyAppReady,
143
- });
144
- await vi.runOnlyPendingTimersAsync();
145
-
146
- expect(onError).not.toHaveBeenCalled();
147
- expect(onNotifyAppReady).toHaveBeenCalledWith({ status: "UNCHANGED" });
148
- expect(warn).toHaveBeenCalledWith(
149
- "[HotUpdater] Automatic notifyAppReady insights failed:",
150
- expect.objectContaining({
151
- message: "baseURL unavailable",
152
- }),
153
- );
154
- warn.mockRestore();
155
- });
156
-
157
- it.each([
158
- { label: "throws", value: new Error("native install id unavailable") },
159
- { label: "returns no identity", value: undefined },
160
- ])(
161
- "warns for a missing native install identity when it $label",
162
- async ({ value }) => {
163
- stubNotifyFrame();
164
- const warn = vi.spyOn(console, "warn").mockImplementation(() => {});
165
- const onError = vi.fn();
166
- const onNotifyAppReady = vi.fn();
167
- if (value instanceof Error) {
168
- mocks.getInstallId.mockImplementation(() => {
169
- throw value;
170
- });
171
- } else {
172
- mocks.getInstallId.mockReturnValue(value);
173
- }
174
- const { client, sendInsightsEvent } = createClient();
175
- const { init } = await import("./wrap");
176
-
177
- init({ insights: true, client, onError, onNotifyAppReady });
178
- await vi.runOnlyPendingTimersAsync();
179
-
180
- expect(sendInsightsEvent).not.toHaveBeenCalled();
181
- expect(onError).not.toHaveBeenCalled();
182
- expect(onNotifyAppReady).toHaveBeenCalledWith({ status: "UNCHANGED" });
183
- expect(warn).toHaveBeenCalledWith(
184
- "[HotUpdater] Automatic notifyAppReady insights failed:",
185
- expect.any(Error),
186
- );
187
- warn.mockRestore();
188
- },
189
- );
190
-
191
- it.each([
192
- { label: "throws", value: new Error("native bundle id unavailable") },
193
- { label: "returns no bundle", value: undefined },
194
- ])(
195
- "warns for a missing current bundle when getBundleId $label",
196
- async ({ value }) => {
197
- stubNotifyFrame();
198
- const warn = vi.spyOn(console, "warn").mockImplementation(() => {});
199
- const onError = vi.fn();
200
- const onNotifyAppReady = vi.fn();
201
- if (value instanceof Error) {
202
- mocks.getBundleId.mockImplementation(() => {
203
- throw value;
204
- });
205
- } else {
206
- mocks.getBundleId.mockReturnValue(value);
207
- }
208
- const { client, sendInsightsEvent } = createClient();
209
- const { init } = await import("./wrap");
210
-
211
- init({ insights: true, client, onError, onNotifyAppReady });
212
- await vi.runOnlyPendingTimersAsync();
213
-
214
- expect(sendInsightsEvent).not.toHaveBeenCalled();
215
- expect(onError).not.toHaveBeenCalled();
216
- expect(onNotifyAppReady).toHaveBeenCalledWith({ status: "UNCHANGED" });
217
- expect(warn).toHaveBeenCalledWith(
218
- "[HotUpdater] Automatic notifyAppReady insights failed:",
219
- expect.any(Error),
220
- );
221
- warn.mockRestore();
222
- },
223
- );
224
-
225
- it.each(["ios", "android"] as const)(
226
- "reads persisted install id through native.ts across JS module resets on %s",
227
- async (platform) => {
228
- platformState.OS = platform;
229
- nativePersistence.setPersistedInstallId("install-persisted");
230
- const native =
231
- await vi.importActual<typeof import("./native")>("./native");
232
-
233
- expect(native.getInstallId()).toBe("install-persisted");
234
- vi.resetModules();
235
- const nativeAfterReset =
236
- await vi.importActual<typeof import("./native")>("./native");
237
-
238
- expect(nativeAfterReset.getInstallId()).toBe("install-persisted");
239
- expect(nativePersistence.getInstallId).toHaveBeenCalledTimes(2);
240
- },
241
- );
242
- });
@@ -1,362 +0,0 @@
1
- import { beforeEach, describe, expect, it, vi } from "vitest";
2
-
3
- import type {
4
- ActiveUpdateState,
5
- NotifyAppReadyInsightsEvent,
6
- NotifyAppReadyResult,
7
- } from "./native";
8
- import {
9
- createNotifyReadResult,
10
- stubNotifyFrame,
11
- } from "./notifyAppReadyInsights.test-utils";
12
-
13
- vi.mock("react-native", () => ({
14
- Platform: { OS: "ios" },
15
- }));
16
-
17
- const mocks = vi.hoisted(() => ({
18
- addListener: vi.fn(() => () => {}),
19
- checkForUpdate: vi.fn(),
20
- getAppVersion: vi.fn(() => "1.0.0"),
21
- getBundleId: vi.fn(() => "bundle-id"),
22
- getChannel: vi.fn(() => "production"),
23
- getActiveUpdateState: vi.fn<() => ActiveUpdateState>(),
24
- getCohort: vi.fn(() => "123"),
25
- getFingerprintHash: vi.fn(() => "fingerprint-hash"),
26
- getInstallId: vi.fn(() => "install-id"),
27
- getPersistedUserIdentity: vi.fn(() => ({})),
28
- readNotifyAppReady: vi.fn<
29
- () => {
30
- insightsEvent: NotifyAppReadyInsightsEvent | null;
31
- pending: boolean;
32
- result: NotifyAppReadyResult;
33
- }
34
- >(() => createNotifyReadResult()),
35
- reload: vi.fn(),
36
- }));
37
-
38
- vi.mock("./checkForUpdate", () => ({
39
- checkForUpdate: mocks.checkForUpdate,
40
- }));
41
-
42
- vi.mock("./native", () => ({
43
- addListener: mocks.addListener,
44
- getAppVersion: mocks.getAppVersion,
45
- getBundleId: mocks.getBundleId,
46
- getChannel: mocks.getChannel,
47
- getActiveUpdateState: mocks.getActiveUpdateState,
48
- getCohort: mocks.getCohort,
49
- getFingerprintHash: mocks.getFingerprintHash,
50
- getInstallId: mocks.getInstallId,
51
- getPersistedUserIdentity: mocks.getPersistedUserIdentity,
52
- readNotifyAppReady: mocks.readNotifyAppReady,
53
- reload: mocks.reload,
54
- }));
55
-
56
- const createClient = () => {
57
- const sendInsightsEvent = vi.fn().mockResolvedValue(undefined);
58
- return {
59
- client: {
60
- createSession: vi.fn(async () => ({
61
- fetchReleaseCatalog: vi.fn(),
62
- resolveArtifact: vi.fn(),
63
- sendInsightsEvent,
64
- })),
65
- },
66
- sendInsightsEvent,
67
- };
68
- };
69
-
70
- describe("automatic notifyAppReady insights", () => {
71
- beforeEach(() => {
72
- vi.resetModules();
73
- vi.unstubAllGlobals();
74
- vi.useRealTimers();
75
-
76
- for (const mock of Object.values(mocks)) {
77
- mock.mockReset();
78
- }
79
-
80
- mocks.getAppVersion.mockReturnValue("1.0.0");
81
- mocks.addListener.mockReturnValue(() => {});
82
- mocks.getBundleId.mockReturnValue("bundle-id");
83
- mocks.getChannel.mockReturnValue("production");
84
- mocks.getActiveUpdateState.mockReturnValue({
85
- activeSelection: null,
86
- stableSelection: null,
87
- verificationPending: false,
88
- });
89
- mocks.getCohort.mockReturnValue("123");
90
- mocks.getFingerprintHash.mockReturnValue("fingerprint-hash");
91
- mocks.getInstallId.mockReturnValue("install-id");
92
- mocks.getPersistedUserIdentity.mockReturnValue({});
93
- mocks.readNotifyAppReady.mockReturnValue(createNotifyReadResult());
94
- });
95
-
96
- it.each([
97
- {
98
- label: "running selection",
99
- pending: false,
100
- channel: "production",
101
- expected: "release-running",
102
- },
103
- {
104
- label: "staged selection",
105
- pending: true,
106
- channel: "production",
107
- expected: "release-running",
108
- },
109
- {
110
- label: "another channel",
111
- pending: false,
112
- channel: "preview",
113
- expected: null,
114
- },
115
- ])(
116
- "attributes an unchanged launch with $label",
117
- async ({ pending, channel, expected }) => {
118
- const running = {
119
- kind: "BUNDLE" as const,
120
- releaseId: "release-running",
121
- bundleId: "bundle-id",
122
- channel,
123
- };
124
- mocks.getActiveUpdateState.mockReturnValue({
125
- activeSelection: pending
126
- ? {
127
- ...running,
128
- releaseId: "release-pending",
129
- bundleId: "bundle-pending",
130
- }
131
- : running,
132
- stableSelection: pending ? running : null,
133
- verificationPending: pending,
134
- });
135
- const { reportNoChange } = await import("./notifyAppReadyInsights");
136
- const { client, sendInsightsEvent } = createClient();
137
- await reportNoChange({ client, insights: true });
138
- expect(sendInsightsEvent).toHaveBeenCalledWith(
139
- expect.objectContaining({
140
- type: "UNCHANGED",
141
- toBundleId: "bundle-id",
142
- toReleaseId: expected,
143
- }),
144
- );
145
- },
146
- );
147
-
148
- it("orders download after in-flight startup reporting and suppresses a later no-change report", async () => {
149
- const { handleNotifyAppReady, reportBundleDownloaded, reportNoChange } =
150
- await import("./notifyAppReadyInsights");
151
- const { client, sendInsightsEvent } = createClient();
152
- let finishStartup!: () => void;
153
- sendInsightsEvent.mockImplementationOnce(
154
- () =>
155
- new Promise<void>((resolve) => {
156
- finishStartup = resolve;
157
- }),
158
- );
159
- const options = { client, insights: true };
160
- const startup = handleNotifyAppReady(options);
161
- await vi.waitFor(() => expect(sendInsightsEvent).toHaveBeenCalledOnce());
162
- const download = reportBundleDownloaded(options, {
163
- fromBundleId: "bundle-id",
164
- fromReleaseId: null,
165
- toBundleId: "next-bundle",
166
- toReleaseId: "next-release",
167
- channel: "production",
168
- updateStrategy: "appVersion",
169
- });
170
- await Promise.resolve();
171
- expect(sendInsightsEvent).toHaveBeenCalledOnce();
172
- finishStartup();
173
- await Promise.all([startup, download]);
174
- await reportNoChange(options);
175
- expect(sendInsightsEvent.mock.calls.map(([params]) => params.type)).toEqual(
176
- ["UNCHANGED", "UPDATE_DOWNLOADED"],
177
- );
178
- });
179
-
180
- it("reports selecting a previous download again after a different pending bundle", async () => {
181
- const { reportBundleDownloaded } = await import("./notifyAppReadyInsights");
182
- const { client, sendInsightsEvent } = createClient();
183
- const transition = {
184
- fromBundleId: "bundle-id",
185
- fromReleaseId: null,
186
- toBundleId: "next-bundle",
187
- toReleaseId: "next-release",
188
- channel: "production",
189
- updateStrategy: "appVersion" as const,
190
- };
191
- await reportBundleDownloaded({ client, insights: true }, transition);
192
- await reportBundleDownloaded({ client, insights: true }, transition);
193
- await reportBundleDownloaded(
194
- { client, insights: true },
195
- {
196
- ...transition,
197
- toBundleId: "other-bundle",
198
- toReleaseId: "other-release",
199
- },
200
- );
201
- await reportBundleDownloaded({ client, insights: true }, transition);
202
- expect(
203
- sendInsightsEvent.mock.calls.map(([params]) => params.toBundleId),
204
- ).toEqual(["next-bundle", "other-bundle", "next-bundle"]);
205
- });
206
-
207
- it("sends UPDATE_APPLIED with transition metadata and invokes readiness", async () => {
208
- stubNotifyFrame();
209
- mocks.getPersistedUserIdentity.mockReturnValue({
210
- userId: "user-123",
211
- username: "alice",
212
- });
213
- mocks.readNotifyAppReady.mockReturnValue(
214
- createNotifyReadResult(
215
- {
216
- fromBundleId: "bundle-a",
217
- status: "UPDATE_APPLIED",
218
- toBundleId: "bundle-b",
219
- },
220
- {
221
- fromBundleId: "bundle-a",
222
- toBundleId: "bundle-b",
223
- type: "UPDATE_APPLIED",
224
- updateStrategy: "fingerprint",
225
- },
226
- ),
227
- );
228
-
229
- const { client, sendInsightsEvent } = createClient();
230
- const onNotifyAppReady = vi.fn();
231
- const { init } = await import("./wrap");
232
-
233
- init({
234
- insights: true,
235
- onNotifyAppReady,
236
- requestHeaders: { Authorization: "Bearer token" },
237
- requestTimeout: 1000,
238
- client,
239
- });
240
- await vi.runOnlyPendingTimersAsync();
241
-
242
- expect(sendInsightsEvent).toHaveBeenCalledWith({
243
- appVersion: "1.0.0",
244
- channel: "production",
245
- cohort: "123",
246
- fingerprintHash: "fingerprint-hash",
247
- fromBundleId: "bundle-a",
248
- fromReleaseId: null,
249
- installId: "install-id",
250
- platform: "ios",
251
- requestHeaders: { Authorization: "Bearer token" },
252
- requestTimeout: 1000,
253
- toBundleId: "bundle-b",
254
- toReleaseId: null,
255
- type: "UPDATE_APPLIED",
256
- updateStrategy: "fingerprint",
257
- userId: "user-123",
258
- username: "alice",
259
- });
260
- expect(onNotifyAppReady).toHaveBeenCalledWith({
261
- fromBundleId: "bundle-a",
262
- status: "UPDATE_APPLIED",
263
- toBundleId: "bundle-b",
264
- });
265
- });
266
-
267
- it("sends RECOVERED with directional ids and invokes readiness", async () => {
268
- stubNotifyFrame();
269
- mocks.readNotifyAppReady.mockReturnValue(
270
- createNotifyReadResult(
271
- {
272
- fromBundleId: "bundle-b",
273
- status: "RECOVERED",
274
- toBundleId: "bundle-a",
275
- },
276
- {
277
- fromBundleId: "bundle-b",
278
- toBundleId: "bundle-a",
279
- type: "RECOVERED",
280
- updateStrategy: "appVersion",
281
- },
282
- ),
283
- );
284
- const { client, sendInsightsEvent } = createClient();
285
- const onNotifyAppReady = vi.fn();
286
- const { init } = await import("./wrap");
287
-
288
- init({ insights: true, client, onNotifyAppReady });
289
- await vi.runOnlyPendingTimersAsync();
290
-
291
- expect(sendInsightsEvent).toHaveBeenCalledWith({
292
- appVersion: "1.0.0",
293
- channel: "production",
294
- cohort: "123",
295
- fingerprintHash: "fingerprint-hash",
296
- fromBundleId: "bundle-b",
297
- fromReleaseId: null,
298
- installId: "install-id",
299
- platform: "ios",
300
- requestHeaders: undefined,
301
- requestTimeout: undefined,
302
- toBundleId: "bundle-a",
303
- toReleaseId: null,
304
- type: "RECOVERED",
305
- updateStrategy: "appVersion",
306
- });
307
- expect(onNotifyAppReady).toHaveBeenCalledWith({
308
- fromBundleId: "bundle-b",
309
- status: "RECOVERED",
310
- toBundleId: "bundle-a",
311
- });
312
- });
313
-
314
- it("sends one UNCHANGED event for repeated init calls", async () => {
315
- stubNotifyFrame();
316
- const { client, sendInsightsEvent } = createClient();
317
- const onNotifyAppReady = vi.fn();
318
- const { init } = await import("./wrap");
319
-
320
- init({ insights: true, client, onNotifyAppReady });
321
- init({ insights: true, client, onNotifyAppReady });
322
- await vi.runOnlyPendingTimersAsync();
323
-
324
- expect(sendInsightsEvent).toHaveBeenCalledTimes(1);
325
- expect(sendInsightsEvent).toHaveBeenCalledWith({
326
- appVersion: "1.0.0",
327
- channel: "production",
328
- cohort: "123",
329
- fingerprintHash: "fingerprint-hash",
330
- fromBundleId: null,
331
- fromReleaseId: null,
332
- installId: "install-id",
333
- platform: "ios",
334
- requestHeaders: undefined,
335
- requestTimeout: undefined,
336
- toBundleId: "bundle-id",
337
- toReleaseId: null,
338
- type: "UNCHANGED",
339
- updateStrategy: null,
340
- });
341
- expect(onNotifyAppReady).toHaveBeenCalledTimes(2);
342
- expect(onNotifyAppReady).toHaveBeenNthCalledWith(1, {
343
- status: "UNCHANGED",
344
- });
345
- expect(onNotifyAppReady).toHaveBeenNthCalledWith(2, {
346
- status: "UNCHANGED",
347
- });
348
- });
349
-
350
- it("skips automatic insights when disabled while preserving readiness", async () => {
351
- stubNotifyFrame();
352
- const { client, sendInsightsEvent } = createClient();
353
- const onNotifyAppReady = vi.fn();
354
- const { init } = await import("./wrap");
355
-
356
- init({ insights: false, client, onNotifyAppReady });
357
- await vi.runOnlyPendingTimersAsync();
358
-
359
- expect(sendInsightsEvent).not.toHaveBeenCalled();
360
- expect(onNotifyAppReady).toHaveBeenCalledWith({ status: "UNCHANGED" });
361
- });
362
- });