fix(modules-sdk): create workflow returning step transformer (#6102)

This commit is contained in:
Carlos R. L. Rodrigues
2024-01-17 09:17:37 -03:00
committed by GitHub
parent 2b9f98895e
commit 19bbae61f8
3 changed files with 116 additions and 28 deletions
@@ -9,7 +9,6 @@ import {
import { Context, LoadedModule, MedusaContainer } from "@medusajs/types"
import { MedusaModule } from "@medusajs/modules-sdk"
import { OrchestrationUtils } from "@medusajs/utils"
import { EOL } from "os"
import { ulid } from "ulid"
import { MedusaWorkflow } from "../medusa-workflow"
@@ -129,33 +128,11 @@ export const exportWorkflow = <TData = unknown, TResult = unknown>(
throw new Error(errorMessage)
}
let result: any = undefined
const resFrom =
resultFrom?.__type === OrchestrationUtils.SymbolWorkflowStep
? resultFrom.__step__
: resultFrom
if (resFrom) {
if (Array.isArray(resFrom)) {
result = resFrom.map((from) => {
const res = transaction.getContext().invoke?.[from]
return res?.__type === OrchestrationUtils.SymbolWorkflowWorkflowData
? res.output
: res
})
} else {
const res = transaction.getContext().invoke?.[resFrom]
result =
res?.__type === OrchestrationUtils.SymbolWorkflowWorkflowData
? res.output
: res
}
const ret = result || resFrom
result = options?.wrappedInput
? await resolveValue(ret, transaction.getContext())
: ret
let result
if (options?.wrappedInput) {
result = await resolveValue(resultFrom, transaction.getContext())
} else {
result = transaction.getContext().invoke?.[resultFrom]
}
return {