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

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
@@ -7,6 +7,7 @@ var _exportNames = {
7
7
  HotUpdater: true,
8
8
  defineClientPlugin: true,
9
9
  insights: true,
10
+ remoteConfig: true,
10
11
  extractSignatureFailure: true,
11
12
  isSignatureVerificationError: true
12
13
  };
@@ -35,6 +36,12 @@ Object.defineProperty(exports, "isSignatureVerificationError", {
35
36
  return _types.isSignatureVerificationError;
36
37
  }
37
38
  });
39
+ Object.defineProperty(exports, "remoteConfig", {
40
+ enumerable: true,
41
+ get: function () {
42
+ return _client2.remoteConfig;
43
+ }
44
+ });
38
45
  var _appReady = require("./appReady.js");
39
46
  var _checkForUpdate = require("./checkForUpdate.js");
40
47
  var _httpClient = require("./httpClient.js");
@@ -55,9 +62,12 @@ Object.keys(_store).forEach(function (key) {
55
62
  var _wrap = require("./wrap.js");
56
63
  var _clientPlugin = require("./clientPlugin.js");
57
64
  var _client = require("@hot-updater/plugin-insights/client");
65
+ var _client2 = require("@hot-updater/plugin-remote-config/client");
58
66
  var _types = require("./types.js");
59
67
  // The built-in Insights client plugin, for HotUpdater.init({ plugins }).
60
68
 
69
+ // The built-in Remote Config client plugin, for HotUpdater.init({ plugins }).
70
+
61
71
  /**
62
72
  * Register getBaseURL to global objects for use without imports.
63
73
  * This is needed for Expo DOM components and Babel plugin generated code.
@@ -75,255 +85,204 @@ const registerGlobalGetBaseURL = () => {
75
85
 
76
86
  // Call registration immediately on module load
77
87
  registerGlobalGetBaseURL();
78
- /**
79
- * Creates a HotUpdater client instance with all update management methods.
80
- * This function is called once on module initialization to create a singleton instance.
81
- */
82
- function createHotUpdaterClient() {
83
- let configurationAPI = null;
84
- let mixedConfigurationReported = false;
88
+ const createMissingNetworkConfigError = () => new Error(`[HotUpdater] baseURL must be provided.\n\n` + `Configure HotUpdater with the standard baseURL setup:\n\n` + ` export const hotUpdater = HotUpdater.init({\n` + ` baseURL: "<your-update-server-url>",\n` + ` });\n\n` + `See https://hot-updater.dev/docs/react-native-api/init`);
85
89
 
86
- // Global configuration stored from wrap
87
- const globalConfig = {
88
- client: null
89
- };
90
- const createMissingNetworkConfigError = apiName => {
91
- if (apiName === "init") {
92
- return new Error(`[HotUpdater] baseURL must be provided.\n\n` + `Configure HotUpdater before calling update APIs with the standard baseURL setup:\n\n` + ` HotUpdater.init({\n` + ` baseURL: "<your-update-server-url>",\n` + ` });\n\n` + `For manual update flows, visit: https://hot-updater.dev/docs/guides/custom-update`);
93
- }
94
- const baseURLExample = ` export default HotUpdater.wrap({\n` + ` baseURL: "<your-update-server-url>",\n` + ` updateStrategy: "appVersion"\n` + ` })(App);\n\n`;
95
- return new Error(`[HotUpdater] baseURL must be provided.\n\n` + `Configure HotUpdater.wrap with the standard baseURL setup:\n\n` + baseURLExample + `For manual update flows, use HotUpdater.init() and visit: ` + `https://hot-updater.dev/docs/guides/custom-update`);
96
- };
97
- const normalizeOptions = options => {
98
- const incoming = options;
99
- if (incoming.updateMode === "manual") {
100
- throw new Error('[HotUpdater] HotUpdater.wrap({ updateMode: "manual" }) was removed. ' + "Call HotUpdater.init({ ... }) instead, export your root component " + "directly, and use HotUpdater.checkForUpdate(...) for the manual " + "update flow. See https://hot-updater.dev/docs/guides/custom-update");
101
- }
102
- const autoOptions = incoming;
103
- if (autoOptions.baseURL) {
104
- const {
105
- baseURL,
106
- plugins: _plugins,
107
- ...rest
108
- } = autoOptions;
109
- return {
110
- ...rest,
111
- client: (0, _httpClient.createHttpClient)(baseURL, response => {
112
- (0, _appReady.emitAfterAppReady)("onHttpResponse", () => response);
113
- })
114
- };
115
- }
116
- throw createMissingNetworkConfigError("wrap");
117
- };
118
- const normalizeInitOptions = options => {
119
- const {
120
- updateMode: _updateMode,
121
- ...rest
122
- } = options;
123
- if (rest.baseURL) {
124
- const {
125
- baseURL,
126
- plugins: _plugins,
127
- ...baseURLRest
128
- } = rest;
129
- return {
130
- ...baseURLRest,
131
- client: (0, _httpClient.createHttpClient)(baseURL, response => {
132
- (0, _appReady.emitAfterAppReady)("onHttpResponse", () => response);
133
- })
134
- };
135
- }
136
- throw createMissingNetworkConfigError("init");
137
- };
138
- const configureGlobal = (normalizedOptions, options) => {
139
- // Plugins are set up before init or wrap reads the launch they observe.
140
- (0, _pluginHost.configurePlugins)(options.plugins, {
141
- baseURL: options.baseURL,
142
- requestHeaders: options.requestHeaders,
143
- requestTimeout: options.requestTimeout,
144
- onError: options.onError
145
- });
146
- globalConfig.client = normalizedOptions.client;
147
- globalConfig.requestHeaders = options.requestHeaders;
148
- globalConfig.requestTimeout = options.requestTimeout;
149
- globalConfig.onError = options.onError;
150
- };
151
- const reportMixedConfiguration = nextAPI => {
152
- if (configurationAPI !== null && configurationAPI !== nextAPI && !mixedConfigurationReported) {
153
- mixedConfigurationReported = true;
154
- console.error("[HotUpdater] HotUpdater.init() and HotUpdater.wrap() must not be used together. " + "For custom or manual update flows, use HotUpdater.init() with " + "HotUpdater.checkForUpdate(). For the automatic HOC flow, use " + "HotUpdater.wrap().");
90
+ /** The methods that read or change native state, the same on every instance. */
91
+ const nativeMethods = {
92
+ /**
93
+ * Reloads the app.
94
+ */
95
+ reload: _native.reload,
96
+ /**
97
+ * Configures how `hotUpdater.reload()` behaves.
98
+ *
99
+ * This can be called unconditionally on both platforms.
100
+ * The default is `processRestart`.
101
+ *
102
+ * - `reload`: built-in React Native reload on both platforms
103
+ * - `processRestart`: Android process restart, iOS behaves like normal reload
104
+ * - `custom`: run a custom JS handler on both platforms
105
+ */
106
+ setReloadBehavior: _native.setReloadBehavior,
107
+ /**
108
+ * Returns whether an update has finished downloading in this app session.
109
+ *
110
+ * When it returns true, calling `hotUpdater.reload()` (or restarting the app)
111
+ * will apply the downloaded update bundle.
112
+ *
113
+ * - Derived from `progress` reaching 1.0
114
+ * - Resets to false when a new download starts (progress < 1)
115
+ *
116
+ * @returns {boolean} True if a downloaded update is ready to apply
117
+ * @example
118
+ * ```ts
119
+ * if (hotUpdater.isUpdateDownloaded()) {
120
+ * await hotUpdater.reload();
121
+ * }
122
+ * ```
123
+ */
124
+ isUpdateDownloaded: () => _store.hotUpdaterStore.getSnapshot().isUpdateDownloaded,
125
+ /**
126
+ * Fetches the current app version.
127
+ */
128
+ getAppVersion: _native.getAppVersion,
129
+ /** Reads the active and stable Release/Bundle state. */
130
+ getActiveUpdateState: async () => (0, _native.getPublicActiveUpdateState)(),
131
+ /**
132
+ * Returns the selected update ID, matching the ID shown in the console.
133
+ * A staged update can change this ID before the app reloads.
134
+ */
135
+ getBundleId: _native.getUpdateId,
136
+ /** Returns the minimum bundle ID based on the native app build time. */
137
+ getMinBundleId: _native.getMinBundleId,
138
+ /**
139
+ * Fetches the current manifest for the active bundle.
140
+ */
141
+ getManifest: _native.getManifest,
142
+ /**
143
+ * Fetches the current channel of the app.
144
+ *
145
+ * If no channel is specified, the app is assigned to the 'production' channel.
146
+ *
147
+ * @returns {string} The current release channel of the app
148
+ * @default "production"
149
+ * @example
150
+ * ```ts
151
+ * const channel = hotUpdater.getChannel();
152
+ * console.log(`Current channel: ${channel}`);
153
+ * ```
154
+ */
155
+ getChannel: _native.getChannel,
156
+ /**
157
+ * Fetches the build-time default channel of the app.
158
+ *
159
+ * This value does not change when a runtime channel override is active.
160
+ *
161
+ * @returns {string} The default release channel embedded in the app
162
+ * @example
163
+ * ```ts
164
+ * const defaultChannel = hotUpdater.getDefaultChannel();
165
+ * console.log(`Default channel: ${defaultChannel}`);
166
+ * ```
167
+ */
168
+ getDefaultChannel: _native.getDefaultChannel,
169
+ /**
170
+ * Returns whether the app is currently using a runtime channel override.
171
+ *
172
+ * @returns {boolean} true when a non-default channel has been applied
173
+ */
174
+ isChannelSwitched: _native.isChannelSwitched,
175
+ /**
176
+ * Sets the persisted cohort used for rollout calculations.
177
+ * Call `getCohort()` first if you need to restore the initial value later.
178
+ */
179
+ setCohort: _native.setCohort,
180
+ /**
181
+ * Gets the persisted cohort used for rollout calculations.
182
+ */
183
+ getCohort: _native.getCohort,
184
+ /**
185
+ * Adds a listener to HotUpdater events.
186
+ *
187
+ * @param {keyof HotUpdaterEvent} eventName - The name of the event to listen for
188
+ * @param {(event: HotUpdaterEvent[T]) => void} listener - The callback function to handle the event
189
+ * @returns {() => void} A cleanup function that removes the event listener
190
+ *
191
+ * @example
192
+ * ```ts
193
+ * const unsubscribe = hotUpdater.addListener("onProgress", ({ progress }) => {
194
+ * console.log(`Update progress: ${progress * 100}%`);
195
+ * });
196
+ *
197
+ * // Unsubscribe when no longer needed
198
+ * unsubscribe();
199
+ * ```
200
+ */
201
+ addListener: _native.addListener,
202
+ /**
203
+ * Clears the runtime channel override and restores the original bundle.
204
+ *
205
+ * @returns {Promise<boolean>} Resolves with true if reset was successful
206
+ */
207
+ resetChannel: async () => {
208
+ const ok = await (0, _native.resetChannel)();
209
+ if (ok) {
210
+ _store.hotUpdaterStore.setState({
211
+ artifactType: null,
212
+ details: null,
213
+ isUpdateDownloaded: false,
214
+ progress: 0
215
+ });
155
216
  }
156
- configurationAPI ??= nextAPI;
157
- };
158
- const ensureGlobalClient = methodName => {
159
- if (!globalConfig.client) {
160
- throw new Error(`[HotUpdater] ${methodName} requires HotUpdater.wrap() or HotUpdater.init() to be used.\n\n` + `To fix this issue, configure HotUpdater before calling ${methodName}:\n\n` + `Option 1: With HotUpdater.wrap()\n` + ` export default HotUpdater.wrap({\n` + ` baseURL: "<your-update-server-url>",\n` + ` updateStrategy: "appVersion"\n` + ` })(App);\n\n` + `Option 2: With HotUpdater.init() for custom runtimes\n` + ` HotUpdater.init({\n` + ` baseURL: "<your-update-server-url>",\n` + ` });\n\n` + `For manual update flows, visit: https://hot-updater.dev/docs/guides/custom-update`);
161
- }
162
- return globalConfig.client;
163
- };
164
- return {
165
- /**
166
- * `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.
167
- *
168
- * @param {object} options - Configuration options
169
- * @param {string} options.source - Update server URL
170
- * @param {object} [options.requestHeaders] - Request headers
171
- * @param {React.ComponentType} [options.fallbackComponent] - Component to display during updates
172
- * @param {boolean} [options.reloadOnForceUpdate=true] - Whether to automatically reload the app on force updates
173
- * @param {Function} [options.onUpdateProcessCompleted] - Callback after update process completes
174
- * @param {Function} [options.onProgress] - Callback to track bundle download progress
175
- * @returns {Function} Higher-order component that wraps the app component
176
- *
177
- * @example
178
- * ```tsx
179
- * export default HotUpdater.wrap({
180
- * baseURL: "<your-update-server-url>",
181
- * updateStrategy: "appVersion",
182
- * requestHeaders: {
183
- * "x-api-key": "<your-api-key>",
184
- * },
185
- * })(App);
186
- * ```
187
- */
188
- wrap: options => {
189
- const normalizedOptions = normalizeOptions(options);
190
- reportMixedConfiguration("wrap");
191
- configureGlobal(normalizedOptions, options);
192
- return (0, _wrap.wrap)(normalizedOptions);
193
- },
194
- /**
195
- * Initializes HotUpdater without wrapping a React component.
196
- *
197
- * Use this for manual update flows in runtimes where a root component HOC
198
- * is not convenient. Use this instead of wrapping the root component.
199
- *
200
- * @example
201
- * ```tsx
202
- * HotUpdater.init({
203
- * baseURL: "<your-update-server-url>",
204
- * });
205
- *
206
- * export default App;
207
- * ```
208
- */
209
- init: options => {
210
- const normalizedOptions = normalizeInitOptions(options);
211
- reportMixedConfiguration("init");
212
- configureGlobal(normalizedOptions, options);
213
- (0, _wrap.init)(normalizedOptions);
217
+ return ok;
218
+ },
219
+ /**
220
+ * Fetches the fingerprint of the app.
221
+ *
222
+ * @returns {string} The fingerprint of the app
223
+ *
224
+ * @example
225
+ * ```ts
226
+ * const fingerprint = hotUpdater.getFingerprintHash();
227
+ * console.log(`Fingerprint: ${fingerprint}`);
228
+ * ```
229
+ */
230
+ getFingerprintHash: _native.getFingerprintHash,
231
+ /**
232
+ * Fetches the persisted install id for this app installation.
233
+ */
234
+ getInstallId: _native.getInstallId,
235
+ /**
236
+ * Reads the native launch report for the current process.
237
+ */
238
+ notifyAppReady: _native.notifyAppReady,
239
+ /**
240
+ * Gets the list of bundle IDs that have been marked as crashed.
241
+ * These bundles will be rejected if attempted to install again.
242
+ *
243
+ * @returns {string[]} Array of crashed bundle IDs
244
+ *
245
+ * @example
246
+ * ```ts
247
+ * const crashedBundles = hotUpdater.getCrashHistory();
248
+ * console.log("Crashed bundles:", crashedBundles);
249
+ * ```
250
+ */
251
+ getCrashHistory: _native.getCrashHistory,
252
+ /**
253
+ * Clears the crashed bundle history, allowing previously crashed bundles
254
+ * to be installed again.
255
+ *
256
+ * @returns {boolean} true if clearing was successful
257
+ *
258
+ * @example
259
+ * ```ts
260
+ * // Clear crash history to allow retrying a previously failed bundle
261
+ * hotUpdater.clearCrashHistory();
262
+ * ```
263
+ */
264
+ clearCrashHistory: _native.clearCrashHistory
265
+ };
266
+
267
+ /** What an instance's own methods use: its server, settings, and launch. */
268
+
269
+ /** The methods that use the instance's own configuration and plugins. */
270
+ const createConfiguredMethods = config => {
271
+ const check = options => (0, _checkForUpdate.checkForUpdate)({
272
+ ...options,
273
+ client: config.client,
274
+ emit: config.launch.emit,
275
+ requestHeaders: {
276
+ ...config.requestHeaders,
277
+ ...options.requestHeaders
214
278
  },
279
+ requestTimeout: options.requestTimeout ?? config.requestTimeout,
280
+ onError: options.onError ?? config.onError
281
+ });
282
+ return {
215
283
  /**
216
- * Reloads the app.
217
- */
218
- reload: _native.reload,
219
- /**
220
- * Configures how `HotUpdater.reload()` behaves.
221
- *
222
- * This can be called unconditionally on both platforms.
223
- * The default is `processRestart`.
224
- *
225
- * - `reload`: built-in React Native reload on both platforms
226
- * - `processRestart`: Android process restart, iOS behaves like normal reload
227
- * - `custom`: run a custom JS handler on both platforms
228
- */
229
- setReloadBehavior: _native.setReloadBehavior,
230
- /**
231
- * Returns whether an update has finished downloading in this app session.
232
- *
233
- * When it returns true, calling `HotUpdater.reload()` (or restarting the app)
234
- * will apply the downloaded update bundle.
235
- *
236
- * - Derived from `progress` reaching 1.0
237
- * - Resets to false when a new download starts (progress < 1)
238
- *
239
- * @returns {boolean} True if a downloaded update is ready to apply
240
- * @example
241
- * ```ts
242
- * if (HotUpdater.isUpdateDownloaded()) {
243
- * await HotUpdater.reload();
244
- * }
245
- * ```
246
- */
247
- isUpdateDownloaded: () => _store.hotUpdaterStore.getSnapshot().isUpdateDownloaded,
248
- /**
249
- * Fetches the current app version.
250
- */
251
- getAppVersion: _native.getAppVersion,
252
- /** Reads the active and stable Release/Bundle state. */
253
- getActiveUpdateState: async () => (0, _native.getPublicActiveUpdateState)(),
254
- /**
255
- * Returns the selected update ID, matching the ID shown in the console.
256
- * A staged update can change this ID before the app reloads.
257
- */
258
- getBundleId: _native.getUpdateId,
259
- /** Returns the minimum bundle ID based on the native app build time. */
260
- getMinBundleId: _native.getMinBundleId,
261
- /**
262
- * Fetches the current manifest for the active bundle.
263
- */
264
- getManifest: _native.getManifest,
265
- /**
266
- * Fetches the current channel of the app.
267
- *
268
- * If no channel is specified, the app is assigned to the 'production' channel.
269
- *
270
- * @returns {string} The current release channel of the app
271
- * @default "production"
272
- * @example
273
- * ```ts
274
- * const channel = HotUpdater.getChannel();
275
- * console.log(`Current channel: ${channel}`);
276
- * ```
277
- */
278
- getChannel: _native.getChannel,
279
- /**
280
- * Fetches the build-time default channel of the app.
281
- *
282
- * This value does not change when a runtime channel override is active.
283
- *
284
- * @returns {string} The default release channel embedded in the app
285
- * @example
286
- * ```ts
287
- * const defaultChannel = HotUpdater.getDefaultChannel();
288
- * console.log(`Default channel: ${defaultChannel}`);
289
- * ```
290
- */
291
- getDefaultChannel: _native.getDefaultChannel,
292
- /**
293
- * Returns whether the app is currently using a runtime channel override.
294
- *
295
- * @returns {boolean} true when a non-default channel has been applied
296
- */
297
- isChannelSwitched: _native.isChannelSwitched,
298
- /**
299
- * Sets the persisted cohort used for rollout calculations.
300
- * Call `getCohort()` first if you need to restore the initial value later.
301
- */
302
- setCohort: _native.setCohort,
303
- /**
304
- * Gets the persisted cohort used for rollout calculations.
305
- */
306
- getCohort: _native.getCohort,
307
- /**
308
- * Adds a listener to HotUpdater events.
309
- *
310
- * @param {keyof HotUpdaterEvent} eventName - The name of the event to listen for
311
- * @param {(event: HotUpdaterEvent[T]) => void} listener - The callback function to handle the event
312
- * @returns {() => void} A cleanup function that removes the event listener
313
- *
314
- * @example
315
- * ```ts
316
- * const unsubscribe = HotUpdater.addListener("onProgress", ({ progress }) => {
317
- * console.log(`Update progress: ${progress * 100}%`);
318
- * });
319
- *
320
- * // Unsubscribe when no longer needed
321
- * unsubscribe();
322
- * ```
323
- */
324
- addListener: _native.addListener,
325
- /**
326
- * Manually checks for updates.
284
+ * Checks for an update, with this instance's server and request
285
+ * settings.
327
286
  *
328
287
  * @param {Object} config - Update check configuration
329
288
  * @param {string} [config.channel] - Optional channel override for this update check
@@ -333,7 +292,7 @@ function createHotUpdaterClient() {
333
292
  *
334
293
  * @example
335
294
  * ```ts
336
- * const updateInfo = await HotUpdater.checkForUpdate({
295
+ * const updateInfo = await hotUpdater.checkForUpdate({
337
296
  * updateStrategy: "appVersion",
338
297
  * requestHeaders: {
339
298
  * "x-api-key": "<your-api-key>",
@@ -347,24 +306,11 @@ function createHotUpdaterClient() {
347
306
  *
348
307
  * await updateInfo.updateBundle();
349
308
  * if (updateInfo.shouldForceUpdate) {
350
- * await HotUpdater.reload();
309
+ * await hotUpdater.reload();
351
310
  * }
352
311
  * ```
353
312
  */
354
- checkForUpdate: config => {
355
- const client = ensureGlobalClient("checkForUpdate");
356
- const mergedConfig = {
357
- ...config,
358
- client,
359
- requestHeaders: {
360
- ...globalConfig.requestHeaders,
361
- ...config.requestHeaders
362
- },
363
- requestTimeout: config.requestTimeout ?? globalConfig.requestTimeout,
364
- onError: config.onError ?? globalConfig.onError
365
- };
366
- return (0, _checkForUpdate.checkForUpdate)(mergedConfig);
367
- },
313
+ checkForUpdate: check,
368
314
  /**
369
315
  * Updates the bundle of the app.
370
316
  *
@@ -374,7 +320,7 @@ function createHotUpdaterClient() {
374
320
  *
375
321
  * @example
376
322
  * ```ts
377
- * const updateInfo = await HotUpdater.checkForUpdate({
323
+ * const updateInfo = await hotUpdater.checkForUpdate({
378
324
  * updateStrategy: "appVersion",
379
325
  * requestHeaders: {
380
326
  * "x-api-key": "<your-api-key>",
@@ -389,12 +335,11 @@ function createHotUpdaterClient() {
389
335
  *
390
336
  * await updateInfo.updateBundle();
391
337
  * if (updateInfo.shouldForceUpdate) {
392
- * await HotUpdater.reload();
338
+ * await hotUpdater.reload();
393
339
  * }
394
340
  * ```
395
341
  */
396
342
  updateBundle: async params => {
397
- ensureGlobalClient("updateBundle");
398
343
  const fromBundleId = (0, _native.getBundleId)();
399
344
  const state = (0, _native.getActiveUpdateState)();
400
345
  const active = state.activeSelection;
@@ -405,7 +350,7 @@ function createHotUpdaterClient() {
405
350
  try {
406
351
  delivery = await (0, _native.stageBundle)(params);
407
352
  } catch (error) {
408
- (0, _checkForUpdate.reportUpdateError)(error, "download", undefined, {
353
+ (0, _checkForUpdate.reportUpdateError)(config.launch.emit, error, "download", undefined, {
409
354
  bundleId: fromBundleId,
410
355
  channel,
411
356
  targetBundleId: params.bundleId,
@@ -415,7 +360,7 @@ function createHotUpdaterClient() {
415
360
  throw error;
416
361
  }
417
362
  if (delivery !== null && params.bundleId !== fromBundleId) {
418
- (0, _appReady.emitAfterAppReady)("onBundleDownloaded", () => {
363
+ config.launch.emit("onBundleDownloaded", () => {
419
364
  const selection = (0, _native.getActiveUpdateState)().activeSelection;
420
365
  return {
421
366
  channel,
@@ -431,69 +376,102 @@ function createHotUpdaterClient() {
431
376
  return true;
432
377
  },
433
378
  /**
434
- * Clears the runtime channel override and restores the original bundle.
435
- *
436
- * @returns {Promise<boolean>} Resolves with true if reset was successful
437
- */
438
- resetChannel: async () => {
439
- const ok = await (0, _native.resetChannel)();
440
- if (ok) {
441
- _store.hotUpdaterStore.setState({
442
- artifactType: null,
443
- details: null,
444
- isUpdateDownloaded: false,
445
- progress: 0
446
- });
447
- }
448
- return ok;
449
- },
450
- /**
451
- * Fetches the fingerprint of the app.
452
- *
453
- * @returns {string} The fingerprint of the app
379
+ * Wraps the app's root: when it mounts, it checks for an update with
380
+ * this instance's configuration, downloads one, and reloads for a
381
+ * forced update. A `fallbackComponent` replaces the root until the
382
+ * check and a forced update finish.
454
383
  *
455
384
  * @example
456
- * ```ts
457
- * const fingerprint = HotUpdater.getFingerprintHash();
458
- * console.log(`Fingerprint: ${fingerprint}`);
459
- * ```
460
- */
461
- getFingerprintHash: _native.getFingerprintHash,
462
- /**
463
- * Fetches the persisted install id for this app installation.
464
- */
465
- getInstallId: _native.getInstallId,
466
- /**
467
- * Reads the native launch report for the current process.
468
- */
469
- notifyAppReady: _native.notifyAppReady,
470
- /**
471
- * Gets the list of bundle IDs that have been marked as crashed.
472
- * These bundles will be rejected if attempted to install again.
473
- *
474
- * @returns {string[]} Array of crashed bundle IDs
475
- *
476
- * @example
477
- * ```ts
478
- * const crashedBundles = HotUpdater.getCrashHistory();
479
- * console.log("Crashed bundles:", crashedBundles);
480
- * ```
481
- */
482
- getCrashHistory: _native.getCrashHistory,
483
- /**
484
- * Clears the crashed bundle history, allowing previously crashed bundles
485
- * to be installed again.
486
- *
487
- * @returns {boolean} true if clearing was successful
488
- *
489
- * @example
490
- * ```ts
491
- * // Clear crash history to allow retrying a previously failed bundle
492
- * HotUpdater.clearCrashHistory();
385
+ * ```tsx
386
+ * export default hotUpdater.wrap({
387
+ * updateStrategy: "appVersion",
388
+ * fallbackComponent: ({ progress }) => <Splash progress={progress} />,
389
+ * })(App);
493
390
  * ```
494
391
  */
495
- clearCrashHistory: _native.clearCrashHistory
392
+ wrap: options => (0, _wrap.wrap)({
393
+ ...options,
394
+ checkForUpdate: check,
395
+ appReady: () => config.launch.appReady,
396
+ onError: error => config.onError?.(error)
397
+ })
496
398
  };
497
- }
498
- const HotUpdater = exports.HotUpdater = createHotUpdaterClient();
399
+ };
400
+
401
+ /** The methods of every instance `HotUpdater.init` returns. */
402
+
403
+ /**
404
+ * The instance `HotUpdater.init` returns: HotUpdater's methods, and each
405
+ * plugin's API under the plugin's id.
406
+ */
407
+
408
+ const HotUpdater = exports.HotUpdater = {
409
+ /**
410
+ * Creates the app's HotUpdater instance: the update server, its request
411
+ * settings, and the client plugins. Each call returns an independent
412
+ * instance with its own configuration and plugins, so create one, at the
413
+ * top level of a module, and export it.
414
+ *
415
+ * The instance has every HotUpdater method, such as `wrap`,
416
+ * `checkForUpdate`, and `reload`, and each plugin's API under the
417
+ * plugin's id, such as `hotUpdater.remoteConfig` for `remoteConfig()`.
418
+ *
419
+ * @example
420
+ * ```tsx
421
+ * export const hotUpdater = HotUpdater.init({
422
+ * baseURL: "<your-update-server-url>",
423
+ * plugins: [remoteConfig({ defaults: { welcome_message: "Hi" } })],
424
+ * });
425
+ *
426
+ * hotUpdater.remoteConfig.getString("welcome_message");
427
+ * ```
428
+ */
429
+ init: options => {
430
+ const {
431
+ baseURL,
432
+ plugins,
433
+ requestHeaders,
434
+ requestTimeout,
435
+ onError,
436
+ onNotifyAppReady
437
+ } = options;
438
+ if (!baseURL) throw createMissingNetworkConfigError();
439
+ const host = (0, _pluginHost.createAppPluginHost)();
440
+ const launch = (0, _appReady.createLaunchReporter)(host);
441
+ const instance = {
442
+ ...nativeMethods,
443
+ ...createConfiguredMethods({
444
+ client: (0, _httpClient.createHttpClient)(baseURL, response => {
445
+ launch.emit("onHttpResponse", () => response);
446
+ }),
447
+ requestHeaders,
448
+ requestTimeout,
449
+ onError,
450
+ launch
451
+ })
452
+ };
453
+ const reservedIds = new Set([...Object.keys(instance), "init"]);
454
+ for (const plugin of plugins ?? []) {
455
+ if (reservedIds.has(plugin.id)) {
456
+ throw new Error(`[HotUpdater] A plugin cannot use the id "${plugin.id}": the HotUpdater instance has its own "${plugin.id}".`);
457
+ }
458
+ }
459
+
460
+ // Plugins are set up before the instance reads the launch they observe.
461
+ const apis = host.configurePlugins(plugins, {
462
+ baseURL,
463
+ requestHeaders,
464
+ requestTimeout,
465
+ onError
466
+ });
467
+ void launch.read({
468
+ onNotifyAppReady,
469
+ onError
470
+ });
471
+ return Object.freeze({
472
+ ...instance,
473
+ ...apis
474
+ });
475
+ }
476
+ };
499
477
  //# sourceMappingURL=index.js.map