Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/bumpy-forks-lie.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@nodesecure/scanner": minor
---

Add a new metadata property in the scanner payload
10 changes: 9 additions & 1 deletion workspaces/scanner/src/depWalker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,7 @@ export async function depWalker(
npmRcConfig
} = options;

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

Expand All @@ -119,7 +120,11 @@ export async function depWalker(
},
scannerVersion: packageVersion,
vulnerabilityStrategy,
warnings: []
warnings: [],
metadata: {
startedAt,
executionTime: 0
}
};

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

const metadata = payload.metadata!;
metadata.executionTime = Date.now() - startedAt;

return payload as Payload;
}
finally {
Expand Down
11 changes: 11 additions & 0 deletions workspaces/scanner/src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -206,6 +206,17 @@ export interface Payload {

/** The integrity of the scanned package */
integrity: string | null;

metadata: {
/**
* UNIX Timestamp when the scan started
*/
startedAt: number;
/**
* Execution time in milliseconds
*/
executionTime: number;
};
}

export interface Options {
Expand Down
2 changes: 2 additions & 0 deletions workspaces/scanner/test/depWalker.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -172,6 +172,7 @@ test("fetch payload of pacote on the npm registry", async() => {
"scannerVersion",
"vulnerabilityStrategy",
"warnings",
"metadata",
"integrity",
"highlighted",
"dependencies"
Expand All @@ -192,6 +193,7 @@ test("fetch payload of pacote on the gitlab registry", async() => {
"scannerVersion",
"vulnerabilityStrategy",
"warnings",
"metadata",
"integrity",
"highlighted",
"dependencies"
Expand Down