comprodls-sdk 2.61.1 → 2.62.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
@@ -6300,9 +6300,6 @@ function createClass(options) {
6300
6300
  //Initializing promise
6301
6301
  var dfd = q.defer();
6302
6302
 
6303
- // Log a dummy message. This is for a dummy commit.
6304
- console.log('This is a test log.');
6305
-
6306
6303
  //Validations
6307
6304
  var err = helpers.validations.isAuthenticated(self.orgId, self.token);
6308
6305
  if(err) {
@@ -12773,6 +12770,7 @@ module.exports = function () {
12773
12770
  var q = require('q');
12774
12771
  var request = require('superagent');
12775
12772
  var helpers = require('../../helpers');
12773
+ var Agent = require('agentkeepalive');
12776
12774
 
12777
12775
  var DLSError = helpers.errors.DLSError;
12778
12776
 
@@ -12780,6 +12778,12 @@ var DLSError = helpers.errors.DLSError;
12780
12778
  * Setting Up Module Entry Point
12781
12779
  **********************************/
12782
12780
  module.exports = rules;
12781
+
12782
+ var keepaliveAgent = new Agent({
12783
+ timeout: 60000,
12784
+ freeSocketTimeout: 30000
12785
+ });
12786
+
12783
12787
  //Rules Adaptor Contsructor
12784
12788
  function rules() {
12785
12789
  return {
@@ -12920,7 +12924,6 @@ function getParticularRule(options) {
12920
12924
  * context: '', // Mandatory
12921
12925
  * ruleType: '', // Mandatory
12922
12926
  * userId: '', // Mandatory
12923
- * mergeGlobalRules:'' // Optional
12924
12927
  * }
12925
12928
  */
12926
12929
  function getUserRule(options) {
@@ -12939,13 +12942,9 @@ function getUserRule(options) {
12939
12942
  userId: options.userId
12940
12943
  });
12941
12944
 
12942
- //Setup request with URL and Params
12943
- var queryParam = { mergeGlobalRules: options.mergeGlobalRules };
12944
-
12945
12945
  var requestAPI = request.get(url)
12946
12946
  .set('Content-Type', 'application/json')
12947
- .set('Accept', 'application/json')
12948
- .query(queryParam);
12947
+ .set('Accept', 'application/json');
12949
12948
 
12950
12949
  if (self.traceid) {
12951
12950
  requestAPI.set('X-Amzn-Trace-Id', self.traceid);
@@ -12954,7 +12953,9 @@ function getUserRule(options) {
12954
12953
  //Setup token in Authorization header
12955
12954
  requestAPI = helpers.api.setupAPIToken(requestAPI, self.token);
12956
12955
 
12957
- requestAPI.end(function (err, response) {
12956
+ requestAPI
12957
+ .agent(keepaliveAgent)
12958
+ .end(function (err, response) {
12958
12959
  if (err) {
12959
12960
  err = new DLSError(helpers.errors.ERROR_TYPES.API_ERROR, err);
12960
12961
  dfd.reject(err);
@@ -13211,7 +13212,7 @@ function deleteRule(options) {
13211
13212
  return dfd.promise;
13212
13213
  }
13213
13214
 
13214
- },{"../../helpers":3,"q":46,"superagent":49}],28:[function(require,module,exports){
13215
+ },{"../../helpers":3,"agentkeepalive":36,"q":46,"superagent":49}],28:[function(require,module,exports){
13215
13216
  /*************************************************************************
13216
13217
  *
13217
13218
  * COMPRO CONFIDENTIAL
@@ -17760,167 +17761,181 @@ module.exports = Array.isArray || function (arr) {
17760
17761
  };
17761
17762
 
17762
17763
  },{}],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
- };
17764
+
17765
+ /**
17766
+ * Expose `Emitter`.
17767
+ */
17768
+
17769
+ if (typeof module !== 'undefined') {
17770
+ module.exports = Emitter;
17771
+ }
17772
+
17773
+ /**
17774
+ * Initialize a new `Emitter`.
17775
+ *
17776
+ * @api public
17777
+ */
17778
+
17779
+ function Emitter(obj) {
17780
+ if (obj) return mixin(obj);
17781
+ };
17782
+
17783
+ /**
17784
+ * Mixin the emitter properties.
17785
+ *
17786
+ * @param {Object} obj
17787
+ * @return {Object}
17788
+ * @api private
17789
+ */
17790
+
17791
+ function mixin(obj) {
17792
+ for (var key in Emitter.prototype) {
17793
+ obj[key] = Emitter.prototype[key];
17794
+ }
17795
+ return obj;
17796
+ }
17797
+
17798
+ /**
17799
+ * Listen on the given `event` with `fn`.
17800
+ *
17801
+ * @param {String} event
17802
+ * @param {Function} fn
17803
+ * @return {Emitter}
17804
+ * @api public
17805
+ */
17806
+
17807
+ Emitter.prototype.on =
17808
+ Emitter.prototype.addEventListener = function(event, fn){
17809
+ this._callbacks = this._callbacks || {};
17810
+ (this._callbacks['$' + event] = this._callbacks['$' + event] || [])
17811
+ .push(fn);
17812
+ return this;
17813
+ };
17814
+
17815
+ /**
17816
+ * Adds an `event` listener that will be invoked a single
17817
+ * time then automatically removed.
17818
+ *
17819
+ * @param {String} event
17820
+ * @param {Function} fn
17821
+ * @return {Emitter}
17822
+ * @api public
17823
+ */
17824
+
17825
+ Emitter.prototype.once = function(event, fn){
17826
+ function on() {
17827
+ this.off(event, on);
17828
+ fn.apply(this, arguments);
17829
+ }
17830
+
17831
+ on.fn = fn;
17832
+ this.on(event, on);
17833
+ return this;
17834
+ };
17835
+
17836
+ /**
17837
+ * Remove the given callback for `event` or all
17838
+ * registered callbacks.
17839
+ *
17840
+ * @param {String} event
17841
+ * @param {Function} fn
17842
+ * @return {Emitter}
17843
+ * @api public
17844
+ */
17845
+
17846
+ Emitter.prototype.off =
17847
+ Emitter.prototype.removeListener =
17848
+ Emitter.prototype.removeAllListeners =
17849
+ Emitter.prototype.removeEventListener = function(event, fn){
17850
+ this._callbacks = this._callbacks || {};
17851
+
17852
+ // all
17853
+ if (0 == arguments.length) {
17854
+ this._callbacks = {};
17855
+ return this;
17856
+ }
17857
+
17858
+ // specific event
17859
+ var callbacks = this._callbacks['$' + event];
17860
+ if (!callbacks) return this;
17861
+
17862
+ // remove all handlers
17863
+ if (1 == arguments.length) {
17864
+ delete this._callbacks['$' + event];
17865
+ return this;
17866
+ }
17867
+
17868
+ // remove specific handler
17869
+ var cb;
17870
+ for (var i = 0; i < callbacks.length; i++) {
17871
+ cb = callbacks[i];
17872
+ if (cb === fn || cb.fn === fn) {
17873
+ callbacks.splice(i, 1);
17874
+ break;
17875
+ }
17876
+ }
17877
+
17878
+ // Remove event specific arrays for event types that no
17879
+ // one is subscribed for to avoid memory leak.
17880
+ if (callbacks.length === 0) {
17881
+ delete this._callbacks['$' + event];
17882
+ }
17883
+
17884
+ return this;
17885
+ };
17886
+
17887
+ /**
17888
+ * Emit `event` with the given args.
17889
+ *
17890
+ * @param {String} event
17891
+ * @param {Mixed} ...
17892
+ * @return {Emitter}
17893
+ */
17894
+
17895
+ Emitter.prototype.emit = function(event){
17896
+ this._callbacks = this._callbacks || {};
17897
+
17898
+ var args = new Array(arguments.length - 1)
17899
+ , callbacks = this._callbacks['$' + event];
17900
+
17901
+ for (var i = 1; i < arguments.length; i++) {
17902
+ args[i - 1] = arguments[i];
17903
+ }
17904
+
17905
+ if (callbacks) {
17906
+ callbacks = callbacks.slice(0);
17907
+ for (var i = 0, len = callbacks.length; i < len; ++i) {
17908
+ callbacks[i].apply(this, args);
17909
+ }
17910
+ }
17911
+
17912
+ return this;
17913
+ };
17914
+
17915
+ /**
17916
+ * Return array of callbacks for `event`.
17917
+ *
17918
+ * @param {String} event
17919
+ * @return {Array}
17920
+ * @api public
17921
+ */
17922
+
17923
+ Emitter.prototype.listeners = function(event){
17924
+ this._callbacks = this._callbacks || {};
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
+ };
17924
17939
 
17925
17940
  },{}],41:[function(require,module,exports){
17926
17941
  // Copyright Joyent, Inc. and other Node contributors.
@@ -18226,6 +18241,8 @@ function isUndefined(arg) {
18226
18241
  }
18227
18242
 
18228
18243
  },{}],42:[function(require,module,exports){
18244
+ 'use strict';
18245
+
18229
18246
  var hasOwn = Object.prototype.hasOwnProperty;
18230
18247
  var toStr = Object.prototype.toString;
18231
18248
  var defineProperty = Object.defineProperty;
@@ -18240,8 +18257,6 @@ var isArray = function isArray(arr) {
18240
18257
  };
18241
18258
 
18242
18259
  var isPlainObject = function isPlainObject(obj) {
18243
- 'use strict';
18244
-
18245
18260
  if (!obj || toStr.call(obj) !== '[object Object]') {
18246
18261
  return false;
18247
18262
  }
@@ -18291,8 +18306,6 @@ var getProperty = function getProperty(obj, name) {
18291
18306
  };
18292
18307
 
18293
18308
  module.exports = function extend() {
18294
- 'use strict';
18295
-
18296
18309
  var options, name, src, copy, copyIsArray, clone;
18297
18310
  var target = arguments[0];
18298
18311
  var i = 1;
@@ -20762,6 +20775,8 @@ function template(string) {
20762
20775
 
20763
20776
  var Emitter = require('emitter');
20764
20777
  var reduce = require('reduce');
20778
+ var requestBase = require('./request-base');
20779
+ var isObject = require('./is-object');
20765
20780
 
20766
20781
  /**
20767
20782
  * Root reference for iframes.
@@ -20783,28 +20798,10 @@ if (typeof window !== 'undefined') { // Browser window
20783
20798
  function noop(){};
20784
20799
 
20785
20800
  /**
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
20801
+ * Expose `request`.
20794
20802
  */
20795
20803
 
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
- }
20804
+ var request = module.exports = require('./request').bind(null, Request);
20808
20805
 
20809
20806
  /**
20810
20807
  * Determine XHR.
@@ -20836,18 +20833,6 @@ var trim = ''.trim
20836
20833
  ? function(s) { return s.trim(); }
20837
20834
  : function(s) { return s.replace(/(^\s*|\s*$)/g, ''); };
20838
20835
 
20839
- /**
20840
- * Check if `obj` is an object.
20841
- *
20842
- * @param {Object} obj
20843
- * @return {Boolean}
20844
- * @api private
20845
- */
20846
-
20847
- function isObject(obj) {
20848
- return obj === Object(obj);
20849
- }
20850
-
20851
20836
  /**
20852
20837
  * Serialize the given `obj`.
20853
20838
  *
@@ -20862,8 +20847,8 @@ function serialize(obj) {
20862
20847
  for (var key in obj) {
20863
20848
  if (null != obj[key]) {
20864
20849
  pushEncodedKeyValuePair(pairs, key, obj[key]);
20865
- }
20866
- }
20850
+ }
20851
+ }
20867
20852
  return pairs.join('&');
20868
20853
  }
20869
20854
 
@@ -20881,6 +20866,11 @@ function pushEncodedKeyValuePair(pairs, key, val) {
20881
20866
  return val.forEach(function(v) {
20882
20867
  pushEncodedKeyValuePair(pairs, key, v);
20883
20868
  });
20869
+ } else if (isObject(val)) {
20870
+ for(var subkey in val) {
20871
+ pushEncodedKeyValuePair(pairs, key + '[' + subkey + ']', val[subkey]);
20872
+ }
20873
+ return;
20884
20874
  }
20885
20875
  pairs.push(encodeURIComponent(key)
20886
20876
  + '=' + encodeURIComponent(val));
@@ -20903,13 +20893,18 @@ function pushEncodedKeyValuePair(pairs, key, val) {
20903
20893
  function parseString(str) {
20904
20894
  var obj = {};
20905
20895
  var pairs = str.split('&');
20906
- var parts;
20907
20896
  var pair;
20897
+ var pos;
20908
20898
 
20909
20899
  for (var i = 0, len = pairs.length; i < len; ++i) {
20910
20900
  pair = pairs[i];
20911
- parts = pair.split('=');
20912
- obj[decodeURIComponent(parts[0])] = decodeURIComponent(parts[1]);
20901
+ pos = pair.indexOf('=');
20902
+ if (pos == -1) {
20903
+ obj[decodeURIComponent(pair)] = '';
20904
+ } else {
20905
+ obj[decodeURIComponent(pair.slice(0, pos))] =
20906
+ decodeURIComponent(pair.slice(pos + 1));
20907
+ }
20913
20908
  }
20914
20909
 
20915
20910
  return obj;
@@ -21093,15 +21088,15 @@ function Response(req, options) {
21093
21088
  ? this.xhr.responseText
21094
21089
  : null;
21095
21090
  this.statusText = this.req.xhr.statusText;
21096
- this.setStatusProperties(this.xhr.status);
21091
+ this._setStatusProperties(this.xhr.status);
21097
21092
  this.header = this.headers = parseHeader(this.xhr.getAllResponseHeaders());
21098
21093
  // getAllResponseHeaders sometimes falsely returns "" for CORS requests, but
21099
21094
  // getResponseHeader still works. so we get content-type even if getting
21100
21095
  // other headers fails.
21101
21096
  this.header['content-type'] = this.xhr.getResponseHeader('content-type');
21102
- this.setHeaderProperties(this.header);
21097
+ this._setHeaderProperties(this.header);
21103
21098
  this.body = this.req.method != 'HEAD'
21104
- ? this.parseBody(this.text ? this.text : this.xhr.response)
21099
+ ? this._parseBody(this.text ? this.text : this.xhr.response)
21105
21100
  : null;
21106
21101
  }
21107
21102
 
@@ -21129,7 +21124,7 @@ Response.prototype.get = function(field){
21129
21124
  * @api private
21130
21125
  */
21131
21126
 
21132
- Response.prototype.setHeaderProperties = function(header){
21127
+ Response.prototype._setHeaderProperties = function(header){
21133
21128
  // content-type
21134
21129
  var ct = this.header['content-type'] || '';
21135
21130
  this.type = type(ct);
@@ -21150,8 +21145,11 @@ Response.prototype.setHeaderProperties = function(header){
21150
21145
  * @api private
21151
21146
  */
21152
21147
 
21153
- Response.prototype.parseBody = function(str){
21148
+ Response.prototype._parseBody = function(str){
21154
21149
  var parse = request.parse[this.type];
21150
+ if (!parse && isJSON(this.type)) {
21151
+ parse = request.parse['application/json'];
21152
+ }
21155
21153
  return parse && str && (str.length || str instanceof Object)
21156
21154
  ? parse(str)
21157
21155
  : null;
@@ -21178,7 +21176,7 @@ Response.prototype.parseBody = function(str){
21178
21176
  * @api private
21179
21177
  */
21180
21178
 
21181
- Response.prototype.setStatusProperties = function(status){
21179
+ Response.prototype._setStatusProperties = function(status){
21182
21180
  // handle IE9 bug: http://stackoverflow.com/questions/10046972/msie-returns-status-code-of-1223-for-ajax-request
21183
21181
  if (status === 1223) {
21184
21182
  status = 204;
@@ -21246,12 +21244,11 @@ request.Response = Response;
21246
21244
 
21247
21245
  function Request(method, url) {
21248
21246
  var self = this;
21249
- Emitter.call(this);
21250
21247
  this._query = this._query || [];
21251
21248
  this.method = method;
21252
21249
  this.url = url;
21253
- this.header = {};
21254
- this._header = {};
21250
+ this.header = {}; // preserves header name case
21251
+ this._header = {}; // coerces header names to lowercase
21255
21252
  this.on('end', function(){
21256
21253
  var err = null;
21257
21254
  var res = null;
@@ -21264,6 +21261,8 @@ function Request(method, url) {
21264
21261
  err.original = e;
21265
21262
  // issue #675: return the raw response if the response parsing fails
21266
21263
  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;
21267
21266
  return self.callback(err);
21268
21267
  }
21269
21268
 
@@ -21273,178 +21272,76 @@ function Request(method, url) {
21273
21272
  return self.callback(err, res);
21274
21273
  }
21275
21274
 
21276
- if (res.status >= 200 && res.status < 300) {
21277
- return self.callback(err, res);
21278
- }
21275
+ try {
21276
+ if (res.status >= 200 && res.status < 300) {
21277
+ return self.callback(err, res);
21278
+ }
21279
21279
 
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;
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;
21284
21284
 
21285
- self.callback(new_err, res);
21285
+ self.callback(new_err, res);
21286
+ } catch(e) {
21287
+ self.callback(e); // #985 touching res may cause INVALID_STATE_ERR on old Android
21288
+ }
21286
21289
  });
21287
21290
  }
21288
21291
 
21289
21292
  /**
21290
- * Mixin `Emitter`.
21293
+ * Mixin `Emitter` and `requestBase`.
21291
21294
  */
21292
21295
 
21293
21296
  Emitter(Request.prototype);
21294
-
21295
- /**
21296
- * Allow for extension
21297
- */
21298
-
21299
- Request.prototype.use = function(fn) {
21300
- fn(this);
21301
- return this;
21297
+ for (var key in requestBase) {
21298
+ Request.prototype[key] = requestBase[key];
21302
21299
  }
21303
21300
 
21304
21301
  /**
21305
- * Set timeout to `ms`.
21302
+ * Set Content-Type to `type`, mapping values from `request.types`.
21306
21303
  *
21307
- * @param {Number} ms
21304
+ * Examples:
21305
+ *
21306
+ * superagent.types.xml = 'application/xml';
21307
+ *
21308
+ * request.post('/')
21309
+ * .type('xml')
21310
+ * .send(xmlstring)
21311
+ * .end(callback);
21312
+ *
21313
+ * request.post('/')
21314
+ * .type('application/xml')
21315
+ * .send(xmlstring)
21316
+ * .end(callback);
21317
+ *
21318
+ * @param {String} type
21308
21319
  * @return {Request} for chaining
21309
21320
  * @api public
21310
21321
  */
21311
21322
 
21312
- Request.prototype.timeout = function(ms){
21313
- this._timeout = ms;
21323
+ Request.prototype.type = function(type){
21324
+ this.set('Content-Type', request.types[type] || type);
21314
21325
  return this;
21315
21326
  };
21316
21327
 
21317
21328
  /**
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.
21329
+ * Set responseType to `val`. Presently valid responseTypes are 'blob' and
21330
+ * 'arraybuffer'.
21348
21331
  *
21349
21332
  * Examples:
21350
21333
  *
21351
21334
  * 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' })
21335
+ * .responseType('blob')
21358
21336
  * .end(callback);
21359
21337
  *
21360
- * @param {String|Object} field
21361
21338
  * @param {String} val
21362
21339
  * @return {Request} for chaining
21363
21340
  * @api public
21364
21341
  */
21365
21342
 
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
- /**
21411
- * Set Content-Type to `type`, mapping values from `request.types`.
21412
- *
21413
- * Examples:
21414
- *
21415
- * superagent.types.xml = 'application/xml';
21416
- *
21417
- * request.post('/')
21418
- * .type('xml')
21419
- * .send(xmlstring)
21420
- * .end(callback);
21421
- *
21422
- * request.post('/')
21423
- * .type('application/xml')
21424
- * .send(xmlstring)
21425
- * .end(callback);
21426
- *
21427
- * @param {String} type
21428
- * @return {Request} for chaining
21429
- * @api public
21430
- */
21431
-
21432
- Request.prototype.type = function(type){
21433
- this.set('Content-Type', request.types[type] || type);
21434
- return this;
21435
- };
21436
-
21437
- /**
21438
- * Force given parser
21439
- *
21440
- * Sets the body parser no matter type.
21441
- *
21442
- * @param {Function}
21443
- * @api public
21444
- */
21445
-
21446
- Request.prototype.parse = function(fn){
21447
- this._parser = fn;
21343
+ Request.prototype.responseType = function(val){
21344
+ this._responseType = val;
21448
21345
  return this;
21449
21346
  };
21450
21347
 
@@ -21478,13 +21375,29 @@ Request.prototype.accept = function(type){
21478
21375
  *
21479
21376
  * @param {String} user
21480
21377
  * @param {String} pass
21378
+ * @param {Object} options with 'type' property 'auto' or 'basic' (default 'basic')
21481
21379
  * @return {Request} for chaining
21482
21380
  * @api public
21483
21381
  */
21484
21382
 
21485
- Request.prototype.auth = function(user, pass){
21486
- var str = btoa(user + ':' + pass);
21487
- this.set('Authorization', 'Basic ' + str);
21383
+ Request.prototype.auth = function(user, pass, options){
21384
+ if (!options) {
21385
+ options = {
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
+ }
21488
21401
  return this;
21489
21402
  };
21490
21403
 
@@ -21508,35 +21421,13 @@ Request.prototype.query = function(val){
21508
21421
  return this;
21509
21422
  };
21510
21423
 
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
21424
  /**
21534
21425
  * Queue the given `file` as an attachment to the specified `field`,
21535
21426
  * with optional `filename`.
21536
21427
  *
21537
21428
  * ``` js
21538
21429
  * request.post('/upload')
21539
- * .attach(new Blob(['<a id="a"><b id="b">hey!</b></a>'], { type: "text/html"}))
21430
+ * .attach('content', new Blob(['<a id="a"><b id="b">hey!</b></a>'], { type: "text/html"}))
21540
21431
  * .end(callback);
21541
21432
  * ```
21542
21433
  *
@@ -21548,77 +21439,15 @@ Request.prototype.field = function(name, val){
21548
21439
  */
21549
21440
 
21550
21441
  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);
21442
+ this._getFormData().append(field, file, filename || file.name);
21553
21443
  return this;
21554
21444
  };
21555
21445
 
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;
21446
+ Request.prototype._getFormData = function(){
21447
+ if (!this._formData) {
21448
+ this._formData = new root.FormData();
21617
21449
  }
21618
-
21619
- if (!obj || isHost(data)) return this;
21620
- if (!type) this.type('json');
21621
- return this;
21450
+ return this._formData;
21622
21451
  };
21623
21452
 
21624
21453
  /**
@@ -21659,7 +21488,7 @@ Request.prototype.crossDomainError = function(){
21659
21488
  * @api private
21660
21489
  */
21661
21490
 
21662
- Request.prototype.timeoutError = function(){
21491
+ Request.prototype._timeoutError = function(){
21663
21492
  var timeout = this._timeout;
21664
21493
  var err = new Error('timeout of ' + timeout + 'ms exceeded');
21665
21494
  err.timeout = timeout;
@@ -21667,19 +21496,18 @@ Request.prototype.timeoutError = function(){
21667
21496
  };
21668
21497
 
21669
21498
  /**
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".
21499
+ * Compose querystring to append to req.url
21676
21500
  *
21677
- * @api public
21501
+ * @api private
21678
21502
  */
21679
21503
 
21680
- Request.prototype.withCredentials = function(){
21681
- this._withCredentials = true;
21682
- return this;
21504
+ Request.prototype._appendQueryString = function(){
21505
+ var query = this._query.join('&');
21506
+ if (query) {
21507
+ this.url += ~this.url.indexOf('?')
21508
+ ? '&' + query
21509
+ : '?' + query;
21510
+ }
21683
21511
  };
21684
21512
 
21685
21513
  /**
@@ -21694,7 +21522,6 @@ Request.prototype.withCredentials = function(){
21694
21522
  Request.prototype.end = function(fn){
21695
21523
  var self = this;
21696
21524
  var xhr = this.xhr = request.getXHR();
21697
- var query = this._query.join('&');
21698
21525
  var timeout = this._timeout;
21699
21526
  var data = this._formData || this._data;
21700
21527
 
@@ -21711,8 +21538,8 @@ Request.prototype.end = function(fn){
21711
21538
  try { status = xhr.status } catch(e) { status = 0; }
21712
21539
 
21713
21540
  if (0 == status) {
21714
- if (self.timedout) return self.timeoutError();
21715
- if (self.aborted) return;
21541
+ if (self.timedout) return self._timeoutError();
21542
+ if (self._aborted) return;
21716
21543
  return self.crossDomainError();
21717
21544
  }
21718
21545
  self.emit('end');
@@ -21748,24 +21575,23 @@ Request.prototype.end = function(fn){
21748
21575
  }
21749
21576
 
21750
21577
  // querystring
21751
- if (query) {
21752
- query = request.serializeObject(query);
21753
- this.url += ~this.url.indexOf('?')
21754
- ? '&' + query
21755
- : '?' + query;
21756
- }
21578
+ this._appendQueryString();
21757
21579
 
21758
21580
  // initiate request
21759
- xhr.open(this.method, this.url, true);
21581
+ if (this.username && this.password) {
21582
+ xhr.open(this.method, this.url, true, this.username, this.password);
21583
+ } else {
21584
+ xhr.open(this.method, this.url, true);
21585
+ }
21760
21586
 
21761
21587
  // CORS
21762
21588
  if (this._withCredentials) xhr.withCredentials = true;
21763
21589
 
21764
21590
  // body
21765
- if ('GET' != this.method && 'HEAD' != this.method && 'string' != typeof data && !isHost(data)) {
21591
+ if ('GET' != this.method && 'HEAD' != this.method && 'string' != typeof data && !this._isHost(data)) {
21766
21592
  // serialize stuff
21767
- var contentType = this.getHeader('Content-Type');
21768
- var serialize = this._parser || request.serialize[contentType ? contentType.split(';')[0] : ''];
21593
+ var contentType = this._header['content-type'];
21594
+ var serialize = this._serializer || request.serialize[contentType ? contentType.split(';')[0] : ''];
21769
21595
  if (!serialize && isJSON(contentType)) serialize = request.serialize['application/json'];
21770
21596
  if (serialize) data = serialize(data);
21771
21597
  }
@@ -21776,6 +21602,10 @@ Request.prototype.end = function(fn){
21776
21602
  xhr.setRequestHeader(field, this.header[field]);
21777
21603
  }
21778
21604
 
21605
+ if (this._responseType) {
21606
+ xhr.responseType = this._responseType;
21607
+ }
21608
+
21779
21609
  // send stuff
21780
21610
  this.emit('request', this);
21781
21611
 
@@ -21785,19 +21615,6 @@ Request.prototype.end = function(fn){
21785
21615
  return this;
21786
21616
  };
21787
21617
 
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
21618
 
21802
21619
  /**
21803
21620
  * Expose `Request`.
@@ -21805,35 +21622,6 @@ Request.prototype.then = function (fulfill, reject) {
21805
21622
 
21806
21623
  request.Request = Request;
21807
21624
 
21808
- /**
21809
- * Issue a request:
21810
- *
21811
- * Examples:
21812
- *
21813
- * request('GET', '/users').end(callback)
21814
- * request('/users').end(callback)
21815
- * request('/users', callback)
21816
- *
21817
- * @param {String} method
21818
- * @param {String|Function} url or callback
21819
- * @return {Request}
21820
- * @api public
21821
- */
21822
-
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
- }
21836
-
21837
21625
  /**
21838
21626
  * GET `url` with optional callback `fn(res)`.
21839
21627
  *
@@ -21871,28 +21659,46 @@ request.head = function(url, data, fn){
21871
21659
  };
21872
21660
 
21873
21661
  /**
21874
- * DELETE `url` with optional callback `fn(res)`.
21662
+ * OPTIONS query to `url` with optional callback `fn(res)`.
21875
21663
  *
21876
21664
  * @param {String} url
21665
+ * @param {Mixed|Function} data or fn
21877
21666
  * @param {Function} fn
21878
21667
  * @return {Request}
21879
21668
  * @api public
21880
21669
  */
21881
21670
 
21882
- function del(url, fn){
21883
- var req = request('DELETE', url);
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);
21884
21675
  if (fn) req.end(fn);
21885
21676
  return req;
21886
21677
  };
21887
21678
 
21888
- request['del'] = del;
21889
- request['delete'] = del;
21890
-
21891
21679
  /**
21892
- * PATCH `url` with optional `data` and callback `fn(res)`.
21680
+ * DELETE `url` with optional callback `fn(res)`.
21893
21681
  *
21894
21682
  * @param {String} url
21895
- * @param {Mixed} data
21683
+ * @param {Function} fn
21684
+ * @return {Request}
21685
+ * @api public
21686
+ */
21687
+
21688
+ function del(url, fn){
21689
+ var req = request('DELETE', url);
21690
+ if (fn) req.end(fn);
21691
+ return req;
21692
+ };
21693
+
21694
+ request['del'] = del;
21695
+ request['delete'] = del;
21696
+
21697
+ /**
21698
+ * PATCH `url` with optional `data` and callback `fn(res)`.
21699
+ *
21700
+ * @param {String} url
21701
+ * @param {Mixed} data
21896
21702
  * @param {Function} fn
21897
21703
  * @return {Request}
21898
21704
  * @api public
@@ -21942,13 +21748,404 @@ request.put = function(url, data, fn){
21942
21748
  return req;
21943
21749
  };
21944
21750
 
21751
+ },{"./is-object":50,"./request":52,"./request-base":51,"emitter":40,"reduce":47}],50:[function(require,module,exports){
21945
21752
  /**
21946
- * Expose `request`.
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
+ /**
21786
+ * Override default response body parser
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
21947
22130
  */
21948
22131
 
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
+
21949
22146
  module.exports = request;
21950
22147
 
21951
- },{"emitter":40,"reduce":47}],50:[function(require,module,exports){
22148
+ },{}],53:[function(require,module,exports){
21952
22149
  /*!
21953
22150
  * validate.js 0.9.0
21954
22151
  *