UNPKG

@worktif/purews

Version:

Work TIF TypeScript-based AWS infrastructure toolkit featuring DynamoDB integration, AppSync support, SES functionality, and GraphQL capabilities with comprehensive audit logging and AWS Signature V4 authentication.

70 lines (69 loc) 3.87 kB
import 'reflect-metadata'; import { StatusCodes } from 'http-status-codes'; import { Logger } from '@aws-lambda-powertools/logger'; import { ApiError, ApiResponse, BeforeInstance, CustomException, LoggerInstance, LoggerInterface, Maybe } from '@worktif/utils'; import { LambdaContext } from '@utils/utils.types'; import { InternalContext } from './lambda.service.api.types'; /** * Class representing a Lambda API utility. */ export declare class LambdaApi implements LoggerInterface { /** * Instance of the `Logger` used for logging operations in the application. * This logger is configured with a service name that indicates its scope, * typically used for tracing logs easily across the system. * * The `serviceName` for this instance is set to * '@lambda/container/lambda.service/lambda.service.api.ts', which reflects * the context and module where the logger is utilized. It assists in * categorizing and filtering logs specific to this module. * * Ensure that appropriate logging levels (e.g., debug, info, warn, error) * are used when working with this logger to maintain clarity and relevancy * of the logged information. * * Type: `Logger` */ loggerInstance: Logger; /** * A default exception response for unrecognized or unexpected errors. * * This variable provides a predefined API response object that includes a generic * user-friendly error message and an HTTP BAD_REQUEST status code. It is intended to be * used as a fallback response when the exact nature of an issue cannot be identified. * * Properties: * - message: A descriptive error message guiding users on how to proceed in case of errors. * - status: The HTTP status code indicating a bad request (400). */ protected defaultUnrecognisedException(error?: ApiError, beforeInstance?: BeforeInstance): Promise<ApiResponse>; /** * Handles exceptions by returning an API response with a default error message or a custom exception message. * * @param {CustomException} [exception] - The optional custom exception containing a specific error message. * @param statusCode * @return {ApiResponse} The API response object containing the error message and status code. */ protected defaultException(exception?: CustomException | any, statusCode?: number): ApiResponse; /** * Composes and returns a standardized API response object. * * @param response The response data, which can be an object, a string, or null/undefined. * This will be serialized as the body of the API response. * @param statusCode The HTTP status code for the API response. Defaults to StatusCodes.OK. * @param contentType The content type for the response header. Defaults to 'application/json'. * @param crucialPoints An array of property names to be omitted from the response body. * @return An ApiResponse object containing the HTTP status code, headers, and the serialized response body. */ protected composeApiResponse<T extends Maybe<object | string>>(response: T, statusCode?: StatusCodes, contentType?: string, crucialPoints?: string[]): ApiResponse; /** * Composes a logger instance for Lambda functions based on the provided event, context, and internal context. * * @param {any} event The input event object for the Lambda function. * @param {LambdaContext} context The AWS Lambda context. * @param {InternalContext} [internalContext] Internal context data for logger configuration. * * @returns {Promise<Maybe<LoggerInstance>>} A Promise that resolves to a Maybe of LoggerInstance. */ protected composeLambdaLogger(event: any, context: LambdaContext, internalContext?: InternalContext): Promise<Maybe<LoggerInstance>>; }