react-native-update-cli 2.20.2 → 2.20.3

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.
package/lib/package.js CHANGED
@@ -93,7 +93,7 @@ function getVersionBinding(version) {
93
93
  }
94
94
  async function uploadNativePackage(filePath, options, config) {
95
95
  const info = await config.getInfo(filePath);
96
- const { versionName: extractedVersionName, buildTime } = info;
96
+ const { versionName: extractedVersionName, buildTime, bundleHash } = info;
97
97
  const { appId: appIdInPkg, appKey: appKeyInPkg } = info;
98
98
  const selectedApp = options.appId
99
99
  ? {
@@ -128,6 +128,10 @@ async function uploadNativePackage(filePath, options, config) {
128
128
  name: versionName,
129
129
  hash,
130
130
  buildTime: uploadBuildTime,
131
+ // Content identity of the embedded JS bundle; the server matches it
132
+ // against the client-reported bundleHash to decide pdiff applicability.
133
+ // Old servers strip unknown fields, so this is forward-compatible.
134
+ ...(bundleHash ? { bundleHash } : {}),
131
135
  deps: dep_versions_1.depVersions,
132
136
  commit: await (0, git_1.getCommitInfo)(),
133
137
  });
@@ -5,14 +5,17 @@ export declare function translateOptions<T extends Record<string, unknown>>(opti
5
5
  export declare function getApkInfo(fn: string): Promise<{
6
6
  versionName: string;
7
7
  buildTime: number;
8
+ bundleHash: string;
8
9
  }>;
9
10
  export declare function getAppInfo(fn: string): Promise<{
10
11
  versionName: string | undefined;
11
12
  buildTime: number;
13
+ bundleHash: string;
12
14
  }>;
13
15
  export declare function getIpaInfo(fn: string): Promise<{
14
16
  versionName: string;
15
17
  buildTime: string;
18
+ bundleHash: string;
16
19
  }>;
17
20
  export declare function getAabInfo(fn: string): Promise<{
18
21
  versionName: string;
@@ -14,6 +14,7 @@ exports.getAabInfo = getAabInfo;
14
14
  exports.printVersionCommand = printVersionCommand;
15
15
  const chalk_1 = __importDefault(require("chalk"));
16
16
  const compare_versions_1 = require("compare-versions");
17
+ const crypto_1 = require("crypto");
17
18
  const path_1 = __importDefault(require("path"));
18
19
  const read_1 = require("read");
19
20
  const yauzl_1 = require("yauzl");
@@ -71,6 +72,18 @@ function translateOptions(options, map) {
71
72
  }
72
73
  return result;
73
74
  }
75
+ // bundleHash: sha256 of the raw bundle bytes extracted from the package. Must
76
+ // stay byte-identical with what the client hashes at runtime (its embedded
77
+ // bundle, which is also the pdiff source) — the server compares the two to
78
+ // decide pdiff applicability. Raw bytes, no normalization of any kind.
79
+ // getEntries is typed Buffer | Blob (app-info-parser's browser/node duality);
80
+ // under Node it is always a Buffer, but handle both.
81
+ async function sha256(data) {
82
+ const buffer = Buffer.isBuffer(data)
83
+ ? data
84
+ : Buffer.from(await data.arrayBuffer());
85
+ return (0, crypto_1.createHash)('sha256').update(buffer).digest('hex');
86
+ }
74
87
  const ApkBundleFileName = /assets\/index.android.bundle/;
75
88
  const ApkUpdateJsonName = /res\/raw\/update.json/;
76
89
  async function getApkInfo(fn) {
@@ -110,7 +123,12 @@ async function getApkInfo(fn) {
110
123
  if (!Number.isFinite(buildTime) || buildTime === 0) {
111
124
  throw new Error((0, i18n_1.t)('buildTimeNotFound'));
112
125
  }
113
- return { versionName, buildTime, ...appCredential };
126
+ return {
127
+ versionName,
128
+ buildTime,
129
+ bundleHash: await sha256(bundleFile),
130
+ ...appCredential,
131
+ };
114
132
  }
115
133
  async function getAppInfo(fn) {
116
134
  const appInfoParser = new app_info_parser_1.default(fn);
@@ -142,7 +160,12 @@ async function getAppInfo(fn) {
142
160
  if (!Number.isFinite(buildTime) || buildTime === 0) {
143
161
  throw new Error((0, i18n_1.t)('buildTimeNotFound'));
144
162
  }
145
- return { versionName, buildTime, ...appCredential };
163
+ return {
164
+ versionName,
165
+ buildTime,
166
+ bundleHash: await sha256(bundleFile),
167
+ ...appCredential,
168
+ };
146
169
  }
147
170
  const IpaBundleFileName = /payload\/.+?\.app\/main.jsbundle/;
148
171
  const IpaUpdateJsonName = /payload\/.+?\.app\/assets\/update.json/;
@@ -177,7 +200,12 @@ async function getIpaInfo(fn) {
177
200
  throw new Error((0, i18n_1.t)('buildTimeNotFound'));
178
201
  }
179
202
  const buildTime = buildTimeTxtBuffer.toString().trim();
180
- return { versionName, buildTime, ...appCredential };
203
+ return {
204
+ versionName,
205
+ buildTime,
206
+ bundleHash: await sha256(bundleFile),
207
+ ...appCredential,
208
+ };
181
209
  }
182
210
  async function getAabInfo(fn) {
183
211
  const protobuf = require('protobufjs');
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "react-native-update-cli",
3
- "version": "2.20.2",
3
+ "version": "2.20.3",
4
4
  "description": "command line tool for react-native-update (remote updates for react native)",
5
5
  "main": "lib/exports.js",
6
6
  "types": "lib/exports.d.ts",
package/src/package.ts CHANGED
@@ -40,6 +40,8 @@ type PackageVersionRef = {
40
40
  type NativePackageInfo = {
41
41
  versionName?: string | number;
42
42
  buildTime?: string | number;
43
+ /** sha256 of the JS bundle embedded in the package (content identity) */
44
+ bundleHash?: string;
43
45
  appId?: string;
44
46
  appKey?: string;
45
47
  [key: string]: unknown;
@@ -112,7 +114,7 @@ async function uploadNativePackage(
112
114
  config: NativeUploadConfig,
113
115
  ): Promise<void> {
114
116
  const info = await config.getInfo(filePath);
115
- const { versionName: extractedVersionName, buildTime } = info;
117
+ const { versionName: extractedVersionName, buildTime, bundleHash } = info;
116
118
  const { appId: appIdInPkg, appKey: appKeyInPkg } = info;
117
119
  const selectedApp = options.appId
118
120
  ? {
@@ -158,6 +160,10 @@ async function uploadNativePackage(
158
160
  name: versionName,
159
161
  hash,
160
162
  buildTime: uploadBuildTime,
163
+ // Content identity of the embedded JS bundle; the server matches it
164
+ // against the client-reported bundleHash to decide pdiff applicability.
165
+ // Old servers strip unknown fields, so this is forward-compatible.
166
+ ...(bundleHash ? { bundleHash } : {}),
161
167
  deps: depVersions,
162
168
  commit: await getCommitInfo(),
163
169
  });
@@ -1,5 +1,6 @@
1
1
  import chalk from 'chalk';
2
2
  import { satisfies } from 'compare-versions';
3
+ import { createHash } from 'crypto';
3
4
  import path from 'path';
4
5
  import type { Root as ProtobufRoot } from 'protobufjs';
5
6
  import { read } from 'read';
@@ -139,6 +140,19 @@ export function translateOptions<T extends Record<string, unknown>>(
139
140
  return result as T;
140
141
  }
141
142
 
143
+ // bundleHash: sha256 of the raw bundle bytes extracted from the package. Must
144
+ // stay byte-identical with what the client hashes at runtime (its embedded
145
+ // bundle, which is also the pdiff source) — the server compares the two to
146
+ // decide pdiff applicability. Raw bytes, no normalization of any kind.
147
+ // getEntries is typed Buffer | Blob (app-info-parser's browser/node duality);
148
+ // under Node it is always a Buffer, but handle both.
149
+ async function sha256(data: Buffer | Blob): Promise<string> {
150
+ const buffer = Buffer.isBuffer(data)
151
+ ? data
152
+ : Buffer.from(await data.arrayBuffer());
153
+ return createHash('sha256').update(buffer).digest('hex');
154
+ }
155
+
142
156
  const ApkBundleFileName = /assets\/index.android.bundle/;
143
157
  const ApkUpdateJsonName = /res\/raw\/update.json/;
144
158
 
@@ -181,7 +195,12 @@ export async function getApkInfo(fn: string) {
181
195
  if (!Number.isFinite(buildTime) || buildTime === 0) {
182
196
  throw new Error(t('buildTimeNotFound'));
183
197
  }
184
- return { versionName, buildTime, ...appCredential };
198
+ return {
199
+ versionName,
200
+ buildTime,
201
+ bundleHash: await sha256(bundleFile),
202
+ ...appCredential,
203
+ };
185
204
  }
186
205
 
187
206
  export async function getAppInfo(fn: string) {
@@ -217,7 +236,12 @@ export async function getAppInfo(fn: string) {
217
236
  if (!Number.isFinite(buildTime) || buildTime === 0) {
218
237
  throw new Error(t('buildTimeNotFound'));
219
238
  }
220
- return { versionName, buildTime, ...appCredential };
239
+ return {
240
+ versionName,
241
+ buildTime,
242
+ bundleHash: await sha256(bundleFile),
243
+ ...appCredential,
244
+ };
221
245
  }
222
246
 
223
247
  const IpaBundleFileName = /payload\/.+?\.app\/main.jsbundle/;
@@ -259,7 +283,12 @@ export async function getIpaInfo(fn: string) {
259
283
  throw new Error(t('buildTimeNotFound'));
260
284
  }
261
285
  const buildTime = buildTimeTxtBuffer.toString().trim();
262
- return { versionName, buildTime, ...appCredential };
286
+ return {
287
+ versionName,
288
+ buildTime,
289
+ bundleHash: await sha256(bundleFile),
290
+ ...appCredential,
291
+ };
263
292
  }
264
293
 
265
294
  export async function getAabInfo(fn: string) {