docs: make code blocks collapsible (#7606)
* added collapsible code feature * fixed side shadow * fix build errors * change design * make code blocks collapsible
This commit is contained in:
@@ -72,7 +72,7 @@ For example:
|
||||
|
||||
export const highlights = [["18", "parseCorsOrigins", "A utility function that parses the CORS configurations in `medusa-config.js`"]]
|
||||
|
||||
```ts title="src/api/middlewares.ts" highlights={highlights}
|
||||
```ts title="src/api/middlewares.ts" highlights={highlights} collapsibleLines="1-7" expandButtonLabel="Show Imports"
|
||||
import {
|
||||
ConfigModule,
|
||||
MiddlewaresConfig,
|
||||
|
||||
@@ -57,7 +57,7 @@ You can access the logged-in customer’s ID in all API routes starting with `/s
|
||||
|
||||
For example:
|
||||
|
||||
```ts title="src/api/store/customers/me/custom/route.ts" highlights={[["16", "", "Access the logged-in customer's ID."]]}
|
||||
```ts title="src/api/store/customers/me/custom/route.ts" highlights={[["16", "", "Access the logged-in customer's ID."]]} collapsibleLines="1-7" expandButtonLabel="Show Imports"
|
||||
import type {
|
||||
AuthenticatedMedusaRequest,
|
||||
MedusaResponse,
|
||||
@@ -90,7 +90,7 @@ You can access the logged-in admin user’s ID in all API Routes starting with `
|
||||
|
||||
For example:
|
||||
|
||||
```ts title="src/api/admin/custom/route.ts" highlights={[["16", "req.user.userId", "Access the logged-in admin user's ID."]]}
|
||||
```ts title="src/api/admin/custom/route.ts" highlights={[["16", "req.user.userId", "Access the logged-in admin user's ID."]]} collapsibleLines="1-7" expandButtonLabel="Show Imports"
|
||||
import type {
|
||||
AuthenticatedMedusaRequest,
|
||||
MedusaResponse,
|
||||
@@ -125,12 +125,11 @@ To protect custom API Routes that don’t start with `/store/customers/me` or `/
|
||||
For example:
|
||||
|
||||
export const highlights = [
|
||||
["11", "authenticate", "Only authenticated admin users can access routes starting with `/custom/admin`"],
|
||||
["17", "authenticate", "Only authenticated customers can access routes starting with `/custom/customers`"]
|
||||
["8", "authenticate", "Only authenticated admin users can access routes starting with `/custom/admin`"],
|
||||
["14", "authenticate", "Only authenticated customers can access routes starting with `/custom/customers`"]
|
||||
]
|
||||
|
||||
```ts title="src/api/middlewares.ts" highlights={highlights}
|
||||
// TODO update import
|
||||
import { MiddlewaresConfig, authenticate } from "@medusajs/medusa"
|
||||
|
||||
export const config: MiddlewaresConfig = {
|
||||
|
||||
@@ -35,7 +35,7 @@ For building relationships between data models in different modules, refer to th
|
||||
|
||||
The following example showcase a data model with common definitions:
|
||||
|
||||
```ts
|
||||
```ts collapsibleLines="1-10" expandButtonLabel="Show Imports"
|
||||
import {
|
||||
Entity,
|
||||
Enum,
|
||||
|
||||
@@ -20,7 +20,7 @@ When retrieving or listing records of that data model, records having their `del
|
||||
|
||||
To create a soft-deletable model, first, add the following filter decorator to the data model class:
|
||||
|
||||
```ts title="src/module/hello/models/my-soft-deletable.ts" highlights={[["7"]]}
|
||||
```ts title="src/module/hello/models/my-soft-deletable.ts" highlights={[["7"]]} collapsibleLines="1-7" expandButtonLabel="Show Imports"
|
||||
// other imports...
|
||||
import { Entity, Filter } from "@mikro-orm/core"
|
||||
import { DALUtils } from "@medusajs/utils"
|
||||
|
||||
@@ -20,10 +20,10 @@ export const highlights = [
|
||||
["9", '"data" in data ? data.data.id : data.id', "The payload data is either in `data.data` or directly in `data`."]
|
||||
]
|
||||
|
||||
```ts title="src/subscribers/product-created.ts" highlights={highlights}
|
||||
import {
|
||||
```ts title="src/subscribers/product-created.ts" highlights={highlights} collapsibleLines="1-5" expandButtonLabel="Show Imports"
|
||||
import type {
|
||||
SubscriberArgs,
|
||||
type SubscriberConfig,
|
||||
SubscriberConfig,
|
||||
} from "@medusajs/medusa"
|
||||
|
||||
export default async function productCreateHandler({
|
||||
|
||||
@@ -48,7 +48,7 @@ When the loader function is created outside a module, it receives the Medusa con
|
||||
|
||||
For example:
|
||||
|
||||
```ts title="src/loaders/hello-world.ts"
|
||||
```ts title="src/loaders/hello-world.ts" collapsibleLines="1-5" expandButtonLabel="Show Imports"
|
||||
import { MedusaContainer } from "@medusajs/medusa"
|
||||
import { IProductModuleService } from "@medusajs/types"
|
||||
import { ModuleRegistrationName } from "@medusajs/modules-sdk"
|
||||
|
||||
@@ -40,7 +40,7 @@ The Medusa application resolves these relationships while maintaining isolation
|
||||
|
||||
Consider you’re creating a data model that adds custom fields associated with a product:
|
||||
|
||||
```ts title="src/modules/hello/models/custom-product-data.ts" highlights={[["17"]]}
|
||||
```ts title="src/modules/hello/models/custom-product-data.ts" highlights={[["17"]]} collapsibleLines="1-8" expandButtonLabel="Show Imports"
|
||||
import { BaseEntity } from "@medusajs/utils"
|
||||
import {
|
||||
Entity,
|
||||
@@ -83,7 +83,7 @@ export const relationshipsHighlight = [
|
||||
["42", "foreignKey", "The name of the field in your data models referencing the other module’s model."],
|
||||
]
|
||||
|
||||
```ts title="src/modules/hello/service.ts" highlights={relationshipsHighlight}
|
||||
```ts title="src/modules/hello/service.ts" highlights={relationshipsHighlight} collapsibleLines="1-6" expandButtonLabel="Show Imports"
|
||||
// other imports...
|
||||
import { MyCustom } from "./models/custom-product-data"
|
||||
import { CustomProductData } from "./models/custom-product-data"
|
||||
|
||||
@@ -12,28 +12,27 @@ The remote link is a class with utility methods to manage links defined by the l
|
||||
|
||||
For example:
|
||||
|
||||
```ts
|
||||
```ts collapsibleLines="1-9" expandButtonLabel="Show Imports"
|
||||
import {
|
||||
MedusaRequest,
|
||||
MedusaResponse,
|
||||
} from "@medusajs/medusa"
|
||||
import {
|
||||
ModuleRegistrationName,
|
||||
RemoteLink,
|
||||
} from "@medusajs/modules-sdk"
|
||||
import {
|
||||
ContainerRegistrationKeys,
|
||||
ContainerRegistrationKeys,
|
||||
} from "@medusajs/utils"
|
||||
import {
|
||||
RemoteLink,
|
||||
} from "@medusajs/modules-sdk"
|
||||
|
||||
export async function POST(
|
||||
req: MedusaRequest,
|
||||
res: MedusaResponse
|
||||
): Promise<void> {
|
||||
const remoteLink: RemoteLink = req.scope.resolve(
|
||||
ContainerRegistrationKeys.REMOTE_LINK
|
||||
)
|
||||
|
||||
// ...
|
||||
const remoteLink: RemoteLink = req.scope.resolve(
|
||||
ContainerRegistrationKeys.REMOTE_LINK
|
||||
)
|
||||
|
||||
// ...
|
||||
}
|
||||
```
|
||||
|
||||
|
||||
@@ -28,7 +28,7 @@ export const exampleHighlights = [
|
||||
["27", "remoteQuery", "Run the query using the remote query."]
|
||||
]
|
||||
|
||||
```ts title="src/api/store/query/route.ts" highlights={exampleHighlights} apiTesting testApiMethod="GET" testApiUrl="http://localhost:9000/store/query"
|
||||
```ts title="src/api/store/query/route.ts" highlights={exampleHighlights} apiTesting testApiMethod="GET" testApiUrl="http://localhost:9000/store/query" collapsibleLines="1-12" expandButtonLabel="Show Imports"
|
||||
import {
|
||||
MedusaRequest,
|
||||
MedusaResponse,
|
||||
@@ -210,7 +210,7 @@ The remote query function alternatively accepts a string with GraphQL syntax as
|
||||
|
||||
### Basic GraphQL usage
|
||||
|
||||
```ts title="src/api/store/query/route.ts" apiTesting testApiMethod="GET" testApiUrl="http://localhost:9000/store/query"
|
||||
```ts title="src/api/store/query/route.ts" apiTesting testApiMethod="GET" testApiUrl="http://localhost:9000/store/query" collapsibleLines="1-10" expandButtonLabel="Show Imports"
|
||||
import {
|
||||
MedusaRequest,
|
||||
MedusaResponse,
|
||||
|
||||
@@ -146,7 +146,7 @@ export const typeArgsHighlights = [
|
||||
["27", "AllModelsDTO", "The expected input/output type of the generated methods of every data model."],
|
||||
]
|
||||
|
||||
```ts title="src/modules/hello/service.ts" highlights={typeArgsHighlights}
|
||||
```ts title="src/modules/hello/service.ts" highlights={typeArgsHighlights} collapsibleLines="1-22" expandButtonLabel="Show More"
|
||||
import { ModulesSdkUtils } from "@medusajs/utils"
|
||||
import { MyCustom } from "./models/my-custom"
|
||||
|
||||
|
||||
@@ -19,7 +19,7 @@ export const highlights = [
|
||||
["14", "throwOnError", "Specify that errors occuring during the workflow's execution should be returned, not thrown."],
|
||||
]
|
||||
|
||||
```ts title="src/api/store/workflows/route.ts" highlights={highlights}
|
||||
```ts title="src/api/store/workflows/route.ts" highlights={highlights} collapsibleLines="1-6" expandButtonLabel="Show Imports"
|
||||
import type {
|
||||
MedusaRequest,
|
||||
MedusaResponse,
|
||||
|
||||
@@ -46,7 +46,7 @@ export const updateProductHighlights = [
|
||||
["39", "", "Revert the product’s data using the `previousProductData` passed from the step to the compensation function."]
|
||||
]
|
||||
|
||||
```ts title="src/workflows/update-product-erp/steps/update-product.ts" highlights={updateProductHighlights}
|
||||
```ts title="src/workflows/update-product-erp/steps/update-product.ts" highlights={updateProductHighlights} collapsibleLines="1-9" expandButtonLabel="Show Imports"
|
||||
import {
|
||||
createStep,
|
||||
StepResponse,
|
||||
@@ -145,7 +145,7 @@ export const updateErpHighlights = [
|
||||
["37", "updateProductErpData", "Revert the product's data in the ERP system to its previous state using the `previousErpData`."]
|
||||
]
|
||||
|
||||
```ts title="src/workflows/update-product-erp/steps/update-erp.ts" highlights={updateErpHighlights}
|
||||
```ts title="src/workflows/update-product-erp/steps/update-erp.ts" highlights={updateErpHighlights} collapsibleLines="1-8" expandButtonLabel="Show Imports"
|
||||
import {
|
||||
createStep,
|
||||
StepResponse,
|
||||
@@ -208,7 +208,7 @@ With the steps ready, you'll create the workflow that runs these steps to update
|
||||
|
||||
Change the content of `src/workflows/update-product-erp/index.ts` to the following:
|
||||
|
||||
```ts title="src/workflows/update-product-erp/index.ts"
|
||||
```ts title="src/workflows/update-product-erp/index.ts" collapsibleLines="1-6" expandButtonLabel="Show Imports"
|
||||
import { createWorkflow } from "@medusajs/workflows-sdk"
|
||||
import { UpdateProductDTO, ProductDTO } from "@medusajs/types"
|
||||
import updateProduct from "./steps/update-product"
|
||||
|
||||
@@ -12,7 +12,7 @@ Errors can occur in a workflow. To avoid data inconsistency, define a function t
|
||||
|
||||
For example:
|
||||
|
||||
```ts title="src/workflows/hello-world.ts" highlights={[["16"], ["17"], ["18"]]}
|
||||
```ts title="src/workflows/hello-world.ts" highlights={[["16"], ["17"], ["18"]]} collapsibleLines="1-6" expandButtonLabel="Show Imports"
|
||||
// other imports...
|
||||
import {
|
||||
createStep,
|
||||
@@ -52,7 +52,7 @@ const step2 = createStep(
|
||||
|
||||
2. Use the steps in a workflow. For example:
|
||||
|
||||
```ts title="src/workflows/hello-world.ts"
|
||||
```ts title="src/workflows/hello-world.ts" collapsibleLines="1-7" expandButtonLabel="Show Imports"
|
||||
import {
|
||||
// other imports...
|
||||
createWorkflow,
|
||||
@@ -81,7 +81,7 @@ export default myWorkflow
|
||||
|
||||
3. Execute the workflow from a resource, such as an API route:
|
||||
|
||||
```ts title="src/api/store/workflow/route.ts"
|
||||
```ts title="src/api/store/workflow/route.ts" collapsibleLines="1-6" expandButtonLabel="Show Imports"
|
||||
import type {
|
||||
MedusaRequest,
|
||||
MedusaResponse,
|
||||
|
||||
@@ -22,7 +22,7 @@ A workflow is considered long-running if at least one step has its `async` confi
|
||||
|
||||
For example, consider the following workflow and steps:
|
||||
|
||||
```ts title="src/workflows/hello-world.ts" highlights={[["13"]]}
|
||||
```ts title="src/workflows/hello-world.ts" highlights={[["13"]]} collapsibleLines="1-10" expandButtonLabel="Show More"
|
||||
import {
|
||||
createStep,
|
||||
createWorkflow,
|
||||
@@ -88,7 +88,7 @@ export const highlights = [
|
||||
["24", "subscribe", "Subscribe to status changes of the workflow execution."],
|
||||
]
|
||||
|
||||
```ts title="src/api/store/workflows/route.ts" highlights={highlights}
|
||||
```ts title="src/api/store/workflows/route.ts" highlights={highlights} collapsibleLines="1-11" expandButtonLabel="Show Imports"
|
||||
import type {
|
||||
MedusaRequest,
|
||||
MedusaResponse,
|
||||
|
||||
@@ -19,7 +19,7 @@ export const highlights = [
|
||||
["23", "parallelize", "Run the steps passed as parameters in parallel."],
|
||||
]
|
||||
|
||||
```ts highlights={highlights}
|
||||
```ts highlights={highlights} collapsibleLines="1-12" expandButtonLabel="Show Imports"
|
||||
import {
|
||||
createWorkflow,
|
||||
parallelize,
|
||||
|
||||
@@ -12,7 +12,7 @@ By default, when an error occurs in a step, the step and the workflow fail, and
|
||||
|
||||
You can configure the step to retry on failure. The `createStep` function can accept a configuration object instead of the step’s name as a first parameter:
|
||||
|
||||
```ts title="src/workflows/hello-world.ts" highlights={[["10"]]}
|
||||
```ts title="src/workflows/hello-world.ts" highlights={[["10"]]} collapsibleLines="1-6" expandButtonLabel="Show Imports"
|
||||
import {
|
||||
createStep,
|
||||
StepResponse,
|
||||
|
||||
@@ -20,7 +20,7 @@ Timeout doesn't stop the execution of a running step. The timeout only affects t
|
||||
|
||||
For example:
|
||||
|
||||
```ts title="src/workflows/hello-world.ts" highlights={[["22"]]}
|
||||
```ts title="src/workflows/hello-world.ts" highlights={[["22"]]} collapsibleLines="1-16" expandButtonLabel="Show More"
|
||||
import {
|
||||
createStep,
|
||||
createWorkflow,
|
||||
|
||||
@@ -1,77 +0,0 @@
|
||||
export const metadata = {
|
||||
title: `${pageNumber} Services`,
|
||||
}
|
||||
|
||||
# {metadata.title}
|
||||
|
||||
In this chapter, you'll learn what services are and how to create a service.
|
||||
|
||||
## What is a Service?
|
||||
|
||||
A service is a class that holds methods related to a business logic or commerce functionality. For example, the `ProductService` holds methods to retrieve and manage products.
|
||||
|
||||
---
|
||||
|
||||
## How to Create a Service
|
||||
|
||||
Services are created in a TypeScript or JavaScript file under the `src/services` directory of your Medusa application.
|
||||
|
||||
For example, to create a `HelloWorld` service, create the file `src/services/hello-world.ts` with the following content:
|
||||
|
||||
```ts title="src/services/hello-world.ts"
|
||||
class HelloWorld {
|
||||
// TODO add methods
|
||||
}
|
||||
|
||||
export default HelloWorld
|
||||
```
|
||||
|
||||
<Note title="Tip">
|
||||
|
||||
A service's file name must be the kebab-case name of the service without the word `Service`.
|
||||
|
||||
</Note>
|
||||
|
||||
---
|
||||
|
||||
## When to Use
|
||||
|
||||
<Note title="Use services when" type="success">
|
||||
|
||||
- You're implementing custom commerce functionality to be reused across the Medusa application.
|
||||
- You're integrating a third-party service, such as an ERP system.
|
||||
|
||||
</Note>
|
||||
|
||||
---
|
||||
|
||||
## Resolve Resources
|
||||
|
||||
In a service's constructor, you can resolve other services or resources of your Medusa application using the Medusa container.
|
||||
|
||||
For example, you can resolve the `IProductModuleService` to use it in your methods:
|
||||
|
||||
```ts title="src/services/hello-world.ts" highlights={[["10"]]}
|
||||
import { IProductModuleService } from "@medusajs/types"
|
||||
|
||||
type InjectedDependencies = {
|
||||
productModuleService: IProductModuleService
|
||||
}
|
||||
|
||||
class HelloWorldService {
|
||||
protected productModuleService: IProductModuleService
|
||||
|
||||
constructor({ productModuleService }: InjectedDependencies) {
|
||||
this.productModuleService = productModuleService
|
||||
}
|
||||
|
||||
async getMessage(): Promise<string> {
|
||||
const [, count] =
|
||||
await this.productModuleService.listAndCount()
|
||||
|
||||
return `You have ${count} products`
|
||||
}
|
||||
}
|
||||
|
||||
export default HelloWorldService
|
||||
```
|
||||
+1
-1
@@ -20,7 +20,7 @@ export const highlights = [
|
||||
["21", "data", "The data to pass to the template defined in the third-party service."]
|
||||
]
|
||||
|
||||
```ts title="src/subscribers/product-created.ts" highlights={highlights}
|
||||
```ts title="src/subscribers/product-created.ts" highlights={highlights} collapsibleLines="1-7" expandButtonLabel="Show Imports"
|
||||
import type {
|
||||
SubscriberArgs,
|
||||
SubscriberConfig,
|
||||
|
||||
@@ -146,7 +146,7 @@ export const highlights = [
|
||||
["21", "data", "The data to pass to the template defined in SendGrid."]
|
||||
]
|
||||
|
||||
```ts title="src/subscribers/product-created.ts" highlights={highlights}
|
||||
```ts title="src/subscribers/product-created.ts" highlights={highlights} collapsibleLines="1-7" expandButtonLabel="Show Imports"
|
||||
import type {
|
||||
SubscriberArgs,
|
||||
SubscriberConfig,
|
||||
|
||||
@@ -119,7 +119,7 @@ In this guide, you’ll find common examples of how you can use the API Key Modu
|
||||
<CodeTabs groupId="app-type">
|
||||
<CodeTab label="Medusa API Router" value="medusa">
|
||||
|
||||
```ts
|
||||
```ts collapsibleLines="1-9" expandButtonLabel="Show Imports"
|
||||
import {
|
||||
AuthenticatedMedusaRequest,
|
||||
MedusaResponse
|
||||
@@ -257,7 +257,7 @@ In this guide, you’ll find common examples of how you can use the API Key Modu
|
||||
<CodeTabs groupId="app-type">
|
||||
<CodeTab label="Medusa API Router" value="medusa">
|
||||
|
||||
```ts
|
||||
```ts collapsibleLines="1-8" expandButtonLabel="Show Imports"
|
||||
import {
|
||||
AuthenticatedMedusaRequest,
|
||||
MedusaResponse
|
||||
|
||||
@@ -19,7 +19,7 @@ This example uses the [jsonwebtoken NPM package](https://www.npmjs.com/package/j
|
||||
<CodeTabs groupId="app-type">
|
||||
<CodeTab label="Medusa API Router" value="medusa">
|
||||
|
||||
```ts
|
||||
```ts collapsibleLines="1-10" expandButtonLabel="Show Imports"
|
||||
import { MedusaRequest, MedusaResponse } from "@medusajs/medusa"
|
||||
import {
|
||||
IAuthModuleService,
|
||||
@@ -122,7 +122,7 @@ This example uses the [jsonwebtoken NPM package](https://www.npmjs.com/package/j
|
||||
<CodeTabs groupId="app-type">
|
||||
<CodeTab label="Medusa API Router" value="medusa">
|
||||
|
||||
```ts
|
||||
```ts collapsibleLines="1-10" expandButtonLabel="Show Imports"
|
||||
import { MedusaRequest, MedusaResponse } from "@medusajs/medusa"
|
||||
import {
|
||||
IAuthModuleService,
|
||||
@@ -171,7 +171,7 @@ This example uses the [jsonwebtoken NPM package](https://www.npmjs.com/package/j
|
||||
</CodeTab>
|
||||
<CodeTab label="Next.js App Router" value="nextjs">
|
||||
|
||||
```ts
|
||||
```ts collapsibleLines="1-7" expandButtonLabel="Show Imports"
|
||||
import { NextResponse } from "next/server"
|
||||
|
||||
import {
|
||||
|
||||
@@ -41,7 +41,7 @@ Learn more about actions in the [Promotion Module’s documentation](../../promo
|
||||
|
||||
</Note>
|
||||
|
||||
```ts
|
||||
```ts collapsibleLines="1-8" expandButtonLabel="Show Imports"
|
||||
import {
|
||||
ComputeActionAdjustmentLine,
|
||||
ComputeActionItemLine,
|
||||
@@ -101,7 +101,7 @@ The `computeActions` method accepts the existing adjustments of line items and s
|
||||
|
||||
Then, use the returned `addItemAdjustment` and `addShippingMethodAdjustment` actions to set the cart’s line item and the shipping method’s adjustments.
|
||||
|
||||
```ts
|
||||
```ts collapsibleLines="1-9" expandButtonLabel="Show Imports"
|
||||
import {
|
||||
AddItemAdjustmentAction,
|
||||
AddShippingMethodAdjustment,
|
||||
|
||||
@@ -41,7 +41,7 @@ Learn more about actions in the [Promotion Module’s documentation](../../promo
|
||||
|
||||
</Note>
|
||||
|
||||
```ts
|
||||
```ts collapsibleLines="1-10" expandButtonLabel="Show Imports"
|
||||
import {
|
||||
ComputeActionAdjustmentLine,
|
||||
ComputeActionItemLine,
|
||||
@@ -103,7 +103,7 @@ The `computeActions` method accepts the existing adjustments of line items and s
|
||||
|
||||
Then, use the returned `addItemAdjustment` and `addShippingMethodAdjustment` actions to set the order’s line items and the shipping method’s adjustments.
|
||||
|
||||
```ts
|
||||
```ts collapsibleLines="1-9" expandButtonLabel="Show Imports"
|
||||
import {
|
||||
AddItemAdjustmentAction,
|
||||
AddShippingMethodAdjustment,
|
||||
|
||||
@@ -323,7 +323,7 @@ In this document, you’ll find common examples of how you can use the Pricing M
|
||||
<CodeTabs groupId="app-type">
|
||||
<CodeTab value="medusa" label="Medusa API Router">
|
||||
|
||||
```ts
|
||||
```ts collapsibleLines="1-8" expandButtonLabel="Show Imports"
|
||||
import { MedusaRequest, MedusaResponse } from "@medusajs/medusa"
|
||||
import {
|
||||
IPricingModuleService,
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import { Table, LegacyCodeTabs } from "docs-ui"
|
||||
import { Table, CodeTabs, CodeTab } from "docs-ui"
|
||||
|
||||
export const metadata = {
|
||||
title: `Medusa JS Client`,
|
||||
@@ -267,13 +267,11 @@ Once the user or customer is authenticated successfully, the Medusa client autom
|
||||
|
||||
For example:
|
||||
|
||||
<LegacyCodeTabs tabs={[
|
||||
{
|
||||
label: "Admin User",
|
||||
value: "user",
|
||||
code: {
|
||||
lang: "ts",
|
||||
source: `import Medusa from "@medusajs/medusa-js"
|
||||
<CodeTabs group="client-authentication-type">
|
||||
<CodeTab label="Admin User" value="user">
|
||||
|
||||
```ts
|
||||
import Medusa from "@medusajs/medusa-js"
|
||||
const medusa = new Medusa({
|
||||
baseUrl: MEDUSA_BACKEND_URL,
|
||||
maxRetries: 3,
|
||||
@@ -282,15 +280,14 @@ For example:
|
||||
email: "user@example.com",
|
||||
password: "supersecret",
|
||||
})
|
||||
// send authenticated requests now`
|
||||
}
|
||||
},
|
||||
{
|
||||
label: "Customer",
|
||||
value: "customer",
|
||||
code: {
|
||||
lang: "ts",
|
||||
source: `import Medusa from "@medusajs/medusa-js"
|
||||
// send authenticated requests now
|
||||
```
|
||||
|
||||
</CodeTab>
|
||||
<CodeTab label="Customer" value="customer">
|
||||
|
||||
```ts
|
||||
import Medusa from "@medusajs/medusa-js"
|
||||
const medusa = new Medusa({
|
||||
baseUrl: MEDUSA_BACKEND_URL,
|
||||
maxRetries: 3,
|
||||
@@ -299,10 +296,11 @@ For example:
|
||||
email: "user@example.com",
|
||||
password: "supersecret",
|
||||
})
|
||||
// send authenticated requests now`
|
||||
}
|
||||
}
|
||||
]} group="client-authentication-type" />
|
||||
// send authenticated requests now
|
||||
```
|
||||
|
||||
</CodeTab>
|
||||
</CodeTabs>
|
||||
|
||||
### Cookie Session ID
|
||||
|
||||
@@ -314,13 +312,11 @@ Once the user or customer is authenticated successfully, the Medusa client sets
|
||||
|
||||
For example:
|
||||
|
||||
<LegacyCodeTabs tabs={[
|
||||
{
|
||||
label: "Admin User",
|
||||
value: "user",
|
||||
code: {
|
||||
lang: "ts",
|
||||
source: `import Medusa from "@medusajs/medusa-js"
|
||||
<CodeTabs group="client-authentication-type">
|
||||
<CodeTab label="Admin User" value="user">
|
||||
|
||||
```ts
|
||||
import Medusa from "@medusajs/medusa-js"
|
||||
const medusa = new Medusa({
|
||||
baseUrl: MEDUSA_BACKEND_URL,
|
||||
maxRetries: 3,
|
||||
@@ -329,15 +325,14 @@ For example:
|
||||
email: "user@example.com",
|
||||
password: "supersecret",
|
||||
})
|
||||
// send authenticated requests now`
|
||||
}
|
||||
},
|
||||
{
|
||||
label: "Customer",
|
||||
value: "customer",
|
||||
code: {
|
||||
lang: "ts",
|
||||
source: `import Medusa from "@medusajs/medusa-js"
|
||||
// send authenticated requests now
|
||||
```
|
||||
|
||||
</CodeTab>
|
||||
<CodeTab label="Customer" value="customer">
|
||||
|
||||
```ts
|
||||
import Medusa from "@medusajs/medusa-js"
|
||||
const medusa = new Medusa({
|
||||
baseUrl: MEDUSA_BACKEND_URL,
|
||||
maxRetries: 3,
|
||||
@@ -346,10 +341,11 @@ For example:
|
||||
email: "user@example.com",
|
||||
password: "user@example.com",
|
||||
})
|
||||
// send authenticated requests now`
|
||||
}
|
||||
}
|
||||
]} group="client-authentication-type" />
|
||||
// send authenticated requests now
|
||||
```
|
||||
|
||||
</CodeTab>
|
||||
</CodeTabs>
|
||||
|
||||
### API Key
|
||||
|
||||
@@ -357,13 +353,11 @@ You can authenticate admin users with a personal API Token.
|
||||
|
||||
If a user doesn't have a personal API token, create one with the [admin.users.update](/references/js-client/AdminUsersResource#update) method or the [Update User API route](https://docs.medusajs.com/api/admin#users_postusersuser):
|
||||
|
||||
<LegacyCodeTabs tabs={[
|
||||
{
|
||||
label: "JS Client",
|
||||
value: "js-client",
|
||||
code: {
|
||||
lang: "ts",
|
||||
source: `import Medusa from "@medusajs/medusa-js"
|
||||
<CodeTabs group="client-type">
|
||||
<CodeTab label="JS Client" value="js-client">
|
||||
|
||||
```ts
|
||||
import Medusa from "@medusajs/medusa-js"
|
||||
const medusa = new Medusa({
|
||||
baseUrl: MEDUSA_BACKEND_URL,
|
||||
maxRetries: 3,
|
||||
@@ -374,23 +368,23 @@ If a user doesn't have a personal API token, create one with the [admin.users.up
|
||||
})
|
||||
.then(({ user }) => {
|
||||
console.log(user.api_token)
|
||||
})`
|
||||
}
|
||||
},
|
||||
{
|
||||
label: "cURL",
|
||||
value: "curl",
|
||||
code: {
|
||||
lang: "bash",
|
||||
source: `curl -L -X POST '<BACKEND_URL>/admin/users/<USER_ID>' \\
|
||||
})
|
||||
```
|
||||
|
||||
</CodeTab>
|
||||
<CodeTab label="cURL" value="curl">
|
||||
|
||||
```bash
|
||||
curl -L -X POST '<BACKEND_URL>/admin/users/<USER_ID>' \\
|
||||
-H 'Cookie: connect.sid={sid}' \\
|
||||
-H 'Content-Type: application/json' \\
|
||||
--data-raw '{
|
||||
"api_token": "{api_token}"
|
||||
}'`
|
||||
}
|
||||
}
|
||||
]} group="client-type" />
|
||||
}'
|
||||
```
|
||||
|
||||
</CodeTab>
|
||||
</CodeTabs>
|
||||
|
||||
Then, initialize the Medusa client passing it the `apiKey` option:
|
||||
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import { Table, LegacyCodeTabs } from "docs-ui"
|
||||
import { Table, CodeTabs, CodeTab } from "docs-ui"
|
||||
|
||||
export const metadata = {
|
||||
title: `Medusa React`,
|
||||
@@ -216,13 +216,11 @@ There are two ways to authenticate an admin user:
|
||||
|
||||
For example:
|
||||
|
||||
<LegacyCodeTabs tabs={[
|
||||
{
|
||||
value: "useadminlogin",
|
||||
label: "useAdminLogin hook",
|
||||
code: {
|
||||
lang: "ts",
|
||||
source: `import React from "react"
|
||||
<CodeTabs group="admin-auth">
|
||||
<CodeTab label="useAdminLogin hook" value="useadminlogin">
|
||||
|
||||
```ts
|
||||
import React from "react"
|
||||
import { useAdminLogin } from "medusa-react"
|
||||
|
||||
const Login = () => {
|
||||
@@ -244,15 +242,14 @@ For example:
|
||||
// ...
|
||||
}
|
||||
|
||||
export default Login`
|
||||
}
|
||||
},
|
||||
{
|
||||
value: "apikey",
|
||||
label: "apikey Option",
|
||||
code: {
|
||||
lang: "tsx",
|
||||
source: `import { MedusaProvider } from "medusa-react"
|
||||
export default Login
|
||||
```
|
||||
|
||||
</CodeTab>
|
||||
<CodeTab label="apikey Option" value="apikey">
|
||||
|
||||
```tsx
|
||||
import { MedusaProvider } from "medusa-react"
|
||||
import Storefront from "./Storefront"
|
||||
import { QueryClient } from "@tanstack/react-query"
|
||||
import React from "react"
|
||||
@@ -271,10 +268,11 @@ For example:
|
||||
)
|
||||
}
|
||||
|
||||
export default App`
|
||||
}
|
||||
}
|
||||
]} group="admin-auth" />
|
||||
export default App
|
||||
```
|
||||
|
||||
</CodeTab>
|
||||
</CodeTabs>
|
||||
|
||||
### Customer Authentication
|
||||
|
||||
|
||||
+18
-23
@@ -1,4 +1,4 @@
|
||||
import { LegacyCodeTabs } from "docs-ui"
|
||||
import { CodeTabs, CodeTab } from "docs-ui"
|
||||
|
||||
If you install the Medusa CLI tool with Yarn, then try to use the CLI tool but get the error:
|
||||
|
||||
@@ -8,28 +8,23 @@ command not found: medusa
|
||||
|
||||
You have to add Yarn’s install location to the PATH variable:
|
||||
|
||||
<LegacyCodeTabs
|
||||
tabs={[
|
||||
{
|
||||
label: "MacOS / Linux",
|
||||
value: "unix",
|
||||
code: {
|
||||
lang: "bash",
|
||||
source: `export PATH="$(yarn global bin):$PATH"`
|
||||
}
|
||||
},
|
||||
{
|
||||
label: "Windows",
|
||||
value: "windows",
|
||||
code: {
|
||||
lang: "bash",
|
||||
source: `# MAKE SURE TO INCLUDE %path%
|
||||
<CodeTabs group="operating-systems">
|
||||
<CodeTab label="MacOS / Linux" value="unix">
|
||||
|
||||
```plain
|
||||
export PATH="$(yarn global bin):$PATH
|
||||
```
|
||||
|
||||
</CodeTab>
|
||||
<CodeTab label="Windows" value="windows">
|
||||
|
||||
```bash
|
||||
# MAKE SURE TO INCLUDE %path%
|
||||
setx path "%path%;c:\\users\\YOURUSERNAME\\appdata\\local\\yarnbin"
|
||||
# YOURUSERNAME is your account username`
|
||||
}
|
||||
}
|
||||
]}
|
||||
group="operating-systems"
|
||||
/>
|
||||
# YOURUSERNAME is your account username
|
||||
```
|
||||
|
||||
</CodeTab>
|
||||
</CodeTabs>
|
||||
|
||||
You can learn more in [Yarn’s documentation](https://classic.yarnpkg.com/en/docs/cli/global#adding-the-install-location-to-your-path).
|
||||
+19
-21
@@ -1,26 +1,24 @@
|
||||
import { LegacyCodeTabs } from "docs-ui"
|
||||
import { CodeTabs, CodeTab } from "docs-ui"
|
||||
|
||||
This error can occur while installing any of Medusa's projects (for example, Next.js Starter Template). There is no specific cause to this error.
|
||||
|
||||
One way to resolve it is by removing the `node_modules` directory in the project and re-installing the dependencies:
|
||||
|
||||
<LegacyCodeTabs tabs={[
|
||||
{
|
||||
label: "MacOS / Linux",
|
||||
value: "unix",
|
||||
code: {
|
||||
lang: "bash",
|
||||
source: `rm -rf node_modules
|
||||
yarn install`
|
||||
}
|
||||
},
|
||||
{
|
||||
label: "Windows",
|
||||
value: "windows",
|
||||
code: {
|
||||
lang: "bash",
|
||||
source: `rd /s /q node_modules
|
||||
yarn install`
|
||||
}
|
||||
}
|
||||
]} group="operating-systems" />
|
||||
<CodeTabs group="operating-systems">
|
||||
<CodeTab label="MacOS / Linux" value="unix">
|
||||
|
||||
```bash
|
||||
rm -rf node_modules
|
||||
yarn install
|
||||
```
|
||||
|
||||
</CodeTab>
|
||||
<CodeTab label="Windows" value="windows">
|
||||
|
||||
```bash
|
||||
rd /s /q node_modules
|
||||
yarn install
|
||||
```
|
||||
|
||||
</CodeTab>
|
||||
</CodeTabs>
|
||||
@@ -227,6 +227,10 @@ export const filesMap = [
|
||||
"filePath": "/www/apps/resources/app/architectural-modules/workflow-engine/redis/page.mdx",
|
||||
"pathname": "/architectural-modules/workflow-engine/redis"
|
||||
},
|
||||
{
|
||||
"filePath": "/www/apps/resources/app/commerce-modules/api-key/concepts/page.mdx",
|
||||
"pathname": "/commerce-modules/api-key/concepts"
|
||||
},
|
||||
{
|
||||
"filePath": "/www/apps/resources/app/commerce-modules/api-key/events/_events-table/page.mdx",
|
||||
"pathname": "/commerce-modules/api-key/events/_events-table"
|
||||
@@ -247,10 +251,6 @@ export const filesMap = [
|
||||
"filePath": "/www/apps/resources/app/commerce-modules/api-key/relations-to-other-modules/page.mdx",
|
||||
"pathname": "/commerce-modules/api-key/relations-to-other-modules"
|
||||
},
|
||||
{
|
||||
"filePath": "/www/apps/resources/app/commerce-modules/api-key/tokens/page.mdx",
|
||||
"pathname": "/commerce-modules/api-key/tokens"
|
||||
},
|
||||
{
|
||||
"filePath": "/www/apps/resources/app/commerce-modules/auth/auth-flows/page.mdx",
|
||||
"pathname": "/commerce-modules/auth/auth-flows"
|
||||
@@ -331,6 +331,10 @@ export const filesMap = [
|
||||
"filePath": "/www/apps/resources/app/commerce-modules/currency/page.mdx",
|
||||
"pathname": "/commerce-modules/currency"
|
||||
},
|
||||
{
|
||||
"filePath": "/www/apps/resources/app/commerce-modules/currency/relations-to-other-modules/page.mdx",
|
||||
"pathname": "/commerce-modules/currency/relations-to-other-modules"
|
||||
},
|
||||
{
|
||||
"filePath": "/www/apps/resources/app/commerce-modules/customer/customer-accounts/page.mdx",
|
||||
"pathname": "/commerce-modules/customer/customer-accounts"
|
||||
@@ -687,6 +691,10 @@ export const filesMap = [
|
||||
"filePath": "/www/apps/resources/app/commerce-modules/store/page.mdx",
|
||||
"pathname": "/commerce-modules/store"
|
||||
},
|
||||
{
|
||||
"filePath": "/www/apps/resources/app/commerce-modules/store/relations-to-other-modules/page.mdx",
|
||||
"pathname": "/commerce-modules/store/relations-to-other-modules"
|
||||
},
|
||||
{
|
||||
"filePath": "/www/apps/resources/app/commerce-modules/tax/events/_events-table/page.mdx",
|
||||
"pathname": "/commerce-modules/tax/events/_events-table"
|
||||
@@ -743,10 +751,6 @@ export const filesMap = [
|
||||
"filePath": "/www/apps/resources/app/commerce-modules/user/user-creation-flows/page.mdx",
|
||||
"pathname": "/commerce-modules/user/user-creation-flows"
|
||||
},
|
||||
{
|
||||
"filePath": "/www/apps/resources/app/configurations/_medusa-admin/page.mdx",
|
||||
"pathname": "/configurations/_medusa-admin"
|
||||
},
|
||||
{
|
||||
"filePath": "/www/apps/resources/app/contribution-guidelines/_admin-translations/page.mdx",
|
||||
"pathname": "/contribution-guidelines/_admin-translations"
|
||||
@@ -931,14 +935,6 @@ export const filesMap = [
|
||||
"filePath": "/www/apps/resources/app/troubleshooting/_transaction-promise-all/page.mdx",
|
||||
"pathname": "/troubleshooting/_transaction-promise-all"
|
||||
},
|
||||
{
|
||||
"filePath": "/www/apps/resources/app/troubleshooting/admin-sign-in/page.mdx",
|
||||
"pathname": "/troubleshooting/admin-sign-in"
|
||||
},
|
||||
{
|
||||
"filePath": "/www/apps/resources/app/troubleshooting/admin-webpack-build-error/page.mdx",
|
||||
"pathname": "/troubleshooting/admin-webpack-build-error"
|
||||
},
|
||||
{
|
||||
"filePath": "/www/apps/resources/app/troubleshooting/cors-errors/page.mdx",
|
||||
"pathname": "/troubleshooting/cors-errors"
|
||||
|
||||
@@ -37,8 +37,8 @@ export const generatedSidebar = [
|
||||
{
|
||||
"loaded": true,
|
||||
"isPathHref": true,
|
||||
"path": "/commerce-modules/api-key/tokens",
|
||||
"title": "Tokens",
|
||||
"path": "/commerce-modules/api-key/concepts",
|
||||
"title": "API Key Concepts",
|
||||
"children": []
|
||||
},
|
||||
{
|
||||
@@ -863,6 +863,20 @@ export const generatedSidebar = [
|
||||
"title": "Examples",
|
||||
"children": []
|
||||
},
|
||||
{
|
||||
"loaded": true,
|
||||
"isPathHref": true,
|
||||
"title": "Concepts",
|
||||
"children": [
|
||||
{
|
||||
"loaded": true,
|
||||
"isPathHref": true,
|
||||
"path": "/commerce-modules/currency/relations-to-other-modules",
|
||||
"title": "Relation to Modules",
|
||||
"children": []
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"loaded": true,
|
||||
"isPathHref": true,
|
||||
@@ -5068,6 +5082,20 @@ export const generatedSidebar = [
|
||||
"title": "Examples",
|
||||
"children": []
|
||||
},
|
||||
{
|
||||
"loaded": true,
|
||||
"isPathHref": true,
|
||||
"title": "Concepts",
|
||||
"children": [
|
||||
{
|
||||
"loaded": true,
|
||||
"isPathHref": true,
|
||||
"path": "/commerce-modules/store/relations-to-other-modules",
|
||||
"title": "Relation to Modules",
|
||||
"children": []
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"loaded": true,
|
||||
"isPathHref": true,
|
||||
@@ -5236,7 +5264,7 @@ export const generatedSidebar = [
|
||||
"loaded": true,
|
||||
"isPathHref": true,
|
||||
"path": "/commerce-modules/tax/tax-calculation-with-provider",
|
||||
"title": "Tax Calculation",
|
||||
"title": "Tax Calculation and Providers",
|
||||
"children": []
|
||||
}
|
||||
]
|
||||
@@ -5246,13 +5274,6 @@ export const generatedSidebar = [
|
||||
"isPathHref": true,
|
||||
"title": "References",
|
||||
"children": [
|
||||
{
|
||||
"loaded": true,
|
||||
"isPathHref": true,
|
||||
"path": "/references/tax/provider",
|
||||
"title": "Tax Provider Reference",
|
||||
"children": []
|
||||
},
|
||||
{
|
||||
"loaded": true,
|
||||
"isPathHref": true,
|
||||
@@ -7144,28 +7165,6 @@ export const generatedSidebar = [
|
||||
"children": []
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"loaded": true,
|
||||
"isPathHref": true,
|
||||
"title": "Medusa Admin",
|
||||
"hasTitleStyling": true,
|
||||
"children": [
|
||||
{
|
||||
"loaded": true,
|
||||
"isPathHref": true,
|
||||
"path": "/troubleshooting/admin-sign-in",
|
||||
"title": "Signing In",
|
||||
"children": []
|
||||
},
|
||||
{
|
||||
"loaded": true,
|
||||
"isPathHref": true,
|
||||
"path": "/troubleshooting/admin-custom-hooks-error",
|
||||
"title": "Custom Hooks Error",
|
||||
"children": []
|
||||
}
|
||||
]
|
||||
}
|
||||
]
|
||||
}
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
|
||||
import {
|
||||
SearchProvider as UiSearchProvider,
|
||||
AiAssistantCommandIcon,
|
||||
AiAssistantIcon,
|
||||
AiAssistantProvider,
|
||||
searchFiltersV1,
|
||||
} from "docs-ui"
|
||||
@@ -48,7 +48,7 @@ const SearchProvider = ({ children }: SearchProviderProps) => {
|
||||
commands={[
|
||||
{
|
||||
name: "ai-assistant",
|
||||
icon: <AiAssistantCommandIcon />,
|
||||
icon: <AiAssistantIcon />,
|
||||
component: (
|
||||
<AiAssistantProvider
|
||||
apiUrl={process.env.NEXT_PUBLIC_AI_ASSISTANT_URL || "temp"}
|
||||
@@ -61,8 +61,9 @@ const SearchProvider = ({ children }: SearchProviderProps) => {
|
||||
),
|
||||
title: "AI Assistant",
|
||||
badge: {
|
||||
variant: "purple",
|
||||
variant: "blue",
|
||||
children: "Beta",
|
||||
badgeType: "shaded",
|
||||
},
|
||||
},
|
||||
]}
|
||||
|
||||
Reference in New Issue
Block a user