@mercurjs/docs 2.3.7 → 2.3.8-canary.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -12,7 +12,7 @@ This reference lists the workflows for the Offer domain. Import them from
12
12
  | Workflow | Input | Purpose |
13
13
  | --- | --- | --- |
14
14
  | `createOffersWorkflow` | `{ offers[], additional_data? }` | Create offers with prices, inventory, and links |
15
- | `updateOffersWorkflow` | `{ offers[], additional_data? }` | Update offer rows and rewrite their price ladders |
15
+ | `updateOffersWorkflow` | `{ offers[], updated_by?, additional_data? }` | Update offer rows and rewrite their price ladders |
16
16
  | `deleteOffersWorkflow` | `{ ids[], additional_data? }` | Delete offers |
17
17
  | `batchOfferInventoryItemsWorkflow` | `{ offer_id, create?, update?, delete?, additional_data? }` | Add, update, and detach an offer's inventory-item links |
18
18
 
@@ -24,9 +24,37 @@ Each workflow exposes hooks so you can extend it without forking:
24
24
  | --- | --- |
25
25
  | `createOffersWorkflow` | `validate`, `offersCreated` |
26
26
  | `updateOffersWorkflow` | `validate`, `offersUpdated` |
27
+ | `upsertOfferPricesWorkflow` | `offerPricesUpserted` |
27
28
  | `deleteOffersWorkflow` | `offersDeleted` |
28
29
  | `batchOfferInventoryItemsWorkflow` | `validate`, `offerInventoryItemsBatched` |
29
30
 
31
+ ### Hook payloads
32
+
33
+ | Hook | Payload |
34
+ | --- | --- |
35
+ | `offersCreated` | `{ offers: OfferDTO[], additional_data? }` — each offer carries `created_by` and its `prices` |
36
+ | `offersUpdated` | `{ offers: OfferDTO[], previous_offers: OfferDTO[], updated_by?, additional_data? }` — `previous_offers` is the row state before the write |
37
+ | `offerPricesUpserted` | `{ offers: Array<{ offer_id, previous_prices: OfferPriceDTO[], prices: OfferPriceDTO[], created: string[], updated: string[], deleted: string[] }>, updated_by: string \| null }` |
38
+ | `offersDeleted` | `{ ids: string[], offers: OfferDTO[], additional_data? }` — `offers` is a snapshot taken before deletion, including `prices` |
39
+
40
+ `updated_by` is the authenticated actor id. Vendor routes fill it from the session; pass it yourself when running `updateOffersWorkflow` or `upsertOfferPricesWorkflow` directly.
41
+
42
+ In `offerPricesUpserted`, `previous_prices` and `prices` are the offer's ladder before and after the write (`amount`, `currency_code`, `min_quantity`, `max_quantity`, `price_rules`). `created` and `deleted` hold the price ids added and removed; `updated` holds the ids rewritten in place whose amount, quantity bounds, or rules actually changed — an unchanged row resent with its id is not listed. The hook also fires when `updateOffersWorkflow` runs the price upsert for you, so a single handler on `upsertOfferPricesWorkflow` covers both entry points. Prices are hard-deleted and Medusa's pricing events carry ids only, so these payloads (and the `offersDeleted` snapshot) are the only place the previous values can be read.
43
+
44
+ ```ts
45
+ import { upsertOfferPricesWorkflow } from "@mercurjs/core/workflows"
46
+ import { StepResponse } from "@medusajs/framework/workflows-sdk"
47
+
48
+ upsertOfferPricesWorkflow.hooks.offerPricesUpserted(
49
+ async ({ offers, updated_by }, { container }) => {
50
+ for (const { offer_id, previous_prices, prices, updated } of offers) {
51
+ // record a price-history entry for every id in `updated`
52
+ }
53
+ return new StepResponse(undefined)
54
+ }
55
+ )
56
+ ```
57
+
30
58
  ## Behavior notes
31
59
 
32
60
  - **Prices** are written on the master variant's shared price set, each row scoped by an `offer_id` `PriceRule`. On update, supplying `prices` replaces the ladder with the given rows; omitting it leaves prices untouched.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@mercurjs/docs",
3
- "version": "2.3.7",
3
+ "version": "2.3.8-canary.0",
4
4
  "repository": {
5
5
  "type": "git",
6
6
  "url": "https://github.com/mercurjs/mercur",