comprodls-sdk 2.65.0 → 2.67.1
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 +1004 -535
- package/dist/comprodls-sdk.min.js +15 -15
- package/lib/config/index.js +5 -1
- package/lib/services/authextn/index.js +271 -2
- package/package.json +1 -1
- package/test.js +38 -0
package/dist/comprodls-sdk.js
CHANGED
|
@@ -396,7 +396,11 @@ exports.AUTHEXTN_API_URLS = {
|
|
|
396
396
|
userAssignedPaths: '/org/{orgid}/classes/{classid}/assigned-paths/{assignedpathid}/enroll-user/multi',
|
|
397
397
|
|
|
398
398
|
// Class related APIs
|
|
399
|
-
particularClass: '/org/{orgId}/classes/{classId}'
|
|
399
|
+
particularClass: '/org/{orgId}/classes/{classId}',
|
|
400
|
+
|
|
401
|
+
// Org Entitlement related APIs
|
|
402
|
+
orgProductEntitlement: '/org/{orgid}/org-entitlements',
|
|
403
|
+
setupUser: '/accounts/{accountId}/user/setup'
|
|
400
404
|
|
|
401
405
|
};
|
|
402
406
|
|
|
@@ -1146,7 +1150,7 @@ validator.validators.contains = function(value, options) {
|
|
|
1146
1150
|
}
|
|
1147
1151
|
}
|
|
1148
1152
|
};
|
|
1149
|
-
},{"./errors":7,"validate.js":
|
|
1153
|
+
},{"./errors":7,"validate.js":53}],10:[function(require,module,exports){
|
|
1150
1154
|
/*************************************************************************
|
|
1151
1155
|
*
|
|
1152
1156
|
* COMPRO CONFIDENTIAL
|
|
@@ -8714,8 +8718,10 @@ var keepaliveAgent = new Agent({
|
|
|
8714
8718
|
});
|
|
8715
8719
|
|
|
8716
8720
|
//AuthExtn Adaptor Contsructor
|
|
8717
|
-
function authextn() {
|
|
8721
|
+
function authextn(accountId) {
|
|
8722
|
+
this.accountId = accountId;
|
|
8718
8723
|
return {
|
|
8724
|
+
// Gradeformat related APIs
|
|
8719
8725
|
createGradeformat: createGradeformat.bind(this),
|
|
8720
8726
|
updateGradeformat: updateGradeformat.bind(this),
|
|
8721
8727
|
deleteGradeformat: deleteGradeformat.bind(this),
|
|
@@ -8727,9 +8733,21 @@ function authextn() {
|
|
|
8727
8733
|
getParticularGradeformatOfAClass: getParticularGradeformatOfAClass.bind(this),
|
|
8728
8734
|
getAllGradeformatsOfAClass: getAllGradeformatsOfAClass.bind(this),
|
|
8729
8735
|
getClassesOfAGradeformat: getClassesOfAGradeformat.bind(this),
|
|
8736
|
+
|
|
8737
|
+
// Assigned-path related APIs
|
|
8730
8738
|
createUserAssignedPathEnrollments: createUserAssignedPathEnrollments.bind(this),
|
|
8731
8739
|
deleteUserAssignedPathEnrollments: deleteUserAssignedPathEnrollments.bind(this),
|
|
8732
|
-
|
|
8740
|
+
|
|
8741
|
+
// Class related APIs
|
|
8742
|
+
getParticularClassV2: getParticularClassV2.bind(this),
|
|
8743
|
+
|
|
8744
|
+
// Org Entitlement related APIs
|
|
8745
|
+
createOrgProductEntitlement: createOrgProductEntitlement.bind(this),
|
|
8746
|
+
updateOrgProductEntitlement: updateOrgProductEntitlement.bind(this),
|
|
8747
|
+
getParticularOrgProductEntitlement: getParticularOrgProductEntitlement.bind(this),
|
|
8748
|
+
getAllOrgProductEntitlements: getAllOrgProductEntitlements.bind(this),
|
|
8749
|
+
setupUser: setupUser.bind(this)
|
|
8750
|
+
|
|
8733
8751
|
};
|
|
8734
8752
|
}
|
|
8735
8753
|
|
|
@@ -9556,6 +9574,261 @@ function getParticularClassV2(options) {
|
|
|
9556
9574
|
|
|
9557
9575
|
return deferred.promise;
|
|
9558
9576
|
}
|
|
9577
|
+
|
|
9578
|
+
/**
|
|
9579
|
+
* @param {
|
|
9580
|
+
* *productcode: "string",
|
|
9581
|
+
* status: "string" // ['active', 'revoked'] - default: 'active'
|
|
9582
|
+
* expired: <boolean>, // default: false
|
|
9583
|
+
* startdate: <epoch>,
|
|
9584
|
+
* enddate: <epoch>,
|
|
9585
|
+
* audit: <boolean> // [true] - default: true
|
|
9586
|
+
* ext_data: {...},
|
|
9587
|
+
* } options
|
|
9588
|
+
*/
|
|
9589
|
+
function createOrgProductEntitlement(options) {
|
|
9590
|
+
var self = this;
|
|
9591
|
+
// Initializing promise
|
|
9592
|
+
var dfd = q.defer();
|
|
9593
|
+
if (!self.orgId) {
|
|
9594
|
+
var err = {};
|
|
9595
|
+
err.message = err.description = 'Mandatory param: orgid not found in options while ' +
|
|
9596
|
+
'initializing comprodls-sdk.';
|
|
9597
|
+
err = new DLSError(helpers.errors.ERROR_TYPES.SDK_ERROR, err);
|
|
9598
|
+
dfd.reject(err);
|
|
9599
|
+
} else {
|
|
9600
|
+
if (options && options.productcode) {
|
|
9601
|
+
// Passed all validations, Contruct API url
|
|
9602
|
+
var url = self.config.DEFAULT_HOSTS.AUTHEXTN +
|
|
9603
|
+
self.config.AUTHEXTN_API_URLS.orgProductEntitlement;
|
|
9604
|
+
url = helpers.api.constructAPIUrl(url, { orgid: self.orgId });
|
|
9605
|
+
|
|
9606
|
+
var requestAPI = request.post(url)
|
|
9607
|
+
.set('Content-Type', 'application/json')
|
|
9608
|
+
.set('Accept', 'application/json')
|
|
9609
|
+
.send(options);
|
|
9610
|
+
|
|
9611
|
+
if(self.traceid) { requestAPI.set('X-Amzn-Trace-Id', self.traceid); }
|
|
9612
|
+
|
|
9613
|
+
requestAPI
|
|
9614
|
+
.agent(keepaliveAgent)
|
|
9615
|
+
.end(function(error, response) {
|
|
9616
|
+
if (error) {
|
|
9617
|
+
var err = new DLSError(helpers.errors.ERROR_TYPES.API_ERROR, error);
|
|
9618
|
+
dfd.reject(err);
|
|
9619
|
+
}
|
|
9620
|
+
else { dfd.resolve(response.body); }
|
|
9621
|
+
});
|
|
9622
|
+
} else {
|
|
9623
|
+
var err = {};
|
|
9624
|
+
err.message = err.description = 'Mandatory param: productcode not found in request options.';
|
|
9625
|
+
err = new DLSError(helpers.errors.ERROR_TYPES.SDK_ERROR, err);
|
|
9626
|
+
dfd.reject(err);
|
|
9627
|
+
}
|
|
9628
|
+
}
|
|
9629
|
+
return dfd.promise;
|
|
9630
|
+
}
|
|
9631
|
+
|
|
9632
|
+
/**
|
|
9633
|
+
* @param {
|
|
9634
|
+
* *productcode: "string",
|
|
9635
|
+
* status: "string" // ['active', 'revoked']
|
|
9636
|
+
* expired: <boolean>,
|
|
9637
|
+
* startdate: <epoch>,
|
|
9638
|
+
* enddate: <epoch>,
|
|
9639
|
+
* audit: <boolean> // [true] - default: true
|
|
9640
|
+
* ext_data: {...},
|
|
9641
|
+
* } options
|
|
9642
|
+
*/
|
|
9643
|
+
function updateOrgProductEntitlement(options) {
|
|
9644
|
+
var self = this;
|
|
9645
|
+
// Initializing promise
|
|
9646
|
+
var dfd = q.defer();
|
|
9647
|
+
|
|
9648
|
+
if (!self.orgId) {
|
|
9649
|
+
var err = {};
|
|
9650
|
+
err.message = err.description = 'Mandatory param: orgid not found in options while ' +
|
|
9651
|
+
'initializing comprodls-sdk.';
|
|
9652
|
+
err = new DLSError(helpers.errors.ERROR_TYPES.SDK_ERROR, err);
|
|
9653
|
+
dfd.reject(err);
|
|
9654
|
+
} else {
|
|
9655
|
+
if (options && options.productcode) {
|
|
9656
|
+
// Passed all validations, Contruct API url
|
|
9657
|
+
var url = self.config.DEFAULT_HOSTS.AUTHEXTN +
|
|
9658
|
+
self.config.AUTHEXTN_API_URLS.orgProductEntitlement;
|
|
9659
|
+
url = helpers.api.constructAPIUrl(url, { orgid: self.orgId });
|
|
9660
|
+
|
|
9661
|
+
var requestAPI = request.put(url)
|
|
9662
|
+
.set('Content-Type', 'application/json')
|
|
9663
|
+
.set('Accept', 'application/json')
|
|
9664
|
+
.send(options);
|
|
9665
|
+
|
|
9666
|
+
if (self.traceid) { requestAPI.set('X-Amzn-Trace-Id', self.traceid); }
|
|
9667
|
+
|
|
9668
|
+
requestAPI
|
|
9669
|
+
.agent(keepaliveAgent)
|
|
9670
|
+
.end(function(error, response) {
|
|
9671
|
+
if (error) {
|
|
9672
|
+
var err = new DLSError(helpers.errors.ERROR_TYPES.API_ERROR, error);
|
|
9673
|
+
dfd.reject(err);
|
|
9674
|
+
}
|
|
9675
|
+
else { dfd.resolve(response.body); }
|
|
9676
|
+
});
|
|
9677
|
+
} else {
|
|
9678
|
+
var err = {};
|
|
9679
|
+
err.message = err.description = 'Mandatory param: productcode not found in request options.';
|
|
9680
|
+
err = new DLSError(helpers.errors.ERROR_TYPES.SDK_ERROR, err);
|
|
9681
|
+
dfd.reject(err);
|
|
9682
|
+
}
|
|
9683
|
+
}
|
|
9684
|
+
|
|
9685
|
+
return dfd.promise;
|
|
9686
|
+
}
|
|
9687
|
+
|
|
9688
|
+
/**
|
|
9689
|
+
* @param {
|
|
9690
|
+
* *productcode: "string"
|
|
9691
|
+
* } options
|
|
9692
|
+
*/
|
|
9693
|
+
function getParticularOrgProductEntitlement(options) {
|
|
9694
|
+
var self = this;
|
|
9695
|
+
//Initializing promise
|
|
9696
|
+
var deferred = q.defer();
|
|
9697
|
+
|
|
9698
|
+
//Validations
|
|
9699
|
+
var error = helpers.validations.isAuthenticated(self.orgId, self.token);
|
|
9700
|
+
if (error) {
|
|
9701
|
+
deferred.reject(error);
|
|
9702
|
+
} else {
|
|
9703
|
+
if (options && options.productcode) {
|
|
9704
|
+
// Passed all validations, Contruct the API URL
|
|
9705
|
+
var url = self.config.DEFAULT_HOSTS.AUTHEXTN +
|
|
9706
|
+
self.config.AUTHEXTN_API_URLS.orgProductEntitlement;
|
|
9707
|
+
url = helpers.api.constructAPIUrl(url, { orgid: self.orgId });
|
|
9708
|
+
|
|
9709
|
+
// Setup request with URL and Query Params
|
|
9710
|
+
var params = { productcode: options.productcode };
|
|
9711
|
+
var requestAPI = request.get(url).query(params);
|
|
9712
|
+
|
|
9713
|
+
// Setup 'traceid' in request header
|
|
9714
|
+
if (self.traceid) { requestAPI.set('X-Amzn-Trace-Id', self.traceid); }
|
|
9715
|
+
|
|
9716
|
+
// Setup 'token' in Authorization header
|
|
9717
|
+
requestAPI = helpers.api.setupAPIToken(requestAPI, self.token);
|
|
9718
|
+
|
|
9719
|
+
requestAPI.agent(keepaliveAgent).end(function (error, response) {
|
|
9720
|
+
if (error) {
|
|
9721
|
+
error = new DLSError(helpers.errors.ERROR_TYPES.API_ERROR, error);
|
|
9722
|
+
deferred.reject(error);
|
|
9723
|
+
} else {
|
|
9724
|
+
deferred.resolve(response.body);
|
|
9725
|
+
}
|
|
9726
|
+
});
|
|
9727
|
+
} else {
|
|
9728
|
+
error = {};
|
|
9729
|
+
error.message = error.description = 'Mandatory field \'productcode\' not found '+
|
|
9730
|
+
'in request options.';
|
|
9731
|
+
error = new DLSError(helpers.errors.ERROR_TYPES.SDK_ERROR, error);
|
|
9732
|
+
deferred.reject(error);
|
|
9733
|
+
}
|
|
9734
|
+
}
|
|
9735
|
+
|
|
9736
|
+
return deferred.promise;
|
|
9737
|
+
}
|
|
9738
|
+
|
|
9739
|
+
/**
|
|
9740
|
+
* @param {
|
|
9741
|
+
* status: "string" // ['active', 'revoked']
|
|
9742
|
+
* expired: <boolean>,
|
|
9743
|
+
* cursor: <epoch>
|
|
9744
|
+
* } options
|
|
9745
|
+
*/
|
|
9746
|
+
function getAllOrgProductEntitlements(options) {
|
|
9747
|
+
var self = this;
|
|
9748
|
+
//Initializing promise
|
|
9749
|
+
var deferred = q.defer();
|
|
9750
|
+
|
|
9751
|
+
//Validations
|
|
9752
|
+
var error = helpers.validations.isAuthenticated(self.orgId, self.token);
|
|
9753
|
+
if (error) {
|
|
9754
|
+
deferred.reject(error);
|
|
9755
|
+
} else {
|
|
9756
|
+
// Passed all validations, Contruct the API URL
|
|
9757
|
+
var url = self.config.DEFAULT_HOSTS.AUTHEXTN +
|
|
9758
|
+
self.config.AUTHEXTN_API_URLS.orgProductEntitlement;
|
|
9759
|
+
url = helpers.api.constructAPIUrl(url, { orgid: self.orgId });
|
|
9760
|
+
|
|
9761
|
+
// Setup request with URL and Query Params
|
|
9762
|
+
var params = { productcode: options.productcode };
|
|
9763
|
+
|
|
9764
|
+
if (options.status) { params.status = options.status; }
|
|
9765
|
+
if (options.hasOwnProperty('expired')) { params.expired = options.expired; }
|
|
9766
|
+
if (options.cursor) { params.cursor = options.cursor; }
|
|
9767
|
+
|
|
9768
|
+
var requestAPI = request.get(url).query(params);
|
|
9769
|
+
|
|
9770
|
+
// Setup 'traceid' in request header
|
|
9771
|
+
if (self.traceid) { requestAPI.set('X-Amzn-Trace-Id', self.traceid); }
|
|
9772
|
+
|
|
9773
|
+
// Setup 'token' in Authorization header
|
|
9774
|
+
requestAPI = helpers.api.setupAPIToken(requestAPI, self.token);
|
|
9775
|
+
|
|
9776
|
+
requestAPI.agent(keepaliveAgent).end(function (error, response) {
|
|
9777
|
+
if (error) {
|
|
9778
|
+
error = new DLSError(helpers.errors.ERROR_TYPES.API_ERROR, error);
|
|
9779
|
+
deferred.reject(error);
|
|
9780
|
+
} else {
|
|
9781
|
+
deferred.resolve(response.body);
|
|
9782
|
+
}
|
|
9783
|
+
});
|
|
9784
|
+
}
|
|
9785
|
+
|
|
9786
|
+
return deferred.promise;
|
|
9787
|
+
}
|
|
9788
|
+
|
|
9789
|
+
/**
|
|
9790
|
+
* @param {
|
|
9791
|
+
* ext_user_id: "string", // mandatory
|
|
9792
|
+
* workflow_type: "string", // mandatory
|
|
9793
|
+
* <workflow_type>: {} // mandatory
|
|
9794
|
+
* } options
|
|
9795
|
+
*/
|
|
9796
|
+
function setupUser(options) {
|
|
9797
|
+
var self = this;
|
|
9798
|
+
//Initializing promise
|
|
9799
|
+
var deferred = q.defer();
|
|
9800
|
+
|
|
9801
|
+
if(options && options.ext_user_id && options.workflow_type) {
|
|
9802
|
+
//Passed all validations, Contruct API url
|
|
9803
|
+
var url = self.config.DEFAULT_HOSTS.AUTHEXTN + self.config.AUTHEXTN_API_URLS.setupUser;
|
|
9804
|
+
url = helpers.api.constructAPIUrl(url, { accountId: self.accountId });
|
|
9805
|
+
|
|
9806
|
+
var requestAPI = request.post(url)
|
|
9807
|
+
.set('Content-Type', 'application/json')
|
|
9808
|
+
.set('Accept', 'application/json')
|
|
9809
|
+
.send(options);
|
|
9810
|
+
|
|
9811
|
+
if(self.traceid) { requestAPI.set('X-Amzn-Trace-Id', self.traceid); }
|
|
9812
|
+
|
|
9813
|
+
requestAPI
|
|
9814
|
+
.agent(keepaliveAgent)
|
|
9815
|
+
.end(function(err, res) {
|
|
9816
|
+
if(err) {
|
|
9817
|
+
err = new DLSError(helpers.errors.ERROR_TYPES.API_ERROR, err);
|
|
9818
|
+
deferred.reject(err);
|
|
9819
|
+
} else {
|
|
9820
|
+
deferred.resolve(res.body);
|
|
9821
|
+
}
|
|
9822
|
+
});
|
|
9823
|
+
} else {
|
|
9824
|
+
err = {};
|
|
9825
|
+
err.message = err.description = 'Mandatory field \'ext_user_id\' or \'workflow_type\' not found '+
|
|
9826
|
+
'in the request options.';
|
|
9827
|
+
err = new DLSError(helpers.errors.ERROR_TYPES.SDK_ERROR, err);
|
|
9828
|
+
deferred.reject(err);
|
|
9829
|
+
}
|
|
9830
|
+
return deferred.promise;
|
|
9831
|
+
}
|
|
9559
9832
|
|
|
9560
9833
|
},{"../../helpers":3,"agentkeepalive":36,"q":46,"superagent":49}],18:[function(require,module,exports){
|
|
9561
9834
|
/*************************************************************************
|
|
@@ -17937,167 +18210,181 @@ module.exports = Array.isArray || function (arr) {
|
|
|
17937
18210
|
};
|
|
17938
18211
|
|
|
17939
18212
|
},{}],40:[function(require,module,exports){
|
|
17940
|
-
|
|
17941
|
-
/**
|
|
17942
|
-
* Expose `Emitter`.
|
|
17943
|
-
*/
|
|
17944
|
-
|
|
17945
|
-
module
|
|
17946
|
-
|
|
17947
|
-
|
|
17948
|
-
|
|
17949
|
-
|
|
17950
|
-
*
|
|
17951
|
-
|
|
17952
|
-
|
|
17953
|
-
|
|
17954
|
-
|
|
17955
|
-
|
|
17956
|
-
|
|
17957
|
-
|
|
17958
|
-
|
|
17959
|
-
|
|
17960
|
-
*
|
|
17961
|
-
*
|
|
17962
|
-
* @
|
|
17963
|
-
|
|
17964
|
-
|
|
17965
|
-
|
|
17966
|
-
|
|
17967
|
-
|
|
17968
|
-
|
|
17969
|
-
|
|
17970
|
-
}
|
|
17971
|
-
|
|
17972
|
-
|
|
17973
|
-
|
|
17974
|
-
|
|
17975
|
-
*
|
|
17976
|
-
*
|
|
17977
|
-
* @
|
|
17978
|
-
* @
|
|
17979
|
-
|
|
17980
|
-
|
|
17981
|
-
|
|
17982
|
-
|
|
17983
|
-
|
|
17984
|
-
|
|
17985
|
-
|
|
17986
|
-
|
|
17987
|
-
|
|
17988
|
-
|
|
17989
|
-
|
|
17990
|
-
|
|
17991
|
-
|
|
17992
|
-
*
|
|
17993
|
-
*
|
|
17994
|
-
*
|
|
17995
|
-
* @
|
|
17996
|
-
* @
|
|
17997
|
-
|
|
17998
|
-
|
|
17999
|
-
|
|
18000
|
-
|
|
18001
|
-
|
|
18002
|
-
|
|
18003
|
-
|
|
18004
|
-
|
|
18005
|
-
|
|
18006
|
-
|
|
18007
|
-
|
|
18008
|
-
|
|
18009
|
-
|
|
18010
|
-
|
|
18011
|
-
|
|
18012
|
-
|
|
18013
|
-
*
|
|
18014
|
-
*
|
|
18015
|
-
*
|
|
18016
|
-
* @
|
|
18017
|
-
* @
|
|
18018
|
-
|
|
18019
|
-
|
|
18020
|
-
|
|
18021
|
-
|
|
18022
|
-
Emitter.prototype.
|
|
18023
|
-
Emitter.prototype.
|
|
18024
|
-
|
|
18025
|
-
|
|
18026
|
-
|
|
18027
|
-
|
|
18028
|
-
|
|
18029
|
-
|
|
18030
|
-
|
|
18031
|
-
|
|
18032
|
-
|
|
18033
|
-
|
|
18034
|
-
|
|
18035
|
-
|
|
18036
|
-
|
|
18037
|
-
|
|
18038
|
-
|
|
18039
|
-
|
|
18040
|
-
|
|
18041
|
-
|
|
18042
|
-
|
|
18043
|
-
|
|
18044
|
-
|
|
18045
|
-
|
|
18046
|
-
|
|
18047
|
-
|
|
18048
|
-
|
|
18049
|
-
|
|
18050
|
-
|
|
18051
|
-
|
|
18052
|
-
}
|
|
18053
|
-
|
|
18054
|
-
|
|
18055
|
-
|
|
18056
|
-
|
|
18057
|
-
|
|
18058
|
-
|
|
18059
|
-
|
|
18060
|
-
|
|
18061
|
-
|
|
18062
|
-
|
|
18063
|
-
|
|
18064
|
-
|
|
18065
|
-
|
|
18066
|
-
|
|
18067
|
-
|
|
18068
|
-
|
|
18069
|
-
|
|
18070
|
-
|
|
18071
|
-
|
|
18072
|
-
}
|
|
18073
|
-
|
|
18074
|
-
|
|
18075
|
-
|
|
18076
|
-
|
|
18077
|
-
|
|
18078
|
-
|
|
18079
|
-
|
|
18080
|
-
|
|
18081
|
-
|
|
18082
|
-
|
|
18083
|
-
|
|
18084
|
-
|
|
18085
|
-
|
|
18086
|
-
|
|
18087
|
-
|
|
18088
|
-
|
|
18089
|
-
|
|
18090
|
-
|
|
18091
|
-
|
|
18092
|
-
*
|
|
18093
|
-
*
|
|
18094
|
-
* @
|
|
18095
|
-
* @
|
|
18096
|
-
|
|
18097
|
-
|
|
18098
|
-
|
|
18099
|
-
|
|
18100
|
-
};
|
|
18213
|
+
|
|
18214
|
+
/**
|
|
18215
|
+
* Expose `Emitter`.
|
|
18216
|
+
*/
|
|
18217
|
+
|
|
18218
|
+
if (typeof module !== 'undefined') {
|
|
18219
|
+
module.exports = Emitter;
|
|
18220
|
+
}
|
|
18221
|
+
|
|
18222
|
+
/**
|
|
18223
|
+
* Initialize a new `Emitter`.
|
|
18224
|
+
*
|
|
18225
|
+
* @api public
|
|
18226
|
+
*/
|
|
18227
|
+
|
|
18228
|
+
function Emitter(obj) {
|
|
18229
|
+
if (obj) return mixin(obj);
|
|
18230
|
+
};
|
|
18231
|
+
|
|
18232
|
+
/**
|
|
18233
|
+
* Mixin the emitter properties.
|
|
18234
|
+
*
|
|
18235
|
+
* @param {Object} obj
|
|
18236
|
+
* @return {Object}
|
|
18237
|
+
* @api private
|
|
18238
|
+
*/
|
|
18239
|
+
|
|
18240
|
+
function mixin(obj) {
|
|
18241
|
+
for (var key in Emitter.prototype) {
|
|
18242
|
+
obj[key] = Emitter.prototype[key];
|
|
18243
|
+
}
|
|
18244
|
+
return obj;
|
|
18245
|
+
}
|
|
18246
|
+
|
|
18247
|
+
/**
|
|
18248
|
+
* Listen on the given `event` with `fn`.
|
|
18249
|
+
*
|
|
18250
|
+
* @param {String} event
|
|
18251
|
+
* @param {Function} fn
|
|
18252
|
+
* @return {Emitter}
|
|
18253
|
+
* @api public
|
|
18254
|
+
*/
|
|
18255
|
+
|
|
18256
|
+
Emitter.prototype.on =
|
|
18257
|
+
Emitter.prototype.addEventListener = function(event, fn){
|
|
18258
|
+
this._callbacks = this._callbacks || {};
|
|
18259
|
+
(this._callbacks['$' + event] = this._callbacks['$' + event] || [])
|
|
18260
|
+
.push(fn);
|
|
18261
|
+
return this;
|
|
18262
|
+
};
|
|
18263
|
+
|
|
18264
|
+
/**
|
|
18265
|
+
* Adds an `event` listener that will be invoked a single
|
|
18266
|
+
* time then automatically removed.
|
|
18267
|
+
*
|
|
18268
|
+
* @param {String} event
|
|
18269
|
+
* @param {Function} fn
|
|
18270
|
+
* @return {Emitter}
|
|
18271
|
+
* @api public
|
|
18272
|
+
*/
|
|
18273
|
+
|
|
18274
|
+
Emitter.prototype.once = function(event, fn){
|
|
18275
|
+
function on() {
|
|
18276
|
+
this.off(event, on);
|
|
18277
|
+
fn.apply(this, arguments);
|
|
18278
|
+
}
|
|
18279
|
+
|
|
18280
|
+
on.fn = fn;
|
|
18281
|
+
this.on(event, on);
|
|
18282
|
+
return this;
|
|
18283
|
+
};
|
|
18284
|
+
|
|
18285
|
+
/**
|
|
18286
|
+
* Remove the given callback for `event` or all
|
|
18287
|
+
* registered callbacks.
|
|
18288
|
+
*
|
|
18289
|
+
* @param {String} event
|
|
18290
|
+
* @param {Function} fn
|
|
18291
|
+
* @return {Emitter}
|
|
18292
|
+
* @api public
|
|
18293
|
+
*/
|
|
18294
|
+
|
|
18295
|
+
Emitter.prototype.off =
|
|
18296
|
+
Emitter.prototype.removeListener =
|
|
18297
|
+
Emitter.prototype.removeAllListeners =
|
|
18298
|
+
Emitter.prototype.removeEventListener = function(event, fn){
|
|
18299
|
+
this._callbacks = this._callbacks || {};
|
|
18300
|
+
|
|
18301
|
+
// all
|
|
18302
|
+
if (0 == arguments.length) {
|
|
18303
|
+
this._callbacks = {};
|
|
18304
|
+
return this;
|
|
18305
|
+
}
|
|
18306
|
+
|
|
18307
|
+
// specific event
|
|
18308
|
+
var callbacks = this._callbacks['$' + event];
|
|
18309
|
+
if (!callbacks) return this;
|
|
18310
|
+
|
|
18311
|
+
// remove all handlers
|
|
18312
|
+
if (1 == arguments.length) {
|
|
18313
|
+
delete this._callbacks['$' + event];
|
|
18314
|
+
return this;
|
|
18315
|
+
}
|
|
18316
|
+
|
|
18317
|
+
// remove specific handler
|
|
18318
|
+
var cb;
|
|
18319
|
+
for (var i = 0; i < callbacks.length; i++) {
|
|
18320
|
+
cb = callbacks[i];
|
|
18321
|
+
if (cb === fn || cb.fn === fn) {
|
|
18322
|
+
callbacks.splice(i, 1);
|
|
18323
|
+
break;
|
|
18324
|
+
}
|
|
18325
|
+
}
|
|
18326
|
+
|
|
18327
|
+
// Remove event specific arrays for event types that no
|
|
18328
|
+
// one is subscribed for to avoid memory leak.
|
|
18329
|
+
if (callbacks.length === 0) {
|
|
18330
|
+
delete this._callbacks['$' + event];
|
|
18331
|
+
}
|
|
18332
|
+
|
|
18333
|
+
return this;
|
|
18334
|
+
};
|
|
18335
|
+
|
|
18336
|
+
/**
|
|
18337
|
+
* Emit `event` with the given args.
|
|
18338
|
+
*
|
|
18339
|
+
* @param {String} event
|
|
18340
|
+
* @param {Mixed} ...
|
|
18341
|
+
* @return {Emitter}
|
|
18342
|
+
*/
|
|
18343
|
+
|
|
18344
|
+
Emitter.prototype.emit = function(event){
|
|
18345
|
+
this._callbacks = this._callbacks || {};
|
|
18346
|
+
|
|
18347
|
+
var args = new Array(arguments.length - 1)
|
|
18348
|
+
, callbacks = this._callbacks['$' + event];
|
|
18349
|
+
|
|
18350
|
+
for (var i = 1; i < arguments.length; i++) {
|
|
18351
|
+
args[i - 1] = arguments[i];
|
|
18352
|
+
}
|
|
18353
|
+
|
|
18354
|
+
if (callbacks) {
|
|
18355
|
+
callbacks = callbacks.slice(0);
|
|
18356
|
+
for (var i = 0, len = callbacks.length; i < len; ++i) {
|
|
18357
|
+
callbacks[i].apply(this, args);
|
|
18358
|
+
}
|
|
18359
|
+
}
|
|
18360
|
+
|
|
18361
|
+
return this;
|
|
18362
|
+
};
|
|
18363
|
+
|
|
18364
|
+
/**
|
|
18365
|
+
* Return array of callbacks for `event`.
|
|
18366
|
+
*
|
|
18367
|
+
* @param {String} event
|
|
18368
|
+
* @return {Array}
|
|
18369
|
+
* @api public
|
|
18370
|
+
*/
|
|
18371
|
+
|
|
18372
|
+
Emitter.prototype.listeners = function(event){
|
|
18373
|
+
this._callbacks = this._callbacks || {};
|
|
18374
|
+
return this._callbacks['$' + event] || [];
|
|
18375
|
+
};
|
|
18376
|
+
|
|
18377
|
+
/**
|
|
18378
|
+
* Check if this emitter has `event` handlers.
|
|
18379
|
+
*
|
|
18380
|
+
* @param {String} event
|
|
18381
|
+
* @return {Boolean}
|
|
18382
|
+
* @api public
|
|
18383
|
+
*/
|
|
18384
|
+
|
|
18385
|
+
Emitter.prototype.hasListeners = function(event){
|
|
18386
|
+
return !! this.listeners(event).length;
|
|
18387
|
+
};
|
|
18101
18388
|
|
|
18102
18389
|
},{}],41:[function(require,module,exports){
|
|
18103
18390
|
// Copyright Joyent, Inc. and other Node contributors.
|
|
@@ -18403,6 +18690,8 @@ function isUndefined(arg) {
|
|
|
18403
18690
|
}
|
|
18404
18691
|
|
|
18405
18692
|
},{}],42:[function(require,module,exports){
|
|
18693
|
+
'use strict';
|
|
18694
|
+
|
|
18406
18695
|
var hasOwn = Object.prototype.hasOwnProperty;
|
|
18407
18696
|
var toStr = Object.prototype.toString;
|
|
18408
18697
|
var defineProperty = Object.defineProperty;
|
|
@@ -18417,8 +18706,6 @@ var isArray = function isArray(arr) {
|
|
|
18417
18706
|
};
|
|
18418
18707
|
|
|
18419
18708
|
var isPlainObject = function isPlainObject(obj) {
|
|
18420
|
-
'use strict';
|
|
18421
|
-
|
|
18422
18709
|
if (!obj || toStr.call(obj) !== '[object Object]') {
|
|
18423
18710
|
return false;
|
|
18424
18711
|
}
|
|
@@ -18468,8 +18755,6 @@ var getProperty = function getProperty(obj, name) {
|
|
|
18468
18755
|
};
|
|
18469
18756
|
|
|
18470
18757
|
module.exports = function extend() {
|
|
18471
|
-
'use strict';
|
|
18472
|
-
|
|
18473
18758
|
var options, name, src, copy, copyIsArray, clone;
|
|
18474
18759
|
var target = arguments[0];
|
|
18475
18760
|
var i = 1;
|
|
@@ -20939,6 +21224,8 @@ function template(string) {
|
|
|
20939
21224
|
|
|
20940
21225
|
var Emitter = require('emitter');
|
|
20941
21226
|
var reduce = require('reduce');
|
|
21227
|
+
var requestBase = require('./request-base');
|
|
21228
|
+
var isObject = require('./is-object');
|
|
20942
21229
|
|
|
20943
21230
|
/**
|
|
20944
21231
|
* Root reference for iframes.
|
|
@@ -20960,28 +21247,10 @@ if (typeof window !== 'undefined') { // Browser window
|
|
|
20960
21247
|
function noop(){};
|
|
20961
21248
|
|
|
20962
21249
|
/**
|
|
20963
|
-
*
|
|
20964
|
-
* we don't want to serialize these :)
|
|
20965
|
-
*
|
|
20966
|
-
* TODO: future proof, move to compoent land
|
|
20967
|
-
*
|
|
20968
|
-
* @param {Object} obj
|
|
20969
|
-
* @return {Boolean}
|
|
20970
|
-
* @api private
|
|
21250
|
+
* Expose `request`.
|
|
20971
21251
|
*/
|
|
20972
21252
|
|
|
20973
|
-
|
|
20974
|
-
var str = {}.toString.call(obj);
|
|
20975
|
-
|
|
20976
|
-
switch (str) {
|
|
20977
|
-
case '[object File]':
|
|
20978
|
-
case '[object Blob]':
|
|
20979
|
-
case '[object FormData]':
|
|
20980
|
-
return true;
|
|
20981
|
-
default:
|
|
20982
|
-
return false;
|
|
20983
|
-
}
|
|
20984
|
-
}
|
|
21253
|
+
var request = module.exports = require('./request').bind(null, Request);
|
|
20985
21254
|
|
|
20986
21255
|
/**
|
|
20987
21256
|
* Determine XHR.
|
|
@@ -21013,18 +21282,6 @@ var trim = ''.trim
|
|
|
21013
21282
|
? function(s) { return s.trim(); }
|
|
21014
21283
|
: function(s) { return s.replace(/(^\s*|\s*$)/g, ''); };
|
|
21015
21284
|
|
|
21016
|
-
/**
|
|
21017
|
-
* Check if `obj` is an object.
|
|
21018
|
-
*
|
|
21019
|
-
* @param {Object} obj
|
|
21020
|
-
* @return {Boolean}
|
|
21021
|
-
* @api private
|
|
21022
|
-
*/
|
|
21023
|
-
|
|
21024
|
-
function isObject(obj) {
|
|
21025
|
-
return obj === Object(obj);
|
|
21026
|
-
}
|
|
21027
|
-
|
|
21028
21285
|
/**
|
|
21029
21286
|
* Serialize the given `obj`.
|
|
21030
21287
|
*
|
|
@@ -21039,8 +21296,8 @@ function serialize(obj) {
|
|
|
21039
21296
|
for (var key in obj) {
|
|
21040
21297
|
if (null != obj[key]) {
|
|
21041
21298
|
pushEncodedKeyValuePair(pairs, key, obj[key]);
|
|
21042
|
-
|
|
21043
|
-
|
|
21299
|
+
}
|
|
21300
|
+
}
|
|
21044
21301
|
return pairs.join('&');
|
|
21045
21302
|
}
|
|
21046
21303
|
|
|
@@ -21058,6 +21315,11 @@ function pushEncodedKeyValuePair(pairs, key, val) {
|
|
|
21058
21315
|
return val.forEach(function(v) {
|
|
21059
21316
|
pushEncodedKeyValuePair(pairs, key, v);
|
|
21060
21317
|
});
|
|
21318
|
+
} else if (isObject(val)) {
|
|
21319
|
+
for(var subkey in val) {
|
|
21320
|
+
pushEncodedKeyValuePair(pairs, key + '[' + subkey + ']', val[subkey]);
|
|
21321
|
+
}
|
|
21322
|
+
return;
|
|
21061
21323
|
}
|
|
21062
21324
|
pairs.push(encodeURIComponent(key)
|
|
21063
21325
|
+ '=' + encodeURIComponent(val));
|
|
@@ -21080,13 +21342,18 @@ function pushEncodedKeyValuePair(pairs, key, val) {
|
|
|
21080
21342
|
function parseString(str) {
|
|
21081
21343
|
var obj = {};
|
|
21082
21344
|
var pairs = str.split('&');
|
|
21083
|
-
var parts;
|
|
21084
21345
|
var pair;
|
|
21346
|
+
var pos;
|
|
21085
21347
|
|
|
21086
21348
|
for (var i = 0, len = pairs.length; i < len; ++i) {
|
|
21087
21349
|
pair = pairs[i];
|
|
21088
|
-
|
|
21089
|
-
|
|
21350
|
+
pos = pair.indexOf('=');
|
|
21351
|
+
if (pos == -1) {
|
|
21352
|
+
obj[decodeURIComponent(pair)] = '';
|
|
21353
|
+
} else {
|
|
21354
|
+
obj[decodeURIComponent(pair.slice(0, pos))] =
|
|
21355
|
+
decodeURIComponent(pair.slice(pos + 1));
|
|
21356
|
+
}
|
|
21090
21357
|
}
|
|
21091
21358
|
|
|
21092
21359
|
return obj;
|
|
@@ -21270,15 +21537,15 @@ function Response(req, options) {
|
|
|
21270
21537
|
? this.xhr.responseText
|
|
21271
21538
|
: null;
|
|
21272
21539
|
this.statusText = this.req.xhr.statusText;
|
|
21273
|
-
this.
|
|
21540
|
+
this._setStatusProperties(this.xhr.status);
|
|
21274
21541
|
this.header = this.headers = parseHeader(this.xhr.getAllResponseHeaders());
|
|
21275
21542
|
// getAllResponseHeaders sometimes falsely returns "" for CORS requests, but
|
|
21276
21543
|
// getResponseHeader still works. so we get content-type even if getting
|
|
21277
21544
|
// other headers fails.
|
|
21278
21545
|
this.header['content-type'] = this.xhr.getResponseHeader('content-type');
|
|
21279
|
-
this.
|
|
21546
|
+
this._setHeaderProperties(this.header);
|
|
21280
21547
|
this.body = this.req.method != 'HEAD'
|
|
21281
|
-
? this.
|
|
21548
|
+
? this._parseBody(this.text ? this.text : this.xhr.response)
|
|
21282
21549
|
: null;
|
|
21283
21550
|
}
|
|
21284
21551
|
|
|
@@ -21306,7 +21573,7 @@ Response.prototype.get = function(field){
|
|
|
21306
21573
|
* @api private
|
|
21307
21574
|
*/
|
|
21308
21575
|
|
|
21309
|
-
Response.prototype.
|
|
21576
|
+
Response.prototype._setHeaderProperties = function(header){
|
|
21310
21577
|
// content-type
|
|
21311
21578
|
var ct = this.header['content-type'] || '';
|
|
21312
21579
|
this.type = type(ct);
|
|
@@ -21327,8 +21594,11 @@ Response.prototype.setHeaderProperties = function(header){
|
|
|
21327
21594
|
* @api private
|
|
21328
21595
|
*/
|
|
21329
21596
|
|
|
21330
|
-
Response.prototype.
|
|
21597
|
+
Response.prototype._parseBody = function(str){
|
|
21331
21598
|
var parse = request.parse[this.type];
|
|
21599
|
+
if (!parse && isJSON(this.type)) {
|
|
21600
|
+
parse = request.parse['application/json'];
|
|
21601
|
+
}
|
|
21332
21602
|
return parse && str && (str.length || str instanceof Object)
|
|
21333
21603
|
? parse(str)
|
|
21334
21604
|
: null;
|
|
@@ -21355,7 +21625,7 @@ Response.prototype.parseBody = function(str){
|
|
|
21355
21625
|
* @api private
|
|
21356
21626
|
*/
|
|
21357
21627
|
|
|
21358
|
-
Response.prototype.
|
|
21628
|
+
Response.prototype._setStatusProperties = function(status){
|
|
21359
21629
|
// handle IE9 bug: http://stackoverflow.com/questions/10046972/msie-returns-status-code-of-1223-for-ajax-request
|
|
21360
21630
|
if (status === 1223) {
|
|
21361
21631
|
status = 204;
|
|
@@ -21423,12 +21693,11 @@ request.Response = Response;
|
|
|
21423
21693
|
|
|
21424
21694
|
function Request(method, url) {
|
|
21425
21695
|
var self = this;
|
|
21426
|
-
Emitter.call(this);
|
|
21427
21696
|
this._query = this._query || [];
|
|
21428
21697
|
this.method = method;
|
|
21429
21698
|
this.url = url;
|
|
21430
|
-
this.header = {};
|
|
21431
|
-
this._header = {};
|
|
21699
|
+
this.header = {}; // preserves header name case
|
|
21700
|
+
this._header = {}; // coerces header names to lowercase
|
|
21432
21701
|
this.on('end', function(){
|
|
21433
21702
|
var err = null;
|
|
21434
21703
|
var res = null;
|
|
@@ -21441,6 +21710,8 @@ function Request(method, url) {
|
|
|
21441
21710
|
err.original = e;
|
|
21442
21711
|
// issue #675: return the raw response if the response parsing fails
|
|
21443
21712
|
err.rawResponse = self.xhr && self.xhr.responseText ? self.xhr.responseText : null;
|
|
21713
|
+
// issue #876: return the http status code if the response parsing fails
|
|
21714
|
+
err.statusCode = self.xhr && self.xhr.status ? self.xhr.status : null;
|
|
21444
21715
|
return self.callback(err);
|
|
21445
21716
|
}
|
|
21446
21717
|
|
|
@@ -21450,218 +21721,132 @@ function Request(method, url) {
|
|
|
21450
21721
|
return self.callback(err, res);
|
|
21451
21722
|
}
|
|
21452
21723
|
|
|
21453
|
-
|
|
21454
|
-
|
|
21455
|
-
|
|
21724
|
+
try {
|
|
21725
|
+
if (res.status >= 200 && res.status < 300) {
|
|
21726
|
+
return self.callback(err, res);
|
|
21727
|
+
}
|
|
21456
21728
|
|
|
21457
|
-
|
|
21458
|
-
|
|
21459
|
-
|
|
21460
|
-
|
|
21729
|
+
var new_err = new Error(res.statusText || 'Unsuccessful HTTP response');
|
|
21730
|
+
new_err.original = err;
|
|
21731
|
+
new_err.response = res;
|
|
21732
|
+
new_err.status = res.status;
|
|
21461
21733
|
|
|
21462
|
-
|
|
21734
|
+
self.callback(new_err, res);
|
|
21735
|
+
} catch(e) {
|
|
21736
|
+
self.callback(e); // #985 touching res may cause INVALID_STATE_ERR on old Android
|
|
21737
|
+
}
|
|
21463
21738
|
});
|
|
21464
21739
|
}
|
|
21465
21740
|
|
|
21466
21741
|
/**
|
|
21467
|
-
* Mixin `Emitter`.
|
|
21742
|
+
* Mixin `Emitter` and `requestBase`.
|
|
21468
21743
|
*/
|
|
21469
21744
|
|
|
21470
21745
|
Emitter(Request.prototype);
|
|
21471
|
-
|
|
21472
|
-
|
|
21473
|
-
* Allow for extension
|
|
21474
|
-
*/
|
|
21475
|
-
|
|
21476
|
-
Request.prototype.use = function(fn) {
|
|
21477
|
-
fn(this);
|
|
21478
|
-
return this;
|
|
21746
|
+
for (var key in requestBase) {
|
|
21747
|
+
Request.prototype[key] = requestBase[key];
|
|
21479
21748
|
}
|
|
21480
21749
|
|
|
21481
21750
|
/**
|
|
21482
|
-
* Set
|
|
21751
|
+
* Set Content-Type to `type`, mapping values from `request.types`.
|
|
21483
21752
|
*
|
|
21484
|
-
*
|
|
21485
|
-
* @return {Request} for chaining
|
|
21486
|
-
* @api public
|
|
21487
|
-
*/
|
|
21488
|
-
|
|
21489
|
-
Request.prototype.timeout = function(ms){
|
|
21490
|
-
this._timeout = ms;
|
|
21491
|
-
return this;
|
|
21492
|
-
};
|
|
21493
|
-
|
|
21494
|
-
/**
|
|
21495
|
-
* Clear previous timeout.
|
|
21753
|
+
* Examples:
|
|
21496
21754
|
*
|
|
21755
|
+
* superagent.types.xml = 'application/xml';
|
|
21756
|
+
*
|
|
21757
|
+
* request.post('/')
|
|
21758
|
+
* .type('xml')
|
|
21759
|
+
* .send(xmlstring)
|
|
21760
|
+
* .end(callback);
|
|
21761
|
+
*
|
|
21762
|
+
* request.post('/')
|
|
21763
|
+
* .type('application/xml')
|
|
21764
|
+
* .send(xmlstring)
|
|
21765
|
+
* .end(callback);
|
|
21766
|
+
*
|
|
21767
|
+
* @param {String} type
|
|
21497
21768
|
* @return {Request} for chaining
|
|
21498
21769
|
* @api public
|
|
21499
21770
|
*/
|
|
21500
21771
|
|
|
21501
|
-
Request.prototype.
|
|
21502
|
-
this.
|
|
21503
|
-
clearTimeout(this._timer);
|
|
21772
|
+
Request.prototype.type = function(type){
|
|
21773
|
+
this.set('Content-Type', request.types[type] || type);
|
|
21504
21774
|
return this;
|
|
21505
21775
|
};
|
|
21506
21776
|
|
|
21507
21777
|
/**
|
|
21508
|
-
*
|
|
21778
|
+
* Set responseType to `val`. Presently valid responseTypes are 'blob' and
|
|
21779
|
+
* 'arraybuffer'.
|
|
21509
21780
|
*
|
|
21510
|
-
*
|
|
21781
|
+
* Examples:
|
|
21782
|
+
*
|
|
21783
|
+
* req.get('/')
|
|
21784
|
+
* .responseType('blob')
|
|
21785
|
+
* .end(callback);
|
|
21786
|
+
*
|
|
21787
|
+
* @param {String} val
|
|
21788
|
+
* @return {Request} for chaining
|
|
21511
21789
|
* @api public
|
|
21512
21790
|
*/
|
|
21513
21791
|
|
|
21514
|
-
Request.prototype.
|
|
21515
|
-
|
|
21516
|
-
this.aborted = true;
|
|
21517
|
-
this.xhr.abort();
|
|
21518
|
-
this.clearTimeout();
|
|
21519
|
-
this.emit('abort');
|
|
21792
|
+
Request.prototype.responseType = function(val){
|
|
21793
|
+
this._responseType = val;
|
|
21520
21794
|
return this;
|
|
21521
21795
|
};
|
|
21522
21796
|
|
|
21523
21797
|
/**
|
|
21524
|
-
* Set
|
|
21798
|
+
* Set Accept to `type`, mapping values from `request.types`.
|
|
21525
21799
|
*
|
|
21526
21800
|
* Examples:
|
|
21527
21801
|
*
|
|
21528
|
-
*
|
|
21529
|
-
*
|
|
21530
|
-
*
|
|
21802
|
+
* superagent.types.json = 'application/json';
|
|
21803
|
+
*
|
|
21804
|
+
* request.get('/agent')
|
|
21805
|
+
* .accept('json')
|
|
21531
21806
|
* .end(callback);
|
|
21532
21807
|
*
|
|
21533
|
-
*
|
|
21534
|
-
* .
|
|
21808
|
+
* request.get('/agent')
|
|
21809
|
+
* .accept('application/json')
|
|
21535
21810
|
* .end(callback);
|
|
21536
21811
|
*
|
|
21537
|
-
* @param {String
|
|
21538
|
-
* @param {String} val
|
|
21812
|
+
* @param {String} accept
|
|
21539
21813
|
* @return {Request} for chaining
|
|
21540
21814
|
* @api public
|
|
21541
21815
|
*/
|
|
21542
21816
|
|
|
21543
|
-
Request.prototype.
|
|
21544
|
-
|
|
21545
|
-
for (var key in field) {
|
|
21546
|
-
this.set(key, field[key]);
|
|
21547
|
-
}
|
|
21548
|
-
return this;
|
|
21549
|
-
}
|
|
21550
|
-
this._header[field.toLowerCase()] = val;
|
|
21551
|
-
this.header[field] = val;
|
|
21817
|
+
Request.prototype.accept = function(type){
|
|
21818
|
+
this.set('Accept', request.types[type] || type);
|
|
21552
21819
|
return this;
|
|
21553
21820
|
};
|
|
21554
21821
|
|
|
21555
21822
|
/**
|
|
21556
|
-
*
|
|
21557
|
-
*
|
|
21558
|
-
* Example:
|
|
21559
|
-
*
|
|
21560
|
-
* req.get('/')
|
|
21561
|
-
* .unset('User-Agent')
|
|
21562
|
-
* .end(callback);
|
|
21823
|
+
* Set Authorization field value with `user` and `pass`.
|
|
21563
21824
|
*
|
|
21564
|
-
* @param {String}
|
|
21825
|
+
* @param {String} user
|
|
21826
|
+
* @param {String} pass
|
|
21827
|
+
* @param {Object} options with 'type' property 'auto' or 'basic' (default 'basic')
|
|
21565
21828
|
* @return {Request} for chaining
|
|
21566
21829
|
* @api public
|
|
21567
21830
|
*/
|
|
21568
21831
|
|
|
21569
|
-
Request.prototype.
|
|
21570
|
-
|
|
21571
|
-
|
|
21572
|
-
|
|
21573
|
-
}
|
|
21574
|
-
|
|
21575
|
-
|
|
21576
|
-
|
|
21577
|
-
|
|
21578
|
-
|
|
21579
|
-
|
|
21580
|
-
|
|
21581
|
-
|
|
21582
|
-
|
|
21583
|
-
|
|
21584
|
-
|
|
21585
|
-
|
|
21586
|
-
|
|
21587
|
-
/**
|
|
21588
|
-
* Set Content-Type to `type`, mapping values from `request.types`.
|
|
21589
|
-
*
|
|
21590
|
-
* Examples:
|
|
21591
|
-
*
|
|
21592
|
-
* superagent.types.xml = 'application/xml';
|
|
21593
|
-
*
|
|
21594
|
-
* request.post('/')
|
|
21595
|
-
* .type('xml')
|
|
21596
|
-
* .send(xmlstring)
|
|
21597
|
-
* .end(callback);
|
|
21598
|
-
*
|
|
21599
|
-
* request.post('/')
|
|
21600
|
-
* .type('application/xml')
|
|
21601
|
-
* .send(xmlstring)
|
|
21602
|
-
* .end(callback);
|
|
21603
|
-
*
|
|
21604
|
-
* @param {String} type
|
|
21605
|
-
* @return {Request} for chaining
|
|
21606
|
-
* @api public
|
|
21607
|
-
*/
|
|
21608
|
-
|
|
21609
|
-
Request.prototype.type = function(type){
|
|
21610
|
-
this.set('Content-Type', request.types[type] || type);
|
|
21611
|
-
return this;
|
|
21612
|
-
};
|
|
21613
|
-
|
|
21614
|
-
/**
|
|
21615
|
-
* Force given parser
|
|
21616
|
-
*
|
|
21617
|
-
* Sets the body parser no matter type.
|
|
21618
|
-
*
|
|
21619
|
-
* @param {Function}
|
|
21620
|
-
* @api public
|
|
21621
|
-
*/
|
|
21622
|
-
|
|
21623
|
-
Request.prototype.parse = function(fn){
|
|
21624
|
-
this._parser = fn;
|
|
21625
|
-
return this;
|
|
21626
|
-
};
|
|
21627
|
-
|
|
21628
|
-
/**
|
|
21629
|
-
* Set Accept to `type`, mapping values from `request.types`.
|
|
21630
|
-
*
|
|
21631
|
-
* Examples:
|
|
21632
|
-
*
|
|
21633
|
-
* superagent.types.json = 'application/json';
|
|
21634
|
-
*
|
|
21635
|
-
* request.get('/agent')
|
|
21636
|
-
* .accept('json')
|
|
21637
|
-
* .end(callback);
|
|
21638
|
-
*
|
|
21639
|
-
* request.get('/agent')
|
|
21640
|
-
* .accept('application/json')
|
|
21641
|
-
* .end(callback);
|
|
21642
|
-
*
|
|
21643
|
-
* @param {String} accept
|
|
21644
|
-
* @return {Request} for chaining
|
|
21645
|
-
* @api public
|
|
21646
|
-
*/
|
|
21647
|
-
|
|
21648
|
-
Request.prototype.accept = function(type){
|
|
21649
|
-
this.set('Accept', request.types[type] || type);
|
|
21650
|
-
return this;
|
|
21651
|
-
};
|
|
21652
|
-
|
|
21653
|
-
/**
|
|
21654
|
-
* Set Authorization field value with `user` and `pass`.
|
|
21655
|
-
*
|
|
21656
|
-
* @param {String} user
|
|
21657
|
-
* @param {String} pass
|
|
21658
|
-
* @return {Request} for chaining
|
|
21659
|
-
* @api public
|
|
21660
|
-
*/
|
|
21661
|
-
|
|
21662
|
-
Request.prototype.auth = function(user, pass){
|
|
21663
|
-
var str = btoa(user + ':' + pass);
|
|
21664
|
-
this.set('Authorization', 'Basic ' + str);
|
|
21832
|
+
Request.prototype.auth = function(user, pass, options){
|
|
21833
|
+
if (!options) {
|
|
21834
|
+
options = {
|
|
21835
|
+
type: 'basic'
|
|
21836
|
+
}
|
|
21837
|
+
}
|
|
21838
|
+
|
|
21839
|
+
switch (options.type) {
|
|
21840
|
+
case 'basic':
|
|
21841
|
+
var str = btoa(user + ':' + pass);
|
|
21842
|
+
this.set('Authorization', 'Basic ' + str);
|
|
21843
|
+
break;
|
|
21844
|
+
|
|
21845
|
+
case 'auto':
|
|
21846
|
+
this.username = user;
|
|
21847
|
+
this.password = pass;
|
|
21848
|
+
break;
|
|
21849
|
+
}
|
|
21665
21850
|
return this;
|
|
21666
21851
|
};
|
|
21667
21852
|
|
|
@@ -21685,35 +21870,13 @@ Request.prototype.query = function(val){
|
|
|
21685
21870
|
return this;
|
|
21686
21871
|
};
|
|
21687
21872
|
|
|
21688
|
-
/**
|
|
21689
|
-
* Write the field `name` and `val` for "multipart/form-data"
|
|
21690
|
-
* request bodies.
|
|
21691
|
-
*
|
|
21692
|
-
* ``` js
|
|
21693
|
-
* request.post('/upload')
|
|
21694
|
-
* .field('foo', 'bar')
|
|
21695
|
-
* .end(callback);
|
|
21696
|
-
* ```
|
|
21697
|
-
*
|
|
21698
|
-
* @param {String} name
|
|
21699
|
-
* @param {String|Blob|File} val
|
|
21700
|
-
* @return {Request} for chaining
|
|
21701
|
-
* @api public
|
|
21702
|
-
*/
|
|
21703
|
-
|
|
21704
|
-
Request.prototype.field = function(name, val){
|
|
21705
|
-
if (!this._formData) this._formData = new root.FormData();
|
|
21706
|
-
this._formData.append(name, val);
|
|
21707
|
-
return this;
|
|
21708
|
-
};
|
|
21709
|
-
|
|
21710
21873
|
/**
|
|
21711
21874
|
* Queue the given `file` as an attachment to the specified `field`,
|
|
21712
21875
|
* with optional `filename`.
|
|
21713
21876
|
*
|
|
21714
21877
|
* ``` js
|
|
21715
21878
|
* request.post('/upload')
|
|
21716
|
-
* .attach(new Blob(['<a id="a"><b id="b">hey!</b></a>'], { type: "text/html"}))
|
|
21879
|
+
* .attach('content', new Blob(['<a id="a"><b id="b">hey!</b></a>'], { type: "text/html"}))
|
|
21717
21880
|
* .end(callback);
|
|
21718
21881
|
* ```
|
|
21719
21882
|
*
|
|
@@ -21725,77 +21888,15 @@ Request.prototype.field = function(name, val){
|
|
|
21725
21888
|
*/
|
|
21726
21889
|
|
|
21727
21890
|
Request.prototype.attach = function(field, file, filename){
|
|
21728
|
-
|
|
21729
|
-
this._formData.append(field, file, filename || file.name);
|
|
21891
|
+
this._getFormData().append(field, file, filename || file.name);
|
|
21730
21892
|
return this;
|
|
21731
21893
|
};
|
|
21732
21894
|
|
|
21733
|
-
|
|
21734
|
-
|
|
21735
|
-
|
|
21736
|
-
*
|
|
21737
|
-
* Examples:
|
|
21738
|
-
*
|
|
21739
|
-
* // manual json
|
|
21740
|
-
* request.post('/user')
|
|
21741
|
-
* .type('json')
|
|
21742
|
-
* .send('{"name":"tj"}')
|
|
21743
|
-
* .end(callback)
|
|
21744
|
-
*
|
|
21745
|
-
* // auto json
|
|
21746
|
-
* request.post('/user')
|
|
21747
|
-
* .send({ name: 'tj' })
|
|
21748
|
-
* .end(callback)
|
|
21749
|
-
*
|
|
21750
|
-
* // manual x-www-form-urlencoded
|
|
21751
|
-
* request.post('/user')
|
|
21752
|
-
* .type('form')
|
|
21753
|
-
* .send('name=tj')
|
|
21754
|
-
* .end(callback)
|
|
21755
|
-
*
|
|
21756
|
-
* // auto x-www-form-urlencoded
|
|
21757
|
-
* request.post('/user')
|
|
21758
|
-
* .type('form')
|
|
21759
|
-
* .send({ name: 'tj' })
|
|
21760
|
-
* .end(callback)
|
|
21761
|
-
*
|
|
21762
|
-
* // defaults to x-www-form-urlencoded
|
|
21763
|
-
* request.post('/user')
|
|
21764
|
-
* .send('name=tobi')
|
|
21765
|
-
* .send('species=ferret')
|
|
21766
|
-
* .end(callback)
|
|
21767
|
-
*
|
|
21768
|
-
* @param {String|Object} data
|
|
21769
|
-
* @return {Request} for chaining
|
|
21770
|
-
* @api public
|
|
21771
|
-
*/
|
|
21772
|
-
|
|
21773
|
-
Request.prototype.send = function(data){
|
|
21774
|
-
var obj = isObject(data);
|
|
21775
|
-
var type = this.getHeader('Content-Type');
|
|
21776
|
-
|
|
21777
|
-
// merge
|
|
21778
|
-
if (obj && isObject(this._data)) {
|
|
21779
|
-
for (var key in data) {
|
|
21780
|
-
this._data[key] = data[key];
|
|
21781
|
-
}
|
|
21782
|
-
} else if ('string' == typeof data) {
|
|
21783
|
-
if (!type) this.type('form');
|
|
21784
|
-
type = this.getHeader('Content-Type');
|
|
21785
|
-
if ('application/x-www-form-urlencoded' == type) {
|
|
21786
|
-
this._data = this._data
|
|
21787
|
-
? this._data + '&' + data
|
|
21788
|
-
: data;
|
|
21789
|
-
} else {
|
|
21790
|
-
this._data = (this._data || '') + data;
|
|
21791
|
-
}
|
|
21792
|
-
} else {
|
|
21793
|
-
this._data = data;
|
|
21895
|
+
Request.prototype._getFormData = function(){
|
|
21896
|
+
if (!this._formData) {
|
|
21897
|
+
this._formData = new root.FormData();
|
|
21794
21898
|
}
|
|
21795
|
-
|
|
21796
|
-
if (!obj || isHost(data)) return this;
|
|
21797
|
-
if (!type) this.type('json');
|
|
21798
|
-
return this;
|
|
21899
|
+
return this._formData;
|
|
21799
21900
|
};
|
|
21800
21901
|
|
|
21801
21902
|
/**
|
|
@@ -21836,7 +21937,7 @@ Request.prototype.crossDomainError = function(){
|
|
|
21836
21937
|
* @api private
|
|
21837
21938
|
*/
|
|
21838
21939
|
|
|
21839
|
-
Request.prototype.
|
|
21940
|
+
Request.prototype._timeoutError = function(){
|
|
21840
21941
|
var timeout = this._timeout;
|
|
21841
21942
|
var err = new Error('timeout of ' + timeout + 'ms exceeded');
|
|
21842
21943
|
err.timeout = timeout;
|
|
@@ -21844,19 +21945,18 @@ Request.prototype.timeoutError = function(){
|
|
|
21844
21945
|
};
|
|
21845
21946
|
|
|
21846
21947
|
/**
|
|
21847
|
-
*
|
|
21848
|
-
*
|
|
21849
|
-
* Note that for this to work the origin must not be
|
|
21850
|
-
* using "Access-Control-Allow-Origin" with a wildcard,
|
|
21851
|
-
* and also must set "Access-Control-Allow-Credentials"
|
|
21852
|
-
* to "true".
|
|
21948
|
+
* Compose querystring to append to req.url
|
|
21853
21949
|
*
|
|
21854
|
-
* @api
|
|
21950
|
+
* @api private
|
|
21855
21951
|
*/
|
|
21856
21952
|
|
|
21857
|
-
Request.prototype.
|
|
21858
|
-
|
|
21859
|
-
|
|
21953
|
+
Request.prototype._appendQueryString = function(){
|
|
21954
|
+
var query = this._query.join('&');
|
|
21955
|
+
if (query) {
|
|
21956
|
+
this.url += ~this.url.indexOf('?')
|
|
21957
|
+
? '&' + query
|
|
21958
|
+
: '?' + query;
|
|
21959
|
+
}
|
|
21860
21960
|
};
|
|
21861
21961
|
|
|
21862
21962
|
/**
|
|
@@ -21871,7 +21971,6 @@ Request.prototype.withCredentials = function(){
|
|
|
21871
21971
|
Request.prototype.end = function(fn){
|
|
21872
21972
|
var self = this;
|
|
21873
21973
|
var xhr = this.xhr = request.getXHR();
|
|
21874
|
-
var query = this._query.join('&');
|
|
21875
21974
|
var timeout = this._timeout;
|
|
21876
21975
|
var data = this._formData || this._data;
|
|
21877
21976
|
|
|
@@ -21888,8 +21987,8 @@ Request.prototype.end = function(fn){
|
|
|
21888
21987
|
try { status = xhr.status } catch(e) { status = 0; }
|
|
21889
21988
|
|
|
21890
21989
|
if (0 == status) {
|
|
21891
|
-
if (self.timedout) return self.
|
|
21892
|
-
if (self.
|
|
21990
|
+
if (self.timedout) return self._timeoutError();
|
|
21991
|
+
if (self._aborted) return;
|
|
21893
21992
|
return self.crossDomainError();
|
|
21894
21993
|
}
|
|
21895
21994
|
self.emit('end');
|
|
@@ -21925,24 +22024,23 @@ Request.prototype.end = function(fn){
|
|
|
21925
22024
|
}
|
|
21926
22025
|
|
|
21927
22026
|
// querystring
|
|
21928
|
-
|
|
21929
|
-
query = request.serializeObject(query);
|
|
21930
|
-
this.url += ~this.url.indexOf('?')
|
|
21931
|
-
? '&' + query
|
|
21932
|
-
: '?' + query;
|
|
21933
|
-
}
|
|
22027
|
+
this._appendQueryString();
|
|
21934
22028
|
|
|
21935
22029
|
// initiate request
|
|
21936
|
-
|
|
22030
|
+
if (this.username && this.password) {
|
|
22031
|
+
xhr.open(this.method, this.url, true, this.username, this.password);
|
|
22032
|
+
} else {
|
|
22033
|
+
xhr.open(this.method, this.url, true);
|
|
22034
|
+
}
|
|
21937
22035
|
|
|
21938
22036
|
// CORS
|
|
21939
22037
|
if (this._withCredentials) xhr.withCredentials = true;
|
|
21940
22038
|
|
|
21941
22039
|
// body
|
|
21942
|
-
if ('GET' != this.method && 'HEAD' != this.method && 'string' != typeof data && !
|
|
22040
|
+
if ('GET' != this.method && 'HEAD' != this.method && 'string' != typeof data && !this._isHost(data)) {
|
|
21943
22041
|
// serialize stuff
|
|
21944
|
-
var contentType = this.
|
|
21945
|
-
var serialize = this.
|
|
22042
|
+
var contentType = this._header['content-type'];
|
|
22043
|
+
var serialize = this._serializer || request.serialize[contentType ? contentType.split(';')[0] : ''];
|
|
21946
22044
|
if (!serialize && isJSON(contentType)) serialize = request.serialize['application/json'];
|
|
21947
22045
|
if (serialize) data = serialize(data);
|
|
21948
22046
|
}
|
|
@@ -21953,6 +22051,10 @@ Request.prototype.end = function(fn){
|
|
|
21953
22051
|
xhr.setRequestHeader(field, this.header[field]);
|
|
21954
22052
|
}
|
|
21955
22053
|
|
|
22054
|
+
if (this._responseType) {
|
|
22055
|
+
xhr.responseType = this._responseType;
|
|
22056
|
+
}
|
|
22057
|
+
|
|
21956
22058
|
// send stuff
|
|
21957
22059
|
this.emit('request', this);
|
|
21958
22060
|
|
|
@@ -21962,19 +22064,6 @@ Request.prototype.end = function(fn){
|
|
|
21962
22064
|
return this;
|
|
21963
22065
|
};
|
|
21964
22066
|
|
|
21965
|
-
/**
|
|
21966
|
-
* Faux promise support
|
|
21967
|
-
*
|
|
21968
|
-
* @param {Function} fulfill
|
|
21969
|
-
* @param {Function} reject
|
|
21970
|
-
* @return {Request}
|
|
21971
|
-
*/
|
|
21972
|
-
|
|
21973
|
-
Request.prototype.then = function (fulfill, reject) {
|
|
21974
|
-
return this.end(function(err, res) {
|
|
21975
|
-
err ? reject(err) : fulfill(res);
|
|
21976
|
-
});
|
|
21977
|
-
}
|
|
21978
22067
|
|
|
21979
22068
|
/**
|
|
21980
22069
|
* Expose `Request`.
|
|
@@ -21982,35 +22071,6 @@ Request.prototype.then = function (fulfill, reject) {
|
|
|
21982
22071
|
|
|
21983
22072
|
request.Request = Request;
|
|
21984
22073
|
|
|
21985
|
-
/**
|
|
21986
|
-
* Issue a request:
|
|
21987
|
-
*
|
|
21988
|
-
* Examples:
|
|
21989
|
-
*
|
|
21990
|
-
* request('GET', '/users').end(callback)
|
|
21991
|
-
* request('/users').end(callback)
|
|
21992
|
-
* request('/users', callback)
|
|
21993
|
-
*
|
|
21994
|
-
* @param {String} method
|
|
21995
|
-
* @param {String|Function} url or callback
|
|
21996
|
-
* @return {Request}
|
|
21997
|
-
* @api public
|
|
21998
|
-
*/
|
|
21999
|
-
|
|
22000
|
-
function request(method, url) {
|
|
22001
|
-
// callback
|
|
22002
|
-
if ('function' == typeof url) {
|
|
22003
|
-
return new Request('GET', method).end(url);
|
|
22004
|
-
}
|
|
22005
|
-
|
|
22006
|
-
// url first
|
|
22007
|
-
if (1 == arguments.length) {
|
|
22008
|
-
return new Request('GET', method);
|
|
22009
|
-
}
|
|
22010
|
-
|
|
22011
|
-
return new Request(method, url);
|
|
22012
|
-
}
|
|
22013
|
-
|
|
22014
22074
|
/**
|
|
22015
22075
|
* GET `url` with optional callback `fn(res)`.
|
|
22016
22076
|
*
|
|
@@ -22047,6 +22107,24 @@ request.head = function(url, data, fn){
|
|
|
22047
22107
|
return req;
|
|
22048
22108
|
};
|
|
22049
22109
|
|
|
22110
|
+
/**
|
|
22111
|
+
* OPTIONS query to `url` with optional callback `fn(res)`.
|
|
22112
|
+
*
|
|
22113
|
+
* @param {String} url
|
|
22114
|
+
* @param {Mixed|Function} data or fn
|
|
22115
|
+
* @param {Function} fn
|
|
22116
|
+
* @return {Request}
|
|
22117
|
+
* @api public
|
|
22118
|
+
*/
|
|
22119
|
+
|
|
22120
|
+
request.options = function(url, data, fn){
|
|
22121
|
+
var req = request('OPTIONS', url);
|
|
22122
|
+
if ('function' == typeof data) fn = data, data = null;
|
|
22123
|
+
if (data) req.send(data);
|
|
22124
|
+
if (fn) req.end(fn);
|
|
22125
|
+
return req;
|
|
22126
|
+
};
|
|
22127
|
+
|
|
22050
22128
|
/**
|
|
22051
22129
|
* DELETE `url` with optional callback `fn(res)`.
|
|
22052
22130
|
*
|
|
@@ -22119,13 +22197,404 @@ request.put = function(url, data, fn){
|
|
|
22119
22197
|
return req;
|
|
22120
22198
|
};
|
|
22121
22199
|
|
|
22200
|
+
},{"./is-object":50,"./request":52,"./request-base":51,"emitter":40,"reduce":47}],50:[function(require,module,exports){
|
|
22122
22201
|
/**
|
|
22123
|
-
*
|
|
22202
|
+
* Check if `obj` is an object.
|
|
22203
|
+
*
|
|
22204
|
+
* @param {Object} obj
|
|
22205
|
+
* @return {Boolean}
|
|
22206
|
+
* @api private
|
|
22207
|
+
*/
|
|
22208
|
+
|
|
22209
|
+
function isObject(obj) {
|
|
22210
|
+
return null !== obj && 'object' === typeof obj;
|
|
22211
|
+
}
|
|
22212
|
+
|
|
22213
|
+
module.exports = isObject;
|
|
22214
|
+
|
|
22215
|
+
},{}],51:[function(require,module,exports){
|
|
22216
|
+
/**
|
|
22217
|
+
* Module of mixed-in functions shared between node and client code
|
|
22218
|
+
*/
|
|
22219
|
+
var isObject = require('./is-object');
|
|
22220
|
+
|
|
22221
|
+
/**
|
|
22222
|
+
* Clear previous timeout.
|
|
22223
|
+
*
|
|
22224
|
+
* @return {Request} for chaining
|
|
22225
|
+
* @api public
|
|
22124
22226
|
*/
|
|
22125
22227
|
|
|
22228
|
+
exports.clearTimeout = function _clearTimeout(){
|
|
22229
|
+
this._timeout = 0;
|
|
22230
|
+
clearTimeout(this._timer);
|
|
22231
|
+
return this;
|
|
22232
|
+
};
|
|
22233
|
+
|
|
22234
|
+
/**
|
|
22235
|
+
* Override default response body parser
|
|
22236
|
+
*
|
|
22237
|
+
* This function will be called to convert incoming data into request.body
|
|
22238
|
+
*
|
|
22239
|
+
* @param {Function}
|
|
22240
|
+
* @api public
|
|
22241
|
+
*/
|
|
22242
|
+
|
|
22243
|
+
exports.parse = function parse(fn){
|
|
22244
|
+
this._parser = fn;
|
|
22245
|
+
return this;
|
|
22246
|
+
};
|
|
22247
|
+
|
|
22248
|
+
/**
|
|
22249
|
+
* Override default request body serializer
|
|
22250
|
+
*
|
|
22251
|
+
* This function will be called to convert data set via .send or .attach into payload to send
|
|
22252
|
+
*
|
|
22253
|
+
* @param {Function}
|
|
22254
|
+
* @api public
|
|
22255
|
+
*/
|
|
22256
|
+
|
|
22257
|
+
exports.serialize = function serialize(fn){
|
|
22258
|
+
this._serializer = fn;
|
|
22259
|
+
return this;
|
|
22260
|
+
};
|
|
22261
|
+
|
|
22262
|
+
/**
|
|
22263
|
+
* Set timeout to `ms`.
|
|
22264
|
+
*
|
|
22265
|
+
* @param {Number} ms
|
|
22266
|
+
* @return {Request} for chaining
|
|
22267
|
+
* @api public
|
|
22268
|
+
*/
|
|
22269
|
+
|
|
22270
|
+
exports.timeout = function timeout(ms){
|
|
22271
|
+
this._timeout = ms;
|
|
22272
|
+
return this;
|
|
22273
|
+
};
|
|
22274
|
+
|
|
22275
|
+
/**
|
|
22276
|
+
* Promise support
|
|
22277
|
+
*
|
|
22278
|
+
* @param {Function} resolve
|
|
22279
|
+
* @param {Function} reject
|
|
22280
|
+
* @return {Request}
|
|
22281
|
+
*/
|
|
22282
|
+
|
|
22283
|
+
exports.then = function then(resolve, reject) {
|
|
22284
|
+
if (!this._fullfilledPromise) {
|
|
22285
|
+
var self = this;
|
|
22286
|
+
this._fullfilledPromise = new Promise(function(innerResolve, innerReject){
|
|
22287
|
+
self.end(function(err, res){
|
|
22288
|
+
if (err) innerReject(err); else innerResolve(res);
|
|
22289
|
+
});
|
|
22290
|
+
});
|
|
22291
|
+
}
|
|
22292
|
+
return this._fullfilledPromise.then(resolve, reject);
|
|
22293
|
+
}
|
|
22294
|
+
|
|
22295
|
+
/**
|
|
22296
|
+
* Allow for extension
|
|
22297
|
+
*/
|
|
22298
|
+
|
|
22299
|
+
exports.use = function use(fn) {
|
|
22300
|
+
fn(this);
|
|
22301
|
+
return this;
|
|
22302
|
+
}
|
|
22303
|
+
|
|
22304
|
+
|
|
22305
|
+
/**
|
|
22306
|
+
* Get request header `field`.
|
|
22307
|
+
* Case-insensitive.
|
|
22308
|
+
*
|
|
22309
|
+
* @param {String} field
|
|
22310
|
+
* @return {String}
|
|
22311
|
+
* @api public
|
|
22312
|
+
*/
|
|
22313
|
+
|
|
22314
|
+
exports.get = function(field){
|
|
22315
|
+
return this._header[field.toLowerCase()];
|
|
22316
|
+
};
|
|
22317
|
+
|
|
22318
|
+
/**
|
|
22319
|
+
* Get case-insensitive header `field` value.
|
|
22320
|
+
* This is a deprecated internal API. Use `.get(field)` instead.
|
|
22321
|
+
*
|
|
22322
|
+
* (getHeader is no longer used internally by the superagent code base)
|
|
22323
|
+
*
|
|
22324
|
+
* @param {String} field
|
|
22325
|
+
* @return {String}
|
|
22326
|
+
* @api private
|
|
22327
|
+
* @deprecated
|
|
22328
|
+
*/
|
|
22329
|
+
|
|
22330
|
+
exports.getHeader = exports.get;
|
|
22331
|
+
|
|
22332
|
+
/**
|
|
22333
|
+
* Set header `field` to `val`, or multiple fields with one object.
|
|
22334
|
+
* Case-insensitive.
|
|
22335
|
+
*
|
|
22336
|
+
* Examples:
|
|
22337
|
+
*
|
|
22338
|
+
* req.get('/')
|
|
22339
|
+
* .set('Accept', 'application/json')
|
|
22340
|
+
* .set('X-API-Key', 'foobar')
|
|
22341
|
+
* .end(callback);
|
|
22342
|
+
*
|
|
22343
|
+
* req.get('/')
|
|
22344
|
+
* .set({ Accept: 'application/json', 'X-API-Key': 'foobar' })
|
|
22345
|
+
* .end(callback);
|
|
22346
|
+
*
|
|
22347
|
+
* @param {String|Object} field
|
|
22348
|
+
* @param {String} val
|
|
22349
|
+
* @return {Request} for chaining
|
|
22350
|
+
* @api public
|
|
22351
|
+
*/
|
|
22352
|
+
|
|
22353
|
+
exports.set = function(field, val){
|
|
22354
|
+
if (isObject(field)) {
|
|
22355
|
+
for (var key in field) {
|
|
22356
|
+
this.set(key, field[key]);
|
|
22357
|
+
}
|
|
22358
|
+
return this;
|
|
22359
|
+
}
|
|
22360
|
+
this._header[field.toLowerCase()] = val;
|
|
22361
|
+
this.header[field] = val;
|
|
22362
|
+
return this;
|
|
22363
|
+
};
|
|
22364
|
+
|
|
22365
|
+
/**
|
|
22366
|
+
* Remove header `field`.
|
|
22367
|
+
* Case-insensitive.
|
|
22368
|
+
*
|
|
22369
|
+
* Example:
|
|
22370
|
+
*
|
|
22371
|
+
* req.get('/')
|
|
22372
|
+
* .unset('User-Agent')
|
|
22373
|
+
* .end(callback);
|
|
22374
|
+
*
|
|
22375
|
+
* @param {String} field
|
|
22376
|
+
*/
|
|
22377
|
+
exports.unset = function(field){
|
|
22378
|
+
delete this._header[field.toLowerCase()];
|
|
22379
|
+
delete this.header[field];
|
|
22380
|
+
return this;
|
|
22381
|
+
};
|
|
22382
|
+
|
|
22383
|
+
/**
|
|
22384
|
+
* Write the field `name` and `val` for "multipart/form-data"
|
|
22385
|
+
* request bodies.
|
|
22386
|
+
*
|
|
22387
|
+
* ``` js
|
|
22388
|
+
* request.post('/upload')
|
|
22389
|
+
* .field('foo', 'bar')
|
|
22390
|
+
* .end(callback);
|
|
22391
|
+
* ```
|
|
22392
|
+
*
|
|
22393
|
+
* @param {String} name
|
|
22394
|
+
* @param {String|Blob|File|Buffer|fs.ReadStream} val
|
|
22395
|
+
* @return {Request} for chaining
|
|
22396
|
+
* @api public
|
|
22397
|
+
*/
|
|
22398
|
+
exports.field = function(name, val) {
|
|
22399
|
+
this._getFormData().append(name, val);
|
|
22400
|
+
return this;
|
|
22401
|
+
};
|
|
22402
|
+
|
|
22403
|
+
/**
|
|
22404
|
+
* Abort the request, and clear potential timeout.
|
|
22405
|
+
*
|
|
22406
|
+
* @return {Request}
|
|
22407
|
+
* @api public
|
|
22408
|
+
*/
|
|
22409
|
+
exports.abort = function(){
|
|
22410
|
+
if (this._aborted) {
|
|
22411
|
+
return this;
|
|
22412
|
+
}
|
|
22413
|
+
this._aborted = true;
|
|
22414
|
+
this.xhr && this.xhr.abort(); // browser
|
|
22415
|
+
this.req && this.req.abort(); // node
|
|
22416
|
+
this.clearTimeout();
|
|
22417
|
+
this.emit('abort');
|
|
22418
|
+
return this;
|
|
22419
|
+
};
|
|
22420
|
+
|
|
22421
|
+
/**
|
|
22422
|
+
* Enable transmission of cookies with x-domain requests.
|
|
22423
|
+
*
|
|
22424
|
+
* Note that for this to work the origin must not be
|
|
22425
|
+
* using "Access-Control-Allow-Origin" with a wildcard,
|
|
22426
|
+
* and also must set "Access-Control-Allow-Credentials"
|
|
22427
|
+
* to "true".
|
|
22428
|
+
*
|
|
22429
|
+
* @api public
|
|
22430
|
+
*/
|
|
22431
|
+
|
|
22432
|
+
exports.withCredentials = function(){
|
|
22433
|
+
// This is browser-only functionality. Node side is no-op.
|
|
22434
|
+
this._withCredentials = true;
|
|
22435
|
+
return this;
|
|
22436
|
+
};
|
|
22437
|
+
|
|
22438
|
+
/**
|
|
22439
|
+
* Set the max redirects to `n`. Does noting in browser XHR implementation.
|
|
22440
|
+
*
|
|
22441
|
+
* @param {Number} n
|
|
22442
|
+
* @return {Request} for chaining
|
|
22443
|
+
* @api public
|
|
22444
|
+
*/
|
|
22445
|
+
|
|
22446
|
+
exports.redirects = function(n){
|
|
22447
|
+
this._maxRedirects = n;
|
|
22448
|
+
return this;
|
|
22449
|
+
};
|
|
22450
|
+
|
|
22451
|
+
/**
|
|
22452
|
+
* Convert to a plain javascript object (not JSON string) of scalar properties.
|
|
22453
|
+
* Note as this method is designed to return a useful non-this value,
|
|
22454
|
+
* it cannot be chained.
|
|
22455
|
+
*
|
|
22456
|
+
* @return {Object} describing method, url, and data of this request
|
|
22457
|
+
* @api public
|
|
22458
|
+
*/
|
|
22459
|
+
|
|
22460
|
+
exports.toJSON = function(){
|
|
22461
|
+
return {
|
|
22462
|
+
method: this.method,
|
|
22463
|
+
url: this.url,
|
|
22464
|
+
data: this._data
|
|
22465
|
+
};
|
|
22466
|
+
};
|
|
22467
|
+
|
|
22468
|
+
/**
|
|
22469
|
+
* Check if `obj` is a host object,
|
|
22470
|
+
* we don't want to serialize these :)
|
|
22471
|
+
*
|
|
22472
|
+
* TODO: future proof, move to compoent land
|
|
22473
|
+
*
|
|
22474
|
+
* @param {Object} obj
|
|
22475
|
+
* @return {Boolean}
|
|
22476
|
+
* @api private
|
|
22477
|
+
*/
|
|
22478
|
+
|
|
22479
|
+
exports._isHost = function _isHost(obj) {
|
|
22480
|
+
var str = {}.toString.call(obj);
|
|
22481
|
+
|
|
22482
|
+
switch (str) {
|
|
22483
|
+
case '[object File]':
|
|
22484
|
+
case '[object Blob]':
|
|
22485
|
+
case '[object FormData]':
|
|
22486
|
+
return true;
|
|
22487
|
+
default:
|
|
22488
|
+
return false;
|
|
22489
|
+
}
|
|
22490
|
+
}
|
|
22491
|
+
|
|
22492
|
+
/**
|
|
22493
|
+
* Send `data` as the request body, defaulting the `.type()` to "json" when
|
|
22494
|
+
* an object is given.
|
|
22495
|
+
*
|
|
22496
|
+
* Examples:
|
|
22497
|
+
*
|
|
22498
|
+
* // manual json
|
|
22499
|
+
* request.post('/user')
|
|
22500
|
+
* .type('json')
|
|
22501
|
+
* .send('{"name":"tj"}')
|
|
22502
|
+
* .end(callback)
|
|
22503
|
+
*
|
|
22504
|
+
* // auto json
|
|
22505
|
+
* request.post('/user')
|
|
22506
|
+
* .send({ name: 'tj' })
|
|
22507
|
+
* .end(callback)
|
|
22508
|
+
*
|
|
22509
|
+
* // manual x-www-form-urlencoded
|
|
22510
|
+
* request.post('/user')
|
|
22511
|
+
* .type('form')
|
|
22512
|
+
* .send('name=tj')
|
|
22513
|
+
* .end(callback)
|
|
22514
|
+
*
|
|
22515
|
+
* // auto x-www-form-urlencoded
|
|
22516
|
+
* request.post('/user')
|
|
22517
|
+
* .type('form')
|
|
22518
|
+
* .send({ name: 'tj' })
|
|
22519
|
+
* .end(callback)
|
|
22520
|
+
*
|
|
22521
|
+
* // defaults to x-www-form-urlencoded
|
|
22522
|
+
* request.post('/user')
|
|
22523
|
+
* .send('name=tobi')
|
|
22524
|
+
* .send('species=ferret')
|
|
22525
|
+
* .end(callback)
|
|
22526
|
+
*
|
|
22527
|
+
* @param {String|Object} data
|
|
22528
|
+
* @return {Request} for chaining
|
|
22529
|
+
* @api public
|
|
22530
|
+
*/
|
|
22531
|
+
|
|
22532
|
+
exports.send = function(data){
|
|
22533
|
+
var obj = isObject(data);
|
|
22534
|
+
var type = this._header['content-type'];
|
|
22535
|
+
|
|
22536
|
+
// merge
|
|
22537
|
+
if (obj && isObject(this._data)) {
|
|
22538
|
+
for (var key in data) {
|
|
22539
|
+
this._data[key] = data[key];
|
|
22540
|
+
}
|
|
22541
|
+
} else if ('string' == typeof data) {
|
|
22542
|
+
// default to x-www-form-urlencoded
|
|
22543
|
+
if (!type) this.type('form');
|
|
22544
|
+
type = this._header['content-type'];
|
|
22545
|
+
if ('application/x-www-form-urlencoded' == type) {
|
|
22546
|
+
this._data = this._data
|
|
22547
|
+
? this._data + '&' + data
|
|
22548
|
+
: data;
|
|
22549
|
+
} else {
|
|
22550
|
+
this._data = (this._data || '') + data;
|
|
22551
|
+
}
|
|
22552
|
+
} else {
|
|
22553
|
+
this._data = data;
|
|
22554
|
+
}
|
|
22555
|
+
|
|
22556
|
+
if (!obj || this._isHost(data)) return this;
|
|
22557
|
+
|
|
22558
|
+
// default to json
|
|
22559
|
+
if (!type) this.type('json');
|
|
22560
|
+
return this;
|
|
22561
|
+
};
|
|
22562
|
+
|
|
22563
|
+
},{"./is-object":50}],52:[function(require,module,exports){
|
|
22564
|
+
// The node and browser modules expose versions of this with the
|
|
22565
|
+
// appropriate constructor function bound as first argument
|
|
22566
|
+
/**
|
|
22567
|
+
* Issue a request:
|
|
22568
|
+
*
|
|
22569
|
+
* Examples:
|
|
22570
|
+
*
|
|
22571
|
+
* request('GET', '/users').end(callback)
|
|
22572
|
+
* request('/users').end(callback)
|
|
22573
|
+
* request('/users', callback)
|
|
22574
|
+
*
|
|
22575
|
+
* @param {String} method
|
|
22576
|
+
* @param {String|Function} url or callback
|
|
22577
|
+
* @return {Request}
|
|
22578
|
+
* @api public
|
|
22579
|
+
*/
|
|
22580
|
+
|
|
22581
|
+
function request(RequestConstructor, method, url) {
|
|
22582
|
+
// callback
|
|
22583
|
+
if ('function' == typeof url) {
|
|
22584
|
+
return new RequestConstructor('GET', method).end(url);
|
|
22585
|
+
}
|
|
22586
|
+
|
|
22587
|
+
// url first
|
|
22588
|
+
if (2 == arguments.length) {
|
|
22589
|
+
return new RequestConstructor('GET', method);
|
|
22590
|
+
}
|
|
22591
|
+
|
|
22592
|
+
return new RequestConstructor(method, url);
|
|
22593
|
+
}
|
|
22594
|
+
|
|
22126
22595
|
module.exports = request;
|
|
22127
22596
|
|
|
22128
|
-
},{
|
|
22597
|
+
},{}],53:[function(require,module,exports){
|
|
22129
22598
|
/*!
|
|
22130
22599
|
* validate.js 0.9.0
|
|
22131
22600
|
*
|