native-update 3.1.5 → 3.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/AI-INTEGRATION-GUIDE.md +199 -3
- package/android/src/main/java/com/aoneahsan/nativeupdate/LiveUpdatePlugin.kt +67 -1
- package/android/src/main/java/com/aoneahsan/nativeupdate/NativeUpdatePlugin.kt +5 -0
- package/cli/commands/remote-shared.js +243 -0
- package/cli/commands/remote.js +211 -0
- package/cli/index.js +144 -0
- package/dist/esm/core/update-check.d.ts +23 -5
- package/dist/esm/core/update-check.js +32 -5
- package/dist/esm/definitions.d.ts +14 -0
- package/dist/esm/index.d.ts +1 -1
- package/dist/esm/plugin.js +23 -0
- package/dist/esm/types/app-identity.d.ts +36 -0
- package/dist/esm/types/app-identity.js +1 -0
- package/dist/esm/web.d.ts +2 -1
- package/dist/esm/web.js +5 -0
- package/dist/plugin.cjs.js +1 -1
- package/dist/plugin.esm.js +1 -1
- package/dist/plugin.js +2 -2
- package/docs/CHANGELOG.md +80 -0
- package/docs/KNOWN_LIMITATIONS.md +23 -0
- package/docs/server-requirements.md +15 -0
- package/ios/Plugin/LiveUpdate/LiveUpdatePlugin.swift +18 -1
- package/ios/Plugin/NativeUpdatePlugin.m +1 -0
- package/ios/Plugin/NativeUpdatePlugin.swift +5 -1
- package/package.json +1 -1
|
@@ -0,0 +1,211 @@
|
|
|
1
|
+
import chalk from 'chalk';
|
|
2
|
+
import fs from 'fs/promises';
|
|
3
|
+
import path from 'path';
|
|
4
|
+
import { apiClient, printTable, resolveBundle, waitForJob } from './remote-shared.js';
|
|
5
|
+
|
|
6
|
+
/** `native-update token info` */
|
|
7
|
+
export async function tokenInfo(options) {
|
|
8
|
+
const client = apiClient(options);
|
|
9
|
+
const { data } = await client.get('/token');
|
|
10
|
+
|
|
11
|
+
console.log(chalk.bold(`\n${data.name}`));
|
|
12
|
+
console.log(chalk.gray(` Server: ${client.server}`));
|
|
13
|
+
console.log(chalk.gray(` Permissions: ${data.permissions.join(', ')}`));
|
|
14
|
+
console.log(chalk.gray(` Last used: ${data.last_used_at ?? 'never'}`));
|
|
15
|
+
console.log(chalk.gray(` Expires: ${data.expires_at ?? 'never'}`));
|
|
16
|
+
console.log(chalk.bold('\nApps this token can manage:'));
|
|
17
|
+
printTable(data.apps, [
|
|
18
|
+
{ header: 'ID', value: (a) => a.id },
|
|
19
|
+
{ header: 'APP ID', value: (a) => a.app_id },
|
|
20
|
+
{ header: 'NAME', value: (a) => a.name },
|
|
21
|
+
]);
|
|
22
|
+
console.log('');
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
/** `native-update apps list` */
|
|
26
|
+
export async function appsList(options) {
|
|
27
|
+
const client = apiClient(options);
|
|
28
|
+
const body = await client.get('/apps');
|
|
29
|
+
|
|
30
|
+
console.log(chalk.bold('\nApps'));
|
|
31
|
+
printTable(body.data, [
|
|
32
|
+
{ header: 'ID', value: (a) => a.id },
|
|
33
|
+
{ header: 'APP ID', value: (a) => a.app_id },
|
|
34
|
+
{ header: 'NAME', value: (a) => a.name },
|
|
35
|
+
{ header: 'PLATFORM', value: (a) => a.platform ?? '—' },
|
|
36
|
+
]);
|
|
37
|
+
console.log('');
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
/** `native-update builds list <app>` */
|
|
41
|
+
export async function buildsList(app, options) {
|
|
42
|
+
const client = apiClient(options);
|
|
43
|
+
const params = new URLSearchParams();
|
|
44
|
+
if (options.channel) params.set('channel', options.channel);
|
|
45
|
+
if (options.status) params.set('status', options.status);
|
|
46
|
+
if (options.page) params.set('page', options.page);
|
|
47
|
+
const query = params.toString() ? `?${params}` : '';
|
|
48
|
+
|
|
49
|
+
const body = await client.get(`/apps/${app}/builds${query}`);
|
|
50
|
+
|
|
51
|
+
console.log(chalk.bold(`\nBuilds for ${app}`));
|
|
52
|
+
printTable(body.data, [
|
|
53
|
+
{ header: 'ID', value: (b) => b.id },
|
|
54
|
+
{ header: 'VERSION', value: (b) => b.version },
|
|
55
|
+
{ header: 'CHANNEL', value: (b) => b.channel },
|
|
56
|
+
{ header: 'STATUS', value: (b) => b.status },
|
|
57
|
+
{ header: 'ROLLOUT', value: (b) => `${b.rollout_percentage}%` },
|
|
58
|
+
{ header: 'CREATED', value: (b) => (b.created_at ?? '').slice(0, 10) },
|
|
59
|
+
]);
|
|
60
|
+
|
|
61
|
+
if (body.meta) {
|
|
62
|
+
console.log(
|
|
63
|
+
chalk.gray(`\n Page ${body.meta.current_page} of ${body.meta.last_page} — ${body.meta.total} total`)
|
|
64
|
+
);
|
|
65
|
+
}
|
|
66
|
+
console.log('');
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
/**
|
|
70
|
+
* `native-update deploy <webDirOrZip>` — the headline command.
|
|
71
|
+
* Uploads a bundle and (with --wait) blocks until the release is live, so a CI
|
|
72
|
+
* step fails when the release fails rather than reporting a false success.
|
|
73
|
+
*/
|
|
74
|
+
export async function deploy(target, options) {
|
|
75
|
+
const client = apiClient(options);
|
|
76
|
+
|
|
77
|
+
const version = options.version ?? (await versionFromPackageJson());
|
|
78
|
+
if (!version) {
|
|
79
|
+
console.error(chalk.red('Error: no --version, and no version found in ./package.json.'));
|
|
80
|
+
process.exit(1);
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
const bundle = await resolveBundle(target);
|
|
84
|
+
|
|
85
|
+
try {
|
|
86
|
+
const stat = await fs.stat(bundle.path);
|
|
87
|
+
console.log(chalk.bold('\nDeploying'));
|
|
88
|
+
console.log(chalk.gray(` App: ${options.app}`));
|
|
89
|
+
console.log(chalk.gray(` Version: ${version}`));
|
|
90
|
+
console.log(chalk.gray(` Channel: ${options.channel}`));
|
|
91
|
+
console.log(chalk.gray(` Bundle: ${(stat.size / 1024 / 1024).toFixed(2)} MB`));
|
|
92
|
+
|
|
93
|
+
const { data } = await client.upload(`/apps/${options.app}/builds`, bundle.path, {
|
|
94
|
+
version,
|
|
95
|
+
channel: options.channel,
|
|
96
|
+
release_notes: options.notes,
|
|
97
|
+
rollout_percentage: options.rollout,
|
|
98
|
+
min_native_version: options.minNative,
|
|
99
|
+
});
|
|
100
|
+
|
|
101
|
+
console.log(chalk.green(`\n✓ Bundle accepted — build #${data.build.id} is processing.`));
|
|
102
|
+
console.log(chalk.gray(` Job: ${data.job_id}`));
|
|
103
|
+
console.log(chalk.gray(` Status: ${data.status_url}`));
|
|
104
|
+
|
|
105
|
+
if (!options.wait) {
|
|
106
|
+
console.log(
|
|
107
|
+
chalk.gray(
|
|
108
|
+
`\n It goes live automatically when processing finishes.\n` +
|
|
109
|
+
` Add --wait to block until then, or poll:\n` +
|
|
110
|
+
` npx native-update jobs status ${data.job_id}`
|
|
111
|
+
)
|
|
112
|
+
);
|
|
113
|
+
return;
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
console.log(chalk.gray('\n Waiting for processing…'));
|
|
117
|
+
const job = await waitForJob(client, data.job_id);
|
|
118
|
+
console.log(
|
|
119
|
+
chalk.green(`\n✓ Live: v${job.result.version} on ${job.result.channel} (build #${job.result.build_id})`)
|
|
120
|
+
);
|
|
121
|
+
} finally {
|
|
122
|
+
await bundle.cleanup();
|
|
123
|
+
}
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
/** `native-update builds promote <app> <build> --to <channel>` */
|
|
127
|
+
export async function buildsPromote(app, build, options) {
|
|
128
|
+
const client = apiClient(options);
|
|
129
|
+
const { data } = await client.send('POST', `/apps/${app}/builds/${build}/promote`, {
|
|
130
|
+
target_channel: options.to,
|
|
131
|
+
});
|
|
132
|
+
|
|
133
|
+
console.log(
|
|
134
|
+
chalk.green(`✓ Promoted v${data.version} to ${data.channel} (new build #${data.id}).`)
|
|
135
|
+
);
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
/** `native-update builds rollout <app> <build> --percent <n>` */
|
|
139
|
+
export async function buildsRollout(app, build, options) {
|
|
140
|
+
const client = apiClient(options);
|
|
141
|
+
const percent = Number(options.percent);
|
|
142
|
+
|
|
143
|
+
if (!Number.isInteger(percent) || percent < 0 || percent > 100) {
|
|
144
|
+
console.error(chalk.red('Error: --percent must be a whole number from 0 to 100.'));
|
|
145
|
+
process.exit(1);
|
|
146
|
+
}
|
|
147
|
+
|
|
148
|
+
const { data } = await client.send('PATCH', `/apps/${app}/builds/${build}/rollout`, {
|
|
149
|
+
rollout_percentage: percent,
|
|
150
|
+
});
|
|
151
|
+
|
|
152
|
+
console.log(chalk.green(`✓ v${data.version} on ${data.channel} is now at ${data.rollout_percentage}%.`));
|
|
153
|
+
}
|
|
154
|
+
|
|
155
|
+
/** `native-update builds status <app> <build> --set <status>` */
|
|
156
|
+
export async function buildsStatus(app, build, options) {
|
|
157
|
+
const client = apiClient(options);
|
|
158
|
+
const { data } = await client.send('PATCH', `/apps/${app}/builds/${build}`, {
|
|
159
|
+
status: options.set,
|
|
160
|
+
});
|
|
161
|
+
|
|
162
|
+
console.log(chalk.green(`✓ Build #${data.id} (v${data.version}) is now ${data.status}.`));
|
|
163
|
+
}
|
|
164
|
+
|
|
165
|
+
/** `native-update builds delete <app> <build> --yes` */
|
|
166
|
+
export async function buildsDelete(app, build, options) {
|
|
167
|
+
if (!options.yes) {
|
|
168
|
+
console.error(chalk.red('Error: refusing to delete without --yes.'));
|
|
169
|
+
console.error(chalk.gray(' Deleting a build is permanent. Re-run with --yes to confirm.'));
|
|
170
|
+
process.exit(1);
|
|
171
|
+
}
|
|
172
|
+
|
|
173
|
+
const client = apiClient(options);
|
|
174
|
+
await client.send('DELETE', `/apps/${app}/builds/${build}`);
|
|
175
|
+
|
|
176
|
+
console.log(chalk.green(`✓ Build ${build} deleted.`));
|
|
177
|
+
}
|
|
178
|
+
|
|
179
|
+
/** `native-update jobs status <jobId>` */
|
|
180
|
+
export async function jobsStatus(jobId, options) {
|
|
181
|
+
const client = apiClient(options);
|
|
182
|
+
|
|
183
|
+
if (options.wait) {
|
|
184
|
+
const job = await waitForJob(client, jobId);
|
|
185
|
+
console.log(chalk.green(`\n✓ ${job.type} completed.`));
|
|
186
|
+
console.log(chalk.gray(` ${JSON.stringify(job.result)}`));
|
|
187
|
+
return;
|
|
188
|
+
}
|
|
189
|
+
|
|
190
|
+
const { data: job } = await client.get(`/jobs/${jobId}`);
|
|
191
|
+
|
|
192
|
+
console.log(chalk.bold(`\nJob ${job.id}`));
|
|
193
|
+
console.log(chalk.gray(` Type: ${job.type}`));
|
|
194
|
+
console.log(chalk.gray(` Status: ${job.status}`));
|
|
195
|
+
console.log(chalk.gray(` Attempts: ${job.attempts}`));
|
|
196
|
+
if (job.error) console.log(chalk.red(` Error: ${job.error}`));
|
|
197
|
+
if (job.result) console.log(chalk.gray(` Result: ${JSON.stringify(job.result)}`));
|
|
198
|
+
console.log('');
|
|
199
|
+
|
|
200
|
+
if (job.status === 'failed') process.exit(1);
|
|
201
|
+
}
|
|
202
|
+
|
|
203
|
+
/** Default the version from the project's package.json, like `bundle create` does. */
|
|
204
|
+
async function versionFromPackageJson() {
|
|
205
|
+
try {
|
|
206
|
+
const raw = await fs.readFile(path.join(process.cwd(), 'package.json'), 'utf-8');
|
|
207
|
+
return JSON.parse(raw).version ?? null;
|
|
208
|
+
} catch {
|
|
209
|
+
return null;
|
|
210
|
+
}
|
|
211
|
+
}
|
package/cli/index.js
CHANGED
|
@@ -199,6 +199,150 @@ ${chalk.bold('Examples:')}
|
|
|
199
199
|
await createBackend(type, options);
|
|
200
200
|
});
|
|
201
201
|
|
|
202
|
+
// ---------------------------------------------------------------------------
|
|
203
|
+
// Public Management API commands (access token → nativeupdatebe.aoneahsan.com)
|
|
204
|
+
//
|
|
205
|
+
// Auth for all of these: NATIVE_UPDATE_TOKEN (preferred — a --token flag lands
|
|
206
|
+
// in shell history and `ps` output) or --token. Server: NATIVE_UPDATE_SERVER or
|
|
207
|
+
// --server, defaulting to the hosted backend.
|
|
208
|
+
//
|
|
209
|
+
// Every parent below calls .enablePositionalOptions() for the same reason
|
|
210
|
+
// `bundle` does: without it the root's `-V, --version` swallows a leaf's own
|
|
211
|
+
// `--version <v>` flag and prints the CLI version instead of deploying.
|
|
212
|
+
// ---------------------------------------------------------------------------
|
|
213
|
+
|
|
214
|
+
const remoteAuthOptions = (cmd) =>
|
|
215
|
+
cmd
|
|
216
|
+
.option('-t, --token <token>', 'Access token (or set NATIVE_UPDATE_TOKEN)')
|
|
217
|
+
.option('-s, --server <url>', 'Backend base URL (or set NATIVE_UPDATE_SERVER)');
|
|
218
|
+
|
|
219
|
+
// deploy — upload a bundle and publish it
|
|
220
|
+
remoteAuthOptions(
|
|
221
|
+
program
|
|
222
|
+
.command('deploy <webDirOrZip>')
|
|
223
|
+
.description(`Upload a bundle to your app and publish it
|
|
224
|
+
|
|
225
|
+
${chalk.bold('Examples:')}
|
|
226
|
+
${chalk.gray('# Deploy a built web directory (zipped for you)')}
|
|
227
|
+
${chalk.green('npx native-update deploy ./dist --app com.example.app --version 1.2.0')}
|
|
228
|
+
|
|
229
|
+
${chalk.gray('# Block until the release is actually live (recommended in CI)')}
|
|
230
|
+
${chalk.green('npx native-update deploy ./dist --app com.example.app --wait')}
|
|
231
|
+
|
|
232
|
+
${chalk.gray('# Staged rollout with release notes')}
|
|
233
|
+
${chalk.green('npx native-update deploy ./bundle.zip --app 12 --version 1.2.0 --rollout 10 --notes "Bug fixes"')}`)
|
|
234
|
+
.requiredOption('-a, --app <appIdOrNumericId>', 'App to deploy to (app_id like com.example.app, or numeric id)')
|
|
235
|
+
.option('-v, --version <version>', 'Bundle version (defaults to ./package.json version)')
|
|
236
|
+
.option('-c, --channel <channel>', 'Release channel', 'production')
|
|
237
|
+
.option('-n, --notes <text>', 'Release notes')
|
|
238
|
+
.option('-r, --rollout <percent>', 'Initial rollout percentage (1-100)')
|
|
239
|
+
.option('--min-native <version>', 'Minimum native app version required')
|
|
240
|
+
.option('-w, --wait', 'Wait for processing to finish (exit non-zero if it fails)', false)
|
|
241
|
+
).action(async (target, options) => {
|
|
242
|
+
const { deploy } = await import('./commands/remote.js');
|
|
243
|
+
await deploy(target, options);
|
|
244
|
+
});
|
|
245
|
+
|
|
246
|
+
// apps
|
|
247
|
+
const appsCmd = program
|
|
248
|
+
.command('apps')
|
|
249
|
+
.enablePositionalOptions()
|
|
250
|
+
.description('Manage the apps your access token can reach');
|
|
251
|
+
|
|
252
|
+
remoteAuthOptions(appsCmd.command('list').description('List apps this token can manage')).action(
|
|
253
|
+
async (options) => {
|
|
254
|
+
const { appsList } = await import('./commands/remote.js');
|
|
255
|
+
await appsList(options);
|
|
256
|
+
}
|
|
257
|
+
);
|
|
258
|
+
|
|
259
|
+
// builds
|
|
260
|
+
const buildsCmd = program
|
|
261
|
+
.command('builds')
|
|
262
|
+
.enablePositionalOptions()
|
|
263
|
+
.description('Manage builds over the public API');
|
|
264
|
+
|
|
265
|
+
remoteAuthOptions(
|
|
266
|
+
buildsCmd
|
|
267
|
+
.command('list <app>')
|
|
268
|
+
.description('List builds for an app')
|
|
269
|
+
.option('-c, --channel <channel>', 'Filter by channel (production|staging|development)')
|
|
270
|
+
.option('--status <status>', 'Filter by status (active|processing|paused|archived|failed)')
|
|
271
|
+
.option('-p, --page <page>', 'Page number')
|
|
272
|
+
).action(async (app, options) => {
|
|
273
|
+
const { buildsList } = await import('./commands/remote.js');
|
|
274
|
+
await buildsList(app, options);
|
|
275
|
+
});
|
|
276
|
+
|
|
277
|
+
remoteAuthOptions(
|
|
278
|
+
buildsCmd
|
|
279
|
+
.command('promote <app> <build>')
|
|
280
|
+
.description('Promote a build into another channel (zero-copy)')
|
|
281
|
+
.requiredOption('--to <channel>', 'Target channel (production|staging|development)')
|
|
282
|
+
).action(async (app, build, options) => {
|
|
283
|
+
const { buildsPromote } = await import('./commands/remote.js');
|
|
284
|
+
await buildsPromote(app, build, options);
|
|
285
|
+
});
|
|
286
|
+
|
|
287
|
+
remoteAuthOptions(
|
|
288
|
+
buildsCmd
|
|
289
|
+
.command('rollout <app> <build>')
|
|
290
|
+
.description('Set a build\'s rollout percentage')
|
|
291
|
+
.requiredOption('--percent <n>', 'Rollout percentage (0-100)')
|
|
292
|
+
).action(async (app, build, options) => {
|
|
293
|
+
const { buildsRollout } = await import('./commands/remote.js');
|
|
294
|
+
await buildsRollout(app, build, options);
|
|
295
|
+
});
|
|
296
|
+
|
|
297
|
+
remoteAuthOptions(
|
|
298
|
+
buildsCmd
|
|
299
|
+
.command('status <app> <build>')
|
|
300
|
+
.description('Pause, resume, or archive a build')
|
|
301
|
+
.requiredOption('--set <status>', 'New status (active|paused|archived)')
|
|
302
|
+
).action(async (app, build, options) => {
|
|
303
|
+
const { buildsStatus } = await import('./commands/remote.js');
|
|
304
|
+
await buildsStatus(app, build, options);
|
|
305
|
+
});
|
|
306
|
+
|
|
307
|
+
remoteAuthOptions(
|
|
308
|
+
buildsCmd
|
|
309
|
+
.command('delete <app> <build>')
|
|
310
|
+
.description('Delete a build (needs a token with the builds.delete permission)')
|
|
311
|
+
.option('-y, --yes', 'Confirm the deletion', false)
|
|
312
|
+
).action(async (app, build, options) => {
|
|
313
|
+
const { buildsDelete } = await import('./commands/remote.js');
|
|
314
|
+
await buildsDelete(app, build, options);
|
|
315
|
+
});
|
|
316
|
+
|
|
317
|
+
// jobs
|
|
318
|
+
const jobsCmd = program
|
|
319
|
+
.command('jobs')
|
|
320
|
+
.enablePositionalOptions()
|
|
321
|
+
.description('Inspect queued work (bundle processing)');
|
|
322
|
+
|
|
323
|
+
remoteAuthOptions(
|
|
324
|
+
jobsCmd
|
|
325
|
+
.command('status <jobId>')
|
|
326
|
+
.description('Show a job\'s status')
|
|
327
|
+
.option('-w, --wait', 'Poll until the job finishes', false)
|
|
328
|
+
).action(async (jobId, options) => {
|
|
329
|
+
const { jobsStatus } = await import('./commands/remote.js');
|
|
330
|
+
await jobsStatus(jobId, options);
|
|
331
|
+
});
|
|
332
|
+
|
|
333
|
+
// token
|
|
334
|
+
const tokenCmd = program
|
|
335
|
+
.command('token')
|
|
336
|
+
.enablePositionalOptions()
|
|
337
|
+
.description('Inspect your access token');
|
|
338
|
+
|
|
339
|
+
remoteAuthOptions(
|
|
340
|
+
tokenCmd.command('info').description('Show what this token is and which apps it can manage')
|
|
341
|
+
).action(async (options) => {
|
|
342
|
+
const { tokenInfo } = await import('./commands/remote.js');
|
|
343
|
+
await tokenInfo(options);
|
|
344
|
+
});
|
|
345
|
+
|
|
202
346
|
// Monitoring Commands
|
|
203
347
|
program
|
|
204
348
|
.command('monitor')
|
|
@@ -13,13 +13,23 @@
|
|
|
13
13
|
*
|
|
14
14
|
* ```
|
|
15
15
|
* GET {baseUrl}/v1/updates/check?channel={channel}
|
|
16
|
-
* X-API-Key:
|
|
17
|
-
* X-Device-ID:
|
|
18
|
-
* X-Current-Version:
|
|
19
|
-
* X-Platform:
|
|
20
|
-
* X-App-Version:
|
|
16
|
+
* X-API-Key: nu_app_… (required; ValidateApiKey middleware → 401 without it)
|
|
17
|
+
* X-Device-ID: stable per-device hash (required; 400 without it)
|
|
18
|
+
* X-Current-Version: the currently-installed bundle version
|
|
19
|
+
* X-Platform: ios | android | web
|
|
20
|
+
* X-App-Version: native app version (optional)
|
|
21
|
+
* X-Android-Package: applicationId (optional; sent when identity.platform === 'android')
|
|
22
|
+
* X-Android-Cert-Sha256: signing cert SHA-256, hex (optional)
|
|
23
|
+
* X-Android-Cert-Sha1: signing cert SHA-1, hex (optional)
|
|
24
|
+
* X-Ios-Bundle-Id: bundle identifier (optional; sent when identity.platform === 'ios')
|
|
25
|
+
* X-Ios-Team-Id: team id (optional; currently never populated)
|
|
21
26
|
* ```
|
|
22
27
|
*
|
|
28
|
+
* The X-Android-* / X-Ios-* headers carry the app's client identity for
|
|
29
|
+
* per-key client restrictions (see AppIdentity + `getAppIdentity()`). They are
|
|
30
|
+
* only attached when a matching `identity` is supplied; web clients identify
|
|
31
|
+
* via the browser-enforced Origin header instead.
|
|
32
|
+
*
|
|
23
33
|
* Response (200):
|
|
24
34
|
* ```jsonc
|
|
25
35
|
* // no update:
|
|
@@ -43,6 +53,7 @@
|
|
|
43
53
|
* Custom backends must return these exact field names — see
|
|
44
54
|
* `docs/server-requirements.md`.
|
|
45
55
|
*/
|
|
56
|
+
import type { AppIdentity } from '../types/app-identity';
|
|
46
57
|
/** Request inputs for a single backend update check. */
|
|
47
58
|
export interface UpdateCheckRequest {
|
|
48
59
|
/** API key issued by the dashboard; sent as `X-API-Key`. Required. */
|
|
@@ -57,6 +68,13 @@ export interface UpdateCheckRequest {
|
|
|
57
68
|
platform: string;
|
|
58
69
|
/** Native app version; sent as `X-App-Version` when present. */
|
|
59
70
|
appVersion?: string;
|
|
71
|
+
/**
|
|
72
|
+
* App client identity for API-key client restrictions. When present and its
|
|
73
|
+
* `platform` is `android`/`ios`, the matching `X-Android-*` / `X-Ios-*`
|
|
74
|
+
* headers are attached. Web clients omit it (the Origin header identifies
|
|
75
|
+
* them). Obtain it from `NativeUpdate.getAppIdentity()`.
|
|
76
|
+
*/
|
|
77
|
+
identity?: AppIdentity;
|
|
60
78
|
/** Optional abort signal so callers can time the request out. */
|
|
61
79
|
signal?: AbortSignal;
|
|
62
80
|
}
|
|
@@ -13,13 +13,23 @@
|
|
|
13
13
|
*
|
|
14
14
|
* ```
|
|
15
15
|
* GET {baseUrl}/v1/updates/check?channel={channel}
|
|
16
|
-
* X-API-Key:
|
|
17
|
-
* X-Device-ID:
|
|
18
|
-
* X-Current-Version:
|
|
19
|
-
* X-Platform:
|
|
20
|
-
* X-App-Version:
|
|
16
|
+
* X-API-Key: nu_app_… (required; ValidateApiKey middleware → 401 without it)
|
|
17
|
+
* X-Device-ID: stable per-device hash (required; 400 without it)
|
|
18
|
+
* X-Current-Version: the currently-installed bundle version
|
|
19
|
+
* X-Platform: ios | android | web
|
|
20
|
+
* X-App-Version: native app version (optional)
|
|
21
|
+
* X-Android-Package: applicationId (optional; sent when identity.platform === 'android')
|
|
22
|
+
* X-Android-Cert-Sha256: signing cert SHA-256, hex (optional)
|
|
23
|
+
* X-Android-Cert-Sha1: signing cert SHA-1, hex (optional)
|
|
24
|
+
* X-Ios-Bundle-Id: bundle identifier (optional; sent when identity.platform === 'ios')
|
|
25
|
+
* X-Ios-Team-Id: team id (optional; currently never populated)
|
|
21
26
|
* ```
|
|
22
27
|
*
|
|
28
|
+
* The X-Android-* / X-Ios-* headers carry the app's client identity for
|
|
29
|
+
* per-key client restrictions (see AppIdentity + `getAppIdentity()`). They are
|
|
30
|
+
* only attached when a matching `identity` is supplied; web clients identify
|
|
31
|
+
* via the browser-enforced Origin header instead.
|
|
32
|
+
*
|
|
23
33
|
* Response (200):
|
|
24
34
|
* ```jsonc
|
|
25
35
|
* // no update:
|
|
@@ -64,6 +74,23 @@ export async function checkForUpdate(baseUrl, req) {
|
|
|
64
74
|
if (req.appVersion) {
|
|
65
75
|
headers['X-App-Version'] = req.appVersion;
|
|
66
76
|
}
|
|
77
|
+
// App client-identity headers for per-key client restrictions. Only attached
|
|
78
|
+
// for native platforms; web clients identify via the browser Origin header.
|
|
79
|
+
const identity = req.identity;
|
|
80
|
+
if ((identity === null || identity === void 0 ? void 0 : identity.platform) === 'android') {
|
|
81
|
+
if (identity.packageName)
|
|
82
|
+
headers['X-Android-Package'] = identity.packageName;
|
|
83
|
+
if (identity.certSha256)
|
|
84
|
+
headers['X-Android-Cert-Sha256'] = identity.certSha256;
|
|
85
|
+
if (identity.certSha1)
|
|
86
|
+
headers['X-Android-Cert-Sha1'] = identity.certSha1;
|
|
87
|
+
}
|
|
88
|
+
else if ((identity === null || identity === void 0 ? void 0 : identity.platform) === 'ios') {
|
|
89
|
+
if (identity.bundleId)
|
|
90
|
+
headers['X-Ios-Bundle-Id'] = identity.bundleId;
|
|
91
|
+
if (identity.teamId)
|
|
92
|
+
headers['X-Ios-Team-Id'] = identity.teamId;
|
|
93
|
+
}
|
|
67
94
|
const response = await fetch(url, { method: 'GET', headers, signal: req.signal });
|
|
68
95
|
if (!response.ok) {
|
|
69
96
|
return { available: false };
|
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
import type { AppIdentity } from './types/app-identity';
|
|
2
|
+
export type { AppIdentity } from './types/app-identity';
|
|
1
3
|
/**
|
|
2
4
|
* Live Update Plugin Interface
|
|
3
5
|
*/
|
|
@@ -42,6 +44,18 @@ export interface LiveUpdatePlugin {
|
|
|
42
44
|
* Check for latest version
|
|
43
45
|
*/
|
|
44
46
|
getLatest(): Promise<LatestVersion>;
|
|
47
|
+
/**
|
|
48
|
+
* The app's client identity for API-key client restrictions (dashboard →
|
|
49
|
+
* API Keys → Restrictions). On Android it is the applicationId + signing-cert
|
|
50
|
+
* SHA-256/SHA-1; on iOS the bundle identifier; on web `{ platform: 'web' }`
|
|
51
|
+
* (browsers identify via the Origin header). Call this when performing your
|
|
52
|
+
* OWN update-check fetch and attach the matching `X-Android-*` / `X-Ios-*`
|
|
53
|
+
* headers; the plugin's native update-check attaches them automatically.
|
|
54
|
+
*
|
|
55
|
+
* Headers are client-attested (parity with Google API-key restrictions):
|
|
56
|
+
* they stop cross-site/casual key reuse, not a forged native client.
|
|
57
|
+
*/
|
|
58
|
+
getAppIdentity(): Promise<AppIdentity>;
|
|
45
59
|
/**
|
|
46
60
|
* Switch update channel
|
|
47
61
|
*/
|
package/dist/esm/index.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
export { NativeUpdate } from './plugin';
|
|
2
2
|
export { BackgroundUpdateType, NotificationPriority, UpdateStrategy, UpdateMode, InstallMode, ChecksumAlgorithm, SyncStatus, BundleStatus, InstallStatus, UpdateErrorCode, } from './definitions';
|
|
3
|
-
export type { NativeUpdatePlugin, NativeUpdateCombinedPlugin, NativeUpdateListeners, LiveUpdatePlugin, AppUpdatePlugin, AppReviewPlugin, PluginConfig, UpdateConfig, LiveUpdateConfig, AppUpdateConfig, AppReviewConfig, BundleInfo, DownloadOptions, DownloadProgressEvent, SyncOptions, SyncResult, DeleteOptions, LatestVersion, ValidateOptions, ValidationResult, CheckForUpdateResult, DownloadUpdateOptions, AppUpdateInfo, OpenAppStoreOptions, ReviewResult, CanRequestReviewResult, UpdateStateChangedEvent, AppUpdateStateChangedEvent, AppUpdateProgressEvent, AppUpdateAvailableEvent, AppUpdateReadyEvent, AppUpdateFailedEvent, AppUpdateNotificationClickedEvent, AppUpdateInstallClickedEvent, BackgroundUpdateProgressEvent, BackgroundUpdateNotificationEvent, UpdateError, BackgroundUpdatePlugin, BackgroundUpdateConfig, BackgroundUpdateStatus, BackgroundCheckResult, NotificationPreferences, NotificationPermissionStatus, SecurityConfig, SecurityInfo, CertificatePinning, CertificatePin, PluginInitConfig, PluginListenerHandle, } from './definitions';
|
|
3
|
+
export type { NativeUpdatePlugin, NativeUpdateCombinedPlugin, NativeUpdateListeners, LiveUpdatePlugin, AppUpdatePlugin, AppReviewPlugin, PluginConfig, UpdateConfig, LiveUpdateConfig, AppUpdateConfig, AppReviewConfig, BundleInfo, DownloadOptions, DownloadProgressEvent, SyncOptions, SyncResult, DeleteOptions, LatestVersion, ValidateOptions, ValidationResult, CheckForUpdateResult, DownloadUpdateOptions, AppIdentity, AppUpdateInfo, OpenAppStoreOptions, ReviewResult, CanRequestReviewResult, UpdateStateChangedEvent, AppUpdateStateChangedEvent, AppUpdateProgressEvent, AppUpdateAvailableEvent, AppUpdateReadyEvent, AppUpdateFailedEvent, AppUpdateNotificationClickedEvent, AppUpdateInstallClickedEvent, BackgroundUpdateProgressEvent, BackgroundUpdateNotificationEvent, UpdateError, BackgroundUpdatePlugin, BackgroundUpdateConfig, BackgroundUpdateStatus, BackgroundCheckResult, NotificationPreferences, NotificationPermissionStatus, SecurityConfig, SecurityInfo, CertificatePinning, CertificatePin, PluginInitConfig, PluginListenerHandle, } from './definitions';
|
|
4
4
|
export type { RolloutConfig, RolloutTargetSegments, RolloutSchedule, RolloutTimestamp, DeviceInfo, UpdateCheckResponse, } from './types/rollout';
|
|
5
5
|
export { ErrorCode, NativeUpdateError, ConfigurationError, DownloadError, ValidationError, StorageError, UpdateError as UpdateErrorClass, } from './core/errors';
|
|
6
6
|
export { ConfigManager } from './core/config';
|
package/dist/esm/plugin.js
CHANGED
|
@@ -286,6 +286,28 @@ class NativeUpdatePluginWeb {
|
|
|
286
286
|
// ============================================
|
|
287
287
|
// Convenience Methods (Aliases)
|
|
288
288
|
// ============================================
|
|
289
|
+
/**
|
|
290
|
+
* The app's client identity for API-key client restrictions. On web this is
|
|
291
|
+
* `{ platform: 'web' }` — browsers identify via the Origin header. On native
|
|
292
|
+
* platforms this method is served by the native layer (Android: applicationId
|
|
293
|
+
* + signing-cert SHA-256/SHA-1; iOS: bundle identifier).
|
|
294
|
+
*/
|
|
295
|
+
async getAppIdentity() {
|
|
296
|
+
return { platform: 'web' };
|
|
297
|
+
}
|
|
298
|
+
/** Session-cached identity; never throws (falls back to `{ platform: 'web' }`). */
|
|
299
|
+
async resolveAppIdentity() {
|
|
300
|
+
if (this.appIdentity) {
|
|
301
|
+
return this.appIdentity;
|
|
302
|
+
}
|
|
303
|
+
try {
|
|
304
|
+
this.appIdentity = await this.getAppIdentity();
|
|
305
|
+
}
|
|
306
|
+
catch (_a) {
|
|
307
|
+
this.appIdentity = { platform: 'web' };
|
|
308
|
+
}
|
|
309
|
+
return this.appIdentity;
|
|
310
|
+
}
|
|
289
311
|
/**
|
|
290
312
|
* Check for available updates (convenience wrapper around getLatest + current version)
|
|
291
313
|
*/
|
|
@@ -323,6 +345,7 @@ class NativeUpdatePluginWeb {
|
|
|
323
345
|
deviceId: deviceInfo.deviceId,
|
|
324
346
|
platform: deviceInfo.platform,
|
|
325
347
|
appVersion: deviceInfo.appVersion,
|
|
348
|
+
identity: await this.resolveAppIdentity(),
|
|
326
349
|
});
|
|
327
350
|
if (!data.available) {
|
|
328
351
|
return {
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The app's client identity, used for API-key client restrictions
|
|
3
|
+
* (dashboard → API Keys → Restrictions). It answers "which app/site is this?"
|
|
4
|
+
* so the backend can enforce a per-key allowlist of clients.
|
|
5
|
+
*
|
|
6
|
+
* - **android**: `packageName` (applicationId) + signing-cert `certSha256` /
|
|
7
|
+
* `certSha1` (lowercase hex, no colons).
|
|
8
|
+
* - **ios**: `bundleId` (`teamId` reserved; currently unset).
|
|
9
|
+
* - **web**: `{ platform: 'web' }` — browsers identify via the Origin header
|
|
10
|
+
* (browser-enforced), so no fields are needed.
|
|
11
|
+
*
|
|
12
|
+
* A consuming app that performs its OWN update-check fetch should call
|
|
13
|
+
* `NativeUpdate.getAppIdentity()` and attach the matching headers
|
|
14
|
+
* (`X-Android-Package`, `X-Android-Cert-Sha256`, `X-Android-Cert-Sha1`,
|
|
15
|
+
* `X-Ios-Bundle-Id`). The plugin's own native update-check path attaches them
|
|
16
|
+
* automatically.
|
|
17
|
+
*
|
|
18
|
+
* Honest note: the native identity headers are CLIENT-ATTESTED (parity with
|
|
19
|
+
* Google Maps API-key app restrictions) — they stop casual key reuse and quota
|
|
20
|
+
* abuse, not a determined attacker replaying headers by hand. Only the web
|
|
21
|
+
* Origin check is browser-enforced.
|
|
22
|
+
*/
|
|
23
|
+
export interface AppIdentity {
|
|
24
|
+
/** The platform this identity was computed on. */
|
|
25
|
+
platform: 'web' | 'android' | 'ios';
|
|
26
|
+
/** Android applicationId (e.g. `com.acme.app`). */
|
|
27
|
+
packageName?: string;
|
|
28
|
+
/** Android signing certificate SHA-256, lowercase hex, no separators. */
|
|
29
|
+
certSha256?: string;
|
|
30
|
+
/** Android signing certificate SHA-1, lowercase hex, no separators. */
|
|
31
|
+
certSha1?: string;
|
|
32
|
+
/** iOS bundle identifier (e.g. `com.acme.app`). */
|
|
33
|
+
bundleId?: string;
|
|
34
|
+
/** iOS team id — reserved; the plugin does not currently populate it. */
|
|
35
|
+
teamId?: string;
|
|
36
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
package/dist/esm/web.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { WebPlugin } from '@capacitor/core';
|
|
2
|
-
import type { NativeUpdateCombinedPlugin, SecurityInfo, SyncOptions, SyncResult, DownloadOptions, BundleInfo, DeleteOptions, LatestVersion, ValidateOptions, ValidationResult, AppUpdateInfo, OpenAppStoreOptions, ReviewResult, CanRequestReviewResult, BackgroundUpdateConfig, BackgroundUpdateStatus, BackgroundCheckResult, NotificationPreferences, NotificationPermissionStatus, CheckForUpdateResult, DownloadUpdateOptions } from './definitions';
|
|
2
|
+
import type { NativeUpdateCombinedPlugin, SecurityInfo, SyncOptions, SyncResult, DownloadOptions, BundleInfo, DeleteOptions, LatestVersion, ValidateOptions, ValidationResult, AppUpdateInfo, OpenAppStoreOptions, ReviewResult, CanRequestReviewResult, BackgroundUpdateConfig, BackgroundUpdateStatus, BackgroundCheckResult, NotificationPreferences, NotificationPermissionStatus, CheckForUpdateResult, DownloadUpdateOptions, AppIdentity } from './definitions';
|
|
3
3
|
import type { PluginInitConfig } from './definitions';
|
|
4
4
|
export declare class NativeUpdateWeb extends WebPlugin implements NativeUpdateCombinedPlugin {
|
|
5
5
|
private config;
|
|
@@ -33,6 +33,7 @@ export declare class NativeUpdateWeb extends WebPlugin implements NativeUpdateCo
|
|
|
33
33
|
delete(options: DeleteOptions): Promise<void>;
|
|
34
34
|
notifyAppReady(): Promise<void>;
|
|
35
35
|
getLatest(): Promise<LatestVersion>;
|
|
36
|
+
getAppIdentity(): Promise<AppIdentity>;
|
|
36
37
|
setChannel(channel: string): Promise<void>;
|
|
37
38
|
/**
|
|
38
39
|
* @deprecated since v2. See NativeUpdatePluginWeb.setUpdateUrl in plugin.ts.
|
package/dist/esm/web.js
CHANGED
|
@@ -265,6 +265,11 @@ export class NativeUpdateWeb extends WebPlugin {
|
|
|
265
265
|
available: false,
|
|
266
266
|
};
|
|
267
267
|
}
|
|
268
|
+
async getAppIdentity() {
|
|
269
|
+
// Web clients identify to the update backend via the browser-enforced
|
|
270
|
+
// Origin header, so no identity fields are needed here.
|
|
271
|
+
return { platform: 'web' };
|
|
272
|
+
}
|
|
268
273
|
async setChannel(channel) {
|
|
269
274
|
if (!this.config.liveUpdate) {
|
|
270
275
|
this.config.liveUpdate = {};
|