import { SQS } from 'aws-sdk' ; import { LONG_POLLING_WAIT_TIME_SECONDS , SINGLE_MESSAGE } from '../constants' ; /**
 * SqsClient wraps SQS, making it far easier to unit test SQS and ignore SQS details
 */ export class SqsClient { constructor ( private readonly _sqs , private readonly _queueUrl ) { } public async receiveMessageAsync ( ) { const response = await this . _sqs . receiveMessage ( { MaxNumberOfMessages : SINGLE_MESSAGE , WaitTimeSeconds : LONG_POLLING_WAIT_TIME_SECONDS , QueueUrl : this . _queueUrl , } ) . promise ( ) ; if ( response ?. Messages ?. length !== 1 ) { return null ; } return response . Messages [ 0 ] ; } public async changeMessageVisibilityAsync ( receiptHandle , visibilityTimeout ) { await this . _sqs . changeMessageVisibility ( { QueueUrl : this . _queueUrl , ReceiptHandle : receiptHandle , VisibilityTimeout : visibilityTimeout , } ) . promise ( ) ; } public async deleteMessageAsync ( receiptHandle ) { await this . _sqs . deleteMessage ( { QueueUrl : this . _queueUrl , ReceiptHandle : receiptHandle , } ) . promise ( ) ; } }