Skip to content

Commit ddc8352

Browse files
authored
Merge pull request #587 from NodeSecure/update-nodesecure-report
Update nodesecure report
1 parent 6c9f979 commit ddc8352

File tree

4 files changed

+24
-10
lines changed

4 files changed

+24
-10
lines changed

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,7 @@
9797
"@nodesecure/npm-registry-sdk": "^4.4.0",
9898
"@nodesecure/ossf-scorecard-sdk": "^3.2.1",
9999
"@nodesecure/rc": "^5.0.0",
100-
"@nodesecure/report": "^3.0.0",
100+
"@nodesecure/report": "4.0.0",
101101
"@nodesecure/scanner": "^7.1.0",
102102
"@nodesecure/utils": "^2.2.0",
103103
"@nodesecure/vulnera": "^2.0.1",

workspaces/server/src/endpoints/report.ts

Lines changed: 20 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,17 +2,18 @@
22
import fs from "node:fs";
33

44
// Import Third-party Dependencies
5-
import { report } from "@nodesecure/report";
65
import send from "@polka/send-type";
7-
import type { Request, Response } from "express-serve-static-core";
6+
import { report } from "@nodesecure/report";
87
import { appCache } from "@nodesecure/cache";
8+
import type { Request, Response } from "express-serve-static-core";
9+
import type { RC } from "@nodesecure/rc";
910

1011
// Import Internal Dependencies
1112
import { context } from "../ALS.js";
1213
import { bodyParser } from "../middlewares/bodyParser.js";
1314

1415
// TODO: provide a non-file-based API on RC side ?
15-
const kReportPayload = {
16+
const kReportPayload: Partial<RC["report"]> = {
1617
includeTransitiveInternal: false,
1718
reporters: [
1819
"pdf"
@@ -46,17 +47,23 @@ const kReportPayload = {
4647
};
4748

4849
export async function post(req: Request, res: Response) {
49-
const body = await bodyParser(req);
50+
const body = await bodyParser(req) as {
51+
title: string;
52+
includesAllDeps: boolean;
53+
theme: "light" | "dark";
54+
};
5055
const { title, includesAllDeps, theme } = body;
56+
5157
const { dataFilePath } = context.getStore()!;
5258

5359
const scannerPayload = dataFilePath ?
5460
JSON.parse(fs.readFileSync(dataFilePath, "utf-8")) :
5561
appCache.getPayload((await appCache.payloadsList()).current);
56-
const reportPayload = structuredClone(kReportPayload);
62+
5763
const rootDependencyName = scannerPayload.rootDependencyName;
5864
const [organizationPrefixOrRepo, repo] = rootDependencyName.split("/");
59-
Object.assign(reportPayload, {
65+
const reportPayload = structuredClone({
66+
...kReportPayload,
6067
title,
6168
npm: {
6269
organizationPrefix: repo === undefined ? null : organizationPrefixOrRepo,
@@ -66,8 +73,14 @@ export async function post(req: Request, res: Response) {
6673
});
6774

6875
try {
76+
const dependencies = includesAllDeps ?
77+
scannerPayload.dependencies :
78+
{
79+
[rootDependencyName]: scannerPayload.dependencies[rootDependencyName]
80+
};
81+
6982
const data = await report(
70-
includesAllDeps ? scannerPayload.dependencies : { [rootDependencyName]: scannerPayload.dependencies[rootDependencyName] },
83+
dependencies,
7184
reportPayload
7285
);
7386

workspaces/server/src/middlewares/bodyParser.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,9 @@ import type { Request } from "express-serve-static-core";
77
* @param {*} req
88
* @returns {Promise<any>}
99
*/
10-
export async function bodyParser(req: Request) {
10+
export async function bodyParser(
11+
req: Request
12+
) {
1113
let rawBody = "";
1214
for await (const chunk of req) {
1315
rawBody += chunk;

workspaces/server/test/httpServer.test.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@ import * as i18n from "@nodesecure/i18n";
1313
import * as flags from "@nodesecure/flags";
1414
import enableDestroy from "server-destroy";
1515
import cacache from "cacache";
16-
import { type Polka } from "polka";
1716

1817
// Import Internal Dependencies
1918
import { buildServer } from "../index.js";

0 commit comments

Comments
 (0)