UNPKG

@bitblit/epsilon

Version:

Tiny adapter to simplify building API gateway Lambda APIS

50 lines (49 loc) 2.9 kB
import { APIGatewayEvent, APIGatewayEventRequestContext, AuthResponseContext } from 'aws-lambda'; import { EpsilonLoggerConfig } from '../config/epsilon-logger-config'; import { LoggerLevelName } from '@bitblit/ratchet/common'; import { BasicAuthToken } from './auth/basic-auth-token'; /** * Endpoints about the api itself */ export declare class EventUtil { private constructor(); static extractStage(event: APIGatewayEvent): string; static extractHostHeader(event: APIGatewayEvent): string; static extractProtocol(event: APIGatewayEvent): string; static extractApiGatewayStage(event: APIGatewayEvent): string; static extractRequestContext(event: APIGatewayEvent): APIGatewayEventRequestContext; static extractAuthorizer(event: APIGatewayEvent): AuthResponseContext; static ipAddressChain(event: APIGatewayEvent): string[]; static ipAddress(event: APIGatewayEvent): string; static extractFullPath(event: APIGatewayEvent, overrideProtocol?: string): string; static extractFullPrefix(event: APIGatewayEvent, overrideProtocol?: string): string; static jsonBodyToObject(event: APIGatewayEvent): any; static calcLogLevelViaEventOrEnvParam(curLevel: LoggerLevelName, event: APIGatewayEvent, rConfig: EpsilonLoggerConfig): LoggerLevelName; /** * This is a weird function - sometimes your customers will not decode their query params and it * results in query params that look like 'amp;SOMETHING' instead of 'SOMETHING'. This function * looks for params that look like that, and strips the amp; from them. If you have any * params you are expecting that have 'amp;' in front of them, DON'T use this function. * * Also, you are a moron for having a param that looks like that * * Yes, it would be better to fix this on the client side, but that is not always an option * in production * @param event */ static fixStillEncodedQueryParams(event: APIGatewayEvent): void; /** * Allows you to force in a token for an arbitrary event without having to pass the whole thing * through Epsilon. Useful for when you need to test a handler that needs authorization, * and don't need to instantiate all of epsilon, just the handler * @param event Event to decorate * @param jwtToken String containing a valid JWT token */ static applyTokenToEventForTesting(event: APIGatewayEvent, jwtToken: string): void; static extractBasicAuthenticationToken(event: APIGatewayEvent, throwErrorOnMissingBad?: boolean): BasicAuthToken; static eventIsAGraphQLIntrospection(event: APIGatewayEvent): boolean; static extractAuthorizationHeaderCaseInsensitive(evt: APIGatewayEvent): string; static extractBearerTokenFromEvent(evt: APIGatewayEvent): string; static hostIsLocal(host: string): boolean; static hostIsLocalOrNotRoutableIP4(host: string): boolean; }