Skip to content

Commit 3ee7ab6

Browse files
committed
fix: lambda type imports
1 parent a12a784 commit 3ee7ab6

File tree

2 files changed

+16
-20
lines changed

2 files changed

+16
-20
lines changed

src/http/auth.ts

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,4 @@
11
import { env } from 'process';
2-
/* eslint-disable */
3-
import { APIGatewayProxyEventV2, AppSyncIdentityCognito, AppSyncResolverEvent } from 'aws-lambda';
4-
/* eslint-enable */
52
import Axios from 'axios';
63
import { verify, JwtHeader, SigningKeyCallback } from 'jsonwebtoken';
74
// import jwkToPem = require('jwk-to-pem');
@@ -122,7 +119,7 @@ export abstract class CognitoAuthorizer {
122119

123120
export class ApiGatewayv2CognitoAuthorizer extends CognitoAuthorizer {
124121

125-
constructor(protected event: APIGatewayProxyEventV2, private _logger: logger.LambdaLog) {
122+
constructor(protected event: AWSLambda.APIGatewayProxyEventV2, private _logger: logger.LambdaLog) {
126123
super();
127124
}
128125

@@ -157,13 +154,13 @@ export class ApiGatewayv2CognitoAuthorizer extends CognitoAuthorizer {
157154

158155
export class AppSyncCognitoAuthorizer extends CognitoAuthorizer {
159156

160-
constructor(protected event: AppSyncResolverEvent<any>) {
157+
constructor(protected event: AWSLambda.AppSyncResolverEvent<any>) {
161158
super();
162159
}
163160

164161
public async authenticate(): Promise<void> {
165162
if (this.event.identity) {
166-
this.claims = (this.event.identity as AppSyncIdentityCognito).claims;
163+
this.claims = (this.event.identity as AWSLambda.AppSyncIdentityCognito).claims;
167164
}
168165
}
169166

src/http/handler.ts

Lines changed: 13 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,4 @@
1-
/* eslint-disable */
2-
import * as lambda from 'aws-lambda';
31
import logger from 'lambda-log';
4-
/* eslint-enable */
52
import * as errors from '../types/errors';
63
import { ApiGatewayv2CognitoAuthorizer, AppSyncCognitoAuthorizer, CognitoAuthorizer } from './auth';
74

@@ -17,8 +14,8 @@ export interface HttpResponseContext {
1714
}
1815

1916
export 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+
4241
export 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

5857
export 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

133132
export 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

144143
export 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

Comments
 (0)