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,17 +47,23 @@ 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
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
0 commit comments