@@ -7,7 +7,9 @@ import { SemverVersioning } from './versioning/SemverVersioning'
77let NativeCodePush = require ( "react-native" ) . NativeModules . CodePush ;
88const PackageMixins = require ( "./package-mixins" ) ( NativeCodePush ) ;
99
10- async function checkForUpdate ( deploymentKey = null , handleBinaryVersionMismatchCallback = null ) {
10+ const DEPLOYMENT_KEY = 'deprecated_deployment_key' ;
11+
12+ async function checkForUpdate ( handleBinaryVersionMismatchCallback = null ) {
1113 /*
1214 * Before we ask the server if an update exists, we
1315 * need to retrieve three pieces of information from the
@@ -18,14 +20,6 @@ async function checkForUpdate(deploymentKey = null, handleBinaryVersionMismatchC
1820 * different from the CodePush update they have already installed.
1921 */
2022 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 ;
2923
3024 // Use dynamically overridden getCurrentPackage() during tests.
3125 const localPackage = await module . exports . getCurrentPackage ( ) ;
@@ -42,22 +36,20 @@ async function checkForUpdate(deploymentKey = null, handleBinaryVersionMismatchC
4236 if ( localPackage ) {
4337 queryPackage = localPackage ;
4438 } 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 ;
4842 }
4943 }
5044
5145 const update = await ( async ( ) => {
5246 try {
53- // refer to `UpdateCheckRequest` type inside code-push SDK
5447 const updateRequest = {
55- deployment_key : config . deploymentKey ,
5648 app_version : queryPackage . appVersion ,
5749 package_hash : queryPackage . packageHash ,
58- is_companion : config . ignoreAppVersion ,
50+ is_companion : nativeConfig . ignoreAppVersion ,
5951 label : queryPackage . label ,
60- client_unique_id : config . clientUniqueId ,
52+ client_unique_id : nativeConfig . clientUniqueId ,
6153 } ;
6254
6355 /**
@@ -68,7 +60,7 @@ async function checkForUpdate(deploymentKey = null, handleBinaryVersionMismatchC
6860 if ( updateChecker ) {
6961 const { update_info } = await updateChecker ( updateRequest ) ;
7062
71- return mapToRemotePackageMetadata ( update_info , config . deploymentKey ) ;
63+ return mapToRemotePackageMetadata ( update_info ) ;
7264 } else {
7365 /**
7466 * `releaseHistory`
@@ -128,7 +120,7 @@ async function checkForUpdate(deploymentKey = null, handleBinaryVersionMismatchC
128120 should_run_binary_version : false ,
129121 }
130122
131- return mapToRemotePackageMetadata ( updateInfo , config . deploymentKey ) ;
123+ return mapToRemotePackageMetadata ( updateInfo ) ;
132124 }
133125 } catch ( error ) {
134126 log ( `An error has occurred at update checker :` ) ;
@@ -158,7 +150,7 @@ async function checkForUpdate(deploymentKey = null, handleBinaryVersionMismatchC
158150 */
159151 if ( ! update || update . updateAppVersion ||
160152 localPackage && ( update . packageHash === localPackage . packageHash ) ||
161- ( ! localPackage || localPackage . _isDebugOnly ) && config . packageHash === update . packageHash ) {
153+ ( ! localPackage || localPackage . _isDebugOnly ) && nativeConfig . packageHash === update . packageHash ) {
162154 if ( update && update . updateAppVersion ) {
163155 log ( "An update is available but it is not targeting the binary version of your app." ) ;
164156 if ( handleBinaryVersionMismatchCallback && typeof handleBinaryVersionMismatchCallback === "function" ) {
@@ -170,17 +162,15 @@ async function checkForUpdate(deploymentKey = null, handleBinaryVersionMismatchC
170162 } else {
171163 const remotePackage = { ...update , ...PackageMixins . remote ( ) } ;
172164 remotePackage . failedInstall = await NativeCodePush . isFailedUpdate ( remotePackage . packageHash ) ;
173- remotePackage . deploymentKey = deploymentKey || nativeConfig . deploymentKey ;
174165 return remotePackage ;
175166 }
176167}
177168
178169/**
179170 * @param updateInfo {UpdateCheckResponse}
180- * @param deploymentKey {string}
181171 * @return {RemotePackage | null }
182172 */
183- function mapToRemotePackageMetadata ( updateInfo , deploymentKey ) {
173+ function mapToRemotePackageMetadata ( updateInfo ) {
184174 if ( ! updateInfo ) {
185175 return null ;
186176 } else if ( ! updateInfo . download_url ) {
@@ -192,7 +182,7 @@ function mapToRemotePackageMetadata(updateInfo, deploymentKey) {
192182
193183 // refer to `RemotePackage` type inside code-push SDK
194184 return {
195- deploymentKey : deploymentKey ,
185+ deploymentKey : DEPLOYMENT_KEY ,
196186 description : updateInfo . description ?? '' ,
197187 label : updateInfo . label ?? '' ,
198188 appVersion : updateInfo . target_binary_range ?? '' ,
@@ -253,15 +243,9 @@ async function notifyApplicationReadyInternal() {
253243}
254244
255245async function tryReportStatus ( statusReport , retryOnAppResume ) {
256- const config = await getConfiguration ( ) ;
257-
258246 try {
259247 if ( statusReport . appVersion ) {
260248 log ( `Reporting binary update (${ statusReport . appVersion } )` ) ;
261-
262- if ( ! config . deploymentKey ) {
263- throw new Error ( "Deployment key is missed" ) ;
264- }
265249 } else {
266250 const label = statusReport . package . label ;
267251 if ( statusReport . status === "DeploymentSucceeded" ) {
@@ -275,6 +259,7 @@ async function tryReportStatus(statusReport, retryOnAppResume) {
275259 NativeCodePush . recordStatusReported ( statusReport ) ;
276260 retryOnAppResume && retryOnAppResume . remove ( ) ;
277261 } catch ( e ) {
262+ log ( `${ e } ` )
278263 log ( `Report status failed: ${ JSON . stringify ( statusReport ) } ` ) ;
279264 NativeCodePush . saveStatusReportForRetry ( statusReport ) ;
280265 // Try again when the app resumes
@@ -480,7 +465,7 @@ async function syncInternal(options = {}, syncStatusChangeCallback, downloadProg
480465 await CodePush . notifyApplicationReady ( ) ;
481466
482467 syncStatusChangeCallback ( CodePush . SyncStatus . CHECKING_FOR_UPDATE ) ;
483- const remotePackage = await checkForUpdate ( syncOptions . deploymentKey , handleBinaryVersionMismatchCallback ) ;
468+ const remotePackage = await checkForUpdate ( handleBinaryVersionMismatchCallback ) ;
484469
485470 const doDownloadAndInstall = async ( ) => {
486471 syncStatusChangeCallback ( CodePush . SyncStatus . DOWNLOADING_PACKAGE ) ;
0 commit comments