@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.
- package/lib/commonjs/appReady.js +25 -31
- package/lib/commonjs/appReady.js.map +1 -1
- package/lib/commonjs/checkForUpdate.js +9 -9
- package/lib/commonjs/checkForUpdate.js.map +1 -1
- package/lib/commonjs/error.js +1 -1
- package/lib/commonjs/httpClient.js +1 -1
- package/lib/commonjs/index.js +304 -326
- package/lib/commonjs/index.js.map +1 -1
- package/lib/commonjs/init.types.js +6 -0
- package/lib/commonjs/init.types.js.map +1 -0
- package/lib/commonjs/native.js +3 -3
- package/lib/commonjs/pluginHost.js +11 -15
- package/lib/commonjs/pluginHost.js.map +1 -1
- package/lib/commonjs/sdkVersion.js +1 -1
- package/lib/commonjs/wrap.js +7 -16
- package/lib/commonjs/wrap.js.map +1 -1
- package/lib/module/appReady.js +23 -28
- package/lib/module/appReady.js.map +1 -1
- package/lib/module/checkForUpdate.js +10 -10
- package/lib/module/checkForUpdate.js.map +1 -1
- package/lib/module/clientPlugin.js.map +1 -1
- package/lib/module/error.js +1 -1
- package/lib/module/httpClient.js +1 -1
- package/lib/module/index.js +299 -329
- package/lib/module/index.js.map +1 -1
- package/lib/module/init.types.js +4 -0
- package/lib/module/init.types.js.map +1 -0
- package/lib/module/native.js +3 -3
- package/lib/module/pluginHost.js +9 -9
- package/lib/module/pluginHost.js.map +1 -1
- package/lib/module/sdkVersion.js +1 -1
- package/lib/module/wrap.js +7 -15
- package/lib/module/wrap.js.map +1 -1
- package/lib/typescript/commonjs/appReady.d.ts +18 -9
- package/lib/typescript/commonjs/appReady.d.ts.map +1 -1
- package/lib/typescript/commonjs/checkForUpdate.d.ts +5 -3
- package/lib/typescript/commonjs/checkForUpdate.d.ts.map +1 -1
- package/lib/typescript/commonjs/clientPlugin.d.ts +1 -1
- package/lib/typescript/commonjs/clientPlugin.d.ts.map +1 -1
- package/lib/typescript/commonjs/error.d.ts +1 -1
- package/lib/typescript/commonjs/httpClient.d.ts +1 -1
- package/lib/typescript/commonjs/httpClient.d.ts.map +1 -1
- package/lib/typescript/commonjs/index.d.ts +122 -110
- package/lib/typescript/commonjs/index.d.ts.map +1 -1
- package/lib/typescript/commonjs/init.types.d.ts +21 -0
- package/lib/typescript/commonjs/init.types.d.ts.map +1 -0
- package/lib/typescript/commonjs/native.d.ts +3 -3
- package/lib/typescript/commonjs/pluginHost.d.ts +7 -3
- package/lib/typescript/commonjs/pluginHost.d.ts.map +1 -1
- package/lib/typescript/commonjs/sdkVersion.d.ts +1 -1
- package/lib/typescript/commonjs/wrap.d.ts +2 -3
- package/lib/typescript/commonjs/wrap.d.ts.map +1 -1
- package/lib/typescript/commonjs/wrap.types.d.ts +13 -40
- package/lib/typescript/commonjs/wrap.types.d.ts.map +1 -1
- package/lib/typescript/module/appReady.d.ts +18 -9
- package/lib/typescript/module/appReady.d.ts.map +1 -1
- package/lib/typescript/module/checkForUpdate.d.ts +5 -3
- package/lib/typescript/module/checkForUpdate.d.ts.map +1 -1
- package/lib/typescript/module/clientPlugin.d.ts +1 -1
- package/lib/typescript/module/clientPlugin.d.ts.map +1 -1
- package/lib/typescript/module/error.d.ts +1 -1
- package/lib/typescript/module/httpClient.d.ts +1 -1
- package/lib/typescript/module/httpClient.d.ts.map +1 -1
- package/lib/typescript/module/index.d.ts +122 -110
- package/lib/typescript/module/index.d.ts.map +1 -1
- package/lib/typescript/module/init.types.d.ts +21 -0
- package/lib/typescript/module/init.types.d.ts.map +1 -0
- package/lib/typescript/module/native.d.ts +3 -3
- package/lib/typescript/module/pluginHost.d.ts +7 -3
- package/lib/typescript/module/pluginHost.d.ts.map +1 -1
- package/lib/typescript/module/sdkVersion.d.ts +1 -1
- package/lib/typescript/module/wrap.d.ts +2 -3
- package/lib/typescript/module/wrap.d.ts.map +1 -1
- package/lib/typescript/module/wrap.types.d.ts +13 -40
- package/lib/typescript/module/wrap.types.d.ts.map +1 -1
- package/package.json +4 -3
- package/src/appReady.ts +43 -37
- package/src/checkForUpdate.ts +19 -11
- package/src/clientPlugin.ts +3 -0
- package/src/error.ts +1 -1
- package/src/httpClient.ts +1 -1
- package/src/index.ts +344 -422
- package/src/init.types.ts +24 -0
- package/src/native.ts +3 -3
- package/src/pluginHost.ts +16 -11
- package/src/sdkVersion.ts +1 -1
- package/src/wrap.tsx +6 -20
- package/src/wrap.types.ts +18 -45
package/lib/commonjs/index.js
CHANGED
|
@@ -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
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
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
|
-
|
|
157
|
-
}
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
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
|
-
*
|
|
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
|
|
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
|
|
309
|
+
* await hotUpdater.reload();
|
|
351
310
|
* }
|
|
352
311
|
* ```
|
|
353
312
|
*/
|
|
354
|
-
checkForUpdate:
|
|
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
|
|
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
|
|
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
|
-
|
|
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
|
-
*
|
|
435
|
-
*
|
|
436
|
-
*
|
|
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
|
-
* ```
|
|
457
|
-
*
|
|
458
|
-
*
|
|
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
|
-
|
|
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
|
-
|
|
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
|