1
- // EVRYTHNG JS SDK v3.4.1
1
+ // EVRYTHNG JS SDK v3.4.2
2
2
// (c) 2012-2015 EVRYTHNG Ltd. London / New York / San Francisco.
3
3
// Released under the Apache Software License, Version 2.0.
4
4
// For all details and usage:
@@ -990,7 +990,7 @@ define('core',[
990
990
'use strict' ;
991
991
992
992
// Version is updated from package.json using `grunt-version` on build.
993
- var version = '3.4.1 ' ;
993
+ var version = '3.4.2 ' ;
994
994
995
995
996
996
// Setup default settings:
@@ -1090,24 +1090,30 @@ define('core',[
1090
1090
// that prefixes EvrythngJS's logs with a custom header.**
1091
1091
1092
1092
define ( 'logger' , [
1093
- 'core' ] ,
1094
- function ( EVT ) {
1093
+ 'core'
1094
+ ] , function ( EVT ) {
1095
1095
'use strict' ;
1096
1096
1097
1097
var header = 'EvrythngJS' ;
1098
1098
1099
1099
return {
1100
1100
1101
- error : function ( data ) {
1102
- if ( EVT . settings . quiet === false ) {
1101
+ error : function ( data ) {
1102
+ if ( EVT . settings . quiet === false ) {
1103
1103
console . error ( header + ' Error:' , data ) ;
1104
1104
}
1105
1105
} ,
1106
1106
1107
- info : function ( data ) {
1108
- if ( EVT . settings . quiet === false ) {
1107
+ info : function ( data ) {
1108
+ if ( EVT . settings . quiet === false ) {
1109
1109
console . info ( header + ' Info:' , data ) ;
1110
1110
}
1111
+ } ,
1112
+
1113
+ // TODO remove when callbacks deprecated
1114
+ warnCallbackDeprecation : function ( ) {
1115
+ console . warn ( header + ' Warning: Callbacks are deprecated, and are scheduled to be ' +
1116
+ 'removed in the next major release of the library. Please, use the Promise API instead.' ) ;
1111
1117
}
1112
1118
1113
1119
} ;
@@ -1141,10 +1147,10 @@ define('network/cors',[
1141
1147
// return *null*.
1142
1148
function _buildResponse ( xhr , fullResponse ) {
1143
1149
// XMLHttpRequest returns a not very usable single big string with all headers
1144
- var _parseHeaders = function ( headers ) {
1150
+ var _parseHeaders = function ( headers ) {
1145
1151
var parsed = { } ;
1146
1152
1147
- if ( headers ) {
1153
+ if ( headers ) {
1148
1154
headers = headers . trim ( ) . split ( "\n" ) ;
1149
1155
for ( var h in headers ) {
1150
1156
var header = headers [ h ] . toLowerCase ( ) . match ( / ( [ ^ : ] + ) : ( .* ) / ) ;
@@ -1188,23 +1194,13 @@ define('network/cors',[
1188
1194
return response ;
1189
1195
}
1190
1196
1191
- // Helper method that builds a custom Error object providing some extra
1192
- // information on a request error.
1197
+ // Forward EVRYTHNG API error and extend with URL and Method.
1193
1198
function _buildError ( xhr , url , method , response ) {
1194
- var errorData = {
1195
- status : xhr . status ,
1196
- type : 'cors' ,
1197
- message : 'Server responded with an error for the CORS request' ,
1198
- url : url ,
1199
- method : method
1200
- } ;
1199
+ var errorData = response || { } ;
1201
1200
1202
- // Evrythng's API return an array of errors in the response. Add them
1203
- // if available.
1204
- if ( response ) {
1205
- errorData . errors = response . errors ;
1206
- errorData . moreInfo = response . moreInfo ;
1207
- }
1201
+ errorData . status = xhr . status ;
1202
+ errorData . url = url ;
1203
+ errorData . method = method ;
1208
1204
1209
1205
return errorData ;
1210
1206
}
@@ -1217,8 +1213,8 @@ define('network/cors',[
1217
1213
xhr . open ( method , url ) ;
1218
1214
1219
1215
// Setup headers, including the *Authorization* that holds the Api Key.
1220
- for ( var header in options . headers ) {
1221
- if ( options . headers . hasOwnProperty ( header ) ) {
1216
+ for ( var header in options . headers ) {
1217
+ if ( options . headers . hasOwnProperty ( header ) ) {
1222
1218
xhr . setRequestHeader ( header , options . headers [ header ] ) ;
1223
1219
}
1224
1220
}
@@ -1252,36 +1248,20 @@ define('network/cors',[
1252
1248
// are callbacks execute them as well before resolving the promise.
1253
1249
return new Promise ( function ( resolve , reject ) {
1254
1250
1255
- // Set protocol error handler.
1256
- xhr . onerror = function ( ) {
1257
- // Could not execute request at all (destination unreachable, offline, ...?)
1258
- var ex = new Error ( 'Network error.' ) ;
1259
- ex . name = 'CorsError' ;
1260
- reject ( ex ) ;
1261
- } ;
1262
-
1263
1251
// Define internal error handler.
1264
- var errorHandler = function ( response ) {
1252
+ function errorHandler ( response ) {
1265
1253
if ( response ) {
1266
1254
var errorData = _buildError ( xhr , url , method , response ) ;
1267
1255
Logger . error ( errorData ) ;
1268
1256
1269
1257
if ( errorCallback ) {
1258
+ Logger . warnCallbackDeprecation ( ) ;
1270
1259
errorCallback ( errorData ) ;
1271
1260
}
1272
1261
reject ( errorData ) ;
1273
1262
}
1274
- } ;
1275
-
1276
- // Set timeout handler if needed.
1277
- if ( options . timeout > 0 ) {
1278
- xhr . ontimeout = function ( ) {
1279
- var timeoutResponse = { errors : [ 'Request timed out.' ] } ;
1280
- errorHandler ( timeoutResponse ) ;
1281
- } ;
1282
1263
}
1283
1264
1284
-
1285
1265
// Define the response handler.
1286
1266
function handler ( ) {
1287
1267
try {
@@ -1294,6 +1274,7 @@ define('network/cors',[
1294
1274
if ( this . status >= 200 && this . status < 300 ) {
1295
1275
1296
1276
if ( successCallback ) {
1277
+ Logger . warnCallbackDeprecation ( ) ;
1297
1278
successCallback ( response ) ;
1298
1279
}
1299
1280
resolve ( response ) ;
@@ -1307,11 +1288,24 @@ define('network/cors',[
1307
1288
}
1308
1289
}
1309
1290
1291
+ // Set timeout handler if needed.
1292
+ if ( options . timeout > 0 ) {
1293
+ xhr . ontimeout = function ( ) {
1294
+ var timeoutErrResponse = { errors : [ 'Request timed out.' ] } ;
1295
+ errorHandler ( timeoutErrResponse ) ;
1296
+ } ;
1297
+ }
1298
+
1299
+ // Could not execute request at all (destination unreachable, offline, ...?)
1300
+ xhr . onerror = function ( ) {
1301
+ var networkErrResponse = { errors : [ 'Network error.' ] } ;
1302
+ errorHandler ( networkErrResponse ) ;
1303
+ } ;
1304
+
1310
1305
// Send the request and wait for the response in the handler.
1311
1306
xhr . onreadystatechange = handler ;
1312
1307
1313
1308
xhr . send ( data ) ;
1314
-
1315
1309
} ) ;
1316
1310
}
1317
1311
@@ -1338,21 +1332,13 @@ define('network/jsonp',[
1338
1332
// Counter defines uniquely identified callbacks.
1339
1333
var counter = 0 , head ;
1340
1334
1341
- // Helper method that builds a custom Error object providing some extra
1342
- // information on a request error.
1343
- function _buildError ( url , status , method , response ) {
1344
- var errorData = {
1345
- status : status ,
1346
- type : 'jsonp' ,
1347
- message : 'Server responded with an error for the JSONP request' ,
1348
- url : url ,
1349
- method : method
1350
- } ;
1335
+ // Forward EVRYTHNG API error and extend with URL and Method.
1336
+ function _buildError ( url , status , method , response ) {
1337
+ var errorData = response || { } ;
1351
1338
1352
- if ( response ) {
1353
- errorData . errors = response . errors ;
1354
- errorData . moreInfo = response . moreInfo ;
1355
- }
1339
+ errorData . status = status ;
1340
+ errorData . url = url ;
1341
+ errorData . method = method ;
1356
1342
1357
1343
return errorData ;
1358
1344
}
@@ -1423,12 +1409,18 @@ define('network/jsonp',[
1423
1409
var errorData = _buildError ( url , response . status , params . method , response ) ;
1424
1410
Logger . error ( errorData ) ;
1425
1411
1426
- if ( errorCallback ) { errorCallback ( errorData ) ; }
1412
+ if ( errorCallback ) {
1413
+ Logger . warnCallbackDeprecation ( ) ;
1414
+ errorCallback ( errorData ) ;
1415
+ }
1427
1416
reject ( errorData ) ;
1428
1417
1429
1418
} else {
1430
1419
1431
- if ( successCallback ) { successCallback ( response ) ; }
1420
+ if ( successCallback ) {
1421
+ Logger . warnCallbackDeprecation ( ) ;
1422
+ successCallback ( response ) ;
1423
+ }
1432
1424
1433
1425
try {
1434
1426
response = JSON . parse ( response ) ;
@@ -2867,8 +2859,9 @@ define('authentication',[
2867
2859
'core' ,
2868
2860
'promise' ,
2869
2861
'social/facebook' ,
2870
- 'utils'
2871
- ] , function ( EVT , Promise , Facebook , Utils ) {
2862
+ 'utils' ,
2863
+ 'logger'
2864
+ ] , function ( EVT , Promise , Facebook , Utils , Logger ) {
2872
2865
'use strict' ;
2873
2866
2874
2867
// Login into Evryhtng. This method is attached to the `EVT.App` API methods.
@@ -2963,7 +2956,10 @@ define('authentication',[
2963
2956
// In this case, we add Evrythng access data to this already wrapped response.
2964
2957
authFacebook . call ( $this , userResponse ) . then ( function ( fullResponse ) {
2965
2958
2966
- if ( successCallback ) { successCallback ( fullResponse ) ; }
2959
+ if ( successCallback ) {
2960
+ Logger . warnCallbackDeprecation ( ) ;
2961
+ successCallback ( fullResponse ) ;
2962
+ }
2967
2963
resolve ( fullResponse ) ;
2968
2964
2969
2965
} ) ;
@@ -2972,7 +2968,10 @@ define('authentication',[
2972
2968
2973
2969
// Login was not successful, apply *errorCb* and reject promise. Response
2974
2970
// has Facebook's *authResponse* and *status* objects.
2975
- if ( errorCallback ) { errorCallback ( response ) ; }
2971
+ if ( errorCallback ) {
2972
+ Logger . warnCallbackDeprecation ( ) ;
2973
+ errorCallback ( response ) ;
2974
+ }
2976
2975
reject ( response ) ;
2977
2976
2978
2977
} ) ;
@@ -2995,13 +2994,19 @@ define('authentication',[
2995
2994
2996
2995
// Login was successful, apply callback and propagate response to the
2997
2996
// next promise handler.
2998
- if ( successCallback ) { successCallback ( userResponse ) ; }
2997
+ if ( successCallback ) {
2998
+ Logger . warnCallbackDeprecation ( ) ;
2999
+ successCallback ( userResponse ) ;
3000
+ }
2999
3001
return userResponse ;
3000
3002
3001
3003
} , function ( response ) {
3002
3004
3003
3005
// Login was not successful, call error callback and re-throw error.
3004
- if ( errorCallback ) { errorCallback ( response ) ; }
3006
+ if ( errorCallback ) {
3007
+ Logger . warnCallbackDeprecation ( ) ;
3008
+ errorCallback ( response ) ;
3009
+ }
3005
3010
throw response ;
3006
3011
3007
3012
} ) ;
@@ -3125,14 +3130,20 @@ define('authentication',[
3125
3130
3126
3131
} ) . then ( function ( response ) {
3127
3132
3128
- if ( successCallback ) { successCallback ( response ) ; }
3133
+ if ( successCallback ) {
3134
+ Logger . warnCallbackDeprecation ( ) ;
3135
+ successCallback ( response ) ;
3136
+ }
3129
3137
return response ;
3130
3138
3131
3139
} , function ( err ) {
3132
3140
3133
3141
// If the logout from Evrythng fails, by some reason, throw error
3134
3142
// which would go to the promise error handler of the caller.
3135
- if ( errorCallback ) { errorCallback ( err ) ; }
3143
+ if ( errorCallback ) {
3144
+ Logger . warnCallbackDeprecation ( ) ;
3145
+ errorCallback ( err ) ;
3146
+ }
3136
3147
throw err ;
3137
3148
3138
3149
} ) ;
0 commit comments