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,262 @@
|
|
|
1
|
+
import chalk from 'chalk';
|
|
2
|
+
import fs from 'fs/promises';
|
|
3
|
+
import path from 'path';
|
|
4
|
+
import os from 'os';
|
|
5
|
+
import { ZipArchive } from 'archiver';
|
|
6
|
+
import { createWriteStream, createReadStream } from 'fs';
|
|
7
|
+
|
|
8
|
+
/** Where the hosted backend lives unless told otherwise. */
|
|
9
|
+
export const DEFAULT_SERVER = 'https://nativeupdatebe.aoneahsan.com';
|
|
10
|
+
|
|
11
|
+
/**
|
|
12
|
+
* Resolve the access token. A flag wins over the environment, but the
|
|
13
|
+
* environment is the intended path for CI — passing a secret as an argv flag
|
|
14
|
+
* leaks it into shell history and process listings.
|
|
15
|
+
*/
|
|
16
|
+
export function resolveToken(options) {
|
|
17
|
+
const token = options.token || process.env.NATIVE_UPDATE_TOKEN;
|
|
18
|
+
|
|
19
|
+
if (!token) {
|
|
20
|
+
console.error(chalk.red('Error: no access token.'));
|
|
21
|
+
console.error(
|
|
22
|
+
chalk.gray(' Set NATIVE_UPDATE_TOKEN, or pass --token. Create a token at\n') +
|
|
23
|
+
chalk.blue(' https://nativeupdate.aoneahsan.com/dashboard/access-tokens')
|
|
24
|
+
);
|
|
25
|
+
process.exit(1);
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
if (!/^nu_pat_[a-f0-9]{64}_[a-f0-9]{4}$/.test(token)) {
|
|
29
|
+
console.error(chalk.red('Error: that does not look like an access token.'));
|
|
30
|
+
console.error(
|
|
31
|
+
chalk.gray(
|
|
32
|
+
' Access tokens start with nu_pat_. An app API key (nu_app_…) authenticates\n' +
|
|
33
|
+
' the device update plane and is not accepted here.'
|
|
34
|
+
)
|
|
35
|
+
);
|
|
36
|
+
process.exit(1);
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
return token;
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
export function resolveServer(options) {
|
|
43
|
+
const base = options.server || process.env.NATIVE_UPDATE_SERVER || DEFAULT_SERVER;
|
|
44
|
+
return base.replace(/\/+$/, '');
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
/**
|
|
48
|
+
* A thin client over the public management API. Every call returns the parsed
|
|
49
|
+
* `data` envelope, or exits non-zero after printing the API's own error message
|
|
50
|
+
* — the backend already explains what went wrong and how to fix it, so the CLI
|
|
51
|
+
* relays that rather than inventing its own wording.
|
|
52
|
+
*/
|
|
53
|
+
export function apiClient(options) {
|
|
54
|
+
const token = resolveToken(options);
|
|
55
|
+
const server = resolveServer(options);
|
|
56
|
+
const base = `${server}/api/public/v1`;
|
|
57
|
+
|
|
58
|
+
async function handle(res, path) {
|
|
59
|
+
if (res.status === 204) return null;
|
|
60
|
+
|
|
61
|
+
let body;
|
|
62
|
+
try {
|
|
63
|
+
body = await res.json();
|
|
64
|
+
} catch {
|
|
65
|
+
fail(`${res.status} ${res.statusText}`, `Unreadable response from ${base}${path}`);
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
if (!res.ok) {
|
|
69
|
+
const err = body?.error ?? {};
|
|
70
|
+
// Laravel's validator answers 422 with {message, errors:{field:[…]}},
|
|
71
|
+
// which is a different shape from our {error:{code,message}} envelope.
|
|
72
|
+
const message = err.message ?? body?.message ?? `${res.status} ${res.statusText}`;
|
|
73
|
+
const details = body?.errors
|
|
74
|
+
? Object.entries(body.errors)
|
|
75
|
+
.map(([field, msgs]) => ` ${field}: ${[].concat(msgs).join(' ')}`)
|
|
76
|
+
.join('\n')
|
|
77
|
+
: null;
|
|
78
|
+
fail(err.code ?? `HTTP ${res.status}`, message, details);
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
return body;
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
function fail(code, message, details) {
|
|
85
|
+
console.error(chalk.red(`Error (${code}): ${message}`));
|
|
86
|
+
if (details) console.error(chalk.gray(details));
|
|
87
|
+
process.exit(1);
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
return {
|
|
91
|
+
server,
|
|
92
|
+
base,
|
|
93
|
+
|
|
94
|
+
async get(path) {
|
|
95
|
+
const res = await fetch(`${base}${path}`, {
|
|
96
|
+
headers: { Authorization: `Bearer ${token}`, Accept: 'application/json' },
|
|
97
|
+
});
|
|
98
|
+
return handle(res, path);
|
|
99
|
+
},
|
|
100
|
+
|
|
101
|
+
async send(method, path, payload) {
|
|
102
|
+
const res = await fetch(`${base}${path}`, {
|
|
103
|
+
method,
|
|
104
|
+
headers: {
|
|
105
|
+
Authorization: `Bearer ${token}`,
|
|
106
|
+
Accept: 'application/json',
|
|
107
|
+
'Content-Type': 'application/json',
|
|
108
|
+
},
|
|
109
|
+
body: payload === undefined ? undefined : JSON.stringify(payload),
|
|
110
|
+
});
|
|
111
|
+
return handle(res, path);
|
|
112
|
+
},
|
|
113
|
+
|
|
114
|
+
/** Multipart upload. Node >= 20 gives us fetch + FormData + Blob natively. */
|
|
115
|
+
async upload(path, filePath, fields) {
|
|
116
|
+
const form = new FormData();
|
|
117
|
+
const buffer = await fs.readFile(filePath);
|
|
118
|
+
form.append('file', new Blob([buffer], { type: 'application/zip' }), path_basename(filePath));
|
|
119
|
+
for (const [key, value] of Object.entries(fields)) {
|
|
120
|
+
if (value !== undefined && value !== null && value !== '') {
|
|
121
|
+
form.append(key, String(value));
|
|
122
|
+
}
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
const res = await fetch(`${base}${path}`, {
|
|
126
|
+
method: 'POST',
|
|
127
|
+
headers: { Authorization: `Bearer ${token}`, Accept: 'application/json' },
|
|
128
|
+
body: form,
|
|
129
|
+
});
|
|
130
|
+
return handle(res, path);
|
|
131
|
+
},
|
|
132
|
+
|
|
133
|
+
/**
|
|
134
|
+
* Download a binary body (the private keystore zip) to a local file. On a
|
|
135
|
+
* non-2xx it relays the API's JSON error like every other call rather than
|
|
136
|
+
* writing an error page to disk.
|
|
137
|
+
*/
|
|
138
|
+
async download(path, outFile) {
|
|
139
|
+
const res = await fetch(`${base}${path}`, {
|
|
140
|
+
headers: { Authorization: `Bearer ${token}`, Accept: 'application/octet-stream' },
|
|
141
|
+
});
|
|
142
|
+
|
|
143
|
+
if (!res.ok) {
|
|
144
|
+
let body;
|
|
145
|
+
try {
|
|
146
|
+
body = await res.json();
|
|
147
|
+
} catch {
|
|
148
|
+
fail(`HTTP ${res.status}`, `${res.status} ${res.statusText}`);
|
|
149
|
+
}
|
|
150
|
+
const err = body?.error ?? {};
|
|
151
|
+
fail(err.code ?? `HTTP ${res.status}`, err.message ?? body?.message ?? `${res.status} ${res.statusText}`);
|
|
152
|
+
}
|
|
153
|
+
|
|
154
|
+
const buffer = Buffer.from(await res.arrayBuffer());
|
|
155
|
+
await fs.writeFile(outFile, buffer);
|
|
156
|
+
return { bytes: buffer.length, path: outFile };
|
|
157
|
+
},
|
|
158
|
+
};
|
|
159
|
+
}
|
|
160
|
+
|
|
161
|
+
function path_basename(p) {
|
|
162
|
+
return path.basename(p);
|
|
163
|
+
}
|
|
164
|
+
|
|
165
|
+
/**
|
|
166
|
+
* Poll a job until it finishes. Uploads are queued server-side, so this is what
|
|
167
|
+
* turns "accepted" into "actually live" for a CI step that must fail the build
|
|
168
|
+
* when a release fails.
|
|
169
|
+
*/
|
|
170
|
+
export async function waitForJob(client, jobId, { intervalMs = 5000, timeoutMs = 600000 } = {}) {
|
|
171
|
+
const startedAt = Date.now();
|
|
172
|
+
|
|
173
|
+
for (;;) {
|
|
174
|
+
const { data: job } = await client.get(`/jobs/${jobId}`);
|
|
175
|
+
|
|
176
|
+
if (job.status === 'completed') return job;
|
|
177
|
+
|
|
178
|
+
if (job.status === 'failed') {
|
|
179
|
+
console.error(chalk.red(`Job failed: ${job.error ?? 'no reason reported'}`));
|
|
180
|
+
process.exit(1);
|
|
181
|
+
}
|
|
182
|
+
|
|
183
|
+
if (Date.now() - startedAt > timeoutMs) {
|
|
184
|
+
console.error(
|
|
185
|
+
chalk.red(`Timed out after ${Math.round(timeoutMs / 1000)}s waiting for job ${jobId}.`)
|
|
186
|
+
);
|
|
187
|
+
console.error(chalk.gray(` The job may still finish — check ${job.status_url}`));
|
|
188
|
+
process.exit(1);
|
|
189
|
+
}
|
|
190
|
+
|
|
191
|
+
process.stdout.write(chalk.gray(` status: ${job.status}…\r`));
|
|
192
|
+
await new Promise((resolve) => setTimeout(resolve, intervalMs));
|
|
193
|
+
}
|
|
194
|
+
}
|
|
195
|
+
|
|
196
|
+
/**
|
|
197
|
+
* Accept either a prebuilt .zip or a web directory. Passing a directory is the
|
|
198
|
+
* common CI case ("deploy ./dist"), so zip it into a temp file rather than
|
|
199
|
+
* making every pipeline shell out to `zip` first.
|
|
200
|
+
*
|
|
201
|
+
* @returns {Promise<{path: string, cleanup: () => Promise<void>}>}
|
|
202
|
+
*/
|
|
203
|
+
export async function resolveBundle(target) {
|
|
204
|
+
const stat = await fs.stat(target).catch(() => null);
|
|
205
|
+
|
|
206
|
+
if (!stat) {
|
|
207
|
+
console.error(chalk.red(`Error: ${target} does not exist.`));
|
|
208
|
+
process.exit(1);
|
|
209
|
+
}
|
|
210
|
+
|
|
211
|
+
if (stat.isFile()) {
|
|
212
|
+
if (!target.endsWith('.zip')) {
|
|
213
|
+
console.error(chalk.red('Error: a bundle file must be a .zip.'));
|
|
214
|
+
process.exit(1);
|
|
215
|
+
}
|
|
216
|
+
return { path: target, cleanup: async () => {} };
|
|
217
|
+
}
|
|
218
|
+
|
|
219
|
+
const tempDir = await fs.mkdtemp(path.join(os.tmpdir(), 'native-update-'));
|
|
220
|
+
const zipPath = path.join(tempDir, 'bundle.zip');
|
|
221
|
+
|
|
222
|
+
console.log(chalk.gray(` Zipping ${target}…`));
|
|
223
|
+
|
|
224
|
+
const output = createWriteStream(zipPath);
|
|
225
|
+
const archive = new ZipArchive({ zlib: { level: 9 } });
|
|
226
|
+
const done = new Promise((resolve, reject) => {
|
|
227
|
+
output.on('close', resolve);
|
|
228
|
+
archive.on('error', reject);
|
|
229
|
+
});
|
|
230
|
+
|
|
231
|
+
archive.pipe(output);
|
|
232
|
+
archive.directory(target, false);
|
|
233
|
+
await archive.finalize();
|
|
234
|
+
await done;
|
|
235
|
+
|
|
236
|
+
return {
|
|
237
|
+
path: zipPath,
|
|
238
|
+
cleanup: () => fs.rm(tempDir, { recursive: true, force: true }),
|
|
239
|
+
};
|
|
240
|
+
}
|
|
241
|
+
|
|
242
|
+
/** Render rows as a simple aligned table — no dependency, readable in CI logs. */
|
|
243
|
+
export function printTable(rows, columns) {
|
|
244
|
+
if (rows.length === 0) {
|
|
245
|
+
console.log(chalk.gray(' (none)'));
|
|
246
|
+
return;
|
|
247
|
+
}
|
|
248
|
+
|
|
249
|
+
const widths = columns.map((col) =>
|
|
250
|
+
Math.max(col.header.length, ...rows.map((row) => String(col.value(row) ?? '').length))
|
|
251
|
+
);
|
|
252
|
+
|
|
253
|
+
console.log(
|
|
254
|
+
' ' + columns.map((col, i) => chalk.bold(col.header.padEnd(widths[i]))).join(' ')
|
|
255
|
+
);
|
|
256
|
+
|
|
257
|
+
for (const row of rows) {
|
|
258
|
+
console.log(
|
|
259
|
+
' ' + columns.map((col, i) => String(col.value(row) ?? '').padEnd(widths[i])).join(' ')
|
|
260
|
+
);
|
|
261
|
+
}
|
|
262
|
+
}
|