@hot-updater/react-native 0.13.0 → 0.13.2

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/dist/index.d.ts CHANGED
@@ -4,13 +4,106 @@ export type { HotUpdaterConfig } from "./wrap";
4
4
  export type { HotUpdaterEvent } from "./native";
5
5
  export * from "./store";
6
6
  export declare const HotUpdater: {
7
+ /**
8
+ * `HotUpdater.wrap` checks for updates at the entry point, and if there is a bundle to update, it downloads the bundle and applies the update strategy.
9
+ *
10
+ * @param {object} options - Configuration options
11
+ * @param {string} options.source - Update server URL
12
+ * @param {object} [options.requestHeaders] - Request headers
13
+ * @param {React.ComponentType} [options.fallbackComponent] - Component to display during updates
14
+ * @param {boolean} [options.reloadOnForceUpdate=true] - Whether to automatically reload the app on force updates
15
+ * @param {Function} [options.onUpdateProcessCompleted] - Callback after update process completes
16
+ * @param {Function} [options.onProgress] - Callback to track bundle download progress
17
+ * @returns {Function} Higher-order component that wraps the app component
18
+ *
19
+ * @example
20
+ * ```tsx
21
+ * export default HotUpdater.wrap({
22
+ * source: "<your-update-server-url>",
23
+ * requestHeaders: {
24
+ * "Authorization": "Bearer <your-access-token>",
25
+ * },
26
+ * })(App);
27
+ * ```
28
+ */
7
29
  wrap: typeof wrap;
30
+ /**
31
+ * Reloads the app.
32
+ */
8
33
  reload: () => void;
34
+ /**
35
+ * Fetches the current app version.
36
+ */
9
37
  getAppVersion: () => Promise<string | null>;
38
+ /**
39
+ * Fetches the current bundle ID of the app.
40
+ */
10
41
  getBundleId: () => string;
42
+ /**
43
+ * Retrieves the initial bundle ID based on the build time of the native app.
44
+ */
11
45
  getMinBundleId: () => string;
46
+ /**
47
+ * Fetches the current release channel of the app.
48
+ *
49
+ * By default, if no channel is specified, the app is assigned to the 'production' channel.
50
+ *
51
+ * @returns {string} The current release channel of the app
52
+ *
53
+ * @example
54
+ * ```ts
55
+ * const channel = HotUpdater.getChannel();
56
+ * console.log(`Current channel: ${channel}`);
57
+ * ```
58
+ */
12
59
  getChannel: () => string;
60
+ /**
61
+ * Adds a listener to HotUpdater events.
62
+ *
63
+ * @param {keyof HotUpdaterEvent} eventName - The name of the event to listen for
64
+ * @param {(event: HotUpdaterEvent[T]) => void} listener - The callback function to handle the event
65
+ * @returns {() => void} A cleanup function that removes the event listener
66
+ *
67
+ * @example
68
+ * ```ts
69
+ * const unsubscribe = HotUpdater.addListener("onProgress", ({ progress }) => {
70
+ * console.log(`Update progress: ${progress * 100}%`);
71
+ * });
72
+ *
73
+ * // Unsubscribe when no longer needed
74
+ * unsubscribe();
75
+ * ```
76
+ */
13
77
  addListener: <T extends keyof import("./native").HotUpdaterEvent>(eventName: T, listener: (event: import("./native").HotUpdaterEvent[T]) => void) => () => void;
78
+ /**
79
+ * Manually checks for updates.
80
+ *
81
+ * @param {Object} config - Update check configuration
82
+ * @param {string} config.source - Update server URL
83
+ * @param {Record<string, string>} [config.requestHeaders] - Request headers
84
+ *
85
+ * @returns {Promise<UpdateInfo | null>} Update information or null if up to date
86
+ *
87
+ * @example
88
+ * ```ts
89
+ * const updateInfo = await HotUpdater.checkForUpdate({
90
+ * source: "<your-update-server-url>",
91
+ * requestHeaders: {
92
+ * Authorization: "Bearer <your-access-token>",
93
+ * },
94
+ * });
95
+ *
96
+ * if (!updateInfo) {
97
+ * console.log("App is up to date");
98
+ * return;
99
+ * }
100
+ *
101
+ * await HotUpdater.updateBundle(updateInfo.id, updateInfo.fileUrl);
102
+ * if (updateInfo.shouldForceUpdate) {
103
+ * HotUpdater.reload();
104
+ * }
105
+ * ```
106
+ */
14
107
  checkForUpdate: typeof checkForUpdate;
15
108
  /**
16
109
  * Manually checks and applies updates for the application.
@@ -45,5 +138,34 @@ export declare const HotUpdater: {
45
138
  * @returns {Promise<RunUpdateProcessResponse>} The result of the update process
46
139
  */
47
140
  runUpdateProcess: ({ reloadOnForceUpdate, ...checkForUpdateConfig }: import("./runUpdateProcess").RunUpdateProcessConfig) => Promise<import("./runUpdateProcess").RunUpdateProcessResponse>;
141
+ /**
142
+ * Updates the bundle of the app.
143
+ *
144
+ * @param {string} bundleId - The bundle ID of the app
145
+ * @param {string} zipUrl - The URL of the zip file
146
+ *
147
+ * @returns {Promise<boolean>} Whether the update was successful
148
+ *
149
+ * @example
150
+ * ```ts
151
+ * const updateInfo = await HotUpdater.checkForUpdate({
152
+ * source: "<your-update-server-url>",
153
+ * requestHeaders: {
154
+ * Authorization: "Bearer <your-access-token>",
155
+ * },
156
+ * });
157
+ *
158
+ * if (!updateInfo) {
159
+ * return {
160
+ * status: "UP_TO_DATE",
161
+ * };
162
+ * }
163
+ *
164
+ * await HotUpdater.updateBundle(updateInfo.id, updateInfo.fileUrl);
165
+ * if (updateInfo.shouldForceUpdate) {
166
+ * HotUpdater.reload();
167
+ * }
168
+ * ```
169
+ */
48
170
  updateBundle: (bundleId: string, zipUrl: string | null) => Promise<boolean>;
49
171
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@hot-updater/react-native",
3
- "version": "0.13.0",
3
+ "version": "0.13.2",
4
4
  "description": "React Native OTA solution for self-hosted",
5
5
  "main": "dist/index.js",
6
6
  "module": "dist/index.mjs",
@@ -81,8 +81,8 @@
81
81
  },
82
82
  "dependencies": {
83
83
  "use-sync-external-store": "1.4.0",
84
- "@hot-updater/js": "0.13.0",
85
- "@hot-updater/core": "0.13.0"
84
+ "@hot-updater/js": "0.13.2",
85
+ "@hot-updater/core": "0.13.2"
86
86
  },
87
87
  "scripts": {
88
88
  "build": "rslib build",
package/src/index.ts CHANGED
@@ -24,15 +24,106 @@ addListener("onProgress", ({ progress }) => {
24
24
  });
25
25
 
26
26
  export const HotUpdater = {
27
+ /**
28
+ * `HotUpdater.wrap` checks for updates at the entry point, and if there is a bundle to update, it downloads the bundle and applies the update strategy.
29
+ *
30
+ * @param {object} options - Configuration options
31
+ * @param {string} options.source - Update server URL
32
+ * @param {object} [options.requestHeaders] - Request headers
33
+ * @param {React.ComponentType} [options.fallbackComponent] - Component to display during updates
34
+ * @param {boolean} [options.reloadOnForceUpdate=true] - Whether to automatically reload the app on force updates
35
+ * @param {Function} [options.onUpdateProcessCompleted] - Callback after update process completes
36
+ * @param {Function} [options.onProgress] - Callback to track bundle download progress
37
+ * @returns {Function} Higher-order component that wraps the app component
38
+ *
39
+ * @example
40
+ * ```tsx
41
+ * export default HotUpdater.wrap({
42
+ * source: "<your-update-server-url>",
43
+ * requestHeaders: {
44
+ * "Authorization": "Bearer <your-access-token>",
45
+ * },
46
+ * })(App);
47
+ * ```
48
+ */
27
49
  wrap,
28
-
50
+ /**
51
+ * Reloads the app.
52
+ */
29
53
  reload,
54
+ /**
55
+ * Fetches the current app version.
56
+ */
30
57
  getAppVersion,
58
+ /**
59
+ * Fetches the current bundle ID of the app.
60
+ */
31
61
  getBundleId,
62
+ /**
63
+ * Retrieves the initial bundle ID based on the build time of the native app.
64
+ */
32
65
  getMinBundleId,
66
+ /**
67
+ * Fetches the current release channel of the app.
68
+ *
69
+ * By default, if no channel is specified, the app is assigned to the 'production' channel.
70
+ *
71
+ * @returns {string} The current release channel of the app
72
+ *
73
+ * @example
74
+ * ```ts
75
+ * const channel = HotUpdater.getChannel();
76
+ * console.log(`Current channel: ${channel}`);
77
+ * ```
78
+ */
33
79
  getChannel,
80
+ /**
81
+ * Adds a listener to HotUpdater events.
82
+ *
83
+ * @param {keyof HotUpdaterEvent} eventName - The name of the event to listen for
84
+ * @param {(event: HotUpdaterEvent[T]) => void} listener - The callback function to handle the event
85
+ * @returns {() => void} A cleanup function that removes the event listener
86
+ *
87
+ * @example
88
+ * ```ts
89
+ * const unsubscribe = HotUpdater.addListener("onProgress", ({ progress }) => {
90
+ * console.log(`Update progress: ${progress * 100}%`);
91
+ * });
92
+ *
93
+ * // Unsubscribe when no longer needed
94
+ * unsubscribe();
95
+ * ```
96
+ */
34
97
  addListener,
35
-
98
+ /**
99
+ * Manually checks for updates.
100
+ *
101
+ * @param {Object} config - Update check configuration
102
+ * @param {string} config.source - Update server URL
103
+ * @param {Record<string, string>} [config.requestHeaders] - Request headers
104
+ *
105
+ * @returns {Promise<UpdateInfo | null>} Update information or null if up to date
106
+ *
107
+ * @example
108
+ * ```ts
109
+ * const updateInfo = await HotUpdater.checkForUpdate({
110
+ * source: "<your-update-server-url>",
111
+ * requestHeaders: {
112
+ * Authorization: "Bearer <your-access-token>",
113
+ * },
114
+ * });
115
+ *
116
+ * if (!updateInfo) {
117
+ * console.log("App is up to date");
118
+ * return;
119
+ * }
120
+ *
121
+ * await HotUpdater.updateBundle(updateInfo.id, updateInfo.fileUrl);
122
+ * if (updateInfo.shouldForceUpdate) {
123
+ * HotUpdater.reload();
124
+ * }
125
+ * ```
126
+ */
36
127
  checkForUpdate,
37
128
  /**
38
129
  * Manually checks and applies updates for the application.
@@ -67,5 +158,34 @@ export const HotUpdater = {
67
158
  * @returns {Promise<RunUpdateProcessResponse>} The result of the update process
68
159
  */
69
160
  runUpdateProcess,
161
+ /**
162
+ * Updates the bundle of the app.
163
+ *
164
+ * @param {string} bundleId - The bundle ID of the app
165
+ * @param {string} zipUrl - The URL of the zip file
166
+ *
167
+ * @returns {Promise<boolean>} Whether the update was successful
168
+ *
169
+ * @example
170
+ * ```ts
171
+ * const updateInfo = await HotUpdater.checkForUpdate({
172
+ * source: "<your-update-server-url>",
173
+ * requestHeaders: {
174
+ * Authorization: "Bearer <your-access-token>",
175
+ * },
176
+ * });
177
+ *
178
+ * if (!updateInfo) {
179
+ * return {
180
+ * status: "UP_TO_DATE",
181
+ * };
182
+ * }
183
+ *
184
+ * await HotUpdater.updateBundle(updateInfo.id, updateInfo.fileUrl);
185
+ * if (updateInfo.shouldForceUpdate) {
186
+ * HotUpdater.reload();
187
+ * }
188
+ * ```
189
+ */
70
190
  updateBundle,
71
191
  };