@nodesecure/scanner 2.0.1 → 3.1.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.
@@ -4,7 +4,7 @@ import semver from "semver";
4
4
  import { getLocalRegistryURL } from "@nodesecure/npm-registry-sdk";
5
5
 
6
6
  // Import Internal Dependencies
7
- import { constants } from "./index.js";
7
+ import { NPM_TOKEN } from "./index.js";
8
8
 
9
9
  /**
10
10
  * @param {!string} version semver range
@@ -31,11 +31,11 @@ export function cleanRange(version) {
31
31
  export async function getExpectedSemVer(depName, range) {
32
32
  try {
33
33
  const { versions, "dist-tags": { latest } } = await pacote.packument(depName, {
34
- ...constants.NPM_TOKEN, registry: getLocalRegistryURL()
34
+ ...NPM_TOKEN, registry: getLocalRegistryURL()
35
35
  });
36
36
  const currVersion = semver.maxSatisfying(Object.keys(versions), range);
37
37
 
38
- return [currVersion === null ? latest : currVersion, semver.eq(latest, currVersion)];
38
+ return currVersion === null ? [latest, true] : [currVersion, semver.eq(latest, currVersion)];
39
39
  }
40
40
  catch (err) {
41
41
  return [cleanRange(range), true];
package/types/api.d.ts CHANGED
@@ -1,12 +1,15 @@
1
1
  import Scanner from "./scanner";
2
- import { Logger } from "./logger";
2
+ import { Logger, LoggerEvents } from "./logger";
3
3
 
4
4
  export {
5
5
  cwd,
6
6
  from,
7
- verify
7
+ verify,
8
+ ScannerLoggerEvents
8
9
  }
9
10
 
11
+ declare const ScannerLoggerEvents: LoggerEvents;
12
+
10
13
  declare function cwd(path: string, options?: Scanner.Options, logger?: Logger): Promise<Scanner.Payload>;
11
14
  declare function from(packageName: string, options?: Scanner.Options, logger?: Logger): Promise<Scanner.Payload>;
12
15
  declare function verify(packageName: string): Promise<Scanner.VerifyPayload>;
package/types/logger.d.ts CHANGED
@@ -2,11 +2,27 @@ import { EventEmitter } from "events";
2
2
 
3
3
  export {
4
4
  Logger,
5
- LoggerEventData
5
+ LoggerEventData,
6
+ LoggerEvents
7
+ }
8
+
9
+ interface LoggerEvents {
10
+ readonly done: "depWalkerFinished";
11
+ readonly analysis: {
12
+ readonly tree: "walkTree";
13
+ readonly tarball: "tarball";
14
+ readonly registry: "registry";
15
+ };
16
+ readonly manifest: {
17
+ readonly read: "readManifest";
18
+ readonly fetch: "fetchManifest";
19
+ };
6
20
  }
7
21
 
8
22
  interface LoggerEventData {
23
+ /** UNIX Timestamp */
9
24
  startedAt: number;
25
+ /** Count of triggered event */
10
26
  count: number;
11
27
  }
12
28
 
@@ -1,64 +1,136 @@
1
- import { Warning, Dependency, BaseWarning } from "@nodesecure/js-x-ray";
1
+ // Import NodeSecure Dependencies
2
+ import * as JSXRay from "@nodesecure/js-x-ray";
2
3
  import { license as License } from "@nodesecure/ntlp";
3
- import { Strategy, NpmStrategy, NodeStrategy } from "@nodesecure/vuln";
4
+ import * as Vuln from "@nodesecure/vuln";
4
5
  import { Flags } from "@nodesecure/flags";
6
+
7
+ // Import Third-party Dependencies
5
8
  import { Maintainer } from "@npm/types";
6
9
 
7
10
  export = Scanner;
8
11
 
9
12
  declare namespace Scanner {
10
13
  export interface Publisher {
14
+ /**
15
+ * Publisher npm user name.
16
+ */
11
17
  name: string;
18
+ /**
19
+ * Publisher npm user email.
20
+ */
21
+ email: string;
22
+ /**
23
+ * First version published.
24
+ */
12
25
  version: string;
26
+ /**
27
+ * Date of the first publication
28
+ * @example 2021-08-10T20:45:08.342Z
29
+ */
13
30
  at: string;
14
31
  }
15
32
 
16
- export interface VersionDescriptor {
33
+ export interface DependencyVersion {
34
+ /** Id of the package (useful for usedBy relation) */
35
+ id: number;
36
+ /** By whom (id) is used the package */
37
+ usedBy: Record<string, string>;
38
+ /** Size on disk of the extracted tarball (in bytes) */
39
+ size: number;
40
+ /** Package description */
41
+ description: string;
42
+ /** Author of the package. This information is not trustable and can be empty. */
43
+ author: Maintainer;
44
+ /**
45
+ * JS-X-Ray warnings
46
+ *
47
+ * @see https://github.com/NodeSecure/js-x-ray/blob/master/WARNINGS.md
48
+ */
49
+ warnings: JSXRay.Warning<JSXRay.BaseWarning>[];
50
+ /** Tarball composition (files and dependencies) */
51
+ composition: {
52
+ /** Files extensions (.js, .md, .exe etc..) */
53
+ extensions: string[];
54
+ files: string[];
55
+ /** Minified files (foo.min.js etc..) */
56
+ minified: string[];
57
+ required_files: string[];
58
+ required_thirdparty: string[];
59
+ required_nodejs: string[];
60
+ unused: string[];
61
+ missing: string[];
62
+ };
63
+ /**
64
+ * Package licenses with SPDX expression.
65
+ *
66
+ * @see https://github.com/NodeSecure/licenses-conformance
67
+ * @see https://github.com/NodeSecure/npm-tarball-license-parser
68
+ */
69
+ license: License[];
70
+ /**
71
+ * Flags (Array of string)
72
+ *
73
+ * @see https://github.com/NodeSecure/flags/blob/main/FLAGS.md
74
+ */
75
+ flags: Flags[];
76
+ /**
77
+ * If the dependency is a GIT repository
78
+ */
79
+ gitUrl: null | string;
80
+ }
81
+
82
+ export interface Dependency {
83
+ /** NPM Registry metadata */
17
84
  metadata: {
85
+ /** Count of dependencies */
18
86
  dependencyCount: number;
87
+ /** Number of releases published on npm */
19
88
  publishedCount: number;
20
89
  lastUpdateAt: number;
90
+ /** Last version SemVer */
21
91
  lastVersion: number;
22
92
  hasChangedAuthor: boolean;
23
93
  hasManyPublishers: boolean;
24
94
  hasReceivedUpdateInOneYear: boolean;
95
+ /** Author of the package. This information is not trustable and can be empty. */
25
96
  author: Maintainer;
97
+ /** Package home page */
26
98
  homepage: string | null;
27
- maintainers: Maintainer[];
99
+ /**
100
+ * List of maintainers (list of people in the organization related to the package)
101
+ */
102
+ maintainers: { name: string, email: string }[];
103
+ /**
104
+ * List of people who published this package
105
+ */
28
106
  publishers: Publisher[];
29
107
  }
30
- versions: string[];
31
- vulnerabilities: (NpmStrategy.Vulnerability | NodeStrategy.Vulnerability)[];
32
- [version: string]: {
33
- id: number;
34
- usedBy: Record<string, string>;
35
- size: number;
36
- description: string;
37
- author: Maintainer;
38
- warnings: Warning<BaseWarning>[];
39
- composition: {
40
- extensions: string[];
41
- files: string[];
42
- minified: string[];
43
- required_files: string[];
44
- required_thirdparty: string[];
45
- required_nodejs: string[];
46
- unused: string[];
47
- missing: string[];
48
- };
49
- license: string | License[];
50
- flags: Flags;
51
- gitUrl: null | string;
52
- };
108
+ /** List of versions of this package available in the dependency tree (In the payload) */
109
+ versions: Record<string, DependencyVersion>;
110
+ /**
111
+ * Vulnerabilities fetched dependending on the selected vulnerabilityStrategy
112
+ *
113
+ * @see https://github.com/NodeSecure/vuln
114
+ */
115
+ vulnerabilities: Vuln.Strategy.StandardVulnerability[];
53
116
  }
54
117
 
118
+ export type GlobalWarning = string[];
119
+ export type Dependencies = Record<string, Dependency>;
120
+
55
121
  export interface Payload {
122
+ /** Payload unique id */
56
123
  id: string;
124
+ /** Name of the analyzed package */
57
125
  rootDependencyName: string;
58
- warnings: [];
59
- dependencies: Record<string, VersionDescriptor>;
126
+ /** Global warnings list */
127
+ warnings: GlobalWarning[];
128
+ /** All the dependencies of the package (flattened) */
129
+ dependencies: Dependencies;
130
+ /** Version of the scanner used to generate the result */
60
131
  version: string;
61
- vulnerabilityStrategy: Strategy.Kind;
132
+ /** Vulnerability strategy name (npm, snyk, node) */
133
+ vulnerabilityStrategy: Vuln.Strategy.Kind;
62
134
  }
63
135
 
64
136
  export interface VerifyPayload {
@@ -71,16 +143,43 @@ declare namespace Scanner {
71
143
  uniqueLicenseIds: string[];
72
144
  licenses: License[];
73
145
  ast: {
74
- dependencies: Record<string, Dependency>;
75
- warnings: Warning<BaseWarning>[];
146
+ dependencies: Record<string, JSXRay.Dependency>;
147
+ warnings: JSXRay.Warning<JSXRay.BaseWarning>[];
76
148
  };
77
149
  }
78
150
 
79
151
  export interface Options {
152
+ /**
153
+ * Maximum tree depth
154
+ *
155
+ * @default 4
156
+ */
80
157
  readonly maxDepth?: number;
158
+ /**
159
+ * Use root package-lock.json. This will have the effect of triggering the Arborist package.
160
+ *
161
+ * @default false for from() API
162
+ * @default true for cwd() API
163
+ */
81
164
  readonly usePackageLock?: boolean;
82
- readonly vulnerabilityStrategy: Strategy.Kind;
165
+ /**
166
+ * Vulnerability strategy name (npm, snyk, node)
167
+ *
168
+ * @default NONE
169
+ */
170
+ readonly vulnerabilityStrategy: Vuln.Strategy.Kind;
171
+ /**
172
+ * Analyze root package.
173
+ *
174
+ * @default false for from() API
175
+ * @default true for cwd() API
176
+ */
83
177
  readonly forceRootAnalysis?: boolean;
178
+ /**
179
+ * Deeper dependencies analysis with cwd() API.
180
+ *
181
+ * @default false
182
+ */
84
183
  readonly fullLockMode?: boolean;
85
184
  }
86
185
  }