@capgo/capacitor-updater 8.46.3 → 8.47.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.
@@ -254,6 +254,16 @@ declare module '@capacitor/cli' {
254
254
  * @since 7.20.0
255
255
  */
256
256
  allowManualBundleError?: boolean;
257
+ /**
258
+ * Allow JavaScript to start a native preview session and temporarily request updates for another app id.
259
+ * This is intended for trusted container apps that implement Expo Go-style preview flows.
260
+ *
261
+ * Only available for Android and iOS.
262
+ *
263
+ * @default false
264
+ * @since 8.47.0
265
+ */
266
+ allowPreview?: boolean;
257
267
  /**
258
268
  * Persist the customId set through {@link CapacitorUpdaterPlugin.setCustomId} across app restarts.
259
269
  *
@@ -500,6 +510,24 @@ export interface CapacitorUpdaterPlugin {
500
510
  * @throws {Error} When there is no index.html file inside the bundle folder.
501
511
  */
502
512
  set(options: BundleId): Promise<void>;
513
+ /**
514
+ * Start a temporary preview/testing session.
515
+ *
516
+ * This stores the currently active bundle as the pending fallback, enables the
517
+ * native shake menu, and makes the next applied bundle show a native notice
518
+ * explaining that shaking the device can reload or leave the preview.
519
+ * Requires {@link PluginsConfig.CapacitorUpdater.allowPreview} to be `true`.
520
+ * When `appId` is provided, the preview session temporarily uses that app id
521
+ * for update checks until the user leaves the preview. Native updater stats are
522
+ * skipped while the preview session is active.
523
+ *
524
+ * Use this before calling {@link set} for Expo Go-style preview flows.
525
+ *
526
+ * @param options Optional preview session options.
527
+ * @returns {Promise<void>} Resolves when preview session state is prepared.
528
+ * @since 8.47.0
529
+ */
530
+ startPreviewSession(options?: StartPreviewSessionOptions): Promise<void>;
503
531
  /**
504
532
  * Delete a bundle from local storage to free up disk space.
505
533
  *
@@ -749,6 +777,53 @@ export interface CapacitorUpdaterPlugin {
749
777
  * @since 4.0.0
750
778
  */
751
779
  getLatest(options?: GetLatestOptions): Promise<LatestVersion>;
780
+ /**
781
+ * Return the manifest entries that still need to be downloaded for a partial update.
782
+ *
783
+ * Pass the result from {@link getLatest} directly when it includes a `manifest`.
784
+ * The native plugin compares each manifest entry with the files already available
785
+ * in the builtin bundle and the local delta cache. Entries that can be reused are
786
+ * omitted from the returned `missing` list.
787
+ *
788
+ * For encrypted manifests, pass the `sessionKey` returned by {@link getLatest} so
789
+ * encrypted file hashes can be checked against local files.
790
+ *
791
+ * ```typescript
792
+ * const latest = await CapacitorUpdater.getLatest();
793
+ * const missing = await CapacitorUpdater.getMissingBundleFiles(latest);
794
+ * ```
795
+ *
796
+ * @param options A {@link GetMissingBundleFilesOptions} object, or a {@link LatestVersion} response containing `manifest`.
797
+ * @returns {Promise<GetMissingBundleFilesResult>} The manifest entries that require network download.
798
+ * @throws {Error} If the manifest is missing or invalid.
799
+ * @since 8.47.0
800
+ */
801
+ getMissingBundleFiles(options: GetMissingBundleFilesOptions): Promise<GetMissingBundleFilesResult>;
802
+ /**
803
+ * Estimate the download size for manifest entries before downloading them.
804
+ *
805
+ * This method sends the provided manifest entries to the Capgo update endpoint
806
+ * once and reads the stored manifest `file_size` metadata. It does not perform
807
+ * per-file `HEAD` requests from the app.
808
+ *
809
+ * Use this after {@link getMissingBundleFiles} to estimate only the files this
810
+ * device still needs:
811
+ *
812
+ * ```typescript
813
+ * const latest = await CapacitorUpdater.getLatest();
814
+ * const missing = await CapacitorUpdater.getMissingBundleFiles(latest);
815
+ * const size = await CapacitorUpdater.getBundleDownloadSize({
816
+ * version: latest.version,
817
+ * manifest: missing.missing,
818
+ * });
819
+ * ```
820
+ *
821
+ * @param options A {@link GetBundleDownloadSizeOptions} object containing manifest entries.
822
+ * @returns {Promise<GetBundleDownloadSizeResult>} Known byte totals and per-file size results.
823
+ * @throws {Error} If the manifest is missing or invalid.
824
+ * @since 8.47.0
825
+ */
826
+ getBundleDownloadSize(options: GetBundleDownloadSizeOptions): Promise<GetBundleDownloadSizeResult>;
752
827
  /**
753
828
  * Assign this device to a specific update channel at runtime.
754
829
  *
@@ -1615,6 +1690,128 @@ export interface ManifestEntry {
1615
1690
  file_hash: string | null;
1616
1691
  download_url: string | null;
1617
1692
  }
1693
+ export interface GetMissingBundleFilesOptions {
1694
+ /**
1695
+ * Manifest returned by {@link getLatest}. Passing the full {@link LatestVersion}
1696
+ * response is supported because it contains this field.
1697
+ *
1698
+ * @since 8.47.0
1699
+ */
1700
+ manifest?: ManifestEntry[];
1701
+ /**
1702
+ * Target bundle version. Passing the full {@link LatestVersion} response is
1703
+ * supported because it contains this field.
1704
+ *
1705
+ * @since 8.47.0
1706
+ */
1707
+ version?: string;
1708
+ /**
1709
+ * Session key returned by {@link getLatest}, required only when file hashes are encrypted.
1710
+ *
1711
+ * @since 8.47.0
1712
+ */
1713
+ sessionKey?: string;
1714
+ }
1715
+ export interface GetMissingBundleFilesResult {
1716
+ /**
1717
+ * Entries that are not available locally and need to be downloaded.
1718
+ *
1719
+ * @since 8.47.0
1720
+ */
1721
+ missing: ManifestEntry[];
1722
+ /**
1723
+ * Total entries in the provided manifest.
1724
+ *
1725
+ * @since 8.47.0
1726
+ */
1727
+ total: number;
1728
+ /**
1729
+ * Number of entries that need to be downloaded.
1730
+ *
1731
+ * @since 8.47.0
1732
+ */
1733
+ missingCount: number;
1734
+ /**
1735
+ * Number of entries that can be reused from builtin files or local cache.
1736
+ *
1737
+ * @since 8.47.0
1738
+ */
1739
+ reusableCount: number;
1740
+ }
1741
+ export interface GetBundleDownloadSizeOptions {
1742
+ /**
1743
+ * Manifest entries to estimate. Pass `missing.missing` from {@link getMissingBundleFiles}
1744
+ * to estimate only the bytes this device still needs to download.
1745
+ *
1746
+ * @since 8.47.0
1747
+ */
1748
+ manifest?: ManifestEntry[];
1749
+ /**
1750
+ * Target bundle version. Pass `latest.version` when estimating files returned
1751
+ * by {@link getLatest}.
1752
+ *
1753
+ * @since 8.47.0
1754
+ */
1755
+ version?: string;
1756
+ }
1757
+ export interface BundleFileSize {
1758
+ /**
1759
+ * File name from the manifest entry.
1760
+ *
1761
+ * @since 8.47.0
1762
+ */
1763
+ file_name: string | null;
1764
+ /**
1765
+ * File hash from the manifest entry.
1766
+ *
1767
+ * @since 8.47.0
1768
+ */
1769
+ file_hash: string | null;
1770
+ /**
1771
+ * Download URL from the manifest entry.
1772
+ *
1773
+ * @since 8.47.0
1774
+ */
1775
+ download_url: string | null;
1776
+ /**
1777
+ * Estimated bytes to download when the server exposes a size.
1778
+ *
1779
+ * @since 8.47.0
1780
+ */
1781
+ size?: number;
1782
+ /**
1783
+ * Error for this entry when the size could not be determined.
1784
+ *
1785
+ * @since 8.47.0
1786
+ */
1787
+ error?: string;
1788
+ }
1789
+ export interface GetBundleDownloadSizeResult {
1790
+ /**
1791
+ * Sum of all known file sizes in bytes.
1792
+ *
1793
+ * @since 8.47.0
1794
+ */
1795
+ totalSize: number;
1796
+ /**
1797
+ * Number of files with a known size.
1798
+ *
1799
+ * @since 8.47.0
1800
+ */
1801
+ knownFiles: number;
1802
+ /**
1803
+ * Number of files whose size could not be determined.
1804
+ *
1805
+ * @since 8.47.0
1806
+ */
1807
+ unknownFiles: number;
1808
+ /**
1809
+ * Per-file size results.
1810
+ *
1811
+ * @since 8.47.0
1812
+ */
1813
+ files: BundleFileSize[];
1814
+ }
1618
1815
  export interface LatestVersion {
1619
1816
  /**
1620
1817
  * Result of getLatest method
@@ -1671,6 +1868,20 @@ export interface LatestVersion {
1671
1868
  * @since 6.1
1672
1869
  */
1673
1870
  manifest?: ManifestEntry[];
1871
+ /**
1872
+ * Missing manifest entries for this device when {@link GetLatestOptions.includeBundleSize}
1873
+ * is enabled.
1874
+ *
1875
+ * @since 8.47.0
1876
+ */
1877
+ missing?: GetMissingBundleFilesResult;
1878
+ /**
1879
+ * Estimated download size for missing manifest entries when
1880
+ * {@link GetLatestOptions.includeBundleSize} is enabled.
1881
+ *
1882
+ * @since 8.47.0
1883
+ */
1884
+ downloadSize?: GetBundleDownloadSizeResult;
1674
1885
  /**
1675
1886
  * Optional link associated with this bundle version (e.g., release notes URL, changelog, GitHub release).
1676
1887
  * @since 7.35.0
@@ -1718,6 +1929,36 @@ export interface GetLatestOptions {
1718
1929
  * @default undefined
1719
1930
  */
1720
1931
  channel?: string;
1932
+ /**
1933
+ * Temporarily use another app id for this update check while using a trusted preview container.
1934
+ * This only changes the app id sent by this request; it does not persist a preview session.
1935
+ * Requires {@link PluginsConfig.CapacitorUpdater.allowPreview} to be `true`.
1936
+ * @since 8.47.0
1937
+ * @default undefined
1938
+ */
1939
+ appId?: string;
1940
+ /**
1941
+ * When true, the native plugin computes which manifest files are missing on
1942
+ * this device and asks the Capgo update endpoint for their stored sizes before
1943
+ * resolving {@link getLatest}.
1944
+ *
1945
+ * This adds one backend request only when the update response contains a
1946
+ * manifest. It does not perform per-file network checks.
1947
+ *
1948
+ * @since 8.47.0
1949
+ * @default false
1950
+ */
1951
+ includeBundleSize?: boolean;
1952
+ }
1953
+ export interface StartPreviewSessionOptions {
1954
+ /**
1955
+ * App id to use while the preview session is active.
1956
+ * The previous app id is restored when leaving the preview session.
1957
+ * Requires {@link PluginsConfig.CapacitorUpdater.allowPreview} to be `true`.
1958
+ * @since 8.47.0
1959
+ * @default undefined
1960
+ */
1961
+ appId?: string;
1721
1962
  }
1722
1963
  export interface AppReadyResult {
1723
1964
  bundle: BundleInfo;