feat: Add emitEvent step + cleanup (#7643)

* feat: Add emitEvent step + cleanup

* fix typo

* fix typo
This commit is contained in:
Adrien de Peretti
2024-06-07 11:52:19 +02:00
committed by GitHub
parent 3cd2d60daa
commit 2e77a076b8
19 changed files with 178 additions and 117 deletions
@@ -11,7 +11,7 @@ describe("MessageAggregator", function () {
eventName: "ProductVariant.created",
body: {
metadata: {
service: "ProductService",
source: "ProductService",
action: "created",
object: "ProductVariant",
eventGroupId: "1",
@@ -23,7 +23,7 @@ describe("MessageAggregator", function () {
eventName: "Product.created",
body: {
metadata: {
service: "ProductService",
source: "ProductService",
action: "created",
object: "Product",
eventGroupId: "1",
@@ -35,7 +35,7 @@ describe("MessageAggregator", function () {
eventName: "ProductVariant.created",
body: {
metadata: {
service: "ProductService",
source: "ProductService",
action: "created",
object: "ProductVariant",
eventGroupId: "1",
@@ -47,7 +47,7 @@ describe("MessageAggregator", function () {
eventName: "ProductType.detached",
body: {
metadata: {
service: "ProductService",
source: "ProductService",
action: "detached",
object: "ProductType",
eventGroupId: "1",
@@ -59,7 +59,7 @@ describe("MessageAggregator", function () {
eventName: "ProductVariant.updated",
body: {
metadata: {
service: "ProductService",
source: "ProductService",
action: "updated",
object: "ProductVariant",
eventGroupId: "1",
@@ -87,7 +87,7 @@ describe("MessageAggregator", function () {
eventName: "ProductType.detached",
body: {
metadata: {
service: "ProductService",
source: "ProductService",
action: "detached",
object: "ProductType",
eventGroupId: "1",
@@ -102,7 +102,7 @@ describe("MessageAggregator", function () {
eventName: "ProductVariant.updated",
body: {
metadata: {
service: "ProductService",
source: "ProductService",
action: "updated",
object: "ProductVariant",
eventGroupId: "1",
@@ -117,7 +117,7 @@ describe("MessageAggregator", function () {
eventName: "ProductVariant.created",
body: {
metadata: {
service: "ProductService",
source: "ProductService",
action: "created",
object: "ProductVariant",
eventGroupId: "1",
@@ -129,7 +129,7 @@ describe("MessageAggregator", function () {
eventName: "ProductVariant.created",
body: {
metadata: {
service: "ProductService",
source: "ProductService",
action: "created",
object: "ProductVariant",
eventGroupId: "1",
@@ -144,7 +144,7 @@ describe("MessageAggregator", function () {
eventName: "Product.created",
body: {
metadata: {
service: "ProductService",
source: "ProductService",
action: "created",
object: "Product",
eventGroupId: "1",
@@ -12,14 +12,14 @@ export function composeMessage(
eventName: string,
{
data,
service,
source,
object,
action,
context = {},
options,
}: {
data: any
service: string
source: string
object: string
action?: string
context?: Context
@@ -34,7 +34,7 @@ export function composeMessage(
}
const metadata: EventBusTypes.MessageBody["metadata"] = {
service,
source,
object,
action: act!,
}
@@ -40,7 +40,7 @@ export class MessageAggregator implements IMessageAggregator {
const composedMessages = messages.map((message) => {
return composeMessage(message.eventName, {
data: message.data,
service: message.service,
source: message.source,
object: message.object,
action: message.action,
options,
@@ -5,7 +5,7 @@ import { Context, EventBusTypes } from "@medusajs/types"
*
* @example
* const createdFulfillment = eventBuilderFactory({
* service: Modules.FULFILLMENT,
* source: Modules.FULFILLMENT,
* action: CommonEvents.CREATED,
* object: "fulfillment",
* eventsEnum: FulfillmentEvents,
@@ -27,13 +27,13 @@ export function eventBuilderFactory({
action,
object,
eventsEnum,
service,
source,
}: {
isMainEntity?: boolean
action: string
object: string
eventsEnum: Record<string, string>
service: string
source: string
}) {
return function ({
data,
@@ -51,7 +51,7 @@ export function eventBuilderFactory({
data.forEach((dataItem) => {
messages.push({
service,
source,
action,
context: sharedContext,
data: { id: dataItem.id },