comprodls-sdk 2.56.0 → 2.57.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.
@@ -1139,7 +1139,7 @@ validator.validators.contains = function(value, options) {
1139
1139
  }
1140
1140
  }
1141
1141
  };
1142
- },{"./errors":7,"validate.js":50}],10:[function(require,module,exports){
1142
+ },{"./errors":7,"validate.js":53}],10:[function(require,module,exports){
1143
1143
  /*************************************************************************
1144
1144
  *
1145
1145
  * COMPRO CONFIDENTIAL
@@ -5030,7 +5030,9 @@ function getUserClasses(options) {
5030
5030
  requestAPI = helpers.api.setupAPIToken(requestAPI, self.token);
5031
5031
 
5032
5032
  // Call GET ALL USER Api
5033
- requestAPI.end(function(err, response) {
5033
+ requestAPI
5034
+ .agent(keepaliveAgent)
5035
+ .end(function(err, response) {
5034
5036
  if(err) {
5035
5037
  err = new DLSError(helpers.errors.ERROR_TYPES.API_ERROR, err);
5036
5038
  dfd.reject(err);
@@ -5530,7 +5532,9 @@ function getAllClasses(options) {
5530
5532
  requestAPI = helpers.api.setupAPIToken(requestAPI, self.token);
5531
5533
 
5532
5534
  //Call GET ALL USER Api
5533
- requestAPI.end(function(err, response) {
5535
+ requestAPI
5536
+ .agent(keepaliveAgent)
5537
+ .end(function(err, response) {
5534
5538
  if(err) {
5535
5539
  var esErrOptions = { type: helpers.errors.ERROR_TYPES.API_ERROR, err: err };
5536
5540
  var error = converter.convertElasticsearchErrResponse(esErrOptions);
@@ -5575,6 +5579,10 @@ function getAllClasses(options) {
5575
5579
  teacherCount: classEntity.teacherCount
5576
5580
  };
5577
5581
 
5582
+ if(classEntity.limits){
5583
+ classObj.limits = classEntity.limits;
5584
+ }
5585
+
5578
5586
  /**
5579
5587
  * Add class-tag association specific fields
5580
5588
  */
@@ -6011,7 +6019,9 @@ function enrollUsertoClass(options) {
6011
6019
  requestAPI = helpers.api.setupAPIToken(requestAPI, self.token);
6012
6020
 
6013
6021
  //Call GET Product by it's code Api
6014
- requestAPI.end(function(err, response) {
6022
+ requestAPI
6023
+ .agent(keepaliveAgent)
6024
+ .end(function(err, response) {
6015
6025
  if(err) {
6016
6026
  err = new DLSError(helpers.errors.ERROR_TYPES.API_ERROR, err);
6017
6027
  dfd.reject(err);
@@ -6064,7 +6074,9 @@ function enrollSelftoClass(options) {
6064
6074
  requestAPI = helpers.api.setupAPIToken(requestAPI, self.token);
6065
6075
 
6066
6076
  //Call GET Product by it's code Api
6067
- requestAPI.end(function(err, response) {
6077
+ requestAPI
6078
+ .agent(keepaliveAgent)
6079
+ .end(function(err, response) {
6068
6080
  if(err) {
6069
6081
  err = new DLSError(helpers.errors.ERROR_TYPES.API_ERROR, err);
6070
6082
  dfd.reject(err);
@@ -6120,7 +6132,9 @@ function enrollMultiUserstoClass(options) {
6120
6132
  requestAPI = helpers.api.setupAPIToken(requestAPI, self.token);
6121
6133
 
6122
6134
  //Call GET Product by it's code Api
6123
- requestAPI.end(function(err, response) {
6135
+ requestAPI
6136
+ .agent(keepaliveAgent)
6137
+ .end(function(err, response) {
6124
6138
  if(err) {
6125
6139
  err = new DLSError(helpers.errors.ERROR_TYPES.API_ERROR, err);
6126
6140
  dfd.reject(err);
@@ -6265,6 +6279,7 @@ function encodeURLParameter(options) {
6265
6279
  * ext_data: {} // Optional
6266
6280
  * analyticsharingmodel: '' // Optional - Valid values: ['NOINHERIT_SYNCBACK']
6267
6281
  * analytics_score_aggregation_type: '' // Optional - Valid values: ['best'/'first'/'last']
6282
+ * limits: {"los": number, "students": number} // Optional field
6268
6283
  * }
6269
6284
  */
6270
6285
  function createClass(options) {
@@ -6302,7 +6317,9 @@ function createClass(options) {
6302
6317
  //Setup token in Authorization header
6303
6318
  requestAPI = helpers.api.setupAPIToken(requestAPI, self.token);
6304
6319
 
6305
- requestAPI.end(function(err, response) {
6320
+ requestAPI
6321
+ .agent(keepaliveAgent)
6322
+ .end(function(err, response) {
6306
6323
  if(err) {
6307
6324
  err = new DLSError(helpers.errors.ERROR_TYPES.API_ERROR, err);
6308
6325
  dfd.reject(err);
@@ -6329,6 +6346,7 @@ function createClass(options) {
6329
6346
  // description: '', //Optional field
6330
6347
  // ext_data: '' //Optional field
6331
6348
  // analytics_score_aggregation_type: '' // Optional - Valid values: ['best'/'first'/'last']
6349
+ // limits: {"los": number, "students": number} // Optional field
6332
6350
  //}
6333
6351
  function updateClass(options) {
6334
6352
  var self = this;
@@ -6354,7 +6372,9 @@ function updateClass(options) {
6354
6372
  //Setup token in Authorization header
6355
6373
  requestAPI = helpers.api.setupAPIToken(requestAPI, self.token);
6356
6374
 
6357
- requestAPI.end(function(err, response) {
6375
+ requestAPI
6376
+ .agent(keepaliveAgent)
6377
+ .end(function(err, response) {
6358
6378
  if(err) {
6359
6379
  err = new DLSError(helpers.errors.ERROR_TYPES.API_ERROR, err);
6360
6380
  dfd.reject(err);
@@ -6388,6 +6408,7 @@ function updateClass(options) {
6388
6408
  "model": "STRICT",
6389
6409
  "analyticsharingmodel":"NOINHERIT_SYNCBACK" // optional
6390
6410
  "analytics_score_aggregation_type":"first/best/last" // optional
6411
+ limits: {los: number, students: number} // Optional field
6391
6412
  "owner": {
6392
6413
  "userid": "string" //Mandatory if model is 'STRICT'
6393
6414
  },
@@ -6432,6 +6453,7 @@ function updateClass(options) {
6432
6453
  "analyticsharingmodel": true,
6433
6454
  "analytics_score_aggregation_type": true,
6434
6455
  "ext_data": true,
6456
+ "limits": true,
6435
6457
  "advanced": {
6436
6458
  "students": [
6437
6459
  {
@@ -6465,7 +6487,8 @@ function updateClass(options) {
6465
6487
  ],
6466
6488
  "products": [ { "productcode": "string" } ],
6467
6489
  "analyticsharingmodel": "string" // Valid values: ['NOINHERIT_SYNCBACK']
6468
- "analytics_score_aggregation_type": "string" // Valid values: ['best', 'first', 'last']
6490
+ "analytics_score_aggregation_type": "string", // Valid values: ['best', 'first', 'last']
6491
+ "limits": {los: number, students: number} // Optional field
6469
6492
  }
6470
6493
  }
6471
6494
  }
@@ -6498,7 +6521,9 @@ function createMultipleClasses(options) {
6498
6521
  //Setup token in Authorization header
6499
6522
  requestAPI = helpers.api.setupAPIToken(requestAPI, self.token);
6500
6523
 
6501
- requestAPI.end(function (err, response) {
6524
+ requestAPI
6525
+ .agent(keepaliveAgent)
6526
+ .end(function (err, response) {
6502
6527
  if (err) {
6503
6528
  err = new DLSError(helpers.errors.ERROR_TYPES.API_ERROR, err);
6504
6529
  dfd.reject(err);
@@ -6675,12 +6700,18 @@ function deleteAssignedPath(options) {
6675
6700
  options = {
6676
6701
  classid: 'string' //mandatory
6677
6702
  assignedpathid: 'string' //mandatory
6678
- data:
6679
- {
6680
- title: 'string' //optional
6681
- startdate: 'string' //optional
6682
- duedate: 'string' //optional
6683
- }
6703
+ data: {
6704
+ title: 'string' //optional
6705
+ startdate: 'string' //optional
6706
+ duedate: 'string' //optional
6707
+ items: [ //optional
6708
+ {
6709
+ item-code: 'string', //mandatory
6710
+ item_type: 'string', //mandatory, ['dls-internal','external']
6711
+ dls_product_code: 'string' //mandatory only if item_type is 'dls-internal'
6712
+ }
6713
+ ]
6714
+ }
6684
6715
  }
6685
6716
  */
6686
6717
  function updateAssignedPath(options) {
@@ -6703,7 +6734,9 @@ function updateAssignedPath(options) {
6703
6734
  //Setup token in Authorization header
6704
6735
  requestAPI = helpers.api.setupAPIToken(requestAPI, self.token);
6705
6736
 
6706
- requestAPI.end(function (error, response) {
6737
+ requestAPI
6738
+ .agent(keepaliveAgent)
6739
+ .end(function (error, response) {
6707
6740
  if(error) {
6708
6741
  err = new DLSError(helpers.errors.ERROR_TYPES.API_ERROR, error);
6709
6742
  dfd.reject(err);
@@ -7465,7 +7498,9 @@ function cloneClass(options) {
7465
7498
  //Setup token in Authorization header
7466
7499
  requestAPI = helpers.api.setupAPIToken(requestAPI, self.token);
7467
7500
 
7468
- requestAPI.end(function(err, response) {
7501
+ requestAPI
7502
+ .agent(keepaliveAgent)
7503
+ .end(function(err, response) {
7469
7504
  if(err) {
7470
7505
  err = new DLSError(helpers.errors.ERROR_TYPES.API_ERROR, err);
7471
7506
  dfd.reject(err);
@@ -13561,26 +13596,34 @@ function provisionBulkSpaces(options) {
13561
13596
  * *startdate: <epoch>,
13562
13597
  * *enddate: <epoch>,
13563
13598
  * description: 'string',
13564
- * ext_data: {}
13599
+ * ext_data: {},
13600
+ * limits: {
13601
+ * *los: 0,
13602
+ * *students: 0
13603
+ * }
13604
+ * },
13605
+ * checkLimits: {
13606
+ * student: 0,
13607
+ * teacher: 0
13608
+ * },
13609
+ * clone_settings: {
13610
+ * *src_ext_classid: 'string',
13611
+ * products: boolean,
13612
+ * assigned_paths: boolean,
13613
+ * advanced: {
13614
+ * assigned_paths: [ //length > 0 if assigned_paths flag is true
13615
+ * {
13616
+ * *ext_assignedpathid: 'string',
13617
+ * *assigned_path_id: 'string',
13618
+ * startdate: 0,
13619
+ * *duedate: 0
13620
+ * },
13621
+ * ],
13622
+ * products: [
13623
+ * { *productcode: 'string' },
13624
+ * ]
13625
+ * }
13565
13626
  * }
13566
- * clone_settings: {
13567
- * *src_ext_classid: 'string',
13568
- * products: boolean,
13569
- * assigned_paths: boolean,
13570
- * advanced: {
13571
- * assigned_paths: [ //length > 0 if assigned_paths flag is true
13572
- * {
13573
- * *ext_assignedpathid: 'string',
13574
- * *assigned_path_id: 'string',
13575
- * startdate: 0,
13576
- * *duedate: 0
13577
- * },
13578
- * ],
13579
- * products: [
13580
- * { *productcode: 'string' },
13581
- * ]
13582
- * }
13583
- * }
13584
13627
  * }
13585
13628
  */
13586
13629
  function shadowProvision(options) {
@@ -17574,167 +17617,181 @@ module.exports = Array.isArray || function (arr) {
17574
17617
  };
17575
17618
 
17576
17619
  },{}],40:[function(require,module,exports){
17577
-
17578
- /**
17579
- * Expose `Emitter`.
17580
- */
17581
-
17582
- module.exports = Emitter;
17583
-
17584
- /**
17585
- * Initialize a new `Emitter`.
17586
- *
17587
- * @api public
17588
- */
17589
-
17590
- function Emitter(obj) {
17591
- if (obj) return mixin(obj);
17592
- };
17593
-
17594
- /**
17595
- * Mixin the emitter properties.
17596
- *
17597
- * @param {Object} obj
17598
- * @return {Object}
17599
- * @api private
17600
- */
17601
-
17602
- function mixin(obj) {
17603
- for (var key in Emitter.prototype) {
17604
- obj[key] = Emitter.prototype[key];
17605
- }
17606
- return obj;
17607
- }
17608
-
17609
- /**
17610
- * Listen on the given `event` with `fn`.
17611
- *
17612
- * @param {String} event
17613
- * @param {Function} fn
17614
- * @return {Emitter}
17615
- * @api public
17616
- */
17617
-
17618
- Emitter.prototype.on =
17619
- Emitter.prototype.addEventListener = function(event, fn){
17620
- this._callbacks = this._callbacks || {};
17621
- (this._callbacks['$' + event] = this._callbacks['$' + event] || [])
17622
- .push(fn);
17623
- return this;
17624
- };
17625
-
17626
- /**
17627
- * Adds an `event` listener that will be invoked a single
17628
- * time then automatically removed.
17629
- *
17630
- * @param {String} event
17631
- * @param {Function} fn
17632
- * @return {Emitter}
17633
- * @api public
17634
- */
17635
-
17636
- Emitter.prototype.once = function(event, fn){
17637
- function on() {
17638
- this.off(event, on);
17639
- fn.apply(this, arguments);
17640
- }
17641
-
17642
- on.fn = fn;
17643
- this.on(event, on);
17644
- return this;
17645
- };
17646
-
17647
- /**
17648
- * Remove the given callback for `event` or all
17649
- * registered callbacks.
17650
- *
17651
- * @param {String} event
17652
- * @param {Function} fn
17653
- * @return {Emitter}
17654
- * @api public
17655
- */
17656
-
17657
- Emitter.prototype.off =
17658
- Emitter.prototype.removeListener =
17659
- Emitter.prototype.removeAllListeners =
17660
- Emitter.prototype.removeEventListener = function(event, fn){
17661
- this._callbacks = this._callbacks || {};
17662
-
17663
- // all
17664
- if (0 == arguments.length) {
17665
- this._callbacks = {};
17666
- return this;
17667
- }
17668
-
17669
- // specific event
17670
- var callbacks = this._callbacks['$' + event];
17671
- if (!callbacks) return this;
17672
-
17673
- // remove all handlers
17674
- if (1 == arguments.length) {
17675
- delete this._callbacks['$' + event];
17676
- return this;
17677
- }
17678
-
17679
- // remove specific handler
17680
- var cb;
17681
- for (var i = 0; i < callbacks.length; i++) {
17682
- cb = callbacks[i];
17683
- if (cb === fn || cb.fn === fn) {
17684
- callbacks.splice(i, 1);
17685
- break;
17686
- }
17687
- }
17688
- return this;
17689
- };
17690
-
17691
- /**
17692
- * Emit `event` with the given args.
17693
- *
17694
- * @param {String} event
17695
- * @param {Mixed} ...
17696
- * @return {Emitter}
17697
- */
17698
-
17699
- Emitter.prototype.emit = function(event){
17700
- this._callbacks = this._callbacks || {};
17701
- var args = [].slice.call(arguments, 1)
17702
- , callbacks = this._callbacks['$' + event];
17703
-
17704
- if (callbacks) {
17705
- callbacks = callbacks.slice(0);
17706
- for (var i = 0, len = callbacks.length; i < len; ++i) {
17707
- callbacks[i].apply(this, args);
17708
- }
17709
- }
17710
-
17711
- return this;
17712
- };
17713
-
17714
- /**
17715
- * Return array of callbacks for `event`.
17716
- *
17717
- * @param {String} event
17718
- * @return {Array}
17719
- * @api public
17720
- */
17721
-
17722
- Emitter.prototype.listeners = function(event){
17723
- this._callbacks = this._callbacks || {};
17724
- return this._callbacks['$' + event] || [];
17725
- };
17726
-
17727
- /**
17728
- * Check if this emitter has `event` handlers.
17729
- *
17730
- * @param {String} event
17731
- * @return {Boolean}
17732
- * @api public
17733
- */
17734
-
17735
- Emitter.prototype.hasListeners = function(event){
17736
- return !! this.listeners(event).length;
17737
- };
17620
+
17621
+ /**
17622
+ * Expose `Emitter`.
17623
+ */
17624
+
17625
+ if (typeof module !== 'undefined') {
17626
+ module.exports = Emitter;
17627
+ }
17628
+
17629
+ /**
17630
+ * Initialize a new `Emitter`.
17631
+ *
17632
+ * @api public
17633
+ */
17634
+
17635
+ function Emitter(obj) {
17636
+ if (obj) return mixin(obj);
17637
+ };
17638
+
17639
+ /**
17640
+ * Mixin the emitter properties.
17641
+ *
17642
+ * @param {Object} obj
17643
+ * @return {Object}
17644
+ * @api private
17645
+ */
17646
+
17647
+ function mixin(obj) {
17648
+ for (var key in Emitter.prototype) {
17649
+ obj[key] = Emitter.prototype[key];
17650
+ }
17651
+ return obj;
17652
+ }
17653
+
17654
+ /**
17655
+ * Listen on the given `event` with `fn`.
17656
+ *
17657
+ * @param {String} event
17658
+ * @param {Function} fn
17659
+ * @return {Emitter}
17660
+ * @api public
17661
+ */
17662
+
17663
+ Emitter.prototype.on =
17664
+ Emitter.prototype.addEventListener = function(event, fn){
17665
+ this._callbacks = this._callbacks || {};
17666
+ (this._callbacks['$' + event] = this._callbacks['$' + event] || [])
17667
+ .push(fn);
17668
+ return this;
17669
+ };
17670
+
17671
+ /**
17672
+ * Adds an `event` listener that will be invoked a single
17673
+ * time then automatically removed.
17674
+ *
17675
+ * @param {String} event
17676
+ * @param {Function} fn
17677
+ * @return {Emitter}
17678
+ * @api public
17679
+ */
17680
+
17681
+ Emitter.prototype.once = function(event, fn){
17682
+ function on() {
17683
+ this.off(event, on);
17684
+ fn.apply(this, arguments);
17685
+ }
17686
+
17687
+ on.fn = fn;
17688
+ this.on(event, on);
17689
+ return this;
17690
+ };
17691
+
17692
+ /**
17693
+ * Remove the given callback for `event` or all
17694
+ * registered callbacks.
17695
+ *
17696
+ * @param {String} event
17697
+ * @param {Function} fn
17698
+ * @return {Emitter}
17699
+ * @api public
17700
+ */
17701
+
17702
+ Emitter.prototype.off =
17703
+ Emitter.prototype.removeListener =
17704
+ Emitter.prototype.removeAllListeners =
17705
+ Emitter.prototype.removeEventListener = function(event, fn){
17706
+ this._callbacks = this._callbacks || {};
17707
+
17708
+ // all
17709
+ if (0 == arguments.length) {
17710
+ this._callbacks = {};
17711
+ return this;
17712
+ }
17713
+
17714
+ // specific event
17715
+ var callbacks = this._callbacks['$' + event];
17716
+ if (!callbacks) return this;
17717
+
17718
+ // remove all handlers
17719
+ if (1 == arguments.length) {
17720
+ delete this._callbacks['$' + event];
17721
+ return this;
17722
+ }
17723
+
17724
+ // remove specific handler
17725
+ var cb;
17726
+ for (var i = 0; i < callbacks.length; i++) {
17727
+ cb = callbacks[i];
17728
+ if (cb === fn || cb.fn === fn) {
17729
+ callbacks.splice(i, 1);
17730
+ break;
17731
+ }
17732
+ }
17733
+
17734
+ // Remove event specific arrays for event types that no
17735
+ // one is subscribed for to avoid memory leak.
17736
+ if (callbacks.length === 0) {
17737
+ delete this._callbacks['$' + event];
17738
+ }
17739
+
17740
+ return this;
17741
+ };
17742
+
17743
+ /**
17744
+ * Emit `event` with the given args.
17745
+ *
17746
+ * @param {String} event
17747
+ * @param {Mixed} ...
17748
+ * @return {Emitter}
17749
+ */
17750
+
17751
+ Emitter.prototype.emit = function(event){
17752
+ this._callbacks = this._callbacks || {};
17753
+
17754
+ var args = new Array(arguments.length - 1)
17755
+ , callbacks = this._callbacks['$' + event];
17756
+
17757
+ for (var i = 1; i < arguments.length; i++) {
17758
+ args[i - 1] = arguments[i];
17759
+ }
17760
+
17761
+ if (callbacks) {
17762
+ callbacks = callbacks.slice(0);
17763
+ for (var i = 0, len = callbacks.length; i < len; ++i) {
17764
+ callbacks[i].apply(this, args);
17765
+ }
17766
+ }
17767
+
17768
+ return this;
17769
+ };
17770
+
17771
+ /**
17772
+ * Return array of callbacks for `event`.
17773
+ *
17774
+ * @param {String} event
17775
+ * @return {Array}
17776
+ * @api public
17777
+ */
17778
+
17779
+ Emitter.prototype.listeners = function(event){
17780
+ this._callbacks = this._callbacks || {};
17781
+ return this._callbacks['$' + event] || [];
17782
+ };
17783
+
17784
+ /**
17785
+ * Check if this emitter has `event` handlers.
17786
+ *
17787
+ * @param {String} event
17788
+ * @return {Boolean}
17789
+ * @api public
17790
+ */
17791
+
17792
+ Emitter.prototype.hasListeners = function(event){
17793
+ return !! this.listeners(event).length;
17794
+ };
17738
17795
 
17739
17796
  },{}],41:[function(require,module,exports){
17740
17797
  // Copyright Joyent, Inc. and other Node contributors.
@@ -18040,6 +18097,8 @@ function isUndefined(arg) {
18040
18097
  }
18041
18098
 
18042
18099
  },{}],42:[function(require,module,exports){
18100
+ 'use strict';
18101
+
18043
18102
  var hasOwn = Object.prototype.hasOwnProperty;
18044
18103
  var toStr = Object.prototype.toString;
18045
18104
  var defineProperty = Object.defineProperty;
@@ -18054,8 +18113,6 @@ var isArray = function isArray(arr) {
18054
18113
  };
18055
18114
 
18056
18115
  var isPlainObject = function isPlainObject(obj) {
18057
- 'use strict';
18058
-
18059
18116
  if (!obj || toStr.call(obj) !== '[object Object]') {
18060
18117
  return false;
18061
18118
  }
@@ -18105,8 +18162,6 @@ var getProperty = function getProperty(obj, name) {
18105
18162
  };
18106
18163
 
18107
18164
  module.exports = function extend() {
18108
- 'use strict';
18109
-
18110
18165
  var options, name, src, copy, copyIsArray, clone;
18111
18166
  var target = arguments[0];
18112
18167
  var i = 1;
@@ -20576,6 +20631,8 @@ function template(string) {
20576
20631
 
20577
20632
  var Emitter = require('emitter');
20578
20633
  var reduce = require('reduce');
20634
+ var requestBase = require('./request-base');
20635
+ var isObject = require('./is-object');
20579
20636
 
20580
20637
  /**
20581
20638
  * Root reference for iframes.
@@ -20597,28 +20654,10 @@ if (typeof window !== 'undefined') { // Browser window
20597
20654
  function noop(){};
20598
20655
 
20599
20656
  /**
20600
- * Check if `obj` is a host object,
20601
- * we don't want to serialize these :)
20602
- *
20603
- * TODO: future proof, move to compoent land
20604
- *
20605
- * @param {Object} obj
20606
- * @return {Boolean}
20607
- * @api private
20657
+ * Expose `request`.
20608
20658
  */
20609
20659
 
20610
- function isHost(obj) {
20611
- var str = {}.toString.call(obj);
20612
-
20613
- switch (str) {
20614
- case '[object File]':
20615
- case '[object Blob]':
20616
- case '[object FormData]':
20617
- return true;
20618
- default:
20619
- return false;
20620
- }
20621
- }
20660
+ var request = module.exports = require('./request').bind(null, Request);
20622
20661
 
20623
20662
  /**
20624
20663
  * Determine XHR.
@@ -20650,18 +20689,6 @@ var trim = ''.trim
20650
20689
  ? function(s) { return s.trim(); }
20651
20690
  : function(s) { return s.replace(/(^\s*|\s*$)/g, ''); };
20652
20691
 
20653
- /**
20654
- * Check if `obj` is an object.
20655
- *
20656
- * @param {Object} obj
20657
- * @return {Boolean}
20658
- * @api private
20659
- */
20660
-
20661
- function isObject(obj) {
20662
- return obj === Object(obj);
20663
- }
20664
-
20665
20692
  /**
20666
20693
  * Serialize the given `obj`.
20667
20694
  *
@@ -20676,8 +20703,8 @@ function serialize(obj) {
20676
20703
  for (var key in obj) {
20677
20704
  if (null != obj[key]) {
20678
20705
  pushEncodedKeyValuePair(pairs, key, obj[key]);
20679
- }
20680
- }
20706
+ }
20707
+ }
20681
20708
  return pairs.join('&');
20682
20709
  }
20683
20710
 
@@ -20695,6 +20722,11 @@ function pushEncodedKeyValuePair(pairs, key, val) {
20695
20722
  return val.forEach(function(v) {
20696
20723
  pushEncodedKeyValuePair(pairs, key, v);
20697
20724
  });
20725
+ } else if (isObject(val)) {
20726
+ for(var subkey in val) {
20727
+ pushEncodedKeyValuePair(pairs, key + '[' + subkey + ']', val[subkey]);
20728
+ }
20729
+ return;
20698
20730
  }
20699
20731
  pairs.push(encodeURIComponent(key)
20700
20732
  + '=' + encodeURIComponent(val));
@@ -20717,13 +20749,18 @@ function pushEncodedKeyValuePair(pairs, key, val) {
20717
20749
  function parseString(str) {
20718
20750
  var obj = {};
20719
20751
  var pairs = str.split('&');
20720
- var parts;
20721
20752
  var pair;
20753
+ var pos;
20722
20754
 
20723
20755
  for (var i = 0, len = pairs.length; i < len; ++i) {
20724
20756
  pair = pairs[i];
20725
- parts = pair.split('=');
20726
- obj[decodeURIComponent(parts[0])] = decodeURIComponent(parts[1]);
20757
+ pos = pair.indexOf('=');
20758
+ if (pos == -1) {
20759
+ obj[decodeURIComponent(pair)] = '';
20760
+ } else {
20761
+ obj[decodeURIComponent(pair.slice(0, pos))] =
20762
+ decodeURIComponent(pair.slice(pos + 1));
20763
+ }
20727
20764
  }
20728
20765
 
20729
20766
  return obj;
@@ -20907,15 +20944,15 @@ function Response(req, options) {
20907
20944
  ? this.xhr.responseText
20908
20945
  : null;
20909
20946
  this.statusText = this.req.xhr.statusText;
20910
- this.setStatusProperties(this.xhr.status);
20947
+ this._setStatusProperties(this.xhr.status);
20911
20948
  this.header = this.headers = parseHeader(this.xhr.getAllResponseHeaders());
20912
20949
  // getAllResponseHeaders sometimes falsely returns "" for CORS requests, but
20913
20950
  // getResponseHeader still works. so we get content-type even if getting
20914
20951
  // other headers fails.
20915
20952
  this.header['content-type'] = this.xhr.getResponseHeader('content-type');
20916
- this.setHeaderProperties(this.header);
20953
+ this._setHeaderProperties(this.header);
20917
20954
  this.body = this.req.method != 'HEAD'
20918
- ? this.parseBody(this.text ? this.text : this.xhr.response)
20955
+ ? this._parseBody(this.text ? this.text : this.xhr.response)
20919
20956
  : null;
20920
20957
  }
20921
20958
 
@@ -20943,7 +20980,7 @@ Response.prototype.get = function(field){
20943
20980
  * @api private
20944
20981
  */
20945
20982
 
20946
- Response.prototype.setHeaderProperties = function(header){
20983
+ Response.prototype._setHeaderProperties = function(header){
20947
20984
  // content-type
20948
20985
  var ct = this.header['content-type'] || '';
20949
20986
  this.type = type(ct);
@@ -20964,8 +21001,11 @@ Response.prototype.setHeaderProperties = function(header){
20964
21001
  * @api private
20965
21002
  */
20966
21003
 
20967
- Response.prototype.parseBody = function(str){
21004
+ Response.prototype._parseBody = function(str){
20968
21005
  var parse = request.parse[this.type];
21006
+ if (!parse && isJSON(this.type)) {
21007
+ parse = request.parse['application/json'];
21008
+ }
20969
21009
  return parse && str && (str.length || str instanceof Object)
20970
21010
  ? parse(str)
20971
21011
  : null;
@@ -20992,7 +21032,7 @@ Response.prototype.parseBody = function(str){
20992
21032
  * @api private
20993
21033
  */
20994
21034
 
20995
- Response.prototype.setStatusProperties = function(status){
21035
+ Response.prototype._setStatusProperties = function(status){
20996
21036
  // handle IE9 bug: http://stackoverflow.com/questions/10046972/msie-returns-status-code-of-1223-for-ajax-request
20997
21037
  if (status === 1223) {
20998
21038
  status = 204;
@@ -21060,12 +21100,11 @@ request.Response = Response;
21060
21100
 
21061
21101
  function Request(method, url) {
21062
21102
  var self = this;
21063
- Emitter.call(this);
21064
21103
  this._query = this._query || [];
21065
21104
  this.method = method;
21066
21105
  this.url = url;
21067
- this.header = {};
21068
- this._header = {};
21106
+ this.header = {}; // preserves header name case
21107
+ this._header = {}; // coerces header names to lowercase
21069
21108
  this.on('end', function(){
21070
21109
  var err = null;
21071
21110
  var res = null;
@@ -21078,6 +21117,8 @@ function Request(method, url) {
21078
21117
  err.original = e;
21079
21118
  // issue #675: return the raw response if the response parsing fails
21080
21119
  err.rawResponse = self.xhr && self.xhr.responseText ? self.xhr.responseText : null;
21120
+ // issue #876: return the http status code if the response parsing fails
21121
+ err.statusCode = self.xhr && self.xhr.status ? self.xhr.status : null;
21081
21122
  return self.callback(err);
21082
21123
  }
21083
21124
 
@@ -21087,140 +21128,32 @@ function Request(method, url) {
21087
21128
  return self.callback(err, res);
21088
21129
  }
21089
21130
 
21090
- if (res.status >= 200 && res.status < 300) {
21091
- return self.callback(err, res);
21092
- }
21131
+ try {
21132
+ if (res.status >= 200 && res.status < 300) {
21133
+ return self.callback(err, res);
21134
+ }
21093
21135
 
21094
- var new_err = new Error(res.statusText || 'Unsuccessful HTTP response');
21095
- new_err.original = err;
21096
- new_err.response = res;
21097
- new_err.status = res.status;
21136
+ var new_err = new Error(res.statusText || 'Unsuccessful HTTP response');
21137
+ new_err.original = err;
21138
+ new_err.response = res;
21139
+ new_err.status = res.status;
21098
21140
 
21099
- self.callback(new_err, res);
21100
- });
21141
+ self.callback(new_err, res);
21142
+ } catch(e) {
21143
+ self.callback(e); // #985 touching res may cause INVALID_STATE_ERR on old Android
21144
+ }
21145
+ });
21101
21146
  }
21102
21147
 
21103
21148
  /**
21104
- * Mixin `Emitter`.
21149
+ * Mixin `Emitter` and `requestBase`.
21105
21150
  */
21106
21151
 
21107
21152
  Emitter(Request.prototype);
21108
-
21109
- /**
21110
- * Allow for extension
21111
- */
21112
-
21113
- Request.prototype.use = function(fn) {
21114
- fn(this);
21115
- return this;
21153
+ for (var key in requestBase) {
21154
+ Request.prototype[key] = requestBase[key];
21116
21155
  }
21117
21156
 
21118
- /**
21119
- * Set timeout to `ms`.
21120
- *
21121
- * @param {Number} ms
21122
- * @return {Request} for chaining
21123
- * @api public
21124
- */
21125
-
21126
- Request.prototype.timeout = function(ms){
21127
- this._timeout = ms;
21128
- return this;
21129
- };
21130
-
21131
- /**
21132
- * Clear previous timeout.
21133
- *
21134
- * @return {Request} for chaining
21135
- * @api public
21136
- */
21137
-
21138
- Request.prototype.clearTimeout = function(){
21139
- this._timeout = 0;
21140
- clearTimeout(this._timer);
21141
- return this;
21142
- };
21143
-
21144
- /**
21145
- * Abort the request, and clear potential timeout.
21146
- *
21147
- * @return {Request}
21148
- * @api public
21149
- */
21150
-
21151
- Request.prototype.abort = function(){
21152
- if (this.aborted) return;
21153
- this.aborted = true;
21154
- this.xhr.abort();
21155
- this.clearTimeout();
21156
- this.emit('abort');
21157
- return this;
21158
- };
21159
-
21160
- /**
21161
- * Set header `field` to `val`, or multiple fields with one object.
21162
- *
21163
- * Examples:
21164
- *
21165
- * req.get('/')
21166
- * .set('Accept', 'application/json')
21167
- * .set('X-API-Key', 'foobar')
21168
- * .end(callback);
21169
- *
21170
- * req.get('/')
21171
- * .set({ Accept: 'application/json', 'X-API-Key': 'foobar' })
21172
- * .end(callback);
21173
- *
21174
- * @param {String|Object} field
21175
- * @param {String} val
21176
- * @return {Request} for chaining
21177
- * @api public
21178
- */
21179
-
21180
- Request.prototype.set = function(field, val){
21181
- if (isObject(field)) {
21182
- for (var key in field) {
21183
- this.set(key, field[key]);
21184
- }
21185
- return this;
21186
- }
21187
- this._header[field.toLowerCase()] = val;
21188
- this.header[field] = val;
21189
- return this;
21190
- };
21191
-
21192
- /**
21193
- * Remove header `field`.
21194
- *
21195
- * Example:
21196
- *
21197
- * req.get('/')
21198
- * .unset('User-Agent')
21199
- * .end(callback);
21200
- *
21201
- * @param {String} field
21202
- * @return {Request} for chaining
21203
- * @api public
21204
- */
21205
-
21206
- Request.prototype.unset = function(field){
21207
- delete this._header[field.toLowerCase()];
21208
- delete this.header[field];
21209
- return this;
21210
- };
21211
-
21212
- /**
21213
- * Get case-insensitive header `field` value.
21214
- *
21215
- * @param {String} field
21216
- * @return {String}
21217
- * @api private
21218
- */
21219
-
21220
- Request.prototype.getHeader = function(field){
21221
- return this._header[field.toLowerCase()];
21222
- };
21223
-
21224
21157
  /**
21225
21158
  * Set Content-Type to `type`, mapping values from `request.types`.
21226
21159
  *
@@ -21249,16 +21182,22 @@ Request.prototype.type = function(type){
21249
21182
  };
21250
21183
 
21251
21184
  /**
21252
- * Force given parser
21185
+ * Set responseType to `val`. Presently valid responseTypes are 'blob' and
21186
+ * 'arraybuffer'.
21187
+ *
21188
+ * Examples:
21253
21189
  *
21254
- * Sets the body parser no matter type.
21190
+ * req.get('/')
21191
+ * .responseType('blob')
21192
+ * .end(callback);
21255
21193
  *
21256
- * @param {Function}
21194
+ * @param {String} val
21195
+ * @return {Request} for chaining
21257
21196
  * @api public
21258
21197
  */
21259
21198
 
21260
- Request.prototype.parse = function(fn){
21261
- this._parser = fn;
21199
+ Request.prototype.responseType = function(val){
21200
+ this._responseType = val;
21262
21201
  return this;
21263
21202
  };
21264
21203
 
@@ -21292,13 +21231,29 @@ Request.prototype.accept = function(type){
21292
21231
  *
21293
21232
  * @param {String} user
21294
21233
  * @param {String} pass
21234
+ * @param {Object} options with 'type' property 'auto' or 'basic' (default 'basic')
21295
21235
  * @return {Request} for chaining
21296
21236
  * @api public
21297
21237
  */
21298
21238
 
21299
- Request.prototype.auth = function(user, pass){
21300
- var str = btoa(user + ':' + pass);
21301
- this.set('Authorization', 'Basic ' + str);
21239
+ Request.prototype.auth = function(user, pass, options){
21240
+ if (!options) {
21241
+ options = {
21242
+ type: 'basic'
21243
+ }
21244
+ }
21245
+
21246
+ switch (options.type) {
21247
+ case 'basic':
21248
+ var str = btoa(user + ':' + pass);
21249
+ this.set('Authorization', 'Basic ' + str);
21250
+ break;
21251
+
21252
+ case 'auto':
21253
+ this.username = user;
21254
+ this.password = pass;
21255
+ break;
21256
+ }
21302
21257
  return this;
21303
21258
  };
21304
21259
 
@@ -21322,35 +21277,13 @@ Request.prototype.query = function(val){
21322
21277
  return this;
21323
21278
  };
21324
21279
 
21325
- /**
21326
- * Write the field `name` and `val` for "multipart/form-data"
21327
- * request bodies.
21328
- *
21329
- * ``` js
21330
- * request.post('/upload')
21331
- * .field('foo', 'bar')
21332
- * .end(callback);
21333
- * ```
21334
- *
21335
- * @param {String} name
21336
- * @param {String|Blob|File} val
21337
- * @return {Request} for chaining
21338
- * @api public
21339
- */
21340
-
21341
- Request.prototype.field = function(name, val){
21342
- if (!this._formData) this._formData = new root.FormData();
21343
- this._formData.append(name, val);
21344
- return this;
21345
- };
21346
-
21347
21280
  /**
21348
21281
  * Queue the given `file` as an attachment to the specified `field`,
21349
21282
  * with optional `filename`.
21350
21283
  *
21351
21284
  * ``` js
21352
21285
  * request.post('/upload')
21353
- * .attach(new Blob(['<a id="a"><b id="b">hey!</b></a>'], { type: "text/html"}))
21286
+ * .attach('content', new Blob(['<a id="a"><b id="b">hey!</b></a>'], { type: "text/html"}))
21354
21287
  * .end(callback);
21355
21288
  * ```
21356
21289
  *
@@ -21362,77 +21295,15 @@ Request.prototype.field = function(name, val){
21362
21295
  */
21363
21296
 
21364
21297
  Request.prototype.attach = function(field, file, filename){
21365
- if (!this._formData) this._formData = new root.FormData();
21366
- this._formData.append(field, file, filename || file.name);
21298
+ this._getFormData().append(field, file, filename || file.name);
21367
21299
  return this;
21368
21300
  };
21369
21301
 
21370
- /**
21371
- * Send `data` as the request body, defaulting the `.type()` to "json" when
21372
- * an object is given.
21373
- *
21374
- * Examples:
21375
- *
21376
- * // manual json
21377
- * request.post('/user')
21378
- * .type('json')
21379
- * .send('{"name":"tj"}')
21380
- * .end(callback)
21381
- *
21382
- * // auto json
21383
- * request.post('/user')
21384
- * .send({ name: 'tj' })
21385
- * .end(callback)
21386
- *
21387
- * // manual x-www-form-urlencoded
21388
- * request.post('/user')
21389
- * .type('form')
21390
- * .send('name=tj')
21391
- * .end(callback)
21392
- *
21393
- * // auto x-www-form-urlencoded
21394
- * request.post('/user')
21395
- * .type('form')
21396
- * .send({ name: 'tj' })
21397
- * .end(callback)
21398
- *
21399
- * // defaults to x-www-form-urlencoded
21400
- * request.post('/user')
21401
- * .send('name=tobi')
21402
- * .send('species=ferret')
21403
- * .end(callback)
21404
- *
21405
- * @param {String|Object} data
21406
- * @return {Request} for chaining
21407
- * @api public
21408
- */
21409
-
21410
- Request.prototype.send = function(data){
21411
- var obj = isObject(data);
21412
- var type = this.getHeader('Content-Type');
21413
-
21414
- // merge
21415
- if (obj && isObject(this._data)) {
21416
- for (var key in data) {
21417
- this._data[key] = data[key];
21418
- }
21419
- } else if ('string' == typeof data) {
21420
- if (!type) this.type('form');
21421
- type = this.getHeader('Content-Type');
21422
- if ('application/x-www-form-urlencoded' == type) {
21423
- this._data = this._data
21424
- ? this._data + '&' + data
21425
- : data;
21426
- } else {
21427
- this._data = (this._data || '') + data;
21428
- }
21429
- } else {
21430
- this._data = data;
21302
+ Request.prototype._getFormData = function(){
21303
+ if (!this._formData) {
21304
+ this._formData = new root.FormData();
21431
21305
  }
21432
-
21433
- if (!obj || isHost(data)) return this;
21434
- if (!type) this.type('json');
21435
- return this;
21306
+ return this._formData;
21436
21307
  };
21437
21308
 
21438
21309
  /**
@@ -21473,7 +21344,7 @@ Request.prototype.crossDomainError = function(){
21473
21344
  * @api private
21474
21345
  */
21475
21346
 
21476
- Request.prototype.timeoutError = function(){
21347
+ Request.prototype._timeoutError = function(){
21477
21348
  var timeout = this._timeout;
21478
21349
  var err = new Error('timeout of ' + timeout + 'ms exceeded');
21479
21350
  err.timeout = timeout;
@@ -21481,19 +21352,18 @@ Request.prototype.timeoutError = function(){
21481
21352
  };
21482
21353
 
21483
21354
  /**
21484
- * Enable transmission of cookies with x-domain requests.
21485
- *
21486
- * Note that for this to work the origin must not be
21487
- * using "Access-Control-Allow-Origin" with a wildcard,
21488
- * and also must set "Access-Control-Allow-Credentials"
21489
- * to "true".
21355
+ * Compose querystring to append to req.url
21490
21356
  *
21491
- * @api public
21357
+ * @api private
21492
21358
  */
21493
21359
 
21494
- Request.prototype.withCredentials = function(){
21495
- this._withCredentials = true;
21496
- return this;
21360
+ Request.prototype._appendQueryString = function(){
21361
+ var query = this._query.join('&');
21362
+ if (query) {
21363
+ this.url += ~this.url.indexOf('?')
21364
+ ? '&' + query
21365
+ : '?' + query;
21366
+ }
21497
21367
  };
21498
21368
 
21499
21369
  /**
@@ -21508,7 +21378,6 @@ Request.prototype.withCredentials = function(){
21508
21378
  Request.prototype.end = function(fn){
21509
21379
  var self = this;
21510
21380
  var xhr = this.xhr = request.getXHR();
21511
- var query = this._query.join('&');
21512
21381
  var timeout = this._timeout;
21513
21382
  var data = this._formData || this._data;
21514
21383
 
@@ -21525,8 +21394,8 @@ Request.prototype.end = function(fn){
21525
21394
  try { status = xhr.status } catch(e) { status = 0; }
21526
21395
 
21527
21396
  if (0 == status) {
21528
- if (self.timedout) return self.timeoutError();
21529
- if (self.aborted) return;
21397
+ if (self.timedout) return self._timeoutError();
21398
+ if (self._aborted) return;
21530
21399
  return self.crossDomainError();
21531
21400
  }
21532
21401
  self.emit('end');
@@ -21562,24 +21431,23 @@ Request.prototype.end = function(fn){
21562
21431
  }
21563
21432
 
21564
21433
  // querystring
21565
- if (query) {
21566
- query = request.serializeObject(query);
21567
- this.url += ~this.url.indexOf('?')
21568
- ? '&' + query
21569
- : '?' + query;
21570
- }
21434
+ this._appendQueryString();
21571
21435
 
21572
21436
  // initiate request
21573
- xhr.open(this.method, this.url, true);
21437
+ if (this.username && this.password) {
21438
+ xhr.open(this.method, this.url, true, this.username, this.password);
21439
+ } else {
21440
+ xhr.open(this.method, this.url, true);
21441
+ }
21574
21442
 
21575
21443
  // CORS
21576
21444
  if (this._withCredentials) xhr.withCredentials = true;
21577
21445
 
21578
21446
  // body
21579
- if ('GET' != this.method && 'HEAD' != this.method && 'string' != typeof data && !isHost(data)) {
21447
+ if ('GET' != this.method && 'HEAD' != this.method && 'string' != typeof data && !this._isHost(data)) {
21580
21448
  // serialize stuff
21581
- var contentType = this.getHeader('Content-Type');
21582
- var serialize = this._parser || request.serialize[contentType ? contentType.split(';')[0] : ''];
21449
+ var contentType = this._header['content-type'];
21450
+ var serialize = this._serializer || request.serialize[contentType ? contentType.split(';')[0] : ''];
21583
21451
  if (!serialize && isJSON(contentType)) serialize = request.serialize['application/json'];
21584
21452
  if (serialize) data = serialize(data);
21585
21453
  }
@@ -21590,6 +21458,10 @@ Request.prototype.end = function(fn){
21590
21458
  xhr.setRequestHeader(field, this.header[field]);
21591
21459
  }
21592
21460
 
21461
+ if (this._responseType) {
21462
+ xhr.responseType = this._responseType;
21463
+ }
21464
+
21593
21465
  // send stuff
21594
21466
  this.emit('request', this);
21595
21467
 
@@ -21599,19 +21471,6 @@ Request.prototype.end = function(fn){
21599
21471
  return this;
21600
21472
  };
21601
21473
 
21602
- /**
21603
- * Faux promise support
21604
- *
21605
- * @param {Function} fulfill
21606
- * @param {Function} reject
21607
- * @return {Request}
21608
- */
21609
-
21610
- Request.prototype.then = function (fulfill, reject) {
21611
- return this.end(function(err, res) {
21612
- err ? reject(err) : fulfill(res);
21613
- });
21614
- }
21615
21474
 
21616
21475
  /**
21617
21476
  * Expose `Request`.
@@ -21619,35 +21478,6 @@ Request.prototype.then = function (fulfill, reject) {
21619
21478
 
21620
21479
  request.Request = Request;
21621
21480
 
21622
- /**
21623
- * Issue a request:
21624
- *
21625
- * Examples:
21626
- *
21627
- * request('GET', '/users').end(callback)
21628
- * request('/users').end(callback)
21629
- * request('/users', callback)
21630
- *
21631
- * @param {String} method
21632
- * @param {String|Function} url or callback
21633
- * @return {Request}
21634
- * @api public
21635
- */
21636
-
21637
- function request(method, url) {
21638
- // callback
21639
- if ('function' == typeof url) {
21640
- return new Request('GET', method).end(url);
21641
- }
21642
-
21643
- // url first
21644
- if (1 == arguments.length) {
21645
- return new Request('GET', method);
21646
- }
21647
-
21648
- return new Request(method, url);
21649
- }
21650
-
21651
21481
  /**
21652
21482
  * GET `url` with optional callback `fn(res)`.
21653
21483
  *
@@ -21685,15 +21515,33 @@ request.head = function(url, data, fn){
21685
21515
  };
21686
21516
 
21687
21517
  /**
21688
- * DELETE `url` with optional callback `fn(res)`.
21518
+ * OPTIONS query to `url` with optional callback `fn(res)`.
21689
21519
  *
21690
21520
  * @param {String} url
21521
+ * @param {Mixed|Function} data or fn
21691
21522
  * @param {Function} fn
21692
21523
  * @return {Request}
21693
21524
  * @api public
21694
21525
  */
21695
21526
 
21696
- function del(url, fn){
21527
+ request.options = function(url, data, fn){
21528
+ var req = request('OPTIONS', url);
21529
+ if ('function' == typeof data) fn = data, data = null;
21530
+ if (data) req.send(data);
21531
+ if (fn) req.end(fn);
21532
+ return req;
21533
+ };
21534
+
21535
+ /**
21536
+ * DELETE `url` with optional callback `fn(res)`.
21537
+ *
21538
+ * @param {String} url
21539
+ * @param {Function} fn
21540
+ * @return {Request}
21541
+ * @api public
21542
+ */
21543
+
21544
+ function del(url, fn){
21697
21545
  var req = request('DELETE', url);
21698
21546
  if (fn) req.end(fn);
21699
21547
  return req;
@@ -21756,13 +21604,404 @@ request.put = function(url, data, fn){
21756
21604
  return req;
21757
21605
  };
21758
21606
 
21607
+ },{"./is-object":50,"./request":52,"./request-base":51,"emitter":40,"reduce":47}],50:[function(require,module,exports){
21759
21608
  /**
21760
- * Expose `request`.
21609
+ * Check if `obj` is an object.
21610
+ *
21611
+ * @param {Object} obj
21612
+ * @return {Boolean}
21613
+ * @api private
21614
+ */
21615
+
21616
+ function isObject(obj) {
21617
+ return null !== obj && 'object' === typeof obj;
21618
+ }
21619
+
21620
+ module.exports = isObject;
21621
+
21622
+ },{}],51:[function(require,module,exports){
21623
+ /**
21624
+ * Module of mixed-in functions shared between node and client code
21625
+ */
21626
+ var isObject = require('./is-object');
21627
+
21628
+ /**
21629
+ * Clear previous timeout.
21630
+ *
21631
+ * @return {Request} for chaining
21632
+ * @api public
21633
+ */
21634
+
21635
+ exports.clearTimeout = function _clearTimeout(){
21636
+ this._timeout = 0;
21637
+ clearTimeout(this._timer);
21638
+ return this;
21639
+ };
21640
+
21641
+ /**
21642
+ * Override default response body parser
21643
+ *
21644
+ * This function will be called to convert incoming data into request.body
21645
+ *
21646
+ * @param {Function}
21647
+ * @api public
21648
+ */
21649
+
21650
+ exports.parse = function parse(fn){
21651
+ this._parser = fn;
21652
+ return this;
21653
+ };
21654
+
21655
+ /**
21656
+ * Override default request body serializer
21657
+ *
21658
+ * This function will be called to convert data set via .send or .attach into payload to send
21659
+ *
21660
+ * @param {Function}
21661
+ * @api public
21662
+ */
21663
+
21664
+ exports.serialize = function serialize(fn){
21665
+ this._serializer = fn;
21666
+ return this;
21667
+ };
21668
+
21669
+ /**
21670
+ * Set timeout to `ms`.
21671
+ *
21672
+ * @param {Number} ms
21673
+ * @return {Request} for chaining
21674
+ * @api public
21761
21675
  */
21762
21676
 
21677
+ exports.timeout = function timeout(ms){
21678
+ this._timeout = ms;
21679
+ return this;
21680
+ };
21681
+
21682
+ /**
21683
+ * Promise support
21684
+ *
21685
+ * @param {Function} resolve
21686
+ * @param {Function} reject
21687
+ * @return {Request}
21688
+ */
21689
+
21690
+ exports.then = function then(resolve, reject) {
21691
+ if (!this._fullfilledPromise) {
21692
+ var self = this;
21693
+ this._fullfilledPromise = new Promise(function(innerResolve, innerReject){
21694
+ self.end(function(err, res){
21695
+ if (err) innerReject(err); else innerResolve(res);
21696
+ });
21697
+ });
21698
+ }
21699
+ return this._fullfilledPromise.then(resolve, reject);
21700
+ }
21701
+
21702
+ /**
21703
+ * Allow for extension
21704
+ */
21705
+
21706
+ exports.use = function use(fn) {
21707
+ fn(this);
21708
+ return this;
21709
+ }
21710
+
21711
+
21712
+ /**
21713
+ * Get request header `field`.
21714
+ * Case-insensitive.
21715
+ *
21716
+ * @param {String} field
21717
+ * @return {String}
21718
+ * @api public
21719
+ */
21720
+
21721
+ exports.get = function(field){
21722
+ return this._header[field.toLowerCase()];
21723
+ };
21724
+
21725
+ /**
21726
+ * Get case-insensitive header `field` value.
21727
+ * This is a deprecated internal API. Use `.get(field)` instead.
21728
+ *
21729
+ * (getHeader is no longer used internally by the superagent code base)
21730
+ *
21731
+ * @param {String} field
21732
+ * @return {String}
21733
+ * @api private
21734
+ * @deprecated
21735
+ */
21736
+
21737
+ exports.getHeader = exports.get;
21738
+
21739
+ /**
21740
+ * Set header `field` to `val`, or multiple fields with one object.
21741
+ * Case-insensitive.
21742
+ *
21743
+ * Examples:
21744
+ *
21745
+ * req.get('/')
21746
+ * .set('Accept', 'application/json')
21747
+ * .set('X-API-Key', 'foobar')
21748
+ * .end(callback);
21749
+ *
21750
+ * req.get('/')
21751
+ * .set({ Accept: 'application/json', 'X-API-Key': 'foobar' })
21752
+ * .end(callback);
21753
+ *
21754
+ * @param {String|Object} field
21755
+ * @param {String} val
21756
+ * @return {Request} for chaining
21757
+ * @api public
21758
+ */
21759
+
21760
+ exports.set = function(field, val){
21761
+ if (isObject(field)) {
21762
+ for (var key in field) {
21763
+ this.set(key, field[key]);
21764
+ }
21765
+ return this;
21766
+ }
21767
+ this._header[field.toLowerCase()] = val;
21768
+ this.header[field] = val;
21769
+ return this;
21770
+ };
21771
+
21772
+ /**
21773
+ * Remove header `field`.
21774
+ * Case-insensitive.
21775
+ *
21776
+ * Example:
21777
+ *
21778
+ * req.get('/')
21779
+ * .unset('User-Agent')
21780
+ * .end(callback);
21781
+ *
21782
+ * @param {String} field
21783
+ */
21784
+ exports.unset = function(field){
21785
+ delete this._header[field.toLowerCase()];
21786
+ delete this.header[field];
21787
+ return this;
21788
+ };
21789
+
21790
+ /**
21791
+ * Write the field `name` and `val` for "multipart/form-data"
21792
+ * request bodies.
21793
+ *
21794
+ * ``` js
21795
+ * request.post('/upload')
21796
+ * .field('foo', 'bar')
21797
+ * .end(callback);
21798
+ * ```
21799
+ *
21800
+ * @param {String} name
21801
+ * @param {String|Blob|File|Buffer|fs.ReadStream} val
21802
+ * @return {Request} for chaining
21803
+ * @api public
21804
+ */
21805
+ exports.field = function(name, val) {
21806
+ this._getFormData().append(name, val);
21807
+ return this;
21808
+ };
21809
+
21810
+ /**
21811
+ * Abort the request, and clear potential timeout.
21812
+ *
21813
+ * @return {Request}
21814
+ * @api public
21815
+ */
21816
+ exports.abort = function(){
21817
+ if (this._aborted) {
21818
+ return this;
21819
+ }
21820
+ this._aborted = true;
21821
+ this.xhr && this.xhr.abort(); // browser
21822
+ this.req && this.req.abort(); // node
21823
+ this.clearTimeout();
21824
+ this.emit('abort');
21825
+ return this;
21826
+ };
21827
+
21828
+ /**
21829
+ * Enable transmission of cookies with x-domain requests.
21830
+ *
21831
+ * Note that for this to work the origin must not be
21832
+ * using "Access-Control-Allow-Origin" with a wildcard,
21833
+ * and also must set "Access-Control-Allow-Credentials"
21834
+ * to "true".
21835
+ *
21836
+ * @api public
21837
+ */
21838
+
21839
+ exports.withCredentials = function(){
21840
+ // This is browser-only functionality. Node side is no-op.
21841
+ this._withCredentials = true;
21842
+ return this;
21843
+ };
21844
+
21845
+ /**
21846
+ * Set the max redirects to `n`. Does noting in browser XHR implementation.
21847
+ *
21848
+ * @param {Number} n
21849
+ * @return {Request} for chaining
21850
+ * @api public
21851
+ */
21852
+
21853
+ exports.redirects = function(n){
21854
+ this._maxRedirects = n;
21855
+ return this;
21856
+ };
21857
+
21858
+ /**
21859
+ * Convert to a plain javascript object (not JSON string) of scalar properties.
21860
+ * Note as this method is designed to return a useful non-this value,
21861
+ * it cannot be chained.
21862
+ *
21863
+ * @return {Object} describing method, url, and data of this request
21864
+ * @api public
21865
+ */
21866
+
21867
+ exports.toJSON = function(){
21868
+ return {
21869
+ method: this.method,
21870
+ url: this.url,
21871
+ data: this._data
21872
+ };
21873
+ };
21874
+
21875
+ /**
21876
+ * Check if `obj` is a host object,
21877
+ * we don't want to serialize these :)
21878
+ *
21879
+ * TODO: future proof, move to compoent land
21880
+ *
21881
+ * @param {Object} obj
21882
+ * @return {Boolean}
21883
+ * @api private
21884
+ */
21885
+
21886
+ exports._isHost = function _isHost(obj) {
21887
+ var str = {}.toString.call(obj);
21888
+
21889
+ switch (str) {
21890
+ case '[object File]':
21891
+ case '[object Blob]':
21892
+ case '[object FormData]':
21893
+ return true;
21894
+ default:
21895
+ return false;
21896
+ }
21897
+ }
21898
+
21899
+ /**
21900
+ * Send `data` as the request body, defaulting the `.type()` to "json" when
21901
+ * an object is given.
21902
+ *
21903
+ * Examples:
21904
+ *
21905
+ * // manual json
21906
+ * request.post('/user')
21907
+ * .type('json')
21908
+ * .send('{"name":"tj"}')
21909
+ * .end(callback)
21910
+ *
21911
+ * // auto json
21912
+ * request.post('/user')
21913
+ * .send({ name: 'tj' })
21914
+ * .end(callback)
21915
+ *
21916
+ * // manual x-www-form-urlencoded
21917
+ * request.post('/user')
21918
+ * .type('form')
21919
+ * .send('name=tj')
21920
+ * .end(callback)
21921
+ *
21922
+ * // auto x-www-form-urlencoded
21923
+ * request.post('/user')
21924
+ * .type('form')
21925
+ * .send({ name: 'tj' })
21926
+ * .end(callback)
21927
+ *
21928
+ * // defaults to x-www-form-urlencoded
21929
+ * request.post('/user')
21930
+ * .send('name=tobi')
21931
+ * .send('species=ferret')
21932
+ * .end(callback)
21933
+ *
21934
+ * @param {String|Object} data
21935
+ * @return {Request} for chaining
21936
+ * @api public
21937
+ */
21938
+
21939
+ exports.send = function(data){
21940
+ var obj = isObject(data);
21941
+ var type = this._header['content-type'];
21942
+
21943
+ // merge
21944
+ if (obj && isObject(this._data)) {
21945
+ for (var key in data) {
21946
+ this._data[key] = data[key];
21947
+ }
21948
+ } else if ('string' == typeof data) {
21949
+ // default to x-www-form-urlencoded
21950
+ if (!type) this.type('form');
21951
+ type = this._header['content-type'];
21952
+ if ('application/x-www-form-urlencoded' == type) {
21953
+ this._data = this._data
21954
+ ? this._data + '&' + data
21955
+ : data;
21956
+ } else {
21957
+ this._data = (this._data || '') + data;
21958
+ }
21959
+ } else {
21960
+ this._data = data;
21961
+ }
21962
+
21963
+ if (!obj || this._isHost(data)) return this;
21964
+
21965
+ // default to json
21966
+ if (!type) this.type('json');
21967
+ return this;
21968
+ };
21969
+
21970
+ },{"./is-object":50}],52:[function(require,module,exports){
21971
+ // The node and browser modules expose versions of this with the
21972
+ // appropriate constructor function bound as first argument
21973
+ /**
21974
+ * Issue a request:
21975
+ *
21976
+ * Examples:
21977
+ *
21978
+ * request('GET', '/users').end(callback)
21979
+ * request('/users').end(callback)
21980
+ * request('/users', callback)
21981
+ *
21982
+ * @param {String} method
21983
+ * @param {String|Function} url or callback
21984
+ * @return {Request}
21985
+ * @api public
21986
+ */
21987
+
21988
+ function request(RequestConstructor, method, url) {
21989
+ // callback
21990
+ if ('function' == typeof url) {
21991
+ return new RequestConstructor('GET', method).end(url);
21992
+ }
21993
+
21994
+ // url first
21995
+ if (2 == arguments.length) {
21996
+ return new RequestConstructor('GET', method);
21997
+ }
21998
+
21999
+ return new RequestConstructor(method, url);
22000
+ }
22001
+
21763
22002
  module.exports = request;
21764
22003
 
21765
- },{"emitter":40,"reduce":47}],50:[function(require,module,exports){
22004
+ },{}],53:[function(require,module,exports){
21766
22005
  /*!
21767
22006
  * validate.js 0.9.0
21768
22007
  *