@capgo/capacitor-updater 6.25.8 → 6.27.10

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.
@@ -71,7 +71,7 @@ public class CapacitorUpdaterPlugin extends Plugin {
71
71
  private static final String[] BREAKING_EVENT_NAMES = { "breakingAvailable", "majorAvailable" };
72
72
  private static final String LAST_FAILED_BUNDLE_PREF_KEY = "CapacitorUpdater.lastFailedBundle";
73
73
 
74
- private final String pluginVersion = "6.25.8";
74
+ private final String pluginVersion = "6.27.10";
75
75
  private static final String DELAY_CONDITION_PREFERENCES = "";
76
76
 
77
77
  private SharedPreferences.Editor editor;
@@ -1572,7 +1572,7 @@ public class CapacitorUpdaterPlugin extends Plugin {
1572
1572
  }
1573
1573
 
1574
1574
  private void endBackGroundTaskWithNotif(String msg, String latestVersionName, BundleInfo current, Boolean error) {
1575
- endBackGroundTaskWithNotif(msg, latestVersionName, current, error, false, "download_fail", "downloadFailed");
1575
+ endBackGroundTaskWithNotif(msg, latestVersionName, current, error, false, "download_fail", "downloadFailed", true);
1576
1576
  }
1577
1577
 
1578
1578
  private void endBackGroundTaskWithNotif(
@@ -1582,7 +1582,7 @@ public class CapacitorUpdaterPlugin extends Plugin {
1582
1582
  Boolean error,
1583
1583
  Boolean isDirectUpdate
1584
1584
  ) {
1585
- endBackGroundTaskWithNotif(msg, latestVersionName, current, error, isDirectUpdate, "download_fail", "downloadFailed");
1585
+ endBackGroundTaskWithNotif(msg, latestVersionName, current, error, isDirectUpdate, "download_fail", "downloadFailed", true);
1586
1586
  }
1587
1587
 
1588
1588
  private void endBackGroundTaskWithNotif(
@@ -1593,6 +1593,19 @@ public class CapacitorUpdaterPlugin extends Plugin {
1593
1593
  Boolean isDirectUpdate,
1594
1594
  String failureAction,
1595
1595
  String failureEvent
1596
+ ) {
1597
+ endBackGroundTaskWithNotif(msg, latestVersionName, current, error, isDirectUpdate, failureAction, failureEvent, true);
1598
+ }
1599
+
1600
+ private void endBackGroundTaskWithNotif(
1601
+ String msg,
1602
+ String latestVersionName,
1603
+ BundleInfo current,
1604
+ Boolean error,
1605
+ Boolean isDirectUpdate,
1606
+ String failureAction,
1607
+ String failureEvent,
1608
+ boolean shouldSendStats
1596
1609
  ) {
1597
1610
  if (error) {
1598
1611
  logger.info(
@@ -1603,7 +1616,9 @@ public class CapacitorUpdaterPlugin extends Plugin {
1603
1616
  "latestVersionName: " +
1604
1617
  latestVersionName
1605
1618
  );
1606
- this.implementation.sendStats(failureAction, current.getVersionName());
1619
+ if (shouldSendStats) {
1620
+ this.implementation.sendStats(failureAction, current.getVersionName());
1621
+ }
1607
1622
  final JSObject ret = new JSObject();
1608
1623
  ret.put("version", latestVersionName);
1609
1624
  this.notifyListeners(failureEvent, ret);
@@ -1634,14 +1649,23 @@ public class CapacitorUpdaterPlugin extends Plugin {
1634
1649
  if (jsRes.has("error")) {
1635
1650
  String error = jsRes.getString("error");
1636
1651
  String errorMessage = jsRes.has("message") ? jsRes.getString("message") : "server did not provide a message";
1637
- logger.error("getLatest failed with error: " + error + ", message: " + errorMessage);
1652
+ int statusCode = jsRes.has("statusCode") ? jsRes.optInt("statusCode", 0) : 0;
1653
+ boolean responseIsOk = statusCode >= 200 && statusCode < 300;
1654
+
1655
+ logger.error(
1656
+ "getLatest failed with error: " + error + ", message: " + errorMessage + ", statusCode: " + statusCode
1657
+ );
1638
1658
  String latestVersion = jsRes.has("version") ? jsRes.getString("version") : current.getVersionName();
1659
+
1639
1660
  CapacitorUpdaterPlugin.this.endBackGroundTaskWithNotif(
1640
1661
  errorMessage,
1641
1662
  latestVersion,
1642
1663
  current,
1643
1664
  true,
1644
- plannedDirectUpdate
1665
+ plannedDirectUpdate,
1666
+ "download_fail",
1667
+ "downloadFailed",
1668
+ !responseIsOk
1645
1669
  );
1646
1670
  return;
1647
1671
  }
@@ -871,11 +871,13 @@ public class CapgoUpdater {
871
871
  @Override
872
872
  public void onResponse(@NonNull Call call, @NonNull Response response) throws IOException {
873
873
  try (ResponseBody responseBody = response.body()) {
874
+ final int statusCode = response.code();
874
875
  // Check for 429 rate limit
875
876
  if (checkAndHandleRateLimitResponse(response)) {
876
877
  Map<String, Object> retError = new HashMap<>();
877
878
  retError.put("message", "Rate limit exceeded");
878
879
  retError.put("error", "rate_limit_exceeded");
880
+ retError.put("statusCode", statusCode);
879
881
  callback.callback(retError);
880
882
  return;
881
883
  }
@@ -884,6 +886,7 @@ public class CapgoUpdater {
884
886
  Map<String, Object> retError = new HashMap<>();
885
887
  retError.put("message", "Server error: " + response.code());
886
888
  retError.put("error", "response_error");
889
+ retError.put("statusCode", statusCode);
887
890
  callback.callback(retError);
888
891
  return;
889
892
  }
@@ -901,11 +904,13 @@ public class CapgoUpdater {
901
904
  } else {
902
905
  retError.put("message", "server did not provide a message");
903
906
  }
907
+ retError.put("statusCode", statusCode);
904
908
  callback.callback(retError);
905
909
  return;
906
910
  }
907
911
 
908
912
  Map<String, Object> ret = new HashMap<>();
913
+ ret.put("statusCode", statusCode);
909
914
 
910
915
  Iterator<String> keys = jsonResponse.keys();
911
916
  while (keys.hasNext()) {
@@ -54,7 +54,7 @@ public class CapacitorUpdaterPlugin: CAPPlugin, CAPBridgedPlugin {
54
54
  CAPPluginMethod(name: "isShakeMenuEnabled", returnType: CAPPluginReturnPromise)
55
55
  ]
56
56
  public var implementation = CapgoUpdater()
57
- private let pluginVersion: String = "6.25.8"
57
+ private let pluginVersion: String = "6.27.10"
58
58
  static let updateUrlDefault = "https://plugin.capgo.app/updates"
59
59
  static let statsUrlDefault = "https://plugin.capgo.app/stats"
60
60
  static let channelUrlDefault = "https://plugin.capgo.app/channel_self"
@@ -1234,10 +1234,13 @@ public class CapacitorUpdaterPlugin: CAPPlugin, CAPBridgedPlugin {
1234
1234
  current: BundleInfo,
1235
1235
  error: Bool = true,
1236
1236
  failureAction: String = "download_fail",
1237
- failureEvent: String = "downloadFailed"
1237
+ failureEvent: String = "downloadFailed",
1238
+ sendStats: Bool = true
1238
1239
  ) {
1239
1240
  if error {
1240
- self.implementation.sendStats(action: failureAction, versionName: current.getVersionName())
1241
+ if sendStats {
1242
+ self.implementation.sendStats(action: failureAction, versionName: current.getVersionName())
1243
+ }
1241
1244
  self.notifyListeners(failureEvent, data: ["version": latestVersionName])
1242
1245
  }
1243
1246
  self.notifyListeners("noNeedUpdate", data: ["bundle": current.toJSON()])
@@ -1265,11 +1268,14 @@ public class CapacitorUpdaterPlugin: CAPPlugin, CAPBridgedPlugin {
1265
1268
  // Handle network errors and other failures first
1266
1269
  if let backendError = res.error, !backendError.isEmpty {
1267
1270
  self.logger.error("getLatest failed with error: \(backendError)")
1271
+ let statusCode = res.statusCode
1272
+ let responseIsOk = statusCode >= 200 && statusCode < 300
1268
1273
  self.endBackGroundTaskWithNotif(
1269
1274
  msg: res.message ?? backendError,
1270
1275
  latestVersionName: res.version,
1271
1276
  current: current,
1272
- error: true
1277
+ error: true,
1278
+ sendStats: !responseIsOk
1273
1279
  )
1274
1280
  return
1275
1281
  }
@@ -343,6 +343,7 @@ import UIKit
343
343
  request.validate().responseDecodable(of: AppVersionDec.self) { response in
344
344
  switch response.result {
345
345
  case .success:
346
+ latest.statusCode = response.response?.statusCode ?? 0
346
347
  if let url = response.value?.url {
347
348
  latest.url = url
348
349
  }
@@ -377,6 +378,7 @@ import UIKit
377
378
  self.logger.error("Error getting Latest \(response.value.debugDescription) \(error)")
378
379
  latest.message = "Error getting Latest \(String(describing: response.value))"
379
380
  latest.error = "response_error"
381
+ latest.statusCode = response.response?.statusCode ?? 0
380
382
  }
381
383
  semaphore.signal()
382
384
  }
@@ -160,6 +160,7 @@ struct AppVersionDec: Decodable {
160
160
  let breaking: Bool?
161
161
  let data: [String: String]?
162
162
  let manifest: [ManifestEntry]?
163
+ // The HTTP status code is captured separately in CapgoUpdater; this struct only mirrors JSON.
163
164
  }
164
165
 
165
166
  public class AppVersion: NSObject {
@@ -173,6 +174,7 @@ public class AppVersion: NSObject {
173
174
  var breaking: Bool?
174
175
  var data: [String: String]?
175
176
  var manifest: [ManifestEntry]?
177
+ var statusCode: Int = 0
176
178
  }
177
179
 
178
180
  extension AppVersion {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@capgo/capacitor-updater",
3
- "version": "6.25.8",
3
+ "version": "6.27.10",
4
4
  "license": "MPL-2.0",
5
5
  "description": "Live update for capacitor apps",
6
6
  "main": "dist/plugin.cjs.js",