@gfean/react-native-bundle-drop 0.1.38 → 0.1.47
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CLIENT_README.md +21 -12
- package/README.md +19 -12
- package/lib/CLI/cli.js +6 -6
- package/lib/api/client.d.ts +1 -0
- package/lib/api/client.js +24 -0
- package/lib/api/clientApi.d.ts +8 -0
- package/lib/api/clientApi.js +42 -0
- package/lib/api/types.d.ts +36 -0
- package/lib/api/types.js +2 -0
- package/lib/api/utils.d.ts +1 -0
- package/lib/api/utils.js +8 -0
- package/lib/bootstrap.d.ts +1 -0
- package/lib/bootstrap.js +10 -0
- package/lib/context.d.ts +5 -0
- package/lib/context.js +16 -0
- package/lib/errors.d.ts +16 -0
- package/lib/errors.js +18 -0
- package/lib/fs/fsUtils.d.ts +4 -0
- package/lib/fs/fsUtils.js +38 -0
- package/lib/fs/iosPointer.d.ts +1 -0
- package/lib/fs/iosPointer.js +20 -0
- package/lib/index.d.ts +7 -49
- package/lib/index.js +18 -414
- package/lib/install/installFromZip.d.ts +12 -0
- package/lib/install/installFromZip.js +117 -0
- package/lib/manager/downloadAndInstall.d.ts +14 -0
- package/lib/manager/downloadAndInstall.js +144 -0
- package/lib/manager/initUpdateManager.d.ts +7 -0
- package/lib/manager/initUpdateManager.js +60 -0
- package/lib/manager/reporting.d.ts +5 -0
- package/lib/manager/reporting.js +40 -0
- package/lib/manager/updateCheck.d.ts +5 -0
- package/lib/manager/updateCheck.js +58 -0
- package/lib/manager/updateState.d.ts +14 -0
- package/lib/manager/updateState.js +62 -0
- package/lib/native/bundleDropNative.d.ts +2 -0
- package/lib/native/bundleDropNative.js +22 -0
- package/lib/scripts/download-bundle.js +29 -12
- package/lib/scripts/upload-bundle.js +26 -19
- package/lib/useBundleDrop.d.ts +21 -20
- package/lib/useBundleDrop.js +67 -73
- package/package.json +1 -1
package/CLIENT_README.md
CHANGED
|
@@ -67,15 +67,12 @@ const {
|
|
|
67
67
|
installedInfo,
|
|
68
68
|
pendingApply,
|
|
69
69
|
checkLatest,
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
downloadManual,
|
|
73
|
-
applyPending,
|
|
70
|
+
downloadUpdate,
|
|
71
|
+
applyUpdate,
|
|
74
72
|
} = useBundleDrop({ channelName: 'General', policy: 'manual' });
|
|
75
73
|
```
|
|
76
|
-
- `
|
|
77
|
-
- `
|
|
78
|
-
- `downloadManual`: download only; call `applyPending` when ready.
|
|
74
|
+
- `downloadUpdate`: download and stage; it will apply on next launch or when you call `applyUpdate` (returns `{ result, status }`).
|
|
75
|
+
- `applyUpdate`: apply a staged update now (reload) (returns `{ result, status }`).
|
|
79
76
|
|
|
80
77
|
Quick check-only pattern (no download):
|
|
81
78
|
```ts
|
|
@@ -86,8 +83,8 @@ console.log(status);
|
|
|
86
83
|
|
|
87
84
|
## 4) Policies
|
|
88
85
|
- `manual`: nothing automatic; call the actions yourself.
|
|
89
|
-
- `immediate`: download and
|
|
90
|
-
- `on-next-launch`: download
|
|
86
|
+
- `immediate`: download and stage, then apply now; if a staged update exists, it applies immediately.
|
|
87
|
+
- `on-next-launch`: download and stage; apply on next cold start (pending flag stays true until applied).
|
|
91
88
|
|
|
92
89
|
## 5) Channels (naming tips)
|
|
93
90
|
- Keep names simple and stable: `General`, `Beta`, `QA`.
|
|
@@ -99,9 +96,20 @@ console.log(status);
|
|
|
99
96
|
- The bundler injects `runtimeVersion` into the metadata JSON inside the ZIP; upload includes it automatically.
|
|
100
97
|
- The client sends `runtimeVersion` on `checkForUpdate`; server should only return bundles that match the requesting runtime.
|
|
101
98
|
|
|
99
|
+
### Channel listing (API key)
|
|
100
|
+
Use `fetchAvailableChannels` from the `useBundleDrop` hook to retrieve available channel names (requires `project.apiKey`):
|
|
101
|
+
```ts
|
|
102
|
+
const { fetchAvailableChannels, availableChannels, status } = useBundleDrop();
|
|
103
|
+
useEffect(() => {
|
|
104
|
+
fetchAvailableChannels();
|
|
105
|
+
}, []);
|
|
106
|
+
```
|
|
107
|
+
The hook calls `GET /channels/public/byProjectSlug?projectSlug=<slug>&orgSlug=<orgSlug>` with your API key and stores the result in `availableChannels`.
|
|
108
|
+
|
|
102
109
|
## 7) Server expectations
|
|
103
110
|
- Endpoint `/bundle/checkForUpdate` should accept `project`, `platform`, `channelName`, `currentBundleVersion?`, `currentHash?`, `runtimeVersion?` and return `{ upToDate, bundleVersion, version, hash, downloadUrl?, reason?, incompatible? }`.
|
|
104
|
-
-
|
|
111
|
+
- Endpoints `/bundle/latest`, `/bundle/:hash`, and `/bundle/:hash/download` should respond with JSON containing a `downloadUrl` to the signed ZIP built by your upload script. Clients should follow that URL to fetch the ZIP (no auth headers needed on the signed URL).
|
|
112
|
+
- Endpoint `/channels/public/byProjectSlug` should accept `projectSlug` and `orgSlug` (API-key protected via `x-api-key` or `apiKey` header) and return an array of channel names (e.g., `["General", "QA"]`).
|
|
105
113
|
|
|
106
114
|
## 8) Bundling/Upload (CI/local)
|
|
107
115
|
- Login once:
|
|
@@ -153,12 +161,13 @@ console.log(status);
|
|
|
153
161
|
- Local metadata is stored at `bundle-info.json` in the app document directory.
|
|
154
162
|
- `getUpdateState()` returns `{ hasBundle, info, pendingApply }` if you need raw state.
|
|
155
163
|
- Types are re-exported from the package entry: `BundleInfo`, `UpdatePolicy`.
|
|
164
|
+
- API calls are centralized under `src/api/` with an axios interceptor that applies your `x-api-key`; `src/index.tsx` remains the public barrel re-export.
|
|
156
165
|
- Env tips:
|
|
157
166
|
- Set `debugLocal: true` in config to force localhost/10.0.2.2.
|
|
158
167
|
- If you want a kill switch, guard your `initUpdateManager` call (e.g., `if (!Config.BUNDLE_DROP_DISABLE) { ... }`).
|
|
159
168
|
|
|
160
169
|
## 11) QA checklist
|
|
161
170
|
- Verify `checkLatest` on the target channel reports up-to-date when expected.
|
|
162
|
-
- Download and
|
|
163
|
-
- Confirm pending flag/UI
|
|
171
|
+
- Download and stage with `downloadUpdate`, then apply with `applyUpdate`; verify both immediate apply and next-launch behavior.
|
|
172
|
+
- Confirm pending flag/UI reflects staged state after download and clears after apply.
|
|
164
173
|
- Spot-check a couple of images/assets after OTA (Android manifest remap) to ensure they resolve.
|
package/README.md
CHANGED
|
@@ -48,17 +48,15 @@ module.exports = {
|
|
|
48
48
|
|
|
49
49
|
## Runtime APIs (app code)
|
|
50
50
|
- `checkForUpdate(channelName?, onStatusUpdate?)`: metadata-only check; no download.
|
|
51
|
-
- `
|
|
52
|
-
- `
|
|
53
|
-
- `downloadUpdate(options?, onStatusUpdate?)`: downloads only (defaults to `applyBehavior: manual`).
|
|
54
|
-
- `applyReadyUpdate(onStatusUpdate?)`: apply a downloaded bundle if pending.
|
|
51
|
+
- `downloadUpdate(options?, onStatusUpdate?)`: downloads and stages the update (sets `pendingApply: true`); it will apply on next launch or when you call `applyUpdate`.
|
|
52
|
+
- `applyUpdate(onStatusUpdate?)`: apply a staged update now (restarts the RN bridge).
|
|
55
53
|
- `getUpdateState()`: returns `{ hasBundle, info, pendingApply }` from local metadata.
|
|
56
54
|
- `initUpdateManager({ channelName, policy, onStatusUpdate, checkOnly })`: startup helper
|
|
57
55
|
- `policy: 'manual' | 'immediate' | 'on-next-launch'`
|
|
58
|
-
- `immediate`: download
|
|
59
|
-
- `on-next-launch`: download and
|
|
60
|
-
- `manual`: no auto download/apply; optional `checkOnly` will just run a check
|
|
61
|
-
- `useBundleDrop` hook (optional helper): returns status, busy flag, installed info, pending state, and actions (`checkLatest`, `
|
|
56
|
+
- `immediate`: download and stage, then apply now (reload). If a staged update is pending, applies it immediately.
|
|
57
|
+
- `on-next-launch`: download and stage; app will pick it up on the next launch (pending flag remains until applied).
|
|
58
|
+
- `manual`: no auto download/apply; optional `checkOnly` will just run a check.
|
|
59
|
+
- `useBundleDrop` hook (optional helper): returns status, busy flag, installed info, pending state, and actions (`checkLatest`, `downloadUpdate`, `applyUpdate`, `fetchAvailableChannels`). Action calls return structured results plus the status string they set.
|
|
62
60
|
|
|
63
61
|
Android extras:
|
|
64
62
|
- Asset resolver patches (`injectBundleDropImageResolver`, `patchImageRenderToForceResolve`) are applied on module load so images referenced directly still resolve after OTA.
|
|
@@ -102,11 +100,11 @@ const {
|
|
|
102
100
|
installedInfo,
|
|
103
101
|
pendingApply,
|
|
104
102
|
checkLatest,
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
downloadManual,
|
|
108
|
-
applyPending,
|
|
103
|
+
downloadUpdate,
|
|
104
|
+
applyUpdate,
|
|
109
105
|
} = useBundleDrop({ channelName: 'General', policy: 'manual' });
|
|
106
|
+
|
|
107
|
+
// downloadUpdate() will stage the bundle (applies on next launch or when you call applyUpdate()).
|
|
110
108
|
```
|
|
111
109
|
|
|
112
110
|
## CLI (bin)
|
|
@@ -121,3 +119,12 @@ const {
|
|
|
121
119
|
## Troubleshooting
|
|
122
120
|
- If bundling fails with `EMFILE`, raise file descriptor limit (`ulimit -n 8192`) and retry.
|
|
123
121
|
- Ensure `bundle.drop.config.js` has `serverUrl`, `org.slug`, and `project.slug`; otherwise the module falls back to localhost defaults.
|
|
122
|
+
|
|
123
|
+
## Maintainer notes (internal structure)
|
|
124
|
+
- `src/index.tsx` is a thin barrel; public API remains unchanged.
|
|
125
|
+
- Early side-effects/config live in `src/bootstrap.ts` (loads config, detects platform, patches Android images).
|
|
126
|
+
- File system helpers: `src/fs/*` (atomic writes, iOS pointer).
|
|
127
|
+
- Native accessors: `src/native/bundleDropNative.ts`.
|
|
128
|
+
- Install flow: `src/install/installFromZip.ts`.
|
|
129
|
+
- API client layer: `src/api/*` (axios client + typed endpoints).
|
|
130
|
+
- Update managers: `src/manager/*` (`updateCheck`, `downloadAndInstall`, `updateState`, `reporting`, `initUpdateManager`).
|
package/lib/CLI/cli.js
CHANGED
|
@@ -86,20 +86,20 @@ program
|
|
|
86
86
|
const organizations = data.organizations || [];
|
|
87
87
|
const downloadApiKey = data.downloadApiKey || '';
|
|
88
88
|
//eslint-disable-next-line
|
|
89
|
-
require('../CLI/scripts/init-config').initConfig({
|
|
89
|
+
await require('../CLI/scripts/init-config').initConfig({
|
|
90
90
|
serverUrl: process.env.BUNDLE_DROP_SERVER_URL?.replace(/\/$/, '') || 'https://bundle-drop-backend.onrender.com',
|
|
91
91
|
projects,
|
|
92
92
|
organizations,
|
|
93
93
|
downloadApiKey,
|
|
94
94
|
});
|
|
95
95
|
// Offer to set up Metro alias for bundle.drop.config.js resolution
|
|
96
|
-
const
|
|
96
|
+
const metroAnswer = await (0, prompts_1.default)({
|
|
97
97
|
type: 'confirm',
|
|
98
98
|
name: 'runMetro',
|
|
99
99
|
message: 'Also add the Metro alias for bundle.drop.config.js (recommended)?',
|
|
100
100
|
initial: true,
|
|
101
101
|
});
|
|
102
|
-
if (runMetro) {
|
|
102
|
+
if (metroAnswer.runMetro) {
|
|
103
103
|
try {
|
|
104
104
|
//eslint-disable-next-line
|
|
105
105
|
await require('../CLI/scripts/init-metro-config').initMetroConfig();
|
|
@@ -108,14 +108,14 @@ program
|
|
|
108
108
|
console.log(`⚠️ Failed to initialize Metro config; please refer to manual setup instructions. (${err?.message || err})`);
|
|
109
109
|
}
|
|
110
110
|
}
|
|
111
|
-
// Offer to patch native entrypoints
|
|
112
|
-
const
|
|
111
|
+
// Offer to patch native entrypoints (after Metro prompt finishes)
|
|
112
|
+
const nativeAnswer = await (0, prompts_1.default)({
|
|
113
113
|
type: 'confirm',
|
|
114
114
|
name: 'runNative',
|
|
115
115
|
message: 'Patch native entrypoints (MainApplication/AppDelegate) to prefer OTA? (Standard RN setups only)',
|
|
116
116
|
initial: false,
|
|
117
117
|
});
|
|
118
|
-
if (runNative) {
|
|
118
|
+
if (nativeAnswer.runNative) {
|
|
119
119
|
try {
|
|
120
120
|
//eslint-disable-next-line
|
|
121
121
|
await require('../CLI/scripts/init-native-config').initNativeConfig();
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare const apiClient: import("axios").AxiosInstance;
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.apiClient = void 0;
|
|
7
|
+
const axios_1 = __importDefault(require("axios"));
|
|
8
|
+
const context_1 = require("../context");
|
|
9
|
+
exports.apiClient = axios_1.default.create({
|
|
10
|
+
baseURL: context_1.config.serverUrl,
|
|
11
|
+
});
|
|
12
|
+
// Attach x-api-key automatically (if configured) and ensure Accept header defaults to JSON for API calls.
|
|
13
|
+
exports.apiClient.interceptors.request.use(request => {
|
|
14
|
+
const headers = (request.headers || {});
|
|
15
|
+
const apiKey = context_1.config.project?.apiKey;
|
|
16
|
+
if (apiKey && !('x-api-key' in headers)) {
|
|
17
|
+
headers['x-api-key'] = apiKey;
|
|
18
|
+
}
|
|
19
|
+
if (!headers.Accept) {
|
|
20
|
+
headers.Accept = 'application/json';
|
|
21
|
+
}
|
|
22
|
+
request.headers = headers;
|
|
23
|
+
return request;
|
|
24
|
+
});
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import type { AxiosResponse } from 'axios';
|
|
2
|
+
import { LatestBundleParams, PublicChannelsParams, ReportInstalledPayload, UpdateCheckParams, UpdateCheckResponse } from './types';
|
|
3
|
+
export declare function getUpdateCheck(params: UpdateCheckParams): Promise<AxiosResponse<UpdateCheckResponse>>;
|
|
4
|
+
export declare function getLatestBundleDownloadUrl(params: LatestBundleParams): Promise<AxiosResponse<{
|
|
5
|
+
downloadUrl?: string;
|
|
6
|
+
}>>;
|
|
7
|
+
export declare function getPublicChannels(params: PublicChannelsParams): Promise<AxiosResponse<string[]>>;
|
|
8
|
+
export declare function reportInstalled(hash: string, payload: ReportInstalledPayload): Promise<AxiosResponse<void>>;
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.getUpdateCheck = getUpdateCheck;
|
|
4
|
+
exports.getLatestBundleDownloadUrl = getLatestBundleDownloadUrl;
|
|
5
|
+
exports.getPublicChannels = getPublicChannels;
|
|
6
|
+
exports.reportInstalled = reportInstalled;
|
|
7
|
+
const client_1 = require("./client");
|
|
8
|
+
const utils_1 = require("./utils");
|
|
9
|
+
function getUpdateCheck(params) {
|
|
10
|
+
const query = (0, utils_1.buildQuery)(params);
|
|
11
|
+
return client_1.apiClient.get(`/bundle/checkForUpdate?${query}`, {
|
|
12
|
+
headers: {
|
|
13
|
+
Accept: 'application/json',
|
|
14
|
+
},
|
|
15
|
+
timeout: 15000,
|
|
16
|
+
});
|
|
17
|
+
}
|
|
18
|
+
function getLatestBundleDownloadUrl(params) {
|
|
19
|
+
const query = (0, utils_1.buildQuery)(params);
|
|
20
|
+
return client_1.apiClient.get(`/bundle/latest?${query}`, {
|
|
21
|
+
headers: {
|
|
22
|
+
Accept: 'application/json',
|
|
23
|
+
},
|
|
24
|
+
});
|
|
25
|
+
}
|
|
26
|
+
function getPublicChannels(params) {
|
|
27
|
+
const query = (0, utils_1.buildQuery)(params);
|
|
28
|
+
return client_1.apiClient.get(`/channels/public/byProjectSlug?${query}`, {
|
|
29
|
+
headers: {
|
|
30
|
+
Accept: 'application/json',
|
|
31
|
+
},
|
|
32
|
+
timeout: 15000,
|
|
33
|
+
});
|
|
34
|
+
}
|
|
35
|
+
function reportInstalled(hash, payload) {
|
|
36
|
+
return client_1.apiClient.post(`/bundle/${encodeURIComponent(hash)}/installed`, payload, {
|
|
37
|
+
headers: {
|
|
38
|
+
Accept: 'application/json',
|
|
39
|
+
},
|
|
40
|
+
timeout: 10000,
|
|
41
|
+
});
|
|
42
|
+
}
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
export type UpdateCheckResponse = {
|
|
2
|
+
upToDate?: boolean;
|
|
3
|
+
bundleVersion?: number;
|
|
4
|
+
version?: string;
|
|
5
|
+
hash?: string;
|
|
6
|
+
downloadUrl?: string;
|
|
7
|
+
channelName?: string;
|
|
8
|
+
reason?: string;
|
|
9
|
+
incompatible?: boolean;
|
|
10
|
+
runtimeVersion?: string;
|
|
11
|
+
};
|
|
12
|
+
export type UpdateCheckParams = {
|
|
13
|
+
platform: string;
|
|
14
|
+
orgSlug: string;
|
|
15
|
+
project: string;
|
|
16
|
+
channelName: string;
|
|
17
|
+
currentBundleVersion?: number | null;
|
|
18
|
+
currentHash?: string | null;
|
|
19
|
+
runtimeVersion?: string | null;
|
|
20
|
+
};
|
|
21
|
+
export type LatestBundleParams = {
|
|
22
|
+
platform: string;
|
|
23
|
+
orgSlug: string;
|
|
24
|
+
project: string;
|
|
25
|
+
channelName: string;
|
|
26
|
+
};
|
|
27
|
+
export type PublicChannelsParams = {
|
|
28
|
+
projectSlug: string;
|
|
29
|
+
orgSlug: string;
|
|
30
|
+
};
|
|
31
|
+
export type ReportInstalledPayload = {
|
|
32
|
+
orgSlug: string;
|
|
33
|
+
projectSlug: string;
|
|
34
|
+
channelName?: string;
|
|
35
|
+
platform?: string;
|
|
36
|
+
};
|
package/lib/api/types.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare const buildQuery: (params: Record<string, string | number | undefined | null>) => string;
|
package/lib/api/utils.js
ADDED
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.buildQuery = void 0;
|
|
4
|
+
const buildQuery = (params) => Object.entries(params)
|
|
5
|
+
.filter(([, v]) => v !== undefined && v !== null)
|
|
6
|
+
.map(([k, v]) => `${encodeURIComponent(k)}=${encodeURIComponent(String(v))}`)
|
|
7
|
+
.join('&');
|
|
8
|
+
exports.buildQuery = buildQuery;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
package/lib/bootstrap.js
ADDED
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const context_1 = require("./context");
|
|
4
|
+
const injectImageResolver_1 = require("./injectImageResolver");
|
|
5
|
+
const patchImageAutoResolve_1 = require("./patchImageAutoResolve");
|
|
6
|
+
// Patch early so assets bundled with the app (before OTA) still resolve on Android.
|
|
7
|
+
if (!context_1.isIOS) {
|
|
8
|
+
(0, injectImageResolver_1.injectBundleDropImageResolver)();
|
|
9
|
+
(0, patchImageAutoResolve_1.patchImageRenderToForceResolve)();
|
|
10
|
+
}
|
package/lib/context.d.ts
ADDED
package/lib/context.js
ADDED
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.BUNDLE_DROP_ROOT = exports.runtimeVersion = exports.isIOS = exports.platform = exports.config = void 0;
|
|
7
|
+
const react_native_1 = require("react-native");
|
|
8
|
+
const react_native_fs_1 = __importDefault(require("react-native-fs"));
|
|
9
|
+
const loadConfig_1 = require("./loadConfig");
|
|
10
|
+
exports.config = (0, loadConfig_1.loadConfig)();
|
|
11
|
+
exports.platform = react_native_1.Platform.OS === 'ios' ? 'ios' : 'android';
|
|
12
|
+
exports.isIOS = exports.platform === 'ios';
|
|
13
|
+
exports.runtimeVersion = exports.config.runtimeVersion?.[exports.platform];
|
|
14
|
+
exports.BUNDLE_DROP_ROOT = exports.isIOS
|
|
15
|
+
? `${react_native_fs_1.default.LibraryDirectoryPath}/bundle-drop`
|
|
16
|
+
: `${react_native_fs_1.default.DocumentDirectoryPath}`;
|
package/lib/errors.d.ts
ADDED
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
export type BundleDropErrorCode = 'CHECK_FAILED' | 'INCOMPATIBLE_BINARY' | 'NO_UPDATE' | 'DOWNLOAD_URL_MISSING' | 'DOWNLOAD_FAILED' | 'INSTALL_FAILED' | 'HASH_MISSING' | 'APPLY_NO_BUNDLE' | 'APPLY_ALREADY_APPLIED' | 'APPLY_FAILED' | 'UNKNOWN';
|
|
2
|
+
export type BundleDropErrorStep = 'check' | 'resolveDownloadUrl' | 'download' | 'install' | 'persist' | 'apply';
|
|
3
|
+
export declare class BundleDropError extends Error {
|
|
4
|
+
code: BundleDropErrorCode;
|
|
5
|
+
step: BundleDropErrorStep;
|
|
6
|
+
context?: Record<string, any>;
|
|
7
|
+
cause?: unknown;
|
|
8
|
+
constructor(args: {
|
|
9
|
+
message: string;
|
|
10
|
+
code: BundleDropErrorCode;
|
|
11
|
+
step: BundleDropErrorStep;
|
|
12
|
+
context?: Record<string, any>;
|
|
13
|
+
cause?: unknown;
|
|
14
|
+
});
|
|
15
|
+
}
|
|
16
|
+
export declare function isBundleDropError(e: unknown): e is BundleDropError;
|
package/lib/errors.js
ADDED
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.BundleDropError = void 0;
|
|
4
|
+
exports.isBundleDropError = isBundleDropError;
|
|
5
|
+
class BundleDropError extends Error {
|
|
6
|
+
constructor(args) {
|
|
7
|
+
super(args.message);
|
|
8
|
+
this.name = 'BundleDropError';
|
|
9
|
+
this.code = args.code;
|
|
10
|
+
this.step = args.step;
|
|
11
|
+
this.context = args.context;
|
|
12
|
+
this.cause = args.cause;
|
|
13
|
+
}
|
|
14
|
+
}
|
|
15
|
+
exports.BundleDropError = BundleDropError;
|
|
16
|
+
function isBundleDropError(e) {
|
|
17
|
+
return !!e && typeof e === 'object' && e.name === 'BundleDropError';
|
|
18
|
+
}
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
export declare function ensureDir(dir: string): Promise<void>;
|
|
2
|
+
export declare function atomicWriteJson(path: string, data: any): Promise<void>;
|
|
3
|
+
export declare function ensureParentDir(filePath: string): Promise<void>;
|
|
4
|
+
export declare function writeFileAtomicBase64(path: string, base64: string): Promise<void>;
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.ensureDir = ensureDir;
|
|
7
|
+
exports.atomicWriteJson = atomicWriteJson;
|
|
8
|
+
exports.ensureParentDir = ensureParentDir;
|
|
9
|
+
exports.writeFileAtomicBase64 = writeFileAtomicBase64;
|
|
10
|
+
const react_native_fs_1 = __importDefault(require("react-native-fs"));
|
|
11
|
+
async function ensureDir(dir) {
|
|
12
|
+
if (!(await react_native_fs_1.default.exists(dir))) {
|
|
13
|
+
await react_native_fs_1.default.mkdir(dir);
|
|
14
|
+
}
|
|
15
|
+
}
|
|
16
|
+
async function atomicWriteJson(path, data) {
|
|
17
|
+
const tmp = `${path}.tmp`;
|
|
18
|
+
await react_native_fs_1.default.writeFile(tmp, JSON.stringify(data), 'utf8');
|
|
19
|
+
if (await react_native_fs_1.default.exists(path)) {
|
|
20
|
+
await react_native_fs_1.default.unlink(path);
|
|
21
|
+
}
|
|
22
|
+
await react_native_fs_1.default.moveFile(tmp, path);
|
|
23
|
+
}
|
|
24
|
+
async function ensureParentDir(filePath) {
|
|
25
|
+
const dir = filePath.substring(0, filePath.lastIndexOf('/'));
|
|
26
|
+
if (!(await react_native_fs_1.default.exists(dir))) {
|
|
27
|
+
await react_native_fs_1.default.mkdir(dir);
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
async function writeFileAtomicBase64(path, base64) {
|
|
31
|
+
const tmp = `${path}.tmp`;
|
|
32
|
+
await ensureParentDir(path);
|
|
33
|
+
await react_native_fs_1.default.writeFile(tmp, base64, 'base64');
|
|
34
|
+
if (await react_native_fs_1.default.exists(path)) {
|
|
35
|
+
await react_native_fs_1.default.unlink(path);
|
|
36
|
+
}
|
|
37
|
+
await react_native_fs_1.default.moveFile(tmp, path);
|
|
38
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function setCurrentBundlePointer(bundlePath: string, hash: string): Promise<void>;
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.setCurrentBundlePointer = setCurrentBundlePointer;
|
|
7
|
+
const react_native_fs_1 = __importDefault(require("react-native-fs"));
|
|
8
|
+
const context_1 = require("../context");
|
|
9
|
+
const fsUtils_1 = require("./fsUtils");
|
|
10
|
+
async function setCurrentBundlePointer(bundlePath, hash) {
|
|
11
|
+
if (!context_1.isIOS)
|
|
12
|
+
return;
|
|
13
|
+
const root = `${react_native_fs_1.default.LibraryDirectoryPath}/bundle-drop`;
|
|
14
|
+
await (0, fsUtils_1.ensureDir)(root);
|
|
15
|
+
await (0, fsUtils_1.atomicWriteJson)(`${root}/current.json`, {
|
|
16
|
+
hash,
|
|
17
|
+
bundlePath,
|
|
18
|
+
updatedAt: new Date().toISOString(),
|
|
19
|
+
});
|
|
20
|
+
}
|
package/lib/index.d.ts
CHANGED
|
@@ -1,52 +1,10 @@
|
|
|
1
|
-
import
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
downloadUrl?: string;
|
|
9
|
-
channelName?: string;
|
|
10
|
-
reason?: string;
|
|
11
|
-
incompatible?: boolean;
|
|
12
|
-
runtimeVersion?: string;
|
|
13
|
-
};
|
|
14
|
-
export declare function getDownloadedBundlePath(): Promise<string | null>;
|
|
15
|
-
export declare function checkForUpdate(channelName?: string, onStatusUpdate?: (status: string) => void): Promise<UpdateCheckResponse | null>;
|
|
16
|
-
export declare function getInstalledBundleInfo(): Promise<BundleInfo | null>;
|
|
17
|
-
export declare function downloadAndInstallBundle(platformOrStatus?: 'ios' | 'android' | ((status: string) => void), onStatusUpdate?: (status: string) => void, options?: {
|
|
18
|
-
channelName?: string;
|
|
19
|
-
forceDownload?: boolean;
|
|
20
|
-
applyBehavior?: UpdatePolicy;
|
|
21
|
-
}): Promise<string | null>;
|
|
22
|
-
export declare const restartAppAndInstallUpdate: (onStatusUpdate: (status: string) => void, options?: {
|
|
23
|
-
channelName?: string;
|
|
24
|
-
forceDownload?: boolean;
|
|
25
|
-
applyBehavior?: UpdatePolicy;
|
|
26
|
-
}) => Promise<void>;
|
|
27
|
-
export declare const downloadUpdate: (options?: {
|
|
28
|
-
channelName?: string;
|
|
29
|
-
forceDownload?: boolean;
|
|
30
|
-
applyBehavior?: UpdatePolicy;
|
|
31
|
-
}, onStatusUpdate?: (status: string) => void) => Promise<string>;
|
|
32
|
-
export declare const applyReadyUpdate: (onStatusUpdate?: (status: string) => void) => Promise<boolean>;
|
|
33
|
-
export declare const getUpdateState: () => Promise<{
|
|
34
|
-
hasBundle: boolean;
|
|
35
|
-
info: BundleInfo;
|
|
36
|
-
pendingApply: boolean;
|
|
37
|
-
}>;
|
|
38
|
-
/**
|
|
39
|
-
* Initialize update behavior at app start.
|
|
40
|
-
* - manual: no auto-download/apply (optional checkOnly)
|
|
41
|
-
* - immediate: download and apply now; if a pending bundle exists, apply it
|
|
42
|
-
* - on-next-launch: download in background; apply on next launch if pending
|
|
43
|
-
*/
|
|
44
|
-
export declare function initUpdateManager(opts?: {
|
|
45
|
-
channelName?: string;
|
|
46
|
-
policy?: UpdatePolicy;
|
|
47
|
-
onStatusUpdate?: (status: string) => void;
|
|
48
|
-
checkOnly?: boolean;
|
|
49
|
-
}): Promise<void>;
|
|
1
|
+
import './bootstrap';
|
|
2
|
+
export { getAvailableChannels, checkForUpdate, getInstalledBundleInfo } from './manager/updateCheck';
|
|
3
|
+
export { downloadUpdate } from './manager/downloadAndInstall';
|
|
4
|
+
export { getUpdateState, applyUpdate } from './manager/updateState';
|
|
5
|
+
export { initUpdateManager } from './manager/initUpdateManager';
|
|
6
|
+
export { getDownloadedBundlePathNative as getDownloadedBundlePath } from './native/bundleDropNative';
|
|
7
|
+
export { BundleDropError, isBundleDropError } from './errors';
|
|
50
8
|
export type { BundleInfo } from './bundleInfo';
|
|
51
9
|
export type { UpdatePolicy } from './types';
|
|
52
10
|
export { useBundleDrop } from './useBundleDrop';
|