@hot-updater/react-native 0.23.1 → 0.24.1

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 (109) hide show
  1. package/android/src/main/java/com/hotupdater/BundleFileStorageService.kt +393 -49
  2. package/android/src/main/java/com/hotupdater/BundleMetadata.kt +204 -0
  3. package/android/src/main/java/com/hotupdater/HotUpdater.kt +48 -36
  4. package/android/src/main/java/com/hotupdater/HotUpdaterException.kt +134 -0
  5. package/android/src/main/java/com/hotupdater/HotUpdaterImpl.kt +168 -95
  6. package/android/src/main/java/com/hotupdater/OkHttpDownloadService.kt +15 -3
  7. package/android/src/main/java/com/hotupdater/SignatureVerifier.kt +17 -12
  8. package/android/src/newarch/HotUpdaterModule.kt +88 -23
  9. package/android/src/oldarch/HotUpdaterModule.kt +89 -22
  10. package/android/src/oldarch/HotUpdaterSpec.kt +6 -0
  11. package/ios/HotUpdater/Internal/BundleFileStorageService.swift +401 -77
  12. package/ios/HotUpdater/Internal/BundleMetadata.swift +177 -0
  13. package/ios/HotUpdater/Internal/HotUpdater.mm +213 -47
  14. package/ios/HotUpdater/Internal/HotUpdaterImpl.swift +96 -25
  15. package/ios/HotUpdater/Internal/SignatureVerifier.swift +35 -29
  16. package/ios/HotUpdater/Internal/URLSessionDownloadService.swift +2 -2
  17. package/ios/HotUpdater/Public/HotUpdater.h +8 -2
  18. package/lib/commonjs/DefaultResolver.js +38 -0
  19. package/lib/commonjs/DefaultResolver.js.map +1 -0
  20. package/lib/commonjs/checkForUpdate.js +33 -45
  21. package/lib/commonjs/checkForUpdate.js.map +1 -1
  22. package/lib/commonjs/error.js +45 -1
  23. package/lib/commonjs/error.js.map +1 -1
  24. package/lib/commonjs/fetchUpdateInfo.js +7 -45
  25. package/lib/commonjs/fetchUpdateInfo.js.map +1 -1
  26. package/lib/commonjs/index.js +249 -208
  27. package/lib/commonjs/index.js.map +1 -1
  28. package/lib/commonjs/native.js +103 -3
  29. package/lib/commonjs/native.js.map +1 -1
  30. package/lib/commonjs/specs/NativeHotUpdater.js.map +1 -1
  31. package/lib/commonjs/types.js +12 -0
  32. package/lib/commonjs/types.js.map +1 -1
  33. package/lib/commonjs/wrap.js +70 -1
  34. package/lib/commonjs/wrap.js.map +1 -1
  35. package/lib/module/DefaultResolver.js +34 -0
  36. package/lib/module/DefaultResolver.js.map +1 -0
  37. package/lib/module/checkForUpdate.js +34 -43
  38. package/lib/module/checkForUpdate.js.map +1 -1
  39. package/lib/module/error.js +45 -0
  40. package/lib/module/error.js.map +1 -1
  41. package/lib/module/fetchUpdateInfo.js +7 -45
  42. package/lib/module/fetchUpdateInfo.js.map +1 -1
  43. package/lib/module/index.js +250 -203
  44. package/lib/module/index.js.map +1 -1
  45. package/lib/module/native.js +87 -2
  46. package/lib/module/native.js.map +1 -1
  47. package/lib/module/specs/NativeHotUpdater.js.map +1 -1
  48. package/lib/module/types.js +12 -0
  49. package/lib/module/types.js.map +1 -1
  50. package/lib/module/wrap.js +71 -2
  51. package/lib/module/wrap.js.map +1 -1
  52. package/lib/typescript/commonjs/DefaultResolver.d.ts +10 -0
  53. package/lib/typescript/commonjs/DefaultResolver.d.ts.map +1 -0
  54. package/lib/typescript/commonjs/checkForUpdate.d.ts +12 -13
  55. package/lib/typescript/commonjs/checkForUpdate.d.ts.map +1 -1
  56. package/lib/typescript/commonjs/error.d.ts +120 -0
  57. package/lib/typescript/commonjs/error.d.ts.map +1 -1
  58. package/lib/typescript/commonjs/fetchUpdateInfo.d.ts +3 -5
  59. package/lib/typescript/commonjs/fetchUpdateInfo.d.ts.map +1 -1
  60. package/lib/typescript/commonjs/index.d.ts +38 -44
  61. package/lib/typescript/commonjs/index.d.ts.map +1 -1
  62. package/lib/typescript/commonjs/native.d.ts +58 -2
  63. package/lib/typescript/commonjs/native.d.ts.map +1 -1
  64. package/lib/typescript/commonjs/specs/NativeHotUpdater.d.ts +62 -0
  65. package/lib/typescript/commonjs/specs/NativeHotUpdater.d.ts.map +1 -1
  66. package/lib/typescript/commonjs/types.d.ts +115 -0
  67. package/lib/typescript/commonjs/types.d.ts.map +1 -1
  68. package/lib/typescript/commonjs/wrap.d.ts +132 -7
  69. package/lib/typescript/commonjs/wrap.d.ts.map +1 -1
  70. package/lib/typescript/module/DefaultResolver.d.ts +10 -0
  71. package/lib/typescript/module/DefaultResolver.d.ts.map +1 -0
  72. package/lib/typescript/module/checkForUpdate.d.ts +12 -13
  73. package/lib/typescript/module/checkForUpdate.d.ts.map +1 -1
  74. package/lib/typescript/module/error.d.ts +120 -0
  75. package/lib/typescript/module/error.d.ts.map +1 -1
  76. package/lib/typescript/module/fetchUpdateInfo.d.ts +3 -5
  77. package/lib/typescript/module/fetchUpdateInfo.d.ts.map +1 -1
  78. package/lib/typescript/module/index.d.ts +38 -44
  79. package/lib/typescript/module/index.d.ts.map +1 -1
  80. package/lib/typescript/module/native.d.ts +58 -2
  81. package/lib/typescript/module/native.d.ts.map +1 -1
  82. package/lib/typescript/module/specs/NativeHotUpdater.d.ts +62 -0
  83. package/lib/typescript/module/specs/NativeHotUpdater.d.ts.map +1 -1
  84. package/lib/typescript/module/types.d.ts +115 -0
  85. package/lib/typescript/module/types.d.ts.map +1 -1
  86. package/lib/typescript/module/wrap.d.ts +132 -7
  87. package/lib/typescript/module/wrap.d.ts.map +1 -1
  88. package/package.json +6 -6
  89. package/plugin/build/withHotUpdater.js +3 -3
  90. package/src/DefaultResolver.ts +36 -0
  91. package/src/checkForUpdate.ts +51 -56
  92. package/src/error.ts +153 -0
  93. package/src/fetchUpdateInfo.ts +10 -58
  94. package/src/index.ts +315 -206
  95. package/src/native.ts +88 -2
  96. package/src/specs/NativeHotUpdater.ts +63 -0
  97. package/src/types.ts +135 -0
  98. package/src/wrap.tsx +245 -34
  99. package/android/src/main/java/com/hotupdater/HotUpdaterFactory.kt +0 -52
  100. package/ios/HotUpdater/Internal/HotUpdaterFactory.swift +0 -24
  101. package/lib/commonjs/runUpdateProcess.js +0 -69
  102. package/lib/commonjs/runUpdateProcess.js.map +0 -1
  103. package/lib/module/runUpdateProcess.js +0 -64
  104. package/lib/module/runUpdateProcess.js.map +0 -1
  105. package/lib/typescript/commonjs/runUpdateProcess.d.ts +0 -49
  106. package/lib/typescript/commonjs/runUpdateProcess.d.ts.map +0 -1
  107. package/lib/typescript/module/runUpdateProcess.d.ts +0 -49
  108. package/lib/typescript/module/runUpdateProcess.d.ts.map +0 -1
  109. package/src/runUpdateProcess.ts +0 -80
@@ -1 +1 @@
1
- {"version":3,"names":["buildRequestHeaders","params","requestHeaders","updateStrategy","fingerprintHash","platform","bundleId","appVersion","minBundleId","channel","resolveSource","source","url","result","info","fetchUpdateInfo","onError","requestTimeout","resolvedSource","controller","AbortController","timeoutId","setTimeout","abort","headers","response","fetch","signal","clearTimeout","status","Error","statusText","json","error","name","exports"],"sourceRoot":"../../src","sources":["fetchUpdateInfo.ts"],"mappings":";;;;;;AAWA,SAASA,mBAAmBA,CAC1BC,MAA0B,EAC1BC,cAAuC,EACf;EACxB,MAAMC,cAA8B,GAAGF,MAAM,CAACG,eAAe,GACzD,aAAa,GACb,YAAY;EAEhB,OAAO;IACL,cAAc,EAAE,kBAAkB;IAClC,gBAAgB,EAAEH,MAAM,CAACI,QAAQ;IACjC,aAAa,EAAEJ,MAAM,CAACK,QAAQ;IAC9B,IAAIH,cAAc,KAAK,aAAa,GAChC;MAAE,oBAAoB,EAAEF,MAAM,CAACG;IAAiB,CAAC,GACjD;MAAE,eAAe,EAAEH,MAAM,CAACM;IAAW,CAAC,CAAC;IAC3C,IAAIN,MAAM,CAACO,WAAW,IAAI;MAAE,iBAAiB,EAAEP,MAAM,CAACO;IAAY,CAAC,CAAC;IACpE,IAAIP,MAAM,CAACQ,OAAO,IAAI;MAAE,WAAW,EAAER,MAAM,CAACQ;IAAQ,CAAC,CAAC;IACtD,GAAGP;EACL,CAAC;AACH;AAEA,eAAeQ,aAAaA,CAC1BC,MAAoB,EACpBV,MAA0B,EACiC;EAC3D,IAAI,OA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AIc,KAAK,CAAC,mBAAmB,CAAC,CAAC;IAC3C,CAAC,MAAM;MACLd,OAAO,GAAGiB,KAAc,CAAC;IAC3B;IACA,OAAO,IAAI;EACb;AACF,CAAC;AAACE,OAAA,CAAApB,eAAA,GAAAA,eAAA","ignoreList":[]}
1
+ {"version":3,"names":["fetchUpdateInfo","url","requestHeaders","onError","requestTimeout","controller","AbortController","timeoutId","setTimeout","abort","headers","response","fetch","signal","clearTimeout","status","Error","statusText","json","error","name","exports"],"sourceRoot":"../../src","sources":["fetchUpdateInfo.ts"],"mappings":";;;;;;AAEO,MAAMA,eAAe,GAAG,MAAAA,CAAO;EACpCC,GAAG;EACHC,cAAc;EACdC,OAAO;EACPC,cAAc,GAAG;AAMnB,CAAC,KAAoC;EACnC,IAAI;IACF,MAAMC,UAAU,GAAG,IAAIC,eAAe,CAAC,CAAC;IACxC,MAAMC,SAAS,GAAGC,UAAU,CAAC,MAAM;MACjCH,UAAU,CAACI,KAAK,CAAC,CAAC;IACpB,CAAC,EAAEL,cAAc,CAAC;IAElB,MAAMM,OAAO,GAAG;MACd,cAAc,EAAE,kBAAkB;MAClC,GAAGR;IACL,CAAC;IAED,MAAMS,QAAQ,GAAG,MAAMC,KAAK,CAACX,GAAG,EAAE;MAChCY,MAAM,EAAER,UAAU,CAACQ,MAAM;MACzBH;IACF,CAAC,CAAC;IACFI,YAAY,CAACP,SAAS,CAAC;IAEvB,IAAII,QAAQ,CAACI,MAAM,KAAK,GAAG,EAAE;MAC3B,MAAM,IAAIC,KAAK,CAACL,QAAQ,CAACM,UAAU,CAAC;IACtC;IACA,OAAON,QAAQ,CAACO,IAAI,CAAC,CAAC;EACxB,CAAC,CAAC,OAAOC,KAAc,EAAE;IACvB,IAAIA,KAAK,YAAYH,KAAK,IAAIG,KAAK,CAACC,IAAI,KAAK,YAAY,EAAE;MACzDjB,OAAO,GAAG,IAAIa,KAAK,CAAC,mBAAmB,CAAC,CAAC;IAC3C,CAAC,MAAM;MACLb,OAAO,GAAGgB,KAAc,CAAC;IAC3B;IACA,OAAO,IAAI;EACb;AACF,CAAC;AAACE,OAAA,CAAArB,eAAA,GAAAA,eAAA","ignoreList":[]}
@@ -5,7 +5,6 @@ Object.defineProperty(exports, "__esModule", {
5
5
  });
6
6
  var _exportNames = {
7
7
  HotUpdater: true,
8
- getUpdateSource: true,
9
8
  extractSignatureFailure: true,
10
9
  isSignatureVerificationError: true
11
10
  };
@@ -16,12 +15,6 @@ Object.defineProperty(exports, "extractSignatureFailure", {
16
15
  return _types.extractSignatureFailure;
17
16
  }
18
17
  });
19
- Object.defineProperty(exports, "getUpdateSource", {
20
- enumerable: true,
21
- get: function () {
22
- return _checkForUpdate.getUpdateSource;
23
- }
24
- });
25
18
  Object.defineProperty(exports, "isSignatureVerificationError", {
26
19
  enumerable: true,
27
20
  get: function () {
@@ -29,8 +22,8 @@ Object.defineProperty(exports, "isSignatureVerificationError", {
29
22
  }
30
23
  });
31
24
  var _checkForUpdate = require("./checkForUpdate.js");
25
+ var _DefaultResolver = require("./DefaultResolver.js");
32
26
  var _native = require("./native.js");
33
- var _runUpdateProcess = require("./runUpdateProcess.js");
34
27
  var _store = require("./store.js");
35
28
  Object.keys(_store).forEach(function (key) {
36
29
  if (key === "default" || key === "__esModule") return;
@@ -52,204 +45,252 @@ var _types = require("./types.js");
52
45
  progress
53
46
  });
54
47
  });
55
- const HotUpdater = exports.HotUpdater = {
56
- /**
57
- * `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.
58
- *
59
- * @param {object} options - Configuration options
60
- * @param {string} options.source - Update server URL
61
- * @param {object} [options.requestHeaders] - Request headers
62
- * @param {React.ComponentType} [options.fallbackComponent] - Component to display during updates
63
- * @param {boolean} [options.reloadOnForceUpdate=true] - Whether to automatically reload the app on force updates
64
- * @param {Function} [options.onUpdateProcessCompleted] - Callback after update process completes
65
- * @param {Function} [options.onProgress] - Callback to track bundle download progress
66
- * @returns {Function} Higher-order component that wraps the app component
67
- *
68
- * @example
69
- * ```tsx
70
- * export default HotUpdater.wrap({
71
- * source: "<your-update-server-url>",
72
- * requestHeaders: {
73
- * "Authorization": "Bearer <your-access-token>",
74
- * },
75
- * })(App);
76
- * ```
77
- */
78
- wrap: _wrap.wrap,
79
- /**
80
- * Reloads the app.
81
- */
82
- reload: _native.reload,
83
- /**
84
- * Returns whether an update has finished downloading in this app session.
85
- *
86
- * When it returns true, calling `HotUpdater.reload()` (or restarting the app)
87
- * will apply the downloaded update bundle.
88
- *
89
- * - Derived from `progress` reaching 1.0
90
- * - Resets to false when a new download starts (progress < 1)
91
- *
92
- * @returns {boolean} True if a downloaded update is ready to apply
93
- * @example
94
- * ```ts
95
- * if (HotUpdater.isUpdateDownloaded()) {
96
- * await HotUpdater.reload();
97
- * }
98
- * ```
99
- */
100
- isUpdateDownloaded: () => _store.hotUpdaterStore.getSnapshot().isUpdateDownloaded,
101
- /**
102
- * Fetches the current app version.
103
- */
104
- getAppVersion: _native.getAppVersion,
105
- /**
106
- * Fetches the current bundle ID of the app.
107
- */
108
- getBundleId: _native.getBundleId,
109
- /**
110
- * Retrieves the initial bundle ID based on the build time of the native app.
111
- */
112
- getMinBundleId: _native.getMinBundleId,
113
- /**
114
- * Fetches the current channel of the app.
115
- *
116
- * If no channel is specified, the app is assigned to the 'production' channel.
117
- *
118
- * @returns {string} The current release channel of the app
119
- * @default "production"
120
- * @example
121
- * ```ts
122
- * const channel = HotUpdater.getChannel();
123
- * console.log(`Current channel: ${channel}`);
124
- * ```
125
- */
126
- getChannel: _native.getChannel,
127
- /**
128
- * Adds a listener to HotUpdater events.
129
- *
130
- * @param {keyof HotUpdaterEvent} eventName - The name of the event to listen for
131
- * @param {(event: HotUpdaterEvent[T]) => void} listener - The callback function to handle the event
132
- * @returns {() => void} A cleanup function that removes the event listener
133
- *
134
- * @example
135
- * ```ts
136
- * const unsubscribe = HotUpdater.addListener("onProgress", ({ progress }) => {
137
- * console.log(`Update progress: ${progress * 100}%`);
138
- * });
139
- *
140
- * // Unsubscribe when no longer needed
141
- * unsubscribe();
142
- * ```
143
- */
144
- addListener: _native.addListener,
145
- /**
146
- * Manually checks for updates.
147
- *
148
- * @param {Object} config - Update check configuration
149
- * @param {string} config.source - Update server URL
150
- * @param {Record<string, string>} [config.requestHeaders] - Request headers
151
- *
152
- * @returns {Promise<UpdateInfo | null>} Update information or null if up to date
153
- *
154
- * @example
155
- * ```ts
156
- * const updateInfo = await HotUpdater.checkForUpdate({
157
- * source: "<your-update-server-url>",
158
- * requestHeaders: {
159
- * Authorization: "Bearer <your-access-token>",
160
- * },
161
- * });
162
- *
163
- * if (!updateInfo) {
164
- * console.log("App is up to date");
165
- * return;
166
- * }
167
- *
168
- * await HotUpdater.updateBundle(updateInfo.id, updateInfo.fileUrl);
169
- * if (updateInfo.shouldForceUpdate) {
170
- * await HotUpdater.reload();
171
- * }
172
- * ```
173
- */
174
- checkForUpdate: _checkForUpdate.checkForUpdate,
175
- /**
176
- * Manually checks and applies updates for the application.
177
- *
178
- * @param {RunUpdateProcessConfig} config - Update process configuration
179
- * @param {string} config.source - Update server URL
180
- * @param {Record<string, string>} [config.requestHeaders] - Request headers
181
- * @param {boolean} [config.reloadOnForceUpdate=false] - Whether to automatically reload on force update
182
- *
183
- * @example
184
- * ```ts
185
- * // Auto reload on force update
186
- * const result = await HotUpdater.runUpdateProcess({
187
- * source: "<your-update-server-url>",
188
- * requestHeaders: {
189
- * // Add necessary headers
190
- * },
191
- * reloadOnForceUpdate: true
192
- * });
193
- *
194
- * // Manually handle reload on force update
195
- * const result = await HotUpdater.runUpdateProcess({
196
- * source: "<your-update-server-url>",
197
- * reloadOnForceUpdate: false
198
- * });
199
- *
200
- * if(result.status !== "UP_TO_DATE" && result.shouldForceUpdate) {
201
- * await HotUpdater.reload();
202
- * }
203
- * ```
204
- *
205
- * @returns {Promise<RunUpdateProcessResponse>} The result of the update process
206
- */
207
- runUpdateProcess: _runUpdateProcess.runUpdateProcess,
208
- /**
209
- * Updates the bundle of the app.
210
- *
211
- * @param {UpdateBundleParams} params - Parameters object required for bundle update
212
- * @param {string} params.bundleId - The bundle ID of the app
213
- * @param {string|null} params.fileUrl - The URL of the zip file
214
- *
215
- * @returns {Promise<boolean>} Whether the update was successful
216
- *
217
- * @example
218
- * ```ts
219
- * const updateInfo = await HotUpdater.checkForUpdate({
220
- * source: "<your-update-server-url>",
221
- * requestHeaders: {
222
- * Authorization: "Bearer <your-access-token>",
223
- * },
224
- * });
225
- *
226
- * if (!updateInfo) {
227
- * return {
228
- * status: "UP_TO_DATE",
229
- * };
230
- * }
231
- *
232
- * await HotUpdater.updateBundle({
233
- * bundleId: updateInfo.id,
234
- * fileUrl: updateInfo.fileUrl
235
- * });
236
- * if (updateInfo.shouldForceUpdate) {
237
- * await HotUpdater.reload();
238
- * }
239
- * ```
240
- */
241
- updateBundle: _native.updateBundle,
242
- /**
243
- * Fetches the fingerprint of the app.
244
- *
245
- * @returns {string} The fingerprint of the app
246
- *
247
- * @example
248
- * ```ts
249
- * const fingerprint = HotUpdater.getFingerprintHash();
250
- * console.log(`Fingerprint: ${fingerprint}`);
251
- * ```
252
- */
253
- getFingerprintHash: _native.getFingerprintHash
254
- };
48
+
49
+ /**
50
+ * Creates a HotUpdater client instance with all update management methods.
51
+ * This function is called once on module initialization to create a singleton instance.
52
+ */
53
+ function createHotUpdaterClient() {
54
+ // Global configuration stored from wrap
55
+ const globalConfig = {
56
+ resolver: null
57
+ };
58
+ const ensureGlobalResolver = methodName => {
59
+ if (!globalConfig.resolver) {
60
+ throw new Error(`[HotUpdater] ${methodName} requires HotUpdater.wrap() to be used.\n\n` + `To fix this issue, wrap your root component with HotUpdater.wrap():\n\n` + `Option 1: With automatic updates\n` + ` export default HotUpdater.wrap({\n` + ` baseURL: "<your-update-server-url>",\n` + ` updateStrategy: "appVersion",\n` + ` updateMode: "auto"\n` + ` })(App);\n\n` + `Option 2: Manual updates only (custom flow)\n` + ` export default HotUpdater.wrap({\n` + ` baseURL: "<your-update-server-url>",\n` + ` updateMode: "manual"\n` + ` })(App);\n\n` + `For more information, visit: https://hot-updater.dev/docs/react-native-api/wrap`);
61
+ }
62
+ return globalConfig.resolver;
63
+ };
64
+ return {
65
+ /**
66
+ * `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.
67
+ *
68
+ * @param {object} options - Configuration options
69
+ * @param {string} options.source - Update server URL
70
+ * @param {object} [options.requestHeaders] - Request headers
71
+ * @param {React.ComponentType} [options.fallbackComponent] - Component to display during updates
72
+ * @param {boolean} [options.reloadOnForceUpdate=true] - Whether to automatically reload the app on force updates
73
+ * @param {Function} [options.onUpdateProcessCompleted] - Callback after update process completes
74
+ * @param {Function} [options.onProgress] - Callback to track bundle download progress
75
+ * @returns {Function} Higher-order component that wraps the app component
76
+ *
77
+ * @example
78
+ * ```tsx
79
+ * export default HotUpdater.wrap({
80
+ * baseURL: "<your-update-server-url>",
81
+ * updateStrategy: "appVersion",
82
+ * updateMode: "auto",
83
+ * requestHeaders: {
84
+ * "Authorization": "Bearer <your-access-token>",
85
+ * },
86
+ * })(App);
87
+ * ```
88
+ */
89
+ wrap: options => {
90
+ let normalizedOptions;
91
+ if ("baseURL" in options && options.baseURL) {
92
+ const {
93
+ baseURL,
94
+ ...rest
95
+ } = options;
96
+ normalizedOptions = {
97
+ ...rest,
98
+ resolver: (0, _DefaultResolver.createDefaultResolver)(baseURL)
99
+ };
100
+ } else if ("resolver" in options && options.resolver) {
101
+ normalizedOptions = options;
102
+ } else {
103
+ throw new Error(`[HotUpdater] Either baseURL or resolver must be provided.\n\n` + `Option 1: Using baseURL (recommended for most cases)\n` + ` export default HotUpdater.wrap({\n` + ` baseURL: "<your-update-server-url>",\n` + ` updateStrategy: "appVersion",\n` + ` updateMode: "auto"\n` + ` })(App);\n\n` + `Option 2: Using custom resolver (advanced)\n` + ` export default HotUpdater.wrap({\n` + ` resolver: {\n` + ` checkUpdate: async (params) => { /* custom logic */ },\n` + ` notifyAppReady: async (params) => { /* custom logic */ }\n` + ` },\n` + ` updateMode: "manual"\n` + ` })(App);\n\n` + `For more information, visit: https://hot-updater.dev/docs/react-native-api/wrap`);
104
+ }
105
+ globalConfig.resolver = normalizedOptions.resolver;
106
+ globalConfig.requestHeaders = options.requestHeaders;
107
+ globalConfig.requestTimeout = options.requestTimeout;
108
+ return (0, _wrap.wrap)(normalizedOptions);
109
+ },
110
+ /**
111
+ * Reloads the app.
112
+ */
113
+ reload: _native.reload,
114
+ /**
115
+ * Returns whether an update has finished downloading in this app session.
116
+ *
117
+ * When it returns true, calling `HotUpdater.reload()` (or restarting the app)
118
+ * will apply the downloaded update bundle.
119
+ *
120
+ * - Derived from `progress` reaching 1.0
121
+ * - Resets to false when a new download starts (progress < 1)
122
+ *
123
+ * @returns {boolean} True if a downloaded update is ready to apply
124
+ * @example
125
+ * ```ts
126
+ * if (HotUpdater.isUpdateDownloaded()) {
127
+ * await HotUpdater.reload();
128
+ * }
129
+ * ```
130
+ */
131
+ isUpdateDownloaded: () => _store.hotUpdaterStore.getSnapshot().isUpdateDownloaded,
132
+ /**
133
+ * Fetches the current app version.
134
+ */
135
+ getAppVersion: _native.getAppVersion,
136
+ /**
137
+ * Fetches the current bundle ID of the app.
138
+ */
139
+ getBundleId: _native.getBundleId,
140
+ /**
141
+ * Retrieves the initial bundle ID based on the build time of the native app.
142
+ */
143
+ getMinBundleId: _native.getMinBundleId,
144
+ /**
145
+ * Fetches the current channel of the app.
146
+ *
147
+ * If no channel is specified, the app is assigned to the 'production' channel.
148
+ *
149
+ * @returns {string} The current release channel of the app
150
+ * @default "production"
151
+ * @example
152
+ * ```ts
153
+ * const channel = HotUpdater.getChannel();
154
+ * console.log(`Current channel: ${channel}`);
155
+ * ```
156
+ */
157
+ getChannel: _native.getChannel,
158
+ /**
159
+ * Adds a listener to HotUpdater events.
160
+ *
161
+ * @param {keyof HotUpdaterEvent} eventName - The name of the event to listen for
162
+ * @param {(event: HotUpdaterEvent[T]) => void} listener - The callback function to handle the event
163
+ * @returns {() => void} A cleanup function that removes the event listener
164
+ *
165
+ * @example
166
+ * ```ts
167
+ * const unsubscribe = HotUpdater.addListener("onProgress", ({ progress }) => {
168
+ * console.log(`Update progress: ${progress * 100}%`);
169
+ * });
170
+ *
171
+ * // Unsubscribe when no longer needed
172
+ * unsubscribe();
173
+ * ```
174
+ */
175
+ addListener: _native.addListener,
176
+ /**
177
+ * Manually checks for updates.
178
+ *
179
+ * @param {Object} config - Update check configuration
180
+ * @param {string} config.source - Update server URL
181
+ * @param {Record<string, string>} [config.requestHeaders] - Request headers
182
+ *
183
+ * @returns {Promise<UpdateInfo | null>} Update information or null if up to date
184
+ *
185
+ * @example
186
+ * ```ts
187
+ * const updateInfo = await HotUpdater.checkForUpdate({
188
+ * source: "<your-update-server-url>",
189
+ * requestHeaders: {
190
+ * Authorization: "Bearer <your-access-token>",
191
+ * },
192
+ * });
193
+ *
194
+ * if (!updateInfo) {
195
+ * console.log("App is up to date");
196
+ * return;
197
+ * }
198
+ *
199
+ * await HotUpdater.updateBundle(updateInfo.id, updateInfo.fileUrl);
200
+ * if (updateInfo.shouldForceUpdate) {
201
+ * await HotUpdater.reload();
202
+ * }
203
+ * ```
204
+ */
205
+ checkForUpdate: config => {
206
+ const resolver = ensureGlobalResolver("checkForUpdate");
207
+ const mergedConfig = {
208
+ ...config,
209
+ resolver,
210
+ requestHeaders: {
211
+ ...globalConfig.requestHeaders,
212
+ ...config.requestHeaders
213
+ },
214
+ requestTimeout: config.requestTimeout ?? globalConfig.requestTimeout
215
+ };
216
+ return (0, _checkForUpdate.checkForUpdate)(mergedConfig);
217
+ },
218
+ /**
219
+ * Updates the bundle of the app.
220
+ *
221
+ * @param {UpdateBundleParams} params - Parameters object required for bundle update
222
+ * @param {string} params.bundleId - The bundle ID of the app
223
+ * @param {string|null} params.fileUrl - The URL of the zip file
224
+ *
225
+ * @returns {Promise<boolean>} Whether the update was successful
226
+ *
227
+ * @example
228
+ * ```ts
229
+ * const updateInfo = await HotUpdater.checkForUpdate({
230
+ * source: "<your-update-server-url>",
231
+ * requestHeaders: {
232
+ * Authorization: "Bearer <your-access-token>",
233
+ * },
234
+ * });
235
+ *
236
+ * if (!updateInfo) {
237
+ * return {
238
+ * status: "UP_TO_DATE",
239
+ * };
240
+ * }
241
+ *
242
+ * await HotUpdater.updateBundle({
243
+ * bundleId: updateInfo.id,
244
+ * fileUrl: updateInfo.fileUrl
245
+ * });
246
+ * if (updateInfo.shouldForceUpdate) {
247
+ * await HotUpdater.reload();
248
+ * }
249
+ * ```
250
+ */
251
+ updateBundle: params => {
252
+ ensureGlobalResolver("updateBundle");
253
+ return (0, _native.updateBundle)(params);
254
+ },
255
+ /**
256
+ * Fetches the fingerprint of the app.
257
+ *
258
+ * @returns {string} The fingerprint of the app
259
+ *
260
+ * @example
261
+ * ```ts
262
+ * const fingerprint = HotUpdater.getFingerprintHash();
263
+ * console.log(`Fingerprint: ${fingerprint}`);
264
+ * ```
265
+ */
266
+ getFingerprintHash: _native.getFingerprintHash,
267
+ /**
268
+ * Gets the list of bundle IDs that have been marked as crashed.
269
+ * These bundles will be rejected if attempted to install again.
270
+ *
271
+ * @returns {string[]} Array of crashed bundle IDs
272
+ *
273
+ * @example
274
+ * ```ts
275
+ * const crashedBundles = HotUpdater.getCrashHistory();
276
+ * console.log("Crashed bundles:", crashedBundles);
277
+ * ```
278
+ */
279
+ getCrashHistory: _native.getCrashHistory,
280
+ /**
281
+ * Clears the crashed bundle history, allowing previously crashed bundles
282
+ * to be installed again.
283
+ *
284
+ * @returns {boolean} true if clearing was successful
285
+ *
286
+ * @example
287
+ * ```ts
288
+ * // Clear crash history to allow retrying a previously failed bundle
289
+ * HotUpdater.clearCrashHistory();
290
+ * ```
291
+ */
292
+ clearCrashHistory: _native.clearCrashHistory
293
+ };
294
+ }
295
+ const HotUpdater = exports.HotUpdater = createHotUpdaterClient();
255
296
  //# sourceMappingURL=index.js.map
@@ -1 +1 @@
1
- {"version":3,"names":["_checkForUpdate","require","_native","_runUpdateProcess","_store","Object","keys","forEach","key","prototype","hasOwnProperty","call","_exportNames","exports","defineProperty","enumerable","get","_wrap","_types","addListener","progress","hotUpdaterStore","setState","HotUpdater","wrap","reload","isUpdateDownloaded","getSnapshot","getAppVersion","getBundleId","getMinBundleId","getChannel","checkForUpdate","runUpdateProcess","updateBundle","getFingerprintHash"],"sourceRoot":"../../src","sources":["index.ts"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,IAAAA,eAAA,GAAAC,OAAA;AACA,IAAAC,OAAA,GAAAD,OAAA;AAUA,IAAAE,iBAAA,GAAAF,OAAA;AACA,IAAAG,MAAA,GAAAH,OAAA;AAIAI,MAAA,CAAAC,IAAA,CAAAF,MAAA,EAAAG,OAAA,WAAAC,GAAA;EAAA,IAAAA,GAAA,kBAAAA,GAAA;EAAA,IAAAH,MAAA,CAAAI,SAAA,CAAAC,cAAA,CAAAC,IAAA,CAAAC,YAAA,EAAAJ,GAAA;EAAA,IAAAA,GAAA,IAAAK,OAAA,IAAAA,OAAA,CAAAL,GAAA,MAAAJ,MAAA,CAAAI,GAAA;EAAAH,MAAA,CAAAS,cAAA,CAAAD,OAAA,EAAAL,GAAA;IAAAO,UAAA;IAAAC,GAAA,WAAAA,CAAA;MAAA,OAAAZ,MAAA,CAAAI,GAAA;IAAA;EAAA;AAAA;AAHA,IAAAS,KAAA,GAAAhB,OAAA;AAIA,IAAAiB,MAAA,GAAAjB,OAAA;AAOA,IAAAkB,mBAAW,EAAC,YAAY,EAAE,CAAC;EAAEC;AAAS,CAAC,KAAK;EAC1CC,sBAAe,CAACC,QAAQ,CAAC;IACvBF;EACF,CAAC,CAAC;AACJ,CAAC,CAAC;AAEK,MAAMG,UAAU,GAAAV,OAAA,CAAAU,UAAA,GAAG;EACxB;AACF;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;EACEC,IAAI,EAAJA,UAAI;EACJ;AACF;AACA;EACEC,MAAM,EAANA,cAAM;EACN;AACF;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;EACEC,kBAAkB,EAAEA,CAAA,KAAML,sBAAe,CAACM,WAAW,CAAC,CAAC,CAACD,kBAAkB;EAC1E;AACF;AACA;EACEE,aAAa,EAAbA,qBAAa;EACb;AACF;AACA;EACEC,WAAW,EAAXA,mBAAW;EACX;AACF;AACA;EACEC,cAAc,EAAdA,sBAAc;EACd;AACF;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;EACEC,UAAU,EAAVA,kBAAU;EACV;AACF;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;EACEZ,WAAW,EAAXA,mBAAW;EACX;AACF;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;EACEa,cAAc,EAAdA,8BAAc;EACd;AACF;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;EACEC,gBAAgB,EAAhBA,kCAAgB;EAChB;AACF;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;EACEC,YAAY,EAAZA,oBAAY;EACZ;AACF;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;EACEC,kBAAkB,EAAlBA;AACF,CAAC","ignoreList":[]}
1
+ {"version":3,"names":["_checkForUpdate","require","_DefaultResolver","_native","_store","Object","keys","forEach","key","prototype","hasOwnProperty","call","_exportNames","exports","defineProperty","enumerable","get","_wrap","_types","addListener","progress","hotUpdaterStore","setState","createHotUpdaterClient","globalConfig","resolver","ensureGlobalResolver","methodName","Error","wrap","options","normalizedOptions","baseURL","rest","createDefaultResolver","requestHeaders","requestTimeout","reload","isUpdateDownloaded","getSnapshot","getAppVersion","getBundleId","getMinBundleId","getChannel","checkForUpdate","config","mergedConfig","updateBundle","params","getFingerprintHash","getCrashHistory","clearCrashHistory","HotUpdater"],"sourceRoot":"../../src","sources":["index.ts"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;AAAA,IAAAA,eAAA,GAAAC,OAAA;AAKA,IAAAC,gBAAA,GAAAD,OAAA;AACA,IAAAE,OAAA,GAAAF,OAAA;AAaA,IAAAG,MAAA,GAAAH,OAAA;AAKAI,MAAA,CAAAC,IAAA,CAAAF,MAAA,EAAAG,OAAA,WAAAC,GAAA;EAAA,IAAAA,GAAA,kBAAAA,GAAA;EAAA,IAAAH,MAAA,CAAAI,SAAA,CAAAC,cAAA,CAAAC,IAAA,CAAAC,YAAA,EAAAJ,GAAA;EAAA,IAAAA,GAAA,IAAAK,OAAA,IAAAA,OAAA,CAAAL,GAAA,MAAAJ,MAAA,CAAAI,GAAA;EAAAH,MAAA,CAAAS,cAAA,CAAAD,OAAA,EAAAL,GAAA;IAAAO,UAAA;IAAAC,GAAA,WAAAA,CAAA;MAAA,OAAAZ,MAAA,CAAAI,GAAA;IAAA;EAAA;AAAA;AAHA,IAAAS,KAAA,GAAAhB,OAAA;AAIA,IAAAiB,MAAA,GAAAjB,OAAA;AAUA,IAAAkB,mBAAW,EAAC,YAAY,EAAE,CAAC;EAAEC;AAAS,CAAC,KAAK;EAC1CC,sBAAe,CAACC,QAAQ,CAAC;IACvBF;EACF,CAAC,CAAC;AACJ,CAAC,CAAC;;AAEF;AACA;AACA;AACA;AACA,SAASG,sBAAsBA,CAAA,EAAG;EAChC;EACA,MAAMC,YAIL,GAAG;IACFC,QAA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,GAAGM,iBAAiB,CAACN,QAAQ;MAClDD,YAAY,CAACW,cAAc,GAAGL,OAAO,CAACK,cAAc;MACpDX,YAAY,CAACY,cAAc,GAAGN,OAAO,CAACM,cAAc;MAEpD,OAAO,IAAAP,UAAI,EAACE,iBAAiB,CAAC;IAChC,CAAC;IAED;AACJ;AACA;IACIM,MAAM,EAANA,cAAM;IAEN;AACJ;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;IACIC,kBAAkB,EAAEA,CAAA,KAAMjB,sBAAe,CAACkB,WAAW,CAAC,CAAC,CAACD,kBAAkB;IAE1E;AACJ;AACA;IACIE,aAAa,EAAbA,qBAAa;IAEb;AACJ;AACA;IACIC,WAAW,EAAXA,mBAAW;IAEX;AACJ;AACA;IACIC,cAAc,EAAdA,sBAAc;IAEd;AACJ;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;IACIC,UAAU,EAAVA,kBAAU;IAEV;AACJ;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;IACIxB,WAAW,EAAXA,mBAAW;IAEX;AACJ;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;IACIyB,cAAc,EAAGC,MAA6B,IAAK;MACjD,MAAMpB,QAAQ,GAAGC,oBAAoB,CAAC,gBAAgB,CAAC;MAEvD,MAAMoB,YAA2C,GAAG;QAClD,GAAGD,MAAM;QACTpB,QAAQ;QACRU,cAAc,EAAE;UACd,GAAGX,YAAY,CAACW,cAAc;UAC9B,GAAGU,MAAM,CAACV;QACZ,CAAC;QACDC,cAAc,EAAES,MAAM,CAACT,cAAc,IAAIZ,YAAY,CAACY;MACxD,CAAC;MAED,OAAO,IAAAQ,8BAAc,EAACE,YAAY,CAAC;IACrC,CAAC;IAED;AACJ;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;IACIC,YAAY,EAAGC,MAAoB,IAAK;MACtCtB,oBAAoB,CAAC,cAAc,CAAC;MACpC,OAAO,IAAAqB,oBAAY,EAACC,MAAM,CAAC;IAC7B,CAAC;IAED;AACJ;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;IACIC,kBAAkB,EAAlBA,0BAAkB;IAElB;AACJ;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;IACIC,eAAe,EAAfA,uBAAe;IAEf;AACJ;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;IACIC,iBAAiB,EAAjBA;EACF,CAAC;AACH;AAEO,MAAMC,UAAU,GAAAvC,OAAA,CAAAuC,UAAA,GAAG7B,sBAAsB,CAAC,CAAC","ignoreList":[]}