native-update 1.0.3 → 1.0.4

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.
@@ -64,388 +64,137 @@ NativeUpdate.addListener('downloadProgress', (progress) => {
64
64
  }
65
65
  ```
66
66
 
67
- ### updateInstalled
68
-
69
- Fired when an update has been successfully installed.
70
-
71
- ```typescript
72
- NativeUpdate.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
- NativeUpdate.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
- NativeUpdate.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
- NativeUpdate.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
- NativeUpdate.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
- NativeUpdate.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
- NativeUpdate.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
- NativeUpdate.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
67
  ## Background Update Events
251
68
 
252
- ### backgroundCheckStarted
69
+ ### backgroundUpdateProgress
253
70
 
254
- Fired when a background update check begins.
71
+ Fired during background update operations.
255
72
 
256
73
  ```typescript
257
- NativeUpdate.addListener('backgroundCheckStarted', (event) => {
258
- console.log('Background check started');
74
+ NativeUpdate.addListener('backgroundUpdateProgress', (event) => {
75
+ console.log('Background update status:', event.status);
259
76
  });
260
77
  ```
261
78
 
262
79
  **Event Data:**
263
80
  ```typescript
264
81
  {
265
- checkId: string;
266
- trigger: 'scheduled' | 'app-resume' | 'manual';
267
- timestamp: number;
82
+ type: BackgroundUpdateType;
83
+ status: 'checking' | 'downloading' | 'installing' | 'completed' | 'failed';
84
+ progress?: number;
85
+ error?: string;
268
86
  }
269
87
  ```
270
88
 
271
- ### backgroundCheckCompleted
89
+ ### backgroundUpdateNotification
272
90
 
273
- Fired when a background update check completes.
91
+ Fired when background update has a notification to show.
274
92
 
275
93
  ```typescript
276
- NativeUpdate.addListener('backgroundCheckCompleted', (result) => {
277
- console.log('Background check result:', result);
94
+ NativeUpdate.addListener('backgroundUpdateNotification', (event) => {
95
+ console.log('Update available:', event.updateAvailable);
278
96
  });
279
97
  ```
280
98
 
281
99
  **Event Data:**
282
100
  ```typescript
283
101
  {
284
- checkId: string;
102
+ type: BackgroundUpdateType;
285
103
  updateAvailable: boolean;
286
104
  version?: string;
287
- downloadStarted: boolean;
288
- duration: number; // Check duration in ms
289
- timestamp: number;
105
+ description?: string;
290
106
  }
291
107
  ```
292
108
 
293
- ### backgroundDownloadCompleted
109
+ ## Event Best Practices
294
110
 
295
- Fired when a background download completes.
111
+ ### 1. Always Remove Listeners
296
112
 
297
113
  ```typescript
298
- NativeUpdate.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
114
+ class UpdateManager {
115
+ private listeners: PluginListenerHandle[] = [];
318
116
 
319
- Generic error event for any plugin errors.
117
+ setupListeners() {
118
+ // Store listener references
119
+ this.listeners.push(
120
+ NativeUpdate.addListener('updateStateChanged', (state) => {
121
+ this.handleStateChange(state);
122
+ })
123
+ );
320
124
 
321
- ```typescript
322
- NativeUpdate.addListener('error', (error) => {
323
- console.error('Plugin error:', error);
324
- errorReporting.log(error);
325
- });
326
- ```
125
+ this.listeners.push(
126
+ NativeUpdate.addListener('downloadProgress', (progress) => {
127
+ this.updateProgressBar(progress.percent);
128
+ })
129
+ );
130
+ }
327
131
 
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;
132
+ cleanup() {
133
+ // Remove all listeners
134
+ this.listeners.forEach(listener => listener.remove());
135
+ this.listeners = [];
136
+ }
338
137
  }
339
138
  ```
340
139
 
341
- ## Analytics Events
342
-
343
- ### analyticsEvent
344
-
345
- Fired for analytics tracking.
346
-
347
- ```typescript
348
- NativeUpdate.addListener('analyticsEvent', (event) => {
349
- // Forward to your analytics provider
350
- analytics.track(event.name, event.properties);
351
- });
352
- ```
140
+ ### 2. Handle All States
353
141
 
354
- **Event Data:**
355
142
  ```typescript
356
- {
357
- name: string; // Event name
358
- properties: Record<string, any>;
359
- category: 'update' | 'review' | 'error' | 'performance';
360
- timestamp: number;
143
+ function handleStateChange(state: UpdateStateChangedEvent) {
144
+ switch (state.status) {
145
+ case 'CHECKING':
146
+ showLoader('Checking for updates...');
147
+ break;
148
+ case 'DOWNLOADING':
149
+ showLoader('Downloading update...');
150
+ break;
151
+ case 'READY':
152
+ hideLoader();
153
+ promptUserToRestart();
154
+ break;
155
+ case 'FAILED':
156
+ hideLoader();
157
+ showError('Update failed. Please try again.');
158
+ break;
159
+ case 'INSTALLING':
160
+ showLoader('Installing update...');
161
+ break;
162
+ }
361
163
  }
362
164
  ```
363
165
 
364
- ## Best Practices
365
-
366
- ### 1. Centralized Event Handling
166
+ ### 3. Progress Updates
367
167
 
368
168
  ```typescript
369
- class UpdateEventManager {
370
- private listeners: PluginListenerHandle[] = [];
371
-
372
- init() {
373
- // Register all listeners
374
- this.listeners.push(
375
- NativeUpdate.addListener('updateStateChanged', this.handleStateChange),
376
- NativeUpdate.addListener('downloadProgress', this.handleProgress),
377
- NativeUpdate.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);
169
+ function setupProgressTracking() {
170
+ let lastUpdate = 0;
171
+
172
+ NativeUpdate.addListener('downloadProgress', (progress) => {
173
+ // Update UI at most once per second
174
+ const now = Date.now();
175
+ if (now - lastUpdate > 1000) {
176
+ updateUI({
177
+ percent: progress.percent,
178
+ speed: formatBytes(progress.bytesPerSecond) + '/s',
179
+ remaining: formatTime(progress.estimatedTime)
180
+ });
181
+ lastUpdate = now;
401
182
  }
402
- errorReporter.log(error);
403
- };
183
+ });
404
184
  }
405
185
  ```
406
186
 
407
- ### 2. Event-Driven UI Updates
187
+ ## Platform-Specific Notes
408
188
 
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
- NativeUpdate.addListener('updateStateChanged', (event) => {
418
- setState(event.status);
419
- }),
420
- NativeUpdate.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
- ```
189
+ ### iOS
190
+ - All events are supported
191
+ - Review events may not fire if StoreKit decides not to show the prompt
433
192
 
434
- ### 3. Analytics Integration
193
+ ### Android
194
+ - All events are supported
195
+ - App update events only fire when using Google Play
435
196
 
436
- ```typescript
437
- // Set up analytics forwarding
438
- NativeUpdate.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
- ```
197
+ ### Web
198
+ - Limited event support
199
+ - No native app update events
200
+ - Review events will not fire
@@ -25,36 +25,30 @@ await NativeUpdate.configure({
25
25
  });
26
26
  ```
27
27
 
28
- ### checkForUpdate()
28
+ ### sync()
29
29
 
30
- Check if a new update is available.
30
+ Sync with update server and apply updates based on strategy.
31
31
 
32
32
  ```typescript
33
- const result = await NativeUpdate.checkForUpdate();
33
+ const result = await NativeUpdate.sync({
34
+ installMode?: 'IMMEDIATE' | 'ON_NEXT_RESTART' | 'ON_NEXT_RESUME';
35
+ minimumBackgroundDuration?: number; // Minimum background time (ms)
36
+ });
34
37
  // Returns:
35
38
  {
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
39
+ status: 'UP_TO_DATE' | 'UPDATE_AVAILABLE' | 'UPDATE_INSTALLED' | 'ERROR';
40
+ bundle?: BundleInfo; // Bundle information if update available/installed
41
+ error?: { code: string; message: string; };
44
42
  }
45
43
  ```
46
44
 
47
- ### downloadUpdate(options?)
45
+ ### download(options)
48
46
 
49
- Download an available update with progress tracking.
47
+ Download a specific bundle version.
50
48
 
51
49
  ```typescript
52
- const result = await NativeUpdate.downloadUpdate({
53
- onProgress?: (progress: {
54
- percent: number; // 0-100
55
- bytesDownloaded: number;
56
- totalBytes: number;
57
- }) => void;
50
+ const result = await NativeUpdate.download({
51
+ version: string; // Version to download
58
52
  });
59
53
  // Returns:
60
54
  {
@@ -62,41 +56,36 @@ const result = await NativeUpdate.downloadUpdate({
62
56
  version: string; // Bundle version
63
57
  path: string; // Local path
64
58
  size: number; // File size
65
- downloadTime: number; // Download duration (ms)
59
+ checksum: string; // SHA-256 checksum
66
60
  }
67
61
  ```
68
62
 
69
- ### applyUpdate()
63
+ ### set(bundle)
70
64
 
71
- Apply a downloaded update (restarts the app).
65
+ Set the active bundle.
72
66
 
73
67
  ```typescript
74
- await NativeUpdate.applyUpdate();
68
+ await NativeUpdate.set({
69
+ bundleId: string;
70
+ version: string;
71
+ checksum: string;
72
+ });
75
73
  ```
76
74
 
77
- ### sync(options?)
75
+ ### reload()
78
76
 
79
- Sync with server and apply updates based on strategy.
77
+ Reload the app with current bundle.
80
78
 
81
79
  ```typescript
82
- const result = await NativeUpdate.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
- }
80
+ await NativeUpdate.reload();
92
81
  ```
93
82
 
94
- ### getCurrentBundle()
83
+ ### current()
95
84
 
96
- Get information about the currently active bundle.
85
+ Get current bundle info.
97
86
 
98
87
  ```typescript
99
- const bundle = await NativeUpdate.getCurrentBundle();
88
+ const bundle = await NativeUpdate.current();
100
89
  // Returns:
101
90
  {
102
91
  bundleId: string;
@@ -110,43 +99,23 @@ const bundle = await NativeUpdate.getCurrentBundle();
110
99
  }
111
100
  ```
112
101
 
113
- ### getBundles()
102
+ ### list()
114
103
 
115
104
  List all downloaded bundles.
116
105
 
117
106
  ```typescript
118
- const result = await NativeUpdate.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 NativeUpdate.setBundle(bundleId: string);
107
+ const bundles = await NativeUpdate.list();
108
+ // Returns: Array<BundleInfo>
137
109
  ```
138
110
 
139
- ### deleteBundle(bundleId)
111
+ ### delete(options)
140
112
 
141
- Delete a specific bundle or clean up old bundles.
113
+ Delete bundles.
142
114
 
143
115
  ```typescript
144
- // Delete specific bundle
145
- await NativeUpdate.deleteBundle(bundleId: string);
146
-
147
- // Or cleanup old bundles
148
- await NativeUpdate.deleteBundle({
149
- keepVersions: number // Keep N most recent versions
116
+ await NativeUpdate.delete({
117
+ bundleId?: string; // Delete specific bundle
118
+ keepLatest?: number; // Keep N most recent versions
150
119
  });
151
120
  ```
152
121