@hot-updater/react-native 1.0.0-rc.40 → 1.0.0-rc.42

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 (88) hide show
  1. package/lib/commonjs/appReady.js +25 -31
  2. package/lib/commonjs/appReady.js.map +1 -1
  3. package/lib/commonjs/checkForUpdate.js +9 -9
  4. package/lib/commonjs/checkForUpdate.js.map +1 -1
  5. package/lib/commonjs/error.js +1 -1
  6. package/lib/commonjs/httpClient.js +1 -1
  7. package/lib/commonjs/index.js +304 -326
  8. package/lib/commonjs/index.js.map +1 -1
  9. package/lib/commonjs/init.types.js +6 -0
  10. package/lib/commonjs/init.types.js.map +1 -0
  11. package/lib/commonjs/native.js +3 -3
  12. package/lib/commonjs/pluginHost.js +11 -15
  13. package/lib/commonjs/pluginHost.js.map +1 -1
  14. package/lib/commonjs/sdkVersion.js +1 -1
  15. package/lib/commonjs/wrap.js +7 -16
  16. package/lib/commonjs/wrap.js.map +1 -1
  17. package/lib/module/appReady.js +23 -28
  18. package/lib/module/appReady.js.map +1 -1
  19. package/lib/module/checkForUpdate.js +10 -10
  20. package/lib/module/checkForUpdate.js.map +1 -1
  21. package/lib/module/clientPlugin.js.map +1 -1
  22. package/lib/module/error.js +1 -1
  23. package/lib/module/httpClient.js +1 -1
  24. package/lib/module/index.js +299 -329
  25. package/lib/module/index.js.map +1 -1
  26. package/lib/module/init.types.js +4 -0
  27. package/lib/module/init.types.js.map +1 -0
  28. package/lib/module/native.js +3 -3
  29. package/lib/module/pluginHost.js +9 -9
  30. package/lib/module/pluginHost.js.map +1 -1
  31. package/lib/module/sdkVersion.js +1 -1
  32. package/lib/module/wrap.js +7 -15
  33. package/lib/module/wrap.js.map +1 -1
  34. package/lib/typescript/commonjs/appReady.d.ts +18 -9
  35. package/lib/typescript/commonjs/appReady.d.ts.map +1 -1
  36. package/lib/typescript/commonjs/checkForUpdate.d.ts +5 -3
  37. package/lib/typescript/commonjs/checkForUpdate.d.ts.map +1 -1
  38. package/lib/typescript/commonjs/clientPlugin.d.ts +1 -1
  39. package/lib/typescript/commonjs/clientPlugin.d.ts.map +1 -1
  40. package/lib/typescript/commonjs/error.d.ts +1 -1
  41. package/lib/typescript/commonjs/httpClient.d.ts +1 -1
  42. package/lib/typescript/commonjs/httpClient.d.ts.map +1 -1
  43. package/lib/typescript/commonjs/index.d.ts +122 -110
  44. package/lib/typescript/commonjs/index.d.ts.map +1 -1
  45. package/lib/typescript/commonjs/init.types.d.ts +21 -0
  46. package/lib/typescript/commonjs/init.types.d.ts.map +1 -0
  47. package/lib/typescript/commonjs/native.d.ts +3 -3
  48. package/lib/typescript/commonjs/pluginHost.d.ts +7 -3
  49. package/lib/typescript/commonjs/pluginHost.d.ts.map +1 -1
  50. package/lib/typescript/commonjs/sdkVersion.d.ts +1 -1
  51. package/lib/typescript/commonjs/wrap.d.ts +2 -3
  52. package/lib/typescript/commonjs/wrap.d.ts.map +1 -1
  53. package/lib/typescript/commonjs/wrap.types.d.ts +13 -40
  54. package/lib/typescript/commonjs/wrap.types.d.ts.map +1 -1
  55. package/lib/typescript/module/appReady.d.ts +18 -9
  56. package/lib/typescript/module/appReady.d.ts.map +1 -1
  57. package/lib/typescript/module/checkForUpdate.d.ts +5 -3
  58. package/lib/typescript/module/checkForUpdate.d.ts.map +1 -1
  59. package/lib/typescript/module/clientPlugin.d.ts +1 -1
  60. package/lib/typescript/module/clientPlugin.d.ts.map +1 -1
  61. package/lib/typescript/module/error.d.ts +1 -1
  62. package/lib/typescript/module/httpClient.d.ts +1 -1
  63. package/lib/typescript/module/httpClient.d.ts.map +1 -1
  64. package/lib/typescript/module/index.d.ts +122 -110
  65. package/lib/typescript/module/index.d.ts.map +1 -1
  66. package/lib/typescript/module/init.types.d.ts +21 -0
  67. package/lib/typescript/module/init.types.d.ts.map +1 -0
  68. package/lib/typescript/module/native.d.ts +3 -3
  69. package/lib/typescript/module/pluginHost.d.ts +7 -3
  70. package/lib/typescript/module/pluginHost.d.ts.map +1 -1
  71. package/lib/typescript/module/sdkVersion.d.ts +1 -1
  72. package/lib/typescript/module/wrap.d.ts +2 -3
  73. package/lib/typescript/module/wrap.d.ts.map +1 -1
  74. package/lib/typescript/module/wrap.types.d.ts +13 -40
  75. package/lib/typescript/module/wrap.types.d.ts.map +1 -1
  76. package/package.json +4 -3
  77. package/src/appReady.ts +43 -37
  78. package/src/checkForUpdate.ts +19 -11
  79. package/src/clientPlugin.ts +3 -0
  80. package/src/error.ts +1 -1
  81. package/src/httpClient.ts +1 -1
  82. package/src/index.ts +344 -422
  83. package/src/init.types.ts +24 -0
  84. package/src/native.ts +3 -3
  85. package/src/pluginHost.ts +16 -11
  86. package/src/sdkVersion.ts +1 -1
  87. package/src/wrap.tsx +6 -20
  88. package/src/wrap.types.ts +18 -45
@@ -0,0 +1,24 @@
1
+ import type { HotUpdaterClientPlugin } from "./clientPlugin";
2
+ import type { HotUpdaterError } from "./error";
3
+ import type { NotifyAppReadyResult } from "./native";
4
+ import type { HotUpdaterBaseURL } from "./types";
5
+
6
+ export interface HotUpdaterInitOptions<
7
+ TPlugins extends readonly HotUpdaterClientPlugin[] =
8
+ readonly HotUpdaterClientPlugin[],
9
+ > {
10
+ /**
11
+ * Client plugins, such as `insights()` and `remoteConfig()` from
12
+ * `@hot-updater/react-native`. Each plugin's `setup` runs once for the
13
+ * instance `init` returns; its hooks observe that instance's launch,
14
+ * update checks, downloads, and update failures, and its API is on the
15
+ * instance, under the plugin's id. Plugin ids must be unique.
16
+ */
17
+ plugins?: TPlugins;
18
+ /** Base URL of a server exposing the Hot Updater v1 client HTTP protocol. */
19
+ baseURL: HotUpdaterBaseURL;
20
+ requestHeaders?: Record<string, string>;
21
+ requestTimeout?: number;
22
+ onNotifyAppReady?: (result: NotifyAppReadyResult) => void;
23
+ onError?: (error: HotUpdaterError | Error | unknown) => void;
24
+ }
package/src/native.ts CHANGED
@@ -46,7 +46,7 @@ type ActiveBundleSnapshotCacheValues = {
46
46
  type ActiveBundleSnapshotCacheKey = keyof ActiveBundleSnapshotCacheValues;
47
47
 
48
48
  /**
49
- * Built-in reload behaviors used by `HotUpdater.reload()`.
49
+ * Built-in reload behaviors used by `hotUpdater.reload()`.
50
50
  *
51
51
  * - `reload`: In-process React Native reload.
52
52
  * - `processRestart`: Android-only cold restart. On iOS the same call behaves like `reload`.
@@ -578,7 +578,7 @@ export const reload = async () => {
578
578
  };
579
579
 
580
580
  /**
581
- * Configures how `HotUpdater.reload()` should behave.
581
+ * Configures how `hotUpdater.reload()` should behave.
582
582
  *
583
583
  * This API is available on both Android and iOS so app code can stay symmetric.
584
584
  * By default, HotUpdater uses `processRestart`.
@@ -959,7 +959,7 @@ export const readNotifyAppReady = (): {
959
959
  *
960
960
  * @example
961
961
  * ```ts
962
- * const result = HotUpdater.notifyAppReady();
962
+ * const result = hotUpdater.notifyAppReady();
963
963
  *
964
964
  * if (result.status === "RECOVERED") {
965
965
  * console.log(result.fromBundleId, result.toBundleId);
package/src/pluginHost.ts CHANGED
@@ -1,4 +1,8 @@
1
- import { createPluginHost } from "@hot-updater/protocol";
1
+ import {
2
+ createPluginHost,
3
+ type PluginHost,
4
+ type PluginHostEnvironment,
5
+ } from "@hot-updater/protocol";
2
6
  import { Platform } from "react-native";
3
7
 
4
8
  import {
@@ -14,16 +18,10 @@ import {
14
18
  } from "./native";
15
19
  import { HOT_UPDATER_SDK_VERSION } from "./sdkVersion";
16
20
 
17
- export type { PluginHostConfig } from "@hot-updater/protocol";
21
+ export type { PluginHost, PluginHostConfig } from "@hot-updater/protocol";
18
22
 
19
- /** The app's plugin host: plugins read the native module and fetch the configured server. */
20
- export const {
21
- configurePlugins,
22
- hasPluginHook,
23
- buildPluginEvent,
24
- dispatchPluginHook,
25
- emitPluginHook,
26
- } = createPluginHost({
23
+ /** The native module and runtime every plugin host reads. */
24
+ const environment: PluginHostEnvironment = {
27
25
  fetch: (url, init) => fetch(url, init),
28
26
  get platform() {
29
27
  return Platform.OS === "android" ? "android" : "ios";
@@ -44,4 +42,11 @@ export const {
44
42
  getStorageItem: (key) => getStorageItem(key),
45
43
  setStorageItem: (key, value) => setStorageItem(key, value),
46
44
  now: () => Date.now(),
47
- });
45
+ };
46
+
47
+ /**
48
+ * Creates an instance's plugin host: its plugins read the native module and
49
+ * fetch the server the instance was configured with.
50
+ */
51
+ export const createAppPluginHost = (): PluginHost =>
52
+ createPluginHost(environment);
package/src/sdkVersion.ts CHANGED
@@ -1 +1 @@
1
- export const HOT_UPDATER_SDK_VERSION = "1.0.0-rc.40";
1
+ export const HOT_UPDATER_SDK_VERSION = "1.0.0-rc.42";
package/src/wrap.tsx CHANGED
@@ -1,31 +1,21 @@
1
1
  import React, { useEffect, useState } from "react";
2
2
 
3
- import { handleNotifyAppReady } from "./appReady";
4
- import { checkForUpdate } from "./checkForUpdate";
5
3
  import { useEventCallback } from "./hooks/useEventCallback";
6
4
  import { getUpdateId, reload } from "./native";
7
5
  import { useHotUpdaterStore } from "./store";
8
6
  import type {
9
7
  HotUpdaterFallbackComponentProps,
10
- InternalInitOptions,
11
8
  InternalWrapOptions,
12
9
  UpdateStatus,
13
10
  } from "./wrap.types";
14
11
 
15
12
  export type {
16
- AutoUpdateOptions,
17
13
  HotUpdaterFallbackComponentProps,
18
- HotUpdaterInitOptions,
19
- HotUpdaterOptions,
20
- InternalInitOptions,
14
+ HotUpdaterWrapOptions,
21
15
  InternalWrapOptions,
22
16
  RunUpdateProcessResponse,
23
17
  } from "./wrap.types";
24
18
 
25
- export function init(options: InternalInitOptions): void {
26
- void handleNotifyAppReady(options);
27
- }
28
-
29
19
  export function wrap(
30
20
  options: InternalWrapOptions,
31
21
  ): <P extends object>(
@@ -81,16 +71,12 @@ export function wrap(
81
71
  try {
82
72
  setUpdateStatus("CHECK_FOR_UPDATE");
83
73
 
84
- const readiness = handleNotifyAppReady(restOptions);
85
- const updateInfo = await checkForUpdate({
86
- client: restOptions.client,
74
+ const updateInfo = await restOptions.checkForUpdate({
87
75
  updateStrategy: restOptions.updateStrategy,
88
- requestHeaders: restOptions.requestHeaders,
89
- requestTimeout: restOptions.requestTimeout,
90
- onError: restOptions.onError,
91
76
  });
92
77
 
93
- await readiness;
78
+ // A forced update reloads only after init has read this launch.
79
+ await restOptions.appReady();
94
80
  setMessage(updateInfo?.message ?? null);
95
81
 
96
82
  if (!updateInfo) {
@@ -106,7 +92,7 @@ export function wrap(
106
92
 
107
93
  if (updateInfo.shouldForceUpdate === false) {
108
94
  void updateInfo.updateBundle().catch((error: unknown) => {
109
- restOptions.onError?.(error);
95
+ restOptions.onError(error);
110
96
  });
111
97
 
112
98
  restOptions.onUpdateProcessCompleted?.({
@@ -143,7 +129,7 @@ export function wrap(
143
129
  } catch (error) {
144
130
  const normalizedError =
145
131
  error instanceof Error ? error : new Error(String(error));
146
- restOptions.onError?.(normalizedError);
132
+ restOptions.onError(normalizedError);
147
133
  setUpdateStatus("UPDATE_PROCESS_COMPLETED");
148
134
  }
149
135
  });
package/src/wrap.types.ts CHANGED
@@ -1,11 +1,10 @@
1
1
  import type React from "react";
2
2
 
3
- import type { HotUpdaterClientPlugin } from "./clientPlugin";
4
- import type { HotUpdaterError } from "./error";
5
- import type { HotUpdaterHttpClient } from "./httpClient";
6
- import type { NotifyAppReadyResult } from "./native";
3
+ import type {
4
+ CheckForUpdateOptions,
5
+ CheckForUpdateResult,
6
+ } from "./checkForUpdate";
7
7
  import type { HotUpdaterState } from "./store";
8
- import type { HotUpdaterBaseURL } from "./types";
9
8
 
10
9
  export interface RunUpdateProcessResponse {
11
10
  status: "ROLLBACK" | "UPDATE" | "UP_TO_DATE";
@@ -27,50 +26,24 @@ export type HotUpdaterFallbackComponentProps = {
27
26
  details: HotUpdaterState["details"];
28
27
  };
29
28
 
30
- interface CommonHotUpdaterOptions {
31
- /**
32
- * Client plugins, such as `insights()` from `@hot-updater/react-native`.
33
- * Each plugin's `setup` runs
34
- * once, and its hooks observe launches, update checks, downloads, and
35
- * update failures. Plugin ids must be unique.
36
- */
37
- plugins?: readonly HotUpdaterClientPlugin[];
38
- /** Base URL of a server exposing the Hot Updater v1 client HTTP protocol. */
39
- baseURL: HotUpdaterBaseURL;
40
- requestHeaders?: Record<string, string>;
41
- requestTimeout?: number;
42
- onNotifyAppReady?: (result: NotifyAppReadyResult) => void;
43
- onError?: (error: HotUpdaterError | Error | unknown) => void;
44
- }
45
-
46
- export type AutoUpdateOptions = CommonHotUpdaterOptions & {
29
+ /**
30
+ * The update flow `hotUpdater.wrap` runs when the wrapped root mounts. The
31
+ * server, request settings, and plugins come from `HotUpdater.init`.
32
+ */
33
+ export interface HotUpdaterWrapOptions {
47
34
  updateStrategy: "fingerprint" | "appVersion";
48
35
  fallbackComponent?: React.FC<HotUpdaterFallbackComponentProps>;
49
36
  onProgress?: (progress: number) => void;
50
37
  reloadOnForceUpdate?: boolean;
51
38
  onUpdateProcessCompleted?: (response: RunUpdateProcessResponse) => void;
52
- };
53
-
54
- export type HotUpdaterInitOptions = CommonHotUpdaterOptions;
55
-
56
- export type HotUpdaterOptions = AutoUpdateOptions;
39
+ }
57
40
 
58
- type InternalCommonOptions = {
59
- client: HotUpdaterHttpClient;
60
- requestHeaders?: Record<string, string>;
61
- requestTimeout?: number;
62
- onNotifyAppReady?: (result: NotifyAppReadyResult) => void;
63
- onError?: (error: HotUpdaterError | Error | unknown) => void;
41
+ export type InternalWrapOptions = HotUpdaterWrapOptions & {
42
+ /** The instance's check, over the configuration of `HotUpdater.init`. */
43
+ checkForUpdate: (
44
+ options: Pick<CheckForUpdateOptions, "updateStrategy">,
45
+ ) => Promise<CheckForUpdateResult | null>;
46
+ /** Settles once `HotUpdater.init` has read this launch. */
47
+ appReady: () => Promise<unknown>;
48
+ onError: (error: unknown) => void;
64
49
  };
65
-
66
- type InternalAutoUpdateOptions = InternalCommonOptions & {
67
- updateStrategy: "fingerprint" | "appVersion";
68
- fallbackComponent?: React.FC<HotUpdaterFallbackComponentProps>;
69
- onProgress?: (progress: number) => void;
70
- reloadOnForceUpdate?: boolean;
71
- onUpdateProcessCompleted?: (response: RunUpdateProcessResponse) => void;
72
- };
73
-
74
- export type InternalInitOptions = InternalCommonOptions;
75
-
76
- export type InternalWrapOptions = InternalAutoUpdateOptions;