@gfean/react-native-bundle-drop 0.3.3 → 0.3.5
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 +2 -0
- package/README.md +8 -2
- package/android/build.gradle +91 -1
- package/android/gradle.properties +1 -0
- package/android/src/main/java/com/bundledrop/BundleDropFileOps.kt +131 -0
- package/android/src/main/java/com/bundledrop/BundleDropModule.kt +65 -89
- package/android/src/main/java/com/bundledrop/BundleDropOtaResolver.kt +93 -0
- package/ios/BundleDropBridge.m +14 -0
- package/ios/BundleDropFileOps.swift +220 -0
- package/ios/BundleDropLocator.swift +33 -44
- package/ios/BundleDropModule.swift +65 -15
- package/ios/BundleDropOtaResolver.swift +112 -0
- package/ios/BundleDropZipExtractor.h +13 -0
- package/ios/BundleDropZipExtractor.m +226 -0
- package/lib/CLI/scripts/upload-cli.js +14 -3
- package/lib/api/types.d.ts +4 -3
- package/lib/bundleInfo.d.ts +12 -0
- package/lib/context.d.ts +17 -0
- package/lib/context.js +3 -0
- package/lib/errors.d.ts +25 -0
- package/lib/errors.js +26 -1
- package/lib/fs/fsUtils.d.ts +1 -2
- package/lib/fs/fsUtils.js +12 -27
- package/lib/fs/userProperties.d.ts +25 -4
- package/lib/fs/userProperties.js +51 -7
- package/lib/index.d.ts +1 -0
- package/lib/install/installFromZip.d.ts +1 -1
- package/lib/install/installFromZip.js +47 -42
- package/lib/loadConfig.d.ts +19 -0
- package/lib/loadConfig.js +11 -7
- package/lib/manager/downloadAndInstall.js +7 -25
- package/lib/manager/reporting.js +2 -2
- package/lib/manager/rollbackState.d.ts +3 -3
- package/lib/manager/rollbackState.js +6 -19
- package/lib/manager/updateCheck.js +2 -2
- package/lib/native/fs.d.ts +6 -0
- package/lib/native/fs.js +27 -0
- package/lib/runtime/initState.d.ts +2 -2
- package/lib/runtime/service.js +2 -0
- package/lib/scripts/bundle.js +2 -2
- package/lib/scripts/resolve-ios-version.d.ts +2 -0
- package/lib/scripts/resolve-ios-version.js +74 -0
- package/lib/scripts/upload-bundle.js +10 -4
- package/lib/types.d.ts +3 -0
- package/package.json +8 -11
|
@@ -0,0 +1,226 @@
|
|
|
1
|
+
#import "BundleDropZipExtractor.h"
|
|
2
|
+
#include <zlib.h>
|
|
3
|
+
|
|
4
|
+
static uint16_t zipRead16(const uint8_t *buf) {
|
|
5
|
+
return (uint16_t)buf[0] | ((uint16_t)buf[1] << 8);
|
|
6
|
+
}
|
|
7
|
+
|
|
8
|
+
static uint32_t zipRead32(const uint8_t *buf) {
|
|
9
|
+
return (uint32_t)buf[0] | ((uint32_t)buf[1] << 8) |
|
|
10
|
+
((uint32_t)buf[2] << 16) | ((uint32_t)buf[3] << 24);
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
@implementation BundleDropZipExtractor
|
|
14
|
+
|
|
15
|
+
static const NSUInteger kMaxZipFileSize = 256 * 1024 * 1024; // 256 MB
|
|
16
|
+
static const NSUInteger kMaxEntrySize = 128 * 1024 * 1024; // 128 MB per entry
|
|
17
|
+
static const NSUInteger kMaxTotalUncompressed = 512 * 1024 * 1024; // 512 MB total
|
|
18
|
+
|
|
19
|
+
+ (BOOL)isPath:(NSString *)path safelyInsideDirectory:(NSString *)dir {
|
|
20
|
+
NSString *resolvedDir = [dir stringByResolvingSymlinksInPath];
|
|
21
|
+
NSString *resolvedPath = [path stringByResolvingSymlinksInPath];
|
|
22
|
+
NSString *prefix = [resolvedDir stringByAppendingString:@"/"];
|
|
23
|
+
return [resolvedPath hasPrefix:prefix];
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
+ (NSArray<NSString *> *)extractZipAtPath:(NSString *)zipPath
|
|
27
|
+
toDirectory:(NSString *)destPath
|
|
28
|
+
error:(NSError **)error {
|
|
29
|
+
return [self extractZipAtPath:zipPath
|
|
30
|
+
toDirectory:destPath
|
|
31
|
+
maxZipFileSize:kMaxZipFileSize
|
|
32
|
+
maxEntrySize:kMaxEntrySize
|
|
33
|
+
maxTotalUncompressed:kMaxTotalUncompressed
|
|
34
|
+
error:error];
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
+ (NSArray<NSString *> *)extractZipAtPath:(NSString *)zipPath
|
|
38
|
+
toDirectory:(NSString *)destPath
|
|
39
|
+
maxZipFileSize:(NSUInteger)maxZipFileSize
|
|
40
|
+
maxEntrySize:(NSUInteger)maxEntrySize
|
|
41
|
+
maxTotalUncompressed:(NSUInteger)maxTotalUncompressed
|
|
42
|
+
error:(NSError **)error {
|
|
43
|
+
NSDictionary *attrs = [[NSFileManager defaultManager] attributesOfItemAtPath:zipPath error:error];
|
|
44
|
+
if (!attrs) return nil;
|
|
45
|
+
NSUInteger fileSize = [attrs[NSFileSize] unsignedIntegerValue];
|
|
46
|
+
if (fileSize > maxZipFileSize) {
|
|
47
|
+
if (error)
|
|
48
|
+
*error = [NSError errorWithDomain:@"BundleDrop" code:5
|
|
49
|
+
userInfo:@{NSLocalizedDescriptionKey:
|
|
50
|
+
[NSString stringWithFormat:@"ZIP too large: %lu bytes (max %lu)",
|
|
51
|
+
(unsigned long)fileSize, (unsigned long)maxZipFileSize]}];
|
|
52
|
+
return nil;
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
NSData *data = [NSData dataWithContentsOfFile:zipPath options:0 error:error];
|
|
56
|
+
if (!data) return nil;
|
|
57
|
+
|
|
58
|
+
const uint8_t *bytes = data.bytes;
|
|
59
|
+
NSUInteger length = data.length;
|
|
60
|
+
|
|
61
|
+
NSInteger eocdOffset = -1;
|
|
62
|
+
for (NSInteger i = (NSInteger)length - 22;
|
|
63
|
+
i >= 0 && i >= (NSInteger)length - 65557; i--) {
|
|
64
|
+
if (zipRead32(bytes + i) == 0x06054b50) {
|
|
65
|
+
eocdOffset = i;
|
|
66
|
+
break;
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
if (eocdOffset < 0) {
|
|
71
|
+
if (error)
|
|
72
|
+
*error = [NSError errorWithDomain:@"BundleDrop" code:1
|
|
73
|
+
userInfo:@{NSLocalizedDescriptionKey: @"Invalid ZIP: end-of-central-directory not found"}];
|
|
74
|
+
return nil;
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
uint16_t entryCount = zipRead16(bytes + eocdOffset + 10);
|
|
78
|
+
uint32_t cdOffset = zipRead32(bytes + eocdOffset + 16);
|
|
79
|
+
|
|
80
|
+
NSFileManager *fm = [NSFileManager defaultManager];
|
|
81
|
+
if (![fm fileExistsAtPath:destPath]) {
|
|
82
|
+
[fm createDirectoryAtPath:destPath withIntermediateDirectories:YES attributes:nil error:nil];
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
NSMutableArray<NSString *> *filenames = [NSMutableArray new];
|
|
86
|
+
NSUInteger offset = cdOffset;
|
|
87
|
+
NSUInteger totalUncompressed = 0;
|
|
88
|
+
|
|
89
|
+
for (uint16_t idx = 0; idx < entryCount; idx++) {
|
|
90
|
+
if (offset + 46 > length) break;
|
|
91
|
+
if (zipRead32(bytes + offset) != 0x02014b50) break;
|
|
92
|
+
|
|
93
|
+
uint16_t method = zipRead16(bytes + offset + 10);
|
|
94
|
+
uint32_t compressedSize = zipRead32(bytes + offset + 20);
|
|
95
|
+
uint32_t uncompressedSize = zipRead32(bytes + offset + 24);
|
|
96
|
+
uint16_t nameLen = zipRead16(bytes + offset + 28);
|
|
97
|
+
uint16_t extraLen = zipRead16(bytes + offset + 30);
|
|
98
|
+
uint16_t commentLen = zipRead16(bytes + offset + 32);
|
|
99
|
+
uint32_t localHdrOffset = zipRead32(bytes + offset + 42);
|
|
100
|
+
|
|
101
|
+
if (offset + 46 + nameLen > length) break;
|
|
102
|
+
|
|
103
|
+
NSString *name = [[NSString alloc] initWithBytes:bytes + offset + 46
|
|
104
|
+
length:nameLen
|
|
105
|
+
encoding:NSUTF8StringEncoding];
|
|
106
|
+
offset += 46 + nameLen + extraLen + commentLen;
|
|
107
|
+
|
|
108
|
+
if (!name) continue;
|
|
109
|
+
|
|
110
|
+
if ([name hasSuffix:@"/"]) {
|
|
111
|
+
NSString *dirPath = [[destPath stringByAppendingPathComponent:name] stringByStandardizingPath];
|
|
112
|
+
if (![self isPath:dirPath safelyInsideDirectory:destPath]) {
|
|
113
|
+
if (error)
|
|
114
|
+
*error = [NSError errorWithDomain:@"BundleDrop" code:6
|
|
115
|
+
userInfo:@{NSLocalizedDescriptionKey:
|
|
116
|
+
[NSString stringWithFormat:@"Zip entry outside target dir: %@", name]}];
|
|
117
|
+
return nil;
|
|
118
|
+
}
|
|
119
|
+
[fm createDirectoryAtPath:dirPath withIntermediateDirectories:YES attributes:nil error:nil];
|
|
120
|
+
continue;
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
if (localHdrOffset + 30 > length) continue;
|
|
124
|
+
uint16_t localNameLen = zipRead16(bytes + localHdrOffset + 26);
|
|
125
|
+
uint16_t localExtraLen = zipRead16(bytes + localHdrOffset + 28);
|
|
126
|
+
NSUInteger dataStart = localHdrOffset + 30 + localNameLen + localExtraLen;
|
|
127
|
+
NSUInteger dataEnd = dataStart + compressedSize;
|
|
128
|
+
if (dataEnd > length) continue;
|
|
129
|
+
|
|
130
|
+
NSUInteger entryOutputSize = (method == 0) ? compressedSize : uncompressedSize;
|
|
131
|
+
if (entryOutputSize > maxEntrySize) {
|
|
132
|
+
if (error)
|
|
133
|
+
*error = [NSError errorWithDomain:@"BundleDrop" code:7
|
|
134
|
+
userInfo:@{NSLocalizedDescriptionKey:
|
|
135
|
+
[NSString stringWithFormat:@"ZIP entry too large: %lu bytes (max %lu)",
|
|
136
|
+
(unsigned long)entryOutputSize, (unsigned long)maxEntrySize]}];
|
|
137
|
+
return nil;
|
|
138
|
+
}
|
|
139
|
+
totalUncompressed += entryOutputSize;
|
|
140
|
+
if (totalUncompressed > maxTotalUncompressed) {
|
|
141
|
+
if (error)
|
|
142
|
+
*error = [NSError errorWithDomain:@"BundleDrop" code:8
|
|
143
|
+
userInfo:@{NSLocalizedDescriptionKey:
|
|
144
|
+
[NSString stringWithFormat:@"ZIP total uncompressed too large: %lu bytes (max %lu)",
|
|
145
|
+
(unsigned long)totalUncompressed, (unsigned long)maxTotalUncompressed]}];
|
|
146
|
+
return nil;
|
|
147
|
+
}
|
|
148
|
+
|
|
149
|
+
NSData *fileData;
|
|
150
|
+
if (method == 0) {
|
|
151
|
+
fileData = [data subdataWithRange:NSMakeRange(dataStart, compressedSize)];
|
|
152
|
+
} else if (method == 8) {
|
|
153
|
+
fileData = [self inflateRaw:bytes + dataStart
|
|
154
|
+
length:compressedSize
|
|
155
|
+
uncompressedSize:uncompressedSize
|
|
156
|
+
error:error];
|
|
157
|
+
if (!fileData) return nil;
|
|
158
|
+
} else {
|
|
159
|
+
if (error)
|
|
160
|
+
*error = [NSError errorWithDomain:@"BundleDrop" code:2
|
|
161
|
+
userInfo:@{NSLocalizedDescriptionKey:
|
|
162
|
+
[NSString stringWithFormat:@"Unsupported ZIP compression method: %d", method]}];
|
|
163
|
+
return nil;
|
|
164
|
+
}
|
|
165
|
+
|
|
166
|
+
NSString *filePath = [[destPath stringByAppendingPathComponent:name] stringByStandardizingPath];
|
|
167
|
+
if (![self isPath:filePath safelyInsideDirectory:destPath]) {
|
|
168
|
+
if (error)
|
|
169
|
+
*error = [NSError errorWithDomain:@"BundleDrop" code:6
|
|
170
|
+
userInfo:@{NSLocalizedDescriptionKey:
|
|
171
|
+
[NSString stringWithFormat:@"Zip entry outside target dir: %@", name]}];
|
|
172
|
+
return nil;
|
|
173
|
+
}
|
|
174
|
+
NSString *fileDir = [filePath stringByDeletingLastPathComponent];
|
|
175
|
+
if (![fm fileExistsAtPath:fileDir]) {
|
|
176
|
+
[fm createDirectoryAtPath:fileDir withIntermediateDirectories:YES attributes:nil error:nil];
|
|
177
|
+
}
|
|
178
|
+
[fileData writeToFile:filePath atomically:YES];
|
|
179
|
+
[filenames addObject:name];
|
|
180
|
+
}
|
|
181
|
+
|
|
182
|
+
return filenames;
|
|
183
|
+
}
|
|
184
|
+
|
|
185
|
+
#pragma mark - Raw DEFLATE decompression via zlib
|
|
186
|
+
|
|
187
|
+
+ (NSData *)inflateRaw:(const uint8_t *)src
|
|
188
|
+
length:(NSUInteger)srcLen
|
|
189
|
+
uncompressedSize:(NSUInteger)dstLen
|
|
190
|
+
error:(NSError **)error {
|
|
191
|
+
if (dstLen == 0) return [NSData data];
|
|
192
|
+
|
|
193
|
+
NSMutableData *output = [NSMutableData dataWithLength:dstLen];
|
|
194
|
+
|
|
195
|
+
z_stream stream;
|
|
196
|
+
memset(&stream, 0, sizeof(stream));
|
|
197
|
+
stream.next_in = (Bytef *)src;
|
|
198
|
+
stream.avail_in = (uInt)srcLen;
|
|
199
|
+
stream.next_out = output.mutableBytes;
|
|
200
|
+
stream.avail_out = (uInt)dstLen;
|
|
201
|
+
|
|
202
|
+
int ret = inflateInit2(&stream, -MAX_WBITS);
|
|
203
|
+
if (ret != Z_OK) {
|
|
204
|
+
if (error)
|
|
205
|
+
*error = [NSError errorWithDomain:@"BundleDrop" code:3
|
|
206
|
+
userInfo:@{NSLocalizedDescriptionKey:
|
|
207
|
+
[NSString stringWithFormat:@"inflateInit2 failed: %d", ret]}];
|
|
208
|
+
return nil;
|
|
209
|
+
}
|
|
210
|
+
|
|
211
|
+
ret = inflate(&stream, Z_FINISH);
|
|
212
|
+
inflateEnd(&stream);
|
|
213
|
+
|
|
214
|
+
if (ret != Z_STREAM_END) {
|
|
215
|
+
if (error)
|
|
216
|
+
*error = [NSError errorWithDomain:@"BundleDrop" code:4
|
|
217
|
+
userInfo:@{NSLocalizedDescriptionKey:
|
|
218
|
+
[NSString stringWithFormat:@"inflate failed: %d", ret]}];
|
|
219
|
+
return nil;
|
|
220
|
+
}
|
|
221
|
+
|
|
222
|
+
output.length = stream.total_out;
|
|
223
|
+
return output;
|
|
224
|
+
}
|
|
225
|
+
|
|
226
|
+
@end
|
|
@@ -44,6 +44,7 @@ const fs = __importStar(require("fs"));
|
|
|
44
44
|
const path = __importStar(require("path"));
|
|
45
45
|
const plist = __importStar(require("plist"));
|
|
46
46
|
const ui_1 = require("../utils/ui");
|
|
47
|
+
const resolve_ios_version_1 = require("../../scripts/resolve-ios-version");
|
|
47
48
|
const DOCS_INSTALLATION_URL = 'https://bundledrop.app/docs/installation';
|
|
48
49
|
const DOCS_UPLOADING_URL = 'https://bundledrop.app/docs/uploading';
|
|
49
50
|
const DOCS_CI_CD_URL = 'https://bundledrop.app/docs/ci-cd';
|
|
@@ -122,7 +123,16 @@ async function upload(platform, options) {
|
|
|
122
123
|
try {
|
|
123
124
|
const plistContent = fs.readFileSync(options.plistFile, 'utf-8');
|
|
124
125
|
const parsed = plist.parse(plistContent);
|
|
125
|
-
|
|
126
|
+
const rawVersion = parsed.CFBundleShortVersionString;
|
|
127
|
+
if (!rawVersion) {
|
|
128
|
+
ui_1.log.error('❌ Could not find CFBundleShortVersionString in plist');
|
|
129
|
+
process.exit(1);
|
|
130
|
+
}
|
|
131
|
+
const resolved = (0, resolve_ios_version_1.resolveIosPlistVersion)(rawVersion, projectRoot);
|
|
132
|
+
if (!resolved) {
|
|
133
|
+
process.exit(1);
|
|
134
|
+
}
|
|
135
|
+
version = resolved;
|
|
126
136
|
}
|
|
127
137
|
catch (err) {
|
|
128
138
|
ui_1.log.error(`❌ Failed to parse Info.plist: ${err.message}`);
|
|
@@ -147,6 +157,7 @@ async function upload(platform, options) {
|
|
|
147
157
|
}
|
|
148
158
|
}
|
|
149
159
|
}
|
|
160
|
+
/* istanbul ignore if -- exhaustive guard; all branches above either set version or exit */
|
|
150
161
|
if (!version) {
|
|
151
162
|
ui_1.log.error('❌ Version could not be determined');
|
|
152
163
|
process.exit(1);
|
|
@@ -158,8 +169,8 @@ async function upload(platform, options) {
|
|
|
158
169
|
const compiledBundleScript = path.join(packageRoot, 'lib', 'scripts', 'bundle.js');
|
|
159
170
|
const tsBundleScript = path.join(packageRoot, 'src', 'scripts', 'bundle.ts');
|
|
160
171
|
const bundleCommand = fs.existsSync(compiledBundleScript)
|
|
161
|
-
? `node ${compiledBundleScript}`
|
|
162
|
-
: `ts-node ${tsBundleScript}`;
|
|
172
|
+
? `node "${compiledBundleScript}"`
|
|
173
|
+
: `ts-node "${tsBundleScript}"`;
|
|
163
174
|
try {
|
|
164
175
|
(0, child_process_1.execSync)(`${bundleCommand} ${platform}`, {
|
|
165
176
|
stdio: 'inherit',
|
package/lib/api/types.d.ts
CHANGED
|
@@ -1,17 +1,18 @@
|
|
|
1
|
+
import type { UserProperties } from '../fs/userProperties';
|
|
1
2
|
export type OtaResolveRequest = {
|
|
2
3
|
channelName: string;
|
|
3
4
|
platform: string;
|
|
4
5
|
runtimeVersion?: string | null;
|
|
5
6
|
environment?: string | null;
|
|
6
7
|
currentHash?: string | null;
|
|
7
|
-
currentUserProperties?:
|
|
8
|
+
currentUserProperties?: UserProperties;
|
|
8
9
|
previousHash?: string | null;
|
|
9
10
|
currentBundleVersion?: number | null;
|
|
10
11
|
installId?: string | null;
|
|
11
12
|
};
|
|
12
13
|
export type OtaResolveResponse = {
|
|
13
14
|
action: 'NOOP';
|
|
14
|
-
reason?: 'UP_TO_DATE' | 'ROLLOUT_PAUSED' | 'ROLLOUT_NOT_ELIGIBLE' | 'NO_PUBLISHED_BUNDLE' | 'NO_COMPATIBLE_BUNDLE';
|
|
15
|
+
reason?: 'UP_TO_DATE' | 'ROLLOUT_PAUSED' | 'ROLLOUT_NOT_ELIGIBLE' | 'TARGETING_NOT_MATCHED' | 'NO_PUBLISHED_BUNDLE' | 'NO_COMPATIBLE_BUNDLE';
|
|
15
16
|
requestedRuntimeVersion?: string;
|
|
16
17
|
latestRuntimeVersionOnChannel?: string;
|
|
17
18
|
} | {
|
|
@@ -66,7 +67,7 @@ export type ReportInstalledPayload = {
|
|
|
66
67
|
installId?: string | null;
|
|
67
68
|
runtimeVersion?: string | null;
|
|
68
69
|
environment?: string | null;
|
|
69
|
-
userProperties?:
|
|
70
|
+
userProperties?: UserProperties;
|
|
70
71
|
};
|
|
71
72
|
/**
|
|
72
73
|
* Public metadata for a single downloadable bundle returned by the bundle list endpoint.
|
package/lib/bundleInfo.d.ts
CHANGED
|
@@ -1,12 +1,24 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Metadata persisted for the currently downloaded or applied OTA bundle.
|
|
3
|
+
*/
|
|
1
4
|
export type BundleInfo = {
|
|
5
|
+
/** Monotonic bundle version assigned by BundleDrop. */
|
|
2
6
|
bundleVersion?: number;
|
|
7
|
+
/** Optional semantic/app version attached during upload. */
|
|
3
8
|
version?: string;
|
|
9
|
+
/** Immutable bundle hash used for install, reporting, and deduplication. */
|
|
4
10
|
hash?: string;
|
|
11
|
+
/** ISO timestamp for when this bundle metadata was written locally. */
|
|
5
12
|
installedAt?: string;
|
|
13
|
+
/** Channel used when the bundle was downloaded or installed. */
|
|
6
14
|
channelName?: string;
|
|
15
|
+
/** Platform this local metadata belongs to. */
|
|
7
16
|
platform?: 'ios' | 'android';
|
|
17
|
+
/** `true` when the bundle has downloaded but has not yet been applied. */
|
|
8
18
|
pendingApply?: boolean;
|
|
19
|
+
/** Last bundle hash successfully reported to the backend as installed. */
|
|
9
20
|
lastInstalledReportedHash?: string;
|
|
21
|
+
/** Runtime version the bundle is compatible with. */
|
|
10
22
|
runtimeVersion?: string;
|
|
11
23
|
};
|
|
12
24
|
export declare function readBundleInfo(): Promise<BundleInfo | null>;
|
package/lib/context.d.ts
CHANGED
|
@@ -4,23 +4,40 @@ export declare const isIOS: boolean;
|
|
|
4
4
|
export declare const runtimeVersion: string;
|
|
5
5
|
export declare const defaultChannel: string;
|
|
6
6
|
export declare const BUNDLE_DROP_ROOT: string;
|
|
7
|
+
/**
|
|
8
|
+
* Resolved static BundleDrop configuration for the current platform.
|
|
9
|
+
*/
|
|
7
10
|
export type BundleDropConfig = {
|
|
11
|
+
/** BundleDrop backend base URL. */
|
|
8
12
|
serverUrl: string;
|
|
13
|
+
/** Current React Native platform. */
|
|
9
14
|
platform: 'ios' | 'android';
|
|
15
|
+
/** Runtime version configured for the current platform, if present. */
|
|
10
16
|
runtimeVersion: string | undefined;
|
|
17
|
+
/** Default channel used before runtime code sets another channel. */
|
|
11
18
|
defaultChannel: string;
|
|
19
|
+
/** Organization identity used by BundleDrop APIs. */
|
|
12
20
|
org: {
|
|
13
21
|
slug: string;
|
|
14
22
|
};
|
|
23
|
+
/** Project identity used by BundleDrop APIs. */
|
|
15
24
|
project: {
|
|
16
25
|
name: string;
|
|
17
26
|
slug: string;
|
|
18
27
|
};
|
|
28
|
+
/** Whether local debug backend routing is enabled. */
|
|
19
29
|
debugLocal: boolean;
|
|
30
|
+
/** Effective rollback/crash recovery policy with defaults applied. */
|
|
20
31
|
rollback: {
|
|
32
|
+
/** Crash count required before rollback. */
|
|
21
33
|
maxCrashCount: number;
|
|
34
|
+
/** Time window, in seconds, used when counting startup crashes. */
|
|
22
35
|
crashWindowSec: number;
|
|
36
|
+
/** Time, in seconds, after which a candidate bundle is considered stable. */
|
|
23
37
|
commitTimeoutSec: number;
|
|
24
38
|
};
|
|
25
39
|
};
|
|
40
|
+
/**
|
|
41
|
+
* Resolved BundleDrop config for the current platform, derived from `bundle.drop.config.js`.
|
|
42
|
+
*/
|
|
26
43
|
export declare const bundleDropConfig: BundleDropConfig;
|
package/lib/context.js
CHANGED
|
@@ -15,6 +15,9 @@ exports.defaultChannel = exports.config.defaultChannel || 'General';
|
|
|
15
15
|
exports.BUNDLE_DROP_ROOT = exports.isIOS
|
|
16
16
|
? `${fs_1.default.LibraryDirectoryPath}/bundle-drop`
|
|
17
17
|
: `${fs_1.default.DocumentDirectoryPath}/bundle-drop`;
|
|
18
|
+
/**
|
|
19
|
+
* Resolved BundleDrop config for the current platform, derived from `bundle.drop.config.js`.
|
|
20
|
+
*/
|
|
18
21
|
exports.bundleDropConfig = {
|
|
19
22
|
serverUrl: exports.config.serverUrl,
|
|
20
23
|
platform: exports.platform,
|
package/lib/errors.d.ts
CHANGED
|
@@ -1,16 +1,41 @@
|
|
|
1
1
|
export type BundleDropErrorCode = 'CHECK_FAILED' | 'RESOLVE_FAILED' | 'INCOMPATIBLE_BINARY' | 'NO_UPDATE' | 'DOWNLOAD_URL_MISSING' | 'DOWNLOAD_FAILED' | 'INSTALL_FAILED' | 'HASH_MISSING' | 'APPLY_NO_BUNDLE' | 'APPLY_ALREADY_APPLIED' | 'APPLY_FAILED' | 'UNKNOWN';
|
|
2
2
|
export type BundleDropErrorStep = 'check' | 'resolve' | 'resolveDownloadUrl' | 'download' | 'install' | 'persist' | 'apply';
|
|
3
|
+
/**
|
|
4
|
+
* Structured error thrown by BundleDrop runtime flows.
|
|
5
|
+
*/
|
|
3
6
|
export declare class BundleDropError extends Error {
|
|
7
|
+
/** Stable machine-readable error code. */
|
|
4
8
|
code: BundleDropErrorCode;
|
|
9
|
+
/** Runtime step where the error occurred. */
|
|
5
10
|
step: BundleDropErrorStep;
|
|
11
|
+
/** Optional diagnostic context for logs or support tooling. */
|
|
6
12
|
context?: Record<string, any>;
|
|
13
|
+
/** Original error or value that caused this error, when available. */
|
|
7
14
|
cause?: unknown;
|
|
15
|
+
/**
|
|
16
|
+
* Create a structured BundleDrop runtime error.
|
|
17
|
+
*/
|
|
8
18
|
constructor(args: {
|
|
19
|
+
/** Human-readable error message. */
|
|
9
20
|
message: string;
|
|
21
|
+
/** Stable machine-readable error code. */
|
|
10
22
|
code: BundleDropErrorCode;
|
|
23
|
+
/** Runtime step where the error occurred. */
|
|
11
24
|
step: BundleDropErrorStep;
|
|
25
|
+
/** Optional diagnostic context for logs or support tooling. */
|
|
12
26
|
context?: Record<string, any>;
|
|
27
|
+
/** Original error or value that caused this error, when available. */
|
|
13
28
|
cause?: unknown;
|
|
14
29
|
});
|
|
15
30
|
}
|
|
31
|
+
/**
|
|
32
|
+
* Type guard for `BundleDropError`.
|
|
33
|
+
*/
|
|
16
34
|
export declare function isBundleDropError(e: unknown): e is BundleDropError;
|
|
35
|
+
export type InstallPhase = 'download' | 'install';
|
|
36
|
+
export declare class InstallPhaseError extends Error {
|
|
37
|
+
phase: InstallPhase;
|
|
38
|
+
originalCause: unknown;
|
|
39
|
+
constructor(phase: InstallPhase, cause: unknown);
|
|
40
|
+
}
|
|
41
|
+
export declare function isInstallPhaseError(e: unknown): e is InstallPhaseError;
|
package/lib/errors.js
CHANGED
|
@@ -1,8 +1,15 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.BundleDropError = void 0;
|
|
3
|
+
exports.InstallPhaseError = exports.BundleDropError = void 0;
|
|
4
4
|
exports.isBundleDropError = isBundleDropError;
|
|
5
|
+
exports.isInstallPhaseError = isInstallPhaseError;
|
|
6
|
+
/**
|
|
7
|
+
* Structured error thrown by BundleDrop runtime flows.
|
|
8
|
+
*/
|
|
5
9
|
class BundleDropError extends Error {
|
|
10
|
+
/**
|
|
11
|
+
* Create a structured BundleDrop runtime error.
|
|
12
|
+
*/
|
|
6
13
|
constructor(args) {
|
|
7
14
|
super(args.message);
|
|
8
15
|
this.name = 'BundleDropError';
|
|
@@ -13,6 +20,24 @@ class BundleDropError extends Error {
|
|
|
13
20
|
}
|
|
14
21
|
}
|
|
15
22
|
exports.BundleDropError = BundleDropError;
|
|
23
|
+
/**
|
|
24
|
+
* Type guard for `BundleDropError`.
|
|
25
|
+
*/
|
|
16
26
|
function isBundleDropError(e) {
|
|
17
27
|
return !!e && typeof e === 'object' && e.name === 'BundleDropError';
|
|
18
28
|
}
|
|
29
|
+
class InstallPhaseError extends Error {
|
|
30
|
+
constructor(phase, cause) {
|
|
31
|
+
const msg = cause instanceof Error ? cause.message : String(cause);
|
|
32
|
+
super(msg);
|
|
33
|
+
this.name = 'InstallPhaseError';
|
|
34
|
+
this.phase = phase;
|
|
35
|
+
this.originalCause = cause;
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
exports.InstallPhaseError = InstallPhaseError;
|
|
39
|
+
function isInstallPhaseError(e) {
|
|
40
|
+
return !!e && typeof e === 'object' &&
|
|
41
|
+
e.name === 'InstallPhaseError' &&
|
|
42
|
+
typeof e.phase === 'string';
|
|
43
|
+
}
|
package/lib/fs/fsUtils.d.ts
CHANGED
|
@@ -1,4 +1,3 @@
|
|
|
1
|
+
export declare function cleanOrphanedTempZips(bundlesDir: string): Promise<number>;
|
|
1
2
|
export declare function ensureDir(dir: string): Promise<void>;
|
|
2
3
|
export declare function atomicWriteJson(path: string, data: any): Promise<void>;
|
|
3
|
-
export declare function ensureParentDir(filePath: string): Promise<void>;
|
|
4
|
-
export declare function writeFileAtomicBase64(path: string, base64: string): Promise<void>;
|
package/lib/fs/fsUtils.js
CHANGED
|
@@ -3,46 +3,30 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
3
3
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
4
|
};
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.cleanOrphanedTempZips = cleanOrphanedTempZips;
|
|
6
7
|
exports.ensureDir = ensureDir;
|
|
7
8
|
exports.atomicWriteJson = atomicWriteJson;
|
|
8
|
-
exports.ensureParentDir = ensureParentDir;
|
|
9
|
-
exports.writeFileAtomicBase64 = writeFileAtomicBase64;
|
|
10
9
|
const fs_1 = __importDefault(require("../native/fs"));
|
|
11
|
-
async function
|
|
12
|
-
if (!(await fs_1.default.exists(dir))) {
|
|
13
|
-
await fs_1.default.mkdir(dir);
|
|
14
|
-
}
|
|
15
|
-
}
|
|
16
|
-
async function atomicWriteJson(path, data) {
|
|
17
|
-
const tmp = `${path}.${Date.now()}_${Math.random().toString(36).slice(2, 8)}.tmp`;
|
|
10
|
+
async function cleanOrphanedTempZips(bundlesDir) {
|
|
18
11
|
try {
|
|
19
|
-
await fs_1.default.
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
catch { /* already removed by concurrent writer */ }
|
|
24
|
-
await fs_1.default.moveFile(tmp, path);
|
|
12
|
+
const entries = await fs_1.default.readDir(bundlesDir);
|
|
13
|
+
const temps = entries.filter(n => n.startsWith('_tmp_') && n.endsWith('.zip'));
|
|
14
|
+
await Promise.all(temps.map(name => fs_1.default.unlink(`${bundlesDir}/${name}`)));
|
|
15
|
+
return temps.length;
|
|
25
16
|
}
|
|
26
17
|
catch {
|
|
27
|
-
|
|
28
|
-
await fs_1.default.writeFile(path, JSON.stringify(data), 'utf8');
|
|
29
|
-
try {
|
|
30
|
-
await fs_1.default.unlink(tmp);
|
|
31
|
-
}
|
|
32
|
-
catch { /* clean up orphaned tmp if it exists */ }
|
|
18
|
+
return 0;
|
|
33
19
|
}
|
|
34
20
|
}
|
|
35
|
-
async function
|
|
36
|
-
const dir = filePath.substring(0, filePath.lastIndexOf('/'));
|
|
21
|
+
async function ensureDir(dir) {
|
|
37
22
|
if (!(await fs_1.default.exists(dir))) {
|
|
38
23
|
await fs_1.default.mkdir(dir);
|
|
39
24
|
}
|
|
40
25
|
}
|
|
41
|
-
async function
|
|
26
|
+
async function atomicWriteJson(path, data) {
|
|
42
27
|
const tmp = `${path}.${Date.now()}_${Math.random().toString(36).slice(2, 8)}.tmp`;
|
|
43
|
-
await ensureParentDir(path);
|
|
44
28
|
try {
|
|
45
|
-
await fs_1.default.writeFile(tmp,
|
|
29
|
+
await fs_1.default.writeFile(tmp, JSON.stringify(data), 'utf8');
|
|
46
30
|
try {
|
|
47
31
|
await fs_1.default.unlink(path);
|
|
48
32
|
}
|
|
@@ -50,7 +34,8 @@ async function writeFileAtomicBase64(path, base64) {
|
|
|
50
34
|
await fs_1.default.moveFile(tmp, path);
|
|
51
35
|
}
|
|
52
36
|
catch {
|
|
53
|
-
|
|
37
|
+
// Atomic rename failed (concurrent writer moved/removed our tmp); fall back to direct write.
|
|
38
|
+
await fs_1.default.writeFile(path, JSON.stringify(data), 'utf8');
|
|
54
39
|
try {
|
|
55
40
|
await fs_1.default.unlink(tmp);
|
|
56
41
|
}
|
|
@@ -1,7 +1,28 @@
|
|
|
1
|
-
export
|
|
2
|
-
export
|
|
3
|
-
|
|
4
|
-
|
|
1
|
+
export type UserPropertyValue = string | number | boolean;
|
|
2
|
+
export type UserProperties = Record<string, UserPropertyValue>;
|
|
3
|
+
/**
|
|
4
|
+
* Read user properties that will be sent with OTA resolve requests.
|
|
5
|
+
*/
|
|
6
|
+
export declare function getCurrentUserProperties(): Promise<UserProperties>;
|
|
7
|
+
/**
|
|
8
|
+
* Alias for `getCurrentUserProperties()`.
|
|
9
|
+
*/
|
|
10
|
+
export declare function getUserProperties(): Promise<UserProperties>;
|
|
11
|
+
/**
|
|
12
|
+
* Set or replace one user property used for targeting future OTA resolve requests.
|
|
13
|
+
*
|
|
14
|
+
* Empty keys are ignored and return the current property map unchanged.
|
|
15
|
+
*/
|
|
16
|
+
export declare function setUserProperty(key: string, value: UserPropertyValue): Promise<UserProperties>;
|
|
17
|
+
/**
|
|
18
|
+
* Remove one user property used for targeting future OTA resolve requests.
|
|
19
|
+
*
|
|
20
|
+
* Empty or missing keys are ignored and return the current property map unchanged.
|
|
21
|
+
*/
|
|
22
|
+
export declare function removeUserProperty(key: string): Promise<UserProperties>;
|
|
23
|
+
/**
|
|
24
|
+
* Clear all locally stored user properties.
|
|
25
|
+
*/
|
|
5
26
|
export declare function resetUserProperties(): Promise<void>;
|
|
6
27
|
/** @deprecated Use setUserProperty(key, value) instead. */
|
|
7
28
|
export declare const setUserPropery: typeof setUserProperty;
|
package/lib/fs/userProperties.js
CHANGED
|
@@ -13,11 +13,31 @@ const fs_1 = __importDefault(require("../native/fs"));
|
|
|
13
13
|
const context_1 = require("../context");
|
|
14
14
|
const fsUtils_1 = require("./fsUtils");
|
|
15
15
|
const USER_PROPERTIES_PATH = `${context_1.BUNDLE_DROP_ROOT}/user-properties.json`;
|
|
16
|
+
const MAX_USER_PROPERTY_KEY_LENGTH = 128;
|
|
17
|
+
const RESERVED_USER_PROPERTY_KEYS = new Set(['__proto__', 'constructor', 'prototype']);
|
|
18
|
+
const normalizeUserPropertyValue = (value) => {
|
|
19
|
+
if (typeof value === 'string')
|
|
20
|
+
return value;
|
|
21
|
+
if (typeof value === 'number' && Number.isFinite(value))
|
|
22
|
+
return value;
|
|
23
|
+
if (typeof value === 'boolean')
|
|
24
|
+
return value;
|
|
25
|
+
return null;
|
|
26
|
+
};
|
|
27
|
+
const isValidUserPropertyKey = (key) => key.length > 0 &&
|
|
28
|
+
key.length <= MAX_USER_PROPERTY_KEY_LENGTH &&
|
|
29
|
+
!key.startsWith('$') &&
|
|
30
|
+
!key.includes('.') &&
|
|
31
|
+
!key.includes('\0') &&
|
|
32
|
+
!RESERVED_USER_PROPERTY_KEYS.has(key);
|
|
16
33
|
async function writeUserProperties(properties) {
|
|
17
34
|
await (0, fsUtils_1.ensureDir)(context_1.BUNDLE_DROP_ROOT);
|
|
18
35
|
const payload = { properties: { ...properties } };
|
|
19
36
|
await (0, fsUtils_1.atomicWriteJson)(USER_PROPERTIES_PATH, payload);
|
|
20
37
|
}
|
|
38
|
+
/**
|
|
39
|
+
* Read user properties that will be sent with OTA resolve requests.
|
|
40
|
+
*/
|
|
21
41
|
async function getCurrentUserProperties() {
|
|
22
42
|
try {
|
|
23
43
|
if (!(await fs_1.default.exists(USER_PROPERTIES_PATH)))
|
|
@@ -29,11 +49,12 @@ async function getCurrentUserProperties() {
|
|
|
29
49
|
return {};
|
|
30
50
|
const result = {};
|
|
31
51
|
for (const [k, v] of Object.entries(props)) {
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
52
|
+
const key = k.trim();
|
|
53
|
+
if (!isValidUserPropertyKey(key))
|
|
54
|
+
continue;
|
|
55
|
+
const value = normalizeUserPropertyValue(v);
|
|
56
|
+
if (value !== null)
|
|
57
|
+
result[key] = value;
|
|
37
58
|
}
|
|
38
59
|
return result;
|
|
39
60
|
}
|
|
@@ -42,22 +63,42 @@ async function getCurrentUserProperties() {
|
|
|
42
63
|
return {};
|
|
43
64
|
}
|
|
44
65
|
}
|
|
66
|
+
/**
|
|
67
|
+
* Alias for `getCurrentUserProperties()`.
|
|
68
|
+
*/
|
|
45
69
|
async function getUserProperties() {
|
|
46
70
|
return getCurrentUserProperties();
|
|
47
71
|
}
|
|
72
|
+
/**
|
|
73
|
+
* Set or replace one user property used for targeting future OTA resolve requests.
|
|
74
|
+
*
|
|
75
|
+
* Empty keys are ignored and return the current property map unchanged.
|
|
76
|
+
*/
|
|
48
77
|
async function setUserProperty(key, value) {
|
|
49
78
|
const trimmedKey = key.trim();
|
|
50
79
|
if (!trimmedKey) {
|
|
51
80
|
return getCurrentUserProperties();
|
|
52
81
|
}
|
|
82
|
+
if (!isValidUserPropertyKey(trimmedKey)) {
|
|
83
|
+
throw new TypeError('User property key is invalid');
|
|
84
|
+
}
|
|
85
|
+
const normalizedValue = normalizeUserPropertyValue(value);
|
|
86
|
+
if (normalizedValue === null) {
|
|
87
|
+
throw new TypeError('User property value must be a string, number, or boolean');
|
|
88
|
+
}
|
|
53
89
|
const existing = await getCurrentUserProperties();
|
|
54
|
-
if (existing[trimmedKey] ===
|
|
90
|
+
if (existing[trimmedKey] === normalizedValue) {
|
|
55
91
|
return existing;
|
|
56
92
|
}
|
|
57
|
-
const next = { ...existing, [trimmedKey]:
|
|
93
|
+
const next = { ...existing, [trimmedKey]: normalizedValue };
|
|
58
94
|
await writeUserProperties(next);
|
|
59
95
|
return next;
|
|
60
96
|
}
|
|
97
|
+
/**
|
|
98
|
+
* Remove one user property used for targeting future OTA resolve requests.
|
|
99
|
+
*
|
|
100
|
+
* Empty or missing keys are ignored and return the current property map unchanged.
|
|
101
|
+
*/
|
|
61
102
|
async function removeUserProperty(key) {
|
|
62
103
|
const trimmedKey = key.trim();
|
|
63
104
|
if (!trimmedKey) {
|
|
@@ -75,6 +116,9 @@ async function removeUserProperty(key) {
|
|
|
75
116
|
await writeUserProperties(next);
|
|
76
117
|
return next;
|
|
77
118
|
}
|
|
119
|
+
/**
|
|
120
|
+
* Clear all locally stored user properties.
|
|
121
|
+
*/
|
|
78
122
|
async function resetUserProperties() {
|
|
79
123
|
try {
|
|
80
124
|
if (await fs_1.default.exists(USER_PROPERTIES_PATH)) {
|