Open dkarlovi opened 1 year ago
FYI we're prototyping this in our own repo, will PR if any of it makes sense.
@dkarlovi any update on this from your side?
I've implemented this on my project, would need to clean it up substantially to PR.
@dkarlovi ?
Currently, notification payloads are ad-hoc defined in
CoreShop\Bundle\CoreBundle\EventListener\NotificationRules
listeners andCoreShop\Bundle\NotificationBundle\Processor\EventedRuleProcessor
.The idea here is to streamline these payloads into a common structure which is easier to rely on if, for example, we dispatch these notifications to outside systems (think webhooks). One external example we can inspire oureselves from is Azure Alerts Common Schema or Cloud events.
Subject
The
$subject
is the object the notification is dealing with and it needs to be instance of\CoreShop\Component\Resource\Model\ResourceInterface
. Here's a list of current subject types across listeners:CustomerListener
CoreShop\Component\Core\Model\CustomerInterface
OrderCommentsListener
CoreShop\Component\Core\Model\OrderInterface
OrderDocumentWorkflowListener
CoreShop\Component\Order\Model\OrderDocumentInterface
OrderWorkflowListener
CoreShop\Component\Order\Model\OrderInterface
PaymentWorkflowListener
CoreShop\Component\Core\Model\PaymentInterface
It's obvious the subject is meant to be directly the resource we're talking about, that part is fine.
Rule Type
Rule type is the type of rules we want to apply, it's defined by the conditions and actions available for the type.
Currently available are:
user
,order
,shipment
,invoice
,payment
,quote
.Params
type
This is where we're getting to the crux of this issue, the inconsistencies between different rule appliers becomes visible here. Since the rule type defined above represents the rule type, not the event type, events are optionally named in the
$params
payload. This allows the conditions / actions to differentiate between different notifications triggered by the same rule, for example.Some of these are defined as consts (example in
CustomerListener
), some are hardcoded (example inOrderCommentsListener
), in some it's not set (example inOrderDocumentWorkflowListener
).This property should be be normalized and always defined.
DTO
My proposal is to introduce a DTO the purpose of which is to solve these common scenarios and streamline the params payload.
The proposed DTO schema is as follows:
The "reference" in the description would mean either an object or a reasonable (serializeable) representation of the object in question, most probably always looking like
but used consistently.
Example usage: own password reset
Example usage: password reset on behalf of customer
Example usage: order comment
Example usage: order document
Example usage: order workflow
Example usage: payment workflow