@nodesecure/scanner 5.2.1 → 5.3.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@nodesecure/scanner",
3
- "version": "5.2.1",
3
+ "version": "5.3.0",
4
4
  "description": "A package API to run a static analysis of your module's dependencies.",
5
5
  "exports": "./index.js",
6
6
  "engines": {
@@ -3,7 +3,7 @@ import crypto from "node:crypto";
3
3
 
4
4
  // Import Third-party Dependencies
5
5
  import semver from "semver";
6
- import { packument, packumentVersion } from "@nodesecure/npm-registry-sdk";
6
+ import { packument, packumentVersion, user as npmUserProfile } from "@nodesecure/npm-registry-sdk";
7
7
 
8
8
  // Import Internal Dependencies
9
9
  import { parseAuthor, getLinks } from "./utils/index.js";
@@ -102,6 +102,7 @@ export async function packageMetadata(name, version, options) {
102
102
  }
103
103
  }
104
104
 
105
+ await addNpmAvatar(metadata);
105
106
  Object.assign(ref.versions[version], { links: getLinks(pkg.versions[version]) });
106
107
  Object.assign(ref.metadata, metadata);
107
108
  }
@@ -134,3 +135,34 @@ function getPackumentVersionIntegrity(packumentVersion) {
134
135
  .update(JSON.stringify(integrityObj))
135
136
  .digest("hex");
136
137
  }
138
+
139
+ async function addNpmAvatar(metadata) {
140
+ const contributors = [metadata.author, ...metadata.maintainers, ...metadata.publishers];
141
+ const emailToAvatar = {};
142
+
143
+ const promises = contributors.map((contributor) => {
144
+ if (contributor.email && emailToAvatar[contributor.email]) {
145
+ contributor.npmAvatar = emailToAvatar[contributor.email];
146
+
147
+ return Promise.resolve();
148
+ }
149
+
150
+ return npmUserProfile(contributor.name, { perPage: 1 }).then((profile) => {
151
+ contributor.npmAvatar = profile.avatars.small;
152
+ if (contributor.email && contributor.npmAvatar) {
153
+ emailToAvatar[contributor.email] = contributor.npmAvatar;
154
+ }
155
+ }).catch(() => {
156
+ contributor.npmAvatar = null;
157
+ });
158
+ });
159
+
160
+ await Promise.all(promises);
161
+
162
+ // back fill npmAvatar if any name property was not npm username in first pass
163
+ for (const contributor of contributors) {
164
+ if (!contributor.npmAvatar && contributor.email && emailToAvatar[contributor.email]) {
165
+ contributor.npmAvatar = emailToAvatar[contributor.email];
166
+ }
167
+ }
168
+ }
@@ -13,11 +13,13 @@ declare namespace Scanner {
13
13
  name: string;
14
14
  email?: string;
15
15
  url?: string;
16
+ npmAvatar?: string;
16
17
  }
17
18
 
18
19
  export interface Maintainer {
19
20
  name: string;
20
21
  email: string;
22
+ npmAvatar?: string;
21
23
  }
22
24
 
23
25
  export interface Publisher {
@@ -38,6 +40,11 @@ declare namespace Scanner {
38
40
  * @example 2021-08-10T20:45:08.342Z
39
41
  */
40
42
  at: string;
43
+ /**
44
+ * Path to publisher's avatar on "https://www.npmjs.com"
45
+ * @example /npm-avatar/eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.e30.LwimMJA3puF3ioGeS-tfczR3370GXBZMIL-bdpu4hOU
46
+ */
47
+ npmAvatar?: string;
41
48
  }
42
49
 
43
50
  export interface DependencyLinks {