comprodls-sdk 2.46.0 → 2.46.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1131,7 +1131,7 @@ validator.validators.contains = function(value, options) {
1131
1131
  }
1132
1132
  }
1133
1133
  };
1134
- },{"./errors":7,"validate.js":95}],10:[function(require,module,exports){
1134
+ },{"./errors":7,"validate.js":92}],10:[function(require,module,exports){
1135
1135
  /*************************************************************************
1136
1136
  *
1137
1137
  * COMPRO CONFIDENTIAL
@@ -11318,7 +11318,7 @@ function createStatement(options) {
11318
11318
  }*/
11319
11319
 
11320
11320
 
11321
- },{"../../helpers":3,"q":58,"tincanjs":92}],24:[function(require,module,exports){
11321
+ },{"../../helpers":3,"q":58,"tincanjs":89}],24:[function(require,module,exports){
11322
11322
  /*************************************************************************
11323
11323
  *
11324
11324
  * COMPRO CONFIDENTIAL
@@ -17621,181 +17621,167 @@ module.exports = {
17621
17621
  }
17622
17622
 
17623
17623
  },{}],42:[function(require,module,exports){
17624
-
17625
- /**
17626
- * Expose `Emitter`.
17627
- */
17628
-
17629
- if (typeof module !== 'undefined') {
17630
- module.exports = Emitter;
17631
- }
17632
-
17633
- /**
17634
- * Initialize a new `Emitter`.
17635
- *
17636
- * @api public
17637
- */
17638
-
17639
- function Emitter(obj) {
17640
- if (obj) return mixin(obj);
17641
- };
17642
-
17643
- /**
17644
- * Mixin the emitter properties.
17645
- *
17646
- * @param {Object} obj
17647
- * @return {Object}
17648
- * @api private
17649
- */
17650
-
17651
- function mixin(obj) {
17652
- for (var key in Emitter.prototype) {
17653
- obj[key] = Emitter.prototype[key];
17654
- }
17655
- return obj;
17656
- }
17657
-
17658
- /**
17659
- * Listen on the given `event` with `fn`.
17660
- *
17661
- * @param {String} event
17662
- * @param {Function} fn
17663
- * @return {Emitter}
17664
- * @api public
17665
- */
17666
-
17667
- Emitter.prototype.on =
17668
- Emitter.prototype.addEventListener = function(event, fn){
17669
- this._callbacks = this._callbacks || {};
17670
- (this._callbacks['$' + event] = this._callbacks['$' + event] || [])
17671
- .push(fn);
17672
- return this;
17673
- };
17674
-
17675
- /**
17676
- * Adds an `event` listener that will be invoked a single
17677
- * time then automatically removed.
17678
- *
17679
- * @param {String} event
17680
- * @param {Function} fn
17681
- * @return {Emitter}
17682
- * @api public
17683
- */
17684
-
17685
- Emitter.prototype.once = function(event, fn){
17686
- function on() {
17687
- this.off(event, on);
17688
- fn.apply(this, arguments);
17689
- }
17690
-
17691
- on.fn = fn;
17692
- this.on(event, on);
17693
- return this;
17694
- };
17695
-
17696
- /**
17697
- * Remove the given callback for `event` or all
17698
- * registered callbacks.
17699
- *
17700
- * @param {String} event
17701
- * @param {Function} fn
17702
- * @return {Emitter}
17703
- * @api public
17704
- */
17705
-
17706
- Emitter.prototype.off =
17707
- Emitter.prototype.removeListener =
17708
- Emitter.prototype.removeAllListeners =
17709
- Emitter.prototype.removeEventListener = function(event, fn){
17710
- this._callbacks = this._callbacks || {};
17711
-
17712
- // all
17713
- if (0 == arguments.length) {
17714
- this._callbacks = {};
17715
- return this;
17716
- }
17717
-
17718
- // specific event
17719
- var callbacks = this._callbacks['$' + event];
17720
- if (!callbacks) return this;
17721
-
17722
- // remove all handlers
17723
- if (1 == arguments.length) {
17724
- delete this._callbacks['$' + event];
17725
- return this;
17726
- }
17727
-
17728
- // remove specific handler
17729
- var cb;
17730
- for (var i = 0; i < callbacks.length; i++) {
17731
- cb = callbacks[i];
17732
- if (cb === fn || cb.fn === fn) {
17733
- callbacks.splice(i, 1);
17734
- break;
17735
- }
17736
- }
17737
-
17738
- // Remove event specific arrays for event types that no
17739
- // one is subscribed for to avoid memory leak.
17740
- if (callbacks.length === 0) {
17741
- delete this._callbacks['$' + event];
17742
- }
17743
-
17744
- return this;
17745
- };
17746
-
17747
- /**
17748
- * Emit `event` with the given args.
17749
- *
17750
- * @param {String} event
17751
- * @param {Mixed} ...
17752
- * @return {Emitter}
17753
- */
17754
-
17755
- Emitter.prototype.emit = function(event){
17756
- this._callbacks = this._callbacks || {};
17757
-
17758
- var args = new Array(arguments.length - 1)
17759
- , callbacks = this._callbacks['$' + event];
17760
-
17761
- for (var i = 1; i < arguments.length; i++) {
17762
- args[i - 1] = arguments[i];
17763
- }
17764
-
17765
- if (callbacks) {
17766
- callbacks = callbacks.slice(0);
17767
- for (var i = 0, len = callbacks.length; i < len; ++i) {
17768
- callbacks[i].apply(this, args);
17769
- }
17770
- }
17771
-
17772
- return this;
17773
- };
17774
-
17775
- /**
17776
- * Return array of callbacks for `event`.
17777
- *
17778
- * @param {String} event
17779
- * @return {Array}
17780
- * @api public
17781
- */
17782
-
17783
- Emitter.prototype.listeners = function(event){
17784
- this._callbacks = this._callbacks || {};
17785
- return this._callbacks['$' + event] || [];
17786
- };
17787
-
17788
- /**
17789
- * Check if this emitter has `event` handlers.
17790
- *
17791
- * @param {String} event
17792
- * @return {Boolean}
17793
- * @api public
17794
- */
17795
-
17796
- Emitter.prototype.hasListeners = function(event){
17797
- return !! this.listeners(event).length;
17798
- };
17624
+
17625
+ /**
17626
+ * Expose `Emitter`.
17627
+ */
17628
+
17629
+ module.exports = Emitter;
17630
+
17631
+ /**
17632
+ * Initialize a new `Emitter`.
17633
+ *
17634
+ * @api public
17635
+ */
17636
+
17637
+ function Emitter(obj) {
17638
+ if (obj) return mixin(obj);
17639
+ };
17640
+
17641
+ /**
17642
+ * Mixin the emitter properties.
17643
+ *
17644
+ * @param {Object} obj
17645
+ * @return {Object}
17646
+ * @api private
17647
+ */
17648
+
17649
+ function mixin(obj) {
17650
+ for (var key in Emitter.prototype) {
17651
+ obj[key] = Emitter.prototype[key];
17652
+ }
17653
+ return obj;
17654
+ }
17655
+
17656
+ /**
17657
+ * Listen on the given `event` with `fn`.
17658
+ *
17659
+ * @param {String} event
17660
+ * @param {Function} fn
17661
+ * @return {Emitter}
17662
+ * @api public
17663
+ */
17664
+
17665
+ Emitter.prototype.on =
17666
+ Emitter.prototype.addEventListener = function(event, fn){
17667
+ this._callbacks = this._callbacks || {};
17668
+ (this._callbacks['$' + event] = this._callbacks['$' + event] || [])
17669
+ .push(fn);
17670
+ return this;
17671
+ };
17672
+
17673
+ /**
17674
+ * Adds an `event` listener that will be invoked a single
17675
+ * time then automatically removed.
17676
+ *
17677
+ * @param {String} event
17678
+ * @param {Function} fn
17679
+ * @return {Emitter}
17680
+ * @api public
17681
+ */
17682
+
17683
+ Emitter.prototype.once = function(event, fn){
17684
+ function on() {
17685
+ this.off(event, on);
17686
+ fn.apply(this, arguments);
17687
+ }
17688
+
17689
+ on.fn = fn;
17690
+ this.on(event, on);
17691
+ return this;
17692
+ };
17693
+
17694
+ /**
17695
+ * Remove the given callback for `event` or all
17696
+ * registered callbacks.
17697
+ *
17698
+ * @param {String} event
17699
+ * @param {Function} fn
17700
+ * @return {Emitter}
17701
+ * @api public
17702
+ */
17703
+
17704
+ Emitter.prototype.off =
17705
+ Emitter.prototype.removeListener =
17706
+ Emitter.prototype.removeAllListeners =
17707
+ Emitter.prototype.removeEventListener = function(event, fn){
17708
+ this._callbacks = this._callbacks || {};
17709
+
17710
+ // all
17711
+ if (0 == arguments.length) {
17712
+ this._callbacks = {};
17713
+ return this;
17714
+ }
17715
+
17716
+ // specific event
17717
+ var callbacks = this._callbacks['$' + event];
17718
+ if (!callbacks) return this;
17719
+
17720
+ // remove all handlers
17721
+ if (1 == arguments.length) {
17722
+ delete this._callbacks['$' + event];
17723
+ return this;
17724
+ }
17725
+
17726
+ // remove specific handler
17727
+ var cb;
17728
+ for (var i = 0; i < callbacks.length; i++) {
17729
+ cb = callbacks[i];
17730
+ if (cb === fn || cb.fn === fn) {
17731
+ callbacks.splice(i, 1);
17732
+ break;
17733
+ }
17734
+ }
17735
+ return this;
17736
+ };
17737
+
17738
+ /**
17739
+ * Emit `event` with the given args.
17740
+ *
17741
+ * @param {String} event
17742
+ * @param {Mixed} ...
17743
+ * @return {Emitter}
17744
+ */
17745
+
17746
+ Emitter.prototype.emit = function(event){
17747
+ this._callbacks = this._callbacks || {};
17748
+ var args = [].slice.call(arguments, 1)
17749
+ , callbacks = this._callbacks['$' + event];
17750
+
17751
+ if (callbacks) {
17752
+ callbacks = callbacks.slice(0);
17753
+ for (var i = 0, len = callbacks.length; i < len; ++i) {
17754
+ callbacks[i].apply(this, args);
17755
+ }
17756
+ }
17757
+
17758
+ return this;
17759
+ };
17760
+
17761
+ /**
17762
+ * Return array of callbacks for `event`.
17763
+ *
17764
+ * @param {String} event
17765
+ * @return {Array}
17766
+ * @api public
17767
+ */
17768
+
17769
+ Emitter.prototype.listeners = function(event){
17770
+ this._callbacks = this._callbacks || {};
17771
+ return this._callbacks['$' + event] || [];
17772
+ };
17773
+
17774
+ /**
17775
+ * Check if this emitter has `event` handlers.
17776
+ *
17777
+ * @param {String} event
17778
+ * @return {Boolean}
17779
+ * @api public
17780
+ */
17781
+
17782
+ Emitter.prototype.hasListeners = function(event){
17783
+ return !! this.listeners(event).length;
17784
+ };
17799
17785
 
17800
17786
  },{}],43:[function(require,module,exports){
17801
17787
  // Copyright Joyent, Inc. and other Node contributors.
@@ -18210,8 +18196,6 @@ function isUndefined(arg) {
18210
18196
  }
18211
18197
 
18212
18198
  },{}],45:[function(require,module,exports){
18213
- 'use strict';
18214
-
18215
18199
  var hasOwn = Object.prototype.hasOwnProperty;
18216
18200
  var toStr = Object.prototype.toString;
18217
18201
  var defineProperty = Object.defineProperty;
@@ -18226,6 +18210,8 @@ var isArray = function isArray(arr) {
18226
18210
  };
18227
18211
 
18228
18212
  var isPlainObject = function isPlainObject(obj) {
18213
+ 'use strict';
18214
+
18229
18215
  if (!obj || toStr.call(obj) !== '[object Object]') {
18230
18216
  return false;
18231
18217
  }
@@ -18275,6 +18261,8 @@ var getProperty = function getProperty(obj, name) {
18275
18261
  };
18276
18262
 
18277
18263
  module.exports = function extend() {
18264
+ 'use strict';
18265
+
18278
18266
  var options, name, src, copy, copyIsArray, clone;
18279
18267
  var target = arguments[0];
18280
18268
  var i = 1;
@@ -23822,7 +23810,7 @@ Writable.prototype._destroy = function (err, cb) {
23822
23810
  cb(err);
23823
23811
  };
23824
23812
  }).call(this,require('_process'),typeof global !== "undefined" ? global : typeof self !== "undefined" ? self : typeof window !== "undefined" ? window : {})
23825
- },{"./_stream_duplex":63,"./internal/streams/destroy":69,"./internal/streams/stream":70,"_process":55,"core-util-is":43,"inherits":71,"process-nextick-args":54,"safe-buffer":73,"util-deprecate":94}],68:[function(require,module,exports){
23813
+ },{"./_stream_duplex":63,"./internal/streams/destroy":69,"./internal/streams/stream":70,"_process":55,"core-util-is":43,"inherits":71,"process-nextick-args":54,"safe-buffer":73,"util-deprecate":91}],68:[function(require,module,exports){
23826
23814
  'use strict';
23827
23815
 
23828
23816
  function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
@@ -24630,7 +24618,7 @@ http.METHODS = [
24630
24618
  'UNLOCK',
24631
24619
  'UNSUBSCRIBE'
24632
24620
  ]
24633
- },{"./lib/request":84,"builtin-status-codes":41,"url":93,"xtend":97}],83:[function(require,module,exports){
24621
+ },{"./lib/request":84,"builtin-status-codes":41,"url":90,"xtend":94}],83:[function(require,module,exports){
24634
24622
  (function (global){
24635
24623
  exports.fetch = isFunction(global.fetch) && isFunction(global.ReadableByteStream)
24636
24624
 
@@ -25180,8 +25168,6 @@ function template(string) {
25180
25168
 
25181
25169
  var Emitter = require('emitter');
25182
25170
  var reduce = require('reduce');
25183
- var requestBase = require('./request-base');
25184
- var isObject = require('./is-object');
25185
25171
 
25186
25172
  /**
25187
25173
  * Root reference for iframes.
@@ -25203,10 +25189,28 @@ if (typeof window !== 'undefined') { // Browser window
25203
25189
  function noop(){};
25204
25190
 
25205
25191
  /**
25206
- * Expose `request`.
25192
+ * Check if `obj` is a host object,
25193
+ * we don't want to serialize these :)
25194
+ *
25195
+ * TODO: future proof, move to compoent land
25196
+ *
25197
+ * @param {Object} obj
25198
+ * @return {Boolean}
25199
+ * @api private
25207
25200
  */
25208
25201
 
25209
- var request = module.exports = require('./request').bind(null, Request);
25202
+ function isHost(obj) {
25203
+ var str = {}.toString.call(obj);
25204
+
25205
+ switch (str) {
25206
+ case '[object File]':
25207
+ case '[object Blob]':
25208
+ case '[object FormData]':
25209
+ return true;
25210
+ default:
25211
+ return false;
25212
+ }
25213
+ }
25210
25214
 
25211
25215
  /**
25212
25216
  * Determine XHR.
@@ -25238,6 +25242,18 @@ var trim = ''.trim
25238
25242
  ? function(s) { return s.trim(); }
25239
25243
  : function(s) { return s.replace(/(^\s*|\s*$)/g, ''); };
25240
25244
 
25245
+ /**
25246
+ * Check if `obj` is an object.
25247
+ *
25248
+ * @param {Object} obj
25249
+ * @return {Boolean}
25250
+ * @api private
25251
+ */
25252
+
25253
+ function isObject(obj) {
25254
+ return obj === Object(obj);
25255
+ }
25256
+
25241
25257
  /**
25242
25258
  * Serialize the given `obj`.
25243
25259
  *
@@ -25252,8 +25268,8 @@ function serialize(obj) {
25252
25268
  for (var key in obj) {
25253
25269
  if (null != obj[key]) {
25254
25270
  pushEncodedKeyValuePair(pairs, key, obj[key]);
25255
- }
25256
- }
25271
+ }
25272
+ }
25257
25273
  return pairs.join('&');
25258
25274
  }
25259
25275
 
@@ -25271,11 +25287,6 @@ function pushEncodedKeyValuePair(pairs, key, val) {
25271
25287
  return val.forEach(function(v) {
25272
25288
  pushEncodedKeyValuePair(pairs, key, v);
25273
25289
  });
25274
- } else if (isObject(val)) {
25275
- for(var subkey in val) {
25276
- pushEncodedKeyValuePair(pairs, key + '[' + subkey + ']', val[subkey]);
25277
- }
25278
- return;
25279
25290
  }
25280
25291
  pairs.push(encodeURIComponent(key)
25281
25292
  + '=' + encodeURIComponent(val));
@@ -25298,18 +25309,13 @@ function pushEncodedKeyValuePair(pairs, key, val) {
25298
25309
  function parseString(str) {
25299
25310
  var obj = {};
25300
25311
  var pairs = str.split('&');
25312
+ var parts;
25301
25313
  var pair;
25302
- var pos;
25303
25314
 
25304
25315
  for (var i = 0, len = pairs.length; i < len; ++i) {
25305
25316
  pair = pairs[i];
25306
- pos = pair.indexOf('=');
25307
- if (pos == -1) {
25308
- obj[decodeURIComponent(pair)] = '';
25309
- } else {
25310
- obj[decodeURIComponent(pair.slice(0, pos))] =
25311
- decodeURIComponent(pair.slice(pos + 1));
25312
- }
25317
+ parts = pair.split('=');
25318
+ obj[decodeURIComponent(parts[0])] = decodeURIComponent(parts[1]);
25313
25319
  }
25314
25320
 
25315
25321
  return obj;
@@ -25493,15 +25499,15 @@ function Response(req, options) {
25493
25499
  ? this.xhr.responseText
25494
25500
  : null;
25495
25501
  this.statusText = this.req.xhr.statusText;
25496
- this._setStatusProperties(this.xhr.status);
25502
+ this.setStatusProperties(this.xhr.status);
25497
25503
  this.header = this.headers = parseHeader(this.xhr.getAllResponseHeaders());
25498
25504
  // getAllResponseHeaders sometimes falsely returns "" for CORS requests, but
25499
25505
  // getResponseHeader still works. so we get content-type even if getting
25500
25506
  // other headers fails.
25501
25507
  this.header['content-type'] = this.xhr.getResponseHeader('content-type');
25502
- this._setHeaderProperties(this.header);
25508
+ this.setHeaderProperties(this.header);
25503
25509
  this.body = this.req.method != 'HEAD'
25504
- ? this._parseBody(this.text ? this.text : this.xhr.response)
25510
+ ? this.parseBody(this.text ? this.text : this.xhr.response)
25505
25511
  : null;
25506
25512
  }
25507
25513
 
@@ -25529,7 +25535,7 @@ Response.prototype.get = function(field){
25529
25535
  * @api private
25530
25536
  */
25531
25537
 
25532
- Response.prototype._setHeaderProperties = function(header){
25538
+ Response.prototype.setHeaderProperties = function(header){
25533
25539
  // content-type
25534
25540
  var ct = this.header['content-type'] || '';
25535
25541
  this.type = type(ct);
@@ -25550,11 +25556,8 @@ Response.prototype._setHeaderProperties = function(header){
25550
25556
  * @api private
25551
25557
  */
25552
25558
 
25553
- Response.prototype._parseBody = function(str){
25559
+ Response.prototype.parseBody = function(str){
25554
25560
  var parse = request.parse[this.type];
25555
- if (!parse && isJSON(this.type)) {
25556
- parse = request.parse['application/json'];
25557
- }
25558
25561
  return parse && str && (str.length || str instanceof Object)
25559
25562
  ? parse(str)
25560
25563
  : null;
@@ -25581,7 +25584,7 @@ Response.prototype._parseBody = function(str){
25581
25584
  * @api private
25582
25585
  */
25583
25586
 
25584
- Response.prototype._setStatusProperties = function(status){
25587
+ Response.prototype.setStatusProperties = function(status){
25585
25588
  // handle IE9 bug: http://stackoverflow.com/questions/10046972/msie-returns-status-code-of-1223-for-ajax-request
25586
25589
  if (status === 1223) {
25587
25590
  status = 204;
@@ -25649,11 +25652,12 @@ request.Response = Response;
25649
25652
 
25650
25653
  function Request(method, url) {
25651
25654
  var self = this;
25655
+ Emitter.call(this);
25652
25656
  this._query = this._query || [];
25653
25657
  this.method = method;
25654
25658
  this.url = url;
25655
- this.header = {}; // preserves header name case
25656
- this._header = {}; // coerces header names to lowercase
25659
+ this.header = {};
25660
+ this._header = {};
25657
25661
  this.on('end', function(){
25658
25662
  var err = null;
25659
25663
  var res = null;
@@ -25666,8 +25670,6 @@ function Request(method, url) {
25666
25670
  err.original = e;
25667
25671
  // issue #675: return the raw response if the response parsing fails
25668
25672
  err.rawResponse = self.xhr && self.xhr.responseText ? self.xhr.responseText : null;
25669
- // issue #876: return the http status code if the response parsing fails
25670
- err.statusCode = self.xhr && self.xhr.status ? self.xhr.status : null;
25671
25673
  return self.callback(err);
25672
25674
  }
25673
25675
 
@@ -25677,32 +25679,140 @@ function Request(method, url) {
25677
25679
  return self.callback(err, res);
25678
25680
  }
25679
25681
 
25680
- try {
25681
- if (res.status >= 200 && res.status < 300) {
25682
- return self.callback(err, res);
25683
- }
25682
+ if (res.status >= 200 && res.status < 300) {
25683
+ return self.callback(err, res);
25684
+ }
25684
25685
 
25685
- var new_err = new Error(res.statusText || 'Unsuccessful HTTP response');
25686
- new_err.original = err;
25687
- new_err.response = res;
25688
- new_err.status = res.status;
25686
+ var new_err = new Error(res.statusText || 'Unsuccessful HTTP response');
25687
+ new_err.original = err;
25688
+ new_err.response = res;
25689
+ new_err.status = res.status;
25689
25690
 
25690
- self.callback(new_err, res);
25691
- } catch(e) {
25692
- self.callback(e); // #985 touching res may cause INVALID_STATE_ERR on old Android
25693
- }
25691
+ self.callback(new_err, res);
25694
25692
  });
25695
25693
  }
25696
25694
 
25697
25695
  /**
25698
- * Mixin `Emitter` and `requestBase`.
25696
+ * Mixin `Emitter`.
25699
25697
  */
25700
25698
 
25701
25699
  Emitter(Request.prototype);
25702
- for (var key in requestBase) {
25703
- Request.prototype[key] = requestBase[key];
25700
+
25701
+ /**
25702
+ * Allow for extension
25703
+ */
25704
+
25705
+ Request.prototype.use = function(fn) {
25706
+ fn(this);
25707
+ return this;
25704
25708
  }
25705
25709
 
25710
+ /**
25711
+ * Set timeout to `ms`.
25712
+ *
25713
+ * @param {Number} ms
25714
+ * @return {Request} for chaining
25715
+ * @api public
25716
+ */
25717
+
25718
+ Request.prototype.timeout = function(ms){
25719
+ this._timeout = ms;
25720
+ return this;
25721
+ };
25722
+
25723
+ /**
25724
+ * Clear previous timeout.
25725
+ *
25726
+ * @return {Request} for chaining
25727
+ * @api public
25728
+ */
25729
+
25730
+ Request.prototype.clearTimeout = function(){
25731
+ this._timeout = 0;
25732
+ clearTimeout(this._timer);
25733
+ return this;
25734
+ };
25735
+
25736
+ /**
25737
+ * Abort the request, and clear potential timeout.
25738
+ *
25739
+ * @return {Request}
25740
+ * @api public
25741
+ */
25742
+
25743
+ Request.prototype.abort = function(){
25744
+ if (this.aborted) return;
25745
+ this.aborted = true;
25746
+ this.xhr.abort();
25747
+ this.clearTimeout();
25748
+ this.emit('abort');
25749
+ return this;
25750
+ };
25751
+
25752
+ /**
25753
+ * Set header `field` to `val`, or multiple fields with one object.
25754
+ *
25755
+ * Examples:
25756
+ *
25757
+ * req.get('/')
25758
+ * .set('Accept', 'application/json')
25759
+ * .set('X-API-Key', 'foobar')
25760
+ * .end(callback);
25761
+ *
25762
+ * req.get('/')
25763
+ * .set({ Accept: 'application/json', 'X-API-Key': 'foobar' })
25764
+ * .end(callback);
25765
+ *
25766
+ * @param {String|Object} field
25767
+ * @param {String} val
25768
+ * @return {Request} for chaining
25769
+ * @api public
25770
+ */
25771
+
25772
+ Request.prototype.set = function(field, val){
25773
+ if (isObject(field)) {
25774
+ for (var key in field) {
25775
+ this.set(key, field[key]);
25776
+ }
25777
+ return this;
25778
+ }
25779
+ this._header[field.toLowerCase()] = val;
25780
+ this.header[field] = val;
25781
+ return this;
25782
+ };
25783
+
25784
+ /**
25785
+ * Remove header `field`.
25786
+ *
25787
+ * Example:
25788
+ *
25789
+ * req.get('/')
25790
+ * .unset('User-Agent')
25791
+ * .end(callback);
25792
+ *
25793
+ * @param {String} field
25794
+ * @return {Request} for chaining
25795
+ * @api public
25796
+ */
25797
+
25798
+ Request.prototype.unset = function(field){
25799
+ delete this._header[field.toLowerCase()];
25800
+ delete this.header[field];
25801
+ return this;
25802
+ };
25803
+
25804
+ /**
25805
+ * Get case-insensitive header `field` value.
25806
+ *
25807
+ * @param {String} field
25808
+ * @return {String}
25809
+ * @api private
25810
+ */
25811
+
25812
+ Request.prototype.getHeader = function(field){
25813
+ return this._header[field.toLowerCase()];
25814
+ };
25815
+
25706
25816
  /**
25707
25817
  * Set Content-Type to `type`, mapping values from `request.types`.
25708
25818
  *
@@ -25731,22 +25841,16 @@ Request.prototype.type = function(type){
25731
25841
  };
25732
25842
 
25733
25843
  /**
25734
- * Set responseType to `val`. Presently valid responseTypes are 'blob' and
25735
- * 'arraybuffer'.
25844
+ * Force given parser
25736
25845
  *
25737
- * Examples:
25846
+ * Sets the body parser no matter type.
25738
25847
  *
25739
- * req.get('/')
25740
- * .responseType('blob')
25741
- * .end(callback);
25742
- *
25743
- * @param {String} val
25744
- * @return {Request} for chaining
25848
+ * @param {Function}
25745
25849
  * @api public
25746
25850
  */
25747
25851
 
25748
- Request.prototype.responseType = function(val){
25749
- this._responseType = val;
25852
+ Request.prototype.parse = function(fn){
25853
+ this._parser = fn;
25750
25854
  return this;
25751
25855
  };
25752
25856
 
@@ -25780,29 +25884,13 @@ Request.prototype.accept = function(type){
25780
25884
  *
25781
25885
  * @param {String} user
25782
25886
  * @param {String} pass
25783
- * @param {Object} options with 'type' property 'auto' or 'basic' (default 'basic')
25784
25887
  * @return {Request} for chaining
25785
25888
  * @api public
25786
25889
  */
25787
25890
 
25788
- Request.prototype.auth = function(user, pass, options){
25789
- if (!options) {
25790
- options = {
25791
- type: 'basic'
25792
- }
25793
- }
25794
-
25795
- switch (options.type) {
25796
- case 'basic':
25797
- var str = btoa(user + ':' + pass);
25798
- this.set('Authorization', 'Basic ' + str);
25799
- break;
25800
-
25801
- case 'auto':
25802
- this.username = user;
25803
- this.password = pass;
25804
- break;
25805
- }
25891
+ Request.prototype.auth = function(user, pass){
25892
+ var str = btoa(user + ':' + pass);
25893
+ this.set('Authorization', 'Basic ' + str);
25806
25894
  return this;
25807
25895
  };
25808
25896
 
@@ -25826,516 +25914,6 @@ Request.prototype.query = function(val){
25826
25914
  return this;
25827
25915
  };
25828
25916
 
25829
- /**
25830
- * Queue the given `file` as an attachment to the specified `field`,
25831
- * with optional `filename`.
25832
- *
25833
- * ``` js
25834
- * request.post('/upload')
25835
- * .attach('content', new Blob(['<a id="a"><b id="b">hey!</b></a>'], { type: "text/html"}))
25836
- * .end(callback);
25837
- * ```
25838
- *
25839
- * @param {String} field
25840
- * @param {Blob|File} file
25841
- * @param {String} filename
25842
- * @return {Request} for chaining
25843
- * @api public
25844
- */
25845
-
25846
- Request.prototype.attach = function(field, file, filename){
25847
- this._getFormData().append(field, file, filename || file.name);
25848
- return this;
25849
- };
25850
-
25851
- Request.prototype._getFormData = function(){
25852
- if (!this._formData) {
25853
- this._formData = new root.FormData();
25854
- }
25855
- return this._formData;
25856
- };
25857
-
25858
- /**
25859
- * Invoke the callback with `err` and `res`
25860
- * and handle arity check.
25861
- *
25862
- * @param {Error} err
25863
- * @param {Response} res
25864
- * @api private
25865
- */
25866
-
25867
- Request.prototype.callback = function(err, res){
25868
- var fn = this._callback;
25869
- this.clearTimeout();
25870
- fn(err, res);
25871
- };
25872
-
25873
- /**
25874
- * Invoke callback with x-domain error.
25875
- *
25876
- * @api private
25877
- */
25878
-
25879
- Request.prototype.crossDomainError = function(){
25880
- var err = new Error('Request has been terminated\nPossible causes: the network is offline, Origin is not allowed by Access-Control-Allow-Origin, the page is being unloaded, etc.');
25881
- err.crossDomain = true;
25882
-
25883
- err.status = this.status;
25884
- err.method = this.method;
25885
- err.url = this.url;
25886
-
25887
- this.callback(err);
25888
- };
25889
-
25890
- /**
25891
- * Invoke callback with timeout error.
25892
- *
25893
- * @api private
25894
- */
25895
-
25896
- Request.prototype._timeoutError = function(){
25897
- var timeout = this._timeout;
25898
- var err = new Error('timeout of ' + timeout + 'ms exceeded');
25899
- err.timeout = timeout;
25900
- this.callback(err);
25901
- };
25902
-
25903
- /**
25904
- * Compose querystring to append to req.url
25905
- *
25906
- * @api private
25907
- */
25908
-
25909
- Request.prototype._appendQueryString = function(){
25910
- var query = this._query.join('&');
25911
- if (query) {
25912
- this.url += ~this.url.indexOf('?')
25913
- ? '&' + query
25914
- : '?' + query;
25915
- }
25916
- };
25917
-
25918
- /**
25919
- * Initiate request, invoking callback `fn(res)`
25920
- * with an instanceof `Response`.
25921
- *
25922
- * @param {Function} fn
25923
- * @return {Request} for chaining
25924
- * @api public
25925
- */
25926
-
25927
- Request.prototype.end = function(fn){
25928
- var self = this;
25929
- var xhr = this.xhr = request.getXHR();
25930
- var timeout = this._timeout;
25931
- var data = this._formData || this._data;
25932
-
25933
- // store callback
25934
- this._callback = fn || noop;
25935
-
25936
- // state change
25937
- xhr.onreadystatechange = function(){
25938
- if (4 != xhr.readyState) return;
25939
-
25940
- // In IE9, reads to any property (e.g. status) off of an aborted XHR will
25941
- // result in the error "Could not complete the operation due to error c00c023f"
25942
- var status;
25943
- try { status = xhr.status } catch(e) { status = 0; }
25944
-
25945
- if (0 == status) {
25946
- if (self.timedout) return self._timeoutError();
25947
- if (self._aborted) return;
25948
- return self.crossDomainError();
25949
- }
25950
- self.emit('end');
25951
- };
25952
-
25953
- // progress
25954
- var handleProgress = function(e){
25955
- if (e.total > 0) {
25956
- e.percent = e.loaded / e.total * 100;
25957
- }
25958
- e.direction = 'download';
25959
- self.emit('progress', e);
25960
- };
25961
- if (this.hasListeners('progress')) {
25962
- xhr.onprogress = handleProgress;
25963
- }
25964
- try {
25965
- if (xhr.upload && this.hasListeners('progress')) {
25966
- xhr.upload.onprogress = handleProgress;
25967
- }
25968
- } catch(e) {
25969
- // Accessing xhr.upload fails in IE from a web worker, so just pretend it doesn't exist.
25970
- // Reported here:
25971
- // https://connect.microsoft.com/IE/feedback/details/837245/xmlhttprequest-upload-throws-invalid-argument-when-used-from-web-worker-context
25972
- }
25973
-
25974
- // timeout
25975
- if (timeout && !this._timer) {
25976
- this._timer = setTimeout(function(){
25977
- self.timedout = true;
25978
- self.abort();
25979
- }, timeout);
25980
- }
25981
-
25982
- // querystring
25983
- this._appendQueryString();
25984
-
25985
- // initiate request
25986
- if (this.username && this.password) {
25987
- xhr.open(this.method, this.url, true, this.username, this.password);
25988
- } else {
25989
- xhr.open(this.method, this.url, true);
25990
- }
25991
-
25992
- // CORS
25993
- if (this._withCredentials) xhr.withCredentials = true;
25994
-
25995
- // body
25996
- if ('GET' != this.method && 'HEAD' != this.method && 'string' != typeof data && !this._isHost(data)) {
25997
- // serialize stuff
25998
- var contentType = this._header['content-type'];
25999
- var serialize = this._serializer || request.serialize[contentType ? contentType.split(';')[0] : ''];
26000
- if (!serialize && isJSON(contentType)) serialize = request.serialize['application/json'];
26001
- if (serialize) data = serialize(data);
26002
- }
26003
-
26004
- // set header fields
26005
- for (var field in this.header) {
26006
- if (null == this.header[field]) continue;
26007
- xhr.setRequestHeader(field, this.header[field]);
26008
- }
26009
-
26010
- if (this._responseType) {
26011
- xhr.responseType = this._responseType;
26012
- }
26013
-
26014
- // send stuff
26015
- this.emit('request', this);
26016
-
26017
- // IE11 xhr.send(undefined) sends 'undefined' string as POST payload (instead of nothing)
26018
- // We need null here if data is undefined
26019
- xhr.send(typeof data !== 'undefined' ? data : null);
26020
- return this;
26021
- };
26022
-
26023
-
26024
- /**
26025
- * Expose `Request`.
26026
- */
26027
-
26028
- request.Request = Request;
26029
-
26030
- /**
26031
- * GET `url` with optional callback `fn(res)`.
26032
- *
26033
- * @param {String} url
26034
- * @param {Mixed|Function} data or fn
26035
- * @param {Function} fn
26036
- * @return {Request}
26037
- * @api public
26038
- */
26039
-
26040
- request.get = function(url, data, fn){
26041
- var req = request('GET', url);
26042
- if ('function' == typeof data) fn = data, data = null;
26043
- if (data) req.query(data);
26044
- if (fn) req.end(fn);
26045
- return req;
26046
- };
26047
-
26048
- /**
26049
- * HEAD `url` with optional callback `fn(res)`.
26050
- *
26051
- * @param {String} url
26052
- * @param {Mixed|Function} data or fn
26053
- * @param {Function} fn
26054
- * @return {Request}
26055
- * @api public
26056
- */
26057
-
26058
- request.head = function(url, data, fn){
26059
- var req = request('HEAD', url);
26060
- if ('function' == typeof data) fn = data, data = null;
26061
- if (data) req.send(data);
26062
- if (fn) req.end(fn);
26063
- return req;
26064
- };
26065
-
26066
- /**
26067
- * OPTIONS query to `url` with optional callback `fn(res)`.
26068
- *
26069
- * @param {String} url
26070
- * @param {Mixed|Function} data or fn
26071
- * @param {Function} fn
26072
- * @return {Request}
26073
- * @api public
26074
- */
26075
-
26076
- request.options = function(url, data, fn){
26077
- var req = request('OPTIONS', url);
26078
- if ('function' == typeof data) fn = data, data = null;
26079
- if (data) req.send(data);
26080
- if (fn) req.end(fn);
26081
- return req;
26082
- };
26083
-
26084
- /**
26085
- * DELETE `url` with optional callback `fn(res)`.
26086
- *
26087
- * @param {String} url
26088
- * @param {Function} fn
26089
- * @return {Request}
26090
- * @api public
26091
- */
26092
-
26093
- function del(url, fn){
26094
- var req = request('DELETE', url);
26095
- if (fn) req.end(fn);
26096
- return req;
26097
- };
26098
-
26099
- request['del'] = del;
26100
- request['delete'] = del;
26101
-
26102
- /**
26103
- * PATCH `url` with optional `data` and callback `fn(res)`.
26104
- *
26105
- * @param {String} url
26106
- * @param {Mixed} data
26107
- * @param {Function} fn
26108
- * @return {Request}
26109
- * @api public
26110
- */
26111
-
26112
- request.patch = function(url, data, fn){
26113
- var req = request('PATCH', url);
26114
- if ('function' == typeof data) fn = data, data = null;
26115
- if (data) req.send(data);
26116
- if (fn) req.end(fn);
26117
- return req;
26118
- };
26119
-
26120
- /**
26121
- * POST `url` with optional `data` and callback `fn(res)`.
26122
- *
26123
- * @param {String} url
26124
- * @param {Mixed} data
26125
- * @param {Function} fn
26126
- * @return {Request}
26127
- * @api public
26128
- */
26129
-
26130
- request.post = function(url, data, fn){
26131
- var req = request('POST', url);
26132
- if ('function' == typeof data) fn = data, data = null;
26133
- if (data) req.send(data);
26134
- if (fn) req.end(fn);
26135
- return req;
26136
- };
26137
-
26138
- /**
26139
- * PUT `url` with optional `data` and callback `fn(res)`.
26140
- *
26141
- * @param {String} url
26142
- * @param {Mixed|Function} data or fn
26143
- * @param {Function} fn
26144
- * @return {Request}
26145
- * @api public
26146
- */
26147
-
26148
- request.put = function(url, data, fn){
26149
- var req = request('PUT', url);
26150
- if ('function' == typeof data) fn = data, data = null;
26151
- if (data) req.send(data);
26152
- if (fn) req.end(fn);
26153
- return req;
26154
- };
26155
-
26156
- },{"./is-object":89,"./request":91,"./request-base":90,"emitter":42,"reduce":79}],89:[function(require,module,exports){
26157
- /**
26158
- * Check if `obj` is an object.
26159
- *
26160
- * @param {Object} obj
26161
- * @return {Boolean}
26162
- * @api private
26163
- */
26164
-
26165
- function isObject(obj) {
26166
- return null !== obj && 'object' === typeof obj;
26167
- }
26168
-
26169
- module.exports = isObject;
26170
-
26171
- },{}],90:[function(require,module,exports){
26172
- /**
26173
- * Module of mixed-in functions shared between node and client code
26174
- */
26175
- var isObject = require('./is-object');
26176
-
26177
- /**
26178
- * Clear previous timeout.
26179
- *
26180
- * @return {Request} for chaining
26181
- * @api public
26182
- */
26183
-
26184
- exports.clearTimeout = function _clearTimeout(){
26185
- this._timeout = 0;
26186
- clearTimeout(this._timer);
26187
- return this;
26188
- };
26189
-
26190
- /**
26191
- * Override default response body parser
26192
- *
26193
- * This function will be called to convert incoming data into request.body
26194
- *
26195
- * @param {Function}
26196
- * @api public
26197
- */
26198
-
26199
- exports.parse = function parse(fn){
26200
- this._parser = fn;
26201
- return this;
26202
- };
26203
-
26204
- /**
26205
- * Override default request body serializer
26206
- *
26207
- * This function will be called to convert data set via .send or .attach into payload to send
26208
- *
26209
- * @param {Function}
26210
- * @api public
26211
- */
26212
-
26213
- exports.serialize = function serialize(fn){
26214
- this._serializer = fn;
26215
- return this;
26216
- };
26217
-
26218
- /**
26219
- * Set timeout to `ms`.
26220
- *
26221
- * @param {Number} ms
26222
- * @return {Request} for chaining
26223
- * @api public
26224
- */
26225
-
26226
- exports.timeout = function timeout(ms){
26227
- this._timeout = ms;
26228
- return this;
26229
- };
26230
-
26231
- /**
26232
- * Promise support
26233
- *
26234
- * @param {Function} resolve
26235
- * @param {Function} reject
26236
- * @return {Request}
26237
- */
26238
-
26239
- exports.then = function then(resolve, reject) {
26240
- if (!this._fullfilledPromise) {
26241
- var self = this;
26242
- this._fullfilledPromise = new Promise(function(innerResolve, innerReject){
26243
- self.end(function(err, res){
26244
- if (err) innerReject(err); else innerResolve(res);
26245
- });
26246
- });
26247
- }
26248
- return this._fullfilledPromise.then(resolve, reject);
26249
- }
26250
-
26251
- /**
26252
- * Allow for extension
26253
- */
26254
-
26255
- exports.use = function use(fn) {
26256
- fn(this);
26257
- return this;
26258
- }
26259
-
26260
-
26261
- /**
26262
- * Get request header `field`.
26263
- * Case-insensitive.
26264
- *
26265
- * @param {String} field
26266
- * @return {String}
26267
- * @api public
26268
- */
26269
-
26270
- exports.get = function(field){
26271
- return this._header[field.toLowerCase()];
26272
- };
26273
-
26274
- /**
26275
- * Get case-insensitive header `field` value.
26276
- * This is a deprecated internal API. Use `.get(field)` instead.
26277
- *
26278
- * (getHeader is no longer used internally by the superagent code base)
26279
- *
26280
- * @param {String} field
26281
- * @return {String}
26282
- * @api private
26283
- * @deprecated
26284
- */
26285
-
26286
- exports.getHeader = exports.get;
26287
-
26288
- /**
26289
- * Set header `field` to `val`, or multiple fields with one object.
26290
- * Case-insensitive.
26291
- *
26292
- * Examples:
26293
- *
26294
- * req.get('/')
26295
- * .set('Accept', 'application/json')
26296
- * .set('X-API-Key', 'foobar')
26297
- * .end(callback);
26298
- *
26299
- * req.get('/')
26300
- * .set({ Accept: 'application/json', 'X-API-Key': 'foobar' })
26301
- * .end(callback);
26302
- *
26303
- * @param {String|Object} field
26304
- * @param {String} val
26305
- * @return {Request} for chaining
26306
- * @api public
26307
- */
26308
-
26309
- exports.set = function(field, val){
26310
- if (isObject(field)) {
26311
- for (var key in field) {
26312
- this.set(key, field[key]);
26313
- }
26314
- return this;
26315
- }
26316
- this._header[field.toLowerCase()] = val;
26317
- this.header[field] = val;
26318
- return this;
26319
- };
26320
-
26321
- /**
26322
- * Remove header `field`.
26323
- * Case-insensitive.
26324
- *
26325
- * Example:
26326
- *
26327
- * req.get('/')
26328
- * .unset('User-Agent')
26329
- * .end(callback);
26330
- *
26331
- * @param {String} field
26332
- */
26333
- exports.unset = function(field){
26334
- delete this._header[field.toLowerCase()];
26335
- delete this.header[field];
26336
- return this;
26337
- };
26338
-
26339
25917
  /**
26340
25918
  * Write the field `name` and `val` for "multipart/form-data"
26341
25919
  * request bodies.
@@ -26347,104 +25925,40 @@ exports.unset = function(field){
26347
25925
  * ```
26348
25926
  *
26349
25927
  * @param {String} name
26350
- * @param {String|Blob|File|Buffer|fs.ReadStream} val
25928
+ * @param {String|Blob|File} val
26351
25929
  * @return {Request} for chaining
26352
25930
  * @api public
26353
25931
  */
26354
- exports.field = function(name, val) {
26355
- this._getFormData().append(name, val);
26356
- return this;
26357
- };
26358
25932
 
26359
- /**
26360
- * Abort the request, and clear potential timeout.
26361
- *
26362
- * @return {Request}
26363
- * @api public
26364
- */
26365
- exports.abort = function(){
26366
- if (this._aborted) {
26367
- return this;
26368
- }
26369
- this._aborted = true;
26370
- this.xhr && this.xhr.abort(); // browser
26371
- this.req && this.req.abort(); // node
26372
- this.clearTimeout();
26373
- this.emit('abort');
25933
+ Request.prototype.field = function(name, val){
25934
+ if (!this._formData) this._formData = new root.FormData();
25935
+ this._formData.append(name, val);
26374
25936
  return this;
26375
25937
  };
26376
25938
 
26377
25939
  /**
26378
- * Enable transmission of cookies with x-domain requests.
26379
- *
26380
- * Note that for this to work the origin must not be
26381
- * using "Access-Control-Allow-Origin" with a wildcard,
26382
- * and also must set "Access-Control-Allow-Credentials"
26383
- * to "true".
25940
+ * Queue the given `file` as an attachment to the specified `field`,
25941
+ * with optional `filename`.
26384
25942
  *
26385
- * @api public
26386
- */
26387
-
26388
- exports.withCredentials = function(){
26389
- // This is browser-only functionality. Node side is no-op.
26390
- this._withCredentials = true;
26391
- return this;
26392
- };
26393
-
26394
- /**
26395
- * Set the max redirects to `n`. Does noting in browser XHR implementation.
25943
+ * ``` js
25944
+ * request.post('/upload')
25945
+ * .attach(new Blob(['<a id="a"><b id="b">hey!</b></a>'], { type: "text/html"}))
25946
+ * .end(callback);
25947
+ * ```
26396
25948
  *
26397
- * @param {Number} n
25949
+ * @param {String} field
25950
+ * @param {Blob|File} file
25951
+ * @param {String} filename
26398
25952
  * @return {Request} for chaining
26399
25953
  * @api public
26400
25954
  */
26401
25955
 
26402
- exports.redirects = function(n){
26403
- this._maxRedirects = n;
25956
+ Request.prototype.attach = function(field, file, filename){
25957
+ if (!this._formData) this._formData = new root.FormData();
25958
+ this._formData.append(field, file, filename || file.name);
26404
25959
  return this;
26405
25960
  };
26406
25961
 
26407
- /**
26408
- * Convert to a plain javascript object (not JSON string) of scalar properties.
26409
- * Note as this method is designed to return a useful non-this value,
26410
- * it cannot be chained.
26411
- *
26412
- * @return {Object} describing method, url, and data of this request
26413
- * @api public
26414
- */
26415
-
26416
- exports.toJSON = function(){
26417
- return {
26418
- method: this.method,
26419
- url: this.url,
26420
- data: this._data
26421
- };
26422
- };
26423
-
26424
- /**
26425
- * Check if `obj` is a host object,
26426
- * we don't want to serialize these :)
26427
- *
26428
- * TODO: future proof, move to compoent land
26429
- *
26430
- * @param {Object} obj
26431
- * @return {Boolean}
26432
- * @api private
26433
- */
26434
-
26435
- exports._isHost = function _isHost(obj) {
26436
- var str = {}.toString.call(obj);
26437
-
26438
- switch (str) {
26439
- case '[object File]':
26440
- case '[object Blob]':
26441
- case '[object FormData]':
26442
- return true;
26443
- default:
26444
- return false;
26445
- }
26446
- }
26447
-
26448
25962
  /**
26449
25963
  * Send `data` as the request body, defaulting the `.type()` to "json" when
26450
25964
  * an object is given.
@@ -26475,19 +25989,19 @@ exports._isHost = function _isHost(obj) {
26475
25989
  * .end(callback)
26476
25990
  *
26477
25991
  * // defaults to x-www-form-urlencoded
26478
- * request.post('/user')
26479
- * .send('name=tobi')
26480
- * .send('species=ferret')
26481
- * .end(callback)
25992
+ * request.post('/user')
25993
+ * .send('name=tobi')
25994
+ * .send('species=ferret')
25995
+ * .end(callback)
26482
25996
  *
26483
25997
  * @param {String|Object} data
26484
25998
  * @return {Request} for chaining
26485
25999
  * @api public
26486
26000
  */
26487
26001
 
26488
- exports.send = function(data){
26002
+ Request.prototype.send = function(data){
26489
26003
  var obj = isObject(data);
26490
- var type = this._header['content-type'];
26004
+ var type = this.getHeader('Content-Type');
26491
26005
 
26492
26006
  // merge
26493
26007
  if (obj && isObject(this._data)) {
@@ -26495,9 +26009,8 @@ exports.send = function(data){
26495
26009
  this._data[key] = data[key];
26496
26010
  }
26497
26011
  } else if ('string' == typeof data) {
26498
- // default to x-www-form-urlencoded
26499
26012
  if (!type) this.type('form');
26500
- type = this._header['content-type'];
26013
+ type = this.getHeader('Content-Type');
26501
26014
  if ('application/x-www-form-urlencoded' == type) {
26502
26015
  this._data = this._data
26503
26016
  ? this._data + '&' + data
@@ -26509,16 +26022,195 @@ exports.send = function(data){
26509
26022
  this._data = data;
26510
26023
  }
26511
26024
 
26512
- if (!obj || this._isHost(data)) return this;
26513
-
26514
- // default to json
26025
+ if (!obj || isHost(data)) return this;
26515
26026
  if (!type) this.type('json');
26516
26027
  return this;
26517
26028
  };
26518
26029
 
26519
- },{"./is-object":89}],91:[function(require,module,exports){
26520
- // The node and browser modules expose versions of this with the
26521
- // appropriate constructor function bound as first argument
26030
+ /**
26031
+ * Invoke the callback with `err` and `res`
26032
+ * and handle arity check.
26033
+ *
26034
+ * @param {Error} err
26035
+ * @param {Response} res
26036
+ * @api private
26037
+ */
26038
+
26039
+ Request.prototype.callback = function(err, res){
26040
+ var fn = this._callback;
26041
+ this.clearTimeout();
26042
+ fn(err, res);
26043
+ };
26044
+
26045
+ /**
26046
+ * Invoke callback with x-domain error.
26047
+ *
26048
+ * @api private
26049
+ */
26050
+
26051
+ Request.prototype.crossDomainError = function(){
26052
+ var err = new Error('Request has been terminated\nPossible causes: the network is offline, Origin is not allowed by Access-Control-Allow-Origin, the page is being unloaded, etc.');
26053
+ err.crossDomain = true;
26054
+
26055
+ err.status = this.status;
26056
+ err.method = this.method;
26057
+ err.url = this.url;
26058
+
26059
+ this.callback(err);
26060
+ };
26061
+
26062
+ /**
26063
+ * Invoke callback with timeout error.
26064
+ *
26065
+ * @api private
26066
+ */
26067
+
26068
+ Request.prototype.timeoutError = function(){
26069
+ var timeout = this._timeout;
26070
+ var err = new Error('timeout of ' + timeout + 'ms exceeded');
26071
+ err.timeout = timeout;
26072
+ this.callback(err);
26073
+ };
26074
+
26075
+ /**
26076
+ * Enable transmission of cookies with x-domain requests.
26077
+ *
26078
+ * Note that for this to work the origin must not be
26079
+ * using "Access-Control-Allow-Origin" with a wildcard,
26080
+ * and also must set "Access-Control-Allow-Credentials"
26081
+ * to "true".
26082
+ *
26083
+ * @api public
26084
+ */
26085
+
26086
+ Request.prototype.withCredentials = function(){
26087
+ this._withCredentials = true;
26088
+ return this;
26089
+ };
26090
+
26091
+ /**
26092
+ * Initiate request, invoking callback `fn(res)`
26093
+ * with an instanceof `Response`.
26094
+ *
26095
+ * @param {Function} fn
26096
+ * @return {Request} for chaining
26097
+ * @api public
26098
+ */
26099
+
26100
+ Request.prototype.end = function(fn){
26101
+ var self = this;
26102
+ var xhr = this.xhr = request.getXHR();
26103
+ var query = this._query.join('&');
26104
+ var timeout = this._timeout;
26105
+ var data = this._formData || this._data;
26106
+
26107
+ // store callback
26108
+ this._callback = fn || noop;
26109
+
26110
+ // state change
26111
+ xhr.onreadystatechange = function(){
26112
+ if (4 != xhr.readyState) return;
26113
+
26114
+ // In IE9, reads to any property (e.g. status) off of an aborted XHR will
26115
+ // result in the error "Could not complete the operation due to error c00c023f"
26116
+ var status;
26117
+ try { status = xhr.status } catch(e) { status = 0; }
26118
+
26119
+ if (0 == status) {
26120
+ if (self.timedout) return self.timeoutError();
26121
+ if (self.aborted) return;
26122
+ return self.crossDomainError();
26123
+ }
26124
+ self.emit('end');
26125
+ };
26126
+
26127
+ // progress
26128
+ var handleProgress = function(e){
26129
+ if (e.total > 0) {
26130
+ e.percent = e.loaded / e.total * 100;
26131
+ }
26132
+ e.direction = 'download';
26133
+ self.emit('progress', e);
26134
+ };
26135
+ if (this.hasListeners('progress')) {
26136
+ xhr.onprogress = handleProgress;
26137
+ }
26138
+ try {
26139
+ if (xhr.upload && this.hasListeners('progress')) {
26140
+ xhr.upload.onprogress = handleProgress;
26141
+ }
26142
+ } catch(e) {
26143
+ // Accessing xhr.upload fails in IE from a web worker, so just pretend it doesn't exist.
26144
+ // Reported here:
26145
+ // https://connect.microsoft.com/IE/feedback/details/837245/xmlhttprequest-upload-throws-invalid-argument-when-used-from-web-worker-context
26146
+ }
26147
+
26148
+ // timeout
26149
+ if (timeout && !this._timer) {
26150
+ this._timer = setTimeout(function(){
26151
+ self.timedout = true;
26152
+ self.abort();
26153
+ }, timeout);
26154
+ }
26155
+
26156
+ // querystring
26157
+ if (query) {
26158
+ query = request.serializeObject(query);
26159
+ this.url += ~this.url.indexOf('?')
26160
+ ? '&' + query
26161
+ : '?' + query;
26162
+ }
26163
+
26164
+ // initiate request
26165
+ xhr.open(this.method, this.url, true);
26166
+
26167
+ // CORS
26168
+ if (this._withCredentials) xhr.withCredentials = true;
26169
+
26170
+ // body
26171
+ if ('GET' != this.method && 'HEAD' != this.method && 'string' != typeof data && !isHost(data)) {
26172
+ // serialize stuff
26173
+ var contentType = this.getHeader('Content-Type');
26174
+ var serialize = this._parser || request.serialize[contentType ? contentType.split(';')[0] : ''];
26175
+ if (!serialize && isJSON(contentType)) serialize = request.serialize['application/json'];
26176
+ if (serialize) data = serialize(data);
26177
+ }
26178
+
26179
+ // set header fields
26180
+ for (var field in this.header) {
26181
+ if (null == this.header[field]) continue;
26182
+ xhr.setRequestHeader(field, this.header[field]);
26183
+ }
26184
+
26185
+ // send stuff
26186
+ this.emit('request', this);
26187
+
26188
+ // IE11 xhr.send(undefined) sends 'undefined' string as POST payload (instead of nothing)
26189
+ // We need null here if data is undefined
26190
+ xhr.send(typeof data !== 'undefined' ? data : null);
26191
+ return this;
26192
+ };
26193
+
26194
+ /**
26195
+ * Faux promise support
26196
+ *
26197
+ * @param {Function} fulfill
26198
+ * @param {Function} reject
26199
+ * @return {Request}
26200
+ */
26201
+
26202
+ Request.prototype.then = function (fulfill, reject) {
26203
+ return this.end(function(err, res) {
26204
+ err ? reject(err) : fulfill(res);
26205
+ });
26206
+ }
26207
+
26208
+ /**
26209
+ * Expose `Request`.
26210
+ */
26211
+
26212
+ request.Request = Request;
26213
+
26522
26214
  /**
26523
26215
  * Issue a request:
26524
26216
  *
@@ -26534,23 +26226,135 @@ exports.send = function(data){
26534
26226
  * @api public
26535
26227
  */
26536
26228
 
26537
- function request(RequestConstructor, method, url) {
26229
+ function request(method, url) {
26538
26230
  // callback
26539
26231
  if ('function' == typeof url) {
26540
- return new RequestConstructor('GET', method).end(url);
26232
+ return new Request('GET', method).end(url);
26541
26233
  }
26542
26234
 
26543
26235
  // url first
26544
- if (2 == arguments.length) {
26545
- return new RequestConstructor('GET', method);
26236
+ if (1 == arguments.length) {
26237
+ return new Request('GET', method);
26546
26238
  }
26547
26239
 
26548
- return new RequestConstructor(method, url);
26240
+ return new Request(method, url);
26549
26241
  }
26550
26242
 
26243
+ /**
26244
+ * GET `url` with optional callback `fn(res)`.
26245
+ *
26246
+ * @param {String} url
26247
+ * @param {Mixed|Function} data or fn
26248
+ * @param {Function} fn
26249
+ * @return {Request}
26250
+ * @api public
26251
+ */
26252
+
26253
+ request.get = function(url, data, fn){
26254
+ var req = request('GET', url);
26255
+ if ('function' == typeof data) fn = data, data = null;
26256
+ if (data) req.query(data);
26257
+ if (fn) req.end(fn);
26258
+ return req;
26259
+ };
26260
+
26261
+ /**
26262
+ * HEAD `url` with optional callback `fn(res)`.
26263
+ *
26264
+ * @param {String} url
26265
+ * @param {Mixed|Function} data or fn
26266
+ * @param {Function} fn
26267
+ * @return {Request}
26268
+ * @api public
26269
+ */
26270
+
26271
+ request.head = function(url, data, fn){
26272
+ var req = request('HEAD', url);
26273
+ if ('function' == typeof data) fn = data, data = null;
26274
+ if (data) req.send(data);
26275
+ if (fn) req.end(fn);
26276
+ return req;
26277
+ };
26278
+
26279
+ /**
26280
+ * DELETE `url` with optional callback `fn(res)`.
26281
+ *
26282
+ * @param {String} url
26283
+ * @param {Function} fn
26284
+ * @return {Request}
26285
+ * @api public
26286
+ */
26287
+
26288
+ function del(url, fn){
26289
+ var req = request('DELETE', url);
26290
+ if (fn) req.end(fn);
26291
+ return req;
26292
+ };
26293
+
26294
+ request['del'] = del;
26295
+ request['delete'] = del;
26296
+
26297
+ /**
26298
+ * PATCH `url` with optional `data` and callback `fn(res)`.
26299
+ *
26300
+ * @param {String} url
26301
+ * @param {Mixed} data
26302
+ * @param {Function} fn
26303
+ * @return {Request}
26304
+ * @api public
26305
+ */
26306
+
26307
+ request.patch = function(url, data, fn){
26308
+ var req = request('PATCH', url);
26309
+ if ('function' == typeof data) fn = data, data = null;
26310
+ if (data) req.send(data);
26311
+ if (fn) req.end(fn);
26312
+ return req;
26313
+ };
26314
+
26315
+ /**
26316
+ * POST `url` with optional `data` and callback `fn(res)`.
26317
+ *
26318
+ * @param {String} url
26319
+ * @param {Mixed} data
26320
+ * @param {Function} fn
26321
+ * @return {Request}
26322
+ * @api public
26323
+ */
26324
+
26325
+ request.post = function(url, data, fn){
26326
+ var req = request('POST', url);
26327
+ if ('function' == typeof data) fn = data, data = null;
26328
+ if (data) req.send(data);
26329
+ if (fn) req.end(fn);
26330
+ return req;
26331
+ };
26332
+
26333
+ /**
26334
+ * PUT `url` with optional `data` and callback `fn(res)`.
26335
+ *
26336
+ * @param {String} url
26337
+ * @param {Mixed|Function} data or fn
26338
+ * @param {Function} fn
26339
+ * @return {Request}
26340
+ * @api public
26341
+ */
26342
+
26343
+ request.put = function(url, data, fn){
26344
+ var req = request('PUT', url);
26345
+ if ('function' == typeof data) fn = data, data = null;
26346
+ if (data) req.send(data);
26347
+ if (fn) req.end(fn);
26348
+ return req;
26349
+ };
26350
+
26351
+ /**
26352
+ * Expose `request`.
26353
+ */
26354
+
26551
26355
  module.exports = request;
26552
26356
 
26553
- },{}],92:[function(require,module,exports){
26357
+ },{"emitter":42,"reduce":79}],89:[function(require,module,exports){
26554
26358
  (function (Buffer){
26555
26359
  "0.50.0";
26556
26360
  /*
@@ -34747,7 +34551,7 @@ TinCan client library
34747
34551
  }());
34748
34552
 
34749
34553
  }).call(this,require("buffer").Buffer)
34750
- },{"buffer":39,"querystring":61,"xhr2":96}],93:[function(require,module,exports){
34554
+ },{"buffer":39,"querystring":61,"xhr2":93}],90:[function(require,module,exports){
34751
34555
  // Copyright Joyent, Inc. and other Node contributors.
34752
34556
  //
34753
34557
  // Permission is hereby granted, free of charge, to any person obtaining a
@@ -35456,7 +35260,7 @@ function isNullOrUndefined(arg) {
35456
35260
  return arg == null;
35457
35261
  }
35458
35262
 
35459
- },{"punycode":57,"querystring":61}],94:[function(require,module,exports){
35263
+ },{"punycode":57,"querystring":61}],91:[function(require,module,exports){
35460
35264
  (function (global){
35461
35265
 
35462
35266
  /**
@@ -35527,7 +35331,7 @@ function config (name) {
35527
35331
  }
35528
35332
 
35529
35333
  }).call(this,typeof global !== "undefined" ? global : typeof self !== "undefined" ? self : typeof window !== "undefined" ? window : {})
35530
- },{}],95:[function(require,module,exports){
35334
+ },{}],92:[function(require,module,exports){
35531
35335
  /*!
35532
35336
  * validate.js 0.9.0
35533
35337
  *
@@ -36615,7 +36419,7 @@ function config (name) {
36615
36419
  typeof module !== 'undefined' ? /* istanbul ignore next */ module : null,
36616
36420
  typeof define !== 'undefined' ? /* istanbul ignore next */ define : null);
36617
36421
 
36618
- },{}],96:[function(require,module,exports){
36422
+ },{}],93:[function(require,module,exports){
36619
36423
  (function (process,Buffer){
36620
36424
  // Generated by CoffeeScript 1.6.3
36621
36425
  (function() {
@@ -37453,7 +37257,7 @@ function config (name) {
37453
37257
  }).call(this);
37454
37258
 
37455
37259
  }).call(this,require('_process'),require("buffer").Buffer)
37456
- },{"_process":55,"buffer":39,"http":82,"https":47,"os":53,"url":93}],97:[function(require,module,exports){
37260
+ },{"_process":55,"buffer":39,"http":82,"https":47,"os":53,"url":90}],94:[function(require,module,exports){
37457
37261
  module.exports = extend
37458
37262
 
37459
37263
  var hasOwnProperty = Object.prototype.hasOwnProperty;