native-update 4.4.3 → 4.4.5

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
@@ -28,7 +28,7 @@ are available as an HTTP API for CI and coding agents.
28
28
 
29
29
  | | |
30
30
  |---|---|
31
- | **Version** | `4.4.3` |
31
+ | **Version** | `4.4.5` |
32
32
  | **License** | Proprietary — free to use in your apps ([LICENSE](./LICENSE)) |
33
33
  | **Node** | `>=24.16.0` (install + CLI toolchain) |
34
34
  | **Platforms** | iOS 14+ · Android 8.0+ (API 26) · Web |
@@ -217,6 +217,9 @@ if (latest.available && latest.url && latest.version && latest.checksum) {
217
217
  }
218
218
  ```
219
219
 
220
+ To leave the running app alone, stage the bundle instead: `await NativeUpdate.set({ ...bundle, applyOn: 'next-start' })`
221
+ loads it at the next cold start, where `notifyAppReady()` confirms it.
222
+
220
223
  ### Handle a store update
221
224
 
222
225
  ```ts
@@ -521,7 +524,8 @@ indexed at [`/raw/manifest.json`](https://nativeupdate-docs.aoneahsan.com/raw/ma
521
524
  <a id="changelog"></a>
522
525
  ## 🔄 Changelog&nbsp;[#](#changelog)
523
526
 
524
- Latest release: **`4.4.3`**. Android logs `Built <id> from a N-byte patch` when an update arrives as a `NUDELTA/1`
527
+ Latest release: **`4.4.5`**. `set()` takes `applyOn: 'next-start'`, which stages a bundle for the next cold start instead of reloading the running app. Before that, 4.4.4: `--ota-tag` reads `versionName` only from a real statement in `build.gradle`
528
+ (comments and message strings are skipped, `versionName appVersionName` is followed to its value). **`4.4.3`**: Android logs `Built <id> from a N-byte patch` when an update arrives as a `NUDELTA/1`
525
529
  patch, so you can see deltas working on a device. No API change.
526
530
 
527
531
  Full history ships inside the package at `docs/CHANGELOG.md`, so it always matches the version you
@@ -61,7 +61,7 @@ class LiveUpdatePlugin(
61
61
 
62
62
  companion object {
63
63
  /** This plugin's version, sent as X-Sdk-Version. Kept equal to package.json by tests/sdk-version.test.ts. */
64
- const val SDK_VERSION = "4.4.3"
64
+ const val SDK_VERSION = "4.4.5"
65
65
 
66
66
  // SharedPreferences keys. Kept as constants so A2 (boot-time
67
67
  // re-verification) and A3 (crash-loop auto-rollback) stay in sync
@@ -307,6 +307,14 @@ class LiveUpdatePlugin(
307
307
 
308
308
  setActiveBundle(bundleId)
309
309
  persistWebViewBasePath(extractedPath)
310
+ if (call.getString("applyOn") == "next-start") {
311
+ // Staged: Capacitor reads the persisted path at the next cold start. The running WebView is
312
+ // untouched, and this process's notifyAppReady() must not confirm a bundle that has not run.
313
+ stagedForNextStart = bundleId
314
+ call.resolve()
315
+ return
316
+ }
317
+ stagedForNextStart = null
310
318
  // Hop to UI thread; setServerBasePath must run on the WebView's
311
319
  // thread per Capacitor's Bridge contract.
312
320
  activity.runOnUiThread {
@@ -891,6 +899,10 @@ class LiveUpdatePlugin(
891
899
  prefs.edit().putString(bundleId, bundleInfo.toString()).apply()
892
900
  }
893
901
 
902
+ /** A bundle set with applyOn "next-start" in this process; it runs from the next cold start. */
903
+ @Volatile
904
+ private var stagedForNextStart: String? = null
905
+
894
906
  private fun setActiveBundle(bundleId: String) {
895
907
  val prefs = context.getSharedPreferences(PREF_FILE, Context.MODE_PRIVATE)
896
908
  val currentActive = prefs.getString(ACTIVE_BUNDLE_KEY, null)
@@ -1047,6 +1059,11 @@ class LiveUpdatePlugin(
1047
1059
  // signal. Clear the pending-verify state so cold starts after this
1048
1060
  // no longer count against the bundle.
1049
1061
  val prefs = context.getSharedPreferences(PREF_FILE, Context.MODE_PRIVATE)
1062
+ val staged = stagedForNextStart
1063
+ if (staged != null && prefs.getString(PENDING_BUNDLE_KEY, null) == staged) {
1064
+ // The bundle waiting for the next start has not run yet; only its own boot may confirm it.
1065
+ return
1066
+ }
1050
1067
  prefs.edit()
1051
1068
  .putBoolean("current_bundle_verified", true)
1052
1069
  .remove(PENDING_BUNDLE_KEY)
@@ -118,10 +118,24 @@ export function otaBase(appVersion, nativeVersion) {
118
118
  /**
119
119
  * Read `versionName` from an Android module's build.gradle (Groovy or Kotlin DSL).
120
120
  *
121
+ * Only a `versionName` STATEMENT counts: one at the start of a line, outside comments. A quoted value is read as it
122
+ * is; an identifier (`versionName appVersionName`) is followed to its assignment (`appVersionName = "3.30.0"`).
123
+ * Words inside comments and error-message strings are never mistaken for it, and only a plain `x.y.z` is returned.
124
+ *
121
125
  * @param {string} gradleText the file's contents
122
126
  * @returns {string|null}
123
127
  */
124
128
  export function versionNameFromGradle(gradleText) {
125
- const match = /versionName\s*=?\s*["']([^"']+)["']/.exec(gradleText ?? '');
126
- return match ? match[1] : null;
129
+ const code = String(gradleText ?? '')
130
+ .replace(/\/\*[\s\S]*?\*\//g, '')
131
+ .replace(/^\s*\/\/.*$/gm, '');
132
+ const statement = /^\s*versionName\s*=?\s*(?:["']([^"'\n]+)["']|([A-Za-z_]\w*))\s*$/m.exec(code);
133
+ if (!statement) return null;
134
+ let value = statement[1];
135
+ if (value === undefined) {
136
+ const name = statement[2].replace(/[.*+?^${}()|[\]\\]/g, '\\$&');
137
+ const assignment = new RegExp(`^\\s*(?:def\\s+|val\\s+|var\\s+)?${name}\\s*=\\s*["']([^"'\\n]+)["']`, 'm').exec(code);
138
+ value = assignment ? assignment[1] : undefined;
139
+ }
140
+ return value && BASE_PATTERN.test(value.trim()) ? value.trim() : null;
127
141
  }
@@ -60,7 +60,7 @@ import type { AppIdentity } from '../types/app-identity';
60
60
  * This plugin's version, sent as `X-Sdk-Version`. Kept equal to package.json (and to the Kotlin and Swift
61
61
  * constants) by tests/sdk-version.test.ts.
62
62
  */
63
- export declare const SDK_VERSION = "4.4.3";
63
+ export declare const SDK_VERSION = "4.4.5";
64
64
  /** Request inputs for a single backend update check. */
65
65
  export interface UpdateCheckRequest {
66
66
  /** API key issued by the dashboard; sent as `X-API-Key`. Required. */
@@ -59,7 +59,7 @@
59
59
  * This plugin's version, sent as `X-Sdk-Version`. Kept equal to package.json (and to the Kotlin and Swift
60
60
  * constants) by tests/sdk-version.test.ts.
61
61
  */
62
- export const SDK_VERSION = '4.4.3';
62
+ export const SDK_VERSION = '4.4.5';
63
63
  /**
64
64
  * Perform one update check against the Native Update backend.
65
65
  *
@@ -13,9 +13,13 @@ export interface LiveUpdatePlugin {
13
13
  */
14
14
  download(options: DownloadOptions): Promise<BundleInfo>;
15
15
  /**
16
- * Set the active bundle
16
+ * Make a downloaded, verified bundle the app's bundle.
17
+ *
18
+ * `applyOn: 'now'` (the default) switches the WebView to it at once. `applyOn: 'next-start'` stages it: the
19
+ * running app is untouched and the bundle loads at the next cold start, where `notifyAppReady()` confirms it
20
+ * (two unconfirmed starts roll it back). Stage when a reload mid-task would lose the user's work.
17
21
  */
18
- set(bundle: BundleInfo): Promise<void>;
22
+ set(bundle: SetBundleOptions): Promise<void>;
19
23
  /**
20
24
  * Reload the app with current bundle
21
25
  */
@@ -344,6 +348,13 @@ export interface BundleInfo {
344
348
  verified: boolean;
345
349
  metadata?: Record<string, unknown>;
346
350
  }
351
+ /** When a bundle passed to `set()` becomes the running app. */
352
+ export type ApplyOn = 'now' | 'next-start';
353
+ /** A bundle from `download()`/`downloadUpdate()`, plus when to switch to it. */
354
+ export interface SetBundleOptions extends BundleInfo {
355
+ /** Default `'now'`. */
356
+ applyOn?: ApplyOn;
357
+ }
347
358
  export interface DeleteOptions {
348
359
  bundleId?: string;
349
360
  keepVersions?: number;
@@ -1,6 +1,6 @@
1
1
  export { NativeUpdate } from './plugin';
2
2
  export { BackgroundUpdateType, NotificationPriority, UpdateStrategy, UpdateMode, InstallMode, ChecksumAlgorithm, SyncStatus, BundleStatus, InstallStatus, UpdateErrorCode, } from './definitions';
3
- export type { NativeUpdatePlugin, NativeUpdateCombinedPlugin, NativeUpdateListeners, LiveUpdatePlugin, AppUpdatePlugin, AppReviewPlugin, PluginConfig, UpdateConfig, LiveUpdateConfig, AppUpdateConfig, AppReviewConfig, BundleInfo, DownloadOptions, DownloadProgressEvent, SyncOptions, SyncResult, DeleteOptions, LatestVersion, ValidateOptions, ValidationResult, CheckForUpdateResult, DownloadUpdateOptions, AppIdentity, AppUpdateInfo, OpenAppStoreOptions, ReviewResult, CanRequestReviewResult, UpdateStateChangedEvent, AppUpdateStateChangedEvent, AppUpdateProgressEvent, AppUpdateAvailableEvent, AppUpdateReadyEvent, AppUpdateFailedEvent, AppUpdateNotificationClickedEvent, AppUpdateInstallClickedEvent, BackgroundUpdateProgressEvent, BackgroundUpdateNotificationEvent, UpdateError, BackgroundUpdatePlugin, BackgroundUpdateConfig, BackgroundUpdateStatus, BackgroundCheckResult, NotificationPreferences, NotificationPermissionStatus, SecurityConfig, SecurityInfo, CertificatePinning, CertificatePin, PluginInitConfig, PluginListenerHandle, } from './definitions';
3
+ export type { NativeUpdatePlugin, NativeUpdateCombinedPlugin, NativeUpdateListeners, LiveUpdatePlugin, AppUpdatePlugin, AppReviewPlugin, PluginConfig, UpdateConfig, LiveUpdateConfig, AppUpdateConfig, AppReviewConfig, BundleInfo, SetBundleOptions, ApplyOn, DownloadOptions, DownloadProgressEvent, SyncOptions, SyncResult, DeleteOptions, LatestVersion, ValidateOptions, ValidationResult, CheckForUpdateResult, DownloadUpdateOptions, AppIdentity, AppUpdateInfo, OpenAppStoreOptions, ReviewResult, CanRequestReviewResult, UpdateStateChangedEvent, AppUpdateStateChangedEvent, AppUpdateProgressEvent, AppUpdateAvailableEvent, AppUpdateReadyEvent, AppUpdateFailedEvent, AppUpdateNotificationClickedEvent, AppUpdateInstallClickedEvent, BackgroundUpdateProgressEvent, BackgroundUpdateNotificationEvent, UpdateError, BackgroundUpdatePlugin, BackgroundUpdateConfig, BackgroundUpdateStatus, BackgroundCheckResult, NotificationPreferences, NotificationPermissionStatus, SecurityConfig, SecurityInfo, CertificatePinning, CertificatePin, PluginInitConfig, PluginListenerHandle, } from './definitions';
4
4
  export type { RolloutConfig, RolloutTargetSegments, RolloutSchedule, RolloutTimestamp, DeviceInfo, UpdateCheckResponse, } from './types/rollout';
5
5
  export { ErrorCode, NativeUpdateError, ConfigurationError, DownloadError, ValidationError, StorageError, UpdateError as UpdateErrorClass, } from './core/errors';
6
6
  export { ConfigManager } from './core/config';
package/dist/esm/web.d.ts CHANGED
@@ -1,5 +1,5 @@
1
1
  import { WebPlugin } from '@capacitor/core';
2
- import type { NativeUpdateCombinedPlugin, SecurityInfo, SyncOptions, SyncResult, DownloadOptions, BundleInfo, DeleteOptions, LatestVersion, ValidateOptions, ValidationResult, AppUpdateInfo, OpenAppStoreOptions, ReviewResult, CanRequestReviewResult, BackgroundUpdateConfig, BackgroundUpdateStatus, BackgroundCheckResult, NotificationPreferences, NotificationPermissionStatus, CheckForUpdateResult, DownloadUpdateOptions, AppIdentity } from './definitions';
2
+ import type { NativeUpdateCombinedPlugin, SecurityInfo, SyncOptions, SyncResult, DownloadOptions, BundleInfo, SetBundleOptions, DeleteOptions, LatestVersion, ValidateOptions, ValidationResult, AppUpdateInfo, OpenAppStoreOptions, ReviewResult, CanRequestReviewResult, BackgroundUpdateConfig, BackgroundUpdateStatus, BackgroundCheckResult, NotificationPreferences, NotificationPermissionStatus, CheckForUpdateResult, DownloadUpdateOptions, AppIdentity } from './definitions';
3
3
  import type { PluginInitConfig } from './definitions';
4
4
  export declare class NativeUpdateWeb extends WebPlugin implements NativeUpdateCombinedPlugin {
5
5
  private config;
@@ -25,7 +25,7 @@ export declare class NativeUpdateWeb extends WebPlugin implements NativeUpdateCo
25
25
  */
26
26
  sync(_options?: SyncOptions): Promise<SyncResult>;
27
27
  download(options: DownloadOptions): Promise<BundleInfo>;
28
- set(bundle: BundleInfo): Promise<void>;
28
+ set(bundle: SetBundleOptions): Promise<void>;
29
29
  reload(): Promise<void>;
30
30
  reset(): Promise<void>;
31
31
  current(): Promise<BundleInfo>;