native-update 1.0.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.
- package/CapacitorNativeUpdate.podspec +18 -0
- package/LICENSE +21 -0
- package/Readme.md +451 -0
- package/android/build.gradle +92 -0
- package/android/gradle/wrapper/gradle-wrapper.properties +8 -0
- package/android/gradle.properties +17 -0
- package/android/proguard-rules.pro +29 -0
- package/android/settings.gradle +2 -0
- package/android/src/main/AndroidManifest.xml +34 -0
- package/android/src/main/java/com/aoneahsan/nativeupdate/AppReviewPlugin.kt +153 -0
- package/android/src/main/java/com/aoneahsan/nativeupdate/AppUpdatePlugin.kt +275 -0
- package/android/src/main/java/com/aoneahsan/nativeupdate/BackgroundNotificationManager.kt +390 -0
- package/android/src/main/java/com/aoneahsan/nativeupdate/BackgroundUpdateManager.kt +46 -0
- package/android/src/main/java/com/aoneahsan/nativeupdate/BackgroundUpdatePlugin.kt +333 -0
- package/android/src/main/java/com/aoneahsan/nativeupdate/BackgroundUpdateWorker.kt +251 -0
- package/android/src/main/java/com/aoneahsan/nativeupdate/CapacitorNativeUpdatePlugin.kt +265 -0
- package/android/src/main/java/com/aoneahsan/nativeupdate/LiveUpdatePlugin.kt +526 -0
- package/android/src/main/java/com/aoneahsan/nativeupdate/NotificationActionReceiver.kt +99 -0
- package/android/src/main/java/com/aoneahsan/nativeupdate/SecurityManager.kt +249 -0
- package/dist/esm/__tests__/bundle-manager.test.d.ts +1 -0
- package/dist/esm/__tests__/bundle-manager.test.js +123 -0
- package/dist/esm/__tests__/bundle-manager.test.js.map +1 -0
- package/dist/esm/__tests__/config.test.d.ts +1 -0
- package/dist/esm/__tests__/config.test.js +69 -0
- package/dist/esm/__tests__/config.test.js.map +1 -0
- package/dist/esm/__tests__/integration.test.d.ts +1 -0
- package/dist/esm/__tests__/integration.test.js +78 -0
- package/dist/esm/__tests__/integration.test.js.map +1 -0
- package/dist/esm/__tests__/security.test.d.ts +1 -0
- package/dist/esm/__tests__/security.test.js +54 -0
- package/dist/esm/__tests__/security.test.js.map +1 -0
- package/dist/esm/__tests__/version-manager.test.d.ts +1 -0
- package/dist/esm/__tests__/version-manager.test.js +45 -0
- package/dist/esm/__tests__/version-manager.test.js.map +1 -0
- package/dist/esm/app-review/app-review-manager.d.ts +24 -0
- package/dist/esm/app-review/app-review-manager.js +195 -0
- package/dist/esm/app-review/app-review-manager.js.map +1 -0
- package/dist/esm/app-review/index.d.ts +5 -0
- package/dist/esm/app-review/index.js +6 -0
- package/dist/esm/app-review/index.js.map +1 -0
- package/dist/esm/app-review/platform-review-handler.d.ts +20 -0
- package/dist/esm/app-review/platform-review-handler.js +138 -0
- package/dist/esm/app-review/platform-review-handler.js.map +1 -0
- package/dist/esm/app-review/review-conditions-checker.d.ts +22 -0
- package/dist/esm/app-review/review-conditions-checker.js +155 -0
- package/dist/esm/app-review/review-conditions-checker.js.map +1 -0
- package/dist/esm/app-review/review-rate-limiter.d.ts +23 -0
- package/dist/esm/app-review/review-rate-limiter.js +164 -0
- package/dist/esm/app-review/review-rate-limiter.js.map +1 -0
- package/dist/esm/app-review/types.d.ts +41 -0
- package/dist/esm/app-review/types.js +2 -0
- package/dist/esm/app-review/types.js.map +1 -0
- package/dist/esm/app-update/app-update-checker.d.ts +13 -0
- package/dist/esm/app-update/app-update-checker.js +104 -0
- package/dist/esm/app-update/app-update-checker.js.map +1 -0
- package/dist/esm/app-update/app-update-installer.d.ts +19 -0
- package/dist/esm/app-update/app-update-installer.js +123 -0
- package/dist/esm/app-update/app-update-installer.js.map +1 -0
- package/dist/esm/app-update/app-update-manager.d.ts +28 -0
- package/dist/esm/app-update/app-update-manager.js +199 -0
- package/dist/esm/app-update/app-update-manager.js.map +1 -0
- package/dist/esm/app-update/app-update-notifier.d.ts +14 -0
- package/dist/esm/app-update/app-update-notifier.js +100 -0
- package/dist/esm/app-update/app-update-notifier.js.map +1 -0
- package/dist/esm/app-update/index.d.ts +6 -0
- package/dist/esm/app-update/index.js +7 -0
- package/dist/esm/app-update/index.js.map +1 -0
- package/dist/esm/app-update/platform-app-update.d.ts +19 -0
- package/dist/esm/app-update/platform-app-update.js +129 -0
- package/dist/esm/app-update/platform-app-update.js.map +1 -0
- package/dist/esm/app-update/types.d.ts +58 -0
- package/dist/esm/app-update/types.js +12 -0
- package/dist/esm/app-update/types.js.map +1 -0
- package/dist/esm/background-update/background-scheduler.d.ts +17 -0
- package/dist/esm/background-update/background-scheduler.js +195 -0
- package/dist/esm/background-update/background-scheduler.js.map +1 -0
- package/dist/esm/background-update/index.d.ts +3 -0
- package/dist/esm/background-update/index.js +3 -0
- package/dist/esm/background-update/index.js.map +1 -0
- package/dist/esm/background-update/notification-manager.d.ts +29 -0
- package/dist/esm/background-update/notification-manager.js +89 -0
- package/dist/esm/background-update/notification-manager.js.map +1 -0
- package/dist/esm/core/analytics.d.ts +70 -0
- package/dist/esm/core/analytics.js +137 -0
- package/dist/esm/core/analytics.js.map +1 -0
- package/dist/esm/core/cache-manager.d.ts +72 -0
- package/dist/esm/core/cache-manager.js +275 -0
- package/dist/esm/core/cache-manager.js.map +1 -0
- package/dist/esm/core/config.d.ts +48 -0
- package/dist/esm/core/config.js +83 -0
- package/dist/esm/core/config.js.map +1 -0
- package/dist/esm/core/errors.d.ts +51 -0
- package/dist/esm/core/errors.js +80 -0
- package/dist/esm/core/errors.js.map +1 -0
- package/dist/esm/core/logger.d.ts +21 -0
- package/dist/esm/core/logger.js +109 -0
- package/dist/esm/core/logger.js.map +1 -0
- package/dist/esm/core/performance.d.ts +53 -0
- package/dist/esm/core/performance.js +140 -0
- package/dist/esm/core/performance.js.map +1 -0
- package/dist/esm/core/plugin-manager.d.ts +66 -0
- package/dist/esm/core/plugin-manager.js +148 -0
- package/dist/esm/core/plugin-manager.js.map +1 -0
- package/dist/esm/core/security.d.ts +93 -0
- package/dist/esm/core/security.js +315 -0
- package/dist/esm/core/security.js.map +1 -0
- package/dist/esm/definitions.d.ts +639 -0
- package/dist/esm/definitions.js +103 -0
- package/dist/esm/definitions.js.map +1 -0
- package/dist/esm/index.d.ts +12 -0
- package/dist/esm/index.js +16 -0
- package/dist/esm/index.js.map +1 -0
- package/dist/esm/live-update/bundle-manager.d.ts +94 -0
- package/dist/esm/live-update/bundle-manager.js +310 -0
- package/dist/esm/live-update/bundle-manager.js.map +1 -0
- package/dist/esm/live-update/certificate-pinning.d.ts +38 -0
- package/dist/esm/live-update/certificate-pinning.js +78 -0
- package/dist/esm/live-update/certificate-pinning.js.map +1 -0
- package/dist/esm/live-update/download-manager.d.ts +67 -0
- package/dist/esm/live-update/download-manager.js +319 -0
- package/dist/esm/live-update/download-manager.js.map +1 -0
- package/dist/esm/live-update/update-manager.d.ts +52 -0
- package/dist/esm/live-update/update-manager.js +294 -0
- package/dist/esm/live-update/update-manager.js.map +1 -0
- package/dist/esm/live-update/version-manager.d.ts +84 -0
- package/dist/esm/live-update/version-manager.js +335 -0
- package/dist/esm/live-update/version-manager.js.map +1 -0
- package/dist/esm/plugin.d.ts +6 -0
- package/dist/esm/plugin.js +283 -0
- package/dist/esm/plugin.js.map +1 -0
- package/dist/esm/security/crypto.d.ts +25 -0
- package/dist/esm/security/crypto.js +70 -0
- package/dist/esm/security/crypto.js.map +1 -0
- package/dist/esm/security/validator.d.ts +60 -0
- package/dist/esm/security/validator.js +143 -0
- package/dist/esm/security/validator.js.map +1 -0
- package/dist/esm/web.d.ts +74 -0
- package/dist/esm/web.js +595 -0
- package/dist/esm/web.js.map +1 -0
- package/dist/plugin.cjs.js +2 -0
- package/dist/plugin.cjs.js.map +1 -0
- package/dist/plugin.esm.js +2 -0
- package/dist/plugin.esm.js.map +1 -0
- package/dist/plugin.js +3 -0
- package/dist/plugin.js.map +1 -0
- package/docs/APP_REVIEW_GUIDE.md +768 -0
- package/docs/BUNDLE_SIGNING.md +264 -0
- package/docs/LIVE_UPDATES_GUIDE.md +650 -0
- package/docs/MIGRATION.md +192 -0
- package/docs/NATIVE_UPDATES_GUIDE.md +694 -0
- package/docs/QUICK_START.md +606 -0
- package/docs/README.md +111 -0
- package/docs/REMAINING_FEATURES.md +139 -0
- package/docs/api/app-review-api.md +259 -0
- package/docs/api/app-update-api.md +238 -0
- package/docs/api/events-api.md +451 -0
- package/docs/api/live-update-api.md +265 -0
- package/docs/background-updates.md +392 -0
- package/docs/examples/advanced-scenarios.md +410 -0
- package/docs/examples/basic-usage.md +185 -0
- package/docs/features/app-reviews.md +975 -0
- package/docs/features/app-updates.md +785 -0
- package/docs/features/live-updates.md +633 -0
- package/docs/getting-started/configuration.md +468 -0
- package/docs/getting-started/installation.md +209 -0
- package/docs/getting-started/quick-start.md +379 -0
- package/docs/guides/deployment-guide.md +333 -0
- package/docs/guides/migration-from-codepush.md +142 -0
- package/docs/guides/security-best-practices.md +1057 -0
- package/docs/guides/testing-guide.md +373 -0
- package/docs/production-readiness.md +478 -0
- package/docs/security/certificate-pinning.md +122 -0
- package/docs/server-requirements.md +147 -0
- package/ios/Plugin/AppReview/AppReviewPlugin.swift +158 -0
- package/ios/Plugin/AppUpdate/AppUpdatePlugin.swift +234 -0
- package/ios/Plugin/BackgroundUpdate/BackgroundNotificationManager.swift +329 -0
- package/ios/Plugin/BackgroundUpdate/BackgroundUpdatePlugin.swift +396 -0
- package/ios/Plugin/CapacitorNativeUpdatePlugin.m +45 -0
- package/ios/Plugin/CapacitorNativeUpdatePlugin.swift +190 -0
- package/ios/Plugin/Info.plist +43 -0
- package/ios/Plugin/LiveUpdate/LiveUpdatePlugin.swift +689 -0
- package/ios/Plugin/LiveUpdate/WebViewConfiguration.swift +45 -0
- package/ios/Plugin/Security/SecurityManager.swift +289 -0
- package/package.json +90 -0
|
@@ -0,0 +1,451 @@
|
|
|
1
|
+
# Events API Reference
|
|
2
|
+
|
|
3
|
+
Complete documentation for all events emitted by the Capacitor Native Update plugin.
|
|
4
|
+
|
|
5
|
+
## Event Listeners
|
|
6
|
+
|
|
7
|
+
### Adding Listeners
|
|
8
|
+
|
|
9
|
+
```typescript
|
|
10
|
+
// Add a listener
|
|
11
|
+
const listener = CapacitorNativeUpdate.addListener('eventName', (data) => {
|
|
12
|
+
console.log('Event data:', data);
|
|
13
|
+
});
|
|
14
|
+
|
|
15
|
+
// Remove a listener
|
|
16
|
+
listener.remove();
|
|
17
|
+
|
|
18
|
+
// Remove all listeners for an event
|
|
19
|
+
CapacitorNativeUpdate.removeAllListeners('eventName');
|
|
20
|
+
```
|
|
21
|
+
|
|
22
|
+
## Live Update Events
|
|
23
|
+
|
|
24
|
+
### updateStateChanged
|
|
25
|
+
|
|
26
|
+
Fired when the update state changes during sync or download.
|
|
27
|
+
|
|
28
|
+
```typescript
|
|
29
|
+
CapacitorNativeUpdate.addListener('updateStateChanged', (state) => {
|
|
30
|
+
console.log('Update state:', state);
|
|
31
|
+
});
|
|
32
|
+
```
|
|
33
|
+
|
|
34
|
+
**Event Data:**
|
|
35
|
+
```typescript
|
|
36
|
+
{
|
|
37
|
+
status: 'CHECKING' | 'DOWNLOADING' | 'READY' | 'FAILED' | 'INSTALLING';
|
|
38
|
+
bundleId?: string;
|
|
39
|
+
version?: string;
|
|
40
|
+
previousState?: string;
|
|
41
|
+
timestamp: number;
|
|
42
|
+
}
|
|
43
|
+
```
|
|
44
|
+
|
|
45
|
+
### downloadProgress
|
|
46
|
+
|
|
47
|
+
Fired periodically during bundle download.
|
|
48
|
+
|
|
49
|
+
```typescript
|
|
50
|
+
CapacitorNativeUpdate.addListener('downloadProgress', (progress) => {
|
|
51
|
+
console.log(`Download: ${progress.percent}%`);
|
|
52
|
+
});
|
|
53
|
+
```
|
|
54
|
+
|
|
55
|
+
**Event Data:**
|
|
56
|
+
```typescript
|
|
57
|
+
{
|
|
58
|
+
percent: number; // 0-100
|
|
59
|
+
bytesDownloaded: number; // Bytes downloaded so far
|
|
60
|
+
totalBytes: number; // Total bundle size
|
|
61
|
+
bytesPerSecond: number; // Download speed
|
|
62
|
+
estimatedTime: number; // Seconds remaining
|
|
63
|
+
bundleId: string; // Bundle being downloaded
|
|
64
|
+
}
|
|
65
|
+
```
|
|
66
|
+
|
|
67
|
+
### updateInstalled
|
|
68
|
+
|
|
69
|
+
Fired when an update has been successfully installed.
|
|
70
|
+
|
|
71
|
+
```typescript
|
|
72
|
+
CapacitorNativeUpdate.addListener('updateInstalled', (update) => {
|
|
73
|
+
console.log('Update installed:', update.version);
|
|
74
|
+
});
|
|
75
|
+
```
|
|
76
|
+
|
|
77
|
+
**Event Data:**
|
|
78
|
+
```typescript
|
|
79
|
+
{
|
|
80
|
+
bundleId: string;
|
|
81
|
+
version: string;
|
|
82
|
+
previousVersion: string;
|
|
83
|
+
installTime: number;
|
|
84
|
+
willRestartApp: boolean;
|
|
85
|
+
}
|
|
86
|
+
```
|
|
87
|
+
|
|
88
|
+
### updateFailed
|
|
89
|
+
|
|
90
|
+
Fired when an update fails to download or install.
|
|
91
|
+
|
|
92
|
+
```typescript
|
|
93
|
+
CapacitorNativeUpdate.addListener('updateFailed', (error) => {
|
|
94
|
+
console.error('Update failed:', error);
|
|
95
|
+
});
|
|
96
|
+
```
|
|
97
|
+
|
|
98
|
+
**Event Data:**
|
|
99
|
+
```typescript
|
|
100
|
+
{
|
|
101
|
+
bundleId?: string;
|
|
102
|
+
version?: string;
|
|
103
|
+
error: {
|
|
104
|
+
code: string;
|
|
105
|
+
message: string;
|
|
106
|
+
details?: any;
|
|
107
|
+
};
|
|
108
|
+
canRetry: boolean;
|
|
109
|
+
timestamp: number;
|
|
110
|
+
}
|
|
111
|
+
```
|
|
112
|
+
|
|
113
|
+
### rollbackOccurred
|
|
114
|
+
|
|
115
|
+
Fired when the app rolls back to a previous version.
|
|
116
|
+
|
|
117
|
+
```typescript
|
|
118
|
+
CapacitorNativeUpdate.addListener('rollbackOccurred', (rollback) => {
|
|
119
|
+
console.log('Rolled back from:', rollback.failedVersion);
|
|
120
|
+
});
|
|
121
|
+
```
|
|
122
|
+
|
|
123
|
+
**Event Data:**
|
|
124
|
+
```typescript
|
|
125
|
+
{
|
|
126
|
+
failedVersion: string;
|
|
127
|
+
failedBundleId: string;
|
|
128
|
+
rolledBackTo: string;
|
|
129
|
+
reason: string;
|
|
130
|
+
timestamp: number;
|
|
131
|
+
}
|
|
132
|
+
```
|
|
133
|
+
|
|
134
|
+
## App Update Events
|
|
135
|
+
|
|
136
|
+
### appUpdateStateChanged
|
|
137
|
+
|
|
138
|
+
Fired when native app update state changes. Android only.
|
|
139
|
+
|
|
140
|
+
```typescript
|
|
141
|
+
CapacitorNativeUpdate.addListener('appUpdateStateChanged', (state) => {
|
|
142
|
+
console.log('App update state:', state);
|
|
143
|
+
});
|
|
144
|
+
```
|
|
145
|
+
|
|
146
|
+
**Event Data:**
|
|
147
|
+
```typescript
|
|
148
|
+
{
|
|
149
|
+
installStatus: number; // Android InstallStatus
|
|
150
|
+
installErrorCode?: number;
|
|
151
|
+
packageName: string;
|
|
152
|
+
availableVersion: string;
|
|
153
|
+
}
|
|
154
|
+
```
|
|
155
|
+
|
|
156
|
+
**Install Status Codes:**
|
|
157
|
+
- `0` - Unknown
|
|
158
|
+
- `1` - Pending
|
|
159
|
+
- `2` - Downloading
|
|
160
|
+
- `3` - Installing
|
|
161
|
+
- `4` - Installed
|
|
162
|
+
- `5` - Failed
|
|
163
|
+
- `6` - Canceled
|
|
164
|
+
- `11` - Downloaded
|
|
165
|
+
|
|
166
|
+
### appUpdateProgress
|
|
167
|
+
|
|
168
|
+
Fired during flexible app update download. Android only.
|
|
169
|
+
|
|
170
|
+
```typescript
|
|
171
|
+
CapacitorNativeUpdate.addListener('appUpdateProgress', (progress) => {
|
|
172
|
+
console.log('App update progress:', progress.percentComplete);
|
|
173
|
+
});
|
|
174
|
+
```
|
|
175
|
+
|
|
176
|
+
**Event Data:**
|
|
177
|
+
```typescript
|
|
178
|
+
{
|
|
179
|
+
bytesDownloaded: number;
|
|
180
|
+
totalBytesToDownload: number;
|
|
181
|
+
percentComplete: number;
|
|
182
|
+
downloadSpeed: number; // Bytes per second
|
|
183
|
+
estimatedTime: number; // Seconds remaining
|
|
184
|
+
}
|
|
185
|
+
```
|
|
186
|
+
|
|
187
|
+
### appUpdateAvailable
|
|
188
|
+
|
|
189
|
+
Fired when an app update becomes available.
|
|
190
|
+
|
|
191
|
+
```typescript
|
|
192
|
+
CapacitorNativeUpdate.addListener('appUpdateAvailable', (update) => {
|
|
193
|
+
console.log('App update available:', update.version);
|
|
194
|
+
});
|
|
195
|
+
```
|
|
196
|
+
|
|
197
|
+
**Event Data:**
|
|
198
|
+
```typescript
|
|
199
|
+
{
|
|
200
|
+
currentVersion: string;
|
|
201
|
+
availableVersion: string;
|
|
202
|
+
updatePriority: 'LOW' | 'MEDIUM' | 'HIGH' | 'IMMEDIATE';
|
|
203
|
+
updateSize?: number;
|
|
204
|
+
releaseNotes?: string;
|
|
205
|
+
storeUrl: string;
|
|
206
|
+
}
|
|
207
|
+
```
|
|
208
|
+
|
|
209
|
+
## App Review Events
|
|
210
|
+
|
|
211
|
+
### reviewPromptDisplayed
|
|
212
|
+
|
|
213
|
+
Fired when a review prompt is shown to the user.
|
|
214
|
+
|
|
215
|
+
```typescript
|
|
216
|
+
CapacitorNativeUpdate.addListener('reviewPromptDisplayed', (event) => {
|
|
217
|
+
analytics.track('review_prompt_shown');
|
|
218
|
+
});
|
|
219
|
+
```
|
|
220
|
+
|
|
221
|
+
**Event Data:**
|
|
222
|
+
```typescript
|
|
223
|
+
{
|
|
224
|
+
platform: 'ios' | 'android' | 'web';
|
|
225
|
+
method: 'in-app' | 'store-redirect';
|
|
226
|
+
timestamp: number;
|
|
227
|
+
sessionTime: number; // Time in app before prompt
|
|
228
|
+
}
|
|
229
|
+
```
|
|
230
|
+
|
|
231
|
+
### reviewPromptDismissed
|
|
232
|
+
|
|
233
|
+
Fired when the review prompt is dismissed.
|
|
234
|
+
|
|
235
|
+
```typescript
|
|
236
|
+
CapacitorNativeUpdate.addListener('reviewPromptDismissed', (event) => {
|
|
237
|
+
console.log('Review prompt dismissed');
|
|
238
|
+
});
|
|
239
|
+
```
|
|
240
|
+
|
|
241
|
+
**Event Data:**
|
|
242
|
+
```typescript
|
|
243
|
+
{
|
|
244
|
+
platform: 'ios' | 'android' | 'web';
|
|
245
|
+
userAction?: 'reviewed' | 'dismissed' | 'later';
|
|
246
|
+
timestamp: number;
|
|
247
|
+
}
|
|
248
|
+
```
|
|
249
|
+
|
|
250
|
+
## Background Update Events
|
|
251
|
+
|
|
252
|
+
### backgroundCheckStarted
|
|
253
|
+
|
|
254
|
+
Fired when a background update check begins.
|
|
255
|
+
|
|
256
|
+
```typescript
|
|
257
|
+
CapacitorNativeUpdate.addListener('backgroundCheckStarted', (event) => {
|
|
258
|
+
console.log('Background check started');
|
|
259
|
+
});
|
|
260
|
+
```
|
|
261
|
+
|
|
262
|
+
**Event Data:**
|
|
263
|
+
```typescript
|
|
264
|
+
{
|
|
265
|
+
checkId: string;
|
|
266
|
+
trigger: 'scheduled' | 'app-resume' | 'manual';
|
|
267
|
+
timestamp: number;
|
|
268
|
+
}
|
|
269
|
+
```
|
|
270
|
+
|
|
271
|
+
### backgroundCheckCompleted
|
|
272
|
+
|
|
273
|
+
Fired when a background update check completes.
|
|
274
|
+
|
|
275
|
+
```typescript
|
|
276
|
+
CapacitorNativeUpdate.addListener('backgroundCheckCompleted', (result) => {
|
|
277
|
+
console.log('Background check result:', result);
|
|
278
|
+
});
|
|
279
|
+
```
|
|
280
|
+
|
|
281
|
+
**Event Data:**
|
|
282
|
+
```typescript
|
|
283
|
+
{
|
|
284
|
+
checkId: string;
|
|
285
|
+
updateAvailable: boolean;
|
|
286
|
+
version?: string;
|
|
287
|
+
downloadStarted: boolean;
|
|
288
|
+
duration: number; // Check duration in ms
|
|
289
|
+
timestamp: number;
|
|
290
|
+
}
|
|
291
|
+
```
|
|
292
|
+
|
|
293
|
+
### backgroundDownloadCompleted
|
|
294
|
+
|
|
295
|
+
Fired when a background download completes.
|
|
296
|
+
|
|
297
|
+
```typescript
|
|
298
|
+
CapacitorNativeUpdate.addListener('backgroundDownloadCompleted', (result) => {
|
|
299
|
+
console.log('Background download completed');
|
|
300
|
+
});
|
|
301
|
+
```
|
|
302
|
+
|
|
303
|
+
**Event Data:**
|
|
304
|
+
```typescript
|
|
305
|
+
{
|
|
306
|
+
bundleId: string;
|
|
307
|
+
version: string;
|
|
308
|
+
success: boolean;
|
|
309
|
+
error?: string;
|
|
310
|
+
downloadTime: number; // Total download time
|
|
311
|
+
willInstallOnResume: boolean;
|
|
312
|
+
}
|
|
313
|
+
```
|
|
314
|
+
|
|
315
|
+
## Error Events
|
|
316
|
+
|
|
317
|
+
### error
|
|
318
|
+
|
|
319
|
+
Generic error event for any plugin errors.
|
|
320
|
+
|
|
321
|
+
```typescript
|
|
322
|
+
CapacitorNativeUpdate.addListener('error', (error) => {
|
|
323
|
+
console.error('Plugin error:', error);
|
|
324
|
+
errorReporting.log(error);
|
|
325
|
+
});
|
|
326
|
+
```
|
|
327
|
+
|
|
328
|
+
**Event Data:**
|
|
329
|
+
```typescript
|
|
330
|
+
{
|
|
331
|
+
code: string; // Error code
|
|
332
|
+
message: string; // Human-readable message
|
|
333
|
+
module: 'live-update' | 'app-update' | 'app-review';
|
|
334
|
+
severity: 'low' | 'medium' | 'high' | 'critical';
|
|
335
|
+
details?: any; // Additional error context
|
|
336
|
+
timestamp: number;
|
|
337
|
+
stackTrace?: string;
|
|
338
|
+
}
|
|
339
|
+
```
|
|
340
|
+
|
|
341
|
+
## Analytics Events
|
|
342
|
+
|
|
343
|
+
### analyticsEvent
|
|
344
|
+
|
|
345
|
+
Fired for analytics tracking.
|
|
346
|
+
|
|
347
|
+
```typescript
|
|
348
|
+
CapacitorNativeUpdate.addListener('analyticsEvent', (event) => {
|
|
349
|
+
// Forward to your analytics provider
|
|
350
|
+
analytics.track(event.name, event.properties);
|
|
351
|
+
});
|
|
352
|
+
```
|
|
353
|
+
|
|
354
|
+
**Event Data:**
|
|
355
|
+
```typescript
|
|
356
|
+
{
|
|
357
|
+
name: string; // Event name
|
|
358
|
+
properties: Record<string, any>;
|
|
359
|
+
category: 'update' | 'review' | 'error' | 'performance';
|
|
360
|
+
timestamp: number;
|
|
361
|
+
}
|
|
362
|
+
```
|
|
363
|
+
|
|
364
|
+
## Best Practices
|
|
365
|
+
|
|
366
|
+
### 1. Centralized Event Handling
|
|
367
|
+
|
|
368
|
+
```typescript
|
|
369
|
+
class UpdateEventManager {
|
|
370
|
+
private listeners: PluginListenerHandle[] = [];
|
|
371
|
+
|
|
372
|
+
init() {
|
|
373
|
+
// Register all listeners
|
|
374
|
+
this.listeners.push(
|
|
375
|
+
CapacitorNativeUpdate.addListener('updateStateChanged', this.handleStateChange),
|
|
376
|
+
CapacitorNativeUpdate.addListener('downloadProgress', this.handleProgress),
|
|
377
|
+
CapacitorNativeUpdate.addListener('error', this.handleError)
|
|
378
|
+
);
|
|
379
|
+
}
|
|
380
|
+
|
|
381
|
+
cleanup() {
|
|
382
|
+
// Remove all listeners
|
|
383
|
+
this.listeners.forEach(listener => listener.remove());
|
|
384
|
+
}
|
|
385
|
+
|
|
386
|
+
private handleStateChange = (state) => {
|
|
387
|
+
// Centralized state handling
|
|
388
|
+
updateUI(state);
|
|
389
|
+
logEvent('update_state', state);
|
|
390
|
+
};
|
|
391
|
+
|
|
392
|
+
private handleProgress = (progress) => {
|
|
393
|
+
// Update progress UI
|
|
394
|
+
progressBar.setValue(progress.percent);
|
|
395
|
+
};
|
|
396
|
+
|
|
397
|
+
private handleError = (error) => {
|
|
398
|
+
// Centralized error handling
|
|
399
|
+
if (error.severity === 'critical') {
|
|
400
|
+
showErrorDialog(error);
|
|
401
|
+
}
|
|
402
|
+
errorReporter.log(error);
|
|
403
|
+
};
|
|
404
|
+
}
|
|
405
|
+
```
|
|
406
|
+
|
|
407
|
+
### 2. Event-Driven UI Updates
|
|
408
|
+
|
|
409
|
+
```typescript
|
|
410
|
+
// React example
|
|
411
|
+
function useUpdateState() {
|
|
412
|
+
const [state, setState] = useState<UpdateState>('idle');
|
|
413
|
+
const [progress, setProgress] = useState(0);
|
|
414
|
+
|
|
415
|
+
useEffect(() => {
|
|
416
|
+
const listeners = [
|
|
417
|
+
CapacitorNativeUpdate.addListener('updateStateChanged', (event) => {
|
|
418
|
+
setState(event.status);
|
|
419
|
+
}),
|
|
420
|
+
CapacitorNativeUpdate.addListener('downloadProgress', (event) => {
|
|
421
|
+
setProgress(event.percent);
|
|
422
|
+
})
|
|
423
|
+
];
|
|
424
|
+
|
|
425
|
+
return () => {
|
|
426
|
+
listeners.forEach(l => l.remove());
|
|
427
|
+
};
|
|
428
|
+
}, []);
|
|
429
|
+
|
|
430
|
+
return { state, progress };
|
|
431
|
+
}
|
|
432
|
+
```
|
|
433
|
+
|
|
434
|
+
### 3. Analytics Integration
|
|
435
|
+
|
|
436
|
+
```typescript
|
|
437
|
+
// Set up analytics forwarding
|
|
438
|
+
CapacitorNativeUpdate.addListener('analyticsEvent', (event) => {
|
|
439
|
+
switch (analyticsProvider) {
|
|
440
|
+
case 'firebase':
|
|
441
|
+
firebase.analytics().logEvent(event.name, event.properties);
|
|
442
|
+
break;
|
|
443
|
+
case 'mixpanel':
|
|
444
|
+
mixpanel.track(event.name, event.properties);
|
|
445
|
+
break;
|
|
446
|
+
case 'custom':
|
|
447
|
+
customAnalytics.track(event);
|
|
448
|
+
break;
|
|
449
|
+
}
|
|
450
|
+
});
|
|
451
|
+
```
|
|
@@ -0,0 +1,265 @@
|
|
|
1
|
+
# Live Update API Reference
|
|
2
|
+
|
|
3
|
+
Complete API documentation for Live/OTA update functionality.
|
|
4
|
+
|
|
5
|
+
## Methods
|
|
6
|
+
|
|
7
|
+
### configure(options)
|
|
8
|
+
|
|
9
|
+
Configure the Live Update plugin with server settings and behavior options.
|
|
10
|
+
|
|
11
|
+
```typescript
|
|
12
|
+
await CapacitorNativeUpdate.configure({
|
|
13
|
+
serverUrl: string; // Update server URL (required)
|
|
14
|
+
channel?: string; // Update channel (default: "production")
|
|
15
|
+
autoCheck?: boolean; // Auto-check for updates (default: true)
|
|
16
|
+
checkInterval?: number; // Check interval in seconds (default: 3600)
|
|
17
|
+
publicKey?: string; // Base64 public key for signatures
|
|
18
|
+
maxRetries?: number; // Max download retries (default: 3)
|
|
19
|
+
security?: {
|
|
20
|
+
enforceHttps?: boolean; // Require HTTPS (default: true)
|
|
21
|
+
validateSignatures?: boolean; // Verify signatures (default: true)
|
|
22
|
+
pinCertificates?: boolean; // Certificate pinning (default: false)
|
|
23
|
+
certificateHashes?: string[]; // Certificate SHA-256 hashes
|
|
24
|
+
};
|
|
25
|
+
});
|
|
26
|
+
```
|
|
27
|
+
|
|
28
|
+
### checkForUpdate()
|
|
29
|
+
|
|
30
|
+
Check if a new update is available.
|
|
31
|
+
|
|
32
|
+
```typescript
|
|
33
|
+
const result = await CapacitorNativeUpdate.checkForUpdate();
|
|
34
|
+
// Returns:
|
|
35
|
+
{
|
|
36
|
+
available: boolean; // Update available?
|
|
37
|
+
version?: string; // Available version
|
|
38
|
+
url?: string; // Download URL
|
|
39
|
+
notes?: string; // Release notes
|
|
40
|
+
size?: number; // Bundle size in bytes
|
|
41
|
+
mandatoryUpdate?: boolean; // Force update?
|
|
42
|
+
checksum?: string; // SHA-256 checksum
|
|
43
|
+
signature?: string; // RSA signature
|
|
44
|
+
}
|
|
45
|
+
```
|
|
46
|
+
|
|
47
|
+
### downloadUpdate(options?)
|
|
48
|
+
|
|
49
|
+
Download an available update with progress tracking.
|
|
50
|
+
|
|
51
|
+
```typescript
|
|
52
|
+
const result = await CapacitorNativeUpdate.downloadUpdate({
|
|
53
|
+
onProgress?: (progress: {
|
|
54
|
+
percent: number; // 0-100
|
|
55
|
+
bytesDownloaded: number;
|
|
56
|
+
totalBytes: number;
|
|
57
|
+
}) => void;
|
|
58
|
+
});
|
|
59
|
+
// Returns:
|
|
60
|
+
{
|
|
61
|
+
bundleId: string; // Unique bundle ID
|
|
62
|
+
version: string; // Bundle version
|
|
63
|
+
path: string; // Local path
|
|
64
|
+
size: number; // File size
|
|
65
|
+
downloadTime: number; // Download duration (ms)
|
|
66
|
+
}
|
|
67
|
+
```
|
|
68
|
+
|
|
69
|
+
### applyUpdate()
|
|
70
|
+
|
|
71
|
+
Apply a downloaded update (restarts the app).
|
|
72
|
+
|
|
73
|
+
```typescript
|
|
74
|
+
await CapacitorNativeUpdate.applyUpdate();
|
|
75
|
+
```
|
|
76
|
+
|
|
77
|
+
### sync(options?)
|
|
78
|
+
|
|
79
|
+
Sync with server and apply updates based on strategy.
|
|
80
|
+
|
|
81
|
+
```typescript
|
|
82
|
+
const result = await CapacitorNativeUpdate.sync({
|
|
83
|
+
installMode?: 'IMMEDIATE' | 'ON_NEXT_RESTART' | 'ON_NEXT_RESUME';
|
|
84
|
+
minimumBackgroundDuration?: number; // Minimum background time (ms)
|
|
85
|
+
});
|
|
86
|
+
// Returns:
|
|
87
|
+
{
|
|
88
|
+
status: 'UP_TO_DATE' | 'UPDATE_AVAILABLE' | 'UPDATE_INSTALLED' | 'ERROR';
|
|
89
|
+
version?: string;
|
|
90
|
+
error?: { code: string; message: string; };
|
|
91
|
+
}
|
|
92
|
+
```
|
|
93
|
+
|
|
94
|
+
### getCurrentBundle()
|
|
95
|
+
|
|
96
|
+
Get information about the currently active bundle.
|
|
97
|
+
|
|
98
|
+
```typescript
|
|
99
|
+
const bundle = await CapacitorNativeUpdate.getCurrentBundle();
|
|
100
|
+
// Returns:
|
|
101
|
+
{
|
|
102
|
+
bundleId: string;
|
|
103
|
+
version: string;
|
|
104
|
+
path: string;
|
|
105
|
+
downloadTime: number;
|
|
106
|
+
size: number;
|
|
107
|
+
status: 'ACTIVE' | 'PENDING' | 'FAILED';
|
|
108
|
+
checksum: string;
|
|
109
|
+
verified: boolean;
|
|
110
|
+
}
|
|
111
|
+
```
|
|
112
|
+
|
|
113
|
+
### getBundles()
|
|
114
|
+
|
|
115
|
+
List all downloaded bundles.
|
|
116
|
+
|
|
117
|
+
```typescript
|
|
118
|
+
const result = await CapacitorNativeUpdate.getBundles();
|
|
119
|
+
// Returns:
|
|
120
|
+
{
|
|
121
|
+
bundles: Array<{
|
|
122
|
+
bundleId: string;
|
|
123
|
+
version: string;
|
|
124
|
+
status: string;
|
|
125
|
+
size: number;
|
|
126
|
+
downloadTime: number;
|
|
127
|
+
}>;
|
|
128
|
+
}
|
|
129
|
+
```
|
|
130
|
+
|
|
131
|
+
### setBundle(bundleId)
|
|
132
|
+
|
|
133
|
+
Set a specific bundle as active.
|
|
134
|
+
|
|
135
|
+
```typescript
|
|
136
|
+
await CapacitorNativeUpdate.setBundle(bundleId: string);
|
|
137
|
+
```
|
|
138
|
+
|
|
139
|
+
### deleteBundle(bundleId)
|
|
140
|
+
|
|
141
|
+
Delete a specific bundle or clean up old bundles.
|
|
142
|
+
|
|
143
|
+
```typescript
|
|
144
|
+
// Delete specific bundle
|
|
145
|
+
await CapacitorNativeUpdate.deleteBundle(bundleId: string);
|
|
146
|
+
|
|
147
|
+
// Or cleanup old bundles
|
|
148
|
+
await CapacitorNativeUpdate.deleteBundle({
|
|
149
|
+
keepVersions: number // Keep N most recent versions
|
|
150
|
+
});
|
|
151
|
+
```
|
|
152
|
+
|
|
153
|
+
### reset()
|
|
154
|
+
|
|
155
|
+
Reset to the original app bundle.
|
|
156
|
+
|
|
157
|
+
```typescript
|
|
158
|
+
await CapacitorNativeUpdate.reset();
|
|
159
|
+
```
|
|
160
|
+
|
|
161
|
+
### notifyAppReady()
|
|
162
|
+
|
|
163
|
+
Notify that the app has successfully started with the new bundle.
|
|
164
|
+
|
|
165
|
+
```typescript
|
|
166
|
+
await CapacitorNativeUpdate.notifyAppReady();
|
|
167
|
+
```
|
|
168
|
+
|
|
169
|
+
### pauseAutoUpdates()
|
|
170
|
+
|
|
171
|
+
Temporarily pause automatic update checks.
|
|
172
|
+
|
|
173
|
+
```typescript
|
|
174
|
+
await CapacitorNativeUpdate.pauseAutoUpdates();
|
|
175
|
+
```
|
|
176
|
+
|
|
177
|
+
### resumeAutoUpdates()
|
|
178
|
+
|
|
179
|
+
Resume automatic update checks.
|
|
180
|
+
|
|
181
|
+
```typescript
|
|
182
|
+
await CapacitorNativeUpdate.resumeAutoUpdates();
|
|
183
|
+
```
|
|
184
|
+
|
|
185
|
+
### setChannel(channel)
|
|
186
|
+
|
|
187
|
+
Change the update channel.
|
|
188
|
+
|
|
189
|
+
```typescript
|
|
190
|
+
await CapacitorNativeUpdate.setChannel(channel: string);
|
|
191
|
+
```
|
|
192
|
+
|
|
193
|
+
### setUpdateUrl(url)
|
|
194
|
+
|
|
195
|
+
Change the update server URL.
|
|
196
|
+
|
|
197
|
+
```typescript
|
|
198
|
+
await CapacitorNativeUpdate.setUpdateUrl(url: string);
|
|
199
|
+
```
|
|
200
|
+
|
|
201
|
+
### validateUpdate(options)
|
|
202
|
+
|
|
203
|
+
Validate a bundle's integrity.
|
|
204
|
+
|
|
205
|
+
```typescript
|
|
206
|
+
const result = await CapacitorNativeUpdate.validateUpdate({
|
|
207
|
+
bundlePath: string;
|
|
208
|
+
checksum: string;
|
|
209
|
+
signature?: string;
|
|
210
|
+
});
|
|
211
|
+
// Returns:
|
|
212
|
+
{
|
|
213
|
+
isValid: boolean;
|
|
214
|
+
details: {
|
|
215
|
+
checksumValid: boolean;
|
|
216
|
+
signatureValid?: boolean;
|
|
217
|
+
};
|
|
218
|
+
}
|
|
219
|
+
```
|
|
220
|
+
|
|
221
|
+
## Events
|
|
222
|
+
|
|
223
|
+
### updateStateChanged
|
|
224
|
+
|
|
225
|
+
Fired when update state changes.
|
|
226
|
+
|
|
227
|
+
```typescript
|
|
228
|
+
CapacitorNativeUpdate.addListener('updateStateChanged', (state) => {
|
|
229
|
+
console.log('State:', state.status);
|
|
230
|
+
// state.status: 'CHECKING' | 'DOWNLOADING' | 'READY' | 'FAILED'
|
|
231
|
+
});
|
|
232
|
+
```
|
|
233
|
+
|
|
234
|
+
### downloadProgress
|
|
235
|
+
|
|
236
|
+
Fired during bundle download.
|
|
237
|
+
|
|
238
|
+
```typescript
|
|
239
|
+
CapacitorNativeUpdate.addListener('downloadProgress', (progress) => {
|
|
240
|
+
console.log(`Progress: ${progress.percent}%`);
|
|
241
|
+
});
|
|
242
|
+
```
|
|
243
|
+
|
|
244
|
+
### error
|
|
245
|
+
|
|
246
|
+
Fired when an error occurs.
|
|
247
|
+
|
|
248
|
+
```typescript
|
|
249
|
+
CapacitorNativeUpdate.addListener('error', (error) => {
|
|
250
|
+
console.error('Update error:', error.code, error.message);
|
|
251
|
+
});
|
|
252
|
+
```
|
|
253
|
+
|
|
254
|
+
## Error Codes
|
|
255
|
+
|
|
256
|
+
| Code | Description |
|
|
257
|
+
|------|-------------|
|
|
258
|
+
| `NETWORK_ERROR` | Network connection failed |
|
|
259
|
+
| `DOWNLOAD_ERROR` | Bundle download failed |
|
|
260
|
+
| `CHECKSUM_ERROR` | Checksum validation failed |
|
|
261
|
+
| `SIGNATURE_ERROR` | Signature verification failed |
|
|
262
|
+
| `STORAGE_ERROR` | Insufficient storage space |
|
|
263
|
+
| `PARSE_ERROR` | Invalid bundle format |
|
|
264
|
+
| `VERSION_ERROR` | Invalid version format |
|
|
265
|
+
| `INSECURE_URL` | HTTP URL when HTTPS required |
|