Skip to content
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

Merged
merged 7 commits into from
Feb 1, 2024
Merged

Webhook get and resend APIs #2021

merged 7 commits into from
Feb 1, 2024

Conversation

mjh1
Copy link
Contributor

@mjh1 mjh1 commented Jan 24, 2024

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)

  • I had to move the storeResponse function outside of the cannon object so that it could be called by the newly written resendWebhook function.
  • I moved the webhook log API handlers to a separate file for better organisation.

How did you test each of these updates (required)

Tested locally and wrote a unit test.

Checklist

  • I have read the CONTRIBUTING document.
  • My change requires a change to the documentation.
  • I have updated the documentation accordingly.
  • I have added tests to cover my changes.

Copy link

vercel bot commented Jan 24, 2024

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated (UTC)
livepeer-studio ✅ Ready (Inspect) Visit Preview 💬 Add feedback Feb 1, 2024 10:36am

@mjh1
Copy link
Contributor Author

mjh1 commented Jan 24, 2024

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.

@mjh1
Copy link
Contributor Author

mjh1 commented Jan 24, 2024

Just realised I need to add the new API paths to api-schema.yaml

@victorges
Copy link
Member

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.

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

@mjh1
Copy link
Contributor Author

mjh1 commented Jan 25, 2024

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.

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! 👀

@mjh1 mjh1 force-pushed the mh/webhook-resend branch from 658336d to 5fccbb3 Compare January 25, 2024 12:21
@mjh1
Copy link
Contributor Author

mjh1 commented Jan 25, 2024

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

Done 👍 the first commit is the one with the real changes, the next two are just moving code around

@mjh1
Copy link
Contributor Author

mjh1 commented Jan 25, 2024

@victorges ready for review now

@mjh1 mjh1 changed the title webhook resend Webhook get and resend APIs Jan 26, 2024
Copy link
Member

@victorges victorges left a 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) => {
Copy link
Member

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 🤔

Copy link
Contributor Author

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?

Copy link
Member

@victorges victorges Jan 31, 2024

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

Comment on lines 308 to 309
const webhook = await db.webhook.get(req.params.id);
const webhookResponse = await db.webhookResponse.get(req.params.requestId);
Copy link
Member

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

Copy link
Contributor Author

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
Copy link
Member

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

@mjh1 mjh1 requested a review from victorges January 31, 2024 16:19
@mjh1
Copy link
Contributor Author

mjh1 commented Jan 31, 2024

@victorges would you mind just sanity checking the last two commits? thanks!

Copy link
Member

@victorges victorges left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

great

sharedSecret: sharedSecret,
};
await db.webhookResponse.create(webhookResponse);
return webhookResponse;
} catch (e) {
Copy link
Member

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

Copy link
Contributor Author

@mjh1 mjh1 Feb 1, 2024

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

@mjh1 mjh1 merged commit d93c77c into master Feb 1, 2024
10 checks passed
@mjh1 mjh1 deleted the mh/webhook-resend branch February 1, 2024 10:37
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants