@gfean/react-native-bundle-drop 0.3.9 → 0.4.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/BundleDrop.podspec +9 -2
- package/README.md +19 -0
- package/android/build.gradle +25 -4
- package/android/src/main/cpp/CMakeLists.txt +33 -0
- package/android/src/main/cpp/bundle_drop_xdelta_jni.c +55 -0
- package/android/src/main/java/com/bundledrop/BundleDropBundleVerifier.kt +73 -0
- package/android/src/main/java/com/bundledrop/BundleDropFileOps.kt +193 -8
- package/android/src/main/java/com/bundledrop/BundleDropModule.kt +60 -7
- package/android/src/main/java/com/bundledrop/BundleDropOtaPrefs.kt +2 -12
- package/android/src/main/java/com/bundledrop/BundleDropOtaResolver.kt +208 -3
- package/android/src/main/java/com/bundledrop/BundleDropXdeltaNative.kt +57 -0
- package/ios/BundleDropBridge.m +27 -0
- package/ios/BundleDropBundleVerifier.swift +106 -0
- package/ios/BundleDropFileOps.swift +149 -0
- package/ios/BundleDropModule.swift +100 -11
- package/ios/BundleDropOtaResolver.swift +149 -3
- package/ios/BundleDropZipExtractor.m +75 -3
- package/lib/CLI/cli.js +1 -8
- package/lib/CLI/scripts/upload-cli.d.ts +0 -1
- package/lib/CLI/scripts/upload-cli.js +26 -20
- package/lib/api/client.d.ts +11 -1
- package/lib/api/client.js +84 -17
- package/lib/api/clientApi.d.ts +2 -1
- package/lib/api/clientApi.js +9 -0
- package/lib/api/types.d.ts +65 -13
- package/lib/bundleInfo.d.ts +2 -0
- package/lib/fs/bundlePointer.d.ts +2 -1
- package/lib/fs/bundlePointer.js +34 -6
- package/lib/fs/fsUtils.js +4 -1
- package/lib/injectImageResolver.js +82 -75
- package/lib/install/bundleInstallShared.d.ts +8 -0
- package/lib/install/bundleInstallShared.js +97 -0
- package/lib/install/bundleVerification.d.ts +5 -0
- package/lib/install/bundleVerification.js +34 -0
- package/lib/install/installFromZip.d.ts +2 -5
- package/lib/install/installFromZip.js +33 -68
- package/lib/loadConfig.js +12 -1
- package/lib/manager/downloadAndInstall.d.ts +9 -0
- package/lib/manager/downloadAndInstall.js +84 -24
- package/lib/manager/reporting.js +26 -2
- package/lib/manager/rollbackState.js +21 -12
- package/lib/manager/updateCheck.js +89 -11
- package/lib/manager/updateState.js +3 -9
- package/lib/manifest/bundleManifest.d.ts +33 -0
- package/lib/manifest/bundleManifest.js +298 -0
- package/lib/native/bundleDropNative.js +1 -2
- package/lib/native/fs.d.ts +14 -0
- package/lib/native/fs.js +35 -0
- package/lib/patch-engine/installFromPatchSet.d.ts +16 -0
- package/lib/patch-engine/installFromPatchSet.js +143 -0
- package/lib/patch-engine/patchOperations.d.ts +33 -0
- package/lib/patch-engine/patchOperations.js +77 -0
- package/lib/patch-engine/patchTransport.d.ts +18 -0
- package/lib/patch-engine/patchTransport.js +81 -0
- package/lib/patchAlgorithms.d.ts +4 -0
- package/lib/patchAlgorithms.js +9 -0
- package/lib/runtime/service.js +43 -9
- package/lib/scripts/bundle.d.ts +3 -0
- package/lib/scripts/bundle.js +184 -41
- package/lib/scripts/download-bundle.js +18 -7
- package/lib/scripts/upload-bundle.js +25 -28
- package/package.json +43 -5
- package/third_party/xdelta/NOTICE +7 -0
- package/third_party/xdelta/PROVENANCE.md +10 -0
- package/third_party/xdelta/bundle_drop_xdelta.c +252 -0
- package/third_party/xdelta/bundle_drop_xdelta.h +26 -0
- package/third_party/xdelta/xdelta3/LICENSE +176 -0
- package/third_party/xdelta/xdelta3/config.h +34 -0
- package/third_party/xdelta/xdelta3/xdelta3-cfgs.h +171 -0
- package/third_party/xdelta/xdelta3/xdelta3-decode.h +1219 -0
- package/third_party/xdelta/xdelta3/xdelta3-hash.h +159 -0
- package/third_party/xdelta/xdelta3/xdelta3-internal.h +385 -0
- package/third_party/xdelta/xdelta3/xdelta3-list.h +127 -0
- package/third_party/xdelta/xdelta3/xdelta3.c +4819 -0
- package/third_party/xdelta/xdelta3/xdelta3.h +1476 -0
- package/lib/CLI/scripts/init-native-config.d.ts +0 -18
- package/lib/CLI/scripts/init-native-config.js +0 -539
- package/lib/assetExtensions.d.ts +0 -4
- package/lib/assetExtensions.js +0 -35
|
@@ -6,6 +6,22 @@ final class BundleDropModule: NSObject {
|
|
|
6
6
|
|
|
7
7
|
private static var isReloading = false
|
|
8
8
|
private static let fm = FileManager.default
|
|
9
|
+
private static let fileOpsQueue = DispatchQueue(label: "com.bundledrop.file-ops", qos: .userInitiated)
|
|
10
|
+
|
|
11
|
+
private func runFileOperation(
|
|
12
|
+
errorCode: String,
|
|
13
|
+
resolve: @escaping RCTPromiseResolveBlock,
|
|
14
|
+
reject: @escaping RCTPromiseRejectBlock,
|
|
15
|
+
operation: @escaping () throws -> Any?
|
|
16
|
+
) {
|
|
17
|
+
Self.fileOpsQueue.async {
|
|
18
|
+
do {
|
|
19
|
+
resolve(try operation())
|
|
20
|
+
} catch {
|
|
21
|
+
reject(errorCode, error.localizedDescription, error)
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
}
|
|
9
25
|
|
|
10
26
|
// MARK: - OTA bundle path
|
|
11
27
|
|
|
@@ -193,14 +209,91 @@ final class BundleDropModule: NSObject {
|
|
|
193
209
|
resolve: @escaping RCTPromiseResolveBlock,
|
|
194
210
|
reject: @escaping RCTPromiseRejectBlock
|
|
195
211
|
) {
|
|
196
|
-
|
|
212
|
+
runFileOperation(errorCode: "ERR_MOVE", resolve: resolve, reject: reject) {
|
|
197
213
|
try BundleDropFileOps.moveFile(srcPath: src, destPath: dest)
|
|
198
|
-
|
|
214
|
+
return nil
|
|
215
|
+
}
|
|
216
|
+
}
|
|
217
|
+
|
|
218
|
+
@objc
|
|
219
|
+
func fsCopyFile(
|
|
220
|
+
_ src: String,
|
|
221
|
+
dest: String,
|
|
222
|
+
resolve: @escaping RCTPromiseResolveBlock,
|
|
223
|
+
reject: @escaping RCTPromiseRejectBlock
|
|
224
|
+
) {
|
|
225
|
+
runFileOperation(errorCode: "ERR_COPY", resolve: resolve, reject: reject) {
|
|
226
|
+
try BundleDropFileOps.copyFile(srcPath: src, destPath: dest)
|
|
227
|
+
return nil
|
|
228
|
+
}
|
|
229
|
+
}
|
|
230
|
+
|
|
231
|
+
@objc
|
|
232
|
+
func fsSha256File(
|
|
233
|
+
_ path: String,
|
|
234
|
+
resolve: @escaping RCTPromiseResolveBlock,
|
|
235
|
+
reject: @escaping RCTPromiseRejectBlock
|
|
236
|
+
) {
|
|
237
|
+
runFileOperation(errorCode: "ERR_SHA256", resolve: resolve, reject: reject) {
|
|
238
|
+
try BundleDropFileOps.sha256File(path)
|
|
239
|
+
}
|
|
240
|
+
}
|
|
241
|
+
|
|
242
|
+
@objc
|
|
243
|
+
func fsFileSize(
|
|
244
|
+
_ path: String,
|
|
245
|
+
resolve: @escaping RCTPromiseResolveBlock,
|
|
246
|
+
reject: @escaping RCTPromiseRejectBlock
|
|
247
|
+
) {
|
|
248
|
+
do {
|
|
249
|
+
resolve(try BundleDropFileOps.fileSize(path))
|
|
199
250
|
} catch {
|
|
200
|
-
reject("
|
|
251
|
+
reject("ERR_FILE_SIZE", error.localizedDescription, error)
|
|
201
252
|
}
|
|
202
253
|
}
|
|
203
254
|
|
|
255
|
+
@objc
|
|
256
|
+
func fsApplyXdelta(
|
|
257
|
+
_ basePath: String,
|
|
258
|
+
patchPath: String,
|
|
259
|
+
outputPath: String,
|
|
260
|
+
resolve: @escaping RCTPromiseResolveBlock,
|
|
261
|
+
reject: @escaping RCTPromiseRejectBlock
|
|
262
|
+
) {
|
|
263
|
+
runFileOperation(errorCode: "ERR_XDELTA", resolve: resolve, reject: reject) {
|
|
264
|
+
try BundleDropFileOps.applyXdelta(
|
|
265
|
+
basePath: basePath,
|
|
266
|
+
patchPath: patchPath,
|
|
267
|
+
outputPath: outputPath
|
|
268
|
+
)
|
|
269
|
+
return nil
|
|
270
|
+
}
|
|
271
|
+
}
|
|
272
|
+
|
|
273
|
+
@objc
|
|
274
|
+
func fsVerifyBundleFiles(
|
|
275
|
+
_ bundleDir: String,
|
|
276
|
+
manifestPath: String,
|
|
277
|
+
resolve: @escaping RCTPromiseResolveBlock,
|
|
278
|
+
reject: @escaping RCTPromiseRejectBlock
|
|
279
|
+
) {
|
|
280
|
+
runFileOperation(errorCode: "ERR_VERIFY_BUNDLE", resolve: resolve, reject: reject) {
|
|
281
|
+
try BundleDropBundleVerifier.verifyBundleFiles(
|
|
282
|
+
bundleDir: URL(fileURLWithPath: bundleDir),
|
|
283
|
+
manifestURL: URL(fileURLWithPath: manifestPath)
|
|
284
|
+
)
|
|
285
|
+
return ["verified": true]
|
|
286
|
+
}
|
|
287
|
+
}
|
|
288
|
+
|
|
289
|
+
@objc
|
|
290
|
+
func fsSupportsXdelta(
|
|
291
|
+
_ resolve: @escaping RCTPromiseResolveBlock,
|
|
292
|
+
reject: @escaping RCTPromiseRejectBlock
|
|
293
|
+
) {
|
|
294
|
+
resolve(BundleDropFileOps.supportsXdelta())
|
|
295
|
+
}
|
|
296
|
+
|
|
204
297
|
@objc
|
|
205
298
|
func fsUnzip(
|
|
206
299
|
_ zipPath: String,
|
|
@@ -208,14 +301,10 @@ final class BundleDropModule: NSObject {
|
|
|
208
301
|
resolve: @escaping RCTPromiseResolveBlock,
|
|
209
302
|
reject: @escaping RCTPromiseRejectBlock
|
|
210
303
|
) {
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
resolve(filenames ?? [])
|
|
216
|
-
} catch {
|
|
217
|
-
reject("ERR_UNZIP", error.localizedDescription, error)
|
|
218
|
-
}
|
|
304
|
+
runFileOperation(errorCode: "ERR_UNZIP", resolve: resolve, reject: reject) {
|
|
305
|
+
let filenames = try BundleDropZipExtractor.extractZip(atPath: zipPath,
|
|
306
|
+
toDirectory: destPath)
|
|
307
|
+
return filenames ?? []
|
|
219
308
|
}
|
|
220
309
|
}
|
|
221
310
|
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import Foundation
|
|
2
|
+
import CryptoKit
|
|
2
3
|
|
|
3
4
|
struct BundleDropOtaResolveResult {
|
|
4
5
|
let bundleURL: URL?
|
|
@@ -17,17 +18,162 @@ enum BundleDropOtaResolver {
|
|
|
17
18
|
do {
|
|
18
19
|
let data = try Data(contentsOf: current)
|
|
19
20
|
let obj = try JSONSerialization.jsonObject(with: data) as? [String: Any]
|
|
20
|
-
guard let
|
|
21
|
+
guard let hash = obj?["hash"] as? String,
|
|
22
|
+
hash.range(of: "^[a-f0-9]{64}$", options: .regularExpression) != nil else {
|
|
21
23
|
return nil
|
|
22
24
|
}
|
|
23
25
|
|
|
24
|
-
let
|
|
25
|
-
|
|
26
|
+
let expectedURL = bundleDropRoot
|
|
27
|
+
.appendingPathComponent("bundles")
|
|
28
|
+
.appendingPathComponent(hash)
|
|
29
|
+
.appendingPathComponent("main.jsbundle")
|
|
30
|
+
let manifestURL = expectedURL
|
|
31
|
+
.deletingLastPathComponent()
|
|
32
|
+
.appendingPathComponent("bundle-manifest.json")
|
|
33
|
+
guard fileManager.fileExists(atPath: manifestURL.path),
|
|
34
|
+
let manifestData = try? Data(contentsOf: manifestURL),
|
|
35
|
+
let manifest = try? JSONSerialization.jsonObject(with: manifestData) as? [String: Any],
|
|
36
|
+
(manifest["manifestVersion"] as? NSNumber)?.intValue == 1,
|
|
37
|
+
manifest["bundleHash"] as? String == hash else {
|
|
38
|
+
return nil
|
|
39
|
+
}
|
|
40
|
+
guard verifyBundleDir(
|
|
41
|
+
bundleDir: expectedURL.deletingLastPathComponent(),
|
|
42
|
+
manifest: manifest,
|
|
43
|
+
expectedHash: hash,
|
|
44
|
+
fileManager: fileManager
|
|
45
|
+
) else {
|
|
46
|
+
return nil
|
|
47
|
+
}
|
|
48
|
+
return fileManager.fileExists(atPath: expectedURL.path) ? expectedURL : nil
|
|
26
49
|
} catch {
|
|
27
50
|
return nil
|
|
28
51
|
}
|
|
29
52
|
}
|
|
30
53
|
|
|
54
|
+
private static func verifyBundleDir(
|
|
55
|
+
bundleDir: URL,
|
|
56
|
+
manifest: [String: Any],
|
|
57
|
+
expectedHash: String,
|
|
58
|
+
fileManager: FileManager
|
|
59
|
+
) -> Bool {
|
|
60
|
+
guard let files = manifest["files"] as? [[String: Any]] else { return false }
|
|
61
|
+
guard manifest["platform"] as? String == "ios" else { return false }
|
|
62
|
+
var mainBundleHash: String?
|
|
63
|
+
var jsBundleRoleCount = 0
|
|
64
|
+
var metadataRoleCount = 0
|
|
65
|
+
var metadataPathMatches = false
|
|
66
|
+
var androidImageManifestRoleCount = 0
|
|
67
|
+
|
|
68
|
+
for file in files {
|
|
69
|
+
guard let path = file["path"] as? String,
|
|
70
|
+
let expectedSha = file["sha256"] as? String,
|
|
71
|
+
let role = file["role"] as? String else {
|
|
72
|
+
return false
|
|
73
|
+
}
|
|
74
|
+
guard BundleDropBundleVerifier.isSafeManifestPath(path) else { return false }
|
|
75
|
+
switch role {
|
|
76
|
+
case "jsbundle":
|
|
77
|
+
jsBundleRoleCount += 1
|
|
78
|
+
if path == "main.jsbundle" {
|
|
79
|
+
mainBundleHash = expectedSha
|
|
80
|
+
}
|
|
81
|
+
case "metadata":
|
|
82
|
+
metadataRoleCount += 1
|
|
83
|
+
if path == "metadata-ios.json" {
|
|
84
|
+
metadataPathMatches = true
|
|
85
|
+
}
|
|
86
|
+
case "androidImageManifest":
|
|
87
|
+
androidImageManifestRoleCount += 1
|
|
88
|
+
default:
|
|
89
|
+
break
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
guard let jsBundleHash = manifest["jsBundleHash"] as? String,
|
|
94
|
+
jsBundleRoleCount == 1,
|
|
95
|
+
mainBundleHash == jsBundleHash,
|
|
96
|
+
metadataRoleCount == 1,
|
|
97
|
+
metadataPathMatches,
|
|
98
|
+
androidImageManifestRoleCount == 0,
|
|
99
|
+
calculateBundleHash(files: files) == expectedHash else {
|
|
100
|
+
return false
|
|
101
|
+
}
|
|
102
|
+
guard verifyManifestHash(manifest: manifest, files: files) else {
|
|
103
|
+
return false
|
|
104
|
+
}
|
|
105
|
+
do {
|
|
106
|
+
try BundleDropBundleVerifier.verifyManifestFiles(
|
|
107
|
+
bundleDir: bundleDir,
|
|
108
|
+
files: files,
|
|
109
|
+
fileManager: fileManager
|
|
110
|
+
)
|
|
111
|
+
return true
|
|
112
|
+
} catch {
|
|
113
|
+
return false
|
|
114
|
+
}
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
private static func calculateBundleHash(files: [[String: Any]]) -> String {
|
|
118
|
+
let entries = canonicalFileEntries(files: files)
|
|
119
|
+
let canonical = "{\"files\":[\(entries.joined(separator: ","))],\"manifestVersion\":1}"
|
|
120
|
+
return SHA256.hash(data: Data(canonical.utf8)).map { String(format: "%02x", $0) }.joined()
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
private static func verifyManifestHash(manifest: [String: Any], files: [[String: Any]]) -> Bool {
|
|
124
|
+
guard let manifestHash = manifest["manifestHash"] as? String,
|
|
125
|
+
manifestHash.range(of: "^[a-f0-9]{64}$", options: .regularExpression) != nil else {
|
|
126
|
+
return false
|
|
127
|
+
}
|
|
128
|
+
for field in ["bundleHash", "jsBundleHash", "platform", "runtimeVersion", "version"] {
|
|
129
|
+
guard let value = manifest[field] as? String, !value.isEmpty else { return false }
|
|
130
|
+
}
|
|
131
|
+
let canonical = [
|
|
132
|
+
"\"bundleHash\":\(jsonString(manifest["bundleHash"] as? String ?? ""))",
|
|
133
|
+
"\"files\":[\(canonicalFileEntries(files: files).joined(separator: ","))]",
|
|
134
|
+
"\"jsBundleHash\":\(jsonString(manifest["jsBundleHash"] as? String ?? ""))",
|
|
135
|
+
"\"manifestVersion\":1",
|
|
136
|
+
"\"platform\":\(jsonString(manifest["platform"] as? String ?? ""))",
|
|
137
|
+
"\"runtimeVersion\":\(jsonString(manifest["runtimeVersion"] as? String ?? ""))",
|
|
138
|
+
"\"version\":\(jsonString(manifest["version"] as? String ?? ""))"
|
|
139
|
+
].joined(separator: ",")
|
|
140
|
+
let expectedHash = SHA256.hash(data: Data("{\(canonical)}".utf8)).map { String(format: "%02x", $0) }.joined()
|
|
141
|
+
return expectedHash == manifestHash
|
|
142
|
+
}
|
|
143
|
+
|
|
144
|
+
private static func canonicalFileEntries(files: [[String: Any]]) -> [String] {
|
|
145
|
+
return files.map { file -> (path: String, serialized: String) in
|
|
146
|
+
let path = file["path"] as? String ?? ""
|
|
147
|
+
let executable = (file["executable"] as? Bool) == true ? "\"executable\":true," : ""
|
|
148
|
+
return (
|
|
149
|
+
path,
|
|
150
|
+
"{\(executable)\"path\":\(jsonString(path)),\"role\":\(jsonString(file["role"] as? String ?? "")),\"sha256\":\(jsonString(file["sha256"] as? String ?? "")),\"size\":\((file["size"] as? NSNumber)?.int64Value ?? -1)}"
|
|
151
|
+
)
|
|
152
|
+
}
|
|
153
|
+
.sorted { compareUtf8($0.path, $1.path) < 0 }
|
|
154
|
+
.map(\.serialized)
|
|
155
|
+
}
|
|
156
|
+
|
|
157
|
+
private static func compareUtf8(_ left: String, _ right: String) -> Int {
|
|
158
|
+
let leftBytes = Array(left.utf8)
|
|
159
|
+
let rightBytes = Array(right.utf8)
|
|
160
|
+
let count = min(leftBytes.count, rightBytes.count)
|
|
161
|
+
for index in 0..<count {
|
|
162
|
+
if leftBytes[index] != rightBytes[index] {
|
|
163
|
+
return Int(leftBytes[index]) - Int(rightBytes[index])
|
|
164
|
+
}
|
|
165
|
+
}
|
|
166
|
+
return leftBytes.count - rightBytes.count
|
|
167
|
+
}
|
|
168
|
+
|
|
169
|
+
private static func jsonString(_ value: String) -> String {
|
|
170
|
+
guard let data = try? JSONSerialization.data(withJSONObject: [value]),
|
|
171
|
+
let encoded = String(data: data, encoding: .utf8) else {
|
|
172
|
+
return "\"\""
|
|
173
|
+
}
|
|
174
|
+
return String(encoded.dropFirst().dropLast()).replacingOccurrences(of: "\\/", with: "/")
|
|
175
|
+
}
|
|
176
|
+
|
|
31
177
|
static func clearOtaState(
|
|
32
178
|
bundleDropRoot: URL,
|
|
33
179
|
documentsDirectory: URL,
|
|
@@ -15,6 +15,8 @@ static uint32_t zipRead32(const uint8_t *buf) {
|
|
|
15
15
|
static const NSUInteger kMaxZipFileSize = 256 * 1024 * 1024; // 256 MB
|
|
16
16
|
static const NSUInteger kMaxEntrySize = 128 * 1024 * 1024; // 128 MB per entry
|
|
17
17
|
static const NSUInteger kMaxTotalUncompressed = 512 * 1024 * 1024; // 512 MB total
|
|
18
|
+
static const uint32_t kUnixSymlinkFileType = 0120000;
|
|
19
|
+
static const uint32_t kUnixFileTypeMask = 0170000;
|
|
18
20
|
|
|
19
21
|
+ (BOOL)isPath:(NSString *)path safelyInsideDirectory:(NSString *)dir {
|
|
20
22
|
NSString *resolvedDir = [dir stringByResolvingSymlinksInPath];
|
|
@@ -23,6 +25,57 @@ static const NSUInteger kMaxTotalUncompressed = 512 * 1024 * 1024; // 512 MB tot
|
|
|
23
25
|
return [resolvedPath hasPrefix:prefix];
|
|
24
26
|
}
|
|
25
27
|
|
|
28
|
+
+ (BOOL)isWindowsAbsolutePath:(NSString *)path {
|
|
29
|
+
if (path.length < 3) return NO;
|
|
30
|
+
unichar first = [path characterAtIndex:0];
|
|
31
|
+
unichar second = [path characterAtIndex:1];
|
|
32
|
+
unichar third = [path characterAtIndex:2];
|
|
33
|
+
BOOL hasDriveLetter = (first >= 'A' && first <= 'Z') || (first >= 'a' && first <= 'z');
|
|
34
|
+
return hasDriveLetter && second == ':' && (third == '/' || third == '\\');
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
+ (BOOL)isSymlinkExternalAttributes:(uint32_t)externalAttributes {
|
|
38
|
+
uint32_t unixMode = (externalAttributes >> 16) & 0xffff;
|
|
39
|
+
return (unixMode & kUnixFileTypeMask) == kUnixSymlinkFileType;
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
+ (NSString *)normalizedZipEntryName:(NSString *)name error:(NSError **)error {
|
|
43
|
+
if (name.length == 0 ||
|
|
44
|
+
[name containsString:@"\0"] ||
|
|
45
|
+
[name containsString:@"\\"] ||
|
|
46
|
+
[name hasPrefix:@"/"] ||
|
|
47
|
+
[self isWindowsAbsolutePath:name]) {
|
|
48
|
+
if (error)
|
|
49
|
+
*error = [NSError errorWithDomain:@"BundleDrop" code:9
|
|
50
|
+
userInfo:@{NSLocalizedDescriptionKey:
|
|
51
|
+
[NSString stringWithFormat:@"Unsafe ZIP entry path: %@", name]}];
|
|
52
|
+
return nil;
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
NSString *normalized = [name hasSuffix:@"/"]
|
|
56
|
+
? [name substringToIndex:name.length - 1]
|
|
57
|
+
: name;
|
|
58
|
+
if (normalized.length == 0) {
|
|
59
|
+
if (error)
|
|
60
|
+
*error = [NSError errorWithDomain:@"BundleDrop" code:9
|
|
61
|
+
userInfo:@{NSLocalizedDescriptionKey:
|
|
62
|
+
[NSString stringWithFormat:@"Unsafe ZIP entry path: %@", name]}];
|
|
63
|
+
return nil;
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
NSArray<NSString *> *parts = [normalized componentsSeparatedByString:@"/"];
|
|
67
|
+
for (NSString *part in parts) {
|
|
68
|
+
if (part.length == 0 || [part isEqualToString:@"."] || [part isEqualToString:@".."]) {
|
|
69
|
+
if (error)
|
|
70
|
+
*error = [NSError errorWithDomain:@"BundleDrop" code:9
|
|
71
|
+
userInfo:@{NSLocalizedDescriptionKey:
|
|
72
|
+
[NSString stringWithFormat:@"Unsafe ZIP entry path: %@", name]}];
|
|
73
|
+
return nil;
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
return normalized;
|
|
77
|
+
}
|
|
78
|
+
|
|
26
79
|
+ (NSArray<NSString *> *)extractZipAtPath:(NSString *)zipPath
|
|
27
80
|
toDirectory:(NSString *)destPath
|
|
28
81
|
error:(NSError **)error {
|
|
@@ -83,6 +136,7 @@ static const NSUInteger kMaxTotalUncompressed = 512 * 1024 * 1024; // 512 MB tot
|
|
|
83
136
|
}
|
|
84
137
|
|
|
85
138
|
NSMutableArray<NSString *> *filenames = [NSMutableArray new];
|
|
139
|
+
NSMutableSet<NSString *> *seenEntries = [NSMutableSet new];
|
|
86
140
|
NSUInteger offset = cdOffset;
|
|
87
141
|
NSUInteger totalUncompressed = 0;
|
|
88
142
|
|
|
@@ -96,6 +150,7 @@ static const NSUInteger kMaxTotalUncompressed = 512 * 1024 * 1024; // 512 MB tot
|
|
|
96
150
|
uint16_t nameLen = zipRead16(bytes + offset + 28);
|
|
97
151
|
uint16_t extraLen = zipRead16(bytes + offset + 30);
|
|
98
152
|
uint16_t commentLen = zipRead16(bytes + offset + 32);
|
|
153
|
+
uint32_t externalAttrs = zipRead32(bytes + offset + 38);
|
|
99
154
|
uint32_t localHdrOffset = zipRead32(bytes + offset + 42);
|
|
100
155
|
|
|
101
156
|
if (offset + 46 + nameLen > length) break;
|
|
@@ -106,9 +161,26 @@ static const NSUInteger kMaxTotalUncompressed = 512 * 1024 * 1024; // 512 MB tot
|
|
|
106
161
|
offset += 46 + nameLen + extraLen + commentLen;
|
|
107
162
|
|
|
108
163
|
if (!name) continue;
|
|
164
|
+
NSString *normalizedName = [self normalizedZipEntryName:name error:error];
|
|
165
|
+
if (!normalizedName) return nil;
|
|
166
|
+
if ([self isSymlinkExternalAttributes:externalAttrs]) {
|
|
167
|
+
if (error)
|
|
168
|
+
*error = [NSError errorWithDomain:@"BundleDrop" code:10
|
|
169
|
+
userInfo:@{NSLocalizedDescriptionKey:
|
|
170
|
+
[NSString stringWithFormat:@"Symlink ZIP entries are not allowed: %@", normalizedName]}];
|
|
171
|
+
return nil;
|
|
172
|
+
}
|
|
173
|
+
if ([seenEntries containsObject:normalizedName]) {
|
|
174
|
+
if (error)
|
|
175
|
+
*error = [NSError errorWithDomain:@"BundleDrop" code:11
|
|
176
|
+
userInfo:@{NSLocalizedDescriptionKey:
|
|
177
|
+
[NSString stringWithFormat:@"Duplicate ZIP entry: %@", normalizedName]}];
|
|
178
|
+
return nil;
|
|
179
|
+
}
|
|
180
|
+
[seenEntries addObject:normalizedName];
|
|
109
181
|
|
|
110
182
|
if ([name hasSuffix:@"/"]) {
|
|
111
|
-
NSString *dirPath = [[destPath stringByAppendingPathComponent:
|
|
183
|
+
NSString *dirPath = [[destPath stringByAppendingPathComponent:normalizedName] stringByStandardizingPath];
|
|
112
184
|
if (![self isPath:dirPath safelyInsideDirectory:destPath]) {
|
|
113
185
|
if (error)
|
|
114
186
|
*error = [NSError errorWithDomain:@"BundleDrop" code:6
|
|
@@ -163,7 +235,7 @@ static const NSUInteger kMaxTotalUncompressed = 512 * 1024 * 1024; // 512 MB tot
|
|
|
163
235
|
return nil;
|
|
164
236
|
}
|
|
165
237
|
|
|
166
|
-
NSString *filePath = [[destPath stringByAppendingPathComponent:
|
|
238
|
+
NSString *filePath = [[destPath stringByAppendingPathComponent:normalizedName] stringByStandardizingPath];
|
|
167
239
|
if (![self isPath:filePath safelyInsideDirectory:destPath]) {
|
|
168
240
|
if (error)
|
|
169
241
|
*error = [NSError errorWithDomain:@"BundleDrop" code:6
|
|
@@ -176,7 +248,7 @@ static const NSUInteger kMaxTotalUncompressed = 512 * 1024 * 1024; // 512 MB tot
|
|
|
176
248
|
[fm createDirectoryAtPath:fileDir withIntermediateDirectories:YES attributes:nil error:nil];
|
|
177
249
|
}
|
|
178
250
|
[fileData writeToFile:filePath atomically:YES];
|
|
179
|
-
[filenames addObject:
|
|
251
|
+
[filenames addObject:normalizedName];
|
|
180
252
|
}
|
|
181
253
|
|
|
182
254
|
return filenames;
|
package/lib/CLI/cli.js
CHANGED
|
@@ -111,7 +111,6 @@ ${chalk_1.default.gray('CI/CD →')} ${chalk_1.default.underline.gray(DOCS_CI_CD
|
|
|
111
111
|
.option('--version <version>', 'App version. iOS will fallback to --plist-file; Android can fallback to build.gradle when provided.')
|
|
112
112
|
.option('--buildgradle-path <path>', 'Optional Android build.gradle path to read versionName')
|
|
113
113
|
.option('--channel <name>', 'Target channel name to associate the bundle')
|
|
114
|
-
.option('--runtimeVersion <runtimeVersion>', 'Override runtimeVersion from metadata/config')
|
|
115
114
|
.option('--release-notes <text>', 'Release notes (max 2000 chars)')
|
|
116
115
|
.option('--token <token>', 'Personal Access Token (alternative to `bundle-drop login`)')
|
|
117
116
|
.option('--author <name>', 'Override the author name stored with the bundle')
|
|
@@ -123,7 +122,6 @@ ${chalk_1.default.bold('Examples:')}
|
|
|
123
122
|
${chalk_1.default.gray('bundle-drop upload android --version 1.2.3 --channel General')}
|
|
124
123
|
${chalk_1.default.gray('bundle-drop upload ios --plist-file ios/Info.plist --channel General')}
|
|
125
124
|
${chalk_1.default.gray('bundle-drop upload android --buildgradle-path android/app/build.gradle --channel QA --release-notes "Bug fixes"')}
|
|
126
|
-
${chalk_1.default.gray('bundle-drop upload android --version 1.2.3 --channel General --runtimeVersion 3.0.0')}
|
|
127
125
|
${chalk_1.default.gray('bundle-drop upload android --version 1.2.3 --channel General --token bdp_pat_xxx')}
|
|
128
126
|
${chalk_1.default.gray('bundle-drop upload android --version 1.2.3 --channel General --sourcemap --artifact-dir ./build/bundledrop')}
|
|
129
127
|
|
|
@@ -202,13 +200,8 @@ ${chalk_1.default.gray('CI/CD docs →')} ${chalk_1.default.underline.gray(DOCS_
|
|
|
202
200
|
});
|
|
203
201
|
program
|
|
204
202
|
.command('init-native')
|
|
205
|
-
.option('--legacy', 'Use deterministic regex-based patching (no network)')
|
|
206
203
|
.description('Apply native changes (AppDelegate / MainApplication) automatically')
|
|
207
|
-
.action(async (
|
|
208
|
-
if (options.legacy) {
|
|
209
|
-
require('../CLI/scripts/init-native-config').initNativeConfig();
|
|
210
|
-
return;
|
|
211
|
-
}
|
|
204
|
+
.action(async () => {
|
|
212
205
|
await require('../CLI/scripts/aipowered/init-native-config').initNativeConfigAi();
|
|
213
206
|
});
|
|
214
207
|
program
|
|
@@ -50,6 +50,22 @@ const DOCS_UPLOADING_URL = 'https://bundledrop.app/docs/uploading';
|
|
|
50
50
|
const DOCS_CI_CD_URL = 'https://bundledrop.app/docs/ci-cd';
|
|
51
51
|
const DOCS_RUNTIME_VERSION_URL = 'https://bundledrop.app/docs/runtime-version';
|
|
52
52
|
const getPackageRoot = () => process.env.BUNDLE_DROP_PACKAGE_ROOT_OVERRIDE || path.resolve(__dirname, '..', '..', '..');
|
|
53
|
+
const readManifestRuntimeVersion = (manifestPath) => {
|
|
54
|
+
let manifest;
|
|
55
|
+
try {
|
|
56
|
+
manifest = JSON.parse(fs.readFileSync(manifestPath, 'utf-8'));
|
|
57
|
+
}
|
|
58
|
+
catch (error) {
|
|
59
|
+
throw new Error(`bundle-manifest.json is required and must be valid JSON: ${error.message}`);
|
|
60
|
+
}
|
|
61
|
+
if (manifest.manifestVersion !== 1) {
|
|
62
|
+
throw new Error('bundle-manifest.json must use manifestVersion 1');
|
|
63
|
+
}
|
|
64
|
+
if (typeof manifest.runtimeVersion !== 'string' || !manifest.runtimeVersion) {
|
|
65
|
+
throw new Error('bundle-manifest.json is missing runtimeVersion');
|
|
66
|
+
}
|
|
67
|
+
return manifest.runtimeVersion;
|
|
68
|
+
};
|
|
53
69
|
async function upload(platform, options) {
|
|
54
70
|
console.log(); // blank line
|
|
55
71
|
ui_1.log.info('🚀 React Native OTA Upload Initialized');
|
|
@@ -94,7 +110,6 @@ async function upload(platform, options) {
|
|
|
94
110
|
ui_1.log.label('Channel', channel);
|
|
95
111
|
let version = options.version;
|
|
96
112
|
const buildGradlePath = options.buildGradlePath || options.buildgradlePath;
|
|
97
|
-
let runtimeVersionOverride = options.runtimeVersion;
|
|
98
113
|
let releaseNotes = options.releaseNotes;
|
|
99
114
|
const MAX_NOTES = 2000;
|
|
100
115
|
if (releaseNotes && releaseNotes.length > MAX_NOTES) {
|
|
@@ -175,6 +190,10 @@ async function upload(platform, options) {
|
|
|
175
190
|
try {
|
|
176
191
|
(0, child_process_1.execSync)(`${bundleCommand} ${platform}${sourcemapArg}`, {
|
|
177
192
|
stdio: 'inherit',
|
|
193
|
+
env: {
|
|
194
|
+
...process.env,
|
|
195
|
+
BUNDLE_DROP_APP_VERSION: version,
|
|
196
|
+
},
|
|
178
197
|
});
|
|
179
198
|
}
|
|
180
199
|
catch {
|
|
@@ -182,28 +201,14 @@ async function upload(platform, options) {
|
|
|
182
201
|
process.exit(1);
|
|
183
202
|
}
|
|
184
203
|
const outputDir = path.join(packageRoot, 'dist');
|
|
185
|
-
const
|
|
204
|
+
const manifestPath = path.join(outputDir, 'bundle-manifest.json');
|
|
186
205
|
let runtimeVersion;
|
|
187
206
|
try {
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
if (runtimeVersion) {
|
|
191
|
-
ui_1.log.label('Runtime Version', runtimeVersion);
|
|
192
|
-
}
|
|
193
|
-
}
|
|
194
|
-
catch {
|
|
195
|
-
// ignore
|
|
196
|
-
}
|
|
197
|
-
if (runtimeVersionOverride) {
|
|
198
|
-
runtimeVersion = runtimeVersionOverride;
|
|
199
|
-
ui_1.log.label('Runtime Version (override)', runtimeVersion);
|
|
200
|
-
}
|
|
201
|
-
else if (!runtimeVersion && config.runtimeVersion?.[platform]) {
|
|
202
|
-
runtimeVersion = config.runtimeVersion[platform];
|
|
203
|
-
ui_1.log.label('Runtime Version (from config)', runtimeVersion);
|
|
207
|
+
runtimeVersion = readManifestRuntimeVersion(manifestPath);
|
|
208
|
+
ui_1.log.label('Runtime Version', runtimeVersion);
|
|
204
209
|
}
|
|
205
|
-
|
|
206
|
-
ui_1.log.error(`❌
|
|
210
|
+
catch (error) {
|
|
211
|
+
ui_1.log.error(`❌ ${error.message}\nSee ${DOCS_RUNTIME_VERSION_URL}`);
|
|
207
212
|
process.exit(1);
|
|
208
213
|
}
|
|
209
214
|
const zipPath = path.join(outputDir, `bundle-${platform}.zip`);
|
|
@@ -304,6 +309,7 @@ async function upload(platform, options) {
|
|
|
304
309
|
const cleanupFiles = [
|
|
305
310
|
zipPath,
|
|
306
311
|
path.join(outputDir, `metadata-${platform}.json`),
|
|
312
|
+
path.join(outputDir, 'bundle-manifest.json'),
|
|
307
313
|
path.join(outputDir, 'main.jsbundle'),
|
|
308
314
|
path.join(outputDir, 'main.jsbundle.map'),
|
|
309
315
|
];
|
package/lib/api/client.d.ts
CHANGED
|
@@ -1 +1,11 @@
|
|
|
1
|
-
|
|
1
|
+
import type { AxiosResponse } from 'axios';
|
|
2
|
+
type ApiRequestOptions = {
|
|
3
|
+
headers?: Record<string, string>;
|
|
4
|
+
timeout?: number;
|
|
5
|
+
};
|
|
6
|
+
type ApiClient = {
|
|
7
|
+
get<T = unknown>(path: string, options?: ApiRequestOptions): Promise<AxiosResponse<T>>;
|
|
8
|
+
post<T = unknown>(path: string, payload?: unknown, options?: ApiRequestOptions): Promise<AxiosResponse<T>>;
|
|
9
|
+
};
|
|
10
|
+
export declare const apiClient: ApiClient;
|
|
11
|
+
export {};
|
package/lib/api/client.js
CHANGED
|
@@ -1,24 +1,91 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
-
};
|
|
5
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
3
|
exports.apiClient = void 0;
|
|
7
|
-
const axios_cjs_1 = __importDefault(require("axios/dist/browser/axios.cjs"));
|
|
8
4
|
const context_1 = require("../context");
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
5
|
+
const joinUrl = (baseUrl, path) => {
|
|
6
|
+
if (/^https?:\/\//i.test(path)) {
|
|
7
|
+
return path;
|
|
8
|
+
}
|
|
9
|
+
return `${baseUrl.replace(/\/+$/, '')}/${path.replace(/^\/+/, '')}`;
|
|
10
|
+
};
|
|
11
|
+
const hasHeader = (headers, name) => {
|
|
12
|
+
const normalizedName = name.toLowerCase();
|
|
13
|
+
return Object.keys(headers).some(header => header.toLowerCase() === normalizedName);
|
|
14
|
+
};
|
|
15
|
+
const buildHeaders = (headers, hasPayload) => {
|
|
16
|
+
const nextHeaders = { ...(headers || {}) };
|
|
15
17
|
const apiKey = context_1.config.project?.apiKey;
|
|
16
|
-
if (apiKey && !('x-api-key'
|
|
17
|
-
|
|
18
|
+
if (apiKey && !hasHeader(nextHeaders, 'x-api-key')) {
|
|
19
|
+
nextHeaders['x-api-key'] = apiKey;
|
|
18
20
|
}
|
|
19
|
-
if (!
|
|
20
|
-
|
|
21
|
+
if (!hasHeader(nextHeaders, 'Accept')) {
|
|
22
|
+
nextHeaders.Accept = 'application/json';
|
|
21
23
|
}
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
}
|
|
24
|
+
if (hasPayload && !hasHeader(nextHeaders, 'Content-Type')) {
|
|
25
|
+
nextHeaders['Content-Type'] = 'application/json';
|
|
26
|
+
}
|
|
27
|
+
return nextHeaders;
|
|
28
|
+
};
|
|
29
|
+
const readResponseHeaders = (headers) => {
|
|
30
|
+
const result = {};
|
|
31
|
+
if (typeof headers.forEach !== 'function') {
|
|
32
|
+
return result;
|
|
33
|
+
}
|
|
34
|
+
headers.forEach((value, key) => {
|
|
35
|
+
result[key] = value;
|
|
36
|
+
});
|
|
37
|
+
return result;
|
|
38
|
+
};
|
|
39
|
+
const readResponseData = async (response) => {
|
|
40
|
+
const text = await response.text();
|
|
41
|
+
if (!text) {
|
|
42
|
+
return undefined;
|
|
43
|
+
}
|
|
44
|
+
try {
|
|
45
|
+
return JSON.parse(text);
|
|
46
|
+
}
|
|
47
|
+
catch {
|
|
48
|
+
return text;
|
|
49
|
+
}
|
|
50
|
+
};
|
|
51
|
+
async function request(method, path, payload, options) {
|
|
52
|
+
const hasPayload = payload !== undefined;
|
|
53
|
+
const controller = typeof AbortController === 'undefined' ? null : new AbortController();
|
|
54
|
+
const timeoutId = controller && options?.timeout
|
|
55
|
+
? setTimeout(() => controller.abort(), options.timeout)
|
|
56
|
+
: null;
|
|
57
|
+
try {
|
|
58
|
+
const response = await fetch(joinUrl(context_1.config.serverUrl, path), {
|
|
59
|
+
method,
|
|
60
|
+
headers: buildHeaders(options?.headers, hasPayload),
|
|
61
|
+
body: hasPayload ? JSON.stringify(payload) : undefined,
|
|
62
|
+
signal: controller?.signal,
|
|
63
|
+
});
|
|
64
|
+
const data = await readResponseData(response);
|
|
65
|
+
const axiosResponse = {
|
|
66
|
+
data,
|
|
67
|
+
status: response.status,
|
|
68
|
+
statusText: response.statusText,
|
|
69
|
+
headers: readResponseHeaders(response.headers),
|
|
70
|
+
config: {},
|
|
71
|
+
};
|
|
72
|
+
if (!response.ok) {
|
|
73
|
+
const error = new Error(`Bundle Drop API request failed with status ${response.status}`);
|
|
74
|
+
Object.assign(error, {
|
|
75
|
+
response: axiosResponse,
|
|
76
|
+
isAxiosError: true,
|
|
77
|
+
});
|
|
78
|
+
throw error;
|
|
79
|
+
}
|
|
80
|
+
return axiosResponse;
|
|
81
|
+
}
|
|
82
|
+
finally {
|
|
83
|
+
if (timeoutId) {
|
|
84
|
+
clearTimeout(timeoutId);
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
exports.apiClient = {
|
|
89
|
+
get: (path, options) => request('GET', path, undefined, options),
|
|
90
|
+
post: (path, payload, options) => request('POST', path, payload, options),
|
|
91
|
+
};
|