docs: fix imports across docs

This commit is contained in:
Shahed Nasser committed 2024-12-09 15:10:38 +02:00
1 parent 8dedb97e40
commit f4b45b8080
21 files changed
+61 -61

No files matched your search

@@ -176,7 +176,7 @@ You configure the properties accepted in `additional_data` in the `src/api/middl
![Directory structure after adding the middelwares file](https://res.cloudinary.com/dza7lstvk/image/upload/v1733386868/Medusa%20Book/brands-middleware-dir-overview_uczos1.jpg)
```ts title="src/api/middlewares.ts"
import { defineMiddlewares } from "@medusajs/medusa"
import { defineMiddlewares } from "@medusajs/framework/http"
import { z } from "zod"
export default defineMiddlewares({
@@ -64,7 +64,7 @@ To do that, use the middleware route object defined in `src/api/middlewares.ts`.
For example, create the file `src/api/middlewares.ts` with the following content:
```ts title="src/api/middlewares.ts"
import { defineMiddlewares } from "@medusajs/medusa"
import { defineMiddlewares } from "@medusajs/framework/http"
import { z } from "zod"
export default defineMiddlewares({
@@ -81,7 +81,7 @@ For example:
export const highlights = [["25", "parseCorsOrigins", "A utility function that parses the CORS configurations in `medusa-config.ts`"]]
```ts title="src/api/middlewares.ts" highlights={highlights} collapsibleLines="1-10" expandButtonLabel="Show Imports"
import { defineMiddlewares } from "@medusajs/medusa"
import { defineMiddlewares } from "@medusajs/framework/http"
import type {
MedusaNextFunction,
MedusaRequest,
@@ -22,13 +22,13 @@ As Medusa's server is based on Express, you can use any [Express middleware](htt
## How to Create a Middleware?
Middlewares are defined in the special file `src/api/middlewares.ts`. Use the `defineMiddlewares` function imported from `@medusajs/medusa` to define the middlewares, and export its value.
Middlewares are defined in the special file `src/api/middlewares.ts`. Use the `defineMiddlewares` function from the Medusa Framework to define the middlewares, and export its value.
For example:
```ts title="src/api/middlewares.ts"
import { defineMiddlewares } from "@medusajs/medusa"
import type {
defineMiddlewares,
MedusaNextFunction,
MedusaRequest,
MedusaResponse,
@@ -118,11 +118,11 @@ For example:
export const pathParamHighlights = [["11", ":id", "Indicates that the API route accepts an `id` path parameter."]]
```ts title="src/api/middlewares.ts" collapsibleLines="1-7" expandMoreLabel="Show Imports" highlights={pathParamHighlights}
import { defineMiddlewares } from "@medusajs/medusa"
import type {
MedusaNextFunction,
MedusaRequest,
MedusaResponse,
defineMiddlewares,
} from "@medusajs/framework/http"
export default defineMiddlewares({
@@ -150,11 +150,11 @@ For example:
export const highlights = [["12", "method", "Apply the middleware only on `POST` requests"]]
```ts title="src/api/middlewares.ts" highlights={highlights} collapsibleLines="1-7" expandButtonLabel="Show Imports"
import { defineMiddlewares } from "@medusajs/medusa"
import type {
MedusaNextFunction,
MedusaRequest,
MedusaResponse,
defineMiddlewares,
} from "@medusajs/framework/http"
export default defineMiddlewares({
@@ -183,11 +183,11 @@ A middleware whose `matcher` pattern doesn't end with a backslash won't be appli
For example, consider you have the following middleware:
```ts collapsibleLines="1-7" expandMoreLabel="Show Imports"
import { defineMiddlewares } from "@medusajs/medusa"
import type {
MedusaNextFunction,
MedusaRequest,
MedusaResponse,
defineMiddlewares,
} from "@medusajs/framework/http"
export default defineMiddlewares({
@@ -49,7 +49,7 @@ export const highlights = [
import {
defineMiddlewares,
authenticate,
} from "@medusajs/medusa"
} from "@medusajs/framework/http"
export default defineMiddlewares({
routes: [
@@ -53,8 +53,8 @@ To use this schema for validating the body parameters of requests to `/custom`,
For example, create the file `src/api/middlewares.ts` with the following content:
```ts title="src/api/middlewares.ts"
import { defineMiddlewares } from "@medusajs/medusa"
import {
defineMiddlewares,
validateAndTransformBody,
} from "@medusajs/framework/http"
import { PostStoreCustomSchema } from "./custom/validators"
@@ -183,9 +183,9 @@ Next, you'll use the schema to validate incoming requests' query parameters to t
Add the `validateAndTransformQuery` middleware to the API route in the file `src/api/middlewares.ts`:
```ts title="src/api/middlewares.ts"
import { defineMiddlewares } from "@medusajs/medusa"
import {
validateAndTransformQuery,
defineMiddlewares
} from "@medusajs/framework/http"
import { PostStoreCustomSchema } from "./custom/validators"
@@ -298,9 +298,9 @@ Using this middleware allows you to have default configurations for retrieved fi
The first step is to use the `validateAndTransformQuery` middleware on the `GET` route. You add the middleware in `src/api/middlewares.ts`:
```ts title="src/api/middlewares.ts"
import { defineMiddlewares } from "@medusajs/medusa"
import {
validateAndTransformQuery,
defineMiddlewares
} from "@medusajs/framework/http"
import { createFindParams } from "@medusajs/medusa/api/utils/validators"
+7 -7
View File
@@ -26,7 +26,7 @@ export const generatedEditDates = {
"app/learn/fundamentals/admin/widgets/page.mdx": "2024-12-04T11:02:57.133Z",
"app/learn/fundamentals/data-models/page.mdx": "2024-12-09T11:34:51.065Z",
"app/learn/fundamentals/modules/remote-link/page.mdx": "2024-09-30T08:43:53.127Z",
"app/learn/fundamentals/api-routes/protected-routes/page.mdx": "2024-11-13T10:44:04.225Z",
"app/learn/fundamentals/api-routes/protected-routes/page.mdx": "2024-12-09T13:04:03.071Z",
"app/learn/fundamentals/workflows/add-workflow-hook/page.mdx": "2024-10-21T13:30:21.371Z",
"app/learn/fundamentals/events-and-subscribers/data-payload/page.mdx": "2024-10-21T13:30:21.369Z",
"app/learn/fundamentals/data-models/default-properties/page.mdx": "2024-10-21T13:30:21.368Z",
@@ -51,9 +51,9 @@ export const generatedEditDates = {
"app/learn/fundamentals/api-routes/parameters/page.mdx": "2024-11-19T16:37:47.251Z",
"app/learn/fundamentals/api-routes/http-methods/page.mdx": "2024-10-21T13:30:21.367Z",
"app/learn/fundamentals/admin/tips/page.mdx": "2024-11-19T16:43:01.662Z",
"app/learn/fundamentals/api-routes/cors/page.mdx": "2024-10-21T13:30:21.366Z",
"app/learn/fundamentals/api-routes/cors/page.mdx": "2024-12-09T13:04:04.357Z",
"app/learn/fundamentals/admin/ui-routes/page.mdx": "2024-12-04T11:02:57.133Z",
"app/learn/fundamentals/api-routes/middlewares/page.mdx": "2024-10-21T13:30:21.367Z",
"app/learn/fundamentals/api-routes/middlewares/page.mdx": "2024-12-09T13:04:03.712Z",
"app/learn/fundamentals/modules/isolation/page.mdx": "2024-12-09T11:02:38.087Z",
"app/learn/fundamentals/data-models/configure-properties/page.mdx": "2024-10-21T13:30:21.368Z",
"app/learn/fundamentals/data-models/index/page.mdx": "2024-10-21T13:30:21.368Z",
@@ -67,7 +67,7 @@ export const generatedEditDates = {
"app/learn/debugging-and-testing/testing-tools/unit-tests/page.mdx": "2024-09-02T11:03:26.997Z",
"app/learn/fundamentals/modules/service-constraints/page.mdx": "2024-11-19T16:37:47.253Z",
"app/learn/fundamentals/api-routes/responses/page.mdx": "2024-10-21T13:30:21.367Z",
"app/learn/fundamentals/api-routes/validation/page.mdx": "2024-12-09T11:02:38.397Z",
"app/learn/fundamentals/api-routes/validation/page.mdx": "2024-12-09T13:04:02.426Z",
"app/learn/fundamentals/api-routes/errors/page.mdx": "2024-10-21T13:30:21.367Z",
"app/learn/fundamentals/admin/constraints/page.mdx": "2024-10-21T13:30:21.366Z",
"app/learn/debugging-and-testing/testing-tools/modules-tests/module-example/page.mdx": "2024-10-16T08:50:03.061Z",
@@ -75,18 +75,18 @@ export const generatedEditDates = {
"app/learn/fundamentals/module-links/custom-columns/page.mdx": "2024-11-20T14:32:09.764Z",
"app/learn/fundamentals/module-links/directions/page.mdx": "2024-10-21T13:30:21.369Z",
"app/learn/fundamentals/module-links/page.mdx": "2024-10-28T04:22:27.541Z",
"app/learn/fundamentals/module-links/query/page.mdx": "2024-12-09T10:38:41.169Z",
"app/learn/fundamentals/module-links/query/page.mdx": "2024-12-09T13:04:01.779Z",
"app/learn/fundamentals/module-links/remote-link/page.mdx": "2024-10-28T04:22:21.328Z",
"app/learn/fundamentals/modules/db-operations/page.mdx": "2024-12-04T11:02:57.134Z",
"app/learn/fundamentals/modules/multiple-services/page.mdx": "2024-10-21T13:30:21.370Z",
"app/learn/fundamentals/modules/page.mdx": "2024-12-09T11:02:37.696Z",
"app/learn/debugging-and-testing/instrumentation/page.mdx": "2024-09-17T08:53:15.910Z",
"app/learn/fundamentals/api-routes/additional-data/page.mdx": "2024-12-09T10:46:28.589Z",
"app/learn/fundamentals/api-routes/additional-data/page.mdx": "2024-12-09T13:04:04.995Z",
"app/learn/fundamentals/workflows/variable-manipulation/page.mdx": "2024-11-19T16:43:01.663Z",
"app/learn/customization/custom-features/api-route/page.mdx": "2024-12-09T10:39:30.046Z",
"app/learn/customization/custom-features/module/page.mdx": "2024-12-09T11:02:39.826Z",
"app/learn/customization/custom-features/workflow/page.mdx": "2024-12-09T10:46:47.051Z",
"app/learn/customization/extend-features/extend-create-product/page.mdx": "2024-12-09T11:02:39.423Z",
"app/learn/customization/extend-features/extend-create-product/page.mdx": "2024-12-09T12:59:23.364Z",
"app/learn/customization/custom-features/page.mdx": "2024-12-09T10:46:28.593Z",
"app/learn/customization/customize-admin/page.mdx": "2024-12-09T11:02:38.801Z",
"app/learn/customization/customize-admin/route/page.mdx": "2024-12-09T11:02:38.969Z",