Skip to main content
The Commission module ships five workflows, exported from @mercurjs/core/workflows. They run against the Medusa container, and each step compensates on failure unless noted. None of them emits an event.

createCommissionRatesWorkflow

Creates one or more commission rates. Workflow id create-commission-rates. CreateCommissionRateDTO takes name, type, and value, and optionally code, currency_code, include_tax, include_shipping, is_enabled, and is_default. The module also accepts nested rules and values arrays, which the DTO doesn’t declare. A missing code is generated from name.
  • Output: the created rates, in input order
  • Steps: createCommissionRatesStep, compensated by deleting the created rates
  • Hooks: none

updateCommissionRatesWorkflow

Updates fields on one or more rates. Workflow id update-commission-rates. Each item needs an id and takes any CreateCommissionRateDTO field as optional.
  • Output: the updated rates
  • Steps: updateCommissionRatesStep
  • Hooks: none
The compensation of updateCommissionRatesStep re-applies the step’s input, not the previous values. If a later step in a parent workflow fails, the rate keeps the new values.

deleteCommissionRatesWorkflow

Soft-deletes rates after checking that none of them is the global rate. Workflow id delete-commission-rates.
  • Output: none
  • Steps: validateCommissionRatesDeletableStep, which throws NOT_ALLOWED for an is_default rate, then deleteCommissionRatesStep, compensated by restoring the rates
  • Hooks: commissionRatesDeleted, with { ids }

batchCommissionRulesWorkflow

Creates, updates, and deletes the rules of one rate. Workflow id batch-commission-rules.
  • Output: { created, updated, deleted }, where deleted holds the ids
  • Steps: createCommissionRulesStep, updateCommissionRulesStep, and deleteCommissionRulesStep, run in parallel
  • Hooks: none
Only create uses commission_rate_id. The ids in update and delete aren’t checked against it.

refreshOrderCommissionLinesWorkflow

Recomputes and replaces the commission lines of one or more orders. Workflow id refresh-order-commission-lines.
  • Output: CommissionLineDTO[], the lines written for all the orders
  • Steps: fetch-orders (useQueryGraphStep), getCommissionLinesStep, upsertCommissionLinesStep
  • Called by: completeCartWithSplitOrdersWorkflow and the order-commission-refresh-handler subscriber
The workflow exposes two hooks:
The handler above adds data to every context before the provider sees it. Neither getCommissionLinesStep nor upsertCommissionLinesStep defines a compensation.

Exported steps

@mercurjs/core/workflows also exports each step, with its id, for use in your own workflows: