@mercurjs/core/workflows and run them with the Medusa container.
createOffersWorkflow
Creates offers with their inventory items, prices, and links. Returns the createdOfferDTO[].
Each
CreateOfferDTO requires seller_id, created_by, sku, variant_id, shipping_profile_id, prices, and at least one inventory_items entry. Optional fields are ean, upc, manage_inventory, allow_backorder, leadtime_to_ship, condition_id, and metadata.
An inventory_items entry takes required_quantity (default 1), sku, title, and stock_levels (location_id, stocked_quantity). A price takes amount, currency_code, and optional min_quantity, max_quantity, and rules.
The run creates the inventory items and links them to the offer and to the store of the first entry. It adds prices to each variant’s price set with an offer_id rule, creating the price set first if the variant has none. It also links each master product to its first offer’s shipping profile when the product has no profile.
updateOffersWorkflow
Updates offer rows and, for entries with aprices array, replaces that offer’s prices through upsertOfferPricesWorkflow. Returns the updated OfferDTO[].
UpdateOfferDTO accepts sku, shipping_profile_id, manage_inventory, allow_backorder, leadtime_to_ship, condition_id, metadata, and prices. Leave out prices to keep the current rows. A condition_id must point at an active condition.
previous_offers holds the offer rows as they were before the write.
upsertOfferPricesWorkflow
Replaces each listed offer’s prices without touching other offers on the same variant. Returns{ offer_id, price_ids }[] for the prices it created.
A price with an
id updates that row, a price without one is added, and owned prices left out are deleted with their links. An id that belongs to another offer fails the run with Price … does not belong to offer ….
Each entry in
offers has these fields:
offer_id: the offerprevious_prices: the offer’s prices before the writeprices: the offer’s prices after the writecreated: ids of new pricesupdated: ids whose amount, currency, quantity bounds, or rules changed; an unchanged row resent with itsidisn’t listeddeleted: ids of removed prices
updateOffersWorkflow runs the upsert, so one handler covers both entry points:
src/workflows/hooks/offer-prices-upserted.ts
deleteOffersWorkflow
Soft-deletes offers. It has no step that removes their prices or inventory items.offers is a snapshot taken before the delete, with each offer’s prices.
batchOfferInventoryItemsWorkflow
Creates, updates, and removesoffer ↔ inventory_item links on one offer. Returns { created, updated, deleted }.
The run fails when the offer doesn’t exist, an item in
create doesn’t exist, an item in delete isn’t linked, or an id repeats within or across the lists.
createOfferConditionsWorkflow
Creates offer conditions. ReturnsOfferConditionDTO[].
updateOfferConditionsWorkflow
Updates offer conditions byid. Returns OfferConditionDTO[].