@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.
- 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 +18 -165
- package/lib/commonjs/httpClient.js.map +1 -1
- package/lib/commonjs/httpClient.spec.js +26 -199
- package/lib/commonjs/httpClient.spec.js.map +1 -1
- package/lib/commonjs/index.js +49 -36
- package/lib/commonjs/index.js.map +1 -1
- package/lib/commonjs/index.spec.js +108 -123
- 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 +18 -165
- package/lib/module/httpClient.js.map +1 -1
- package/lib/module/httpClient.spec.js +27 -200
- package/lib/module/httpClient.spec.js.map +1 -1
- package/lib/module/index.js +44 -38
- package/lib/module/index.js.map +1 -1
- package/lib/module/index.spec.js +108 -123
- 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 -36
- 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 -10
- 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 -36
- 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 -10
- 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 +30 -227
- package/src/httpClient.ts +20 -256
- package/src/index.spec.ts +117 -93
- package/src/index.ts +67 -52
- 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 -12
- 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 -171
- package/lib/commonjs/notifyAppReadyInsights.transport.spec.js.map +0 -1
- package/lib/commonjs/uuidv7.js +0 -41
- package/lib/commonjs/uuidv7.js.map +0 -1
- package/lib/commonjs/uuidv7.spec.js +0 -30
- package/lib/commonjs/uuidv7.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 -170
- package/lib/module/notifyAppReadyInsights.transport.spec.js.map +0 -1
- package/lib/module/uuidv7.js +0 -36
- package/lib/module/uuidv7.js.map +0 -1
- package/lib/module/uuidv7.spec.js +0 -30
- package/lib/module/uuidv7.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/commonjs/uuidv7.d.ts +0 -10
- package/lib/typescript/commonjs/uuidv7.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/lib/typescript/module/uuidv7.d.ts +0 -10
- package/lib/typescript/module/uuidv7.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 -196
- package/src/notifyAppReadyInsights.ts +0 -293
- package/src/uuidv7.spec.ts +0 -25
- package/src/uuidv7.ts +0 -38
|
@@ -0,0 +1,200 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
import { Platform } from "react-native";
|
|
4
|
+
import { resolveBaseURL } from "./baseURL.js";
|
|
5
|
+
import { getAppVersion, getBundleId, getChannel, getCohort, getFingerprintHash, getInstallId, getStorageItem, setStorageItem } from "./native.js";
|
|
6
|
+
import { HOT_UPDATER_SDK_VERSION } from "./sdkVersion.js";
|
|
7
|
+
|
|
8
|
+
/** The init or wrap settings plugins see through their context. */
|
|
9
|
+
|
|
10
|
+
/** Storage values stay small, since native reads them on the JS thread. */
|
|
11
|
+
const MAX_STORAGE_VALUE_LENGTH = 64 * 1024;
|
|
12
|
+
let config = null;
|
|
13
|
+
/** Hooks by plugin, so a plugin configured again is not set up twice. */
|
|
14
|
+
const setUpPlugins = new WeakMap();
|
|
15
|
+
let activePlugins = [];
|
|
16
|
+
/** What plugins read and wrote, so a read follows a write before native does. */
|
|
17
|
+
const storageValues = new Map();
|
|
18
|
+
const reportHookError = (message, error) => {
|
|
19
|
+
const report = new Error(`[HotUpdater] ${message}`, {
|
|
20
|
+
cause: error
|
|
21
|
+
});
|
|
22
|
+
try {
|
|
23
|
+
if (config?.onError) {
|
|
24
|
+
config.onError(report);
|
|
25
|
+
return;
|
|
26
|
+
}
|
|
27
|
+
} catch {
|
|
28
|
+
// A throwing onError must not break the update path either.
|
|
29
|
+
}
|
|
30
|
+
console.warn(report.message, error);
|
|
31
|
+
};
|
|
32
|
+
const fetchFromServer = async (path, init = {}) => {
|
|
33
|
+
if (config === null) {
|
|
34
|
+
throw new Error("[HotUpdater] Plugins can fetch only after init or wrap.");
|
|
35
|
+
}
|
|
36
|
+
if (/^[a-z][a-z\d+.-]*:/i.test(path) || path.startsWith("//")) {
|
|
37
|
+
throw new TypeError("[HotUpdater] Plugin fetch takes a path relative to baseURL.");
|
|
38
|
+
}
|
|
39
|
+
const {
|
|
40
|
+
requestHeaders,
|
|
41
|
+
requestTimeout
|
|
42
|
+
} = config;
|
|
43
|
+
const url = `${await resolveBaseURL(config.baseURL)}/${path.replace(/^\/+/, "")}`;
|
|
44
|
+
const headers = new Headers(requestHeaders);
|
|
45
|
+
new Headers(init.headers).forEach((value, name) => {
|
|
46
|
+
headers.set(name, value);
|
|
47
|
+
});
|
|
48
|
+
const controller = new AbortController();
|
|
49
|
+
const callerSignal = init.signal;
|
|
50
|
+
const abortFromCaller = () => controller.abort();
|
|
51
|
+
if (callerSignal?.aborted) controller.abort();
|
|
52
|
+
callerSignal?.addEventListener("abort", abortFromCaller);
|
|
53
|
+
const timeoutId = setTimeout(() => controller.abort(), requestTimeout ?? 5000);
|
|
54
|
+
try {
|
|
55
|
+
return await fetch(url, {
|
|
56
|
+
...init,
|
|
57
|
+
headers,
|
|
58
|
+
signal: controller.signal
|
|
59
|
+
});
|
|
60
|
+
} catch (error) {
|
|
61
|
+
if (error instanceof Error && error.name === "AbortError" && !callerSignal?.aborted) {
|
|
62
|
+
throw new Error("Request timed out");
|
|
63
|
+
}
|
|
64
|
+
throw error;
|
|
65
|
+
} finally {
|
|
66
|
+
clearTimeout(timeoutId);
|
|
67
|
+
callerSignal?.removeEventListener("abort", abortFromCaller);
|
|
68
|
+
}
|
|
69
|
+
};
|
|
70
|
+
const createStorage = pluginId => {
|
|
71
|
+
const scopedKey = key => {
|
|
72
|
+
if (typeof key !== "string" || key.length === 0) {
|
|
73
|
+
throw new TypeError("[HotUpdater] Plugin storage keys are non-empty strings.");
|
|
74
|
+
}
|
|
75
|
+
// Encoded, so no id and key pair can name another plugin's key.
|
|
76
|
+
return `plugins/${encodeURIComponent(pluginId)}/${key}`;
|
|
77
|
+
};
|
|
78
|
+
return {
|
|
79
|
+
get: key => {
|
|
80
|
+
const storageKey = scopedKey(key);
|
|
81
|
+
const cached = storageValues.get(storageKey);
|
|
82
|
+
if (cached !== undefined) return cached;
|
|
83
|
+
const value = getStorageItem(storageKey);
|
|
84
|
+
storageValues.set(storageKey, value);
|
|
85
|
+
return value;
|
|
86
|
+
},
|
|
87
|
+
set: (key, value) => {
|
|
88
|
+
const storageKey = scopedKey(key);
|
|
89
|
+
if (value !== null && typeof value !== "string") {
|
|
90
|
+
throw new TypeError("[HotUpdater] Plugin storage values are strings or null.");
|
|
91
|
+
}
|
|
92
|
+
if (value !== null && value.length > MAX_STORAGE_VALUE_LENGTH) {
|
|
93
|
+
throw new RangeError("[HotUpdater] Plugin storage values are at most 64 KB.");
|
|
94
|
+
}
|
|
95
|
+
setStorageItem(storageKey, value);
|
|
96
|
+
storageValues.set(storageKey, value);
|
|
97
|
+
}
|
|
98
|
+
};
|
|
99
|
+
};
|
|
100
|
+
const createContext = pluginId => ({
|
|
101
|
+
fetch: fetchFromServer,
|
|
102
|
+
get installId() {
|
|
103
|
+
return getInstallId();
|
|
104
|
+
},
|
|
105
|
+
platform: Platform.OS === "android" ? "android" : "ios",
|
|
106
|
+
get appVersion() {
|
|
107
|
+
return getAppVersion();
|
|
108
|
+
},
|
|
109
|
+
get sdkVersion() {
|
|
110
|
+
return HOT_UPDATER_SDK_VERSION;
|
|
111
|
+
},
|
|
112
|
+
isDebugBuild: typeof __DEV__ !== "undefined" && __DEV__,
|
|
113
|
+
getBundleId,
|
|
114
|
+
getChannel,
|
|
115
|
+
getCohort,
|
|
116
|
+
getFingerprintHash,
|
|
117
|
+
storage: createStorage(pluginId),
|
|
118
|
+
now: () => Date.now()
|
|
119
|
+
});
|
|
120
|
+
|
|
121
|
+
/**
|
|
122
|
+
* Sets up the plugins of an init or wrap call. A plugin passed to an earlier
|
|
123
|
+
* call keeps its hooks, and a plugin left out stops receiving events.
|
|
124
|
+
*/
|
|
125
|
+
export const configurePlugins = (plugins, nextConfig) => {
|
|
126
|
+
const ids = new Set();
|
|
127
|
+
for (const plugin of plugins ?? []) {
|
|
128
|
+
if (typeof plugin.id !== "string" || plugin.id.length === 0) {
|
|
129
|
+
throw new Error("[HotUpdater] A plugin id must be a non-empty string.");
|
|
130
|
+
}
|
|
131
|
+
if (ids.has(plugin.id)) {
|
|
132
|
+
throw new Error(`[HotUpdater] Two plugins use the id "${plugin.id}". Plugin ids must be unique.`);
|
|
133
|
+
}
|
|
134
|
+
ids.add(plugin.id);
|
|
135
|
+
}
|
|
136
|
+
config = nextConfig;
|
|
137
|
+
activePlugins = (plugins ?? []).map(plugin => {
|
|
138
|
+
let hooks = setUpPlugins.get(plugin);
|
|
139
|
+
if (hooks === undefined) {
|
|
140
|
+
try {
|
|
141
|
+
hooks = plugin.setup(createContext(plugin.id)) ?? {};
|
|
142
|
+
} catch (error) {
|
|
143
|
+
reportHookError(`Plugin "${plugin.id}" failed in setup`, error);
|
|
144
|
+
hooks = {};
|
|
145
|
+
}
|
|
146
|
+
setUpPlugins.set(plugin, hooks);
|
|
147
|
+
}
|
|
148
|
+
return {
|
|
149
|
+
plugin,
|
|
150
|
+
hooks
|
|
151
|
+
};
|
|
152
|
+
});
|
|
153
|
+
};
|
|
154
|
+
|
|
155
|
+
/** Whether any plugin listens to this hook, so callers build events only when one does. */
|
|
156
|
+
export const hasPluginHook = name => activePlugins.some(({
|
|
157
|
+
hooks
|
|
158
|
+
}) => typeof hooks[name] === "function");
|
|
159
|
+
|
|
160
|
+
/**
|
|
161
|
+
* Builds a hook's event when a plugin listens. A failure to build it is
|
|
162
|
+
* reported, not thrown, since reporting never changes an update.
|
|
163
|
+
*/
|
|
164
|
+
export const buildPluginEvent = (name, createPayload) => {
|
|
165
|
+
if (!hasPluginHook(name)) return null;
|
|
166
|
+
try {
|
|
167
|
+
return createPayload();
|
|
168
|
+
} catch (error) {
|
|
169
|
+
reportHookError(`Failed to build the ${name} event for plugins`, error);
|
|
170
|
+
return null;
|
|
171
|
+
}
|
|
172
|
+
};
|
|
173
|
+
|
|
174
|
+
/** Calls a hook on every plugin that listens, without waiting for any. */
|
|
175
|
+
export const dispatchPluginHook = (name, payload) => {
|
|
176
|
+
for (const {
|
|
177
|
+
plugin,
|
|
178
|
+
hooks
|
|
179
|
+
} of activePlugins) {
|
|
180
|
+
const hook = hooks[name];
|
|
181
|
+
if (typeof hook !== "function") continue;
|
|
182
|
+
try {
|
|
183
|
+
const result = hook.call(hooks, payload);
|
|
184
|
+
if (result !== null && typeof result === "object" && typeof result.then === "function") {
|
|
185
|
+
void Promise.resolve(result).catch(error => {
|
|
186
|
+
reportHookError(`Plugin "${plugin.id}" failed in ${name}`, error);
|
|
187
|
+
});
|
|
188
|
+
}
|
|
189
|
+
} catch (error) {
|
|
190
|
+
reportHookError(`Plugin "${plugin.id}" failed in ${name}`, error);
|
|
191
|
+
}
|
|
192
|
+
}
|
|
193
|
+
};
|
|
194
|
+
|
|
195
|
+
/** Builds a hook's event when a plugin listens and calls the hook right away. */
|
|
196
|
+
export const emitPluginHook = (name, createPayload) => {
|
|
197
|
+
const payload = buildPluginEvent(name, createPayload);
|
|
198
|
+
if (payload !== null) dispatchPluginHook(name, payload);
|
|
199
|
+
};
|
|
200
|
+
//# sourceMappingURL=pluginHost.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":["Platform","resolveBaseURL","getAppVersion","getBundleId","getChannel","getCohort","getFingerprintHash","getInstallId","getStorageItem","setStorageItem","HOT_UPDATER_SDK_VERSION","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","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","RangeError","createContext","installId","platform","OS","appVersion","sdkVersion","isDebugBuild","__DEV__","storage","now","Date","configurePlugins","plugins","nextConfig","ids","Set","plugin","id","has","add","map","hooks","setup","hasPluginHook","some","buildPluginEvent","createPayload","dispatchPluginHook","payload","hook","result","call","then","Promise","resolve","catch","emitPluginHook"],"sourceRoot":"../../src","sources":["pluginHost.ts"],"mappings":";;AAAA,SAASA,QAAQ,QAAQ,c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AAM,GAAGD,IAAI,CAACE,IAAI,CAACV,KAAK,EAAEO,OAAO,CAAC;MACxC,IACEE,MAAM,KAAK,IAAI,IACf,OAAOA,MAAM,KAAK,QAAQ,IAC1B,OAAQA,MAAM,CAA0BE,IAAI,KAAK,UAAU,EAC3D;QACA,KAAKC,OAAO,CAACC,OAAO,CAACJ,MAAM,CAAC,CAACK,KAAK,CAAEnF,KAAc,IAAK;UACrDF,eAAe,CAAC,WAAWkE,MAAM,CAACC,EAAE,eAAe3C,IAAI,EAAE,EAAEtB,KAAK,CAAC;QACnE,CAAC,CAAC;MACJ;IACF,CAAC,CAAC,OAAOA,KAAK,EAAE;MACdF,eAAe,CAAC,WAAWkE,MAAM,CAACC,EAAE,eAAe3C,IAAI,EAAE,EAAEtB,KAAK,CAAC;IACnE;EACF;AACF,CAAC;;AAED;AACA,OAAO,MAAMoF,cAAc,GAAGA,CAC5B9D,IAAO,EACPoD,aAA0C,KACjC;EACT,MAAME,OAAO,GAAGH,gBAAgB,CAACnD,IAAI,EAAEoD,aAAa,CAAC;EACrD,IAAIE,OAAO,KAAK,IAAI,EAAED,kBAAkB,CAACrD,IAAI,EAAEsD,OAAO,CAAC;AACzD,CAAC","ignoreList":[]}
|
|
@@ -0,0 +1,291 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
import { afterEach, beforeEach, describe, expect, it, vi } from "vitest";
|
|
4
|
+
vi.mock("react-native", () => ({
|
|
5
|
+
Platform: {
|
|
6
|
+
OS: "android"
|
|
7
|
+
}
|
|
8
|
+
}));
|
|
9
|
+
const mocks = vi.hoisted(() => {
|
|
10
|
+
Reflect.set(globalThis, "HotUpdater", {
|
|
11
|
+
SDK_VERSION: "test-sdk-version"
|
|
12
|
+
});
|
|
13
|
+
return {
|
|
14
|
+
getAppVersion: vi.fn(() => "1.2.3"),
|
|
15
|
+
getBundleId: vi.fn(() => "bundle-id"),
|
|
16
|
+
getChannel: vi.fn(() => "production"),
|
|
17
|
+
getCohort: vi.fn(() => "123"),
|
|
18
|
+
getFingerprintHash: vi.fn(() => null),
|
|
19
|
+
getInstallId: vi.fn(() => "install-id"),
|
|
20
|
+
getStorageItem: vi.fn(() => null),
|
|
21
|
+
setStorageItem: vi.fn()
|
|
22
|
+
};
|
|
23
|
+
});
|
|
24
|
+
vi.mock("./native", () => mocks);
|
|
25
|
+
const importHost = () => import("./pluginHost");
|
|
26
|
+
const capture = (id = "example") => {
|
|
27
|
+
let context;
|
|
28
|
+
const setup = vi.fn(pluginContext => {
|
|
29
|
+
context = pluginContext;
|
|
30
|
+
});
|
|
31
|
+
const plugin = {
|
|
32
|
+
id,
|
|
33
|
+
setup
|
|
34
|
+
};
|
|
35
|
+
return {
|
|
36
|
+
plugin,
|
|
37
|
+
setup,
|
|
38
|
+
context: () => context
|
|
39
|
+
};
|
|
40
|
+
};
|
|
41
|
+
describe("client plugin host", () => {
|
|
42
|
+
beforeEach(() => {
|
|
43
|
+
vi.resetModules();
|
|
44
|
+
for (const mock of Object.values(mocks)) mock.mockClear();
|
|
45
|
+
mocks.getStorageItem.mockReturnValue(null);
|
|
46
|
+
});
|
|
47
|
+
afterEach(() => {
|
|
48
|
+
vi.useRealTimers();
|
|
49
|
+
vi.unstubAllGlobals();
|
|
50
|
+
vi.restoreAllMocks();
|
|
51
|
+
});
|
|
52
|
+
it("throws at configuration for two plugins with one id", async () => {
|
|
53
|
+
const {
|
|
54
|
+
configurePlugins
|
|
55
|
+
} = await importHost();
|
|
56
|
+
expect(() => configurePlugins([capture("same").plugin, capture("same").plugin], {
|
|
57
|
+
baseURL: "https://updates.example.com"
|
|
58
|
+
})).toThrow('Two plugins use the id "same"');
|
|
59
|
+
});
|
|
60
|
+
it("sets a plugin up once and stops calling a plugin left out", async () => {
|
|
61
|
+
const {
|
|
62
|
+
configurePlugins,
|
|
63
|
+
emitPluginHook
|
|
64
|
+
} = await importHost();
|
|
65
|
+
const onAppReady = vi.fn();
|
|
66
|
+
const plugin = {
|
|
67
|
+
id: "example",
|
|
68
|
+
setup: vi.fn(() => ({
|
|
69
|
+
onAppReady
|
|
70
|
+
}))
|
|
71
|
+
};
|
|
72
|
+
const config = {
|
|
73
|
+
baseURL: "https://updates.example.com"
|
|
74
|
+
};
|
|
75
|
+
configurePlugins([plugin], config);
|
|
76
|
+
configurePlugins([plugin], config);
|
|
77
|
+
emitPluginHook("onAppReady", () => ({
|
|
78
|
+
status: "UNCHANGED",
|
|
79
|
+
channel: "production",
|
|
80
|
+
bundleId: "bundle-id",
|
|
81
|
+
releaseId: null,
|
|
82
|
+
previousProcessExit: null
|
|
83
|
+
}));
|
|
84
|
+
configurePlugins([], config);
|
|
85
|
+
emitPluginHook("onAppReady", () => ({
|
|
86
|
+
status: "UNCHANGED",
|
|
87
|
+
channel: "production",
|
|
88
|
+
bundleId: "bundle-id",
|
|
89
|
+
releaseId: null,
|
|
90
|
+
previousProcessExit: null
|
|
91
|
+
}));
|
|
92
|
+
expect(plugin.setup).toHaveBeenCalledOnce();
|
|
93
|
+
expect(onAppReady).toHaveBeenCalledOnce();
|
|
94
|
+
});
|
|
95
|
+
it("warns without onError when setup throws, and keeps other plugins", async () => {
|
|
96
|
+
const warn = vi.spyOn(console, "warn").mockImplementation(() => {});
|
|
97
|
+
const {
|
|
98
|
+
configurePlugins
|
|
99
|
+
} = await importHost();
|
|
100
|
+
const healthy = capture("healthy");
|
|
101
|
+
configurePlugins([{
|
|
102
|
+
id: "broken",
|
|
103
|
+
setup: () => {
|
|
104
|
+
throw new Error("setup failed");
|
|
105
|
+
}
|
|
106
|
+
}, healthy.plugin], {
|
|
107
|
+
baseURL: "https://updates.example.com"
|
|
108
|
+
});
|
|
109
|
+
expect(healthy.setup).toHaveBeenCalledOnce();
|
|
110
|
+
expect(warn).toHaveBeenCalledWith('[HotUpdater] Plugin "broken" failed in setup', expect.objectContaining({
|
|
111
|
+
message: "setup failed"
|
|
112
|
+
}));
|
|
113
|
+
});
|
|
114
|
+
it("never waits for a hook", async () => {
|
|
115
|
+
const {
|
|
116
|
+
configurePlugins,
|
|
117
|
+
emitPluginHook
|
|
118
|
+
} = await importHost();
|
|
119
|
+
const onUpdateCheck = vi.fn(() => new Promise(() => {}));
|
|
120
|
+
configurePlugins([{
|
|
121
|
+
id: "slow",
|
|
122
|
+
setup: () => ({
|
|
123
|
+
onUpdateCheck
|
|
124
|
+
})
|
|
125
|
+
}], {
|
|
126
|
+
baseURL: "https://updates.example.com"
|
|
127
|
+
});
|
|
128
|
+
const result = emitPluginHook("onUpdateCheck", () => ({
|
|
129
|
+
status: "UNCHANGED",
|
|
130
|
+
channel: "production",
|
|
131
|
+
bundleId: "bundle-id",
|
|
132
|
+
releaseId: null,
|
|
133
|
+
previousReleaseId: null
|
|
134
|
+
}));
|
|
135
|
+
expect(result).toBeUndefined();
|
|
136
|
+
expect(onUpdateCheck).toHaveBeenCalledOnce();
|
|
137
|
+
});
|
|
138
|
+
it("builds an event only when a plugin listens", async () => {
|
|
139
|
+
const {
|
|
140
|
+
configurePlugins,
|
|
141
|
+
emitPluginHook
|
|
142
|
+
} = await importHost();
|
|
143
|
+
configurePlugins([capture().plugin], {
|
|
144
|
+
baseURL: "https://updates.example.com"
|
|
145
|
+
});
|
|
146
|
+
const createPayload = vi.fn(() => null);
|
|
147
|
+
emitPluginHook("onUpdateError", createPayload);
|
|
148
|
+
expect(createPayload).not.toHaveBeenCalled();
|
|
149
|
+
});
|
|
150
|
+
it("exposes the app's identity and environment", async () => {
|
|
151
|
+
vi.stubGlobal("__DEV__", true);
|
|
152
|
+
vi.spyOn(Date, "now").mockReturnValue(1_700_000_000_000);
|
|
153
|
+
const {
|
|
154
|
+
configurePlugins
|
|
155
|
+
} = await importHost();
|
|
156
|
+
const plugin = capture();
|
|
157
|
+
configurePlugins([plugin.plugin], {
|
|
158
|
+
baseURL: "https://updates.example.com"
|
|
159
|
+
});
|
|
160
|
+
const context = plugin.context();
|
|
161
|
+
expect({
|
|
162
|
+
appVersion: context.appVersion,
|
|
163
|
+
bundleId: context.getBundleId(),
|
|
164
|
+
channel: context.getChannel(),
|
|
165
|
+
cohort: context.getCohort(),
|
|
166
|
+
fingerprintHash: context.getFingerprintHash(),
|
|
167
|
+
installId: context.installId,
|
|
168
|
+
isDebugBuild: context.isDebugBuild,
|
|
169
|
+
now: context.now(),
|
|
170
|
+
platform: context.platform,
|
|
171
|
+
sdkVersion: context.sdkVersion
|
|
172
|
+
}).toEqual({
|
|
173
|
+
appVersion: "1.2.3",
|
|
174
|
+
bundleId: "bundle-id",
|
|
175
|
+
channel: "production",
|
|
176
|
+
cohort: "123",
|
|
177
|
+
fingerprintHash: null,
|
|
178
|
+
installId: "install-id",
|
|
179
|
+
isDebugBuild: true,
|
|
180
|
+
now: 1_700_000_000_000,
|
|
181
|
+
platform: "android",
|
|
182
|
+
sdkVersion: "test-sdk-version"
|
|
183
|
+
});
|
|
184
|
+
});
|
|
185
|
+
describe("fetch", () => {
|
|
186
|
+
it("requests a path under the resolved baseURL with the SDK's headers", async () => {
|
|
187
|
+
const fetchMock = vi.fn(async () => new Response(null, {
|
|
188
|
+
status: 204
|
|
189
|
+
}));
|
|
190
|
+
vi.stubGlobal("fetch", fetchMock);
|
|
191
|
+
const {
|
|
192
|
+
configurePlugins
|
|
193
|
+
} = await importHost();
|
|
194
|
+
const plugin = capture();
|
|
195
|
+
configurePlugins([plugin.plugin], {
|
|
196
|
+
baseURL: async () => "https://updates.example.com/hot-updater/",
|
|
197
|
+
requestHeaders: {
|
|
198
|
+
"x-api-key": "client-key",
|
|
199
|
+
"X-Shared": "sdk"
|
|
200
|
+
}
|
|
201
|
+
});
|
|
202
|
+
await plugin.context().fetch("/events", {
|
|
203
|
+
headers: {
|
|
204
|
+
"Content-Type": "application/json",
|
|
205
|
+
"X-Shared": "plugin"
|
|
206
|
+
},
|
|
207
|
+
method: "POST"
|
|
208
|
+
});
|
|
209
|
+
const [url, init] = fetchMock.mock.calls[0];
|
|
210
|
+
expect(url).toBe("https://updates.example.com/hot-updater/events");
|
|
211
|
+
expect(init?.method).toBe("POST");
|
|
212
|
+
const headers = new Headers(init?.headers);
|
|
213
|
+
expect(headers.get("x-api-key")).toBe("client-key");
|
|
214
|
+
expect(headers.get("content-type")).toBe("application/json");
|
|
215
|
+
expect(headers.get("x-shared")).toBe("plugin");
|
|
216
|
+
});
|
|
217
|
+
it("rejects with Request timed out after the SDK's timeout", async () => {
|
|
218
|
+
vi.useFakeTimers();
|
|
219
|
+
vi.stubGlobal("fetch", vi.fn((_input, init) => new Promise((_resolve, reject) => {
|
|
220
|
+
init?.signal?.addEventListener("abort", () => {
|
|
221
|
+
reject(Object.assign(new Error("aborted"), {
|
|
222
|
+
name: "AbortError"
|
|
223
|
+
}));
|
|
224
|
+
});
|
|
225
|
+
})));
|
|
226
|
+
const {
|
|
227
|
+
configurePlugins
|
|
228
|
+
} = await importHost();
|
|
229
|
+
const plugin = capture();
|
|
230
|
+
configurePlugins([plugin.plugin], {
|
|
231
|
+
baseURL: "https://updates.example.com",
|
|
232
|
+
requestTimeout: 2_000
|
|
233
|
+
});
|
|
234
|
+
const request = plugin.context().fetch("events");
|
|
235
|
+
const settled = expect(request).rejects.toThrow("Request timed out");
|
|
236
|
+
await vi.advanceTimersByTimeAsync(2_000);
|
|
237
|
+
await settled;
|
|
238
|
+
});
|
|
239
|
+
it("refuses a URL outside baseURL", async () => {
|
|
240
|
+
const {
|
|
241
|
+
configurePlugins
|
|
242
|
+
} = await importHost();
|
|
243
|
+
const plugin = capture();
|
|
244
|
+
configurePlugins([plugin.plugin], {
|
|
245
|
+
baseURL: "https://updates.example.com"
|
|
246
|
+
});
|
|
247
|
+
await expect(plugin.context().fetch("https://elsewhere.example.com/events")).rejects.toThrow("relative to baseURL");
|
|
248
|
+
});
|
|
249
|
+
});
|
|
250
|
+
describe("storage", () => {
|
|
251
|
+
it("scopes keys to the plugin and reads its own writes", async () => {
|
|
252
|
+
mocks.getStorageItem.mockReturnValue("from-native");
|
|
253
|
+
const {
|
|
254
|
+
configurePlugins
|
|
255
|
+
} = await importHost();
|
|
256
|
+
const plugin = capture("example");
|
|
257
|
+
configurePlugins([plugin.plugin], {
|
|
258
|
+
baseURL: "https://updates.example.com"
|
|
259
|
+
});
|
|
260
|
+
const {
|
|
261
|
+
storage
|
|
262
|
+
} = plugin.context();
|
|
263
|
+
expect(storage.get("state")).toBe("from-native");
|
|
264
|
+
expect(storage.get("state")).toBe("from-native");
|
|
265
|
+
storage.set("state", "next");
|
|
266
|
+
expect(storage.get("state")).toBe("next");
|
|
267
|
+
storage.set("state", null);
|
|
268
|
+
expect(storage.get("state")).toBeNull();
|
|
269
|
+
expect(mocks.getStorageItem).toHaveBeenCalledOnce();
|
|
270
|
+
expect(mocks.getStorageItem).toHaveBeenCalledWith("plugins/example/state");
|
|
271
|
+
expect(mocks.setStorageItem.mock.calls).toEqual([["plugins/example/state", "next"], ["plugins/example/state", null]]);
|
|
272
|
+
});
|
|
273
|
+
it("refuses empty keys, non-string values, and values over 64 KB", async () => {
|
|
274
|
+
const {
|
|
275
|
+
configurePlugins
|
|
276
|
+
} = await importHost();
|
|
277
|
+
const plugin = capture();
|
|
278
|
+
configurePlugins([plugin.plugin], {
|
|
279
|
+
baseURL: "https://updates.example.com"
|
|
280
|
+
});
|
|
281
|
+
const {
|
|
282
|
+
storage
|
|
283
|
+
} = plugin.context();
|
|
284
|
+
expect(() => storage.get("")).toThrow("non-empty strings");
|
|
285
|
+
expect(() => storage.set("key", 1)).toThrow("strings or null");
|
|
286
|
+
expect(() => storage.set("key", "x".repeat(64 * 1024 + 1))).toThrow("at most 64 KB");
|
|
287
|
+
expect(mocks.setStorageItem).not.toHaveBeenCalled();
|
|
288
|
+
});
|
|
289
|
+
});
|
|
290
|
+
});
|
|
291
|
+
//# sourceMappingURL=pluginHost.spec.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":["afterEach","beforeEach","describe","expect","it","vi","mock","Platform","OS","mocks","hoisted","Reflect","set","globalThis","SDK_VERSION","getAppVersion","fn","getBundleId","getChannel","getCohort","getFingerprintHash","getInstallId","getStorageItem","setStorageItem","importHost","capture","id","context","setup","pluginContext","plugin","resetModules","Object","values","mockClear","mockReturnValue","useRealTimers","unstubAllGlobals","restoreAllMocks","configurePlugins","baseURL","toThrow","emitPluginHook","onAppReady","config","status","channel","bundleId","releaseId","previousProcessExit","toHaveBeenCalledOnce","warn","spyOn","console","mockImplementation","healthy","Error","toHaveBeenCalledWith","objectContaining","message","onUpdateCheck","Promise","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","get","useFakeTimers","_input","_resolve","reject","signal","addEventListener","assign","name","requestTimeout","request","settled","rejects","advanceTimersByTimeAsync","storage","toBeNull","repeat"],"sourceRoot":"../../src","sources":["pluginHost.spec.ts"],"mappings":";;AAAA,SAASA,SAAS,EAAEC,UAAU,EAAEC,QAAQ,EAAEC,MAAM,EAAEC,EAAE,EAAEC,EAAE,QAAQ,QAAQ;AAOxEA,EAAE,CAACC,IAAI,CAAC,cAAc,EAAE,OAAO;EAC7BC,QAAQ,EAAE;IAAEC,EAAE,EAAE;EAAU;AAC5B,CAAC,CAAC,CAAC;AAEH,MAAMC,KAAK,GAAGJ,EAAE,CAACK,OAAO,CAAC,MAAM;EAC7BC,OAAO,CAACC,GAAG,CAACC,UAAU,EAAE,YAAY,EAAE;IAAEC,WAAW,EAAE;EAAmB,CAAC,CAAC;EAC1E,OAAO;IACLC,aAAa,EAAEV,EAAE,CAACW,EAAE,CAAsB,MAAM,OAAO,CAAC;IACxDC,WAAW,EAAEZ,EAAE,CAACW,EAAE,CAAC,MAAM,WAAW,CAAC;IACrCE,UAAU,EAAEb,EAAE,CAACW,EAAE,CAAC,MAAM,YAAY,CAAC;IACrCG,SAAS,EAAEd,EAAE,CAACW,EAAE,CAAC,MAAM,KAAK,CAA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ChC,CAAC;IACJ,CAAC,CAAC;IAEF1E,EAAE,CAAC,8DAA8D,EAAE,YAAY;MAC7E,MAAM;QAAEmC;MAAiB,CAAC,GAAG,MAAMf,UAAU,CAAC,CAAC;MAC/C,MAAMM,MAAM,GAAGL,OAAO,CAAC,CAAC;MACxBc,gBAAgB,CAAC,CAACT,MAAM,CAACA,MAAM,CAAC,EAAE;QAChCU,OAAO,EAAE;MACX,CAAC,CAAC;MACF,MAAM;QAAEgE;MAAQ,CAAC,GAAG1E,MAAM,CAACH,OAAO,CAAC,CAAC;MAEpCxB,MAAM,CAAC,MAAMqG,OAAO,CAACd,GAAG,CAAC,EAAE,CAAC,CAAC,CAACjD,OAAO,CAAC,mBAAmB,CAAC;MAC1DtC,MAAM,CAAC,MAAMqG,OAAO,CAAC5F,GAAG,CAAC,KAAK,EAAE,CAAsB,CAAC,CAAC,CAAC6B,OAAO,CAC9D,iBACF,CAAC;MACDtC,MAAM,CAAC,MAAMqG,OAAO,CAAC5F,GAAG,CAAC,KAAK,EAAE,GAAG,CAAC8F,MAAM,CAAC,EAAE,GAAG,IAAI,GAAG,CAAC,CAAC,CAAC,CAAC,CAACjE,OAAO,CACjE,eACF,CAAC;MACDtC,MAAM,CAACM,KAAK,CAACc,cAAc,CAAC,CAAC2C,GAAG,CAACC,gBAAgB,CAAC,CAAC;IACrD,CAAC,CAAC;EACJ,CAAC,CAAC;AACJ,CAAC,CAAC","ignoreList":[]}
|
|
@@ -0,0 +1,122 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
const formatUUIDv7 = (bytes, timestamp) => {
|
|
4
|
+
// Division, not bit shifts: shifts truncate to 32 bits, and a millisecond
|
|
5
|
+
// timestamp already needs 41.
|
|
6
|
+
let time = timestamp;
|
|
7
|
+
for (let index = 5; index >= 0; index -= 1) {
|
|
8
|
+
bytes[index] = time % 256;
|
|
9
|
+
time = Math.floor(time / 256);
|
|
10
|
+
}
|
|
11
|
+
bytes[6] = 0x70 | bytes[6] & 0x0f;
|
|
12
|
+
bytes[8] = 0x80 | bytes[8] & 0x3f;
|
|
13
|
+
const hex = Array.from(bytes, byte => byte.toString(16).padStart(2, "0")).join("");
|
|
14
|
+
return `${hex.slice(0, 8)}-${hex.slice(8, 12)}-${hex.slice(12, 16)}-${hex.slice(16, 20)}-${hex.slice(20)}`;
|
|
15
|
+
};
|
|
16
|
+
|
|
17
|
+
/**
|
|
18
|
+
* Creates an RFC 9562 UUIDv7: a 48-bit millisecond timestamp, then random bits.
|
|
19
|
+
*
|
|
20
|
+
* `createUUIDv7` from `@hot-updater/plugin-core` calls `crypto.getRandomValues`
|
|
21
|
+
* unconditionally, but React Native has no Web Crypto unless the app installs a
|
|
22
|
+
* polyfill. An Insights event ID only has to tell one event from another so a
|
|
23
|
+
* retried POST is counted once, so `Math.random` is enough without one.
|
|
24
|
+
*/
|
|
25
|
+
export const createUUIDv7 = () => {
|
|
26
|
+
const bytes = new Uint8Array(16);
|
|
27
|
+
const {
|
|
28
|
+
crypto
|
|
29
|
+
} = globalThis;
|
|
30
|
+
if (typeof crypto?.getRandomValues === "function") {
|
|
31
|
+
crypto.getRandomValues(bytes);
|
|
32
|
+
} else {
|
|
33
|
+
for (let index = 0; index < bytes.length; index += 1) {
|
|
34
|
+
bytes[index] = Math.floor(Math.random() * 256);
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
return formatUUIDv7(bytes, Date.now());
|
|
38
|
+
};
|
|
39
|
+
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];
|
|
40
|
+
const encodeUtf8 = value => {
|
|
41
|
+
const bytes = [];
|
|
42
|
+
for (const character of value) {
|
|
43
|
+
const code = character.codePointAt(0);
|
|
44
|
+
if (code < 0x80) {
|
|
45
|
+
bytes.push(code);
|
|
46
|
+
} else if (code < 0x800) {
|
|
47
|
+
bytes.push(0xc0 | code >> 6, 0x80 | code & 0x3f);
|
|
48
|
+
} else if (code < 0x10000) {
|
|
49
|
+
bytes.push(0xe0 | code >> 12, 0x80 | code >> 6 & 0x3f, 0x80 | code & 0x3f);
|
|
50
|
+
} else {
|
|
51
|
+
bytes.push(0xf0 | code >> 18, 0x80 | code >> 12 & 0x3f, 0x80 | code >> 6 & 0x3f, 0x80 | code & 0x3f);
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
return bytes;
|
|
55
|
+
};
|
|
56
|
+
|
|
57
|
+
/** SHA-256 of a string's UTF-8 bytes, since React Native has no Web Crypto. */
|
|
58
|
+
export const sha256 = value => {
|
|
59
|
+
const bytes = encodeUtf8(value);
|
|
60
|
+
const bitLength = bytes.length * 8;
|
|
61
|
+
bytes.push(0x80);
|
|
62
|
+
while (bytes.length % 64 !== 56) bytes.push(0);
|
|
63
|
+
for (let shift = 56; shift >= 0; shift -= 8) {
|
|
64
|
+
// The length's high word, as division, since shifts truncate to 32 bits.
|
|
65
|
+
bytes.push(shift >= 32 ? Math.floor(bitLength / 2 ** shift) & 0xff : bitLength >>> shift & 0xff);
|
|
66
|
+
}
|
|
67
|
+
const hash = [0x6a09e667, 0xbb67ae85, 0x3c6ef372, 0xa54ff53a, 0x510e527f, 0x9b05688c, 0x1f83d9ab, 0x5be0cd19];
|
|
68
|
+
const words = Array.from({
|
|
69
|
+
length: 64
|
|
70
|
+
}, () => 0);
|
|
71
|
+
const rotate = (word, bits) => word >>> bits | word << 32 - bits;
|
|
72
|
+
for (let offset = 0; offset < bytes.length; offset += 64) {
|
|
73
|
+
for (let index = 0; index < 16; index += 1) {
|
|
74
|
+
const at = offset + index * 4;
|
|
75
|
+
words[index] = bytes[at] << 24 | bytes[at + 1] << 16 | bytes[at + 2] << 8 | bytes[at + 3];
|
|
76
|
+
}
|
|
77
|
+
for (let index = 16; index < 64; index += 1) {
|
|
78
|
+
const low = words[index - 15];
|
|
79
|
+
const high = words[index - 2];
|
|
80
|
+
const s0 = rotate(low, 7) ^ rotate(low, 18) ^ low >>> 3;
|
|
81
|
+
const s1 = rotate(high, 17) ^ rotate(high, 19) ^ high >>> 10;
|
|
82
|
+
words[index] = words[index - 16] + s0 + words[index - 7] + s1 | 0;
|
|
83
|
+
}
|
|
84
|
+
let [a, b, c, d, e, f, g, h] = hash;
|
|
85
|
+
for (let index = 0; index < 64; index += 1) {
|
|
86
|
+
const s1 = rotate(e, 6) ^ rotate(e, 11) ^ rotate(e, 25);
|
|
87
|
+
const choose = e & f ^ ~e & g;
|
|
88
|
+
const temp1 = h + s1 + choose + SHA256_K[index] + words[index] | 0;
|
|
89
|
+
const s0 = rotate(a, 2) ^ rotate(a, 13) ^ rotate(a, 22);
|
|
90
|
+
const majority = a & b ^ a & c ^ b & c;
|
|
91
|
+
const temp2 = s0 + majority | 0;
|
|
92
|
+
h = g;
|
|
93
|
+
g = f;
|
|
94
|
+
f = e;
|
|
95
|
+
e = d + temp1 | 0;
|
|
96
|
+
d = c;
|
|
97
|
+
c = b;
|
|
98
|
+
b = a;
|
|
99
|
+
a = temp1 + temp2 | 0;
|
|
100
|
+
}
|
|
101
|
+
const results = [a, b, c, d, e, f, g, h];
|
|
102
|
+
for (let index = 0; index < 8; index += 1) {
|
|
103
|
+
hash[index] = hash[index] + results[index] | 0;
|
|
104
|
+
}
|
|
105
|
+
}
|
|
106
|
+
const digest = new Uint8Array(32);
|
|
107
|
+
hash.forEach((word, index) => {
|
|
108
|
+
digest[index * 4] = word >>> 24 & 0xff;
|
|
109
|
+
digest[index * 4 + 1] = word >>> 16 & 0xff;
|
|
110
|
+
digest[index * 4 + 2] = word >>> 8 & 0xff;
|
|
111
|
+
digest[index * 4 + 3] = word & 0xff;
|
|
112
|
+
});
|
|
113
|
+
return digest;
|
|
114
|
+
};
|
|
115
|
+
|
|
116
|
+
/**
|
|
117
|
+
* A UUIDv7 derived from a key: its time field is `timestamp` and its random
|
|
118
|
+
* bits are the key's SHA-256, so the same key and time always give the same
|
|
119
|
+
* id, and a server that stores reports by id counts it once.
|
|
120
|
+
*/
|
|
121
|
+
export const createKeyedUUIDv7 = (key, timestamp) => formatUUIDv7(sha256(key).slice(0, 16), timestamp);
|
|
122
|
+
//# sourceMappingURL=eventId.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":["formatUUIDv7","bytes","timestamp","time","index","Math","floor","hex","Array","from","byte","toString","padStart","join","slice","createUUIDv7","Uint8Array","crypto","globalThis","getRandomValues","length","random","Date","now","SHA256_K","encodeUtf8","value","character","code","codePointAt","push","sha256","bitLength","shift","hash","words","rotate","word","bits","offset","at","low","high","s0","s1","a","b","c","d","e","f","g","h","choose","temp1","majority","temp2","results","digest","forEach","createKeyedUUIDv7","key"],"sourceRoot":"../../../../src","sources":["plugins/insights/eventId.ts"],"mappings":";;AAIA,MAAMA,YAAY,GAAGA,CAACC,KAAiB,EAAEC,SAAiB,KAAa;EACrE;EACA;EACA,IAAIC,IAAI,GAAGD,SAAS;EACpB,KAAK,I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