docs: various improvements to introduction guides (#14398)

This commit is contained in:
Shahed Nasser
2025-12-24 15:37:37 +02:00
committed by GitHub
parent 10dab3a47a
commit ba3a572a89
9 changed files with 61 additions and 53 deletions
@@ -77,12 +77,12 @@ You add a single test that sends a `GET` request to `/custom` using the `api.get
Run the following command to run your tests:
```bash npm2yarn
npm run test:integration
npm run test:integration:http
```
<Note title="Tip">
If you don't have a `test:integration` script in `package.json`, refer to the [Medusa Testing Tools chapter](../../page.mdx#add-test-commands).
If you don't have a `test:integration:http` script in `package.json`, refer to the [Medusa Testing Tools chapter](../../page.mdx#add-test-commands).
</Note>
@@ -68,12 +68,12 @@ jest.setTimeout(60 * 1000)
Run the following command to run your tests:
```bash npm2yarn
npm run test:integration
npm run test:integration:http
```
<Note title="Tip">
If you don't have a `test:integration` script in `package.json`, refer to the [Medusa Testing Tools chapter](../page.mdx#add-test-commands).
If you don't have a `test:integration:http` script in `package.json`, refer to the [Medusa Testing Tools chapter](../page.mdx#add-test-commands).
</Note>
@@ -71,11 +71,12 @@ To fetch data with a route loader:
For example, consider the following UI route created at `src/admin/routes/custom/page.tsx`:
export const loaderHighlights = [
["6", "loader", "Export a loader function to fetch products."],
["15", "useLoaderData", "Access the data returned by the loader function in the route component."],
["7", "loader", "Export a loader function to fetch products."],
["16", "useLoaderData", "Access the data returned by the loader function in the route component."],
]
```tsx title="src/admin/routes/custom/page.tsx" highlights={loaderHighlights}
import { defineRouteConfig } from "@medusajs/admin-sdk"
import { Container, Heading } from "@medusajs/ui"
import {
useLoaderData,
@@ -42,6 +42,7 @@ export const sdk = new Medusa({
import Medusa from "@medusajs/js-sdk"
export const sdk = new Medusa({
// add __BACKEND_URL__ to src/admin/vite-env.d.ts if you get type errors
baseUrl: __BACKEND_URL__ || "/",
auth: {
type: "session",
@@ -26,12 +26,11 @@ For example, create the file `src/scripts/my-script.ts` with the following conte
```ts title="src/scripts/my-script.ts"
import {
ExecArgs,
IProductModuleService,
} from "@medusajs/framework/types"
import { Modules } from "@medusajs/framework/utils"
export default async function myScript({ container }: ExecArgs) {
const productModuleService: IProductModuleService = container.resolve(
const productModuleService = container.resolve(
Modules.PRODUCT
)
@@ -34,11 +34,9 @@ Find a list of all emitted events in [this reference](!resources!/references/eve
You create a subscriber in a TypeScript or JavaScript file under the `src/subscribers` directory. The file exports the function to execute and the subscriber's configuration that indicate what event(s) it listens to.
For example, create the file `src/subscribers/product-created.ts` with the following content:
For example, create the file `src/subscribers/order-placed.ts` with the following content:
![Example of subscriber file in the application's directory structure](https://res.cloudinary.com/dza7lstvk/image/upload/v1732866244/Medusa%20Book/subscriber-dir-overview_pusyeu.jpg)
```ts title="src/subscribers/product-created.ts"
```ts title="src/subscribers/order-placed.ts"
import { SubscriberArgs, type SubscriberConfig } from "@medusajs/framework"
import { sendOrderConfirmationWorkflow } from "../workflows/send-order-confirmation"
@@ -256,9 +256,9 @@ export const workflowHighlights = [
["17", "resolve", "Resolve the Blog Module's service from the Medusa container."],
["19", "createPosts", "Create a blog post using the Blog Module service's generated method."],
["25", "", "Add a compensation function that only runs if an error occurs in the workflow."],
["28", "", "Delete the post if an error occurs using the Blog Module service's generated method."],
["32", "createWorkflow", "Create and workflow that can be executed to create a blog post."],
["35", "createPostStep", "Execute the `createPostStep` to create the post."]
["31", "deletePosts", "Delete the post if an error occurs using the Blog Module service's generated method."],
["35", "createWorkflow", "Create and workflow that can be executed to create a blog post."],
["38", "createPostStep", "Execute the `createPostStep` to create the post."]
]
```ts title="src/workflows/create-post.ts" highlights={workflowHighlights}
@@ -287,6 +287,9 @@ const createPostStep = createStep(
return new StepResponse(post, post)
},
async (post, { container }) => {
if (!post) {
return
}
const blogModuleService: BlogModuleService = container.resolve(BLOG_MODULE)
await blogModuleService.deletePosts(post.id)
@@ -309,7 +312,7 @@ The step also has a compensation function, which is a function passed as a third
You'll now execute that workflow in an API route to expose the feature of creating blog posts to clients. To create an API route, create the file `src/api/blog/posts/route.ts` with the following content:
```ts
```ts title="src/api/blog/posts/route.ts"
import type {
MedusaRequest,
MedusaResponse,