@capgo/capacitor-updater 9.0.0 → 9.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/CapgoCapacitorUpdater.podspec +3 -6
- package/Package.swift +30 -0
- package/README.md +2382 -292
- package/android/build.gradle +37 -15
- package/android/consumer-rules.pro +48 -0
- package/android/proguard-rules.pro +23 -0
- package/android/src/main/AndroidManifest.xml +0 -1
- package/android/src/main/java/ee/forgr/capacitor_updater/AndroidAppExitReporter.java +92 -0
- package/android/src/main/java/ee/forgr/capacitor_updater/AppLifecycleObserver.java +115 -0
- package/android/src/main/java/ee/forgr/capacitor_updater/BundleInfo.java +227 -195
- package/android/src/main/java/ee/forgr/capacitor_updater/BundleStatus.java +24 -23
- package/android/src/main/java/ee/forgr/capacitor_updater/Callback.java +13 -0
- package/android/src/main/java/ee/forgr/capacitor_updater/CapacitorUpdaterPlugin.java +7435 -1243
- package/android/src/main/java/ee/forgr/capacitor_updater/CapgoUpdater.java +5144 -0
- package/android/src/main/java/ee/forgr/capacitor_updater/CryptoCipher.java +564 -121
- package/android/src/main/java/ee/forgr/capacitor_updater/DataManager.java +44 -0
- package/android/src/main/java/ee/forgr/capacitor_updater/DelayCondition.java +43 -49
- package/android/src/main/java/ee/forgr/capacitor_updater/DelayUntilNext.java +4 -4
- package/android/src/main/java/ee/forgr/capacitor_updater/DelayUpdateUtils.java +427 -0
- package/android/src/main/java/ee/forgr/capacitor_updater/DeviceIdHelper.java +230 -0
- package/android/src/main/java/ee/forgr/capacitor_updater/DownloadService.java +1969 -118
- package/android/src/main/java/ee/forgr/capacitor_updater/DownloadWorkerManager.java +278 -0
- package/android/src/main/java/ee/forgr/capacitor_updater/HeadlessUpdateWorker.java +385 -0
- package/android/src/main/java/ee/forgr/capacitor_updater/Http3.java +356 -0
- package/android/src/main/java/ee/forgr/capacitor_updater/HttpEngineTransport.java +553 -0
- package/android/src/main/java/ee/forgr/capacitor_updater/InternalUtils.java +79 -0
- package/android/src/main/java/ee/forgr/capacitor_updater/Logger.java +419 -0
- package/android/src/main/java/ee/forgr/capacitor_updater/NativeUpdatePrompt.java +303 -0
- package/android/src/main/java/ee/forgr/capacitor_updater/ShakeDetector.java +72 -0
- package/android/src/main/java/ee/forgr/capacitor_updater/ShakeMenu.java +959 -0
- package/android/src/main/java/ee/forgr/capacitor_updater/StatsBatchFailureDiagnostics.java +40 -0
- package/android/src/main/java/ee/forgr/capacitor_updater/ThreeFingerPinchDetector.java +323 -0
- package/android/src/main/java/ee/forgr/capacitor_updater/Version.java +306 -0
- package/dist/docs.json +4431 -840
- package/dist/esm/definitions.d.ts +2607 -225
- package/dist/esm/definitions.js +103 -1
- package/dist/esm/definitions.js.map +1 -1
- package/dist/esm/history.d.ts +1 -0
- package/dist/esm/history.js +283 -0
- package/dist/esm/history.js.map +1 -0
- package/dist/esm/index.d.ts +3 -2
- package/dist/esm/index.js +5 -4
- package/dist/esm/index.js.map +1 -1
- package/dist/esm/web.d.ts +53 -42
- package/dist/esm/web.js +180 -37
- package/dist/esm/web.js.map +1 -1
- package/dist/plugin.cjs.js +570 -37
- package/dist/plugin.cjs.js.map +1 -1
- package/dist/plugin.js +570 -37
- package/dist/plugin.js.map +1 -1
- package/ios/Sources/CapacitorUpdaterPlugin/AES.swift +262 -0
- package/ios/Sources/CapacitorUpdaterPlugin/AppHealthTracker.swift +82 -0
- package/ios/Sources/CapacitorUpdaterPlugin/BundleInfo.swift +185 -0
- package/ios/Sources/CapacitorUpdaterPlugin/BundleStatus.swift +127 -0
- package/ios/Sources/CapacitorUpdaterPlugin/CapacitorUpdaterPlugin.swift +5642 -0
- package/ios/Sources/CapacitorUpdaterPlugin/CapgoRawRsa.swift +36 -0
- package/ios/Sources/CapacitorUpdaterPlugin/CapgoSemanticVersion.swift +162 -0
- package/ios/Sources/CapacitorUpdaterPlugin/CapgoUpdater.swift +4572 -0
- package/ios/Sources/CapacitorUpdaterPlugin/CryptoCipher.swift +380 -0
- package/ios/Sources/CapacitorUpdaterPlugin/DelayUpdateUtils.swift +343 -0
- package/ios/Sources/CapacitorUpdaterPlugin/DeviceIdHelper.swift +120 -0
- package/ios/Sources/CapacitorUpdaterPlugin/InternalUtils.swift +452 -0
- package/ios/Sources/CapacitorUpdaterPlugin/Logger.swift +380 -0
- package/ios/Sources/CapacitorUpdaterPlugin/NativeUpdatePrompt.swift +183 -0
- package/ios/Sources/CapacitorUpdaterPlugin/RSA.swift +96 -0
- package/ios/Sources/CapacitorUpdaterPlugin/RedirectPolicyDelegate.swift +97 -0
- package/ios/Sources/CapacitorUpdaterPlugin/ShakeMenu.swift +871 -0
- package/ios/{Plugin → Sources/CapacitorUpdaterPlugin}/UserDefaultsExtension.swift +0 -2
- package/ios/Sources/CapacitorUpdaterPlugin/WKWebView+CapgoObjcBridge.swift +20 -0
- package/ios/Sources/CapacitorUpdaterPlugin/WebViewStatsReporter.swift +304 -0
- package/ios/Sources/CapacitorUpdaterPlugin/ZipArchiveReader.swift +247 -0
- package/ios/Sources/CapacitorUpdaterPlugin/ZipCentralDirectory.swift +280 -0
- package/ios/Tests/CapacitorUpdaterPluginTests/BuiltinHashesTests.swift +210 -0
- package/ios/Tests/CapacitorUpdaterPluginTests/BundleHardeningTests.swift +292 -0
- package/ios/Tests/CapacitorUpdaterPluginTests/CapacitorUpdaterPluginTests.swift +3905 -0
- package/ios/Tests/CapacitorUpdaterPluginTests/CapgoSemanticVersionTests.swift +64 -0
- package/ios/Tests/CapacitorUpdaterPluginTests/ChecksumRequiredTests.swift +151 -0
- package/ios/Tests/CapacitorUpdaterPluginTests/CliCryptoFixtureTests.swift +249 -0
- package/ios/Tests/CapacitorUpdaterPluginTests/HttpsOnlyBuiltinMinimumTests.swift +528 -0
- package/ios/Tests/CapacitorUpdaterPluginTests/InstallPerfTests.swift +174 -0
- package/ios/Tests/CapacitorUpdaterPluginTests/ListChannelsTests.swift +74 -0
- package/ios/Tests/CapacitorUpdaterPluginTests/LoggerSecurityTests.swift +149 -0
- package/ios/Tests/CapacitorUpdaterPluginTests/NativeContractTests.swift +160 -0
- package/ios/Tests/CapacitorUpdaterPluginTests/NetworkTransportTests.swift +1095 -0
- package/ios/Tests/CapacitorUpdaterPluginTests/PopulateDeltaCacheTests.swift +573 -0
- package/ios/Tests/CapacitorUpdaterPluginTests/RedirectPolicyTests.swift +63 -0
- package/ios/Tests/CapacitorUpdaterPluginTests/RsaContractTests.swift +281 -0
- package/ios/Tests/CapacitorUpdaterPluginTests/SessionKeyRequiredTests.swift +192 -0
- package/ios/Tests/CapacitorUpdaterPluginTests/TestZipWriter.swift +235 -0
- package/ios/Tests/CapacitorUpdaterPluginTests/UpdateLifecycleTests.swift +454 -0
- package/ios/Tests/CapacitorUpdaterPluginTests/WebKitOverlayGuardTests.swift +32 -0
- package/ios/Tests/CapacitorUpdaterPluginTests/ZipArchiveReaderTests.swift +302 -0
- package/ios/Tests/CapacitorUpdaterPluginTests/ZipBundleExtractionTests.swift +122 -0
- package/package.json +80 -43
- package/scripts/builtin-hashes-lib.mjs +148 -0
- package/scripts/capacitor-builtin-hashes-hook.mjs +65 -0
- package/scripts/resolve-real-path.mjs +25 -0
- package/android/src/main/java/ee/forgr/capacitor_updater/CapacitorUpdater.java +0 -1130
- package/ios/Plugin/BundleInfo.swift +0 -113
- package/ios/Plugin/BundleStatus.swift +0 -48
- package/ios/Plugin/CapacitorUpdater.swift +0 -858
- package/ios/Plugin/CapacitorUpdaterPlugin.h +0 -10
- package/ios/Plugin/CapacitorUpdaterPlugin.m +0 -27
- package/ios/Plugin/CapacitorUpdaterPlugin.swift +0 -677
- package/ios/Plugin/CryptoCipher.swift +0 -240
- /package/{LICENCE → LICENSE} +0 -0
- /package/ios/{Plugin → Sources/CapacitorUpdaterPlugin}/DelayCondition.swift +0 -0
- /package/ios/{Plugin → Sources/CapacitorUpdaterPlugin}/DelayUntilNext.swift +0 -0
- /package/ios/{Plugin → Sources/CapacitorUpdaterPlugin}/Info.plist +0 -0
|
@@ -0,0 +1,148 @@
|
|
|
1
|
+
import { createHash } from 'node:crypto';
|
|
2
|
+
import fs from 'node:fs';
|
|
3
|
+
import path from 'node:path';
|
|
4
|
+
import process from 'node:process';
|
|
5
|
+
import { resolveRealPath } from './resolve-real-path.mjs';
|
|
6
|
+
|
|
7
|
+
export const BUILTIN_HASHES_FILE_NAME = 'ota-builtin-hashes.json';
|
|
8
|
+
|
|
9
|
+
/** On Android, sized manifest rows compare against uncompressed asset length (openFd when stored uncompressed, otherwise InputStream). */
|
|
10
|
+
|
|
11
|
+
export function sha256File(file) {
|
|
12
|
+
const hash = createHash('sha256');
|
|
13
|
+
const fd = fs.openSync(file, 'r');
|
|
14
|
+
try {
|
|
15
|
+
const chunk = Buffer.alloc(1024 * 1024);
|
|
16
|
+
let bytesRead;
|
|
17
|
+
while ((bytesRead = fs.readSync(fd, chunk, 0, chunk.length, null)) > 0) {
|
|
18
|
+
hash.update(chunk.subarray(0, bytesRead));
|
|
19
|
+
}
|
|
20
|
+
} finally {
|
|
21
|
+
fs.closeSync(fd);
|
|
22
|
+
}
|
|
23
|
+
return hash.digest('hex');
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
/**
|
|
27
|
+
* Walk `webDir` and collect relativePath -> sha256 hex. Skips the manifest output file,
|
|
28
|
+
* symlinks (does not follow), and non-regular files.
|
|
29
|
+
*/
|
|
30
|
+
export function collectWebBundleHashes(webDir, { outputFileAbs = null } = {}) {
|
|
31
|
+
const base = fs.realpathSync(webDir);
|
|
32
|
+
const resolvedOutput = outputFileAbs ? resolveRealPath(outputFileAbs) : null;
|
|
33
|
+
const skipNames = new Set([BUILTIN_HASHES_FILE_NAME]);
|
|
34
|
+
const files = {};
|
|
35
|
+
|
|
36
|
+
function recordRegularFile(resolvedFull) {
|
|
37
|
+
if (resolvedOutput && resolvedFull === resolvedOutput) {
|
|
38
|
+
return;
|
|
39
|
+
}
|
|
40
|
+
if (!pathContains(base, resolvedFull)) {
|
|
41
|
+
return;
|
|
42
|
+
}
|
|
43
|
+
const rel = path.relative(base, resolvedFull).split(path.sep).join('/');
|
|
44
|
+
const stat = fs.statSync(resolvedFull);
|
|
45
|
+
files[rel] = { sha256: sha256File(resolvedFull), size: stat.size };
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
function visitName(name, realDir, ancestors) {
|
|
49
|
+
if (skipNames.has(name)) {
|
|
50
|
+
return;
|
|
51
|
+
}
|
|
52
|
+
const full = path.join(realDir, name);
|
|
53
|
+
let stat;
|
|
54
|
+
try {
|
|
55
|
+
stat = fs.lstatSync(full);
|
|
56
|
+
} catch {
|
|
57
|
+
return;
|
|
58
|
+
}
|
|
59
|
+
if (stat.isSymbolicLink()) {
|
|
60
|
+
return;
|
|
61
|
+
}
|
|
62
|
+
if (stat.isDirectory()) {
|
|
63
|
+
walk(full, ancestors);
|
|
64
|
+
return;
|
|
65
|
+
}
|
|
66
|
+
if (!stat.isFile()) {
|
|
67
|
+
return;
|
|
68
|
+
}
|
|
69
|
+
recordRegularFile(fs.realpathSync(full));
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
function walk(dir, ancestors = new Set()) {
|
|
73
|
+
const realDir = fs.realpathSync(dir);
|
|
74
|
+
if (ancestors.has(realDir)) {
|
|
75
|
+
return;
|
|
76
|
+
}
|
|
77
|
+
ancestors.add(realDir);
|
|
78
|
+
try {
|
|
79
|
+
for (const name of fs.readdirSync(realDir)) {
|
|
80
|
+
visitName(name, realDir, ancestors);
|
|
81
|
+
}
|
|
82
|
+
} finally {
|
|
83
|
+
ancestors.delete(realDir);
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
walk(base);
|
|
88
|
+
return files;
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
export function pathContains(parent, descendant) {
|
|
92
|
+
const relative = path.relative(parent, descendant);
|
|
93
|
+
if (relative === '') {
|
|
94
|
+
return true;
|
|
95
|
+
}
|
|
96
|
+
if (path.isAbsolute(relative) || relative === '..' || relative.startsWith(`..${path.sep}`)) {
|
|
97
|
+
return false;
|
|
98
|
+
}
|
|
99
|
+
return true;
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
export function resolveIosPublicDir(rootDir, extConfig = {}) {
|
|
103
|
+
const platformDir = extConfig.ios?.path ?? 'ios';
|
|
104
|
+
const platformDirAbs = path.resolve(rootDir, platformDir);
|
|
105
|
+
const nativeProjectDirAbs = path.join(platformDirAbs, 'App');
|
|
106
|
+
const nativeTargetDirAbs = path.join(platformDirAbs, 'App', 'App');
|
|
107
|
+
const pbxprojPath = path.join(platformDirAbs, 'App', 'App.xcodeproj', 'project.pbxproj');
|
|
108
|
+
try {
|
|
109
|
+
const pbxproj = fs.readFileSync(pbxprojPath, 'utf8');
|
|
110
|
+
const re = /path\s=\spublic[\s\S]+?sourceTree\s=\s([^;]+)/;
|
|
111
|
+
const match = pbxproj.match(re);
|
|
112
|
+
if (match?.[1] === 'SOURCE_ROOT') {
|
|
113
|
+
return path.join(nativeProjectDirAbs, 'public');
|
|
114
|
+
}
|
|
115
|
+
} catch {
|
|
116
|
+
// ignore
|
|
117
|
+
}
|
|
118
|
+
return path.join(nativeTargetDirAbs, 'public');
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
export function resolveAndroidPublicDir(rootDir, extConfig = {}) {
|
|
122
|
+
const platformDir = extConfig.android?.path ?? 'android';
|
|
123
|
+
const platformDirAbs = path.resolve(rootDir, platformDir);
|
|
124
|
+
return path.join(platformDirAbs, 'app', 'src', 'main', 'assets', 'public');
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
export function resolveNativePublicDir(rootDir, platformName, extConfig = {}) {
|
|
128
|
+
if (platformName === 'android') {
|
|
129
|
+
return resolveAndroidPublicDir(rootDir, extConfig);
|
|
130
|
+
}
|
|
131
|
+
if (platformName === 'ios') {
|
|
132
|
+
return resolveIosPublicDir(rootDir, extConfig);
|
|
133
|
+
}
|
|
134
|
+
return null;
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
export function writeBuiltinHashesManifest(outputFile, files) {
|
|
138
|
+
const payload = `${JSON.stringify({ files }, null, 2)}\n`;
|
|
139
|
+
fs.mkdirSync(path.dirname(outputFile), { recursive: true });
|
|
140
|
+
const tmpFile = `${outputFile}.${process.pid}.tmp`;
|
|
141
|
+
try {
|
|
142
|
+
fs.writeFileSync(tmpFile, payload, 'utf8');
|
|
143
|
+
fs.renameSync(tmpFile, outputFile);
|
|
144
|
+
} catch (err) {
|
|
145
|
+
fs.rmSync(tmpFile, { force: true });
|
|
146
|
+
throw err;
|
|
147
|
+
}
|
|
148
|
+
}
|
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
/**
|
|
3
|
+
* Capacitor plugin hook: runs on capacitor:copy:after (covers standalone copy and sync, which invokes copy).
|
|
4
|
+
* Writes ota-builtin-hashes.json into the native web public folder for the active platform.
|
|
5
|
+
*/
|
|
6
|
+
import fs from 'node:fs';
|
|
7
|
+
import path from 'node:path';
|
|
8
|
+
import process from 'node:process';
|
|
9
|
+
import {
|
|
10
|
+
BUILTIN_HASHES_FILE_NAME,
|
|
11
|
+
collectWebBundleHashes,
|
|
12
|
+
resolveNativePublicDir,
|
|
13
|
+
writeBuiltinHashesManifest,
|
|
14
|
+
} from './builtin-hashes-lib.mjs';
|
|
15
|
+
|
|
16
|
+
function readExtConfig() {
|
|
17
|
+
const raw = process.env.CAPACITOR_CONFIG;
|
|
18
|
+
if (!raw) {
|
|
19
|
+
return {};
|
|
20
|
+
}
|
|
21
|
+
try {
|
|
22
|
+
return JSON.parse(raw);
|
|
23
|
+
} catch {
|
|
24
|
+
return {};
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
function main() {
|
|
29
|
+
try {
|
|
30
|
+
const platformName = process.env.CAPACITOR_PLATFORM_NAME;
|
|
31
|
+
if (!platformName || platformName === 'web') {
|
|
32
|
+
return;
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
const rootDir = process.env.CAPACITOR_ROOT_DIR;
|
|
36
|
+
if (!rootDir) {
|
|
37
|
+
return;
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
const extConfig = readExtConfig();
|
|
41
|
+
const nativePublicDir = resolveNativePublicDir(rootDir, platformName, extConfig);
|
|
42
|
+
if (!nativePublicDir) {
|
|
43
|
+
return;
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
if (!fs.existsSync(nativePublicDir)) {
|
|
47
|
+
return;
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
const outputFile = path.join(nativePublicDir, BUILTIN_HASHES_FILE_NAME);
|
|
51
|
+
fs.rmSync(outputFile, { force: true });
|
|
52
|
+
try {
|
|
53
|
+
const files = collectWebBundleHashes(nativePublicDir, { outputFileAbs: outputFile });
|
|
54
|
+
writeBuiltinHashesManifest(outputFile, files);
|
|
55
|
+
} catch (err) {
|
|
56
|
+
const message = err instanceof Error ? err.message : String(err);
|
|
57
|
+
console.warn(`[capgo] ${BUILTIN_HASHES_FILE_NAME} not generated: ${message}`);
|
|
58
|
+
}
|
|
59
|
+
} catch (err) {
|
|
60
|
+
const message = err instanceof Error ? err.message : String(err);
|
|
61
|
+
console.warn(`[capgo] ${BUILTIN_HASHES_FILE_NAME} hook failed: ${message}`);
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
main();
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import fs from 'node:fs';
|
|
2
|
+
import path from 'node:path';
|
|
3
|
+
|
|
4
|
+
/** Resolve symlinks; walk up to the nearest existing ancestor when target does not exist yet. */
|
|
5
|
+
export function resolveRealPath(target) {
|
|
6
|
+
const normalized = path.resolve(target);
|
|
7
|
+
const suffix = [];
|
|
8
|
+
let cursor = normalized;
|
|
9
|
+
while (true) {
|
|
10
|
+
try {
|
|
11
|
+
const real = fs.realpathSync(cursor);
|
|
12
|
+
return suffix.length === 0 ? real : path.join(real, ...suffix);
|
|
13
|
+
} catch (err) {
|
|
14
|
+
if (err?.code !== 'ENOENT') {
|
|
15
|
+
throw err;
|
|
16
|
+
}
|
|
17
|
+
suffix.unshift(path.basename(cursor));
|
|
18
|
+
const parent = path.dirname(cursor);
|
|
19
|
+
if (parent === cursor) {
|
|
20
|
+
throw err;
|
|
21
|
+
}
|
|
22
|
+
cursor = parent;
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
}
|