@scloud/lambda-api
Version:
Lambda handler for API Gateway proxy requests
51 lines (50 loc) • 1.75 kB
TypeScript
import { APIGatewayProxyEvent } from 'aws-lambda';
import { Request, Route, Routes } from './types';
/**
* Ensures the path is lowercased, 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 header names are lowercased for ease of access.
* @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(values: {
[key: string]: string;
} | undefined): string[] | undefined;
export declare function parseRequest(event: APIGatewayProxyEvent): Request;
export declare function matchRoute(routes: Routes, path: string): {
route: Route | undefined;
params: {
[name: string]: string;
};
};