lambda-middleware icon indicating copy to clipboard operation
lambda-middleware copied to clipboard

Updated deserializeBody middleware to also work on APIGatewayProxyEventV2 event types

Open abmohan opened this issue 3 years ago • 5 comments

Closes #70

Checklist:

  • [x] I have updated the documentation accordingly. (nothing to update here)
  • [x] I have read the CONTRIBUTING document. (apologies if I missed something; please let me know if I did)

abmohan avatar Jul 06 '22 00:07 abmohan

CLA assistant check
All committers have signed the CLA.

CLAassistant avatar Jul 06 '22 00:07 CLAassistant

@dbartholomae took a stab at this. It's my first time making a PR to the repo and using the tooling (e.g., rush).

How does it look? Apologies if it's not the format and process you were looking for; I'm happy to revise as necessary.

Also, do we have a discord server available?

abmohan avatar Jul 07 '22 17:07 abmohan

Thanks! I'll take a closer look on the weekend :)

dbartholomae avatar Jul 07 '22 18:07 dbartholomae

Thanks for taking a stab at this! Unfortunately, I don't think it's this simple:

To be able to use the middleware with an APIGatewayProxyEventV2, the src/JsonDeserializer.ts would need to accept events that extend APIGatewayProxyEventV2, not only APIGatewayProxyEvent. I don't think changing only the internal types would make a difference.

Unfortunately this would mean that also the handler return type and the handler event type would need to be adjusted.

This becomes a bit complicated, because both types need to exist next to each other: If the incoming event is an APIGatewayProxyEvent, then the handler needs to get APIGatewayProxyObjectEvent<APIGatewayProxyEvent>, but if the incoming event is an APIGatewayProxyEventV2, then the handler needs to get APIGatewayProxyObjectEvent<APIGatewayProxyEventV2>.

I'm not sure how to best solve this off the back of my head. Ideally, we could reduce the required type to just the parts that are actually needed for the middleware, something like

{
    body?: string | null;
    headers?: Record<string, string>;
    isBase64Encoded: boolean;
  }

I haven't checked yet whether this would work, though.

dbartholomae avatar Jul 09 '22 15:07 dbartholomae

Cool makes sense. I'll take a stab at this later this week!

abmohan avatar Jul 11 '22 00:07 abmohan

This PR is stale because it has been open 60 days with no activity. Remove stale label or comment or this will be closed in 7 days.

github-actions[bot] avatar Sep 09 '22 01:09 github-actions[bot]