@gfean/react-native-bundle-drop 0.2.0 → 0.2.2

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.
@@ -1,5 +1,6 @@
1
1
  import type { AxiosResponse } from 'axios';
2
- import { OtaResolveRequest, OtaResolveResponse, PublicChannelsParams, ReportInstalledPayload } from './types';
2
+ import { OtaResolveRequest, OtaResolveResponse, PublicChannelsParams, ReportInstalledPayload, BundleListParams, BundleListResponse } from './types';
3
3
  export declare function postOtaResolve(projectSlug: string, payload: OtaResolveRequest): Promise<AxiosResponse<OtaResolveResponse>>;
4
4
  export declare function getPublicChannels(params: PublicChannelsParams): Promise<AxiosResponse<string[]>>;
5
5
  export declare function reportInstalled(projectSlug: string, hash: string, payload: ReportInstalledPayload): Promise<AxiosResponse<void>>;
6
+ export declare function getBundleList(projectSlug: string, params: BundleListParams): Promise<AxiosResponse<BundleListResponse>>;
@@ -3,6 +3,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.postOtaResolve = postOtaResolve;
4
4
  exports.getPublicChannels = getPublicChannels;
5
5
  exports.reportInstalled = reportInstalled;
6
+ exports.getBundleList = getBundleList;
6
7
  const client_1 = require("./client");
7
8
  function postOtaResolve(projectSlug, payload) {
8
9
  return client_1.apiClient.post(`/projects/${encodeURIComponent(projectSlug)}/ota/resolve`, payload, {
@@ -29,3 +30,16 @@ function reportInstalled(projectSlug, hash, payload) {
29
30
  timeout: 10000,
30
31
  });
31
32
  }
33
+ function getBundleList(projectSlug, params) {
34
+ const parts = [`channelName=${encodeURIComponent(params.channelName)}`];
35
+ if (params.platform)
36
+ parts.push(`platform=${encodeURIComponent(params.platform)}`);
37
+ if (params.limit)
38
+ parts.push(`limit=${params.limit}`);
39
+ if (params.cursor)
40
+ parts.push(`cursor=${encodeURIComponent(params.cursor)}`);
41
+ return client_1.apiClient.get(`/projects/${encodeURIComponent(projectSlug)}/bundle/list?${parts.join('&')}`, {
42
+ headers: { Accept: 'application/json' },
43
+ timeout: 15000,
44
+ });
45
+ }
@@ -3,7 +3,7 @@ export type OtaResolveRequest = {
3
3
  platform: string;
4
4
  runtimeVersion?: string | null;
5
5
  currentHash?: string | null;
6
- currentUserProperties?: string[];
6
+ currentUserProperties?: Record<string, string>;
7
7
  previousHash?: string | null;
8
8
  currentBundleVersion?: number | null;
9
9
  installId?: string | null;
@@ -48,4 +48,26 @@ export type ReportInstalledPayload = {
48
48
  platform?: string;
49
49
  installId?: string | null;
50
50
  runtimeVersion?: string | null;
51
+ userProperties?: Record<string, string>;
52
+ };
53
+ export type BundleListItem = {
54
+ hash: string;
55
+ bundleVersion: number;
56
+ version: string;
57
+ platform: string;
58
+ runtimeVersion: string;
59
+ releaseNotes: string | null;
60
+ createdAt: string;
61
+ downloadUrl: string | null;
62
+ };
63
+ export type BundleListResponse = {
64
+ items: BundleListItem[];
65
+ nextCursor: string | null;
66
+ hasMore: boolean;
67
+ };
68
+ export type BundleListParams = {
69
+ channelName: string;
70
+ platform?: string;
71
+ limit?: number;
72
+ cursor?: string;
51
73
  };
package/lib/context.d.ts CHANGED
@@ -4,3 +4,23 @@ export declare const isIOS: boolean;
4
4
  export declare const runtimeVersion: string;
5
5
  export declare const defaultChannel: string;
6
6
  export declare const BUNDLE_DROP_ROOT: string;
7
+ export type BundleDropConfig = {
8
+ serverUrl: string;
9
+ platform: 'ios' | 'android';
10
+ runtimeVersion: string | undefined;
11
+ defaultChannel: string;
12
+ org: {
13
+ slug: string;
14
+ };
15
+ project: {
16
+ name: string;
17
+ slug: string;
18
+ };
19
+ debugLocal: boolean;
20
+ rollback: {
21
+ maxCrashCount: number;
22
+ crashWindowSec: number;
23
+ commitTimeoutSec: number;
24
+ };
25
+ };
26
+ export declare const bundleDropConfig: BundleDropConfig;
package/lib/context.js CHANGED
@@ -3,7 +3,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
3
3
  return (mod && mod.__esModule) ? mod : { "default": mod };
4
4
  };
5
5
  Object.defineProperty(exports, "__esModule", { value: true });
6
- exports.BUNDLE_DROP_ROOT = exports.defaultChannel = exports.runtimeVersion = exports.isIOS = exports.platform = exports.config = void 0;
6
+ exports.bundleDropConfig = exports.BUNDLE_DROP_ROOT = exports.defaultChannel = exports.runtimeVersion = exports.isIOS = exports.platform = exports.config = void 0;
7
7
  const react_native_1 = require("react-native");
8
8
  const fs_1 = __importDefault(require("./native/fs"));
9
9
  const loadConfig_1 = require("./loadConfig");
@@ -15,3 +15,17 @@ exports.defaultChannel = exports.config.defaultChannel || 'General';
15
15
  exports.BUNDLE_DROP_ROOT = exports.isIOS
16
16
  ? `${fs_1.default.LibraryDirectoryPath}/bundle-drop`
17
17
  : `${fs_1.default.DocumentDirectoryPath}/bundle-drop`;
18
+ exports.bundleDropConfig = {
19
+ serverUrl: exports.config.serverUrl,
20
+ platform: exports.platform,
21
+ runtimeVersion: exports.runtimeVersion,
22
+ defaultChannel: exports.defaultChannel,
23
+ org: { slug: exports.config.org.slug },
24
+ project: { name: exports.config.project.name, slug: exports.config.project.slug },
25
+ debugLocal: exports.config.debugLocal ?? false,
26
+ rollback: {
27
+ maxCrashCount: exports.config.rollback?.maxCrashCount ?? 3,
28
+ crashWindowSec: exports.config.rollback?.crashWindowSec ?? 30,
29
+ commitTimeoutSec: exports.config.rollback?.commitTimeoutSec ?? 10,
30
+ },
31
+ };
@@ -1,6 +1,7 @@
1
- export declare function getCurrentUserProperties(): Promise<string[]>;
2
- export declare function getUserProperties(): Promise<string[]>;
3
- export declare function setUserProperty(value: string): Promise<string[]>;
4
- export declare function removeUserProperty(value: string): Promise<string[]>;
1
+ export declare function getCurrentUserProperties(): Promise<Record<string, string>>;
2
+ export declare function getUserProperties(): Promise<Record<string, string>>;
3
+ export declare function setUserProperty(key: string, value: string): Promise<Record<string, string>>;
4
+ export declare function removeUserProperty(key: string): Promise<Record<string, string>>;
5
5
  export declare function resetUserProperties(): Promise<void>;
6
+ /** @deprecated Use setUserProperty(key, value) instead. */
6
7
  export declare const setUserPropery: typeof setUserProperty;
@@ -13,75 +13,64 @@ const fs_1 = __importDefault(require("../native/fs"));
13
13
  const context_1 = require("../context");
14
14
  const fsUtils_1 = require("./fsUtils");
15
15
  const USER_PROPERTIES_PATH = `${context_1.BUNDLE_DROP_ROOT}/user-properties.json`;
16
- function normalizeUserProperty(input) {
17
- return input.trim();
18
- }
19
- function unique(values) {
20
- const seen = new Set();
21
- const result = [];
22
- for (const value of values) {
23
- if (seen.has(value))
24
- continue;
25
- seen.add(value);
26
- result.push(value);
27
- }
28
- return result;
29
- }
30
16
  async function writeUserProperties(properties) {
31
17
  await (0, fsUtils_1.ensureDir)(context_1.BUNDLE_DROP_ROOT);
32
- const payload = {
33
- properties: unique(properties),
34
- };
18
+ const payload = { properties: { ...properties } };
35
19
  await (0, fsUtils_1.atomicWriteJson)(USER_PROPERTIES_PATH, payload);
36
20
  }
37
21
  async function getCurrentUserProperties() {
38
22
  try {
39
23
  if (!(await fs_1.default.exists(USER_PROPERTIES_PATH)))
40
- return [];
24
+ return {};
41
25
  const raw = await fs_1.default.readFile(USER_PROPERTIES_PATH, 'utf8');
42
26
  const parsed = JSON.parse(raw);
43
- if (Array.isArray(parsed)) {
44
- return unique(parsed.filter(value => typeof value === 'string').map(normalizeUserProperty).filter(Boolean));
27
+ const props = parsed?.properties;
28
+ if (!props || typeof props !== 'object' || Array.isArray(props))
29
+ return {};
30
+ const result = {};
31
+ for (const [k, v] of Object.entries(props)) {
32
+ if (typeof k === 'string' && typeof v === 'string') {
33
+ const key = k.trim();
34
+ if (key)
35
+ result[key] = v;
36
+ }
45
37
  }
46
- const values = parsed?.properties;
47
- if (!Array.isArray(values))
48
- return [];
49
- return unique(values.filter(value => typeof value === 'string').map(normalizeUserProperty).filter(Boolean));
38
+ return result;
50
39
  }
51
40
  catch (e) {
52
41
  console.warn('âš ī¸ Failed to read user-properties.json', e);
53
- return [];
42
+ return {};
54
43
  }
55
44
  }
56
45
  async function getUserProperties() {
57
46
  return getCurrentUserProperties();
58
47
  }
59
- async function setUserProperty(value) {
60
- const normalized = normalizeUserProperty(value);
61
- if (!normalized) {
48
+ async function setUserProperty(key, value) {
49
+ const trimmedKey = key.trim();
50
+ if (!trimmedKey) {
62
51
  return getCurrentUserProperties();
63
52
  }
64
53
  const existing = await getCurrentUserProperties();
65
- if (existing.includes(normalized)) {
54
+ if (existing[trimmedKey] === value) {
66
55
  return existing;
67
56
  }
68
- const next = [...existing, normalized];
57
+ const next = { ...existing, [trimmedKey]: value };
69
58
  await writeUserProperties(next);
70
59
  return next;
71
60
  }
72
- async function removeUserProperty(value) {
73
- const normalized = normalizeUserProperty(value);
74
- if (!normalized) {
61
+ async function removeUserProperty(key) {
62
+ const trimmedKey = key.trim();
63
+ if (!trimmedKey) {
75
64
  return getCurrentUserProperties();
76
65
  }
77
66
  const existing = await getCurrentUserProperties();
78
- const next = existing.filter(item => item !== normalized);
79
- if (next.length === existing.length) {
67
+ if (!(trimmedKey in existing)) {
80
68
  return existing;
81
69
  }
82
- if (next.length === 0) {
70
+ const { [trimmedKey]: _, ...next } = existing;
71
+ if (Object.keys(next).length === 0) {
83
72
  await resetUserProperties();
84
- return [];
73
+ return {};
85
74
  }
86
75
  await writeUserProperties(next);
87
76
  return next;
@@ -96,5 +85,5 @@ async function resetUserProperties() {
96
85
  console.warn('âš ī¸ Failed to reset user-properties.json', e);
97
86
  }
98
87
  }
99
- // Backward-compatible alias for the requested API name.
88
+ /** @deprecated Use setUserProperty(key, value) instead. */
100
89
  exports.setUserPropery = setUserProperty;
package/lib/index.d.ts CHANGED
@@ -1,10 +1,15 @@
1
1
  import './bootstrap';
2
- export { getAvailableChannels, checkForUpdate, getInstalledBundleInfo } from './manager/updateCheck';
3
- export { downloadUpdate } from './manager/downloadAndInstall';
2
+ export { getAvailableChannels, checkForUpdate, getInstalledBundleInfo, getAvailableBundles } from './manager/updateCheck';
3
+ export type { AvailableBundlesPage, GetAvailableBundlesOptions } from './manager/updateCheck';
4
+ export { downloadUpdate, installBundle } from './manager/downloadAndInstall';
4
5
  export { getUpdateState, applyUpdate } from './manager/updateState';
5
6
  export { initUpdateManager, isUpdateFlowActive } from './manager/initUpdateManager';
6
7
  export { BundleDropError, isBundleDropError } from './errors';
7
8
  export { getCurrentUserProperties, getUserProperties, setUserProperty, setUserPropery, removeUserProperty, resetUserProperties, } from './fs/userProperties';
8
9
  export type { BundleInfo } from './bundleInfo';
9
10
  export type { UpdatePolicy } from './types';
11
+ export type { BundleListItem } from './api/types';
12
+ export type { BundleDropProjectConfig } from './loadConfig';
13
+ export type { BundleDropConfig } from './context';
10
14
  export { useBundleDrop } from './useBundleDrop';
15
+ export { bundleDropConfig } from './context';
package/lib/index.js CHANGED
@@ -1,13 +1,15 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.useBundleDrop = exports.resetUserProperties = exports.removeUserProperty = exports.setUserPropery = exports.setUserProperty = exports.getUserProperties = exports.getCurrentUserProperties = exports.isBundleDropError = exports.BundleDropError = exports.isUpdateFlowActive = exports.initUpdateManager = exports.applyUpdate = exports.getUpdateState = exports.downloadUpdate = exports.getInstalledBundleInfo = exports.checkForUpdate = exports.getAvailableChannels = void 0;
3
+ exports.bundleDropConfig = exports.useBundleDrop = exports.resetUserProperties = exports.removeUserProperty = exports.setUserPropery = exports.setUserProperty = exports.getUserProperties = exports.getCurrentUserProperties = exports.isBundleDropError = exports.BundleDropError = exports.isUpdateFlowActive = exports.initUpdateManager = exports.applyUpdate = exports.getUpdateState = exports.installBundle = exports.downloadUpdate = exports.getAvailableBundles = exports.getInstalledBundleInfo = exports.checkForUpdate = exports.getAvailableChannels = void 0;
4
4
  require("./bootstrap");
5
5
  var updateCheck_1 = require("./manager/updateCheck");
6
6
  Object.defineProperty(exports, "getAvailableChannels", { enumerable: true, get: function () { return updateCheck_1.getAvailableChannels; } });
7
7
  Object.defineProperty(exports, "checkForUpdate", { enumerable: true, get: function () { return updateCheck_1.checkForUpdate; } });
8
8
  Object.defineProperty(exports, "getInstalledBundleInfo", { enumerable: true, get: function () { return updateCheck_1.getInstalledBundleInfo; } });
9
+ Object.defineProperty(exports, "getAvailableBundles", { enumerable: true, get: function () { return updateCheck_1.getAvailableBundles; } });
9
10
  var downloadAndInstall_1 = require("./manager/downloadAndInstall");
10
11
  Object.defineProperty(exports, "downloadUpdate", { enumerable: true, get: function () { return downloadAndInstall_1.downloadUpdate; } });
12
+ Object.defineProperty(exports, "installBundle", { enumerable: true, get: function () { return downloadAndInstall_1.installBundle; } });
11
13
  var updateState_1 = require("./manager/updateState");
12
14
  Object.defineProperty(exports, "getUpdateState", { enumerable: true, get: function () { return updateState_1.getUpdateState; } });
13
15
  Object.defineProperty(exports, "applyUpdate", { enumerable: true, get: function () { return updateState_1.applyUpdate; } });
@@ -26,3 +28,5 @@ Object.defineProperty(exports, "removeUserProperty", { enumerable: true, get: fu
26
28
  Object.defineProperty(exports, "resetUserProperties", { enumerable: true, get: function () { return userProperties_1.resetUserProperties; } });
27
29
  var useBundleDrop_1 = require("./useBundleDrop");
28
30
  Object.defineProperty(exports, "useBundleDrop", { enumerable: true, get: function () { return useBundleDrop_1.useBundleDrop; } });
31
+ var context_1 = require("./context");
32
+ Object.defineProperty(exports, "bundleDropConfig", { enumerable: true, get: function () { return context_1.bundleDropConfig; } });
@@ -21,4 +21,9 @@ type DownloadOptions = {
21
21
  };
22
22
  };
23
23
  export declare const downloadUpdate: (options?: DownloadOptions, onStatusUpdate?: (status: string) => void) => Promise<DownloadUpdateResult>;
24
+ export type InstallBundleOptions = {
25
+ channelName?: string;
26
+ onStatusUpdate?: (status: string) => void;
27
+ };
28
+ export declare const installBundle: (hash: string, downloadUrl: string, bundleVersion?: number, version?: string, runtimeVersion?: string, options?: InstallBundleOptions) => Promise<DownloadUpdateResult>;
24
29
  export {};
@@ -3,7 +3,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
3
3
  return (mod && mod.__esModule) ? mod : { "default": mod };
4
4
  };
5
5
  Object.defineProperty(exports, "__esModule", { value: true });
6
- exports.downloadUpdate = void 0;
6
+ exports.installBundle = exports.downloadUpdate = void 0;
7
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");
@@ -150,3 +150,10 @@ const downloadUpdate = async (options, onStatusUpdate) => {
150
150
  return downloadAndStageUpdate(options, onStatusUpdate);
151
151
  };
152
152
  exports.downloadUpdate = downloadUpdate;
153
+ const installBundle = async (hash, downloadUrl, bundleVersion, version, runtimeVersion, options) => {
154
+ return downloadAndStageUpdate({
155
+ channelName: options?.channelName,
156
+ resolvedTarget: { hash, downloadUrl, bundleVersion, version, runtimeVersion },
157
+ }, options?.onStatusUpdate);
158
+ };
159
+ exports.installBundle = installBundle;
@@ -6,6 +6,7 @@ const bundleInfo_1 = require("../bundleInfo");
6
6
  const clientApi_1 = require("../api/clientApi");
7
7
  const bundleDropNative_1 = require("../native/bundleDropNative");
8
8
  const installId_1 = require("../fs/installId");
9
+ const userProperties_1 = require("../fs/userProperties");
9
10
  async function getReportingState() {
10
11
  const info = await (0, bundleInfo_1.readBundleInfo)();
11
12
  const path = await (0, bundleDropNative_1.getDownloadedBundlePathNative)();
@@ -27,12 +28,16 @@ async function reportInstalledIfReady(state) {
27
28
  if (info.lastInstalledReportedHash === info.hash)
28
29
  return;
29
30
  try {
30
- const installId = await (0, installId_1.getOrCreateInstallId)();
31
+ const [installId, userProperties] = await Promise.all([
32
+ (0, installId_1.getOrCreateInstallId)(),
33
+ (0, userProperties_1.getCurrentUserProperties)(),
34
+ ]);
31
35
  await (0, clientApi_1.reportInstalled)(context_1.config.project.slug, info.hash, {
32
36
  channelName: info.channelName,
33
37
  platform: info.platform,
34
38
  installId,
35
39
  runtimeVersion: info.runtimeVersion ?? context_1.runtimeVersion ?? null,
40
+ userProperties: Object.keys(userProperties).length > 0 ? userProperties : undefined,
36
41
  });
37
42
  await (0, bundleInfo_1.updateBundleInfo)({ lastInstalledReportedHash: info.hash });
38
43
  }
@@ -1,5 +1,17 @@
1
1
  import { BundleInfo } from '../bundleInfo';
2
- import type { UpdateCheckResponse } from '../api/types';
2
+ import type { UpdateCheckResponse, BundleListItem } from '../api/types';
3
3
  export declare function getAvailableChannels(): Promise<string[]>;
4
4
  export declare function checkForUpdate(channelName?: string, onStatusUpdate?: (status: string) => void): Promise<UpdateCheckResponse | null>;
5
5
  export declare function getInstalledBundleInfo(): Promise<BundleInfo | null>;
6
+ export type GetAvailableBundlesOptions = {
7
+ channelName?: string;
8
+ platform?: string;
9
+ limit?: number;
10
+ cursor?: string;
11
+ };
12
+ export type AvailableBundlesPage = {
13
+ items: BundleListItem[];
14
+ nextCursor: string | null;
15
+ hasMore: boolean;
16
+ };
17
+ export declare function getAvailableBundles(options?: GetAvailableBundlesOptions): Promise<AvailableBundlesPage>;
@@ -3,6 +3,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.getAvailableChannels = getAvailableChannels;
4
4
  exports.checkForUpdate = checkForUpdate;
5
5
  exports.getInstalledBundleInfo = getInstalledBundleInfo;
6
+ exports.getAvailableBundles = getAvailableBundles;
6
7
  const context_1 = require("../context");
7
8
  const bundleInfo_1 = require("../bundleInfo");
8
9
  const clientApi_1 = require("../api/clientApi");
@@ -96,3 +97,17 @@ async function checkForUpdate(channelName = context_2.defaultChannel, onStatusUp
96
97
  async function getInstalledBundleInfo() {
97
98
  return (0, bundleInfo_1.readBundleInfo)();
98
99
  }
100
+ async function getAvailableBundles(options) {
101
+ const { project } = context_1.config;
102
+ if (!project?.slug) {
103
+ throw new Error('Missing project slug in bundle.drop.config.js');
104
+ }
105
+ const channelName = options?.channelName || context_2.defaultChannel;
106
+ const res = await (0, clientApi_1.getBundleList)(project.slug, {
107
+ channelName,
108
+ platform: options?.platform || context_1.platform,
109
+ limit: options?.limit,
110
+ cursor: options?.cursor,
111
+ });
112
+ return res.data;
113
+ }
@@ -101,6 +101,31 @@ console.log(`đŸ“Ļ Bundling React Native code for platform: ${platform}...`);
101
101
  --bundle-output ${bundlePath} \
102
102
  --assets-dest ${assetsDir}`, { stdio: 'inherit' });
103
103
  console.log('✅ Bundle created:', bundlePath);
104
+ // đŸ”Ĩ Compile to Hermes bytecode if hermesc is available.
105
+ // The presence of the hermesc binary is the most reliable indicator that the
106
+ // project uses Hermes — config flag locations vary across RN versions.
107
+ // If hermesc is not found, the plain JS bundle is used (works on JSC).
108
+ const osBin = process.platform === 'darwin' ? 'osx-bin' : process.platform === 'win32' ? 'win64-bin' : 'linux64-bin';
109
+ const hermesLocations = [
110
+ path.join(projectRoot, 'node_modules', 'react-native', 'sdks', 'hermesc', osBin, 'hermesc'),
111
+ path.join(projectRoot, 'node_modules', 'hermes-engine', osBin, 'hermesc'),
112
+ ];
113
+ const hermescPath = hermesLocations.find(p => fs.existsSync(p));
114
+ if (hermescPath) {
115
+ console.log(`đŸ”Ĩ Compiling to Hermes bytecode (${platform})...`);
116
+ const hbcPath = bundlePath + '.hbc';
117
+ try {
118
+ (0, child_process_1.execSync)(`"${hermescPath}" -emit-binary -out "${hbcPath}" "${bundlePath}"`, { stdio: 'inherit' });
119
+ fs.renameSync(hbcPath, bundlePath);
120
+ console.log('✅ Hermes bytecode compiled successfully');
121
+ }
122
+ catch (e) {
123
+ console.warn('âš ī¸ Hermes compilation failed, falling back to plain JS bundle:', e.message);
124
+ }
125
+ }
126
+ else {
127
+ console.log('â„šī¸ hermesc not found — bundling plain JS (JSC or older RN)');
128
+ }
104
129
  // 📎 Create metadata
105
130
  const bundleBuffer = fs.readFileSync(bundlePath);
106
131
  const hash = (0, crypto_1.createHash)('sha256').update(bundleBuffer).digest('hex');
@@ -1,7 +1,8 @@
1
1
  import type { BundleInfo } from './bundleInfo';
2
+ import type { AvailableBundlesPage, GetAvailableBundlesOptions } from './manager/updateCheck';
2
3
  import { DownloadUpdateResult } from './manager/downloadAndInstall';
3
4
  import { ApplyUpdateResult } from './manager/updateState';
4
- import { UpdateCheckResponse } from './api/types';
5
+ import type { UpdateCheckResponse, BundleListItem } from './api/types';
5
6
  type UseBundleDropOptions = {
6
7
  /** Channel to target; defaults to config.defaultChannel or "General". */
7
8
  channelName?: string;
@@ -36,6 +37,13 @@ type UseBundleDropReturn = {
36
37
  fetchAvailableChannels: () => Promise<string[]>;
37
38
  /** Last fetched list of channel names. */
38
39
  availableChannels: string[];
40
+ /** Fetch a paginated list of downloadable bundles for a channel. */
41
+ fetchBundles: (options?: GetAvailableBundlesOptions) => Promise<AvailableBundlesPage>;
42
+ /** Download and stage a specific bundle by its metadata from fetchBundles. */
43
+ installBundle: (bundle: BundleListItem) => Promise<{
44
+ result: DownloadUpdateResult;
45
+ status?: string;
46
+ }>;
39
47
  };
40
48
  export declare function useBundleDrop(options?: UseBundleDropOptions): UseBundleDropReturn;
41
49
  export {};
@@ -124,6 +124,38 @@ function useBundleDrop(options) {
124
124
  setIsBusy(false);
125
125
  }
126
126
  }, [setAvailableChannels, setStatus]);
127
+ const fetchBundles = (0, react_1.useCallback)(async (options) => {
128
+ setIsBusy(true);
129
+ try {
130
+ return await (0, updateCheck_1.getAvailableBundles)({
131
+ channelName: options?.channelName || channelName,
132
+ ...options,
133
+ });
134
+ }
135
+ catch (e) {
136
+ setStatus('âš ī¸ Unable to fetch bundles.');
137
+ return { items: [], nextCursor: null, hasMore: false };
138
+ }
139
+ finally {
140
+ setIsBusy(false);
141
+ }
142
+ }, [channelName]);
143
+ const installBundleFromItem = (0, react_1.useCallback)(async (bundle) => {
144
+ if (!bundle.downloadUrl) {
145
+ const nextStatus = 'âš ī¸ Bundle is not downloadable (expired or unavailable)';
146
+ setStatus(nextStatus);
147
+ return { result: { status: 'incompatible' }, status: nextStatus };
148
+ }
149
+ return withBusy(async () => {
150
+ const result = await (0, downloadAndInstall_1.installBundle)(bundle.hash, bundle.downloadUrl, bundle.bundleVersion, bundle.version, bundle.runtimeVersion, { channelName, onStatusUpdate: msg => setStatus(msg) });
151
+ if (result.status === 'staged') {
152
+ const nextStatus = `✅ v${bundle.bundleVersion} downloaded. Will apply on next launch or when you call applyUpdate.`;
153
+ setStatus(nextStatus);
154
+ return { result, status: nextStatus };
155
+ }
156
+ return { result, status: undefined };
157
+ });
158
+ }, [channelName, withBusy]);
127
159
  (0, react_1.useEffect)(() => {
128
160
  refresh();
129
161
  if (!(0, initUpdateManager_1.isUpdateFlowActive)()) {
@@ -141,5 +173,7 @@ function useBundleDrop(options) {
141
173
  applyUpdate,
142
174
  fetchAvailableChannels,
143
175
  availableChannels,
176
+ fetchBundles,
177
+ installBundle: installBundleFromItem,
144
178
  };
145
179
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@gfean/react-native-bundle-drop",
3
- "version": "0.2.0",
3
+ "version": "0.2.2",
4
4
  "description": "react native ota by gFean",
5
5
  "main": "lib/index.js",
6
6
  "types": "lib/index.d.ts",