diff --git a/packages/types/src/inventory/common/inventory-item.ts b/packages/types/src/inventory/common/inventory-item.ts index 64890fe6cd..4f788d313e 100644 --- a/packages/types/src/inventory/common/inventory-item.ts +++ b/packages/types/src/inventory/common/inventory-item.ts @@ -1,89 +1,97 @@ 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 + * The inventory item details. */ export interface InventoryItemDTO { + /** + * The ID of the inventory item. + */ id: string + + /** + * The SKU of the inventory item. + */ sku?: string | null + + /** + * The origin country of the inventory item. + */ origin_country?: string | null + + /** + * The HS code of the inventory item. + */ hs_code?: string | null + + /** + * Whether the inventory item requires shipping. + */ requires_shipping: boolean + + /** + * 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 | null + + /** + * The creation date of the inventory item. + */ created_at: string | Date + + /** + * The update date of the inventory item. + */ updated_at: string | Date + + /** + * The deletion date of the inventory item. + */ deleted_at: string | Date | null } @@ -97,26 +105,32 @@ 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. */ diff --git a/packages/types/src/inventory/common/inventory-level.ts b/packages/types/src/inventory/common/inventory-level.ts index 2034d0e786..e0f239ebba 100644 --- a/packages/types/src/inventory/common/inventory-level.ts +++ b/packages/types/src/inventory/common/inventory-level.ts @@ -3,76 +3,90 @@ import { BaseFilterable, OperatorMap } from "../../dal" 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 + * The inventory level details. */ export interface InventoryLevelDTO { + /** + * The ID of the inventory level. + */ id: string + + /** + * The associated inventory item's ID. + */ inventory_item_id: string + + /** + * The associated location's ID. + */ location_id: string + + /** + * The stocked quantity of the inventory level. + */ stocked_quantity: number + + /** + * The reserved quantity of the inventory level. + */ reserved_quantity: number + + /** + * The incoming quantity of the inventory level. + */ incoming_quantity: number + + /** + * The available quantity of the inventory level. + */ available_quantity: number + + /** + * Holds custom data in key-value pairs. + */ metadata: Record | null + + /** + * The creation date of the inventory level. + */ created_at: string | Date + + /** + * The update date of the inventory level. + */ updated_at: string | Date + + /** + * The deletion date of the inventory level. + */ deleted_at: string | Date | null } +/** + * The filters to apply on the retrieved inventory levels. + */ export interface FilterableInventoryLevelProps extends BaseFilterable { /** * 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 | OperatorMap + /** * Filters to apply on inventory levels' `reserved_quantity` attribute. */ reserved_quantity?: number | OperatorMap + /** * Filters to apply on inventory levels' `incoming_quantity` attribute. */ diff --git a/packages/types/src/inventory/common/reservation-item.ts b/packages/types/src/inventory/common/reservation-item.ts index 2f3a075189..20c771b2b2 100644 --- a/packages/types/src/inventory/common/reservation-item.ts +++ b/packages/types/src/inventory/common/reservation-item.ts @@ -4,62 +4,62 @@ import { } 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 + * The reservation item details. */ export interface ReservationItemDTO { + /** + * The ID of the reservation item. + */ id: string + + /** + * The associated location's ID. + */ location_id: string + + /** + * The associated inventory item's ID. + */ inventory_item_id: string + + /** + * The quantity of the reservation item. + */ quantity: number + + /** + * The associated line item's ID. + */ line_item_id?: string | null + + /** + * The description of the reservation item. + */ description?: string | null + + /** + * The created by of the reservation item. + */ created_by?: string | null + + /** + * Holds custom data in key-value pairs. + */ metadata: Record | null + + /** + * The creation date of the reservation item. + */ created_at: string | Date + + /** + * The update date of the reservation item. + */ updated_at: string | Date + + /** + * The deletion date of the reservation item. + */ deleted_at: string | Date | null } @@ -73,6 +73,7 @@ export interface FilterableReservationItemProps { * The IDs to filter reservation items by. */ id?: string | string[] + /** * @ignore * @@ -80,26 +81,32 @@ export interface FilterableReservationItemProps { * 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. */ diff --git a/packages/types/src/inventory/service-next.ts b/packages/types/src/inventory/service-next.ts index b8be5a8597..b07ad241ca 100644 --- a/packages/types/src/inventory/service-next.ts +++ b/packages/types/src/inventory/service-next.ts @@ -1,82 +1,57 @@ 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. + * 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. + * This method retrieves a paginated list of inventory items based on optional filters and configuration. + * * @param {FilterableInventoryItemProps} selector - The filters to apply on the retrieved inventory items. - * @param {FindConfig} config - - * The configurations determining how the inventory items are retrieved. Its properties, such as `select` or `relations`, accept the + * @param {FindConfig} 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. - * @return {Promise<[InventoryItemDTO[], number]>} The list of inventory items along with the total count. + * @returns {Promise} The list of inventory items. * * @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 - * } + * const inventoryItems = await inventoryModuleService.list({ + * id: ["iitem_123", "iitem_321"], + * }) * ``` * * 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 - * } + * const inventoryItems = await inventoryModuleService.list( + * { + * id: ["iitem_123", "iitem_321"], + * }, + * { + * relations: ["location_levels"], + * } + * ) * ``` * * 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 - * } + * const inventoryItems = await inventoryModuleService.list( + * { + * id: ["iitem_123", "iitem_321"], + * }, + * { + * relations: ["location_levels"], + * take: 20, + * skip: 2, + * } + * ) * ``` */ list( @@ -85,6 +60,55 @@ export interface IInventoryServiceNext extends IModuleService { context?: Context ): Promise + /** + * This method retrieves 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} 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[], number]>} The list of inventory items along with their total count. + * + * @example + * To retrieve a list of inventory items using their IDs: + * + * ```ts + * const [inventoryItems, count] = + * await inventoryModuleService.listAndCount({ + * id: ["iitem_123", "iitem_321"], + * }) + * ``` + * + * To specify relations that should be retrieved within the inventory items: + * + * ```ts + * const [inventoryItems, count] = + * await inventoryModuleService.listAndCount( + * { + * id: ["iitem_123", "iitem_321"], + * }, + * { + * relations: ["location_levels"], + * } + * ) + * ``` + * + * 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 + * const [inventoryItems, count] = + * await inventoryModuleService.listAndCount( + * { + * id: ["iitem_123", "iitem_321"], + * }, + * { + * relations: ["location_levels"], + * take: 20, + * skip: 2, + * } + * ) + * ``` + */ listAndCount( selector: InventoryNext.FilterableInventoryItemProps, config?: FindConfig, @@ -92,73 +116,52 @@ export interface IInventoryServiceNext extends IModuleService { ): 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. + * This method retrieves a paginated list of reservation items based on optional filters and configuration. + * * @param {FilterableReservationItemProps} selector - The filters to apply on the retrieved reservation items. - * @param {FindConfig} config - - * The configurations determining how the reservation items are retrieved. Its properties, such as `select` or `relations`, accept the + * @param {FindConfig} config - The configurations determining how the reservation item is 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. + * @returns {Promise} The list of reservation items. * * @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 + * const reservationItems = + * await inventoryModuleService.listReservationItems({ + * id: ["resitem_123", "resitem_321"], * }) - * - * // 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 - * } + * const reservationItems = + * await inventoryModuleService.listReservationItems( + * { + * id: ["resitem_123", "resitem_321"], + * }, + * { + * relations: ["inventory_item"], + * } + * ) * ``` * * 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 - * } + * const reservationItems = + * await inventoryModuleService.listReservationItems( + * { + * id: ["resitem_123", "resitem_321"], + * }, + * { + * relations: ["inventory_item"], + * take: 20, + * skip: 2, + * } + * ) * ``` */ listReservationItems( @@ -167,6 +170,55 @@ export interface IInventoryServiceNext extends IModuleService { context?: Context ): Promise + /** + * This method retrieves 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} config - The configurations determining how the reservation item is 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. + * @returns {Promise<[ReservationItemDTO[], number]>} The list of reservation items along with their total count. + * + * @example + * To retrieve a list of reservation items using their IDs: + * + * ```ts + * const [reservationItems, count] = + * await inventoryModuleService.listAndCountReservationItems({ + * id: ["resitem_123", "resitem_321"], + * }) + * ``` + * + * To specify relations that should be retrieved within the reservation items: + * + * ```ts + * const [reservationItems, count] = + * await inventoryModuleService.listAndCountReservationItems( + * { + * id: ["resitem_123", "resitem_321"], + * }, + * { + * relations: ["inventory_item"], + * } + * ) + * ``` + * + * 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 + * const [reservationItems, count] = + * await inventoryModuleService.listAndCountReservationItems( + * { + * id: ["resitem_123", "resitem_321"], + * }, + * { + * relations: ["inventory_item"], + * take: 20, + * skip: 2, + * } + * ) + * ``` + */ listAndCountReservationItems( selector: InventoryNext.FilterableReservationItemProps, config?: FindConfig, @@ -174,73 +226,52 @@ export interface IInventoryServiceNext extends IModuleService { ): 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. + * This method retrieves a paginated list of inventory levels based on optional filters and configuration. + * * @param {FilterableInventoryLevelProps} selector - The filters to apply on the retrieved inventory levels. - * @param {FindConfig} config - - * The configurations determining how the inventory levels are retrieved. Its properties, such as `select` or `relations`, accept the + * @param {FindConfig} config - The configurations determining how the inventory level is 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. + * @returns {Promise} The list of inventory levels. * * @example - * To retrieve a list of inventory levels using their IDs: + * To retrieve a list of inventory levels using the IDs of their associated inventory items: * * ```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 + * const inventoryLevels = + * await inventoryModuleService.listInventoryLevels({ + * inventory_item_id: ["iitem_123", "iitem_321"], * }) - * - * // 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 - * } + * const inventoryLevels = + * await inventoryModuleService.listInventoryLevels( + * { + * inventory_item_id: ["iitem_123", "iitem_321"], + * }, + * { + * relations: ["inventory_item"], + * } + * ) * ``` * * 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 - * } + * const inventoryLevels = + * await inventoryModuleService.listInventoryLevels( + * { + * inventory_item_id: ["iitem_123", "iitem_321"], + * }, + * { + * relations: ["inventory_item"], + * take: 20, + * skip: 2, + * } + * ) * ``` */ listInventoryLevels( @@ -249,6 +280,55 @@ export interface IInventoryServiceNext extends IModuleService { context?: Context ): Promise + /** + * This method retrieves 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} config - The configurations determining how the inventory level is 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. + * @returns {Promise<[InventoryLevelDTO[], number]>} The list of inventory levels along with their total count. + * + * @example + * To retrieve a list of inventory levels using the IDs of their associated inventory items: + * + * ```ts + * const [inventoryLevels, count] = + * await inventoryModuleService.listAndCountInventoryLevels( + * { + * inventory_item_id: ["iitem_123", "iitem_321"], + * }, + * { + * relations: ["inventory_item"], + * take: 20, + * skip: 2, + * } + * ) + * ``` + * + * To specify relations that should be retrieved within the inventory levels: + * + * ```ts + * const [inventoryLevels, count] = + * await inventoryModuleService.listAndCountInventoryLevels( + * { + * inventory_item_id: ["iitem_123", "iitem_321"], + * }, + * { + * relations: ["inventory_item"], + * } + * ) + * ``` + * + * 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 + * const [inventoryLevels, count] = + * await inventoryModuleService.listAndCountInventoryLevels({ + * inventory_item_id: ["iitem_123", "iitem_321"], + * }) + * ``` + */ listAndCountInventoryLevels( selector: InventoryNext.FilterableInventoryLevelProps, config?: FindConfig, @@ -256,11 +336,10 @@ export interface IInventoryServiceNext extends IModuleService { ): Promise<[InventoryNext.InventoryLevelDTO[], number]> /** - * This method is used to retrieve an inventory item by its ID + * This method retrieves an inventory item by its ID. * - * @param {string} inventoryItemId - The ID of the inventory item to retrieve. - * @param {FindConfig} config - - * The configurations determining how the inventory item is retrieved. Its properties, such as `select` or `relations`, accept the + * @param {string} inventoryItemId - The inventory item's ID. + * @param {FindConfig} 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} The retrieved inventory item. @@ -269,35 +348,19 @@ export interface IInventoryServiceNext extends IModuleService { * 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 - * } + * const inventoryItem = + * await inventoryModuleService.retrieve("iitem_123") * ``` * * 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 - * } + * const inventoryItem = await inventoryModuleService.retrieve( + * "iitem_123", + * { + * relations: ["location_levels"], + * } + * ) * ``` */ retrieve( @@ -307,31 +370,19 @@ export interface IInventoryServiceNext extends IModuleService { ): Promise /** - * This method is used to retrieve an inventory level for an inventory item and a location. + * This method retrieves an inventory level based on its associated inventory item and location. * - * @param {string} inventoryItemId - The ID of the inventory item. - * @param {string} locationId - The ID of the location. + * @param {string} inventoryItemId - The inventory item's ID. + * @param {string} locationId - The location's ID. * @param {Context} context - A context used to share resources, such as transaction manager, between the application and the module. * @returns {Promise} 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 + * const inventoryLevel = + * await inventoryModuleService.retrieveInventoryLevelByItemAndLocation( + * "iitem_123", + * "loc_123" * ) - * - * // do something with the inventory level or return it - * } */ retrieveInventoryLevelByItemAndLocation( inventoryItemId: string, @@ -339,6 +390,37 @@ export interface IInventoryServiceNext extends IModuleService { context?: Context ): Promise + /** + * This method retrieves an inventory level by its ID. + * + * @param {string} inventoryLevelId - The inventory level's ID. + * @param {FindConfig} config - The configurations determining how the inventory level is 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. + * @returns {Promise} The retrieved inventory level. + * + * @example + * A simple example that retrieves a inventory level by its ID: + * + * ```ts + * const inventoryLevel = + * await inventoryModuleService.retrieveInventoryLevel( + * "iitem_123" + * ) + * ``` + * + * To specify relations that should be retrieved: + * + * ```ts + * const inventoryLevel = + * await inventoryModuleService.retrieveInventoryLevel( + * "iitem_123", + * { + * relations: ["inventory_item"], + * } + * ) + * ``` + */ retrieveInventoryLevel( inventoryLevelId: string, config?: FindConfig, @@ -346,24 +428,35 @@ export interface IInventoryServiceNext extends IModuleService { ): Promise /** - * This method is used to retrieve a reservation item by its ID. + * This method retrieves a reservation item by its ID. * - * @param {string} reservationId - The ID of the reservation item. + * @param {string} reservationId - The reservation's ID. + * @param {FindConfig} config - The configurations determining how the reservation item is 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. * @returns {Promise} The retrieved reservation item. * * @example - * import { - * initialize as initializeInventoryModule, - * } from "@medusajs/inventory" + * A simple example that retrieves a reservation item by its ID: * - * async function retrieveReservationItem (id: string) { - * const inventoryModule = await initializeInventoryModule({}) + * ```ts + * const reservationItem = + * await inventoryModuleService.retrieveReservationItem( + * "resitem" + * ) + * ``` * - * const reservationItem = await inventoryModule.retrieveReservationItem(id) + * To specify relations that should be retrieved: * - * // do something with the reservation item or return it - * } + * ```ts + * const reservationItem = + * await inventoryModuleService.retrieveReservationItem( + * "resitem", + * { + * relations: ["inventory_item"], + * } + * ) + * ``` */ retrieveReservationItem( reservationId: string, @@ -372,241 +465,267 @@ export interface IInventoryServiceNext extends IModuleService { ): Promise /** - * This method is used to create reservation items. + * This method creates reservation items. * - * @param {CreateReservationItemInput[]} input - The details of the reservation items to create. + * @param {CreateReservationItemInput[]} input - The details of the reservation items to be created. * @param {Context} context - A context used to share resources, such as transaction manager, between the application and the module. - * @returns { Promise} The created reservation items' details. + * @returns {Promise} The created reservation items. * * @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 - * } + * const reservationItems = + * await inventoryModuleService.createReservationItems([ + * { + * inventory_item_id: "iitem_123", + * location_id: "loc_123", + * quantity: 10, + * }, + * ]) */ createReservationItems( input: InventoryNext.CreateReservationItemInput[], context?: Context ): Promise + + /** + * This method creates a reservation item. + * + * @param {CreateReservationItemInput} input - The details of the reservation item to be created. + * @param {Context} context - A context used to share resources, such as transaction manager, between the application and the module. + * @returns {Promise} The created reservation item. + * + * @example + * const reservationItem = + * await inventoryModuleService.createReservationItems({ + * inventory_item_id: "iitem_123", + * location_id: "loc_123", + * quantity: 10, + * }) + */ createReservationItems( input: InventoryNext.CreateReservationItemInput, context?: Context ): Promise /** - * This method is used to create inventory items. + * This method creates inventory items. * - * @param {CreateInventoryItemInput[]} input - The details of the inventory items to create. + * @param {CreateInventoryItemInput[]} input - The details of the inventory items to be created. * @param {Context} context - A context used to share resources, such as transaction manager, between the application and the module. - * @returns {Promise} The created inventory items' details. + * @returns {Promise} The created inventory items. * * @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 - * } + * const inventoryItems = await inventoryModuleService.create([ + * { + * sku: "SHIRT", + * }, + * ]) */ create( input: InventoryNext.CreateInventoryItemInput[], context?: Context ): Promise + + /** + * This method creates an inventory item. + * + * @param {CreateInventoryItemInput} input - The details of the inventory item to be created. + * @param {Context} context - A context used to share resources, such as transaction manager, between the application and the module. + * @returns {Promise} The created inventory item. + * + * @example + * const inventoryItem = await inventoryModuleService.create({ + * sku: "SHIRT", + * }) + */ create( input: InventoryNext.CreateInventoryItemInput, context?: Context ): Promise /** - * This method is used to create inventory levels. + * This method creates inventory levels. * - * @param {CreateInventoryLevelInput[]} data - The details of the inventory levels to create. + * @param {CreateInventoryLevelInput[]} data - The details of the inventory levels to be created. * @param {Context} context - A context used to share resources, such as transaction manager, between the application and the module. - * @returns {Promise} The created inventory levels' details. + * @returns {Promise} The created inventory levels. * * @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 - * } + * const inventoryLevels = + * await inventoryModuleService.createInventoryLevels([ + * { + * inventory_item_id: "iitem_123", + * location_id: "loc_123", + * stocked_quantity: 10, + * }, + * { + * inventory_item_id: "iitem_321", + * location_id: "loc_321", + * stocked_quantity: 20, + * reserved_quantity: 10, + * }, + * ]) */ createInventoryLevels( data: InventoryNext.CreateInventoryLevelInput[], context?: Context ): Promise + + /** + * This method creates an inventory level. + * + * @param {CreateInventoryLevelInput} data - The details of the inventory level to be created. + * @param {Context} context - A context used to share resources, such as transaction manager, between the application and the module. + * @returns {Promise} The created inventory level. + * + * @example + * const inventoryLevels = + * await inventoryModuleService.createInventoryLevels({ + * inventory_item_id: "iitem_123", + * location_id: "loc_123", + * stocked_quantity: 10, + * }) + */ createInventoryLevels( data: InventoryNext.CreateInventoryLevelInput, context?: Context ): Promise /** - * This method is used to update inventory levels. Each inventory level is identified by the IDs of its associated inventory item and location. + * This method updates existing inventory levels. * - * @param {BulkUpdateInventoryLevelInput} updates - The attributes to update in each inventory level. + * @param {BulkUpdateInventoryLevelInput[]} updates - The list of The attributes to update in an inventory level. The inventory level is identified by the IDs of its associated inventory item and location. * @param {Context} context - A context used to share resources, such as transaction manager, between the application and the module. - * @returns {Promise} The updated inventory levels' details. + * @returns {Promise} The updated inventory levels. * * @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 - * } + * const inventoryLevels = + * await inventoryModuleService.updateInventoryLevels([ + * { + * inventory_item_id: "iitem_123", + * location_id: "loc_123", + * id: "ilev_123", + * stocked_quantity: 20, + * }, + * ]) */ updateInventoryLevels( updates: InventoryNext.BulkUpdateInventoryLevelInput[], context?: Context ): Promise + + /** + * This method updates an existing inventory level. + * + * @param {BulkUpdateInventoryLevelInput} updates - The attributes to update in an inventory level. The inventory level is identified by the IDs of its associated inventory item and location. + * @param {Context} context - A context used to share resources, such as transaction manager, between the application and the module. + * @returns {Promise} The updated inventory level. + * + * @example + * const inventoryLevel = + * await inventoryModuleService.updateInventoryLevels({ + * inventory_item_id: "iitem_123", + * location_id: "loc_123", + * stocked_quantity: 20, + * }) + */ updateInventoryLevels( updates: InventoryNext.BulkUpdateInventoryLevelInput, context?: Context ): Promise /** - * This method is used to update an inventory item. + * This method updates an existing inventory item. * - * @param {string} inventoryItemId - The ID of the inventory item. - * @param {Partial} input - The attributes to update in the inventory item. + * @param {UpdateInventoryItemInput} 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} The updated inventory item's details. + * @returns {Promise} The updated inventory item. * * @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 - * } + * const inventoryItem = await inventoryModuleService.update({ + * id: "iitem_123", + * title: "Medusa Shirt Inventory", + * }) */ update( input: InventoryNext.UpdateInventoryItemInput, context?: Context ): Promise + + /** + * This method updates existing inventory items. + * + * @param {UpdateInventoryItemInput[]} input - The attributes to update in the inventory items. + * @param {Context} context - A context used to share resources, such as transaction manager, between the application and the module. + * @returns {Promise} The updated inventory items. + * + * @example + * const inventoryItems = await inventoryModuleService.update([ + * { + * id: "iitem_123", + * title: "Medusa Shirt Inventory", + * }, + * { + * id: "iitem_321", + * description: "The inventory of Medusa pants", + * }, + * ]) + */ update( input: InventoryNext.UpdateInventoryItemInput[], context?: Context ): Promise /** - * This method is used to update a reservation item. + * This method updates an existing reservation item. * - * @param {string} reservationItemId - The ID of the reservation item. - * @param {UpdateReservationItemInput} input - The attributes to update in the reservation item. + * @param {UpdateReservationItemInput} input - The attributes to update in a reservation item. * @param {Context} context - A context used to share resources, such as transaction manager, between the application and the module. * @returns {Promise} 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 - * } + * const reservationItem = + * await inventoryModuleService.updateReservationItems({ + * id: "resitem_123", + * quantity: 10, + * }) */ updateReservationItems( input: InventoryNext.UpdateReservationItemInput, context?: Context ): Promise + + /** + * This method updates existing reservation items. + * + * @param {UpdateReservationItemInput[]} input - The attributes to update in the reservation items. + * @param {Context} context - A context used to share resources, such as transaction manager, between the application and the module. + * @returns {Promise} The updated reservation items. + * + * @example + * const reservationItems = + * await inventoryModuleService.updateReservationItems([ + * { + * id: "resitem_123", + * quantity: 10, + * }, + * ]) + */ updateReservationItems( input: InventoryNext.UpdateReservationItemInput[], context?: Context ): Promise /** - * This method is used to delete the reservation items associated with a line item or multiple line items. + * This method deletes a reservation item by its associated line item. * - * @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} Resolves when the reservation items are successfully deleted. + * @param {string | string[]} lineItemId - The line item's ID. + * @param {Context} context - A context used to share resources, such as transaction manager, between the application and the module. + * @returns {Promise} Resolves when the reservation item is deleted. * * @example - * import { - * initialize as initializeInventoryModule, - * } from "@medusajs/inventory" - * - * async function deleteReservationItemsByLineItem ( - * lineItemIds: string[] - * ) { - * const inventoryModule = await initializeInventoryModule({}) - * - * await inventoryModule.deleteReservationItemsByLineItem( - * lineItemIds - * ) - * } + * await inventoryModuleService.deleteReservationItemByLocationId( + * "cali_123" + * ) */ deleteReservationItemsByLineItem( lineItemId: string | string[], @@ -614,26 +733,16 @@ export interface IInventoryServiceNext extends IModuleService { ): Promise /** - * This method is used to delete a reservation item or multiple reservation items by their IDs. + * This method deletes reservation items by their IDs. * - * @param {string | string[]} reservationItemId - The ID(s) of the reservation item(s) to delete. + * @param {string | string[]} reservationItemId - The reservation items' IDs. * @param {Context} context - A context used to share resources, such as transaction manager, between the application and the module. - * @returns {Promise} Resolves when the reservation item(s) are successfully deleted. + * @returns {Promise} Resolves when the reservation item is deleted. * * @example - * import { - * initialize as initializeInventoryModule, - * } from "@medusajs/inventory" - * - * async function deleteReservationItems ( - * reservationItemIds: string[] - * ) { - * const inventoryModule = await initializeInventoryModule({}) - * - * await inventoryModule.deleteReservationItem( - * reservationItemIds - * ) - * } + * await inventoryModuleService.deleteReservationItems( + * "resitem_123" + * ) */ deleteReservationItems( reservationItemId: string | string[], @@ -641,63 +750,64 @@ export interface IInventoryServiceNext extends IModuleService { ): Promise /** - * 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. + * This method deletes inventory items by their IDs. * - * @param {string | string[]} inventoryItemId - The ID(s) of the inventory item(s) to delete. + * @param {string | string[]} inventoryItemId - The inventory item's ID. * @param {Context} context - A context used to share resources, such as transaction manager, between the application and the module. - * @returns {Promise} Resolves when the inventory item(s) are successfully deleted. + * @returns {Promise} Resolves when the inventory items are deleted. * * @example - * import { - * initialize as initializeInventoryModule, - * } from "@medusajs/inventory" - * - * async function deleteInventoryItem ( - * inventoryItems: string[] - * ) { - * const inventoryModule = await initializeInventoryModule({}) - * - * await inventoryModule.deleteInventoryItem( - * inventoryItems - * ) - * } + * await inventoryModuleService.delete("iitem_123") */ delete(inventoryItemId: string | string[], context?: Context): Promise /** - * Soft delete inventory items - * @param inventoryItemIds - * @param config - * @param sharedContext + * This method soft deletes inventory items by their IDs. + * + * @param {string[]} inventoryItemIds - The inventory items' IDs. + * @param {SoftDeleteReturn} config - An object that is used to specify an entity's related entities that should be soft-deleted when the main entity is soft-deleted. + * @param {Context} sharedContext - A context used to share resources, such as transaction manager, between the application and the module. + * @returns {Promise>} An object that includes the IDs of related records that were also soft deleted, such as the ID of the associated location levels. + * The object's keys are the ID attribute names of the inventory service next entity's relations, such as `location_level_id`, and its value is an array of strings, each being the ID of a record associated + * with the inventory item through this relation, such as the IDs of associated location levels. + * + * If there are no related records, the promise resolves to `void`. + * + * @example + * await inventoryModuleService.softDelete( + * ["iitem_123", "iitem_321"], + * { + * returnLinkableKeys: ["location_level"], + * } + * ) */ softDelete( inventoryItemIds: string[], config?: SoftDeleteReturn, sharedContext?: Context ): Promise | void> + /** - * This method is used to restore an inventory item or multiple inventory items that were previously deleted using the {@link deleteInventoryItem} method. + * This method restores soft deleted inventory items by their IDs. * - * @param {string[]} inventoryItemId - The ID(s) of the inventory item(s) to restore. - * @param {RestoreReturn} config - Restore config - * @param {Context} context - A context used to share resources, such as transaction manager, between the application and the module. - * @returns {Promise} Resolves when the inventory item(s) are successfully restored. + * @param {string[]} inventoryItemIds - The inventory items' IDs. + * @param {RestoreReturn} config - Configurations determining which relations to restore along with each of the inventory items. You can pass to its `returnLinkableKeys` + * property any of the inventory item's relation attribute names, such as `location_levels`. + * @param {Context} sharedContext - A context used to share resources, such as transaction manager, between the application and the module. + * @returns {Promise>} An object that includes the IDs of related records that were restored, such as the ID of associated location levels. + * The object's keys are the ID attribute names of the inventory item entity's relations, such as `location_level_id`, + * and its value is an array of strings, each being the ID of the record associated with the inventory item through this relation, + * such as the IDs of associated location levels. + * + * If there are no related records restored, the promise resolves to `void`. * * @example - * import { - * initialize as initializeInventoryModule, - * } from "@medusajs/inventory" - * - * async function restoreInventoryItem ( - * inventoryItems: string[] - * ) { - * const inventoryModule = await initializeInventoryModule({}) - * - * await inventoryModule.restoreInventoryItem( - * inventoryItems - * ) - * } + * await inventoryModuleService.restore( + * ["iitem_123", "iitem_321"], + * { + * returnLinkableKeys: ["location_level"], + * } + * ) */ restore( inventoryItemIds: string[], @@ -706,26 +816,17 @@ export interface IInventoryServiceNext extends IModuleService { ): Promise | void> /** - * This method deletes the inventory item level(s) for the ID(s) of associated location(s). + * This method soft deletes inventory item's level by the associated location. * - * @param {string | string[]} locationId - The ID(s) of the associated location(s). + * @param {string | string[]} locationId - The locations' IDs. * @param {Context} context - A context used to share resources, such as transaction manager, between the application and the module. - * @returns {Promise} Resolves when the inventory item level(s) are successfully restored. + * @returns {Promise<[object[], Record]>} An array, where the first item is an array includes the soft-deleted inventory levels, + * and the second is an object that includes the IDs of related records that were soft-deleted. * * @example - * import { - * initialize as initializeInventoryModule, - * } from "@medusajs/inventory" - * - * async function deleteInventoryItemLevelByLocationId ( - * locationIds: string[] - * ) { - * const inventoryModule = await initializeInventoryModule({}) - * - * await inventoryModule.deleteInventoryItemLevelByLocationId( - * locationIds - * ) - * } + * await inventoryModuleService.deleteInventoryItemLevelByLocationId( + * "loc_123" + * ) */ deleteInventoryItemLevelByLocationId( locationId: string | string[], @@ -733,26 +834,16 @@ export interface IInventoryServiceNext extends IModuleService { ): Promise<[object[], Record]> /** - * This method deletes reservation item(s) by the ID(s) of associated location(s). + * This method deletes reservation items by their associated location. * - * @param {string | string[]} locationId - The ID(s) of the associated location(s). + * @param {string | string[]} locationId - The location's ID. * @param {Context} context - A context used to share resources, such as transaction manager, between the application and the module. - * @returns {Promise} Resolves when the reservation item(s) are successfully restored. + * @returns {Promise} Resolves when then reservation items are deleted successfully. * * @example - * import { - * initialize as initializeInventoryModule, - * } from "@medusajs/inventory" - * - * async function deleteReservationItemByLocationId ( - * locationIds: string[] - * ) { - * const inventoryModule = await initializeInventoryModule({}) - * - * await inventoryModule.deleteReservationItemByLocationId( - * locationIds - * ) - * } + * await inventoryModuleService.deleteReservationItemByLocationId( + * "loc_123" + * ) */ deleteReservationItemByLocationId( locationId: string | string[], @@ -760,29 +851,18 @@ export interface IInventoryServiceNext extends IModuleService { ): Promise /** - * This method is used to delete an inventory level. The inventory level is identified by the IDs of its associated inventory item and location. + * This method deletes an inventory level by 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 {string} inventoryItemId - The inventory item's ID. + * @param {string} locationId - The location's ID. * @param {Context} context - A context used to share resources, such as transaction manager, between the application and the module. - * @returns {Promise} Resolves when the inventory level(s) are successfully restored. + * @returns {Promise} Resolves when the inventory level is deleted successfully. * * @example - * import { - * initialize as initializeInventoryModule, - * } from "@medusajs/inventory" - * - * async function deleteInventoryLevel ( - * inventoryItemId: string, - * locationId: string - * ) { - * const inventoryModule = await initializeInventoryModule({}) - * - * await inventoryModule.deleteInventoryLevel( - * inventoryItemId, - * locationId - * ) - * } + * await inventoryModuleService.deleteInventoryLevel( + * "iitem_123", + * "loc_123" + * ) */ deleteInventoryLevel( inventoryItemId: string, @@ -790,51 +870,87 @@ export interface IInventoryServiceNext extends IModuleService { context?: Context ): Promise + /** + * This method deletes inventory levels by their IDs. + * + * @param {string | string[]} inventoryLevelIds - The inventory levels' IDs. + * @param {Context} context - A context used to share resources, such as transaction manager, between the application and the module. + * @returns {Promise} Resolves when the inventory levels are deleted. + * + * @example + * await inventoryModuleService.deleteInventoryLevels("ilev_123") + */ deleteInventoryLevels( inventoryLevelIds: string | string[], context?: Context ): Promise + /** + * This method soft deletes inventory levels by their IDs. + * + * @param {string[]} inventoryLevelIds - The inventory levels' IDs. + * @param {SoftDeleteReturn} config - An object that is used to specify an entity's related entities that should be soft-deleted when the main entity is soft-deleted. + * @param {Context} sharedContext - A context used to share resources, such as transaction manager, between the application and the module. + * @returns {Promise>} An object that includes the IDs of related records that were also soft deleted. + * If there are no related records, the promise resolves to `void`. + * + * @example + * await inventoryModuleService.softDeleteInventoryLevels([ + * "ilev_123", + * ]) + */ softDeleteInventoryLevels( inventoryLevelIds: string[], config?: SoftDeleteReturn, sharedContext?: Context ): Promise | void> + /** + * This method restores soft deleted inventory levels by their IDs. + * + * @param {string[]} inventoryLevelIds - The inventory levels' IDs. + * @param {RestoreReturn} config - Configurations determining which relations to restore along with each of the inventory level. You can pass to its `returnLinkableKeys` + * property any of the inventory level's relation attribute names, such as `{type relation name}`. + * @param {Context} sharedContext - A context used to share resources, such as transaction manager, between the application and the module. + * @returns {Promise>} An object that includes the IDs of related records that were restored. + * If there are no related records restored, the promise resolves to `void`. + * + * @example + * await inventoryModuleService.restoreInventoryLevels([ + * "ilev_123", + * ]) + */ restoreInventoryLevels( inventoryLevelIds: string[], config?: RestoreReturn, sharedContext?: 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. + * This method adjusts the inventory quantity of an item in a 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 {string} inventoryItemId - The inventory item's ID. + * @param {string} locationId - The location's ID. + * @param {number} adjustment - the adjustment to make to the quantity. * @param {Context} context - A context used to share resources, such as transaction manager, between the application and the module. - * @returns {Promise} The inventory level's details. + * @returns {Promise} The updated inventory level. * * @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 + * // add to the inventory quantity + * const inventoryLevel1 = + * await inventoryModuleService.adjustInventory( + * "iitem_123", + * "loc_123", + * 5 * ) * - * // do something with the inventory level or return it. - * } + * // subtract from the inventory quantity + * const inventoryLevel2 = + * await inventoryModuleService.adjustInventory( + * "iitem_123", + * "loc_123", + * -5 + * ) */ adjustInventory( inventoryItemId: string, @@ -844,32 +960,21 @@ export interface IInventoryServiceNext extends IModuleService { ): Promise /** - * This method is used to confirm whether the specified quantity of an inventory item is available in the specified locations. + * This method confirms that a quantity is available of an inventory item 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 {string} inventoryItemId - The inventory item's ID. + * @param {string[]} locationIds - The locations' IDs. + * @param {number} quantity - The quantity to confirm its availability. * @param {Context} context - A context used to share resources, such as transaction manager, between the application and the module. - * @returns {Promise} Whether the specified quantity is available for the inventory item in the specified locations. + * @returns {Promise} Whether the quantity is available. * * @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 + * const isAvailable = + * await inventoryModuleService.confirmInventory( + * "iitem_123", + * ["loc_123", "loc_321"], + * 10 * ) - * } */ confirmInventory( inventoryItemId: string, @@ -879,31 +984,19 @@ export interface IInventoryServiceNext extends IModuleService { ): Promise /** - * This method is used to retrieve the available quantity of an inventory item within the specified locations. + * This method retrieves the available quantity of an inventory item in 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 {string} inventoryItemId - The inventory item's ID. + * @param {string[]} locationIds - The locations' IDs. * @param {Context} context - A context used to share resources, such as transaction manager, between the application and the module. - * @returns {Promise} The available quantity of the inventory item in the specified locations. + * @returns {Promise} The available quantity of the item. * * @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, + * const availableQuantity = + * await inventoryModuleService.retrieveAvailableQuantity( + * "iitem_123", + * ["loc_123", "loc_321"] * ) - * - * // do something with the quantity or return it - * } */ retrieveAvailableQuantity( inventoryItemId: string, @@ -912,31 +1005,19 @@ export interface IInventoryServiceNext extends IModuleService { ): Promise /** - * This method is used to retrieve the stocked quantity of an inventory item within the specified locations. + * This method retrieves the stocked quantity of an inventory item in the specified location. * - * @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 {string} inventoryItemId - The inventory item's ID. + * @param {string[]} locationIds - The locations' IDs. * @param {Context} context - A context used to share resources, such as transaction manager, between the application and the module. - * @returns {Promise} The stocked quantity of the inventory item in the specified locations. + * @returns {Promise} The stocked quantity of the item. * * @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, + * const stockedQuantity = + * await inventoryModuleService.retrieveStockedQuantity( + * "iitem_123", + * ["loc_123", "loc_321"] * ) - * - * // do something with the quantity or return it - * } */ retrieveStockedQuantity( inventoryItemId: string, @@ -945,31 +1026,19 @@ export interface IInventoryServiceNext extends IModuleService { ): Promise /** - * This method is used to retrieve the reserved quantity of an inventory item within the specified locations. + * This method retrieves the reserved quantity of an inventory item in the specified location. * - * @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 {string} inventoryItemId - The inventory item's ID. + * @param {string[]} locationIds - The locations' IDs. * @param {Context} context - A context used to share resources, such as transaction manager, between the application and the module. - * @returns {Promise} The reserved quantity of the inventory item in the specified locations. + * @returns {Promise} The reserved quantity of the item. * * @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, + * const reservedQuantity = + * await inventoryModuleService.retrieveReservedQuantity( + * "iitem_123", + * ["loc_123", "loc_321"] * ) - * - * // do something with the quantity or return it - * } */ retrieveReservedQuantity( inventoryItemId: string,