comprodls-sdk 2.56.0 → 2.58.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 +796 -542
- package/dist/comprodls-sdk.min.js +15 -15
- package/lib/config/index.js +3 -0
- package/lib/services/analytics/index.js +17 -5
- package/lib/services/auth/index.js +52 -17
- package/lib/services/spaces/index.js +27 -19
- package/package.json +1 -1
package/dist/comprodls-sdk.js
CHANGED
|
@@ -193,6 +193,9 @@ exports.REALM_HOSTS = {
|
|
|
193
193
|
ANALYTICS: 'http://internal-dls-global-prod1-1755536919.us-west-2.elb.amazonaws.com/lb-analytics',
|
|
194
194
|
INTEGRATION: 'http://internal-dls-global-prod1-1755536919.us-west-2.elb.amazonaws.com/lb-integrations',
|
|
195
195
|
DRIVE: 'http://internal-dls-global-prod1-1755536919.us-west-2.elb.amazonaws.com/lb-drive'
|
|
196
|
+
},
|
|
197
|
+
DEVELOPMENT: {
|
|
198
|
+
ANALYTICS: 'http://localhost:4000'
|
|
196
199
|
}
|
|
197
200
|
},
|
|
198
201
|
ASGARD: {
|
|
@@ -1139,7 +1142,7 @@ validator.validators.contains = function(value, options) {
|
|
|
1139
1142
|
}
|
|
1140
1143
|
}
|
|
1141
1144
|
};
|
|
1142
|
-
},{"./errors":7,"validate.js":
|
|
1145
|
+
},{"./errors":7,"validate.js":53}],10:[function(require,module,exports){
|
|
1143
1146
|
/*************************************************************************
|
|
1144
1147
|
*
|
|
1145
1148
|
* COMPRO CONFIDENTIAL
|
|
@@ -3428,7 +3431,9 @@ function getQuestionProgressByLearningObjective(questionsArray) {
|
|
|
3428
3431
|
"classid": "string", // required
|
|
3429
3432
|
"status_active": <boolean>,
|
|
3430
3433
|
"status_not_started": <boolean>,
|
|
3431
|
-
"status_expired": <boolean
|
|
3434
|
+
"status_expired": <boolean>,
|
|
3435
|
+
"limit": integer, // Number of entities to be fetched
|
|
3436
|
+
"cursor": "string" // cursor to get next set of assignments
|
|
3432
3437
|
};
|
|
3433
3438
|
*/
|
|
3434
3439
|
function getAllAssignedPathsOfClass(options) {
|
|
@@ -3448,7 +3453,9 @@ function getAllAssignedPathsOfClass(options) {
|
|
|
3448
3453
|
classid: options.classid,
|
|
3449
3454
|
status_not_started: options.status_not_started,
|
|
3450
3455
|
status_active: options.status_active,
|
|
3451
|
-
status_expired: options.status_expired
|
|
3456
|
+
status_expired: options.status_expired,
|
|
3457
|
+
limit: options.limit,
|
|
3458
|
+
cursor: options.cursor
|
|
3452
3459
|
};
|
|
3453
3460
|
|
|
3454
3461
|
// Setup request with URL and Params
|
|
@@ -3460,7 +3467,9 @@ function getAllAssignedPathsOfClass(options) {
|
|
|
3460
3467
|
// setting up traceid
|
|
3461
3468
|
if(self.traceid) { requestAPI.set('X-Amzn-Trace-Id', self.traceid); }
|
|
3462
3469
|
|
|
3463
|
-
requestAPI
|
|
3470
|
+
requestAPI
|
|
3471
|
+
.agent(keepaliveAgent)
|
|
3472
|
+
.end(function (error, response) {
|
|
3464
3473
|
if(error) {
|
|
3465
3474
|
err = new DLSError(helpers.errors.ERROR_TYPES.API_ERROR, error);
|
|
3466
3475
|
dfd.reject(err);
|
|
@@ -3537,7 +3546,9 @@ function getAssignedPathAnalytics(options) {
|
|
|
3537
3546
|
"status_not_started": <boolean>,
|
|
3538
3547
|
"status_expired": <boolean>,
|
|
3539
3548
|
"progress" : "true/false",
|
|
3540
|
-
"group" : "true/false"
|
|
3549
|
+
"group" : "true/false",
|
|
3550
|
+
"limit": integer, // Number of entities to be fetched
|
|
3551
|
+
"cursor": "string" // cursor to get next set of assignments
|
|
3541
3552
|
};
|
|
3542
3553
|
*/
|
|
3543
3554
|
function getMyAssignedPathsOfClass(options) {
|
|
@@ -3559,6 +3570,8 @@ function getMyAssignedPathsOfClass(options) {
|
|
|
3559
3570
|
if(options.status_not_started) { queryParams.status_not_started = options.status_not_started; }
|
|
3560
3571
|
if(options.status_active) { queryParams.status_active = options.status_active; }
|
|
3561
3572
|
if(options.status_expired) { queryParams.status_expired = options.status_expired; }
|
|
3573
|
+
if(options.limit) { queryParams.limit = options.limit; }
|
|
3574
|
+
if(options.cursor) { queryParams.cursor = options.cursor; }
|
|
3562
3575
|
|
|
3563
3576
|
// Setup request with URL and Params
|
|
3564
3577
|
var requestAPI = request.get(url).query(queryParams);
|
|
@@ -3568,7 +3581,9 @@ function getMyAssignedPathsOfClass(options) {
|
|
|
3568
3581
|
// setting up traceid
|
|
3569
3582
|
if(self.traceid) { requestAPI.set('X-Amzn-Trace-Id', self.traceid); }
|
|
3570
3583
|
|
|
3571
|
-
requestAPI
|
|
3584
|
+
requestAPI
|
|
3585
|
+
.agent(keepaliveAgent)
|
|
3586
|
+
.end(function (error, response) {
|
|
3572
3587
|
if(error) {
|
|
3573
3588
|
err = new DLSError(helpers.errors.ERROR_TYPES.API_ERROR, error);
|
|
3574
3589
|
dfd.reject(err);
|
|
@@ -5030,7 +5045,9 @@ function getUserClasses(options) {
|
|
|
5030
5045
|
requestAPI = helpers.api.setupAPIToken(requestAPI, self.token);
|
|
5031
5046
|
|
|
5032
5047
|
// Call GET ALL USER Api
|
|
5033
|
-
requestAPI
|
|
5048
|
+
requestAPI
|
|
5049
|
+
.agent(keepaliveAgent)
|
|
5050
|
+
.end(function(err, response) {
|
|
5034
5051
|
if(err) {
|
|
5035
5052
|
err = new DLSError(helpers.errors.ERROR_TYPES.API_ERROR, err);
|
|
5036
5053
|
dfd.reject(err);
|
|
@@ -5530,7 +5547,9 @@ function getAllClasses(options) {
|
|
|
5530
5547
|
requestAPI = helpers.api.setupAPIToken(requestAPI, self.token);
|
|
5531
5548
|
|
|
5532
5549
|
//Call GET ALL USER Api
|
|
5533
|
-
requestAPI
|
|
5550
|
+
requestAPI
|
|
5551
|
+
.agent(keepaliveAgent)
|
|
5552
|
+
.end(function(err, response) {
|
|
5534
5553
|
if(err) {
|
|
5535
5554
|
var esErrOptions = { type: helpers.errors.ERROR_TYPES.API_ERROR, err: err };
|
|
5536
5555
|
var error = converter.convertElasticsearchErrResponse(esErrOptions);
|
|
@@ -5575,6 +5594,10 @@ function getAllClasses(options) {
|
|
|
5575
5594
|
teacherCount: classEntity.teacherCount
|
|
5576
5595
|
};
|
|
5577
5596
|
|
|
5597
|
+
if(classEntity.limits){
|
|
5598
|
+
classObj.limits = classEntity.limits;
|
|
5599
|
+
}
|
|
5600
|
+
|
|
5578
5601
|
/**
|
|
5579
5602
|
* Add class-tag association specific fields
|
|
5580
5603
|
*/
|
|
@@ -6011,7 +6034,9 @@ function enrollUsertoClass(options) {
|
|
|
6011
6034
|
requestAPI = helpers.api.setupAPIToken(requestAPI, self.token);
|
|
6012
6035
|
|
|
6013
6036
|
//Call GET Product by it's code Api
|
|
6014
|
-
requestAPI
|
|
6037
|
+
requestAPI
|
|
6038
|
+
.agent(keepaliveAgent)
|
|
6039
|
+
.end(function(err, response) {
|
|
6015
6040
|
if(err) {
|
|
6016
6041
|
err = new DLSError(helpers.errors.ERROR_TYPES.API_ERROR, err);
|
|
6017
6042
|
dfd.reject(err);
|
|
@@ -6064,7 +6089,9 @@ function enrollSelftoClass(options) {
|
|
|
6064
6089
|
requestAPI = helpers.api.setupAPIToken(requestAPI, self.token);
|
|
6065
6090
|
|
|
6066
6091
|
//Call GET Product by it's code Api
|
|
6067
|
-
requestAPI
|
|
6092
|
+
requestAPI
|
|
6093
|
+
.agent(keepaliveAgent)
|
|
6094
|
+
.end(function(err, response) {
|
|
6068
6095
|
if(err) {
|
|
6069
6096
|
err = new DLSError(helpers.errors.ERROR_TYPES.API_ERROR, err);
|
|
6070
6097
|
dfd.reject(err);
|
|
@@ -6120,7 +6147,9 @@ function enrollMultiUserstoClass(options) {
|
|
|
6120
6147
|
requestAPI = helpers.api.setupAPIToken(requestAPI, self.token);
|
|
6121
6148
|
|
|
6122
6149
|
//Call GET Product by it's code Api
|
|
6123
|
-
requestAPI
|
|
6150
|
+
requestAPI
|
|
6151
|
+
.agent(keepaliveAgent)
|
|
6152
|
+
.end(function(err, response) {
|
|
6124
6153
|
if(err) {
|
|
6125
6154
|
err = new DLSError(helpers.errors.ERROR_TYPES.API_ERROR, err);
|
|
6126
6155
|
dfd.reject(err);
|
|
@@ -6265,6 +6294,7 @@ function encodeURLParameter(options) {
|
|
|
6265
6294
|
* ext_data: {} // Optional
|
|
6266
6295
|
* analyticsharingmodel: '' // Optional - Valid values: ['NOINHERIT_SYNCBACK']
|
|
6267
6296
|
* analytics_score_aggregation_type: '' // Optional - Valid values: ['best'/'first'/'last']
|
|
6297
|
+
* limits: {"los": number, "students": number} // Optional field
|
|
6268
6298
|
* }
|
|
6269
6299
|
*/
|
|
6270
6300
|
function createClass(options) {
|
|
@@ -6302,7 +6332,9 @@ function createClass(options) {
|
|
|
6302
6332
|
//Setup token in Authorization header
|
|
6303
6333
|
requestAPI = helpers.api.setupAPIToken(requestAPI, self.token);
|
|
6304
6334
|
|
|
6305
|
-
requestAPI
|
|
6335
|
+
requestAPI
|
|
6336
|
+
.agent(keepaliveAgent)
|
|
6337
|
+
.end(function(err, response) {
|
|
6306
6338
|
if(err) {
|
|
6307
6339
|
err = new DLSError(helpers.errors.ERROR_TYPES.API_ERROR, err);
|
|
6308
6340
|
dfd.reject(err);
|
|
@@ -6329,6 +6361,7 @@ function createClass(options) {
|
|
|
6329
6361
|
// description: '', //Optional field
|
|
6330
6362
|
// ext_data: '' //Optional field
|
|
6331
6363
|
// analytics_score_aggregation_type: '' // Optional - Valid values: ['best'/'first'/'last']
|
|
6364
|
+
// limits: {"los": number, "students": number} // Optional field
|
|
6332
6365
|
//}
|
|
6333
6366
|
function updateClass(options) {
|
|
6334
6367
|
var self = this;
|
|
@@ -6354,7 +6387,9 @@ function updateClass(options) {
|
|
|
6354
6387
|
//Setup token in Authorization header
|
|
6355
6388
|
requestAPI = helpers.api.setupAPIToken(requestAPI, self.token);
|
|
6356
6389
|
|
|
6357
|
-
requestAPI
|
|
6390
|
+
requestAPI
|
|
6391
|
+
.agent(keepaliveAgent)
|
|
6392
|
+
.end(function(err, response) {
|
|
6358
6393
|
if(err) {
|
|
6359
6394
|
err = new DLSError(helpers.errors.ERROR_TYPES.API_ERROR, err);
|
|
6360
6395
|
dfd.reject(err);
|
|
@@ -6388,6 +6423,7 @@ function updateClass(options) {
|
|
|
6388
6423
|
"model": "STRICT",
|
|
6389
6424
|
"analyticsharingmodel":"NOINHERIT_SYNCBACK" // optional
|
|
6390
6425
|
"analytics_score_aggregation_type":"first/best/last" // optional
|
|
6426
|
+
limits: {los: number, students: number} // Optional field
|
|
6391
6427
|
"owner": {
|
|
6392
6428
|
"userid": "string" //Mandatory if model is 'STRICT'
|
|
6393
6429
|
},
|
|
@@ -6432,6 +6468,7 @@ function updateClass(options) {
|
|
|
6432
6468
|
"analyticsharingmodel": true,
|
|
6433
6469
|
"analytics_score_aggregation_type": true,
|
|
6434
6470
|
"ext_data": true,
|
|
6471
|
+
"limits": true,
|
|
6435
6472
|
"advanced": {
|
|
6436
6473
|
"students": [
|
|
6437
6474
|
{
|
|
@@ -6465,7 +6502,8 @@ function updateClass(options) {
|
|
|
6465
6502
|
],
|
|
6466
6503
|
"products": [ { "productcode": "string" } ],
|
|
6467
6504
|
"analyticsharingmodel": "string" // Valid values: ['NOINHERIT_SYNCBACK']
|
|
6468
|
-
"analytics_score_aggregation_type": "string" // Valid values: ['best', 'first', 'last']
|
|
6505
|
+
"analytics_score_aggregation_type": "string", // Valid values: ['best', 'first', 'last']
|
|
6506
|
+
"limits": {los: number, students: number} // Optional field
|
|
6469
6507
|
}
|
|
6470
6508
|
}
|
|
6471
6509
|
}
|
|
@@ -6498,7 +6536,9 @@ function createMultipleClasses(options) {
|
|
|
6498
6536
|
//Setup token in Authorization header
|
|
6499
6537
|
requestAPI = helpers.api.setupAPIToken(requestAPI, self.token);
|
|
6500
6538
|
|
|
6501
|
-
requestAPI
|
|
6539
|
+
requestAPI
|
|
6540
|
+
.agent(keepaliveAgent)
|
|
6541
|
+
.end(function (err, response) {
|
|
6502
6542
|
if (err) {
|
|
6503
6543
|
err = new DLSError(helpers.errors.ERROR_TYPES.API_ERROR, err);
|
|
6504
6544
|
dfd.reject(err);
|
|
@@ -6675,12 +6715,18 @@ function deleteAssignedPath(options) {
|
|
|
6675
6715
|
options = {
|
|
6676
6716
|
classid: 'string' //mandatory
|
|
6677
6717
|
assignedpathid: 'string' //mandatory
|
|
6678
|
-
data:
|
|
6679
|
-
|
|
6680
|
-
|
|
6681
|
-
|
|
6682
|
-
|
|
6683
|
-
|
|
6718
|
+
data: {
|
|
6719
|
+
title: 'string' //optional
|
|
6720
|
+
startdate: 'string' //optional
|
|
6721
|
+
duedate: 'string' //optional
|
|
6722
|
+
items: [ //optional
|
|
6723
|
+
{
|
|
6724
|
+
item-code: 'string', //mandatory
|
|
6725
|
+
item_type: 'string', //mandatory, ['dls-internal','external']
|
|
6726
|
+
dls_product_code: 'string' //mandatory only if item_type is 'dls-internal'
|
|
6727
|
+
}
|
|
6728
|
+
]
|
|
6729
|
+
}
|
|
6684
6730
|
}
|
|
6685
6731
|
*/
|
|
6686
6732
|
function updateAssignedPath(options) {
|
|
@@ -6703,7 +6749,9 @@ function updateAssignedPath(options) {
|
|
|
6703
6749
|
//Setup token in Authorization header
|
|
6704
6750
|
requestAPI = helpers.api.setupAPIToken(requestAPI, self.token);
|
|
6705
6751
|
|
|
6706
|
-
requestAPI
|
|
6752
|
+
requestAPI
|
|
6753
|
+
.agent(keepaliveAgent)
|
|
6754
|
+
.end(function (error, response) {
|
|
6707
6755
|
if(error) {
|
|
6708
6756
|
err = new DLSError(helpers.errors.ERROR_TYPES.API_ERROR, error);
|
|
6709
6757
|
dfd.reject(err);
|
|
@@ -7465,7 +7513,9 @@ function cloneClass(options) {
|
|
|
7465
7513
|
//Setup token in Authorization header
|
|
7466
7514
|
requestAPI = helpers.api.setupAPIToken(requestAPI, self.token);
|
|
7467
7515
|
|
|
7468
|
-
requestAPI
|
|
7516
|
+
requestAPI
|
|
7517
|
+
.agent(keepaliveAgent)
|
|
7518
|
+
.end(function(err, response) {
|
|
7469
7519
|
if(err) {
|
|
7470
7520
|
err = new DLSError(helpers.errors.ERROR_TYPES.API_ERROR, err);
|
|
7471
7521
|
dfd.reject(err);
|
|
@@ -13561,26 +13611,34 @@ function provisionBulkSpaces(options) {
|
|
|
13561
13611
|
* *startdate: <epoch>,
|
|
13562
13612
|
* *enddate: <epoch>,
|
|
13563
13613
|
* description: 'string',
|
|
13564
|
-
* ext_data: {}
|
|
13614
|
+
* ext_data: {},
|
|
13615
|
+
* limits: {
|
|
13616
|
+
* *los: 0,
|
|
13617
|
+
* *students: 0
|
|
13618
|
+
* }
|
|
13619
|
+
* },
|
|
13620
|
+
* checkLimits: {
|
|
13621
|
+
* student: 0,
|
|
13622
|
+
* teacher: 0
|
|
13623
|
+
* },
|
|
13624
|
+
* clone_settings: {
|
|
13625
|
+
* *src_ext_classid: 'string',
|
|
13626
|
+
* products: boolean,
|
|
13627
|
+
* assigned_paths: boolean,
|
|
13628
|
+
* advanced: {
|
|
13629
|
+
* assigned_paths: [ //length > 0 if assigned_paths flag is true
|
|
13630
|
+
* {
|
|
13631
|
+
* *ext_assignedpathid: 'string',
|
|
13632
|
+
* *assigned_path_id: 'string',
|
|
13633
|
+
* startdate: 0,
|
|
13634
|
+
* *duedate: 0
|
|
13635
|
+
* },
|
|
13636
|
+
* ],
|
|
13637
|
+
* products: [
|
|
13638
|
+
* { *productcode: 'string' },
|
|
13639
|
+
* ]
|
|
13640
|
+
* }
|
|
13565
13641
|
* }
|
|
13566
|
-
* clone_settings: {
|
|
13567
|
-
* *src_ext_classid: 'string',
|
|
13568
|
-
* products: boolean,
|
|
13569
|
-
* assigned_paths: boolean,
|
|
13570
|
-
* advanced: {
|
|
13571
|
-
* assigned_paths: [ //length > 0 if assigned_paths flag is true
|
|
13572
|
-
* {
|
|
13573
|
-
* *ext_assignedpathid: 'string',
|
|
13574
|
-
* *assigned_path_id: 'string',
|
|
13575
|
-
* startdate: 0,
|
|
13576
|
-
* *duedate: 0
|
|
13577
|
-
* },
|
|
13578
|
-
* ],
|
|
13579
|
-
* products: [
|
|
13580
|
-
* { *productcode: 'string' },
|
|
13581
|
-
* ]
|
|
13582
|
-
* }
|
|
13583
|
-
* }
|
|
13584
13642
|
* }
|
|
13585
13643
|
*/
|
|
13586
13644
|
function shadowProvision(options) {
|
|
@@ -17574,167 +17632,181 @@ module.exports = Array.isArray || function (arr) {
|
|
|
17574
17632
|
};
|
|
17575
17633
|
|
|
17576
17634
|
},{}],40:[function(require,module,exports){
|
|
17577
|
-
|
|
17578
|
-
/**
|
|
17579
|
-
* Expose `Emitter`.
|
|
17580
|
-
*/
|
|
17581
|
-
|
|
17582
|
-
module
|
|
17583
|
-
|
|
17584
|
-
|
|
17585
|
-
|
|
17586
|
-
|
|
17587
|
-
*
|
|
17588
|
-
|
|
17589
|
-
|
|
17590
|
-
|
|
17591
|
-
|
|
17592
|
-
|
|
17593
|
-
|
|
17594
|
-
|
|
17595
|
-
|
|
17596
|
-
|
|
17597
|
-
*
|
|
17598
|
-
*
|
|
17599
|
-
* @
|
|
17600
|
-
|
|
17601
|
-
|
|
17602
|
-
|
|
17603
|
-
|
|
17604
|
-
|
|
17605
|
-
|
|
17606
|
-
|
|
17607
|
-
}
|
|
17608
|
-
|
|
17609
|
-
|
|
17610
|
-
|
|
17611
|
-
|
|
17612
|
-
*
|
|
17613
|
-
*
|
|
17614
|
-
* @
|
|
17615
|
-
* @
|
|
17616
|
-
|
|
17617
|
-
|
|
17618
|
-
|
|
17619
|
-
|
|
17620
|
-
|
|
17621
|
-
|
|
17622
|
-
|
|
17623
|
-
|
|
17624
|
-
|
|
17625
|
-
|
|
17626
|
-
|
|
17627
|
-
|
|
17628
|
-
|
|
17629
|
-
*
|
|
17630
|
-
*
|
|
17631
|
-
*
|
|
17632
|
-
* @
|
|
17633
|
-
* @
|
|
17634
|
-
|
|
17635
|
-
|
|
17636
|
-
|
|
17637
|
-
|
|
17638
|
-
|
|
17639
|
-
|
|
17640
|
-
|
|
17641
|
-
|
|
17642
|
-
|
|
17643
|
-
|
|
17644
|
-
|
|
17645
|
-
|
|
17646
|
-
|
|
17647
|
-
|
|
17648
|
-
|
|
17649
|
-
|
|
17650
|
-
*
|
|
17651
|
-
*
|
|
17652
|
-
*
|
|
17653
|
-
* @
|
|
17654
|
-
* @
|
|
17655
|
-
|
|
17656
|
-
|
|
17657
|
-
|
|
17658
|
-
|
|
17659
|
-
Emitter.prototype.
|
|
17660
|
-
Emitter.prototype.
|
|
17661
|
-
|
|
17662
|
-
|
|
17663
|
-
|
|
17664
|
-
|
|
17665
|
-
|
|
17666
|
-
|
|
17667
|
-
|
|
17668
|
-
|
|
17669
|
-
|
|
17670
|
-
|
|
17671
|
-
|
|
17672
|
-
|
|
17673
|
-
|
|
17674
|
-
|
|
17675
|
-
|
|
17676
|
-
|
|
17677
|
-
|
|
17678
|
-
|
|
17679
|
-
|
|
17680
|
-
|
|
17681
|
-
|
|
17682
|
-
|
|
17683
|
-
|
|
17684
|
-
|
|
17685
|
-
|
|
17686
|
-
|
|
17687
|
-
|
|
17688
|
-
|
|
17689
|
-
}
|
|
17690
|
-
|
|
17691
|
-
|
|
17692
|
-
|
|
17693
|
-
|
|
17694
|
-
|
|
17695
|
-
|
|
17696
|
-
|
|
17697
|
-
|
|
17698
|
-
|
|
17699
|
-
|
|
17700
|
-
|
|
17701
|
-
|
|
17702
|
-
|
|
17703
|
-
|
|
17704
|
-
|
|
17705
|
-
|
|
17706
|
-
|
|
17707
|
-
|
|
17708
|
-
|
|
17709
|
-
}
|
|
17710
|
-
|
|
17711
|
-
|
|
17712
|
-
|
|
17713
|
-
|
|
17714
|
-
|
|
17715
|
-
|
|
17716
|
-
|
|
17717
|
-
|
|
17718
|
-
|
|
17719
|
-
|
|
17720
|
-
|
|
17721
|
-
|
|
17722
|
-
|
|
17723
|
-
|
|
17724
|
-
|
|
17725
|
-
|
|
17726
|
-
|
|
17727
|
-
|
|
17728
|
-
|
|
17729
|
-
*
|
|
17730
|
-
*
|
|
17731
|
-
* @
|
|
17732
|
-
* @
|
|
17733
|
-
|
|
17734
|
-
|
|
17735
|
-
|
|
17736
|
-
|
|
17737
|
-
};
|
|
17635
|
+
|
|
17636
|
+
/**
|
|
17637
|
+
* Expose `Emitter`.
|
|
17638
|
+
*/
|
|
17639
|
+
|
|
17640
|
+
if (typeof module !== 'undefined') {
|
|
17641
|
+
module.exports = Emitter;
|
|
17642
|
+
}
|
|
17643
|
+
|
|
17644
|
+
/**
|
|
17645
|
+
* Initialize a new `Emitter`.
|
|
17646
|
+
*
|
|
17647
|
+
* @api public
|
|
17648
|
+
*/
|
|
17649
|
+
|
|
17650
|
+
function Emitter(obj) {
|
|
17651
|
+
if (obj) return mixin(obj);
|
|
17652
|
+
};
|
|
17653
|
+
|
|
17654
|
+
/**
|
|
17655
|
+
* Mixin the emitter properties.
|
|
17656
|
+
*
|
|
17657
|
+
* @param {Object} obj
|
|
17658
|
+
* @return {Object}
|
|
17659
|
+
* @api private
|
|
17660
|
+
*/
|
|
17661
|
+
|
|
17662
|
+
function mixin(obj) {
|
|
17663
|
+
for (var key in Emitter.prototype) {
|
|
17664
|
+
obj[key] = Emitter.prototype[key];
|
|
17665
|
+
}
|
|
17666
|
+
return obj;
|
|
17667
|
+
}
|
|
17668
|
+
|
|
17669
|
+
/**
|
|
17670
|
+
* Listen on the given `event` with `fn`.
|
|
17671
|
+
*
|
|
17672
|
+
* @param {String} event
|
|
17673
|
+
* @param {Function} fn
|
|
17674
|
+
* @return {Emitter}
|
|
17675
|
+
* @api public
|
|
17676
|
+
*/
|
|
17677
|
+
|
|
17678
|
+
Emitter.prototype.on =
|
|
17679
|
+
Emitter.prototype.addEventListener = function(event, fn){
|
|
17680
|
+
this._callbacks = this._callbacks || {};
|
|
17681
|
+
(this._callbacks['$' + event] = this._callbacks['$' + event] || [])
|
|
17682
|
+
.push(fn);
|
|
17683
|
+
return this;
|
|
17684
|
+
};
|
|
17685
|
+
|
|
17686
|
+
/**
|
|
17687
|
+
* Adds an `event` listener that will be invoked a single
|
|
17688
|
+
* time then automatically removed.
|
|
17689
|
+
*
|
|
17690
|
+
* @param {String} event
|
|
17691
|
+
* @param {Function} fn
|
|
17692
|
+
* @return {Emitter}
|
|
17693
|
+
* @api public
|
|
17694
|
+
*/
|
|
17695
|
+
|
|
17696
|
+
Emitter.prototype.once = function(event, fn){
|
|
17697
|
+
function on() {
|
|
17698
|
+
this.off(event, on);
|
|
17699
|
+
fn.apply(this, arguments);
|
|
17700
|
+
}
|
|
17701
|
+
|
|
17702
|
+
on.fn = fn;
|
|
17703
|
+
this.on(event, on);
|
|
17704
|
+
return this;
|
|
17705
|
+
};
|
|
17706
|
+
|
|
17707
|
+
/**
|
|
17708
|
+
* Remove the given callback for `event` or all
|
|
17709
|
+
* registered callbacks.
|
|
17710
|
+
*
|
|
17711
|
+
* @param {String} event
|
|
17712
|
+
* @param {Function} fn
|
|
17713
|
+
* @return {Emitter}
|
|
17714
|
+
* @api public
|
|
17715
|
+
*/
|
|
17716
|
+
|
|
17717
|
+
Emitter.prototype.off =
|
|
17718
|
+
Emitter.prototype.removeListener =
|
|
17719
|
+
Emitter.prototype.removeAllListeners =
|
|
17720
|
+
Emitter.prototype.removeEventListener = function(event, fn){
|
|
17721
|
+
this._callbacks = this._callbacks || {};
|
|
17722
|
+
|
|
17723
|
+
// all
|
|
17724
|
+
if (0 == arguments.length) {
|
|
17725
|
+
this._callbacks = {};
|
|
17726
|
+
return this;
|
|
17727
|
+
}
|
|
17728
|
+
|
|
17729
|
+
// specific event
|
|
17730
|
+
var callbacks = this._callbacks['$' + event];
|
|
17731
|
+
if (!callbacks) return this;
|
|
17732
|
+
|
|
17733
|
+
// remove all handlers
|
|
17734
|
+
if (1 == arguments.length) {
|
|
17735
|
+
delete this._callbacks['$' + event];
|
|
17736
|
+
return this;
|
|
17737
|
+
}
|
|
17738
|
+
|
|
17739
|
+
// remove specific handler
|
|
17740
|
+
var cb;
|
|
17741
|
+
for (var i = 0; i < callbacks.length; i++) {
|
|
17742
|
+
cb = callbacks[i];
|
|
17743
|
+
if (cb === fn || cb.fn === fn) {
|
|
17744
|
+
callbacks.splice(i, 1);
|
|
17745
|
+
break;
|
|
17746
|
+
}
|
|
17747
|
+
}
|
|
17748
|
+
|
|
17749
|
+
// Remove event specific arrays for event types that no
|
|
17750
|
+
// one is subscribed for to avoid memory leak.
|
|
17751
|
+
if (callbacks.length === 0) {
|
|
17752
|
+
delete this._callbacks['$' + event];
|
|
17753
|
+
}
|
|
17754
|
+
|
|
17755
|
+
return this;
|
|
17756
|
+
};
|
|
17757
|
+
|
|
17758
|
+
/**
|
|
17759
|
+
* Emit `event` with the given args.
|
|
17760
|
+
*
|
|
17761
|
+
* @param {String} event
|
|
17762
|
+
* @param {Mixed} ...
|
|
17763
|
+
* @return {Emitter}
|
|
17764
|
+
*/
|
|
17765
|
+
|
|
17766
|
+
Emitter.prototype.emit = function(event){
|
|
17767
|
+
this._callbacks = this._callbacks || {};
|
|
17768
|
+
|
|
17769
|
+
var args = new Array(arguments.length - 1)
|
|
17770
|
+
, callbacks = this._callbacks['$' + event];
|
|
17771
|
+
|
|
17772
|
+
for (var i = 1; i < arguments.length; i++) {
|
|
17773
|
+
args[i - 1] = arguments[i];
|
|
17774
|
+
}
|
|
17775
|
+
|
|
17776
|
+
if (callbacks) {
|
|
17777
|
+
callbacks = callbacks.slice(0);
|
|
17778
|
+
for (var i = 0, len = callbacks.length; i < len; ++i) {
|
|
17779
|
+
callbacks[i].apply(this, args);
|
|
17780
|
+
}
|
|
17781
|
+
}
|
|
17782
|
+
|
|
17783
|
+
return this;
|
|
17784
|
+
};
|
|
17785
|
+
|
|
17786
|
+
/**
|
|
17787
|
+
* Return array of callbacks for `event`.
|
|
17788
|
+
*
|
|
17789
|
+
* @param {String} event
|
|
17790
|
+
* @return {Array}
|
|
17791
|
+
* @api public
|
|
17792
|
+
*/
|
|
17793
|
+
|
|
17794
|
+
Emitter.prototype.listeners = function(event){
|
|
17795
|
+
this._callbacks = this._callbacks || {};
|
|
17796
|
+
return this._callbacks['$' + event] || [];
|
|
17797
|
+
};
|
|
17798
|
+
|
|
17799
|
+
/**
|
|
17800
|
+
* Check if this emitter has `event` handlers.
|
|
17801
|
+
*
|
|
17802
|
+
* @param {String} event
|
|
17803
|
+
* @return {Boolean}
|
|
17804
|
+
* @api public
|
|
17805
|
+
*/
|
|
17806
|
+
|
|
17807
|
+
Emitter.prototype.hasListeners = function(event){
|
|
17808
|
+
return !! this.listeners(event).length;
|
|
17809
|
+
};
|
|
17738
17810
|
|
|
17739
17811
|
},{}],41:[function(require,module,exports){
|
|
17740
17812
|
// Copyright Joyent, Inc. and other Node contributors.
|
|
@@ -18040,6 +18112,8 @@ function isUndefined(arg) {
|
|
|
18040
18112
|
}
|
|
18041
18113
|
|
|
18042
18114
|
},{}],42:[function(require,module,exports){
|
|
18115
|
+
'use strict';
|
|
18116
|
+
|
|
18043
18117
|
var hasOwn = Object.prototype.hasOwnProperty;
|
|
18044
18118
|
var toStr = Object.prototype.toString;
|
|
18045
18119
|
var defineProperty = Object.defineProperty;
|
|
@@ -18054,8 +18128,6 @@ var isArray = function isArray(arr) {
|
|
|
18054
18128
|
};
|
|
18055
18129
|
|
|
18056
18130
|
var isPlainObject = function isPlainObject(obj) {
|
|
18057
|
-
'use strict';
|
|
18058
|
-
|
|
18059
18131
|
if (!obj || toStr.call(obj) !== '[object Object]') {
|
|
18060
18132
|
return false;
|
|
18061
18133
|
}
|
|
@@ -18105,8 +18177,6 @@ var getProperty = function getProperty(obj, name) {
|
|
|
18105
18177
|
};
|
|
18106
18178
|
|
|
18107
18179
|
module.exports = function extend() {
|
|
18108
|
-
'use strict';
|
|
18109
|
-
|
|
18110
18180
|
var options, name, src, copy, copyIsArray, clone;
|
|
18111
18181
|
var target = arguments[0];
|
|
18112
18182
|
var i = 1;
|
|
@@ -20576,6 +20646,8 @@ function template(string) {
|
|
|
20576
20646
|
|
|
20577
20647
|
var Emitter = require('emitter');
|
|
20578
20648
|
var reduce = require('reduce');
|
|
20649
|
+
var requestBase = require('./request-base');
|
|
20650
|
+
var isObject = require('./is-object');
|
|
20579
20651
|
|
|
20580
20652
|
/**
|
|
20581
20653
|
* Root reference for iframes.
|
|
@@ -20597,28 +20669,10 @@ if (typeof window !== 'undefined') { // Browser window
|
|
|
20597
20669
|
function noop(){};
|
|
20598
20670
|
|
|
20599
20671
|
/**
|
|
20600
|
-
*
|
|
20601
|
-
* we don't want to serialize these :)
|
|
20602
|
-
*
|
|
20603
|
-
* TODO: future proof, move to compoent land
|
|
20604
|
-
*
|
|
20605
|
-
* @param {Object} obj
|
|
20606
|
-
* @return {Boolean}
|
|
20607
|
-
* @api private
|
|
20672
|
+
* Expose `request`.
|
|
20608
20673
|
*/
|
|
20609
20674
|
|
|
20610
|
-
|
|
20611
|
-
var str = {}.toString.call(obj);
|
|
20612
|
-
|
|
20613
|
-
switch (str) {
|
|
20614
|
-
case '[object File]':
|
|
20615
|
-
case '[object Blob]':
|
|
20616
|
-
case '[object FormData]':
|
|
20617
|
-
return true;
|
|
20618
|
-
default:
|
|
20619
|
-
return false;
|
|
20620
|
-
}
|
|
20621
|
-
}
|
|
20675
|
+
var request = module.exports = require('./request').bind(null, Request);
|
|
20622
20676
|
|
|
20623
20677
|
/**
|
|
20624
20678
|
* Determine XHR.
|
|
@@ -20650,18 +20704,6 @@ var trim = ''.trim
|
|
|
20650
20704
|
? function(s) { return s.trim(); }
|
|
20651
20705
|
: function(s) { return s.replace(/(^\s*|\s*$)/g, ''); };
|
|
20652
20706
|
|
|
20653
|
-
/**
|
|
20654
|
-
* Check if `obj` is an object.
|
|
20655
|
-
*
|
|
20656
|
-
* @param {Object} obj
|
|
20657
|
-
* @return {Boolean}
|
|
20658
|
-
* @api private
|
|
20659
|
-
*/
|
|
20660
|
-
|
|
20661
|
-
function isObject(obj) {
|
|
20662
|
-
return obj === Object(obj);
|
|
20663
|
-
}
|
|
20664
|
-
|
|
20665
20707
|
/**
|
|
20666
20708
|
* Serialize the given `obj`.
|
|
20667
20709
|
*
|
|
@@ -20676,8 +20718,8 @@ function serialize(obj) {
|
|
|
20676
20718
|
for (var key in obj) {
|
|
20677
20719
|
if (null != obj[key]) {
|
|
20678
20720
|
pushEncodedKeyValuePair(pairs, key, obj[key]);
|
|
20679
|
-
|
|
20680
|
-
|
|
20721
|
+
}
|
|
20722
|
+
}
|
|
20681
20723
|
return pairs.join('&');
|
|
20682
20724
|
}
|
|
20683
20725
|
|
|
@@ -20695,6 +20737,11 @@ function pushEncodedKeyValuePair(pairs, key, val) {
|
|
|
20695
20737
|
return val.forEach(function(v) {
|
|
20696
20738
|
pushEncodedKeyValuePair(pairs, key, v);
|
|
20697
20739
|
});
|
|
20740
|
+
} else if (isObject(val)) {
|
|
20741
|
+
for(var subkey in val) {
|
|
20742
|
+
pushEncodedKeyValuePair(pairs, key + '[' + subkey + ']', val[subkey]);
|
|
20743
|
+
}
|
|
20744
|
+
return;
|
|
20698
20745
|
}
|
|
20699
20746
|
pairs.push(encodeURIComponent(key)
|
|
20700
20747
|
+ '=' + encodeURIComponent(val));
|
|
@@ -20717,13 +20764,18 @@ function pushEncodedKeyValuePair(pairs, key, val) {
|
|
|
20717
20764
|
function parseString(str) {
|
|
20718
20765
|
var obj = {};
|
|
20719
20766
|
var pairs = str.split('&');
|
|
20720
|
-
var parts;
|
|
20721
20767
|
var pair;
|
|
20768
|
+
var pos;
|
|
20722
20769
|
|
|
20723
20770
|
for (var i = 0, len = pairs.length; i < len; ++i) {
|
|
20724
20771
|
pair = pairs[i];
|
|
20725
|
-
|
|
20726
|
-
|
|
20772
|
+
pos = pair.indexOf('=');
|
|
20773
|
+
if (pos == -1) {
|
|
20774
|
+
obj[decodeURIComponent(pair)] = '';
|
|
20775
|
+
} else {
|
|
20776
|
+
obj[decodeURIComponent(pair.slice(0, pos))] =
|
|
20777
|
+
decodeURIComponent(pair.slice(pos + 1));
|
|
20778
|
+
}
|
|
20727
20779
|
}
|
|
20728
20780
|
|
|
20729
20781
|
return obj;
|
|
@@ -20907,15 +20959,15 @@ function Response(req, options) {
|
|
|
20907
20959
|
? this.xhr.responseText
|
|
20908
20960
|
: null;
|
|
20909
20961
|
this.statusText = this.req.xhr.statusText;
|
|
20910
|
-
this.
|
|
20962
|
+
this._setStatusProperties(this.xhr.status);
|
|
20911
20963
|
this.header = this.headers = parseHeader(this.xhr.getAllResponseHeaders());
|
|
20912
20964
|
// getAllResponseHeaders sometimes falsely returns "" for CORS requests, but
|
|
20913
20965
|
// getResponseHeader still works. so we get content-type even if getting
|
|
20914
20966
|
// other headers fails.
|
|
20915
20967
|
this.header['content-type'] = this.xhr.getResponseHeader('content-type');
|
|
20916
|
-
this.
|
|
20968
|
+
this._setHeaderProperties(this.header);
|
|
20917
20969
|
this.body = this.req.method != 'HEAD'
|
|
20918
|
-
? this.
|
|
20970
|
+
? this._parseBody(this.text ? this.text : this.xhr.response)
|
|
20919
20971
|
: null;
|
|
20920
20972
|
}
|
|
20921
20973
|
|
|
@@ -20943,7 +20995,7 @@ Response.prototype.get = function(field){
|
|
|
20943
20995
|
* @api private
|
|
20944
20996
|
*/
|
|
20945
20997
|
|
|
20946
|
-
Response.prototype.
|
|
20998
|
+
Response.prototype._setHeaderProperties = function(header){
|
|
20947
20999
|
// content-type
|
|
20948
21000
|
var ct = this.header['content-type'] || '';
|
|
20949
21001
|
this.type = type(ct);
|
|
@@ -20964,8 +21016,11 @@ Response.prototype.setHeaderProperties = function(header){
|
|
|
20964
21016
|
* @api private
|
|
20965
21017
|
*/
|
|
20966
21018
|
|
|
20967
|
-
Response.prototype.
|
|
21019
|
+
Response.prototype._parseBody = function(str){
|
|
20968
21020
|
var parse = request.parse[this.type];
|
|
21021
|
+
if (!parse && isJSON(this.type)) {
|
|
21022
|
+
parse = request.parse['application/json'];
|
|
21023
|
+
}
|
|
20969
21024
|
return parse && str && (str.length || str instanceof Object)
|
|
20970
21025
|
? parse(str)
|
|
20971
21026
|
: null;
|
|
@@ -20992,7 +21047,7 @@ Response.prototype.parseBody = function(str){
|
|
|
20992
21047
|
* @api private
|
|
20993
21048
|
*/
|
|
20994
21049
|
|
|
20995
|
-
Response.prototype.
|
|
21050
|
+
Response.prototype._setStatusProperties = function(status){
|
|
20996
21051
|
// handle IE9 bug: http://stackoverflow.com/questions/10046972/msie-returns-status-code-of-1223-for-ajax-request
|
|
20997
21052
|
if (status === 1223) {
|
|
20998
21053
|
status = 204;
|
|
@@ -21060,12 +21115,11 @@ request.Response = Response;
|
|
|
21060
21115
|
|
|
21061
21116
|
function Request(method, url) {
|
|
21062
21117
|
var self = this;
|
|
21063
|
-
Emitter.call(this);
|
|
21064
21118
|
this._query = this._query || [];
|
|
21065
21119
|
this.method = method;
|
|
21066
21120
|
this.url = url;
|
|
21067
|
-
this.header = {};
|
|
21068
|
-
this._header = {};
|
|
21121
|
+
this.header = {}; // preserves header name case
|
|
21122
|
+
this._header = {}; // coerces header names to lowercase
|
|
21069
21123
|
this.on('end', function(){
|
|
21070
21124
|
var err = null;
|
|
21071
21125
|
var res = null;
|
|
@@ -21078,6 +21132,8 @@ function Request(method, url) {
|
|
|
21078
21132
|
err.original = e;
|
|
21079
21133
|
// issue #675: return the raw response if the response parsing fails
|
|
21080
21134
|
err.rawResponse = self.xhr && self.xhr.responseText ? self.xhr.responseText : null;
|
|
21135
|
+
// issue #876: return the http status code if the response parsing fails
|
|
21136
|
+
err.statusCode = self.xhr && self.xhr.status ? self.xhr.status : null;
|
|
21081
21137
|
return self.callback(err);
|
|
21082
21138
|
}
|
|
21083
21139
|
|
|
@@ -21087,140 +21143,32 @@ function Request(method, url) {
|
|
|
21087
21143
|
return self.callback(err, res);
|
|
21088
21144
|
}
|
|
21089
21145
|
|
|
21090
|
-
|
|
21091
|
-
|
|
21092
|
-
|
|
21146
|
+
try {
|
|
21147
|
+
if (res.status >= 200 && res.status < 300) {
|
|
21148
|
+
return self.callback(err, res);
|
|
21149
|
+
}
|
|
21093
21150
|
|
|
21094
|
-
|
|
21095
|
-
|
|
21096
|
-
|
|
21097
|
-
|
|
21151
|
+
var new_err = new Error(res.statusText || 'Unsuccessful HTTP response');
|
|
21152
|
+
new_err.original = err;
|
|
21153
|
+
new_err.response = res;
|
|
21154
|
+
new_err.status = res.status;
|
|
21098
21155
|
|
|
21099
|
-
|
|
21156
|
+
self.callback(new_err, res);
|
|
21157
|
+
} catch(e) {
|
|
21158
|
+
self.callback(e); // #985 touching res may cause INVALID_STATE_ERR on old Android
|
|
21159
|
+
}
|
|
21100
21160
|
});
|
|
21101
21161
|
}
|
|
21102
21162
|
|
|
21103
21163
|
/**
|
|
21104
|
-
* Mixin `Emitter`.
|
|
21164
|
+
* Mixin `Emitter` and `requestBase`.
|
|
21105
21165
|
*/
|
|
21106
21166
|
|
|
21107
21167
|
Emitter(Request.prototype);
|
|
21108
|
-
|
|
21109
|
-
|
|
21110
|
-
* Allow for extension
|
|
21111
|
-
*/
|
|
21112
|
-
|
|
21113
|
-
Request.prototype.use = function(fn) {
|
|
21114
|
-
fn(this);
|
|
21115
|
-
return this;
|
|
21168
|
+
for (var key in requestBase) {
|
|
21169
|
+
Request.prototype[key] = requestBase[key];
|
|
21116
21170
|
}
|
|
21117
21171
|
|
|
21118
|
-
/**
|
|
21119
|
-
* Set timeout to `ms`.
|
|
21120
|
-
*
|
|
21121
|
-
* @param {Number} ms
|
|
21122
|
-
* @return {Request} for chaining
|
|
21123
|
-
* @api public
|
|
21124
|
-
*/
|
|
21125
|
-
|
|
21126
|
-
Request.prototype.timeout = function(ms){
|
|
21127
|
-
this._timeout = ms;
|
|
21128
|
-
return this;
|
|
21129
|
-
};
|
|
21130
|
-
|
|
21131
|
-
/**
|
|
21132
|
-
* Clear previous timeout.
|
|
21133
|
-
*
|
|
21134
|
-
* @return {Request} for chaining
|
|
21135
|
-
* @api public
|
|
21136
|
-
*/
|
|
21137
|
-
|
|
21138
|
-
Request.prototype.clearTimeout = function(){
|
|
21139
|
-
this._timeout = 0;
|
|
21140
|
-
clearTimeout(this._timer);
|
|
21141
|
-
return this;
|
|
21142
|
-
};
|
|
21143
|
-
|
|
21144
|
-
/**
|
|
21145
|
-
* Abort the request, and clear potential timeout.
|
|
21146
|
-
*
|
|
21147
|
-
* @return {Request}
|
|
21148
|
-
* @api public
|
|
21149
|
-
*/
|
|
21150
|
-
|
|
21151
|
-
Request.prototype.abort = function(){
|
|
21152
|
-
if (this.aborted) return;
|
|
21153
|
-
this.aborted = true;
|
|
21154
|
-
this.xhr.abort();
|
|
21155
|
-
this.clearTimeout();
|
|
21156
|
-
this.emit('abort');
|
|
21157
|
-
return this;
|
|
21158
|
-
};
|
|
21159
|
-
|
|
21160
|
-
/**
|
|
21161
|
-
* Set header `field` to `val`, or multiple fields with one object.
|
|
21162
|
-
*
|
|
21163
|
-
* Examples:
|
|
21164
|
-
*
|
|
21165
|
-
* req.get('/')
|
|
21166
|
-
* .set('Accept', 'application/json')
|
|
21167
|
-
* .set('X-API-Key', 'foobar')
|
|
21168
|
-
* .end(callback);
|
|
21169
|
-
*
|
|
21170
|
-
* req.get('/')
|
|
21171
|
-
* .set({ Accept: 'application/json', 'X-API-Key': 'foobar' })
|
|
21172
|
-
* .end(callback);
|
|
21173
|
-
*
|
|
21174
|
-
* @param {String|Object} field
|
|
21175
|
-
* @param {String} val
|
|
21176
|
-
* @return {Request} for chaining
|
|
21177
|
-
* @api public
|
|
21178
|
-
*/
|
|
21179
|
-
|
|
21180
|
-
Request.prototype.set = function(field, val){
|
|
21181
|
-
if (isObject(field)) {
|
|
21182
|
-
for (var key in field) {
|
|
21183
|
-
this.set(key, field[key]);
|
|
21184
|
-
}
|
|
21185
|
-
return this;
|
|
21186
|
-
}
|
|
21187
|
-
this._header[field.toLowerCase()] = val;
|
|
21188
|
-
this.header[field] = val;
|
|
21189
|
-
return this;
|
|
21190
|
-
};
|
|
21191
|
-
|
|
21192
|
-
/**
|
|
21193
|
-
* Remove header `field`.
|
|
21194
|
-
*
|
|
21195
|
-
* Example:
|
|
21196
|
-
*
|
|
21197
|
-
* req.get('/')
|
|
21198
|
-
* .unset('User-Agent')
|
|
21199
|
-
* .end(callback);
|
|
21200
|
-
*
|
|
21201
|
-
* @param {String} field
|
|
21202
|
-
* @return {Request} for chaining
|
|
21203
|
-
* @api public
|
|
21204
|
-
*/
|
|
21205
|
-
|
|
21206
|
-
Request.prototype.unset = function(field){
|
|
21207
|
-
delete this._header[field.toLowerCase()];
|
|
21208
|
-
delete this.header[field];
|
|
21209
|
-
return this;
|
|
21210
|
-
};
|
|
21211
|
-
|
|
21212
|
-
/**
|
|
21213
|
-
* Get case-insensitive header `field` value.
|
|
21214
|
-
*
|
|
21215
|
-
* @param {String} field
|
|
21216
|
-
* @return {String}
|
|
21217
|
-
* @api private
|
|
21218
|
-
*/
|
|
21219
|
-
|
|
21220
|
-
Request.prototype.getHeader = function(field){
|
|
21221
|
-
return this._header[field.toLowerCase()];
|
|
21222
|
-
};
|
|
21223
|
-
|
|
21224
21172
|
/**
|
|
21225
21173
|
* Set Content-Type to `type`, mapping values from `request.types`.
|
|
21226
21174
|
*
|
|
@@ -21249,16 +21197,22 @@ Request.prototype.type = function(type){
|
|
|
21249
21197
|
};
|
|
21250
21198
|
|
|
21251
21199
|
/**
|
|
21252
|
-
*
|
|
21200
|
+
* Set responseType to `val`. Presently valid responseTypes are 'blob' and
|
|
21201
|
+
* 'arraybuffer'.
|
|
21253
21202
|
*
|
|
21254
|
-
*
|
|
21203
|
+
* Examples:
|
|
21255
21204
|
*
|
|
21256
|
-
*
|
|
21205
|
+
* req.get('/')
|
|
21206
|
+
* .responseType('blob')
|
|
21207
|
+
* .end(callback);
|
|
21208
|
+
*
|
|
21209
|
+
* @param {String} val
|
|
21210
|
+
* @return {Request} for chaining
|
|
21257
21211
|
* @api public
|
|
21258
21212
|
*/
|
|
21259
21213
|
|
|
21260
|
-
Request.prototype.
|
|
21261
|
-
this.
|
|
21214
|
+
Request.prototype.responseType = function(val){
|
|
21215
|
+
this._responseType = val;
|
|
21262
21216
|
return this;
|
|
21263
21217
|
};
|
|
21264
21218
|
|
|
@@ -21292,13 +21246,29 @@ Request.prototype.accept = function(type){
|
|
|
21292
21246
|
*
|
|
21293
21247
|
* @param {String} user
|
|
21294
21248
|
* @param {String} pass
|
|
21249
|
+
* @param {Object} options with 'type' property 'auto' or 'basic' (default 'basic')
|
|
21295
21250
|
* @return {Request} for chaining
|
|
21296
21251
|
* @api public
|
|
21297
21252
|
*/
|
|
21298
21253
|
|
|
21299
|
-
Request.prototype.auth = function(user, pass){
|
|
21300
|
-
|
|
21301
|
-
|
|
21254
|
+
Request.prototype.auth = function(user, pass, options){
|
|
21255
|
+
if (!options) {
|
|
21256
|
+
options = {
|
|
21257
|
+
type: 'basic'
|
|
21258
|
+
}
|
|
21259
|
+
}
|
|
21260
|
+
|
|
21261
|
+
switch (options.type) {
|
|
21262
|
+
case 'basic':
|
|
21263
|
+
var str = btoa(user + ':' + pass);
|
|
21264
|
+
this.set('Authorization', 'Basic ' + str);
|
|
21265
|
+
break;
|
|
21266
|
+
|
|
21267
|
+
case 'auto':
|
|
21268
|
+
this.username = user;
|
|
21269
|
+
this.password = pass;
|
|
21270
|
+
break;
|
|
21271
|
+
}
|
|
21302
21272
|
return this;
|
|
21303
21273
|
};
|
|
21304
21274
|
|
|
@@ -21322,35 +21292,13 @@ Request.prototype.query = function(val){
|
|
|
21322
21292
|
return this;
|
|
21323
21293
|
};
|
|
21324
21294
|
|
|
21325
|
-
/**
|
|
21326
|
-
* Write the field `name` and `val` for "multipart/form-data"
|
|
21327
|
-
* request bodies.
|
|
21328
|
-
*
|
|
21329
|
-
* ``` js
|
|
21330
|
-
* request.post('/upload')
|
|
21331
|
-
* .field('foo', 'bar')
|
|
21332
|
-
* .end(callback);
|
|
21333
|
-
* ```
|
|
21334
|
-
*
|
|
21335
|
-
* @param {String} name
|
|
21336
|
-
* @param {String|Blob|File} val
|
|
21337
|
-
* @return {Request} for chaining
|
|
21338
|
-
* @api public
|
|
21339
|
-
*/
|
|
21340
|
-
|
|
21341
|
-
Request.prototype.field = function(name, val){
|
|
21342
|
-
if (!this._formData) this._formData = new root.FormData();
|
|
21343
|
-
this._formData.append(name, val);
|
|
21344
|
-
return this;
|
|
21345
|
-
};
|
|
21346
|
-
|
|
21347
21295
|
/**
|
|
21348
21296
|
* Queue the given `file` as an attachment to the specified `field`,
|
|
21349
21297
|
* with optional `filename`.
|
|
21350
21298
|
*
|
|
21351
21299
|
* ``` js
|
|
21352
21300
|
* request.post('/upload')
|
|
21353
|
-
* .attach(new Blob(['<a id="a"><b id="b">hey!</b></a>'], { type: "text/html"}))
|
|
21301
|
+
* .attach('content', new Blob(['<a id="a"><b id="b">hey!</b></a>'], { type: "text/html"}))
|
|
21354
21302
|
* .end(callback);
|
|
21355
21303
|
* ```
|
|
21356
21304
|
*
|
|
@@ -21362,77 +21310,15 @@ Request.prototype.field = function(name, val){
|
|
|
21362
21310
|
*/
|
|
21363
21311
|
|
|
21364
21312
|
Request.prototype.attach = function(field, file, filename){
|
|
21365
|
-
|
|
21366
|
-
this._formData.append(field, file, filename || file.name);
|
|
21313
|
+
this._getFormData().append(field, file, filename || file.name);
|
|
21367
21314
|
return this;
|
|
21368
21315
|
};
|
|
21369
21316
|
|
|
21370
|
-
|
|
21371
|
-
|
|
21372
|
-
|
|
21373
|
-
*
|
|
21374
|
-
* Examples:
|
|
21375
|
-
*
|
|
21376
|
-
* // manual json
|
|
21377
|
-
* request.post('/user')
|
|
21378
|
-
* .type('json')
|
|
21379
|
-
* .send('{"name":"tj"}')
|
|
21380
|
-
* .end(callback)
|
|
21381
|
-
*
|
|
21382
|
-
* // auto json
|
|
21383
|
-
* request.post('/user')
|
|
21384
|
-
* .send({ name: 'tj' })
|
|
21385
|
-
* .end(callback)
|
|
21386
|
-
*
|
|
21387
|
-
* // manual x-www-form-urlencoded
|
|
21388
|
-
* request.post('/user')
|
|
21389
|
-
* .type('form')
|
|
21390
|
-
* .send('name=tj')
|
|
21391
|
-
* .end(callback)
|
|
21392
|
-
*
|
|
21393
|
-
* // auto x-www-form-urlencoded
|
|
21394
|
-
* request.post('/user')
|
|
21395
|
-
* .type('form')
|
|
21396
|
-
* .send({ name: 'tj' })
|
|
21397
|
-
* .end(callback)
|
|
21398
|
-
*
|
|
21399
|
-
* // defaults to x-www-form-urlencoded
|
|
21400
|
-
* request.post('/user')
|
|
21401
|
-
* .send('name=tobi')
|
|
21402
|
-
* .send('species=ferret')
|
|
21403
|
-
* .end(callback)
|
|
21404
|
-
*
|
|
21405
|
-
* @param {String|Object} data
|
|
21406
|
-
* @return {Request} for chaining
|
|
21407
|
-
* @api public
|
|
21408
|
-
*/
|
|
21409
|
-
|
|
21410
|
-
Request.prototype.send = function(data){
|
|
21411
|
-
var obj = isObject(data);
|
|
21412
|
-
var type = this.getHeader('Content-Type');
|
|
21413
|
-
|
|
21414
|
-
// merge
|
|
21415
|
-
if (obj && isObject(this._data)) {
|
|
21416
|
-
for (var key in data) {
|
|
21417
|
-
this._data[key] = data[key];
|
|
21418
|
-
}
|
|
21419
|
-
} else if ('string' == typeof data) {
|
|
21420
|
-
if (!type) this.type('form');
|
|
21421
|
-
type = this.getHeader('Content-Type');
|
|
21422
|
-
if ('application/x-www-form-urlencoded' == type) {
|
|
21423
|
-
this._data = this._data
|
|
21424
|
-
? this._data + '&' + data
|
|
21425
|
-
: data;
|
|
21426
|
-
} else {
|
|
21427
|
-
this._data = (this._data || '') + data;
|
|
21428
|
-
}
|
|
21429
|
-
} else {
|
|
21430
|
-
this._data = data;
|
|
21317
|
+
Request.prototype._getFormData = function(){
|
|
21318
|
+
if (!this._formData) {
|
|
21319
|
+
this._formData = new root.FormData();
|
|
21431
21320
|
}
|
|
21432
|
-
|
|
21433
|
-
if (!obj || isHost(data)) return this;
|
|
21434
|
-
if (!type) this.type('json');
|
|
21435
|
-
return this;
|
|
21321
|
+
return this._formData;
|
|
21436
21322
|
};
|
|
21437
21323
|
|
|
21438
21324
|
/**
|
|
@@ -21473,7 +21359,7 @@ Request.prototype.crossDomainError = function(){
|
|
|
21473
21359
|
* @api private
|
|
21474
21360
|
*/
|
|
21475
21361
|
|
|
21476
|
-
Request.prototype.
|
|
21362
|
+
Request.prototype._timeoutError = function(){
|
|
21477
21363
|
var timeout = this._timeout;
|
|
21478
21364
|
var err = new Error('timeout of ' + timeout + 'ms exceeded');
|
|
21479
21365
|
err.timeout = timeout;
|
|
@@ -21481,19 +21367,18 @@ Request.prototype.timeoutError = function(){
|
|
|
21481
21367
|
};
|
|
21482
21368
|
|
|
21483
21369
|
/**
|
|
21484
|
-
*
|
|
21485
|
-
*
|
|
21486
|
-
* Note that for this to work the origin must not be
|
|
21487
|
-
* using "Access-Control-Allow-Origin" with a wildcard,
|
|
21488
|
-
* and also must set "Access-Control-Allow-Credentials"
|
|
21489
|
-
* to "true".
|
|
21370
|
+
* Compose querystring to append to req.url
|
|
21490
21371
|
*
|
|
21491
|
-
* @api
|
|
21372
|
+
* @api private
|
|
21492
21373
|
*/
|
|
21493
21374
|
|
|
21494
|
-
Request.prototype.
|
|
21495
|
-
|
|
21496
|
-
|
|
21375
|
+
Request.prototype._appendQueryString = function(){
|
|
21376
|
+
var query = this._query.join('&');
|
|
21377
|
+
if (query) {
|
|
21378
|
+
this.url += ~this.url.indexOf('?')
|
|
21379
|
+
? '&' + query
|
|
21380
|
+
: '?' + query;
|
|
21381
|
+
}
|
|
21497
21382
|
};
|
|
21498
21383
|
|
|
21499
21384
|
/**
|
|
@@ -21508,7 +21393,6 @@ Request.prototype.withCredentials = function(){
|
|
|
21508
21393
|
Request.prototype.end = function(fn){
|
|
21509
21394
|
var self = this;
|
|
21510
21395
|
var xhr = this.xhr = request.getXHR();
|
|
21511
|
-
var query = this._query.join('&');
|
|
21512
21396
|
var timeout = this._timeout;
|
|
21513
21397
|
var data = this._formData || this._data;
|
|
21514
21398
|
|
|
@@ -21525,8 +21409,8 @@ Request.prototype.end = function(fn){
|
|
|
21525
21409
|
try { status = xhr.status } catch(e) { status = 0; }
|
|
21526
21410
|
|
|
21527
21411
|
if (0 == status) {
|
|
21528
|
-
if (self.timedout) return self.
|
|
21529
|
-
if (self.
|
|
21412
|
+
if (self.timedout) return self._timeoutError();
|
|
21413
|
+
if (self._aborted) return;
|
|
21530
21414
|
return self.crossDomainError();
|
|
21531
21415
|
}
|
|
21532
21416
|
self.emit('end');
|
|
@@ -21562,24 +21446,23 @@ Request.prototype.end = function(fn){
|
|
|
21562
21446
|
}
|
|
21563
21447
|
|
|
21564
21448
|
// querystring
|
|
21565
|
-
|
|
21566
|
-
query = request.serializeObject(query);
|
|
21567
|
-
this.url += ~this.url.indexOf('?')
|
|
21568
|
-
? '&' + query
|
|
21569
|
-
: '?' + query;
|
|
21570
|
-
}
|
|
21449
|
+
this._appendQueryString();
|
|
21571
21450
|
|
|
21572
21451
|
// initiate request
|
|
21573
|
-
|
|
21452
|
+
if (this.username && this.password) {
|
|
21453
|
+
xhr.open(this.method, this.url, true, this.username, this.password);
|
|
21454
|
+
} else {
|
|
21455
|
+
xhr.open(this.method, this.url, true);
|
|
21456
|
+
}
|
|
21574
21457
|
|
|
21575
21458
|
// CORS
|
|
21576
21459
|
if (this._withCredentials) xhr.withCredentials = true;
|
|
21577
21460
|
|
|
21578
21461
|
// body
|
|
21579
|
-
if ('GET' != this.method && 'HEAD' != this.method && 'string' != typeof data && !
|
|
21462
|
+
if ('GET' != this.method && 'HEAD' != this.method && 'string' != typeof data && !this._isHost(data)) {
|
|
21580
21463
|
// serialize stuff
|
|
21581
|
-
var contentType = this.
|
|
21582
|
-
var serialize = this.
|
|
21464
|
+
var contentType = this._header['content-type'];
|
|
21465
|
+
var serialize = this._serializer || request.serialize[contentType ? contentType.split(';')[0] : ''];
|
|
21583
21466
|
if (!serialize && isJSON(contentType)) serialize = request.serialize['application/json'];
|
|
21584
21467
|
if (serialize) data = serialize(data);
|
|
21585
21468
|
}
|
|
@@ -21590,6 +21473,10 @@ Request.prototype.end = function(fn){
|
|
|
21590
21473
|
xhr.setRequestHeader(field, this.header[field]);
|
|
21591
21474
|
}
|
|
21592
21475
|
|
|
21476
|
+
if (this._responseType) {
|
|
21477
|
+
xhr.responseType = this._responseType;
|
|
21478
|
+
}
|
|
21479
|
+
|
|
21593
21480
|
// send stuff
|
|
21594
21481
|
this.emit('request', this);
|
|
21595
21482
|
|
|
@@ -21599,19 +21486,6 @@ Request.prototype.end = function(fn){
|
|
|
21599
21486
|
return this;
|
|
21600
21487
|
};
|
|
21601
21488
|
|
|
21602
|
-
/**
|
|
21603
|
-
* Faux promise support
|
|
21604
|
-
*
|
|
21605
|
-
* @param {Function} fulfill
|
|
21606
|
-
* @param {Function} reject
|
|
21607
|
-
* @return {Request}
|
|
21608
|
-
*/
|
|
21609
|
-
|
|
21610
|
-
Request.prototype.then = function (fulfill, reject) {
|
|
21611
|
-
return this.end(function(err, res) {
|
|
21612
|
-
err ? reject(err) : fulfill(res);
|
|
21613
|
-
});
|
|
21614
|
-
}
|
|
21615
21489
|
|
|
21616
21490
|
/**
|
|
21617
21491
|
* Expose `Request`.
|
|
@@ -21620,36 +21494,25 @@ Request.prototype.then = function (fulfill, reject) {
|
|
|
21620
21494
|
request.Request = Request;
|
|
21621
21495
|
|
|
21622
21496
|
/**
|
|
21623
|
-
*
|
|
21624
|
-
*
|
|
21625
|
-
* Examples:
|
|
21626
|
-
*
|
|
21627
|
-
* request('GET', '/users').end(callback)
|
|
21628
|
-
* request('/users').end(callback)
|
|
21629
|
-
* request('/users', callback)
|
|
21497
|
+
* GET `url` with optional callback `fn(res)`.
|
|
21630
21498
|
*
|
|
21631
|
-
* @param {String}
|
|
21632
|
-
* @param {
|
|
21499
|
+
* @param {String} url
|
|
21500
|
+
* @param {Mixed|Function} data or fn
|
|
21501
|
+
* @param {Function} fn
|
|
21633
21502
|
* @return {Request}
|
|
21634
21503
|
* @api public
|
|
21635
21504
|
*/
|
|
21636
21505
|
|
|
21637
|
-
function
|
|
21638
|
-
|
|
21639
|
-
if ('function' == typeof
|
|
21640
|
-
|
|
21641
|
-
|
|
21642
|
-
|
|
21643
|
-
|
|
21644
|
-
if (1 == arguments.length) {
|
|
21645
|
-
return new Request('GET', method);
|
|
21646
|
-
}
|
|
21647
|
-
|
|
21648
|
-
return new Request(method, url);
|
|
21649
|
-
}
|
|
21506
|
+
request.get = function(url, data, fn){
|
|
21507
|
+
var req = request('GET', url);
|
|
21508
|
+
if ('function' == typeof data) fn = data, data = null;
|
|
21509
|
+
if (data) req.query(data);
|
|
21510
|
+
if (fn) req.end(fn);
|
|
21511
|
+
return req;
|
|
21512
|
+
};
|
|
21650
21513
|
|
|
21651
21514
|
/**
|
|
21652
|
-
*
|
|
21515
|
+
* HEAD `url` with optional callback `fn(res)`.
|
|
21653
21516
|
*
|
|
21654
21517
|
* @param {String} url
|
|
21655
21518
|
* @param {Mixed|Function} data or fn
|
|
@@ -21658,16 +21521,16 @@ function request(method, url) {
|
|
|
21658
21521
|
* @api public
|
|
21659
21522
|
*/
|
|
21660
21523
|
|
|
21661
|
-
request.
|
|
21662
|
-
var req = request('
|
|
21524
|
+
request.head = function(url, data, fn){
|
|
21525
|
+
var req = request('HEAD', url);
|
|
21663
21526
|
if ('function' == typeof data) fn = data, data = null;
|
|
21664
|
-
if (data) req.
|
|
21527
|
+
if (data) req.send(data);
|
|
21665
21528
|
if (fn) req.end(fn);
|
|
21666
21529
|
return req;
|
|
21667
21530
|
};
|
|
21668
21531
|
|
|
21669
21532
|
/**
|
|
21670
|
-
*
|
|
21533
|
+
* OPTIONS query to `url` with optional callback `fn(res)`.
|
|
21671
21534
|
*
|
|
21672
21535
|
* @param {String} url
|
|
21673
21536
|
* @param {Mixed|Function} data or fn
|
|
@@ -21676,8 +21539,8 @@ request.get = function(url, data, fn){
|
|
|
21676
21539
|
* @api public
|
|
21677
21540
|
*/
|
|
21678
21541
|
|
|
21679
|
-
request.
|
|
21680
|
-
var req = request('
|
|
21542
|
+
request.options = function(url, data, fn){
|
|
21543
|
+
var req = request('OPTIONS', url);
|
|
21681
21544
|
if ('function' == typeof data) fn = data, data = null;
|
|
21682
21545
|
if (data) req.send(data);
|
|
21683
21546
|
if (fn) req.end(fn);
|
|
@@ -21756,13 +21619,404 @@ request.put = function(url, data, fn){
|
|
|
21756
21619
|
return req;
|
|
21757
21620
|
};
|
|
21758
21621
|
|
|
21622
|
+
},{"./is-object":50,"./request":52,"./request-base":51,"emitter":40,"reduce":47}],50:[function(require,module,exports){
|
|
21759
21623
|
/**
|
|
21760
|
-
*
|
|
21624
|
+
* Check if `obj` is an object.
|
|
21625
|
+
*
|
|
21626
|
+
* @param {Object} obj
|
|
21627
|
+
* @return {Boolean}
|
|
21628
|
+
* @api private
|
|
21629
|
+
*/
|
|
21630
|
+
|
|
21631
|
+
function isObject(obj) {
|
|
21632
|
+
return null !== obj && 'object' === typeof obj;
|
|
21633
|
+
}
|
|
21634
|
+
|
|
21635
|
+
module.exports = isObject;
|
|
21636
|
+
|
|
21637
|
+
},{}],51:[function(require,module,exports){
|
|
21638
|
+
/**
|
|
21639
|
+
* Module of mixed-in functions shared between node and client code
|
|
21640
|
+
*/
|
|
21641
|
+
var isObject = require('./is-object');
|
|
21642
|
+
|
|
21643
|
+
/**
|
|
21644
|
+
* Clear previous timeout.
|
|
21645
|
+
*
|
|
21646
|
+
* @return {Request} for chaining
|
|
21647
|
+
* @api public
|
|
21648
|
+
*/
|
|
21649
|
+
|
|
21650
|
+
exports.clearTimeout = function _clearTimeout(){
|
|
21651
|
+
this._timeout = 0;
|
|
21652
|
+
clearTimeout(this._timer);
|
|
21653
|
+
return this;
|
|
21654
|
+
};
|
|
21655
|
+
|
|
21656
|
+
/**
|
|
21657
|
+
* Override default response body parser
|
|
21658
|
+
*
|
|
21659
|
+
* This function will be called to convert incoming data into request.body
|
|
21660
|
+
*
|
|
21661
|
+
* @param {Function}
|
|
21662
|
+
* @api public
|
|
21663
|
+
*/
|
|
21664
|
+
|
|
21665
|
+
exports.parse = function parse(fn){
|
|
21666
|
+
this._parser = fn;
|
|
21667
|
+
return this;
|
|
21668
|
+
};
|
|
21669
|
+
|
|
21670
|
+
/**
|
|
21671
|
+
* Override default request body serializer
|
|
21672
|
+
*
|
|
21673
|
+
* This function will be called to convert data set via .send or .attach into payload to send
|
|
21674
|
+
*
|
|
21675
|
+
* @param {Function}
|
|
21676
|
+
* @api public
|
|
21677
|
+
*/
|
|
21678
|
+
|
|
21679
|
+
exports.serialize = function serialize(fn){
|
|
21680
|
+
this._serializer = fn;
|
|
21681
|
+
return this;
|
|
21682
|
+
};
|
|
21683
|
+
|
|
21684
|
+
/**
|
|
21685
|
+
* Set timeout to `ms`.
|
|
21686
|
+
*
|
|
21687
|
+
* @param {Number} ms
|
|
21688
|
+
* @return {Request} for chaining
|
|
21689
|
+
* @api public
|
|
21690
|
+
*/
|
|
21691
|
+
|
|
21692
|
+
exports.timeout = function timeout(ms){
|
|
21693
|
+
this._timeout = ms;
|
|
21694
|
+
return this;
|
|
21695
|
+
};
|
|
21696
|
+
|
|
21697
|
+
/**
|
|
21698
|
+
* Promise support
|
|
21699
|
+
*
|
|
21700
|
+
* @param {Function} resolve
|
|
21701
|
+
* @param {Function} reject
|
|
21702
|
+
* @return {Request}
|
|
21703
|
+
*/
|
|
21704
|
+
|
|
21705
|
+
exports.then = function then(resolve, reject) {
|
|
21706
|
+
if (!this._fullfilledPromise) {
|
|
21707
|
+
var self = this;
|
|
21708
|
+
this._fullfilledPromise = new Promise(function(innerResolve, innerReject){
|
|
21709
|
+
self.end(function(err, res){
|
|
21710
|
+
if (err) innerReject(err); else innerResolve(res);
|
|
21711
|
+
});
|
|
21712
|
+
});
|
|
21713
|
+
}
|
|
21714
|
+
return this._fullfilledPromise.then(resolve, reject);
|
|
21715
|
+
}
|
|
21716
|
+
|
|
21717
|
+
/**
|
|
21718
|
+
* Allow for extension
|
|
21719
|
+
*/
|
|
21720
|
+
|
|
21721
|
+
exports.use = function use(fn) {
|
|
21722
|
+
fn(this);
|
|
21723
|
+
return this;
|
|
21724
|
+
}
|
|
21725
|
+
|
|
21726
|
+
|
|
21727
|
+
/**
|
|
21728
|
+
* Get request header `field`.
|
|
21729
|
+
* Case-insensitive.
|
|
21730
|
+
*
|
|
21731
|
+
* @param {String} field
|
|
21732
|
+
* @return {String}
|
|
21733
|
+
* @api public
|
|
21734
|
+
*/
|
|
21735
|
+
|
|
21736
|
+
exports.get = function(field){
|
|
21737
|
+
return this._header[field.toLowerCase()];
|
|
21738
|
+
};
|
|
21739
|
+
|
|
21740
|
+
/**
|
|
21741
|
+
* Get case-insensitive header `field` value.
|
|
21742
|
+
* This is a deprecated internal API. Use `.get(field)` instead.
|
|
21743
|
+
*
|
|
21744
|
+
* (getHeader is no longer used internally by the superagent code base)
|
|
21745
|
+
*
|
|
21746
|
+
* @param {String} field
|
|
21747
|
+
* @return {String}
|
|
21748
|
+
* @api private
|
|
21749
|
+
* @deprecated
|
|
21750
|
+
*/
|
|
21751
|
+
|
|
21752
|
+
exports.getHeader = exports.get;
|
|
21753
|
+
|
|
21754
|
+
/**
|
|
21755
|
+
* Set header `field` to `val`, or multiple fields with one object.
|
|
21756
|
+
* Case-insensitive.
|
|
21757
|
+
*
|
|
21758
|
+
* Examples:
|
|
21759
|
+
*
|
|
21760
|
+
* req.get('/')
|
|
21761
|
+
* .set('Accept', 'application/json')
|
|
21762
|
+
* .set('X-API-Key', 'foobar')
|
|
21763
|
+
* .end(callback);
|
|
21764
|
+
*
|
|
21765
|
+
* req.get('/')
|
|
21766
|
+
* .set({ Accept: 'application/json', 'X-API-Key': 'foobar' })
|
|
21767
|
+
* .end(callback);
|
|
21768
|
+
*
|
|
21769
|
+
* @param {String|Object} field
|
|
21770
|
+
* @param {String} val
|
|
21771
|
+
* @return {Request} for chaining
|
|
21772
|
+
* @api public
|
|
21773
|
+
*/
|
|
21774
|
+
|
|
21775
|
+
exports.set = function(field, val){
|
|
21776
|
+
if (isObject(field)) {
|
|
21777
|
+
for (var key in field) {
|
|
21778
|
+
this.set(key, field[key]);
|
|
21779
|
+
}
|
|
21780
|
+
return this;
|
|
21781
|
+
}
|
|
21782
|
+
this._header[field.toLowerCase()] = val;
|
|
21783
|
+
this.header[field] = val;
|
|
21784
|
+
return this;
|
|
21785
|
+
};
|
|
21786
|
+
|
|
21787
|
+
/**
|
|
21788
|
+
* Remove header `field`.
|
|
21789
|
+
* Case-insensitive.
|
|
21790
|
+
*
|
|
21791
|
+
* Example:
|
|
21792
|
+
*
|
|
21793
|
+
* req.get('/')
|
|
21794
|
+
* .unset('User-Agent')
|
|
21795
|
+
* .end(callback);
|
|
21796
|
+
*
|
|
21797
|
+
* @param {String} field
|
|
21798
|
+
*/
|
|
21799
|
+
exports.unset = function(field){
|
|
21800
|
+
delete this._header[field.toLowerCase()];
|
|
21801
|
+
delete this.header[field];
|
|
21802
|
+
return this;
|
|
21803
|
+
};
|
|
21804
|
+
|
|
21805
|
+
/**
|
|
21806
|
+
* Write the field `name` and `val` for "multipart/form-data"
|
|
21807
|
+
* request bodies.
|
|
21808
|
+
*
|
|
21809
|
+
* ``` js
|
|
21810
|
+
* request.post('/upload')
|
|
21811
|
+
* .field('foo', 'bar')
|
|
21812
|
+
* .end(callback);
|
|
21813
|
+
* ```
|
|
21814
|
+
*
|
|
21815
|
+
* @param {String} name
|
|
21816
|
+
* @param {String|Blob|File|Buffer|fs.ReadStream} val
|
|
21817
|
+
* @return {Request} for chaining
|
|
21818
|
+
* @api public
|
|
21819
|
+
*/
|
|
21820
|
+
exports.field = function(name, val) {
|
|
21821
|
+
this._getFormData().append(name, val);
|
|
21822
|
+
return this;
|
|
21823
|
+
};
|
|
21824
|
+
|
|
21825
|
+
/**
|
|
21826
|
+
* Abort the request, and clear potential timeout.
|
|
21827
|
+
*
|
|
21828
|
+
* @return {Request}
|
|
21829
|
+
* @api public
|
|
21761
21830
|
*/
|
|
21831
|
+
exports.abort = function(){
|
|
21832
|
+
if (this._aborted) {
|
|
21833
|
+
return this;
|
|
21834
|
+
}
|
|
21835
|
+
this._aborted = true;
|
|
21836
|
+
this.xhr && this.xhr.abort(); // browser
|
|
21837
|
+
this.req && this.req.abort(); // node
|
|
21838
|
+
this.clearTimeout();
|
|
21839
|
+
this.emit('abort');
|
|
21840
|
+
return this;
|
|
21841
|
+
};
|
|
21842
|
+
|
|
21843
|
+
/**
|
|
21844
|
+
* Enable transmission of cookies with x-domain requests.
|
|
21845
|
+
*
|
|
21846
|
+
* Note that for this to work the origin must not be
|
|
21847
|
+
* using "Access-Control-Allow-Origin" with a wildcard,
|
|
21848
|
+
* and also must set "Access-Control-Allow-Credentials"
|
|
21849
|
+
* to "true".
|
|
21850
|
+
*
|
|
21851
|
+
* @api public
|
|
21852
|
+
*/
|
|
21853
|
+
|
|
21854
|
+
exports.withCredentials = function(){
|
|
21855
|
+
// This is browser-only functionality. Node side is no-op.
|
|
21856
|
+
this._withCredentials = true;
|
|
21857
|
+
return this;
|
|
21858
|
+
};
|
|
21859
|
+
|
|
21860
|
+
/**
|
|
21861
|
+
* Set the max redirects to `n`. Does noting in browser XHR implementation.
|
|
21862
|
+
*
|
|
21863
|
+
* @param {Number} n
|
|
21864
|
+
* @return {Request} for chaining
|
|
21865
|
+
* @api public
|
|
21866
|
+
*/
|
|
21867
|
+
|
|
21868
|
+
exports.redirects = function(n){
|
|
21869
|
+
this._maxRedirects = n;
|
|
21870
|
+
return this;
|
|
21871
|
+
};
|
|
21872
|
+
|
|
21873
|
+
/**
|
|
21874
|
+
* Convert to a plain javascript object (not JSON string) of scalar properties.
|
|
21875
|
+
* Note as this method is designed to return a useful non-this value,
|
|
21876
|
+
* it cannot be chained.
|
|
21877
|
+
*
|
|
21878
|
+
* @return {Object} describing method, url, and data of this request
|
|
21879
|
+
* @api public
|
|
21880
|
+
*/
|
|
21881
|
+
|
|
21882
|
+
exports.toJSON = function(){
|
|
21883
|
+
return {
|
|
21884
|
+
method: this.method,
|
|
21885
|
+
url: this.url,
|
|
21886
|
+
data: this._data
|
|
21887
|
+
};
|
|
21888
|
+
};
|
|
21889
|
+
|
|
21890
|
+
/**
|
|
21891
|
+
* Check if `obj` is a host object,
|
|
21892
|
+
* we don't want to serialize these :)
|
|
21893
|
+
*
|
|
21894
|
+
* TODO: future proof, move to compoent land
|
|
21895
|
+
*
|
|
21896
|
+
* @param {Object} obj
|
|
21897
|
+
* @return {Boolean}
|
|
21898
|
+
* @api private
|
|
21899
|
+
*/
|
|
21900
|
+
|
|
21901
|
+
exports._isHost = function _isHost(obj) {
|
|
21902
|
+
var str = {}.toString.call(obj);
|
|
21903
|
+
|
|
21904
|
+
switch (str) {
|
|
21905
|
+
case '[object File]':
|
|
21906
|
+
case '[object Blob]':
|
|
21907
|
+
case '[object FormData]':
|
|
21908
|
+
return true;
|
|
21909
|
+
default:
|
|
21910
|
+
return false;
|
|
21911
|
+
}
|
|
21912
|
+
}
|
|
21913
|
+
|
|
21914
|
+
/**
|
|
21915
|
+
* Send `data` as the request body, defaulting the `.type()` to "json" when
|
|
21916
|
+
* an object is given.
|
|
21917
|
+
*
|
|
21918
|
+
* Examples:
|
|
21919
|
+
*
|
|
21920
|
+
* // manual json
|
|
21921
|
+
* request.post('/user')
|
|
21922
|
+
* .type('json')
|
|
21923
|
+
* .send('{"name":"tj"}')
|
|
21924
|
+
* .end(callback)
|
|
21925
|
+
*
|
|
21926
|
+
* // auto json
|
|
21927
|
+
* request.post('/user')
|
|
21928
|
+
* .send({ name: 'tj' })
|
|
21929
|
+
* .end(callback)
|
|
21930
|
+
*
|
|
21931
|
+
* // manual x-www-form-urlencoded
|
|
21932
|
+
* request.post('/user')
|
|
21933
|
+
* .type('form')
|
|
21934
|
+
* .send('name=tj')
|
|
21935
|
+
* .end(callback)
|
|
21936
|
+
*
|
|
21937
|
+
* // auto x-www-form-urlencoded
|
|
21938
|
+
* request.post('/user')
|
|
21939
|
+
* .type('form')
|
|
21940
|
+
* .send({ name: 'tj' })
|
|
21941
|
+
* .end(callback)
|
|
21942
|
+
*
|
|
21943
|
+
* // defaults to x-www-form-urlencoded
|
|
21944
|
+
* request.post('/user')
|
|
21945
|
+
* .send('name=tobi')
|
|
21946
|
+
* .send('species=ferret')
|
|
21947
|
+
* .end(callback)
|
|
21948
|
+
*
|
|
21949
|
+
* @param {String|Object} data
|
|
21950
|
+
* @return {Request} for chaining
|
|
21951
|
+
* @api public
|
|
21952
|
+
*/
|
|
21953
|
+
|
|
21954
|
+
exports.send = function(data){
|
|
21955
|
+
var obj = isObject(data);
|
|
21956
|
+
var type = this._header['content-type'];
|
|
21957
|
+
|
|
21958
|
+
// merge
|
|
21959
|
+
if (obj && isObject(this._data)) {
|
|
21960
|
+
for (var key in data) {
|
|
21961
|
+
this._data[key] = data[key];
|
|
21962
|
+
}
|
|
21963
|
+
} else if ('string' == typeof data) {
|
|
21964
|
+
// default to x-www-form-urlencoded
|
|
21965
|
+
if (!type) this.type('form');
|
|
21966
|
+
type = this._header['content-type'];
|
|
21967
|
+
if ('application/x-www-form-urlencoded' == type) {
|
|
21968
|
+
this._data = this._data
|
|
21969
|
+
? this._data + '&' + data
|
|
21970
|
+
: data;
|
|
21971
|
+
} else {
|
|
21972
|
+
this._data = (this._data || '') + data;
|
|
21973
|
+
}
|
|
21974
|
+
} else {
|
|
21975
|
+
this._data = data;
|
|
21976
|
+
}
|
|
21977
|
+
|
|
21978
|
+
if (!obj || this._isHost(data)) return this;
|
|
21979
|
+
|
|
21980
|
+
// default to json
|
|
21981
|
+
if (!type) this.type('json');
|
|
21982
|
+
return this;
|
|
21983
|
+
};
|
|
21984
|
+
|
|
21985
|
+
},{"./is-object":50}],52:[function(require,module,exports){
|
|
21986
|
+
// The node and browser modules expose versions of this with the
|
|
21987
|
+
// appropriate constructor function bound as first argument
|
|
21988
|
+
/**
|
|
21989
|
+
* Issue a request:
|
|
21990
|
+
*
|
|
21991
|
+
* Examples:
|
|
21992
|
+
*
|
|
21993
|
+
* request('GET', '/users').end(callback)
|
|
21994
|
+
* request('/users').end(callback)
|
|
21995
|
+
* request('/users', callback)
|
|
21996
|
+
*
|
|
21997
|
+
* @param {String} method
|
|
21998
|
+
* @param {String|Function} url or callback
|
|
21999
|
+
* @return {Request}
|
|
22000
|
+
* @api public
|
|
22001
|
+
*/
|
|
22002
|
+
|
|
22003
|
+
function request(RequestConstructor, method, url) {
|
|
22004
|
+
// callback
|
|
22005
|
+
if ('function' == typeof url) {
|
|
22006
|
+
return new RequestConstructor('GET', method).end(url);
|
|
22007
|
+
}
|
|
22008
|
+
|
|
22009
|
+
// url first
|
|
22010
|
+
if (2 == arguments.length) {
|
|
22011
|
+
return new RequestConstructor('GET', method);
|
|
22012
|
+
}
|
|
22013
|
+
|
|
22014
|
+
return new RequestConstructor(method, url);
|
|
22015
|
+
}
|
|
21762
22016
|
|
|
21763
22017
|
module.exports = request;
|
|
21764
22018
|
|
|
21765
|
-
},{
|
|
22019
|
+
},{}],53:[function(require,module,exports){
|
|
21766
22020
|
/*!
|
|
21767
22021
|
* validate.js 0.9.0
|
|
21768
22022
|
*
|