@gfean/react-native-bundle-drop 0.3.3 → 0.3.6

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.
Files changed (84) hide show
  1. package/BundleDrop.podspec +2 -0
  2. package/README.md +8 -2
  3. package/android/build.gradle +91 -1
  4. package/android/gradle.properties +1 -0
  5. package/android/src/main/java/com/bundledrop/BundleDropFileOps.kt +131 -0
  6. package/android/src/main/java/com/bundledrop/BundleDropModule.kt +65 -89
  7. package/android/src/main/java/com/bundledrop/BundleDropOtaResolver.kt +93 -0
  8. package/ios/BundleDropBridge.m +14 -0
  9. package/ios/BundleDropFileOps.swift +220 -0
  10. package/ios/BundleDropLocator.h +11 -0
  11. package/ios/BundleDropLocator.swift +34 -45
  12. package/ios/BundleDropModule.swift +65 -15
  13. package/ios/BundleDropOtaResolver.swift +112 -0
  14. package/ios/BundleDropZipExtractor.h +13 -0
  15. package/ios/BundleDropZipExtractor.m +226 -0
  16. package/lib/CLI/cli.js +56 -6
  17. package/lib/CLI/scripts/aipowered/apply-plan.d.ts +10 -0
  18. package/lib/CLI/scripts/aipowered/apply-plan.js +50 -0
  19. package/lib/CLI/scripts/aipowered/backend-client.d.ts +6 -0
  20. package/lib/CLI/scripts/aipowered/backend-client.js +34 -0
  21. package/lib/CLI/scripts/aipowered/diff-preview.d.ts +7 -0
  22. package/lib/CLI/scripts/aipowered/diff-preview.js +33 -0
  23. package/lib/CLI/scripts/aipowered/init-native-config.d.ts +2 -0
  24. package/lib/CLI/scripts/aipowered/init-native-config.js +131 -0
  25. package/lib/CLI/scripts/aipowered/scanner.d.ts +5 -0
  26. package/lib/CLI/scripts/aipowered/scanner.js +349 -0
  27. package/lib/CLI/scripts/aipowered/types.d.ts +53 -0
  28. package/lib/CLI/scripts/aipowered/types.js +2 -0
  29. package/lib/CLI/scripts/aipowered/validate-plan.d.ts +8 -0
  30. package/lib/CLI/scripts/aipowered/validate-plan.js +164 -0
  31. package/lib/CLI/scripts/init-config.js +10 -5
  32. package/lib/CLI/scripts/init-native-config.js +1 -1
  33. package/lib/CLI/scripts/post-init.js +7 -18
  34. package/lib/CLI/scripts/upload-cli.d.ts +2 -0
  35. package/lib/CLI/scripts/upload-cli.js +67 -28
  36. package/lib/CLI/utils/ui.d.ts +3 -0
  37. package/lib/CLI/utils/ui.js +26 -0
  38. package/lib/api/clientApi.d.ts +2 -1
  39. package/lib/api/clientApi.js +9 -0
  40. package/lib/api/types.d.ts +21 -3
  41. package/lib/bundleInfo.d.ts +12 -0
  42. package/lib/context.d.ts +19 -2
  43. package/lib/context.js +5 -2
  44. package/lib/errors.d.ts +25 -0
  45. package/lib/errors.js +26 -1
  46. package/lib/fs/bundlePointer.d.ts +2 -0
  47. package/lib/fs/bundlePointer.js +14 -4
  48. package/lib/fs/fsUtils.d.ts +1 -2
  49. package/lib/fs/fsUtils.js +12 -27
  50. package/lib/fs/userProperties.d.ts +25 -4
  51. package/lib/fs/userProperties.js +51 -7
  52. package/lib/index.d.ts +7 -3
  53. package/lib/index.js +5 -1
  54. package/lib/injectImageResolver.js +6 -15
  55. package/lib/install/installFromZip.d.ts +1 -1
  56. package/lib/install/installFromZip.js +47 -42
  57. package/lib/loadConfig.d.ts +21 -2
  58. package/lib/loadConfig.js +11 -7
  59. package/lib/manager/downloadAndInstall.d.ts +3 -0
  60. package/lib/manager/downloadAndInstall.js +30 -28
  61. package/lib/manager/reporting.d.ts +2 -0
  62. package/lib/manager/reporting.js +27 -2
  63. package/lib/manager/rollbackState.d.ts +28 -11
  64. package/lib/manager/rollbackState.js +90 -38
  65. package/lib/manager/updateCheck.js +17 -3
  66. package/lib/manager/updateState.d.ts +5 -1
  67. package/lib/manager/updateState.js +20 -11
  68. package/lib/native/fs.d.ts +6 -0
  69. package/lib/native/fs.js +27 -0
  70. package/lib/runtime/initState.d.ts +2 -2
  71. package/lib/runtime/service.d.ts +28 -0
  72. package/lib/runtime/service.js +136 -10
  73. package/lib/scripts/bundle.d.ts +4 -1
  74. package/lib/scripts/bundle.js +42 -29
  75. package/lib/scripts/projectRoot.d.ts +1 -0
  76. package/lib/scripts/projectRoot.js +54 -0
  77. package/lib/scripts/resolve-ios-version.d.ts +2 -0
  78. package/lib/scripts/resolve-ios-version.js +74 -0
  79. package/lib/scripts/upload-bundle.d.ts +2 -1
  80. package/lib/scripts/upload-bundle.js +56 -41
  81. package/lib/types.d.ts +3 -0
  82. package/lib/useBundleDrop.d.ts +2 -0
  83. package/lib/useBundleDrop.js +1 -0
  84. package/package.json +9 -11
@@ -44,6 +44,7 @@ const fs = __importStar(require("fs"));
44
44
  const path = __importStar(require("path"));
45
45
  const plist = __importStar(require("plist"));
46
46
  const ui_1 = require("../utils/ui");
47
+ const resolve_ios_version_1 = require("../../scripts/resolve-ios-version");
47
48
  const DOCS_INSTALLATION_URL = 'https://bundledrop.app/docs/installation';
48
49
  const DOCS_UPLOADING_URL = 'https://bundledrop.app/docs/uploading';
49
50
  const DOCS_CI_CD_URL = 'https://bundledrop.app/docs/ci-cd';
@@ -122,7 +123,16 @@ async function upload(platform, options) {
122
123
  try {
123
124
  const plistContent = fs.readFileSync(options.plistFile, 'utf-8');
124
125
  const parsed = plist.parse(plistContent);
125
- version = parsed.CFBundleShortVersionString;
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;
126
136
  }
127
137
  catch (err) {
128
138
  ui_1.log.error(`❌ Failed to parse Info.plist: ${err.message}`);
@@ -147,6 +157,7 @@ async function upload(platform, options) {
147
157
  }
148
158
  }
149
159
  }
160
+ /* istanbul ignore if -- exhaustive guard; all branches above either set version or exit */
150
161
  if (!version) {
151
162
  ui_1.log.error('❌ Version could not be determined');
152
163
  process.exit(1);
@@ -158,10 +169,11 @@ async function upload(platform, options) {
158
169
  const compiledBundleScript = path.join(packageRoot, 'lib', 'scripts', 'bundle.js');
159
170
  const tsBundleScript = path.join(packageRoot, 'src', 'scripts', 'bundle.ts');
160
171
  const bundleCommand = fs.existsSync(compiledBundleScript)
161
- ? `node ${compiledBundleScript}`
162
- : `ts-node ${tsBundleScript}`;
172
+ ? `node "${compiledBundleScript}"`
173
+ : `ts-node "${tsBundleScript}"`;
174
+ const sourcemapArg = options.sourcemap ? ' --sourcemap' : '';
163
175
  try {
164
- (0, child_process_1.execSync)(`${bundleCommand} ${platform}`, {
176
+ (0, child_process_1.execSync)(`${bundleCommand} ${platform}${sourcemapArg}`, {
165
177
  stdio: 'inherit',
166
178
  });
167
179
  }
@@ -214,7 +226,7 @@ async function upload(platform, options) {
214
226
  form.append('author', options.author);
215
227
  }
216
228
  form.append('file', fs.createReadStream(zipPath));
217
- ui_1.log.arrow('Uploading bundle to server...');
229
+ const uploadLoader = (0, ui_1.startLoadingStatus)('Uploading bundle to server');
218
230
  try {
219
231
  const res = await axios_1.default.post(`${serverUrl}/bundle/upload`, form, {
220
232
  headers: {
@@ -224,6 +236,9 @@ async function upload(platform, options) {
224
236
  maxContentLength: Infinity,
225
237
  maxBodyLength: Infinity,
226
238
  });
239
+ const sourceMapFile = path.join(outputDir, 'main.jsbundle.map');
240
+ const hasSourceMap = options.sourcemap && fs.existsSync(sourceMapFile);
241
+ const artifactDir = options.artifactDir ? path.resolve(options.artifactDir) : undefined;
227
242
  const result = {
228
243
  platform,
229
244
  appVersion: version ?? null,
@@ -238,21 +253,43 @@ async function upload(platform, options) {
238
253
  releaseNotes: releaseNotes ?? null,
239
254
  author: options.author ?? null,
240
255
  };
256
+ if (artifactDir) {
257
+ try {
258
+ fs.mkdirSync(artifactDir, { recursive: true });
259
+ const bundleFile = path.join(outputDir, 'main.jsbundle');
260
+ if (fs.existsSync(bundleFile)) {
261
+ fs.copyFileSync(bundleFile, path.join(artifactDir, 'main.jsbundle'));
262
+ result.bundlePath = path.join(artifactDir, 'main.jsbundle');
263
+ }
264
+ if (hasSourceMap) {
265
+ fs.copyFileSync(sourceMapFile, path.join(artifactDir, 'main.jsbundle.map'));
266
+ result.sourceMapPath = path.join(artifactDir, 'main.jsbundle.map');
267
+ }
268
+ }
269
+ catch (copyErr) {
270
+ ui_1.log.warn(`Upload succeeded but artifact copy failed: ${copyErr.message}`);
271
+ }
272
+ }
273
+ uploadLoader.stop();
241
274
  ui_1.log.success(`✅ Upload complete`);
242
275
  if (result.bundleVersion != null)
243
276
  ui_1.log.label('Bundle Version', `${result.bundleVersion}`);
244
277
  if (result.bundleVersionLabel)
245
- ui_1.log.label('Bundle Label', result.bundleVersionLabel);
278
+ ui_1.log.label('Bundle Label', `${result.bundleVersionLabel}`);
246
279
  if (result.hash)
247
- ui_1.log.label('Hash', result.hash);
248
- const resultDir = path.join(packageRoot, 'dist');
280
+ ui_1.log.label('Hash', `${result.hash}`);
281
+ const resultDir = artifactDir ?? path.join(packageRoot, 'dist');
249
282
  if (!fs.existsSync(resultDir))
250
283
  fs.mkdirSync(resultDir, { recursive: true });
251
284
  const resultPath = path.join(resultDir, 'bundle-drop-result.json');
252
285
  fs.writeFileSync(resultPath, JSON.stringify(result, null, 2));
253
286
  ui_1.log.label('Result file', resultPath);
287
+ if (artifactDir) {
288
+ ui_1.log.label('Artifact dir', artifactDir);
289
+ }
254
290
  }
255
291
  catch (err) {
292
+ uploadLoader.stop();
256
293
  const raw = err?.response?.data || err.message;
257
294
  if (typeof raw === 'object') {
258
295
  ui_1.log.error(`Upload failed:\n${JSON.stringify(raw, null, 2)}`);
@@ -262,26 +299,28 @@ async function upload(platform, options) {
262
299
  }
263
300
  process.exit(1);
264
301
  }
265
- // Cleanup
266
- console.log();
267
- ui_1.log.arrow('Cleaning up temporary files...');
268
- const cleanupFiles = [
269
- zipPath,
270
- path.join(outputDir, `metadata-${platform}.json`),
271
- path.join(outputDir, 'main.jsbundle'),
272
- ];
273
- const assetsPath = path.join(outputDir, 'assets');
274
- for (const file of cleanupFiles) {
275
- if (fs.existsSync(file)) {
276
- fs.unlinkSync(file);
277
- ui_1.log.label('🧹 Deleted', file);
302
+ finally {
303
+ try {
304
+ const cleanupFiles = [
305
+ zipPath,
306
+ path.join(outputDir, `metadata-${platform}.json`),
307
+ path.join(outputDir, 'main.jsbundle'),
308
+ path.join(outputDir, 'main.jsbundle.map'),
309
+ ];
310
+ const assetsPath = path.join(outputDir, 'assets');
311
+ for (const file of cleanupFiles) {
312
+ if (fs.existsSync(file))
313
+ fs.unlinkSync(file);
314
+ }
315
+ if (fs.existsSync(assetsPath)) {
316
+ fs.rmSync(assetsPath, { recursive: true, force: true });
317
+ }
318
+ console.log();
319
+ ui_1.log.success('🎉 Done! Bundle uploaded and cleaned.');
320
+ console.log();
321
+ }
322
+ catch (cleanupErr) {
323
+ ui_1.log.warn(`Cleanup failed: ${cleanupErr.message}`);
278
324
  }
279
325
  }
280
- if (fs.existsSync(assetsPath)) {
281
- fs.rmSync(assetsPath, { recursive: true, force: true });
282
- ui_1.log.label('🧹 Deleted', assetsPath);
283
- }
284
- console.log();
285
- ui_1.log.success('🎉 Done! Bundle uploaded and cleaned.');
286
- console.log();
287
326
  }
@@ -6,3 +6,6 @@ export declare const log: {
6
6
  arrow: (msg: string) => void;
7
7
  label: (label: string, value: string) => void;
8
8
  };
9
+ export declare function startLoadingStatus(message: string, intervalMs?: number): {
10
+ stop: () => any;
11
+ };
@@ -4,6 +4,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
4
4
  };
5
5
  Object.defineProperty(exports, "__esModule", { value: true });
6
6
  exports.log = void 0;
7
+ exports.startLoadingStatus = startLoadingStatus;
7
8
  const chalk_1 = __importDefault(require("chalk"));
8
9
  const figures_1 = __importDefault(require("figures"));
9
10
  exports.log = {
@@ -14,3 +15,28 @@ exports.log = {
14
15
  arrow: (msg) => console.log(chalk_1.default.cyan(figures_1.default.arrowRight), msg),
15
16
  label: (label, value) => console.log(`${chalk_1.default.gray(label)}: ${chalk_1.default.white(value)}`),
16
17
  };
18
+ function startLoadingStatus(message, intervalMs = 300) {
19
+ const frames = ['', '.', '..', '...'];
20
+ let frameIndex = 0;
21
+ let lastLineLength = 0;
22
+ if (!process.stdout.isTTY) {
23
+ exports.log.arrow(`${message}...`);
24
+ return {
25
+ stop: () => undefined,
26
+ };
27
+ }
28
+ const render = () => {
29
+ const line = `${chalk_1.default.cyan(figures_1.default.arrowRight)} ${message}${frames[frameIndex]}`;
30
+ lastLineLength = Math.max(lastLineLength, line.length);
31
+ process.stdout.write(`\r${line}${' '.repeat(Math.max(0, lastLineLength - line.length))}`);
32
+ frameIndex = (frameIndex + 1) % frames.length;
33
+ };
34
+ render();
35
+ const timer = setInterval(render, intervalMs);
36
+ return {
37
+ stop: () => {
38
+ clearInterval(timer);
39
+ process.stdout.write(`\r${' '.repeat(lastLineLength)}\r`);
40
+ },
41
+ };
42
+ }
@@ -1,6 +1,7 @@
1
1
  import type { AxiosResponse } from 'axios';
2
- import { OtaResolveRequest, OtaResolveResponse, PublicChannelsParams, ReportInstalledPayload, BundleListParams, BundleListResponse } from './types';
2
+ import { OtaResolveRequest, OtaResolveResponse, PublicChannelsParams, ReportInstalledPayload, ReportLocalRollbackPayload, BundleListParams, BundleListResponse } from './types';
3
3
  export declare function postOtaResolve(projectSlug: string, payload: OtaResolveRequest): Promise<AxiosResponse<OtaResolveResponse>>;
4
4
  export declare function getPublicChannels(params: PublicChannelsParams): Promise<AxiosResponse<string[]>>;
5
5
  export declare function reportInstalled(projectSlug: string, hash: string, payload: ReportInstalledPayload): Promise<AxiosResponse<void>>;
6
+ export declare function reportLocalRollback(projectSlug: string, hash: string, payload: ReportLocalRollbackPayload): Promise<AxiosResponse<void>>;
6
7
  export declare function getBundleList(projectSlug: string, params: BundleListParams): Promise<AxiosResponse<BundleListResponse>>;
@@ -3,6 +3,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.postOtaResolve = postOtaResolve;
4
4
  exports.getPublicChannels = getPublicChannels;
5
5
  exports.reportInstalled = reportInstalled;
6
+ exports.reportLocalRollback = reportLocalRollback;
6
7
  exports.getBundleList = getBundleList;
7
8
  const client_1 = require("./client");
8
9
  function postOtaResolve(projectSlug, payload) {
@@ -24,6 +25,14 @@ function getPublicChannels(params) {
24
25
  }
25
26
  function reportInstalled(projectSlug, hash, payload) {
26
27
  return client_1.apiClient.post(`/projects/${encodeURIComponent(projectSlug)}/bundle/${encodeURIComponent(hash)}/installed`, payload, {
28
+ headers: {
29
+ Accept: 'application/json',
30
+ },
31
+ timeout: 3000,
32
+ });
33
+ }
34
+ function reportLocalRollback(projectSlug, hash, payload) {
35
+ return client_1.apiClient.post(`/projects/${encodeURIComponent(projectSlug)}/bundle/${encodeURIComponent(hash)}/local-rollback-report`, payload, {
27
36
  headers: {
28
37
  Accept: 'application/json',
29
38
  },
@@ -1,17 +1,19 @@
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?: Record<string, string>;
8
+ currentUserProperties?: UserProperties;
8
9
  previousHash?: string | null;
10
+ rejectedHashes?: string[];
9
11
  currentBundleVersion?: number | null;
10
12
  installId?: string | null;
11
13
  };
12
14
  export type OtaResolveResponse = {
13
15
  action: 'NOOP';
14
- reason?: 'UP_TO_DATE' | 'ROLLOUT_PAUSED' | 'ROLLOUT_NOT_ELIGIBLE' | 'NO_PUBLISHED_BUNDLE' | 'NO_COMPATIBLE_BUNDLE';
16
+ reason?: 'UP_TO_DATE' | 'ROLLOUT_PAUSED' | 'ROLLOUT_NOT_ELIGIBLE' | 'TARGETING_NOT_MATCHED' | 'NO_PUBLISHED_BUNDLE' | 'NO_COMPATIBLE_BUNDLE';
15
17
  requestedRuntimeVersion?: string;
16
18
  latestRuntimeVersionOnChannel?: string;
17
19
  } | {
@@ -48,6 +50,10 @@ export type UpdateCheckResponse = {
48
50
  channelName?: string;
49
51
  /** Server-side reason for `NOOP` or `ROLLBACK` decisions. */
50
52
  reason?: string;
53
+ /** True when the latest server target was skipped because this install already failed it. */
54
+ skippedFailedBundle?: boolean;
55
+ /** Hash skipped by local failed-bundle quarantine. */
56
+ skippedHash?: string;
51
57
  /** `true` when no compatible bundle exists for the current runtime version. */
52
58
  incompatible?: boolean;
53
59
  /** Runtime version attached to the target bundle or current request. */
@@ -66,7 +72,19 @@ export type ReportInstalledPayload = {
66
72
  installId?: string | null;
67
73
  runtimeVersion?: string | null;
68
74
  environment?: string | null;
69
- userProperties?: Record<string, string>;
75
+ userProperties?: UserProperties;
76
+ };
77
+ export type ReportLocalRollbackPayload = {
78
+ reason: string;
79
+ previousHash?: string | null;
80
+ channelName?: string | null;
81
+ platform?: string | null;
82
+ runtimeVersion?: string | null;
83
+ installId?: string | null;
84
+ environment?: string | null;
85
+ userProperties?: UserProperties;
86
+ crashCount?: number | null;
87
+ failedAt?: string | null;
70
88
  };
71
89
  /**
72
90
  * Public metadata for a single downloadable bundle returned by the bundle list endpoint.
@@ -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;
22
- crashWindowSec: number;
23
- commitTimeoutSec: number;
34
+ /** How Bundle Drop marks a newly launched OTA bundle healthy. */
35
+ healthCheckMode: 'auto' | 'manual';
36
+ /** Seconds to wait before automatically marking a candidate healthy in auto mode. */
37
+ healthyAfterSec: 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,
@@ -25,7 +28,7 @@ exports.bundleDropConfig = {
25
28
  debugLocal: exports.config.debugLocal ?? false,
26
29
  rollback: {
27
30
  maxCrashCount: exports.config.rollback?.maxCrashCount ?? 3,
28
- crashWindowSec: exports.config.rollback?.crashWindowSec ?? 30,
29
- commitTimeoutSec: exports.config.rollback?.commitTimeoutSec ?? 10,
31
+ healthCheckMode: exports.config.rollback?.healthCheckMode === 'manual' ? 'manual' : 'auto',
32
+ healthyAfterSec: exports.config.rollback?.healthyAfterSec ?? 0,
30
33
  },
31
34
  };
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
+ }
@@ -11,4 +11,6 @@ export declare function setCurrentBundlePointer(bundlePath: string, hash: string
11
11
  setPrevious?: boolean;
12
12
  }): Promise<void>;
13
13
  export declare function rollbackToPreviousPointer(): Promise<BundlePointer | null>;
14
+ export declare function deleteCurrentBundlePointer(): Promise<void>;
15
+ export declare function deletePreviousBundlePointer(): Promise<void>;
14
16
  export declare function clearCurrentBundlePointer(): Promise<void>;
@@ -9,6 +9,8 @@ exports.writeCurrentBundlePointer = writeCurrentBundlePointer;
9
9
  exports.writePreviousBundlePointer = writePreviousBundlePointer;
10
10
  exports.setCurrentBundlePointer = setCurrentBundlePointer;
11
11
  exports.rollbackToPreviousPointer = rollbackToPreviousPointer;
12
+ exports.deleteCurrentBundlePointer = deleteCurrentBundlePointer;
13
+ exports.deletePreviousBundlePointer = deletePreviousBundlePointer;
12
14
  exports.clearCurrentBundlePointer = clearCurrentBundlePointer;
13
15
  const fs_1 = __importDefault(require("../native/fs"));
14
16
  const context_1 = require("../context");
@@ -65,13 +67,21 @@ async function rollbackToPreviousPointer() {
65
67
  await writeCurrentBundlePointer({ ...previous, updatedAt: new Date().toISOString() });
66
68
  return previous;
67
69
  }
70
+ async function deleteCurrentBundlePointer() {
71
+ if (await fs_1.default.exists(CURRENT_POINTER_PATH)) {
72
+ await fs_1.default.unlink(CURRENT_POINTER_PATH);
73
+ }
74
+ }
75
+ async function deletePreviousBundlePointer() {
76
+ if (await fs_1.default.exists(PREVIOUS_POINTER_PATH)) {
77
+ await fs_1.default.unlink(PREVIOUS_POINTER_PATH);
78
+ }
79
+ }
68
80
  async function clearCurrentBundlePointer() {
69
81
  try {
70
- if (await fs_1.default.exists(CURRENT_POINTER_PATH)) {
71
- await fs_1.default.unlink(CURRENT_POINTER_PATH);
72
- }
82
+ await deleteCurrentBundlePointer();
73
83
  }
74
84
  catch {
75
- // ignore
85
+ // Best-effort cleanup for callers that do not need strict rollback semantics.
76
86
  }
77
87
  }
@@ -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 ensureDir(dir) {
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.writeFile(tmp, JSON.stringify(data), 'utf8');
20
- try {
21
- await fs_1.default.unlink(path);
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
- // Atomic rename failed (concurrent writer moved/removed our tmp); fall back to direct write.
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 ensureParentDir(filePath) {
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 writeFileAtomicBase64(path, base64) {
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, base64, 'base64');
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
- await fs_1.default.writeFile(path, base64, 'base64');
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 declare function getCurrentUserProperties(): Promise<Record<string, string>>;
2
- export declare function getUserProperties(): Promise<Record<string, string>>;
3
- export declare function setUserProperty(key: string, value: string): Promise<Record<string, string>>;
4
- export declare function removeUserProperty(key: string): Promise<Record<string, string>>;
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;