chore: reorganize docs apps (#7228)
* reorganize docs apps * add README * fix directory * add condition for old docs
This commit is contained in:
1 parent
224ebb2154
commit
4fe28f5a95
6187 files changed
+601447
-598226
No files matched your search
+85
@@ -0,0 +1,85 @@
|
||||
import { TypeList } from "docs-ui"
|
||||
|
||||
# permanentFailure
|
||||
|
||||
Creates a StepResponse that indicates that the step has failed and the retry mechanism should not kick in anymore.
|
||||
|
||||
## Example
|
||||
|
||||
```ts
|
||||
import { Product } from "@medusajs/medusa"
|
||||
import {
|
||||
createStep,
|
||||
StepResponse,
|
||||
createWorkflow
|
||||
} from "@medusajs/workflows-sdk"
|
||||
|
||||
interface CreateProductInput {
|
||||
title: string
|
||||
}
|
||||
|
||||
export const createProductStep = createStep(
|
||||
"createProductStep",
|
||||
async function (
|
||||
input: CreateProductInput,
|
||||
context
|
||||
) {
|
||||
const productService = context.container.resolve(
|
||||
"productService"
|
||||
)
|
||||
|
||||
try {
|
||||
const product = await productService.create(input)
|
||||
return new StepResponse({
|
||||
product
|
||||
}, {
|
||||
product_id: product.id
|
||||
})
|
||||
} catch (e) {
|
||||
return StepResponse.permanentFailure(`Couldn't create the product: ${e}`)
|
||||
}
|
||||
}
|
||||
)
|
||||
|
||||
interface WorkflowInput {
|
||||
title: string
|
||||
}
|
||||
|
||||
const myWorkflow = createWorkflow<
|
||||
WorkflowInput,
|
||||
Product
|
||||
>("my-workflow", (input) => {
|
||||
// Everything here will be executed and resolved later
|
||||
// during the execution. Including the data access.
|
||||
|
||||
const product = createProductStep(input)
|
||||
}
|
||||
)
|
||||
|
||||
myWorkflow()
|
||||
.run({
|
||||
input: {
|
||||
title: "Shirt"
|
||||
}
|
||||
})
|
||||
.then(({ errors, result }) => {
|
||||
if (errors.length) {
|
||||
errors.forEach((err) => {
|
||||
if (typeof err.error === "object" && "message" in err.error) {
|
||||
console.error(err.error.message)
|
||||
} else {
|
||||
console.error(err.error)
|
||||
}
|
||||
})
|
||||
}
|
||||
console.log(result)
|
||||
})
|
||||
```
|
||||
|
||||
## Parameters
|
||||
|
||||
<TypeList types={[{"name":"message","type":"`string`","description":"An optional message to be logged.","optional":false,"defaultValue":"\"Permanent failure\"","expandable":false,"children":[]}]} sectionTitle="permanentFailure"/>
|
||||
|
||||
## Returns
|
||||
|
||||
<TypeList types={[{"name":"never","type":"`never`","optional":false,"defaultValue":"","description":"Creates a StepResponse that indicates that the step has failed and the retry mechanism should not kick in anymore.","expandable":false,"children":[]}]} sectionTitle="permanentFailure"/>
|
||||
@@ -0,0 +1,25 @@
|
||||
import { TypeList } from "docs-ui"
|
||||
|
||||
# StepResponse
|
||||
|
||||
This class is used to create the response returned by a step. A step return its data by returning an instance of `StepResponse`.
|
||||
|
||||
## Type parameters
|
||||
|
||||
<TypeList types={[{"name":"TOutput","type":"`object`","description":"The type of the output of the step.","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"TCompensateInput","type":"`object`","description":"The type of the compensation input. If the step doesn't specify any compensation input, then the type of `TCompensateInput` is the same\nas that of `TOutput`.","optional":false,"defaultValue":"","expandable":false,"children":[]}]} sectionTitle="StepResponse"/>
|
||||
|
||||
## Methods
|
||||
|
||||
- [permanentFailure](../../StepResponse/methods/workflows.StepResponse.permanentFailure/page.mdx)
|
||||
|
||||
## constructor
|
||||
|
||||
The constructor of the StepResponse
|
||||
|
||||
### Type Parameters
|
||||
|
||||
<TypeList types={[{"name":"TOutput","type":"`object`","description":"The type of the output of the step.","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"TCompensateInput","type":"`object`","description":"The type of the compensation input. If the step doesn't specify any compensation input, then the type of `TCompensateInput` is the same\nas that of `TOutput`.","optional":false,"defaultValue":"","expandable":false,"children":[]}]} sectionTitle="new StepResponse"/>
|
||||
|
||||
### Parameters
|
||||
|
||||
<TypeList types={[{"name":"output","type":"TOutput","description":"The output of the step.","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"compensateInput","type":"TCompensateInput","description":"The input to be passed as a parameter to the step's compensation function. If not provided, the `output` will be provided instead.","optional":true,"defaultValue":"","expandable":false,"children":[]}]} sectionTitle="new StepResponse"/>
|
||||
@@ -0,0 +1,66 @@
|
||||
---
|
||||
slug: /references/workflows/createStep
|
||||
sidebar_label: createStep
|
||||
---
|
||||
|
||||
import { TypeList } from "docs-ui"
|
||||
|
||||
# createStep - Workflows API Reference
|
||||
|
||||
This documentation provides a reference to the `createStep` . It belongs to the `@medusajs/workflows-sdk` package.
|
||||
|
||||
This function creates a [StepFunction](../../types/workflows.StepFunction/page.mdx) that can be used as a step in a workflow constructed by the [createWorkflow](../workflows.createWorkflow/page.mdx) function.
|
||||
|
||||
## Example
|
||||
|
||||
```ts
|
||||
import {
|
||||
createStep,
|
||||
StepResponse,
|
||||
StepExecutionContext,
|
||||
WorkflowData
|
||||
} from "@medusajs/workflows-sdk"
|
||||
|
||||
interface CreateProductInput {
|
||||
title: string
|
||||
}
|
||||
|
||||
export const createProductStep = createStep(
|
||||
"createProductStep",
|
||||
async function (
|
||||
input: CreateProductInput,
|
||||
context
|
||||
) {
|
||||
const productService = context.container.resolve(
|
||||
"productService"
|
||||
)
|
||||
const product = await productService.create(input)
|
||||
return new StepResponse({
|
||||
product
|
||||
}, {
|
||||
product_id: product.id
|
||||
})
|
||||
},
|
||||
async function (
|
||||
input,
|
||||
context
|
||||
) {
|
||||
const productService = context.container.resolve(
|
||||
"productService"
|
||||
)
|
||||
await productService.delete(input.product_id)
|
||||
}
|
||||
)
|
||||
```
|
||||
|
||||
## Type Parameters
|
||||
|
||||
<TypeList types={[{"name":"TInvokeInput","type":"`object`","description":"The type of the expected input parameter to the invocation function.","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"TInvokeResultOutput","type":"`object`","description":"The type of the expected output parameter of the invocation function.","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"TInvokeResultCompensateInput","type":"`object`","description":"The type of the expected input parameter to the compensation function.","optional":false,"defaultValue":"","expandable":false,"children":[]}]} sectionTitle="createStep"/>
|
||||
|
||||
## Parameters
|
||||
|
||||
<TypeList types={[{"name":"nameOrConfig","type":"`string` \\| `object` & Omit<TransactionStepsDefinition, \"next\" \\| \"uuid\" \\| \"action\">","description":"The name of the step or its configuration.","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"invokeFn","type":"InvokeFn<TInvokeInput, TInvokeResultOutput, TInvokeResultCompensateInput>","description":"An invocation function that will be executed when the workflow is executed. The function must return an instance of [StepResponse](../../classes/workflows.StepResponse/page.mdx). The constructor of [StepResponse](../../classes/workflows.StepResponse/page.mdx)\naccepts the output of the step as a first argument, and optionally as a second argument the data to be passed to the compensation function as a parameter.","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"compensateFn","type":"CompensateFn<TInvokeResultCompensateInput>","description":"A compensation function that's executed if an error occurs in the workflow. It's used to roll-back actions when errors occur.\nIt accepts as a parameter the second argument passed to the constructor of the [StepResponse](../../classes/workflows.StepResponse/page.mdx) instance returned by the invocation function. If the\ninvocation function doesn't pass the second argument to `StepResponse` constructor, the compensation function receives the first argument\npassed to the `StepResponse` constructor instead.","optional":true,"defaultValue":"","expandable":false,"children":[]}]} sectionTitle="createStep"/>
|
||||
|
||||
## Returns
|
||||
|
||||
<TypeList types={[{"name":"StepFunction","type":"[StepFunction](../../types/workflows.StepFunction/page.mdx)<TInvokeInput, TInvokeResultOutput>","optional":false,"defaultValue":"","description":"A step function to be used in a workflow.","expandable":false,"children":[]}]} sectionTitle="createStep"/>
|
||||
@@ -0,0 +1,72 @@
|
||||
---
|
||||
slug: /references/workflows/createWorkflow
|
||||
sidebar_label: createWorkflow
|
||||
---
|
||||
|
||||
import { TypeList } from "docs-ui"
|
||||
|
||||
# createWorkflow - Workflows API Reference
|
||||
|
||||
This documentation provides a reference to the `createWorkflow` . It belongs to the `@medusajs/workflows-sdk` package.
|
||||
|
||||
This function creates a workflow with the provided name and a constructor function.
|
||||
The constructor function builds the workflow from steps created by the [createStep](../workflows.createStep/page.mdx) function.
|
||||
The returned workflow is an exported workflow of type [ReturnWorkflow](../../types/workflows.ReturnWorkflow/page.mdx), meaning it's not executed right away. To execute it,
|
||||
invoke the exported workflow, then run its `run` method.
|
||||
|
||||
## Example
|
||||
|
||||
```ts
|
||||
import { createWorkflow } from "@medusajs/workflows-sdk"
|
||||
import { MedusaRequest, MedusaResponse, Product } from "@medusajs/medusa"
|
||||
import {
|
||||
createProductStep,
|
||||
getProductStep,
|
||||
createPricesStep
|
||||
} from "./steps"
|
||||
|
||||
interface WorkflowInput {
|
||||
title: string
|
||||
}
|
||||
|
||||
const myWorkflow = createWorkflow<
|
||||
WorkflowInput,
|
||||
Product
|
||||
>("my-workflow", (input) => {
|
||||
// Everything here will be executed and resolved later
|
||||
// during the execution. Including the data access.
|
||||
|
||||
const product = createProductStep(input)
|
||||
const prices = createPricesStep(product)
|
||||
return getProductStep(product.id)
|
||||
}
|
||||
)
|
||||
|
||||
export async function GET(
|
||||
req: MedusaRequest,
|
||||
res: MedusaResponse
|
||||
) {
|
||||
const { result: product } = await myWorkflow(req.scope)
|
||||
.run({
|
||||
input: {
|
||||
title: "Shirt"
|
||||
}
|
||||
})
|
||||
|
||||
res.json({
|
||||
product
|
||||
})
|
||||
}
|
||||
```
|
||||
|
||||
## Type Parameters
|
||||
|
||||
<TypeList types={[{"name":"TData","type":"`object`","description":"The type of the input passed to the composer function.","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"TResult","type":"`object`","description":"The type of the output returned by the composer function.","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"THooks","type":"`Record<string, Function>`","description":"The type of hooks defined in the workflow.","optional":false,"defaultValue":"","expandable":false,"children":[]}]} sectionTitle="createWorkflow"/>
|
||||
|
||||
## Parameters
|
||||
|
||||
<TypeList types={[{"name":"nameOrConfig","type":"`string` \\| `object` & `TransactionModelOptions`","description":"The name of the workflow or its configuration.","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"composer","type":"(`input`: [WorkflowData](../../types/workflows.WorkflowData/page.mdx)<TData>) => `void` \\| [WorkflowData](../../types/workflows.WorkflowData/page.mdx)<TResult> \\| { [K in string \\| number \\| symbol]: WorkflowDataProperties<TResult[K]> \\| WorkflowData<TResult[K]> }","description":"The constructor function that is executed when the `run` method in [ReturnWorkflow](../../types/workflows.ReturnWorkflow/page.mdx) is used.\nThe function can't be an arrow function or an asynchronus function. It also can't directly manipulate data.\nYou'll have to use the [transform](../workflows.transform/page.mdx) function if you need to directly manipulate data.","optional":false,"defaultValue":"","expandable":false,"children":[]}]} sectionTitle="createWorkflow"/>
|
||||
|
||||
## Returns
|
||||
|
||||
<TypeList types={[{"name":"ReturnWorkflow","type":"[ReturnWorkflow](../../types/workflows.ReturnWorkflow/page.mdx)<TData, TResult, THooks>","optional":false,"defaultValue":"","description":"The created workflow. You can later execute the workflow by invoking it, then using its `run` method.","expandable":false,"children":[]}]} sectionTitle="createWorkflow"/>
|
||||
@@ -0,0 +1,59 @@
|
||||
---
|
||||
slug: /references/workflows/parallelize
|
||||
sidebar_label: parallelize
|
||||
---
|
||||
|
||||
import { TypeList } from "docs-ui"
|
||||
|
||||
# parallelize - Workflows API Reference
|
||||
|
||||
This documentation provides a reference to the `parallelize` . It belongs to the `@medusajs/workflows-sdk` package.
|
||||
|
||||
This function is used to run multiple steps in parallel. The result of each step will be returned as part of the result array.
|
||||
|
||||
## Example
|
||||
|
||||
```ts
|
||||
import {
|
||||
createWorkflow,
|
||||
parallelize
|
||||
} from "@medusajs/workflows-sdk"
|
||||
import {
|
||||
createProductStep,
|
||||
getProductStep,
|
||||
createPricesStep,
|
||||
attachProductToSalesChannelStep
|
||||
} from "./steps"
|
||||
|
||||
interface WorkflowInput {
|
||||
title: string
|
||||
}
|
||||
|
||||
const myWorkflow = createWorkflow<
|
||||
WorkflowInput,
|
||||
Product
|
||||
>("my-workflow", (input) => {
|
||||
const product = createProductStep(input)
|
||||
|
||||
const [prices, productSalesChannel] = parallelize(
|
||||
createPricesStep(product),
|
||||
attachProductToSalesChannelStep(product)
|
||||
)
|
||||
|
||||
const id = product.id
|
||||
return getProductStep(product.id)
|
||||
}
|
||||
)
|
||||
```
|
||||
|
||||
## Type Parameters
|
||||
|
||||
<TypeList types={[{"name":"TResult","type":"[WorkflowData](../../types/workflows.WorkflowData/page.mdx)[]","description":"The type of the expected result.","optional":false,"defaultValue":"","expandable":false,"children":[]}]} sectionTitle="parallelize"/>
|
||||
|
||||
## Parameters
|
||||
|
||||
<TypeList types={[{"name":"steps","type":"TResult","description":"","optional":false,"defaultValue":"","expandable":false,"children":[]}]} sectionTitle="parallelize"/>
|
||||
|
||||
## Returns
|
||||
|
||||
<TypeList types={[{"name":"TResult","type":"TResult","optional":false,"defaultValue":"","description":"The step results. The results are ordered in the array by the order they're passed in the function's parameter.","expandable":false,"children":[]}]} sectionTitle="parallelize"/>
|
||||
@@ -0,0 +1,65 @@
|
||||
---
|
||||
slug: /references/workflows/transform
|
||||
sidebar_label: transform
|
||||
---
|
||||
|
||||
import { TypeList } from "docs-ui"
|
||||
|
||||
# transform - Workflows API Reference
|
||||
|
||||
This documentation provides a reference to the `transform` . It belongs to the `@medusajs/workflows-sdk` package.
|
||||
|
||||
This function transforms the output of other utility functions.
|
||||
|
||||
For example, if you're using the value(s) of some step(s) as an input to a later step. As you can't directly manipulate data in the workflow constructor function passed to [createWorkflow](../workflows.createWorkflow/page.mdx),
|
||||
the `transform` function provides access to the runtime value of the step(s) output so that you can manipulate them.
|
||||
|
||||
Another example is if you're using the runtime value of some step(s) as the output of a workflow.
|
||||
|
||||
If you're also retrieving the output of a hook and want to check if its value is set, you must use a workflow to get the runtime value of that hook.
|
||||
|
||||
## Example
|
||||
|
||||
```ts
|
||||
import {
|
||||
createWorkflow,
|
||||
transform
|
||||
} from "@medusajs/workflows-sdk"
|
||||
import { step1, step2 } from "./steps"
|
||||
|
||||
type WorkflowInput = {
|
||||
name: string
|
||||
}
|
||||
|
||||
type WorkflowOutput = {
|
||||
message: string
|
||||
}
|
||||
|
||||
const myWorkflow = createWorkflow<
|
||||
WorkflowInput,
|
||||
WorkflowOutput
|
||||
>
|
||||
("hello-world", (input) => {
|
||||
const str1 = step1(input)
|
||||
const str2 = step2(input)
|
||||
|
||||
return transform({
|
||||
str1,
|
||||
str2
|
||||
}, (input) => ({
|
||||
message: `${input.str1}${input.str2}`
|
||||
}))
|
||||
})
|
||||
```
|
||||
|
||||
## Type Parameters
|
||||
|
||||
<TypeList types={[{"name":"T","type":"`object` \\| [WorkflowData](../../types/workflows.WorkflowData/page.mdx)","description":"","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"RFinal","type":"`object`","description":"","optional":false,"defaultValue":"","expandable":false,"children":[]}]} sectionTitle="transform"/>
|
||||
|
||||
## Parameters
|
||||
|
||||
<TypeList types={[{"name":"values","type":"T","description":"The output(s) of other step functions.","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"func","type":"[Func1<T, RFinal>]","description":"The transform function used to perform action on the runtime values of the provided `values`.","optional":false,"defaultValue":"","expandable":false,"children":[]}]} sectionTitle="transform"/>
|
||||
|
||||
## Returns
|
||||
|
||||
<TypeList types={[{"name":"WorkflowData","type":"[WorkflowData](../../types/workflows.WorkflowData/page.mdx)<RFinal>","optional":false,"defaultValue":"","description":"There's no expected value to be returned by the `transform` function.","expandable":false,"children":[]}]} sectionTitle="transform"/>
|
||||
+7
@@ -0,0 +1,7 @@
|
||||
import { TypeList } from "docs-ui"
|
||||
|
||||
# StepExecutionContext
|
||||
|
||||
The step's context.
|
||||
|
||||
<TypeList types={[{"name":"workflowId","type":"`string`","description":"The ID of the workflow.","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"attempt","type":"`number`","description":"The attempt number of the step.","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"idempotencyKey","type":"`string`","description":"The idempoency key of the step.","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"stepName","type":"`string`","description":"The name of the step.","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"action","type":"`\"invoke\"` \\| `\"compensate\"`","description":"The action of the step.","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"container","type":"[MedusaContainer](../../../medusa/types/medusa.MedusaContainer-2/page.mdx)","description":"The container used to access resources, such as services, in the step.","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"metadata","type":"`TransactionMetadata`","description":"Metadata passed in the input.","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"context","type":"[Context](../../../types/interfaces/types.Context/page.mdx)","description":"A context used to share resources, such as transaction manager, between the application and the module.","optional":false,"defaultValue":"","expandable":false,"children":[{"name":"transactionManager","type":"TManager","description":"An instance of a transaction manager of type `TManager`, which is a typed parameter passed to the context to specify the type of the `transactionManager`.","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"manager","type":"TManager","description":"An instance of a manager, typically an entity manager, of type `TManager`, which is a typed parameter passed to the context to specify the type of the `manager`.","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"isolationLevel","type":"`string`","description":"A string indicating the isolation level of the context. Possible values are `READ UNCOMMITTED`, `READ COMMITTED`, `REPEATABLE READ`, or `SERIALIZABLE`.","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"enableNestedTransactions","type":"`boolean`","description":"A boolean value indicating whether nested transactions are enabled.","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"eventGroupId","type":"`string`","description":"A string indicating the ID of the group to aggregate the events to be emitted at a later point.","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"transactionId","type":"`string`","description":"A string indicating the ID of the current transaction.","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"messageAggregator","type":"[IMessageAggregator](../../../types/interfaces/types.IMessageAggregator/page.mdx)","description":"An instance of a message aggregator, which is used to aggregate messages to be emitted at a later point.","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"requestId","type":"`string`","description":"A string indicating the ID of the current request.","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"idempotencyKey","type":"`string`","description":"A string indicating the idempotencyKey of the current workflow execution.","optional":true,"defaultValue":"","expandable":false,"children":[]}]}]} sectionTitle="StepExecutionContext"/>
|
||||
+9
@@ -0,0 +1,9 @@
|
||||
import { TypeList } from "docs-ui"
|
||||
|
||||
# CreateWorkflowComposerContext
|
||||
|
||||
**CreateWorkflowComposerContext**: `Object`
|
||||
|
||||
## Properties
|
||||
|
||||
<TypeList types={[{"name":"hooks_","type":"`string`[]","description":"","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"hooksCallback_","type":"`Record<string, Function[]>`","description":"","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"workflowId","type":"`string`","description":"","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"flow","type":"`OrchestratorBuilder`","description":"","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"handlers","type":"`WorkflowHandler`","description":"","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"stepBinder","type":"`<TOutput>`(`fn`: [StepFunctionResult](../workflows.StepFunctionResult/page.mdx)) => [WorkflowData](../workflows.WorkflowData/page.mdx)<TOutput>","description":"","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"hookBinder","type":"`<TOutput>`(`name`: `string`, `fn`: `Function`) => [WorkflowData](../workflows.WorkflowData/page.mdx)<TOutput>","description":"","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"parallelizeBinder","type":"`<TOutput>`(`fn`: (`this`: [CreateWorkflowComposerContext](page.mdx)) => TOutput) => TOutput","description":"","optional":false,"defaultValue":"","expandable":false,"children":[]}]} sectionTitle="CreateWorkflowComposerContext"/>
|
||||
@@ -0,0 +1,56 @@
|
||||
import { TypeList } from "docs-ui"
|
||||
|
||||
# ReturnWorkflow
|
||||
|
||||
**ReturnWorkflow**: `<TDataOverride, TResultOverride>`(`container?`: [MedusaContainer](../../../medusa/types/medusa.MedusaContainer-2/page.mdx) \| ``{ __joinerConfig: [ModuleJoinerConfig](../../../types/ModulesSdkTypes/types/types.ModulesSdkTypes.ModuleJoinerConfig/page.mdx) ; __definition: [ModuleDefinition](../../../medusa/types/medusa.ModuleDefinition/page.mdx) }``[]) => Omit<LocalWorkflow, "run" \| "registerStepSuccess" \| "registerStepFailure" \| "cancel"> & ExportedWorkflow<TData, TResult, TDataOverride, TResultOverride> & THooks & `object` & `object`
|
||||
|
||||
An exported workflow, which is the type of a workflow constructed by the [createWorkflow](../../functions/workflows.createWorkflow/page.mdx) function. The exported workflow can be invoked to create
|
||||
an executable workflow, optionally within a specified container. So, to execute the workflow, you must invoke the exported workflow, then run the
|
||||
`run` method of the exported workflow.
|
||||
|
||||
## Example
|
||||
|
||||
To execute a workflow:
|
||||
|
||||
```ts
|
||||
myWorkflow()
|
||||
.run({
|
||||
input: {
|
||||
name: "John"
|
||||
}
|
||||
})
|
||||
.then(({ result }) => {
|
||||
console.log(result)
|
||||
})
|
||||
```
|
||||
|
||||
To specify the container of the workflow, you can pass it as an argument to the call of the exported workflow. This is necessary when executing the workflow
|
||||
within a Medusa resource such as an API Route or a Subscriber.
|
||||
|
||||
For example:
|
||||
|
||||
```ts
|
||||
import type {
|
||||
MedusaRequest,
|
||||
MedusaResponse
|
||||
} from "@medusajs/medusa";
|
||||
import myWorkflow from "../../../workflows/hello-world";
|
||||
|
||||
export async function GET(
|
||||
req: MedusaRequest,
|
||||
res: MedusaResponse
|
||||
) {
|
||||
const { result } = await myWorkflow(req.scope)
|
||||
.run({
|
||||
input: {
|
||||
name: req.query.name as string
|
||||
}
|
||||
})
|
||||
|
||||
res.send(result)
|
||||
}
|
||||
```
|
||||
|
||||
## Type Parameters
|
||||
|
||||
<TypeList types={[{"name":"TData","type":"`object`","description":"","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"TResult","type":"`object`","description":"","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"THooks","type":"`Record<string, Function>`","description":"","optional":false,"defaultValue":"","expandable":false,"children":[]}]} sectionTitle="ReturnWorkflow"/>
|
||||
@@ -0,0 +1,11 @@
|
||||
import { TypeList } from "docs-ui"
|
||||
|
||||
# StepFunction
|
||||
|
||||
**StepFunction**: KeysOfUnion<TInput> extends [] ? () => TOutput extends `Item`[] ? (`Item` \| [WorkflowData](../workflows.WorkflowData/page.mdx)<Item>)[] : TOutput extends `object` ? { [Key in string \| number \| symbol]: TOutput[Key] \| WorkflowData<(...)[(...)]> } : TOutput & [WorkflowDataProperties](../workflows.WorkflowDataProperties/page.mdx)<TOutput> & TOutput & [WorkflowDataProperties](../workflows.WorkflowDataProperties/page.mdx)<TOutput> & ``{ config: Method config }`` & StepFunctionReturnConfig<TOutput> : (`input`: TInput \| [WorkflowData](../workflows.WorkflowData/page.mdx)<TInput>) => TOutput extends `Item`[] ? (`Item` \| [WorkflowData](../workflows.WorkflowData/page.mdx)<Item>)[] : TOutput extends `object` ? { [Key in string \| number \| symbol]: TOutput[Key] \| WorkflowData<(...)[(...)]> } : TOutput & [WorkflowDataProperties](../workflows.WorkflowDataProperties/page.mdx)<TOutput> & TOutput & [WorkflowDataProperties](../workflows.WorkflowDataProperties/page.mdx)<TOutput> & ``{ config: Method config }`` & StepFunctionReturnConfig<TOutput> & [WorkflowDataProperties](../workflows.WorkflowDataProperties/page.mdx)<TOutput>
|
||||
|
||||
A step function to be used in a workflow.
|
||||
|
||||
## Type Parameters
|
||||
|
||||
<TypeList types={[{"name":"TInput","type":"`object`","description":"The type of the input of the step.","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"TOutput","type":"`object`","description":"The type of the output of the step.","optional":false,"defaultValue":"","expandable":false,"children":[]}]} sectionTitle="StepFunction"/>
|
||||
@@ -0,0 +1,19 @@
|
||||
import { TypeList } from "docs-ui"
|
||||
|
||||
# StepFunctionResult
|
||||
|
||||
**StepFunctionResult**: (`this`: [CreateWorkflowComposerContext](../workflows.CreateWorkflowComposerContext/page.mdx)) => [WorkflowData](../workflows.WorkflowData/page.mdx)<TOutput>
|
||||
|
||||
## Type Parameters
|
||||
|
||||
<TypeList types={[{"name":"TOutput","type":"`unknown` \\| `unknown`[]","description":"","optional":false,"defaultValue":"","expandable":false,"children":[]}]} sectionTitle="StepFunctionResult"/>
|
||||
|
||||
## Type declaration
|
||||
|
||||
### Parameters
|
||||
|
||||
<TypeList types={[{"name":"this","type":"[CreateWorkflowComposerContext](../workflows.CreateWorkflowComposerContext/page.mdx)","description":"","optional":false,"defaultValue":"","expandable":false,"children":[{"name":"hooks_","type":"`string`[]","description":"","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"hooksCallback_","type":"`Record<string, Function[]>`","description":"","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"workflowId","type":"`string`","description":"","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"flow","type":"`OrchestratorBuilder`","description":"","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"handlers","type":"`WorkflowHandler`","description":"","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"stepBinder","type":"`<TOutput>`(`fn`: [StepFunctionResult](page.mdx)) => [WorkflowData](../workflows.WorkflowData/page.mdx)<TOutput>","description":"","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"hookBinder","type":"`<TOutput>`(`name`: `string`, `fn`: `Function`) => [WorkflowData](../workflows.WorkflowData/page.mdx)<TOutput>","description":"","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"parallelizeBinder","type":"`<TOutput>`(`fn`: (`this`: [CreateWorkflowComposerContext](../workflows.CreateWorkflowComposerContext/page.mdx)) => TOutput) => TOutput","description":"","optional":false,"defaultValue":"","expandable":false,"children":[]}]}]} sectionTitle="__type"/>
|
||||
|
||||
### Returns
|
||||
|
||||
<TypeList types={[{"name":"WorkflowData","type":"[WorkflowData](../workflows.WorkflowData/page.mdx)<TOutput>","optional":false,"defaultValue":"","description":"","expandable":false,"children":[{"name":"TOutput","type":"TOutput","optional":false,"defaultValue":"","description":"","expandable":false,"children":[]}]}]} sectionTitle="__type"/>
|
||||
+17
@@ -0,0 +1,17 @@
|
||||
import { TypeList } from "docs-ui"
|
||||
|
||||
# UnwrapWorkflowInputDataType
|
||||
|
||||
**UnwrapWorkflowInputDataType**: T extends [ReturnWorkflow](../workflows.ReturnWorkflow/page.mdx)<infer TData, infer R, infer THooks> ? TData : `never`
|
||||
|
||||
Extract the raw type of the expected input data of a workflow.
|
||||
|
||||
## Example
|
||||
|
||||
```ts
|
||||
type WorkflowInputData = UnwrapWorkflowInputDataType<typeof myWorkflow>
|
||||
```
|
||||
|
||||
## Type Parameters
|
||||
|
||||
<TypeList types={[{"name":"T","type":"[ReturnWorkflow](../workflows.ReturnWorkflow/page.mdx)<any, any, any>","description":"","optional":false,"defaultValue":"","expandable":false,"children":[]}]} sectionTitle="UnwrapWorkflowInputDataType"/>
|
||||
@@ -0,0 +1,11 @@
|
||||
import { TypeList } from "docs-ui"
|
||||
|
||||
# WorkflowData
|
||||
|
||||
**WorkflowData**: T extends infer Item[] ? (`Item` \| [WorkflowData](page.mdx)<Item>)[] : T extends `object` ? { [Key in keyof T]: T[Key] \| WorkflowData<T[Key]> } : T & [WorkflowDataProperties](../workflows.WorkflowDataProperties/page.mdx)<T> & T & [WorkflowDataProperties](../workflows.WorkflowDataProperties/page.mdx)<T> & `object`
|
||||
|
||||
This type is used to encapsulate the input or output type of all utils.
|
||||
|
||||
## Type Parameters
|
||||
|
||||
<TypeList types={[{"name":"T","type":"`object`","description":"The type of a step's input or result.","optional":false,"defaultValue":"","expandable":false,"children":[]}]} sectionTitle="WorkflowData"/>
|
||||
+13
@@ -0,0 +1,13 @@
|
||||
import { TypeList } from "docs-ui"
|
||||
|
||||
# WorkflowDataProperties
|
||||
|
||||
**WorkflowDataProperties**: `Object`
|
||||
|
||||
## Type Parameters
|
||||
|
||||
<TypeList types={[{"name":"T","type":"`object`","description":"","optional":false,"defaultValue":"","expandable":false,"children":[]}]} sectionTitle="WorkflowDataProperties"/>
|
||||
|
||||
## Properties
|
||||
|
||||
<TypeList types={[{"name":"__type","type":"`string`","description":"","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"__step__","type":"`string`","description":"","optional":false,"defaultValue":"","expandable":false,"children":[]}]} sectionTitle="WorkflowDataProperties"/>
|
||||
+5
@@ -0,0 +1,5 @@
|
||||
import { TypeList } from "docs-ui"
|
||||
|
||||
# WorkflowTransactionContext
|
||||
|
||||
**WorkflowTransactionContext**: [StepExecutionContext](../../interfaces/workflows.StepExecutionContext/page.mdx) & `OriginalWorkflowTransactionContext` & `object`
|
||||
Reference in new issue
Block a user