@gfean/react-native-bundle-drop 0.5.1 → 0.7.0

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 (127) hide show
  1. package/BundleDrop.podspec +96 -0
  2. package/README.md +194 -5
  3. package/android/build.gradle +66 -0
  4. package/android/src/main/java/com/bundledrop/BundleDropBoundedDownloader.kt +86 -0
  5. package/android/src/main/java/com/bundledrop/BundleDropModule.kt +206 -13
  6. package/android/src/main/java/com/bundledrop/BundleDropNativePaths.kt +43 -13
  7. package/android/src/main/java/com/bundledrop/BundleDropOtaResolver.kt +35 -0
  8. package/android/src/main/java/com/bundledrop/BundleDropRuntimeCrypto.kt +81 -0
  9. package/android/src/main/java/com/bundledrop/BundleDropStartupRecovery.kt +1117 -0
  10. package/ios/BundleDropBridge.m +45 -0
  11. package/ios/BundleDropLocator.swift +66 -4
  12. package/ios/BundleDropModule.swift +181 -3
  13. package/ios/BundleDropOtaResolver.swift +137 -29
  14. package/ios/BundleDropRuntimeCrypto.swift +45 -0
  15. package/ios/BundleDropStartupRecovery.swift +1108 -0
  16. package/ios/BundleDropStartupRecoveryAdapter.swift +301 -0
  17. package/lib/CLI/cli.d.ts +1 -0
  18. package/lib/CLI/cli.js +57 -6
  19. package/lib/CLI/scripts/aipowered/apply-setup-plan.js +7 -17
  20. package/lib/CLI/scripts/aipowered/backend-client.js +29 -4
  21. package/lib/CLI/scripts/aipowered/code-push-residue.d.ts +5 -0
  22. package/lib/CLI/scripts/aipowered/code-push-residue.js +126 -0
  23. package/lib/CLI/scripts/aipowered/credential-safety.d.ts +1 -0
  24. package/lib/CLI/scripts/aipowered/credential-safety.js +14 -0
  25. package/lib/CLI/scripts/aipowered/diff-preview.js +12 -4
  26. package/lib/CLI/scripts/aipowered/init-project-config.d.ts +4 -0
  27. package/lib/CLI/scripts/aipowered/init-project-config.js +221 -45
  28. package/lib/CLI/scripts/aipowered/scanner.d.ts +1 -0
  29. package/lib/CLI/scripts/aipowered/scanner.js +164 -32
  30. package/lib/CLI/scripts/aipowered/terminal-safety.d.ts +4 -0
  31. package/lib/CLI/scripts/aipowered/terminal-safety.js +124 -0
  32. package/lib/CLI/scripts/aipowered/validate-plan.d.ts +3 -0
  33. package/lib/CLI/scripts/aipowered/validate-plan.js +1080 -19
  34. package/lib/CLI/scripts/bare-metro-config.d.ts +1 -1
  35. package/lib/CLI/scripts/bare-metro-config.js +24 -32
  36. package/lib/CLI/scripts/doctor.js +162 -22
  37. package/lib/CLI/scripts/expo/configure-expo.js +52 -60
  38. package/lib/CLI/scripts/expo/package-manager.d.ts +2 -0
  39. package/lib/CLI/scripts/expo/package-manager.js +63 -25
  40. package/lib/CLI/scripts/init-config.d.ts +7 -7
  41. package/lib/CLI/scripts/init-config.js +198 -14
  42. package/lib/CLI/scripts/login-cli.js +31 -7
  43. package/lib/CLI/scripts/metro-config-authority.d.ts +8 -0
  44. package/lib/CLI/scripts/metro-config-authority.js +303 -0
  45. package/lib/CLI/scripts/native/write-runtime-identity.d.ts +19 -0
  46. package/lib/CLI/scripts/native/write-runtime-identity.js +92 -0
  47. package/lib/CLI/scripts/native-entrypoint-authority.d.ts +2 -0
  48. package/lib/CLI/scripts/native-entrypoint-authority.js +378 -0
  49. package/lib/CLI/scripts/native-setup-contract.d.ts +2 -2
  50. package/lib/CLI/scripts/native-setup-contract.js +63 -33
  51. package/lib/CLI/scripts/native-startup-validator.d.ts +3 -0
  52. package/lib/CLI/scripts/native-startup-validator.js +964 -0
  53. package/lib/CLI/scripts/safe-file-transaction.d.ts +12 -0
  54. package/lib/CLI/scripts/safe-file-transaction.js +159 -0
  55. package/lib/CLI/scripts/upload-cli.d.ts +12 -2
  56. package/lib/CLI/scripts/upload-cli.js +74 -11
  57. package/lib/CLI/serverUrl.d.ts +3 -0
  58. package/lib/CLI/serverUrl.js +31 -0
  59. package/lib/api/clientApi.d.ts +3 -1
  60. package/lib/api/clientApi.js +14 -0
  61. package/lib/api/types.d.ts +39 -0
  62. package/lib/bundleInfo.d.ts +2 -0
  63. package/lib/bundleInfo.js +16 -1
  64. package/lib/context.d.ts +1 -1
  65. package/lib/context.js +12 -2
  66. package/lib/fs/bundlePointer.d.ts +1 -17
  67. package/lib/fs/bundlePointer.js +5 -93
  68. package/lib/index.d.ts +2 -0
  69. package/lib/index.js +3 -1
  70. package/lib/install/bundleInstallShared.js +4 -4
  71. package/lib/install/installFromZip.d.ts +3 -0
  72. package/lib/install/installFromZip.js +10 -1
  73. package/lib/loadConfig.d.ts +17 -1
  74. package/lib/loadConfig.js +16 -0
  75. package/lib/manager/downloadAndInstall.d.ts +3 -2
  76. package/lib/manager/downloadAndInstall.js +134 -66
  77. package/lib/manager/reporting.d.ts +8 -1
  78. package/lib/manager/reporting.js +17 -22
  79. package/lib/manager/rollbackState.d.ts +18 -52
  80. package/lib/manager/rollbackState.js +115 -216
  81. package/lib/manager/updateCheck.d.ts +1 -0
  82. package/lib/manager/updateCheck.js +224 -78
  83. package/lib/manager/updateState.d.ts +2 -1
  84. package/lib/manager/updateState.js +59 -6
  85. package/lib/metro.d.ts +8 -1
  86. package/lib/metro.js +69 -19
  87. package/lib/native/bundleDropNative.d.ts +62 -0
  88. package/lib/native/bundleDropNative.js +268 -2
  89. package/lib/native/fs.d.ts +6 -0
  90. package/lib/native/fs.js +24 -0
  91. package/lib/patch-engine/installFromPatchSet.d.ts +2 -0
  92. package/lib/patch-engine/installFromPatchSet.js +16 -5
  93. package/lib/patch-engine/patchTransport.d.ts +2 -0
  94. package/lib/patch-engine/patchTransport.js +9 -0
  95. package/lib/runtime/initState.d.ts +5 -0
  96. package/lib/runtime/initState.js +4 -0
  97. package/lib/runtime/service.js +82 -67
  98. package/lib/runtime-delivery/artifactCapability.d.ts +1 -0
  99. package/lib/runtime-delivery/artifactCapability.js +32 -0
  100. package/lib/runtime-delivery/authorityLeaseVerifier.d.ts +3 -0
  101. package/lib/runtime-delivery/authorityLeaseVerifier.js +106 -0
  102. package/lib/runtime-delivery/bootstrapConfig.d.ts +68 -0
  103. package/lib/runtime-delivery/bootstrapConfig.js +278 -0
  104. package/lib/runtime-delivery/diagnostics.d.ts +17 -0
  105. package/lib/runtime-delivery/diagnostics.js +58 -0
  106. package/lib/runtime-delivery/encoding.d.ts +5 -0
  107. package/lib/runtime-delivery/encoding.js +132 -0
  108. package/lib/runtime-delivery/heartbeat.d.ts +3 -0
  109. package/lib/runtime-delivery/heartbeat.js +88 -0
  110. package/lib/runtime-delivery/localResolver.d.ts +23 -0
  111. package/lib/runtime-delivery/localResolver.js +81 -0
  112. package/lib/runtime-delivery/manifestState.d.ts +11 -0
  113. package/lib/runtime-delivery/manifestState.js +123 -0
  114. package/lib/runtime-delivery/manifestVerifier.d.ts +13 -0
  115. package/lib/runtime-delivery/manifestVerifier.js +335 -0
  116. package/lib/runtime-delivery/runtimeDelivery.d.ts +19 -0
  117. package/lib/runtime-delivery/runtimeDelivery.js +375 -0
  118. package/lib/runtime-delivery/types.d.ts +87 -0
  119. package/lib/runtime-delivery/types.js +6 -0
  120. package/lib/scripts/bundle.d.ts +9 -2
  121. package/lib/scripts/bundle.js +68 -18
  122. package/lib/scripts/download-bundle.d.ts +1 -0
  123. package/lib/scripts/download-bundle.js +2 -2
  124. package/lib/scripts/resolveModule.d.ts +2 -0
  125. package/lib/scripts/resolveModule.js +5 -0
  126. package/package.json +5 -2
  127. package/plugin/xcodeBuildPhase.js +2 -1
@@ -0,0 +1,12 @@
1
+ export type InspectedFile = {
2
+ exists: boolean;
3
+ content: string;
4
+ mode: number;
5
+ };
6
+ export declare const inspectProjectFile: (root: string, relativePath: string) => InspectedFile;
7
+ export declare const inspectProjectDirectory: (root: string, relativePath: string) => boolean;
8
+ export declare const writeProjectFileAtomically: (root: string, relativePath: string, content: string, mode?: number) => void;
9
+ export declare const createSafeBackupDirectory: (projectRoot: string, label: string) => string;
10
+ export declare const writeBackupFile: (backupRoot: string, relativePath: string, content: string, mode: number) => void;
11
+ export declare const restoreProjectFile: (projectRoot: string, backupRoot: string, relativePath: string) => void;
12
+ export declare const removeProjectFile: (projectRoot: string, relativePath: string) => void;
@@ -0,0 +1,159 @@
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.removeProjectFile = exports.restoreProjectFile = exports.writeBackupFile = exports.createSafeBackupDirectory = exports.writeProjectFileAtomically = exports.inspectProjectDirectory = exports.inspectProjectFile = void 0;
7
+ const crypto_1 = __importDefault(require("crypto"));
8
+ const fs_1 = __importDefault(require("fs"));
9
+ const path_1 = __importDefault(require("path"));
10
+ const assertSafeRelativePath = (relativePath) => {
11
+ if (!relativePath ||
12
+ path_1.default.isAbsolute(relativePath) ||
13
+ relativePath.includes('\\') ||
14
+ relativePath.split('/').includes('..')) {
15
+ throw new Error(`Refusing unsafe transaction path: ${relativePath}`);
16
+ }
17
+ };
18
+ const assertRegularDirectory = (directory) => {
19
+ const stat = fs_1.default.lstatSync(directory);
20
+ if (stat.isSymbolicLink() || !stat.isDirectory()) {
21
+ throw new Error(`Refusing symlinked or non-directory transaction path: ${directory}`);
22
+ }
23
+ };
24
+ const lstatIfPresent = (targetPath) => {
25
+ try {
26
+ return fs_1.default.lstatSync(targetPath);
27
+ }
28
+ catch (error) {
29
+ if (error.code === 'ENOENT')
30
+ return null;
31
+ throw error;
32
+ }
33
+ };
34
+ const ensureSafeParentDirectory = (root, relativePath) => {
35
+ assertSafeRelativePath(relativePath);
36
+ assertRegularDirectory(root);
37
+ const parentParts = path_1.default.dirname(relativePath).split('/').filter(part => part !== '.');
38
+ let current = root;
39
+ for (const part of parentParts) {
40
+ current = path_1.default.join(current, part);
41
+ if (!lstatIfPresent(current)) {
42
+ fs_1.default.mkdirSync(current);
43
+ }
44
+ assertRegularDirectory(current);
45
+ }
46
+ };
47
+ const hasSafeParentDirectory = (root, relativePath) => {
48
+ assertSafeRelativePath(relativePath);
49
+ assertRegularDirectory(root);
50
+ const parentParts = path_1.default.dirname(relativePath).split('/').filter(part => part !== '.');
51
+ let current = root;
52
+ for (const part of parentParts) {
53
+ current = path_1.default.join(current, part);
54
+ if (!lstatIfPresent(current))
55
+ return false;
56
+ assertRegularDirectory(current);
57
+ }
58
+ return true;
59
+ };
60
+ const readRegularFile = (filePath) => {
61
+ const descriptor = fs_1.default.openSync(filePath, fs_1.default.constants.O_RDONLY | fs_1.default.constants.O_NOFOLLOW);
62
+ try {
63
+ const stat = fs_1.default.fstatSync(descriptor);
64
+ if (!stat.isFile()) {
65
+ throw new Error(`Refusing symlinked or non-regular transaction target: ${filePath}`);
66
+ }
67
+ return {
68
+ content: fs_1.default.readFileSync(descriptor, 'utf8'),
69
+ mode: stat.mode & 0o777,
70
+ };
71
+ }
72
+ finally {
73
+ fs_1.default.closeSync(descriptor);
74
+ }
75
+ };
76
+ const inspectProjectFile = (root, relativePath) => {
77
+ if (!hasSafeParentDirectory(root, relativePath)) {
78
+ return { exists: false, content: '', mode: 0o666 };
79
+ }
80
+ const filePath = path_1.default.join(root, relativePath);
81
+ const stat = lstatIfPresent(filePath);
82
+ if (!stat)
83
+ return { exists: false, content: '', mode: 0o666 };
84
+ if (stat.isSymbolicLink() || !stat.isFile()) {
85
+ throw new Error(`Refusing symlinked or non-regular transaction target: ${relativePath}`);
86
+ }
87
+ return { exists: true, ...readRegularFile(filePath) };
88
+ };
89
+ exports.inspectProjectFile = inspectProjectFile;
90
+ const inspectProjectDirectory = (root, relativePath) => {
91
+ if (!hasSafeParentDirectory(root, relativePath))
92
+ return false;
93
+ const directoryPath = path_1.default.join(root, relativePath);
94
+ const stat = lstatIfPresent(directoryPath);
95
+ if (!stat)
96
+ return false;
97
+ if (stat.isSymbolicLink() || !stat.isDirectory()) {
98
+ throw new Error(`Refusing symlinked or non-directory transaction target: ${relativePath}`);
99
+ }
100
+ return true;
101
+ };
102
+ exports.inspectProjectDirectory = inspectProjectDirectory;
103
+ const writeExclusiveFile = (filePath, content, mode) => {
104
+ const descriptor = fs_1.default.openSync(filePath, fs_1.default.constants.O_WRONLY |
105
+ fs_1.default.constants.O_CREAT |
106
+ fs_1.default.constants.O_EXCL |
107
+ fs_1.default.constants.O_NOFOLLOW, mode);
108
+ try {
109
+ fs_1.default.writeFileSync(descriptor, content, 'utf8');
110
+ fs_1.default.fsyncSync(descriptor);
111
+ }
112
+ finally {
113
+ fs_1.default.closeSync(descriptor);
114
+ }
115
+ };
116
+ const writeProjectFileAtomically = (root, relativePath, content, mode = 0o666) => {
117
+ const current = (0, exports.inspectProjectFile)(root, relativePath);
118
+ ensureSafeParentDirectory(root, relativePath);
119
+ const targetPath = path_1.default.join(root, relativePath);
120
+ const temporaryName = `.${path_1.default.basename(relativePath)}.bundledrop-${crypto_1.default.randomBytes(12).toString('hex')}.tmp`;
121
+ const temporaryPath = path_1.default.join(path_1.default.dirname(targetPath), temporaryName);
122
+ writeExclusiveFile(temporaryPath, content, current.exists ? current.mode : mode);
123
+ try {
124
+ fs_1.default.renameSync(temporaryPath, targetPath);
125
+ }
126
+ catch (error) {
127
+ if (lstatIfPresent(temporaryPath))
128
+ fs_1.default.unlinkSync(temporaryPath);
129
+ throw error;
130
+ }
131
+ };
132
+ exports.writeProjectFileAtomically = writeProjectFileAtomically;
133
+ const createSafeBackupDirectory = (projectRoot, label) => {
134
+ ensureSafeParentDirectory(projectRoot, '.bundledrop-backup/transaction');
135
+ const backupRoot = path_1.default.join(projectRoot, '.bundledrop-backup');
136
+ const backupDirectory = fs_1.default.mkdtempSync(path_1.default.join(backupRoot, `${label}-`));
137
+ assertRegularDirectory(backupDirectory);
138
+ return backupDirectory;
139
+ };
140
+ exports.createSafeBackupDirectory = createSafeBackupDirectory;
141
+ const writeBackupFile = (backupRoot, relativePath, content, mode) => {
142
+ ensureSafeParentDirectory(backupRoot, relativePath);
143
+ writeExclusiveFile(path_1.default.join(backupRoot, relativePath), content, mode);
144
+ };
145
+ exports.writeBackupFile = writeBackupFile;
146
+ const restoreProjectFile = (projectRoot, backupRoot, relativePath) => {
147
+ const backup = (0, exports.inspectProjectFile)(backupRoot, relativePath);
148
+ if (!backup.exists)
149
+ throw new Error(`Missing transaction backup: ${relativePath}`);
150
+ (0, exports.inspectProjectFile)(projectRoot, relativePath);
151
+ (0, exports.writeProjectFileAtomically)(projectRoot, relativePath, backup.content, backup.mode);
152
+ };
153
+ exports.restoreProjectFile = restoreProjectFile;
154
+ const removeProjectFile = (projectRoot, relativePath) => {
155
+ const target = (0, exports.inspectProjectFile)(projectRoot, relativePath);
156
+ if (target.exists)
157
+ fs_1.default.unlinkSync(path_1.default.join(projectRoot, relativePath));
158
+ };
159
+ exports.removeProjectFile = removeProjectFile;
@@ -1,4 +1,6 @@
1
- export default function upload(platform: string, options: {
1
+ import { spawnSync } from 'child_process';
2
+ import { type ModuleResolver } from '../../scripts/resolveModule';
3
+ type UploadOptions = {
2
4
  plistFile?: string;
3
5
  version?: string;
4
6
  channel?: string;
@@ -9,4 +11,12 @@ export default function upload(platform: string, options: {
9
11
  sourcemap?: boolean;
10
12
  artifactDir?: string;
11
13
  buildReceipt?: string;
12
- }): Promise<void>;
14
+ };
15
+ type UploadDependencies = {
16
+ packageRoot: string;
17
+ spawnProcess: typeof spawnSync;
18
+ resolveModule: ModuleResolver;
19
+ };
20
+ export declare function runUpload(platform: string, options: UploadOptions, dependencies?: UploadDependencies): Promise<void>;
21
+ export default function upload(platform: string, options: UploadOptions): Promise<void>;
22
+ export {};
@@ -36,6 +36,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
36
36
  return (mod && mod.__esModule) ? mod : { "default": mod };
37
37
  };
38
38
  Object.defineProperty(exports, "__esModule", { value: true });
39
+ exports.runUpload = runUpload;
39
40
  exports.default = upload;
40
41
  const axios_1 = __importDefault(require("axios"));
41
42
  const child_process_1 = require("child_process");
@@ -46,6 +47,8 @@ const plist = __importStar(require("plist"));
46
47
  const ui_1 = require("../utils/ui");
47
48
  const resolve_ios_version_1 = require("../../scripts/resolve-ios-version");
48
49
  const expo_1 = require("../../expo");
50
+ const resolveModule_1 = require("../../scripts/resolveModule");
51
+ const serverUrl_1 = require("../serverUrl");
49
52
  const DOCS_INSTALLATION_URL = 'https://bundledrop.app/docs/installation';
50
53
  const DOCS_UPLOADING_URL = 'https://bundledrop.app/docs/uploading';
51
54
  const DOCS_CI_CD_URL = 'https://bundledrop.app/docs/ci-cd';
@@ -55,7 +58,23 @@ const BUNDLE_DROP_ARTIFACT_FILES = [
55
58
  'main.jsbundle.map',
56
59
  'bundle-drop-result.json',
57
60
  ];
58
- const getPackageRoot = () => process.env.BUNDLE_DROP_PACKAGE_ROOT_OVERRIDE || path.resolve(__dirname, '..', '..', '..');
61
+ const defaultUploadDependencies = () => ({
62
+ packageRoot: path.resolve(__dirname, '..', '..', '..'),
63
+ spawnProcess: child_process_1.spawnSync,
64
+ resolveModule: resolveModule_1.resolveModuleFrom,
65
+ });
66
+ const assertPathInside = (targetPath, parentPath, label) => {
67
+ const resolvedParent = path.resolve(parentPath);
68
+ const resolvedTarget = path.resolve(targetPath);
69
+ const relative = path.relative(resolvedParent, resolvedTarget);
70
+ const escapesParent = relative === '..' ||
71
+ relative.startsWith(`..${path.sep}`) ||
72
+ path.isAbsolute(relative);
73
+ if (!escapesParent) {
74
+ return;
75
+ }
76
+ throw new Error(`${label} escaped its generated output directory: ${resolvedTarget}`);
77
+ };
59
78
  const readPackageVersion = (packageRoot) => {
60
79
  try {
61
80
  const packageJson = JSON.parse(fs.readFileSync(path.join(packageRoot, 'package.json'), 'utf-8'));
@@ -114,7 +133,7 @@ const bareArtifactPaths = (packageRoot, platform) => {
114
133
  zipPath: path.join(outputDir, `bundle-${platform}.zip`),
115
134
  };
116
135
  };
117
- async function upload(platform, options) {
136
+ async function runUpload(platform, options, dependencies = defaultUploadDependencies()) {
118
137
  console.log(); // blank line
119
138
  ui_1.log.info('🚀 React Native OTA Upload Initialized');
120
139
  const projectRoot = process.cwd();
@@ -165,7 +184,26 @@ async function upload(platform, options) {
165
184
  `CI/CD tokens: ${DOCS_CI_CD_URL}`);
166
185
  process.exit(1);
167
186
  }
168
- token = JSON.parse(fs.readFileSync(authPath, 'utf-8')).token;
187
+ let storedAuth;
188
+ try {
189
+ storedAuth = JSON.parse(fs.readFileSync(authPath, 'utf-8'));
190
+ }
191
+ catch {
192
+ ui_1.log.error('❌ Failed to read CLI auth session. Run `bundle-drop login` again or pass --token.');
193
+ process.exit(1);
194
+ }
195
+ if (!storedAuth?.token) {
196
+ ui_1.log.error('❌ CLI auth session is missing a token. Run `bundle-drop login` again or pass --token.');
197
+ process.exit(1);
198
+ }
199
+ try {
200
+ (0, serverUrl_1.assertMatchingServerOrigin)(serverUrl, storedAuth.serverUrl || storedAuth.baseUrl);
201
+ }
202
+ catch (error) {
203
+ ui_1.log.error(`❌ ${error.message}`);
204
+ process.exit(1);
205
+ }
206
+ token = storedAuth.token;
169
207
  }
170
208
  // Validate channel
171
209
  const channel = options.channel;
@@ -271,7 +309,7 @@ async function upload(platform, options) {
271
309
  ui_1.log.label('App Version', version);
272
310
  console.log();
273
311
  ui_1.log.arrow(`Bundling ${platform} app...`);
274
- const packageRoot = getPackageRoot();
312
+ const packageRoot = dependencies.packageRoot;
275
313
  const packageVersion = readPackageVersion(packageRoot);
276
314
  const compiledBundleScript = path.join(packageRoot, 'lib', 'scripts', 'bundle.js');
277
315
  const tsBundleScript = path.join(packageRoot, 'src', 'scripts', 'bundle.ts');
@@ -289,17 +327,30 @@ async function upload(platform, options) {
289
327
  });
290
328
  }
291
329
  else {
292
- const bundleCommand = fs.existsSync(compiledBundleScript)
293
- ? `node "${compiledBundleScript}"`
294
- : `ts-node "${tsBundleScript}"`;
295
- const sourcemapArg = options.sourcemap ? ' --sourcemap' : '';
296
- (0, child_process_1.execSync)(`${bundleCommand} ${platform}${sourcemapArg}`, {
330
+ const useCompiledScript = fs.existsSync(compiledBundleScript);
331
+ const script = useCompiledScript
332
+ ? compiledBundleScript
333
+ : dependencies.resolveModule('ts-node/dist/bin.js', [packageRoot, __dirname]);
334
+ const args = [
335
+ script,
336
+ ...(useCompiledScript ? [] : [tsBundleScript]),
337
+ platform,
338
+ ];
339
+ if (options.sourcemap)
340
+ args.push('--sourcemap');
341
+ const result = dependencies.spawnProcess(process.execPath, args, {
297
342
  stdio: 'inherit',
343
+ shell: false,
298
344
  env: {
299
345
  ...process.env,
300
346
  BUNDLE_DROP_APP_VERSION: version,
301
347
  },
302
348
  });
349
+ if (result.error)
350
+ throw result.error;
351
+ if (result.status !== 0) {
352
+ throw new Error(`Bundle process exited with status ${result.status}`);
353
+ }
303
354
  }
304
355
  }
305
356
  catch (error) {
@@ -425,6 +476,10 @@ async function upload(platform, options) {
425
476
  }
426
477
  finally {
427
478
  try {
479
+ const generatedRoot = isExpoProject
480
+ ? path.join(projectRoot, '.bundle-drop', 'artifacts')
481
+ : path.join(packageRoot, 'dist');
482
+ assertPathInside(artifact.outputDir, generatedRoot, 'Artifact output');
428
483
  const cleanupFiles = [
429
484
  artifact.zipPath,
430
485
  artifact.metadataPath,
@@ -436,12 +491,17 @@ async function upload(platform, options) {
436
491
  const expoExportDirectory = artifact.expoExportDirectory ??
437
492
  path.join(packageRoot, 'dist', `expo-export-${platform}`);
438
493
  for (const file of cleanupFiles) {
439
- if (file && fs.existsSync(file))
440
- fs.unlinkSync(file);
494
+ if (file) {
495
+ assertPathInside(file, artifact.outputDir, 'Artifact file');
496
+ if (fs.existsSync(file))
497
+ fs.unlinkSync(file);
498
+ }
441
499
  }
500
+ assertPathInside(assetsPath, artifact.outputDir, 'Artifact assets');
442
501
  if (fs.existsSync(assetsPath)) {
443
502
  fs.rmSync(assetsPath, { recursive: true, force: true });
444
503
  }
504
+ assertPathInside(expoExportDirectory, generatedRoot, 'Expo export');
445
505
  if (fs.existsSync(expoExportDirectory)) {
446
506
  fs.rmSync(expoExportDirectory, { recursive: true, force: true });
447
507
  }
@@ -456,3 +516,6 @@ async function upload(platform, options) {
456
516
  }
457
517
  }
458
518
  }
519
+ function upload(platform, options) {
520
+ return runUpload(platform, options);
521
+ }
@@ -0,0 +1,3 @@
1
+ export declare const DEFAULT_SERVER_URL = "https://api.bundledrop.app";
2
+ export declare const normalizeServerUrl: (value?: string) => string;
3
+ export declare const assertMatchingServerOrigin: (requestServerUrl: string, authenticatedServerUrl: string | undefined) => void;
@@ -0,0 +1,31 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.assertMatchingServerOrigin = exports.normalizeServerUrl = exports.DEFAULT_SERVER_URL = void 0;
4
+ exports.DEFAULT_SERVER_URL = 'https://api.bundledrop.app';
5
+ const normalizeServerUrl = (value) => {
6
+ const serverUrl = value || exports.DEFAULT_SERVER_URL;
7
+ let parsed;
8
+ try {
9
+ parsed = new URL(serverUrl);
10
+ }
11
+ catch {
12
+ throw new Error('Bundle Drop serverUrl must be an HTTP(S) URL without embedded credentials.');
13
+ }
14
+ if (!['http:', 'https:'].includes(parsed.protocol) || parsed.username || parsed.password) {
15
+ throw new Error('Bundle Drop serverUrl must be an HTTP(S) URL without embedded credentials.');
16
+ }
17
+ return serverUrl.replace(/\/+$/, '');
18
+ };
19
+ exports.normalizeServerUrl = normalizeServerUrl;
20
+ const assertMatchingServerOrigin = (requestServerUrl, authenticatedServerUrl) => {
21
+ if (!authenticatedServerUrl) {
22
+ throw new Error('The stored CLI login is not bound to a server. Run `bundle-drop login` again or pass --token explicitly.');
23
+ }
24
+ const requestOrigin = new URL((0, exports.normalizeServerUrl)(requestServerUrl)).origin;
25
+ const authenticatedOrigin = new URL((0, exports.normalizeServerUrl)(authenticatedServerUrl)).origin;
26
+ if (requestOrigin !== authenticatedOrigin) {
27
+ throw new Error(`The stored CLI login belongs to ${authenticatedOrigin}, but this project targets ${requestOrigin}. ` +
28
+ 'Run `bundle-drop login` for this server or pass --token explicitly.');
29
+ }
30
+ };
31
+ exports.assertMatchingServerOrigin = assertMatchingServerOrigin;
@@ -1,5 +1,7 @@
1
1
  import type { AxiosResponse } from 'axios';
2
- import { OtaResolveRequest, OtaResolveResponse, PublicChannelsParams, ReportInstalledPayload, ReportPatchApplyFailurePayload, ReportLocalRollbackPayload, BundleListParams, BundleListResponse } from './types';
2
+ import { OtaResolveRequest, OtaResolveResponse, PublicChannelsParams, ReportInstalledPayload, ReportPatchApplyFailurePayload, ReportLocalRollbackPayload, BundleListParams, BundleListResponse, OtaArtifactAuthorizationRequest, OtaActiveInstallHeartbeat } from './types';
3
+ export declare function postOtaActiveInstallHeartbeat(projectSlug: string, payload: OtaActiveInstallHeartbeat): Promise<AxiosResponse<void>>;
4
+ export declare function postOtaArtifactAuthorization(projectSlug: string, payload: OtaArtifactAuthorizationRequest): Promise<AxiosResponse<OtaResolveResponse>>;
3
5
  export declare function postOtaResolve(projectSlug: string, payload: OtaResolveRequest): Promise<AxiosResponse<OtaResolveResponse>>;
4
6
  export declare function getPublicChannels(params: PublicChannelsParams): Promise<AxiosResponse<string[]>>;
5
7
  export declare function reportInstalled(projectSlug: string, hash: string, payload: ReportInstalledPayload): Promise<AxiosResponse<void>>;
@@ -1,5 +1,7 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.postOtaActiveInstallHeartbeat = postOtaActiveInstallHeartbeat;
4
+ exports.postOtaArtifactAuthorization = postOtaArtifactAuthorization;
3
5
  exports.postOtaResolve = postOtaResolve;
4
6
  exports.getPublicChannels = getPublicChannels;
5
7
  exports.reportInstalled = reportInstalled;
@@ -7,6 +9,18 @@ exports.reportPatchApplyFailure = reportPatchApplyFailure;
7
9
  exports.reportLocalRollback = reportLocalRollback;
8
10
  exports.getBundleList = getBundleList;
9
11
  const client_1 = require("./client");
12
+ function postOtaActiveInstallHeartbeat(projectSlug, payload) {
13
+ return client_1.apiClient.post(`/projects/${encodeURIComponent(projectSlug)}/ota/active-install`, payload, {
14
+ headers: { Accept: 'application/json' },
15
+ timeout: 3000,
16
+ });
17
+ }
18
+ function postOtaArtifactAuthorization(projectSlug, payload) {
19
+ return client_1.apiClient.post(`/projects/${encodeURIComponent(projectSlug)}/ota/artifacts/authorize`, payload, {
20
+ headers: { Accept: 'application/json' },
21
+ timeout: 15000,
22
+ });
23
+ }
10
24
  function postOtaResolve(projectSlug, payload) {
11
25
  return client_1.apiClient.post(`/projects/${encodeURIComponent(projectSlug)}/ota/resolve`, payload, {
12
26
  headers: {
@@ -13,8 +13,33 @@ export type OtaResolveRequest = {
13
13
  manifestVersion: 1;
14
14
  patchAlgorithms: string[];
15
15
  supportsContentAddressedAssets: boolean;
16
+ /** Present only when this runtime sends the dedicated active-install heartbeat. */
17
+ activeInstallHeartbeatVersion?: 1;
16
18
  };
17
19
  };
20
+ export type OtaArtifactAuthorizationRequest = {
21
+ channelName: string;
22
+ platform: string;
23
+ runtimeVersion: string;
24
+ generation: number;
25
+ targetReleaseRef: string;
26
+ targetHash: string;
27
+ mode: 'full' | 'patch';
28
+ patchArtifactRef: string | null;
29
+ currentHash: string | null;
30
+ rejectedHashes: string[];
31
+ installId: string;
32
+ transport: OtaResolveRequest['transport'];
33
+ };
34
+ export type OtaActiveInstallHeartbeat = {
35
+ channelName: string;
36
+ platform: string;
37
+ runtimeVersion: string;
38
+ installId: string;
39
+ currentHash: string | null;
40
+ environment?: string;
41
+ userProperties?: UserProperties;
42
+ };
18
43
  export type OtaInstallTarget = {
19
44
  bundleHash: string;
20
45
  downloadUrl?: string;
@@ -105,6 +130,20 @@ export type UpdateCheckResponse = {
105
130
  requestedRuntimeVersion?: string;
106
131
  /** Latest runtime version available on the channel when the current runtime is incompatible. */
107
132
  latestRuntimeVersionOnChannel?: string;
133
+ /** Internal runtime-delivery authorization context. */
134
+ runtimeDelivery?: {
135
+ generation: number;
136
+ targetReleaseRef: string;
137
+ selectedMode: 'full' | 'patch';
138
+ baseHash?: string;
139
+ patchAlgorithm?: string;
140
+ patchSetHash?: string;
141
+ patchArtifactRef?: string;
142
+ missingAssetsHash?: string | null;
143
+ manifestHash?: string;
144
+ jsBundleHash?: string;
145
+ fullBundleHash?: string;
146
+ };
108
147
  };
109
148
  export type ReportPatchApplyFailurePayload = {
110
149
  platform: string;
@@ -24,5 +24,7 @@ export type BundleInfo = {
24
24
  runtimeVersion?: string;
25
25
  };
26
26
  export declare function readBundleInfo(): Promise<BundleInfo | null>;
27
+ export declare function writeBundleInfoDurably(info: BundleInfo): Promise<void>;
27
28
  export declare function writeBundleInfo(info: BundleInfo): Promise<void>;
28
29
  export declare function updateBundleInfo(partial: Partial<BundleInfo>): Promise<void>;
30
+ export declare function deleteBundleInfo(): Promise<void>;
package/lib/bundleInfo.js CHANGED
@@ -4,8 +4,10 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
4
4
  };
5
5
  Object.defineProperty(exports, "__esModule", { value: true });
6
6
  exports.readBundleInfo = readBundleInfo;
7
+ exports.writeBundleInfoDurably = writeBundleInfoDurably;
7
8
  exports.writeBundleInfo = writeBundleInfo;
8
9
  exports.updateBundleInfo = updateBundleInfo;
10
+ exports.deleteBundleInfo = deleteBundleInfo;
9
11
  const fs_1 = __importDefault(require("./native/fs"));
10
12
  const BUNDLE_INFO_PATH = `${fs_1.default.DocumentDirectoryPath}/bundle-info.json`;
11
13
  async function readBundleInfo() {
@@ -20,9 +22,12 @@ async function readBundleInfo() {
20
22
  return null;
21
23
  }
22
24
  }
25
+ async function writeBundleInfoDurably(info) {
26
+ await fs_1.default.writeFile(BUNDLE_INFO_PATH, JSON.stringify(info, null, 2), 'utf8');
27
+ }
23
28
  async function writeBundleInfo(info) {
24
29
  try {
25
- await fs_1.default.writeFile(BUNDLE_INFO_PATH, JSON.stringify(info, null, 2), 'utf8');
30
+ await writeBundleInfoDurably(info);
26
31
  }
27
32
  catch (e) {
28
33
  console.warn('⚠️ Failed to write bundle-info.json', e);
@@ -32,3 +37,13 @@ async function updateBundleInfo(partial) {
32
37
  const existing = (await readBundleInfo()) || {};
33
38
  await writeBundleInfo({ ...existing, ...partial });
34
39
  }
40
+ async function deleteBundleInfo() {
41
+ try {
42
+ if (await fs_1.default.exists(BUNDLE_INFO_PATH)) {
43
+ await fs_1.default.unlink(BUNDLE_INFO_PATH);
44
+ }
45
+ }
46
+ catch (e) {
47
+ console.warn('⚠️ Failed to delete bundle-info.json', e);
48
+ }
49
+ }
package/lib/context.d.ts CHANGED
@@ -1,4 +1,4 @@
1
- export declare const config: import("./loadConfig").BundleDropProjectConfig;
1
+ export declare const config: import("./loadConfig").ResolvedBundleDropProjectConfig;
2
2
  export declare const platform: string;
3
3
  export declare const isIOS: boolean;
4
4
  export declare const runtimeVersion: string;
package/lib/context.js CHANGED
@@ -29,6 +29,16 @@ exports.runtimeVersion = typeof platformRuntimeVersion === 'string'
29
29
  : (0, nativeIdentity_1.resolveExpoNativeRuntimeVersion)(platformRuntimeVersion.source)
30
30
  : undefined;
31
31
  exports.defaultChannel = exports.config.defaultChannel || 'develop';
32
+ const configuredMaxCrashCount = exports.config.rollback?.maxCrashCount ?? 3;
33
+ if (!Number.isSafeInteger(configuredMaxCrashCount) ||
34
+ configuredMaxCrashCount < 0 ||
35
+ configuredMaxCrashCount > 2147483647) {
36
+ throw new Error('[BundleDrop] rollback.maxCrashCount must be a non-negative 32-bit integer.');
37
+ }
38
+ const configuredHealthyAfterSec = exports.config.rollback?.healthyAfterSec ?? 0;
39
+ if (!Number.isFinite(configuredHealthyAfterSec) || configuredHealthyAfterSec < 0) {
40
+ throw new Error('[BundleDrop] rollback.healthyAfterSec must be a finite non-negative number.');
41
+ }
32
42
  exports.BUNDLE_DROP_ROOT = exports.isIOS
33
43
  ? `${fs_1.default.LibraryDirectoryPath}/bundle-drop`
34
44
  : `${fs_1.default.DocumentDirectoryPath}/bundle-drop`;
@@ -43,8 +53,8 @@ exports.bundleDropConfig = {
43
53
  org: { slug: exports.config.org.slug },
44
54
  project: { name: exports.config.project.name, slug: exports.config.project.slug },
45
55
  rollback: {
46
- maxCrashCount: exports.config.rollback?.maxCrashCount ?? 3,
56
+ maxCrashCount: configuredMaxCrashCount,
47
57
  healthCheckMode: exports.config.rollback?.healthCheckMode === 'manual' ? 'manual' : 'auto',
48
- healthyAfterSec: exports.config.rollback?.healthyAfterSec ?? 0,
58
+ healthyAfterSec: configuredHealthyAfterSec,
49
59
  },
50
60
  };
@@ -1,17 +1 @@
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 restorePreviousBundlePointer(pointer: BundlePointer | null): Promise<void>;
11
- export declare function setCurrentBundlePointer(_bundlePath: string, hash: string, options?: {
12
- setPrevious?: boolean;
13
- }): Promise<void>;
14
- export declare function rollbackToPreviousPointer(): Promise<BundlePointer | null>;
15
- export declare function deleteCurrentBundlePointer(): Promise<void>;
16
- export declare function deletePreviousBundlePointer(): Promise<void>;
17
- export declare function clearCurrentBundlePointer(): Promise<void>;
1
+ export declare function readCurrentBundleHash(): Promise<string | null>;