1- /* eslint-disable */
2- import * as lambda from 'aws-lambda' ;
31import logger from 'lambda-log' ;
4- /* eslint-enable */
52import * as errors from '../types/errors' ;
63import { ApiGatewayv2CognitoAuthorizer , AppSyncCognitoAuthorizer , CognitoAuthorizer } from './auth' ;
74
@@ -17,8 +14,8 @@ export interface HttpResponseContext {
1714}
1815
1916export interface HttpHandlerContext {
20- event : lambda . APIGatewayProxyEventV2 ;
21- lambdaContext : lambda . Context ;
17+ event : AWSLambda . APIGatewayProxyEventV2 ;
18+ lambdaContext : AWSLambda . Context ;
2219 logger : logger . LambdaLog ;
2320 response : HttpResponseContext ;
2421 cognitoAuth : CognitoAuthorizer ;
@@ -39,24 +36,26 @@ export interface Operation {
3936 } ;
4037}
4138
39+ export type APIGatewayv2Handler = AWSLambda . Handler < AWSLambda . APIGatewayProxyEventV2 , AWSLambda . APIGatewayProxyStructuredResultV2 | undefined > ;
40+
4241export interface OperationWithRequestBody extends Operation {
4342 requestBody : { content : { 'application/json' : any } } ;
4443}
4544
46- export const createOpenApiHandlerWithRequestBody = < OP extends OperationWithRequestBody , SC extends number = 200 > ( handler : HttpHandler < OP [ 'requestBody' ] [ 'content' ] [ 'application/json' ] , OP [ 'responses' ] [ SC ] [ 'application/json' ] > ) : lambda . Handler < lambda . APIGatewayProxyEventV2 , lambda . APIGatewayProxyStructuredResultV2 | undefined > => {
45+ export const createOpenApiHandlerWithRequestBody = < OP extends OperationWithRequestBody , SC extends number = 200 > ( handler : HttpHandler < OP [ 'requestBody' ] [ 'content' ] [ 'application/json' ] , OP [ 'responses' ] [ SC ] [ 'application/json' ] > ) : APIGatewayv2Handler => {
4746 return createHttpHandler ( handler ) ;
4847} ;
4948
50- export const createOpenApiHandlerWithRequestBodyNoResponse = < OP extends OperationWithRequestBody > ( handler : HttpHandler < OP [ 'requestBody' ] [ 'content' ] [ 'application/json' ] , void > ) : lambda . Handler < lambda . APIGatewayProxyEventV2 , lambda . APIGatewayProxyStructuredResultV2 | undefined > => {
49+ export const createOpenApiHandlerWithRequestBodyNoResponse = < OP extends OperationWithRequestBody > ( handler : HttpHandler < OP [ 'requestBody' ] [ 'content' ] [ 'application/json' ] , void > ) : APIGatewayv2Handler => {
5150 return createHttpHandler ( handler ) ;
5251} ;
5352
54- export const createOpenApiHandler = < OP extends Operation , SC extends number = 200 > ( handler : HttpHandler < any , OP [ 'responses' ] [ SC ] [ 'content' ] [ 'application/json' ] > ) : lambda . Handler < lambda . APIGatewayProxyEventV2 , lambda . APIGatewayProxyStructuredResultV2 | undefined > => {
53+ export const createOpenApiHandler = < OP extends Operation , SC extends number = 200 > ( handler : HttpHandler < any , OP [ 'responses' ] [ SC ] [ 'content' ] [ 'application/json' ] > ) : APIGatewayv2Handler => {
5554 return createHttpHandler ( handler ) ;
5655} ;
5756
5857export const createHttpHandler =
59- < T , R > ( handler : HttpHandler < T , R > ) : lambda . Handler < lambda . APIGatewayProxyEventV2 , lambda . APIGatewayProxyStructuredResultV2 | undefined > => {
58+ < T , R > ( handler : HttpHandler < T , R > ) : APIGatewayv2Handler => {
6059 return async ( event , context ) => {
6160 const ctx : HttpHandlerContext = {
6261 event,
@@ -109,15 +108,15 @@ export const createHttpHandler =
109108 } ;
110109 } ;
111110
112- function parseBody < T > ( event : lambda . APIGatewayProxyEventV2 ) : T {
111+ function parseBody < T > ( event : AWSLambda . APIGatewayProxyEventV2 ) : T {
113112 if ( ! event . body || ! event . isBase64Encoded ) {
114113 return JSON . parse ( event . body ?? '{}' ) ;
115114 }
116115 const buff = Buffer . from ( event . body , 'base64' ) ;
117116 return JSON . parse ( buff . toString ( 'utf8' ) ) ;
118117}
119118
120- function corsHeader ( event : lambda . APIGatewayProxyEventV2 ) : { [ name : string ] : string } {
119+ function corsHeader ( event : AWSLambda . APIGatewayProxyEventV2 ) : { [ name : string ] : string } {
121120 return {
122121 'Access-Control-Allow-Origin' : event ?. headers ?. origin ?? '*' ,
123122 'Access-Control-Allow-Credentials' : event ?. headers ?. origin ? 'true' : 'false' ,
@@ -131,8 +130,8 @@ function corsHeader(event: lambda.APIGatewayProxyEventV2): { [name: string]: str
131130/////////////////////////////////
132131
133132export interface AppSyncHandlerContext < T > {
134- event : lambda . AppSyncResolverEvent < T > ;
135- lambdaContext : lambda . Context ;
133+ event : AWSLambda . AppSyncResolverEvent < T > ;
134+ lambdaContext : AWSLambda . Context ;
136135 logger : logger . LambdaLog ;
137136 cognitoAuth : CognitoAuthorizer ;
138137}
@@ -142,7 +141,7 @@ export type AppSyncHandler<T, R> = (
142141) => Promise < R > ;
143142
144143export const createAppSyncHandler =
145- < T , R > ( handler : AppSyncHandler < T , R > ) : lambda . AppSyncResolverHandler < T , R > => {
144+ < T , R > ( handler : AppSyncHandler < T , R > ) : AWSLambda . AppSyncResolverHandler < T , R > => {
146145 return async ( event , context ) => {
147146 const ctx : AppSyncHandlerContext < T > = {
148147 event,
0 commit comments