@gfean/react-native-bundle-drop 0.2.2 → 0.3.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.
- package/CLIENT_README.md +47 -17
- package/README.md +45 -22
- package/lib/CLI/cli.d.ts +2 -1
- package/lib/CLI/cli.js +141 -130
- package/lib/CLI/scripts/init-native-config.d.ts +16 -0
- package/lib/CLI/scripts/init-native-config.js +11 -0
- package/lib/CLI/scripts/login-cli.d.ts +71 -0
- package/lib/CLI/scripts/login-cli.js +24 -13
- package/lib/CLI/scripts/upload-cli.js +2 -1
- package/lib/api/types.d.ts +29 -0
- package/lib/index.d.ts +16 -4
- package/lib/index.js +25 -15
- package/lib/manager/downloadAndInstall.d.ts +2 -0
- package/lib/manager/reporting.js +3 -0
- package/lib/manager/updateCheck.d.ts +13 -0
- package/lib/manager/updateCheck.js +6 -0
- package/lib/manager/updateState.d.ts +2 -0
- package/lib/manager/updateState.js +10 -4
- package/lib/runtime/initState.d.ts +48 -0
- package/lib/runtime/initState.js +131 -0
- package/lib/runtime/service.d.ts +111 -0
- package/lib/runtime/service.js +537 -0
- package/lib/scripts/bundle.d.ts +13 -1
- package/lib/scripts/bundle.js +126 -115
- package/lib/scripts/download-bundle.d.ts +4 -1
- package/lib/scripts/download-bundle.js +41 -33
- package/lib/scripts/upload-bundle.d.ts +7 -1
- package/lib/scripts/upload-bundle.js +183 -175
- package/lib/useBundleDrop.d.ts +19 -9
- package/lib/useBundleDrop.js +26 -172
- package/package.json +13 -2
- package/lib/manager/initUpdateManager.d.ts +0 -10
- package/lib/manager/initUpdateManager.js +0 -137
|
@@ -1,2 +1,73 @@
|
|
|
1
|
+
import { IncomingMessage, ServerResponse } from 'http';
|
|
2
|
+
type CliSessionResponse = {
|
|
3
|
+
sessionId: string;
|
|
4
|
+
state: string;
|
|
5
|
+
authorizeUrl: string;
|
|
6
|
+
expiresAt: string;
|
|
7
|
+
};
|
|
8
|
+
type Project = {
|
|
9
|
+
name: string;
|
|
10
|
+
slug: string;
|
|
11
|
+
orgId: string;
|
|
12
|
+
};
|
|
13
|
+
type Org = {
|
|
14
|
+
slug: string;
|
|
15
|
+
orgId: string;
|
|
16
|
+
name: string;
|
|
17
|
+
};
|
|
18
|
+
type CliExchangeResponse = {
|
|
19
|
+
token: string;
|
|
20
|
+
email: string;
|
|
21
|
+
firstName: string;
|
|
22
|
+
lastName: string;
|
|
23
|
+
projects?: Project[];
|
|
24
|
+
organizations?: Org[];
|
|
25
|
+
memberships?: unknown[];
|
|
26
|
+
downloadApiKey?: string;
|
|
27
|
+
};
|
|
28
|
+
type CallbackPayload = {
|
|
29
|
+
sessionId: string;
|
|
30
|
+
state: string;
|
|
31
|
+
exchangeCode: string;
|
|
32
|
+
};
|
|
33
|
+
type AuthFilePayload = {
|
|
34
|
+
token: string;
|
|
35
|
+
user: {
|
|
36
|
+
email: string;
|
|
37
|
+
firstName: string;
|
|
38
|
+
lastName: string;
|
|
39
|
+
};
|
|
40
|
+
projects: Project[];
|
|
41
|
+
organizations: Org[];
|
|
42
|
+
memberships: unknown[];
|
|
43
|
+
downloadApiKey: string;
|
|
44
|
+
serverUrl: string;
|
|
45
|
+
};
|
|
46
|
+
export declare const getBaseUrl: () => string;
|
|
47
|
+
export declare const getClientName: () => string;
|
|
48
|
+
export declare const openBrowser: (url: string) => Promise<void>;
|
|
49
|
+
export declare const writeAuthFile: ({ payload, serverUrl, }: {
|
|
50
|
+
payload: CliExchangeResponse;
|
|
51
|
+
serverUrl: string;
|
|
52
|
+
}) => Promise<AuthFilePayload>;
|
|
53
|
+
export declare const respondJson: (res: ServerResponse, statusCode: number, body: Record<string, unknown>) => void;
|
|
54
|
+
export declare const readJsonBody: (req: IncomingMessage) => Promise<string>;
|
|
55
|
+
export declare const createLoginSession: ({ baseUrl, clientName, callbackUrl, }: {
|
|
56
|
+
baseUrl: string;
|
|
57
|
+
clientName: string;
|
|
58
|
+
callbackUrl: string;
|
|
59
|
+
}) => Promise<CliSessionResponse>;
|
|
60
|
+
export declare const exchangeSession: ({ baseUrl, payload, }: {
|
|
61
|
+
baseUrl: string;
|
|
62
|
+
payload: CallbackPayload;
|
|
63
|
+
}) => Promise<CliExchangeResponse>;
|
|
64
|
+
export declare const waitForExchangeWithTimeout: (exchangePromise: Promise<CliExchangeResponse>) => Promise<CliExchangeResponse>;
|
|
65
|
+
export declare const startCallbackServer: ({ baseUrl, }: {
|
|
66
|
+
baseUrl: string;
|
|
67
|
+
}) => Promise<{
|
|
68
|
+
callbackUrl: string;
|
|
69
|
+
waitForExchange: () => Promise<CliExchangeResponse>;
|
|
70
|
+
close: () => Promise<void>;
|
|
71
|
+
}>;
|
|
1
72
|
declare const login: () => Promise<void>;
|
|
2
73
|
export default login;
|
|
@@ -3,6 +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.startCallbackServer = exports.waitForExchangeWithTimeout = exports.exchangeSession = exports.createLoginSession = exports.readJsonBody = exports.respondJson = exports.writeAuthFile = exports.openBrowser = exports.getClientName = exports.getBaseUrl = void 0;
|
|
6
7
|
const axios_1 = __importDefault(require("axios"));
|
|
7
8
|
const chalk_1 = __importDefault(require("chalk"));
|
|
8
9
|
const fs_extra_1 = __importDefault(require("fs-extra"));
|
|
@@ -17,6 +18,7 @@ const LOGIN_TIMEOUT_MS = 10 * 60 * 1000;
|
|
|
17
18
|
const getBaseUrl = () => process.env.BUNDLE_DROP_SERVER_URL
|
|
18
19
|
? process.env.BUNDLE_DROP_SERVER_URL.replace(/\/$/, '')
|
|
19
20
|
: 'https://api.bundledrop.app';
|
|
21
|
+
exports.getBaseUrl = getBaseUrl;
|
|
20
22
|
const getClientName = () => {
|
|
21
23
|
const hostname = os_1.default.hostname();
|
|
22
24
|
const termProgram = (process.env.TERM_PROGRAM || '').toLowerCase();
|
|
@@ -35,6 +37,7 @@ const getClientName = () => {
|
|
|
35
37
|
}
|
|
36
38
|
return `your IDE on ${hostname}`;
|
|
37
39
|
};
|
|
40
|
+
exports.getClientName = getClientName;
|
|
38
41
|
const openBrowser = async (url) => {
|
|
39
42
|
const platform = process.platform;
|
|
40
43
|
const command = platform === 'darwin'
|
|
@@ -52,6 +55,7 @@ const openBrowser = async (url) => {
|
|
|
52
55
|
child.unref();
|
|
53
56
|
});
|
|
54
57
|
};
|
|
58
|
+
exports.openBrowser = openBrowser;
|
|
55
59
|
const writeAuthFile = async ({ payload, serverUrl, }) => {
|
|
56
60
|
const tokenPath = path_1.default.join(os_1.default.homedir(), '.bundle-drop', 'auth.json');
|
|
57
61
|
const authFile = {
|
|
@@ -71,6 +75,7 @@ const writeAuthFile = async ({ payload, serverUrl, }) => {
|
|
|
71
75
|
await fs_extra_1.default.writeJson(tokenPath, authFile, { spaces: 2 });
|
|
72
76
|
return authFile;
|
|
73
77
|
};
|
|
78
|
+
exports.writeAuthFile = writeAuthFile;
|
|
74
79
|
const respondJson = (res, statusCode, body) => {
|
|
75
80
|
res.writeHead(statusCode, {
|
|
76
81
|
'Content-Type': 'application/json',
|
|
@@ -81,6 +86,7 @@ const respondJson = (res, statusCode, body) => {
|
|
|
81
86
|
});
|
|
82
87
|
res.end(JSON.stringify(body));
|
|
83
88
|
};
|
|
89
|
+
exports.respondJson = respondJson;
|
|
84
90
|
const readJsonBody = (req) => new Promise((resolve, reject) => {
|
|
85
91
|
let raw = '';
|
|
86
92
|
req.setEncoding('utf8');
|
|
@@ -94,6 +100,7 @@ const readJsonBody = (req) => new Promise((resolve, reject) => {
|
|
|
94
100
|
req.on('end', () => resolve(raw));
|
|
95
101
|
req.on('error', reject);
|
|
96
102
|
});
|
|
103
|
+
exports.readJsonBody = readJsonBody;
|
|
97
104
|
const createLoginSession = async ({ baseUrl, clientName, callbackUrl, }) => {
|
|
98
105
|
const response = await axios_1.default.post(`${baseUrl}/auth/cli/sessions`, {
|
|
99
106
|
clientName,
|
|
@@ -101,10 +108,12 @@ const createLoginSession = async ({ baseUrl, clientName, callbackUrl, }) => {
|
|
|
101
108
|
});
|
|
102
109
|
return response.data;
|
|
103
110
|
};
|
|
111
|
+
exports.createLoginSession = createLoginSession;
|
|
104
112
|
const exchangeSession = async ({ baseUrl, payload, }) => {
|
|
105
113
|
const response = await axios_1.default.post(`${baseUrl}/auth/cli/exchange`, payload);
|
|
106
114
|
return response.data;
|
|
107
115
|
};
|
|
116
|
+
exports.exchangeSession = exchangeSession;
|
|
108
117
|
const waitForExchangeWithTimeout = (exchangePromise) => new Promise((resolve, reject) => {
|
|
109
118
|
const timeout = setTimeout(() => {
|
|
110
119
|
reject(new Error('Timed out waiting for browser authorization'));
|
|
@@ -118,6 +127,7 @@ const waitForExchangeWithTimeout = (exchangePromise) => new Promise((resolve, re
|
|
|
118
127
|
reject(error);
|
|
119
128
|
});
|
|
120
129
|
});
|
|
130
|
+
exports.waitForExchangeWithTimeout = waitForExchangeWithTimeout;
|
|
121
131
|
const startCallbackServer = ({ baseUrl, }) => new Promise((resolve, reject) => {
|
|
122
132
|
let settled = false;
|
|
123
133
|
let exchangeInFlight = false;
|
|
@@ -139,16 +149,16 @@ const startCallbackServer = ({ baseUrl, }) => new Promise((resolve, reject) => {
|
|
|
139
149
|
return;
|
|
140
150
|
}
|
|
141
151
|
if (req.method !== 'POST' || req.url !== '/callback') {
|
|
142
|
-
respondJson(res, 404, { error: 'Not found' });
|
|
152
|
+
(0, exports.respondJson)(res, 404, { error: 'Not found' });
|
|
143
153
|
return;
|
|
144
154
|
}
|
|
145
155
|
if (exchangeInFlight) {
|
|
146
|
-
respondJson(res, 409, { error: 'CLI login is already being completed' });
|
|
156
|
+
(0, exports.respondJson)(res, 409, { error: 'CLI login is already being completed' });
|
|
147
157
|
return;
|
|
148
158
|
}
|
|
149
159
|
exchangeInFlight = true;
|
|
150
160
|
try {
|
|
151
|
-
const rawBody = await readJsonBody(req);
|
|
161
|
+
const rawBody = await (0, exports.readJsonBody)(req);
|
|
152
162
|
const parsed = JSON.parse(rawBody || '{}');
|
|
153
163
|
const sessionId = typeof parsed.sessionId === 'string' ? parsed.sessionId.trim() : '';
|
|
154
164
|
const state = typeof parsed.state === 'string' ? parsed.state.trim() : '';
|
|
@@ -156,18 +166,18 @@ const startCallbackServer = ({ baseUrl, }) => new Promise((resolve, reject) => {
|
|
|
156
166
|
if (!sessionId || !state || !exchangeCode) {
|
|
157
167
|
throw new Error('Missing CLI login callback payload');
|
|
158
168
|
}
|
|
159
|
-
const authPayload = await exchangeSession({
|
|
169
|
+
const authPayload = await (0, exports.exchangeSession)({
|
|
160
170
|
baseUrl,
|
|
161
171
|
payload: { sessionId, state, exchangeCode },
|
|
162
172
|
});
|
|
163
|
-
respondJson(res, 200, { ok: true });
|
|
173
|
+
(0, exports.respondJson)(res, 200, { ok: true });
|
|
164
174
|
exchangeResolve?.(authPayload);
|
|
165
175
|
}
|
|
166
176
|
catch (error) {
|
|
167
177
|
const message = axios_1.default.isAxiosError(error)
|
|
168
178
|
? error.response?.data?.error || error.message
|
|
169
179
|
: error.message;
|
|
170
|
-
respondJson(res, 400, { error: message });
|
|
180
|
+
(0, exports.respondJson)(res, 400, { error: message });
|
|
171
181
|
exchangeReject?.(new Error(message));
|
|
172
182
|
}
|
|
173
183
|
finally {
|
|
@@ -214,6 +224,7 @@ const startCallbackServer = ({ baseUrl, }) => new Promise((resolve, reject) => {
|
|
|
214
224
|
}, 5000);
|
|
215
225
|
startupTimeout.unref();
|
|
216
226
|
});
|
|
227
|
+
exports.startCallbackServer = startCallbackServer;
|
|
217
228
|
const login = async () => {
|
|
218
229
|
const { shouldOpenBrowser } = await (0, prompts_1.default)({
|
|
219
230
|
type: 'confirm',
|
|
@@ -224,12 +235,12 @@ const login = async () => {
|
|
|
224
235
|
if (shouldOpenBrowser === false) {
|
|
225
236
|
console.log(chalk_1.default.gray('A sign-in URL will be printed. Open it manually in your browser.'));
|
|
226
237
|
}
|
|
227
|
-
const baseUrl = getBaseUrl();
|
|
228
|
-
const clientName = getClientName();
|
|
238
|
+
const baseUrl = (0, exports.getBaseUrl)();
|
|
239
|
+
const clientName = (0, exports.getClientName)();
|
|
229
240
|
let serverHandle;
|
|
230
241
|
try {
|
|
231
|
-
serverHandle = await startCallbackServer({ baseUrl });
|
|
232
|
-
const session = await createLoginSession({
|
|
242
|
+
serverHandle = await (0, exports.startCallbackServer)({ baseUrl });
|
|
243
|
+
const session = await (0, exports.createLoginSession)({
|
|
233
244
|
baseUrl,
|
|
234
245
|
clientName,
|
|
235
246
|
callbackUrl: serverHandle.callbackUrl,
|
|
@@ -238,15 +249,15 @@ const login = async () => {
|
|
|
238
249
|
console.log(chalk_1.default.gray(`If the browser does not open, use this URL:\n${session.authorizeUrl}`));
|
|
239
250
|
if (shouldOpenBrowser !== false) {
|
|
240
251
|
try {
|
|
241
|
-
await openBrowser(session.authorizeUrl);
|
|
252
|
+
await (0, exports.openBrowser)(session.authorizeUrl);
|
|
242
253
|
}
|
|
243
254
|
catch (error) {
|
|
244
255
|
console.log(chalk_1.default.yellow(`Could not open the browser automatically. Open this URL manually:\n${session.authorizeUrl}`));
|
|
245
256
|
}
|
|
246
257
|
}
|
|
247
258
|
const exchangePromise = serverHandle.waitForExchange();
|
|
248
|
-
const authPayload = await waitForExchangeWithTimeout(exchangePromise);
|
|
249
|
-
const authFile = await writeAuthFile({
|
|
259
|
+
const authPayload = await (0, exports.waitForExchangeWithTimeout)(exchangePromise);
|
|
260
|
+
const authFile = await (0, exports.writeAuthFile)({
|
|
250
261
|
payload: authPayload,
|
|
251
262
|
serverUrl: baseUrl,
|
|
252
263
|
});
|
|
@@ -44,7 +44,7 @@ const fs = __importStar(require("fs"));
|
|
|
44
44
|
const path = __importStar(require("path"));
|
|
45
45
|
const plist = __importStar(require("plist"));
|
|
46
46
|
const ui_1 = require("../utils/ui");
|
|
47
|
-
const
|
|
47
|
+
const getPackageRoot = () => process.env.BUNDLE_DROP_PACKAGE_ROOT_OVERRIDE || path.resolve(__dirname, '..', '..', '..');
|
|
48
48
|
async function upload(platform, options) {
|
|
49
49
|
console.log(); // blank line
|
|
50
50
|
ui_1.log.info('🚀 React Native OTA Upload Initialized');
|
|
@@ -148,6 +148,7 @@ async function upload(platform, options) {
|
|
|
148
148
|
ui_1.log.label('App Version', version);
|
|
149
149
|
console.log();
|
|
150
150
|
ui_1.log.arrow(`Bundling ${platform} app...`);
|
|
151
|
+
const packageRoot = getPackageRoot();
|
|
151
152
|
const compiledBundleScript = path.join(packageRoot, 'lib', 'scripts', 'bundle.js');
|
|
152
153
|
const tsBundleScript = path.join(packageRoot, 'src', 'scripts', 'bundle.ts');
|
|
153
154
|
const bundleCommand = fs.existsSync(compiledBundleScript)
|
package/lib/api/types.d.ts
CHANGED
|
@@ -2,6 +2,7 @@ export type OtaResolveRequest = {
|
|
|
2
2
|
channelName: string;
|
|
3
3
|
platform: string;
|
|
4
4
|
runtimeVersion?: string | null;
|
|
5
|
+
environment?: string | null;
|
|
5
6
|
currentHash?: string | null;
|
|
6
7
|
currentUserProperties?: Record<string, string>;
|
|
7
8
|
previousHash?: string | null;
|
|
@@ -26,18 +27,34 @@ export type OtaResolveResponse = {
|
|
|
26
27
|
runtimeVersion?: string;
|
|
27
28
|
};
|
|
28
29
|
};
|
|
30
|
+
/**
|
|
31
|
+
* Simplified update-check result returned by UI-facing APIs such as `useBundleDrop().checkLatest()`.
|
|
32
|
+
* Internally this is derived from the `/ota/resolve` response.
|
|
33
|
+
*/
|
|
29
34
|
export type UpdateCheckResponse = {
|
|
35
|
+
/** Server decision for the current channel/runtime. */
|
|
30
36
|
action: 'NOOP' | 'INSTALL' | 'ROLLBACK';
|
|
37
|
+
/** `true` when the current bundle is already up to date. */
|
|
31
38
|
upToDate?: boolean;
|
|
39
|
+
/** Target bundle version when an install is available. */
|
|
32
40
|
bundleVersion?: number;
|
|
41
|
+
/** Optional semantic/app version associated with the target bundle. */
|
|
33
42
|
version?: string;
|
|
43
|
+
/** Target bundle hash when an install is available. */
|
|
34
44
|
hash?: string;
|
|
45
|
+
/** Signed or public download URL for the target bundle. */
|
|
35
46
|
downloadUrl?: string;
|
|
47
|
+
/** Channel used for this resolve decision. */
|
|
36
48
|
channelName?: string;
|
|
49
|
+
/** Server-side reason for `NOOP` or `ROLLBACK` decisions. */
|
|
37
50
|
reason?: string;
|
|
51
|
+
/** `true` when no compatible bundle exists for the current runtime version. */
|
|
38
52
|
incompatible?: boolean;
|
|
53
|
+
/** Runtime version attached to the target bundle or current request. */
|
|
39
54
|
runtimeVersion?: string;
|
|
55
|
+
/** Runtime version requested by the client when an incompatibility is reported. */
|
|
40
56
|
requestedRuntimeVersion?: string;
|
|
57
|
+
/** Latest runtime version available on the channel when the current runtime is incompatible. */
|
|
41
58
|
latestRuntimeVersionOnChannel?: string;
|
|
42
59
|
};
|
|
43
60
|
export type PublicChannelsParams = {
|
|
@@ -48,16 +65,28 @@ export type ReportInstalledPayload = {
|
|
|
48
65
|
platform?: string;
|
|
49
66
|
installId?: string | null;
|
|
50
67
|
runtimeVersion?: string | null;
|
|
68
|
+
environment?: string | null;
|
|
51
69
|
userProperties?: Record<string, string>;
|
|
52
70
|
};
|
|
71
|
+
/**
|
|
72
|
+
* Public metadata for a single downloadable bundle returned by the bundle list endpoint.
|
|
73
|
+
*/
|
|
53
74
|
export type BundleListItem = {
|
|
75
|
+
/** Immutable bundle hash used for install and deduplication. */
|
|
54
76
|
hash: string;
|
|
77
|
+
/** Monotonic bundle version number assigned by BundleDrop. */
|
|
55
78
|
bundleVersion: number;
|
|
79
|
+
/** Optional semantic/app version attached during upload. */
|
|
56
80
|
version: string;
|
|
81
|
+
/** Platform the bundle was built for. */
|
|
57
82
|
platform: string;
|
|
83
|
+
/** Runtime version the bundle is compatible with. */
|
|
58
84
|
runtimeVersion: string;
|
|
85
|
+
/** Optional release notes shown in UI. */
|
|
59
86
|
releaseNotes: string | null;
|
|
87
|
+
/** Bundle creation timestamp in ISO format. */
|
|
60
88
|
createdAt: string;
|
|
89
|
+
/** Download URL if the bundle is currently installable; `null` when unavailable. */
|
|
61
90
|
downloadUrl: string | null;
|
|
62
91
|
};
|
|
63
92
|
export type BundleListResponse = {
|
package/lib/index.d.ts
CHANGED
|
@@ -1,9 +1,8 @@
|
|
|
1
1
|
import './bootstrap';
|
|
2
|
-
|
|
2
|
+
import { getChannelName, initBundleDrop, setChannel } from './runtime/service';
|
|
3
|
+
export { getAvailableChannels, checkForUpdate, getInstalledBundleInfo, getAvailableBundles } from './runtime/service';
|
|
3
4
|
export type { AvailableBundlesPage, GetAvailableBundlesOptions } from './manager/updateCheck';
|
|
4
|
-
export { downloadUpdate, installBundle } from './
|
|
5
|
-
export { getUpdateState, applyUpdate } from './manager/updateState';
|
|
6
|
-
export { initUpdateManager, isUpdateFlowActive } from './manager/initUpdateManager';
|
|
5
|
+
export { downloadUpdate, installBundle, getRuntimeUpdateState as getUpdateState, applyUpdate, setChannel, getChannelName, } from './runtime/service';
|
|
7
6
|
export { BundleDropError, isBundleDropError } from './errors';
|
|
8
7
|
export { getCurrentUserProperties, getUserProperties, setUserProperty, setUserPropery, removeUserProperty, resetUserProperties, } from './fs/userProperties';
|
|
9
8
|
export type { BundleInfo } from './bundleInfo';
|
|
@@ -11,5 +10,18 @@ export type { UpdatePolicy } from './types';
|
|
|
11
10
|
export type { BundleListItem } from './api/types';
|
|
12
11
|
export type { BundleDropProjectConfig } from './loadConfig';
|
|
13
12
|
export type { BundleDropConfig } from './context';
|
|
13
|
+
export type { BundleDropInitOptions, BundleDropRuntimeConfig } from './runtime/initState';
|
|
14
14
|
export { useBundleDrop } from './useBundleDrop';
|
|
15
|
+
export type { UseBundleDropReturn } from './useBundleDrop';
|
|
15
16
|
export { bundleDropConfig } from './context';
|
|
17
|
+
/**
|
|
18
|
+
* Top-level BundleDrop runtime controller.
|
|
19
|
+
*/
|
|
20
|
+
export declare const BundleDrop: {
|
|
21
|
+
/** Initialize BundleDrop for the current app process. `enabled` defaults to `true` when omitted. */
|
|
22
|
+
readonly init: typeof initBundleDrop;
|
|
23
|
+
/** Change the active runtime channel used by singleton OTA actions. */
|
|
24
|
+
readonly setChannel: typeof setChannel;
|
|
25
|
+
/** Read the currently active runtime channel. */
|
|
26
|
+
readonly getChannelName: typeof getChannelName;
|
|
27
|
+
};
|
package/lib/index.js
CHANGED
|
@@ -1,21 +1,20 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.bundleDropConfig = exports.useBundleDrop = exports.resetUserProperties = exports.removeUserProperty = exports.setUserPropery = exports.setUserProperty = exports.getUserProperties = exports.getCurrentUserProperties = exports.isBundleDropError = exports.BundleDropError = exports.
|
|
3
|
+
exports.BundleDrop = exports.bundleDropConfig = exports.useBundleDrop = exports.resetUserProperties = exports.removeUserProperty = exports.setUserPropery = exports.setUserProperty = exports.getUserProperties = exports.getCurrentUserProperties = exports.isBundleDropError = exports.BundleDropError = exports.getChannelName = exports.setChannel = exports.applyUpdate = exports.getUpdateState = exports.installBundle = exports.downloadUpdate = exports.getAvailableBundles = exports.getInstalledBundleInfo = exports.checkForUpdate = exports.getAvailableChannels = void 0;
|
|
4
4
|
require("./bootstrap");
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
Object.defineProperty(exports, "
|
|
8
|
-
Object.defineProperty(exports, "
|
|
9
|
-
Object.defineProperty(exports, "
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
Object.defineProperty(exports, "
|
|
13
|
-
|
|
14
|
-
Object.defineProperty(exports, "getUpdateState", { enumerable: true, get: function () { return
|
|
15
|
-
Object.defineProperty(exports, "applyUpdate", { enumerable: true, get: function () { return
|
|
16
|
-
|
|
17
|
-
Object.defineProperty(exports, "
|
|
18
|
-
Object.defineProperty(exports, "isUpdateFlowActive", { enumerable: true, get: function () { return initUpdateManager_1.isUpdateFlowActive; } });
|
|
5
|
+
const service_1 = require("./runtime/service");
|
|
6
|
+
var service_2 = require("./runtime/service");
|
|
7
|
+
Object.defineProperty(exports, "getAvailableChannels", { enumerable: true, get: function () { return service_2.getAvailableChannels; } });
|
|
8
|
+
Object.defineProperty(exports, "checkForUpdate", { enumerable: true, get: function () { return service_2.checkForUpdate; } });
|
|
9
|
+
Object.defineProperty(exports, "getInstalledBundleInfo", { enumerable: true, get: function () { return service_2.getInstalledBundleInfo; } });
|
|
10
|
+
Object.defineProperty(exports, "getAvailableBundles", { enumerable: true, get: function () { return service_2.getAvailableBundles; } });
|
|
11
|
+
var service_3 = require("./runtime/service");
|
|
12
|
+
Object.defineProperty(exports, "downloadUpdate", { enumerable: true, get: function () { return service_3.downloadUpdate; } });
|
|
13
|
+
Object.defineProperty(exports, "installBundle", { enumerable: true, get: function () { return service_3.installBundle; } });
|
|
14
|
+
Object.defineProperty(exports, "getUpdateState", { enumerable: true, get: function () { return service_3.getRuntimeUpdateState; } });
|
|
15
|
+
Object.defineProperty(exports, "applyUpdate", { enumerable: true, get: function () { return service_3.applyUpdate; } });
|
|
16
|
+
Object.defineProperty(exports, "setChannel", { enumerable: true, get: function () { return service_3.setChannel; } });
|
|
17
|
+
Object.defineProperty(exports, "getChannelName", { enumerable: true, get: function () { return service_3.getChannelName; } });
|
|
19
18
|
var errors_1 = require("./errors");
|
|
20
19
|
Object.defineProperty(exports, "BundleDropError", { enumerable: true, get: function () { return errors_1.BundleDropError; } });
|
|
21
20
|
Object.defineProperty(exports, "isBundleDropError", { enumerable: true, get: function () { return errors_1.isBundleDropError; } });
|
|
@@ -30,3 +29,14 @@ var useBundleDrop_1 = require("./useBundleDrop");
|
|
|
30
29
|
Object.defineProperty(exports, "useBundleDrop", { enumerable: true, get: function () { return useBundleDrop_1.useBundleDrop; } });
|
|
31
30
|
var context_1 = require("./context");
|
|
32
31
|
Object.defineProperty(exports, "bundleDropConfig", { enumerable: true, get: function () { return context_1.bundleDropConfig; } });
|
|
32
|
+
/**
|
|
33
|
+
* Top-level BundleDrop runtime controller.
|
|
34
|
+
*/
|
|
35
|
+
exports.BundleDrop = {
|
|
36
|
+
/** Initialize BundleDrop for the current app process. `enabled` defaults to `true` when omitted. */
|
|
37
|
+
init: service_1.initBundleDrop,
|
|
38
|
+
/** Change the active runtime channel used by singleton OTA actions. */
|
|
39
|
+
setChannel: service_1.setChannel,
|
|
40
|
+
/** Read the currently active runtime channel. */
|
|
41
|
+
getChannelName: service_1.getChannelName,
|
|
42
|
+
};
|
package/lib/manager/reporting.js
CHANGED
|
@@ -7,6 +7,7 @@ const clientApi_1 = require("../api/clientApi");
|
|
|
7
7
|
const bundleDropNative_1 = require("../native/bundleDropNative");
|
|
8
8
|
const installId_1 = require("../fs/installId");
|
|
9
9
|
const userProperties_1 = require("../fs/userProperties");
|
|
10
|
+
const initState_1 = require("../runtime/initState");
|
|
10
11
|
async function getReportingState() {
|
|
11
12
|
const info = await (0, bundleInfo_1.readBundleInfo)();
|
|
12
13
|
const path = await (0, bundleDropNative_1.getDownloadedBundlePathNative)();
|
|
@@ -32,11 +33,13 @@ async function reportInstalledIfReady(state) {
|
|
|
32
33
|
(0, installId_1.getOrCreateInstallId)(),
|
|
33
34
|
(0, userProperties_1.getCurrentUserProperties)(),
|
|
34
35
|
]);
|
|
36
|
+
const environment = (0, initState_1.getBundleDropRuntimeConfig)()?.environment ?? null;
|
|
35
37
|
await (0, clientApi_1.reportInstalled)(context_1.config.project.slug, info.hash, {
|
|
36
38
|
channelName: info.channelName,
|
|
37
39
|
platform: info.platform,
|
|
38
40
|
installId,
|
|
39
41
|
runtimeVersion: info.runtimeVersion ?? context_1.runtimeVersion ?? null,
|
|
42
|
+
environment,
|
|
40
43
|
userProperties: Object.keys(userProperties).length > 0 ? userProperties : undefined,
|
|
41
44
|
});
|
|
42
45
|
await (0, bundleInfo_1.updateBundleInfo)({ lastInstalledReportedHash: info.hash });
|
|
@@ -3,15 +3,28 @@ 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
|
+
/**
|
|
7
|
+
* Query options for browsing downloadable bundles from a public channel.
|
|
8
|
+
*/
|
|
6
9
|
export type GetAvailableBundlesOptions = {
|
|
10
|
+
/** Channel to browse. Defaults to the active runtime channel. */
|
|
7
11
|
channelName?: string;
|
|
12
|
+
/** Override platform when browsing bundles outside the current device platform. */
|
|
8
13
|
platform?: string;
|
|
14
|
+
/** Maximum number of items to return in this page. */
|
|
9
15
|
limit?: number;
|
|
16
|
+
/** Cursor returned by a previous page response. */
|
|
10
17
|
cursor?: string;
|
|
11
18
|
};
|
|
19
|
+
/**
|
|
20
|
+
* One page of public bundle-list results.
|
|
21
|
+
*/
|
|
12
22
|
export type AvailableBundlesPage = {
|
|
23
|
+
/** Bundles available on the requested channel/page. */
|
|
13
24
|
items: BundleListItem[];
|
|
25
|
+
/** Cursor for the next page, or `null` when there is no next page. */
|
|
14
26
|
nextCursor: string | null;
|
|
27
|
+
/** `true` when another page can be fetched with `nextCursor`. */
|
|
15
28
|
hasMore: boolean;
|
|
16
29
|
};
|
|
17
30
|
export declare function getAvailableBundles(options?: GetAvailableBundlesOptions): Promise<AvailableBundlesPage>;
|
|
@@ -11,6 +11,7 @@ const context_2 = require("../context");
|
|
|
11
11
|
const bundlePointer_1 = require("../fs/bundlePointer");
|
|
12
12
|
const installId_1 = require("../fs/installId");
|
|
13
13
|
const userProperties_1 = require("../fs/userProperties");
|
|
14
|
+
const initState_1 = require("../runtime/initState");
|
|
14
15
|
async function getAvailableChannels() {
|
|
15
16
|
const { project } = context_1.config;
|
|
16
17
|
if (!project?.slug) {
|
|
@@ -33,6 +34,9 @@ async function getAvailableChannels() {
|
|
|
33
34
|
async function checkForUpdate(channelName = context_2.defaultChannel, onStatusUpdate) {
|
|
34
35
|
const { project } = context_1.config;
|
|
35
36
|
try {
|
|
37
|
+
if (!project?.slug) {
|
|
38
|
+
throw new Error('Missing project slug in bundle.drop.config.js');
|
|
39
|
+
}
|
|
36
40
|
onStatusUpdate?.('🔍 Checking for updates...');
|
|
37
41
|
const [local, currentPtr, previousPtr, currentUserProperties, installId] = await Promise.all([
|
|
38
42
|
(0, bundleInfo_1.readBundleInfo)(),
|
|
@@ -43,10 +47,12 @@ async function checkForUpdate(channelName = context_2.defaultChannel, onStatusUp
|
|
|
43
47
|
]);
|
|
44
48
|
const currentHash = currentPtr?.hash ?? local?.hash ?? null;
|
|
45
49
|
const previousHash = previousPtr?.hash ?? null;
|
|
50
|
+
const environment = (0, initState_1.getBundleDropRuntimeConfig)()?.environment ?? null;
|
|
46
51
|
const res = await (0, clientApi_1.postOtaResolve)(project.slug, {
|
|
47
52
|
channelName,
|
|
48
53
|
platform: context_1.platform,
|
|
49
54
|
runtimeVersion: context_1.runtimeVersion ?? null,
|
|
55
|
+
environment,
|
|
50
56
|
currentHash,
|
|
51
57
|
currentUserProperties,
|
|
52
58
|
previousHash,
|
|
@@ -43,10 +43,16 @@ const applyUpdate = async (onStatusUpdate) => {
|
|
|
43
43
|
}
|
|
44
44
|
onStatusUpdate?.('♻️ Applying downloaded bundle...');
|
|
45
45
|
await (0, bundleInfo_1.updateBundleInfo)({ pendingApply: false, installedAt: new Date().toISOString() });
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
46
|
+
try {
|
|
47
|
+
await (0, reporting_1.reportInstalledIfReady)({
|
|
48
|
+
hasBundle: true,
|
|
49
|
+
info: info ? { ...info, pendingApply: false } : info,
|
|
50
|
+
});
|
|
51
|
+
}
|
|
52
|
+
catch (reportError) {
|
|
53
|
+
// Telemetry should not block applying the already-downloaded bundle.
|
|
54
|
+
console.warn('⚠️ Failed to report bundle install during apply:', reportError);
|
|
55
|
+
}
|
|
50
56
|
(0, bundleDropNative_1.restartReactNativeNative)();
|
|
51
57
|
return { status: 'applied' };
|
|
52
58
|
}
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
import type { UpdatePolicy } from '../types';
|
|
2
|
+
export declare const BUNDLE_DROP_NOT_INITIALIZED_MESSAGE = "BundleDrop has not been initialized. Call BundleDrop.init({ environment, ... }) before using OTA APIs or useBundleDrop().";
|
|
3
|
+
export declare const BUNDLE_DROP_DISABLED_MESSAGE = "BundleDrop is disabled. OTA APIs are running in no-op mode because BundleDrop.init({ enabled: false, ... }) was used.";
|
|
4
|
+
/**
|
|
5
|
+
* Runtime options for `BundleDrop.init(...)`.
|
|
6
|
+
*/
|
|
7
|
+
export type BundleDropInitOptions = {
|
|
8
|
+
/** Deployment environment shown in analytics, for example `production`, `staging`, or `development`. */
|
|
9
|
+
environment: string;
|
|
10
|
+
/** Defaults to `true`. Set to `false` to keep BundleDrop configured but fully no-op for the current app process. */
|
|
11
|
+
enabled?: boolean;
|
|
12
|
+
/** Initial OTA channel for this app process. Defaults to the static `defaultChannel` from `bundle.drop.config.js`. */
|
|
13
|
+
channelName?: string;
|
|
14
|
+
/** Startup behavior after local state hydration. Defaults to `manual`. */
|
|
15
|
+
policy?: UpdatePolicy;
|
|
16
|
+
/** Optional listener for human-readable status messages emitted during checks, downloads, and apply flow. */
|
|
17
|
+
onStatusUpdate?: (status: string) => void;
|
|
18
|
+
/** When `true`, startup performs only a resolve/check and skips download/apply even if policy would normally do more. */
|
|
19
|
+
checkOnly?: boolean;
|
|
20
|
+
};
|
|
21
|
+
/**
|
|
22
|
+
* Resolved runtime configuration currently active inside the singleton service.
|
|
23
|
+
*/
|
|
24
|
+
export type BundleDropRuntimeConfig = {
|
|
25
|
+
/** Deployment environment sent to BundleDrop analytics and resolve payloads. */
|
|
26
|
+
environment: string;
|
|
27
|
+
/** Whether BundleDrop is active or running in disabled no-op mode. */
|
|
28
|
+
enabled: boolean;
|
|
29
|
+
/** Current active OTA channel used by singleton update actions. */
|
|
30
|
+
channelName: string;
|
|
31
|
+
/** Effective startup policy after defaults are applied. */
|
|
32
|
+
policy: UpdatePolicy;
|
|
33
|
+
/** Optional listener receiving status messages from runtime actions. */
|
|
34
|
+
onStatusUpdate?: (status: string) => void;
|
|
35
|
+
/** Whether startup is limited to a resolve/check without downloading or applying. */
|
|
36
|
+
checkOnly: boolean;
|
|
37
|
+
};
|
|
38
|
+
export declare function resolveBundleDropRuntimeConfig(options: BundleDropInitOptions): BundleDropRuntimeConfig;
|
|
39
|
+
export declare function initializeBundleDropRuntime(options: BundleDropInitOptions): {
|
|
40
|
+
config: BundleDropRuntimeConfig;
|
|
41
|
+
alreadyInitialized: boolean;
|
|
42
|
+
};
|
|
43
|
+
export declare function getBundleDropRuntimeConfig(): BundleDropRuntimeConfig | null;
|
|
44
|
+
export declare function getBundleDropRuntimeConfigOrWarn(): BundleDropRuntimeConfig | null;
|
|
45
|
+
export declare function assertBundleDropInitialized(): BundleDropRuntimeConfig;
|
|
46
|
+
export declare function hasBundleDropBeenInitialized(): boolean;
|
|
47
|
+
export declare function setBundleDropChannel(channelName: string): BundleDropRuntimeConfig;
|
|
48
|
+
export declare function resetBundleDropRuntimeForTests(): void;
|