comprodls-sdk 2.44.0 → 2.46.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.
@@ -465,7 +465,8 @@ exports.ATTEMPTS_API_URLS = {
465
465
  getUserAttemptStatsForActivity: '/org/{orgId}/user/{userId}/activities/{activityId}/attempts/stats',
466
466
  getUserAttemptForActivity: '/org/{orgId}/user/{userId}/activities/{activityId}/attempts/{attemptId}',
467
467
  getUserFirstAttemptForActivity: '/org/{orgId}/user/{userId}/activities/{activityId}/attempts/first',
468
- getUserLastAttemptForActivity: '/org/{orgId}/user/{userId}/activities/{activityId}/attempts/last'
468
+ getUserLastAttemptForActivity: '/org/{orgId}/user/{userId}/activities/{activityId}/attempts/last',
469
+ getUserActivityMeta: '/org/{orgId}/user/{userId}/activities/{activityId}/meta'
469
470
  };
470
471
 
471
472
  exports.PUB_API_URLS = {
@@ -1130,7 +1131,7 @@ validator.validators.contains = function(value, options) {
1130
1131
  }
1131
1132
  }
1132
1133
  };
1133
- },{"./errors":7,"validate.js":92}],10:[function(require,module,exports){
1134
+ },{"./errors":7,"validate.js":95}],10:[function(require,module,exports){
1134
1135
  /*************************************************************************
1135
1136
  *
1136
1137
  * COMPRO CONFIDENTIAL
@@ -3869,7 +3870,9 @@ function attempts() {
3869
3870
  getUserAttemptStatsForActivity: getUserAttemptStatsForActivity.bind(this),
3870
3871
  getUserAttemptForActivity: getUserAttemptForActivity.bind(this),
3871
3872
  getUserFirstAttemptForActivity: getUserFirstAttemptForActivity.bind(this),
3872
- getUserLastAttemptForActivity: getUserLastAttemptForActivity.bind(this)
3873
+ getUserLastAttemptForActivity: getUserLastAttemptForActivity.bind(this),
3874
+ updateUserAttemptForActivity: updateUserAttemptForActivity.bind(this),
3875
+ getUserActivityMeta: getUserActivityMeta.bind(this)
3873
3876
  };
3874
3877
  }
3875
3878
 
@@ -3938,7 +3941,8 @@ function getUserAllAttemptsForActivity(options) {
3938
3941
  "assignmentid": "string",
3939
3942
  "itemcode":"string",
3940
3943
  "productcode": "string",
3941
- "max_allowed":"string"
3944
+ "max_allowed":"string",
3945
+ "status": "string"
3942
3946
  }
3943
3947
  }
3944
3948
  */
@@ -4164,7 +4168,100 @@ function getUserLastAttemptForActivity(options) {
4164
4168
  }
4165
4169
  return dfd.promise;
4166
4170
  }
4167
-
4171
+
4172
+ /*
4173
+ options = {
4174
+ userid: 'string', //mandatory
4175
+ activityid: 'string', //mandatory
4176
+ attemptid: 'string', //mandatory
4177
+ body: { //mandatory
4178
+ status: 'string'
4179
+ }
4180
+ }
4181
+ */
4182
+ function updateUserAttemptForActivity(options) {
4183
+ var self = this;
4184
+ var dfd = q.defer();
4185
+ var err;
4186
+
4187
+ if(options && options.userid && options.activityid && options.attemptid && options.body) {
4188
+ //Passed all validations, Construct API url
4189
+ var url = self.config.DEFAULT_HOSTS.ATTEMPTS + self.config.ATTEMPTS_API_URLS.getUserAttemptForActivity;
4190
+ url = helpers.api.constructAPIUrl(url, { orgId: self.orgId, userId: options.userid, activityId: options.activityid,
4191
+ attemptId: options.attemptid });
4192
+
4193
+ var params = options.body;
4194
+ //Setup request with URL and Params
4195
+ var requestAPI = request.put(url)
4196
+ .set('Content-Type', 'application/json')
4197
+ .set('Accept', 'application/json')
4198
+ .send(params);
4199
+
4200
+ if(self.traceid) { requestAPI.set('X-Amzn-Trace-Id', self.traceid); }
4201
+
4202
+ requestAPI.end(function (err, response) {
4203
+ if (err) {
4204
+ err = new DLSError(helpers.errors.ERROR_TYPES.API_ERROR, err);
4205
+ dfd.reject(err);
4206
+ }
4207
+ else { dfd.resolve(response.body); }
4208
+ });
4209
+ }
4210
+ else {
4211
+ err = {};
4212
+ err.message = err.description = 'Mandatory params - userid or activityid or attemptid or body ' +
4213
+ 'not found in request options.';
4214
+ err = new DLSError(helpers.errors.ERROR_TYPES.SDK_ERROR, err);
4215
+ dfd.reject(err);
4216
+ }
4217
+ return dfd.promise;
4218
+ }
4219
+
4220
+ /*
4221
+ options = {
4222
+ userid: 'string', //mandatory
4223
+ activityid: 'string', //mandatory
4224
+ classid: 'string', //mandatory with assignmentid
4225
+ assignmentid: 'string'
4226
+ }
4227
+ */
4228
+ function getUserActivityMeta(options) {
4229
+ var self = this;
4230
+ var dfd = q.defer();
4231
+ var err;
4232
+
4233
+ if(options && options.userid && options.activityid) {
4234
+ //Passed all validations, Construct API url
4235
+ var url = self.config.DEFAULT_HOSTS.ATTEMPTS + self.config.ATTEMPTS_API_URLS.getUserActivityMeta;
4236
+ url = helpers.api.constructAPIUrl(url, { orgId: self.orgId, userId: options.userid, activityId: options.activityid });
4237
+
4238
+ // Contruct parameters
4239
+ var params = {};
4240
+ if(options.classid) { params.classid = options.classid; }
4241
+ if(options.assignmentid) { params.assignmentid = options.assignmentid; }
4242
+
4243
+ //Setup request with URL and Params
4244
+ var requestAPI = request.get(url).query(params);
4245
+
4246
+ if(self.traceid) { requestAPI.set('X-Amzn-Trace-Id', self.traceid); }
4247
+
4248
+ requestAPI.end(function (err, response) {
4249
+ if (err) {
4250
+ err = new DLSError(helpers.errors.ERROR_TYPES.API_ERROR, err);
4251
+ dfd.reject(err);
4252
+ }
4253
+ else { dfd.resolve(response.body); }
4254
+ });
4255
+ }
4256
+ else {
4257
+ err = {};
4258
+ err.message = err.description = 'Mandatory params - userid or activityid ' +
4259
+ 'not found in request options.';
4260
+ err = new DLSError(helpers.errors.ERROR_TYPES.SDK_ERROR, err);
4261
+ dfd.reject(err);
4262
+ }
4263
+ return dfd.promise;
4264
+ }
4168
4265
  },{"../../helpers":3,"q":58,"superagent":88}],16:[function(require,module,exports){
4169
4266
  /*************************************************************************
4170
4267
  *
@@ -11221,7 +11318,7 @@ function createStatement(options) {
11221
11318
  }*/
11222
11319
 
11223
11320
 
11224
- },{"../../helpers":3,"q":58,"tincanjs":89}],24:[function(require,module,exports){
11321
+ },{"../../helpers":3,"q":58,"tincanjs":92}],24:[function(require,module,exports){
11225
11322
  /*************************************************************************
11226
11323
  *
11227
11324
  * COMPRO CONFIDENTIAL
@@ -13394,7 +13491,8 @@ function joinInstituteSpace(options) {
13394
13491
  startdate: 'string',
13395
13492
  enddate: 'string',
13396
13493
  ...
13397
- }
13494
+ },
13495
+ ext_data: {}
13398
13496
  }]
13399
13497
  }*/
13400
13498
  function provisionSpacesToStudent(options) {
@@ -13626,6 +13724,7 @@ function shadowProvision(options) {
13626
13724
  enddate: 'string',
13627
13725
  ...
13628
13726
  },
13727
+ ext_data: {},
13629
13728
  audit: boolean
13630
13729
  }*/
13631
13730
  function entitleUserToProduct(options) {
@@ -17522,167 +17621,181 @@ module.exports = {
17522
17621
  }
17523
17622
 
17524
17623
  },{}],42:[function(require,module,exports){
17525
-
17526
- /**
17527
- * Expose `Emitter`.
17528
- */
17529
-
17530
- module.exports = Emitter;
17531
-
17532
- /**
17533
- * Initialize a new `Emitter`.
17534
- *
17535
- * @api public
17536
- */
17537
-
17538
- function Emitter(obj) {
17539
- if (obj) return mixin(obj);
17540
- };
17541
-
17542
- /**
17543
- * Mixin the emitter properties.
17544
- *
17545
- * @param {Object} obj
17546
- * @return {Object}
17547
- * @api private
17548
- */
17549
-
17550
- function mixin(obj) {
17551
- for (var key in Emitter.prototype) {
17552
- obj[key] = Emitter.prototype[key];
17553
- }
17554
- return obj;
17555
- }
17556
-
17557
- /**
17558
- * Listen on the given `event` with `fn`.
17559
- *
17560
- * @param {String} event
17561
- * @param {Function} fn
17562
- * @return {Emitter}
17563
- * @api public
17564
- */
17565
-
17566
- Emitter.prototype.on =
17567
- Emitter.prototype.addEventListener = function(event, fn){
17568
- this._callbacks = this._callbacks || {};
17569
- (this._callbacks['$' + event] = this._callbacks['$' + event] || [])
17570
- .push(fn);
17571
- return this;
17572
- };
17573
-
17574
- /**
17575
- * Adds an `event` listener that will be invoked a single
17576
- * time then automatically removed.
17577
- *
17578
- * @param {String} event
17579
- * @param {Function} fn
17580
- * @return {Emitter}
17581
- * @api public
17582
- */
17583
-
17584
- Emitter.prototype.once = function(event, fn){
17585
- function on() {
17586
- this.off(event, on);
17587
- fn.apply(this, arguments);
17588
- }
17589
-
17590
- on.fn = fn;
17591
- this.on(event, on);
17592
- return this;
17593
- };
17594
-
17595
- /**
17596
- * Remove the given callback for `event` or all
17597
- * registered callbacks.
17598
- *
17599
- * @param {String} event
17600
- * @param {Function} fn
17601
- * @return {Emitter}
17602
- * @api public
17603
- */
17604
-
17605
- Emitter.prototype.off =
17606
- Emitter.prototype.removeListener =
17607
- Emitter.prototype.removeAllListeners =
17608
- Emitter.prototype.removeEventListener = function(event, fn){
17609
- this._callbacks = this._callbacks || {};
17610
-
17611
- // all
17612
- if (0 == arguments.length) {
17613
- this._callbacks = {};
17614
- return this;
17615
- }
17616
-
17617
- // specific event
17618
- var callbacks = this._callbacks['$' + event];
17619
- if (!callbacks) return this;
17620
-
17621
- // remove all handlers
17622
- if (1 == arguments.length) {
17623
- delete this._callbacks['$' + event];
17624
- return this;
17625
- }
17626
-
17627
- // remove specific handler
17628
- var cb;
17629
- for (var i = 0; i < callbacks.length; i++) {
17630
- cb = callbacks[i];
17631
- if (cb === fn || cb.fn === fn) {
17632
- callbacks.splice(i, 1);
17633
- break;
17634
- }
17635
- }
17636
- return this;
17637
- };
17638
-
17639
- /**
17640
- * Emit `event` with the given args.
17641
- *
17642
- * @param {String} event
17643
- * @param {Mixed} ...
17644
- * @return {Emitter}
17645
- */
17646
-
17647
- Emitter.prototype.emit = function(event){
17648
- this._callbacks = this._callbacks || {};
17649
- var args = [].slice.call(arguments, 1)
17650
- , callbacks = this._callbacks['$' + event];
17651
-
17652
- if (callbacks) {
17653
- callbacks = callbacks.slice(0);
17654
- for (var i = 0, len = callbacks.length; i < len; ++i) {
17655
- callbacks[i].apply(this, args);
17656
- }
17657
- }
17658
-
17659
- return this;
17660
- };
17661
-
17662
- /**
17663
- * Return array of callbacks for `event`.
17664
- *
17665
- * @param {String} event
17666
- * @return {Array}
17667
- * @api public
17668
- */
17669
-
17670
- Emitter.prototype.listeners = function(event){
17671
- this._callbacks = this._callbacks || {};
17672
- return this._callbacks['$' + event] || [];
17673
- };
17674
-
17675
- /**
17676
- * Check if this emitter has `event` handlers.
17677
- *
17678
- * @param {String} event
17679
- * @return {Boolean}
17680
- * @api public
17681
- */
17682
-
17683
- Emitter.prototype.hasListeners = function(event){
17684
- return !! this.listeners(event).length;
17685
- };
17624
+
17625
+ /**
17626
+ * Expose `Emitter`.
17627
+ */
17628
+
17629
+ if (typeof module !== 'undefined') {
17630
+ module.exports = Emitter;
17631
+ }
17632
+
17633
+ /**
17634
+ * Initialize a new `Emitter`.
17635
+ *
17636
+ * @api public
17637
+ */
17638
+
17639
+ function Emitter(obj) {
17640
+ if (obj) return mixin(obj);
17641
+ };
17642
+
17643
+ /**
17644
+ * Mixin the emitter properties.
17645
+ *
17646
+ * @param {Object} obj
17647
+ * @return {Object}
17648
+ * @api private
17649
+ */
17650
+
17651
+ function mixin(obj) {
17652
+ for (var key in Emitter.prototype) {
17653
+ obj[key] = Emitter.prototype[key];
17654
+ }
17655
+ return obj;
17656
+ }
17657
+
17658
+ /**
17659
+ * Listen on the given `event` with `fn`.
17660
+ *
17661
+ * @param {String} event
17662
+ * @param {Function} fn
17663
+ * @return {Emitter}
17664
+ * @api public
17665
+ */
17666
+
17667
+ Emitter.prototype.on =
17668
+ Emitter.prototype.addEventListener = function(event, fn){
17669
+ this._callbacks = this._callbacks || {};
17670
+ (this._callbacks['$' + event] = this._callbacks['$' + event] || [])
17671
+ .push(fn);
17672
+ return this;
17673
+ };
17674
+
17675
+ /**
17676
+ * Adds an `event` listener that will be invoked a single
17677
+ * time then automatically removed.
17678
+ *
17679
+ * @param {String} event
17680
+ * @param {Function} fn
17681
+ * @return {Emitter}
17682
+ * @api public
17683
+ */
17684
+
17685
+ Emitter.prototype.once = function(event, fn){
17686
+ function on() {
17687
+ this.off(event, on);
17688
+ fn.apply(this, arguments);
17689
+ }
17690
+
17691
+ on.fn = fn;
17692
+ this.on(event, on);
17693
+ return this;
17694
+ };
17695
+
17696
+ /**
17697
+ * Remove the given callback for `event` or all
17698
+ * registered callbacks.
17699
+ *
17700
+ * @param {String} event
17701
+ * @param {Function} fn
17702
+ * @return {Emitter}
17703
+ * @api public
17704
+ */
17705
+
17706
+ Emitter.prototype.off =
17707
+ Emitter.prototype.removeListener =
17708
+ Emitter.prototype.removeAllListeners =
17709
+ Emitter.prototype.removeEventListener = function(event, fn){
17710
+ this._callbacks = this._callbacks || {};
17711
+
17712
+ // all
17713
+ if (0 == arguments.length) {
17714
+ this._callbacks = {};
17715
+ return this;
17716
+ }
17717
+
17718
+ // specific event
17719
+ var callbacks = this._callbacks['$' + event];
17720
+ if (!callbacks) return this;
17721
+
17722
+ // remove all handlers
17723
+ if (1 == arguments.length) {
17724
+ delete this._callbacks['$' + event];
17725
+ return this;
17726
+ }
17727
+
17728
+ // remove specific handler
17729
+ var cb;
17730
+ for (var i = 0; i < callbacks.length; i++) {
17731
+ cb = callbacks[i];
17732
+ if (cb === fn || cb.fn === fn) {
17733
+ callbacks.splice(i, 1);
17734
+ break;
17735
+ }
17736
+ }
17737
+
17738
+ // Remove event specific arrays for event types that no
17739
+ // one is subscribed for to avoid memory leak.
17740
+ if (callbacks.length === 0) {
17741
+ delete this._callbacks['$' + event];
17742
+ }
17743
+
17744
+ return this;
17745
+ };
17746
+
17747
+ /**
17748
+ * Emit `event` with the given args.
17749
+ *
17750
+ * @param {String} event
17751
+ * @param {Mixed} ...
17752
+ * @return {Emitter}
17753
+ */
17754
+
17755
+ Emitter.prototype.emit = function(event){
17756
+ this._callbacks = this._callbacks || {};
17757
+
17758
+ var args = new Array(arguments.length - 1)
17759
+ , callbacks = this._callbacks['$' + event];
17760
+
17761
+ for (var i = 1; i < arguments.length; i++) {
17762
+ args[i - 1] = arguments[i];
17763
+ }
17764
+
17765
+ if (callbacks) {
17766
+ callbacks = callbacks.slice(0);
17767
+ for (var i = 0, len = callbacks.length; i < len; ++i) {
17768
+ callbacks[i].apply(this, args);
17769
+ }
17770
+ }
17771
+
17772
+ return this;
17773
+ };
17774
+
17775
+ /**
17776
+ * Return array of callbacks for `event`.
17777
+ *
17778
+ * @param {String} event
17779
+ * @return {Array}
17780
+ * @api public
17781
+ */
17782
+
17783
+ Emitter.prototype.listeners = function(event){
17784
+ this._callbacks = this._callbacks || {};
17785
+ return this._callbacks['$' + event] || [];
17786
+ };
17787
+
17788
+ /**
17789
+ * Check if this emitter has `event` handlers.
17790
+ *
17791
+ * @param {String} event
17792
+ * @return {Boolean}
17793
+ * @api public
17794
+ */
17795
+
17796
+ Emitter.prototype.hasListeners = function(event){
17797
+ return !! this.listeners(event).length;
17798
+ };
17686
17799
 
17687
17800
  },{}],43:[function(require,module,exports){
17688
17801
  // Copyright Joyent, Inc. and other Node contributors.
@@ -18097,6 +18210,8 @@ function isUndefined(arg) {
18097
18210
  }
18098
18211
 
18099
18212
  },{}],45:[function(require,module,exports){
18213
+ 'use strict';
18214
+
18100
18215
  var hasOwn = Object.prototype.hasOwnProperty;
18101
18216
  var toStr = Object.prototype.toString;
18102
18217
  var defineProperty = Object.defineProperty;
@@ -18111,8 +18226,6 @@ var isArray = function isArray(arr) {
18111
18226
  };
18112
18227
 
18113
18228
  var isPlainObject = function isPlainObject(obj) {
18114
- 'use strict';
18115
-
18116
18229
  if (!obj || toStr.call(obj) !== '[object Object]') {
18117
18230
  return false;
18118
18231
  }
@@ -18162,8 +18275,6 @@ var getProperty = function getProperty(obj, name) {
18162
18275
  };
18163
18276
 
18164
18277
  module.exports = function extend() {
18165
- 'use strict';
18166
-
18167
18278
  var options, name, src, copy, copyIsArray, clone;
18168
18279
  var target = arguments[0];
18169
18280
  var i = 1;
@@ -23711,7 +23822,7 @@ Writable.prototype._destroy = function (err, cb) {
23711
23822
  cb(err);
23712
23823
  };
23713
23824
  }).call(this,require('_process'),typeof global !== "undefined" ? global : typeof self !== "undefined" ? self : typeof window !== "undefined" ? window : {})
23714
- },{"./_stream_duplex":63,"./internal/streams/destroy":69,"./internal/streams/stream":70,"_process":55,"core-util-is":43,"inherits":71,"process-nextick-args":54,"safe-buffer":73,"util-deprecate":91}],68:[function(require,module,exports){
23825
+ },{"./_stream_duplex":63,"./internal/streams/destroy":69,"./internal/streams/stream":70,"_process":55,"core-util-is":43,"inherits":71,"process-nextick-args":54,"safe-buffer":73,"util-deprecate":94}],68:[function(require,module,exports){
23715
23826
  'use strict';
23716
23827
 
23717
23828
  function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
@@ -24519,7 +24630,7 @@ http.METHODS = [
24519
24630
  'UNLOCK',
24520
24631
  'UNSUBSCRIBE'
24521
24632
  ]
24522
- },{"./lib/request":84,"builtin-status-codes":41,"url":90,"xtend":94}],83:[function(require,module,exports){
24633
+ },{"./lib/request":84,"builtin-status-codes":41,"url":93,"xtend":97}],83:[function(require,module,exports){
24523
24634
  (function (global){
24524
24635
  exports.fetch = isFunction(global.fetch) && isFunction(global.ReadableByteStream)
24525
24636
 
@@ -25069,6 +25180,8 @@ function template(string) {
25069
25180
 
25070
25181
  var Emitter = require('emitter');
25071
25182
  var reduce = require('reduce');
25183
+ var requestBase = require('./request-base');
25184
+ var isObject = require('./is-object');
25072
25185
 
25073
25186
  /**
25074
25187
  * Root reference for iframes.
@@ -25090,28 +25203,10 @@ if (typeof window !== 'undefined') { // Browser window
25090
25203
  function noop(){};
25091
25204
 
25092
25205
  /**
25093
- * Check if `obj` is a host object,
25094
- * we don't want to serialize these :)
25095
- *
25096
- * TODO: future proof, move to compoent land
25097
- *
25098
- * @param {Object} obj
25099
- * @return {Boolean}
25100
- * @api private
25206
+ * Expose `request`.
25101
25207
  */
25102
25208
 
25103
- function isHost(obj) {
25104
- var str = {}.toString.call(obj);
25105
-
25106
- switch (str) {
25107
- case '[object File]':
25108
- case '[object Blob]':
25109
- case '[object FormData]':
25110
- return true;
25111
- default:
25112
- return false;
25113
- }
25114
- }
25209
+ var request = module.exports = require('./request').bind(null, Request);
25115
25210
 
25116
25211
  /**
25117
25212
  * Determine XHR.
@@ -25143,18 +25238,6 @@ var trim = ''.trim
25143
25238
  ? function(s) { return s.trim(); }
25144
25239
  : function(s) { return s.replace(/(^\s*|\s*$)/g, ''); };
25145
25240
 
25146
- /**
25147
- * Check if `obj` is an object.
25148
- *
25149
- * @param {Object} obj
25150
- * @return {Boolean}
25151
- * @api private
25152
- */
25153
-
25154
- function isObject(obj) {
25155
- return obj === Object(obj);
25156
- }
25157
-
25158
25241
  /**
25159
25242
  * Serialize the given `obj`.
25160
25243
  *
@@ -25169,8 +25252,8 @@ function serialize(obj) {
25169
25252
  for (var key in obj) {
25170
25253
  if (null != obj[key]) {
25171
25254
  pushEncodedKeyValuePair(pairs, key, obj[key]);
25172
- }
25173
- }
25255
+ }
25256
+ }
25174
25257
  return pairs.join('&');
25175
25258
  }
25176
25259
 
@@ -25188,6 +25271,11 @@ function pushEncodedKeyValuePair(pairs, key, val) {
25188
25271
  return val.forEach(function(v) {
25189
25272
  pushEncodedKeyValuePair(pairs, key, v);
25190
25273
  });
25274
+ } else if (isObject(val)) {
25275
+ for(var subkey in val) {
25276
+ pushEncodedKeyValuePair(pairs, key + '[' + subkey + ']', val[subkey]);
25277
+ }
25278
+ return;
25191
25279
  }
25192
25280
  pairs.push(encodeURIComponent(key)
25193
25281
  + '=' + encodeURIComponent(val));
@@ -25210,13 +25298,18 @@ function pushEncodedKeyValuePair(pairs, key, val) {
25210
25298
  function parseString(str) {
25211
25299
  var obj = {};
25212
25300
  var pairs = str.split('&');
25213
- var parts;
25214
25301
  var pair;
25302
+ var pos;
25215
25303
 
25216
25304
  for (var i = 0, len = pairs.length; i < len; ++i) {
25217
25305
  pair = pairs[i];
25218
- parts = pair.split('=');
25219
- obj[decodeURIComponent(parts[0])] = decodeURIComponent(parts[1]);
25306
+ pos = pair.indexOf('=');
25307
+ if (pos == -1) {
25308
+ obj[decodeURIComponent(pair)] = '';
25309
+ } else {
25310
+ obj[decodeURIComponent(pair.slice(0, pos))] =
25311
+ decodeURIComponent(pair.slice(pos + 1));
25312
+ }
25220
25313
  }
25221
25314
 
25222
25315
  return obj;
@@ -25400,15 +25493,15 @@ function Response(req, options) {
25400
25493
  ? this.xhr.responseText
25401
25494
  : null;
25402
25495
  this.statusText = this.req.xhr.statusText;
25403
- this.setStatusProperties(this.xhr.status);
25496
+ this._setStatusProperties(this.xhr.status);
25404
25497
  this.header = this.headers = parseHeader(this.xhr.getAllResponseHeaders());
25405
25498
  // getAllResponseHeaders sometimes falsely returns "" for CORS requests, but
25406
25499
  // getResponseHeader still works. so we get content-type even if getting
25407
25500
  // other headers fails.
25408
25501
  this.header['content-type'] = this.xhr.getResponseHeader('content-type');
25409
- this.setHeaderProperties(this.header);
25502
+ this._setHeaderProperties(this.header);
25410
25503
  this.body = this.req.method != 'HEAD'
25411
- ? this.parseBody(this.text ? this.text : this.xhr.response)
25504
+ ? this._parseBody(this.text ? this.text : this.xhr.response)
25412
25505
  : null;
25413
25506
  }
25414
25507
 
@@ -25436,7 +25529,7 @@ Response.prototype.get = function(field){
25436
25529
  * @api private
25437
25530
  */
25438
25531
 
25439
- Response.prototype.setHeaderProperties = function(header){
25532
+ Response.prototype._setHeaderProperties = function(header){
25440
25533
  // content-type
25441
25534
  var ct = this.header['content-type'] || '';
25442
25535
  this.type = type(ct);
@@ -25457,8 +25550,11 @@ Response.prototype.setHeaderProperties = function(header){
25457
25550
  * @api private
25458
25551
  */
25459
25552
 
25460
- Response.prototype.parseBody = function(str){
25553
+ Response.prototype._parseBody = function(str){
25461
25554
  var parse = request.parse[this.type];
25555
+ if (!parse && isJSON(this.type)) {
25556
+ parse = request.parse['application/json'];
25557
+ }
25462
25558
  return parse && str && (str.length || str instanceof Object)
25463
25559
  ? parse(str)
25464
25560
  : null;
@@ -25485,7 +25581,7 @@ Response.prototype.parseBody = function(str){
25485
25581
  * @api private
25486
25582
  */
25487
25583
 
25488
- Response.prototype.setStatusProperties = function(status){
25584
+ Response.prototype._setStatusProperties = function(status){
25489
25585
  // handle IE9 bug: http://stackoverflow.com/questions/10046972/msie-returns-status-code-of-1223-for-ajax-request
25490
25586
  if (status === 1223) {
25491
25587
  status = 204;
@@ -25553,12 +25649,11 @@ request.Response = Response;
25553
25649
 
25554
25650
  function Request(method, url) {
25555
25651
  var self = this;
25556
- Emitter.call(this);
25557
25652
  this._query = this._query || [];
25558
25653
  this.method = method;
25559
25654
  this.url = url;
25560
- this.header = {};
25561
- this._header = {};
25655
+ this.header = {}; // preserves header name case
25656
+ this._header = {}; // coerces header names to lowercase
25562
25657
  this.on('end', function(){
25563
25658
  var err = null;
25564
25659
  var res = null;
@@ -25571,6 +25666,8 @@ function Request(method, url) {
25571
25666
  err.original = e;
25572
25667
  // issue #675: return the raw response if the response parsing fails
25573
25668
  err.rawResponse = self.xhr && self.xhr.responseText ? self.xhr.responseText : null;
25669
+ // issue #876: return the http status code if the response parsing fails
25670
+ err.statusCode = self.xhr && self.xhr.status ? self.xhr.status : null;
25574
25671
  return self.callback(err);
25575
25672
  }
25576
25673
 
@@ -25580,140 +25677,32 @@ function Request(method, url) {
25580
25677
  return self.callback(err, res);
25581
25678
  }
25582
25679
 
25583
- if (res.status >= 200 && res.status < 300) {
25584
- return self.callback(err, res);
25585
- }
25680
+ try {
25681
+ if (res.status >= 200 && res.status < 300) {
25682
+ return self.callback(err, res);
25683
+ }
25586
25684
 
25587
- var new_err = new Error(res.statusText || 'Unsuccessful HTTP response');
25588
- new_err.original = err;
25589
- new_err.response = res;
25590
- new_err.status = res.status;
25685
+ var new_err = new Error(res.statusText || 'Unsuccessful HTTP response');
25686
+ new_err.original = err;
25687
+ new_err.response = res;
25688
+ new_err.status = res.status;
25591
25689
 
25592
- self.callback(new_err, res);
25690
+ self.callback(new_err, res);
25691
+ } catch(e) {
25692
+ self.callback(e); // #985 touching res may cause INVALID_STATE_ERR on old Android
25693
+ }
25593
25694
  });
25594
25695
  }
25595
25696
 
25596
25697
  /**
25597
- * Mixin `Emitter`.
25698
+ * Mixin `Emitter` and `requestBase`.
25598
25699
  */
25599
25700
 
25600
25701
  Emitter(Request.prototype);
25601
-
25602
- /**
25603
- * Allow for extension
25604
- */
25605
-
25606
- Request.prototype.use = function(fn) {
25607
- fn(this);
25608
- return this;
25702
+ for (var key in requestBase) {
25703
+ Request.prototype[key] = requestBase[key];
25609
25704
  }
25610
25705
 
25611
- /**
25612
- * Set timeout to `ms`.
25613
- *
25614
- * @param {Number} ms
25615
- * @return {Request} for chaining
25616
- * @api public
25617
- */
25618
-
25619
- Request.prototype.timeout = function(ms){
25620
- this._timeout = ms;
25621
- return this;
25622
- };
25623
-
25624
- /**
25625
- * Clear previous timeout.
25626
- *
25627
- * @return {Request} for chaining
25628
- * @api public
25629
- */
25630
-
25631
- Request.prototype.clearTimeout = function(){
25632
- this._timeout = 0;
25633
- clearTimeout(this._timer);
25634
- return this;
25635
- };
25636
-
25637
- /**
25638
- * Abort the request, and clear potential timeout.
25639
- *
25640
- * @return {Request}
25641
- * @api public
25642
- */
25643
-
25644
- Request.prototype.abort = function(){
25645
- if (this.aborted) return;
25646
- this.aborted = true;
25647
- this.xhr.abort();
25648
- this.clearTimeout();
25649
- this.emit('abort');
25650
- return this;
25651
- };
25652
-
25653
- /**
25654
- * Set header `field` to `val`, or multiple fields with one object.
25655
- *
25656
- * Examples:
25657
- *
25658
- * req.get('/')
25659
- * .set('Accept', 'application/json')
25660
- * .set('X-API-Key', 'foobar')
25661
- * .end(callback);
25662
- *
25663
- * req.get('/')
25664
- * .set({ Accept: 'application/json', 'X-API-Key': 'foobar' })
25665
- * .end(callback);
25666
- *
25667
- * @param {String|Object} field
25668
- * @param {String} val
25669
- * @return {Request} for chaining
25670
- * @api public
25671
- */
25672
-
25673
- Request.prototype.set = function(field, val){
25674
- if (isObject(field)) {
25675
- for (var key in field) {
25676
- this.set(key, field[key]);
25677
- }
25678
- return this;
25679
- }
25680
- this._header[field.toLowerCase()] = val;
25681
- this.header[field] = val;
25682
- return this;
25683
- };
25684
-
25685
- /**
25686
- * Remove header `field`.
25687
- *
25688
- * Example:
25689
- *
25690
- * req.get('/')
25691
- * .unset('User-Agent')
25692
- * .end(callback);
25693
- *
25694
- * @param {String} field
25695
- * @return {Request} for chaining
25696
- * @api public
25697
- */
25698
-
25699
- Request.prototype.unset = function(field){
25700
- delete this._header[field.toLowerCase()];
25701
- delete this.header[field];
25702
- return this;
25703
- };
25704
-
25705
- /**
25706
- * Get case-insensitive header `field` value.
25707
- *
25708
- * @param {String} field
25709
- * @return {String}
25710
- * @api private
25711
- */
25712
-
25713
- Request.prototype.getHeader = function(field){
25714
- return this._header[field.toLowerCase()];
25715
- };
25716
-
25717
25706
  /**
25718
25707
  * Set Content-Type to `type`, mapping values from `request.types`.
25719
25708
  *
@@ -25742,16 +25731,22 @@ Request.prototype.type = function(type){
25742
25731
  };
25743
25732
 
25744
25733
  /**
25745
- * Force given parser
25734
+ * Set responseType to `val`. Presently valid responseTypes are 'blob' and
25735
+ * 'arraybuffer'.
25746
25736
  *
25747
- * Sets the body parser no matter type.
25737
+ * Examples:
25748
25738
  *
25749
- * @param {Function}
25739
+ * req.get('/')
25740
+ * .responseType('blob')
25741
+ * .end(callback);
25742
+ *
25743
+ * @param {String} val
25744
+ * @return {Request} for chaining
25750
25745
  * @api public
25751
25746
  */
25752
25747
 
25753
- Request.prototype.parse = function(fn){
25754
- this._parser = fn;
25748
+ Request.prototype.responseType = function(val){
25749
+ this._responseType = val;
25755
25750
  return this;
25756
25751
  };
25757
25752
 
@@ -25785,13 +25780,29 @@ Request.prototype.accept = function(type){
25785
25780
  *
25786
25781
  * @param {String} user
25787
25782
  * @param {String} pass
25783
+ * @param {Object} options with 'type' property 'auto' or 'basic' (default 'basic')
25788
25784
  * @return {Request} for chaining
25789
25785
  * @api public
25790
25786
  */
25791
25787
 
25792
- Request.prototype.auth = function(user, pass){
25793
- var str = btoa(user + ':' + pass);
25794
- this.set('Authorization', 'Basic ' + str);
25788
+ Request.prototype.auth = function(user, pass, options){
25789
+ if (!options) {
25790
+ options = {
25791
+ type: 'basic'
25792
+ }
25793
+ }
25794
+
25795
+ switch (options.type) {
25796
+ case 'basic':
25797
+ var str = btoa(user + ':' + pass);
25798
+ this.set('Authorization', 'Basic ' + str);
25799
+ break;
25800
+
25801
+ case 'auto':
25802
+ this.username = user;
25803
+ this.password = pass;
25804
+ break;
25805
+ }
25795
25806
  return this;
25796
25807
  };
25797
25808
 
@@ -25815,35 +25826,13 @@ Request.prototype.query = function(val){
25815
25826
  return this;
25816
25827
  };
25817
25828
 
25818
- /**
25819
- * Write the field `name` and `val` for "multipart/form-data"
25820
- * request bodies.
25821
- *
25822
- * ``` js
25823
- * request.post('/upload')
25824
- * .field('foo', 'bar')
25825
- * .end(callback);
25826
- * ```
25827
- *
25828
- * @param {String} name
25829
- * @param {String|Blob|File} val
25830
- * @return {Request} for chaining
25831
- * @api public
25832
- */
25833
-
25834
- Request.prototype.field = function(name, val){
25835
- if (!this._formData) this._formData = new root.FormData();
25836
- this._formData.append(name, val);
25837
- return this;
25838
- };
25839
-
25840
25829
  /**
25841
25830
  * Queue the given `file` as an attachment to the specified `field`,
25842
25831
  * with optional `filename`.
25843
25832
  *
25844
25833
  * ``` js
25845
25834
  * request.post('/upload')
25846
- * .attach(new Blob(['<a id="a"><b id="b">hey!</b></a>'], { type: "text/html"}))
25835
+ * .attach('content', new Blob(['<a id="a"><b id="b">hey!</b></a>'], { type: "text/html"}))
25847
25836
  * .end(callback);
25848
25837
  * ```
25849
25838
  *
@@ -25855,77 +25844,15 @@ Request.prototype.field = function(name, val){
25855
25844
  */
25856
25845
 
25857
25846
  Request.prototype.attach = function(field, file, filename){
25858
- if (!this._formData) this._formData = new root.FormData();
25859
- this._formData.append(field, file, filename || file.name);
25847
+ this._getFormData().append(field, file, filename || file.name);
25860
25848
  return this;
25861
25849
  };
25862
25850
 
25863
- /**
25864
- * Send `data` as the request body, defaulting the `.type()` to "json" when
25865
- * an object is given.
25866
- *
25867
- * Examples:
25868
- *
25869
- * // manual json
25870
- * request.post('/user')
25871
- * .type('json')
25872
- * .send('{"name":"tj"}')
25873
- * .end(callback)
25874
- *
25875
- * // auto json
25876
- * request.post('/user')
25877
- * .send({ name: 'tj' })
25878
- * .end(callback)
25879
- *
25880
- * // manual x-www-form-urlencoded
25881
- * request.post('/user')
25882
- * .type('form')
25883
- * .send('name=tj')
25884
- * .end(callback)
25885
- *
25886
- * // auto x-www-form-urlencoded
25887
- * request.post('/user')
25888
- * .type('form')
25889
- * .send({ name: 'tj' })
25890
- * .end(callback)
25891
- *
25892
- * // defaults to x-www-form-urlencoded
25893
- * request.post('/user')
25894
- * .send('name=tobi')
25895
- * .send('species=ferret')
25896
- * .end(callback)
25897
- *
25898
- * @param {String|Object} data
25899
- * @return {Request} for chaining
25900
- * @api public
25901
- */
25902
-
25903
- Request.prototype.send = function(data){
25904
- var obj = isObject(data);
25905
- var type = this.getHeader('Content-Type');
25906
-
25907
- // merge
25908
- if (obj && isObject(this._data)) {
25909
- for (var key in data) {
25910
- this._data[key] = data[key];
25911
- }
25912
- } else if ('string' == typeof data) {
25913
- if (!type) this.type('form');
25914
- type = this.getHeader('Content-Type');
25915
- if ('application/x-www-form-urlencoded' == type) {
25916
- this._data = this._data
25917
- ? this._data + '&' + data
25918
- : data;
25919
- } else {
25920
- this._data = (this._data || '') + data;
25921
- }
25922
- } else {
25923
- this._data = data;
25851
+ Request.prototype._getFormData = function(){
25852
+ if (!this._formData) {
25853
+ this._formData = new root.FormData();
25924
25854
  }
25925
-
25926
- if (!obj || isHost(data)) return this;
25927
- if (!type) this.type('json');
25928
- return this;
25855
+ return this._formData;
25929
25856
  };
25930
25857
 
25931
25858
  /**
@@ -25966,7 +25893,7 @@ Request.prototype.crossDomainError = function(){
25966
25893
  * @api private
25967
25894
  */
25968
25895
 
25969
- Request.prototype.timeoutError = function(){
25896
+ Request.prototype._timeoutError = function(){
25970
25897
  var timeout = this._timeout;
25971
25898
  var err = new Error('timeout of ' + timeout + 'ms exceeded');
25972
25899
  err.timeout = timeout;
@@ -25974,19 +25901,18 @@ Request.prototype.timeoutError = function(){
25974
25901
  };
25975
25902
 
25976
25903
  /**
25977
- * Enable transmission of cookies with x-domain requests.
25978
- *
25979
- * Note that for this to work the origin must not be
25980
- * using "Access-Control-Allow-Origin" with a wildcard,
25981
- * and also must set "Access-Control-Allow-Credentials"
25982
- * to "true".
25904
+ * Compose querystring to append to req.url
25983
25905
  *
25984
- * @api public
25906
+ * @api private
25985
25907
  */
25986
25908
 
25987
- Request.prototype.withCredentials = function(){
25988
- this._withCredentials = true;
25989
- return this;
25909
+ Request.prototype._appendQueryString = function(){
25910
+ var query = this._query.join('&');
25911
+ if (query) {
25912
+ this.url += ~this.url.indexOf('?')
25913
+ ? '&' + query
25914
+ : '?' + query;
25915
+ }
25990
25916
  };
25991
25917
 
25992
25918
  /**
@@ -26001,7 +25927,6 @@ Request.prototype.withCredentials = function(){
26001
25927
  Request.prototype.end = function(fn){
26002
25928
  var self = this;
26003
25929
  var xhr = this.xhr = request.getXHR();
26004
- var query = this._query.join('&');
26005
25930
  var timeout = this._timeout;
26006
25931
  var data = this._formData || this._data;
26007
25932
 
@@ -26018,8 +25943,8 @@ Request.prototype.end = function(fn){
26018
25943
  try { status = xhr.status } catch(e) { status = 0; }
26019
25944
 
26020
25945
  if (0 == status) {
26021
- if (self.timedout) return self.timeoutError();
26022
- if (self.aborted) return;
25946
+ if (self.timedout) return self._timeoutError();
25947
+ if (self._aborted) return;
26023
25948
  return self.crossDomainError();
26024
25949
  }
26025
25950
  self.emit('end');
@@ -26055,24 +25980,23 @@ Request.prototype.end = function(fn){
26055
25980
  }
26056
25981
 
26057
25982
  // querystring
26058
- if (query) {
26059
- query = request.serializeObject(query);
26060
- this.url += ~this.url.indexOf('?')
26061
- ? '&' + query
26062
- : '?' + query;
26063
- }
25983
+ this._appendQueryString();
26064
25984
 
26065
25985
  // initiate request
26066
- xhr.open(this.method, this.url, true);
25986
+ if (this.username && this.password) {
25987
+ xhr.open(this.method, this.url, true, this.username, this.password);
25988
+ } else {
25989
+ xhr.open(this.method, this.url, true);
25990
+ }
26067
25991
 
26068
25992
  // CORS
26069
25993
  if (this._withCredentials) xhr.withCredentials = true;
26070
25994
 
26071
25995
  // body
26072
- if ('GET' != this.method && 'HEAD' != this.method && 'string' != typeof data && !isHost(data)) {
25996
+ if ('GET' != this.method && 'HEAD' != this.method && 'string' != typeof data && !this._isHost(data)) {
26073
25997
  // serialize stuff
26074
- var contentType = this.getHeader('Content-Type');
26075
- var serialize = this._parser || request.serialize[contentType ? contentType.split(';')[0] : ''];
25998
+ var contentType = this._header['content-type'];
25999
+ var serialize = this._serializer || request.serialize[contentType ? contentType.split(';')[0] : ''];
26076
26000
  if (!serialize && isJSON(contentType)) serialize = request.serialize['application/json'];
26077
26001
  if (serialize) data = serialize(data);
26078
26002
  }
@@ -26083,6 +26007,10 @@ Request.prototype.end = function(fn){
26083
26007
  xhr.setRequestHeader(field, this.header[field]);
26084
26008
  }
26085
26009
 
26010
+ if (this._responseType) {
26011
+ xhr.responseType = this._responseType;
26012
+ }
26013
+
26086
26014
  // send stuff
26087
26015
  this.emit('request', this);
26088
26016
 
@@ -26092,19 +26020,6 @@ Request.prototype.end = function(fn){
26092
26020
  return this;
26093
26021
  };
26094
26022
 
26095
- /**
26096
- * Faux promise support
26097
- *
26098
- * @param {Function} fulfill
26099
- * @param {Function} reject
26100
- * @return {Request}
26101
- */
26102
-
26103
- Request.prototype.then = function (fulfill, reject) {
26104
- return this.end(function(err, res) {
26105
- err ? reject(err) : fulfill(res);
26106
- });
26107
- }
26108
26023
 
26109
26024
  /**
26110
26025
  * Expose `Request`.
@@ -26112,35 +26027,6 @@ Request.prototype.then = function (fulfill, reject) {
26112
26027
 
26113
26028
  request.Request = Request;
26114
26029
 
26115
- /**
26116
- * Issue a request:
26117
- *
26118
- * Examples:
26119
- *
26120
- * request('GET', '/users').end(callback)
26121
- * request('/users').end(callback)
26122
- * request('/users', callback)
26123
- *
26124
- * @param {String} method
26125
- * @param {String|Function} url or callback
26126
- * @return {Request}
26127
- * @api public
26128
- */
26129
-
26130
- function request(method, url) {
26131
- // callback
26132
- if ('function' == typeof url) {
26133
- return new Request('GET', method).end(url);
26134
- }
26135
-
26136
- // url first
26137
- if (1 == arguments.length) {
26138
- return new Request('GET', method);
26139
- }
26140
-
26141
- return new Request(method, url);
26142
- }
26143
-
26144
26030
  /**
26145
26031
  * GET `url` with optional callback `fn(res)`.
26146
26032
  *
@@ -26177,6 +26063,24 @@ request.head = function(url, data, fn){
26177
26063
  return req;
26178
26064
  };
26179
26065
 
26066
+ /**
26067
+ * OPTIONS query to `url` with optional callback `fn(res)`.
26068
+ *
26069
+ * @param {String} url
26070
+ * @param {Mixed|Function} data or fn
26071
+ * @param {Function} fn
26072
+ * @return {Request}
26073
+ * @api public
26074
+ */
26075
+
26076
+ request.options = function(url, data, fn){
26077
+ var req = request('OPTIONS', url);
26078
+ if ('function' == typeof data) fn = data, data = null;
26079
+ if (data) req.send(data);
26080
+ if (fn) req.end(fn);
26081
+ return req;
26082
+ };
26083
+
26180
26084
  /**
26181
26085
  * DELETE `url` with optional callback `fn(res)`.
26182
26086
  *
@@ -26249,13 +26153,404 @@ request.put = function(url, data, fn){
26249
26153
  return req;
26250
26154
  };
26251
26155
 
26156
+ },{"./is-object":89,"./request":91,"./request-base":90,"emitter":42,"reduce":79}],89:[function(require,module,exports){
26252
26157
  /**
26253
- * Expose `request`.
26158
+ * Check if `obj` is an object.
26159
+ *
26160
+ * @param {Object} obj
26161
+ * @return {Boolean}
26162
+ * @api private
26163
+ */
26164
+
26165
+ function isObject(obj) {
26166
+ return null !== obj && 'object' === typeof obj;
26167
+ }
26168
+
26169
+ module.exports = isObject;
26170
+
26171
+ },{}],90:[function(require,module,exports){
26172
+ /**
26173
+ * Module of mixed-in functions shared between node and client code
26174
+ */
26175
+ var isObject = require('./is-object');
26176
+
26177
+ /**
26178
+ * Clear previous timeout.
26179
+ *
26180
+ * @return {Request} for chaining
26181
+ * @api public
26182
+ */
26183
+
26184
+ exports.clearTimeout = function _clearTimeout(){
26185
+ this._timeout = 0;
26186
+ clearTimeout(this._timer);
26187
+ return this;
26188
+ };
26189
+
26190
+ /**
26191
+ * Override default response body parser
26192
+ *
26193
+ * This function will be called to convert incoming data into request.body
26194
+ *
26195
+ * @param {Function}
26196
+ * @api public
26197
+ */
26198
+
26199
+ exports.parse = function parse(fn){
26200
+ this._parser = fn;
26201
+ return this;
26202
+ };
26203
+
26204
+ /**
26205
+ * Override default request body serializer
26206
+ *
26207
+ * This function will be called to convert data set via .send or .attach into payload to send
26208
+ *
26209
+ * @param {Function}
26210
+ * @api public
26211
+ */
26212
+
26213
+ exports.serialize = function serialize(fn){
26214
+ this._serializer = fn;
26215
+ return this;
26216
+ };
26217
+
26218
+ /**
26219
+ * Set timeout to `ms`.
26220
+ *
26221
+ * @param {Number} ms
26222
+ * @return {Request} for chaining
26223
+ * @api public
26224
+ */
26225
+
26226
+ exports.timeout = function timeout(ms){
26227
+ this._timeout = ms;
26228
+ return this;
26229
+ };
26230
+
26231
+ /**
26232
+ * Promise support
26233
+ *
26234
+ * @param {Function} resolve
26235
+ * @param {Function} reject
26236
+ * @return {Request}
26237
+ */
26238
+
26239
+ exports.then = function then(resolve, reject) {
26240
+ if (!this._fullfilledPromise) {
26241
+ var self = this;
26242
+ this._fullfilledPromise = new Promise(function(innerResolve, innerReject){
26243
+ self.end(function(err, res){
26244
+ if (err) innerReject(err); else innerResolve(res);
26245
+ });
26246
+ });
26247
+ }
26248
+ return this._fullfilledPromise.then(resolve, reject);
26249
+ }
26250
+
26251
+ /**
26252
+ * Allow for extension
26253
+ */
26254
+
26255
+ exports.use = function use(fn) {
26256
+ fn(this);
26257
+ return this;
26258
+ }
26259
+
26260
+
26261
+ /**
26262
+ * Get request header `field`.
26263
+ * Case-insensitive.
26264
+ *
26265
+ * @param {String} field
26266
+ * @return {String}
26267
+ * @api public
26268
+ */
26269
+
26270
+ exports.get = function(field){
26271
+ return this._header[field.toLowerCase()];
26272
+ };
26273
+
26274
+ /**
26275
+ * Get case-insensitive header `field` value.
26276
+ * This is a deprecated internal API. Use `.get(field)` instead.
26277
+ *
26278
+ * (getHeader is no longer used internally by the superagent code base)
26279
+ *
26280
+ * @param {String} field
26281
+ * @return {String}
26282
+ * @api private
26283
+ * @deprecated
26284
+ */
26285
+
26286
+ exports.getHeader = exports.get;
26287
+
26288
+ /**
26289
+ * Set header `field` to `val`, or multiple fields with one object.
26290
+ * Case-insensitive.
26291
+ *
26292
+ * Examples:
26293
+ *
26294
+ * req.get('/')
26295
+ * .set('Accept', 'application/json')
26296
+ * .set('X-API-Key', 'foobar')
26297
+ * .end(callback);
26298
+ *
26299
+ * req.get('/')
26300
+ * .set({ Accept: 'application/json', 'X-API-Key': 'foobar' })
26301
+ * .end(callback);
26302
+ *
26303
+ * @param {String|Object} field
26304
+ * @param {String} val
26305
+ * @return {Request} for chaining
26306
+ * @api public
26307
+ */
26308
+
26309
+ exports.set = function(field, val){
26310
+ if (isObject(field)) {
26311
+ for (var key in field) {
26312
+ this.set(key, field[key]);
26313
+ }
26314
+ return this;
26315
+ }
26316
+ this._header[field.toLowerCase()] = val;
26317
+ this.header[field] = val;
26318
+ return this;
26319
+ };
26320
+
26321
+ /**
26322
+ * Remove header `field`.
26323
+ * Case-insensitive.
26324
+ *
26325
+ * Example:
26326
+ *
26327
+ * req.get('/')
26328
+ * .unset('User-Agent')
26329
+ * .end(callback);
26330
+ *
26331
+ * @param {String} field
26332
+ */
26333
+ exports.unset = function(field){
26334
+ delete this._header[field.toLowerCase()];
26335
+ delete this.header[field];
26336
+ return this;
26337
+ };
26338
+
26339
+ /**
26340
+ * Write the field `name` and `val` for "multipart/form-data"
26341
+ * request bodies.
26342
+ *
26343
+ * ``` js
26344
+ * request.post('/upload')
26345
+ * .field('foo', 'bar')
26346
+ * .end(callback);
26347
+ * ```
26348
+ *
26349
+ * @param {String} name
26350
+ * @param {String|Blob|File|Buffer|fs.ReadStream} val
26351
+ * @return {Request} for chaining
26352
+ * @api public
26353
+ */
26354
+ exports.field = function(name, val) {
26355
+ this._getFormData().append(name, val);
26356
+ return this;
26357
+ };
26358
+
26359
+ /**
26360
+ * Abort the request, and clear potential timeout.
26361
+ *
26362
+ * @return {Request}
26363
+ * @api public
26364
+ */
26365
+ exports.abort = function(){
26366
+ if (this._aborted) {
26367
+ return this;
26368
+ }
26369
+ this._aborted = true;
26370
+ this.xhr && this.xhr.abort(); // browser
26371
+ this.req && this.req.abort(); // node
26372
+ this.clearTimeout();
26373
+ this.emit('abort');
26374
+ return this;
26375
+ };
26376
+
26377
+ /**
26378
+ * Enable transmission of cookies with x-domain requests.
26379
+ *
26380
+ * Note that for this to work the origin must not be
26381
+ * using "Access-Control-Allow-Origin" with a wildcard,
26382
+ * and also must set "Access-Control-Allow-Credentials"
26383
+ * to "true".
26384
+ *
26385
+ * @api public
26386
+ */
26387
+
26388
+ exports.withCredentials = function(){
26389
+ // This is browser-only functionality. Node side is no-op.
26390
+ this._withCredentials = true;
26391
+ return this;
26392
+ };
26393
+
26394
+ /**
26395
+ * Set the max redirects to `n`. Does noting in browser XHR implementation.
26396
+ *
26397
+ * @param {Number} n
26398
+ * @return {Request} for chaining
26399
+ * @api public
26400
+ */
26401
+
26402
+ exports.redirects = function(n){
26403
+ this._maxRedirects = n;
26404
+ return this;
26405
+ };
26406
+
26407
+ /**
26408
+ * Convert to a plain javascript object (not JSON string) of scalar properties.
26409
+ * Note as this method is designed to return a useful non-this value,
26410
+ * it cannot be chained.
26411
+ *
26412
+ * @return {Object} describing method, url, and data of this request
26413
+ * @api public
26414
+ */
26415
+
26416
+ exports.toJSON = function(){
26417
+ return {
26418
+ method: this.method,
26419
+ url: this.url,
26420
+ data: this._data
26421
+ };
26422
+ };
26423
+
26424
+ /**
26425
+ * Check if `obj` is a host object,
26426
+ * we don't want to serialize these :)
26427
+ *
26428
+ * TODO: future proof, move to compoent land
26429
+ *
26430
+ * @param {Object} obj
26431
+ * @return {Boolean}
26432
+ * @api private
26254
26433
  */
26255
26434
 
26435
+ exports._isHost = function _isHost(obj) {
26436
+ var str = {}.toString.call(obj);
26437
+
26438
+ switch (str) {
26439
+ case '[object File]':
26440
+ case '[object Blob]':
26441
+ case '[object FormData]':
26442
+ return true;
26443
+ default:
26444
+ return false;
26445
+ }
26446
+ }
26447
+
26448
+ /**
26449
+ * Send `data` as the request body, defaulting the `.type()` to "json" when
26450
+ * an object is given.
26451
+ *
26452
+ * Examples:
26453
+ *
26454
+ * // manual json
26455
+ * request.post('/user')
26456
+ * .type('json')
26457
+ * .send('{"name":"tj"}')
26458
+ * .end(callback)
26459
+ *
26460
+ * // auto json
26461
+ * request.post('/user')
26462
+ * .send({ name: 'tj' })
26463
+ * .end(callback)
26464
+ *
26465
+ * // manual x-www-form-urlencoded
26466
+ * request.post('/user')
26467
+ * .type('form')
26468
+ * .send('name=tj')
26469
+ * .end(callback)
26470
+ *
26471
+ * // auto x-www-form-urlencoded
26472
+ * request.post('/user')
26473
+ * .type('form')
26474
+ * .send({ name: 'tj' })
26475
+ * .end(callback)
26476
+ *
26477
+ * // defaults to x-www-form-urlencoded
26478
+ * request.post('/user')
26479
+ * .send('name=tobi')
26480
+ * .send('species=ferret')
26481
+ * .end(callback)
26482
+ *
26483
+ * @param {String|Object} data
26484
+ * @return {Request} for chaining
26485
+ * @api public
26486
+ */
26487
+
26488
+ exports.send = function(data){
26489
+ var obj = isObject(data);
26490
+ var type = this._header['content-type'];
26491
+
26492
+ // merge
26493
+ if (obj && isObject(this._data)) {
26494
+ for (var key in data) {
26495
+ this._data[key] = data[key];
26496
+ }
26497
+ } else if ('string' == typeof data) {
26498
+ // default to x-www-form-urlencoded
26499
+ if (!type) this.type('form');
26500
+ type = this._header['content-type'];
26501
+ if ('application/x-www-form-urlencoded' == type) {
26502
+ this._data = this._data
26503
+ ? this._data + '&' + data
26504
+ : data;
26505
+ } else {
26506
+ this._data = (this._data || '') + data;
26507
+ }
26508
+ } else {
26509
+ this._data = data;
26510
+ }
26511
+
26512
+ if (!obj || this._isHost(data)) return this;
26513
+
26514
+ // default to json
26515
+ if (!type) this.type('json');
26516
+ return this;
26517
+ };
26518
+
26519
+ },{"./is-object":89}],91:[function(require,module,exports){
26520
+ // The node and browser modules expose versions of this with the
26521
+ // appropriate constructor function bound as first argument
26522
+ /**
26523
+ * Issue a request:
26524
+ *
26525
+ * Examples:
26526
+ *
26527
+ * request('GET', '/users').end(callback)
26528
+ * request('/users').end(callback)
26529
+ * request('/users', callback)
26530
+ *
26531
+ * @param {String} method
26532
+ * @param {String|Function} url or callback
26533
+ * @return {Request}
26534
+ * @api public
26535
+ */
26536
+
26537
+ function request(RequestConstructor, method, url) {
26538
+ // callback
26539
+ if ('function' == typeof url) {
26540
+ return new RequestConstructor('GET', method).end(url);
26541
+ }
26542
+
26543
+ // url first
26544
+ if (2 == arguments.length) {
26545
+ return new RequestConstructor('GET', method);
26546
+ }
26547
+
26548
+ return new RequestConstructor(method, url);
26549
+ }
26550
+
26256
26551
  module.exports = request;
26257
26552
 
26258
- },{"emitter":42,"reduce":79}],89:[function(require,module,exports){
26553
+ },{}],92:[function(require,module,exports){
26259
26554
  (function (Buffer){
26260
26555
  "0.50.0";
26261
26556
  /*
@@ -34452,7 +34747,7 @@ TinCan client library
34452
34747
  }());
34453
34748
 
34454
34749
  }).call(this,require("buffer").Buffer)
34455
- },{"buffer":39,"querystring":61,"xhr2":93}],90:[function(require,module,exports){
34750
+ },{"buffer":39,"querystring":61,"xhr2":96}],93:[function(require,module,exports){
34456
34751
  // Copyright Joyent, Inc. and other Node contributors.
34457
34752
  //
34458
34753
  // Permission is hereby granted, free of charge, to any person obtaining a
@@ -35161,7 +35456,7 @@ function isNullOrUndefined(arg) {
35161
35456
  return arg == null;
35162
35457
  }
35163
35458
 
35164
- },{"punycode":57,"querystring":61}],91:[function(require,module,exports){
35459
+ },{"punycode":57,"querystring":61}],94:[function(require,module,exports){
35165
35460
  (function (global){
35166
35461
 
35167
35462
  /**
@@ -35232,7 +35527,7 @@ function config (name) {
35232
35527
  }
35233
35528
 
35234
35529
  }).call(this,typeof global !== "undefined" ? global : typeof self !== "undefined" ? self : typeof window !== "undefined" ? window : {})
35235
- },{}],92:[function(require,module,exports){
35530
+ },{}],95:[function(require,module,exports){
35236
35531
  /*!
35237
35532
  * validate.js 0.9.0
35238
35533
  *
@@ -36320,7 +36615,7 @@ function config (name) {
36320
36615
  typeof module !== 'undefined' ? /* istanbul ignore next */ module : null,
36321
36616
  typeof define !== 'undefined' ? /* istanbul ignore next */ define : null);
36322
36617
 
36323
- },{}],93:[function(require,module,exports){
36618
+ },{}],96:[function(require,module,exports){
36324
36619
  (function (process,Buffer){
36325
36620
  // Generated by CoffeeScript 1.6.3
36326
36621
  (function() {
@@ -37158,7 +37453,7 @@ function config (name) {
37158
37453
  }).call(this);
37159
37454
 
37160
37455
  }).call(this,require('_process'),require("buffer").Buffer)
37161
- },{"_process":55,"buffer":39,"http":82,"https":47,"os":53,"url":90}],94:[function(require,module,exports){
37456
+ },{"_process":55,"buffer":39,"http":82,"https":47,"os":53,"url":93}],97:[function(require,module,exports){
37162
37457
  module.exports = extend
37163
37458
 
37164
37459
  var hasOwnProperty = Object.prototype.hasOwnProperty;