Skip to main content
Manages the offer ↔ inventory_item links that define what stock an offer consumes. Validates the payload (no duplicates, no ID in more than one bucket, created items must exist, deleted items must already be linked), then batches the link changes — each link carries a required_quantity (default 1). Emits offer.updated. Triggered by POST /vendor/offers/:id/inventory-items/batch.

Usage

import { batchOfferInventoryItemsWorkflow } from "@mercurjs/core/workflows"

const { result } = await batchOfferInventoryItemsWorkflow(container).run({
  input: {
    offer_id: "offer_123",
    create: [{ inventory_item_id: "iitem_1", required_quantity: 2 }],
    update: [{ inventory_item_id: "iitem_2", required_quantity: 1 }],
    delete: ["iitem_3"],
  },
})

Input

offer_id
string
required
The offer whose inventory links are managed; fails if not found.
create
object[]
Links to create; the inventory items must exist and not appear in update/delete.
update
object[]
Existing links to update.
delete
string[]
Inventory item IDs to unlink; each must currently be linked or the workflow throws a 404.
additional_data
object
Custom data passed through to the workflow hooks.

Result

result.created
LinkDefinition[]
The created offer ↔ inventory-item links.
result.updated
LinkDefinition[]
The updated links.
result.deleted
string[]
Inventory item IDs that were unlinked.

Hooks

  • validate — runs first with { input }.
  • offerInventoryItemsBatched — runs after the batch with { offer_id, result, additional_data }.
batchOfferInventoryItemsWorkflow.hooks.offerInventoryItemsBatched(
  async ({ offer_id, result }) => {
    // react to link changes
  }
)