@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.
Files changed (127) hide show
  1. package/BundleDrop.podspec +96 -0
  2. package/README.md +194 -5
  3. package/android/build.gradle +66 -0
  4. package/android/src/main/java/com/bundledrop/BundleDropBoundedDownloader.kt +86 -0
  5. package/android/src/main/java/com/bundledrop/BundleDropModule.kt +206 -13
  6. package/android/src/main/java/com/bundledrop/BundleDropNativePaths.kt +43 -13
  7. package/android/src/main/java/com/bundledrop/BundleDropOtaResolver.kt +35 -0
  8. package/android/src/main/java/com/bundledrop/BundleDropRuntimeCrypto.kt +81 -0
  9. package/android/src/main/java/com/bundledrop/BundleDropStartupRecovery.kt +1117 -0
  10. package/ios/BundleDropBridge.m +45 -0
  11. package/ios/BundleDropLocator.swift +66 -4
  12. package/ios/BundleDropModule.swift +181 -3
  13. package/ios/BundleDropOtaResolver.swift +137 -29
  14. package/ios/BundleDropRuntimeCrypto.swift +45 -0
  15. package/ios/BundleDropStartupRecovery.swift +1108 -0
  16. package/ios/BundleDropStartupRecoveryAdapter.swift +301 -0
  17. package/lib/CLI/cli.d.ts +1 -0
  18. package/lib/CLI/cli.js +57 -6
  19. package/lib/CLI/scripts/aipowered/apply-setup-plan.js +7 -17
  20. package/lib/CLI/scripts/aipowered/backend-client.js +29 -4
  21. package/lib/CLI/scripts/aipowered/code-push-residue.d.ts +5 -0
  22. package/lib/CLI/scripts/aipowered/code-push-residue.js +126 -0
  23. package/lib/CLI/scripts/aipowered/credential-safety.d.ts +1 -0
  24. package/lib/CLI/scripts/aipowered/credential-safety.js +14 -0
  25. package/lib/CLI/scripts/aipowered/diff-preview.js +12 -4
  26. package/lib/CLI/scripts/aipowered/init-project-config.d.ts +4 -0
  27. package/lib/CLI/scripts/aipowered/init-project-config.js +221 -45
  28. package/lib/CLI/scripts/aipowered/scanner.d.ts +1 -0
  29. package/lib/CLI/scripts/aipowered/scanner.js +164 -32
  30. package/lib/CLI/scripts/aipowered/terminal-safety.d.ts +4 -0
  31. package/lib/CLI/scripts/aipowered/terminal-safety.js +124 -0
  32. package/lib/CLI/scripts/aipowered/validate-plan.d.ts +3 -0
  33. package/lib/CLI/scripts/aipowered/validate-plan.js +1080 -19
  34. package/lib/CLI/scripts/bare-metro-config.d.ts +1 -1
  35. package/lib/CLI/scripts/bare-metro-config.js +24 -32
  36. package/lib/CLI/scripts/doctor.js +162 -22
  37. package/lib/CLI/scripts/expo/configure-expo.js +52 -60
  38. package/lib/CLI/scripts/expo/package-manager.d.ts +2 -0
  39. package/lib/CLI/scripts/expo/package-manager.js +63 -25
  40. package/lib/CLI/scripts/init-config.d.ts +7 -7
  41. package/lib/CLI/scripts/init-config.js +198 -14
  42. package/lib/CLI/scripts/login-cli.js +31 -7
  43. package/lib/CLI/scripts/metro-config-authority.d.ts +8 -0
  44. package/lib/CLI/scripts/metro-config-authority.js +303 -0
  45. package/lib/CLI/scripts/native/write-runtime-identity.d.ts +19 -0
  46. package/lib/CLI/scripts/native/write-runtime-identity.js +92 -0
  47. package/lib/CLI/scripts/native-entrypoint-authority.d.ts +2 -0
  48. package/lib/CLI/scripts/native-entrypoint-authority.js +378 -0
  49. package/lib/CLI/scripts/native-setup-contract.d.ts +2 -2
  50. package/lib/CLI/scripts/native-setup-contract.js +63 -33
  51. package/lib/CLI/scripts/native-startup-validator.d.ts +3 -0
  52. package/lib/CLI/scripts/native-startup-validator.js +964 -0
  53. package/lib/CLI/scripts/safe-file-transaction.d.ts +12 -0
  54. package/lib/CLI/scripts/safe-file-transaction.js +159 -0
  55. package/lib/CLI/scripts/upload-cli.d.ts +12 -2
  56. package/lib/CLI/scripts/upload-cli.js +74 -11
  57. package/lib/CLI/serverUrl.d.ts +3 -0
  58. package/lib/CLI/serverUrl.js +31 -0
  59. package/lib/api/clientApi.d.ts +3 -1
  60. package/lib/api/clientApi.js +14 -0
  61. package/lib/api/types.d.ts +39 -0
  62. package/lib/bundleInfo.d.ts +2 -0
  63. package/lib/bundleInfo.js +16 -1
  64. package/lib/context.d.ts +1 -1
  65. package/lib/context.js +12 -2
  66. package/lib/fs/bundlePointer.d.ts +1 -17
  67. package/lib/fs/bundlePointer.js +5 -93
  68. package/lib/index.d.ts +2 -0
  69. package/lib/index.js +3 -1
  70. package/lib/install/bundleInstallShared.js +4 -4
  71. package/lib/install/installFromZip.d.ts +3 -0
  72. package/lib/install/installFromZip.js +10 -1
  73. package/lib/loadConfig.d.ts +17 -1
  74. package/lib/loadConfig.js +16 -0
  75. package/lib/manager/downloadAndInstall.d.ts +3 -2
  76. package/lib/manager/downloadAndInstall.js +134 -66
  77. package/lib/manager/reporting.d.ts +8 -1
  78. package/lib/manager/reporting.js +17 -22
  79. package/lib/manager/rollbackState.d.ts +18 -52
  80. package/lib/manager/rollbackState.js +115 -216
  81. package/lib/manager/updateCheck.d.ts +1 -0
  82. package/lib/manager/updateCheck.js +224 -78
  83. package/lib/manager/updateState.d.ts +2 -1
  84. package/lib/manager/updateState.js +59 -6
  85. package/lib/metro.d.ts +8 -1
  86. package/lib/metro.js +69 -19
  87. package/lib/native/bundleDropNative.d.ts +62 -0
  88. package/lib/native/bundleDropNative.js +268 -2
  89. package/lib/native/fs.d.ts +6 -0
  90. package/lib/native/fs.js +24 -0
  91. package/lib/patch-engine/installFromPatchSet.d.ts +2 -0
  92. package/lib/patch-engine/installFromPatchSet.js +16 -5
  93. package/lib/patch-engine/patchTransport.d.ts +2 -0
  94. package/lib/patch-engine/patchTransport.js +9 -0
  95. package/lib/runtime/initState.d.ts +5 -0
  96. package/lib/runtime/initState.js +4 -0
  97. package/lib/runtime/service.js +82 -67
  98. package/lib/runtime-delivery/artifactCapability.d.ts +1 -0
  99. package/lib/runtime-delivery/artifactCapability.js +32 -0
  100. package/lib/runtime-delivery/authorityLeaseVerifier.d.ts +3 -0
  101. package/lib/runtime-delivery/authorityLeaseVerifier.js +106 -0
  102. package/lib/runtime-delivery/bootstrapConfig.d.ts +68 -0
  103. package/lib/runtime-delivery/bootstrapConfig.js +278 -0
  104. package/lib/runtime-delivery/diagnostics.d.ts +17 -0
  105. package/lib/runtime-delivery/diagnostics.js +58 -0
  106. package/lib/runtime-delivery/encoding.d.ts +5 -0
  107. package/lib/runtime-delivery/encoding.js +132 -0
  108. package/lib/runtime-delivery/heartbeat.d.ts +3 -0
  109. package/lib/runtime-delivery/heartbeat.js +88 -0
  110. package/lib/runtime-delivery/localResolver.d.ts +23 -0
  111. package/lib/runtime-delivery/localResolver.js +81 -0
  112. package/lib/runtime-delivery/manifestState.d.ts +11 -0
  113. package/lib/runtime-delivery/manifestState.js +123 -0
  114. package/lib/runtime-delivery/manifestVerifier.d.ts +13 -0
  115. package/lib/runtime-delivery/manifestVerifier.js +335 -0
  116. package/lib/runtime-delivery/runtimeDelivery.d.ts +19 -0
  117. package/lib/runtime-delivery/runtimeDelivery.js +375 -0
  118. package/lib/runtime-delivery/types.d.ts +87 -0
  119. package/lib/runtime-delivery/types.js +6 -0
  120. package/lib/scripts/bundle.d.ts +9 -2
  121. package/lib/scripts/bundle.js +68 -18
  122. package/lib/scripts/download-bundle.d.ts +1 -0
  123. package/lib/scripts/download-bundle.js +2 -2
  124. package/lib/scripts/resolveModule.d.ts +2 -0
  125. package/lib/scripts/resolveModule.js +5 -0
  126. package/package.json +5 -2
  127. package/plugin/xcodeBuildPhase.js +2 -1
@@ -2,16 +2,282 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.isBundleDropNativeAvailable = isBundleDropNativeAvailable;
4
4
  exports.isExpoOtaStartupEnabledNative = isExpoOtaStartupEnabledNative;
5
+ exports.isStartupRecoveryAvailableNative = isStartupRecoveryAvailableNative;
6
+ exports.warnIfStartupRecoveryUnavailableNative = warnIfStartupRecoveryUnavailableNative;
7
+ exports.getStartupRecoveryAttemptNative = getStartupRecoveryAttemptNative;
8
+ exports.getStartupRecoverySelectedHashNative = getStartupRecoverySelectedHashNative;
9
+ exports.activateStartupCandidateNative = activateStartupCandidateNative;
10
+ exports.markStartupHealthyNative = markStartupHealthyNative;
11
+ exports.getStartupRecoveryStateNative = getStartupRecoveryStateNative;
12
+ exports.setStartupRecoveryRevokedHashesNative = setStartupRecoveryRevokedHashesNative;
13
+ exports.acknowledgeStartupRecoveryNative = acknowledgeStartupRecoveryNative;
14
+ exports.rollbackStartupBundleNative = rollbackStartupBundleNative;
5
15
  exports.getDownloadedBundlePathNative = getDownloadedBundlePathNative;
6
16
  exports.restartReactNativeNative = restartReactNativeNative;
7
17
  exports.setOtaEnabledNative = setOtaEnabledNative;
8
18
  const react_native_1 = require("react-native");
9
- const { BundleDrop, BundleDropExpoIdentity } = react_native_1.NativeModules;
19
+ const STARTUP_RECOVERY_PROTOCOL_VERSION = 1;
20
+ const SHA256_HASH_PATTERN = /^[a-f0-9]{64}$/;
21
+ const STARTUP_RECOVERY_CAPABILITY_WARNING = '[BundleDrop] Automatic startup recovery requires a newer BundleDrop native build. ' +
22
+ 'Recovery is disabled for this binary; rebuild the app before shipping another OTA update.';
23
+ const BundleDrop = react_native_1.NativeModules.BundleDrop;
24
+ const BundleDropExpoIdentity = react_native_1.NativeModules.BundleDropExpoIdentity;
25
+ // These constants describe the bundle selected by native code for this specific
26
+ // React runtime. Capture them once so later native state changes cannot rewrite
27
+ // the running identity or the attempt acknowledged by reportHealthy().
28
+ const startupRecoverySelectedHash = readStartupRecoverySelectedHash(BundleDrop);
29
+ const startupRecoveryAttempt = readStartupRecoveryAttempt(BundleDrop);
30
+ let hasWarnedAboutStartupRecoveryCapability = false;
31
+ function isRecord(value) {
32
+ return !!value && typeof value === 'object' && !Array.isArray(value);
33
+ }
34
+ function nonEmptyString(value) {
35
+ return typeof value === 'string' && value.trim() ? value : null;
36
+ }
37
+ function canonicalHash(value) {
38
+ return typeof value === 'string' && SHA256_HASH_PATTERN.test(value) ? value : null;
39
+ }
40
+ function readStartupRecoverySelectedHash(nativeModule) {
41
+ if (!nativeModule || !Object.prototype.hasOwnProperty.call(nativeModule, 'startupRecoverySelectedHash')) {
42
+ return undefined;
43
+ }
44
+ if (nativeModule.startupRecoverySelectedHash == null)
45
+ return null;
46
+ return canonicalHash(nativeModule.startupRecoverySelectedHash);
47
+ }
48
+ function nonNegativeInteger(value) {
49
+ return Number.isSafeInteger(value) && value >= 0 ? value : null;
50
+ }
51
+ function readStartupRecoveryAttempt(nativeModule) {
52
+ const hash = canonicalHash(nativeModule?.startupRecoveryAttemptHash);
53
+ const attemptId = nonEmptyString(nativeModule?.startupRecoveryAttemptId);
54
+ return hash && attemptId ? { hash, attemptId } : null;
55
+ }
56
+ function hasStartupRecoveryMethods(nativeModule) {
57
+ return nativeModule?.startupRecoveryProtocolVersion === STARTUP_RECOVERY_PROTOCOL_VERSION &&
58
+ typeof nativeModule.activateStartupCandidate === 'function' &&
59
+ typeof nativeModule.markStartupHealthy === 'function' &&
60
+ typeof nativeModule.getStartupRecoveryState === 'function' &&
61
+ typeof nativeModule.setStartupRecoveryRevokedHashes === 'function' &&
62
+ typeof nativeModule.acknowledgeStartupRecovery === 'function' &&
63
+ typeof nativeModule.rollbackStartupBundle === 'function';
64
+ }
65
+ function warnAboutMissingStartupRecovery() {
66
+ if (hasWarnedAboutStartupRecoveryCapability)
67
+ return;
68
+ hasWarnedAboutStartupRecoveryCapability = true;
69
+ console.warn(STARTUP_RECOVERY_CAPABILITY_WARNING);
70
+ }
71
+ function requireStartupRecoveryCapability() {
72
+ if (!hasStartupRecoveryMethods(BundleDrop)) {
73
+ warnAboutMissingStartupRecovery();
74
+ return null;
75
+ }
76
+ return BundleDrop;
77
+ }
78
+ function normalizeRecoveryEvent(value) {
79
+ if (!isRecord(value))
80
+ return null;
81
+ const id = nonEmptyString(value.id);
82
+ const failedHash = canonicalHash(value.failedHash);
83
+ const hasRecoveredHash = value.recoveredHash != null;
84
+ const recoveredHash = hasRecoveredHash ? canonicalHash(value.recoveredHash) : undefined;
85
+ const crashCount = nonNegativeInteger(value.crashCount);
86
+ const failedAt = nonNegativeInteger(value.failedAt);
87
+ const recoveryTarget = value.recoveryTarget;
88
+ if (!id ||
89
+ !failedHash ||
90
+ (hasRecoveredHash && !recoveredHash) ||
91
+ crashCount === null ||
92
+ failedAt === null ||
93
+ value.reason !== 'crash_loop' ||
94
+ (recoveryTarget !== 'previous' && recoveryTarget !== 'embedded')) {
95
+ return null;
96
+ }
97
+ if (recoveryTarget === 'previous' && !recoveredHash)
98
+ return null;
99
+ return {
100
+ id,
101
+ failedHash,
102
+ recoveryTarget,
103
+ ...(recoveredHash ? { recoveredHash } : {}),
104
+ crashCount,
105
+ reason: 'crash_loop',
106
+ failedAt,
107
+ };
108
+ }
109
+ function normalizeStartupRecoveryState(value) {
110
+ if (!isRecord(value) || value.protocolVersion !== STARTUP_RECOVERY_PROTOCOL_VERSION) {
111
+ return null;
112
+ }
113
+ const revision = nonNegativeInteger(value.revision);
114
+ if (revision === null)
115
+ return null;
116
+ const phase = value.phase;
117
+ if (!['idle', 'armed', 'launching', 'stable', 'recovered'].includes(String(phase))) {
118
+ return null;
119
+ }
120
+ const hasCandidateHash = value.candidateHash != null;
121
+ const candidateHash = hasCandidateHash ? canonicalHash(value.candidateHash) : undefined;
122
+ const hasStableHash = value.stableHash != null;
123
+ const stableHash = hasStableHash ? canonicalHash(value.stableHash) : undefined;
124
+ if ((hasCandidateHash && !candidateHash) || (hasStableHash && !stableHash))
125
+ return null;
126
+ const baseAttempt = value.activeAttempt == null
127
+ ? null
128
+ : readStartupRecoveryAttempt({
129
+ startupRecoveryAttemptHash: isRecord(value.activeAttempt)
130
+ ? value.activeAttempt.hash
131
+ : undefined,
132
+ startupRecoveryAttemptId: isRecord(value.activeAttempt)
133
+ ? value.activeAttempt.attemptId
134
+ : undefined,
135
+ });
136
+ const activeAttemptCount = isRecord(value.activeAttempt)
137
+ ? nonNegativeInteger(value.activeAttempt.unacknowledgedLaunchCount)
138
+ : null;
139
+ const activeAttempt = baseAttempt && isRecord(value.activeAttempt) &&
140
+ value.activeAttempt.status === 'launching' && activeAttemptCount !== null
141
+ ? {
142
+ ...baseAttempt,
143
+ status: 'launching',
144
+ unacknowledgedLaunchCount: activeAttemptCount,
145
+ }
146
+ : undefined;
147
+ if (value.activeAttempt != null && !activeAttempt)
148
+ return null;
149
+ let policy;
150
+ if (value.policy != null) {
151
+ if (!isRecord(value.policy))
152
+ return null;
153
+ const maxCrashCount = nonNegativeInteger(value.policy.maxCrashCount);
154
+ const healthyAfterSec = typeof value.policy.healthyAfterSec === 'number' &&
155
+ Number.isFinite(value.policy.healthyAfterSec) && value.policy.healthyAfterSec >= 0
156
+ ? value.policy.healthyAfterSec
157
+ : null;
158
+ const healthCheckMode = value.policy.healthCheckMode;
159
+ if (maxCrashCount === null ||
160
+ healthyAfterSec === null ||
161
+ (healthCheckMode !== 'auto' && healthCheckMode !== 'manual')) {
162
+ return null;
163
+ }
164
+ policy = { maxCrashCount, healthCheckMode, healthyAfterSec };
165
+ }
166
+ const quarantinedHashes = Array.isArray(value.quarantinedHashes)
167
+ ? Array.from(new Set(value.quarantinedHashes.map(canonicalHash).filter(Boolean)))
168
+ : null;
169
+ const pendingRecoveryEvents = Array.isArray(value.pendingRecoveryEvents)
170
+ ? value.pendingRecoveryEvents.map(normalizeRecoveryEvent).filter(Boolean)
171
+ : null;
172
+ if (!quarantinedHashes || !pendingRecoveryEvents)
173
+ return null;
174
+ const uniqueEvents = Array.from(new Map(pendingRecoveryEvents.map(event => [event.id, event])).values());
175
+ return {
176
+ protocolVersion: STARTUP_RECOVERY_PROTOCOL_VERSION,
177
+ revision,
178
+ phase: phase,
179
+ ...(candidateHash ? { candidateHash } : {}),
180
+ ...(stableHash ? { stableHash } : {}),
181
+ ...(activeAttempt ? { activeAttempt } : {}),
182
+ ...(policy ? { policy } : {}),
183
+ quarantinedHashes,
184
+ pendingRecoveryEvents: uniqueEvents,
185
+ };
186
+ }
187
+ function normalizeCandidateActivation(value) {
188
+ if (!isRecord(value))
189
+ return null;
190
+ const hash = canonicalHash(value.hash);
191
+ const bundlePath = nonEmptyString(value.bundlePath);
192
+ return hash && bundlePath ? { hash, bundlePath } : null;
193
+ }
194
+ function normalizeRollbackResult(value) {
195
+ if (!isRecord(value) || typeof value.rolledBack !== 'boolean' || typeof value.toEmbedded !== 'boolean') {
196
+ return null;
197
+ }
198
+ const hasHash = value.hash != null;
199
+ const hash = hasHash ? canonicalHash(value.hash) : undefined;
200
+ if (hasHash && !hash)
201
+ return null;
202
+ return {
203
+ rolledBack: value.rolledBack,
204
+ toEmbedded: value.toEmbedded,
205
+ ...(hash ? { hash } : {}),
206
+ };
207
+ }
10
208
  function isBundleDropNativeAvailable() {
11
209
  return Boolean(BundleDrop);
12
210
  }
13
211
  function isExpoOtaStartupEnabledNative() {
14
- return BundleDropExpoIdentity?.otaStartupEnabled === true;
212
+ const nativeValue = BundleDropExpoIdentity?.otaStartupEnabled;
213
+ return nativeValue === true || nativeValue === 1;
214
+ }
215
+ function isStartupRecoveryAvailableNative() {
216
+ return hasStartupRecoveryMethods(BundleDrop);
217
+ }
218
+ function warnIfStartupRecoveryUnavailableNative() {
219
+ if (!isStartupRecoveryAvailableNative()) {
220
+ warnAboutMissingStartupRecovery();
221
+ }
222
+ }
223
+ function getStartupRecoveryAttemptNative() {
224
+ return startupRecoveryAttempt ? { ...startupRecoveryAttempt } : null;
225
+ }
226
+ /**
227
+ * Hash selected for this exact React runtime. `undefined` means the installed
228
+ * native adapter predates this constant; `null` means native selected embedded.
229
+ */
230
+ function getStartupRecoverySelectedHashNative() {
231
+ return startupRecoverySelectedHash;
232
+ }
233
+ async function activateStartupCandidateNative(hash, policy) {
234
+ if (!Number.isSafeInteger(policy.maxCrashCount) ||
235
+ policy.maxCrashCount < 0 ||
236
+ policy.maxCrashCount > 2147483647) {
237
+ throw new Error('maxCrashCount must be a non-negative 32-bit integer');
238
+ }
239
+ if (!Number.isFinite(policy.healthyAfterSec) || policy.healthyAfterSec < 0) {
240
+ throw new Error('healthyAfterSec must be a finite non-negative number');
241
+ }
242
+ const nativeModule = requireStartupRecoveryCapability();
243
+ if (!nativeModule)
244
+ return null;
245
+ const result = await nativeModule.activateStartupCandidate(hash, policy.maxCrashCount, policy.healthCheckMode, policy.healthyAfterSec);
246
+ return normalizeCandidateActivation(result);
247
+ }
248
+ async function markStartupHealthyNative(attempt) {
249
+ const nativeModule = requireStartupRecoveryCapability();
250
+ if (!nativeModule)
251
+ return false;
252
+ return nativeModule.markStartupHealthy(attempt.hash, attempt.attemptId);
253
+ }
254
+ async function getStartupRecoveryStateNative() {
255
+ const nativeModule = requireStartupRecoveryCapability();
256
+ if (!nativeModule)
257
+ return null;
258
+ const state = normalizeStartupRecoveryState(await nativeModule.getStartupRecoveryState());
259
+ if (!state) {
260
+ console.warn('[BundleDrop] Ignoring malformed native startup recovery state.');
261
+ }
262
+ return state;
263
+ }
264
+ async function setStartupRecoveryRevokedHashesNative(hashes) {
265
+ const nativeModule = requireStartupRecoveryCapability();
266
+ if (!nativeModule)
267
+ return false;
268
+ return nativeModule.setStartupRecoveryRevokedHashes(Array.from(new Set(hashes)));
269
+ }
270
+ async function acknowledgeStartupRecoveryNative(eventId) {
271
+ const nativeModule = requireStartupRecoveryCapability();
272
+ if (!nativeModule)
273
+ return false;
274
+ return nativeModule.acknowledgeStartupRecovery(eventId);
275
+ }
276
+ async function rollbackStartupBundleNative(forceEmbedded) {
277
+ const nativeModule = requireStartupRecoveryCapability();
278
+ if (!nativeModule)
279
+ return null;
280
+ return normalizeRollbackResult(await nativeModule.rollbackStartupBundle(forceEmbedded));
15
281
  }
16
282
  async function getDownloadedBundlePathNative() {
17
283
  if (!BundleDrop?.getDownloadedBundlePath) {
@@ -7,7 +7,10 @@ declare function unlink(path: string): Promise<void>;
7
7
  declare function moveFile(src: string, dest: string): Promise<void>;
8
8
  declare function unzip(zipPath: string, destPath: string): Promise<string[]>;
9
9
  declare function downloadFile(url: string, destPath: string): Promise<void>;
10
+ declare function downloadFileBounded(url: string, destPath: string, maxBytes: number, timeoutMs: number): Promise<void>;
10
11
  declare function sha256File(path: string): Promise<string>;
12
+ declare function sha256String(value: string): Promise<string>;
13
+ declare function verifyEs256Signature(signingInput: string, signatureBase64Url: string, xBase64Url: string, yBase64Url: string): Promise<boolean>;
11
14
  declare function fileSize(path: string): Promise<number>;
12
15
  declare function copyFile(src: string, dest: string): Promise<void>;
13
16
  declare function applyXdelta(basePath: string, patchPath: string, outputPath: string): Promise<void>;
@@ -27,7 +30,10 @@ declare const BundleDropFS: {
27
30
  moveFile: typeof moveFile;
28
31
  unzip: typeof unzip;
29
32
  downloadFile: typeof downloadFile;
33
+ downloadFileBounded: typeof downloadFileBounded;
30
34
  sha256File: typeof sha256File;
35
+ sha256String: typeof sha256String;
36
+ verifyEs256Signature: typeof verifyEs256Signature;
31
37
  fileSize: typeof fileSize;
32
38
  copyFile: typeof copyFile;
33
39
  applyXdelta: typeof applyXdelta;
package/lib/native/fs.js CHANGED
@@ -44,10 +44,31 @@ async function downloadFile(url, destPath) {
44
44
  assertModule();
45
45
  return BundleDrop.fsDownloadFile(url, destPath);
46
46
  }
47
+ async function downloadFileBounded(url, destPath, maxBytes, timeoutMs) {
48
+ assertModule();
49
+ if (typeof BundleDrop.fsDownloadFileBounded !== 'function') {
50
+ throw new Error('BundleDrop native module is outdated. Rebuild the app for bounded manifest downloads.');
51
+ }
52
+ return BundleDrop.fsDownloadFileBounded(url, destPath, maxBytes, timeoutMs);
53
+ }
47
54
  async function sha256File(path) {
48
55
  assertModule();
49
56
  return BundleDrop.fsSha256File(path);
50
57
  }
58
+ async function sha256String(value) {
59
+ assertModule();
60
+ if (typeof BundleDrop.fsSha256String !== 'function') {
61
+ throw new Error('BundleDrop native module is outdated. Rebuild the app for runtime delivery.');
62
+ }
63
+ return BundleDrop.fsSha256String(value);
64
+ }
65
+ async function verifyEs256Signature(signingInput, signatureBase64Url, xBase64Url, yBase64Url) {
66
+ assertModule();
67
+ if (typeof BundleDrop.fsVerifyEs256Signature !== 'function') {
68
+ throw new Error('BundleDrop native module is outdated. Rebuild the app for runtime delivery.');
69
+ }
70
+ return BundleDrop.fsVerifyEs256Signature(signingInput, signatureBase64Url, xBase64Url, yBase64Url);
71
+ }
51
72
  async function fileSize(path) {
52
73
  assertModule();
53
74
  return BundleDrop.fsFileSize(path);
@@ -85,7 +106,10 @@ const BundleDropFS = {
85
106
  moveFile,
86
107
  unzip,
87
108
  downloadFile,
109
+ downloadFileBounded,
88
110
  sha256File,
111
+ sha256String,
112
+ verifyEs256Signature,
89
113
  fileSize,
90
114
  copyFile,
91
115
  applyXdelta,
@@ -11,6 +11,8 @@ type InstallFromPatchSetParams = {
11
11
  algorithm: SupportedPatchAlgorithm;
12
12
  platform?: 'ios' | 'android';
13
13
  statusCb?: (status: string) => void;
14
+ expectedManifestHash?: string;
15
+ expectedJsBundleHash?: string;
14
16
  };
15
17
  export declare function installFromPatchSet(params: InstallFromPatchSetParams): Promise<InstallResult>;
16
18
  export {};
@@ -32,11 +32,11 @@ const reconstructPatchTarget = async (baseDir, baseHash, platform, patchDir, tar
32
32
  }
33
33
  };
34
34
  async function installFromPatchSet(params) {
35
- const { patchesUrl, patchSetHash, manifestUrl, missingAssetsUrl, missingAssetsHash, baseHash, targetHash, algorithm, statusCb, platform = context_1.platform, } = params;
35
+ const { patchesUrl, patchSetHash, manifestUrl, missingAssetsUrl, missingAssetsHash, baseHash, targetHash, algorithm, statusCb, platform = context_1.platform, expectedManifestHash, expectedJsBundleHash, } = params;
36
36
  (0, bundleInstallShared_1.assertCanonicalBundleHash)(baseHash, 'base hash');
37
37
  (0, bundleInstallShared_1.assertCanonicalBundleHash)(targetHash, 'target hash');
38
- const currentPointer = await (0, bundlePointer_1.readCurrentBundlePointer)();
39
- if (currentPointer?.hash !== baseHash) {
38
+ const currentHash = await (0, bundlePointer_1.readCurrentBundleHash)();
39
+ if (currentHash !== baseHash) {
40
40
  throw new errors_1.InstallPhaseError('install', new Error('Patch base hash does not match current bundle'));
41
41
  }
42
42
  const baseDir = `${context_1.BUNDLE_DROP_ROOT}/bundles/${baseHash}`;
@@ -90,14 +90,19 @@ async function installFromPatchSet(params) {
90
90
  }
91
91
  const assetsZipPath = `${context_1.BUNDLE_DROP_ROOT}/bundles/_patch_assets_${targetHash}.zip`;
92
92
  try {
93
- await fs_1.default.downloadFile(missingAssetsUrl, assetsZipPath);
93
+ try {
94
+ await fs_1.default.downloadFile(missingAssetsUrl, assetsZipPath);
95
+ }
96
+ catch (e) {
97
+ throw new errors_1.InstallPhaseError('download', e);
98
+ }
94
99
  if ((await fs_1.default.sha256File(assetsZipPath)) !== missingAssetsHash) {
95
100
  throw new Error('Missing assets archive hash mismatch');
96
101
  }
97
102
  await fs_1.default.unzip(assetsZipPath, `${patchDir}/missing-assets`);
98
103
  }
99
104
  catch (e) {
100
- throw new errors_1.InstallPhaseError('install', e);
105
+ throw (0, errors_1.isInstallPhaseError)(e) ? e : new errors_1.InstallPhaseError('install', e);
101
106
  }
102
107
  finally {
103
108
  try {
@@ -109,6 +114,12 @@ async function installFromPatchSet(params) {
109
114
  try {
110
115
  targetManifest = await (0, bundleVerification_1.readJsonFile)(`${patchDir}/${bundleManifest_1.BUNDLE_MANIFEST}`);
111
116
  (0, bundleManifest_1.assertValidBundleManifest)(targetManifest, targetHash, platform);
117
+ if (expectedManifestHash && targetManifest.manifestHash !== expectedManifestHash) {
118
+ throw new Error('Signed manifest hash does not match patch target manifest');
119
+ }
120
+ if (expectedJsBundleHash && targetManifest.jsBundleHash !== expectedJsBundleHash) {
121
+ throw new Error('Signed JavaScript bundle hash does not match patch target manifest');
122
+ }
112
123
  await reconstructPatchTarget(baseDir, baseHash, platform, patchDir, targetTempDir, targetManifest, algorithm);
113
124
  await fs_1.default.writeFile(`${targetTempDir}/${bundleManifest_1.BUNDLE_MANIFEST}`, JSON.stringify(targetManifest, null, 2), 'utf8');
114
125
  await (0, bundleVerification_1.verifyBundleDir)(targetTempDir, targetHash, platform);
@@ -6,6 +6,8 @@ export type PatchTransportTarget = {
6
6
  manifestUrl?: string;
7
7
  baseHash?: string;
8
8
  patchSet?: OtaPatchSet;
9
+ expectedManifestHash?: string;
10
+ expectedJsBundleHash?: string;
9
11
  };
10
12
  type TryInstallPatchTransportParams = {
11
13
  target: PatchTransportTarget;
@@ -6,6 +6,7 @@ const installId_1 = require("../fs/installId");
6
6
  const clientApi_1 = require("../api/clientApi");
7
7
  const installFromPatchSet_1 = require("./installFromPatchSet");
8
8
  const patchOperations_1 = require("./patchOperations");
9
+ const artifactCapability_1 = require("../runtime-delivery/artifactCapability");
9
10
  const PATCH_FAILURE_REPORT_TIMEOUT_MS = 1500;
10
11
  const reportPatchInstallFailure = async ({ projectSlug, platform, runtimeVersionValue, baseHash, targetHash, algorithm, error, }) => {
11
12
  try {
@@ -59,11 +60,19 @@ const tryInstallPatchTransport = async ({ target, projectSlug, platform, runtime
59
60
  baseHash: target.baseHash,
60
61
  targetHash: target.hash,
61
62
  algorithm: target.patchSet.algorithm,
63
+ ...(target.expectedManifestHash
64
+ ? { expectedManifestHash: target.expectedManifestHash }
65
+ : {}),
66
+ ...(target.expectedJsBundleHash
67
+ ? { expectedJsBundleHash: target.expectedJsBundleHash }
68
+ : {}),
62
69
  platform,
63
70
  statusCb,
64
71
  });
65
72
  }
66
73
  catch (e) {
74
+ if ((0, artifactCapability_1.isArtifactCapabilityRejected)(e))
75
+ throw e;
67
76
  await reportPatchInstallFailureBeforeFallback({
68
77
  projectSlug,
69
78
  platform,
@@ -1,4 +1,5 @@
1
1
  import type { UpdatePolicy } from '../types';
2
+ import type { RuntimeDeliveryDiagnosticEvent } from '../runtime-delivery/diagnostics';
2
3
  export declare const BUNDLE_DROP_NOT_INITIALIZED_MESSAGE = "BundleDrop has not been initialized. Call BundleDrop.init({ environment, ... }) before using OTA APIs or useBundleDrop().";
3
4
  export declare const BUNDLE_DROP_DISABLED_MESSAGE = "BundleDrop is disabled. OTA APIs are running in no-op mode because BundleDrop.init({ enabled: false, ... }) was used.";
4
5
  /**
@@ -15,6 +16,8 @@ export type BundleDropInitOptions = {
15
16
  policy?: UpdatePolicy;
16
17
  /** Optional listener for human-readable status messages emitted during checks, downloads, and apply flow. */
17
18
  onStatusUpdate?: (status: string) => void;
19
+ /** Optional sink for structured runtime-delivery diagnostic counter events. */
20
+ onRuntimeDeliveryDiagnostic?: (event: RuntimeDeliveryDiagnosticEvent) => void;
18
21
  /** When `true`, startup performs only a resolve/check and skips download/apply even if policy would normally do more. */
19
22
  checkOnly?: boolean;
20
23
  };
@@ -32,6 +35,8 @@ export type BundleDropRuntimeConfig = {
32
35
  policy: UpdatePolicy;
33
36
  /** Optional listener receiving status messages from runtime actions. */
34
37
  onStatusUpdate?: (status: string) => void;
38
+ /** Optional sink receiving structured runtime-delivery diagnostic counter events. */
39
+ onRuntimeDeliveryDiagnostic?: (event: RuntimeDeliveryDiagnosticEvent) => void;
35
40
  /** Whether startup is limited to a resolve/check without downloading or applying. */
36
41
  checkOnly: boolean;
37
42
  };
@@ -53,6 +53,7 @@ function resolveBundleDropRuntimeConfig(options) {
53
53
  channelName,
54
54
  policy: options.policy || 'manual',
55
55
  onStatusUpdate: options.onStatusUpdate,
56
+ onRuntimeDeliveryDiagnostic: options.onRuntimeDeliveryDiagnostic,
56
57
  checkOnly: !!options.checkOnly,
57
58
  };
58
59
  }
@@ -66,6 +67,7 @@ function initializeBundleDropRuntime(options) {
66
67
  initialChannelName: nextConfig.channelName,
67
68
  policy: nextConfig.policy,
68
69
  onStatusUpdate: nextConfig.onStatusUpdate,
70
+ onRuntimeDeliveryDiagnostic: nextConfig.onRuntimeDeliveryDiagnostic,
69
71
  checkOnly: nextConfig.checkOnly,
70
72
  };
71
73
  runtimeConfigKey = nextKey;
@@ -78,6 +80,7 @@ function initializeBundleDropRuntime(options) {
78
80
  initConfig = {
79
81
  ...initConfig,
80
82
  onStatusUpdate: nextConfig.onStatusUpdate,
83
+ onRuntimeDeliveryDiagnostic: nextConfig.onRuntimeDeliveryDiagnostic,
81
84
  };
82
85
  return { config: assertBundleDropInitialized(), alreadyInitialized: true };
83
86
  }
@@ -91,6 +94,7 @@ function getBundleDropRuntimeConfig() {
91
94
  channelName: runtimeChannelName,
92
95
  policy: initConfig.policy,
93
96
  onStatusUpdate: initConfig.onStatusUpdate,
97
+ onRuntimeDeliveryDiagnostic: initConfig.onRuntimeDeliveryDiagnostic,
94
98
  checkOnly: initConfig.checkOnly,
95
99
  };
96
100
  }