Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

docs: update imports of middlewares and http types #9440

Merged
merged 4 commits into from
Oct 3, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ For example:
import type {
MedusaRequest,
MedusaResponse,
} from "@medusajs/medusa"
} from "@medusajs/framework/http"

export const GET = (
req: MedusaRequest,
Expand Down Expand Up @@ -86,7 +86,7 @@ import type {
MedusaNextFunction,
MedusaRequest,
MedusaResponse,
} from "@medusajs/medusa"
} from "@medusajs/framework/http"
import { ConfigModule } from "@medusajs/framework/types"
import { parseCorsOrigins } from "@medusajs/framework/utils"
import cors from "cors"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ The Medusa application's API route error handler then wraps your thrown error in
For example:

```ts
import { MedusaRequest, MedusaResponse } from "@medusajs/medusa"
import { MedusaRequest, MedusaResponse } from "@medusajs/framework/http"
import { MedusaError } from "@medusajs/framework/utils"

export const GET = async (
Expand Down Expand Up @@ -257,7 +257,7 @@ import {
MedusaNextFunction,
MedusaRequest,
MedusaResponse,
} from "@medusajs/medusa"
} from "@medusajs/framework/http"
import { MedusaError } from "@medusajs/framework/utils"

export default defineMiddlewares({
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ For example, create the file `src/api/hello-world/route.ts` with the following c
import type {
MedusaRequest,
MedusaResponse,
} from "@medusajs/medusa"
} from "@medusajs/framework/http"

export const GET = async (
req: MedusaRequest,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ import type {
MedusaNextFunction,
MedusaRequest,
MedusaResponse,
} from "@medusajs/medusa"
} from "@medusajs/framework/http"

export default defineMiddlewares({
routes: [
Expand Down Expand Up @@ -123,7 +123,7 @@ import type {
MedusaNextFunction,
MedusaRequest,
MedusaResponse,
} from "@medusajs/medusa"
} from "@medusajs/framework/http"

export default defineMiddlewares({
routes: [
Expand Down Expand Up @@ -155,7 +155,7 @@ import type {
MedusaNextFunction,
MedusaRequest,
MedusaResponse,
} from "@medusajs/medusa"
} from "@medusajs/framework/http"

export default defineMiddlewares({
routes: [
Expand Down Expand Up @@ -188,7 +188,7 @@ import type {
MedusaNextFunction,
MedusaRequest,
MedusaResponse,
} from "@medusajs/medusa"
} from "@medusajs/framework/http"

export default defineMiddlewares({
routes: [
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ export const singlePathHighlights = [
import type {
MedusaRequest,
MedusaResponse,
} from "@medusajs/medusa"
} from "@medusajs/framework/http"

export const GET = async (
req: MedusaRequest,
Expand Down Expand Up @@ -49,7 +49,7 @@ export const multiplePathHighlights = [
import type {
MedusaRequest,
MedusaResponse,
} from "@medusajs/medusa"
} from "@medusajs/framework/http"

export const GET = async (
req: MedusaRequest,
Expand Down Expand Up @@ -81,7 +81,7 @@ export const queryHighlights = [
import type {
MedusaRequest,
MedusaResponse,
} from "@medusajs/medusa"
} from "@medusajs/framework/http"

export const GET = async (
req: MedusaRequest,
Expand Down Expand Up @@ -112,7 +112,7 @@ export const bodyHighlights = [
import type {
MedusaRequest,
MedusaResponse,
} from "@medusajs/medusa"
} from "@medusajs/framework/http"

type HelloWorldReq = {
name: string
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ For example:
import type {
AuthenticatedMedusaRequest,
MedusaResponse,
} from "@medusajs/medusa"
} from "@medusajs/framework/http"

export const GET = async (
req: AuthenticatedMedusaRequest,
Expand Down Expand Up @@ -124,7 +124,7 @@ For example:
import type {
AuthenticatedMedusaRequest,
MedusaResponse,
} from "@medusajs/medusa"
} from "@medusajs/framework/http"
import { Modules } from "@medusajs/framework/utils"
import { ICustomerModuleService } from "@medusajs/framework/types"

Expand Down Expand Up @@ -159,7 +159,7 @@ For example:
import type {
AuthenticatedMedusaRequest,
MedusaResponse,
} from "@medusajs/medusa"
} from "@medusajs/framework/http"
import { Modules } from "@medusajs/framework/utils"
import { IUserModuleService } from "@medusajs/framework/types"

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ export const jsonHighlights = [
]

```ts title="src/api/custom/route.ts" highlights={jsonHighlights}
import { MedusaRequest, MedusaResponse } from "@medusajs/medusa"
import { MedusaRequest, MedusaResponse } from "@medusajs/framework/http"

export const GET = async (
req: MedusaRequest,
Expand Down Expand Up @@ -52,7 +52,7 @@ export const statusHighlight = [
]

```ts title="src/api/custom/route.ts" highlights={statusHighlight}
import { MedusaRequest, MedusaResponse } from "@medusajs/medusa"
import { MedusaRequest, MedusaResponse } from "@medusajs/framework/http"

export const GET = async (
req: MedusaRequest,
Expand Down Expand Up @@ -84,7 +84,7 @@ export const streamHighlights = [
]

```ts highlights={streamHighlights}
import { MedusaRequest, MedusaResponse } from "@medusajs/medusa"
import { MedusaRequest, MedusaResponse } from "@medusajs/framework/http"

export const GET = async (
req: MedusaRequest,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,15 +41,15 @@ The `PostStoreCustomSchema` variable is a Zod schema that indicates the request

## Step 2: Add Validation Middleware

To use this schema for validating the body parameters of requests to `/custom`, use the `validateAndTransformBody` middleware provided by `@medusajs/medusa`. It accepts the Zod schema as a parameter.
To use this schema for validating the body parameters of requests to `/custom`, use the `validateAndTransformBody` middleware provided by `@medusajs/framework/utils`. It accepts the Zod schema as a parameter.

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 {
validateAndTransformBody,
} from "@medusajs/medusa/api/utils/validate-body"
} from "@medusajs/framework/utils"
import { PostStoreCustomSchema } from "./custom/validators"

export default defineMiddlewares({
Expand Down Expand Up @@ -87,7 +87,7 @@ export const routeHighlights = [
]

```ts title="src/api/custom/route.ts" highlights={routeHighlights}
import { MedusaRequest, MedusaResponse } from "@medusajs/medusa"
import { MedusaRequest, MedusaResponse } from "@medusajs/framework/http"
import { z } from "zod"
import { PostStoreCustomSchema } from "./validators"

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ export const highlights = [
import type {
SubscriberArgs,
SubscriberConfig,
} from "@medusajs/medusa"
} from "@medusajs/framework"

export default async function productCreateHandler({
event,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ export const exampleHighlights = [
import {
MedusaRequest,
MedusaResponse,
} from "@medusajs/medusa"
} from "@medusajs/framework/http"
import {
ContainerRegistrationKeys,
} from "@medusajs/framework/utils"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ For example:
import {
MedusaRequest,
MedusaResponse,
} from "@medusajs/medusa"
} from "@medusajs/framework/http"
import {
ContainerRegistrationKeys,
} from "@medusajs/framework/utils"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ export const highlights = [
import type {
MedusaRequest,
MedusaResponse,
} from "@medusajs/medusa"
} from "@medusajs/framework/http"
import myWorkflow from "../../../workflows/hello-world"

export async function GET(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ Finally, execute the workflow from an API route:
import type {
MedusaRequest,
MedusaResponse,
} from "@medusajs/medusa"
} from "@medusajs/framework/http"
import myWorkflow from "../../../workflows/hello-world"

export async function GET(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -284,7 +284,7 @@ export const highlights = [
]

```ts title="src/api/workflows/route.ts" highlights={highlights} collapsibleLines="1-11" expandButtonLabel="Show Imports"
import type { MedusaRequest, MedusaResponse } from "@medusajs/medusa"
import type { MedusaRequest, MedusaResponse } from "@medusajs/framework/http"
import myWorkflow from "../../../workflows/hello-world"
import {
IWorkflowEngineService,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ Learn how to pass `additional_data` in requests to API routes in [this chapter](
You can also pass that additional data when executing the workflow. Pass it as a parameter to the `.run` method of the workflow:

```ts title="src/workflows/hooks/product-created.ts" highlights={[["10", "additional_data"]]}
import type { MedusaRequest, MedusaResponse } from "@medusajs/medusa"
import type { MedusaRequest, MedusaResponse } from "@medusajs/framework/http"
import { createProductsWorkflow } from "@medusajs/medusa/core-flows"

export async function POST(req: MedusaRequest, res: MedusaResponse) {
Expand Down
2 changes: 1 addition & 1 deletion www/apps/book/app/basics/api-routes/page.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ For example, to create a `GET` API Route at `/hello-world`, create the file `src
import type {
MedusaRequest,
MedusaResponse,
} from "@medusajs/medusa"
} from "@medusajs/framework/http"

export const GET = (
req: MedusaRequest,
Expand Down
2 changes: 1 addition & 1 deletion www/apps/book/app/basics/commerce-modules/page.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ Similarly to your custom module, a commerce module's main service is registered
For example, you saw this code snippet in the [Medusa container chapter](../medusa-container/page.mdx):

```ts highlights={[["10"]]}
import type { MedusaRequest, MedusaResponse } from "@medusajs/medusa"
import type { MedusaRequest, MedusaResponse } from "@medusajs/framework/http"
import { IProductModuleService } from "@medusajs/framework/types"
import { Modules } from "@medusajs/framework/utils"

Expand Down
4 changes: 2 additions & 2 deletions www/apps/book/app/basics/events-and-subscribers/page.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ A subscriber is created in a TypeScript or JavaScript file under the `src/subscr
For example, create the file `src/subscribers/product-created.ts` with the following content:

```ts title="src/subscribers/product-created.ts"
import { type SubscriberConfig } from "@medusajs/medusa"
import { type SubscriberConfig } from "@medusajs/framework"

// subscriber function
export default async function productCreateHandler() {
Expand Down Expand Up @@ -89,7 +89,7 @@ export const highlights = [
]

```ts title="src/subscribers/product-created.ts" highlights={highlights}
import { SubscriberArgs, type SubscriberConfig } from "@medusajs/medusa"
import { SubscriberArgs, type SubscriberConfig } from "@medusajs/framework"
import { IProductModuleService } from "@medusajs/framework/types"
import { Modules } from "@medusajs/framework/utils"

Expand Down
2 changes: 1 addition & 1 deletion www/apps/book/app/basics/medusa-container/page.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ export const highlights = [
]

```ts highlights={highlights}
import type { MedusaRequest, MedusaResponse } from "@medusajs/medusa"
import type { MedusaRequest, MedusaResponse } from "@medusajs/framework/http"
import { IProductModuleService } from "@medusajs/framework/types"
import { Modules } from "@medusajs/framework/utils"

Expand Down
2 changes: 1 addition & 1 deletion www/apps/book/app/basics/modules-and-services/page.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ Resolving a module's service is essential to use its methods that perform action
For example, create the API route `src/api/custom/route.ts` with the following content:

```ts title="src/api/custom/route.ts"
import { MedusaRequest, MedusaResponse } from "@medusajs/medusa"
import { MedusaRequest, MedusaResponse } from "@medusajs/framework/http"
import HelloModuleService from "../../modules/hello/service"
import { HELLO_MODULE } from "../../modules/hello"

Expand Down
4 changes: 2 additions & 2 deletions www/apps/book/app/basics/workflows/page.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ To execute the workflow, invoke it passing the Medusa container as a parameter.
import type {
MedusaRequest,
MedusaResponse,
} from "@medusajs/medusa"
} from "@medusajs/framework/http"
import myWorkflow from "../../../workflows/hello-world"

export async function GET(
Expand All @@ -125,7 +125,7 @@ To execute the workflow, invoke it passing the Medusa container as a parameter.
import {
type SubscriberConfig,
type SubscriberArgs,
} from "@medusajs/medusa"
} from "@medusajs/framework"
import myWorkflow from "../workflows/hello-world"
import { Modules } from "@medusajs/framework/utils"
import { IUserModuleService } from "@medusajs/framework/types"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ Create the file `src/api/admin/brands/route.ts` with the following content:
import {
MedusaRequest,
MedusaResponse,
} from "@medusajs/medusa"
} from "@medusajs/framework/http"
import {
CreateBrandInput,
createBrandWorkflow,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ Create the file `src/api/admin/brands/route.ts` with the following content:
import {
MedusaRequest,
MedusaResponse,
} from "@medusajs/medusa"
} from "@medusajs/framework/http"
import { BRAND_MODULE } from "../../../modules/brand"
import BrandModuleService from "../../../modules/brand/service"

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ export const highlights = [
import {
MedusaRequest,
MedusaResponse,
} from "@medusajs/medusa"
} from "@medusajs/framework/http"
import {
ContainerRegistrationKeys,
} from "@medusajs/framework/utils"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,7 @@ To handle the `brand.created` event, create a subscriber at `src/subscribers/bra
import type {
SubscriberConfig,
SubscriberArgs,
} from "@medusajs/medusa"
} from "@medusajs/framework"
import { syncBrandToSystemWorkflow } from "../workflows/sync-brand-to-system"

export default async function brandCreatedHandler({
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ In this chapter, you'll learn how to write integration tests for API routes usin
Consider the following API route created at `src/api/custom/route.ts`:

```ts title="src/api/custom/route.ts"
import { MedusaRequest, MedusaResponse } from "@medusajs/medusa"
import { MedusaRequest, MedusaResponse } from "@medusajs/framework/http"

export async function GET(
req: MedusaRequest,
Expand Down Expand Up @@ -223,7 +223,7 @@ The `afterAll` hook resolves the `HelloModuleService` and use its `deleteMyCusto
Consider a `/custom/:id` API route created at `src/api/custom/[id]/route.ts`:

```ts title="src/api/custom/[id]/route.ts"
import { MedusaRequest, MedusaResponse } from "@medusajs/medusa"
import { MedusaRequest, MedusaResponse } from "@medusajs/framework/http"
import HelloModuleService from "../../../modules/hello/service"

export async function DELETE(
Expand Down
2 changes: 1 addition & 1 deletion www/apps/book/app/first-customizations/page.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ To create an API route, create the file `src/api/hello-world/route.ts` with the
import type {
MedusaRequest,
MedusaResponse,
} from "@medusajs/medusa"
} from "@medusajs/framework/http"

export const GET = (
req: MedusaRequest,
Expand Down
Loading
Loading