@gfean/react-native-bundle-drop 0.3.2 → 0.3.5
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/BundleDrop.podspec +4 -1
- package/LICENSE +15 -0
- package/README.md +120 -253
- package/android/build.gradle +91 -1
- package/android/gradle.properties +1 -0
- package/android/src/main/java/com/bundledrop/BundleDropFileOps.kt +131 -0
- package/android/src/main/java/com/bundledrop/BundleDropModule.kt +65 -89
- package/android/src/main/java/com/bundledrop/BundleDropOtaResolver.kt +93 -0
- package/ios/BundleDropBridge.m +14 -0
- package/ios/BundleDropFileOps.swift +220 -0
- package/ios/BundleDropLocator.swift +33 -44
- package/ios/BundleDropModule.swift +65 -15
- package/ios/BundleDropOtaResolver.swift +112 -0
- package/ios/BundleDropZipExtractor.h +13 -0
- package/ios/BundleDropZipExtractor.m +226 -0
- package/lib/CLI/cli.js +15 -3
- package/lib/CLI/scripts/init-config.js +12 -5
- package/lib/CLI/scripts/init-native-config.js +17 -9
- package/lib/CLI/scripts/post-init.js +9 -3
- package/lib/CLI/scripts/upload-cli.js +26 -9
- package/lib/api/types.d.ts +4 -3
- package/lib/bundleInfo.d.ts +12 -0
- package/lib/context.d.ts +17 -0
- package/lib/context.js +3 -0
- package/lib/errors.d.ts +25 -0
- package/lib/errors.js +26 -1
- package/lib/fs/fsUtils.d.ts +1 -2
- package/lib/fs/fsUtils.js +12 -27
- package/lib/fs/userProperties.d.ts +25 -4
- package/lib/fs/userProperties.js +51 -7
- package/lib/index.d.ts +1 -0
- package/lib/install/installFromZip.d.ts +1 -1
- package/lib/install/installFromZip.js +47 -42
- package/lib/loadConfig.d.ts +19 -0
- package/lib/loadConfig.js +11 -7
- package/lib/manager/downloadAndInstall.js +7 -25
- package/lib/manager/reporting.js +2 -2
- package/lib/manager/rollbackState.d.ts +3 -3
- package/lib/manager/rollbackState.js +6 -19
- package/lib/manager/updateCheck.js +2 -2
- package/lib/native/fs.d.ts +6 -0
- package/lib/native/fs.js +27 -0
- package/lib/runtime/initState.d.ts +2 -2
- package/lib/runtime/service.js +2 -0
- package/lib/scripts/bundle.js +2 -2
- package/lib/scripts/resolve-ios-version.d.ts +2 -0
- package/lib/scripts/resolve-ios-version.js +74 -0
- package/lib/scripts/upload-bundle.js +10 -4
- package/lib/types.d.ts +3 -0
- package/package.json +53 -16
- package/CLIENT_README.md +0 -411
|
@@ -5,6 +5,9 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
6
|
exports.runPostInitPrompts = runPostInitPrompts;
|
|
7
7
|
const prompts_1 = __importDefault(require("prompts"));
|
|
8
|
+
const DOCS_INSTALLATION_URL = 'https://bundledrop.app/docs/installation';
|
|
9
|
+
const DOCS_METRO_SETUP_URL = `${DOCS_INSTALLATION_URL}#metro-setup`;
|
|
10
|
+
const DOCS_NATIVE_SETUP_URL = `${DOCS_INSTALLATION_URL}#manual-native-setup`;
|
|
8
11
|
async function runPostInitPrompts() {
|
|
9
12
|
// Offer to set up Metro alias for bundle.drop.config.js resolution
|
|
10
13
|
const metroAnswer = await (0, prompts_1.default)({
|
|
@@ -19,7 +22,8 @@ async function runPostInitPrompts() {
|
|
|
19
22
|
await require('./init-metro-config').initMetroConfig();
|
|
20
23
|
}
|
|
21
24
|
catch (err) {
|
|
22
|
-
console.log(`⚠️ Failed to initialize Metro config; please refer to manual setup instructions
|
|
25
|
+
console.log(`⚠️ Failed to initialize Metro config; please refer to manual setup instructions.\n` +
|
|
26
|
+
`See ${DOCS_METRO_SETUP_URL} (${err?.message || err})`);
|
|
23
27
|
}
|
|
24
28
|
}
|
|
25
29
|
// Offer to patch native entrypoints (after Metro prompt finishes)
|
|
@@ -33,10 +37,12 @@ async function runPostInitPrompts() {
|
|
|
33
37
|
try {
|
|
34
38
|
//eslint-disable-next-line
|
|
35
39
|
await require('./init-native-config').initNativeConfig();
|
|
36
|
-
console.log(
|
|
40
|
+
console.log(`⚠️ Please double-check the native changes in MainApplication/AppDelegate.\n` +
|
|
41
|
+
`See ${DOCS_NATIVE_SETUP_URL}`);
|
|
37
42
|
}
|
|
38
43
|
catch (err) {
|
|
39
|
-
console.log(`⚠️ Failed to initialize native config; please refer to manual setup instructions
|
|
44
|
+
console.log(`⚠️ Failed to initialize native config; please refer to manual setup instructions.\n` +
|
|
45
|
+
`See ${DOCS_NATIVE_SETUP_URL} (${err?.message || err})`);
|
|
40
46
|
}
|
|
41
47
|
}
|
|
42
48
|
}
|
|
@@ -44,6 +44,11 @@ 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 resolve_ios_version_1 = require("../../scripts/resolve-ios-version");
|
|
48
|
+
const DOCS_INSTALLATION_URL = 'https://bundledrop.app/docs/installation';
|
|
49
|
+
const DOCS_UPLOADING_URL = 'https://bundledrop.app/docs/uploading';
|
|
50
|
+
const DOCS_CI_CD_URL = 'https://bundledrop.app/docs/ci-cd';
|
|
51
|
+
const DOCS_RUNTIME_VERSION_URL = 'https://bundledrop.app/docs/runtime-version';
|
|
47
52
|
const getPackageRoot = () => process.env.BUNDLE_DROP_PACKAGE_ROOT_OVERRIDE || path.resolve(__dirname, '..', '..', '..');
|
|
48
53
|
async function upload(platform, options) {
|
|
49
54
|
console.log(); // blank line
|
|
@@ -54,7 +59,7 @@ async function upload(platform, options) {
|
|
|
54
59
|
const authPath = path.join(require('os').homedir(), '.bundle-drop', 'auth.json');
|
|
55
60
|
// Validate config
|
|
56
61
|
if (!fs.existsSync(configPath)) {
|
|
57
|
-
ui_1.log.error(
|
|
62
|
+
ui_1.log.error(`❌ bundle.drop.config.js not found in project root\nSee ${DOCS_INSTALLATION_URL}`);
|
|
58
63
|
process.exit(1);
|
|
59
64
|
}
|
|
60
65
|
//eslint-disable-next-line
|
|
@@ -63,14 +68,16 @@ async function upload(platform, options) {
|
|
|
63
68
|
const orgSlug = config.org?.slug;
|
|
64
69
|
const projectSlug = config.project?.slug;
|
|
65
70
|
if (!serverUrl || !projectSlug || !orgSlug) {
|
|
66
|
-
ui_1.log.error(
|
|
71
|
+
ui_1.log.error(`❌ Missing "serverUrl", "org.slug" or "project.slug" in config\nSee ${DOCS_INSTALLATION_URL}`);
|
|
67
72
|
process.exit(1);
|
|
68
73
|
}
|
|
69
74
|
// Resolve auth token: --token flag takes priority over auth.json
|
|
70
75
|
let token = options.token;
|
|
71
76
|
if (!token) {
|
|
72
77
|
if (!fs.existsSync(authPath)) {
|
|
73
|
-
ui_1.log.error(
|
|
78
|
+
ui_1.log.error(`❌ Not authenticated. Please run \`bundle-drop login\` or pass --token.\n` +
|
|
79
|
+
`Local setup: ${DOCS_INSTALLATION_URL}\n` +
|
|
80
|
+
`CI/CD tokens: ${DOCS_CI_CD_URL}`);
|
|
74
81
|
process.exit(1);
|
|
75
82
|
}
|
|
76
83
|
token = JSON.parse(fs.readFileSync(authPath, 'utf-8')).token;
|
|
@@ -110,13 +117,22 @@ async function upload(platform, options) {
|
|
|
110
117
|
if (platform === 'ios') {
|
|
111
118
|
if (!version) {
|
|
112
119
|
if (!options.plistFile) {
|
|
113
|
-
ui_1.log.error(
|
|
120
|
+
ui_1.log.error(`❌ Provide --version or --plist-file for iOS\nSee ${DOCS_UPLOADING_URL}`);
|
|
114
121
|
process.exit(1);
|
|
115
122
|
}
|
|
116
123
|
try {
|
|
117
124
|
const plistContent = fs.readFileSync(options.plistFile, 'utf-8');
|
|
118
125
|
const parsed = plist.parse(plistContent);
|
|
119
|
-
|
|
126
|
+
const rawVersion = parsed.CFBundleShortVersionString;
|
|
127
|
+
if (!rawVersion) {
|
|
128
|
+
ui_1.log.error('❌ Could not find CFBundleShortVersionString in plist');
|
|
129
|
+
process.exit(1);
|
|
130
|
+
}
|
|
131
|
+
const resolved = (0, resolve_ios_version_1.resolveIosPlistVersion)(rawVersion, projectRoot);
|
|
132
|
+
if (!resolved) {
|
|
133
|
+
process.exit(1);
|
|
134
|
+
}
|
|
135
|
+
version = resolved;
|
|
120
136
|
}
|
|
121
137
|
catch (err) {
|
|
122
138
|
ui_1.log.error(`❌ Failed to parse Info.plist: ${err.message}`);
|
|
@@ -135,12 +151,13 @@ async function upload(platform, options) {
|
|
|
135
151
|
version = parseAndroidVersionFromGradle(defaultPath);
|
|
136
152
|
}
|
|
137
153
|
else {
|
|
138
|
-
ui_1.log.error(
|
|
154
|
+
ui_1.log.error(`❌ Provide --version or --buildgradle-path for Android\nSee ${DOCS_UPLOADING_URL}`);
|
|
139
155
|
process.exit(1);
|
|
140
156
|
}
|
|
141
157
|
}
|
|
142
158
|
}
|
|
143
159
|
}
|
|
160
|
+
/* istanbul ignore if -- exhaustive guard; all branches above either set version or exit */
|
|
144
161
|
if (!version) {
|
|
145
162
|
ui_1.log.error('❌ Version could not be determined');
|
|
146
163
|
process.exit(1);
|
|
@@ -152,8 +169,8 @@ async function upload(platform, options) {
|
|
|
152
169
|
const compiledBundleScript = path.join(packageRoot, 'lib', 'scripts', 'bundle.js');
|
|
153
170
|
const tsBundleScript = path.join(packageRoot, 'src', 'scripts', 'bundle.ts');
|
|
154
171
|
const bundleCommand = fs.existsSync(compiledBundleScript)
|
|
155
|
-
? `node ${compiledBundleScript}`
|
|
156
|
-
: `ts-node ${tsBundleScript}`;
|
|
172
|
+
? `node "${compiledBundleScript}"`
|
|
173
|
+
: `ts-node "${tsBundleScript}"`;
|
|
157
174
|
try {
|
|
158
175
|
(0, child_process_1.execSync)(`${bundleCommand} ${platform}`, {
|
|
159
176
|
stdio: 'inherit',
|
|
@@ -185,7 +202,7 @@ async function upload(platform, options) {
|
|
|
185
202
|
ui_1.log.label('Runtime Version (from config)', runtimeVersion);
|
|
186
203
|
}
|
|
187
204
|
if (!runtimeVersion) {
|
|
188
|
-
ui_1.log.error(
|
|
205
|
+
ui_1.log.error(`❌ runtimeVersion could not be determined\nSee ${DOCS_RUNTIME_VERSION_URL}`);
|
|
189
206
|
process.exit(1);
|
|
190
207
|
}
|
|
191
208
|
const zipPath = path.join(outputDir, `bundle-${platform}.zip`);
|
package/lib/api/types.d.ts
CHANGED
|
@@ -1,17 +1,18 @@
|
|
|
1
|
+
import type { UserProperties } from '../fs/userProperties';
|
|
1
2
|
export type OtaResolveRequest = {
|
|
2
3
|
channelName: string;
|
|
3
4
|
platform: string;
|
|
4
5
|
runtimeVersion?: string | null;
|
|
5
6
|
environment?: string | null;
|
|
6
7
|
currentHash?: string | null;
|
|
7
|
-
currentUserProperties?:
|
|
8
|
+
currentUserProperties?: UserProperties;
|
|
8
9
|
previousHash?: string | null;
|
|
9
10
|
currentBundleVersion?: number | null;
|
|
10
11
|
installId?: string | null;
|
|
11
12
|
};
|
|
12
13
|
export type OtaResolveResponse = {
|
|
13
14
|
action: 'NOOP';
|
|
14
|
-
reason?: 'UP_TO_DATE' | 'ROLLOUT_PAUSED' | 'ROLLOUT_NOT_ELIGIBLE' | 'NO_PUBLISHED_BUNDLE' | 'NO_COMPATIBLE_BUNDLE';
|
|
15
|
+
reason?: 'UP_TO_DATE' | 'ROLLOUT_PAUSED' | 'ROLLOUT_NOT_ELIGIBLE' | 'TARGETING_NOT_MATCHED' | 'NO_PUBLISHED_BUNDLE' | 'NO_COMPATIBLE_BUNDLE';
|
|
15
16
|
requestedRuntimeVersion?: string;
|
|
16
17
|
latestRuntimeVersionOnChannel?: string;
|
|
17
18
|
} | {
|
|
@@ -66,7 +67,7 @@ export type ReportInstalledPayload = {
|
|
|
66
67
|
installId?: string | null;
|
|
67
68
|
runtimeVersion?: string | null;
|
|
68
69
|
environment?: string | null;
|
|
69
|
-
userProperties?:
|
|
70
|
+
userProperties?: UserProperties;
|
|
70
71
|
};
|
|
71
72
|
/**
|
|
72
73
|
* Public metadata for a single downloadable bundle returned by the bundle list endpoint.
|
package/lib/bundleInfo.d.ts
CHANGED
|
@@ -1,12 +1,24 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Metadata persisted for the currently downloaded or applied OTA bundle.
|
|
3
|
+
*/
|
|
1
4
|
export type BundleInfo = {
|
|
5
|
+
/** Monotonic bundle version assigned by BundleDrop. */
|
|
2
6
|
bundleVersion?: number;
|
|
7
|
+
/** Optional semantic/app version attached during upload. */
|
|
3
8
|
version?: string;
|
|
9
|
+
/** Immutable bundle hash used for install, reporting, and deduplication. */
|
|
4
10
|
hash?: string;
|
|
11
|
+
/** ISO timestamp for when this bundle metadata was written locally. */
|
|
5
12
|
installedAt?: string;
|
|
13
|
+
/** Channel used when the bundle was downloaded or installed. */
|
|
6
14
|
channelName?: string;
|
|
15
|
+
/** Platform this local metadata belongs to. */
|
|
7
16
|
platform?: 'ios' | 'android';
|
|
17
|
+
/** `true` when the bundle has downloaded but has not yet been applied. */
|
|
8
18
|
pendingApply?: boolean;
|
|
19
|
+
/** Last bundle hash successfully reported to the backend as installed. */
|
|
9
20
|
lastInstalledReportedHash?: string;
|
|
21
|
+
/** Runtime version the bundle is compatible with. */
|
|
10
22
|
runtimeVersion?: string;
|
|
11
23
|
};
|
|
12
24
|
export declare function readBundleInfo(): Promise<BundleInfo | null>;
|
package/lib/context.d.ts
CHANGED
|
@@ -4,23 +4,40 @@ export declare const isIOS: boolean;
|
|
|
4
4
|
export declare const runtimeVersion: string;
|
|
5
5
|
export declare const defaultChannel: string;
|
|
6
6
|
export declare const BUNDLE_DROP_ROOT: string;
|
|
7
|
+
/**
|
|
8
|
+
* Resolved static BundleDrop configuration for the current platform.
|
|
9
|
+
*/
|
|
7
10
|
export type BundleDropConfig = {
|
|
11
|
+
/** BundleDrop backend base URL. */
|
|
8
12
|
serverUrl: string;
|
|
13
|
+
/** Current React Native platform. */
|
|
9
14
|
platform: 'ios' | 'android';
|
|
15
|
+
/** Runtime version configured for the current platform, if present. */
|
|
10
16
|
runtimeVersion: string | undefined;
|
|
17
|
+
/** Default channel used before runtime code sets another channel. */
|
|
11
18
|
defaultChannel: string;
|
|
19
|
+
/** Organization identity used by BundleDrop APIs. */
|
|
12
20
|
org: {
|
|
13
21
|
slug: string;
|
|
14
22
|
};
|
|
23
|
+
/** Project identity used by BundleDrop APIs. */
|
|
15
24
|
project: {
|
|
16
25
|
name: string;
|
|
17
26
|
slug: string;
|
|
18
27
|
};
|
|
28
|
+
/** Whether local debug backend routing is enabled. */
|
|
19
29
|
debugLocal: boolean;
|
|
30
|
+
/** Effective rollback/crash recovery policy with defaults applied. */
|
|
20
31
|
rollback: {
|
|
32
|
+
/** Crash count required before rollback. */
|
|
21
33
|
maxCrashCount: number;
|
|
34
|
+
/** Time window, in seconds, used when counting startup crashes. */
|
|
22
35
|
crashWindowSec: number;
|
|
36
|
+
/** Time, in seconds, after which a candidate bundle is considered stable. */
|
|
23
37
|
commitTimeoutSec: number;
|
|
24
38
|
};
|
|
25
39
|
};
|
|
40
|
+
/**
|
|
41
|
+
* Resolved BundleDrop config for the current platform, derived from `bundle.drop.config.js`.
|
|
42
|
+
*/
|
|
26
43
|
export declare const bundleDropConfig: BundleDropConfig;
|
package/lib/context.js
CHANGED
|
@@ -15,6 +15,9 @@ exports.defaultChannel = exports.config.defaultChannel || 'General';
|
|
|
15
15
|
exports.BUNDLE_DROP_ROOT = exports.isIOS
|
|
16
16
|
? `${fs_1.default.LibraryDirectoryPath}/bundle-drop`
|
|
17
17
|
: `${fs_1.default.DocumentDirectoryPath}/bundle-drop`;
|
|
18
|
+
/**
|
|
19
|
+
* Resolved BundleDrop config for the current platform, derived from `bundle.drop.config.js`.
|
|
20
|
+
*/
|
|
18
21
|
exports.bundleDropConfig = {
|
|
19
22
|
serverUrl: exports.config.serverUrl,
|
|
20
23
|
platform: exports.platform,
|
package/lib/errors.d.ts
CHANGED
|
@@ -1,16 +1,41 @@
|
|
|
1
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
2
|
export type BundleDropErrorStep = 'check' | 'resolve' | 'resolveDownloadUrl' | 'download' | 'install' | 'persist' | 'apply';
|
|
3
|
+
/**
|
|
4
|
+
* Structured error thrown by BundleDrop runtime flows.
|
|
5
|
+
*/
|
|
3
6
|
export declare class BundleDropError extends Error {
|
|
7
|
+
/** Stable machine-readable error code. */
|
|
4
8
|
code: BundleDropErrorCode;
|
|
9
|
+
/** Runtime step where the error occurred. */
|
|
5
10
|
step: BundleDropErrorStep;
|
|
11
|
+
/** Optional diagnostic context for logs or support tooling. */
|
|
6
12
|
context?: Record<string, any>;
|
|
13
|
+
/** Original error or value that caused this error, when available. */
|
|
7
14
|
cause?: unknown;
|
|
15
|
+
/**
|
|
16
|
+
* Create a structured BundleDrop runtime error.
|
|
17
|
+
*/
|
|
8
18
|
constructor(args: {
|
|
19
|
+
/** Human-readable error message. */
|
|
9
20
|
message: string;
|
|
21
|
+
/** Stable machine-readable error code. */
|
|
10
22
|
code: BundleDropErrorCode;
|
|
23
|
+
/** Runtime step where the error occurred. */
|
|
11
24
|
step: BundleDropErrorStep;
|
|
25
|
+
/** Optional diagnostic context for logs or support tooling. */
|
|
12
26
|
context?: Record<string, any>;
|
|
27
|
+
/** Original error or value that caused this error, when available. */
|
|
13
28
|
cause?: unknown;
|
|
14
29
|
});
|
|
15
30
|
}
|
|
31
|
+
/**
|
|
32
|
+
* Type guard for `BundleDropError`.
|
|
33
|
+
*/
|
|
16
34
|
export declare function isBundleDropError(e: unknown): e is BundleDropError;
|
|
35
|
+
export type InstallPhase = 'download' | 'install';
|
|
36
|
+
export declare class InstallPhaseError extends Error {
|
|
37
|
+
phase: InstallPhase;
|
|
38
|
+
originalCause: unknown;
|
|
39
|
+
constructor(phase: InstallPhase, cause: unknown);
|
|
40
|
+
}
|
|
41
|
+
export declare function isInstallPhaseError(e: unknown): e is InstallPhaseError;
|
package/lib/errors.js
CHANGED
|
@@ -1,8 +1,15 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.BundleDropError = void 0;
|
|
3
|
+
exports.InstallPhaseError = exports.BundleDropError = void 0;
|
|
4
4
|
exports.isBundleDropError = isBundleDropError;
|
|
5
|
+
exports.isInstallPhaseError = isInstallPhaseError;
|
|
6
|
+
/**
|
|
7
|
+
* Structured error thrown by BundleDrop runtime flows.
|
|
8
|
+
*/
|
|
5
9
|
class BundleDropError extends Error {
|
|
10
|
+
/**
|
|
11
|
+
* Create a structured BundleDrop runtime error.
|
|
12
|
+
*/
|
|
6
13
|
constructor(args) {
|
|
7
14
|
super(args.message);
|
|
8
15
|
this.name = 'BundleDropError';
|
|
@@ -13,6 +20,24 @@ class BundleDropError extends Error {
|
|
|
13
20
|
}
|
|
14
21
|
}
|
|
15
22
|
exports.BundleDropError = BundleDropError;
|
|
23
|
+
/**
|
|
24
|
+
* Type guard for `BundleDropError`.
|
|
25
|
+
*/
|
|
16
26
|
function isBundleDropError(e) {
|
|
17
27
|
return !!e && typeof e === 'object' && e.name === 'BundleDropError';
|
|
18
28
|
}
|
|
29
|
+
class InstallPhaseError extends Error {
|
|
30
|
+
constructor(phase, cause) {
|
|
31
|
+
const msg = cause instanceof Error ? cause.message : String(cause);
|
|
32
|
+
super(msg);
|
|
33
|
+
this.name = 'InstallPhaseError';
|
|
34
|
+
this.phase = phase;
|
|
35
|
+
this.originalCause = cause;
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
exports.InstallPhaseError = InstallPhaseError;
|
|
39
|
+
function isInstallPhaseError(e) {
|
|
40
|
+
return !!e && typeof e === 'object' &&
|
|
41
|
+
e.name === 'InstallPhaseError' &&
|
|
42
|
+
typeof e.phase === 'string';
|
|
43
|
+
}
|
package/lib/fs/fsUtils.d.ts
CHANGED
|
@@ -1,4 +1,3 @@
|
|
|
1
|
+
export declare function cleanOrphanedTempZips(bundlesDir: string): Promise<number>;
|
|
1
2
|
export declare function ensureDir(dir: string): Promise<void>;
|
|
2
3
|
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>;
|
package/lib/fs/fsUtils.js
CHANGED
|
@@ -3,46 +3,30 @@ 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.cleanOrphanedTempZips = cleanOrphanedTempZips;
|
|
6
7
|
exports.ensureDir = ensureDir;
|
|
7
8
|
exports.atomicWriteJson = atomicWriteJson;
|
|
8
|
-
exports.ensureParentDir = ensureParentDir;
|
|
9
|
-
exports.writeFileAtomicBase64 = writeFileAtomicBase64;
|
|
10
9
|
const fs_1 = __importDefault(require("../native/fs"));
|
|
11
|
-
async function
|
|
12
|
-
if (!(await fs_1.default.exists(dir))) {
|
|
13
|
-
await fs_1.default.mkdir(dir);
|
|
14
|
-
}
|
|
15
|
-
}
|
|
16
|
-
async function atomicWriteJson(path, data) {
|
|
17
|
-
const tmp = `${path}.${Date.now()}_${Math.random().toString(36).slice(2, 8)}.tmp`;
|
|
10
|
+
async function cleanOrphanedTempZips(bundlesDir) {
|
|
18
11
|
try {
|
|
19
|
-
await fs_1.default.
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
catch { /* already removed by concurrent writer */ }
|
|
24
|
-
await fs_1.default.moveFile(tmp, path);
|
|
12
|
+
const entries = await fs_1.default.readDir(bundlesDir);
|
|
13
|
+
const temps = entries.filter(n => n.startsWith('_tmp_') && n.endsWith('.zip'));
|
|
14
|
+
await Promise.all(temps.map(name => fs_1.default.unlink(`${bundlesDir}/${name}`)));
|
|
15
|
+
return temps.length;
|
|
25
16
|
}
|
|
26
17
|
catch {
|
|
27
|
-
|
|
28
|
-
await fs_1.default.writeFile(path, JSON.stringify(data), 'utf8');
|
|
29
|
-
try {
|
|
30
|
-
await fs_1.default.unlink(tmp);
|
|
31
|
-
}
|
|
32
|
-
catch { /* clean up orphaned tmp if it exists */ }
|
|
18
|
+
return 0;
|
|
33
19
|
}
|
|
34
20
|
}
|
|
35
|
-
async function
|
|
36
|
-
const dir = filePath.substring(0, filePath.lastIndexOf('/'));
|
|
21
|
+
async function ensureDir(dir) {
|
|
37
22
|
if (!(await fs_1.default.exists(dir))) {
|
|
38
23
|
await fs_1.default.mkdir(dir);
|
|
39
24
|
}
|
|
40
25
|
}
|
|
41
|
-
async function
|
|
26
|
+
async function atomicWriteJson(path, data) {
|
|
42
27
|
const tmp = `${path}.${Date.now()}_${Math.random().toString(36).slice(2, 8)}.tmp`;
|
|
43
|
-
await ensureParentDir(path);
|
|
44
28
|
try {
|
|
45
|
-
await fs_1.default.writeFile(tmp,
|
|
29
|
+
await fs_1.default.writeFile(tmp, JSON.stringify(data), 'utf8');
|
|
46
30
|
try {
|
|
47
31
|
await fs_1.default.unlink(path);
|
|
48
32
|
}
|
|
@@ -50,7 +34,8 @@ async function writeFileAtomicBase64(path, base64) {
|
|
|
50
34
|
await fs_1.default.moveFile(tmp, path);
|
|
51
35
|
}
|
|
52
36
|
catch {
|
|
53
|
-
|
|
37
|
+
// Atomic rename failed (concurrent writer moved/removed our tmp); fall back to direct write.
|
|
38
|
+
await fs_1.default.writeFile(path, JSON.stringify(data), 'utf8');
|
|
54
39
|
try {
|
|
55
40
|
await fs_1.default.unlink(tmp);
|
|
56
41
|
}
|
|
@@ -1,7 +1,28 @@
|
|
|
1
|
-
export
|
|
2
|
-
export
|
|
3
|
-
|
|
4
|
-
|
|
1
|
+
export type UserPropertyValue = string | number | boolean;
|
|
2
|
+
export type UserProperties = Record<string, UserPropertyValue>;
|
|
3
|
+
/**
|
|
4
|
+
* Read user properties that will be sent with OTA resolve requests.
|
|
5
|
+
*/
|
|
6
|
+
export declare function getCurrentUserProperties(): Promise<UserProperties>;
|
|
7
|
+
/**
|
|
8
|
+
* Alias for `getCurrentUserProperties()`.
|
|
9
|
+
*/
|
|
10
|
+
export declare function getUserProperties(): Promise<UserProperties>;
|
|
11
|
+
/**
|
|
12
|
+
* Set or replace one user property used for targeting future OTA resolve requests.
|
|
13
|
+
*
|
|
14
|
+
* Empty keys are ignored and return the current property map unchanged.
|
|
15
|
+
*/
|
|
16
|
+
export declare function setUserProperty(key: string, value: UserPropertyValue): Promise<UserProperties>;
|
|
17
|
+
/**
|
|
18
|
+
* Remove one user property used for targeting future OTA resolve requests.
|
|
19
|
+
*
|
|
20
|
+
* Empty or missing keys are ignored and return the current property map unchanged.
|
|
21
|
+
*/
|
|
22
|
+
export declare function removeUserProperty(key: string): Promise<UserProperties>;
|
|
23
|
+
/**
|
|
24
|
+
* Clear all locally stored user properties.
|
|
25
|
+
*/
|
|
5
26
|
export declare function resetUserProperties(): Promise<void>;
|
|
6
27
|
/** @deprecated Use setUserProperty(key, value) instead. */
|
|
7
28
|
export declare const setUserPropery: typeof setUserProperty;
|
package/lib/fs/userProperties.js
CHANGED
|
@@ -13,11 +13,31 @@ const fs_1 = __importDefault(require("../native/fs"));
|
|
|
13
13
|
const context_1 = require("../context");
|
|
14
14
|
const fsUtils_1 = require("./fsUtils");
|
|
15
15
|
const USER_PROPERTIES_PATH = `${context_1.BUNDLE_DROP_ROOT}/user-properties.json`;
|
|
16
|
+
const MAX_USER_PROPERTY_KEY_LENGTH = 128;
|
|
17
|
+
const RESERVED_USER_PROPERTY_KEYS = new Set(['__proto__', 'constructor', 'prototype']);
|
|
18
|
+
const normalizeUserPropertyValue = (value) => {
|
|
19
|
+
if (typeof value === 'string')
|
|
20
|
+
return value;
|
|
21
|
+
if (typeof value === 'number' && Number.isFinite(value))
|
|
22
|
+
return value;
|
|
23
|
+
if (typeof value === 'boolean')
|
|
24
|
+
return value;
|
|
25
|
+
return null;
|
|
26
|
+
};
|
|
27
|
+
const isValidUserPropertyKey = (key) => key.length > 0 &&
|
|
28
|
+
key.length <= MAX_USER_PROPERTY_KEY_LENGTH &&
|
|
29
|
+
!key.startsWith('$') &&
|
|
30
|
+
!key.includes('.') &&
|
|
31
|
+
!key.includes('\0') &&
|
|
32
|
+
!RESERVED_USER_PROPERTY_KEYS.has(key);
|
|
16
33
|
async function writeUserProperties(properties) {
|
|
17
34
|
await (0, fsUtils_1.ensureDir)(context_1.BUNDLE_DROP_ROOT);
|
|
18
35
|
const payload = { properties: { ...properties } };
|
|
19
36
|
await (0, fsUtils_1.atomicWriteJson)(USER_PROPERTIES_PATH, payload);
|
|
20
37
|
}
|
|
38
|
+
/**
|
|
39
|
+
* Read user properties that will be sent with OTA resolve requests.
|
|
40
|
+
*/
|
|
21
41
|
async function getCurrentUserProperties() {
|
|
22
42
|
try {
|
|
23
43
|
if (!(await fs_1.default.exists(USER_PROPERTIES_PATH)))
|
|
@@ -29,11 +49,12 @@ async function getCurrentUserProperties() {
|
|
|
29
49
|
return {};
|
|
30
50
|
const result = {};
|
|
31
51
|
for (const [k, v] of Object.entries(props)) {
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
52
|
+
const key = k.trim();
|
|
53
|
+
if (!isValidUserPropertyKey(key))
|
|
54
|
+
continue;
|
|
55
|
+
const value = normalizeUserPropertyValue(v);
|
|
56
|
+
if (value !== null)
|
|
57
|
+
result[key] = value;
|
|
37
58
|
}
|
|
38
59
|
return result;
|
|
39
60
|
}
|
|
@@ -42,22 +63,42 @@ async function getCurrentUserProperties() {
|
|
|
42
63
|
return {};
|
|
43
64
|
}
|
|
44
65
|
}
|
|
66
|
+
/**
|
|
67
|
+
* Alias for `getCurrentUserProperties()`.
|
|
68
|
+
*/
|
|
45
69
|
async function getUserProperties() {
|
|
46
70
|
return getCurrentUserProperties();
|
|
47
71
|
}
|
|
72
|
+
/**
|
|
73
|
+
* Set or replace one user property used for targeting future OTA resolve requests.
|
|
74
|
+
*
|
|
75
|
+
* Empty keys are ignored and return the current property map unchanged.
|
|
76
|
+
*/
|
|
48
77
|
async function setUserProperty(key, value) {
|
|
49
78
|
const trimmedKey = key.trim();
|
|
50
79
|
if (!trimmedKey) {
|
|
51
80
|
return getCurrentUserProperties();
|
|
52
81
|
}
|
|
82
|
+
if (!isValidUserPropertyKey(trimmedKey)) {
|
|
83
|
+
throw new TypeError('User property key is invalid');
|
|
84
|
+
}
|
|
85
|
+
const normalizedValue = normalizeUserPropertyValue(value);
|
|
86
|
+
if (normalizedValue === null) {
|
|
87
|
+
throw new TypeError('User property value must be a string, number, or boolean');
|
|
88
|
+
}
|
|
53
89
|
const existing = await getCurrentUserProperties();
|
|
54
|
-
if (existing[trimmedKey] ===
|
|
90
|
+
if (existing[trimmedKey] === normalizedValue) {
|
|
55
91
|
return existing;
|
|
56
92
|
}
|
|
57
|
-
const next = { ...existing, [trimmedKey]:
|
|
93
|
+
const next = { ...existing, [trimmedKey]: normalizedValue };
|
|
58
94
|
await writeUserProperties(next);
|
|
59
95
|
return next;
|
|
60
96
|
}
|
|
97
|
+
/**
|
|
98
|
+
* Remove one user property used for targeting future OTA resolve requests.
|
|
99
|
+
*
|
|
100
|
+
* Empty or missing keys are ignored and return the current property map unchanged.
|
|
101
|
+
*/
|
|
61
102
|
async function removeUserProperty(key) {
|
|
62
103
|
const trimmedKey = key.trim();
|
|
63
104
|
if (!trimmedKey) {
|
|
@@ -75,6 +116,9 @@ async function removeUserProperty(key) {
|
|
|
75
116
|
await writeUserProperties(next);
|
|
76
117
|
return next;
|
|
77
118
|
}
|
|
119
|
+
/**
|
|
120
|
+
* Clear all locally stored user properties.
|
|
121
|
+
*/
|
|
78
122
|
async function resetUserProperties() {
|
|
79
123
|
try {
|
|
80
124
|
if (await fs_1.default.exists(USER_PROPERTIES_PATH)) {
|
package/lib/index.d.ts
CHANGED
|
@@ -5,6 +5,7 @@ export type { AvailableBundlesPage, GetAvailableBundlesOptions } from './manager
|
|
|
5
5
|
export { downloadUpdate, installBundle, getRuntimeUpdateState as getUpdateState, applyUpdate, setChannel, getChannelName, } from './runtime/service';
|
|
6
6
|
export { BundleDropError, isBundleDropError } from './errors';
|
|
7
7
|
export { getCurrentUserProperties, getUserProperties, setUserProperty, setUserPropery, removeUserProperty, resetUserProperties, } from './fs/userProperties';
|
|
8
|
+
export type { UserProperties, UserPropertyValue } from './fs/userProperties';
|
|
8
9
|
export type { BundleInfo } from './bundleInfo';
|
|
9
10
|
export type { UpdatePolicy } from './types';
|
|
10
11
|
export type { BundleListItem } from './api/types';
|