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

This commit is contained in:
Carlos R. L. Rodrigues
2024-03-20 13:59:03 -03:00
committed by GitHub
parent 20243e22ee
commit 3ca957ec0f
4 changed files with 45 additions and 0 deletions

View File

@@ -0,0 +1,5 @@
---
"@medusajs/workflows-sdk": patch
---
Added idempotencyKey to workflow step context

View File

@@ -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,

View File

@@ -110,6 +110,11 @@ export function hook<TOutput>(
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,

View File

@@ -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.
*/