UNPKG

cassava

Version:
184 lines (183 loc) 5.93 kB
import * as jsonschema from "jsonschema"; /** * Input to the HTTP router. Based on the ProxyEvent but enriched. */ export declare class RouterEvent { /** * API Gateway event context. * @link https://docs.aws.amazon.com/apigateway/latest/developerguide/set-up-lambda-proxy-integrations.html#api-gateway-simple-proxy-for-lambda-input-format */ requestContext: { accountId: string; apiId: string; authorizer?: { [name: string]: any; }; httpMethod: string; identity: { accessKey: string; apiKey: string; accountId: string; apiKeyId: string; caller: string; cognitoAuthenticationProvider: string; cognitoAuthenticationType: string; cognitoIdentityId: string; cognitoIdentityPoolId: string; sourceIp: string; user: string; userAgent: string; userArn: string; }; path: string; requestId: string; requestTimeEpoch: number; resourceId: string; resourcePath: string; stage: string; }; /** * Parsed Cookie header. */ cookies: { [name: string]: string; }; /** * Request body (JSON.parsed if possible). */ body: any; /** * Unparsed request body. */ bodyRaw: any; /** * All headers of the request with only the first value. They are stored here in their original * form but the spec requires that header keys are treated as case-insensitive. * Use `headersLowerCase` for easier retrieval. */ headers: { [key: string]: string; }; /** * All headers of the request with only the first value, keys in lower case. */ headersLowerCase: { [key: string]: string; }; /** * All headers of the request including all values. They are stored here in their original * form but the spec requires that header keys are treated as case-insensitive. * Use `multiValueHeadersLowerCase` for easier retrieval. */ multiValueHeaders: { [key: string]: string[]; }; /** * All headers of the request including all values, keys in lower case. */ multiValueHeadersLowerCase: { [key: string]: string[]; }; /** * GET, POST, PUT, etc... */ httpMethod: string; /** * A work area for Routes to add properties to. This can be used * to sneak information from routes that preprocess to later routes; * for example auth credentials. */ meta: { [name: string]: any; }; /** * The request URI path. eg: /foo/bar */ path: string; /** * The parsed URI path parameters. */ pathParameters: { [key: string]: string; }; /** * The parsed URI query parameters with only their first value. */ queryStringParameters: { [key: string]: string; }; /** * The parsed URI query parameters including all values. */ multiValueQueryStringParameters: { [key: string]: string[]; }; /** * Configuration attributes associated with a deployment stage of an API. */ stageVariables: { [key: string]: string; }; /** * Require that the given query parameter is set. * If the parameter is not set a RestError is thrown. */ requireQueryStringParameter(param: string): void; /** * Require that the given query parameter is set and has * one of the given values. If the parameter is not set or * does not take on one of the given values a RestError is thrown. */ requireQueryStringParameter(param: string, values: string[], explanation?: string): void; /** * Require that the given query parameter is set and satisfies * the validator function. If the parameter is not set or * does not satisfy the given validator function a RestError is thrown. */ requireQueryStringParameter(param: string, validator: (value: string) => boolean, explanation?: string): void; /** * Require that the given query parameters are *not* set. * If any parameter in this list is set a RestError is thrown. */ blacklistQueryStringParameters(...params: string[]): void; /** * Require that only the given query parameters are set. No parameter * in this list has to be set, but if any parameter is set that is not in * this list a RestError will be thrown. */ whitelistQueryStringParameters(...params: string[]): void; /** * Require that the given header field is set. */ requireHeader(field: string): void; /** * Require that the given header field is set and has * one of the given values. */ requireHeader(field: string, values: string[], explanation?: string): void; /** * Require that the given header field is set and satisfies * the validator function. */ requireHeader(field: string, validator: (value: string) => boolean, explanation?: string): void; /** * Validate the body of the request using JSON Schema. * * JSON Schema is a concise way to define a valid JSON object. * The spec and examples can be found at http://json-schema.org/ * with additional help at * https://spacetelescope.github.io/understanding-json-schema/index.html . * * The actual implementation comes from https://github.com/tdegrunt/jsonschema . */ validateBody(schema: jsonschema.Schema, options?: ValidateBodyOptions): void; } /** * RouterEvent.validateBody() options. Extends jsonschema.validate() Options. */ export interface ValidateBodyOptions extends jsonschema.Options { /** * The HTTP status code to use for validation errors. Defaults to 422. */ httpStatusCode?: number; }