import type { Context, APIGatewayEvent } from 'aws-lambda'; import Logger from '../Logger/Logger.js'; /** * Represents a request object with generic types for input, query parameters, and path parameters. * @class Request * @template InputType - The type of the input data for the request. * @template PathParamsType - The type of the path parameters for the request. * @template QueryParamsType - The type of the query parameters for the request. */ export default class Request { /** * Default paths to exclude from verbose logging (health checks, monitoring, etc.) */ private static readonly DEFAULT_NO_LOG_PATHS; /** * Combined list of ignored paths, computed once at class-load time. */ private static readonly IGNORED_PATHS; /** * Represents an API Gateway event for a request. * @type {APIGatewayEvent} */ private requestEvent; /** * The context object for the current instance. */ private context; /** * Cached result of whether this request is a health/monitoring endpoint. */ private readonly _isHealthCheckPath; /** * Constructs a new instance of the class. * @param {APIGatewayEvent} requestEvent - The API Gateway event object. * @param {Context} context - The context object. * @param {Logger} logger - The logger object. * @returns None */ constructor(requestEvent: APIGatewayEvent, context: Context, logger: Logger); /** * Builds a concise, sanitized request summary for logging. * Avoid logging the full event object, raw body, or sensitive header values. */ private getRelevantLogData; /** * Detects queue-style event payloads such as SQS events. */ private isQueueEvent; /** * Builds a concise log payload for SQS-style record batches. */ private getQueueEventLogData; private getUniqueRecordValues; /** * Parses record bodies when they are JSON strings; otherwise returns the raw value. */ private parseRecordBody; /** * Logs body shape instead of full request payload to keep logs useful and safe. */ private getBodyLogData; private getBodySummary; /** * Checks if the path is a health check or monitoring endpoint that should not be logged verbosely. * @param {string} path - The request path * @returns {boolean} - True if it's a health/monitoring endpoint */ private isHealthOrMonitoringPath; /** * Checks if the specified query parameter exists and has a valid value. * @param {keyof QueryParamsType} paramName - The name of the query parameter to check. * @returns {boolean} - True if the query parameter exists and has a valid value, false otherwise. */ containsQueryParam(paramName: keyof QueryParamsType): boolean; /** * Retrieves the value of a query parameter from the URL. * @param {keyof QueryParamsType} paramName - The name of the query parameter to retrieve. * @returns {string | null} The value of the query parameter, or null if it does not exist. */ getQueryParam(paramName: keyof QueryParamsType): string; /** * Retrieves the value of the specified header from the request event headers. * @param {string} headerName - The name of the header to retrieve. * @returns {string | null} - The value of the header, or null if the header is not found. */ getHeader(headerName: string): string | null; /** * Retrieves the value of a context parameter from the request context object. * @param {string} cxtParam - The name of the context parameter to retrieve. * @returns The value of the context parameter, or null if it does not exist. */ getContextParam(cxtParam: string): any | null; /** * Checks if the given parameter name exists in the PathParamsType object. * @param {keyof PathParamsType} paramName - The name of the parameter to check. * @returns {boolean} - True if the parameter exists, false otherwise. */ containsPathParam(paramName: keyof PathParamsType): boolean; /** * Retrieves the value of a specific path parameter from the URL. * @param {keyof PathParamsType} paramName - The name of the path parameter to retrieve. * @returns {string} The value of the path parameter, or null if it does not exist. */ getPathParam(paramName: keyof PathParamsType): string; /** * Retrieves the body of the request event and parses it if it is a string. * @returns {InputType} The parsed body of the request event. */ getBody(raw?: boolean): InputType; /** * Retrieves the path from the request event. * @returns {string} The path of the request event. */ getPath(): string; isHealthCheckPath(): boolean; static isHealthCheckPath(path: string): boolean; /** * Retrieves the HTTP method of the current request. * @returns {string} The HTTP method of the request. */ getMethod(): HttpMethod; /** * Retrieves the path parameters from the request event. * @returns {PathParamsType | null} - The path parameters object, or null if not found. */ getPathParams(): PathParamsType; /** * Retrieves the query parameters from the request event. * @returns {QueryParamsType | null} - The query parameters object, or null if not found. */ getQueryParams(): QueryParamsType; /** * Retrieves the value of the 'Authorization' header from the request. * @returns The value of the 'Authorization' header, or null if it is not present. */ getAuthorizationHeader(): string | null; /** * Retrieves the request ID associated with the current execution context. * @returns {string} The request ID. */ getRequestID(): string; /** * Retrieves the origin IP address of the request. * @returns {string} The origin IP address. If the IP address is not available, it returns 'unknown'. */ getOriginIP(): string; /** * Sets the fixed path parameters in the request event object. * @param {any[]} keys - An array of keys representing the path parameter names. * @param {any[]} result - An array of values representing the path parameter values. * @returns None */ setFixedPathParams(keys: any[], result: any[]): void; } /** * Enum representing the HTTP methods. */ export declare enum HttpMethod { GET = "GET", HEAD = "HEAD", POST = "POST", PUT = "PUT", DELETE = "DELETE", CONNECT = "CONNECT", OPTIONS = "OPTIONS", TRACE = "TRACE", PATCH = "PATCH" }