@gfean/react-native-bundle-drop 0.4.6 → 0.6.0
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/README.md +168 -4
- package/android/build.gradle +1 -0
- package/android/src/main/java/com/bundledrop/BundleDropBoundedDownloader.kt +86 -0
- package/android/src/main/java/com/bundledrop/BundleDropModule.kt +69 -0
- package/android/src/main/java/com/bundledrop/BundleDropRuntimeCrypto.kt +81 -0
- package/ios/BundleDropBridge.m +18 -0
- package/ios/BundleDropLocator.swift +48 -2
- package/ios/BundleDropModule.swift +75 -0
- package/ios/BundleDropRuntimeCrypto.swift +45 -0
- package/lib/CLI/cli.d.ts +1 -0
- package/lib/CLI/cli.js +166 -79
- package/lib/CLI/scripts/aipowered/apply-setup-plan.js +7 -17
- package/lib/CLI/scripts/aipowered/backend-client.js +29 -4
- package/lib/CLI/scripts/aipowered/code-push-residue.d.ts +5 -0
- package/lib/CLI/scripts/aipowered/code-push-residue.js +126 -0
- package/lib/CLI/scripts/aipowered/credential-safety.d.ts +1 -0
- package/lib/CLI/scripts/aipowered/credential-safety.js +14 -0
- package/lib/CLI/scripts/aipowered/diff-preview.js +12 -4
- package/lib/CLI/scripts/aipowered/init-project-config.d.ts +4 -0
- package/lib/CLI/scripts/aipowered/init-project-config.js +228 -43
- package/lib/CLI/scripts/aipowered/scanner.d.ts +1 -0
- package/lib/CLI/scripts/aipowered/scanner.js +164 -32
- package/lib/CLI/scripts/aipowered/terminal-safety.d.ts +4 -0
- package/lib/CLI/scripts/aipowered/terminal-safety.js +124 -0
- package/lib/CLI/scripts/aipowered/validate-plan.d.ts +3 -0
- package/lib/CLI/scripts/aipowered/validate-plan.js +1080 -19
- package/lib/CLI/scripts/bare-metro-config.d.ts +1 -1
- package/lib/CLI/scripts/bare-metro-config.js +24 -32
- package/lib/CLI/scripts/doctor.js +143 -22
- package/lib/CLI/scripts/expo/configure-expo.js +51 -60
- package/lib/CLI/scripts/expo/package-manager.d.ts +2 -0
- package/lib/CLI/scripts/expo/package-manager.js +63 -25
- package/lib/CLI/scripts/init-config.d.ts +7 -7
- package/lib/CLI/scripts/init-config.js +246 -32
- package/lib/CLI/scripts/login-cli.js +35 -10
- package/lib/CLI/scripts/metro-config-authority.d.ts +8 -0
- package/lib/CLI/scripts/metro-config-authority.js +303 -0
- package/lib/CLI/scripts/native-entrypoint-authority.d.ts +2 -0
- package/lib/CLI/scripts/native-entrypoint-authority.js +378 -0
- package/lib/CLI/scripts/native-setup-contract.d.ts +2 -2
- package/lib/CLI/scripts/native-setup-contract.js +63 -33
- package/lib/CLI/scripts/native-startup-validator.d.ts +3 -0
- package/lib/CLI/scripts/native-startup-validator.js +964 -0
- package/lib/CLI/scripts/safe-file-transaction.d.ts +12 -0
- package/lib/CLI/scripts/safe-file-transaction.js +159 -0
- package/lib/CLI/scripts/sight-artifacts.d.ts +17 -0
- package/lib/CLI/scripts/sight-artifacts.js +204 -0
- package/lib/CLI/scripts/sight-cli.d.ts +10 -0
- package/lib/CLI/scripts/sight-cli.js +127 -0
- package/lib/CLI/scripts/sight-session.d.ts +14 -0
- package/lib/CLI/scripts/sight-session.js +192 -0
- package/lib/api/clientApi.d.ts +3 -1
- package/lib/api/clientApi.js +14 -0
- package/lib/api/types.d.ts +39 -0
- package/lib/context.d.ts +1 -1
- package/lib/index.d.ts +2 -0
- package/lib/index.js +3 -1
- package/lib/install/installFromZip.d.ts +3 -0
- package/lib/install/installFromZip.js +10 -1
- package/lib/loadConfig.d.ts +17 -1
- package/lib/loadConfig.js +16 -0
- package/lib/manager/downloadAndInstall.d.ts +3 -2
- package/lib/manager/downloadAndInstall.js +111 -46
- package/lib/manager/rollbackState.d.ts +3 -1
- package/lib/manager/rollbackState.js +2 -2
- package/lib/manager/updateCheck.d.ts +1 -0
- package/lib/manager/updateCheck.js +218 -78
- package/lib/metro.d.ts +8 -1
- package/lib/metro.js +68 -19
- package/lib/native/bundleDropNative.js +2 -1
- package/lib/native/fs.d.ts +6 -0
- package/lib/native/fs.js +24 -0
- package/lib/patch-engine/installFromPatchSet.d.ts +2 -0
- package/lib/patch-engine/installFromPatchSet.js +14 -3
- package/lib/patch-engine/patchTransport.d.ts +2 -0
- package/lib/patch-engine/patchTransport.js +9 -0
- package/lib/runtime/initState.d.ts +5 -0
- package/lib/runtime/initState.js +4 -0
- package/lib/runtime/service.js +60 -3
- package/lib/runtime-delivery/artifactCapability.d.ts +1 -0
- package/lib/runtime-delivery/artifactCapability.js +32 -0
- package/lib/runtime-delivery/authorityLeaseVerifier.d.ts +3 -0
- package/lib/runtime-delivery/authorityLeaseVerifier.js +106 -0
- package/lib/runtime-delivery/bootstrapConfig.d.ts +50 -0
- package/lib/runtime-delivery/bootstrapConfig.js +217 -0
- package/lib/runtime-delivery/diagnostics.d.ts +17 -0
- package/lib/runtime-delivery/diagnostics.js +58 -0
- package/lib/runtime-delivery/encoding.d.ts +5 -0
- package/lib/runtime-delivery/encoding.js +132 -0
- package/lib/runtime-delivery/heartbeat.d.ts +3 -0
- package/lib/runtime-delivery/heartbeat.js +88 -0
- package/lib/runtime-delivery/localResolver.d.ts +23 -0
- package/lib/runtime-delivery/localResolver.js +81 -0
- package/lib/runtime-delivery/manifestState.d.ts +9 -0
- package/lib/runtime-delivery/manifestState.js +102 -0
- package/lib/runtime-delivery/manifestVerifier.d.ts +13 -0
- package/lib/runtime-delivery/manifestVerifier.js +329 -0
- package/lib/runtime-delivery/runtimeDelivery.d.ts +19 -0
- package/lib/runtime-delivery/runtimeDelivery.js +375 -0
- package/lib/runtime-delivery/types.d.ts +87 -0
- package/lib/runtime-delivery/types.js +6 -0
- package/package.json +2 -2
|
@@ -174,14 +174,14 @@ async function rollbackToPreviousIfNeeded(policy, cached) {
|
|
|
174
174
|
function getRollbackPolicy() {
|
|
175
175
|
return context_1.bundleDropConfig.rollback;
|
|
176
176
|
}
|
|
177
|
-
async function rollbackToPreviousOrNative() {
|
|
177
|
+
async function rollbackToPreviousOrNative(options = {}) {
|
|
178
178
|
const [current, previous, state] = await Promise.all([
|
|
179
179
|
(0, bundlePointer_1.readCurrentBundlePointer)(),
|
|
180
180
|
(0, bundlePointer_1.readPreviousBundlePointer)(),
|
|
181
181
|
readState(),
|
|
182
182
|
]);
|
|
183
183
|
const previousIsFailed = previous ? !!state?.failedBundles?.[previous.hash] : false;
|
|
184
|
-
if (previous && previous.hash !== current?.hash && !previousIsFailed) {
|
|
184
|
+
if (!options.forceNative && previous && previous.hash !== current?.hash && !previousIsFailed) {
|
|
185
185
|
await (0, bundlePointer_1.writeCurrentBundlePointer)({ ...previous, updatedAt: new Date().toISOString() });
|
|
186
186
|
const metadata = await readBundleMetadata(previous.bundlePath);
|
|
187
187
|
await (0, bundleInfo_1.updateBundleInfo)({
|
|
@@ -2,6 +2,7 @@ import { BundleInfo } from '../bundleInfo';
|
|
|
2
2
|
import type { UpdateCheckResponse, BundleListItem } from '../api/types';
|
|
3
3
|
export declare function getAvailableChannels(): Promise<string[]>;
|
|
4
4
|
export declare function checkForUpdate(channelName?: string, onStatusUpdate?: (status: string) => void): Promise<UpdateCheckResponse | null>;
|
|
5
|
+
export declare function authorizeRuntimeDeliveryUpdate(decision: UpdateCheckResponse): Promise<UpdateCheckResponse | null>;
|
|
5
6
|
export declare function getInstalledBundleInfo(): Promise<BundleInfo | null>;
|
|
6
7
|
/**
|
|
7
8
|
* Query options for browsing downloadable bundles from a public channel.
|
|
@@ -35,6 +35,7 @@ var __importStar = (this && this.__importStar) || (function () {
|
|
|
35
35
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
36
36
|
exports.getAvailableChannels = getAvailableChannels;
|
|
37
37
|
exports.checkForUpdate = checkForUpdate;
|
|
38
|
+
exports.authorizeRuntimeDeliveryUpdate = authorizeRuntimeDeliveryUpdate;
|
|
38
39
|
exports.getInstalledBundleInfo = getInstalledBundleInfo;
|
|
39
40
|
exports.getAvailableBundles = getAvailableBundles;
|
|
40
41
|
const context_1 = require("../context");
|
|
@@ -48,6 +49,11 @@ const initState_1 = require("../runtime/initState");
|
|
|
48
49
|
const rollbackState_1 = require("./rollbackState");
|
|
49
50
|
const bundleDropNative_1 = require("../native/bundleDropNative");
|
|
50
51
|
const patchOperations_1 = require("../patch-engine/patchOperations");
|
|
52
|
+
const runtimeDelivery_1 = require("../runtime-delivery/runtimeDelivery");
|
|
53
|
+
const diagnostics_1 = require("../runtime-delivery/diagnostics");
|
|
54
|
+
const manifestVerifier_1 = require("../runtime-delivery/manifestVerifier");
|
|
55
|
+
const loadConfig_1 = require("../loadConfig");
|
|
56
|
+
const ACTIVE_INSTALL_HEARTBEAT_VERSION = 1;
|
|
51
57
|
function assertInstallDecisionShape(decision) {
|
|
52
58
|
const { target } = decision;
|
|
53
59
|
if (!target?.bundleHash) {
|
|
@@ -99,97 +105,231 @@ async function getAvailableChannels() {
|
|
|
99
105
|
throw e;
|
|
100
106
|
}
|
|
101
107
|
}
|
|
108
|
+
async function readResolveContext(channelName) {
|
|
109
|
+
const [currentPtr, nativeBundlePath, userProperties, installId, rejectedHashes] = await Promise.all([
|
|
110
|
+
(0, bundlePointer_1.readCurrentBundlePointer)(),
|
|
111
|
+
(0, bundleDropNative_1.getDownloadedBundlePathNative)(),
|
|
112
|
+
(0, userProperties_1.getCurrentUserProperties)(),
|
|
113
|
+
(0, installId_1.getOrCreateInstallId)(),
|
|
114
|
+
(0, rollbackState_1.getFailedBundleHashes)(),
|
|
115
|
+
]);
|
|
116
|
+
const supportsXdelta = await Promise.resolve().then(() => __importStar(require('../native/fs'))).then(module => module.default.supportsXdelta())
|
|
117
|
+
.catch(() => false);
|
|
118
|
+
return {
|
|
119
|
+
channelName,
|
|
120
|
+
currentHash: nativeBundlePath && currentPtr?.hash ? currentPtr.hash : null,
|
|
121
|
+
rejectedHashes,
|
|
122
|
+
installId,
|
|
123
|
+
patchAlgorithms: (0, patchOperations_1.advertisedPatchAlgorithms)(supportsXdelta),
|
|
124
|
+
supportsContentAddressedAssets: true,
|
|
125
|
+
environment: (0, initState_1.getBundleDropRuntimeConfig)()?.environment ?? null,
|
|
126
|
+
userProperties,
|
|
127
|
+
};
|
|
128
|
+
}
|
|
129
|
+
async function mapServerDecision(decision, channelName, onStatusUpdate) {
|
|
130
|
+
if (decision.action === 'NOOP') {
|
|
131
|
+
const incompatible = decision.reason === 'NO_COMPATIBLE_BUNDLE';
|
|
132
|
+
onStatusUpdate?.(incompatible
|
|
133
|
+
? '⛔️ No compatible update for this binary'
|
|
134
|
+
: '✅ You have the latest version');
|
|
135
|
+
return {
|
|
136
|
+
action: 'NOOP',
|
|
137
|
+
upToDate: !incompatible,
|
|
138
|
+
channelName,
|
|
139
|
+
reason: decision.reason,
|
|
140
|
+
incompatible: incompatible || undefined,
|
|
141
|
+
requestedRuntimeVersion: decision.requestedRuntimeVersion,
|
|
142
|
+
latestRuntimeVersionOnChannel: decision.latestRuntimeVersionOnChannel,
|
|
143
|
+
};
|
|
144
|
+
}
|
|
145
|
+
if (decision.action === 'ROLLBACK') {
|
|
146
|
+
onStatusUpdate?.('↩️ Rollback requested');
|
|
147
|
+
return { action: 'ROLLBACK', channelName, reason: decision.reason };
|
|
148
|
+
}
|
|
149
|
+
assertInstallDecisionShape(decision);
|
|
150
|
+
const targetHash = decision.target.bundleHash;
|
|
151
|
+
if (await (0, rollbackState_1.isBundleHashFailed)(targetHash)) {
|
|
152
|
+
onStatusUpdate?.('✅ Current bundle retained; latest update previously failed on this device');
|
|
153
|
+
return {
|
|
154
|
+
action: 'NOOP',
|
|
155
|
+
upToDate: false,
|
|
156
|
+
channelName,
|
|
157
|
+
reason: 'BUNDLE_PREVIOUSLY_FAILED',
|
|
158
|
+
skippedFailedBundle: true,
|
|
159
|
+
skippedHash: targetHash,
|
|
160
|
+
};
|
|
161
|
+
}
|
|
162
|
+
onStatusUpdate?.('⬇️ Update available');
|
|
163
|
+
return {
|
|
164
|
+
action: 'INSTALL',
|
|
165
|
+
upToDate: false,
|
|
166
|
+
channelName,
|
|
167
|
+
hash: targetHash,
|
|
168
|
+
bundleHash: targetHash,
|
|
169
|
+
mode: decision.mode,
|
|
170
|
+
baseHash: decision.mode === 'patch' ? decision.baseHash : undefined,
|
|
171
|
+
patchSet: decision.mode === 'patch' ? decision.patchSet : undefined,
|
|
172
|
+
fallback: decision.mode === 'patch' ? decision.fallback : undefined,
|
|
173
|
+
downloadUrl: decision.target.downloadUrl,
|
|
174
|
+
manifestUrl: decision.target.manifestUrl,
|
|
175
|
+
bundleVersion: decision.target.bundleVersion,
|
|
176
|
+
version: decision.target.version,
|
|
177
|
+
runtimeVersion: decision.target.runtimeVersion,
|
|
178
|
+
};
|
|
179
|
+
}
|
|
180
|
+
async function resolveWithServer(context, onStatusUpdate, options = {}) {
|
|
181
|
+
const response = await (0, clientApi_1.postOtaResolve)(context_1.config.project.slug, {
|
|
182
|
+
channelName: context.channelName,
|
|
183
|
+
platform: context_1.platform,
|
|
184
|
+
runtimeVersion: context_1.runtimeVersion ?? null,
|
|
185
|
+
environment: context.environment,
|
|
186
|
+
currentHash: context.currentHash,
|
|
187
|
+
currentUserProperties: context.userProperties,
|
|
188
|
+
rejectedHashes: context.rejectedHashes,
|
|
189
|
+
installId: context.installId,
|
|
190
|
+
transport: {
|
|
191
|
+
manifestVersion: 1,
|
|
192
|
+
patchAlgorithms: context.patchAlgorithms,
|
|
193
|
+
supportsContentAddressedAssets: context.supportsContentAddressedAssets,
|
|
194
|
+
...(options.activeInstallHeartbeatVersion
|
|
195
|
+
? { activeInstallHeartbeatVersion: options.activeInstallHeartbeatVersion }
|
|
196
|
+
: {}),
|
|
197
|
+
},
|
|
198
|
+
});
|
|
199
|
+
return mapServerDecision(response.data, context.channelName, onStatusUpdate);
|
|
200
|
+
}
|
|
201
|
+
function emitLocalDecisionStatus(decision, onStatusUpdate) {
|
|
202
|
+
if (decision.action === 'INSTALL')
|
|
203
|
+
onStatusUpdate?.('⬇️ Update available');
|
|
204
|
+
else if (decision.action === 'ROLLBACK')
|
|
205
|
+
onStatusUpdate?.('↩️ Rollback requested');
|
|
206
|
+
else
|
|
207
|
+
onStatusUpdate?.('✅ You have the latest version');
|
|
208
|
+
}
|
|
102
209
|
async function checkForUpdate(channelName = context_2.defaultChannel, onStatusUpdate) {
|
|
103
|
-
|
|
210
|
+
if (!context_1.config.project?.slug) {
|
|
211
|
+
const error = new Error('Missing project slug in bundle.drop.config.js');
|
|
212
|
+
console.warn('⚠️ checkForUpdate failed:', error.toString());
|
|
213
|
+
return null;
|
|
214
|
+
}
|
|
215
|
+
onStatusUpdate?.('🔍 Checking for updates...');
|
|
216
|
+
let context = null;
|
|
104
217
|
try {
|
|
105
|
-
|
|
106
|
-
|
|
218
|
+
context = await readResolveContext(channelName);
|
|
219
|
+
if (!(0, loadConfig_1.isRuntimeDeliveryConfigured)(context_1.config.runtimeDelivery) || !context_1.runtimeVersion) {
|
|
220
|
+
return await resolveWithServer(context, onStatusUpdate);
|
|
107
221
|
}
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
(0,
|
|
111
|
-
(
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
222
|
+
(0, runtimeDelivery_1.reportActiveInstall)(context);
|
|
223
|
+
try {
|
|
224
|
+
const manifest = await (0, runtimeDelivery_1.fetchRuntimeDeliveryManifest)(channelName);
|
|
225
|
+
if (manifest.resolutionMode === 'dynamic') {
|
|
226
|
+
(0, diagnostics_1.recordRuntimeDeliveryDiagnostic)('origin_fallback', {
|
|
227
|
+
channelName,
|
|
228
|
+
reason: `dynamic:${manifest.dynamicReason ?? 'unspecified'}`,
|
|
229
|
+
});
|
|
230
|
+
return await resolveWithServer(context, onStatusUpdate, {
|
|
231
|
+
activeInstallHeartbeatVersion: ACTIVE_INSTALL_HEARTBEAT_VERSION,
|
|
232
|
+
});
|
|
233
|
+
}
|
|
234
|
+
const local = await (0, runtimeDelivery_1.resolveFromRuntimeDeliveryManifest)(manifest, context);
|
|
235
|
+
emitLocalDecisionStatus(local, onStatusUpdate);
|
|
236
|
+
return local;
|
|
237
|
+
}
|
|
238
|
+
catch (manifestError) {
|
|
239
|
+
(0, diagnostics_1.recordRuntimeDeliveryDiagnostic)('origin_fallback', {
|
|
240
|
+
channelName,
|
|
241
|
+
reason: manifestError instanceof manifestVerifier_1.RuntimeDeliveryManifestError
|
|
242
|
+
? manifestError.code
|
|
243
|
+
: 'manifest_error',
|
|
244
|
+
});
|
|
245
|
+
console.warn('[BundleDrop] manifest delivery unavailable; falling back to /resolve:', manifestError);
|
|
246
|
+
return await resolveWithServer(context, onStatusUpdate, {
|
|
247
|
+
activeInstallHeartbeatVersion: ACTIVE_INSTALL_HEARTBEAT_VERSION,
|
|
248
|
+
});
|
|
249
|
+
}
|
|
250
|
+
}
|
|
251
|
+
catch (error) {
|
|
252
|
+
if ((0, loadConfig_1.isRuntimeDeliveryConfigured)(context_1.config.runtimeDelivery) &&
|
|
253
|
+
context &&
|
|
254
|
+
await (0, runtimeDelivery_1.shouldRollbackFromLastKnownRevocations)(channelName, context.currentHash).catch(() => false)) {
|
|
255
|
+
onStatusUpdate?.('↩️ Rollback requested');
|
|
256
|
+
return {
|
|
257
|
+
action: 'ROLLBACK',
|
|
258
|
+
channelName,
|
|
259
|
+
reason: 'CURRENT_REVOKED_ORIGIN_UNAVAILABLE',
|
|
260
|
+
};
|
|
261
|
+
}
|
|
262
|
+
console.warn('⚠️ checkForUpdate failed:', error?.toString?.() || error);
|
|
263
|
+
return null;
|
|
264
|
+
}
|
|
265
|
+
}
|
|
266
|
+
async function authorizeRuntimeDeliveryUpdate(decision) {
|
|
267
|
+
if (decision.action !== 'INSTALL' || !decision.runtimeDelivery || !decision.channelName) {
|
|
268
|
+
return decision;
|
|
269
|
+
}
|
|
270
|
+
const context = await readResolveContext(decision.channelName);
|
|
271
|
+
try {
|
|
272
|
+
if (!context_1.runtimeVersion)
|
|
273
|
+
throw new Error('Runtime version is required for artifact authorization');
|
|
274
|
+
const response = await (0, clientApi_1.postOtaArtifactAuthorization)(context_1.config.project.slug, {
|
|
275
|
+
channelName: decision.channelName,
|
|
122
276
|
platform: context_1.platform,
|
|
123
|
-
runtimeVersion: context_1.runtimeVersion
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
277
|
+
runtimeVersion: context_1.runtimeVersion,
|
|
278
|
+
generation: decision.runtimeDelivery.generation,
|
|
279
|
+
targetReleaseRef: decision.runtimeDelivery.targetReleaseRef,
|
|
280
|
+
targetHash: decision.hash,
|
|
281
|
+
mode: decision.runtimeDelivery.selectedMode,
|
|
282
|
+
patchArtifactRef: decision.runtimeDelivery.patchArtifactRef ?? null,
|
|
283
|
+
currentHash: context.currentHash,
|
|
284
|
+
rejectedHashes: context.rejectedHashes,
|
|
285
|
+
installId: context.installId,
|
|
129
286
|
transport: {
|
|
130
287
|
manifestVersion: 1,
|
|
131
|
-
patchAlgorithms:
|
|
132
|
-
supportsContentAddressedAssets:
|
|
288
|
+
patchAlgorithms: context.patchAlgorithms,
|
|
289
|
+
supportsContentAddressedAssets: context.supportsContentAddressedAssets,
|
|
133
290
|
},
|
|
134
291
|
});
|
|
135
|
-
const
|
|
136
|
-
if (
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
onStatusUpdate?.('⛔️ No compatible update for this binary');
|
|
292
|
+
const authorized = await mapServerDecision(response.data, decision.channelName);
|
|
293
|
+
if (authorized.action === 'INSTALL') {
|
|
294
|
+
if (authorized.hash !== decision.hash || authorized.runtimeVersion !== context_1.runtimeVersion) {
|
|
295
|
+
throw new Error('Artifact authorization returned a different target identity');
|
|
140
296
|
}
|
|
141
|
-
|
|
142
|
-
|
|
297
|
+
const selection = decision.runtimeDelivery;
|
|
298
|
+
if (authorized.mode === 'patch') {
|
|
299
|
+
if (selection.selectedMode !== 'patch' ||
|
|
300
|
+
authorized.baseHash !== selection.baseHash ||
|
|
301
|
+
authorized.patchSet?.algorithm !== selection.patchAlgorithm ||
|
|
302
|
+
authorized.patchSet.patchSetHash !== selection.patchSetHash ||
|
|
303
|
+
(authorized.patchSet.assets?.missingAssetsHash ?? null) !==
|
|
304
|
+
(selection.missingAssetsHash ?? null)) {
|
|
305
|
+
throw new Error('Artifact authorization returned an unsafe patch selection');
|
|
306
|
+
}
|
|
143
307
|
}
|
|
144
|
-
return {
|
|
145
|
-
action: 'NOOP',
|
|
146
|
-
upToDate: !incompatible,
|
|
147
|
-
channelName,
|
|
148
|
-
reason: decision.reason,
|
|
149
|
-
incompatible: incompatible || undefined,
|
|
150
|
-
requestedRuntimeVersion: decision.requestedRuntimeVersion,
|
|
151
|
-
latestRuntimeVersionOnChannel: decision.latestRuntimeVersionOnChannel,
|
|
152
|
-
};
|
|
308
|
+
return { ...authorized, runtimeDelivery: selection };
|
|
153
309
|
}
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
310
|
+
return authorized;
|
|
311
|
+
}
|
|
312
|
+
catch (error) {
|
|
313
|
+
(0, diagnostics_1.recordRuntimeDeliveryDiagnostic)('origin_fallback', {
|
|
314
|
+
channelName: decision.channelName,
|
|
315
|
+
reason: 'artifact_authorization_failed',
|
|
316
|
+
});
|
|
317
|
+
console.warn('[BundleDrop] artifact authorization failed; falling back to /resolve:', error);
|
|
318
|
+
try {
|
|
319
|
+
return await resolveWithServer(context, undefined, {
|
|
320
|
+
activeInstallHeartbeatVersion: ACTIVE_INSTALL_HEARTBEAT_VERSION,
|
|
321
|
+
});
|
|
157
322
|
}
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
reason: 'BUNDLE_PREVIOUSLY_FAILED',
|
|
168
|
-
skippedFailedBundle: true,
|
|
169
|
-
skippedHash: targetHash,
|
|
170
|
-
};
|
|
323
|
+
catch {
|
|
324
|
+
if (await (0, runtimeDelivery_1.shouldRollbackFromLastKnownRevocations)(decision.channelName, context.currentHash).catch(() => false)) {
|
|
325
|
+
return {
|
|
326
|
+
action: 'ROLLBACK',
|
|
327
|
+
channelName: decision.channelName,
|
|
328
|
+
reason: 'CURRENT_REVOKED_ORIGIN_UNAVAILABLE',
|
|
329
|
+
};
|
|
330
|
+
}
|
|
331
|
+
return null;
|
|
171
332
|
}
|
|
172
|
-
onStatusUpdate?.('⬇️ Update available');
|
|
173
|
-
return {
|
|
174
|
-
action: 'INSTALL',
|
|
175
|
-
upToDate: false,
|
|
176
|
-
channelName,
|
|
177
|
-
hash: targetHash,
|
|
178
|
-
bundleHash: targetHash,
|
|
179
|
-
mode: decision.mode,
|
|
180
|
-
baseHash: decision.mode === 'patch' ? decision.baseHash : undefined,
|
|
181
|
-
patchSet: decision.mode === 'patch' ? decision.patchSet : undefined,
|
|
182
|
-
fallback: decision.mode === 'patch' ? decision.fallback : undefined,
|
|
183
|
-
downloadUrl: decision.target.downloadUrl,
|
|
184
|
-
manifestUrl: decision.target.manifestUrl,
|
|
185
|
-
bundleVersion: decision.target.bundleVersion,
|
|
186
|
-
version: decision.target.version,
|
|
187
|
-
runtimeVersion: decision.target.runtimeVersion,
|
|
188
|
-
};
|
|
189
|
-
}
|
|
190
|
-
catch (e) {
|
|
191
|
-
console.warn('⚠️ checkForUpdate failed:', e?.toString?.() || e);
|
|
192
|
-
return null;
|
|
193
333
|
}
|
|
194
334
|
}
|
|
195
335
|
async function getInstalledBundleInfo() {
|
package/lib/metro.d.ts
CHANGED
|
@@ -6,9 +6,16 @@ export type BundleDropMetroConfig = {
|
|
|
6
6
|
};
|
|
7
7
|
[key: string]: unknown;
|
|
8
8
|
};
|
|
9
|
-
export type
|
|
9
|
+
export type WithBundleDropOptions = {
|
|
10
10
|
projectRoot?: string;
|
|
11
11
|
};
|
|
12
|
+
export type WithBundleDropExpoOptions = WithBundleDropOptions;
|
|
13
|
+
/**
|
|
14
|
+
* Preserves a bare React Native Metro config and resolves Bundle Drop through
|
|
15
|
+
* the project-owned, package-validated generated bootstrap.
|
|
16
|
+
*/
|
|
17
|
+
export declare function withBundleDrop<T extends BundleDropMetroConfig>(config: T, options?: WithBundleDropOptions): T;
|
|
18
|
+
export declare const withBundleDropBare: typeof withBundleDrop;
|
|
12
19
|
/**
|
|
13
20
|
* Preserves the caller's Expo Metro config and only adds Bundle Drop's config
|
|
14
21
|
* alias after resolving the same concrete identity used by build and upload.
|
package/lib/metro.js
CHANGED
|
@@ -3,34 +3,87 @@ 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.withBundleDropBare = void 0;
|
|
7
|
+
exports.withBundleDrop = withBundleDrop;
|
|
6
8
|
exports.withBundleDropExpo = withBundleDropExpo;
|
|
7
9
|
const fs_extra_1 = __importDefault(require("fs-extra"));
|
|
8
10
|
const path_1 = __importDefault(require("path"));
|
|
9
11
|
const expo_1 = require("./expo");
|
|
12
|
+
const bootstrapConfig_1 = require("./runtime-delivery/bootstrapConfig");
|
|
13
|
+
const loadBaseConfig = (projectRoot) => {
|
|
14
|
+
const configPath = path_1.default.join(projectRoot, 'bundle.drop.config.js');
|
|
15
|
+
if (!fs_extra_1.default.existsSync(configPath)) {
|
|
16
|
+
throw new Error('Bundle Drop Metro setup requires bundle.drop.config.js in the project root.');
|
|
17
|
+
}
|
|
18
|
+
delete require.cache[require.resolve(configPath)];
|
|
19
|
+
// eslint-disable-next-line @typescript-eslint/no-var-requires
|
|
20
|
+
const config = require(configPath);
|
|
21
|
+
if (!config?.serverUrl || !config.org?.slug || !config.project?.slug) {
|
|
22
|
+
throw new Error('bundle.drop.config.js must define serverUrl, org.slug, and project.slug before Metro setup.');
|
|
23
|
+
}
|
|
24
|
+
return config;
|
|
25
|
+
};
|
|
26
|
+
const resolveRuntimeDelivery = (projectRoot, baseConfig) => {
|
|
27
|
+
const generated = (0, bootstrapConfig_1.readGeneratedRuntimeDeliveryBootstrap)({
|
|
28
|
+
projectRoot,
|
|
29
|
+
expectedIdentity: {
|
|
30
|
+
serverUrl: baseConfig.serverUrl,
|
|
31
|
+
orgSlug: baseConfig.org.slug,
|
|
32
|
+
projectSlug: baseConfig.project.slug,
|
|
33
|
+
},
|
|
34
|
+
});
|
|
35
|
+
return generated?.runtimeDelivery;
|
|
36
|
+
};
|
|
10
37
|
const writeGeneratedRuntimeConfig = (params) => {
|
|
11
38
|
const generatedDirectory = path_1.default.join(params.projectRoot, '.bundle-drop', 'generated');
|
|
12
39
|
const generatedConfigPath = path_1.default.join(generatedDirectory, 'bundle.drop.config.js');
|
|
13
40
|
fs_extra_1.default.ensureDirSync(generatedDirectory);
|
|
14
|
-
const
|
|
15
|
-
if (
|
|
16
|
-
|
|
41
|
+
const generatedFields = [];
|
|
42
|
+
if (params.runtimeVersion) {
|
|
43
|
+
generatedFields.push(` runtimeVersion: ${JSON.stringify(params.runtimeVersion)},`);
|
|
44
|
+
}
|
|
45
|
+
if (params.runtimeDelivery) {
|
|
46
|
+
generatedFields.push(` runtimeDelivery: ${JSON.stringify(params.runtimeDelivery)},`);
|
|
17
47
|
}
|
|
18
48
|
const content = [
|
|
19
49
|
"'use strict';",
|
|
20
50
|
'',
|
|
21
51
|
"const baseConfig = require('../../bundle.drop.config.js');",
|
|
52
|
+
'const resolvedConfig = { ...baseConfig };',
|
|
53
|
+
'delete resolvedConfig.runtimeDelivery;',
|
|
22
54
|
'module.exports = {',
|
|
23
|
-
' ...
|
|
24
|
-
|
|
25
|
-
ios: params.ios,
|
|
26
|
-
android: params.android,
|
|
27
|
-
})},`,
|
|
55
|
+
' ...resolvedConfig,',
|
|
56
|
+
...generatedFields,
|
|
28
57
|
'};',
|
|
29
58
|
'',
|
|
30
59
|
].join('\n');
|
|
31
60
|
fs_extra_1.default.writeFileSync(generatedConfigPath, content, 'utf8');
|
|
32
61
|
return generatedConfigPath;
|
|
33
62
|
};
|
|
63
|
+
const mergeMetroAlias = (config, generatedConfigPath) => ({
|
|
64
|
+
...config,
|
|
65
|
+
resolver: {
|
|
66
|
+
...(config.resolver || {}),
|
|
67
|
+
extraNodeModules: {
|
|
68
|
+
...(config.resolver?.extraNodeModules || {}),
|
|
69
|
+
'bundle-drop-config': generatedConfigPath,
|
|
70
|
+
},
|
|
71
|
+
},
|
|
72
|
+
});
|
|
73
|
+
/**
|
|
74
|
+
* Preserves a bare React Native Metro config and resolves Bundle Drop through
|
|
75
|
+
* the project-owned, package-validated generated bootstrap.
|
|
76
|
+
*/
|
|
77
|
+
function withBundleDrop(config, options = {}) {
|
|
78
|
+
const projectRoot = path_1.default.resolve(options.projectRoot || process.cwd());
|
|
79
|
+
const baseConfig = loadBaseConfig(projectRoot);
|
|
80
|
+
const generatedConfigPath = writeGeneratedRuntimeConfig({
|
|
81
|
+
projectRoot,
|
|
82
|
+
runtimeDelivery: resolveRuntimeDelivery(projectRoot, baseConfig),
|
|
83
|
+
});
|
|
84
|
+
return mergeMetroAlias(config, generatedConfigPath);
|
|
85
|
+
}
|
|
86
|
+
exports.withBundleDropBare = withBundleDrop;
|
|
34
87
|
/**
|
|
35
88
|
* Preserves the caller's Expo Metro config and only adds Bundle Drop's config
|
|
36
89
|
* alias after resolving the same concrete identity used by build and upload.
|
|
@@ -42,16 +95,12 @@ async function withBundleDropExpo(configOrPromise, options = {}) {
|
|
|
42
95
|
(0, expo_1.resolveExpoMetroRuntimeVersion)(projectRoot, 'ios'),
|
|
43
96
|
(0, expo_1.resolveExpoMetroRuntimeVersion)(projectRoot, 'android'),
|
|
44
97
|
]);
|
|
45
|
-
const
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
'bundle-drop-config': generatedConfigPath,
|
|
53
|
-
},
|
|
54
|
-
},
|
|
55
|
-
};
|
|
98
|
+
const baseConfig = loadBaseConfig(projectRoot);
|
|
99
|
+
const generatedConfigPath = writeGeneratedRuntimeConfig({
|
|
100
|
+
projectRoot,
|
|
101
|
+
runtimeDelivery: resolveRuntimeDelivery(projectRoot, baseConfig),
|
|
102
|
+
runtimeVersion: { ios, android },
|
|
103
|
+
});
|
|
104
|
+
return mergeMetroAlias(config, generatedConfigPath);
|
|
56
105
|
}
|
|
57
106
|
exports.default = withBundleDropExpo;
|
|
@@ -11,7 +11,8 @@ function isBundleDropNativeAvailable() {
|
|
|
11
11
|
return Boolean(BundleDrop);
|
|
12
12
|
}
|
|
13
13
|
function isExpoOtaStartupEnabledNative() {
|
|
14
|
-
|
|
14
|
+
const nativeValue = BundleDropExpoIdentity?.otaStartupEnabled;
|
|
15
|
+
return nativeValue === true || nativeValue === 1;
|
|
15
16
|
}
|
|
16
17
|
async function getDownloadedBundlePathNative() {
|
|
17
18
|
if (!BundleDrop?.getDownloadedBundlePath) {
|
package/lib/native/fs.d.ts
CHANGED
|
@@ -7,7 +7,10 @@ declare function unlink(path: string): Promise<void>;
|
|
|
7
7
|
declare function moveFile(src: string, dest: string): Promise<void>;
|
|
8
8
|
declare function unzip(zipPath: string, destPath: string): Promise<string[]>;
|
|
9
9
|
declare function downloadFile(url: string, destPath: string): Promise<void>;
|
|
10
|
+
declare function downloadFileBounded(url: string, destPath: string, maxBytes: number, timeoutMs: number): Promise<void>;
|
|
10
11
|
declare function sha256File(path: string): Promise<string>;
|
|
12
|
+
declare function sha256String(value: string): Promise<string>;
|
|
13
|
+
declare function verifyEs256Signature(signingInput: string, signatureBase64Url: string, xBase64Url: string, yBase64Url: string): Promise<boolean>;
|
|
11
14
|
declare function fileSize(path: string): Promise<number>;
|
|
12
15
|
declare function copyFile(src: string, dest: string): Promise<void>;
|
|
13
16
|
declare function applyXdelta(basePath: string, patchPath: string, outputPath: string): Promise<void>;
|
|
@@ -27,7 +30,10 @@ declare const BundleDropFS: {
|
|
|
27
30
|
moveFile: typeof moveFile;
|
|
28
31
|
unzip: typeof unzip;
|
|
29
32
|
downloadFile: typeof downloadFile;
|
|
33
|
+
downloadFileBounded: typeof downloadFileBounded;
|
|
30
34
|
sha256File: typeof sha256File;
|
|
35
|
+
sha256String: typeof sha256String;
|
|
36
|
+
verifyEs256Signature: typeof verifyEs256Signature;
|
|
31
37
|
fileSize: typeof fileSize;
|
|
32
38
|
copyFile: typeof copyFile;
|
|
33
39
|
applyXdelta: typeof applyXdelta;
|
package/lib/native/fs.js
CHANGED
|
@@ -44,10 +44,31 @@ async function downloadFile(url, destPath) {
|
|
|
44
44
|
assertModule();
|
|
45
45
|
return BundleDrop.fsDownloadFile(url, destPath);
|
|
46
46
|
}
|
|
47
|
+
async function downloadFileBounded(url, destPath, maxBytes, timeoutMs) {
|
|
48
|
+
assertModule();
|
|
49
|
+
if (typeof BundleDrop.fsDownloadFileBounded !== 'function') {
|
|
50
|
+
throw new Error('BundleDrop native module is outdated. Rebuild the app for bounded manifest downloads.');
|
|
51
|
+
}
|
|
52
|
+
return BundleDrop.fsDownloadFileBounded(url, destPath, maxBytes, timeoutMs);
|
|
53
|
+
}
|
|
47
54
|
async function sha256File(path) {
|
|
48
55
|
assertModule();
|
|
49
56
|
return BundleDrop.fsSha256File(path);
|
|
50
57
|
}
|
|
58
|
+
async function sha256String(value) {
|
|
59
|
+
assertModule();
|
|
60
|
+
if (typeof BundleDrop.fsSha256String !== 'function') {
|
|
61
|
+
throw new Error('BundleDrop native module is outdated. Rebuild the app for runtime delivery.');
|
|
62
|
+
}
|
|
63
|
+
return BundleDrop.fsSha256String(value);
|
|
64
|
+
}
|
|
65
|
+
async function verifyEs256Signature(signingInput, signatureBase64Url, xBase64Url, yBase64Url) {
|
|
66
|
+
assertModule();
|
|
67
|
+
if (typeof BundleDrop.fsVerifyEs256Signature !== 'function') {
|
|
68
|
+
throw new Error('BundleDrop native module is outdated. Rebuild the app for runtime delivery.');
|
|
69
|
+
}
|
|
70
|
+
return BundleDrop.fsVerifyEs256Signature(signingInput, signatureBase64Url, xBase64Url, yBase64Url);
|
|
71
|
+
}
|
|
51
72
|
async function fileSize(path) {
|
|
52
73
|
assertModule();
|
|
53
74
|
return BundleDrop.fsFileSize(path);
|
|
@@ -85,7 +106,10 @@ const BundleDropFS = {
|
|
|
85
106
|
moveFile,
|
|
86
107
|
unzip,
|
|
87
108
|
downloadFile,
|
|
109
|
+
downloadFileBounded,
|
|
88
110
|
sha256File,
|
|
111
|
+
sha256String,
|
|
112
|
+
verifyEs256Signature,
|
|
89
113
|
fileSize,
|
|
90
114
|
copyFile,
|
|
91
115
|
applyXdelta,
|
|
@@ -11,6 +11,8 @@ type InstallFromPatchSetParams = {
|
|
|
11
11
|
algorithm: SupportedPatchAlgorithm;
|
|
12
12
|
platform?: 'ios' | 'android';
|
|
13
13
|
statusCb?: (status: string) => void;
|
|
14
|
+
expectedManifestHash?: string;
|
|
15
|
+
expectedJsBundleHash?: string;
|
|
14
16
|
};
|
|
15
17
|
export declare function installFromPatchSet(params: InstallFromPatchSetParams): Promise<InstallResult>;
|
|
16
18
|
export {};
|
|
@@ -32,7 +32,7 @@ const reconstructPatchTarget = async (baseDir, baseHash, platform, patchDir, tar
|
|
|
32
32
|
}
|
|
33
33
|
};
|
|
34
34
|
async function installFromPatchSet(params) {
|
|
35
|
-
const { patchesUrl, patchSetHash, manifestUrl, missingAssetsUrl, missingAssetsHash, baseHash, targetHash, algorithm, statusCb, platform = context_1.platform, } = params;
|
|
35
|
+
const { patchesUrl, patchSetHash, manifestUrl, missingAssetsUrl, missingAssetsHash, baseHash, targetHash, algorithm, statusCb, platform = context_1.platform, expectedManifestHash, expectedJsBundleHash, } = params;
|
|
36
36
|
(0, bundleInstallShared_1.assertCanonicalBundleHash)(baseHash, 'base hash');
|
|
37
37
|
(0, bundleInstallShared_1.assertCanonicalBundleHash)(targetHash, 'target hash');
|
|
38
38
|
const currentPointer = await (0, bundlePointer_1.readCurrentBundlePointer)();
|
|
@@ -90,14 +90,19 @@ async function installFromPatchSet(params) {
|
|
|
90
90
|
}
|
|
91
91
|
const assetsZipPath = `${context_1.BUNDLE_DROP_ROOT}/bundles/_patch_assets_${targetHash}.zip`;
|
|
92
92
|
try {
|
|
93
|
-
|
|
93
|
+
try {
|
|
94
|
+
await fs_1.default.downloadFile(missingAssetsUrl, assetsZipPath);
|
|
95
|
+
}
|
|
96
|
+
catch (e) {
|
|
97
|
+
throw new errors_1.InstallPhaseError('download', e);
|
|
98
|
+
}
|
|
94
99
|
if ((await fs_1.default.sha256File(assetsZipPath)) !== missingAssetsHash) {
|
|
95
100
|
throw new Error('Missing assets archive hash mismatch');
|
|
96
101
|
}
|
|
97
102
|
await fs_1.default.unzip(assetsZipPath, `${patchDir}/missing-assets`);
|
|
98
103
|
}
|
|
99
104
|
catch (e) {
|
|
100
|
-
throw new errors_1.InstallPhaseError('install', e);
|
|
105
|
+
throw (0, errors_1.isInstallPhaseError)(e) ? e : new errors_1.InstallPhaseError('install', e);
|
|
101
106
|
}
|
|
102
107
|
finally {
|
|
103
108
|
try {
|
|
@@ -109,6 +114,12 @@ async function installFromPatchSet(params) {
|
|
|
109
114
|
try {
|
|
110
115
|
targetManifest = await (0, bundleVerification_1.readJsonFile)(`${patchDir}/${bundleManifest_1.BUNDLE_MANIFEST}`);
|
|
111
116
|
(0, bundleManifest_1.assertValidBundleManifest)(targetManifest, targetHash, platform);
|
|
117
|
+
if (expectedManifestHash && targetManifest.manifestHash !== expectedManifestHash) {
|
|
118
|
+
throw new Error('Signed manifest hash does not match patch target manifest');
|
|
119
|
+
}
|
|
120
|
+
if (expectedJsBundleHash && targetManifest.jsBundleHash !== expectedJsBundleHash) {
|
|
121
|
+
throw new Error('Signed JavaScript bundle hash does not match patch target manifest');
|
|
122
|
+
}
|
|
112
123
|
await reconstructPatchTarget(baseDir, baseHash, platform, patchDir, targetTempDir, targetManifest, algorithm);
|
|
113
124
|
await fs_1.default.writeFile(`${targetTempDir}/${bundleManifest_1.BUNDLE_MANIFEST}`, JSON.stringify(targetManifest, null, 2), 'utf8');
|
|
114
125
|
await (0, bundleVerification_1.verifyBundleDir)(targetTempDir, targetHash, platform);
|