native-update 4.2.4 → 4.3.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/README.md +4 -6
- package/android/src/main/java/com/aoneahsan/nativeupdate/LiveUpdatePlugin.kt +6 -0
- package/cli/commands/remote.js +7 -0
- package/cli/index.js +5 -0
- package/dist/esm/core/update-check.d.ts +9 -0
- package/dist/esm/core/update-check.js +10 -0
- package/dist/plugin.cjs +1 -1
- package/dist/plugin.esm.js +1 -1
- package/dist/plugin.js +2 -2
- package/docs/CHANGELOG.md +20 -0
- package/docs/KNOWN_LIMITATIONS.md +3 -0
- package/docs/protocol/CLIENT-PROTOCOL.md +178 -0
- package/docs/server-requirements.md +4 -0
- package/ios/Plugin/LiveUpdate/LiveUpdatePlugin.swift +5 -0
- package/package.json +2 -1
|
@@ -0,0 +1,178 @@
|
|
|
1
|
+
# Native Update client protocol
|
|
2
|
+
|
|
3
|
+
**Version:** 1 (server marker `2026.11.19.1`, plugin 4.3.0) · **Last updated:** 2026-11-19
|
|
4
|
+
|
|
5
|
+
Every Native Update SDK speaks this protocol: the Capacitor plugin, the native Android library, the Flutter
|
|
6
|
+
plugin, the React Native package and, later, native iOS. It is written from the code that runs today:
|
|
7
|
+
`backend/app/Http/Controllers/Api/UpdateController.php`, `src/core/update-check.ts`,
|
|
8
|
+
`android/src/main/java/com/aoneahsan/nativeupdate/LiveUpdatePlugin.kt` and `SecurityManager.kt`. If code and
|
|
9
|
+
this file disagree, the code is right and this file is fixed in the same change.
|
|
10
|
+
|
|
11
|
+
## 1. Update check
|
|
12
|
+
|
|
13
|
+
```
|
|
14
|
+
GET {serverUrl}/v1/updates/check?channel={production|staging|development}
|
|
15
|
+
```
|
|
16
|
+
|
|
17
|
+
`serverUrl` is the canonical base ending in `/api` (`https://nativeupdatebe.aoneahsan.com/api`). HTTPS only.
|
|
18
|
+
|
|
19
|
+
| Header | Required | Value |
|
|
20
|
+
|---|---|---|
|
|
21
|
+
| `X-API-Key` | yes | The app's `nu_app_…` device key. Missing → 401 `MISSING_API_KEY`. |
|
|
22
|
+
| `X-Device-ID` | yes | A stable random id per install, generated once and stored. Missing → 400 `MISSING_DEVICE_ID`. |
|
|
23
|
+
| `X-Current-Version` | yes | The version of the payload running now: the active OTA payload, or the version shipped inside the binary when none is active. |
|
|
24
|
+
| `X-Platform` | yes | `android` · `ios` · `web` |
|
|
25
|
+
| `X-App-Version` | when known | The native binary's version name. Used by `minNativeVersion`. |
|
|
26
|
+
| `X-Client-Sdk` | yes, new SDKs | `capacitor` · `android` · `flutter` · `react-native` · `ios` |
|
|
27
|
+
| `X-Sdk-Version` | yes, new SDKs | The SDK's own version, `[0-9A-Za-z.+-]{1,32}` |
|
|
28
|
+
| `X-Android-Package` | Android | applicationId, for per-key client restrictions |
|
|
29
|
+
| `X-Android-Cert-Sha256` / `-Sha1` | Android, when readable | Signing certificate digest, lowercase hex |
|
|
30
|
+
| `X-Ios-Bundle-Id` | iOS | Bundle identifier |
|
|
31
|
+
|
|
32
|
+
A key restricted to other identities answers 403 `API_KEY_RESTRICTED`. The identity headers are reported by the
|
|
33
|
+
client, not cryptographically attested.
|
|
34
|
+
|
|
35
|
+
### Payload types
|
|
36
|
+
|
|
37
|
+
A build is one ZIP with one `payloadType`. The server offers a build only to an SDK that can run it:
|
|
38
|
+
|
|
39
|
+
| `X-Client-Sdk` | Accepted payload | What the SDK does with it |
|
|
40
|
+
|---|---|---|
|
|
41
|
+
| `capacitor`, `react-native`, absent | `web_bundle` | Serves it as the app's web / JS bundle |
|
|
42
|
+
| `android`, `flutter`, `ios` | `assets` | Exposes the unpacked files to the app (images, JSON config). Never loads code from it. |
|
|
43
|
+
|
|
44
|
+
A client that sends no `X-Client-Sdk` is a Capacitor plugin older than 4.3.0. When the newest build has a
|
|
45
|
+
payload the client cannot use, the check answers `available:false` with `code:"PAYLOAD_NOT_SUPPORTED"`.
|
|
46
|
+
|
|
47
|
+
Native Android and Flutter apps never receive executable code by OTA. That is the store-policy line, and the
|
|
48
|
+
server enforces it.
|
|
49
|
+
|
|
50
|
+
### Response (always HTTP 200 once the key is valid)
|
|
51
|
+
|
|
52
|
+
No update:
|
|
53
|
+
|
|
54
|
+
```json
|
|
55
|
+
{ "available": false, "message": "Already on latest version" }
|
|
56
|
+
```
|
|
57
|
+
|
|
58
|
+
Other `available:false` shapes carry extra fields:
|
|
59
|
+
- `minNativeVersion`: the binary is too old for the newest build;
|
|
60
|
+
- `held: true, code: "BILLING_HOLD", version`: an update exists but delivery is paused;
|
|
61
|
+
- `code: "PAYLOAD_NOT_SUPPORTED"`.
|
|
62
|
+
|
|
63
|
+
Update available:
|
|
64
|
+
|
|
65
|
+
```json
|
|
66
|
+
{
|
|
67
|
+
"available": true,
|
|
68
|
+
"version": "1.4.0",
|
|
69
|
+
"bundleId": "9b1c…uuid",
|
|
70
|
+
"downloadUrl": "https://…/api/v1/bundles/123/download?signature=…",
|
|
71
|
+
"checksum": "64 lowercase hex chars (SHA-256 of the ZIP)",
|
|
72
|
+
"signature": "base64 | null",
|
|
73
|
+
"signatureAlgorithm": "RSA-SHA256 | null",
|
|
74
|
+
"payloadType": "web_bundle | assets",
|
|
75
|
+
"size": 482113,
|
|
76
|
+
"mandatory": false,
|
|
77
|
+
"releaseNotes": "text | null",
|
|
78
|
+
"minNativeVersion": "1.16.0 | null",
|
|
79
|
+
"expiresAt": "ISO-8601, when downloadUrl stops working",
|
|
80
|
+
"delta": null
|
|
81
|
+
}
|
|
82
|
+
```
|
|
83
|
+
|
|
84
|
+
The server never offers a version equal to or older than `X-Current-Version`. A client still compares the
|
|
85
|
+
two itself (semver: numeric major.minor.patch) and refuses a downgrade.
|
|
86
|
+
|
|
87
|
+
A network error, a timeout or a non-2xx answer is an **error**, never "no update". The SDK reports it to the
|
|
88
|
+
app (`NETWORK_ERROR`) and keeps running the current payload.
|
|
89
|
+
|
|
90
|
+
## 2. Download and verification
|
|
91
|
+
|
|
92
|
+
1. GET `downloadUrl` before `expiresAt`. Write it to a temporary file and stop past the configured size limit
|
|
93
|
+
(`maxBundleSize`, default 100 MB).
|
|
94
|
+
2. **Checksum:** SHA-256 of the downloaded bytes, lowercase hex, must equal `checksum`. On a mismatch, delete
|
|
95
|
+
the file (`CHECKSUM_ERROR`).
|
|
96
|
+
3. **Signature:** when `requireSignature` is on (the production default), `signature` must be present and
|
|
97
|
+
`signatureAlgorithm` must be `RSA-SHA256`. Verify `SHA256withRSA` (PKCS#1 v1.5) over the **exact ZIP bytes**
|
|
98
|
+
with the app's public key (X.509 SubjectPublicKeyInfo, PEM or bare base64). Any failure deletes the file,
|
|
99
|
+
stores nothing and keeps the current payload (`SIGNATURE_ERROR`). Unsigned payloads are allowed only in
|
|
100
|
+
debug builds, with both `requireSignature:false` and `allowUnsignedDevelopmentUpdates:true`.
|
|
101
|
+
4. **Unpack** into a new directory named after `bundleId`. Every entry's canonical path must stay inside that
|
|
102
|
+
directory (Zip-Slip refusal), and the unpacked size is bounded (`maxUncompressedBundleSize`).
|
|
103
|
+
|
|
104
|
+
### Delta (`NUDELTA/1`)
|
|
105
|
+
|
|
106
|
+
When the device runs a version the server still holds, `delta` carries:
|
|
107
|
+
`{ format:"NUDELTA/1", fromVersion, patchUrl, patchSize, patchChecksum, targetChecksum }`.
|
|
108
|
+
|
|
109
|
+
The patch is JSON: `{ format, baseChecksum, targetChecksum, targetSize, operations[] }`. Each operation is
|
|
110
|
+
`{op:"copy", offset, length}` (bytes from the current ZIP) or `{op:"literal", data:"base64"}`.
|
|
111
|
+
|
|
112
|
+
A client:
|
|
113
|
+
- checks `patchChecksum`, then `baseChecksum` against its current ZIP;
|
|
114
|
+
- applies at most 100,000 bounded operations and refuses any out-of-range copy or oversize output;
|
|
115
|
+
- runs steps 2 and 3 on the rebuilt ZIP exactly as for a full download.
|
|
116
|
+
|
|
117
|
+
Any delta failure falls back to the full `downloadUrl`. Delta support is optional for an SDK; the full
|
|
118
|
+
download is always valid.
|
|
119
|
+
|
|
120
|
+
## 3. Activation, confirmation and rollback
|
|
121
|
+
|
|
122
|
+
State kept per install (Android uses SharedPreferences, iOS UserDefaults):
|
|
123
|
+
|
|
124
|
+
| Key | Meaning |
|
|
125
|
+
|---|---|
|
|
126
|
+
| active | the bundle now in use |
|
|
127
|
+
| previous | the rollback target |
|
|
128
|
+
| pending + attempts | an activated bundle not yet confirmed, and how many cold starts it has had |
|
|
129
|
+
| binary identity | `versionCode:versionName` of the binary that activated `active` |
|
|
130
|
+
|
|
131
|
+
- **Activate:** previous ← active, active ← new, pending ← new, attempts ← 0, and record the binary identity.
|
|
132
|
+
When the payload type needs a restart (web bundles), switch on the next start or background.
|
|
133
|
+
- **Confirm:** the app calls `notifyAppReady()` once it has started cleanly on the payload. That clears
|
|
134
|
+
pending.
|
|
135
|
+
- **Rollback:** on each cold start with pending set, attempts += 1. At **2** unconfirmed starts, go back to
|
|
136
|
+
previous (or to the binary's own payload) and stop offering that bundle. A checksum or signature mismatch
|
|
137
|
+
of the active payload on start rolls back at once.
|
|
138
|
+
- **New binary:** when the recorded binary identity differs from the running binary (a store update), the
|
|
139
|
+
stored OTA payload is retired and the binary's own payload is used. The server then decides afresh.
|
|
140
|
+
- **Pruning:** after a confirmed start, delete every stored bundle except active, previous, pending and the
|
|
141
|
+
newest staged download that is newer than active.
|
|
142
|
+
|
|
143
|
+
## 4. Configuration
|
|
144
|
+
|
|
145
|
+
Configuration is applied once per process. Calling it again with identical values resolves. Different values
|
|
146
|
+
are refused until `reset()`. Optional fields are read null-safely: a missing optional field never fails
|
|
147
|
+
configuration (ISSUE-14).
|
|
148
|
+
|
|
149
|
+
## 5. Release gate (layer 2)
|
|
150
|
+
|
|
151
|
+
The update check answers "is there a payload". The release gate answers "must this binary update first". It
|
|
152
|
+
reads the app's release record on start and resume, and on a push, never on a timer:
|
|
153
|
+
- an **urgent** release with a newer native version blocks the app now, showing its reason and one Update
|
|
154
|
+
action;
|
|
155
|
+
- a **normal** one says so, then blocks from the next start;
|
|
156
|
+
- offline, it fails open.
|
|
157
|
+
|
|
158
|
+
On Play builds the Update action uses Play in-app update (IMMEDIATE). Play-excluded apps open their APK
|
|
159
|
+
download instead.
|
|
160
|
+
|
|
161
|
+
## 6. Error codes an SDK reports
|
|
162
|
+
|
|
163
|
+
Codes in use by the Capacitor plugin today, which the new SDKs reuse with the same meaning:
|
|
164
|
+
|
|
165
|
+
| Code | When |
|
|
166
|
+
|---|---|
|
|
167
|
+
| `NETWORK_ERROR` / `UPDATE_CHECK_FAILED` | the check or download could not reach the server or got a non-2xx |
|
|
168
|
+
| `DOWNLOAD_ERROR` | the download stopped or exceeded the size limit |
|
|
169
|
+
| `CHECKSUM_ERROR` | SHA-256 mismatch |
|
|
170
|
+
| `SIGNATURE_ERROR` | signature missing, unsupported algorithm or invalid |
|
|
171
|
+
| `EXTRACTION_ERROR` | unpack failed, Zip-Slip or the unpacked size limit |
|
|
172
|
+
| `INSECURE_URL` | a non-HTTPS server or download URL |
|
|
173
|
+
| `VALIDATION_ERROR` | bad input from the app |
|
|
174
|
+
| `PAYLOAD_NOT_SUPPORTED` | server-side: the newest build is not a payload this SDK runs |
|
|
175
|
+
| `BILLING_HOLD` | server-side, informational: delivery paused |
|
|
176
|
+
|
|
177
|
+
A repeated configuration with different values is refused with the message "Configuration is locked after
|
|
178
|
+
initialization; call reset() first". Errors never include filesystem paths, keys or signatures.
|
|
@@ -25,6 +25,10 @@ implements it in exactly one place — `src/core/update-check.ts` — used by
|
|
|
25
25
|
- `X-Current-Version`: currently-installed bundle version
|
|
26
26
|
- `X-Platform`: ios | android | web
|
|
27
27
|
- `X-App-Version`: native app version (optional)
|
|
28
|
+
- `X-Client-Sdk`: `capacitor` (4.3.0+). A backend serving only this plugin may ignore it. A backend that also
|
|
29
|
+
serves the native Android, Flutter or React Native SDKs must offer each SDK only a payload it can run; see
|
|
30
|
+
`docs/protocol/CLIENT-PROTOCOL.md` (shipped in this package).
|
|
31
|
+
- `X-Sdk-Version`: the plugin version (4.3.0+, optional to read)
|
|
28
32
|
|
|
29
33
|
**Optional client-identity headers** (for API-key client restrictions; a custom
|
|
30
34
|
backend MAY read + enforce these, or ignore them):
|
|
@@ -19,6 +19,8 @@ class LiveUpdatePlugin: @unchecked Sendable {
|
|
|
19
19
|
// UserDefaults keys for the A2 (boot-time re-verify) and A3
|
|
20
20
|
// (crash-loop auto-rollback) defenses. Mirrors the Android constants
|
|
21
21
|
// in LiveUpdatePlugin.kt so the two platforms stay in lockstep.
|
|
22
|
+
/// This plugin's version, sent as X-Sdk-Version. Kept equal to package.json by tests/sdk-version.test.ts.
|
|
23
|
+
static let sdkVersion = "4.3.0"
|
|
22
24
|
private static let activeBundleKey = "native_update_active_bundle"
|
|
23
25
|
private static let previousBundleKey = "native_update_previous_active_bundle"
|
|
24
26
|
private static let pendingBundleKey = "native_update_pending_verify_bundle"
|
|
@@ -504,6 +506,9 @@ class LiveUpdatePlugin: @unchecked Sendable {
|
|
|
504
506
|
request.setValue(getOrCreateDeviceId(), forHTTPHeaderField: "X-Device-ID")
|
|
505
507
|
request.setValue(getCurrentVersion(), forHTTPHeaderField: "X-Current-Version")
|
|
506
508
|
request.setValue("ios", forHTTPHeaderField: "X-Platform")
|
|
509
|
+
// SDK identity: the server offers this WebView only web bundles (docs/protocol/CLIENT-PROTOCOL.md).
|
|
510
|
+
request.setValue("capacitor", forHTTPHeaderField: "X-Client-Sdk")
|
|
511
|
+
request.setValue(LiveUpdatePlugin.sdkVersion, forHTTPHeaderField: "X-Sdk-Version")
|
|
507
512
|
// App-identity header for API-key client restrictions (bundle id only;
|
|
508
513
|
// team id is intentionally not sent by the plugin).
|
|
509
514
|
if let bundleId = Bundle.main.bundleIdentifier {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "native-update",
|
|
3
|
-
"version": "4.
|
|
3
|
+
"version": "4.3.0",
|
|
4
4
|
"packageManager": "yarn@4.18.1",
|
|
5
5
|
"engines": {
|
|
6
6
|
"node": ">=24.16.0"
|
|
@@ -40,6 +40,7 @@
|
|
|
40
40
|
"docs/CHANGELOG.md",
|
|
41
41
|
"docs/MIGRATION.md",
|
|
42
42
|
"docs/server-requirements.md",
|
|
43
|
+
"docs/protocol/CLIENT-PROTOCOL.md",
|
|
43
44
|
"docs/KNOWN_LIMITATIONS.md",
|
|
44
45
|
"cli/",
|
|
45
46
|
"AI-INTEGRATION-GUIDE.md",
|