comprodls-sdk 2.45.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
@@ -3870,7 +3871,8 @@ function attempts() {
3870
3871
  getUserAttemptForActivity: getUserAttemptForActivity.bind(this),
3871
3872
  getUserFirstAttemptForActivity: getUserFirstAttemptForActivity.bind(this),
3872
3873
  getUserLastAttemptForActivity: getUserLastAttemptForActivity.bind(this),
3873
- updateUserAttemptForActivity: updateUserAttemptForActivity.bind(this)
3874
+ updateUserAttemptForActivity: updateUserAttemptForActivity.bind(this),
3875
+ getUserActivityMeta: getUserActivityMeta.bind(this)
3874
3876
  };
3875
3877
  }
3876
3878
 
@@ -4214,7 +4216,52 @@ function updateUserAttemptForActivity(options) {
4214
4216
  }
4215
4217
  return dfd.promise;
4216
4218
  }
4217
-
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
+ }
4218
4265
  },{"../../helpers":3,"q":58,"superagent":88}],16:[function(require,module,exports){
4219
4266
  /*************************************************************************
4220
4267
  *
@@ -11271,7 +11318,7 @@ function createStatement(options) {
11271
11318
  }*/
11272
11319
 
11273
11320
 
11274
- },{"../../helpers":3,"q":58,"tincanjs":89}],24:[function(require,module,exports){
11321
+ },{"../../helpers":3,"q":58,"tincanjs":92}],24:[function(require,module,exports){
11275
11322
  /*************************************************************************
11276
11323
  *
11277
11324
  * COMPRO CONFIDENTIAL
@@ -17574,278 +17621,292 @@ module.exports = {
17574
17621
  }
17575
17622
 
17576
17623
  },{}],42:[function(require,module,exports){
17624
+
17625
+ /**
17626
+ * Expose `Emitter`.
17627
+ */
17628
+
17629
+ if (typeof module !== 'undefined') {
17630
+ module.exports = Emitter;
17631
+ }
17632
+
17633
+ /**
17634
+ * Initialize a new `Emitter`.
17635
+ *
17636
+ * @api public
17637
+ */
17638
+
17639
+ function Emitter(obj) {
17640
+ if (obj) return mixin(obj);
17641
+ };
17642
+
17643
+ /**
17644
+ * Mixin the emitter properties.
17645
+ *
17646
+ * @param {Object} obj
17647
+ * @return {Object}
17648
+ * @api private
17649
+ */
17650
+
17651
+ function mixin(obj) {
17652
+ for (var key in Emitter.prototype) {
17653
+ obj[key] = Emitter.prototype[key];
17654
+ }
17655
+ return obj;
17656
+ }
17657
+
17658
+ /**
17659
+ * Listen on the given `event` with `fn`.
17660
+ *
17661
+ * @param {String} event
17662
+ * @param {Function} fn
17663
+ * @return {Emitter}
17664
+ * @api public
17665
+ */
17666
+
17667
+ Emitter.prototype.on =
17668
+ Emitter.prototype.addEventListener = function(event, fn){
17669
+ this._callbacks = this._callbacks || {};
17670
+ (this._callbacks['$' + event] = this._callbacks['$' + event] || [])
17671
+ .push(fn);
17672
+ return this;
17673
+ };
17674
+
17675
+ /**
17676
+ * Adds an `event` listener that will be invoked a single
17677
+ * time then automatically removed.
17678
+ *
17679
+ * @param {String} event
17680
+ * @param {Function} fn
17681
+ * @return {Emitter}
17682
+ * @api public
17683
+ */
17684
+
17685
+ Emitter.prototype.once = function(event, fn){
17686
+ function on() {
17687
+ this.off(event, on);
17688
+ fn.apply(this, arguments);
17689
+ }
17690
+
17691
+ on.fn = fn;
17692
+ this.on(event, on);
17693
+ return this;
17694
+ };
17695
+
17696
+ /**
17697
+ * Remove the given callback for `event` or all
17698
+ * registered callbacks.
17699
+ *
17700
+ * @param {String} event
17701
+ * @param {Function} fn
17702
+ * @return {Emitter}
17703
+ * @api public
17704
+ */
17705
+
17706
+ Emitter.prototype.off =
17707
+ Emitter.prototype.removeListener =
17708
+ Emitter.prototype.removeAllListeners =
17709
+ Emitter.prototype.removeEventListener = function(event, fn){
17710
+ this._callbacks = this._callbacks || {};
17711
+
17712
+ // all
17713
+ if (0 == arguments.length) {
17714
+ this._callbacks = {};
17715
+ return this;
17716
+ }
17717
+
17718
+ // specific event
17719
+ var callbacks = this._callbacks['$' + event];
17720
+ if (!callbacks) return this;
17721
+
17722
+ // remove all handlers
17723
+ if (1 == arguments.length) {
17724
+ delete this._callbacks['$' + event];
17725
+ return this;
17726
+ }
17727
+
17728
+ // remove specific handler
17729
+ var cb;
17730
+ for (var i = 0; i < callbacks.length; i++) {
17731
+ cb = callbacks[i];
17732
+ if (cb === fn || cb.fn === fn) {
17733
+ callbacks.splice(i, 1);
17734
+ break;
17735
+ }
17736
+ }
17737
+
17738
+ // Remove event specific arrays for event types that no
17739
+ // one is subscribed for to avoid memory leak.
17740
+ if (callbacks.length === 0) {
17741
+ delete this._callbacks['$' + event];
17742
+ }
17743
+
17744
+ return this;
17745
+ };
17746
+
17747
+ /**
17748
+ * Emit `event` with the given args.
17749
+ *
17750
+ * @param {String} event
17751
+ * @param {Mixed} ...
17752
+ * @return {Emitter}
17753
+ */
17754
+
17755
+ Emitter.prototype.emit = function(event){
17756
+ this._callbacks = this._callbacks || {};
17757
+
17758
+ var args = new Array(arguments.length - 1)
17759
+ , callbacks = this._callbacks['$' + event];
17760
+
17761
+ for (var i = 1; i < arguments.length; i++) {
17762
+ args[i - 1] = arguments[i];
17763
+ }
17764
+
17765
+ if (callbacks) {
17766
+ callbacks = callbacks.slice(0);
17767
+ for (var i = 0, len = callbacks.length; i < len; ++i) {
17768
+ callbacks[i].apply(this, args);
17769
+ }
17770
+ }
17771
+
17772
+ return this;
17773
+ };
17774
+
17775
+ /**
17776
+ * Return array of callbacks for `event`.
17777
+ *
17778
+ * @param {String} event
17779
+ * @return {Array}
17780
+ * @api public
17781
+ */
17782
+
17783
+ Emitter.prototype.listeners = function(event){
17784
+ this._callbacks = this._callbacks || {};
17785
+ return this._callbacks['$' + event] || [];
17786
+ };
17787
+
17788
+ /**
17789
+ * Check if this emitter has `event` handlers.
17790
+ *
17791
+ * @param {String} event
17792
+ * @return {Boolean}
17793
+ * @api public
17794
+ */
17795
+
17796
+ Emitter.prototype.hasListeners = function(event){
17797
+ return !! this.listeners(event).length;
17798
+ };
17577
17799
 
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
- };
17800
+ },{}],43:[function(require,module,exports){
17801
+ // Copyright Joyent, Inc. and other Node contributors.
17802
+ //
17803
+ // Permission is hereby granted, free of charge, to any person obtaining a
17804
+ // copy of this software and associated documentation files (the
17805
+ // "Software"), to deal in the Software without restriction, including
17806
+ // without limitation the rights to use, copy, modify, merge, publish,
17807
+ // distribute, sublicense, and/or sell copies of the Software, and to permit
17808
+ // persons to whom the Software is furnished to do so, subject to the
17809
+ // following conditions:
17810
+ //
17811
+ // The above copyright notice and this permission notice shall be included
17812
+ // in all copies or substantial portions of the Software.
17813
+ //
17814
+ // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
17815
+ // OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
17816
+ // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN
17817
+ // NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
17818
+ // DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
17819
+ // OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
17820
+ // USE OR OTHER DEALINGS IN THE SOFTWARE.
17593
17821
 
17594
- /**
17595
- * Mixin the emitter properties.
17596
- *
17597
- * @param {Object} obj
17598
- * @return {Object}
17599
- * @api private
17600
- */
17822
+ // NOTE: These type checking functions intentionally don't use `instanceof`
17823
+ // because it is fragile and can be easily faked with `Object.create()`.
17601
17824
 
17602
- function mixin(obj) {
17603
- for (var key in Emitter.prototype) {
17604
- obj[key] = Emitter.prototype[key];
17825
+ function isArray(arg) {
17826
+ if (Array.isArray) {
17827
+ return Array.isArray(arg);
17605
17828
  }
17606
- return obj;
17829
+ return objectToString(arg) === '[object Array]';
17607
17830
  }
17831
+ exports.isArray = isArray;
17608
17832
 
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
- };
17833
+ function isBoolean(arg) {
17834
+ return typeof arg === 'boolean';
17835
+ }
17836
+ exports.isBoolean = isBoolean;
17646
17837
 
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
- */
17838
+ function isNull(arg) {
17839
+ return arg === null;
17840
+ }
17841
+ exports.isNull = isNull;
17656
17842
 
17657
- Emitter.prototype.off =
17658
- Emitter.prototype.removeListener =
17659
- Emitter.prototype.removeAllListeners =
17660
- Emitter.prototype.removeEventListener = function(event, fn){
17661
- this._callbacks = this._callbacks || {};
17843
+ function isNullOrUndefined(arg) {
17844
+ return arg == null;
17845
+ }
17846
+ exports.isNullOrUndefined = isNullOrUndefined;
17662
17847
 
17663
- // all
17664
- if (0 == arguments.length) {
17665
- this._callbacks = {};
17666
- return this;
17667
- }
17848
+ function isNumber(arg) {
17849
+ return typeof arg === 'number';
17850
+ }
17851
+ exports.isNumber = isNumber;
17668
17852
 
17669
- // specific event
17670
- var callbacks = this._callbacks['$' + event];
17671
- if (!callbacks) return this;
17853
+ function isString(arg) {
17854
+ return typeof arg === 'string';
17855
+ }
17856
+ exports.isString = isString;
17672
17857
 
17673
- // remove all handlers
17674
- if (1 == arguments.length) {
17675
- delete this._callbacks['$' + event];
17676
- return this;
17677
- }
17858
+ function isSymbol(arg) {
17859
+ return typeof arg === 'symbol';
17860
+ }
17861
+ exports.isSymbol = isSymbol;
17678
17862
 
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
- };
17863
+ function isUndefined(arg) {
17864
+ return arg === void 0;
17865
+ }
17866
+ exports.isUndefined = isUndefined;
17690
17867
 
17691
- /**
17692
- * Emit `event` with the given args.
17693
- *
17694
- * @param {String} event
17695
- * @param {Mixed} ...
17696
- * @return {Emitter}
17697
- */
17868
+ function isRegExp(re) {
17869
+ return objectToString(re) === '[object RegExp]';
17870
+ }
17871
+ exports.isRegExp = isRegExp;
17698
17872
 
17699
- Emitter.prototype.emit = function(event){
17700
- this._callbacks = this._callbacks || {};
17701
- var args = [].slice.call(arguments, 1)
17702
- , callbacks = this._callbacks['$' + event];
17873
+ function isObject(arg) {
17874
+ return typeof arg === 'object' && arg !== null;
17875
+ }
17876
+ exports.isObject = isObject;
17703
17877
 
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
- }
17878
+ function isDate(d) {
17879
+ return objectToString(d) === '[object Date]';
17880
+ }
17881
+ exports.isDate = isDate;
17710
17882
 
17711
- return this;
17712
- };
17883
+ function isError(e) {
17884
+ return (objectToString(e) === '[object Error]' || e instanceof Error);
17885
+ }
17886
+ exports.isError = isError;
17713
17887
 
17714
- /**
17715
- * Return array of callbacks for `event`.
17716
- *
17717
- * @param {String} event
17718
- * @return {Array}
17719
- * @api public
17720
- */
17888
+ function isFunction(arg) {
17889
+ return typeof arg === 'function';
17890
+ }
17891
+ exports.isFunction = isFunction;
17721
17892
 
17722
- Emitter.prototype.listeners = function(event){
17723
- this._callbacks = this._callbacks || {};
17724
- return this._callbacks['$' + event] || [];
17725
- };
17893
+ function isPrimitive(arg) {
17894
+ return arg === null ||
17895
+ typeof arg === 'boolean' ||
17896
+ typeof arg === 'number' ||
17897
+ typeof arg === 'string' ||
17898
+ typeof arg === 'symbol' || // ES6 symbol
17899
+ typeof arg === 'undefined';
17900
+ }
17901
+ exports.isPrimitive = isPrimitive;
17726
17902
 
17727
- /**
17728
- * Check if this emitter has `event` handlers.
17729
- *
17730
- * @param {String} event
17731
- * @return {Boolean}
17732
- * @api public
17733
- */
17903
+ exports.isBuffer = require('buffer').Buffer.isBuffer;
17734
17904
 
17735
- Emitter.prototype.hasListeners = function(event){
17736
- return !! this.listeners(event).length;
17737
- };
17905
+ function objectToString(o) {
17906
+ return Object.prototype.toString.call(o);
17907
+ }
17738
17908
 
17739
- },{}],43:[function(require,module,exports){
17740
- // Copyright Joyent, Inc. and other Node contributors.
17741
- //
17742
- // Permission is hereby granted, free of charge, to any person obtaining a
17743
- // copy of this software and associated documentation files (the
17744
- // "Software"), to deal in the Software without restriction, including
17745
- // without limitation the rights to use, copy, modify, merge, publish,
17746
- // distribute, sublicense, and/or sell copies of the Software, and to permit
17747
- // persons to whom the Software is furnished to do so, subject to the
17748
- // following conditions:
17749
- //
17750
- // The above copyright notice and this permission notice shall be included
17751
- // in all copies or substantial portions of the Software.
17752
- //
17753
- // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
17754
- // OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
17755
- // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN
17756
- // NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
17757
- // DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
17758
- // OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
17759
- // USE OR OTHER DEALINGS IN THE SOFTWARE.
17760
-
17761
- // NOTE: These type checking functions intentionally don't use `instanceof`
17762
- // because it is fragile and can be easily faked with `Object.create()`.
17763
-
17764
- function isArray(arg) {
17765
- if (Array.isArray) {
17766
- return Array.isArray(arg);
17767
- }
17768
- return objectToString(arg) === '[object Array]';
17769
- }
17770
- exports.isArray = isArray;
17771
-
17772
- function isBoolean(arg) {
17773
- return typeof arg === 'boolean';
17774
- }
17775
- exports.isBoolean = isBoolean;
17776
-
17777
- function isNull(arg) {
17778
- return arg === null;
17779
- }
17780
- exports.isNull = isNull;
17781
-
17782
- function isNullOrUndefined(arg) {
17783
- return arg == null;
17784
- }
17785
- exports.isNullOrUndefined = isNullOrUndefined;
17786
-
17787
- function isNumber(arg) {
17788
- return typeof arg === 'number';
17789
- }
17790
- exports.isNumber = isNumber;
17791
-
17792
- function isString(arg) {
17793
- return typeof arg === 'string';
17794
- }
17795
- exports.isString = isString;
17796
-
17797
- function isSymbol(arg) {
17798
- return typeof arg === 'symbol';
17799
- }
17800
- exports.isSymbol = isSymbol;
17801
-
17802
- function isUndefined(arg) {
17803
- return arg === void 0;
17804
- }
17805
- exports.isUndefined = isUndefined;
17806
-
17807
- function isRegExp(re) {
17808
- return objectToString(re) === '[object RegExp]';
17809
- }
17810
- exports.isRegExp = isRegExp;
17811
-
17812
- function isObject(arg) {
17813
- return typeof arg === 'object' && arg !== null;
17814
- }
17815
- exports.isObject = isObject;
17816
-
17817
- function isDate(d) {
17818
- return objectToString(d) === '[object Date]';
17819
- }
17820
- exports.isDate = isDate;
17821
-
17822
- function isError(e) {
17823
- return (objectToString(e) === '[object Error]' || e instanceof Error);
17824
- }
17825
- exports.isError = isError;
17826
-
17827
- function isFunction(arg) {
17828
- return typeof arg === 'function';
17829
- }
17830
- exports.isFunction = isFunction;
17831
-
17832
- function isPrimitive(arg) {
17833
- return arg === null ||
17834
- typeof arg === 'boolean' ||
17835
- typeof arg === 'number' ||
17836
- typeof arg === 'string' ||
17837
- typeof arg === 'symbol' || // ES6 symbol
17838
- typeof arg === 'undefined';
17839
- }
17840
- exports.isPrimitive = isPrimitive;
17841
-
17842
- exports.isBuffer = require('buffer').Buffer.isBuffer;
17843
-
17844
- function objectToString(o) {
17845
- return Object.prototype.toString.call(o);
17846
- }
17847
-
17848
- },{"buffer":39}],44:[function(require,module,exports){
17909
+ },{"buffer":39}],44:[function(require,module,exports){
17849
17910
  // Copyright Joyent, Inc. and other Node contributors.
17850
17911
  //
17851
17912
  // Permission is hereby granted, free of charge, to any person obtaining a
@@ -18149,6 +18210,8 @@ function isUndefined(arg) {
18149
18210
  }
18150
18211
 
18151
18212
  },{}],45:[function(require,module,exports){
18213
+ 'use strict';
18214
+
18152
18215
  var hasOwn = Object.prototype.hasOwnProperty;
18153
18216
  var toStr = Object.prototype.toString;
18154
18217
  var defineProperty = Object.defineProperty;
@@ -18163,8 +18226,6 @@ var isArray = function isArray(arr) {
18163
18226
  };
18164
18227
 
18165
18228
  var isPlainObject = function isPlainObject(obj) {
18166
- 'use strict';
18167
-
18168
18229
  if (!obj || toStr.call(obj) !== '[object Object]') {
18169
18230
  return false;
18170
18231
  }
@@ -18214,8 +18275,6 @@ var getProperty = function getProperty(obj, name) {
18214
18275
  };
18215
18276
 
18216
18277
  module.exports = function extend() {
18217
- 'use strict';
18218
-
18219
18278
  var options, name, src, copy, copyIsArray, clone;
18220
18279
  var target = arguments[0];
18221
18280
  var i = 1;
@@ -23763,7 +23822,7 @@ Writable.prototype._destroy = function (err, cb) {
23763
23822
  cb(err);
23764
23823
  };
23765
23824
  }).call(this,require('_process'),typeof global !== "undefined" ? global : typeof self !== "undefined" ? self : typeof window !== "undefined" ? window : {})
23766
- },{"./_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){
23767
23826
  'use strict';
23768
23827
 
23769
23828
  function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
@@ -24571,7 +24630,7 @@ http.METHODS = [
24571
24630
  'UNLOCK',
24572
24631
  'UNSUBSCRIBE'
24573
24632
  ]
24574
- },{"./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){
24575
24634
  (function (global){
24576
24635
  exports.fetch = isFunction(global.fetch) && isFunction(global.ReadableByteStream)
24577
24636
 
@@ -25121,6 +25180,8 @@ function template(string) {
25121
25180
 
25122
25181
  var Emitter = require('emitter');
25123
25182
  var reduce = require('reduce');
25183
+ var requestBase = require('./request-base');
25184
+ var isObject = require('./is-object');
25124
25185
 
25125
25186
  /**
25126
25187
  * Root reference for iframes.
@@ -25142,28 +25203,10 @@ if (typeof window !== 'undefined') { // Browser window
25142
25203
  function noop(){};
25143
25204
 
25144
25205
  /**
25145
- * Check if `obj` is a host object,
25146
- * we don't want to serialize these :)
25147
- *
25148
- * TODO: future proof, move to compoent land
25149
- *
25150
- * @param {Object} obj
25151
- * @return {Boolean}
25152
- * @api private
25206
+ * Expose `request`.
25153
25207
  */
25154
25208
 
25155
- function isHost(obj) {
25156
- var str = {}.toString.call(obj);
25157
-
25158
- switch (str) {
25159
- case '[object File]':
25160
- case '[object Blob]':
25161
- case '[object FormData]':
25162
- return true;
25163
- default:
25164
- return false;
25165
- }
25166
- }
25209
+ var request = module.exports = require('./request').bind(null, Request);
25167
25210
 
25168
25211
  /**
25169
25212
  * Determine XHR.
@@ -25195,18 +25238,6 @@ var trim = ''.trim
25195
25238
  ? function(s) { return s.trim(); }
25196
25239
  : function(s) { return s.replace(/(^\s*|\s*$)/g, ''); };
25197
25240
 
25198
- /**
25199
- * Check if `obj` is an object.
25200
- *
25201
- * @param {Object} obj
25202
- * @return {Boolean}
25203
- * @api private
25204
- */
25205
-
25206
- function isObject(obj) {
25207
- return obj === Object(obj);
25208
- }
25209
-
25210
25241
  /**
25211
25242
  * Serialize the given `obj`.
25212
25243
  *
@@ -25221,8 +25252,8 @@ function serialize(obj) {
25221
25252
  for (var key in obj) {
25222
25253
  if (null != obj[key]) {
25223
25254
  pushEncodedKeyValuePair(pairs, key, obj[key]);
25224
- }
25225
- }
25255
+ }
25256
+ }
25226
25257
  return pairs.join('&');
25227
25258
  }
25228
25259
 
@@ -25240,6 +25271,11 @@ function pushEncodedKeyValuePair(pairs, key, val) {
25240
25271
  return val.forEach(function(v) {
25241
25272
  pushEncodedKeyValuePair(pairs, key, v);
25242
25273
  });
25274
+ } else if (isObject(val)) {
25275
+ for(var subkey in val) {
25276
+ pushEncodedKeyValuePair(pairs, key + '[' + subkey + ']', val[subkey]);
25277
+ }
25278
+ return;
25243
25279
  }
25244
25280
  pairs.push(encodeURIComponent(key)
25245
25281
  + '=' + encodeURIComponent(val));
@@ -25262,13 +25298,18 @@ function pushEncodedKeyValuePair(pairs, key, val) {
25262
25298
  function parseString(str) {
25263
25299
  var obj = {};
25264
25300
  var pairs = str.split('&');
25265
- var parts;
25266
25301
  var pair;
25302
+ var pos;
25267
25303
 
25268
25304
  for (var i = 0, len = pairs.length; i < len; ++i) {
25269
25305
  pair = pairs[i];
25270
- parts = pair.split('=');
25271
- 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
+ }
25272
25313
  }
25273
25314
 
25274
25315
  return obj;
@@ -25452,15 +25493,15 @@ function Response(req, options) {
25452
25493
  ? this.xhr.responseText
25453
25494
  : null;
25454
25495
  this.statusText = this.req.xhr.statusText;
25455
- this.setStatusProperties(this.xhr.status);
25496
+ this._setStatusProperties(this.xhr.status);
25456
25497
  this.header = this.headers = parseHeader(this.xhr.getAllResponseHeaders());
25457
25498
  // getAllResponseHeaders sometimes falsely returns "" for CORS requests, but
25458
25499
  // getResponseHeader still works. so we get content-type even if getting
25459
25500
  // other headers fails.
25460
25501
  this.header['content-type'] = this.xhr.getResponseHeader('content-type');
25461
- this.setHeaderProperties(this.header);
25502
+ this._setHeaderProperties(this.header);
25462
25503
  this.body = this.req.method != 'HEAD'
25463
- ? this.parseBody(this.text ? this.text : this.xhr.response)
25504
+ ? this._parseBody(this.text ? this.text : this.xhr.response)
25464
25505
  : null;
25465
25506
  }
25466
25507
 
@@ -25488,7 +25529,7 @@ Response.prototype.get = function(field){
25488
25529
  * @api private
25489
25530
  */
25490
25531
 
25491
- Response.prototype.setHeaderProperties = function(header){
25532
+ Response.prototype._setHeaderProperties = function(header){
25492
25533
  // content-type
25493
25534
  var ct = this.header['content-type'] || '';
25494
25535
  this.type = type(ct);
@@ -25509,8 +25550,11 @@ Response.prototype.setHeaderProperties = function(header){
25509
25550
  * @api private
25510
25551
  */
25511
25552
 
25512
- Response.prototype.parseBody = function(str){
25553
+ Response.prototype._parseBody = function(str){
25513
25554
  var parse = request.parse[this.type];
25555
+ if (!parse && isJSON(this.type)) {
25556
+ parse = request.parse['application/json'];
25557
+ }
25514
25558
  return parse && str && (str.length || str instanceof Object)
25515
25559
  ? parse(str)
25516
25560
  : null;
@@ -25537,7 +25581,7 @@ Response.prototype.parseBody = function(str){
25537
25581
  * @api private
25538
25582
  */
25539
25583
 
25540
- Response.prototype.setStatusProperties = function(status){
25584
+ Response.prototype._setStatusProperties = function(status){
25541
25585
  // handle IE9 bug: http://stackoverflow.com/questions/10046972/msie-returns-status-code-of-1223-for-ajax-request
25542
25586
  if (status === 1223) {
25543
25587
  status = 204;
@@ -25605,12 +25649,11 @@ request.Response = Response;
25605
25649
 
25606
25650
  function Request(method, url) {
25607
25651
  var self = this;
25608
- Emitter.call(this);
25609
25652
  this._query = this._query || [];
25610
25653
  this.method = method;
25611
25654
  this.url = url;
25612
- this.header = {};
25613
- this._header = {};
25655
+ this.header = {}; // preserves header name case
25656
+ this._header = {}; // coerces header names to lowercase
25614
25657
  this.on('end', function(){
25615
25658
  var err = null;
25616
25659
  var res = null;
@@ -25623,6 +25666,8 @@ function Request(method, url) {
25623
25666
  err.original = e;
25624
25667
  // issue #675: return the raw response if the response parsing fails
25625
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;
25626
25671
  return self.callback(err);
25627
25672
  }
25628
25673
 
@@ -25632,140 +25677,32 @@ function Request(method, url) {
25632
25677
  return self.callback(err, res);
25633
25678
  }
25634
25679
 
25635
- if (res.status >= 200 && res.status < 300) {
25636
- return self.callback(err, res);
25637
- }
25680
+ try {
25681
+ if (res.status >= 200 && res.status < 300) {
25682
+ return self.callback(err, res);
25683
+ }
25638
25684
 
25639
- var new_err = new Error(res.statusText || 'Unsuccessful HTTP response');
25640
- new_err.original = err;
25641
- new_err.response = res;
25642
- 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;
25643
25689
 
25644
- 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
+ }
25645
25694
  });
25646
25695
  }
25647
25696
 
25648
25697
  /**
25649
- * Mixin `Emitter`.
25698
+ * Mixin `Emitter` and `requestBase`.
25650
25699
  */
25651
25700
 
25652
25701
  Emitter(Request.prototype);
25653
-
25654
- /**
25655
- * Allow for extension
25656
- */
25657
-
25658
- Request.prototype.use = function(fn) {
25659
- fn(this);
25660
- return this;
25702
+ for (var key in requestBase) {
25703
+ Request.prototype[key] = requestBase[key];
25661
25704
  }
25662
25705
 
25663
- /**
25664
- * Set timeout to `ms`.
25665
- *
25666
- * @param {Number} ms
25667
- * @return {Request} for chaining
25668
- * @api public
25669
- */
25670
-
25671
- Request.prototype.timeout = function(ms){
25672
- this._timeout = ms;
25673
- return this;
25674
- };
25675
-
25676
- /**
25677
- * Clear previous timeout.
25678
- *
25679
- * @return {Request} for chaining
25680
- * @api public
25681
- */
25682
-
25683
- Request.prototype.clearTimeout = function(){
25684
- this._timeout = 0;
25685
- clearTimeout(this._timer);
25686
- return this;
25687
- };
25688
-
25689
- /**
25690
- * Abort the request, and clear potential timeout.
25691
- *
25692
- * @return {Request}
25693
- * @api public
25694
- */
25695
-
25696
- Request.prototype.abort = function(){
25697
- if (this.aborted) return;
25698
- this.aborted = true;
25699
- this.xhr.abort();
25700
- this.clearTimeout();
25701
- this.emit('abort');
25702
- return this;
25703
- };
25704
-
25705
- /**
25706
- * Set header `field` to `val`, or multiple fields with one object.
25707
- *
25708
- * Examples:
25709
- *
25710
- * req.get('/')
25711
- * .set('Accept', 'application/json')
25712
- * .set('X-API-Key', 'foobar')
25713
- * .end(callback);
25714
- *
25715
- * req.get('/')
25716
- * .set({ Accept: 'application/json', 'X-API-Key': 'foobar' })
25717
- * .end(callback);
25718
- *
25719
- * @param {String|Object} field
25720
- * @param {String} val
25721
- * @return {Request} for chaining
25722
- * @api public
25723
- */
25724
-
25725
- Request.prototype.set = function(field, val){
25726
- if (isObject(field)) {
25727
- for (var key in field) {
25728
- this.set(key, field[key]);
25729
- }
25730
- return this;
25731
- }
25732
- this._header[field.toLowerCase()] = val;
25733
- this.header[field] = val;
25734
- return this;
25735
- };
25736
-
25737
- /**
25738
- * Remove header `field`.
25739
- *
25740
- * Example:
25741
- *
25742
- * req.get('/')
25743
- * .unset('User-Agent')
25744
- * .end(callback);
25745
- *
25746
- * @param {String} field
25747
- * @return {Request} for chaining
25748
- * @api public
25749
- */
25750
-
25751
- Request.prototype.unset = function(field){
25752
- delete this._header[field.toLowerCase()];
25753
- delete this.header[field];
25754
- return this;
25755
- };
25756
-
25757
- /**
25758
- * Get case-insensitive header `field` value.
25759
- *
25760
- * @param {String} field
25761
- * @return {String}
25762
- * @api private
25763
- */
25764
-
25765
- Request.prototype.getHeader = function(field){
25766
- return this._header[field.toLowerCase()];
25767
- };
25768
-
25769
25706
  /**
25770
25707
  * Set Content-Type to `type`, mapping values from `request.types`.
25771
25708
  *
@@ -25794,16 +25731,22 @@ Request.prototype.type = function(type){
25794
25731
  };
25795
25732
 
25796
25733
  /**
25797
- * Force given parser
25734
+ * Set responseType to `val`. Presently valid responseTypes are 'blob' and
25735
+ * 'arraybuffer'.
25798
25736
  *
25799
- * Sets the body parser no matter type.
25737
+ * Examples:
25800
25738
  *
25801
- * @param {Function}
25739
+ * req.get('/')
25740
+ * .responseType('blob')
25741
+ * .end(callback);
25742
+ *
25743
+ * @param {String} val
25744
+ * @return {Request} for chaining
25802
25745
  * @api public
25803
25746
  */
25804
25747
 
25805
- Request.prototype.parse = function(fn){
25806
- this._parser = fn;
25748
+ Request.prototype.responseType = function(val){
25749
+ this._responseType = val;
25807
25750
  return this;
25808
25751
  };
25809
25752
 
@@ -25837,13 +25780,29 @@ Request.prototype.accept = function(type){
25837
25780
  *
25838
25781
  * @param {String} user
25839
25782
  * @param {String} pass
25783
+ * @param {Object} options with 'type' property 'auto' or 'basic' (default 'basic')
25840
25784
  * @return {Request} for chaining
25841
25785
  * @api public
25842
25786
  */
25843
25787
 
25844
- Request.prototype.auth = function(user, pass){
25845
- var str = btoa(user + ':' + pass);
25846
- 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
+ }
25847
25806
  return this;
25848
25807
  };
25849
25808
 
@@ -25867,35 +25826,13 @@ Request.prototype.query = function(val){
25867
25826
  return this;
25868
25827
  };
25869
25828
 
25870
- /**
25871
- * Write the field `name` and `val` for "multipart/form-data"
25872
- * request bodies.
25873
- *
25874
- * ``` js
25875
- * request.post('/upload')
25876
- * .field('foo', 'bar')
25877
- * .end(callback);
25878
- * ```
25879
- *
25880
- * @param {String} name
25881
- * @param {String|Blob|File} val
25882
- * @return {Request} for chaining
25883
- * @api public
25884
- */
25885
-
25886
- Request.prototype.field = function(name, val){
25887
- if (!this._formData) this._formData = new root.FormData();
25888
- this._formData.append(name, val);
25889
- return this;
25890
- };
25891
-
25892
25829
  /**
25893
25830
  * Queue the given `file` as an attachment to the specified `field`,
25894
25831
  * with optional `filename`.
25895
25832
  *
25896
25833
  * ``` js
25897
25834
  * request.post('/upload')
25898
- * .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"}))
25899
25836
  * .end(callback);
25900
25837
  * ```
25901
25838
  *
@@ -25907,77 +25844,15 @@ Request.prototype.field = function(name, val){
25907
25844
  */
25908
25845
 
25909
25846
  Request.prototype.attach = function(field, file, filename){
25910
- if (!this._formData) this._formData = new root.FormData();
25911
- this._formData.append(field, file, filename || file.name);
25847
+ this._getFormData().append(field, file, filename || file.name);
25912
25848
  return this;
25913
25849
  };
25914
25850
 
25915
- /**
25916
- * Send `data` as the request body, defaulting the `.type()` to "json" when
25917
- * an object is given.
25918
- *
25919
- * Examples:
25920
- *
25921
- * // manual json
25922
- * request.post('/user')
25923
- * .type('json')
25924
- * .send('{"name":"tj"}')
25925
- * .end(callback)
25926
- *
25927
- * // auto json
25928
- * request.post('/user')
25929
- * .send({ name: 'tj' })
25930
- * .end(callback)
25931
- *
25932
- * // manual x-www-form-urlencoded
25933
- * request.post('/user')
25934
- * .type('form')
25935
- * .send('name=tj')
25936
- * .end(callback)
25937
- *
25938
- * // auto x-www-form-urlencoded
25939
- * request.post('/user')
25940
- * .type('form')
25941
- * .send({ name: 'tj' })
25942
- * .end(callback)
25943
- *
25944
- * // defaults to x-www-form-urlencoded
25945
- * request.post('/user')
25946
- * .send('name=tobi')
25947
- * .send('species=ferret')
25948
- * .end(callback)
25949
- *
25950
- * @param {String|Object} data
25951
- * @return {Request} for chaining
25952
- * @api public
25953
- */
25954
-
25955
- Request.prototype.send = function(data){
25956
- var obj = isObject(data);
25957
- var type = this.getHeader('Content-Type');
25958
-
25959
- // merge
25960
- if (obj && isObject(this._data)) {
25961
- for (var key in data) {
25962
- this._data[key] = data[key];
25963
- }
25964
- } else if ('string' == typeof data) {
25965
- if (!type) this.type('form');
25966
- type = this.getHeader('Content-Type');
25967
- if ('application/x-www-form-urlencoded' == type) {
25968
- this._data = this._data
25969
- ? this._data + '&' + data
25970
- : data;
25971
- } else {
25972
- this._data = (this._data || '') + data;
25973
- }
25974
- } else {
25975
- this._data = data;
25851
+ Request.prototype._getFormData = function(){
25852
+ if (!this._formData) {
25853
+ this._formData = new root.FormData();
25976
25854
  }
25977
-
25978
- if (!obj || isHost(data)) return this;
25979
- if (!type) this.type('json');
25980
- return this;
25855
+ return this._formData;
25981
25856
  };
25982
25857
 
25983
25858
  /**
@@ -26018,7 +25893,7 @@ Request.prototype.crossDomainError = function(){
26018
25893
  * @api private
26019
25894
  */
26020
25895
 
26021
- Request.prototype.timeoutError = function(){
25896
+ Request.prototype._timeoutError = function(){
26022
25897
  var timeout = this._timeout;
26023
25898
  var err = new Error('timeout of ' + timeout + 'ms exceeded');
26024
25899
  err.timeout = timeout;
@@ -26026,19 +25901,18 @@ Request.prototype.timeoutError = function(){
26026
25901
  };
26027
25902
 
26028
25903
  /**
26029
- * Enable transmission of cookies with x-domain requests.
26030
- *
26031
- * Note that for this to work the origin must not be
26032
- * using "Access-Control-Allow-Origin" with a wildcard,
26033
- * and also must set "Access-Control-Allow-Credentials"
26034
- * to "true".
25904
+ * Compose querystring to append to req.url
26035
25905
  *
26036
- * @api public
25906
+ * @api private
26037
25907
  */
26038
25908
 
26039
- Request.prototype.withCredentials = function(){
26040
- this._withCredentials = true;
26041
- 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
+ }
26042
25916
  };
26043
25917
 
26044
25918
  /**
@@ -26053,7 +25927,6 @@ Request.prototype.withCredentials = function(){
26053
25927
  Request.prototype.end = function(fn){
26054
25928
  var self = this;
26055
25929
  var xhr = this.xhr = request.getXHR();
26056
- var query = this._query.join('&');
26057
25930
  var timeout = this._timeout;
26058
25931
  var data = this._formData || this._data;
26059
25932
 
@@ -26070,8 +25943,8 @@ Request.prototype.end = function(fn){
26070
25943
  try { status = xhr.status } catch(e) { status = 0; }
26071
25944
 
26072
25945
  if (0 == status) {
26073
- if (self.timedout) return self.timeoutError();
26074
- if (self.aborted) return;
25946
+ if (self.timedout) return self._timeoutError();
25947
+ if (self._aborted) return;
26075
25948
  return self.crossDomainError();
26076
25949
  }
26077
25950
  self.emit('end');
@@ -26107,24 +25980,23 @@ Request.prototype.end = function(fn){
26107
25980
  }
26108
25981
 
26109
25982
  // querystring
26110
- if (query) {
26111
- query = request.serializeObject(query);
26112
- this.url += ~this.url.indexOf('?')
26113
- ? '&' + query
26114
- : '?' + query;
26115
- }
25983
+ this._appendQueryString();
26116
25984
 
26117
25985
  // initiate request
26118
- 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
+ }
26119
25991
 
26120
25992
  // CORS
26121
25993
  if (this._withCredentials) xhr.withCredentials = true;
26122
25994
 
26123
25995
  // body
26124
- 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)) {
26125
25997
  // serialize stuff
26126
- var contentType = this.getHeader('Content-Type');
26127
- 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] : ''];
26128
26000
  if (!serialize && isJSON(contentType)) serialize = request.serialize['application/json'];
26129
26001
  if (serialize) data = serialize(data);
26130
26002
  }
@@ -26135,6 +26007,10 @@ Request.prototype.end = function(fn){
26135
26007
  xhr.setRequestHeader(field, this.header[field]);
26136
26008
  }
26137
26009
 
26010
+ if (this._responseType) {
26011
+ xhr.responseType = this._responseType;
26012
+ }
26013
+
26138
26014
  // send stuff
26139
26015
  this.emit('request', this);
26140
26016
 
@@ -26144,19 +26020,6 @@ Request.prototype.end = function(fn){
26144
26020
  return this;
26145
26021
  };
26146
26022
 
26147
- /**
26148
- * Faux promise support
26149
- *
26150
- * @param {Function} fulfill
26151
- * @param {Function} reject
26152
- * @return {Request}
26153
- */
26154
-
26155
- Request.prototype.then = function (fulfill, reject) {
26156
- return this.end(function(err, res) {
26157
- err ? reject(err) : fulfill(res);
26158
- });
26159
- }
26160
26023
 
26161
26024
  /**
26162
26025
  * Expose `Request`.
@@ -26164,35 +26027,6 @@ Request.prototype.then = function (fulfill, reject) {
26164
26027
 
26165
26028
  request.Request = Request;
26166
26029
 
26167
- /**
26168
- * Issue a request:
26169
- *
26170
- * Examples:
26171
- *
26172
- * request('GET', '/users').end(callback)
26173
- * request('/users').end(callback)
26174
- * request('/users', callback)
26175
- *
26176
- * @param {String} method
26177
- * @param {String|Function} url or callback
26178
- * @return {Request}
26179
- * @api public
26180
- */
26181
-
26182
- function request(method, url) {
26183
- // callback
26184
- if ('function' == typeof url) {
26185
- return new Request('GET', method).end(url);
26186
- }
26187
-
26188
- // url first
26189
- if (1 == arguments.length) {
26190
- return new Request('GET', method);
26191
- }
26192
-
26193
- return new Request(method, url);
26194
- }
26195
-
26196
26030
  /**
26197
26031
  * GET `url` with optional callback `fn(res)`.
26198
26032
  *
@@ -26229,6 +26063,24 @@ request.head = function(url, data, fn){
26229
26063
  return req;
26230
26064
  };
26231
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
+
26232
26084
  /**
26233
26085
  * DELETE `url` with optional callback `fn(res)`.
26234
26086
  *
@@ -26301,13 +26153,404 @@ request.put = function(url, data, fn){
26301
26153
  return req;
26302
26154
  };
26303
26155
 
26156
+ },{"./is-object":89,"./request":91,"./request-base":90,"emitter":42,"reduce":79}],89:[function(require,module,exports){
26304
26157
  /**
26305
- * 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
26433
+ */
26434
+
26435
+ exports._isHost = function _isHost(obj) {
26436
+ var str = {}.toString.call(obj);
26437
+
26438
+ switch (str) {
26439
+ case '[object File]':
26440
+ case '[object Blob]':
26441
+ case '[object FormData]':
26442
+ return true;
26443
+ default:
26444
+ return false;
26445
+ }
26446
+ }
26447
+
26448
+ /**
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
26306
26535
  */
26307
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
+
26308
26551
  module.exports = request;
26309
26552
 
26310
- },{"emitter":42,"reduce":79}],89:[function(require,module,exports){
26553
+ },{}],92:[function(require,module,exports){
26311
26554
  (function (Buffer){
26312
26555
  "0.50.0";
26313
26556
  /*
@@ -34504,7 +34747,7 @@ TinCan client library
34504
34747
  }());
34505
34748
 
34506
34749
  }).call(this,require("buffer").Buffer)
34507
- },{"buffer":39,"querystring":61,"xhr2":93}],90:[function(require,module,exports){
34750
+ },{"buffer":39,"querystring":61,"xhr2":96}],93:[function(require,module,exports){
34508
34751
  // Copyright Joyent, Inc. and other Node contributors.
34509
34752
  //
34510
34753
  // Permission is hereby granted, free of charge, to any person obtaining a
@@ -35213,7 +35456,7 @@ function isNullOrUndefined(arg) {
35213
35456
  return arg == null;
35214
35457
  }
35215
35458
 
35216
- },{"punycode":57,"querystring":61}],91:[function(require,module,exports){
35459
+ },{"punycode":57,"querystring":61}],94:[function(require,module,exports){
35217
35460
  (function (global){
35218
35461
 
35219
35462
  /**
@@ -35284,7 +35527,7 @@ function config (name) {
35284
35527
  }
35285
35528
 
35286
35529
  }).call(this,typeof global !== "undefined" ? global : typeof self !== "undefined" ? self : typeof window !== "undefined" ? window : {})
35287
- },{}],92:[function(require,module,exports){
35530
+ },{}],95:[function(require,module,exports){
35288
35531
  /*!
35289
35532
  * validate.js 0.9.0
35290
35533
  *
@@ -36372,7 +36615,7 @@ function config (name) {
36372
36615
  typeof module !== 'undefined' ? /* istanbul ignore next */ module : null,
36373
36616
  typeof define !== 'undefined' ? /* istanbul ignore next */ define : null);
36374
36617
 
36375
- },{}],93:[function(require,module,exports){
36618
+ },{}],96:[function(require,module,exports){
36376
36619
  (function (process,Buffer){
36377
36620
  // Generated by CoffeeScript 1.6.3
36378
36621
  (function() {
@@ -37210,7 +37453,7 @@ function config (name) {
37210
37453
  }).call(this);
37211
37454
 
37212
37455
  }).call(this,require('_process'),require("buffer").Buffer)
37213
- },{"_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){
37214
37457
  module.exports = extend
37215
37458
 
37216
37459
  var hasOwnProperty = Object.prototype.hasOwnProperty;