@gfean/react-native-bundle-drop 0.1.48 → 0.1.85
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 +254 -84
- package/README.md +145 -14
- package/android/src/main/java/com/bundledrop/BundleDropModule.kt +94 -21
- package/ios/BundleDropBridge.m +29 -1
- package/ios/BundleDropLocator.swift +0 -6
- package/ios/BundleDropModule.swift +132 -4
- package/lib/CLI/cli.js +48 -39
- package/lib/CLI/scripts/init-config.d.ts +1 -0
- package/lib/CLI/scripts/init-config.js +42 -2
- package/lib/CLI/scripts/init-native-config.js +428 -45
- package/lib/CLI/scripts/login-cli.js +6 -2
- package/lib/CLI/scripts/post-init.d.ts +1 -0
- package/lib/CLI/scripts/post-init.js +42 -0
- package/lib/CLI/scripts/upload-cli.d.ts +2 -0
- package/lib/CLI/scripts/upload-cli.js +11 -5
- package/lib/api/client.d.ts +1 -1
- package/lib/api/client.js +2 -2
- package/lib/api/clientApi.d.ts +3 -6
- package/lib/api/clientApi.js +7 -18
- package/lib/api/types.d.ts +33 -18
- package/lib/bundleInfo.js +5 -5
- package/lib/context.js +3 -3
- package/lib/errors.d.ts +2 -2
- package/lib/fs/bundlePointer.d.ts +14 -0
- package/lib/fs/bundlePointer.js +77 -0
- package/lib/fs/fsUtils.js +13 -13
- package/lib/fs/installId.d.ts +1 -0
- package/lib/fs/installId.js +29 -0
- package/lib/fs/userProperties.d.ts +6 -0
- package/lib/fs/userProperties.js +100 -0
- package/lib/index.d.ts +1 -1
- package/lib/index.js +8 -3
- package/lib/injectImageResolver.js +2 -2
- package/lib/install/installFromZip.js +9 -20
- package/lib/loadConfig.d.ts +5 -0
- package/lib/manager/downloadAndInstall.d.ts +10 -0
- package/lib/manager/downloadAndInstall.js +50 -42
- package/lib/manager/initUpdateManager.js +46 -10
- package/lib/manager/reporting.js +5 -3
- package/lib/manager/rollbackState.d.ts +30 -0
- package/lib/manager/rollbackState.js +186 -0
- package/lib/manager/updateCheck.js +57 -18
- package/lib/native/fs.d.ts +17 -0
- package/lib/native/fs.js +33 -0
- package/lib/scripts/download-bundle.js +19 -8
- package/lib/useBundleDrop.js +14 -2
- package/package.json +3 -4
- package/lib/api/utils.d.ts +0 -1
- package/lib/api/utils.js +0 -8
- package/lib/fs/iosPointer.d.ts +0 -1
- package/lib/fs/iosPointer.js +0 -20
package/lib/api/clientApi.d.ts
CHANGED
|
@@ -1,8 +1,5 @@
|
|
|
1
1
|
import type { AxiosResponse } from 'axios';
|
|
2
|
-
import {
|
|
3
|
-
export declare function
|
|
4
|
-
export declare function getLatestBundleDownloadUrl(params: LatestBundleParams): Promise<AxiosResponse<{
|
|
5
|
-
downloadUrl?: string;
|
|
6
|
-
}>>;
|
|
2
|
+
import { OtaResolveRequest, OtaResolveResponse, PublicChannelsParams, ReportInstalledPayload } from './types';
|
|
3
|
+
export declare function postOtaResolve(projectSlug: string, payload: OtaResolveRequest): Promise<AxiosResponse<OtaResolveResponse>>;
|
|
7
4
|
export declare function getPublicChannels(params: PublicChannelsParams): Promise<AxiosResponse<string[]>>;
|
|
8
|
-
export declare function reportInstalled(hash: string, payload: ReportInstalledPayload): Promise<AxiosResponse<void>>;
|
|
5
|
+
export declare function reportInstalled(projectSlug: string, hash: string, payload: ReportInstalledPayload): Promise<AxiosResponse<void>>;
|
package/lib/api/clientApi.js
CHANGED
|
@@ -1,39 +1,28 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.
|
|
4
|
-
exports.getLatestBundleDownloadUrl = getLatestBundleDownloadUrl;
|
|
3
|
+
exports.postOtaResolve = postOtaResolve;
|
|
5
4
|
exports.getPublicChannels = getPublicChannels;
|
|
6
5
|
exports.reportInstalled = reportInstalled;
|
|
7
6
|
const client_1 = require("./client");
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
const query = (0, utils_1.buildQuery)(params);
|
|
11
|
-
return client_1.apiClient.get(`/bundle/checkForUpdate?${query}`, {
|
|
7
|
+
function postOtaResolve(projectSlug, payload) {
|
|
8
|
+
return client_1.apiClient.post(`/projects/${encodeURIComponent(projectSlug)}/ota/resolve`, payload, {
|
|
12
9
|
headers: {
|
|
13
10
|
Accept: 'application/json',
|
|
14
11
|
},
|
|
15
12
|
timeout: 15000,
|
|
16
13
|
});
|
|
17
14
|
}
|
|
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
15
|
function getPublicChannels(params) {
|
|
27
|
-
const
|
|
28
|
-
return client_1.apiClient.get(`/channels/public
|
|
16
|
+
const { projectSlug } = params;
|
|
17
|
+
return client_1.apiClient.get(`/projects/${encodeURIComponent(projectSlug)}/channels/public`, {
|
|
29
18
|
headers: {
|
|
30
19
|
Accept: 'application/json',
|
|
31
20
|
},
|
|
32
21
|
timeout: 15000,
|
|
33
22
|
});
|
|
34
23
|
}
|
|
35
|
-
function reportInstalled(hash, payload) {
|
|
36
|
-
return client_1.apiClient.post(`/bundle/${encodeURIComponent(hash)}/installed`, payload, {
|
|
24
|
+
function reportInstalled(projectSlug, hash, payload) {
|
|
25
|
+
return client_1.apiClient.post(`/projects/${encodeURIComponent(projectSlug)}/bundle/${encodeURIComponent(hash)}/installed`, payload, {
|
|
37
26
|
headers: {
|
|
38
27
|
Accept: 'application/json',
|
|
39
28
|
},
|
package/lib/api/types.d.ts
CHANGED
|
@@ -1,4 +1,33 @@
|
|
|
1
|
+
export type OtaResolveRequest = {
|
|
2
|
+
channelName: string;
|
|
3
|
+
platform: string;
|
|
4
|
+
runtimeVersion?: string | null;
|
|
5
|
+
currentHash?: string | null;
|
|
6
|
+
currentUserProperties?: string[];
|
|
7
|
+
previousHash?: string | null;
|
|
8
|
+
currentBundleVersion?: number | null;
|
|
9
|
+
installId?: string | null;
|
|
10
|
+
};
|
|
11
|
+
export type OtaResolveResponse = {
|
|
12
|
+
action: 'NOOP';
|
|
13
|
+
reason?: 'UP_TO_DATE' | 'ROLLOUT_PAUSED' | 'ROLLOUT_NOT_ELIGIBLE' | 'NO_PUBLISHED_BUNDLE' | 'NO_COMPATIBLE_BUNDLE';
|
|
14
|
+
requestedRuntimeVersion?: string;
|
|
15
|
+
latestRuntimeVersionOnChannel?: string;
|
|
16
|
+
} | {
|
|
17
|
+
action: 'ROLLBACK';
|
|
18
|
+
reason?: string;
|
|
19
|
+
} | {
|
|
20
|
+
action: 'INSTALL';
|
|
21
|
+
target: {
|
|
22
|
+
hash: string;
|
|
23
|
+
downloadUrl: string;
|
|
24
|
+
bundleVersion?: number;
|
|
25
|
+
version?: string;
|
|
26
|
+
runtimeVersion?: string;
|
|
27
|
+
};
|
|
28
|
+
};
|
|
1
29
|
export type UpdateCheckResponse = {
|
|
30
|
+
action: 'NOOP' | 'INSTALL' | 'ROLLBACK';
|
|
2
31
|
upToDate?: boolean;
|
|
3
32
|
bundleVersion?: number;
|
|
4
33
|
version?: string;
|
|
@@ -8,29 +37,15 @@ export type UpdateCheckResponse = {
|
|
|
8
37
|
reason?: string;
|
|
9
38
|
incompatible?: boolean;
|
|
10
39
|
runtimeVersion?: string;
|
|
11
|
-
|
|
12
|
-
|
|
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;
|
|
40
|
+
requestedRuntimeVersion?: string;
|
|
41
|
+
latestRuntimeVersionOnChannel?: string;
|
|
26
42
|
};
|
|
27
43
|
export type PublicChannelsParams = {
|
|
28
44
|
projectSlug: string;
|
|
29
|
-
orgSlug: string;
|
|
30
45
|
};
|
|
31
46
|
export type ReportInstalledPayload = {
|
|
32
|
-
orgSlug: string;
|
|
33
|
-
projectSlug: string;
|
|
34
47
|
channelName?: string;
|
|
35
48
|
platform?: string;
|
|
49
|
+
installId?: string | null;
|
|
50
|
+
runtimeVersion?: string | null;
|
|
36
51
|
};
|
package/lib/bundleInfo.js
CHANGED
|
@@ -6,13 +6,13 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
6
6
|
exports.readBundleInfo = readBundleInfo;
|
|
7
7
|
exports.writeBundleInfo = writeBundleInfo;
|
|
8
8
|
exports.updateBundleInfo = updateBundleInfo;
|
|
9
|
-
const
|
|
10
|
-
const BUNDLE_INFO_PATH = `${
|
|
9
|
+
const fs_1 = __importDefault(require("./native/fs"));
|
|
10
|
+
const BUNDLE_INFO_PATH = `${fs_1.default.DocumentDirectoryPath}/bundle-info.json`;
|
|
11
11
|
async function readBundleInfo() {
|
|
12
12
|
try {
|
|
13
|
-
if (!(await
|
|
13
|
+
if (!(await fs_1.default.exists(BUNDLE_INFO_PATH)))
|
|
14
14
|
return null;
|
|
15
|
-
const raw = await
|
|
15
|
+
const raw = await fs_1.default.readFile(BUNDLE_INFO_PATH, 'utf8');
|
|
16
16
|
return JSON.parse(raw);
|
|
17
17
|
}
|
|
18
18
|
catch (e) {
|
|
@@ -22,7 +22,7 @@ async function readBundleInfo() {
|
|
|
22
22
|
}
|
|
23
23
|
async function writeBundleInfo(info) {
|
|
24
24
|
try {
|
|
25
|
-
await
|
|
25
|
+
await fs_1.default.writeFile(BUNDLE_INFO_PATH, JSON.stringify(info, null, 2), 'utf8');
|
|
26
26
|
}
|
|
27
27
|
catch (e) {
|
|
28
28
|
console.warn('⚠️ Failed to write bundle-info.json', e);
|
package/lib/context.js
CHANGED
|
@@ -5,12 +5,12 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
6
|
exports.BUNDLE_DROP_ROOT = exports.runtimeVersion = exports.isIOS = exports.platform = exports.config = void 0;
|
|
7
7
|
const react_native_1 = require("react-native");
|
|
8
|
-
const
|
|
8
|
+
const fs_1 = __importDefault(require("./native/fs"));
|
|
9
9
|
const loadConfig_1 = require("./loadConfig");
|
|
10
10
|
exports.config = (0, loadConfig_1.loadConfig)();
|
|
11
11
|
exports.platform = react_native_1.Platform.OS === 'ios' ? 'ios' : 'android';
|
|
12
12
|
exports.isIOS = exports.platform === 'ios';
|
|
13
13
|
exports.runtimeVersion = exports.config.runtimeVersion?.[exports.platform];
|
|
14
14
|
exports.BUNDLE_DROP_ROOT = exports.isIOS
|
|
15
|
-
? `${
|
|
16
|
-
: `${
|
|
15
|
+
? `${fs_1.default.LibraryDirectoryPath}/bundle-drop`
|
|
16
|
+
: `${fs_1.default.DocumentDirectoryPath}/bundle-drop`;
|
package/lib/errors.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
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';
|
|
1
|
+
export type BundleDropErrorCode = 'CHECK_FAILED' | 'RESOLVE_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' | 'resolve' | 'resolveDownloadUrl' | 'download' | 'install' | 'persist' | 'apply';
|
|
3
3
|
export declare class BundleDropError extends Error {
|
|
4
4
|
code: BundleDropErrorCode;
|
|
5
5
|
step: BundleDropErrorStep;
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
export type BundlePointer = {
|
|
2
|
+
hash: string;
|
|
3
|
+
bundlePath: string;
|
|
4
|
+
updatedAt: string;
|
|
5
|
+
};
|
|
6
|
+
export declare function readCurrentBundlePointer(): Promise<BundlePointer | null>;
|
|
7
|
+
export declare function readPreviousBundlePointer(): Promise<BundlePointer | null>;
|
|
8
|
+
export declare function writeCurrentBundlePointer(pointer: BundlePointer): Promise<void>;
|
|
9
|
+
export declare function writePreviousBundlePointer(pointer: BundlePointer): Promise<void>;
|
|
10
|
+
export declare function setCurrentBundlePointer(bundlePath: string, hash: string, options?: {
|
|
11
|
+
setPrevious?: boolean;
|
|
12
|
+
}): Promise<void>;
|
|
13
|
+
export declare function rollbackToPreviousPointer(): Promise<BundlePointer | null>;
|
|
14
|
+
export declare function clearCurrentBundlePointer(): Promise<void>;
|
|
@@ -0,0 +1,77 @@
|
|
|
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.readCurrentBundlePointer = readCurrentBundlePointer;
|
|
7
|
+
exports.readPreviousBundlePointer = readPreviousBundlePointer;
|
|
8
|
+
exports.writeCurrentBundlePointer = writeCurrentBundlePointer;
|
|
9
|
+
exports.writePreviousBundlePointer = writePreviousBundlePointer;
|
|
10
|
+
exports.setCurrentBundlePointer = setCurrentBundlePointer;
|
|
11
|
+
exports.rollbackToPreviousPointer = rollbackToPreviousPointer;
|
|
12
|
+
exports.clearCurrentBundlePointer = clearCurrentBundlePointer;
|
|
13
|
+
const fs_1 = __importDefault(require("../native/fs"));
|
|
14
|
+
const context_1 = require("../context");
|
|
15
|
+
const fsUtils_1 = require("./fsUtils");
|
|
16
|
+
const CURRENT_POINTER_PATH = `${context_1.BUNDLE_DROP_ROOT}/current.json`;
|
|
17
|
+
const PREVIOUS_POINTER_PATH = `${context_1.BUNDLE_DROP_ROOT}/previous.json`;
|
|
18
|
+
async function readPointer(path) {
|
|
19
|
+
try {
|
|
20
|
+
if (!(await fs_1.default.exists(path)))
|
|
21
|
+
return null;
|
|
22
|
+
const raw = await fs_1.default.readFile(path, 'utf8');
|
|
23
|
+
const parsed = JSON.parse(raw);
|
|
24
|
+
if (!parsed?.hash || !parsed?.bundlePath)
|
|
25
|
+
return null;
|
|
26
|
+
return parsed;
|
|
27
|
+
}
|
|
28
|
+
catch {
|
|
29
|
+
return null;
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
async function readCurrentBundlePointer() {
|
|
33
|
+
return readPointer(CURRENT_POINTER_PATH);
|
|
34
|
+
}
|
|
35
|
+
async function readPreviousBundlePointer() {
|
|
36
|
+
return readPointer(PREVIOUS_POINTER_PATH);
|
|
37
|
+
}
|
|
38
|
+
async function writeCurrentBundlePointer(pointer) {
|
|
39
|
+
const root = context_1.BUNDLE_DROP_ROOT;
|
|
40
|
+
await (0, fsUtils_1.ensureDir)(root);
|
|
41
|
+
await (0, fsUtils_1.atomicWriteJson)(CURRENT_POINTER_PATH, pointer);
|
|
42
|
+
}
|
|
43
|
+
async function writePreviousBundlePointer(pointer) {
|
|
44
|
+
const root = context_1.BUNDLE_DROP_ROOT;
|
|
45
|
+
await (0, fsUtils_1.ensureDir)(root);
|
|
46
|
+
await (0, fsUtils_1.atomicWriteJson)(PREVIOUS_POINTER_PATH, pointer);
|
|
47
|
+
}
|
|
48
|
+
async function setCurrentBundlePointer(bundlePath, hash, options) {
|
|
49
|
+
const root = context_1.BUNDLE_DROP_ROOT;
|
|
50
|
+
await (0, fsUtils_1.ensureDir)(root);
|
|
51
|
+
const current = await readCurrentBundlePointer();
|
|
52
|
+
if (options?.setPrevious !== false && current?.hash && current?.bundlePath) {
|
|
53
|
+
await writePreviousBundlePointer({ ...current, updatedAt: new Date().toISOString() });
|
|
54
|
+
}
|
|
55
|
+
await writeCurrentBundlePointer({
|
|
56
|
+
hash,
|
|
57
|
+
bundlePath,
|
|
58
|
+
updatedAt: new Date().toISOString(),
|
|
59
|
+
});
|
|
60
|
+
}
|
|
61
|
+
async function rollbackToPreviousPointer() {
|
|
62
|
+
const previous = await readPreviousBundlePointer();
|
|
63
|
+
if (!previous)
|
|
64
|
+
return null;
|
|
65
|
+
await writeCurrentBundlePointer({ ...previous, updatedAt: new Date().toISOString() });
|
|
66
|
+
return previous;
|
|
67
|
+
}
|
|
68
|
+
async function clearCurrentBundlePointer() {
|
|
69
|
+
try {
|
|
70
|
+
if (await fs_1.default.exists(CURRENT_POINTER_PATH)) {
|
|
71
|
+
await fs_1.default.unlink(CURRENT_POINTER_PATH);
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
catch {
|
|
75
|
+
// ignore
|
|
76
|
+
}
|
|
77
|
+
}
|
package/lib/fs/fsUtils.js
CHANGED
|
@@ -7,32 +7,32 @@ exports.ensureDir = ensureDir;
|
|
|
7
7
|
exports.atomicWriteJson = atomicWriteJson;
|
|
8
8
|
exports.ensureParentDir = ensureParentDir;
|
|
9
9
|
exports.writeFileAtomicBase64 = writeFileAtomicBase64;
|
|
10
|
-
const
|
|
10
|
+
const fs_1 = __importDefault(require("../native/fs"));
|
|
11
11
|
async function ensureDir(dir) {
|
|
12
|
-
if (!(await
|
|
13
|
-
await
|
|
12
|
+
if (!(await fs_1.default.exists(dir))) {
|
|
13
|
+
await fs_1.default.mkdir(dir);
|
|
14
14
|
}
|
|
15
15
|
}
|
|
16
16
|
async function atomicWriteJson(path, data) {
|
|
17
17
|
const tmp = `${path}.tmp`;
|
|
18
|
-
await
|
|
19
|
-
if (await
|
|
20
|
-
await
|
|
18
|
+
await fs_1.default.writeFile(tmp, JSON.stringify(data), 'utf8');
|
|
19
|
+
if (await fs_1.default.exists(path)) {
|
|
20
|
+
await fs_1.default.unlink(path);
|
|
21
21
|
}
|
|
22
|
-
await
|
|
22
|
+
await fs_1.default.moveFile(tmp, path);
|
|
23
23
|
}
|
|
24
24
|
async function ensureParentDir(filePath) {
|
|
25
25
|
const dir = filePath.substring(0, filePath.lastIndexOf('/'));
|
|
26
|
-
if (!(await
|
|
27
|
-
await
|
|
26
|
+
if (!(await fs_1.default.exists(dir))) {
|
|
27
|
+
await fs_1.default.mkdir(dir);
|
|
28
28
|
}
|
|
29
29
|
}
|
|
30
30
|
async function writeFileAtomicBase64(path, base64) {
|
|
31
31
|
const tmp = `${path}.tmp`;
|
|
32
32
|
await ensureParentDir(path);
|
|
33
|
-
await
|
|
34
|
-
if (await
|
|
35
|
-
await
|
|
33
|
+
await fs_1.default.writeFile(tmp, base64, 'base64');
|
|
34
|
+
if (await fs_1.default.exists(path)) {
|
|
35
|
+
await fs_1.default.unlink(path);
|
|
36
36
|
}
|
|
37
|
-
await
|
|
37
|
+
await fs_1.default.moveFile(tmp, path);
|
|
38
38
|
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function getOrCreateInstallId(): Promise<string>;
|
|
@@ -0,0 +1,29 @@
|
|
|
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.getOrCreateInstallId = getOrCreateInstallId;
|
|
7
|
+
const fs_1 = __importDefault(require("../native/fs"));
|
|
8
|
+
const context_1 = require("../context");
|
|
9
|
+
const fsUtils_1 = require("./fsUtils");
|
|
10
|
+
function getInstallIdPath() {
|
|
11
|
+
return `${context_1.BUNDLE_DROP_ROOT}/install-id.txt`;
|
|
12
|
+
}
|
|
13
|
+
async function getOrCreateInstallId() {
|
|
14
|
+
const path = getInstallIdPath();
|
|
15
|
+
try {
|
|
16
|
+
const existing = await fs_1.default.readFile(path, 'utf8');
|
|
17
|
+
if (existing?.trim())
|
|
18
|
+
return existing.trim();
|
|
19
|
+
}
|
|
20
|
+
catch {
|
|
21
|
+
// ignore and create a new one
|
|
22
|
+
}
|
|
23
|
+
const id = `${Date.now().toString(36)}-` +
|
|
24
|
+
`${Math.random().toString(36).slice(2, 10)}-` +
|
|
25
|
+
`${Math.random().toString(36).slice(2, 10)}`;
|
|
26
|
+
await (0, fsUtils_1.ensureDir)(context_1.BUNDLE_DROP_ROOT);
|
|
27
|
+
await fs_1.default.writeFile(path, id, 'utf8');
|
|
28
|
+
return id;
|
|
29
|
+
}
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
export declare function getCurrentUserProperties(): Promise<string[]>;
|
|
2
|
+
export declare function getUserProperties(): Promise<string[]>;
|
|
3
|
+
export declare function setUserProperty(value: string): Promise<string[]>;
|
|
4
|
+
export declare function removeUserProperty(value: string): Promise<string[]>;
|
|
5
|
+
export declare function resetUserProperties(): Promise<void>;
|
|
6
|
+
export declare const setUserPropery: typeof setUserProperty;
|
|
@@ -0,0 +1,100 @@
|
|
|
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.setUserPropery = void 0;
|
|
7
|
+
exports.getCurrentUserProperties = getCurrentUserProperties;
|
|
8
|
+
exports.getUserProperties = getUserProperties;
|
|
9
|
+
exports.setUserProperty = setUserProperty;
|
|
10
|
+
exports.removeUserProperty = removeUserProperty;
|
|
11
|
+
exports.resetUserProperties = resetUserProperties;
|
|
12
|
+
const fs_1 = __importDefault(require("../native/fs"));
|
|
13
|
+
const context_1 = require("../context");
|
|
14
|
+
const fsUtils_1 = require("./fsUtils");
|
|
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
|
+
async function writeUserProperties(properties) {
|
|
31
|
+
await (0, fsUtils_1.ensureDir)(context_1.BUNDLE_DROP_ROOT);
|
|
32
|
+
const payload = {
|
|
33
|
+
properties: unique(properties),
|
|
34
|
+
};
|
|
35
|
+
await (0, fsUtils_1.atomicWriteJson)(USER_PROPERTIES_PATH, payload);
|
|
36
|
+
}
|
|
37
|
+
async function getCurrentUserProperties() {
|
|
38
|
+
try {
|
|
39
|
+
if (!(await fs_1.default.exists(USER_PROPERTIES_PATH)))
|
|
40
|
+
return [];
|
|
41
|
+
const raw = await fs_1.default.readFile(USER_PROPERTIES_PATH, 'utf8');
|
|
42
|
+
const parsed = JSON.parse(raw);
|
|
43
|
+
if (Array.isArray(parsed)) {
|
|
44
|
+
return unique(parsed.filter(value => typeof value === 'string').map(normalizeUserProperty).filter(Boolean));
|
|
45
|
+
}
|
|
46
|
+
const values = parsed?.properties;
|
|
47
|
+
if (!Array.isArray(values))
|
|
48
|
+
return [];
|
|
49
|
+
return unique(values.filter(value => typeof value === 'string').map(normalizeUserProperty).filter(Boolean));
|
|
50
|
+
}
|
|
51
|
+
catch (e) {
|
|
52
|
+
console.warn('⚠️ Failed to read user-properties.json', e);
|
|
53
|
+
return [];
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
async function getUserProperties() {
|
|
57
|
+
return getCurrentUserProperties();
|
|
58
|
+
}
|
|
59
|
+
async function setUserProperty(value) {
|
|
60
|
+
const normalized = normalizeUserProperty(value);
|
|
61
|
+
if (!normalized) {
|
|
62
|
+
return getCurrentUserProperties();
|
|
63
|
+
}
|
|
64
|
+
const existing = await getCurrentUserProperties();
|
|
65
|
+
if (existing.includes(normalized)) {
|
|
66
|
+
return existing;
|
|
67
|
+
}
|
|
68
|
+
const next = [...existing, normalized];
|
|
69
|
+
await writeUserProperties(next);
|
|
70
|
+
return next;
|
|
71
|
+
}
|
|
72
|
+
async function removeUserProperty(value) {
|
|
73
|
+
const normalized = normalizeUserProperty(value);
|
|
74
|
+
if (!normalized) {
|
|
75
|
+
return getCurrentUserProperties();
|
|
76
|
+
}
|
|
77
|
+
const existing = await getCurrentUserProperties();
|
|
78
|
+
const next = existing.filter(item => item !== normalized);
|
|
79
|
+
if (next.length === existing.length) {
|
|
80
|
+
return existing;
|
|
81
|
+
}
|
|
82
|
+
if (next.length === 0) {
|
|
83
|
+
await resetUserProperties();
|
|
84
|
+
return [];
|
|
85
|
+
}
|
|
86
|
+
await writeUserProperties(next);
|
|
87
|
+
return next;
|
|
88
|
+
}
|
|
89
|
+
async function resetUserProperties() {
|
|
90
|
+
try {
|
|
91
|
+
if (await fs_1.default.exists(USER_PROPERTIES_PATH)) {
|
|
92
|
+
await fs_1.default.unlink(USER_PROPERTIES_PATH);
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
catch (e) {
|
|
96
|
+
console.warn('⚠️ Failed to reset user-properties.json', e);
|
|
97
|
+
}
|
|
98
|
+
}
|
|
99
|
+
// Backward-compatible alias for the requested API name.
|
|
100
|
+
exports.setUserPropery = setUserProperty;
|
package/lib/index.d.ts
CHANGED
|
@@ -3,8 +3,8 @@ export { getAvailableChannels, checkForUpdate, getInstalledBundleInfo } from './
|
|
|
3
3
|
export { downloadUpdate } from './manager/downloadAndInstall';
|
|
4
4
|
export { getUpdateState, applyUpdate } from './manager/updateState';
|
|
5
5
|
export { initUpdateManager } from './manager/initUpdateManager';
|
|
6
|
-
export { getDownloadedBundlePathNative as getDownloadedBundlePath } from './native/bundleDropNative';
|
|
7
6
|
export { BundleDropError, isBundleDropError } from './errors';
|
|
7
|
+
export { getCurrentUserProperties, getUserProperties, setUserProperty, setUserPropery, removeUserProperty, resetUserProperties, } from './fs/userProperties';
|
|
8
8
|
export type { BundleInfo } from './bundleInfo';
|
|
9
9
|
export type { UpdatePolicy } from './types';
|
|
10
10
|
export { useBundleDrop } from './useBundleDrop';
|
package/lib/index.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.useBundleDrop = exports.
|
|
3
|
+
exports.useBundleDrop = exports.resetUserProperties = exports.removeUserProperty = exports.setUserPropery = exports.setUserProperty = exports.getUserProperties = exports.getCurrentUserProperties = exports.isBundleDropError = exports.BundleDropError = exports.initUpdateManager = exports.applyUpdate = exports.getUpdateState = exports.downloadUpdate = 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; } });
|
|
@@ -13,10 +13,15 @@ Object.defineProperty(exports, "getUpdateState", { enumerable: true, get: functi
|
|
|
13
13
|
Object.defineProperty(exports, "applyUpdate", { enumerable: true, get: function () { return updateState_1.applyUpdate; } });
|
|
14
14
|
var initUpdateManager_1 = require("./manager/initUpdateManager");
|
|
15
15
|
Object.defineProperty(exports, "initUpdateManager", { enumerable: true, get: function () { return initUpdateManager_1.initUpdateManager; } });
|
|
16
|
-
var bundleDropNative_1 = require("./native/bundleDropNative");
|
|
17
|
-
Object.defineProperty(exports, "getDownloadedBundlePath", { enumerable: true, get: function () { return bundleDropNative_1.getDownloadedBundlePathNative; } });
|
|
18
16
|
var errors_1 = require("./errors");
|
|
19
17
|
Object.defineProperty(exports, "BundleDropError", { enumerable: true, get: function () { return errors_1.BundleDropError; } });
|
|
20
18
|
Object.defineProperty(exports, "isBundleDropError", { enumerable: true, get: function () { return errors_1.isBundleDropError; } });
|
|
19
|
+
var userProperties_1 = require("./fs/userProperties");
|
|
20
|
+
Object.defineProperty(exports, "getCurrentUserProperties", { enumerable: true, get: function () { return userProperties_1.getCurrentUserProperties; } });
|
|
21
|
+
Object.defineProperty(exports, "getUserProperties", { enumerable: true, get: function () { return userProperties_1.getUserProperties; } });
|
|
22
|
+
Object.defineProperty(exports, "setUserProperty", { enumerable: true, get: function () { return userProperties_1.setUserProperty; } });
|
|
23
|
+
Object.defineProperty(exports, "setUserPropery", { enumerable: true, get: function () { return userProperties_1.setUserPropery; } });
|
|
24
|
+
Object.defineProperty(exports, "removeUserProperty", { enumerable: true, get: function () { return userProperties_1.removeUserProperty; } });
|
|
25
|
+
Object.defineProperty(exports, "resetUserProperties", { enumerable: true, get: function () { return userProperties_1.resetUserProperties; } });
|
|
21
26
|
var useBundleDrop_1 = require("./useBundleDrop");
|
|
22
27
|
Object.defineProperty(exports, "useBundleDrop", { enumerable: true, get: function () { return useBundleDrop_1.useBundleDrop; } });
|
|
@@ -6,7 +6,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
6
6
|
exports.patchImageResolverWithManifest = patchImageResolverWithManifest;
|
|
7
7
|
exports.injectBundleDropImageResolver = injectBundleDropImageResolver;
|
|
8
8
|
const react_native_1 = require("react-native");
|
|
9
|
-
const
|
|
9
|
+
const fs_1 = __importDefault(require("./native/fs"));
|
|
10
10
|
let hasPatched = false;
|
|
11
11
|
const { BundleDrop } = react_native_1.NativeModules;
|
|
12
12
|
// Build lookup maps: exact keys and basename aliases so we can resolve filename-only URIs.
|
|
@@ -89,7 +89,7 @@ function patchImageResolverWithManifest(manifest) {
|
|
|
89
89
|
}
|
|
90
90
|
if (finalPath) {
|
|
91
91
|
const hasExtension = /\.[a-zA-Z0-9]+$/.test(finalPath);
|
|
92
|
-
const fullPath = `file://${
|
|
92
|
+
const fullPath = `file://${fs_1.default.DocumentDirectoryPath}/${finalPath}${hasExtension ? '' : (uri.match(/\.[^.]+$/)?.[0] ?? '')}`;
|
|
93
93
|
console.log(`🧩 Overriding asset path: ${uri} → ${fullPath}`);
|
|
94
94
|
return { ...resolved, uri: fullPath };
|
|
95
95
|
}
|
|
@@ -6,7 +6,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
6
6
|
exports.installFromZip = installFromZip;
|
|
7
7
|
const buffer_1 = require("buffer");
|
|
8
8
|
const fflate_1 = require("fflate");
|
|
9
|
-
const
|
|
9
|
+
const fs_1 = __importDefault(require("../native/fs"));
|
|
10
10
|
const context_1 = require("../context");
|
|
11
11
|
const image_manifest_1 = require("../image-manifest");
|
|
12
12
|
const injectImageResolver_1 = require("../injectImageResolver");
|
|
@@ -46,41 +46,30 @@ async function installFromZip(params) {
|
|
|
46
46
|
}
|
|
47
47
|
// Build a runtime manifest from extracted assets to handle filename-only resolutions.
|
|
48
48
|
const runtimeManifest = {};
|
|
49
|
-
// Platform-specific bundle location
|
|
50
|
-
const bundleDir =
|
|
51
|
-
|
|
52
|
-
await (0, fsUtils_1.ensureDir)(bundleDir);
|
|
53
|
-
}
|
|
49
|
+
// Platform-specific bundle location (hash-scoped)
|
|
50
|
+
const bundleDir = `${context_1.BUNDLE_DROP_ROOT}/bundles/${resolvedHash}`;
|
|
51
|
+
await (0, fsUtils_1.ensureDir)(bundleDir);
|
|
54
52
|
const bundlePath = `${bundleDir}/main.jsbundle`;
|
|
55
53
|
for (const [filename, fileData] of Object.entries(files)) {
|
|
56
54
|
const dataBuffer = buffer_1.Buffer.from(fileData);
|
|
57
55
|
const base64 = dataBuffer.toString('base64');
|
|
58
56
|
if (filename === 'main.jsbundle') {
|
|
59
57
|
await (0, fsUtils_1.writeFileAtomicBase64)(bundlePath, base64);
|
|
60
|
-
// Legacy copy for iOS fallback (documents/main.jsbundle + assets)
|
|
61
|
-
if (context_1.isIOS) {
|
|
62
|
-
const legacyPath = `${react_native_fs_1.default.DocumentDirectoryPath}/main.jsbundle`;
|
|
63
|
-
await (0, fsUtils_1.writeFileAtomicBase64)(legacyPath, base64);
|
|
64
|
-
}
|
|
65
58
|
continue;
|
|
66
59
|
}
|
|
67
60
|
// Write other files under bundleDir (e.g., metadata, assets)
|
|
68
61
|
const filePath = `${bundleDir}/${filename}`;
|
|
69
62
|
await (0, fsUtils_1.ensureParentDir)(filePath);
|
|
70
|
-
await
|
|
71
|
-
// Legacy copy for iOS assets/metadata into Documents for fallback bundle
|
|
72
|
-
if (context_1.isIOS) {
|
|
73
|
-
const legacyPath = `${react_native_fs_1.default.DocumentDirectoryPath}/${filename}`;
|
|
74
|
-
await (0, fsUtils_1.ensureParentDir)(legacyPath);
|
|
75
|
-
await react_native_fs_1.default.writeFile(legacyPath, base64, 'base64');
|
|
76
|
-
}
|
|
63
|
+
await fs_1.default.writeFile(filePath, base64, 'base64');
|
|
77
64
|
// Collect runtime manifest entries for assets; support paths with or without "assets/" prefix.
|
|
78
65
|
if (filename.includes('drawable') || filename.startsWith('assets/') || filename.startsWith('res/')) {
|
|
79
66
|
const noExt = filename.replace(/\.[^.]+$/, '');
|
|
80
67
|
const base = noExt.split('/').pop();
|
|
81
68
|
const withAssetsPrefix = filename.startsWith('assets/') ? filename : `assets/${filename}`;
|
|
82
|
-
//
|
|
83
|
-
const mappedPath = context_1.isIOS
|
|
69
|
+
// Map to on-disk location relative to DocumentDirectoryPath
|
|
70
|
+
const mappedPath = context_1.isIOS
|
|
71
|
+
? `${resolvedHash}/${filename}`
|
|
72
|
+
: `bundle-drop/bundles/${resolvedHash}/${filename}`;
|
|
84
73
|
runtimeManifest[noExt.replace(/^assets\//, '')] = mappedPath;
|
|
85
74
|
runtimeManifest[withAssetsPrefix.replace(/\.[^.]+$/, '')] = mappedPath;
|
|
86
75
|
if (base && !runtimeManifest[base]) {
|
package/lib/loadConfig.d.ts
CHANGED
|
@@ -13,5 +13,10 @@ export type BundleDropProjectConfig = {
|
|
|
13
13
|
ios: string;
|
|
14
14
|
android: string;
|
|
15
15
|
};
|
|
16
|
+
rollback?: {
|
|
17
|
+
maxCrashCount?: number;
|
|
18
|
+
crashWindowSec?: number;
|
|
19
|
+
commitTimeoutSec?: number;
|
|
20
|
+
};
|
|
16
21
|
};
|
|
17
22
|
export declare function loadConfig(): BundleDropProjectConfig;
|
|
@@ -6,9 +6,19 @@ export type DownloadUpdateResult = {
|
|
|
6
6
|
status: 'upToDate';
|
|
7
7
|
} | {
|
|
8
8
|
status: 'incompatible';
|
|
9
|
+
} | {
|
|
10
|
+
status: 'rollback';
|
|
11
|
+
reason?: string;
|
|
9
12
|
};
|
|
10
13
|
type DownloadOptions = {
|
|
11
14
|
channelName?: string;
|
|
15
|
+
resolvedTarget?: {
|
|
16
|
+
hash: string;
|
|
17
|
+
downloadUrl: string;
|
|
18
|
+
bundleVersion?: number;
|
|
19
|
+
version?: string;
|
|
20
|
+
runtimeVersion?: string;
|
|
21
|
+
};
|
|
12
22
|
};
|
|
13
23
|
export declare const downloadUpdate: (options?: DownloadOptions, onStatusUpdate?: (status: string) => void) => Promise<DownloadUpdateResult>;
|
|
14
24
|
export {};
|