@gfean/react-native-bundle-drop 0.3.9 → 0.4.2

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 (80) hide show
  1. package/BundleDrop.podspec +9 -2
  2. package/README.md +19 -0
  3. package/android/build.gradle +43 -4
  4. package/android/src/main/cpp/CMakeLists.txt +45 -0
  5. package/android/src/main/cpp/bundle_drop_xdelta_jni.c +55 -0
  6. package/android/src/main/java/com/bundledrop/BundleDropBundleVerifier.kt +73 -0
  7. package/android/src/main/java/com/bundledrop/BundleDropFileOps.kt +193 -8
  8. package/android/src/main/java/com/bundledrop/BundleDropModule.kt +60 -7
  9. package/android/src/main/java/com/bundledrop/BundleDropOtaPrefs.kt +2 -12
  10. package/android/src/main/java/com/bundledrop/BundleDropOtaResolver.kt +208 -3
  11. package/android/src/main/java/com/bundledrop/BundleDropXdeltaNative.kt +57 -0
  12. package/ios/BundleDropBridge.m +27 -0
  13. package/ios/BundleDropBundleVerifier.swift +106 -0
  14. package/ios/BundleDropFileOps.swift +149 -0
  15. package/ios/BundleDropModule.swift +100 -11
  16. package/ios/BundleDropOtaResolver.swift +149 -3
  17. package/ios/BundleDropZipExtractor.m +75 -3
  18. package/lib/CLI/cli.js +1 -8
  19. package/lib/CLI/scripts/upload-cli.d.ts +0 -1
  20. package/lib/CLI/scripts/upload-cli.js +98 -36
  21. package/lib/api/client.d.ts +11 -1
  22. package/lib/api/client.js +84 -17
  23. package/lib/api/clientApi.d.ts +2 -1
  24. package/lib/api/clientApi.js +9 -0
  25. package/lib/api/types.d.ts +65 -13
  26. package/lib/bundleInfo.d.ts +2 -0
  27. package/lib/fs/bundlePointer.d.ts +2 -1
  28. package/lib/fs/bundlePointer.js +34 -6
  29. package/lib/fs/fsUtils.js +4 -1
  30. package/lib/injectImageResolver.js +82 -75
  31. package/lib/install/bundleInstallShared.d.ts +8 -0
  32. package/lib/install/bundleInstallShared.js +97 -0
  33. package/lib/install/bundleVerification.d.ts +5 -0
  34. package/lib/install/bundleVerification.js +34 -0
  35. package/lib/install/installFromZip.d.ts +2 -5
  36. package/lib/install/installFromZip.js +33 -68
  37. package/lib/loadConfig.js +12 -1
  38. package/lib/manager/downloadAndInstall.d.ts +9 -0
  39. package/lib/manager/downloadAndInstall.js +84 -24
  40. package/lib/manager/reporting.js +26 -2
  41. package/lib/manager/rollbackState.js +21 -12
  42. package/lib/manager/updateCheck.js +89 -11
  43. package/lib/manager/updateState.js +3 -9
  44. package/lib/manifest/bundleManifest.d.ts +33 -0
  45. package/lib/manifest/bundleManifest.js +298 -0
  46. package/lib/native/bundleDropNative.js +1 -2
  47. package/lib/native/fs.d.ts +14 -0
  48. package/lib/native/fs.js +35 -0
  49. package/lib/patch-engine/installFromPatchSet.d.ts +16 -0
  50. package/lib/patch-engine/installFromPatchSet.js +143 -0
  51. package/lib/patch-engine/patchOperations.d.ts +33 -0
  52. package/lib/patch-engine/patchOperations.js +77 -0
  53. package/lib/patch-engine/patchTransport.d.ts +18 -0
  54. package/lib/patch-engine/patchTransport.js +81 -0
  55. package/lib/patchAlgorithms.d.ts +4 -0
  56. package/lib/patchAlgorithms.js +9 -0
  57. package/lib/runtime/service.js +43 -9
  58. package/lib/scripts/bundle.d.ts +3 -0
  59. package/lib/scripts/bundle.js +197 -43
  60. package/lib/scripts/download-bundle.js +18 -7
  61. package/package.json +44 -6
  62. package/third_party/xdelta/NOTICE +7 -0
  63. package/third_party/xdelta/PROVENANCE.md +10 -0
  64. package/third_party/xdelta/bundle_drop_xdelta.c +252 -0
  65. package/third_party/xdelta/bundle_drop_xdelta.h +26 -0
  66. package/third_party/xdelta/xdelta3/LICENSE +176 -0
  67. package/third_party/xdelta/xdelta3/config.h +34 -0
  68. package/third_party/xdelta/xdelta3/xdelta3-cfgs.h +171 -0
  69. package/third_party/xdelta/xdelta3/xdelta3-decode.h +1219 -0
  70. package/third_party/xdelta/xdelta3/xdelta3-hash.h +159 -0
  71. package/third_party/xdelta/xdelta3/xdelta3-internal.h +385 -0
  72. package/third_party/xdelta/xdelta3/xdelta3-list.h +127 -0
  73. package/third_party/xdelta/xdelta3/xdelta3.c +4819 -0
  74. package/third_party/xdelta/xdelta3/xdelta3.h +1476 -0
  75. package/lib/CLI/scripts/init-native-config.d.ts +0 -18
  76. package/lib/CLI/scripts/init-native-config.js +0 -539
  77. package/lib/assetExtensions.d.ts +0 -4
  78. package/lib/assetExtensions.js +0 -35
  79. package/lib/scripts/upload-bundle.d.ts +0 -9
  80. package/lib/scripts/upload-bundle.js +0 -320
@@ -49,11 +49,65 @@ const DOCS_INSTALLATION_URL = 'https://bundledrop.app/docs/installation';
49
49
  const DOCS_UPLOADING_URL = 'https://bundledrop.app/docs/uploading';
50
50
  const DOCS_CI_CD_URL = 'https://bundledrop.app/docs/ci-cd';
51
51
  const DOCS_RUNTIME_VERSION_URL = 'https://bundledrop.app/docs/runtime-version';
52
+ const BUNDLE_DROP_ARTIFACT_FILES = [
53
+ 'main.jsbundle',
54
+ 'main.jsbundle.map',
55
+ 'bundle-drop-result.json',
56
+ ];
52
57
  const getPackageRoot = () => process.env.BUNDLE_DROP_PACKAGE_ROOT_OVERRIDE || path.resolve(__dirname, '..', '..', '..');
58
+ const readPackageVersion = (packageRoot) => {
59
+ try {
60
+ const packageJson = JSON.parse(fs.readFileSync(path.join(packageRoot, 'package.json'), 'utf-8'));
61
+ return typeof packageJson.version === 'string' && packageJson.version.trim()
62
+ ? packageJson.version.trim()
63
+ : undefined;
64
+ }
65
+ catch {
66
+ return undefined;
67
+ }
68
+ };
69
+ const readManifestRuntimeVersion = (manifestPath) => {
70
+ let manifest;
71
+ try {
72
+ manifest = JSON.parse(fs.readFileSync(manifestPath, 'utf-8'));
73
+ }
74
+ catch (error) {
75
+ throw new Error(`bundle-manifest.json is required and must be valid JSON: ${error.message}`);
76
+ }
77
+ if (manifest.manifestVersion !== 1) {
78
+ throw new Error('bundle-manifest.json must use manifestVersion 1');
79
+ }
80
+ if (typeof manifest.runtimeVersion !== 'string' || !manifest.runtimeVersion) {
81
+ throw new Error('bundle-manifest.json is missing runtimeVersion');
82
+ }
83
+ return manifest.runtimeVersion;
84
+ };
85
+ const prepareArtifactDirForRun = (artifactDir) => {
86
+ if (!artifactDir)
87
+ return;
88
+ fs.mkdirSync(artifactDir, { recursive: true });
89
+ for (const fileName of BUNDLE_DROP_ARTIFACT_FILES) {
90
+ const filePath = path.join(artifactDir, fileName);
91
+ if (fs.existsSync(filePath))
92
+ fs.unlinkSync(filePath);
93
+ }
94
+ };
95
+ const writeArtifactResult = (artifactDir, result) => {
96
+ if (!artifactDir)
97
+ return;
98
+ fs.mkdirSync(artifactDir, { recursive: true });
99
+ fs.writeFileSync(path.join(artifactDir, 'bundle-drop-result.json'), JSON.stringify(result, null, 2));
100
+ };
101
+ const stringifyUploadError = (err) => {
102
+ const raw = err?.response?.data || err.message;
103
+ return typeof raw === 'object' ? JSON.stringify(raw, null, 2) : String(raw);
104
+ };
53
105
  async function upload(platform, options) {
54
106
  console.log(); // blank line
55
107
  ui_1.log.info('🚀 React Native OTA Upload Initialized');
56
108
  const projectRoot = process.cwd();
109
+ const artifactDir = options.artifactDir ? path.resolve(options.artifactDir) : undefined;
110
+ prepareArtifactDirForRun(artifactDir);
57
111
  const configPath = path.resolve(projectRoot, 'bundle.drop.config.js');
58
112
  //eslint-disable-next-line
59
113
  const authPath = path.join(require('os').homedir(), '.bundle-drop', 'auth.json');
@@ -94,7 +148,6 @@ async function upload(platform, options) {
94
148
  ui_1.log.label('Channel', channel);
95
149
  let version = options.version;
96
150
  const buildGradlePath = options.buildGradlePath || options.buildgradlePath;
97
- let runtimeVersionOverride = options.runtimeVersion;
98
151
  let releaseNotes = options.releaseNotes;
99
152
  const MAX_NOTES = 2000;
100
153
  if (releaseNotes && releaseNotes.length > MAX_NOTES) {
@@ -166,6 +219,7 @@ async function upload(platform, options) {
166
219
  console.log();
167
220
  ui_1.log.arrow(`Bundling ${platform} app...`);
168
221
  const packageRoot = getPackageRoot();
222
+ const packageVersion = readPackageVersion(packageRoot);
169
223
  const compiledBundleScript = path.join(packageRoot, 'lib', 'scripts', 'bundle.js');
170
224
  const tsBundleScript = path.join(packageRoot, 'src', 'scripts', 'bundle.ts');
171
225
  const bundleCommand = fs.existsSync(compiledBundleScript)
@@ -175,6 +229,10 @@ async function upload(platform, options) {
175
229
  try {
176
230
  (0, child_process_1.execSync)(`${bundleCommand} ${platform}${sourcemapArg}`, {
177
231
  stdio: 'inherit',
232
+ env: {
233
+ ...process.env,
234
+ BUNDLE_DROP_APP_VERSION: version,
235
+ },
178
236
  });
179
237
  }
180
238
  catch {
@@ -182,28 +240,14 @@ async function upload(platform, options) {
182
240
  process.exit(1);
183
241
  }
184
242
  const outputDir = path.join(packageRoot, 'dist');
185
- const metadataPath = path.join(outputDir, `metadata-${platform}.json`);
243
+ const manifestPath = path.join(outputDir, 'bundle-manifest.json');
186
244
  let runtimeVersion;
187
245
  try {
188
- const parsed = JSON.parse(fs.readFileSync(metadataPath, 'utf-8'));
189
- runtimeVersion = parsed.runtimeVersion;
190
- if (runtimeVersion) {
191
- ui_1.log.label('Runtime Version', runtimeVersion);
192
- }
193
- }
194
- catch {
195
- // ignore
246
+ runtimeVersion = readManifestRuntimeVersion(manifestPath);
247
+ ui_1.log.label('Runtime Version', runtimeVersion);
196
248
  }
197
- if (runtimeVersionOverride) {
198
- runtimeVersion = runtimeVersionOverride;
199
- ui_1.log.label('Runtime Version (override)', runtimeVersion);
200
- }
201
- else if (!runtimeVersion && config.runtimeVersion?.[platform]) {
202
- runtimeVersion = config.runtimeVersion[platform];
203
- ui_1.log.label('Runtime Version (from config)', runtimeVersion);
204
- }
205
- if (!runtimeVersion) {
206
- ui_1.log.error(`❌ runtimeVersion could not be determined\nSee ${DOCS_RUNTIME_VERSION_URL}`);
249
+ catch (error) {
250
+ ui_1.log.error(`❌ ${error.message}\nSee ${DOCS_RUNTIME_VERSION_URL}`);
207
251
  process.exit(1);
208
252
  }
209
253
  const zipPath = path.join(outputDir, `bundle-${platform}.zip`);
@@ -219,6 +263,9 @@ async function upload(platform, options) {
219
263
  form.append('version', version);
220
264
  form.append('channelName', channel);
221
265
  form.append('runtimeVersion', runtimeVersion);
266
+ if (packageVersion) {
267
+ form.append('packageVersion', packageVersion);
268
+ }
222
269
  if (releaseNotes) {
223
270
  form.append('releaseNotes', releaseNotes);
224
271
  }
@@ -227,6 +274,7 @@ async function upload(platform, options) {
227
274
  }
228
275
  form.append('file', fs.createReadStream(zipPath));
229
276
  const uploadLoader = (0, ui_1.startLoadingStatus)('Uploading bundle to server');
277
+ let uploadSucceeded = false;
230
278
  try {
231
279
  const res = await axios_1.default.post(`${serverUrl}/bundle/upload`, form, {
232
280
  headers: {
@@ -238,14 +286,14 @@ async function upload(platform, options) {
238
286
  });
239
287
  const sourceMapFile = path.join(outputDir, 'main.jsbundle.map');
240
288
  const hasSourceMap = options.sourcemap && fs.existsSync(sourceMapFile);
241
- const artifactDir = options.artifactDir ? path.resolve(options.artifactDir) : undefined;
242
289
  const result = {
243
290
  platform,
244
- appVersion: version ?? null,
245
- channel: channel ?? null,
246
- orgSlug: orgSlug ?? null,
247
- projectSlug: projectSlug ?? null,
291
+ appVersion: version,
292
+ channel,
293
+ orgSlug,
294
+ projectSlug,
248
295
  runtimeVersion: res.data?.runtimeVersion ?? runtimeVersion ?? null,
296
+ packageVersion: res.data?.packageVersion ?? packageVersion ?? null,
249
297
  bundleId: res.data?.bundleId ?? null,
250
298
  bundleVersion: res.data?.bundleVersion ?? null,
251
299
  bundleVersionLabel: res.data?.bundleVersionLabel ?? null,
@@ -287,23 +335,35 @@ async function upload(platform, options) {
287
335
  if (artifactDir) {
288
336
  ui_1.log.label('Artifact dir', artifactDir);
289
337
  }
338
+ uploadSucceeded = true;
290
339
  }
291
340
  catch (err) {
292
341
  uploadLoader.stop();
293
- const raw = err?.response?.data || err.message;
294
- if (typeof raw === 'object') {
295
- ui_1.log.error(`Upload failed:\n${JSON.stringify(raw, null, 2)}`);
296
- }
297
- else {
298
- ui_1.log.error(`Upload failed: ${raw}`);
299
- }
300
- process.exit(1);
342
+ const uploadError = stringifyUploadError(err);
343
+ writeArtifactResult(artifactDir, {
344
+ success: false,
345
+ status: 'failed',
346
+ error: uploadError,
347
+ platform,
348
+ appVersion: version,
349
+ channel,
350
+ orgSlug,
351
+ projectSlug,
352
+ runtimeVersion,
353
+ packageVersion: packageVersion ?? null,
354
+ releaseNotes: releaseNotes ?? null,
355
+ author: options.author ?? null,
356
+ });
357
+ ui_1.log.error(`Upload failed: ${uploadError}`);
358
+ process.exitCode = 1;
359
+ return;
301
360
  }
302
361
  finally {
303
362
  try {
304
363
  const cleanupFiles = [
305
364
  zipPath,
306
365
  path.join(outputDir, `metadata-${platform}.json`),
366
+ path.join(outputDir, 'bundle-manifest.json'),
307
367
  path.join(outputDir, 'main.jsbundle'),
308
368
  path.join(outputDir, 'main.jsbundle.map'),
309
369
  ];
@@ -315,9 +375,11 @@ async function upload(platform, options) {
315
375
  if (fs.existsSync(assetsPath)) {
316
376
  fs.rmSync(assetsPath, { recursive: true, force: true });
317
377
  }
318
- console.log();
319
- ui_1.log.success('🎉 Done! Bundle uploaded and cleaned.');
320
- console.log();
378
+ if (uploadSucceeded) {
379
+ console.log();
380
+ ui_1.log.success('🎉 Done! Bundle uploaded and cleaned.');
381
+ console.log();
382
+ }
321
383
  }
322
384
  catch (cleanupErr) {
323
385
  ui_1.log.warn(`Cleanup failed: ${cleanupErr.message}`);
@@ -1 +1,11 @@
1
- export declare const apiClient: any;
1
+ import type { AxiosResponse } from 'axios';
2
+ type ApiRequestOptions = {
3
+ headers?: Record<string, string>;
4
+ timeout?: number;
5
+ };
6
+ type ApiClient = {
7
+ get<T = unknown>(path: string, options?: ApiRequestOptions): Promise<AxiosResponse<T>>;
8
+ post<T = unknown>(path: string, payload?: unknown, options?: ApiRequestOptions): Promise<AxiosResponse<T>>;
9
+ };
10
+ export declare const apiClient: ApiClient;
11
+ export {};
package/lib/api/client.js CHANGED
@@ -1,24 +1,91 @@
1
1
  "use strict";
2
- var __importDefault = (this && this.__importDefault) || function (mod) {
3
- return (mod && mod.__esModule) ? mod : { "default": mod };
4
- };
5
2
  Object.defineProperty(exports, "__esModule", { value: true });
6
3
  exports.apiClient = void 0;
7
- const axios_cjs_1 = __importDefault(require("axios/dist/browser/axios.cjs"));
8
4
  const context_1 = require("../context");
9
- exports.apiClient = axios_cjs_1.default.create({
10
- baseURL: context_1.config.serverUrl,
11
- });
12
- // Attach x-api-key automatically (if configured) and ensure Accept header defaults to JSON for API calls.
13
- exports.apiClient.interceptors.request.use(request => {
14
- const headers = (request.headers || {});
5
+ const joinUrl = (baseUrl, path) => {
6
+ if (/^https?:\/\//i.test(path)) {
7
+ return path;
8
+ }
9
+ return `${baseUrl.replace(/\/+$/, '')}/${path.replace(/^\/+/, '')}`;
10
+ };
11
+ const hasHeader = (headers, name) => {
12
+ const normalizedName = name.toLowerCase();
13
+ return Object.keys(headers).some(header => header.toLowerCase() === normalizedName);
14
+ };
15
+ const buildHeaders = (headers, hasPayload) => {
16
+ const nextHeaders = { ...(headers || {}) };
15
17
  const apiKey = context_1.config.project?.apiKey;
16
- if (apiKey && !('x-api-key' in headers)) {
17
- headers['x-api-key'] = apiKey;
18
+ if (apiKey && !hasHeader(nextHeaders, 'x-api-key')) {
19
+ nextHeaders['x-api-key'] = apiKey;
18
20
  }
19
- if (!headers.Accept) {
20
- headers.Accept = 'application/json';
21
+ if (!hasHeader(nextHeaders, 'Accept')) {
22
+ nextHeaders.Accept = 'application/json';
21
23
  }
22
- request.headers = headers;
23
- return request;
24
- });
24
+ if (hasPayload && !hasHeader(nextHeaders, 'Content-Type')) {
25
+ nextHeaders['Content-Type'] = 'application/json';
26
+ }
27
+ return nextHeaders;
28
+ };
29
+ const readResponseHeaders = (headers) => {
30
+ const result = {};
31
+ if (typeof headers.forEach !== 'function') {
32
+ return result;
33
+ }
34
+ headers.forEach((value, key) => {
35
+ result[key] = value;
36
+ });
37
+ return result;
38
+ };
39
+ const readResponseData = async (response) => {
40
+ const text = await response.text();
41
+ if (!text) {
42
+ return undefined;
43
+ }
44
+ try {
45
+ return JSON.parse(text);
46
+ }
47
+ catch {
48
+ return text;
49
+ }
50
+ };
51
+ async function request(method, path, payload, options) {
52
+ const hasPayload = payload !== undefined;
53
+ const controller = typeof AbortController === 'undefined' ? null : new AbortController();
54
+ const timeoutId = controller && options?.timeout
55
+ ? setTimeout(() => controller.abort(), options.timeout)
56
+ : null;
57
+ try {
58
+ const response = await fetch(joinUrl(context_1.config.serverUrl, path), {
59
+ method,
60
+ headers: buildHeaders(options?.headers, hasPayload),
61
+ body: hasPayload ? JSON.stringify(payload) : undefined,
62
+ signal: controller?.signal,
63
+ });
64
+ const data = await readResponseData(response);
65
+ const axiosResponse = {
66
+ data,
67
+ status: response.status,
68
+ statusText: response.statusText,
69
+ headers: readResponseHeaders(response.headers),
70
+ config: {},
71
+ };
72
+ if (!response.ok) {
73
+ const error = new Error(`Bundle Drop API request failed with status ${response.status}`);
74
+ Object.assign(error, {
75
+ response: axiosResponse,
76
+ isAxiosError: true,
77
+ });
78
+ throw error;
79
+ }
80
+ return axiosResponse;
81
+ }
82
+ finally {
83
+ if (timeoutId) {
84
+ clearTimeout(timeoutId);
85
+ }
86
+ }
87
+ }
88
+ exports.apiClient = {
89
+ get: (path, options) => request('GET', path, undefined, options),
90
+ post: (path, payload, options) => request('POST', path, payload, options),
91
+ };
@@ -1,7 +1,8 @@
1
1
  import type { AxiosResponse } from 'axios';
2
- import { OtaResolveRequest, OtaResolveResponse, PublicChannelsParams, ReportInstalledPayload, ReportLocalRollbackPayload, BundleListParams, BundleListResponse } from './types';
2
+ import { OtaResolveRequest, OtaResolveResponse, PublicChannelsParams, ReportInstalledPayload, ReportPatchApplyFailurePayload, 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 reportPatchApplyFailure(projectSlug: string, payload: ReportPatchApplyFailurePayload): Promise<AxiosResponse<void>>;
6
7
  export declare function reportLocalRollback(projectSlug: string, hash: string, payload: ReportLocalRollbackPayload): Promise<AxiosResponse<void>>;
7
8
  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.reportPatchApplyFailure = reportPatchApplyFailure;
6
7
  exports.reportLocalRollback = reportLocalRollback;
7
8
  exports.getBundleList = getBundleList;
8
9
  const client_1 = require("./client");
@@ -31,6 +32,14 @@ function reportInstalled(projectSlug, hash, payload) {
31
32
  timeout: 3000,
32
33
  });
33
34
  }
35
+ function reportPatchApplyFailure(projectSlug, payload) {
36
+ return client_1.apiClient.post(`/projects/${encodeURIComponent(projectSlug)}/ota/patch/apply-failure`, payload, {
37
+ headers: {
38
+ Accept: 'application/json',
39
+ },
40
+ timeout: 3000,
41
+ });
42
+ }
34
43
  function reportLocalRollback(projectSlug, hash, payload) {
35
44
  return client_1.apiClient.post(`/projects/${encodeURIComponent(projectSlug)}/bundle/${encodeURIComponent(hash)}/local-rollback-report`, payload, {
36
45
  headers: {
@@ -1,15 +1,36 @@
1
1
  import type { UserProperties } from '../fs/userProperties';
2
+ import type { SupportedPatchAlgorithm } from '../patchAlgorithms';
2
3
  export type OtaResolveRequest = {
3
4
  channelName: string;
4
5
  platform: string;
5
- runtimeVersion?: string | null;
6
- environment?: string | null;
7
- currentHash?: string | null;
8
- currentUserProperties?: UserProperties;
9
- previousHash?: string | null;
10
- rejectedHashes?: string[];
11
- currentBundleVersion?: number | null;
12
- installId?: string | null;
6
+ runtimeVersion: string | null;
7
+ environment: string | null;
8
+ currentHash: string | null;
9
+ currentUserProperties: UserProperties;
10
+ rejectedHashes: string[];
11
+ installId: string;
12
+ transport: {
13
+ manifestVersion: 1;
14
+ patchAlgorithms: string[];
15
+ supportsContentAddressedAssets: boolean;
16
+ };
17
+ };
18
+ export type OtaInstallTarget = {
19
+ bundleHash: string;
20
+ downloadUrl?: string;
21
+ manifestUrl: string;
22
+ bundleVersion?: number;
23
+ version?: string;
24
+ runtimeVersion: string;
25
+ };
26
+ export type OtaPatchSet = {
27
+ algorithm: string;
28
+ patchSetHash: string;
29
+ patchesUrl: string;
30
+ assets?: {
31
+ missingAssetsUrl?: string | null;
32
+ missingAssetsHash?: string | null;
33
+ };
13
34
  };
14
35
  export type OtaResolveResponse = {
15
36
  action: 'NOOP';
@@ -21,12 +42,19 @@ export type OtaResolveResponse = {
21
42
  reason?: string;
22
43
  } | {
23
44
  action: 'INSTALL';
24
- target: {
25
- hash: string;
45
+ mode: 'full';
46
+ target: OtaInstallTarget & {
47
+ downloadUrl: string;
48
+ };
49
+ } | {
50
+ action: 'INSTALL';
51
+ mode: 'patch';
52
+ baseHash: string;
53
+ target: OtaInstallTarget;
54
+ patchSet: OtaPatchSet;
55
+ fallback: {
56
+ mode: 'full';
26
57
  downloadUrl: string;
27
- bundleVersion?: number;
28
- version?: string;
29
- runtimeVersion?: string;
30
58
  };
31
59
  };
32
60
  /**
@@ -44,6 +72,21 @@ export type UpdateCheckResponse = {
44
72
  version?: string;
45
73
  /** Target bundle hash when an install is available. */
46
74
  hash?: string;
75
+ /** Canonical full-tree bundle hash when an install is available. */
76
+ bundleHash?: string;
77
+ /** Response transport selected by the server. */
78
+ mode?: 'full' | 'patch';
79
+ /** Base bundle hash required when mode is patch. */
80
+ baseHash?: string;
81
+ /** Patch-set transport metadata when mode is patch. */
82
+ patchSet?: OtaPatchSet;
83
+ /** Full bundle fallback for patch responses. */
84
+ fallback?: {
85
+ mode: 'full';
86
+ downloadUrl: string;
87
+ };
88
+ /** Target manifest URL, when provided by the server. */
89
+ manifestUrl?: string;
47
90
  /** Signed or public download URL for the target bundle. */
48
91
  downloadUrl?: string;
49
92
  /** Channel used for this resolve decision. */
@@ -63,6 +106,15 @@ export type UpdateCheckResponse = {
63
106
  /** Latest runtime version available on the channel when the current runtime is incompatible. */
64
107
  latestRuntimeVersionOnChannel?: string;
65
108
  };
109
+ export type ReportPatchApplyFailurePayload = {
110
+ platform: string;
111
+ runtimeVersion: string;
112
+ installId?: string;
113
+ baseHash?: string;
114
+ targetHash: string;
115
+ algorithm?: SupportedPatchAlgorithm;
116
+ reason?: string;
117
+ };
66
118
  export type PublicChannelsParams = {
67
119
  projectSlug: string;
68
120
  };
@@ -18,6 +18,8 @@ export type BundleInfo = {
18
18
  pendingApply?: boolean;
19
19
  /** Last bundle hash successfully reported to the backend as installed. */
20
20
  lastInstalledReportedHash?: string;
21
+ /** Bundle hashes already reported as installed for this app install. */
22
+ installedReportedHashes?: string[];
21
23
  /** Runtime version the bundle is compatible with. */
22
24
  runtimeVersion?: string;
23
25
  };
@@ -7,7 +7,8 @@ export declare function readCurrentBundlePointer(): Promise<BundlePointer | null
7
7
  export declare function readPreviousBundlePointer(): Promise<BundlePointer | null>;
8
8
  export declare function writeCurrentBundlePointer(pointer: BundlePointer): Promise<void>;
9
9
  export declare function writePreviousBundlePointer(pointer: BundlePointer): Promise<void>;
10
- export declare function setCurrentBundlePointer(bundlePath: string, hash: string, options?: {
10
+ export declare function restorePreviousBundlePointer(pointer: BundlePointer | null): Promise<void>;
11
+ export declare function setCurrentBundlePointer(_bundlePath: string, hash: string, options?: {
11
12
  setPrevious?: boolean;
12
13
  }): Promise<void>;
13
14
  export declare function rollbackToPreviousPointer(): Promise<BundlePointer | null>;
@@ -7,6 +7,7 @@ exports.readCurrentBundlePointer = readCurrentBundlePointer;
7
7
  exports.readPreviousBundlePointer = readPreviousBundlePointer;
8
8
  exports.writeCurrentBundlePointer = writeCurrentBundlePointer;
9
9
  exports.writePreviousBundlePointer = writePreviousBundlePointer;
10
+ exports.restorePreviousBundlePointer = restorePreviousBundlePointer;
10
11
  exports.setCurrentBundlePointer = setCurrentBundlePointer;
11
12
  exports.rollbackToPreviousPointer = rollbackToPreviousPointer;
12
13
  exports.deleteCurrentBundlePointer = deleteCurrentBundlePointer;
@@ -17,15 +18,21 @@ const context_1 = require("../context");
17
18
  const fsUtils_1 = require("./fsUtils");
18
19
  const CURRENT_POINTER_PATH = `${context_1.BUNDLE_DROP_ROOT}/current.json`;
19
20
  const PREVIOUS_POINTER_PATH = `${context_1.BUNDLE_DROP_ROOT}/previous.json`;
21
+ const BUNDLE_HASH_PATTERN = /^[a-f0-9]{64}$/;
22
+ const bundlePathForHash = (hash) => `${context_1.BUNDLE_DROP_ROOT}/bundles/${hash}/main.jsbundle`;
20
23
  async function readPointer(path) {
21
24
  try {
22
25
  if (!(await fs_1.default.exists(path)))
23
26
  return null;
24
27
  const raw = await fs_1.default.readFile(path, 'utf8');
25
28
  const parsed = JSON.parse(raw);
26
- if (!parsed?.hash || !parsed?.bundlePath)
29
+ if (!BUNDLE_HASH_PATTERN.test(parsed?.hash ?? ''))
27
30
  return null;
28
- return parsed;
31
+ return {
32
+ hash: parsed.hash,
33
+ bundlePath: bundlePathForHash(parsed.hash),
34
+ updatedAt: typeof parsed.updatedAt === 'string' ? parsed.updatedAt : '',
35
+ };
29
36
  }
30
37
  catch {
31
38
  return null;
@@ -38,16 +45,26 @@ async function readPreviousBundlePointer() {
38
45
  return readPointer(PREVIOUS_POINTER_PATH);
39
46
  }
40
47
  async function writeCurrentBundlePointer(pointer) {
48
+ assertCanonicalPointerHash(pointer.hash);
41
49
  const root = context_1.BUNDLE_DROP_ROOT;
42
50
  await (0, fsUtils_1.ensureDir)(root);
43
- await (0, fsUtils_1.atomicWriteJson)(CURRENT_POINTER_PATH, pointer);
51
+ await (0, fsUtils_1.atomicWriteJson)(CURRENT_POINTER_PATH, pointerJson(pointer));
44
52
  }
45
53
  async function writePreviousBundlePointer(pointer) {
54
+ assertCanonicalPointerHash(pointer.hash);
46
55
  const root = context_1.BUNDLE_DROP_ROOT;
47
56
  await (0, fsUtils_1.ensureDir)(root);
48
- await (0, fsUtils_1.atomicWriteJson)(PREVIOUS_POINTER_PATH, pointer);
57
+ await (0, fsUtils_1.atomicWriteJson)(PREVIOUS_POINTER_PATH, pointerJson(pointer));
49
58
  }
50
- async function setCurrentBundlePointer(bundlePath, hash, options) {
59
+ async function restorePreviousBundlePointer(pointer) {
60
+ if (pointer) {
61
+ await writePreviousBundlePointer({ ...pointer, updatedAt: new Date().toISOString() });
62
+ return;
63
+ }
64
+ await deletePreviousBundlePointer();
65
+ }
66
+ async function setCurrentBundlePointer(_bundlePath, hash, options) {
67
+ assertCanonicalPointerHash(hash);
51
68
  const root = context_1.BUNDLE_DROP_ROOT;
52
69
  await (0, fsUtils_1.ensureDir)(root);
53
70
  const current = await readCurrentBundlePointer();
@@ -56,10 +73,21 @@ async function setCurrentBundlePointer(bundlePath, hash, options) {
56
73
  }
57
74
  await writeCurrentBundlePointer({
58
75
  hash,
59
- bundlePath,
76
+ bundlePath: bundlePathForHash(hash),
60
77
  updatedAt: new Date().toISOString(),
61
78
  });
62
79
  }
80
+ function pointerJson(pointer) {
81
+ return {
82
+ hash: pointer.hash,
83
+ updatedAt: pointer.updatedAt,
84
+ };
85
+ }
86
+ function assertCanonicalPointerHash(hash) {
87
+ if (!BUNDLE_HASH_PATTERN.test(hash)) {
88
+ throw new Error('Bundle pointer hash must be a canonical 64-character lowercase SHA-256 hash');
89
+ }
90
+ }
63
91
  async function rollbackToPreviousPointer() {
64
92
  const previous = await readPreviousBundlePointer();
65
93
  if (!previous)
package/lib/fs/fsUtils.js CHANGED
@@ -10,7 +10,10 @@ const fs_1 = __importDefault(require("../native/fs"));
10
10
  async function cleanOrphanedTempZips(bundlesDir) {
11
11
  try {
12
12
  const entries = await fs_1.default.readDir(bundlesDir);
13
- const temps = entries.filter(n => n.startsWith('_tmp_') && n.endsWith('.zip'));
13
+ const temps = entries.filter(n => n.startsWith('_tmp_') ||
14
+ n.startsWith('_patch_') ||
15
+ n.startsWith('_patch_target_') ||
16
+ n.startsWith('_patch_assets_'));
14
17
  await Promise.all(temps.map(name => fs_1.default.unlink(`${bundlesDir}/${name}`)));
15
18
  return temps.length;
16
19
  }