diff --git a/.changeset/long-carrots-tap.md b/.changeset/long-carrots-tap.md new file mode 100644 index 0000000000..fdd7286da4 --- /dev/null +++ b/.changeset/long-carrots-tap.md @@ -0,0 +1,5 @@ +--- +"@medusajs/types": patch +--- + +fix(types): Fix types used in the IInventoryService diff --git a/packages/types/src/inventory/common.ts b/packages/types/src/inventory/common.ts index af8f54b588..a53689d314 100644 --- a/packages/types/src/inventory/common.ts +++ b/packages/types/src/inventory/common.ts @@ -202,8 +202,27 @@ export type InventoryLevelDTO = { deleted_at: string | Date | null } +/** + * @interface + * + * The filters to apply on retrieved reservation items. + * + * @prop id - The IDs to filter reservation items by. + * @prop line_item_id - Filter reservation items by the ID of their associated line item. + * @prop inventory_item_id - Filter reservation items by the ID of their associated inventory item. + * @prop location_id - Filter reservation items by the ID of their associated location. + * @prop description - Description filters to apply on the reservation items' `description` attribute. + * @prop created_by - The "created by" values to filter reservation items by. + * @prop quantity - Filters to apply on the reservation items' `quantity` attribute. + */ export type FilterableReservationItemProps = { id?: string | string[] + /** + * @ignore + * + * @privateRemark + * This property is not used. + */ type?: string | string[] line_item_id?: string | string[] inventory_item_id?: string | string[] @@ -213,6 +232,19 @@ export type FilterableReservationItemProps = { quantity?: number | NumericalComparisonOperator } +/** + * @interface + * + * The filters to apply on retrieved inventory items. + * + * @prop id - The IDs to filter inventory items by. + * @prop location_id - Filter inventory items by the ID of their associated location. + * @prop q - Search term to search inventory items' attributes. + * @prop sku - The SKUs to filter inventory items by. + * @prop origin_country - The origin country to filter inventory items by. + * @prop hs_code - The HS Codes to filter inventory items by. + * @prop requires_shipping - Filter inventory items by whether they require shipping. + */ export type FilterableInventoryItemProps = { id?: string | string[] location_id?: string | string[] @@ -223,6 +255,26 @@ export type FilterableInventoryItemProps = { requires_shipping?: boolean } +/** + * @interface + * + * The details of the inventory item to be created. + * + * @prop sku - The SKU of the inventory item. + * @prop origin_country - The origin country of the inventory item. + * @prop mid_code - The MID code of the inventory item. + * @prop material - The material of the inventory item. + * @prop weight - The weight of the inventory item. + * @prop length - The length of the inventory item. + * @prop height - The height of the inventory item. + * @prop width - The width of the inventory item. + * @prop title - The title of the inventory item. + * @prop description - The description of the inventory item. + * @prop thumbnail - The thumbnail of the inventory item. + * @prop metadata - Holds custom data in key-value pairs. + * @prop hs_code - The HS code of the inventory item. + * @prop requries_shipping - Whether the inventory item requires shipping. + */ export type CreateInventoryItemInput = { sku?: string | null origin_country?: string | null @@ -240,6 +292,20 @@ export type CreateInventoryItemInput = { requires_shipping?: boolean } +/** + * @interface + * + * The details of the reservation item to be created. + * + * @prop line_item_id - The ID of the associated line item. + * @prop inventory_item_id - The ID of the associated inventory item. + * @prop location_id - The ID of the associated location. + * @prop quantity - The reserved quantity. + * @prop description - The description of the reservation. + * @prop created_by - The user or system that created the reservation. Can be any form of identification string. + * @prop external_id - An ID associated with an external third-party system that the reservation item is connected to. + * @prop metadata - Holds custom data in key-value pairs. + */ export type CreateReservationItemInput = { line_item_id?: string inventory_item_id: string @@ -251,6 +317,17 @@ export type CreateReservationItemInput = { metadata?: Record | null } +/** + * @interface + * + * The filters to apply on retrieved inventory levels. + * + * @prop inventory_item_id - Filter inventory levels by the ID of their associated inventory item. + * @prop location_id - Filter inventory levels by the ID of their associated inventory location. + * @prop stocked_quantity - Filters to apply on inventory levels' `stocked_quantity` attribute. + * @prop reserved_quantity - Filters to apply on inventory levels' `reserved_quantity` attribute. + * @prop incoming_quantity - Filters to apply on inventory levels' `incoming_quantity` attribute. + */ export type FilterableInventoryLevelProps = { inventory_item_id?: string | string[] location_id?: string | string[] @@ -259,6 +336,17 @@ export type FilterableInventoryLevelProps = { incoming_quantity?: number | NumericalComparisonOperator } +/** + * @interface + * + * The details of the inventory level to be created. + * + * @prop inventory_item_id - The ID of the associated inventory item. + * @prop location_id - The ID of the associated location. + * @prop stocked_quantity - The stocked quantity of the associated inventory item in the associated location. + * @prop reserved_quantity - The reserved quantity of the associated inventory item in the associated location. + * @prop incoming_quantity - The incoming quantity of the associated inventory item in the associated location. + */ export type CreateInventoryLevelInput = { inventory_item_id: string location_id: string @@ -267,16 +355,42 @@ export type CreateInventoryLevelInput = { incoming_quantity?: number } +/** + * @interface + * + * The attributes to update in an inventory level. + * + * @prop stocked_quantity - The stocked quantity of the associated inventory item in the associated location. + * @prop incoming_quantity - The incoming quantity of the associated inventory item in the associated location. + */ export type UpdateInventoryLevelInput = { stocked_quantity?: number 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. + * + * @prop inventory_item_id - The ID of the associated inventory level. + * @prop location_id - The ID of the associated location. + */ export type BulkUpdateInventoryLevelInput = { inventory_item_id: string location_id: string } & UpdateInventoryLevelInput +/** + * @interface + * + * The attributes to update in a reservation item. + * + * @prop quantity - The reserved quantity. + * @prop location_id - The ID of the associated location. + * @prop description - The description of the reservation item. + * @prop metadata - Holds custom data in key-value pairs. + */ export type UpdateReservationItemInput = { quantity?: number location_id?: string diff --git a/packages/types/src/inventory/service.ts b/packages/types/src/inventory/service.ts index ed08d1970e..2d01f2864f 100644 --- a/packages/types/src/inventory/service.ts +++ b/packages/types/src/inventory/service.ts @@ -1,4 +1,5 @@ import { + BulkUpdateInventoryLevelInput, CreateInventoryItemInput, CreateInventoryLevelInput, CreateReservationItemInput, @@ -17,81 +18,595 @@ import { ModuleJoinerConfig } from "../modules-sdk" import { SharedContext } from "../shared-context" export interface IInventoryService { + /** + * @ignore + */ __joinerConfig(): ModuleJoinerConfig + + /** + * 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} 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 {SharedContext} 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 + * } + * ``` + */ listInventoryItems( selector: FilterableInventoryItemProps, config?: FindConfig, context?: SharedContext ): Promise<[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} 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 {SharedContext} 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: FilterableReservationItemProps, config?: FindConfig, context?: SharedContext ): Promise<[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} 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 {SharedContext} 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: FilterableInventoryLevelProps, config?: FindConfig, context?: SharedContext ): Promise<[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} 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 {SharedContext} context - A context used to share resources, such as transaction manager, between the application and the module. + * @returns {Promise} 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 + * } + * ``` + */ retrieveInventoryItem( inventoryItemId: string, config?: FindConfig, context?: SharedContext ): Promise + /** + * 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 {SharedContext} 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 + * ) + * + * // do something with the inventory level or return it + * } + */ retrieveInventoryLevel( inventoryItemId: string, locationId: string, context?: SharedContext ): Promise + /** + * This method is used to retrieve a reservation item by its ID. + * + * @param {string} reservationId - The ID of the reservation item. + * @param {SharedContext} 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" + * + * 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, context?: SharedContext ): Promise + /** + * This method is used to create a reservation item. + * + * @param {CreateReservationItemInput} input - The details of the reservation item to create. + * @param {SharedContext} context - A context used to share resources, such as transaction manager, between the application and the module. + * @returns {Promise} The created reservation item's details. + * + * @example + * import { + * initialize as initializeInventoryModule, + * } from "@medusajs/inventory" + * + * async function createReservationItem (item: { + * inventory_item_id: string, + * location_id: string, + * quantity: number + * }) { + * const inventoryModule = await initializeInventoryModule({}) + * + * const reservationItem = await inventoryModule.createReservationItems( + * item + * ) + * + * // do something with the reservation item or return them + * } + */ createReservationItem( input: CreateReservationItemInput, context?: SharedContext ): Promise - // TODO make it bulk + /** + * This method is used to create reservation items. + * + * @param {CreateReservationItemInput[]} input - The details of the reservation items to create. + * @param {SharedContext} context - A context used to share resources, such as transaction manager, between the application and the module. + * @returns { Promise} 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: CreateReservationItemInput[], context?: SharedContext ): Promise + /** + * This method is used to create an inventory item. + * + * @param {CreateInventoryItemInput} input - The details of the inventory item to create. + * @param {SharedContext} context - A context used to share resources, such as transaction manager, between the application and the module. + * @returns {Promise} The created inventory item's details. + * + * @example + * import { + * initialize as initializeInventoryModule, + * } from "@medusajs/inventory" + * + * async function createInventoryItem (item: { + * sku: string, + * requires_shipping: boolean + * }) { + * const inventoryModule = await initializeInventoryModule({}) + * + * const inventoryItem = await inventoryModule.createInventoryItem( + * item + * ) + * + * // do something with the inventory item or return it + * } + */ createInventoryItem( input: CreateInventoryItemInput, context?: SharedContext ): Promise + /** + * This method is used to create inventory items. + * + * @param {CreateInventoryItemInput[]} input - The details of the inventory items to create. + * @param {SharedContext} context - A context used to share resources, such as transaction manager, between the application and the module. + * @returns {Promise} 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 + * } + */ createInventoryItems( input: CreateInventoryItemInput[], context?: SharedContext ): Promise + /** + * This method is used to create inventory level. + * + * @param {CreateInventoryLevelInput} data - The details of the inventory level to create. + * @param {SharedContext} context - A context used to share resources, such as transaction manager, between the application and the module. + * @returns {Promise} The created inventory level's details. + * + * @example + * import { + * initialize as initializeInventoryModule, + * } from "@medusajs/inventory" + * + * async function createInventoryLevel (item: { + * inventory_item_id: string + * location_id: string + * stocked_quantity: number + * }) { + * const inventoryModule = await initializeInventoryModule({}) + * + * const inventoryLevel = await inventoryModule.createInventoryLevel( + * item + * ) + * + * // do something with the inventory level or return it + * } + */ createInventoryLevel( data: CreateInventoryLevelInput, context?: SharedContext ): Promise + /** + * This method is used to create inventory levels. + * + * @param {CreateInventoryLevelInput[]} data - The details of the inventory levels to create. + * @param {SharedContext} context - A context used to share resources, such as transaction manager, between the application and the module. + * @returns {Promise} 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: CreateInventoryLevelInput[], context?: SharedContext ): Promise + /** + * 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 {SharedContext} context - A context used to share resources, such as transaction manager, between the application and the module. + * @returns {Promise} 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: ({ - inventory_item_id: string - location_id: string - } & UpdateInventoryLevelInput)[], + updates: BulkUpdateInventoryLevelInput[], context?: SharedContext ): Promise + /** + * This method is used to update 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 inventory item. + * @param {string} locationId - The ID of the location. + * @param {UpdateInventoryLevelInput} update - The attributes to update in the location level. + * @param {SharedContext} context - A context used to share resources, such as transaction manager, between the application and the module. + * @returns {Promise} The updated inventory level's details. + * + * @example + * import { + * initialize as initializeInventoryModule, + * } from "@medusajs/inventory" + * + * async function updateInventoryLevel ( + * inventoryItemId: string, + * locationId: string, + * stockedQuantity: number + * ) { + * const inventoryModule = await initializeInventoryModule({}) + * + * const inventoryLevel = await inventoryModule.updateInventoryLevels( + * inventoryItemId, + * locationId, + * { + * stocked_quantity: stockedQuantity + * } + * ) + * + * // do something with the inventory level or return it + * } + */ updateInventoryLevel( inventoryItemId: string, locationId: string, @@ -99,55 +614,300 @@ export interface IInventoryService { context?: SharedContext ): Promise + /** + * This method is used to update an inventory item. + * + * @param {string} inventoryItemId - The ID of the inventory item. + * @param {Partial} input - The attributes to update in the inventory item. + * @param {SharedContext} 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. + * + * @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 + * } + */ updateInventoryItem( inventoryItemId: string, - input: CreateInventoryItemInput, + input: Partial, context?: SharedContext ): Promise + /** + * 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 {SharedContext} 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 + * } + */ updateReservationItem( reservationItemId: string, input: UpdateReservationItemInput, context?: SharedContext ): Promise + /** + * 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 {SharedContext} 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. + * + * @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?: SharedContext ): Promise + /** + * 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 {SharedContext} 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. + * + * @example + * import { + * initialize as initializeInventoryModule, + * } from "@medusajs/inventory" + * + * async function deleteReservationItems ( + * reservationItemIds: string[] + * ) { + * const inventoryModule = await initializeInventoryModule({}) + * + * await inventoryModule.deleteReservationItem( + * reservationItemIds + * ) + * } + */ deleteReservationItem( reservationItemId: string | string[], context?: SharedContext ): Promise - // TODO make it bulk + /** + * 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 {SharedContext} 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. + * + * @example + * import { + * initialize as initializeInventoryModule, + * } from "@medusajs/inventory" + * + * async function deleteInventoryItem ( + * inventoryItems: string[] + * ) { + * const inventoryModule = await initializeInventoryModule({}) + * + * await inventoryModule.deleteInventoryItem( + * inventoryItems + * ) + * } + */ deleteInventoryItem( inventoryItemId: string | string[], context?: SharedContext ): Promise + /** + * This method is used to restore an inventory item or multiple inventory items that were previously deleted using the {@link deleteInventoryItem} method. + * + * @param {string | string[]} inventoryItemId - The ID(s) of the inventory item(s) to restore. + * @param {SharedContext} 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. + * + * @example + * import { + * initialize as initializeInventoryModule, + * } from "@medusajs/inventory" + * + * async function restoreInventoryItem ( + * inventoryItems: string[] + * ) { + * const inventoryModule = await initializeInventoryModule({}) + * + * await inventoryModule.restoreInventoryItem( + * inventoryItems + * ) + * } + */ restoreInventoryItem( inventoryItemId: string | string[], context?: SharedContext ): Promise + /** + * 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 {SharedContext} 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. + * + * @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?: SharedContext ): Promise + /** + * 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 {SharedContext} 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. + * + * @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?: SharedContext ): 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. + * + * @param {string} inventoryItemId - The ID of the associated inventory item. + * @param {string} locationId - The ID of the associated location. + * @param {SharedContext} 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. + * + * @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( - inventoryLevelId: string, + inventoryItemId: string, locationId: string, context?: SharedContext ): Promise + /** + * 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 {SharedContext} context - A context used to share resources, such as transaction manager, between the application and the module. + * @returns {Promise} 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, @@ -155,6 +915,34 @@ export interface IInventoryService { context?: SharedContext ): Promise + /** + * 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 {SharedContext} 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. + * + * @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[], @@ -162,18 +950,99 @@ export interface IInventoryService { context?: SharedContext ): Promise + /** + * 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 {SharedContext} 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. + * + * @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?: SharedContext ): Promise + /** + * 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 {SharedContext} 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. + * + * @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?: SharedContext ): Promise + /** + * 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 {SharedContext} 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. + * + * @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[], diff --git a/packages/types/src/product/service.ts b/packages/types/src/product/service.ts index 418a462f79..14a67c4260 100644 --- a/packages/types/src/product/service.ts +++ b/packages/types/src/product/service.ts @@ -69,20 +69,17 @@ export interface IProductModuleService { * * ```ts * import { - * initialize as initializePricingModule, - * } from "@medusajs/pricing" + * initialize as initializeProductModule, + * } from "@medusajs/product" * - * async function retrievePriceSet (priceSetId: string) { - * const pricingService = await initializePricingModule() + * async function retrieveProduct (id: string) { + * const productModule = await initializeProductModule() * - * const priceSet = await pricingService.retrieve( - * priceSetId, - * { - * relations: ["money_amounts"] - * } - * ) + * const product = await productModule.retrieve(id, { + * relations: ["categories"] + * }) * - * // do something with the price set or return it + * // do something with the product or return it * } * ``` */