Skip to content

Commit c91b2c6

Browse files
authored
feat(scanner): implement new metadata property (#564)
1 parent c009145 commit c91b2c6

File tree

4 files changed

+27
-1
lines changed

4 files changed

+27
-1
lines changed

.changeset/bumpy-forks-lie.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"@nodesecure/scanner": minor
3+
---
4+
5+
Add a new metadata property in the scanner payload

workspaces/scanner/src/depWalker.ts

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,7 @@ export async function depWalker(
104104
npmRcConfig
105105
} = options;
106106

107+
const startedAt = Date.now();
107108
const isRemoteScanning = typeof location === "undefined";
108109
const tokenStore = new RegistryTokenStore(npmRcConfig, NPM_TOKEN.token);
109110

@@ -119,7 +120,11 @@ export async function depWalker(
119120
},
120121
scannerVersion: packageVersion,
121122
vulnerabilityStrategy,
122-
warnings: []
123+
warnings: [],
124+
metadata: {
125+
startedAt,
126+
executionTime: 0
127+
}
123128
};
124129

125130
const dependencies: Map<string, Dependency> = new Map();
@@ -327,6 +332,9 @@ export async function depWalker(
327332
};
328333
payload.dependencies = Object.fromEntries(dependencies);
329334

335+
const metadata = payload.metadata!;
336+
metadata.executionTime = Date.now() - startedAt;
337+
330338
return payload as Payload;
331339
}
332340
finally {

workspaces/scanner/src/types.ts

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -206,6 +206,17 @@ export interface Payload {
206206

207207
/** The integrity of the scanned package */
208208
integrity: string | null;
209+
210+
metadata: {
211+
/**
212+
* UNIX Timestamp when the scan started
213+
*/
214+
startedAt: number;
215+
/**
216+
* Execution time in milliseconds
217+
*/
218+
executionTime: number;
219+
};
209220
}
210221

211222
export interface Options {

workspaces/scanner/test/depWalker.spec.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -172,6 +172,7 @@ test("fetch payload of pacote on the npm registry", async() => {
172172
"scannerVersion",
173173
"vulnerabilityStrategy",
174174
"warnings",
175+
"metadata",
175176
"integrity",
176177
"highlighted",
177178
"dependencies"
@@ -192,6 +193,7 @@ test("fetch payload of pacote on the gitlab registry", async() => {
192193
"scannerVersion",
193194
"vulnerabilityStrategy",
194195
"warnings",
196+
"metadata",
195197
"integrity",
196198
"highlighted",
197199
"dependencies"

0 commit comments

Comments
 (0)