Skip to content

Commit cd599e1

Browse files
authored
docs: general updates to documentation pages (medusajs#13055)
1 parent 6e66e36 commit cd599e1

File tree

10 files changed

+231
-135
lines changed

10 files changed

+231
-135
lines changed

www/apps/book/app/learn/fundamentals/admin/widgets/page.mdx

Lines changed: 19 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -6,13 +6,13 @@ export const metadata = {
66

77
# {metadata.title}
88

9-
In this chapter, you’ll learn more about widgets and how to use them.
9+
In this chapter, you’ll learn about widgets and how to use them.
1010

1111
## What is an Admin Widget?
1212

13-
The Medusa Admin dashboard's pages are customizable to insert widgets of custom content in pre-defined injection zones. You create these widgets as React components that allow admin users to perform custom actions.
13+
The Medusa Admin's pages are customizable for inserting widgets of custom content in pre-defined injection zones. For example, you can add a widget on the product details page that allows admin users to sync products to a third-party service.
1414

15-
For example, you can add a widget on the product details page that allow admin users to sync products to a third-party service.
15+
You create these widgets as React components that render the content and functionality of the widget.
1616

1717
---
1818

@@ -25,15 +25,18 @@ For example, you can add a widget on the product details page that allow admin u
2525
}]}
2626
/>
2727

28-
You create a widget in a `.tsx` file under the `src/admin/widgets` directory. The file’s default export must be the widget, which is the React component that renders the custom content. The file must also export the widget’s configurations indicating where to insert the widget.
28+
You create a widget in a `.tsx` file under the `src/admin/widgets` directory. The file must export:
29+
30+
1. A React component that renders the widget. This will be the file's default export.
31+
2. The widget’s configurations indicating where to insert the widget.
2932

3033
For example, create the file `src/admin/widgets/product-widget.tsx` with the following content:
3134

3235
![Example of widget file in the application's directory structure](https://res.cloudinary.com/dza7lstvk/image/upload/v1732867137/Medusa%20Book/widget-dir-overview_dqsbct.jpg)
3336

3437
export const widgetHighlights = [
3538
["5", "ProductWidget", "The React component of the product widget."],
36-
["17", "zone", "The zone to inject the widget to."]
39+
["17", "zone", "The zone to inject the widget into."]
3740
]
3841

3942
```tsx title="src/admin/widgets/product-widget.tsx" highlights={widgetHighlights}
@@ -59,11 +62,11 @@ export const config = defineWidgetConfig({
5962
export default ProductWidget
6063
```
6164

62-
You export the `ProductWidget` component, which shows the heading `Product Widget`. In the widget, you use [Medusa UI](!ui!), a package that Medusa maintains to allow you to customize the dashboard with the same components used to build it.
65+
In the example above, the widget is injected at the top of a product’s details.
6366

64-
To export the widget's configurations, you use `defineWidgetConfig` from the Admin Extension SDK. It accepts as a parameter an object with the `zone` property, whose value is a string or an array of strings, each being the name of the zone to inject the widget into.
67+
You export the `ProductWidget` component, which displays the heading `Product Widget`. In the widget, you use [Medusa UI](!ui!) to customize the dashboard with the same components used to build it.
6568

66-
In the example above, the widget is injected at the top of a product’s details.
69+
To export the widget's configuration, you use `defineWidgetConfig` from the Admin Extension SDK. It accepts an object as a parameter with the `zone` property, whose value is a string or an array of strings, each being the name of the zone to inject the widget into.
6770

6871
<Note title="Important" type="warning">
6972

@@ -83,9 +86,9 @@ Then, open a product’s details page. You’ll find your custom widget at the t
8386

8487
---
8588

86-
## Props Passed in Detail Pages
89+
## Props Passed to Widgets on Detail Pages
8790

88-
Widgets that are injected into a details page receive a `data` prop, which is the main data of the details page.
91+
Widgets that are injected into a detail page receive a `data` prop, which is the main data of the details page.
8992

9093
For example, a widget injected into the `product.details.before` zone receives the product's details in the `data` prop:
9194

@@ -130,23 +133,25 @@ The props type is `DetailWidgetProps`, and it accepts as a type argument the exp
130133

131134
---
132135

133-
## Injection Zone
136+
## Injection Zones List
134137

135-
Refer to [this reference](!resources!/admin-widget-injection-zones) for the full list of injection zones and their props.
138+
Refer to the [Admin Widget Injection Zones](!resources!/admin-widget-injection-zones) reference for the full list of injection zones and their props.
136139

137140
---
138141

139142
## Admin Components List
140143

141-
To build admin customizations that match the Medusa Admin's designs and layouts, refer to [this guide](!resources!/admin-components) to find common components.
144+
While the Medusa Admin uses the [Medusa UI](!ui!) components, it also expands on them for styling and design purposes.
145+
146+
To build admin customizations that match the Medusa Admin's designs and layouts, refer to the [Admin Components](!resources!/admin-components) guide. You'll find components like `Header`, `JSON View`, and more that match the Medusa Admin's design.
142147

143148
---
144149

145150
## Show Widgets Conditionally
146151

147152
In some cases, you may want to show a widget only if certain conditions are met. For example, you may want to show a widget only if the product has a brand.
148153

149-
To disable the widget from showing, return an empty fragment from the widget component:
154+
To prevent the widget from showing, return an empty fragment from the widget component:
150155

151156
```tsx title="src/admin/widgets/product-widget.tsx"
152157
import { defineWidgetConfig } from "@medusajs/admin-sdk"

www/apps/book/app/learn/fundamentals/api-routes/http-methods/page.mdx

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ In this chapter, you'll learn about how to add new API routes for each HTTP meth
88

99
## HTTP Method Handler
1010

11-
An API route is created for every HTTP method you export a handler function for in a route file.
11+
An API route is created for every HTTP method you export a handler function for in a `route.ts` or `route.js` file.
1212

1313
Allowed HTTP methods are: `GET`, `POST`, `DELETE`, `PUT`, `PATCH`, `OPTIONS`, and `HEAD`.
1414

@@ -39,7 +39,7 @@ export const POST = async (
3939
}
4040
```
4141

42-
This adds two API Routes:
42+
This file adds two API Routes:
4343

44-
- A `GET` route at `http://localhost:9000/hello-world`.
45-
- A `POST` route at `http://localhost:9000/hello-world`.
44+
- A `GET` API route at `http://localhost:9000/hello-world`.
45+
- A `POST` API route at `http://localhost:9000/hello-world`.

www/apps/book/app/learn/fundamentals/api-routes/page.mdx

Lines changed: 17 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -4,25 +4,25 @@ export const metadata = {
44

55
# {metadata.title}
66

7-
In this chapter, you’ll learn what API Routes are and how to create them.
7+
In this chapter, you’ll learn what API routes are and how to create them.
88

99
## What is an API Route?
1010

11-
An API Route is an endpoint. It exposes commerce features to external applications, such as storefronts, the admin dashboard, or third-party systems.
11+
An API route is a REST endpoint that exposes commerce features to external applications, such as storefronts, the admin dashboard, or third-party systems.
1212

13-
The Medusa core application provides a set of admin and store API routes out-of-the-box. You can also create custom API routes to expose your custom functionalities.
13+
The Medusa core application provides a set of [admin](!api!/admin) and [store](!api!/store) API routes out-of-the-box. You can also create custom API routes to expose your custom functionalities.
1414

1515
---
1616

1717
## How to Create an API Route?
1818

19-
An API Route is created in a TypeScript or JavaScript file under the `src/api` directory of your Medusa application. The file’s name must be `route.ts` or `route.js`.
19+
You can create an API route in a TypeScript or JavaScript file under the `src/api` directory of your Medusa application. The file’s name must be `route.ts` or `route.js`.
2020

2121
![Example of API route in the application's directory structure](https://res.cloudinary.com/dza7lstvk/image/upload/v1732808645/Medusa%20Book/route-dir-overview_dqgzmk.jpg)
2222

23-
Each file exports API Route handler functions for at least one HTTP method (`GET`, `POST`, `DELETE`, etc…).
23+
Each file exports API route handler functions for at least one HTTP method (`GET`, `POST`, `DELETE`, etc…).
2424

25-
For example, to create a `GET` API Route at `/hello-world`, create the file `src/api/hello-world/route.ts` with the following content:
25+
For example, to create a `GET` API route at `/hello-world`, create the file `src/api/hello-world/route.ts` with the following content:
2626

2727
```ts title="src/api/hello-world/route.ts"
2828
import type {
@@ -40,26 +40,30 @@ export const GET = (
4040
}
4141
```
4242

43-
### Test API Route
43+
### Test the API Route
4444

4545
To test the API route above, start the Medusa application:
4646

4747
```bash npm2yarn
4848
npm run dev
4949
```
5050

51-
Then, send a `GET` request to the `/hello-world` API Route:
51+
Then, send a `GET` request to the `/hello-world` API route:
5252

5353
```bash
5454
curl http://localhost:9000/hello-world
5555
```
5656

57-
---
57+
You should receive the following response:
5858

59-
## When to Use API Routes
59+
```json
60+
{
61+
"message": "[GET] Hello world!"
62+
}
63+
```
6064

61-
<Note title="Use API routes when" type="success">
65+
---
6266

63-
You're exposing custom functionality to be used by a storefront, admin dashboard, or any external application.
67+
## Next Chapters: Learn More About API Routes
6468

65-
</Note>
69+
Follow the next chapters to learn about the different HTTP methods you can use in API routes, parameters and validation, protecting routes, and more.

www/apps/book/app/learn/fundamentals/api-routes/responses/page.mdx

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ In this chapter, you'll learn how to send a response in your API route.
88

99
## Send a JSON Response
1010

11-
To send a JSON response, use the `json` method of the `MedusaResponse` object passed as the second parameter of your API route handler.
11+
To send a JSON response, use the `json` method of the `MedusaResponse` object that is passed as the second parameter of your API route handler.
1212

1313
For example:
1414

@@ -78,7 +78,7 @@ export const streamHighlights = [
7878
["7", "writeHead", "Set the response's headers."],
7979
["7", "200", "Set the status code."],
8080
["8", `"Content-Type"`, "Set the response's content type."],
81-
["13", "interval", "Simulate stream data using an interval"],
81+
["13", "interval", "Simulate stream data using an interval."],
8282
["14", "write", "Write stream data."],
8383
["17", "on", "Stop the stream when the request is terminated."]
8484
]
@@ -109,10 +109,10 @@ export const GET = async (
109109

110110
The `writeHead` method accepts two parameters:
111111

112-
1. The first one is the response's status code.
113-
2. The second is an object of key-value pairs to set the headers of the response.
112+
1. The first parameter is the response's status code.
113+
2. The second parameter is an object of key-value pairs to set the response headers.
114114

115-
This API route opens a stream by setting the `Content-Type` in the header to `text/event-stream`. It then simulates a stream by creating an interval that writes the stream data every three seconds.
115+
This API route opens a stream by setting the `Content-Type` to `text/event-stream`. It then simulates a stream by creating an interval that writes the stream data every three seconds.
116116

117117
---
118118

www/apps/book/app/learn/fundamentals/custom-cli-scripts/page.mdx

Lines changed: 37 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -4,17 +4,22 @@ export const metadata = {
44

55
# {metadata.title}
66

7-
In this chapter, you'll learn how to create and execute custom scripts from Medusa's CLI tool.
7+
In this chapter, you'll learn how to create and execute custom scripts using Medusa's CLI tool.
88

99
## What is a Custom CLI Script?
1010

11-
A custom CLI script is a function to execute through Medusa's CLI tool. This is useful when creating custom Medusa tooling to run through the CLI.
11+
A custom CLI script is a function that you can execute using Medusa's CLI tool. It is useful when you need a script that has access to the [Medusa container](../medusa-container/page.mdx) and can be executed using Medusa's CLI.
12+
13+
For example, you can create a custom CLI script that:
14+
15+
- [Seeds data into the database](./seed-data/page.mdx).
16+
- Runs a script before starting the Medusa application.
1217

1318
---
1419

1520
## How to Create a Custom CLI Script?
1621

17-
To create a custom CLI script, create a TypeScript or JavaScript file under the `src/scripts` directory. The file must default export a function.
22+
To create a custom CLI script, create a TypeScript or JavaScript file under the `src/scripts` directory. The file must export a function by default.
1823

1924
For example, create the file `src/scripts/my-script.ts` with the following content:
2025

@@ -37,13 +42,13 @@ export default async function myScript({ container }: ExecArgs) {
3742
}
3843
```
3944

40-
The function receives as a parameter an object having a `container` property, which is an instance of the Medusa Container. Use it to resolve resources in your Medusa application.
45+
The function receives as a parameter an object with a `container` property, which is an instance of the Medusa Container. Use it to resolve resources in your Medusa application.
4146

4247
---
4348

44-
## How to Run Custom CLI Script?
49+
## How to Run a Custom CLI Script?
4550

46-
To run the custom CLI script, run the Medusa CLI's `exec` command:
51+
To run a custom CLI script, run the Medusa CLI's `exec` command:
4752

4853
```bash
4954
npx medusa exec ./src/scripts/my-script.ts
@@ -55,7 +60,7 @@ npx medusa exec ./src/scripts/my-script.ts
5560

5661
Your script can accept arguments from the command line. Arguments are passed to the function's object parameter in the `args` property.
5762

58-
For example:
63+
For example, create the following CLI script that logs the command line arguments:
5964

6065
```ts
6166
import { ExecArgs } from "@medusajs/framework/types"
@@ -65,8 +70,32 @@ export default async function myScript({ args }: ExecArgs) {
6570
}
6671
```
6772

68-
Then, pass the arguments in the `exec` command after the file path:
73+
Then, run the script with the `exec` command and pass arguments after the script's path.
6974

7075
```bash
7176
npx medusa exec ./src/scripts/my-script.ts arg1 arg2
7277
```
78+
79+
---
80+
81+
## Run Custom Script on Application Startup
82+
83+
In some cases, you may need to perform an action when the Medusa application starts.
84+
85+
If the action is related to a module, you should use a [loader](../modules/loaders/page.mdx). Otherwise, you can create a custom CLI script and run it before starting the Medusa application.
86+
87+
To run a custom script on application startup, modify the `dev` and `start` commands in `package.json` to execute your script first.
88+
89+
For example:
90+
91+
```json title="package.json"
92+
{
93+
"scripts": {
94+
"startup": "medusa exec ./src/scripts/startup.ts",
95+
"dev": "npm run startup && medusa develop",
96+
"start": "npm run startup && medusa start"
97+
}
98+
}
99+
```
100+
101+
The `startup` script will run every time you run the Medusa application.

www/apps/book/app/learn/fundamentals/modules/modules-directory-structure/page.mdx

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

55
# {metadata.title}
66

7-
In this document, you'll learn about the expected files and directories in your module.
7+
In this chapter, you'll learn about the expected files and directories in your module.
88

99
![Module Directory Structure Example](https://res.cloudinary.com/dza7lstvk/image/upload/v1714379976/Medusa%20Book/modules-dir-overview_nqq7ne.jpg)
1010

1111
## index.ts
1212

13-
The `index.ts` file in the root of your module's directory is the only required file. It must export the module's definition as explained in a [previous chapter](../page.mdx).
13+
The `index.ts` file is in the root of your module's directory and exports the module's definition as explained in the [Modules](../page.mdx) chapter.
1414

1515
---
1616

1717
## service.ts
1818

19-
A module must have a main service. It's created in the `service.ts` file at the root of your module directory as explained in a [previous chapter](../page.mdx).
19+
A module must have a main service that contains the module's business logic. It's created in the `service.ts` file at the root of your module directory as explained in the [Modules](../page.mdx) chapter.
2020

2121
---
2222

2323
## Other Directories
2424

25-
The following directories are optional and their content are explained more in the following chapters:
25+
The following directories are optional and you can choose to create them based on your module's functionality:
2626

27-
- `models`: Holds the data models representing tables in the database.
28-
- `migrations`: Holds the migration files used to reflect changes on the database.
29-
- `loaders`: Holds the scripts to run on the Medusa application's start-up.
27+
- `models`: Holds the [data models](../../data-models/page.mdx) representing tables in the database.
28+
- `migrations`: Holds the [migration](../../data-models/write-migration/page.mdx) files used to reflect changes on the database.
29+
- `loaders`: Holds the [script files to run on the application's startup](../loaders/page.mdx) when Medusa loads the module.
Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,20 @@
11
export const metadata = {
2-
title: `${pageNumber} Scheduled Jobs Number of Executions`,
2+
title: `${pageNumber} Scheduled Job Number of Executions`,
33
}
44

55
# {metadata.title}
66

77
In this chapter, you'll learn how to set a limit on the number of times a scheduled job is executed.
88

9-
## numberOfExecutions Option
9+
## Default Number of Scheduled Job Executions
1010

11-
The export configuration object of the scheduled job accepts an optional property `numberOfExecutions`. Its value is a number indicating how many times the scheduled job can be executed during the Medusa application's runtime.
11+
By default, a scheduled job is executed whenever it matches its specified pattern. For example, if you set a scheduled job to run every five minutes, it will run every five minutes until you stop the Medusa application.
12+
13+
---
14+
15+
## Configure Number of Scheduled Job Executions
16+
17+
To execute a scheduled job a specific number of times only, you can configure it with the `numberOfExecutions` option. Its value is the number of times the scheduled job can be executed during the Medusa application's runtime.
1218

1319
For example:
1420

@@ -18,7 +24,7 @@ export const highlights = [
1824

1925
```ts highlights={highlights}
2026
export default async function myCustomJob() {
21-
console.log("I'll be executed three times only.")
27+
console.log("I'll be executed only three times.")
2228
}
2329

2430
export const config = {
@@ -31,10 +37,10 @@ export const config = {
3137

3238
The above scheduled job has the `numberOfExecutions` configuration set to `3`.
3339

34-
So, it'll only execute 3 times, each every minute, then it won't be executed anymore.
40+
So, Medusa will execute this job only 3 times, once every minute, and then it won't be executed anymore during the current runtime.
3541

36-
<Note>
42+
### Configuration is Per Application Runtime
3743

38-
If you restart the Medusa application, the scheduled job will be executed again until reaching the number of executions specified.
44+
Medusa tracks the number of executions for a scheduled job during its current runtime. Once the application stops, the next time you start it, the counter will be reset to `0`.
3945

40-
</Note>
46+
So, if you restart the Medusa application, the scheduled job will be executed again until it reaches the number of executions specified.

0 commit comments

Comments
 (0)