import { EntityManager } from "typeorm"; import { ICacheService, IEventBusService, IInventoryService, InventoryItemDTO, InventoryLevelDTO, IStockLocationService, ReservationItemDTO, ReserveQuantityContext } from "@medusajs/types"; import { LineItem, Product, ProductVariant } from "../models"; import { PricedProduct, PricedVariant } from "../types/pricing"; import { ProductVariantInventoryItem } from "../models/product-variant-inventory-item"; import ProductVariantService from "./product-variant"; import SalesChannelInventoryService from "./sales-channel-inventory"; import SalesChannelLocationService from "./sales-channel-location"; import { TransactionBaseService } from "../interfaces"; type InjectedDependencies = { manager: EntityManager; salesChannelLocationService: SalesChannelLocationService; salesChannelInventoryService: SalesChannelInventoryService; productVariantService: ProductVariantService; stockLocationService: IStockLocationService; inventoryService: IInventoryService; eventBusService: IEventBusService; }; type AvailabilityContext = { variantInventoryMap?: Map; inventoryLocationMap?: Map; }; declare class ProductVariantInventoryService extends TransactionBaseService { protected manager_: EntityManager; protected transactionManager_: EntityManager | undefined; protected readonly salesChannelLocationService_: SalesChannelLocationService; protected readonly salesChannelInventoryService_: SalesChannelInventoryService; protected readonly productVariantService_: ProductVariantService; protected readonly stockLocationService_: IStockLocationService; protected readonly inventoryService_: IInventoryService; protected readonly eventBusService_: IEventBusService; protected readonly cacheService_: ICacheService; constructor({ stockLocationService, salesChannelLocationService, salesChannelInventoryService, productVariantService, inventoryService, eventBusService, }: InjectedDependencies); /** * confirms if requested inventory is available * @param variantId id of the variant to confirm inventory for * @param quantity quantity of inventory to confirm is available * @param context optionally include a sales channel if applicable * @returns boolean indicating if inventory is available */ confirmInventory(variantId: string, quantity: number, context?: { salesChannelId?: string | null; }): Promise; /** * Retrieves a product variant inventory item by its inventory item ID and variant ID. * * @param inventoryItemId - The ID of the inventory item to retrieve. * @param variantId - The ID of the variant to retrieve. * @returns A promise that resolves with the product variant inventory item. */ retrieve(inventoryItemId: string, variantId: string): Promise; /** * list registered inventory items * @param itemIds list inventory item ids * @returns list of inventory items */ listByItem(itemIds: string[]): Promise; /** * List inventory items for a specific variant * @param variantId variant id * @returns variant inventory items for the variant id */ listByVariant(variantId: string | string[]): Promise; /** * lists variant by inventory item id * @param itemId item id * @returns a list of product variants that are associated with the item id */ listVariantsByItem(itemId: string): Promise; /** * lists inventory items for a given variant * @param variantId variant id * @returns lidt of inventory items for the variant */ listInventoryItemsByVariant(variantId: string): Promise; /** * Attach a variant to an inventory item * @param variantId variant id * @param inventoryItemId inventory item id * @param requiredQuantity quantity of variant to attach * @returns the variant inventory item */ attachInventoryItem(attachments: { variantId: string; inventoryItemId: string; requiredQuantity?: number; }[]): Promise; attachInventoryItem(variantId: string, inventoryItemId: string, requiredQuantity?: number): Promise; /** * Remove a variant from an inventory item * @param variantId variant id or undefined if all the variants will be affected * @param inventoryItemId inventory item id */ detachInventoryItem(inventoryItemId: string, variantId?: string): Promise; /** * Reserves a quantity of a variant * @param variantId variant id * @param quantity quantity to reserve * @param context optional parameters */ reserveQuantity(variantId: string, quantity: number, context?: ReserveQuantityContext): Promise; /** * Adjusts the quantity of reservations for a line item by a given amount. * @param {string} lineItemId - The ID of the line item * @param {string} variantId - The ID of the variant * @param {string} locationId - The ID of the location to prefer adjusting quantities at * @param {number} quantity - The amount to adjust the quantity by */ adjustReservationsQuantityByLineItem(lineItemId: string, variantId: string, locationId: string, quantity: number): Promise; /** * Validate stock at a location for fulfillment items * @param items Fulfillment Line items to validate quantities for * @param locationId Location to validate stock at * @returns nothing if successful, throws error if not */ validateInventoryAtLocation(items: Omit[], locationId: string): Promise; /** * delete a reservation of variant quantity * @param lineItemId line item id * @param variantId variant id * @param quantity quantity to release */ deleteReservationsByLineItem(lineItemId: string | string[], variantId: string, quantity: number): Promise; /** * Adjusts inventory of a variant on a location * @param variantId variant id * @param locationId location id * @param quantity quantity to adjust */ adjustInventory(variantId: string, locationId: string, quantity: number): Promise; setVariantAvailability(variants: ProductVariant[] | PricedVariant[], salesChannelId: string | string[] | undefined, availabilityContext?: AvailabilityContext): Promise; private getAvailabilityContext; setProductAvailability(products: (Product | PricedProduct)[], salesChannelId: string | string[] | undefined): Promise<(Product | PricedProduct)[]>; /** * Get the quantity of a variant from a list of variantInventoryItems * The inventory quantity of the variant should be equal to the inventory * item with the smallest stock, adjusted for quantity required to fulfill * the given variant. * * @param variantInventoryItems List of inventoryItems for a given variant, These must all be for the same variant * @param channelId Sales channel id to fetch availability for * @returns The available quantity of the variant from the inventoryItems */ getVariantQuantityFromVariantInventoryItems(variantInventoryItems: ProductVariantInventoryItem[], channelId: string): Promise; } export default ProductVariantInventoryService;