@gfean/react-native-bundle-drop 0.3.9 → 0.4.2

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 (80) hide show
  1. package/BundleDrop.podspec +9 -2
  2. package/README.md +19 -0
  3. package/android/build.gradle +43 -4
  4. package/android/src/main/cpp/CMakeLists.txt +45 -0
  5. package/android/src/main/cpp/bundle_drop_xdelta_jni.c +55 -0
  6. package/android/src/main/java/com/bundledrop/BundleDropBundleVerifier.kt +73 -0
  7. package/android/src/main/java/com/bundledrop/BundleDropFileOps.kt +193 -8
  8. package/android/src/main/java/com/bundledrop/BundleDropModule.kt +60 -7
  9. package/android/src/main/java/com/bundledrop/BundleDropOtaPrefs.kt +2 -12
  10. package/android/src/main/java/com/bundledrop/BundleDropOtaResolver.kt +208 -3
  11. package/android/src/main/java/com/bundledrop/BundleDropXdeltaNative.kt +57 -0
  12. package/ios/BundleDropBridge.m +27 -0
  13. package/ios/BundleDropBundleVerifier.swift +106 -0
  14. package/ios/BundleDropFileOps.swift +149 -0
  15. package/ios/BundleDropModule.swift +100 -11
  16. package/ios/BundleDropOtaResolver.swift +149 -3
  17. package/ios/BundleDropZipExtractor.m +75 -3
  18. package/lib/CLI/cli.js +1 -8
  19. package/lib/CLI/scripts/upload-cli.d.ts +0 -1
  20. package/lib/CLI/scripts/upload-cli.js +98 -36
  21. package/lib/api/client.d.ts +11 -1
  22. package/lib/api/client.js +84 -17
  23. package/lib/api/clientApi.d.ts +2 -1
  24. package/lib/api/clientApi.js +9 -0
  25. package/lib/api/types.d.ts +65 -13
  26. package/lib/bundleInfo.d.ts +2 -0
  27. package/lib/fs/bundlePointer.d.ts +2 -1
  28. package/lib/fs/bundlePointer.js +34 -6
  29. package/lib/fs/fsUtils.js +4 -1
  30. package/lib/injectImageResolver.js +82 -75
  31. package/lib/install/bundleInstallShared.d.ts +8 -0
  32. package/lib/install/bundleInstallShared.js +97 -0
  33. package/lib/install/bundleVerification.d.ts +5 -0
  34. package/lib/install/bundleVerification.js +34 -0
  35. package/lib/install/installFromZip.d.ts +2 -5
  36. package/lib/install/installFromZip.js +33 -68
  37. package/lib/loadConfig.js +12 -1
  38. package/lib/manager/downloadAndInstall.d.ts +9 -0
  39. package/lib/manager/downloadAndInstall.js +84 -24
  40. package/lib/manager/reporting.js +26 -2
  41. package/lib/manager/rollbackState.js +21 -12
  42. package/lib/manager/updateCheck.js +89 -11
  43. package/lib/manager/updateState.js +3 -9
  44. package/lib/manifest/bundleManifest.d.ts +33 -0
  45. package/lib/manifest/bundleManifest.js +298 -0
  46. package/lib/native/bundleDropNative.js +1 -2
  47. package/lib/native/fs.d.ts +14 -0
  48. package/lib/native/fs.js +35 -0
  49. package/lib/patch-engine/installFromPatchSet.d.ts +16 -0
  50. package/lib/patch-engine/installFromPatchSet.js +143 -0
  51. package/lib/patch-engine/patchOperations.d.ts +33 -0
  52. package/lib/patch-engine/patchOperations.js +77 -0
  53. package/lib/patch-engine/patchTransport.d.ts +18 -0
  54. package/lib/patch-engine/patchTransport.js +81 -0
  55. package/lib/patchAlgorithms.d.ts +4 -0
  56. package/lib/patchAlgorithms.js +9 -0
  57. package/lib/runtime/service.js +43 -9
  58. package/lib/scripts/bundle.d.ts +3 -0
  59. package/lib/scripts/bundle.js +197 -43
  60. package/lib/scripts/download-bundle.js +18 -7
  61. package/package.json +44 -6
  62. package/third_party/xdelta/NOTICE +7 -0
  63. package/third_party/xdelta/PROVENANCE.md +10 -0
  64. package/third_party/xdelta/bundle_drop_xdelta.c +252 -0
  65. package/third_party/xdelta/bundle_drop_xdelta.h +26 -0
  66. package/third_party/xdelta/xdelta3/LICENSE +176 -0
  67. package/third_party/xdelta/xdelta3/config.h +34 -0
  68. package/third_party/xdelta/xdelta3/xdelta3-cfgs.h +171 -0
  69. package/third_party/xdelta/xdelta3/xdelta3-decode.h +1219 -0
  70. package/third_party/xdelta/xdelta3/xdelta3-hash.h +159 -0
  71. package/third_party/xdelta/xdelta3/xdelta3-internal.h +385 -0
  72. package/third_party/xdelta/xdelta3/xdelta3-list.h +127 -0
  73. package/third_party/xdelta/xdelta3/xdelta3.c +4819 -0
  74. package/third_party/xdelta/xdelta3/xdelta3.h +1476 -0
  75. package/lib/CLI/scripts/init-native-config.d.ts +0 -18
  76. package/lib/CLI/scripts/init-native-config.js +0 -539
  77. package/lib/assetExtensions.d.ts +0 -4
  78. package/lib/assetExtensions.js +0 -35
  79. package/lib/scripts/upload-bundle.d.ts +0 -9
  80. package/lib/scripts/upload-bundle.js +0 -320
@@ -5,9 +5,18 @@ const context_1 = require("../context");
5
5
  const bundleInfo_1 = require("../bundleInfo");
6
6
  const bundlePointer_1 = require("../fs/bundlePointer");
7
7
  const installFromZip_1 = require("../install/installFromZip");
8
+ const patchTransport_1 = require("../patch-engine/patchTransport");
9
+ const bundleDropNative_1 = require("../native/bundleDropNative");
8
10
  const updateCheck_1 = require("./updateCheck");
9
11
  const errors_1 = require("../errors");
10
12
  const rollbackState_1 = require("./rollbackState");
13
+ async function restoreCurrentPointer(pointer) {
14
+ if (pointer) {
15
+ await (0, bundlePointer_1.writeCurrentBundlePointer)({ ...pointer, updatedAt: new Date().toISOString() });
16
+ return;
17
+ }
18
+ await (0, bundlePointer_1.deleteCurrentBundlePointer)();
19
+ }
11
20
  async function downloadAndStageUpdate(options, onStatusUpdate) {
12
21
  const { project } = context_1.config;
13
22
  const channelName = options?.channelName || context_1.defaultChannel;
@@ -19,10 +28,16 @@ async function downloadAndStageUpdate(options, onStatusUpdate) {
19
28
  ? {
20
29
  action: 'INSTALL',
21
30
  hash: resolvedTarget.hash,
31
+ bundleHash: resolvedTarget.hash,
22
32
  downloadUrl: resolvedTarget.downloadUrl,
23
33
  bundleVersion: resolvedTarget.bundleVersion,
24
34
  version: resolvedTarget.version,
25
35
  runtimeVersion: resolvedTarget.runtimeVersion,
36
+ manifestUrl: resolvedTarget.manifestUrl,
37
+ mode: resolvedTarget.mode ?? 'full',
38
+ baseHash: resolvedTarget.baseHash,
39
+ patchSet: resolvedTarget.patchSet,
40
+ fallback: resolvedTarget.fallback,
26
41
  }
27
42
  : await (0, updateCheck_1.checkForUpdate)(channelName, statusCb);
28
43
  if (!checkResult) {
@@ -48,7 +63,7 @@ async function downloadAndStageUpdate(options, onStatusUpdate) {
48
63
  skippedFailedBundle: true,
49
64
  skippedHash: checkResult.skippedHash,
50
65
  }
51
- : { status: 'upToDate' };
66
+ : { status: 'upToDate', reason: checkResult.reason };
52
67
  }
53
68
  if (checkResult.action === 'ROLLBACK') {
54
69
  statusCb?.('↩️ Rollback requested');
@@ -58,9 +73,19 @@ async function downloadAndStageUpdate(options, onStatusUpdate) {
58
73
  const serverBundleVersion = checkResult.bundleVersion;
59
74
  const serverVersion = checkResult.version;
60
75
  const serverRuntimeVersion = checkResult.runtimeVersion;
61
- const bundleZipUrl = checkResult.downloadUrl || null;
76
+ const fullBundleZipUrl = checkResult.mode === 'patch'
77
+ ? checkResult.fallback?.downloadUrl || null
78
+ : checkResult.downloadUrl || null;
62
79
  try {
63
- if (!bundleZipUrl) {
80
+ if (!serverHash) {
81
+ throw new errors_1.BundleDropError({
82
+ message: 'Missing bundleHash from ota resolve response',
83
+ code: 'HASH_MISSING',
84
+ step: 'resolve',
85
+ context: { channelName, platform, projectSlug: project.slug },
86
+ });
87
+ }
88
+ if (!fullBundleZipUrl) {
64
89
  throw new errors_1.BundleDropError({
65
90
  message: 'Missing downloadUrl from ota resolve response',
66
91
  code: 'DOWNLOAD_URL_MISSING',
@@ -82,15 +107,29 @@ async function downloadAndStageUpdate(options, onStatusUpdate) {
82
107
  skippedHash: hash,
83
108
  };
84
109
  }
85
- statusCb?.('⬇️ Downloading full bundle ZIP!...');
86
- let installResult;
87
- try {
88
- installResult = await (0, installFromZip_1.installFromZip)({
89
- downloadUrl: bundleZipUrl,
110
+ let installResult = await (0, patchTransport_1.tryInstallPatchTransport)({
111
+ target: {
112
+ mode: checkResult.mode,
90
113
  hash,
91
- platform,
92
- statusCb,
93
- });
114
+ manifestUrl: checkResult.manifestUrl,
115
+ baseHash: checkResult.baseHash,
116
+ patchSet: checkResult.patchSet,
117
+ },
118
+ projectSlug: project.slug,
119
+ platform,
120
+ runtimeVersionValue: serverRuntimeVersion,
121
+ statusCb,
122
+ });
123
+ try {
124
+ if (!installResult) {
125
+ statusCb?.('⬇️ Downloading full bundle ZIP!...');
126
+ installResult = await (0, installFromZip_1.installFromZip)({
127
+ downloadUrl: fullBundleZipUrl,
128
+ hash,
129
+ platform,
130
+ statusCb,
131
+ });
132
+ }
94
133
  }
95
134
  catch (e) {
96
135
  const phaseErr = (0, errors_1.isInstallPhaseError)(e);
@@ -104,19 +143,14 @@ async function downloadAndStageUpdate(options, onStatusUpdate) {
104
143
  });
105
144
  }
106
145
  const { bundlePath, metadataFromZip } = installResult;
107
- // Try to read metadata from the bundle itself as a fallback when server check is unavailable.
108
- const installedHash = hash ?? metadataFromZip.hash;
109
- if (!installedHash) {
110
- throw new errors_1.BundleDropError({
111
- message: 'Missing bundle hash after install',
112
- code: 'HASH_MISSING',
113
- step: 'install',
114
- context: { channelName, platform },
115
- });
116
- }
146
+ const installedHash = hash;
117
147
  statusCb?.('✅ Update downloaded. Will apply on next launch or when you call applyUpdate().');
118
148
  // Persist installed metadata for future skip logic.
119
- const previousInfo = await (0, bundleInfo_1.readBundleInfo)();
149
+ const [previousInfo, previousCurrentPointer, previousRollbackPointer] = await Promise.all([
150
+ (0, bundleInfo_1.readBundleInfo)(),
151
+ (0, bundlePointer_1.readCurrentBundlePointer)(),
152
+ (0, bundlePointer_1.readPreviousBundlePointer)(),
153
+ ]);
120
154
  const installedInfo = {
121
155
  bundleVersion: serverBundleVersion ?? metadataFromZip.bundleVersion,
122
156
  version: serverVersion ?? metadataFromZip.version,
@@ -125,11 +159,37 @@ async function downloadAndStageUpdate(options, onStatusUpdate) {
125
159
  platform,
126
160
  installedAt: new Date().toISOString(),
127
161
  pendingApply: true,
128
- runtimeVersion: metadataFromZip.runtimeVersion ?? serverRuntimeVersion ?? context_1.runtimeVersion ?? undefined,
162
+ runtimeVersion: serverRuntimeVersion ?? metadataFromZip.runtimeVersion,
129
163
  lastInstalledReportedHash: previousInfo?.lastInstalledReportedHash,
164
+ installedReportedHashes: previousInfo?.installedReportedHashes,
130
165
  };
131
- await (0, bundleInfo_1.writeBundleInfo)(installedInfo);
132
166
  await (0, bundlePointer_1.setCurrentBundlePointer)(bundlePath, installedHash);
167
+ try {
168
+ const resolvedBundlePath = await (0, bundleDropNative_1.getDownloadedBundlePathNative)();
169
+ if (resolvedBundlePath !== bundlePath) {
170
+ throw new errors_1.BundleDropError({
171
+ message: 'Installed bundle was not accepted by the native resolver',
172
+ code: 'INSTALL_FAILED',
173
+ step: 'install',
174
+ context: { channelName, platform, hash, expectedBundlePath: bundlePath, resolvedBundlePath },
175
+ });
176
+ }
177
+ }
178
+ catch (nativeError) {
179
+ await restoreCurrentPointer(previousCurrentPointer);
180
+ await (0, bundlePointer_1.restorePreviousBundlePointer)(previousRollbackPointer);
181
+ if (nativeError instanceof errors_1.BundleDropError) {
182
+ throw nativeError;
183
+ }
184
+ throw new errors_1.BundleDropError({
185
+ message: 'Installed bundle was not accepted by the native resolver',
186
+ code: 'INSTALL_FAILED',
187
+ step: 'install',
188
+ context: { channelName, platform, hash },
189
+ cause: nativeError,
190
+ });
191
+ }
192
+ await (0, bundleInfo_1.writeBundleInfo)(installedInfo);
133
193
  await (0, rollbackState_1.markCandidateActivated)(installedHash);
134
194
  return { status: 'staged', bundlePath, hash: installedHash };
135
195
  }
@@ -9,6 +9,12 @@ const bundleDropNative_1 = require("../native/bundleDropNative");
9
9
  const installId_1 = require("../fs/installId");
10
10
  const userProperties_1 = require("../fs/userProperties");
11
11
  const initState_1 = require("../runtime/initState");
12
+ const MAX_REPORTED_INSTALL_HASHES = 50;
13
+ const installedReportInFlightHashes = new Set();
14
+ function appendReportedHash(existing, hash) {
15
+ const next = [...(existing || []).filter(value => value !== hash), hash];
16
+ return next.slice(-MAX_REPORTED_INSTALL_HASHES);
17
+ }
12
18
  async function getReportingState() {
13
19
  const info = await (0, bundleInfo_1.readBundleInfo)();
14
20
  const path = await (0, bundleDropNative_1.getDownloadedBundlePathNative)();
@@ -29,13 +35,19 @@ async function reportInstalledIfReady(state) {
29
35
  return;
30
36
  if (info.lastInstalledReportedHash === info.hash)
31
37
  return;
38
+ if (info.installedReportedHashes?.includes(info.hash))
39
+ return;
40
+ if (installedReportInFlightHashes.has(info.hash))
41
+ return;
42
+ const reportedHash = info.hash;
43
+ installedReportInFlightHashes.add(reportedHash);
32
44
  try {
33
45
  const [installId, userProperties] = await Promise.all([
34
46
  (0, installId_1.getOrCreateInstallId)(),
35
47
  (0, userProperties_1.getCurrentUserProperties)(),
36
48
  ]);
37
49
  const appEnvironment = (0, initState_1.getBundleDropRuntimeConfig)()?.environment ?? null;
38
- await (0, clientApi_1.reportInstalled)(context_1.config.project.slug, info.hash, {
50
+ await (0, clientApi_1.reportInstalled)(context_1.config.project.slug, reportedHash, {
39
51
  channelName: info.channelName,
40
52
  platform: info.platform,
41
53
  installId,
@@ -43,11 +55,23 @@ async function reportInstalledIfReady(state) {
43
55
  environment: appEnvironment,
44
56
  userProperties: Object.keys(userProperties).length > 0 ? userProperties : undefined,
45
57
  });
46
- await (0, bundleInfo_1.updateBundleInfo)({ lastInstalledReportedHash: info.hash });
58
+ const latestInfo = await (0, bundleInfo_1.readBundleInfo)();
59
+ if (latestInfo) {
60
+ const nextInfo = {
61
+ installedReportedHashes: appendReportedHash(latestInfo.installedReportedHashes, reportedHash),
62
+ };
63
+ if (latestInfo.hash === reportedHash) {
64
+ nextInfo.lastInstalledReportedHash = reportedHash;
65
+ }
66
+ await (0, bundleInfo_1.updateBundleInfo)(nextInfo);
67
+ }
47
68
  }
48
69
  catch (e) {
49
70
  console.warn('⚠️ Failed to report bundle install:', e?.toString?.() || e);
50
71
  }
72
+ finally {
73
+ installedReportInFlightHashes.delete(reportedHash);
74
+ }
51
75
  }
52
76
  async function reportLocalRollback(hash, record) {
53
77
  try {
@@ -19,6 +19,7 @@ const fsUtils_1 = require("../fs/fsUtils");
19
19
  const bundlePointer_1 = require("../fs/bundlePointer");
20
20
  const bundleInfo_1 = require("../bundleInfo");
21
21
  const reporting_1 = require("./reporting");
22
+ const bundleManifest_1 = require("../manifest/bundleManifest");
22
23
  const STATE_PATH = `${context_1.BUNDLE_DROP_ROOT}/state.json`;
23
24
  const MAX_FAILED_BUNDLES = 20;
24
25
  function nowSec() {
@@ -190,12 +191,14 @@ async function rollbackToPreviousOrNative() {
190
191
  runtimeVersion: metadata?.runtimeVersion,
191
192
  pendingApply: false,
192
193
  installedAt: new Date().toISOString(),
194
+ lastInstalledReportedHash: previous.hash,
193
195
  });
194
196
  await updateState({
195
197
  activeHash: previous.hash,
196
198
  candidateHash: previous.hash,
197
199
  candidateCommitted: true,
198
200
  crashCount: 0,
201
+ lastGoodHash: previous.hash,
199
202
  });
200
203
  return { rolledBack: true };
201
204
  }
@@ -218,22 +221,28 @@ async function rollbackToPreviousOrNative() {
218
221
  });
219
222
  return { rolledBack: true, toNative: true };
220
223
  }
221
- async function readBundleMetadata(bundlePath) {
224
+ async function readJsonIfExists(path) {
222
225
  try {
223
- const dir = bundlePath.substring(0, bundlePath.lastIndexOf('/'));
224
- const metadataFile = context_1.platform === 'android' ? 'metadata-android.json' : 'metadata-ios.json';
225
- const filePath = `${dir}/${metadataFile}`;
226
- if (!(await fs_1.default.exists(filePath)))
226
+ if (!(await fs_1.default.exists(path)))
227
227
  return null;
228
- const raw = await fs_1.default.readFile(filePath, 'utf8');
229
- const parsed = JSON.parse(raw);
230
- return {
231
- bundleVersion: parsed?.bundleVersion,
232
- version: parsed?.version,
233
- runtimeVersion: parsed?.runtimeVersion,
234
- };
228
+ const raw = await fs_1.default.readFile(path, 'utf8');
229
+ return JSON.parse(raw);
235
230
  }
236
231
  catch {
237
232
  return null;
238
233
  }
239
234
  }
235
+ async function readBundleMetadata(bundlePath) {
236
+ const dir = bundlePath.substring(0, bundlePath.lastIndexOf('/'));
237
+ const manifest = await readJsonIfExists(`${dir}/${bundleManifest_1.BUNDLE_MANIFEST}`);
238
+ const metadataFile = context_1.platform === 'android' ? 'metadata-android.json' : 'metadata-ios.json';
239
+ const parsed = await readJsonIfExists(`${dir}/${metadataFile}`);
240
+ if (!manifest && !parsed) {
241
+ return null;
242
+ }
243
+ return {
244
+ bundleVersion: parsed?.bundleVersion,
245
+ version: manifest?.version ?? parsed?.version,
246
+ runtimeVersion: manifest?.runtimeVersion ?? parsed?.runtimeVersion,
247
+ };
248
+ }
@@ -1,4 +1,37 @@
1
1
  "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
15
+ }) : function(o, v) {
16
+ o["default"] = v;
17
+ });
18
+ var __importStar = (this && this.__importStar) || (function () {
19
+ var ownKeys = function(o) {
20
+ ownKeys = Object.getOwnPropertyNames || function (o) {
21
+ var ar = [];
22
+ for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
23
+ return ar;
24
+ };
25
+ return ownKeys(o);
26
+ };
27
+ return function (mod) {
28
+ if (mod && mod.__esModule) return mod;
29
+ var result = {};
30
+ if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
31
+ __setModuleDefault(result, mod);
32
+ return result;
33
+ };
34
+ })();
2
35
  Object.defineProperty(exports, "__esModule", { value: true });
3
36
  exports.getAvailableChannels = getAvailableChannels;
4
37
  exports.checkForUpdate = checkForUpdate;
@@ -13,6 +46,40 @@ const installId_1 = require("../fs/installId");
13
46
  const userProperties_1 = require("../fs/userProperties");
14
47
  const initState_1 = require("../runtime/initState");
15
48
  const rollbackState_1 = require("./rollbackState");
49
+ const bundleDropNative_1 = require("../native/bundleDropNative");
50
+ const patchOperations_1 = require("../patch-engine/patchOperations");
51
+ function assertInstallDecisionShape(decision) {
52
+ const { target } = decision;
53
+ if (!target?.bundleHash) {
54
+ throw new Error('Invalid INSTALL resolve response: target.bundleHash is required');
55
+ }
56
+ if (!target.manifestUrl) {
57
+ throw new Error('Invalid INSTALL resolve response: target.manifestUrl is required');
58
+ }
59
+ if (!target.runtimeVersion) {
60
+ throw new Error('Invalid INSTALL resolve response: target.runtimeVersion is required');
61
+ }
62
+ if (decision.mode === 'full') {
63
+ if (!target.downloadUrl) {
64
+ throw new Error('Invalid INSTALL resolve response: target.downloadUrl is required');
65
+ }
66
+ return;
67
+ }
68
+ if (decision.mode !== 'patch') {
69
+ throw new Error('Invalid INSTALL resolve response: mode must be full or patch');
70
+ }
71
+ if (!decision.baseHash) {
72
+ throw new Error('Invalid INSTALL resolve response: baseHash is required for patch mode');
73
+ }
74
+ if (!decision.patchSet?.patchSetHash ||
75
+ !decision.patchSet?.patchesUrl ||
76
+ !decision.patchSet?.algorithm) {
77
+ throw new Error('Invalid INSTALL resolve response: patchSet is incomplete');
78
+ }
79
+ if (decision.fallback?.mode !== 'full' || !decision.fallback.downloadUrl) {
80
+ throw new Error('Invalid INSTALL resolve response: patch mode requires full fallback');
81
+ }
82
+ }
16
83
  async function getAvailableChannels() {
17
84
  const { project } = context_1.config;
18
85
  if (!project?.slug) {
@@ -39,17 +106,17 @@ async function checkForUpdate(channelName = context_2.defaultChannel, onStatusUp
39
106
  throw new Error('Missing project slug in bundle.drop.config.js');
40
107
  }
41
108
  onStatusUpdate?.('🔍 Checking for updates...');
42
- const [local, currentPtr, previousPtr, currentUserProperties, installId, rejectedHashes] = await Promise.all([
43
- (0, bundleInfo_1.readBundleInfo)(),
109
+ const [currentPtr, nativeBundlePath, currentUserProperties, installId, rejectedHashes] = await Promise.all([
44
110
  (0, bundlePointer_1.readCurrentBundlePointer)(),
45
- (0, bundlePointer_1.readPreviousBundlePointer)(),
111
+ (0, bundleDropNative_1.getDownloadedBundlePathNative)(),
46
112
  (0, userProperties_1.getCurrentUserProperties)(),
47
113
  (0, installId_1.getOrCreateInstallId)(),
48
114
  (0, rollbackState_1.getFailedBundleHashes)(),
49
115
  ]);
50
- const currentHash = currentPtr?.hash ?? local?.hash ?? null;
51
- const previousHash = previousPtr?.hash ?? null;
116
+ const currentHash = nativeBundlePath && currentPtr?.hash ? currentPtr.hash : null;
52
117
  const appEnvironment = (0, initState_1.getBundleDropRuntimeConfig)()?.environment ?? null;
118
+ const supportsXdelta = await Promise.resolve().then(() => __importStar(require('../native/fs'))).then(module => module.default.supportsXdelta())
119
+ .catch(() => false);
53
120
  const res = await (0, clientApi_1.postOtaResolve)(project.slug, {
54
121
  channelName,
55
122
  platform: context_1.platform,
@@ -57,10 +124,13 @@ async function checkForUpdate(channelName = context_2.defaultChannel, onStatusUp
57
124
  environment: appEnvironment,
58
125
  currentHash,
59
126
  currentUserProperties,
60
- previousHash,
61
127
  rejectedHashes,
62
- currentBundleVersion: local?.bundleVersion ?? null,
63
128
  installId,
129
+ transport: {
130
+ manifestVersion: 1,
131
+ patchAlgorithms: (0, patchOperations_1.advertisedPatchAlgorithms)(supportsXdelta),
132
+ supportsContentAddressedAssets: true,
133
+ },
64
134
  });
65
135
  const decision = res.data;
66
136
  if (decision.action === 'NOOP') {
@@ -85,8 +155,10 @@ async function checkForUpdate(channelName = context_2.defaultChannel, onStatusUp
85
155
  onStatusUpdate?.('↩️ Rollback requested');
86
156
  return { action: 'ROLLBACK', channelName, reason: decision.reason };
87
157
  }
158
+ assertInstallDecisionShape(decision);
88
159
  // INSTALL
89
- if (await (0, rollbackState_1.isBundleHashFailed)(decision.target.hash)) {
160
+ const targetHash = decision.target.bundleHash;
161
+ if (await (0, rollbackState_1.isBundleHashFailed)(targetHash)) {
90
162
  onStatusUpdate?.('✅ Current bundle retained; latest update previously failed on this device');
91
163
  return {
92
164
  action: 'NOOP',
@@ -94,7 +166,7 @@ async function checkForUpdate(channelName = context_2.defaultChannel, onStatusUp
94
166
  channelName,
95
167
  reason: 'BUNDLE_PREVIOUSLY_FAILED',
96
168
  skippedFailedBundle: true,
97
- skippedHash: decision.target.hash,
169
+ skippedHash: targetHash,
98
170
  };
99
171
  }
100
172
  onStatusUpdate?.('⬇️ Update available');
@@ -102,11 +174,17 @@ async function checkForUpdate(channelName = context_2.defaultChannel, onStatusUp
102
174
  action: 'INSTALL',
103
175
  upToDate: false,
104
176
  channelName,
105
- hash: decision.target.hash,
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,
106
183
  downloadUrl: decision.target.downloadUrl,
184
+ manifestUrl: decision.target.manifestUrl,
107
185
  bundleVersion: decision.target.bundleVersion,
108
186
  version: decision.target.version,
109
- runtimeVersion: decision.target.runtimeVersion ?? context_1.runtimeVersion ?? undefined,
187
+ runtimeVersion: decision.target.runtimeVersion,
110
188
  };
111
189
  }
112
190
  catch (e) {
@@ -9,10 +9,11 @@ const rollbackState_1 = require("./rollbackState");
9
9
  const getUpdateState = async (cached) => {
10
10
  const info = cached?.bundleInfo !== undefined ? cached.bundleInfo : await (0, bundleInfo_1.readBundleInfo)();
11
11
  const path = cached?.bundlePath !== undefined ? cached.bundlePath : await (0, bundleDropNative_1.getDownloadedBundlePathNative)();
12
+ const pendingApply = !!path && (info?.pendingApply ?? false);
12
13
  return {
13
14
  hasBundle: !!path,
14
15
  info,
15
- pendingApply: info?.pendingApply ?? false,
16
+ pendingApply,
16
17
  };
17
18
  };
18
19
  exports.getUpdateState = getUpdateState;
@@ -34,8 +35,8 @@ const reconcileAppliedBundleOnLaunch = async (cached) => {
34
35
  exports.reconcileAppliedBundleOnLaunch = reconcileAppliedBundleOnLaunch;
35
36
  const applyUpdate = async (onStatusUpdate, onBeforeRestart) => {
36
37
  try {
37
- const path = await (0, bundleDropNative_1.getDownloadedBundlePathNative)();
38
38
  const info = await (0, bundleInfo_1.readBundleInfo)();
39
+ const path = await (0, bundleDropNative_1.getDownloadedBundlePathNative)();
39
40
  if (!path) {
40
41
  onStatusUpdate?.('⚠️ No downloaded bundle to apply');
41
42
  return { status: 'noBundle' };
@@ -54,13 +55,6 @@ const applyUpdate = async (onStatusUpdate, onBeforeRestart) => {
54
55
  }
55
56
  onStatusUpdate?.('♻️ Applying downloaded bundle...');
56
57
  await (0, bundleInfo_1.updateBundleInfo)({ pendingApply: false, installedAt: new Date().toISOString() });
57
- (0, reporting_1.reportInstalledIfReady)({
58
- hasBundle: true,
59
- info: info ? { ...info, pendingApply: false } : info,
60
- }).catch(reportError => {
61
- // Telemetry should not block applying the already-downloaded bundle.
62
- console.warn('⚠️ Failed to report bundle install during apply:', reportError);
63
- });
64
58
  onBeforeRestart?.();
65
59
  (0, bundleDropNative_1.restartReactNativeNative)();
66
60
  return { status: 'applied' };
@@ -0,0 +1,33 @@
1
+ export declare const BUNDLE_MANIFEST = "bundle-manifest.json";
2
+ export type BundleManifestFileRole = 'jsbundle' | 'metadata' | 'asset' | 'androidImageManifest';
3
+ export type BundleManifestFile = {
4
+ path: string;
5
+ size: number;
6
+ sha256: string;
7
+ role: BundleManifestFileRole;
8
+ executable?: boolean;
9
+ };
10
+ export type BundleManifest = {
11
+ manifestVersion: 1;
12
+ bundleHash: string;
13
+ jsBundleHash: string;
14
+ platform: 'ios' | 'android' | string;
15
+ runtimeVersion: string;
16
+ version: string;
17
+ manifestHash: string;
18
+ files: BundleManifestFile[];
19
+ };
20
+ export declare const byteLengthFromBase64: (value: string) => number;
21
+ export declare const base64ToBytes: (value: string) => number[];
22
+ export declare const sha256Bytes: (input: number[] | Uint8Array) => string;
23
+ export declare const sha256String: (value: string) => string;
24
+ export declare const sha256Base64: (value: string) => string;
25
+ export declare const normalizeManifestPath: (value: string) => string;
26
+ export declare const sortManifestFiles: (files: BundleManifestFile[]) => BundleManifestFile[];
27
+ export declare const canonicalManifestFileEntries: (files: BundleManifestFile[]) => Record<string, unknown>[];
28
+ export declare const calculateBundleHash: (files: BundleManifestFile[]) => string;
29
+ export declare const calculateManifestHash: (manifest: Omit<BundleManifest, "manifestHash">) => string;
30
+ export declare const createBundleManifest: (input: Omit<BundleManifest, "manifestVersion" | "manifestHash" | "files"> & {
31
+ files: BundleManifestFile[];
32
+ }) => BundleManifest;
33
+ export declare const assertValidBundleManifest: (manifest: BundleManifest, expectedBundleHash?: string, expectedPlatform?: "ios" | "android") => void;