Skip to content

Commit ba9a307

Browse files
authored
docs: general improvements (medusajs#13530)
1 parent 1c4f7bd commit ba9a307

File tree

7 files changed

+140
-110
lines changed

7 files changed

+140
-110
lines changed

www/apps/book/app/learn/fundamentals/workflows/workflow-hooks/page.mdx

Lines changed: 21 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,11 @@ export const metadata = {
44

55
# {metadata.title}
66

7-
In this chapter, you'll learn what a workflow hook is and how to consume them.
7+
In this chapter, you'll learn what workflow hooks are and how to use them.
88

99
## What is a Workflow Hook?
1010

11-
A workflow hook is a point in a workflow where you can inject custom functionality as a step function, called a hook handler.
11+
A workflow hook is a specific point in a workflow where you can inject custom functionality. This custom functionality is called a hook handler.
1212

1313
Medusa exposes hooks in many of its workflows that are used in its API routes. You can consume those hooks to add your custom logic.
1414

@@ -28,13 +28,13 @@ You want to perform a custom action during a workflow's execution, such as when
2828

2929
## How to Consume a Hook?
3030

31-
A workflow has a special `hooks` property which is an object that holds its hooks.
31+
A workflow has a special `hooks` property. This property is an object that contains all available hooks.
3232

3333
So, in a TypeScript or JavaScript file created under the `src/workflows/hooks` directory:
3434

35-
- Import the workflow.
36-
- Access its hook using the `hooks` property.
37-
- Pass the hook a step function as a parameter to consume it.
35+
1. Import the workflow.
36+
2. Access the hook using the `hooks` property.
37+
3. Pass a step function as a parameter to the hook.
3838

3939
For example, to consume the `productsCreated` hook of Medusa's `createProductsWorkflow`, create the file `src/workflows/hooks/product-created.ts` with the following content:
4040

@@ -52,15 +52,15 @@ createProductsWorkflow.hooks.productsCreated(
5252
)
5353
```
5454

55-
The `productsCreated` hook is available on the workflow's `hooks` property by its name.
55+
The `productsCreated` hook is available in the workflow's `hooks` property.
5656

57-
You invoke the hook, passing a step function (the hook handler) as a parameter.
57+
You call the hook and pass a step function (the hook handler) as a parameter.
5858

59-
Now, when a product is created using the [Create Product API route](!api!/admin#products_postproducts), your hook handler is executed after the product is created.
59+
Now, when a product is created using the [Create Product API route](!api!/admin#products_postproducts), your hook handler runs after the product is created.
6060

6161
<Note>
6262

63-
A hook can have only one handler.
63+
A hook can have only one handler. So, you can't consume the same hook multiple times.
6464

6565
</Note>
6666

@@ -74,7 +74,9 @@ Refer to the [createProductsWorkflow reference](!resources!/references/medusa-wo
7474

7575
Since a hook handler is essentially a step function, it receives the hook's input as a first parameter, and an object holding a `container` property as a second parameter.
7676

77-
Each hook has different input. For example, the `productsCreated` hook receives an object having a `products` property holding the created product.
77+
Each hook has different input. For example, the `productsCreated` hook receives an object with a `products` property that contains the created product.
78+
79+
You can find the input for each workflow's hooks in the [Core Workflows Reference](!resources!/medusa-workflows-reference).
7880

7981
### Hook Handler Compensation
8082

@@ -97,15 +99,15 @@ createProductsWorkflow.hooks.productsCreated(
9799
)
98100
```
99101

100-
The compensation function is executed if an error occurs in the workflow to undo the actions performed by the hook handler.
102+
The compensation function runs if an error occurs in the workflow. It undoes the actions performed by the hook handler.
101103

102-
The compensation function receives as an input the second parameter passed to the `StepResponse` returned by the step function.
104+
The compensation function receives the second parameter passed to the `StepResponse` returned by the step function as input.
103105

104-
It also accepts as a second parameter an object holding a `container` property to resolve resources from the Medusa container.
106+
It also accepts an object with a `container` property as a second parameter. This allows you to resolve resources from the Medusa container.
105107

106108
### Additional Data Property
107109

108-
Medusa's workflows pass in the hook's input an `additional_data` property:
110+
Medusa's workflows include an `additional_data` property in the hook's input:
109111

110112
```ts title="src/workflows/hooks/product-created.ts" highlights={[["4", "additional_data"]]}
111113
import { createProductsWorkflow } from "@medusajs/medusa/core-flows"
@@ -117,17 +119,13 @@ createProductsWorkflow.hooks.productsCreated(
117119
)
118120
```
119121

120-
This property is an object that holds additional data passed to the workflow through the request sent to the API route using the workflow.
121-
122-
<Note>
122+
This property is an object that contains additional data passed to the workflow through the request sent to the API route.
123123

124-
Learn how to pass `additional_data` in requests to API routes in [this chapter](../../api-routes/additional-data/page.mdx).
125-
126-
</Note>
124+
Learn how to pass `additional_data` in requests to API routes in the [Additional Data](../../api-routes/additional-data/page.mdx) chapter.
127125

128126
### Pass Additional Data to Workflow
129127

130-
You can also pass that additional data when executing the workflow. Pass it as a parameter to the `.run` method of the workflow:
128+
You can also pass additional data when running the workflow. Pass it as a parameter to the workflow's `.run` method:
131129

132130
```ts title="src/workflows/hooks/product-created.ts" highlights={[["10", "additional_data"]]}
133131
import type { MedusaRequest, MedusaResponse } from "@medusajs/framework/http"
@@ -147,4 +145,4 @@ export async function POST(req: MedusaRequest, res: MedusaResponse) {
147145
}
148146
```
149147

150-
Your hook handler then receives that passed data in the `additional_data` object.
148+
Your hook handler then receives the passed data in the `additional_data` object.

www/apps/book/app/learn/storefront-development/page.mdx

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,15 @@ export const metadata = {
66

77
# {metadata.title}
88

9-
The Medusa application is made up of a Node.js server and an admin dashboard. Storefronts are installed, built, and hosted separately from the Medusa application, giving you the flexibility to choose the frontend tech stack that you and your team are proficient in, and implement unique design systems and user experience.
9+
In this chapter, you'll learn about storefronts and how to build one.
1010

11-
You can build your storefront from scratch with your preferred tech stack, or start with our Next.js Starter storefront. The Next.js Starter storefront provides rich commerce features and a sleek design. Developers and businesses can use it as-is or build on top of it to tailor it for the business's unique use case, design, and customer experience.
11+
## Storefronts in Medusa
12+
13+
The Medusa application includes a Node.js server and an admin dashboard. Storefronts are separate applications that you install, build, and host independently from Medusa. This gives you the flexibility to choose your preferred frontend tech stack and implement unique designs and user experiences.
14+
15+
In your storefront, you can retrieve data and perform commerce operations by sending requests to the Medusa application's [Store API routes](!api!/store) and your custom API routes.
16+
17+
You can build your storefront from scratch with your preferred tech stack, or start with our Next.js Starter storefront. The Next.js Starter storefront provides rich commerce features and a modern design. You can use it as-is or customize it to match your business needs, design requirements, and customer experience goals.
1218

1319
<CardList
1420
items={[
@@ -25,12 +31,12 @@ You can build your storefront from scratch with your preferred tech stack, or st
2531

2632
---
2733

28-
## Passing a Publishable API Key in Storefront Requests
34+
## Using a Publishable API Key in Storefront Requests
2935

30-
When sending a request to an API route starting with `/store`, you must include a publishable API key in the header of your request.
36+
When sending requests to API routes that start with `/store`, you must include a publishable API key in the request header.
3137

3238
A publishable API key sets the scope of your request to one or more sales channels.
3339

34-
Then, when you retrieve products, only products of those sales channels are retrieved. This also ensures you retrieve correct inventory data, and associate created orders with the scoped sales channel.
40+
When you retrieve products, only products from those sales channels are returned. This also ensures you get correct inventory data and associate created orders with the right sales channel.
3541

36-
Learn more about passing the publishable API key in [this storefront development guide](!resources!/storefront-development/publishable-api-keys).
42+
Learn more about using the publishable API key in the [Storefront Development guide](!resources!/storefront-development/publishable-api-keys).

www/apps/book/generated/edit-dates.mjs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,9 @@ export const generatedEditDates = {
55
"app/learn/page.mdx": "2025-06-27T11:39:15.941Z",
66
"app/learn/fundamentals/modules/commerce-modules/page.mdx": "2025-04-17T08:51:32.723Z",
77
"app/learn/fundamentals/workflows/retry-failed-steps/page.mdx": "2025-09-15T09:38:18.299Z",
8-
"app/learn/fundamentals/workflows/workflow-hooks/page.mdx": "2024-12-09T10:44:33.781Z",
8+
"app/learn/fundamentals/workflows/workflow-hooks/page.mdx": "2025-09-16T15:52:33.602Z",
99
"app/learn/debugging-and-testing/logging/page.mdx": "2025-08-28T15:31:57.879Z",
10-
"app/learn/storefront-development/page.mdx": "2024-12-10T09:11:04.993Z",
10+
"app/learn/storefront-development/page.mdx": "2025-09-16T15:57:42.189Z",
1111
"app/learn/fundamentals/page.mdx": "2024-07-04T17:26:03+03:00",
1212
"app/learn/fundamentals/admin-customizations/page.mdx": "2024-10-07T12:41:39.218Z",
1313
"app/learn/fundamentals/workflows/workflow-timeout/page.mdx": "2025-04-24T13:15:14.472Z",

0 commit comments

Comments
 (0)