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

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 (240) hide show
  1. package/lib/commonjs/checkForUpdate.js +7 -9
  2. package/lib/commonjs/checkForUpdate.js.map +1 -1
  3. package/lib/commonjs/clientPlugin.js +7 -43
  4. package/lib/commonjs/clientPlugin.js.map +1 -1
  5. package/lib/commonjs/httpClient.js +7 -9
  6. package/lib/commonjs/httpClient.js.map +1 -1
  7. package/lib/commonjs/index.js +10 -0
  8. package/lib/commonjs/index.js.map +1 -1
  9. package/lib/commonjs/native.js +4 -4
  10. package/lib/commonjs/native.js.map +1 -1
  11. package/lib/commonjs/pluginHost.js +26 -190
  12. package/lib/commonjs/pluginHost.js.map +1 -1
  13. package/lib/commonjs/releaseCatalogCache.js +7 -59
  14. package/lib/commonjs/releaseCatalogCache.js.map +1 -1
  15. package/lib/commonjs/sdkVersion.js +1 -1
  16. package/lib/module/checkForUpdate.js +1 -3
  17. package/lib/module/checkForUpdate.js.map +1 -1
  18. package/lib/module/clientPlugin.js +1 -41
  19. package/lib/module/clientPlugin.js.map +1 -1
  20. package/lib/module/httpClient.js +1 -3
  21. package/lib/module/httpClient.js.map +1 -1
  22. package/lib/module/index.js +2 -0
  23. package/lib/module/index.js.map +1 -1
  24. package/lib/module/native.js +1 -1
  25. package/lib/module/native.js.map +1 -1
  26. package/lib/module/pluginHost.js +22 -187
  27. package/lib/module/pluginHost.js.map +1 -1
  28. package/lib/module/releaseCatalogCache.js +3 -54
  29. package/lib/module/releaseCatalogCache.js.map +1 -1
  30. package/lib/module/sdkVersion.js +1 -1
  31. package/lib/typescript/commonjs/checkForUpdate.d.ts.map +1 -1
  32. package/lib/typescript/commonjs/clientPlugin.d.ts +1 -184
  33. package/lib/typescript/commonjs/clientPlugin.d.ts.map +1 -1
  34. package/lib/typescript/commonjs/httpClient.d.ts +1 -2
  35. package/lib/typescript/commonjs/httpClient.d.ts.map +1 -1
  36. package/lib/typescript/commonjs/index.d.ts +1 -0
  37. package/lib/typescript/commonjs/index.d.ts.map +1 -1
  38. package/lib/typescript/commonjs/native.d.ts +1 -1
  39. package/lib/typescript/commonjs/native.d.ts.map +1 -1
  40. package/lib/typescript/commonjs/pluginHost.d.ts +3 -28
  41. package/lib/typescript/commonjs/pluginHost.d.ts.map +1 -1
  42. package/lib/typescript/commonjs/releaseCatalogCache.d.ts +1 -13
  43. package/lib/typescript/commonjs/releaseCatalogCache.d.ts.map +1 -1
  44. package/lib/typescript/commonjs/sdkVersion.d.ts +1 -1
  45. package/lib/typescript/commonjs/types.d.ts +1 -1
  46. package/lib/typescript/commonjs/types.d.ts.map +1 -1
  47. package/lib/typescript/commonjs/wrap.types.d.ts +2 -2
  48. package/lib/typescript/module/checkForUpdate.d.ts.map +1 -1
  49. package/lib/typescript/module/clientPlugin.d.ts +1 -184
  50. package/lib/typescript/module/clientPlugin.d.ts.map +1 -1
  51. package/lib/typescript/module/httpClient.d.ts +1 -2
  52. package/lib/typescript/module/httpClient.d.ts.map +1 -1
  53. package/lib/typescript/module/index.d.ts +1 -0
  54. package/lib/typescript/module/index.d.ts.map +1 -1
  55. package/lib/typescript/module/native.d.ts +1 -1
  56. package/lib/typescript/module/native.d.ts.map +1 -1
  57. package/lib/typescript/module/pluginHost.d.ts +3 -28
  58. package/lib/typescript/module/pluginHost.d.ts.map +1 -1
  59. package/lib/typescript/module/releaseCatalogCache.d.ts +1 -13
  60. package/lib/typescript/module/releaseCatalogCache.d.ts.map +1 -1
  61. package/lib/typescript/module/sdkVersion.d.ts +1 -1
  62. package/lib/typescript/module/types.d.ts +1 -1
  63. package/lib/typescript/module/types.d.ts.map +1 -1
  64. package/lib/typescript/module/wrap.types.d.ts +2 -2
  65. package/package.json +7 -16
  66. package/src/checkForUpdate.ts +4 -6
  67. package/src/clientPlugin.ts +17 -231
  68. package/src/httpClient.ts +4 -4
  69. package/src/index.ts +7 -0
  70. package/src/native.ts +1 -1
  71. package/src/pluginHost.ts +24 -241
  72. package/src/releaseCatalogCache.ts +7 -136
  73. package/src/sdkVersion.ts +1 -1
  74. package/src/types.ts +1 -1
  75. package/src/wrap.types.ts +2 -2
  76. package/android/src/test/java/com/hotupdater/BsdiffPatchTest.kt +0 -46
  77. package/android/src/test/java/com/hotupdater/BundleFileStorageServiceTest.kt +0 -2236
  78. package/android/src/test/java/com/hotupdater/HotUpdaterExceptionTest.kt +0 -220
  79. package/android/src/test/java/com/hotupdater/HotUpdaterImplTest.kt +0 -264
  80. package/android/src/test/java/com/hotupdater/HotUpdaterRecoveryStateTest.kt +0 -97
  81. package/android/src/test/java/com/hotupdater/InstallIdentityServiceTest.kt +0 -71
  82. package/android/src/test/java/com/hotupdater/KeyValueStorageServiceTest.kt +0 -106
  83. package/android/src/test/java/com/hotupdater/NativeConfigUtilsTest.kt +0 -20
  84. package/android/src/test/java/com/hotupdater/NoBackupContext.kt +0 -11
  85. package/android/src/test/java/com/hotupdater/OkHttpDownloadServiceTest.kt +0 -397
  86. package/android/src/test/java/com/hotupdater/PendingCrashRecoveryTest.kt +0 -44
  87. package/android/src/test/java/com/hotupdater/PreviousProcessExitTest.kt +0 -57
  88. package/android/src/test/java/com/hotupdater/RelativePathResolverTest.kt +0 -41
  89. package/android/src/test/java/com/hotupdater/ReleaseCatalogCacheServiceTest.kt +0 -118
  90. package/android/src/test/java/com/hotupdater/TarBrArchiveExtractorTest.kt +0 -206
  91. package/lib/commonjs/appReady.spec.js +0 -360
  92. package/lib/commonjs/appReady.spec.js.map +0 -1
  93. package/lib/commonjs/appReady.test-utils.js +0 -25
  94. package/lib/commonjs/appReady.test-utils.js.map +0 -1
  95. package/lib/commonjs/baseURL.js +0 -16
  96. package/lib/commonjs/baseURL.js.map +0 -1
  97. package/lib/commonjs/catalogCacheNative.spec.js +0 -31
  98. package/lib/commonjs/catalogCacheNative.spec.js.map +0 -1
  99. package/lib/commonjs/checkForUpdate.releaseCatalog.spec.js +0 -936
  100. package/lib/commonjs/checkForUpdate.releaseCatalog.spec.js.map +0 -1
  101. package/lib/commonjs/entryImportGraph.spec.js +0 -50
  102. package/lib/commonjs/entryImportGraph.spec.js.map +0 -1
  103. package/lib/commonjs/httpClient.spec.js +0 -171
  104. package/lib/commonjs/httpClient.spec.js.map +0 -1
  105. package/lib/commonjs/index.spec.js +0 -395
  106. package/lib/commonjs/index.spec.js.map +0 -1
  107. package/lib/commonjs/iosInterop.spec.js +0 -18
  108. package/lib/commonjs/iosInterop.spec.js.map +0 -1
  109. package/lib/commonjs/native.spec.js +0 -910
  110. package/lib/commonjs/native.spec.js.map +0 -1
  111. package/lib/commonjs/pluginHost.spec.js +0 -292
  112. package/lib/commonjs/pluginHost.spec.js.map +0 -1
  113. package/lib/commonjs/plugins/insights/eventId.js +0 -129
  114. package/lib/commonjs/plugins/insights/eventId.js.map +0 -1
  115. package/lib/commonjs/plugins/insights/eventId.spec.js +0 -47
  116. package/lib/commonjs/plugins/insights/eventId.spec.js.map +0 -1
  117. package/lib/commonjs/plugins/insights/index.js +0 -272
  118. package/lib/commonjs/plugins/insights/index.js.map +0 -1
  119. package/lib/commonjs/plugins/insights/insights.spec.js +0 -640
  120. package/lib/commonjs/plugins/insights/insights.spec.js.map +0 -1
  121. package/lib/commonjs/plugins/insights/sender.js +0 -128
  122. package/lib/commonjs/plugins/insights/sender.js.map +0 -1
  123. package/lib/commonjs/plugins/insights/sender.spec.js +0 -265
  124. package/lib/commonjs/plugins/insights/sender.spec.js.map +0 -1
  125. package/lib/commonjs/plugins/insights/state.js +0 -145
  126. package/lib/commonjs/plugins/insights/state.js.map +0 -1
  127. package/lib/commonjs/releaseCatalogCache.spec.js +0 -213
  128. package/lib/commonjs/releaseCatalogCache.spec.js.map +0 -1
  129. package/lib/commonjs/releaseCatalogCacheNativeContract.spec.js +0 -64
  130. package/lib/commonjs/releaseCatalogCacheNativeContract.spec.js.map +0 -1
  131. package/lib/commonjs/store.notification.spec.js +0 -84
  132. package/lib/commonjs/store.notification.spec.js.map +0 -1
  133. package/lib/commonjs/store.spec.js +0 -182
  134. package/lib/commonjs/store.spec.js.map +0 -1
  135. package/lib/commonjs/updateError.spec.js +0 -149
  136. package/lib/commonjs/updateError.spec.js.map +0 -1
  137. package/lib/commonjs/wrap.progress.spec.js +0 -195
  138. package/lib/commonjs/wrap.progress.spec.js.map +0 -1
  139. package/lib/commonjs/wrap.spec.js +0 -232
  140. package/lib/commonjs/wrap.spec.js.map +0 -1
  141. package/lib/module/appReady.spec.js +0 -359
  142. package/lib/module/appReady.spec.js.map +0 -1
  143. package/lib/module/appReady.test-utils.js +0 -19
  144. package/lib/module/appReady.test-utils.js.map +0 -1
  145. package/lib/module/baseURL.js +0 -11
  146. package/lib/module/baseURL.js.map +0 -1
  147. package/lib/module/catalogCacheNative.spec.js +0 -31
  148. package/lib/module/catalogCacheNative.spec.js.map +0 -1
  149. package/lib/module/checkForUpdate.releaseCatalog.spec.js +0 -935
  150. package/lib/module/checkForUpdate.releaseCatalog.spec.js.map +0 -1
  151. package/lib/module/entryImportGraph.spec.js +0 -50
  152. package/lib/module/entryImportGraph.spec.js.map +0 -1
  153. package/lib/module/httpClient.spec.js +0 -171
  154. package/lib/module/httpClient.spec.js.map +0 -1
  155. package/lib/module/index.spec.js +0 -394
  156. package/lib/module/index.spec.js.map +0 -1
  157. package/lib/module/iosInterop.spec.js +0 -18
  158. package/lib/module/iosInterop.spec.js.map +0 -1
  159. package/lib/module/native.spec.js +0 -909
  160. package/lib/module/native.spec.js.map +0 -1
  161. package/lib/module/pluginHost.spec.js +0 -291
  162. package/lib/module/pluginHost.spec.js.map +0 -1
  163. package/lib/module/plugins/insights/eventId.js +0 -122
  164. package/lib/module/plugins/insights/eventId.js.map +0 -1
  165. package/lib/module/plugins/insights/eventId.spec.js +0 -47
  166. package/lib/module/plugins/insights/eventId.spec.js.map +0 -1
  167. package/lib/module/plugins/insights/index.js +0 -268
  168. package/lib/module/plugins/insights/index.js.map +0 -1
  169. package/lib/module/plugins/insights/insights.spec.js +0 -639
  170. package/lib/module/plugins/insights/insights.spec.js.map +0 -1
  171. package/lib/module/plugins/insights/sender.js +0 -123
  172. package/lib/module/plugins/insights/sender.js.map +0 -1
  173. package/lib/module/plugins/insights/sender.spec.js +0 -265
  174. package/lib/module/plugins/insights/sender.spec.js.map +0 -1
  175. package/lib/module/plugins/insights/state.js +0 -139
  176. package/lib/module/plugins/insights/state.js.map +0 -1
  177. package/lib/module/releaseCatalogCache.spec.js +0 -213
  178. package/lib/module/releaseCatalogCache.spec.js.map +0 -1
  179. package/lib/module/releaseCatalogCacheNativeContract.spec.js +0 -64
  180. package/lib/module/releaseCatalogCacheNativeContract.spec.js.map +0 -1
  181. package/lib/module/store.notification.spec.js +0 -85
  182. package/lib/module/store.notification.spec.js.map +0 -1
  183. package/lib/module/store.spec.js +0 -181
  184. package/lib/module/store.spec.js.map +0 -1
  185. package/lib/module/updateError.spec.js +0 -149
  186. package/lib/module/updateError.spec.js.map +0 -1
  187. package/lib/module/wrap.progress.spec.js +0 -196
  188. package/lib/module/wrap.progress.spec.js.map +0 -1
  189. package/lib/module/wrap.spec.js +0 -233
  190. package/lib/module/wrap.spec.js.map +0 -1
  191. package/lib/typescript/commonjs/appReady.test-utils.d.ts +0 -9
  192. package/lib/typescript/commonjs/appReady.test-utils.d.ts.map +0 -1
  193. package/lib/typescript/commonjs/baseURL.d.ts +0 -4
  194. package/lib/typescript/commonjs/baseURL.d.ts.map +0 -1
  195. package/lib/typescript/commonjs/plugins/insights/eventId.d.ts +0 -18
  196. package/lib/typescript/commonjs/plugins/insights/eventId.d.ts.map +0 -1
  197. package/lib/typescript/commonjs/plugins/insights/index.d.ts +0 -40
  198. package/lib/typescript/commonjs/plugins/insights/index.d.ts.map +0 -1
  199. package/lib/typescript/commonjs/plugins/insights/sender.d.ts +0 -74
  200. package/lib/typescript/commonjs/plugins/insights/sender.d.ts.map +0 -1
  201. package/lib/typescript/commonjs/plugins/insights/state.d.ts +0 -46
  202. package/lib/typescript/commonjs/plugins/insights/state.d.ts.map +0 -1
  203. package/lib/typescript/module/appReady.test-utils.d.ts +0 -9
  204. package/lib/typescript/module/appReady.test-utils.d.ts.map +0 -1
  205. package/lib/typescript/module/baseURL.d.ts +0 -4
  206. package/lib/typescript/module/baseURL.d.ts.map +0 -1
  207. package/lib/typescript/module/plugins/insights/eventId.d.ts +0 -18
  208. package/lib/typescript/module/plugins/insights/eventId.d.ts.map +0 -1
  209. package/lib/typescript/module/plugins/insights/index.d.ts +0 -40
  210. package/lib/typescript/module/plugins/insights/index.d.ts.map +0 -1
  211. package/lib/typescript/module/plugins/insights/sender.d.ts +0 -74
  212. package/lib/typescript/module/plugins/insights/sender.d.ts.map +0 -1
  213. package/lib/typescript/module/plugins/insights/state.d.ts +0 -46
  214. package/lib/typescript/module/plugins/insights/state.d.ts.map +0 -1
  215. package/plugins/insights/package.json +0 -8
  216. package/src/appReady.spec.ts +0 -393
  217. package/src/appReady.test-utils.ts +0 -31
  218. package/src/baseURL.ts +0 -15
  219. package/src/catalogCacheNative.spec.ts +0 -63
  220. package/src/checkForUpdate.releaseCatalog.spec.ts +0 -966
  221. package/src/entryImportGraph.spec.ts +0 -65
  222. package/src/httpClient.spec.ts +0 -216
  223. package/src/index.spec.ts +0 -434
  224. package/src/iosInterop.spec.ts +0 -30
  225. package/src/native.spec.ts +0 -978
  226. package/src/pluginHost.spec.ts +0 -297
  227. package/src/plugins/insights/eventId.spec.ts +0 -60
  228. package/src/plugins/insights/eventId.ts +0 -171
  229. package/src/plugins/insights/index.ts +0 -367
  230. package/src/plugins/insights/insights.spec.ts +0 -732
  231. package/src/plugins/insights/sender.spec.ts +0 -287
  232. package/src/plugins/insights/sender.ts +0 -221
  233. package/src/plugins/insights/state.ts +0 -184
  234. package/src/releaseCatalogCache.spec.ts +0 -304
  235. package/src/releaseCatalogCacheNativeContract.spec.ts +0 -80
  236. package/src/store.notification.spec.ts +0 -102
  237. package/src/store.spec.ts +0 -215
  238. package/src/updateError.spec.ts +0 -144
  239. package/src/wrap.progress.spec.ts +0 -232
  240. package/src/wrap.spec.ts +0 -262
@@ -1,65 +0,0 @@
1
- import { existsSync, readFileSync } from "node:fs";
2
- import { dirname, join, relative, resolve } from "node:path";
3
- import { fileURLToPath } from "node:url";
4
-
5
- import { describe, expect, it } from "vitest";
6
-
7
- const sourceRoot = dirname(fileURLToPath(import.meta.url));
8
-
9
- /** Every relative module a file imports, statically or dynamically. */
10
- const readImports = (file: string): string[] => {
11
- const source = readFileSync(file, "utf8");
12
- const specifiers = [
13
- ...source.matchAll(/\b(?:import|export)\s[^;]*?\bfrom\s*["']([^"']+)["']/g),
14
- ...source.matchAll(/\bimport\s*["']([^"']+)["']/g),
15
- ...source.matchAll(/\bimport\(\s*["']([^"']+)["']\s*\)/g),
16
- ].map((match) => match[1]!);
17
- return specifiers.filter((specifier) => specifier.startsWith("."));
18
- };
19
-
20
- const resolveModule = (from: string, specifier: string): string => {
21
- const base = resolve(dirname(from), specifier);
22
- const file = [
23
- `${base}.ts`,
24
- `${base}.tsx`,
25
- join(base, "index.ts"),
26
- join(base, "index.tsx"),
27
- ].find((path) => existsSync(path));
28
- if (file === undefined) {
29
- throw new Error(`Cannot resolve ${specifier} from ${from}`);
30
- }
31
- return file;
32
- };
33
-
34
- const collectGraph = (entry: string): Set<string> => {
35
- const seen = new Set<string>();
36
- const pending = [entry];
37
- while (pending.length > 0) {
38
- const file = pending.pop()!;
39
- if (seen.has(file)) continue;
40
- seen.add(file);
41
- for (const specifier of readImports(file)) {
42
- pending.push(resolveModule(file, specifier));
43
- }
44
- }
45
- return seen;
46
- };
47
-
48
- describe("@hot-updater/react-native root entry", () => {
49
- const graph = [...collectGraph(join(sourceRoot, "index.ts"))].map((file) =>
50
- relative(sourceRoot, file),
51
- );
52
-
53
- it("bundles no plugin, since Metro does not tree-shake", () => {
54
- expect(graph).toContain("pluginHost.ts");
55
- expect(graph.filter((file) => file.startsWith("plugins/"))).toEqual([]);
56
- });
57
-
58
- it("sends no Insights request", () => {
59
- const insightsCode = graph.filter((file) => {
60
- const source = readFileSync(join(sourceRoot, file), "utf8");
61
- return /["'`/]events["'`]/.test(source);
62
- });
63
- expect(insightsCode).toEqual([]);
64
- });
65
- });
@@ -1,216 +0,0 @@
1
- import type { ArtifactInfo, ReleaseCatalog } from "@hot-updater/core";
2
- import { beforeEach, describe, expect, it, vi } from "vitest";
3
-
4
- import { FetchJSONResponseError } from "./fetchJSON";
5
- import { createHttpClient } from "./httpClient";
6
- import { InvalidUpdateResponseError } from "./updateError";
7
-
8
- const mocks = vi.hoisted(() => ({
9
- fetchCatalog: vi.fn(),
10
- fetchJSON: vi.fn(),
11
- }));
12
-
13
- vi.mock("./releaseCatalogCache", () => ({
14
- fetchReleaseCatalogWithCache: mocks.fetchCatalog,
15
- }));
16
-
17
- vi.mock("./fetchJSON", () => ({
18
- FetchJSONResponseError: class FetchJSONResponseError extends Error {
19
- constructor(
20
- readonly status: number,
21
- statusText: string,
22
- ) {
23
- super(statusText);
24
- }
25
- },
26
- fetchJSON: mocks.fetchJSON,
27
- }));
28
-
29
- const artifact: ArtifactInfo = {
30
- artifactProtocolVersion: 1,
31
- assets: {
32
- "index.ios.bundle": {
33
- file: { url: "/storage/index.bundle.br" },
34
- fileHash: "bundle-hash",
35
- },
36
- },
37
- manifestFileHash: "manifest-hash",
38
- manifestUrl: "/storage/manifest.json",
39
- archiveUrl: "/storage/bundle.tar.br",
40
- };
41
-
42
- const catalog: ReleaseCatalog = {
43
- catalogId: "server-owned-project",
44
- catalogHash: `sha256:${"a".repeat(64)}`,
45
- fallbackPolicy: "BUILTIN_IF_ACTIVE_INELIGIBLE",
46
- generation: 1,
47
- releases: [],
48
- schemaVersion: 1,
49
- scopeKey: "v1:app-version:server-owned-project:ios:cHJvZHVjdGlvbg",
50
- };
51
-
52
- describe("private HotUpdater HTTP client", () => {
53
- beforeEach(() => {
54
- vi.clearAllMocks();
55
- mocks.fetchCatalog.mockResolvedValue(catalog);
56
- mocks.fetchJSON.mockResolvedValue(artifact);
57
- });
58
-
59
- it("fetches a catalog without putting its internal identity in the route", async () => {
60
- const session = await createHttpClient(
61
- "https://updates.example.com/hot-updater/",
62
- ).createSession();
63
-
64
- await expect(
65
- session.fetchReleaseCatalog({
66
- appVersion: "1.2.0",
67
- channel: "production",
68
- fingerprintHash: null,
69
- platform: "ios",
70
- updateStrategy: "appVersion",
71
- }),
72
- ).resolves.toBe(catalog);
73
-
74
- expect(mocks.fetchCatalog).toHaveBeenCalledWith({
75
- baseURL: "https://updates.example.com/hot-updater",
76
- expectedScope: {
77
- channelKey: "cHJvZHVjdGlvbg",
78
- platform: "ios",
79
- strategy: "APP_VERSION",
80
- },
81
- requestHeaders: undefined,
82
- requestTimeout: undefined,
83
- url: "https://updates.example.com/hot-updater/release-catalogs/app-version/ios/cHJvZHVjdGlvbg/1.2.0",
84
- });
85
- });
86
-
87
- it("resolves a functional baseURL once per session and captures it for a deferred artifact", async () => {
88
- const resolveBaseURL = vi
89
- .fn()
90
- .mockResolvedValueOnce("https://first.example.com/hot-updater")
91
- .mockResolvedValueOnce("https://second.example.com/hot-updater");
92
- const client = createHttpClient(resolveBaseURL);
93
- const firstSession = await client.createSession();
94
-
95
- await firstSession.fetchReleaseCatalog({
96
- appVersion: "1.2.0",
97
- channel: "production",
98
- fingerprintHash: null,
99
- platform: "ios",
100
- updateStrategy: "appVersion",
101
- });
102
- await expect(
103
- firstSession.resolveArtifact({
104
- currentBundleId: "current",
105
- targetBundleId: "target",
106
- }),
107
- ).resolves.toEqual({
108
- ...artifact,
109
- assets: {
110
- "index.ios.bundle": {
111
- file: {
112
- url: "https://first.example.com/hot-updater/storage/index.bundle.br",
113
- },
114
- fileHash: "bundle-hash",
115
- },
116
- },
117
- manifestUrl:
118
- "https://first.example.com/hot-updater/storage/manifest.json",
119
- archiveUrl: "https://first.example.com/hot-updater/storage/bundle.tar.br",
120
- });
121
-
122
- expect(resolveBaseURL).toHaveBeenCalledOnce();
123
- expect(mocks.fetchJSON).toHaveBeenCalledWith({
124
- requestHeaders: undefined,
125
- requestTimeout: undefined,
126
- url: "https://first.example.com/hot-updater/artifacts/v1/target/from/current",
127
- });
128
-
129
- await client.createSession();
130
- expect(resolveBaseURL).toHaveBeenCalledTimes(2);
131
- });
132
-
133
- it("rejects non-storage relative artifact URLs", async () => {
134
- mocks.fetchJSON.mockResolvedValue({
135
- ...artifact,
136
- assets: {
137
- "index.ios.bundle": {
138
- file: { url: "/private/index.bundle.br" },
139
- fileHash: "bundle-hash",
140
- },
141
- },
142
- });
143
- const session = await createHttpClient(
144
- "https://updates.example.com",
145
- ).createSession();
146
-
147
- await expect(
148
- session.resolveArtifact({
149
- currentBundleId: "current",
150
- targetBundleId: "target",
151
- }),
152
- ).rejects.toThrow("client-relative storage paths");
153
- });
154
-
155
- it("rejects a legacy artifact response", async () => {
156
- mocks.fetchJSON.mockResolvedValue({
157
- fileHash: "archive-hash",
158
- fileUrl: "/storage/bundle.zip",
159
- });
160
- const session = await createHttpClient(
161
- "https://updates.example.com",
162
- ).createSession();
163
-
164
- await expect(
165
- session.resolveArtifact({
166
- currentBundleId: "current",
167
- targetBundleId: "target",
168
- }),
169
- ).rejects.toThrow("does not support artifact protocol 1");
170
- });
171
-
172
- it("reports an old server without the v1 endpoint explicitly", async () => {
173
- mocks.fetchJSON.mockRejectedValue(
174
- new FetchJSONResponseError(404, "Not Found"),
175
- );
176
- const session = await createHttpClient(
177
- "https://updates.example.com",
178
- ).createSession();
179
-
180
- await expect(
181
- session.resolveArtifact({
182
- currentBundleId: "current",
183
- targetBundleId: "target",
184
- }),
185
- ).rejects.toThrow("does not support artifact protocol 1");
186
- });
187
-
188
- it.each([
189
- { label: "a legacy response", response: { fileUrl: "/storage/a.zip" } },
190
- {
191
- label: "an invalid absolute URL",
192
- response: {
193
- ...artifact,
194
- manifestUrl: "https://",
195
- },
196
- },
197
- ])("marks $label as an invalid update response", async ({ response }) => {
198
- mocks.fetchJSON.mockResolvedValue(response);
199
- const session = await createHttpClient(
200
- "https://updates.example.com",
201
- ).createSession();
202
-
203
- await expect(
204
- session.resolveArtifact({
205
- currentBundleId: "current",
206
- targetBundleId: "target",
207
- }),
208
- ).rejects.toBeInstanceOf(InvalidUpdateResponseError);
209
- });
210
-
211
- it("requires a functional baseURL to resolve to a non-empty string", async () => {
212
- await expect(createHttpClient(() => "").createSession()).rejects.toThrow(
213
- "baseURL function must return a non-empty string",
214
- );
215
- });
216
- });