native-update-capacitor 5.0.0 → 5.0.2
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 +85 -76
- package/README.md +23 -15
- package/android/build.gradle +1 -1
- package/android/src/main/java/com/aoneahsan/nativeupdate/AppUpdatePlugin.kt +13 -13
- package/android/src/main/java/com/aoneahsan/nativeupdate/LiveUpdatePlugin.kt +3 -1
- package/android/src/main/java/com/aoneahsan/nativeupdate/NativeUpdatePlugin.kt +79 -6
- package/cli/commands/bundle-create.js +4 -21
- package/cli/commands/flutter-patch.js +2 -11
- package/cli/commands/init.js +68 -87
- package/cli/commands/remote-shared.js +8 -13
- package/cli/commands/server-start.js +3 -3
- package/cli/index.js +6 -6
- package/cli/lib/archive-directory.js +54 -0
- package/cli/package.json +1 -1
- package/dist/esm/core/update-check.d.ts +2 -1
- package/dist/esm/core/update-check.js +5 -1
- package/dist/esm/definitions.d.ts +25 -6
- package/dist/esm/definitions.js +6 -0
- package/dist/esm/plugin.js +2 -0
- package/dist/esm/web.js +2 -0
- package/dist/plugin.cjs +1 -1
- package/dist/plugin.esm.js +1 -1
- package/dist/plugin.js +2 -2
- package/docs/CHANGELOG.md +24 -26
- package/docs/MIGRATION.md +2 -2
- package/docs/protocol/CLIENT-PROTOCOL.md +1 -0
- package/ios/Plugin/LiveUpdate/LiveUpdatePlugin.swift +2 -1
- package/package.json +5 -4
|
@@ -2,8 +2,8 @@ import chalk from 'chalk';
|
|
|
2
2
|
import fs from 'fs/promises';
|
|
3
3
|
import path from 'path';
|
|
4
4
|
import crypto from 'crypto';
|
|
5
|
-
import {
|
|
6
|
-
import {
|
|
5
|
+
import { createReadStream } from 'fs';
|
|
6
|
+
import { archiveDirectory } from '../lib/archive-directory.js';
|
|
7
7
|
import { fileURLToPath } from 'url';
|
|
8
8
|
import { dirname, join } from 'path';
|
|
9
9
|
|
|
@@ -87,24 +87,7 @@ export async function createBundle(webDir, options) {
|
|
|
87
87
|
console.log(chalk.gray(` Channel: ${options.channel}`));
|
|
88
88
|
console.log(chalk.gray(` Output: ${bundlePath}`));
|
|
89
89
|
|
|
90
|
-
|
|
91
|
-
const output = createWriteStream(bundlePath);
|
|
92
|
-
const archive = new ZipArchive({
|
|
93
|
-
zlib: { level: 9 }
|
|
94
|
-
});
|
|
95
|
-
|
|
96
|
-
const archivePromise = new Promise((resolve, reject) => {
|
|
97
|
-
output.on('close', resolve);
|
|
98
|
-
archive.on('error', reject);
|
|
99
|
-
});
|
|
100
|
-
|
|
101
|
-
archive.pipe(output);
|
|
102
|
-
|
|
103
|
-
// Add all files from web directory
|
|
104
|
-
archive.directory(webDir, false);
|
|
105
|
-
|
|
106
|
-
await archive.finalize();
|
|
107
|
-
await archivePromise;
|
|
90
|
+
await archiveDirectory(webDir, bundlePath);
|
|
108
91
|
|
|
109
92
|
// Stream the bundle through the SHA-256 hasher so a 100MB+ bundle
|
|
110
93
|
// doesn't get slurped into RAM all at once. Size comes from fs.stat.
|
|
@@ -142,4 +125,4 @@ export async function createBundle(webDir, options) {
|
|
|
142
125
|
console.error(chalk.red('❌ Failed to create bundle:'), error.message);
|
|
143
126
|
process.exit(1);
|
|
144
127
|
}
|
|
145
|
-
}
|
|
128
|
+
}
|
|
@@ -3,8 +3,7 @@ import crypto from 'crypto';
|
|
|
3
3
|
import fs from 'fs/promises';
|
|
4
4
|
import path from 'path';
|
|
5
5
|
import zlib from 'zlib';
|
|
6
|
-
import {
|
|
7
|
-
import { createWriteStream } from 'fs';
|
|
6
|
+
import { archiveDirectory } from '../lib/archive-directory.js';
|
|
8
7
|
|
|
9
8
|
/**
|
|
10
9
|
* Reads the entries of a ZIP (an APK) from its central directory. Handles stored and deflated entries, which is
|
|
@@ -85,15 +84,7 @@ export async function createFlutterPatch(apkPath, options) {
|
|
|
85
84
|
await fs.cp(path.resolve(options.assets), stage, { recursive: true, filter: (src) => !src.includes(`${path.sep}lib${path.sep}`) });
|
|
86
85
|
}
|
|
87
86
|
|
|
88
|
-
await
|
|
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
|
-
});
|
|
87
|
+
await archiveDirectory(stage, out);
|
|
97
88
|
} finally {
|
|
98
89
|
await fs.rm(stage, { recursive: true, force: true });
|
|
99
90
|
}
|
package/cli/commands/init.js
CHANGED
|
@@ -1,43 +1,89 @@
|
|
|
1
1
|
import chalk from 'chalk';
|
|
2
2
|
import fs from 'fs/promises';
|
|
3
|
-
import path from 'path';
|
|
4
3
|
import prompts from 'prompts';
|
|
5
4
|
|
|
5
|
+
/** Render the file consumed by the SDK at app startup. */
|
|
6
|
+
export function renderConfig(config) {
|
|
7
|
+
return `export default {
|
|
8
|
+
appId: ${JSON.stringify(config.appId)},
|
|
9
|
+
serverUrl: ${JSON.stringify(config.serverUrl)},
|
|
10
|
+
apiKey: ${JSON.stringify(config.apiKey)},
|
|
11
|
+
channel: ${JSON.stringify(config.channel)},
|
|
12
|
+
|
|
13
|
+
// Replace this with the public key created by native-update keys generate.
|
|
14
|
+
publicKey: \`-----BEGIN PUBLIC KEY-----
|
|
15
|
+
YOUR_PUBLIC_KEY_HERE
|
|
16
|
+
-----END PUBLIC KEY-----\`,
|
|
17
|
+
requireSignature: true,
|
|
18
|
+
};
|
|
19
|
+
`;
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
/** Render the optional startup integration, including a staged update. */
|
|
23
|
+
export function renderExample() {
|
|
24
|
+
return `import { NativeUpdate } from 'native-update';
|
|
25
|
+
import config from './native-update.config.js';
|
|
26
|
+
|
|
27
|
+
// Call after your app has rendered successfully.
|
|
28
|
+
export async function initializeUpdates() {
|
|
29
|
+
await NativeUpdate.initialize(config);
|
|
30
|
+
await NativeUpdate.notifyAppReady();
|
|
31
|
+
|
|
32
|
+
const update = await NativeUpdate.checkForUpdate();
|
|
33
|
+
if (!update.available) return;
|
|
34
|
+
|
|
35
|
+
const bundle = await NativeUpdate.downloadUpdate();
|
|
36
|
+
await NativeUpdate.set({ ...bundle, applyOn: 'next-start' });
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
// Call initializeUpdates() from your app's startup code after its first render.
|
|
40
|
+
`;
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
/** Ask for the minimum hosted/self-hosted settings and write the selected files. */
|
|
6
44
|
export async function init(options) {
|
|
7
45
|
console.log(chalk.blue('🚀 Initializing Native Update in your project...'));
|
|
8
46
|
|
|
9
47
|
try {
|
|
10
|
-
|
|
48
|
+
let exists = false;
|
|
11
49
|
try {
|
|
12
50
|
await fs.access('./native-update.config.js');
|
|
51
|
+
exists = true;
|
|
52
|
+
} catch (error) {
|
|
53
|
+
if (error.code !== 'ENOENT') throw error;
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
if (exists) {
|
|
13
57
|
const { overwrite } = await prompts({
|
|
14
58
|
type: 'confirm',
|
|
15
59
|
name: 'overwrite',
|
|
16
60
|
message: 'Config file already exists. Overwrite?',
|
|
17
|
-
initial: false
|
|
61
|
+
initial: false,
|
|
18
62
|
});
|
|
19
|
-
|
|
20
63
|
if (!overwrite) {
|
|
21
64
|
console.log(chalk.yellow('Initialization cancelled.'));
|
|
22
65
|
return;
|
|
23
66
|
}
|
|
24
|
-
} catch {
|
|
25
|
-
// File doesn't exist, good
|
|
26
67
|
}
|
|
27
68
|
|
|
28
|
-
// Prompt for configuration
|
|
29
69
|
const config = await prompts([
|
|
30
70
|
{
|
|
31
71
|
type: 'text',
|
|
32
72
|
name: 'appId',
|
|
33
|
-
message: '
|
|
34
|
-
validate: value => value.length > 0
|
|
73
|
+
message: 'Hosted app ID (UUID from the dashboard):',
|
|
74
|
+
validate: value => value.length > 0,
|
|
35
75
|
},
|
|
36
76
|
{
|
|
37
77
|
type: 'text',
|
|
38
78
|
name: 'serverUrl',
|
|
39
79
|
message: 'Update server URL:',
|
|
40
|
-
initial: 'https://
|
|
80
|
+
initial: 'https://nativeupdatebe.aoneahsan.com/api',
|
|
81
|
+
},
|
|
82
|
+
{
|
|
83
|
+
type: 'text',
|
|
84
|
+
name: 'apiKey',
|
|
85
|
+
message: 'App API key (from the dashboard):',
|
|
86
|
+
validate: value => value.length > 0,
|
|
41
87
|
},
|
|
42
88
|
{
|
|
43
89
|
type: 'select',
|
|
@@ -46,83 +92,19 @@ export async function init(options) {
|
|
|
46
92
|
choices: [
|
|
47
93
|
{ title: 'Production', value: 'production' },
|
|
48
94
|
{ title: 'Staging', value: 'staging' },
|
|
49
|
-
{ title: 'Development', value: 'development' }
|
|
50
|
-
]
|
|
95
|
+
{ title: 'Development', value: 'development' },
|
|
96
|
+
],
|
|
51
97
|
},
|
|
52
|
-
{
|
|
53
|
-
type: 'confirm',
|
|
54
|
-
name: 'autoUpdate',
|
|
55
|
-
message: 'Enable automatic updates?',
|
|
56
|
-
initial: true
|
|
57
|
-
}
|
|
58
98
|
]);
|
|
59
99
|
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
serverUrl: '${config.serverUrl}',
|
|
64
|
-
channel: '${config.channel}',
|
|
65
|
-
autoUpdate: ${config.autoUpdate},
|
|
66
|
-
|
|
67
|
-
// Security
|
|
68
|
-
publicKey: \`-----BEGIN PUBLIC KEY-----
|
|
69
|
-
YOUR_PUBLIC_KEY_HERE
|
|
70
|
-
-----END PUBLIC KEY-----\`,
|
|
71
|
-
|
|
72
|
-
// Update behavior
|
|
73
|
-
updateStrategy: 'immediate', // immediate, on-app-start, on-app-resume
|
|
74
|
-
checkInterval: 60 * 60 * 1000, // 1 hour
|
|
75
|
-
|
|
76
|
-
// Optional callbacks
|
|
77
|
-
onUpdateAvailable: (update) => {
|
|
78
|
-
console.log('Update available:', update.version);
|
|
79
|
-
},
|
|
80
|
-
|
|
81
|
-
onUpdateDownloaded: (update) => {
|
|
82
|
-
console.log('Update downloaded:', update.version);
|
|
83
|
-
},
|
|
84
|
-
|
|
85
|
-
onUpdateFailed: (error) => {
|
|
86
|
-
console.error('Update failed:', error);
|
|
87
|
-
}
|
|
88
|
-
};
|
|
89
|
-
`;
|
|
90
|
-
|
|
91
|
-
await fs.writeFile('./native-update.config.js', configContent);
|
|
92
|
-
|
|
93
|
-
// Create example integration if requested
|
|
94
|
-
if (options.example) {
|
|
95
|
-
const exampleCode = `import { NativeUpdate } from 'native-update';
|
|
96
|
-
import config from './native-update.config.js';
|
|
97
|
-
|
|
98
|
-
// Initialize on app start
|
|
99
|
-
export async function initializeUpdates() {
|
|
100
|
-
try {
|
|
101
|
-
// Configure the plugin
|
|
102
|
-
await NativeUpdate.configure(config);
|
|
103
|
-
|
|
104
|
-
// Check for updates
|
|
105
|
-
const update = await NativeUpdate.checkForUpdate();
|
|
106
|
-
|
|
107
|
-
if (update.available) {
|
|
108
|
-
console.log(\`Update available: \${update.version}\`);
|
|
109
|
-
|
|
110
|
-
// Download in background
|
|
111
|
-
await NativeUpdate.downloadUpdate();
|
|
112
|
-
|
|
113
|
-
// Apply on next restart
|
|
114
|
-
await NativeUpdate.installOnNextRestart();
|
|
100
|
+
if (!config.appId || !config.serverUrl || !config.apiKey || !config.channel) {
|
|
101
|
+
console.log(chalk.yellow('Initialization cancelled.'));
|
|
102
|
+
return;
|
|
115
103
|
}
|
|
116
|
-
} catch (error) {
|
|
117
|
-
console.error('Update check failed:', error);
|
|
118
|
-
}
|
|
119
|
-
}
|
|
120
104
|
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
await fs.writeFile('./native-update-example.js', exampleCode);
|
|
105
|
+
await fs.writeFile('./native-update.config.js', renderConfig(config));
|
|
106
|
+
if (options.example) {
|
|
107
|
+
await fs.writeFile('./native-update-example.js', renderExample());
|
|
126
108
|
console.log(chalk.gray(' Created: native-update-example.js'));
|
|
127
109
|
}
|
|
128
110
|
|
|
@@ -131,16 +113,15 @@ initializeUpdates();
|
|
|
131
113
|
console.log(chalk.bold('Next steps:'));
|
|
132
114
|
console.log(chalk.gray(' 1. Generate signing keys:'));
|
|
133
115
|
console.log(chalk.cyan(' npx native-update keys generate'));
|
|
134
|
-
console.log(chalk.gray(' 2. Add public key to native-update.config.js'));
|
|
135
|
-
console.log(chalk.gray(' 3. Import and
|
|
136
|
-
|
|
116
|
+
console.log(chalk.gray(' 2. Add the public key to native-update.config.js'));
|
|
117
|
+
console.log(chalk.gray(' 3. Import and call initializeUpdates() after your app renders'));
|
|
118
|
+
|
|
137
119
|
if (options.backend !== 'custom') {
|
|
138
120
|
console.log(chalk.gray(` 4. Create ${options.backend} backend:`));
|
|
139
121
|
console.log(chalk.cyan(` npx native-update backend create ${options.backend}`));
|
|
140
122
|
}
|
|
141
|
-
|
|
142
123
|
} catch (error) {
|
|
143
124
|
console.error(chalk.red('❌ Initialization failed:'), error.message);
|
|
144
125
|
process.exit(1);
|
|
145
126
|
}
|
|
146
|
-
}
|
|
127
|
+
}
|
|
@@ -2,8 +2,8 @@ import chalk from 'chalk';
|
|
|
2
2
|
import fs from 'fs/promises';
|
|
3
3
|
import path from 'path';
|
|
4
4
|
import os from 'os';
|
|
5
|
-
import {
|
|
6
|
-
import {
|
|
5
|
+
import { createReadStream } from 'fs';
|
|
6
|
+
import { archiveDirectory } from '../lib/archive-directory.js';
|
|
7
7
|
|
|
8
8
|
/** Where the hosted backend lives unless told otherwise. */
|
|
9
9
|
export const DEFAULT_SERVER = 'https://nativeupdatebe.aoneahsan.com';
|
|
@@ -223,17 +223,12 @@ export async function resolveBundle(target) {
|
|
|
223
223
|
|
|
224
224
|
console.log(chalk.gray(` Zipping ${target}…`));
|
|
225
225
|
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
}
|
|
232
|
-
|
|
233
|
-
archive.pipe(output);
|
|
234
|
-
archive.directory(target, false);
|
|
235
|
-
await archive.finalize();
|
|
236
|
-
await done;
|
|
226
|
+
try {
|
|
227
|
+
await archiveDirectory(target, zipPath);
|
|
228
|
+
} catch (error) {
|
|
229
|
+
await fs.rm(tempDir, { recursive: true, force: true });
|
|
230
|
+
throw error;
|
|
231
|
+
}
|
|
237
232
|
|
|
238
233
|
return {
|
|
239
234
|
path: zipPath,
|
|
@@ -88,9 +88,9 @@ export async function startServer(options) {
|
|
|
88
88
|
console.log(chalk.gray(` GET /bundles/<filename> - Download bundle`));
|
|
89
89
|
console.log(chalk.gray(` GET /health - Health check`));
|
|
90
90
|
console.log('');
|
|
91
|
-
console.log(chalk.yellow('
|
|
92
|
-
console.log(chalk.
|
|
91
|
+
console.log(chalk.yellow('Inspect generated bundles with these local endpoints.'));
|
|
92
|
+
console.log(chalk.gray('The v5 device SDK needs an HTTPS backend with /v1/updates/check.'));
|
|
93
93
|
console.log('');
|
|
94
94
|
console.log(chalk.gray('Press Ctrl+C to stop'));
|
|
95
95
|
});
|
|
96
|
-
}
|
|
96
|
+
}
|
package/cli/index.js
CHANGED
|
@@ -56,7 +56,7 @@ bundleCmd
|
|
|
56
56
|
|
|
57
57
|
${chalk.bold('Examples:')}
|
|
58
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
|
|
59
|
+
${chalk.green('npx native-update deploy patch.zip --app 550e8400-e29b-41d4-a716-446655440000 --version 1.0.1 --payload-type dart_aot --wait')}`)
|
|
60
60
|
.option('-o, --output <file>', 'Patch ZIP to write', 'flutter-patch.zip')
|
|
61
61
|
.option('--assets <dir>', 'Also ship the files in this folder, read with NativeUpdate.file()')
|
|
62
62
|
.action(async (apk, options) => {
|
|
@@ -240,17 +240,17 @@ remoteAuthOptions(
|
|
|
240
240
|
|
|
241
241
|
${chalk.bold('Examples:')}
|
|
242
242
|
${chalk.gray('# Deploy a built web directory (zipped for you)')}
|
|
243
|
-
${chalk.green('npx native-update deploy ./dist --app
|
|
243
|
+
${chalk.green('npx native-update deploy ./dist --app 550e8400-e29b-41d4-a716-446655440000 --version 1.2.0')}
|
|
244
244
|
|
|
245
245
|
${chalk.gray('# Block until the release is actually live (recommended in CI)')}
|
|
246
|
-
${chalk.green('npx native-update deploy ./dist --app
|
|
246
|
+
${chalk.green('npx native-update deploy ./dist --app 550e8400-e29b-41d4-a716-446655440000 --wait')}
|
|
247
247
|
|
|
248
248
|
${chalk.gray('# OTA tag: 1.16.1 → 1.16.1-nu1, then -nu2 … until the version changes')}
|
|
249
|
-
${chalk.green('npx native-update deploy ./dist --app
|
|
249
|
+
${chalk.green('npx native-update deploy ./dist --app 550e8400-e29b-41d4-a716-446655440000 --ota-tag nu --wait')}
|
|
250
250
|
|
|
251
251
|
${chalk.gray('# Staged rollout with release notes')}
|
|
252
252
|
${chalk.green('npx native-update deploy ./bundle.zip --app 12 --version 1.2.0 --rollout 10 --notes "Bug fixes"')}`)
|
|
253
|
-
.requiredOption('-a, --app <appIdOrNumericId>', 'App to deploy to (app_id
|
|
253
|
+
.requiredOption('-a, --app <appIdOrNumericId>', 'App to deploy to (dashboard app_id UUID, or numeric id)')
|
|
254
254
|
.option('-v, --version <version>', 'Bundle version (defaults to ./package.json version)')
|
|
255
255
|
.option('-c, --channel <channel>', 'Release channel', 'production')
|
|
256
256
|
.option('-n, --notes <text>', 'Release notes')
|
|
@@ -277,7 +277,7 @@ remoteAuthOptions(
|
|
|
277
277
|
program
|
|
278
278
|
.command('ota-tag')
|
|
279
279
|
.description('Print the next OTA tag for this app and channel, e.g. 1.16.1-nu3')
|
|
280
|
-
.requiredOption('-a, --app <appIdOrNumericId>', 'App (app_id
|
|
280
|
+
.requiredOption('-a, --app <appIdOrNumericId>', 'App (dashboard app_id UUID, or numeric id)')
|
|
281
281
|
.option('-v, --version <version>', 'Base version (defaults to ./package.json version)')
|
|
282
282
|
.option('-c, --channel <channel>', 'Release channel', 'production')
|
|
283
283
|
.option('--ota-tag <prefix>', 'Tag prefix', 'nu')
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
import fs from 'node:fs/promises';
|
|
2
|
+
import { createWriteStream } from 'node:fs';
|
|
3
|
+
import path from 'node:path';
|
|
4
|
+
import yazl from 'yazl';
|
|
5
|
+
|
|
6
|
+
/** Write a directory as a ZIP without following links outside the selected build. */
|
|
7
|
+
export async function archiveDirectory(source, destination) {
|
|
8
|
+
const root = path.resolve(source);
|
|
9
|
+
const files = [];
|
|
10
|
+
const emptyDirectories = [];
|
|
11
|
+
|
|
12
|
+
async function collect(directory) {
|
|
13
|
+
const entries = (await fs.readdir(directory, { withFileTypes: true }))
|
|
14
|
+
.sort((a, b) => a.name.localeCompare(b.name));
|
|
15
|
+
if (entries.length === 0 && directory !== root) {
|
|
16
|
+
emptyDirectories.push(path.relative(root, directory).split(path.sep).join('/'));
|
|
17
|
+
}
|
|
18
|
+
for (const entry of entries) {
|
|
19
|
+
const fullPath = path.join(directory, entry.name);
|
|
20
|
+
if (entry.isSymbolicLink()) {
|
|
21
|
+
throw new Error(`Refusing to archive a symbolic link: ${path.relative(root, fullPath)}`);
|
|
22
|
+
}
|
|
23
|
+
if (entry.isDirectory()) {
|
|
24
|
+
await collect(fullPath);
|
|
25
|
+
} else if (entry.isFile()) {
|
|
26
|
+
files.push({ fullPath, name: path.relative(root, fullPath).split(path.sep).join('/') });
|
|
27
|
+
} else {
|
|
28
|
+
throw new Error(`Unsupported archive entry: ${path.relative(root, fullPath)}`);
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
await collect(root);
|
|
34
|
+
const zip = new yazl.ZipFile();
|
|
35
|
+
for (const name of emptyDirectories) zip.addEmptyDirectory(name);
|
|
36
|
+
for (const { fullPath, name } of files) zip.addFile(fullPath, name, { compressionLevel: 9 });
|
|
37
|
+
|
|
38
|
+
try {
|
|
39
|
+
await new Promise((resolve, reject) => {
|
|
40
|
+
const output = createWriteStream(destination);
|
|
41
|
+
zip.outputStream.on('error', (error) => {
|
|
42
|
+
output.destroy();
|
|
43
|
+
reject(error);
|
|
44
|
+
});
|
|
45
|
+
output.on('error', reject);
|
|
46
|
+
output.on('close', resolve);
|
|
47
|
+
zip.outputStream.pipe(output);
|
|
48
|
+
zip.end();
|
|
49
|
+
});
|
|
50
|
+
} catch (error) {
|
|
51
|
+
await fs.rm(destination, { force: true });
|
|
52
|
+
throw error;
|
|
53
|
+
}
|
|
54
|
+
}
|
package/cli/package.json
CHANGED
|
@@ -20,6 +20,7 @@
|
|
|
20
20
|
* X-App-Version: native app version (optional)
|
|
21
21
|
* X-Client-Sdk: capacitor (the server then offers only `web_bundle` builds)
|
|
22
22
|
* X-Sdk-Version: this plugin's version (SDK_VERSION)
|
|
23
|
+
* Accept-Language: device or browser language for translated server messages
|
|
23
24
|
* X-Android-Package: applicationId (optional; sent when identity.platform === 'android')
|
|
24
25
|
* X-Android-Cert-Sha256: signing cert SHA-256, hex (optional)
|
|
25
26
|
* X-Android-Cert-Sha1: signing cert SHA-1, hex (optional)
|
|
@@ -60,7 +61,7 @@ import type { AppIdentity } from '../types/app-identity';
|
|
|
60
61
|
* This plugin's version, sent as `X-Sdk-Version`. Kept equal to package.json (and to the Kotlin and Swift
|
|
61
62
|
* constants) by tests/sdk-version.test.ts.
|
|
62
63
|
*/
|
|
63
|
-
export declare const SDK_VERSION = "5.0.
|
|
64
|
+
export declare const SDK_VERSION = "5.0.2";
|
|
64
65
|
/** Request inputs for a single backend update check. */
|
|
65
66
|
export interface UpdateCheckRequest {
|
|
66
67
|
/** API key issued by the dashboard; sent as `X-API-Key`. Required. */
|
|
@@ -20,6 +20,7 @@
|
|
|
20
20
|
* X-App-Version: native app version (optional)
|
|
21
21
|
* X-Client-Sdk: capacitor (the server then offers only `web_bundle` builds)
|
|
22
22
|
* X-Sdk-Version: this plugin's version (SDK_VERSION)
|
|
23
|
+
* Accept-Language: device or browser language for translated server messages
|
|
23
24
|
* X-Android-Package: applicationId (optional; sent when identity.platform === 'android')
|
|
24
25
|
* X-Android-Cert-Sha256: signing cert SHA-256, hex (optional)
|
|
25
26
|
* X-Android-Cert-Sha1: signing cert SHA-1, hex (optional)
|
|
@@ -59,7 +60,7 @@
|
|
|
59
60
|
* This plugin's version, sent as `X-Sdk-Version`. Kept equal to package.json (and to the Kotlin and Swift
|
|
60
61
|
* constants) by tests/sdk-version.test.ts.
|
|
61
62
|
*/
|
|
62
|
-
export const SDK_VERSION = '5.0.
|
|
63
|
+
export const SDK_VERSION = '5.0.2';
|
|
63
64
|
/**
|
|
64
65
|
* Perform one update check against the Native Update backend.
|
|
65
66
|
*
|
|
@@ -80,6 +81,9 @@ export async function checkForUpdate(baseUrl, req) {
|
|
|
80
81
|
'X-Client-Sdk': 'capacitor',
|
|
81
82
|
'X-Sdk-Version': SDK_VERSION,
|
|
82
83
|
};
|
|
84
|
+
if (typeof navigator !== 'undefined' && navigator.language) {
|
|
85
|
+
headers['Accept-Language'] = navigator.language;
|
|
86
|
+
}
|
|
83
87
|
if (req.appVersion) {
|
|
84
88
|
headers['X-App-Version'] = req.appVersion;
|
|
85
89
|
}
|
|
@@ -5,7 +5,8 @@ export type { AppIdentity } from './types/app-identity';
|
|
|
5
5
|
*/
|
|
6
6
|
export interface LiveUpdatePlugin {
|
|
7
7
|
/**
|
|
8
|
-
*
|
|
8
|
+
* Check for an update. On Android this does not download or apply it.
|
|
9
|
+
* To install across platforms, call checkForUpdate(), downloadUpdate(), then applyUpdate().
|
|
9
10
|
*/
|
|
10
11
|
sync(options?: SyncOptions): Promise<SyncResult>;
|
|
11
12
|
/**
|
|
@@ -114,11 +115,13 @@ export interface AppUpdatePlugin {
|
|
|
114
115
|
*/
|
|
115
116
|
performImmediateUpdate(): Promise<void>;
|
|
116
117
|
/**
|
|
117
|
-
* Start flexible
|
|
118
|
+
* Start Play's flexible download. When appUpdateReady fires, ask the user
|
|
119
|
+
* when to restart; this method does not install the downloaded update.
|
|
118
120
|
*/
|
|
119
121
|
startFlexibleUpdate(): Promise<void>;
|
|
120
122
|
/**
|
|
121
|
-
*
|
|
123
|
+
* Install a downloaded flexible update and restart the app. Call only after
|
|
124
|
+
* appUpdateReady and the user's confirmation.
|
|
122
125
|
*/
|
|
123
126
|
completeFlexibleUpdate(): Promise<void>;
|
|
124
127
|
/**
|
|
@@ -468,11 +471,17 @@ export interface OpenAppStoreOptions {
|
|
|
468
471
|
* App Review Types
|
|
469
472
|
*/
|
|
470
473
|
export interface ReviewResult {
|
|
474
|
+
/** Whether the native review API accepted the request; not proof that a sheet appeared. */
|
|
475
|
+
shown?: boolean;
|
|
476
|
+
/** Compatibility alias for shown. */
|
|
471
477
|
displayed: boolean;
|
|
472
478
|
error?: string;
|
|
473
479
|
reason?: string;
|
|
474
480
|
}
|
|
475
481
|
export interface CanRequestReviewResult {
|
|
482
|
+
/** Native wire field; true when the plugin allows a review request. */
|
|
483
|
+
allowed?: boolean;
|
|
484
|
+
/** Compatibility alias for allowed. */
|
|
476
485
|
canRequest: boolean;
|
|
477
486
|
reason?: string;
|
|
478
487
|
}
|
|
@@ -610,13 +619,19 @@ export declare enum UpdateErrorCode {
|
|
|
610
619
|
INSTALL_ERROR = "INSTALL_ERROR",
|
|
611
620
|
ROLLBACK_ERROR = "ROLLBACK_ERROR",
|
|
612
621
|
VERSION_MISMATCH = "VERSION_MISMATCH",
|
|
622
|
+
/** @deprecated Reserved for compatibility; the 5.x SDK does not emit this code. */
|
|
613
623
|
PERMISSION_DENIED = "PERMISSION_DENIED",
|
|
614
624
|
UPDATE_NOT_AVAILABLE = "UPDATE_NOT_AVAILABLE",
|
|
625
|
+
/** @deprecated Reserved for compatibility; the 5.x SDK does not emit this code. */
|
|
615
626
|
UPDATE_IN_PROGRESS = "UPDATE_IN_PROGRESS",
|
|
627
|
+
/** @deprecated Reserved for compatibility; the 5.x SDK does not emit this code. */
|
|
616
628
|
UPDATE_CANCELLED = "UPDATE_CANCELLED",
|
|
617
629
|
PLATFORM_NOT_SUPPORTED = "PLATFORM_NOT_SUPPORTED",
|
|
630
|
+
/** @deprecated Reserved for compatibility; the 5.x SDK does not emit this code. */
|
|
618
631
|
REVIEW_NOT_SUPPORTED = "REVIEW_NOT_SUPPORTED",
|
|
632
|
+
/** @deprecated Reserved for compatibility; the 5.x SDK does not emit this code. */
|
|
619
633
|
QUOTA_EXCEEDED = "QUOTA_EXCEEDED",
|
|
634
|
+
/** @deprecated Reserved for compatibility; the 5.x SDK does not emit this code. */
|
|
620
635
|
CONDITIONS_NOT_MET = "CONDITIONS_NOT_MET",
|
|
621
636
|
INVALID_CONFIG = "INVALID_CONFIG",
|
|
622
637
|
NOT_CONFIGURED = "NOT_CONFIGURED",
|
|
@@ -669,6 +684,7 @@ export interface AppUpdateAvailableEvent {
|
|
|
669
684
|
storeUrl?: string;
|
|
670
685
|
}
|
|
671
686
|
export interface AppUpdateReadyEvent {
|
|
687
|
+
/** Android sends this when Play finishes downloading; localise your own prompt. */
|
|
672
688
|
message: string;
|
|
673
689
|
}
|
|
674
690
|
export interface AppUpdateFailedEvent {
|
|
@@ -809,8 +825,9 @@ export interface PluginInitConfig {
|
|
|
809
825
|
/**
|
|
810
826
|
* API key bound to this app in the Native Update dashboard. Sent as
|
|
811
827
|
* the `X-API-Key` header on every request to the backend. As of v2
|
|
812
|
-
* the plugin does not persist this across sessions
|
|
813
|
-
*
|
|
828
|
+
* the plugin does not persist this across sessions. Web apps pass it
|
|
829
|
+
* on every boot; Android apps may package it in `plugins.NativeUpdate`
|
|
830
|
+
* and restrict that client key to their package and signing certificate.
|
|
814
831
|
*/
|
|
815
832
|
apiKey?: string;
|
|
816
833
|
/**
|
|
@@ -865,7 +882,9 @@ export interface PluginInitConfig {
|
|
|
865
882
|
*/
|
|
866
883
|
export interface NativeUpdatePlugin extends NativeUpdateCombinedPlugin, NativeUpdateListeners {
|
|
867
884
|
/**
|
|
868
|
-
* Initialize the plugin with configuration
|
|
885
|
+
* Initialize the plugin with configuration. On Android, values from
|
|
886
|
+
* `plugins.NativeUpdate` in capacitor.config.ts are packaged defaults;
|
|
887
|
+
* explicit fields here override them.
|
|
869
888
|
*/
|
|
870
889
|
initialize(config: PluginInitConfig): Promise<void>;
|
|
871
890
|
/**
|
package/dist/esm/definitions.js
CHANGED
|
@@ -87,15 +87,21 @@ export var UpdateErrorCode;
|
|
|
87
87
|
UpdateErrorCode["ROLLBACK_ERROR"] = "ROLLBACK_ERROR";
|
|
88
88
|
UpdateErrorCode["VERSION_MISMATCH"] = "VERSION_MISMATCH";
|
|
89
89
|
// Permission errors
|
|
90
|
+
/** @deprecated Reserved for compatibility; the 5.x SDK does not emit this code. */
|
|
90
91
|
UpdateErrorCode["PERMISSION_DENIED"] = "PERMISSION_DENIED";
|
|
91
92
|
// App update errors
|
|
92
93
|
UpdateErrorCode["UPDATE_NOT_AVAILABLE"] = "UPDATE_NOT_AVAILABLE";
|
|
94
|
+
/** @deprecated Reserved for compatibility; the 5.x SDK does not emit this code. */
|
|
93
95
|
UpdateErrorCode["UPDATE_IN_PROGRESS"] = "UPDATE_IN_PROGRESS";
|
|
96
|
+
/** @deprecated Reserved for compatibility; the 5.x SDK does not emit this code. */
|
|
94
97
|
UpdateErrorCode["UPDATE_CANCELLED"] = "UPDATE_CANCELLED";
|
|
95
98
|
UpdateErrorCode["PLATFORM_NOT_SUPPORTED"] = "PLATFORM_NOT_SUPPORTED";
|
|
96
99
|
// Review errors
|
|
100
|
+
/** @deprecated Reserved for compatibility; the 5.x SDK does not emit this code. */
|
|
97
101
|
UpdateErrorCode["REVIEW_NOT_SUPPORTED"] = "REVIEW_NOT_SUPPORTED";
|
|
102
|
+
/** @deprecated Reserved for compatibility; the 5.x SDK does not emit this code. */
|
|
98
103
|
UpdateErrorCode["QUOTA_EXCEEDED"] = "QUOTA_EXCEEDED";
|
|
104
|
+
/** @deprecated Reserved for compatibility; the 5.x SDK does not emit this code. */
|
|
99
105
|
UpdateErrorCode["CONDITIONS_NOT_MET"] = "CONDITIONS_NOT_MET";
|
|
100
106
|
// General errors
|
|
101
107
|
UpdateErrorCode["INVALID_CONFIG"] = "INVALID_CONFIG";
|
package/dist/esm/plugin.js
CHANGED
|
@@ -594,12 +594,14 @@ class NativeUpdatePluginWeb {
|
|
|
594
594
|
// AppReviewPlugin methods
|
|
595
595
|
async requestReview() {
|
|
596
596
|
return {
|
|
597
|
+
shown: false,
|
|
597
598
|
displayed: false,
|
|
598
599
|
error: 'Reviews are not supported on web',
|
|
599
600
|
};
|
|
600
601
|
}
|
|
601
602
|
async canRequestReview() {
|
|
602
603
|
return {
|
|
604
|
+
allowed: false,
|
|
603
605
|
canRequest: false,
|
|
604
606
|
reason: 'Reviews are not supported on web',
|
|
605
607
|
};
|
package/dist/esm/web.js
CHANGED
|
@@ -459,6 +459,7 @@ export class NativeUpdateWeb extends WebPlugin {
|
|
|
459
459
|
const canRequest = await this.canRequestReview();
|
|
460
460
|
if (!canRequest.canRequest) {
|
|
461
461
|
return {
|
|
462
|
+
shown: false,
|
|
462
463
|
displayed: false,
|
|
463
464
|
error: canRequest.reason,
|
|
464
465
|
};
|
|
@@ -479,6 +480,7 @@ export class NativeUpdateWeb extends WebPlugin {
|
|
|
479
480
|
}
|
|
480
481
|
// Web platform returns displayed: false because we cannot show native review dialog
|
|
481
482
|
return {
|
|
483
|
+
shown: false,
|
|
482
484
|
displayed: false,
|
|
483
485
|
};
|
|
484
486
|
}
|