UNPKG

@allthings/cloud-toolkit

Version:

Standardizes the setup of aws, datadog and other things

83 lines (82 loc) 3.96 kB
import { APIGatewayEvent, APIGatewayProxyEventV2, Callback, Context } from 'aws-lambda'; export type Alagarr = (event: APIGatewayEvent | APIGatewayProxyEventV2, context: Context, callback: Callback) => void; export type HandlerFunction = (request: any, response: any, context?: Context) => string | object | void | Promise<string | object | void>; export type Logger = (request: any, response: any) => boolean; export type ErrorHandler = (request: IInterfaceRequest, response: IInterfaceResponse, error: any) => void; export interface IInterfaceAlagarrOptions { readonly cspPolicies?: any; readonly enableCompression?: boolean; readonly enableContentLength?: boolean; readonly enableCspHeaders?: boolean; readonly enableETagHeader?: boolean; readonly enableEnforcedHeaders?: boolean; readonly enableLogger?: boolean; readonly enableStrictTransportSecurity?: boolean; readonly errorHandler?: ErrorHandler; readonly headers?: object; readonly logger?: Logger; readonly requestMiddleware?: any; readonly responseMiddleware?: any; } export type IIndexSignature = Readonly<Record<string, any>>; export type IInterfaceCookie = Readonly<Record<string, string>>; export type IInterfaceHeaders = Readonly<Record<string, string>>; export type IInterfaceQueryParameters = Readonly<Record<string, string>>; export interface IInterfaceRequest extends APIGatewayEvent { readonly body: any; readonly context: Context; readonly cookies: IInterfaceCookie; readonly headers: IInterfaceHeaders; readonly hostname?: string; readonly isBase64Encoded: boolean; readonly meta: IIndexSignature; readonly method: string; readonly provider: string; readonly query: IInterfaceQueryParameters; readonly source: string; readonly timestamp: number; } export interface IInterfaceRequestV2 extends APIGatewayProxyEventV2 { readonly body: any; readonly context: Context; readonly headers: IInterfaceHeaders; readonly hostname?: string; readonly isBase64Encoded: boolean; readonly meta: IIndexSignature; readonly method: string; readonly provider: string; readonly query: IInterfaceQueryParameters; readonly source: string; readonly timestamp: number; } export type RequestMiddleware = (request: IInterfaceRequest) => IInterfaceRequest; export interface IInterfaceResponseData { readonly body: string; readonly headers: any; readonly isBase64Encoded?: boolean; readonly statusCode: number; } export declare enum EnumDefaultRespondToFormat { html = "html", json = "json" } export interface IInterfaceRespondToFormat { readonly default?: EnumDefaultRespondToFormat; readonly html?: string; readonly json?: any; } export interface IInterfaceResponseOptions { readonly headers?: Readonly<Record<string, boolean | number | string>>; readonly isBase64Encoded?: boolean; } export interface IInterfaceResponse { readonly html: (html: string, statusCode?: number, options?: IInterfaceResponseOptions) => void; readonly json: (json: any, statusCode?: number, options?: IInterfaceResponseOptions) => void; readonly raw: (error?: Error | null, result?: object | boolean | number | string) => void; readonly redirect: (location: string, statusCode?: number, options?: IInterfaceResponseOptions) => void; readonly respondTo: (formats: IInterfaceRespondToFormat, statusCode?: number, options?: IInterfaceResponseOptions) => void; readonly setHeader: (key: string, value: string) => IInterfaceResponse; readonly text: (text: string, statusCode?: number, options?: IInterfaceResponseOptions) => void; } export type ResponseHelper = (responseData: IInterfaceResponseData, request: IInterfaceRequest, body: any, statusCode?: number, options?: object) => IInterfaceResponseData; export type ResponseMiddleware = (response: IInterfaceResponse, request: IInterfaceRequest) => IInterfaceResponse;