async-request
Advanced tools
Comparing version 1.0.1 to 1.1.0
@@ -9,36 +9,49 @@ "use strict"; | ||
var Arequest = {}, | ||
arequest = undefined, | ||
var Arequest = undefined, | ||
request = require("request"), | ||
_ = require("lodash"); | ||
arequest = function callee$0$0(url, options) { | ||
return _regeneratorRuntime.async(function callee$0$0$(context$1$0) { | ||
while (1) switch (context$1$0.prev = context$1$0.next) { | ||
case 0: | ||
return context$1$0.abrupt("return", new _core.Promise(function (resolve) { | ||
Arequest.validateOptions(options); | ||
Arequest = function (defaultOptions) { | ||
var arequest = undefined; | ||
options = Arequest.mapOptions(options); | ||
arequest = function callee$1$0(url, options) { | ||
return _regeneratorRuntime.async(function callee$1$0$(context$2$0) { | ||
while (1) switch (context$2$0.prev = context$2$0.next) { | ||
case 0: | ||
return context$2$0.abrupt("return", new _core.Promise(function (resolve) { | ||
Arequest.validateOptions(options); | ||
options = _.assign({ url: url }, options); | ||
options = Arequest.mapOptions(options); | ||
request(options, function (error, response) { | ||
if (error) { | ||
throw new Error(error); | ||
} | ||
options = _.assign({ url: url }, options); | ||
resolve({ | ||
statusCode: response.statusCode, | ||
headers: response.headers, | ||
body: response.body | ||
request(options, function (error, response) { | ||
if (error) { | ||
throw new Error(error); | ||
} | ||
resolve({ | ||
statusCode: response.statusCode, | ||
headers: response.headers, | ||
body: response.body | ||
}); | ||
}); | ||
}); | ||
})); | ||
})); | ||
case 1: | ||
case "end": | ||
return context$1$0.stop(); | ||
case 1: | ||
case "end": | ||
return context$2$0.stop(); | ||
} | ||
}, null, _this); | ||
}; | ||
arequest.defaults = function (options) { | ||
if (!options) { | ||
return defaultOptions; | ||
} | ||
}, null, _this); | ||
return Arequest(options); | ||
}; | ||
return arequest; | ||
}; | ||
@@ -81,3 +94,3 @@ | ||
module.exports = arequest; | ||
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJzb3VyY2VzIjpbIm1haW4uanMiXSwibmFtZXMiOltdLCJtYXBwaW5ncyI6IkFBQUEsW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iJtYWluLmpzIiwic291cmNlc0NvbnRlbnQiOlsiJ3VzZSBzdHJpY3QnO1xuXG5sZXQgQXJlcXVlc3QgPSB7fSxcbiAgICBhcmVxdWVzdCxcbiAgICByZXF1ZXN0ID0gcmVxdWlyZSgncmVxdWVzdCcpLFxuICAgIF8gPSByZXF1aXJlKCdsb2Rhc2gnKTtcblxuYXJlcXVlc3QgPSBhc3luYyAodXJsLCBvcHRpb25zKSA9PiB7XG4gICAgcmV0dXJuIG5ldyBQcm9taXNlKChyZXNvbHZlKSA9PiB7XG4gICAgICAgIEFyZXF1ZXN0LnZhbGlkYXRlT3B0aW9ucyhvcHRpb25zKTtcblxuICAgICAgICBvcHRpb25zID0gQXJlcXVlc3QubWFwT3B0aW9ucyhvcHRpb25zKTtcblxuICAgICAgICBvcHRpb25zID0gXy5hc3NpZ24oe3VybDogdXJsfSwgb3B0aW9ucyk7XG5cbiAgICAgICAgcmVxdWVzdChvcHRpb25zLCAoZXJyb3IsIHJlc3BvbnNlKSA9PiB7XG4gICAgICAgICAgICBpZiAoZXJyb3IpIHtcbiAgICAgICAgICAgICAgICB0aHJvdyBuZXcgRXJyb3IoZXJyb3IpO1xuICAgICAgICAgICAgfVxuXG4gICAgICAgICAgICByZXNvbHZlKHtcbiAgICAgICAgICAgICAgICBzdGF0dXNDb2RlOiByZXNwb25zZS5zdGF0dXNDb2RlLFxuICAgICAgICAgICAgICAgIGhlYWRlcnM6IHJlc3BvbnNlLmhlYWRlcnMsXG4gICAgICAgICAgICAgICAgYm9keTogcmVzcG9uc2UuYm9keVxuICAgICAgICAgICAgfSk7XG4gICAgICAgIH0pO1xuICAgIH0pO1xufTtcblxuQXJlcXVlc3QudmFsaWRhdGVPcHRpb25zID0gKG9wdGlvbnMpID0+IHtcbiAgICBsZXQgdW5rbm93bk9wdGlvbjtcblxuICAgIGlmICghb3B0aW9ucykge1xuICAgICAgICByZXR1cm47XG4gICAgfVxuXG4gICAgdW5rbm93bk9wdGlvbiA9IF8uZmlyc3QoXy5kaWZmZXJlbmNlKF8ua2V5cyhvcHRpb25zKSwgWydtZXRob2QnLCAnZGF0YScsICdoZWFkZXJzJywgJ3Byb3h5J10pKTtcblxuICAgIGlmICh1bmtub3duT3B0aW9uKSB7XG4gICAgICAgIHRocm93IG5ldyBFcnJvcignVW5rbm93biBvcHRpb24gKFwiJyArIHVua25vd25PcHRpb24gKyAnXCIpLicpO1xuICAgIH1cblxuICAgIGlmIChvcHRpb25zLm1ldGhvZCAmJiBfLmluZGV4T2YoWydHRVQnLCAnUE9TVCcsICdQVVQnLCAnSEVBRCcsICdERUxFVEUnXSwgb3B0aW9ucy5tZXRob2QpID09PSAtMSkge1xuICAgICAgICB0aHJvdyBuZXcgRXJyb3IoJ1Vua25vd24gb3B0aW9uLm1ldGhvZCB2YWx1ZSAoXCInICsgb3B0aW9ucy5tZXRob2QgKyAnXCIpLicpO1xuICAgIH1cbn07XG5cbi8qKlxuICogTWFwIG9wdGlvbnMgdG8gbWVldCB0aGUgcmVxdWVzdCBpbnRlcmZhY2UuXG4gKi9cbkFyZXF1ZXN0Lm1hcE9wdGlvbnMgPSAob3B0aW9ucykgPT4ge1xuICAgIGlmICghb3B0aW9ucykge1xuICAgICAgICByZXR1cm4gb3B0aW9ucztcbiAgICB9XG5cbiAgICBpZiAob3B0aW9ucy5kYXRhKSB7XG4gICAgICAgIG9wdGlvbnMuZm9ybSA9IG9wdGlvbnMuZGF0YTtcblxuICAgICAgICBkZWxldGUgb3B0aW9ucy5kYXRhO1xuICAgIH1cblxuICAgIHJldHVybiBvcHRpb25zO1xufTtcblxubW9kdWxlLmV4cG9ydHMgPSBhcmVxdWVzdDtcbiJdLCJzb3VyY2VSb290IjoiL3NvdXJjZS8ifQ== | ||
module.exports = Arequest({}); | ||
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJzb3VyY2VzIjpbIm1haW4uanMiXSwibmFtZXMiOltdLCJtYXBwaW5ncyI6IkFBQUEsWUFBWSxDQUFDOz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KHtcbiAgICAgICAgICAgICAgICAgICAgc3RhdHVzQ29kZTogcmVzcG9uc2Uuc3RhdHVzQ29kZSxcbiAgICAgICAgICAgICAgICAgICAgaGVhZGVyczogcmVzcG9uc2UuaGVhZGVycyxcbiAgICAgICAgICAgICAgICAgICAgYm9keTogcmVzcG9uc2UuYm9keVxuICAgICAgICAgICAgICAgIH0pO1xuICAgICAgICAgICAgfSk7XG4gICAgICAgIH0pO1xuICAgIH07XG5cbiAgICBhcmVxdWVzdC5kZWZhdWx0cyA9IChvcHRpb25zKSA9PiB7XG4gICAgICAgIGlmICghb3B0aW9ucykge1xuICAgICAgICAgICAgcmV0dXJuIGRlZmF1bHRPcHRpb25zO1xuICAgICAgICB9XG5cbiAgICAgICAgcmV0dXJuIEFyZXF1ZXN0KG9wdGlvbnMpO1xuICAgIH07XG5cbiAgICByZXR1cm4gYXJlcXVlc3Q7XG59O1xuXG5BcmVxdWVzdC52YWxpZGF0ZU9wdGlvbnMgPSAob3B0aW9ucykgPT4ge1xuICAgIGxldCB1bmtub3duT3B0aW9uO1xuXG4gICAgaWYgKCFvcHRpb25zKSB7XG4gICAgICAgIHJldHVybjtcbiAgICB9XG5cbiAgICB1bmtub3duT3B0aW9uID0gXy5maXJzdChfLmRpZmZlcmVuY2UoXy5rZXlzKG9wdGlvbnMpLCBbJ21ldGhvZCcsICdkYXRhJywgJ2hlYWRlcnMnLCAncHJveHknXSkpO1xuXG4gICAgaWYgKHVua25vd25PcHRpb24pIHtcbiAgICAgICAgdGhyb3cgbmV3IEVycm9yKCdVbmtub3duIG9wdGlvbiAoXCInICsgdW5rbm93bk9wdGlvbiArICdcIikuJyk7XG4gICAgfVxuXG4gICAgaWYgKG9wdGlvbnMubWV0aG9kICYmIF8uaW5kZXhPZihbJ0dFVCcsICdQT1NUJywgJ1BVVCcsICdIRUFEJywgJ0RFTEVURSddLCBvcHRpb25zLm1ldGhvZCkgPT09IC0xKSB7XG4gICAgICAgIHRocm93IG5ldyBFcnJvcignVW5rbm93biBvcHRpb24ubWV0aG9kIHZhbHVlIChcIicgKyBvcHRpb25zLm1ldGhvZCArICdcIikuJyk7XG4gICAgfVxufTtcblxuLyoqXG4gKiBNYXAgb3B0aW9ucyB0byBtZWV0IHRoZSByZXF1ZXN0IGludGVyZmFjZS5cbiAqL1xuQXJlcXVlc3QubWFwT3B0aW9ucyA9IChvcHRpb25zKSA9PiB7XG4gICAgaWYgKCFvcHRpb25zKSB7XG4gICAgICAgIHJldHVybiBvcHRpb25zO1xuICAgIH1cblxuICAgIGlmIChvcHRpb25zLmRhdGEpIHtcbiAgICAgICAgb3B0aW9ucy5mb3JtID0gb3B0aW9ucy5kYXRhO1xuXG4gICAgICAgIGRlbGV0ZSBvcHRpb25zLmRhdGE7XG4gICAgfVxuXG4gICAgcmV0dXJuIG9wdGlvbnM7XG59O1xuXG5tb2R1bGUuZXhwb3J0cyA9IEFyZXF1ZXN0KHt9KTtcbiJdLCJzb3VyY2VSb290IjoiL3NvdXJjZS8ifQ== |
{ | ||
"name": "async-request", | ||
"description": "async-request is a wrapper for request that uses ES7 async functions.", | ||
"version": "1.0.1", | ||
"version": "1.1.0", | ||
"main": "src/main.js", | ||
@@ -13,3 +13,3 @@ "author": { | ||
"type": "git", | ||
"url": "https://github.com/gajus/async-request.js" | ||
"url": "https://github.com/gajus/async-request" | ||
}, | ||
@@ -16,0 +16,0 @@ "license": "BSD-3-Clause", |
@@ -37,2 +37,12 @@ # async-request | ||
} | ||
// Returns a wrapper for the request using predefined custom options. | ||
request = request.defaults({headers: {foo: 'bar'}}); | ||
// Returns the current default options. | ||
request.defaults(); | ||
// {foo: 'bar'} | ||
// Makes a HTTP GET request with {foo: 'bar'} headers. | ||
await request('http://gajus.com'); | ||
``` | ||
@@ -39,0 +49,0 @@ |
'use strict'; | ||
let Arequest = {}, | ||
arequest, | ||
let Arequest, | ||
request = require('request'), | ||
_ = require('lodash'); | ||
arequest = async (url, options) => { | ||
return new Promise((resolve) => { | ||
Arequest.validateOptions(options); | ||
Arequest = (defaultOptions) => { | ||
let arequest; | ||
options = Arequest.mapOptions(options); | ||
arequest = async (url, options) => { | ||
return new Promise((resolve) => { | ||
Arequest.validateOptions(options); | ||
options = _.assign({url: url}, options); | ||
options = Arequest.mapOptions(options); | ||
request(options, (error, response) => { | ||
if (error) { | ||
throw new Error(error); | ||
} | ||
options = _.assign({url: url}, options); | ||
resolve({ | ||
statusCode: response.statusCode, | ||
headers: response.headers, | ||
body: response.body | ||
request(options, (error, response) => { | ||
if (error) { | ||
throw new Error(error); | ||
} | ||
resolve({ | ||
statusCode: response.statusCode, | ||
headers: response.headers, | ||
body: response.body | ||
}); | ||
}); | ||
}); | ||
}); | ||
}; | ||
arequest.defaults = (options) => { | ||
if (!options) { | ||
return defaultOptions; | ||
} | ||
return Arequest(options); | ||
}; | ||
return arequest; | ||
}; | ||
@@ -65,2 +78,2 @@ | ||
module.exports = arequest; | ||
module.exports = Arequest({}); |
@@ -137,2 +137,51 @@ 'use strict'; | ||
}); | ||
describe('request.defauls()', () => { | ||
it('returns the current default options', () => { | ||
expect(request.defaults()).to.deep.equal({}); | ||
request = request.defaults({headers: {foo: 'bar'}}); | ||
expect(request.defaults()).to.deep.equal({headers: {foo: 'bar'}}); | ||
}); | ||
}); | ||
describe('request.defauls({})', () => { | ||
it('returns a wrapper around the normal request API with predefined default options', async () => { | ||
let nrequest; | ||
request = request.defaults({headers: {foo: 'bar'}}); | ||
nrequest = nock('http://gajus.com') | ||
.matchHeader('foo', 'bar') | ||
.get('/') | ||
.reply(200); | ||
await request('http://gajus.com/', {headers: {foo: 'bar'}}); | ||
expect(nrequest.isDone()).to.equal(true); | ||
}); | ||
it('does not affect the original instance', async () => { | ||
let nrequest; | ||
request.defaults({method: 'POST'}); | ||
nrequest = nock('http://gajus.com') | ||
.get('/') | ||
.reply(200, ''); | ||
await request('http://gajus.com/'); | ||
expect(nrequest.isDone()).to.equal(true); | ||
}); | ||
it('overwrites existing defaults', () => { | ||
request = request.defaults({headers: {foo: 'bar'}}); | ||
expect(request.defaults()).to.deep.equal({headers: {foo: 'bar'}}); | ||
request = request.defaults({method: 'POST'}); | ||
expect(request.defaults()).to.deep.equal({method: 'POST'}); | ||
}); | ||
}); | ||
}); |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
22291
305
66
0