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.
@@ -10,13 +10,10 @@ Minimize download sizes by only downloading changed files:
10
10
  import { NativeUpdate } from 'native-update';
11
11
 
12
12
  async function checkForDeltaUpdate() {
13
- const currentManifest = await NativeUpdate.getCurrentManifest();
13
+ const currentManifest = await NativeUpdate.current();
14
14
 
15
- const result = await NativeUpdate.checkForUpdate({
16
- updateUrl: 'https://your-update-server.com/api/check',
17
- currentVersion: currentManifest.version,
18
- currentChecksum: currentManifest.checksum,
19
- supportsDelta: true
15
+ const result = await NativeUpdate.sync({
16
+ installMode: 'ON_NEXT_RESTART'
20
17
  });
21
18
 
22
19
  if (result.updateAvailable && result.deltaAvailable) {
@@ -26,15 +23,15 @@ async function checkForDeltaUpdate() {
26
23
  }
27
24
 
28
25
  async function downloadDeltaUpdate(deltaUrl: string) {
29
- const download = await NativeUpdate.downloadUpdate({
30
- url: deltaUrl,
31
- isDelta: true
26
+ const download = await NativeUpdate.download({
27
+ version: 'delta-version'
32
28
  });
33
29
 
34
- // Apply delta patch
35
- await NativeUpdate.applyDelta({
30
+ // Set the bundle as active
31
+ await NativeUpdate.set({
36
32
  bundleId: download.bundleId,
37
- baseVersion: getCurrentVersion()
33
+ version: download.version,
34
+ checksum: download.checksum
38
35
  });
39
36
  }
40
37
  ```
@@ -63,9 +60,7 @@ async function switchToBetaChannel() {
63
60
  await setupUpdateChannel(UpdateChannel.BETA);
64
61
 
65
62
  // Check for updates in the new channel
66
- const result = await NativeUpdate.checkForUpdate({
67
- currentVersion: await getCurrentVersion()
68
- });
63
+ const result = await NativeUpdate.sync();
69
64
 
70
65
  if (result.updateAvailable) {
71
66
  console.log(`Beta update ${result.version} available`);
@@ -82,13 +77,8 @@ async function checkStagedUpdate() {
82
77
  const deviceId = await getDeviceId();
83
78
  const rolloutPercentage = hashDeviceId(deviceId) % 100;
84
79
 
85
- const result = await NativeUpdate.checkForUpdate({
86
- updateUrl: 'https://your-update-server.com/api/check',
87
- currentVersion: '1.0.0',
88
- metadata: {
89
- deviceId,
90
- rolloutGroup: rolloutPercentage
91
- }
80
+ const result = await NativeUpdate.sync({
81
+ installMode: 'ON_NEXT_RESTART'
92
82
  });
93
83
 
94
84
  if (result.updateAvailable && result.rolloutPercentage >= rolloutPercentage) {
@@ -110,11 +100,10 @@ async function setupBackgroundUpdates() {
110
100
  autoInstallMode: 'on-restart'
111
101
  });
112
102
 
113
- // Schedule background update checks
114
- await NativeUpdate.scheduleBackgroundCheck({
115
- interval: 14400000, // 4 hours
116
- requiresWifi: true,
117
- requiresCharging: false
103
+ // Configure automatic update checks
104
+ await NativeUpdate.configure({
105
+ checkInterval: 14400, // 4 hours in seconds
106
+ autoCheck: true
118
107
  });
119
108
  }
120
109
 
@@ -134,14 +123,15 @@ Implement automatic rollback on update failures:
134
123
 
135
124
  ```typescript
136
125
  async function safeUpdate() {
137
- // Save current version info before update
138
- const backup = await NativeUpdate.createBackup();
126
+ // Get current version info before update
127
+ const backup = await NativeUpdate.current();
139
128
 
140
129
  try {
141
130
  // Attempt update
142
- await NativeUpdate.installUpdate({
131
+ await NativeUpdate.set({
143
132
  bundleId: 'new-update-id',
144
- validateAfterInstall: true
133
+ version: 'new-version',
134
+ checksum: 'bundle-checksum'
145
135
  });
146
136
 
147
137
  // Verify update success
@@ -150,15 +140,13 @@ async function safeUpdate() {
150
140
  throw new Error('Health check failed');
151
141
  }
152
142
 
153
- // Confirm successful update
154
- await NativeUpdate.confirmUpdate();
143
+ // Notify app is ready with new bundle
144
+ await NativeUpdate.notifyAppReady();
155
145
  } catch (error) {
156
146
  console.error('Update failed, rolling back:', error);
157
147
 
158
148
  // Automatic rollback
159
- await NativeUpdate.rollback({
160
- backupId: backup.id
161
- });
149
+ await NativeUpdate.reset();
162
150
 
163
151
  // Report failure to analytics
164
152
  reportUpdateFailure(error);
@@ -201,18 +189,15 @@ async function setupABTest(config: ABTestConfig) {
201
189
  ? config.variants.treatment
202
190
  : config.variants.control;
203
191
 
204
- const download = await NativeUpdate.downloadUpdate({
205
- url: bundleUrl,
206
- metadata: {
207
- testId: config.testId,
208
- variant
209
- }
192
+ const download = await NativeUpdate.download({
193
+ version: variant
210
194
  });
211
195
 
212
- // Install with test metadata
213
- await NativeUpdate.installUpdate({
196
+ // Set the bundle as active
197
+ await NativeUpdate.set({
214
198
  bundleId: download.bundleId,
215
- preserveData: true
199
+ version: download.version,
200
+ checksum: download.checksum
216
201
  });
217
202
  }
218
203
  ```
@@ -227,10 +212,7 @@ class UpdateManager {
227
212
 
228
213
  async checkAndPromptUpdate() {
229
214
  // Check for update
230
- const result = await NativeUpdate.checkForUpdate({
231
- updateUrl: 'https://your-update-server.com/api/check',
232
- currentVersion: await this.getCurrentVersion()
233
- });
215
+ const result = await NativeUpdate.sync();
234
216
 
235
217
  if (!result.updateAvailable) return;
236
218
 
@@ -265,15 +247,17 @@ class UpdateManager {
265
247
  );
266
248
 
267
249
  try {
268
- const download = await NativeUpdate.downloadUpdate({
269
- url: updateInfo.downloadUrl
250
+ const download = await NativeUpdate.download({
251
+ version: updateInfo.version
270
252
  });
271
253
 
272
254
  this.updateState = { status: 'installing' };
273
255
  this.updateUI();
274
256
 
275
- await NativeUpdate.installUpdate({
276
- bundleId: download.bundleId
257
+ await NativeUpdate.set({
258
+ bundleId: download.bundleId,
259
+ version: download.version,
260
+ checksum: download.checksum
277
261
  });
278
262
 
279
263
  this.updateState = { status: 'ready' };
@@ -300,18 +284,7 @@ async function secureUpdateCheck() {
300
284
  version: getCurrentVersion()
301
285
  });
302
286
 
303
- const result = await NativeUpdate.checkForUpdate({
304
- updateUrl: 'https://your-update-server.com/api/check',
305
- currentVersion: getCurrentVersion(),
306
- headers: {
307
- 'X-Timestamp': timestamp.toString(),
308
- 'X-Nonce': nonce,
309
- 'X-Signature': signature
310
- },
311
- certificatePins: [
312
- 'sha256/AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA='
313
- ]
314
- });
287
+ const result = await NativeUpdate.sync();
315
288
 
316
289
  // Verify response signature
317
290
  if (!await verifyUpdateSignature(result)) {
@@ -322,20 +295,18 @@ async function secureUpdateCheck() {
322
295
  }
323
296
 
324
297
  async function downloadWithIntegrityCheck(url: string, expectedHash: string) {
325
- const download = await NativeUpdate.downloadUpdate({
326
- url,
327
- validateChecksum: true,
328
- expectedChecksum: expectedHash,
329
- algorithm: 'sha256'
298
+ const download = await NativeUpdate.download({
299
+ version: 'secure-version'
330
300
  });
331
301
 
332
302
  // Additional verification
333
- const verified = await NativeUpdate.verifyBundle({
334
- bundleId: download.bundleId,
335
- publicKey: await getPublicKey()
303
+ const verified = await NativeUpdate.validateUpdate({
304
+ bundlePath: download.path,
305
+ checksum: download.checksum,
306
+ signature: 'bundle-signature'
336
307
  });
337
308
 
338
- if (!verified.valid) {
309
+ if (!verified.isValid) {
339
310
  throw new Error('Bundle verification failed');
340
311
  }
341
312
 
@@ -362,10 +333,7 @@ class UpdateMetrics {
362
333
 
363
334
  try {
364
335
  // Check phase
365
- const result = await NativeUpdate.checkForUpdate({
366
- updateUrl: 'https://your-update-server.com/api/check',
367
- currentVersion: getCurrentVersion()
368
- });
336
+ const result = await NativeUpdate.sync();
369
337
 
370
338
  if (!result.updateAvailable) {
371
339
  metrics.checkCompleted = Date.now();
@@ -375,16 +343,18 @@ class UpdateMetrics {
375
343
 
376
344
  // Download phase
377
345
  metrics.downloadStarted = Date.now();
378
- const download = await NativeUpdate.downloadUpdate({
379
- url: result.downloadUrl
346
+ const download = await NativeUpdate.download({
347
+ version: result.version
380
348
  });
381
349
  metrics.downloadCompleted = Date.now();
382
350
  metrics.downloadSize = download.size;
383
351
 
384
352
  // Install phase
385
353
  metrics.installStarted = Date.now();
386
- await NativeUpdate.installUpdate({
387
- bundleId: download.bundleId
354
+ await NativeUpdate.set({
355
+ bundleId: download.bundleId,
356
+ version: download.version,
357
+ checksum: download.checksum
388
358
  });
389
359
  metrics.installCompleted = Date.now();
390
360
 
@@ -405,6 +375,6 @@ class UpdateMetrics {
405
375
 
406
376
  ## Next Steps
407
377
 
408
- - Review [Integration Examples](./integration-examples.md) for framework-specific implementations
409
- - See the [API Reference](../api/README.md) for detailed method documentation
378
+ - Review [Basic Usage](./basic-usage.md) for framework-specific implementations
379
+ - See the [API Reference](../api/live-update-api.md) for detailed method documentation
410
380
  - Check [Basic Usage](./basic-usage.md) for simpler examples
@@ -17,39 +17,36 @@ import { NativeUpdate } from 'native-update';
17
17
  // Check for updates on app startup
18
18
  async function checkForUpdates() {
19
19
  try {
20
- const result = await NativeUpdate.checkForUpdate({
21
- updateUrl: 'https://your-update-server.com/api/check',
22
- currentVersion: '1.0.0'
20
+ const result = await NativeUpdate.sync({
21
+ updateUrl: 'https://your-update-server.com/api/check'
23
22
  });
24
23
 
25
- if (result.updateAvailable) {
26
- console.log(`Update available: ${result.version}`);
27
- // Download and install the update
28
- await downloadAndInstall(result.downloadUrl);
24
+ if (result.status === 'UPDATE_AVAILABLE') {
25
+ console.log(`Update available: ${result.bundle?.version}`);
26
+ // Update will be downloaded and installed automatically
27
+ } else if (result.status === 'UPDATE_INSTALLED') {
28
+ // Reload the app to apply the update
29
+ await NativeUpdate.reload();
29
30
  }
30
31
  } catch (error) {
31
32
  console.error('Update check failed:', error);
32
33
  }
33
34
  }
34
35
 
35
- async function downloadAndInstall(downloadUrl: string) {
36
- // Download the update
37
- const download = await NativeUpdate.downloadUpdate({
38
- url: downloadUrl
36
+ async function downloadAndInstall(version: string) {
37
+ // Download a specific version
38
+ const download = await NativeUpdate.download({
39
+ version: version
39
40
  });
40
41
 
41
- // Monitor download progress
42
- NativeUpdate.addListener('downloadProgress', (progress) => {
43
- console.log(`Download progress: ${progress.percent}%`);
44
- });
45
-
46
- // Install the update
47
- await NativeUpdate.installUpdate({
48
- bundleId: download.bundleId
42
+ // Set the downloaded bundle as active
43
+ await NativeUpdate.set({
44
+ version: download.version,
45
+ checksum: download.checksum
49
46
  });
50
47
 
51
48
  // Reload the app with new bundle
52
- await NativeUpdate.reloadApp();
49
+ await NativeUpdate.reload();
53
50
  }
54
51
  ```
55
52
 
@@ -58,7 +55,7 @@ async function downloadAndInstall(downloadUrl: string) {
58
55
  ```typescript
59
56
  // Check if a native app update is available
60
57
  async function checkAppStoreUpdate() {
61
- const result = await NativeUpdate.checkAppUpdate();
58
+ const result = await NativeUpdate.getAppUpdateInfo();
62
59
 
63
60
  if (result.updateAvailable) {
64
61
  // Show update prompt to user
@@ -147,12 +144,11 @@ await NativeUpdate.configure({
147
144
  // Comprehensive error handling
148
145
  async function safeUpdateCheck() {
149
146
  try {
150
- const result = await NativeUpdate.checkForUpdate({
151
- updateUrl: 'https://your-update-server.com/api/check',
152
- currentVersion: '1.0.0'
147
+ const result = await NativeUpdate.sync({
148
+ updateUrl: 'https://your-update-server.com/api/check'
153
149
  });
154
150
 
155
- if (result.updateAvailable) {
151
+ if (result.status === 'UPDATE_AVAILABLE' || result.status === 'UPDATE_INSTALLED') {
156
152
  await handleUpdate(result);
157
153
  }
158
154
  } catch (error) {
@@ -172,21 +168,26 @@ async function safeUpdateCheck() {
172
168
  ```typescript
173
169
  // Set up event listeners
174
170
  function setupUpdateListeners() {
175
- // Download progress
176
- NativeUpdate.addListener('downloadProgress', (event) => {
177
- updateProgressBar(event.percent);
171
+ // Update state changes
172
+ NativeUpdate.addListener('updateStateChanged', (event) => {
173
+ console.log('Update state:', event.status);
174
+ if (event.status === 'READY') {
175
+ // Update has been applied successfully
176
+ console.log('Update ready to use');
177
+ }
178
178
  });
179
179
 
180
- // Update installed
181
- NativeUpdate.addListener('updateInstalled', (event) => {
182
- console.log(`Update ${event.version} installed successfully`);
180
+ // Download progress
181
+ NativeUpdate.addListener('downloadProgress', (progress) => {
182
+ console.log(`Download progress: ${progress.percent}%`);
183
+ console.log(`Speed: ${progress.bytesPerSecond} bytes/s`);
183
184
  });
184
185
 
185
- // Update failed
186
- NativeUpdate.addListener('updateFailed', (event) => {
187
- console.error(`Update failed: ${event.error}`);
188
- // Optionally rollback
189
- NativeUpdate.rollback();
186
+ // Background update notifications
187
+ NativeUpdate.addListener('backgroundUpdateNotification', (event) => {
188
+ if (event.updateAvailable) {
189
+ console.log(`Background update available: ${event.version}`);
190
+ }
190
191
  });
191
192
  }
192
193
 
@@ -199,5 +200,6 @@ function cleanup() {
199
200
  ## Next Steps
200
201
 
201
202
  - See [Advanced Scenarios](./advanced-scenarios.md) for more complex use cases
202
- - Check [Integration Examples](./integration-examples.md) for framework-specific implementations
203
- - Read the [API Reference](../api/README.md) for complete method documentation
203
+ - Read the [Live Update API Reference](../api/live-update-api.md) for complete live update methods
204
+ - Read the [App Update API Reference](../api/app-update-api.md) for native update methods
205
+ - Read the [App Review API Reference](../api/app-review-api.md) for review request methods
@@ -73,11 +73,10 @@ codePush.sync({
73
73
  });
74
74
 
75
75
  // New (Capacitor Native Update)
76
- const update = await NativeUpdate.checkForUpdate();
77
- if (update.available) {
78
- await NativeUpdate.downloadUpdate();
79
- await NativeUpdate.applyUpdate();
80
- }
76
+ const result = await NativeUpdate.sync({
77
+ installMode: 'IMMEDIATE'
78
+ });
79
+ // Sync handles check, download, and apply automatically
81
80
  ```
82
81
 
83
82
  ### 5. Bundle Creation
@@ -98,11 +97,11 @@ node tools/bundle-signer.js sign bundle.zip private-key.pem
98
97
 
99
98
  | CodePush Feature | Capacitor Native Update |
100
99
  |-----------------|------------------------|
101
- | sync() | checkForUpdate() + downloadUpdate() + applyUpdate() |
102
- | getUpdateMetadata() | getCurrentVersion() |
103
- | notifyAppReady() | confirmUpdate() |
104
- | restartApp() | applyUpdate() |
105
- | clearUpdates() | rollback() |
100
+ | sync() | sync() |
101
+ | getUpdateMetadata() | current() |
102
+ | notifyAppReady() | notifyAppReady() |
103
+ | restartApp() | reload() |
104
+ | clearUpdates() | reset() |
106
105
 
107
106
  ## Migration Checklist
108
107
 
@@ -55,12 +55,11 @@ src/__tests__/
55
55
  3. **Test Update Flow**
56
56
  ```typescript
57
57
  // Check for updates
58
- const update = await NativeUpdate.checkForUpdate();
58
+ const update = await NativeUpdate.sync();
59
59
 
60
- // Download if available
61
- if (update.available) {
62
- await NativeUpdate.downloadUpdate();
63
- await NativeUpdate.applyUpdate();
60
+ // Update will be downloaded and applied based on sync result
61
+ if (update.status === 'UPDATE_INSTALLED') {
62
+ await NativeUpdate.reload();
64
63
  }
65
64
  ```
66
65
 
@@ -124,10 +123,11 @@ try {
124
123
  node tools/bundle-signer.js sign test-bundle.zip private-key.pem
125
124
 
126
125
  # Verify in app
127
- const isValid = await NativeUpdate.verifySignature(
128
- bundleData,
129
- signature
130
- );
126
+ const isValid = await NativeUpdate.validateUpdate({
127
+ bundlePath: 'bundle-path',
128
+ checksum: 'bundle-checksum',
129
+ signature: signature
130
+ });
131
131
  ```
132
132
 
133
133
  ### 4. Performance Testing
@@ -175,18 +175,16 @@ NativeUpdate.addListener('downloadProgress', (progress) => {
175
175
  publicKey: 'your-public-key',
176
176
  });
177
177
 
178
- // Check
179
- const update = await NativeUpdate.checkForUpdate();
180
- if (!update.available) return;
181
-
182
- // Download with progress
183
- await NativeUpdate.downloadUpdate();
178
+ // Sync will check, download and apply update
179
+ const result = await NativeUpdate.sync();
184
180
 
185
- // Apply
186
- await NativeUpdate.applyUpdate();
181
+ if (result.status === 'UPDATE_INSTALLED') {
182
+ // Reload to apply update
183
+ await NativeUpdate.reload();
184
+ }
187
185
 
188
186
  // Verify
189
- const current = await NativeUpdate.getCurrentVersion();
187
+ const current = await NativeUpdate.current();
190
188
  console.log('Updated to:', current.version);
191
189
  }
192
190
  ```
@@ -196,7 +194,7 @@ NativeUpdate.addListener('downloadProgress', (progress) => {
196
194
  #### Network Failures
197
195
  ```typescript
198
196
  // Test offline behavior
199
- await NativeUpdate.checkForUpdate()
197
+ await NativeUpdate.sync()
200
198
  .catch(error => {
201
199
  expect(error.code).toBe('NETWORK_ERROR');
202
200
  });
@@ -205,8 +203,9 @@ await NativeUpdate.checkForUpdate()
205
203
  #### Corrupted Bundles
206
204
  ```typescript
207
205
  // Test checksum validation
208
- const corruptedBundle = await fetch('corrupted-bundle.zip');
209
- await NativeUpdate.applyUpdate(corruptedBundle)
206
+ await NativeUpdate.download({
207
+ version: 'corrupted-version'
208
+ })
210
209
  .catch(error => {
211
210
  expect(error.code).toBe('CHECKSUM_ERROR');
212
211
  });
@@ -217,15 +216,15 @@ await NativeUpdate.applyUpdate(corruptedBundle)
217
216
  ```typescript
218
217
  // Test rollback mechanism
219
218
  async function testRollback() {
220
- // Apply bad update
221
- await NativeUpdate.applyUpdate(badUpdate);
219
+ // Set bad update
220
+ await NativeUpdate.set(badUpdate);
222
221
 
223
222
  // Simulate app crash
224
223
  await simulateCrash();
225
224
 
226
225
  // Verify rollback on restart
227
- const version = await NativeUpdate.getCurrentVersion();
228
- expect(version).toBe(previousVersion);
226
+ const version = await NativeUpdate.current();
227
+ expect(version.version).toBe(previousVersion);
229
228
  }
230
229
  ```
231
230
 
@@ -269,8 +268,8 @@ jobs:
269
268
  - [ ] Invalid configs rejected
270
269
  - [ ] Channel switching works
271
270
 
272
- - [ ] **Update Check**
273
- - [ ] Returns correct update status
271
+ - [ ] **Update Sync**
272
+ - [ ] Returns correct sync status
274
273
  - [ ] Respects version constraints
275
274
  - [ ] Handles network errors
276
275
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "native-update",
3
- "version": "1.0.3",
3
+ "version": "1.0.4",
4
4
  "description": "Foundation package for building a comprehensive update system for Capacitor apps. Provides architecture and interfaces but requires backend implementation.",
5
5
  "type": "module",
6
6
  "main": "dist/plugin.cjs.js",