feat(inventory-next, types): inventory module conversion (#6596)

* init

* create new interface

* prep integration tests

* update denpencies

* inventory service partial tests

* finalize integration tests

* add events

* align events

* adjust inventory level reservation levels

* add test validating reserved quantity after reseration item update

* fix nits

* rename to inventory-next

* update yarn.lock

* remove changelog

* remove fixtures

* remove unused files

* ready for review

* Update packages/inventory-next/package.json

Co-authored-by: Oli Juhl <59018053+olivermrbl@users.noreply.github.com>

* pr feedback

* add tests and docs for partition-array util

* remote decorators from private method

* fix unit tests

* add migrations

* add foreign keys

* fix build

---------

Co-authored-by: Oli Juhl <59018053+olivermrbl@users.noreply.github.com>
This commit is contained in:
Philip Korsholm
2024-03-08 14:09:05 +01:00
committed by GitHub
co-authored by Oli Juhl
parent 8406eb5a35
commit c19d276458
46 changed files with 4896 additions and 14 deletions
+2
View File
@@ -0,0 +1,2 @@
export * from "./common/index"
export * from "./mutations"
+15 -11
View File
@@ -204,7 +204,7 @@ export type InventoryLevelDTO = {
/**
* @interface
*
*
* The filters to apply on retrieved reservation items.
*/
export type FilterableReservationItemProps = {
@@ -214,7 +214,7 @@ export type FilterableReservationItemProps = {
id?: string | string[]
/**
* @ignore
*
*
* @privateRemark
* This property is not used.
*/
@@ -247,7 +247,7 @@ export type FilterableReservationItemProps = {
/**
* @interface
*
*
* The filters to apply on retrieved inventory items.
*/
export type FilterableInventoryItemProps = {
@@ -281,12 +281,16 @@ export type FilterableInventoryItemProps = {
requires_shipping?: boolean
}
export interface UpdateInventoryItemInput
extends Partial<CreateInventoryItemInput> {
id: string
}
/**
* @interface
*
*
* The details of the inventory item to be created.
*/
export type CreateInventoryItemInput = {
export interface CreateInventoryItemInput {
/**
* The SKU of the inventory item.
*/
@@ -347,7 +351,7 @@ export type CreateInventoryItemInput = {
/**
* @interface
*
*
* The details of the reservation item to be created.
*/
export type CreateReservationItemInput = {
@@ -387,7 +391,7 @@ export type CreateReservationItemInput = {
/**
* @interface
*
*
* The filters to apply on retrieved inventory levels.
*/
export type FilterableInventoryLevelProps = {
@@ -415,7 +419,7 @@ export type FilterableInventoryLevelProps = {
/**
* @interface
*
*
* The details of the inventory level to be created.
*/
export type CreateInventoryLevelInput = {
@@ -443,7 +447,7 @@ export type CreateInventoryLevelInput = {
/**
* @interface
*
*
* The attributes to update in an inventory level.
*/
export type UpdateInventoryLevelInput = {
@@ -459,7 +463,7 @@ export type UpdateInventoryLevelInput = {
/**
* @interface
*
*
* The attributes to update in an inventory level. The inventory level is identified by the IDs of its associated inventory item and location.
*/
export type BulkUpdateInventoryLevelInput = {
@@ -475,7 +479,7 @@ export type BulkUpdateInventoryLevelInput = {
/**
* @interface
*
*
* The attributes to update in a reservation item.
*/
export type UpdateReservationItemInput = {
@@ -0,0 +1,3 @@
export * from "./inventory-item"
export * from "./inventory-level"
export * from "./reservation-item"
@@ -0,0 +1,124 @@
import { StringComparisonOperator } from "../../common"
/**
* @schema InventoryItemDTO
* type: object
* required:
* - sku
* properties:
* id:
* description: The inventory item's ID.
* type: string
* example: "iitem_12334"
* sku:
* description: The Stock Keeping Unit (SKU) code of the Inventory Item.
* type: string
* hs_code:
* description: The Harmonized System code of the Inventory Item. May be used by Fulfillment Providers to pass customs information to shipping carriers.
* type: string
* origin_country:
* description: The country in which the Inventory Item was produced. May be used by Fulfillment Providers to pass customs information to shipping carriers.
* type: string
* mid_code:
* description: The Manufacturers Identification code that identifies the manufacturer of the Inventory Item. May be used by Fulfillment Providers to pass customs information to shipping carriers.
* type: string
* title:
* description: "Title of the inventory item"
* type: string
* description:
* description: "Description of the inventory item"
* type: string
* thumbnail:
* description: "Thumbnail for the inventory item"
* type: string
* material:
* description: The material and composition that the Inventory Item is made of, May be used by Fulfillment Providers to pass customs information to shipping carriers.
* type: string
* weight:
* description: The weight of the Inventory Item. May be used in shipping rate calculations.
* type: number
* height:
* description: The height of the Inventory Item. May be used in shipping rate calculations.
* type: number
* width:
* description: The width of the Inventory Item. May be used in shipping rate calculations.
* type: number
* length:
* description: The length of the Inventory Item. May be used in shipping rate calculations.
* type: number
* requires_shipping:
* description: Whether the item requires shipping.
* type: boolean
* metadata:
* type: object
* description: An optional key-value map with additional details
* example: {car: "white"}
* created_at:
* type: string
* description: "The date with timezone at which the resource was created."
* format: date-time
* updated_at:
* type: string
* description: "The date with timezone at which the resource was updated."
* format: date-time
* deleted_at:
* type: string
* description: "The date with timezone at which the resource was deleted."
* format: date-time
*/
export interface InventoryItemDTO {
id: string
sku?: string | null
origin_country?: string | null
hs_code?: string | null
requires_shipping: boolean
mid_code?: string | null
material?: string | null
weight?: number | null
length?: number | null
height?: number | null
width?: number | null
title?: string | null
description?: string | null
thumbnail?: string | null
metadata?: Record<string, unknown> | null
created_at: string | Date
updated_at: string | Date
deleted_at: string | Date | null
}
/**
* @interface
*
* The filters to apply on retrieved inventory items.
*/
export interface FilterableInventoryItemProps {
/**
* The IDs to filter inventory items by.
*/
id?: string | string[]
/**
* Filter inventory items by the ID of their associated location.
*/
location_id?: string | string[]
/**
* Search term to search inventory items' attributes.
*/
q?: string
/**
* The SKUs to filter inventory items by.
*/
sku?: string | string[] | StringComparisonOperator
/**
* The origin country to filter inventory items by.
*/
origin_country?: string | string[]
/**
* The HS Codes to filter inventory items by.
*/
hs_code?: string | string[] | StringComparisonOperator
/**
* Filter inventory items by whether they require shipping.
*/
requires_shipping?: boolean
}
@@ -0,0 +1,76 @@
import { NumericalComparisonOperator } from "../../common"
/**
* @schema InventoryLevelDTO
* type: object
* required:
* - inventory_item_id
* - location_id
* - stocked_quantity
* - reserved_quantity
* - incoming_quantity
* properties:
* location_id:
* description: the item location ID
* type: string
* stocked_quantity:
* description: the total stock quantity of an inventory item at the given location ID
* type: number
* reserved_quantity:
* description: the reserved stock quantity of an inventory item at the given location ID
* type: number
* incoming_quantity:
* description: the incoming stock quantity of an inventory item at the given location ID
* type: number
* metadata:
* type: object
* description: An optional key-value map with additional details
* example: {car: "white"}
* created_at:
* type: string
* description: "The date with timezone at which the resource was created."
* format: date-time
* updated_at:
* type: string
* description: "The date with timezone at which the resource was updated."
* format: date-time
* deleted_at:
* type: string
* description: "The date with timezone at which the resource was deleted."
* format: date-time
*/
export interface InventoryLevelDTO {
id: string
inventory_item_id: string
location_id: string
stocked_quantity: number
reserved_quantity: number
incoming_quantity: number
metadata: Record<string, unknown> | null
created_at: string | Date
updated_at: string | Date
deleted_at: string | Date | null
}
export interface FilterableInventoryLevelProps {
/**
* Filter inventory levels by the ID of their associated inventory item.
*/
inventory_item_id?: string | string[]
/**
* Filter inventory levels by the ID of their associated inventory location.
*/
location_id?: string | string[]
/**
* Filters to apply on inventory levels' `stocked_quantity` attribute.
*/
stocked_quantity?: number | NumericalComparisonOperator
/**
* Filters to apply on inventory levels' `reserved_quantity` attribute.
*/
reserved_quantity?: number | NumericalComparisonOperator
/**
* Filters to apply on inventory levels' `incoming_quantity` attribute.
*/
incoming_quantity?: number | NumericalComparisonOperator
}
@@ -0,0 +1,107 @@
import {
NumericalComparisonOperator,
StringComparisonOperator,
} from "../../common"
/**
* @schema ReservationItemDTO
* title: "Reservation item"
* description: "Represents a reservation of an inventory item at a stock location"
* type: object
* required:
* - id
* - location_id
* - inventory_item_id
* - quantity
* properties:
* id:
* description: "The id of the reservation item"
* type: string
* location_id:
* description: "The id of the location of the reservation"
* type: string
* inventory_item_id:
* description: "The id of the inventory item the reservation relates to"
* type: string
* description:
* description: "Description of the reservation item"
* type: string
* created_by:
* description: "UserId of user who created the reservation item"
* type: string
* quantity:
* description: "The id of the reservation item"
* type: number
* metadata:
* type: object
* description: An optional key-value map with additional details
* example: {car: "white"}
* created_at:
* type: string
* description: "The date with timezone at which the resource was created."
* format: date-time
* updated_at:
* type: string
* description: "The date with timezone at which the resource was updated."
* format: date-time
* deleted_at:
* type: string
* description: "The date with timezone at which the resource was deleted."
* format: date-time
*/
export interface ReservationItemDTO {
id: string
location_id: string
inventory_item_id: string
quantity: number
line_item_id?: string | null
description?: string | null
created_by?: string | null
metadata: Record<string, unknown> | null
created_at: string | Date
updated_at: string | Date
deleted_at: string | Date | null
}
/**
* @interface
*
* The filters to apply on retrieved reservation items.
*/
export interface FilterableReservationItemProps {
/**
* The IDs to filter reservation items by.
*/
id?: string | string[]
/**
* @ignore
*
* @privateRemark
* This property is not used.
*/
type?: string | string[]
/**
* Filter reservation items by the ID of their associated line item.
*/
line_item_id?: string | string[]
/**
* Filter reservation items by the ID of their associated inventory item.
*/
inventory_item_id?: string | string[]
/**
* Filter reservation items by the ID of their associated location.
*/
location_id?: string | string[]
/**
* Description filters to apply on the reservation items' `description` attribute.
*/
description?: string | StringComparisonOperator
/**
* The "created by" values to filter reservation items by.
*/
created_by?: string | string[]
/**
* Filters to apply on the reservation items' `quantity` attribute.
*/
quantity?: number | NumericalComparisonOperator
}
+2
View File
@@ -1,2 +1,4 @@
export * as InventoryNext from "./bundle"
export * from "./common"
export * from "./service"
export * from "./service-next"
@@ -0,0 +1,3 @@
export * from "./inventory-item"
export * from "./inventory-level"
export * from "./reservation-item"
@@ -0,0 +1,67 @@
export interface UpdateInventoryItemInput
extends Partial<CreateInventoryItemInput> {
id: string
}
/**
* @interface
*
* The details of the inventory item to be created.
*/
export interface CreateInventoryItemInput {
/**
* The SKU of the inventory item.
*/
sku?: string | null
/**
* The origin country of the inventory item.
*/
origin_country?: string | null
/**
* The MID code of the inventory item.
*/
mid_code?: string | null
/**
* The material of the inventory item.
*/
material?: string | null
/**
* The weight of the inventory item.
*/
weight?: number | null
/**
* The length of the inventory item.
*/
length?: number | null
/**
* The height of the inventory item.
*/
height?: number | null
/**
* The width of the inventory item.
*/
width?: number | null
/**
* The title of the inventory item.
*/
title?: string | null
/**
* The description of the inventory item.
*/
description?: string | null
/**
* The thumbnail of the inventory item.
*/
thumbnail?: string | null
/**
* Holds custom data in key-value pairs.
*/
metadata?: Record<string, unknown> | null
/**
* The HS code of the inventory item.
*/
hs_code?: string | null
/**
* Whether the inventory item requires shipping.
*/
requires_shipping?: boolean
}
@@ -0,0 +1,58 @@
export interface CreateInventoryLevelInput {
/**
* The ID of the associated inventory item.
*/
inventory_item_id: string
/**
* The ID of the associated location.
*/
location_id: string
/**
* The stocked quantity of the associated inventory item in the associated location.
*/
stocked_quantity: number
/**
* The reserved quantity of the associated inventory item in the associated location.
*/
reserved_quantity?: number
/**
* The incoming quantity of the associated inventory item in the associated location.
*/
incoming_quantity?: number
}
/**
* @interface
*
* The attributes to update in an inventory level.
*/
export interface UpdateInventoryLevelInput {
/**
* id of the inventory level to update
*/
id: string
/**
* The stocked quantity of the associated inventory item in the associated location.
*/
stocked_quantity?: number
/**
* The incoming quantity of the associated inventory item in the associated location.
*/
incoming_quantity?: number
}
/**
* @interface
*
* The attributes to update in an inventory level. The inventory level is identified by the IDs of its associated inventory item and location.
*/
export type BulkUpdateInventoryLevelInput = {
/**
* The ID of the associated inventory level.
*/
inventory_item_id: string
/**
* The ID of the associated location.
*/
location_id: string
} & UpdateInventoryLevelInput
@@ -0,0 +1,70 @@
/**
* @interface
*
* The attributes to update in a reservation item.
*/
export interface UpdateReservationItemInput {
id: string
/**
* The reserved quantity.
*/
quantity?: number
/**
* The ID of the associated location.
*/
location_id?: string
/**
* The description of the reservation item.
*/
description?: string
/**
* Holds custom data in key-value pairs.
*/
metadata?: Record<string, unknown> | null
}
/**
* @interface
*
* The details of the reservation item to be created.
*/
export interface CreateReservationItemInput {
/**
* The ID of the associated line item.
*/
line_item_id?: string
/**
* The ID of the associated inventory item.
*/
inventory_item_id: string
/**
* The ID of the associated location.
*/
location_id: string
/**
* The reserved quantity.
*/
quantity: number
/**
* The description of the reservation.
*/
description?: string
/**
* The user or system that created the reservation. Can be any form of identification string.
*/
created_by?: string
/**
* An ID associated with an external third-party system that the reservation item is connected to.
*/
external_id?: string
/**
* Holds custom data in key-value pairs.
*/
metadata?: Record<string, unknown> | null
}
export interface ReserveQuantityContext {
locationId?: string
lineItemId?: string
salesChannelId?: string | null
}
@@ -0,0 +1,963 @@
import { RestoreReturn, SoftDeleteReturn } from "../dal"
import { Context } from "../shared-context"
import { FindConfig } from "../common"
import { IModuleService } from "../modules-sdk"
import { InventoryNext } from "."
/**
* The main service interface for the inventory module.
*/
export interface IInventoryServiceNext extends IModuleService {
/**
* This method is used to retrieve a paginated list of inventory items along with the total count of available inventory items satisfying the provided filters.
* @param {FilterableInventoryItemProps} selector - The filters to apply on the retrieved inventory items.
* @param {FindConfig<InventoryItemDTO>} config -
* The configurations determining how the inventory items are retrieved. Its properties, such as `select` or `relations`, accept the
* attributes or relations associated with a inventory item.
* @param {Context} context - A context used to share resources, such as transaction manager, between the application and the module.
* @return {Promise<[InventoryItemDTO[], number]>} The list of inventory items along with the total count.
*
* @example
* To retrieve a list of inventory items using their IDs:
*
* ```ts
* import {
* initialize as initializeInventoryModule,
* } from "@medusajs/inventory"
*
* async function retrieveInventoryItems (ids: string[]) {
* const inventoryModule = await initializeInventoryModule({})
*
* const [inventoryItems, count] = await inventoryModule.listInventoryItems({
* id: ids
* })
*
* // do something with the inventory items or return them
* }
* ```
*
* To specify relations that should be retrieved within the inventory items:
*
* ```ts
* import {
* initialize as initializeInventoryModule,
* } from "@medusajs/inventory"
*
* async function retrieveInventoryItems (ids: string[]) {
* const inventoryModule = await initializeInventoryModule({})
*
* const [inventoryItems, count] = await inventoryModule.listInventoryItems({
* id: ids
* }, {
* relations: ["inventory_level"]
* })
*
* // do something with the inventory items or return them
* }
* ```
*
* By default, only the first `10` records are retrieved. You can control pagination by specifying the `skip` and `take` properties of the `config` parameter:
*
* ```ts
* import {
* initialize as initializeInventoryModule,
* } from "@medusajs/inventory"
*
* async function retrieveInventoryItems (ids: string[], skip: number, take: number) {
* const inventoryModule = await initializeInventoryModule({})
*
* const [inventoryItems, count] = await inventoryModule.listInventoryItems({
* id: ids
* }, {
* relations: ["inventory_level"],
* skip,
* take
* })
*
* // do something with the inventory items or return them
* }
* ```
*/
list(
selector: InventoryNext.FilterableInventoryItemProps,
config?: FindConfig<InventoryNext.InventoryItemDTO>,
context?: Context
): Promise<InventoryNext.InventoryItemDTO[]>
listAndCount(
selector: InventoryNext.FilterableInventoryItemProps,
config?: FindConfig<InventoryNext.InventoryItemDTO>,
context?: Context
): Promise<[InventoryNext.InventoryItemDTO[], number]>
/**
* This method is used to retrieve a paginated list of reservation items along with the total count of available reservation items satisfying the provided filters.
* @param {FilterableReservationItemProps} selector - The filters to apply on the retrieved reservation items.
* @param {FindConfig<ReservationItemDTO>} config -
* The configurations determining how the reservation items are retrieved. Its properties, such as `select` or `relations`, accept the
* attributes or relations associated with a reservation item.
* @param {Context} context - A context used to share resources, such as transaction manager, between the application and the module.
* @return {Promise<[ReservationItemDTO[], number]>} The list of reservation items along with the total count.
*
* @example
* To retrieve a list of reservation items using their IDs:
*
* ```ts
* import {
* initialize as initializeInventoryModule,
* } from "@medusajs/inventory"
*
* async function retrieveReservationItems (ids: string[]) {
* const inventoryModule = await initializeInventoryModule({})
*
* const [reservationItems, count] = await inventoryModule.listReservationItems({
* id: ids
* })
*
* // do something with the reservation items or return them
* }
* ```
*
* To specify relations that should be retrieved within the reservation items:
*
* ```ts
* import {
* initialize as initializeInventoryModule,
* } from "@medusajs/inventory"
*
* async function retrieveReservationItems (ids: string[]) {
* const inventoryModule = await initializeInventoryModule({})
*
* const [reservationItems, count] = await inventoryModule.listReservationItems({
* id: ids
* }, {
* relations: ["inventory_item"]
* })
*
* // do something with the reservation items or return them
* }
* ```
*
* By default, only the first `10` records are retrieved. You can control pagination by specifying the `skip` and `take` properties of the `config` parameter:
*
* ```ts
* import {
* initialize as initializeInventoryModule,
* } from "@medusajs/inventory"
*
* async function retrieveReservationItems (ids: string[], skip: number, take: number) {
* const inventoryModule = await initializeInventoryModule({})
*
* const [reservationItems, count] = await inventoryModule.listReservationItems({
* id: ids
* }, {
* relations: ["inventory_item"],
* skip,
* take
* })
*
* // do something with the reservation items or return them
* }
* ```
*/
listReservationItems(
selector: InventoryNext.FilterableReservationItemProps,
config?: FindConfig<InventoryNext.ReservationItemDTO>,
context?: Context
): Promise<InventoryNext.ReservationItemDTO[]>
listAndCountReservationItems(
selector: InventoryNext.FilterableReservationItemProps,
config?: FindConfig<InventoryNext.ReservationItemDTO>,
context?: Context
): Promise<[InventoryNext.ReservationItemDTO[], number]>
/**
* This method is used to retrieve a paginated list of inventory levels along with the total count of available inventory levels satisfying the provided filters.
* @param {FilterableInventoryLevelProps} selector - The filters to apply on the retrieved inventory levels.
* @param {FindConfig<InventoryLevelDTO>} config -
* The configurations determining how the inventory levels are retrieved. Its properties, such as `select` or `relations`, accept the
* attributes or relations associated with a inventory level.
* @param {Context} context - A context used to share resources, such as transaction manager, between the application and the module.
* @return {Promise<[InventoryLevelDTO[], number]>} The list of inventory levels along with the total count.
*
* @example
* To retrieve a list of inventory levels using their IDs:
*
* ```ts
* import {
* initialize as initializeInventoryModule,
* } from "@medusajs/inventory"
*
* async function retrieveInventoryLevels (inventoryItemIds: string[]) {
* const inventoryModule = await initializeInventoryModule({})
*
* const [inventoryLevels, count] = await inventoryModule.listInventoryLevels({
* inventory_item_id: inventoryItemIds
* })
*
* // do something with the inventory levels or return them
* }
* ```
*
* To specify relations that should be retrieved within the inventory levels:
*
* ```ts
* import {
* initialize as initializeInventoryModule,
* } from "@medusajs/inventory"
*
* async function retrieveInventoryLevels (inventoryItemIds: string[]) {
* const inventoryModule = await initializeInventoryModule({})
*
* const [inventoryLevels, count] = await inventoryModule.listInventoryLevels({
* inventory_item_id: inventoryItemIds
* }, {
* relations: ["inventory_item"]
* })
*
* // do something with the inventory levels or return them
* }
* ```
*
* By default, only the first `10` records are retrieved. You can control pagination by specifying the `skip` and `take` properties of the `config` parameter:
*
* ```ts
* import {
* initialize as initializeInventoryModule,
* } from "@medusajs/inventory"
*
* async function retrieveInventoryLevels (inventoryItemIds: string[], skip: number, take: number) {
* const inventoryModule = await initializeInventoryModule({})
*
* const [inventoryLevels, count] = await inventoryModule.listInventoryLevels({
* inventory_item_id: inventoryItemIds
* }, {
* relations: ["inventory_item"],
* skip,
* take
* })
*
* // do something with the inventory levels or return them
* }
* ```
*/
listInventoryLevels(
selector: InventoryNext.FilterableInventoryLevelProps,
config?: FindConfig<InventoryNext.InventoryLevelDTO>,
context?: Context
): Promise<InventoryNext.InventoryLevelDTO[]>
listAndCountInventoryLevels(
selector: InventoryNext.FilterableInventoryLevelProps,
config?: FindConfig<InventoryNext.InventoryLevelDTO>,
context?: Context
): Promise<[InventoryNext.InventoryLevelDTO[], number]>
/**
* This method is used to retrieve an inventory item by its ID
*
* @param {string} inventoryItemId - The ID of the inventory item to retrieve.
* @param {FindConfig<InventoryItemDTO>} config -
* The configurations determining how the inventory item is retrieved. Its properties, such as `select` or `relations`, accept the
* attributes or relations associated with a inventory item.
* @param {Context} context - A context used to share resources, such as transaction manager, between the application and the module.
* @returns {Promise<InventoryItemDTO>} The retrieved inventory item.
*
* @example
* A simple example that retrieves a inventory item by its ID:
*
* ```ts
* import {
* initialize as initializeInventoryModule,
* } from "@medusajs/inventory"
*
* async function retrieveInventoryItem (id: string) {
* const inventoryModule = await initializeInventoryModule({})
*
* const inventoryItem = await inventoryModule.retrieveInventoryItem(id)
*
* // do something with the inventory item or return it
* }
* ```
*
* To specify relations that should be retrieved:
*
* ```ts
* import {
* initialize as initializeInventoryModule,
* } from "@medusajs/inventory"
*
* async function retrieveInventoryItem (id: string) {
* const inventoryModule = await initializeInventoryModule({})
*
* const inventoryItem = await inventoryModule.retrieveInventoryItem(id, {
* relations: ["inventory_level"]
* })
*
* // do something with the inventory item or return it
* }
* ```
*/
retrieve(
inventoryItemId: string,
config?: FindConfig<InventoryNext.InventoryItemDTO>,
context?: Context
): Promise<InventoryNext.InventoryItemDTO>
/**
* This method is used to retrieve an inventory level for an inventory item and a location.
*
* @param {string} inventoryItemId - The ID of the inventory item.
* @param {string} locationId - The ID of the location.
* @param {Context} context - A context used to share resources, such as transaction manager, between the application and the module.
* @returns {Promise<InventoryLevelDTO>} The retrieved inventory level.
*
* @example
* import {
* initialize as initializeInventoryModule,
* } from "@medusajs/inventory"
*
* async function retrieveInventoryLevel (
* inventoryItemId: string,
* locationId: string
* ) {
* const inventoryModule = await initializeInventoryModule({})
*
* const inventoryLevel = await inventoryModule.retrieveInventoryLevel(
* inventoryItemId,
* locationId
* )
*
* // do something with the inventory level or return it
* }
*/
retrieveInventoryLevelByItemAndLocation(
inventoryItemId: string,
locationId: string,
context?: Context
): Promise<InventoryNext.InventoryLevelDTO>
retrieveInventoryLevel(
inventoryLevelId: string,
config?: FindConfig<InventoryNext.InventoryLevelDTO>,
context?: Context
): Promise<InventoryNext.InventoryLevelDTO>
/**
* This method is used to retrieve a reservation item by its ID.
*
* @param {string} reservationId - The ID of the reservation item.
* @param {Context} context - A context used to share resources, such as transaction manager, between the application and the module.
* @returns {Promise<ReservationItemDTO>} The retrieved reservation item.
*
* @example
* import {
* initialize as initializeInventoryModule,
* } from "@medusajs/inventory"
*
* async function retrieveReservationItem (id: string) {
* const inventoryModule = await initializeInventoryModule({})
*
* const reservationItem = await inventoryModule.retrieveReservationItem(id)
*
* // do something with the reservation item or return it
* }
*/
retrieveReservationItem(
reservationId: string,
config?: FindConfig<InventoryNext.ReservationItemDTO>,
context?: Context
): Promise<InventoryNext.ReservationItemDTO>
/**
* This method is used to create reservation items.
*
* @param {CreateReservationItemInput[]} input - The details of the reservation items to create.
* @param {Context} context - A context used to share resources, such as transaction manager, between the application and the module.
* @returns { Promise<ReservationItemDTO[]>} The created reservation items' details.
*
* @example
* import {
* initialize as initializeInventoryModule,
* } from "@medusajs/inventory"
*
* async function createReservationItems (items: {
* inventory_item_id: string,
* location_id: string,
* quantity: number
* }[]) {
* const inventoryModule = await initializeInventoryModule({})
*
* const reservationItems = await inventoryModule.createReservationItems(
* items
* )
*
* // do something with the reservation items or return them
* }
*/
createReservationItems(
input: InventoryNext.CreateReservationItemInput[],
context?: Context
): Promise<InventoryNext.ReservationItemDTO[]>
createReservationItems(
input: InventoryNext.CreateReservationItemInput,
context?: Context
): Promise<InventoryNext.ReservationItemDTO>
/**
* This method is used to create inventory items.
*
* @param {CreateInventoryItemInput[]} input - The details of the inventory items to create.
* @param {Context} context - A context used to share resources, such as transaction manager, between the application and the module.
* @returns {Promise<InventoryItemDTO[]>} The created inventory items' details.
*
* @example
* import {
* initialize as initializeInventoryModule,
* } from "@medusajs/inventory"
*
* async function createInventoryItems (items: {
* sku: string,
* requires_shipping: boolean
* }[]) {
* const inventoryModule = await initializeInventoryModule({})
*
* const inventoryItems = await inventoryModule.createInventoryItems(
* items
* )
*
* // do something with the inventory items or return them
* }
*/
create(
input: InventoryNext.CreateInventoryItemInput[],
context?: Context
): Promise<InventoryNext.InventoryItemDTO[]>
create(
input: InventoryNext.CreateInventoryItemInput,
context?: Context
): Promise<InventoryNext.InventoryItemDTO>
/**
* This method is used to create inventory levels.
*
* @param {CreateInventoryLevelInput[]} data - The details of the inventory levels to create.
* @param {Context} context - A context used to share resources, such as transaction manager, between the application and the module.
* @returns {Promise<InventoryLevelDTO[]>} The created inventory levels' details.
*
* @example
* import {
* initialize as initializeInventoryModule,
* } from "@medusajs/inventory"
*
* async function createInventoryLevels (items: {
* inventory_item_id: string
* location_id: string
* stocked_quantity: number
* }[]) {
* const inventoryModule = await initializeInventoryModule({})
*
* const inventoryLevels = await inventoryModule.createInventoryLevels(
* items
* )
*
* // do something with the inventory levels or return them
* }
*/
createInventoryLevels(
data: InventoryNext.CreateInventoryLevelInput[],
context?: Context
): Promise<InventoryNext.InventoryLevelDTO[]>
createInventoryLevels(
data: InventoryNext.CreateInventoryLevelInput,
context?: Context
): Promise<InventoryNext.InventoryLevelDTO>
/**
* This method is used to update inventory levels. Each inventory level is identified by the IDs of its associated inventory item and location.
*
* @param {BulkUpdateInventoryLevelInput} updates - The attributes to update in each inventory level.
* @param {Context} context - A context used to share resources, such as transaction manager, between the application and the module.
* @returns {Promise<InventoryLevelDTO[]>} The updated inventory levels' details.
*
* @example
* import {
* initialize as initializeInventoryModule,
* } from "@medusajs/inventory"
*
* async function updateInventoryLevels (items: {
* inventory_item_id: string,
* location_id: string,
* stocked_quantity: number
* }[]) {
* const inventoryModule = await initializeInventoryModule({})
*
* const inventoryLevels = await inventoryModule.updateInventoryLevels(
* items
* )
*
* // do something with the inventory levels or return them
* }
*/
updateInventoryLevels(
updates: InventoryNext.BulkUpdateInventoryLevelInput[],
context?: Context
): Promise<InventoryNext.InventoryLevelDTO[]>
updateInventoryLevels(
updates: InventoryNext.BulkUpdateInventoryLevelInput,
context?: Context
): Promise<InventoryNext.InventoryLevelDTO>
/**
* This method is used to update an inventory item.
*
* @param {string} inventoryItemId - The ID of the inventory item.
* @param {Partial<CreateInventoryItemInput>} input - The attributes to update in the inventory item.
* @param {Context} context - A context used to share resources, such as transaction manager, between the application and the module.
* @returns {Promise<InventoryItemDTO>} The updated inventory item's details.
*
* @example
* import {
* initialize as initializeInventoryModule,
* } from "@medusajs/inventory"
*
* async function updateInventoryItem (
* inventoryItemId: string,
* sku: string
* ) {
* const inventoryModule = await initializeInventoryModule({})
*
* const inventoryItem = await inventoryModule.updateInventoryItem(
* inventoryItemId,
* {
* sku
* }
* )
*
* // do something with the inventory item or return it
* }
*/
update(
input: InventoryNext.UpdateInventoryItemInput,
context?: Context
): Promise<InventoryNext.InventoryItemDTO>
update(
input: InventoryNext.UpdateInventoryItemInput[],
context?: Context
): Promise<InventoryNext.InventoryItemDTO[]>
/**
* This method is used to update a reservation item.
*
* @param {string} reservationItemId - The ID of the reservation item.
* @param {UpdateReservationItemInput} input - The attributes to update in the reservation item.
* @param {Context} context - A context used to share resources, such as transaction manager, between the application and the module.
* @returns {Promise<ReservationItemDTO>} The updated reservation item.
*
* @example
* import {
* initialize as initializeInventoryModule,
* } from "@medusajs/inventory"
*
* async function updateReservationItem (
* reservationItemId: string,
* quantity: number
* ) {
* const inventoryModule = await initializeInventoryModule({})
*
* const reservationItem = await inventoryModule.updateReservationItem(
* reservationItemId,
* {
* quantity
* }
* )
*
* // do something with the reservation item or return it
* }
*/
updateReservationItems(
input: InventoryNext.UpdateReservationItemInput,
context?: Context
): Promise<InventoryNext.ReservationItemDTO>
updateReservationItems(
input: InventoryNext.UpdateReservationItemInput[],
context?: Context
): Promise<InventoryNext.ReservationItemDTO[]>
/**
* This method is used to delete the reservation items associated with a line item or multiple line items.
*
* @param {string | string[]} lineItemId - The ID(s) of the line item(s).
* @param {Context} context - A context used to share re9sources, such as transaction manager, between the application and the module.
* @returns {Promise<void>} Resolves when the reservation items are successfully deleted.
*
* @example
* import {
* initialize as initializeInventoryModule,
* } from "@medusajs/inventory"
*
* async function deleteReservationItemsByLineItem (
* lineItemIds: string[]
* ) {
* const inventoryModule = await initializeInventoryModule({})
*
* await inventoryModule.deleteReservationItemsByLineItem(
* lineItemIds
* )
* }
*/
deleteReservationItemsByLineItem(
lineItemId: string | string[],
context?: Context
): Promise<void>
/**
* This method is used to delete a reservation item or multiple reservation items by their IDs.
*
* @param {string | string[]} reservationItemId - The ID(s) of the reservation item(s) to delete.
* @param {Context} context - A context used to share resources, such as transaction manager, between the application and the module.
* @returns {Promise<void>} Resolves when the reservation item(s) are successfully deleted.
*
* @example
* import {
* initialize as initializeInventoryModule,
* } from "@medusajs/inventory"
*
* async function deleteReservationItems (
* reservationItemIds: string[]
* ) {
* const inventoryModule = await initializeInventoryModule({})
*
* await inventoryModule.deleteReservationItem(
* reservationItemIds
* )
* }
*/
deleteReservationItems(
reservationItemId: string | string[],
context?: Context
): Promise<void>
/**
* This method is used to delete an inventory item or multiple inventory items. The inventory items are only soft deleted and can be restored using the
* {@link restoreInventoryItem} method.
*
* @param {string | string[]} inventoryItemId - The ID(s) of the inventory item(s) to delete.
* @param {Context} context - A context used to share resources, such as transaction manager, between the application and the module.
* @returns {Promise<void>} Resolves when the inventory item(s) are successfully deleted.
*
* @example
* import {
* initialize as initializeInventoryModule,
* } from "@medusajs/inventory"
*
* async function deleteInventoryItem (
* inventoryItems: string[]
* ) {
* const inventoryModule = await initializeInventoryModule({})
*
* await inventoryModule.deleteInventoryItem(
* inventoryItems
* )
* }
*/
delete(inventoryItemId: string | string[], context?: Context): Promise<void>
/**
* Soft delete inventory items
* @param inventoryItemIds
* @param config
* @param sharedContext
*/
softDelete<TReturnableLinkableKeys extends string = string>(
inventoryItemIds: string[],
config?: SoftDeleteReturn<TReturnableLinkableKeys>,
sharedContext?: Context
): Promise<Record<string, string[]> | void>
/**
* This method is used to restore an inventory item or multiple inventory items that were previously deleted using the {@link deleteInventoryItem} method.
*
* @param {string[]} inventoryItemId - The ID(s) of the inventory item(s) to restore.
* @param {RestoreReturn<TReturnableLinkableKeys>} config - Restore config
* @param {Context} context - A context used to share resources, such as transaction manager, between the application and the module.
* @returns {Promise<void>} Resolves when the inventory item(s) are successfully restored.
*
* @example
* import {
* initialize as initializeInventoryModule,
* } from "@medusajs/inventory"
*
* async function restoreInventoryItem (
* inventoryItems: string[]
* ) {
* const inventoryModule = await initializeInventoryModule({})
*
* await inventoryModule.restoreInventoryItem(
* inventoryItems
* )
* }
*/
restore<TReturnableLinkableKeys extends string = string>(
inventoryItemIds: string[],
config?: RestoreReturn<TReturnableLinkableKeys>,
sharedContext?: Context
): Promise<Record<string, string[]> | void>
/**
* This method deletes the inventory item level(s) for the ID(s) of associated location(s).
*
* @param {string | string[]} locationId - The ID(s) of the associated location(s).
* @param {Context} context - A context used to share resources, such as transaction manager, between the application and the module.
* @returns {Promise<void>} Resolves when the inventory item level(s) are successfully restored.
*
* @example
* import {
* initialize as initializeInventoryModule,
* } from "@medusajs/inventory"
*
* async function deleteInventoryItemLevelByLocationId (
* locationIds: string[]
* ) {
* const inventoryModule = await initializeInventoryModule({})
*
* await inventoryModule.deleteInventoryItemLevelByLocationId(
* locationIds
* )
* }
*/
deleteInventoryItemLevelByLocationId(
locationId: string | string[],
context?: Context
): Promise<[object[], Record<string, unknown[]>]>
/**
* This method deletes reservation item(s) by the ID(s) of associated location(s).
*
* @param {string | string[]} locationId - The ID(s) of the associated location(s).
* @param {Context} context - A context used to share resources, such as transaction manager, between the application and the module.
* @returns {Promise<void>} Resolves when the reservation item(s) are successfully restored.
*
* @example
* import {
* initialize as initializeInventoryModule,
* } from "@medusajs/inventory"
*
* async function deleteReservationItemByLocationId (
* locationIds: string[]
* ) {
* const inventoryModule = await initializeInventoryModule({})
*
* await inventoryModule.deleteReservationItemByLocationId(
* locationIds
* )
* }
*/
deleteReservationItemByLocationId(
locationId: string | string[],
context?: Context
): Promise<void>
/**
* This method is used to delete an inventory level. The inventory level is identified by the IDs of its associated inventory item and location.
*
* @param {string} inventoryItemId - The ID of the associated inventory item.
* @param {string} locationId - The ID of the associated location.
* @param {Context} context - A context used to share resources, such as transaction manager, between the application and the module.
* @returns {Promise<void>} Resolves when the inventory level(s) are successfully restored.
*
* @example
* import {
* initialize as initializeInventoryModule,
* } from "@medusajs/inventory"
*
* async function deleteInventoryLevel (
* inventoryItemId: string,
* locationId: string
* ) {
* const inventoryModule = await initializeInventoryModule({})
*
* await inventoryModule.deleteInventoryLevel(
* inventoryItemId,
* locationId
* )
* }
*/
deleteInventoryLevel(
inventoryItemId: string,
locationId: string,
context?: Context
): Promise<void>
/**
* This method is used to adjust the inventory level's stocked quantity. The inventory level is identified by the IDs of its associated inventory item and location.
*
* @param {string} inventoryItemId - The ID of the associated inventory item.
* @param {string} locationId - The ID of the associated location.
* @param {number} adjustment - A positive or negative number used to adjust the inventory level's stocked quantity.
* @param {Context} context - A context used to share resources, such as transaction manager, between the application and the module.
* @returns {Promise<InventoryLevelDTO>} The inventory level's details.
*
* @example
* import {
* initialize as initializeInventoryModule,
* } from "@medusajs/inventory"
*
* async function adjustInventory (
* inventoryItemId: string,
* locationId: string,
* adjustment: number
* ) {
* const inventoryModule = await initializeInventoryModule({})
*
* const inventoryLevel = await inventoryModule.adjustInventory(
* inventoryItemId,
* locationId,
* adjustment
* )
*
* // do something with the inventory level or return it.
* }
*/
adjustInventory(
inventoryItemId: string,
locationId: string,
adjustment: number,
context?: Context
): Promise<InventoryNext.InventoryLevelDTO>
/**
* This method is used to confirm whether the specified quantity of an inventory item is available in the specified locations.
*
* @param {string} inventoryItemId - The ID of the inventory item to check its availability.
* @param {string[]} locationIds - The IDs of the locations to check the quantity availability in.
* @param {number} quantity - The quantity to check if available for the inventory item in the specified locations.
* @param {Context} context - A context used to share resources, such as transaction manager, between the application and the module.
* @returns {Promise<boolean>} Whether the specified quantity is available for the inventory item in the specified locations.
*
* @example
* import {
* initialize as initializeInventoryModule,
* } from "@medusajs/inventory"
*
* async function confirmInventory (
* inventoryItemId: string,
* locationIds: string[],
* quantity: number
* ) {
* const inventoryModule = await initializeInventoryModule({})
*
* return await inventoryModule.confirmInventory(
* inventoryItemId,
* locationIds,
* quantity
* )
* }
*/
confirmInventory(
inventoryItemId: string,
locationIds: string[],
quantity: number,
context?: Context
): Promise<boolean>
/**
* This method is used to retrieve the available quantity of an inventory item within the specified locations.
*
* @param {string} inventoryItemId - The ID of the inventory item to retrieve its quantity.
* @param {string[]} locationIds - The IDs of the locations to retrieve the available quantity from.
* @param {Context} context - A context used to share resources, such as transaction manager, between the application and the module.
* @returns {Promise<number>} The available quantity of the inventory item in the specified locations.
*
* @example
* import {
* initialize as initializeInventoryModule,
* } from "@medusajs/inventory"
*
* async function retrieveAvailableQuantity (
* inventoryItemId: string,
* locationIds: string[],
* ) {
* const inventoryModule = await initializeInventoryModule({})
*
* const quantity = await inventoryModule.retrieveAvailableQuantity(
* inventoryItemId,
* locationIds,
* )
*
* // do something with the quantity or return it
* }
*/
retrieveAvailableQuantity(
inventoryItemId: string,
locationIds: string[],
context?: Context
): Promise<number>
/**
* This method is used to retrieve the stocked quantity of an inventory item within the specified locations.
*
* @param {string} inventoryItemId - The ID of the inventory item to retrieve its stocked quantity.
* @param {string[]} locationIds - The IDs of the locations to retrieve the stocked quantity from.
* @param {Context} context - A context used to share resources, such as transaction manager, between the application and the module.
* @returns {Promise<number>} The stocked quantity of the inventory item in the specified locations.
*
* @example
* import {
* initialize as initializeInventoryModule,
* } from "@medusajs/inventory"
*
* async function retrieveStockedQuantity (
* inventoryItemId: string,
* locationIds: string[],
* ) {
* const inventoryModule = await initializeInventoryModule({})
*
* const quantity = await inventoryModule.retrieveStockedQuantity(
* inventoryItemId,
* locationIds,
* )
*
* // do something with the quantity or return it
* }
*/
retrieveStockedQuantity(
inventoryItemId: string,
locationIds: string[],
context?: Context
): Promise<number>
/**
* This method is used to retrieve the reserved quantity of an inventory item within the specified locations.
*
* @param {string} inventoryItemId - The ID of the inventory item to retrieve its reserved quantity.
* @param {string[]} locationIds - The IDs of the locations to retrieve the reserved quantity from.
* @param {Context} context - A context used to share resources, such as transaction manager, between the application and the module.
* @returns {Promise<number>} The reserved quantity of the inventory item in the specified locations.
*
* @example
* import {
* initialize as initializeInventoryModule,
* } from "@medusajs/inventory"
*
* async function retrieveReservedQuantity (
* inventoryItemId: string,
* locationIds: string[],
* ) {
* const inventoryModule = await initializeInventoryModule({})
*
* const quantity = await inventoryModule.retrieveReservedQuantity(
* inventoryItemId,
* locationIds,
* )
*
* // do something with the quantity or return it
* }
*/
retrieveReservedQuantity(
inventoryItemId: string,
locationIds: string[],
context?: Context
): Promise<number>
}