Skip to content

Commit 352276b

Browse files
committed
mod: deprecate deployment key
1 parent 3b8b3d6 commit 352276b

File tree

7 files changed

+38
-55
lines changed

7 files changed

+38
-55
lines changed

CodePush.js

+15-30
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,9 @@ import { SemverVersioning } from './versioning/SemverVersioning'
77
let NativeCodePush = require("react-native").NativeModules.CodePush;
88
const 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

255245
async 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);

android/app/src/main/java/com/microsoft/codepush/react/CodePush.java

+13-13
Original file line numberDiff line numberDiff line change
@@ -50,20 +50,20 @@ public class CodePush implements ReactPackage {
5050
private static ReactInstanceHolder mReactInstanceHolder;
5151
private static CodePush mCurrentInstance;
5252

53-
public CodePush(String deploymentKey, Context context) {
54-
this(deploymentKey, context, false);
53+
public CodePush(Context context) {
54+
this(context, false);
5555
}
5656

5757
public static String getServiceUrl() {
5858
return mServerUrl;
5959
}
6060

61-
public CodePush(String deploymentKey, Context context, boolean isDebugMode) {
61+
public CodePush(Context context, boolean isDebugMode) {
6262
mContext = context.getApplicationContext();
6363

6464
mUpdateManager = new CodePushUpdateManager(context.getFilesDir().getAbsolutePath());
6565
mTelemetryManager = new CodePushTelemetryManager(mContext);
66-
mDeploymentKey = deploymentKey;
66+
mDeploymentKey = "deprecated_deployment_key";
6767
mIsDebugMode = isDebugMode;
6868
mSettingsManager = new SettingsManager(mContext);
6969

@@ -88,19 +88,19 @@ public CodePush(String deploymentKey, Context context, boolean isDebugMode) {
8888
initializeUpdateAfterRestart();
8989
}
9090

91-
public CodePush(String deploymentKey, Context context, boolean isDebugMode, String serverUrl) {
92-
this(deploymentKey, context, isDebugMode);
91+
public CodePush(Context context, boolean isDebugMode, String serverUrl) {
92+
this(context, isDebugMode);
9393
mServerUrl = serverUrl;
9494
}
9595

96-
public CodePush(String deploymentKey, Context context, boolean isDebugMode, int publicKeyResourceDescriptor) {
97-
this(deploymentKey, context, isDebugMode);
96+
public CodePush(Context context, boolean isDebugMode, int publicKeyResourceDescriptor) {
97+
this(context, isDebugMode);
9898

9999
mPublicKey = getPublicKeyByResourceDescriptor(publicKeyResourceDescriptor);
100100
}
101101

102-
public CodePush(String deploymentKey, Context context, boolean isDebugMode, String serverUrl, Integer publicKeyResourceDescriptor) {
103-
this(deploymentKey, context, isDebugMode);
102+
public CodePush(Context context, boolean isDebugMode, String serverUrl, Integer publicKeyResourceDescriptor) {
103+
this(context, isDebugMode);
104104

105105
if (publicKeyResourceDescriptor != null) {
106106
mPublicKey = getPublicKeyByResourceDescriptor(publicKeyResourceDescriptor);
@@ -129,18 +129,18 @@ private String getPublicKeyByResourceDescriptor(int publicKeyResourceDescriptor)
129129

130130
private String getCustomPropertyFromStringsIfExist(String propertyName) {
131131
String property;
132-
132+
133133
String packageName = mContext.getPackageName();
134134
int resId = mContext.getResources().getIdentifier("CodePush" + propertyName, "string", packageName);
135-
135+
136136
if (resId != 0) {
137137
property = mContext.getString(resId);
138138

139139
if (!property.isEmpty()) {
140140
return property;
141141
} else {
142142
CodePushUtils.log("Specified " + propertyName + " is empty");
143-
}
143+
}
144144
}
145145

146146
return null;

android/app/src/main/java/com/microsoft/codepush/react/CodePushBuilder.java

+3-3
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,8 @@ public class CodePushBuilder {
1010
private String mServerUrl;
1111
private Integer mPublicKeyResourceDescriptor;
1212

13-
public CodePushBuilder(String deploymentKey, Context context) {
14-
this.mDeploymentKey = deploymentKey;
13+
public CodePushBuilder(Context context) {
14+
this.mDeploymentKey = "deprecated_deployment_key";
1515
this.mContext = context;
1616
this.mServerUrl = CodePush.getServiceUrl();
1717
}
@@ -32,6 +32,6 @@ public CodePushBuilder setPublicKeyResourceDescriptor(int publicKeyResourceDescr
3232
}
3333

3434
public CodePush build() {
35-
return new CodePush(this.mDeploymentKey, this.mContext, this.mIsDebugMode, this.mServerUrl, this.mPublicKeyResourceDescriptor);
35+
return new CodePush(this.mContext, this.mIsDebugMode, this.mServerUrl, this.mPublicKeyResourceDescriptor);
3636
}
3737
}

ios/CodePush/CodePush.m

+5-5
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ @implementation CodePush {
3131
long long _latestExpectedContentLength;
3232
long long _latestReceivedConentLength;
3333
BOOL _didUpdateProgress;
34-
34+
3535
BOOL _allowed;
3636
BOOL _restartInProgress;
3737
NSMutableArray *_restartQueue;
@@ -216,7 +216,7 @@ + (void)overrideAppVersion:(NSString *)appVersion
216216

217217
+ (void)setDeploymentKey:(NSString *)deploymentKey
218218
{
219-
[CodePushConfig current].deploymentKey = deploymentKey;
219+
[CodePushConfig current].deploymentKey = @"deprecated_deployment_key";
220220
}
221221

222222
/*
@@ -376,7 +376,7 @@ - (instancetype)init
376376
_allowed = YES;
377377
_restartInProgress = NO;
378378
_restartQueue = [NSMutableArray arrayWithCapacity:1];
379-
379+
380380
self = [super init];
381381
if (self) {
382382
[self initializeUpdateAfterRestart];
@@ -582,7 +582,7 @@ - (void)saveFailedUpdate:(NSDictionary *)failedPackage
582582
if ([[self class] isFailedHash:[failedPackage objectForKey:PackageHashKey]]) {
583583
return;
584584
}
585-
585+
586586
NSUserDefaults *preferences = [NSUserDefaults standardUserDefaults];
587587
NSMutableArray *failedUpdates = [preferences objectForKey:FailedUpdatesKey];
588588
if (failedUpdates == nil) {
@@ -913,7 +913,7 @@ - (void)restartAppInternal:(BOOL)onlyIfUpdateIsPending
913913
selector:@selector(applicationDidBecomeActive)
914914
name:UIApplicationDidBecomeActiveNotification
915915
object:RCTSharedApplication()];
916-
916+
917917
[[NSNotificationCenter defaultCenter] addObserver:self
918918
selector:@selector(applicationWillEnterForeground)
919919
name:UIApplicationWillEnterForegroundNotification

ios/CodePush/CodePushConfig.m

+1-1
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ - (instancetype)init
3636
NSString *deploymentKey = [infoDictionary objectForKey:@"CodePushDeploymentKey"];
3737
NSString *serverURL = [infoDictionary objectForKey:@"CodePushServerURL"];
3838
NSString *publicKey = [infoDictionary objectForKey:@"CodePushPublicKey"];
39-
39+
4040
NSUserDefaults *userDefaults = [NSUserDefaults standardUserDefaults];
4141
NSString *clientUniqueId = [userDefaults stringForKey:ClientUniqueIDConfigKey];
4242
if (clientUniqueId == nil) {

react-native.config.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ module.exports = {
44
android: {
55
packageImportPath: "import com.microsoft.codepush.react.CodePush;",
66
packageInstance:
7-
"new CodePush(getResources().getString(R.string.CodePushDeploymentKey), getApplicationContext(), BuildConfig.DEBUG)",
7+
"new CodePush(getApplicationContext(), BuildConfig.DEBUG)",
88
sourceDir: './android/app'
99
}
1010
}

typings/react-native-code-push.d.ts

-2
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,10 @@ export type DownloadProgressCallback = (progress: DownloadProgress) => void;
22
export type SyncStatusChangedCallback = (status: CodePush.SyncStatus) => void;
33
export type HandleBinaryVersionMismatchCallback = (update: RemotePackage) => void;
44

5-
// from code-push SDK
65
export interface UpdateCheckRequest {
76
/** The native version, not in package.json. */
87
app_version: string;
98
client_unique_id?: string;
10-
deployment_key: string;
119
is_companion?: boolean;
1210
label?: string;
1311
package_hash?: string;

0 commit comments

Comments
 (0)