Skip to content

Commit 21acfeb

Browse files
committed
chore: update @middy/core + remove aws-lambda not needed in runtime
1 parent 3950f83 commit 21acfeb

File tree

4 files changed

+21
-208
lines changed

4 files changed

+21
-208
lines changed

packages/large-response-middleware/package.json

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@
4747
"@babel/preset-env": "^7.25.4",
4848
"@babel/preset-typescript": "^7.23.3",
4949
"@dazn/lambda-powertools-logger": "^1.28.1",
50-
"@middy/core": "^2.5.7",
50+
"@middy/core": "^3.6.2",
5151
"@rollup/plugin-babel": "^6.0.4",
5252
"@rollup/plugin-commonjs": "^25.0.7",
5353
"@rollup/plugin-json": "^6.1.0",
@@ -56,7 +56,6 @@
5656
"@size-limit/file": "^11.0.1",
5757
"@types/aws-lambda": "^8.10.130",
5858
"@types/node": "^20.10.5",
59-
"aws-lambda": "^1.0.7",
6059
"cross-env": "^7.0.3",
6160
"npm-run-all": "^4.1.5",
6261
"rollup": "^4.9.1",
@@ -72,8 +71,7 @@
7271
"@aws-sdk/client-s3": "^3.x",
7372
"@aws-sdk/s3-request-presigner": "^3.x",
7473
"@dazn/lambda-powertools-logger": "^1.28.1",
75-
"@middy/core": "^2.5.7",
76-
"aws-lambda": "^1.0.7"
74+
"@middy/core": ">=2.x"
7775
},
7876
"dependencies": {
7977
"core-js": "^3.34.0",

packages/large-response-middleware/src/index.test.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
/* eslint-disable @typescript-eslint/no-explicit-any */
22
import Log from '@dazn/lambda-powertools-logger';
3-
import type { APIGatewayProxyEventV2 } from 'aws-lambda';
3+
import type * as Lambda from 'aws-lambda';
44
import { beforeEach, describe, expect, it, vi } from 'vitest';
55

66
import { getOrgIdFromContext } from './__tests__/util';
@@ -191,7 +191,7 @@ describe('withLargeResponseHandler', () => {
191191
const middleware = withLargeResponseHandler({
192192
thresholdWarn: 0.5,
193193
thresholdError: 0.9,
194-
customErrorMessage: (event: APIGatewayProxyEventV2) =>
194+
customErrorMessage: (event: Lambda.APIGatewayProxyEventV2) =>
195195
`Custom error message for ${event.requestContext?.requestId}`,
196196
sizeLimitInMB: 1,
197197
outputBucket: 'the-bucket-list',
@@ -243,7 +243,7 @@ describe('withLargeResponseHandler', () => {
243243
headers: {
244244
Accept: LARGE_RESPONSE_MIME_TYPE,
245245
},
246-
} as Partial<APIGatewayProxyEventV2>,
246+
} as Partial<Lambda.APIGatewayProxyEventV2>,
247247
response: {
248248
headers: {
249249
random: Buffer.alloc(0.85 * 1024 * 1024, 'a').toString(), // 0.85MB
@@ -301,7 +301,7 @@ describe('withLargeResponseHandler', () => {
301301
headers: {
302302
'Handle-Large-Response': 'true',
303303
},
304-
} as Partial<APIGatewayProxyEventV2>,
304+
} as Partial<Lambda.APIGatewayProxyEventV2>,
305305
response: {
306306
headers: {
307307
random: Buffer.alloc(0.85 * 1024 * 1024, 'a').toString(), // 0.85MB

packages/large-response-middleware/src/index.ts

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import Log from '@dazn/lambda-powertools-logger';
22
import type middy from '@middy/core';
3-
import type { APIGatewayProxyEventV2, APIGatewayProxyStructuredResultV2 } from 'aws-lambda';
3+
import type * as Lambda from 'aws-lambda';
44
import yn from 'yn';
55

66
import { uploadFile } from './file-storage-service';
@@ -27,7 +27,7 @@ export type FileUploadContext = {
2727
fileName: string;
2828
};
2929

30-
export type CustomErrorMessage = string | ((event: APIGatewayProxyEventV2) => string);
30+
export type CustomErrorMessage = string | ((event: Lambda.APIGatewayProxyEventV2) => string);
3131

3232
export const withLargeResponseHandler = ({
3333
thresholdWarn,
@@ -42,13 +42,13 @@ export const withLargeResponseHandler = ({
4242
sizeLimitInMB: number;
4343
outputBucket: string;
4444
customErrorMessage?: CustomErrorMessage;
45-
groupRequestsBy?: (event: APIGatewayProxyEventV2) => string;
45+
groupRequestsBy?: (event: Lambda.APIGatewayProxyEventV2) => string;
4646
}) => {
4747
return {
4848
after: async (handlerRequestContext: middy.Request) => {
49-
const event = handlerRequestContext.event as APIGatewayProxyEventV2;
49+
const event = handlerRequestContext.event as Lambda.APIGatewayProxyEventV2;
5050
const requestHeaders = event?.headers || {};
51-
const response = handlerRequestContext.response as APIGatewayProxyStructuredResultV2;
51+
const response = handlerRequestContext.response as Lambda.APIGatewayProxyStructuredResultV2;
5252

5353
try {
5454
const groupId = groupRequestsBy?.(handlerRequestContext.event) || 'all';
@@ -187,7 +187,10 @@ export const safeUploadLargeResponse = async ({
187187
}
188188
};
189189

190-
function getCustomErrorMessage(customErrorMessage: CustomErrorMessage | undefined, event: APIGatewayProxyEventV2) {
190+
function getCustomErrorMessage(
191+
customErrorMessage: CustomErrorMessage | undefined,
192+
event: Lambda.APIGatewayProxyEventV2,
193+
) {
191194
return typeof customErrorMessage === 'function'
192195
? customErrorMessage(event)
193196
: (customErrorMessage ?? LARGE_RESPONSE_USER_INFO);

0 commit comments

Comments
 (0)