chore(core-flows,types): improve TSDocs of inventory-related workflows (#11013)

This commit is contained in:
Shahed Nasser
2025-01-17 11:07:12 +02:00
committed by GitHub
parent 6b6026487d
commit c09d7e5ba8
45 changed files with 764 additions and 56 deletions
@@ -3,14 +3,30 @@ import { StepResponse, createStep } from "@medusajs/framework/workflows-sdk"
import { MathBN, Modules } from "@medusajs/framework/utils" import { MathBN, Modules } from "@medusajs/framework/utils"
/**
* The data to adjust the inventory levels.
*/
export type AdjustInventoryLevelsStepInput = InventoryTypes.BulkAdjustInventoryLevelInput[]
export const adjustInventoryLevelsStepId = "adjust-inventory-levels-step" export const adjustInventoryLevelsStepId = "adjust-inventory-levels-step"
/** /**
* This step adjusts one or more inventory levels. * This step adjusts the stocked quantity of one or more inventory levels. You can
* pass a positive value in `adjustment` to add to the stocked quantity, or a negative value to
* subtract from the stocked quantity.
*
* @example
* const data = adjustInventoryLevelsStep([
* {
* inventory_item_id: "iitem_123",
* location_id: "sloc_123",
* adjustment: 10,
* }
* ])
*/ */
export const adjustInventoryLevelsStep = createStep( export const adjustInventoryLevelsStep = createStep(
adjustInventoryLevelsStepId, adjustInventoryLevelsStepId,
async ( async (
input: InventoryTypes.BulkAdjustInventoryLevelInput[], input: AdjustInventoryLevelsStepInput,
{ container } { container }
) => { ) => {
const inventoryService: IInventoryService = container.resolve( const inventoryService: IInventoryService = container.resolve(
@@ -2,18 +2,37 @@ import { createStep, StepResponse } from "@medusajs/framework/workflows-sdk"
import { ContainerRegistrationKeys, Modules } from "@medusajs/framework/utils" import { ContainerRegistrationKeys, Modules } from "@medusajs/framework/utils"
/**
* The data to attach inventory items to variants.
*/
export type AttachInventoryItemToVariantsStepInput = {
/**
* The inventory item ID to attach to the variant.
*/
inventoryItemId: string
/**
* The variant ID to attach the inventory item to.
*/
tag: string
}[]
export const attachInventoryItemToVariantsStepId = export const attachInventoryItemToVariantsStepId =
"attach-inventory-items-to-variants-step" "attach-inventory-items-to-variants-step"
/** /**
* This step creates one or more links between variant and inventory item records. * This step creates one or more links between variant and inventory item records.
*
* @example
* const data = attachInventoryItemToVariants([
* {
* inventoryItemId: "iitem_123",
* tag: "variant_123"
* }
* ])
*/ */
export const attachInventoryItemToVariants = createStep( export const attachInventoryItemToVariants = createStep(
attachInventoryItemToVariantsStepId, attachInventoryItemToVariantsStepId,
async ( async (
input: { input: AttachInventoryItemToVariantsStepInput,
inventoryItemId: string
tag?: string
}[],
{ container } { container }
) => { ) => {
const remoteLink = container.resolve(ContainerRegistrationKeys.LINK) const remoteLink = container.resolve(ContainerRegistrationKeys.LINK)
@@ -3,13 +3,18 @@ import { StepResponse, createStep } from "@medusajs/framework/workflows-sdk"
import { IInventoryService, InventoryTypes } from "@medusajs/framework/types" import { IInventoryService, InventoryTypes } from "@medusajs/framework/types"
import { Modules } from "@medusajs/framework/utils" import { Modules } from "@medusajs/framework/utils"
/**
* The data to create the inventory items.
*/
export type CreateInventoryItemsStepInput = InventoryTypes.CreateInventoryItemInput[]
export const createInventoryItemsStepId = "create-inventory-items" export const createInventoryItemsStepId = "create-inventory-items"
/** /**
* This step creates one or more inventory items. * This step creates one or more inventory items.
*/ */
export const createInventoryItemsStep = createStep( export const createInventoryItemsStep = createStep(
createInventoryItemsStepId, createInventoryItemsStepId,
async (data: InventoryTypes.CreateInventoryItemInput[], { container }) => { async (data: CreateInventoryItemsStepInput, { container }) => {
const inventoryService: IInventoryService = container.resolve( const inventoryService: IInventoryService = container.resolve(
Modules.INVENTORY Modules.INVENTORY
) )
@@ -3,13 +3,18 @@ import { StepResponse, createStep } from "@medusajs/framework/workflows-sdk"
import { Modules } from "@medusajs/framework/utils" import { Modules } from "@medusajs/framework/utils"
/**
* The data to create the inventory levels.
*/
export type CreateInventoryLevelsStepInput = InventoryTypes.CreateInventoryLevelInput[]
export const createInventoryLevelsStepId = "create-inventory-levels" export const createInventoryLevelsStepId = "create-inventory-levels"
/** /**
* This step creates one or more inventory levels. * This step creates one or more inventory levels.
*/ */
export const createInventoryLevelsStep = createStep( export const createInventoryLevelsStep = createStep(
createInventoryLevelsStepId, createInventoryLevelsStepId,
async (data: InventoryTypes.CreateInventoryLevelInput[], { container }) => { async (data: CreateInventoryLevelsStepInput, { container }) => {
const service = container.resolve<IInventoryService>(Modules.INVENTORY) const service = container.resolve<IInventoryService>(Modules.INVENTORY)
const inventoryLevels = await service.createInventoryLevels(data) const inventoryLevels = await service.createInventoryLevels(data)
return new StepResponse( return new StepResponse(
@@ -26,13 +26,18 @@ export const validateInventoryDeleteStep = createStep(
} }
) )
/**
* The IDs of the inventory items to delete.
*/
export type DeleteInventoryItemStepInput = string[]
export const deleteInventoryItemStepId = "delete-inventory-item-step" export const deleteInventoryItemStepId = "delete-inventory-item-step"
/** /**
* This step deletes one or more inventory items. * This step deletes one or more inventory items.
*/ */
export const deleteInventoryItemStep = createStep( export const deleteInventoryItemStep = createStep(
deleteInventoryItemStepId, deleteInventoryItemStepId,
async (ids: string[], { container }) => { async (ids: DeleteInventoryItemStepInput, { container }) => {
const inventoryService = container.resolve(Modules.INVENTORY) const inventoryService = container.resolve(Modules.INVENTORY)
await inventoryService.softDeleteInventoryItems(ids) await inventoryService.softDeleteInventoryItems(ids)
@@ -3,13 +3,18 @@ import { StepResponse, createStep } from "@medusajs/framework/workflows-sdk"
import { Modules } from "@medusajs/framework/utils" import { Modules } from "@medusajs/framework/utils"
/**
* The IDs of inventory levels to delete.
*/
export type DeleteInventoryLevelsStepInput = string[]
export const deleteInventoryLevelsStepId = "delete-inventory-levels-step" export const deleteInventoryLevelsStepId = "delete-inventory-levels-step"
/** /**
* This step deletes one or more inventory levels. * This step deletes one or more inventory levels.
*/ */
export const deleteInventoryLevelsStep = createStep( export const deleteInventoryLevelsStep = createStep(
deleteInventoryLevelsStepId, deleteInventoryLevelsStepId,
async (ids: string[], { container }) => { async (ids: DeleteInventoryLevelsStepInput, { container }) => {
const service = container.resolve<IInventoryService>(Modules.INVENTORY) const service = container.resolve<IInventoryService>(Modules.INVENTORY)
await service.softDeleteInventoryLevels(ids) await service.softDeleteInventoryLevels(ids)
@@ -7,13 +7,18 @@ import { StepResponse, createStep } from "@medusajs/framework/workflows-sdk"
import { Modules } from "@medusajs/framework/utils" import { Modules } from "@medusajs/framework/utils"
/**
* The data to update the inventory items.
*/
export type UpdateInventoryItemsStepInput = InventoryTypes.UpdateInventoryItemInput[]
export const updateInventoryItemsStepId = "update-inventory-items-step" export const updateInventoryItemsStepId = "update-inventory-items-step"
/** /**
* This step updates one or more inventory items. * This step updates one or more inventory items.
*/ */
export const updateInventoryItemsStep = createStep( export const updateInventoryItemsStep = createStep(
updateInventoryItemsStepId, updateInventoryItemsStepId,
async (input: InventoryTypes.UpdateInventoryItemInput[], { container }) => { async (input: UpdateInventoryItemsStepInput, { container }) => {
const inventoryService = container.resolve<IInventoryService>( const inventoryService = container.resolve<IInventoryService>(
Modules.INVENTORY Modules.INVENTORY
) )
@@ -7,13 +7,18 @@ import { StepResponse, createStep } from "@medusajs/framework/workflows-sdk"
import { Modules } from "@medusajs/framework/utils" import { Modules } from "@medusajs/framework/utils"
/**
* The data to update the inventory levels.
*/
export type UpdateInventoryLevelsStepInput = InventoryTypes.UpdateInventoryLevelInput[]
export const updateInventoryLevelsStepId = "update-inventory-levels-step" export const updateInventoryLevelsStepId = "update-inventory-levels-step"
/** /**
* This step updates one or more inventory levels. * This step updates one or more inventory levels.
*/ */
export const updateInventoryLevelsStep = createStep( export const updateInventoryLevelsStep = createStep(
updateInventoryLevelsStepId, updateInventoryLevelsStepId,
async (input: InventoryTypes.UpdateInventoryLevelInput[], { container }) => { async (input: UpdateInventoryLevelsStepInput, { container }) => {
const inventoryService: IInventoryService = container.resolve( const inventoryService: IInventoryService = container.resolve(
Modules.INVENTORY Modules.INVENTORY
) )
@@ -5,13 +5,19 @@ import {
} from "@medusajs/framework/utils" } from "@medusajs/framework/utils"
import { createStep } from "@medusajs/framework/workflows-sdk" import { createStep } from "@medusajs/framework/workflows-sdk"
/**
* The IDs of the inventory items to validate.
*/
export type ValidateInventoryItemsStepInput = string[]
export const validateInventoryItemsId = "validate-inventory-items-step" export const validateInventoryItemsId = "validate-inventory-items-step"
/** /**
* This step ensures that the inventory items with the specified IDs exist. * This step ensures that the inventory items with the specified IDs exist.
* If not valid, the step will throw an error.
*/ */
export const validateInventoryItems = createStep( export const validateInventoryItems = createStep(
validateInventoryItemsId, validateInventoryItemsId,
async (id: string[], { container }) => { async (id: ValidateInventoryItemsStepInput, { container }) => {
const remoteQuery = container.resolve( const remoteQuery = container.resolve(
ContainerRegistrationKeys.REMOTE_QUERY ContainerRegistrationKeys.REMOTE_QUERY
) )
@@ -7,13 +7,20 @@ import {
import { InventoryTypes } from "@medusajs/framework/types" import { InventoryTypes } from "@medusajs/framework/types"
import { createStep } from "@medusajs/framework/workflows-sdk" import { createStep } from "@medusajs/framework/workflows-sdk"
/**
* The data to validate the inventory levels.
*/
export type ValidateInventoryLocationsStepInput = InventoryTypes.CreateInventoryLevelInput[]
export const validateInventoryLocationsStepId = "validate-inventory-levels-step" export const validateInventoryLocationsStepId = "validate-inventory-levels-step"
/** /**
* This step ensures that the inventory levels exist for each specified pair of inventory item and location. * This step ensures that the inventory levels exist for each
* specified pair of inventory item and location. If not,
* the step will throw an error.
*/ */
export const validateInventoryLocationsStep = createStep( export const validateInventoryLocationsStep = createStep(
validateInventoryLocationsStepId, validateInventoryLocationsStepId,
async (data: InventoryTypes.CreateInventoryLevelInput[], { container }) => { async (data: ValidateInventoryLocationsStepInput, { container }) => {
const remoteQuery = container.resolve( const remoteQuery = container.resolve(
ContainerRegistrationKeys.REMOTE_QUERY ContainerRegistrationKeys.REMOTE_QUERY
) )
@@ -5,17 +5,33 @@ import {
} from "@medusajs/framework/utils" } from "@medusajs/framework/utils"
import { createStep, StepResponse } from "@medusajs/framework/workflows-sdk" import { createStep, StepResponse } from "@medusajs/framework/workflows-sdk"
/**
* The data to validate inventory items for creation.
*/
export type ValidateInventoryItemsForCreateStepInput = {
/**
* The ID of the variant to validate.
*/
tag?: string
}[]
export const validateInventoryItemsForCreateStepId = export const validateInventoryItemsForCreateStepId =
"validate-inventory-items-for-create-step" "validate-inventory-items-for-create-step"
/** /**
* This step checks whether a variant already has an inventory item. * This step checks whether a variant already has an inventory item.
* If so, the step will throw an error.
*
* @example
* const data = validateInventoryItemsForCreate([
* {
* tag: "variant_123"
* }
* ])
*/ */
export const validateInventoryItemsForCreate = createStep( export const validateInventoryItemsForCreate = createStep(
validateInventoryItemsForCreateStepId, validateInventoryItemsForCreateStepId,
async ( async (
input: { input: ValidateInventoryItemsForCreateStepInput,
tag?: string
}[],
{ container } { container }
) => { ) => {
const remoteLink = container.resolve(ContainerRegistrationKeys.LINK) const remoteLink = container.resolve(ContainerRegistrationKeys.LINK)
@@ -5,18 +5,25 @@ import {
WorkflowData, WorkflowData,
WorkflowResponse, WorkflowResponse,
} from "@medusajs/framework/workflows-sdk" } from "@medusajs/framework/workflows-sdk"
import { BatchWorkflowInput, InventoryTypes } from "@medusajs/types" import { BatchWorkflowInput, BatchWorkflowOutput, InventoryLevelDTO, InventoryTypes } from "@medusajs/types"
import { createInventoryLevelsStep, updateInventoryLevelsStep } from "../steps" import { createInventoryLevelsStep, updateInventoryLevelsStep } from "../steps"
import { deleteInventoryLevelsWorkflow } from "./delete-inventory-levels" import { deleteInventoryLevelsWorkflow } from "./delete-inventory-levels"
/**
* The data to manage the inventory levels in bulk.
*
* @property create - The inventory levels to create.
* @property update - The inventory levels to update.
* @property delete - The IDs of inventory levels to delete.
*/
export interface BatchInventoryItemLevelsWorkflowInput export interface BatchInventoryItemLevelsWorkflowInput
extends BatchWorkflowInput< extends BatchWorkflowInput<
InventoryTypes.CreateInventoryLevelInput, InventoryTypes.CreateInventoryLevelInput,
InventoryTypes.UpdateInventoryLevelInput InventoryTypes.UpdateInventoryLevelInput
> { > {
/** /**
* If true, the workflow will force deletion of the inventory levels, even * If true, the workflow will force the deletion of the inventory levels, even
* if they have a non-zero stocked quantity. It false, the workflow will * if they have a non-zero stocked quantity. If false, the workflow will
* not delete the inventory levels if they have a non-zero stocked quantity. * not delete the inventory levels if they have a non-zero stocked quantity.
* *
* Inventory levels that have reserved or incoming items at the location * Inventory levels that have reserved or incoming items at the location
@@ -27,9 +34,50 @@ export interface BatchInventoryItemLevelsWorkflowInput
force?: boolean force?: boolean
} }
/**
* The result of managing inventory levels in bulk.
*
* @property created - The inventory levels that were created.
* @property updated - The inventory levels that were updated.
* @property deleted - The IDs of the inventory levels that were deleted.
*/
export type BatchInventoryItemLevelsWorkflowOutput = BatchWorkflowOutput<InventoryLevelDTO>
export const batchInventoryItemLevelsWorkflowId = export const batchInventoryItemLevelsWorkflowId =
"batch-inventory-item-levels-workflow" "batch-inventory-item-levels-workflow"
/**
* This workflow creates, updates and deletes inventory levels in bulk.
*
* You can use this workflow within your own customizations or custom workflows, allowing you
* to manage inventory levels in your custom flows.
*
* @example
* const { result } = await batchInventoryItemLevelsWorkflow(container)
* .run({
* input: {
* create: [
* {
* inventory_item_id: "iitem_123",
* location_id: "sloc_123"
* }
* ],
* update: [
* {
* id: "iilev_123",
* inventory_item_id: "iitem_123",
* location_id: "sloc_123",
* stocked_quantity: 10
* }
* ],
* delete: ["iilev_321"]
* }
* })
*
* @summary
*
* Manage inventory levels in bulk.
*/
export const batchInventoryItemLevelsWorkflow = createWorkflow( export const batchInventoryItemLevelsWorkflow = createWorkflow(
batchInventoryItemLevelsWorkflowId, batchInventoryItemLevelsWorkflowId,
(input: WorkflowData<BatchInventoryItemLevelsWorkflowInput>) => { (input: WorkflowData<BatchInventoryItemLevelsWorkflowInput>) => {
@@ -61,7 +109,7 @@ export const batchInventoryItemLevelsWorkflow = createWorkflow(
created: data.res[0], created: data.res[0],
updated: data.res[1], updated: data.res[1],
deleted: data.input.delete, deleted: data.input.delete,
} } as BatchInventoryItemLevelsWorkflowOutput
}) })
) )
} }
@@ -9,12 +9,24 @@ import { createInventoryItemsStep } from "../steps"
import { InventoryTypes } from "@medusajs/framework/types" import { InventoryTypes } from "@medusajs/framework/types"
import { createInventoryLevelsWorkflow } from "./create-inventory-levels" import { createInventoryLevelsWorkflow } from "./create-inventory-levels"
/**
* The inventory level to create.
*/
type LocationLevelWithoutInventory = Omit< type LocationLevelWithoutInventory = Omit<
InventoryTypes.CreateInventoryLevelInput, InventoryTypes.CreateInventoryLevelInput,
"inventory_item_id" "inventory_item_id"
> >
/**
* The data to create the inventory items.
*/
export interface CreateInventoryItemsWorkflowInput { export interface CreateInventoryItemsWorkflowInput {
/**
* The items to create.
*/
items: (InventoryTypes.CreateInventoryItemInput & { items: (InventoryTypes.CreateInventoryItemInput & {
/**
* The inventory levels of the inventory item.
*/
location_levels?: LocationLevelWithoutInventory[] location_levels?: LocationLevelWithoutInventory[]
})[] })[]
} }
@@ -68,7 +80,32 @@ const buildInventoryLevelsInput = (data: {
export const createInventoryItemsWorkflowId = "create-inventory-items-workflow" export const createInventoryItemsWorkflowId = "create-inventory-items-workflow"
/** /**
* This workflow creates one or more inventory items. * This workflow creates one or more inventory items. It's used by the
* [Create Inventory Item Admin API Route](https://docs.medusajs.com/api/admin#inventory-items_postinventoryitems).
*
* You can use this workflow within your own customizations or custom workflows, allowing you
* to create inventory items in your custom flows.
*
* @example
* const { result } = await createInventoryItemsWorkflow(container)
* .run({
* input: {
* items: [
* {
* sku: "shirt",
* location_levels: [
* {
* location_id: "sloc_123",
* }
* ]
* }
* ]
* }
* })
*
* @summary
*
* Create one or more inventory items.
*/ */
export const createInventoryItemsWorkflow = createWorkflow( export const createInventoryItemsWorkflow = createWorkflow(
createInventoryItemsWorkflowId, createInventoryItemsWorkflowId,
@@ -9,13 +9,40 @@ import {
validateInventoryLocationsStep, validateInventoryLocationsStep,
} from "../steps" } from "../steps"
/**
* The data to create the inventory levels.
*/
export interface CreateInventoryLevelsWorkflowInput { export interface CreateInventoryLevelsWorkflowInput {
/**
* The inventory levels to create.
*/
inventory_levels: InventoryTypes.CreateInventoryLevelInput[] inventory_levels: InventoryTypes.CreateInventoryLevelInput[]
} }
export const createInventoryLevelsWorkflowId = export const createInventoryLevelsWorkflowId =
"create-inventory-levels-workflow" "create-inventory-levels-workflow"
/** /**
* This workflow creates one or more inventory levels. * This workflow creates one or more inventory levels. It's used by the
* [Create Inventory Level API Route](https://docs.medusajs.com/api/admin#inventory-items_postinventoryitemsidlocationlevels).
*
* You can use this workflow within your own customizations or custom workflows, allowing you
* to create inventory levels in your custom flows.
*
* @example
* const { result } = await createInventoryLevelsWorkflow(container)
* .run({
* input: {
* inventory_levels: [
* {
* inventory_item_id: "iitem_123",
* location_id: "sloc_123",
* }
* ]
* }
* })
*
* @summary
*
* Create one or more inventory levels.
*/ */
export const createInventoryLevelsWorkflow = createWorkflow( export const createInventoryLevelsWorkflow = createWorkflow(
createInventoryLevelsWorkflowId, createInventoryLevelsWorkflowId,
@@ -9,13 +9,39 @@ import { deleteInventoryItemStep, validateInventoryDeleteStep } from "../steps"
import { removeRemoteLinkStep } from "../../common/steps/remove-remote-links" import { removeRemoteLinkStep } from "../../common/steps/remove-remote-links"
import { useQueryGraphStep } from "../../common" import { useQueryGraphStep } from "../../common"
/**
* The IDs of the inventory items to delete.
*/
export type DeleteInventoryItemWorkflowInput = string[]
/**
* The IDs of deleted inventory items.
*/
export type DeleteInventoryItemWorkflowOutput = string[]
export const deleteInventoryItemWorkflowId = "delete-inventory-item-workflow" export const deleteInventoryItemWorkflowId = "delete-inventory-item-workflow"
/** /**
* This workflow deletes one or more inventory items. * This workflow deletes one or more inventory items. It's used by the
* [Delete Inventory Item Admin API Route](https://docs.medusajs.com/api/admin#inventory-items_deleteinventoryitemsid).
*
* You can use this workflow within your own customizations or custom workflows, allowing you
* to delete inventory items in your custom flows.
*
* @example
* const { result } = await deleteInventoryItemWorkflow(container)
* .run({
* input: ["iitem_123"]
* })
*
* @summary
*
* Delete one or more inventory items.
*/ */
export const deleteInventoryItemWorkflow = createWorkflow( export const deleteInventoryItemWorkflow = createWorkflow(
deleteInventoryItemWorkflowId, deleteInventoryItemWorkflowId,
(input: WorkflowData<string[]>): WorkflowResponse<string[]> => { (input: WorkflowData<DeleteInventoryItemWorkflowInput>): WorkflowResponse<
DeleteInventoryItemWorkflowOutput
> => {
const { data: inventoryItemsToDelete } = useQueryGraphStep({ const { data: inventoryItemsToDelete } = useQueryGraphStep({
entity: "inventory", entity: "inventory",
fields: ["id", "reserved_quantity"], fields: ["id", "reserved_quantity"],
@@ -15,17 +15,48 @@ import { useRemoteQueryStep } from "../../common"
import { deleteEntitiesStep } from "../../common/steps/delete-entities" import { deleteEntitiesStep } from "../../common/steps/delete-entities"
/** /**
* This step validates that inventory levels are deletable. * The data to validate the deletion of inventory levels.
*/
export type ValidateInventoryLevelsDeleteStepInput = {
/**
* The inventory levels to validate.
*/
inventoryLevels: InventoryLevelDTO[]
/**
* If true, the inventory levels will be deleted even if they have stocked items.
*/
force?: boolean
}
/**
* This step validates that inventory levels are deletable. If the
* inventory levels have reserved or incoming items, or the force
* flag is not set and the inventory levels have stocked items, the
* step will throw an error.
*
* :::note
*
* You can retrieve an inventory level's details using [Query](https://docs.medusajs.com/learn/fundamentals/module-links/query),
* or [useQueryGraphStep](https://docs.medusajs.com/resources/references/medusa-workflows/steps/useQueryGraphStep).
*
* :::
*
* @example
* const data = validateInventoryLevelsDelete({
* inventoryLevels: [
* {
* id: "iilev_123",
* // other inventory level details...
* }
* ]
* })
*/ */
export const validateInventoryLevelsDelete = createStep( export const validateInventoryLevelsDelete = createStep(
"validate-inventory-levels-delete", "validate-inventory-levels-delete",
async function ({ async function ({
inventoryLevels, inventoryLevels,
force, force,
}: { }: ValidateInventoryLevelsDeleteStepInput) {
inventoryLevels: InventoryLevelDTO[]
force?: boolean
}) {
const undeleteableDueToReservation = inventoryLevels.filter( const undeleteableDueToReservation = inventoryLevels.filter(
(i) => i.reserved_quantity > 0 || i.incoming_quantity > 0 (i) => i.reserved_quantity > 0 || i.incoming_quantity > 0
) )
@@ -60,15 +91,38 @@ export const validateInventoryLevelsDelete = createStep(
} }
) )
/**
* The data to delete inventory levels. The inventory levels to be deleted
* are selected based on the filters that you specify.
*/
export interface DeleteInventoryLevelsWorkflowInput export interface DeleteInventoryLevelsWorkflowInput
extends FilterableInventoryLevelProps { extends FilterableInventoryLevelProps {
/**
* If true, the inventory levels will be deleted even if they have stocked items.
*/
force?: boolean force?: boolean
} }
export const deleteInventoryLevelsWorkflowId = export const deleteInventoryLevelsWorkflowId =
"delete-inventory-levels-workflow" "delete-inventory-levels-workflow"
/** /**
* This workflow deletes one or more inventory levels. * This workflow deletes one or more inventory levels. It's used by the
* [Delete Inventory Levels Admin API Route](https://docs.medusajs.com/api/admin#inventory-items_deleteinventoryitemsidlocationlevelslocation_id).
*
* You can use this workflow within your own customizations or custom workflows, allowing you
* to delete inventory levels in your custom flows.
*
* @example
* const { result } = await deleteInventoryLevelsWorkflow(container)
* .run({
* input: {
* id: ["iilev_123", "iilev_321"],
* }
* })
*
* @summary
*
* Delete one or more inventory levels.
*/ */
export const deleteInventoryLevelsWorkflow = createWorkflow( export const deleteInventoryLevelsWorkflow = createWorkflow(
deleteInventoryLevelsWorkflowId, deleteInventoryLevelsWorkflowId,
@@ -7,18 +7,51 @@ import {
import { InventoryTypes } from "@medusajs/framework/types" import { InventoryTypes } from "@medusajs/framework/types"
import { updateInventoryItemsStep } from "../steps" import { updateInventoryItemsStep } from "../steps"
/**
* The data to update the inventory items.
*/
export interface UpdateInventoryItemsWorkflowInput { export interface UpdateInventoryItemsWorkflowInput {
/**
* The items to update.
*/
updates: InventoryTypes.UpdateInventoryItemInput[] updates: InventoryTypes.UpdateInventoryItemInput[]
} }
/**
* The updated inventory items.
*/
export type UpdateInventoryItemsWorkflowOutput = InventoryTypes.InventoryItemDTO[]
export const updateInventoryItemsWorkflowId = "update-inventory-items-workflow" export const updateInventoryItemsWorkflowId = "update-inventory-items-workflow"
/** /**
* This workflow updates one or more inventory items. * This workflow updates one or more inventory items. It's used by the
* [Update an Inventory Item Admin API Route](https://docs.medusajs.com/api/admin#inventory-items_postinventoryitemsid).
*
* You can use this workflow within your own customizations or custom workflows, allowing you
* to update inventory items in your custom flows.
*
* @example
* const { result } = await updateInventoryItemsWorkflow(container)
* .run({
* input: {
* updates: [
* {
* id: "iitem_123",
* sku: "shirt",
* }
* ]
* }
* })
*
* @summary
*
* Update one or more inventory items.
*/ */
export const updateInventoryItemsWorkflow = createWorkflow( export const updateInventoryItemsWorkflow = createWorkflow(
updateInventoryItemsWorkflowId, updateInventoryItemsWorkflowId,
( (
input: WorkflowData<UpdateInventoryItemsWorkflowInput> input: WorkflowData<UpdateInventoryItemsWorkflowInput>
): WorkflowResponse<InventoryTypes.InventoryItemDTO[]> => { ): WorkflowResponse<UpdateInventoryItemsWorkflowOutput> => {
return new WorkflowResponse(updateInventoryItemsStep(input.updates)) return new WorkflowResponse(updateInventoryItemsStep(input.updates))
} }
) )
@@ -7,19 +7,54 @@ import {
import { updateInventoryLevelsStep } from "../steps/update-inventory-levels" import { updateInventoryLevelsStep } from "../steps/update-inventory-levels"
/**
* The data to update the inventory levels.
*/
export interface UpdateInventoryLevelsWorkflowInput { export interface UpdateInventoryLevelsWorkflowInput {
/**
* The inventory levels to update.
*/
updates: InventoryTypes.UpdateInventoryLevelInput[] updates: InventoryTypes.UpdateInventoryLevelInput[]
} }
/**
* The updated inventory levels.
*/
export type UpdateInventoryLevelsWorkflowOutput = InventoryLevelDTO[]
export const updateInventoryLevelsWorkflowId = export const updateInventoryLevelsWorkflowId =
"update-inventory-levels-workflow" "update-inventory-levels-workflow"
/** /**
* This workflow updates one or more inventory levels. * This workflow updates one or more inventory levels. It's used by the
* [Update Inventory Level Admin API Route](https://docs.medusajs.com/api/admin#inventory-items_postinventoryitemsidlocationlevelslocation_id).
*
* You can use this workflow within your own customizations or custom workflows, allowing you
* to update inventory levels in your custom flows.
*
* @example
* const { result } = await updateInventoryLevelsWorkflow(container)
* .run({
* input: {
* updates: [
* {
* id: "iilev_123",
* inventory_item_id: "iitem_123",
* location_id: "sloc_123",
* stocked_quantity: 10,
* }
* ]
* }
* })
*
* @summary
*
* Update one or more inventory levels.
*/ */
export const updateInventoryLevelsWorkflow = createWorkflow( export const updateInventoryLevelsWorkflow = createWorkflow(
updateInventoryLevelsWorkflowId, updateInventoryLevelsWorkflowId,
( (
input: WorkflowData<UpdateInventoryLevelsWorkflowInput> input: WorkflowData<UpdateInventoryLevelsWorkflowInput>
): WorkflowResponse<InventoryLevelDTO[]> => { ): WorkflowResponse<UpdateInventoryLevelsWorkflowOutput> => {
return new WorkflowResponse(updateInventoryLevelsStep(input.updates)) return new WorkflowResponse(updateInventoryLevelsStep(input.updates))
} }
) )
@@ -21,7 +21,8 @@ export type CreateRefundReasonsWorkflowInput = {
export const createRefundReasonsWorkflowId = "create-refund-reasons-workflow" export const createRefundReasonsWorkflowId = "create-refund-reasons-workflow"
/** /**
* This workflow creates one or more refund reasons. * This workflow creates one or more refund reasons. It's used by the
* [Create Refund Reason Admin API Route](https://docs.medusajs.com/api/admin#refund-reasons_postrefundreasons).
* *
* You can use this workflow within your own customizations or custom workflows, allowing you * You can use this workflow within your own customizations or custom workflows, allowing you
* to create refund reasons in your custom flows. * to create refund reasons in your custom flows.
@@ -5,13 +5,39 @@ import {
} from "@medusajs/framework/workflows-sdk" } from "@medusajs/framework/workflows-sdk"
import { deleteRefundReasonsStep } from "../steps" import { deleteRefundReasonsStep } from "../steps"
/**
* The data to delete refund reasons.
*/
export type DeleteRefundReasonsWorkflowInput = {
/**
* The refund reasons to delete.
*/
ids: string[]
}
export const deleteRefundReasonsWorkflowId = "delete-refund-reasons-workflow" export const deleteRefundReasonsWorkflowId = "delete-refund-reasons-workflow"
/** /**
* This workflow deletes one or more refund reasons. * This workflow deletes one or more refund reasons. It's used by the
* [Delete Refund Reason Admin API Route](https://docs.medusajs.com/api/admin#refund-reasons_deleterefundreasonsid).
*
* You can use this workflow within your own customizations or custom workflows, allowing you
* to delete refund reasons in your custom flows.
*
* @example
* const { result } = await deleteRefundReasonsWorkflow(container)
* .run({
* input: {
* ids: ["refres_123"]
* }
* })
*
* @summary
*
* Delete refund reasons.
*/ */
export const deleteRefundReasonsWorkflow = createWorkflow( export const deleteRefundReasonsWorkflow = createWorkflow(
deleteRefundReasonsWorkflowId, deleteRefundReasonsWorkflowId,
(input: WorkflowData<{ ids: string[] }>): WorkflowResponse<void> => { (input: WorkflowData<DeleteRefundReasonsWorkflowInput>): WorkflowResponse<void> => {
return new WorkflowResponse(deleteRefundReasonsStep(input.ids)) return new WorkflowResponse(deleteRefundReasonsStep(input.ids))
} }
) )
@@ -21,7 +21,8 @@ export type UpdateRefundReasonsWorkflowOutput = RefundReasonDTO[]
export const updateRefundReasonsWorkflowId = "update-refund-reasons" export const updateRefundReasonsWorkflowId = "update-refund-reasons"
/** /**
* This workflow updates one or more refund reasons. * This workflow updates one or more refund reasons. It's used by the
* [Update Refund Reason Admin API Route](https://docs.medusajs.com/api/admin#refund-reasons_postrefundreasonsid).
* *
* You can use this workflow within your own customizations or custom workflows, allowing you * You can use this workflow within your own customizations or custom workflows, allowing you
* to update refund reasons in your custom flows. * to update refund reasons in your custom flows.
@@ -3,13 +3,27 @@ import { createStep, StepResponse } from "@medusajs/framework/workflows-sdk"
import { Modules } from "@medusajs/framework/utils" import { Modules } from "@medusajs/framework/utils"
/**
* The data to create reservation items.
*/
export type CreateReservationsStepInput = InventoryTypes.CreateReservationItemInput[]
export const createReservationsStepId = "create-reservations-step" export const createReservationsStepId = "create-reservations-step"
/** /**
* This step creates one or more reservations. * This step creates one or more reservations.
*
* @example
* const data = createReservationsStep([
* {
* inventory_item_id: "iitem_123",
* location_id: "sloc_123",
* quantity: 1,
* }
* ])
*/ */
export const createReservationsStep = createStep( export const createReservationsStep = createStep(
createReservationsStepId, createReservationsStepId,
async (data: InventoryTypes.CreateReservationItemInput[], { container }) => { async (data: CreateReservationsStepInput, { container }) => {
const service = container.resolve(Modules.INVENTORY) const service = container.resolve(Modules.INVENTORY)
const locking = container.resolve(Modules.LOCKING) const locking = container.resolve(Modules.LOCKING)
@@ -3,6 +3,11 @@ import { StepResponse, createStep } from "@medusajs/framework/workflows-sdk"
import { IInventoryService } from "@medusajs/framework/types" import { IInventoryService } from "@medusajs/framework/types"
import { Modules } from "@medusajs/framework/utils" import { Modules } from "@medusajs/framework/utils"
/**
* The IDs of the line items to delete reservations for.
*/
export type DeleteReservationsByLineItemsStepInput = string[]
export const deleteReservationsByLineItemsStepId = export const deleteReservationsByLineItemsStepId =
"delete-reservations-by-line-items" "delete-reservations-by-line-items"
/** /**
@@ -10,7 +15,7 @@ export const deleteReservationsByLineItemsStepId =
*/ */
export const deleteReservationsByLineItemsStep = createStep( export const deleteReservationsByLineItemsStep = createStep(
deleteReservationsByLineItemsStepId, deleteReservationsByLineItemsStepId,
async (ids: string[], { container }) => { async (ids: DeleteReservationsByLineItemsStepInput, { container }) => {
const service = container.resolve<IInventoryService>(Modules.INVENTORY) const service = container.resolve<IInventoryService>(Modules.INVENTORY)
await service.deleteReservationItemsByLineItem(ids) await service.deleteReservationItemsByLineItem(ids)
@@ -3,13 +3,18 @@ import { StepResponse, createStep } from "@medusajs/framework/workflows-sdk"
import { IInventoryService } from "@medusajs/framework/types" import { IInventoryService } from "@medusajs/framework/types"
import { Modules } from "@medusajs/framework/utils" import { Modules } from "@medusajs/framework/utils"
/**
* The IDs of the reservations to delete.
*/
export type DeleteReservationsStepInput = string[]
export const deleteReservationsStepId = "delete-reservations" export const deleteReservationsStepId = "delete-reservations"
/** /**
* This step deletes one or more reservations. * This step deletes one or more reservations.
*/ */
export const deleteReservationsStep = createStep( export const deleteReservationsStep = createStep(
deleteReservationsStepId, deleteReservationsStepId,
async (ids: string[], { container }) => { async (ids: DeleteReservationsStepInput, { container }) => {
const service = container.resolve<IInventoryService>(Modules.INVENTORY) const service = container.resolve<IInventoryService>(Modules.INVENTORY)
await service.softDeleteReservationItems(ids) await service.softDeleteReservationItems(ids)
@@ -7,13 +7,26 @@ import { StepResponse, createStep } from "@medusajs/framework/workflows-sdk"
import { Modules } from "@medusajs/framework/utils" import { Modules } from "@medusajs/framework/utils"
/**
* The data to update reservation items.
*/
export type UpdateReservationsStepInput = InventoryTypes.UpdateReservationItemInput[]
export const updateReservationsStepId = "update-reservations-step" export const updateReservationsStepId = "update-reservations-step"
/** /**
* This step updates one or more reservations. * This step updates one or more reservations.
*
* @example
* const data = updateReservationsStep([
* {
* id: "res_123",
* quantity: 1,
* }
* ])
*/ */
export const updateReservationsStep = createStep( export const updateReservationsStep = createStep(
updateReservationsStepId, updateReservationsStepId,
async (data: InventoryTypes.UpdateReservationItemInput[], { container }) => { async (data: UpdateReservationsStepInput, { container }) => {
const inventoryModuleService = container.resolve<IInventoryService>( const inventoryModuleService = container.resolve<IInventoryService>(
Modules.INVENTORY Modules.INVENTORY
) )
@@ -9,7 +9,29 @@ import { createReservationsStep } from "../steps"
export const createReservationsWorkflowId = "create-reservations-workflow" export const createReservationsWorkflowId = "create-reservations-workflow"
/** /**
* This workflow creates one or more reservations. * This workflow creates one or more reservations. It's used by the
* [Create Reservations Admin API Route](https://docs.medusajs.com/api/admin#reservations_postreservations).
*
* You can use this workflow within your own customizations or custom workflows, allowing you
* to create reservations in your custom flows.
*
* @example
* const { result } = await createReservationsWorkflow(container)
* .run({
* input: {
* reservations: [
* {
* inventory_item_id: "iitem_123",
* location_id: "sloc_123",
* quantity: 1,
* }
* ]
* }
* })
*
* @summary
*
* Create one or more reservations.
*/ */
export const createReservationsWorkflow = createWorkflow( export const createReservationsWorkflow = createWorkflow(
createReservationsWorkflowId, createReservationsWorkflowId,
@@ -2,11 +2,35 @@ import { WorkflowData, createWorkflow } from "@medusajs/framework/workflows-sdk"
import { deleteReservationsStep } from "../steps" import { deleteReservationsStep } from "../steps"
type WorkflowInput = { ids: string[] } /**
* The data to delete the reservations.
*/
type WorkflowInput = {
/**
* The IDs of the reservations to delete.
*/
ids: string[]
}
export const deleteReservationsWorkflowId = "delete-reservations" export const deleteReservationsWorkflowId = "delete-reservations"
/** /**
* This workflow deletes one or more reservations. * This workflow deletes one or more reservations. It's used by the
* [Delete Reservations Admin API Route](https://docs.medusajs.com/api/admin#reservations_deletereservationsid).
*
* You can use this workflow within your own customizations or custom workflows, allowing you
* to delete reservations in your custom flows.
*
* @example
* const { result } = await deleteReservationsWorkflow(container)
* .run({
* input: {
* ids: ["res_123"]
* }
* })
*
* @summary
*
* Delete one or more reservations.
*/ */
export const deleteReservationsWorkflow = createWorkflow( export const deleteReservationsWorkflow = createWorkflow(
deleteReservationsWorkflowId, deleteReservationsWorkflowId,
@@ -9,7 +9,28 @@ import { updateReservationsStep } from "../steps"
export const updateReservationsWorkflowId = "update-reservations-workflow" export const updateReservationsWorkflowId = "update-reservations-workflow"
/** /**
* This workflow updates one or more reservations. * This workflow updates one or more reservations. It's used by the
* [Update Reservations Admin API Route](https://docs.medusajs.com/api/admin#reservations_postreservationsid).
*
* You can use this workflow within your own customizations or custom workflows, allowing you
* to update reservations in your custom flows.
*
* @example
* const { result } = await updateReservationsWorkflow(container)
* .run({
* input: {
* updates: [
* {
* id: "res_123",
* quantity: 1,
* }
* ]
* }
* })
*
* @summary
*
* Update one or more reservations.
*/ */
export const updateReservationsWorkflow = createWorkflow( export const updateReservationsWorkflow = createWorkflow(
updateReservationsWorkflowId, updateReservationsWorkflowId,
@@ -1,9 +1,21 @@
import { ContainerRegistrationKeys, Modules } from "@medusajs/framework/utils" import { ContainerRegistrationKeys, Modules } from "@medusajs/framework/utils"
import { createStep, StepResponse } from "@medusajs/framework/workflows-sdk" import { createStep, StepResponse } from "@medusajs/framework/workflows-sdk"
/**
* The data to associate fulfillment sets with locations.
*/
export interface AssociateFulfillmentSetsWithLocationStepInput { export interface AssociateFulfillmentSetsWithLocationStepInput {
/**
* The data to associate fulfillment sets with locations.
*/
input: { input: {
/**
* The ID of the location to associate the fulfillment sets with.
*/
location_id: string location_id: string
/**
* The IDs of the fulfillment sets to associate with the location.
*/
fulfillment_set_ids: string[] fulfillment_set_ids: string[]
}[] }[]
} }
@@ -6,13 +6,18 @@ import { StepResponse, createStep } from "@medusajs/framework/workflows-sdk"
import { Modules } from "@medusajs/framework/utils" import { Modules } from "@medusajs/framework/utils"
/**
* The stock locations to create.
*/
export type CreateStockLocationsStepInput = CreateStockLocationInput[]
export const createStockLocationsStepId = "create-stock-locations" export const createStockLocationsStepId = "create-stock-locations"
/** /**
* This step creates one or more stock locations. * This step creates one or more stock locations.
*/ */
export const createStockLocations = createStep( export const createStockLocations = createStep(
createStockLocationsStepId, createStockLocationsStepId,
async (data: CreateStockLocationInput[], { container }) => { async (data: CreateStockLocationsStepInput, { container }) => {
const stockLocationService = container.resolve<IStockLocationService>( const stockLocationService = container.resolve<IStockLocationService>(
Modules.STOCK_LOCATION Modules.STOCK_LOCATION
) )
@@ -2,13 +2,18 @@ import { DeleteEntityInput } from "@medusajs/framework/modules-sdk"
import { Modules } from "@medusajs/framework/utils" import { Modules } from "@medusajs/framework/utils"
import { StepResponse, createStep } from "@medusajs/framework/workflows-sdk" import { StepResponse, createStep } from "@medusajs/framework/workflows-sdk"
/**
* The IDs of stock locations to delete.
*/
export type DeleteStockLocationsStepInput = string[]
export const deleteStockLocationsStepId = "delete-stock-locations-step" export const deleteStockLocationsStepId = "delete-stock-locations-step"
/** /**
* This step deletes one or more stock locations. * This step deletes one or more stock locations.
*/ */
export const deleteStockLocationsStep = createStep( export const deleteStockLocationsStep = createStep(
deleteStockLocationsStepId, deleteStockLocationsStepId,
async (input: string[], { container }) => { async (input: DeleteStockLocationsStepInput, { container }) => {
const service = container.resolve(Modules.STOCK_LOCATION) const service = container.resolve(Modules.STOCK_LOCATION)
const softDeletedEntities = await service.softDeleteStockLocations(input) const softDeletedEntities = await service.softDeleteStockLocations(input)
@@ -8,14 +8,33 @@ import { StepResponse, createStep } from "@medusajs/framework/workflows-sdk"
import { Modules } from "@medusajs/framework/utils" import { Modules } from "@medusajs/framework/utils"
/**
* The data to update stock locations.
*/
interface StepInput { interface StepInput {
/**
* The filters to select stock locations to update.
*/
selector: FilterableStockLocationProps selector: FilterableStockLocationProps
/**
* The data to update stock locations with.
*/
update: UpdateStockLocationInput update: UpdateStockLocationInput
} }
export const updateStockLocationsStepId = "update-stock-locations-step" export const updateStockLocationsStepId = "update-stock-locations-step"
/** /**
* This step updates stock locations matching the specified filters. * This step updates stock locations matching the specified filters.
*
* @example
* const data = updateStockLocationsStep({
* selector: {
* id: "sloc_123"
* },
* update: {
* name: "European Warehouse"
* }
* })
*/ */
export const updateStockLocationsStep = createStep( export const updateStockLocationsStep = createStep(
updateStockLocationsStepId, updateStockLocationsStepId,
@@ -10,6 +10,11 @@ import { StepResponse, createStep } from "@medusajs/framework/workflows-sdk"
import { Modules } from "@medusajs/framework/utils" import { Modules } from "@medusajs/framework/utils"
/**
* The data to upsert stock location addresses.
*/
export type UpsertStockLocationAddressesStepInput = UpsertStockLocationAddressInput[]
export const upsertStockLocationAddressesStepId = export const upsertStockLocationAddressesStepId =
"upsert-stock-location-addresses-step" "upsert-stock-location-addresses-step"
/** /**
@@ -10,7 +10,27 @@ import { associateFulfillmentSetsWithLocationStep } from "../steps/associate-loc
export const createLocationFulfillmentSetWorkflowId = export const createLocationFulfillmentSetWorkflowId =
"create-location-fulfillment-set" "create-location-fulfillment-set"
/** /**
* This workflow creates links between location and fulfillment set records. * This workflow adds a fulfillment set to a stock location. It's used by the
* [Add Fulfillment Set to Stock Location Admin API Route](https://docs.medusajs.com/api/admin#stock-locations_poststocklocationsidfulfillmentsets).
*
* You can use this workflow within your own customizations or custom workflows, allowing you
* to add fulfillment sets to a stock location in your custom flows.
*
* @example
* const { result } = await createLocationFulfillmentSetWorkflow(container)
* .run({
* input: {
* location_id: "sloc_123",
* fulfillment_set_data: {
* name: "Shipping",
* type: "shipping",
* }
* }
* })
*
* @summary
*
* Add fulfillment set to a stock location.
*/ */
export const createLocationFulfillmentSetWorkflow = createWorkflow( export const createLocationFulfillmentSetWorkflow = createWorkflow(
createLocationFulfillmentSetWorkflowId, createLocationFulfillmentSetWorkflowId,
@@ -7,13 +7,39 @@ import {
import { CreateStockLocationInput } from "@medusajs/framework/types" import { CreateStockLocationInput } from "@medusajs/framework/types"
import { createStockLocations } from "../steps" import { createStockLocations } from "../steps"
/**
* The data to create the stock locations.
*/
export interface CreateStockLocationsWorkflowInput { export interface CreateStockLocationsWorkflowInput {
/**
* The stock locations to create.
*/
locations: CreateStockLocationInput[] locations: CreateStockLocationInput[]
} }
export const createStockLocationsWorkflowId = "create-stock-locations-workflow" export const createStockLocationsWorkflowId = "create-stock-locations-workflow"
/** /**
* This workflow creates one or more stock locations. * This workflow creates one or more stock locations. It's used by the
* [Create Stock Location Admin API Route](https://docs.medusajs.com/api/admin#stock-locations_poststocklocations).
*
* You can use this workflow within your own customizations or custom workflows, allowing you
* to create stock locations in your custom flows.
*
* @example
* const { result } = await createStockLocationsWorkflow(container)
* .run({
* input: {
* locations: [
* {
* name: "European Warehouse",
* }
* ]
* }
* })
*
* @summary
*
* Create one or more stock locations.
*/ */
export const createStockLocationsWorkflow = createWorkflow( export const createStockLocationsWorkflow = createWorkflow(
createStockLocationsWorkflowId, createStockLocationsWorkflowId,
@@ -3,13 +3,35 @@ import { WorkflowData, createWorkflow } from "@medusajs/framework/workflows-sdk"
import { removeRemoteLinkStep } from "../../common/steps/remove-remote-links" import { removeRemoteLinkStep } from "../../common/steps/remove-remote-links"
import { deleteStockLocationsStep } from "../steps" import { deleteStockLocationsStep } from "../steps"
/**
* The data to delete stock locations.
*/
export interface DeleteStockLocationWorkflowInput { export interface DeleteStockLocationWorkflowInput {
/**
* The IDs of the stock locations to delete.
*/
ids: string[] ids: string[]
} }
export const deleteStockLocationsWorkflowId = "delete-stock-locations-workflow" export const deleteStockLocationsWorkflowId = "delete-stock-locations-workflow"
/** /**
* This workflow deletes one or more stock locations. * This workflow deletes one or more stock locations. It's used by the
* [Delete Stock Location Admin API Route](https://docs.medusajs.com/api/admin#stock-locations_deletestocklocationsid).
*
* You can use this workflow within your own customizations or custom workflows, allowing you
* to delete stock locations in your custom flows.
*
* @example
* const { result } = await deleteStockLocationsWorkflow(container)
* .run({
* input: {
* ids: ["sloc_123"]
* }
* })
*
* @summary
*
* Delete one or more stock locations.
*/ */
export const deleteStockLocationsWorkflow = createWorkflow( export const deleteStockLocationsWorkflow = createWorkflow(
deleteStockLocationsWorkflowId, deleteStockLocationsWorkflowId,
@@ -6,14 +6,41 @@ import {
detachLocationsFromSalesChannelsStep, detachLocationsFromSalesChannelsStep,
} from "../../sales-channel" } from "../../sales-channel"
/**
* The sales channels to manage for a stock location.
*
* @property id - The ID of the stock location.
* @property add - The IDs of the sales channels to add to the stock location.
* @property remove - The IDs of the sales channels to remove from the stock location.
*/
export type LinkSalesChannelsToStockLocationWorkflowInput = LinkWorkflowInput
export const linkSalesChannelsToStockLocationWorkflowId = export const linkSalesChannelsToStockLocationWorkflowId =
"link-sales-channels-to-stock-location" "link-sales-channels-to-stock-location"
/** /**
* This workflow creates and dismisses links between location and sales channel records. * This workflow manages the sales channels of a stock location. It's used by the
* [Manage Sales Channels Admin API Route](https://docs.medusajs.com/api/admin#stock-locations_poststocklocationsidsaleschannels).
*
* You can use this workflow within your own customizations or custom workflows, allowing you
* to manage the sales channels of a stock location in your custom flows.
*
* @example
* const { result } = await linkSalesChannelsToStockLocationWorkflow(container)
* .run({
* input: {
* id: "sloc_123",
* add: ["sc_123"],
* remove: ["sc_321"]
* }
* })
*
* @summary
*
* Manage the sales channels of a stock location.
*/ */
export const linkSalesChannelsToStockLocationWorkflow = createWorkflow( export const linkSalesChannelsToStockLocationWorkflow = createWorkflow(
linkSalesChannelsToStockLocationWorkflowId, linkSalesChannelsToStockLocationWorkflowId,
(input: WorkflowData<LinkWorkflowInput>): void => { (input: WorkflowData<LinkSalesChannelsToStockLocationWorkflowInput>): void => {
const toAdd = transform({ input }, (data) => { const toAdd = transform({ input }, (data) => {
return data.input.add?.map((salesChannelId) => ({ return data.input.add?.map((salesChannelId) => ({
sales_channel_id: salesChannelId, sales_channel_id: salesChannelId,
@@ -15,13 +15,43 @@ import { useQueryGraphStep } from "../../common"
import { updateStockLocationsStep } from "../steps" import { updateStockLocationsStep } from "../steps"
import { upsertStockLocationAddressesStep } from "../steps/upsert-stock-location-addresses" import { upsertStockLocationAddressesStep } from "../steps/upsert-stock-location-addresses"
/**
* The data to update the stock locations.
*/
export interface UpdateStockLocationsWorkflowInput { export interface UpdateStockLocationsWorkflowInput {
/**
* The filters to select the stock locations to update.
*/
selector: FilterableStockLocationProps selector: FilterableStockLocationProps
/**
* The data to update the stock locations with.
*/
update: UpdateStockLocationInput update: UpdateStockLocationInput
} }
export const updateStockLocationsWorkflowId = "update-stock-locations-workflow" export const updateStockLocationsWorkflowId = "update-stock-locations-workflow"
/** /**
* This workflow updates stock locations matching the specified filters. * This workflow updates stock locations matching the specified filters. It's used by the
* [Update Stock Location Admin API Route](https://docs.medusajs.com/api/admin#stock-locations_poststocklocationsid).
*
* You can use this workflow within your own customizations or custom workflows, allowing you
* to update stock locations in your custom flows.
*
* @example
* const { result } = await updateStockLocationsWorkflow(container)
* .run({
* input: {
* selector: {
* id: "sloc_123"
* },
* update: {
* name: "European Warehouse"
* }
* }
* })
*
* @summary
*
* Update stock locations.
*/ */
export const updateStockLocationsWorkflow = createWorkflow( export const updateStockLocationsWorkflow = createWorkflow(
updateStockLocationsWorkflowId, updateStockLocationsWorkflowId,
@@ -1,5 +1,11 @@
/**
* The data to update in an inventory item.
*/
export interface UpdateInventoryItemInput export interface UpdateInventoryItemInput
extends Partial<CreateInventoryItemInput> { extends Partial<CreateInventoryItemInput> {
/**
* The ID of the inventory item to update.
*/
id: string id: string
} }
/** /**
@@ -59,6 +59,8 @@ export type BulkAdjustInventoryLevelInput = {
/** /**
* The quantity to adjust the inventory level by. * The quantity to adjust the inventory level by.
* If positive, the quantity will be added to the stocked quantity.
* If negative, the quantity will be subtracted from the stocked quantity.
*/ */
adjustment: BigNumberInput adjustment: BigNumberInput
} }
@@ -6,6 +6,9 @@ import { BigNumberInput } from "../../totals"
* The attributes to update in a reservation item. * The attributes to update in a reservation item.
*/ */
export interface UpdateReservationItemInput { export interface UpdateReservationItemInput {
/**
* The ID of the reservation to update.
*/
id: string id: string
/** /**
* The reserved quantity. * The reserved quantity.
@@ -457,7 +457,14 @@ export type UpdateStockLocationAddressInput = StockLocationAddressInput & {
id: string id: string
} }
/**
* The stock location address to create or update. If the `id` property isn't provided,
* the stock location address is created. In that case, the `address_1` property is required.
*/
export type UpsertStockLocationAddressInput = StockLocationAddressInput & { export type UpsertStockLocationAddressInput = StockLocationAddressInput & {
/**
* The ID of the stock location address, if updating.
*/
id?: string id?: string
} }
@@ -1,7 +1,16 @@
import { CreateReservationItemInput, ReservationItemDTO } from "../../inventory" import { CreateReservationItemInput, ReservationItemDTO } from "../../inventory"
/**
* The data to create the reservations.
*/
export interface CreateReservationsWorkflowInput { export interface CreateReservationsWorkflowInput {
/**
* The reservations to create.
*/
reservations: CreateReservationItemInput[] reservations: CreateReservationItemInput[]
} }
/**
* The created reservations.
*/
export type CreateReservationsWorkflowOutput = ReservationItemDTO[] export type CreateReservationsWorkflowOutput = ReservationItemDTO[]
@@ -1,7 +1,16 @@
import { ReservationItemDTO, UpdateReservationItemInput } from "../../inventory" import { ReservationItemDTO, UpdateReservationItemInput } from "../../inventory"
/**
* The data to update the reservations.
*/
export interface UpdateReservationsWorkflowInput { export interface UpdateReservationsWorkflowInput {
/**
* The reservations to update.
*/
updates: UpdateReservationItemInput[] updates: UpdateReservationItemInput[]
} }
/**
* The updated reservations.
*/
export type UpdateReservationsWorkflowOutput = ReservationItemDTO[] export type UpdateReservationsWorkflowOutput = ReservationItemDTO[]
@@ -1,7 +1,22 @@
/**
* The data to add a fulfillment set to a stock location.
*/
export interface CreateLocationFulfillmentSetWorkflowInputDTO { export interface CreateLocationFulfillmentSetWorkflowInputDTO {
/**
* The ID of the stock location to add the fulfillment set to.
*/
location_id: string location_id: string
/**
* The data of the fulfillment set to add.
*/
fulfillment_set_data: { fulfillment_set_data: {
/**
* The name of the fulfillment set.
*/
name: string name: string
/**
* The type of the fulfillment set.
*/
type: string type: string
} }
} }