@gfean/react-native-bundle-drop 0.5.1 → 0.7.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/BundleDrop.podspec +96 -0
- package/README.md +194 -5
- package/android/build.gradle +66 -0
- package/android/src/main/java/com/bundledrop/BundleDropBoundedDownloader.kt +86 -0
- package/android/src/main/java/com/bundledrop/BundleDropModule.kt +206 -13
- package/android/src/main/java/com/bundledrop/BundleDropNativePaths.kt +43 -13
- package/android/src/main/java/com/bundledrop/BundleDropOtaResolver.kt +35 -0
- package/android/src/main/java/com/bundledrop/BundleDropRuntimeCrypto.kt +81 -0
- package/android/src/main/java/com/bundledrop/BundleDropStartupRecovery.kt +1117 -0
- package/ios/BundleDropBridge.m +45 -0
- package/ios/BundleDropLocator.swift +66 -4
- package/ios/BundleDropModule.swift +181 -3
- package/ios/BundleDropOtaResolver.swift +137 -29
- package/ios/BundleDropRuntimeCrypto.swift +45 -0
- package/ios/BundleDropStartupRecovery.swift +1108 -0
- package/ios/BundleDropStartupRecoveryAdapter.swift +301 -0
- package/lib/CLI/cli.d.ts +1 -0
- package/lib/CLI/cli.js +57 -6
- 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 +221 -45
- 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 +162 -22
- package/lib/CLI/scripts/expo/configure-expo.js +52 -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 +198 -14
- package/lib/CLI/scripts/login-cli.js +31 -7
- 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/write-runtime-identity.d.ts +19 -0
- package/lib/CLI/scripts/native/write-runtime-identity.js +92 -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/upload-cli.d.ts +12 -2
- package/lib/CLI/scripts/upload-cli.js +74 -11
- package/lib/CLI/serverUrl.d.ts +3 -0
- package/lib/CLI/serverUrl.js +31 -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/bundleInfo.d.ts +2 -0
- package/lib/bundleInfo.js +16 -1
- package/lib/context.d.ts +1 -1
- package/lib/context.js +12 -2
- package/lib/fs/bundlePointer.d.ts +1 -17
- package/lib/fs/bundlePointer.js +5 -93
- package/lib/index.d.ts +2 -0
- package/lib/index.js +3 -1
- package/lib/install/bundleInstallShared.js +4 -4
- 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 +134 -66
- package/lib/manager/reporting.d.ts +8 -1
- package/lib/manager/reporting.js +17 -22
- package/lib/manager/rollbackState.d.ts +18 -52
- package/lib/manager/rollbackState.js +115 -216
- package/lib/manager/updateCheck.d.ts +1 -0
- package/lib/manager/updateCheck.js +224 -78
- package/lib/manager/updateState.d.ts +2 -1
- package/lib/manager/updateState.js +59 -6
- package/lib/metro.d.ts +8 -1
- package/lib/metro.js +69 -19
- package/lib/native/bundleDropNative.d.ts +62 -0
- package/lib/native/bundleDropNative.js +268 -2
- 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 +16 -5
- 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 +82 -67
- 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 +68 -0
- package/lib/runtime-delivery/bootstrapConfig.js +278 -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 +11 -0
- package/lib/runtime-delivery/manifestState.js +123 -0
- package/lib/runtime-delivery/manifestVerifier.d.ts +13 -0
- package/lib/runtime-delivery/manifestVerifier.js +335 -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/lib/scripts/bundle.d.ts +9 -2
- package/lib/scripts/bundle.js +68 -18
- package/lib/scripts/download-bundle.d.ts +1 -0
- package/lib/scripts/download-bundle.js +2 -2
- package/lib/scripts/resolveModule.d.ts +2 -0
- package/lib/scripts/resolveModule.js +5 -0
- package/package.json +5 -2
- package/plugin/xcodeBuildPhase.js +2 -1
package/lib/runtime/service.js
CHANGED
|
@@ -27,6 +27,7 @@ exports.waitForBundleDropStartupForTests = waitForBundleDropStartupForTests;
|
|
|
27
27
|
const bundleInfo_1 = require("../bundleInfo");
|
|
28
28
|
const context_1 = require("../context");
|
|
29
29
|
const fsUtils_1 = require("../fs/fsUtils");
|
|
30
|
+
const loadConfig_1 = require("../loadConfig");
|
|
30
31
|
const bundleDropNative_1 = require("../native/bundleDropNative");
|
|
31
32
|
const bundlePointer_1 = require("../fs/bundlePointer");
|
|
32
33
|
const downloadAndInstall_1 = require("../manager/downloadAndInstall");
|
|
@@ -39,10 +40,16 @@ const DISABLED_STATUS = 'BundleDrop is disabled';
|
|
|
39
40
|
const EXPO_DEVELOPMENT_FALLBACK_WARNING = '[BundleDrop] OTA startup is unavailable in this Expo runtime. ' +
|
|
40
41
|
'Expo Go and standard Debug/development-client builds keep Metro priority, so OTA features are disabled. ' +
|
|
41
42
|
'Use a non-Debug/Release native build to test Bundle Drop updates.';
|
|
43
|
+
const CURRENT_REVOKED_ROLLBACK_REASONS = new Set([
|
|
44
|
+
'CURRENT_REVOKED_NO_COMPATIBLE_TARGET',
|
|
45
|
+
'CURRENT_REVOKED_NO_SAFE_TARGET',
|
|
46
|
+
'CURRENT_REVOKED_ORIGIN_UNAVAILABLE',
|
|
47
|
+
]);
|
|
48
|
+
const MANAGED_LIST_INSTALL_NOT_AUTHORIZED_STATUS = '⚠️ Selected bundle is not authorized by the current runtime delivery decision';
|
|
49
|
+
const MANAGED_DIRECT_INSTALL_NOT_AUTHORIZED_STATUS = '⚠️ Direct URL installs are unavailable with managed runtime delivery; use downloadUpdate or a bundle-list item';
|
|
42
50
|
let updateFlowActive = false;
|
|
43
51
|
let startupPromise = null;
|
|
44
52
|
let localStartupPromise = null;
|
|
45
|
-
let healthTimer = null;
|
|
46
53
|
let runtimeRestartRequested = false;
|
|
47
54
|
let activeBundleInfoForObservability = null;
|
|
48
55
|
let nativeOtaEnabledPromise = Promise.resolve();
|
|
@@ -110,6 +117,9 @@ function getEnabledRuntime(extraStatusHandler) {
|
|
|
110
117
|
function isSameStatus(current, next) {
|
|
111
118
|
return !!current && current === next;
|
|
112
119
|
}
|
|
120
|
+
function isCurrentRevokedRollback(reason) {
|
|
121
|
+
return !!reason && CURRENT_REVOKED_ROLLBACK_REASONS.has(reason);
|
|
122
|
+
}
|
|
113
123
|
function getCheckStatus(response) {
|
|
114
124
|
if (!response)
|
|
115
125
|
return '⚠️ Unable to check for updates. Try again.';
|
|
@@ -157,49 +167,23 @@ function getApplyStatus(result) {
|
|
|
157
167
|
? '⚠️ Update previously failed on this device'
|
|
158
168
|
: 'ℹ️ Bundle already applied';
|
|
159
169
|
}
|
|
160
|
-
function clearHealthTimer() {
|
|
161
|
-
if (!healthTimer)
|
|
162
|
-
return;
|
|
163
|
-
clearTimeout(healthTimer);
|
|
164
|
-
healthTimer = null;
|
|
165
|
-
}
|
|
166
170
|
function requestRuntimeRestart() {
|
|
167
171
|
runtimeRestartRequested = true;
|
|
168
172
|
(0, bundleDropNative_1.restartReactNativeNative)();
|
|
169
173
|
}
|
|
170
|
-
async function
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
const state = await (0, updateState_1.getUpdateState)();
|
|
175
|
-
if (runtimeRestartRequested) {
|
|
176
|
-
return false;
|
|
177
|
-
}
|
|
178
|
-
if (state.pendingApply) {
|
|
179
|
-
return false;
|
|
174
|
+
async function applyAuthoritativeRollback(reason) {
|
|
175
|
+
const result = await (0, rollbackState_1.rollbackStartupBundle)(isCurrentRevokedRollback(reason));
|
|
176
|
+
if (result?.rolledBack) {
|
|
177
|
+
requestRuntimeRestart();
|
|
180
178
|
}
|
|
181
|
-
|
|
179
|
+
}
|
|
180
|
+
async function markActiveCandidateHealthy() {
|
|
181
|
+
const markedHealthy = await (0, rollbackState_1.reportActiveBundleHealthy)();
|
|
182
182
|
if (markedHealthy) {
|
|
183
183
|
await refreshState();
|
|
184
184
|
}
|
|
185
185
|
return markedHealthy;
|
|
186
186
|
}
|
|
187
|
-
function scheduleCandidateHealthMark(currentPointer, rollbackState) {
|
|
188
|
-
clearHealthTimer();
|
|
189
|
-
const hash = currentPointer?.hash;
|
|
190
|
-
const rollbackPolicy = (0, rollbackState_1.getRollbackPolicy)();
|
|
191
|
-
if (!hash || rollbackPolicy.healthCheckMode === 'manual')
|
|
192
|
-
return;
|
|
193
|
-
if (rollbackState?.candidateHash !== hash || rollbackState.candidateCommitted === true)
|
|
194
|
-
return;
|
|
195
|
-
const delayMs = Math.max(0, rollbackPolicy.healthyAfterSec || 0) * 1000;
|
|
196
|
-
healthTimer = setTimeout(() => {
|
|
197
|
-
healthTimer = null;
|
|
198
|
-
markActiveCandidateHealthy(hash).catch(error => {
|
|
199
|
-
console.warn('⚠️ Failed to mark BundleDrop candidate healthy:', error);
|
|
200
|
-
});
|
|
201
|
-
}, delayMs);
|
|
202
|
-
}
|
|
203
187
|
async function refreshState(cached) {
|
|
204
188
|
const state = await (0, updateState_1.getUpdateState)(cached);
|
|
205
189
|
patchSnapshot({
|
|
@@ -237,21 +221,27 @@ async function waitForLocalStartupIfNeeded() {
|
|
|
237
221
|
}
|
|
238
222
|
}
|
|
239
223
|
async function runLocalStartupFlow() {
|
|
240
|
-
const [bundleInfo, bundlePath,
|
|
224
|
+
const [bundleInfo, bundlePath, currentHash, recoveryState] = await Promise.all([
|
|
241
225
|
(0, bundleInfo_1.readBundleInfo)(),
|
|
242
226
|
(0, bundleDropNative_1.getDownloadedBundlePathNative)(),
|
|
243
|
-
(0, bundlePointer_1.
|
|
244
|
-
(0, rollbackState_1.
|
|
227
|
+
(0, bundlePointer_1.readCurrentBundleHash)(),
|
|
228
|
+
(0, rollbackState_1.readStartupRecoveryState)(),
|
|
245
229
|
]);
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
230
|
+
void (0, rollbackState_1.reconcileStartupRecovery)(recoveryState, bundleInfo).catch(error => {
|
|
231
|
+
console.warn('⚠️ Failed to reconcile BundleDrop startup recovery telemetry:', error);
|
|
232
|
+
});
|
|
233
|
+
const reconciledBundleInfo = await (0, updateState_1.reconcileAppliedBundleOnLaunch)({
|
|
234
|
+
bundleInfo,
|
|
251
235
|
bundlePath,
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
};
|
|
236
|
+
currentHash,
|
|
237
|
+
});
|
|
238
|
+
await refreshState({ bundleInfo: reconciledBundleInfo, bundlePath });
|
|
239
|
+
const state = await (0, updateState_1.getUpdateState)({
|
|
240
|
+
bundleInfo: reconciledBundleInfo,
|
|
241
|
+
bundlePath,
|
|
242
|
+
});
|
|
243
|
+
activeBundleInfoForObservability = state.hasBundle ? state.info || null : null;
|
|
244
|
+
return { bundlePath };
|
|
255
245
|
}
|
|
256
246
|
async function runStartupFlow() {
|
|
257
247
|
const runtime = (0, initState_1.assertBundleDropInitialized)();
|
|
@@ -261,19 +251,7 @@ async function runStartupFlow() {
|
|
|
261
251
|
await nativeOtaEnabledPromise;
|
|
262
252
|
return runLocalStartupFlow();
|
|
263
253
|
})();
|
|
264
|
-
const { bundlePath
|
|
265
|
-
const rollbackPolicy = (0, rollbackState_1.getRollbackPolicy)();
|
|
266
|
-
const rollbackResult = await (0, rollbackState_1.rollbackToPreviousIfNeeded)(rollbackPolicy, {
|
|
267
|
-
currentPointer,
|
|
268
|
-
rollbackState,
|
|
269
|
-
});
|
|
270
|
-
if (rollbackResult.rolledBack) {
|
|
271
|
-
clearHealthTimer();
|
|
272
|
-
emitStatus('↩️ Rolled back to previous bundle');
|
|
273
|
-
requestRuntimeRestart();
|
|
274
|
-
return;
|
|
275
|
-
}
|
|
276
|
-
scheduleCandidateHealthMark(currentPointer, await (0, rollbackState_1.readRollbackState)());
|
|
254
|
+
const { bundlePath } = await localStartupPromise;
|
|
277
255
|
const pendingState = await refreshState({ bundlePath });
|
|
278
256
|
if (pendingState.pendingApply) {
|
|
279
257
|
if (runtime.policy === 'immediate') {
|
|
@@ -302,8 +280,7 @@ async function runStartupFlow() {
|
|
|
302
280
|
return;
|
|
303
281
|
if (decision.action === 'ROLLBACK') {
|
|
304
282
|
emitStatus('↩️ Server requested rollback...');
|
|
305
|
-
await (
|
|
306
|
-
requestRuntimeRestart();
|
|
283
|
+
await applyAuthoritativeRollback(decision.reason);
|
|
307
284
|
return;
|
|
308
285
|
}
|
|
309
286
|
if (decision.action === 'NOOP' || runtime.policy === 'manual' || runtime.checkOnly) {
|
|
@@ -312,7 +289,7 @@ async function runStartupFlow() {
|
|
|
312
289
|
const downloadUrl = decision.mode === 'patch'
|
|
313
290
|
? decision.fallback?.downloadUrl
|
|
314
291
|
: decision.downloadUrl;
|
|
315
|
-
if (!downloadUrl || !decision.hash) {
|
|
292
|
+
if ((!downloadUrl && !decision.runtimeDelivery) || !decision.hash) {
|
|
316
293
|
emitStatus('⚠️ Update available but missing download URL');
|
|
317
294
|
return;
|
|
318
295
|
}
|
|
@@ -327,11 +304,17 @@ async function runStartupFlow() {
|
|
|
327
304
|
baseHash: decision.baseHash,
|
|
328
305
|
patchSet: decision.patchSet,
|
|
329
306
|
fallback: decision.fallback,
|
|
307
|
+
...(decision.runtimeDelivery ? { runtimeDelivery: decision.runtimeDelivery } : {}),
|
|
330
308
|
};
|
|
331
309
|
const downloadResult = await (0, downloadAndInstall_1.downloadUpdate)({
|
|
332
310
|
channelName: runtime.channelName,
|
|
333
311
|
resolvedTarget,
|
|
334
312
|
}, statusCb);
|
|
313
|
+
if (downloadResult.status === 'rollback') {
|
|
314
|
+
emitStatus('↩️ Server requested rollback...');
|
|
315
|
+
await applyAuthoritativeRollback(downloadResult.reason);
|
|
316
|
+
return;
|
|
317
|
+
}
|
|
335
318
|
if (runtime.policy === 'on-next-launch') {
|
|
336
319
|
if (downloadResult.status === 'staged') {
|
|
337
320
|
emitStatus('✅ Update downloaded for next launch');
|
|
@@ -383,6 +366,9 @@ function initBundleDrop(options) {
|
|
|
383
366
|
if (!alreadyInitialized) {
|
|
384
367
|
runtimeRestartRequested = false;
|
|
385
368
|
activeBundleInfoForObservability = null;
|
|
369
|
+
if (config.enabled) {
|
|
370
|
+
(0, bundleDropNative_1.warnIfStartupRecoveryUnavailableNative)();
|
|
371
|
+
}
|
|
386
372
|
}
|
|
387
373
|
// Persist for the next cold start and for native path reads in this process.
|
|
388
374
|
nativeOtaEnabledPromise = (0, bundleDropNative_1.setOtaEnabledNative)(config.enabled);
|
|
@@ -465,6 +451,9 @@ async function downloadAndStage(extraStatusHandler) {
|
|
|
465
451
|
await waitForStartupIfNeeded();
|
|
466
452
|
return withBusy(async () => {
|
|
467
453
|
const result = await (0, downloadAndInstall_1.downloadUpdate)({ channelName: runtime.channelName }, status => emitStatus(status, extraStatusHandler));
|
|
454
|
+
if (result.status === 'rollback') {
|
|
455
|
+
await applyAuthoritativeRollback(result.reason);
|
|
456
|
+
}
|
|
468
457
|
const status = getDownloadStatus(result);
|
|
469
458
|
if (status) {
|
|
470
459
|
emitStatus(status, extraStatusHandler);
|
|
@@ -500,11 +489,9 @@ async function reportHealthy() {
|
|
|
500
489
|
if (!runtime) {
|
|
501
490
|
return;
|
|
502
491
|
}
|
|
503
|
-
|
|
504
|
-
if (runtimeRestartRequested || updateFlowActive) {
|
|
492
|
+
if (runtimeRestartRequested) {
|
|
505
493
|
return;
|
|
506
494
|
}
|
|
507
|
-
clearHealthTimer();
|
|
508
495
|
await markActiveCandidateHealthy();
|
|
509
496
|
}
|
|
510
497
|
/**
|
|
@@ -560,8 +547,27 @@ async function installBundleFromListItem(bundle) {
|
|
|
560
547
|
}
|
|
561
548
|
return withBusy(async () => {
|
|
562
549
|
const resolvedDecision = await (0, updateCheck_1.checkForUpdate)(runtime.channelName, emitStatus).catch(() => null);
|
|
550
|
+
const usesManagedRuntimeDelivery = (0, loadConfig_1.isRuntimeDeliveryConfigured)(context_1.config.runtimeDelivery);
|
|
563
551
|
const canUseResolvedTransport = resolvedDecision?.action === 'INSTALL' &&
|
|
564
552
|
(resolvedDecision.bundleHash ?? resolvedDecision.hash) === bundle.hash;
|
|
553
|
+
if (usesManagedRuntimeDelivery && resolvedDecision?.action === 'ROLLBACK') {
|
|
554
|
+
const result = {
|
|
555
|
+
status: 'rollback',
|
|
556
|
+
reason: resolvedDecision.reason,
|
|
557
|
+
};
|
|
558
|
+
await applyAuthoritativeRollback(result.reason);
|
|
559
|
+
const status = getDownloadStatus(result);
|
|
560
|
+
if (status)
|
|
561
|
+
emitStatus(status);
|
|
562
|
+
return { result, status };
|
|
563
|
+
}
|
|
564
|
+
if (usesManagedRuntimeDelivery && !canUseResolvedTransport) {
|
|
565
|
+
emitStatus(MANAGED_LIST_INSTALL_NOT_AUTHORIZED_STATUS);
|
|
566
|
+
return {
|
|
567
|
+
result: { status: 'incompatible' },
|
|
568
|
+
status: MANAGED_LIST_INSTALL_NOT_AUTHORIZED_STATUS,
|
|
569
|
+
};
|
|
570
|
+
}
|
|
565
571
|
const result = canUseResolvedTransport
|
|
566
572
|
? await (0, downloadAndInstall_1.downloadUpdate)({
|
|
567
573
|
channelName: runtime.channelName,
|
|
@@ -578,12 +584,18 @@ async function installBundleFromListItem(bundle) {
|
|
|
578
584
|
baseHash: resolvedDecision.baseHash,
|
|
579
585
|
patchSet: resolvedDecision.patchSet,
|
|
580
586
|
fallback: resolvedDecision.fallback,
|
|
587
|
+
...(resolvedDecision.runtimeDelivery
|
|
588
|
+
? { runtimeDelivery: resolvedDecision.runtimeDelivery }
|
|
589
|
+
: {}),
|
|
581
590
|
},
|
|
582
591
|
}, emitStatus)
|
|
583
592
|
: await (0, downloadAndInstall_1.installBundle)(bundle.hash, downloadUrl, bundle.bundleVersion, bundle.version, bundle.runtimeVersion, {
|
|
584
593
|
channelName: runtime.channelName,
|
|
585
594
|
onStatusUpdate: emitStatus,
|
|
586
595
|
});
|
|
596
|
+
if (usesManagedRuntimeDelivery && result.status === 'rollback') {
|
|
597
|
+
await applyAuthoritativeRollback(result.reason);
|
|
598
|
+
}
|
|
587
599
|
if (result.status === 'staged') {
|
|
588
600
|
const status = `✅ v${bundle.bundleVersion} downloaded. Will apply on next launch or when you call applyUpdate.`;
|
|
589
601
|
emitStatus(status);
|
|
@@ -642,9 +654,9 @@ async function getObservabilityContext() {
|
|
|
642
654
|
}
|
|
643
655
|
return {
|
|
644
656
|
source: 'ota',
|
|
645
|
-
dist: info.hash
|
|
657
|
+
dist: info.hash,
|
|
646
658
|
tags: {
|
|
647
|
-
bundle_drop_hash: info.hash
|
|
659
|
+
bundle_drop_hash: info.hash,
|
|
648
660
|
bundle_drop_channel: info.channelName ?? null,
|
|
649
661
|
bundle_drop_version: info.bundleVersion != null ? `${info.bundleVersion}` : null,
|
|
650
662
|
bundle_drop_runtime_version: info.runtimeVersion ?? null,
|
|
@@ -708,6 +720,10 @@ async function installBundle(hash, downloadUrl, bundleVersion, version, runtimeV
|
|
|
708
720
|
return { status: 'disabled' };
|
|
709
721
|
}
|
|
710
722
|
await waitForStartupIfNeeded();
|
|
723
|
+
if ((0, loadConfig_1.isRuntimeDeliveryConfigured)(context_1.config.runtimeDelivery)) {
|
|
724
|
+
emitStatus(MANAGED_DIRECT_INSTALL_NOT_AUTHORIZED_STATUS, onStatusUpdate);
|
|
725
|
+
return { status: 'incompatible' };
|
|
726
|
+
}
|
|
711
727
|
return withBusy(async () => {
|
|
712
728
|
const result = await (0, downloadAndInstall_1.installBundle)(hash, downloadUrl, bundleVersion, version, runtimeVersion, {
|
|
713
729
|
channelName: runtime.channelName,
|
|
@@ -721,7 +737,6 @@ async function installBundle(hash, downloadUrl, bundleVersion, version, runtimeV
|
|
|
721
737
|
});
|
|
722
738
|
}
|
|
723
739
|
function resetBundleDropRuntimeServiceForTests() {
|
|
724
|
-
clearHealthTimer();
|
|
725
740
|
updateFlowActive = false;
|
|
726
741
|
startupPromise = null;
|
|
727
742
|
localStartupPromise = null;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function isArtifactCapabilityRejected(error: unknown): boolean;
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.isArtifactCapabilityRejected = isArtifactCapabilityRejected;
|
|
4
|
+
const errors_1 = require("../errors");
|
|
5
|
+
const CAPABILITY_HTTP_STATUS = /(?:^|\b)HTTP\s+(401|403)(?:\b|:)/i;
|
|
6
|
+
function readHttpStatus(error, depth = 0) {
|
|
7
|
+
if (depth > 5 || !error)
|
|
8
|
+
return undefined;
|
|
9
|
+
if (typeof error === 'string') {
|
|
10
|
+
const match = CAPABILITY_HTTP_STATUS.exec(error);
|
|
11
|
+
return match ? Number(match[1]) : undefined;
|
|
12
|
+
}
|
|
13
|
+
if (typeof error !== 'object')
|
|
14
|
+
return undefined;
|
|
15
|
+
const value = error;
|
|
16
|
+
for (const candidate of [value.status, value.statusCode, value.httpStatus]) {
|
|
17
|
+
if (candidate === 401 || candidate === 403)
|
|
18
|
+
return candidate;
|
|
19
|
+
}
|
|
20
|
+
const messageStatus = readHttpStatus(value.message, depth + 1);
|
|
21
|
+
if (messageStatus)
|
|
22
|
+
return messageStatus;
|
|
23
|
+
const nested = (0, errors_1.isInstallPhaseError)(error)
|
|
24
|
+
? error.originalCause
|
|
25
|
+
: value.cause ?? value.error ?? value.userInfo;
|
|
26
|
+
return readHttpStatus(nested, depth + 1);
|
|
27
|
+
}
|
|
28
|
+
function isArtifactCapabilityRejected(error) {
|
|
29
|
+
return (0, errors_1.isInstallPhaseError)(error) &&
|
|
30
|
+
error.phase === 'download' &&
|
|
31
|
+
Boolean(readHttpStatus(error.originalCause));
|
|
32
|
+
}
|
|
@@ -0,0 +1,3 @@
|
|
|
1
|
+
import { type RuntimeDeliveryAuthorityLease, type RuntimeDeliveryAuthorityLeaseV1, type RuntimeDeliveryPublicKey } from './types';
|
|
2
|
+
export declare const MAX_RUNTIME_DELIVERY_AUTHORITY_LEASE_MS = 15000;
|
|
3
|
+
export declare function verifyRuntimeDeliveryAuthorityLease(serializedJws: string, expectedManifestOrigin: string, publicKeys: Record<string, RuntimeDeliveryPublicKey>, now?: number): Promise<RuntimeDeliveryAuthorityLease | RuntimeDeliveryAuthorityLeaseV1>;
|
|
@@ -0,0 +1,106 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.MAX_RUNTIME_DELIVERY_AUTHORITY_LEASE_MS = void 0;
|
|
4
|
+
exports.verifyRuntimeDeliveryAuthorityLease = verifyRuntimeDeliveryAuthorityLease;
|
|
5
|
+
const encoding_1 = require("./encoding");
|
|
6
|
+
const manifestVerifier_1 = require("./manifestVerifier");
|
|
7
|
+
const types_1 = require("./types");
|
|
8
|
+
exports.MAX_RUNTIME_DELIVERY_AUTHORITY_LEASE_MS = 15000;
|
|
9
|
+
const MAX_CLOCK_SKEW_MS = 5000;
|
|
10
|
+
const isRecord = (value) => Boolean(value) && typeof value === 'object' && !Array.isArray(value);
|
|
11
|
+
function normalizeDnsOrIpv4Host(value) {
|
|
12
|
+
const host = value.toLowerCase();
|
|
13
|
+
if (host.length > 253 || !/^[a-z0-9.-]+$/.test(host))
|
|
14
|
+
return undefined;
|
|
15
|
+
const labels = host.split('.');
|
|
16
|
+
if (labels.some(label => !label ||
|
|
17
|
+
label.length > 63 ||
|
|
18
|
+
label.startsWith('-') ||
|
|
19
|
+
label.endsWith('-'))) {
|
|
20
|
+
return undefined;
|
|
21
|
+
}
|
|
22
|
+
if (labels.every(label => /^\d+$/.test(label))) {
|
|
23
|
+
if (labels.length !== 4 || labels.some(label => Number(label) > 255))
|
|
24
|
+
return undefined;
|
|
25
|
+
}
|
|
26
|
+
return host;
|
|
27
|
+
}
|
|
28
|
+
function normalizeManifestOrigin(value) {
|
|
29
|
+
const match = /^https:\/\/([^/?#@]+)\/?$/i.exec(value);
|
|
30
|
+
if (!match)
|
|
31
|
+
return undefined;
|
|
32
|
+
const authority = match[1];
|
|
33
|
+
const authorityMatch = /^([^:]+)(?::(\d{1,5}))?$/.exec(authority);
|
|
34
|
+
if (!authorityMatch)
|
|
35
|
+
return undefined;
|
|
36
|
+
const host = normalizeDnsOrIpv4Host(authorityMatch[1]);
|
|
37
|
+
const port = authorityMatch[2] ? Number(authorityMatch[2]) : 443;
|
|
38
|
+
if (!host || port < 1 || port > 65535)
|
|
39
|
+
return undefined;
|
|
40
|
+
return `https://${host}${port === 443 ? '' : `:${port}`}`;
|
|
41
|
+
}
|
|
42
|
+
function authorityError(error, fallbackMessage) {
|
|
43
|
+
if (error instanceof manifestVerifier_1.RuntimeDeliveryManifestError) {
|
|
44
|
+
const mapped = {
|
|
45
|
+
body_too_large: 'authority_body_too_large',
|
|
46
|
+
invalid_signature: 'authority_invalid_signature',
|
|
47
|
+
unknown_key: 'authority_unknown_key',
|
|
48
|
+
}[error.code];
|
|
49
|
+
if (mapped)
|
|
50
|
+
return new manifestVerifier_1.RuntimeDeliveryManifestError(mapped, error.message, { cause: error });
|
|
51
|
+
}
|
|
52
|
+
return new manifestVerifier_1.RuntimeDeliveryManifestError('authority_invalid', fallbackMessage, { cause: error });
|
|
53
|
+
}
|
|
54
|
+
async function verifyRuntimeDeliveryAuthorityLease(serializedJws, expectedManifestOrigin, publicKeys, now = Date.now()) {
|
|
55
|
+
let payloadValue;
|
|
56
|
+
try {
|
|
57
|
+
payloadValue = await (0, manifestVerifier_1.verifyRuntimeDeliverySignedPayload)(serializedJws, types_1.RUNTIME_DELIVERY_AUTHORITY_LEASE_JWS_TYPE, publicKeys);
|
|
58
|
+
}
|
|
59
|
+
catch (error) {
|
|
60
|
+
throw authorityError(error, 'Runtime delivery authority lease signature is invalid');
|
|
61
|
+
}
|
|
62
|
+
let payload;
|
|
63
|
+
try {
|
|
64
|
+
payload = JSON.parse((0, encoding_1.decodeBase64UrlUtf8)(payloadValue));
|
|
65
|
+
}
|
|
66
|
+
catch (error) {
|
|
67
|
+
throw authorityError(error, 'Runtime delivery authority lease payload is invalid');
|
|
68
|
+
}
|
|
69
|
+
const schemaVersion = isRecord(payload) ? payload.schemaVersion : undefined;
|
|
70
|
+
const expectedKeys = schemaVersion === 2
|
|
71
|
+
? ['clientAuthority', 'expiresAt', 'generatedAt', 'manifestOrigin', 'schemaVersion', 'type']
|
|
72
|
+
: ['expiresAt', 'generatedAt', 'manifestOrigin', 'schemaVersion', 'type'];
|
|
73
|
+
if (!isRecord(payload) ||
|
|
74
|
+
Object.keys(payload).sort().join(',') !== expectedKeys.join(',') ||
|
|
75
|
+
(payload.schemaVersion !== 1 && payload.schemaVersion !== 2) ||
|
|
76
|
+
payload.type !== 'publisher-lease' ||
|
|
77
|
+
typeof payload.manifestOrigin !== 'string' ||
|
|
78
|
+
typeof payload.generatedAt !== 'string' ||
|
|
79
|
+
typeof payload.expiresAt !== 'string' ||
|
|
80
|
+
(payload.schemaVersion === 2 &&
|
|
81
|
+
payload.clientAuthority !== 'enabled' &&
|
|
82
|
+
payload.clientAuthority !== 'disabled')) {
|
|
83
|
+
throw new manifestVerifier_1.RuntimeDeliveryManifestError('authority_invalid', 'Runtime delivery authority lease payload is invalid');
|
|
84
|
+
}
|
|
85
|
+
const manifestOrigin = normalizeManifestOrigin(payload.manifestOrigin);
|
|
86
|
+
const expectedOrigin = normalizeManifestOrigin(expectedManifestOrigin);
|
|
87
|
+
if (!manifestOrigin || !expectedOrigin || manifestOrigin !== expectedOrigin) {
|
|
88
|
+
throw new manifestVerifier_1.RuntimeDeliveryManifestError('authority_origin_mismatch', 'Runtime delivery authority lease manifest origin mismatch');
|
|
89
|
+
}
|
|
90
|
+
const generatedAt = Date.parse(payload.generatedAt);
|
|
91
|
+
const expiresAt = Date.parse(payload.expiresAt);
|
|
92
|
+
if (!Number.isFinite(generatedAt) ||
|
|
93
|
+
!Number.isFinite(expiresAt) ||
|
|
94
|
+
expiresAt <= generatedAt ||
|
|
95
|
+
expiresAt - generatedAt > exports.MAX_RUNTIME_DELIVERY_AUTHORITY_LEASE_MS ||
|
|
96
|
+
generatedAt > now + MAX_CLOCK_SKEW_MS) {
|
|
97
|
+
throw new manifestVerifier_1.RuntimeDeliveryManifestError('authority_invalid', 'Runtime delivery authority lease validity window is invalid');
|
|
98
|
+
}
|
|
99
|
+
if (expiresAt <= now) {
|
|
100
|
+
throw new manifestVerifier_1.RuntimeDeliveryManifestError('authority_expired', 'Runtime delivery authority lease is expired');
|
|
101
|
+
}
|
|
102
|
+
if (payload.schemaVersion === 2 && payload.clientAuthority === 'disabled') {
|
|
103
|
+
throw new manifestVerifier_1.RuntimeDeliveryManifestError('authority_disabled', 'Runtime delivery client authority is disabled by the operator');
|
|
104
|
+
}
|
|
105
|
+
return payload;
|
|
106
|
+
}
|
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
export declare const RUNTIME_DELIVERY_BOOTSTRAP_SCHEMA_VERSION = 1;
|
|
2
|
+
export declare const RUNTIME_DELIVERY_BOOTSTRAP_PATH: string;
|
|
3
|
+
export declare const LEGACY_RUNTIME_DELIVERY_BOOTSTRAP_PATH: string;
|
|
4
|
+
export declare const RUNTIME_DELIVERY_BOOTSTRAP_GITIGNORE_MARKER = "!.bundle-drop/runtime-delivery.lock.json";
|
|
5
|
+
export declare const LEGACY_RUNTIME_DELIVERY_BOOTSTRAP_GITIGNORE_MARKER = "!.bundle-drop/runtime-delivery.generated.json";
|
|
6
|
+
export type RuntimeDeliveryPublicKey = {
|
|
7
|
+
kty: 'EC';
|
|
8
|
+
crv: 'P-256';
|
|
9
|
+
x: string;
|
|
10
|
+
y: string;
|
|
11
|
+
};
|
|
12
|
+
export type RuntimeDeliveryConfig = {
|
|
13
|
+
manifestBaseUrl: string;
|
|
14
|
+
manifestAccessId: string;
|
|
15
|
+
publicKeys: Record<string, RuntimeDeliveryPublicKey>;
|
|
16
|
+
};
|
|
17
|
+
export type RuntimeDeliveryProjectIdentity = {
|
|
18
|
+
serverUrl: string;
|
|
19
|
+
orgSlug: string;
|
|
20
|
+
projectSlug: string;
|
|
21
|
+
projectId?: string;
|
|
22
|
+
orgId?: string;
|
|
23
|
+
};
|
|
24
|
+
export type RuntimeDeliveryBootstrapLockfile = {
|
|
25
|
+
schemaVersion: typeof RUNTIME_DELIVERY_BOOTSTRAP_SCHEMA_VERSION;
|
|
26
|
+
project: RuntimeDeliveryProjectIdentity;
|
|
27
|
+
runtimeDelivery: RuntimeDeliveryConfig;
|
|
28
|
+
};
|
|
29
|
+
export type RuntimeDeliveryBootstrapSource = 'lock' | 'legacy' | 'matching-dual';
|
|
30
|
+
export type RuntimeDeliveryBootstrapReadResult = {
|
|
31
|
+
bootstrap: RuntimeDeliveryBootstrapLockfile;
|
|
32
|
+
source: RuntimeDeliveryBootstrapSource;
|
|
33
|
+
};
|
|
34
|
+
/**
|
|
35
|
+
* Accepts the current backend-authorized trust shape and the temporary legacy
|
|
36
|
+
* wire shape. Explicit legacy non-authoritative modes must never create a
|
|
37
|
+
* package-managed bootstrap.
|
|
38
|
+
*/
|
|
39
|
+
export declare function normalizeRuntimeDeliveryBootstrap(value: unknown): RuntimeDeliveryConfig | undefined;
|
|
40
|
+
export declare function createRuntimeDeliveryBootstrapLockfile(params: {
|
|
41
|
+
identity: RuntimeDeliveryProjectIdentity;
|
|
42
|
+
runtimeDelivery: unknown;
|
|
43
|
+
}): RuntimeDeliveryBootstrapLockfile | undefined;
|
|
44
|
+
export declare function parseRuntimeDeliveryBootstrapLockfile(value: unknown, expectedIdentity?: RuntimeDeliveryProjectIdentity): RuntimeDeliveryBootstrapLockfile;
|
|
45
|
+
export declare function runtimeDeliveryBootstrapPath(projectRoot: string): string;
|
|
46
|
+
export declare function legacyRuntimeDeliveryBootstrapPath(projectRoot: string): string;
|
|
47
|
+
export declare function addRuntimeDeliveryBootstrapGitignoreRules(content: string): string;
|
|
48
|
+
export declare function readRuntimeDeliveryLockfile(params: {
|
|
49
|
+
projectRoot: string;
|
|
50
|
+
expectedIdentity?: RuntimeDeliveryProjectIdentity;
|
|
51
|
+
}): RuntimeDeliveryBootstrapLockfile | null;
|
|
52
|
+
export declare function inspectRuntimeDeliveryBootstrap(params: {
|
|
53
|
+
projectRoot: string;
|
|
54
|
+
expectedIdentity?: RuntimeDeliveryProjectIdentity;
|
|
55
|
+
}): RuntimeDeliveryBootstrapReadResult | null;
|
|
56
|
+
export declare function readRuntimeDeliveryBootstrap(params: {
|
|
57
|
+
projectRoot: string;
|
|
58
|
+
expectedIdentity?: RuntimeDeliveryProjectIdentity;
|
|
59
|
+
}): RuntimeDeliveryBootstrapLockfile | null;
|
|
60
|
+
export declare function serializeRuntimeDeliveryBootstrapLockfile(bootstrap: RuntimeDeliveryBootstrapLockfile): string;
|
|
61
|
+
export declare function writeRuntimeDeliveryBootstrapLockfile(params: {
|
|
62
|
+
projectRoot: string;
|
|
63
|
+
bootstrap: RuntimeDeliveryBootstrapLockfile;
|
|
64
|
+
}): Promise<string>;
|
|
65
|
+
export declare function removeRuntimeDeliveryBootstrapLockfile(projectRoot: string): Promise<string | null>;
|
|
66
|
+
export declare function removeLegacyRuntimeDeliveryBootstrap(projectRoot: string): Promise<string | null>;
|
|
67
|
+
export declare function removeAllRuntimeDeliveryBootstraps(projectRoot: string): Promise<string[]>;
|
|
68
|
+
export declare function ensureRuntimeDeliveryBootstrapGitignore(projectRoot: string): Promise<string>;
|