@capgo/capacitor-updater 7.51.23 → 7.53.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.
Files changed (29) hide show
  1. package/CapgoCapacitorUpdater.podspec +0 -3
  2. package/Package.swift +3 -11
  3. package/README.md +201 -66
  4. package/android/build.gradle +2 -3
  5. package/android/src/main/java/ee/forgr/capacitor_updater/CapacitorUpdaterPlugin.java +593 -176
  6. package/android/src/main/java/ee/forgr/capacitor_updater/CapgoUpdater.java +775 -162
  7. package/android/src/main/java/ee/forgr/capacitor_updater/CryptoCipher.java +2 -1
  8. package/android/src/main/java/ee/forgr/capacitor_updater/DelayUpdateUtils.java +226 -106
  9. package/android/src/main/java/ee/forgr/capacitor_updater/DownloadService.java +107 -30
  10. package/android/src/main/java/ee/forgr/capacitor_updater/HeadlessUpdateWorker.java +325 -0
  11. package/android/src/main/java/ee/forgr/capacitor_updater/Logger.java +63 -4
  12. package/android/src/main/java/ee/forgr/capacitor_updater/NativeUpdatePrompt.java +303 -0
  13. package/android/src/main/java/ee/forgr/capacitor_updater/Version.java +306 -0
  14. package/dist/docs.json +394 -27
  15. package/dist/esm/definitions.d.ts +220 -7
  16. package/dist/esm/definitions.js.map +1 -1
  17. package/ios/Sources/CapacitorUpdaterPlugin/AES.swift +104 -52
  18. package/ios/Sources/CapacitorUpdaterPlugin/CapacitorUpdaterPlugin.swift +472 -144
  19. package/ios/Sources/CapacitorUpdaterPlugin/CapgoSemanticVersion.swift +162 -0
  20. package/ios/Sources/CapacitorUpdaterPlugin/CapgoUpdater.swift +392 -82
  21. package/ios/Sources/CapacitorUpdaterPlugin/CryptoCipher.swift +2 -1
  22. package/ios/Sources/CapacitorUpdaterPlugin/DelayUpdateUtils.swift +204 -93
  23. package/ios/Sources/CapacitorUpdaterPlugin/Logger.swift +75 -5
  24. package/ios/Sources/CapacitorUpdaterPlugin/NativeUpdatePrompt.swift +183 -0
  25. package/ios/Sources/CapacitorUpdaterPlugin/RedirectPolicyDelegate.swift +53 -0
  26. package/ios/Sources/CapacitorUpdaterPlugin/ShakeMenu.swift +5 -2
  27. package/ios/Sources/CapacitorUpdaterPlugin/ZipArchiveReader.swift +247 -0
  28. package/ios/Sources/CapacitorUpdaterPlugin/ZipCentralDirectory.swift +280 -0
  29. package/package.json +7 -3
@@ -110,6 +110,11 @@ declare module '@capacitor/cli' {
110
110
  * WebView renderer exits, unclean WebView restarts, app launch readiness timing,
111
111
  * and WebView load milestones when available.
112
112
  *
113
+ * Failed background update checks that never start a download (network errors, timeouts,
114
+ * non-2xx responses, unreadable payloads) are reported as `update_check_error` with
115
+ * `metadata.error` and optional `metadata.status_code`, not as `download_fail`.
116
+ * Self-hosted Capgo backends must allow the `update_check_error` stats action.
117
+ *
113
118
  * @default https://plugin.capgo.app/stats
114
119
  * @example https://example.com/api/stats
115
120
  */
@@ -264,6 +269,20 @@ declare module '@capacitor/cli' {
264
269
  * @since 5.4.0
265
270
  */
266
271
  allowModifyUrl?: boolean;
272
+ /**
273
+ * Allow the plugin to follow redirects from HTTPS to plain HTTP for its own network requests
274
+ * (update checks, stats, channel calls, and bundle/manifest downloads).
275
+ *
276
+ * Blocked by default so a redirect can never downgrade updater traffic to an unencrypted connection.
277
+ * Only enable this if your self-hosted update server or CDN must redirect to an HTTP URL.
278
+ * Direct HTTP URLs (for example `localApi` during development) are not affected.
279
+ *
280
+ * Only available for Android and iOS.
281
+ *
282
+ * @default false
283
+ * @since 8.52.0
284
+ */
285
+ allowHttpsToHttpRedirect?: boolean;
267
286
  /**
268
287
  * Allow the plugin to modify the appId dynamically from the JavaScript side.
269
288
  *
@@ -411,6 +430,82 @@ declare module '@capacitor/cli' {
411
430
  * @since 8.43.0
412
431
  */
413
432
  allowShakeChannelSelector?: boolean;
433
+ /**
434
+ * When enabled, show a native dialog prompting the user to install a newer native app from the App Store or Play Store.
435
+ * The prompt appears when a live update is blocked because the device native app is too old, including backend
436
+ * `disable_auto_update_*` responses, `store_update_required`, and `breakingAvailable` / `majorAvailable` flows.
437
+ *
438
+ * Only available for Android and iOS. No-op on web.
439
+ *
440
+ * @default false
441
+ * @since 8.53.0
442
+ */
443
+ nativeUpdatePrompt?: boolean;
444
+ /**
445
+ * Optional title for the native store update dialog shown when {@link PluginsConfig.CapacitorUpdater.nativeUpdatePrompt} is enabled.
446
+ *
447
+ * Only available for Android and iOS.
448
+ *
449
+ * @default "Update available"
450
+ * @since 8.53.0
451
+ */
452
+ nativeUpdatePromptTitle?: string;
453
+ /**
454
+ * Optional message body for the native store update dialog shown when {@link PluginsConfig.CapacitorUpdater.nativeUpdatePrompt} is enabled.
455
+ *
456
+ * Only available for Android and iOS.
457
+ *
458
+ * @default A short message explaining that a newer native app is available in the store.
459
+ * @since 8.53.0
460
+ */
461
+ nativeUpdatePromptMessage?: string;
462
+ /**
463
+ * Optional label for the primary action button that opens the store or starts an in-app update on Android.
464
+ *
465
+ * Only available for Android and iOS.
466
+ *
467
+ * @default "Update"
468
+ * @since 8.53.0
469
+ */
470
+ nativeUpdatePromptUpdateButton?: string;
471
+ /**
472
+ * Optional label for the dismiss action on the native store update dialog.
473
+ *
474
+ * Only available for Android and iOS.
475
+ *
476
+ * @default "Not now"
477
+ * @since 8.53.0
478
+ */
479
+ nativeUpdatePromptLaterButton?: string;
480
+ /**
481
+ * Optional ISO 3166-1 alpha-2 country filter. When set, the prompt is shown only when the device region matches
482
+ * one of the comma-separated country codes (for example `"US"` or `"US,CA"`).
483
+ *
484
+ * Only available for Android and iOS.
485
+ *
486
+ * @default undefined (show in all regions)
487
+ * @since 8.53.0
488
+ */
489
+ nativeUpdatePromptCountry?: string;
490
+ /**
491
+ * When {@link PluginsConfig.CapacitorUpdater.nativeUpdatePrompt} is enabled, also show the dialog when {@link CapacitorUpdaterPlugin.getAppUpdateInfo}
492
+ * reports that a store update is available.
493
+ *
494
+ * Only available for Android and iOS.
495
+ *
496
+ * @default false
497
+ * @since 8.53.0
498
+ */
499
+ nativeUpdatePromptOnStoreCheck?: boolean;
500
+ /**
501
+ * Minimum hours between native update prompts for the same native app version. Also limited to once per app session.
502
+ *
503
+ * Only available for Android and iOS.
504
+ *
505
+ * @default 24
506
+ * @since 8.53.0
507
+ */
508
+ nativeUpdatePromptCooldownHours?: number;
414
509
  };
415
510
  }
416
511
  }
@@ -790,23 +885,25 @@ export interface CapacitorUpdaterPlugin {
790
885
  * Configure conditions that must be met before a pending update is applied.
791
886
  *
792
887
  * After calling {@link next} to queue an update, use this method to control when it gets applied.
793
- * The update will only be installed after ALL specified conditions are satisfied.
888
+ * By default, the update is installed only after **all** specified conditions are satisfied (`conditionMode: 'and'`).
889
+ * Set `conditionMode` to `'or'` to apply the update as soon as **any** condition is met.
794
890
  *
795
891
  * Available condition types:
796
- * - `background`: Wait for the app to be backgrounded. Optionally specify duration in milliseconds.
797
- * - `kill`: Wait for the app to be killed and relaunched (**Note:** Current behavior triggers update immediately on kill, not on next background. This will be fixed in v8.)
892
+ * - `background`: Wait until the app has spent more than the configured time in the background (see value formats below).
893
+ * - `kill`: The condition clears on the next launch and can also clear during Android activity destruction; activity destruction does not prove that the app process ended. Automatic installation waits for the next background, because it runs from appMovedToBackground. Calling {@link reload} can apply the pending bundle immediately.
798
894
  * - `date`: Wait until a specific date/time (ISO 8601 format)
799
895
  * - `nativeVersion`: Wait until the native app is updated to a specific version
800
896
  *
801
897
  * Condition value formats:
802
- * - `background`: Number in milliseconds (e.g., `"300000"` for 5 minutes), or omit for immediate
898
+ * - `background`: Time in milliseconds in background must exceed this value before the condition can clear on return to foreground (e.g., `"300000"` for more than 5 minutes; exactly `300000` ms does not clear). Omit `value` or use `"0"` to clear after one background-and-return cycle; the update installs on the following background.
803
899
  * - `kill`: No value needed
804
900
  * - `date`: ISO 8601 date string (e.g., `"2025-12-31T23:59:59Z"`)
805
901
  * - `nativeVersion`: Version string (e.g., `"2.0.0"`)
806
902
  *
807
903
  * @example
808
- * // Update after user kills app OR after 5 minutes in background
904
+ * // Update after kill condition clears on launch AND background time exceeds 5 minutes
809
905
  * await CapacitorUpdater.setMultiDelay({
906
+ * conditionMode: 'or',
810
907
  * delayConditions: [
811
908
  * { kind: 'kill' },
812
909
  * { kind: 'background', value: '300000' }
@@ -820,7 +917,7 @@ export interface CapacitorUpdaterPlugin {
820
917
  * });
821
918
  *
822
919
  * @example
823
- * // Default behavior: update on next background
920
+ * // One background-and-return clears the condition; update installs on the next background
824
921
  * await CapacitorUpdater.setMultiDelay({
825
922
  * delayConditions: [{ kind: 'background' }]
826
923
  * });
@@ -1184,6 +1281,7 @@ export interface CapacitorUpdaterPlugin {
1184
1281
  * Remove all event listeners registered for this plugin.
1185
1282
  *
1186
1283
  * This unregisters all listeners added via {@link addListener} for all event types:
1284
+ * - `updaterEvent`
1187
1285
  * - `download`
1188
1286
  * - `noNeedUpdate`
1189
1287
  * - `updateCheckResult`
@@ -1202,16 +1300,44 @@ export interface CapacitorUpdaterPlugin {
1202
1300
  * @since 1.0.0
1203
1301
  */
1204
1302
  removeAllListeners(): Promise<void>;
1303
+ /**
1304
+ * Listen for every updater event with a single listener.
1305
+ *
1306
+ * Each call receives `{ type, data }`: `type` is the event name (`download`, `updateAvailable`,
1307
+ * `downloadFailed`, `appReady`, ...) and `data` is the payload the matching legacy listener receives.
1308
+ * When the native layer retains an event until a listener attaches (for example `set` and `appReady`),
1309
+ * `updaterEvent` gets the same retention.
1310
+ *
1311
+ * The per-event listeners below are deprecated and will be removed in v9.
1312
+ *
1313
+ * ```typescript
1314
+ * CapacitorUpdater.addListener('updaterEvent', (event) => {
1315
+ * switch (event.type) {
1316
+ * case 'download':
1317
+ * console.log('progress', event.data.percent);
1318
+ * break;
1319
+ * case 'downloadFailed':
1320
+ * console.warn('download failed', event.data.version);
1321
+ * break;
1322
+ * }
1323
+ * });
1324
+ * ```
1325
+ *
1326
+ * @since 8.53.0
1327
+ */
1328
+ addListener(eventName: 'updaterEvent', listenerFunc: (event: UpdaterEvent) => void): Promise<PluginListenerHandle>;
1205
1329
  /**
1206
1330
  * Listen for bundle download event in the App. Fires once a download has started, during downloading and when finished.
1207
1331
  * This will return you all download percent during the download
1208
1332
  *
1333
+ * @deprecated Use `addListener('updaterEvent', ...)` and switch on `event.type`. This listener keeps working until v9.
1209
1334
  * @since 2.0.11
1210
1335
  */
1211
1336
  addListener(eventName: 'download', listenerFunc: (state: DownloadEvent) => void): Promise<PluginListenerHandle>;
1212
1337
  /**
1213
1338
  * Listen for no need to update event, useful when you want force check every time the app is launched
1214
1339
  *
1340
+ * @deprecated Use `addListener('updaterEvent', ...)` and switch on `event.type`. This listener keeps working until v9.
1215
1341
  * @since 4.0.0
1216
1342
  */
1217
1343
  addListener(eventName: 'noNeedUpdate', listenerFunc: (state: NoNeedEvent) => void): Promise<PluginListenerHandle>;
@@ -1221,20 +1347,24 @@ export interface CapacitorUpdaterPlugin {
1221
1347
  *
1222
1348
  * This event is emitted alongside legacy events. For `up_to_date` and `blocked`, it is emitted before
1223
1349
  * `noNeedUpdate` and does not emit `downloadFailed`. For `failed`, it is emitted before the legacy
1224
- * `downloadFailed` event and keeps the existing failure stats behavior.
1350
+ * `downloadFailed` event; native code also sends an `update_check_error` stat (with error metadata)
1351
+ * instead of `download_fail`, because no bundle download was attempted.
1225
1352
  *
1353
+ * @deprecated Use `addListener('updaterEvent', ...)` and switch on `event.type`. This listener keeps working until v9.
1226
1354
  * @since 8.45.11
1227
1355
  */
1228
1356
  addListener(eventName: 'updateCheckResult', listenerFunc: (state: UpdateCheckResultEvent) => void): Promise<PluginListenerHandle>;
1229
1357
  /**
1230
1358
  * Listen for available update event, useful when you want to force check every time the app is launched
1231
1359
  *
1360
+ * @deprecated Use `addListener('updaterEvent', ...)` and switch on `event.type`. This listener keeps working until v9.
1232
1361
  * @since 4.0.0
1233
1362
  */
1234
1363
  addListener(eventName: 'updateAvailable', listenerFunc: (state: UpdateAvailableEvent) => void): Promise<PluginListenerHandle>;
1235
1364
  /**
1236
1365
  * Listen for downloadComplete events.
1237
1366
  *
1367
+ * @deprecated Use `addListener('updaterEvent', ...)` and switch on `event.type`. This listener keeps working until v9.
1238
1368
  * @since 4.0.0
1239
1369
  */
1240
1370
  addListener(eventName: 'downloadComplete', listenerFunc: (state: DownloadCompleteEvent) => void): Promise<PluginListenerHandle>;
@@ -1242,6 +1372,7 @@ export interface CapacitorUpdaterPlugin {
1242
1372
  * Listen for breaking update events when the backend flags an update as incompatible with the current app.
1243
1373
  * Emits the same payload as the legacy `majorAvailable` listener.
1244
1374
  *
1375
+ * @deprecated Use `addListener('updaterEvent', ...)` and switch on `event.type`. This listener keeps working until v9.
1245
1376
  * @since 7.22.0
1246
1377
  */
1247
1378
  addListener(eventName: 'breakingAvailable', listenerFunc: (state: BreakingAvailableEvent) => void): Promise<PluginListenerHandle>;
@@ -1255,6 +1386,7 @@ export interface CapacitorUpdaterPlugin {
1255
1386
  /**
1256
1387
  * Listen for update fail event in the App, let you know when update has fail to install at next app start
1257
1388
  *
1389
+ * @deprecated Use `addListener('updaterEvent', ...)` and switch on `event.type`. This listener keeps working until v9.
1258
1390
  * @since 2.3.0
1259
1391
  */
1260
1392
  addListener(eventName: 'updateFailed', listenerFunc: (state: UpdateFailedEvent) => void): Promise<PluginListenerHandle>;
@@ -1263,24 +1395,28 @@ export interface CapacitorUpdaterPlugin {
1263
1395
  * This event is retained natively until JavaScript consumes it, so if the app reloads before your
1264
1396
  * listener is attached, the last pending `set` event is delivered once the listener subscribes.
1265
1397
  *
1398
+ * @deprecated Use `addListener('updaterEvent', ...)` and switch on `event.type`. This listener keeps working until v9.
1266
1399
  * @since 8.43.12
1267
1400
  */
1268
1401
  addListener(eventName: 'set', listenerFunc: (state: SetEvent) => void): Promise<PluginListenerHandle>;
1269
1402
  /**
1270
1403
  * Listen for set next event in the App, let you know when a bundle is queued as the next bundle to install.
1271
1404
  *
1405
+ * @deprecated Use `addListener('updaterEvent', ...)` and switch on `event.type`. This listener keeps working until v9.
1272
1406
  * @since 6.14.0
1273
1407
  */
1274
1408
  addListener(eventName: 'setNext', listenerFunc: (state: SetNextEvent) => void): Promise<PluginListenerHandle>;
1275
1409
  /**
1276
1410
  * Listen for download fail event in the App, let you know when a bundle download has failed
1277
1411
  *
1412
+ * @deprecated Use `addListener('updaterEvent', ...)` and switch on `event.type`. This listener keeps working until v9.
1278
1413
  * @since 4.0.0
1279
1414
  */
1280
1415
  addListener(eventName: 'downloadFailed', listenerFunc: (state: DownloadFailedEvent) => void): Promise<PluginListenerHandle>;
1281
1416
  /**
1282
1417
  * Listen for reload event in the App, let you know when reload has happened
1283
1418
  *
1419
+ * @deprecated Use `addListener('updaterEvent', ...)` and switch on `event.type`. This listener keeps working until v9.
1284
1420
  * @since 4.3.0
1285
1421
  */
1286
1422
  addListener(eventName: 'appReloaded', listenerFunc: () => void): Promise<PluginListenerHandle>;
@@ -1289,6 +1425,7 @@ export interface CapacitorUpdaterPlugin {
1289
1425
  * This event is retained natively until JavaScript consumes it, so it can still be delivered after
1290
1426
  * a reload even if the listener is attached later in app startup.
1291
1427
  *
1428
+ * @deprecated Use `addListener('updaterEvent', ...)` and switch on `event.type`. This listener keeps working until v9.
1292
1429
  * @since 5.1.0
1293
1430
  */
1294
1431
  addListener(eventName: 'appReady', listenerFunc: (state: AppReadyEvent) => void): Promise<PluginListenerHandle>;
@@ -1300,6 +1437,7 @@ export interface CapacitorUpdaterPlugin {
1300
1437
  * - Implementing custom error handling for channel restrictions
1301
1438
  * - Logging unauthorized channel access attempts
1302
1439
  *
1440
+ * @deprecated Use `addListener('updaterEvent', ...)` and switch on `event.type`. This listener keeps working until v9.
1303
1441
  * @since 7.34.0
1304
1442
  */
1305
1443
  addListener(eventName: 'channelPrivate', listenerFunc: (state: ChannelPrivateEvent) => void): Promise<PluginListenerHandle>;
@@ -1323,6 +1461,7 @@ export interface CapacitorUpdaterPlugin {
1323
1461
  * When status is `DOWNLOADED`, you should prompt the user and call
1324
1462
  * {@link completeFlexibleUpdate} to finish the installation.
1325
1463
  *
1464
+ * @deprecated Use `addListener('updaterEvent', ...)` and switch on `event.type`. This listener keeps working until v9.
1326
1465
  * @since 8.0.0
1327
1466
  */
1328
1467
  addListener(eventName: 'onFlexibleUpdateStateChange', listenerFunc: (state: FlexibleUpdateState) => void): Promise<PluginListenerHandle>;
@@ -1830,6 +1969,64 @@ export interface ChannelPrivateEvent {
1830
1969
  channel: string;
1831
1970
  message: string;
1832
1971
  }
1972
+ /**
1973
+ * Payload of the single `updaterEvent` listener: every plugin event as `{ type, data }`.
1974
+ * `type` is the legacy event name and `data` is the same payload the legacy listener receives,
1975
+ * so you can switch on `type` and get a typed `data`.
1976
+ *
1977
+ * The deprecated `majorAvailable` alias is not forwarded: use `breakingAvailable`.
1978
+ *
1979
+ * @since 8.53.0
1980
+ */
1981
+ export type UpdaterEvent = {
1982
+ type: 'download';
1983
+ data: DownloadEvent;
1984
+ } | {
1985
+ type: 'noNeedUpdate';
1986
+ data: NoNeedEvent;
1987
+ } | {
1988
+ type: 'updateCheckResult';
1989
+ data: UpdateCheckResultEvent;
1990
+ } | {
1991
+ type: 'updateAvailable';
1992
+ data: UpdateAvailableEvent;
1993
+ } | {
1994
+ type: 'downloadComplete';
1995
+ data: DownloadCompleteEvent;
1996
+ } | {
1997
+ type: 'downloadFailed';
1998
+ data: DownloadFailedEvent;
1999
+ } | {
2000
+ type: 'breakingAvailable';
2001
+ data: BreakingAvailableEvent;
2002
+ } | {
2003
+ type: 'updateFailed';
2004
+ data: UpdateFailedEvent;
2005
+ } | {
2006
+ type: 'set';
2007
+ data: SetEvent;
2008
+ } | {
2009
+ type: 'setNext';
2010
+ data: SetNextEvent;
2011
+ } | {
2012
+ type: 'appReloaded';
2013
+ data: Record<string, never>;
2014
+ } | {
2015
+ type: 'appReady';
2016
+ data: AppReadyEvent;
2017
+ } | {
2018
+ type: 'channelPrivate';
2019
+ data: ChannelPrivateEvent;
2020
+ } | {
2021
+ type: 'onFlexibleUpdateStateChange';
2022
+ data: FlexibleUpdateState;
2023
+ };
2024
+ /**
2025
+ * Every event name that can appear in {@link UpdaterEvent}.
2026
+ *
2027
+ * @since 8.53.0
2028
+ */
2029
+ export type UpdaterEventType = UpdaterEvent['type'];
1833
2030
  export interface ManifestEntry {
1834
2031
  file_name: string | null;
1835
2032
  file_hash: string | null;
@@ -2339,8 +2536,24 @@ export interface CurrentBundleResult {
2339
2536
  bundle: BundleInfo;
2340
2537
  native: string;
2341
2538
  }
2539
+ /**
2540
+ * How multiple delay conditions are combined when more than one is set.
2541
+ *
2542
+ * - `and`: every condition must be satisfied before the pending update is applied (default, backward compatible).
2543
+ * - `or`: the pending update is applied as soon as any condition is satisfied.
2544
+ *
2545
+ * @since 8.50.0
2546
+ */
2547
+ export type DelayConditionMode = 'and' | 'or';
2342
2548
  export interface MultiDelayConditions {
2343
2549
  delayConditions: DelayCondition[];
2550
+ /**
2551
+ * How to combine multiple delay conditions.
2552
+ *
2553
+ * @default 'and'
2554
+ * @since 8.50.0
2555
+ */
2556
+ conditionMode?: DelayConditionMode;
2344
2557
  }
2345
2558
  export interface BuiltinVersion {
2346
2559
  version: string;