comprodls-sdk 2.68.0-development → 2.69.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 +887 -664
- package/dist/comprodls-sdk.min.js +12 -12
- package/lib/services/auth/index.js +49 -1
- package/lib/services/authextn/index.js +39 -104
- package/lib/services/spacesextn/index.js +45 -1
- package/package.json +2 -2
- package/test.js +0 -38
package/dist/comprodls-sdk.js
CHANGED
|
@@ -1150,7 +1150,7 @@ validator.validators.contains = function(value, options) {
|
|
|
1150
1150
|
}
|
|
1151
1151
|
}
|
|
1152
1152
|
};
|
|
1153
|
-
},{"./errors":7,"validate.js":
|
|
1153
|
+
},{"./errors":7,"validate.js":53}],10:[function(require,module,exports){
|
|
1154
1154
|
/*************************************************************************
|
|
1155
1155
|
*
|
|
1156
1156
|
* COMPRO CONFIDENTIAL
|
|
@@ -6595,6 +6595,7 @@ function updateClass(options) {
|
|
|
6595
6595
|
"analytics_score_aggregation_type": true,
|
|
6596
6596
|
"ext_data": true,
|
|
6597
6597
|
"limits": true,
|
|
6598
|
+
"skip_assigned_path_create_notification": true,
|
|
6598
6599
|
"advanced": {
|
|
6599
6600
|
"students": [
|
|
6600
6601
|
{
|
|
@@ -7614,7 +7615,54 @@ function deleteItemsFromShowcaseOfAClass(options){
|
|
|
7614
7615
|
* startdate: 'Epoch(Unix) timestamp in milliseconds',
|
|
7615
7616
|
* enddate: 'Epoch(Unix) timestamp in milliseconds',
|
|
7616
7617
|
* instructor: 'user who clones the class',
|
|
7617
|
-
* clone_setting: {
|
|
7618
|
+
* clone_setting: { // optional field
|
|
7619
|
+
* "students": true,
|
|
7620
|
+
* "teachers": true,
|
|
7621
|
+
* "products": true,
|
|
7622
|
+
* "groups": true,
|
|
7623
|
+
* "assigned_paths": true,
|
|
7624
|
+
* "skip_assigned_path_create_notification": true,
|
|
7625
|
+
* "tags": true,
|
|
7626
|
+
* "analyticsharingmodel": true,
|
|
7627
|
+
* "analytics_score_aggregation_type": true,
|
|
7628
|
+
* "ext_data": true,
|
|
7629
|
+
* "limits": true,
|
|
7630
|
+
* "advanced": {
|
|
7631
|
+
* "students": [
|
|
7632
|
+
* {
|
|
7633
|
+
* "ext_user_id": "string"
|
|
7634
|
+
* }
|
|
7635
|
+
* ],
|
|
7636
|
+
* "teachers": [
|
|
7637
|
+
* {
|
|
7638
|
+
* "ext_user_id": "string"
|
|
7639
|
+
* }
|
|
7640
|
+
* ],
|
|
7641
|
+
* "groups": [
|
|
7642
|
+
* {
|
|
7643
|
+
* "groupid": "string"
|
|
7644
|
+
* }
|
|
7645
|
+
* ],
|
|
7646
|
+
* "assigned_paths": [
|
|
7647
|
+
* {
|
|
7648
|
+
* "assigned_path_id": "string",
|
|
7649
|
+
* "startdate": 0,
|
|
7650
|
+
* "duedate": 0
|
|
7651
|
+
* }
|
|
7652
|
+
* ],
|
|
7653
|
+
* "products": [
|
|
7654
|
+
* {
|
|
7655
|
+
* "productcode": "string"
|
|
7656
|
+
* }
|
|
7657
|
+
* ],
|
|
7658
|
+
* "analyticsharingmodel": "NOINHERIT_SYNCBACK",
|
|
7659
|
+
* "analytics_score_aggregation_type": "best",
|
|
7660
|
+
* "limits": {
|
|
7661
|
+
* "los": 0,
|
|
7662
|
+
* "students": 0
|
|
7663
|
+
* }
|
|
7664
|
+
* }
|
|
7665
|
+
* },
|
|
7618
7666
|
* }
|
|
7619
7667
|
*/
|
|
7620
7668
|
function cloneClass(options) {
|
|
@@ -8718,8 +8766,7 @@ var keepaliveAgent = new Agent({
|
|
|
8718
8766
|
});
|
|
8719
8767
|
|
|
8720
8768
|
//AuthExtn Adaptor Contsructor
|
|
8721
|
-
function authextn(
|
|
8722
|
-
this.accountId = accountId;
|
|
8769
|
+
function authextn() {
|
|
8723
8770
|
return {
|
|
8724
8771
|
// Gradeformat related APIs
|
|
8725
8772
|
createGradeformat: createGradeformat.bind(this),
|
|
@@ -8745,9 +8792,7 @@ function authextn(accountId) {
|
|
|
8745
8792
|
createOrgProductEntitlement: createOrgProductEntitlement.bind(this),
|
|
8746
8793
|
updateOrgProductEntitlement: updateOrgProductEntitlement.bind(this),
|
|
8747
8794
|
getParticularOrgProductEntitlement: getParticularOrgProductEntitlement.bind(this),
|
|
8748
|
-
getAllOrgProductEntitlements: getAllOrgProductEntitlements.bind(this)
|
|
8749
|
-
setupUser: setupUser.bind(this)
|
|
8750
|
-
|
|
8795
|
+
getAllOrgProductEntitlements: getAllOrgProductEntitlements.bind(this)
|
|
8751
8796
|
};
|
|
8752
8797
|
}
|
|
8753
8798
|
|
|
@@ -9695,64 +9740,7 @@ function getParticularOrgProductEntitlement(options) {
|
|
|
9695
9740
|
//Initializing promise
|
|
9696
9741
|
var deferred = q.defer();
|
|
9697
9742
|
|
|
9698
|
-
|
|
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 {
|
|
9743
|
+
if (options && options.productcode) {
|
|
9756
9744
|
// Passed all validations, Contruct the API URL
|
|
9757
9745
|
var url = self.config.DEFAULT_HOSTS.AUTHEXTN +
|
|
9758
9746
|
self.config.AUTHEXTN_API_URLS.orgProductEntitlement;
|
|
@@ -9760,19 +9748,11 @@ function getAllOrgProductEntitlements(options) {
|
|
|
9760
9748
|
|
|
9761
9749
|
// Setup request with URL and Query Params
|
|
9762
9750
|
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
9751
|
var requestAPI = request.get(url).query(params);
|
|
9769
9752
|
|
|
9770
9753
|
// Setup 'traceid' in request header
|
|
9771
9754
|
if (self.traceid) { requestAPI.set('X-Amzn-Trace-Id', self.traceid); }
|
|
9772
9755
|
|
|
9773
|
-
// Setup 'token' in Authorization header
|
|
9774
|
-
requestAPI = helpers.api.setupAPIToken(requestAPI, self.token);
|
|
9775
|
-
|
|
9776
9756
|
requestAPI.agent(keepaliveAgent).end(function (error, response) {
|
|
9777
9757
|
if (error) {
|
|
9778
9758
|
error = new DLSError(helpers.errors.ERROR_TYPES.API_ERROR, error);
|
|
@@ -9781,6 +9761,12 @@ function getAllOrgProductEntitlements(options) {
|
|
|
9781
9761
|
deferred.resolve(response.body);
|
|
9782
9762
|
}
|
|
9783
9763
|
});
|
|
9764
|
+
} else {
|
|
9765
|
+
var error = {};
|
|
9766
|
+
error.message = error.description = 'Mandatory field \'productcode\' not found '+
|
|
9767
|
+
'in request options.';
|
|
9768
|
+
error = new DLSError(helpers.errors.ERROR_TYPES.SDK_ERROR, error);
|
|
9769
|
+
deferred.reject(error);
|
|
9784
9770
|
}
|
|
9785
9771
|
|
|
9786
9772
|
return deferred.promise;
|
|
@@ -9788,46 +9774,43 @@ function getAllOrgProductEntitlements(options) {
|
|
|
9788
9774
|
|
|
9789
9775
|
/**
|
|
9790
9776
|
* @param {
|
|
9791
|
-
*
|
|
9792
|
-
*
|
|
9793
|
-
* <
|
|
9794
|
-
* } options
|
|
9795
|
-
*/
|
|
9796
|
-
function
|
|
9777
|
+
* status: "string" // ['active', 'revoked']
|
|
9778
|
+
* expired: <boolean>,
|
|
9779
|
+
* cursor: <epoch>
|
|
9780
|
+
* } options
|
|
9781
|
+
*/
|
|
9782
|
+
function getAllOrgProductEntitlements(options) {
|
|
9797
9783
|
var self = this;
|
|
9798
9784
|
//Initializing promise
|
|
9799
9785
|
var deferred = q.defer();
|
|
9800
9786
|
|
|
9801
|
-
|
|
9802
|
-
|
|
9803
|
-
|
|
9804
|
-
|
|
9787
|
+
// Contruct the API URL
|
|
9788
|
+
var url = self.config.DEFAULT_HOSTS.AUTHEXTN +
|
|
9789
|
+
self.config.AUTHEXTN_API_URLS.orgProductEntitlement;
|
|
9790
|
+
url = helpers.api.constructAPIUrl(url, { orgid: self.orgId });
|
|
9805
9791
|
|
|
9806
|
-
|
|
9807
|
-
|
|
9808
|
-
.set('Accept', 'application/json')
|
|
9809
|
-
.send(options);
|
|
9792
|
+
// Setup request with URL and Query Params
|
|
9793
|
+
var params = { productcode: options.productcode };
|
|
9810
9794
|
|
|
9811
|
-
|
|
9795
|
+
if (options.status) { params.status = options.status; }
|
|
9796
|
+
if (options.hasOwnProperty('expired')) { params.expired = options.expired; }
|
|
9797
|
+
if (options.cursor) { params.cursor = options.cursor; }
|
|
9812
9798
|
|
|
9813
|
-
|
|
9814
|
-
|
|
9815
|
-
|
|
9816
|
-
|
|
9817
|
-
|
|
9818
|
-
|
|
9819
|
-
|
|
9820
|
-
|
|
9821
|
-
|
|
9822
|
-
}
|
|
9823
|
-
|
|
9824
|
-
|
|
9825
|
-
|
|
9826
|
-
|
|
9827
|
-
|
|
9828
|
-
deferred.reject(err);
|
|
9829
|
-
}
|
|
9830
|
-
return deferred.promise;
|
|
9799
|
+
var requestAPI = request.get(url).query(params);
|
|
9800
|
+
|
|
9801
|
+
// Setup 'traceid' in request header
|
|
9802
|
+
if (self.traceid) { requestAPI.set('X-Amzn-Trace-Id', self.traceid); }
|
|
9803
|
+
|
|
9804
|
+
requestAPI.agent(keepaliveAgent).end(function (error, response) {
|
|
9805
|
+
if (error) {
|
|
9806
|
+
error = new DLSError(helpers.errors.ERROR_TYPES.API_ERROR, error);
|
|
9807
|
+
deferred.reject(error);
|
|
9808
|
+
} else {
|
|
9809
|
+
deferred.resolve(response.body);
|
|
9810
|
+
}
|
|
9811
|
+
});
|
|
9812
|
+
|
|
9813
|
+
return deferred.promise;
|
|
9831
9814
|
}
|
|
9832
9815
|
|
|
9833
9816
|
},{"../../helpers":3,"agentkeepalive":36,"q":46,"superagent":49}],18:[function(require,module,exports){
|
|
@@ -14892,7 +14875,8 @@ var keepaliveAgent = new Agent({
|
|
|
14892
14875
|
function spacesextn(accountId) {
|
|
14893
14876
|
this.accountId = accountId;
|
|
14894
14877
|
return {
|
|
14895
|
-
entitleBulkUsersToProducts: entitleBulkUsersToProducts.bind(this)
|
|
14878
|
+
entitleBulkUsersToProducts: entitleBulkUsersToProducts.bind(this),
|
|
14879
|
+
setupUser: setupUser.bind(this)
|
|
14896
14880
|
};
|
|
14897
14881
|
}
|
|
14898
14882
|
|
|
@@ -14953,6 +14937,49 @@ function entitleBulkUsersToProducts(options) {
|
|
|
14953
14937
|
return dfd.promise;
|
|
14954
14938
|
}
|
|
14955
14939
|
|
|
14940
|
+
/**
|
|
14941
|
+
* @param {
|
|
14942
|
+
* *ext_user_id: "string",
|
|
14943
|
+
* *workflow_type: "string",
|
|
14944
|
+
* *<workflow_type>: {}
|
|
14945
|
+
* } options
|
|
14946
|
+
*/
|
|
14947
|
+
function setupUser(options) {
|
|
14948
|
+
var self = this;
|
|
14949
|
+
//Initializing promise
|
|
14950
|
+
var deferred = q.defer();
|
|
14951
|
+
|
|
14952
|
+
if (options && options.ext_user_id && options.workflow_type) {
|
|
14953
|
+
//Passed all validations, Contruct API url
|
|
14954
|
+
var url = self.config.DEFAULT_HOSTS.AUTHEXTN + self.config.AUTHEXTN_API_URLS.setupUser;
|
|
14955
|
+
url = helpers.api.constructAPIUrl(url, { accountId: self.accountId });
|
|
14956
|
+
|
|
14957
|
+
var requestAPI = request.post(url)
|
|
14958
|
+
.set('Content-Type', 'application/json')
|
|
14959
|
+
.set('Accept', 'application/json')
|
|
14960
|
+
.send(options);
|
|
14961
|
+
|
|
14962
|
+
if (self.traceid) { requestAPI.set('X-Amzn-Trace-Id', self.traceid); }
|
|
14963
|
+
|
|
14964
|
+
requestAPI
|
|
14965
|
+
.agent(keepaliveAgent)
|
|
14966
|
+
.end(function(err, res) {
|
|
14967
|
+
if (err) {
|
|
14968
|
+
err = new DLSError(helpers.errors.ERROR_TYPES.API_ERROR, err);
|
|
14969
|
+
deferred.reject(err);
|
|
14970
|
+
} else {
|
|
14971
|
+
deferred.resolve(res.body);
|
|
14972
|
+
}
|
|
14973
|
+
});
|
|
14974
|
+
} else {
|
|
14975
|
+
var err = {};
|
|
14976
|
+
err.message = err.description = 'Mandatory field \'ext_user_id\' or \'workflow_type\' not found '+
|
|
14977
|
+
'in the request options.';
|
|
14978
|
+
err = new DLSError(helpers.errors.ERROR_TYPES.SDK_ERROR, err);
|
|
14979
|
+
deferred.reject(err);
|
|
14980
|
+
}
|
|
14981
|
+
return deferred.promise;
|
|
14982
|
+
}
|
|
14956
14983
|
|
|
14957
14984
|
},{"../../helpers":3,"agentkeepalive":36,"q":46,"superagent":49}],30:[function(require,module,exports){
|
|
14958
14985
|
/*************************************************************************
|
|
@@ -18210,195 +18237,209 @@ module.exports = Array.isArray || function (arr) {
|
|
|
18210
18237
|
};
|
|
18211
18238
|
|
|
18212
18239
|
},{}],40:[function(require,module,exports){
|
|
18240
|
+
|
|
18241
|
+
/**
|
|
18242
|
+
* Expose `Emitter`.
|
|
18243
|
+
*/
|
|
18244
|
+
|
|
18245
|
+
if (typeof module !== 'undefined') {
|
|
18246
|
+
module.exports = Emitter;
|
|
18247
|
+
}
|
|
18248
|
+
|
|
18249
|
+
/**
|
|
18250
|
+
* Initialize a new `Emitter`.
|
|
18251
|
+
*
|
|
18252
|
+
* @api public
|
|
18253
|
+
*/
|
|
18254
|
+
|
|
18255
|
+
function Emitter(obj) {
|
|
18256
|
+
if (obj) return mixin(obj);
|
|
18257
|
+
};
|
|
18258
|
+
|
|
18259
|
+
/**
|
|
18260
|
+
* Mixin the emitter properties.
|
|
18261
|
+
*
|
|
18262
|
+
* @param {Object} obj
|
|
18263
|
+
* @return {Object}
|
|
18264
|
+
* @api private
|
|
18265
|
+
*/
|
|
18266
|
+
|
|
18267
|
+
function mixin(obj) {
|
|
18268
|
+
for (var key in Emitter.prototype) {
|
|
18269
|
+
obj[key] = Emitter.prototype[key];
|
|
18270
|
+
}
|
|
18271
|
+
return obj;
|
|
18272
|
+
}
|
|
18273
|
+
|
|
18274
|
+
/**
|
|
18275
|
+
* Listen on the given `event` with `fn`.
|
|
18276
|
+
*
|
|
18277
|
+
* @param {String} event
|
|
18278
|
+
* @param {Function} fn
|
|
18279
|
+
* @return {Emitter}
|
|
18280
|
+
* @api public
|
|
18281
|
+
*/
|
|
18282
|
+
|
|
18283
|
+
Emitter.prototype.on =
|
|
18284
|
+
Emitter.prototype.addEventListener = function(event, fn){
|
|
18285
|
+
this._callbacks = this._callbacks || {};
|
|
18286
|
+
(this._callbacks['$' + event] = this._callbacks['$' + event] || [])
|
|
18287
|
+
.push(fn);
|
|
18288
|
+
return this;
|
|
18289
|
+
};
|
|
18290
|
+
|
|
18291
|
+
/**
|
|
18292
|
+
* Adds an `event` listener that will be invoked a single
|
|
18293
|
+
* time then automatically removed.
|
|
18294
|
+
*
|
|
18295
|
+
* @param {String} event
|
|
18296
|
+
* @param {Function} fn
|
|
18297
|
+
* @return {Emitter}
|
|
18298
|
+
* @api public
|
|
18299
|
+
*/
|
|
18300
|
+
|
|
18301
|
+
Emitter.prototype.once = function(event, fn){
|
|
18302
|
+
function on() {
|
|
18303
|
+
this.off(event, on);
|
|
18304
|
+
fn.apply(this, arguments);
|
|
18305
|
+
}
|
|
18306
|
+
|
|
18307
|
+
on.fn = fn;
|
|
18308
|
+
this.on(event, on);
|
|
18309
|
+
return this;
|
|
18310
|
+
};
|
|
18311
|
+
|
|
18312
|
+
/**
|
|
18313
|
+
* Remove the given callback for `event` or all
|
|
18314
|
+
* registered callbacks.
|
|
18315
|
+
*
|
|
18316
|
+
* @param {String} event
|
|
18317
|
+
* @param {Function} fn
|
|
18318
|
+
* @return {Emitter}
|
|
18319
|
+
* @api public
|
|
18320
|
+
*/
|
|
18321
|
+
|
|
18322
|
+
Emitter.prototype.off =
|
|
18323
|
+
Emitter.prototype.removeListener =
|
|
18324
|
+
Emitter.prototype.removeAllListeners =
|
|
18325
|
+
Emitter.prototype.removeEventListener = function(event, fn){
|
|
18326
|
+
this._callbacks = this._callbacks || {};
|
|
18327
|
+
|
|
18328
|
+
// all
|
|
18329
|
+
if (0 == arguments.length) {
|
|
18330
|
+
this._callbacks = {};
|
|
18331
|
+
return this;
|
|
18332
|
+
}
|
|
18333
|
+
|
|
18334
|
+
// specific event
|
|
18335
|
+
var callbacks = this._callbacks['$' + event];
|
|
18336
|
+
if (!callbacks) return this;
|
|
18337
|
+
|
|
18338
|
+
// remove all handlers
|
|
18339
|
+
if (1 == arguments.length) {
|
|
18340
|
+
delete this._callbacks['$' + event];
|
|
18341
|
+
return this;
|
|
18342
|
+
}
|
|
18343
|
+
|
|
18344
|
+
// remove specific handler
|
|
18345
|
+
var cb;
|
|
18346
|
+
for (var i = 0; i < callbacks.length; i++) {
|
|
18347
|
+
cb = callbacks[i];
|
|
18348
|
+
if (cb === fn || cb.fn === fn) {
|
|
18349
|
+
callbacks.splice(i, 1);
|
|
18350
|
+
break;
|
|
18351
|
+
}
|
|
18352
|
+
}
|
|
18353
|
+
|
|
18354
|
+
// Remove event specific arrays for event types that no
|
|
18355
|
+
// one is subscribed for to avoid memory leak.
|
|
18356
|
+
if (callbacks.length === 0) {
|
|
18357
|
+
delete this._callbacks['$' + event];
|
|
18358
|
+
}
|
|
18359
|
+
|
|
18360
|
+
return this;
|
|
18361
|
+
};
|
|
18362
|
+
|
|
18363
|
+
/**
|
|
18364
|
+
* Emit `event` with the given args.
|
|
18365
|
+
*
|
|
18366
|
+
* @param {String} event
|
|
18367
|
+
* @param {Mixed} ...
|
|
18368
|
+
* @return {Emitter}
|
|
18369
|
+
*/
|
|
18370
|
+
|
|
18371
|
+
Emitter.prototype.emit = function(event){
|
|
18372
|
+
this._callbacks = this._callbacks || {};
|
|
18373
|
+
|
|
18374
|
+
var args = new Array(arguments.length - 1)
|
|
18375
|
+
, callbacks = this._callbacks['$' + event];
|
|
18376
|
+
|
|
18377
|
+
for (var i = 1; i < arguments.length; i++) {
|
|
18378
|
+
args[i - 1] = arguments[i];
|
|
18379
|
+
}
|
|
18380
|
+
|
|
18381
|
+
if (callbacks) {
|
|
18382
|
+
callbacks = callbacks.slice(0);
|
|
18383
|
+
for (var i = 0, len = callbacks.length; i < len; ++i) {
|
|
18384
|
+
callbacks[i].apply(this, args);
|
|
18385
|
+
}
|
|
18386
|
+
}
|
|
18387
|
+
|
|
18388
|
+
return this;
|
|
18389
|
+
};
|
|
18390
|
+
|
|
18391
|
+
/**
|
|
18392
|
+
* Return array of callbacks for `event`.
|
|
18393
|
+
*
|
|
18394
|
+
* @param {String} event
|
|
18395
|
+
* @return {Array}
|
|
18396
|
+
* @api public
|
|
18397
|
+
*/
|
|
18398
|
+
|
|
18399
|
+
Emitter.prototype.listeners = function(event){
|
|
18400
|
+
this._callbacks = this._callbacks || {};
|
|
18401
|
+
return this._callbacks['$' + event] || [];
|
|
18402
|
+
};
|
|
18403
|
+
|
|
18404
|
+
/**
|
|
18405
|
+
* Check if this emitter has `event` handlers.
|
|
18406
|
+
*
|
|
18407
|
+
* @param {String} event
|
|
18408
|
+
* @return {Boolean}
|
|
18409
|
+
* @api public
|
|
18410
|
+
*/
|
|
18411
|
+
|
|
18412
|
+
Emitter.prototype.hasListeners = function(event){
|
|
18413
|
+
return !! this.listeners(event).length;
|
|
18414
|
+
};
|
|
18213
18415
|
|
|
18214
|
-
|
|
18215
|
-
|
|
18216
|
-
|
|
18416
|
+
},{}],41:[function(require,module,exports){
|
|
18417
|
+
// Copyright Joyent, Inc. and other Node contributors.
|
|
18418
|
+
//
|
|
18419
|
+
// Permission is hereby granted, free of charge, to any person obtaining a
|
|
18420
|
+
// copy of this software and associated documentation files (the
|
|
18421
|
+
// "Software"), to deal in the Software without restriction, including
|
|
18422
|
+
// without limitation the rights to use, copy, modify, merge, publish,
|
|
18423
|
+
// distribute, sublicense, and/or sell copies of the Software, and to permit
|
|
18424
|
+
// persons to whom the Software is furnished to do so, subject to the
|
|
18425
|
+
// following conditions:
|
|
18426
|
+
//
|
|
18427
|
+
// The above copyright notice and this permission notice shall be included
|
|
18428
|
+
// in all copies or substantial portions of the Software.
|
|
18429
|
+
//
|
|
18430
|
+
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
|
|
18431
|
+
// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
|
18432
|
+
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN
|
|
18433
|
+
// NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
|
|
18434
|
+
// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
|
|
18435
|
+
// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
|
|
18436
|
+
// USE OR OTHER DEALINGS IN THE SOFTWARE.
|
|
18217
18437
|
|
|
18218
|
-
|
|
18219
|
-
|
|
18220
|
-
|
|
18221
|
-
|
|
18222
|
-
|
|
18223
|
-
* @api public
|
|
18224
|
-
*/
|
|
18225
|
-
|
|
18226
|
-
function Emitter(obj) {
|
|
18227
|
-
if (obj) return mixin(obj);
|
|
18228
|
-
};
|
|
18229
|
-
|
|
18230
|
-
/**
|
|
18231
|
-
* Mixin the emitter properties.
|
|
18232
|
-
*
|
|
18233
|
-
* @param {Object} obj
|
|
18234
|
-
* @return {Object}
|
|
18235
|
-
* @api private
|
|
18236
|
-
*/
|
|
18237
|
-
|
|
18238
|
-
function mixin(obj) {
|
|
18239
|
-
for (var key in Emitter.prototype) {
|
|
18240
|
-
obj[key] = Emitter.prototype[key];
|
|
18241
|
-
}
|
|
18242
|
-
return obj;
|
|
18243
|
-
}
|
|
18244
|
-
|
|
18245
|
-
/**
|
|
18246
|
-
* Listen on the given `event` with `fn`.
|
|
18247
|
-
*
|
|
18248
|
-
* @param {String} event
|
|
18249
|
-
* @param {Function} fn
|
|
18250
|
-
* @return {Emitter}
|
|
18251
|
-
* @api public
|
|
18252
|
-
*/
|
|
18253
|
-
|
|
18254
|
-
Emitter.prototype.on =
|
|
18255
|
-
Emitter.prototype.addEventListener = function(event, fn){
|
|
18256
|
-
this._callbacks = this._callbacks || {};
|
|
18257
|
-
(this._callbacks['$' + event] = this._callbacks['$' + event] || [])
|
|
18258
|
-
.push(fn);
|
|
18259
|
-
return this;
|
|
18260
|
-
};
|
|
18261
|
-
|
|
18262
|
-
/**
|
|
18263
|
-
* Adds an `event` listener that will be invoked a single
|
|
18264
|
-
* time then automatically removed.
|
|
18265
|
-
*
|
|
18266
|
-
* @param {String} event
|
|
18267
|
-
* @param {Function} fn
|
|
18268
|
-
* @return {Emitter}
|
|
18269
|
-
* @api public
|
|
18270
|
-
*/
|
|
18271
|
-
|
|
18272
|
-
Emitter.prototype.once = function(event, fn){
|
|
18273
|
-
function on() {
|
|
18274
|
-
this.off(event, on);
|
|
18275
|
-
fn.apply(this, arguments);
|
|
18276
|
-
}
|
|
18277
|
-
|
|
18278
|
-
on.fn = fn;
|
|
18279
|
-
this.on(event, on);
|
|
18280
|
-
return this;
|
|
18281
|
-
};
|
|
18282
|
-
|
|
18283
|
-
/**
|
|
18284
|
-
* Remove the given callback for `event` or all
|
|
18285
|
-
* registered callbacks.
|
|
18286
|
-
*
|
|
18287
|
-
* @param {String} event
|
|
18288
|
-
* @param {Function} fn
|
|
18289
|
-
* @return {Emitter}
|
|
18290
|
-
* @api public
|
|
18291
|
-
*/
|
|
18292
|
-
|
|
18293
|
-
Emitter.prototype.off =
|
|
18294
|
-
Emitter.prototype.removeListener =
|
|
18295
|
-
Emitter.prototype.removeAllListeners =
|
|
18296
|
-
Emitter.prototype.removeEventListener = function(event, fn){
|
|
18297
|
-
this._callbacks = this._callbacks || {};
|
|
18298
|
-
|
|
18299
|
-
// all
|
|
18300
|
-
if (0 == arguments.length) {
|
|
18301
|
-
this._callbacks = {};
|
|
18302
|
-
return this;
|
|
18303
|
-
}
|
|
18304
|
-
|
|
18305
|
-
// specific event
|
|
18306
|
-
var callbacks = this._callbacks['$' + event];
|
|
18307
|
-
if (!callbacks) return this;
|
|
18308
|
-
|
|
18309
|
-
// remove all handlers
|
|
18310
|
-
if (1 == arguments.length) {
|
|
18311
|
-
delete this._callbacks['$' + event];
|
|
18312
|
-
return this;
|
|
18313
|
-
}
|
|
18314
|
-
|
|
18315
|
-
// remove specific handler
|
|
18316
|
-
var cb;
|
|
18317
|
-
for (var i = 0; i < callbacks.length; i++) {
|
|
18318
|
-
cb = callbacks[i];
|
|
18319
|
-
if (cb === fn || cb.fn === fn) {
|
|
18320
|
-
callbacks.splice(i, 1);
|
|
18321
|
-
break;
|
|
18322
|
-
}
|
|
18323
|
-
}
|
|
18324
|
-
return this;
|
|
18325
|
-
};
|
|
18326
|
-
|
|
18327
|
-
/**
|
|
18328
|
-
* Emit `event` with the given args.
|
|
18329
|
-
*
|
|
18330
|
-
* @param {String} event
|
|
18331
|
-
* @param {Mixed} ...
|
|
18332
|
-
* @return {Emitter}
|
|
18333
|
-
*/
|
|
18334
|
-
|
|
18335
|
-
Emitter.prototype.emit = function(event){
|
|
18336
|
-
this._callbacks = this._callbacks || {};
|
|
18337
|
-
var args = [].slice.call(arguments, 1)
|
|
18338
|
-
, callbacks = this._callbacks['$' + event];
|
|
18339
|
-
|
|
18340
|
-
if (callbacks) {
|
|
18341
|
-
callbacks = callbacks.slice(0);
|
|
18342
|
-
for (var i = 0, len = callbacks.length; i < len; ++i) {
|
|
18343
|
-
callbacks[i].apply(this, args);
|
|
18344
|
-
}
|
|
18345
|
-
}
|
|
18346
|
-
|
|
18347
|
-
return this;
|
|
18348
|
-
};
|
|
18349
|
-
|
|
18350
|
-
/**
|
|
18351
|
-
* Return array of callbacks for `event`.
|
|
18352
|
-
*
|
|
18353
|
-
* @param {String} event
|
|
18354
|
-
* @return {Array}
|
|
18355
|
-
* @api public
|
|
18356
|
-
*/
|
|
18357
|
-
|
|
18358
|
-
Emitter.prototype.listeners = function(event){
|
|
18359
|
-
this._callbacks = this._callbacks || {};
|
|
18360
|
-
return this._callbacks['$' + event] || [];
|
|
18361
|
-
};
|
|
18362
|
-
|
|
18363
|
-
/**
|
|
18364
|
-
* Check if this emitter has `event` handlers.
|
|
18365
|
-
*
|
|
18366
|
-
* @param {String} event
|
|
18367
|
-
* @return {Boolean}
|
|
18368
|
-
* @api public
|
|
18369
|
-
*/
|
|
18370
|
-
|
|
18371
|
-
Emitter.prototype.hasListeners = function(event){
|
|
18372
|
-
return !! this.listeners(event).length;
|
|
18373
|
-
};
|
|
18374
|
-
|
|
18375
|
-
},{}],41:[function(require,module,exports){
|
|
18376
|
-
// Copyright Joyent, Inc. and other Node contributors.
|
|
18377
|
-
//
|
|
18378
|
-
// Permission is hereby granted, free of charge, to any person obtaining a
|
|
18379
|
-
// copy of this software and associated documentation files (the
|
|
18380
|
-
// "Software"), to deal in the Software without restriction, including
|
|
18381
|
-
// without limitation the rights to use, copy, modify, merge, publish,
|
|
18382
|
-
// distribute, sublicense, and/or sell copies of the Software, and to permit
|
|
18383
|
-
// persons to whom the Software is furnished to do so, subject to the
|
|
18384
|
-
// following conditions:
|
|
18385
|
-
//
|
|
18386
|
-
// The above copyright notice and this permission notice shall be included
|
|
18387
|
-
// in all copies or substantial portions of the Software.
|
|
18388
|
-
//
|
|
18389
|
-
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
|
|
18390
|
-
// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
|
18391
|
-
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN
|
|
18392
|
-
// NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
|
|
18393
|
-
// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
|
|
18394
|
-
// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
|
|
18395
|
-
// USE OR OTHER DEALINGS IN THE SOFTWARE.
|
|
18396
|
-
|
|
18397
|
-
function EventEmitter() {
|
|
18398
|
-
this._events = this._events || {};
|
|
18399
|
-
this._maxListeners = this._maxListeners || undefined;
|
|
18400
|
-
}
|
|
18401
|
-
module.exports = EventEmitter;
|
|
18438
|
+
function EventEmitter() {
|
|
18439
|
+
this._events = this._events || {};
|
|
18440
|
+
this._maxListeners = this._maxListeners || undefined;
|
|
18441
|
+
}
|
|
18442
|
+
module.exports = EventEmitter;
|
|
18402
18443
|
|
|
18403
18444
|
// Backwards-compat with node 0.10.x
|
|
18404
18445
|
EventEmitter.EventEmitter = EventEmitter;
|
|
@@ -18676,6 +18717,8 @@ function isUndefined(arg) {
|
|
|
18676
18717
|
}
|
|
18677
18718
|
|
|
18678
18719
|
},{}],42:[function(require,module,exports){
|
|
18720
|
+
'use strict';
|
|
18721
|
+
|
|
18679
18722
|
var hasOwn = Object.prototype.hasOwnProperty;
|
|
18680
18723
|
var toStr = Object.prototype.toString;
|
|
18681
18724
|
var defineProperty = Object.defineProperty;
|
|
@@ -18690,8 +18733,6 @@ var isArray = function isArray(arr) {
|
|
|
18690
18733
|
};
|
|
18691
18734
|
|
|
18692
18735
|
var isPlainObject = function isPlainObject(obj) {
|
|
18693
|
-
'use strict';
|
|
18694
|
-
|
|
18695
18736
|
if (!obj || toStr.call(obj) !== '[object Object]') {
|
|
18696
18737
|
return false;
|
|
18697
18738
|
}
|
|
@@ -18741,8 +18782,6 @@ var getProperty = function getProperty(obj, name) {
|
|
|
18741
18782
|
};
|
|
18742
18783
|
|
|
18743
18784
|
module.exports = function extend() {
|
|
18744
|
-
'use strict';
|
|
18745
|
-
|
|
18746
18785
|
var options, name, src, copy, copyIsArray, clone;
|
|
18747
18786
|
var target = arguments[0];
|
|
18748
18787
|
var i = 1;
|
|
@@ -21212,6 +21251,8 @@ function template(string) {
|
|
|
21212
21251
|
|
|
21213
21252
|
var Emitter = require('emitter');
|
|
21214
21253
|
var reduce = require('reduce');
|
|
21254
|
+
var requestBase = require('./request-base');
|
|
21255
|
+
var isObject = require('./is-object');
|
|
21215
21256
|
|
|
21216
21257
|
/**
|
|
21217
21258
|
* Root reference for iframes.
|
|
@@ -21233,28 +21274,10 @@ if (typeof window !== 'undefined') { // Browser window
|
|
|
21233
21274
|
function noop(){};
|
|
21234
21275
|
|
|
21235
21276
|
/**
|
|
21236
|
-
*
|
|
21237
|
-
* we don't want to serialize these :)
|
|
21238
|
-
*
|
|
21239
|
-
* TODO: future proof, move to compoent land
|
|
21240
|
-
*
|
|
21241
|
-
* @param {Object} obj
|
|
21242
|
-
* @return {Boolean}
|
|
21243
|
-
* @api private
|
|
21277
|
+
* Expose `request`.
|
|
21244
21278
|
*/
|
|
21245
21279
|
|
|
21246
|
-
|
|
21247
|
-
var str = {}.toString.call(obj);
|
|
21248
|
-
|
|
21249
|
-
switch (str) {
|
|
21250
|
-
case '[object File]':
|
|
21251
|
-
case '[object Blob]':
|
|
21252
|
-
case '[object FormData]':
|
|
21253
|
-
return true;
|
|
21254
|
-
default:
|
|
21255
|
-
return false;
|
|
21256
|
-
}
|
|
21257
|
-
}
|
|
21280
|
+
var request = module.exports = require('./request').bind(null, Request);
|
|
21258
21281
|
|
|
21259
21282
|
/**
|
|
21260
21283
|
* Determine XHR.
|
|
@@ -21286,18 +21309,6 @@ var trim = ''.trim
|
|
|
21286
21309
|
? function(s) { return s.trim(); }
|
|
21287
21310
|
: function(s) { return s.replace(/(^\s*|\s*$)/g, ''); };
|
|
21288
21311
|
|
|
21289
|
-
/**
|
|
21290
|
-
* Check if `obj` is an object.
|
|
21291
|
-
*
|
|
21292
|
-
* @param {Object} obj
|
|
21293
|
-
* @return {Boolean}
|
|
21294
|
-
* @api private
|
|
21295
|
-
*/
|
|
21296
|
-
|
|
21297
|
-
function isObject(obj) {
|
|
21298
|
-
return obj === Object(obj);
|
|
21299
|
-
}
|
|
21300
|
-
|
|
21301
21312
|
/**
|
|
21302
21313
|
* Serialize the given `obj`.
|
|
21303
21314
|
*
|
|
@@ -21312,8 +21323,8 @@ function serialize(obj) {
|
|
|
21312
21323
|
for (var key in obj) {
|
|
21313
21324
|
if (null != obj[key]) {
|
|
21314
21325
|
pushEncodedKeyValuePair(pairs, key, obj[key]);
|
|
21315
|
-
|
|
21316
|
-
|
|
21326
|
+
}
|
|
21327
|
+
}
|
|
21317
21328
|
return pairs.join('&');
|
|
21318
21329
|
}
|
|
21319
21330
|
|
|
@@ -21331,6 +21342,11 @@ function pushEncodedKeyValuePair(pairs, key, val) {
|
|
|
21331
21342
|
return val.forEach(function(v) {
|
|
21332
21343
|
pushEncodedKeyValuePair(pairs, key, v);
|
|
21333
21344
|
});
|
|
21345
|
+
} else if (isObject(val)) {
|
|
21346
|
+
for(var subkey in val) {
|
|
21347
|
+
pushEncodedKeyValuePair(pairs, key + '[' + subkey + ']', val[subkey]);
|
|
21348
|
+
}
|
|
21349
|
+
return;
|
|
21334
21350
|
}
|
|
21335
21351
|
pairs.push(encodeURIComponent(key)
|
|
21336
21352
|
+ '=' + encodeURIComponent(val));
|
|
@@ -21353,13 +21369,18 @@ function pushEncodedKeyValuePair(pairs, key, val) {
|
|
|
21353
21369
|
function parseString(str) {
|
|
21354
21370
|
var obj = {};
|
|
21355
21371
|
var pairs = str.split('&');
|
|
21356
|
-
var parts;
|
|
21357
21372
|
var pair;
|
|
21373
|
+
var pos;
|
|
21358
21374
|
|
|
21359
21375
|
for (var i = 0, len = pairs.length; i < len; ++i) {
|
|
21360
21376
|
pair = pairs[i];
|
|
21361
|
-
|
|
21362
|
-
|
|
21377
|
+
pos = pair.indexOf('=');
|
|
21378
|
+
if (pos == -1) {
|
|
21379
|
+
obj[decodeURIComponent(pair)] = '';
|
|
21380
|
+
} else {
|
|
21381
|
+
obj[decodeURIComponent(pair.slice(0, pos))] =
|
|
21382
|
+
decodeURIComponent(pair.slice(pos + 1));
|
|
21383
|
+
}
|
|
21363
21384
|
}
|
|
21364
21385
|
|
|
21365
21386
|
return obj;
|
|
@@ -21543,15 +21564,15 @@ function Response(req, options) {
|
|
|
21543
21564
|
? this.xhr.responseText
|
|
21544
21565
|
: null;
|
|
21545
21566
|
this.statusText = this.req.xhr.statusText;
|
|
21546
|
-
this.
|
|
21567
|
+
this._setStatusProperties(this.xhr.status);
|
|
21547
21568
|
this.header = this.headers = parseHeader(this.xhr.getAllResponseHeaders());
|
|
21548
21569
|
// getAllResponseHeaders sometimes falsely returns "" for CORS requests, but
|
|
21549
21570
|
// getResponseHeader still works. so we get content-type even if getting
|
|
21550
21571
|
// other headers fails.
|
|
21551
21572
|
this.header['content-type'] = this.xhr.getResponseHeader('content-type');
|
|
21552
|
-
this.
|
|
21573
|
+
this._setHeaderProperties(this.header);
|
|
21553
21574
|
this.body = this.req.method != 'HEAD'
|
|
21554
|
-
? this.
|
|
21575
|
+
? this._parseBody(this.text ? this.text : this.xhr.response)
|
|
21555
21576
|
: null;
|
|
21556
21577
|
}
|
|
21557
21578
|
|
|
@@ -21579,7 +21600,7 @@ Response.prototype.get = function(field){
|
|
|
21579
21600
|
* @api private
|
|
21580
21601
|
*/
|
|
21581
21602
|
|
|
21582
|
-
Response.prototype.
|
|
21603
|
+
Response.prototype._setHeaderProperties = function(header){
|
|
21583
21604
|
// content-type
|
|
21584
21605
|
var ct = this.header['content-type'] || '';
|
|
21585
21606
|
this.type = type(ct);
|
|
@@ -21600,8 +21621,11 @@ Response.prototype.setHeaderProperties = function(header){
|
|
|
21600
21621
|
* @api private
|
|
21601
21622
|
*/
|
|
21602
21623
|
|
|
21603
|
-
Response.prototype.
|
|
21624
|
+
Response.prototype._parseBody = function(str){
|
|
21604
21625
|
var parse = request.parse[this.type];
|
|
21626
|
+
if (!parse && isJSON(this.type)) {
|
|
21627
|
+
parse = request.parse['application/json'];
|
|
21628
|
+
}
|
|
21605
21629
|
return parse && str && (str.length || str instanceof Object)
|
|
21606
21630
|
? parse(str)
|
|
21607
21631
|
: null;
|
|
@@ -21628,7 +21652,7 @@ Response.prototype.parseBody = function(str){
|
|
|
21628
21652
|
* @api private
|
|
21629
21653
|
*/
|
|
21630
21654
|
|
|
21631
|
-
Response.prototype.
|
|
21655
|
+
Response.prototype._setStatusProperties = function(status){
|
|
21632
21656
|
// handle IE9 bug: http://stackoverflow.com/questions/10046972/msie-returns-status-code-of-1223-for-ajax-request
|
|
21633
21657
|
if (status === 1223) {
|
|
21634
21658
|
status = 204;
|
|
@@ -21696,12 +21720,11 @@ request.Response = Response;
|
|
|
21696
21720
|
|
|
21697
21721
|
function Request(method, url) {
|
|
21698
21722
|
var self = this;
|
|
21699
|
-
Emitter.call(this);
|
|
21700
21723
|
this._query = this._query || [];
|
|
21701
21724
|
this.method = method;
|
|
21702
21725
|
this.url = url;
|
|
21703
|
-
this.header = {};
|
|
21704
|
-
this._header = {};
|
|
21726
|
+
this.header = {}; // preserves header name case
|
|
21727
|
+
this._header = {}; // coerces header names to lowercase
|
|
21705
21728
|
this.on('end', function(){
|
|
21706
21729
|
var err = null;
|
|
21707
21730
|
var res = null;
|
|
@@ -21714,6 +21737,8 @@ function Request(method, url) {
|
|
|
21714
21737
|
err.original = e;
|
|
21715
21738
|
// issue #675: return the raw response if the response parsing fails
|
|
21716
21739
|
err.rawResponse = self.xhr && self.xhr.responseText ? self.xhr.responseText : null;
|
|
21740
|
+
// issue #876: return the http status code if the response parsing fails
|
|
21741
|
+
err.statusCode = self.xhr && self.xhr.status ? self.xhr.status : null;
|
|
21717
21742
|
return self.callback(err);
|
|
21718
21743
|
}
|
|
21719
21744
|
|
|
@@ -21723,218 +21748,132 @@ function Request(method, url) {
|
|
|
21723
21748
|
return self.callback(err, res);
|
|
21724
21749
|
}
|
|
21725
21750
|
|
|
21726
|
-
|
|
21727
|
-
|
|
21728
|
-
|
|
21751
|
+
try {
|
|
21752
|
+
if (res.status >= 200 && res.status < 300) {
|
|
21753
|
+
return self.callback(err, res);
|
|
21754
|
+
}
|
|
21729
21755
|
|
|
21730
|
-
|
|
21731
|
-
|
|
21732
|
-
|
|
21733
|
-
|
|
21756
|
+
var new_err = new Error(res.statusText || 'Unsuccessful HTTP response');
|
|
21757
|
+
new_err.original = err;
|
|
21758
|
+
new_err.response = res;
|
|
21759
|
+
new_err.status = res.status;
|
|
21734
21760
|
|
|
21735
|
-
|
|
21761
|
+
self.callback(new_err, res);
|
|
21762
|
+
} catch(e) {
|
|
21763
|
+
self.callback(e); // #985 touching res may cause INVALID_STATE_ERR on old Android
|
|
21764
|
+
}
|
|
21736
21765
|
});
|
|
21737
21766
|
}
|
|
21738
21767
|
|
|
21739
21768
|
/**
|
|
21740
|
-
* Mixin `Emitter`.
|
|
21769
|
+
* Mixin `Emitter` and `requestBase`.
|
|
21741
21770
|
*/
|
|
21742
21771
|
|
|
21743
21772
|
Emitter(Request.prototype);
|
|
21744
|
-
|
|
21745
|
-
|
|
21746
|
-
* Allow for extension
|
|
21747
|
-
*/
|
|
21748
|
-
|
|
21749
|
-
Request.prototype.use = function(fn) {
|
|
21750
|
-
fn(this);
|
|
21751
|
-
return this;
|
|
21773
|
+
for (var key in requestBase) {
|
|
21774
|
+
Request.prototype[key] = requestBase[key];
|
|
21752
21775
|
}
|
|
21753
21776
|
|
|
21754
21777
|
/**
|
|
21755
|
-
* Set
|
|
21778
|
+
* Set Content-Type to `type`, mapping values from `request.types`.
|
|
21756
21779
|
*
|
|
21757
|
-
*
|
|
21758
|
-
*
|
|
21759
|
-
*
|
|
21760
|
-
|
|
21761
|
-
|
|
21762
|
-
|
|
21763
|
-
|
|
21764
|
-
|
|
21765
|
-
|
|
21766
|
-
|
|
21767
|
-
|
|
21768
|
-
*
|
|
21780
|
+
* Examples:
|
|
21781
|
+
*
|
|
21782
|
+
* superagent.types.xml = 'application/xml';
|
|
21783
|
+
*
|
|
21784
|
+
* request.post('/')
|
|
21785
|
+
* .type('xml')
|
|
21786
|
+
* .send(xmlstring)
|
|
21787
|
+
* .end(callback);
|
|
21788
|
+
*
|
|
21789
|
+
* request.post('/')
|
|
21790
|
+
* .type('application/xml')
|
|
21791
|
+
* .send(xmlstring)
|
|
21792
|
+
* .end(callback);
|
|
21769
21793
|
*
|
|
21794
|
+
* @param {String} type
|
|
21770
21795
|
* @return {Request} for chaining
|
|
21771
21796
|
* @api public
|
|
21772
21797
|
*/
|
|
21773
21798
|
|
|
21774
|
-
Request.prototype.
|
|
21775
|
-
this.
|
|
21776
|
-
clearTimeout(this._timer);
|
|
21799
|
+
Request.prototype.type = function(type){
|
|
21800
|
+
this.set('Content-Type', request.types[type] || type);
|
|
21777
21801
|
return this;
|
|
21778
21802
|
};
|
|
21779
21803
|
|
|
21780
21804
|
/**
|
|
21781
|
-
*
|
|
21805
|
+
* Set responseType to `val`. Presently valid responseTypes are 'blob' and
|
|
21806
|
+
* 'arraybuffer'.
|
|
21782
21807
|
*
|
|
21783
|
-
*
|
|
21808
|
+
* Examples:
|
|
21809
|
+
*
|
|
21810
|
+
* req.get('/')
|
|
21811
|
+
* .responseType('blob')
|
|
21812
|
+
* .end(callback);
|
|
21813
|
+
*
|
|
21814
|
+
* @param {String} val
|
|
21815
|
+
* @return {Request} for chaining
|
|
21784
21816
|
* @api public
|
|
21785
21817
|
*/
|
|
21786
21818
|
|
|
21787
|
-
Request.prototype.
|
|
21788
|
-
|
|
21789
|
-
this.aborted = true;
|
|
21790
|
-
this.xhr.abort();
|
|
21791
|
-
this.clearTimeout();
|
|
21792
|
-
this.emit('abort');
|
|
21819
|
+
Request.prototype.responseType = function(val){
|
|
21820
|
+
this._responseType = val;
|
|
21793
21821
|
return this;
|
|
21794
21822
|
};
|
|
21795
21823
|
|
|
21796
21824
|
/**
|
|
21797
|
-
* Set
|
|
21825
|
+
* Set Accept to `type`, mapping values from `request.types`.
|
|
21798
21826
|
*
|
|
21799
21827
|
* Examples:
|
|
21800
21828
|
*
|
|
21801
|
-
*
|
|
21802
|
-
*
|
|
21803
|
-
*
|
|
21829
|
+
* superagent.types.json = 'application/json';
|
|
21830
|
+
*
|
|
21831
|
+
* request.get('/agent')
|
|
21832
|
+
* .accept('json')
|
|
21804
21833
|
* .end(callback);
|
|
21805
21834
|
*
|
|
21806
|
-
*
|
|
21807
|
-
* .
|
|
21835
|
+
* request.get('/agent')
|
|
21836
|
+
* .accept('application/json')
|
|
21808
21837
|
* .end(callback);
|
|
21809
21838
|
*
|
|
21810
|
-
* @param {String
|
|
21811
|
-
* @param {String} val
|
|
21839
|
+
* @param {String} accept
|
|
21812
21840
|
* @return {Request} for chaining
|
|
21813
21841
|
* @api public
|
|
21814
21842
|
*/
|
|
21815
21843
|
|
|
21816
|
-
Request.prototype.
|
|
21817
|
-
|
|
21818
|
-
for (var key in field) {
|
|
21819
|
-
this.set(key, field[key]);
|
|
21820
|
-
}
|
|
21821
|
-
return this;
|
|
21822
|
-
}
|
|
21823
|
-
this._header[field.toLowerCase()] = val;
|
|
21824
|
-
this.header[field] = val;
|
|
21844
|
+
Request.prototype.accept = function(type){
|
|
21845
|
+
this.set('Accept', request.types[type] || type);
|
|
21825
21846
|
return this;
|
|
21826
21847
|
};
|
|
21827
21848
|
|
|
21828
21849
|
/**
|
|
21829
|
-
*
|
|
21830
|
-
*
|
|
21831
|
-
* Example:
|
|
21832
|
-
*
|
|
21833
|
-
* req.get('/')
|
|
21834
|
-
* .unset('User-Agent')
|
|
21835
|
-
* .end(callback);
|
|
21850
|
+
* Set Authorization field value with `user` and `pass`.
|
|
21836
21851
|
*
|
|
21837
|
-
* @param {String}
|
|
21852
|
+
* @param {String} user
|
|
21853
|
+
* @param {String} pass
|
|
21854
|
+
* @param {Object} options with 'type' property 'auto' or 'basic' (default 'basic')
|
|
21838
21855
|
* @return {Request} for chaining
|
|
21839
21856
|
* @api public
|
|
21840
21857
|
*/
|
|
21841
21858
|
|
|
21842
|
-
Request.prototype.
|
|
21843
|
-
|
|
21844
|
-
|
|
21845
|
-
|
|
21846
|
-
}
|
|
21847
|
-
|
|
21848
|
-
|
|
21849
|
-
|
|
21850
|
-
|
|
21851
|
-
|
|
21852
|
-
|
|
21853
|
-
|
|
21854
|
-
|
|
21855
|
-
|
|
21856
|
-
|
|
21857
|
-
|
|
21858
|
-
|
|
21859
|
-
|
|
21860
|
-
/**
|
|
21861
|
-
* Set Content-Type to `type`, mapping values from `request.types`.
|
|
21862
|
-
*
|
|
21863
|
-
* Examples:
|
|
21864
|
-
*
|
|
21865
|
-
* superagent.types.xml = 'application/xml';
|
|
21866
|
-
*
|
|
21867
|
-
* request.post('/')
|
|
21868
|
-
* .type('xml')
|
|
21869
|
-
* .send(xmlstring)
|
|
21870
|
-
* .end(callback);
|
|
21871
|
-
*
|
|
21872
|
-
* request.post('/')
|
|
21873
|
-
* .type('application/xml')
|
|
21874
|
-
* .send(xmlstring)
|
|
21875
|
-
* .end(callback);
|
|
21876
|
-
*
|
|
21877
|
-
* @param {String} type
|
|
21878
|
-
* @return {Request} for chaining
|
|
21879
|
-
* @api public
|
|
21880
|
-
*/
|
|
21881
|
-
|
|
21882
|
-
Request.prototype.type = function(type){
|
|
21883
|
-
this.set('Content-Type', request.types[type] || type);
|
|
21884
|
-
return this;
|
|
21885
|
-
};
|
|
21886
|
-
|
|
21887
|
-
/**
|
|
21888
|
-
* Force given parser
|
|
21889
|
-
*
|
|
21890
|
-
* Sets the body parser no matter type.
|
|
21891
|
-
*
|
|
21892
|
-
* @param {Function}
|
|
21893
|
-
* @api public
|
|
21894
|
-
*/
|
|
21895
|
-
|
|
21896
|
-
Request.prototype.parse = function(fn){
|
|
21897
|
-
this._parser = fn;
|
|
21898
|
-
return this;
|
|
21899
|
-
};
|
|
21900
|
-
|
|
21901
|
-
/**
|
|
21902
|
-
* Set Accept to `type`, mapping values from `request.types`.
|
|
21903
|
-
*
|
|
21904
|
-
* Examples:
|
|
21905
|
-
*
|
|
21906
|
-
* superagent.types.json = 'application/json';
|
|
21907
|
-
*
|
|
21908
|
-
* request.get('/agent')
|
|
21909
|
-
* .accept('json')
|
|
21910
|
-
* .end(callback);
|
|
21911
|
-
*
|
|
21912
|
-
* request.get('/agent')
|
|
21913
|
-
* .accept('application/json')
|
|
21914
|
-
* .end(callback);
|
|
21915
|
-
*
|
|
21916
|
-
* @param {String} accept
|
|
21917
|
-
* @return {Request} for chaining
|
|
21918
|
-
* @api public
|
|
21919
|
-
*/
|
|
21920
|
-
|
|
21921
|
-
Request.prototype.accept = function(type){
|
|
21922
|
-
this.set('Accept', request.types[type] || type);
|
|
21923
|
-
return this;
|
|
21924
|
-
};
|
|
21925
|
-
|
|
21926
|
-
/**
|
|
21927
|
-
* Set Authorization field value with `user` and `pass`.
|
|
21928
|
-
*
|
|
21929
|
-
* @param {String} user
|
|
21930
|
-
* @param {String} pass
|
|
21931
|
-
* @return {Request} for chaining
|
|
21932
|
-
* @api public
|
|
21933
|
-
*/
|
|
21934
|
-
|
|
21935
|
-
Request.prototype.auth = function(user, pass){
|
|
21936
|
-
var str = btoa(user + ':' + pass);
|
|
21937
|
-
this.set('Authorization', 'Basic ' + str);
|
|
21859
|
+
Request.prototype.auth = function(user, pass, options){
|
|
21860
|
+
if (!options) {
|
|
21861
|
+
options = {
|
|
21862
|
+
type: 'basic'
|
|
21863
|
+
}
|
|
21864
|
+
}
|
|
21865
|
+
|
|
21866
|
+
switch (options.type) {
|
|
21867
|
+
case 'basic':
|
|
21868
|
+
var str = btoa(user + ':' + pass);
|
|
21869
|
+
this.set('Authorization', 'Basic ' + str);
|
|
21870
|
+
break;
|
|
21871
|
+
|
|
21872
|
+
case 'auto':
|
|
21873
|
+
this.username = user;
|
|
21874
|
+
this.password = pass;
|
|
21875
|
+
break;
|
|
21876
|
+
}
|
|
21938
21877
|
return this;
|
|
21939
21878
|
};
|
|
21940
21879
|
|
|
@@ -21958,35 +21897,13 @@ Request.prototype.query = function(val){
|
|
|
21958
21897
|
return this;
|
|
21959
21898
|
};
|
|
21960
21899
|
|
|
21961
|
-
/**
|
|
21962
|
-
* Write the field `name` and `val` for "multipart/form-data"
|
|
21963
|
-
* request bodies.
|
|
21964
|
-
*
|
|
21965
|
-
* ``` js
|
|
21966
|
-
* request.post('/upload')
|
|
21967
|
-
* .field('foo', 'bar')
|
|
21968
|
-
* .end(callback);
|
|
21969
|
-
* ```
|
|
21970
|
-
*
|
|
21971
|
-
* @param {String} name
|
|
21972
|
-
* @param {String|Blob|File} val
|
|
21973
|
-
* @return {Request} for chaining
|
|
21974
|
-
* @api public
|
|
21975
|
-
*/
|
|
21976
|
-
|
|
21977
|
-
Request.prototype.field = function(name, val){
|
|
21978
|
-
if (!this._formData) this._formData = new root.FormData();
|
|
21979
|
-
this._formData.append(name, val);
|
|
21980
|
-
return this;
|
|
21981
|
-
};
|
|
21982
|
-
|
|
21983
21900
|
/**
|
|
21984
21901
|
* Queue the given `file` as an attachment to the specified `field`,
|
|
21985
21902
|
* with optional `filename`.
|
|
21986
21903
|
*
|
|
21987
21904
|
* ``` js
|
|
21988
21905
|
* request.post('/upload')
|
|
21989
|
-
* .attach(new Blob(['<a id="a"><b id="b">hey!</b></a>'], { type: "text/html"}))
|
|
21906
|
+
* .attach('content', new Blob(['<a id="a"><b id="b">hey!</b></a>'], { type: "text/html"}))
|
|
21990
21907
|
* .end(callback);
|
|
21991
21908
|
* ```
|
|
21992
21909
|
*
|
|
@@ -21998,77 +21915,15 @@ Request.prototype.field = function(name, val){
|
|
|
21998
21915
|
*/
|
|
21999
21916
|
|
|
22000
21917
|
Request.prototype.attach = function(field, file, filename){
|
|
22001
|
-
|
|
22002
|
-
this._formData.append(field, file, filename || file.name);
|
|
21918
|
+
this._getFormData().append(field, file, filename || file.name);
|
|
22003
21919
|
return this;
|
|
22004
21920
|
};
|
|
22005
21921
|
|
|
22006
|
-
|
|
22007
|
-
|
|
22008
|
-
|
|
22009
|
-
*
|
|
22010
|
-
* Examples:
|
|
22011
|
-
*
|
|
22012
|
-
* // manual json
|
|
22013
|
-
* request.post('/user')
|
|
22014
|
-
* .type('json')
|
|
22015
|
-
* .send('{"name":"tj"}')
|
|
22016
|
-
* .end(callback)
|
|
22017
|
-
*
|
|
22018
|
-
* // auto json
|
|
22019
|
-
* request.post('/user')
|
|
22020
|
-
* .send({ name: 'tj' })
|
|
22021
|
-
* .end(callback)
|
|
22022
|
-
*
|
|
22023
|
-
* // manual x-www-form-urlencoded
|
|
22024
|
-
* request.post('/user')
|
|
22025
|
-
* .type('form')
|
|
22026
|
-
* .send('name=tj')
|
|
22027
|
-
* .end(callback)
|
|
22028
|
-
*
|
|
22029
|
-
* // auto x-www-form-urlencoded
|
|
22030
|
-
* request.post('/user')
|
|
22031
|
-
* .type('form')
|
|
22032
|
-
* .send({ name: 'tj' })
|
|
22033
|
-
* .end(callback)
|
|
22034
|
-
*
|
|
22035
|
-
* // defaults to x-www-form-urlencoded
|
|
22036
|
-
* request.post('/user')
|
|
22037
|
-
* .send('name=tobi')
|
|
22038
|
-
* .send('species=ferret')
|
|
22039
|
-
* .end(callback)
|
|
22040
|
-
*
|
|
22041
|
-
* @param {String|Object} data
|
|
22042
|
-
* @return {Request} for chaining
|
|
22043
|
-
* @api public
|
|
22044
|
-
*/
|
|
22045
|
-
|
|
22046
|
-
Request.prototype.send = function(data){
|
|
22047
|
-
var obj = isObject(data);
|
|
22048
|
-
var type = this.getHeader('Content-Type');
|
|
22049
|
-
|
|
22050
|
-
// merge
|
|
22051
|
-
if (obj && isObject(this._data)) {
|
|
22052
|
-
for (var key in data) {
|
|
22053
|
-
this._data[key] = data[key];
|
|
22054
|
-
}
|
|
22055
|
-
} else if ('string' == typeof data) {
|
|
22056
|
-
if (!type) this.type('form');
|
|
22057
|
-
type = this.getHeader('Content-Type');
|
|
22058
|
-
if ('application/x-www-form-urlencoded' == type) {
|
|
22059
|
-
this._data = this._data
|
|
22060
|
-
? this._data + '&' + data
|
|
22061
|
-
: data;
|
|
22062
|
-
} else {
|
|
22063
|
-
this._data = (this._data || '') + data;
|
|
22064
|
-
}
|
|
22065
|
-
} else {
|
|
22066
|
-
this._data = data;
|
|
21922
|
+
Request.prototype._getFormData = function(){
|
|
21923
|
+
if (!this._formData) {
|
|
21924
|
+
this._formData = new root.FormData();
|
|
22067
21925
|
}
|
|
22068
|
-
|
|
22069
|
-
if (!obj || isHost(data)) return this;
|
|
22070
|
-
if (!type) this.type('json');
|
|
22071
|
-
return this;
|
|
21926
|
+
return this._formData;
|
|
22072
21927
|
};
|
|
22073
21928
|
|
|
22074
21929
|
/**
|
|
@@ -22109,7 +21964,7 @@ Request.prototype.crossDomainError = function(){
|
|
|
22109
21964
|
* @api private
|
|
22110
21965
|
*/
|
|
22111
21966
|
|
|
22112
|
-
Request.prototype.
|
|
21967
|
+
Request.prototype._timeoutError = function(){
|
|
22113
21968
|
var timeout = this._timeout;
|
|
22114
21969
|
var err = new Error('timeout of ' + timeout + 'ms exceeded');
|
|
22115
21970
|
err.timeout = timeout;
|
|
@@ -22117,19 +21972,18 @@ Request.prototype.timeoutError = function(){
|
|
|
22117
21972
|
};
|
|
22118
21973
|
|
|
22119
21974
|
/**
|
|
22120
|
-
*
|
|
22121
|
-
*
|
|
22122
|
-
* Note that for this to work the origin must not be
|
|
22123
|
-
* using "Access-Control-Allow-Origin" with a wildcard,
|
|
22124
|
-
* and also must set "Access-Control-Allow-Credentials"
|
|
22125
|
-
* to "true".
|
|
21975
|
+
* Compose querystring to append to req.url
|
|
22126
21976
|
*
|
|
22127
|
-
* @api
|
|
21977
|
+
* @api private
|
|
22128
21978
|
*/
|
|
22129
21979
|
|
|
22130
|
-
Request.prototype.
|
|
22131
|
-
|
|
22132
|
-
|
|
21980
|
+
Request.prototype._appendQueryString = function(){
|
|
21981
|
+
var query = this._query.join('&');
|
|
21982
|
+
if (query) {
|
|
21983
|
+
this.url += ~this.url.indexOf('?')
|
|
21984
|
+
? '&' + query
|
|
21985
|
+
: '?' + query;
|
|
21986
|
+
}
|
|
22133
21987
|
};
|
|
22134
21988
|
|
|
22135
21989
|
/**
|
|
@@ -22144,7 +21998,6 @@ Request.prototype.withCredentials = function(){
|
|
|
22144
21998
|
Request.prototype.end = function(fn){
|
|
22145
21999
|
var self = this;
|
|
22146
22000
|
var xhr = this.xhr = request.getXHR();
|
|
22147
|
-
var query = this._query.join('&');
|
|
22148
22001
|
var timeout = this._timeout;
|
|
22149
22002
|
var data = this._formData || this._data;
|
|
22150
22003
|
|
|
@@ -22161,8 +22014,8 @@ Request.prototype.end = function(fn){
|
|
|
22161
22014
|
try { status = xhr.status } catch(e) { status = 0; }
|
|
22162
22015
|
|
|
22163
22016
|
if (0 == status) {
|
|
22164
|
-
if (self.timedout) return self.
|
|
22165
|
-
if (self.
|
|
22017
|
+
if (self.timedout) return self._timeoutError();
|
|
22018
|
+
if (self._aborted) return;
|
|
22166
22019
|
return self.crossDomainError();
|
|
22167
22020
|
}
|
|
22168
22021
|
self.emit('end');
|
|
@@ -22198,24 +22051,23 @@ Request.prototype.end = function(fn){
|
|
|
22198
22051
|
}
|
|
22199
22052
|
|
|
22200
22053
|
// querystring
|
|
22201
|
-
|
|
22202
|
-
query = request.serializeObject(query);
|
|
22203
|
-
this.url += ~this.url.indexOf('?')
|
|
22204
|
-
? '&' + query
|
|
22205
|
-
: '?' + query;
|
|
22206
|
-
}
|
|
22054
|
+
this._appendQueryString();
|
|
22207
22055
|
|
|
22208
22056
|
// initiate request
|
|
22209
|
-
|
|
22057
|
+
if (this.username && this.password) {
|
|
22058
|
+
xhr.open(this.method, this.url, true, this.username, this.password);
|
|
22059
|
+
} else {
|
|
22060
|
+
xhr.open(this.method, this.url, true);
|
|
22061
|
+
}
|
|
22210
22062
|
|
|
22211
22063
|
// CORS
|
|
22212
22064
|
if (this._withCredentials) xhr.withCredentials = true;
|
|
22213
22065
|
|
|
22214
22066
|
// body
|
|
22215
|
-
if ('GET' != this.method && 'HEAD' != this.method && 'string' != typeof data && !
|
|
22067
|
+
if ('GET' != this.method && 'HEAD' != this.method && 'string' != typeof data && !this._isHost(data)) {
|
|
22216
22068
|
// serialize stuff
|
|
22217
|
-
var contentType = this.
|
|
22218
|
-
var serialize = this.
|
|
22069
|
+
var contentType = this._header['content-type'];
|
|
22070
|
+
var serialize = this._serializer || request.serialize[contentType ? contentType.split(';')[0] : ''];
|
|
22219
22071
|
if (!serialize && isJSON(contentType)) serialize = request.serialize['application/json'];
|
|
22220
22072
|
if (serialize) data = serialize(data);
|
|
22221
22073
|
}
|
|
@@ -22226,6 +22078,10 @@ Request.prototype.end = function(fn){
|
|
|
22226
22078
|
xhr.setRequestHeader(field, this.header[field]);
|
|
22227
22079
|
}
|
|
22228
22080
|
|
|
22081
|
+
if (this._responseType) {
|
|
22082
|
+
xhr.responseType = this._responseType;
|
|
22083
|
+
}
|
|
22084
|
+
|
|
22229
22085
|
// send stuff
|
|
22230
22086
|
this.emit('request', this);
|
|
22231
22087
|
|
|
@@ -22235,19 +22091,6 @@ Request.prototype.end = function(fn){
|
|
|
22235
22091
|
return this;
|
|
22236
22092
|
};
|
|
22237
22093
|
|
|
22238
|
-
/**
|
|
22239
|
-
* Faux promise support
|
|
22240
|
-
*
|
|
22241
|
-
* @param {Function} fulfill
|
|
22242
|
-
* @param {Function} reject
|
|
22243
|
-
* @return {Request}
|
|
22244
|
-
*/
|
|
22245
|
-
|
|
22246
|
-
Request.prototype.then = function (fulfill, reject) {
|
|
22247
|
-
return this.end(function(err, res) {
|
|
22248
|
-
err ? reject(err) : fulfill(res);
|
|
22249
|
-
});
|
|
22250
|
-
}
|
|
22251
22094
|
|
|
22252
22095
|
/**
|
|
22253
22096
|
* Expose `Request`.
|
|
@@ -22255,35 +22098,6 @@ Request.prototype.then = function (fulfill, reject) {
|
|
|
22255
22098
|
|
|
22256
22099
|
request.Request = Request;
|
|
22257
22100
|
|
|
22258
|
-
/**
|
|
22259
|
-
* Issue a request:
|
|
22260
|
-
*
|
|
22261
|
-
* Examples:
|
|
22262
|
-
*
|
|
22263
|
-
* request('GET', '/users').end(callback)
|
|
22264
|
-
* request('/users').end(callback)
|
|
22265
|
-
* request('/users', callback)
|
|
22266
|
-
*
|
|
22267
|
-
* @param {String} method
|
|
22268
|
-
* @param {String|Function} url or callback
|
|
22269
|
-
* @return {Request}
|
|
22270
|
-
* @api public
|
|
22271
|
-
*/
|
|
22272
|
-
|
|
22273
|
-
function request(method, url) {
|
|
22274
|
-
// callback
|
|
22275
|
-
if ('function' == typeof url) {
|
|
22276
|
-
return new Request('GET', method).end(url);
|
|
22277
|
-
}
|
|
22278
|
-
|
|
22279
|
-
// url first
|
|
22280
|
-
if (1 == arguments.length) {
|
|
22281
|
-
return new Request('GET', method);
|
|
22282
|
-
}
|
|
22283
|
-
|
|
22284
|
-
return new Request(method, url);
|
|
22285
|
-
}
|
|
22286
|
-
|
|
22287
22101
|
/**
|
|
22288
22102
|
* GET `url` with optional callback `fn(res)`.
|
|
22289
22103
|
*
|
|
@@ -22320,6 +22134,24 @@ request.head = function(url, data, fn){
|
|
|
22320
22134
|
return req;
|
|
22321
22135
|
};
|
|
22322
22136
|
|
|
22137
|
+
/**
|
|
22138
|
+
* OPTIONS query to `url` with optional callback `fn(res)`.
|
|
22139
|
+
*
|
|
22140
|
+
* @param {String} url
|
|
22141
|
+
* @param {Mixed|Function} data or fn
|
|
22142
|
+
* @param {Function} fn
|
|
22143
|
+
* @return {Request}
|
|
22144
|
+
* @api public
|
|
22145
|
+
*/
|
|
22146
|
+
|
|
22147
|
+
request.options = function(url, data, fn){
|
|
22148
|
+
var req = request('OPTIONS', url);
|
|
22149
|
+
if ('function' == typeof data) fn = data, data = null;
|
|
22150
|
+
if (data) req.send(data);
|
|
22151
|
+
if (fn) req.end(fn);
|
|
22152
|
+
return req;
|
|
22153
|
+
};
|
|
22154
|
+
|
|
22323
22155
|
/**
|
|
22324
22156
|
* DELETE `url` with optional callback `fn(res)`.
|
|
22325
22157
|
*
|
|
@@ -22392,13 +22224,404 @@ request.put = function(url, data, fn){
|
|
|
22392
22224
|
return req;
|
|
22393
22225
|
};
|
|
22394
22226
|
|
|
22227
|
+
},{"./is-object":50,"./request":52,"./request-base":51,"emitter":40,"reduce":47}],50:[function(require,module,exports){
|
|
22395
22228
|
/**
|
|
22396
|
-
*
|
|
22229
|
+
* Check if `obj` is an object.
|
|
22230
|
+
*
|
|
22231
|
+
* @param {Object} obj
|
|
22232
|
+
* @return {Boolean}
|
|
22233
|
+
* @api private
|
|
22234
|
+
*/
|
|
22235
|
+
|
|
22236
|
+
function isObject(obj) {
|
|
22237
|
+
return null !== obj && 'object' === typeof obj;
|
|
22238
|
+
}
|
|
22239
|
+
|
|
22240
|
+
module.exports = isObject;
|
|
22241
|
+
|
|
22242
|
+
},{}],51:[function(require,module,exports){
|
|
22243
|
+
/**
|
|
22244
|
+
* Module of mixed-in functions shared between node and client code
|
|
22245
|
+
*/
|
|
22246
|
+
var isObject = require('./is-object');
|
|
22247
|
+
|
|
22248
|
+
/**
|
|
22249
|
+
* Clear previous timeout.
|
|
22250
|
+
*
|
|
22251
|
+
* @return {Request} for chaining
|
|
22252
|
+
* @api public
|
|
22397
22253
|
*/
|
|
22398
22254
|
|
|
22255
|
+
exports.clearTimeout = function _clearTimeout(){
|
|
22256
|
+
this._timeout = 0;
|
|
22257
|
+
clearTimeout(this._timer);
|
|
22258
|
+
return this;
|
|
22259
|
+
};
|
|
22260
|
+
|
|
22261
|
+
/**
|
|
22262
|
+
* Override default response body parser
|
|
22263
|
+
*
|
|
22264
|
+
* This function will be called to convert incoming data into request.body
|
|
22265
|
+
*
|
|
22266
|
+
* @param {Function}
|
|
22267
|
+
* @api public
|
|
22268
|
+
*/
|
|
22269
|
+
|
|
22270
|
+
exports.parse = function parse(fn){
|
|
22271
|
+
this._parser = fn;
|
|
22272
|
+
return this;
|
|
22273
|
+
};
|
|
22274
|
+
|
|
22275
|
+
/**
|
|
22276
|
+
* Override default request body serializer
|
|
22277
|
+
*
|
|
22278
|
+
* This function will be called to convert data set via .send or .attach into payload to send
|
|
22279
|
+
*
|
|
22280
|
+
* @param {Function}
|
|
22281
|
+
* @api public
|
|
22282
|
+
*/
|
|
22283
|
+
|
|
22284
|
+
exports.serialize = function serialize(fn){
|
|
22285
|
+
this._serializer = fn;
|
|
22286
|
+
return this;
|
|
22287
|
+
};
|
|
22288
|
+
|
|
22289
|
+
/**
|
|
22290
|
+
* Set timeout to `ms`.
|
|
22291
|
+
*
|
|
22292
|
+
* @param {Number} ms
|
|
22293
|
+
* @return {Request} for chaining
|
|
22294
|
+
* @api public
|
|
22295
|
+
*/
|
|
22296
|
+
|
|
22297
|
+
exports.timeout = function timeout(ms){
|
|
22298
|
+
this._timeout = ms;
|
|
22299
|
+
return this;
|
|
22300
|
+
};
|
|
22301
|
+
|
|
22302
|
+
/**
|
|
22303
|
+
* Promise support
|
|
22304
|
+
*
|
|
22305
|
+
* @param {Function} resolve
|
|
22306
|
+
* @param {Function} reject
|
|
22307
|
+
* @return {Request}
|
|
22308
|
+
*/
|
|
22309
|
+
|
|
22310
|
+
exports.then = function then(resolve, reject) {
|
|
22311
|
+
if (!this._fullfilledPromise) {
|
|
22312
|
+
var self = this;
|
|
22313
|
+
this._fullfilledPromise = new Promise(function(innerResolve, innerReject){
|
|
22314
|
+
self.end(function(err, res){
|
|
22315
|
+
if (err) innerReject(err); else innerResolve(res);
|
|
22316
|
+
});
|
|
22317
|
+
});
|
|
22318
|
+
}
|
|
22319
|
+
return this._fullfilledPromise.then(resolve, reject);
|
|
22320
|
+
}
|
|
22321
|
+
|
|
22322
|
+
/**
|
|
22323
|
+
* Allow for extension
|
|
22324
|
+
*/
|
|
22325
|
+
|
|
22326
|
+
exports.use = function use(fn) {
|
|
22327
|
+
fn(this);
|
|
22328
|
+
return this;
|
|
22329
|
+
}
|
|
22330
|
+
|
|
22331
|
+
|
|
22332
|
+
/**
|
|
22333
|
+
* Get request header `field`.
|
|
22334
|
+
* Case-insensitive.
|
|
22335
|
+
*
|
|
22336
|
+
* @param {String} field
|
|
22337
|
+
* @return {String}
|
|
22338
|
+
* @api public
|
|
22339
|
+
*/
|
|
22340
|
+
|
|
22341
|
+
exports.get = function(field){
|
|
22342
|
+
return this._header[field.toLowerCase()];
|
|
22343
|
+
};
|
|
22344
|
+
|
|
22345
|
+
/**
|
|
22346
|
+
* Get case-insensitive header `field` value.
|
|
22347
|
+
* This is a deprecated internal API. Use `.get(field)` instead.
|
|
22348
|
+
*
|
|
22349
|
+
* (getHeader is no longer used internally by the superagent code base)
|
|
22350
|
+
*
|
|
22351
|
+
* @param {String} field
|
|
22352
|
+
* @return {String}
|
|
22353
|
+
* @api private
|
|
22354
|
+
* @deprecated
|
|
22355
|
+
*/
|
|
22356
|
+
|
|
22357
|
+
exports.getHeader = exports.get;
|
|
22358
|
+
|
|
22359
|
+
/**
|
|
22360
|
+
* Set header `field` to `val`, or multiple fields with one object.
|
|
22361
|
+
* Case-insensitive.
|
|
22362
|
+
*
|
|
22363
|
+
* Examples:
|
|
22364
|
+
*
|
|
22365
|
+
* req.get('/')
|
|
22366
|
+
* .set('Accept', 'application/json')
|
|
22367
|
+
* .set('X-API-Key', 'foobar')
|
|
22368
|
+
* .end(callback);
|
|
22369
|
+
*
|
|
22370
|
+
* req.get('/')
|
|
22371
|
+
* .set({ Accept: 'application/json', 'X-API-Key': 'foobar' })
|
|
22372
|
+
* .end(callback);
|
|
22373
|
+
*
|
|
22374
|
+
* @param {String|Object} field
|
|
22375
|
+
* @param {String} val
|
|
22376
|
+
* @return {Request} for chaining
|
|
22377
|
+
* @api public
|
|
22378
|
+
*/
|
|
22379
|
+
|
|
22380
|
+
exports.set = function(field, val){
|
|
22381
|
+
if (isObject(field)) {
|
|
22382
|
+
for (var key in field) {
|
|
22383
|
+
this.set(key, field[key]);
|
|
22384
|
+
}
|
|
22385
|
+
return this;
|
|
22386
|
+
}
|
|
22387
|
+
this._header[field.toLowerCase()] = val;
|
|
22388
|
+
this.header[field] = val;
|
|
22389
|
+
return this;
|
|
22390
|
+
};
|
|
22391
|
+
|
|
22392
|
+
/**
|
|
22393
|
+
* Remove header `field`.
|
|
22394
|
+
* Case-insensitive.
|
|
22395
|
+
*
|
|
22396
|
+
* Example:
|
|
22397
|
+
*
|
|
22398
|
+
* req.get('/')
|
|
22399
|
+
* .unset('User-Agent')
|
|
22400
|
+
* .end(callback);
|
|
22401
|
+
*
|
|
22402
|
+
* @param {String} field
|
|
22403
|
+
*/
|
|
22404
|
+
exports.unset = function(field){
|
|
22405
|
+
delete this._header[field.toLowerCase()];
|
|
22406
|
+
delete this.header[field];
|
|
22407
|
+
return this;
|
|
22408
|
+
};
|
|
22409
|
+
|
|
22410
|
+
/**
|
|
22411
|
+
* Write the field `name` and `val` for "multipart/form-data"
|
|
22412
|
+
* request bodies.
|
|
22413
|
+
*
|
|
22414
|
+
* ``` js
|
|
22415
|
+
* request.post('/upload')
|
|
22416
|
+
* .field('foo', 'bar')
|
|
22417
|
+
* .end(callback);
|
|
22418
|
+
* ```
|
|
22419
|
+
*
|
|
22420
|
+
* @param {String} name
|
|
22421
|
+
* @param {String|Blob|File|Buffer|fs.ReadStream} val
|
|
22422
|
+
* @return {Request} for chaining
|
|
22423
|
+
* @api public
|
|
22424
|
+
*/
|
|
22425
|
+
exports.field = function(name, val) {
|
|
22426
|
+
this._getFormData().append(name, val);
|
|
22427
|
+
return this;
|
|
22428
|
+
};
|
|
22429
|
+
|
|
22430
|
+
/**
|
|
22431
|
+
* Abort the request, and clear potential timeout.
|
|
22432
|
+
*
|
|
22433
|
+
* @return {Request}
|
|
22434
|
+
* @api public
|
|
22435
|
+
*/
|
|
22436
|
+
exports.abort = function(){
|
|
22437
|
+
if (this._aborted) {
|
|
22438
|
+
return this;
|
|
22439
|
+
}
|
|
22440
|
+
this._aborted = true;
|
|
22441
|
+
this.xhr && this.xhr.abort(); // browser
|
|
22442
|
+
this.req && this.req.abort(); // node
|
|
22443
|
+
this.clearTimeout();
|
|
22444
|
+
this.emit('abort');
|
|
22445
|
+
return this;
|
|
22446
|
+
};
|
|
22447
|
+
|
|
22448
|
+
/**
|
|
22449
|
+
* Enable transmission of cookies with x-domain requests.
|
|
22450
|
+
*
|
|
22451
|
+
* Note that for this to work the origin must not be
|
|
22452
|
+
* using "Access-Control-Allow-Origin" with a wildcard,
|
|
22453
|
+
* and also must set "Access-Control-Allow-Credentials"
|
|
22454
|
+
* to "true".
|
|
22455
|
+
*
|
|
22456
|
+
* @api public
|
|
22457
|
+
*/
|
|
22458
|
+
|
|
22459
|
+
exports.withCredentials = function(){
|
|
22460
|
+
// This is browser-only functionality. Node side is no-op.
|
|
22461
|
+
this._withCredentials = true;
|
|
22462
|
+
return this;
|
|
22463
|
+
};
|
|
22464
|
+
|
|
22465
|
+
/**
|
|
22466
|
+
* Set the max redirects to `n`. Does noting in browser XHR implementation.
|
|
22467
|
+
*
|
|
22468
|
+
* @param {Number} n
|
|
22469
|
+
* @return {Request} for chaining
|
|
22470
|
+
* @api public
|
|
22471
|
+
*/
|
|
22472
|
+
|
|
22473
|
+
exports.redirects = function(n){
|
|
22474
|
+
this._maxRedirects = n;
|
|
22475
|
+
return this;
|
|
22476
|
+
};
|
|
22477
|
+
|
|
22478
|
+
/**
|
|
22479
|
+
* Convert to a plain javascript object (not JSON string) of scalar properties.
|
|
22480
|
+
* Note as this method is designed to return a useful non-this value,
|
|
22481
|
+
* it cannot be chained.
|
|
22482
|
+
*
|
|
22483
|
+
* @return {Object} describing method, url, and data of this request
|
|
22484
|
+
* @api public
|
|
22485
|
+
*/
|
|
22486
|
+
|
|
22487
|
+
exports.toJSON = function(){
|
|
22488
|
+
return {
|
|
22489
|
+
method: this.method,
|
|
22490
|
+
url: this.url,
|
|
22491
|
+
data: this._data
|
|
22492
|
+
};
|
|
22493
|
+
};
|
|
22494
|
+
|
|
22495
|
+
/**
|
|
22496
|
+
* Check if `obj` is a host object,
|
|
22497
|
+
* we don't want to serialize these :)
|
|
22498
|
+
*
|
|
22499
|
+
* TODO: future proof, move to compoent land
|
|
22500
|
+
*
|
|
22501
|
+
* @param {Object} obj
|
|
22502
|
+
* @return {Boolean}
|
|
22503
|
+
* @api private
|
|
22504
|
+
*/
|
|
22505
|
+
|
|
22506
|
+
exports._isHost = function _isHost(obj) {
|
|
22507
|
+
var str = {}.toString.call(obj);
|
|
22508
|
+
|
|
22509
|
+
switch (str) {
|
|
22510
|
+
case '[object File]':
|
|
22511
|
+
case '[object Blob]':
|
|
22512
|
+
case '[object FormData]':
|
|
22513
|
+
return true;
|
|
22514
|
+
default:
|
|
22515
|
+
return false;
|
|
22516
|
+
}
|
|
22517
|
+
}
|
|
22518
|
+
|
|
22519
|
+
/**
|
|
22520
|
+
* Send `data` as the request body, defaulting the `.type()` to "json" when
|
|
22521
|
+
* an object is given.
|
|
22522
|
+
*
|
|
22523
|
+
* Examples:
|
|
22524
|
+
*
|
|
22525
|
+
* // manual json
|
|
22526
|
+
* request.post('/user')
|
|
22527
|
+
* .type('json')
|
|
22528
|
+
* .send('{"name":"tj"}')
|
|
22529
|
+
* .end(callback)
|
|
22530
|
+
*
|
|
22531
|
+
* // auto json
|
|
22532
|
+
* request.post('/user')
|
|
22533
|
+
* .send({ name: 'tj' })
|
|
22534
|
+
* .end(callback)
|
|
22535
|
+
*
|
|
22536
|
+
* // manual x-www-form-urlencoded
|
|
22537
|
+
* request.post('/user')
|
|
22538
|
+
* .type('form')
|
|
22539
|
+
* .send('name=tj')
|
|
22540
|
+
* .end(callback)
|
|
22541
|
+
*
|
|
22542
|
+
* // auto x-www-form-urlencoded
|
|
22543
|
+
* request.post('/user')
|
|
22544
|
+
* .type('form')
|
|
22545
|
+
* .send({ name: 'tj' })
|
|
22546
|
+
* .end(callback)
|
|
22547
|
+
*
|
|
22548
|
+
* // defaults to x-www-form-urlencoded
|
|
22549
|
+
* request.post('/user')
|
|
22550
|
+
* .send('name=tobi')
|
|
22551
|
+
* .send('species=ferret')
|
|
22552
|
+
* .end(callback)
|
|
22553
|
+
*
|
|
22554
|
+
* @param {String|Object} data
|
|
22555
|
+
* @return {Request} for chaining
|
|
22556
|
+
* @api public
|
|
22557
|
+
*/
|
|
22558
|
+
|
|
22559
|
+
exports.send = function(data){
|
|
22560
|
+
var obj = isObject(data);
|
|
22561
|
+
var type = this._header['content-type'];
|
|
22562
|
+
|
|
22563
|
+
// merge
|
|
22564
|
+
if (obj && isObject(this._data)) {
|
|
22565
|
+
for (var key in data) {
|
|
22566
|
+
this._data[key] = data[key];
|
|
22567
|
+
}
|
|
22568
|
+
} else if ('string' == typeof data) {
|
|
22569
|
+
// default to x-www-form-urlencoded
|
|
22570
|
+
if (!type) this.type('form');
|
|
22571
|
+
type = this._header['content-type'];
|
|
22572
|
+
if ('application/x-www-form-urlencoded' == type) {
|
|
22573
|
+
this._data = this._data
|
|
22574
|
+
? this._data + '&' + data
|
|
22575
|
+
: data;
|
|
22576
|
+
} else {
|
|
22577
|
+
this._data = (this._data || '') + data;
|
|
22578
|
+
}
|
|
22579
|
+
} else {
|
|
22580
|
+
this._data = data;
|
|
22581
|
+
}
|
|
22582
|
+
|
|
22583
|
+
if (!obj || this._isHost(data)) return this;
|
|
22584
|
+
|
|
22585
|
+
// default to json
|
|
22586
|
+
if (!type) this.type('json');
|
|
22587
|
+
return this;
|
|
22588
|
+
};
|
|
22589
|
+
|
|
22590
|
+
},{"./is-object":50}],52:[function(require,module,exports){
|
|
22591
|
+
// The node and browser modules expose versions of this with the
|
|
22592
|
+
// appropriate constructor function bound as first argument
|
|
22593
|
+
/**
|
|
22594
|
+
* Issue a request:
|
|
22595
|
+
*
|
|
22596
|
+
* Examples:
|
|
22597
|
+
*
|
|
22598
|
+
* request('GET', '/users').end(callback)
|
|
22599
|
+
* request('/users').end(callback)
|
|
22600
|
+
* request('/users', callback)
|
|
22601
|
+
*
|
|
22602
|
+
* @param {String} method
|
|
22603
|
+
* @param {String|Function} url or callback
|
|
22604
|
+
* @return {Request}
|
|
22605
|
+
* @api public
|
|
22606
|
+
*/
|
|
22607
|
+
|
|
22608
|
+
function request(RequestConstructor, method, url) {
|
|
22609
|
+
// callback
|
|
22610
|
+
if ('function' == typeof url) {
|
|
22611
|
+
return new RequestConstructor('GET', method).end(url);
|
|
22612
|
+
}
|
|
22613
|
+
|
|
22614
|
+
// url first
|
|
22615
|
+
if (2 == arguments.length) {
|
|
22616
|
+
return new RequestConstructor('GET', method);
|
|
22617
|
+
}
|
|
22618
|
+
|
|
22619
|
+
return new RequestConstructor(method, url);
|
|
22620
|
+
}
|
|
22621
|
+
|
|
22399
22622
|
module.exports = request;
|
|
22400
22623
|
|
|
22401
|
-
},{
|
|
22624
|
+
},{}],53:[function(require,module,exports){
|
|
22402
22625
|
/*!
|
|
22403
22626
|
* validate.js 0.9.0
|
|
22404
22627
|
*
|