@gfean/react-native-bundle-drop 0.2.1 → 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 +127 -91
- 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
|
@@ -0,0 +1,131 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.BUNDLE_DROP_DISABLED_MESSAGE = exports.BUNDLE_DROP_NOT_INITIALIZED_MESSAGE = void 0;
|
|
4
|
+
exports.resolveBundleDropRuntimeConfig = resolveBundleDropRuntimeConfig;
|
|
5
|
+
exports.initializeBundleDropRuntime = initializeBundleDropRuntime;
|
|
6
|
+
exports.getBundleDropRuntimeConfig = getBundleDropRuntimeConfig;
|
|
7
|
+
exports.getBundleDropRuntimeConfigOrWarn = getBundleDropRuntimeConfigOrWarn;
|
|
8
|
+
exports.assertBundleDropInitialized = assertBundleDropInitialized;
|
|
9
|
+
exports.hasBundleDropBeenInitialized = hasBundleDropBeenInitialized;
|
|
10
|
+
exports.setBundleDropChannel = setBundleDropChannel;
|
|
11
|
+
exports.resetBundleDropRuntimeForTests = resetBundleDropRuntimeForTests;
|
|
12
|
+
const context_1 = require("../context");
|
|
13
|
+
exports.BUNDLE_DROP_NOT_INITIALIZED_MESSAGE = 'BundleDrop has not been initialized. Call BundleDrop.init({ environment, ... }) before using OTA APIs or useBundleDrop().';
|
|
14
|
+
exports.BUNDLE_DROP_DISABLED_MESSAGE = 'BundleDrop is disabled. OTA APIs are running in no-op mode because BundleDrop.init({ enabled: false, ... }) was used.';
|
|
15
|
+
let initConfig = null;
|
|
16
|
+
let runtimeConfigKey = null;
|
|
17
|
+
let runtimeChannelName = null;
|
|
18
|
+
const warnedMessages = new Set();
|
|
19
|
+
function warnOnce(message) {
|
|
20
|
+
if (warnedMessages.has(message)) {
|
|
21
|
+
return;
|
|
22
|
+
}
|
|
23
|
+
warnedMessages.add(message);
|
|
24
|
+
console.warn(message);
|
|
25
|
+
}
|
|
26
|
+
function normalizeRequiredString(value, fieldName) {
|
|
27
|
+
if (typeof value !== 'string') {
|
|
28
|
+
throw new Error(`BundleDrop.init(...) requires a string ${fieldName}`);
|
|
29
|
+
}
|
|
30
|
+
const normalized = value.trim();
|
|
31
|
+
if (!normalized) {
|
|
32
|
+
throw new Error(`BundleDrop.init(...) requires a non-empty ${fieldName}`);
|
|
33
|
+
}
|
|
34
|
+
return normalized;
|
|
35
|
+
}
|
|
36
|
+
function buildRuntimeConfigKey(config) {
|
|
37
|
+
return JSON.stringify({
|
|
38
|
+
environment: config.environment,
|
|
39
|
+
enabled: config.enabled,
|
|
40
|
+
channelName: config.channelName,
|
|
41
|
+
policy: config.policy,
|
|
42
|
+
checkOnly: config.checkOnly,
|
|
43
|
+
});
|
|
44
|
+
}
|
|
45
|
+
function resolveBundleDropRuntimeConfig(options) {
|
|
46
|
+
const environment = normalizeRequiredString(options.environment, 'environment');
|
|
47
|
+
const channelName = typeof options.channelName === 'string' && options.channelName.trim()
|
|
48
|
+
? options.channelName.trim()
|
|
49
|
+
: context_1.defaultChannel;
|
|
50
|
+
return {
|
|
51
|
+
environment,
|
|
52
|
+
enabled: options.enabled !== false,
|
|
53
|
+
channelName,
|
|
54
|
+
policy: options.policy || 'manual',
|
|
55
|
+
onStatusUpdate: options.onStatusUpdate,
|
|
56
|
+
checkOnly: !!options.checkOnly,
|
|
57
|
+
};
|
|
58
|
+
}
|
|
59
|
+
function initializeBundleDropRuntime(options) {
|
|
60
|
+
const nextConfig = resolveBundleDropRuntimeConfig(options);
|
|
61
|
+
const nextKey = buildRuntimeConfigKey(nextConfig);
|
|
62
|
+
if (!initConfig) {
|
|
63
|
+
initConfig = {
|
|
64
|
+
environment: nextConfig.environment,
|
|
65
|
+
enabled: nextConfig.enabled,
|
|
66
|
+
initialChannelName: nextConfig.channelName,
|
|
67
|
+
policy: nextConfig.policy,
|
|
68
|
+
onStatusUpdate: nextConfig.onStatusUpdate,
|
|
69
|
+
checkOnly: nextConfig.checkOnly,
|
|
70
|
+
};
|
|
71
|
+
runtimeConfigKey = nextKey;
|
|
72
|
+
runtimeChannelName = nextConfig.channelName;
|
|
73
|
+
return { config: nextConfig, alreadyInitialized: false };
|
|
74
|
+
}
|
|
75
|
+
if (runtimeConfigKey !== nextKey) {
|
|
76
|
+
throw new Error('BundleDrop.init(...) was called more than once with different runtime config. Keep the init config stable for the lifetime of the app process.');
|
|
77
|
+
}
|
|
78
|
+
initConfig = {
|
|
79
|
+
...initConfig,
|
|
80
|
+
onStatusUpdate: nextConfig.onStatusUpdate,
|
|
81
|
+
};
|
|
82
|
+
return { config: assertBundleDropInitialized(), alreadyInitialized: true };
|
|
83
|
+
}
|
|
84
|
+
function getBundleDropRuntimeConfig() {
|
|
85
|
+
if (!initConfig || !runtimeChannelName) {
|
|
86
|
+
return null;
|
|
87
|
+
}
|
|
88
|
+
return {
|
|
89
|
+
environment: initConfig.environment,
|
|
90
|
+
enabled: initConfig.enabled,
|
|
91
|
+
channelName: runtimeChannelName,
|
|
92
|
+
policy: initConfig.policy,
|
|
93
|
+
onStatusUpdate: initConfig.onStatusUpdate,
|
|
94
|
+
checkOnly: initConfig.checkOnly,
|
|
95
|
+
};
|
|
96
|
+
}
|
|
97
|
+
function getBundleDropRuntimeConfigOrWarn() {
|
|
98
|
+
const runtimeConfig = getBundleDropRuntimeConfig();
|
|
99
|
+
if (!runtimeConfig) {
|
|
100
|
+
warnOnce(exports.BUNDLE_DROP_NOT_INITIALIZED_MESSAGE);
|
|
101
|
+
return null;
|
|
102
|
+
}
|
|
103
|
+
if (!runtimeConfig.enabled) {
|
|
104
|
+
warnOnce(exports.BUNDLE_DROP_DISABLED_MESSAGE);
|
|
105
|
+
}
|
|
106
|
+
return runtimeConfig;
|
|
107
|
+
}
|
|
108
|
+
function assertBundleDropInitialized() {
|
|
109
|
+
const runtimeConfig = getBundleDropRuntimeConfig();
|
|
110
|
+
if (!runtimeConfig) {
|
|
111
|
+
throw new Error(exports.BUNDLE_DROP_NOT_INITIALIZED_MESSAGE);
|
|
112
|
+
}
|
|
113
|
+
return runtimeConfig;
|
|
114
|
+
}
|
|
115
|
+
function hasBundleDropBeenInitialized() {
|
|
116
|
+
return initConfig !== null;
|
|
117
|
+
}
|
|
118
|
+
function setBundleDropChannel(channelName) {
|
|
119
|
+
const runtimeConfig = assertBundleDropInitialized();
|
|
120
|
+
runtimeChannelName = normalizeRequiredString(channelName, 'channelName');
|
|
121
|
+
return {
|
|
122
|
+
...runtimeConfig,
|
|
123
|
+
channelName: runtimeChannelName,
|
|
124
|
+
};
|
|
125
|
+
}
|
|
126
|
+
function resetBundleDropRuntimeForTests() {
|
|
127
|
+
initConfig = null;
|
|
128
|
+
runtimeConfigKey = null;
|
|
129
|
+
runtimeChannelName = null;
|
|
130
|
+
warnedMessages.clear();
|
|
131
|
+
}
|
|
@@ -0,0 +1,111 @@
|
|
|
1
|
+
import type { BundleInfo } from '../bundleInfo';
|
|
2
|
+
import type { BundleListItem, UpdateCheckResponse } from '../api/types';
|
|
3
|
+
import type { DownloadUpdateResult } from '../manager/downloadAndInstall';
|
|
4
|
+
import type { ApplyUpdateResult } from '../manager/updateState';
|
|
5
|
+
import type { AvailableBundlesPage, GetAvailableBundlesOptions } from '../manager/updateCheck';
|
|
6
|
+
import { type BundleDropInitOptions } from './initState';
|
|
7
|
+
type BundleDropRuntimeSnapshot = {
|
|
8
|
+
status: string;
|
|
9
|
+
isBusy: boolean;
|
|
10
|
+
isEnabled: boolean;
|
|
11
|
+
channelName: string;
|
|
12
|
+
installedInfo: BundleInfo | null;
|
|
13
|
+
pendingApply: boolean;
|
|
14
|
+
hasBundle: boolean;
|
|
15
|
+
availableChannels: string[];
|
|
16
|
+
};
|
|
17
|
+
type StatusHandler = (status: string) => void;
|
|
18
|
+
type DownloadAndStageResult = {
|
|
19
|
+
result: DownloadUpdateResult;
|
|
20
|
+
status?: string;
|
|
21
|
+
};
|
|
22
|
+
type ApplyAndRefreshResult = {
|
|
23
|
+
result: ApplyUpdateResult;
|
|
24
|
+
status?: string;
|
|
25
|
+
};
|
|
26
|
+
type CheckLatestResult = {
|
|
27
|
+
response: UpdateCheckResponse | null;
|
|
28
|
+
status?: string;
|
|
29
|
+
};
|
|
30
|
+
/**
|
|
31
|
+
* Initialize the singleton BundleDrop runtime for the current app process.
|
|
32
|
+
*
|
|
33
|
+
* Call this once during app startup, typically from `index.js`, before using
|
|
34
|
+
* `useBundleDrop()` or any OTA runtime APIs.
|
|
35
|
+
*/
|
|
36
|
+
export declare function initBundleDrop(options: BundleDropInitOptions): void;
|
|
37
|
+
/**
|
|
38
|
+
* Change the active runtime channel used by singleton OTA actions such as checks,
|
|
39
|
+
* downloads, and installs triggered through `useBundleDrop()` or named exports.
|
|
40
|
+
*/
|
|
41
|
+
export declare function setChannel(channelName: string): void;
|
|
42
|
+
/**
|
|
43
|
+
* Read the current active runtime channel.
|
|
44
|
+
*/
|
|
45
|
+
export declare function getChannelName(): string;
|
|
46
|
+
export declare function subscribeBundleDropState(listener: () => void): () => void;
|
|
47
|
+
export declare function getBundleDropSnapshot(): BundleDropRuntimeSnapshot;
|
|
48
|
+
export declare function isUpdateFlowActive(): boolean;
|
|
49
|
+
/**
|
|
50
|
+
* Resolve update metadata from the server without downloading anything.
|
|
51
|
+
*/
|
|
52
|
+
export declare function checkLatest(extraStatusHandler?: StatusHandler): Promise<CheckLatestResult>;
|
|
53
|
+
/**
|
|
54
|
+
* Resolve, download, and stage the latest compatible update for the active runtime channel.
|
|
55
|
+
*/
|
|
56
|
+
export declare function downloadAndStage(extraStatusHandler?: StatusHandler): Promise<DownloadAndStageResult>;
|
|
57
|
+
/**
|
|
58
|
+
* Apply a previously staged bundle immediately by restarting the React Native bridge.
|
|
59
|
+
*/
|
|
60
|
+
export declare function applyDownloadedUpdate(extraStatusHandler?: StatusHandler): Promise<ApplyAndRefreshResult>;
|
|
61
|
+
/**
|
|
62
|
+
* Fetch the list of public channel names available for the configured project.
|
|
63
|
+
*/
|
|
64
|
+
export declare function fetchAvailableChannels(): Promise<string[]>;
|
|
65
|
+
/**
|
|
66
|
+
* Fetch a paginated list of bundles for a channel. Defaults to the active runtime channel.
|
|
67
|
+
*/
|
|
68
|
+
export declare function fetchAvailableBundles(options?: GetAvailableBundlesOptions): Promise<AvailableBundlesPage>;
|
|
69
|
+
/**
|
|
70
|
+
* Download and stage a specific bundle returned by `fetchAvailableBundles()`.
|
|
71
|
+
*/
|
|
72
|
+
export declare function installBundleFromListItem(bundle: BundleListItem): Promise<DownloadAndStageResult>;
|
|
73
|
+
/**
|
|
74
|
+
* Read locally stored metadata for the currently downloaded or applied bundle.
|
|
75
|
+
*/
|
|
76
|
+
export declare function getInstalledBundleInfo(): Promise<BundleInfo | null>;
|
|
77
|
+
/**
|
|
78
|
+
* Read the current local update state from disk.
|
|
79
|
+
*/
|
|
80
|
+
export declare function getRuntimeUpdateState(): Promise<{
|
|
81
|
+
hasBundle: boolean;
|
|
82
|
+
info: BundleInfo;
|
|
83
|
+
pendingApply: boolean;
|
|
84
|
+
}>;
|
|
85
|
+
/**
|
|
86
|
+
* Named-export variant of `useBundleDrop().checkLatest()`.
|
|
87
|
+
*/
|
|
88
|
+
export declare function checkForUpdate(onStatusUpdate?: StatusHandler): Promise<UpdateCheckResponse | null>;
|
|
89
|
+
/**
|
|
90
|
+
* Named-export variant of `useBundleDrop().downloadUpdate()`.
|
|
91
|
+
*/
|
|
92
|
+
export declare function downloadUpdate(onStatusUpdate?: StatusHandler): Promise<DownloadUpdateResult>;
|
|
93
|
+
/**
|
|
94
|
+
* Named-export variant of `useBundleDrop().applyUpdate()`.
|
|
95
|
+
*/
|
|
96
|
+
export declare function applyUpdate(onStatusUpdate?: StatusHandler): Promise<ApplyUpdateResult>;
|
|
97
|
+
/**
|
|
98
|
+
* Named-export variant of `useBundleDrop().fetchAvailableChannels()`.
|
|
99
|
+
*/
|
|
100
|
+
export declare function getAvailableChannels(): Promise<string[]>;
|
|
101
|
+
/**
|
|
102
|
+
* Named-export variant of `useBundleDrop().fetchBundles()`.
|
|
103
|
+
*/
|
|
104
|
+
export declare function getAvailableBundles(options?: GetAvailableBundlesOptions): Promise<AvailableBundlesPage>;
|
|
105
|
+
/**
|
|
106
|
+
* Download and stage a specific bundle by hash and URL instead of browsing through `fetchBundles()`.
|
|
107
|
+
*/
|
|
108
|
+
export declare function installBundle(hash: string, downloadUrl: string, bundleVersion?: number, version?: string, runtimeVersion?: string, onStatusUpdate?: StatusHandler): Promise<DownloadUpdateResult>;
|
|
109
|
+
export declare function resetBundleDropRuntimeServiceForTests(): void;
|
|
110
|
+
export declare function waitForBundleDropStartupForTests(): Promise<void>;
|
|
111
|
+
export {};
|