@@ -7,7 +7,9 @@ import { SemverVersioning } from './versioning/SemverVersioning'
7
7
let NativeCodePush = require ( "react-native" ) . NativeModules . CodePush ;
8
8
const PackageMixins = require ( "./package-mixins" ) ( NativeCodePush ) ;
9
9
10
- async function checkForUpdate ( deploymentKey = null , handleBinaryVersionMismatchCallback = null ) {
10
+ const DEPLOYMENT_KEY = 'deprecated_deployment_key' ;
11
+
12
+ async function checkForUpdate ( handleBinaryVersionMismatchCallback = null ) {
11
13
/*
12
14
* Before we ask the server if an update exists, we
13
15
* need to retrieve three pieces of information from the
@@ -18,14 +20,6 @@ async function checkForUpdate(deploymentKey = null, handleBinaryVersionMismatchC
18
20
* different from the CodePush update they have already installed.
19
21
*/
20
22
const nativeConfig = await getConfiguration ( ) ;
21
- /*
22
- * If a deployment key was explicitly provided,
23
- * then let's override the one we retrieved
24
- * from the native-side of the app. This allows
25
- * dynamically "redirecting" end-users at different
26
- * deployments (e.g. an early access deployment for insiders).
27
- */
28
- const config = deploymentKey ? { ...nativeConfig , ...{ deploymentKey } } : nativeConfig ;
29
23
30
24
// Use dynamically overridden getCurrentPackage() during tests.
31
25
const localPackage = await module . exports . getCurrentPackage ( ) ;
@@ -42,22 +36,20 @@ async function checkForUpdate(deploymentKey = null, handleBinaryVersionMismatchC
42
36
if ( localPackage ) {
43
37
queryPackage = localPackage ;
44
38
} else {
45
- queryPackage = { appVersion : config . appVersion } ;
46
- if ( Platform . OS === "ios" && config . packageHash ) {
47
- queryPackage . packageHash = config . packageHash ;
39
+ queryPackage = { appVersion : nativeConfig . appVersion } ;
40
+ if ( Platform . OS === "ios" && nativeConfig . packageHash ) {
41
+ queryPackage . packageHash = nativeConfig . packageHash ;
48
42
}
49
43
}
50
44
51
45
const update = await ( async ( ) => {
52
46
try {
53
- // refer to `UpdateCheckRequest` type inside code-push SDK
54
47
const updateRequest = {
55
- deployment_key : config . deploymentKey ,
56
48
app_version : queryPackage . appVersion ,
57
49
package_hash : queryPackage . packageHash ,
58
- is_companion : config . ignoreAppVersion ,
50
+ is_companion : nativeConfig . ignoreAppVersion ,
59
51
label : queryPackage . label ,
60
- client_unique_id : config . clientUniqueId ,
52
+ client_unique_id : nativeConfig . clientUniqueId ,
61
53
} ;
62
54
63
55
/**
@@ -68,7 +60,7 @@ async function checkForUpdate(deploymentKey = null, handleBinaryVersionMismatchC
68
60
if ( updateChecker ) {
69
61
const { update_info } = await updateChecker ( updateRequest ) ;
70
62
71
- return mapToRemotePackageMetadata ( update_info , config . deploymentKey ) ;
63
+ return mapToRemotePackageMetadata ( update_info ) ;
72
64
} else {
73
65
/**
74
66
* `releaseHistory`
@@ -128,7 +120,7 @@ async function checkForUpdate(deploymentKey = null, handleBinaryVersionMismatchC
128
120
should_run_binary_version : false ,
129
121
}
130
122
131
- return mapToRemotePackageMetadata ( updateInfo , config . deploymentKey ) ;
123
+ return mapToRemotePackageMetadata ( updateInfo ) ;
132
124
}
133
125
} catch ( error ) {
134
126
log ( `An error has occurred at update checker :` ) ;
@@ -158,7 +150,7 @@ async function checkForUpdate(deploymentKey = null, handleBinaryVersionMismatchC
158
150
*/
159
151
if ( ! update || update . updateAppVersion ||
160
152
localPackage && ( update . packageHash === localPackage . packageHash ) ||
161
- ( ! localPackage || localPackage . _isDebugOnly ) && config . packageHash === update . packageHash ) {
153
+ ( ! localPackage || localPackage . _isDebugOnly ) && nativeConfig . packageHash === update . packageHash ) {
162
154
if ( update && update . updateAppVersion ) {
163
155
log ( "An update is available but it is not targeting the binary version of your app." ) ;
164
156
if ( handleBinaryVersionMismatchCallback && typeof handleBinaryVersionMismatchCallback === "function" ) {
@@ -170,17 +162,15 @@ async function checkForUpdate(deploymentKey = null, handleBinaryVersionMismatchC
170
162
} else {
171
163
const remotePackage = { ...update , ...PackageMixins . remote ( ) } ;
172
164
remotePackage . failedInstall = await NativeCodePush . isFailedUpdate ( remotePackage . packageHash ) ;
173
- remotePackage . deploymentKey = deploymentKey || nativeConfig . deploymentKey ;
174
165
return remotePackage ;
175
166
}
176
167
}
177
168
178
169
/**
179
170
* @param updateInfo {UpdateCheckResponse}
180
- * @param deploymentKey {string}
181
171
* @return {RemotePackage | null }
182
172
*/
183
- function mapToRemotePackageMetadata ( updateInfo , deploymentKey ) {
173
+ function mapToRemotePackageMetadata ( updateInfo ) {
184
174
if ( ! updateInfo ) {
185
175
return null ;
186
176
} else if ( ! updateInfo . download_url ) {
@@ -192,7 +182,7 @@ function mapToRemotePackageMetadata(updateInfo, deploymentKey) {
192
182
193
183
// refer to `RemotePackage` type inside code-push SDK
194
184
return {
195
- deploymentKey : deploymentKey ,
185
+ deploymentKey : DEPLOYMENT_KEY ,
196
186
description : updateInfo . description ?? '' ,
197
187
label : updateInfo . label ?? '' ,
198
188
appVersion : updateInfo . target_binary_range ?? '' ,
@@ -253,15 +243,9 @@ async function notifyApplicationReadyInternal() {
253
243
}
254
244
255
245
async function tryReportStatus ( statusReport , retryOnAppResume ) {
256
- const config = await getConfiguration ( ) ;
257
-
258
246
try {
259
247
if ( statusReport . appVersion ) {
260
248
log ( `Reporting binary update (${ statusReport . appVersion } )` ) ;
261
-
262
- if ( ! config . deploymentKey ) {
263
- throw new Error ( "Deployment key is missed" ) ;
264
- }
265
249
} else {
266
250
const label = statusReport . package . label ;
267
251
if ( statusReport . status === "DeploymentSucceeded" ) {
@@ -275,6 +259,7 @@ async function tryReportStatus(statusReport, retryOnAppResume) {
275
259
NativeCodePush . recordStatusReported ( statusReport ) ;
276
260
retryOnAppResume && retryOnAppResume . remove ( ) ;
277
261
} catch ( e ) {
262
+ log ( `${ e } ` )
278
263
log ( `Report status failed: ${ JSON . stringify ( statusReport ) } ` ) ;
279
264
NativeCodePush . saveStatusReportForRetry ( statusReport ) ;
280
265
// Try again when the app resumes
@@ -480,7 +465,7 @@ async function syncInternal(options = {}, syncStatusChangeCallback, downloadProg
480
465
await CodePush . notifyApplicationReady ( ) ;
481
466
482
467
syncStatusChangeCallback ( CodePush . SyncStatus . CHECKING_FOR_UPDATE ) ;
483
- const remotePackage = await checkForUpdate ( syncOptions . deploymentKey , handleBinaryVersionMismatchCallback ) ;
468
+ const remotePackage = await checkForUpdate ( handleBinaryVersionMismatchCallback ) ;
484
469
485
470
const doDownloadAndInstall = async ( ) => {
486
471
syncStatusChangeCallback ( CodePush . SyncStatus . DOWNLOADING_PACKAGE ) ;
0 commit comments