chore: move ModuleRegistrationName to utils (#7911)

This commit is contained in:
Carlos R. L. Rodrigues
2024-07-03 06:30:56 -03:00
committed by GitHub
parent 46f15b4909
commit a7844efd09
339 changed files with 7203 additions and 7620 deletions
@@ -13,43 +13,41 @@ In this guide, youll find common examples of how you can use the Currency Mod
<CodeTabs groupId="app-type">
<CodeTab label="Medusa API Router" value="medusa">
```ts
import { MedusaRequest, MedusaResponse } from "@medusajs/medusa"
import { ICurrencyModuleService } from "@medusajs/types"
import { ModuleRegistrationName } from "@medusajs/modules-sdk"
```ts
import { MedusaRequest, MedusaResponse } from "@medusajs/medusa"
import { ICurrencyModuleService } from "@medusajs/types"
import { ModuleRegistrationName } from "@medusajs/utils"
export async function GET(
req: MedusaRequest,
res: MedusaResponse
): Promise<void> {
const currencyModuleService: ICurrencyModuleService =
req.scope.resolve(ModuleRegistrationName.CURRENCY)
export async function GET(
req: MedusaRequest,
res: MedusaResponse
): Promise<void> {
const currencyModuleService: ICurrencyModuleService = req.scope.resolve(
ModuleRegistrationName.CURRENCY
)
res.json({
currencies: await currencyModuleService.listCurrencies(),
})
}
```
res.json({
currencies: await currencyModuleService.listCurrencies(),
})
}
```
</CodeTab>
<CodeTab label="Next.js App Router" value="nextjs">
```ts
import { NextResponse } from "next/server"
```ts
import { NextResponse } from "next/server"
import {
initialize as initializeCurrencyModule,
} from "@medusajs/currency"
import { initialize as initializeCurrencyModule } from "@medusajs/currency"
export async function GET(request: Request) {
const currencyModuleService =
await initializeCurrencyModule()
export async function GET(request: Request) {
const currencyModuleService = await initializeCurrencyModule()
return NextResponse.json({
currencies: await currencyModuleService.listCurrencies(),
})
}
```
return NextResponse.json({
currencies: await currencyModuleService.listCurrencies(),
})
}
```
</CodeTab>
</CodeTabs>
@@ -61,48 +59,43 @@ In this guide, youll find common examples of how you can use the Currency Mod
<CodeTabs groupId="app-type">
<CodeTab label="Medusa API Router" value="medusa">
```ts
import { MedusaRequest, MedusaResponse } from "@medusajs/medusa"
import { ICurrencyModuleService } from "@medusajs/types"
import { ModuleRegistrationName } from "@medusajs/modules-sdk"
```ts
import { MedusaRequest, MedusaResponse } from "@medusajs/medusa"
import { ICurrencyModuleService } from "@medusajs/types"
import { ModuleRegistrationName } from "@medusajs/utils"
export async function GET(
req: MedusaRequest,
res: MedusaResponse
): Promise<void> {
const currencyModuleService: ICurrencyModuleService =
req.scope.resolve(ModuleRegistrationName.CURRENCY)
export async function GET(
req: MedusaRequest,
res: MedusaResponse
): Promise<void> {
const currencyModuleService: ICurrencyModuleService = req.scope.resolve(
ModuleRegistrationName.CURRENCY
)
const currency = await currencyModuleService
.retrieveCurrency("usd")
const currency = await currencyModuleService.retrieveCurrency("usd")
res.json({
currency,
})
}
```
res.json({
currency,
})
}
```
</CodeTab>
<CodeTab label="Next.js App Router" value="nextjs">
```ts
import { NextResponse } from "next/server"
```ts
import { NextResponse } from "next/server"
import {
initialize as initializeCurrencyModule,
} from "@medusajs/currency"
import { initialize as initializeCurrencyModule } from "@medusajs/currency"
export async function GET(
request: Request
) {
const currencyModuleService = await initializeCurrencyModule()
export async function GET(request: Request) {
const currencyModuleService = await initializeCurrencyModule()
const currency = await currencyModuleService
.retrieveCurrency("usd")
const currency = await currencyModuleService.retrieveCurrency("usd")
return NextResponse.json({ currency })
}
```
return NextResponse.json({ currency })
}
```
</CodeTab>
</CodeTabs>
@@ -15,9 +15,7 @@ The Currency Module is the `@medusajs/currency` NPM package that provides curren
List and retrieve currencies stored in your application.
```ts
const currency = await currencyModuleService.retrieveCurrency(
"usd"
)
const currency = await currencyModuleService.retrieveCurrency("usd")
```
### Support Currencies in Modules
@@ -27,9 +25,7 @@ Other commerce modules use currency codes in their data models or operations. Yo
An example with the Region Module:
```ts
const region = await regionModuleService.retrieveCurrency(
"reg_123"
)
const region = await regionModuleService.retrieveCurrency("reg_123")
const currency = await currencyModuleService.retrieveCurrency(
region.currency_code
)
@@ -46,63 +42,58 @@ For example:
<CodeTabs groupId="resource-type">
<CodeTab label="API Route" value="api-route">
```ts title="src/api/store/custom/route.ts"
import { MedusaRequest, MedusaResponse } from "@medusajs/medusa"
import { ICurrencyModuleService } from "@medusajs/types"
import { ModuleRegistrationName } from "@medusajs/modules-sdk"
```ts title="src/api/store/custom/route.ts"
import { MedusaRequest, MedusaResponse } from "@medusajs/medusa"
import { ICurrencyModuleService } from "@medusajs/types"
import { ModuleRegistrationName } from "@medusajs/utils"
export async function GET(
req: MedusaRequest,
res: MedusaResponse
): Promise<void> {
const currencyModuleService: ICurrencyModuleService =
req.scope.resolve(ModuleRegistrationName.CURRENCY)
export async function GET(
req: MedusaRequest,
res: MedusaResponse
): Promise<void> {
const currencyModuleService: ICurrencyModuleService = req.scope.resolve(
ModuleRegistrationName.CURRENCY
)
res.json({
currencies: await currencyModuleService.listCurrencies(),
})
}
```
res.json({
currencies: await currencyModuleService.listCurrencies(),
})
}
```
</CodeTab>
<CodeTab label="Subscriber" value="subscribers">
```ts title="src/subscribers/custom-handler.ts"
import { SubscriberArgs } from "@medusajs/medusa"
import { ICurrencyModuleService } from "@medusajs/types"
import { ModuleRegistrationName } from "@medusajs/modules-sdk"
```ts title="src/subscribers/custom-handler.ts"
import { SubscriberArgs } from "@medusajs/medusa"
import { ICurrencyModuleService } from "@medusajs/types"
import { ModuleRegistrationName } from "@medusajs/utils"
export default async function subscriberHandler({
container,
}: SubscriberArgs) {
const currencyModuleService: ICurrencyModuleService =
container.resolve(ModuleRegistrationName.CURRENCY)
export default async function subscriberHandler({ container }: SubscriberArgs) {
const currencyModuleService: ICurrencyModuleService = container.resolve(
ModuleRegistrationName.CURRENCY
)
const currencies = await currencyModuleService
.listCurrencies()
}
```
const currencies = await currencyModuleService.listCurrencies()
}
```
</CodeTab>
<CodeTab label="Workflow Step" value="workflow-step">
```ts title="src/workflows/hello-world/step1.ts"
import { createStep } from "@medusajs/workflows-sdk"
import { ICurrencyModuleService } from "@medusajs/types"
import { ModuleRegistrationName } from "@medusajs/modules-sdk"
```ts title="src/workflows/hello-world/step1.ts"
import { createStep } from "@medusajs/workflows-sdk"
import { ICurrencyModuleService } from "@medusajs/types"
import { ModuleRegistrationName } from "@medusajs/utils"
const step1 = createStep(
"step-1",
async (_, { container }) => {
const currencyModuleService: ICurrencyModuleService =
container.resolve(
ModuleRegistrationName.CURRENCY
)
const currencies = await currencyModuleService
.listCurrencies()
})
```
const step1 = createStep("step-1", async (_, { container }) => {
const currencyModuleService: ICurrencyModuleService = container.resolve(
ModuleRegistrationName.CURRENCY
)
const currencies = await currencyModuleService.listCurrencies()
})
```
</CodeTab>
</CodeTabs>