@gfean/react-native-bundle-drop 0.1.48 → 0.1.85
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/CLIENT_README.md +254 -84
- package/README.md +145 -14
- package/android/src/main/java/com/bundledrop/BundleDropModule.kt +94 -21
- package/ios/BundleDropBridge.m +29 -1
- package/ios/BundleDropLocator.swift +0 -6
- package/ios/BundleDropModule.swift +132 -4
- package/lib/CLI/cli.js +48 -39
- package/lib/CLI/scripts/init-config.d.ts +1 -0
- package/lib/CLI/scripts/init-config.js +42 -2
- package/lib/CLI/scripts/init-native-config.js +428 -45
- package/lib/CLI/scripts/login-cli.js +6 -2
- package/lib/CLI/scripts/post-init.d.ts +1 -0
- package/lib/CLI/scripts/post-init.js +42 -0
- package/lib/CLI/scripts/upload-cli.d.ts +2 -0
- package/lib/CLI/scripts/upload-cli.js +11 -5
- package/lib/api/client.d.ts +1 -1
- package/lib/api/client.js +2 -2
- package/lib/api/clientApi.d.ts +3 -6
- package/lib/api/clientApi.js +7 -18
- package/lib/api/types.d.ts +33 -18
- package/lib/bundleInfo.js +5 -5
- package/lib/context.js +3 -3
- package/lib/errors.d.ts +2 -2
- package/lib/fs/bundlePointer.d.ts +14 -0
- package/lib/fs/bundlePointer.js +77 -0
- package/lib/fs/fsUtils.js +13 -13
- package/lib/fs/installId.d.ts +1 -0
- package/lib/fs/installId.js +29 -0
- package/lib/fs/userProperties.d.ts +6 -0
- package/lib/fs/userProperties.js +100 -0
- package/lib/index.d.ts +1 -1
- package/lib/index.js +8 -3
- package/lib/injectImageResolver.js +2 -2
- package/lib/install/installFromZip.js +9 -20
- package/lib/loadConfig.d.ts +5 -0
- package/lib/manager/downloadAndInstall.d.ts +10 -0
- package/lib/manager/downloadAndInstall.js +50 -42
- package/lib/manager/initUpdateManager.js +46 -10
- package/lib/manager/reporting.js +5 -3
- package/lib/manager/rollbackState.d.ts +30 -0
- package/lib/manager/rollbackState.js +186 -0
- package/lib/manager/updateCheck.js +57 -18
- package/lib/native/fs.d.ts +17 -0
- package/lib/native/fs.js +33 -0
- package/lib/scripts/download-bundle.js +19 -8
- package/lib/useBundleDrop.js +14 -2
- package/package.json +3 -4
- package/lib/api/utils.d.ts +0 -1
- package/lib/api/utils.js +0 -8
- package/lib/fs/iosPointer.d.ts +0 -1
- package/lib/fs/iosPointer.js +0 -20
|
@@ -4,67 +4,74 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
4
4
|
};
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
6
|
exports.downloadUpdate = void 0;
|
|
7
|
-
const
|
|
7
|
+
const axios_cjs_1 = __importDefault(require("axios/dist/browser/axios.cjs"));
|
|
8
8
|
const context_1 = require("../context");
|
|
9
9
|
const bundleInfo_1 = require("../bundleInfo");
|
|
10
|
-
const
|
|
10
|
+
const bundlePointer_1 = require("../fs/bundlePointer");
|
|
11
11
|
const installFromZip_1 = require("../install/installFromZip");
|
|
12
12
|
const updateCheck_1 = require("./updateCheck");
|
|
13
|
-
const clientApi_1 = require("../api/clientApi");
|
|
14
13
|
const errors_1 = require("../errors");
|
|
14
|
+
const rollbackState_1 = require("./rollbackState");
|
|
15
15
|
async function downloadAndStageUpdate(options, onStatusUpdate) {
|
|
16
|
-
const { project
|
|
16
|
+
const { project } = context_1.config;
|
|
17
17
|
const channelName = options?.channelName || 'General';
|
|
18
18
|
const platform = context_1.platform;
|
|
19
19
|
const statusCb = onStatusUpdate;
|
|
20
|
-
const
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
if (checkResult
|
|
33
|
-
|
|
34
|
-
|
|
20
|
+
const resolvedTarget = options?.resolvedTarget;
|
|
21
|
+
// Resolve target via /ota/resolve unless the caller already provided it.
|
|
22
|
+
const checkResult = resolvedTarget
|
|
23
|
+
? {
|
|
24
|
+
action: 'INSTALL',
|
|
25
|
+
hash: resolvedTarget.hash,
|
|
26
|
+
downloadUrl: resolvedTarget.downloadUrl,
|
|
27
|
+
bundleVersion: resolvedTarget.bundleVersion,
|
|
28
|
+
version: resolvedTarget.version,
|
|
29
|
+
runtimeVersion: resolvedTarget.runtimeVersion,
|
|
30
|
+
}
|
|
31
|
+
: await (0, updateCheck_1.checkForUpdate)(channelName, statusCb);
|
|
32
|
+
if (!checkResult) {
|
|
33
|
+
throw new errors_1.BundleDropError({
|
|
34
|
+
message: 'Failed to resolve update decision',
|
|
35
|
+
code: 'RESOLVE_FAILED',
|
|
36
|
+
step: 'resolve',
|
|
37
|
+
context: { channelName, platform, projectSlug: project.slug },
|
|
38
|
+
});
|
|
35
39
|
}
|
|
36
|
-
if (checkResult
|
|
40
|
+
if (checkResult.incompatible) {
|
|
37
41
|
statusCb?.('⛔️ No compatible update for this binary');
|
|
38
42
|
return { status: 'incompatible' };
|
|
39
43
|
}
|
|
40
|
-
|
|
44
|
+
if (checkResult.action === 'NOOP') {
|
|
45
|
+
statusCb?.('✅ You have the latest version');
|
|
46
|
+
return { status: 'upToDate' };
|
|
47
|
+
}
|
|
48
|
+
if (checkResult.action === 'ROLLBACK') {
|
|
49
|
+
statusCb?.('↩️ Rollback requested');
|
|
50
|
+
return { status: 'rollback', reason: checkResult.reason };
|
|
51
|
+
}
|
|
52
|
+
const serverHash = checkResult.hash;
|
|
53
|
+
const serverBundleVersion = checkResult.bundleVersion;
|
|
54
|
+
const serverVersion = checkResult.version;
|
|
55
|
+
const serverRuntimeVersion = checkResult.runtimeVersion;
|
|
56
|
+
const bundleZipUrl = checkResult.downloadUrl || null;
|
|
41
57
|
try {
|
|
42
|
-
// Resolve download URL if not provided by checkForUpdate.
|
|
43
|
-
if (!bundleZipUrl) {
|
|
44
|
-
const latestResponse = await (0, clientApi_1.getLatestBundleDownloadUrl)(latestBundleParams);
|
|
45
|
-
if (!latestResponse.data?.downloadUrl) {
|
|
46
|
-
throw new errors_1.BundleDropError({
|
|
47
|
-
message: 'Missing downloadUrl from latest bundle response',
|
|
48
|
-
code: 'DOWNLOAD_URL_MISSING',
|
|
49
|
-
step: 'resolveDownloadUrl',
|
|
50
|
-
context: {
|
|
51
|
-
channelName,
|
|
52
|
-
platform,
|
|
53
|
-
orgSlug: org.slug,
|
|
54
|
-
projectSlug: project.slug,
|
|
55
|
-
},
|
|
56
|
-
});
|
|
57
|
-
}
|
|
58
|
-
bundleZipUrl = latestResponse.data.downloadUrl;
|
|
59
|
-
}
|
|
60
58
|
if (!bundleZipUrl) {
|
|
61
|
-
throw new
|
|
59
|
+
throw new errors_1.BundleDropError({
|
|
60
|
+
message: 'Missing downloadUrl from ota resolve response',
|
|
61
|
+
code: 'DOWNLOAD_URL_MISSING',
|
|
62
|
+
step: 'resolve',
|
|
63
|
+
context: {
|
|
64
|
+
channelName,
|
|
65
|
+
platform,
|
|
66
|
+
projectSlug: project.slug,
|
|
67
|
+
},
|
|
68
|
+
});
|
|
62
69
|
}
|
|
63
70
|
// Fetch bundle zip from server.
|
|
64
71
|
statusCb?.('⬇️ Downloading full bundle ZIP!...');
|
|
65
72
|
let zipResponse;
|
|
66
73
|
try {
|
|
67
|
-
zipResponse = await
|
|
74
|
+
zipResponse = await axios_cjs_1.default.get(bundleZipUrl, {
|
|
68
75
|
responseType: 'arraybuffer',
|
|
69
76
|
});
|
|
70
77
|
}
|
|
@@ -120,7 +127,8 @@ async function downloadAndStageUpdate(options, onStatusUpdate) {
|
|
|
120
127
|
runtimeVersion: metadataFromZip.runtimeVersion ?? serverRuntimeVersion ?? context_1.runtimeVersion ?? undefined,
|
|
121
128
|
};
|
|
122
129
|
(0, bundleInfo_1.writeBundleInfo)(installedInfo);
|
|
123
|
-
await (0,
|
|
130
|
+
await (0, bundlePointer_1.setCurrentBundlePointer)(bundlePath, installedHash);
|
|
131
|
+
await (0, rollbackState_1.markCandidateActivated)(installedHash);
|
|
124
132
|
return { status: 'staged', bundlePath, hash: installedHash };
|
|
125
133
|
}
|
|
126
134
|
catch (err) {
|
|
@@ -4,12 +4,23 @@ exports.initUpdateManager = initUpdateManager;
|
|
|
4
4
|
const downloadAndInstall_1 = require("./downloadAndInstall");
|
|
5
5
|
const updateCheck_1 = require("./updateCheck");
|
|
6
6
|
const updateState_1 = require("./updateState");
|
|
7
|
+
const rollbackState_1 = require("./rollbackState");
|
|
8
|
+
const bundleDropNative_1 = require("../native/bundleDropNative");
|
|
7
9
|
async function initUpdateManager(opts) {
|
|
8
10
|
const policy = opts?.policy || 'manual';
|
|
9
11
|
const channelName = opts?.channelName || 'General';
|
|
10
12
|
const statusCb = opts?.onStatusUpdate;
|
|
11
13
|
// Reconcile pending state on launch (assume downloaded bundle is active if present).
|
|
12
14
|
await (0, updateState_1.reconcileAppliedBundleOnLaunch)();
|
|
15
|
+
const rollbackPolicy = (0, rollbackState_1.getRollbackPolicy)();
|
|
16
|
+
const rollbackResult = await (0, rollbackState_1.rollbackToPreviousIfNeeded)(rollbackPolicy);
|
|
17
|
+
if (rollbackResult.rolledBack) {
|
|
18
|
+
statusCb?.('↩️ Rolled back to previous bundle');
|
|
19
|
+
(0, bundleDropNative_1.restartReactNativeNative)();
|
|
20
|
+
return;
|
|
21
|
+
}
|
|
22
|
+
// If we got this far, JS booted successfully for the current bundle.
|
|
23
|
+
await (0, rollbackState_1.commitActiveBundle)();
|
|
13
24
|
const pendingState = await (0, updateState_1.getUpdateState)();
|
|
14
25
|
if (pendingState.pendingApply) {
|
|
15
26
|
if (policy === 'immediate') {
|
|
@@ -22,22 +33,47 @@ async function initUpdateManager(opts) {
|
|
|
22
33
|
return;
|
|
23
34
|
}
|
|
24
35
|
}
|
|
25
|
-
//
|
|
26
|
-
|
|
36
|
+
// Resolve server decision once (covers INSTALL, ROLLBACK, NOOP).
|
|
37
|
+
const decision = await (0, updateCheck_1.checkForUpdate)(channelName, statusCb);
|
|
38
|
+
if (!decision) {
|
|
39
|
+
statusCb?.('⚠️ Unable to check for updates. Try again.');
|
|
40
|
+
return;
|
|
41
|
+
}
|
|
42
|
+
if (decision.action === 'ROLLBACK') {
|
|
43
|
+
statusCb?.('↩️ Server requested rollback...');
|
|
44
|
+
await (0, rollbackState_1.rollbackToPreviousOrNative)();
|
|
45
|
+
(0, bundleDropNative_1.restartReactNativeNative)();
|
|
46
|
+
return;
|
|
47
|
+
}
|
|
48
|
+
if (decision.action === 'NOOP') {
|
|
49
|
+
if (decision.incompatible) {
|
|
50
|
+
statusCb?.('⛔️ No compatible update for this binary');
|
|
51
|
+
return;
|
|
52
|
+
}
|
|
53
|
+
if (opts?.checkOnly)
|
|
54
|
+
statusCb?.('✅ You have the latest version');
|
|
27
55
|
return;
|
|
28
56
|
}
|
|
57
|
+
// INSTALL available
|
|
29
58
|
if (policy === 'manual') {
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
59
|
+
// Check-only mode is already handled by checkForUpdate status updates; no auto download/apply.
|
|
60
|
+
return;
|
|
61
|
+
}
|
|
62
|
+
const resolvedTarget = decision.downloadUrl && decision.hash
|
|
63
|
+
? {
|
|
64
|
+
hash: decision.hash,
|
|
65
|
+
downloadUrl: decision.downloadUrl,
|
|
66
|
+
bundleVersion: decision.bundleVersion,
|
|
67
|
+
version: decision.version,
|
|
68
|
+
runtimeVersion: decision.runtimeVersion,
|
|
36
69
|
}
|
|
70
|
+
: undefined;
|
|
71
|
+
if (!resolvedTarget) {
|
|
72
|
+
statusCb?.('⚠️ Update available but missing download URL');
|
|
37
73
|
return;
|
|
38
74
|
}
|
|
39
75
|
if (policy === 'on-next-launch') {
|
|
40
|
-
const res = await (0, downloadAndInstall_1.downloadUpdate)({ channelName }, statusCb || (() => { }));
|
|
76
|
+
const res = await (0, downloadAndInstall_1.downloadUpdate)({ channelName, resolvedTarget }, statusCb || (() => { }));
|
|
41
77
|
if (res.status === 'staged')
|
|
42
78
|
statusCb?.('✅ Update downloaded for next launch');
|
|
43
79
|
if (res.status === 'upToDate')
|
|
@@ -47,7 +83,7 @@ async function initUpdateManager(opts) {
|
|
|
47
83
|
return;
|
|
48
84
|
}
|
|
49
85
|
// immediate
|
|
50
|
-
const res = await (0, downloadAndInstall_1.downloadUpdate)({ channelName }, statusCb || (() => { }));
|
|
86
|
+
const res = await (0, downloadAndInstall_1.downloadUpdate)({ channelName, resolvedTarget }, statusCb || (() => { }));
|
|
51
87
|
if (res.status === 'staged') {
|
|
52
88
|
await (0, updateState_1.applyUpdate)(statusCb);
|
|
53
89
|
return;
|
package/lib/manager/reporting.js
CHANGED
|
@@ -5,6 +5,7 @@ const context_1 = require("../context");
|
|
|
5
5
|
const bundleInfo_1 = require("../bundleInfo");
|
|
6
6
|
const clientApi_1 = require("../api/clientApi");
|
|
7
7
|
const bundleDropNative_1 = require("../native/bundleDropNative");
|
|
8
|
+
const installId_1 = require("../fs/installId");
|
|
8
9
|
async function getReportingState() {
|
|
9
10
|
const info = await (0, bundleInfo_1.readBundleInfo)();
|
|
10
11
|
const path = await (0, bundleDropNative_1.getDownloadedBundlePathNative)();
|
|
@@ -26,11 +27,12 @@ async function reportInstalledIfReady(state) {
|
|
|
26
27
|
if (info.lastInstalledReportedHash === info.hash)
|
|
27
28
|
return;
|
|
28
29
|
try {
|
|
29
|
-
await (0,
|
|
30
|
-
|
|
31
|
-
projectSlug: context_1.config.project.slug,
|
|
30
|
+
const installId = await (0, installId_1.getOrCreateInstallId)();
|
|
31
|
+
await (0, clientApi_1.reportInstalled)(context_1.config.project.slug, info.hash, {
|
|
32
32
|
channelName: info.channelName,
|
|
33
33
|
platform: info.platform,
|
|
34
|
+
installId,
|
|
35
|
+
runtimeVersion: info.runtimeVersion ?? context_1.runtimeVersion ?? null,
|
|
34
36
|
});
|
|
35
37
|
await (0, bundleInfo_1.updateBundleInfo)({ lastInstalledReportedHash: info.hash });
|
|
36
38
|
}
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
export type RollbackPolicy = {
|
|
2
|
+
maxCrashCount?: number;
|
|
3
|
+
crashWindowSec?: number;
|
|
4
|
+
commitTimeoutSec?: number;
|
|
5
|
+
};
|
|
6
|
+
export type RollbackState = {
|
|
7
|
+
activeHash?: string;
|
|
8
|
+
lastGoodHash?: string;
|
|
9
|
+
candidateHash?: string;
|
|
10
|
+
candidateActivatedAt?: number;
|
|
11
|
+
candidateCommitted?: boolean;
|
|
12
|
+
crashCount?: number;
|
|
13
|
+
crashWindowStartedAt?: number;
|
|
14
|
+
lastLaunchAt?: number;
|
|
15
|
+
};
|
|
16
|
+
export declare function markCandidateActivated(hash: string): Promise<void>;
|
|
17
|
+
export declare function commitActiveBundle(): Promise<void>;
|
|
18
|
+
export declare function evaluateRollbackOnLaunch(policy?: RollbackPolicy): Promise<{
|
|
19
|
+
shouldRollback: boolean;
|
|
20
|
+
reason?: 'crash_loop' | 'commit_timeout';
|
|
21
|
+
}>;
|
|
22
|
+
export declare function rollbackToPreviousIfNeeded(policy?: RollbackPolicy): Promise<{
|
|
23
|
+
rolledBack: boolean;
|
|
24
|
+
reason?: 'crash_loop' | 'commit_timeout';
|
|
25
|
+
}>;
|
|
26
|
+
export declare function getRollbackPolicy(): RollbackPolicy | undefined;
|
|
27
|
+
export declare function rollbackToPreviousOrNative(): Promise<{
|
|
28
|
+
rolledBack: boolean;
|
|
29
|
+
toNative?: boolean;
|
|
30
|
+
}>;
|
|
@@ -0,0 +1,186 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.markCandidateActivated = markCandidateActivated;
|
|
7
|
+
exports.commitActiveBundle = commitActiveBundle;
|
|
8
|
+
exports.evaluateRollbackOnLaunch = evaluateRollbackOnLaunch;
|
|
9
|
+
exports.rollbackToPreviousIfNeeded = rollbackToPreviousIfNeeded;
|
|
10
|
+
exports.getRollbackPolicy = getRollbackPolicy;
|
|
11
|
+
exports.rollbackToPreviousOrNative = rollbackToPreviousOrNative;
|
|
12
|
+
const fs_1 = __importDefault(require("../native/fs"));
|
|
13
|
+
const context_1 = require("../context");
|
|
14
|
+
const fsUtils_1 = require("../fs/fsUtils");
|
|
15
|
+
const bundlePointer_1 = require("../fs/bundlePointer");
|
|
16
|
+
const bundleInfo_1 = require("../bundleInfo");
|
|
17
|
+
const STATE_PATH = `${context_1.BUNDLE_DROP_ROOT}/state.json`;
|
|
18
|
+
const DEFAULT_POLICY = {
|
|
19
|
+
maxCrashCount: 2,
|
|
20
|
+
crashWindowSec: 300,
|
|
21
|
+
commitTimeoutSec: 300,
|
|
22
|
+
};
|
|
23
|
+
function nowSec() {
|
|
24
|
+
return Math.floor(Date.now() / 1000);
|
|
25
|
+
}
|
|
26
|
+
function normalizePolicy(policy) {
|
|
27
|
+
return {
|
|
28
|
+
maxCrashCount: policy?.maxCrashCount ?? DEFAULT_POLICY.maxCrashCount,
|
|
29
|
+
crashWindowSec: policy?.crashWindowSec ?? DEFAULT_POLICY.crashWindowSec,
|
|
30
|
+
commitTimeoutSec: policy?.commitTimeoutSec ?? DEFAULT_POLICY.commitTimeoutSec,
|
|
31
|
+
};
|
|
32
|
+
}
|
|
33
|
+
async function readState() {
|
|
34
|
+
try {
|
|
35
|
+
if (!(await fs_1.default.exists(STATE_PATH)))
|
|
36
|
+
return null;
|
|
37
|
+
const raw = await fs_1.default.readFile(STATE_PATH, 'utf8');
|
|
38
|
+
return JSON.parse(raw);
|
|
39
|
+
}
|
|
40
|
+
catch {
|
|
41
|
+
return null;
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
async function writeState(state) {
|
|
45
|
+
await (0, fsUtils_1.ensureDir)(context_1.BUNDLE_DROP_ROOT);
|
|
46
|
+
await (0, fsUtils_1.atomicWriteJson)(STATE_PATH, state);
|
|
47
|
+
}
|
|
48
|
+
async function updateState(partial) {
|
|
49
|
+
const existing = (await readState()) || {};
|
|
50
|
+
const next = { ...existing, ...partial };
|
|
51
|
+
await writeState(next);
|
|
52
|
+
return next;
|
|
53
|
+
}
|
|
54
|
+
async function markCandidateActivated(hash) {
|
|
55
|
+
const previous = await (0, bundlePointer_1.readPreviousBundlePointer)();
|
|
56
|
+
const previousHash = previous?.hash;
|
|
57
|
+
const now = nowSec();
|
|
58
|
+
await updateState({
|
|
59
|
+
activeHash: hash,
|
|
60
|
+
candidateHash: hash,
|
|
61
|
+
candidateActivatedAt: now,
|
|
62
|
+
candidateCommitted: false,
|
|
63
|
+
crashCount: 0,
|
|
64
|
+
crashWindowStartedAt: now,
|
|
65
|
+
lastLaunchAt: now,
|
|
66
|
+
lastGoodHash: previousHash ?? undefined,
|
|
67
|
+
});
|
|
68
|
+
}
|
|
69
|
+
async function commitActiveBundle() {
|
|
70
|
+
const current = await (0, bundlePointer_1.readCurrentBundlePointer)();
|
|
71
|
+
const hash = current?.hash;
|
|
72
|
+
if (!hash)
|
|
73
|
+
return;
|
|
74
|
+
await updateState({
|
|
75
|
+
activeHash: hash,
|
|
76
|
+
candidateHash: hash,
|
|
77
|
+
candidateCommitted: true,
|
|
78
|
+
crashCount: 0,
|
|
79
|
+
crashWindowStartedAt: nowSec(),
|
|
80
|
+
lastGoodHash: hash,
|
|
81
|
+
});
|
|
82
|
+
}
|
|
83
|
+
async function evaluateRollbackOnLaunch(policy) {
|
|
84
|
+
const current = await (0, bundlePointer_1.readCurrentBundlePointer)();
|
|
85
|
+
const activeHash = current?.hash;
|
|
86
|
+
if (!activeHash)
|
|
87
|
+
return { shouldRollback: false };
|
|
88
|
+
const now = nowSec();
|
|
89
|
+
const state = (await readState()) || {};
|
|
90
|
+
const normalized = normalizePolicy(policy);
|
|
91
|
+
const next = {
|
|
92
|
+
...state,
|
|
93
|
+
activeHash,
|
|
94
|
+
lastLaunchAt: now,
|
|
95
|
+
};
|
|
96
|
+
const isCandidate = state.candidateHash === activeHash && state.candidateCommitted !== true;
|
|
97
|
+
if (isCandidate) {
|
|
98
|
+
const windowStart = state.crashWindowStartedAt ?? now;
|
|
99
|
+
const inWindow = now - windowStart <= normalized.crashWindowSec;
|
|
100
|
+
const crashCount = inWindow ? (state.crashCount ?? 0) + 1 : 1;
|
|
101
|
+
next.crashCount = crashCount;
|
|
102
|
+
next.crashWindowStartedAt = inWindow ? windowStart : now;
|
|
103
|
+
if (normalized.maxCrashCount > 0 &&
|
|
104
|
+
crashCount >= normalized.maxCrashCount) {
|
|
105
|
+
await writeState(next);
|
|
106
|
+
return { shouldRollback: true, reason: 'crash_loop' };
|
|
107
|
+
}
|
|
108
|
+
if (normalized.commitTimeoutSec > 0 &&
|
|
109
|
+
state.candidateActivatedAt &&
|
|
110
|
+
now - state.candidateActivatedAt > normalized.commitTimeoutSec) {
|
|
111
|
+
await writeState(next);
|
|
112
|
+
return { shouldRollback: true, reason: 'commit_timeout' };
|
|
113
|
+
}
|
|
114
|
+
}
|
|
115
|
+
await writeState(next);
|
|
116
|
+
return { shouldRollback: false };
|
|
117
|
+
}
|
|
118
|
+
async function rollbackToPreviousIfNeeded(policy) {
|
|
119
|
+
const decision = await evaluateRollbackOnLaunch(policy);
|
|
120
|
+
if (!decision.shouldRollback)
|
|
121
|
+
return { rolledBack: false };
|
|
122
|
+
const res = await rollbackToPreviousOrNative();
|
|
123
|
+
return res.rolledBack ? { rolledBack: true, reason: decision.reason } : { rolledBack: false };
|
|
124
|
+
}
|
|
125
|
+
function getRollbackPolicy() {
|
|
126
|
+
return context_1.config.rollback;
|
|
127
|
+
}
|
|
128
|
+
async function rollbackToPreviousOrNative() {
|
|
129
|
+
const previous = await (0, bundlePointer_1.rollbackToPreviousPointer)();
|
|
130
|
+
if (previous) {
|
|
131
|
+
const metadata = await readBundleMetadata(previous.bundlePath);
|
|
132
|
+
await (0, bundleInfo_1.updateBundleInfo)({
|
|
133
|
+
hash: previous.hash,
|
|
134
|
+
bundleVersion: metadata?.bundleVersion,
|
|
135
|
+
version: metadata?.version,
|
|
136
|
+
runtimeVersion: metadata?.runtimeVersion,
|
|
137
|
+
pendingApply: false,
|
|
138
|
+
installedAt: new Date().toISOString(),
|
|
139
|
+
});
|
|
140
|
+
await updateState({
|
|
141
|
+
activeHash: previous.hash,
|
|
142
|
+
candidateHash: previous.hash,
|
|
143
|
+
candidateCommitted: true,
|
|
144
|
+
crashCount: 0,
|
|
145
|
+
crashWindowStartedAt: nowSec(),
|
|
146
|
+
});
|
|
147
|
+
return { rolledBack: true };
|
|
148
|
+
}
|
|
149
|
+
// No previous OTA bundle exists; fall back to native bundle by clearing the active pointer.
|
|
150
|
+
await (0, bundlePointer_1.clearCurrentBundlePointer)();
|
|
151
|
+
await (0, bundleInfo_1.updateBundleInfo)({
|
|
152
|
+
hash: undefined,
|
|
153
|
+
bundleVersion: undefined,
|
|
154
|
+
version: undefined,
|
|
155
|
+
runtimeVersion: undefined,
|
|
156
|
+
pendingApply: false,
|
|
157
|
+
installedAt: new Date().toISOString(),
|
|
158
|
+
});
|
|
159
|
+
await updateState({
|
|
160
|
+
activeHash: undefined,
|
|
161
|
+
candidateHash: undefined,
|
|
162
|
+
candidateCommitted: true,
|
|
163
|
+
crashCount: 0,
|
|
164
|
+
crashWindowStartedAt: nowSec(),
|
|
165
|
+
});
|
|
166
|
+
return { rolledBack: true, toNative: true };
|
|
167
|
+
}
|
|
168
|
+
async function readBundleMetadata(bundlePath) {
|
|
169
|
+
try {
|
|
170
|
+
const dir = bundlePath.substring(0, bundlePath.lastIndexOf('/'));
|
|
171
|
+
const metadataFile = context_1.platform === 'android' ? 'metadata-android.json' : 'metadata-ios.json';
|
|
172
|
+
const filePath = `${dir}/${metadataFile}`;
|
|
173
|
+
if (!(await fs_1.default.exists(filePath)))
|
|
174
|
+
return null;
|
|
175
|
+
const raw = await fs_1.default.readFile(filePath, 'utf8');
|
|
176
|
+
const parsed = JSON.parse(raw);
|
|
177
|
+
return {
|
|
178
|
+
bundleVersion: parsed?.bundleVersion,
|
|
179
|
+
version: parsed?.version,
|
|
180
|
+
runtimeVersion: parsed?.runtimeVersion,
|
|
181
|
+
};
|
|
182
|
+
}
|
|
183
|
+
catch {
|
|
184
|
+
return null;
|
|
185
|
+
}
|
|
186
|
+
}
|
|
@@ -6,15 +6,17 @@ exports.getInstalledBundleInfo = getInstalledBundleInfo;
|
|
|
6
6
|
const context_1 = require("../context");
|
|
7
7
|
const bundleInfo_1 = require("../bundleInfo");
|
|
8
8
|
const clientApi_1 = require("../api/clientApi");
|
|
9
|
+
const bundlePointer_1 = require("../fs/bundlePointer");
|
|
10
|
+
const installId_1 = require("../fs/installId");
|
|
11
|
+
const userProperties_1 = require("../fs/userProperties");
|
|
9
12
|
async function getAvailableChannels() {
|
|
10
|
-
const { project
|
|
11
|
-
if (!project?.slug
|
|
12
|
-
throw new Error('Missing project
|
|
13
|
+
const { project } = context_1.config;
|
|
14
|
+
if (!project?.slug) {
|
|
15
|
+
throw new Error('Missing project slug in bundle.drop.config.js');
|
|
13
16
|
}
|
|
14
17
|
try {
|
|
15
18
|
const res = await (0, clientApi_1.getPublicChannels)({
|
|
16
19
|
projectSlug: project.slug,
|
|
17
|
-
orgSlug: org.slug,
|
|
18
20
|
});
|
|
19
21
|
if (!Array.isArray(res.data)) {
|
|
20
22
|
throw new Error('Invalid channel list response');
|
|
@@ -27,29 +29,66 @@ async function getAvailableChannels() {
|
|
|
27
29
|
}
|
|
28
30
|
}
|
|
29
31
|
async function checkForUpdate(channelName = 'General', onStatusUpdate) {
|
|
30
|
-
const { project
|
|
32
|
+
const { project } = context_1.config;
|
|
31
33
|
const local = await (0, bundleInfo_1.readBundleInfo)();
|
|
32
34
|
try {
|
|
33
35
|
onStatusUpdate?.('🔍 Checking for updates...');
|
|
34
|
-
const
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
36
|
+
const [currentPtr, previousPtr, currentUserProperties] = await Promise.all([
|
|
37
|
+
(0, bundlePointer_1.readCurrentBundlePointer)(),
|
|
38
|
+
(0, bundlePointer_1.readPreviousBundlePointer)(),
|
|
39
|
+
(0, userProperties_1.getCurrentUserProperties)(),
|
|
40
|
+
]);
|
|
41
|
+
const currentHash = currentPtr?.hash ?? local?.hash ?? null;
|
|
42
|
+
const previousHash = previousPtr?.hash ?? null;
|
|
43
|
+
const installId = await (0, installId_1.getOrCreateInstallId)();
|
|
44
|
+
const res = await (0, clientApi_1.postOtaResolve)(project.slug, {
|
|
38
45
|
channelName,
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
46
|
+
platform: context_1.platform,
|
|
47
|
+
runtimeVersion: context_1.runtimeVersion ?? null,
|
|
48
|
+
currentHash,
|
|
49
|
+
currentUserProperties,
|
|
50
|
+
previousHash,
|
|
51
|
+
currentBundleVersion: local?.bundleVersion ?? null,
|
|
52
|
+
installId,
|
|
42
53
|
});
|
|
43
|
-
|
|
44
|
-
|
|
54
|
+
const decision = res.data;
|
|
55
|
+
if (decision.action === 'NOOP') {
|
|
56
|
+
const incompatible = decision.reason === 'NO_COMPATIBLE_BUNDLE';
|
|
57
|
+
if (incompatible) {
|
|
58
|
+
onStatusUpdate?.('⛔️ No compatible update for this binary');
|
|
59
|
+
}
|
|
60
|
+
else {
|
|
61
|
+
onStatusUpdate?.('✅ You have the latest version');
|
|
62
|
+
}
|
|
63
|
+
return {
|
|
64
|
+
action: 'NOOP',
|
|
65
|
+
upToDate: !incompatible,
|
|
66
|
+
channelName,
|
|
67
|
+
reason: decision.reason,
|
|
68
|
+
incompatible: incompatible || undefined,
|
|
69
|
+
requestedRuntimeVersion: decision.requestedRuntimeVersion,
|
|
70
|
+
latestRuntimeVersionOnChannel: decision.latestRuntimeVersionOnChannel,
|
|
71
|
+
};
|
|
45
72
|
}
|
|
46
|
-
if (
|
|
47
|
-
onStatusUpdate?.('
|
|
73
|
+
if (decision.action === 'ROLLBACK') {
|
|
74
|
+
onStatusUpdate?.('↩️ Rollback requested');
|
|
75
|
+
return { action: 'ROLLBACK', channelName, reason: decision.reason };
|
|
48
76
|
}
|
|
49
|
-
|
|
77
|
+
// INSTALL
|
|
78
|
+
onStatusUpdate?.('⬇️ Update available');
|
|
79
|
+
return {
|
|
80
|
+
action: 'INSTALL',
|
|
81
|
+
upToDate: false,
|
|
82
|
+
channelName,
|
|
83
|
+
hash: decision.target.hash,
|
|
84
|
+
downloadUrl: decision.target.downloadUrl,
|
|
85
|
+
bundleVersion: decision.target.bundleVersion,
|
|
86
|
+
version: decision.target.version,
|
|
87
|
+
runtimeVersion: decision.target.runtimeVersion ?? context_1.runtimeVersion ?? undefined,
|
|
88
|
+
};
|
|
50
89
|
}
|
|
51
90
|
catch (e) {
|
|
52
|
-
console.warn('⚠️ checkForUpdate failed
|
|
91
|
+
console.warn('⚠️ checkForUpdate failed:', e?.toString?.() || e);
|
|
53
92
|
return null;
|
|
54
93
|
}
|
|
55
94
|
}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
declare function exists(path: string): Promise<boolean>;
|
|
2
|
+
declare function readFile(path: string, encoding?: 'utf8' | 'base64'): Promise<string>;
|
|
3
|
+
declare function writeFile(path: string, content: string, encoding?: 'utf8' | 'base64'): Promise<void>;
|
|
4
|
+
declare function mkdir(path: string): Promise<void>;
|
|
5
|
+
declare function unlink(path: string): Promise<void>;
|
|
6
|
+
declare function moveFile(src: string, dest: string): Promise<void>;
|
|
7
|
+
declare const BundleDropFS: {
|
|
8
|
+
DocumentDirectoryPath: string;
|
|
9
|
+
LibraryDirectoryPath: string;
|
|
10
|
+
exists: typeof exists;
|
|
11
|
+
readFile: typeof readFile;
|
|
12
|
+
writeFile: typeof writeFile;
|
|
13
|
+
mkdir: typeof mkdir;
|
|
14
|
+
unlink: typeof unlink;
|
|
15
|
+
moveFile: typeof moveFile;
|
|
16
|
+
};
|
|
17
|
+
export default BundleDropFS;
|
package/lib/native/fs.js
ADDED
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const react_native_1 = require("react-native");
|
|
4
|
+
const { BundleDrop } = react_native_1.NativeModules;
|
|
5
|
+
async function exists(path) {
|
|
6
|
+
return BundleDrop.fsExists(path);
|
|
7
|
+
}
|
|
8
|
+
async function readFile(path, encoding = 'utf8') {
|
|
9
|
+
return BundleDrop.fsReadFile(path, encoding);
|
|
10
|
+
}
|
|
11
|
+
async function writeFile(path, content, encoding = 'utf8') {
|
|
12
|
+
return BundleDrop.fsWriteFile(path, content, encoding);
|
|
13
|
+
}
|
|
14
|
+
async function mkdir(path) {
|
|
15
|
+
return BundleDrop.fsMkdir(path);
|
|
16
|
+
}
|
|
17
|
+
async function unlink(path) {
|
|
18
|
+
return BundleDrop.fsUnlink(path);
|
|
19
|
+
}
|
|
20
|
+
async function moveFile(src, dest) {
|
|
21
|
+
return BundleDrop.fsMoveFile(src, dest);
|
|
22
|
+
}
|
|
23
|
+
const BundleDropFS = {
|
|
24
|
+
DocumentDirectoryPath: (BundleDrop?.DocumentDirectoryPath ?? ''),
|
|
25
|
+
LibraryDirectoryPath: (BundleDrop?.LibraryDirectoryPath ?? ''),
|
|
26
|
+
exists,
|
|
27
|
+
readFile,
|
|
28
|
+
writeFile,
|
|
29
|
+
mkdir,
|
|
30
|
+
unlink,
|
|
31
|
+
moveFile,
|
|
32
|
+
};
|
|
33
|
+
exports.default = BundleDropFS;
|
|
@@ -56,12 +56,14 @@ if (!fs.existsSync(configPath)) {
|
|
|
56
56
|
}
|
|
57
57
|
// eslint-disable-next-line
|
|
58
58
|
const config = require(configPath);
|
|
59
|
-
const { serverUrl, project
|
|
60
|
-
if (!
|
|
61
|
-
console.error('❌ Missing "
|
|
59
|
+
const { serverUrl, project } = config;
|
|
60
|
+
if (!project?.slug) {
|
|
61
|
+
console.error('❌ Missing "project.slug" in bundle.drop.config.js');
|
|
62
62
|
process.exit(1);
|
|
63
63
|
}
|
|
64
|
-
const
|
|
64
|
+
const runtimeVersion = config?.runtimeVersion?.[platform] || config?.runtimeVersion?.[platform];
|
|
65
|
+
const channelName = process.argv[3] || 'General';
|
|
66
|
+
const resolveEndpoint = `${serverUrl}/projects/${encodeURIComponent(project.slug)}/ota/resolve`;
|
|
65
67
|
const outputPath = path.join(outputDir, `main.${platform}.jsbundle`);
|
|
66
68
|
if (!fs.existsSync(outputDir)) {
|
|
67
69
|
fs.mkdirSync(outputDir, { recursive: true });
|
|
@@ -71,16 +73,25 @@ const authHeaders = {
|
|
|
71
73
|
};
|
|
72
74
|
async function downloadLatestBundle() {
|
|
73
75
|
try {
|
|
74
|
-
console.log(`⬇️
|
|
75
|
-
const
|
|
76
|
+
console.log(`⬇️ Resolving OTA target from: ${resolveEndpoint}`);
|
|
77
|
+
const resolveResponse = await axios_1.default.post(resolveEndpoint, {
|
|
78
|
+
channelName,
|
|
79
|
+
platform,
|
|
80
|
+
runtimeVersion: runtimeVersion ?? null,
|
|
81
|
+
currentHash: null,
|
|
82
|
+
previousHash: null,
|
|
83
|
+
currentBundleVersion: null,
|
|
84
|
+
}, {
|
|
76
85
|
headers: {
|
|
77
86
|
Accept: 'application/json',
|
|
78
87
|
...authHeaders,
|
|
79
88
|
},
|
|
89
|
+
timeout: 15000,
|
|
80
90
|
});
|
|
81
|
-
const
|
|
91
|
+
const decision = resolveResponse.data;
|
|
92
|
+
const bundleDownloadUrl = decision?.action === 'INSTALL' ? decision?.target?.downloadUrl : null;
|
|
82
93
|
if (!bundleDownloadUrl) {
|
|
83
|
-
console.error('❌
|
|
94
|
+
console.error('❌ Resolve did not return an INSTALL decision with a downloadUrl');
|
|
84
95
|
process.exit(1);
|
|
85
96
|
}
|
|
86
97
|
console.log(`⬇️ Downloading latest ${platform} bundle from signed URL...`);
|