comprodls-sdk 2.71.0-development → 2.72.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/comprodls-sdk.js +757 -530
- package/dist/comprodls-sdk.min.js +15 -15
- package/lib/comprodls.js +0 -2
- package/lib/config/index.js +2 -21
- package/lib/services/pushX/index.js +56 -4
- package/package.json +1 -1
package/dist/comprodls-sdk.js
CHANGED
|
@@ -84,8 +84,6 @@ function comproDLS(environment, realm, options) {
|
|
|
84
84
|
try {
|
|
85
85
|
config.DEFAULT_HOSTS = config.REALM_HOSTS[realm.toUpperCase()][environment.toUpperCase()];
|
|
86
86
|
if(!config.DEFAULT_HOSTS){ throw 'Invalid Environment'; }
|
|
87
|
-
|
|
88
|
-
config.PUBNUB_ORIGINS = config.PUBNUB_ORIGINS[realm.toUpperCase()][environment.toUpperCase()];
|
|
89
87
|
}
|
|
90
88
|
catch (e){
|
|
91
89
|
var realmObj = config.REALM_HOSTS[realm.toUpperCase()];
|
|
@@ -505,7 +503,8 @@ exports.PUB_API_URLS = {
|
|
|
505
503
|
|
|
506
504
|
exports.PUSHX_API_URLS = {
|
|
507
505
|
grantByUserOrgId: '/orgs/{orgId}/grants',
|
|
508
|
-
grantByAccountId: '/accounts/{accountId}/grants'
|
|
506
|
+
grantByAccountId: '/accounts/{accountId}/grants',
|
|
507
|
+
getPushedEvents: '/accounts/{accountId}/pushed-events/channels'
|
|
509
508
|
};
|
|
510
509
|
|
|
511
510
|
exports.INTEGRATIONS_API_URLS = {
|
|
@@ -534,26 +533,6 @@ exports.RULES_API_URLS = {
|
|
|
534
533
|
updateRuleDisplay: '/org/{orgId}/context/{context}/rule_type/{ruleType}/rules/{ruleId}/update-rule-display',
|
|
535
534
|
getUserRule: '/org/{orgId}/context/{context}/rule_type/{ruleType}/users/{userId}/rules'
|
|
536
535
|
};
|
|
537
|
-
|
|
538
|
-
exports.PUBNUB_ORIGINS = {
|
|
539
|
-
ASGARD: {
|
|
540
|
-
THOR: {
|
|
541
|
-
CUSTOM: 'pushdlsthor.pubnubapi.com'
|
|
542
|
-
}
|
|
543
|
-
},
|
|
544
|
-
GLOBAL: {
|
|
545
|
-
PRODUCTION: {
|
|
546
|
-
},
|
|
547
|
-
PROD1: {}
|
|
548
|
-
},
|
|
549
|
-
CUP: {
|
|
550
|
-
QA: {},
|
|
551
|
-
REL: {},
|
|
552
|
-
HFX: {},
|
|
553
|
-
ALPHA: {},
|
|
554
|
-
PROD1: {}
|
|
555
|
-
}
|
|
556
|
-
};
|
|
557
536
|
|
|
558
537
|
},{}],3:[function(require,module,exports){
|
|
559
538
|
/*************************************************************************
|
|
@@ -1172,7 +1151,7 @@ validator.validators.contains = function(value, options) {
|
|
|
1172
1151
|
}
|
|
1173
1152
|
}
|
|
1174
1153
|
};
|
|
1175
|
-
},{"./errors":7,"validate.js":
|
|
1154
|
+
},{"./errors":7,"validate.js":53}],10:[function(require,module,exports){
|
|
1176
1155
|
/*************************************************************************
|
|
1177
1156
|
*
|
|
1178
1157
|
* COMPRO CONFIDENTIAL
|
|
@@ -12826,6 +12805,7 @@ function getAllProductFamilies(options) {
|
|
|
12826
12805
|
|
|
12827
12806
|
var q = require('q');
|
|
12828
12807
|
var request = require('superagent');
|
|
12808
|
+
var Agent = require('agentkeepalive');
|
|
12829
12809
|
|
|
12830
12810
|
var helpers = require('../../helpers');
|
|
12831
12811
|
var pubnubClientWrapper = require('./pubnubClientWrapper');
|
|
@@ -12836,6 +12816,11 @@ var DLSError = helpers.errors.DLSError;
|
|
|
12836
12816
|
**********************************/
|
|
12837
12817
|
module.exports = pushX;
|
|
12838
12818
|
|
|
12819
|
+
var keepaliveAgent = new Agent({
|
|
12820
|
+
timeout: 60000,
|
|
12821
|
+
freeSocketTimeout: 30000
|
|
12822
|
+
});
|
|
12823
|
+
|
|
12839
12824
|
/*********************************
|
|
12840
12825
|
* Public Function definitions
|
|
12841
12826
|
**********************************/
|
|
@@ -12846,14 +12831,15 @@ function pushX() {
|
|
|
12846
12831
|
"cleanup": _cleanup.bind(this, _pubnubClientWrapper),
|
|
12847
12832
|
"grantByUserOrgId": grantByUserOrgId.bind(this),
|
|
12848
12833
|
"grantByAccountId": grantByAccountId.bind(this),
|
|
12849
|
-
"grantByAccountIdOnExtUserId": grantByAccountIdOnExtUserId.bind(this)
|
|
12834
|
+
"grantByAccountIdOnExtUserId": grantByAccountIdOnExtUserId.bind(this),
|
|
12835
|
+
"getPushedEvents": getPushedEvents.bind(this)
|
|
12850
12836
|
};
|
|
12851
12837
|
}
|
|
12852
12838
|
|
|
12853
12839
|
/*********************************
|
|
12854
12840
|
* Public Function definitions
|
|
12855
12841
|
**********************************/
|
|
12856
|
-
|
|
12842
|
+
// This is a dummy comment to test release.
|
|
12857
12843
|
function _connect(pubnubCW, options) {
|
|
12858
12844
|
var bpubnubV7 = true; // If pubnub v7 or higher in package.json, set it true
|
|
12859
12845
|
if (bpubnubV7 && !options.userid) {
|
|
@@ -12870,8 +12856,7 @@ function _connect(pubnubCW, options) {
|
|
|
12870
12856
|
'publishKey': options.publishKey,
|
|
12871
12857
|
'subscribeKey': options.subscribeKey,
|
|
12872
12858
|
'authKey': options.authKey,
|
|
12873
|
-
'ssl': true
|
|
12874
|
-
'origin': this.config.PUBNUB_ORIGINS.CUSTOM
|
|
12859
|
+
'ssl': true
|
|
12875
12860
|
}
|
|
12876
12861
|
});
|
|
12877
12862
|
}
|
|
@@ -12997,8 +12982,54 @@ function grantByAccountIdOnExtUserId(options) {
|
|
|
12997
12982
|
return dfd.promise;
|
|
12998
12983
|
}
|
|
12999
12984
|
|
|
12985
|
+
/**
|
|
12986
|
+
* @param {
|
|
12987
|
+
* *accountid: "string",
|
|
12988
|
+
* *channelName: "string",
|
|
12989
|
+
* *starttime: number,
|
|
12990
|
+
* *endtime: number
|
|
12991
|
+
* } options
|
|
12992
|
+
*/
|
|
12993
|
+
function getPushedEvents(options) {
|
|
12994
|
+
var self = this;
|
|
12995
|
+
var dfd = q.defer(); // Initializing promise
|
|
12996
|
+
var accountid = options.accountid,
|
|
12997
|
+
channelname = options.channelname,
|
|
12998
|
+
starttime = options.starttime,
|
|
12999
|
+
endtime = options.endtime;
|
|
13000
|
+
|
|
13001
|
+
if (accountid && channelname && starttime && endtime) {
|
|
13002
|
+
// Passed all validations, Construct API url
|
|
13003
|
+
var url = self.config.DEFAULT_HOSTS.PUSHX + self.config.PUSHX_API_URLS.getPushedEvents;
|
|
13004
|
+
url = helpers.api.constructAPIUrl(url, { accountId: accountid });
|
|
13005
|
+
|
|
13006
|
+
// Setup request with URL and Params
|
|
13007
|
+
var params = {channelname: channelname, starttime: starttime, endtime: endtime};
|
|
13008
|
+
var requestAPI = request.get(url).query(params);
|
|
13009
|
+
if(self.traceid) { requestAPI.set('X-Amzn-Trace-Id', self.traceid); }
|
|
13010
|
+
|
|
13011
|
+
requestAPI
|
|
13012
|
+
.agent(keepaliveAgent)
|
|
13013
|
+
.end(function(error, response) {
|
|
13014
|
+
if (error) {
|
|
13015
|
+
error = new DLSError(helpers.errors.ERROR_TYPES.API_ERROR, error);
|
|
13016
|
+
dfd.reject(error);
|
|
13017
|
+
} else {
|
|
13018
|
+
dfd.resolve(response.body);
|
|
13019
|
+
}
|
|
13020
|
+
});
|
|
13021
|
+
}
|
|
13022
|
+
else {
|
|
13023
|
+
var err = {};
|
|
13024
|
+
err.message = err.description = 'Mandatory parameters [accountId, channelname,' +
|
|
13025
|
+
' starttime, endtime] not found in request options';
|
|
13026
|
+
err = new DLSError(helpers.errors.ERROR_TYPES.SDK_ERROR, err);
|
|
13027
|
+
dfd.reject(err);
|
|
13028
|
+
}
|
|
13029
|
+
return dfd.promise;
|
|
13030
|
+
}
|
|
13000
13031
|
|
|
13001
|
-
},{"../../helpers":3,"./pubnubClientWrapper":26,"q":46,"superagent":49}],26:[function(require,module,exports){
|
|
13032
|
+
},{"../../helpers":3,"./pubnubClientWrapper":26,"agentkeepalive":36,"q":46,"superagent":49}],26:[function(require,module,exports){
|
|
13002
13033
|
var pubNub = require("pubnub");
|
|
13003
13034
|
var EventEmitter = require("events").EventEmitter;
|
|
13004
13035
|
var helpers = require('../../helpers');
|
|
@@ -18278,167 +18309,181 @@ module.exports = Array.isArray || function (arr) {
|
|
|
18278
18309
|
};
|
|
18279
18310
|
|
|
18280
18311
|
},{}],40:[function(require,module,exports){
|
|
18281
|
-
|
|
18282
|
-
/**
|
|
18283
|
-
* Expose `Emitter`.
|
|
18284
|
-
*/
|
|
18285
|
-
|
|
18286
|
-
module
|
|
18287
|
-
|
|
18288
|
-
|
|
18289
|
-
|
|
18290
|
-
|
|
18291
|
-
*
|
|
18292
|
-
|
|
18293
|
-
|
|
18294
|
-
|
|
18295
|
-
|
|
18296
|
-
|
|
18297
|
-
|
|
18298
|
-
|
|
18299
|
-
|
|
18300
|
-
|
|
18301
|
-
*
|
|
18302
|
-
*
|
|
18303
|
-
* @
|
|
18304
|
-
|
|
18305
|
-
|
|
18306
|
-
|
|
18307
|
-
|
|
18308
|
-
|
|
18309
|
-
|
|
18310
|
-
|
|
18311
|
-
}
|
|
18312
|
-
|
|
18313
|
-
|
|
18314
|
-
|
|
18315
|
-
|
|
18316
|
-
*
|
|
18317
|
-
*
|
|
18318
|
-
* @
|
|
18319
|
-
* @
|
|
18320
|
-
|
|
18321
|
-
|
|
18322
|
-
|
|
18323
|
-
|
|
18324
|
-
|
|
18325
|
-
|
|
18326
|
-
|
|
18327
|
-
|
|
18328
|
-
|
|
18329
|
-
|
|
18330
|
-
|
|
18331
|
-
|
|
18332
|
-
|
|
18333
|
-
*
|
|
18334
|
-
*
|
|
18335
|
-
*
|
|
18336
|
-
* @
|
|
18337
|
-
* @
|
|
18338
|
-
|
|
18339
|
-
|
|
18340
|
-
|
|
18341
|
-
|
|
18342
|
-
|
|
18343
|
-
|
|
18344
|
-
|
|
18345
|
-
|
|
18346
|
-
|
|
18347
|
-
|
|
18348
|
-
|
|
18349
|
-
|
|
18350
|
-
|
|
18351
|
-
|
|
18352
|
-
|
|
18353
|
-
|
|
18354
|
-
*
|
|
18355
|
-
*
|
|
18356
|
-
*
|
|
18357
|
-
* @
|
|
18358
|
-
* @
|
|
18359
|
-
|
|
18360
|
-
|
|
18361
|
-
|
|
18362
|
-
|
|
18363
|
-
Emitter.prototype.
|
|
18364
|
-
Emitter.prototype.
|
|
18365
|
-
|
|
18366
|
-
|
|
18367
|
-
|
|
18368
|
-
|
|
18369
|
-
|
|
18370
|
-
|
|
18371
|
-
|
|
18372
|
-
|
|
18373
|
-
|
|
18374
|
-
|
|
18375
|
-
|
|
18376
|
-
|
|
18377
|
-
|
|
18378
|
-
|
|
18379
|
-
|
|
18380
|
-
|
|
18381
|
-
|
|
18382
|
-
|
|
18383
|
-
|
|
18384
|
-
|
|
18385
|
-
|
|
18386
|
-
|
|
18387
|
-
|
|
18388
|
-
|
|
18389
|
-
|
|
18390
|
-
|
|
18391
|
-
|
|
18392
|
-
|
|
18393
|
-
}
|
|
18394
|
-
|
|
18395
|
-
|
|
18396
|
-
|
|
18397
|
-
|
|
18398
|
-
|
|
18399
|
-
|
|
18400
|
-
|
|
18401
|
-
|
|
18402
|
-
|
|
18403
|
-
|
|
18404
|
-
|
|
18405
|
-
|
|
18406
|
-
|
|
18407
|
-
|
|
18408
|
-
|
|
18409
|
-
|
|
18410
|
-
|
|
18411
|
-
|
|
18412
|
-
|
|
18413
|
-
}
|
|
18414
|
-
|
|
18415
|
-
|
|
18416
|
-
|
|
18417
|
-
|
|
18418
|
-
|
|
18419
|
-
|
|
18420
|
-
|
|
18421
|
-
|
|
18422
|
-
|
|
18423
|
-
|
|
18424
|
-
|
|
18425
|
-
|
|
18426
|
-
|
|
18427
|
-
|
|
18428
|
-
|
|
18429
|
-
|
|
18430
|
-
|
|
18431
|
-
|
|
18432
|
-
|
|
18433
|
-
*
|
|
18434
|
-
*
|
|
18435
|
-
* @
|
|
18436
|
-
* @
|
|
18437
|
-
|
|
18438
|
-
|
|
18439
|
-
|
|
18440
|
-
|
|
18441
|
-
};
|
|
18312
|
+
|
|
18313
|
+
/**
|
|
18314
|
+
* Expose `Emitter`.
|
|
18315
|
+
*/
|
|
18316
|
+
|
|
18317
|
+
if (typeof module !== 'undefined') {
|
|
18318
|
+
module.exports = Emitter;
|
|
18319
|
+
}
|
|
18320
|
+
|
|
18321
|
+
/**
|
|
18322
|
+
* Initialize a new `Emitter`.
|
|
18323
|
+
*
|
|
18324
|
+
* @api public
|
|
18325
|
+
*/
|
|
18326
|
+
|
|
18327
|
+
function Emitter(obj) {
|
|
18328
|
+
if (obj) return mixin(obj);
|
|
18329
|
+
};
|
|
18330
|
+
|
|
18331
|
+
/**
|
|
18332
|
+
* Mixin the emitter properties.
|
|
18333
|
+
*
|
|
18334
|
+
* @param {Object} obj
|
|
18335
|
+
* @return {Object}
|
|
18336
|
+
* @api private
|
|
18337
|
+
*/
|
|
18338
|
+
|
|
18339
|
+
function mixin(obj) {
|
|
18340
|
+
for (var key in Emitter.prototype) {
|
|
18341
|
+
obj[key] = Emitter.prototype[key];
|
|
18342
|
+
}
|
|
18343
|
+
return obj;
|
|
18344
|
+
}
|
|
18345
|
+
|
|
18346
|
+
/**
|
|
18347
|
+
* Listen on the given `event` with `fn`.
|
|
18348
|
+
*
|
|
18349
|
+
* @param {String} event
|
|
18350
|
+
* @param {Function} fn
|
|
18351
|
+
* @return {Emitter}
|
|
18352
|
+
* @api public
|
|
18353
|
+
*/
|
|
18354
|
+
|
|
18355
|
+
Emitter.prototype.on =
|
|
18356
|
+
Emitter.prototype.addEventListener = function(event, fn){
|
|
18357
|
+
this._callbacks = this._callbacks || {};
|
|
18358
|
+
(this._callbacks['$' + event] = this._callbacks['$' + event] || [])
|
|
18359
|
+
.push(fn);
|
|
18360
|
+
return this;
|
|
18361
|
+
};
|
|
18362
|
+
|
|
18363
|
+
/**
|
|
18364
|
+
* Adds an `event` listener that will be invoked a single
|
|
18365
|
+
* time then automatically removed.
|
|
18366
|
+
*
|
|
18367
|
+
* @param {String} event
|
|
18368
|
+
* @param {Function} fn
|
|
18369
|
+
* @return {Emitter}
|
|
18370
|
+
* @api public
|
|
18371
|
+
*/
|
|
18372
|
+
|
|
18373
|
+
Emitter.prototype.once = function(event, fn){
|
|
18374
|
+
function on() {
|
|
18375
|
+
this.off(event, on);
|
|
18376
|
+
fn.apply(this, arguments);
|
|
18377
|
+
}
|
|
18378
|
+
|
|
18379
|
+
on.fn = fn;
|
|
18380
|
+
this.on(event, on);
|
|
18381
|
+
return this;
|
|
18382
|
+
};
|
|
18383
|
+
|
|
18384
|
+
/**
|
|
18385
|
+
* Remove the given callback for `event` or all
|
|
18386
|
+
* registered callbacks.
|
|
18387
|
+
*
|
|
18388
|
+
* @param {String} event
|
|
18389
|
+
* @param {Function} fn
|
|
18390
|
+
* @return {Emitter}
|
|
18391
|
+
* @api public
|
|
18392
|
+
*/
|
|
18393
|
+
|
|
18394
|
+
Emitter.prototype.off =
|
|
18395
|
+
Emitter.prototype.removeListener =
|
|
18396
|
+
Emitter.prototype.removeAllListeners =
|
|
18397
|
+
Emitter.prototype.removeEventListener = function(event, fn){
|
|
18398
|
+
this._callbacks = this._callbacks || {};
|
|
18399
|
+
|
|
18400
|
+
// all
|
|
18401
|
+
if (0 == arguments.length) {
|
|
18402
|
+
this._callbacks = {};
|
|
18403
|
+
return this;
|
|
18404
|
+
}
|
|
18405
|
+
|
|
18406
|
+
// specific event
|
|
18407
|
+
var callbacks = this._callbacks['$' + event];
|
|
18408
|
+
if (!callbacks) return this;
|
|
18409
|
+
|
|
18410
|
+
// remove all handlers
|
|
18411
|
+
if (1 == arguments.length) {
|
|
18412
|
+
delete this._callbacks['$' + event];
|
|
18413
|
+
return this;
|
|
18414
|
+
}
|
|
18415
|
+
|
|
18416
|
+
// remove specific handler
|
|
18417
|
+
var cb;
|
|
18418
|
+
for (var i = 0; i < callbacks.length; i++) {
|
|
18419
|
+
cb = callbacks[i];
|
|
18420
|
+
if (cb === fn || cb.fn === fn) {
|
|
18421
|
+
callbacks.splice(i, 1);
|
|
18422
|
+
break;
|
|
18423
|
+
}
|
|
18424
|
+
}
|
|
18425
|
+
|
|
18426
|
+
// Remove event specific arrays for event types that no
|
|
18427
|
+
// one is subscribed for to avoid memory leak.
|
|
18428
|
+
if (callbacks.length === 0) {
|
|
18429
|
+
delete this._callbacks['$' + event];
|
|
18430
|
+
}
|
|
18431
|
+
|
|
18432
|
+
return this;
|
|
18433
|
+
};
|
|
18434
|
+
|
|
18435
|
+
/**
|
|
18436
|
+
* Emit `event` with the given args.
|
|
18437
|
+
*
|
|
18438
|
+
* @param {String} event
|
|
18439
|
+
* @param {Mixed} ...
|
|
18440
|
+
* @return {Emitter}
|
|
18441
|
+
*/
|
|
18442
|
+
|
|
18443
|
+
Emitter.prototype.emit = function(event){
|
|
18444
|
+
this._callbacks = this._callbacks || {};
|
|
18445
|
+
|
|
18446
|
+
var args = new Array(arguments.length - 1)
|
|
18447
|
+
, callbacks = this._callbacks['$' + event];
|
|
18448
|
+
|
|
18449
|
+
for (var i = 1; i < arguments.length; i++) {
|
|
18450
|
+
args[i - 1] = arguments[i];
|
|
18451
|
+
}
|
|
18452
|
+
|
|
18453
|
+
if (callbacks) {
|
|
18454
|
+
callbacks = callbacks.slice(0);
|
|
18455
|
+
for (var i = 0, len = callbacks.length; i < len; ++i) {
|
|
18456
|
+
callbacks[i].apply(this, args);
|
|
18457
|
+
}
|
|
18458
|
+
}
|
|
18459
|
+
|
|
18460
|
+
return this;
|
|
18461
|
+
};
|
|
18462
|
+
|
|
18463
|
+
/**
|
|
18464
|
+
* Return array of callbacks for `event`.
|
|
18465
|
+
*
|
|
18466
|
+
* @param {String} event
|
|
18467
|
+
* @return {Array}
|
|
18468
|
+
* @api public
|
|
18469
|
+
*/
|
|
18470
|
+
|
|
18471
|
+
Emitter.prototype.listeners = function(event){
|
|
18472
|
+
this._callbacks = this._callbacks || {};
|
|
18473
|
+
return this._callbacks['$' + event] || [];
|
|
18474
|
+
};
|
|
18475
|
+
|
|
18476
|
+
/**
|
|
18477
|
+
* Check if this emitter has `event` handlers.
|
|
18478
|
+
*
|
|
18479
|
+
* @param {String} event
|
|
18480
|
+
* @return {Boolean}
|
|
18481
|
+
* @api public
|
|
18482
|
+
*/
|
|
18483
|
+
|
|
18484
|
+
Emitter.prototype.hasListeners = function(event){
|
|
18485
|
+
return !! this.listeners(event).length;
|
|
18486
|
+
};
|
|
18442
18487
|
|
|
18443
18488
|
},{}],41:[function(require,module,exports){
|
|
18444
18489
|
// Copyright Joyent, Inc. and other Node contributors.
|
|
@@ -18744,6 +18789,8 @@ function isUndefined(arg) {
|
|
|
18744
18789
|
}
|
|
18745
18790
|
|
|
18746
18791
|
},{}],42:[function(require,module,exports){
|
|
18792
|
+
'use strict';
|
|
18793
|
+
|
|
18747
18794
|
var hasOwn = Object.prototype.hasOwnProperty;
|
|
18748
18795
|
var toStr = Object.prototype.toString;
|
|
18749
18796
|
var defineProperty = Object.defineProperty;
|
|
@@ -18758,8 +18805,6 @@ var isArray = function isArray(arr) {
|
|
|
18758
18805
|
};
|
|
18759
18806
|
|
|
18760
18807
|
var isPlainObject = function isPlainObject(obj) {
|
|
18761
|
-
'use strict';
|
|
18762
|
-
|
|
18763
18808
|
if (!obj || toStr.call(obj) !== '[object Object]') {
|
|
18764
18809
|
return false;
|
|
18765
18810
|
}
|
|
@@ -18809,8 +18854,6 @@ var getProperty = function getProperty(obj, name) {
|
|
|
18809
18854
|
};
|
|
18810
18855
|
|
|
18811
18856
|
module.exports = function extend() {
|
|
18812
|
-
'use strict';
|
|
18813
|
-
|
|
18814
18857
|
var options, name, src, copy, copyIsArray, clone;
|
|
18815
18858
|
var target = arguments[0];
|
|
18816
18859
|
var i = 1;
|
|
@@ -21280,6 +21323,8 @@ function template(string) {
|
|
|
21280
21323
|
|
|
21281
21324
|
var Emitter = require('emitter');
|
|
21282
21325
|
var reduce = require('reduce');
|
|
21326
|
+
var requestBase = require('./request-base');
|
|
21327
|
+
var isObject = require('./is-object');
|
|
21283
21328
|
|
|
21284
21329
|
/**
|
|
21285
21330
|
* Root reference for iframes.
|
|
@@ -21301,28 +21346,10 @@ if (typeof window !== 'undefined') { // Browser window
|
|
|
21301
21346
|
function noop(){};
|
|
21302
21347
|
|
|
21303
21348
|
/**
|
|
21304
|
-
*
|
|
21305
|
-
* we don't want to serialize these :)
|
|
21306
|
-
*
|
|
21307
|
-
* TODO: future proof, move to compoent land
|
|
21308
|
-
*
|
|
21309
|
-
* @param {Object} obj
|
|
21310
|
-
* @return {Boolean}
|
|
21311
|
-
* @api private
|
|
21349
|
+
* Expose `request`.
|
|
21312
21350
|
*/
|
|
21313
21351
|
|
|
21314
|
-
|
|
21315
|
-
var str = {}.toString.call(obj);
|
|
21316
|
-
|
|
21317
|
-
switch (str) {
|
|
21318
|
-
case '[object File]':
|
|
21319
|
-
case '[object Blob]':
|
|
21320
|
-
case '[object FormData]':
|
|
21321
|
-
return true;
|
|
21322
|
-
default:
|
|
21323
|
-
return false;
|
|
21324
|
-
}
|
|
21325
|
-
}
|
|
21352
|
+
var request = module.exports = require('./request').bind(null, Request);
|
|
21326
21353
|
|
|
21327
21354
|
/**
|
|
21328
21355
|
* Determine XHR.
|
|
@@ -21354,18 +21381,6 @@ var trim = ''.trim
|
|
|
21354
21381
|
? function(s) { return s.trim(); }
|
|
21355
21382
|
: function(s) { return s.replace(/(^\s*|\s*$)/g, ''); };
|
|
21356
21383
|
|
|
21357
|
-
/**
|
|
21358
|
-
* Check if `obj` is an object.
|
|
21359
|
-
*
|
|
21360
|
-
* @param {Object} obj
|
|
21361
|
-
* @return {Boolean}
|
|
21362
|
-
* @api private
|
|
21363
|
-
*/
|
|
21364
|
-
|
|
21365
|
-
function isObject(obj) {
|
|
21366
|
-
return obj === Object(obj);
|
|
21367
|
-
}
|
|
21368
|
-
|
|
21369
21384
|
/**
|
|
21370
21385
|
* Serialize the given `obj`.
|
|
21371
21386
|
*
|
|
@@ -21380,8 +21395,8 @@ function serialize(obj) {
|
|
|
21380
21395
|
for (var key in obj) {
|
|
21381
21396
|
if (null != obj[key]) {
|
|
21382
21397
|
pushEncodedKeyValuePair(pairs, key, obj[key]);
|
|
21383
|
-
|
|
21384
|
-
|
|
21398
|
+
}
|
|
21399
|
+
}
|
|
21385
21400
|
return pairs.join('&');
|
|
21386
21401
|
}
|
|
21387
21402
|
|
|
@@ -21399,6 +21414,11 @@ function pushEncodedKeyValuePair(pairs, key, val) {
|
|
|
21399
21414
|
return val.forEach(function(v) {
|
|
21400
21415
|
pushEncodedKeyValuePair(pairs, key, v);
|
|
21401
21416
|
});
|
|
21417
|
+
} else if (isObject(val)) {
|
|
21418
|
+
for(var subkey in val) {
|
|
21419
|
+
pushEncodedKeyValuePair(pairs, key + '[' + subkey + ']', val[subkey]);
|
|
21420
|
+
}
|
|
21421
|
+
return;
|
|
21402
21422
|
}
|
|
21403
21423
|
pairs.push(encodeURIComponent(key)
|
|
21404
21424
|
+ '=' + encodeURIComponent(val));
|
|
@@ -21421,13 +21441,18 @@ function pushEncodedKeyValuePair(pairs, key, val) {
|
|
|
21421
21441
|
function parseString(str) {
|
|
21422
21442
|
var obj = {};
|
|
21423
21443
|
var pairs = str.split('&');
|
|
21424
|
-
var parts;
|
|
21425
21444
|
var pair;
|
|
21445
|
+
var pos;
|
|
21426
21446
|
|
|
21427
21447
|
for (var i = 0, len = pairs.length; i < len; ++i) {
|
|
21428
21448
|
pair = pairs[i];
|
|
21429
|
-
|
|
21430
|
-
|
|
21449
|
+
pos = pair.indexOf('=');
|
|
21450
|
+
if (pos == -1) {
|
|
21451
|
+
obj[decodeURIComponent(pair)] = '';
|
|
21452
|
+
} else {
|
|
21453
|
+
obj[decodeURIComponent(pair.slice(0, pos))] =
|
|
21454
|
+
decodeURIComponent(pair.slice(pos + 1));
|
|
21455
|
+
}
|
|
21431
21456
|
}
|
|
21432
21457
|
|
|
21433
21458
|
return obj;
|
|
@@ -21611,15 +21636,15 @@ function Response(req, options) {
|
|
|
21611
21636
|
? this.xhr.responseText
|
|
21612
21637
|
: null;
|
|
21613
21638
|
this.statusText = this.req.xhr.statusText;
|
|
21614
|
-
this.
|
|
21639
|
+
this._setStatusProperties(this.xhr.status);
|
|
21615
21640
|
this.header = this.headers = parseHeader(this.xhr.getAllResponseHeaders());
|
|
21616
21641
|
// getAllResponseHeaders sometimes falsely returns "" for CORS requests, but
|
|
21617
21642
|
// getResponseHeader still works. so we get content-type even if getting
|
|
21618
21643
|
// other headers fails.
|
|
21619
21644
|
this.header['content-type'] = this.xhr.getResponseHeader('content-type');
|
|
21620
|
-
this.
|
|
21645
|
+
this._setHeaderProperties(this.header);
|
|
21621
21646
|
this.body = this.req.method != 'HEAD'
|
|
21622
|
-
? this.
|
|
21647
|
+
? this._parseBody(this.text ? this.text : this.xhr.response)
|
|
21623
21648
|
: null;
|
|
21624
21649
|
}
|
|
21625
21650
|
|
|
@@ -21647,7 +21672,7 @@ Response.prototype.get = function(field){
|
|
|
21647
21672
|
* @api private
|
|
21648
21673
|
*/
|
|
21649
21674
|
|
|
21650
|
-
Response.prototype.
|
|
21675
|
+
Response.prototype._setHeaderProperties = function(header){
|
|
21651
21676
|
// content-type
|
|
21652
21677
|
var ct = this.header['content-type'] || '';
|
|
21653
21678
|
this.type = type(ct);
|
|
@@ -21668,8 +21693,11 @@ Response.prototype.setHeaderProperties = function(header){
|
|
|
21668
21693
|
* @api private
|
|
21669
21694
|
*/
|
|
21670
21695
|
|
|
21671
|
-
Response.prototype.
|
|
21696
|
+
Response.prototype._parseBody = function(str){
|
|
21672
21697
|
var parse = request.parse[this.type];
|
|
21698
|
+
if (!parse && isJSON(this.type)) {
|
|
21699
|
+
parse = request.parse['application/json'];
|
|
21700
|
+
}
|
|
21673
21701
|
return parse && str && (str.length || str instanceof Object)
|
|
21674
21702
|
? parse(str)
|
|
21675
21703
|
: null;
|
|
@@ -21696,7 +21724,7 @@ Response.prototype.parseBody = function(str){
|
|
|
21696
21724
|
* @api private
|
|
21697
21725
|
*/
|
|
21698
21726
|
|
|
21699
|
-
Response.prototype.
|
|
21727
|
+
Response.prototype._setStatusProperties = function(status){
|
|
21700
21728
|
// handle IE9 bug: http://stackoverflow.com/questions/10046972/msie-returns-status-code-of-1223-for-ajax-request
|
|
21701
21729
|
if (status === 1223) {
|
|
21702
21730
|
status = 204;
|
|
@@ -21764,12 +21792,11 @@ request.Response = Response;
|
|
|
21764
21792
|
|
|
21765
21793
|
function Request(method, url) {
|
|
21766
21794
|
var self = this;
|
|
21767
|
-
Emitter.call(this);
|
|
21768
21795
|
this._query = this._query || [];
|
|
21769
21796
|
this.method = method;
|
|
21770
21797
|
this.url = url;
|
|
21771
|
-
this.header = {};
|
|
21772
|
-
this._header = {};
|
|
21798
|
+
this.header = {}; // preserves header name case
|
|
21799
|
+
this._header = {}; // coerces header names to lowercase
|
|
21773
21800
|
this.on('end', function(){
|
|
21774
21801
|
var err = null;
|
|
21775
21802
|
var res = null;
|
|
@@ -21782,6 +21809,8 @@ function Request(method, url) {
|
|
|
21782
21809
|
err.original = e;
|
|
21783
21810
|
// issue #675: return the raw response if the response parsing fails
|
|
21784
21811
|
err.rawResponse = self.xhr && self.xhr.responseText ? self.xhr.responseText : null;
|
|
21812
|
+
// issue #876: return the http status code if the response parsing fails
|
|
21813
|
+
err.statusCode = self.xhr && self.xhr.status ? self.xhr.status : null;
|
|
21785
21814
|
return self.callback(err);
|
|
21786
21815
|
}
|
|
21787
21816
|
|
|
@@ -21791,140 +21820,32 @@ function Request(method, url) {
|
|
|
21791
21820
|
return self.callback(err, res);
|
|
21792
21821
|
}
|
|
21793
21822
|
|
|
21794
|
-
|
|
21795
|
-
|
|
21796
|
-
|
|
21823
|
+
try {
|
|
21824
|
+
if (res.status >= 200 && res.status < 300) {
|
|
21825
|
+
return self.callback(err, res);
|
|
21826
|
+
}
|
|
21797
21827
|
|
|
21798
|
-
|
|
21799
|
-
|
|
21800
|
-
|
|
21801
|
-
|
|
21828
|
+
var new_err = new Error(res.statusText || 'Unsuccessful HTTP response');
|
|
21829
|
+
new_err.original = err;
|
|
21830
|
+
new_err.response = res;
|
|
21831
|
+
new_err.status = res.status;
|
|
21802
21832
|
|
|
21803
|
-
|
|
21833
|
+
self.callback(new_err, res);
|
|
21834
|
+
} catch(e) {
|
|
21835
|
+
self.callback(e); // #985 touching res may cause INVALID_STATE_ERR on old Android
|
|
21836
|
+
}
|
|
21804
21837
|
});
|
|
21805
21838
|
}
|
|
21806
21839
|
|
|
21807
21840
|
/**
|
|
21808
|
-
* Mixin `Emitter`.
|
|
21841
|
+
* Mixin `Emitter` and `requestBase`.
|
|
21809
21842
|
*/
|
|
21810
21843
|
|
|
21811
21844
|
Emitter(Request.prototype);
|
|
21812
|
-
|
|
21813
|
-
|
|
21814
|
-
* Allow for extension
|
|
21815
|
-
*/
|
|
21816
|
-
|
|
21817
|
-
Request.prototype.use = function(fn) {
|
|
21818
|
-
fn(this);
|
|
21819
|
-
return this;
|
|
21845
|
+
for (var key in requestBase) {
|
|
21846
|
+
Request.prototype[key] = requestBase[key];
|
|
21820
21847
|
}
|
|
21821
21848
|
|
|
21822
|
-
/**
|
|
21823
|
-
* Set timeout to `ms`.
|
|
21824
|
-
*
|
|
21825
|
-
* @param {Number} ms
|
|
21826
|
-
* @return {Request} for chaining
|
|
21827
|
-
* @api public
|
|
21828
|
-
*/
|
|
21829
|
-
|
|
21830
|
-
Request.prototype.timeout = function(ms){
|
|
21831
|
-
this._timeout = ms;
|
|
21832
|
-
return this;
|
|
21833
|
-
};
|
|
21834
|
-
|
|
21835
|
-
/**
|
|
21836
|
-
* Clear previous timeout.
|
|
21837
|
-
*
|
|
21838
|
-
* @return {Request} for chaining
|
|
21839
|
-
* @api public
|
|
21840
|
-
*/
|
|
21841
|
-
|
|
21842
|
-
Request.prototype.clearTimeout = function(){
|
|
21843
|
-
this._timeout = 0;
|
|
21844
|
-
clearTimeout(this._timer);
|
|
21845
|
-
return this;
|
|
21846
|
-
};
|
|
21847
|
-
|
|
21848
|
-
/**
|
|
21849
|
-
* Abort the request, and clear potential timeout.
|
|
21850
|
-
*
|
|
21851
|
-
* @return {Request}
|
|
21852
|
-
* @api public
|
|
21853
|
-
*/
|
|
21854
|
-
|
|
21855
|
-
Request.prototype.abort = function(){
|
|
21856
|
-
if (this.aborted) return;
|
|
21857
|
-
this.aborted = true;
|
|
21858
|
-
this.xhr.abort();
|
|
21859
|
-
this.clearTimeout();
|
|
21860
|
-
this.emit('abort');
|
|
21861
|
-
return this;
|
|
21862
|
-
};
|
|
21863
|
-
|
|
21864
|
-
/**
|
|
21865
|
-
* Set header `field` to `val`, or multiple fields with one object.
|
|
21866
|
-
*
|
|
21867
|
-
* Examples:
|
|
21868
|
-
*
|
|
21869
|
-
* req.get('/')
|
|
21870
|
-
* .set('Accept', 'application/json')
|
|
21871
|
-
* .set('X-API-Key', 'foobar')
|
|
21872
|
-
* .end(callback);
|
|
21873
|
-
*
|
|
21874
|
-
* req.get('/')
|
|
21875
|
-
* .set({ Accept: 'application/json', 'X-API-Key': 'foobar' })
|
|
21876
|
-
* .end(callback);
|
|
21877
|
-
*
|
|
21878
|
-
* @param {String|Object} field
|
|
21879
|
-
* @param {String} val
|
|
21880
|
-
* @return {Request} for chaining
|
|
21881
|
-
* @api public
|
|
21882
|
-
*/
|
|
21883
|
-
|
|
21884
|
-
Request.prototype.set = function(field, val){
|
|
21885
|
-
if (isObject(field)) {
|
|
21886
|
-
for (var key in field) {
|
|
21887
|
-
this.set(key, field[key]);
|
|
21888
|
-
}
|
|
21889
|
-
return this;
|
|
21890
|
-
}
|
|
21891
|
-
this._header[field.toLowerCase()] = val;
|
|
21892
|
-
this.header[field] = val;
|
|
21893
|
-
return this;
|
|
21894
|
-
};
|
|
21895
|
-
|
|
21896
|
-
/**
|
|
21897
|
-
* Remove header `field`.
|
|
21898
|
-
*
|
|
21899
|
-
* Example:
|
|
21900
|
-
*
|
|
21901
|
-
* req.get('/')
|
|
21902
|
-
* .unset('User-Agent')
|
|
21903
|
-
* .end(callback);
|
|
21904
|
-
*
|
|
21905
|
-
* @param {String} field
|
|
21906
|
-
* @return {Request} for chaining
|
|
21907
|
-
* @api public
|
|
21908
|
-
*/
|
|
21909
|
-
|
|
21910
|
-
Request.prototype.unset = function(field){
|
|
21911
|
-
delete this._header[field.toLowerCase()];
|
|
21912
|
-
delete this.header[field];
|
|
21913
|
-
return this;
|
|
21914
|
-
};
|
|
21915
|
-
|
|
21916
|
-
/**
|
|
21917
|
-
* Get case-insensitive header `field` value.
|
|
21918
|
-
*
|
|
21919
|
-
* @param {String} field
|
|
21920
|
-
* @return {String}
|
|
21921
|
-
* @api private
|
|
21922
|
-
*/
|
|
21923
|
-
|
|
21924
|
-
Request.prototype.getHeader = function(field){
|
|
21925
|
-
return this._header[field.toLowerCase()];
|
|
21926
|
-
};
|
|
21927
|
-
|
|
21928
21849
|
/**
|
|
21929
21850
|
* Set Content-Type to `type`, mapping values from `request.types`.
|
|
21930
21851
|
*
|
|
@@ -21953,16 +21874,22 @@ Request.prototype.type = function(type){
|
|
|
21953
21874
|
};
|
|
21954
21875
|
|
|
21955
21876
|
/**
|
|
21956
|
-
*
|
|
21877
|
+
* Set responseType to `val`. Presently valid responseTypes are 'blob' and
|
|
21878
|
+
* 'arraybuffer'.
|
|
21957
21879
|
*
|
|
21958
|
-
*
|
|
21880
|
+
* Examples:
|
|
21959
21881
|
*
|
|
21960
|
-
*
|
|
21882
|
+
* req.get('/')
|
|
21883
|
+
* .responseType('blob')
|
|
21884
|
+
* .end(callback);
|
|
21885
|
+
*
|
|
21886
|
+
* @param {String} val
|
|
21887
|
+
* @return {Request} for chaining
|
|
21961
21888
|
* @api public
|
|
21962
21889
|
*/
|
|
21963
21890
|
|
|
21964
|
-
Request.prototype.
|
|
21965
|
-
this.
|
|
21891
|
+
Request.prototype.responseType = function(val){
|
|
21892
|
+
this._responseType = val;
|
|
21966
21893
|
return this;
|
|
21967
21894
|
};
|
|
21968
21895
|
|
|
@@ -21996,13 +21923,29 @@ Request.prototype.accept = function(type){
|
|
|
21996
21923
|
*
|
|
21997
21924
|
* @param {String} user
|
|
21998
21925
|
* @param {String} pass
|
|
21926
|
+
* @param {Object} options with 'type' property 'auto' or 'basic' (default 'basic')
|
|
21999
21927
|
* @return {Request} for chaining
|
|
22000
21928
|
* @api public
|
|
22001
21929
|
*/
|
|
22002
21930
|
|
|
22003
|
-
Request.prototype.auth = function(user, pass){
|
|
22004
|
-
|
|
22005
|
-
|
|
21931
|
+
Request.prototype.auth = function(user, pass, options){
|
|
21932
|
+
if (!options) {
|
|
21933
|
+
options = {
|
|
21934
|
+
type: 'basic'
|
|
21935
|
+
}
|
|
21936
|
+
}
|
|
21937
|
+
|
|
21938
|
+
switch (options.type) {
|
|
21939
|
+
case 'basic':
|
|
21940
|
+
var str = btoa(user + ':' + pass);
|
|
21941
|
+
this.set('Authorization', 'Basic ' + str);
|
|
21942
|
+
break;
|
|
21943
|
+
|
|
21944
|
+
case 'auto':
|
|
21945
|
+
this.username = user;
|
|
21946
|
+
this.password = pass;
|
|
21947
|
+
break;
|
|
21948
|
+
}
|
|
22006
21949
|
return this;
|
|
22007
21950
|
};
|
|
22008
21951
|
|
|
@@ -22026,35 +21969,13 @@ Request.prototype.query = function(val){
|
|
|
22026
21969
|
return this;
|
|
22027
21970
|
};
|
|
22028
21971
|
|
|
22029
|
-
/**
|
|
22030
|
-
* Write the field `name` and `val` for "multipart/form-data"
|
|
22031
|
-
* request bodies.
|
|
22032
|
-
*
|
|
22033
|
-
* ``` js
|
|
22034
|
-
* request.post('/upload')
|
|
22035
|
-
* .field('foo', 'bar')
|
|
22036
|
-
* .end(callback);
|
|
22037
|
-
* ```
|
|
22038
|
-
*
|
|
22039
|
-
* @param {String} name
|
|
22040
|
-
* @param {String|Blob|File} val
|
|
22041
|
-
* @return {Request} for chaining
|
|
22042
|
-
* @api public
|
|
22043
|
-
*/
|
|
22044
|
-
|
|
22045
|
-
Request.prototype.field = function(name, val){
|
|
22046
|
-
if (!this._formData) this._formData = new root.FormData();
|
|
22047
|
-
this._formData.append(name, val);
|
|
22048
|
-
return this;
|
|
22049
|
-
};
|
|
22050
|
-
|
|
22051
21972
|
/**
|
|
22052
21973
|
* Queue the given `file` as an attachment to the specified `field`,
|
|
22053
21974
|
* with optional `filename`.
|
|
22054
21975
|
*
|
|
22055
21976
|
* ``` js
|
|
22056
21977
|
* request.post('/upload')
|
|
22057
|
-
* .attach(new Blob(['<a id="a"><b id="b">hey!</b></a>'], { type: "text/html"}))
|
|
21978
|
+
* .attach('content', new Blob(['<a id="a"><b id="b">hey!</b></a>'], { type: "text/html"}))
|
|
22058
21979
|
* .end(callback);
|
|
22059
21980
|
* ```
|
|
22060
21981
|
*
|
|
@@ -22066,77 +21987,15 @@ Request.prototype.field = function(name, val){
|
|
|
22066
21987
|
*/
|
|
22067
21988
|
|
|
22068
21989
|
Request.prototype.attach = function(field, file, filename){
|
|
22069
|
-
|
|
22070
|
-
this._formData.append(field, file, filename || file.name);
|
|
21990
|
+
this._getFormData().append(field, file, filename || file.name);
|
|
22071
21991
|
return this;
|
|
22072
21992
|
};
|
|
22073
21993
|
|
|
22074
|
-
|
|
22075
|
-
|
|
22076
|
-
|
|
22077
|
-
*
|
|
22078
|
-
* Examples:
|
|
22079
|
-
*
|
|
22080
|
-
* // manual json
|
|
22081
|
-
* request.post('/user')
|
|
22082
|
-
* .type('json')
|
|
22083
|
-
* .send('{"name":"tj"}')
|
|
22084
|
-
* .end(callback)
|
|
22085
|
-
*
|
|
22086
|
-
* // auto json
|
|
22087
|
-
* request.post('/user')
|
|
22088
|
-
* .send({ name: 'tj' })
|
|
22089
|
-
* .end(callback)
|
|
22090
|
-
*
|
|
22091
|
-
* // manual x-www-form-urlencoded
|
|
22092
|
-
* request.post('/user')
|
|
22093
|
-
* .type('form')
|
|
22094
|
-
* .send('name=tj')
|
|
22095
|
-
* .end(callback)
|
|
22096
|
-
*
|
|
22097
|
-
* // auto x-www-form-urlencoded
|
|
22098
|
-
* request.post('/user')
|
|
22099
|
-
* .type('form')
|
|
22100
|
-
* .send({ name: 'tj' })
|
|
22101
|
-
* .end(callback)
|
|
22102
|
-
*
|
|
22103
|
-
* // defaults to x-www-form-urlencoded
|
|
22104
|
-
* request.post('/user')
|
|
22105
|
-
* .send('name=tobi')
|
|
22106
|
-
* .send('species=ferret')
|
|
22107
|
-
* .end(callback)
|
|
22108
|
-
*
|
|
22109
|
-
* @param {String|Object} data
|
|
22110
|
-
* @return {Request} for chaining
|
|
22111
|
-
* @api public
|
|
22112
|
-
*/
|
|
22113
|
-
|
|
22114
|
-
Request.prototype.send = function(data){
|
|
22115
|
-
var obj = isObject(data);
|
|
22116
|
-
var type = this.getHeader('Content-Type');
|
|
22117
|
-
|
|
22118
|
-
// merge
|
|
22119
|
-
if (obj && isObject(this._data)) {
|
|
22120
|
-
for (var key in data) {
|
|
22121
|
-
this._data[key] = data[key];
|
|
22122
|
-
}
|
|
22123
|
-
} else if ('string' == typeof data) {
|
|
22124
|
-
if (!type) this.type('form');
|
|
22125
|
-
type = this.getHeader('Content-Type');
|
|
22126
|
-
if ('application/x-www-form-urlencoded' == type) {
|
|
22127
|
-
this._data = this._data
|
|
22128
|
-
? this._data + '&' + data
|
|
22129
|
-
: data;
|
|
22130
|
-
} else {
|
|
22131
|
-
this._data = (this._data || '') + data;
|
|
22132
|
-
}
|
|
22133
|
-
} else {
|
|
22134
|
-
this._data = data;
|
|
21994
|
+
Request.prototype._getFormData = function(){
|
|
21995
|
+
if (!this._formData) {
|
|
21996
|
+
this._formData = new root.FormData();
|
|
22135
21997
|
}
|
|
22136
|
-
|
|
22137
|
-
if (!obj || isHost(data)) return this;
|
|
22138
|
-
if (!type) this.type('json');
|
|
22139
|
-
return this;
|
|
21998
|
+
return this._formData;
|
|
22140
21999
|
};
|
|
22141
22000
|
|
|
22142
22001
|
/**
|
|
@@ -22177,7 +22036,7 @@ Request.prototype.crossDomainError = function(){
|
|
|
22177
22036
|
* @api private
|
|
22178
22037
|
*/
|
|
22179
22038
|
|
|
22180
|
-
Request.prototype.
|
|
22039
|
+
Request.prototype._timeoutError = function(){
|
|
22181
22040
|
var timeout = this._timeout;
|
|
22182
22041
|
var err = new Error('timeout of ' + timeout + 'ms exceeded');
|
|
22183
22042
|
err.timeout = timeout;
|
|
@@ -22185,19 +22044,18 @@ Request.prototype.timeoutError = function(){
|
|
|
22185
22044
|
};
|
|
22186
22045
|
|
|
22187
22046
|
/**
|
|
22188
|
-
*
|
|
22189
|
-
*
|
|
22190
|
-
* Note that for this to work the origin must not be
|
|
22191
|
-
* using "Access-Control-Allow-Origin" with a wildcard,
|
|
22192
|
-
* and also must set "Access-Control-Allow-Credentials"
|
|
22193
|
-
* to "true".
|
|
22047
|
+
* Compose querystring to append to req.url
|
|
22194
22048
|
*
|
|
22195
|
-
* @api
|
|
22049
|
+
* @api private
|
|
22196
22050
|
*/
|
|
22197
22051
|
|
|
22198
|
-
Request.prototype.
|
|
22199
|
-
|
|
22200
|
-
|
|
22052
|
+
Request.prototype._appendQueryString = function(){
|
|
22053
|
+
var query = this._query.join('&');
|
|
22054
|
+
if (query) {
|
|
22055
|
+
this.url += ~this.url.indexOf('?')
|
|
22056
|
+
? '&' + query
|
|
22057
|
+
: '?' + query;
|
|
22058
|
+
}
|
|
22201
22059
|
};
|
|
22202
22060
|
|
|
22203
22061
|
/**
|
|
@@ -22212,7 +22070,6 @@ Request.prototype.withCredentials = function(){
|
|
|
22212
22070
|
Request.prototype.end = function(fn){
|
|
22213
22071
|
var self = this;
|
|
22214
22072
|
var xhr = this.xhr = request.getXHR();
|
|
22215
|
-
var query = this._query.join('&');
|
|
22216
22073
|
var timeout = this._timeout;
|
|
22217
22074
|
var data = this._formData || this._data;
|
|
22218
22075
|
|
|
@@ -22229,8 +22086,8 @@ Request.prototype.end = function(fn){
|
|
|
22229
22086
|
try { status = xhr.status } catch(e) { status = 0; }
|
|
22230
22087
|
|
|
22231
22088
|
if (0 == status) {
|
|
22232
|
-
if (self.timedout) return self.
|
|
22233
|
-
if (self.
|
|
22089
|
+
if (self.timedout) return self._timeoutError();
|
|
22090
|
+
if (self._aborted) return;
|
|
22234
22091
|
return self.crossDomainError();
|
|
22235
22092
|
}
|
|
22236
22093
|
self.emit('end');
|
|
@@ -22266,24 +22123,23 @@ Request.prototype.end = function(fn){
|
|
|
22266
22123
|
}
|
|
22267
22124
|
|
|
22268
22125
|
// querystring
|
|
22269
|
-
|
|
22270
|
-
query = request.serializeObject(query);
|
|
22271
|
-
this.url += ~this.url.indexOf('?')
|
|
22272
|
-
? '&' + query
|
|
22273
|
-
: '?' + query;
|
|
22274
|
-
}
|
|
22126
|
+
this._appendQueryString();
|
|
22275
22127
|
|
|
22276
22128
|
// initiate request
|
|
22277
|
-
|
|
22129
|
+
if (this.username && this.password) {
|
|
22130
|
+
xhr.open(this.method, this.url, true, this.username, this.password);
|
|
22131
|
+
} else {
|
|
22132
|
+
xhr.open(this.method, this.url, true);
|
|
22133
|
+
}
|
|
22278
22134
|
|
|
22279
22135
|
// CORS
|
|
22280
22136
|
if (this._withCredentials) xhr.withCredentials = true;
|
|
22281
22137
|
|
|
22282
22138
|
// body
|
|
22283
|
-
if ('GET' != this.method && 'HEAD' != this.method && 'string' != typeof data && !
|
|
22139
|
+
if ('GET' != this.method && 'HEAD' != this.method && 'string' != typeof data && !this._isHost(data)) {
|
|
22284
22140
|
// serialize stuff
|
|
22285
|
-
var contentType = this.
|
|
22286
|
-
var serialize = this.
|
|
22141
|
+
var contentType = this._header['content-type'];
|
|
22142
|
+
var serialize = this._serializer || request.serialize[contentType ? contentType.split(';')[0] : ''];
|
|
22287
22143
|
if (!serialize && isJSON(contentType)) serialize = request.serialize['application/json'];
|
|
22288
22144
|
if (serialize) data = serialize(data);
|
|
22289
22145
|
}
|
|
@@ -22294,6 +22150,10 @@ Request.prototype.end = function(fn){
|
|
|
22294
22150
|
xhr.setRequestHeader(field, this.header[field]);
|
|
22295
22151
|
}
|
|
22296
22152
|
|
|
22153
|
+
if (this._responseType) {
|
|
22154
|
+
xhr.responseType = this._responseType;
|
|
22155
|
+
}
|
|
22156
|
+
|
|
22297
22157
|
// send stuff
|
|
22298
22158
|
this.emit('request', this);
|
|
22299
22159
|
|
|
@@ -22303,19 +22163,6 @@ Request.prototype.end = function(fn){
|
|
|
22303
22163
|
return this;
|
|
22304
22164
|
};
|
|
22305
22165
|
|
|
22306
|
-
/**
|
|
22307
|
-
* Faux promise support
|
|
22308
|
-
*
|
|
22309
|
-
* @param {Function} fulfill
|
|
22310
|
-
* @param {Function} reject
|
|
22311
|
-
* @return {Request}
|
|
22312
|
-
*/
|
|
22313
|
-
|
|
22314
|
-
Request.prototype.then = function (fulfill, reject) {
|
|
22315
|
-
return this.end(function(err, res) {
|
|
22316
|
-
err ? reject(err) : fulfill(res);
|
|
22317
|
-
});
|
|
22318
|
-
}
|
|
22319
22166
|
|
|
22320
22167
|
/**
|
|
22321
22168
|
* Expose `Request`.
|
|
@@ -22323,35 +22170,6 @@ Request.prototype.then = function (fulfill, reject) {
|
|
|
22323
22170
|
|
|
22324
22171
|
request.Request = Request;
|
|
22325
22172
|
|
|
22326
|
-
/**
|
|
22327
|
-
* Issue a request:
|
|
22328
|
-
*
|
|
22329
|
-
* Examples:
|
|
22330
|
-
*
|
|
22331
|
-
* request('GET', '/users').end(callback)
|
|
22332
|
-
* request('/users').end(callback)
|
|
22333
|
-
* request('/users', callback)
|
|
22334
|
-
*
|
|
22335
|
-
* @param {String} method
|
|
22336
|
-
* @param {String|Function} url or callback
|
|
22337
|
-
* @return {Request}
|
|
22338
|
-
* @api public
|
|
22339
|
-
*/
|
|
22340
|
-
|
|
22341
|
-
function request(method, url) {
|
|
22342
|
-
// callback
|
|
22343
|
-
if ('function' == typeof url) {
|
|
22344
|
-
return new Request('GET', method).end(url);
|
|
22345
|
-
}
|
|
22346
|
-
|
|
22347
|
-
// url first
|
|
22348
|
-
if (1 == arguments.length) {
|
|
22349
|
-
return new Request('GET', method);
|
|
22350
|
-
}
|
|
22351
|
-
|
|
22352
|
-
return new Request(method, url);
|
|
22353
|
-
}
|
|
22354
|
-
|
|
22355
22173
|
/**
|
|
22356
22174
|
* GET `url` with optional callback `fn(res)`.
|
|
22357
22175
|
*
|
|
@@ -22389,7 +22207,25 @@ request.head = function(url, data, fn){
|
|
|
22389
22207
|
};
|
|
22390
22208
|
|
|
22391
22209
|
/**
|
|
22392
|
-
*
|
|
22210
|
+
* OPTIONS query to `url` with optional callback `fn(res)`.
|
|
22211
|
+
*
|
|
22212
|
+
* @param {String} url
|
|
22213
|
+
* @param {Mixed|Function} data or fn
|
|
22214
|
+
* @param {Function} fn
|
|
22215
|
+
* @return {Request}
|
|
22216
|
+
* @api public
|
|
22217
|
+
*/
|
|
22218
|
+
|
|
22219
|
+
request.options = function(url, data, fn){
|
|
22220
|
+
var req = request('OPTIONS', url);
|
|
22221
|
+
if ('function' == typeof data) fn = data, data = null;
|
|
22222
|
+
if (data) req.send(data);
|
|
22223
|
+
if (fn) req.end(fn);
|
|
22224
|
+
return req;
|
|
22225
|
+
};
|
|
22226
|
+
|
|
22227
|
+
/**
|
|
22228
|
+
* DELETE `url` with optional callback `fn(res)`.
|
|
22393
22229
|
*
|
|
22394
22230
|
* @param {String} url
|
|
22395
22231
|
* @param {Function} fn
|
|
@@ -22460,13 +22296,404 @@ request.put = function(url, data, fn){
|
|
|
22460
22296
|
return req;
|
|
22461
22297
|
};
|
|
22462
22298
|
|
|
22299
|
+
},{"./is-object":50,"./request":52,"./request-base":51,"emitter":40,"reduce":47}],50:[function(require,module,exports){
|
|
22463
22300
|
/**
|
|
22464
|
-
*
|
|
22301
|
+
* Check if `obj` is an object.
|
|
22302
|
+
*
|
|
22303
|
+
* @param {Object} obj
|
|
22304
|
+
* @return {Boolean}
|
|
22305
|
+
* @api private
|
|
22306
|
+
*/
|
|
22307
|
+
|
|
22308
|
+
function isObject(obj) {
|
|
22309
|
+
return null !== obj && 'object' === typeof obj;
|
|
22310
|
+
}
|
|
22311
|
+
|
|
22312
|
+
module.exports = isObject;
|
|
22313
|
+
|
|
22314
|
+
},{}],51:[function(require,module,exports){
|
|
22315
|
+
/**
|
|
22316
|
+
* Module of mixed-in functions shared between node and client code
|
|
22317
|
+
*/
|
|
22318
|
+
var isObject = require('./is-object');
|
|
22319
|
+
|
|
22320
|
+
/**
|
|
22321
|
+
* Clear previous timeout.
|
|
22322
|
+
*
|
|
22323
|
+
* @return {Request} for chaining
|
|
22324
|
+
* @api public
|
|
22325
|
+
*/
|
|
22326
|
+
|
|
22327
|
+
exports.clearTimeout = function _clearTimeout(){
|
|
22328
|
+
this._timeout = 0;
|
|
22329
|
+
clearTimeout(this._timer);
|
|
22330
|
+
return this;
|
|
22331
|
+
};
|
|
22332
|
+
|
|
22333
|
+
/**
|
|
22334
|
+
* Override default response body parser
|
|
22335
|
+
*
|
|
22336
|
+
* This function will be called to convert incoming data into request.body
|
|
22337
|
+
*
|
|
22338
|
+
* @param {Function}
|
|
22339
|
+
* @api public
|
|
22340
|
+
*/
|
|
22341
|
+
|
|
22342
|
+
exports.parse = function parse(fn){
|
|
22343
|
+
this._parser = fn;
|
|
22344
|
+
return this;
|
|
22345
|
+
};
|
|
22346
|
+
|
|
22347
|
+
/**
|
|
22348
|
+
* Override default request body serializer
|
|
22349
|
+
*
|
|
22350
|
+
* This function will be called to convert data set via .send or .attach into payload to send
|
|
22351
|
+
*
|
|
22352
|
+
* @param {Function}
|
|
22353
|
+
* @api public
|
|
22354
|
+
*/
|
|
22355
|
+
|
|
22356
|
+
exports.serialize = function serialize(fn){
|
|
22357
|
+
this._serializer = fn;
|
|
22358
|
+
return this;
|
|
22359
|
+
};
|
|
22360
|
+
|
|
22361
|
+
/**
|
|
22362
|
+
* Set timeout to `ms`.
|
|
22363
|
+
*
|
|
22364
|
+
* @param {Number} ms
|
|
22365
|
+
* @return {Request} for chaining
|
|
22366
|
+
* @api public
|
|
22367
|
+
*/
|
|
22368
|
+
|
|
22369
|
+
exports.timeout = function timeout(ms){
|
|
22370
|
+
this._timeout = ms;
|
|
22371
|
+
return this;
|
|
22372
|
+
};
|
|
22373
|
+
|
|
22374
|
+
/**
|
|
22375
|
+
* Promise support
|
|
22376
|
+
*
|
|
22377
|
+
* @param {Function} resolve
|
|
22378
|
+
* @param {Function} reject
|
|
22379
|
+
* @return {Request}
|
|
22380
|
+
*/
|
|
22381
|
+
|
|
22382
|
+
exports.then = function then(resolve, reject) {
|
|
22383
|
+
if (!this._fullfilledPromise) {
|
|
22384
|
+
var self = this;
|
|
22385
|
+
this._fullfilledPromise = new Promise(function(innerResolve, innerReject){
|
|
22386
|
+
self.end(function(err, res){
|
|
22387
|
+
if (err) innerReject(err); else innerResolve(res);
|
|
22388
|
+
});
|
|
22389
|
+
});
|
|
22390
|
+
}
|
|
22391
|
+
return this._fullfilledPromise.then(resolve, reject);
|
|
22392
|
+
}
|
|
22393
|
+
|
|
22394
|
+
/**
|
|
22395
|
+
* Allow for extension
|
|
22396
|
+
*/
|
|
22397
|
+
|
|
22398
|
+
exports.use = function use(fn) {
|
|
22399
|
+
fn(this);
|
|
22400
|
+
return this;
|
|
22401
|
+
}
|
|
22402
|
+
|
|
22403
|
+
|
|
22404
|
+
/**
|
|
22405
|
+
* Get request header `field`.
|
|
22406
|
+
* Case-insensitive.
|
|
22407
|
+
*
|
|
22408
|
+
* @param {String} field
|
|
22409
|
+
* @return {String}
|
|
22410
|
+
* @api public
|
|
22411
|
+
*/
|
|
22412
|
+
|
|
22413
|
+
exports.get = function(field){
|
|
22414
|
+
return this._header[field.toLowerCase()];
|
|
22415
|
+
};
|
|
22416
|
+
|
|
22417
|
+
/**
|
|
22418
|
+
* Get case-insensitive header `field` value.
|
|
22419
|
+
* This is a deprecated internal API. Use `.get(field)` instead.
|
|
22420
|
+
*
|
|
22421
|
+
* (getHeader is no longer used internally by the superagent code base)
|
|
22422
|
+
*
|
|
22423
|
+
* @param {String} field
|
|
22424
|
+
* @return {String}
|
|
22425
|
+
* @api private
|
|
22426
|
+
* @deprecated
|
|
22427
|
+
*/
|
|
22428
|
+
|
|
22429
|
+
exports.getHeader = exports.get;
|
|
22430
|
+
|
|
22431
|
+
/**
|
|
22432
|
+
* Set header `field` to `val`, or multiple fields with one object.
|
|
22433
|
+
* Case-insensitive.
|
|
22434
|
+
*
|
|
22435
|
+
* Examples:
|
|
22436
|
+
*
|
|
22437
|
+
* req.get('/')
|
|
22438
|
+
* .set('Accept', 'application/json')
|
|
22439
|
+
* .set('X-API-Key', 'foobar')
|
|
22440
|
+
* .end(callback);
|
|
22441
|
+
*
|
|
22442
|
+
* req.get('/')
|
|
22443
|
+
* .set({ Accept: 'application/json', 'X-API-Key': 'foobar' })
|
|
22444
|
+
* .end(callback);
|
|
22445
|
+
*
|
|
22446
|
+
* @param {String|Object} field
|
|
22447
|
+
* @param {String} val
|
|
22448
|
+
* @return {Request} for chaining
|
|
22449
|
+
* @api public
|
|
22450
|
+
*/
|
|
22451
|
+
|
|
22452
|
+
exports.set = function(field, val){
|
|
22453
|
+
if (isObject(field)) {
|
|
22454
|
+
for (var key in field) {
|
|
22455
|
+
this.set(key, field[key]);
|
|
22456
|
+
}
|
|
22457
|
+
return this;
|
|
22458
|
+
}
|
|
22459
|
+
this._header[field.toLowerCase()] = val;
|
|
22460
|
+
this.header[field] = val;
|
|
22461
|
+
return this;
|
|
22462
|
+
};
|
|
22463
|
+
|
|
22464
|
+
/**
|
|
22465
|
+
* Remove header `field`.
|
|
22466
|
+
* Case-insensitive.
|
|
22467
|
+
*
|
|
22468
|
+
* Example:
|
|
22469
|
+
*
|
|
22470
|
+
* req.get('/')
|
|
22471
|
+
* .unset('User-Agent')
|
|
22472
|
+
* .end(callback);
|
|
22473
|
+
*
|
|
22474
|
+
* @param {String} field
|
|
22475
|
+
*/
|
|
22476
|
+
exports.unset = function(field){
|
|
22477
|
+
delete this._header[field.toLowerCase()];
|
|
22478
|
+
delete this.header[field];
|
|
22479
|
+
return this;
|
|
22480
|
+
};
|
|
22481
|
+
|
|
22482
|
+
/**
|
|
22483
|
+
* Write the field `name` and `val` for "multipart/form-data"
|
|
22484
|
+
* request bodies.
|
|
22485
|
+
*
|
|
22486
|
+
* ``` js
|
|
22487
|
+
* request.post('/upload')
|
|
22488
|
+
* .field('foo', 'bar')
|
|
22489
|
+
* .end(callback);
|
|
22490
|
+
* ```
|
|
22491
|
+
*
|
|
22492
|
+
* @param {String} name
|
|
22493
|
+
* @param {String|Blob|File|Buffer|fs.ReadStream} val
|
|
22494
|
+
* @return {Request} for chaining
|
|
22495
|
+
* @api public
|
|
22496
|
+
*/
|
|
22497
|
+
exports.field = function(name, val) {
|
|
22498
|
+
this._getFormData().append(name, val);
|
|
22499
|
+
return this;
|
|
22500
|
+
};
|
|
22501
|
+
|
|
22502
|
+
/**
|
|
22503
|
+
* Abort the request, and clear potential timeout.
|
|
22504
|
+
*
|
|
22505
|
+
* @return {Request}
|
|
22506
|
+
* @api public
|
|
22507
|
+
*/
|
|
22508
|
+
exports.abort = function(){
|
|
22509
|
+
if (this._aborted) {
|
|
22510
|
+
return this;
|
|
22511
|
+
}
|
|
22512
|
+
this._aborted = true;
|
|
22513
|
+
this.xhr && this.xhr.abort(); // browser
|
|
22514
|
+
this.req && this.req.abort(); // node
|
|
22515
|
+
this.clearTimeout();
|
|
22516
|
+
this.emit('abort');
|
|
22517
|
+
return this;
|
|
22518
|
+
};
|
|
22519
|
+
|
|
22520
|
+
/**
|
|
22521
|
+
* Enable transmission of cookies with x-domain requests.
|
|
22522
|
+
*
|
|
22523
|
+
* Note that for this to work the origin must not be
|
|
22524
|
+
* using "Access-Control-Allow-Origin" with a wildcard,
|
|
22525
|
+
* and also must set "Access-Control-Allow-Credentials"
|
|
22526
|
+
* to "true".
|
|
22527
|
+
*
|
|
22528
|
+
* @api public
|
|
22529
|
+
*/
|
|
22530
|
+
|
|
22531
|
+
exports.withCredentials = function(){
|
|
22532
|
+
// This is browser-only functionality. Node side is no-op.
|
|
22533
|
+
this._withCredentials = true;
|
|
22534
|
+
return this;
|
|
22535
|
+
};
|
|
22536
|
+
|
|
22537
|
+
/**
|
|
22538
|
+
* Set the max redirects to `n`. Does noting in browser XHR implementation.
|
|
22539
|
+
*
|
|
22540
|
+
* @param {Number} n
|
|
22541
|
+
* @return {Request} for chaining
|
|
22542
|
+
* @api public
|
|
22543
|
+
*/
|
|
22544
|
+
|
|
22545
|
+
exports.redirects = function(n){
|
|
22546
|
+
this._maxRedirects = n;
|
|
22547
|
+
return this;
|
|
22548
|
+
};
|
|
22549
|
+
|
|
22550
|
+
/**
|
|
22551
|
+
* Convert to a plain javascript object (not JSON string) of scalar properties.
|
|
22552
|
+
* Note as this method is designed to return a useful non-this value,
|
|
22553
|
+
* it cannot be chained.
|
|
22554
|
+
*
|
|
22555
|
+
* @return {Object} describing method, url, and data of this request
|
|
22556
|
+
* @api public
|
|
22557
|
+
*/
|
|
22558
|
+
|
|
22559
|
+
exports.toJSON = function(){
|
|
22560
|
+
return {
|
|
22561
|
+
method: this.method,
|
|
22562
|
+
url: this.url,
|
|
22563
|
+
data: this._data
|
|
22564
|
+
};
|
|
22565
|
+
};
|
|
22566
|
+
|
|
22567
|
+
/**
|
|
22568
|
+
* Check if `obj` is a host object,
|
|
22569
|
+
* we don't want to serialize these :)
|
|
22570
|
+
*
|
|
22571
|
+
* TODO: future proof, move to compoent land
|
|
22572
|
+
*
|
|
22573
|
+
* @param {Object} obj
|
|
22574
|
+
* @return {Boolean}
|
|
22575
|
+
* @api private
|
|
22576
|
+
*/
|
|
22577
|
+
|
|
22578
|
+
exports._isHost = function _isHost(obj) {
|
|
22579
|
+
var str = {}.toString.call(obj);
|
|
22580
|
+
|
|
22581
|
+
switch (str) {
|
|
22582
|
+
case '[object File]':
|
|
22583
|
+
case '[object Blob]':
|
|
22584
|
+
case '[object FormData]':
|
|
22585
|
+
return true;
|
|
22586
|
+
default:
|
|
22587
|
+
return false;
|
|
22588
|
+
}
|
|
22589
|
+
}
|
|
22590
|
+
|
|
22591
|
+
/**
|
|
22592
|
+
* Send `data` as the request body, defaulting the `.type()` to "json" when
|
|
22593
|
+
* an object is given.
|
|
22594
|
+
*
|
|
22595
|
+
* Examples:
|
|
22596
|
+
*
|
|
22597
|
+
* // manual json
|
|
22598
|
+
* request.post('/user')
|
|
22599
|
+
* .type('json')
|
|
22600
|
+
* .send('{"name":"tj"}')
|
|
22601
|
+
* .end(callback)
|
|
22602
|
+
*
|
|
22603
|
+
* // auto json
|
|
22604
|
+
* request.post('/user')
|
|
22605
|
+
* .send({ name: 'tj' })
|
|
22606
|
+
* .end(callback)
|
|
22607
|
+
*
|
|
22608
|
+
* // manual x-www-form-urlencoded
|
|
22609
|
+
* request.post('/user')
|
|
22610
|
+
* .type('form')
|
|
22611
|
+
* .send('name=tj')
|
|
22612
|
+
* .end(callback)
|
|
22613
|
+
*
|
|
22614
|
+
* // auto x-www-form-urlencoded
|
|
22615
|
+
* request.post('/user')
|
|
22616
|
+
* .type('form')
|
|
22617
|
+
* .send({ name: 'tj' })
|
|
22618
|
+
* .end(callback)
|
|
22619
|
+
*
|
|
22620
|
+
* // defaults to x-www-form-urlencoded
|
|
22621
|
+
* request.post('/user')
|
|
22622
|
+
* .send('name=tobi')
|
|
22623
|
+
* .send('species=ferret')
|
|
22624
|
+
* .end(callback)
|
|
22625
|
+
*
|
|
22626
|
+
* @param {String|Object} data
|
|
22627
|
+
* @return {Request} for chaining
|
|
22628
|
+
* @api public
|
|
22465
22629
|
*/
|
|
22466
22630
|
|
|
22631
|
+
exports.send = function(data){
|
|
22632
|
+
var obj = isObject(data);
|
|
22633
|
+
var type = this._header['content-type'];
|
|
22634
|
+
|
|
22635
|
+
// merge
|
|
22636
|
+
if (obj && isObject(this._data)) {
|
|
22637
|
+
for (var key in data) {
|
|
22638
|
+
this._data[key] = data[key];
|
|
22639
|
+
}
|
|
22640
|
+
} else if ('string' == typeof data) {
|
|
22641
|
+
// default to x-www-form-urlencoded
|
|
22642
|
+
if (!type) this.type('form');
|
|
22643
|
+
type = this._header['content-type'];
|
|
22644
|
+
if ('application/x-www-form-urlencoded' == type) {
|
|
22645
|
+
this._data = this._data
|
|
22646
|
+
? this._data + '&' + data
|
|
22647
|
+
: data;
|
|
22648
|
+
} else {
|
|
22649
|
+
this._data = (this._data || '') + data;
|
|
22650
|
+
}
|
|
22651
|
+
} else {
|
|
22652
|
+
this._data = data;
|
|
22653
|
+
}
|
|
22654
|
+
|
|
22655
|
+
if (!obj || this._isHost(data)) return this;
|
|
22656
|
+
|
|
22657
|
+
// default to json
|
|
22658
|
+
if (!type) this.type('json');
|
|
22659
|
+
return this;
|
|
22660
|
+
};
|
|
22661
|
+
|
|
22662
|
+
},{"./is-object":50}],52:[function(require,module,exports){
|
|
22663
|
+
// The node and browser modules expose versions of this with the
|
|
22664
|
+
// appropriate constructor function bound as first argument
|
|
22665
|
+
/**
|
|
22666
|
+
* Issue a request:
|
|
22667
|
+
*
|
|
22668
|
+
* Examples:
|
|
22669
|
+
*
|
|
22670
|
+
* request('GET', '/users').end(callback)
|
|
22671
|
+
* request('/users').end(callback)
|
|
22672
|
+
* request('/users', callback)
|
|
22673
|
+
*
|
|
22674
|
+
* @param {String} method
|
|
22675
|
+
* @param {String|Function} url or callback
|
|
22676
|
+
* @return {Request}
|
|
22677
|
+
* @api public
|
|
22678
|
+
*/
|
|
22679
|
+
|
|
22680
|
+
function request(RequestConstructor, method, url) {
|
|
22681
|
+
// callback
|
|
22682
|
+
if ('function' == typeof url) {
|
|
22683
|
+
return new RequestConstructor('GET', method).end(url);
|
|
22684
|
+
}
|
|
22685
|
+
|
|
22686
|
+
// url first
|
|
22687
|
+
if (2 == arguments.length) {
|
|
22688
|
+
return new RequestConstructor('GET', method);
|
|
22689
|
+
}
|
|
22690
|
+
|
|
22691
|
+
return new RequestConstructor(method, url);
|
|
22692
|
+
}
|
|
22693
|
+
|
|
22467
22694
|
module.exports = request;
|
|
22468
22695
|
|
|
22469
|
-
},{
|
|
22696
|
+
},{}],53:[function(require,module,exports){
|
|
22470
22697
|
/*!
|
|
22471
22698
|
* validate.js 0.9.0
|
|
22472
22699
|
*
|