feat(workflows-sdk): additional properties to context (#6760)

This commit is contained in:
Carlos R. L. Rodrigues
2024-03-20 17:59:03 +01:00
committed by GitHub
parent 20243e22ee
commit 3ca957ec0f
4 changed files with 45 additions and 0 deletions
+5
View File
@@ -0,0 +1,5 @@
---
"@medusajs/workflows-sdk": patch
---
Added idempotencyKey to workflow step context
@@ -122,6 +122,11 @@ function applyStep<
const handler = { const handler = {
invoke: async (transactionContext) => { invoke: async (transactionContext) => {
const executionContext: StepExecutionContext = { const executionContext: StepExecutionContext = {
workflowId: transactionContext.model_id,
stepName: transactionContext.action,
action: "invoke",
idempotencyKey: transactionContext.idempotency_key,
attempt: transactionContext.attempt,
container: transactionContext.container, container: transactionContext.container,
metadata: transactionContext.metadata, metadata: transactionContext.metadata,
context: transactionContext.context, context: transactionContext.context,
@@ -148,6 +153,11 @@ function applyStep<
compensate: compensateFn compensate: compensateFn
? async (transactionContext) => { ? async (transactionContext) => {
const executionContext: StepExecutionContext = { const executionContext: StepExecutionContext = {
workflowId: transactionContext.model_id,
stepName: transactionContext.action,
action: "compensate",
idempotencyKey: transactionContext.idempotency_key,
attempt: transactionContext.attempt,
container: transactionContext.container, container: transactionContext.container,
metadata: transactionContext.metadata, metadata: transactionContext.metadata,
context: transactionContext.context, context: transactionContext.context,
@@ -110,6 +110,11 @@ export function hook<TOutput>(
return { return {
__value: async function (transactionContext) { __value: async function (transactionContext) {
const executionContext: StepExecutionContext = { const executionContext: StepExecutionContext = {
workflowId: transactionContext.model_id,
stepName: transactionContext.action,
action: transactionContext.action_type,
idempotencyKey: transactionContext.idempotency_key,
attempt: transactionContext.attempt,
container: transactionContext.container, container: transactionContext.container,
metadata: transactionContext.metadata, metadata: transactionContext.metadata,
context: transactionContext.context, context: transactionContext.context,
@@ -86,6 +86,31 @@ export type CreateWorkflowComposerContext = {
* The step's context. * The step's context.
*/ */
export interface StepExecutionContext { 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. * The container used to access resources, such as services, in the step.
*/ */