diff --git a/.changeset/violet-bikes-develop.md b/.changeset/violet-bikes-develop.md new file mode 100644 index 0000000000..1205290c94 --- /dev/null +++ b/.changeset/violet-bikes-develop.md @@ -0,0 +1,5 @@ +--- +"@medusajs/workflows-sdk": patch +--- + +Added idempotencyKey to workflow step context diff --git a/packages/workflows-sdk/src/utils/composer/create-step.ts b/packages/workflows-sdk/src/utils/composer/create-step.ts index 8d8cc6c423..7b3f0bde01 100644 --- a/packages/workflows-sdk/src/utils/composer/create-step.ts +++ b/packages/workflows-sdk/src/utils/composer/create-step.ts @@ -122,6 +122,11 @@ function applyStep< const handler = { invoke: async (transactionContext) => { const executionContext: StepExecutionContext = { + workflowId: transactionContext.model_id, + stepName: transactionContext.action, + action: "invoke", + idempotencyKey: transactionContext.idempotency_key, + attempt: transactionContext.attempt, container: transactionContext.container, metadata: transactionContext.metadata, context: transactionContext.context, @@ -148,6 +153,11 @@ function applyStep< compensate: compensateFn ? async (transactionContext) => { const executionContext: StepExecutionContext = { + workflowId: transactionContext.model_id, + stepName: transactionContext.action, + action: "compensate", + idempotencyKey: transactionContext.idempotency_key, + attempt: transactionContext.attempt, container: transactionContext.container, metadata: transactionContext.metadata, context: transactionContext.context, diff --git a/packages/workflows-sdk/src/utils/composer/hook.ts b/packages/workflows-sdk/src/utils/composer/hook.ts index 1dd8324455..1576a08a1d 100644 --- a/packages/workflows-sdk/src/utils/composer/hook.ts +++ b/packages/workflows-sdk/src/utils/composer/hook.ts @@ -110,6 +110,11 @@ export function hook( return { __value: async function (transactionContext) { const executionContext: StepExecutionContext = { + workflowId: transactionContext.model_id, + stepName: transactionContext.action, + action: transactionContext.action_type, + idempotencyKey: transactionContext.idempotency_key, + attempt: transactionContext.attempt, container: transactionContext.container, metadata: transactionContext.metadata, context: transactionContext.context, diff --git a/packages/workflows-sdk/src/utils/composer/type.ts b/packages/workflows-sdk/src/utils/composer/type.ts index d61c004fdf..91f9e2b296 100644 --- a/packages/workflows-sdk/src/utils/composer/type.ts +++ b/packages/workflows-sdk/src/utils/composer/type.ts @@ -86,6 +86,31 @@ export type CreateWorkflowComposerContext = { * The step's context. */ export interface StepExecutionContext { + /** + * The ID of the workflow. + */ + workflowId: string + + /** + * The attempt number of the step. + */ + attempt: number + + /** + * The idempoency key of the step. + */ + idempotencyKey: string + + /** + * The name of the step. + */ + stepName: string + + /** + * The action of the step. + */ + action: "invoke" | "compensate" + /** * The container used to access resources, such as services, in the step. */