1- import { CxConfig } from "./CxConfig" ;
2- import { CxParamType } from "./CxParamType" ;
3- import { CxConstants } from "./CxConstants" ;
4- import { ExecutionService } from "./ExecutionService" ;
5- import { CxCommandOutput } from "./CxCommandOutput" ;
6- import { getLoggerWithFilePath , logger } from "./loggerConfig" ;
1+ import { CxConfig } from "./CxConfig" ;
2+ import { CxParamType } from "./CxParamType" ;
3+ import { CxConstants } from "./CxConstants" ;
4+ import { ExecutionService } from "./ExecutionService" ;
5+ import { CxCommandOutput } from "./CxCommandOutput" ;
6+ import { getLoggerWithFilePath , logger } from "./loggerConfig" ;
77import * as fs from "fs"
88import * as os from "os" ;
99import CxBFL from "../bfl/CxBFL" ;
1010import path = require( 'path' ) ;
11- import { getTrimmedMapValue } from "./utils" ;
11+ import { getTrimmedMapValue } from "./utils" ;
1212
1313type ParamTypeMap = Map < CxParamType , string > ;
1414
@@ -57,7 +57,7 @@ export class CxWrapper {
5757 }
5858 }
5959
60-
60+
6161 initializeCommands ( formatRequired : boolean ) : string [ ] {
6262 const list : string [ ] = [ ] ;
6363 if ( this . config . clientId ) {
@@ -84,8 +84,8 @@ export class CxWrapper {
8484 list . push ( CxConstants . TENANT ) ;
8585 list . push ( this . config . tenant ) ;
8686 }
87- if ( this . config . additionalParameters ) {
88- this . prepareAdditionalParams ( this . config . additionalParameters ) . forEach ( function ( param ) {
87+ if ( this . config . additionalParameters ) {
88+ this . prepareAdditionalParams ( this . config . additionalParameters ) . forEach ( function ( param ) {
8989 list . push ( param )
9090 } )
9191 }
@@ -216,9 +216,9 @@ export class CxWrapper {
216216 return await exec . executeCommands ( this . config . pathToExecutable , commands , CxConstants . PREDICATE_TYPE ) ;
217217 }
218218
219- async triageUpdate ( projectId : string , similarityId : string , scanType : string , state : string , comment : string , severity : string , stateId :number | null = null ) : Promise < CxCommandOutput > {
219+ async triageUpdate ( projectId : string , similarityId : string , scanType : string , state : string , comment : string , severity : string , stateId : number | null = null ) : Promise < CxCommandOutput > {
220220 const commands : string [ ] = [ CxConstants . CMD_TRIAGE , CxConstants . SUB_CMD_UPDATE , CxConstants . PROJECT_ID , projectId , CxConstants . SIMILARITY_ID , similarityId , CxConstants . SCAN_TYPES_SUB_CMD , scanType , CxConstants . STATE , state , CxConstants . COMMENT , comment , CxConstants . SEVERITY , severity ] ;
221- if ( stateId ) {
221+ if ( stateId ) {
222222 commands . push ( CxConstants . STATE_ID )
223223 commands . push ( stateId . toString ( ) )
224224 }
@@ -245,7 +245,7 @@ export class CxWrapper {
245245 return exec . executeResultsCommandsFile ( scanId , CxConstants . FORMAT_JSON , CxConstants . FORMAT_JSON_FILE , commands , this . config . pathToExecutable , fileName ) ;
246246 }
247247
248- async riskManagementResults ( projectId : string , scanId : string , limit ?: number ) : Promise < CxCommandOutput > {
248+ async riskManagementResults ( projectId : string , scanId : string , limit ?: number ) : Promise < CxCommandOutput > {
249249 const commands : string [ ] = [ CxConstants . CMD_RESULT , CxConstants . CMD_RISK_MANAGEMENT ] ;
250250 commands . push ( CxConstants . PROJECT_ID , projectId ) ;
251251 commands . push ( CxConstants . SCAN_ID , scanId ) ;
@@ -313,10 +313,10 @@ export class CxWrapper {
313313 return response ;
314314 }
315315
316- async kicsRealtimeScan ( fileSources : string , engine :string , additionalParams : string ) :Promise < [ Promise < CxCommandOutput > , any ] > {
316+ async kicsRealtimeScan ( fileSources : string , engine : string , additionalParams : string ) : Promise < [ Promise < CxCommandOutput > , any ] > {
317317 const commands : string [ ] = [ CxConstants . CMD_SCAN , CxConstants . CMD_KICS_REALTIME , CxConstants . FILE_SOURCES , fileSources , CxConstants . ADDITONAL_PARAMS , additionalParams ] ;
318- if ( engine . length > 0 ) {
319- commands . push ( CxConstants . ENGINE , engine )
318+ if ( engine . length > 0 ) {
319+ commands . push ( CxConstants . ENGINE , engine )
320320 }
321321 commands . push ( ...this . initializeCommands ( false ) ) ;
322322 const exec = new ExecutionService ( ) ;
@@ -335,66 +335,66 @@ export class CxWrapper {
335335 }
336336
337337
338- async learnMore ( queryId : string ) {
339- const commands : string [ ] = [ CxConstants . CMD_UTILS , CxConstants . CMD_LEARN_MORE , CxConstants . QUERY_ID , queryId ]
338+ async learnMore ( queryId : string ) {
339+ const commands : string [ ] = [ CxConstants . CMD_UTILS , CxConstants . CMD_LEARN_MORE , CxConstants . QUERY_ID , queryId ]
340340 commands . push ( ...this . initializeCommands ( true ) )
341341 const exec = new ExecutionService ( ) ;
342342 return exec . executeCommands ( this . config . pathToExecutable , commands , CxConstants . LEARN_MORE_DESCRIPTIONS_TYPE ) ;
343343 }
344344
345- async kicsRemediation ( resultsFile : string , kicsFile :string , engine :string , similarityIds ?: string ) :Promise < [ Promise < CxCommandOutput > , any ] > {
346- const commands : string [ ] = [ CxConstants . CMD_UTILS , CxConstants . CMD_REMEDIATION , CxConstants . KICS , CxConstants . KICS_REMEDIATION_RESULTS_FILE , resultsFile , CxConstants . KICS_REMEDIATION_KICS_FILE , kicsFile ] ;
347- if ( engine . length > 0 ) {
348- commands . push ( CxConstants . ENGINE , engine )
345+ async kicsRemediation ( resultsFile : string , kicsFile : string , engine : string , similarityIds ?: string ) : Promise < [ Promise < CxCommandOutput > , any ] > {
346+ const commands : string [ ] = [ CxConstants . CMD_UTILS , CxConstants . CMD_REMEDIATION , CxConstants . KICS , CxConstants . KICS_REMEDIATION_RESULTS_FILE , resultsFile , CxConstants . KICS_REMEDIATION_KICS_FILE , kicsFile ] ;
347+ if ( engine . length > 0 ) {
348+ commands . push ( CxConstants . ENGINE , engine )
349349 }
350- if ( similarityIds ) {
351- commands . push ( CxConstants . KICS_REMEDIATION_SIMILARITY_IDS , similarityIds )
350+ if ( similarityIds ) {
351+ commands . push ( CxConstants . KICS_REMEDIATION_SIMILARITY_IDS , similarityIds )
352352 }
353353 commands . push ( ...this . initializeCommands ( false ) ) ;
354354 const exec = new ExecutionService ( ) ;
355355 return exec . executeKicsCommands ( this . config . pathToExecutable , commands , CxConstants . KICS_REMEDIATION_TYPE ) ;
356356 }
357357
358- async scaRemediation ( packageFiles : string , packages :string , packageVersion :string ) : Promise < CxCommandOutput > {
359- const commands : string [ ] = [ CxConstants . CMD_UTILS , CxConstants . CMD_REMEDIATION , CxConstants . SUB_CMD_REMEDIATION_SCA , CxConstants . SCA_REMEDIATION_PACKAGE_FILES , packageFiles , CxConstants . SCA_REMEDIATION_PACKAGE , packages , CxConstants . SCA_REMEDIATION_PACKAGE_VERSION , packageVersion ] ;
358+ async scaRemediation ( packageFiles : string , packages : string , packageVersion : string ) : Promise < CxCommandOutput > {
359+ const commands : string [ ] = [ CxConstants . CMD_UTILS , CxConstants . CMD_REMEDIATION , CxConstants . SUB_CMD_REMEDIATION_SCA , CxConstants . SCA_REMEDIATION_PACKAGE_FILES , packageFiles , CxConstants . SCA_REMEDIATION_PACKAGE , packages , CxConstants . SCA_REMEDIATION_PACKAGE_VERSION , packageVersion ] ;
360360 commands . push ( ...this . initializeCommands ( false ) ) ;
361361 const exec = new ExecutionService ( ) ;
362362 return exec . executeCommands ( this . config . pathToExecutable , commands ) ;
363363 }
364364
365365 async ideScansEnabled ( ) : Promise < boolean > {
366- const commands : string [ ] = [ CxConstants . CMD_UTILS , CxConstants . SUB_CMD_TENANT ] ;
367- commands . push ( ...this . initializeCommands ( false ) ) ;
366+ const commands : string [ ] = [ CxConstants . CMD_UTILS , CxConstants . SUB_CMD_TENANT ] ;
367+ commands . push ( ...this . initializeCommands ( false ) ) ;
368368
369- const exec = new ExecutionService ( ) ;
370- const output = await exec . executeMapTenantOutputCommands ( this . config . pathToExecutable , commands ) ;
369+ const exec = new ExecutionService ( ) ;
370+ const output = await exec . executeMapTenantOutputCommands ( this . config . pathToExecutable , commands ) ;
371371
372- const value = getTrimmedMapValue ( output , CxConstants . IDE_SCANS_KEY ) ;
373- return value ?. toLowerCase ( ) === "true" ;
374- }
372+ const value = getTrimmedMapValue ( output , CxConstants . IDE_SCANS_KEY ) ;
373+ return value ?. toLowerCase ( ) === "true" ;
374+ }
375375
376376 async guidedRemediationEnabled ( ) : Promise < boolean > {
377- const commands : string [ ] = [ CxConstants . CMD_UTILS , CxConstants . SUB_CMD_TENANT ] ;
378- commands . push ( ...this . initializeCommands ( false ) ) ;
377+ const commands : string [ ] = [ CxConstants . CMD_UTILS , CxConstants . SUB_CMD_TENANT ] ;
378+ commands . push ( ...this . initializeCommands ( false ) ) ;
379379
380- const exec = new ExecutionService ( ) ;
381- const output = await exec . executeMapTenantOutputCommands ( this . config . pathToExecutable , commands ) ;
380+ const exec = new ExecutionService ( ) ;
381+ const output = await exec . executeMapTenantOutputCommands ( this . config . pathToExecutable , commands ) ;
382382
383- const value = getTrimmedMapValue ( output , CxConstants . AI_GUIDED_REMEDIATION_KEY ) ;
384- return value ?. toLowerCase ( ) === "true" ;
385- }
383+ const value = getTrimmedMapValue ( output , CxConstants . AI_GUIDED_REMEDIATION_KEY ) ;
384+ return value ?. toLowerCase ( ) === "true" ;
385+ }
386386
387387
388- async aiMcpServerEnabled ( ) : Promise < boolean > {
389- const commands : string [ ] = [ CxConstants . CMD_UTILS , CxConstants . SUB_CMD_TENANT ] ;
390- commands . push ( ...this . initializeCommands ( false ) ) ;
388+ async aiMcpServerEnabled ( ) : Promise < boolean > {
389+ const commands : string [ ] = [ CxConstants . CMD_UTILS , CxConstants . SUB_CMD_TENANT ] ;
390+ commands . push ( ...this . initializeCommands ( false ) ) ;
391391
392- const exec = new ExecutionService ( ) ;
393- const output = await exec . executeMapTenantOutputCommands ( this . config . pathToExecutable , commands ) ;
392+ const exec = new ExecutionService ( ) ;
393+ const output = await exec . executeMapTenantOutputCommands ( this . config . pathToExecutable , commands ) ;
394394
395- const value = getTrimmedMapValue ( output , CxConstants . AI_MCP_SERVER_KEY ) ;
396- return value ?. toLowerCase ( ) === "true" ;
397- }
395+ const value = getTrimmedMapValue ( output , CxConstants . AI_MCP_SERVER_KEY ) ;
396+ return value ?. toLowerCase ( ) === "true" ;
397+ }
398398
399399 async kicsChat ( apikey : string , file : string , line : number , severity : string , vulnerability : string , input : string , conversationId ?: string , model ?: string ) : Promise < CxCommandOutput > {
400400 const commands : string [ ] = [
@@ -437,7 +437,7 @@ export class CxWrapper {
437437 return new ExecutionService ( ) . executeCommands ( this . config . pathToExecutable , commands , CxConstants . CHAT_TYPE ) ;
438438 }
439439
440- async maskSecrets ( file : string ) : Promise < CxCommandOutput > {
440+ async maskSecrets ( file : string ) : Promise < CxCommandOutput > {
441441 const commands : string [ ] = [
442442 CxConstants . CMD_UTILS ,
443443 CxConstants . CMD_MASK_SECRETS ,
@@ -448,10 +448,26 @@ export class CxWrapper {
448448 return new ExecutionService ( ) . executeCommands ( this . config . pathToExecutable , commands , CxConstants . MASK_TYPE ) ;
449449 }
450450
451- prepareAdditionalParams ( additionalParameters : string ) : string [ ] {
451+ telemetryAIEvent ( aiProvider : string , agent : string , timestamp : Date , clickType : string , engine : string , problemSeverity : string ) : Promise < CxCommandOutput > {
452+ const commands : string [ ] = [
453+ CxConstants . TELEMETRY ,
454+ CxConstants . SUB_CMD_TELEMETRY_AI ,
455+ CxConstants . AI_PROVIDER , aiProvider ,
456+ CxConstants . AGENT , agent ,
457+ CxConstants . TIMESTAMP , timestamp . toISOString ( ) ,
458+ CxConstants . CLICK_TYPE , clickType ,
459+ CxConstants . ENGINE , engine ,
460+ CxConstants . PROBLEM_SEVERITY , problemSeverity
461+ ] ;
462+ commands . push ( ...this . initializeCommands ( true ) ) ;
463+ const exec = new ExecutionService ( ) ;
464+ return exec . executeCommands ( this . config . pathToExecutable , commands ) ;
465+ }
466+
467+ prepareAdditionalParams ( additionalParameters : string ) : string [ ] {
452468 const params : string [ ] = [ ] ;
453469
454- if ( ! additionalParameters ) {
470+ if ( ! additionalParameters ) {
455471 return params ;
456472 }
457473
0 commit comments