1 # TSDoc: core-flows Workflows and Steps
2
3 Workflow and step files live under `packages/core/core-flows/src/`. Workflows are created with `createWorkflow(...)`, steps with `createStep(...)`.
4
5 ## Workflows
6
7 Document the exported workflow `const` with:
8 - A description paragraph explaining what the workflow does and when it's used
9 - A link to the API route that executes it (if applicable)
10 - `@example` showing how to call `.run()`
11 - `@summary` with a one-line description
12 - `@property hooks.*` entries for each hook the workflow exposes
13 - `@since` if new (version from prompt)
14 - `@featureFlag` if behind a feature flag
15
16 ### Workflow Template
17
18 ```typescript
19 export const myWorkflowId = "my-workflow"
20 /**
21 * This workflow [does X]. It's executed by the
22 * [Some API Route](https://docs.medusajs.com/api/admin#resource_postresourceid).
23 *
24 * You can use this workflow within your own customizations or custom workflows,
25 * allowing you to wrap custom logic around [the operation].
26 *
27 * @example
28 * const { result } = await myWorkflow(container)
29 * .run({
30 * input: {
31 * id: "foo_123",
32 * },
33 * })
34 *
35 * @summary
36 *
37 * [One-line summary of what the workflow does.]
38 *
39 * @property hooks.myHook - This hook is called [when/before/after X]. You can
40 * use it to [describe what customization is possible].
41 */
42 export const myWorkflow = createWorkflow(myWorkflowId, (input) => {
43 ```
44
45 ### Workflow with @featureFlag and @since
46
47 ```typescript
48 /**
49 * This workflow creates a view configuration.
50 *
51 * @since 2.10.3
52 * @featureFlag view_configurations
53 *
54 * @example
55 * const { result } = await createViewConfigurationWorkflow(container)
56 * .run({ input: { ... } })
57 *
58 * @summary
59 *
60 * Create a view configuration.
61 */
62 export const createViewConfigurationWorkflow = createWorkflow(...)
63 ```
64
65 ### @property hooks — Documenting Hooks
66
67 Each hook exposed on `hooks.*` gets a `@property` entry describing when it runs and what it enables:
68
69 ```typescript
70 * @property hooks.validate - This hook is called before all operations. You can
71 * use it to validate the input or perform any custom validation logic.
72 *
73 * @property hooks.setPricingContext - This hook is called after the cart is
74 * retrieved. You can use it to pass custom pricing context to the workflow.
75 ```
76
77 ## Steps
78
79 Document the exported step `const` with:
80 - A description of what the step does (and what it throws/returns)
81 - `@example` showing how to call the step
82 - `@since` if new
83 - `@featureFlag` if behind a feature flag
84
85 Document the step's input type interface with descriptions for each property.
86
87 ### Step Template
88
89 ```typescript
90 export const myStepId = "my-step"
91 /**
92 * This step [does X]. If [condition], the step throws an error.
93 *
94 * @example
95 * const data = myStep({
96 * id: "foo_123",
97 * })
98 */
99 export const myStep = createStep(
100 myStepId,
101 async (data: MyStepInput, { container }) => {
102 ```
103
104 ### Step Input Type
105
106 ```typescript
107 /**
108 * The input for the {@link validateCartStep}.
109 */
110 export interface ValidateCartStepInput {
111 /**
112 * The cart to validate.
113 */
114 cart: CartWorkflowDTO | CartDTO
115 }
116 ```
117
118 > Use `{@link stepName}` in descriptions to cross-reference related steps.
119
120 ### Step with @featureFlag and @since
121
122 For simple flag/version-only documentation (no full description warranted):
123
124 ```typescript
125 export const createViewConfigurationStepId = "create-view-configuration"
126 /**
127 * @since 2.10.3
128 * @featureFlag view_configurations
129 */
130 export const createViewConfigurationStep = createStep(...)
131 ```
132
133 When a step is more complex or widely used, include a full description and `@example` even if it also has `@featureFlag`/`@since`.
134
135 ## What NOT to Document
136
137 - The `*Id` string constant (e.g. `export const addToCartWorkflowId = "add-to-cart"`) — no TSDoc needed
138 - Internal helper functions not exported from the module
139 - Compensation functions (the third argument to `createStep`) — internal implementation detail