import type { Context, SQSBatchResponse, SQSEvent } from 'aws-lambda'; import Transaction, { TransactionConfig } from './Transaction.js'; import Response, { ResponseErrorType } from '../API/Response.js'; /** * Type definition for an event processor execution function. * @param {Transaction} transaction - The transaction object. * @param {string | object} recordContent - The content of the record being processed. * @returns {Promise | SQSBatchResponse>} - A promise that resolves to the response or batch response. */ export type EventProcessorExecution = (transaction: Transaction, recordContent: string | object) => Promise | SQSBatchResponse | null>; /** * EventProcessor class that processes events from an SQS queue. * @template ResponseInnerType - The type of the inner response object. */ export default class EventProcessor { /** * A boolean flag indicating whether failures are allowed or not. * @readonly */ private readonly allowFailure; /** * The configuration object for the API transaction. */ private readonly config; /** * The private readonly context property of the class. * @type {Context} */ private readonly context; /** * The SQS event object that triggered the Lambda function. */ private readonly event; /** * Constructs a new instance of the class. * @param {SQSEvent} event - The event object representing the incoming SQS message. * @param {Context} context - The context object representing the AWS Lambda execution context. * @param {TransactionConfig} [config] - Optional configuration object for the transaction. * @param {boolean} [allowFailure] - Optional flag indicating whether to allow failure for the transaction. * @returns None */ constructor(event: SQSEvent, context: Context, config?: TransactionConfig, allowFailure?: boolean); /** * Processes an event using the provided execution object and returns a response. * @param {EventProcessorExecution} execution - The execution object containing the event to process. * @param {boolean} [doNotDecodeMessage] - Optional flag indicating whether to decode the message. * @returns {Promise | null | SQSBatchResponse>} - A promise that resolves to the response object, or null if no response is available. * @throws {Error} - Throws an error if the response code is not within the range of 200 to 299 and failure is not allowed. */ processEvent(execution: EventProcessorExecution, doNotDecodeMessage?: boolean): Promise | null | SQSBatchResponse>; /** * Processes a raw event by executing the provided execution function and handling any errors or failures. * @param {EventProcessorExecution} execution - The execution function to process the event. * @param {boolean} doNotDecodeMessage - Flag indicating whether to decode the message or not. * @returns {Promise | null | SQSBatchResponse>} - A promise that resolves to a response object, null, or a SQS batch response. */ private processRawEvent; }