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

[WebHooks] - expose allowed webhook events in webhook store #16835

Merged
merged 24 commits into from
Jun 2, 2023

Conversation

jhoward1994
Copy link
Contributor

@jhoward1994 jhoward1994 commented May 25, 2023

What does it do?

Changes how we store and validate webhook events in the backend
Storing them in strapi.webhookStore.allowedEvents
Adds relevant events from the upload plugin and ee directory

Why is it needed?

Making webhooks more modular, allowing plugins to extend the webhook store

Related issue(s)/PR(s)

CONTENT-1451

@jhoward1994 jhoward1994 self-assigned this May 25, 2023
@jhoward1994 jhoward1994 added the pr: enhancement This PR adds or updates some part of the codebase or features label May 25, 2023
@jhoward1994
Copy link
Contributor Author

@Marc-Roig & @nathan-pichon - This PR amends the BE of the webhooks as we discussed the other day

Do you think it's okay to merge this first and handle the emitting of the review workflow events in a separate PR?

Copy link
Contributor

@Marc-Roig Marc-Roig left a comment

Choose a reason for hiding this comment

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

nice work on webhooks 🚀

Added some minor comments, and just to throw my random thought
await this.emitEvent(strapi.webhookStore.allowedEvents.get('MEDIA_UPDATE'), res);

I was trying to think shorter ways to get the event name, because I feel it's a bit too much, but other than using a constant in each package I can't think of anything else 🤔

@Marc-Roig
Copy link
Contributor

@Marc-Roig & @nathan-pichon - This PR amends the BE of the webhooks as we discussed the other day
Do you think it's okay to merge this first and handle the emitting of the review workflow events in a separate PR?

Yes :) I think is the best approach to do that

@Marc-Roig Marc-Roig added the source: core:strapi Source is core/strapi package label May 26, 2023
@jhoward1994
Copy link
Contributor Author

@Marc-Roig & @nathan-pichon this is ready for another review now 🙏🏻

@jhoward1994
Copy link
Contributor Author

Hey @nathan-pichon & @Marc-Roig sorry for the delay this is ready for review again.

The only thing I'm unsure of is whether the entity service events should be registered in the bootstrap phase like other plugins or from the entity service. wdyt?

For other plugins I had to register them in the bootstrap phase as the services aren't initialised until you're using the plugin - e.g. having navigated to the upload plugin

@nathan-pichon
Copy link
Member

The Entity service is responsible for the business code around entities, so, it makes sense that the Entity service put its own event in the webhook module.
But it can also be considered a setup and placed in a bootstrap phase.

I would say that the second option is better, as a service should be capable of being instantiated multiple times (we might not want to add events each time the service is instantiated, even if the map will just overwrite the overlapping events).
Can a service have a bootstrap phase? 🤔 I mean, for now, we do not have any. But it might be something to consider in the future.

@Marc-Roig
Copy link
Contributor

as of today bootstrap is referred to a lifecycle of a package, so I guess services do not have that.

What we can do today is execute code before initialising as you are doing in the PR already. I actually think that is ok, as a service does not really need a register/bootstrap/destroy lifecycle.

@jhoward1994
Copy link
Contributor Author

as of today bootstrap is referred to a lifecycle of a package, so I guess services do not have that.

What we can do today is execute code before initialising as you are doing in the PR already. I actually think that is ok, as a service does not really need a register/bootstrap/destroy lifecycle.

okay, happy to go with this implementation then. I was unsure as it will make the entity service inconsistent with how we register events elsewhere

nathan-pichon
nathan-pichon previously approved these changes Jun 1, 2023
Comment on lines 18 to 21
const event = ALLOWED_WEBHOOK_EVENTS[eventName];
if (!event) {
throw new ApplicationError(`The webhook event ${eventName} doesn't exist.`);
}
Copy link
Contributor

@Marc-Roig Marc-Roig Jun 1, 2023

Choose a reason for hiding this comment

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

why do we need this?

could we export from constants something like this:

const { ENTRY_PUBLISH, ENTRY_UNPUBLISH } = require('../constants/webhooks');

I think we could do something as before, but importing those webhook events from the package constants.

Sorry for the back and forth, just want to make sure this is as clean as possible!

Copy link
Contributor Author

Choose a reason for hiding this comment

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

No worries that's a good point, I've addressed it in c53b7a7 (#16835)

Copy link
Contributor

@Marc-Roig Marc-Roig left a comment

Choose a reason for hiding this comment

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

Good job 🚀🚀🚀🚀

@jhoward1994 jhoward1994 added this to the 4.11.0 milestone Jun 2, 2023
@jhoward1994 jhoward1994 merged commit ca1ed38 into main Jun 2, 2023
54 checks passed
@jhoward1994 jhoward1994 deleted the feature/set-webhook-events branch June 2, 2023 10:00
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
pr: enhancement This PR adds or updates some part of the codebase or features source: core:strapi Source is core/strapi package
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants