Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

searchitunes

Package Overview
Dependencies
Maintainers
1
Versions
17
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

searchitunes - npm Package Compare versions

Comparing version 2.5.5 to 2.5.6

10

package.json

@@ -9,3 +9,3 @@ {

"description": "Search the Apple iTunes Store and App Store with this lightweight module",
"version": "2.5.5",
"version": "2.5.6",
"repository": {

@@ -22,10 +22,8 @@ "type": "git",

],
"dependencies": {
"httpreq": "^0.5.2"
},
"dependencies": {},
"devDependencies": {
"dotest": "^2.12.2"
"dotest": "^2"
},
"engines": {
"node": ">=14"
"node": ">=18"
},

@@ -32,0 +30,0 @@ "keywords": [

97

searchitunes.js

@@ -9,56 +9,4 @@ /*

const { doRequest } = require( 'httpreq' );
/**
* Check if one of the keys is a property
*
* @param {object} obj Object to process
*
* @return {Promise<boolean>} `true` = yes
*/
async function keysInObject ( obj ) {
const objKeys = Object.keys( obj );
const keys = [
'amgAlbumId',
'amgArtistId',
'amgVideoId',
'id',
'isbn',
'upc',
];
return objKeys.some( key => keys.includes( key ) );
}
/**
* Process HTTP response
*
* @param {object} res Response
* @param {bool} [first=false] Only first result
*
* @return {Promise<object|array>}
*/
async function httpResponse ( {
res,
first = false,
} ) {
const data = JSON.parse( res.body );
if ( ! data.results || ! data.results.length ) {
throw new Error( 'no results' );
}
if ( first ) {
return data.results[0];
}
return data;
}
/**
* Send HTTP request

@@ -79,7 +27,7 @@ *

let first;
let params = arguments[0];
let url = 'https://itunes.apple.com/search?';
let options = {
method: 'POST',
url: 'https://itunes.apple.com/search',
parameters: arguments[0],
timeout,
signal: AbortSignal.timeout( parseInt( timeout, 10 ) ),
headers: {

@@ -91,13 +39,25 @@ 'Accept': 'application/json',

delete params.timeout;
delete params.userAgent;
// Convert trackId from a search response
if ( trackId ) {
options.parameters.id = trackId;
delete options.parameters.trackId;
params.id = trackId;
delete params.trackId;
}
// Search or lookup
const hasKeys = await keysInObject( options.parameters );
const idKeys = [
'amgAlbumId',
'amgArtistId',
'amgVideoId',
'id',
'isbn',
'upc',
];
const hasKeys = Object.keys( params ).some( key => idKeys.includes( key ) );
if ( hasKeys ) {
options.url = 'https://itunes.apple.com/lookup';
url = 'https://itunes.apple.com/lookup';
first = true;

@@ -107,8 +67,17 @@ }

// Process request
delete options.parameters.timeout;
delete options.parameters.userAgent;
params = new URLSearchParams( params );
url += '?' + params.toString();
const res = await doRequest( options );
const res = await fetch( url, options );
const data = await res.json();
return httpResponse( { res, first } );
if ( ! data.results || ! data.results.length ) {
throw new Error( 'no results' );
}
if ( first ) {
return data.results[0];
}
return data;
};
SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc