@capgo/capacitor-updater 4.15.5 → 4.16.0

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/README.md CHANGED
@@ -182,14 +182,14 @@ Notify Capacitor Updater that the current bundle is working (a rollback will occ
182
182
  ### download(...)
183
183
 
184
184
  ```typescript
185
- download(options: { url: string; version: string; }) => Promise<BundleInfo>
185
+ download(options: { url: string; version: string; sessionKey?: string; checksum?: string; }) => Promise<BundleInfo>
186
186
  ```
187
187
 
188
188
  Download a new bundle from the provided URL, it should be a zip file, with files inside or with a unique id inside with all your files
189
189
 
190
- | Param | Type |
191
- | ------------- | ---------------------------------------------- |
192
- | **`options`** | <code>{ url: string; version: string; }</code> |
190
+ | Param | Type |
191
+ | ------------- | -------------------------------------------------------------------------------------- |
192
+ | **`options`** | <code>{ url: string; version: string; sessionKey?: string; checksum?: string; }</code> |
193
193
 
194
194
  **Returns:** <code>Promise&lt;<a href="#bundleinfo">BundleInfo</a>&gt;</code>
195
195
 
@@ -64,7 +64,7 @@ public class CapacitorUpdater {
64
64
  private static final String bundleDirectory = "versions";
65
65
 
66
66
  public static final String TAG = "Capacitor-updater";
67
- public static final String pluginVersion = "4.15.5";
67
+ public static final String pluginVersion = "4.16.0";
68
68
  public static final int timeout = 20000;
69
69
 
70
70
  public SharedPreferences.Editor editor;
@@ -281,6 +281,12 @@ public class CapacitorUpdater {
281
281
  checksum
282
282
  );
283
283
  if (dest == null) {
284
+ final JSObject ret = new JSObject();
285
+ ret.put(
286
+ "version",
287
+ CapacitorUpdater.this.getCurrentBundle().getVersionName()
288
+ );
289
+ CapacitorUpdater.this.notifyListeners("downloadFailed", ret);
284
290
  CapacitorUpdater.this.sendStats(
285
291
  "download_fail",
286
292
  CapacitorUpdater.this.getCurrentBundle().getVersionName()
@@ -354,6 +360,12 @@ public class CapacitorUpdater {
354
360
  }
355
361
  } catch (IOException e) {
356
362
  e.printStackTrace();
363
+ final JSObject ret = new JSObject();
364
+ ret.put(
365
+ "version",
366
+ CapacitorUpdater.this.getCurrentBundle().getVersionName()
367
+ );
368
+ CapacitorUpdater.this.notifyListeners("downloadFailed", ret);
357
369
  CapacitorUpdater.this.sendStats(
358
370
  "download_fail",
359
371
  CapacitorUpdater.this.getCurrentBundle().getVersionName()
@@ -516,7 +528,8 @@ public class CapacitorUpdater {
516
528
  public BundleInfo download(
517
529
  final String url,
518
530
  final String version,
519
- final String sessionKey
531
+ final String sessionKey,
532
+ final String checksum
520
533
  ) throws IOException {
521
534
  final String id = this.randomString(10);
522
535
  this.saveBundleInfo(
@@ -534,7 +547,6 @@ public class CapacitorUpdater {
534
547
  this.notifyDownload(id, 5);
535
548
  final String dest = this.randomString(10);
536
549
  final File downloaded = this.downloadFile(id, url, dest);
537
- final String checksum = this.getChecksum(downloaded);
538
550
  this.finishDownload(id, dest, version, sessionKey, checksum, false);
539
551
  BundleInfo info = new BundleInfo(
540
552
  id,
@@ -324,6 +324,7 @@ public class CapacitorUpdaterPlugin
324
324
  final String url = call.getString("url");
325
325
  final String version = call.getString("version");
326
326
  final String sessionKey = call.getString("sessionKey", "");
327
+ final String checksum = call.getString("checksum", "");
327
328
  if (url == null) {
328
329
  Log.e(CapacitorUpdater.TAG, "Download called without url");
329
330
  call.reject("Download called without url");
@@ -345,8 +346,10 @@ public class CapacitorUpdaterPlugin
345
346
  CapacitorUpdaterPlugin.this.implementation.download(
346
347
  url,
347
348
  version,
348
- sessionKey
349
+ sessionKey,
350
+ checksum
349
351
  );
352
+
350
353
  call.resolve(downloaded.toJSON());
351
354
  } catch (final IOException e) {
352
355
  Log.e(CapacitorUpdater.TAG, "Failed to download from: " + url, e);
package/dist/docs.json CHANGED
@@ -28,12 +28,12 @@
28
28
  },
29
29
  {
30
30
  "name": "download",
31
- "signature": "(options: { url: string; version: string; }) => Promise<BundleInfo>",
31
+ "signature": "(options: { url: string; version: string; sessionKey?: string; checksum?: string; }) => Promise<BundleInfo>",
32
32
  "parameters": [
33
33
  {
34
34
  "name": "options",
35
35
  "docs": "",
36
- "type": "{ url: string; version: string; }"
36
+ "type": "{ url: string; version: string; sessionKey?: string | undefined; checksum?: string | undefined; }"
37
37
  }
38
38
  ],
39
39
  "returns": "Promise<BundleInfo>",
@@ -221,6 +221,8 @@ export interface CapacitorUpdaterPlugin {
221
221
  download(options: {
222
222
  url: string;
223
223
  version: string;
224
+ sessionKey?: string;
225
+ checksum?: string;
224
226
  }): Promise<BundleInfo>;
225
227
  /**
226
228
  * Set the next bundle to be used when the app is reloaded.
@@ -335,7 +335,7 @@ extension CustomError: LocalizedError {
335
335
 
336
336
  private func decryptFile(filePath: URL, sessionKey: String) throws {
337
337
  if self.privateKey == "" || sessionKey == "" {
338
- print("\(self.TAG) Cannot fond privateKey or sessionKey")
338
+ print("\(self.TAG) Cannot found privateKey or sessionKey")
339
339
  return
340
340
  }
341
341
  do {
@@ -345,7 +345,10 @@ extension CustomError: LocalizedError {
345
345
  }
346
346
 
347
347
  let sessionKeyArray: [String] = sessionKey.components(separatedBy: ":")
348
- let ivData: Data = Data(base64Encoded: sessionKeyArray[0])!
348
+ guard let ivData: Data = Data(base64Encoded: sessionKeyArray[0]) else {
349
+ print("cannot decode sessionKey", sessionKey)
350
+ return
351
+ }
349
352
  let sessionKeyDataEncrypted: Data = Data(base64Encoded: sessionKeyArray[1])!
350
353
  let sessionKeyDataDecrypted: Data = rsaPrivateKey.decrypt(data: sessionKeyDataEncrypted)!
351
354
  let aesPrivateKey: AES128Key = AES128Key(iv: ivData, aes128Key: sessionKeyDataDecrypted)
@@ -441,6 +444,7 @@ extension CustomError: LocalizedError {
441
444
  let semaphore: DispatchSemaphore = DispatchSemaphore(value: 0)
442
445
  let id: String = self.randomString(length: 10)
443
446
  var checksum: String = ""
447
+
444
448
  var mainError: NSError?
445
449
  let destination: DownloadRequest.Destination = { _, _ in
446
450
  let documentsURL: URL = FileManager.default.urls(for: .documentDirectory, in: .userDomainMask)[0]
@@ -111,12 +111,23 @@ public class CapacitorUpdaterPlugin: CAPPlugin {
111
111
  return
112
112
  }
113
113
  let sessionKey = call.getString("sessionKey", "")
114
+ let checksum = call.getString("checksum", "")
114
115
  let url = URL(string: urlString)
115
116
  print("\(self.implementation.TAG) Downloading \(url!)")
116
117
  DispatchQueue.global(qos: .background).async {
117
118
  do {
118
- let res = try self.implementation.download(url: url!, version: version, sessionKey: sessionKey)
119
- call.resolve(res.toJSON())
119
+ let next = try self.implementation.download(url: url!, version: version, sessionKey: sessionKey)
120
+ if checksum != "" && next.getChecksum() != checksum {
121
+ print("\(self.implementation.TAG) Error checksum", next.getChecksum(), checksum)
122
+ self.implementation.sendStats(action: "checksum_fail", versionName: next.getVersionName())
123
+ let resDel = self.implementation.delete(id: next.getId())
124
+ if !resDel {
125
+ print("\(self.implementation.TAG) Delete failed, id \(next.getId()) doesn't exist")
126
+ }
127
+ return
128
+ }
129
+ self.notifyListeners("updateAvailable", data: ["bundle": next.toJSON()])
130
+ call.resolve(next.toJSON())
120
131
  } catch {
121
132
  print("\(self.implementation.TAG) Failed to download from: \(url!) \(error.localizedDescription)")
122
133
  self.notifyListeners("downloadFailed", data: ["version": version])
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@capgo/capacitor-updater",
3
- "version": "4.15.5",
3
+ "version": "4.16.0",
4
4
  "packageManager": "pnpm@7.21.0",
5
5
  "license": "LGPL-3.0-only",
6
6
  "description": "Live update for capacitor apps",