@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
@@ -1,8 +1,17 @@
1
1
  import { type BundlePointer } from '../fs/bundlePointer';
2
2
  export type RollbackPolicy = {
3
3
  maxCrashCount?: number;
4
- crashWindowSec?: number;
5
- commitTimeoutSec?: number;
4
+ healthCheckMode?: 'auto' | 'manual';
5
+ healthyAfterSec?: number;
6
+ };
7
+ export type FailedBundleReason = 'crash_loop';
8
+ export type FailedBundleRecord = {
9
+ reason: FailedBundleReason;
10
+ failedAt: number;
11
+ crashCount?: number;
12
+ channelName?: string;
13
+ runtimeVersion?: string;
14
+ previousHash?: string;
6
15
  };
7
16
  export type RollbackState = {
8
17
  activeHash?: string;
@@ -11,30 +20,38 @@ export type RollbackState = {
11
20
  candidateActivatedAt?: number;
12
21
  candidateCommitted?: boolean;
13
22
  crashCount?: number;
14
- crashWindowStartedAt?: number;
15
23
  lastLaunchAt?: number;
24
+ failedBundles?: Record<string, FailedBundleRecord>;
25
+ };
26
+ type RollbackDecision = {
27
+ shouldRollback: false;
28
+ } | {
29
+ shouldRollback: true;
30
+ reason: FailedBundleReason;
16
31
  };
17
32
  declare function readState(): Promise<RollbackState | null>;
18
33
  export { readState as readRollbackState };
19
34
  export declare function markCandidateActivated(hash: string): Promise<void>;
35
+ export declare function reportActiveBundleHealthy(cached?: {
36
+ currentPointer?: BundlePointer | null;
37
+ }, expectedHash?: string): Promise<boolean>;
20
38
  export declare function commitActiveBundle(cached?: {
21
39
  currentPointer?: BundlePointer | null;
22
40
  }): Promise<void>;
23
- export declare function evaluateRollbackOnLaunch(policy?: RollbackPolicy, cached?: {
41
+ export declare function isBundleHashFailed(hash?: string | null): Promise<boolean>;
42
+ export declare function getFailedBundleHashes(): Promise<string[]>;
43
+ export declare function evaluateRollbackOnLaunch(policy: Required<RollbackPolicy>, cached?: {
24
44
  currentPointer?: BundlePointer | null;
25
45
  rollbackState?: RollbackState | null;
26
- }): Promise<{
27
- shouldRollback: boolean;
28
- reason?: 'crash_loop' | 'commit_timeout';
29
- }>;
30
- export declare function rollbackToPreviousIfNeeded(policy?: RollbackPolicy, cached?: {
46
+ }): Promise<RollbackDecision>;
47
+ export declare function rollbackToPreviousIfNeeded(policy: Required<RollbackPolicy>, cached?: {
31
48
  currentPointer?: BundlePointer | null;
32
49
  rollbackState?: RollbackState | null;
33
50
  }): Promise<{
34
51
  rolledBack: boolean;
35
- reason?: 'crash_loop' | 'commit_timeout';
52
+ reason?: FailedBundleReason;
36
53
  }>;
37
- export declare function getRollbackPolicy(): RollbackPolicy | undefined;
54
+ export declare function getRollbackPolicy(): Required<RollbackPolicy>;
38
55
  export declare function rollbackToPreviousOrNative(): Promise<{
39
56
  rolledBack: boolean;
40
57
  toNative?: boolean;
@@ -5,7 +5,10 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
5
5
  Object.defineProperty(exports, "__esModule", { value: true });
6
6
  exports.readRollbackState = readState;
7
7
  exports.markCandidateActivated = markCandidateActivated;
8
+ exports.reportActiveBundleHealthy = reportActiveBundleHealthy;
8
9
  exports.commitActiveBundle = commitActiveBundle;
10
+ exports.isBundleHashFailed = isBundleHashFailed;
11
+ exports.getFailedBundleHashes = getFailedBundleHashes;
9
12
  exports.evaluateRollbackOnLaunch = evaluateRollbackOnLaunch;
10
13
  exports.rollbackToPreviousIfNeeded = rollbackToPreviousIfNeeded;
11
14
  exports.getRollbackPolicy = getRollbackPolicy;
@@ -15,22 +18,12 @@ const context_1 = require("../context");
15
18
  const fsUtils_1 = require("../fs/fsUtils");
16
19
  const bundlePointer_1 = require("../fs/bundlePointer");
17
20
  const bundleInfo_1 = require("../bundleInfo");
21
+ const reporting_1 = require("./reporting");
18
22
  const STATE_PATH = `${context_1.BUNDLE_DROP_ROOT}/state.json`;
19
- const DEFAULT_POLICY = {
20
- maxCrashCount: 2,
21
- crashWindowSec: 300,
22
- commitTimeoutSec: 300,
23
- };
23
+ const MAX_FAILED_BUNDLES = 20;
24
24
  function nowSec() {
25
25
  return Math.floor(Date.now() / 1000);
26
26
  }
27
- function normalizePolicy(policy) {
28
- return {
29
- maxCrashCount: policy?.maxCrashCount ?? DEFAULT_POLICY.maxCrashCount,
30
- crashWindowSec: policy?.crashWindowSec ?? DEFAULT_POLICY.crashWindowSec,
31
- commitTimeoutSec: policy?.commitTimeoutSec ?? DEFAULT_POLICY.commitTimeoutSec,
32
- };
33
- }
34
27
  async function readState() {
35
28
  try {
36
29
  if (!(await fs_1.default.exists(STATE_PATH)))
@@ -52,6 +45,11 @@ async function updateState(partial) {
52
45
  await writeState(next);
53
46
  return next;
54
47
  }
48
+ function pruneFailedBundles(failedBundles) {
49
+ return Object.fromEntries(Object.entries(failedBundles)
50
+ .sort(([, left], [, right]) => right.failedAt - left.failedAt)
51
+ .slice(0, MAX_FAILED_BUNDLES));
52
+ }
55
53
  async function markCandidateActivated(hash) {
56
54
  const previous = await (0, bundlePointer_1.readPreviousBundlePointer)();
57
55
  const previousHash = previous?.hash;
@@ -62,24 +60,68 @@ async function markCandidateActivated(hash) {
62
60
  candidateActivatedAt: now,
63
61
  candidateCommitted: false,
64
62
  crashCount: 0,
65
- crashWindowStartedAt: now,
66
63
  lastLaunchAt: now,
67
64
  lastGoodHash: previousHash ?? undefined,
68
65
  });
69
66
  }
70
- async function commitActiveBundle(cached) {
67
+ async function reportActiveBundleHealthy(cached, expectedHash) {
71
68
  const current = cached?.currentPointer !== undefined ? cached.currentPointer : await (0, bundlePointer_1.readCurrentBundlePointer)();
72
69
  const hash = current?.hash;
73
70
  if (!hash)
74
- return;
71
+ return false;
72
+ if (expectedHash && hash !== expectedHash)
73
+ return false;
74
+ const state = (await readState()) || {};
75
+ const isCandidate = state.candidateHash === hash && state.candidateCommitted !== true;
76
+ if (!isCandidate)
77
+ return false;
75
78
  await updateState({
76
79
  activeHash: hash,
77
80
  candidateHash: hash,
78
81
  candidateCommitted: true,
79
82
  crashCount: 0,
80
- crashWindowStartedAt: nowSec(),
81
83
  lastGoodHash: hash,
82
84
  });
85
+ return true;
86
+ }
87
+ async function commitActiveBundle(cached) {
88
+ await reportActiveBundleHealthy(cached);
89
+ }
90
+ async function isBundleHashFailed(hash) {
91
+ if (!hash)
92
+ return false;
93
+ const state = await readState();
94
+ return !!state?.failedBundles?.[hash];
95
+ }
96
+ async function getFailedBundleHashes() {
97
+ const state = await readState();
98
+ return Object.entries(state?.failedBundles || {})
99
+ .sort(([, left], [, right]) => right.failedAt - left.failedAt)
100
+ .slice(0, MAX_FAILED_BUNDLES)
101
+ .map(([hash]) => hash);
102
+ }
103
+ async function buildFailedBundleRecord(hash, reason, state) {
104
+ const [bundleInfo, previous] = await Promise.all([
105
+ (0, bundleInfo_1.readBundleInfo)(),
106
+ (0, bundlePointer_1.readPreviousBundlePointer)(),
107
+ ]);
108
+ const record = {
109
+ reason,
110
+ failedAt: nowSec(),
111
+ crashCount: state.crashCount,
112
+ channelName: bundleInfo?.channelName,
113
+ runtimeVersion: bundleInfo?.runtimeVersion,
114
+ previousHash: previous?.hash,
115
+ };
116
+ return record;
117
+ }
118
+ async function recordFailedBundle(hash, record) {
119
+ const state = (await readState()) || {};
120
+ const failedBundles = pruneFailedBundles({
121
+ ...(state.failedBundles || {}),
122
+ [hash]: record,
123
+ });
124
+ await updateState({ failedBundles });
83
125
  }
84
126
  async function evaluateRollbackOnLaunch(policy, cached) {
85
127
  const current = cached?.currentPointer !== undefined ? cached.currentPointer : await (0, bundlePointer_1.readCurrentBundlePointer)();
@@ -87,8 +129,14 @@ async function evaluateRollbackOnLaunch(policy, cached) {
87
129
  if (!activeHash)
88
130
  return { shouldRollback: false };
89
131
  const now = nowSec();
90
- const state = (cached?.rollbackState !== undefined ? cached.rollbackState : await readState()) || {};
91
- const normalized = normalizePolicy(policy);
132
+ const persistedState = (await readState()) || {};
133
+ const state = cached?.rollbackState !== undefined
134
+ ? {
135
+ ...persistedState,
136
+ ...cached.rollbackState,
137
+ failedBundles: persistedState.failedBundles ?? cached.rollbackState?.failedBundles,
138
+ }
139
+ : persistedState;
92
140
  const next = {
93
141
  ...state,
94
142
  activeHash,
@@ -96,22 +144,13 @@ async function evaluateRollbackOnLaunch(policy, cached) {
96
144
  };
97
145
  const isCandidate = state.candidateHash === activeHash && state.candidateCommitted !== true;
98
146
  if (isCandidate) {
99
- const windowStart = state.crashWindowStartedAt ?? now;
100
- const inWindow = now - windowStart <= normalized.crashWindowSec;
101
- const crashCount = inWindow ? (state.crashCount ?? 0) + 1 : 1;
147
+ const crashCount = (state.crashCount ?? 0) + 1;
102
148
  next.crashCount = crashCount;
103
- next.crashWindowStartedAt = inWindow ? windowStart : now;
104
- if (normalized.maxCrashCount > 0 &&
105
- crashCount >= normalized.maxCrashCount) {
149
+ if (policy.maxCrashCount > 0 &&
150
+ crashCount >= policy.maxCrashCount) {
106
151
  await writeState(next);
107
152
  return { shouldRollback: true, reason: 'crash_loop' };
108
153
  }
109
- if (normalized.commitTimeoutSec > 0 &&
110
- state.candidateActivatedAt &&
111
- now - state.candidateActivatedAt > normalized.commitTimeoutSec) {
112
- await writeState(next);
113
- return { shouldRollback: true, reason: 'commit_timeout' };
114
- }
115
154
  }
116
155
  await writeState(next);
117
156
  return { shouldRollback: false };
@@ -120,15 +159,29 @@ async function rollbackToPreviousIfNeeded(policy, cached) {
120
159
  const decision = await evaluateRollbackOnLaunch(policy, cached);
121
160
  if (!decision.shouldRollback)
122
161
  return { rolledBack: false };
123
- const res = await rollbackToPreviousOrNative();
124
- return res.rolledBack ? { rolledBack: true, reason: decision.reason } : { rolledBack: false };
162
+ const current = cached?.currentPointer !== undefined ? cached.currentPointer : await (0, bundlePointer_1.readCurrentBundlePointer)();
163
+ const failedHash = current?.hash;
164
+ const state = (await readState()) || {};
165
+ if (!failedHash)
166
+ return { rolledBack: false };
167
+ const failedRecord = await buildFailedBundleRecord(failedHash, decision.reason, state);
168
+ await rollbackToPreviousOrNative();
169
+ await recordFailedBundle(failedHash, failedRecord);
170
+ await (0, reporting_1.reportLocalRollback)(failedHash, failedRecord).catch(() => undefined);
171
+ return { rolledBack: true, reason: decision.reason };
125
172
  }
126
173
  function getRollbackPolicy() {
127
- return context_1.config.rollback;
174
+ return context_1.bundleDropConfig.rollback;
128
175
  }
129
176
  async function rollbackToPreviousOrNative() {
130
- const previous = await (0, bundlePointer_1.rollbackToPreviousPointer)();
131
- if (previous) {
177
+ const [current, previous, state] = await Promise.all([
178
+ (0, bundlePointer_1.readCurrentBundlePointer)(),
179
+ (0, bundlePointer_1.readPreviousBundlePointer)(),
180
+ readState(),
181
+ ]);
182
+ const previousIsFailed = previous ? !!state?.failedBundles?.[previous.hash] : false;
183
+ if (previous && previous.hash !== current?.hash && !previousIsFailed) {
184
+ await (0, bundlePointer_1.writeCurrentBundlePointer)({ ...previous, updatedAt: new Date().toISOString() });
132
185
  const metadata = await readBundleMetadata(previous.bundlePath);
133
186
  await (0, bundleInfo_1.updateBundleInfo)({
134
187
  hash: previous.hash,
@@ -143,12 +196,12 @@ async function rollbackToPreviousOrNative() {
143
196
  candidateHash: previous.hash,
144
197
  candidateCommitted: true,
145
198
  crashCount: 0,
146
- crashWindowStartedAt: nowSec(),
147
199
  });
148
200
  return { rolledBack: true };
149
201
  }
150
202
  // No previous OTA bundle exists; fall back to native bundle by clearing the active pointer.
151
- await (0, bundlePointer_1.clearCurrentBundlePointer)();
203
+ await (0, bundlePointer_1.deleteCurrentBundlePointer)();
204
+ await (0, bundlePointer_1.deletePreviousBundlePointer)();
152
205
  await (0, bundleInfo_1.updateBundleInfo)({
153
206
  hash: undefined,
154
207
  bundleVersion: undefined,
@@ -162,7 +215,6 @@ async function rollbackToPreviousOrNative() {
162
215
  candidateHash: undefined,
163
216
  candidateCommitted: true,
164
217
  crashCount: 0,
165
- crashWindowStartedAt: nowSec(),
166
218
  });
167
219
  return { rolledBack: true, toNative: true };
168
220
  }
@@ -12,6 +12,7 @@ const bundlePointer_1 = require("../fs/bundlePointer");
12
12
  const installId_1 = require("../fs/installId");
13
13
  const userProperties_1 = require("../fs/userProperties");
14
14
  const initState_1 = require("../runtime/initState");
15
+ const rollbackState_1 = require("./rollbackState");
15
16
  async function getAvailableChannels() {
16
17
  const { project } = context_1.config;
17
18
  if (!project?.slug) {
@@ -38,24 +39,26 @@ async function checkForUpdate(channelName = context_2.defaultChannel, onStatusUp
38
39
  throw new Error('Missing project slug in bundle.drop.config.js');
39
40
  }
40
41
  onStatusUpdate?.('🔍 Checking for updates...');
41
- const [local, currentPtr, previousPtr, currentUserProperties, installId] = await Promise.all([
42
+ const [local, currentPtr, previousPtr, currentUserProperties, installId, rejectedHashes] = await Promise.all([
42
43
  (0, bundleInfo_1.readBundleInfo)(),
43
44
  (0, bundlePointer_1.readCurrentBundlePointer)(),
44
45
  (0, bundlePointer_1.readPreviousBundlePointer)(),
45
46
  (0, userProperties_1.getCurrentUserProperties)(),
46
47
  (0, installId_1.getOrCreateInstallId)(),
48
+ (0, rollbackState_1.getFailedBundleHashes)(),
47
49
  ]);
48
50
  const currentHash = currentPtr?.hash ?? local?.hash ?? null;
49
51
  const previousHash = previousPtr?.hash ?? null;
50
- const environment = (0, initState_1.getBundleDropRuntimeConfig)()?.environment ?? null;
52
+ const appEnvironment = (0, initState_1.getBundleDropRuntimeConfig)()?.environment ?? null;
51
53
  const res = await (0, clientApi_1.postOtaResolve)(project.slug, {
52
54
  channelName,
53
55
  platform: context_1.platform,
54
56
  runtimeVersion: context_1.runtimeVersion ?? null,
55
- environment,
57
+ environment: appEnvironment,
56
58
  currentHash,
57
59
  currentUserProperties,
58
60
  previousHash,
61
+ rejectedHashes,
59
62
  currentBundleVersion: local?.bundleVersion ?? null,
60
63
  installId,
61
64
  });
@@ -83,6 +86,17 @@ async function checkForUpdate(channelName = context_2.defaultChannel, onStatusUp
83
86
  return { action: 'ROLLBACK', channelName, reason: decision.reason };
84
87
  }
85
88
  // INSTALL
89
+ if (await (0, rollbackState_1.isBundleHashFailed)(decision.target.hash)) {
90
+ onStatusUpdate?.('✅ Current bundle retained; latest update previously failed on this device');
91
+ return {
92
+ action: 'NOOP',
93
+ upToDate: false,
94
+ channelName,
95
+ reason: 'BUNDLE_PREVIOUSLY_FAILED',
96
+ skippedFailedBundle: true,
97
+ skippedHash: decision.target.hash,
98
+ };
99
+ }
86
100
  onStatusUpdate?.('⬇️ Update available');
87
101
  return {
88
102
  action: 'INSTALL',
@@ -7,6 +7,10 @@ export type ApplyUpdateResult = {
7
7
  status: 'disabled';
8
8
  } | {
9
9
  status: 'alreadyApplied';
10
+ } | {
11
+ status: 'blocked';
12
+ reason: 'BUNDLE_PREVIOUSLY_FAILED';
13
+ skippedHash?: string;
10
14
  };
11
15
  export declare const getUpdateState: (cached?: {
12
16
  bundleInfo?: BundleInfo | null;
@@ -20,4 +24,4 @@ export declare const reconcileAppliedBundleOnLaunch: (cached?: {
20
24
  bundleInfo?: BundleInfo | null;
21
25
  bundlePath?: string | null;
22
26
  }) => Promise<void>;
23
- export declare const applyUpdate: (onStatusUpdate?: (status: string) => void) => Promise<ApplyUpdateResult>;
27
+ export declare const applyUpdate: (onStatusUpdate?: (status: string) => void, onBeforeRestart?: () => void) => Promise<ApplyUpdateResult>;
@@ -5,6 +5,7 @@ const bundleDropNative_1 = require("../native/bundleDropNative");
5
5
  const bundleInfo_1 = require("../bundleInfo");
6
6
  const reporting_1 = require("./reporting");
7
7
  const errors_1 = require("../errors");
8
+ const rollbackState_1 = require("./rollbackState");
8
9
  const getUpdateState = async (cached) => {
9
10
  const info = cached?.bundleInfo !== undefined ? cached.bundleInfo : await (0, bundleInfo_1.readBundleInfo)();
10
11
  const path = cached?.bundlePath !== undefined ? cached.bundlePath : await (0, bundleDropNative_1.getDownloadedBundlePathNative)();
@@ -17,10 +18,12 @@ const getUpdateState = async (cached) => {
17
18
  exports.getUpdateState = getUpdateState;
18
19
  const reconcileAppliedBundleOnLaunch = async (cached) => {
19
20
  const state = await (0, exports.getUpdateState)(cached);
20
- if (!state.info?.pendingApply)
21
- return;
22
21
  if (!state.hasBundle)
23
22
  return;
23
+ if (!state.info?.pendingApply) {
24
+ (0, reporting_1.reportInstalledIfReady)(state).catch(() => { });
25
+ return;
26
+ }
24
27
  await (0, bundleInfo_1.updateBundleInfo)({ pendingApply: false, installedAt: new Date().toISOString() });
25
28
  // Fire-and-forget: don't block the startup path for server reporting
26
29
  (0, reporting_1.reportInstalledIfReady)({
@@ -29,7 +32,7 @@ const reconcileAppliedBundleOnLaunch = async (cached) => {
29
32
  }).catch(() => { });
30
33
  };
31
34
  exports.reconcileAppliedBundleOnLaunch = reconcileAppliedBundleOnLaunch;
32
- const applyUpdate = async (onStatusUpdate) => {
35
+ const applyUpdate = async (onStatusUpdate, onBeforeRestart) => {
33
36
  try {
34
37
  const path = await (0, bundleDropNative_1.getDownloadedBundlePathNative)();
35
38
  const info = await (0, bundleInfo_1.readBundleInfo)();
@@ -41,18 +44,24 @@ const applyUpdate = async (onStatusUpdate) => {
41
44
  onStatusUpdate?.('ℹ️ Bundle already applied');
42
45
  return { status: 'alreadyApplied' };
43
46
  }
47
+ if (await (0, rollbackState_1.isBundleHashFailed)(info?.hash)) {
48
+ onStatusUpdate?.('⚠️ Update previously failed on this device');
49
+ return {
50
+ status: 'blocked',
51
+ reason: 'BUNDLE_PREVIOUSLY_FAILED',
52
+ skippedHash: info?.hash,
53
+ };
54
+ }
44
55
  onStatusUpdate?.('♻️ Applying downloaded bundle...');
45
56
  await (0, bundleInfo_1.updateBundleInfo)({ pendingApply: false, installedAt: new Date().toISOString() });
46
- try {
47
- await (0, reporting_1.reportInstalledIfReady)({
48
- hasBundle: true,
49
- info: info ? { ...info, pendingApply: false } : info,
50
- });
51
- }
52
- catch (reportError) {
57
+ (0, reporting_1.reportInstalledIfReady)({
58
+ hasBundle: true,
59
+ info: info ? { ...info, pendingApply: false } : info,
60
+ }).catch(reportError => {
53
61
  // Telemetry should not block applying the already-downloaded bundle.
54
62
  console.warn('⚠️ Failed to report bundle install during apply:', reportError);
55
- }
63
+ });
64
+ onBeforeRestart?.();
56
65
  (0, bundleDropNative_1.restartReactNativeNative)();
57
66
  return { status: 'applied' };
58
67
  }
@@ -2,8 +2,11 @@ declare function exists(path: string): Promise<boolean>;
2
2
  declare function readFile(path: string, encoding?: 'utf8' | 'base64'): Promise<string>;
3
3
  declare function writeFile(path: string, content: string, encoding?: 'utf8' | 'base64'): Promise<void>;
4
4
  declare function mkdir(path: string): Promise<void>;
5
+ declare function readDir(path: string): Promise<string[]>;
5
6
  declare function unlink(path: string): Promise<void>;
6
7
  declare function moveFile(src: string, dest: string): Promise<void>;
8
+ declare function unzip(zipPath: string, destPath: string): Promise<string[]>;
9
+ declare function downloadFile(url: string, destPath: string): Promise<void>;
7
10
  declare const BundleDropFS: {
8
11
  DocumentDirectoryPath: string;
9
12
  LibraryDirectoryPath: string;
@@ -11,7 +14,10 @@ declare const BundleDropFS: {
11
14
  readFile: typeof readFile;
12
15
  writeFile: typeof writeFile;
13
16
  mkdir: typeof mkdir;
17
+ readDir: typeof readDir;
14
18
  unlink: typeof unlink;
15
19
  moveFile: typeof moveFile;
20
+ unzip: typeof unzip;
21
+ downloadFile: typeof downloadFile;
16
22
  };
17
23
  export default BundleDropFS;
package/lib/native/fs.js CHANGED
@@ -2,24 +2,48 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  const react_native_1 = require("react-native");
4
4
  const { BundleDrop } = react_native_1.NativeModules;
5
+ function assertModule() {
6
+ if (!BundleDrop) {
7
+ throw new Error('BundleDrop native module is not linked. ' +
8
+ 'Run pod install (iOS) or rebuild (Android).');
9
+ }
10
+ }
5
11
  async function exists(path) {
12
+ assertModule();
6
13
  return BundleDrop.fsExists(path);
7
14
  }
8
15
  async function readFile(path, encoding = 'utf8') {
16
+ assertModule();
9
17
  return BundleDrop.fsReadFile(path, encoding);
10
18
  }
11
19
  async function writeFile(path, content, encoding = 'utf8') {
20
+ assertModule();
12
21
  return BundleDrop.fsWriteFile(path, content, encoding);
13
22
  }
14
23
  async function mkdir(path) {
24
+ assertModule();
15
25
  return BundleDrop.fsMkdir(path);
16
26
  }
27
+ async function readDir(path) {
28
+ assertModule();
29
+ return BundleDrop.fsReadDir(path);
30
+ }
17
31
  async function unlink(path) {
32
+ assertModule();
18
33
  return BundleDrop.fsUnlink(path);
19
34
  }
20
35
  async function moveFile(src, dest) {
36
+ assertModule();
21
37
  return BundleDrop.fsMoveFile(src, dest);
22
38
  }
39
+ async function unzip(zipPath, destPath) {
40
+ assertModule();
41
+ return BundleDrop.fsUnzip(zipPath, destPath);
42
+ }
43
+ async function downloadFile(url, destPath) {
44
+ assertModule();
45
+ return BundleDrop.fsDownloadFile(url, destPath);
46
+ }
23
47
  const BundleDropFS = {
24
48
  DocumentDirectoryPath: (BundleDrop?.DocumentDirectoryPath ?? ''),
25
49
  LibraryDirectoryPath: (BundleDrop?.LibraryDirectoryPath ?? ''),
@@ -27,7 +51,10 @@ const BundleDropFS = {
27
51
  readFile,
28
52
  writeFile,
29
53
  mkdir,
54
+ readDir,
30
55
  unlink,
31
56
  moveFile,
57
+ unzip,
58
+ downloadFile,
32
59
  };
33
60
  exports.default = BundleDropFS;
@@ -5,7 +5,7 @@ export declare const BUNDLE_DROP_DISABLED_MESSAGE = "BundleDrop is disabled. OTA
5
5
  * Runtime options for `BundleDrop.init(...)`.
6
6
  */
7
7
  export type BundleDropInitOptions = {
8
- /** Deployment environment shown in analytics, for example `production`, `staging`, or `development`. */
8
+ /** Customer app environment shown in analytics, for example `production`, `staging`, or `development`. */
9
9
  environment: string;
10
10
  /** Defaults to `true`. Set to `false` to keep BundleDrop configured but fully no-op for the current app process. */
11
11
  enabled?: boolean;
@@ -22,7 +22,7 @@ export type BundleDropInitOptions = {
22
22
  * Resolved runtime configuration currently active inside the singleton service.
23
23
  */
24
24
  export type BundleDropRuntimeConfig = {
25
- /** Deployment environment sent to BundleDrop analytics and resolve payloads. */
25
+ /** Customer app environment sent to BundleDrop analytics and resolve payloads. */
26
26
  environment: string;
27
27
  /** Whether BundleDrop is active or running in disabled no-op mode. */
28
28
  enabled: boolean;
@@ -58,6 +58,10 @@ export declare function downloadAndStage(extraStatusHandler?: StatusHandler): Pr
58
58
  * Apply a previously staged bundle immediately by restarting the React Native bridge.
59
59
  */
60
60
  export declare function applyDownloadedUpdate(extraStatusHandler?: StatusHandler): Promise<ApplyAndRefreshResult>;
61
+ /**
62
+ * Mark the currently running OTA candidate healthy for this device.
63
+ */
64
+ export declare function reportHealthy(): Promise<void>;
61
65
  /**
62
66
  * Fetch the list of public channel names available for the configured project.
63
67
  */
@@ -74,6 +78,30 @@ export declare function installBundleFromListItem(bundle: BundleListItem): Promi
74
78
  * Read locally stored metadata for the currently downloaded or applied bundle.
75
79
  */
76
80
  export declare function getInstalledBundleInfo(): Promise<BundleInfo | null>;
81
+ export type ObservabilityContext = {
82
+ source: 'embedded' | 'ota';
83
+ dist: string;
84
+ tags: {
85
+ bundle_drop_hash: string | null;
86
+ bundle_drop_channel: string | null;
87
+ bundle_drop_version: string | null;
88
+ bundle_drop_runtime_version: string | null;
89
+ bundle_drop_platform: string | null;
90
+ };
91
+ context: BundleInfo | null;
92
+ };
93
+ /**
94
+ * Pre-formatted context for error tracking integrations.
95
+ *
96
+ * Returns `dist`, `tags`, and `context` shaped for direct use with
97
+ * Sentry, Bugsnag, Datadog, or any provider. Handles the embedded
98
+ * fallback automatically: when no OTA bundle is active, `source`
99
+ * is `'embedded'` and `dist` is `'embedded'`.
100
+ *
101
+ * If the installed bundle has `pendingApply: true` it is not yet
102
+ * executing, so the context falls back to `'embedded'`.
103
+ */
104
+ export declare function getObservabilityContext(): Promise<ObservabilityContext>;
77
105
  /**
78
106
  * Read the current local update state from disk.
79
107
  */