@gfean/react-native-bundle-drop 0.10.0 → 0.11.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.
Files changed (107) hide show
  1. package/BundleDrop.podspec +17 -20
  2. package/README.md +60 -1
  3. package/android/build.gradle +4 -0
  4. package/android/src/main/java/com/bundledrop/BundleDropFileOps.kt +20 -0
  5. package/android/src/main/java/com/bundledrop/BundleDropModule.kt +4 -1
  6. package/android/src/main/java/com/bundledrop/BundleDropNativePaths.kt +5 -1
  7. package/docs/native-fingerprint.md +211 -0
  8. package/expo/android/build.gradle +61 -56
  9. package/ios/BundleDropLocator.swift +12 -0
  10. package/ios/BundleDropModule.swift +31 -13
  11. package/ios/BundleDropReactContent.swift +54 -0
  12. package/ios/BundleDropStartupRecovery.swift +48 -2
  13. package/ios/BundleDropStartupRecoveryAdapter.swift +87 -30
  14. package/lib/CLI/cli.js +9 -0
  15. package/lib/CLI/scripts/doctor.js +18 -7
  16. package/lib/CLI/scripts/expo/configure-expo.js +8 -3
  17. package/lib/CLI/scripts/fingerprint-cli.d.ts +12 -0
  18. package/lib/CLI/scripts/fingerprint-cli.js +36 -0
  19. package/lib/CLI/scripts/native/write-runtime-identity.js +3 -1
  20. package/lib/CLI/scripts/sight-ota.js +12 -3
  21. package/lib/CLI/scripts/upload-cli.d.ts +1 -0
  22. package/lib/CLI/scripts/upload-cli.js +35 -0
  23. package/lib/context.js +9 -1
  24. package/lib/errors.d.ts +2 -1
  25. package/lib/errors.js +2 -1
  26. package/lib/expo/buildIdentity.d.ts +1 -1
  27. package/lib/expo/buildIdentity.js +3 -0
  28. package/lib/expo/runtimeVersion.d.ts +10 -0
  29. package/lib/expo/runtimeVersion.js +11 -9
  30. package/lib/fingerprint/client.d.ts +5 -0
  31. package/lib/fingerprint/client.js +21 -0
  32. package/lib/fingerprint/collect.d.ts +3 -0
  33. package/lib/fingerprint/collect.js +116 -0
  34. package/lib/fingerprint/config.d.ts +14 -0
  35. package/lib/fingerprint/config.js +60 -0
  36. package/lib/fingerprint/normalizeBuildNumber.d.ts +4 -0
  37. package/lib/fingerprint/normalizeBuildNumber.js +55 -0
  38. package/lib/fingerprint/normalizeIosBuildNumber.d.ts +4 -0
  39. package/lib/fingerprint/normalizeIosBuildNumber.js +62 -0
  40. package/lib/fingerprint/types.d.ts +29 -0
  41. package/lib/fingerprint/types.js +2 -0
  42. package/lib/fingerprint/worker.d.ts +1 -0
  43. package/lib/fingerprint/worker.js +24 -0
  44. package/lib/fs/installedReportHistory.d.ts +2 -0
  45. package/lib/fs/installedReportHistory.js +55 -0
  46. package/lib/loadConfig.d.ts +6 -2
  47. package/lib/manager/downloadAndInstall.d.ts +1 -0
  48. package/lib/manager/downloadAndInstall.js +4 -0
  49. package/lib/manager/pendingRollback.d.ts +11 -0
  50. package/lib/manager/pendingRollback.js +54 -0
  51. package/lib/manager/reporting.d.ts +1 -0
  52. package/lib/manager/reporting.js +23 -6
  53. package/lib/manager/updateState.d.ts +3 -0
  54. package/lib/manager/updateState.js +1 -0
  55. package/lib/metro.js +3 -0
  56. package/lib/native/bundleDropNative.d.ts +2 -0
  57. package/lib/native/bundleDropNative.js +15 -5
  58. package/lib/patch-engine/installFromPatchSet.js +1 -1
  59. package/lib/patch-engine/patchTransport.d.ts +2 -1
  60. package/lib/patch-engine/patchTransport.js +4 -2
  61. package/lib/runtime/service.d.ts +2 -1
  62. package/lib/runtime/service.js +77 -22
  63. package/lib/scripts/bundle.js +10 -0
  64. package/lib/scripts/canonicalArtifact.d.ts +3 -0
  65. package/lib/scripts/canonicalArtifact.js +3 -1
  66. package/lib/scripts/exportProject.js +11 -0
  67. package/lib/scripts/nativeBuildNumber.d.ts +9 -0
  68. package/lib/scripts/nativeBuildNumber.js +110 -0
  69. package/lib/scripts/runtimeCompatibilityMetadata.d.ts +10 -0
  70. package/lib/scripts/runtimeCompatibilityMetadata.js +13 -0
  71. package/package.json +25 -11
  72. package/third_party/expo-fingerprint/LICENSE +22 -0
  73. package/third_party/expo-fingerprint/NOTICE +5 -0
  74. package/third_party/expo-fingerprint/PROVENANCE.md +41 -0
  75. package/third_party/expo-fingerprint/build/Config.js +122 -0
  76. package/third_party/expo-fingerprint/build/Dedup.js +89 -0
  77. package/third_party/expo-fingerprint/build/ExpoConfig.js +93 -0
  78. package/third_party/expo-fingerprint/build/ExpoConfigLoader.js +201 -0
  79. package/third_party/expo-fingerprint/build/ExpoResolver.js +84 -0
  80. package/third_party/expo-fingerprint/build/Fingerprint.js +111 -0
  81. package/third_party/expo-fingerprint/build/Fingerprint.types.js +3 -0
  82. package/third_party/expo-fingerprint/build/Options.js +140 -0
  83. package/third_party/expo-fingerprint/build/Presets.js +62 -0
  84. package/third_party/expo-fingerprint/build/ProjectWorkflow.js +163 -0
  85. package/third_party/expo-fingerprint/build/Sort.js +46 -0
  86. package/third_party/expo-fingerprint/build/hash/FileHookTransform.js +42 -0
  87. package/third_party/expo-fingerprint/build/hash/Hash.js +264 -0
  88. package/third_party/expo-fingerprint/build/hash/ReactImportsPatcher.js +344 -0
  89. package/third_party/expo-fingerprint/build/index.js +23 -0
  90. package/third_party/expo-fingerprint/build/sourcer/AutolinkingConfig.js +130 -0
  91. package/third_party/expo-fingerprint/build/sourcer/Bare.js +231 -0
  92. package/third_party/expo-fingerprint/build/sourcer/Expo.js +376 -0
  93. package/third_party/expo-fingerprint/build/sourcer/Packages.js +54 -0
  94. package/third_party/expo-fingerprint/build/sourcer/PatchPackage.js +22 -0
  95. package/third_party/expo-fingerprint/build/sourcer/SourceSkips.js +79 -0
  96. package/third_party/expo-fingerprint/build/sourcer/Sourcer.js +58 -0
  97. package/third_party/expo-fingerprint/build/sourcer/Utils.js +129 -0
  98. package/third_party/expo-fingerprint/build/types/module.d.js +2 -0
  99. package/third_party/expo-fingerprint/build/utils/Concurrency.js +47 -0
  100. package/third_party/expo-fingerprint/build/utils/Env.js +28 -0
  101. package/third_party/expo-fingerprint/build/utils/Path.js +161 -0
  102. package/third_party/expo-fingerprint/build/utils/Predicates.js +6 -0
  103. package/third_party/expo-fingerprint/build/utils/Profile.js +41 -0
  104. package/third_party/expo-fingerprint/build/utils/Spawn.js +38 -0
  105. package/third_party/expo-fingerprint/build/utils/SpawnIPC.js +28 -0
  106. package/third_party/expo-fingerprint/scheme-1-contract.json +132 -0
  107. package/third_party/expo-fingerprint/upstream-files.json +37 -0
@@ -0,0 +1,55 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.MAX_REPORTED_INSTALL_HASHES = void 0;
7
+ exports.mergeInstalledReportHistory = mergeInstalledReportHistory;
8
+ const fs_1 = __importDefault(require("../native/fs"));
9
+ const context_1 = require("../context");
10
+ const fsUtils_1 = require("./fsUtils");
11
+ exports.MAX_REPORTED_INSTALL_HASHES = 50;
12
+ // Serialize read/merge/write so simultaneous reports for different hashes cannot
13
+ // overwrite one another. This file outlives disposable current-bundle metadata.
14
+ let pendingWrite = Promise.resolve();
15
+ function mergeInstalledReportHistory(installId, legacyHashes, reportedHash) {
16
+ const path = `${context_1.BUNDLE_DROP_ROOT}/installed-report-history.json`;
17
+ const scope = JSON.stringify([context_1.config.serverUrl, context_1.config.org.slug, context_1.config.project.slug, installId]);
18
+ const operation = pendingWrite.then(async () => {
19
+ let existing;
20
+ if (await fs_1.default.exists(path)) {
21
+ const contents = await fs_1.default.readFile(path, 'utf8');
22
+ try {
23
+ existing = JSON.parse(contents);
24
+ }
25
+ catch {
26
+ existing = null;
27
+ }
28
+ if (typeof existing?.scope !== 'string' || !Array.isArray(existing.hashes)
29
+ || existing.hashes.some(hash => typeof hash !== 'string')) {
30
+ existing = null;
31
+ }
32
+ }
33
+ // Legacy metadata has no scope. Migrate it only when creating the ledger,
34
+ // never after a known installation/project change.
35
+ const sameScope = existing?.scope === scope;
36
+ const hashes = [...new Set([
37
+ ...(sameScope ? existing.hashes : []),
38
+ ...(existing === undefined ? legacyHashes : []),
39
+ ])];
40
+ if (reportedHash) {
41
+ const previous = hashes.indexOf(reportedHash);
42
+ if (previous !== -1)
43
+ hashes.splice(previous, 1);
44
+ hashes.push(reportedHash);
45
+ }
46
+ const bounded = hashes.slice(-exports.MAX_REPORTED_INSTALL_HASHES);
47
+ if (!sameScope || JSON.stringify(existing.hashes) !== JSON.stringify(bounded)) {
48
+ await (0, fsUtils_1.ensureDir)(context_1.BUNDLE_DROP_ROOT);
49
+ await fs_1.default.writeFile(path, JSON.stringify({ scope, hashes: bounded }), 'utf8');
50
+ }
51
+ return bounded;
52
+ });
53
+ pendingWrite = operation.catch(() => { });
54
+ return operation;
55
+ }
@@ -1,3 +1,4 @@
1
+ import type { FingerprintOptions } from './fingerprint/types';
1
2
  /**
2
3
  * Shape of `bundle.drop.config.js` after it is loaded through Metro.
3
4
  */
@@ -39,13 +40,16 @@ export type BundleDropProjectConfig = {
39
40
  * declaration with the concrete values embedded in the build.
40
41
  */
41
42
  runtimeVersion?: {
43
+ /** Missing selector preserves manual runtimes. Fingerprinting is experimental. */
44
+ compatibilitySource?: 'manual' | 'fingerprint';
45
+ fingerprint?: FingerprintOptions;
42
46
  /** iOS runtime version. */
43
47
  ios?: string | {
44
- source: 'appVersion' | 'nativeVersion';
48
+ source: 'appVersion' | 'nativeVersion' | 'native';
45
49
  };
46
50
  /** Android runtime version. */
47
51
  android?: string | {
48
- source: 'appVersion' | 'nativeVersion';
52
+ source: 'appVersion' | 'nativeVersion' | 'native';
49
53
  };
50
54
  } | {
51
55
  /** Explicitly resolve concrete values from the evaluated Expo app config. */
@@ -15,6 +15,7 @@ export type DownloadUpdateResult = {
15
15
  } | {
16
16
  status: 'rollback';
17
17
  reason?: string;
18
+ pendingApply?: boolean;
18
19
  };
19
20
  type DownloadOptions = {
20
21
  channelName?: string;
@@ -145,6 +145,10 @@ async function downloadAndStageUpdate(options, onStatusUpdate) {
145
145
  projectSlug: project.slug,
146
146
  platform,
147
147
  runtimeVersionValue: serverRuntimeVersion,
148
+ // The resolve decision supplies this target's full ZIP. Managed
149
+ // capability rejection must instead retain its bounded refresh path.
150
+ allowUnmanagedPatchAuthFallback: !unresolvedCheckResult.runtimeDelivery &&
151
+ !checkResult.runtimeDelivery && checkResult.fallback?.mode === 'full',
148
152
  statusCb,
149
153
  });
150
154
  if (!installResult) {
@@ -0,0 +1,11 @@
1
+ export type PendingRollback = {
2
+ schemaVersion: 1;
3
+ channelName: string;
4
+ currentHash: string | null;
5
+ runtimeVersion: string | null;
6
+ reason?: string;
7
+ };
8
+ export declare function readPendingRollback(): Promise<PendingRollback | null>;
9
+ export declare function stageRollback(channelName: string, reason?: string): Promise<void>;
10
+ export declare function clearPendingRollback(): Promise<void>;
11
+ export declare function isPendingRollbackCurrent(intent: PendingRollback, channelName: string): Promise<boolean>;
@@ -0,0 +1,54 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.readPendingRollback = readPendingRollback;
7
+ exports.stageRollback = stageRollback;
8
+ exports.clearPendingRollback = clearPendingRollback;
9
+ exports.isPendingRollbackCurrent = isPendingRollbackCurrent;
10
+ const context_1 = require("../context");
11
+ const bundlePointer_1 = require("../fs/bundlePointer");
12
+ const fsUtils_1 = require("../fs/fsUtils");
13
+ const fs_1 = __importDefault(require("../native/fs"));
14
+ const PENDING_ROLLBACK_PATH = `${context_1.BUNDLE_DROP_ROOT}/pending-rollback.json`;
15
+ async function readPendingRollback() {
16
+ try {
17
+ if (!await fs_1.default.exists(PENDING_ROLLBACK_PATH))
18
+ return null;
19
+ const value = JSON.parse(await fs_1.default.readFile(PENDING_ROLLBACK_PATH, 'utf8'));
20
+ if (value?.schemaVersion !== 1 ||
21
+ typeof value.channelName !== 'string' ||
22
+ !(value.currentHash === null ||
23
+ (typeof value.currentHash === 'string' && /^[a-f0-9]{64}$/.test(value.currentHash))) ||
24
+ !(value.runtimeVersion === null || typeof value.runtimeVersion === 'string') ||
25
+ !(value.reason === undefined || typeof value.reason === 'string')) {
26
+ throw new Error('Invalid pending BundleDrop rollback');
27
+ }
28
+ return value;
29
+ }
30
+ catch (error) {
31
+ console.warn('⚠️ Ignoring unreadable BundleDrop pending rollback:', error);
32
+ return null;
33
+ }
34
+ }
35
+ async function stageRollback(channelName, reason) {
36
+ const intent = {
37
+ schemaVersion: 1,
38
+ channelName,
39
+ currentHash: await (0, bundlePointer_1.readCurrentBundleHash)(),
40
+ runtimeVersion: context_1.runtimeVersion ?? null,
41
+ reason,
42
+ };
43
+ await (0, fsUtils_1.ensureDir)(context_1.BUNDLE_DROP_ROOT);
44
+ await (0, fsUtils_1.atomicWriteJson)(PENDING_ROLLBACK_PATH, intent);
45
+ }
46
+ async function clearPendingRollback() {
47
+ if (await fs_1.default.exists(PENDING_ROLLBACK_PATH))
48
+ await fs_1.default.unlink(PENDING_ROLLBACK_PATH);
49
+ }
50
+ async function isPendingRollbackCurrent(intent, channelName) {
51
+ return intent.channelName === channelName &&
52
+ intent.runtimeVersion === (context_1.runtimeVersion ?? null) &&
53
+ intent.currentHash === await (0, bundlePointer_1.readCurrentBundleHash)();
54
+ }
@@ -7,6 +7,7 @@ export type FailedBundleRecord = {
7
7
  runtimeVersion?: string;
8
8
  previousHash?: string;
9
9
  };
10
+ export declare function preserveInstalledReportHistory(info: BundleInfo): Promise<void>;
10
11
  export declare function reportInstalledIfReady(state?: {
11
12
  hasBundle?: boolean;
12
13
  info?: BundleInfo | null;
@@ -1,5 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.preserveInstalledReportHistory = preserveInstalledReportHistory;
3
4
  exports.reportInstalledIfReady = reportInstalledIfReady;
4
5
  exports.reportLocalRollback = reportLocalRollback;
5
6
  const context_1 = require("../context");
@@ -9,11 +10,27 @@ const bundleDropNative_1 = require("../native/bundleDropNative");
9
10
  const installId_1 = require("../fs/installId");
10
11
  const userProperties_1 = require("../fs/userProperties");
11
12
  const initState_1 = require("../runtime/initState");
12
- const MAX_REPORTED_INSTALL_HASHES = 50;
13
+ const installedReportHistory_1 = require("../fs/installedReportHistory");
13
14
  const installedReportInFlightHashes = new Set();
14
15
  function appendReportedHash(existing, hash) {
15
16
  const next = [...(existing || []).filter(value => value !== hash), hash];
16
- return next.slice(-MAX_REPORTED_INSTALL_HASHES);
17
+ return next.slice(-installedReportHistory_1.MAX_REPORTED_INSTALL_HASHES);
18
+ }
19
+ function legacyReportedHashes(info) {
20
+ return [
21
+ ...(info.installedReportedHashes ?? []),
22
+ ...(info.lastInstalledReportedHash ? [info.lastInstalledReportedHash] : []),
23
+ ];
24
+ }
25
+ async function preserveInstalledReportHistory(info) {
26
+ try {
27
+ const installId = await (0, installId_1.getOrCreateInstallId)();
28
+ await (0, installedReportHistory_1.mergeInstalledReportHistory)(installId, legacyReportedHashes(info));
29
+ }
30
+ catch (e) {
31
+ // Reporting persistence must not prevent authoritative embedded recovery.
32
+ console.warn('⚠️ Failed to preserve install-report history:', e);
33
+ }
17
34
  }
18
35
  async function getReportingState() {
19
36
  const info = await (0, bundleInfo_1.readBundleInfo)();
@@ -33,10 +50,6 @@ async function reportInstalledIfReady(state) {
33
50
  return;
34
51
  if (hasBundle === false)
35
52
  return;
36
- if (info.lastInstalledReportedHash === info.hash)
37
- return;
38
- if (info.installedReportedHashes?.includes(info.hash))
39
- return;
40
53
  if (installedReportInFlightHashes.has(info.hash))
41
54
  return;
42
55
  const reportedHash = info.hash;
@@ -46,6 +59,9 @@ async function reportInstalledIfReady(state) {
46
59
  (0, installId_1.getOrCreateInstallId)(),
47
60
  (0, userProperties_1.getCurrentUserProperties)(),
48
61
  ]);
62
+ const history = await (0, installedReportHistory_1.mergeInstalledReportHistory)(installId, legacyReportedHashes(info));
63
+ if (history.includes(reportedHash))
64
+ return;
49
65
  const appEnvironment = (0, initState_1.getBundleDropRuntimeConfig)()?.environment ?? null;
50
66
  await (0, clientApi_1.reportInstalled)(context_1.config.project.slug, reportedHash, {
51
67
  channelName: info.channelName,
@@ -55,6 +71,7 @@ async function reportInstalledIfReady(state) {
55
71
  environment: appEnvironment,
56
72
  userProperties: Object.keys(userProperties).length > 0 ? userProperties : undefined,
57
73
  });
74
+ await (0, installedReportHistory_1.mergeInstalledReportHistory)(installId, [], reportedHash);
58
75
  const latestInfo = await (0, bundleInfo_1.readBundleInfo)();
59
76
  if (latestInfo) {
60
77
  const nextInfo = {
@@ -7,6 +7,9 @@ export type ApplyUpdateResult = {
7
7
  status: 'disabled';
8
8
  } | {
9
9
  status: 'alreadyApplied';
10
+ } | {
11
+ status: 'blocked';
12
+ reason: 'ROLLBACK_REVALIDATION_FAILED';
10
13
  } | {
11
14
  status: 'blocked';
12
15
  reason: 'BUNDLE_PREVIOUSLY_FAILED';
@@ -57,6 +57,7 @@ const reconcileAppliedBundleOnLaunch = async (cached) => {
57
57
  const state = await (0, exports.getUpdateState)({ ...cached, bundlePath });
58
58
  if (!state.hasBundle) {
59
59
  if (state.info) {
60
+ await (0, reporting_1.preserveInstalledReportHistory)(state.info);
60
61
  await (0, bundleInfo_1.deleteBundleInfo)();
61
62
  }
62
63
  return null;
package/lib/metro.js CHANGED
@@ -81,6 +81,9 @@ function withBundleDrop(config, options = {}) {
81
81
  const generatedConfigPath = writeGeneratedRuntimeConfig({
82
82
  projectRoot,
83
83
  runtimeDelivery: resolveRuntimeDelivery(projectRoot, baseConfig),
84
+ ...(baseConfig.runtimeVersion?.compatibilitySource === 'fingerprint'
85
+ ? { runtimeVersion: { ios: { source: 'native' }, android: { source: 'native' } } }
86
+ : {}),
84
87
  });
85
88
  return mergeMetroAlias(config, generatedConfigPath);
86
89
  }
@@ -41,6 +41,8 @@ export type StartupRollbackResult = {
41
41
  toEmbedded: boolean;
42
42
  hash?: string;
43
43
  };
44
+ /** undefined identifies an older binary; null identifies missing required native data. */
45
+ export declare function getNativeRuntimeVersion(): string | null | undefined;
44
46
  export declare function isBundleDropNativeAvailable(): boolean;
45
47
  export declare function isExpoOtaStartupEnabledNative(): boolean;
46
48
  export declare function isStartupRecoveryAvailableNative(): boolean;
@@ -1,5 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.getNativeRuntimeVersion = getNativeRuntimeVersion;
3
4
  exports.isBundleDropNativeAvailable = isBundleDropNativeAvailable;
4
5
  exports.isExpoOtaStartupEnabledNative = isExpoOtaStartupEnabledNative;
5
6
  exports.isStartupRecoveryAvailableNative = isStartupRecoveryAvailableNative;
@@ -27,6 +28,16 @@ const BundleDropExpoIdentity = react_native_1.NativeModules.BundleDropExpoIdenti
27
28
  // the running identity or the attempt acknowledged by reportHealthy().
28
29
  const startupRecoverySelectedHash = readStartupRecoverySelectedHash(BundleDrop);
29
30
  const startupRecoveryAttempt = readStartupRecoveryAttempt(BundleDrop);
31
+ // New Architecture host objects expose constants through getters without own
32
+ // property descriptors. Read the value once rather than testing hasOwnProperty.
33
+ const capturedNativeRuntime = BundleDrop?.nativeRuntimeVersion;
34
+ const nativeRuntimeVersion = capturedNativeRuntime === undefined
35
+ ? undefined
36
+ : nonEmptyString(capturedNativeRuntime);
37
+ /** undefined identifies an older binary; null identifies missing required native data. */
38
+ function getNativeRuntimeVersion() {
39
+ return nativeRuntimeVersion;
40
+ }
30
41
  let hasWarnedAboutStartupRecoveryCapability = false;
31
42
  function isRecord(value) {
32
43
  return !!value && typeof value === 'object' && !Array.isArray(value);
@@ -38,12 +49,11 @@ function canonicalHash(value) {
38
49
  return typeof value === 'string' && SHA256_HASH_PATTERN.test(value) ? value : null;
39
50
  }
40
51
  function readStartupRecoverySelectedHash(nativeModule) {
41
- if (!nativeModule || !Object.prototype.hasOwnProperty.call(nativeModule, 'startupRecoverySelectedHash')) {
52
+ // New Architecture constants can be getter-backed without an own descriptor.
53
+ const selectedHash = nativeModule?.startupRecoverySelectedHash;
54
+ if (selectedHash === undefined)
42
55
  return undefined;
43
- }
44
- if (nativeModule.startupRecoverySelectedHash == null)
45
- return null;
46
- return canonicalHash(nativeModule.startupRecoverySelectedHash);
56
+ return canonicalHash(selectedHash);
47
57
  }
48
58
  function nonNegativeInteger(value) {
49
59
  return Number.isSafeInteger(value) && value >= 0 ? value : null;
@@ -59,7 +59,7 @@ async function installFromPatchSet(params) {
59
59
  await fs_1.default.downloadFile(patchesUrl, tempZipPath);
60
60
  }
61
61
  catch (e) {
62
- throw new errors_1.InstallPhaseError('download', e);
62
+ throw new errors_1.InstallPhaseError('download', e, 'patch-set');
63
63
  }
64
64
  const actualPatchSetHash = await fs_1.default.sha256File(tempZipPath);
65
65
  if (actualPatchSetHash !== patchSetHash) {
@@ -14,7 +14,8 @@ type TryInstallPatchTransportParams = {
14
14
  projectSlug: string;
15
15
  platform: 'ios' | 'android';
16
16
  runtimeVersionValue?: string;
17
+ allowUnmanagedPatchAuthFallback?: boolean;
17
18
  statusCb?: (status: string) => void;
18
19
  };
19
- export declare const tryInstallPatchTransport: ({ target, projectSlug, platform, runtimeVersionValue, statusCb, }: TryInstallPatchTransportParams) => Promise<InstallResult | null>;
20
+ export declare const tryInstallPatchTransport: ({ target, projectSlug, platform, runtimeVersionValue, allowUnmanagedPatchAuthFallback, statusCb, }: TryInstallPatchTransportParams) => Promise<InstallResult | null>;
20
21
  export {};
@@ -7,6 +7,7 @@ const clientApi_1 = require("../api/clientApi");
7
7
  const installFromPatchSet_1 = require("./installFromPatchSet");
8
8
  const patchOperations_1 = require("./patchOperations");
9
9
  const artifactCapability_1 = require("../runtime-delivery/artifactCapability");
10
+ const errors_1 = require("../errors");
10
11
  const PATCH_FAILURE_REPORT_TIMEOUT_MS = 1500;
11
12
  const reportPatchInstallFailure = async ({ projectSlug, platform, runtimeVersionValue, baseHash, targetHash, algorithm, error, }) => {
12
13
  try {
@@ -41,7 +42,7 @@ const reportPatchInstallFailureBeforeFallback = async (params) => {
41
42
  clearTimeout(timeout);
42
43
  }
43
44
  };
44
- const tryInstallPatchTransport = async ({ target, projectSlug, platform, runtimeVersionValue, statusCb, }) => {
45
+ const tryInstallPatchTransport = async ({ target, projectSlug, platform, runtimeVersionValue, allowUnmanagedPatchAuthFallback = false, statusCb, }) => {
45
46
  if (target.mode !== 'patch' ||
46
47
  !target.baseHash ||
47
48
  !(0, patchOperations_1.isSupportedPatchAlgorithm)(target.patchSet?.algorithm) ||
@@ -71,7 +72,8 @@ const tryInstallPatchTransport = async ({ target, projectSlug, platform, runtime
71
72
  });
72
73
  }
73
74
  catch (e) {
74
- if ((0, artifactCapability_1.isArtifactCapabilityRejected)(e))
75
+ if ((0, artifactCapability_1.isArtifactCapabilityRejected)(e) && !(allowUnmanagedPatchAuthFallback &&
76
+ (0, errors_1.isInstallPhaseError)(e) && e.downloadSource === 'patch-set'))
75
77
  throw e;
76
78
  await reportPatchInstallFailureBeforeFallback({
77
79
  projectSlug,
@@ -106,9 +106,10 @@ export declare function getObservabilityContext(): Promise<ObservabilityContext>
106
106
  * Read the current local update state from disk.
107
107
  */
108
108
  export declare function getRuntimeUpdateState(): Promise<{
109
+ pendingRollback?: boolean;
110
+ pendingApply: boolean;
109
111
  hasBundle: boolean;
110
112
  info: BundleInfo;
111
- pendingApply: boolean;
112
113
  }>;
113
114
  /**
114
115
  * Named-export variant of `useBundleDrop().checkLatest()`.
@@ -33,6 +33,7 @@ const bundlePointer_1 = require("../fs/bundlePointer");
33
33
  const downloadAndInstall_1 = require("../manager/downloadAndInstall");
34
34
  const updateCheck_1 = require("../manager/updateCheck");
35
35
  const rollbackState_1 = require("../manager/rollbackState");
36
+ const pendingRollback_1 = require("../manager/pendingRollback");
36
37
  const updateState_1 = require("../manager/updateState");
37
38
  const initState_1 = require("./initState");
38
39
  const DEFAULT_STATUS = 'Click the button to check for updates';
@@ -164,7 +165,9 @@ function getApplyStatus(result) {
164
165
  : result.status === 'noBundle'
165
166
  ? '⚠️ No downloaded bundle to apply'
166
167
  : result.status === 'blocked'
167
- ? '⚠️ Update previously failed on this device'
168
+ ? result.reason === 'ROLLBACK_REVALIDATION_FAILED'
169
+ ? '⚠️ Rollback decision changed or could not be revalidated; check for updates again'
170
+ : '⚠️ Update previously failed on this device'
168
171
  : 'ℹ️ Bundle already applied';
169
172
  }
170
173
  function requestRuntimeRestart() {
@@ -173,9 +176,56 @@ function requestRuntimeRestart() {
173
176
  }
174
177
  async function applyAuthoritativeRollback(reason) {
175
178
  const result = await (0, rollbackState_1.rollbackStartupBundle)(isCurrentRevokedRollback(reason));
176
- if (result?.rolledBack) {
179
+ if (!result)
180
+ return { status: 'blocked', reason: 'ROLLBACK_REVALIDATION_FAILED' };
181
+ // A bookkeeping failure must not prevent confirmed-revocation recovery.
182
+ await (0, pendingRollback_1.clearPendingRollback)().catch(error => {
183
+ console.warn('⚠️ Failed to clear pending BundleDrop rollback:', error);
184
+ });
185
+ if (result.rolledBack) {
177
186
  requestRuntimeRestart();
187
+ return { status: 'applied' };
188
+ }
189
+ return { status: 'alreadyApplied' };
190
+ }
191
+ async function handleDownloadRollback(result) {
192
+ if (result.status !== 'rollback') {
193
+ await (0, pendingRollback_1.clearPendingRollback)();
194
+ return result;
195
+ }
196
+ const runtime = (0, initState_1.assertBundleDropInitialized)();
197
+ if (runtime.policy === 'manual' && !isCurrentRevokedRollback(result.reason)) {
198
+ await (0, pendingRollback_1.stageRollback)(runtime.channelName, result.reason);
199
+ return { ...result, pendingApply: true };
178
200
  }
201
+ await applyAuthoritativeRollback(result.reason);
202
+ return result;
203
+ }
204
+ async function applyPendingRollback() {
205
+ const intent = await (0, pendingRollback_1.readPendingRollback)();
206
+ if (!intent)
207
+ return null;
208
+ const runtime = (0, initState_1.assertBundleDropInitialized)();
209
+ if (!await (0, pendingRollback_1.isPendingRollbackCurrent)(intent, runtime.channelName)) {
210
+ await (0, pendingRollback_1.clearPendingRollback)();
211
+ return { status: 'blocked', reason: 'ROLLBACK_REVALIDATION_FAILED' };
212
+ }
213
+ // Refresh authority before native atomically selects and verifies the fallback.
214
+ const decision = await (0, updateCheck_1.checkForUpdate)(runtime.channelName);
215
+ if (decision?.action === 'ROLLBACK' && isCurrentRevokedRollback(decision.reason)) {
216
+ return applyAuthoritativeRollback(decision.reason);
217
+ }
218
+ if (decision?.action !== 'ROLLBACK' || decision.reason !== intent.reason) {
219
+ if (decision)
220
+ await (0, pendingRollback_1.clearPendingRollback)();
221
+ return { status: 'blocked', reason: 'ROLLBACK_REVALIDATION_FAILED' };
222
+ }
223
+ // A native recovery or another selection may have happened during the check.
224
+ if (!await (0, pendingRollback_1.isPendingRollbackCurrent)(intent, runtime.channelName)) {
225
+ await (0, pendingRollback_1.clearPendingRollback)();
226
+ return { status: 'blocked', reason: 'ROLLBACK_REVALIDATION_FAILED' };
227
+ }
228
+ return applyAuthoritativeRollback(decision.reason);
179
229
  }
180
230
  async function markActiveCandidateHealthy() {
181
231
  const markedHealthy = await (0, rollbackState_1.reportActiveBundleHealthy)();
@@ -186,12 +236,17 @@ async function markActiveCandidateHealthy() {
186
236
  }
187
237
  async function refreshState(cached) {
188
238
  const state = await (0, updateState_1.getUpdateState)(cached);
239
+ const intent = await (0, pendingRollback_1.readPendingRollback)();
240
+ const pendingRollback = !!intent &&
241
+ await (0, pendingRollback_1.isPendingRollbackCurrent)(intent, (0, initState_1.assertBundleDropInitialized)().channelName);
242
+ const pendingApply = state.pendingApply || pendingRollback;
189
243
  patchSnapshot({
190
244
  installedInfo: state.info || null,
191
- pendingApply: state.pendingApply,
245
+ pendingApply,
192
246
  hasBundle: state.hasBundle,
193
247
  });
194
- return state;
248
+ // Startup automatic bundle application must never consume a manual rollback intent.
249
+ return { ...state, pendingApply, ...(pendingRollback ? { pendingRollback: true } : {}) };
195
250
  }
196
251
  async function withBusy(fn) {
197
252
  if (updateFlowActive) {
@@ -253,7 +308,7 @@ async function runStartupFlow() {
253
308
  })();
254
309
  const { bundlePath } = await localStartupPromise;
255
310
  const pendingState = await refreshState({ bundlePath });
256
- if (pendingState.pendingApply) {
311
+ if (pendingState.pendingApply && !pendingState.pendingRollback) {
257
312
  if (runtime.policy === 'immediate') {
258
313
  emitStatus('♻️ Applying previously downloaded update...');
259
314
  const applied = await (0, updateState_1.applyUpdate)(statusCb, () => {
@@ -279,6 +334,9 @@ async function runStartupFlow() {
279
334
  if (!decision)
280
335
  return;
281
336
  if (decision.action === 'ROLLBACK') {
337
+ if (!isCurrentRevokedRollback(decision.reason) && (runtime.policy === 'manual' || runtime.checkOnly)) {
338
+ return;
339
+ }
282
340
  emitStatus('↩️ Server requested rollback...');
283
341
  await applyAuthoritativeRollback(decision.reason);
284
342
  return;
@@ -370,8 +428,11 @@ function initBundleDrop(options) {
370
428
  (0, bundleDropNative_1.warnIfStartupRecoveryUnavailableNative)();
371
429
  }
372
430
  }
373
- // Persist for the next cold start and for native path reads in this process.
374
- nativeOtaEnabledPromise = (0, bundleDropNative_1.setOtaEnabledNative)(config.enabled);
431
+ // Explicit app enablement persists across cold starts. Implicit Expo Debug
432
+ // suppression is local to this process and must not disable the Release app.
433
+ if (!useExpoDevelopmentFallback) {
434
+ nativeOtaEnabledPromise = (0, bundleDropNative_1.setOtaEnabledNative)(config.enabled);
435
+ }
375
436
  patchSnapshot({
376
437
  channelName: config.channelName,
377
438
  isEnabled: config.enabled,
@@ -450,10 +511,8 @@ async function downloadAndStage(extraStatusHandler) {
450
511
  }
451
512
  await waitForStartupIfNeeded();
452
513
  return withBusy(async () => {
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
- }
514
+ const downloadResult = await (0, downloadAndInstall_1.downloadUpdate)({ channelName: runtime.channelName }, status => emitStatus(status, extraStatusHandler));
515
+ const result = await handleDownloadRollback(downloadResult);
457
516
  const status = getDownloadStatus(result);
458
517
  if (status) {
459
518
  emitStatus(status, extraStatusHandler);
@@ -471,9 +530,7 @@ async function applyDownloadedUpdate(extraStatusHandler) {
471
530
  await waitForStartupIfNeeded();
472
531
  await nativeOtaEnabledPromise;
473
532
  return withBusy(async () => {
474
- const result = await (0, updateState_1.applyUpdate)(status => emitStatus(status, extraStatusHandler), () => {
475
- runtimeRestartRequested = true;
476
- });
533
+ const result = await applyPendingRollback() ?? await (0, updateState_1.applyUpdate)(status => emitStatus(status, extraStatusHandler), () => { runtimeRestartRequested = true; });
477
534
  const status = getApplyStatus(result);
478
535
  if (status) {
479
536
  emitStatus(status, extraStatusHandler);
@@ -551,11 +608,10 @@ async function installBundleFromListItem(bundle) {
551
608
  const canUseResolvedTransport = resolvedDecision?.action === 'INSTALL' &&
552
609
  (resolvedDecision.bundleHash ?? resolvedDecision.hash) === bundle.hash;
553
610
  if (usesManagedRuntimeDelivery && resolvedDecision?.action === 'ROLLBACK') {
554
- const result = {
611
+ const result = await handleDownloadRollback({
555
612
  status: 'rollback',
556
613
  reason: resolvedDecision.reason,
557
- };
558
- await applyAuthoritativeRollback(result.reason);
614
+ });
559
615
  const status = getDownloadStatus(result);
560
616
  if (status)
561
617
  emitStatus(status);
@@ -568,7 +624,7 @@ async function installBundleFromListItem(bundle) {
568
624
  status: MANAGED_LIST_INSTALL_NOT_AUTHORIZED_STATUS,
569
625
  };
570
626
  }
571
- const result = canUseResolvedTransport
627
+ let result = canUseResolvedTransport
572
628
  ? await (0, downloadAndInstall_1.downloadUpdate)({
573
629
  channelName: runtime.channelName,
574
630
  resolvedTarget: {
@@ -593,9 +649,7 @@ async function installBundleFromListItem(bundle) {
593
649
  channelName: runtime.channelName,
594
650
  onStatusUpdate: emitStatus,
595
651
  });
596
- if (usesManagedRuntimeDelivery && result.status === 'rollback') {
597
- await applyAuthoritativeRollback(result.reason);
598
- }
652
+ result = await handleDownloadRollback(result);
599
653
  if (result.status === 'staged') {
600
654
  const status = `✅ v${bundle.bundleVersion} downloaded. Will apply on next launch or when you call applyUpdate.`;
601
655
  emitStatus(status);
@@ -725,10 +779,11 @@ async function installBundle(hash, downloadUrl, bundleVersion, version, runtimeV
725
779
  return { status: 'incompatible' };
726
780
  }
727
781
  return withBusy(async () => {
728
- const result = await (0, downloadAndInstall_1.installBundle)(hash, downloadUrl, bundleVersion, version, runtimeVersion, {
782
+ const downloadResult = await (0, downloadAndInstall_1.installBundle)(hash, downloadUrl, bundleVersion, version, runtimeVersion, {
729
783
  channelName: runtime.channelName,
730
784
  onStatusUpdate: status => emitStatus(status, onStatusUpdate),
731
785
  });
786
+ const result = await handleDownloadRollback(downloadResult);
732
787
  const status = getDownloadStatus(result);
733
788
  if (status) {
734
789
  emitStatus(status, onStatusUpdate);
@@ -41,10 +41,13 @@ const fs = __importStar(require("fs"));
41
41
  const path = __importStar(require("path"));
42
42
  const bundleManifest_1 = require("../manifest/bundleManifest");
43
43
  const canonicalArtifact_1 = require("./canonicalArtifact");
44
+ const runtimeCompatibilityMetadata_1 = require("./runtimeCompatibilityMetadata");
45
+ const nativeBuildNumber_1 = require("./nativeBuildNumber");
44
46
  const projectRoot_1 = require("./projectRoot");
45
47
  Object.defineProperty(exports, "findProjectRoot", { enumerable: true, get: function () { return projectRoot_1.findProjectRoot; } });
46
48
  const resolveModule_1 = require("./resolveModule");
47
49
  const iosHermesDefault_1 = require("./iosHermesDefault");
50
+ const runtimeVersion_1 = require("../expo/runtimeVersion");
48
51
  const SENTRY_HERMES_OTA_DOCS_URL = 'https://bundledrop.app/docs/observability#sentry-and-hermes-ota-builds';
49
52
  const SENTRY_DEBUG_ID_MARKERS = ['//# debugId=', 'sentry-dbid-'];
50
53
  const runProcess = (spawnProcess, executable, args, options) => {
@@ -229,6 +232,11 @@ function runBundleScript(options = {}) {
229
232
  //eslint-disable-next-line
230
233
  const cfg = require(configPath);
231
234
  runtimeVersion = cfg?.runtimeVersion?.[platform];
235
+ if (cfg?.runtimeVersion?.compatibilitySource === 'fingerprint') {
236
+ const authority = (0, runtimeVersion_1.resolveBundleDropRuntimeVersionAuthority)(projectRoot, platform);
237
+ if (authority.source === 'bundle-drop')
238
+ runtimeVersion = authority.runtimeVersion;
239
+ }
232
240
  if (!runtimeVersion) {
233
241
  console.error(`❌ Missing runtimeVersion.${platform} in bundle.drop.config.js. Example: runtimeVersion: { ios: "1.0.0", android: "1.0.0" }`);
234
242
  process.exit(1);
@@ -341,6 +349,8 @@ function runBundleScript(options = {}) {
341
349
  platform: platform,
342
350
  appVersion,
343
351
  runtimeVersion,
352
+ runtimeCompatibility: (0, runtimeCompatibilityMetadata_1.runtimeCompatibilityMetadata)(cfg.runtimeVersion, platform, runtimeVersion),
353
+ buildNumber: (0, nativeBuildNumber_1.normalizeBuildNumber)(process.env.BUNDLE_DROP_BUILD_NUMBER, platform),
344
354
  bundlePath,
345
355
  assetsDir,
346
356
  outputDir,
@@ -1,9 +1,12 @@
1
+ import type { RuntimeCompatibilityMetadata } from './runtimeCompatibilityMetadata';
1
2
  export type CanonicalArtifactPlatform = 'ios' | 'android';
2
3
  export type CanonicalAssetTraversal = 'strict' | 'legacy-bare';
3
4
  export type BuildCanonicalArtifactOptions = {
4
5
  platform: CanonicalArtifactPlatform;
5
6
  appVersion: string;
6
7
  runtimeVersion: string;
8
+ runtimeCompatibility?: RuntimeCompatibilityMetadata;
9
+ buildNumber?: string | null;
7
10
  bundlePath: string;
8
11
  assetsDir: string;
9
12
  outputDir: string;
@@ -130,7 +130,7 @@ const collectLegacyBareAssets = (assetsDir) => {
130
130
  * ZIP roles. Framework-specific export commands must finish before this runs.
131
131
  */
132
132
  function buildCanonicalArtifact(options) {
133
- const { platform, appVersion, runtimeVersion, bundlePath, assetsDir, outputDir, sourceMapPath, assetTraversal = 'strict', } = options;
133
+ const { platform, appVersion, runtimeVersion, runtimeCompatibility = { compatibilitySource: 'manual' }, buildNumber, bundlePath, assetsDir, outputDir, sourceMapPath, assetTraversal = 'strict', } = options;
134
134
  if (!appVersion.trim())
135
135
  throw new Error('Canonical artifact requires an app version');
136
136
  if (!runtimeVersion.trim())
@@ -153,6 +153,8 @@ function buildCanonicalArtifact(options) {
153
153
  bundlePath: 'main.jsbundle',
154
154
  sizeInBytes: bundleBuffer.length,
155
155
  runtimeVersion,
156
+ ...runtimeCompatibility,
157
+ ...(buildNumber != null ? { buildNumber } : {}),
156
158
  };
157
159
  const metadataBuffer = Buffer.from(JSON.stringify(metadata, null, 2));
158
160
  const stagedFiles = new Map([