@@ -20,75 +20,75 @@ function checkForUpdate(deploymentKey = null) {
20
20
* different from the CodePush update they have already installed.
21
21
*/
22
22
return getConfiguration ( )
23
- . then ( ( configResult ) => {
24
- /*
25
- * If a deployment key was explicitly provided,
26
- * then let's override the one we retrieved
27
- * from the native-side of the app. This allows
28
- * dynamically "redirecting" end-users at different
29
- * deployments (e.g. an early access deployment for insiders).
30
- */
31
- if ( deploymentKey ) {
32
- config = Object . assign ( { } , configResult , { deploymentKey } ) ;
33
- } else {
34
- config = configResult ;
35
- }
36
-
37
- sdk = getSDK ( config ) ;
38
-
39
- // Allow dynamic overwrite of function. This is only to be used for tests.
40
- return module . exports . getCurrentPackage ( ) ;
41
- } )
42
- . then ( ( localPackage ) => {
43
- var queryPackage = { appVersion : config . appVersion } ;
44
-
45
- /*
46
- * If the app has a previously installed update, and that update
47
- * was targetted at the same app version that is currently running,
48
- * then we want to use its package hash to determine whether a new
49
- * release has been made on the server. Otherwise, we only need
50
- * to send the app version to the server, since we are interested
51
- * in any updates for current app store version, regardless of hash.
52
- */
53
- if ( localPackage && localPackage . appVersion && semver . compare ( localPackage . appVersion , config . appVersion ) === 0 ) {
54
- queryPackage = localPackage ;
55
- }
56
-
57
- return new Promise ( ( resolve , reject ) => {
58
- sdk . queryUpdateWithCurrentPackage ( queryPackage , ( err , update ) => {
59
- if ( err ) {
60
- return reject ( err ) ;
61
- }
62
-
63
- /*
64
- * There are three cases where checkForUpdate will resolve to null:
65
- * ----------------------------------------------------------------
66
- * 1) The server said there isn't an update. This is the most common case.
67
- * 2) The server said there is an update but it requires a newer binary version.
68
- * This would occur when end-users are running an older app store version than
69
- * is available, and CodePush is making sure they don't get an update that
70
- * potentially wouldn't be compatible with what they are running.
71
- * 3) The server said there is an update, but the update's hash is the same as
72
- * the currently running update. This should _never_ happen, unless there is a
73
- * bug in the server, but we're adding this check just to double-check that the
74
- * client app is resilient to a potential issue with the update check.
75
- */
76
- if ( ! update || update . updateAppVersion || ( update . packageHash === localPackage . packageHash ) ) {
77
- return resolve ( null ) ;
78
- }
23
+ . then ( ( configResult ) => {
24
+ /*
25
+ * If a deployment key was explicitly provided,
26
+ * then let's override the one we retrieved
27
+ * from the native-side of the app. This allows
28
+ * dynamically "redirecting" end-users at different
29
+ * deployments (e.g. an early access deployment for insiders).
30
+ */
31
+ if ( deploymentKey ) {
32
+ config = Object . assign ( { } , configResult , { deploymentKey } ) ;
33
+ } else {
34
+ config = configResult ;
35
+ }
36
+
37
+ sdk = new module . exports . AcquisitionSdk ( requestFetchAdapter , config ) ;
38
+
39
+ // Allow dynamic overwrite of function. This is only to be used for tests.
40
+ return module . exports . getCurrentPackage ( ) ;
41
+ } )
42
+ . then ( ( localPackage ) => {
43
+ var queryPackage = { appVersion : config . appVersion } ;
44
+
45
+ /*
46
+ * If the app has a previously installed update, and that update
47
+ * was targetted at the same app version that is currently running,
48
+ * then we want to use its package hash to determine whether a new
49
+ * release has been made on the server. Otherwise, we only need
50
+ * to send the app version to the server, since we are interested
51
+ * in any updates for current app store version, regardless of hash.
52
+ */
53
+ if ( localPackage && localPackage . appVersion && semver . compare ( localPackage . appVersion , config . appVersion ) === 0 ) {
54
+ queryPackage = localPackage ;
55
+ }
56
+
57
+ return new Promise ( ( resolve , reject ) => {
58
+ sdk . queryUpdateWithCurrentPackage ( queryPackage , ( err , update ) => {
59
+ if ( err ) {
60
+ return reject ( err ) ;
61
+ }
62
+
63
+ /*
64
+ * There are three cases where checkForUpdate will resolve to null:
65
+ * ----------------------------------------------------------------
66
+ * 1) The server said there isn't an update. This is the most common case.
67
+ * 2) The server said there is an update but it requires a newer binary version.
68
+ * This would occur when end-users are running an older app store version than
69
+ * is available, and CodePush is making sure they don't get an update that
70
+ * potentially wouldn't be compatible with what they are running.
71
+ * 3) The server said there is an update, but the update's hash is the same as
72
+ * the currently running update. This should _never_ happen, unless there is a
73
+ * bug in the server, but we're adding this check just to double-check that the
74
+ * client app is resilient to a potential issue with the update check.
75
+ */
76
+ if ( ! update || update . updateAppVersion || ( update . packageHash === localPackage . packageHash ) ) {
77
+ return resolve ( null ) ;
78
+ }
79
79
80
- update = Object . assign ( update , PackageMixins . remote ) ;
81
-
82
- NativeCodePush . isFailedUpdate ( update . packageHash )
83
- . then ( ( isFailedHash ) => {
84
- update . failedInstall = isFailedHash ;
85
- resolve ( update ) ;
86
- } )
87
- . catch ( reject )
88
- . done ( ) ;
89
- } )
90
- } ) ;
91
- } ) ;
80
+ update = Object . assign ( update , PackageMixins . remote ) ;
81
+
82
+ NativeCodePush . isFailedUpdate ( update . packageHash )
83
+ . then ( ( isFailedHash ) => {
84
+ update . failedInstall = isFailedHash ;
85
+ resolve ( update ) ;
86
+ } )
87
+ . catch ( reject )
88
+ . done ( ) ;
89
+ } )
90
+ } ) ;
91
+ } ) ;
92
92
}
93
93
94
94
var getConfiguration = ( ( ) => {
@@ -129,30 +129,21 @@ function getCurrentPackage() {
129
129
} ) ;
130
130
}
131
131
132
- function getSDK ( config ) {
133
- if ( testSdk ) {
134
- return testSdk ;
135
- } else {
136
- return new Sdk ( requestFetchAdapter , config ) ;
137
- }
138
- }
139
-
140
132
/* Logs messages to console with the [CodePush] prefix */
141
133
function log ( message ) {
142
134
console . log ( `[CodePush] ${ message } ` )
143
135
}
144
136
145
137
var testConfig ;
146
- var testSdk ;
147
138
148
139
// This function is only used for tests. Replaces the default SDK, configuration and native bridge
149
- function setUpTestDependencies ( providedTestSdk , providedTestConfig , testNativeBridge ) {
150
- if ( providedTestSdk ) testSdk = providedTestSdk ;
140
+ function setUpTestDependencies ( testSdk , providedTestConfig , testNativeBridge ) {
141
+ if ( testSdk ) module . exports . AcquisitionSdk = testSdk ;
151
142
if ( providedTestConfig ) testConfig = providedTestConfig ;
152
143
if ( testNativeBridge ) NativeCodePush = testNativeBridge ;
153
144
}
154
145
155
- /**
146
+ /*
156
147
* The sync method provides a simple, one-line experience for
157
148
* incorporating the check, download and application of an update.
158
149
*
@@ -303,6 +294,7 @@ function sync(options = {}, syncStatusChangeCallback, downloadProgressCallback)
303
294
} ;
304
295
305
296
var CodePush = {
297
+ AcquisitionSdk : Sdk ,
306
298
checkForUpdate : checkForUpdate ,
307
299
getConfiguration : getConfiguration ,
308
300
getCurrentPackage : getCurrentPackage ,
0 commit comments