@capgo/capacitor-updater 9.0.1 → 9.0.2

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 (26) hide show
  1. package/README.md +106 -81
  2. package/android/build.gradle +1 -3
  3. package/android/src/main/java/ee/forgr/capacitor_updater/CapacitorUpdaterPlugin.java +513 -21
  4. package/android/src/main/java/ee/forgr/capacitor_updater/CapgoUpdater.java +675 -34
  5. package/android/src/main/java/ee/forgr/capacitor_updater/DownloadService.java +82 -10
  6. package/android/src/main/java/ee/forgr/capacitor_updater/DownloadWorkerManager.java +23 -0
  7. package/android/src/main/java/ee/forgr/capacitor_updater/HeadlessUpdateWorker.java +188 -4
  8. package/android/src/main/java/ee/forgr/capacitor_updater/Http3.java +81 -1
  9. package/android/src/main/java/ee/forgr/capacitor_updater/HttpEngineTransport.java +72 -21
  10. package/android/src/main/java/ee/forgr/capacitor_updater/ShakeMenu.java +5 -1
  11. package/dist/docs.json +13 -13
  12. package/dist/esm/definitions.d.ts +57 -23
  13. package/dist/esm/definitions.js.map +1 -1
  14. package/ios/Sources/CapacitorUpdaterPlugin/CapacitorUpdaterPlugin.swift +1278 -107
  15. package/ios/Sources/CapacitorUpdaterPlugin/CapgoSemanticVersion.swift +38 -0
  16. package/ios/Sources/CapacitorUpdaterPlugin/CapgoUpdater.swift +583 -56
  17. package/ios/Sources/CapacitorUpdaterPlugin/CryptoCipher.swift +8 -1
  18. package/ios/Sources/CapacitorUpdaterPlugin/ShakeMenu.swift +6 -1
  19. package/ios/Tests/CapacitorUpdaterPluginTests/CapacitorUpdaterPluginTests.swift +2705 -77
  20. package/ios/Tests/CapacitorUpdaterPluginTests/ChecksumRequiredTests.swift +9 -4
  21. package/ios/Tests/CapacitorUpdaterPluginTests/CliCryptoFixtureTests.swift +67 -2
  22. package/ios/Tests/CapacitorUpdaterPluginTests/HttpsOnlyBuiltinMinimumTests.swift +130 -5
  23. package/ios/Tests/CapacitorUpdaterPluginTests/NetworkTransportTests.swift +22 -8
  24. package/ios/Tests/CapacitorUpdaterPluginTests/SessionKeyRequiredTests.swift +4 -0
  25. package/ios/Tests/CapacitorUpdaterPluginTests/UpdateLifecycleTests.swift +19 -3
  26. package/package.json +2 -2
@@ -136,17 +136,17 @@ final class HttpEngineTransport implements Http3.Transport {
136
136
  } catch (NumberFormatException ignored) {}
137
137
  }
138
138
  String message = info.getHttpStatusText();
139
- Request finalRequest = request;
139
+ Request.Builder finalRequest = request.newBuilder().tag(Http3.ServedByEngine.class, Http3.ServedByEngine.TAG);
140
140
  String finalUrl = info.getUrl();
141
141
  if (finalUrl != null && !finalUrl.equals(request.url().toString())) {
142
142
  okhttp3.HttpUrl parsed = okhttp3.HttpUrl.parse(finalUrl);
143
143
  if (parsed != null) {
144
- finalRequest = request.newBuilder().url(parsed).build();
144
+ finalRequest.url(parsed);
145
145
  }
146
146
  }
147
147
  InputStream body = engineCall.bodyStream(readTimeoutMs);
148
148
  return new Response.Builder()
149
- .request(finalRequest)
149
+ .request(finalRequest.build())
150
150
  .protocol(Http3.protocolFor(negotiated))
151
151
  .code(info.getHttpStatusCode())
152
152
  .message(message != null ? message : "")
@@ -222,7 +222,7 @@ final class HttpEngineTransport implements Http3.Transport {
222
222
 
223
223
  /**
224
224
  * Last time any request on the shared engine got a callback (one engine, one picture of whether it is alive),
225
- * and the last time per host, which tells a request on a warm connection from one still setting up a new one.
225
+ * and the last time per connection (scheme, host, port), which tells a request on a warm connection from one still setting up a new one.
226
226
  */
227
227
  static final class Liveness {
228
228
 
@@ -303,7 +303,17 @@ final class HttpEngineTransport implements Http3.Transport {
303
303
 
304
304
  private volatile UrlRequest request;
305
305
  private volatile String currentUrl;
306
- private volatile String currentHost;
306
+ // Warmth key of the current hop (scheme, host, port); see Http3.connectionKey.
307
+ private volatile String currentConnection;
308
+ // When the current hop started: set on each followed redirect, so a redirect target is judged warm or cold
309
+ // from the redirect, not from the start of the whole header wait. Guarded by the liveness monitor.
310
+ private long hopStartNanos;
311
+ private boolean redirected;
312
+ // Warm/cold verdict for the hop that started at warmHopStart, decided once from activity recorded before that
313
+ // hop: callbacks of the hop itself must never turn a cold hop warm mid-wait. Guarded by the liveness monitor.
314
+ private boolean warmDecided;
315
+ private long warmHopStart;
316
+ private boolean hopWarm;
307
317
  private volatile IOException redirectError;
308
318
 
309
319
  private final Liveness liveness;
@@ -316,7 +326,7 @@ final class HttpEngineTransport implements Http3.Transport {
316
326
  EngineCall(String url, @Nullable Call call, @NonNull Liveness liveness, long stallMs) {
317
327
  this.url = url;
318
328
  this.currentUrl = url;
319
- this.currentHost = Http3.safeHost(url);
329
+ this.currentConnection = Http3.connectionKey(url);
320
330
  this.call = call;
321
331
  this.liveness = liveness;
322
332
  this.stallNanos = TimeUnit.MILLISECONDS.toNanos(stallMs);
@@ -329,7 +339,10 @@ final class HttpEngineTransport implements Http3.Transport {
329
339
 
330
340
  @Override
331
341
  public void onRedirectReceived(@NonNull UrlRequest urlRequest, @NonNull UrlResponseInfo info, @NonNull String newLocationUrl) {
332
- liveness.mark(currentHost);
342
+ // Same monitor as the stall check, so it never sees a host mark without the matching global mark.
343
+ synchronized (liveness) {
344
+ liveness.mark(currentConnection);
345
+ }
333
346
  IOException error = Http3.redirectError(currentUrl, newLocationUrl);
334
347
  if (error != null) {
335
348
  redirectError = error;
@@ -337,7 +350,13 @@ final class HttpEngineTransport implements Http3.Transport {
337
350
  return;
338
351
  }
339
352
  currentUrl = newLocationUrl;
340
- currentHost = Http3.safeHost(newLocationUrl);
353
+ synchronized (liveness) {
354
+ currentConnection = Http3.connectionKey(newLocationUrl);
355
+ hopStartNanos = liveness.clock.nanoTime();
356
+ redirected = true;
357
+ // Decide now, before the target can answer: only activity before the redirect counts.
358
+ decideHopWarmth(hopStartNanos);
359
+ }
341
360
  urlRequest.followRedirect();
342
361
  }
343
362
 
@@ -373,7 +392,7 @@ final class HttpEngineTransport implements Http3.Transport {
373
392
  */
374
393
  private void publish(@NonNull Object event) {
375
394
  synchronized (liveness) {
376
- liveness.mark(currentHost);
395
+ liveness.mark(currentConnection);
377
396
  events.offer(event);
378
397
  }
379
398
  }
@@ -387,7 +406,16 @@ final class HttpEngineTransport implements Http3.Transport {
387
406
  @Nullable
388
407
  private Object next(long timeoutMs, boolean waitingForHeaders) throws IOException {
389
408
  Clock clock = liveness.clock;
390
- long start = clock.nanoTime();
409
+ long start;
410
+ synchronized (liveness) {
411
+ start = clock.nanoTime();
412
+ // Decide the first hop's warmth with its boundary, under the lock: a mark from another request on this
413
+ // host between the two would otherwise replace the earlier activity the verdict needs. A followed
414
+ // redirect was already decided when it arrived.
415
+ if (!redirected) {
416
+ decideHopWarmth(start);
417
+ }
418
+ }
391
419
  long deadline = timeoutMs > 0 ? start + TimeUnit.MILLISECONDS.toNanos(timeoutMs) : Long.MAX_VALUE;
392
420
  try {
393
421
  while (true) {
@@ -401,11 +429,18 @@ final class HttpEngineTransport implements Http3.Transport {
401
429
  if (ready != null) {
402
430
  return ready;
403
431
  }
404
- long remainingMs = timeoutMs > 0 ? TimeUnit.NANOSECONDS.toMillis(deadline - clock.nanoTime()) : POLL_MS;
405
- if (remainingMs <= 0) {
406
- return null;
432
+ long remainingNanos;
433
+ synchronized (liveness) {
434
+ // Decide the deadline in nanoseconds and under the publish lock: a sub-millisecond budget is
435
+ // still a budget, and a callback published right at the deadline is handed over, not dropped.
436
+ remainingNanos = timeoutMs > 0 ? deadline - clock.nanoTime() : TimeUnit.MILLISECONDS.toNanos(POLL_MS);
437
+ if (remainingNanos <= 0) {
438
+ return events.poll();
439
+ }
407
440
  }
408
- Object event = clock.poll(events, Math.min(POLL_MS, remainingMs));
441
+ // Round up so the last partial millisecond is waited for instead of read as zero.
442
+ long waitMs = Math.min(POLL_MS, Math.max(1, (remainingNanos + 999_999L) / 1_000_000L));
443
+ Object event = clock.poll(events, waitMs);
409
444
  if (event != null) {
410
445
  return event;
411
446
  }
@@ -436,9 +471,15 @@ final class HttpEngineTransport implements Http3.Transport {
436
471
  // rides a warm connection. The first request of a process, a lone one after a quiet period, and one to
437
472
  // a host the engine has not reached recently (a redirect target, another CDN) pay a full handshake
438
473
  // that can take longer on a slow network, and keep the normal timeout instead of suspending HTTP/3.
439
- Long hostLast = liveness.lastNanos(currentHost);
440
- boolean warm = hostLast != null && hostLast - (waitStartNanos - stallNanos) >= 0;
441
- boolean armed = waitingForHeaders ? warm : Http3.isSuspended(now);
474
+ // Judge the current hop: after a followed redirect (before or during this wait), the target must have
475
+ // been active within the stall window before the redirect, not merely at some point since. The verdict
476
+ // is fixed once per hop, so later callbacks cannot make a cold host warm. Silence and the deadline still
477
+ // count from the wait start.
478
+ long hopStart = redirected ? hopStartNanos : waitStartNanos;
479
+ if (!warmDecided || warmHopStart != hopStart) {
480
+ decideHopWarmth(hopStart);
481
+ }
482
+ boolean armed = waitingForHeaders ? hopWarm : Http3.isStallConfirmed(now);
442
483
  long silentSince = last - waitStartNanos >= 0 ? last : waitStartNanos;
443
484
  if (!armed || now - silentSince < stallNanos) {
444
485
  return null;
@@ -450,6 +491,14 @@ final class HttpEngineTransport implements Http3.Transport {
450
491
  throw new Http3.EngineStalledException("HttpEngine made no progress for " + silentMs + " ms on " + Http3.safeHost(url));
451
492
  }
452
493
 
494
+ /** Caller holds the liveness monitor. Warm only for activity on currentConnection within the stall window before hopStart. */
495
+ private void decideHopWarmth(long hopStart) {
496
+ Long hostLast = liveness.lastNanos(currentConnection);
497
+ hopWarm = hostLast != null && hostLast - (hopStart - stallNanos) >= 0 && hopStart - hostLast >= 0;
498
+ warmHopStart = hopStart;
499
+ warmDecided = true;
500
+ }
501
+
453
502
  UrlResponseInfo awaitResponse(long timeoutMs) throws IOException {
454
503
  Object event = next(timeoutMs, true);
455
504
  if (event instanceof Started) {
@@ -459,7 +508,8 @@ final class HttpEngineTransport implements Http3.Transport {
459
508
  throw ((Failed) event).error;
460
509
  }
461
510
  cancel();
462
- throw new SocketTimeoutException("HttpEngine timeout waiting for response headers from " + Http3.safeHost(url));
511
+ // No headers yet: the interceptor can still retry this request on OkHttp (see EngineHeaderTimeoutException).
512
+ throw new Http3.EngineHeaderTimeoutException("HttpEngine timeout waiting for response headers from " + Http3.safeHost(url));
463
513
  }
464
514
 
465
515
  InputStream bodyStream(int readTimeoutMs) {
@@ -520,11 +570,12 @@ final class HttpEngineTransport implements Http3.Transport {
520
570
  done = true;
521
571
  buffer.limit(0);
522
572
  cancel();
523
- // The body stalled on the engine. Skip it for the cooldown so the caller's retry, which
573
+ // The body timed out on the engine. Skip it for the cooldown so the caller's retry, which
524
574
  // starts a new request and keeps its own partial-file and checksum checks, runs on OkHttp
525
575
  // instead of waiting on the same engine again. Bytes already delivered stay from this
526
- // response; nothing switches streams mid-body.
527
- Http3.suspendAfterStall(liveness.clock.nanoTime());
576
+ // response; nothing switches streams mid-body. One slow body is not a confirmed engine
577
+ // stall, so other bodies still streaming on the engine keep their normal read timeout.
578
+ Http3.suspendAfterBodyTimeout(liveness.clock.nanoTime());
528
579
  throw new SocketTimeoutException("HttpEngine read timeout");
529
580
  }
530
581
  }
@@ -416,7 +416,11 @@ public class ShakeMenu implements ShakeDetector.Listener, ThreeFingerPinchDetect
416
416
 
417
417
  if (next != null && !next.isBuiltin()) {
418
418
  logger.info("Setting bundle to: " + next.toString());
419
- updater.set(next);
419
+ // A pending bundle below the native version floor is rejected: fall back to builtin.
420
+ if (!Boolean.TRUE.equals(updater.set(next))) {
421
+ logger.warn("Cannot activate " + next.toString() + ", resetting to builtin");
422
+ updater.reset();
423
+ }
420
424
  String path = updater.getCurrentBundlePath();
421
425
  logger.info("Setting server path: " + path);
422
426
  if (updater.isUsingBuiltin()) {
package/dist/docs.json CHANGED
@@ -703,7 +703,7 @@
703
703
  "text": "Whether a native update check was queued."
704
704
  }
705
705
  ],
706
- "docs": "Trigger the native auto-update check/download pipeline immediately.\n\nThis starts the same background update flow used when the app moves to the\nforeground with auto-update enabled. It is useful for native integrations\nsuch as a silent push notification asking the app to check for a Capgo\nbundle without reimplementing the update protocol in JavaScript.\n\nThe promise resolves after the native background work has been queued, not\nafter the update has been downloaded or installed. Listen to `updaterEvent`\nand its `updateAvailable`, `downloadComplete`, `downloadFailed`, and\n`noNeedUpdate` types for the final result.\n\nNative support is available on iOS and Android. On Web, this method returns\na result with `status: 'unavailable'`. Native platforms also return\n`unavailable` when the native auto-update system is disabled.",
706
+ "docs": "Trigger the native auto-update check/download pipeline immediately.\n\nThis starts the same background update flow used when the app moves to the\nforeground with auto-update enabled. It is useful for native integrations\nsuch as a silent push notification asking the app to check for a Capgo\nbundle without reimplementing the update protocol in JavaScript.\n\nThe promise resolves after the native background work has been queued, not\nafter the update has been downloaded or installed. Listen to `updaterEvent`:\nits `updateCheckResult` type reports classified responses (`kind` with the\nbackend error or message), including blocked and up-to-date results, which\nboth emit `noNeedUpdate`. A successful offer of a new bundle is not always\nclassified: it can go straight to `download` and `updateAvailable` events\nwithout an `updateCheckResult`, so do not wait for one after every check.\nUse `updateAvailable`, `downloadComplete`, `downloadFailed`, and\n`noNeedUpdate` for download and activation progress.\n\nNative support is available on iOS and Android. On Web, this method returns\na result with `status: 'unavailable'`. Native platforms also return\n`unavailable` when the native auto-update system is disabled.",
707
707
  "complexTypes": [
708
708
  "TriggerUpdateCheckResult"
709
709
  ],
@@ -1102,7 +1102,7 @@
1102
1102
  "text": "8.53.0"
1103
1103
  }
1104
1104
  ],
1105
- "docs": "Listen for every updater event with a single listener.\n\nEach call receives `{ type, data }`: `type` is the event name and `data` is its payload\n(see {@link UpdaterEvent} for every type and its payload).\n\nSince 9.0.0 this is the only listener the plugin emits. The per-event listeners\n(`addListener('download', ...)`, `addListener('appReady', ...)`, ...) and the `majorAvailable`\nalias were removed: switch on `event.type` instead.\n\n`set` and `appReady` are retained natively until a listener attaches, so they are still\ndelivered after a reload even when the listener is registered later in app startup.\n\n```typescript\nCapacitorUpdater.addListener('updaterEvent', (event) => {\n switch (event.type) {\n case 'download':\n console.log('progress', event.data.percent);\n break;\n case 'downloadFailed':\n console.warn('download failed', event.data.version);\n break;\n case 'channelPrivate':\n console.warn(`Cannot access channel \"${event.data.channel}\": ${event.data.message}`);\n break;\n }\n});\n```",
1105
+ "docs": "Listen for every updater event with a single listener.\n\nEach call receives `{ type, data }`: `type` is the event name and `data` is its payload\n(see {@link UpdaterEvent} for every type and its payload).\n\nSince 9.0.0 this is the only listener the plugin emits. The per-event listeners\n(`addListener('download', ...)`, `addListener('appReady', ...)`, ...) and the `majorAvailable`\nalias were removed: switch on `event.type` instead.\n\nSome events are retained natively until a listener attaches: `set`, `appReady`, `noNeedUpdate`, and\n`updateAvailable` from the automatic update when `autoUpdate` is `onlyDownload`. Do not rely on retention for an\n`updateAvailable` from a manual `download()` (iOS does not retain it): register the listener before calling it.\nThe first `updaterEvent` listener receives every\nretained event in emission order, so these are still delivered after a reload or a fast update check\neven when the listener is registered later in app startup.\n\n```typescript\nCapacitorUpdater.addListener('updaterEvent', (event) => {\n switch (event.type) {\n case 'download':\n console.log('progress', event.data.percent);\n break;\n case 'downloadFailed':\n console.warn('download failed', event.data.version);\n break;\n case 'channelPrivate':\n console.warn(`Cannot access channel \"${event.data.channel}\": ${event.data.message}`);\n break;\n }\n});\n```",
1106
1106
  "complexTypes": [
1107
1107
  "PluginListenerHandle",
1108
1108
  "UpdaterEvent"
@@ -1487,7 +1487,7 @@
1487
1487
  "text": "8.0.0"
1488
1488
  }
1489
1489
  ],
1490
- "docs": "Start a flexible in-app update on Android.\n\nThis triggers Google Play's flexible update flow, which:\n1. Downloads the update in the background\n2. Allows the user to continue using the app\n3. Notifies when download is complete\n4. Requires calling {@link completeFlexibleUpdate} to install\n\nMonitor the download progress with the `onFlexibleUpdateStateChange` type of `updaterEvent`.\n\n**Requirements:**\n- Android only (throws error on iOS)\n- An update must be available (check with {@link getAppUpdateInfo} first)\n- The update must allow flexible updates (`flexibleUpdateAllowed: true`)\n\n**Typical flow:**\n1. Call `startFlexibleUpdate()` to begin download\n2. Listen to `updaterEvent` and handle `onFlexibleUpdateStateChange` for progress\n3. When status is `DOWNLOADED`, prompt user to restart\n4. Call `completeFlexibleUpdate()` to install and restart",
1490
+ "docs": "Start a flexible in-app update on Android.\n\nThis triggers Google Play's flexible update flow, which:\n1. Downloads the update in the background\n2. Allows the user to continue using the app\n3. Notifies when download is complete\n4. Requires calling {@link completeFlexibleUpdate} to install\n\nMonitor the download progress with the `onFlexibleUpdateStateChange` type of `updaterEvent`.\n\n**Requirements:**\n- Android only (throws error on iOS)\n- An update must be available (check with {@link getAppUpdateInfo} first)\n- The update must allow flexible updates (`flexibleUpdateAllowed: true`)\n\n**Typical flow:**\n1. Register `addListener('updaterEvent', ...)` and await it, handling `onFlexibleUpdateStateChange`\n for progress, so no state change is missed\n2. Call `startFlexibleUpdate()` to begin download\n3. When status is `DOWNLOADED`, prompt user to restart\n4. Call `completeFlexibleUpdate()` to install and restart",
1491
1491
  "complexTypes": [
1492
1492
  "AppUpdateResult"
1493
1493
  ],
@@ -1635,7 +1635,7 @@
1635
1635
  {
1636
1636
  "name": "DownloadOptions",
1637
1637
  "slug": "downloadoptions",
1638
- "docs": "This URL and versions are used to download the bundle from the server, If you use backend all information will be given by the method getLatest.\nIf you don't use backend, you need to provide the URL and version of the bundle. Checksum and sessionKey are required if you encrypted the bundle with the CLI command encrypt, you should receive them as result of the command.",
1638
+ "docs": "This URL and versions are used to download the bundle from the server, If you use backend all information will be given by the method getLatest.\nIf you don't use backend, you need to provide the URL and version of the bundle. Encrypted ZIP downloads require checksum and sessionKey. Encrypted manifest downloads require\nsessionKey and a signed file_hash for each manifest entry. For updater 9, take them from the Capgo CLI upload flow, which produces the v9 checksum format when it\ndetects updater 9 in the project; see \"Migration to v9\" in the README. A standalone encrypt command may not produce it.",
1639
1639
  "tags": [],
1640
1640
  "methods": [],
1641
1641
  "properties": [
@@ -1681,7 +1681,7 @@
1681
1681
  "name": "default"
1682
1682
  }
1683
1683
  ],
1684
- "docs": "The checksum for the update, it should be in sha256 and encrypted with private key if the bundle is encrypted.\n\nSince 9.0.0, the checksum of an encrypted bundle must sign both the SHA-256 of the bundle zip and the\nSHA-256 of the encrypted bytes (the format `npx @capgo/cli@latest bundle encrypt` produces for updater 9).\nThe plugin checks the downloaded bytes against it before decrypting them.",
1684
+ "docs": "The checksum for the update, it should be in sha256 and encrypted with private key if the bundle is encrypted.\n\nSince 9.0.0, the checksum of an encrypted bundle must sign both the SHA-256 of the bundle zip and the\nSHA-256 of the encrypted bytes. The plugin checks the downloaded bytes against it before decrypting them.\nThe Capgo CLI upload flow produces this format when it detects updater 9 in the project; for self-hosted\nupdates, follow \"Migration to v9\" in the README instead of relying on a standalone encrypt command.",
1685
1685
  "complexTypes": [],
1686
1686
  "type": "string | undefined"
1687
1687
  },
@@ -3351,7 +3351,7 @@
3351
3351
  "name": "since"
3352
3352
  }
3353
3353
  ],
3354
- "docs": "Version of the breaking update that the backend blocked for this native app.",
3354
+ "docs": "Version of the breaking update that the backend blocked for this native app.\n\nThis is the target version when the backend sends one. When the backend omits it,\nthe native code can fall back to the current bundle version, so do not show this\nvalue as the required upgrade without checking that it differs from the running bundle.",
3355
3355
  "complexTypes": [],
3356
3356
  "type": "string"
3357
3357
  }
@@ -4137,7 +4137,7 @@
4137
4137
  {
4138
4138
  "name": "UpdaterEvent",
4139
4139
  "slug": "updaterevent",
4140
- "docs": "Payload of the single `updaterEvent` listener: every plugin event as `{ type, data }`.\nSwitch on `type` to get a typed `data`.\n\n- `download`: download progress of a bundle, from start to finish (`percent` between 0 and 100).\n- `noNeedUpdate`: the update check found nothing to install.\n- `updateCheckResult`: classified result of an update check, before the updater decides whether to download.\n In the background update pipeline, `up_to_date` and `blocked` are emitted before `noNeedUpdate` and no\n `downloadFailed` follows. A `failed` result is emitted before `downloadFailed`, and native code sends an\n `update_check_error` stat instead of `download_fail` because no bundle download was attempted.\n Periodic checks (`periodCheckDelay`) may emit only `updateCheckResult`, without those follow-up events or stats.\n- `updateAvailable`: a new bundle is downloaded and ready.\n- `downloadComplete`: a bundle download finished.\n- `downloadFailed`: a bundle download or update check failed.\n- `breakingAvailable`: the backend blocked an update as incompatible with the current native app.\n- `updateFailed`: a bundle failed to install at the next app start and was rolled back.\n- `set`: a bundle was applied. Retained natively until a listener consumes it.\n- `setNext`: a bundle was queued as the next bundle to install.\n- `appReloaded`: the app reloaded.\n- `appReady`: the app is ready to use. Retained natively until a listener consumes it.\n- `channelPrivate`: `setChannel()` targeted a channel that does not allow device self-assignment.\n- `onFlexibleUpdateStateChange`: Android flexible in-app update progress and install status.\n When `installStatus` is `DOWNLOADED`, prompt the user and call\n {@link CapacitorUpdaterPlugin.completeFlexibleUpdate}.",
4140
+ "docs": "Payload of the single `updaterEvent` listener: every plugin event as `{ type, data }`.\nSwitch on `type` to get a typed `data`.\n\n- `download`: download progress of a bundle, from start to finish (`percent` between 0 and 100).\n- `noNeedUpdate`: the update pipeline run completed. It does not mean nothing is pending: a bundle can already be\n downloaded and waiting (iOS can queue one to apply on background), so use `getNextBundle()` for what is queued\n and `updateCheckResult.kind` for the backend's classification. `data.bundle` is usually the running\n bundle, but after a download waiting on install conditions (for example `autoUpdate: 'always'` with delay\n conditions) it is that downloaded bundle, not the active one; use `current()` for the running bundle.\n It is not proof that no update existed (it also follows a blocked check and a background install).\n Retained natively until a listener consumes it.\n- `updateCheckResult`: classified result of an update check, before the updater decides whether to download.\n In the background update pipeline, `up_to_date` and `blocked` are emitted before `noNeedUpdate` and no\n `downloadFailed` follows. A `failed` result is emitted before `downloadFailed`, and native code sends an\n `update_check_error` stat instead of `download_fail` because no bundle download was attempted.\n Periodic checks (`periodCheckDelay`) may emit only `updateCheckResult`, without those follow-up events or stats.\n- `updateAvailable`: a new bundle is downloaded and ready. When `autoUpdate` is `onlyDownload`, the one from the\n automatic update is retained natively until a listener consumes it, because the app must apply that bundle\n itself. Do not rely on retention for one from a manual `download()` (iOS does not retain it).\n- `downloadComplete`: a bundle download finished.\n- `downloadFailed`: a bundle download or update check failed.\n- `breakingAvailable`: the backend blocked an update as incompatible with the current native app.\n- `updateFailed`: a bundle failed its readiness check (no `notifyAppReady()` in time) and was rolled back. This happens\n at the next app start or after an in-session reload (for example `set()`, `next()` applied on background, or an\n instant apply update).\n- `set`: a bundle was applied. Retained natively until a listener consumes it.\n- `setNext`: a bundle was queued as the next bundle to install.\n- `appReloaded`: the app reloaded.\n- `appReady`: the app is ready to use. Retained natively until a listener consumes it.\n- `channelPrivate`: `setChannel()` targeted a channel that does not allow device self-assignment.\n- `onFlexibleUpdateStateChange`: Android flexible in-app update progress and install status.\n `installStatus` is numeric: when it equals `FlexibleUpdateInstallStatus.DOWNLOADED` (`11`), prompt the user and call\n {@link CapacitorUpdaterPlugin.completeFlexibleUpdate}.",
4141
4141
  "types": [
4142
4142
  {
4143
4143
  "text": "{ type: 'download'; data: DownloadEvent }",
@@ -4336,7 +4336,7 @@
4336
4336
  "name": "example"
4337
4337
  }
4338
4338
  ],
4339
- "docs": "Configure how the plugin checks for, downloads, and applies live updates.\n\nThe plugin checks for updates when the app moves to the foreground. When\n{@link periodCheckDelay} is greater than 0, it also checks on a repeating timer\nwhile the app stays open.\n\nBoolean values keep their existing behavior:\n- `true`: Same as `\"atBackground\"`.\n- `false`: Same as `\"off\"`.\n\nString values merge the previous Auto Update and Direct Update configuration:\n- `\"off\"`: Disable automatic update checks.\n- `\"atBackground\"`: Check and download automatically on each foreground check, then apply the update the next time the app moves to background.\n- `\"atInstall\"`: Apply immediately only after a fresh install or native app store update; otherwise use `\"atBackground\"` behavior.\n- `\"onLaunch\"`: Apply immediately only when the app is brought to the foreground from a killed state (cold start). After that first check, fall back to `\"atBackground\"` behavior.\n- `\"always\"`: Check on every foreground transition and apply immediately whenever an update is available.\n- `\"onlyDownload\"`: Check and download automatically, emit `updateAvailable`, and never set the next bundle or apply an update automatically.\n\nInstant apply modes (`\"atInstall\"`, `\"onLaunch\"`, `\"always\"`) apply while the user is waiting.\nUpload with `npx @capgo/cli@latest bundle upload --delta` so only changed files download. A full zip upload slows the user experience.\nThese modes require `autoSplashscreen: true` and `@capacitor/splash-screen` installed with `launchAutoHide: false`.\n\nOnly available for Android and iOS.",
4339
+ "docs": "Configure how the plugin checks for, downloads, and applies live updates.\n\nThe plugin checks for updates when the app moves to the foreground. When\n{@link periodCheckDelay} is greater than 0, it also checks on a repeating timer\nwhile the app stays open.\n\nBoolean values keep their existing behavior:\n- `true`: Same as `\"atBackground\"`.\n- `false`: Same as `\"off\"`.\n\nString values merge the previous Auto Update and Direct Update configuration:\n- `\"off\"`: Disable automatic update checks.\n- `\"atBackground\"`: Check and download automatically on each foreground check, then apply the update the next time the app moves to background.\n- `\"atInstall\"`: Apply immediately only after a fresh install or native app store update; otherwise use `\"atBackground\"` behavior.\n- `\"onLaunch\"`: Apply immediately only when the app is brought to the foreground from a killed state (cold start). After that first check, fall back to `\"atBackground\"` behavior.\n- `\"always\"`: Check on every foreground transition and apply immediately whenever an update is available.\n- `\"onlyDownload\"`: Check and download automatically, emit `updateAvailable`, and never set the next bundle or apply an update automatically.\n\nInstant apply modes (`\"atInstall\"`, `\"onLaunch\"`, `\"always\"`) apply while the user is waiting.\nUpload with `npx @capgo/cli@latest bundle upload --delta` so only changed files download. A full zip upload slows the user experience.\nThey apply without `autoSplashscreen`, but `autoSplashscreen: true` (with `@capacitor/splash-screen` installed and\n`launchAutoHide: false`) is recommended so the splash screen covers the wait and hides itself afterwards.\n\nOnly available for Android and iOS.",
4340
4340
  "complexTypes": [],
4341
4341
  "type": "boolean | 'always' | 'off' | 'atBackground' | 'atInstall' | 'onLaunch' | 'onlyDownload' | undefined"
4342
4342
  },
@@ -4448,7 +4448,7 @@
4448
4448
  "name": "since"
4449
4449
  }
4450
4450
  ],
4451
- "docs": "Automatically hide the splashscreen after instant apply updates finish, or when no update is needed.\nRequired when using the instant apply {@link autoUpdate} modes (`\"atInstall\"`, `\"onLaunch\"`, `\"always\"`).\n`@capacitor/splash-screen` must be installed and configured with `launchAutoHide: false`.\nThis removes the need to manually listen for appReady events and call SplashScreen.hide().\n\nOnly available for Android and iOS.",
4451
+ "docs": "Let the plugin handle the splashscreen: keep it up while an instant apply update runs, then hide it when the\nupdate finishes, when no update is needed, or after {@link autoSplashscreenTimeout}. It controls splash handling\nonly, not whether an update applies immediately (that is {@link autoUpdate}); it is recommended with the instant\napply modes (`\"atInstall\"`, `\"onLaunch\"`, `\"always\"`) so users do not see the app reload.\n`@capacitor/splash-screen` must be installed and configured with `launchAutoHide: false`.\nThis removes the need to manually listen for appReady events and call SplashScreen.hide().\n\nOnly available for Android and iOS.",
4452
4452
  "complexTypes": [],
4453
4453
  "type": "boolean | undefined"
4454
4454
  },
@@ -4684,7 +4684,7 @@
4684
4684
  "name": "builtinMinimum",
4685
4685
  "tags": [
4686
4686
  {
4687
- "text": "true (was `false` before 9.0.0)",
4687
+ "text": "true",
4688
4688
  "name": "default"
4689
4689
  },
4690
4690
  {
@@ -4692,7 +4692,7 @@
4692
4692
  "name": "since"
4693
4693
  }
4694
4694
  ],
4695
- "docs": "Refuse to download or install a bundle whose version is lower than the native app version\n(`version` config override, else `CFBundleShortVersionString` / `versionName`). This is the on-device\ncounterpart of the Capgo channel setting \"disable auto update under native\" and protects against a\nreplayed old update response rolling the app back below its store version. Only the numeric\n`major.minor.patch` part is compared (a `1.2.3-beta.1` bundle is accepted on native `1.2.3`), and\nversions that do not parse as semver skip the check. Rejections are reported as the\n`version_below_native` stat. Set it to `false` if you version web bundles independently of the native\napp (for example native `2.0.0` with bundle `1.4.7`).\n\nOnly available for Android and iOS.",
4695
+ "docs": "Refuse to download or install a bundle whose version is lower than the native app version\n(`version` config override, else `CFBundleShortVersionString` / `versionName`). This is the on-device\ncounterpart of the Capgo channel setting \"disable auto update under native\" and protects against a\nreplayed old update response rolling the app back below its store version. This is not strict semver\nvalidation: both versions are read as a numeric core, ignoring whitespace and `+build` metadata, cutting the\nprerelease at the first `-`, and taking the leading digits of the first three dot-separated parts (missing or\nnon-numeric parts count as `0`, extra parts are ignored). So a `1.2.3-beta.1` bundle is accepted on native\n`1.2.3`, `1.2.preview` is read as `1.2.0`, and native `2.0.0.4` compares as `2.0.0`. Only a version that does\nnot start with a digit (after whitespace is removed) skips the check. Rejections are reported as the\n`version_below_native` stat. Set it to `false` if you version web bundles independently of the native\napp (for example native `2.0.0` with bundle `1.4.7`). The default was `false` before 9.0.0.\n\nOnly available for Android and iOS.",
4696
4696
  "complexTypes": [],
4697
4697
  "type": "boolean | undefined"
4698
4698
  },
@@ -4748,7 +4748,7 @@
4748
4748
  "name": "persistCustomId",
4749
4749
  "tags": [
4750
4750
  {
4751
- "text": "true (was `false` before 9.0.0)",
4751
+ "text": "true",
4752
4752
  "name": "default"
4753
4753
  },
4754
4754
  {
@@ -4756,7 +4756,7 @@
4756
4756
  "name": "since"
4757
4757
  }
4758
4758
  ],
4759
- "docs": "Persist the customId set through {@link CapacitorUpdaterPlugin.setCustomId} across app restarts.\nSet it to `false` to keep the customId in memory only, so it resets on every app launch.\nCalling `setCustomId({ customId: '' })` clears the saved value even when persistence is disabled.\n\nOnly available for Android and iOS.",
4759
+ "docs": "Persist the customId set through {@link CapacitorUpdaterPlugin.setCustomId} across app restarts.\nSet it to `false` to keep the customId in memory only, so it resets on every app launch.\nCalling `setCustomId({ customId: '' })` clears the saved value even when persistence is disabled.\nThe default was `false` before 9.0.0.\n\nOnly available for Android and iOS.",
4760
4760
  "complexTypes": [],
4761
4761
  "type": "boolean | undefined"
4762
4762
  },
@@ -65,7 +65,8 @@ declare module '@capacitor/cli' {
65
65
  *
66
66
  * Instant apply modes (`"atInstall"`, `"onLaunch"`, `"always"`) apply while the user is waiting.
67
67
  * Upload with `npx @capgo/cli@latest bundle upload --delta` so only changed files download. A full zip upload slows the user experience.
68
- * These modes require `autoSplashscreen: true` and `@capacitor/splash-screen` installed with `launchAutoHide: false`.
68
+ * They apply without `autoSplashscreen`, but `autoSplashscreen: true` (with `@capacitor/splash-screen` installed and
69
+ * `launchAutoHide: false`) is recommended so the splash screen covers the wait and hides itself afterwards.
69
70
  *
70
71
  * Only available for Android and iOS.
71
72
  *
@@ -146,8 +147,10 @@ declare module '@capacitor/cli' {
146
147
  */
147
148
  version?: string;
148
149
  /**
149
- * Automatically hide the splashscreen after instant apply updates finish, or when no update is needed.
150
- * Required when using the instant apply {@link autoUpdate} modes (`"atInstall"`, `"onLaunch"`, `"always"`).
150
+ * Let the plugin handle the splashscreen: keep it up while an instant apply update runs, then hide it when the
151
+ * update finishes, when no update is needed, or after {@link autoSplashscreenTimeout}. It controls splash handling
152
+ * only, not whether an update applies immediately (that is {@link autoUpdate}); it is recommended with the instant
153
+ * apply modes (`"atInstall"`, `"onLaunch"`, `"always"`) so users do not see the app reload.
151
154
  * `@capacitor/splash-screen` must be installed and configured with `launchAutoHide: false`.
152
155
  * This removes the need to manually listen for appReady events and call SplashScreen.hide().
153
156
  *
@@ -316,15 +319,18 @@ declare module '@capacitor/cli' {
316
319
  * Refuse to download or install a bundle whose version is lower than the native app version
317
320
  * (`version` config override, else `CFBundleShortVersionString` / `versionName`). This is the on-device
318
321
  * counterpart of the Capgo channel setting "disable auto update under native" and protects against a
319
- * replayed old update response rolling the app back below its store version. Only the numeric
320
- * `major.minor.patch` part is compared (a `1.2.3-beta.1` bundle is accepted on native `1.2.3`), and
321
- * versions that do not parse as semver skip the check. Rejections are reported as the
322
+ * replayed old update response rolling the app back below its store version. This is not strict semver
323
+ * validation: both versions are read as a numeric core, ignoring whitespace and `+build` metadata, cutting the
324
+ * prerelease at the first `-`, and taking the leading digits of the first three dot-separated parts (missing or
325
+ * non-numeric parts count as `0`, extra parts are ignored). So a `1.2.3-beta.1` bundle is accepted on native
326
+ * `1.2.3`, `1.2.preview` is read as `1.2.0`, and native `2.0.0.4` compares as `2.0.0`. Only a version that does
327
+ * not start with a digit (after whitespace is removed) skips the check. Rejections are reported as the
322
328
  * `version_below_native` stat. Set it to `false` if you version web bundles independently of the native
323
- * app (for example native `2.0.0` with bundle `1.4.7`).
329
+ * app (for example native `2.0.0` with bundle `1.4.7`). The default was `false` before 9.0.0.
324
330
  *
325
331
  * Only available for Android and iOS.
326
332
  *
327
- * @default true (was `false` before 9.0.0)
333
+ * @default true
328
334
  * @since 8.54.0
329
335
  */
330
336
  builtinMinimum?: boolean;
@@ -358,10 +364,11 @@ declare module '@capacitor/cli' {
358
364
  * Persist the customId set through {@link CapacitorUpdaterPlugin.setCustomId} across app restarts.
359
365
  * Set it to `false` to keep the customId in memory only, so it resets on every app launch.
360
366
  * Calling `setCustomId({ customId: '' })` clears the saved value even when persistence is disabled.
367
+ * The default was `false` before 9.0.0.
361
368
  *
362
369
  * Only available for Android and iOS.
363
370
  *
364
- * @default true (was `false` before 9.0.0)
371
+ * @default true
365
372
  * @since 7.17.3
366
373
  */
367
374
  persistCustomId?: boolean;
@@ -1003,9 +1010,14 @@ export interface CapacitorUpdaterPlugin {
1003
1010
  * bundle without reimplementing the update protocol in JavaScript.
1004
1011
  *
1005
1012
  * The promise resolves after the native background work has been queued, not
1006
- * after the update has been downloaded or installed. Listen to `updaterEvent`
1007
- * and its `updateAvailable`, `downloadComplete`, `downloadFailed`, and
1008
- * `noNeedUpdate` types for the final result.
1013
+ * after the update has been downloaded or installed. Listen to `updaterEvent`:
1014
+ * its `updateCheckResult` type reports classified responses (`kind` with the
1015
+ * backend error or message), including blocked and up-to-date results, which
1016
+ * both emit `noNeedUpdate`. A successful offer of a new bundle is not always
1017
+ * classified: it can go straight to `download` and `updateAvailable` events
1018
+ * without an `updateCheckResult`, so do not wait for one after every check.
1019
+ * Use `updateAvailable`, `downloadComplete`, `downloadFailed`, and
1020
+ * `noNeedUpdate` for download and activation progress.
1009
1021
  *
1010
1022
  * Native support is available on iOS and Android. On Web, this method returns
1011
1023
  * a result with `status: 'unavailable'`. Native platforms also return
@@ -1353,8 +1365,12 @@ export interface CapacitorUpdaterPlugin {
1353
1365
  * (`addListener('download', ...)`, `addListener('appReady', ...)`, ...) and the `majorAvailable`
1354
1366
  * alias were removed: switch on `event.type` instead.
1355
1367
  *
1356
- * `set` and `appReady` are retained natively until a listener attaches, so they are still
1357
- * delivered after a reload even when the listener is registered later in app startup.
1368
+ * Some events are retained natively until a listener attaches: `set`, `appReady`, `noNeedUpdate`, and
1369
+ * `updateAvailable` from the automatic update when `autoUpdate` is `onlyDownload`. Do not rely on retention for an
1370
+ * `updateAvailable` from a manual `download()` (iOS does not retain it): register the listener before calling it.
1371
+ * The first `updaterEvent` listener receives every
1372
+ * retained event in emission order, so these are still delivered after a reload or a fast update check
1373
+ * even when the listener is registered later in app startup.
1358
1374
  *
1359
1375
  * ```typescript
1360
1376
  * CapacitorUpdater.addListener('updaterEvent', (event) => {
@@ -1641,8 +1657,9 @@ export interface CapacitorUpdaterPlugin {
1641
1657
  * - The update must allow flexible updates (`flexibleUpdateAllowed: true`)
1642
1658
  *
1643
1659
  * **Typical flow:**
1644
- * 1. Call `startFlexibleUpdate()` to begin download
1645
- * 2. Listen to `updaterEvent` and handle `onFlexibleUpdateStateChange` for progress
1660
+ * 1. Register `addListener('updaterEvent', ...)` and await it, handling `onFlexibleUpdateStateChange`
1661
+ * for progress, so no state change is missed
1662
+ * 2. Call `startFlexibleUpdate()` to begin download
1646
1663
  * 3. When status is `DOWNLOADED`, prompt user to restart
1647
1664
  * 4. Call `completeFlexibleUpdate()` to install and restart
1648
1665
  *
@@ -1813,6 +1830,10 @@ export interface BreakingAvailableEvent {
1813
1830
  /**
1814
1831
  * Version of the breaking update that the backend blocked for this native app.
1815
1832
  *
1833
+ * This is the target version when the backend sends one. When the backend omits it,
1834
+ * the native code can fall back to the current bundle version, so do not show this
1835
+ * value as the required upgrade without checking that it differs from the running bundle.
1836
+ *
1816
1837
  * @since 7.22.0
1817
1838
  */
1818
1839
  version: string;
@@ -1882,24 +1903,34 @@ export interface ChannelPrivateEvent {
1882
1903
  * Switch on `type` to get a typed `data`.
1883
1904
  *
1884
1905
  * - `download`: download progress of a bundle, from start to finish (`percent` between 0 and 100).
1885
- * - `noNeedUpdate`: the update check found nothing to install.
1906
+ * - `noNeedUpdate`: the update pipeline run completed. It does not mean nothing is pending: a bundle can already be
1907
+ * downloaded and waiting (iOS can queue one to apply on background), so use `getNextBundle()` for what is queued
1908
+ * and `updateCheckResult.kind` for the backend's classification. `data.bundle` is usually the running
1909
+ * bundle, but after a download waiting on install conditions (for example `autoUpdate: 'always'` with delay
1910
+ * conditions) it is that downloaded bundle, not the active one; use `current()` for the running bundle.
1911
+ * It is not proof that no update existed (it also follows a blocked check and a background install).
1912
+ * Retained natively until a listener consumes it.
1886
1913
  * - `updateCheckResult`: classified result of an update check, before the updater decides whether to download.
1887
1914
  * In the background update pipeline, `up_to_date` and `blocked` are emitted before `noNeedUpdate` and no
1888
1915
  * `downloadFailed` follows. A `failed` result is emitted before `downloadFailed`, and native code sends an
1889
1916
  * `update_check_error` stat instead of `download_fail` because no bundle download was attempted.
1890
1917
  * Periodic checks (`periodCheckDelay`) may emit only `updateCheckResult`, without those follow-up events or stats.
1891
- * - `updateAvailable`: a new bundle is downloaded and ready.
1918
+ * - `updateAvailable`: a new bundle is downloaded and ready. When `autoUpdate` is `onlyDownload`, the one from the
1919
+ * automatic update is retained natively until a listener consumes it, because the app must apply that bundle
1920
+ * itself. Do not rely on retention for one from a manual `download()` (iOS does not retain it).
1892
1921
  * - `downloadComplete`: a bundle download finished.
1893
1922
  * - `downloadFailed`: a bundle download or update check failed.
1894
1923
  * - `breakingAvailable`: the backend blocked an update as incompatible with the current native app.
1895
- * - `updateFailed`: a bundle failed to install at the next app start and was rolled back.
1924
+ * - `updateFailed`: a bundle failed its readiness check (no `notifyAppReady()` in time) and was rolled back. This happens
1925
+ * at the next app start or after an in-session reload (for example `set()`, `next()` applied on background, or an
1926
+ * instant apply update).
1896
1927
  * - `set`: a bundle was applied. Retained natively until a listener consumes it.
1897
1928
  * - `setNext`: a bundle was queued as the next bundle to install.
1898
1929
  * - `appReloaded`: the app reloaded.
1899
1930
  * - `appReady`: the app is ready to use. Retained natively until a listener consumes it.
1900
1931
  * - `channelPrivate`: `setChannel()` targeted a channel that does not allow device self-assignment.
1901
1932
  * - `onFlexibleUpdateStateChange`: Android flexible in-app update progress and install status.
1902
- * When `installStatus` is `DOWNLOADED`, prompt the user and call
1933
+ * `installStatus` is numeric: when it equals `FlexibleUpdateInstallStatus.DOWNLOADED` (`11`), prompt the user and call
1903
1934
  * {@link CapacitorUpdaterPlugin.completeFlexibleUpdate}.
1904
1935
  *
1905
1936
  * @since 8.53.0
@@ -2395,7 +2426,9 @@ export interface ChannelUrl {
2395
2426
  }
2396
2427
  /**
2397
2428
  * This URL and versions are used to download the bundle from the server, If you use backend all information will be given by the method getLatest.
2398
- * If you don't use backend, you need to provide the URL and version of the bundle. Checksum and sessionKey are required if you encrypted the bundle with the CLI command encrypt, you should receive them as result of the command.
2429
+ * If you don't use backend, you need to provide the URL and version of the bundle. Encrypted ZIP downloads require checksum and sessionKey. Encrypted manifest downloads require
2430
+ * sessionKey and a signed file_hash for each manifest entry. For updater 9, take them from the Capgo CLI upload flow, which produces the v9 checksum format when it
2431
+ * detects updater 9 in the project; see "Migration to v9" in the README. A standalone encrypt command may not produce it.
2399
2432
  */
2400
2433
  export interface DownloadOptions {
2401
2434
  /**
@@ -2416,8 +2449,9 @@ export interface DownloadOptions {
2416
2449
  * The checksum for the update, it should be in sha256 and encrypted with private key if the bundle is encrypted.
2417
2450
  *
2418
2451
  * Since 9.0.0, the checksum of an encrypted bundle must sign both the SHA-256 of the bundle zip and the
2419
- * SHA-256 of the encrypted bytes (the format `npx @capgo/cli@latest bundle encrypt` produces for updater 9).
2420
- * The plugin checks the downloaded bytes against it before decrypting them.
2452
+ * SHA-256 of the encrypted bytes. The plugin checks the downloaded bytes against it before decrypting them.
2453
+ * The Capgo CLI upload flow produces this format when it detects updater 9 in the project; for self-hosted
2454
+ * updates, follow "Migration to v9" in the README instead of relying on a standalone encrypt command.
2421
2455
  * @since 4.0.0
2422
2456
  * @default undefined
2423
2457
  */