native-update-capacitor 0.0.0-stage → 4.3.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/AI-INTEGRATION-GUIDE.md +578 -0
- package/LICENSE +25 -0
- package/NativeUpdate.podspec +19 -0
- package/README.md +574 -2
- package/android/build.gradle +125 -0
- package/android/consumer-rules.pro +9 -0
- package/android/gradle/wrapper/gradle-wrapper.properties +8 -0
- package/android/gradle.properties +17 -0
- package/android/manifest-additions.xml +28 -0
- package/android/proguard-rules.pro +26 -0
- package/android/settings.gradle +2 -0
- package/android/src/main/AndroidManifest.xml +13 -0
- package/android/src/main/java/com/aoneahsan/nativeupdate/AppReviewPlugin.kt +159 -0
- package/android/src/main/java/com/aoneahsan/nativeupdate/AppUpdatePlugin.kt +314 -0
- package/android/src/main/java/com/aoneahsan/nativeupdate/BackgroundNotificationManager.kt +406 -0
- package/android/src/main/java/com/aoneahsan/nativeupdate/BackgroundUpdateManager.kt +48 -0
- package/android/src/main/java/com/aoneahsan/nativeupdate/BackgroundUpdatePlugin.kt +343 -0
- package/android/src/main/java/com/aoneahsan/nativeupdate/BackgroundUpdateWorker.kt +236 -0
- package/android/src/main/java/com/aoneahsan/nativeupdate/JsonOptional.kt +26 -0
- package/android/src/main/java/com/aoneahsan/nativeupdate/LiveUpdatePlugin.kt +1249 -0
- package/android/src/main/java/com/aoneahsan/nativeupdate/NativeUpdatePlugin.kt +404 -0
- package/android/src/main/java/com/aoneahsan/nativeupdate/NotificationActionReceiver.kt +107 -0
- package/android/src/main/java/com/aoneahsan/nativeupdate/SecurityManager.kt +240 -0
- package/android/variables.gradle +5 -0
- package/cli/commands/backend-create.js +623 -0
- package/cli/commands/bundle-create.js +145 -0
- package/cli/commands/bundle-sign.js +64 -0
- package/cli/commands/bundle-verify.js +58 -0
- package/cli/commands/init.js +146 -0
- package/cli/commands/keys-generate.js +58 -0
- package/cli/commands/monitor.js +89 -0
- package/cli/commands/remote-shared.js +262 -0
- package/cli/commands/remote.js +622 -0
- package/cli/commands/server-start.js +96 -0
- package/cli/index.js +605 -0
- package/cli/package.json +21 -0
- package/dist/esm/app-review/app-review-manager.d.ts +24 -0
- package/dist/esm/app-review/app-review-manager.js +194 -0
- package/dist/esm/app-review/index.d.ts +5 -0
- package/dist/esm/app-review/index.js +5 -0
- package/dist/esm/app-review/platform-review-handler.d.ts +20 -0
- package/dist/esm/app-review/platform-review-handler.js +137 -0
- package/dist/esm/app-review/review-conditions-checker.d.ts +22 -0
- package/dist/esm/app-review/review-conditions-checker.js +154 -0
- package/dist/esm/app-review/review-rate-limiter.d.ts +23 -0
- package/dist/esm/app-review/review-rate-limiter.js +163 -0
- package/dist/esm/app-review/types.d.ts +41 -0
- package/dist/esm/app-review/types.js +1 -0
- package/dist/esm/app-update/app-update-checker.d.ts +58 -0
- package/dist/esm/app-update/app-update-checker.js +227 -0
- package/dist/esm/app-update/app-update-installer.d.ts +20 -0
- package/dist/esm/app-update/app-update-installer.js +134 -0
- package/dist/esm/app-update/app-update-manager.d.ts +28 -0
- package/dist/esm/app-update/app-update-manager.js +198 -0
- package/dist/esm/app-update/app-update-notifier.d.ts +14 -0
- package/dist/esm/app-update/app-update-notifier.js +99 -0
- package/dist/esm/app-update/index.d.ts +6 -0
- package/dist/esm/app-update/index.js +6 -0
- package/dist/esm/app-update/platform-app-update.d.ts +19 -0
- package/dist/esm/app-update/platform-app-update.js +138 -0
- package/dist/esm/app-update/types.d.ts +58 -0
- package/dist/esm/app-update/types.js +11 -0
- package/dist/esm/background-update/background-scheduler.d.ts +63 -0
- package/dist/esm/background-update/background-scheduler.js +332 -0
- package/dist/esm/background-update/index.d.ts +3 -0
- package/dist/esm/background-update/index.js +2 -0
- package/dist/esm/background-update/notification-manager.d.ts +29 -0
- package/dist/esm/background-update/notification-manager.js +88 -0
- package/dist/esm/config/support.d.ts +9 -0
- package/dist/esm/config/support.js +9 -0
- package/dist/esm/core/analytics.d.ts +83 -0
- package/dist/esm/core/analytics.js +151 -0
- package/dist/esm/core/cache-manager.d.ts +72 -0
- package/dist/esm/core/cache-manager.js +274 -0
- package/dist/esm/core/config.d.ts +69 -0
- package/dist/esm/core/config.js +107 -0
- package/dist/esm/core/errors.d.ts +56 -0
- package/dist/esm/core/errors.js +85 -0
- package/dist/esm/core/event-emitter.d.ts +30 -0
- package/dist/esm/core/event-emitter.js +80 -0
- package/dist/esm/core/logger.d.ts +21 -0
- package/dist/esm/core/logger.js +108 -0
- package/dist/esm/core/performance.d.ts +53 -0
- package/dist/esm/core/performance.js +153 -0
- package/dist/esm/core/plugin-manager.d.ts +88 -0
- package/dist/esm/core/plugin-manager.js +224 -0
- package/dist/esm/core/security.d.ts +123 -0
- package/dist/esm/core/security.js +361 -0
- package/dist/esm/core/update-check.d.ts +121 -0
- package/dist/esm/core/update-check.js +127 -0
- package/dist/esm/definitions.d.ts +872 -0
- package/dist/esm/definitions.js +104 -0
- package/dist/esm/index.d.ts +14 -0
- package/dist/esm/index.js +18 -0
- package/dist/esm/live-update/bundle-manager.d.ts +102 -0
- package/dist/esm/live-update/bundle-manager.js +344 -0
- package/dist/esm/live-update/certificate-pinning.d.ts +38 -0
- package/dist/esm/live-update/certificate-pinning.js +77 -0
- package/dist/esm/live-update/delta-processor.d.ts +84 -0
- package/dist/esm/live-update/delta-processor.js +257 -0
- package/dist/esm/live-update/download-manager.d.ts +106 -0
- package/dist/esm/live-update/download-manager.js +412 -0
- package/dist/esm/live-update/rollout-checker.d.ts +86 -0
- package/dist/esm/live-update/rollout-checker.js +304 -0
- package/dist/esm/live-update/update-manager.d.ts +63 -0
- package/dist/esm/live-update/update-manager.js +321 -0
- package/dist/esm/live-update/version-manager.d.ts +93 -0
- package/dist/esm/live-update/version-manager.js +390 -0
- package/dist/esm/plugin.d.ts +3 -0
- package/dist/esm/plugin.js +848 -0
- package/dist/esm/security/crypto.d.ts +88 -0
- package/dist/esm/security/crypto.js +228 -0
- package/dist/esm/security/validator.d.ts +60 -0
- package/dist/esm/security/validator.js +142 -0
- package/dist/esm/types/app-identity.d.ts +36 -0
- package/dist/esm/types/app-identity.js +1 -0
- package/dist/esm/types/rollout.d.ts +91 -0
- package/dist/esm/types/rollout.js +25 -0
- package/dist/esm/web.d.ts +130 -0
- package/dist/esm/web.js +981 -0
- package/dist/plugin.cjs +1 -0
- package/dist/plugin.esm.js +1 -0
- package/dist/plugin.js +2 -0
- package/docs/CHANGELOG.md +993 -0
- package/docs/KNOWN_LIMITATIONS.md +235 -0
- package/docs/MIGRATION.md +391 -0
- package/docs/protocol/CLIENT-PROTOCOL.md +178 -0
- package/docs/server-requirements.md +211 -0
- package/ios/Plugin/AppReview/AppReviewPlugin.swift +158 -0
- package/ios/Plugin/AppUpdate/AppUpdatePlugin.swift +249 -0
- package/ios/Plugin/BackgroundUpdate/BackgroundNotificationManager.swift +333 -0
- package/ios/Plugin/BackgroundUpdate/BackgroundUpdatePlugin.swift +464 -0
- package/ios/Plugin/Info.plist +43 -0
- package/ios/Plugin/LiveUpdate/LiveUpdatePlugin.swift +1286 -0
- package/ios/Plugin/LiveUpdate/WebViewConfiguration.swift +45 -0
- package/ios/Plugin/NativeUpdatePlugin.m +53 -0
- package/ios/Plugin/NativeUpdatePlugin.swift +315 -0
- package/ios/Plugin/Security/SecurityManager.swift +289 -0
- package/package.json +135 -4
|
@@ -0,0 +1,622 @@
|
|
|
1
|
+
import chalk from 'chalk';
|
|
2
|
+
import { createHash } from 'crypto';
|
|
3
|
+
import fs from 'fs/promises';
|
|
4
|
+
import path from 'path';
|
|
5
|
+
import { apiClient, printTable, resolveBundle, waitForJob } from './remote-shared.js';
|
|
6
|
+
|
|
7
|
+
/** `native-update token info` */
|
|
8
|
+
export async function tokenInfo(options) {
|
|
9
|
+
const client = apiClient(options);
|
|
10
|
+
const { data } = await client.get('/token');
|
|
11
|
+
|
|
12
|
+
console.log(chalk.bold(`\n${data.name}`));
|
|
13
|
+
console.log(chalk.gray(` Server: ${client.server}`));
|
|
14
|
+
console.log(chalk.gray(` Permissions: ${data.permissions.join(', ')}`));
|
|
15
|
+
console.log(chalk.gray(` Last used: ${data.last_used_at ?? 'never'}`));
|
|
16
|
+
console.log(chalk.gray(` Expires: ${data.expires_at ?? 'never'}`));
|
|
17
|
+
console.log(chalk.bold('\nApps this token can manage:'));
|
|
18
|
+
printTable(data.apps, [
|
|
19
|
+
{ header: 'ID', value: (a) => a.id },
|
|
20
|
+
{ header: 'APP ID', value: (a) => a.app_id },
|
|
21
|
+
{ header: 'NAME', value: (a) => a.name },
|
|
22
|
+
]);
|
|
23
|
+
console.log('');
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
/** `native-update apps list` */
|
|
27
|
+
export async function appsList(options) {
|
|
28
|
+
const client = apiClient(options);
|
|
29
|
+
const body = await client.get('/apps');
|
|
30
|
+
|
|
31
|
+
console.log(chalk.bold('\nApps'));
|
|
32
|
+
printTable(body.data, [
|
|
33
|
+
{ header: 'ID', value: (a) => a.id },
|
|
34
|
+
{ header: 'APP ID', value: (a) => a.app_id },
|
|
35
|
+
{ header: 'NAME', value: (a) => a.name },
|
|
36
|
+
{ header: 'PLATFORM', value: (a) => a.platform ?? '—' },
|
|
37
|
+
]);
|
|
38
|
+
console.log('');
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
/** `native-update builds list <app>` */
|
|
42
|
+
export async function buildsList(app, options) {
|
|
43
|
+
const client = apiClient(options);
|
|
44
|
+
const params = new URLSearchParams();
|
|
45
|
+
if (options.channel) params.set('channel', options.channel);
|
|
46
|
+
if (options.status) params.set('status', options.status);
|
|
47
|
+
if (options.page) params.set('page', options.page);
|
|
48
|
+
const query = params.toString() ? `?${params}` : '';
|
|
49
|
+
|
|
50
|
+
const body = await client.get(`/apps/${app}/builds${query}`);
|
|
51
|
+
|
|
52
|
+
console.log(chalk.bold(`\nBuilds for ${app}`));
|
|
53
|
+
printTable(body.data, [
|
|
54
|
+
{ header: 'ID', value: (b) => b.id },
|
|
55
|
+
{ header: 'VERSION', value: (b) => b.version },
|
|
56
|
+
{ header: 'CHANNEL', value: (b) => b.channel },
|
|
57
|
+
{ header: 'STATUS', value: (b) => b.status },
|
|
58
|
+
{ header: 'ROLLOUT', value: (b) => `${b.rollout_percentage}%` },
|
|
59
|
+
{ header: 'CREATED', value: (b) => (b.created_at ?? '').slice(0, 10) },
|
|
60
|
+
]);
|
|
61
|
+
|
|
62
|
+
if (body.meta) {
|
|
63
|
+
console.log(
|
|
64
|
+
chalk.gray(`\n Page ${body.meta.current_page} of ${body.meta.last_page} — ${body.meta.total} total`)
|
|
65
|
+
);
|
|
66
|
+
}
|
|
67
|
+
console.log('');
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
/**
|
|
71
|
+
* `native-update deploy <webDirOrZip>` — the headline command.
|
|
72
|
+
* Uploads a bundle and (with --wait) blocks until the release is live, so a CI
|
|
73
|
+
* step fails when the release fails rather than reporting a false success.
|
|
74
|
+
*/
|
|
75
|
+
export async function deploy(target, options) {
|
|
76
|
+
const client = apiClient(options);
|
|
77
|
+
|
|
78
|
+
const version = options.version ?? (await versionFromPackageJson());
|
|
79
|
+
if (!version) {
|
|
80
|
+
console.error(chalk.red('Error: no --version, and no version found in ./package.json.'));
|
|
81
|
+
process.exit(1);
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
const bundle = await resolveBundle(target);
|
|
85
|
+
|
|
86
|
+
try {
|
|
87
|
+
const stat = await fs.stat(bundle.path);
|
|
88
|
+
console.log(chalk.bold('\nDeploying'));
|
|
89
|
+
console.log(chalk.gray(` App: ${options.app}`));
|
|
90
|
+
console.log(chalk.gray(` Version: ${version}`));
|
|
91
|
+
console.log(chalk.gray(` Channel: ${options.channel}`));
|
|
92
|
+
console.log(chalk.gray(` Bundle: ${(stat.size / 1024 / 1024).toFixed(2)} MB`));
|
|
93
|
+
|
|
94
|
+
// A detached signature from `native-update bundle sign`, if the consumer
|
|
95
|
+
// keeps their own private key. Explicit --signature wins; otherwise the
|
|
96
|
+
// sibling .sig that `bundle sign` writes is picked up automatically, so the
|
|
97
|
+
// documented local-signing flow works without a new flag to remember.
|
|
98
|
+
const signature = await resolveSignature(target, bundle.path, options.signature);
|
|
99
|
+
if (signature) {
|
|
100
|
+
console.log(chalk.gray(` Signed: yes (${signature.source})`));
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
const payloadType = options.payloadType ?? 'web_bundle';
|
|
104
|
+
if (!['web_bundle', 'assets'].includes(payloadType)) {
|
|
105
|
+
throw new Error(`--payload-type must be web_bundle or assets, not "${payloadType}"`);
|
|
106
|
+
}
|
|
107
|
+
console.log(chalk.gray(` Payload: ${payloadType}`));
|
|
108
|
+
|
|
109
|
+
const { data } = await client.upload(`/apps/${options.app}/builds`, bundle.path, {
|
|
110
|
+
payload_type: payloadType,
|
|
111
|
+
version,
|
|
112
|
+
channel: options.channel,
|
|
113
|
+
release_notes: options.notes,
|
|
114
|
+
rollout_percentage: options.rollout,
|
|
115
|
+
min_native_version: options.minNative,
|
|
116
|
+
signature: signature?.value,
|
|
117
|
+
});
|
|
118
|
+
|
|
119
|
+
console.log(chalk.green(`\n✓ Bundle accepted — build #${data.build.id} is processing.`));
|
|
120
|
+
console.log(chalk.gray(` Job: ${data.job_id}`));
|
|
121
|
+
console.log(chalk.gray(` Status: ${data.status_url}`));
|
|
122
|
+
|
|
123
|
+
if (!options.wait) {
|
|
124
|
+
console.log(
|
|
125
|
+
chalk.gray(
|
|
126
|
+
`\n It goes live automatically when processing finishes.\n` +
|
|
127
|
+
` Add --wait to block until then, or poll:\n` +
|
|
128
|
+
` npx native-update jobs status ${data.job_id}`
|
|
129
|
+
)
|
|
130
|
+
);
|
|
131
|
+
return;
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
console.log(chalk.gray('\n Waiting for processing…'));
|
|
135
|
+
const job = await waitForJob(client, data.job_id);
|
|
136
|
+
console.log(
|
|
137
|
+
chalk.green(`\n✓ Live: v${job.result.version} on ${job.result.channel} (build #${job.result.build_id})`)
|
|
138
|
+
);
|
|
139
|
+
} finally {
|
|
140
|
+
await bundle.cleanup();
|
|
141
|
+
}
|
|
142
|
+
}
|
|
143
|
+
|
|
144
|
+
/**
|
|
145
|
+
* Resolve the detached bundle signature to upload, or null.
|
|
146
|
+
*
|
|
147
|
+
* Looks at --signature first, then the `<bundle>.sig` that `bundle sign` writes
|
|
148
|
+
* beside its output. Accepts either the JSON metadata that command produces or
|
|
149
|
+
* a file containing the bare base64 signature.
|
|
150
|
+
*
|
|
151
|
+
* 🔴 When the metadata carries `bundleSha256`, the bundle being uploaded is
|
|
152
|
+
* hashed and compared. A stale or mismatched .sig is REFUSED here rather than
|
|
153
|
+
* uploaded: the server cannot detect it (it has no public key to check
|
|
154
|
+
* against), so the failure would otherwise surface only on a device, as a
|
|
155
|
+
* release that silently never applies. That is ISSUE-08's failure mode and this
|
|
156
|
+
* guard exists so it cannot come back through the front door.
|
|
157
|
+
*/
|
|
158
|
+
async function resolveSignature(target, bundlePath, explicitPath) {
|
|
159
|
+
const candidates = [];
|
|
160
|
+
if (explicitPath) {
|
|
161
|
+
candidates.push(explicitPath);
|
|
162
|
+
} else {
|
|
163
|
+
// `bundle sign` writes <out>.sig next to <out>.zip; deploying either the
|
|
164
|
+
// signed zip or the original picks up the same file.
|
|
165
|
+
candidates.push(bundlePath.replace(/\.zip$/, '.sig'));
|
|
166
|
+
if (typeof target === 'string' && target.endsWith('.zip')) {
|
|
167
|
+
candidates.push(target.replace(/\.zip$/, '.sig'));
|
|
168
|
+
}
|
|
169
|
+
}
|
|
170
|
+
|
|
171
|
+
for (const candidate of candidates) {
|
|
172
|
+
const raw = await fs.readFile(candidate, 'utf-8').catch(() => null);
|
|
173
|
+
if (raw === null) continue;
|
|
174
|
+
|
|
175
|
+
let value = raw.trim();
|
|
176
|
+
let expected = null;
|
|
177
|
+
if (value.startsWith('{')) {
|
|
178
|
+
let meta;
|
|
179
|
+
try {
|
|
180
|
+
meta = JSON.parse(value);
|
|
181
|
+
} catch {
|
|
182
|
+
console.error(chalk.red(`Error: ${candidate} is not valid JSON and not a bare signature.`));
|
|
183
|
+
process.exit(1);
|
|
184
|
+
}
|
|
185
|
+
if (!meta.signature) {
|
|
186
|
+
console.error(chalk.red(`Error: ${candidate} has no "signature" field.`));
|
|
187
|
+
process.exit(1);
|
|
188
|
+
}
|
|
189
|
+
if (meta.algorithm && meta.algorithm !== 'RSA-SHA256') {
|
|
190
|
+
console.error(
|
|
191
|
+
chalk.red(`Error: ${candidate} is ${meta.algorithm}; the device verifies RSA-SHA256 only.`)
|
|
192
|
+
);
|
|
193
|
+
process.exit(1);
|
|
194
|
+
}
|
|
195
|
+
value = String(meta.signature).trim();
|
|
196
|
+
expected = meta.bundleSha256 ?? null;
|
|
197
|
+
}
|
|
198
|
+
|
|
199
|
+
if (expected) {
|
|
200
|
+
const actual = createHash('sha256').update(await fs.readFile(bundlePath)).digest('hex');
|
|
201
|
+
if (actual !== expected) {
|
|
202
|
+
console.error(chalk.red('\nError: that signature does not cover this bundle.'));
|
|
203
|
+
console.error(chalk.gray(` signature file: ${candidate}`));
|
|
204
|
+
console.error(chalk.gray(` signed sha256: ${expected}`));
|
|
205
|
+
console.error(chalk.gray(` bundle sha256: ${actual}`));
|
|
206
|
+
console.error(
|
|
207
|
+
chalk.gray(' Re-run `native-update bundle sign` on the bundle you are deploying.')
|
|
208
|
+
);
|
|
209
|
+
console.error(
|
|
210
|
+
chalk.gray(' Uploading it anyway would publish a release every device rejects.')
|
|
211
|
+
);
|
|
212
|
+
process.exit(1);
|
|
213
|
+
}
|
|
214
|
+
} else if (!explicitPath) {
|
|
215
|
+
console.log(
|
|
216
|
+
chalk.yellow(` Note: ${candidate} predates checksum recording — cannot confirm it matches.`)
|
|
217
|
+
);
|
|
218
|
+
}
|
|
219
|
+
|
|
220
|
+
return { value, source: explicitPath ? candidate : `auto-detected ${candidate}` };
|
|
221
|
+
}
|
|
222
|
+
|
|
223
|
+
if (explicitPath) {
|
|
224
|
+
console.error(chalk.red(`Error: signature file not found: ${explicitPath}`));
|
|
225
|
+
process.exit(1);
|
|
226
|
+
}
|
|
227
|
+
return null;
|
|
228
|
+
}
|
|
229
|
+
|
|
230
|
+
/** `native-update builds promote <app> <build> --to <channel>` */
|
|
231
|
+
export async function buildsPromote(app, build, options) {
|
|
232
|
+
const client = apiClient(options);
|
|
233
|
+
const { data } = await client.send('POST', `/apps/${app}/builds/${build}/promote`, {
|
|
234
|
+
target_channel: options.to,
|
|
235
|
+
});
|
|
236
|
+
|
|
237
|
+
console.log(
|
|
238
|
+
chalk.green(`✓ Promoted v${data.version} to ${data.channel} (new build #${data.id}).`)
|
|
239
|
+
);
|
|
240
|
+
}
|
|
241
|
+
|
|
242
|
+
/** `native-update builds rollout <app> <build> --percent <n>` */
|
|
243
|
+
export async function buildsRollout(app, build, options) {
|
|
244
|
+
const client = apiClient(options);
|
|
245
|
+
const percent = Number(options.percent);
|
|
246
|
+
|
|
247
|
+
if (!Number.isInteger(percent) || percent < 0 || percent > 100) {
|
|
248
|
+
console.error(chalk.red('Error: --percent must be a whole number from 0 to 100.'));
|
|
249
|
+
process.exit(1);
|
|
250
|
+
}
|
|
251
|
+
|
|
252
|
+
const { data } = await client.send('PATCH', `/apps/${app}/builds/${build}/rollout`, {
|
|
253
|
+
rollout_percentage: percent,
|
|
254
|
+
});
|
|
255
|
+
|
|
256
|
+
console.log(chalk.green(`✓ v${data.version} on ${data.channel} is now at ${data.rollout_percentage}%.`));
|
|
257
|
+
}
|
|
258
|
+
|
|
259
|
+
/** `native-update builds status <app> <build> --set <status>` */
|
|
260
|
+
export async function buildsStatus(app, build, options) {
|
|
261
|
+
const client = apiClient(options);
|
|
262
|
+
const { data } = await client.send('PATCH', `/apps/${app}/builds/${build}`, {
|
|
263
|
+
status: options.set,
|
|
264
|
+
});
|
|
265
|
+
|
|
266
|
+
console.log(chalk.green(`✓ Build #${data.id} (v${data.version}) is now ${data.status}.`));
|
|
267
|
+
}
|
|
268
|
+
|
|
269
|
+
/** `native-update builds delete <app> <build> --yes` */
|
|
270
|
+
export async function buildsDelete(app, build, options) {
|
|
271
|
+
if (!options.yes) {
|
|
272
|
+
console.error(chalk.red('Error: refusing to delete without --yes.'));
|
|
273
|
+
console.error(chalk.gray(' Deleting a build is permanent. Re-run with --yes to confirm.'));
|
|
274
|
+
process.exit(1);
|
|
275
|
+
}
|
|
276
|
+
|
|
277
|
+
const client = apiClient(options);
|
|
278
|
+
await client.send('DELETE', `/apps/${app}/builds/${build}`);
|
|
279
|
+
|
|
280
|
+
console.log(chalk.green(`✓ Build ${build} deleted.`));
|
|
281
|
+
}
|
|
282
|
+
|
|
283
|
+
/** `native-update jobs status <jobId>` */
|
|
284
|
+
export async function jobsStatus(jobId, options) {
|
|
285
|
+
const client = apiClient(options);
|
|
286
|
+
|
|
287
|
+
if (options.wait) {
|
|
288
|
+
const job = await waitForJob(client, jobId);
|
|
289
|
+
console.log(chalk.green(`\n✓ ${job.type} completed.`));
|
|
290
|
+
console.log(chalk.gray(` ${JSON.stringify(job.result)}`));
|
|
291
|
+
return;
|
|
292
|
+
}
|
|
293
|
+
|
|
294
|
+
const { data: job } = await client.get(`/jobs/${jobId}`);
|
|
295
|
+
|
|
296
|
+
console.log(chalk.bold(`\nJob ${job.id}`));
|
|
297
|
+
console.log(chalk.gray(` Type: ${job.type}`));
|
|
298
|
+
console.log(chalk.gray(` Status: ${job.status}`));
|
|
299
|
+
console.log(chalk.gray(` Attempts: ${job.attempts}`));
|
|
300
|
+
if (job.error) console.log(chalk.red(` Error: ${job.error}`));
|
|
301
|
+
if (job.result) console.log(chalk.gray(` Result: ${JSON.stringify(job.result)}`));
|
|
302
|
+
console.log('');
|
|
303
|
+
|
|
304
|
+
if (job.status === 'failed') process.exit(1);
|
|
305
|
+
}
|
|
306
|
+
|
|
307
|
+
// --- Apps (create / show / update / delete) --------------------------------
|
|
308
|
+
|
|
309
|
+
/** Print one app's fields consistently. */
|
|
310
|
+
function printApp(app) {
|
|
311
|
+
console.log(chalk.gray(` ID: ${app.id}`));
|
|
312
|
+
console.log(chalk.gray(` App ID: ${app.app_id}`));
|
|
313
|
+
console.log(chalk.gray(` Bundle ID: ${app.bundle_id ?? '—'}`));
|
|
314
|
+
console.log(chalk.gray(` Name: ${app.name}`));
|
|
315
|
+
console.log(chalk.gray(` Platform: ${app.platform ?? '—'}`));
|
|
316
|
+
if (app.description) console.log(chalk.gray(` Description: ${app.description}`));
|
|
317
|
+
}
|
|
318
|
+
|
|
319
|
+
/** `native-update apps create --name <name> [--bundle-id] [--platform] [--description]` */
|
|
320
|
+
export async function appsCreate(options) {
|
|
321
|
+
const client = apiClient(options);
|
|
322
|
+
const { data } = await client.send('POST', '/apps', {
|
|
323
|
+
name: options.name,
|
|
324
|
+
bundle_id: options.bundleId,
|
|
325
|
+
platform: options.platform,
|
|
326
|
+
description: options.description,
|
|
327
|
+
});
|
|
328
|
+
|
|
329
|
+
console.log(chalk.green(`\n✓ Created app "${data.name}".`));
|
|
330
|
+
printApp(data);
|
|
331
|
+
console.log(
|
|
332
|
+
chalk.gray(
|
|
333
|
+
`\n This token can now manage it. Next: create an API key —\n` +
|
|
334
|
+
` npx native-update apps keys create ${data.id}`
|
|
335
|
+
)
|
|
336
|
+
);
|
|
337
|
+
}
|
|
338
|
+
|
|
339
|
+
/** `native-update apps show <app>` */
|
|
340
|
+
export async function appsShow(app, options) {
|
|
341
|
+
const client = apiClient(options);
|
|
342
|
+
const { data } = await client.get(`/apps/${app}`);
|
|
343
|
+
|
|
344
|
+
console.log(chalk.bold(`\nApp ${data.name}`));
|
|
345
|
+
printApp(data);
|
|
346
|
+
console.log('');
|
|
347
|
+
}
|
|
348
|
+
|
|
349
|
+
/** `native-update apps update <app> [--name] [--platform] [--description]` */
|
|
350
|
+
export async function appsUpdate(app, options) {
|
|
351
|
+
const payload = {};
|
|
352
|
+
if (options.name !== undefined) payload.name = options.name;
|
|
353
|
+
if (options.platform !== undefined) payload.platform = options.platform;
|
|
354
|
+
if (options.description !== undefined) payload.description = options.description;
|
|
355
|
+
|
|
356
|
+
if (Object.keys(payload).length === 0) {
|
|
357
|
+
console.error(chalk.red('Error: nothing to update — pass --name, --platform, and/or --description.'));
|
|
358
|
+
process.exit(1);
|
|
359
|
+
}
|
|
360
|
+
|
|
361
|
+
const client = apiClient(options);
|
|
362
|
+
const { data } = await client.send('PATCH', `/apps/${app}`, payload);
|
|
363
|
+
|
|
364
|
+
console.log(chalk.green(`\n✓ Updated app "${data.name}".`));
|
|
365
|
+
printApp(data);
|
|
366
|
+
console.log('');
|
|
367
|
+
}
|
|
368
|
+
|
|
369
|
+
/** `native-update apps delete <app> --yes` (needs the apps.delete token permission) */
|
|
370
|
+
export async function appsDelete(app, options) {
|
|
371
|
+
if (!options.yes) {
|
|
372
|
+
console.error(chalk.red('Error: refusing to delete without --yes.'));
|
|
373
|
+
console.error(chalk.gray(' Deleting an app also deletes its builds + API keys. Re-run with --yes.'));
|
|
374
|
+
process.exit(1);
|
|
375
|
+
}
|
|
376
|
+
|
|
377
|
+
const client = apiClient(options);
|
|
378
|
+
await client.send('DELETE', `/apps/${app}`);
|
|
379
|
+
console.log(chalk.green(`✓ App ${app} deleted (builds + API keys cascaded).`));
|
|
380
|
+
}
|
|
381
|
+
|
|
382
|
+
// --- App API keys ----------------------------------------------------------
|
|
383
|
+
|
|
384
|
+
/** `native-update apps keys list <app>` */
|
|
385
|
+
export async function keysList(app, options) {
|
|
386
|
+
const client = apiClient(options);
|
|
387
|
+
const body = await client.get(`/apps/${app}/api-keys`);
|
|
388
|
+
|
|
389
|
+
console.log(chalk.bold(`\nAPI keys for ${app}`));
|
|
390
|
+
printTable(body.data, [
|
|
391
|
+
{ header: 'ID', value: (k) => k.id },
|
|
392
|
+
{ header: 'NAME', value: (k) => k.name },
|
|
393
|
+
{ header: 'PREVIEW', value: (k) => k.key_preview },
|
|
394
|
+
{ header: 'STATUS', value: (k) => k.status },
|
|
395
|
+
{ header: 'RESTRICTED', value: (k) => (k.unrestricted ? 'no' : 'yes') },
|
|
396
|
+
]);
|
|
397
|
+
console.log('');
|
|
398
|
+
}
|
|
399
|
+
|
|
400
|
+
function printPlaintextKey(key) {
|
|
401
|
+
console.log(chalk.green('\n✓ Store this key now — treat it like a password:'));
|
|
402
|
+
console.log(' ' + chalk.bold(key));
|
|
403
|
+
console.log(chalk.gray(' (recoverable later via `apps keys reveal`, but copy it now).\n'));
|
|
404
|
+
}
|
|
405
|
+
|
|
406
|
+
/** `native-update apps keys create <app> [--name]` */
|
|
407
|
+
export async function keysCreate(app, options) {
|
|
408
|
+
const client = apiClient(options);
|
|
409
|
+
const { data } = await client.send('POST', `/apps/${app}/api-keys`, {
|
|
410
|
+
name: options.name ?? `CLI key ${new Date().toISOString().slice(0, 10)}`,
|
|
411
|
+
});
|
|
412
|
+
|
|
413
|
+
console.log(chalk.bold(`\nCreated API key #${data.id} (${data.name})`));
|
|
414
|
+
printPlaintextKey(data.plaintext_key);
|
|
415
|
+
}
|
|
416
|
+
|
|
417
|
+
/** `native-update apps keys show <app> <key>` */
|
|
418
|
+
export async function keysShow(app, key, options) {
|
|
419
|
+
const client = apiClient(options);
|
|
420
|
+
const { data } = await client.get(`/apps/${app}/api-keys/${key}`);
|
|
421
|
+
|
|
422
|
+
console.log(chalk.bold(`\nAPI key #${data.id}`));
|
|
423
|
+
console.log(chalk.gray(` Name: ${data.name}`));
|
|
424
|
+
console.log(chalk.gray(` Preview: ${data.key_preview}`));
|
|
425
|
+
console.log(chalk.gray(` Status: ${data.status}`));
|
|
426
|
+
console.log(chalk.gray(` Restricted: ${data.unrestricted ? 'no' : 'yes'}`));
|
|
427
|
+
console.log('');
|
|
428
|
+
}
|
|
429
|
+
|
|
430
|
+
/** `native-update apps keys rotate <app> <key>` */
|
|
431
|
+
export async function keysRotate(app, key, options) {
|
|
432
|
+
const client = apiClient(options);
|
|
433
|
+
const { data } = await client.send('POST', `/apps/${app}/api-keys/${key}/rotate`);
|
|
434
|
+
|
|
435
|
+
console.log(chalk.bold(`\nRotated API key #${data.id} — the previous key is now invalid.`));
|
|
436
|
+
printPlaintextKey(data.plaintext_key);
|
|
437
|
+
}
|
|
438
|
+
|
|
439
|
+
/** `native-update apps keys reveal <app> <key>` */
|
|
440
|
+
export async function keysReveal(app, key, options) {
|
|
441
|
+
const client = apiClient(options);
|
|
442
|
+
const { data } = await client.send('POST', `/apps/${app}/api-keys/${key}/reveal`);
|
|
443
|
+
printPlaintextKey(data.plaintext_key);
|
|
444
|
+
}
|
|
445
|
+
|
|
446
|
+
/** `native-update apps keys revoke <app> <key>` */
|
|
447
|
+
export async function keysRevoke(app, key, options) {
|
|
448
|
+
const client = apiClient(options);
|
|
449
|
+
const { data } = await client.send('POST', `/apps/${app}/api-keys/${key}/revoke`);
|
|
450
|
+
console.log(chalk.green(`✓ API key #${data.id} revoked.`));
|
|
451
|
+
}
|
|
452
|
+
|
|
453
|
+
/** `native-update apps keys deprecate <app> <key>` */
|
|
454
|
+
export async function keysDeprecate(app, key, options) {
|
|
455
|
+
const client = apiClient(options);
|
|
456
|
+
const { data } = await client.send('POST', `/apps/${app}/api-keys/${key}/deprecate`);
|
|
457
|
+
console.log(chalk.green(`✓ API key #${data.id} deprecated (still works, usage logged).`));
|
|
458
|
+
}
|
|
459
|
+
|
|
460
|
+
/** `native-update apps keys restrict <app> <key> --json <restrictionsJson>` */
|
|
461
|
+
export async function keysRestrict(app, key, options) {
|
|
462
|
+
let payload;
|
|
463
|
+
try {
|
|
464
|
+
payload = JSON.parse(options.json);
|
|
465
|
+
} catch (e) {
|
|
466
|
+
console.error(chalk.red('Error: --json must be valid JSON.'));
|
|
467
|
+
console.error(
|
|
468
|
+
chalk.gray(
|
|
469
|
+
' Example: --json \'{"origins":["https://app.example.com"],' +
|
|
470
|
+
'"android":[{"package_name":"com.example.app","sha256":["AB:CD:…"]}]}\'\n' +
|
|
471
|
+
' Pass {} to clear all restrictions (make the key unrestricted).'
|
|
472
|
+
)
|
|
473
|
+
);
|
|
474
|
+
process.exit(1);
|
|
475
|
+
}
|
|
476
|
+
|
|
477
|
+
const client = apiClient(options);
|
|
478
|
+
const { data } = await client.send('PATCH', `/apps/${app}/api-keys/${key}/restrictions`, payload);
|
|
479
|
+
console.log(
|
|
480
|
+
chalk.green(
|
|
481
|
+
`✓ Restrictions ${data.unrestricted ? 'cleared — key is now unrestricted' : 'saved'} for key #${data.id}.`
|
|
482
|
+
)
|
|
483
|
+
);
|
|
484
|
+
}
|
|
485
|
+
|
|
486
|
+
/** `native-update apps keys delete <app> <key> --yes` (needs keys.delete) */
|
|
487
|
+
export async function keysDelete(app, key, options) {
|
|
488
|
+
if (!options.yes) {
|
|
489
|
+
console.error(chalk.red('Error: refusing to delete without --yes.'));
|
|
490
|
+
console.error(chalk.gray(' Deleting a key is permanent — apps using it lose access. Re-run with --yes.'));
|
|
491
|
+
process.exit(1);
|
|
492
|
+
}
|
|
493
|
+
|
|
494
|
+
const client = apiClient(options);
|
|
495
|
+
await client.send('DELETE', `/apps/${app}/api-keys/${key}`);
|
|
496
|
+
console.log(chalk.green(`✓ API key ${key} deleted.`));
|
|
497
|
+
}
|
|
498
|
+
|
|
499
|
+
// --- Signing keys ----------------------------------------------------------
|
|
500
|
+
|
|
501
|
+
function printSigningKey(data) {
|
|
502
|
+
console.log(chalk.gray(` ID: ${data.id}`));
|
|
503
|
+
console.log(chalk.gray(` Name: ${data.name ?? '—'}`));
|
|
504
|
+
console.log(chalk.gray(` Fingerprint: ${data.fingerprint}`));
|
|
505
|
+
console.log(chalk.gray(` Status: ${data.status}`));
|
|
506
|
+
console.log(chalk.bold(' Public key:'));
|
|
507
|
+
console.log(data.public_key);
|
|
508
|
+
}
|
|
509
|
+
|
|
510
|
+
/** `native-update apps signing show <app>` */
|
|
511
|
+
export async function signingShow(app, options) {
|
|
512
|
+
const client = apiClient(options);
|
|
513
|
+
const { data } = await client.get(`/apps/${app}/signing-key`);
|
|
514
|
+
|
|
515
|
+
if (!data.configured) {
|
|
516
|
+
console.log(chalk.gray(`\n No signing key configured for ${app}. Create one:`));
|
|
517
|
+
console.log(chalk.gray(` npx native-update apps signing create ${app}\n`));
|
|
518
|
+
return;
|
|
519
|
+
}
|
|
520
|
+
|
|
521
|
+
console.log(chalk.bold(`\nSigning key for ${app}`));
|
|
522
|
+
printSigningKey(data);
|
|
523
|
+
console.log('');
|
|
524
|
+
}
|
|
525
|
+
|
|
526
|
+
/** `native-update apps signing create <app> [--name]` */
|
|
527
|
+
export async function signingCreate(app, options) {
|
|
528
|
+
const client = apiClient(options);
|
|
529
|
+
const { data } = await client.send('POST', `/apps/${app}/signing-key`, { name: options.name });
|
|
530
|
+
|
|
531
|
+
console.log(chalk.green(`\n✓ Signing key created for ${app}.`));
|
|
532
|
+
printSigningKey(data);
|
|
533
|
+
console.log(chalk.gray('\n Add this public key to your app config to verify signed bundles.\n'));
|
|
534
|
+
}
|
|
535
|
+
|
|
536
|
+
/** `native-update apps signing rotate <app> [--name]` */
|
|
537
|
+
export async function signingRotate(app, options) {
|
|
538
|
+
const client = apiClient(options);
|
|
539
|
+
const { data } = await client.send('POST', `/apps/${app}/signing-key/rotate`, { name: options.name });
|
|
540
|
+
|
|
541
|
+
console.log(chalk.green(`\n✓ Signing key rotated for ${app} — update your app config with the new public key.`));
|
|
542
|
+
printSigningKey(data);
|
|
543
|
+
console.log('');
|
|
544
|
+
}
|
|
545
|
+
|
|
546
|
+
// --- Keystore backup -------------------------------------------------------
|
|
547
|
+
|
|
548
|
+
function printKeystore(meta) {
|
|
549
|
+
console.log(chalk.gray(` File: ${meta.original_name}`));
|
|
550
|
+
console.log(chalk.gray(` Size: ${(meta.size_bytes / 1024).toFixed(1)} KB`));
|
|
551
|
+
console.log(chalk.gray(` SHA-256: ${meta.sha256}`));
|
|
552
|
+
console.log(chalk.gray(` Uploaded: ${meta.uploaded_at}`));
|
|
553
|
+
}
|
|
554
|
+
|
|
555
|
+
/** `native-update apps keystore upload <app> <zipPath>` */
|
|
556
|
+
export async function keystoreUpload(app, zipPath, options) {
|
|
557
|
+
if (!zipPath.endsWith('.zip')) {
|
|
558
|
+
console.error(chalk.red('Error: the keystore backup must be a .zip file.'));
|
|
559
|
+
console.error(chalk.gray(' Zip your keystore first (an added layer of protection), then upload the .zip.'));
|
|
560
|
+
process.exit(1);
|
|
561
|
+
}
|
|
562
|
+
|
|
563
|
+
const stat = await fs.stat(zipPath).catch(() => null);
|
|
564
|
+
if (!stat) {
|
|
565
|
+
console.error(chalk.red(`Error: ${zipPath} does not exist.`));
|
|
566
|
+
process.exit(1);
|
|
567
|
+
}
|
|
568
|
+
|
|
569
|
+
const client = apiClient(options);
|
|
570
|
+
const { data } = await client.upload(`/apps/${app}/keystore`, zipPath, {});
|
|
571
|
+
|
|
572
|
+
console.log(chalk.green(`\n✓ Keystore backup saved for ${app} (private).`));
|
|
573
|
+
printKeystore(data);
|
|
574
|
+
console.log('');
|
|
575
|
+
}
|
|
576
|
+
|
|
577
|
+
/** `native-update apps keystore info <app>` */
|
|
578
|
+
export async function keystoreInfo(app, options) {
|
|
579
|
+
const client = apiClient(options);
|
|
580
|
+
const { data } = await client.get(`/apps/${app}/keystore`);
|
|
581
|
+
|
|
582
|
+
if (!data.configured) {
|
|
583
|
+
console.log(chalk.gray(`\n No keystore backup for ${app}.\n`));
|
|
584
|
+
return;
|
|
585
|
+
}
|
|
586
|
+
|
|
587
|
+
console.log(chalk.bold(`\nKeystore backup for ${app}`));
|
|
588
|
+
printKeystore(data);
|
|
589
|
+
console.log('');
|
|
590
|
+
}
|
|
591
|
+
|
|
592
|
+
/** `native-update apps keystore download <app> [-o file.zip]` */
|
|
593
|
+
export async function keystoreDownload(app, options) {
|
|
594
|
+
const client = apiClient(options);
|
|
595
|
+
const outFile = options.output ?? `keystore-${app}.zip`;
|
|
596
|
+
|
|
597
|
+
const { bytes } = await client.download(`/apps/${app}/keystore/download`, outFile);
|
|
598
|
+
console.log(chalk.green(`✓ Downloaded keystore backup → ${outFile} (${(bytes / 1024).toFixed(1)} KB).`));
|
|
599
|
+
}
|
|
600
|
+
|
|
601
|
+
/** `native-update apps keystore delete <app> --yes` */
|
|
602
|
+
export async function keystoreDelete(app, options) {
|
|
603
|
+
if (!options.yes) {
|
|
604
|
+
console.error(chalk.red('Error: refusing to delete without --yes.'));
|
|
605
|
+
console.error(chalk.gray(' This removes the stored keystore backup permanently. Re-run with --yes.'));
|
|
606
|
+
process.exit(1);
|
|
607
|
+
}
|
|
608
|
+
|
|
609
|
+
const client = apiClient(options);
|
|
610
|
+
await client.send('DELETE', `/apps/${app}/keystore`);
|
|
611
|
+
console.log(chalk.green(`✓ Keystore backup for ${app} deleted.`));
|
|
612
|
+
}
|
|
613
|
+
|
|
614
|
+
/** Default the version from the project's package.json, like `bundle create` does. */
|
|
615
|
+
async function versionFromPackageJson() {
|
|
616
|
+
try {
|
|
617
|
+
const raw = await fs.readFile(path.join(process.cwd(), 'package.json'), 'utf-8');
|
|
618
|
+
return JSON.parse(raw).version ?? null;
|
|
619
|
+
} catch {
|
|
620
|
+
return null;
|
|
621
|
+
}
|
|
622
|
+
}
|