UNPKG

@scloud/lambda-api

Version:

Lambda handler for API Gateway proxy requests

61 lines (60 loc) 2.18 kB
import { APIGatewayProxyEvent } from 'aws-lambda'; import { Request, Response, Route, Routes } from './types'; /** * Ensures the path always has a leading slash and never a trailing slash * @param path APIGatewayProxyEvent.path */ export declare function standardPath(path: string): string; /** * Ensures a non-null object containing only query-string parameters that have a value. * @param query APIGatewayProxyEvent.query */ export declare function standardQueryParameters(query: { [name: string]: string | undefined; } | null): { [name: string]: string; }; /** * Ensures all headers have a value. * @param headers APIGatewayProxyEvent.headers */ export declare function standardHeaders(headers: { [name: string]: string | undefined; }): { [name: string]: string; }; /** * Parses the body (if present) from application/x-www-form-urlencoded or JSON string. * If the body fails to parse as JSOn, the raw body is returned. * @param body APIGatewayProxyEvent.body */ export declare function parseBody(body: string | null, isBase64Encoded: boolean, contentType?: string): Record<string, unknown> | string; /** * Parses the cookie, if any, returning at minimum an empty object. * @param headers APIGatewayProxyEvent.headers */ export declare function parseCookie(headers: { [name: string]: string | undefined; }): { [name: string]: string; }; export declare function buildCookie(response: Response, maxAge?: number | undefined, expires?: Date | undefined, secure?: boolean, httpOnly?: boolean, sameSite?: 'strict' | 'lax' | 'none'): string[] | undefined; /** * Case-insensitive header lookup */ export declare function getHeader(name: string, headers: { [key: string]: string | undefined; } | undefined): string | undefined; /** * Case-insensitive header setting */ export declare function setHeader(name: string, value: string, headers: { [key: string]: string | undefined; } | undefined): void; export declare function parseRequest(event: APIGatewayProxyEvent): Request; export declare function matchRoute(routes: Routes, path: string): { methods: Route | undefined; params: { [name: string]: string; }; };