Skip to content

Commit

Permalink
docs(email-plugin): Add example for new setMetadata method
Browse files Browse the repository at this point in the history
  • Loading branch information
michaelbromley committed Jul 22, 2024
1 parent ac0baf9 commit a835b3f
Showing 1 changed file with 21 additions and 1 deletion.
22 changes: 21 additions & 1 deletion packages/email-plugin/src/handler/event-handler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -250,7 +250,27 @@ export class EmailEventHandler<T extends string = string, Event extends EventWit

/**
* @description
* A function which allows {@link EmailMetadata} to be specified for the email.
* A function which allows {@link EmailMetadata} to be specified for the email. This can be used
* to store arbitrary data about the email which can be used for tracking or other purposes.
*
* It will be exposed in the {@link EmailSendEvent} as `event.metadata`. Here's an example of usage:
*
* - An {@link OrderStateTransitionEvent} occurs, and the EmailEventListener starts processing it.
* - The EmailEventHandler attaches metadata to the email:
* ```ts
* new EmailEventListener(EventType.ORDER_CONFIRMATION)
* .on(OrderStateTransitionEvent)
* .setMetadata(event => ({
* type: EventType.ORDER_CONFIRMATION,
* orderId: event.order.id,
* }));
* ```
* - Then, the EmailPlugin tries to send the email and publishes {@link EmailSendEvent},
* passing ctx, emailDetails, error or success, and this metadata.
* - In another part of the server, we have an eventBus that subscribes to EmailSendEvent. We can use
* `metadata.type` and `metadata.orderId` to identify the related order. For example, we can indicate on the
* order that the email was successfully sent, or in case of an error, send a notification confirming
* the order in another available way.
*
* @since 3.1.0
*/
Expand Down

0 comments on commit a835b3f

Please sign in to comment.