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
@@ -17,12 +17,11 @@ Store and manage inventory of any stock-kept item, such as product variants.
Inventory items hold details of the underlying stock-kept item, as well as inventory details such as whether the item requires shipping.
```ts
const inventoryItem =
await inventoryModuleService.createInventoryItems({
sku: "SHIRT",
title: "Green Medusa Shirt",
requires_shipping: true,
})
const inventoryItem = await inventoryModuleService.createInventoryItems({
sku: "SHIRT",
title: "Green Medusa Shirt",
requires_shipping: true,
})
```
### Inventory Across Locations
@@ -30,12 +29,13 @@ const inventoryItem =
Inventory items' quantities are set per locations through inventory levels. This gives you more flexibility in managing the quantity of a stock-kept item across different locations, such as different warehouses.
```ts
const inventoryLevel =
await inventoryModuleService.createInventoryLevels([{
const inventoryLevel = await inventoryModuleService.createInventoryLevels([
{
inventory_item_id: "iitem_123",
location_id: "sloc_123",
stocked_quantity: 20,
}])
},
])
```
### Reservation Management
@@ -43,12 +43,13 @@ const inventoryLevel =
Reserve quantities of inventory items at specific locations for orders or other purposes. The reserved quantity isn't considered for purchase, but can be deleted to revert the reservation.
```ts
const reservationItem =
await inventoryModuleService.createReservationItems([{
const reservationItem = await inventoryModuleService.createReservationItems([
{
inventory_item_id: "iitem_123",
location_id: "sloc_123",
quantity: 10,
}])
},
])
```
### Check Inventory Availability
@@ -56,12 +57,11 @@ const reservationItem =
Check whether an inventory item has the necessary quantity for purchase. Any reserved quantity is considered unavailable.
```ts
const isAvailable =
await inventoryModuleService.confirmInventory(
inventoryItemId,
[locationId],
neededQuantity
)
const isAvailable = await inventoryModuleService.confirmInventory(
inventoryItemId,
[locationId],
neededQuantity
)
```
---
@@ -75,62 +75,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 { IInventoryService } from "@medusajs/types"
import { ModuleRegistrationName } from "@medusajs/modules-sdk"
```ts title="src/api/store/custom/route.ts"
import { MedusaRequest, MedusaResponse } from "@medusajs/medusa"
import { IInventoryService } from "@medusajs/types"
import { ModuleRegistrationName } from "@medusajs/utils"
export async function GET(
request: MedusaRequest,
res: MedusaResponse
): Promise<void> {
const inventoryModuleService: IInventoryService =
request.scope.resolve(ModuleRegistrationName.INVENTORY)
export async function GET(
request: MedusaRequest,
res: MedusaResponse
): Promise<void> {
const inventoryModuleService: IInventoryService = request.scope.resolve(
ModuleRegistrationName.INVENTORY
)
res.json({
inventory_items:
await inventoryModuleService.listInventoryItems({}),
})
}
```
res.json({
inventory_items: await inventoryModuleService.listInventoryItems({}),
})
}
```
</CodeTab>
<CodeTab label="Subscriber" value="subscribers">
```ts title="src/subscribers/custom-handler.ts"
import { SubscriberArgs } from "@medusajs/medusa"
import { IInventoryService } from "@medusajs/types"
import { ModuleRegistrationName } from "@medusajs/modules-sdk"
```ts title="src/subscribers/custom-handler.ts"
import { SubscriberArgs } from "@medusajs/medusa"
import { IInventoryService } from "@medusajs/types"
import { ModuleRegistrationName } from "@medusajs/utils"
export default async function subscriberHandler({
container,
}: SubscriberArgs) {
const inventoryModuleService: IInventoryService =
container.resolve(ModuleRegistrationName.INVENTORY)
export default async function subscriberHandler({ container }: SubscriberArgs) {
const inventoryModuleService: IInventoryService = container.resolve(
ModuleRegistrationName.INVENTORY
)
const inventoryItems =
await inventoryModuleService.listInventoryItems({})
}
```
const inventoryItems = await inventoryModuleService.listInventoryItems({})
}
```
</CodeTab>
<CodeTab label="Workflow Step" value="workflow-step">
```ts title="src/workflows/hello-world/step1.ts"
import { createStep } from "@medusajs/workflows-sdk"
import { IInventoryService } from "@medusajs/types"
import { ModuleRegistrationName } from "@medusajs/modules-sdk"
```ts title="src/workflows/hello-world/step1.ts"
import { createStep } from "@medusajs/workflows-sdk"
import { IInventoryService } from "@medusajs/types"
import { ModuleRegistrationName } from "@medusajs/utils"
const step1 = createStep(
"step-1",
async (_, { container }) => {
const inventoryModuleService: IInventoryService =
container.resolve(ModuleRegistrationName.INVENTORY)
const step1 = createStep("step-1", async (_, { container }) => {
const inventoryModuleService: IInventoryService = container.resolve(
ModuleRegistrationName.INVENTORY
)
const inventoryItems =
await inventoryModuleService.listInventoryItems({})
})
```
const inventoryItems = await inventoryModuleService.listInventoryItems({})
})
```
</CodeTab>
</CodeTabs>