22import fs from "node:fs" ;
33
44// Import Third-party Dependencies
5- import { report } from "@nodesecure/report" ;
65import send from "@polka/send-type" ;
7- import type { Request , Response } from "express-serve-static-core " ;
6+ import { report } from "@nodesecure/report " ;
87import { 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
1112import { context } from "../ALS.js" ;
1213import { 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
4849export 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
0 commit comments