comprodls-sdk 2.62.0 → 2.63.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/comprodls-sdk.js +558 -699
- package/dist/comprodls-sdk.min.js +15 -15
- package/lib/services/analytics/index.js +56 -1
- package/package.json +3 -3
package/dist/comprodls-sdk.js
CHANGED
|
@@ -1143,7 +1143,7 @@ validator.validators.contains = function(value, options) {
|
|
|
1143
1143
|
}
|
|
1144
1144
|
}
|
|
1145
1145
|
};
|
|
1146
|
-
},{"./errors":7,"validate.js":
|
|
1146
|
+
},{"./errors":7,"validate.js":50}],10:[function(require,module,exports){
|
|
1147
1147
|
/*************************************************************************
|
|
1148
1148
|
*
|
|
1149
1149
|
* COMPRO CONFIDENTIAL
|
|
@@ -2027,7 +2027,8 @@ function analytics() {
|
|
|
2027
2027
|
getMyAssignedPathsOfClass: getMyAssignedPathsOfClass.bind(this),
|
|
2028
2028
|
getAssignedPathAnalytics: getAssignedPathAnalytics.bind(this),
|
|
2029
2029
|
getMyParticularAssignedPathOfClass: getMyParticularAssignedPathOfClass.bind(this),
|
|
2030
|
-
|
|
2030
|
+
getParticularAssignedPathOfClass: getParticularAssignedPathOfClass.bind(this),
|
|
2031
|
+
|
|
2031
2032
|
getTimeseriesAnalytics: getTimeseriesAnalytics.bind(this),
|
|
2032
2033
|
postProgressTimeseries: postProgressTimeseries.bind(this),
|
|
2033
2034
|
|
|
@@ -3658,6 +3659,60 @@ function getMyParticularAssignedPathOfClass(options) {
|
|
|
3658
3659
|
return dfd.promise;
|
|
3659
3660
|
}
|
|
3660
3661
|
|
|
3662
|
+
/* options = {
|
|
3663
|
+
"classid": "string", // Mandatory
|
|
3664
|
+
"assignedpathid" : "string",
|
|
3665
|
+
"ext_assignedpathid": "string", // Either ext_assignedpathid or assignedpathid is mandatory.
|
|
3666
|
+
};
|
|
3667
|
+
*/
|
|
3668
|
+
function getParticularAssignedPathOfClass(options) {
|
|
3669
|
+
var self = this;
|
|
3670
|
+
// Initializing promise
|
|
3671
|
+
var dfd = q.defer();
|
|
3672
|
+
var err = helpers.validations.isAuthenticated(self.orgId, self.token);
|
|
3673
|
+
if(err) { dfd.reject(err); }
|
|
3674
|
+
else {
|
|
3675
|
+
if(options && options.classid && (options.assignedpathid || options.ext_assignedpathid)) {
|
|
3676
|
+
|
|
3677
|
+
// Passed all validations, Contruct API url
|
|
3678
|
+
var url = self.config.DEFAULT_HOSTS.ANALYTICS +
|
|
3679
|
+
self.config.ANALYTICS_API_URLS.getAllAssignedPathsOfClass;
|
|
3680
|
+
url = helpers.api.constructAPIUrl(url, { orgId: self.orgId });
|
|
3681
|
+
|
|
3682
|
+
var queryParams = { classid: options.classid };
|
|
3683
|
+
if(options.assignedpathid) { queryParams.assignedpathid = options.assignedpathid; }
|
|
3684
|
+
if(options.ext_assignedpathid) {queryParams.ext_assignedpathid = options.ext_assignedpathid;}
|
|
3685
|
+
|
|
3686
|
+
// Setup request with URL and Params
|
|
3687
|
+
var requestAPI = request.get(url).query(queryParams);
|
|
3688
|
+
|
|
3689
|
+
// Setup token in Authorization header
|
|
3690
|
+
requestAPI = helpers.api.setupAPIToken(requestAPI, self.token);
|
|
3691
|
+
|
|
3692
|
+
// Setting up traceid
|
|
3693
|
+
if(self.traceid) { requestAPI.set('X-Amzn-Trace-Id', self.traceid); }
|
|
3694
|
+
|
|
3695
|
+
requestAPI
|
|
3696
|
+
.agent(keepaliveAgent)
|
|
3697
|
+
.end(function (error, response) {
|
|
3698
|
+
if(error) {
|
|
3699
|
+
err = new DLSError(helpers.errors.ERROR_TYPES.API_ERROR, error);
|
|
3700
|
+
dfd.reject(err);
|
|
3701
|
+
}
|
|
3702
|
+
else { dfd.resolve(response.body.entities[0]); }
|
|
3703
|
+
});
|
|
3704
|
+
}
|
|
3705
|
+
else {
|
|
3706
|
+
err = {};
|
|
3707
|
+
err.message = err.description = 'Mandatory params - \'classid\', ' +
|
|
3708
|
+
'\'assignedpathid\'/\'ext_assignedpathid\' not found in request options.';
|
|
3709
|
+
err = new DLSError(helpers.errors.ERROR_TYPES.SDK_ERROR, err);
|
|
3710
|
+
dfd.reject(err);
|
|
3711
|
+
}
|
|
3712
|
+
}
|
|
3713
|
+
return dfd.promise;
|
|
3714
|
+
}
|
|
3715
|
+
|
|
3661
3716
|
/*
|
|
3662
3717
|
options = {
|
|
3663
3718
|
query: 'string', //mandatory
|
|
@@ -17761,181 +17816,167 @@ module.exports = Array.isArray || function (arr) {
|
|
|
17761
17816
|
};
|
|
17762
17817
|
|
|
17763
17818
|
},{}],40:[function(require,module,exports){
|
|
17764
|
-
|
|
17765
|
-
/**
|
|
17766
|
-
* Expose `Emitter`.
|
|
17767
|
-
*/
|
|
17768
|
-
|
|
17769
|
-
|
|
17770
|
-
|
|
17771
|
-
|
|
17772
|
-
|
|
17773
|
-
|
|
17774
|
-
*
|
|
17775
|
-
|
|
17776
|
-
|
|
17777
|
-
|
|
17778
|
-
|
|
17779
|
-
|
|
17780
|
-
|
|
17781
|
-
|
|
17782
|
-
|
|
17783
|
-
|
|
17784
|
-
*
|
|
17785
|
-
*
|
|
17786
|
-
* @
|
|
17787
|
-
|
|
17788
|
-
|
|
17789
|
-
|
|
17790
|
-
|
|
17791
|
-
|
|
17792
|
-
|
|
17793
|
-
|
|
17794
|
-
|
|
17795
|
-
|
|
17796
|
-
|
|
17797
|
-
|
|
17798
|
-
|
|
17799
|
-
*
|
|
17800
|
-
*
|
|
17801
|
-
* @
|
|
17802
|
-
* @
|
|
17803
|
-
|
|
17804
|
-
|
|
17805
|
-
|
|
17806
|
-
|
|
17807
|
-
|
|
17808
|
-
|
|
17809
|
-
|
|
17810
|
-
|
|
17811
|
-
|
|
17812
|
-
|
|
17813
|
-
|
|
17814
|
-
|
|
17815
|
-
|
|
17816
|
-
*
|
|
17817
|
-
*
|
|
17818
|
-
*
|
|
17819
|
-
* @
|
|
17820
|
-
* @
|
|
17821
|
-
|
|
17822
|
-
|
|
17823
|
-
|
|
17824
|
-
|
|
17825
|
-
|
|
17826
|
-
|
|
17827
|
-
|
|
17828
|
-
|
|
17829
|
-
|
|
17830
|
-
|
|
17831
|
-
|
|
17832
|
-
|
|
17833
|
-
|
|
17834
|
-
|
|
17835
|
-
|
|
17836
|
-
|
|
17837
|
-
*
|
|
17838
|
-
*
|
|
17839
|
-
*
|
|
17840
|
-
* @
|
|
17841
|
-
* @
|
|
17842
|
-
|
|
17843
|
-
|
|
17844
|
-
|
|
17845
|
-
|
|
17846
|
-
Emitter.prototype.
|
|
17847
|
-
Emitter.prototype.
|
|
17848
|
-
|
|
17849
|
-
|
|
17850
|
-
|
|
17851
|
-
|
|
17852
|
-
|
|
17853
|
-
|
|
17854
|
-
|
|
17855
|
-
|
|
17856
|
-
|
|
17857
|
-
|
|
17858
|
-
|
|
17859
|
-
|
|
17860
|
-
|
|
17861
|
-
|
|
17862
|
-
|
|
17863
|
-
|
|
17864
|
-
|
|
17865
|
-
|
|
17866
|
-
|
|
17867
|
-
|
|
17868
|
-
|
|
17869
|
-
|
|
17870
|
-
|
|
17871
|
-
|
|
17872
|
-
|
|
17873
|
-
|
|
17874
|
-
|
|
17875
|
-
|
|
17876
|
-
|
|
17877
|
-
|
|
17878
|
-
|
|
17879
|
-
|
|
17880
|
-
|
|
17881
|
-
|
|
17882
|
-
|
|
17883
|
-
|
|
17884
|
-
|
|
17885
|
-
|
|
17886
|
-
|
|
17887
|
-
|
|
17888
|
-
|
|
17889
|
-
|
|
17890
|
-
|
|
17891
|
-
|
|
17892
|
-
|
|
17893
|
-
|
|
17894
|
-
|
|
17895
|
-
|
|
17896
|
-
|
|
17897
|
-
|
|
17898
|
-
|
|
17899
|
-
|
|
17900
|
-
|
|
17901
|
-
|
|
17902
|
-
|
|
17903
|
-
|
|
17904
|
-
|
|
17905
|
-
|
|
17906
|
-
|
|
17907
|
-
|
|
17908
|
-
|
|
17909
|
-
|
|
17910
|
-
}
|
|
17911
|
-
|
|
17912
|
-
|
|
17913
|
-
|
|
17914
|
-
|
|
17915
|
-
|
|
17916
|
-
*
|
|
17917
|
-
*
|
|
17918
|
-
* @
|
|
17919
|
-
* @
|
|
17920
|
-
|
|
17921
|
-
|
|
17922
|
-
|
|
17923
|
-
|
|
17924
|
-
|
|
17925
|
-
return this._callbacks['$' + event] || [];
|
|
17926
|
-
};
|
|
17927
|
-
|
|
17928
|
-
/**
|
|
17929
|
-
* Check if this emitter has `event` handlers.
|
|
17930
|
-
*
|
|
17931
|
-
* @param {String} event
|
|
17932
|
-
* @return {Boolean}
|
|
17933
|
-
* @api public
|
|
17934
|
-
*/
|
|
17935
|
-
|
|
17936
|
-
Emitter.prototype.hasListeners = function(event){
|
|
17937
|
-
return !! this.listeners(event).length;
|
|
17938
|
-
};
|
|
17819
|
+
|
|
17820
|
+
/**
|
|
17821
|
+
* Expose `Emitter`.
|
|
17822
|
+
*/
|
|
17823
|
+
|
|
17824
|
+
module.exports = Emitter;
|
|
17825
|
+
|
|
17826
|
+
/**
|
|
17827
|
+
* Initialize a new `Emitter`.
|
|
17828
|
+
*
|
|
17829
|
+
* @api public
|
|
17830
|
+
*/
|
|
17831
|
+
|
|
17832
|
+
function Emitter(obj) {
|
|
17833
|
+
if (obj) return mixin(obj);
|
|
17834
|
+
};
|
|
17835
|
+
|
|
17836
|
+
/**
|
|
17837
|
+
* Mixin the emitter properties.
|
|
17838
|
+
*
|
|
17839
|
+
* @param {Object} obj
|
|
17840
|
+
* @return {Object}
|
|
17841
|
+
* @api private
|
|
17842
|
+
*/
|
|
17843
|
+
|
|
17844
|
+
function mixin(obj) {
|
|
17845
|
+
for (var key in Emitter.prototype) {
|
|
17846
|
+
obj[key] = Emitter.prototype[key];
|
|
17847
|
+
}
|
|
17848
|
+
return obj;
|
|
17849
|
+
}
|
|
17850
|
+
|
|
17851
|
+
/**
|
|
17852
|
+
* Listen on the given `event` with `fn`.
|
|
17853
|
+
*
|
|
17854
|
+
* @param {String} event
|
|
17855
|
+
* @param {Function} fn
|
|
17856
|
+
* @return {Emitter}
|
|
17857
|
+
* @api public
|
|
17858
|
+
*/
|
|
17859
|
+
|
|
17860
|
+
Emitter.prototype.on =
|
|
17861
|
+
Emitter.prototype.addEventListener = function(event, fn){
|
|
17862
|
+
this._callbacks = this._callbacks || {};
|
|
17863
|
+
(this._callbacks['$' + event] = this._callbacks['$' + event] || [])
|
|
17864
|
+
.push(fn);
|
|
17865
|
+
return this;
|
|
17866
|
+
};
|
|
17867
|
+
|
|
17868
|
+
/**
|
|
17869
|
+
* Adds an `event` listener that will be invoked a single
|
|
17870
|
+
* time then automatically removed.
|
|
17871
|
+
*
|
|
17872
|
+
* @param {String} event
|
|
17873
|
+
* @param {Function} fn
|
|
17874
|
+
* @return {Emitter}
|
|
17875
|
+
* @api public
|
|
17876
|
+
*/
|
|
17877
|
+
|
|
17878
|
+
Emitter.prototype.once = function(event, fn){
|
|
17879
|
+
function on() {
|
|
17880
|
+
this.off(event, on);
|
|
17881
|
+
fn.apply(this, arguments);
|
|
17882
|
+
}
|
|
17883
|
+
|
|
17884
|
+
on.fn = fn;
|
|
17885
|
+
this.on(event, on);
|
|
17886
|
+
return this;
|
|
17887
|
+
};
|
|
17888
|
+
|
|
17889
|
+
/**
|
|
17890
|
+
* Remove the given callback for `event` or all
|
|
17891
|
+
* registered callbacks.
|
|
17892
|
+
*
|
|
17893
|
+
* @param {String} event
|
|
17894
|
+
* @param {Function} fn
|
|
17895
|
+
* @return {Emitter}
|
|
17896
|
+
* @api public
|
|
17897
|
+
*/
|
|
17898
|
+
|
|
17899
|
+
Emitter.prototype.off =
|
|
17900
|
+
Emitter.prototype.removeListener =
|
|
17901
|
+
Emitter.prototype.removeAllListeners =
|
|
17902
|
+
Emitter.prototype.removeEventListener = function(event, fn){
|
|
17903
|
+
this._callbacks = this._callbacks || {};
|
|
17904
|
+
|
|
17905
|
+
// all
|
|
17906
|
+
if (0 == arguments.length) {
|
|
17907
|
+
this._callbacks = {};
|
|
17908
|
+
return this;
|
|
17909
|
+
}
|
|
17910
|
+
|
|
17911
|
+
// specific event
|
|
17912
|
+
var callbacks = this._callbacks['$' + event];
|
|
17913
|
+
if (!callbacks) return this;
|
|
17914
|
+
|
|
17915
|
+
// remove all handlers
|
|
17916
|
+
if (1 == arguments.length) {
|
|
17917
|
+
delete this._callbacks['$' + event];
|
|
17918
|
+
return this;
|
|
17919
|
+
}
|
|
17920
|
+
|
|
17921
|
+
// remove specific handler
|
|
17922
|
+
var cb;
|
|
17923
|
+
for (var i = 0; i < callbacks.length; i++) {
|
|
17924
|
+
cb = callbacks[i];
|
|
17925
|
+
if (cb === fn || cb.fn === fn) {
|
|
17926
|
+
callbacks.splice(i, 1);
|
|
17927
|
+
break;
|
|
17928
|
+
}
|
|
17929
|
+
}
|
|
17930
|
+
return this;
|
|
17931
|
+
};
|
|
17932
|
+
|
|
17933
|
+
/**
|
|
17934
|
+
* Emit `event` with the given args.
|
|
17935
|
+
*
|
|
17936
|
+
* @param {String} event
|
|
17937
|
+
* @param {Mixed} ...
|
|
17938
|
+
* @return {Emitter}
|
|
17939
|
+
*/
|
|
17940
|
+
|
|
17941
|
+
Emitter.prototype.emit = function(event){
|
|
17942
|
+
this._callbacks = this._callbacks || {};
|
|
17943
|
+
var args = [].slice.call(arguments, 1)
|
|
17944
|
+
, callbacks = this._callbacks['$' + event];
|
|
17945
|
+
|
|
17946
|
+
if (callbacks) {
|
|
17947
|
+
callbacks = callbacks.slice(0);
|
|
17948
|
+
for (var i = 0, len = callbacks.length; i < len; ++i) {
|
|
17949
|
+
callbacks[i].apply(this, args);
|
|
17950
|
+
}
|
|
17951
|
+
}
|
|
17952
|
+
|
|
17953
|
+
return this;
|
|
17954
|
+
};
|
|
17955
|
+
|
|
17956
|
+
/**
|
|
17957
|
+
* Return array of callbacks for `event`.
|
|
17958
|
+
*
|
|
17959
|
+
* @param {String} event
|
|
17960
|
+
* @return {Array}
|
|
17961
|
+
* @api public
|
|
17962
|
+
*/
|
|
17963
|
+
|
|
17964
|
+
Emitter.prototype.listeners = function(event){
|
|
17965
|
+
this._callbacks = this._callbacks || {};
|
|
17966
|
+
return this._callbacks['$' + event] || [];
|
|
17967
|
+
};
|
|
17968
|
+
|
|
17969
|
+
/**
|
|
17970
|
+
* Check if this emitter has `event` handlers.
|
|
17971
|
+
*
|
|
17972
|
+
* @param {String} event
|
|
17973
|
+
* @return {Boolean}
|
|
17974
|
+
* @api public
|
|
17975
|
+
*/
|
|
17976
|
+
|
|
17977
|
+
Emitter.prototype.hasListeners = function(event){
|
|
17978
|
+
return !! this.listeners(event).length;
|
|
17979
|
+
};
|
|
17939
17980
|
|
|
17940
17981
|
},{}],41:[function(require,module,exports){
|
|
17941
17982
|
// Copyright Joyent, Inc. and other Node contributors.
|
|
@@ -18241,8 +18282,6 @@ function isUndefined(arg) {
|
|
|
18241
18282
|
}
|
|
18242
18283
|
|
|
18243
18284
|
},{}],42:[function(require,module,exports){
|
|
18244
|
-
'use strict';
|
|
18245
|
-
|
|
18246
18285
|
var hasOwn = Object.prototype.hasOwnProperty;
|
|
18247
18286
|
var toStr = Object.prototype.toString;
|
|
18248
18287
|
var defineProperty = Object.defineProperty;
|
|
@@ -18257,6 +18296,8 @@ var isArray = function isArray(arr) {
|
|
|
18257
18296
|
};
|
|
18258
18297
|
|
|
18259
18298
|
var isPlainObject = function isPlainObject(obj) {
|
|
18299
|
+
'use strict';
|
|
18300
|
+
|
|
18260
18301
|
if (!obj || toStr.call(obj) !== '[object Object]') {
|
|
18261
18302
|
return false;
|
|
18262
18303
|
}
|
|
@@ -18306,6 +18347,8 @@ var getProperty = function getProperty(obj, name) {
|
|
|
18306
18347
|
};
|
|
18307
18348
|
|
|
18308
18349
|
module.exports = function extend() {
|
|
18350
|
+
'use strict';
|
|
18351
|
+
|
|
18309
18352
|
var options, name, src, copy, copyIsArray, clone;
|
|
18310
18353
|
var target = arguments[0];
|
|
18311
18354
|
var i = 1;
|
|
@@ -20775,8 +20818,6 @@ function template(string) {
|
|
|
20775
20818
|
|
|
20776
20819
|
var Emitter = require('emitter');
|
|
20777
20820
|
var reduce = require('reduce');
|
|
20778
|
-
var requestBase = require('./request-base');
|
|
20779
|
-
var isObject = require('./is-object');
|
|
20780
20821
|
|
|
20781
20822
|
/**
|
|
20782
20823
|
* Root reference for iframes.
|
|
@@ -20798,10 +20839,28 @@ if (typeof window !== 'undefined') { // Browser window
|
|
|
20798
20839
|
function noop(){};
|
|
20799
20840
|
|
|
20800
20841
|
/**
|
|
20801
|
-
*
|
|
20842
|
+
* Check if `obj` is a host object,
|
|
20843
|
+
* we don't want to serialize these :)
|
|
20844
|
+
*
|
|
20845
|
+
* TODO: future proof, move to compoent land
|
|
20846
|
+
*
|
|
20847
|
+
* @param {Object} obj
|
|
20848
|
+
* @return {Boolean}
|
|
20849
|
+
* @api private
|
|
20802
20850
|
*/
|
|
20803
20851
|
|
|
20804
|
-
|
|
20852
|
+
function isHost(obj) {
|
|
20853
|
+
var str = {}.toString.call(obj);
|
|
20854
|
+
|
|
20855
|
+
switch (str) {
|
|
20856
|
+
case '[object File]':
|
|
20857
|
+
case '[object Blob]':
|
|
20858
|
+
case '[object FormData]':
|
|
20859
|
+
return true;
|
|
20860
|
+
default:
|
|
20861
|
+
return false;
|
|
20862
|
+
}
|
|
20863
|
+
}
|
|
20805
20864
|
|
|
20806
20865
|
/**
|
|
20807
20866
|
* Determine XHR.
|
|
@@ -20833,6 +20892,18 @@ var trim = ''.trim
|
|
|
20833
20892
|
? function(s) { return s.trim(); }
|
|
20834
20893
|
: function(s) { return s.replace(/(^\s*|\s*$)/g, ''); };
|
|
20835
20894
|
|
|
20895
|
+
/**
|
|
20896
|
+
* Check if `obj` is an object.
|
|
20897
|
+
*
|
|
20898
|
+
* @param {Object} obj
|
|
20899
|
+
* @return {Boolean}
|
|
20900
|
+
* @api private
|
|
20901
|
+
*/
|
|
20902
|
+
|
|
20903
|
+
function isObject(obj) {
|
|
20904
|
+
return obj === Object(obj);
|
|
20905
|
+
}
|
|
20906
|
+
|
|
20836
20907
|
/**
|
|
20837
20908
|
* Serialize the given `obj`.
|
|
20838
20909
|
*
|
|
@@ -20847,8 +20918,8 @@ function serialize(obj) {
|
|
|
20847
20918
|
for (var key in obj) {
|
|
20848
20919
|
if (null != obj[key]) {
|
|
20849
20920
|
pushEncodedKeyValuePair(pairs, key, obj[key]);
|
|
20850
|
-
|
|
20851
|
-
|
|
20921
|
+
}
|
|
20922
|
+
}
|
|
20852
20923
|
return pairs.join('&');
|
|
20853
20924
|
}
|
|
20854
20925
|
|
|
@@ -20866,11 +20937,6 @@ function pushEncodedKeyValuePair(pairs, key, val) {
|
|
|
20866
20937
|
return val.forEach(function(v) {
|
|
20867
20938
|
pushEncodedKeyValuePair(pairs, key, v);
|
|
20868
20939
|
});
|
|
20869
|
-
} else if (isObject(val)) {
|
|
20870
|
-
for(var subkey in val) {
|
|
20871
|
-
pushEncodedKeyValuePair(pairs, key + '[' + subkey + ']', val[subkey]);
|
|
20872
|
-
}
|
|
20873
|
-
return;
|
|
20874
20940
|
}
|
|
20875
20941
|
pairs.push(encodeURIComponent(key)
|
|
20876
20942
|
+ '=' + encodeURIComponent(val));
|
|
@@ -20893,18 +20959,13 @@ function pushEncodedKeyValuePair(pairs, key, val) {
|
|
|
20893
20959
|
function parseString(str) {
|
|
20894
20960
|
var obj = {};
|
|
20895
20961
|
var pairs = str.split('&');
|
|
20962
|
+
var parts;
|
|
20896
20963
|
var pair;
|
|
20897
|
-
var pos;
|
|
20898
20964
|
|
|
20899
20965
|
for (var i = 0, len = pairs.length; i < len; ++i) {
|
|
20900
20966
|
pair = pairs[i];
|
|
20901
|
-
|
|
20902
|
-
|
|
20903
|
-
obj[decodeURIComponent(pair)] = '';
|
|
20904
|
-
} else {
|
|
20905
|
-
obj[decodeURIComponent(pair.slice(0, pos))] =
|
|
20906
|
-
decodeURIComponent(pair.slice(pos + 1));
|
|
20907
|
-
}
|
|
20967
|
+
parts = pair.split('=');
|
|
20968
|
+
obj[decodeURIComponent(parts[0])] = decodeURIComponent(parts[1]);
|
|
20908
20969
|
}
|
|
20909
20970
|
|
|
20910
20971
|
return obj;
|
|
@@ -21088,15 +21149,15 @@ function Response(req, options) {
|
|
|
21088
21149
|
? this.xhr.responseText
|
|
21089
21150
|
: null;
|
|
21090
21151
|
this.statusText = this.req.xhr.statusText;
|
|
21091
|
-
this.
|
|
21152
|
+
this.setStatusProperties(this.xhr.status);
|
|
21092
21153
|
this.header = this.headers = parseHeader(this.xhr.getAllResponseHeaders());
|
|
21093
21154
|
// getAllResponseHeaders sometimes falsely returns "" for CORS requests, but
|
|
21094
21155
|
// getResponseHeader still works. so we get content-type even if getting
|
|
21095
21156
|
// other headers fails.
|
|
21096
21157
|
this.header['content-type'] = this.xhr.getResponseHeader('content-type');
|
|
21097
|
-
this.
|
|
21158
|
+
this.setHeaderProperties(this.header);
|
|
21098
21159
|
this.body = this.req.method != 'HEAD'
|
|
21099
|
-
? this.
|
|
21160
|
+
? this.parseBody(this.text ? this.text : this.xhr.response)
|
|
21100
21161
|
: null;
|
|
21101
21162
|
}
|
|
21102
21163
|
|
|
@@ -21124,7 +21185,7 @@ Response.prototype.get = function(field){
|
|
|
21124
21185
|
* @api private
|
|
21125
21186
|
*/
|
|
21126
21187
|
|
|
21127
|
-
Response.prototype.
|
|
21188
|
+
Response.prototype.setHeaderProperties = function(header){
|
|
21128
21189
|
// content-type
|
|
21129
21190
|
var ct = this.header['content-type'] || '';
|
|
21130
21191
|
this.type = type(ct);
|
|
@@ -21145,11 +21206,8 @@ Response.prototype._setHeaderProperties = function(header){
|
|
|
21145
21206
|
* @api private
|
|
21146
21207
|
*/
|
|
21147
21208
|
|
|
21148
|
-
Response.prototype.
|
|
21209
|
+
Response.prototype.parseBody = function(str){
|
|
21149
21210
|
var parse = request.parse[this.type];
|
|
21150
|
-
if (!parse && isJSON(this.type)) {
|
|
21151
|
-
parse = request.parse['application/json'];
|
|
21152
|
-
}
|
|
21153
21211
|
return parse && str && (str.length || str instanceof Object)
|
|
21154
21212
|
? parse(str)
|
|
21155
21213
|
: null;
|
|
@@ -21176,7 +21234,7 @@ Response.prototype._parseBody = function(str){
|
|
|
21176
21234
|
* @api private
|
|
21177
21235
|
*/
|
|
21178
21236
|
|
|
21179
|
-
Response.prototype.
|
|
21237
|
+
Response.prototype.setStatusProperties = function(status){
|
|
21180
21238
|
// handle IE9 bug: http://stackoverflow.com/questions/10046972/msie-returns-status-code-of-1223-for-ajax-request
|
|
21181
21239
|
if (status === 1223) {
|
|
21182
21240
|
status = 204;
|
|
@@ -21244,11 +21302,12 @@ request.Response = Response;
|
|
|
21244
21302
|
|
|
21245
21303
|
function Request(method, url) {
|
|
21246
21304
|
var self = this;
|
|
21305
|
+
Emitter.call(this);
|
|
21247
21306
|
this._query = this._query || [];
|
|
21248
21307
|
this.method = method;
|
|
21249
21308
|
this.url = url;
|
|
21250
|
-
this.header = {};
|
|
21251
|
-
this._header = {};
|
|
21309
|
+
this.header = {};
|
|
21310
|
+
this._header = {};
|
|
21252
21311
|
this.on('end', function(){
|
|
21253
21312
|
var err = null;
|
|
21254
21313
|
var res = null;
|
|
@@ -21261,8 +21320,6 @@ function Request(method, url) {
|
|
|
21261
21320
|
err.original = e;
|
|
21262
21321
|
// issue #675: return the raw response if the response parsing fails
|
|
21263
21322
|
err.rawResponse = self.xhr && self.xhr.responseText ? self.xhr.responseText : null;
|
|
21264
|
-
// issue #876: return the http status code if the response parsing fails
|
|
21265
|
-
err.statusCode = self.xhr && self.xhr.status ? self.xhr.status : null;
|
|
21266
21323
|
return self.callback(err);
|
|
21267
21324
|
}
|
|
21268
21325
|
|
|
@@ -21272,32 +21329,140 @@ function Request(method, url) {
|
|
|
21272
21329
|
return self.callback(err, res);
|
|
21273
21330
|
}
|
|
21274
21331
|
|
|
21275
|
-
|
|
21276
|
-
|
|
21277
|
-
|
|
21278
|
-
}
|
|
21332
|
+
if (res.status >= 200 && res.status < 300) {
|
|
21333
|
+
return self.callback(err, res);
|
|
21334
|
+
}
|
|
21279
21335
|
|
|
21280
|
-
|
|
21281
|
-
|
|
21282
|
-
|
|
21283
|
-
|
|
21336
|
+
var new_err = new Error(res.statusText || 'Unsuccessful HTTP response');
|
|
21337
|
+
new_err.original = err;
|
|
21338
|
+
new_err.response = res;
|
|
21339
|
+
new_err.status = res.status;
|
|
21284
21340
|
|
|
21285
|
-
|
|
21286
|
-
} catch(e) {
|
|
21287
|
-
self.callback(e); // #985 touching res may cause INVALID_STATE_ERR on old Android
|
|
21288
|
-
}
|
|
21341
|
+
self.callback(new_err, res);
|
|
21289
21342
|
});
|
|
21290
21343
|
}
|
|
21291
21344
|
|
|
21292
21345
|
/**
|
|
21293
|
-
* Mixin `Emitter
|
|
21346
|
+
* Mixin `Emitter`.
|
|
21294
21347
|
*/
|
|
21295
21348
|
|
|
21296
21349
|
Emitter(Request.prototype);
|
|
21297
|
-
|
|
21298
|
-
|
|
21350
|
+
|
|
21351
|
+
/**
|
|
21352
|
+
* Allow for extension
|
|
21353
|
+
*/
|
|
21354
|
+
|
|
21355
|
+
Request.prototype.use = function(fn) {
|
|
21356
|
+
fn(this);
|
|
21357
|
+
return this;
|
|
21299
21358
|
}
|
|
21300
21359
|
|
|
21360
|
+
/**
|
|
21361
|
+
* Set timeout to `ms`.
|
|
21362
|
+
*
|
|
21363
|
+
* @param {Number} ms
|
|
21364
|
+
* @return {Request} for chaining
|
|
21365
|
+
* @api public
|
|
21366
|
+
*/
|
|
21367
|
+
|
|
21368
|
+
Request.prototype.timeout = function(ms){
|
|
21369
|
+
this._timeout = ms;
|
|
21370
|
+
return this;
|
|
21371
|
+
};
|
|
21372
|
+
|
|
21373
|
+
/**
|
|
21374
|
+
* Clear previous timeout.
|
|
21375
|
+
*
|
|
21376
|
+
* @return {Request} for chaining
|
|
21377
|
+
* @api public
|
|
21378
|
+
*/
|
|
21379
|
+
|
|
21380
|
+
Request.prototype.clearTimeout = function(){
|
|
21381
|
+
this._timeout = 0;
|
|
21382
|
+
clearTimeout(this._timer);
|
|
21383
|
+
return this;
|
|
21384
|
+
};
|
|
21385
|
+
|
|
21386
|
+
/**
|
|
21387
|
+
* Abort the request, and clear potential timeout.
|
|
21388
|
+
*
|
|
21389
|
+
* @return {Request}
|
|
21390
|
+
* @api public
|
|
21391
|
+
*/
|
|
21392
|
+
|
|
21393
|
+
Request.prototype.abort = function(){
|
|
21394
|
+
if (this.aborted) return;
|
|
21395
|
+
this.aborted = true;
|
|
21396
|
+
this.xhr.abort();
|
|
21397
|
+
this.clearTimeout();
|
|
21398
|
+
this.emit('abort');
|
|
21399
|
+
return this;
|
|
21400
|
+
};
|
|
21401
|
+
|
|
21402
|
+
/**
|
|
21403
|
+
* Set header `field` to `val`, or multiple fields with one object.
|
|
21404
|
+
*
|
|
21405
|
+
* Examples:
|
|
21406
|
+
*
|
|
21407
|
+
* req.get('/')
|
|
21408
|
+
* .set('Accept', 'application/json')
|
|
21409
|
+
* .set('X-API-Key', 'foobar')
|
|
21410
|
+
* .end(callback);
|
|
21411
|
+
*
|
|
21412
|
+
* req.get('/')
|
|
21413
|
+
* .set({ Accept: 'application/json', 'X-API-Key': 'foobar' })
|
|
21414
|
+
* .end(callback);
|
|
21415
|
+
*
|
|
21416
|
+
* @param {String|Object} field
|
|
21417
|
+
* @param {String} val
|
|
21418
|
+
* @return {Request} for chaining
|
|
21419
|
+
* @api public
|
|
21420
|
+
*/
|
|
21421
|
+
|
|
21422
|
+
Request.prototype.set = function(field, val){
|
|
21423
|
+
if (isObject(field)) {
|
|
21424
|
+
for (var key in field) {
|
|
21425
|
+
this.set(key, field[key]);
|
|
21426
|
+
}
|
|
21427
|
+
return this;
|
|
21428
|
+
}
|
|
21429
|
+
this._header[field.toLowerCase()] = val;
|
|
21430
|
+
this.header[field] = val;
|
|
21431
|
+
return this;
|
|
21432
|
+
};
|
|
21433
|
+
|
|
21434
|
+
/**
|
|
21435
|
+
* Remove header `field`.
|
|
21436
|
+
*
|
|
21437
|
+
* Example:
|
|
21438
|
+
*
|
|
21439
|
+
* req.get('/')
|
|
21440
|
+
* .unset('User-Agent')
|
|
21441
|
+
* .end(callback);
|
|
21442
|
+
*
|
|
21443
|
+
* @param {String} field
|
|
21444
|
+
* @return {Request} for chaining
|
|
21445
|
+
* @api public
|
|
21446
|
+
*/
|
|
21447
|
+
|
|
21448
|
+
Request.prototype.unset = function(field){
|
|
21449
|
+
delete this._header[field.toLowerCase()];
|
|
21450
|
+
delete this.header[field];
|
|
21451
|
+
return this;
|
|
21452
|
+
};
|
|
21453
|
+
|
|
21454
|
+
/**
|
|
21455
|
+
* Get case-insensitive header `field` value.
|
|
21456
|
+
*
|
|
21457
|
+
* @param {String} field
|
|
21458
|
+
* @return {String}
|
|
21459
|
+
* @api private
|
|
21460
|
+
*/
|
|
21461
|
+
|
|
21462
|
+
Request.prototype.getHeader = function(field){
|
|
21463
|
+
return this._header[field.toLowerCase()];
|
|
21464
|
+
};
|
|
21465
|
+
|
|
21301
21466
|
/**
|
|
21302
21467
|
* Set Content-Type to `type`, mapping values from `request.types`.
|
|
21303
21468
|
*
|
|
@@ -21326,22 +21491,16 @@ Request.prototype.type = function(type){
|
|
|
21326
21491
|
};
|
|
21327
21492
|
|
|
21328
21493
|
/**
|
|
21329
|
-
*
|
|
21330
|
-
* 'arraybuffer'.
|
|
21331
|
-
*
|
|
21332
|
-
* Examples:
|
|
21494
|
+
* Force given parser
|
|
21333
21495
|
*
|
|
21334
|
-
*
|
|
21335
|
-
* .responseType('blob')
|
|
21336
|
-
* .end(callback);
|
|
21496
|
+
* Sets the body parser no matter type.
|
|
21337
21497
|
*
|
|
21338
|
-
* @param {
|
|
21339
|
-
* @return {Request} for chaining
|
|
21498
|
+
* @param {Function}
|
|
21340
21499
|
* @api public
|
|
21341
21500
|
*/
|
|
21342
21501
|
|
|
21343
|
-
Request.prototype.
|
|
21344
|
-
this.
|
|
21502
|
+
Request.prototype.parse = function(fn){
|
|
21503
|
+
this._parser = fn;
|
|
21345
21504
|
return this;
|
|
21346
21505
|
};
|
|
21347
21506
|
|
|
@@ -21375,29 +21534,13 @@ Request.prototype.accept = function(type){
|
|
|
21375
21534
|
*
|
|
21376
21535
|
* @param {String} user
|
|
21377
21536
|
* @param {String} pass
|
|
21378
|
-
* @param {Object} options with 'type' property 'auto' or 'basic' (default 'basic')
|
|
21379
21537
|
* @return {Request} for chaining
|
|
21380
21538
|
* @api public
|
|
21381
21539
|
*/
|
|
21382
21540
|
|
|
21383
|
-
Request.prototype.auth = function(user, pass
|
|
21384
|
-
|
|
21385
|
-
|
|
21386
|
-
type: 'basic'
|
|
21387
|
-
}
|
|
21388
|
-
}
|
|
21389
|
-
|
|
21390
|
-
switch (options.type) {
|
|
21391
|
-
case 'basic':
|
|
21392
|
-
var str = btoa(user + ':' + pass);
|
|
21393
|
-
this.set('Authorization', 'Basic ' + str);
|
|
21394
|
-
break;
|
|
21395
|
-
|
|
21396
|
-
case 'auto':
|
|
21397
|
-
this.username = user;
|
|
21398
|
-
this.password = pass;
|
|
21399
|
-
break;
|
|
21400
|
-
}
|
|
21541
|
+
Request.prototype.auth = function(user, pass){
|
|
21542
|
+
var str = btoa(user + ':' + pass);
|
|
21543
|
+
this.set('Authorization', 'Basic ' + str);
|
|
21401
21544
|
return this;
|
|
21402
21545
|
};
|
|
21403
21546
|
|
|
@@ -21421,13 +21564,35 @@ Request.prototype.query = function(val){
|
|
|
21421
21564
|
return this;
|
|
21422
21565
|
};
|
|
21423
21566
|
|
|
21567
|
+
/**
|
|
21568
|
+
* Write the field `name` and `val` for "multipart/form-data"
|
|
21569
|
+
* request bodies.
|
|
21570
|
+
*
|
|
21571
|
+
* ``` js
|
|
21572
|
+
* request.post('/upload')
|
|
21573
|
+
* .field('foo', 'bar')
|
|
21574
|
+
* .end(callback);
|
|
21575
|
+
* ```
|
|
21576
|
+
*
|
|
21577
|
+
* @param {String} name
|
|
21578
|
+
* @param {String|Blob|File} val
|
|
21579
|
+
* @return {Request} for chaining
|
|
21580
|
+
* @api public
|
|
21581
|
+
*/
|
|
21582
|
+
|
|
21583
|
+
Request.prototype.field = function(name, val){
|
|
21584
|
+
if (!this._formData) this._formData = new root.FormData();
|
|
21585
|
+
this._formData.append(name, val);
|
|
21586
|
+
return this;
|
|
21587
|
+
};
|
|
21588
|
+
|
|
21424
21589
|
/**
|
|
21425
21590
|
* Queue the given `file` as an attachment to the specified `field`,
|
|
21426
21591
|
* with optional `filename`.
|
|
21427
21592
|
*
|
|
21428
21593
|
* ``` js
|
|
21429
21594
|
* request.post('/upload')
|
|
21430
|
-
* .attach(
|
|
21595
|
+
* .attach(new Blob(['<a id="a"><b id="b">hey!</b></a>'], { type: "text/html"}))
|
|
21431
21596
|
* .end(callback);
|
|
21432
21597
|
* ```
|
|
21433
21598
|
*
|
|
@@ -21439,15 +21604,77 @@ Request.prototype.query = function(val){
|
|
|
21439
21604
|
*/
|
|
21440
21605
|
|
|
21441
21606
|
Request.prototype.attach = function(field, file, filename){
|
|
21442
|
-
this.
|
|
21607
|
+
if (!this._formData) this._formData = new root.FormData();
|
|
21608
|
+
this._formData.append(field, file, filename || file.name);
|
|
21443
21609
|
return this;
|
|
21444
21610
|
};
|
|
21445
21611
|
|
|
21446
|
-
|
|
21447
|
-
|
|
21448
|
-
|
|
21612
|
+
/**
|
|
21613
|
+
* Send `data` as the request body, defaulting the `.type()` to "json" when
|
|
21614
|
+
* an object is given.
|
|
21615
|
+
*
|
|
21616
|
+
* Examples:
|
|
21617
|
+
*
|
|
21618
|
+
* // manual json
|
|
21619
|
+
* request.post('/user')
|
|
21620
|
+
* .type('json')
|
|
21621
|
+
* .send('{"name":"tj"}')
|
|
21622
|
+
* .end(callback)
|
|
21623
|
+
*
|
|
21624
|
+
* // auto json
|
|
21625
|
+
* request.post('/user')
|
|
21626
|
+
* .send({ name: 'tj' })
|
|
21627
|
+
* .end(callback)
|
|
21628
|
+
*
|
|
21629
|
+
* // manual x-www-form-urlencoded
|
|
21630
|
+
* request.post('/user')
|
|
21631
|
+
* .type('form')
|
|
21632
|
+
* .send('name=tj')
|
|
21633
|
+
* .end(callback)
|
|
21634
|
+
*
|
|
21635
|
+
* // auto x-www-form-urlencoded
|
|
21636
|
+
* request.post('/user')
|
|
21637
|
+
* .type('form')
|
|
21638
|
+
* .send({ name: 'tj' })
|
|
21639
|
+
* .end(callback)
|
|
21640
|
+
*
|
|
21641
|
+
* // defaults to x-www-form-urlencoded
|
|
21642
|
+
* request.post('/user')
|
|
21643
|
+
* .send('name=tobi')
|
|
21644
|
+
* .send('species=ferret')
|
|
21645
|
+
* .end(callback)
|
|
21646
|
+
*
|
|
21647
|
+
* @param {String|Object} data
|
|
21648
|
+
* @return {Request} for chaining
|
|
21649
|
+
* @api public
|
|
21650
|
+
*/
|
|
21651
|
+
|
|
21652
|
+
Request.prototype.send = function(data){
|
|
21653
|
+
var obj = isObject(data);
|
|
21654
|
+
var type = this.getHeader('Content-Type');
|
|
21655
|
+
|
|
21656
|
+
// merge
|
|
21657
|
+
if (obj && isObject(this._data)) {
|
|
21658
|
+
for (var key in data) {
|
|
21659
|
+
this._data[key] = data[key];
|
|
21660
|
+
}
|
|
21661
|
+
} else if ('string' == typeof data) {
|
|
21662
|
+
if (!type) this.type('form');
|
|
21663
|
+
type = this.getHeader('Content-Type');
|
|
21664
|
+
if ('application/x-www-form-urlencoded' == type) {
|
|
21665
|
+
this._data = this._data
|
|
21666
|
+
? this._data + '&' + data
|
|
21667
|
+
: data;
|
|
21668
|
+
} else {
|
|
21669
|
+
this._data = (this._data || '') + data;
|
|
21670
|
+
}
|
|
21671
|
+
} else {
|
|
21672
|
+
this._data = data;
|
|
21449
21673
|
}
|
|
21450
|
-
|
|
21674
|
+
|
|
21675
|
+
if (!obj || isHost(data)) return this;
|
|
21676
|
+
if (!type) this.type('json');
|
|
21677
|
+
return this;
|
|
21451
21678
|
};
|
|
21452
21679
|
|
|
21453
21680
|
/**
|
|
@@ -21488,7 +21715,7 @@ Request.prototype.crossDomainError = function(){
|
|
|
21488
21715
|
* @api private
|
|
21489
21716
|
*/
|
|
21490
21717
|
|
|
21491
|
-
Request.prototype.
|
|
21718
|
+
Request.prototype.timeoutError = function(){
|
|
21492
21719
|
var timeout = this._timeout;
|
|
21493
21720
|
var err = new Error('timeout of ' + timeout + 'ms exceeded');
|
|
21494
21721
|
err.timeout = timeout;
|
|
@@ -21496,18 +21723,19 @@ Request.prototype._timeoutError = function(){
|
|
|
21496
21723
|
};
|
|
21497
21724
|
|
|
21498
21725
|
/**
|
|
21499
|
-
*
|
|
21726
|
+
* Enable transmission of cookies with x-domain requests.
|
|
21500
21727
|
*
|
|
21501
|
-
*
|
|
21728
|
+
* Note that for this to work the origin must not be
|
|
21729
|
+
* using "Access-Control-Allow-Origin" with a wildcard,
|
|
21730
|
+
* and also must set "Access-Control-Allow-Credentials"
|
|
21731
|
+
* to "true".
|
|
21732
|
+
*
|
|
21733
|
+
* @api public
|
|
21502
21734
|
*/
|
|
21503
21735
|
|
|
21504
|
-
Request.prototype.
|
|
21505
|
-
|
|
21506
|
-
|
|
21507
|
-
this.url += ~this.url.indexOf('?')
|
|
21508
|
-
? '&' + query
|
|
21509
|
-
: '?' + query;
|
|
21510
|
-
}
|
|
21736
|
+
Request.prototype.withCredentials = function(){
|
|
21737
|
+
this._withCredentials = true;
|
|
21738
|
+
return this;
|
|
21511
21739
|
};
|
|
21512
21740
|
|
|
21513
21741
|
/**
|
|
@@ -21522,6 +21750,7 @@ Request.prototype._appendQueryString = function(){
|
|
|
21522
21750
|
Request.prototype.end = function(fn){
|
|
21523
21751
|
var self = this;
|
|
21524
21752
|
var xhr = this.xhr = request.getXHR();
|
|
21753
|
+
var query = this._query.join('&');
|
|
21525
21754
|
var timeout = this._timeout;
|
|
21526
21755
|
var data = this._formData || this._data;
|
|
21527
21756
|
|
|
@@ -21538,8 +21767,8 @@ Request.prototype.end = function(fn){
|
|
|
21538
21767
|
try { status = xhr.status } catch(e) { status = 0; }
|
|
21539
21768
|
|
|
21540
21769
|
if (0 == status) {
|
|
21541
|
-
if (self.timedout) return self.
|
|
21542
|
-
if (self.
|
|
21770
|
+
if (self.timedout) return self.timeoutError();
|
|
21771
|
+
if (self.aborted) return;
|
|
21543
21772
|
return self.crossDomainError();
|
|
21544
21773
|
}
|
|
21545
21774
|
self.emit('end');
|
|
@@ -21575,23 +21804,24 @@ Request.prototype.end = function(fn){
|
|
|
21575
21804
|
}
|
|
21576
21805
|
|
|
21577
21806
|
// querystring
|
|
21578
|
-
|
|
21807
|
+
if (query) {
|
|
21808
|
+
query = request.serializeObject(query);
|
|
21809
|
+
this.url += ~this.url.indexOf('?')
|
|
21810
|
+
? '&' + query
|
|
21811
|
+
: '?' + query;
|
|
21812
|
+
}
|
|
21579
21813
|
|
|
21580
21814
|
// initiate request
|
|
21581
|
-
|
|
21582
|
-
xhr.open(this.method, this.url, true, this.username, this.password);
|
|
21583
|
-
} else {
|
|
21584
|
-
xhr.open(this.method, this.url, true);
|
|
21585
|
-
}
|
|
21815
|
+
xhr.open(this.method, this.url, true);
|
|
21586
21816
|
|
|
21587
21817
|
// CORS
|
|
21588
21818
|
if (this._withCredentials) xhr.withCredentials = true;
|
|
21589
21819
|
|
|
21590
21820
|
// body
|
|
21591
|
-
if ('GET' != this.method && 'HEAD' != this.method && 'string' != typeof data && !
|
|
21821
|
+
if ('GET' != this.method && 'HEAD' != this.method && 'string' != typeof data && !isHost(data)) {
|
|
21592
21822
|
// serialize stuff
|
|
21593
|
-
var contentType = this.
|
|
21594
|
-
var serialize = this.
|
|
21823
|
+
var contentType = this.getHeader('Content-Type');
|
|
21824
|
+
var serialize = this._parser || request.serialize[contentType ? contentType.split(';')[0] : ''];
|
|
21595
21825
|
if (!serialize && isJSON(contentType)) serialize = request.serialize['application/json'];
|
|
21596
21826
|
if (serialize) data = serialize(data);
|
|
21597
21827
|
}
|
|
@@ -21602,10 +21832,6 @@ Request.prototype.end = function(fn){
|
|
|
21602
21832
|
xhr.setRequestHeader(field, this.header[field]);
|
|
21603
21833
|
}
|
|
21604
21834
|
|
|
21605
|
-
if (this._responseType) {
|
|
21606
|
-
xhr.responseType = this._responseType;
|
|
21607
|
-
}
|
|
21608
|
-
|
|
21609
21835
|
// send stuff
|
|
21610
21836
|
this.emit('request', this);
|
|
21611
21837
|
|
|
@@ -21615,6 +21841,19 @@ Request.prototype.end = function(fn){
|
|
|
21615
21841
|
return this;
|
|
21616
21842
|
};
|
|
21617
21843
|
|
|
21844
|
+
/**
|
|
21845
|
+
* Faux promise support
|
|
21846
|
+
*
|
|
21847
|
+
* @param {Function} fulfill
|
|
21848
|
+
* @param {Function} reject
|
|
21849
|
+
* @return {Request}
|
|
21850
|
+
*/
|
|
21851
|
+
|
|
21852
|
+
Request.prototype.then = function (fulfill, reject) {
|
|
21853
|
+
return this.end(function(err, res) {
|
|
21854
|
+
err ? reject(err) : fulfill(res);
|
|
21855
|
+
});
|
|
21856
|
+
}
|
|
21618
21857
|
|
|
21619
21858
|
/**
|
|
21620
21859
|
* Expose `Request`.
|
|
@@ -21622,6 +21861,35 @@ Request.prototype.end = function(fn){
|
|
|
21622
21861
|
|
|
21623
21862
|
request.Request = Request;
|
|
21624
21863
|
|
|
21864
|
+
/**
|
|
21865
|
+
* Issue a request:
|
|
21866
|
+
*
|
|
21867
|
+
* Examples:
|
|
21868
|
+
*
|
|
21869
|
+
* request('GET', '/users').end(callback)
|
|
21870
|
+
* request('/users').end(callback)
|
|
21871
|
+
* request('/users', callback)
|
|
21872
|
+
*
|
|
21873
|
+
* @param {String} method
|
|
21874
|
+
* @param {String|Function} url or callback
|
|
21875
|
+
* @return {Request}
|
|
21876
|
+
* @api public
|
|
21877
|
+
*/
|
|
21878
|
+
|
|
21879
|
+
function request(method, url) {
|
|
21880
|
+
// callback
|
|
21881
|
+
if ('function' == typeof url) {
|
|
21882
|
+
return new Request('GET', method).end(url);
|
|
21883
|
+
}
|
|
21884
|
+
|
|
21885
|
+
// url first
|
|
21886
|
+
if (1 == arguments.length) {
|
|
21887
|
+
return new Request('GET', method);
|
|
21888
|
+
}
|
|
21889
|
+
|
|
21890
|
+
return new Request(method, url);
|
|
21891
|
+
}
|
|
21892
|
+
|
|
21625
21893
|
/**
|
|
21626
21894
|
* GET `url` with optional callback `fn(res)`.
|
|
21627
21895
|
*
|
|
@@ -21659,25 +21927,7 @@ request.head = function(url, data, fn){
|
|
|
21659
21927
|
};
|
|
21660
21928
|
|
|
21661
21929
|
/**
|
|
21662
|
-
*
|
|
21663
|
-
*
|
|
21664
|
-
* @param {String} url
|
|
21665
|
-
* @param {Mixed|Function} data or fn
|
|
21666
|
-
* @param {Function} fn
|
|
21667
|
-
* @return {Request}
|
|
21668
|
-
* @api public
|
|
21669
|
-
*/
|
|
21670
|
-
|
|
21671
|
-
request.options = function(url, data, fn){
|
|
21672
|
-
var req = request('OPTIONS', url);
|
|
21673
|
-
if ('function' == typeof data) fn = data, data = null;
|
|
21674
|
-
if (data) req.send(data);
|
|
21675
|
-
if (fn) req.end(fn);
|
|
21676
|
-
return req;
|
|
21677
|
-
};
|
|
21678
|
-
|
|
21679
|
-
/**
|
|
21680
|
-
* DELETE `url` with optional callback `fn(res)`.
|
|
21930
|
+
* DELETE `url` with optional callback `fn(res)`.
|
|
21681
21931
|
*
|
|
21682
21932
|
* @param {String} url
|
|
21683
21933
|
* @param {Function} fn
|
|
@@ -21748,404 +21998,13 @@ request.put = function(url, data, fn){
|
|
|
21748
21998
|
return req;
|
|
21749
21999
|
};
|
|
21750
22000
|
|
|
21751
|
-
},{"./is-object":50,"./request":52,"./request-base":51,"emitter":40,"reduce":47}],50:[function(require,module,exports){
|
|
21752
|
-
/**
|
|
21753
|
-
* Check if `obj` is an object.
|
|
21754
|
-
*
|
|
21755
|
-
* @param {Object} obj
|
|
21756
|
-
* @return {Boolean}
|
|
21757
|
-
* @api private
|
|
21758
|
-
*/
|
|
21759
|
-
|
|
21760
|
-
function isObject(obj) {
|
|
21761
|
-
return null !== obj && 'object' === typeof obj;
|
|
21762
|
-
}
|
|
21763
|
-
|
|
21764
|
-
module.exports = isObject;
|
|
21765
|
-
|
|
21766
|
-
},{}],51:[function(require,module,exports){
|
|
21767
|
-
/**
|
|
21768
|
-
* Module of mixed-in functions shared between node and client code
|
|
21769
|
-
*/
|
|
21770
|
-
var isObject = require('./is-object');
|
|
21771
|
-
|
|
21772
|
-
/**
|
|
21773
|
-
* Clear previous timeout.
|
|
21774
|
-
*
|
|
21775
|
-
* @return {Request} for chaining
|
|
21776
|
-
* @api public
|
|
21777
|
-
*/
|
|
21778
|
-
|
|
21779
|
-
exports.clearTimeout = function _clearTimeout(){
|
|
21780
|
-
this._timeout = 0;
|
|
21781
|
-
clearTimeout(this._timer);
|
|
21782
|
-
return this;
|
|
21783
|
-
};
|
|
21784
|
-
|
|
21785
22001
|
/**
|
|
21786
|
-
*
|
|
21787
|
-
*
|
|
21788
|
-
* This function will be called to convert incoming data into request.body
|
|
21789
|
-
*
|
|
21790
|
-
* @param {Function}
|
|
21791
|
-
* @api public
|
|
21792
|
-
*/
|
|
21793
|
-
|
|
21794
|
-
exports.parse = function parse(fn){
|
|
21795
|
-
this._parser = fn;
|
|
21796
|
-
return this;
|
|
21797
|
-
};
|
|
21798
|
-
|
|
21799
|
-
/**
|
|
21800
|
-
* Override default request body serializer
|
|
21801
|
-
*
|
|
21802
|
-
* This function will be called to convert data set via .send or .attach into payload to send
|
|
21803
|
-
*
|
|
21804
|
-
* @param {Function}
|
|
21805
|
-
* @api public
|
|
21806
|
-
*/
|
|
21807
|
-
|
|
21808
|
-
exports.serialize = function serialize(fn){
|
|
21809
|
-
this._serializer = fn;
|
|
21810
|
-
return this;
|
|
21811
|
-
};
|
|
21812
|
-
|
|
21813
|
-
/**
|
|
21814
|
-
* Set timeout to `ms`.
|
|
21815
|
-
*
|
|
21816
|
-
* @param {Number} ms
|
|
21817
|
-
* @return {Request} for chaining
|
|
21818
|
-
* @api public
|
|
21819
|
-
*/
|
|
21820
|
-
|
|
21821
|
-
exports.timeout = function timeout(ms){
|
|
21822
|
-
this._timeout = ms;
|
|
21823
|
-
return this;
|
|
21824
|
-
};
|
|
21825
|
-
|
|
21826
|
-
/**
|
|
21827
|
-
* Promise support
|
|
21828
|
-
*
|
|
21829
|
-
* @param {Function} resolve
|
|
21830
|
-
* @param {Function} reject
|
|
21831
|
-
* @return {Request}
|
|
21832
|
-
*/
|
|
21833
|
-
|
|
21834
|
-
exports.then = function then(resolve, reject) {
|
|
21835
|
-
if (!this._fullfilledPromise) {
|
|
21836
|
-
var self = this;
|
|
21837
|
-
this._fullfilledPromise = new Promise(function(innerResolve, innerReject){
|
|
21838
|
-
self.end(function(err, res){
|
|
21839
|
-
if (err) innerReject(err); else innerResolve(res);
|
|
21840
|
-
});
|
|
21841
|
-
});
|
|
21842
|
-
}
|
|
21843
|
-
return this._fullfilledPromise.then(resolve, reject);
|
|
21844
|
-
}
|
|
21845
|
-
|
|
21846
|
-
/**
|
|
21847
|
-
* Allow for extension
|
|
21848
|
-
*/
|
|
21849
|
-
|
|
21850
|
-
exports.use = function use(fn) {
|
|
21851
|
-
fn(this);
|
|
21852
|
-
return this;
|
|
21853
|
-
}
|
|
21854
|
-
|
|
21855
|
-
|
|
21856
|
-
/**
|
|
21857
|
-
* Get request header `field`.
|
|
21858
|
-
* Case-insensitive.
|
|
21859
|
-
*
|
|
21860
|
-
* @param {String} field
|
|
21861
|
-
* @return {String}
|
|
21862
|
-
* @api public
|
|
21863
|
-
*/
|
|
21864
|
-
|
|
21865
|
-
exports.get = function(field){
|
|
21866
|
-
return this._header[field.toLowerCase()];
|
|
21867
|
-
};
|
|
21868
|
-
|
|
21869
|
-
/**
|
|
21870
|
-
* Get case-insensitive header `field` value.
|
|
21871
|
-
* This is a deprecated internal API. Use `.get(field)` instead.
|
|
21872
|
-
*
|
|
21873
|
-
* (getHeader is no longer used internally by the superagent code base)
|
|
21874
|
-
*
|
|
21875
|
-
* @param {String} field
|
|
21876
|
-
* @return {String}
|
|
21877
|
-
* @api private
|
|
21878
|
-
* @deprecated
|
|
21879
|
-
*/
|
|
21880
|
-
|
|
21881
|
-
exports.getHeader = exports.get;
|
|
21882
|
-
|
|
21883
|
-
/**
|
|
21884
|
-
* Set header `field` to `val`, or multiple fields with one object.
|
|
21885
|
-
* Case-insensitive.
|
|
21886
|
-
*
|
|
21887
|
-
* Examples:
|
|
21888
|
-
*
|
|
21889
|
-
* req.get('/')
|
|
21890
|
-
* .set('Accept', 'application/json')
|
|
21891
|
-
* .set('X-API-Key', 'foobar')
|
|
21892
|
-
* .end(callback);
|
|
21893
|
-
*
|
|
21894
|
-
* req.get('/')
|
|
21895
|
-
* .set({ Accept: 'application/json', 'X-API-Key': 'foobar' })
|
|
21896
|
-
* .end(callback);
|
|
21897
|
-
*
|
|
21898
|
-
* @param {String|Object} field
|
|
21899
|
-
* @param {String} val
|
|
21900
|
-
* @return {Request} for chaining
|
|
21901
|
-
* @api public
|
|
21902
|
-
*/
|
|
21903
|
-
|
|
21904
|
-
exports.set = function(field, val){
|
|
21905
|
-
if (isObject(field)) {
|
|
21906
|
-
for (var key in field) {
|
|
21907
|
-
this.set(key, field[key]);
|
|
21908
|
-
}
|
|
21909
|
-
return this;
|
|
21910
|
-
}
|
|
21911
|
-
this._header[field.toLowerCase()] = val;
|
|
21912
|
-
this.header[field] = val;
|
|
21913
|
-
return this;
|
|
21914
|
-
};
|
|
21915
|
-
|
|
21916
|
-
/**
|
|
21917
|
-
* Remove header `field`.
|
|
21918
|
-
* Case-insensitive.
|
|
21919
|
-
*
|
|
21920
|
-
* Example:
|
|
21921
|
-
*
|
|
21922
|
-
* req.get('/')
|
|
21923
|
-
* .unset('User-Agent')
|
|
21924
|
-
* .end(callback);
|
|
21925
|
-
*
|
|
21926
|
-
* @param {String} field
|
|
21927
|
-
*/
|
|
21928
|
-
exports.unset = function(field){
|
|
21929
|
-
delete this._header[field.toLowerCase()];
|
|
21930
|
-
delete this.header[field];
|
|
21931
|
-
return this;
|
|
21932
|
-
};
|
|
21933
|
-
|
|
21934
|
-
/**
|
|
21935
|
-
* Write the field `name` and `val` for "multipart/form-data"
|
|
21936
|
-
* request bodies.
|
|
21937
|
-
*
|
|
21938
|
-
* ``` js
|
|
21939
|
-
* request.post('/upload')
|
|
21940
|
-
* .field('foo', 'bar')
|
|
21941
|
-
* .end(callback);
|
|
21942
|
-
* ```
|
|
21943
|
-
*
|
|
21944
|
-
* @param {String} name
|
|
21945
|
-
* @param {String|Blob|File|Buffer|fs.ReadStream} val
|
|
21946
|
-
* @return {Request} for chaining
|
|
21947
|
-
* @api public
|
|
21948
|
-
*/
|
|
21949
|
-
exports.field = function(name, val) {
|
|
21950
|
-
this._getFormData().append(name, val);
|
|
21951
|
-
return this;
|
|
21952
|
-
};
|
|
21953
|
-
|
|
21954
|
-
/**
|
|
21955
|
-
* Abort the request, and clear potential timeout.
|
|
21956
|
-
*
|
|
21957
|
-
* @return {Request}
|
|
21958
|
-
* @api public
|
|
21959
|
-
*/
|
|
21960
|
-
exports.abort = function(){
|
|
21961
|
-
if (this._aborted) {
|
|
21962
|
-
return this;
|
|
21963
|
-
}
|
|
21964
|
-
this._aborted = true;
|
|
21965
|
-
this.xhr && this.xhr.abort(); // browser
|
|
21966
|
-
this.req && this.req.abort(); // node
|
|
21967
|
-
this.clearTimeout();
|
|
21968
|
-
this.emit('abort');
|
|
21969
|
-
return this;
|
|
21970
|
-
};
|
|
21971
|
-
|
|
21972
|
-
/**
|
|
21973
|
-
* Enable transmission of cookies with x-domain requests.
|
|
21974
|
-
*
|
|
21975
|
-
* Note that for this to work the origin must not be
|
|
21976
|
-
* using "Access-Control-Allow-Origin" with a wildcard,
|
|
21977
|
-
* and also must set "Access-Control-Allow-Credentials"
|
|
21978
|
-
* to "true".
|
|
21979
|
-
*
|
|
21980
|
-
* @api public
|
|
21981
|
-
*/
|
|
21982
|
-
|
|
21983
|
-
exports.withCredentials = function(){
|
|
21984
|
-
// This is browser-only functionality. Node side is no-op.
|
|
21985
|
-
this._withCredentials = true;
|
|
21986
|
-
return this;
|
|
21987
|
-
};
|
|
21988
|
-
|
|
21989
|
-
/**
|
|
21990
|
-
* Set the max redirects to `n`. Does noting in browser XHR implementation.
|
|
21991
|
-
*
|
|
21992
|
-
* @param {Number} n
|
|
21993
|
-
* @return {Request} for chaining
|
|
21994
|
-
* @api public
|
|
21995
|
-
*/
|
|
21996
|
-
|
|
21997
|
-
exports.redirects = function(n){
|
|
21998
|
-
this._maxRedirects = n;
|
|
21999
|
-
return this;
|
|
22000
|
-
};
|
|
22001
|
-
|
|
22002
|
-
/**
|
|
22003
|
-
* Convert to a plain javascript object (not JSON string) of scalar properties.
|
|
22004
|
-
* Note as this method is designed to return a useful non-this value,
|
|
22005
|
-
* it cannot be chained.
|
|
22006
|
-
*
|
|
22007
|
-
* @return {Object} describing method, url, and data of this request
|
|
22008
|
-
* @api public
|
|
22009
|
-
*/
|
|
22010
|
-
|
|
22011
|
-
exports.toJSON = function(){
|
|
22012
|
-
return {
|
|
22013
|
-
method: this.method,
|
|
22014
|
-
url: this.url,
|
|
22015
|
-
data: this._data
|
|
22016
|
-
};
|
|
22017
|
-
};
|
|
22018
|
-
|
|
22019
|
-
/**
|
|
22020
|
-
* Check if `obj` is a host object,
|
|
22021
|
-
* we don't want to serialize these :)
|
|
22022
|
-
*
|
|
22023
|
-
* TODO: future proof, move to compoent land
|
|
22024
|
-
*
|
|
22025
|
-
* @param {Object} obj
|
|
22026
|
-
* @return {Boolean}
|
|
22027
|
-
* @api private
|
|
22028
|
-
*/
|
|
22029
|
-
|
|
22030
|
-
exports._isHost = function _isHost(obj) {
|
|
22031
|
-
var str = {}.toString.call(obj);
|
|
22032
|
-
|
|
22033
|
-
switch (str) {
|
|
22034
|
-
case '[object File]':
|
|
22035
|
-
case '[object Blob]':
|
|
22036
|
-
case '[object FormData]':
|
|
22037
|
-
return true;
|
|
22038
|
-
default:
|
|
22039
|
-
return false;
|
|
22040
|
-
}
|
|
22041
|
-
}
|
|
22042
|
-
|
|
22043
|
-
/**
|
|
22044
|
-
* Send `data` as the request body, defaulting the `.type()` to "json" when
|
|
22045
|
-
* an object is given.
|
|
22046
|
-
*
|
|
22047
|
-
* Examples:
|
|
22048
|
-
*
|
|
22049
|
-
* // manual json
|
|
22050
|
-
* request.post('/user')
|
|
22051
|
-
* .type('json')
|
|
22052
|
-
* .send('{"name":"tj"}')
|
|
22053
|
-
* .end(callback)
|
|
22054
|
-
*
|
|
22055
|
-
* // auto json
|
|
22056
|
-
* request.post('/user')
|
|
22057
|
-
* .send({ name: 'tj' })
|
|
22058
|
-
* .end(callback)
|
|
22059
|
-
*
|
|
22060
|
-
* // manual x-www-form-urlencoded
|
|
22061
|
-
* request.post('/user')
|
|
22062
|
-
* .type('form')
|
|
22063
|
-
* .send('name=tj')
|
|
22064
|
-
* .end(callback)
|
|
22065
|
-
*
|
|
22066
|
-
* // auto x-www-form-urlencoded
|
|
22067
|
-
* request.post('/user')
|
|
22068
|
-
* .type('form')
|
|
22069
|
-
* .send({ name: 'tj' })
|
|
22070
|
-
* .end(callback)
|
|
22071
|
-
*
|
|
22072
|
-
* // defaults to x-www-form-urlencoded
|
|
22073
|
-
* request.post('/user')
|
|
22074
|
-
* .send('name=tobi')
|
|
22075
|
-
* .send('species=ferret')
|
|
22076
|
-
* .end(callback)
|
|
22077
|
-
*
|
|
22078
|
-
* @param {String|Object} data
|
|
22079
|
-
* @return {Request} for chaining
|
|
22080
|
-
* @api public
|
|
22081
|
-
*/
|
|
22082
|
-
|
|
22083
|
-
exports.send = function(data){
|
|
22084
|
-
var obj = isObject(data);
|
|
22085
|
-
var type = this._header['content-type'];
|
|
22086
|
-
|
|
22087
|
-
// merge
|
|
22088
|
-
if (obj && isObject(this._data)) {
|
|
22089
|
-
for (var key in data) {
|
|
22090
|
-
this._data[key] = data[key];
|
|
22091
|
-
}
|
|
22092
|
-
} else if ('string' == typeof data) {
|
|
22093
|
-
// default to x-www-form-urlencoded
|
|
22094
|
-
if (!type) this.type('form');
|
|
22095
|
-
type = this._header['content-type'];
|
|
22096
|
-
if ('application/x-www-form-urlencoded' == type) {
|
|
22097
|
-
this._data = this._data
|
|
22098
|
-
? this._data + '&' + data
|
|
22099
|
-
: data;
|
|
22100
|
-
} else {
|
|
22101
|
-
this._data = (this._data || '') + data;
|
|
22102
|
-
}
|
|
22103
|
-
} else {
|
|
22104
|
-
this._data = data;
|
|
22105
|
-
}
|
|
22106
|
-
|
|
22107
|
-
if (!obj || this._isHost(data)) return this;
|
|
22108
|
-
|
|
22109
|
-
// default to json
|
|
22110
|
-
if (!type) this.type('json');
|
|
22111
|
-
return this;
|
|
22112
|
-
};
|
|
22113
|
-
|
|
22114
|
-
},{"./is-object":50}],52:[function(require,module,exports){
|
|
22115
|
-
// The node and browser modules expose versions of this with the
|
|
22116
|
-
// appropriate constructor function bound as first argument
|
|
22117
|
-
/**
|
|
22118
|
-
* Issue a request:
|
|
22119
|
-
*
|
|
22120
|
-
* Examples:
|
|
22121
|
-
*
|
|
22122
|
-
* request('GET', '/users').end(callback)
|
|
22123
|
-
* request('/users').end(callback)
|
|
22124
|
-
* request('/users', callback)
|
|
22125
|
-
*
|
|
22126
|
-
* @param {String} method
|
|
22127
|
-
* @param {String|Function} url or callback
|
|
22128
|
-
* @return {Request}
|
|
22129
|
-
* @api public
|
|
22002
|
+
* Expose `request`.
|
|
22130
22003
|
*/
|
|
22131
22004
|
|
|
22132
|
-
function request(RequestConstructor, method, url) {
|
|
22133
|
-
// callback
|
|
22134
|
-
if ('function' == typeof url) {
|
|
22135
|
-
return new RequestConstructor('GET', method).end(url);
|
|
22136
|
-
}
|
|
22137
|
-
|
|
22138
|
-
// url first
|
|
22139
|
-
if (2 == arguments.length) {
|
|
22140
|
-
return new RequestConstructor('GET', method);
|
|
22141
|
-
}
|
|
22142
|
-
|
|
22143
|
-
return new RequestConstructor(method, url);
|
|
22144
|
-
}
|
|
22145
|
-
|
|
22146
22005
|
module.exports = request;
|
|
22147
22006
|
|
|
22148
|
-
},{}],
|
|
22007
|
+
},{"emitter":40,"reduce":47}],50:[function(require,module,exports){
|
|
22149
22008
|
/*!
|
|
22150
22009
|
* validate.js 0.9.0
|
|
22151
22010
|
*
|