docs: improve commerce modules [1/n] (#9498)
Improve and add docs for API Key, Auth, and Cart Modules [1/n]
This commit is contained in:
@@ -4,7 +4,8 @@ export const metadata = {
|
||||
|
||||
# {metadata.title}
|
||||
|
||||
In this document, you’ll learn how about the different types of API keys, and their expiration and verification.
|
||||
In this document, you’ll learn about the different types of API keys, their expiration and verification.
|
||||
|
||||
## API Key Types
|
||||
|
||||
There are two types of API keys:
|
||||
|
||||
@@ -13,13 +13,12 @@ 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
|
||||
import { MedusaRequest, MedusaResponse } from "@medusajs/framework/http"
|
||||
import { IApiKeyModuleService } from "@medusajs/framework/types"
|
||||
import { Modules } from "@medusajs/framework/utils"
|
||||
```ts
|
||||
import { MedusaRequest, MedusaResponse } from "@medusajs/framework/http"
|
||||
import { Modules } from "@medusajs/framework/utils"
|
||||
|
||||
export async function POST(request: MedusaRequest, res: MedusaResponse) {
|
||||
const apiKeyModuleService: IApiKeyModuleService = request.scope.resolve(
|
||||
const apiKeyModuleService = request.scope.resolve(
|
||||
Modules.API_KEY
|
||||
)
|
||||
|
||||
@@ -68,13 +67,12 @@ export async function POST(request: Request) {
|
||||
<CodeTabs groupId="app-type">
|
||||
<CodeTab label="Medusa API Router" value="medusa">
|
||||
|
||||
```ts
|
||||
import { MedusaRequest, MedusaResponse } from "@medusajs/framework/http"
|
||||
import { IApiKeyModuleService } from "@medusajs/framework/types"
|
||||
import { Modules } from "@medusajs/framework/utils"
|
||||
```ts
|
||||
import { MedusaRequest, MedusaResponse } from "@medusajs/framework/http"
|
||||
import { Modules } from "@medusajs/framework/utils"
|
||||
|
||||
export async function GET(request: MedusaRequest, res: MedusaResponse) {
|
||||
const apiKeyModuleService: IApiKeyModuleService = request.scope.resolve(
|
||||
const apiKeyModuleService = request.scope.resolve(
|
||||
Modules.API_KEY
|
||||
)
|
||||
|
||||
@@ -113,14 +111,13 @@ export async function GET(request: Request) {
|
||||
|
||||
```ts collapsibleLines="1-9" expandButtonLabel="Show Imports"
|
||||
import { AuthenticatedMedusaRequest, MedusaResponse } from "@medusajs/framework/http"
|
||||
import { IApiKeyModuleService } from "@medusajs/framework/types"
|
||||
import { Modules } from "@medusajs/framework/utils"
|
||||
|
||||
export async function POST(
|
||||
request: AuthenticatedMedusaRequest,
|
||||
res: MedusaResponse
|
||||
) {
|
||||
const apiKeyModuleService: IApiKeyModuleService = request.scope.resolve(
|
||||
const apiKeyModuleService = request.scope.resolve(
|
||||
Modules.API_KEY
|
||||
)
|
||||
|
||||
@@ -172,13 +169,12 @@ export async function POST(request: Request, { params }: ContextType) {
|
||||
<CodeTabs groupId="app-type">
|
||||
<CodeTab label="Medusa API Router" value="medusa">
|
||||
|
||||
```ts
|
||||
import { MedusaRequest, MedusaResponse } from "@medusajs/framework/http"
|
||||
import { IApiKeyModuleService } from "@medusajs/framework/types"
|
||||
import { Modules } from "@medusajs/framework/utils"
|
||||
```ts
|
||||
import { MedusaRequest, MedusaResponse } from "@medusajs/framework/http"
|
||||
import { Modules } from "@medusajs/framework/utils"
|
||||
|
||||
export async function POST(request: MedusaRequest, res: MedusaResponse) {
|
||||
const apiKeyModuleService: IApiKeyModuleService = request.scope.resolve(
|
||||
const apiKeyModuleService = request.scope.resolve(
|
||||
Modules.API_KEY
|
||||
)
|
||||
|
||||
@@ -229,19 +225,18 @@ export async function POST(request: Request, { params }: ContextType) {
|
||||
<CodeTabs groupId="app-type">
|
||||
<CodeTab label="Medusa API Router" value="medusa">
|
||||
|
||||
```ts collapsibleLines="1-8" expandButtonLabel="Show Imports"
|
||||
import {
|
||||
AuthenticatedMedusaRequest,
|
||||
MedusaResponse,
|
||||
} from "@medusajs/framework/http"
|
||||
import { IApiKeyModuleService } from "@medusajs/framework/types"
|
||||
import { Modules } from "@medusajs/framework/utils"
|
||||
```ts collapsibleLines="1-8" expandButtonLabel="Show Imports"
|
||||
import {
|
||||
AuthenticatedMedusaRequest,
|
||||
MedusaResponse,
|
||||
} from "@medusajs/framework/http"
|
||||
import { Modules } from "@medusajs/framework/utils"
|
||||
|
||||
export async function POST(
|
||||
request: AuthenticatedMedusaRequest,
|
||||
res: MedusaResponse
|
||||
) {
|
||||
const apiKeyModuleService: IApiKeyModuleService = request.scope.resolve(
|
||||
const apiKeyModuleService = request.scope.resolve(
|
||||
Modules.API_KEY
|
||||
)
|
||||
|
||||
|
||||
+3
-3
@@ -1,14 +1,14 @@
|
||||
export const metadata = {
|
||||
title: `Relations between API Key Module and Other Modules`,
|
||||
title: `Links between API Key Module and Other Modules`,
|
||||
}
|
||||
|
||||
# {metadata.title}
|
||||
|
||||
This document showcases the link modules defined between the API Key Module and other commerce modules.
|
||||
This document showcases the module links defined between the API Key Module and other commerce modules.
|
||||
|
||||
## Sales Channel Module
|
||||
|
||||
You can create a publishable API key and associate it with a sales channel. Medusa defines a link module that builds a relation between the `ApiKey` and the `SalesChannel` data models.
|
||||
You can create a publishable API key and associate it with a sales channel. Medusa defines a link between the `ApiKey` and the `SalesChannel` data models.
|
||||
|
||||

|
||||
|
||||
@@ -6,27 +6,42 @@ export const metadata = {
|
||||
|
||||
# {metadata.title}
|
||||
|
||||
The API Key Module is the `@medusajs/medusa/api-key` NPM package that provides API-key-related features in your Medusa and Node.js applications.
|
||||
The API Key Module provides API-key-related features in your Medusa and Node.js applications.
|
||||
|
||||
## How to Use API Key Module's Service
|
||||
|
||||
You can use the API Key Module's main service by resolving from the Medusa container the resource `Modules.API_KEY` imported from `@medusajs/framework/utils`.
|
||||
Use the API Key Module's main service by resolving from the Medusa container the resource `Modules.API_KEY` imported from `@medusajs/framework/utils`.
|
||||
|
||||
For example:
|
||||
|
||||
<CodeTabs groupId="resource-type">
|
||||
<CodeTab label="Workflow Step" value="workflow-step">
|
||||
|
||||
```ts title="src/workflows/hello-world/step1.ts"
|
||||
import { createStep } from "@medusajs/framework/workflows-sdk"
|
||||
import { Modules } from "@medusajs/framework/utils"
|
||||
|
||||
const step1 = createStep("step-1", async (_, { container }) => {
|
||||
const apiKeyModuleService = container.resolve(
|
||||
Modules.API_KEY
|
||||
)
|
||||
|
||||
const apiKeys = await apiKeyModuleService.listApiKeys()
|
||||
})
|
||||
```
|
||||
|
||||
</CodeTab>
|
||||
<CodeTab label="API Route" value="api-route">
|
||||
|
||||
```ts title="src/api/store/custom/route.ts"
|
||||
import { MedusaRequest, MedusaResponse } from "@medusajs/framework/http"
|
||||
import { IApiKeyModuleService } from "@medusajs/framework/types"
|
||||
import { Modules } from "@medusajs/framework/utils"
|
||||
```ts title="src/api/store/custom/route.ts"
|
||||
import { MedusaRequest, MedusaResponse } from "@medusajs/framework/http"
|
||||
import { Modules } from "@medusajs/framework/utils"
|
||||
|
||||
export async function GET(
|
||||
request: MedusaRequest,
|
||||
res: MedusaResponse
|
||||
): Promise<void> {
|
||||
const apiKeyModuleService: IApiKeyModuleService = request.scope.resolve(
|
||||
const apiKeyModuleService = request.scope.resolve(
|
||||
Modules.API_KEY
|
||||
)
|
||||
|
||||
@@ -39,35 +54,17 @@ export async function GET(
|
||||
</CodeTab>
|
||||
<CodeTab label="Subscriber" value="subscribers">
|
||||
|
||||
```ts title="src/subscribers/custom-handler.ts"
|
||||
import { SubscriberArgs } from "@medusajs/framework"
|
||||
import { IApiKeyModuleService } from "@medusajs/framework/types"
|
||||
import { Modules } from "@medusajs/framework/utils"
|
||||
```ts title="src/subscribers/custom-handler.ts"
|
||||
import { SubscriberArgs } from "@medusajs/framework"
|
||||
import { Modules } from "@medusajs/framework/utils"
|
||||
|
||||
export default async function subscriberHandler({ container }: SubscriberArgs) {
|
||||
const apiKeyModuleService: IApiKeyModuleService = container.resolve(
|
||||
const apiKeyModuleService = container.resolve(
|
||||
Modules.API_KEY
|
||||
)
|
||||
|
||||
const apiKeys = await apiKeyModuleService.listApiKeys()
|
||||
}
|
||||
```
|
||||
|
||||
</CodeTab>
|
||||
<CodeTab label="Workflow Step" value="workflow-step">
|
||||
|
||||
```ts title="src/workflows/hello-world/step1.ts"
|
||||
import { createStep } from "@medusajs/framework/workflows-sdk"
|
||||
import { IApiKeyModuleService } from "@medusajs/framework/types"
|
||||
import { Modules } from "@medusajs/framework/utils"
|
||||
|
||||
const step1 = createStep("step-1", async (_, { container }) => {
|
||||
const apiKeyModuleService: IApiKeyModuleService = container.resolve(
|
||||
Modules.API_KEY
|
||||
)
|
||||
|
||||
const apiKeys = await apiKeyModuleService.listApiKeys()
|
||||
})
|
||||
```
|
||||
|
||||
</CodeTab>
|
||||
@@ -79,7 +76,7 @@ const step1 = createStep("step-1", async (_, { container }) => {
|
||||
|
||||
### API Key Types and Management
|
||||
|
||||
Store and manage API keys in your store. You can create both publishable and secret API keys for different use cases, such as:
|
||||
Manage API keys in your store. You can create both publishable and secret API keys for different use cases, such as:
|
||||
|
||||
- Publishable API Key associated with resources like sales channels.
|
||||
- Authentication token for admin users to access Admin API Routes.
|
||||
|
||||
Reference in New Issue
Block a user