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

View File

@@ -1,6 +1,7 @@
export * from "./steps/create-remote-links"
export * from "./steps/dismiss-remote-links"
export * from "./steps/remove-remote-links"
export * from "./steps/emit-event"
export * from "./steps/use-remote-query"
export * from "./workflows/batch-links"
export * from "./workflows/create-links"

View File

@@ -0,0 +1,41 @@
import { composeMessage, ModuleRegistrationName } from "@medusajs/utils"
import { createStep, StepExecutionContext } from "@medusajs/workflows-sdk"
type Input = {
eventName: string
source: string
object: string
action?: string
options?: Record<string, any>
data: (
context: StepExecutionContext
) => Promise<Record<any, any>> | Record<any, any>
}
export const emitEventStepId = "emit-event-step"
export const emitEventStep = createStep(
emitEventStepId,
async (input: Input, context) => {
if (!input) {
return
}
const { container } = context
const eventBus = container.resolve(ModuleRegistrationName.EVENT_BUS)
const data_ =
typeof input.data === "function" ? await input.data(context) : input.data
const message = composeMessage(input.eventName, {
data: data_,
action: input.action ?? "",
object: input.object,
source: input.source,
options: input.options,
context,
})
await eventBus.emit([message])
},
async (data: void) => {}
)

View File

@@ -0,0 +1,20 @@
import { ModuleRegistrationName } from "@medusajs/utils"
import { createStep } from "@medusajs/workflows-sdk"
export const releaseEventsStepId = "release-events-step"
export const releaseEventsStep = createStep(
releaseEventsStepId,
async (
input: void,
{
container,
metadata: {
/* eventGroupId */
},
}
) => {
const eventBus = container.resolve(ModuleRegistrationName.EVENT_BUS)
// await eventBus.release
},
async (data: void) => {}
)

View File

@@ -27,7 +27,7 @@ export type EmitData<T = unknown> = {
export type MessageBody<T = unknown> = {
metadata: {
service: string
source: string
action: string
object: string
eventGroupId?: string
@@ -44,7 +44,7 @@ export type Message<T = unknown> = {
export type RawMessageFormat<T = any> = {
eventName: string
data: T
service: string
source: string
object: string
action?: string
context?: Pick<Context, "eventGroupId">

View File

@@ -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",

View File

@@ -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!,
}

View File

@@ -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,

View File

@@ -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 },

View File

@@ -14,7 +14,7 @@ export function buildExpectedEventMessageShape(options: {
metadata: {
action: options.action,
eventGroupId: options.eventGroupId,
service: "fulfillment",
source: "fulfillment",
object: options.object,
},
data: options.data,

View File

@@ -17,154 +17,154 @@ import {
export const eventBuilders = {
createdFulfillment: eventBuilderFactory({
service: Modules.FULFILLMENT,
source: Modules.FULFILLMENT,
action: CommonEvents.CREATED,
object: "fulfillment",
eventsEnum: FulfillmentEvents,
}),
updatedFulfillment: eventBuilderFactory({
service: Modules.FULFILLMENT,
source: Modules.FULFILLMENT,
action: CommonEvents.UPDATED,
object: "fulfillment",
eventsEnum: FulfillmentEvents,
}),
createdFulfillmentAddress: eventBuilderFactory({
service: Modules.FULFILLMENT,
source: Modules.FULFILLMENT,
action: CommonEvents.CREATED,
object: "fulfillment_address",
eventsEnum: FulfillmentEvents,
}),
createdFulfillmentItem: eventBuilderFactory({
service: Modules.FULFILLMENT,
source: Modules.FULFILLMENT,
action: CommonEvents.CREATED,
object: "fulfillment_item",
eventsEnum: FulfillmentEvents,
}),
createdFulfillmentLabel: eventBuilderFactory({
service: Modules.FULFILLMENT,
source: Modules.FULFILLMENT,
action: CommonEvents.CREATED,
object: "fulfillment_label",
eventsEnum: FulfillmentEvents,
}),
updatedFulfillmentLabel: eventBuilderFactory({
service: Modules.FULFILLMENT,
source: Modules.FULFILLMENT,
action: CommonEvents.UPDATED,
object: "fulfillment_label",
eventsEnum: FulfillmentEvents,
}),
deletedFulfillmentLabel: eventBuilderFactory({
service: Modules.FULFILLMENT,
source: Modules.FULFILLMENT,
action: CommonEvents.DELETED,
object: "fulfillment_label",
eventsEnum: FulfillmentEvents,
}),
createdShippingProfile: eventBuilderFactory({
service: Modules.FULFILLMENT,
source: Modules.FULFILLMENT,
action: CommonEvents.CREATED,
object: "shipping_profile",
eventsEnum: FulfillmentEvents,
}),
createdShippingOptionType: eventBuilderFactory({
service: Modules.FULFILLMENT,
source: Modules.FULFILLMENT,
action: CommonEvents.CREATED,
object: "shipping_option_type",
eventsEnum: FulfillmentEvents,
}),
updatedShippingOptionType: eventBuilderFactory({
service: Modules.FULFILLMENT,
source: Modules.FULFILLMENT,
action: CommonEvents.UPDATED,
object: "shipping_option_type",
eventsEnum: FulfillmentEvents,
}),
deletedShippingOptionType: eventBuilderFactory({
service: Modules.FULFILLMENT,
source: Modules.FULFILLMENT,
action: CommonEvents.DELETED,
object: "shipping_option_type",
eventsEnum: FulfillmentEvents,
}),
createdShippingOptionRule: eventBuilderFactory({
service: Modules.FULFILLMENT,
source: Modules.FULFILLMENT,
action: CommonEvents.CREATED,
object: "shipping_option_rule",
eventsEnum: FulfillmentEvents,
}),
updatedShippingOptionRule: eventBuilderFactory({
service: Modules.FULFILLMENT,
source: Modules.FULFILLMENT,
action: CommonEvents.UPDATED,
object: "shipping_option_rule",
eventsEnum: FulfillmentEvents,
}),
deletedShippingOptionRule: eventBuilderFactory({
service: Modules.FULFILLMENT,
source: Modules.FULFILLMENT,
action: CommonEvents.DELETED,
object: "shipping_option_rule",
eventsEnum: FulfillmentEvents,
}),
createdShippingOption: eventBuilderFactory({
service: Modules.FULFILLMENT,
source: Modules.FULFILLMENT,
action: CommonEvents.CREATED,
object: "shipping_option",
eventsEnum: FulfillmentEvents,
}),
updatedShippingOption: eventBuilderFactory({
service: Modules.FULFILLMENT,
source: Modules.FULFILLMENT,
action: CommonEvents.UPDATED,
object: "shipping_option",
eventsEnum: FulfillmentEvents,
}),
createdFulfillmentSet: eventBuilderFactory({
service: Modules.FULFILLMENT,
source: Modules.FULFILLMENT,
action: CommonEvents.CREATED,
object: "fulfillment_set",
isMainEntity: true,
eventsEnum: FulfillmentEvents,
}),
updatedFulfillmentSet: eventBuilderFactory({
service: Modules.FULFILLMENT,
source: Modules.FULFILLMENT,
action: CommonEvents.UPDATED,
object: "fulfillment_set",
isMainEntity: true,
eventsEnum: FulfillmentEvents,
}),
deletedFulfillmentSet: eventBuilderFactory({
service: Modules.FULFILLMENT,
source: Modules.FULFILLMENT,
action: CommonEvents.DELETED,
object: "fulfillment_set",
isMainEntity: true,
eventsEnum: FulfillmentEvents,
}),
createdServiceZone: eventBuilderFactory({
service: Modules.FULFILLMENT,
source: Modules.FULFILLMENT,
action: CommonEvents.CREATED,
object: "service_zone",
eventsEnum: FulfillmentEvents,
}),
updatedServiceZone: eventBuilderFactory({
service: Modules.FULFILLMENT,
source: Modules.FULFILLMENT,
action: CommonEvents.UPDATED,
object: "service_zone",
eventsEnum: FulfillmentEvents,
}),
deletedServiceZone: eventBuilderFactory({
service: Modules.FULFILLMENT,
source: Modules.FULFILLMENT,
action: CommonEvents.DELETED,
object: "service_zone",
eventsEnum: FulfillmentEvents,
}),
createdGeoZone: eventBuilderFactory({
service: Modules.FULFILLMENT,
source: Modules.FULFILLMENT,
action: CommonEvents.CREATED,
object: "geo_zone",
eventsEnum: FulfillmentEvents,
}),
updatedGeoZone: eventBuilderFactory({
service: Modules.FULFILLMENT,
source: Modules.FULFILLMENT,
action: CommonEvents.UPDATED,
object: "geo_zone",
eventsEnum: FulfillmentEvents,
}),
deletedGeoZone: eventBuilderFactory({
service: Modules.FULFILLMENT,
source: Modules.FULFILLMENT,
action: CommonEvents.DELETED,
object: "geo_zone",
eventsEnum: FulfillmentEvents,

View File

@@ -10,17 +10,17 @@ import {
ReservationItemDTO,
} from "@medusajs/types"
import {
arrayDifference,
CommonEvents,
EmitEvents,
InjectManager,
InjectTransactionManager,
InventoryEvents,
isDefined,
isString,
MedusaContext,
MedusaError,
ModulesSdkUtils,
arrayDifference,
isDefined,
isString,
partitionArray,
promiseAll,
} from "@medusajs/utils"
@@ -241,7 +241,7 @@ export default class InventoryModuleService<
context.messageAggregator?.saveRawMessageData(
created.map((reservationItem) => ({
eventName: InventoryEvents.reservation_item_created,
service: this.constructor.name,
source: this.constructor.name,
action: CommonEvents.CREATED,
object: "reservation-item",
context,
@@ -340,7 +340,7 @@ export default class InventoryModuleService<
context.messageAggregator?.saveRawMessageData(
result.map((inventoryItem) => ({
eventName: InventoryEvents.created,
service: this.constructor.name,
source: this.constructor.name,
action: CommonEvents.CREATED,
object: "inventory-item",
context,
@@ -393,7 +393,7 @@ export default class InventoryModuleService<
context.messageAggregator?.saveRawMessageData(
created.map((inventoryLevel) => ({
eventName: InventoryEvents.inventory_level_created,
service: this.constructor.name,
source: this.constructor.name,
action: CommonEvents.CREATED,
object: "inventory-level",
context,
@@ -453,7 +453,7 @@ export default class InventoryModuleService<
context.messageAggregator?.saveRawMessageData(
result.map((inventoryItem) => ({
eventName: InventoryEvents.updated,
service: this.constructor.name,
source: this.constructor.name,
action: CommonEvents.UPDATED,
object: "inventory-item",
context,
@@ -492,7 +492,7 @@ export default class InventoryModuleService<
context.messageAggregator?.saveRawMessageData(
result[0].map((inventoryLevel) => ({
eventName: InventoryEvents.inventory_level_deleted,
service: this.constructor.name,
source: this.constructor.name,
action: CommonEvents.DELETED,
object: "inventory-level",
context,
@@ -523,7 +523,7 @@ export default class InventoryModuleService<
context.messageAggregator?.saveRawMessageData({
eventName: InventoryEvents.inventory_level_deleted,
service: this.constructor.name,
source: this.constructor.name,
action: CommonEvents.DELETED,
object: "inventory-level",
context,
@@ -565,7 +565,7 @@ export default class InventoryModuleService<
context.messageAggregator?.saveRawMessageData(
levels.map((inventoryLevel) => ({
eventName: InventoryEvents.inventory_level_updated,
service: this.constructor.name,
source: this.constructor.name,
action: CommonEvents.UPDATED,
object: "inventory-level",
context,
@@ -648,7 +648,7 @@ export default class InventoryModuleService<
context.messageAggregator?.saveRawMessageData(
result.map((reservationItem) => ({
eventName: InventoryEvents.inventory_level_updated,
service: this.constructor.name,
source: this.constructor.name,
action: CommonEvents.UPDATED,
object: "reservation-item",
context,
@@ -801,7 +801,7 @@ export default class InventoryModuleService<
context.messageAggregator?.saveRawMessageData(
reservations.map((reservationItem) => ({
eventName: InventoryEvents.reservation_item_deleted,
service: this.constructor.name,
source: this.constructor.name,
action: CommonEvents.DELETED,
object: "reservation-item",
context,
@@ -843,7 +843,7 @@ export default class InventoryModuleService<
context.messageAggregator?.saveRawMessageData(
reservations.map((reservationItem) => ({
eventName: InventoryEvents.reservation_item_deleted,
service: this.constructor.name,
source: this.constructor.name,
action: CommonEvents.DELETED,
object: "reservation-item",
context,
@@ -880,7 +880,7 @@ export default class InventoryModuleService<
context.messageAggregator?.saveRawMessageData(
reservations.map((reservationItem) => ({
eventName: InventoryEvents.reservation_item_created,
service: this.constructor.name,
source: this.constructor.name,
action: CommonEvents.CREATED,
object: "reservation-item",
context,
@@ -949,7 +949,7 @@ export default class InventoryModuleService<
context.messageAggregator?.saveRawMessageData({
eventName: InventoryEvents.inventory_level_updated,
service: this.constructor.name,
source: this.constructor.name,
action: CommonEvents.UPDATED,
object: "inventory-level",
context,

View File

@@ -13,12 +13,12 @@ import {
CommonEvents,
InjectManager,
InjectTransactionManager,
isDefined,
mapObjectTo,
MapToConfig,
MedusaContext,
MedusaError,
ModulesSdkUtils,
isDefined,
mapObjectTo,
} from "@medusajs/utils"
import { LinkService } from "@services"
import { shouldForceTransaction } from "../utils"
@@ -210,7 +210,7 @@ export default class LinkModuleService<TLink> implements ILinkModule {
eventName: this.entityName_ + "." + CommonEvents.ATTACHED,
body: {
metadata: {
service: this.serviceName_,
source: this.serviceName_,
action: CommonEvents.ATTACHED,
object: this.entityName_,
eventGroupId: sharedContext.eventGroupId,
@@ -263,7 +263,7 @@ export default class LinkModuleService<TLink> implements ILinkModule {
eventName: this.entityName_ + "." + CommonEvents.DETACHED,
body: {
metadata: {
service: this.serviceName_,
source: this.serviceName_,
action: CommonEvents.DETACHED,
object: this.entityName_,
eventGroupId: sharedContext.eventGroupId,
@@ -314,7 +314,7 @@ export default class LinkModuleService<TLink> implements ILinkModule {
eventName: this.entityName_ + "." + CommonEvents.DETACHED,
body: {
metadata: {
service: this.serviceName_,
source: this.serviceName_,
action: CommonEvents.DETACHED,
object: this.entityName_,
eventGroupId: sharedContext.eventGroupId,
@@ -374,7 +374,7 @@ export default class LinkModuleService<TLink> implements ILinkModule {
eventName: this.entityName_ + "." + CommonEvents.ATTACHED,
body: {
metadata: {
service: this.serviceName_,
source: this.serviceName_,
action: CommonEvents.ATTACHED,
object: this.entityName_,
eventGroupId: sharedContext.eventGroupId,

View File

@@ -508,7 +508,7 @@ moduleIntegrationTestRunner({
expect(events).toHaveLength(4)
expect(events[0]).toEqual(
composeMessage(PricingEvents.price_list_created, {
service: Modules.PRICING,
source: Modules.PRICING,
action: CommonEvents.CREATED,
object: "price_list",
data: { id: priceList.id },
@@ -516,7 +516,7 @@ moduleIntegrationTestRunner({
)
expect(events[1]).toEqual(
composeMessage(PricingEvents.price_list_rule_created, {
service: Modules.PRICING,
source: Modules.PRICING,
action: CommonEvents.CREATED,
object: "price_list_rule",
data: { id: priceList.price_list_rules?.[0].id },
@@ -524,7 +524,7 @@ moduleIntegrationTestRunner({
)
expect(events[2]).toEqual(
composeMessage(PricingEvents.price_list_rule_created, {
service: Modules.PRICING,
source: Modules.PRICING,
action: CommonEvents.CREATED,
object: "price_list_rule",
data: { id: priceList.price_list_rules?.[1].id },
@@ -532,7 +532,7 @@ moduleIntegrationTestRunner({
)
expect(events[3]).toEqual(
composeMessage(PricingEvents.price_created, {
service: Modules.PRICING,
source: Modules.PRICING,
action: CommonEvents.CREATED,
object: "price",
data: { id: priceList.prices![0].id },
@@ -867,7 +867,7 @@ moduleIntegrationTestRunner({
expect(events).toHaveLength(2)
expect(events[0]).toEqual(
composeMessage(PricingEvents.price_created, {
service: Modules.PRICING,
source: Modules.PRICING,
action: CommonEvents.CREATED,
object: "price",
data: { id: priceList.prices![0].id },
@@ -875,7 +875,7 @@ moduleIntegrationTestRunner({
)
expect(events[1]).toEqual(
composeMessage(PricingEvents.price_rule_created, {
service: Modules.PRICING,
source: Modules.PRICING,
action: CommonEvents.CREATED,
object: "price_rule",
data: { id: priceList.prices![0].price_rules![0].id },

View File

@@ -12,7 +12,7 @@ import {
} from "medusa-test-utils"
import { PriceSetRuleType } from "../../../../src"
import { seedPriceData } from "../../../__fixtures__/seed-price-data"
import { CommonEvents, PricingEvents, composeMessage } from "@medusajs/utils"
import { CommonEvents, composeMessage, PricingEvents } from "@medusajs/utils"
jest.setTimeout(30000)
@@ -446,7 +446,7 @@ moduleIntegrationTestRunner({
expect(events).toHaveLength(3)
expect(events[0]).toEqual(
composeMessage(PricingEvents.price_set_created, {
service: Modules.PRICING,
source: Modules.PRICING,
action: CommonEvents.CREATED,
object: "price_set",
data: { id: priceSet.id },
@@ -455,7 +455,7 @@ moduleIntegrationTestRunner({
expect(events[1]).toEqual(
composeMessage(PricingEvents.price_created, {
service: Modules.PRICING,
source: Modules.PRICING,
action: CommonEvents.CREATED,
object: "price",
data: { id: priceSet.prices![0].id },
@@ -464,7 +464,7 @@ moduleIntegrationTestRunner({
expect(events[2]).toEqual(
composeMessage(PricingEvents.price_rule_created, {
service: Modules.PRICING,
source: Modules.PRICING,
action: CommonEvents.CREATED,
object: "price_rule",
data: {
@@ -694,7 +694,7 @@ moduleIntegrationTestRunner({
expect(events).toHaveLength(2)
expect(events[0]).toEqual(
composeMessage(PricingEvents.price_created, {
service: Modules.PRICING,
source: Modules.PRICING,
action: CommonEvents.CREATED,
object: "price",
data: { id: priceSet.prices![1].id },
@@ -702,7 +702,7 @@ moduleIntegrationTestRunner({
)
expect(events[1]).toEqual(
composeMessage(PricingEvents.price_rule_created, {
service: Modules.PRICING,
source: Modules.PRICING,
action: CommonEvents.CREATED,
object: "price_rule",
data: { id: priceSet.prices![1].price_rules[0].id },

View File

@@ -1,50 +1,49 @@
import {} from "@models"
import {
Modules,
CommonEvents,
PricingEvents,
eventBuilderFactory,
Modules,
PricingEvents,
} from "@medusajs/utils"
export const eventBuilders = {
createdPriceSet: eventBuilderFactory({
service: Modules.PRICING,
source: Modules.PRICING,
action: CommonEvents.CREATED,
object: "price_set",
eventsEnum: PricingEvents,
}),
createdPriceSetRuleType: eventBuilderFactory({
service: Modules.PRICING,
source: Modules.PRICING,
action: CommonEvents.CREATED,
object: "price_set_rule_type",
eventsEnum: PricingEvents,
}),
createdPrice: eventBuilderFactory({
service: Modules.PRICING,
source: Modules.PRICING,
action: CommonEvents.CREATED,
object: "price",
eventsEnum: PricingEvents,
}),
createdPriceRule: eventBuilderFactory({
service: Modules.PRICING,
source: Modules.PRICING,
action: CommonEvents.CREATED,
object: "price_rule",
eventsEnum: PricingEvents,
}),
createdPriceList: eventBuilderFactory({
service: Modules.PRICING,
source: Modules.PRICING,
action: CommonEvents.CREATED,
object: "price_list",
eventsEnum: PricingEvents,
}),
createdPriceListRule: eventBuilderFactory({
service: Modules.PRICING,
source: Modules.PRICING,
action: CommonEvents.CREATED,
object: "price_list_rule",
eventsEnum: PricingEvents,
}),
attachedPriceListRule: eventBuilderFactory({
service: Modules.PRICING,
source: Modules.PRICING,
action: CommonEvents.ATTACHED,
object: "price_list_rule",
eventsEnum: PricingEvents,

View File

@@ -279,7 +279,7 @@ moduleIntegrationTestRunner<IProductModuleService>({
composeMessage(ProductEvents.product_tag_updated, {
data: { id: productTag.id },
object: "product_tag",
service: Modules.PRODUCT,
source: Modules.PRODUCT,
action: CommonEvents.UPDATED,
}),
])
@@ -321,7 +321,7 @@ moduleIntegrationTestRunner<IProductModuleService>({
composeMessage(ProductEvents.product_tag_created, {
data: { id: productTag[0].id },
object: "product_tag",
service: Modules.PRODUCT,
source: Modules.PRODUCT,
action: CommonEvents.CREATED,
}),
])
@@ -375,13 +375,13 @@ moduleIntegrationTestRunner<IProductModuleService>({
composeMessage(ProductEvents.product_tag_created, {
data: { id: newTag.id },
object: "product_tag",
service: Modules.PRODUCT,
source: Modules.PRODUCT,
action: CommonEvents.CREATED,
}),
composeMessage(ProductEvents.product_tag_updated, {
data: { id: updatedTag.id },
object: "product_tag",
service: Modules.PRODUCT,
source: Modules.PRODUCT,
action: CommonEvents.UPDATED,
}),
])

View File

@@ -211,7 +211,7 @@ moduleIntegrationTestRunner<IProductModuleService>({
composeMessage(ProductEvents.product_variant_updated, {
data: { id: variantOne.id },
object: "product_variant",
service: Modules.PRODUCT,
source: Modules.PRODUCT,
action: CommonEvents.UPDATED,
}),
])
@@ -241,7 +241,7 @@ moduleIntegrationTestRunner<IProductModuleService>({
composeMessage(ProductEvents.product_variant_updated, {
data: { id: variantOne.id },
object: "product_variant",
service: Modules.PRODUCT,
source: Modules.PRODUCT,
action: CommonEvents.UPDATED,
}),
])
@@ -312,7 +312,7 @@ moduleIntegrationTestRunner<IProductModuleService>({
composeMessage(ProductEvents.product_variant_created, {
data: { id: variant.id },
object: "product_variant",
service: Modules.PRODUCT,
source: Modules.PRODUCT,
action: CommonEvents.CREATED,
}),
])

View File

@@ -7,94 +7,94 @@ import {
export const eventBuilders = {
createdProduct: eventBuilderFactory({
service: Modules.PRODUCT,
source: Modules.PRODUCT,
action: CommonEvents.CREATED,
object: "product",
eventsEnum: ProductEvents,
isMainEntity: true,
}),
updatedProduct: eventBuilderFactory({
service: Modules.PRODUCT,
source: Modules.PRODUCT,
action: CommonEvents.UPDATED,
object: "product",
eventsEnum: ProductEvents,
isMainEntity: true,
}),
deletedProduct: eventBuilderFactory({
service: Modules.PRODUCT,
source: Modules.PRODUCT,
action: CommonEvents.DELETED,
object: "product",
eventsEnum: ProductEvents,
isMainEntity: true,
}),
createdProductVariant: eventBuilderFactory({
service: Modules.PRODUCT,
source: Modules.PRODUCT,
action: CommonEvents.CREATED,
object: "product_variant",
eventsEnum: ProductEvents,
}),
updatedProductVariant: eventBuilderFactory({
service: Modules.PRODUCT,
source: Modules.PRODUCT,
action: CommonEvents.UPDATED,
object: "product_variant",
eventsEnum: ProductEvents,
}),
deletedProductVariant: eventBuilderFactory({
service: Modules.PRODUCT,
source: Modules.PRODUCT,
action: CommonEvents.DELETED,
object: "product_variant",
eventsEnum: ProductEvents,
}),
createdProductOption: eventBuilderFactory({
service: Modules.PRODUCT,
source: Modules.PRODUCT,
action: CommonEvents.CREATED,
object: "product_option",
eventsEnum: ProductEvents,
}),
updatedProductOption: eventBuilderFactory({
service: Modules.PRODUCT,
source: Modules.PRODUCT,
action: CommonEvents.UPDATED,
object: "product_option",
eventsEnum: ProductEvents,
}),
deletedProductOption: eventBuilderFactory({
service: Modules.PRODUCT,
source: Modules.PRODUCT,
action: CommonEvents.DELETED,
object: "product_option",
eventsEnum: ProductEvents,
}),
createdProductType: eventBuilderFactory({
service: Modules.PRODUCT,
source: Modules.PRODUCT,
action: CommonEvents.CREATED,
object: "product_type",
eventsEnum: ProductEvents,
}),
updatedProductType: eventBuilderFactory({
service: Modules.PRODUCT,
source: Modules.PRODUCT,
action: CommonEvents.UPDATED,
object: "product_type",
eventsEnum: ProductEvents,
}),
deletedProductType: eventBuilderFactory({
service: Modules.PRODUCT,
source: Modules.PRODUCT,
action: CommonEvents.DELETED,
object: "product_type",
eventsEnum: ProductEvents,
}),
createdProductTag: eventBuilderFactory({
service: Modules.PRODUCT,
source: Modules.PRODUCT,
action: CommonEvents.CREATED,
object: "product_tag",
eventsEnum: ProductEvents,
}),
updatedProductTag: eventBuilderFactory({
service: Modules.PRODUCT,
source: Modules.PRODUCT,
action: CommonEvents.UPDATED,
object: "product_tag",
eventsEnum: ProductEvents,
}),
deletedProductTag: eventBuilderFactory({
service: Modules.PRODUCT,
source: Modules.PRODUCT,
action: CommonEvents.DELETED,
object: "product_tag",
eventsEnum: ProductEvents,

View File

@@ -94,7 +94,7 @@ export default class UserModuleService<
sharedContext.messageAggregator?.saveRawMessageData(
invites.map((invite) => ({
eventName: UserEvents.invite_token_generated,
service: this.constructor.name,
source: this.constructor.name,
action: "token_generated",
object: "invite",
context: sharedContext,
@@ -149,7 +149,7 @@ export default class UserModuleService<
sharedContext.messageAggregator?.saveRawMessageData(
users.map((user) => ({
eventName: UserEvents.created,
service: this.constructor.name,
source: this.constructor.name,
action: CommonEvents.CREATED,
object: "user",
context: sharedContext,
@@ -188,7 +188,7 @@ export default class UserModuleService<
sharedContext.messageAggregator?.saveRawMessageData(
updatedUsers.map((user) => ({
eventName: UserEvents.updated,
service: this.constructor.name,
source: this.constructor.name,
action: CommonEvents.UPDATED,
object: "user",
context: sharedContext,
@@ -227,7 +227,7 @@ export default class UserModuleService<
sharedContext.messageAggregator?.saveRawMessageData(
invites.map((invite) => ({
eventName: UserEvents.invite_created,
service: this.constructor.name,
source: this.constructor.name,
action: CommonEvents.CREATED,
object: "invite",
context: sharedContext,
@@ -238,7 +238,7 @@ export default class UserModuleService<
sharedContext.messageAggregator?.saveRawMessageData(
invites.map((invite) => ({
eventName: UserEvents.invite_token_generated,
service: this.constructor.name,
source: this.constructor.name,
action: "token_generated",
object: "invite",
context: sharedContext,
@@ -296,7 +296,7 @@ export default class UserModuleService<
sharedContext.messageAggregator?.saveRawMessageData(
serializedInvites.map((invite) => ({
eventName: UserEvents.invite_updated,
service: this.constructor.name,
source: this.constructor.name,
action: CommonEvents.UPDATED,
object: "invite",
context: sharedContext,