docs: revise main docs outline (#10502)

This commit is contained in:
Shahed Nasser
2024-12-09 13:54:42 +02:00
committed by GitHub
parent c8cb9b5c1a
commit 0ae98c51eb
141 changed files with 814 additions and 1181 deletions
@@ -27,7 +27,7 @@ You create an API route in a `route.{ts,js}` file under a sub-directory of the `
<Note>
Learn more about API routes [in this guide](../../../basics/api-routes/page.mdx).
Learn more about API routes [in this guide](../../../fundamentals/api-routes/page.mdx).
</Note>
@@ -63,7 +63,7 @@ export const POST = async (
You export a route handler function with its name (`POST`) being the HTTP method of the API route you're exposing.
The function receives two parameters: a `MedusaRequest` object to access request details, and `MedusaResponse` object to return or manipulate the response. The `MedusaRequest` object's `scope` property is the [Medusa container](../../../basics/medusa-container/page.mdx) that holds framework tools and custom and core modules' services.
The function receives two parameters: a `MedusaRequest` object to access request details, and `MedusaResponse` object to return or manipulate the response. The `MedusaRequest` object's `scope` property is the [Medusa container](../../../fundamentals/medusa-container/page.mdx) that holds framework tools and custom and core modules' services.
<Note title="Tip">
@@ -85,7 +85,7 @@ Medusa uses [Zod](https://zod.dev/) to create validation schemas. These schemas
<Note>
Learn more about API route validation in [this chapter](../../../advanced-development/api-routes/validation/page.mdx).
Learn more about API route validation in [this chapter](../../../fundamentals/api-routes/validation/page.mdx).
</Note>
@@ -123,7 +123,7 @@ A middleware is a function executed before the route handler when a request is s
<Note>
Learn more about middlewares in [this chapter](../../../advanced-development/api-routes/middlewares/page.mdx).
Learn more about middlewares in [this chapter](../../../fundamentals/api-routes/middlewares/page.mdx).
</Note>
@@ -12,7 +12,7 @@ In a module, you create data models and business logic to manage them. In the ne
<Note>
Learn more about modules in [this chapter](../../../basics/modules/page.mdx).
Learn more about modules in [this chapter](../../../fundamentals/modules/page.mdx).
</Note>
@@ -30,7 +30,7 @@ A data model represents a table in the database. You create data models using Me
<Note>
Learn more about data models in [this chapter](../../../basics/modules/page.mdx#1-create-data-model).
Learn more about data models in [this chapter](../../../fundamentals/modules/page.mdx#1-create-data-model).
</Note>
@@ -56,7 +56,7 @@ You define the data model using the `define` method of the `model` utility impor
<Note title="Tip">
Learn about other property types in [this chapter](../../../advanced-development/data-models/property-types/page.mdx).
Learn about other property types in [this chapter](../../../fundamentals/data-models/property-types/page.mdx).
</Note>
@@ -70,7 +70,7 @@ In this step, you'll create the Brand Module's service that provides methods to
<Note>
Learn more about services in [this chapter](../../../basics/modules/page.mdx#2-create-service).
Learn more about services in [this chapter](../../../fundamentals/modules/page.mdx#2-create-service).
</Note>
@@ -168,7 +168,7 @@ A migration is a TypeScript or JavaScript file that defines database changes mad
<Note>
Learn more about migrations in [this chapter](../../../basics/modules/page.mdx#5-generate-migrations).
Learn more about migrations in [this chapter](../../../fundamentals/modules/page.mdx#5-generate-migrations).
</Note>
@@ -10,9 +10,9 @@ By following these guides, you'll add brands to the Medusa application that you
To build a custom feature in Medusa, you need three main tools:
- [Module](../../basics/modules/page.mdx): a package with commerce logic for a single domain. It defines new tables to add to the database, and a class of methods to manage these tables.
- [Workflow](../../basics/workflows/page.mdx): a tool to perform an operation comprising multiple steps with built-in rollback and retry mechanisms.
- [API route](../../basics/api-routes/page.mdx): a REST endpoint that exposes commerce features to clients, such as the admin dashboard or a storefront. The API route executes a workflow that implements the commerce feature using modules.
- [Module](../../fundamentals/modules/page.mdx): a package with commerce logic for a single domain. It defines new tables to add to the database, and a class of methods to manage these tables.
- [Workflow](../../fundamentals/workflows/page.mdx): a tool to perform an operation comprising multiple steps with built-in rollback and retry mechanisms.
- [API route](../../fundamentals/api-routes/page.mdx): a REST endpoint that exposes commerce features to clients, such as the admin dashboard or a storefront. The API route executes a workflow that implements the commerce feature using modules.
![Diagram showcasing the flow of a custom developed feature](https://res.cloudinary.com/dza7lstvk/image/upload/v1725867628/Medusa%20Book/custom-development_nofvp6.jpg)
@@ -14,7 +14,7 @@ The workflow you'll create in this chapter will use the Brand Module's service t
<Note>
Learn more about workflows in [this chapter](../../../basics/workflows/page.mdx).
Learn more about workflows in [this chapter](../../../fundamentals/workflows/page.mdx).
</Note>
@@ -67,7 +67,7 @@ You create a `createBrandStep` using the `createStep` function. It accepts the s
The step function receives two parameters: input passed to the step when it's invoked, and an object of general context and configurations. This object has a `container` property, which is the Medusa container.
The [Medusa container](../../../basics/medusa-container/page.mdx) is a registry of framework and commerce tools accessible in your customizations, such as a workflow's step. The Medusa application registers the services of core and custom modules in the container, allowing you to resolve and use them.
The [Medusa container](../../../fundamentals/medusa-container/page.mdx) is a registry of framework and commerce tools accessible in your customizations, such as a workflow's step. The Medusa application registers the services of core and custom modules in the container, allowing you to resolve and use them.
So, In the step function, you use the Medusa container to resolve the Brand Module's service and use its generated `createBrands` method, which accepts an object of brands to create.
@@ -85,7 +85,7 @@ You define for each step a compensation function that's executed when an error o
<Note>
Learn more about the compensation function in [this chapter](../../../advanced-development/workflows/compensation-function/page.mdx).
Learn more about the compensation function in [this chapter](../../../fundamentals/workflows/compensation-function/page.mdx).
</Note>
@@ -8,8 +8,8 @@ In the previous chapters, you've customized your Medusa application to [add bran
After customizing and extending your application with new features, you may need to provide an interface for admin users to utilize these features. The Medusa Admin dashboard is extendable, allowing you to:
- Insert components, called [widgets](../../advanced-development/admin/widgets/page.mdx), on existing pages.
- Add new pages, called [UI Routes](../../advanced-development/admin/ui-routes/page.mdx).
- Insert components, called [widgets](../../fundamentals/admin/widgets/page.mdx), on existing pages.
- Add new pages, called [UI Routes](../../fundamentals/admin/ui-routes/page.mdx).
From these customizations, you can send requests to custom API routes, allowing admin users to manage custom resources on the dashboard
@@ -19,7 +19,7 @@ In this chapter, you'll add a UI route to the admin dashboard that shows the all
## 1. Get Brands API Route
In a [previous chapter](../../extend-features/query-linked-records/page.mdx), you learned how to add an API route that retrieves brands and their products using [Query](../../../advanced-development/module-links/query/page.mdx). You'll expand that API route to support pagination, so that on the admin dashboard you can show the brands in a paginated table.
In a [previous chapter](../../extend-features/query-linked-records/page.mdx), you learned how to add an API route that retrieves brands and their products using [Query](../../../fundamentals/module-links/query/page.mdx). You'll expand that API route to support pagination, so that on the admin dashboard you can show the brands in a paginated table.
Replace or create the `GET` API route at `src/api/admin/brands/route.ts` with the following:
@@ -76,7 +76,7 @@ You return in the response the retrieved brands and the pagination configuration
<Note>
Learn more about pagination with Query in [this chapter](../../../advanced-development/module-links/query/page.mdx#apply-pagination).
Learn more about pagination with Query in [this chapter](../../../fundamentals/module-links/query/page.mdx#apply-pagination).
</Note>
@@ -138,7 +138,7 @@ By applying the above middleware, you can pass pagination configurations to `GET
<Note>
Learn more about using the `validateAndTransformQuery` middleware to configure Query in [this chapter](../../../advanced-development/module-links/query/page.mdx#request-query-configurations).
Learn more about using the `validateAndTransformQuery` middleware to configure Query in [this chapter](../../../fundamentals/module-links/query/page.mdx#request-query-configurations).
</Note>
@@ -186,7 +186,7 @@ You'll now add the UI route that shows the paginated list of brands. A UI route
<Note>
Learn more about UI routes in [this chapter](../../../advanced-development/admin/ui-routes/page.mdx).
Learn more about UI routes in [this chapter](../../../fundamentals/admin/ui-routes/page.mdx).
</Note>
@@ -59,7 +59,7 @@ You'll now add a widget to the product-details page. A widget is a React compone
<Note>
Learn more about widgets in [this documentation](../../../advanced-development/admin/widgets/page.mdx).
Learn more about widgets in [this documentation](../../../fundamentals/admin/widgets/page.mdx).
</Note>
@@ -8,7 +8,7 @@ export const metadata = {
In this chapter, you'll learn how to define a module link between a brand defined in the [custom Brand Module](../../custom-features/module/page.mdx), and a product defined in the [Product Module](!resources!/commerce-modules/product) that's available in your Medusa application out-of-the-box.
Modules are [isolated](../../../advanced-development/modules/isolation/page.mdx) from other resources, ensuring that they're integrated into the Medusa application without side effects. However, you may need to associate data models of different modules, or you're trying to extend data models from commerce modules with custom properties. To do that, you define module links.
Modules are [isolated](../../../fundamentals/modules/isolation/page.mdx) from other resources, ensuring that they're integrated into the Medusa application without side effects. However, you may need to associate data models of different modules, or you're trying to extend data models from commerce modules with custom properties. To do that, you define module links.
A module link forms an association between two data models of different modules while maintaining module isolation. You can then manage and query linked records of the data models using Medusa's Modules SDK.
@@ -16,7 +16,7 @@ In this chapter, you'll define a module link between the `Brand` data model of t
<Note>
Learn more about module links in [this chapters](../../../advanced-development/module-links/page.mdx).
Learn more about module links in [this chapters](../../../fundamentals/module-links/page.mdx).
</Note>
@@ -8,7 +8,7 @@ export const metadata = {
After linking the [custom Brand data model](../../custom-features/module/page.mdx) and Medusa's [Product Module](!resources!/commerce-modules/product) in the [previous chapter](../define-link/page.mdx), you'll extend the create product workflow and API route to allow associating a brand with a product.
Some API routes, including the [Create Product API route](!api!/admin#products_postproducts), accept an `additional_data` request body parameter. This parameter can hold custom data that's passed to the [hooks](../../../advanced-development/workflows/workflow-hooks/page.mdx) of the workflow executed in the API route, allowing you to consume those hooks and perform actions with the custom data.
Some API routes, including the [Create Product API route](!api!/admin#products_postproducts), accept an `additional_data` request body parameter. This parameter can hold custom data that's passed to the [hooks](../../../fundamentals/workflows/workflow-hooks/page.mdx) of the workflow executed in the API route, allowing you to consume those hooks and perform actions with the custom data.
So, in this chapter, to extend the create product flow and associate a brand with a product, you will:
@@ -17,7 +17,7 @@ So, in this chapter, to extend the create product flow and associate a brand wit
<Note>
To learn more about the `additional_data` property and the API routes that accept additional data, refer to [this chapter](../../../advanced-development/api-routes/additional-data/page.mdx).
To learn more about the `additional_data` property and the API routes that accept additional data, refer to [this chapter](../../../fundamentals/api-routes/additional-data/page.mdx).
</Note>
@@ -42,7 +42,7 @@ A workflow hook is a point in a workflow where you can inject a step to perform
<Note>
Learn more about the workflow hooks in [this chapter](../../../advanced-development/workflows/workflow-hooks/page.mdx).
Learn more about the workflow hooks in [this chapter](../../../fundamentals/workflows/workflow-hooks/page.mdx).
</Note>
@@ -87,7 +87,7 @@ createProductsWorkflow.hooks.productsCreated(
Workflows have a special `hooks` property to access its hooks and consume them. Each hook, such as `productCreated`, accepts a step function as a parameter. The step function accepts the following parameters:
1. An object having an `additional_data` property, which is the custom data passed in the request body under `additional_data`. The object will also have properties passed from the workflow to the hook, which in this case is the `products` property that holds an array of the created products.
2. An object of properties related to the step's context. It has a `container` property whose value is the [Medusa container](../../../basics/medusa-container/page.mdx) to resolve framework and commerce tools.
2. An object of properties related to the step's context. It has a `container` property whose value is the [Medusa container](../../../fundamentals/medusa-container/page.mdx) to resolve framework and commerce tools.
In the step, if a brand ID is passed in `additional_data`, you resolve the Brand Module's service and use its generated `retrieveBrand` method to retrieve the brand by its ID. The `retrieveBrand` method will throw an error if the brand doesn't exist.
@@ -97,7 +97,7 @@ Next, you want to create a link between the created products and the brand. To d
<Note>
Learn more about the remote link in [this chapter](../../../advanced-development/module-links/remote-link/page.mdx).
Learn more about the remote link in [this chapter](../../../fundamentals/module-links/remote-link/page.mdx).
</Note>
@@ -10,9 +10,9 @@ In other commerce platforms, you extend core features and models through hacky w
Medusa's framework and orchestration tools mitigate these issues while supporting all your customization needs:
- [Module Links](../../advanced-development/module-links/page.mdx): Link data models of different modules without building direct dependencies, ensuring that the Medusa application integrates your modules without side effects.
- [Workflow Hooks](../../advanced-development/workflows/workflow-hooks/page.mdx): inject custom functionalities into a workflow at predefined points, called hooks. This allows you to perform custom actions as a part of a core workflow without hacky workarounds.
- [Additional Data in API Routes](../../advanced-development/api-routes/additional-data/page.mdx): Configure core API routes to accept request parameters relevant to your customizations. These parameters are passed to the underlying workflow's hooks, where you can manage your custom data as part of an existing flow.
- [Module Links](../../fundamentals/module-links/page.mdx): Link data models of different modules without building direct dependencies, ensuring that the Medusa application integrates your modules without side effects.
- [Workflow Hooks](../../fundamentals/workflows/workflow-hooks/page.mdx): inject custom functionalities into a workflow at predefined points, called hooks. This allows you to perform custom actions as a part of a core workflow without hacky workarounds.
- [Additional Data in API Routes](../../fundamentals/api-routes/additional-data/page.mdx): Configure core API routes to accept request parameters relevant to your customizations. These parameters are passed to the underlying workflow's hooks, where you can manage your custom data as part of an existing flow.
---
@@ -74,7 +74,7 @@ You can also retrieve linked records using Query. Query allows you to retrieve d
<Note>
Learn more about Query in [this chapter](../../../advanced-development/module-links/query/page.mdx).
Learn more about Query in [this chapter](../../../fundamentals/module-links/query/page.mdx).
</Note>
@@ -10,11 +10,11 @@ In the [previous chapter](../service/page.mdx), you created a CMS Module that in
In another previous chapter, you [added a workflow](../../custom-features/workflow/page.mdx) that creates a brand. After integrating the CMS, you want to sync that brand to the third-party system as well.
Medusa has an event system that emits events when an operation is performed. It allows you to listen to those events and perform an asynchronous action in a function called a [subscriber](../../../basics/events-and-subscribers/page.mdx). This is useful to perform actions that aren't integral to the original flow, such as syncing data to a third-party system.
Medusa has an event system that emits events when an operation is performed. It allows you to listen to those events and perform an asynchronous action in a function called a [subscriber](../../../fundamentals/events-and-subscribers/page.mdx). This is useful to perform actions that aren't integral to the original flow, such as syncing data to a third-party system.
<Note>
Learn more about Medusa's event system and subscribers in [this chapter](../../../basics/events-and-subscribers/page.mdx).
Learn more about Medusa's event system and subscribers in [this chapter](../../../fundamentals/events-and-subscribers/page.mdx).
</Note>
@@ -87,13 +87,13 @@ Workflows have a built-in durable execution engine that helps you complete tasks
<Note>
Learn more about workflows in [this chapter](../../../basics/workflows/page.mdx).
Learn more about workflows in [this chapter](../../../fundamentals/workflows/page.mdx).
</Note>
You'll create a `syncBrandToSystemWorkflow` that has two steps:
- `useQueryGraphStep`: a step that Medusa provides to retrieve data using [Query](../../../advanced-development/module-links/query/page.mdx). You'll use this to retrieve the brand's details using its ID.
- `useQueryGraphStep`: a step that Medusa provides to retrieve data using [Query](../../../fundamentals/module-links/query/page.mdx). You'll use this to retrieve the brand's details using its ID.
- `syncBrandToCmsStep`: a step that you'll create to sync the brand to the CMS.
### syncBrandToCmsStep
@@ -142,13 +142,13 @@ const syncBrandToCmsStep = createStep(
)
```
You create the `syncBrandToCmsStep` that accepts a brand as an input. In the step, you resolve the CMS Module's service from the [Medusa container](../../../basics/medusa-container/page.mdx) and use its `createBrand` method. This method will create the brand in the third-party CMS.
You create the `syncBrandToCmsStep` that accepts a brand as an input. In the step, you resolve the CMS Module's service from the [Medusa container](../../../fundamentals/medusa-container/page.mdx) and use its `createBrand` method. This method will create the brand in the third-party CMS.
You also pass the brand's ID to the step's compensation function. In this function, you delete the brand in the third-party CMS if an error occurs during the workflow's execution.
<Note>
Learn more about compensation functions in [this chapter](../../../advanced-development/workflows/compensation-function/page.mdx).
Learn more about compensation functions in [this chapter](../../../fundamentals/workflows/compensation-function/page.mdx).
</Note>
@@ -270,7 +270,7 @@ In the function, you execute the `syncBrandToCmsWorkflow`, passing it the data p
<Note>
Learn more about subscribers in [this chapter](../../../basics/events-and-subscribers/page.mdx).
Learn more about subscribers in [this chapter](../../../fundamentals/events-and-subscribers/page.mdx).
</Note>
@@ -12,7 +12,7 @@ In Medusa, you integrate a third-party system by:
1. Creating a module whose service provides the methods to connect to and perform operations in the third-party system.
2. Building workflows that complete tasks spanning across systems. You use the module that integrates a third-party system in the workflow's steps.
3. Executing the workflows you built in an [API route](../../basics/api-routes/page.mdx), at a scheduled time, or when an event is emitted.
3. Executing the workflows you built in an [API route](../../fundamentals/api-routes/page.mdx), at a scheduled time, or when an event is emitted.
---
@@ -14,7 +14,7 @@ You can create an action to be automatically executed at a specified interval us
<Note>
Learn more about scheduled jobs in [this chapter](../../../basics/scheduled-jobs/page.mdx).
Learn more about scheduled jobs in [this chapter](../../../fundamentals/scheduled-jobs/page.mdx).
</Note>
@@ -39,7 +39,7 @@ Workflows have a built-in durable execution engine that helps you complete tasks
<Note>
Learn more about workflows in [this chapter](../../../basics/workflows/page.mdx).
Learn more about workflows in [this chapter](../../../fundamentals/workflows/page.mdx).
</Note>
@@ -134,7 +134,7 @@ The step passes the created brands to the compensation function, which deletes t
<Note>
Learn more about compensation functions in [this chapter](../../../advanced-development/workflows/compensation-function/page.mdx).
Learn more about compensation functions in [this chapter](../../../fundamentals/workflows/compensation-function/page.mdx).
</Note>
@@ -220,11 +220,11 @@ export const syncBrandsFromSystemWorkflow = createWorkflow(
In the workflow, you only use the `retrieveBrandsFromSystemStep` for now, which retrieves the brands from the third-party CMS.
Next, you need to identify which brands must be created or updated. Since workflows are constructed internally and are only evaluated during execution, you can't access values to perform data manipulation directly. Instead, use [transform](../../../advanced-development/workflows/variable-manipulation/page.mdx) from the Workflows SDK that gives you access to the real-time values of the data, allowing you to create new variables using those values.
Next, you need to identify which brands must be created or updated. Since workflows are constructed internally and are only evaluated during execution, you can't access values to perform data manipulation directly. Instead, use [transform](../../../fundamentals/workflows/variable-manipulation/page.mdx) from the Workflows SDK that gives you access to the real-time values of the data, allowing you to create new variables using those values.
<Note>
Learn more about data manipulation using `transform` in [this chapter](../../../advanced-development/workflows/variable-manipulation/page.mdx).
Learn more about data manipulation using `transform` in [this chapter](../../../fundamentals/workflows/variable-manipulation/page.mdx).
</Note>
@@ -320,7 +320,7 @@ A scheduled job file must export:
- `name`: A unique name for the scheduled job.
- `schedule`: A string that holds a [cron expression](https://crontab.guru/) indicating the schedule to run the job.
The scheduled job function accepts as a parameter the [Medusa container](../../../basics/medusa-container/page.mdx) used to resolve framework and commerce tools. You then execute the `syncBrandsFromCmsWorkflow` and use its result to log how many brands were created or updated.
The scheduled job function accepts as a parameter the [Medusa container](../../../fundamentals/medusa-container/page.mdx) used to resolve framework and commerce tools. You then execute the `syncBrandsFromCmsWorkflow` and use its result to log how many brands were created or updated.
Based on the cron expression specified in `config.schedule`, Medusa will run the scheduled job every day at midnight. You can also change it to `* * * * *` to run it every minute for easier debugging.
@@ -10,7 +10,7 @@ In the previous chapters, you've created a [Brand Module](../../custom-features/
<Note>
Learn more about modules in [this chapter](../../../basics/modules/page.mdx).
Learn more about modules in [this chapter](../../../fundamentals/modules/page.mdx).
</Note>
@@ -66,7 +66,7 @@ export default CmsModuleService
You create a `CmsModuleService` that will hold the methods to connect to the third-party CMS. A service's constructor accepts two parameters:
1. The module's container. Since a module is [isolated](../../../advanced-development/modules/isolation/page.mdx), it has a [local container](../../../advanced-development/modules/container/page.mdx) different than the Medusa container you use in other customizations. This container holds framework tools like the [Logger utility](../../../debugging-and-testing/logging/page.mdx) and resources within the module.
1. The module's container. Since a module is [isolated](../../../fundamentals/modules/isolation/page.mdx), it has a [local container](../../../fundamentals/modules/container/page.mdx) different than the Medusa container you use in other customizations. This container holds framework tools like the [Logger utility](../../../debugging-and-testing/logging/page.mdx) and resources within the module.
2. Options passed to the module when it's later added in Medusa's configurations. These options are useful to pass secret keys or configurations that ensure your module is re-usable across applications. For the CMS Module, you accept the API key to connect to the dummy CMS as an option.
When integrating a third-party system that has a Node.js SDK or client, you can initialize that client in the constructor to be used in the service's methods.
@@ -1,14 +0,0 @@
export const metadata = {
title: `${pageNumber} Custom Development`,
}
# {metadata.title}
In the next chapters, youll customize Medusa using the concepts you learned.
You'll follow an example of building a Brands Module that leads you through:
1. The main concepts you need to build custom features.
2. How to extend data models that are in the Commerce Modules.
3. How to use your custom features in pages and widgets in the admin dashboard.
4. How to integrate third-party systems into your Medusa application.