@hot-updater/react-native 1.0.6 → 1.0.7

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 (46) hide show
  1. package/android/src/newarch/HotUpdaterModule.kt +108 -57
  2. package/android/src/oldarch/HotUpdaterModule.kt +109 -57
  3. package/android/src/oldarch/HotUpdaterSpec.kt +5 -0
  4. package/ios/HotUpdater/Interface/HotUpdaterInterface.h +3 -0
  5. package/ios/HotUpdater/Internal/HotUpdater.mm +49 -0
  6. package/ios/HotUpdater/Internal/HotUpdaterImpl.swift +150 -62
  7. package/lib/commonjs/checkForUpdate.js +16 -9
  8. package/lib/commonjs/checkForUpdate.js.map +1 -1
  9. package/lib/commonjs/httpClient.js +14 -20
  10. package/lib/commonjs/httpClient.js.map +1 -1
  11. package/lib/commonjs/native.js +36 -10
  12. package/lib/commonjs/native.js.map +1 -1
  13. package/lib/commonjs/sdkVersion.js +1 -1
  14. package/lib/commonjs/specs/NativeHotUpdater.js +5 -0
  15. package/lib/commonjs/specs/NativeHotUpdater.js.map +1 -1
  16. package/lib/module/checkForUpdate.js +17 -10
  17. package/lib/module/checkForUpdate.js.map +1 -1
  18. package/lib/module/httpClient.js +14 -20
  19. package/lib/module/httpClient.js.map +1 -1
  20. package/lib/module/native.js +35 -10
  21. package/lib/module/native.js.map +1 -1
  22. package/lib/module/sdkVersion.js +1 -1
  23. package/lib/module/specs/NativeHotUpdater.js +7 -0
  24. package/lib/module/specs/NativeHotUpdater.js.map +1 -1
  25. package/lib/typescript/commonjs/checkForUpdate.d.ts.map +1 -1
  26. package/lib/typescript/commonjs/httpClient.d.ts +20 -12
  27. package/lib/typescript/commonjs/httpClient.d.ts.map +1 -1
  28. package/lib/typescript/commonjs/native.d.ts +17 -3
  29. package/lib/typescript/commonjs/native.d.ts.map +1 -1
  30. package/lib/typescript/commonjs/sdkVersion.d.ts +1 -1
  31. package/lib/typescript/commonjs/specs/NativeHotUpdater.d.ts +31 -7
  32. package/lib/typescript/commonjs/specs/NativeHotUpdater.d.ts.map +1 -1
  33. package/lib/typescript/module/checkForUpdate.d.ts.map +1 -1
  34. package/lib/typescript/module/httpClient.d.ts +20 -12
  35. package/lib/typescript/module/httpClient.d.ts.map +1 -1
  36. package/lib/typescript/module/native.d.ts +17 -3
  37. package/lib/typescript/module/native.d.ts.map +1 -1
  38. package/lib/typescript/module/sdkVersion.d.ts +1 -1
  39. package/lib/typescript/module/specs/NativeHotUpdater.d.ts +31 -7
  40. package/lib/typescript/module/specs/NativeHotUpdater.d.ts.map +1 -1
  41. package/package.json +4 -4
  42. package/src/checkForUpdate.ts +13 -8
  43. package/src/httpClient.ts +35 -31
  44. package/src/native.ts +53 -16
  45. package/src/sdkVersion.ts +1 -1
  46. package/src/specs/NativeHotUpdater.ts +33 -7
package/src/native.ts CHANGED
@@ -1,6 +1,7 @@
1
1
  import {
2
2
  type ArtifactAsset,
3
3
  type CatalogHighWater,
4
+ type ChangedAssetPatch,
4
5
  INVALID_COHORT_ERROR_MESSAGE,
5
6
  isValidCohort,
6
7
  normalizeCohortValue,
@@ -11,6 +12,7 @@ import { NativeEventEmitter, Platform } from "react-native";
11
12
 
12
13
  import { HotUpdaterErrorCode, isHotUpdaterError } from "./error";
13
14
  import HotUpdaterNative, {
15
+ type InstallArtifactParams,
14
16
  type UpdateBundleParams,
15
17
  } from "./specs/NativeHotUpdater";
16
18
 
@@ -298,6 +300,25 @@ export type UpdateParams = UpdateBundleParams & {
298
300
  shouldSkipCurrentBundleIdCheck?: boolean;
299
301
  };
300
302
 
303
+ /** How the update check stages a Bundle over artifact protocol v2. */
304
+ export type InstallArtifactUpdateParams = Omit<
305
+ InstallArtifactParams,
306
+ "patch"
307
+ > & {
308
+ patch?: (ChangedAssetPatch & { assetPath: string }) | null;
309
+ status: UpdateStatus;
310
+ shouldSkipCurrentBundleIdCheck?: boolean;
311
+ };
312
+
313
+ /**
314
+ * Whether native installs artifact protocol v2. Native built from an SDK
315
+ * older than protocol v2 has no `installArtifact`, and an OTA can bring this
316
+ * JavaScript to such native code, so the update check then asks for v1.
317
+ */
318
+ export const supportsArtifactFiles = (): boolean =>
319
+ typeof (HotUpdaterNative as { installArtifact?: unknown }).installArtifact ===
320
+ "function";
321
+
301
322
  export interface ActiveUpdateState {
302
323
  readonly activeSelection: ActiveUpdateSelection | null;
303
324
  readonly stableSelection: ActiveUpdateSelection | null;
@@ -411,7 +432,7 @@ const readBundleDelivery = (value: unknown): BundleDelivery | null => {
411
432
  * @throws {Error} Rejects with error.code from HotUpdaterErrorCode enum and error.message
412
433
  */
413
434
  export async function stageBundle(
414
- params: UpdateParams,
435
+ params: UpdateParams | InstallArtifactUpdateParams,
415
436
  ): Promise<BundleDelivery | null> {
416
437
  const updateBundleId = params.bundleId;
417
438
  const status = params.status;
@@ -447,29 +468,45 @@ export async function stageBundle(
447
468
  if (existing) return existing;
448
469
 
449
470
  const targetChannel = params.channel;
450
- const targetManifestUrl = params.manifestUrl;
451
- const targetManifestFileHash = params.manifestFileHash;
452
- const targetAssets = params.assets;
453
471
 
454
472
  const promise = (async () => {
455
473
  try {
456
474
  const selection = params.selection;
457
- const staged = await HotUpdaterNative.updateBundle({
475
+ const common = {
458
476
  bundleId: updateBundleId,
459
477
  channel: targetChannel,
460
- assets: targetAssets as Record<string, ArtifactAsset>,
461
- manifestFileHash: targetManifestFileHash,
462
- manifestUrl: targetManifestUrl,
478
+ manifestFileHash: params.manifestFileHash,
479
+ manifestUrl: params.manifestUrl,
463
480
  ...(params.archiveUrl ? { archiveUrl: params.archiveUrl } : {}),
464
- ...(params.filesUrl ? { filesUrl: params.filesUrl } : {}),
465
- ...(params.filesUrl && params.requestHeaders
466
- ? { requestHeaders: params.requestHeaders }
467
- : {}),
468
- ...(params.filesUrl && params.requestTimeout
469
- ? { requestTimeout: params.requestTimeout }
470
- : {}),
471
481
  ...(selection === undefined ? {} : { selection }),
472
- });
482
+ };
483
+ const staged =
484
+ "assets" in params
485
+ ? // Legacy: artifact protocol v1, where every file comes with its
486
+ // URL, and the `filesUrl` form earlier releases documented, which
487
+ // native `updateBundle` keeps accepting.
488
+ await HotUpdaterNative.updateBundle({
489
+ ...common,
490
+ assets: params.assets as Record<string, ArtifactAsset>,
491
+ ...(params.filesUrl ? { filesUrl: params.filesUrl } : {}),
492
+ ...(params.filesUrl && params.requestHeaders
493
+ ? { requestHeaders: params.requestHeaders }
494
+ : {}),
495
+ ...(params.filesUrl && params.requestTimeout
496
+ ? { requestTimeout: params.requestTimeout }
497
+ : {}),
498
+ })
499
+ : await HotUpdaterNative.installArtifact({
500
+ ...common,
501
+ filesUrl: params.filesUrl,
502
+ ...(params.patch ? { patch: params.patch } : {}),
503
+ ...(params.requestHeaders
504
+ ? { requestHeaders: params.requestHeaders }
505
+ : {}),
506
+ ...(params.requestTimeout
507
+ ? { requestTimeout: params.requestTimeout }
508
+ : {}),
509
+ });
473
510
  sessionState.markBundleInstalled(updateBundleId, targetChannel);
474
511
  return readBundleDelivery(staged);
475
512
  } finally {
package/src/sdkVersion.ts CHANGED
@@ -1 +1 @@
1
- export const HOT_UPDATER_SDK_VERSION = "1.0.6";
1
+ export const HOT_UPDATER_SDK_VERSION = "1.0.7";
@@ -15,21 +15,40 @@ export interface UpdateBundleParams {
15
15
  manifestFileHash: string;
16
16
  /** Optional tar.br URL; integrity and sizes come from the verified manifest. */
17
17
  archiveUrl?: string | null;
18
- /**
19
- * Target file descriptors: every file with its URL in artifact protocol v1,
20
- * or only the Hermes patch in v2, where native asks `filesUrl`.
21
- */
18
+ /** Every target file with its download URL and optional Hermes patch. */
22
19
  assets: UnsafeObject;
23
20
  /**
24
- * Artifact protocol v2: where native POSTs the paths of the files it
25
- * downloads one by one, after reusing local files and choosing the archive.
21
+ * Legacy: JavaScript from the first artifact protocol v2 SDK sends these
22
+ * here, with only the Hermes patch in `assets`, and apps may pass them to
23
+ * `updateBundle` as that release documented. Native keeps accepting them so
24
+ * such OTA Bundles still install. The update check sends them to
25
+ * `installArtifact`.
26
26
  */
27
27
  filesUrl?: string | null;
28
+ requestHeaders?: UnsafeObject | null;
29
+ requestTimeout?: number | null;
30
+ /** Full Release Catalog selection receipt committed with the staged Bundle. */
31
+ selection?: UnsafeObject | null;
32
+ }
33
+
34
+ /**
35
+ * Artifact protocol v2: no URL per file. Native reuses local files, chooses
36
+ * the archive or files, and POSTs the paths it downloads one by one to
37
+ * `filesUrl` for their URLs.
38
+ */
39
+ export interface InstallArtifactParams {
40
+ bundleId: string;
41
+ channel?: string;
42
+ manifestUrl: string;
43
+ manifestFileHash: string;
44
+ archiveUrl?: string | null;
45
+ /** The Hermes bytecode patch from the running Bundle, with its `assetPath`. */
46
+ patch?: UnsafeObject | null;
47
+ filesUrl: string;
28
48
  /** Headers for the `filesUrl` request, as the update check sent them. */
29
49
  requestHeaders?: UnsafeObject | null;
30
50
  /** Milliseconds the `filesUrl` request may take, as the update check's. */
31
51
  requestTimeout?: number | null;
32
- /** Full Release Catalog selection receipt committed with the staged Bundle. */
33
52
  selection?: UnsafeObject | null;
34
53
  }
35
54
 
@@ -90,6 +109,13 @@ export interface Spec extends TurboModule {
90
109
  */
91
110
  updateBundle(params: UpdateBundleParams): Promise<UnsafeObject>;
92
111
 
112
+ /**
113
+ * Stages a Bundle over artifact protocol v2 and resolves like
114
+ * `updateBundle`. Native built from an SDK older than protocol v2 lacks
115
+ * it, so JS checks for it before asking the server for v2.
116
+ */
117
+ installArtifact(params: InstallArtifactParams): Promise<UnsafeObject>;
118
+
93
119
  /** Accepts and durably advances the catalog high-water for a scope. */
94
120
  acceptReleaseCatalog(params: UnsafeObject): boolean;
95
121