@gfean/react-native-bundle-drop 0.1.48 → 0.1.82

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (44) hide show
  1. package/CLIENT_README.md +254 -84
  2. package/README.md +145 -14
  3. package/android/src/main/java/com/bundledrop/BundleDropModule.kt +9 -22
  4. package/ios/BundleDropLocator.swift +0 -6
  5. package/lib/CLI/cli.js +48 -39
  6. package/lib/CLI/scripts/init-config.d.ts +1 -0
  7. package/lib/CLI/scripts/init-config.js +42 -2
  8. package/lib/CLI/scripts/init-native-config.js +428 -45
  9. package/lib/CLI/scripts/login-cli.js +6 -2
  10. package/lib/CLI/scripts/post-init.d.ts +1 -0
  11. package/lib/CLI/scripts/post-init.js +42 -0
  12. package/lib/CLI/scripts/upload-cli.d.ts +2 -0
  13. package/lib/CLI/scripts/upload-cli.js +11 -5
  14. package/lib/api/client.d.ts +1 -1
  15. package/lib/api/client.js +2 -2
  16. package/lib/api/clientApi.d.ts +3 -6
  17. package/lib/api/clientApi.js +7 -18
  18. package/lib/api/types.d.ts +33 -18
  19. package/lib/context.js +1 -1
  20. package/lib/errors.d.ts +2 -2
  21. package/lib/fs/bundlePointer.d.ts +14 -0
  22. package/lib/fs/bundlePointer.js +77 -0
  23. package/lib/fs/installId.d.ts +1 -0
  24. package/lib/fs/installId.js +29 -0
  25. package/lib/fs/userProperties.d.ts +6 -0
  26. package/lib/fs/userProperties.js +100 -0
  27. package/lib/index.d.ts +1 -1
  28. package/lib/index.js +8 -3
  29. package/lib/install/installFromZip.js +7 -18
  30. package/lib/loadConfig.d.ts +5 -0
  31. package/lib/manager/downloadAndInstall.d.ts +10 -0
  32. package/lib/manager/downloadAndInstall.js +50 -42
  33. package/lib/manager/initUpdateManager.js +46 -10
  34. package/lib/manager/reporting.js +5 -3
  35. package/lib/manager/rollbackState.d.ts +30 -0
  36. package/lib/manager/rollbackState.js +186 -0
  37. package/lib/manager/updateCheck.js +57 -18
  38. package/lib/scripts/download-bundle.js +19 -8
  39. package/lib/useBundleDrop.js +14 -2
  40. package/package.json +3 -3
  41. package/lib/api/utils.d.ts +0 -1
  42. package/lib/api/utils.js +0 -8
  43. package/lib/fs/iosPointer.d.ts +0 -1
  44. package/lib/fs/iosPointer.js +0 -20
@@ -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
- // Manual policy: optionally just check and return.
26
- if (policy === 'manual' && !opts?.checkOnly) {
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
- if (opts?.checkOnly) {
31
- const check = await (0, updateCheck_1.checkForUpdate)(channelName, statusCb);
32
- if (check?.upToDate)
33
- statusCb?.('✅ You have the latest version');
34
- if (check?.incompatible)
35
- statusCb?.('⛔️ No compatible update for this binary');
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;
@@ -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, clientApi_1.reportInstalled)(info.hash, {
30
- orgSlug: context_1.config.org.slug,
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 react_native_fs_1 = __importDefault(require("react-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 react_native_fs_1.default.exists(STATE_PATH)))
36
+ return null;
37
+ const raw = await react_native_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 react_native_fs_1.default.exists(filePath)))
174
+ return null;
175
+ const raw = await react_native_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, org } = context_1.config;
11
- if (!project?.slug || !org?.slug) {
12
- throw new Error('Missing project/org slug in bundle.drop.config.js');
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, org } = context_1.config;
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 res = await (0, clientApi_1.getUpdateCheck)({
35
- platform: context_1.platform,
36
- orgSlug: org.slug,
37
- project: project.slug,
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
- currentBundleVersion: local?.bundleVersion,
40
- currentHash: local?.hash,
41
- runtimeVersion: context_1.runtimeVersion,
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
- if (res.data.upToDate) {
44
- onStatusUpdate?.(`You've got the latest version for the given channel ${res.data.channelName ?? ''}`);
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 (res.data.incompatible) {
47
- onStatusUpdate?.('⛔️ No compatible update for this binary');
73
+ if (decision.action === 'ROLLBACK') {
74
+ onStatusUpdate?.('↩️ Rollback requested');
75
+ return { action: 'ROLLBACK', channelName, reason: decision.reason };
48
76
  }
49
- return res.data;
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, will fallback to download:', e?.toString?.() || e);
91
+ console.warn('⚠️ checkForUpdate failed:', e?.toString?.() || e);
53
92
  return null;
54
93
  }
55
94
  }
@@ -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, org } = config;
60
- if (!org?.slug) {
61
- console.error('❌ Missing "org.slug" in bundle.drop.config.js');
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 latestEndpoint = `${serverUrl}/bundle/latest?platform=${platform}&orgSlug=${org.slug}&project=${project.slug}`;
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(`⬇️ Fetching bundle download URL from: ${latestEndpoint}`);
75
- const latestResponse = await axios_1.default.get(latestEndpoint, {
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 bundleDownloadUrl = latestResponse.data?.downloadUrl;
91
+ const decision = resolveResponse.data;
92
+ const bundleDownloadUrl = decision?.action === 'INSTALL' ? decision?.target?.downloadUrl : null;
82
93
  if (!bundleDownloadUrl) {
83
- console.error('❌ Missing downloadUrl in latest bundle response');
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...`);
@@ -5,6 +5,7 @@ const react_1 = require("react");
5
5
  const updateCheck_1 = require("./manager/updateCheck");
6
6
  const downloadAndInstall_1 = require("./manager/downloadAndInstall");
7
7
  const updateState_1 = require("./manager/updateState");
8
+ const rollbackState_1 = require("./manager/rollbackState");
8
9
  function useBundleDrop(options) {
9
10
  const channelName = options?.channelName || 'General';
10
11
  const [status, setStatus] = (0, react_1.useState)('Click the button to check for updates');
@@ -38,8 +39,8 @@ function useBundleDrop(options) {
38
39
  setStatus(nextStatus);
39
40
  return { response: null, status: nextStatus };
40
41
  }
41
- if (res.upToDate) {
42
- const nextStatus = '✅ You have the latest version';
42
+ if (res.action === 'ROLLBACK') {
43
+ const nextStatus = res.reason ? `↩️ Rollback requested: ${res.reason}` : '↩️ Rollback requested';
43
44
  setStatus(nextStatus);
44
45
  return { response: res, status: nextStatus };
45
46
  }
@@ -48,6 +49,11 @@ function useBundleDrop(options) {
48
49
  setStatus(nextStatus);
49
50
  return { response: res, status: nextStatus };
50
51
  }
52
+ if (res.action === 'NOOP') {
53
+ const nextStatus = '✅ You have the latest version';
54
+ setStatus(nextStatus);
55
+ return { response: res, status: nextStatus };
56
+ }
51
57
  const nextLabel = res.bundleVersion
52
58
  ? `⬇️ Update available${res.bundleVersion ? ` (v${res.bundleVersion})` : ''}`
53
59
  : '⬇️ Update available';
@@ -63,6 +69,11 @@ function useBundleDrop(options) {
63
69
  setStatus(nextStatus);
64
70
  return { result, status: nextStatus };
65
71
  }
72
+ if (result.status === 'rollback') {
73
+ const nextStatus = result.reason ? `↩️ Rollback requested: ${result.reason}` : '↩️ Rollback requested';
74
+ setStatus(nextStatus);
75
+ return { result, status: nextStatus };
76
+ }
66
77
  if (result.status === 'incompatible') {
67
78
  const nextStatus = '⛔️ No compatible update for this binary';
68
79
  setStatus(nextStatus);
@@ -109,6 +120,7 @@ function useBundleDrop(options) {
109
120
  }, [setAvailableChannels, setStatus]);
110
121
  (0, react_1.useEffect)(() => {
111
122
  refresh();
123
+ (0, rollbackState_1.commitActiveBundle)();
112
124
  }, [refresh]);
113
125
  return {
114
126
  status,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@gfean/react-native-bundle-drop",
3
- "version": "0.1.48",
3
+ "version": "0.1.82",
4
4
  "description": "react native ota by gFean",
5
5
  "main": "lib/index.js",
6
6
  "types": "lib/index.d.ts",
@@ -22,7 +22,8 @@
22
22
  "clean": "rimraf lib dist",
23
23
  "build": "tsc -p tsconfig.json && node scripts/make-cli-executable.js",
24
24
  "prepublishOnly": "yarn clean && yarn build",
25
- "build-and-publish": "yarn clean && yarn build && npm publish --access=restricted"
25
+ "build-and-publish": "yarn clean && yarn build && npm publish --access=restricted",
26
+ "publish:local": "yalc publish --private"
26
27
  },
27
28
  "create-react-native-library": {
28
29
  "type": "legacy-module",
@@ -68,7 +69,6 @@
68
69
  "plist": "^3.1.0",
69
70
  "prompts": "^2.4.2",
70
71
  "react-native-fs": "^2.20.0",
71
- "react-native-zip-archive": "^7.0.1",
72
72
  "undici": "^7.8.0"
73
73
  },
74
74
  "publishConfig": {
@@ -1 +0,0 @@
1
- export declare const buildQuery: (params: Record<string, string | number | undefined | null>) => string;
package/lib/api/utils.js DELETED
@@ -1,8 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.buildQuery = void 0;
4
- const buildQuery = (params) => Object.entries(params)
5
- .filter(([, v]) => v !== undefined && v !== null)
6
- .map(([k, v]) => `${encodeURIComponent(k)}=${encodeURIComponent(String(v))}`)
7
- .join('&');
8
- exports.buildQuery = buildQuery;
@@ -1 +0,0 @@
1
- export declare function setCurrentBundlePointer(bundlePath: string, hash: string): Promise<void>;
@@ -1,20 +0,0 @@
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.setCurrentBundlePointer = setCurrentBundlePointer;
7
- const react_native_fs_1 = __importDefault(require("react-native-fs"));
8
- const context_1 = require("../context");
9
- const fsUtils_1 = require("./fsUtils");
10
- async function setCurrentBundlePointer(bundlePath, hash) {
11
- if (!context_1.isIOS)
12
- return;
13
- const root = `${react_native_fs_1.default.LibraryDirectoryPath}/bundle-drop`;
14
- await (0, fsUtils_1.ensureDir)(root);
15
- await (0, fsUtils_1.atomicWriteJson)(`${root}/current.json`, {
16
- hash,
17
- bundlePath,
18
- updatedAt: new Date().toISOString(),
19
- });
20
- }