@hot-updater/react-native 1.0.0-rc.16 → 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 (316) 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 +18 -165
  52. package/lib/commonjs/httpClient.js.map +1 -1
  53. package/lib/commonjs/httpClient.spec.js +26 -199
  54. package/lib/commonjs/httpClient.spec.js.map +1 -1
  55. package/lib/commonjs/index.js +49 -36
  56. package/lib/commonjs/index.js.map +1 -1
  57. package/lib/commonjs/index.spec.js +108 -123
  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 +18 -165
  116. package/lib/module/httpClient.js.map +1 -1
  117. package/lib/module/httpClient.spec.js +27 -200
  118. package/lib/module/httpClient.spec.js.map +1 -1
  119. package/lib/module/index.js +44 -38
  120. package/lib/module/index.js.map +1 -1
  121. package/lib/module/index.spec.js +108 -123
  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 -36
  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 -10
  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 -36
  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 -10
  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 +30 -227
  249. package/src/httpClient.ts +20 -256
  250. package/src/index.spec.ts +117 -93
  251. package/src/index.ts +67 -52
  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 -12
  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 -171
  281. package/lib/commonjs/notifyAppReadyInsights.transport.spec.js.map +0 -1
  282. package/lib/commonjs/uuidv7.js +0 -41
  283. package/lib/commonjs/uuidv7.js.map +0 -1
  284. package/lib/commonjs/uuidv7.spec.js +0 -30
  285. package/lib/commonjs/uuidv7.spec.js.map +0 -1
  286. package/lib/module/notifyAppReadyInsights.boundary.spec.js +0 -224
  287. package/lib/module/notifyAppReadyInsights.boundary.spec.js.map +0 -1
  288. package/lib/module/notifyAppReadyInsights.js +0 -181
  289. package/lib/module/notifyAppReadyInsights.js.map +0 -1
  290. package/lib/module/notifyAppReadyInsights.spec.js +0 -377
  291. package/lib/module/notifyAppReadyInsights.spec.js.map +0 -1
  292. package/lib/module/notifyAppReadyInsights.test-utils.js.map +0 -1
  293. package/lib/module/notifyAppReadyInsights.transport.spec.js +0 -170
  294. package/lib/module/notifyAppReadyInsights.transport.spec.js.map +0 -1
  295. package/lib/module/uuidv7.js +0 -36
  296. package/lib/module/uuidv7.js.map +0 -1
  297. package/lib/module/uuidv7.spec.js +0 -30
  298. package/lib/module/uuidv7.spec.js.map +0 -1
  299. package/lib/typescript/commonjs/notifyAppReadyInsights.d.ts +0 -25
  300. package/lib/typescript/commonjs/notifyAppReadyInsights.d.ts.map +0 -1
  301. package/lib/typescript/commonjs/notifyAppReadyInsights.test-utils.d.ts +0 -8
  302. package/lib/typescript/commonjs/notifyAppReadyInsights.test-utils.d.ts.map +0 -1
  303. package/lib/typescript/commonjs/uuidv7.d.ts +0 -10
  304. package/lib/typescript/commonjs/uuidv7.d.ts.map +0 -1
  305. package/lib/typescript/module/notifyAppReadyInsights.d.ts +0 -25
  306. package/lib/typescript/module/notifyAppReadyInsights.d.ts.map +0 -1
  307. package/lib/typescript/module/notifyAppReadyInsights.test-utils.d.ts +0 -8
  308. package/lib/typescript/module/notifyAppReadyInsights.test-utils.d.ts.map +0 -1
  309. package/lib/typescript/module/uuidv7.d.ts +0 -10
  310. package/lib/typescript/module/uuidv7.d.ts.map +0 -1
  311. package/src/notifyAppReadyInsights.boundary.spec.ts +0 -242
  312. package/src/notifyAppReadyInsights.spec.ts +0 -362
  313. package/src/notifyAppReadyInsights.transport.spec.ts +0 -196
  314. package/src/notifyAppReadyInsights.ts +0 -293
  315. package/src/uuidv7.spec.ts +0 -25
  316. package/src/uuidv7.ts +0 -38
@@ -0,0 +1,208 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.hasPluginHook = exports.emitPluginHook = exports.dispatchPluginHook = exports.configurePlugins = exports.buildPluginEvent = void 0;
7
+ var _reactNative = require("react-native");
8
+ var _baseURL = require("./baseURL.js");
9
+ var _native = require("./native.js");
10
+ var _sdkVersion = require("./sdkVersion.js");
11
+ /** The init or wrap settings plugins see through their context. */
12
+
13
+ /** Storage values stay small, since native reads them on the JS thread. */
14
+ const MAX_STORAGE_VALUE_LENGTH = 64 * 1024;
15
+ let config = null;
16
+ /** Hooks by plugin, so a plugin configured again is not set up twice. */
17
+ const setUpPlugins = new WeakMap();
18
+ let activePlugins = [];
19
+ /** What plugins read and wrote, so a read follows a write before native does. */
20
+ const storageValues = new Map();
21
+ const reportHookError = (message, error) => {
22
+ const report = new Error(`[HotUpdater] ${message}`, {
23
+ cause: error
24
+ });
25
+ try {
26
+ if (config?.onError) {
27
+ config.onError(report);
28
+ return;
29
+ }
30
+ } catch {
31
+ // A throwing onError must not break the update path either.
32
+ }
33
+ console.warn(report.message, error);
34
+ };
35
+ const fetchFromServer = async (path, init = {}) => {
36
+ if (config === null) {
37
+ throw new Error("[HotUpdater] Plugins can fetch only after init or wrap.");
38
+ }
39
+ if (/^[a-z][a-z\d+.-]*:/i.test(path) || path.startsWith("//")) {
40
+ throw new TypeError("[HotUpdater] Plugin fetch takes a path relative to baseURL.");
41
+ }
42
+ const {
43
+ requestHeaders,
44
+ requestTimeout
45
+ } = config;
46
+ const url = `${await (0, _baseURL.resolveBaseURL)(config.baseURL)}/${path.replace(/^\/+/, "")}`;
47
+ const headers = new Headers(requestHeaders);
48
+ new Headers(init.headers).forEach((value, name) => {
49
+ headers.set(name, value);
50
+ });
51
+ const controller = new AbortController();
52
+ const callerSignal = init.signal;
53
+ const abortFromCaller = () => controller.abort();
54
+ if (callerSignal?.aborted) controller.abort();
55
+ callerSignal?.addEventListener("abort", abortFromCaller);
56
+ const timeoutId = setTimeout(() => controller.abort(), requestTimeout ?? 5000);
57
+ try {
58
+ return await fetch(url, {
59
+ ...init,
60
+ headers,
61
+ signal: controller.signal
62
+ });
63
+ } catch (error) {
64
+ if (error instanceof Error && error.name === "AbortError" && !callerSignal?.aborted) {
65
+ throw new Error("Request timed out");
66
+ }
67
+ throw error;
68
+ } finally {
69
+ clearTimeout(timeoutId);
70
+ callerSignal?.removeEventListener("abort", abortFromCaller);
71
+ }
72
+ };
73
+ const createStorage = pluginId => {
74
+ const scopedKey = key => {
75
+ if (typeof key !== "string" || key.length === 0) {
76
+ throw new TypeError("[HotUpdater] Plugin storage keys are non-empty strings.");
77
+ }
78
+ // Encoded, so no id and key pair can name another plugin's key.
79
+ return `plugins/${encodeURIComponent(pluginId)}/${key}`;
80
+ };
81
+ return {
82
+ get: key => {
83
+ const storageKey = scopedKey(key);
84
+ const cached = storageValues.get(storageKey);
85
+ if (cached !== undefined) return cached;
86
+ const value = (0, _native.getStorageItem)(storageKey);
87
+ storageValues.set(storageKey, value);
88
+ return value;
89
+ },
90
+ set: (key, value) => {
91
+ const storageKey = scopedKey(key);
92
+ if (value !== null && typeof value !== "string") {
93
+ throw new TypeError("[HotUpdater] Plugin storage values are strings or null.");
94
+ }
95
+ if (value !== null && value.length > MAX_STORAGE_VALUE_LENGTH) {
96
+ throw new RangeError("[HotUpdater] Plugin storage values are at most 64 KB.");
97
+ }
98
+ (0, _native.setStorageItem)(storageKey, value);
99
+ storageValues.set(storageKey, value);
100
+ }
101
+ };
102
+ };
103
+ const createContext = pluginId => ({
104
+ fetch: fetchFromServer,
105
+ get installId() {
106
+ return (0, _native.getInstallId)();
107
+ },
108
+ platform: _reactNative.Platform.OS === "android" ? "android" : "ios",
109
+ get appVersion() {
110
+ return (0, _native.getAppVersion)();
111
+ },
112
+ get sdkVersion() {
113
+ return _sdkVersion.HOT_UPDATER_SDK_VERSION;
114
+ },
115
+ isDebugBuild: typeof __DEV__ !== "undefined" && __DEV__,
116
+ getBundleId: _native.getBundleId,
117
+ getChannel: _native.getChannel,
118
+ getCohort: _native.getCohort,
119
+ getFingerprintHash: _native.getFingerprintHash,
120
+ storage: createStorage(pluginId),
121
+ now: () => Date.now()
122
+ });
123
+
124
+ /**
125
+ * Sets up the plugins of an init or wrap call. A plugin passed to an earlier
126
+ * call keeps its hooks, and a plugin left out stops receiving events.
127
+ */
128
+ const configurePlugins = (plugins, nextConfig) => {
129
+ const ids = new Set();
130
+ for (const plugin of plugins ?? []) {
131
+ if (typeof plugin.id !== "string" || plugin.id.length === 0) {
132
+ throw new Error("[HotUpdater] A plugin id must be a non-empty string.");
133
+ }
134
+ if (ids.has(plugin.id)) {
135
+ throw new Error(`[HotUpdater] Two plugins use the id "${plugin.id}". Plugin ids must be unique.`);
136
+ }
137
+ ids.add(plugin.id);
138
+ }
139
+ config = nextConfig;
140
+ activePlugins = (plugins ?? []).map(plugin => {
141
+ let hooks = setUpPlugins.get(plugin);
142
+ if (hooks === undefined) {
143
+ try {
144
+ hooks = plugin.setup(createContext(plugin.id)) ?? {};
145
+ } catch (error) {
146
+ reportHookError(`Plugin "${plugin.id}" failed in setup`, error);
147
+ hooks = {};
148
+ }
149
+ setUpPlugins.set(plugin, hooks);
150
+ }
151
+ return {
152
+ plugin,
153
+ hooks
154
+ };
155
+ });
156
+ };
157
+
158
+ /** Whether any plugin listens to this hook, so callers build events only when one does. */
159
+ exports.configurePlugins = configurePlugins;
160
+ const hasPluginHook = name => activePlugins.some(({
161
+ hooks
162
+ }) => typeof hooks[name] === "function");
163
+
164
+ /**
165
+ * Builds a hook's event when a plugin listens. A failure to build it is
166
+ * reported, not thrown, since reporting never changes an update.
167
+ */
168
+ exports.hasPluginHook = hasPluginHook;
169
+ const buildPluginEvent = (name, createPayload) => {
170
+ if (!hasPluginHook(name)) return null;
171
+ try {
172
+ return createPayload();
173
+ } catch (error) {
174
+ reportHookError(`Failed to build the ${name} event for plugins`, error);
175
+ return null;
176
+ }
177
+ };
178
+
179
+ /** Calls a hook on every plugin that listens, without waiting for any. */
180
+ exports.buildPluginEvent = buildPluginEvent;
181
+ const dispatchPluginHook = (name, payload) => {
182
+ for (const {
183
+ plugin,
184
+ hooks
185
+ } of activePlugins) {
186
+ const hook = hooks[name];
187
+ if (typeof hook !== "function") continue;
188
+ try {
189
+ const result = hook.call(hooks, payload);
190
+ if (result !== null && typeof result === "object" && typeof result.then === "function") {
191
+ void Promise.resolve(result).catch(error => {
192
+ reportHookError(`Plugin "${plugin.id}" failed in ${name}`, error);
193
+ });
194
+ }
195
+ } catch (error) {
196
+ reportHookError(`Plugin "${plugin.id}" failed in ${name}`, error);
197
+ }
198
+ }
199
+ };
200
+
201
+ /** Builds a hook's event when a plugin listens and calls the hook right away. */
202
+ exports.dispatchPluginHook = dispatchPluginHook;
203
+ const emitPluginHook = (name, createPayload) => {
204
+ const payload = buildPluginEvent(name, createPayload);
205
+ if (payload !== null) dispatchPluginHook(name, payload);
206
+ };
207
+ exports.emitPluginHook = emitPluginHook;
208
+ //# sourceMappingURL=pluginHost.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"names":["_reactNative","require","_baseURL","_native","_sdkVersion","MAX_STORAGE_VALUE_LENGTH","config","setUpPlugins","WeakMap","activePlugins","storageValues","Map","reportHookError","message","error","report","Error","cause","onError","console","warn","fetchFromServer","path","init","test","startsWith","TypeError","requestHeaders","requestTimeout","url","resolveBaseURL","baseURL","replace","headers","Headers","forEach","value","name","set","controller","AbortController","callerSignal","signal","abortFromCaller","abort","aborted","addEventListener","timeoutId","setTimeout","fetch","clearTimeout","removeEventListener","createStorage","pluginId","scopedKey","key","length","encodeURIComponent","get","storageKey","cached","undefined","getStorageItem","RangeError","setStorageItem","createContext","installId","getInstallId","platform","Platform","OS","appVersion","getAppVersion","sdkVersion","HOT_UPDATER_SDK_VERSION","isDebugBuild","__DEV__","getBundleId","getChannel","getCohort","getFingerprintHash","storage","now","Date","configurePlugins","plugins","nextConfig","ids","Set","plugin","id","has","add","map","hooks","setup","exports","hasPluginHook","some","buildPluginEvent","createPayload","dispatchPluginHook","payload","hook","result","call","then","Promise","resolve","catch","emitPluginHook"],"sourceRoot":"../../src","sources":["pluginHost.ts"],"mappings":";;;;;;AAAA,IAAAA,YAAA,GAAAC,OAAA;AAEA,IAAAC,QAAA,GAAAD,OAAA;AAOA,IAAAE,OAAA,GAAAF,OAAA;AAUA,IAAAG,WAAA,GAAAH,OAAA;AAQA;;AAQA;AACA,MAAMI,wBAAwB,GAAG,EAAE,GAAG,IAAI;AAE1C,IAAIC,MAA+B,GAAG,IAAI;AAC1C;AACA,MAAMC,YAAY,GAAG,IAAIC,OAAO,CAG9B,CAAC;AACH,IAAIC,aAGD,GAAG,EAAE;AACR;AACA,MAAMC,aAAa,GAAG,IAAIC,GAAG,CAAwB,CAAC;AAEtD,MAAMC,eAAe,GA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eAAe,CAAC,WAAW6E,MAAM,CAACC,EAAE,eAAerD,IAAI,EAAE,EAAEvB,KAAK,CAAC;QACnE,CAAC,CAAC;MACJ;IACF,CAAC,CAAC,OAAOA,KAAK,EAAE;MACdF,eAAe,CAAC,WAAW6E,MAAM,CAACC,EAAE,eAAerD,IAAI,EAAE,EAAEvB,KAAK,CAAC;IACnE;EACF;AACF,CAAC;;AAED;AAAAkF,OAAA,CAAAK,kBAAA,GAAAA,kBAAA;AACO,MAAMS,cAAc,GAAGA,CAC5BzE,IAAO,EACP+D,aAA0C,KACjC;EACT,MAAME,OAAO,GAAGH,gBAAgB,CAAC9D,IAAI,EAAE+D,aAAa,CAAC;EACrD,IAAIE,OAAO,KAAK,IAAI,EAAED,kBAAkB,CAAChE,IAAI,EAAEiE,OAAO,CAAC;AACzD,CAAC;AAACN,OAAA,CAAAc,cAAA,GAAAA,cAAA","ignoreList":[]}
@@ -0,0 +1,292 @@
1
+ "use strict";
2
+
3
+ var _vitest = require("vitest");
4
+ function _interopRequireWildcard(e, t) { if ("function" == typeof WeakMap) var r = new WeakMap(), n = new WeakMap(); return (_interopRequireWildcard = function (e, t) { if (!t && e && e.__esModule) return e; var o, i, f = { __proto__: null, default: e }; if (null === e || "object" != typeof e && "function" != typeof e) return f; if (o = t ? n : r) { if (o.has(e)) return o.get(e); o.set(e, f); } for (const t in e) "default" !== t && {}.hasOwnProperty.call(e, t) && ((i = (o = Object.defineProperty) && Object.getOwnPropertyDescriptor(e, t)) && (i.get || i.set) ? o(f, t, i) : f[t] = e[t]); return f; })(e, t); }
5
+ _vitest.vi.mock("react-native", () => ({
6
+ Platform: {
7
+ OS: "android"
8
+ }
9
+ }));
10
+ const mocks = _vitest.vi.hoisted(() => {
11
+ Reflect.set(globalThis, "HotUpdater", {
12
+ SDK_VERSION: "test-sdk-version"
13
+ });
14
+ return {
15
+ getAppVersion: _vitest.vi.fn(() => "1.2.3"),
16
+ getBundleId: _vitest.vi.fn(() => "bundle-id"),
17
+ getChannel: _vitest.vi.fn(() => "production"),
18
+ getCohort: _vitest.vi.fn(() => "123"),
19
+ getFingerprintHash: _vitest.vi.fn(() => null),
20
+ getInstallId: _vitest.vi.fn(() => "install-id"),
21
+ getStorageItem: _vitest.vi.fn(() => null),
22
+ setStorageItem: _vitest.vi.fn()
23
+ };
24
+ });
25
+ _vitest.vi.mock("./native", () => mocks);
26
+ const importHost = () => Promise.resolve().then(() => _interopRequireWildcard(require("./pluginHost")));
27
+ const capture = (id = "example") => {
28
+ let context;
29
+ const setup = _vitest.vi.fn(pluginContext => {
30
+ context = pluginContext;
31
+ });
32
+ const plugin = {
33
+ id,
34
+ setup
35
+ };
36
+ return {
37
+ plugin,
38
+ setup,
39
+ context: () => context
40
+ };
41
+ };
42
+ (0, _vitest.describe)("client plugin host", () => {
43
+ (0, _vitest.beforeEach)(() => {
44
+ _vitest.vi.resetModules();
45
+ for (const mock of Object.values(mocks)) mock.mockClear();
46
+ mocks.getStorageItem.mockReturnValue(null);
47
+ });
48
+ (0, _vitest.afterEach)(() => {
49
+ _vitest.vi.useRealTimers();
50
+ _vitest.vi.unstubAllGlobals();
51
+ _vitest.vi.restoreAllMocks();
52
+ });
53
+ (0, _vitest.it)("throws at configuration for two plugins with one id", async () => {
54
+ const {
55
+ configurePlugins
56
+ } = await importHost();
57
+ (0, _vitest.expect)(() => configurePlugins([capture("same").plugin, capture("same").plugin], {
58
+ baseURL: "https://updates.example.com"
59
+ })).toThrow('Two plugins use the id "same"');
60
+ });
61
+ (0, _vitest.it)("sets a plugin up once and stops calling a plugin left out", async () => {
62
+ const {
63
+ configurePlugins,
64
+ emitPluginHook
65
+ } = await importHost();
66
+ const onAppReady = _vitest.vi.fn();
67
+ const plugin = {
68
+ id: "example",
69
+ setup: _vitest.vi.fn(() => ({
70
+ onAppReady
71
+ }))
72
+ };
73
+ const config = {
74
+ baseURL: "https://updates.example.com"
75
+ };
76
+ configurePlugins([plugin], config);
77
+ configurePlugins([plugin], config);
78
+ emitPluginHook("onAppReady", () => ({
79
+ status: "UNCHANGED",
80
+ channel: "production",
81
+ bundleId: "bundle-id",
82
+ releaseId: null,
83
+ previousProcessExit: null
84
+ }));
85
+ configurePlugins([], config);
86
+ emitPluginHook("onAppReady", () => ({
87
+ status: "UNCHANGED",
88
+ channel: "production",
89
+ bundleId: "bundle-id",
90
+ releaseId: null,
91
+ previousProcessExit: null
92
+ }));
93
+ (0, _vitest.expect)(plugin.setup).toHaveBeenCalledOnce();
94
+ (0, _vitest.expect)(onAppReady).toHaveBeenCalledOnce();
95
+ });
96
+ (0, _vitest.it)("warns without onError when setup throws, and keeps other plugins", async () => {
97
+ const warn = _vitest.vi.spyOn(console, "warn").mockImplementation(() => {});
98
+ const {
99
+ configurePlugins
100
+ } = await importHost();
101
+ const healthy = capture("healthy");
102
+ configurePlugins([{
103
+ id: "broken",
104
+ setup: () => {
105
+ throw new Error("setup failed");
106
+ }
107
+ }, healthy.plugin], {
108
+ baseURL: "https://updates.example.com"
109
+ });
110
+ (0, _vitest.expect)(healthy.setup).toHaveBeenCalledOnce();
111
+ (0, _vitest.expect)(warn).toHaveBeenCalledWith('[HotUpdater] Plugin "broken" failed in setup', _vitest.expect.objectContaining({
112
+ message: "setup failed"
113
+ }));
114
+ });
115
+ (0, _vitest.it)("never waits for a hook", async () => {
116
+ const {
117
+ configurePlugins,
118
+ emitPluginHook
119
+ } = await importHost();
120
+ const onUpdateCheck = _vitest.vi.fn(() => new Promise(() => {}));
121
+ configurePlugins([{
122
+ id: "slow",
123
+ setup: () => ({
124
+ onUpdateCheck
125
+ })
126
+ }], {
127
+ baseURL: "https://updates.example.com"
128
+ });
129
+ const result = emitPluginHook("onUpdateCheck", () => ({
130
+ status: "UNCHANGED",
131
+ channel: "production",
132
+ bundleId: "bundle-id",
133
+ releaseId: null,
134
+ previousReleaseId: null
135
+ }));
136
+ (0, _vitest.expect)(result).toBeUndefined();
137
+ (0, _vitest.expect)(onUpdateCheck).toHaveBeenCalledOnce();
138
+ });
139
+ (0, _vitest.it)("builds an event only when a plugin listens", async () => {
140
+ const {
141
+ configurePlugins,
142
+ emitPluginHook
143
+ } = await importHost();
144
+ configurePlugins([capture().plugin], {
145
+ baseURL: "https://updates.example.com"
146
+ });
147
+ const createPayload = _vitest.vi.fn(() => null);
148
+ emitPluginHook("onUpdateError", createPayload);
149
+ (0, _vitest.expect)(createPayload).not.toHaveBeenCalled();
150
+ });
151
+ (0, _vitest.it)("exposes the app's identity and environment", async () => {
152
+ _vitest.vi.stubGlobal("__DEV__", true);
153
+ _vitest.vi.spyOn(Date, "now").mockReturnValue(1_700_000_000_000);
154
+ const {
155
+ configurePlugins
156
+ } = await importHost();
157
+ const plugin = capture();
158
+ configurePlugins([plugin.plugin], {
159
+ baseURL: "https://updates.example.com"
160
+ });
161
+ const context = plugin.context();
162
+ (0, _vitest.expect)({
163
+ appVersion: context.appVersion,
164
+ bundleId: context.getBundleId(),
165
+ channel: context.getChannel(),
166
+ cohort: context.getCohort(),
167
+ fingerprintHash: context.getFingerprintHash(),
168
+ installId: context.installId,
169
+ isDebugBuild: context.isDebugBuild,
170
+ now: context.now(),
171
+ platform: context.platform,
172
+ sdkVersion: context.sdkVersion
173
+ }).toEqual({
174
+ appVersion: "1.2.3",
175
+ bundleId: "bundle-id",
176
+ channel: "production",
177
+ cohort: "123",
178
+ fingerprintHash: null,
179
+ installId: "install-id",
180
+ isDebugBuild: true,
181
+ now: 1_700_000_000_000,
182
+ platform: "android",
183
+ sdkVersion: "test-sdk-version"
184
+ });
185
+ });
186
+ (0, _vitest.describe)("fetch", () => {
187
+ (0, _vitest.it)("requests a path under the resolved baseURL with the SDK's headers", async () => {
188
+ const fetchMock = _vitest.vi.fn(async () => new Response(null, {
189
+ status: 204
190
+ }));
191
+ _vitest.vi.stubGlobal("fetch", fetchMock);
192
+ const {
193
+ configurePlugins
194
+ } = await importHost();
195
+ const plugin = capture();
196
+ configurePlugins([plugin.plugin], {
197
+ baseURL: async () => "https://updates.example.com/hot-updater/",
198
+ requestHeaders: {
199
+ "x-api-key": "client-key",
200
+ "X-Shared": "sdk"
201
+ }
202
+ });
203
+ await plugin.context().fetch("/events", {
204
+ headers: {
205
+ "Content-Type": "application/json",
206
+ "X-Shared": "plugin"
207
+ },
208
+ method: "POST"
209
+ });
210
+ const [url, init] = fetchMock.mock.calls[0];
211
+ (0, _vitest.expect)(url).toBe("https://updates.example.com/hot-updater/events");
212
+ (0, _vitest.expect)(init?.method).toBe("POST");
213
+ const headers = new Headers(init?.headers);
214
+ (0, _vitest.expect)(headers.get("x-api-key")).toBe("client-key");
215
+ (0, _vitest.expect)(headers.get("content-type")).toBe("application/json");
216
+ (0, _vitest.expect)(headers.get("x-shared")).toBe("plugin");
217
+ });
218
+ (0, _vitest.it)("rejects with Request timed out after the SDK's timeout", async () => {
219
+ _vitest.vi.useFakeTimers();
220
+ _vitest.vi.stubGlobal("fetch", _vitest.vi.fn((_input, init) => new Promise((_resolve, reject) => {
221
+ init?.signal?.addEventListener("abort", () => {
222
+ reject(Object.assign(new Error("aborted"), {
223
+ name: "AbortError"
224
+ }));
225
+ });
226
+ })));
227
+ const {
228
+ configurePlugins
229
+ } = await importHost();
230
+ const plugin = capture();
231
+ configurePlugins([plugin.plugin], {
232
+ baseURL: "https://updates.example.com",
233
+ requestTimeout: 2_000
234
+ });
235
+ const request = plugin.context().fetch("events");
236
+ const settled = (0, _vitest.expect)(request).rejects.toThrow("Request timed out");
237
+ await _vitest.vi.advanceTimersByTimeAsync(2_000);
238
+ await settled;
239
+ });
240
+ (0, _vitest.it)("refuses a URL outside baseURL", async () => {
241
+ const {
242
+ configurePlugins
243
+ } = await importHost();
244
+ const plugin = capture();
245
+ configurePlugins([plugin.plugin], {
246
+ baseURL: "https://updates.example.com"
247
+ });
248
+ await (0, _vitest.expect)(plugin.context().fetch("https://elsewhere.example.com/events")).rejects.toThrow("relative to baseURL");
249
+ });
250
+ });
251
+ (0, _vitest.describe)("storage", () => {
252
+ (0, _vitest.it)("scopes keys to the plugin and reads its own writes", async () => {
253
+ mocks.getStorageItem.mockReturnValue("from-native");
254
+ const {
255
+ configurePlugins
256
+ } = await importHost();
257
+ const plugin = capture("example");
258
+ configurePlugins([plugin.plugin], {
259
+ baseURL: "https://updates.example.com"
260
+ });
261
+ const {
262
+ storage
263
+ } = plugin.context();
264
+ (0, _vitest.expect)(storage.get("state")).toBe("from-native");
265
+ (0, _vitest.expect)(storage.get("state")).toBe("from-native");
266
+ storage.set("state", "next");
267
+ (0, _vitest.expect)(storage.get("state")).toBe("next");
268
+ storage.set("state", null);
269
+ (0, _vitest.expect)(storage.get("state")).toBeNull();
270
+ (0, _vitest.expect)(mocks.getStorageItem).toHaveBeenCalledOnce();
271
+ (0, _vitest.expect)(mocks.getStorageItem).toHaveBeenCalledWith("plugins/example/state");
272
+ (0, _vitest.expect)(mocks.setStorageItem.mock.calls).toEqual([["plugins/example/state", "next"], ["plugins/example/state", null]]);
273
+ });
274
+ (0, _vitest.it)("refuses empty keys, non-string values, and values over 64 KB", async () => {
275
+ const {
276
+ configurePlugins
277
+ } = await importHost();
278
+ const plugin = capture();
279
+ configurePlugins([plugin.plugin], {
280
+ baseURL: "https://updates.example.com"
281
+ });
282
+ const {
283
+ storage
284
+ } = plugin.context();
285
+ (0, _vitest.expect)(() => storage.get("")).toThrow("non-empty strings");
286
+ (0, _vitest.expect)(() => storage.set("key", 1)).toThrow("strings or null");
287
+ (0, _vitest.expect)(() => storage.set("key", "x".repeat(64 * 1024 + 1))).toThrow("at most 64 KB");
288
+ (0, _vitest.expect)(mocks.setStorageItem).not.toHaveBeenCalled();
289
+ });
290
+ });
291
+ });
292
+ //# sourceMappingURL=pluginHost.spec.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"names":["_vitest","require","_interopRequireWildcard","e","t","WeakMap","r","n","__esModule","o","i","f","__proto__","default","has","get","set","hasOwnProperty","call","Object","defineProperty","getOwnPropertyDescriptor","vi","mock","Platform","OS","mocks","hoisted","Reflect","globalThis","SDK_VERSION","getAppVersion","fn","getBundleId","getChannel","getCohort","getFingerprintHash","getInstallId","getStorageItem","setStorageItem","importHost","Promise","resolve","then","capture","id","context","setup","pluginContext","plugin","describe","beforeEach","resetModules","values","mockClear","mockReturnValue","afterEach","useRealTimers","unstubAllGlobals","restoreAllMocks","it","configurePlugins","expect","baseURL","toThrow","emitPluginHook","onAppReady","config","status","channel","bundleId","releaseId","previousProcessExit","toHaveBeenCalledOnce","warn","spyOn","console","mockImplementation","healthy","Error","toHaveBeenCalledWith","objectContaining","message","onUpdateCheck","result","previousReleaseId","toBeUndefined","createPayload","not","toHaveBeenCalled","stubGlobal","Date","appVersion","cohort","fingerprintHash","installId","isDebugBuild","now","platform","sdkVersion","toEqual","fetchMock","Response","requestHeaders","fetch","headers","method","url","init","calls","toBe","Headers","useFakeTimers","_input","_resolve","reject","signal","addEventListener","assign","name","requestTimeout","request","settled","rejects","advanceTimersByTimeAsync","storage","toBeNull","repeat"],"sourceRoot":"../../src","sources":["pluginHost.spec.ts"],"mappings":";;AAAA,IAAAA,OAAA,GAAAC,OAAA;AAAyE,SAAAC,wBAAAC,CAAA,EAAAC,CAAA,6BAAAC,OAAA,MAAAC,CAAA,OAAAD,OAAA,IAAAE,CAAA,OAAAF,OAAA,YAAAH,uBAAA,YAAAA,CAAAC,CAAA,EAAAC,CAAA,SAAAA,CAAA,IAAAD,CAAA,IAAAA,CAAA,CAAAK,UAAA,SAAAL,CAAA,MAAAM,CAAA,EAAAC,CAAA,EAAAC,CAAA,KAAAC,SAAA,QAAAC,OAAA,EAAAV,CAAA,iBAAAA,CAAA,uBAAAA,CAAA,yBAAAA,CAAA,SAAAQ,CAAA,MAAAF,CAAA,GAAAL,CAAA,GAAAG,CAAA,GAAAD,CAAA,QAAAG,CAAA,CAAAK,GAAA,CAAAX,CAAA,UAAAM,CAAA,CAAAM,GAAA,CAAAZ,CAAA,GAAAM,CAAA,CAAAO,GAAA,CAAAb,CAAA,EAAAQ,CAAA,gBAAAP,CAAA,IAAAD,CAAA,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CAAC,uBAAuB,EAAE,IAAI,CAAC,CAChC,CAAC;IACJ,CAAC,CAAC;IAEF,IAAAxC,UAAE,EAAC,8DAA8D,EAAE,YAAY;MAC7E,MAAM;QAAEC;MAAiB,CAAC,GAAG,MAAMrB,UAAU,CAAC,CAAC;MAC/C,MAAMS,MAAM,GAAGL,OAAO,CAAC,CAAC;MACxBiB,gBAAgB,CAAC,CAACZ,MAAM,CAACA,MAAM,CAAC,EAAE;QAChCc,OAAO,EAAE;MACX,CAAC,CAAC;MACF,MAAM;QAAE8D;MAAQ,CAAC,GAAG5E,MAAM,CAACH,OAAO,CAAC,CAAC;MAEpC,IAAAgB,cAAM,EAAC,MAAM+D,OAAO,CAAC9G,GAAG,CAAC,EAAE,CAAC,CAAC,CAACiD,OAAO,CAAC,mBAAmB,CAAC;MAC1D,IAAAF,cAAM,EAAC,MAAM+D,OAAO,CAAC7G,GAAG,CAAC,KAAK,EAAE,CAAsB,CAAC,CAAC,CAACgD,OAAO,CAC9D,iBACF,CAAC;MACD,IAAAF,cAAM,EAAC,MAAM+D,OAAO,CAAC7G,GAAG,CAAC,KAAK,EAAE,GAAG,CAAC+G,MAAM,CAAC,EAAE,GAAG,IAAI,GAAG,CAAC,CAAC,CAAC,CAAC,CAAC/D,OAAO,CACjE,eACF,CAAC;MACD,IAAAF,cAAM,EAACpC,KAAK,CAACa,cAAc,CAAC,CAACiD,GAAG,CAACC,gBAAgB,CAAC,CAAC;IACrD,CAAC,CAAC;EACJ,CAAC,CAAC;AACJ,CAAC,CAAC","ignoreList":[]}
@@ -0,0 +1,129 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.sha256 = exports.createUUIDv7 = exports.createKeyedUUIDv7 = void 0;
7
+ const formatUUIDv7 = (bytes, timestamp) => {
8
+ // Division, not bit shifts: shifts truncate to 32 bits, and a millisecond
9
+ // timestamp already needs 41.
10
+ let time = timestamp;
11
+ for (let index = 5; index >= 0; index -= 1) {
12
+ bytes[index] = time % 256;
13
+ time = Math.floor(time / 256);
14
+ }
15
+ bytes[6] = 0x70 | bytes[6] & 0x0f;
16
+ bytes[8] = 0x80 | bytes[8] & 0x3f;
17
+ const hex = Array.from(bytes, byte => byte.toString(16).padStart(2, "0")).join("");
18
+ return `${hex.slice(0, 8)}-${hex.slice(8, 12)}-${hex.slice(12, 16)}-${hex.slice(16, 20)}-${hex.slice(20)}`;
19
+ };
20
+
21
+ /**
22
+ * Creates an RFC 9562 UUIDv7: a 48-bit millisecond timestamp, then random bits.
23
+ *
24
+ * `createUUIDv7` from `@hot-updater/plugin-core` calls `crypto.getRandomValues`
25
+ * unconditionally, but React Native has no Web Crypto unless the app installs a
26
+ * polyfill. An Insights event ID only has to tell one event from another so a
27
+ * retried POST is counted once, so `Math.random` is enough without one.
28
+ */
29
+ const createUUIDv7 = () => {
30
+ const bytes = new Uint8Array(16);
31
+ const {
32
+ crypto
33
+ } = globalThis;
34
+ if (typeof crypto?.getRandomValues === "function") {
35
+ crypto.getRandomValues(bytes);
36
+ } else {
37
+ for (let index = 0; index < bytes.length; index += 1) {
38
+ bytes[index] = Math.floor(Math.random() * 256);
39
+ }
40
+ }
41
+ return formatUUIDv7(bytes, Date.now());
42
+ };
43
+ exports.createUUIDv7 = createUUIDv7;
44
+ const SHA256_K = [0x428a2f98, 0x71374491, 0xb5c0fbcf, 0xe9b5dba5, 0x3956c25b, 0x59f111f1, 0x923f82a4, 0xab1c5ed5, 0xd807aa98, 0x12835b01, 0x243185be, 0x550c7dc3, 0x72be5d74, 0x80deb1fe, 0x9bdc06a7, 0xc19bf174, 0xe49b69c1, 0xefbe4786, 0x0fc19dc6, 0x240ca1cc, 0x2de92c6f, 0x4a7484aa, 0x5cb0a9dc, 0x76f988da, 0x983e5152, 0xa831c66d, 0xb00327c8, 0xbf597fc7, 0xc6e00bf3, 0xd5a79147, 0x06ca6351, 0x14292967, 0x27b70a85, 0x2e1b2138, 0x4d2c6dfc, 0x53380d13, 0x650a7354, 0x766a0abb, 0x81c2c92e, 0x92722c85, 0xa2bfe8a1, 0xa81a664b, 0xc24b8b70, 0xc76c51a3, 0xd192e819, 0xd6990624, 0xf40e3585, 0x106aa070, 0x19a4c116, 0x1e376c08, 0x2748774c, 0x34b0bcb5, 0x391c0cb3, 0x4ed8aa4a, 0x5b9cca4f, 0x682e6ff3, 0x748f82ee, 0x78a5636f, 0x84c87814, 0x8cc70208, 0x90befffa, 0xa4506ceb, 0xbef9a3f7, 0xc67178f2];
45
+ const encodeUtf8 = value => {
46
+ const bytes = [];
47
+ for (const character of value) {
48
+ const code = character.codePointAt(0);
49
+ if (code < 0x80) {
50
+ bytes.push(code);
51
+ } else if (code < 0x800) {
52
+ bytes.push(0xc0 | code >> 6, 0x80 | code & 0x3f);
53
+ } else if (code < 0x10000) {
54
+ bytes.push(0xe0 | code >> 12, 0x80 | code >> 6 & 0x3f, 0x80 | code & 0x3f);
55
+ } else {
56
+ bytes.push(0xf0 | code >> 18, 0x80 | code >> 12 & 0x3f, 0x80 | code >> 6 & 0x3f, 0x80 | code & 0x3f);
57
+ }
58
+ }
59
+ return bytes;
60
+ };
61
+
62
+ /** SHA-256 of a string's UTF-8 bytes, since React Native has no Web Crypto. */
63
+ const sha256 = value => {
64
+ const bytes = encodeUtf8(value);
65
+ const bitLength = bytes.length * 8;
66
+ bytes.push(0x80);
67
+ while (bytes.length % 64 !== 56) bytes.push(0);
68
+ for (let shift = 56; shift >= 0; shift -= 8) {
69
+ // The length's high word, as division, since shifts truncate to 32 bits.
70
+ bytes.push(shift >= 32 ? Math.floor(bitLength / 2 ** shift) & 0xff : bitLength >>> shift & 0xff);
71
+ }
72
+ const hash = [0x6a09e667, 0xbb67ae85, 0x3c6ef372, 0xa54ff53a, 0x510e527f, 0x9b05688c, 0x1f83d9ab, 0x5be0cd19];
73
+ const words = Array.from({
74
+ length: 64
75
+ }, () => 0);
76
+ const rotate = (word, bits) => word >>> bits | word << 32 - bits;
77
+ for (let offset = 0; offset < bytes.length; offset += 64) {
78
+ for (let index = 0; index < 16; index += 1) {
79
+ const at = offset + index * 4;
80
+ words[index] = bytes[at] << 24 | bytes[at + 1] << 16 | bytes[at + 2] << 8 | bytes[at + 3];
81
+ }
82
+ for (let index = 16; index < 64; index += 1) {
83
+ const low = words[index - 15];
84
+ const high = words[index - 2];
85
+ const s0 = rotate(low, 7) ^ rotate(low, 18) ^ low >>> 3;
86
+ const s1 = rotate(high, 17) ^ rotate(high, 19) ^ high >>> 10;
87
+ words[index] = words[index - 16] + s0 + words[index - 7] + s1 | 0;
88
+ }
89
+ let [a, b, c, d, e, f, g, h] = hash;
90
+ for (let index = 0; index < 64; index += 1) {
91
+ const s1 = rotate(e, 6) ^ rotate(e, 11) ^ rotate(e, 25);
92
+ const choose = e & f ^ ~e & g;
93
+ const temp1 = h + s1 + choose + SHA256_K[index] + words[index] | 0;
94
+ const s0 = rotate(a, 2) ^ rotate(a, 13) ^ rotate(a, 22);
95
+ const majority = a & b ^ a & c ^ b & c;
96
+ const temp2 = s0 + majority | 0;
97
+ h = g;
98
+ g = f;
99
+ f = e;
100
+ e = d + temp1 | 0;
101
+ d = c;
102
+ c = b;
103
+ b = a;
104
+ a = temp1 + temp2 | 0;
105
+ }
106
+ const results = [a, b, c, d, e, f, g, h];
107
+ for (let index = 0; index < 8; index += 1) {
108
+ hash[index] = hash[index] + results[index] | 0;
109
+ }
110
+ }
111
+ const digest = new Uint8Array(32);
112
+ hash.forEach((word, index) => {
113
+ digest[index * 4] = word >>> 24 & 0xff;
114
+ digest[index * 4 + 1] = word >>> 16 & 0xff;
115
+ digest[index * 4 + 2] = word >>> 8 & 0xff;
116
+ digest[index * 4 + 3] = word & 0xff;
117
+ });
118
+ return digest;
119
+ };
120
+
121
+ /**
122
+ * A UUIDv7 derived from a key: its time field is `timestamp` and its random
123
+ * bits are the key's SHA-256, so the same key and time always give the same
124
+ * id, and a server that stores reports by id counts it once.
125
+ */
126
+ exports.sha256 = sha256;
127
+ const createKeyedUUIDv7 = (key, timestamp) => formatUUIDv7(sha256(key).slice(0, 16), timestamp);
128
+ exports.createKeyedUUIDv7 = createKeyedUUIDv7;
129
+ //# sourceMappingURL=eventId.js.map