native-update 4.2.4 → 4.4.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/flutter-patch.js +107 -0
- package/cli/commands/remote-shared.js +3 -1
- package/cli/commands/remote.js +19 -0
- package/cli/index.js +25 -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 +43 -0
- package/docs/KNOWN_LIMITATIONS.md +16 -1
- package/docs/protocol/CLIENT-PROTOCOL.md +199 -0
- package/docs/server-requirements.md +4 -0
- package/ios/Plugin/LiveUpdate/LiveUpdatePlugin.swift +5 -0
- package/package.json +8 -6
package/README.md
CHANGED
|
@@ -28,7 +28,7 @@ are available as an HTTP API for CI and coding agents.
|
|
|
28
28
|
|
|
29
29
|
| | |
|
|
30
30
|
|---|---|
|
|
31
|
-
| **Version** | `4.
|
|
31
|
+
| **Version** | `4.4.0` |
|
|
32
32
|
| **License** | Proprietary — free to use in your apps ([LICENSE](./LICENSE)) |
|
|
33
33
|
| **Node** | `>=24.16.0` (install + CLI toolchain) |
|
|
34
34
|
| **Platforms** | iOS 14+ · Android 8.0+ (API 26) · Web |
|
|
@@ -513,11 +513,9 @@ indexed at [`/raw/manifest.json`](https://nativeupdate-docs.aoneahsan.com/raw/ma
|
|
|
513
513
|
<a id="changelog"></a>
|
|
514
514
|
## 🔄 Changelog [#](#changelog)
|
|
515
515
|
|
|
516
|
-
Latest release: **`4.
|
|
517
|
-
|
|
518
|
-
|
|
519
|
-
carry the typed `displayed` and `canRequest` fields. Upgrade the package and ship a new native build: these
|
|
520
|
-
fixes are in native code, so an over-the-air bundle cannot deliver them.
|
|
516
|
+
Latest release: **`4.4.0`**. The CLI builds and uploads Dart code patches for Flutter apps
|
|
517
|
+
(`bundle flutter-patch`, `deploy --payload-type dart_aot`), for the Flutter SDK 1.1.0. The Capacitor plugin's API is
|
|
518
|
+
unchanged.
|
|
521
519
|
|
|
522
520
|
Full history ships inside the package at `docs/CHANGELOG.md`, so it always matches the version you
|
|
523
521
|
installed. It is also published as the
|
|
@@ -60,6 +60,9 @@ class LiveUpdatePlugin(
|
|
|
60
60
|
private val appSigningSha1: String? get() = signingCertFingerprints.second
|
|
61
61
|
|
|
62
62
|
companion object {
|
|
63
|
+
/** This plugin's version, sent as X-Sdk-Version. Kept equal to package.json by tests/sdk-version.test.ts. */
|
|
64
|
+
const val SDK_VERSION = "4.4.0"
|
|
65
|
+
|
|
63
66
|
// SharedPreferences keys. Kept as constants so A2 (boot-time
|
|
64
67
|
// re-verification) and A3 (crash-loop auto-rollback) stay in sync
|
|
65
68
|
// with the call-sites in setActiveBundle / notifyAppReady.
|
|
@@ -581,6 +584,9 @@ class LiveUpdatePlugin(
|
|
|
581
584
|
.header("X-Device-ID", getOrCreateDeviceId())
|
|
582
585
|
.header("X-Current-Version", getCurrentVersion())
|
|
583
586
|
.header("X-Platform", "android")
|
|
587
|
+
// SDK identity: the server offers this WebView only web bundles (docs/protocol/CLIENT-PROTOCOL.md).
|
|
588
|
+
.header("X-Client-Sdk", "capacitor")
|
|
589
|
+
.header("X-Sdk-Version", SDK_VERSION)
|
|
584
590
|
.header("X-Android-Package", context.packageName)
|
|
585
591
|
getBinaryVersion()?.let { requestBuilder.header("X-App-Version", it) }
|
|
586
592
|
// App-identity headers for API-key client restrictions. Best-effort:
|
|
@@ -0,0 +1,107 @@
|
|
|
1
|
+
import chalk from 'chalk';
|
|
2
|
+
import crypto from 'crypto';
|
|
3
|
+
import fs from 'fs/promises';
|
|
4
|
+
import path from 'path';
|
|
5
|
+
import zlib from 'zlib';
|
|
6
|
+
import { ZipArchive } from 'archiver';
|
|
7
|
+
import { createWriteStream } from 'fs';
|
|
8
|
+
|
|
9
|
+
/**
|
|
10
|
+
* Reads the entries of a ZIP (an APK) from its central directory. Handles stored and deflated entries, which is
|
|
11
|
+
* everything the Android build tools write. Returns a Map of name -> { read(): Buffer }.
|
|
12
|
+
*/
|
|
13
|
+
async function readZip(filePath) {
|
|
14
|
+
const buf = await fs.readFile(filePath);
|
|
15
|
+
const minEnd = Math.max(0, buf.length - 0xffff - 22);
|
|
16
|
+
let end = -1;
|
|
17
|
+
for (let i = buf.length - 22; i >= minEnd; i--) {
|
|
18
|
+
if (buf.readUInt32LE(i) === 0x06054b50) {
|
|
19
|
+
end = i;
|
|
20
|
+
break;
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
if (end < 0) throw new Error(`${filePath} is not a ZIP/APK file`);
|
|
24
|
+
const count = buf.readUInt16LE(end + 10);
|
|
25
|
+
let offset = buf.readUInt32LE(end + 16);
|
|
26
|
+
const entries = new Map();
|
|
27
|
+
for (let i = 0; i < count; i++) {
|
|
28
|
+
if (buf.readUInt32LE(offset) !== 0x02014b50) throw new Error('Corrupt ZIP central directory');
|
|
29
|
+
const method = buf.readUInt16LE(offset + 10);
|
|
30
|
+
const compressed = buf.readUInt32LE(offset + 20);
|
|
31
|
+
const nameLength = buf.readUInt16LE(offset + 28);
|
|
32
|
+
const extraLength = buf.readUInt16LE(offset + 30);
|
|
33
|
+
const commentLength = buf.readUInt16LE(offset + 32);
|
|
34
|
+
const local = buf.readUInt32LE(offset + 42);
|
|
35
|
+
const name = buf.toString('utf8', offset + 46, offset + 46 + nameLength);
|
|
36
|
+
entries.set(name, {
|
|
37
|
+
read() {
|
|
38
|
+
const localName = buf.readUInt16LE(local + 26);
|
|
39
|
+
const localExtra = buf.readUInt16LE(local + 28);
|
|
40
|
+
const start = local + 30 + localName + localExtra;
|
|
41
|
+
const data = buf.subarray(start, start + compressed);
|
|
42
|
+
if (method === 0) return Buffer.from(data);
|
|
43
|
+
if (method === 8) return zlib.inflateRawSync(data);
|
|
44
|
+
throw new Error(`Unsupported ZIP compression method ${method} for ${name}`);
|
|
45
|
+
},
|
|
46
|
+
});
|
|
47
|
+
offset += 46 + nameLength + extraLength + commentLength;
|
|
48
|
+
}
|
|
49
|
+
return entries;
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
const sha256 = (data) => crypto.createHash('sha256').update(data).digest('hex');
|
|
53
|
+
|
|
54
|
+
/**
|
|
55
|
+
* `native-update bundle flutter-patch <apk>`: turns a Flutter RELEASE APK into a Dart code update.
|
|
56
|
+
*
|
|
57
|
+
* The patch holds lib/<abi>/libapp.so for every architecture in the APK, plus the files of --assets. Next to it,
|
|
58
|
+
* <out>.runtime-keys lists the SHA-256 of each libflutter.so: a device is offered the patch only when its own engine
|
|
59
|
+
* is one of them, because compiled Dart code runs only on the engine it was built against. Build the patch APK from
|
|
60
|
+
* the same Flutter version and the same native plugins as the app build it updates.
|
|
61
|
+
*/
|
|
62
|
+
export async function createFlutterPatch(apkPath, options) {
|
|
63
|
+
const entries = await readZip(apkPath);
|
|
64
|
+
const abis = [...entries.keys()]
|
|
65
|
+
.map((name) => /^lib\/([^/]+)\/libapp\.so$/.exec(name)?.[1])
|
|
66
|
+
.filter(Boolean);
|
|
67
|
+
if (abis.length === 0) {
|
|
68
|
+
throw new Error(
|
|
69
|
+
`${apkPath} has no lib/<abi>/libapp.so. Build it with \`flutter build apk --release\` (debug builds carry no compiled Dart code).`
|
|
70
|
+
);
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
const out = path.resolve(options.output ?? 'flutter-patch.zip');
|
|
74
|
+
const stage = await fs.mkdtemp(path.join(path.dirname(out), '.flutter-patch-'));
|
|
75
|
+
const keys = [];
|
|
76
|
+
try {
|
|
77
|
+
for (const abi of abis) {
|
|
78
|
+
const engine = entries.get(`lib/${abi}/libflutter.so`);
|
|
79
|
+
if (!engine) throw new Error(`${apkPath} has libapp.so for ${abi} but no libflutter.so`);
|
|
80
|
+
keys.push({ abi, key: sha256(engine.read()) });
|
|
81
|
+
await fs.mkdir(path.join(stage, 'lib', abi), { recursive: true });
|
|
82
|
+
await fs.writeFile(path.join(stage, 'lib', abi, 'libapp.so'), entries.get(`lib/${abi}/libapp.so`).read());
|
|
83
|
+
}
|
|
84
|
+
if (options.assets) {
|
|
85
|
+
await fs.cp(path.resolve(options.assets), stage, { recursive: true, filter: (src) => !src.includes(`${path.sep}lib${path.sep}`) });
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
await new Promise((resolve, reject) => {
|
|
89
|
+
const output = createWriteStream(out);
|
|
90
|
+
const zip = new ZipArchive({ zlib: { level: 9 } });
|
|
91
|
+
output.on('close', resolve);
|
|
92
|
+
zip.on('error', reject);
|
|
93
|
+
zip.pipe(output);
|
|
94
|
+
zip.directory(stage, false);
|
|
95
|
+
zip.finalize();
|
|
96
|
+
});
|
|
97
|
+
} finally {
|
|
98
|
+
await fs.rm(stage, { recursive: true, force: true });
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
await fs.writeFile(`${out}.runtime-keys`, keys.map((k) => k.key).join('\n') + '\n');
|
|
102
|
+
const size = (await fs.stat(out)).size;
|
|
103
|
+
console.log(chalk.green(`✓ Dart code patch: ${out} (${(size / 1024 / 1024).toFixed(2)} MB)`));
|
|
104
|
+
for (const { abi, key } of keys) console.log(chalk.gray(` ${abi.padEnd(12)} engine ${key}`));
|
|
105
|
+
console.log(chalk.gray(` Engine keys written to ${out}.runtime-keys; deploy picks them up:`));
|
|
106
|
+
console.log(chalk.gray(` npx native-update deploy ${path.relative(process.cwd(), out)} --app <app> --version <v> --payload-type dart_aot --wait`));
|
|
107
|
+
}
|
|
@@ -117,7 +117,9 @@ export function apiClient(options) {
|
|
|
117
117
|
const buffer = await fs.readFile(filePath);
|
|
118
118
|
form.append('file', new Blob([buffer], { type: 'application/zip' }), path_basename(filePath));
|
|
119
119
|
for (const [key, value] of Object.entries(fields)) {
|
|
120
|
-
if (value
|
|
120
|
+
if (Array.isArray(value)) {
|
|
121
|
+
for (const item of value) form.append(`${key}[]`, String(item));
|
|
122
|
+
} else if (value !== undefined && value !== null && value !== '') {
|
|
121
123
|
form.append(key, String(value));
|
|
122
124
|
}
|
|
123
125
|
}
|
package/cli/commands/remote.js
CHANGED
|
@@ -100,7 +100,26 @@ export async function deploy(target, options) {
|
|
|
100
100
|
console.log(chalk.gray(` Signed: yes (${signature.source})`));
|
|
101
101
|
}
|
|
102
102
|
|
|
103
|
+
const payloadType = options.payloadType ?? 'web_bundle';
|
|
104
|
+
if (!['web_bundle', 'assets', 'dart_aot'].includes(payloadType)) {
|
|
105
|
+
throw new Error(`--payload-type must be web_bundle, assets or dart_aot, not "${payloadType}"`);
|
|
106
|
+
}
|
|
107
|
+
console.log(chalk.gray(` Payload: ${payloadType}`));
|
|
108
|
+
let runtimeKeys;
|
|
109
|
+
if (payloadType === 'dart_aot') {
|
|
110
|
+
const listed = options.runtimeKeys
|
|
111
|
+
? options.runtimeKeys
|
|
112
|
+
: await fs.readFile(`${target}.runtime-keys`, 'utf8').catch(() => '');
|
|
113
|
+
runtimeKeys = listed.split(/[\s,]+/).filter(Boolean);
|
|
114
|
+
if (runtimeKeys.length === 0) {
|
|
115
|
+
throw new Error('dart_aot needs engine keys: run `bundle flutter-patch` (it writes <zip>.runtime-keys) or pass --runtime-keys');
|
|
116
|
+
}
|
|
117
|
+
console.log(chalk.gray(` Engines: ${runtimeKeys.length}`));
|
|
118
|
+
}
|
|
119
|
+
|
|
103
120
|
const { data } = await client.upload(`/apps/${options.app}/builds`, bundle.path, {
|
|
121
|
+
payload_type: payloadType,
|
|
122
|
+
runtime_keys: runtimeKeys,
|
|
104
123
|
version,
|
|
105
124
|
channel: options.channel,
|
|
106
125
|
release_notes: options.notes,
|
package/cli/index.js
CHANGED
|
@@ -50,6 +50,25 @@ const bundleCmd = program
|
|
|
50
50
|
.enablePositionalOptions()
|
|
51
51
|
.description('Bundle management commands');
|
|
52
52
|
|
|
53
|
+
bundleCmd
|
|
54
|
+
.command('flutter-patch <apk>')
|
|
55
|
+
.description(`Turn a Flutter release APK into a signed-ready Dart code update (sideloaded apps only)
|
|
56
|
+
|
|
57
|
+
${chalk.bold('Examples:')}
|
|
58
|
+
${chalk.green('npx native-update bundle flutter-patch build/app/outputs/flutter-apk/app-release.apk -o patch.zip')}
|
|
59
|
+
${chalk.green('npx native-update deploy patch.zip --app com.example.app --version 1.0.1 --payload-type dart_aot --wait')}`)
|
|
60
|
+
.option('-o, --output <file>', 'Patch ZIP to write', 'flutter-patch.zip')
|
|
61
|
+
.option('--assets <dir>', 'Also ship the files in this folder, read with NativeUpdate.file()')
|
|
62
|
+
.action(async (apk, options) => {
|
|
63
|
+
const { createFlutterPatch } = await import('./commands/flutter-patch.js');
|
|
64
|
+
try {
|
|
65
|
+
await createFlutterPatch(apk, options);
|
|
66
|
+
} catch (error) {
|
|
67
|
+
console.error(chalk.red(`Error: ${error.message}`));
|
|
68
|
+
process.exit(1);
|
|
69
|
+
}
|
|
70
|
+
});
|
|
71
|
+
|
|
53
72
|
bundleCmd
|
|
54
73
|
.command('create <webDir>')
|
|
55
74
|
.alias('create-bundle')
|
|
@@ -234,6 +253,12 @@ ${chalk.bold('Examples:')}
|
|
|
234
253
|
.option('-n, --notes <text>', 'Release notes')
|
|
235
254
|
.option('-r, --rollout <percent>', 'Initial rollout percentage (1-100)')
|
|
236
255
|
.option('--min-native <version>', 'Minimum native app version required')
|
|
256
|
+
.option(
|
|
257
|
+
'--payload-type <type>',
|
|
258
|
+
'web_bundle (Capacitor / React Native code), assets (files a native Android or Flutter app reads) or dart_aot (a Flutter code patch from `bundle flutter-patch`)',
|
|
259
|
+
'web_bundle'
|
|
260
|
+
)
|
|
261
|
+
.option('--runtime-keys <keys>', 'dart_aot only: comma-separated engine keys (auto-read from a sibling .runtime-keys)')
|
|
237
262
|
.option('--signature <file>', 'Detached signature from `bundle sign` (auto-detects a sibling .sig)')
|
|
238
263
|
.option('-w, --wait', 'Wait for processing to finish (exit non-zero if it fails)', false)
|
|
239
264
|
).action(async (target, options) => {
|
|
@@ -18,6 +18,8 @@
|
|
|
18
18
|
* X-Current-Version: the currently-installed bundle version
|
|
19
19
|
* X-Platform: ios | android | web
|
|
20
20
|
* X-App-Version: native app version (optional)
|
|
21
|
+
* X-Client-Sdk: capacitor (the server then offers only `web_bundle` builds)
|
|
22
|
+
* X-Sdk-Version: this plugin's version (SDK_VERSION)
|
|
21
23
|
* X-Android-Package: applicationId (optional; sent when identity.platform === 'android')
|
|
22
24
|
* X-Android-Cert-Sha256: signing cert SHA-256, hex (optional)
|
|
23
25
|
* X-Android-Cert-Sha1: signing cert SHA-1, hex (optional)
|
|
@@ -54,6 +56,11 @@
|
|
|
54
56
|
* `docs/server-requirements.md`.
|
|
55
57
|
*/
|
|
56
58
|
import type { AppIdentity } from '../types/app-identity';
|
|
59
|
+
/**
|
|
60
|
+
* This plugin's version, sent as `X-Sdk-Version`. Kept equal to package.json (and to the Kotlin and Swift
|
|
61
|
+
* constants) by tests/sdk-version.test.ts.
|
|
62
|
+
*/
|
|
63
|
+
export declare const SDK_VERSION = "4.4.0";
|
|
57
64
|
/** Request inputs for a single backend update check. */
|
|
58
65
|
export interface UpdateCheckRequest {
|
|
59
66
|
/** API key issued by the dashboard; sent as `X-API-Key`. Required. */
|
|
@@ -96,6 +103,8 @@ export interface BackendUpdateCheckResponse {
|
|
|
96
103
|
releaseNotes?: string | null;
|
|
97
104
|
minNativeVersion?: string | null;
|
|
98
105
|
expiresAt?: string;
|
|
106
|
+
/** `web_bundle` for every build this client is offered (the server filters by X-Client-Sdk). */
|
|
107
|
+
payloadType?: 'web_bundle' | 'assets';
|
|
99
108
|
message?: string;
|
|
100
109
|
/** Billing hold: a newer release exists but is not served (see `CheckForUpdateResult.held`). */
|
|
101
110
|
held?: boolean;
|
|
@@ -18,6 +18,8 @@
|
|
|
18
18
|
* X-Current-Version: the currently-installed bundle version
|
|
19
19
|
* X-Platform: ios | android | web
|
|
20
20
|
* X-App-Version: native app version (optional)
|
|
21
|
+
* X-Client-Sdk: capacitor (the server then offers only `web_bundle` builds)
|
|
22
|
+
* X-Sdk-Version: this plugin's version (SDK_VERSION)
|
|
21
23
|
* X-Android-Package: applicationId (optional; sent when identity.platform === 'android')
|
|
22
24
|
* X-Android-Cert-Sha256: signing cert SHA-256, hex (optional)
|
|
23
25
|
* X-Android-Cert-Sha1: signing cert SHA-1, hex (optional)
|
|
@@ -53,6 +55,11 @@
|
|
|
53
55
|
* Custom backends must return these exact field names — see
|
|
54
56
|
* `docs/server-requirements.md`.
|
|
55
57
|
*/
|
|
58
|
+
/**
|
|
59
|
+
* This plugin's version, sent as `X-Sdk-Version`. Kept equal to package.json (and to the Kotlin and Swift
|
|
60
|
+
* constants) by tests/sdk-version.test.ts.
|
|
61
|
+
*/
|
|
62
|
+
export const SDK_VERSION = '4.4.0';
|
|
56
63
|
/**
|
|
57
64
|
* Perform one update check against the Native Update backend.
|
|
58
65
|
*
|
|
@@ -70,6 +77,8 @@ export async function checkForUpdate(baseUrl, req) {
|
|
|
70
77
|
'X-Device-ID': req.deviceId,
|
|
71
78
|
'X-Current-Version': req.currentVersion,
|
|
72
79
|
'X-Platform': req.platform,
|
|
80
|
+
'X-Client-Sdk': 'capacitor',
|
|
81
|
+
'X-Sdk-Version': SDK_VERSION,
|
|
73
82
|
};
|
|
74
83
|
if (req.appVersion) {
|
|
75
84
|
headers['X-App-Version'] = req.appVersion;
|
|
@@ -110,6 +119,7 @@ export async function checkForUpdate(baseUrl, req) {
|
|
|
110
119
|
releaseNotes: (_d = data.releaseNotes) !== null && _d !== void 0 ? _d : undefined,
|
|
111
120
|
minNativeVersion: (_e = data.minNativeVersion) !== null && _e !== void 0 ? _e : undefined,
|
|
112
121
|
expiresAt: data.expiresAt,
|
|
122
|
+
payloadType: data.payloadType,
|
|
113
123
|
message: data.message,
|
|
114
124
|
held: data.held === true ? true : undefined,
|
|
115
125
|
code: data.code,
|