@gfean/react-native-bundle-drop 0.5.1 → 0.6.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 (96) hide show
  1. package/README.md +168 -4
  2. package/android/build.gradle +1 -0
  3. package/android/src/main/java/com/bundledrop/BundleDropBoundedDownloader.kt +86 -0
  4. package/android/src/main/java/com/bundledrop/BundleDropModule.kt +69 -0
  5. package/android/src/main/java/com/bundledrop/BundleDropRuntimeCrypto.kt +81 -0
  6. package/ios/BundleDropBridge.m +18 -0
  7. package/ios/BundleDropLocator.swift +48 -2
  8. package/ios/BundleDropModule.swift +75 -0
  9. package/ios/BundleDropRuntimeCrypto.swift +45 -0
  10. package/lib/CLI/cli.d.ts +1 -0
  11. package/lib/CLI/cli.js +54 -2
  12. package/lib/CLI/scripts/aipowered/apply-setup-plan.js +7 -17
  13. package/lib/CLI/scripts/aipowered/backend-client.js +29 -4
  14. package/lib/CLI/scripts/aipowered/code-push-residue.d.ts +5 -0
  15. package/lib/CLI/scripts/aipowered/code-push-residue.js +126 -0
  16. package/lib/CLI/scripts/aipowered/credential-safety.d.ts +1 -0
  17. package/lib/CLI/scripts/aipowered/credential-safety.js +14 -0
  18. package/lib/CLI/scripts/aipowered/diff-preview.js +12 -4
  19. package/lib/CLI/scripts/aipowered/init-project-config.d.ts +4 -0
  20. package/lib/CLI/scripts/aipowered/init-project-config.js +221 -45
  21. package/lib/CLI/scripts/aipowered/scanner.d.ts +1 -0
  22. package/lib/CLI/scripts/aipowered/scanner.js +164 -32
  23. package/lib/CLI/scripts/aipowered/terminal-safety.d.ts +4 -0
  24. package/lib/CLI/scripts/aipowered/terminal-safety.js +124 -0
  25. package/lib/CLI/scripts/aipowered/validate-plan.d.ts +3 -0
  26. package/lib/CLI/scripts/aipowered/validate-plan.js +1080 -19
  27. package/lib/CLI/scripts/bare-metro-config.d.ts +1 -1
  28. package/lib/CLI/scripts/bare-metro-config.js +24 -32
  29. package/lib/CLI/scripts/doctor.js +143 -22
  30. package/lib/CLI/scripts/expo/configure-expo.js +51 -60
  31. package/lib/CLI/scripts/expo/package-manager.d.ts +2 -0
  32. package/lib/CLI/scripts/expo/package-manager.js +63 -25
  33. package/lib/CLI/scripts/init-config.d.ts +7 -7
  34. package/lib/CLI/scripts/init-config.js +185 -10
  35. package/lib/CLI/scripts/login-cli.js +29 -4
  36. package/lib/CLI/scripts/metro-config-authority.d.ts +8 -0
  37. package/lib/CLI/scripts/metro-config-authority.js +303 -0
  38. package/lib/CLI/scripts/native-entrypoint-authority.d.ts +2 -0
  39. package/lib/CLI/scripts/native-entrypoint-authority.js +378 -0
  40. package/lib/CLI/scripts/native-setup-contract.d.ts +2 -2
  41. package/lib/CLI/scripts/native-setup-contract.js +63 -33
  42. package/lib/CLI/scripts/native-startup-validator.d.ts +3 -0
  43. package/lib/CLI/scripts/native-startup-validator.js +964 -0
  44. package/lib/CLI/scripts/safe-file-transaction.d.ts +12 -0
  45. package/lib/CLI/scripts/safe-file-transaction.js +159 -0
  46. package/lib/api/clientApi.d.ts +3 -1
  47. package/lib/api/clientApi.js +14 -0
  48. package/lib/api/types.d.ts +39 -0
  49. package/lib/context.d.ts +1 -1
  50. package/lib/index.d.ts +2 -0
  51. package/lib/index.js +3 -1
  52. package/lib/install/installFromZip.d.ts +3 -0
  53. package/lib/install/installFromZip.js +10 -1
  54. package/lib/loadConfig.d.ts +17 -1
  55. package/lib/loadConfig.js +16 -0
  56. package/lib/manager/downloadAndInstall.d.ts +3 -2
  57. package/lib/manager/downloadAndInstall.js +111 -46
  58. package/lib/manager/rollbackState.d.ts +3 -1
  59. package/lib/manager/rollbackState.js +2 -2
  60. package/lib/manager/updateCheck.d.ts +1 -0
  61. package/lib/manager/updateCheck.js +218 -78
  62. package/lib/metro.d.ts +8 -1
  63. package/lib/metro.js +68 -19
  64. package/lib/native/bundleDropNative.js +2 -1
  65. package/lib/native/fs.d.ts +6 -0
  66. package/lib/native/fs.js +24 -0
  67. package/lib/patch-engine/installFromPatchSet.d.ts +2 -0
  68. package/lib/patch-engine/installFromPatchSet.js +14 -3
  69. package/lib/patch-engine/patchTransport.d.ts +2 -0
  70. package/lib/patch-engine/patchTransport.js +9 -0
  71. package/lib/runtime/initState.d.ts +5 -0
  72. package/lib/runtime/initState.js +4 -0
  73. package/lib/runtime/service.js +60 -3
  74. package/lib/runtime-delivery/artifactCapability.d.ts +1 -0
  75. package/lib/runtime-delivery/artifactCapability.js +32 -0
  76. package/lib/runtime-delivery/authorityLeaseVerifier.d.ts +3 -0
  77. package/lib/runtime-delivery/authorityLeaseVerifier.js +106 -0
  78. package/lib/runtime-delivery/bootstrapConfig.d.ts +50 -0
  79. package/lib/runtime-delivery/bootstrapConfig.js +217 -0
  80. package/lib/runtime-delivery/diagnostics.d.ts +17 -0
  81. package/lib/runtime-delivery/diagnostics.js +58 -0
  82. package/lib/runtime-delivery/encoding.d.ts +5 -0
  83. package/lib/runtime-delivery/encoding.js +132 -0
  84. package/lib/runtime-delivery/heartbeat.d.ts +3 -0
  85. package/lib/runtime-delivery/heartbeat.js +88 -0
  86. package/lib/runtime-delivery/localResolver.d.ts +23 -0
  87. package/lib/runtime-delivery/localResolver.js +81 -0
  88. package/lib/runtime-delivery/manifestState.d.ts +9 -0
  89. package/lib/runtime-delivery/manifestState.js +102 -0
  90. package/lib/runtime-delivery/manifestVerifier.d.ts +13 -0
  91. package/lib/runtime-delivery/manifestVerifier.js +329 -0
  92. package/lib/runtime-delivery/runtimeDelivery.d.ts +19 -0
  93. package/lib/runtime-delivery/runtimeDelivery.js +375 -0
  94. package/lib/runtime-delivery/types.d.ts +87 -0
  95. package/lib/runtime-delivery/types.js +6 -0
  96. package/package.json +2 -2
@@ -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,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;
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/index.d.ts CHANGED
@@ -13,6 +13,8 @@ export type { BundleListItem } from './api/types';
13
13
  export type { BundleDropProjectConfig } from './loadConfig';
14
14
  export type { BundleDropConfig } from './context';
15
15
  export type { BundleDropInitOptions, BundleDropRuntimeConfig } from './runtime/initState';
16
+ export { getRuntimeDeliveryDiagnosticCounters } from './runtime-delivery/diagnostics';
17
+ export type { RuntimeDeliveryDiagnosticCounters, RuntimeDeliveryDiagnosticDetails, RuntimeDeliveryDiagnosticEvent, RuntimeDeliveryDiagnosticName, } from './runtime-delivery/diagnostics';
16
18
  export { useBundleDrop } from './useBundleDrop';
17
19
  export type { UseBundleDropReturn } from './useBundleDrop';
18
20
  export { bundleDropConfig } from './context';
package/lib/index.js CHANGED
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.BundleDrop = exports.bundleDropConfig = exports.useBundleDrop = exports.resetUserProperties = exports.removeUserProperty = exports.setUserProperty = exports.getUserProperties = exports.getCurrentUserProperties = exports.isBundleDropError = exports.BundleDropError = exports.reportHealthy = exports.getChannelName = exports.setChannel = exports.applyUpdate = exports.getUpdateState = exports.installBundle = exports.downloadUpdate = exports.getAvailableBundles = exports.getObservabilityContext = exports.getInstalledBundleInfo = exports.checkForUpdate = exports.getAvailableChannels = void 0;
3
+ exports.BundleDrop = exports.bundleDropConfig = exports.useBundleDrop = exports.getRuntimeDeliveryDiagnosticCounters = exports.resetUserProperties = exports.removeUserProperty = exports.setUserProperty = exports.getUserProperties = exports.getCurrentUserProperties = exports.isBundleDropError = exports.BundleDropError = exports.reportHealthy = exports.getChannelName = exports.setChannel = exports.applyUpdate = exports.getUpdateState = exports.installBundle = exports.downloadUpdate = exports.getAvailableBundles = exports.getObservabilityContext = exports.getInstalledBundleInfo = exports.checkForUpdate = exports.getAvailableChannels = void 0;
4
4
  require("./bootstrap");
5
5
  const service_1 = require("./runtime/service");
6
6
  var service_2 = require("./runtime/service");
@@ -26,6 +26,8 @@ Object.defineProperty(exports, "getUserProperties", { enumerable: true, get: fun
26
26
  Object.defineProperty(exports, "setUserProperty", { enumerable: true, get: function () { return userProperties_1.setUserProperty; } });
27
27
  Object.defineProperty(exports, "removeUserProperty", { enumerable: true, get: function () { return userProperties_1.removeUserProperty; } });
28
28
  Object.defineProperty(exports, "resetUserProperties", { enumerable: true, get: function () { return userProperties_1.resetUserProperties; } });
29
+ var diagnostics_1 = require("./runtime-delivery/diagnostics");
30
+ Object.defineProperty(exports, "getRuntimeDeliveryDiagnosticCounters", { enumerable: true, get: function () { return diagnostics_1.getRuntimeDeliveryDiagnosticCounters; } });
29
31
  var useBundleDrop_1 = require("./useBundleDrop");
30
32
  Object.defineProperty(exports, "useBundleDrop", { enumerable: true, get: function () { return useBundleDrop_1.useBundleDrop; } });
31
33
  var context_1 = require("./context");
@@ -4,6 +4,9 @@ type InstallFromZipParams = {
4
4
  hash?: string;
5
5
  platform?: 'ios' | 'android';
6
6
  statusCb?: (status: string) => void;
7
+ expectedArchiveHash?: string;
8
+ expectedManifestHash?: string;
9
+ expectedJsBundleHash?: string;
7
10
  };
8
11
  export declare function installFromZip(params: InstallFromZipParams): Promise<InstallResult>;
9
12
  export {};
@@ -12,7 +12,7 @@ const bundleManifest_1 = require("../manifest/bundleManifest");
12
12
  const bundleVerification_1 = require("./bundleVerification");
13
13
  const bundleInstallShared_1 = require("./bundleInstallShared");
14
14
  async function installFromZip(params) {
15
- const { downloadUrl, hash, statusCb, platform = context_1.platform } = params;
15
+ const { downloadUrl, hash, statusCb, platform = context_1.platform, expectedArchiveHash, expectedManifestHash, expectedJsBundleHash, } = params;
16
16
  if (!hash) {
17
17
  throw new Error('Missing bundle hash');
18
18
  }
@@ -33,6 +33,9 @@ async function installFromZip(params) {
33
33
  catch (e) {
34
34
  throw new errors_1.InstallPhaseError('download', e);
35
35
  }
36
+ if (expectedArchiveHash && (await fs_1.default.sha256File(tempZipPath)) !== expectedArchiveHash) {
37
+ throw new errors_1.InstallPhaseError('install', new Error('Full bundle archive hash mismatch'));
38
+ }
36
39
  try {
37
40
  fileNames = await fs_1.default.unzip(tempZipPath, tempDir);
38
41
  }
@@ -47,6 +50,12 @@ async function installFromZip(params) {
47
50
  if (!manifest) {
48
51
  throw new Error('Bundle manifest is missing');
49
52
  }
53
+ if (expectedManifestHash && manifest.manifestHash !== expectedManifestHash) {
54
+ throw new Error('Signed manifest hash does not match downloaded bundle manifest');
55
+ }
56
+ if (expectedJsBundleHash && manifest.jsBundleHash !== expectedJsBundleHash) {
57
+ throw new Error('Signed JavaScript bundle hash does not match downloaded bundle manifest');
58
+ }
50
59
  verifiedHash = manifest.bundleHash;
51
60
  }
52
61
  catch (e) {
@@ -1,6 +1,18 @@
1
1
  /**
2
2
  * Shape of `bundle.drop.config.js` after it is loaded through Metro.
3
3
  */
4
+ export type RuntimeDeliveryConfig = {
5
+ manifestBaseUrl: string;
6
+ manifestAccessId: string;
7
+ publicKeys: Record<string, {
8
+ kty: 'EC';
9
+ crv: 'P-256';
10
+ x: string;
11
+ y: string;
12
+ }>;
13
+ };
14
+ /** Returns true only for a complete package-managed trust configuration. */
15
+ export declare function isRuntimeDeliveryConfigured(value: unknown): value is RuntimeDeliveryConfig;
4
16
  export type BundleDropProjectConfig = {
5
17
  /** Persisted project shape used to keep Expo and bare runtime behavior distinct. */
6
18
  projectType?: 'expo' | 'bare';
@@ -51,4 +63,8 @@ export type BundleDropProjectConfig = {
51
63
  healthyAfterSec?: number;
52
64
  };
53
65
  };
54
- export declare function loadConfig(): BundleDropProjectConfig;
66
+ /** Internal Metro-resolved config. Generated trust data is deliberately absent from the public type. */
67
+ export type ResolvedBundleDropProjectConfig = BundleDropProjectConfig & {
68
+ runtimeDelivery?: RuntimeDeliveryConfig;
69
+ };
70
+ export declare function loadConfig(): ResolvedBundleDropProjectConfig;
package/lib/loadConfig.js CHANGED
@@ -1,6 +1,22 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.isRuntimeDeliveryConfigured = isRuntimeDeliveryConfigured;
3
4
  exports.loadConfig = loadConfig;
5
+ /** Returns true only for a complete package-managed trust configuration. */
6
+ function isRuntimeDeliveryConfigured(value) {
7
+ if (!value || typeof value !== 'object' || Array.isArray(value))
8
+ return false;
9
+ const candidate = value;
10
+ if (candidate.mode === 'v1' || candidate.mode === 'shadow')
11
+ return false;
12
+ return (typeof candidate.manifestBaseUrl === 'string' &&
13
+ Boolean(candidate.manifestBaseUrl) &&
14
+ typeof candidate.manifestAccessId === 'string' &&
15
+ Boolean(candidate.manifestAccessId) &&
16
+ Boolean(candidate.publicKeys) &&
17
+ typeof candidate.publicKeys === 'object' &&
18
+ !Array.isArray(candidate.publicKeys));
19
+ }
4
20
  function loadConfig() {
5
21
  try {
6
22
  // ✅ Resolved via Metro alias in the host app (extraNodeModules)
@@ -1,4 +1,4 @@
1
- import type { OtaPatchSet } from '../api/types';
1
+ import type { OtaPatchSet, UpdateCheckResponse } from '../api/types';
2
2
  export type DownloadUpdateResult = {
3
3
  status: 'staged';
4
4
  bundlePath: string;
@@ -20,7 +20,7 @@ type DownloadOptions = {
20
20
  channelName?: string;
21
21
  resolvedTarget?: {
22
22
  hash: string;
23
- downloadUrl: string;
23
+ downloadUrl?: string;
24
24
  bundleVersion?: number;
25
25
  version?: string;
26
26
  runtimeVersion?: string;
@@ -32,6 +32,7 @@ type DownloadOptions = {
32
32
  mode: 'full';
33
33
  downloadUrl: string;
34
34
  };
35
+ runtimeDelivery?: UpdateCheckResponse['runtimeDelivery'];
35
36
  };
36
37
  };
37
38
  export declare const downloadUpdate: (options?: DownloadOptions, onStatusUpdate?: (status: string) => void) => Promise<DownloadUpdateResult>;
@@ -10,6 +10,7 @@ const bundleDropNative_1 = require("../native/bundleDropNative");
10
10
  const updateCheck_1 = require("./updateCheck");
11
11
  const errors_1 = require("../errors");
12
12
  const rollbackState_1 = require("./rollbackState");
13
+ const artifactCapability_1 = require("../runtime-delivery/artifactCapability");
13
14
  async function restoreCurrentPointer(pointer) {
14
15
  if (pointer) {
15
16
  await (0, bundlePointer_1.writeCurrentBundlePointer)({ ...pointer, updatedAt: new Date().toISOString() });
@@ -17,6 +18,29 @@ async function restoreCurrentPointer(pointer) {
17
18
  }
18
19
  await (0, bundlePointer_1.deleteCurrentBundlePointer)();
19
20
  }
21
+ function isSameRuntimeDeliverySelection(selected, refreshed) {
22
+ if (!refreshed ||
23
+ refreshed.action !== 'INSTALL' ||
24
+ refreshed.hash !== selected.hash ||
25
+ refreshed.runtimeVersion !== selected.runtimeVersion ||
26
+ !selected.runtimeDelivery ||
27
+ !refreshed.runtimeDelivery) {
28
+ return false;
29
+ }
30
+ const before = selected.runtimeDelivery;
31
+ const after = refreshed.runtimeDelivery;
32
+ return before.generation === after.generation &&
33
+ before.targetReleaseRef === after.targetReleaseRef &&
34
+ before.selectedMode === after.selectedMode &&
35
+ (before.baseHash ?? null) === (after.baseHash ?? null) &&
36
+ (before.patchAlgorithm ?? null) === (after.patchAlgorithm ?? null) &&
37
+ (before.patchSetHash ?? null) === (after.patchSetHash ?? null) &&
38
+ (before.patchArtifactRef ?? null) === (after.patchArtifactRef ?? null) &&
39
+ (before.missingAssetsHash ?? null) === (after.missingAssetsHash ?? null) &&
40
+ (before.manifestHash ?? null) === (after.manifestHash ?? null) &&
41
+ (before.jsBundleHash ?? null) === (after.jsBundleHash ?? null) &&
42
+ (before.fullBundleHash ?? null) === (after.fullBundleHash ?? null);
43
+ }
20
44
  async function downloadAndStageUpdate(options, onStatusUpdate) {
21
45
  const { project } = context_1.config;
22
46
  const channelName = options?.channelName || context_1.defaultChannel;
@@ -24,9 +48,10 @@ async function downloadAndStageUpdate(options, onStatusUpdate) {
24
48
  const statusCb = onStatusUpdate;
25
49
  const resolvedTarget = options?.resolvedTarget;
26
50
  // Resolve target via /ota/resolve unless the caller already provided it.
27
- const checkResult = resolvedTarget
51
+ const unresolvedCheckResult = resolvedTarget
28
52
  ? {
29
53
  action: 'INSTALL',
54
+ channelName,
30
55
  hash: resolvedTarget.hash,
31
56
  bundleHash: resolvedTarget.hash,
32
57
  downloadUrl: resolvedTarget.downloadUrl,
@@ -38,8 +63,12 @@ async function downloadAndStageUpdate(options, onStatusUpdate) {
38
63
  baseHash: resolvedTarget.baseHash,
39
64
  patchSet: resolvedTarget.patchSet,
40
65
  fallback: resolvedTarget.fallback,
66
+ runtimeDelivery: resolvedTarget.runtimeDelivery,
41
67
  }
42
68
  : await (0, updateCheck_1.checkForUpdate)(channelName, statusCb);
69
+ let checkResult = unresolvedCheckResult
70
+ ? await (0, updateCheck_1.authorizeRuntimeDeliveryUpdate)(unresolvedCheckResult)
71
+ : null;
43
72
  if (!checkResult) {
44
73
  throw new errors_1.BundleDropError({
45
74
  message: 'Failed to resolve update decision',
@@ -73,9 +102,6 @@ async function downloadAndStageUpdate(options, onStatusUpdate) {
73
102
  const serverBundleVersion = checkResult.bundleVersion;
74
103
  const serverVersion = checkResult.version;
75
104
  const serverRuntimeVersion = checkResult.runtimeVersion;
76
- const fullBundleZipUrl = checkResult.mode === 'patch'
77
- ? checkResult.fallback?.downloadUrl || null
78
- : checkResult.downloadUrl || null;
79
105
  try {
80
106
  if (!serverHash) {
81
107
  throw new errors_1.BundleDropError({
@@ -85,18 +111,6 @@ async function downloadAndStageUpdate(options, onStatusUpdate) {
85
111
  context: { channelName, platform, projectSlug: project.slug },
86
112
  });
87
113
  }
88
- if (!fullBundleZipUrl) {
89
- throw new errors_1.BundleDropError({
90
- message: 'Missing downloadUrl from ota resolve response',
91
- code: 'DOWNLOAD_URL_MISSING',
92
- step: 'resolve',
93
- context: {
94
- channelName,
95
- platform,
96
- projectSlug: project.slug,
97
- },
98
- });
99
- }
100
114
  const hash = serverHash;
101
115
  if (await (0, rollbackState_1.isBundleHashFailed)(hash)) {
102
116
  statusCb?.('✅ Current bundle retained; selected update previously failed on this device');
@@ -107,40 +121,91 @@ async function downloadAndStageUpdate(options, onStatusUpdate) {
107
121
  skippedHash: hash,
108
122
  };
109
123
  }
110
- let installResult = await (0, patchTransport_1.tryInstallPatchTransport)({
111
- target: {
112
- mode: checkResult.mode,
113
- hash,
114
- manifestUrl: checkResult.manifestUrl,
115
- baseHash: checkResult.baseHash,
116
- patchSet: checkResult.patchSet,
117
- },
118
- projectSlug: project.slug,
119
- platform,
120
- runtimeVersionValue: serverRuntimeVersion,
121
- statusCb,
122
- });
123
- try {
124
- if (!installResult) {
125
- statusCb?.('⬇️ Downloading full bundle ZIP!...');
126
- installResult = await (0, installFromZip_1.installFromZip)({
127
- downloadUrl: fullBundleZipUrl,
128
- hash,
124
+ let installResult;
125
+ let capabilityRefreshAttempted = false;
126
+ let patchFallbackSelected = false;
127
+ while (true) {
128
+ const fullBundleZipUrl = checkResult.mode === 'patch'
129
+ ? checkResult.fallback?.downloadUrl || null
130
+ : checkResult.downloadUrl || null;
131
+ if (!fullBundleZipUrl) {
132
+ throw new errors_1.BundleDropError({
133
+ message: 'Missing downloadUrl from ota resolve response',
134
+ code: 'DOWNLOAD_URL_MISSING',
135
+ step: 'resolve',
136
+ context: { channelName, platform, projectSlug: project.slug },
137
+ });
138
+ }
139
+ try {
140
+ installResult = patchFallbackSelected ? null : await (0, patchTransport_1.tryInstallPatchTransport)({
141
+ target: {
142
+ mode: checkResult.mode,
143
+ hash,
144
+ manifestUrl: checkResult.manifestUrl,
145
+ baseHash: checkResult.baseHash,
146
+ patchSet: checkResult.patchSet,
147
+ ...(checkResult.runtimeDelivery?.manifestHash
148
+ ? { expectedManifestHash: checkResult.runtimeDelivery.manifestHash }
149
+ : {}),
150
+ ...(checkResult.runtimeDelivery?.jsBundleHash
151
+ ? { expectedJsBundleHash: checkResult.runtimeDelivery.jsBundleHash }
152
+ : {}),
153
+ },
154
+ projectSlug: project.slug,
129
155
  platform,
156
+ runtimeVersionValue: serverRuntimeVersion,
130
157
  statusCb,
131
158
  });
159
+ if (!installResult) {
160
+ patchFallbackSelected = checkResult.mode === 'patch';
161
+ statusCb?.('⬇️ Downloading full bundle ZIP!...');
162
+ installResult = await (0, installFromZip_1.installFromZip)({
163
+ downloadUrl: fullBundleZipUrl,
164
+ hash,
165
+ platform,
166
+ statusCb,
167
+ ...(checkResult.runtimeDelivery?.fullBundleHash
168
+ ? { expectedArchiveHash: checkResult.runtimeDelivery.fullBundleHash }
169
+ : {}),
170
+ ...(checkResult.runtimeDelivery?.manifestHash
171
+ ? { expectedManifestHash: checkResult.runtimeDelivery.manifestHash }
172
+ : {}),
173
+ ...(checkResult.runtimeDelivery?.jsBundleHash
174
+ ? { expectedJsBundleHash: checkResult.runtimeDelivery.jsBundleHash }
175
+ : {}),
176
+ });
177
+ }
178
+ break;
179
+ }
180
+ catch (e) {
181
+ if (!capabilityRefreshAttempted &&
182
+ unresolvedCheckResult.runtimeDelivery &&
183
+ (0, artifactCapability_1.isArtifactCapabilityRejected)(e)) {
184
+ capabilityRefreshAttempted = true;
185
+ statusCb?.('🔐 Download authorization expired; refreshing once...');
186
+ const refreshed = await (0, updateCheck_1.authorizeRuntimeDeliveryUpdate)(unresolvedCheckResult);
187
+ if (!isSameRuntimeDeliverySelection(unresolvedCheckResult, refreshed)) {
188
+ throw new errors_1.BundleDropError({
189
+ message: 'Refreshed download authorization changed update identity',
190
+ code: 'DOWNLOAD_FAILED',
191
+ step: 'download',
192
+ context: { channelName, platform, hash },
193
+ cause: e,
194
+ });
195
+ }
196
+ checkResult = refreshed;
197
+ continue;
198
+ }
199
+ const phaseErr = (0, errors_1.isInstallPhaseError)(e);
200
+ const isDownload = phaseErr && e.phase === 'download';
201
+ throw new errors_1.BundleDropError({
202
+ message: isDownload ? 'Failed to download update ZIP' : 'Failed to install update ZIP',
203
+ code: isDownload ? 'DOWNLOAD_FAILED' : 'INSTALL_FAILED',
204
+ step: isDownload ? 'download' : 'install',
205
+ context: { channelName, platform, hash },
206
+ cause: phaseErr ? e.originalCause : e,
207
+ });
132
208
  }
133
- }
134
- catch (e) {
135
- const phaseErr = (0, errors_1.isInstallPhaseError)(e);
136
- const isDownload = phaseErr && e.phase === 'download';
137
- throw new errors_1.BundleDropError({
138
- message: isDownload ? 'Failed to download update ZIP' : 'Failed to install update ZIP',
139
- code: isDownload ? 'DOWNLOAD_FAILED' : 'INSTALL_FAILED',
140
- step: isDownload ? 'download' : 'install',
141
- context: { channelName, platform, hash },
142
- cause: phaseErr ? e.originalCause : e,
143
- });
144
209
  }
145
210
  const { bundlePath, metadataFromZip } = installResult;
146
211
  const installedHash = hash;
@@ -52,7 +52,9 @@ export declare function rollbackToPreviousIfNeeded(policy: Required<RollbackPoli
52
52
  reason?: FailedBundleReason;
53
53
  }>;
54
54
  export declare function getRollbackPolicy(): Required<RollbackPolicy>;
55
- export declare function rollbackToPreviousOrNative(): Promise<{
55
+ export declare function rollbackToPreviousOrNative(options?: {
56
+ forceNative?: boolean;
57
+ }): Promise<{
56
58
  rolledBack: boolean;
57
59
  toNative?: boolean;
58
60
  }>;