@nodesecure/scanner
Version:
A package API to run a static analysis of your module's dependencies.
64 lines • 2.1 kB
JavaScript
// Import Third-party Dependencies
// import * as npmRegistrySDK from "@nodesecure/npm-registry-sdk";
export async function fetchNpmAvatars(metadata) {
const contributors = [
...metadata.maintainers,
...metadata.publishers,
...(metadata.author ? [metadata.author] : [])
];
const avatarCache = new Map();
/**
* @deprecated
* NPM website user API is no longer exploitable for avatar
* We need to find an alternative way to fetch avatars
*/
// await Promise.all(
// contributors.map((contributor) => enrichContributorWithAvatar(contributor, avatarCache))
// );
// Backfill missing avatars: some contributors may have failed username lookup
// but their email might match a cached avatar from a successful contributor
contributors
.filter((contributor) => !contributor.npmAvatar && contributor.email)
.forEach((contributor) => {
const cachedAvatar = avatarCache.get(contributor.email);
if (cachedAvatar) {
contributor.npmAvatar = cachedAvatar;
}
});
}
// async function enrichContributorWithAvatar(
// contributor: Contributor,
// avatarCache: Map<string, string>
// ): Promise<void> {
// if (trySetAvatarFromCache(contributor, avatarCache)) {
// return;
// }
// try {
// const profile = await npmRegistrySDK.user(
// contributor.name,
// { perPage: 1 }
// );
// contributor.npmAvatar = profile.avatars.small;
// if (contributor.email && contributor.npmAvatar) {
// avatarCache.set(contributor.email, contributor.npmAvatar);
// }
// }
// catch {
// contributor.npmAvatar = undefined;
// }
// }
// function trySetAvatarFromCache(
// contributor: Contributor,
// avatarCache: Map<string, string>
// ): boolean {
// if (!contributor.email) {
// return false;
// }
// const cachedAvatar = avatarCache.get(contributor.email);
// if (cachedAvatar) {
// contributor.npmAvatar = cachedAvatar;
// return true;
// }
// return false;
// }
//# sourceMappingURL=fetchNpmAvatars.js.map