comprodls-sdk 2.70.1 → 2.72.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.
@@ -503,7 +503,8 @@ exports.PUB_API_URLS = {
503
503
 
504
504
  exports.PUSHX_API_URLS = {
505
505
  grantByUserOrgId: '/orgs/{orgId}/grants',
506
- grantByAccountId: '/accounts/{accountId}/grants'
506
+ grantByAccountId: '/accounts/{accountId}/grants',
507
+ getPushedEvents: '/accounts/{accountId}/pushed-events/channels'
507
508
  };
508
509
 
509
510
  exports.INTEGRATIONS_API_URLS = {
@@ -1150,7 +1151,7 @@ validator.validators.contains = function(value, options) {
1150
1151
  }
1151
1152
  }
1152
1153
  };
1153
- },{"./errors":7,"validate.js":50}],10:[function(require,module,exports){
1154
+ },{"./errors":7,"validate.js":53}],10:[function(require,module,exports){
1154
1155
  /*************************************************************************
1155
1156
  *
1156
1157
  * COMPRO CONFIDENTIAL
@@ -12804,6 +12805,7 @@ function getAllProductFamilies(options) {
12804
12805
 
12805
12806
  var q = require('q');
12806
12807
  var request = require('superagent');
12808
+ var Agent = require('agentkeepalive');
12807
12809
 
12808
12810
  var helpers = require('../../helpers');
12809
12811
  var pubnubClientWrapper = require('./pubnubClientWrapper');
@@ -12814,6 +12816,11 @@ var DLSError = helpers.errors.DLSError;
12814
12816
  **********************************/
12815
12817
  module.exports = pushX;
12816
12818
 
12819
+ var keepaliveAgent = new Agent({
12820
+ timeout: 60000,
12821
+ freeSocketTimeout: 30000
12822
+ });
12823
+
12817
12824
  /*********************************
12818
12825
  * Public Function definitions
12819
12826
  **********************************/
@@ -12824,7 +12831,8 @@ function pushX() {
12824
12831
  "cleanup": _cleanup.bind(this, _pubnubClientWrapper),
12825
12832
  "grantByUserOrgId": grantByUserOrgId.bind(this),
12826
12833
  "grantByAccountId": grantByAccountId.bind(this),
12827
- "grantByAccountIdOnExtUserId": grantByAccountIdOnExtUserId.bind(this)
12834
+ "grantByAccountIdOnExtUserId": grantByAccountIdOnExtUserId.bind(this),
12835
+ "getPushedEvents": getPushedEvents.bind(this)
12828
12836
  };
12829
12837
  }
12830
12838
 
@@ -12974,8 +12982,54 @@ function grantByAccountIdOnExtUserId(options) {
12974
12982
  return dfd.promise;
12975
12983
  }
12976
12984
 
12985
+ /**
12986
+ * @param {
12987
+ * *accountid: "string",
12988
+ * *channelName: "string",
12989
+ * *starttime: number,
12990
+ * *endtime: number
12991
+ * } options
12992
+ */
12993
+ function getPushedEvents(options) {
12994
+ var self = this;
12995
+ var dfd = q.defer(); // Initializing promise
12996
+ var accountid = options.accountid,
12997
+ channelname = options.channelname,
12998
+ starttime = options.starttime,
12999
+ endtime = options.endtime;
13000
+
13001
+ if (accountid && channelname && starttime && endtime) {
13002
+ // Passed all validations, Construct API url
13003
+ var url = self.config.DEFAULT_HOSTS.PUSHX + self.config.PUSHX_API_URLS.getPushedEvents;
13004
+ url = helpers.api.constructAPIUrl(url, { accountId: accountid });
13005
+
13006
+ // Setup request with URL and Params
13007
+ var params = {channelname: channelname, starttime: starttime, endtime: endtime};
13008
+ var requestAPI = request.get(url).query(params);
13009
+ if(self.traceid) { requestAPI.set('X-Amzn-Trace-Id', self.traceid); }
13010
+
13011
+ requestAPI
13012
+ .agent(keepaliveAgent)
13013
+ .end(function(error, response) {
13014
+ if (error) {
13015
+ error = new DLSError(helpers.errors.ERROR_TYPES.API_ERROR, error);
13016
+ dfd.reject(error);
13017
+ } else {
13018
+ dfd.resolve(response.body);
13019
+ }
13020
+ });
13021
+ }
13022
+ else {
13023
+ var err = {};
13024
+ err.message = err.description = 'Mandatory parameters [accountId, channelname,' +
13025
+ ' starttime, endtime] not found in request options';
13026
+ err = new DLSError(helpers.errors.ERROR_TYPES.SDK_ERROR, err);
13027
+ dfd.reject(err);
13028
+ }
13029
+ return dfd.promise;
13030
+ }
12977
13031
 
12978
- },{"../../helpers":3,"./pubnubClientWrapper":26,"q":46,"superagent":49}],26:[function(require,module,exports){
13032
+ },{"../../helpers":3,"./pubnubClientWrapper":26,"agentkeepalive":36,"q":46,"superagent":49}],26:[function(require,module,exports){
12979
13033
  var pubNub = require("pubnub");
12980
13034
  var EventEmitter = require("events").EventEmitter;
12981
13035
  var helpers = require('../../helpers');
@@ -18255,167 +18309,181 @@ module.exports = Array.isArray || function (arr) {
18255
18309
  };
18256
18310
 
18257
18311
  },{}],40:[function(require,module,exports){
18258
-
18259
- /**
18260
- * Expose `Emitter`.
18261
- */
18262
-
18263
- module.exports = Emitter;
18264
-
18265
- /**
18266
- * Initialize a new `Emitter`.
18267
- *
18268
- * @api public
18269
- */
18270
-
18271
- function Emitter(obj) {
18272
- if (obj) return mixin(obj);
18273
- };
18274
-
18275
- /**
18276
- * Mixin the emitter properties.
18277
- *
18278
- * @param {Object} obj
18279
- * @return {Object}
18280
- * @api private
18281
- */
18282
-
18283
- function mixin(obj) {
18284
- for (var key in Emitter.prototype) {
18285
- obj[key] = Emitter.prototype[key];
18286
- }
18287
- return obj;
18288
- }
18289
-
18290
- /**
18291
- * Listen on the given `event` with `fn`.
18292
- *
18293
- * @param {String} event
18294
- * @param {Function} fn
18295
- * @return {Emitter}
18296
- * @api public
18297
- */
18298
-
18299
- Emitter.prototype.on =
18300
- Emitter.prototype.addEventListener = function(event, fn){
18301
- this._callbacks = this._callbacks || {};
18302
- (this._callbacks['$' + event] = this._callbacks['$' + event] || [])
18303
- .push(fn);
18304
- return this;
18305
- };
18306
-
18307
- /**
18308
- * Adds an `event` listener that will be invoked a single
18309
- * time then automatically removed.
18310
- *
18311
- * @param {String} event
18312
- * @param {Function} fn
18313
- * @return {Emitter}
18314
- * @api public
18315
- */
18316
-
18317
- Emitter.prototype.once = function(event, fn){
18318
- function on() {
18319
- this.off(event, on);
18320
- fn.apply(this, arguments);
18321
- }
18322
-
18323
- on.fn = fn;
18324
- this.on(event, on);
18325
- return this;
18326
- };
18327
-
18328
- /**
18329
- * Remove the given callback for `event` or all
18330
- * registered callbacks.
18331
- *
18332
- * @param {String} event
18333
- * @param {Function} fn
18334
- * @return {Emitter}
18335
- * @api public
18336
- */
18337
-
18338
- Emitter.prototype.off =
18339
- Emitter.prototype.removeListener =
18340
- Emitter.prototype.removeAllListeners =
18341
- Emitter.prototype.removeEventListener = function(event, fn){
18342
- this._callbacks = this._callbacks || {};
18343
-
18344
- // all
18345
- if (0 == arguments.length) {
18346
- this._callbacks = {};
18347
- return this;
18348
- }
18349
-
18350
- // specific event
18351
- var callbacks = this._callbacks['$' + event];
18352
- if (!callbacks) return this;
18353
-
18354
- // remove all handlers
18355
- if (1 == arguments.length) {
18356
- delete this._callbacks['$' + event];
18357
- return this;
18358
- }
18359
-
18360
- // remove specific handler
18361
- var cb;
18362
- for (var i = 0; i < callbacks.length; i++) {
18363
- cb = callbacks[i];
18364
- if (cb === fn || cb.fn === fn) {
18365
- callbacks.splice(i, 1);
18366
- break;
18367
- }
18368
- }
18369
- return this;
18370
- };
18371
-
18372
- /**
18373
- * Emit `event` with the given args.
18374
- *
18375
- * @param {String} event
18376
- * @param {Mixed} ...
18377
- * @return {Emitter}
18378
- */
18379
-
18380
- Emitter.prototype.emit = function(event){
18381
- this._callbacks = this._callbacks || {};
18382
- var args = [].slice.call(arguments, 1)
18383
- , callbacks = this._callbacks['$' + event];
18384
-
18385
- if (callbacks) {
18386
- callbacks = callbacks.slice(0);
18387
- for (var i = 0, len = callbacks.length; i < len; ++i) {
18388
- callbacks[i].apply(this, args);
18389
- }
18390
- }
18391
-
18392
- return this;
18393
- };
18394
-
18395
- /**
18396
- * Return array of callbacks for `event`.
18397
- *
18398
- * @param {String} event
18399
- * @return {Array}
18400
- * @api public
18401
- */
18402
-
18403
- Emitter.prototype.listeners = function(event){
18404
- this._callbacks = this._callbacks || {};
18405
- return this._callbacks['$' + event] || [];
18406
- };
18407
-
18408
- /**
18409
- * Check if this emitter has `event` handlers.
18410
- *
18411
- * @param {String} event
18412
- * @return {Boolean}
18413
- * @api public
18414
- */
18415
-
18416
- Emitter.prototype.hasListeners = function(event){
18417
- return !! this.listeners(event).length;
18418
- };
18312
+
18313
+ /**
18314
+ * Expose `Emitter`.
18315
+ */
18316
+
18317
+ if (typeof module !== 'undefined') {
18318
+ module.exports = Emitter;
18319
+ }
18320
+
18321
+ /**
18322
+ * Initialize a new `Emitter`.
18323
+ *
18324
+ * @api public
18325
+ */
18326
+
18327
+ function Emitter(obj) {
18328
+ if (obj) return mixin(obj);
18329
+ };
18330
+
18331
+ /**
18332
+ * Mixin the emitter properties.
18333
+ *
18334
+ * @param {Object} obj
18335
+ * @return {Object}
18336
+ * @api private
18337
+ */
18338
+
18339
+ function mixin(obj) {
18340
+ for (var key in Emitter.prototype) {
18341
+ obj[key] = Emitter.prototype[key];
18342
+ }
18343
+ return obj;
18344
+ }
18345
+
18346
+ /**
18347
+ * Listen on the given `event` with `fn`.
18348
+ *
18349
+ * @param {String} event
18350
+ * @param {Function} fn
18351
+ * @return {Emitter}
18352
+ * @api public
18353
+ */
18354
+
18355
+ Emitter.prototype.on =
18356
+ Emitter.prototype.addEventListener = function(event, fn){
18357
+ this._callbacks = this._callbacks || {};
18358
+ (this._callbacks['$' + event] = this._callbacks['$' + event] || [])
18359
+ .push(fn);
18360
+ return this;
18361
+ };
18362
+
18363
+ /**
18364
+ * Adds an `event` listener that will be invoked a single
18365
+ * time then automatically removed.
18366
+ *
18367
+ * @param {String} event
18368
+ * @param {Function} fn
18369
+ * @return {Emitter}
18370
+ * @api public
18371
+ */
18372
+
18373
+ Emitter.prototype.once = function(event, fn){
18374
+ function on() {
18375
+ this.off(event, on);
18376
+ fn.apply(this, arguments);
18377
+ }
18378
+
18379
+ on.fn = fn;
18380
+ this.on(event, on);
18381
+ return this;
18382
+ };
18383
+
18384
+ /**
18385
+ * Remove the given callback for `event` or all
18386
+ * registered callbacks.
18387
+ *
18388
+ * @param {String} event
18389
+ * @param {Function} fn
18390
+ * @return {Emitter}
18391
+ * @api public
18392
+ */
18393
+
18394
+ Emitter.prototype.off =
18395
+ Emitter.prototype.removeListener =
18396
+ Emitter.prototype.removeAllListeners =
18397
+ Emitter.prototype.removeEventListener = function(event, fn){
18398
+ this._callbacks = this._callbacks || {};
18399
+
18400
+ // all
18401
+ if (0 == arguments.length) {
18402
+ this._callbacks = {};
18403
+ return this;
18404
+ }
18405
+
18406
+ // specific event
18407
+ var callbacks = this._callbacks['$' + event];
18408
+ if (!callbacks) return this;
18409
+
18410
+ // remove all handlers
18411
+ if (1 == arguments.length) {
18412
+ delete this._callbacks['$' + event];
18413
+ return this;
18414
+ }
18415
+
18416
+ // remove specific handler
18417
+ var cb;
18418
+ for (var i = 0; i < callbacks.length; i++) {
18419
+ cb = callbacks[i];
18420
+ if (cb === fn || cb.fn === fn) {
18421
+ callbacks.splice(i, 1);
18422
+ break;
18423
+ }
18424
+ }
18425
+
18426
+ // Remove event specific arrays for event types that no
18427
+ // one is subscribed for to avoid memory leak.
18428
+ if (callbacks.length === 0) {
18429
+ delete this._callbacks['$' + event];
18430
+ }
18431
+
18432
+ return this;
18433
+ };
18434
+
18435
+ /**
18436
+ * Emit `event` with the given args.
18437
+ *
18438
+ * @param {String} event
18439
+ * @param {Mixed} ...
18440
+ * @return {Emitter}
18441
+ */
18442
+
18443
+ Emitter.prototype.emit = function(event){
18444
+ this._callbacks = this._callbacks || {};
18445
+
18446
+ var args = new Array(arguments.length - 1)
18447
+ , callbacks = this._callbacks['$' + event];
18448
+
18449
+ for (var i = 1; i < arguments.length; i++) {
18450
+ args[i - 1] = arguments[i];
18451
+ }
18452
+
18453
+ if (callbacks) {
18454
+ callbacks = callbacks.slice(0);
18455
+ for (var i = 0, len = callbacks.length; i < len; ++i) {
18456
+ callbacks[i].apply(this, args);
18457
+ }
18458
+ }
18459
+
18460
+ return this;
18461
+ };
18462
+
18463
+ /**
18464
+ * Return array of callbacks for `event`.
18465
+ *
18466
+ * @param {String} event
18467
+ * @return {Array}
18468
+ * @api public
18469
+ */
18470
+
18471
+ Emitter.prototype.listeners = function(event){
18472
+ this._callbacks = this._callbacks || {};
18473
+ return this._callbacks['$' + event] || [];
18474
+ };
18475
+
18476
+ /**
18477
+ * Check if this emitter has `event` handlers.
18478
+ *
18479
+ * @param {String} event
18480
+ * @return {Boolean}
18481
+ * @api public
18482
+ */
18483
+
18484
+ Emitter.prototype.hasListeners = function(event){
18485
+ return !! this.listeners(event).length;
18486
+ };
18419
18487
 
18420
18488
  },{}],41:[function(require,module,exports){
18421
18489
  // Copyright Joyent, Inc. and other Node contributors.
@@ -18721,6 +18789,8 @@ function isUndefined(arg) {
18721
18789
  }
18722
18790
 
18723
18791
  },{}],42:[function(require,module,exports){
18792
+ 'use strict';
18793
+
18724
18794
  var hasOwn = Object.prototype.hasOwnProperty;
18725
18795
  var toStr = Object.prototype.toString;
18726
18796
  var defineProperty = Object.defineProperty;
@@ -18735,8 +18805,6 @@ var isArray = function isArray(arr) {
18735
18805
  };
18736
18806
 
18737
18807
  var isPlainObject = function isPlainObject(obj) {
18738
- 'use strict';
18739
-
18740
18808
  if (!obj || toStr.call(obj) !== '[object Object]') {
18741
18809
  return false;
18742
18810
  }
@@ -18786,8 +18854,6 @@ var getProperty = function getProperty(obj, name) {
18786
18854
  };
18787
18855
 
18788
18856
  module.exports = function extend() {
18789
- 'use strict';
18790
-
18791
18857
  var options, name, src, copy, copyIsArray, clone;
18792
18858
  var target = arguments[0];
18793
18859
  var i = 1;
@@ -21257,6 +21323,8 @@ function template(string) {
21257
21323
 
21258
21324
  var Emitter = require('emitter');
21259
21325
  var reduce = require('reduce');
21326
+ var requestBase = require('./request-base');
21327
+ var isObject = require('./is-object');
21260
21328
 
21261
21329
  /**
21262
21330
  * Root reference for iframes.
@@ -21278,28 +21346,10 @@ if (typeof window !== 'undefined') { // Browser window
21278
21346
  function noop(){};
21279
21347
 
21280
21348
  /**
21281
- * Check if `obj` is a host object,
21282
- * we don't want to serialize these :)
21283
- *
21284
- * TODO: future proof, move to compoent land
21285
- *
21286
- * @param {Object} obj
21287
- * @return {Boolean}
21288
- * @api private
21349
+ * Expose `request`.
21289
21350
  */
21290
21351
 
21291
- function isHost(obj) {
21292
- var str = {}.toString.call(obj);
21293
-
21294
- switch (str) {
21295
- case '[object File]':
21296
- case '[object Blob]':
21297
- case '[object FormData]':
21298
- return true;
21299
- default:
21300
- return false;
21301
- }
21302
- }
21352
+ var request = module.exports = require('./request').bind(null, Request);
21303
21353
 
21304
21354
  /**
21305
21355
  * Determine XHR.
@@ -21331,18 +21381,6 @@ var trim = ''.trim
21331
21381
  ? function(s) { return s.trim(); }
21332
21382
  : function(s) { return s.replace(/(^\s*|\s*$)/g, ''); };
21333
21383
 
21334
- /**
21335
- * Check if `obj` is an object.
21336
- *
21337
- * @param {Object} obj
21338
- * @return {Boolean}
21339
- * @api private
21340
- */
21341
-
21342
- function isObject(obj) {
21343
- return obj === Object(obj);
21344
- }
21345
-
21346
21384
  /**
21347
21385
  * Serialize the given `obj`.
21348
21386
  *
@@ -21357,8 +21395,8 @@ function serialize(obj) {
21357
21395
  for (var key in obj) {
21358
21396
  if (null != obj[key]) {
21359
21397
  pushEncodedKeyValuePair(pairs, key, obj[key]);
21360
- }
21361
- }
21398
+ }
21399
+ }
21362
21400
  return pairs.join('&');
21363
21401
  }
21364
21402
 
@@ -21376,6 +21414,11 @@ function pushEncodedKeyValuePair(pairs, key, val) {
21376
21414
  return val.forEach(function(v) {
21377
21415
  pushEncodedKeyValuePair(pairs, key, v);
21378
21416
  });
21417
+ } else if (isObject(val)) {
21418
+ for(var subkey in val) {
21419
+ pushEncodedKeyValuePair(pairs, key + '[' + subkey + ']', val[subkey]);
21420
+ }
21421
+ return;
21379
21422
  }
21380
21423
  pairs.push(encodeURIComponent(key)
21381
21424
  + '=' + encodeURIComponent(val));
@@ -21398,13 +21441,18 @@ function pushEncodedKeyValuePair(pairs, key, val) {
21398
21441
  function parseString(str) {
21399
21442
  var obj = {};
21400
21443
  var pairs = str.split('&');
21401
- var parts;
21402
21444
  var pair;
21445
+ var pos;
21403
21446
 
21404
21447
  for (var i = 0, len = pairs.length; i < len; ++i) {
21405
21448
  pair = pairs[i];
21406
- parts = pair.split('=');
21407
- obj[decodeURIComponent(parts[0])] = decodeURIComponent(parts[1]);
21449
+ pos = pair.indexOf('=');
21450
+ if (pos == -1) {
21451
+ obj[decodeURIComponent(pair)] = '';
21452
+ } else {
21453
+ obj[decodeURIComponent(pair.slice(0, pos))] =
21454
+ decodeURIComponent(pair.slice(pos + 1));
21455
+ }
21408
21456
  }
21409
21457
 
21410
21458
  return obj;
@@ -21588,15 +21636,15 @@ function Response(req, options) {
21588
21636
  ? this.xhr.responseText
21589
21637
  : null;
21590
21638
  this.statusText = this.req.xhr.statusText;
21591
- this.setStatusProperties(this.xhr.status);
21639
+ this._setStatusProperties(this.xhr.status);
21592
21640
  this.header = this.headers = parseHeader(this.xhr.getAllResponseHeaders());
21593
21641
  // getAllResponseHeaders sometimes falsely returns "" for CORS requests, but
21594
21642
  // getResponseHeader still works. so we get content-type even if getting
21595
21643
  // other headers fails.
21596
21644
  this.header['content-type'] = this.xhr.getResponseHeader('content-type');
21597
- this.setHeaderProperties(this.header);
21645
+ this._setHeaderProperties(this.header);
21598
21646
  this.body = this.req.method != 'HEAD'
21599
- ? this.parseBody(this.text ? this.text : this.xhr.response)
21647
+ ? this._parseBody(this.text ? this.text : this.xhr.response)
21600
21648
  : null;
21601
21649
  }
21602
21650
 
@@ -21624,7 +21672,7 @@ Response.prototype.get = function(field){
21624
21672
  * @api private
21625
21673
  */
21626
21674
 
21627
- Response.prototype.setHeaderProperties = function(header){
21675
+ Response.prototype._setHeaderProperties = function(header){
21628
21676
  // content-type
21629
21677
  var ct = this.header['content-type'] || '';
21630
21678
  this.type = type(ct);
@@ -21645,8 +21693,11 @@ Response.prototype.setHeaderProperties = function(header){
21645
21693
  * @api private
21646
21694
  */
21647
21695
 
21648
- Response.prototype.parseBody = function(str){
21696
+ Response.prototype._parseBody = function(str){
21649
21697
  var parse = request.parse[this.type];
21698
+ if (!parse && isJSON(this.type)) {
21699
+ parse = request.parse['application/json'];
21700
+ }
21650
21701
  return parse && str && (str.length || str instanceof Object)
21651
21702
  ? parse(str)
21652
21703
  : null;
@@ -21673,7 +21724,7 @@ Response.prototype.parseBody = function(str){
21673
21724
  * @api private
21674
21725
  */
21675
21726
 
21676
- Response.prototype.setStatusProperties = function(status){
21727
+ Response.prototype._setStatusProperties = function(status){
21677
21728
  // handle IE9 bug: http://stackoverflow.com/questions/10046972/msie-returns-status-code-of-1223-for-ajax-request
21678
21729
  if (status === 1223) {
21679
21730
  status = 204;
@@ -21741,12 +21792,11 @@ request.Response = Response;
21741
21792
 
21742
21793
  function Request(method, url) {
21743
21794
  var self = this;
21744
- Emitter.call(this);
21745
21795
  this._query = this._query || [];
21746
21796
  this.method = method;
21747
21797
  this.url = url;
21748
- this.header = {};
21749
- this._header = {};
21798
+ this.header = {}; // preserves header name case
21799
+ this._header = {}; // coerces header names to lowercase
21750
21800
  this.on('end', function(){
21751
21801
  var err = null;
21752
21802
  var res = null;
@@ -21759,6 +21809,8 @@ function Request(method, url) {
21759
21809
  err.original = e;
21760
21810
  // issue #675: return the raw response if the response parsing fails
21761
21811
  err.rawResponse = self.xhr && self.xhr.responseText ? self.xhr.responseText : null;
21812
+ // issue #876: return the http status code if the response parsing fails
21813
+ err.statusCode = self.xhr && self.xhr.status ? self.xhr.status : null;
21762
21814
  return self.callback(err);
21763
21815
  }
21764
21816
 
@@ -21768,142 +21820,34 @@ function Request(method, url) {
21768
21820
  return self.callback(err, res);
21769
21821
  }
21770
21822
 
21771
- if (res.status >= 200 && res.status < 300) {
21772
- return self.callback(err, res);
21773
- }
21823
+ try {
21824
+ if (res.status >= 200 && res.status < 300) {
21825
+ return self.callback(err, res);
21826
+ }
21774
21827
 
21775
- var new_err = new Error(res.statusText || 'Unsuccessful HTTP response');
21776
- new_err.original = err;
21777
- new_err.response = res;
21778
- new_err.status = res.status;
21828
+ var new_err = new Error(res.statusText || 'Unsuccessful HTTP response');
21829
+ new_err.original = err;
21830
+ new_err.response = res;
21831
+ new_err.status = res.status;
21779
21832
 
21780
- self.callback(new_err, res);
21833
+ self.callback(new_err, res);
21834
+ } catch(e) {
21835
+ self.callback(e); // #985 touching res may cause INVALID_STATE_ERR on old Android
21836
+ }
21781
21837
  });
21782
21838
  }
21783
21839
 
21784
21840
  /**
21785
- * Mixin `Emitter`.
21841
+ * Mixin `Emitter` and `requestBase`.
21786
21842
  */
21787
21843
 
21788
21844
  Emitter(Request.prototype);
21789
-
21790
- /**
21791
- * Allow for extension
21792
- */
21793
-
21794
- Request.prototype.use = function(fn) {
21795
- fn(this);
21796
- return this;
21845
+ for (var key in requestBase) {
21846
+ Request.prototype[key] = requestBase[key];
21797
21847
  }
21798
21848
 
21799
21849
  /**
21800
- * Set timeout to `ms`.
21801
- *
21802
- * @param {Number} ms
21803
- * @return {Request} for chaining
21804
- * @api public
21805
- */
21806
-
21807
- Request.prototype.timeout = function(ms){
21808
- this._timeout = ms;
21809
- return this;
21810
- };
21811
-
21812
- /**
21813
- * Clear previous timeout.
21814
- *
21815
- * @return {Request} for chaining
21816
- * @api public
21817
- */
21818
-
21819
- Request.prototype.clearTimeout = function(){
21820
- this._timeout = 0;
21821
- clearTimeout(this._timer);
21822
- return this;
21823
- };
21824
-
21825
- /**
21826
- * Abort the request, and clear potential timeout.
21827
- *
21828
- * @return {Request}
21829
- * @api public
21830
- */
21831
-
21832
- Request.prototype.abort = function(){
21833
- if (this.aborted) return;
21834
- this.aborted = true;
21835
- this.xhr.abort();
21836
- this.clearTimeout();
21837
- this.emit('abort');
21838
- return this;
21839
- };
21840
-
21841
- /**
21842
- * Set header `field` to `val`, or multiple fields with one object.
21843
- *
21844
- * Examples:
21845
- *
21846
- * req.get('/')
21847
- * .set('Accept', 'application/json')
21848
- * .set('X-API-Key', 'foobar')
21849
- * .end(callback);
21850
- *
21851
- * req.get('/')
21852
- * .set({ Accept: 'application/json', 'X-API-Key': 'foobar' })
21853
- * .end(callback);
21854
- *
21855
- * @param {String|Object} field
21856
- * @param {String} val
21857
- * @return {Request} for chaining
21858
- * @api public
21859
- */
21860
-
21861
- Request.prototype.set = function(field, val){
21862
- if (isObject(field)) {
21863
- for (var key in field) {
21864
- this.set(key, field[key]);
21865
- }
21866
- return this;
21867
- }
21868
- this._header[field.toLowerCase()] = val;
21869
- this.header[field] = val;
21870
- return this;
21871
- };
21872
-
21873
- /**
21874
- * Remove header `field`.
21875
- *
21876
- * Example:
21877
- *
21878
- * req.get('/')
21879
- * .unset('User-Agent')
21880
- * .end(callback);
21881
- *
21882
- * @param {String} field
21883
- * @return {Request} for chaining
21884
- * @api public
21885
- */
21886
-
21887
- Request.prototype.unset = function(field){
21888
- delete this._header[field.toLowerCase()];
21889
- delete this.header[field];
21890
- return this;
21891
- };
21892
-
21893
- /**
21894
- * Get case-insensitive header `field` value.
21895
- *
21896
- * @param {String} field
21897
- * @return {String}
21898
- * @api private
21899
- */
21900
-
21901
- Request.prototype.getHeader = function(field){
21902
- return this._header[field.toLowerCase()];
21903
- };
21904
-
21905
- /**
21906
- * Set Content-Type to `type`, mapping values from `request.types`.
21850
+ * Set Content-Type to `type`, mapping values from `request.types`.
21907
21851
  *
21908
21852
  * Examples:
21909
21853
  *
@@ -21930,16 +21874,22 @@ Request.prototype.type = function(type){
21930
21874
  };
21931
21875
 
21932
21876
  /**
21933
- * Force given parser
21877
+ * Set responseType to `val`. Presently valid responseTypes are 'blob' and
21878
+ * 'arraybuffer'.
21934
21879
  *
21935
- * Sets the body parser no matter type.
21880
+ * Examples:
21936
21881
  *
21937
- * @param {Function}
21882
+ * req.get('/')
21883
+ * .responseType('blob')
21884
+ * .end(callback);
21885
+ *
21886
+ * @param {String} val
21887
+ * @return {Request} for chaining
21938
21888
  * @api public
21939
21889
  */
21940
21890
 
21941
- Request.prototype.parse = function(fn){
21942
- this._parser = fn;
21891
+ Request.prototype.responseType = function(val){
21892
+ this._responseType = val;
21943
21893
  return this;
21944
21894
  };
21945
21895
 
@@ -21973,13 +21923,29 @@ Request.prototype.accept = function(type){
21973
21923
  *
21974
21924
  * @param {String} user
21975
21925
  * @param {String} pass
21926
+ * @param {Object} options with 'type' property 'auto' or 'basic' (default 'basic')
21976
21927
  * @return {Request} for chaining
21977
21928
  * @api public
21978
21929
  */
21979
21930
 
21980
- Request.prototype.auth = function(user, pass){
21981
- var str = btoa(user + ':' + pass);
21982
- this.set('Authorization', 'Basic ' + str);
21931
+ Request.prototype.auth = function(user, pass, options){
21932
+ if (!options) {
21933
+ options = {
21934
+ type: 'basic'
21935
+ }
21936
+ }
21937
+
21938
+ switch (options.type) {
21939
+ case 'basic':
21940
+ var str = btoa(user + ':' + pass);
21941
+ this.set('Authorization', 'Basic ' + str);
21942
+ break;
21943
+
21944
+ case 'auto':
21945
+ this.username = user;
21946
+ this.password = pass;
21947
+ break;
21948
+ }
21983
21949
  return this;
21984
21950
  };
21985
21951
 
@@ -22003,35 +21969,13 @@ Request.prototype.query = function(val){
22003
21969
  return this;
22004
21970
  };
22005
21971
 
22006
- /**
22007
- * Write the field `name` and `val` for "multipart/form-data"
22008
- * request bodies.
22009
- *
22010
- * ``` js
22011
- * request.post('/upload')
22012
- * .field('foo', 'bar')
22013
- * .end(callback);
22014
- * ```
22015
- *
22016
- * @param {String} name
22017
- * @param {String|Blob|File} val
22018
- * @return {Request} for chaining
22019
- * @api public
22020
- */
22021
-
22022
- Request.prototype.field = function(name, val){
22023
- if (!this._formData) this._formData = new root.FormData();
22024
- this._formData.append(name, val);
22025
- return this;
22026
- };
22027
-
22028
21972
  /**
22029
21973
  * Queue the given `file` as an attachment to the specified `field`,
22030
21974
  * with optional `filename`.
22031
21975
  *
22032
21976
  * ``` js
22033
21977
  * request.post('/upload')
22034
- * .attach(new Blob(['<a id="a"><b id="b">hey!</b></a>'], { type: "text/html"}))
21978
+ * .attach('content', new Blob(['<a id="a"><b id="b">hey!</b></a>'], { type: "text/html"}))
22035
21979
  * .end(callback);
22036
21980
  * ```
22037
21981
  *
@@ -22043,77 +21987,15 @@ Request.prototype.field = function(name, val){
22043
21987
  */
22044
21988
 
22045
21989
  Request.prototype.attach = function(field, file, filename){
22046
- if (!this._formData) this._formData = new root.FormData();
22047
- this._formData.append(field, file, filename || file.name);
21990
+ this._getFormData().append(field, file, filename || file.name);
22048
21991
  return this;
22049
21992
  };
22050
21993
 
22051
- /**
22052
- * Send `data` as the request body, defaulting the `.type()` to "json" when
22053
- * an object is given.
22054
- *
22055
- * Examples:
22056
- *
22057
- * // manual json
22058
- * request.post('/user')
22059
- * .type('json')
22060
- * .send('{"name":"tj"}')
22061
- * .end(callback)
22062
- *
22063
- * // auto json
22064
- * request.post('/user')
22065
- * .send({ name: 'tj' })
22066
- * .end(callback)
22067
- *
22068
- * // manual x-www-form-urlencoded
22069
- * request.post('/user')
22070
- * .type('form')
22071
- * .send('name=tj')
22072
- * .end(callback)
22073
- *
22074
- * // auto x-www-form-urlencoded
22075
- * request.post('/user')
22076
- * .type('form')
22077
- * .send({ name: 'tj' })
22078
- * .end(callback)
22079
- *
22080
- * // defaults to x-www-form-urlencoded
22081
- * request.post('/user')
22082
- * .send('name=tobi')
22083
- * .send('species=ferret')
22084
- * .end(callback)
22085
- *
22086
- * @param {String|Object} data
22087
- * @return {Request} for chaining
22088
- * @api public
22089
- */
22090
-
22091
- Request.prototype.send = function(data){
22092
- var obj = isObject(data);
22093
- var type = this.getHeader('Content-Type');
22094
-
22095
- // merge
22096
- if (obj && isObject(this._data)) {
22097
- for (var key in data) {
22098
- this._data[key] = data[key];
22099
- }
22100
- } else if ('string' == typeof data) {
22101
- if (!type) this.type('form');
22102
- type = this.getHeader('Content-Type');
22103
- if ('application/x-www-form-urlencoded' == type) {
22104
- this._data = this._data
22105
- ? this._data + '&' + data
22106
- : data;
22107
- } else {
22108
- this._data = (this._data || '') + data;
22109
- }
22110
- } else {
22111
- this._data = data;
21994
+ Request.prototype._getFormData = function(){
21995
+ if (!this._formData) {
21996
+ this._formData = new root.FormData();
22112
21997
  }
22113
-
22114
- if (!obj || isHost(data)) return this;
22115
- if (!type) this.type('json');
22116
- return this;
21998
+ return this._formData;
22117
21999
  };
22118
22000
 
22119
22001
  /**
@@ -22154,7 +22036,7 @@ Request.prototype.crossDomainError = function(){
22154
22036
  * @api private
22155
22037
  */
22156
22038
 
22157
- Request.prototype.timeoutError = function(){
22039
+ Request.prototype._timeoutError = function(){
22158
22040
  var timeout = this._timeout;
22159
22041
  var err = new Error('timeout of ' + timeout + 'ms exceeded');
22160
22042
  err.timeout = timeout;
@@ -22162,19 +22044,18 @@ Request.prototype.timeoutError = function(){
22162
22044
  };
22163
22045
 
22164
22046
  /**
22165
- * Enable transmission of cookies with x-domain requests.
22166
- *
22167
- * Note that for this to work the origin must not be
22168
- * using "Access-Control-Allow-Origin" with a wildcard,
22169
- * and also must set "Access-Control-Allow-Credentials"
22170
- * to "true".
22047
+ * Compose querystring to append to req.url
22171
22048
  *
22172
- * @api public
22049
+ * @api private
22173
22050
  */
22174
22051
 
22175
- Request.prototype.withCredentials = function(){
22176
- this._withCredentials = true;
22177
- return this;
22052
+ Request.prototype._appendQueryString = function(){
22053
+ var query = this._query.join('&');
22054
+ if (query) {
22055
+ this.url += ~this.url.indexOf('?')
22056
+ ? '&' + query
22057
+ : '?' + query;
22058
+ }
22178
22059
  };
22179
22060
 
22180
22061
  /**
@@ -22189,7 +22070,6 @@ Request.prototype.withCredentials = function(){
22189
22070
  Request.prototype.end = function(fn){
22190
22071
  var self = this;
22191
22072
  var xhr = this.xhr = request.getXHR();
22192
- var query = this._query.join('&');
22193
22073
  var timeout = this._timeout;
22194
22074
  var data = this._formData || this._data;
22195
22075
 
@@ -22206,8 +22086,8 @@ Request.prototype.end = function(fn){
22206
22086
  try { status = xhr.status } catch(e) { status = 0; }
22207
22087
 
22208
22088
  if (0 == status) {
22209
- if (self.timedout) return self.timeoutError();
22210
- if (self.aborted) return;
22089
+ if (self.timedout) return self._timeoutError();
22090
+ if (self._aborted) return;
22211
22091
  return self.crossDomainError();
22212
22092
  }
22213
22093
  self.emit('end');
@@ -22243,24 +22123,23 @@ Request.prototype.end = function(fn){
22243
22123
  }
22244
22124
 
22245
22125
  // querystring
22246
- if (query) {
22247
- query = request.serializeObject(query);
22248
- this.url += ~this.url.indexOf('?')
22249
- ? '&' + query
22250
- : '?' + query;
22251
- }
22126
+ this._appendQueryString();
22252
22127
 
22253
22128
  // initiate request
22254
- xhr.open(this.method, this.url, true);
22129
+ if (this.username && this.password) {
22130
+ xhr.open(this.method, this.url, true, this.username, this.password);
22131
+ } else {
22132
+ xhr.open(this.method, this.url, true);
22133
+ }
22255
22134
 
22256
22135
  // CORS
22257
22136
  if (this._withCredentials) xhr.withCredentials = true;
22258
22137
 
22259
22138
  // body
22260
- if ('GET' != this.method && 'HEAD' != this.method && 'string' != typeof data && !isHost(data)) {
22139
+ if ('GET' != this.method && 'HEAD' != this.method && 'string' != typeof data && !this._isHost(data)) {
22261
22140
  // serialize stuff
22262
- var contentType = this.getHeader('Content-Type');
22263
- var serialize = this._parser || request.serialize[contentType ? contentType.split(';')[0] : ''];
22141
+ var contentType = this._header['content-type'];
22142
+ var serialize = this._serializer || request.serialize[contentType ? contentType.split(';')[0] : ''];
22264
22143
  if (!serialize && isJSON(contentType)) serialize = request.serialize['application/json'];
22265
22144
  if (serialize) data = serialize(data);
22266
22145
  }
@@ -22271,6 +22150,10 @@ Request.prototype.end = function(fn){
22271
22150
  xhr.setRequestHeader(field, this.header[field]);
22272
22151
  }
22273
22152
 
22153
+ if (this._responseType) {
22154
+ xhr.responseType = this._responseType;
22155
+ }
22156
+
22274
22157
  // send stuff
22275
22158
  this.emit('request', this);
22276
22159
 
@@ -22280,19 +22163,6 @@ Request.prototype.end = function(fn){
22280
22163
  return this;
22281
22164
  };
22282
22165
 
22283
- /**
22284
- * Faux promise support
22285
- *
22286
- * @param {Function} fulfill
22287
- * @param {Function} reject
22288
- * @return {Request}
22289
- */
22290
-
22291
- Request.prototype.then = function (fulfill, reject) {
22292
- return this.end(function(err, res) {
22293
- err ? reject(err) : fulfill(res);
22294
- });
22295
- }
22296
22166
 
22297
22167
  /**
22298
22168
  * Expose `Request`.
@@ -22300,35 +22170,6 @@ Request.prototype.then = function (fulfill, reject) {
22300
22170
 
22301
22171
  request.Request = Request;
22302
22172
 
22303
- /**
22304
- * Issue a request:
22305
- *
22306
- * Examples:
22307
- *
22308
- * request('GET', '/users').end(callback)
22309
- * request('/users').end(callback)
22310
- * request('/users', callback)
22311
- *
22312
- * @param {String} method
22313
- * @param {String|Function} url or callback
22314
- * @return {Request}
22315
- * @api public
22316
- */
22317
-
22318
- function request(method, url) {
22319
- // callback
22320
- if ('function' == typeof url) {
22321
- return new Request('GET', method).end(url);
22322
- }
22323
-
22324
- // url first
22325
- if (1 == arguments.length) {
22326
- return new Request('GET', method);
22327
- }
22328
-
22329
- return new Request(method, url);
22330
- }
22331
-
22332
22173
  /**
22333
22174
  * GET `url` with optional callback `fn(res)`.
22334
22175
  *
@@ -22366,34 +22207,52 @@ request.head = function(url, data, fn){
22366
22207
  };
22367
22208
 
22368
22209
  /**
22369
- * DELETE `url` with optional callback `fn(res)`.
22210
+ * OPTIONS query to `url` with optional callback `fn(res)`.
22370
22211
  *
22371
22212
  * @param {String} url
22213
+ * @param {Mixed|Function} data or fn
22372
22214
  * @param {Function} fn
22373
22215
  * @return {Request}
22374
22216
  * @api public
22375
22217
  */
22376
22218
 
22377
- function del(url, fn){
22378
- var req = request('DELETE', url);
22219
+ request.options = function(url, data, fn){
22220
+ var req = request('OPTIONS', url);
22221
+ if ('function' == typeof data) fn = data, data = null;
22222
+ if (data) req.send(data);
22379
22223
  if (fn) req.end(fn);
22380
22224
  return req;
22381
22225
  };
22382
22226
 
22383
- request['del'] = del;
22384
- request['delete'] = del;
22385
-
22386
22227
  /**
22387
- * PATCH `url` with optional `data` and callback `fn(res)`.
22228
+ * DELETE `url` with optional callback `fn(res)`.
22388
22229
  *
22389
22230
  * @param {String} url
22390
- * @param {Mixed} data
22391
22231
  * @param {Function} fn
22392
22232
  * @return {Request}
22393
22233
  * @api public
22394
22234
  */
22395
22235
 
22396
- request.patch = function(url, data, fn){
22236
+ function del(url, fn){
22237
+ var req = request('DELETE', url);
22238
+ if (fn) req.end(fn);
22239
+ return req;
22240
+ };
22241
+
22242
+ request['del'] = del;
22243
+ request['delete'] = del;
22244
+
22245
+ /**
22246
+ * PATCH `url` with optional `data` and callback `fn(res)`.
22247
+ *
22248
+ * @param {String} url
22249
+ * @param {Mixed} data
22250
+ * @param {Function} fn
22251
+ * @return {Request}
22252
+ * @api public
22253
+ */
22254
+
22255
+ request.patch = function(url, data, fn){
22397
22256
  var req = request('PATCH', url);
22398
22257
  if ('function' == typeof data) fn = data, data = null;
22399
22258
  if (data) req.send(data);
@@ -22437,13 +22296,404 @@ request.put = function(url, data, fn){
22437
22296
  return req;
22438
22297
  };
22439
22298
 
22299
+ },{"./is-object":50,"./request":52,"./request-base":51,"emitter":40,"reduce":47}],50:[function(require,module,exports){
22440
22300
  /**
22441
- * Expose `request`.
22301
+ * Check if `obj` is an object.
22302
+ *
22303
+ * @param {Object} obj
22304
+ * @return {Boolean}
22305
+ * @api private
22306
+ */
22307
+
22308
+ function isObject(obj) {
22309
+ return null !== obj && 'object' === typeof obj;
22310
+ }
22311
+
22312
+ module.exports = isObject;
22313
+
22314
+ },{}],51:[function(require,module,exports){
22315
+ /**
22316
+ * Module of mixed-in functions shared between node and client code
22442
22317
  */
22318
+ var isObject = require('./is-object');
22319
+
22320
+ /**
22321
+ * Clear previous timeout.
22322
+ *
22323
+ * @return {Request} for chaining
22324
+ * @api public
22325
+ */
22326
+
22327
+ exports.clearTimeout = function _clearTimeout(){
22328
+ this._timeout = 0;
22329
+ clearTimeout(this._timer);
22330
+ return this;
22331
+ };
22332
+
22333
+ /**
22334
+ * Override default response body parser
22335
+ *
22336
+ * This function will be called to convert incoming data into request.body
22337
+ *
22338
+ * @param {Function}
22339
+ * @api public
22340
+ */
22341
+
22342
+ exports.parse = function parse(fn){
22343
+ this._parser = fn;
22344
+ return this;
22345
+ };
22346
+
22347
+ /**
22348
+ * Override default request body serializer
22349
+ *
22350
+ * This function will be called to convert data set via .send or .attach into payload to send
22351
+ *
22352
+ * @param {Function}
22353
+ * @api public
22354
+ */
22355
+
22356
+ exports.serialize = function serialize(fn){
22357
+ this._serializer = fn;
22358
+ return this;
22359
+ };
22360
+
22361
+ /**
22362
+ * Set timeout to `ms`.
22363
+ *
22364
+ * @param {Number} ms
22365
+ * @return {Request} for chaining
22366
+ * @api public
22367
+ */
22368
+
22369
+ exports.timeout = function timeout(ms){
22370
+ this._timeout = ms;
22371
+ return this;
22372
+ };
22373
+
22374
+ /**
22375
+ * Promise support
22376
+ *
22377
+ * @param {Function} resolve
22378
+ * @param {Function} reject
22379
+ * @return {Request}
22380
+ */
22381
+
22382
+ exports.then = function then(resolve, reject) {
22383
+ if (!this._fullfilledPromise) {
22384
+ var self = this;
22385
+ this._fullfilledPromise = new Promise(function(innerResolve, innerReject){
22386
+ self.end(function(err, res){
22387
+ if (err) innerReject(err); else innerResolve(res);
22388
+ });
22389
+ });
22390
+ }
22391
+ return this._fullfilledPromise.then(resolve, reject);
22392
+ }
22393
+
22394
+ /**
22395
+ * Allow for extension
22396
+ */
22397
+
22398
+ exports.use = function use(fn) {
22399
+ fn(this);
22400
+ return this;
22401
+ }
22402
+
22403
+
22404
+ /**
22405
+ * Get request header `field`.
22406
+ * Case-insensitive.
22407
+ *
22408
+ * @param {String} field
22409
+ * @return {String}
22410
+ * @api public
22411
+ */
22412
+
22413
+ exports.get = function(field){
22414
+ return this._header[field.toLowerCase()];
22415
+ };
22416
+
22417
+ /**
22418
+ * Get case-insensitive header `field` value.
22419
+ * This is a deprecated internal API. Use `.get(field)` instead.
22420
+ *
22421
+ * (getHeader is no longer used internally by the superagent code base)
22422
+ *
22423
+ * @param {String} field
22424
+ * @return {String}
22425
+ * @api private
22426
+ * @deprecated
22427
+ */
22428
+
22429
+ exports.getHeader = exports.get;
22430
+
22431
+ /**
22432
+ * Set header `field` to `val`, or multiple fields with one object.
22433
+ * Case-insensitive.
22434
+ *
22435
+ * Examples:
22436
+ *
22437
+ * req.get('/')
22438
+ * .set('Accept', 'application/json')
22439
+ * .set('X-API-Key', 'foobar')
22440
+ * .end(callback);
22441
+ *
22442
+ * req.get('/')
22443
+ * .set({ Accept: 'application/json', 'X-API-Key': 'foobar' })
22444
+ * .end(callback);
22445
+ *
22446
+ * @param {String|Object} field
22447
+ * @param {String} val
22448
+ * @return {Request} for chaining
22449
+ * @api public
22450
+ */
22451
+
22452
+ exports.set = function(field, val){
22453
+ if (isObject(field)) {
22454
+ for (var key in field) {
22455
+ this.set(key, field[key]);
22456
+ }
22457
+ return this;
22458
+ }
22459
+ this._header[field.toLowerCase()] = val;
22460
+ this.header[field] = val;
22461
+ return this;
22462
+ };
22463
+
22464
+ /**
22465
+ * Remove header `field`.
22466
+ * Case-insensitive.
22467
+ *
22468
+ * Example:
22469
+ *
22470
+ * req.get('/')
22471
+ * .unset('User-Agent')
22472
+ * .end(callback);
22473
+ *
22474
+ * @param {String} field
22475
+ */
22476
+ exports.unset = function(field){
22477
+ delete this._header[field.toLowerCase()];
22478
+ delete this.header[field];
22479
+ return this;
22480
+ };
22481
+
22482
+ /**
22483
+ * Write the field `name` and `val` for "multipart/form-data"
22484
+ * request bodies.
22485
+ *
22486
+ * ``` js
22487
+ * request.post('/upload')
22488
+ * .field('foo', 'bar')
22489
+ * .end(callback);
22490
+ * ```
22491
+ *
22492
+ * @param {String} name
22493
+ * @param {String|Blob|File|Buffer|fs.ReadStream} val
22494
+ * @return {Request} for chaining
22495
+ * @api public
22496
+ */
22497
+ exports.field = function(name, val) {
22498
+ this._getFormData().append(name, val);
22499
+ return this;
22500
+ };
22501
+
22502
+ /**
22503
+ * Abort the request, and clear potential timeout.
22504
+ *
22505
+ * @return {Request}
22506
+ * @api public
22507
+ */
22508
+ exports.abort = function(){
22509
+ if (this._aborted) {
22510
+ return this;
22511
+ }
22512
+ this._aborted = true;
22513
+ this.xhr && this.xhr.abort(); // browser
22514
+ this.req && this.req.abort(); // node
22515
+ this.clearTimeout();
22516
+ this.emit('abort');
22517
+ return this;
22518
+ };
22519
+
22520
+ /**
22521
+ * Enable transmission of cookies with x-domain requests.
22522
+ *
22523
+ * Note that for this to work the origin must not be
22524
+ * using "Access-Control-Allow-Origin" with a wildcard,
22525
+ * and also must set "Access-Control-Allow-Credentials"
22526
+ * to "true".
22527
+ *
22528
+ * @api public
22529
+ */
22530
+
22531
+ exports.withCredentials = function(){
22532
+ // This is browser-only functionality. Node side is no-op.
22533
+ this._withCredentials = true;
22534
+ return this;
22535
+ };
22536
+
22537
+ /**
22538
+ * Set the max redirects to `n`. Does noting in browser XHR implementation.
22539
+ *
22540
+ * @param {Number} n
22541
+ * @return {Request} for chaining
22542
+ * @api public
22543
+ */
22544
+
22545
+ exports.redirects = function(n){
22546
+ this._maxRedirects = n;
22547
+ return this;
22548
+ };
22549
+
22550
+ /**
22551
+ * Convert to a plain javascript object (not JSON string) of scalar properties.
22552
+ * Note as this method is designed to return a useful non-this value,
22553
+ * it cannot be chained.
22554
+ *
22555
+ * @return {Object} describing method, url, and data of this request
22556
+ * @api public
22557
+ */
22558
+
22559
+ exports.toJSON = function(){
22560
+ return {
22561
+ method: this.method,
22562
+ url: this.url,
22563
+ data: this._data
22564
+ };
22565
+ };
22566
+
22567
+ /**
22568
+ * Check if `obj` is a host object,
22569
+ * we don't want to serialize these :)
22570
+ *
22571
+ * TODO: future proof, move to compoent land
22572
+ *
22573
+ * @param {Object} obj
22574
+ * @return {Boolean}
22575
+ * @api private
22576
+ */
22577
+
22578
+ exports._isHost = function _isHost(obj) {
22579
+ var str = {}.toString.call(obj);
22580
+
22581
+ switch (str) {
22582
+ case '[object File]':
22583
+ case '[object Blob]':
22584
+ case '[object FormData]':
22585
+ return true;
22586
+ default:
22587
+ return false;
22588
+ }
22589
+ }
22590
+
22591
+ /**
22592
+ * Send `data` as the request body, defaulting the `.type()` to "json" when
22593
+ * an object is given.
22594
+ *
22595
+ * Examples:
22596
+ *
22597
+ * // manual json
22598
+ * request.post('/user')
22599
+ * .type('json')
22600
+ * .send('{"name":"tj"}')
22601
+ * .end(callback)
22602
+ *
22603
+ * // auto json
22604
+ * request.post('/user')
22605
+ * .send({ name: 'tj' })
22606
+ * .end(callback)
22607
+ *
22608
+ * // manual x-www-form-urlencoded
22609
+ * request.post('/user')
22610
+ * .type('form')
22611
+ * .send('name=tj')
22612
+ * .end(callback)
22613
+ *
22614
+ * // auto x-www-form-urlencoded
22615
+ * request.post('/user')
22616
+ * .type('form')
22617
+ * .send({ name: 'tj' })
22618
+ * .end(callback)
22619
+ *
22620
+ * // defaults to x-www-form-urlencoded
22621
+ * request.post('/user')
22622
+ * .send('name=tobi')
22623
+ * .send('species=ferret')
22624
+ * .end(callback)
22625
+ *
22626
+ * @param {String|Object} data
22627
+ * @return {Request} for chaining
22628
+ * @api public
22629
+ */
22630
+
22631
+ exports.send = function(data){
22632
+ var obj = isObject(data);
22633
+ var type = this._header['content-type'];
22634
+
22635
+ // merge
22636
+ if (obj && isObject(this._data)) {
22637
+ for (var key in data) {
22638
+ this._data[key] = data[key];
22639
+ }
22640
+ } else if ('string' == typeof data) {
22641
+ // default to x-www-form-urlencoded
22642
+ if (!type) this.type('form');
22643
+ type = this._header['content-type'];
22644
+ if ('application/x-www-form-urlencoded' == type) {
22645
+ this._data = this._data
22646
+ ? this._data + '&' + data
22647
+ : data;
22648
+ } else {
22649
+ this._data = (this._data || '') + data;
22650
+ }
22651
+ } else {
22652
+ this._data = data;
22653
+ }
22654
+
22655
+ if (!obj || this._isHost(data)) return this;
22656
+
22657
+ // default to json
22658
+ if (!type) this.type('json');
22659
+ return this;
22660
+ };
22661
+
22662
+ },{"./is-object":50}],52:[function(require,module,exports){
22663
+ // The node and browser modules expose versions of this with the
22664
+ // appropriate constructor function bound as first argument
22665
+ /**
22666
+ * Issue a request:
22667
+ *
22668
+ * Examples:
22669
+ *
22670
+ * request('GET', '/users').end(callback)
22671
+ * request('/users').end(callback)
22672
+ * request('/users', callback)
22673
+ *
22674
+ * @param {String} method
22675
+ * @param {String|Function} url or callback
22676
+ * @return {Request}
22677
+ * @api public
22678
+ */
22679
+
22680
+ function request(RequestConstructor, method, url) {
22681
+ // callback
22682
+ if ('function' == typeof url) {
22683
+ return new RequestConstructor('GET', method).end(url);
22684
+ }
22685
+
22686
+ // url first
22687
+ if (2 == arguments.length) {
22688
+ return new RequestConstructor('GET', method);
22689
+ }
22690
+
22691
+ return new RequestConstructor(method, url);
22692
+ }
22443
22693
 
22444
22694
  module.exports = request;
22445
22695
 
22446
- },{"emitter":40,"reduce":47}],50:[function(require,module,exports){
22696
+ },{}],53:[function(require,module,exports){
22447
22697
  /*!
22448
22698
  * validate.js 0.9.0
22449
22699
  *