@gfean/react-native-bundle-drop 0.1.97 → 0.2.1
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/lib/CLI/scripts/init-config.d.ts +2 -0
- package/lib/CLI/scripts/init-config.js +10 -2
- package/lib/CLI/scripts/login-cli.js +256 -37
- package/lib/api/clientApi.d.ts +2 -1
- package/lib/api/clientApi.js +14 -0
- package/lib/api/types.d.ts +23 -1
- package/lib/context.d.ts +20 -0
- package/lib/context.js +15 -1
- package/lib/fs/userProperties.d.ts +5 -4
- package/lib/fs/userProperties.js +27 -38
- package/lib/index.d.ts +7 -2
- package/lib/index.js +5 -1
- package/lib/manager/downloadAndInstall.d.ts +5 -0
- package/lib/manager/downloadAndInstall.js +8 -1
- package/lib/manager/reporting.js +6 -1
- package/lib/manager/updateCheck.d.ts +13 -1
- package/lib/manager/updateCheck.js +15 -0
- package/lib/useBundleDrop.d.ts +9 -1
- package/lib/useBundleDrop.js +34 -0
- package/package.json +1 -1
|
@@ -8,6 +8,8 @@ type Org = {
|
|
|
8
8
|
orgId: string;
|
|
9
9
|
name: string;
|
|
10
10
|
};
|
|
11
|
+
export declare function getBundleDropConfigPath(startDir?: string): string;
|
|
12
|
+
export declare function hasExistingBundleDropConfig(startDir?: string): boolean;
|
|
11
13
|
export declare function initConfig(params: {
|
|
12
14
|
serverUrl: string;
|
|
13
15
|
projects: Project[];
|
|
@@ -3,6 +3,8 @@ 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.getBundleDropConfigPath = getBundleDropConfigPath;
|
|
7
|
+
exports.hasExistingBundleDropConfig = hasExistingBundleDropConfig;
|
|
6
8
|
exports.initConfig = initConfig;
|
|
7
9
|
const axios_1 = __importDefault(require("axios"));
|
|
8
10
|
const chalk_1 = __importDefault(require("chalk"));
|
|
@@ -43,9 +45,15 @@ function findProjectRoot(startDir) {
|
|
|
43
45
|
}
|
|
44
46
|
return startDir;
|
|
45
47
|
}
|
|
48
|
+
function getBundleDropConfigPath(startDir = process.cwd()) {
|
|
49
|
+
const projectRoot = findProjectRoot(startDir);
|
|
50
|
+
return path_1.default.join(projectRoot, 'bundle.drop.config.js');
|
|
51
|
+
}
|
|
52
|
+
function hasExistingBundleDropConfig(startDir = process.cwd()) {
|
|
53
|
+
return fs_extra_1.default.existsSync(getBundleDropConfigPath(startDir));
|
|
54
|
+
}
|
|
46
55
|
async function initConfig(params) {
|
|
47
|
-
const
|
|
48
|
-
const configPath = path_1.default.join(projectRoot, 'bundle.drop.config.js');
|
|
56
|
+
const configPath = getBundleDropConfigPath();
|
|
49
57
|
if (fs_extra_1.default.existsSync(configPath)) {
|
|
50
58
|
console.log(chalk_1.default.yellow(`ℹ️ bundle.drop.config.js already exists at ${configPath}. If this is accidental, delete it and rerun the init/login.`));
|
|
51
59
|
return;
|
|
@@ -3,58 +3,277 @@ 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
|
-
// src/CLI/scripts/login-cli.ts
|
|
7
6
|
const axios_1 = __importDefault(require("axios"));
|
|
8
7
|
const chalk_1 = __importDefault(require("chalk"));
|
|
9
8
|
const fs_extra_1 = __importDefault(require("fs-extra"));
|
|
9
|
+
const http_1 = __importDefault(require("http"));
|
|
10
10
|
const os_1 = __importDefault(require("os"));
|
|
11
11
|
const path_1 = __importDefault(require("path"));
|
|
12
12
|
const prompts_1 = __importDefault(require("prompts"));
|
|
13
|
+
const child_process_1 = require("child_process");
|
|
13
14
|
const init_config_1 = require("./init-config");
|
|
14
15
|
const post_init_1 = require("./post-init");
|
|
15
|
-
const
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
16
|
+
const LOGIN_TIMEOUT_MS = 10 * 60 * 1000;
|
|
17
|
+
const getBaseUrl = () => process.env.BUNDLE_DROP_SERVER_URL
|
|
18
|
+
? process.env.BUNDLE_DROP_SERVER_URL.replace(/\/$/, '')
|
|
19
|
+
: 'https://api.bundledrop.app';
|
|
20
|
+
const getClientName = () => {
|
|
21
|
+
const hostname = os_1.default.hostname();
|
|
22
|
+
const termProgram = (process.env.TERM_PROGRAM || '').toLowerCase();
|
|
23
|
+
const term = (process.env.TERM || '').toLowerCase();
|
|
24
|
+
if (process.env.CURSOR_TRACE_ID || process.env.CURSOR_AGENT) {
|
|
25
|
+
return `Cursor on ${hostname}`;
|
|
26
|
+
}
|
|
27
|
+
if (process.env.VSCODE_GIT_IPC_HANDLE || termProgram === 'vscode') {
|
|
28
|
+
return `VS Code on ${hostname}`;
|
|
29
|
+
}
|
|
30
|
+
if (termProgram.includes('warp')) {
|
|
31
|
+
return `Warp on ${hostname}`;
|
|
32
|
+
}
|
|
33
|
+
if (term.includes('windsurf')) {
|
|
34
|
+
return `Windsurf on ${hostname}`;
|
|
35
|
+
}
|
|
36
|
+
return `your IDE on ${hostname}`;
|
|
37
|
+
};
|
|
38
|
+
const openBrowser = async (url) => {
|
|
39
|
+
const platform = process.platform;
|
|
40
|
+
const command = platform === 'darwin'
|
|
41
|
+
? { file: 'open', args: [url] }
|
|
42
|
+
: platform === 'win32'
|
|
43
|
+
? { file: 'cmd', args: ['/c', 'start', '', url] }
|
|
44
|
+
: { file: 'xdg-open', args: [url] };
|
|
45
|
+
await new Promise((resolve, reject) => {
|
|
46
|
+
const child = (0, child_process_1.spawn)(command.file, command.args, {
|
|
47
|
+
detached: true,
|
|
48
|
+
stdio: 'ignore',
|
|
49
|
+
});
|
|
50
|
+
child.once('error', reject);
|
|
51
|
+
child.once('spawn', () => resolve());
|
|
52
|
+
child.unref();
|
|
53
|
+
});
|
|
54
|
+
};
|
|
55
|
+
const writeAuthFile = async ({ payload, serverUrl, }) => {
|
|
56
|
+
const tokenPath = path_1.default.join(os_1.default.homedir(), '.bundle-drop', 'auth.json');
|
|
57
|
+
const authFile = {
|
|
58
|
+
token: payload.token,
|
|
59
|
+
user: {
|
|
60
|
+
email: payload.email,
|
|
61
|
+
firstName: payload.firstName,
|
|
62
|
+
lastName: payload.lastName,
|
|
26
63
|
},
|
|
27
|
-
|
|
64
|
+
projects: payload.projects || [],
|
|
65
|
+
organizations: payload.organizations || [],
|
|
66
|
+
memberships: payload.memberships || [],
|
|
67
|
+
downloadApiKey: payload.downloadApiKey || '',
|
|
68
|
+
serverUrl,
|
|
69
|
+
};
|
|
70
|
+
await fs_extra_1.default.ensureDir(path_1.default.dirname(tokenPath));
|
|
71
|
+
await fs_extra_1.default.writeJson(tokenPath, authFile, { spaces: 2 });
|
|
72
|
+
return authFile;
|
|
73
|
+
};
|
|
74
|
+
const respondJson = (res, statusCode, body) => {
|
|
75
|
+
res.writeHead(statusCode, {
|
|
76
|
+
'Content-Type': 'application/json',
|
|
77
|
+
Connection: 'close',
|
|
78
|
+
'Access-Control-Allow-Origin': '*',
|
|
79
|
+
'Access-Control-Allow-Methods': 'POST, OPTIONS',
|
|
80
|
+
'Access-Control-Allow-Headers': 'Content-Type',
|
|
81
|
+
});
|
|
82
|
+
res.end(JSON.stringify(body));
|
|
83
|
+
};
|
|
84
|
+
const readJsonBody = (req) => new Promise((resolve, reject) => {
|
|
85
|
+
let raw = '';
|
|
86
|
+
req.setEncoding('utf8');
|
|
87
|
+
req.on('data', chunk => {
|
|
88
|
+
raw += chunk;
|
|
89
|
+
if (raw.length > 20000) {
|
|
90
|
+
reject(new Error('CLI callback payload is too large'));
|
|
91
|
+
req.destroy();
|
|
92
|
+
}
|
|
93
|
+
});
|
|
94
|
+
req.on('end', () => resolve(raw));
|
|
95
|
+
req.on('error', reject);
|
|
96
|
+
});
|
|
97
|
+
const createLoginSession = async ({ baseUrl, clientName, callbackUrl, }) => {
|
|
98
|
+
const response = await axios_1.default.post(`${baseUrl}/auth/cli/sessions`, {
|
|
99
|
+
clientName,
|
|
100
|
+
callbackUrl,
|
|
101
|
+
});
|
|
102
|
+
return response.data;
|
|
103
|
+
};
|
|
104
|
+
const exchangeSession = async ({ baseUrl, payload, }) => {
|
|
105
|
+
const response = await axios_1.default.post(`${baseUrl}/auth/cli/exchange`, payload);
|
|
106
|
+
return response.data;
|
|
107
|
+
};
|
|
108
|
+
const waitForExchangeWithTimeout = (exchangePromise) => new Promise((resolve, reject) => {
|
|
109
|
+
const timeout = setTimeout(() => {
|
|
110
|
+
reject(new Error('Timed out waiting for browser authorization'));
|
|
111
|
+
}, LOGIN_TIMEOUT_MS);
|
|
112
|
+
timeout.unref();
|
|
113
|
+
exchangePromise.then(payload => {
|
|
114
|
+
clearTimeout(timeout);
|
|
115
|
+
resolve(payload);
|
|
116
|
+
}, error => {
|
|
117
|
+
clearTimeout(timeout);
|
|
118
|
+
reject(error);
|
|
119
|
+
});
|
|
120
|
+
});
|
|
121
|
+
const startCallbackServer = ({ baseUrl, }) => new Promise((resolve, reject) => {
|
|
122
|
+
let settled = false;
|
|
123
|
+
let exchangeInFlight = false;
|
|
124
|
+
let exchangeResolve = null;
|
|
125
|
+
let exchangeReject = null;
|
|
126
|
+
const sockets = new Set();
|
|
127
|
+
const exchangePromise = new Promise((innerResolve, innerReject) => {
|
|
128
|
+
exchangeResolve = innerResolve;
|
|
129
|
+
exchangeReject = innerReject;
|
|
130
|
+
});
|
|
131
|
+
const server = http_1.default.createServer(async (req, res) => {
|
|
132
|
+
if (req.method === 'OPTIONS') {
|
|
133
|
+
res.writeHead(204, {
|
|
134
|
+
'Access-Control-Allow-Origin': '*',
|
|
135
|
+
'Access-Control-Allow-Methods': 'POST, OPTIONS',
|
|
136
|
+
'Access-Control-Allow-Headers': 'Content-Type',
|
|
137
|
+
});
|
|
138
|
+
res.end();
|
|
139
|
+
return;
|
|
140
|
+
}
|
|
141
|
+
if (req.method !== 'POST' || req.url !== '/callback') {
|
|
142
|
+
respondJson(res, 404, { error: 'Not found' });
|
|
143
|
+
return;
|
|
144
|
+
}
|
|
145
|
+
if (exchangeInFlight) {
|
|
146
|
+
respondJson(res, 409, { error: 'CLI login is already being completed' });
|
|
147
|
+
return;
|
|
148
|
+
}
|
|
149
|
+
exchangeInFlight = true;
|
|
150
|
+
try {
|
|
151
|
+
const rawBody = await readJsonBody(req);
|
|
152
|
+
const parsed = JSON.parse(rawBody || '{}');
|
|
153
|
+
const sessionId = typeof parsed.sessionId === 'string' ? parsed.sessionId.trim() : '';
|
|
154
|
+
const state = typeof parsed.state === 'string' ? parsed.state.trim() : '';
|
|
155
|
+
const exchangeCode = typeof parsed.exchangeCode === 'string' ? parsed.exchangeCode.trim() : '';
|
|
156
|
+
if (!sessionId || !state || !exchangeCode) {
|
|
157
|
+
throw new Error('Missing CLI login callback payload');
|
|
158
|
+
}
|
|
159
|
+
const authPayload = await exchangeSession({
|
|
160
|
+
baseUrl,
|
|
161
|
+
payload: { sessionId, state, exchangeCode },
|
|
162
|
+
});
|
|
163
|
+
respondJson(res, 200, { ok: true });
|
|
164
|
+
exchangeResolve?.(authPayload);
|
|
165
|
+
}
|
|
166
|
+
catch (error) {
|
|
167
|
+
const message = axios_1.default.isAxiosError(error)
|
|
168
|
+
? error.response?.data?.error || error.message
|
|
169
|
+
: error.message;
|
|
170
|
+
respondJson(res, 400, { error: message });
|
|
171
|
+
exchangeReject?.(new Error(message));
|
|
172
|
+
}
|
|
173
|
+
finally {
|
|
174
|
+
exchangeInFlight = false;
|
|
175
|
+
}
|
|
176
|
+
});
|
|
177
|
+
server.on('error', reject);
|
|
178
|
+
server.on('connection', socket => {
|
|
179
|
+
sockets.add(socket);
|
|
180
|
+
socket.on('close', () => {
|
|
181
|
+
sockets.delete(socket);
|
|
182
|
+
});
|
|
183
|
+
});
|
|
184
|
+
server.keepAliveTimeout = 1;
|
|
185
|
+
server.listen(0, '127.0.0.1', () => {
|
|
186
|
+
const address = server.address();
|
|
187
|
+
if (!address) {
|
|
188
|
+
reject(new Error('Unable to start the local CLI callback server'));
|
|
189
|
+
return;
|
|
190
|
+
}
|
|
191
|
+
settled = true;
|
|
192
|
+
const callbackUrl = `http://127.0.0.1:${address.port}/callback`;
|
|
193
|
+
resolve({
|
|
194
|
+
callbackUrl,
|
|
195
|
+
waitForExchange: () => exchangePromise,
|
|
196
|
+
close: () => new Promise((innerResolve, innerReject) => {
|
|
197
|
+
server.close(error => {
|
|
198
|
+
if (error) {
|
|
199
|
+
innerReject(error);
|
|
200
|
+
return;
|
|
201
|
+
}
|
|
202
|
+
innerResolve();
|
|
203
|
+
});
|
|
204
|
+
sockets.forEach(socket => {
|
|
205
|
+
socket.destroy();
|
|
206
|
+
});
|
|
207
|
+
}),
|
|
208
|
+
});
|
|
209
|
+
});
|
|
210
|
+
const startupTimeout = setTimeout(() => {
|
|
211
|
+
if (!settled) {
|
|
212
|
+
reject(new Error('Timed out while starting the local CLI callback server'));
|
|
213
|
+
}
|
|
214
|
+
}, 5000);
|
|
215
|
+
startupTimeout.unref();
|
|
216
|
+
});
|
|
217
|
+
const login = async () => {
|
|
218
|
+
const { shouldOpenBrowser } = await (0, prompts_1.default)({
|
|
219
|
+
type: 'confirm',
|
|
220
|
+
name: 'shouldOpenBrowser',
|
|
221
|
+
message: 'Open the browser to sign in?',
|
|
222
|
+
initial: true,
|
|
223
|
+
});
|
|
224
|
+
if (shouldOpenBrowser === false) {
|
|
225
|
+
console.log(chalk_1.default.gray('A sign-in URL will be printed. Open it manually in your browser.'));
|
|
226
|
+
}
|
|
227
|
+
const baseUrl = getBaseUrl();
|
|
228
|
+
const clientName = getClientName();
|
|
229
|
+
let serverHandle;
|
|
28
230
|
try {
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
email,
|
|
35
|
-
password,
|
|
231
|
+
serverHandle = await startCallbackServer({ baseUrl });
|
|
232
|
+
const session = await createLoginSession({
|
|
233
|
+
baseUrl,
|
|
234
|
+
clientName,
|
|
235
|
+
callbackUrl: serverHandle.callbackUrl,
|
|
36
236
|
});
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
237
|
+
console.log(chalk_1.default.cyan(`Signing in for ${clientName}`));
|
|
238
|
+
console.log(chalk_1.default.gray(`If the browser does not open, use this URL:\n${session.authorizeUrl}`));
|
|
239
|
+
if (shouldOpenBrowser !== false) {
|
|
240
|
+
try {
|
|
241
|
+
await openBrowser(session.authorizeUrl);
|
|
242
|
+
}
|
|
243
|
+
catch (error) {
|
|
244
|
+
console.log(chalk_1.default.yellow(`Could not open the browser automatically. Open this URL manually:\n${session.authorizeUrl}`));
|
|
245
|
+
}
|
|
246
|
+
}
|
|
247
|
+
const exchangePromise = serverHandle.waitForExchange();
|
|
248
|
+
const authPayload = await waitForExchangeWithTimeout(exchangePromise);
|
|
249
|
+
const authFile = await writeAuthFile({
|
|
250
|
+
payload: authPayload,
|
|
48
251
|
serverUrl: baseUrl,
|
|
49
252
|
});
|
|
50
|
-
console.log(chalk_1.default.green('✅ Logged in successfully as:'), chalk_1.default.cyan(`${firstName} ${lastName}`));
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
253
|
+
console.log(chalk_1.default.green('✅ Logged in successfully as:'), chalk_1.default.cyan(`${authFile.user.firstName} ${authFile.user.lastName}`));
|
|
254
|
+
if ((0, init_config_1.hasExistingBundleDropConfig)()) {
|
|
255
|
+
console.log(chalk_1.default.gray(`ℹ️ Found existing bundle.drop.config.js at ${(0, init_config_1.getBundleDropConfigPath)()}. Skipping setup prompts.`));
|
|
256
|
+
return;
|
|
257
|
+
}
|
|
258
|
+
await (0, init_config_1.initConfig)({
|
|
259
|
+
serverUrl: baseUrl,
|
|
260
|
+
projects: authFile.projects,
|
|
261
|
+
organizations: authFile.organizations,
|
|
262
|
+
downloadApiKey: authFile.downloadApiKey,
|
|
263
|
+
authToken: authFile.token,
|
|
264
|
+
});
|
|
54
265
|
await (0, post_init_1.runPostInitPrompts)();
|
|
55
266
|
}
|
|
56
|
-
catch (
|
|
57
|
-
|
|
267
|
+
catch (error) {
|
|
268
|
+
const message = axios_1.default.isAxiosError(error)
|
|
269
|
+
? error.response?.data?.error || error.message
|
|
270
|
+
: error.message;
|
|
271
|
+
console.error(chalk_1.default.red('❌ Login failed:'), message);
|
|
272
|
+
}
|
|
273
|
+
finally {
|
|
274
|
+
if (serverHandle) {
|
|
275
|
+
await serverHandle.close().catch(() => undefined);
|
|
276
|
+
}
|
|
58
277
|
}
|
|
59
278
|
};
|
|
60
279
|
exports.default = login;
|
package/lib/api/clientApi.d.ts
CHANGED
|
@@ -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>>;
|
package/lib/api/clientApi.js
CHANGED
|
@@ -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
|
+
}
|
package/lib/api/types.d.ts
CHANGED
|
@@ -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(
|
|
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;
|
package/lib/fs/userProperties.js
CHANGED
|
@@ -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
|
-
|
|
44
|
-
|
|
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
|
-
|
|
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
|
|
61
|
-
if (!
|
|
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
|
|
54
|
+
if (existing[trimmedKey] === value) {
|
|
66
55
|
return existing;
|
|
67
56
|
}
|
|
68
|
-
const next =
|
|
57
|
+
const next = { ...existing, [trimmedKey]: value };
|
|
69
58
|
await writeUserProperties(next);
|
|
70
59
|
return next;
|
|
71
60
|
}
|
|
72
|
-
async function removeUserProperty(
|
|
73
|
-
const
|
|
74
|
-
if (!
|
|
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
|
-
|
|
79
|
-
if (next.length === existing.length) {
|
|
67
|
+
if (!(trimmedKey in existing)) {
|
|
80
68
|
return existing;
|
|
81
69
|
}
|
|
82
|
-
|
|
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
|
-
|
|
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 {
|
|
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;
|
package/lib/manager/reporting.js
CHANGED
|
@@ -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
|
|
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
|
+
}
|
package/lib/useBundleDrop.d.ts
CHANGED
|
@@ -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 {};
|
package/lib/useBundleDrop.js
CHANGED
|
@@ -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
|
}
|