@gfean/react-native-bundle-drop 0.3.5 → 0.3.6
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/ios/BundleDropLocator.h +11 -0
- package/ios/BundleDropLocator.swift +1 -1
- package/lib/CLI/cli.js +56 -6
- package/lib/CLI/scripts/aipowered/apply-plan.d.ts +10 -0
- package/lib/CLI/scripts/aipowered/apply-plan.js +50 -0
- package/lib/CLI/scripts/aipowered/backend-client.d.ts +6 -0
- package/lib/CLI/scripts/aipowered/backend-client.js +34 -0
- package/lib/CLI/scripts/aipowered/diff-preview.d.ts +7 -0
- package/lib/CLI/scripts/aipowered/diff-preview.js +33 -0
- package/lib/CLI/scripts/aipowered/init-native-config.d.ts +2 -0
- package/lib/CLI/scripts/aipowered/init-native-config.js +131 -0
- package/lib/CLI/scripts/aipowered/scanner.d.ts +5 -0
- package/lib/CLI/scripts/aipowered/scanner.js +349 -0
- package/lib/CLI/scripts/aipowered/types.d.ts +53 -0
- package/lib/CLI/scripts/aipowered/types.js +2 -0
- package/lib/CLI/scripts/aipowered/validate-plan.d.ts +8 -0
- package/lib/CLI/scripts/aipowered/validate-plan.js +164 -0
- package/lib/CLI/scripts/init-config.js +10 -5
- package/lib/CLI/scripts/init-native-config.js +1 -1
- package/lib/CLI/scripts/post-init.js +7 -18
- package/lib/CLI/scripts/upload-cli.d.ts +2 -0
- package/lib/CLI/scripts/upload-cli.js +53 -25
- package/lib/CLI/utils/ui.d.ts +3 -0
- package/lib/CLI/utils/ui.js +26 -0
- package/lib/api/clientApi.d.ts +2 -1
- package/lib/api/clientApi.js +9 -0
- package/lib/api/types.d.ts +17 -0
- package/lib/context.d.ts +4 -4
- package/lib/context.js +2 -2
- package/lib/fs/bundlePointer.d.ts +2 -0
- package/lib/fs/bundlePointer.js +14 -4
- package/lib/index.d.ts +6 -3
- package/lib/index.js +5 -1
- package/lib/injectImageResolver.js +6 -15
- package/lib/loadConfig.d.ts +4 -4
- package/lib/manager/downloadAndInstall.d.ts +3 -0
- package/lib/manager/downloadAndInstall.js +23 -3
- package/lib/manager/reporting.d.ts +2 -0
- package/lib/manager/reporting.js +25 -0
- package/lib/manager/rollbackState.d.ts +25 -8
- package/lib/manager/rollbackState.js +87 -22
- package/lib/manager/updateCheck.js +15 -1
- package/lib/manager/updateState.d.ts +5 -1
- package/lib/manager/updateState.js +20 -11
- package/lib/runtime/service.d.ts +28 -0
- package/lib/runtime/service.js +134 -10
- package/lib/scripts/bundle.d.ts +4 -1
- package/lib/scripts/bundle.js +41 -28
- package/lib/scripts/projectRoot.d.ts +1 -0
- package/lib/scripts/projectRoot.js +54 -0
- package/lib/scripts/upload-bundle.d.ts +2 -1
- package/lib/scripts/upload-bundle.js +46 -37
- package/lib/useBundleDrop.d.ts +2 -0
- package/lib/useBundleDrop.js +1 -0
- package/package.json +3 -2
|
@@ -5,7 +5,10 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
6
|
exports.readRollbackState = readState;
|
|
7
7
|
exports.markCandidateActivated = markCandidateActivated;
|
|
8
|
+
exports.reportActiveBundleHealthy = reportActiveBundleHealthy;
|
|
8
9
|
exports.commitActiveBundle = commitActiveBundle;
|
|
10
|
+
exports.isBundleHashFailed = isBundleHashFailed;
|
|
11
|
+
exports.getFailedBundleHashes = getFailedBundleHashes;
|
|
9
12
|
exports.evaluateRollbackOnLaunch = evaluateRollbackOnLaunch;
|
|
10
13
|
exports.rollbackToPreviousIfNeeded = rollbackToPreviousIfNeeded;
|
|
11
14
|
exports.getRollbackPolicy = getRollbackPolicy;
|
|
@@ -15,7 +18,9 @@ const context_1 = require("../context");
|
|
|
15
18
|
const fsUtils_1 = require("../fs/fsUtils");
|
|
16
19
|
const bundlePointer_1 = require("../fs/bundlePointer");
|
|
17
20
|
const bundleInfo_1 = require("../bundleInfo");
|
|
21
|
+
const reporting_1 = require("./reporting");
|
|
18
22
|
const STATE_PATH = `${context_1.BUNDLE_DROP_ROOT}/state.json`;
|
|
23
|
+
const MAX_FAILED_BUNDLES = 20;
|
|
19
24
|
function nowSec() {
|
|
20
25
|
return Math.floor(Date.now() / 1000);
|
|
21
26
|
}
|
|
@@ -40,6 +45,11 @@ async function updateState(partial) {
|
|
|
40
45
|
await writeState(next);
|
|
41
46
|
return next;
|
|
42
47
|
}
|
|
48
|
+
function pruneFailedBundles(failedBundles) {
|
|
49
|
+
return Object.fromEntries(Object.entries(failedBundles)
|
|
50
|
+
.sort(([, left], [, right]) => right.failedAt - left.failedAt)
|
|
51
|
+
.slice(0, MAX_FAILED_BUNDLES));
|
|
52
|
+
}
|
|
43
53
|
async function markCandidateActivated(hash) {
|
|
44
54
|
const previous = await (0, bundlePointer_1.readPreviousBundlePointer)();
|
|
45
55
|
const previousHash = previous?.hash;
|
|
@@ -50,24 +60,68 @@ async function markCandidateActivated(hash) {
|
|
|
50
60
|
candidateActivatedAt: now,
|
|
51
61
|
candidateCommitted: false,
|
|
52
62
|
crashCount: 0,
|
|
53
|
-
crashWindowStartedAt: now,
|
|
54
63
|
lastLaunchAt: now,
|
|
55
64
|
lastGoodHash: previousHash ?? undefined,
|
|
56
65
|
});
|
|
57
66
|
}
|
|
58
|
-
async function
|
|
67
|
+
async function reportActiveBundleHealthy(cached, expectedHash) {
|
|
59
68
|
const current = cached?.currentPointer !== undefined ? cached.currentPointer : await (0, bundlePointer_1.readCurrentBundlePointer)();
|
|
60
69
|
const hash = current?.hash;
|
|
61
70
|
if (!hash)
|
|
62
|
-
return;
|
|
71
|
+
return false;
|
|
72
|
+
if (expectedHash && hash !== expectedHash)
|
|
73
|
+
return false;
|
|
74
|
+
const state = (await readState()) || {};
|
|
75
|
+
const isCandidate = state.candidateHash === hash && state.candidateCommitted !== true;
|
|
76
|
+
if (!isCandidate)
|
|
77
|
+
return false;
|
|
63
78
|
await updateState({
|
|
64
79
|
activeHash: hash,
|
|
65
80
|
candidateHash: hash,
|
|
66
81
|
candidateCommitted: true,
|
|
67
82
|
crashCount: 0,
|
|
68
|
-
crashWindowStartedAt: nowSec(),
|
|
69
83
|
lastGoodHash: hash,
|
|
70
84
|
});
|
|
85
|
+
return true;
|
|
86
|
+
}
|
|
87
|
+
async function commitActiveBundle(cached) {
|
|
88
|
+
await reportActiveBundleHealthy(cached);
|
|
89
|
+
}
|
|
90
|
+
async function isBundleHashFailed(hash) {
|
|
91
|
+
if (!hash)
|
|
92
|
+
return false;
|
|
93
|
+
const state = await readState();
|
|
94
|
+
return !!state?.failedBundles?.[hash];
|
|
95
|
+
}
|
|
96
|
+
async function getFailedBundleHashes() {
|
|
97
|
+
const state = await readState();
|
|
98
|
+
return Object.entries(state?.failedBundles || {})
|
|
99
|
+
.sort(([, left], [, right]) => right.failedAt - left.failedAt)
|
|
100
|
+
.slice(0, MAX_FAILED_BUNDLES)
|
|
101
|
+
.map(([hash]) => hash);
|
|
102
|
+
}
|
|
103
|
+
async function buildFailedBundleRecord(hash, reason, state) {
|
|
104
|
+
const [bundleInfo, previous] = await Promise.all([
|
|
105
|
+
(0, bundleInfo_1.readBundleInfo)(),
|
|
106
|
+
(0, bundlePointer_1.readPreviousBundlePointer)(),
|
|
107
|
+
]);
|
|
108
|
+
const record = {
|
|
109
|
+
reason,
|
|
110
|
+
failedAt: nowSec(),
|
|
111
|
+
crashCount: state.crashCount,
|
|
112
|
+
channelName: bundleInfo?.channelName,
|
|
113
|
+
runtimeVersion: bundleInfo?.runtimeVersion,
|
|
114
|
+
previousHash: previous?.hash,
|
|
115
|
+
};
|
|
116
|
+
return record;
|
|
117
|
+
}
|
|
118
|
+
async function recordFailedBundle(hash, record) {
|
|
119
|
+
const state = (await readState()) || {};
|
|
120
|
+
const failedBundles = pruneFailedBundles({
|
|
121
|
+
...(state.failedBundles || {}),
|
|
122
|
+
[hash]: record,
|
|
123
|
+
});
|
|
124
|
+
await updateState({ failedBundles });
|
|
71
125
|
}
|
|
72
126
|
async function evaluateRollbackOnLaunch(policy, cached) {
|
|
73
127
|
const current = cached?.currentPointer !== undefined ? cached.currentPointer : await (0, bundlePointer_1.readCurrentBundlePointer)();
|
|
@@ -75,7 +129,14 @@ async function evaluateRollbackOnLaunch(policy, cached) {
|
|
|
75
129
|
if (!activeHash)
|
|
76
130
|
return { shouldRollback: false };
|
|
77
131
|
const now = nowSec();
|
|
78
|
-
const
|
|
132
|
+
const persistedState = (await readState()) || {};
|
|
133
|
+
const state = cached?.rollbackState !== undefined
|
|
134
|
+
? {
|
|
135
|
+
...persistedState,
|
|
136
|
+
...cached.rollbackState,
|
|
137
|
+
failedBundles: persistedState.failedBundles ?? cached.rollbackState?.failedBundles,
|
|
138
|
+
}
|
|
139
|
+
: persistedState;
|
|
79
140
|
const next = {
|
|
80
141
|
...state,
|
|
81
142
|
activeHash,
|
|
@@ -83,22 +144,13 @@ async function evaluateRollbackOnLaunch(policy, cached) {
|
|
|
83
144
|
};
|
|
84
145
|
const isCandidate = state.candidateHash === activeHash && state.candidateCommitted !== true;
|
|
85
146
|
if (isCandidate) {
|
|
86
|
-
const
|
|
87
|
-
const inWindow = now - windowStart <= policy.crashWindowSec;
|
|
88
|
-
const crashCount = inWindow ? (state.crashCount ?? 0) + 1 : 1;
|
|
147
|
+
const crashCount = (state.crashCount ?? 0) + 1;
|
|
89
148
|
next.crashCount = crashCount;
|
|
90
|
-
next.crashWindowStartedAt = inWindow ? windowStart : now;
|
|
91
149
|
if (policy.maxCrashCount > 0 &&
|
|
92
150
|
crashCount >= policy.maxCrashCount) {
|
|
93
151
|
await writeState(next);
|
|
94
152
|
return { shouldRollback: true, reason: 'crash_loop' };
|
|
95
153
|
}
|
|
96
|
-
if (policy.commitTimeoutSec > 0 &&
|
|
97
|
-
state.candidateActivatedAt &&
|
|
98
|
-
now - state.candidateActivatedAt > policy.commitTimeoutSec) {
|
|
99
|
-
await writeState(next);
|
|
100
|
-
return { shouldRollback: true, reason: 'commit_timeout' };
|
|
101
|
-
}
|
|
102
154
|
}
|
|
103
155
|
await writeState(next);
|
|
104
156
|
return { shouldRollback: false };
|
|
@@ -107,15 +159,29 @@ async function rollbackToPreviousIfNeeded(policy, cached) {
|
|
|
107
159
|
const decision = await evaluateRollbackOnLaunch(policy, cached);
|
|
108
160
|
if (!decision.shouldRollback)
|
|
109
161
|
return { rolledBack: false };
|
|
110
|
-
const
|
|
111
|
-
|
|
162
|
+
const current = cached?.currentPointer !== undefined ? cached.currentPointer : await (0, bundlePointer_1.readCurrentBundlePointer)();
|
|
163
|
+
const failedHash = current?.hash;
|
|
164
|
+
const state = (await readState()) || {};
|
|
165
|
+
if (!failedHash)
|
|
166
|
+
return { rolledBack: false };
|
|
167
|
+
const failedRecord = await buildFailedBundleRecord(failedHash, decision.reason, state);
|
|
168
|
+
await rollbackToPreviousOrNative();
|
|
169
|
+
await recordFailedBundle(failedHash, failedRecord);
|
|
170
|
+
await (0, reporting_1.reportLocalRollback)(failedHash, failedRecord).catch(() => undefined);
|
|
171
|
+
return { rolledBack: true, reason: decision.reason };
|
|
112
172
|
}
|
|
113
173
|
function getRollbackPolicy() {
|
|
114
174
|
return context_1.bundleDropConfig.rollback;
|
|
115
175
|
}
|
|
116
176
|
async function rollbackToPreviousOrNative() {
|
|
117
|
-
const previous = await
|
|
118
|
-
|
|
177
|
+
const [current, previous, state] = await Promise.all([
|
|
178
|
+
(0, bundlePointer_1.readCurrentBundlePointer)(),
|
|
179
|
+
(0, bundlePointer_1.readPreviousBundlePointer)(),
|
|
180
|
+
readState(),
|
|
181
|
+
]);
|
|
182
|
+
const previousIsFailed = previous ? !!state?.failedBundles?.[previous.hash] : false;
|
|
183
|
+
if (previous && previous.hash !== current?.hash && !previousIsFailed) {
|
|
184
|
+
await (0, bundlePointer_1.writeCurrentBundlePointer)({ ...previous, updatedAt: new Date().toISOString() });
|
|
119
185
|
const metadata = await readBundleMetadata(previous.bundlePath);
|
|
120
186
|
await (0, bundleInfo_1.updateBundleInfo)({
|
|
121
187
|
hash: previous.hash,
|
|
@@ -130,12 +196,12 @@ async function rollbackToPreviousOrNative() {
|
|
|
130
196
|
candidateHash: previous.hash,
|
|
131
197
|
candidateCommitted: true,
|
|
132
198
|
crashCount: 0,
|
|
133
|
-
crashWindowStartedAt: nowSec(),
|
|
134
199
|
});
|
|
135
200
|
return { rolledBack: true };
|
|
136
201
|
}
|
|
137
202
|
// No previous OTA bundle exists; fall back to native bundle by clearing the active pointer.
|
|
138
|
-
await (0, bundlePointer_1.
|
|
203
|
+
await (0, bundlePointer_1.deleteCurrentBundlePointer)();
|
|
204
|
+
await (0, bundlePointer_1.deletePreviousBundlePointer)();
|
|
139
205
|
await (0, bundleInfo_1.updateBundleInfo)({
|
|
140
206
|
hash: undefined,
|
|
141
207
|
bundleVersion: undefined,
|
|
@@ -149,7 +215,6 @@ async function rollbackToPreviousOrNative() {
|
|
|
149
215
|
candidateHash: undefined,
|
|
150
216
|
candidateCommitted: true,
|
|
151
217
|
crashCount: 0,
|
|
152
|
-
crashWindowStartedAt: nowSec(),
|
|
153
218
|
});
|
|
154
219
|
return { rolledBack: true, toNative: true };
|
|
155
220
|
}
|
|
@@ -12,6 +12,7 @@ const bundlePointer_1 = require("../fs/bundlePointer");
|
|
|
12
12
|
const installId_1 = require("../fs/installId");
|
|
13
13
|
const userProperties_1 = require("../fs/userProperties");
|
|
14
14
|
const initState_1 = require("../runtime/initState");
|
|
15
|
+
const rollbackState_1 = require("./rollbackState");
|
|
15
16
|
async function getAvailableChannels() {
|
|
16
17
|
const { project } = context_1.config;
|
|
17
18
|
if (!project?.slug) {
|
|
@@ -38,12 +39,13 @@ async function checkForUpdate(channelName = context_2.defaultChannel, onStatusUp
|
|
|
38
39
|
throw new Error('Missing project slug in bundle.drop.config.js');
|
|
39
40
|
}
|
|
40
41
|
onStatusUpdate?.('🔍 Checking for updates...');
|
|
41
|
-
const [local, currentPtr, previousPtr, currentUserProperties, installId] = await Promise.all([
|
|
42
|
+
const [local, currentPtr, previousPtr, currentUserProperties, installId, rejectedHashes] = await Promise.all([
|
|
42
43
|
(0, bundleInfo_1.readBundleInfo)(),
|
|
43
44
|
(0, bundlePointer_1.readCurrentBundlePointer)(),
|
|
44
45
|
(0, bundlePointer_1.readPreviousBundlePointer)(),
|
|
45
46
|
(0, userProperties_1.getCurrentUserProperties)(),
|
|
46
47
|
(0, installId_1.getOrCreateInstallId)(),
|
|
48
|
+
(0, rollbackState_1.getFailedBundleHashes)(),
|
|
47
49
|
]);
|
|
48
50
|
const currentHash = currentPtr?.hash ?? local?.hash ?? null;
|
|
49
51
|
const previousHash = previousPtr?.hash ?? null;
|
|
@@ -56,6 +58,7 @@ async function checkForUpdate(channelName = context_2.defaultChannel, onStatusUp
|
|
|
56
58
|
currentHash,
|
|
57
59
|
currentUserProperties,
|
|
58
60
|
previousHash,
|
|
61
|
+
rejectedHashes,
|
|
59
62
|
currentBundleVersion: local?.bundleVersion ?? null,
|
|
60
63
|
installId,
|
|
61
64
|
});
|
|
@@ -83,6 +86,17 @@ async function checkForUpdate(channelName = context_2.defaultChannel, onStatusUp
|
|
|
83
86
|
return { action: 'ROLLBACK', channelName, reason: decision.reason };
|
|
84
87
|
}
|
|
85
88
|
// INSTALL
|
|
89
|
+
if (await (0, rollbackState_1.isBundleHashFailed)(decision.target.hash)) {
|
|
90
|
+
onStatusUpdate?.('✅ Current bundle retained; latest update previously failed on this device');
|
|
91
|
+
return {
|
|
92
|
+
action: 'NOOP',
|
|
93
|
+
upToDate: false,
|
|
94
|
+
channelName,
|
|
95
|
+
reason: 'BUNDLE_PREVIOUSLY_FAILED',
|
|
96
|
+
skippedFailedBundle: true,
|
|
97
|
+
skippedHash: decision.target.hash,
|
|
98
|
+
};
|
|
99
|
+
}
|
|
86
100
|
onStatusUpdate?.('⬇️ Update available');
|
|
87
101
|
return {
|
|
88
102
|
action: 'INSTALL',
|
|
@@ -7,6 +7,10 @@ export type ApplyUpdateResult = {
|
|
|
7
7
|
status: 'disabled';
|
|
8
8
|
} | {
|
|
9
9
|
status: 'alreadyApplied';
|
|
10
|
+
} | {
|
|
11
|
+
status: 'blocked';
|
|
12
|
+
reason: 'BUNDLE_PREVIOUSLY_FAILED';
|
|
13
|
+
skippedHash?: string;
|
|
10
14
|
};
|
|
11
15
|
export declare const getUpdateState: (cached?: {
|
|
12
16
|
bundleInfo?: BundleInfo | null;
|
|
@@ -20,4 +24,4 @@ export declare const reconcileAppliedBundleOnLaunch: (cached?: {
|
|
|
20
24
|
bundleInfo?: BundleInfo | null;
|
|
21
25
|
bundlePath?: string | null;
|
|
22
26
|
}) => Promise<void>;
|
|
23
|
-
export declare const applyUpdate: (onStatusUpdate?: (status: string) => void) => Promise<ApplyUpdateResult>;
|
|
27
|
+
export declare const applyUpdate: (onStatusUpdate?: (status: string) => void, onBeforeRestart?: () => void) => Promise<ApplyUpdateResult>;
|
|
@@ -5,6 +5,7 @@ const bundleDropNative_1 = require("../native/bundleDropNative");
|
|
|
5
5
|
const bundleInfo_1 = require("../bundleInfo");
|
|
6
6
|
const reporting_1 = require("./reporting");
|
|
7
7
|
const errors_1 = require("../errors");
|
|
8
|
+
const rollbackState_1 = require("./rollbackState");
|
|
8
9
|
const getUpdateState = async (cached) => {
|
|
9
10
|
const info = cached?.bundleInfo !== undefined ? cached.bundleInfo : await (0, bundleInfo_1.readBundleInfo)();
|
|
10
11
|
const path = cached?.bundlePath !== undefined ? cached.bundlePath : await (0, bundleDropNative_1.getDownloadedBundlePathNative)();
|
|
@@ -17,10 +18,12 @@ const getUpdateState = async (cached) => {
|
|
|
17
18
|
exports.getUpdateState = getUpdateState;
|
|
18
19
|
const reconcileAppliedBundleOnLaunch = async (cached) => {
|
|
19
20
|
const state = await (0, exports.getUpdateState)(cached);
|
|
20
|
-
if (!state.info?.pendingApply)
|
|
21
|
-
return;
|
|
22
21
|
if (!state.hasBundle)
|
|
23
22
|
return;
|
|
23
|
+
if (!state.info?.pendingApply) {
|
|
24
|
+
(0, reporting_1.reportInstalledIfReady)(state).catch(() => { });
|
|
25
|
+
return;
|
|
26
|
+
}
|
|
24
27
|
await (0, bundleInfo_1.updateBundleInfo)({ pendingApply: false, installedAt: new Date().toISOString() });
|
|
25
28
|
// Fire-and-forget: don't block the startup path for server reporting
|
|
26
29
|
(0, reporting_1.reportInstalledIfReady)({
|
|
@@ -29,7 +32,7 @@ const reconcileAppliedBundleOnLaunch = async (cached) => {
|
|
|
29
32
|
}).catch(() => { });
|
|
30
33
|
};
|
|
31
34
|
exports.reconcileAppliedBundleOnLaunch = reconcileAppliedBundleOnLaunch;
|
|
32
|
-
const applyUpdate = async (onStatusUpdate) => {
|
|
35
|
+
const applyUpdate = async (onStatusUpdate, onBeforeRestart) => {
|
|
33
36
|
try {
|
|
34
37
|
const path = await (0, bundleDropNative_1.getDownloadedBundlePathNative)();
|
|
35
38
|
const info = await (0, bundleInfo_1.readBundleInfo)();
|
|
@@ -41,18 +44,24 @@ const applyUpdate = async (onStatusUpdate) => {
|
|
|
41
44
|
onStatusUpdate?.('ℹ️ Bundle already applied');
|
|
42
45
|
return { status: 'alreadyApplied' };
|
|
43
46
|
}
|
|
47
|
+
if (await (0, rollbackState_1.isBundleHashFailed)(info?.hash)) {
|
|
48
|
+
onStatusUpdate?.('⚠️ Update previously failed on this device');
|
|
49
|
+
return {
|
|
50
|
+
status: 'blocked',
|
|
51
|
+
reason: 'BUNDLE_PREVIOUSLY_FAILED',
|
|
52
|
+
skippedHash: info?.hash,
|
|
53
|
+
};
|
|
54
|
+
}
|
|
44
55
|
onStatusUpdate?.('♻️ Applying downloaded bundle...');
|
|
45
56
|
await (0, bundleInfo_1.updateBundleInfo)({ pendingApply: false, installedAt: new Date().toISOString() });
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
});
|
|
51
|
-
}
|
|
52
|
-
catch (reportError) {
|
|
57
|
+
(0, reporting_1.reportInstalledIfReady)({
|
|
58
|
+
hasBundle: true,
|
|
59
|
+
info: info ? { ...info, pendingApply: false } : info,
|
|
60
|
+
}).catch(reportError => {
|
|
53
61
|
// Telemetry should not block applying the already-downloaded bundle.
|
|
54
62
|
console.warn('⚠️ Failed to report bundle install during apply:', reportError);
|
|
55
|
-
}
|
|
63
|
+
});
|
|
64
|
+
onBeforeRestart?.();
|
|
56
65
|
(0, bundleDropNative_1.restartReactNativeNative)();
|
|
57
66
|
return { status: 'applied' };
|
|
58
67
|
}
|
package/lib/runtime/service.d.ts
CHANGED
|
@@ -58,6 +58,10 @@ export declare function downloadAndStage(extraStatusHandler?: StatusHandler): Pr
|
|
|
58
58
|
* Apply a previously staged bundle immediately by restarting the React Native bridge.
|
|
59
59
|
*/
|
|
60
60
|
export declare function applyDownloadedUpdate(extraStatusHandler?: StatusHandler): Promise<ApplyAndRefreshResult>;
|
|
61
|
+
/**
|
|
62
|
+
* Mark the currently running OTA candidate healthy for this device.
|
|
63
|
+
*/
|
|
64
|
+
export declare function reportHealthy(): Promise<void>;
|
|
61
65
|
/**
|
|
62
66
|
* Fetch the list of public channel names available for the configured project.
|
|
63
67
|
*/
|
|
@@ -74,6 +78,30 @@ export declare function installBundleFromListItem(bundle: BundleListItem): Promi
|
|
|
74
78
|
* Read locally stored metadata for the currently downloaded or applied bundle.
|
|
75
79
|
*/
|
|
76
80
|
export declare function getInstalledBundleInfo(): Promise<BundleInfo | null>;
|
|
81
|
+
export type ObservabilityContext = {
|
|
82
|
+
source: 'embedded' | 'ota';
|
|
83
|
+
dist: string;
|
|
84
|
+
tags: {
|
|
85
|
+
bundle_drop_hash: string | null;
|
|
86
|
+
bundle_drop_channel: string | null;
|
|
87
|
+
bundle_drop_version: string | null;
|
|
88
|
+
bundle_drop_runtime_version: string | null;
|
|
89
|
+
bundle_drop_platform: string | null;
|
|
90
|
+
};
|
|
91
|
+
context: BundleInfo | null;
|
|
92
|
+
};
|
|
93
|
+
/**
|
|
94
|
+
* Pre-formatted context for error tracking integrations.
|
|
95
|
+
*
|
|
96
|
+
* Returns `dist`, `tags`, and `context` shaped for direct use with
|
|
97
|
+
* Sentry, Bugsnag, Datadog, or any provider. Handles the embedded
|
|
98
|
+
* fallback automatically: when no OTA bundle is active, `source`
|
|
99
|
+
* is `'embedded'` and `dist` is `'embedded'`.
|
|
100
|
+
*
|
|
101
|
+
* If the installed bundle has `pendingApply: true` it is not yet
|
|
102
|
+
* executing, so the context falls back to `'embedded'`.
|
|
103
|
+
*/
|
|
104
|
+
export declare function getObservabilityContext(): Promise<ObservabilityContext>;
|
|
77
105
|
/**
|
|
78
106
|
* Read the current local update state from disk.
|
|
79
107
|
*/
|
package/lib/runtime/service.js
CHANGED
|
@@ -9,10 +9,12 @@ exports.isUpdateFlowActive = isUpdateFlowActive;
|
|
|
9
9
|
exports.checkLatest = checkLatest;
|
|
10
10
|
exports.downloadAndStage = downloadAndStage;
|
|
11
11
|
exports.applyDownloadedUpdate = applyDownloadedUpdate;
|
|
12
|
+
exports.reportHealthy = reportHealthy;
|
|
12
13
|
exports.fetchAvailableChannels = fetchAvailableChannels;
|
|
13
14
|
exports.fetchAvailableBundles = fetchAvailableBundles;
|
|
14
15
|
exports.installBundleFromListItem = installBundleFromListItem;
|
|
15
16
|
exports.getInstalledBundleInfo = getInstalledBundleInfo;
|
|
17
|
+
exports.getObservabilityContext = getObservabilityContext;
|
|
16
18
|
exports.getRuntimeUpdateState = getRuntimeUpdateState;
|
|
17
19
|
exports.checkForUpdate = checkForUpdate;
|
|
18
20
|
exports.downloadUpdate = downloadUpdate;
|
|
@@ -36,6 +38,8 @@ const DEFAULT_STATUS = 'Click the button to check for updates';
|
|
|
36
38
|
const DISABLED_STATUS = 'BundleDrop is disabled';
|
|
37
39
|
let updateFlowActive = false;
|
|
38
40
|
let startupPromise = null;
|
|
41
|
+
let healthTimer = null;
|
|
42
|
+
let runtimeRestartRequested = false;
|
|
39
43
|
let snapshot = {
|
|
40
44
|
status: DISABLED_STATUS,
|
|
41
45
|
isBusy: false,
|
|
@@ -102,6 +106,9 @@ function isSameStatus(current, next) {
|
|
|
102
106
|
function getCheckStatus(response) {
|
|
103
107
|
if (!response)
|
|
104
108
|
return '⚠️ Unable to check for updates. Try again.';
|
|
109
|
+
if (response.skippedFailedBundle) {
|
|
110
|
+
return '✅ Current bundle retained; requested update previously failed on this device';
|
|
111
|
+
}
|
|
105
112
|
if (response.action === 'ROLLBACK') {
|
|
106
113
|
if (!response.reason) {
|
|
107
114
|
return '↩️ Rollback requested';
|
|
@@ -119,8 +126,11 @@ function getCheckStatus(response) {
|
|
|
119
126
|
: '⬇️ Update available';
|
|
120
127
|
}
|
|
121
128
|
function getDownloadStatus(result) {
|
|
122
|
-
if (result.status === 'upToDate')
|
|
123
|
-
return
|
|
129
|
+
if (result.status === 'upToDate') {
|
|
130
|
+
return result.skippedFailedBundle
|
|
131
|
+
? '✅ Current bundle retained; requested update previously failed on this device'
|
|
132
|
+
: '✅ You have the latest version';
|
|
133
|
+
}
|
|
124
134
|
if (result.status === 'rollback') {
|
|
125
135
|
if (!result.reason) {
|
|
126
136
|
return '↩️ Rollback requested';
|
|
@@ -136,7 +146,52 @@ function getApplyStatus(result) {
|
|
|
136
146
|
? '✅ Update applied, reloading...'
|
|
137
147
|
: result.status === 'noBundle'
|
|
138
148
|
? '⚠️ No downloaded bundle to apply'
|
|
139
|
-
:
|
|
149
|
+
: result.status === 'blocked'
|
|
150
|
+
? '⚠️ Update previously failed on this device'
|
|
151
|
+
: 'ℹ️ Bundle already applied';
|
|
152
|
+
}
|
|
153
|
+
function clearHealthTimer() {
|
|
154
|
+
if (!healthTimer)
|
|
155
|
+
return;
|
|
156
|
+
clearTimeout(healthTimer);
|
|
157
|
+
healthTimer = null;
|
|
158
|
+
}
|
|
159
|
+
function requestRuntimeRestart() {
|
|
160
|
+
runtimeRestartRequested = true;
|
|
161
|
+
(0, bundleDropNative_1.restartReactNativeNative)();
|
|
162
|
+
}
|
|
163
|
+
async function markActiveCandidateHealthy(expectedHash) {
|
|
164
|
+
if (runtimeRestartRequested) {
|
|
165
|
+
return false;
|
|
166
|
+
}
|
|
167
|
+
const state = await (0, updateState_1.getUpdateState)();
|
|
168
|
+
if (runtimeRestartRequested) {
|
|
169
|
+
return false;
|
|
170
|
+
}
|
|
171
|
+
if (state.pendingApply) {
|
|
172
|
+
return false;
|
|
173
|
+
}
|
|
174
|
+
const markedHealthy = await (0, rollbackState_1.reportActiveBundleHealthy)(undefined, expectedHash);
|
|
175
|
+
if (markedHealthy) {
|
|
176
|
+
await refreshState();
|
|
177
|
+
}
|
|
178
|
+
return markedHealthy;
|
|
179
|
+
}
|
|
180
|
+
function scheduleCandidateHealthMark(currentPointer, rollbackState) {
|
|
181
|
+
clearHealthTimer();
|
|
182
|
+
const hash = currentPointer?.hash;
|
|
183
|
+
const rollbackPolicy = (0, rollbackState_1.getRollbackPolicy)();
|
|
184
|
+
if (!hash || rollbackPolicy.healthCheckMode === 'manual')
|
|
185
|
+
return;
|
|
186
|
+
if (rollbackState?.candidateHash !== hash || rollbackState.candidateCommitted === true)
|
|
187
|
+
return;
|
|
188
|
+
const delayMs = Math.max(0, rollbackPolicy.healthyAfterSec || 0) * 1000;
|
|
189
|
+
healthTimer = setTimeout(() => {
|
|
190
|
+
healthTimer = null;
|
|
191
|
+
markActiveCandidateHealthy(hash).catch(error => {
|
|
192
|
+
console.warn('⚠️ Failed to mark BundleDrop candidate healthy:', error);
|
|
193
|
+
});
|
|
194
|
+
}, delayMs);
|
|
140
195
|
}
|
|
141
196
|
async function refreshState(cached) {
|
|
142
197
|
const state = await (0, updateState_1.getUpdateState)(cached);
|
|
@@ -184,16 +239,19 @@ async function runStartupFlow() {
|
|
|
184
239
|
rollbackState,
|
|
185
240
|
});
|
|
186
241
|
if (rollbackResult.rolledBack) {
|
|
242
|
+
clearHealthTimer();
|
|
187
243
|
emitStatus('↩️ Rolled back to previous bundle');
|
|
188
|
-
(
|
|
244
|
+
requestRuntimeRestart();
|
|
189
245
|
return;
|
|
190
246
|
}
|
|
191
|
-
await (0, rollbackState_1.
|
|
247
|
+
scheduleCandidateHealthMark(currentPointer, await (0, rollbackState_1.readRollbackState)());
|
|
192
248
|
const pendingState = await refreshState({ bundlePath });
|
|
193
249
|
if (pendingState.pendingApply) {
|
|
194
250
|
if (runtime.policy === 'immediate') {
|
|
195
251
|
emitStatus('♻️ Applying previously downloaded update...');
|
|
196
|
-
const applied = await (0, updateState_1.applyUpdate)(statusCb)
|
|
252
|
+
const applied = await (0, updateState_1.applyUpdate)(statusCb, () => {
|
|
253
|
+
runtimeRestartRequested = true;
|
|
254
|
+
});
|
|
197
255
|
if (applied.status === 'applied') {
|
|
198
256
|
return;
|
|
199
257
|
}
|
|
@@ -216,7 +274,7 @@ async function runStartupFlow() {
|
|
|
216
274
|
if (decision.action === 'ROLLBACK') {
|
|
217
275
|
emitStatus('↩️ Server requested rollback...');
|
|
218
276
|
await (0, rollbackState_1.rollbackToPreviousOrNative)();
|
|
219
|
-
(
|
|
277
|
+
requestRuntimeRestart();
|
|
220
278
|
return;
|
|
221
279
|
}
|
|
222
280
|
if (decision.action === 'NOOP' || runtime.policy === 'manual' || runtime.checkOnly) {
|
|
@@ -248,7 +306,9 @@ async function runStartupFlow() {
|
|
|
248
306
|
return;
|
|
249
307
|
}
|
|
250
308
|
if (downloadResult.status === 'staged') {
|
|
251
|
-
await (0, updateState_1.applyUpdate)(statusCb)
|
|
309
|
+
await (0, updateState_1.applyUpdate)(statusCb, () => {
|
|
310
|
+
runtimeRestartRequested = true;
|
|
311
|
+
});
|
|
252
312
|
return;
|
|
253
313
|
}
|
|
254
314
|
const nextStatus = getDownloadStatus(downloadResult);
|
|
@@ -276,6 +336,9 @@ function ensureStartupFlow() {
|
|
|
276
336
|
*/
|
|
277
337
|
function initBundleDrop(options) {
|
|
278
338
|
const { alreadyInitialized, config } = (0, initState_1.initializeBundleDropRuntime)(options);
|
|
339
|
+
if (!alreadyInitialized) {
|
|
340
|
+
runtimeRestartRequested = false;
|
|
341
|
+
}
|
|
279
342
|
patchSnapshot({
|
|
280
343
|
channelName: config.channelName,
|
|
281
344
|
isEnabled: config.enabled,
|
|
@@ -371,7 +434,9 @@ async function applyDownloadedUpdate(extraStatusHandler) {
|
|
|
371
434
|
}
|
|
372
435
|
await waitForStartupIfNeeded();
|
|
373
436
|
return withBusy(async () => {
|
|
374
|
-
const result = await (0, updateState_1.applyUpdate)(status => emitStatus(status, extraStatusHandler))
|
|
437
|
+
const result = await (0, updateState_1.applyUpdate)(status => emitStatus(status, extraStatusHandler), () => {
|
|
438
|
+
runtimeRestartRequested = true;
|
|
439
|
+
});
|
|
375
440
|
const status = getApplyStatus(result);
|
|
376
441
|
if (status) {
|
|
377
442
|
emitStatus(status, extraStatusHandler);
|
|
@@ -379,6 +444,21 @@ async function applyDownloadedUpdate(extraStatusHandler) {
|
|
|
379
444
|
return { result, status };
|
|
380
445
|
});
|
|
381
446
|
}
|
|
447
|
+
/**
|
|
448
|
+
* Mark the currently running OTA candidate healthy for this device.
|
|
449
|
+
*/
|
|
450
|
+
async function reportHealthy() {
|
|
451
|
+
const runtime = getEnabledRuntime();
|
|
452
|
+
if (!runtime) {
|
|
453
|
+
return;
|
|
454
|
+
}
|
|
455
|
+
await waitForStartupIfNeeded();
|
|
456
|
+
if (runtimeRestartRequested || updateFlowActive) {
|
|
457
|
+
return;
|
|
458
|
+
}
|
|
459
|
+
clearHealthTimer();
|
|
460
|
+
await markActiveCandidateHealthy();
|
|
461
|
+
}
|
|
382
462
|
/**
|
|
383
463
|
* Fetch the list of public channel names available for the configured project.
|
|
384
464
|
*/
|
|
@@ -439,7 +519,10 @@ async function installBundleFromListItem(bundle) {
|
|
|
439
519
|
emitStatus(status);
|
|
440
520
|
return { result, status };
|
|
441
521
|
}
|
|
442
|
-
|
|
522
|
+
const status = getDownloadStatus(result);
|
|
523
|
+
if (status)
|
|
524
|
+
emitStatus(status);
|
|
525
|
+
return { result, status };
|
|
443
526
|
});
|
|
444
527
|
}
|
|
445
528
|
/**
|
|
@@ -452,6 +535,46 @@ async function getInstalledBundleInfo() {
|
|
|
452
535
|
const state = await refreshState();
|
|
453
536
|
return state.info || null;
|
|
454
537
|
}
|
|
538
|
+
/**
|
|
539
|
+
* Pre-formatted context for error tracking integrations.
|
|
540
|
+
*
|
|
541
|
+
* Returns `dist`, `tags`, and `context` shaped for direct use with
|
|
542
|
+
* Sentry, Bugsnag, Datadog, or any provider. Handles the embedded
|
|
543
|
+
* fallback automatically: when no OTA bundle is active, `source`
|
|
544
|
+
* is `'embedded'` and `dist` is `'embedded'`.
|
|
545
|
+
*
|
|
546
|
+
* If the installed bundle has `pendingApply: true` it is not yet
|
|
547
|
+
* executing, so the context falls back to `'embedded'`.
|
|
548
|
+
*/
|
|
549
|
+
async function getObservabilityContext() {
|
|
550
|
+
const info = await getInstalledBundleInfo();
|
|
551
|
+
if (!info || info.pendingApply || !info.hash) {
|
|
552
|
+
return {
|
|
553
|
+
source: 'embedded',
|
|
554
|
+
dist: 'embedded',
|
|
555
|
+
tags: {
|
|
556
|
+
bundle_drop_hash: null,
|
|
557
|
+
bundle_drop_channel: null,
|
|
558
|
+
bundle_drop_version: null,
|
|
559
|
+
bundle_drop_runtime_version: null,
|
|
560
|
+
bundle_drop_platform: null,
|
|
561
|
+
},
|
|
562
|
+
context: null,
|
|
563
|
+
};
|
|
564
|
+
}
|
|
565
|
+
return {
|
|
566
|
+
source: 'ota',
|
|
567
|
+
dist: info.hash ?? 'embedded',
|
|
568
|
+
tags: {
|
|
569
|
+
bundle_drop_hash: info.hash ?? null,
|
|
570
|
+
bundle_drop_channel: info.channelName ?? null,
|
|
571
|
+
bundle_drop_version: info.bundleVersion != null ? `${info.bundleVersion}` : null,
|
|
572
|
+
bundle_drop_runtime_version: info.runtimeVersion ?? null,
|
|
573
|
+
bundle_drop_platform: info.platform ?? null,
|
|
574
|
+
},
|
|
575
|
+
context: info,
|
|
576
|
+
};
|
|
577
|
+
}
|
|
455
578
|
/**
|
|
456
579
|
* Read the current local update state from disk.
|
|
457
580
|
*/
|
|
@@ -520,6 +643,7 @@ async function installBundle(hash, downloadUrl, bundleVersion, version, runtimeV
|
|
|
520
643
|
});
|
|
521
644
|
}
|
|
522
645
|
function resetBundleDropRuntimeServiceForTests() {
|
|
646
|
+
clearHealthTimer();
|
|
523
647
|
updateFlowActive = false;
|
|
524
648
|
startupPromise = null;
|
|
525
649
|
snapshot = {
|
package/lib/scripts/bundle.d.ts
CHANGED
|
@@ -1,12 +1,15 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
|
-
|
|
2
|
+
import { findProjectRoot } from './projectRoot';
|
|
3
|
+
export { findProjectRoot };
|
|
3
4
|
export declare function runBundleScript(options?: {
|
|
4
5
|
platform?: string;
|
|
5
6
|
cwd?: string;
|
|
7
|
+
sourcemap?: boolean;
|
|
6
8
|
}): {
|
|
7
9
|
projectRoot: string;
|
|
8
10
|
outputDir: string;
|
|
9
11
|
bundlePath: string;
|
|
12
|
+
sourceMapPath: string;
|
|
10
13
|
metadataPath: string;
|
|
11
14
|
zipPath: string;
|
|
12
15
|
runtimeVersion: string;
|