@gfean/react-native-bundle-drop 0.1.38 → 0.1.47

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 (42) hide show
  1. package/CLIENT_README.md +21 -12
  2. package/README.md +19 -12
  3. package/lib/CLI/cli.js +6 -6
  4. package/lib/api/client.d.ts +1 -0
  5. package/lib/api/client.js +24 -0
  6. package/lib/api/clientApi.d.ts +8 -0
  7. package/lib/api/clientApi.js +42 -0
  8. package/lib/api/types.d.ts +36 -0
  9. package/lib/api/types.js +2 -0
  10. package/lib/api/utils.d.ts +1 -0
  11. package/lib/api/utils.js +8 -0
  12. package/lib/bootstrap.d.ts +1 -0
  13. package/lib/bootstrap.js +10 -0
  14. package/lib/context.d.ts +5 -0
  15. package/lib/context.js +16 -0
  16. package/lib/errors.d.ts +16 -0
  17. package/lib/errors.js +18 -0
  18. package/lib/fs/fsUtils.d.ts +4 -0
  19. package/lib/fs/fsUtils.js +38 -0
  20. package/lib/fs/iosPointer.d.ts +1 -0
  21. package/lib/fs/iosPointer.js +20 -0
  22. package/lib/index.d.ts +7 -49
  23. package/lib/index.js +18 -414
  24. package/lib/install/installFromZip.d.ts +12 -0
  25. package/lib/install/installFromZip.js +117 -0
  26. package/lib/manager/downloadAndInstall.d.ts +14 -0
  27. package/lib/manager/downloadAndInstall.js +144 -0
  28. package/lib/manager/initUpdateManager.d.ts +7 -0
  29. package/lib/manager/initUpdateManager.js +60 -0
  30. package/lib/manager/reporting.d.ts +5 -0
  31. package/lib/manager/reporting.js +40 -0
  32. package/lib/manager/updateCheck.d.ts +5 -0
  33. package/lib/manager/updateCheck.js +58 -0
  34. package/lib/manager/updateState.d.ts +14 -0
  35. package/lib/manager/updateState.js +62 -0
  36. package/lib/native/bundleDropNative.d.ts +2 -0
  37. package/lib/native/bundleDropNative.js +22 -0
  38. package/lib/scripts/download-bundle.js +29 -12
  39. package/lib/scripts/upload-bundle.js +26 -19
  40. package/lib/useBundleDrop.d.ts +21 -20
  41. package/lib/useBundleDrop.js +67 -73
  42. package/package.json +1 -1
@@ -0,0 +1,144 @@
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.downloadUpdate = void 0;
7
+ const axios_1 = __importDefault(require("axios"));
8
+ const context_1 = require("../context");
9
+ const bundleInfo_1 = require("../bundleInfo");
10
+ const iosPointer_1 = require("../fs/iosPointer");
11
+ const installFromZip_1 = require("../install/installFromZip");
12
+ const updateCheck_1 = require("./updateCheck");
13
+ const clientApi_1 = require("../api/clientApi");
14
+ const errors_1 = require("../errors");
15
+ async function downloadAndStageUpdate(options, onStatusUpdate) {
16
+ const { project, org } = context_1.config;
17
+ const channelName = options?.channelName || 'General';
18
+ const platform = context_1.platform;
19
+ const statusCb = onStatusUpdate;
20
+ const latestBundleParams = {
21
+ platform,
22
+ orgSlug: org.slug,
23
+ project: project.slug,
24
+ channelName,
25
+ };
26
+ // Optional pre-flight check to avoid unnecessary downloads.
27
+ const checkResult = await (0, updateCheck_1.checkForUpdate)(channelName, statusCb);
28
+ const serverHash = checkResult?.hash;
29
+ const serverBundleVersion = checkResult?.bundleVersion;
30
+ const serverVersion = checkResult?.version;
31
+ const serverRuntimeVersion = checkResult?.runtimeVersion;
32
+ if (checkResult?.upToDate) {
33
+ statusCb?.('✅ You have the latest version');
34
+ return { status: 'upToDate' };
35
+ }
36
+ if (checkResult?.incompatible) {
37
+ statusCb?.('⛔️ No compatible update for this binary');
38
+ return { status: 'incompatible' };
39
+ }
40
+ let bundleZipUrl = checkResult?.downloadUrl || null;
41
+ 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
+ if (!bundleZipUrl) {
61
+ throw new Error('Missing bundle download URL');
62
+ }
63
+ // Fetch bundle zip from server.
64
+ statusCb?.('⬇️ Downloading full bundle ZIP!...');
65
+ let zipResponse;
66
+ try {
67
+ zipResponse = await axios_1.default.get(bundleZipUrl, {
68
+ responseType: 'arraybuffer',
69
+ });
70
+ }
71
+ catch (e) {
72
+ throw new errors_1.BundleDropError({
73
+ message: 'Failed to download update ZIP',
74
+ code: 'DOWNLOAD_FAILED',
75
+ step: 'download',
76
+ context: { channelName, platform, url: bundleZipUrl },
77
+ cause: e,
78
+ });
79
+ }
80
+ const hash = serverHash;
81
+ let installResult;
82
+ try {
83
+ installResult = await (0, installFromZip_1.installFromZip)({
84
+ zipArrayBuffer: zipResponse.data,
85
+ hash,
86
+ platform,
87
+ statusCb,
88
+ });
89
+ }
90
+ catch (e) {
91
+ throw new errors_1.BundleDropError({
92
+ message: 'Failed to install update ZIP',
93
+ code: 'INSTALL_FAILED',
94
+ step: 'install',
95
+ context: { channelName, platform, hash },
96
+ cause: e,
97
+ });
98
+ }
99
+ const { bundlePath, metadataFromZip } = installResult;
100
+ // Try to read metadata from the bundle itself as a fallback when server check is unavailable.
101
+ const installedHash = hash ?? metadataFromZip.hash;
102
+ if (!installedHash) {
103
+ throw new errors_1.BundleDropError({
104
+ message: 'Missing bundle hash after install',
105
+ code: 'HASH_MISSING',
106
+ step: 'install',
107
+ context: { channelName, platform },
108
+ });
109
+ }
110
+ statusCb?.('✅ Update downloaded. Will apply on next launch or when you call applyUpdate().');
111
+ // Persist installed metadata for future skip logic.
112
+ const installedInfo = {
113
+ bundleVersion: serverBundleVersion ?? metadataFromZip.bundleVersion,
114
+ version: serverVersion ?? metadataFromZip.version,
115
+ hash: installedHash,
116
+ channelName,
117
+ platform,
118
+ installedAt: new Date().toISOString(),
119
+ pendingApply: true,
120
+ runtimeVersion: metadataFromZip.runtimeVersion ?? serverRuntimeVersion ?? context_1.runtimeVersion ?? undefined,
121
+ };
122
+ (0, bundleInfo_1.writeBundleInfo)(installedInfo);
123
+ await (0, iosPointer_1.setCurrentBundlePointer)(bundlePath, installedHash);
124
+ return { status: 'staged', bundlePath, hash: installedHash };
125
+ }
126
+ catch (err) {
127
+ const wrapped = err instanceof errors_1.BundleDropError
128
+ ? err
129
+ : new errors_1.BundleDropError({
130
+ message: 'OTA update failed',
131
+ code: 'UNKNOWN',
132
+ step: 'install',
133
+ context: { channelName, platform },
134
+ cause: err,
135
+ });
136
+ console.error('❌ OTA update failed:', wrapped);
137
+ statusCb?.(`❌ OTA update failed (${wrapped.code}/${wrapped.step})`);
138
+ throw wrapped;
139
+ }
140
+ }
141
+ const downloadUpdate = async (options, onStatusUpdate) => {
142
+ return downloadAndStageUpdate(options, onStatusUpdate);
143
+ };
144
+ exports.downloadUpdate = downloadUpdate;
@@ -0,0 +1,7 @@
1
+ import { UpdatePolicy } from '../types';
2
+ export declare function initUpdateManager(opts?: {
3
+ channelName?: string;
4
+ policy?: UpdatePolicy;
5
+ onStatusUpdate?: (status: string) => void;
6
+ checkOnly?: boolean;
7
+ }): Promise<void>;
@@ -0,0 +1,60 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.initUpdateManager = initUpdateManager;
4
+ const downloadAndInstall_1 = require("./downloadAndInstall");
5
+ const updateCheck_1 = require("./updateCheck");
6
+ const updateState_1 = require("./updateState");
7
+ async function initUpdateManager(opts) {
8
+ const policy = opts?.policy || 'manual';
9
+ const channelName = opts?.channelName || 'General';
10
+ const statusCb = opts?.onStatusUpdate;
11
+ // Reconcile pending state on launch (assume downloaded bundle is active if present).
12
+ await (0, updateState_1.reconcileAppliedBundleOnLaunch)();
13
+ const pendingState = await (0, updateState_1.getUpdateState)();
14
+ if (pendingState.pendingApply) {
15
+ if (policy === 'immediate') {
16
+ statusCb?.('♻️ Applying previously downloaded update...');
17
+ await (0, updateState_1.applyUpdate)(statusCb);
18
+ return;
19
+ }
20
+ if (policy === 'on-next-launch') {
21
+ statusCb?.('✅ Update downloaded; will apply on next launch.');
22
+ return;
23
+ }
24
+ }
25
+ // Manual policy: optionally just check and return.
26
+ if (policy === 'manual' && !opts?.checkOnly) {
27
+ return;
28
+ }
29
+ 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');
36
+ }
37
+ return;
38
+ }
39
+ if (policy === 'on-next-launch') {
40
+ const res = await (0, downloadAndInstall_1.downloadUpdate)({ channelName }, statusCb || (() => { }));
41
+ if (res.status === 'staged')
42
+ statusCb?.('✅ Update downloaded for next launch');
43
+ if (res.status === 'upToDate')
44
+ statusCb?.('✅ You have the latest version');
45
+ if (res.status === 'incompatible')
46
+ statusCb?.('⛔️ No compatible update for this binary');
47
+ return;
48
+ }
49
+ // immediate
50
+ const res = await (0, downloadAndInstall_1.downloadUpdate)({ channelName }, statusCb || (() => { }));
51
+ if (res.status === 'staged') {
52
+ await (0, updateState_1.applyUpdate)(statusCb);
53
+ return;
54
+ }
55
+ if (res.status === 'upToDate')
56
+ statusCb?.('✅ You have the latest version');
57
+ if (res.status === 'incompatible')
58
+ statusCb?.('⛔️ No compatible update for this binary');
59
+ return;
60
+ }
@@ -0,0 +1,5 @@
1
+ import { BundleInfo } from '../bundleInfo';
2
+ export declare function reportInstalledIfReady(state?: {
3
+ hasBundle?: boolean;
4
+ info?: BundleInfo | null;
5
+ }): Promise<void>;
@@ -0,0 +1,40 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.reportInstalledIfReady = reportInstalledIfReady;
4
+ const context_1 = require("../context");
5
+ const bundleInfo_1 = require("../bundleInfo");
6
+ const clientApi_1 = require("../api/clientApi");
7
+ const bundleDropNative_1 = require("../native/bundleDropNative");
8
+ async function getReportingState() {
9
+ const info = await (0, bundleInfo_1.readBundleInfo)();
10
+ const path = await (0, bundleDropNative_1.getDownloadedBundlePathNative)();
11
+ return {
12
+ hasBundle: !!path,
13
+ info,
14
+ };
15
+ }
16
+ async function reportInstalledIfReady(state) {
17
+ const current = state ?? (await getReportingState());
18
+ const info = state?.info ?? current.info;
19
+ const hasBundle = state?.hasBundle ?? current.hasBundle;
20
+ if (!info?.hash)
21
+ return;
22
+ if (info.pendingApply)
23
+ return;
24
+ if (hasBundle === false)
25
+ return;
26
+ if (info.lastInstalledReportedHash === info.hash)
27
+ return;
28
+ try {
29
+ await (0, clientApi_1.reportInstalled)(info.hash, {
30
+ orgSlug: context_1.config.org.slug,
31
+ projectSlug: context_1.config.project.slug,
32
+ channelName: info.channelName,
33
+ platform: info.platform,
34
+ });
35
+ await (0, bundleInfo_1.updateBundleInfo)({ lastInstalledReportedHash: info.hash });
36
+ }
37
+ catch (e) {
38
+ console.warn('⚠️ Failed to report bundle install:', e?.toString?.() || e);
39
+ }
40
+ }
@@ -0,0 +1,5 @@
1
+ import { BundleInfo } from '../bundleInfo';
2
+ import type { UpdateCheckResponse } from '../api/types';
3
+ export declare function getAvailableChannels(): Promise<string[]>;
4
+ export declare function checkForUpdate(channelName?: string, onStatusUpdate?: (status: string) => void): Promise<UpdateCheckResponse | null>;
5
+ export declare function getInstalledBundleInfo(): Promise<BundleInfo | null>;
@@ -0,0 +1,58 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.getAvailableChannels = getAvailableChannels;
4
+ exports.checkForUpdate = checkForUpdate;
5
+ exports.getInstalledBundleInfo = getInstalledBundleInfo;
6
+ const context_1 = require("../context");
7
+ const bundleInfo_1 = require("../bundleInfo");
8
+ const clientApi_1 = require("../api/clientApi");
9
+ 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
+ }
14
+ try {
15
+ const res = await (0, clientApi_1.getPublicChannels)({
16
+ projectSlug: project.slug,
17
+ orgSlug: org.slug,
18
+ });
19
+ if (!Array.isArray(res.data)) {
20
+ throw new Error('Invalid channel list response');
21
+ }
22
+ return res.data;
23
+ }
24
+ catch (e) {
25
+ console.warn('⚠️ Failed to fetch available channels:', e?.toString?.() || e);
26
+ throw e;
27
+ }
28
+ }
29
+ async function checkForUpdate(channelName = 'General', onStatusUpdate) {
30
+ const { project, org } = context_1.config;
31
+ const local = await (0, bundleInfo_1.readBundleInfo)();
32
+ try {
33
+ 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,
38
+ channelName,
39
+ currentBundleVersion: local?.bundleVersion,
40
+ currentHash: local?.hash,
41
+ runtimeVersion: context_1.runtimeVersion,
42
+ });
43
+ if (res.data.upToDate) {
44
+ onStatusUpdate?.(`You've got the latest version for the given channel ${res.data.channelName ?? ''}`);
45
+ }
46
+ if (res.data.incompatible) {
47
+ onStatusUpdate?.('⛔️ No compatible update for this binary');
48
+ }
49
+ return res.data;
50
+ }
51
+ catch (e) {
52
+ console.warn('⚠️ checkForUpdate failed, will fallback to download:', e?.toString?.() || e);
53
+ return null;
54
+ }
55
+ }
56
+ async function getInstalledBundleInfo() {
57
+ return (0, bundleInfo_1.readBundleInfo)();
58
+ }
@@ -0,0 +1,14 @@
1
+ export type ApplyUpdateResult = {
2
+ status: 'applied';
3
+ } | {
4
+ status: 'noBundle';
5
+ } | {
6
+ status: 'alreadyApplied';
7
+ };
8
+ export declare const getUpdateState: () => Promise<{
9
+ hasBundle: boolean;
10
+ info: import("../bundleInfo").BundleInfo;
11
+ pendingApply: boolean;
12
+ }>;
13
+ export declare const reconcileAppliedBundleOnLaunch: () => Promise<void>;
14
+ export declare const applyUpdate: (onStatusUpdate?: (status: string) => void) => Promise<ApplyUpdateResult>;
@@ -0,0 +1,62 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.applyUpdate = exports.reconcileAppliedBundleOnLaunch = exports.getUpdateState = void 0;
4
+ const bundleDropNative_1 = require("../native/bundleDropNative");
5
+ const bundleInfo_1 = require("../bundleInfo");
6
+ const reporting_1 = require("./reporting");
7
+ const errors_1 = require("../errors");
8
+ const getUpdateState = async () => {
9
+ const info = await (0, bundleInfo_1.readBundleInfo)();
10
+ const path = await (0, bundleDropNative_1.getDownloadedBundlePathNative)();
11
+ return {
12
+ hasBundle: !!path,
13
+ info,
14
+ pendingApply: info?.pendingApply ?? false,
15
+ };
16
+ };
17
+ exports.getUpdateState = getUpdateState;
18
+ const reconcileAppliedBundleOnLaunch = async () => {
19
+ const state = await (0, exports.getUpdateState)();
20
+ if (!state.info?.pendingApply)
21
+ return;
22
+ if (!state.hasBundle)
23
+ return;
24
+ // Assume that if a downloaded bundle exists on disk during app launch, it is the active bundle.
25
+ await (0, bundleInfo_1.updateBundleInfo)({ pendingApply: false, installedAt: new Date().toISOString() });
26
+ await (0, reporting_1.reportInstalledIfReady)({
27
+ hasBundle: true,
28
+ info: state.info ? { ...state.info, pendingApply: false } : state.info,
29
+ });
30
+ };
31
+ exports.reconcileAppliedBundleOnLaunch = reconcileAppliedBundleOnLaunch;
32
+ const applyUpdate = async (onStatusUpdate) => {
33
+ try {
34
+ const path = await (0, bundleDropNative_1.getDownloadedBundlePathNative)();
35
+ const info = await (0, bundleInfo_1.readBundleInfo)();
36
+ if (!path) {
37
+ onStatusUpdate?.('⚠️ No downloaded bundle to apply');
38
+ return { status: 'noBundle' };
39
+ }
40
+ if (info?.pendingApply === false) {
41
+ onStatusUpdate?.('ℹ️ Bundle already applied');
42
+ return { status: 'alreadyApplied' };
43
+ }
44
+ onStatusUpdate?.('♻️ Applying downloaded bundle...');
45
+ await (0, bundleInfo_1.updateBundleInfo)({ pendingApply: false, installedAt: new Date().toISOString() });
46
+ await (0, reporting_1.reportInstalledIfReady)({
47
+ hasBundle: true,
48
+ info: info ? { ...info, pendingApply: false } : info,
49
+ });
50
+ (0, bundleDropNative_1.restartReactNativeNative)();
51
+ return { status: 'applied' };
52
+ }
53
+ catch (e) {
54
+ throw new errors_1.BundleDropError({
55
+ message: 'Failed to apply update',
56
+ code: 'APPLY_FAILED',
57
+ step: 'apply',
58
+ cause: e,
59
+ });
60
+ }
61
+ };
62
+ exports.applyUpdate = applyUpdate;
@@ -0,0 +1,2 @@
1
+ export declare function getDownloadedBundlePathNative(): Promise<string | null>;
2
+ export declare function restartReactNativeNative(): void;
@@ -0,0 +1,22 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.getDownloadedBundlePathNative = getDownloadedBundlePathNative;
4
+ exports.restartReactNativeNative = restartReactNativeNative;
5
+ const react_native_1 = require("react-native");
6
+ const { BundleDrop } = react_native_1.NativeModules;
7
+ async function getDownloadedBundlePathNative() {
8
+ if (!BundleDrop?.getDownloadedBundlePath) {
9
+ console.warn('BundleDrop.getDownloadedBundlePath is not defined');
10
+ return null;
11
+ }
12
+ try {
13
+ return await BundleDrop.getDownloadedBundlePath();
14
+ }
15
+ catch (e) {
16
+ console.error('❌ Failed to get bundle path:', e);
17
+ return null;
18
+ }
19
+ }
20
+ function restartReactNativeNative() {
21
+ BundleDrop?.restartReactNative?.();
22
+ }
@@ -61,19 +61,36 @@ if (!org?.slug) {
61
61
  console.error('❌ Missing "org.slug" in bundle.drop.config.js');
62
62
  process.exit(1);
63
63
  }
64
- const downloadUrl = `${serverUrl}/bundle/latest?platform=${platform}&orgSlug=${org.slug}&project=${project.slug}`;
64
+ const latestEndpoint = `${serverUrl}/bundle/latest?platform=${platform}&orgSlug=${org.slug}&project=${project.slug}`;
65
65
  const outputPath = path.join(outputDir, `main.${platform}.jsbundle`);
66
66
  if (!fs.existsSync(outputDir)) {
67
67
  fs.mkdirSync(outputDir, { recursive: true });
68
68
  }
69
- console.log(`⬇️ Downloading latest ${platform} bundle from: ${downloadUrl}`);
70
- axios_1.default
71
- .get(downloadUrl, { responseType: 'arraybuffer' })
72
- .then(async (response) => {
73
- await fs.promises.writeFile(outputPath, Buffer.from(response.data));
74
- console.log(`✅ Bundle downloaded and saved to: ${outputPath}`);
75
- })
76
- .catch(err => {
77
- console.error('❌ Download failed:', err.response?.data || err.message);
78
- process.exit(1);
79
- });
69
+ const authHeaders = {
70
+ ...(project?.apiKey ? { 'x-api-key': project.apiKey } : {}),
71
+ };
72
+ async function downloadLatestBundle() {
73
+ try {
74
+ console.log(`⬇️ Fetching bundle download URL from: ${latestEndpoint}`);
75
+ const latestResponse = await axios_1.default.get(latestEndpoint, {
76
+ headers: {
77
+ Accept: 'application/json',
78
+ ...authHeaders,
79
+ },
80
+ });
81
+ const bundleDownloadUrl = latestResponse.data?.downloadUrl;
82
+ if (!bundleDownloadUrl) {
83
+ console.error('❌ Missing downloadUrl in latest bundle response');
84
+ process.exit(1);
85
+ }
86
+ console.log(`⬇️ Downloading latest ${platform} bundle from signed URL...`);
87
+ const bundleResponse = await axios_1.default.get(bundleDownloadUrl, { responseType: 'arraybuffer' });
88
+ await fs.promises.writeFile(outputPath, Buffer.from(bundleResponse.data));
89
+ console.log(`✅ Bundle downloaded and saved to: ${outputPath}`);
90
+ }
91
+ catch (err) {
92
+ console.error('❌ Download failed:', err.response?.data || err.message || err);
93
+ process.exit(1);
94
+ }
95
+ }
96
+ downloadLatestBundle();
@@ -248,21 +248,12 @@ if (releaseNotes) {
248
248
  }
249
249
  form.append('file', fs.createReadStream(zipPath));
250
250
  console.log(`⬆️ Uploading ${platform} bundle (v${version}) to project "${projectSlug}" at ${serverUrl}...`);
251
- axios_1.default
252
- .post(`${serverUrl}/bundle/upload`, form, {
253
- headers: {
254
- ...form.getHeaders(),
255
- Authorization: `Bearer ${token}`,
256
- },
257
- maxContentLength: Infinity,
258
- maxBodyLength: Infinity,
259
- })
260
- .then(res => {
261
- console.log('✅ Upload complete:', res.data);
262
- // --- CLEANUP ---
251
+ const cleanupArtifacts = () => {
263
252
  try {
264
- fs.unlinkSync(zipPath);
265
- console.log(`🧹 Deleted: ${zipPath}`);
253
+ if (fs.existsSync(zipPath)) {
254
+ fs.unlinkSync(zipPath);
255
+ console.log(`🧹 Deleted: ${zipPath}`);
256
+ }
266
257
  const suffix = platform === 'ios' ? 'ios' : 'android';
267
258
  const metadataPath = path.join(outputDir, `metadata-${suffix}.json`);
268
259
  const assetsPath = path.join(outputDir, 'assets');
@@ -283,8 +274,24 @@ axios_1.default
283
274
  catch (err) {
284
275
  console.warn('⚠️ Cleanup failed:', err);
285
276
  }
286
- })
287
- .catch(err => {
288
- console.error('❌ Upload failed:', err?.response?.data || err.message);
289
- process.exit(1);
290
- });
277
+ };
278
+ (async () => {
279
+ try {
280
+ const res = await axios_1.default.post(`${serverUrl}/bundle/upload`, form, {
281
+ headers: {
282
+ ...form.getHeaders(),
283
+ Authorization: `Bearer ${token}`,
284
+ },
285
+ maxContentLength: Infinity,
286
+ maxBodyLength: Infinity,
287
+ });
288
+ console.log('✅ Upload complete:', res.data);
289
+ }
290
+ catch (err) {
291
+ console.error('❌ Upload failed:', err?.response?.data || err.message);
292
+ throw err;
293
+ }
294
+ finally {
295
+ cleanupArtifacts();
296
+ }
297
+ })().catch(() => process.exit(1));
@@ -1,16 +1,10 @@
1
1
  import type { BundleInfo } from './bundleInfo';
2
- import type { UpdatePolicy } from './types';
2
+ import { DownloadUpdateResult } from './manager/downloadAndInstall';
3
+ import { ApplyUpdateResult } from './manager/updateState';
4
+ import { UpdateCheckResponse } from './api/types';
3
5
  type UseBundleDropOptions = {
4
6
  /** Channel to target; defaults to "General". */
5
7
  channelName?: string;
6
- /** Update policy to honor on mount when autoInit is true. */
7
- policy?: UpdatePolicy;
8
- /** If true, initUpdateManager runs on mount with the provided policy. */
9
- autoInit?: boolean;
10
- /** Optional status callback for initUpdateManager. */
11
- onStatusUpdate?: (status: string) => void;
12
- /** For manual policy, set true to run a check without downloading. */
13
- checkOnly?: boolean;
14
8
  };
15
9
  type UseBundleDropReturn = {
16
10
  /** Last human-readable status message (downloads, checks, applies). */
@@ -24,17 +18,24 @@ type UseBundleDropReturn = {
24
18
  /** True when a bundle file exists on disk (downloaded). */
25
19
  hasBundle: boolean;
26
20
  /** Check server for updates; updates status only. */
27
- checkLatest: () => Promise<void>;
28
- /** Download and apply immediately (reload). */
29
- downloadImmediate: () => Promise<void>;
30
- /** Download now, apply on next launch (sets pending). */
31
- downloadForNextLaunch: () => Promise<void>;
32
- /** Download without applying; keeps pending flag true. */
33
- downloadManual: () => Promise<void>;
34
- /** Apply a pending downloaded bundle (reload). */
35
- applyPending: () => Promise<void>;
36
- /** Re-read local bundle state (installedInfo/pending). */
37
- refresh: () => Promise<void>;
21
+ checkLatest: () => Promise<{
22
+ response: UpdateCheckResponse | null;
23
+ status?: string;
24
+ }>;
25
+ /** Download and stage update (will apply on next launch or when applyUpdate is called). */
26
+ downloadUpdate: () => Promise<{
27
+ result: DownloadUpdateResult;
28
+ status?: string;
29
+ }>;
30
+ /** Apply a staged update (reload). */
31
+ applyUpdate: () => Promise<{
32
+ result: ApplyUpdateResult;
33
+ status?: string;
34
+ }>;
35
+ /** Fetch available channel names from the server (API key auth). */
36
+ fetchAvailableChannels: () => Promise<string[]>;
37
+ /** Last fetched list of channel names. */
38
+ availableChannels: string[];
38
39
  };
39
40
  export declare function useBundleDrop(options?: UseBundleDropOptions): UseBundleDropReturn;
40
41
  export {};