comprodls-sdk 2.61.1 → 2.63.0

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.
@@ -1143,7 +1143,7 @@ validator.validators.contains = function(value, options) {
1143
1143
  }
1144
1144
  }
1145
1145
  };
1146
- },{"./errors":7,"validate.js":50}],10:[function(require,module,exports){
1146
+ },{"./errors":7,"validate.js":53}],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
@@ -6300,9 +6355,6 @@ function createClass(options) {
6300
6355
  //Initializing promise
6301
6356
  var dfd = q.defer();
6302
6357
 
6303
- // Log a dummy message. This is for a dummy commit.
6304
- console.log('This is a test log.');
6305
-
6306
6358
  //Validations
6307
6359
  var err = helpers.validations.isAuthenticated(self.orgId, self.token);
6308
6360
  if(err) {
@@ -12773,6 +12825,7 @@ module.exports = function () {
12773
12825
  var q = require('q');
12774
12826
  var request = require('superagent');
12775
12827
  var helpers = require('../../helpers');
12828
+ var Agent = require('agentkeepalive');
12776
12829
 
12777
12830
  var DLSError = helpers.errors.DLSError;
12778
12831
 
@@ -12780,6 +12833,12 @@ var DLSError = helpers.errors.DLSError;
12780
12833
  * Setting Up Module Entry Point
12781
12834
  **********************************/
12782
12835
  module.exports = rules;
12836
+
12837
+ var keepaliveAgent = new Agent({
12838
+ timeout: 60000,
12839
+ freeSocketTimeout: 30000
12840
+ });
12841
+
12783
12842
  //Rules Adaptor Contsructor
12784
12843
  function rules() {
12785
12844
  return {
@@ -12920,7 +12979,6 @@ function getParticularRule(options) {
12920
12979
  * context: '', // Mandatory
12921
12980
  * ruleType: '', // Mandatory
12922
12981
  * userId: '', // Mandatory
12923
- * mergeGlobalRules:'' // Optional
12924
12982
  * }
12925
12983
  */
12926
12984
  function getUserRule(options) {
@@ -12939,13 +12997,9 @@ function getUserRule(options) {
12939
12997
  userId: options.userId
12940
12998
  });
12941
12999
 
12942
- //Setup request with URL and Params
12943
- var queryParam = { mergeGlobalRules: options.mergeGlobalRules };
12944
-
12945
13000
  var requestAPI = request.get(url)
12946
13001
  .set('Content-Type', 'application/json')
12947
- .set('Accept', 'application/json')
12948
- .query(queryParam);
13002
+ .set('Accept', 'application/json');
12949
13003
 
12950
13004
  if (self.traceid) {
12951
13005
  requestAPI.set('X-Amzn-Trace-Id', self.traceid);
@@ -12954,7 +13008,9 @@ function getUserRule(options) {
12954
13008
  //Setup token in Authorization header
12955
13009
  requestAPI = helpers.api.setupAPIToken(requestAPI, self.token);
12956
13010
 
12957
- requestAPI.end(function (err, response) {
13011
+ requestAPI
13012
+ .agent(keepaliveAgent)
13013
+ .end(function (err, response) {
12958
13014
  if (err) {
12959
13015
  err = new DLSError(helpers.errors.ERROR_TYPES.API_ERROR, err);
12960
13016
  dfd.reject(err);
@@ -13211,7 +13267,7 @@ function deleteRule(options) {
13211
13267
  return dfd.promise;
13212
13268
  }
13213
13269
 
13214
- },{"../../helpers":3,"q":46,"superagent":49}],28:[function(require,module,exports){
13270
+ },{"../../helpers":3,"agentkeepalive":36,"q":46,"superagent":49}],28:[function(require,module,exports){
13215
13271
  /*************************************************************************
13216
13272
  *
13217
13273
  * COMPRO CONFIDENTIAL
@@ -17760,167 +17816,181 @@ module.exports = Array.isArray || function (arr) {
17760
17816
  };
17761
17817
 
17762
17818
  },{}],40:[function(require,module,exports){
17763
-
17764
- /**
17765
- * Expose `Emitter`.
17766
- */
17767
-
17768
- module.exports = Emitter;
17769
-
17770
- /**
17771
- * Initialize a new `Emitter`.
17772
- *
17773
- * @api public
17774
- */
17775
-
17776
- function Emitter(obj) {
17777
- if (obj) return mixin(obj);
17778
- };
17779
-
17780
- /**
17781
- * Mixin the emitter properties.
17782
- *
17783
- * @param {Object} obj
17784
- * @return {Object}
17785
- * @api private
17786
- */
17787
-
17788
- function mixin(obj) {
17789
- for (var key in Emitter.prototype) {
17790
- obj[key] = Emitter.prototype[key];
17791
- }
17792
- return obj;
17793
- }
17794
-
17795
- /**
17796
- * Listen on the given `event` with `fn`.
17797
- *
17798
- * @param {String} event
17799
- * @param {Function} fn
17800
- * @return {Emitter}
17801
- * @api public
17802
- */
17803
-
17804
- Emitter.prototype.on =
17805
- Emitter.prototype.addEventListener = function(event, fn){
17806
- this._callbacks = this._callbacks || {};
17807
- (this._callbacks['$' + event] = this._callbacks['$' + event] || [])
17808
- .push(fn);
17809
- return this;
17810
- };
17811
-
17812
- /**
17813
- * Adds an `event` listener that will be invoked a single
17814
- * time then automatically removed.
17815
- *
17816
- * @param {String} event
17817
- * @param {Function} fn
17818
- * @return {Emitter}
17819
- * @api public
17820
- */
17821
-
17822
- Emitter.prototype.once = function(event, fn){
17823
- function on() {
17824
- this.off(event, on);
17825
- fn.apply(this, arguments);
17826
- }
17827
-
17828
- on.fn = fn;
17829
- this.on(event, on);
17830
- return this;
17831
- };
17832
-
17833
- /**
17834
- * Remove the given callback for `event` or all
17835
- * registered callbacks.
17836
- *
17837
- * @param {String} event
17838
- * @param {Function} fn
17839
- * @return {Emitter}
17840
- * @api public
17841
- */
17842
-
17843
- Emitter.prototype.off =
17844
- Emitter.prototype.removeListener =
17845
- Emitter.prototype.removeAllListeners =
17846
- Emitter.prototype.removeEventListener = function(event, fn){
17847
- this._callbacks = this._callbacks || {};
17848
-
17849
- // all
17850
- if (0 == arguments.length) {
17851
- this._callbacks = {};
17852
- return this;
17853
- }
17854
-
17855
- // specific event
17856
- var callbacks = this._callbacks['$' + event];
17857
- if (!callbacks) return this;
17858
-
17859
- // remove all handlers
17860
- if (1 == arguments.length) {
17861
- delete this._callbacks['$' + event];
17862
- return this;
17863
- }
17864
-
17865
- // remove specific handler
17866
- var cb;
17867
- for (var i = 0; i < callbacks.length; i++) {
17868
- cb = callbacks[i];
17869
- if (cb === fn || cb.fn === fn) {
17870
- callbacks.splice(i, 1);
17871
- break;
17872
- }
17873
- }
17874
- return this;
17875
- };
17876
-
17877
- /**
17878
- * Emit `event` with the given args.
17879
- *
17880
- * @param {String} event
17881
- * @param {Mixed} ...
17882
- * @return {Emitter}
17883
- */
17884
-
17885
- Emitter.prototype.emit = function(event){
17886
- this._callbacks = this._callbacks || {};
17887
- var args = [].slice.call(arguments, 1)
17888
- , callbacks = this._callbacks['$' + event];
17889
-
17890
- if (callbacks) {
17891
- callbacks = callbacks.slice(0);
17892
- for (var i = 0, len = callbacks.length; i < len; ++i) {
17893
- callbacks[i].apply(this, args);
17894
- }
17895
- }
17896
-
17897
- return this;
17898
- };
17899
-
17900
- /**
17901
- * Return array of callbacks for `event`.
17902
- *
17903
- * @param {String} event
17904
- * @return {Array}
17905
- * @api public
17906
- */
17907
-
17908
- Emitter.prototype.listeners = function(event){
17909
- this._callbacks = this._callbacks || {};
17910
- return this._callbacks['$' + event] || [];
17911
- };
17912
-
17913
- /**
17914
- * Check if this emitter has `event` handlers.
17915
- *
17916
- * @param {String} event
17917
- * @return {Boolean}
17918
- * @api public
17919
- */
17920
-
17921
- Emitter.prototype.hasListeners = function(event){
17922
- return !! this.listeners(event).length;
17923
- };
17819
+
17820
+ /**
17821
+ * Expose `Emitter`.
17822
+ */
17823
+
17824
+ if (typeof module !== 'undefined') {
17825
+ module.exports = Emitter;
17826
+ }
17827
+
17828
+ /**
17829
+ * Initialize a new `Emitter`.
17830
+ *
17831
+ * @api public
17832
+ */
17833
+
17834
+ function Emitter(obj) {
17835
+ if (obj) return mixin(obj);
17836
+ };
17837
+
17838
+ /**
17839
+ * Mixin the emitter properties.
17840
+ *
17841
+ * @param {Object} obj
17842
+ * @return {Object}
17843
+ * @api private
17844
+ */
17845
+
17846
+ function mixin(obj) {
17847
+ for (var key in Emitter.prototype) {
17848
+ obj[key] = Emitter.prototype[key];
17849
+ }
17850
+ return obj;
17851
+ }
17852
+
17853
+ /**
17854
+ * Listen on the given `event` with `fn`.
17855
+ *
17856
+ * @param {String} event
17857
+ * @param {Function} fn
17858
+ * @return {Emitter}
17859
+ * @api public
17860
+ */
17861
+
17862
+ Emitter.prototype.on =
17863
+ Emitter.prototype.addEventListener = function(event, fn){
17864
+ this._callbacks = this._callbacks || {};
17865
+ (this._callbacks['$' + event] = this._callbacks['$' + event] || [])
17866
+ .push(fn);
17867
+ return this;
17868
+ };
17869
+
17870
+ /**
17871
+ * Adds an `event` listener that will be invoked a single
17872
+ * time then automatically removed.
17873
+ *
17874
+ * @param {String} event
17875
+ * @param {Function} fn
17876
+ * @return {Emitter}
17877
+ * @api public
17878
+ */
17879
+
17880
+ Emitter.prototype.once = function(event, fn){
17881
+ function on() {
17882
+ this.off(event, on);
17883
+ fn.apply(this, arguments);
17884
+ }
17885
+
17886
+ on.fn = fn;
17887
+ this.on(event, on);
17888
+ return this;
17889
+ };
17890
+
17891
+ /**
17892
+ * Remove the given callback for `event` or all
17893
+ * registered callbacks.
17894
+ *
17895
+ * @param {String} event
17896
+ * @param {Function} fn
17897
+ * @return {Emitter}
17898
+ * @api public
17899
+ */
17900
+
17901
+ Emitter.prototype.off =
17902
+ Emitter.prototype.removeListener =
17903
+ Emitter.prototype.removeAllListeners =
17904
+ Emitter.prototype.removeEventListener = function(event, fn){
17905
+ this._callbacks = this._callbacks || {};
17906
+
17907
+ // all
17908
+ if (0 == arguments.length) {
17909
+ this._callbacks = {};
17910
+ return this;
17911
+ }
17912
+
17913
+ // specific event
17914
+ var callbacks = this._callbacks['$' + event];
17915
+ if (!callbacks) return this;
17916
+
17917
+ // remove all handlers
17918
+ if (1 == arguments.length) {
17919
+ delete this._callbacks['$' + event];
17920
+ return this;
17921
+ }
17922
+
17923
+ // remove specific handler
17924
+ var cb;
17925
+ for (var i = 0; i < callbacks.length; i++) {
17926
+ cb = callbacks[i];
17927
+ if (cb === fn || cb.fn === fn) {
17928
+ callbacks.splice(i, 1);
17929
+ break;
17930
+ }
17931
+ }
17932
+
17933
+ // Remove event specific arrays for event types that no
17934
+ // one is subscribed for to avoid memory leak.
17935
+ if (callbacks.length === 0) {
17936
+ delete this._callbacks['$' + event];
17937
+ }
17938
+
17939
+ return this;
17940
+ };
17941
+
17942
+ /**
17943
+ * Emit `event` with the given args.
17944
+ *
17945
+ * @param {String} event
17946
+ * @param {Mixed} ...
17947
+ * @return {Emitter}
17948
+ */
17949
+
17950
+ Emitter.prototype.emit = function(event){
17951
+ this._callbacks = this._callbacks || {};
17952
+
17953
+ var args = new Array(arguments.length - 1)
17954
+ , callbacks = this._callbacks['$' + event];
17955
+
17956
+ for (var i = 1; i < arguments.length; i++) {
17957
+ args[i - 1] = arguments[i];
17958
+ }
17959
+
17960
+ if (callbacks) {
17961
+ callbacks = callbacks.slice(0);
17962
+ for (var i = 0, len = callbacks.length; i < len; ++i) {
17963
+ callbacks[i].apply(this, args);
17964
+ }
17965
+ }
17966
+
17967
+ return this;
17968
+ };
17969
+
17970
+ /**
17971
+ * Return array of callbacks for `event`.
17972
+ *
17973
+ * @param {String} event
17974
+ * @return {Array}
17975
+ * @api public
17976
+ */
17977
+
17978
+ Emitter.prototype.listeners = function(event){
17979
+ this._callbacks = this._callbacks || {};
17980
+ return this._callbacks['$' + event] || [];
17981
+ };
17982
+
17983
+ /**
17984
+ * Check if this emitter has `event` handlers.
17985
+ *
17986
+ * @param {String} event
17987
+ * @return {Boolean}
17988
+ * @api public
17989
+ */
17990
+
17991
+ Emitter.prototype.hasListeners = function(event){
17992
+ return !! this.listeners(event).length;
17993
+ };
17924
17994
 
17925
17995
  },{}],41:[function(require,module,exports){
17926
17996
  // Copyright Joyent, Inc. and other Node contributors.
@@ -18226,6 +18296,8 @@ function isUndefined(arg) {
18226
18296
  }
18227
18297
 
18228
18298
  },{}],42:[function(require,module,exports){
18299
+ 'use strict';
18300
+
18229
18301
  var hasOwn = Object.prototype.hasOwnProperty;
18230
18302
  var toStr = Object.prototype.toString;
18231
18303
  var defineProperty = Object.defineProperty;
@@ -18240,8 +18312,6 @@ var isArray = function isArray(arr) {
18240
18312
  };
18241
18313
 
18242
18314
  var isPlainObject = function isPlainObject(obj) {
18243
- 'use strict';
18244
-
18245
18315
  if (!obj || toStr.call(obj) !== '[object Object]') {
18246
18316
  return false;
18247
18317
  }
@@ -18291,8 +18361,6 @@ var getProperty = function getProperty(obj, name) {
18291
18361
  };
18292
18362
 
18293
18363
  module.exports = function extend() {
18294
- 'use strict';
18295
-
18296
18364
  var options, name, src, copy, copyIsArray, clone;
18297
18365
  var target = arguments[0];
18298
18366
  var i = 1;
@@ -20762,6 +20830,8 @@ function template(string) {
20762
20830
 
20763
20831
  var Emitter = require('emitter');
20764
20832
  var reduce = require('reduce');
20833
+ var requestBase = require('./request-base');
20834
+ var isObject = require('./is-object');
20765
20835
 
20766
20836
  /**
20767
20837
  * Root reference for iframes.
@@ -20783,28 +20853,10 @@ if (typeof window !== 'undefined') { // Browser window
20783
20853
  function noop(){};
20784
20854
 
20785
20855
  /**
20786
- * Check if `obj` is a host object,
20787
- * we don't want to serialize these :)
20788
- *
20789
- * TODO: future proof, move to compoent land
20790
- *
20791
- * @param {Object} obj
20792
- * @return {Boolean}
20793
- * @api private
20856
+ * Expose `request`.
20794
20857
  */
20795
20858
 
20796
- function isHost(obj) {
20797
- var str = {}.toString.call(obj);
20798
-
20799
- switch (str) {
20800
- case '[object File]':
20801
- case '[object Blob]':
20802
- case '[object FormData]':
20803
- return true;
20804
- default:
20805
- return false;
20806
- }
20807
- }
20859
+ var request = module.exports = require('./request').bind(null, Request);
20808
20860
 
20809
20861
  /**
20810
20862
  * Determine XHR.
@@ -20837,22 +20889,10 @@ var trim = ''.trim
20837
20889
  : function(s) { return s.replace(/(^\s*|\s*$)/g, ''); };
20838
20890
 
20839
20891
  /**
20840
- * Check if `obj` is an object.
20892
+ * Serialize the given `obj`.
20841
20893
  *
20842
20894
  * @param {Object} obj
20843
- * @return {Boolean}
20844
- * @api private
20845
- */
20846
-
20847
- function isObject(obj) {
20848
- return obj === Object(obj);
20849
- }
20850
-
20851
- /**
20852
- * Serialize the given `obj`.
20853
- *
20854
- * @param {Object} obj
20855
- * @return {String}
20895
+ * @return {String}
20856
20896
  * @api private
20857
20897
  */
20858
20898
 
@@ -20862,8 +20902,8 @@ function serialize(obj) {
20862
20902
  for (var key in obj) {
20863
20903
  if (null != obj[key]) {
20864
20904
  pushEncodedKeyValuePair(pairs, key, obj[key]);
20865
- }
20866
- }
20905
+ }
20906
+ }
20867
20907
  return pairs.join('&');
20868
20908
  }
20869
20909
 
@@ -20881,6 +20921,11 @@ function pushEncodedKeyValuePair(pairs, key, val) {
20881
20921
  return val.forEach(function(v) {
20882
20922
  pushEncodedKeyValuePair(pairs, key, v);
20883
20923
  });
20924
+ } else if (isObject(val)) {
20925
+ for(var subkey in val) {
20926
+ pushEncodedKeyValuePair(pairs, key + '[' + subkey + ']', val[subkey]);
20927
+ }
20928
+ return;
20884
20929
  }
20885
20930
  pairs.push(encodeURIComponent(key)
20886
20931
  + '=' + encodeURIComponent(val));
@@ -20903,13 +20948,18 @@ function pushEncodedKeyValuePair(pairs, key, val) {
20903
20948
  function parseString(str) {
20904
20949
  var obj = {};
20905
20950
  var pairs = str.split('&');
20906
- var parts;
20907
20951
  var pair;
20952
+ var pos;
20908
20953
 
20909
20954
  for (var i = 0, len = pairs.length; i < len; ++i) {
20910
20955
  pair = pairs[i];
20911
- parts = pair.split('=');
20912
- obj[decodeURIComponent(parts[0])] = decodeURIComponent(parts[1]);
20956
+ pos = pair.indexOf('=');
20957
+ if (pos == -1) {
20958
+ obj[decodeURIComponent(pair)] = '';
20959
+ } else {
20960
+ obj[decodeURIComponent(pair.slice(0, pos))] =
20961
+ decodeURIComponent(pair.slice(pos + 1));
20962
+ }
20913
20963
  }
20914
20964
 
20915
20965
  return obj;
@@ -21093,15 +21143,15 @@ function Response(req, options) {
21093
21143
  ? this.xhr.responseText
21094
21144
  : null;
21095
21145
  this.statusText = this.req.xhr.statusText;
21096
- this.setStatusProperties(this.xhr.status);
21146
+ this._setStatusProperties(this.xhr.status);
21097
21147
  this.header = this.headers = parseHeader(this.xhr.getAllResponseHeaders());
21098
21148
  // getAllResponseHeaders sometimes falsely returns "" for CORS requests, but
21099
21149
  // getResponseHeader still works. so we get content-type even if getting
21100
21150
  // other headers fails.
21101
21151
  this.header['content-type'] = this.xhr.getResponseHeader('content-type');
21102
- this.setHeaderProperties(this.header);
21152
+ this._setHeaderProperties(this.header);
21103
21153
  this.body = this.req.method != 'HEAD'
21104
- ? this.parseBody(this.text ? this.text : this.xhr.response)
21154
+ ? this._parseBody(this.text ? this.text : this.xhr.response)
21105
21155
  : null;
21106
21156
  }
21107
21157
 
@@ -21129,7 +21179,7 @@ Response.prototype.get = function(field){
21129
21179
  * @api private
21130
21180
  */
21131
21181
 
21132
- Response.prototype.setHeaderProperties = function(header){
21182
+ Response.prototype._setHeaderProperties = function(header){
21133
21183
  // content-type
21134
21184
  var ct = this.header['content-type'] || '';
21135
21185
  this.type = type(ct);
@@ -21150,8 +21200,11 @@ Response.prototype.setHeaderProperties = function(header){
21150
21200
  * @api private
21151
21201
  */
21152
21202
 
21153
- Response.prototype.parseBody = function(str){
21203
+ Response.prototype._parseBody = function(str){
21154
21204
  var parse = request.parse[this.type];
21205
+ if (!parse && isJSON(this.type)) {
21206
+ parse = request.parse['application/json'];
21207
+ }
21155
21208
  return parse && str && (str.length || str instanceof Object)
21156
21209
  ? parse(str)
21157
21210
  : null;
@@ -21178,7 +21231,7 @@ Response.prototype.parseBody = function(str){
21178
21231
  * @api private
21179
21232
  */
21180
21233
 
21181
- Response.prototype.setStatusProperties = function(status){
21234
+ Response.prototype._setStatusProperties = function(status){
21182
21235
  // handle IE9 bug: http://stackoverflow.com/questions/10046972/msie-returns-status-code-of-1223-for-ajax-request
21183
21236
  if (status === 1223) {
21184
21237
  status = 204;
@@ -21246,12 +21299,11 @@ request.Response = Response;
21246
21299
 
21247
21300
  function Request(method, url) {
21248
21301
  var self = this;
21249
- Emitter.call(this);
21250
21302
  this._query = this._query || [];
21251
21303
  this.method = method;
21252
21304
  this.url = url;
21253
- this.header = {};
21254
- this._header = {};
21305
+ this.header = {}; // preserves header name case
21306
+ this._header = {}; // coerces header names to lowercase
21255
21307
  this.on('end', function(){
21256
21308
  var err = null;
21257
21309
  var res = null;
@@ -21264,6 +21316,8 @@ function Request(method, url) {
21264
21316
  err.original = e;
21265
21317
  // issue #675: return the raw response if the response parsing fails
21266
21318
  err.rawResponse = self.xhr && self.xhr.responseText ? self.xhr.responseText : null;
21319
+ // issue #876: return the http status code if the response parsing fails
21320
+ err.statusCode = self.xhr && self.xhr.status ? self.xhr.status : null;
21267
21321
  return self.callback(err);
21268
21322
  }
21269
21323
 
@@ -21273,140 +21327,32 @@ function Request(method, url) {
21273
21327
  return self.callback(err, res);
21274
21328
  }
21275
21329
 
21276
- if (res.status >= 200 && res.status < 300) {
21277
- return self.callback(err, res);
21278
- }
21330
+ try {
21331
+ if (res.status >= 200 && res.status < 300) {
21332
+ return self.callback(err, res);
21333
+ }
21279
21334
 
21280
- var new_err = new Error(res.statusText || 'Unsuccessful HTTP response');
21281
- new_err.original = err;
21282
- new_err.response = res;
21283
- new_err.status = res.status;
21335
+ var new_err = new Error(res.statusText || 'Unsuccessful HTTP response');
21336
+ new_err.original = err;
21337
+ new_err.response = res;
21338
+ new_err.status = res.status;
21284
21339
 
21285
- self.callback(new_err, res);
21340
+ self.callback(new_err, res);
21341
+ } catch(e) {
21342
+ self.callback(e); // #985 touching res may cause INVALID_STATE_ERR on old Android
21343
+ }
21286
21344
  });
21287
21345
  }
21288
21346
 
21289
21347
  /**
21290
- * Mixin `Emitter`.
21348
+ * Mixin `Emitter` and `requestBase`.
21291
21349
  */
21292
21350
 
21293
21351
  Emitter(Request.prototype);
21294
-
21295
- /**
21296
- * Allow for extension
21297
- */
21298
-
21299
- Request.prototype.use = function(fn) {
21300
- fn(this);
21301
- return this;
21352
+ for (var key in requestBase) {
21353
+ Request.prototype[key] = requestBase[key];
21302
21354
  }
21303
21355
 
21304
- /**
21305
- * Set timeout to `ms`.
21306
- *
21307
- * @param {Number} ms
21308
- * @return {Request} for chaining
21309
- * @api public
21310
- */
21311
-
21312
- Request.prototype.timeout = function(ms){
21313
- this._timeout = ms;
21314
- return this;
21315
- };
21316
-
21317
- /**
21318
- * Clear previous timeout.
21319
- *
21320
- * @return {Request} for chaining
21321
- * @api public
21322
- */
21323
-
21324
- Request.prototype.clearTimeout = function(){
21325
- this._timeout = 0;
21326
- clearTimeout(this._timer);
21327
- return this;
21328
- };
21329
-
21330
- /**
21331
- * Abort the request, and clear potential timeout.
21332
- *
21333
- * @return {Request}
21334
- * @api public
21335
- */
21336
-
21337
- Request.prototype.abort = function(){
21338
- if (this.aborted) return;
21339
- this.aborted = true;
21340
- this.xhr.abort();
21341
- this.clearTimeout();
21342
- this.emit('abort');
21343
- return this;
21344
- };
21345
-
21346
- /**
21347
- * Set header `field` to `val`, or multiple fields with one object.
21348
- *
21349
- * Examples:
21350
- *
21351
- * req.get('/')
21352
- * .set('Accept', 'application/json')
21353
- * .set('X-API-Key', 'foobar')
21354
- * .end(callback);
21355
- *
21356
- * req.get('/')
21357
- * .set({ Accept: 'application/json', 'X-API-Key': 'foobar' })
21358
- * .end(callback);
21359
- *
21360
- * @param {String|Object} field
21361
- * @param {String} val
21362
- * @return {Request} for chaining
21363
- * @api public
21364
- */
21365
-
21366
- Request.prototype.set = function(field, val){
21367
- if (isObject(field)) {
21368
- for (var key in field) {
21369
- this.set(key, field[key]);
21370
- }
21371
- return this;
21372
- }
21373
- this._header[field.toLowerCase()] = val;
21374
- this.header[field] = val;
21375
- return this;
21376
- };
21377
-
21378
- /**
21379
- * Remove header `field`.
21380
- *
21381
- * Example:
21382
- *
21383
- * req.get('/')
21384
- * .unset('User-Agent')
21385
- * .end(callback);
21386
- *
21387
- * @param {String} field
21388
- * @return {Request} for chaining
21389
- * @api public
21390
- */
21391
-
21392
- Request.prototype.unset = function(field){
21393
- delete this._header[field.toLowerCase()];
21394
- delete this.header[field];
21395
- return this;
21396
- };
21397
-
21398
- /**
21399
- * Get case-insensitive header `field` value.
21400
- *
21401
- * @param {String} field
21402
- * @return {String}
21403
- * @api private
21404
- */
21405
-
21406
- Request.prototype.getHeader = function(field){
21407
- return this._header[field.toLowerCase()];
21408
- };
21409
-
21410
21356
  /**
21411
21357
  * Set Content-Type to `type`, mapping values from `request.types`.
21412
21358
  *
@@ -21435,16 +21381,22 @@ Request.prototype.type = function(type){
21435
21381
  };
21436
21382
 
21437
21383
  /**
21438
- * Force given parser
21384
+ * Set responseType to `val`. Presently valid responseTypes are 'blob' and
21385
+ * 'arraybuffer'.
21439
21386
  *
21440
- * Sets the body parser no matter type.
21387
+ * Examples:
21441
21388
  *
21442
- * @param {Function}
21389
+ * req.get('/')
21390
+ * .responseType('blob')
21391
+ * .end(callback);
21392
+ *
21393
+ * @param {String} val
21394
+ * @return {Request} for chaining
21443
21395
  * @api public
21444
21396
  */
21445
21397
 
21446
- Request.prototype.parse = function(fn){
21447
- this._parser = fn;
21398
+ Request.prototype.responseType = function(val){
21399
+ this._responseType = val;
21448
21400
  return this;
21449
21401
  };
21450
21402
 
@@ -21478,13 +21430,29 @@ Request.prototype.accept = function(type){
21478
21430
  *
21479
21431
  * @param {String} user
21480
21432
  * @param {String} pass
21433
+ * @param {Object} options with 'type' property 'auto' or 'basic' (default 'basic')
21481
21434
  * @return {Request} for chaining
21482
21435
  * @api public
21483
21436
  */
21484
21437
 
21485
- Request.prototype.auth = function(user, pass){
21486
- var str = btoa(user + ':' + pass);
21487
- this.set('Authorization', 'Basic ' + str);
21438
+ Request.prototype.auth = function(user, pass, options){
21439
+ if (!options) {
21440
+ options = {
21441
+ type: 'basic'
21442
+ }
21443
+ }
21444
+
21445
+ switch (options.type) {
21446
+ case 'basic':
21447
+ var str = btoa(user + ':' + pass);
21448
+ this.set('Authorization', 'Basic ' + str);
21449
+ break;
21450
+
21451
+ case 'auto':
21452
+ this.username = user;
21453
+ this.password = pass;
21454
+ break;
21455
+ }
21488
21456
  return this;
21489
21457
  };
21490
21458
 
@@ -21508,35 +21476,13 @@ Request.prototype.query = function(val){
21508
21476
  return this;
21509
21477
  };
21510
21478
 
21511
- /**
21512
- * Write the field `name` and `val` for "multipart/form-data"
21513
- * request bodies.
21514
- *
21515
- * ``` js
21516
- * request.post('/upload')
21517
- * .field('foo', 'bar')
21518
- * .end(callback);
21519
- * ```
21520
- *
21521
- * @param {String} name
21522
- * @param {String|Blob|File} val
21523
- * @return {Request} for chaining
21524
- * @api public
21525
- */
21526
-
21527
- Request.prototype.field = function(name, val){
21528
- if (!this._formData) this._formData = new root.FormData();
21529
- this._formData.append(name, val);
21530
- return this;
21531
- };
21532
-
21533
21479
  /**
21534
21480
  * Queue the given `file` as an attachment to the specified `field`,
21535
21481
  * with optional `filename`.
21536
21482
  *
21537
21483
  * ``` js
21538
21484
  * request.post('/upload')
21539
- * .attach(new Blob(['<a id="a"><b id="b">hey!</b></a>'], { type: "text/html"}))
21485
+ * .attach('content', new Blob(['<a id="a"><b id="b">hey!</b></a>'], { type: "text/html"}))
21540
21486
  * .end(callback);
21541
21487
  * ```
21542
21488
  *
@@ -21548,77 +21494,15 @@ Request.prototype.field = function(name, val){
21548
21494
  */
21549
21495
 
21550
21496
  Request.prototype.attach = function(field, file, filename){
21551
- if (!this._formData) this._formData = new root.FormData();
21552
- this._formData.append(field, file, filename || file.name);
21497
+ this._getFormData().append(field, file, filename || file.name);
21553
21498
  return this;
21554
21499
  };
21555
21500
 
21556
- /**
21557
- * Send `data` as the request body, defaulting the `.type()` to "json" when
21558
- * an object is given.
21559
- *
21560
- * Examples:
21561
- *
21562
- * // manual json
21563
- * request.post('/user')
21564
- * .type('json')
21565
- * .send('{"name":"tj"}')
21566
- * .end(callback)
21567
- *
21568
- * // auto json
21569
- * request.post('/user')
21570
- * .send({ name: 'tj' })
21571
- * .end(callback)
21572
- *
21573
- * // manual x-www-form-urlencoded
21574
- * request.post('/user')
21575
- * .type('form')
21576
- * .send('name=tj')
21577
- * .end(callback)
21578
- *
21579
- * // auto x-www-form-urlencoded
21580
- * request.post('/user')
21581
- * .type('form')
21582
- * .send({ name: 'tj' })
21583
- * .end(callback)
21584
- *
21585
- * // defaults to x-www-form-urlencoded
21586
- * request.post('/user')
21587
- * .send('name=tobi')
21588
- * .send('species=ferret')
21589
- * .end(callback)
21590
- *
21591
- * @param {String|Object} data
21592
- * @return {Request} for chaining
21593
- * @api public
21594
- */
21595
-
21596
- Request.prototype.send = function(data){
21597
- var obj = isObject(data);
21598
- var type = this.getHeader('Content-Type');
21599
-
21600
- // merge
21601
- if (obj && isObject(this._data)) {
21602
- for (var key in data) {
21603
- this._data[key] = data[key];
21604
- }
21605
- } else if ('string' == typeof data) {
21606
- if (!type) this.type('form');
21607
- type = this.getHeader('Content-Type');
21608
- if ('application/x-www-form-urlencoded' == type) {
21609
- this._data = this._data
21610
- ? this._data + '&' + data
21611
- : data;
21612
- } else {
21613
- this._data = (this._data || '') + data;
21614
- }
21615
- } else {
21616
- this._data = data;
21501
+ Request.prototype._getFormData = function(){
21502
+ if (!this._formData) {
21503
+ this._formData = new root.FormData();
21617
21504
  }
21618
-
21619
- if (!obj || isHost(data)) return this;
21620
- if (!type) this.type('json');
21621
- return this;
21505
+ return this._formData;
21622
21506
  };
21623
21507
 
21624
21508
  /**
@@ -21659,7 +21543,7 @@ Request.prototype.crossDomainError = function(){
21659
21543
  * @api private
21660
21544
  */
21661
21545
 
21662
- Request.prototype.timeoutError = function(){
21546
+ Request.prototype._timeoutError = function(){
21663
21547
  var timeout = this._timeout;
21664
21548
  var err = new Error('timeout of ' + timeout + 'ms exceeded');
21665
21549
  err.timeout = timeout;
@@ -21667,19 +21551,18 @@ Request.prototype.timeoutError = function(){
21667
21551
  };
21668
21552
 
21669
21553
  /**
21670
- * Enable transmission of cookies with x-domain requests.
21671
- *
21672
- * Note that for this to work the origin must not be
21673
- * using "Access-Control-Allow-Origin" with a wildcard,
21674
- * and also must set "Access-Control-Allow-Credentials"
21675
- * to "true".
21554
+ * Compose querystring to append to req.url
21676
21555
  *
21677
- * @api public
21556
+ * @api private
21678
21557
  */
21679
21558
 
21680
- Request.prototype.withCredentials = function(){
21681
- this._withCredentials = true;
21682
- return this;
21559
+ Request.prototype._appendQueryString = function(){
21560
+ var query = this._query.join('&');
21561
+ if (query) {
21562
+ this.url += ~this.url.indexOf('?')
21563
+ ? '&' + query
21564
+ : '?' + query;
21565
+ }
21683
21566
  };
21684
21567
 
21685
21568
  /**
@@ -21694,7 +21577,6 @@ Request.prototype.withCredentials = function(){
21694
21577
  Request.prototype.end = function(fn){
21695
21578
  var self = this;
21696
21579
  var xhr = this.xhr = request.getXHR();
21697
- var query = this._query.join('&');
21698
21580
  var timeout = this._timeout;
21699
21581
  var data = this._formData || this._data;
21700
21582
 
@@ -21711,8 +21593,8 @@ Request.prototype.end = function(fn){
21711
21593
  try { status = xhr.status } catch(e) { status = 0; }
21712
21594
 
21713
21595
  if (0 == status) {
21714
- if (self.timedout) return self.timeoutError();
21715
- if (self.aborted) return;
21596
+ if (self.timedout) return self._timeoutError();
21597
+ if (self._aborted) return;
21716
21598
  return self.crossDomainError();
21717
21599
  }
21718
21600
  self.emit('end');
@@ -21748,24 +21630,23 @@ Request.prototype.end = function(fn){
21748
21630
  }
21749
21631
 
21750
21632
  // querystring
21751
- if (query) {
21752
- query = request.serializeObject(query);
21753
- this.url += ~this.url.indexOf('?')
21754
- ? '&' + query
21755
- : '?' + query;
21756
- }
21633
+ this._appendQueryString();
21757
21634
 
21758
21635
  // initiate request
21759
- xhr.open(this.method, this.url, true);
21636
+ if (this.username && this.password) {
21637
+ xhr.open(this.method, this.url, true, this.username, this.password);
21638
+ } else {
21639
+ xhr.open(this.method, this.url, true);
21640
+ }
21760
21641
 
21761
21642
  // CORS
21762
21643
  if (this._withCredentials) xhr.withCredentials = true;
21763
21644
 
21764
21645
  // body
21765
- if ('GET' != this.method && 'HEAD' != this.method && 'string' != typeof data && !isHost(data)) {
21646
+ if ('GET' != this.method && 'HEAD' != this.method && 'string' != typeof data && !this._isHost(data)) {
21766
21647
  // serialize stuff
21767
- var contentType = this.getHeader('Content-Type');
21768
- var serialize = this._parser || request.serialize[contentType ? contentType.split(';')[0] : ''];
21648
+ var contentType = this._header['content-type'];
21649
+ var serialize = this._serializer || request.serialize[contentType ? contentType.split(';')[0] : ''];
21769
21650
  if (!serialize && isJSON(contentType)) serialize = request.serialize['application/json'];
21770
21651
  if (serialize) data = serialize(data);
21771
21652
  }
@@ -21776,6 +21657,10 @@ Request.prototype.end = function(fn){
21776
21657
  xhr.setRequestHeader(field, this.header[field]);
21777
21658
  }
21778
21659
 
21660
+ if (this._responseType) {
21661
+ xhr.responseType = this._responseType;
21662
+ }
21663
+
21779
21664
  // send stuff
21780
21665
  this.emit('request', this);
21781
21666
 
@@ -21785,19 +21670,6 @@ Request.prototype.end = function(fn){
21785
21670
  return this;
21786
21671
  };
21787
21672
 
21788
- /**
21789
- * Faux promise support
21790
- *
21791
- * @param {Function} fulfill
21792
- * @param {Function} reject
21793
- * @return {Request}
21794
- */
21795
-
21796
- Request.prototype.then = function (fulfill, reject) {
21797
- return this.end(function(err, res) {
21798
- err ? reject(err) : fulfill(res);
21799
- });
21800
- }
21801
21673
 
21802
21674
  /**
21803
21675
  * Expose `Request`.
@@ -21806,36 +21678,25 @@ Request.prototype.then = function (fulfill, reject) {
21806
21678
  request.Request = Request;
21807
21679
 
21808
21680
  /**
21809
- * Issue a request:
21810
- *
21811
- * Examples:
21812
- *
21813
- * request('GET', '/users').end(callback)
21814
- * request('/users').end(callback)
21815
- * request('/users', callback)
21681
+ * GET `url` with optional callback `fn(res)`.
21816
21682
  *
21817
- * @param {String} method
21818
- * @param {String|Function} url or callback
21683
+ * @param {String} url
21684
+ * @param {Mixed|Function} data or fn
21685
+ * @param {Function} fn
21819
21686
  * @return {Request}
21820
21687
  * @api public
21821
21688
  */
21822
21689
 
21823
- function request(method, url) {
21824
- // callback
21825
- if ('function' == typeof url) {
21826
- return new Request('GET', method).end(url);
21827
- }
21828
-
21829
- // url first
21830
- if (1 == arguments.length) {
21831
- return new Request('GET', method);
21832
- }
21833
-
21834
- return new Request(method, url);
21835
- }
21690
+ request.get = function(url, data, fn){
21691
+ var req = request('GET', url);
21692
+ if ('function' == typeof data) fn = data, data = null;
21693
+ if (data) req.query(data);
21694
+ if (fn) req.end(fn);
21695
+ return req;
21696
+ };
21836
21697
 
21837
21698
  /**
21838
- * GET `url` with optional callback `fn(res)`.
21699
+ * HEAD `url` with optional callback `fn(res)`.
21839
21700
  *
21840
21701
  * @param {String} url
21841
21702
  * @param {Mixed|Function} data or fn
@@ -21844,16 +21705,16 @@ function request(method, url) {
21844
21705
  * @api public
21845
21706
  */
21846
21707
 
21847
- request.get = function(url, data, fn){
21848
- var req = request('GET', url);
21708
+ request.head = function(url, data, fn){
21709
+ var req = request('HEAD', url);
21849
21710
  if ('function' == typeof data) fn = data, data = null;
21850
- if (data) req.query(data);
21711
+ if (data) req.send(data);
21851
21712
  if (fn) req.end(fn);
21852
21713
  return req;
21853
21714
  };
21854
21715
 
21855
21716
  /**
21856
- * HEAD `url` with optional callback `fn(res)`.
21717
+ * OPTIONS query to `url` with optional callback `fn(res)`.
21857
21718
  *
21858
21719
  * @param {String} url
21859
21720
  * @param {Mixed|Function} data or fn
@@ -21862,8 +21723,8 @@ request.get = function(url, data, fn){
21862
21723
  * @api public
21863
21724
  */
21864
21725
 
21865
- request.head = function(url, data, fn){
21866
- var req = request('HEAD', url);
21726
+ request.options = function(url, data, fn){
21727
+ var req = request('OPTIONS', url);
21867
21728
  if ('function' == typeof data) fn = data, data = null;
21868
21729
  if (data) req.send(data);
21869
21730
  if (fn) req.end(fn);
@@ -21942,13 +21803,404 @@ request.put = function(url, data, fn){
21942
21803
  return req;
21943
21804
  };
21944
21805
 
21806
+ },{"./is-object":50,"./request":52,"./request-base":51,"emitter":40,"reduce":47}],50:[function(require,module,exports){
21945
21807
  /**
21946
- * Expose `request`.
21808
+ * Check if `obj` is an object.
21809
+ *
21810
+ * @param {Object} obj
21811
+ * @return {Boolean}
21812
+ * @api private
21813
+ */
21814
+
21815
+ function isObject(obj) {
21816
+ return null !== obj && 'object' === typeof obj;
21817
+ }
21818
+
21819
+ module.exports = isObject;
21820
+
21821
+ },{}],51:[function(require,module,exports){
21822
+ /**
21823
+ * Module of mixed-in functions shared between node and client code
21824
+ */
21825
+ var isObject = require('./is-object');
21826
+
21827
+ /**
21828
+ * Clear previous timeout.
21829
+ *
21830
+ * @return {Request} for chaining
21831
+ * @api public
21832
+ */
21833
+
21834
+ exports.clearTimeout = function _clearTimeout(){
21835
+ this._timeout = 0;
21836
+ clearTimeout(this._timer);
21837
+ return this;
21838
+ };
21839
+
21840
+ /**
21841
+ * Override default response body parser
21842
+ *
21843
+ * This function will be called to convert incoming data into request.body
21844
+ *
21845
+ * @param {Function}
21846
+ * @api public
21847
+ */
21848
+
21849
+ exports.parse = function parse(fn){
21850
+ this._parser = fn;
21851
+ return this;
21852
+ };
21853
+
21854
+ /**
21855
+ * Override default request body serializer
21856
+ *
21857
+ * This function will be called to convert data set via .send or .attach into payload to send
21858
+ *
21859
+ * @param {Function}
21860
+ * @api public
21861
+ */
21862
+
21863
+ exports.serialize = function serialize(fn){
21864
+ this._serializer = fn;
21865
+ return this;
21866
+ };
21867
+
21868
+ /**
21869
+ * Set timeout to `ms`.
21870
+ *
21871
+ * @param {Number} ms
21872
+ * @return {Request} for chaining
21873
+ * @api public
21874
+ */
21875
+
21876
+ exports.timeout = function timeout(ms){
21877
+ this._timeout = ms;
21878
+ return this;
21879
+ };
21880
+
21881
+ /**
21882
+ * Promise support
21883
+ *
21884
+ * @param {Function} resolve
21885
+ * @param {Function} reject
21886
+ * @return {Request}
21887
+ */
21888
+
21889
+ exports.then = function then(resolve, reject) {
21890
+ if (!this._fullfilledPromise) {
21891
+ var self = this;
21892
+ this._fullfilledPromise = new Promise(function(innerResolve, innerReject){
21893
+ self.end(function(err, res){
21894
+ if (err) innerReject(err); else innerResolve(res);
21895
+ });
21896
+ });
21897
+ }
21898
+ return this._fullfilledPromise.then(resolve, reject);
21899
+ }
21900
+
21901
+ /**
21902
+ * Allow for extension
21903
+ */
21904
+
21905
+ exports.use = function use(fn) {
21906
+ fn(this);
21907
+ return this;
21908
+ }
21909
+
21910
+
21911
+ /**
21912
+ * Get request header `field`.
21913
+ * Case-insensitive.
21914
+ *
21915
+ * @param {String} field
21916
+ * @return {String}
21917
+ * @api public
21918
+ */
21919
+
21920
+ exports.get = function(field){
21921
+ return this._header[field.toLowerCase()];
21922
+ };
21923
+
21924
+ /**
21925
+ * Get case-insensitive header `field` value.
21926
+ * This is a deprecated internal API. Use `.get(field)` instead.
21927
+ *
21928
+ * (getHeader is no longer used internally by the superagent code base)
21929
+ *
21930
+ * @param {String} field
21931
+ * @return {String}
21932
+ * @api private
21933
+ * @deprecated
21934
+ */
21935
+
21936
+ exports.getHeader = exports.get;
21937
+
21938
+ /**
21939
+ * Set header `field` to `val`, or multiple fields with one object.
21940
+ * Case-insensitive.
21941
+ *
21942
+ * Examples:
21943
+ *
21944
+ * req.get('/')
21945
+ * .set('Accept', 'application/json')
21946
+ * .set('X-API-Key', 'foobar')
21947
+ * .end(callback);
21948
+ *
21949
+ * req.get('/')
21950
+ * .set({ Accept: 'application/json', 'X-API-Key': 'foobar' })
21951
+ * .end(callback);
21952
+ *
21953
+ * @param {String|Object} field
21954
+ * @param {String} val
21955
+ * @return {Request} for chaining
21956
+ * @api public
21957
+ */
21958
+
21959
+ exports.set = function(field, val){
21960
+ if (isObject(field)) {
21961
+ for (var key in field) {
21962
+ this.set(key, field[key]);
21963
+ }
21964
+ return this;
21965
+ }
21966
+ this._header[field.toLowerCase()] = val;
21967
+ this.header[field] = val;
21968
+ return this;
21969
+ };
21970
+
21971
+ /**
21972
+ * Remove header `field`.
21973
+ * Case-insensitive.
21974
+ *
21975
+ * Example:
21976
+ *
21977
+ * req.get('/')
21978
+ * .unset('User-Agent')
21979
+ * .end(callback);
21980
+ *
21981
+ * @param {String} field
21982
+ */
21983
+ exports.unset = function(field){
21984
+ delete this._header[field.toLowerCase()];
21985
+ delete this.header[field];
21986
+ return this;
21987
+ };
21988
+
21989
+ /**
21990
+ * Write the field `name` and `val` for "multipart/form-data"
21991
+ * request bodies.
21992
+ *
21993
+ * ``` js
21994
+ * request.post('/upload')
21995
+ * .field('foo', 'bar')
21996
+ * .end(callback);
21997
+ * ```
21998
+ *
21999
+ * @param {String} name
22000
+ * @param {String|Blob|File|Buffer|fs.ReadStream} val
22001
+ * @return {Request} for chaining
22002
+ * @api public
22003
+ */
22004
+ exports.field = function(name, val) {
22005
+ this._getFormData().append(name, val);
22006
+ return this;
22007
+ };
22008
+
22009
+ /**
22010
+ * Abort the request, and clear potential timeout.
22011
+ *
22012
+ * @return {Request}
22013
+ * @api public
22014
+ */
22015
+ exports.abort = function(){
22016
+ if (this._aborted) {
22017
+ return this;
22018
+ }
22019
+ this._aborted = true;
22020
+ this.xhr && this.xhr.abort(); // browser
22021
+ this.req && this.req.abort(); // node
22022
+ this.clearTimeout();
22023
+ this.emit('abort');
22024
+ return this;
22025
+ };
22026
+
22027
+ /**
22028
+ * Enable transmission of cookies with x-domain requests.
22029
+ *
22030
+ * Note that for this to work the origin must not be
22031
+ * using "Access-Control-Allow-Origin" with a wildcard,
22032
+ * and also must set "Access-Control-Allow-Credentials"
22033
+ * to "true".
22034
+ *
22035
+ * @api public
21947
22036
  */
21948
22037
 
22038
+ exports.withCredentials = function(){
22039
+ // This is browser-only functionality. Node side is no-op.
22040
+ this._withCredentials = true;
22041
+ return this;
22042
+ };
22043
+
22044
+ /**
22045
+ * Set the max redirects to `n`. Does noting in browser XHR implementation.
22046
+ *
22047
+ * @param {Number} n
22048
+ * @return {Request} for chaining
22049
+ * @api public
22050
+ */
22051
+
22052
+ exports.redirects = function(n){
22053
+ this._maxRedirects = n;
22054
+ return this;
22055
+ };
22056
+
22057
+ /**
22058
+ * Convert to a plain javascript object (not JSON string) of scalar properties.
22059
+ * Note as this method is designed to return a useful non-this value,
22060
+ * it cannot be chained.
22061
+ *
22062
+ * @return {Object} describing method, url, and data of this request
22063
+ * @api public
22064
+ */
22065
+
22066
+ exports.toJSON = function(){
22067
+ return {
22068
+ method: this.method,
22069
+ url: this.url,
22070
+ data: this._data
22071
+ };
22072
+ };
22073
+
22074
+ /**
22075
+ * Check if `obj` is a host object,
22076
+ * we don't want to serialize these :)
22077
+ *
22078
+ * TODO: future proof, move to compoent land
22079
+ *
22080
+ * @param {Object} obj
22081
+ * @return {Boolean}
22082
+ * @api private
22083
+ */
22084
+
22085
+ exports._isHost = function _isHost(obj) {
22086
+ var str = {}.toString.call(obj);
22087
+
22088
+ switch (str) {
22089
+ case '[object File]':
22090
+ case '[object Blob]':
22091
+ case '[object FormData]':
22092
+ return true;
22093
+ default:
22094
+ return false;
22095
+ }
22096
+ }
22097
+
22098
+ /**
22099
+ * Send `data` as the request body, defaulting the `.type()` to "json" when
22100
+ * an object is given.
22101
+ *
22102
+ * Examples:
22103
+ *
22104
+ * // manual json
22105
+ * request.post('/user')
22106
+ * .type('json')
22107
+ * .send('{"name":"tj"}')
22108
+ * .end(callback)
22109
+ *
22110
+ * // auto json
22111
+ * request.post('/user')
22112
+ * .send({ name: 'tj' })
22113
+ * .end(callback)
22114
+ *
22115
+ * // manual x-www-form-urlencoded
22116
+ * request.post('/user')
22117
+ * .type('form')
22118
+ * .send('name=tj')
22119
+ * .end(callback)
22120
+ *
22121
+ * // auto x-www-form-urlencoded
22122
+ * request.post('/user')
22123
+ * .type('form')
22124
+ * .send({ name: 'tj' })
22125
+ * .end(callback)
22126
+ *
22127
+ * // defaults to x-www-form-urlencoded
22128
+ * request.post('/user')
22129
+ * .send('name=tobi')
22130
+ * .send('species=ferret')
22131
+ * .end(callback)
22132
+ *
22133
+ * @param {String|Object} data
22134
+ * @return {Request} for chaining
22135
+ * @api public
22136
+ */
22137
+
22138
+ exports.send = function(data){
22139
+ var obj = isObject(data);
22140
+ var type = this._header['content-type'];
22141
+
22142
+ // merge
22143
+ if (obj && isObject(this._data)) {
22144
+ for (var key in data) {
22145
+ this._data[key] = data[key];
22146
+ }
22147
+ } else if ('string' == typeof data) {
22148
+ // default to x-www-form-urlencoded
22149
+ if (!type) this.type('form');
22150
+ type = this._header['content-type'];
22151
+ if ('application/x-www-form-urlencoded' == type) {
22152
+ this._data = this._data
22153
+ ? this._data + '&' + data
22154
+ : data;
22155
+ } else {
22156
+ this._data = (this._data || '') + data;
22157
+ }
22158
+ } else {
22159
+ this._data = data;
22160
+ }
22161
+
22162
+ if (!obj || this._isHost(data)) return this;
22163
+
22164
+ // default to json
22165
+ if (!type) this.type('json');
22166
+ return this;
22167
+ };
22168
+
22169
+ },{"./is-object":50}],52:[function(require,module,exports){
22170
+ // The node and browser modules expose versions of this with the
22171
+ // appropriate constructor function bound as first argument
22172
+ /**
22173
+ * Issue a request:
22174
+ *
22175
+ * Examples:
22176
+ *
22177
+ * request('GET', '/users').end(callback)
22178
+ * request('/users').end(callback)
22179
+ * request('/users', callback)
22180
+ *
22181
+ * @param {String} method
22182
+ * @param {String|Function} url or callback
22183
+ * @return {Request}
22184
+ * @api public
22185
+ */
22186
+
22187
+ function request(RequestConstructor, method, url) {
22188
+ // callback
22189
+ if ('function' == typeof url) {
22190
+ return new RequestConstructor('GET', method).end(url);
22191
+ }
22192
+
22193
+ // url first
22194
+ if (2 == arguments.length) {
22195
+ return new RequestConstructor('GET', method);
22196
+ }
22197
+
22198
+ return new RequestConstructor(method, url);
22199
+ }
22200
+
21949
22201
  module.exports = request;
21950
22202
 
21951
- },{"emitter":40,"reduce":47}],50:[function(require,module,exports){
22203
+ },{}],53:[function(require,module,exports){
21952
22204
  /*!
21953
22205
  * validate.js 0.9.0
21954
22206
  *