comprodls-sdk 2.61.0 → 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
@@ -12770,6 +12770,7 @@ module.exports = function () {
12770
12770
  var q = require('q');
12771
12771
  var request = require('superagent');
12772
12772
  var helpers = require('../../helpers');
12773
+ var Agent = require('agentkeepalive');
12773
12774
 
12774
12775
  var DLSError = helpers.errors.DLSError;
12775
12776
 
@@ -12777,6 +12778,12 @@ var DLSError = helpers.errors.DLSError;
12777
12778
  * Setting Up Module Entry Point
12778
12779
  **********************************/
12779
12780
  module.exports = rules;
12781
+
12782
+ var keepaliveAgent = new Agent({
12783
+ timeout: 60000,
12784
+ freeSocketTimeout: 30000
12785
+ });
12786
+
12780
12787
  //Rules Adaptor Contsructor
12781
12788
  function rules() {
12782
12789
  return {
@@ -12917,7 +12924,6 @@ function getParticularRule(options) {
12917
12924
  * context: '', // Mandatory
12918
12925
  * ruleType: '', // Mandatory
12919
12926
  * userId: '', // Mandatory
12920
- * mergeGlobalRules:'' // Optional
12921
12927
  * }
12922
12928
  */
12923
12929
  function getUserRule(options) {
@@ -12936,13 +12942,9 @@ function getUserRule(options) {
12936
12942
  userId: options.userId
12937
12943
  });
12938
12944
 
12939
- //Setup request with URL and Params
12940
- var queryParam = { mergeGlobalRules: options.mergeGlobalRules };
12941
-
12942
12945
  var requestAPI = request.get(url)
12943
12946
  .set('Content-Type', 'application/json')
12944
- .set('Accept', 'application/json')
12945
- .query(queryParam);
12947
+ .set('Accept', 'application/json');
12946
12948
 
12947
12949
  if (self.traceid) {
12948
12950
  requestAPI.set('X-Amzn-Trace-Id', self.traceid);
@@ -12951,7 +12953,9 @@ function getUserRule(options) {
12951
12953
  //Setup token in Authorization header
12952
12954
  requestAPI = helpers.api.setupAPIToken(requestAPI, self.token);
12953
12955
 
12954
- requestAPI.end(function (err, response) {
12956
+ requestAPI
12957
+ .agent(keepaliveAgent)
12958
+ .end(function (err, response) {
12955
12959
  if (err) {
12956
12960
  err = new DLSError(helpers.errors.ERROR_TYPES.API_ERROR, err);
12957
12961
  dfd.reject(err);
@@ -13208,7 +13212,7 @@ function deleteRule(options) {
13208
13212
  return dfd.promise;
13209
13213
  }
13210
13214
 
13211
- },{"../../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){
13212
13216
  /*************************************************************************
13213
13217
  *
13214
13218
  * COMPRO CONFIDENTIAL
@@ -17757,167 +17761,181 @@ module.exports = Array.isArray || function (arr) {
17757
17761
  };
17758
17762
 
17759
17763
  },{}],40:[function(require,module,exports){
17760
-
17761
- /**
17762
- * Expose `Emitter`.
17763
- */
17764
-
17765
- module.exports = Emitter;
17766
-
17767
- /**
17768
- * Initialize a new `Emitter`.
17769
- *
17770
- * @api public
17771
- */
17772
-
17773
- function Emitter(obj) {
17774
- if (obj) return mixin(obj);
17775
- };
17776
-
17777
- /**
17778
- * Mixin the emitter properties.
17779
- *
17780
- * @param {Object} obj
17781
- * @return {Object}
17782
- * @api private
17783
- */
17784
-
17785
- function mixin(obj) {
17786
- for (var key in Emitter.prototype) {
17787
- obj[key] = Emitter.prototype[key];
17788
- }
17789
- return obj;
17790
- }
17791
-
17792
- /**
17793
- * Listen on the given `event` with `fn`.
17794
- *
17795
- * @param {String} event
17796
- * @param {Function} fn
17797
- * @return {Emitter}
17798
- * @api public
17799
- */
17800
-
17801
- Emitter.prototype.on =
17802
- Emitter.prototype.addEventListener = function(event, fn){
17803
- this._callbacks = this._callbacks || {};
17804
- (this._callbacks['$' + event] = this._callbacks['$' + event] || [])
17805
- .push(fn);
17806
- return this;
17807
- };
17808
-
17809
- /**
17810
- * Adds an `event` listener that will be invoked a single
17811
- * time then automatically removed.
17812
- *
17813
- * @param {String} event
17814
- * @param {Function} fn
17815
- * @return {Emitter}
17816
- * @api public
17817
- */
17818
-
17819
- Emitter.prototype.once = function(event, fn){
17820
- function on() {
17821
- this.off(event, on);
17822
- fn.apply(this, arguments);
17823
- }
17824
-
17825
- on.fn = fn;
17826
- this.on(event, on);
17827
- return this;
17828
- };
17829
-
17830
- /**
17831
- * Remove the given callback for `event` or all
17832
- * registered callbacks.
17833
- *
17834
- * @param {String} event
17835
- * @param {Function} fn
17836
- * @return {Emitter}
17837
- * @api public
17838
- */
17839
-
17840
- Emitter.prototype.off =
17841
- Emitter.prototype.removeListener =
17842
- Emitter.prototype.removeAllListeners =
17843
- Emitter.prototype.removeEventListener = function(event, fn){
17844
- this._callbacks = this._callbacks || {};
17845
-
17846
- // all
17847
- if (0 == arguments.length) {
17848
- this._callbacks = {};
17849
- return this;
17850
- }
17851
-
17852
- // specific event
17853
- var callbacks = this._callbacks['$' + event];
17854
- if (!callbacks) return this;
17855
-
17856
- // remove all handlers
17857
- if (1 == arguments.length) {
17858
- delete this._callbacks['$' + event];
17859
- return this;
17860
- }
17861
-
17862
- // remove specific handler
17863
- var cb;
17864
- for (var i = 0; i < callbacks.length; i++) {
17865
- cb = callbacks[i];
17866
- if (cb === fn || cb.fn === fn) {
17867
- callbacks.splice(i, 1);
17868
- break;
17869
- }
17870
- }
17871
- return this;
17872
- };
17873
-
17874
- /**
17875
- * Emit `event` with the given args.
17876
- *
17877
- * @param {String} event
17878
- * @param {Mixed} ...
17879
- * @return {Emitter}
17880
- */
17881
-
17882
- Emitter.prototype.emit = function(event){
17883
- this._callbacks = this._callbacks || {};
17884
- var args = [].slice.call(arguments, 1)
17885
- , callbacks = this._callbacks['$' + event];
17886
-
17887
- if (callbacks) {
17888
- callbacks = callbacks.slice(0);
17889
- for (var i = 0, len = callbacks.length; i < len; ++i) {
17890
- callbacks[i].apply(this, args);
17891
- }
17892
- }
17893
-
17894
- return this;
17895
- };
17896
-
17897
- /**
17898
- * Return array of callbacks for `event`.
17899
- *
17900
- * @param {String} event
17901
- * @return {Array}
17902
- * @api public
17903
- */
17904
-
17905
- Emitter.prototype.listeners = function(event){
17906
- this._callbacks = this._callbacks || {};
17907
- return this._callbacks['$' + event] || [];
17908
- };
17909
-
17910
- /**
17911
- * Check if this emitter has `event` handlers.
17912
- *
17913
- * @param {String} event
17914
- * @return {Boolean}
17915
- * @api public
17916
- */
17917
-
17918
- Emitter.prototype.hasListeners = function(event){
17919
- return !! this.listeners(event).length;
17920
- };
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
+ };
17921
17939
 
17922
17940
  },{}],41:[function(require,module,exports){
17923
17941
  // Copyright Joyent, Inc. and other Node contributors.
@@ -18223,6 +18241,8 @@ function isUndefined(arg) {
18223
18241
  }
18224
18242
 
18225
18243
  },{}],42:[function(require,module,exports){
18244
+ 'use strict';
18245
+
18226
18246
  var hasOwn = Object.prototype.hasOwnProperty;
18227
18247
  var toStr = Object.prototype.toString;
18228
18248
  var defineProperty = Object.defineProperty;
@@ -18237,8 +18257,6 @@ var isArray = function isArray(arr) {
18237
18257
  };
18238
18258
 
18239
18259
  var isPlainObject = function isPlainObject(obj) {
18240
- 'use strict';
18241
-
18242
18260
  if (!obj || toStr.call(obj) !== '[object Object]') {
18243
18261
  return false;
18244
18262
  }
@@ -18288,8 +18306,6 @@ var getProperty = function getProperty(obj, name) {
18288
18306
  };
18289
18307
 
18290
18308
  module.exports = function extend() {
18291
- 'use strict';
18292
-
18293
18309
  var options, name, src, copy, copyIsArray, clone;
18294
18310
  var target = arguments[0];
18295
18311
  var i = 1;
@@ -20759,6 +20775,8 @@ function template(string) {
20759
20775
 
20760
20776
  var Emitter = require('emitter');
20761
20777
  var reduce = require('reduce');
20778
+ var requestBase = require('./request-base');
20779
+ var isObject = require('./is-object');
20762
20780
 
20763
20781
  /**
20764
20782
  * Root reference for iframes.
@@ -20780,28 +20798,10 @@ if (typeof window !== 'undefined') { // Browser window
20780
20798
  function noop(){};
20781
20799
 
20782
20800
  /**
20783
- * Check if `obj` is a host object,
20784
- * we don't want to serialize these :)
20785
- *
20786
- * TODO: future proof, move to compoent land
20787
- *
20788
- * @param {Object} obj
20789
- * @return {Boolean}
20790
- * @api private
20801
+ * Expose `request`.
20791
20802
  */
20792
20803
 
20793
- function isHost(obj) {
20794
- var str = {}.toString.call(obj);
20795
-
20796
- switch (str) {
20797
- case '[object File]':
20798
- case '[object Blob]':
20799
- case '[object FormData]':
20800
- return true;
20801
- default:
20802
- return false;
20803
- }
20804
- }
20804
+ var request = module.exports = require('./request').bind(null, Request);
20805
20805
 
20806
20806
  /**
20807
20807
  * Determine XHR.
@@ -20833,18 +20833,6 @@ var trim = ''.trim
20833
20833
  ? function(s) { return s.trim(); }
20834
20834
  : function(s) { return s.replace(/(^\s*|\s*$)/g, ''); };
20835
20835
 
20836
- /**
20837
- * Check if `obj` is an object.
20838
- *
20839
- * @param {Object} obj
20840
- * @return {Boolean}
20841
- * @api private
20842
- */
20843
-
20844
- function isObject(obj) {
20845
- return obj === Object(obj);
20846
- }
20847
-
20848
20836
  /**
20849
20837
  * Serialize the given `obj`.
20850
20838
  *
@@ -20859,8 +20847,8 @@ function serialize(obj) {
20859
20847
  for (var key in obj) {
20860
20848
  if (null != obj[key]) {
20861
20849
  pushEncodedKeyValuePair(pairs, key, obj[key]);
20862
- }
20863
- }
20850
+ }
20851
+ }
20864
20852
  return pairs.join('&');
20865
20853
  }
20866
20854
 
@@ -20878,6 +20866,11 @@ function pushEncodedKeyValuePair(pairs, key, val) {
20878
20866
  return val.forEach(function(v) {
20879
20867
  pushEncodedKeyValuePair(pairs, key, v);
20880
20868
  });
20869
+ } else if (isObject(val)) {
20870
+ for(var subkey in val) {
20871
+ pushEncodedKeyValuePair(pairs, key + '[' + subkey + ']', val[subkey]);
20872
+ }
20873
+ return;
20881
20874
  }
20882
20875
  pairs.push(encodeURIComponent(key)
20883
20876
  + '=' + encodeURIComponent(val));
@@ -20900,13 +20893,18 @@ function pushEncodedKeyValuePair(pairs, key, val) {
20900
20893
  function parseString(str) {
20901
20894
  var obj = {};
20902
20895
  var pairs = str.split('&');
20903
- var parts;
20904
20896
  var pair;
20897
+ var pos;
20905
20898
 
20906
20899
  for (var i = 0, len = pairs.length; i < len; ++i) {
20907
20900
  pair = pairs[i];
20908
- parts = pair.split('=');
20909
- 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
+ }
20910
20908
  }
20911
20909
 
20912
20910
  return obj;
@@ -21090,15 +21088,15 @@ function Response(req, options) {
21090
21088
  ? this.xhr.responseText
21091
21089
  : null;
21092
21090
  this.statusText = this.req.xhr.statusText;
21093
- this.setStatusProperties(this.xhr.status);
21091
+ this._setStatusProperties(this.xhr.status);
21094
21092
  this.header = this.headers = parseHeader(this.xhr.getAllResponseHeaders());
21095
21093
  // getAllResponseHeaders sometimes falsely returns "" for CORS requests, but
21096
21094
  // getResponseHeader still works. so we get content-type even if getting
21097
21095
  // other headers fails.
21098
21096
  this.header['content-type'] = this.xhr.getResponseHeader('content-type');
21099
- this.setHeaderProperties(this.header);
21097
+ this._setHeaderProperties(this.header);
21100
21098
  this.body = this.req.method != 'HEAD'
21101
- ? this.parseBody(this.text ? this.text : this.xhr.response)
21099
+ ? this._parseBody(this.text ? this.text : this.xhr.response)
21102
21100
  : null;
21103
21101
  }
21104
21102
 
@@ -21126,7 +21124,7 @@ Response.prototype.get = function(field){
21126
21124
  * @api private
21127
21125
  */
21128
21126
 
21129
- Response.prototype.setHeaderProperties = function(header){
21127
+ Response.prototype._setHeaderProperties = function(header){
21130
21128
  // content-type
21131
21129
  var ct = this.header['content-type'] || '';
21132
21130
  this.type = type(ct);
@@ -21147,8 +21145,11 @@ Response.prototype.setHeaderProperties = function(header){
21147
21145
  * @api private
21148
21146
  */
21149
21147
 
21150
- Response.prototype.parseBody = function(str){
21148
+ Response.prototype._parseBody = function(str){
21151
21149
  var parse = request.parse[this.type];
21150
+ if (!parse && isJSON(this.type)) {
21151
+ parse = request.parse['application/json'];
21152
+ }
21152
21153
  return parse && str && (str.length || str instanceof Object)
21153
21154
  ? parse(str)
21154
21155
  : null;
@@ -21175,7 +21176,7 @@ Response.prototype.parseBody = function(str){
21175
21176
  * @api private
21176
21177
  */
21177
21178
 
21178
- Response.prototype.setStatusProperties = function(status){
21179
+ Response.prototype._setStatusProperties = function(status){
21179
21180
  // handle IE9 bug: http://stackoverflow.com/questions/10046972/msie-returns-status-code-of-1223-for-ajax-request
21180
21181
  if (status === 1223) {
21181
21182
  status = 204;
@@ -21243,12 +21244,11 @@ request.Response = Response;
21243
21244
 
21244
21245
  function Request(method, url) {
21245
21246
  var self = this;
21246
- Emitter.call(this);
21247
21247
  this._query = this._query || [];
21248
21248
  this.method = method;
21249
21249
  this.url = url;
21250
- this.header = {};
21251
- this._header = {};
21250
+ this.header = {}; // preserves header name case
21251
+ this._header = {}; // coerces header names to lowercase
21252
21252
  this.on('end', function(){
21253
21253
  var err = null;
21254
21254
  var res = null;
@@ -21261,6 +21261,8 @@ function Request(method, url) {
21261
21261
  err.original = e;
21262
21262
  // issue #675: return the raw response if the response parsing fails
21263
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;
21264
21266
  return self.callback(err);
21265
21267
  }
21266
21268
 
@@ -21270,178 +21272,76 @@ function Request(method, url) {
21270
21272
  return self.callback(err, res);
21271
21273
  }
21272
21274
 
21273
- if (res.status >= 200 && res.status < 300) {
21274
- return self.callback(err, res);
21275
- }
21275
+ try {
21276
+ if (res.status >= 200 && res.status < 300) {
21277
+ return self.callback(err, res);
21278
+ }
21276
21279
 
21277
- var new_err = new Error(res.statusText || 'Unsuccessful HTTP response');
21278
- new_err.original = err;
21279
- new_err.response = res;
21280
- 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;
21281
21284
 
21282
- 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
+ }
21283
21289
  });
21284
21290
  }
21285
21291
 
21286
21292
  /**
21287
- * Mixin `Emitter`.
21293
+ * Mixin `Emitter` and `requestBase`.
21288
21294
  */
21289
21295
 
21290
21296
  Emitter(Request.prototype);
21291
-
21292
- /**
21293
- * Allow for extension
21294
- */
21295
-
21296
- Request.prototype.use = function(fn) {
21297
- fn(this);
21298
- return this;
21297
+ for (var key in requestBase) {
21298
+ Request.prototype[key] = requestBase[key];
21299
21299
  }
21300
21300
 
21301
21301
  /**
21302
- * Set timeout to `ms`.
21302
+ * Set Content-Type to `type`, mapping values from `request.types`.
21303
21303
  *
21304
- * @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
21305
21319
  * @return {Request} for chaining
21306
21320
  * @api public
21307
21321
  */
21308
21322
 
21309
- Request.prototype.timeout = function(ms){
21310
- this._timeout = ms;
21323
+ Request.prototype.type = function(type){
21324
+ this.set('Content-Type', request.types[type] || type);
21311
21325
  return this;
21312
21326
  };
21313
21327
 
21314
21328
  /**
21315
- * Clear previous timeout.
21316
- *
21317
- * @return {Request} for chaining
21318
- * @api public
21319
- */
21320
-
21321
- Request.prototype.clearTimeout = function(){
21322
- this._timeout = 0;
21323
- clearTimeout(this._timer);
21324
- return this;
21325
- };
21326
-
21327
- /**
21328
- * Abort the request, and clear potential timeout.
21329
- *
21330
- * @return {Request}
21331
- * @api public
21332
- */
21333
-
21334
- Request.prototype.abort = function(){
21335
- if (this.aborted) return;
21336
- this.aborted = true;
21337
- this.xhr.abort();
21338
- this.clearTimeout();
21339
- this.emit('abort');
21340
- return this;
21341
- };
21342
-
21343
- /**
21344
- * Set header `field` to `val`, or multiple fields with one object.
21329
+ * Set responseType to `val`. Presently valid responseTypes are 'blob' and
21330
+ * 'arraybuffer'.
21345
21331
  *
21346
21332
  * Examples:
21347
21333
  *
21348
21334
  * req.get('/')
21349
- * .set('Accept', 'application/json')
21350
- * .set('X-API-Key', 'foobar')
21351
- * .end(callback);
21352
- *
21353
- * req.get('/')
21354
- * .set({ Accept: 'application/json', 'X-API-Key': 'foobar' })
21335
+ * .responseType('blob')
21355
21336
  * .end(callback);
21356
21337
  *
21357
- * @param {String|Object} field
21358
21338
  * @param {String} val
21359
21339
  * @return {Request} for chaining
21360
21340
  * @api public
21361
21341
  */
21362
21342
 
21363
- Request.prototype.set = function(field, val){
21364
- if (isObject(field)) {
21365
- for (var key in field) {
21366
- this.set(key, field[key]);
21367
- }
21368
- return this;
21369
- }
21370
- this._header[field.toLowerCase()] = val;
21371
- this.header[field] = val;
21372
- return this;
21373
- };
21374
-
21375
- /**
21376
- * Remove header `field`.
21377
- *
21378
- * Example:
21379
- *
21380
- * req.get('/')
21381
- * .unset('User-Agent')
21382
- * .end(callback);
21383
- *
21384
- * @param {String} field
21385
- * @return {Request} for chaining
21386
- * @api public
21387
- */
21388
-
21389
- Request.prototype.unset = function(field){
21390
- delete this._header[field.toLowerCase()];
21391
- delete this.header[field];
21392
- return this;
21393
- };
21394
-
21395
- /**
21396
- * Get case-insensitive header `field` value.
21397
- *
21398
- * @param {String} field
21399
- * @return {String}
21400
- * @api private
21401
- */
21402
-
21403
- Request.prototype.getHeader = function(field){
21404
- return this._header[field.toLowerCase()];
21405
- };
21406
-
21407
- /**
21408
- * Set Content-Type to `type`, mapping values from `request.types`.
21409
- *
21410
- * Examples:
21411
- *
21412
- * superagent.types.xml = 'application/xml';
21413
- *
21414
- * request.post('/')
21415
- * .type('xml')
21416
- * .send(xmlstring)
21417
- * .end(callback);
21418
- *
21419
- * request.post('/')
21420
- * .type('application/xml')
21421
- * .send(xmlstring)
21422
- * .end(callback);
21423
- *
21424
- * @param {String} type
21425
- * @return {Request} for chaining
21426
- * @api public
21427
- */
21428
-
21429
- Request.prototype.type = function(type){
21430
- this.set('Content-Type', request.types[type] || type);
21431
- return this;
21432
- };
21433
-
21434
- /**
21435
- * Force given parser
21436
- *
21437
- * Sets the body parser no matter type.
21438
- *
21439
- * @param {Function}
21440
- * @api public
21441
- */
21442
-
21443
- Request.prototype.parse = function(fn){
21444
- this._parser = fn;
21343
+ Request.prototype.responseType = function(val){
21344
+ this._responseType = val;
21445
21345
  return this;
21446
21346
  };
21447
21347
 
@@ -21475,13 +21375,29 @@ Request.prototype.accept = function(type){
21475
21375
  *
21476
21376
  * @param {String} user
21477
21377
  * @param {String} pass
21378
+ * @param {Object} options with 'type' property 'auto' or 'basic' (default 'basic')
21478
21379
  * @return {Request} for chaining
21479
21380
  * @api public
21480
21381
  */
21481
21382
 
21482
- Request.prototype.auth = function(user, pass){
21483
- var str = btoa(user + ':' + pass);
21484
- 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
+ }
21485
21401
  return this;
21486
21402
  };
21487
21403
 
@@ -21505,35 +21421,13 @@ Request.prototype.query = function(val){
21505
21421
  return this;
21506
21422
  };
21507
21423
 
21508
- /**
21509
- * Write the field `name` and `val` for "multipart/form-data"
21510
- * request bodies.
21511
- *
21512
- * ``` js
21513
- * request.post('/upload')
21514
- * .field('foo', 'bar')
21515
- * .end(callback);
21516
- * ```
21517
- *
21518
- * @param {String} name
21519
- * @param {String|Blob|File} val
21520
- * @return {Request} for chaining
21521
- * @api public
21522
- */
21523
-
21524
- Request.prototype.field = function(name, val){
21525
- if (!this._formData) this._formData = new root.FormData();
21526
- this._formData.append(name, val);
21527
- return this;
21528
- };
21529
-
21530
21424
  /**
21531
21425
  * Queue the given `file` as an attachment to the specified `field`,
21532
21426
  * with optional `filename`.
21533
21427
  *
21534
21428
  * ``` js
21535
21429
  * request.post('/upload')
21536
- * .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"}))
21537
21431
  * .end(callback);
21538
21432
  * ```
21539
21433
  *
@@ -21545,77 +21439,15 @@ Request.prototype.field = function(name, val){
21545
21439
  */
21546
21440
 
21547
21441
  Request.prototype.attach = function(field, file, filename){
21548
- if (!this._formData) this._formData = new root.FormData();
21549
- this._formData.append(field, file, filename || file.name);
21442
+ this._getFormData().append(field, file, filename || file.name);
21550
21443
  return this;
21551
21444
  };
21552
21445
 
21553
- /**
21554
- * Send `data` as the request body, defaulting the `.type()` to "json" when
21555
- * an object is given.
21556
- *
21557
- * Examples:
21558
- *
21559
- * // manual json
21560
- * request.post('/user')
21561
- * .type('json')
21562
- * .send('{"name":"tj"}')
21563
- * .end(callback)
21564
- *
21565
- * // auto json
21566
- * request.post('/user')
21567
- * .send({ name: 'tj' })
21568
- * .end(callback)
21569
- *
21570
- * // manual x-www-form-urlencoded
21571
- * request.post('/user')
21572
- * .type('form')
21573
- * .send('name=tj')
21574
- * .end(callback)
21575
- *
21576
- * // auto x-www-form-urlencoded
21577
- * request.post('/user')
21578
- * .type('form')
21579
- * .send({ name: 'tj' })
21580
- * .end(callback)
21581
- *
21582
- * // defaults to x-www-form-urlencoded
21583
- * request.post('/user')
21584
- * .send('name=tobi')
21585
- * .send('species=ferret')
21586
- * .end(callback)
21587
- *
21588
- * @param {String|Object} data
21589
- * @return {Request} for chaining
21590
- * @api public
21591
- */
21592
-
21593
- Request.prototype.send = function(data){
21594
- var obj = isObject(data);
21595
- var type = this.getHeader('Content-Type');
21596
-
21597
- // merge
21598
- if (obj && isObject(this._data)) {
21599
- for (var key in data) {
21600
- this._data[key] = data[key];
21601
- }
21602
- } else if ('string' == typeof data) {
21603
- if (!type) this.type('form');
21604
- type = this.getHeader('Content-Type');
21605
- if ('application/x-www-form-urlencoded' == type) {
21606
- this._data = this._data
21607
- ? this._data + '&' + data
21608
- : data;
21609
- } else {
21610
- this._data = (this._data || '') + data;
21611
- }
21612
- } else {
21613
- this._data = data;
21446
+ Request.prototype._getFormData = function(){
21447
+ if (!this._formData) {
21448
+ this._formData = new root.FormData();
21614
21449
  }
21615
-
21616
- if (!obj || isHost(data)) return this;
21617
- if (!type) this.type('json');
21618
- return this;
21450
+ return this._formData;
21619
21451
  };
21620
21452
 
21621
21453
  /**
@@ -21656,7 +21488,7 @@ Request.prototype.crossDomainError = function(){
21656
21488
  * @api private
21657
21489
  */
21658
21490
 
21659
- Request.prototype.timeoutError = function(){
21491
+ Request.prototype._timeoutError = function(){
21660
21492
  var timeout = this._timeout;
21661
21493
  var err = new Error('timeout of ' + timeout + 'ms exceeded');
21662
21494
  err.timeout = timeout;
@@ -21664,19 +21496,18 @@ Request.prototype.timeoutError = function(){
21664
21496
  };
21665
21497
 
21666
21498
  /**
21667
- * Enable transmission of cookies with x-domain requests.
21668
- *
21669
- * Note that for this to work the origin must not be
21670
- * using "Access-Control-Allow-Origin" with a wildcard,
21671
- * and also must set "Access-Control-Allow-Credentials"
21672
- * to "true".
21499
+ * Compose querystring to append to req.url
21673
21500
  *
21674
- * @api public
21501
+ * @api private
21675
21502
  */
21676
21503
 
21677
- Request.prototype.withCredentials = function(){
21678
- this._withCredentials = true;
21679
- 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
+ }
21680
21511
  };
21681
21512
 
21682
21513
  /**
@@ -21691,7 +21522,6 @@ Request.prototype.withCredentials = function(){
21691
21522
  Request.prototype.end = function(fn){
21692
21523
  var self = this;
21693
21524
  var xhr = this.xhr = request.getXHR();
21694
- var query = this._query.join('&');
21695
21525
  var timeout = this._timeout;
21696
21526
  var data = this._formData || this._data;
21697
21527
 
@@ -21708,8 +21538,8 @@ Request.prototype.end = function(fn){
21708
21538
  try { status = xhr.status } catch(e) { status = 0; }
21709
21539
 
21710
21540
  if (0 == status) {
21711
- if (self.timedout) return self.timeoutError();
21712
- if (self.aborted) return;
21541
+ if (self.timedout) return self._timeoutError();
21542
+ if (self._aborted) return;
21713
21543
  return self.crossDomainError();
21714
21544
  }
21715
21545
  self.emit('end');
@@ -21745,24 +21575,23 @@ Request.prototype.end = function(fn){
21745
21575
  }
21746
21576
 
21747
21577
  // querystring
21748
- if (query) {
21749
- query = request.serializeObject(query);
21750
- this.url += ~this.url.indexOf('?')
21751
- ? '&' + query
21752
- : '?' + query;
21753
- }
21578
+ this._appendQueryString();
21754
21579
 
21755
21580
  // initiate request
21756
- 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
+ }
21757
21586
 
21758
21587
  // CORS
21759
21588
  if (this._withCredentials) xhr.withCredentials = true;
21760
21589
 
21761
21590
  // body
21762
- 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)) {
21763
21592
  // serialize stuff
21764
- var contentType = this.getHeader('Content-Type');
21765
- 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] : ''];
21766
21595
  if (!serialize && isJSON(contentType)) serialize = request.serialize['application/json'];
21767
21596
  if (serialize) data = serialize(data);
21768
21597
  }
@@ -21773,6 +21602,10 @@ Request.prototype.end = function(fn){
21773
21602
  xhr.setRequestHeader(field, this.header[field]);
21774
21603
  }
21775
21604
 
21605
+ if (this._responseType) {
21606
+ xhr.responseType = this._responseType;
21607
+ }
21608
+
21776
21609
  // send stuff
21777
21610
  this.emit('request', this);
21778
21611
 
@@ -21782,19 +21615,6 @@ Request.prototype.end = function(fn){
21782
21615
  return this;
21783
21616
  };
21784
21617
 
21785
- /**
21786
- * Faux promise support
21787
- *
21788
- * @param {Function} fulfill
21789
- * @param {Function} reject
21790
- * @return {Request}
21791
- */
21792
-
21793
- Request.prototype.then = function (fulfill, reject) {
21794
- return this.end(function(err, res) {
21795
- err ? reject(err) : fulfill(res);
21796
- });
21797
- }
21798
21618
 
21799
21619
  /**
21800
21620
  * Expose `Request`.
@@ -21802,35 +21622,6 @@ Request.prototype.then = function (fulfill, reject) {
21802
21622
 
21803
21623
  request.Request = Request;
21804
21624
 
21805
- /**
21806
- * Issue a request:
21807
- *
21808
- * Examples:
21809
- *
21810
- * request('GET', '/users').end(callback)
21811
- * request('/users').end(callback)
21812
- * request('/users', callback)
21813
- *
21814
- * @param {String} method
21815
- * @param {String|Function} url or callback
21816
- * @return {Request}
21817
- * @api public
21818
- */
21819
-
21820
- function request(method, url) {
21821
- // callback
21822
- if ('function' == typeof url) {
21823
- return new Request('GET', method).end(url);
21824
- }
21825
-
21826
- // url first
21827
- if (1 == arguments.length) {
21828
- return new Request('GET', method);
21829
- }
21830
-
21831
- return new Request(method, url);
21832
- }
21833
-
21834
21625
  /**
21835
21626
  * GET `url` with optional callback `fn(res)`.
21836
21627
  *
@@ -21868,34 +21659,52 @@ request.head = function(url, data, fn){
21868
21659
  };
21869
21660
 
21870
21661
  /**
21871
- * DELETE `url` with optional callback `fn(res)`.
21662
+ * OPTIONS query to `url` with optional callback `fn(res)`.
21872
21663
  *
21873
21664
  * @param {String} url
21665
+ * @param {Mixed|Function} data or fn
21874
21666
  * @param {Function} fn
21875
21667
  * @return {Request}
21876
21668
  * @api public
21877
21669
  */
21878
21670
 
21879
- function del(url, fn){
21880
- 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);
21881
21675
  if (fn) req.end(fn);
21882
21676
  return req;
21883
21677
  };
21884
21678
 
21885
- request['del'] = del;
21886
- request['delete'] = del;
21887
-
21888
21679
  /**
21889
- * PATCH `url` with optional `data` and callback `fn(res)`.
21680
+ * DELETE `url` with optional callback `fn(res)`.
21890
21681
  *
21891
21682
  * @param {String} url
21892
- * @param {Mixed} data
21893
21683
  * @param {Function} fn
21894
21684
  * @return {Request}
21895
21685
  * @api public
21896
21686
  */
21897
21687
 
21898
- request.patch = function(url, data, fn){
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
21702
+ * @param {Function} fn
21703
+ * @return {Request}
21704
+ * @api public
21705
+ */
21706
+
21707
+ request.patch = function(url, data, fn){
21899
21708
  var req = request('PATCH', url);
21900
21709
  if ('function' == typeof data) fn = data, data = null;
21901
21710
  if (data) req.send(data);
@@ -21939,13 +21748,404 @@ request.put = function(url, data, fn){
21939
21748
  return req;
21940
21749
  };
21941
21750
 
21751
+ },{"./is-object":50,"./request":52,"./request-base":51,"emitter":40,"reduce":47}],50:[function(require,module,exports){
21942
21752
  /**
21943
- * 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
21944
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
22130
+ */
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
+ }
21945
22145
 
21946
22146
  module.exports = request;
21947
22147
 
21948
- },{"emitter":40,"reduce":47}],50:[function(require,module,exports){
22148
+ },{}],53:[function(require,module,exports){
21949
22149
  /*!
21950
22150
  * validate.js 0.9.0
21951
22151
  *