@gfean/react-native-bundle-drop 0.3.3 → 0.3.6
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.h +11 -0
- package/ios/BundleDropLocator.swift +34 -45
- 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/cli.js +56 -6
- package/lib/CLI/scripts/aipowered/apply-plan.d.ts +10 -0
- package/lib/CLI/scripts/aipowered/apply-plan.js +50 -0
- package/lib/CLI/scripts/aipowered/backend-client.d.ts +6 -0
- package/lib/CLI/scripts/aipowered/backend-client.js +34 -0
- package/lib/CLI/scripts/aipowered/diff-preview.d.ts +7 -0
- package/lib/CLI/scripts/aipowered/diff-preview.js +33 -0
- package/lib/CLI/scripts/aipowered/init-native-config.d.ts +2 -0
- package/lib/CLI/scripts/aipowered/init-native-config.js +131 -0
- package/lib/CLI/scripts/aipowered/scanner.d.ts +5 -0
- package/lib/CLI/scripts/aipowered/scanner.js +349 -0
- package/lib/CLI/scripts/aipowered/types.d.ts +53 -0
- package/lib/CLI/scripts/aipowered/types.js +2 -0
- package/lib/CLI/scripts/aipowered/validate-plan.d.ts +8 -0
- package/lib/CLI/scripts/aipowered/validate-plan.js +164 -0
- package/lib/CLI/scripts/init-config.js +10 -5
- package/lib/CLI/scripts/init-native-config.js +1 -1
- package/lib/CLI/scripts/post-init.js +7 -18
- package/lib/CLI/scripts/upload-cli.d.ts +2 -0
- package/lib/CLI/scripts/upload-cli.js +67 -28
- package/lib/CLI/utils/ui.d.ts +3 -0
- package/lib/CLI/utils/ui.js +26 -0
- package/lib/api/clientApi.d.ts +2 -1
- package/lib/api/clientApi.js +9 -0
- package/lib/api/types.d.ts +21 -3
- package/lib/bundleInfo.d.ts +12 -0
- package/lib/context.d.ts +19 -2
- package/lib/context.js +5 -2
- package/lib/errors.d.ts +25 -0
- package/lib/errors.js +26 -1
- package/lib/fs/bundlePointer.d.ts +2 -0
- package/lib/fs/bundlePointer.js +14 -4
- 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 +7 -3
- package/lib/index.js +5 -1
- package/lib/injectImageResolver.js +6 -15
- package/lib/install/installFromZip.d.ts +1 -1
- package/lib/install/installFromZip.js +47 -42
- package/lib/loadConfig.d.ts +21 -2
- package/lib/loadConfig.js +11 -7
- package/lib/manager/downloadAndInstall.d.ts +3 -0
- package/lib/manager/downloadAndInstall.js +30 -28
- package/lib/manager/reporting.d.ts +2 -0
- package/lib/manager/reporting.js +27 -2
- package/lib/manager/rollbackState.d.ts +28 -11
- package/lib/manager/rollbackState.js +90 -38
- package/lib/manager/updateCheck.js +17 -3
- package/lib/manager/updateState.d.ts +5 -1
- package/lib/manager/updateState.js +20 -11
- 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.d.ts +28 -0
- package/lib/runtime/service.js +136 -10
- package/lib/scripts/bundle.d.ts +4 -1
- package/lib/scripts/bundle.js +42 -29
- package/lib/scripts/projectRoot.d.ts +1 -0
- package/lib/scripts/projectRoot.js +54 -0
- package/lib/scripts/resolve-ios-version.d.ts +2 -0
- package/lib/scripts/resolve-ios-version.js +74 -0
- package/lib/scripts/upload-bundle.d.ts +2 -1
- package/lib/scripts/upload-bundle.js +56 -41
- package/lib/types.d.ts +3 -0
- package/lib/useBundleDrop.d.ts +2 -0
- package/lib/useBundleDrop.js +1 -0
- package/package.json +9 -11
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)) {
|
package/lib/index.d.ts
CHANGED
|
@@ -1,10 +1,12 @@
|
|
|
1
1
|
import './bootstrap';
|
|
2
|
-
import { getChannelName, initBundleDrop, setChannel } from './runtime/service';
|
|
3
|
-
export { getAvailableChannels, checkForUpdate, getInstalledBundleInfo, getAvailableBundles } from './runtime/service';
|
|
2
|
+
import { getChannelName, initBundleDrop, reportHealthy, setChannel } from './runtime/service';
|
|
3
|
+
export { getAvailableChannels, checkForUpdate, getInstalledBundleInfo, getObservabilityContext, getAvailableBundles } from './runtime/service';
|
|
4
|
+
export type { ObservabilityContext } from './runtime/service';
|
|
4
5
|
export type { AvailableBundlesPage, GetAvailableBundlesOptions } from './manager/updateCheck';
|
|
5
|
-
export { downloadUpdate, installBundle, getRuntimeUpdateState as getUpdateState, applyUpdate, setChannel, getChannelName, } from './runtime/service';
|
|
6
|
+
export { downloadUpdate, installBundle, getRuntimeUpdateState as getUpdateState, applyUpdate, setChannel, getChannelName, reportHealthy, } from './runtime/service';
|
|
6
7
|
export { BundleDropError, isBundleDropError } from './errors';
|
|
7
8
|
export { getCurrentUserProperties, getUserProperties, setUserProperty, setUserPropery, removeUserProperty, resetUserProperties, } from './fs/userProperties';
|
|
9
|
+
export type { UserProperties, UserPropertyValue } from './fs/userProperties';
|
|
8
10
|
export type { BundleInfo } from './bundleInfo';
|
|
9
11
|
export type { UpdatePolicy } from './types';
|
|
10
12
|
export type { BundleListItem } from './api/types';
|
|
@@ -24,4 +26,6 @@ export declare const BundleDrop: {
|
|
|
24
26
|
readonly setChannel: typeof setChannel;
|
|
25
27
|
/** Read the currently active runtime channel. */
|
|
26
28
|
readonly getChannelName: typeof getChannelName;
|
|
29
|
+
/** Mark the currently running OTA candidate healthy for this device. */
|
|
30
|
+
readonly reportHealthy: typeof reportHealthy;
|
|
27
31
|
};
|
package/lib/index.js
CHANGED
|
@@ -1,12 +1,13 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.BundleDrop = exports.bundleDropConfig = exports.useBundleDrop = exports.resetUserProperties = exports.removeUserProperty = exports.setUserPropery = exports.setUserProperty = exports.getUserProperties = exports.getCurrentUserProperties = exports.isBundleDropError = exports.BundleDropError = exports.getChannelName = exports.setChannel = exports.applyUpdate = exports.getUpdateState = exports.installBundle = exports.downloadUpdate = exports.getAvailableBundles = exports.getInstalledBundleInfo = exports.checkForUpdate = exports.getAvailableChannels = void 0;
|
|
3
|
+
exports.BundleDrop = exports.bundleDropConfig = exports.useBundleDrop = exports.resetUserProperties = exports.removeUserProperty = exports.setUserPropery = exports.setUserProperty = exports.getUserProperties = exports.getCurrentUserProperties = exports.isBundleDropError = exports.BundleDropError = exports.reportHealthy = exports.getChannelName = exports.setChannel = exports.applyUpdate = exports.getUpdateState = exports.installBundle = exports.downloadUpdate = exports.getAvailableBundles = exports.getObservabilityContext = exports.getInstalledBundleInfo = exports.checkForUpdate = exports.getAvailableChannels = void 0;
|
|
4
4
|
require("./bootstrap");
|
|
5
5
|
const service_1 = require("./runtime/service");
|
|
6
6
|
var service_2 = require("./runtime/service");
|
|
7
7
|
Object.defineProperty(exports, "getAvailableChannels", { enumerable: true, get: function () { return service_2.getAvailableChannels; } });
|
|
8
8
|
Object.defineProperty(exports, "checkForUpdate", { enumerable: true, get: function () { return service_2.checkForUpdate; } });
|
|
9
9
|
Object.defineProperty(exports, "getInstalledBundleInfo", { enumerable: true, get: function () { return service_2.getInstalledBundleInfo; } });
|
|
10
|
+
Object.defineProperty(exports, "getObservabilityContext", { enumerable: true, get: function () { return service_2.getObservabilityContext; } });
|
|
10
11
|
Object.defineProperty(exports, "getAvailableBundles", { enumerable: true, get: function () { return service_2.getAvailableBundles; } });
|
|
11
12
|
var service_3 = require("./runtime/service");
|
|
12
13
|
Object.defineProperty(exports, "downloadUpdate", { enumerable: true, get: function () { return service_3.downloadUpdate; } });
|
|
@@ -15,6 +16,7 @@ Object.defineProperty(exports, "getUpdateState", { enumerable: true, get: functi
|
|
|
15
16
|
Object.defineProperty(exports, "applyUpdate", { enumerable: true, get: function () { return service_3.applyUpdate; } });
|
|
16
17
|
Object.defineProperty(exports, "setChannel", { enumerable: true, get: function () { return service_3.setChannel; } });
|
|
17
18
|
Object.defineProperty(exports, "getChannelName", { enumerable: true, get: function () { return service_3.getChannelName; } });
|
|
19
|
+
Object.defineProperty(exports, "reportHealthy", { enumerable: true, get: function () { return service_3.reportHealthy; } });
|
|
18
20
|
var errors_1 = require("./errors");
|
|
19
21
|
Object.defineProperty(exports, "BundleDropError", { enumerable: true, get: function () { return errors_1.BundleDropError; } });
|
|
20
22
|
Object.defineProperty(exports, "isBundleDropError", { enumerable: true, get: function () { return errors_1.isBundleDropError; } });
|
|
@@ -39,4 +41,6 @@ exports.BundleDrop = {
|
|
|
39
41
|
setChannel: service_1.setChannel,
|
|
40
42
|
/** Read the currently active runtime channel. */
|
|
41
43
|
getChannelName: service_1.getChannelName,
|
|
44
|
+
/** Mark the currently running OTA candidate healthy for this device. */
|
|
45
|
+
reportHealthy: service_1.reportHealthy,
|
|
42
46
|
};
|
|
@@ -37,9 +37,15 @@ function patchImageResolverWithManifest(manifest) {
|
|
|
37
37
|
const originalResolve = react_native_1.Image.resolveAssetSource;
|
|
38
38
|
react_native_1.Image.resolveAssetSource = (source) => {
|
|
39
39
|
const resolved = originalResolve(source);
|
|
40
|
+
if (typeof source !== 'number' && !source?.__packager_asset) {
|
|
41
|
+
return resolved;
|
|
42
|
+
}
|
|
40
43
|
const uri = resolved?.uri;
|
|
41
44
|
if (!uri)
|
|
42
45
|
return resolved;
|
|
46
|
+
if (/^(https?|data|content):/.test(uri)) {
|
|
47
|
+
return resolved;
|
|
48
|
+
}
|
|
43
49
|
let cleanedKey = uri;
|
|
44
50
|
if (uri.startsWith('file://')) {
|
|
45
51
|
const parts = uri.split('/files/')[1];
|
|
@@ -73,21 +79,6 @@ function patchImageResolverWithManifest(manifest) {
|
|
|
73
79
|
finalPath = byBase[base];
|
|
74
80
|
}
|
|
75
81
|
}
|
|
76
|
-
// Fallback: try basename with extension
|
|
77
|
-
if (!finalPath) {
|
|
78
|
-
const baseWithExt = (cleanedKey.split('/').pop() || '').replace(/^android_asset\//, '');
|
|
79
|
-
if (baseWithExt && byKey[baseWithExt]) {
|
|
80
|
-
finalPath = byKey[baseWithExt];
|
|
81
|
-
}
|
|
82
|
-
}
|
|
83
|
-
// Last-resort fallback: point to assets/<basename> if nothing is mapped.
|
|
84
|
-
if (!finalPath) {
|
|
85
|
-
const filename = cleanedKey.split('/').pop();
|
|
86
|
-
if (filename) {
|
|
87
|
-
const guessed = `assets/${filename}`;
|
|
88
|
-
finalPath = guessed;
|
|
89
|
-
}
|
|
90
|
-
}
|
|
91
82
|
if (finalPath) {
|
|
92
83
|
const hasExtension = /\.[a-zA-Z0-9]+$/.test(finalPath);
|
|
93
84
|
const fullPath = `file://${fs_1.default.DocumentDirectoryPath}/${finalPath}${hasExtension ? '' : (uri.match(/\.[^.]+$/)?.[0] ?? '')}`;
|
|
@@ -4,29 +4,59 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
4
4
|
};
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
6
|
exports.installFromZip = installFromZip;
|
|
7
|
-
const buffer_1 = require("buffer");
|
|
8
|
-
const fflate_1 = require("fflate");
|
|
9
7
|
const fs_1 = __importDefault(require("../native/fs"));
|
|
10
8
|
const context_1 = require("../context");
|
|
11
9
|
const image_manifest_1 = require("../image-manifest");
|
|
12
10
|
const injectImageResolver_1 = require("../injectImageResolver");
|
|
13
11
|
const fsUtils_1 = require("../fs/fsUtils");
|
|
12
|
+
const errors_1 = require("../errors");
|
|
14
13
|
async function installFromZip(params) {
|
|
15
|
-
const {
|
|
16
|
-
|
|
17
|
-
|
|
14
|
+
const { downloadUrl, hash, statusCb, platform = context_1.platform } = params;
|
|
15
|
+
if (!hash) {
|
|
16
|
+
throw new Error('Missing bundle hash');
|
|
17
|
+
}
|
|
18
|
+
const bundleDir = `${context_1.BUNDLE_DROP_ROOT}/bundles/${hash}`;
|
|
19
|
+
await (0, fsUtils_1.ensureDir)(bundleDir);
|
|
20
|
+
const bundlePath = `${bundleDir}/main.jsbundle`;
|
|
21
|
+
const tempZipPath = `${context_1.BUNDLE_DROP_ROOT}/bundles/_tmp_${hash}.zip`;
|
|
22
|
+
let fileNames;
|
|
18
23
|
try {
|
|
19
|
-
|
|
24
|
+
try {
|
|
25
|
+
await fs_1.default.downloadFile(downloadUrl, tempZipPath);
|
|
26
|
+
}
|
|
27
|
+
catch (e) {
|
|
28
|
+
throw new errors_1.InstallPhaseError('download', e);
|
|
29
|
+
}
|
|
30
|
+
try {
|
|
31
|
+
fileNames = await fs_1.default.unzip(tempZipPath, bundleDir);
|
|
32
|
+
}
|
|
33
|
+
catch (e) {
|
|
34
|
+
throw new errors_1.InstallPhaseError('install', e);
|
|
35
|
+
}
|
|
36
|
+
if (!(await fs_1.default.exists(bundlePath))) {
|
|
37
|
+
throw new errors_1.InstallPhaseError('install', new Error('main.jsbundle missing after extraction'));
|
|
38
|
+
}
|
|
20
39
|
}
|
|
21
40
|
catch (e) {
|
|
22
|
-
|
|
41
|
+
try {
|
|
42
|
+
await fs_1.default.unlink(bundleDir);
|
|
43
|
+
}
|
|
44
|
+
catch { /* best-effort cleanup */ }
|
|
23
45
|
throw e;
|
|
24
46
|
}
|
|
47
|
+
finally {
|
|
48
|
+
try {
|
|
49
|
+
await fs_1.default.unlink(tempZipPath);
|
|
50
|
+
}
|
|
51
|
+
catch { /* best-effort cleanup */ }
|
|
52
|
+
}
|
|
53
|
+
statusCb?.(`📁 ${fileNames.length} files extracted`);
|
|
54
|
+
// Read metadata from the extracted files
|
|
25
55
|
const metadataFromZip = {};
|
|
26
56
|
const metadataFile = platform === 'android' ? 'metadata-android.json' : 'metadata-ios.json';
|
|
27
|
-
if (
|
|
57
|
+
if (fileNames.includes(metadataFile)) {
|
|
28
58
|
try {
|
|
29
|
-
const raw =
|
|
59
|
+
const raw = await fs_1.default.readFile(`${bundleDir}/${metadataFile}`, 'utf8');
|
|
30
60
|
const parsed = JSON.parse(raw);
|
|
31
61
|
metadataFromZip.bundleVersion = parsed.bundleVersion ?? metadataFromZip.bundleVersion;
|
|
32
62
|
metadataFromZip.version = parsed.version ?? metadataFromZip.version;
|
|
@@ -37,39 +67,16 @@ async function installFromZip(params) {
|
|
|
37
67
|
console.warn('⚠️ Failed to parse bundle metadata from zip', e);
|
|
38
68
|
}
|
|
39
69
|
}
|
|
40
|
-
|
|
41
|
-
statusCb?.(`📁 ${fileNames.length} files extracted from ZIP`);
|
|
42
|
-
statusCb?.('💾 Writing files...');
|
|
43
|
-
const resolvedHash = hash ?? metadataFromZip.hash;
|
|
44
|
-
if (!resolvedHash) {
|
|
45
|
-
throw new Error('Missing bundle hash');
|
|
46
|
-
}
|
|
47
|
-
// Build a runtime manifest from extracted assets to handle filename-only resolutions.
|
|
70
|
+
// Build runtime manifest from extracted filenames (assets only)
|
|
48
71
|
const runtimeManifest = {};
|
|
49
|
-
|
|
50
|
-
const bundleDir = `${context_1.BUNDLE_DROP_ROOT}/bundles/${resolvedHash}`;
|
|
51
|
-
await (0, fsUtils_1.ensureDir)(bundleDir);
|
|
52
|
-
const bundlePath = `${bundleDir}/main.jsbundle`;
|
|
53
|
-
for (const [filename, fileData] of Object.entries(files)) {
|
|
54
|
-
const dataBuffer = buffer_1.Buffer.from(fileData);
|
|
55
|
-
const base64 = dataBuffer.toString('base64');
|
|
56
|
-
if (filename === 'main.jsbundle') {
|
|
57
|
-
await (0, fsUtils_1.writeFileAtomicBase64)(bundlePath, base64);
|
|
58
|
-
continue;
|
|
59
|
-
}
|
|
60
|
-
// Write other files under bundleDir (e.g., metadata, assets)
|
|
61
|
-
const filePath = `${bundleDir}/${filename}`;
|
|
62
|
-
await (0, fsUtils_1.ensureParentDir)(filePath);
|
|
63
|
-
await fs_1.default.writeFile(filePath, base64, 'base64');
|
|
64
|
-
// Collect runtime manifest entries for assets; support paths with or without "assets/" prefix.
|
|
72
|
+
for (const filename of fileNames) {
|
|
65
73
|
if (filename.includes('drawable') || filename.startsWith('assets/') || filename.startsWith('res/')) {
|
|
66
74
|
const noExt = filename.replace(/\.[^.]+$/, '');
|
|
67
75
|
const base = noExt.split('/').pop();
|
|
68
76
|
const withAssetsPrefix = filename.startsWith('assets/') ? filename : `assets/${filename}`;
|
|
69
|
-
// Map to on-disk location relative to DocumentDirectoryPath
|
|
70
77
|
const mappedPath = context_1.isIOS
|
|
71
|
-
? `${
|
|
72
|
-
: `bundle-drop/bundles/${
|
|
78
|
+
? `${hash}/${filename}`
|
|
79
|
+
: `bundle-drop/bundles/${hash}/${filename}`;
|
|
73
80
|
runtimeManifest[noExt.replace(/^assets\//, '')] = mappedPath;
|
|
74
81
|
runtimeManifest[withAssetsPrefix.replace(/\.[^.]+$/, '')] = mappedPath;
|
|
75
82
|
if (base && !runtimeManifest[base]) {
|
|
@@ -81,11 +88,11 @@ async function installFromZip(params) {
|
|
|
81
88
|
}
|
|
82
89
|
}
|
|
83
90
|
}
|
|
84
|
-
//
|
|
85
|
-
if (platform === 'android' &&
|
|
91
|
+
// Load image manifest (Android)
|
|
92
|
+
if (platform === 'android' && fileNames.includes('image-manifest.json')) {
|
|
86
93
|
try {
|
|
87
|
-
const
|
|
88
|
-
const parsed = JSON.parse(
|
|
94
|
+
const raw = await fs_1.default.readFile(`${bundleDir}/image-manifest.json`, 'utf8');
|
|
95
|
+
const parsed = JSON.parse(raw);
|
|
89
96
|
Object.assign(image_manifest_1.imageManifest, parsed);
|
|
90
97
|
statusCb?.(`🧩 Image manifest injected: ${Object.keys(parsed).length} items`);
|
|
91
98
|
}
|
|
@@ -94,12 +101,10 @@ async function installFromZip(params) {
|
|
|
94
101
|
statusCb?.('❌ Failed to parse image manifest');
|
|
95
102
|
}
|
|
96
103
|
}
|
|
97
|
-
// Merge runtime manifest to catch any assets missing from the bundle-time manifest.
|
|
98
104
|
if (platform === 'android' && Object.keys(runtimeManifest).length > 0) {
|
|
99
105
|
Object.assign(image_manifest_1.imageManifest, runtimeManifest);
|
|
100
106
|
}
|
|
101
107
|
if (platform === 'android') {
|
|
102
|
-
// Re-patch with the freshest manifest so newly downloaded assets resolve.
|
|
103
108
|
(0, injectImageResolver_1.injectBundleDropImageResolver)(image_manifest_1.imageManifest);
|
|
104
109
|
}
|
|
105
110
|
return { bundlePath, metadataFromZip };
|
package/lib/loadConfig.d.ts
CHANGED
|
@@ -1,23 +1,42 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Shape of `bundle.drop.config.js` after it is loaded through Metro.
|
|
3
|
+
*/
|
|
1
4
|
export type BundleDropProjectConfig = {
|
|
5
|
+
/** BundleDrop backend base URL. */
|
|
2
6
|
serverUrl: string;
|
|
7
|
+
/** Organization identity used for public API calls. */
|
|
3
8
|
org: {
|
|
9
|
+
/** Organization slug. */
|
|
4
10
|
slug: string;
|
|
5
11
|
};
|
|
12
|
+
/** Project identity and public access configuration. */
|
|
6
13
|
project: {
|
|
14
|
+
/** Human-readable project name. */
|
|
7
15
|
name: string;
|
|
16
|
+
/** Project slug used by public API calls. */
|
|
8
17
|
slug: string;
|
|
18
|
+
/** Optional public API key used by CLI/runtime integrations. */
|
|
9
19
|
apiKey?: string;
|
|
10
20
|
};
|
|
21
|
+
/** When true, route local dev traffic to emulator/simulator-friendly localhost URLs. */
|
|
11
22
|
debugLocal?: boolean;
|
|
23
|
+
/** Native runtime versions for platform compatibility checks. */
|
|
12
24
|
runtimeVersion?: {
|
|
25
|
+
/** iOS runtime version. */
|
|
13
26
|
ios: string;
|
|
27
|
+
/** Android runtime version. */
|
|
14
28
|
android: string;
|
|
15
29
|
};
|
|
30
|
+
/** Default OTA channel used before runtime code sets another channel. */
|
|
16
31
|
defaultChannel?: string;
|
|
32
|
+
/** Rollback/crash recovery tuning. */
|
|
17
33
|
rollback?: {
|
|
34
|
+
/** Crash count required before rollback. */
|
|
18
35
|
maxCrashCount?: number;
|
|
19
|
-
|
|
20
|
-
|
|
36
|
+
/** How Bundle Drop marks a newly launched OTA bundle healthy. */
|
|
37
|
+
healthCheckMode?: 'auto' | 'manual';
|
|
38
|
+
/** Seconds to wait before automatically marking a candidate healthy in auto mode. */
|
|
39
|
+
healthyAfterSec?: number;
|
|
21
40
|
};
|
|
22
41
|
};
|
|
23
42
|
export declare function loadConfig(): BundleDropProjectConfig;
|
package/lib/loadConfig.js
CHANGED
|
@@ -20,12 +20,16 @@ function loadConfig() {
|
|
|
20
20
|
return cfg;
|
|
21
21
|
}
|
|
22
22
|
catch (e) {
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
23
|
+
if (typeof __DEV__ !== 'undefined' && __DEV__) {
|
|
24
|
+
console.warn('[BundleDrop] loadConfig failed, using dev defaults:', e);
|
|
25
|
+
return {
|
|
26
|
+
serverUrl: 'https://api.bundledrop.app',
|
|
27
|
+
org: { slug: 'default-org' },
|
|
28
|
+
project: { name: 'BundleDrop', slug: 'default' },
|
|
29
|
+
debugLocal: false,
|
|
30
|
+
};
|
|
31
|
+
}
|
|
32
|
+
throw new Error('[BundleDrop] bundle.drop.config.js could not be loaded. ' +
|
|
33
|
+
'Ensure the config file exists and Metro is configured with the bundle-drop-config alias.');
|
|
30
34
|
}
|
|
31
35
|
}
|
|
@@ -1,10 +1,6 @@
|
|
|
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.installBundle = exports.downloadUpdate = void 0;
|
|
7
|
-
const axios_cjs_1 = __importDefault(require("axios/dist/browser/axios.cjs"));
|
|
8
4
|
const context_1 = require("../context");
|
|
9
5
|
const bundleInfo_1 = require("../bundleInfo");
|
|
10
6
|
const bundlePointer_1 = require("../fs/bundlePointer");
|
|
@@ -42,8 +38,17 @@ async function downloadAndStageUpdate(options, onStatusUpdate) {
|
|
|
42
38
|
return { status: 'incompatible' };
|
|
43
39
|
}
|
|
44
40
|
if (checkResult.action === 'NOOP') {
|
|
45
|
-
statusCb?.(
|
|
46
|
-
|
|
41
|
+
statusCb?.(checkResult.skippedFailedBundle
|
|
42
|
+
? '✅ Current bundle retained; requested update previously failed on this device'
|
|
43
|
+
: '✅ You have the latest version');
|
|
44
|
+
return checkResult.skippedFailedBundle
|
|
45
|
+
? {
|
|
46
|
+
status: 'upToDate',
|
|
47
|
+
reason: checkResult.reason,
|
|
48
|
+
skippedFailedBundle: true,
|
|
49
|
+
skippedHash: checkResult.skippedHash,
|
|
50
|
+
}
|
|
51
|
+
: { status: 'upToDate' };
|
|
47
52
|
}
|
|
48
53
|
if (checkResult.action === 'ROLLBACK') {
|
|
49
54
|
statusCb?.('↩️ Rollback requested');
|
|
@@ -67,40 +72,35 @@ async function downloadAndStageUpdate(options, onStatusUpdate) {
|
|
|
67
72
|
},
|
|
68
73
|
});
|
|
69
74
|
}
|
|
70
|
-
// Fetch bundle zip from server.
|
|
71
|
-
statusCb?.('⬇️ Downloading full bundle ZIP!...');
|
|
72
|
-
let zipResponse;
|
|
73
|
-
try {
|
|
74
|
-
zipResponse = await axios_cjs_1.default.get(bundleZipUrl, {
|
|
75
|
-
responseType: 'arraybuffer',
|
|
76
|
-
});
|
|
77
|
-
}
|
|
78
|
-
catch (e) {
|
|
79
|
-
throw new errors_1.BundleDropError({
|
|
80
|
-
message: 'Failed to download update ZIP',
|
|
81
|
-
code: 'DOWNLOAD_FAILED',
|
|
82
|
-
step: 'download',
|
|
83
|
-
context: { channelName, platform, url: bundleZipUrl },
|
|
84
|
-
cause: e,
|
|
85
|
-
});
|
|
86
|
-
}
|
|
87
75
|
const hash = serverHash;
|
|
76
|
+
if (await (0, rollbackState_1.isBundleHashFailed)(hash)) {
|
|
77
|
+
statusCb?.('✅ Current bundle retained; selected update previously failed on this device');
|
|
78
|
+
return {
|
|
79
|
+
status: 'upToDate',
|
|
80
|
+
reason: 'BUNDLE_PREVIOUSLY_FAILED',
|
|
81
|
+
skippedFailedBundle: true,
|
|
82
|
+
skippedHash: hash,
|
|
83
|
+
};
|
|
84
|
+
}
|
|
85
|
+
statusCb?.('⬇️ Downloading full bundle ZIP!...');
|
|
88
86
|
let installResult;
|
|
89
87
|
try {
|
|
90
88
|
installResult = await (0, installFromZip_1.installFromZip)({
|
|
91
|
-
|
|
89
|
+
downloadUrl: bundleZipUrl,
|
|
92
90
|
hash,
|
|
93
91
|
platform,
|
|
94
92
|
statusCb,
|
|
95
93
|
});
|
|
96
94
|
}
|
|
97
95
|
catch (e) {
|
|
96
|
+
const phaseErr = (0, errors_1.isInstallPhaseError)(e);
|
|
97
|
+
const isDownload = phaseErr && e.phase === 'download';
|
|
98
98
|
throw new errors_1.BundleDropError({
|
|
99
|
-
message: 'Failed to install update ZIP',
|
|
100
|
-
code: 'INSTALL_FAILED',
|
|
101
|
-
step: 'install',
|
|
99
|
+
message: isDownload ? 'Failed to download update ZIP' : 'Failed to install update ZIP',
|
|
100
|
+
code: isDownload ? 'DOWNLOAD_FAILED' : 'INSTALL_FAILED',
|
|
101
|
+
step: isDownload ? 'download' : 'install',
|
|
102
102
|
context: { channelName, platform, hash },
|
|
103
|
-
cause: e,
|
|
103
|
+
cause: phaseErr ? e.originalCause : e,
|
|
104
104
|
});
|
|
105
105
|
}
|
|
106
106
|
const { bundlePath, metadataFromZip } = installResult;
|
|
@@ -116,6 +116,7 @@ async function downloadAndStageUpdate(options, onStatusUpdate) {
|
|
|
116
116
|
}
|
|
117
117
|
statusCb?.('✅ Update downloaded. Will apply on next launch or when you call applyUpdate().');
|
|
118
118
|
// Persist installed metadata for future skip logic.
|
|
119
|
+
const previousInfo = await (0, bundleInfo_1.readBundleInfo)();
|
|
119
120
|
const installedInfo = {
|
|
120
121
|
bundleVersion: serverBundleVersion ?? metadataFromZip.bundleVersion,
|
|
121
122
|
version: serverVersion ?? metadataFromZip.version,
|
|
@@ -125,6 +126,7 @@ async function downloadAndStageUpdate(options, onStatusUpdate) {
|
|
|
125
126
|
installedAt: new Date().toISOString(),
|
|
126
127
|
pendingApply: true,
|
|
127
128
|
runtimeVersion: metadataFromZip.runtimeVersion ?? serverRuntimeVersion ?? context_1.runtimeVersion ?? undefined,
|
|
129
|
+
lastInstalledReportedHash: previousInfo?.lastInstalledReportedHash,
|
|
128
130
|
};
|
|
129
131
|
await (0, bundleInfo_1.writeBundleInfo)(installedInfo);
|
|
130
132
|
await (0, bundlePointer_1.setCurrentBundlePointer)(bundlePath, installedHash);
|
|
@@ -1,5 +1,7 @@
|
|
|
1
1
|
import { BundleInfo } from '../bundleInfo';
|
|
2
|
+
import type { FailedBundleRecord } from './rollbackState';
|
|
2
3
|
export declare function reportInstalledIfReady(state?: {
|
|
3
4
|
hasBundle?: boolean;
|
|
4
5
|
info?: BundleInfo | null;
|
|
5
6
|
}): Promise<void>;
|
|
7
|
+
export declare function reportLocalRollback(hash: string, record: FailedBundleRecord): Promise<void>;
|
package/lib/manager/reporting.js
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.reportInstalledIfReady = reportInstalledIfReady;
|
|
4
|
+
exports.reportLocalRollback = reportLocalRollback;
|
|
4
5
|
const context_1 = require("../context");
|
|
5
6
|
const bundleInfo_1 = require("../bundleInfo");
|
|
6
7
|
const clientApi_1 = require("../api/clientApi");
|
|
@@ -33,13 +34,13 @@ async function reportInstalledIfReady(state) {
|
|
|
33
34
|
(0, installId_1.getOrCreateInstallId)(),
|
|
34
35
|
(0, userProperties_1.getCurrentUserProperties)(),
|
|
35
36
|
]);
|
|
36
|
-
const
|
|
37
|
+
const appEnvironment = (0, initState_1.getBundleDropRuntimeConfig)()?.environment ?? null;
|
|
37
38
|
await (0, clientApi_1.reportInstalled)(context_1.config.project.slug, info.hash, {
|
|
38
39
|
channelName: info.channelName,
|
|
39
40
|
platform: info.platform,
|
|
40
41
|
installId,
|
|
41
42
|
runtimeVersion: info.runtimeVersion ?? context_1.runtimeVersion ?? null,
|
|
42
|
-
environment,
|
|
43
|
+
environment: appEnvironment,
|
|
43
44
|
userProperties: Object.keys(userProperties).length > 0 ? userProperties : undefined,
|
|
44
45
|
});
|
|
45
46
|
await (0, bundleInfo_1.updateBundleInfo)({ lastInstalledReportedHash: info.hash });
|
|
@@ -48,3 +49,27 @@ async function reportInstalledIfReady(state) {
|
|
|
48
49
|
console.warn('⚠️ Failed to report bundle install:', e?.toString?.() || e);
|
|
49
50
|
}
|
|
50
51
|
}
|
|
52
|
+
async function reportLocalRollback(hash, record) {
|
|
53
|
+
try {
|
|
54
|
+
const [installId, userProperties] = await Promise.all([
|
|
55
|
+
(0, installId_1.getOrCreateInstallId)(),
|
|
56
|
+
(0, userProperties_1.getCurrentUserProperties)(),
|
|
57
|
+
]);
|
|
58
|
+
const appEnvironment = (0, initState_1.getBundleDropRuntimeConfig)()?.environment ?? null;
|
|
59
|
+
await (0, clientApi_1.reportLocalRollback)(context_1.config.project.slug, hash, {
|
|
60
|
+
reason: record.reason,
|
|
61
|
+
previousHash: record.previousHash ?? null,
|
|
62
|
+
channelName: record.channelName ?? null,
|
|
63
|
+
platform: context_1.platform,
|
|
64
|
+
installId,
|
|
65
|
+
runtimeVersion: record.runtimeVersion ?? context_1.runtimeVersion ?? null,
|
|
66
|
+
environment: appEnvironment,
|
|
67
|
+
userProperties: Object.keys(userProperties).length > 0 ? userProperties : undefined,
|
|
68
|
+
crashCount: record.crashCount ?? null,
|
|
69
|
+
failedAt: record.failedAt ? new Date(record.failedAt * 1000).toISOString() : null,
|
|
70
|
+
});
|
|
71
|
+
}
|
|
72
|
+
catch (e) {
|
|
73
|
+
console.warn('⚠️ Failed to report local rollback:', e?.toString?.() || e);
|
|
74
|
+
}
|
|
75
|
+
}
|