@capgo/cordova-updater 8.1.4 → 8.2.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/dist/esm/definitions.d.ts +116 -86
- package/dist/esm/definitions.js +2 -2
- package/dist/esm/definitions.js.map +1 -1
- package/dist/esm/exec.js +11 -1
- package/dist/esm/exec.js.map +1 -1
- package/dist/esm/history.js +7 -7
- package/dist/esm/history.js.map +1 -1
- package/dist/plugin.cjs.js +13 -3
- package/dist/plugin.cjs.js.map +1 -1
- package/dist/plugin.js +13 -3
- package/dist/plugin.js.map +1 -1
- package/package.json +5 -3
- package/plugin.xml +9 -9
- package/src/android/CordovaUpdaterPlugin.java +173 -5
- package/src/android/app/capgo/cordova/updater/CapgoUpdater.java +313 -55
- package/src/android/app/capgo/cordova/updater/CryptoCipher.java +51 -18
- package/src/android/app/capgo/cordova/updater/DelayUpdateUtils.java +0 -1
- package/src/android/app/capgo/cordova/updater/DownloadService.java +402 -89
- package/src/android/app/capgo/cordova/updater/Version.java +312 -0
- package/src/android/capgo-cordova-updater.gradle +3 -5
- package/src/android/test/app/capgo/cordova/updater/BackgroundDownloadSettlementTest.java +29 -0
- package/src/android/test/app/capgo/cordova/updater/CapacitorUpdaterUnitTest.java.skip +2 -12
- package/src/android/test/app/capgo/cordova/updater/DelayUpdateUtilsTest.java +0 -1
- package/src/android/test/app/capgo/cordova/updater/RsaContractTest.java +137 -0
- package/src/android/test/app/capgo/cordova/updater/SecurityHardeningTest.java +197 -0
- package/src/android/test/app/capgo/cordova/updater/SessionKeyRequiredTest.java +344 -0
- package/src/ios/CapgoSemanticVersion.swift +181 -0
- package/src/ios/CapgoUpdater.swift +427 -114
- package/src/ios/CordovaUpdaterPlugin.swift +171 -40
- package/src/ios/CryptoCipher.swift +41 -38
- package/src/ios/DelayUpdateUtils.swift +19 -45
- package/src/ios/Logger.swift +81 -5
- package/src/ios/RedirectPolicyDelegate.swift +53 -0
- package/src/ios/WebViewStatsReporter.swift +5 -0
- package/src/ios/ZipArchiveReader.swift +263 -0
- package/src/ios/ZipCentralDirectory.swift +283 -0
|
@@ -0,0 +1,181 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* This Source Code Form is subject to the terms of the Mozilla Public
|
|
3
|
+
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
4
|
+
* file, You can obtain one at https://mozilla.org/MPL/2.0/.
|
|
5
|
+
*/
|
|
6
|
+
|
|
7
|
+
import Foundation
|
|
8
|
+
|
|
9
|
+
/// Minimal version value used for native version comparisons.
|
|
10
|
+
///
|
|
11
|
+
/// Parsing and ordering intentionally mirror the lenient parser of the `Version` package
|
|
12
|
+
/// (mrackwitz/Version 0.8.0) that this type replaces, so existing comparisons keep the same results:
|
|
13
|
+
/// - `MAJOR[.MINOR[.PATCH]][-PRERELEASE][+BUILD]`, numeric components are ASCII digits (leading zeros allowed).
|
|
14
|
+
/// - Missing minor/patch compare as `0`.
|
|
15
|
+
/// - A version with a prerelease is lower than the same version without one.
|
|
16
|
+
/// - Prerelease identifiers are compared dot by dot: numerically when both are digits, lexically otherwise.
|
|
17
|
+
/// - Build metadata is ignored for equality and ordering.
|
|
18
|
+
public struct CapgoSemanticVersion: Comparable, Hashable, CustomStringConvertible {
|
|
19
|
+
public enum ParseError: Error {
|
|
20
|
+
case invalidComponents
|
|
21
|
+
case invalidMajorComponent
|
|
22
|
+
case invalidMinorComponent
|
|
23
|
+
case invalidPatchComponent
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
public let major: Int
|
|
27
|
+
public let minor: Int?
|
|
28
|
+
public let patch: Int?
|
|
29
|
+
public let prerelease: String?
|
|
30
|
+
public let build: String?
|
|
31
|
+
|
|
32
|
+
public var canonicalMinor: Int { minor ?? 0 }
|
|
33
|
+
public var canonicalPatch: Int { patch ?? 0 }
|
|
34
|
+
|
|
35
|
+
// Same pattern as the lenient `Version` parser (including its build group quirk: no dots in build metadata).
|
|
36
|
+
private static let versionPattern =
|
|
37
|
+
"\\A([0-9]+)(?:\\.([0-9]+))?(?:\\.([0-9]+))?(?:-([0-9A-Za-z-.]+))?(?:\\+([0-9A-Za-z-]+))??\\z"
|
|
38
|
+
private static let versionRegex = try? NSRegularExpression(pattern: versionPattern)
|
|
39
|
+
|
|
40
|
+
public init(major: Int, minor: Int? = nil, patch: Int? = nil, prerelease: String? = nil, build: String? = nil) {
|
|
41
|
+
self.major = max(0, major)
|
|
42
|
+
self.minor = minor.map { max(0, $0) }
|
|
43
|
+
self.patch = patch.map { max(0, $0) }
|
|
44
|
+
self.prerelease = prerelease
|
|
45
|
+
self.build = build
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
public init(_ string: String) throws {
|
|
49
|
+
guard let regex = Self.versionRegex else {
|
|
50
|
+
throw ParseError.invalidComponents
|
|
51
|
+
}
|
|
52
|
+
let nsString = string as NSString
|
|
53
|
+
guard let match = regex.firstMatch(in: string, options: [], range: NSRange(location: 0, length: nsString.length)),
|
|
54
|
+
match.numberOfRanges == 6 else {
|
|
55
|
+
throw ParseError.invalidComponents
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
func group(_ index: Int) -> String? {
|
|
59
|
+
let range = match.range(at: index)
|
|
60
|
+
return range.location == NSNotFound ? nil : nsString.substring(with: range)
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
guard let major = group(1).flatMap({ Int($0) }) else {
|
|
64
|
+
throw ParseError.invalidMajorComponent
|
|
65
|
+
}
|
|
66
|
+
let minorComponent = group(2)
|
|
67
|
+
let minor = minorComponent.flatMap { Int($0) }
|
|
68
|
+
if minorComponent != nil && minor == nil {
|
|
69
|
+
throw ParseError.invalidMinorComponent
|
|
70
|
+
}
|
|
71
|
+
let patchComponent = group(3)
|
|
72
|
+
let patch = patchComponent.flatMap { Int($0) }
|
|
73
|
+
if patchComponent != nil && patch == nil {
|
|
74
|
+
throw ParseError.invalidPatchComponent
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
self.major = major
|
|
78
|
+
self.minor = minor
|
|
79
|
+
self.patch = patch
|
|
80
|
+
self.prerelease = group(4)
|
|
81
|
+
self.build = group(5)
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
public var description: String {
|
|
85
|
+
var result = "\(major)"
|
|
86
|
+
if let minor {
|
|
87
|
+
result += ".\(minor)"
|
|
88
|
+
}
|
|
89
|
+
if let patch {
|
|
90
|
+
result += ".\(patch)"
|
|
91
|
+
}
|
|
92
|
+
if let prerelease {
|
|
93
|
+
result += "-\(prerelease)"
|
|
94
|
+
}
|
|
95
|
+
if let build {
|
|
96
|
+
result += "+\(build)"
|
|
97
|
+
}
|
|
98
|
+
return result
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
public static func == (lhs: CapgoSemanticVersion, rhs: CapgoSemanticVersion) -> Bool {
|
|
102
|
+
return lhs.major == rhs.major
|
|
103
|
+
&& lhs.canonicalMinor == rhs.canonicalMinor
|
|
104
|
+
&& lhs.canonicalPatch == rhs.canonicalPatch
|
|
105
|
+
&& lhs.prerelease == rhs.prerelease
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
public func hash(into hasher: inout Hasher) {
|
|
109
|
+
hasher.combine(major)
|
|
110
|
+
hasher.combine(canonicalMinor)
|
|
111
|
+
hasher.combine(canonicalPatch)
|
|
112
|
+
hasher.combine(prerelease)
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
public static func < (lhs: CapgoSemanticVersion, rhs: CapgoSemanticVersion) -> Bool {
|
|
116
|
+
if lhs.major != rhs.major {
|
|
117
|
+
return lhs.major < rhs.major
|
|
118
|
+
}
|
|
119
|
+
if lhs.canonicalMinor != rhs.canonicalMinor {
|
|
120
|
+
return lhs.canonicalMinor < rhs.canonicalMinor
|
|
121
|
+
}
|
|
122
|
+
if lhs.canonicalPatch != rhs.canonicalPatch {
|
|
123
|
+
return lhs.canonicalPatch < rhs.canonicalPatch
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
switch (lhs.prerelease, rhs.prerelease) {
|
|
127
|
+
case (.some, .none):
|
|
128
|
+
return true
|
|
129
|
+
case (.none, .some), (.none, .none):
|
|
130
|
+
return false
|
|
131
|
+
case let (.some(lpre), .some(rpre)):
|
|
132
|
+
return comparePrerelease(lpre, rpre) == .orderedAscending
|
|
133
|
+
}
|
|
134
|
+
}
|
|
135
|
+
|
|
136
|
+
private static func isNumericIdentifier(_ value: String) -> Bool {
|
|
137
|
+
return !value.isEmpty && value.utf8.allSatisfy { $0 >= 0x30 && $0 <= 0x39 }
|
|
138
|
+
}
|
|
139
|
+
|
|
140
|
+
private static func compareNumericIdentifiers(_ left: String, _ right: String) -> ComparisonResult {
|
|
141
|
+
if left.count != right.count {
|
|
142
|
+
return left.count < right.count ? .orderedAscending : .orderedDescending
|
|
143
|
+
}
|
|
144
|
+
if left == right {
|
|
145
|
+
return .orderedSame
|
|
146
|
+
}
|
|
147
|
+
return left < right ? .orderedAscending : .orderedDescending
|
|
148
|
+
}
|
|
149
|
+
|
|
150
|
+
private static func comparePrerelease(_ lhs: String, _ rhs: String) -> ComparisonResult {
|
|
151
|
+
let lhsComponents = lhs.components(separatedBy: ".")
|
|
152
|
+
let rhsComponents = rhs.components(separatedBy: ".")
|
|
153
|
+
let count = max(lhsComponents.count, rhsComponents.count)
|
|
154
|
+
for index in 0..<count {
|
|
155
|
+
let left = index < lhsComponents.count ? lhsComponents[index] : nil
|
|
156
|
+
let right = index < rhsComponents.count ? rhsComponents[index] : nil
|
|
157
|
+
switch (left, right) {
|
|
158
|
+
case (nil, nil):
|
|
159
|
+
continue
|
|
160
|
+
case (nil, _):
|
|
161
|
+
return .orderedAscending
|
|
162
|
+
case (_, nil):
|
|
163
|
+
return .orderedDescending
|
|
164
|
+
case let (l?, r?) where l == r:
|
|
165
|
+
continue
|
|
166
|
+
case let (l?, r?) where isNumericIdentifier(l) && isNumericIdentifier(r):
|
|
167
|
+
let cmp = compareNumericIdentifiers(l, r)
|
|
168
|
+
if cmp != .orderedSame {
|
|
169
|
+
return cmp
|
|
170
|
+
}
|
|
171
|
+
case let (l?, r?) where isNumericIdentifier(l) && !isNumericIdentifier(r):
|
|
172
|
+
return .orderedAscending
|
|
173
|
+
case let (l?, r?) where !isNumericIdentifier(l) && isNumericIdentifier(r):
|
|
174
|
+
return .orderedDescending
|
|
175
|
+
case let (l?, r?):
|
|
176
|
+
return l < r ? .orderedAscending : .orderedDescending
|
|
177
|
+
}
|
|
178
|
+
}
|
|
179
|
+
return .orderedSame
|
|
180
|
+
}
|
|
181
|
+
}
|