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.
Files changed (184) hide show
  1. package/CapacitorNativeUpdate.podspec +18 -0
  2. package/LICENSE +21 -0
  3. package/Readme.md +451 -0
  4. package/android/build.gradle +92 -0
  5. package/android/gradle/wrapper/gradle-wrapper.properties +8 -0
  6. package/android/gradle.properties +17 -0
  7. package/android/proguard-rules.pro +29 -0
  8. package/android/settings.gradle +2 -0
  9. package/android/src/main/AndroidManifest.xml +34 -0
  10. package/android/src/main/java/com/aoneahsan/nativeupdate/AppReviewPlugin.kt +153 -0
  11. package/android/src/main/java/com/aoneahsan/nativeupdate/AppUpdatePlugin.kt +275 -0
  12. package/android/src/main/java/com/aoneahsan/nativeupdate/BackgroundNotificationManager.kt +390 -0
  13. package/android/src/main/java/com/aoneahsan/nativeupdate/BackgroundUpdateManager.kt +46 -0
  14. package/android/src/main/java/com/aoneahsan/nativeupdate/BackgroundUpdatePlugin.kt +333 -0
  15. package/android/src/main/java/com/aoneahsan/nativeupdate/BackgroundUpdateWorker.kt +251 -0
  16. package/android/src/main/java/com/aoneahsan/nativeupdate/CapacitorNativeUpdatePlugin.kt +265 -0
  17. package/android/src/main/java/com/aoneahsan/nativeupdate/LiveUpdatePlugin.kt +526 -0
  18. package/android/src/main/java/com/aoneahsan/nativeupdate/NotificationActionReceiver.kt +99 -0
  19. package/android/src/main/java/com/aoneahsan/nativeupdate/SecurityManager.kt +249 -0
  20. package/dist/esm/__tests__/bundle-manager.test.d.ts +1 -0
  21. package/dist/esm/__tests__/bundle-manager.test.js +123 -0
  22. package/dist/esm/__tests__/bundle-manager.test.js.map +1 -0
  23. package/dist/esm/__tests__/config.test.d.ts +1 -0
  24. package/dist/esm/__tests__/config.test.js +69 -0
  25. package/dist/esm/__tests__/config.test.js.map +1 -0
  26. package/dist/esm/__tests__/integration.test.d.ts +1 -0
  27. package/dist/esm/__tests__/integration.test.js +78 -0
  28. package/dist/esm/__tests__/integration.test.js.map +1 -0
  29. package/dist/esm/__tests__/security.test.d.ts +1 -0
  30. package/dist/esm/__tests__/security.test.js +54 -0
  31. package/dist/esm/__tests__/security.test.js.map +1 -0
  32. package/dist/esm/__tests__/version-manager.test.d.ts +1 -0
  33. package/dist/esm/__tests__/version-manager.test.js +45 -0
  34. package/dist/esm/__tests__/version-manager.test.js.map +1 -0
  35. package/dist/esm/app-review/app-review-manager.d.ts +24 -0
  36. package/dist/esm/app-review/app-review-manager.js +195 -0
  37. package/dist/esm/app-review/app-review-manager.js.map +1 -0
  38. package/dist/esm/app-review/index.d.ts +5 -0
  39. package/dist/esm/app-review/index.js +6 -0
  40. package/dist/esm/app-review/index.js.map +1 -0
  41. package/dist/esm/app-review/platform-review-handler.d.ts +20 -0
  42. package/dist/esm/app-review/platform-review-handler.js +138 -0
  43. package/dist/esm/app-review/platform-review-handler.js.map +1 -0
  44. package/dist/esm/app-review/review-conditions-checker.d.ts +22 -0
  45. package/dist/esm/app-review/review-conditions-checker.js +155 -0
  46. package/dist/esm/app-review/review-conditions-checker.js.map +1 -0
  47. package/dist/esm/app-review/review-rate-limiter.d.ts +23 -0
  48. package/dist/esm/app-review/review-rate-limiter.js +164 -0
  49. package/dist/esm/app-review/review-rate-limiter.js.map +1 -0
  50. package/dist/esm/app-review/types.d.ts +41 -0
  51. package/dist/esm/app-review/types.js +2 -0
  52. package/dist/esm/app-review/types.js.map +1 -0
  53. package/dist/esm/app-update/app-update-checker.d.ts +13 -0
  54. package/dist/esm/app-update/app-update-checker.js +104 -0
  55. package/dist/esm/app-update/app-update-checker.js.map +1 -0
  56. package/dist/esm/app-update/app-update-installer.d.ts +19 -0
  57. package/dist/esm/app-update/app-update-installer.js +123 -0
  58. package/dist/esm/app-update/app-update-installer.js.map +1 -0
  59. package/dist/esm/app-update/app-update-manager.d.ts +28 -0
  60. package/dist/esm/app-update/app-update-manager.js +199 -0
  61. package/dist/esm/app-update/app-update-manager.js.map +1 -0
  62. package/dist/esm/app-update/app-update-notifier.d.ts +14 -0
  63. package/dist/esm/app-update/app-update-notifier.js +100 -0
  64. package/dist/esm/app-update/app-update-notifier.js.map +1 -0
  65. package/dist/esm/app-update/index.d.ts +6 -0
  66. package/dist/esm/app-update/index.js +7 -0
  67. package/dist/esm/app-update/index.js.map +1 -0
  68. package/dist/esm/app-update/platform-app-update.d.ts +19 -0
  69. package/dist/esm/app-update/platform-app-update.js +129 -0
  70. package/dist/esm/app-update/platform-app-update.js.map +1 -0
  71. package/dist/esm/app-update/types.d.ts +58 -0
  72. package/dist/esm/app-update/types.js +12 -0
  73. package/dist/esm/app-update/types.js.map +1 -0
  74. package/dist/esm/background-update/background-scheduler.d.ts +17 -0
  75. package/dist/esm/background-update/background-scheduler.js +195 -0
  76. package/dist/esm/background-update/background-scheduler.js.map +1 -0
  77. package/dist/esm/background-update/index.d.ts +3 -0
  78. package/dist/esm/background-update/index.js +3 -0
  79. package/dist/esm/background-update/index.js.map +1 -0
  80. package/dist/esm/background-update/notification-manager.d.ts +29 -0
  81. package/dist/esm/background-update/notification-manager.js +89 -0
  82. package/dist/esm/background-update/notification-manager.js.map +1 -0
  83. package/dist/esm/core/analytics.d.ts +70 -0
  84. package/dist/esm/core/analytics.js +137 -0
  85. package/dist/esm/core/analytics.js.map +1 -0
  86. package/dist/esm/core/cache-manager.d.ts +72 -0
  87. package/dist/esm/core/cache-manager.js +275 -0
  88. package/dist/esm/core/cache-manager.js.map +1 -0
  89. package/dist/esm/core/config.d.ts +48 -0
  90. package/dist/esm/core/config.js +83 -0
  91. package/dist/esm/core/config.js.map +1 -0
  92. package/dist/esm/core/errors.d.ts +51 -0
  93. package/dist/esm/core/errors.js +80 -0
  94. package/dist/esm/core/errors.js.map +1 -0
  95. package/dist/esm/core/logger.d.ts +21 -0
  96. package/dist/esm/core/logger.js +109 -0
  97. package/dist/esm/core/logger.js.map +1 -0
  98. package/dist/esm/core/performance.d.ts +53 -0
  99. package/dist/esm/core/performance.js +140 -0
  100. package/dist/esm/core/performance.js.map +1 -0
  101. package/dist/esm/core/plugin-manager.d.ts +66 -0
  102. package/dist/esm/core/plugin-manager.js +148 -0
  103. package/dist/esm/core/plugin-manager.js.map +1 -0
  104. package/dist/esm/core/security.d.ts +93 -0
  105. package/dist/esm/core/security.js +315 -0
  106. package/dist/esm/core/security.js.map +1 -0
  107. package/dist/esm/definitions.d.ts +639 -0
  108. package/dist/esm/definitions.js +103 -0
  109. package/dist/esm/definitions.js.map +1 -0
  110. package/dist/esm/index.d.ts +12 -0
  111. package/dist/esm/index.js +16 -0
  112. package/dist/esm/index.js.map +1 -0
  113. package/dist/esm/live-update/bundle-manager.d.ts +94 -0
  114. package/dist/esm/live-update/bundle-manager.js +310 -0
  115. package/dist/esm/live-update/bundle-manager.js.map +1 -0
  116. package/dist/esm/live-update/certificate-pinning.d.ts +38 -0
  117. package/dist/esm/live-update/certificate-pinning.js +78 -0
  118. package/dist/esm/live-update/certificate-pinning.js.map +1 -0
  119. package/dist/esm/live-update/download-manager.d.ts +67 -0
  120. package/dist/esm/live-update/download-manager.js +319 -0
  121. package/dist/esm/live-update/download-manager.js.map +1 -0
  122. package/dist/esm/live-update/update-manager.d.ts +52 -0
  123. package/dist/esm/live-update/update-manager.js +294 -0
  124. package/dist/esm/live-update/update-manager.js.map +1 -0
  125. package/dist/esm/live-update/version-manager.d.ts +84 -0
  126. package/dist/esm/live-update/version-manager.js +335 -0
  127. package/dist/esm/live-update/version-manager.js.map +1 -0
  128. package/dist/esm/plugin.d.ts +6 -0
  129. package/dist/esm/plugin.js +283 -0
  130. package/dist/esm/plugin.js.map +1 -0
  131. package/dist/esm/security/crypto.d.ts +25 -0
  132. package/dist/esm/security/crypto.js +70 -0
  133. package/dist/esm/security/crypto.js.map +1 -0
  134. package/dist/esm/security/validator.d.ts +60 -0
  135. package/dist/esm/security/validator.js +143 -0
  136. package/dist/esm/security/validator.js.map +1 -0
  137. package/dist/esm/web.d.ts +74 -0
  138. package/dist/esm/web.js +595 -0
  139. package/dist/esm/web.js.map +1 -0
  140. package/dist/plugin.cjs.js +2 -0
  141. package/dist/plugin.cjs.js.map +1 -0
  142. package/dist/plugin.esm.js +2 -0
  143. package/dist/plugin.esm.js.map +1 -0
  144. package/dist/plugin.js +3 -0
  145. package/dist/plugin.js.map +1 -0
  146. package/docs/APP_REVIEW_GUIDE.md +768 -0
  147. package/docs/BUNDLE_SIGNING.md +264 -0
  148. package/docs/LIVE_UPDATES_GUIDE.md +650 -0
  149. package/docs/MIGRATION.md +192 -0
  150. package/docs/NATIVE_UPDATES_GUIDE.md +694 -0
  151. package/docs/QUICK_START.md +606 -0
  152. package/docs/README.md +111 -0
  153. package/docs/REMAINING_FEATURES.md +139 -0
  154. package/docs/api/app-review-api.md +259 -0
  155. package/docs/api/app-update-api.md +238 -0
  156. package/docs/api/events-api.md +451 -0
  157. package/docs/api/live-update-api.md +265 -0
  158. package/docs/background-updates.md +392 -0
  159. package/docs/examples/advanced-scenarios.md +410 -0
  160. package/docs/examples/basic-usage.md +185 -0
  161. package/docs/features/app-reviews.md +975 -0
  162. package/docs/features/app-updates.md +785 -0
  163. package/docs/features/live-updates.md +633 -0
  164. package/docs/getting-started/configuration.md +468 -0
  165. package/docs/getting-started/installation.md +209 -0
  166. package/docs/getting-started/quick-start.md +379 -0
  167. package/docs/guides/deployment-guide.md +333 -0
  168. package/docs/guides/migration-from-codepush.md +142 -0
  169. package/docs/guides/security-best-practices.md +1057 -0
  170. package/docs/guides/testing-guide.md +373 -0
  171. package/docs/production-readiness.md +478 -0
  172. package/docs/security/certificate-pinning.md +122 -0
  173. package/docs/server-requirements.md +147 -0
  174. package/ios/Plugin/AppReview/AppReviewPlugin.swift +158 -0
  175. package/ios/Plugin/AppUpdate/AppUpdatePlugin.swift +234 -0
  176. package/ios/Plugin/BackgroundUpdate/BackgroundNotificationManager.swift +329 -0
  177. package/ios/Plugin/BackgroundUpdate/BackgroundUpdatePlugin.swift +396 -0
  178. package/ios/Plugin/CapacitorNativeUpdatePlugin.m +45 -0
  179. package/ios/Plugin/CapacitorNativeUpdatePlugin.swift +190 -0
  180. package/ios/Plugin/Info.plist +43 -0
  181. package/ios/Plugin/LiveUpdate/LiveUpdatePlugin.swift +689 -0
  182. package/ios/Plugin/LiveUpdate/WebViewConfiguration.swift +45 -0
  183. package/ios/Plugin/Security/SecurityManager.swift +289 -0
  184. package/package.json +90 -0
@@ -0,0 +1,373 @@
1
+ # Comprehensive Testing Guide
2
+
3
+ This guide covers all testing approaches for the Capacitor Native Update plugin.
4
+
5
+ ## Testing Levels
6
+
7
+ ### 1. Unit Testing
8
+
9
+ The plugin includes unit tests for core functionality:
10
+
11
+ ```bash
12
+ # Run all tests
13
+ npm test
14
+
15
+ # Run with coverage
16
+ npm run test:coverage
17
+
18
+ # Watch mode for development
19
+ npm run test:watch
20
+ ```
21
+
22
+ #### Test Structure
23
+
24
+ ```
25
+ src/__tests__/
26
+ ├── security.test.ts # Security validation tests
27
+ ├── version-manager.test.ts # Version comparison tests
28
+ ├── bundle-manager.test.ts # Bundle management tests
29
+ ├── config.test.ts # Configuration tests
30
+ └── integration.test.ts # Integration tests
31
+ ```
32
+
33
+ ### 2. Integration Testing
34
+
35
+ #### Web Platform Testing
36
+
37
+ 1. **Setup Test Environment**
38
+ ```bash
39
+ # Start the test server
40
+ cd production-backend
41
+ npm install
42
+ npm run db:init
43
+ npm start
44
+ ```
45
+
46
+ 2. **Configure Plugin**
47
+ ```typescript
48
+ await CapacitorNativeUpdate.configure({
49
+ serverUrl: 'http://localhost:3000',
50
+ channel: 'development',
51
+ autoCheck: true,
52
+ });
53
+ ```
54
+
55
+ 3. **Test Update Flow**
56
+ ```typescript
57
+ // Check for updates
58
+ const update = await CapacitorNativeUpdate.checkForUpdate();
59
+
60
+ // Download if available
61
+ if (update.available) {
62
+ await CapacitorNativeUpdate.downloadUpdate();
63
+ await CapacitorNativeUpdate.applyUpdate();
64
+ }
65
+ ```
66
+
67
+ #### iOS Testing
68
+
69
+ 1. **Simulator Testing**
70
+ ```bash
71
+ # Build and run in iOS simulator
72
+ npx cap sync ios
73
+ npx cap run ios
74
+ ```
75
+
76
+ 2. **Device Testing**
77
+ - Connect iOS device
78
+ - Enable developer mode
79
+ - Run via Xcode
80
+
81
+ 3. **Test Cases**
82
+ - HTTPS enforcement
83
+ - Bundle download progress
84
+ - Checksum validation
85
+ - App store redirect
86
+
87
+ #### Android Testing
88
+
89
+ 1. **Emulator Testing**
90
+ ```bash
91
+ # Build and run in Android emulator
92
+ npx cap sync android
93
+ npx cap run android
94
+ ```
95
+
96
+ 2. **Device Testing**
97
+ - Enable USB debugging
98
+ - Connect Android device
99
+ - Run via Android Studio
100
+
101
+ 3. **Test Cases**
102
+ - Permission handling
103
+ - Background updates
104
+ - In-app update UI
105
+ - Rollback functionality
106
+
107
+ ### 3. Security Testing
108
+
109
+ #### Certificate Validation
110
+ ```typescript
111
+ // Test HTTPS enforcement
112
+ try {
113
+ await CapacitorNativeUpdate.configure({
114
+ serverUrl: 'http://insecure.com', // Should fail
115
+ });
116
+ } catch (error) {
117
+ console.log('HTTPS enforcement working');
118
+ }
119
+ ```
120
+
121
+ #### Signature Verification
122
+ ```bash
123
+ # Create signed bundle
124
+ node tools/bundle-signer.js sign test-bundle.zip private-key.pem
125
+
126
+ # Verify in app
127
+ const isValid = await CapacitorNativeUpdate.verifySignature(
128
+ bundleData,
129
+ signature
130
+ );
131
+ ```
132
+
133
+ ### 4. Performance Testing
134
+
135
+ #### Download Performance
136
+ ```typescript
137
+ // Monitor download speed
138
+ CapacitorNativeUpdate.addListener('downloadProgress', (progress) => {
139
+ console.log(`Speed: ${progress.speed} MB/s`);
140
+ console.log(`Progress: ${progress.percent}%`);
141
+ });
142
+ ```
143
+
144
+ #### Memory Usage
145
+ - Monitor app memory during updates
146
+ - Test with large bundles (50MB+)
147
+ - Verify cleanup of old bundles
148
+
149
+ ### 5. End-to-End Testing
150
+
151
+ #### Complete Update Cycle
152
+
153
+ 1. **Prepare Test Bundle**
154
+ ```bash
155
+ # Create bundle
156
+ node tools/bundle-creator.js create ./www
157
+
158
+ # Sign bundle
159
+ node tools/bundle-signer.js sign bundle.zip private-key.pem
160
+
161
+ # Upload to server
162
+ curl -X POST http://localhost:3000/api/updates/upload/update-id \
163
+ -H "Authorization: ApiKey your-api-key" \
164
+ -F "bundle=@bundle.zip" \
165
+ -F "signature=@bundle.sig"
166
+ ```
167
+
168
+ 2. **Test Update Flow**
169
+ ```typescript
170
+ // Full update test
171
+ async function testCompleteUpdate() {
172
+ // Configure
173
+ await CapacitorNativeUpdate.configure({
174
+ serverUrl: 'https://your-server.com',
175
+ publicKey: 'your-public-key',
176
+ });
177
+
178
+ // Check
179
+ const update = await CapacitorNativeUpdate.checkForUpdate();
180
+ if (!update.available) return;
181
+
182
+ // Download with progress
183
+ await CapacitorNativeUpdate.downloadUpdate();
184
+
185
+ // Apply
186
+ await CapacitorNativeUpdate.applyUpdate();
187
+
188
+ // Verify
189
+ const current = await CapacitorNativeUpdate.getCurrentVersion();
190
+ console.log('Updated to:', current.version);
191
+ }
192
+ ```
193
+
194
+ ### 6. Error Handling Testing
195
+
196
+ #### Network Failures
197
+ ```typescript
198
+ // Test offline behavior
199
+ await CapacitorNativeUpdate.checkForUpdate()
200
+ .catch(error => {
201
+ expect(error.code).toBe('NETWORK_ERROR');
202
+ });
203
+ ```
204
+
205
+ #### Corrupted Bundles
206
+ ```typescript
207
+ // Test checksum validation
208
+ const corruptedBundle = await fetch('corrupted-bundle.zip');
209
+ await CapacitorNativeUpdate.applyUpdate(corruptedBundle)
210
+ .catch(error => {
211
+ expect(error.code).toBe('CHECKSUM_ERROR');
212
+ });
213
+ ```
214
+
215
+ ### 7. Rollback Testing
216
+
217
+ ```typescript
218
+ // Test rollback mechanism
219
+ async function testRollback() {
220
+ // Apply bad update
221
+ await CapacitorNativeUpdate.applyUpdate(badUpdate);
222
+
223
+ // Simulate app crash
224
+ await simulateCrash();
225
+
226
+ // Verify rollback on restart
227
+ const version = await CapacitorNativeUpdate.getCurrentVersion();
228
+ expect(version).toBe(previousVersion);
229
+ }
230
+ ```
231
+
232
+ ### 8. Platform-Specific Testing
233
+
234
+ #### iOS Specific
235
+ - Test with different iOS versions (13+)
236
+ - Verify App Store redirect
237
+ - Test StoreKit integration
238
+ - Check background fetch
239
+
240
+ #### Android Specific
241
+ - Test with different Android versions (5.0+)
242
+ - Verify Play Core integration
243
+ - Test notification permissions
244
+ - Check WorkManager scheduling
245
+
246
+ ### 9. Automated Testing
247
+
248
+ #### CI/CD Integration
249
+ ```yaml
250
+ # .github/workflows/test.yml
251
+ name: Test
252
+ on: [push, pull_request]
253
+
254
+ jobs:
255
+ test:
256
+ runs-on: ubuntu-latest
257
+ steps:
258
+ - uses: actions/checkout@v2
259
+ - uses: actions/setup-node@v2
260
+ - run: npm install
261
+ - run: npm test
262
+ - run: npm run test:e2e
263
+ ```
264
+
265
+ ### 10. Manual Testing Checklist
266
+
267
+ - [ ] **Configuration**
268
+ - [ ] Valid HTTPS URL required
269
+ - [ ] Invalid configs rejected
270
+ - [ ] Channel switching works
271
+
272
+ - [ ] **Update Check**
273
+ - [ ] Returns correct update status
274
+ - [ ] Respects version constraints
275
+ - [ ] Handles network errors
276
+
277
+ - [ ] **Download**
278
+ - [ ] Progress updates work
279
+ - [ ] Pause/resume functionality
280
+ - [ ] Checksum validation
281
+ - [ ] Signature verification
282
+
283
+ - [ ] **Installation**
284
+ - [ ] Update applies correctly
285
+ - [ ] App restarts properly
286
+ - [ ] Rollback on failure
287
+
288
+ - [ ] **Native Updates**
289
+ - [ ] App store redirect works
290
+ - [ ] Version comparison accurate
291
+ - [ ] Update UI displays correctly
292
+
293
+ - [ ] **App Reviews**
294
+ - [ ] Review prompt appears
295
+ - [ ] Rate limiting works
296
+ - [ ] Platform APIs called correctly
297
+
298
+ ## Testing Tools
299
+
300
+ ### Bundle Testing
301
+ ```bash
302
+ # Create test bundle
303
+ node tools/bundle-creator.js create ./test-www
304
+
305
+ # Verify bundle
306
+ unzip -t test-bundle.zip
307
+
308
+ # Check signature
309
+ openssl dgst -sha256 -verify public-key.pem -signature bundle.sig bundle.zip
310
+ ```
311
+
312
+ ### Server Testing
313
+ ```bash
314
+ # Test update check
315
+ curl http://localhost:3000/api/updates/check/com.example.app/web/1.0.0
316
+
317
+ # Test analytics
318
+ curl -X POST http://localhost:3000/api/analytics/event \
319
+ -H "Content-Type: application/json" \
320
+ -d '{"appId":"com.example.app","eventType":"update_check"}'
321
+ ```
322
+
323
+ ### Load Testing
324
+ ```bash
325
+ # Install artillery
326
+ npm install -g artillery
327
+
328
+ # Run load test
329
+ artillery quick --count 100 --num 10 \
330
+ http://localhost:3000/api/updates/check/app/web/1.0.0
331
+ ```
332
+
333
+ ## Debugging
334
+
335
+ ### Enable Debug Logging
336
+ ```typescript
337
+ CapacitorNativeUpdate.configure({
338
+ debug: true,
339
+ logLevel: 'verbose',
340
+ });
341
+ ```
342
+
343
+ ### Native Platform Debugging
344
+
345
+ **iOS:**
346
+ - Use Xcode console
347
+ - Enable network debugging
348
+ - Check device logs
349
+
350
+ **Android:**
351
+ - Use Logcat in Android Studio
352
+ - Enable USB debugging
353
+ - Monitor network traffic
354
+
355
+ ## Common Issues
356
+
357
+ ### Issue: Updates Not Detected
358
+ - Verify server is running
359
+ - Check version numbers
360
+ - Ensure HTTPS is used
361
+ - Check CORS configuration
362
+
363
+ ### Issue: Download Fails
364
+ - Check network connectivity
365
+ - Verify bundle URL
366
+ - Check file permissions
367
+ - Monitor server logs
368
+
369
+ ### Issue: Signature Verification Fails
370
+ - Ensure keys match
371
+ - Check base64 encoding
372
+ - Verify bundle integrity
373
+ - Update public key in app