:hedgehog: PostHog is the leading platform for building self-driving products. Our developer tools – AI observability, analytics, session replay, flags, experiments, error tracking, logs, and more – capture all the context agents need to diagnose problems, uncover opportunities, and ship fixes. Steer it all from Slack, web, desktop, or the MCP.
Python ab-testingai-analyticsanalyticscdpdata-warehouseexperimentsfeature-flagsjavascriptproduct-analyticspythonreactsession-replaysurveystypescriptweb-analytics
feat(warehouse_sources): add four medusa endpoint tables (#122644)
Tom Owers74ac6126803f
diff --git a/products/warehouse_sources/backend/temporal/data_imports/sources/COVERAGE_GAPS_APPENDIX.md b/products/warehouse_sources/backend/temporal/data_imports/sources/COVERAGE_GAPS_APPENDIX.mdindex 0efdcfedae3d..ac06a9126869 100644--- a/products/warehouse_sources/backend/temporal/data_imports/sources/COVERAGE_GAPS_APPENDIX.md+++ b/products/warehouse_sources/backend/temporal/data_imports/sources/COVERAGE_GAPS_APPENDIX.md@@ -7734,15 +7734,15 @@ Note: Read the vendor SDK's controller docs (32 controllers) and enumerated the## Medusa — gaps-Today (9): `CustomerGroups`, `Customers`, `DraftOrders`, `Orders`, `PriceLists`, `Products`, `ProductVariants`, `Regions`, `Returns`+Today (13): `Claims`, `CustomerGroups`, `Customers`, `DraftOrders`, `Exchanges`, `InventoryItems`, `Orders`, `PriceLists`, `Products`, `ProductVariants`, `Regions`, `Returns`, `StockLocations`Diffed against: <https://raw.githubusercontent.com/medusajs/medusa/develop/www/apps/api-reference/specs/admin/openapi.yaml>-- [ ] `Stock locations (GET /admin/stock-locations)` — resolve location_id on returns and support stock analysis by warehouse (high)-- [ ] `Claims (GET /admin/claims)` — resolve claim_id on returns and analyze reasons for after-sale claims (high)-- [ ] `Exchanges (GET /admin/exchanges)` — resolve exchange_id on returns and measure replacement activity (high)+- [x] `Stock locations (GET /admin/stock-locations)` — resolve location_id on returns and support stock analysis by warehouse (high). Added as `StockLocations`.+- [x] `Claims (GET /admin/claims)` — resolve claim_id on returns and analyze reasons for after-sale claims (high). Added as `Claims`.+- [x] `Exchanges (GET /admin/exchanges)` — resolve exchange_id on returns and measure replacement activity (high). Added as `Exchanges`.- [ ] `Payments (GET /admin/payments)` — track captured and refunded payments for revenue reconciliation (high)-- [ ] `Inventory items (GET /admin/inventory-items)` — measure available, reserved, and stocked quantities, including nested location levels (high)+- [x] `Inventory items (GET /admin/inventory-items)` — measure available, reserved, and stocked quantities, including nested location levels (high). Added as `InventoryItems` (full refresh: the list route has no timestamp filters).- [ ] `Reservations (GET /admin/reservations)` — analyze inventory commitments and their impact on available stock (medium)- [ ] `Promotions (GET /admin/promotions)` — compare discount rules with order revenue and promotional performance (medium)- [ ] `Campaigns (GET /admin/campaigns)` — measure promotion budgets and campaign usage (medium)diff --git a/products/warehouse_sources/backend/temporal/data_imports/sources/medusa/canonical_descriptions.py b/products/warehouse_sources/backend/temporal/data_imports/sources/medusa/canonical_descriptions.pyindex 6e1fb4d2a383..a844b91cd06e 100644--- a/products/warehouse_sources/backend/temporal/data_imports/sources/medusa/canonical_descriptions.py+++ b/products/warehouse_sources/backend/temporal/data_imports/sources/medusa/canonical_descriptions.py@@ -132,4 +132,59 @@ CANONICAL_DESCRIPTIONS: CanonicalDescriptions = {**_TIMESTAMPS,},},+ "Exchanges": {+ "description": "An exchange on an order, where returned items are swapped for new ones.",+ "docs_url": "https://docs.medusajs.com/api/admin#exchanges",+ "columns": {+ "id": "Unique identifier of the exchange.",+ "order_id": "ID of the order the exchange is created for.",+ "return_id": "ID of the return that carries the exchange's inbound items.",+ "display_id": "Human-readable display ID of the exchange.",+ "order_version": "Version of the order once the exchange is applied.",+ "created_by": "ID of the user that created the exchange.",+ "canceled_at": "Date the exchange was canceled.",+ **_TIMESTAMPS,+ },+ },+ "Claims": {+ "description": "A claim on an order, to refund or replace items the customer received damaged or wrong.",+ "docs_url": "https://docs.medusajs.com/api/admin#claims",+ "columns": {+ "id": "Unique identifier of the claim.",+ "type": "Type of the claim: refund or replace.",+ "order_id": "ID of the order associated with the claim.",+ "return_id": "ID of the associated return.",+ "display_id": "Human-readable display ID of the claim.",+ "order_version": "Version of the order when the claim is applied.",+ "refund_amount": "Amount to be refunded.",+ "created_by": "ID of the user that created the claim.",+ "canceled_at": "Date the claim was canceled.",+ **_TIMESTAMPS,+ },+ },+ "StockLocations": {+ "description": "A physical location, such as a warehouse, where inventory is stocked and fulfilled from.",+ "docs_url": "https://docs.medusajs.com/api/admin#stock-locations",+ "columns": {+ "id": "Unique identifier of the stock location.",+ "name": "Name of the stock location.",+ "address": "Address of the stock location.",+ "metadata": "Key-value pairs of custom data.",+ **_TIMESTAMPS,+ },+ },+ "InventoryItems": {+ "description": "A stock-keeping item, with its total stocked and reserved quantities and its levels per stock location.",+ "docs_url": "https://docs.medusajs.com/api/admin#inventory-items",+ "columns": {+ "id": "Unique identifier of the inventory item.",+ "sku": "SKU of the inventory item.",+ "title": "Title of the inventory item.",+ "requires_shipping": "Whether the inventory item requires shipping.",+ "stocked_quantity": "Total quantity of the item stocked across all locations.",+ "reserved_quantity": "Total quantity of the item reserved across all locations.",+ "location_levels": "Per-location inventory levels, with stocked, reserved, incoming, and available quantities.",+ **_TIMESTAMPS,+ },+ },}diff --git a/products/warehouse_sources/backend/temporal/data_imports/sources/medusa/settings.py b/products/warehouse_sources/backend/temporal/data_imports/sources/medusa/settings.pyindex d75580271312..1a7681ab1faf 100644--- a/products/warehouse_sources/backend/temporal/data_imports/sources/medusa/settings.py+++ b/products/warehouse_sources/backend/temporal/data_imports/sources/medusa/settings.py@@ -67,8 +67,9 @@ class MedusaEndpointConfig:# Medusa v2 Admin API list routes. Every entry is a documented list route on a stock v2 server;-# all carry `created_at`/`updated_at` operator filters except price lists, whose list route-# documents no timestamp filters. Fulfillments have no list route in v2, so they are absent.+# all carry `created_at`/`updated_at` operator filters except price lists and inventory items,+# whose list routes document no timestamp filters (the inventory item validator is strict and+# rejects them). Fulfillments have no list route in v2, so they are absent.MEDUSA_ENDPOINTS: dict[str, MedusaEndpointConfig] = {"Orders": MedusaEndpointConfig(name="Orders", path="/orders", data_selector="orders"),"DraftOrders": MedusaEndpointConfig(name="DraftOrders", path="/draft-orders", data_selector="draft_orders"),@@ -83,6 +84,14 @@ MEDUSA_ENDPOINTS: dict[str, MedusaEndpointConfig] = {name="PriceLists", path="/price-lists", data_selector="price_lists", incremental_field_name=None),"Returns": MedusaEndpointConfig(name="Returns", path="/returns", data_selector="returns"),+ "Exchanges": MedusaEndpointConfig(name="Exchanges", path="/exchanges", data_selector="exchanges"),+ "Claims": MedusaEndpointConfig(name="Claims", path="/claims", data_selector="claims"),+ "StockLocations": MedusaEndpointConfig(+ name="StockLocations", path="/stock-locations", data_selector="stock_locations"+ ),+ "InventoryItems": MedusaEndpointConfig(+ name="InventoryItems", path="/inventory-items", data_selector="inventory_items", incremental_field_name=None+ ),}ENDPOINTS = tuple(MEDUSA_ENDPOINTS)diff --git a/products/warehouse_sources/backend/temporal/data_imports/sources/medusa/tests/test_medusa.py b/products/warehouse_sources/backend/temporal/data_imports/sources/medusa/tests/test_medusa.pyindex f380c6f0ced1..9c31e3c36179 100644--- a/products/warehouse_sources/backend/temporal/data_imports/sources/medusa/tests/test_medusa.py+++ b/products/warehouse_sources/backend/temporal/data_imports/sources/medusa/tests/test_medusa.py@@ -107,9 +107,10 @@ class TestMedusaTransport:assert endpoint["incremental"]["start_param"] == "updated_at[$gte]"assert endpoint["incremental"]["cursor_path"] == "updated_at"- def test_incremental_rejected_for_endpoint_without_timestamp_filters(self) -> None:+ @pytest.mark.parametrize("endpoint", ["PriceLists", "InventoryItems"])+ def test_incremental_rejected_for_endpoint_without_timestamp_filters(self, endpoint: str) -> None:with pytest.raises(ValueError, match="does not support incremental"):- get_resource(MEDUSA_ENDPOINTS["PriceLists"], should_use_incremental_field=True)+ get_resource(MEDUSA_ENDPOINTS[endpoint], should_use_incremental_field=True)def test_incremental_rejected_for_unadvertised_cursor_field(self) -> None:with pytest.raises(ValueError, match="no incremental field 'created_at'"):