import FindMyWay, { Handler, HTTPVersion, HTTPMethod, RouteOptions } from 'find-my-way'; import { StatusCodes } from 'readable-http-codes'; import * as pino from 'pino'; import { Logger } from 'pino'; import { LambdaRequestTrackerOptions, lambdaRequestTracker } from 'pino-lambda'; import { RequireAllOrNone, Promisable } from 'type-fest'; import { Buffer } from 'node:buffer'; type RouterInstance = ReturnType>; interface FMWRoute { handler: Handler; method: HTTPMethod; path: string; pattern?: string; params: string[]; opts?: RouteOptions; store?: Record; } type Plugin, PluginOptions = any> = (instance: Instance, options: PluginOptions) => any; type HandlerEvent = Record & RequireAllOrNone<{ version: string; routeKey: string; rawPath: string; rawQueryString: string; headers: { [key: string]: string; 'accept-encoding': string; 'host': string; 'user-agent': string; 'via': string; 'x-amz-cf-id': string; 'x-amzn-trace-id': string; 'x-forwarded-for': string; 'x-forwarded-port': string; 'x-forwarded-proto': string; }; requestContext: { accountId: string; apiId: string; domainName: string; domainPrefix: string; http: { method: string; path: string; protocol: string; sourceIp: string; userAgent: string; }; requestId: string; routeKey: string; stage: string; time: string; timeEpoch: number; }; isBase64Encoded: boolean; }> & RequireAllOrNone<{ Records: HandlerEventRecord[]; }>; type HandlerEventRecord = Record & RequireAllOrNone<{ eventVersion: string; eventSource: string; awsRegion: string; eventTime: string; eventName: string; userIdentity: any | { principalId: string; }; requestParameters: any | { sourceIPAddress: string; }; responseElements: any; [key: string]: any; }>; interface HandlerContext { callbackWaitsForEmptyEventLoop: boolean; functionName: string; functionVersion: string; invokedFunctionArn: string; memoryLimitInMB: string; awsRequestId: string; logGroupName: string; logStreamName: string; identity?: any | undefined; clientContext?: any | undefined; getRemainingTimeInMillis: () => number; } interface HandlerResponse { headers?: { [key: string]: any; }; cookies?: string[]; statusCode?: number; body?: any; isBase64Encoded?: boolean; [key: string]: any; } interface VoieEventInterfaceAdapter { route: { method: Route['method']; path: Route['path']; params: Record; cookies?: Record; }; } interface EventRoute { eventSource: string; name: string; handler: (record: HandlerEventRecord, context: HandlerContext) => any; befores: MiddlewareBefore[]; afters: MiddlewareAfter[]; before: (fn: MiddlewareBefore) => this; after: (fn: MiddlewareAfter) => this; } interface Route extends Pick { handler: LambdaHandler; befores: MiddlewareBefore[]; afters: MiddlewareAfter[]; before: (fn: MiddlewareBefore) => this; after: (fn: MiddlewareAfter) => this; } type MiddlewareBefore = (data: D, context: HandlerContext) => Promisable; type MiddlewareAfter = (data: D, context: HandlerContext, res: HandlerResponse) => Promisable; type LambdaHandler = (event: EventInterface, context: HandlerContext) => Promisable | any; interface RouterConstructOptions { /** * Pass in your custom logger if needed. */ logger?: Logger; /** * Options for `pino-lambda`'s withRequest(), could be disabled with falsy values. */ withRequestOptions?: LambdaRequestTrackerOptions; } declare function fakeEvent(method: Route['method'], path: Route['path'], spread?: Record): HandlerEvent; declare function tryIt any, D = any>(fn: F, fallbackValue?: D): ReturnType | D | undefined; declare class DetailedError extends Error { /** * Additional message that will be logged AND returned to client */ detail?: any; /** * Additional code that will be logged AND returned to client */ code?: any; /** * Additional object that will be logged AND NOT returned to client */ log?: any; /** * Optionally set the status code to return */ statusCode?: any; constructor(message: string, options?: { detail?: any; code?: any; statusCode?: number; log?: any; }); } declare function eventMethodUrl(event: HandlerEvent): { method: string; url: string; }; /** * This utility picks the follow keys from the event: routeKey, rawPath, rawQueryString, headers, requestContext, isBase64Encoded * * @param {boolean} [options.minimal] - pick only necessary contexts for a response call, that is: routeKey, rawPath, headers, requestContext.http.method * @returns */ declare function pickEventContext(event: HandlerEvent, options?: { minimal?: boolean; }): Pick | { requestContext: { http: { method: string; }; }; routeKey: string; rawPath: string; headers: { [key: string]: string; 'accept-encoding': string; host: string; 'user-agent': string; via: string; 'x-amz-cf-id': string; 'x-amzn-trace-id': string; 'x-forwarded-for': string; 'x-forwarded-port': string; 'x-forwarded-proto': string; }; }; /** * Compress inputted data, `response` could be passed in to mutate it. */ declare function compress(data: any, options?: { response?: HandlerResponse; acceptEncoding?: string; level?: number; }): { encoding: string; data: Buffer; }; declare function decompress(compressedData: string | Buffer, options: { contentEncoding: string; }): string; declare function decodeBody(body: any): any; /** * Helper to decompress and parse the response's body if needed */ declare function decodeResponse(response: R): R; declare const logger: pino.Logger<{ level: "debug" | "info"; base: undefined; }>; declare class Router { EventInterface: EventInterface; RouteInterface: Route; __pluginData__: Record; $event?: EventInterface; logger: Logger; withRequest?: ReturnType; router: RouterInstance; routes: Record; eventRoutes: Record>; allowEmptyRouteLookup: boolean; constructor(options?: RouterConstructOptions); use

>(plugin: P, options?: Parameters

[1]): this; getDefaultRoute(): any; setDefaultRoute(handler: this['RouteInterface']['handler'], passThrough?: boolean): void; eventRoute(eventSource: EventRoute['eventSource'], name: EventRoute['name']): EventRoute | undefined; eventRoute(eventSource: EventRoute['eventSource'], name: EventRoute['name'], handler: EventRoute['handler'], options?: { override?: boolean; }): EventRoute; route(method: this['RouteInterface']['method'], path: this['RouteInterface']['path']): this['RouteInterface'] | undefined; route(method: this['RouteInterface']['method'], path: this['RouteInterface']['path'], handler: this['RouteInterface']['handler'], options?: { override?: boolean; }): this['RouteInterface']; routeHandler(route: this['RouteInterface'], data: EventInterface, context: HandlerContext): Promisable | any; routeHandler(route: EventRoute, data: HandlerEventRecord, context: HandlerContext): Promisable | any; _routeHandler(route: this['RouteInterface'] | EventRoute, data: EventInterface | HandlerEventRecord, context: HandlerContext): Promise; handle(): LambdaHandler; _lookupShims(event: EventInterface, context?: HandlerContext): ReturnType; _lookupTransform(fn: (lookupData: { method: string; path: string; event: EventInterface; context: HandlerContext; params: { [k: string]: string | undefined; }; searchParams: { [k: string]: string; }; }) => any): FMWRoute['handler']; makePassThrough(handler: this['RouteInterface']['handler']): FindMyWay.Handler; makeOnHandler(route: this['RouteInterface']): FindMyWay.Handler; makeLambdaHandler(): LambdaHandler; processRecordHandler(handler: EventRoute['handler'], record: HandlerEventRecord, context: HandlerContext): Promise; } declare class Voie extends Router { EventInterface: EventInterface; RouteInterface: Route; autoCorsCheck(event: EventInterface): boolean; response(statusCode: StatusCodes, body: any, options?: { event?: EventInterface; headers?: Record; cookies?: Record | Array; autoAllow?: boolean; autoCors?: boolean; compress?: false | 'auto' | number; contentType?: string | false; }): HandlerResponse; } export { DetailedError, type EventRoute, type FMWRoute, type HandlerContext, type HandlerEvent, type HandlerEventRecord, type HandlerResponse, type LambdaHandler, type MiddlewareAfter, type MiddlewareBefore, type Plugin, type Route, Router, type RouterConstructOptions, type RouterInstance, Voie, type VoieEventInterfaceAdapter, compress, decodeBody, decodeResponse, decompress, eventMethodUrl, fakeEvent, logger, pickEventContext, tryIt };