diff --git a/packages/core/workflows-sdk/src/utils/_playground.ts b/packages/core/workflows-sdk/src/utils/_playground.ts index 9f96a3e160c3e..94ce92494b2f2 100644 --- a/packages/core/workflows-sdk/src/utils/_playground.ts +++ b/packages/core/workflows-sdk/src/utils/_playground.ts @@ -30,8 +30,9 @@ const workflow = createWorkflow( } ) -workflow.hooks.something((input) => { +workflow.hooks.something((input, context) => { console.log("input>", input) + console.log("context>", context) }) workflow.run().then((res) => { diff --git a/packages/core/workflows-sdk/src/utils/composer/create-hook.ts b/packages/core/workflows-sdk/src/utils/composer/create-hook.ts index b9d68c2c61d86..f5fcb0b77558d 100644 --- a/packages/core/workflows-sdk/src/utils/composer/create-hook.ts +++ b/packages/core/workflows-sdk/src/utils/composer/create-hook.ts @@ -19,12 +19,12 @@ export type Hook = { } /** - * Expose a hook in your workflow where you can inject custom functionality as a step function. - * + * Expose a hook in your workflow where you can inject custom functionality as a step function. + * * A handler hook can later be registered to consume the hook and perform custom functionality. - * + * * Learn more in [this documentation](https://docs.medusajs.com/v2/advanced-development/workflows/add-workflow-hook). - * + * * @param name - The hook's name. This is used when the hook handler is registered to consume the workflow. * @param input - The input to pass to the hook handler. * @returns A workflow hook. @@ -37,16 +37,16 @@ export type Hook = { * WorkflowResponse, * } from "@medusajs/workflows-sdk" * import { createProductStep } from "./steps/create-product" - * + * * export const myWorkflow = createWorkflow( - * "my-workflow", + * "my-workflow", * function (input) { * const product = createProductStep(input) * const productCreatedHook = createHook( - * "productCreated", + * "productCreated", * { productId: product.id } * ) - * + * * return new WorkflowResponse(product, { * hooks: [productCreatedHook], * }) diff --git a/packages/core/workflows-sdk/src/utils/composer/type.ts b/packages/core/workflows-sdk/src/utils/composer/type.ts index 801a4128cbd2a..74615fd6fb242 100644 --- a/packages/core/workflows-sdk/src/utils/composer/type.ts +++ b/packages/core/workflows-sdk/src/utils/composer/type.ts @@ -32,7 +32,9 @@ export type HookHandler = (...args: any[]) => void | Promise type ConvertHooksToFunctions = { [K in keyof THooks]: THooks[K] extends Hook ? { - [Fn in Name]: (callback: (input: Input) => any) => void + [Fn in Name]: ( + callback: (input: Input, context: StepExecutionContext) => any + ) => void } : never }[number] @@ -218,9 +220,9 @@ export type ReturnWorkflow = { } & { /** * This method executes the workflow as a step. Useful when running a workflow within another. - * + * * Learn more in [this documentation](https://docs.medusajs.com/v2/advanced-development/workflows/execute-another-workflow). - * + * * @param param0 - The options to execute the workflow. * @returns The workflow's result */ @@ -234,7 +236,7 @@ export type ReturnWorkflow = { }) => ReturnType> /** * This method executes a workflow. - * + * * @param args - The options to execute the workflow. * @returns Details of the workflow's execution, including its result. */ @@ -255,7 +257,7 @@ export type ReturnWorkflow = { config: (config: TransactionModelOptions) => void /** * The workflow's exposed hooks, used to register a handler to consume the hook. - * + * * Learn more in [this documentation](https://docs.medusajs.com/v2/advanced-development/workflows/add-workflow-hook#how-to-consume-a-hook). */ hooks: ConvertHooksToFunctions