import { getForeverAgents , ResponseWithBodyType } from 'common' ; import got , { Agents , Got , Options } from 'got' ; import { injectable } from 'inversify' ; import { isEmpty } from 'lodash' ; import { NotificationSenderMetadata } from '../types/notification-sender-metadata' ; @ injectable ( ) export class NotificationSenderWebAPIClient { private readonly defaultRequestObject : Got ; private readonly defaultOptions : Options = { headers : { 'Content-Type' : 'application/json' , } , } ; constructor ( private readonly throwOnRequestFailure = false , requestObject = got , getAgentsFn = getForeverAgents ) { this . defaultRequestObject = requestObject . extend ( { ... this . defaultOptions , agent : getAgentsFn ( ) , throwHttpErrors : this . throwOnRequestFailure , } ) ; } public async sendNotification ( notificationSenderConfigData ) { const requestBody = { scanId : notificationSenderConfigData . scanId , runStatus : notificationSenderConfigData . runStatus , scanStatus : isEmpty ( notificationSenderConfigData . scanStatus ) ? undefined : notificationSenderConfigData . scanStatus , } ; const options = { json : requestBody , timeout : 30000 } ; return ( await this . defaultRequestObject . post ( notificationSenderConfigData . scanNotifyUrl , options ) ) as ResponseWithBodyType ; } }