native-update 3.4.1 → 4.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/AI-INTEGRATION-GUIDE.md +26 -16
- package/NativeUpdate.podspec +2 -2
- package/README.md +554 -0
- package/android/build.gradle +43 -34
- package/android/gradle/wrapper/gradle-wrapper.properties +2 -2
- package/android/proguard-rules.pro +0 -3
- package/android/src/main/java/com/aoneahsan/nativeupdate/BackgroundNotificationManager.kt +45 -49
- package/android/src/main/java/com/aoneahsan/nativeupdate/BackgroundUpdateManager.kt +12 -10
- package/android/src/main/java/com/aoneahsan/nativeupdate/BackgroundUpdatePlugin.kt +12 -21
- package/android/src/main/java/com/aoneahsan/nativeupdate/BackgroundUpdateWorker.kt +3 -34
- package/android/src/main/java/com/aoneahsan/nativeupdate/LiveUpdatePlugin.kt +206 -72
- package/android/src/main/java/com/aoneahsan/nativeupdate/NativeUpdatePlugin.kt +74 -37
- package/android/src/main/java/com/aoneahsan/nativeupdate/SecurityManager.kt +169 -179
- package/android/variables.gradle +2 -2
- package/cli/.yarn/install-state.gz +0 -0
- package/cli/commands/bundle-verify.js +4 -1
- package/cli/commands/keys-generate.js +12 -46
- package/cli/index.js +4 -7
- package/cli/package.json +2 -1
- package/dist/esm/core/config.d.ts +3 -0
- package/dist/esm/core/config.js +17 -0
- package/dist/esm/core/plugin-manager.js +4 -2
- package/dist/esm/core/security.js +2 -5
- package/dist/esm/core/update-check.d.ts +2 -0
- package/dist/esm/core/update-check.js +5 -3
- package/dist/esm/definitions.d.ts +43 -2
- package/dist/esm/live-update/delta-processor.d.ts +6 -20
- package/dist/esm/live-update/delta-processor.js +75 -119
- package/dist/esm/plugin.d.ts +0 -3
- package/dist/esm/plugin.js +172 -12
- package/dist/esm/security/crypto.js +2 -5
- package/dist/esm/web.d.ts +1 -9
- package/dist/esm/web.js +4 -56
- package/dist/plugin.cjs +1 -1
- package/dist/plugin.esm.js +1 -1
- package/dist/plugin.js +2 -2
- package/docs/CHANGELOG.md +66 -0
- package/docs/KNOWN_LIMITATIONS.md +4 -3
- package/docs/MIGRATION.md +32 -3
- package/docs/server-requirements.md +40 -29
- package/ios/Plugin/BackgroundUpdate/BackgroundNotificationManager.swift +6 -2
- package/ios/Plugin/BackgroundUpdate/BackgroundUpdatePlugin.swift +21 -30
- package/ios/Plugin/LiveUpdate/LiveUpdatePlugin.swift +269 -61
- package/ios/Plugin/NativeUpdatePlugin.m +8 -1
- package/ios/Plugin/NativeUpdatePlugin.swift +71 -34
- package/ios/Plugin/Security/SecurityManager.swift +100 -99
- package/package.json +27 -15
- package/Readme.md +0 -565
|
@@ -2,9 +2,8 @@
|
|
|
2
2
|
|
|
3
3
|
This document outlines the server infrastructure you need to build to use this plugin.
|
|
4
4
|
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
This plugin does **not** include a backend server. You must build your own server that implements these requirements.
|
|
5
|
+
The hosted service already implements this contract, and the repository includes its Laravel 13 +
|
|
6
|
+
Nova 5 reference backend. Use this document only when implementing or auditing another backend.
|
|
8
7
|
|
|
9
8
|
## Required API Endpoints
|
|
10
9
|
|
|
@@ -59,7 +58,8 @@ anti-casual-reuse, not a hard security boundary.
|
|
|
59
58
|
"bundleId": "0f1e…uuid",
|
|
60
59
|
"downloadUrl": "https://cdn.example.com/bundles/1.2.3.zip",
|
|
61
60
|
"checksum": "sha256-hash",
|
|
62
|
-
"signature": "base64-encoded-signature
|
|
61
|
+
"signature": "base64-encoded-signature",
|
|
62
|
+
"signatureAlgorithm": "RSA-SHA256",
|
|
63
63
|
"size": 1234567,
|
|
64
64
|
"mandatory": false,
|
|
65
65
|
"releaseNotes": "Bug fixes and improvements",
|
|
@@ -68,6 +68,35 @@ anti-casual-reuse, not a hard security boundary.
|
|
|
68
68
|
}
|
|
69
69
|
```
|
|
70
70
|
|
|
71
|
+
Sign the exact ZIP bytes with RSASSA-PKCS1-v1_5 + SHA-256. The checksum is 64 hexadecimal SHA-256
|
|
72
|
+
characters. Production clients reject missing signatures, unknown algorithms, checksum mismatches,
|
|
73
|
+
non-HTTPS URLs, oversized downloads, and paths outside their bundle sandbox.
|
|
74
|
+
|
|
75
|
+
**Optional delta object:** when a patch is materially smaller than the full target ZIP, include:
|
|
76
|
+
|
|
77
|
+
```json
|
|
78
|
+
{
|
|
79
|
+
"delta": {
|
|
80
|
+
"format": "NUDELTA/1",
|
|
81
|
+
"fromVersion": "1.2.2",
|
|
82
|
+
"patchUrl": "https://cdn.example.com/deltas/1.2.2-to-1.2.3.json",
|
|
83
|
+
"patchSize": 45678,
|
|
84
|
+
"patchChecksum": "64-hex-sha256-of-the-patch",
|
|
85
|
+
"targetChecksum": "64-hex-sha256-of-the-target-zip"
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
```
|
|
89
|
+
|
|
90
|
+
`NUDELTA/1` is a JSON document containing `format`, `fromVersion`, `toVersion`, `baseChecksum`,
|
|
91
|
+
`targetChecksum`, `targetSize`, and bounded `operations`. Each operation is either
|
|
92
|
+
`{"op":"copy","offset":0,"length":8192}` into the source ZIP or
|
|
93
|
+
`{"op":"literal","data":"<base64>"}`. A client validates every boundary and falls back to
|
|
94
|
+
`downloadUrl` on any mismatch. The canonical backend builds patches only from the last three active
|
|
95
|
+
builds in the same app/channel and advertises one only when it is smaller than 85% of the full ZIP.
|
|
96
|
+
Serve `patchUrl` over HTTPS from a host allowed by the client. The canonical backend proxies patches
|
|
97
|
+
through a short-lived, checksum-bound signed URL on the same API host as `downloadUrl`; its generator
|
|
98
|
+
uses a 25 MiB input cap and simply leaves `delta` absent for larger bundles.
|
|
99
|
+
|
|
71
100
|
> **Field names are the contract.** Use `available` (not `updateAvailable`)
|
|
72
101
|
> and `downloadUrl` (not `bundleUrl`); a custom backend that renames these
|
|
73
102
|
> will read back as "no update available". These names match the reference
|
|
@@ -83,38 +112,20 @@ plugin extension point, separate from the OTA `/v1/updates/check` flow, and
|
|
|
83
112
|
is a no-op unless you configure it. Return `{ "version": "2.1.0", "priority": 3 }`
|
|
84
113
|
(or `latestVersion`). See `docs/api/background-update-api.md`.
|
|
85
114
|
|
|
86
|
-
### 2. Bundle Download
|
|
87
|
-
```
|
|
88
|
-
GET /api/v1/bundles/{version}
|
|
89
|
-
```
|
|
115
|
+
### 2. Bundle Download URL
|
|
90
116
|
|
|
91
117
|
**Requirements:**
|
|
92
|
-
-
|
|
93
|
-
-
|
|
118
|
+
- Return an HTTPS URL in `downloadUrl`; it may be signed and need not use a fixed path
|
|
119
|
+
- Serve ZIP bytes with `application/zip` (or `application/octet-stream`) and an accurate content length
|
|
120
|
+
- Support byte ranges when possible so resumable clients can use `Range`
|
|
94
121
|
- Include security headers
|
|
95
122
|
- CDN integration recommended
|
|
96
123
|
|
|
97
|
-
### 3. Update Confirmation Endpoint
|
|
98
|
-
```
|
|
99
|
-
POST /api/v1/updates/confirm
|
|
100
|
-
```
|
|
101
|
-
|
|
102
|
-
**Body:**
|
|
103
|
-
```json
|
|
104
|
-
{
|
|
105
|
-
"appId": "com.example.app",
|
|
106
|
-
"version": "1.2.3",
|
|
107
|
-
"platform": "ios",
|
|
108
|
-
"success": true,
|
|
109
|
-
"deviceId": "unique-device-id"
|
|
110
|
-
}
|
|
111
|
-
```
|
|
112
|
-
|
|
113
124
|
## Security Requirements
|
|
114
125
|
|
|
115
126
|
### Bundle Signing
|
|
116
|
-
- Generate RSA
|
|
117
|
-
- Sign
|
|
127
|
+
- Generate RSA key pairs (2048 bits minimum)
|
|
128
|
+
- Sign the exact bundle bytes with RSA-SHA256 (PKCS#1 v1.5)
|
|
118
129
|
- Include public key in app
|
|
119
130
|
- Verify signatures before applying updates
|
|
120
131
|
|
|
@@ -193,4 +204,4 @@ Since no server is provided, you'll need to:
|
|
|
193
204
|
2. Use a third-party service
|
|
194
205
|
3. Hire developers familiar with update servers
|
|
195
206
|
|
|
196
|
-
Consider looking at open-source examples or commercial solutions for inspiration.
|
|
207
|
+
Consider looking at open-source examples or commercial solutions for inspiration.
|
|
@@ -171,7 +171,11 @@ extension BackgroundNotificationManager: UNUserNotificationCenterDelegate {
|
|
|
171
171
|
|
|
172
172
|
func userNotificationCenter(_ center: UNUserNotificationCenter, willPresent notification: UNNotification, withCompletionHandler completionHandler: @escaping (UNNotificationPresentationOptions) -> Void) {
|
|
173
173
|
// Show notification even when app is in foreground
|
|
174
|
-
|
|
174
|
+
if #available(iOS 14.0, *) {
|
|
175
|
+
completionHandler([.banner, .sound, .badge])
|
|
176
|
+
} else {
|
|
177
|
+
completionHandler([.alert, .sound, .badge])
|
|
178
|
+
}
|
|
175
179
|
}
|
|
176
180
|
|
|
177
181
|
func userNotificationCenter(_ center: UNUserNotificationCenter, didReceive response: UNNotificationResponse, withCompletionHandler completionHandler: @escaping () -> Void) {
|
|
@@ -326,4 +330,4 @@ struct NotificationPermissionStatus {
|
|
|
326
330
|
|
|
327
331
|
return obj
|
|
328
332
|
}
|
|
329
|
-
}
|
|
333
|
+
}
|
|
@@ -29,6 +29,19 @@ public class BackgroundUpdatePlugin: CAPPlugin {
|
|
|
29
29
|
failureCount: 0
|
|
30
30
|
)
|
|
31
31
|
private var notificationManager: BackgroundNotificationManager?
|
|
32
|
+
private var appUpdateProvider: (() async -> AppUpdateInfo?)?
|
|
33
|
+
private var liveUpdateProvider: (() async -> LatestVersion?)?
|
|
34
|
+
private var eventListener: ((String, [String: Any]) -> Void)?
|
|
35
|
+
|
|
36
|
+
func configureProviders(
|
|
37
|
+
appUpdate: @escaping () async -> AppUpdateInfo?,
|
|
38
|
+
liveUpdate: @escaping () async -> LatestVersion?,
|
|
39
|
+
eventListener: @escaping (String, [String: Any]) -> Void
|
|
40
|
+
) {
|
|
41
|
+
appUpdateProvider = appUpdate
|
|
42
|
+
liveUpdateProvider = liveUpdate
|
|
43
|
+
self.eventListener = eventListener
|
|
44
|
+
}
|
|
32
45
|
|
|
33
46
|
public override func load() {
|
|
34
47
|
super.load()
|
|
@@ -190,6 +203,8 @@ public class BackgroundUpdatePlugin: CAPPlugin {
|
|
|
190
203
|
NSLog("[native-update] BGTaskScheduler .tooManyPendingTaskRequests — another task is already queued; background updates will run on the existing schedule")
|
|
191
204
|
case .unavailable:
|
|
192
205
|
NSLog("[native-update] BGTaskScheduler .unavailable — background tasks are disabled on this device (likely simulator or Low Power Mode)")
|
|
206
|
+
case .immediateRunIneligible:
|
|
207
|
+
NSLog("[native-update] BGTaskScheduler immediate run is ineligible; the next scheduled refresh will be used")
|
|
193
208
|
@unknown default:
|
|
194
209
|
NSLog("[native-update] Failed to schedule background task: \(error.localizedDescription)")
|
|
195
210
|
}
|
|
@@ -228,11 +243,12 @@ public class BackgroundUpdatePlugin: CAPPlugin {
|
|
|
228
243
|
|
|
229
244
|
// Notify listeners
|
|
230
245
|
await MainActor.run {
|
|
231
|
-
|
|
246
|
+
let data: [String: Any] = [
|
|
232
247
|
"type": result.appUpdate != nil ? "app_update" : "live_update",
|
|
233
248
|
"status": result.success ? "completed" : "failed",
|
|
234
249
|
"percent": 100
|
|
235
|
-
]
|
|
250
|
+
]
|
|
251
|
+
self.eventListener?("backgroundUpdateProgress", data)
|
|
236
252
|
}
|
|
237
253
|
|
|
238
254
|
task.setTaskCompleted(success: result.success)
|
|
@@ -255,7 +271,6 @@ public class BackgroundUpdatePlugin: CAPPlugin {
|
|
|
255
271
|
backgroundUpdateStatus.checkCount += 1
|
|
256
272
|
backgroundUpdateStatus.lastCheckTime = Int(Date().timeIntervalSince1970 * 1000)
|
|
257
273
|
|
|
258
|
-
do {
|
|
259
274
|
var appUpdate: AppUpdateInfo?
|
|
260
275
|
var liveUpdate: LatestVersion?
|
|
261
276
|
|
|
@@ -291,38 +306,14 @@ public class BackgroundUpdatePlugin: CAPPlugin {
|
|
|
291
306
|
notificationSent: notificationSent,
|
|
292
307
|
error: nil
|
|
293
308
|
)
|
|
294
|
-
|
|
295
|
-
} catch {
|
|
296
|
-
backgroundUpdateStatus.isRunning = false
|
|
297
|
-
backgroundUpdateStatus.failureCount += 1
|
|
298
|
-
|
|
299
|
-
let updateError = UpdateError(
|
|
300
|
-
code: "UNKNOWN_ERROR",
|
|
301
|
-
message: error.localizedDescription
|
|
302
|
-
)
|
|
303
|
-
backgroundUpdateStatus.lastError = updateError
|
|
304
|
-
|
|
305
|
-
return BackgroundCheckResult(
|
|
306
|
-
success: false,
|
|
307
|
-
updatesFound: false,
|
|
308
|
-
appUpdate: nil,
|
|
309
|
-
liveUpdate: nil,
|
|
310
|
-
notificationSent: false,
|
|
311
|
-
error: updateError
|
|
312
|
-
)
|
|
313
|
-
}
|
|
314
309
|
}
|
|
315
310
|
|
|
316
311
|
private func checkForAppUpdate() async -> AppUpdateInfo? {
|
|
317
|
-
|
|
318
|
-
let appUpdatePlugin = AppUpdatePlugin(plugin: self)
|
|
319
|
-
return await appUpdatePlugin.getAppUpdateInfoAsync()
|
|
312
|
+
await appUpdateProvider?()
|
|
320
313
|
}
|
|
321
314
|
|
|
322
315
|
private func checkForLiveUpdate() async -> LatestVersion? {
|
|
323
|
-
|
|
324
|
-
let liveUpdatePlugin = LiveUpdatePlugin(plugin: self)
|
|
325
|
-
return await liveUpdatePlugin.getLatestVersionAsync()
|
|
316
|
+
await liveUpdateProvider?()
|
|
326
317
|
}
|
|
327
318
|
|
|
328
319
|
private func sendNotification(appUpdate: AppUpdateInfo?, liveUpdate: LatestVersion?) async -> Bool {
|
|
@@ -470,4 +461,4 @@ struct UpdateError {
|
|
|
470
461
|
"message": message
|
|
471
462
|
]
|
|
472
463
|
}
|
|
473
|
-
}
|
|
464
|
+
}
|