-
Notifications
You must be signed in to change notification settings - Fork 106
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Improve aws-lambda webhookCallback adapter #418
Improve aws-lambda webhookCallback adapter #418
Conversation
Codecov ReportPatch coverage:
Additional details and impacted files@@ Coverage Diff @@
## main #418 +/- ##
==========================================
- Coverage 39.01% 38.88% -0.14%
==========================================
Files 16 16
Lines 4831 4850 +19
Branches 194 194
==========================================
+ Hits 1885 1886 +1
- Misses 2944 2962 +18
Partials 2 2
☔ View full report in Codecov by Sentry. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks! I assume that this closes #412?
Regarding the tests: it's very hard to write tests for adapters without just mocking all the APIs. But since they may change in unexpected ways anyway, there's little reason to test these few lines of code automatically. I trust your manual tests (and the community to complain if stuff breaks).
Did you test it by installing grammY from this branch using GitHub installs?
7e30e21
to
d992906
Compare
I tested it on a node.js side project by switching grammy from the npm version to the fork I have on disk, which I built with |
Could you try once more using |
@KnorpelSenf Installing with npm directly from the branch doesn't seem to work because there is a build step to generate the
Let me know if you think more tests/changes are needed, and I will try to get to them in the coming days. |
Update regarding the In short, it seem we can't just pick one. I updated the PR to address this behavior. Let me know what you think. |
8720f8d
to
9e9a10f
Compare
That is very strange. If you install this package with npm from this repo, then it should run the prepare script after installation. This will run the backporting script. I'm surprised it doesn't work that way on your end …
So do you think we should add a new adapter for SST? |
src/convenience/frameworks.ts
Outdated
let resolveResponse: (response: unknown) => void; | ||
let handlerReturn: Promise<unknown> | undefined; | ||
|
||
if (callback) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It seems to me like you actually have two different adapters here that you're trying to support—one that passes a callback and one that doesn't. Why is this branching even necessary? Wouldn't it be much cleaner to have one adapter for every environment?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
AWS lambdas support both ways, so that is not uncommon for middleware, plugins, and extensions aimed at it.
My intention was to keep the legacy behavior while adding support for the modern format.
That being said, separating it as a new adapter is also an alternative. Maybe call it aws-lambda-async
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, that sounds good!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just to confirm: you think it is best to have a new adapter called aws-lambda-async
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes. For every call signature there's exactly one adapter.
For comparison, check the two cloudflare adapters. One is for module workers, and one is for legacy workers.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I will look into it soon. Should all the changes be extracted to the new aws-lambda-async
(leaving the current one unchanged) or are the headers changes being applied to the current one as well?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Does the current one have a problem with secret tokens? You can fix it if that's the case. If there's no problem, there's no need to touch the code.
No, not really. Since posting that comment I've done more tests and some research and posted my findings here. |
9e9a10f
to
5504c0c
Compare
Have you actually encountered a non-lowercase header for a grammY bot on AWS? |
During my tests, no. If you think it is ok to look only for the lowercase version, fine by me, I was just avoiding introducing breaking behavior. |
It's good to be cautious about that. In this particular case, I'm fine with using the lowercase header name only. I see no way how it could change from request to request. If I'm wrong, it will be reliable to reproduce and simple to fix. |
Ah, I see what happened. Grammy's setup currently doesn't support being installed from git using |
Can we merge? Is there anything left to test or to fix? |
Ah nvm, we're waiting for #418 (comment) |
5504c0c
to
60d8216
Compare
All done! |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you so much!
@all-contributors add @chrisandrewcl for code |
I've put up a pull request to add @chrisandrewcl! 🎉 |
Changes:
I did not find any relevant test cases covering adapters, so I am opening this PR with just a few manual tests.