Skip to content

Commit 93ef53f

Browse files
committed
chore: update @nodesecure/report to v4.x
1 parent 69aa9a5 commit 93ef53f

File tree

3 files changed

+24
-9
lines changed

3 files changed

+24
-9
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,16 +47,22 @@ 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
const scannerPayload = dataFilePath ?
5359
JSON.parse(fs.readFileSync(dataFilePath, "utf-8")) :
5460
appCache.getPayload((await appCache.payloadsList()).current);
55-
const reportPayload = structuredClone(kReportPayload);
61+
5662
const rootDependencyName = scannerPayload.rootDependencyName;
5763
const [organizationPrefixOrRepo, repo] = rootDependencyName.split("/");
58-
Object.assign(reportPayload, {
64+
const reportPayload = structuredClone({
65+
...kReportPayload,
5966
title,
6067
npm: {
6168
organizationPrefix: repo === undefined ? null : organizationPrefixOrRepo,
@@ -65,8 +72,14 @@ export async function post(req: Request, res: Response) {
6572
});
6673

6774
try {
75+
const dependencies = includesAllDeps ?
76+
scannerPayload.dependencies :
77+
{
78+
[rootDependencyName]: scannerPayload.dependencies[rootDependencyName]
79+
};
80+
6881
const data = await report(
69-
includesAllDeps ? scannerPayload.dependencies : { [rootDependencyName]: scannerPayload.dependencies[rootDependencyName] },
82+
dependencies,
7083
reportPayload
7184
);
7285

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;

0 commit comments

Comments
 (0)