native-update 1.0.2 → 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.
- package/dist/esm/core/plugin-manager.js +8 -3
- package/dist/esm/core/plugin-manager.js.map +1 -1
- package/dist/esm/definitions.d.ts +1 -1
- package/dist/esm/plugin.js +17 -3
- package/dist/esm/plugin.js.map +1 -1
- package/dist/plugin.cjs.js +1 -1
- package/dist/plugin.cjs.js.map +1 -1
- package/dist/plugin.esm.js +1 -1
- package/dist/plugin.esm.js.map +1 -1
- package/dist/plugin.js +1 -1
- package/dist/plugin.js.map +1 -1
- package/docs/APP_REVIEW_GUIDE.md +1 -1
- package/docs/LIVE_UPDATES_GUIDE.md +35 -35
- package/docs/MIGRATION.md +1 -1
- package/docs/NATIVE_UPDATES_GUIDE.md +8 -8
- package/docs/QUICK_START.md +41 -52
- package/docs/README.md +4 -5
- package/docs/api/app-update-api.md +18 -110
- package/docs/api/events-api.md +83 -334
- package/docs/api/live-update-api.md +35 -66
- package/docs/examples/advanced-scenarios.md +54 -84
- package/docs/examples/basic-usage.md +40 -38
- package/docs/guides/migration-from-codepush.md +9 -10
- package/docs/guides/testing-guide.md +26 -27
- package/package.json +1 -1
|
@@ -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.
|
|
13
|
+
const currentManifest = await NativeUpdate.current();
|
|
14
14
|
|
|
15
|
-
const result = await NativeUpdate.
|
|
16
|
-
|
|
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.
|
|
30
|
-
|
|
31
|
-
isDelta: true
|
|
26
|
+
const download = await NativeUpdate.download({
|
|
27
|
+
version: 'delta-version'
|
|
32
28
|
});
|
|
33
29
|
|
|
34
|
-
//
|
|
35
|
-
await NativeUpdate.
|
|
30
|
+
// Set the bundle as active
|
|
31
|
+
await NativeUpdate.set({
|
|
36
32
|
bundleId: download.bundleId,
|
|
37
|
-
|
|
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.
|
|
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.
|
|
86
|
-
|
|
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
|
-
//
|
|
114
|
-
await NativeUpdate.
|
|
115
|
-
|
|
116
|
-
|
|
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
|
-
//
|
|
138
|
-
const backup = await NativeUpdate.
|
|
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.
|
|
131
|
+
await NativeUpdate.set({
|
|
143
132
|
bundleId: 'new-update-id',
|
|
144
|
-
|
|
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
|
-
//
|
|
154
|
-
await NativeUpdate.
|
|
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.
|
|
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.
|
|
205
|
-
|
|
206
|
-
metadata: {
|
|
207
|
-
testId: config.testId,
|
|
208
|
-
variant
|
|
209
|
-
}
|
|
192
|
+
const download = await NativeUpdate.download({
|
|
193
|
+
version: variant
|
|
210
194
|
});
|
|
211
195
|
|
|
212
|
-
//
|
|
213
|
-
await NativeUpdate.
|
|
196
|
+
// Set the bundle as active
|
|
197
|
+
await NativeUpdate.set({
|
|
214
198
|
bundleId: download.bundleId,
|
|
215
|
-
|
|
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.
|
|
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.
|
|
269
|
-
|
|
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.
|
|
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.
|
|
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.
|
|
326
|
-
|
|
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.
|
|
334
|
-
|
|
335
|
-
|
|
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.
|
|
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.
|
|
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.
|
|
379
|
-
|
|
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.
|
|
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 [
|
|
409
|
-
- See the [API Reference](../api/
|
|
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.
|
|
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.
|
|
26
|
-
console.log(`Update available: ${result.version}`);
|
|
27
|
-
//
|
|
28
|
-
|
|
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(
|
|
36
|
-
// Download
|
|
37
|
-
const download = await NativeUpdate.
|
|
38
|
-
|
|
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
|
-
//
|
|
42
|
-
NativeUpdate.
|
|
43
|
-
|
|
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.
|
|
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.
|
|
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.
|
|
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.
|
|
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
|
-
//
|
|
176
|
-
NativeUpdate.addListener('
|
|
177
|
-
|
|
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
|
-
//
|
|
181
|
-
NativeUpdate.addListener('
|
|
182
|
-
console.log(`
|
|
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
|
-
//
|
|
186
|
-
NativeUpdate.addListener('
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
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
|
-
-
|
|
203
|
-
- Read the [API Reference](../api/
|
|
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
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
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() |
|
|
102
|
-
| getUpdateMetadata() |
|
|
103
|
-
| notifyAppReady() |
|
|
104
|
-
| restartApp() |
|
|
105
|
-
| clearUpdates() |
|
|
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.
|
|
58
|
+
const update = await NativeUpdate.sync();
|
|
59
59
|
|
|
60
|
-
//
|
|
61
|
-
if (update.
|
|
62
|
-
await NativeUpdate.
|
|
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.
|
|
128
|
-
|
|
129
|
-
|
|
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
|
-
//
|
|
179
|
-
const
|
|
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
|
-
|
|
186
|
-
|
|
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.
|
|
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.
|
|
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
|
-
|
|
209
|
-
|
|
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
|
-
//
|
|
221
|
-
await NativeUpdate.
|
|
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.
|
|
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
|
|
273
|
-
- [ ] Returns correct
|
|
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
|
+
"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",
|