-
Notifications
You must be signed in to change notification settings - Fork 33
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
Webhook get and resend APIs #2021
Conversation
The latest updates on your projects. Learn more about Vercel for Git ↗︎
|
0aebcf9
to
7d2c05a
Compare
Annoyingly this PR looks bigger than it really is, I had to move some code around so lots of deletes and additions of the same lines. |
Just realised I need to add the new API paths to api-schema.yaml |
If it'd be easy to separate the moving around on a separate commit, it'd be easier to review! no problem if it's not trivial tho |
I'll try! 👀 |
7d2c05a
to
658336d
Compare
658336d
to
5fccbb3
Compare
Done 👍 the first commit is the one with the real changes, the next two are just moving code around |
@victorges ready for review now |
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.
LGTM either way but I have some functional suggestions/discussions (and some less important non-functional/nits)
Reviewed commit by commit (thanks!), so some comments may be in the initial places where the code was written
@@ -287,9 +295,45 @@ const requestsFieldsMap: FieldsMap = { | |||
statusCode: `webhook_response.data->'response'->>'status'`, | |||
}; | |||
|
|||
app.put("/:id/log/:requestId/resend", authorizer({}), async (req, res) => { |
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.
Should this be a POST
instead? Unless we somehow keep the same requestId
when we resend, but I guess we don't 🤔
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.
So you're suggesting POST /:id/log/resend
with the requestID in the request body?
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.
No, I think POST /:id/log/:requestId/resend
is fine! It's just that a PUT .../:requestId
would seem like it's updating the same request/log, instead of creating a new one. Also I think the general pattern for "actions" (in this case "resend") is to be a POST
as well
const webhook = await db.webhook.get(req.params.id); | ||
const webhookResponse = await db.webhookResponse.get(req.params.requestId); |
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.
Something funny here is that the id
and requestId
params are redundant right? I wonder if we'll ever need an API which is just /webhook/log/:requestId
instead, but let's keep it like this for now I think it's consistent with standards
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.
Yeah I wasn't too sure which way was preferable
$ref: "#/components/schemas/error" | ||
"/webhook/{id}/log/{logId}/resend": | ||
put: | ||
summary: Resend a webhook |
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 might be worth some further description:
about what this API does
@victorges would you mind just sanity checking the last two commits? thanks! |
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.
great
packages/api/src/webhooks/cannon.ts
Outdated
sharedSecret: sharedSecret, | ||
}; | ||
await db.webhookResponse.create(webhookResponse); | ||
return webhookResponse; | ||
} catch (e) { |
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.
Perhaps we should rethrow this error now, otherwise the API will respond with a 200
and an "undefined" body
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 moved the catch into the main firehook function where it's still needed. hopefully that looks good to you 9490476?w=1
What does this pull request do? Explain your changes. (required)
Implements get and resend APIs for webhook logs. So now you can retrieve info for a single webhook log and trigger a resend.
Specific updates (required)
storeResponse
function outside of the cannon object so that it could be called by the newly writtenresendWebhook
function.How did you test each of these updates (required)
Tested locally and wrote a unit test.
Checklist