native-update-capacitor 0.0.0-stage → 4.3.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 (139) hide show
  1. package/AI-INTEGRATION-GUIDE.md +578 -0
  2. package/LICENSE +25 -0
  3. package/NativeUpdate.podspec +19 -0
  4. package/README.md +574 -2
  5. package/android/build.gradle +125 -0
  6. package/android/consumer-rules.pro +9 -0
  7. package/android/gradle/wrapper/gradle-wrapper.properties +8 -0
  8. package/android/gradle.properties +17 -0
  9. package/android/manifest-additions.xml +28 -0
  10. package/android/proguard-rules.pro +26 -0
  11. package/android/settings.gradle +2 -0
  12. package/android/src/main/AndroidManifest.xml +13 -0
  13. package/android/src/main/java/com/aoneahsan/nativeupdate/AppReviewPlugin.kt +159 -0
  14. package/android/src/main/java/com/aoneahsan/nativeupdate/AppUpdatePlugin.kt +314 -0
  15. package/android/src/main/java/com/aoneahsan/nativeupdate/BackgroundNotificationManager.kt +406 -0
  16. package/android/src/main/java/com/aoneahsan/nativeupdate/BackgroundUpdateManager.kt +48 -0
  17. package/android/src/main/java/com/aoneahsan/nativeupdate/BackgroundUpdatePlugin.kt +343 -0
  18. package/android/src/main/java/com/aoneahsan/nativeupdate/BackgroundUpdateWorker.kt +236 -0
  19. package/android/src/main/java/com/aoneahsan/nativeupdate/JsonOptional.kt +26 -0
  20. package/android/src/main/java/com/aoneahsan/nativeupdate/LiveUpdatePlugin.kt +1249 -0
  21. package/android/src/main/java/com/aoneahsan/nativeupdate/NativeUpdatePlugin.kt +404 -0
  22. package/android/src/main/java/com/aoneahsan/nativeupdate/NotificationActionReceiver.kt +107 -0
  23. package/android/src/main/java/com/aoneahsan/nativeupdate/SecurityManager.kt +240 -0
  24. package/android/variables.gradle +5 -0
  25. package/cli/commands/backend-create.js +623 -0
  26. package/cli/commands/bundle-create.js +145 -0
  27. package/cli/commands/bundle-sign.js +64 -0
  28. package/cli/commands/bundle-verify.js +58 -0
  29. package/cli/commands/init.js +146 -0
  30. package/cli/commands/keys-generate.js +58 -0
  31. package/cli/commands/monitor.js +89 -0
  32. package/cli/commands/remote-shared.js +262 -0
  33. package/cli/commands/remote.js +622 -0
  34. package/cli/commands/server-start.js +96 -0
  35. package/cli/index.js +605 -0
  36. package/cli/package.json +21 -0
  37. package/dist/esm/app-review/app-review-manager.d.ts +24 -0
  38. package/dist/esm/app-review/app-review-manager.js +194 -0
  39. package/dist/esm/app-review/index.d.ts +5 -0
  40. package/dist/esm/app-review/index.js +5 -0
  41. package/dist/esm/app-review/platform-review-handler.d.ts +20 -0
  42. package/dist/esm/app-review/platform-review-handler.js +137 -0
  43. package/dist/esm/app-review/review-conditions-checker.d.ts +22 -0
  44. package/dist/esm/app-review/review-conditions-checker.js +154 -0
  45. package/dist/esm/app-review/review-rate-limiter.d.ts +23 -0
  46. package/dist/esm/app-review/review-rate-limiter.js +163 -0
  47. package/dist/esm/app-review/types.d.ts +41 -0
  48. package/dist/esm/app-review/types.js +1 -0
  49. package/dist/esm/app-update/app-update-checker.d.ts +58 -0
  50. package/dist/esm/app-update/app-update-checker.js +227 -0
  51. package/dist/esm/app-update/app-update-installer.d.ts +20 -0
  52. package/dist/esm/app-update/app-update-installer.js +134 -0
  53. package/dist/esm/app-update/app-update-manager.d.ts +28 -0
  54. package/dist/esm/app-update/app-update-manager.js +198 -0
  55. package/dist/esm/app-update/app-update-notifier.d.ts +14 -0
  56. package/dist/esm/app-update/app-update-notifier.js +99 -0
  57. package/dist/esm/app-update/index.d.ts +6 -0
  58. package/dist/esm/app-update/index.js +6 -0
  59. package/dist/esm/app-update/platform-app-update.d.ts +19 -0
  60. package/dist/esm/app-update/platform-app-update.js +138 -0
  61. package/dist/esm/app-update/types.d.ts +58 -0
  62. package/dist/esm/app-update/types.js +11 -0
  63. package/dist/esm/background-update/background-scheduler.d.ts +63 -0
  64. package/dist/esm/background-update/background-scheduler.js +332 -0
  65. package/dist/esm/background-update/index.d.ts +3 -0
  66. package/dist/esm/background-update/index.js +2 -0
  67. package/dist/esm/background-update/notification-manager.d.ts +29 -0
  68. package/dist/esm/background-update/notification-manager.js +88 -0
  69. package/dist/esm/config/support.d.ts +9 -0
  70. package/dist/esm/config/support.js +9 -0
  71. package/dist/esm/core/analytics.d.ts +83 -0
  72. package/dist/esm/core/analytics.js +151 -0
  73. package/dist/esm/core/cache-manager.d.ts +72 -0
  74. package/dist/esm/core/cache-manager.js +274 -0
  75. package/dist/esm/core/config.d.ts +69 -0
  76. package/dist/esm/core/config.js +107 -0
  77. package/dist/esm/core/errors.d.ts +56 -0
  78. package/dist/esm/core/errors.js +85 -0
  79. package/dist/esm/core/event-emitter.d.ts +30 -0
  80. package/dist/esm/core/event-emitter.js +80 -0
  81. package/dist/esm/core/logger.d.ts +21 -0
  82. package/dist/esm/core/logger.js +108 -0
  83. package/dist/esm/core/performance.d.ts +53 -0
  84. package/dist/esm/core/performance.js +153 -0
  85. package/dist/esm/core/plugin-manager.d.ts +88 -0
  86. package/dist/esm/core/plugin-manager.js +224 -0
  87. package/dist/esm/core/security.d.ts +123 -0
  88. package/dist/esm/core/security.js +361 -0
  89. package/dist/esm/core/update-check.d.ts +121 -0
  90. package/dist/esm/core/update-check.js +127 -0
  91. package/dist/esm/definitions.d.ts +872 -0
  92. package/dist/esm/definitions.js +104 -0
  93. package/dist/esm/index.d.ts +14 -0
  94. package/dist/esm/index.js +18 -0
  95. package/dist/esm/live-update/bundle-manager.d.ts +102 -0
  96. package/dist/esm/live-update/bundle-manager.js +344 -0
  97. package/dist/esm/live-update/certificate-pinning.d.ts +38 -0
  98. package/dist/esm/live-update/certificate-pinning.js +77 -0
  99. package/dist/esm/live-update/delta-processor.d.ts +84 -0
  100. package/dist/esm/live-update/delta-processor.js +257 -0
  101. package/dist/esm/live-update/download-manager.d.ts +106 -0
  102. package/dist/esm/live-update/download-manager.js +412 -0
  103. package/dist/esm/live-update/rollout-checker.d.ts +86 -0
  104. package/dist/esm/live-update/rollout-checker.js +304 -0
  105. package/dist/esm/live-update/update-manager.d.ts +63 -0
  106. package/dist/esm/live-update/update-manager.js +321 -0
  107. package/dist/esm/live-update/version-manager.d.ts +93 -0
  108. package/dist/esm/live-update/version-manager.js +390 -0
  109. package/dist/esm/plugin.d.ts +3 -0
  110. package/dist/esm/plugin.js +848 -0
  111. package/dist/esm/security/crypto.d.ts +88 -0
  112. package/dist/esm/security/crypto.js +228 -0
  113. package/dist/esm/security/validator.d.ts +60 -0
  114. package/dist/esm/security/validator.js +142 -0
  115. package/dist/esm/types/app-identity.d.ts +36 -0
  116. package/dist/esm/types/app-identity.js +1 -0
  117. package/dist/esm/types/rollout.d.ts +91 -0
  118. package/dist/esm/types/rollout.js +25 -0
  119. package/dist/esm/web.d.ts +130 -0
  120. package/dist/esm/web.js +981 -0
  121. package/dist/plugin.cjs +1 -0
  122. package/dist/plugin.esm.js +1 -0
  123. package/dist/plugin.js +2 -0
  124. package/docs/CHANGELOG.md +993 -0
  125. package/docs/KNOWN_LIMITATIONS.md +235 -0
  126. package/docs/MIGRATION.md +391 -0
  127. package/docs/protocol/CLIENT-PROTOCOL.md +178 -0
  128. package/docs/server-requirements.md +211 -0
  129. package/ios/Plugin/AppReview/AppReviewPlugin.swift +158 -0
  130. package/ios/Plugin/AppUpdate/AppUpdatePlugin.swift +249 -0
  131. package/ios/Plugin/BackgroundUpdate/BackgroundNotificationManager.swift +333 -0
  132. package/ios/Plugin/BackgroundUpdate/BackgroundUpdatePlugin.swift +464 -0
  133. package/ios/Plugin/Info.plist +43 -0
  134. package/ios/Plugin/LiveUpdate/LiveUpdatePlugin.swift +1286 -0
  135. package/ios/Plugin/LiveUpdate/WebViewConfiguration.swift +45 -0
  136. package/ios/Plugin/NativeUpdatePlugin.m +53 -0
  137. package/ios/Plugin/NativeUpdatePlugin.swift +315 -0
  138. package/ios/Plugin/Security/SecurityManager.swift +289 -0
  139. package/package.json +135 -4
@@ -0,0 +1,235 @@
1
+ # Known Limitations & Implementation Notes
2
+
3
+ **Last Updated**: 2026-08-05
4
+ **Applies to**: v4.x (the npm version badge on the README is the version source of truth)
5
+ **Status**: Production Ready
6
+
7
+ ---
8
+
9
+ ## Overview
10
+
11
+ This document tracks known limitations and platform-specific implementation notes that need attention before production deployment. These are intentional design decisions or platform limitations that cannot be fully resolved in the web/JavaScript layer.
12
+
13
+ ---
14
+
15
+ ## Web Platform Limitations
16
+
17
+ ### 1. Storage Size Detection
18
+ **Location**: `src/core/performance.ts:166-167`
19
+
20
+ **Issue**: Accurate storage detection is not available via web APIs
21
+
22
+ **Current Implementation**:
23
+ ```typescript
24
+ // Check storage (placeholder - implement per platform)
25
+ const storage = 1000; // MB - placeholder
26
+ ```
27
+
28
+ **Why This Exists**:
29
+ - Web platform does not provide reliable storage size APIs
30
+ - Navigator.storage.estimate() has limited support and accuracy
31
+ - Actual storage depends on platform implementation (iOS/Android)
32
+
33
+ **Resolution**:
34
+ - ✅ Web: Use hardcoded reasonable value (1000MB)
35
+ - ✅ iOS: Implement via native FileManager in Swift
36
+ - ✅ Android: Implement via native StatFs in Kotlin
37
+
38
+ **Status**: **ACCEPTABLE** - This is a web platform limitation, native implementations should override this
39
+
40
+ ---
41
+
42
+ ### 2. Certificate Pinning
43
+ **Location**: `src/core/security.ts:363`
44
+
45
+ **Issue**: Certificate pinning cannot be implemented on web platform
46
+
47
+ **Current Implementation**:
48
+ ```typescript
49
+ /**
50
+ * Validate certificate pinning
51
+ * Note: This is a placeholder for web implementation as certificate pinning
52
+ * is primarily a native platform feature and cannot be fully implemented in web
53
+ */
54
+ async validateCertificatePin(hostname: string, certificate: string): Promise<boolean> {
55
+ // Implementation for native platforms only
56
+ // Web platform always returns true (no pinning available)
57
+ }
58
+ ```
59
+
60
+ **Why This Exists**:
61
+ - Certificate pinning requires low-level network stack access
62
+ - Web browsers do not expose certificate details to JavaScript
63
+ - This is a security feature that MUST be implemented on native platforms
64
+
65
+ **Resolution**:
66
+ - ✅ Web: Document limitation, rely on HTTPS
67
+ - ✅ iOS: Implement via URLSessionDelegate in Swift
68
+ - ✅ Android: Implement via OkHttp CertificatePinner in Kotlin
69
+
70
+ **Status**: **ACCEPTABLE** - This is intentional, native implementations exist
71
+
72
+ ---
73
+
74
+ ## iOS Native Implementation Notes
75
+
76
+ ### 1. File Operations - Bundle Installation
77
+ **Location**: `ios/Plugin/LiveUpdate/LiveUpdatePlugin.swift`
78
+
79
+ **Status**: ✅ **IMPLEMENTED**
80
+
81
+ **Current Implementation**:
82
+ - Uses ZIPFoundation for secure archive extraction
83
+ - Proper error handling with rollback support
84
+ - Verification of extracted bundle contents (checks for index.html)
85
+ - Retains the signed ZIP while its bundle is installed so cold-start integrity re-verification can
86
+ hash and verify the original signed bytes; bundle deletion/retention cleanup removes it later
87
+
88
+ ```swift
89
+ private func extractZipBundle(from zipUrl: URL, to destinationUrl: URL) throws {
90
+ try FileManager.default.unzipItem(at: zipUrl, to: destinationUrl)
91
+ // Verifies extraction and cleans up
92
+ }
93
+ ```
94
+
95
+ ---
96
+
97
+ ### 2. Archive Extraction
98
+ **Location**: `ios/Plugin/LiveUpdate/LiveUpdatePlugin.swift:577`
99
+
100
+ **Status**: ✅ **IMPLEMENTED**
101
+
102
+ **Implementation Details**:
103
+ - ZIPFoundation library used via CocoaPods
104
+ - Secure extraction with path validation
105
+ - Graceful error handling with rollback to safe bundle
106
+ - WebView configuration for extracted bundle paths
107
+
108
+ ---
109
+
110
+ ### 3. Not yet proven on an iPhone (2026-11-19)
111
+
112
+ The Android defects fixed in 4.2.4 were found on a device. Two of the same classes may exist on iOS and are open until
113
+ the iOS phase can test them on hardware:
114
+
115
+ - **Configure after an apply.** iOS `configure()` / `initialize()` still refuse any second call with "locked after
116
+ initialization". An apply reloads the WebView while the plugin instance lives on, so the new bundle's configure may be
117
+ refused, as it was on Android (ISSUE-16).
118
+ - **Cold-start restore.** iOS stores the bundle path under `native_update_webview_path`; whether Capacitor's iOS bridge
119
+ serves it on a cold start before the built-in assets load has not been verified (Android needed ISSUE-17).
120
+ - **Framework SDKs on iOS (2026-11-19).** The native Android, Flutter and React Native SDKs are proven on an Android
121
+ phone. On iOS, the Flutter plugin is a foundation: review works, and asset updates answer `UNAVAILABLE_ON_IOS`.
122
+ React Native doesn't link on iOS yet, and there is no native iOS SDK yet. All of these, written and not compiled, wait
123
+ for the Mac phase.
124
+ - **The Android library needs a GitHub token to install.** GitHub Packages asks for one even to read a public package.
125
+ That lasts until the library moves to Maven Central. The Flutter and React Native packages carry the same Kotlin code
126
+ as source, so they need no token.
127
+ - **4.3.0 iOS headers are written, not compiled.** `LiveUpdatePlugin.swift` sends `X-Client-Sdk: capacitor` and
128
+ `X-Sdk-Version`. Swift cannot be compiled on the Linux machine this release was made on. It is a two-line header
129
+ change, and the Mac phase builds it first (`docs/features/multi-platform-sdks/ios-mac-runbook.md`).
130
+
131
+ ---
132
+
133
+ ## Android Native Implementation Notes
134
+
135
+ ### Status
136
+ - ✅ Android implementation is more complete than iOS
137
+ - ✅ Uses standard Java/Kotlin APIs for file operations
138
+ - ✅ Archive extraction via java.util.zip
139
+
140
+ **No critical placeholders identified in Android code**
141
+
142
+ ---
143
+
144
+ ## API Key Client Restrictions (v3.2.0)
145
+
146
+ Per-key client restrictions let you ship the API key inside your app. Be clear
147
+ on what each layer actually guarantees:
148
+
149
+ - **Web origin restrictions are strong.** The `Origin` header is set by the
150
+ browser and cannot be forged by page JavaScript, so a restricted key genuinely
151
+ cannot be reused from another website.
152
+ - **Android/iOS identity headers are client-attested, NOT cryptographic
153
+ attestation.** The plugin reads the applicationId + signing-cert fingerprints
154
+ (Android) or bundle id (iOS) and sends them as headers — the same trust model
155
+ as Google Maps API-key app restrictions. They stop casual key reuse and quota
156
+ abuse, but a determined attacker can replay the headers with `curl`. For
157
+ hard device attestation you would layer Play Integrity / App Attest yourself
158
+ (out of scope for this plugin).
159
+ - **Legacy builds:** apps built with native-update **< 3.2.0** send no identity
160
+ headers, so an Android/iOS restriction blocks them until the app is rebuilt on
161
+ ≥ 3.2.0. Web restrictions are unaffected by app version.
162
+ - The iOS `team_id` is accepted in the dashboard but the plugin does not
163
+ currently send `X-Ios-Team-Id`; only set it if your own fetch sends it.
164
+
165
+ ---
166
+
167
+ ## Summary of Implementation Status
168
+
169
+ ### Completed Items
170
+
171
+ 1. **iOS File Operations** ✅
172
+ - [x] Secure archive extraction with ZIPFoundation
173
+ - [x] Comprehensive error handling with rollback
174
+ - [x] Bundle verification after extraction
175
+
176
+ 2. **Android File Operations** ✅
177
+ - [x] Archive extraction via java.util.zip
178
+ - [x] Standard Java/Kotlin APIs for file operations
179
+
180
+ 3. **Web Implementation** ✅
181
+ - [x] Full API parity with native platforms
182
+ - [x] Graceful degradation for unsupported features
183
+
184
+ ### Platform-Specific Notes
185
+
186
+ 1. **Certificate Pinning** (OPTIONAL)
187
+ - Web: Not supported (browser limitation, documented)
188
+ - iOS/Android: Implemented in native code
189
+
190
+ 2. **Storage Detection** (LOW PRIORITY)
191
+ - Web: Uses reasonable default value
192
+ - iOS/Android: Native implementations available
193
+
194
+ ---
195
+
196
+ ## Production Readiness Status
197
+
198
+ ### Current State
199
+ - ✅ iOS implementation complete with ZIPFoundation
200
+ - ✅ Android implementation complete
201
+ - ✅ Web implementation complete with documented limitations
202
+ - ✅ All core features production-ready
203
+
204
+ ---
205
+
206
+ ## Testing Recommendations
207
+
208
+ ### Before Marking as Production-Ready
209
+
210
+ 1. **iOS Testing**
211
+ - Test bundle download and extraction on real device
212
+ - Test with large bundles (50MB+)
213
+ - Test with corrupted/invalid archives
214
+ - Verify rollback works when extraction fails
215
+
216
+ 2. **Android Testing**
217
+ - Verify archive extraction works correctly
218
+ - Test storage detection accuracy
219
+ - Test certificate pinning if enabled
220
+
221
+ 3. **Web Testing**
222
+ - Document limitations clearly
223
+ - Ensure graceful degradation
224
+ - Test error handling
225
+
226
+ ---
227
+
228
+ ## Notes
229
+
230
+ - Web platform limitations are **inherent browser restrictions** and are documented
231
+ - Native implementations (iOS/Android) are **complete and production-ready**
232
+ - Certificate pinning is optional and depends on security requirements
233
+ - Storage detection has reasonable defaults for all platforms
234
+
235
+ **The native-update SDK is production-ready.** Users should review web platform limitations if targeting web-only deployments.
@@ -0,0 +1,391 @@
1
+ # Migration Guide
2
+
3
+ ## Upgrading v3 → v4.0.0
4
+
5
+ v4 deliberately tightens runtime and security contracts. Upgrade the native shell and configuration
6
+ together; do not ship a v4 JavaScript bundle into a shell still built with v3 native code.
7
+
8
+ ### Required actions
9
+
10
+ 1. Upgrade to Capacitor 8, Node.js 24.16+, Java 21, Android min SDK 24, and compile/target SDK 36.
11
+ 2. Configure an RSA signing key. `requireSignature` defaults to `true`, and a server/API-key setup
12
+ without `publicKey` is rejected. The supported algorithm is `RSA-SHA256` (PKCS#1 v1.5).
13
+ 3. Replace runtime reconfiguration with `await NativeUpdate.reset()` followed by one fresh
14
+ `initialize()` or `configure()` call. `setUpdateUrl()` is a no-op and configuration is locked after
15
+ initialization; `setChannel()` remains the intentional channel-switch operation.
16
+ 4. If you intentionally run unsigned local fixtures, set both `requireSignature: false` and
17
+ `allowUnsignedDevelopmentUpdates: true`. Native release builds ignore this escape hatch. HTTPS
18
+ remains mandatory in every build.
19
+ 5. Custom backends should add `signatureAlgorithm: "RSA-SHA256"` and may return a `NUDELTA/1` delta
20
+ object as documented in `server-requirements.md`. Clients safely fall back to the full bundle.
21
+
22
+ ### API normalization
23
+
24
+ - `isInitialized()` now consistently resolves to `boolean`.
25
+ - `list()` consistently resolves to `BundleInfo[]`; notification permission and download-state
26
+ helpers likewise return their documented scalar values.
27
+ - `checkForUpdate()`, `downloadUpdate()`, and `applyUpdate()` are real cross-platform convenience
28
+ methods. Prefer `downloadUpdate()` with no arguments so it fetches the complete signed manifest,
29
+ including compatible delta metadata.
30
+
31
+ ---
32
+
33
+ ## Upgrading v2 → v3.0.0
34
+
35
+ v3 narrows the plugin to a single, well-supported backend contract: the
36
+ hosted Native Update SaaS at `https://nativeupdate.aoneahsan.com`
37
+ (reference implementation: Laravel 11 + Nova 5 in `backend/`). The
38
+ direct-Firestore branch — `backendType: 'firestore'` plus the
39
+ `firestore: { … }` config — is removed, along with the
40
+ `src/firestore/` schema/client/manifest-reader/rules/indexes and the
41
+ `example-apps/firebase-backend/` example.
42
+
43
+ ### Why
44
+
45
+ The Firestore branch existed so apps could run without any server. In
46
+ practice it pushed a lot of operational work (security rules, indexes,
47
+ billing, Drive token storage) onto every consumer. The SaaS handles all
48
+ of it server-side, so the SDK only needs to know how to call one
49
+ backend.
50
+
51
+ ### Required action
52
+
53
+ #### 1. Drop `backendType` and `firestore` from your config
54
+
55
+ ```diff
56
+ await NativeUpdate.initialize({
57
+ - backendType: 'firestore',
58
+ - firestore: { projectId: '…', appId: 'com.your.app', channel: 'production' },
59
+ + serverUrl: 'https://nativeupdatebe.aoneahsan.com/api',
60
+ + apiKey: import.meta.env.VITE_NATIVE_UPDATE_API_KEY,
61
+ + publicKey: import.meta.env.VITE_NATIVE_UPDATE_PUBLIC_KEY,
62
+ appId: 'com.your.app',
63
+ channel: 'production',
64
+ });
65
+ ```
66
+
67
+ If you were running your own Firestore project for manifests, register
68
+ your app in the Native Update dashboard, generate an API key, and
69
+ switch to the HTTP config above. The dashboard mirrors every field
70
+ that previously lived in your Firestore manifest.
71
+
72
+ #### 2. Delete any direct Firestore reads from your app code
73
+
74
+ ```diff
75
+ - import { FirestoreConfig } from 'native-update';
76
+ ```
77
+
78
+ The plugin no longer exposes `FirestoreConfig`, `firestore-client`, or
79
+ `manifest-reader`. Update checks happen via
80
+ `NativeUpdate.checkForUpdate()` / `NativeUpdate.sync()`, which now
81
+ always speak HTTP to your configured `serverUrl`.
82
+
83
+ #### 3. Replace `firestore/schema` type imports
84
+
85
+ If you were importing rollout / device / update-check types, switch to
86
+ the new backend-neutral exports:
87
+
88
+ ```diff
89
+ - import type {
90
+ - RolloutConfig,
91
+ - RolloutTargetSegments,
92
+ - DeviceInfo,
93
+ - UpdateCheckResponse,
94
+ - } from 'native-update/firestore';
95
+ + import type {
96
+ + RolloutConfig,
97
+ + RolloutTargetSegments,
98
+ + DeviceInfo,
99
+ + UpdateCheckResponse,
100
+ + } from 'native-update';
101
+ ```
102
+
103
+ `FirestoreTimestamp` is replaced by `RolloutTimestamp` (`number |
104
+ string | Date`); a `toEpochMs()` helper handles all three forms.
105
+
106
+ ### Not affected
107
+
108
+ - Bundle download, verification, install, rollback, boot-time
109
+ re-verify, and crash-loop auto-rollback are unchanged.
110
+ - Native Android / iOS plugin code is unchanged.
111
+ - App store update checks (`AppUpdate`) and in-app review prompts
112
+ (`AppReview`) are unchanged.
113
+
114
+ ---
115
+
116
+ ## Upgrading v1 → v2.0.0
117
+
118
+ v2 is a security-focused hardening release with a handful of breaking
119
+ changes. Every change is either (a) a credential-hardening tightening
120
+ that removes a silent-pass path, or (b) a feature removal for an option
121
+ that was documented but never actually implemented. Typical integrations
122
+ need only 2–3 config edits.
123
+
124
+ ### Required action
125
+
126
+ #### 1. Re-pass `apiKey` / `publicKey` on every `initialize()`
127
+
128
+ v1 persisted config (including `apiKey` and `publicKey`) to
129
+ `localStorage` / `SharedPreferences` / `UserDefaults`. v2 strips these
130
+ fields before persistence on every platform. Your app must provide them
131
+ on every `initialize()` call instead of relying on the cached copy.
132
+
133
+ ```ts
134
+ await NativeUpdate.initialize({
135
+ serverUrl: import.meta.env.VITE_NATIVE_UPDATE_API_URL,
136
+ apiKey: import.meta.env.VITE_NATIVE_UPDATE_API_KEY,
137
+ publicKey: import.meta.env.VITE_NATIVE_UPDATE_PUBLIC_KEY,
138
+ appId: 'com.your.app',
139
+ channel: 'production',
140
+ });
141
+ ```
142
+
143
+ If you relied on a "call initialize once, then continue" pattern without
144
+ re-passing the key, sync + download calls will fail with
145
+ "API key not configured" after the first cold start.
146
+
147
+ #### 2. Remove `enableEncryption`, `encryptionKey`, `encryptionSalt`
148
+
149
+ These options claimed AES-256-GCM bundle encryption but were only wired
150
+ on the web platform and never on Android/iOS — they shipped a false
151
+ guarantee. v2 removes them from the public API.
152
+
153
+ #### 3. Remove `allowDowngrade` from `UpdateOptions`
154
+
155
+ Downgrades are a debug / recovery operation, not a production flag.
156
+ v2 removes the option and always blocks downgrades against the
157
+ persisted high-water mark per channel.
158
+
159
+ #### 4. Stop calling `setUpdateUrl()` at runtime
160
+
161
+ `setUpdateUrl()` is deprecated and now a no-op. Server URL is fixed at
162
+ `initialize()` to close an XSS-repoint attack path. Call `reset()` and then
163
+ `initialize()` with the new config if you legitimately need to switch servers.
164
+
165
+ #### 5. iOS host-app Info.plist for background updates
166
+
167
+ If you use `enableBackgroundUpdates` on iOS, add to your app's own
168
+ `Info.plist`:
169
+
170
+ ```xml
171
+ <key>UIBackgroundModes</key>
172
+ <array><string>background-app-refresh</string></array>
173
+ <key>BGTaskSchedulerPermittedIdentifiers</key>
174
+ <array><string>com.aoneahsan.nativeupdate.background</string></array>
175
+ ```
176
+
177
+ Without these, iOS silently refuses to register the background task.
178
+ v2 surfaces an actionable error in `backgroundUpdateStatus.lastError`.
179
+
180
+ ### Behaviour that changed (no action needed)
181
+
182
+ - Signature verification fails closed when a `publicKey` is configured.
183
+ - Active bundle is re-hashed + re-signature-verified on every cold start.
184
+ - 2 failed cold starts without `notifyAppReady()` trigger auto-rollback.
185
+ - 3 most recent bundles kept by default (pass `cleanupOldBundles: false`
186
+ to opt out).
187
+ - Jittered exponential backoff on retries.
188
+ - Android WorkManager background jobs cap at 5 retries.
189
+
190
+ ### Backend changes (if self-hosting)
191
+
192
+ - Stripe → PayPal swap via `srmklive/paypal`. Run `composer update`,
193
+ apply the new migration, set `PAYPAL_*` env vars. See
194
+ `/docs/deployment/HOSTINGER_DEPLOY.md`.
195
+ - Signed URL TTL moved 5min → 30min, configurable via
196
+ `NATIVE_UPDATE_DOWNLOAD_TTL_MIN`.
197
+ - Device IDs HMAC-SHA256 hashed at DB write. New rows only — existing
198
+ rows are not backfilled.
199
+
200
+ ---
201
+
202
+ ## Migrating from Other Update Solutions
203
+
204
+ ### From Capacitor Live Updates (Official)
205
+
206
+ If you're migrating from the official Capacitor Live Updates plugin:
207
+
208
+ 1. **Update imports**:
209
+
210
+ ```typescript
211
+ // Before
212
+ import { LiveUpdates } from '@capacitor/live-updates';
213
+
214
+ // After
215
+ import { NativeUpdate } from 'native-update';
216
+ ```
217
+
218
+ 2. **Update configuration**:
219
+
220
+ ```typescript
221
+ // Before
222
+ await LiveUpdates.configure({
223
+ appId: 'your-app-id',
224
+ channel: 'production',
225
+ autoUpdateMethod: 'background',
226
+ });
227
+
228
+ // After
229
+ await NativeUpdate.configure({
230
+ liveUpdate: {
231
+ appId: 'your-app-id',
232
+ serverUrl: 'https://your-server.com',
233
+ channel: 'production',
234
+ updateStrategy: 'background',
235
+ publicKey: 'your-public-key',
236
+ },
237
+ });
238
+ ```
239
+
240
+ 3. **Update method calls**:
241
+
242
+ ```typescript
243
+ // Before
244
+ const result = await LiveUpdates.sync();
245
+
246
+ // After
247
+ const result = await NativeUpdate.sync();
248
+ ```
249
+
250
+ ### From Capgo Capacitor Updater
251
+
252
+ If you're migrating from @capgo/capacitor-updater:
253
+
254
+ 1. **Bundle management differences**:
255
+ - Our plugin uses a different bundle storage mechanism
256
+ - You'll need to re-download any active bundles
257
+ - Bundle IDs are generated differently
258
+
259
+ 2. **API differences**:
260
+
261
+ ```typescript
262
+ // Capgo
263
+ import { CapacitorUpdater } from '@capgo/capacitor-updater';
264
+ await CapacitorUpdater.download({ url, version });
265
+
266
+ // Capacitor Native Update
267
+ import { NativeUpdate } from 'native-update';
268
+ await NativeUpdate.download({
269
+ url,
270
+ version,
271
+ checksum: 'required-checksum',
272
+ });
273
+ ```
274
+
275
+ 3. **Security enhancements**:
276
+ - Checksum is now required for all downloads
277
+ - HTTPS is enforced by default
278
+ - Public key verification is built-in
279
+
280
+ ### From Ionic Appflow
281
+
282
+ If you're migrating from Ionic Appflow:
283
+
284
+ 1. **Self-hosted server required**:
285
+ - Unlike Appflow, this plugin requires your own update server
286
+ - See our server implementation guide for details
287
+
288
+ 2. **Channel management**:
289
+
290
+ ```typescript
291
+ // Similar channel concept
292
+ await NativeUpdate.setChannel('production');
293
+ ```
294
+
295
+ 3. **Additional features**:
296
+ - Native app update checks
297
+ - In-app review integration
298
+ - More granular security controls
299
+
300
+ ## Breaking Changes
301
+
302
+ ### Version 1.0.0
303
+
304
+ This is the initial release, but here are key differences from similar plugins:
305
+
306
+ 1. **Required parameters**:
307
+ - `checksum` is required for all bundle downloads
308
+ - `serverUrl` must use HTTPS (unless explicitly disabled)
309
+
310
+ 2. **Security by default**:
311
+ - HTTPS enforcement is on by default
312
+ - Signature verification is recommended
313
+ - Input validation cannot be disabled
314
+
315
+ 3. **Unified API**:
316
+ - All update types (live, native, reviews) in one plugin
317
+ - Single configuration object
318
+ - Consistent error handling
319
+
320
+ ## Data Migration
321
+
322
+ If you have existing bundles from another solution:
323
+
324
+ ```typescript
325
+ // Clear old data and start fresh
326
+ await NativeUpdate.reset();
327
+
328
+ // Or manually migrate bundles
329
+ const oldBundles = getOldBundles(); // Your migration logic
330
+ for (const bundle of oldBundles) {
331
+ // Re-download with new security requirements
332
+ await NativeUpdate.download({
333
+ url: bundle.url,
334
+ version: bundle.version,
335
+ checksum: await calculateChecksum(bundle.url),
336
+ });
337
+ }
338
+ ```
339
+
340
+ ## Configuration Migration
341
+
342
+ ### Old Configuration Patterns
343
+
344
+ ```typescript
345
+ // CodePush style
346
+ codePush.sync({
347
+ deploymentKey: 'key',
348
+ installMode: codePush.InstallMode.IMMEDIATE,
349
+ });
350
+
351
+ // Convert to:
352
+ await NativeUpdate.sync({
353
+ updateMode: 'immediate',
354
+ });
355
+ ```
356
+
357
+ ### Environment-Specific Config
358
+
359
+ ```typescript
360
+ const config = {
361
+ liveUpdate: {
362
+ serverUrl: process.env.UPDATE_SERVER_URL,
363
+ channel: process.env.UPDATE_CHANNEL || 'production',
364
+ publicKey: process.env.UPDATE_PUBLIC_KEY,
365
+ },
366
+ };
367
+
368
+ await NativeUpdate.configure(config);
369
+ ```
370
+
371
+ ## Troubleshooting Migration
372
+
373
+ ### Common Issues
374
+
375
+ 1. **"Checksum required" error**:
376
+ - Calculate SHA-256 checksum of your bundles
377
+ - Include in download request
378
+
379
+ 2. **"HTTPS required" error**:
380
+ - Update server URLs to use HTTPS
381
+ - Or disable enforcement (not recommended)
382
+
383
+ 3. **Bundle compatibility**:
384
+ - Bundles from other systems won't work directly
385
+ - Re-package and sign your bundles
386
+
387
+ ### Getting Help
388
+
389
+ - Check our example app in the `/example` directory for implementation patterns
390
+ - Review the [API documentation](https://nativeupdate.aoneahsan.com/docs/api/live-update-api)
391
+ - File issues on GitHub for migration problems