@nodesecure/scanner
Advanced tools
Comparing version 5.2.1 to 5.3.0
{ | ||
"name": "@nodesecure/scanner", | ||
"version": "5.2.1", | ||
"version": "5.3.0", | ||
"description": "A package API to run a static analysis of your module's dependencies.", | ||
@@ -5,0 +5,0 @@ "exports": "./index.js", |
@@ -6,3 +6,3 @@ // Import Node.js Dependencies | ||
import semver from "semver"; | ||
import { packument, packumentVersion } from "@nodesecure/npm-registry-sdk"; | ||
import { packument, packumentVersion, user as npmUserProfile } from "@nodesecure/npm-registry-sdk"; | ||
@@ -106,2 +106,3 @@ // Import Internal Dependencies | ||
await addNpmAvatar(metadata); | ||
Object.assign(ref.versions[version], { links: getLinks(pkg.versions[version]) }); | ||
@@ -139,1 +140,32 @@ Object.assign(ref.metadata, metadata); | ||
} | ||
async function addNpmAvatar(metadata) { | ||
const contributors = [metadata.author, ...metadata.maintainers, ...metadata.publishers]; | ||
const emailToAvatar = {}; | ||
const promises = contributors.map((contributor) => { | ||
if (contributor.email && emailToAvatar[contributor.email]) { | ||
contributor.npmAvatar = emailToAvatar[contributor.email]; | ||
return Promise.resolve(); | ||
} | ||
return npmUserProfile(contributor.name, { perPage: 1 }).then((profile) => { | ||
contributor.npmAvatar = profile.avatars.small; | ||
if (contributor.email && contributor.npmAvatar) { | ||
emailToAvatar[contributor.email] = contributor.npmAvatar; | ||
} | ||
}).catch(() => { | ||
contributor.npmAvatar = null; | ||
}); | ||
}); | ||
await Promise.all(promises); | ||
// back fill npmAvatar if any name property was not npm username in first pass | ||
for (const contributor of contributors) { | ||
if (!contributor.npmAvatar && contributor.email && emailToAvatar[contributor.email]) { | ||
contributor.npmAvatar = emailToAvatar[contributor.email]; | ||
} | ||
} | ||
} |
@@ -16,2 +16,3 @@ // Import NodeSecure Dependencies | ||
url?: string; | ||
npmAvatar?: string; | ||
} | ||
@@ -22,2 +23,3 @@ | ||
email: string; | ||
npmAvatar?: string; | ||
} | ||
@@ -43,2 +45,7 @@ | ||
at: string; | ||
/** | ||
* Path to publisher's avatar on "https://www.npmjs.com" | ||
* @example /npm-avatar/eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.e30.LwimMJA3puF3ioGeS-tfczR3370GXBZMIL-bdpu4hOU | ||
*/ | ||
npmAvatar?: string; | ||
} | ||
@@ -45,0 +52,0 @@ |
72979
1734