diff --git a/packages/core/core-flows/src/common/steps/emit-event.ts b/packages/core/core-flows/src/common/steps/emit-event.ts index 1ee3ddfb27..7eb102ab0a 100644 --- a/packages/core/core-flows/src/common/steps/emit-event.ts +++ b/packages/core/core-flows/src/common/steps/emit-event.ts @@ -2,18 +2,57 @@ import { EventBusTypes, IEventBusModuleService } from "@medusajs/types" import { ModuleRegistrationName } from "@medusajs/utils" import { StepExecutionContext, createStep } from "@medusajs/workflows-sdk" +/** + * The event's details. + */ type Input = { + /** + * The event's name. + */ eventName: string + /** + * Options to emit the event. + */ options?: Record + /** + * Metadata that the subscriber receives in the `metadata` property + * of its first parameter. + */ metadata?: Record + /** + * The data payload that the subscriber receives in the `data` property + * of its first parameter. Use this property to pass data relevant for the + * subscriber, such as the ID of a created record. + */ data: | ((context: StepExecutionContext) => Promise>) | Record } export const emitEventStepId = "emit-event-step" + /** - * @ignore + * Emit an event. + * + * @example + * import { + * createWorkflow + * } from "@medusajs/workflows-sdk" + * import { + * emitEventStep + * } from "@medusajs/core-flows" + * + * const helloWorldWorkflow = createWorkflow( + * "hello-world", + * () => { + * emitEventStep({ + * eventName: "custom.created", + * data: { + * id: "123" + * } + * }) + * } + * ) */ export const emitEventStep = createStep( emitEventStepId,