searchitunes
Advanced tools
Comparing version 2.1.1 to 2.2.0
{ | ||
"author": { | ||
"name": "Franklin van de Meent", | ||
"email": "fr@nkl.in", | ||
"url": "https://frankl.in" | ||
"name": "Franklin van de Meent", | ||
"email": "fr@nkl.in", | ||
"url": "https://frankl.in" | ||
}, | ||
"name": "searchitunes", | ||
"description": "Search the Apple iTunes Store and App Store with this lightweight module", | ||
"version": "2.1.1", | ||
"name": "searchitunes", | ||
"description": "Search the Apple iTunes Store and App Store with this lightweight module", | ||
"version": "2.2.0", | ||
"repository": { | ||
"type": "git", | ||
"url": "git://github.com/fvdm/nodejs-searchitunes.git" | ||
"type": "git", | ||
"url": "git://github.com/fvdm/nodejs-searchitunes.git" | ||
}, | ||
"bugs": { | ||
"url": "https://github.com/fvdm/nodejs-searchitunes/issues" | ||
"url": "https://github.com/fvdm/nodejs-searchitunes/issues" | ||
}, | ||
"main": "searchitunes.js", | ||
"main": "searchitunes.js", | ||
"dependencies": { | ||
"httpreq": "0.4.x" | ||
"httpreq": "^0.4.16" | ||
}, | ||
"devDependencies": {}, | ||
"optionalDependencies": {}, | ||
"devDependencies": { | ||
"dotest": "^1.7.0", | ||
"eslint": "^2.7.0" | ||
}, | ||
"engines": { | ||
"node": ">=0.8.0" | ||
"node": ">=0.12.0" | ||
}, | ||
"keywords": ["itunes", "apps", "music", "appstore", "apple", "api"], | ||
"license": "Unlicense", | ||
"keywords": [ | ||
"itunes", | ||
"apps", | ||
"music", | ||
"appstore", | ||
"apple", | ||
"api" | ||
], | ||
"license": "Unlicense", | ||
"scripts": { | ||
"test": "node test.js" | ||
"test": "st=0; eslint . || st=1; node test.js || st=1; exit $st" | ||
} | ||
} |
@@ -14,5 +14,11 @@ /* | ||
module.exports = function (params, callback) { | ||
module.exports = function (params, timeout, callback) { | ||
if (typeof timeout === 'function') { | ||
callback = timeout; | ||
timeout = 5000; | ||
} | ||
if (!params || !(params instanceof Object)) { | ||
return callback (new Error ('invalid params')); | ||
callback (new Error ('invalid params')); | ||
return; | ||
} | ||
@@ -23,5 +29,6 @@ | ||
http.get ( | ||
'http://itunes.apple.com/WebObjects/MZStoreServices.woa/ws/wsSearch', | ||
'https://itunes.apple.com/WebObjects/MZStoreServices.woa/ws/wsSearch', | ||
{ | ||
parameters: params, | ||
timeout: timeout, | ||
headers: { | ||
@@ -33,7 +40,11 @@ 'Accept': 'application/json', | ||
function (err, res) { | ||
var error = null; | ||
var data; | ||
if (err) { | ||
var error = new Error ('http error'); | ||
error = new Error ('http error'); | ||
error.code = res.statusCode; | ||
error.body = res.body; | ||
return callback (error); | ||
callback (error); | ||
return; | ||
} | ||
@@ -43,9 +54,11 @@ | ||
data = JSON.parse (res.body); | ||
if (!(data.results instanceof Array) || data.results.length === 0) { | ||
return callback (new Error ('no results')); | ||
if (!(data.results instanceof Array) || !data.results.length) { | ||
callback (new Error ('no results')); | ||
return; | ||
} | ||
return callback (null, data); | ||
} | ||
catch (e) { | ||
var error = new Error ('invalid response'); | ||
callback (null, data); | ||
} catch (e) { | ||
error = new Error ('invalid response'); | ||
error.error = e; | ||
@@ -52,0 +65,0 @@ callback (error); |
151
test.js
@@ -9,76 +9,41 @@ /* | ||
var util = require ('util'); | ||
var dotest = require ('dotest'); | ||
var app = require ('./'); | ||
// Setup | ||
var app = require ('./'); | ||
var timeout = process.env.testTimeout || 5000; | ||
// handle exits | ||
var errors = 0; | ||
process.on ('exit', function () { | ||
if (errors === 0) { | ||
console.log ('\n\033[1mDONE, no errors.\033[0m\n'); | ||
process.exit (0); | ||
} else { | ||
console.log ('\n\033[1mFAIL, '+ errors +' error'+ (errors > 1 ? 's' : '') +' occurred!\033[0m\n'); | ||
process.exit (1); | ||
} | ||
// Tests | ||
dotest.add ('Module', function (test) { | ||
test () | ||
.isFunction ('fail', 'exports', app) | ||
.done (); | ||
}); | ||
// prevent errors from killing the process | ||
process.on ('uncaughtException', function (err) { | ||
console.log (); | ||
console.error (err.stack); | ||
console.trace (); | ||
console.log (); | ||
errors++; | ||
dotest.add ('Error: invalid params', function (test) { | ||
app (null, function (err) { | ||
test () | ||
.isError ('fail', 'err', err) | ||
.isExactly ('fail', 'err.message', err && err.message, 'invalid params') | ||
.done (); | ||
}); | ||
}); | ||
// Queue to prevent flooding | ||
var queue = []; | ||
var next = 0; | ||
function doNext () { | ||
next++; | ||
if (queue[next]) { | ||
queue[next] (); | ||
} | ||
} | ||
dotest.add ('Error: no results', function (test) { | ||
var params = { | ||
entity: 'software', | ||
country: 'NL', | ||
term: null, | ||
limit: 1, | ||
price: 0 | ||
}; | ||
// doTest( passErr, 'methods', [ | ||
// ['feeds', typeof feeds === 'object'] | ||
// ]) | ||
function doTest (err, label, tests) { | ||
if (err instanceof Error) { | ||
console.error (label +': \033[1m\033[31mERROR\033[0m\n'); | ||
console.error (util.inspect (err, {depth: 10, colors: true})); | ||
console.log (); | ||
console.error (err.stack); | ||
console.log (); | ||
errors++; | ||
} else { | ||
var testErrors = []; | ||
tests.forEach (function (test) { | ||
if (test[1] !== true) { | ||
testErrors.push (test[0]); | ||
errors++; | ||
} | ||
}); | ||
if (testErrors.length === 0) { | ||
console.log (label +': \033[1m\033[32mok\033[0m'); | ||
} else { | ||
console.error (label +': \033[1m\033[31mfailed\033[0m ('+ testErrors.join (', ') +')'); | ||
} | ||
} | ||
doNext (); | ||
} | ||
queue.push (function () { | ||
app (null, function (err) { | ||
doTest (null, 'Error: invalid params', [ | ||
['error', err && err.message === 'invalid params'] | ||
]); | ||
app (params, timeout, function (err) { | ||
test () | ||
.isError ('fail', 'err', err) | ||
.isExactly ('fail', 'err.message', err && err.message, 'no results') | ||
.done (); | ||
}); | ||
@@ -88,40 +53,23 @@ }); | ||
queue.push (function () { | ||
app ( | ||
{ | ||
entity: 'software', | ||
country: 'NL', | ||
term: null, | ||
limit: 1, | ||
price: 0 | ||
}, | ||
function (err) { | ||
doTest (null, 'Error: no results', [ | ||
['error', err && err.message === 'no results'] | ||
]); | ||
} | ||
); | ||
}); | ||
dotest.add ('Search', function (test) { | ||
var params = { | ||
entity: 'software', | ||
country: 'NL', | ||
term: 'github', | ||
limit: 1, | ||
price: 0 | ||
}; | ||
app (params, timeout, function (err, data) { | ||
var item = data && data.results && data.results [0]; | ||
queue.push (function () { | ||
app ( | ||
{ | ||
entity: 'software', | ||
country: 'NL', | ||
term: 'github', | ||
limit: 1, | ||
price: 0 | ||
}, | ||
function (err, data) { | ||
doTest (err, 'search', [ | ||
['data type', data && data instanceof Object], | ||
['resultCount', data && data.resultCount && data.resultCount === 1], | ||
['results type', data && data.results && data.results instanceof Array], | ||
['results length', data && data.results && data.results instanceof Array && data.results.length === 1], | ||
['item type', data && data.results && data.results[0] && data.results[0] instanceof Object], | ||
['item kind', data && data.results && data.results[0] && data.results[0].kind === 'software'] | ||
]); | ||
} | ||
); | ||
test (err) | ||
.isObject ('fail', 'data', data) | ||
.isExactly ('fail', 'data.resultCount', data && data.resultCount, 1) | ||
.isArray ('fail', 'data.results', data && data.results) | ||
.isNotEmpty ('fail', 'data.results', data && data.results) | ||
.isObject ('fail', 'data.results[0]', item) | ||
.isExactly ('fail', 'data.results[0].kind', item && item.kind, 'software') | ||
.done (); | ||
}); | ||
}); | ||
@@ -131,3 +79,2 @@ | ||
// Start the tests | ||
console.log ('Running tests...\n'); | ||
queue[0] (); | ||
dotest.run (); |
Sorry, the diff of this file is not supported yet
Environment variable access
Supply chain riskPackage accesses environment variables, which may be a sign of credential stuffing or data theft.
Found 1 instance in 1 package
16092
7
2
118
1
Updatedhttpreq@^0.4.16