feat: Add emitEvent step + cleanup (#7643)
* feat: Add emitEvent step + cleanup * fix typo * fix typo
This commit is contained in:
committed by
GitHub
parent
3cd2d60daa
commit
2e77a076b8
@@ -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"
|
||||
|
||||
41
packages/core/core-flows/src/common/steps/emit-event.ts
Normal file
41
packages/core/core-flows/src/common/steps/emit-event.ts
Normal 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) => {}
|
||||
)
|
||||
20
packages/core/core-flows/src/common/steps/release-event.ts
Normal file
20
packages/core/core-flows/src/common/steps/release-event.ts
Normal 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) => {}
|
||||
)
|
||||
Reference in New Issue
Block a user