@gfean/react-native-bundle-drop 0.6.0 → 0.7.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/BundleDrop.podspec +96 -0
- package/README.md +34 -9
- package/android/build.gradle +65 -0
- package/android/src/main/java/com/bundledrop/BundleDropModule.kt +137 -13
- package/android/src/main/java/com/bundledrop/BundleDropNativePaths.kt +43 -13
- package/android/src/main/java/com/bundledrop/BundleDropOtaResolver.kt +35 -0
- package/android/src/main/java/com/bundledrop/BundleDropStartupRecovery.kt +1117 -0
- package/ios/BundleDropBridge.m +27 -0
- package/ios/BundleDropLocator.swift +31 -15
- package/ios/BundleDropModule.swift +106 -3
- package/ios/BundleDropOtaResolver.swift +137 -29
- package/ios/BundleDropStartupRecovery.swift +1108 -0
- package/ios/BundleDropStartupRecoveryAdapter.swift +301 -0
- package/lib/CLI/cli.js +4 -5
- package/lib/CLI/scripts/doctor.js +28 -9
- package/lib/CLI/scripts/expo/configure-expo.js +2 -1
- package/lib/CLI/scripts/init-config.d.ts +2 -2
- package/lib/CLI/scripts/init-config.js +23 -14
- package/lib/CLI/scripts/login-cli.js +2 -3
- package/lib/CLI/scripts/native/write-runtime-identity.d.ts +19 -0
- package/lib/CLI/scripts/native/write-runtime-identity.js +92 -0
- package/lib/CLI/scripts/upload-cli.d.ts +12 -2
- package/lib/CLI/scripts/upload-cli.js +74 -11
- package/lib/CLI/serverUrl.d.ts +3 -0
- package/lib/CLI/serverUrl.js +31 -0
- package/lib/bundleInfo.d.ts +2 -0
- package/lib/bundleInfo.js +16 -1
- package/lib/context.js +12 -2
- package/lib/fs/bundlePointer.d.ts +1 -17
- package/lib/fs/bundlePointer.js +5 -93
- package/lib/install/bundleInstallShared.js +4 -4
- package/lib/manager/downloadAndInstall.js +25 -22
- package/lib/manager/reporting.d.ts +8 -1
- package/lib/manager/reporting.js +17 -22
- package/lib/manager/rollbackState.d.ts +18 -54
- package/lib/manager/rollbackState.js +115 -216
- package/lib/manager/updateCheck.js +9 -3
- package/lib/manager/updateState.d.ts +2 -1
- package/lib/manager/updateState.js +59 -6
- package/lib/metro.d.ts +1 -1
- package/lib/metro.js +4 -3
- package/lib/native/bundleDropNative.d.ts +62 -0
- package/lib/native/bundleDropNative.js +266 -1
- package/lib/patch-engine/installFromPatchSet.js +2 -2
- package/lib/runtime/service.js +29 -71
- package/lib/runtime-delivery/bootstrapConfig.d.ts +29 -11
- package/lib/runtime-delivery/bootstrapConfig.js +83 -22
- package/lib/runtime-delivery/manifestState.d.ts +3 -1
- package/lib/runtime-delivery/manifestState.js +22 -1
- package/lib/runtime-delivery/manifestVerifier.js +7 -1
- package/lib/scripts/bundle.d.ts +9 -2
- package/lib/scripts/bundle.js +68 -18
- package/lib/scripts/download-bundle.d.ts +1 -0
- package/lib/scripts/download-bundle.js +2 -2
- package/lib/scripts/resolveModule.d.ts +2 -0
- package/lib/scripts/resolveModule.js +5 -0
- package/package.json +5 -2
- package/plugin/xcodeBuildPhase.js +2 -1
|
@@ -1,5 +1,67 @@
|
|
|
1
|
+
declare const STARTUP_RECOVERY_PROTOCOL_VERSION = 1;
|
|
2
|
+
export type StartupRecoveryHealthCheckMode = 'auto' | 'manual';
|
|
3
|
+
export type StartupRecoveryAttempt = {
|
|
4
|
+
hash: string;
|
|
5
|
+
attemptId: string;
|
|
6
|
+
};
|
|
7
|
+
export type StartupRecoverySnapshotAttempt = StartupRecoveryAttempt & {
|
|
8
|
+
status: 'launching';
|
|
9
|
+
unacknowledgedLaunchCount: number;
|
|
10
|
+
};
|
|
11
|
+
export type StartupRecoveryEvent = {
|
|
12
|
+
id: string;
|
|
13
|
+
failedHash: string;
|
|
14
|
+
recoveryTarget: 'previous' | 'embedded';
|
|
15
|
+
recoveredHash?: string;
|
|
16
|
+
crashCount: number;
|
|
17
|
+
reason: 'crash_loop';
|
|
18
|
+
failedAt: number;
|
|
19
|
+
};
|
|
20
|
+
export type StartupRecoveryState = {
|
|
21
|
+
protocolVersion: typeof STARTUP_RECOVERY_PROTOCOL_VERSION;
|
|
22
|
+
revision: number;
|
|
23
|
+
phase: 'idle' | 'armed' | 'launching' | 'stable' | 'recovered';
|
|
24
|
+
candidateHash?: string;
|
|
25
|
+
stableHash?: string;
|
|
26
|
+
activeAttempt?: StartupRecoverySnapshotAttempt;
|
|
27
|
+
policy?: {
|
|
28
|
+
maxCrashCount: number;
|
|
29
|
+
healthCheckMode: StartupRecoveryHealthCheckMode;
|
|
30
|
+
healthyAfterSec: number;
|
|
31
|
+
};
|
|
32
|
+
quarantinedHashes: string[];
|
|
33
|
+
pendingRecoveryEvents: StartupRecoveryEvent[];
|
|
34
|
+
};
|
|
35
|
+
export type StartupCandidateActivation = {
|
|
36
|
+
hash: string;
|
|
37
|
+
bundlePath: string;
|
|
38
|
+
};
|
|
39
|
+
export type StartupRollbackResult = {
|
|
40
|
+
rolledBack: boolean;
|
|
41
|
+
toEmbedded: boolean;
|
|
42
|
+
hash?: string;
|
|
43
|
+
};
|
|
1
44
|
export declare function isBundleDropNativeAvailable(): boolean;
|
|
2
45
|
export declare function isExpoOtaStartupEnabledNative(): boolean;
|
|
46
|
+
export declare function isStartupRecoveryAvailableNative(): boolean;
|
|
47
|
+
export declare function warnIfStartupRecoveryUnavailableNative(): void;
|
|
48
|
+
export declare function getStartupRecoveryAttemptNative(): StartupRecoveryAttempt | null;
|
|
49
|
+
/**
|
|
50
|
+
* Hash selected for this exact React runtime. `undefined` means the installed
|
|
51
|
+
* native adapter predates this constant; `null` means native selected embedded.
|
|
52
|
+
*/
|
|
53
|
+
export declare function getStartupRecoverySelectedHashNative(): string | null | undefined;
|
|
54
|
+
export declare function activateStartupCandidateNative(hash: string, policy: {
|
|
55
|
+
maxCrashCount: number;
|
|
56
|
+
healthCheckMode: StartupRecoveryHealthCheckMode;
|
|
57
|
+
healthyAfterSec: number;
|
|
58
|
+
}): Promise<StartupCandidateActivation | null>;
|
|
59
|
+
export declare function markStartupHealthyNative(attempt: StartupRecoveryAttempt): Promise<boolean>;
|
|
60
|
+
export declare function getStartupRecoveryStateNative(): Promise<StartupRecoveryState | null>;
|
|
61
|
+
export declare function setStartupRecoveryRevokedHashesNative(hashes: string[]): Promise<boolean>;
|
|
62
|
+
export declare function acknowledgeStartupRecoveryNative(eventId: string): Promise<boolean>;
|
|
63
|
+
export declare function rollbackStartupBundleNative(forceEmbedded: boolean): Promise<StartupRollbackResult | null>;
|
|
3
64
|
export declare function getDownloadedBundlePathNative(): Promise<string | null>;
|
|
4
65
|
export declare function restartReactNativeNative(): void;
|
|
5
66
|
export declare function setOtaEnabledNative(enabled: boolean): Promise<void>;
|
|
67
|
+
export {};
|
|
@@ -2,11 +2,209 @@
|
|
|
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
|
|
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
|
}
|
|
@@ -14,6 +212,73 @@ function isExpoOtaStartupEnabledNative() {
|
|
|
14
212
|
const nativeValue = BundleDropExpoIdentity?.otaStartupEnabled;
|
|
15
213
|
return nativeValue === true || nativeValue === 1;
|
|
16
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));
|
|
281
|
+
}
|
|
17
282
|
async function getDownloadedBundlePathNative() {
|
|
18
283
|
if (!BundleDrop?.getDownloadedBundlePath) {
|
|
19
284
|
console.warn('BundleDrop.getDownloadedBundlePath is not defined');
|
|
@@ -35,8 +35,8 @@ async function installFromPatchSet(params) {
|
|
|
35
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
|
|
39
|
-
if (
|
|
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}`;
|
package/lib/runtime/service.js
CHANGED
|
@@ -50,7 +50,6 @@ const MANAGED_DIRECT_INSTALL_NOT_AUTHORIZED_STATUS = '⚠️ Direct URL installs
|
|
|
50
50
|
let updateFlowActive = false;
|
|
51
51
|
let startupPromise = null;
|
|
52
52
|
let localStartupPromise = null;
|
|
53
|
-
let healthTimer = null;
|
|
54
53
|
let runtimeRestartRequested = false;
|
|
55
54
|
let activeBundleInfoForObservability = null;
|
|
56
55
|
let nativeOtaEnabledPromise = Promise.resolve();
|
|
@@ -168,58 +167,23 @@ function getApplyStatus(result) {
|
|
|
168
167
|
? '⚠️ Update previously failed on this device'
|
|
169
168
|
: 'ℹ️ Bundle already applied';
|
|
170
169
|
}
|
|
171
|
-
function clearHealthTimer() {
|
|
172
|
-
if (!healthTimer)
|
|
173
|
-
return;
|
|
174
|
-
clearTimeout(healthTimer);
|
|
175
|
-
healthTimer = null;
|
|
176
|
-
}
|
|
177
170
|
function requestRuntimeRestart() {
|
|
178
171
|
runtimeRestartRequested = true;
|
|
179
172
|
(0, bundleDropNative_1.restartReactNativeNative)();
|
|
180
173
|
}
|
|
181
174
|
async function applyAuthoritativeRollback(reason) {
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
else {
|
|
186
|
-
await (0, rollbackState_1.rollbackToPreviousOrNative)();
|
|
175
|
+
const result = await (0, rollbackState_1.rollbackStartupBundle)(isCurrentRevokedRollback(reason));
|
|
176
|
+
if (result?.rolledBack) {
|
|
177
|
+
requestRuntimeRestart();
|
|
187
178
|
}
|
|
188
|
-
requestRuntimeRestart();
|
|
189
179
|
}
|
|
190
|
-
async function markActiveCandidateHealthy(
|
|
191
|
-
|
|
192
|
-
return false;
|
|
193
|
-
}
|
|
194
|
-
const state = await (0, updateState_1.getUpdateState)();
|
|
195
|
-
if (runtimeRestartRequested) {
|
|
196
|
-
return false;
|
|
197
|
-
}
|
|
198
|
-
if (state.pendingApply) {
|
|
199
|
-
return false;
|
|
200
|
-
}
|
|
201
|
-
const markedHealthy = await (0, rollbackState_1.reportActiveBundleHealthy)(undefined, expectedHash);
|
|
180
|
+
async function markActiveCandidateHealthy() {
|
|
181
|
+
const markedHealthy = await (0, rollbackState_1.reportActiveBundleHealthy)();
|
|
202
182
|
if (markedHealthy) {
|
|
203
183
|
await refreshState();
|
|
204
184
|
}
|
|
205
185
|
return markedHealthy;
|
|
206
186
|
}
|
|
207
|
-
function scheduleCandidateHealthMark(currentPointer, rollbackState) {
|
|
208
|
-
clearHealthTimer();
|
|
209
|
-
const hash = currentPointer?.hash;
|
|
210
|
-
const rollbackPolicy = (0, rollbackState_1.getRollbackPolicy)();
|
|
211
|
-
if (!hash || rollbackPolicy.healthCheckMode === 'manual')
|
|
212
|
-
return;
|
|
213
|
-
if (rollbackState?.candidateHash !== hash || rollbackState.candidateCommitted === true)
|
|
214
|
-
return;
|
|
215
|
-
const delayMs = Math.max(0, rollbackPolicy.healthyAfterSec || 0) * 1000;
|
|
216
|
-
healthTimer = setTimeout(() => {
|
|
217
|
-
healthTimer = null;
|
|
218
|
-
markActiveCandidateHealthy(hash).catch(error => {
|
|
219
|
-
console.warn('⚠️ Failed to mark BundleDrop candidate healthy:', error);
|
|
220
|
-
});
|
|
221
|
-
}, delayMs);
|
|
222
|
-
}
|
|
223
187
|
async function refreshState(cached) {
|
|
224
188
|
const state = await (0, updateState_1.getUpdateState)(cached);
|
|
225
189
|
patchSnapshot({
|
|
@@ -257,21 +221,27 @@ async function waitForLocalStartupIfNeeded() {
|
|
|
257
221
|
}
|
|
258
222
|
}
|
|
259
223
|
async function runLocalStartupFlow() {
|
|
260
|
-
const [bundleInfo, bundlePath,
|
|
224
|
+
const [bundleInfo, bundlePath, currentHash, recoveryState] = await Promise.all([
|
|
261
225
|
(0, bundleInfo_1.readBundleInfo)(),
|
|
262
226
|
(0, bundleDropNative_1.getDownloadedBundlePathNative)(),
|
|
263
|
-
(0, bundlePointer_1.
|
|
264
|
-
(0, rollbackState_1.
|
|
227
|
+
(0, bundlePointer_1.readCurrentBundleHash)(),
|
|
228
|
+
(0, rollbackState_1.readStartupRecoveryState)(),
|
|
265
229
|
]);
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
230
|
+
void (0, rollbackState_1.reconcileStartupRecovery)(recoveryState, bundleInfo).catch(error => {
|
|
231
|
+
console.warn('⚠️ Failed to reconcile BundleDrop startup recovery telemetry:', error);
|
|
232
|
+
});
|
|
233
|
+
const reconciledBundleInfo = await (0, updateState_1.reconcileAppliedBundleOnLaunch)({
|
|
234
|
+
bundleInfo,
|
|
271
235
|
bundlePath,
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
};
|
|
236
|
+
currentHash,
|
|
237
|
+
});
|
|
238
|
+
await refreshState({ bundleInfo: reconciledBundleInfo, bundlePath });
|
|
239
|
+
const state = await (0, updateState_1.getUpdateState)({
|
|
240
|
+
bundleInfo: reconciledBundleInfo,
|
|
241
|
+
bundlePath,
|
|
242
|
+
});
|
|
243
|
+
activeBundleInfoForObservability = state.hasBundle ? state.info || null : null;
|
|
244
|
+
return { bundlePath };
|
|
275
245
|
}
|
|
276
246
|
async function runStartupFlow() {
|
|
277
247
|
const runtime = (0, initState_1.assertBundleDropInitialized)();
|
|
@@ -281,19 +251,7 @@ async function runStartupFlow() {
|
|
|
281
251
|
await nativeOtaEnabledPromise;
|
|
282
252
|
return runLocalStartupFlow();
|
|
283
253
|
})();
|
|
284
|
-
const { bundlePath
|
|
285
|
-
const rollbackPolicy = (0, rollbackState_1.getRollbackPolicy)();
|
|
286
|
-
const rollbackResult = await (0, rollbackState_1.rollbackToPreviousIfNeeded)(rollbackPolicy, {
|
|
287
|
-
currentPointer,
|
|
288
|
-
rollbackState,
|
|
289
|
-
});
|
|
290
|
-
if (rollbackResult.rolledBack) {
|
|
291
|
-
clearHealthTimer();
|
|
292
|
-
emitStatus('↩️ Rolled back to previous bundle');
|
|
293
|
-
requestRuntimeRestart();
|
|
294
|
-
return;
|
|
295
|
-
}
|
|
296
|
-
scheduleCandidateHealthMark(currentPointer, await (0, rollbackState_1.readRollbackState)());
|
|
254
|
+
const { bundlePath } = await localStartupPromise;
|
|
297
255
|
const pendingState = await refreshState({ bundlePath });
|
|
298
256
|
if (pendingState.pendingApply) {
|
|
299
257
|
if (runtime.policy === 'immediate') {
|
|
@@ -408,6 +366,9 @@ function initBundleDrop(options) {
|
|
|
408
366
|
if (!alreadyInitialized) {
|
|
409
367
|
runtimeRestartRequested = false;
|
|
410
368
|
activeBundleInfoForObservability = null;
|
|
369
|
+
if (config.enabled) {
|
|
370
|
+
(0, bundleDropNative_1.warnIfStartupRecoveryUnavailableNative)();
|
|
371
|
+
}
|
|
411
372
|
}
|
|
412
373
|
// Persist for the next cold start and for native path reads in this process.
|
|
413
374
|
nativeOtaEnabledPromise = (0, bundleDropNative_1.setOtaEnabledNative)(config.enabled);
|
|
@@ -528,11 +489,9 @@ async function reportHealthy() {
|
|
|
528
489
|
if (!runtime) {
|
|
529
490
|
return;
|
|
530
491
|
}
|
|
531
|
-
|
|
532
|
-
if (runtimeRestartRequested || updateFlowActive) {
|
|
492
|
+
if (runtimeRestartRequested) {
|
|
533
493
|
return;
|
|
534
494
|
}
|
|
535
|
-
clearHealthTimer();
|
|
536
495
|
await markActiveCandidateHealthy();
|
|
537
496
|
}
|
|
538
497
|
/**
|
|
@@ -695,9 +654,9 @@ async function getObservabilityContext() {
|
|
|
695
654
|
}
|
|
696
655
|
return {
|
|
697
656
|
source: 'ota',
|
|
698
|
-
dist: info.hash
|
|
657
|
+
dist: info.hash,
|
|
699
658
|
tags: {
|
|
700
|
-
bundle_drop_hash: info.hash
|
|
659
|
+
bundle_drop_hash: info.hash,
|
|
701
660
|
bundle_drop_channel: info.channelName ?? null,
|
|
702
661
|
bundle_drop_version: info.bundleVersion != null ? `${info.bundleVersion}` : null,
|
|
703
662
|
bundle_drop_runtime_version: info.runtimeVersion ?? null,
|
|
@@ -778,7 +737,6 @@ async function installBundle(hash, downloadUrl, bundleVersion, version, runtimeV
|
|
|
778
737
|
});
|
|
779
738
|
}
|
|
780
739
|
function resetBundleDropRuntimeServiceForTests() {
|
|
781
|
-
clearHealthTimer();
|
|
782
740
|
updateFlowActive = false;
|
|
783
741
|
startupPromise = null;
|
|
784
742
|
localStartupPromise = null;
|
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
export declare const RUNTIME_DELIVERY_BOOTSTRAP_SCHEMA_VERSION = 1;
|
|
2
2
|
export declare const RUNTIME_DELIVERY_BOOTSTRAP_PATH: string;
|
|
3
|
-
export declare const
|
|
3
|
+
export declare const LEGACY_RUNTIME_DELIVERY_BOOTSTRAP_PATH: string;
|
|
4
|
+
export declare const RUNTIME_DELIVERY_BOOTSTRAP_GITIGNORE_MARKER = "!.bundle-drop/runtime-delivery.lock.json";
|
|
5
|
+
export declare const LEGACY_RUNTIME_DELIVERY_BOOTSTRAP_GITIGNORE_MARKER = "!.bundle-drop/runtime-delivery.generated.json";
|
|
4
6
|
export type RuntimeDeliveryPublicKey = {
|
|
5
7
|
kty: 'EC';
|
|
6
8
|
crv: 'P-256';
|
|
@@ -19,32 +21,48 @@ export type RuntimeDeliveryProjectIdentity = {
|
|
|
19
21
|
projectId?: string;
|
|
20
22
|
orgId?: string;
|
|
21
23
|
};
|
|
22
|
-
export type
|
|
24
|
+
export type RuntimeDeliveryBootstrapLockfile = {
|
|
23
25
|
schemaVersion: typeof RUNTIME_DELIVERY_BOOTSTRAP_SCHEMA_VERSION;
|
|
24
26
|
project: RuntimeDeliveryProjectIdentity;
|
|
25
27
|
runtimeDelivery: RuntimeDeliveryConfig;
|
|
26
28
|
};
|
|
29
|
+
export type RuntimeDeliveryBootstrapSource = 'lock' | 'legacy' | 'matching-dual';
|
|
30
|
+
export type RuntimeDeliveryBootstrapReadResult = {
|
|
31
|
+
bootstrap: RuntimeDeliveryBootstrapLockfile;
|
|
32
|
+
source: RuntimeDeliveryBootstrapSource;
|
|
33
|
+
};
|
|
27
34
|
/**
|
|
28
35
|
* Accepts the current backend-authorized trust shape and the temporary legacy
|
|
29
36
|
* wire shape. Explicit legacy non-authoritative modes must never create a
|
|
30
37
|
* package-managed bootstrap.
|
|
31
38
|
*/
|
|
32
39
|
export declare function normalizeRuntimeDeliveryBootstrap(value: unknown): RuntimeDeliveryConfig | undefined;
|
|
33
|
-
export declare function
|
|
40
|
+
export declare function createRuntimeDeliveryBootstrapLockfile(params: {
|
|
34
41
|
identity: RuntimeDeliveryProjectIdentity;
|
|
35
42
|
runtimeDelivery: unknown;
|
|
36
|
-
}):
|
|
37
|
-
export declare function
|
|
43
|
+
}): RuntimeDeliveryBootstrapLockfile | undefined;
|
|
44
|
+
export declare function parseRuntimeDeliveryBootstrapLockfile(value: unknown, expectedIdentity?: RuntimeDeliveryProjectIdentity): RuntimeDeliveryBootstrapLockfile;
|
|
38
45
|
export declare function runtimeDeliveryBootstrapPath(projectRoot: string): string;
|
|
46
|
+
export declare function legacyRuntimeDeliveryBootstrapPath(projectRoot: string): string;
|
|
39
47
|
export declare function addRuntimeDeliveryBootstrapGitignoreRules(content: string): string;
|
|
40
|
-
export declare function
|
|
48
|
+
export declare function readRuntimeDeliveryLockfile(params: {
|
|
49
|
+
projectRoot: string;
|
|
50
|
+
expectedIdentity?: RuntimeDeliveryProjectIdentity;
|
|
51
|
+
}): RuntimeDeliveryBootstrapLockfile | null;
|
|
52
|
+
export declare function inspectRuntimeDeliveryBootstrap(params: {
|
|
53
|
+
projectRoot: string;
|
|
54
|
+
expectedIdentity?: RuntimeDeliveryProjectIdentity;
|
|
55
|
+
}): RuntimeDeliveryBootstrapReadResult | null;
|
|
56
|
+
export declare function readRuntimeDeliveryBootstrap(params: {
|
|
41
57
|
projectRoot: string;
|
|
42
58
|
expectedIdentity?: RuntimeDeliveryProjectIdentity;
|
|
43
|
-
}):
|
|
44
|
-
export declare function
|
|
45
|
-
export declare function
|
|
59
|
+
}): RuntimeDeliveryBootstrapLockfile | null;
|
|
60
|
+
export declare function serializeRuntimeDeliveryBootstrapLockfile(bootstrap: RuntimeDeliveryBootstrapLockfile): string;
|
|
61
|
+
export declare function writeRuntimeDeliveryBootstrapLockfile(params: {
|
|
46
62
|
projectRoot: string;
|
|
47
|
-
bootstrap:
|
|
63
|
+
bootstrap: RuntimeDeliveryBootstrapLockfile;
|
|
48
64
|
}): Promise<string>;
|
|
49
|
-
export declare function
|
|
65
|
+
export declare function removeRuntimeDeliveryBootstrapLockfile(projectRoot: string): Promise<string | null>;
|
|
66
|
+
export declare function removeLegacyRuntimeDeliveryBootstrap(projectRoot: string): Promise<string | null>;
|
|
67
|
+
export declare function removeAllRuntimeDeliveryBootstraps(projectRoot: string): Promise<string[]>;
|
|
50
68
|
export declare function ensureRuntimeDeliveryBootstrapGitignore(projectRoot: string): Promise<string>;
|