native-update 4.4.6 → 5.0.1
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/NativeUpdate.podspec +2 -2
- package/README.md +31 -23
- package/android/build.gradle +9 -23
- package/android/gradle/wrapper/gradle-wrapper.properties +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/android/variables.gradle +0 -1
- package/cli/commands/init.js +68 -87
- package/cli/commands/server-start.js +3 -3
- package/cli/index.js +6 -6
- 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 +25 -24
- package/docs/MIGRATION.md +8 -0
- package/docs/protocol/CLIENT-PROTOCOL.md +1 -0
- package/ios/Plugin/AppReview/AppReviewPlugin.swift +10 -20
- package/ios/Plugin/BackgroundUpdate/BackgroundNotificationManager.swift +1 -5
- package/ios/Plugin/BackgroundUpdate/BackgroundUpdatePlugin.swift +10 -27
- package/ios/Plugin/LiveUpdate/LiveUpdatePlugin.swift +2 -1
- package/ios/Plugin/NativeUpdatePlugin.swift +1 -14
- package/package.json +22 -14
|
@@ -18,6 +18,8 @@ class NativeUpdatePlugin : Plugin() {
|
|
|
18
18
|
private lateinit var backgroundUpdatePlugin: BackgroundUpdatePlugin
|
|
19
19
|
private lateinit var securityManager: SecurityManager
|
|
20
20
|
private var isInitialized = false
|
|
21
|
+
private var capacitorConfiguration: JSObject? = null
|
|
22
|
+
private var initializedFromCapacitorConfig = false
|
|
21
23
|
|
|
22
24
|
/** The configuration that took the lock, so an identical repeat can be told apart from a change (ISSUE-16). */
|
|
23
25
|
private var appliedConfiguration: String? = null
|
|
@@ -31,6 +33,21 @@ class NativeUpdatePlugin : Plugin() {
|
|
|
31
33
|
appReviewPlugin = AppReviewPlugin(activity, context)
|
|
32
34
|
backgroundUpdatePlugin = BackgroundUpdatePlugin(context)
|
|
33
35
|
securityManager = SecurityManager(context)
|
|
36
|
+
|
|
37
|
+
val packagedConfig = getConfig().configJSON
|
|
38
|
+
if (packagedConfig.length() > 0) {
|
|
39
|
+
capacitorConfiguration = JSObject(packagedConfig.toString())
|
|
40
|
+
if (canInitializeFromCapacitorConfiguration(capacitorConfiguration!!)) {
|
|
41
|
+
try {
|
|
42
|
+
applyConfiguration(capacitorConfiguration!!)
|
|
43
|
+
appliedConfiguration = configurationFingerprint(capacitorConfiguration!!)
|
|
44
|
+
isInitialized = true
|
|
45
|
+
initializedFromCapacitorConfig = true
|
|
46
|
+
} catch (_: Exception) {
|
|
47
|
+
// An invalid native block can still be replaced by initialize().
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
}
|
|
34
51
|
|
|
35
52
|
// Set up app update event listener
|
|
36
53
|
appUpdatePlugin.setEventListener { eventName, data ->
|
|
@@ -83,14 +100,15 @@ class NativeUpdatePlugin : Plugin() {
|
|
|
83
100
|
@PluginMethod
|
|
84
101
|
fun initialize(call: PluginCall) {
|
|
85
102
|
try {
|
|
86
|
-
val config = call.getObject("config") ?: call.data
|
|
87
|
-
if (isInitialized) {
|
|
103
|
+
val config = mergeWithCapacitorConfiguration(call.getObject("config") ?: call.data)
|
|
104
|
+
if (isInitialized && !initializedFromCapacitorConfig) {
|
|
88
105
|
rejectUnlessSameConfiguration(call, config)
|
|
89
106
|
return
|
|
90
107
|
}
|
|
91
108
|
applyConfiguration(config)
|
|
92
109
|
appliedConfiguration = configurationFingerprint(config)
|
|
93
110
|
isInitialized = true
|
|
111
|
+
initializedFromCapacitorConfig = false
|
|
94
112
|
call.resolve()
|
|
95
113
|
} catch (e: Exception) {
|
|
96
114
|
call.reject("Initialization failed", e)
|
|
@@ -122,8 +140,8 @@ class NativeUpdatePlugin : Plugin() {
|
|
|
122
140
|
// configure(UpdateConfig) — nested sections
|
|
123
141
|
// Before this fix, only the wrapped shape reached native, so the
|
|
124
142
|
// flat initialize() every consumer uses configured NOTHING here.
|
|
125
|
-
val config = call.getObject("config") ?: call.data
|
|
126
|
-
if (isInitialized) {
|
|
143
|
+
val config = mergeWithCapacitorConfiguration(call.getObject("config") ?: call.data)
|
|
144
|
+
if (isInitialized && !initializedFromCapacitorConfig) {
|
|
127
145
|
rejectUnlessSameConfiguration(call, config)
|
|
128
146
|
return
|
|
129
147
|
}
|
|
@@ -132,6 +150,7 @@ class NativeUpdatePlugin : Plugin() {
|
|
|
132
150
|
applyConfiguration(config)
|
|
133
151
|
appliedConfiguration = configurationFingerprint(config)
|
|
134
152
|
isInitialized = true
|
|
153
|
+
initializedFromCapacitorConfig = false
|
|
135
154
|
call.resolve()
|
|
136
155
|
} catch (e: Exception) {
|
|
137
156
|
call.reject("Configuration failed", e)
|
|
@@ -154,6 +173,46 @@ class NativeUpdatePlugin : Plugin() {
|
|
|
154
173
|
/** A stable comparison form; injected JS objects (filesystem, preferences) arrive as {} and compare equal. */
|
|
155
174
|
private fun configurationFingerprint(config: JSObject): String = config.toString()
|
|
156
175
|
|
|
176
|
+
internal fun canInitializeFromCapacitorConfiguration(config: JSObject): Boolean {
|
|
177
|
+
val live = effectiveLiveUpdateConfig(config) ?: return true
|
|
178
|
+
val requiresSignature = live.getBool("requireSignature") ?: config.getBool("requireSignature") ?: true
|
|
179
|
+
return !live.getString("appId").isNullOrBlank() &&
|
|
180
|
+
live.getString("serverUrl")?.startsWith("https://") == true &&
|
|
181
|
+
!live.getString("apiKey").isNullOrBlank() &&
|
|
182
|
+
(!requiresSignature || !live.getString("publicKey").isNullOrBlank())
|
|
183
|
+
}
|
|
184
|
+
|
|
185
|
+
/** The packaged Capacitor block supplies defaults; JS initialization wins per key. */
|
|
186
|
+
private fun mergeWithCapacitorConfiguration(overrides: JSObject): JSObject =
|
|
187
|
+
mergeWithCapacitorConfiguration(capacitorConfiguration, overrides)
|
|
188
|
+
|
|
189
|
+
internal fun mergeWithCapacitorConfiguration(defaults: JSObject?, overrides: JSObject): JSObject {
|
|
190
|
+
if (defaults == null) return overrides
|
|
191
|
+
val merged = mergeObjects(defaults, overrides)
|
|
192
|
+
val defaultLive = effectiveLiveUpdateConfig(defaults)
|
|
193
|
+
val overrideLive = effectiveLiveUpdateConfig(overrides)
|
|
194
|
+
if (defaultLive != null || overrideLive != null) {
|
|
195
|
+
merged.put("liveUpdate", mergeObjects(defaultLive ?: JSObject(), overrideLive ?: JSObject()))
|
|
196
|
+
}
|
|
197
|
+
return merged
|
|
198
|
+
}
|
|
199
|
+
|
|
200
|
+
private fun mergeObjects(defaults: JSObject, overrides: JSObject): JSObject {
|
|
201
|
+
val merged = JSObject(defaults.toString())
|
|
202
|
+
val keys = overrides.keys()
|
|
203
|
+
while (keys.hasNext()) {
|
|
204
|
+
val key = keys.next()
|
|
205
|
+
val existing = merged.getJSObject(key)
|
|
206
|
+
val replacement = overrides.getJSObject(key)
|
|
207
|
+
merged.put(key, if (existing != null && replacement != null) {
|
|
208
|
+
mergeObjects(existing, replacement)
|
|
209
|
+
} else {
|
|
210
|
+
overrides.get(key)
|
|
211
|
+
})
|
|
212
|
+
}
|
|
213
|
+
return merged
|
|
214
|
+
}
|
|
215
|
+
|
|
157
216
|
private fun applyConfiguration(config: JSObject) {
|
|
158
217
|
securityManager.configure(config)
|
|
159
218
|
normalizeLiveUpdateConfig(config)?.let(liveUpdatePlugin::configure)
|
|
@@ -170,7 +229,10 @@ class NativeUpdatePlugin : Plugin() {
|
|
|
170
229
|
private fun buildFlatLiveUpdateConfig(config: JSObject): JSObject? {
|
|
171
230
|
val serverUrl = config.getString("serverUrl") ?: config.getString("baseUrl")
|
|
172
231
|
val apiKey = config.getString("apiKey")
|
|
173
|
-
|
|
232
|
+
val liveKeys = listOf("serverUrl", "baseUrl", "apiKey", "appId", "channel", "publicKey",
|
|
233
|
+
"requireSignature", "allowUnsignedDevelopmentUpdates", "checksumAlgorithm", "maxBundleSize",
|
|
234
|
+
"maxUncompressedBundleSize", "enableDeltaUpdates", "allowedHosts")
|
|
235
|
+
if (liveKeys.none(config::has)) {
|
|
174
236
|
return null
|
|
175
237
|
}
|
|
176
238
|
|
|
@@ -195,9 +257,19 @@ class NativeUpdatePlugin : Plugin() {
|
|
|
195
257
|
return liveUpdate
|
|
196
258
|
}
|
|
197
259
|
|
|
260
|
+
private fun effectiveLiveUpdateConfig(config: JSObject): JSObject? {
|
|
261
|
+
val flat = buildFlatLiveUpdateConfig(config)
|
|
262
|
+
val nested = config.getJSObject("liveUpdate")
|
|
263
|
+
return when {
|
|
264
|
+
flat != null && nested != null -> mergeObjects(flat, nested)
|
|
265
|
+
nested != null -> nested
|
|
266
|
+
else -> flat
|
|
267
|
+
}
|
|
268
|
+
}
|
|
269
|
+
|
|
198
270
|
/** Merge root security controls into both documented configuration shapes. */
|
|
199
271
|
private fun normalizeLiveUpdateConfig(config: JSObject): JSObject? {
|
|
200
|
-
val liveUpdate =
|
|
272
|
+
val liveUpdate = effectiveLiveUpdateConfig(config) ?: return null
|
|
201
273
|
if (!liveUpdate.has("security")) {
|
|
202
274
|
config.getJSObject("security")?.let { liveUpdate.put("security", it) }
|
|
203
275
|
}
|
|
@@ -258,6 +330,7 @@ class NativeUpdatePlugin : Plugin() {
|
|
|
258
330
|
liveUpdatePlugin.reset(call)
|
|
259
331
|
isInitialized = false
|
|
260
332
|
appliedConfiguration = null
|
|
333
|
+
initializedFromCapacitorConfig = false
|
|
261
334
|
} catch (e: Exception) {
|
|
262
335
|
call.reject("Reset failed", e)
|
|
263
336
|
}
|
package/android/variables.gradle
CHANGED
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
|
+
}
|
|
@@ -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')
|
|
@@ -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 = "
|
|
64
|
+
export declare const SDK_VERSION = "5.0.1";
|
|
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 = '
|
|
63
|
+
export const SDK_VERSION = '5.0.1';
|
|
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
|
}
|