@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.
- package/android/src/main/java/com/hotupdater/BundleFileStorageService.kt +491 -388
- package/android/src/main/java/com/hotupdater/BundleMetadata.kt +5 -11
- package/android/src/main/java/com/hotupdater/FileManagerService.kt +45 -0
- package/android/src/main/java/com/hotupdater/HotUpdaterException.kt +290 -12
- package/android/src/main/java/com/hotupdater/HotUpdaterImpl.kt +35 -19
- package/android/src/main/java/com/hotupdater/InstallIdentityService.kt +37 -0
- package/android/src/main/java/com/hotupdater/KeyValueStorageService.kt +86 -0
- package/android/src/main/java/com/hotupdater/NetworkState.kt +31 -0
- package/android/src/main/java/com/hotupdater/NoBackupStorage.kt +17 -0
- package/android/src/main/java/com/hotupdater/OkHttpDownloadService.kt +110 -52
- package/android/src/main/java/com/hotupdater/PreviousProcessExit.kt +89 -0
- package/android/src/main/java/com/hotupdater/ReactNativeValueConverters.kt +34 -0
- package/android/src/newarch/HotUpdaterModule.kt +74 -69
- package/android/src/oldarch/HotUpdaterModule.kt +63 -59
- package/android/src/oldarch/HotUpdaterSpec.kt +4 -6
- package/android/src/test/java/com/hotupdater/BsdiffPatchTest.kt +1 -1
- package/android/src/test/java/com/hotupdater/BundleFileStorageServiceTest.kt +446 -61
- package/android/src/test/java/com/hotupdater/HotUpdaterExceptionTest.kt +220 -0
- package/android/src/test/java/com/hotupdater/HotUpdaterImplTest.kt +19 -27
- package/android/src/test/java/com/hotupdater/InstallIdentityServiceTest.kt +71 -0
- package/android/src/test/java/com/hotupdater/KeyValueStorageServiceTest.kt +106 -0
- package/android/src/test/java/com/hotupdater/NoBackupContext.kt +11 -0
- package/android/src/test/java/com/hotupdater/OkHttpDownloadServiceTest.kt +309 -23
- package/android/src/test/java/com/hotupdater/PreviousProcessExitTest.kt +57 -0
- package/ios/HotUpdater/Internal/BundleFileStorageService.swift +238 -157
- package/ios/HotUpdater/Internal/BundleMetadata.swift +3 -53
- package/ios/HotUpdater/Internal/FileManagerService.swift +48 -0
- package/ios/HotUpdater/Internal/HotUpdater.mm +8 -18
- package/ios/HotUpdater/Internal/HotUpdaterImpl.swift +48 -29
- package/ios/HotUpdater/Internal/KeyValueStorageService.swift +71 -0
- package/ios/HotUpdater/Internal/URLSessionDownloadService.swift +108 -1
- package/ios/HotUpdater/Internal/UpdateFailure.swift +390 -0
- package/lib/commonjs/appReady.js +111 -0
- package/lib/commonjs/appReady.js.map +1 -0
- package/lib/commonjs/appReady.spec.js +360 -0
- package/lib/commonjs/appReady.spec.js.map +1 -0
- package/lib/commonjs/{notifyAppReadyInsights.test-utils.js → appReady.test-utils.js} +4 -3
- package/lib/commonjs/appReady.test-utils.js.map +1 -0
- package/lib/commonjs/baseURL.js +16 -0
- package/lib/commonjs/baseURL.js.map +1 -0
- package/lib/commonjs/checkForUpdate.js +104 -56
- package/lib/commonjs/checkForUpdate.js.map +1 -1
- package/lib/commonjs/checkForUpdate.releaseCatalog.spec.js +337 -74
- package/lib/commonjs/checkForUpdate.releaseCatalog.spec.js.map +1 -1
- package/lib/commonjs/clientPlugin.js +49 -0
- package/lib/commonjs/clientPlugin.js.map +1 -0
- package/lib/commonjs/entryImportGraph.spec.js +50 -0
- package/lib/commonjs/entryImportGraph.spec.js.map +1 -0
- package/lib/commonjs/fetchJSON.js +2 -6
- package/lib/commonjs/fetchJSON.js.map +1 -1
- package/lib/commonjs/httpClient.js +15 -67
- package/lib/commonjs/httpClient.js.map +1 -1
- package/lib/commonjs/httpClient.spec.js +26 -9
- package/lib/commonjs/httpClient.spec.js.map +1 -1
- package/lib/commonjs/index.js +49 -25
- package/lib/commonjs/index.js.map +1 -1
- package/lib/commonjs/index.spec.js +126 -40
- package/lib/commonjs/index.spec.js.map +1 -1
- package/lib/commonjs/native.js +67 -48
- package/lib/commonjs/native.js.map +1 -1
- package/lib/commonjs/native.spec.js +80 -58
- package/lib/commonjs/native.spec.js.map +1 -1
- package/lib/commonjs/pluginHost.js +208 -0
- package/lib/commonjs/pluginHost.js.map +1 -0
- package/lib/commonjs/pluginHost.spec.js +292 -0
- package/lib/commonjs/pluginHost.spec.js.map +1 -0
- package/lib/commonjs/plugins/insights/eventId.js +129 -0
- package/lib/commonjs/plugins/insights/eventId.js.map +1 -0
- package/lib/commonjs/plugins/insights/eventId.spec.js +47 -0
- package/lib/commonjs/plugins/insights/eventId.spec.js.map +1 -0
- package/lib/commonjs/plugins/insights/index.js +272 -0
- package/lib/commonjs/plugins/insights/index.js.map +1 -0
- package/lib/commonjs/plugins/insights/insights.spec.js +640 -0
- package/lib/commonjs/plugins/insights/insights.spec.js.map +1 -0
- package/lib/commonjs/plugins/insights/sender.js +128 -0
- package/lib/commonjs/plugins/insights/sender.js.map +1 -0
- package/lib/commonjs/plugins/insights/sender.spec.js +265 -0
- package/lib/commonjs/plugins/insights/sender.spec.js.map +1 -0
- package/lib/commonjs/plugins/insights/state.js +145 -0
- package/lib/commonjs/plugins/insights/state.js.map +1 -0
- package/lib/commonjs/releaseCatalogCache.js +13 -2
- package/lib/commonjs/releaseCatalogCache.js.map +1 -1
- package/lib/commonjs/releaseCatalogCache.spec.js +18 -0
- package/lib/commonjs/releaseCatalogCache.spec.js.map +1 -1
- package/lib/commonjs/sdkVersion.js +1 -1
- package/lib/commonjs/specs/NativeHotUpdater.js.map +1 -1
- package/lib/commonjs/updateError.js +132 -0
- package/lib/commonjs/updateError.js.map +1 -0
- package/lib/commonjs/updateError.spec.js +149 -0
- package/lib/commonjs/updateError.spec.js.map +1 -0
- package/lib/commonjs/wrap.js +43 -25
- package/lib/commonjs/wrap.js.map +1 -1
- package/lib/commonjs/wrap.progress.spec.js +195 -0
- package/lib/commonjs/wrap.progress.spec.js.map +1 -0
- package/lib/commonjs/wrap.spec.js +94 -230
- package/lib/commonjs/wrap.spec.js.map +1 -1
- package/lib/module/appReady.js +103 -0
- package/lib/module/appReady.js.map +1 -0
- package/lib/module/appReady.spec.js +359 -0
- package/lib/module/appReady.spec.js.map +1 -0
- package/lib/module/{notifyAppReadyInsights.test-utils.js → appReady.test-utils.js} +4 -3
- package/lib/module/appReady.test-utils.js.map +1 -0
- package/lib/module/baseURL.js +11 -0
- package/lib/module/baseURL.js.map +1 -0
- package/lib/module/checkForUpdate.js +103 -57
- package/lib/module/checkForUpdate.js.map +1 -1
- package/lib/module/checkForUpdate.releaseCatalog.spec.js +337 -74
- package/lib/module/checkForUpdate.releaseCatalog.spec.js.map +1 -1
- package/lib/module/clientPlugin.js +44 -0
- package/lib/module/clientPlugin.js.map +1 -0
- package/lib/module/entryImportGraph.spec.js +50 -0
- package/lib/module/entryImportGraph.spec.js.map +1 -0
- package/lib/module/fetchJSON.js +2 -6
- package/lib/module/fetchJSON.js.map +1 -1
- package/lib/module/httpClient.js +14 -66
- package/lib/module/httpClient.js.map +1 -1
- package/lib/module/httpClient.spec.js +26 -9
- package/lib/module/httpClient.spec.js.map +1 -1
- package/lib/module/index.js +44 -27
- package/lib/module/index.js.map +1 -1
- package/lib/module/index.spec.js +127 -41
- package/lib/module/index.spec.js.map +1 -1
- package/lib/module/native.js +63 -44
- package/lib/module/native.js.map +1 -1
- package/lib/module/native.spec.js +80 -58
- package/lib/module/native.spec.js.map +1 -1
- package/lib/module/pluginHost.js +200 -0
- package/lib/module/pluginHost.js.map +1 -0
- package/lib/module/pluginHost.spec.js +291 -0
- package/lib/module/pluginHost.spec.js.map +1 -0
- package/lib/module/plugins/insights/eventId.js +122 -0
- package/lib/module/plugins/insights/eventId.js.map +1 -0
- package/lib/module/plugins/insights/eventId.spec.js +47 -0
- package/lib/module/plugins/insights/eventId.spec.js.map +1 -0
- package/lib/module/plugins/insights/index.js +268 -0
- package/lib/module/plugins/insights/index.js.map +1 -0
- package/lib/module/plugins/insights/insights.spec.js +639 -0
- package/lib/module/plugins/insights/insights.spec.js.map +1 -0
- package/lib/module/plugins/insights/sender.js +123 -0
- package/lib/module/plugins/insights/sender.js.map +1 -0
- package/lib/module/plugins/insights/sender.spec.js +265 -0
- package/lib/module/plugins/insights/sender.spec.js.map +1 -0
- package/lib/module/plugins/insights/state.js +139 -0
- package/lib/module/plugins/insights/state.js.map +1 -0
- package/lib/module/releaseCatalogCache.js +13 -2
- package/lib/module/releaseCatalogCache.js.map +1 -1
- package/lib/module/releaseCatalogCache.spec.js +18 -0
- package/lib/module/releaseCatalogCache.spec.js.map +1 -1
- package/lib/module/sdkVersion.js +1 -1
- package/lib/module/specs/NativeHotUpdater.js.map +1 -1
- package/lib/module/updateError.js +126 -0
- package/lib/module/updateError.js.map +1 -0
- package/lib/module/updateError.spec.js +149 -0
- package/lib/module/updateError.spec.js.map +1 -0
- package/lib/module/wrap.js +43 -25
- package/lib/module/wrap.js.map +1 -1
- package/lib/module/wrap.progress.spec.js +196 -0
- package/lib/module/wrap.progress.spec.js.map +1 -0
- package/lib/module/wrap.spec.js +93 -229
- package/lib/module/wrap.spec.js.map +1 -1
- package/lib/typescript/commonjs/appReady.d.ts +23 -0
- package/lib/typescript/commonjs/appReady.d.ts.map +1 -0
- package/lib/typescript/commonjs/appReady.test-utils.d.ts +9 -0
- package/lib/typescript/commonjs/appReady.test-utils.d.ts.map +1 -0
- package/lib/typescript/commonjs/baseURL.d.ts +4 -0
- package/lib/typescript/commonjs/baseURL.d.ts.map +1 -0
- package/lib/typescript/commonjs/checkForUpdate.d.ts +15 -2
- package/lib/typescript/commonjs/checkForUpdate.d.ts.map +1 -1
- package/lib/typescript/commonjs/clientPlugin.d.ts +185 -0
- package/lib/typescript/commonjs/clientPlugin.d.ts.map +1 -0
- package/lib/typescript/commonjs/fetchJSON.d.ts +2 -3
- package/lib/typescript/commonjs/fetchJSON.d.ts.map +1 -1
- package/lib/typescript/commonjs/httpClient.d.ts +2 -30
- package/lib/typescript/commonjs/httpClient.d.ts.map +1 -1
- package/lib/typescript/commonjs/index.d.ts +3 -6
- package/lib/typescript/commonjs/index.d.ts.map +1 -1
- package/lib/typescript/commonjs/native.d.ts +29 -15
- package/lib/typescript/commonjs/native.d.ts.map +1 -1
- package/lib/typescript/commonjs/pluginHost.d.ts +29 -0
- package/lib/typescript/commonjs/pluginHost.d.ts.map +1 -0
- package/lib/typescript/commonjs/plugins/insights/eventId.d.ts +18 -0
- package/lib/typescript/commonjs/plugins/insights/eventId.d.ts.map +1 -0
- package/lib/typescript/commonjs/plugins/insights/index.d.ts +40 -0
- package/lib/typescript/commonjs/plugins/insights/index.d.ts.map +1 -0
- package/lib/typescript/commonjs/plugins/insights/sender.d.ts +74 -0
- package/lib/typescript/commonjs/plugins/insights/sender.d.ts.map +1 -0
- package/lib/typescript/commonjs/plugins/insights/state.d.ts +46 -0
- package/lib/typescript/commonjs/plugins/insights/state.d.ts.map +1 -0
- package/lib/typescript/commonjs/releaseCatalogCache.d.ts +5 -1
- package/lib/typescript/commonjs/releaseCatalogCache.d.ts.map +1 -1
- package/lib/typescript/commonjs/sdkVersion.d.ts +1 -1
- package/lib/typescript/commonjs/specs/NativeHotUpdater.d.ts +34 -12
- package/lib/typescript/commonjs/specs/NativeHotUpdater.d.ts.map +1 -1
- package/lib/typescript/commonjs/updateError.d.ts +26 -0
- package/lib/typescript/commonjs/updateError.d.ts.map +1 -0
- package/lib/typescript/commonjs/wrap.d.ts.map +1 -1
- package/lib/typescript/commonjs/wrap.types.d.ts +6 -5
- package/lib/typescript/commonjs/wrap.types.d.ts.map +1 -1
- package/lib/typescript/module/appReady.d.ts +23 -0
- package/lib/typescript/module/appReady.d.ts.map +1 -0
- package/lib/typescript/module/appReady.test-utils.d.ts +9 -0
- package/lib/typescript/module/appReady.test-utils.d.ts.map +1 -0
- package/lib/typescript/module/baseURL.d.ts +4 -0
- package/lib/typescript/module/baseURL.d.ts.map +1 -0
- package/lib/typescript/module/checkForUpdate.d.ts +15 -2
- package/lib/typescript/module/checkForUpdate.d.ts.map +1 -1
- package/lib/typescript/module/clientPlugin.d.ts +185 -0
- package/lib/typescript/module/clientPlugin.d.ts.map +1 -0
- package/lib/typescript/module/fetchJSON.d.ts +2 -3
- package/lib/typescript/module/fetchJSON.d.ts.map +1 -1
- package/lib/typescript/module/httpClient.d.ts +2 -30
- package/lib/typescript/module/httpClient.d.ts.map +1 -1
- package/lib/typescript/module/index.d.ts +3 -6
- package/lib/typescript/module/index.d.ts.map +1 -1
- package/lib/typescript/module/native.d.ts +29 -15
- package/lib/typescript/module/native.d.ts.map +1 -1
- package/lib/typescript/module/pluginHost.d.ts +29 -0
- package/lib/typescript/module/pluginHost.d.ts.map +1 -0
- package/lib/typescript/module/plugins/insights/eventId.d.ts +18 -0
- package/lib/typescript/module/plugins/insights/eventId.d.ts.map +1 -0
- package/lib/typescript/module/plugins/insights/index.d.ts +40 -0
- package/lib/typescript/module/plugins/insights/index.d.ts.map +1 -0
- package/lib/typescript/module/plugins/insights/sender.d.ts +74 -0
- package/lib/typescript/module/plugins/insights/sender.d.ts.map +1 -0
- package/lib/typescript/module/plugins/insights/state.d.ts +46 -0
- package/lib/typescript/module/plugins/insights/state.d.ts.map +1 -0
- package/lib/typescript/module/releaseCatalogCache.d.ts +5 -1
- package/lib/typescript/module/releaseCatalogCache.d.ts.map +1 -1
- package/lib/typescript/module/sdkVersion.d.ts +1 -1
- package/lib/typescript/module/specs/NativeHotUpdater.d.ts +34 -12
- package/lib/typescript/module/specs/NativeHotUpdater.d.ts.map +1 -1
- package/lib/typescript/module/updateError.d.ts +26 -0
- package/lib/typescript/module/updateError.d.ts.map +1 -0
- package/lib/typescript/module/wrap.d.ts.map +1 -1
- package/lib/typescript/module/wrap.types.d.ts +6 -5
- package/lib/typescript/module/wrap.types.d.ts.map +1 -1
- package/package.json +14 -2
- package/plugins/insights/package.json +8 -0
- package/src/appReady.spec.ts +393 -0
- package/src/{notifyAppReadyInsights.test-utils.ts → appReady.test-utils.ts} +7 -7
- package/src/appReady.ts +149 -0
- package/src/baseURL.ts +15 -0
- package/src/checkForUpdate.releaseCatalog.spec.ts +370 -76
- package/src/checkForUpdate.ts +135 -80
- package/src/clientPlugin.ts +231 -0
- package/src/entryImportGraph.spec.ts +65 -0
- package/src/fetchJSON.ts +3 -10
- package/src/httpClient.spec.ts +28 -9
- package/src/httpClient.ts +16 -109
- package/src/index.spec.ts +129 -36
- package/src/index.ts +67 -37
- package/src/native.spec.ts +98 -72
- package/src/native.ts +93 -77
- package/src/pluginHost.spec.ts +297 -0
- package/src/pluginHost.ts +262 -0
- package/src/plugins/insights/eventId.spec.ts +60 -0
- package/src/plugins/insights/eventId.ts +171 -0
- package/src/plugins/insights/index.ts +367 -0
- package/src/plugins/insights/insights.spec.ts +732 -0
- package/src/plugins/insights/sender.spec.ts +287 -0
- package/src/plugins/insights/sender.ts +221 -0
- package/src/plugins/insights/state.ts +184 -0
- package/src/releaseCatalogCache.spec.ts +22 -0
- package/src/releaseCatalogCache.ts +19 -4
- package/src/sdkVersion.ts +1 -1
- package/src/specs/NativeHotUpdater.ts +34 -13
- package/src/updateError.spec.ts +144 -0
- package/src/updateError.ts +153 -0
- package/src/wrap.progress.spec.ts +232 -0
- package/src/wrap.spec.ts +100 -283
- package/src/wrap.tsx +57 -26
- package/src/wrap.types.ts +6 -5
- package/lib/commonjs/notifyAppReadyInsights.boundary.spec.js +0 -225
- package/lib/commonjs/notifyAppReadyInsights.boundary.spec.js.map +0 -1
- package/lib/commonjs/notifyAppReadyInsights.js +0 -188
- package/lib/commonjs/notifyAppReadyInsights.js.map +0 -1
- package/lib/commonjs/notifyAppReadyInsights.spec.js +0 -378
- package/lib/commonjs/notifyAppReadyInsights.spec.js.map +0 -1
- package/lib/commonjs/notifyAppReadyInsights.test-utils.js.map +0 -1
- package/lib/commonjs/notifyAppReadyInsights.transport.spec.js +0 -124
- package/lib/commonjs/notifyAppReadyInsights.transport.spec.js.map +0 -1
- package/lib/module/notifyAppReadyInsights.boundary.spec.js +0 -224
- package/lib/module/notifyAppReadyInsights.boundary.spec.js.map +0 -1
- package/lib/module/notifyAppReadyInsights.js +0 -181
- package/lib/module/notifyAppReadyInsights.js.map +0 -1
- package/lib/module/notifyAppReadyInsights.spec.js +0 -377
- package/lib/module/notifyAppReadyInsights.spec.js.map +0 -1
- package/lib/module/notifyAppReadyInsights.test-utils.js.map +0 -1
- package/lib/module/notifyAppReadyInsights.transport.spec.js +0 -123
- package/lib/module/notifyAppReadyInsights.transport.spec.js.map +0 -1
- package/lib/typescript/commonjs/notifyAppReadyInsights.d.ts +0 -25
- package/lib/typescript/commonjs/notifyAppReadyInsights.d.ts.map +0 -1
- package/lib/typescript/commonjs/notifyAppReadyInsights.test-utils.d.ts +0 -8
- package/lib/typescript/commonjs/notifyAppReadyInsights.test-utils.d.ts.map +0 -1
- package/lib/typescript/module/notifyAppReadyInsights.d.ts +0 -25
- package/lib/typescript/module/notifyAppReadyInsights.d.ts.map +0 -1
- package/lib/typescript/module/notifyAppReadyInsights.test-utils.d.ts +0 -8
- package/lib/typescript/module/notifyAppReadyInsights.test-utils.d.ts.map +0 -1
- package/src/notifyAppReadyInsights.boundary.spec.ts +0 -242
- package/src/notifyAppReadyInsights.spec.ts +0 -362
- package/src/notifyAppReadyInsights.transport.spec.ts +0 -138
- package/src/notifyAppReadyInsights.ts +0 -293
|
@@ -1,138 +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 failureCases = [
|
|
18
|
-
{ label: "400", responseStatus: 400 },
|
|
19
|
-
{ label: "404", responseStatus: 404 },
|
|
20
|
-
{ label: "500", responseStatus: 500 },
|
|
21
|
-
{
|
|
22
|
-
error: Object.assign(new Error("request aborted"), { name: "AbortError" }),
|
|
23
|
-
label: "timeout",
|
|
24
|
-
},
|
|
25
|
-
{ error: new Error("network unavailable"), label: "network" },
|
|
26
|
-
] as const;
|
|
27
|
-
|
|
28
|
-
const mocks = vi.hoisted(() => ({
|
|
29
|
-
addListener: vi.fn(() => () => {}),
|
|
30
|
-
checkForUpdate: vi.fn(),
|
|
31
|
-
getAppVersion: vi.fn(() => "1.0.0"),
|
|
32
|
-
getBundleId: vi.fn(() => "bundle-id"),
|
|
33
|
-
getChannel: vi.fn(() => "production"),
|
|
34
|
-
getActiveUpdateState: vi.fn<() => ActiveUpdateState>(),
|
|
35
|
-
getCohort: vi.fn(() => "123"),
|
|
36
|
-
getFingerprintHash: vi.fn(() => "fingerprint-hash"),
|
|
37
|
-
getInstallId: vi.fn(() => "install-id"),
|
|
38
|
-
getPersistedUserIdentity: vi.fn(() => ({})),
|
|
39
|
-
readNotifyAppReady: vi.fn<
|
|
40
|
-
() => {
|
|
41
|
-
insightsEvent: NotifyAppReadyInsightsEvent | null;
|
|
42
|
-
pending: boolean;
|
|
43
|
-
result: NotifyAppReadyResult;
|
|
44
|
-
}
|
|
45
|
-
>(() => createNotifyReadResult()),
|
|
46
|
-
reload: vi.fn(),
|
|
47
|
-
}));
|
|
48
|
-
|
|
49
|
-
vi.mock("./checkForUpdate", () => ({
|
|
50
|
-
checkForUpdate: mocks.checkForUpdate,
|
|
51
|
-
}));
|
|
52
|
-
|
|
53
|
-
vi.mock("./native", () => ({
|
|
54
|
-
addListener: mocks.addListener,
|
|
55
|
-
getAppVersion: mocks.getAppVersion,
|
|
56
|
-
getBundleId: mocks.getBundleId,
|
|
57
|
-
getChannel: mocks.getChannel,
|
|
58
|
-
getActiveUpdateState: mocks.getActiveUpdateState,
|
|
59
|
-
getCohort: mocks.getCohort,
|
|
60
|
-
getFingerprintHash: mocks.getFingerprintHash,
|
|
61
|
-
getInstallId: mocks.getInstallId,
|
|
62
|
-
getPersistedUserIdentity: mocks.getPersistedUserIdentity,
|
|
63
|
-
readNotifyAppReady: mocks.readNotifyAppReady,
|
|
64
|
-
reload: mocks.reload,
|
|
65
|
-
}));
|
|
66
|
-
|
|
67
|
-
describe("automatic notifyAppReady transport failures", () => {
|
|
68
|
-
beforeEach(() => {
|
|
69
|
-
vi.resetModules();
|
|
70
|
-
vi.unstubAllGlobals();
|
|
71
|
-
vi.useRealTimers();
|
|
72
|
-
|
|
73
|
-
for (const mock of Object.values(mocks)) {
|
|
74
|
-
mock.mockReset();
|
|
75
|
-
}
|
|
76
|
-
|
|
77
|
-
mocks.addListener.mockReturnValue(() => {});
|
|
78
|
-
mocks.getAppVersion.mockReturnValue("1.0.0");
|
|
79
|
-
mocks.getBundleId.mockReturnValue("bundle-id");
|
|
80
|
-
mocks.getChannel.mockReturnValue("production");
|
|
81
|
-
mocks.getActiveUpdateState.mockReturnValue({
|
|
82
|
-
activeSelection: null,
|
|
83
|
-
stableSelection: null,
|
|
84
|
-
verificationPending: false,
|
|
85
|
-
});
|
|
86
|
-
mocks.getCohort.mockReturnValue("123");
|
|
87
|
-
mocks.getFingerprintHash.mockReturnValue("fingerprint-hash");
|
|
88
|
-
mocks.getInstallId.mockReturnValue("install-id");
|
|
89
|
-
mocks.getPersistedUserIdentity.mockReturnValue({});
|
|
90
|
-
mocks.readNotifyAppReady.mockReturnValue(createNotifyReadResult());
|
|
91
|
-
});
|
|
92
|
-
|
|
93
|
-
it.each(failureCases)(
|
|
94
|
-
"warns and preserves UNCHANGED readiness for a real HTTP client $label failure",
|
|
95
|
-
async (failureCase) => {
|
|
96
|
-
stubNotifyFrame();
|
|
97
|
-
const warn = vi.spyOn(console, "warn").mockImplementation(() => {});
|
|
98
|
-
const onError = vi.fn();
|
|
99
|
-
const onNotifyAppReady = vi.fn();
|
|
100
|
-
const fetchMock = vi.fn(async () => {
|
|
101
|
-
if ("error" in failureCase) {
|
|
102
|
-
throw failureCase.error;
|
|
103
|
-
}
|
|
104
|
-
|
|
105
|
-
return new Response(null, { status: failureCase.responseStatus });
|
|
106
|
-
});
|
|
107
|
-
vi.stubGlobal("fetch", fetchMock);
|
|
108
|
-
Reflect.set(globalThis, "HotUpdater", {
|
|
109
|
-
SDK_VERSION: "test-sdk-version",
|
|
110
|
-
});
|
|
111
|
-
|
|
112
|
-
try {
|
|
113
|
-
const [{ createHttpClient }, { init }] = await Promise.all([
|
|
114
|
-
import("./httpClient"),
|
|
115
|
-
import("./wrap"),
|
|
116
|
-
]);
|
|
117
|
-
const client = createHttpClient(
|
|
118
|
-
"https://updates.example.test/hot-updater",
|
|
119
|
-
);
|
|
120
|
-
|
|
121
|
-
init({ insights: true, client, onError, onNotifyAppReady });
|
|
122
|
-
await vi.runOnlyPendingTimersAsync();
|
|
123
|
-
|
|
124
|
-
expect(fetchMock).toHaveBeenCalledTimes(1);
|
|
125
|
-
expect(onError).not.toHaveBeenCalled();
|
|
126
|
-
expect(onNotifyAppReady).toHaveBeenCalledWith({
|
|
127
|
-
status: "UNCHANGED",
|
|
128
|
-
});
|
|
129
|
-
expect(warn).toHaveBeenCalledWith(
|
|
130
|
-
"[HotUpdater] Automatic notifyAppReady insights failed:",
|
|
131
|
-
expect.any(Error),
|
|
132
|
-
);
|
|
133
|
-
} finally {
|
|
134
|
-
warn.mockRestore();
|
|
135
|
-
}
|
|
136
|
-
},
|
|
137
|
-
);
|
|
138
|
-
});
|
|
@@ -1,293 +0,0 @@
|
|
|
1
|
-
import { Platform } from "react-native";
|
|
2
|
-
|
|
3
|
-
import type { HotUpdaterError } from "./error";
|
|
4
|
-
import type { InsightsEventParams, HotUpdaterHttpClient } from "./httpClient";
|
|
5
|
-
import {
|
|
6
|
-
getActiveUpdateState,
|
|
7
|
-
getAppVersion,
|
|
8
|
-
getBundleId,
|
|
9
|
-
getChannel,
|
|
10
|
-
getCohort,
|
|
11
|
-
getFingerprintHash,
|
|
12
|
-
getInstallId,
|
|
13
|
-
getPersistedUserIdentity,
|
|
14
|
-
type NotifyAppReadyInsightsEvent,
|
|
15
|
-
type NotifyAppReadyResult,
|
|
16
|
-
readNotifyAppReady,
|
|
17
|
-
} from "./native";
|
|
18
|
-
|
|
19
|
-
export type NotifyAppReadyOptions = {
|
|
20
|
-
insights?: boolean;
|
|
21
|
-
client: HotUpdaterHttpClient;
|
|
22
|
-
requestHeaders?: Record<string, string>;
|
|
23
|
-
requestTimeout?: number;
|
|
24
|
-
reportUnchanged?: boolean;
|
|
25
|
-
onNotifyAppReady?: (result: NotifyAppReadyResult) => void;
|
|
26
|
-
onError?: (error: HotUpdaterError | Error | unknown) => void;
|
|
27
|
-
};
|
|
28
|
-
|
|
29
|
-
type RequestAnimationFrame = (callback: (timestamp: number) => void) => number;
|
|
30
|
-
|
|
31
|
-
let didAttemptAutomaticInsights = false;
|
|
32
|
-
let didDownload = false;
|
|
33
|
-
let readinessPromise: Promise<NotifyAppReadyResult | undefined> | undefined;
|
|
34
|
-
|
|
35
|
-
const waitForNextFrame = () =>
|
|
36
|
-
new Promise<void>((resolve) => {
|
|
37
|
-
const requestAnimationFrame = (
|
|
38
|
-
globalThis as typeof globalThis & {
|
|
39
|
-
requestAnimationFrame?: RequestAnimationFrame;
|
|
40
|
-
}
|
|
41
|
-
)?.requestAnimationFrame;
|
|
42
|
-
|
|
43
|
-
if (requestAnimationFrame) {
|
|
44
|
-
requestAnimationFrame(() => resolve());
|
|
45
|
-
return;
|
|
46
|
-
}
|
|
47
|
-
|
|
48
|
-
void Promise.resolve().then(resolve);
|
|
49
|
-
});
|
|
50
|
-
|
|
51
|
-
const assertNever = (value: never): never => {
|
|
52
|
-
throw new Error(`[HotUpdater] Unexpected notifyAppReady status: ${value}`);
|
|
53
|
-
};
|
|
54
|
-
|
|
55
|
-
const buildNotifyAppReadyInsightsParams = (
|
|
56
|
-
nativeResult: NotifyAppReadyResult,
|
|
57
|
-
insightsEvent: NotifyAppReadyInsightsEvent | null,
|
|
58
|
-
options: Pick<NotifyAppReadyOptions, "requestHeaders" | "requestTimeout">,
|
|
59
|
-
): InsightsEventParams => {
|
|
60
|
-
const appVersion = getAppVersion();
|
|
61
|
-
|
|
62
|
-
if (!appVersion) {
|
|
63
|
-
throw new Error(
|
|
64
|
-
"[HotUpdater] Automatic insights requires a non-null native app version.",
|
|
65
|
-
);
|
|
66
|
-
}
|
|
67
|
-
|
|
68
|
-
const { userId, username } = getPersistedUserIdentity();
|
|
69
|
-
const installId = getInstallId();
|
|
70
|
-
|
|
71
|
-
if (!installId) {
|
|
72
|
-
throw new Error(
|
|
73
|
-
"[HotUpdater] Automatic insights requires a non-null native install id.",
|
|
74
|
-
);
|
|
75
|
-
}
|
|
76
|
-
|
|
77
|
-
const platform: "ios" | "android" =
|
|
78
|
-
Platform.OS === "android" ? "android" : "ios";
|
|
79
|
-
|
|
80
|
-
const commonParams = {
|
|
81
|
-
appVersion,
|
|
82
|
-
channel: getChannel(),
|
|
83
|
-
cohort: getCohort(),
|
|
84
|
-
fingerprintHash: getFingerprintHash(),
|
|
85
|
-
fromReleaseId: insightsEvent?.fromReleaseId ?? null,
|
|
86
|
-
installId,
|
|
87
|
-
platform,
|
|
88
|
-
requestHeaders: options.requestHeaders,
|
|
89
|
-
requestTimeout: options.requestTimeout,
|
|
90
|
-
toReleaseId: insightsEvent?.toReleaseId ?? null,
|
|
91
|
-
...(userId != null ? { userId } : {}),
|
|
92
|
-
...(username != null ? { username } : {}),
|
|
93
|
-
};
|
|
94
|
-
|
|
95
|
-
switch (nativeResult.status) {
|
|
96
|
-
case "UNCHANGED": {
|
|
97
|
-
const bundleId = getBundleId();
|
|
98
|
-
|
|
99
|
-
if (!bundleId) {
|
|
100
|
-
throw new Error(
|
|
101
|
-
"[HotUpdater] Automatic insights requires a non-null current bundle id.",
|
|
102
|
-
);
|
|
103
|
-
}
|
|
104
|
-
|
|
105
|
-
const state = getActiveUpdateState();
|
|
106
|
-
const runningSelection = [
|
|
107
|
-
state.activeSelection,
|
|
108
|
-
state.stableSelection,
|
|
109
|
-
].find(
|
|
110
|
-
(selection) =>
|
|
111
|
-
selection?.bundleId === bundleId &&
|
|
112
|
-
selection.channel === commonParams.channel,
|
|
113
|
-
);
|
|
114
|
-
|
|
115
|
-
return {
|
|
116
|
-
...commonParams,
|
|
117
|
-
fromBundleId: null,
|
|
118
|
-
toBundleId: bundleId,
|
|
119
|
-
toReleaseId: runningSelection?.releaseId ?? null,
|
|
120
|
-
type: "UNCHANGED",
|
|
121
|
-
updateStrategy: null,
|
|
122
|
-
};
|
|
123
|
-
}
|
|
124
|
-
case "UPDATE_APPLIED":
|
|
125
|
-
case "RECOVERED":
|
|
126
|
-
if (!insightsEvent) {
|
|
127
|
-
throw new Error(
|
|
128
|
-
"[HotUpdater] Native launch report is missing persisted metadata required for automatic insights.",
|
|
129
|
-
);
|
|
130
|
-
}
|
|
131
|
-
|
|
132
|
-
switch (insightsEvent.type) {
|
|
133
|
-
case "UPDATE_APPLIED":
|
|
134
|
-
return {
|
|
135
|
-
...commonParams,
|
|
136
|
-
fromBundleId: insightsEvent.fromBundleId,
|
|
137
|
-
toBundleId: insightsEvent.toBundleId,
|
|
138
|
-
type: "UPDATE_APPLIED",
|
|
139
|
-
updateStrategy: insightsEvent.updateStrategy,
|
|
140
|
-
};
|
|
141
|
-
case "RECOVERED":
|
|
142
|
-
return {
|
|
143
|
-
...commonParams,
|
|
144
|
-
fromBundleId: insightsEvent.fromBundleId,
|
|
145
|
-
toBundleId: insightsEvent.toBundleId,
|
|
146
|
-
type: "RECOVERED",
|
|
147
|
-
updateStrategy: insightsEvent.updateStrategy,
|
|
148
|
-
};
|
|
149
|
-
default:
|
|
150
|
-
return assertNever(insightsEvent.type);
|
|
151
|
-
}
|
|
152
|
-
default:
|
|
153
|
-
return assertNever(nativeResult);
|
|
154
|
-
}
|
|
155
|
-
};
|
|
156
|
-
|
|
157
|
-
let lastInsightsReport = Promise.resolve();
|
|
158
|
-
const sendInsights = (
|
|
159
|
-
options: Pick<NotifyAppReadyOptions, "client">,
|
|
160
|
-
params: InsightsEventParams,
|
|
161
|
-
): Promise<void> => {
|
|
162
|
-
lastInsightsReport = lastInsightsReport
|
|
163
|
-
.catch(() => {})
|
|
164
|
-
.then(async () => {
|
|
165
|
-
const session = await options.client.createSession();
|
|
166
|
-
await session.sendInsightsEvent(params);
|
|
167
|
-
});
|
|
168
|
-
return lastInsightsReport;
|
|
169
|
-
};
|
|
170
|
-
|
|
171
|
-
const maybeSendAutomaticInsights = async (
|
|
172
|
-
options: NotifyAppReadyOptions,
|
|
173
|
-
nativeResult: NotifyAppReadyResult,
|
|
174
|
-
insightsEvent: NotifyAppReadyInsightsEvent | null,
|
|
175
|
-
): Promise<void> => {
|
|
176
|
-
if (
|
|
177
|
-
!options.insights ||
|
|
178
|
-
didAttemptAutomaticInsights ||
|
|
179
|
-
(nativeResult.status === "UNCHANGED" &&
|
|
180
|
-
(options.reportUnchanged === false || didDownload))
|
|
181
|
-
) {
|
|
182
|
-
return;
|
|
183
|
-
}
|
|
184
|
-
|
|
185
|
-
didAttemptAutomaticInsights = true;
|
|
186
|
-
|
|
187
|
-
if (nativeResult.status !== "UNCHANGED" && !insightsEvent) {
|
|
188
|
-
throw new Error(
|
|
189
|
-
"[HotUpdater] Native launch report is missing persisted metadata required for automatic insights.",
|
|
190
|
-
);
|
|
191
|
-
}
|
|
192
|
-
|
|
193
|
-
await sendInsights(
|
|
194
|
-
options,
|
|
195
|
-
buildNotifyAppReadyInsightsParams(nativeResult, insightsEvent, options),
|
|
196
|
-
);
|
|
197
|
-
};
|
|
198
|
-
|
|
199
|
-
const notifyAppReady = async (
|
|
200
|
-
options: NotifyAppReadyOptions,
|
|
201
|
-
): Promise<NotifyAppReadyResult | undefined> => {
|
|
202
|
-
try {
|
|
203
|
-
let nativeReadResult: ReturnType<typeof readNotifyAppReady>;
|
|
204
|
-
do {
|
|
205
|
-
await waitForNextFrame();
|
|
206
|
-
nativeReadResult = readNotifyAppReady();
|
|
207
|
-
} while (nativeReadResult.pending);
|
|
208
|
-
|
|
209
|
-
const { insightsEvent, result: nativeResult } = nativeReadResult;
|
|
210
|
-
|
|
211
|
-
try {
|
|
212
|
-
await maybeSendAutomaticInsights(options, nativeResult, insightsEvent);
|
|
213
|
-
} catch (error) {
|
|
214
|
-
const warning = error instanceof Error ? error : new Error(String(error));
|
|
215
|
-
console.warn(
|
|
216
|
-
"[HotUpdater] Automatic notifyAppReady insights failed:",
|
|
217
|
-
warning,
|
|
218
|
-
);
|
|
219
|
-
}
|
|
220
|
-
|
|
221
|
-
options.onNotifyAppReady?.(nativeResult);
|
|
222
|
-
return nativeResult;
|
|
223
|
-
} catch (error) {
|
|
224
|
-
const normalizedError =
|
|
225
|
-
error instanceof Error ? error : new Error(String(error));
|
|
226
|
-
options.onError?.(error);
|
|
227
|
-
console.warn("[HotUpdater] Failed to notify app ready:", normalizedError);
|
|
228
|
-
return undefined;
|
|
229
|
-
}
|
|
230
|
-
};
|
|
231
|
-
|
|
232
|
-
export const handleNotifyAppReady = (
|
|
233
|
-
options: NotifyAppReadyOptions,
|
|
234
|
-
): Promise<NotifyAppReadyResult | undefined> => {
|
|
235
|
-
readinessPromise = notifyAppReady(options);
|
|
236
|
-
return readinessPromise;
|
|
237
|
-
};
|
|
238
|
-
|
|
239
|
-
/** Called after an automatic update check finds no download or transition. */
|
|
240
|
-
export const reportNoChange = async (
|
|
241
|
-
options: NotifyAppReadyOptions,
|
|
242
|
-
): Promise<void> => {
|
|
243
|
-
try {
|
|
244
|
-
await maybeSendAutomaticInsights(options, { status: "UNCHANGED" }, null);
|
|
245
|
-
} catch (error) {
|
|
246
|
-
console.warn("[HotUpdater] Automatic no-change insights failed:", error);
|
|
247
|
-
}
|
|
248
|
-
};
|
|
249
|
-
|
|
250
|
-
let lastDownloadedSelection: string | undefined;
|
|
251
|
-
|
|
252
|
-
/** Report only after the manifest update has been verified and staged successfully. */
|
|
253
|
-
export const reportBundleDownloaded = async (
|
|
254
|
-
options: Pick<
|
|
255
|
-
NotifyAppReadyOptions,
|
|
256
|
-
"insights" | "client" | "requestHeaders" | "requestTimeout"
|
|
257
|
-
>,
|
|
258
|
-
transition: {
|
|
259
|
-
readonly fromBundleId: string;
|
|
260
|
-
readonly fromReleaseId: string | null;
|
|
261
|
-
readonly toBundleId: string;
|
|
262
|
-
readonly toReleaseId: string | null;
|
|
263
|
-
readonly channel: string;
|
|
264
|
-
readonly updateStrategy: "fingerprint" | "appVersion";
|
|
265
|
-
},
|
|
266
|
-
): Promise<void> => {
|
|
267
|
-
if (!options.insights || transition.fromBundleId === transition.toBundleId)
|
|
268
|
-
return;
|
|
269
|
-
const key = JSON.stringify([
|
|
270
|
-
transition.channel,
|
|
271
|
-
transition.toReleaseId,
|
|
272
|
-
transition.toBundleId,
|
|
273
|
-
]);
|
|
274
|
-
if (lastDownloadedSelection === key) return;
|
|
275
|
-
lastDownloadedSelection = key;
|
|
276
|
-
// A later init/mount in this JS runtime must not overwrite pending apply with UNCHANGED.
|
|
277
|
-
didDownload = true;
|
|
278
|
-
try {
|
|
279
|
-
await readinessPromise;
|
|
280
|
-
const common = buildNotifyAppReadyInsightsParams(
|
|
281
|
-
{ status: "UNCHANGED" },
|
|
282
|
-
null,
|
|
283
|
-
options,
|
|
284
|
-
);
|
|
285
|
-
await sendInsights(options, {
|
|
286
|
-
...common,
|
|
287
|
-
...transition,
|
|
288
|
-
type: "UPDATE_DOWNLOADED",
|
|
289
|
-
});
|
|
290
|
-
} catch (error) {
|
|
291
|
-
console.warn("[HotUpdater] Download insights failed:", error);
|
|
292
|
-
}
|
|
293
|
-
};
|