: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(data-warehouse): add 4 missing tables to the Veeqo source (#118348)
Tom Owers2bde4869c8c7
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 29b43ce3e6bd..c31c278c3aaf 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@@ -12891,10 +12891,10 @@ Today (9): `customers`, `delivery_methods`, `orders`, `products`, `purchase_ordeDiffed against: <https://developers.veeqo.com/api/operations/list-all-customers/>-- [ ] `GET returns on order (/orders/{order_id}/returns)` — returns and refunds per order — not present in any synced table (medium)-- [ ] `GET stock entry (/sellables/{sellable_id}/warehouses/{warehouse_id}/stock_entry)` — per-warehouse inventory levels, Veeqo's core operational metric, as a flat table (medium)-- [ ] `GET view tracking events (shipments)` — delivery state transitions per shipment, the fulfillment timeline (medium)-- [ ] `GET retrieve bundle detail and GET retrieve bundle content` — bundle/kit composition — resolves which sellables make up a bundled product (low)+- [x] `GET returns on order (/orders/{order_id}/returns)` — returns and refunds per order — not present in any synced table (medium)+- [x] `GET stock entry (/sellables/{sellable_id}/warehouses/{warehouse_id}/stock_entry)` — per-warehouse inventory levels, Veeqo's core operational metric, as a flat table (medium)+- [x] `GET view tracking events (shipments)` — delivery state transitions per shipment, the fulfillment timeline (medium)+- [x] `GET retrieve bundle detail and GET retrieve bundle content` — bundle/kit composition — resolves which sellables make up a bundled product (low)- [ ] `GET view properties (/products/{product_id}/product_property_specifics/{property_id})` — custom product attributes used as breakdown dimensions (low)- [ ] `GET view company detail (/company)` — single account/company record for currency and locale context (low)diff --git a/products/warehouse_sources/backend/temporal/data_imports/sources/veeqo/api_inventory.md b/products/warehouse_sources/backend/temporal/data_imports/sources/veeqo/api_inventory.mdindex 9ac86b4ad9a4..e5a33e26bde0 100644--- a/products/warehouse_sources/backend/temporal/data_imports/sources/veeqo/api_inventory.md+++ b/products/warehouse_sources/backend/temporal/data_imports/sources/veeqo/api_inventory.md@@ -29,21 +29,27 @@ Source: Veeqo — multichannel ecommerce inventory, order and shipping managemen## Endpoints-| Schema | Path | Primary key | Partition key | Incremental | Notes |-| ------------------ | ------------------- | ----------- | ------------- | ----------- | --------------------------------------------------------------- |-| `orders` | `/orders` | `id` | `created_at` | ✅ | `updated_at_min` / `created_at_min` / `since_id`. |-| `products` | `/products` | `id` | `created_at` | ✅ | `updated_at_min` / `created_at_min` / `since_id`; max page 100. |-| `customers` | `/customers` | `id` | — | ➖ full | Only `page`/`page_size`/`query`/`customer_type` documented. |-| `purchase_orders` | `/purchase_orders` | `id` | `created_at` | ➖ full | `show_complete=true` sent so completed POs are included. |-| `suppliers` | `/suppliers` | `id` | — | ➖ full | |-| `warehouses` | `/warehouses` | `id` | — | ➖ full | |-| `stores` | `/channels` | `id` | — | ➖ full | Veeqo calls stores "channels" in the API. |-| `tags` | `/tags` | `id` | — | ➖ full | No pagination params documented; fetched as a single page. |-| `delivery_methods` | `/delivery_methods` | `id` | `created_at` | ➖ full | |+| Schema | Path | Primary key | Partition key | Incremental | Notes |+| -------------------------- | ----------------------------------------- | ------------------------------------ | ------------- | ----------- | ------------------------------------------------------------------------------ |+| `orders` | `/orders` | `id` | `created_at` | ✅ | `updated_at_min` / `created_at_min` / `since_id`. |+| `products` | `/products` | `id` | `created_at` | ✅ | `updated_at_min` / `created_at_min` / `since_id`; max page 100. |+| `customers` | `/customers` | `id` | — | ➖ full | Only `page`/`page_size`/`query`/`customer_type` documented. |+| `purchase_orders` | `/purchase_orders` | `id` | `created_at` | ➖ full | `show_complete=true` sent so completed POs are included. |+| `suppliers` | `/suppliers` | `id` | — | ➖ full | |+| `warehouses` | `/warehouses` | `id` | — | ➖ full | |+| `stores` | `/channels` | `id` | — | ➖ full | Veeqo calls stores "channels" in the API. |+| `tags` | `/tags` | `id` | — | ➖ full | No pagination params documented; fetched as a single page. |+| `delivery_methods` | `/delivery_methods` | `id` | `created_at` | ➖ full | |+| `returns` | `/orders` | `order_id`, `id` | `created_at` | ➖ full | Exploded from each order's embedded `returns`. |+| `stock_entries` | `/products` | `sellable_id`, `warehouse_id` | — | ➖ full | Exploded from each product's `sellables[].stock_entries`. |+| `shipment_tracking_events` | `/shipping/tracking_events/{shipment_id}` | `shipment_id`, `timestamp`, `status` | — | ➖ full | Fan-out: one request per `orders[].allocations[].shipment`; 404 skipped. |+| `bundle_contents` | `/kits/{kit_id}` | `kit_id`, `id` | — | ➖ full | Fan-out: one request per product sellable of type `Kit`; rows from `contents`. |## Possible future work-- **Nested resources.** Order allocations/shipments, product sellables and per-warehouse stock- entries are nested in the orders/products payloads today; dedicated fan-out endpoints- (`/sellables/{id}/warehouses/{id}/stock_entry`) exist if flattened tables are ever needed.+- **Nested resources.** Order allocations/shipments and product sellables are still nested in+ the orders/products payloads.+- **Fan-out cost.** `shipment_tracking_events` and `bundle_contents` make one request per+ shipment or bundle on every sync, at Veeqo's 5 requests/second rate limit. Veeqo has no+ server-side filter that limits them to changed shipments or bundles.- **Webhooks.** Veeqo has no webhook API, so `WebhookSource` is not applicable.diff --git a/products/warehouse_sources/backend/temporal/data_imports/sources/veeqo/canonical_descriptions.py b/products/warehouse_sources/backend/temporal/data_imports/sources/veeqo/canonical_descriptions.pyindex ab4c97cc8191..81e26a84c427 100644--- a/products/warehouse_sources/backend/temporal/data_imports/sources/veeqo/canonical_descriptions.py+++ b/products/warehouse_sources/backend/temporal/data_imports/sources/veeqo/canonical_descriptions.py@@ -160,4 +160,71 @@ CANONICAL_DESCRIPTIONS: CanonicalDescriptions = {"updated_at": "The date and time when the delivery method was last updated.",},},+ "returns": {+ "description": "A return raised against an order, with its returned line items. One row per return.",+ "docs_url": "https://developers.veeqo.com/api/operations/show-returns-on-order/",+ "columns": {+ "id": "Unique identifier for the return.",+ "order_id": "ID of the order the return belongs to.",+ "number": "The return's reference number.",+ "status": "The return's status (for example returning).",+ "reason": "The reason given for the return, if any.",+ "created_at": "The date and time when the return was created.",+ "type": "The kind of return (for example ShippedItemsReturn).",+ "line_items": "The returned items, with the quantity returned and the quantity received.",+ "user": "The user who created the return.",+ "warehouse_name": "The name of the warehouse that receives the return.",+ },+ },+ "stock_entries": {+ "description": "The stock level of one sellable (product variant or bundle) in one warehouse. One row per sellable and warehouse.",+ "docs_url": "https://developers.veeqo.com/api/operations/show-a-stock-entry/",+ "columns": {+ "sellable_id": "ID of the sellable (product variant or bundle) this stock entry is for.",+ "warehouse_id": "ID of the warehouse this stock entry is for.",+ "product_id": "ID of the product the sellable belongs to.",+ "infinite": "Whether the stock level in this warehouse is infinite.",+ "allocated_stock_level": "The number of units allocated to orders from this warehouse.",+ "physical_stock_level": "The number of units physically on hand in this warehouse.",+ "available_stock_level": "The number of units available for sale from this warehouse.",+ "incoming_stock_level": "The number of incoming units from purchase orders.",+ "transit_incoming_stock_level": "The number of incoming units from stock transfers in transit to this warehouse.",+ "transit_outgoing_stock_level": "The number of outgoing units from stock transfers in transit out of this warehouse.",+ "sellable_on_hand_value": "The value of the units on hand in this warehouse.",+ "stock_running_low": "Whether the physical stock level is below the reorder level.",+ "location": "The bin location of the sellable in this warehouse, if set.",+ "warehouse": "The warehouse this stock entry is for.",+ "updated_at": "The date and time when this stock entry was last updated.",+ },+ },+ "shipment_tracking_events": {+ "description": "A carrier tracking event for a shipment, such as in transit or delivered. Tracking events exist only for labels bought in Veeqo.",+ "docs_url": "https://developers.veeqo.com/api/operations/view-tracking-events/",+ "columns": {+ "shipment_id": "ID of the shipment the event belongs to.",+ "order_id": "ID of the order the shipment belongs to.",+ "timestamp": "The date and time of the tracking event.",+ "status": "The tracking status (for example in_transit, out_for_delivery or delivered).",+ "description": "A readable description of the tracking event.",+ "detail": "More detail about the tracking event, if any.",+ "location": "Where the tracking event happened, if known.",+ },+ },+ "bundle_contents": {+ "description": "A product variant included in a bundle, with its quantity. One row per bundle and content.",+ "docs_url": "https://developers.veeqo.com/api/operations/retrieve-bundle-content/",+ "columns": {+ "id": "ID of this bundle content. This is different from the product variant ID.",+ "kit_id": "ID of the bundle this content belongs to.",+ "product_id": "ID of the product the bundle belongs to.",+ "product_variant_id": "ID of the product variant this bundle content contains.",+ "quantity": "The number of units of the product variant in the bundle.",+ "sku_code": "The SKU code of the product variant.",+ "title": "The title of the product variant.",+ "total_available_stock_level": "The number of units of the product variant that are available for sale.",+ "product_variant": "The product variant this bundle content contains.",+ "created_at": "The date and time when the bundle content was created.",+ "updated_at": "The date and time when the bundle content was last updated.",+ },+ },}diff --git a/products/warehouse_sources/backend/temporal/data_imports/sources/veeqo/settings.py b/products/warehouse_sources/backend/temporal/data_imports/sources/veeqo/settings.pyindex cc43826a5444..297fcc4dfbf5 100644--- a/products/warehouse_sources/backend/temporal/data_imports/sources/veeqo/settings.py+++ b/products/warehouse_sources/backend/temporal/data_imports/sources/veeqo/settings.py@@ -1,6 +1,9 @@from dataclasses import dataclass, fieldfrom typing import Any, Optional+from products.warehouse_sources.backend.temporal.data_imports.sources.common.rest_source.fanout import (+ DependentEndpointConfig,+)from products.warehouse_sources.backend.types import IncrementalField, IncrementalFieldType# Veeqo defaults to tiny pages (12 on most endpoints, 10 on warehouses), so the page@@ -9,7 +12,7 @@ from products.warehouse_sources.backend.types import IncrementalField, IncrementDEFAULT_PAGE_SIZE = 100-@dataclass+@dataclass # nosemgrep: prefer-frozen-dataclasses -- pre-existing; new field shifts the backlog finding into diffclass VeeqoEndpointConfig:"""Declarative metadata for a single Veeqo list endpoint.@@ -34,6 +37,14 @@ class VeeqoEndpointConfig:# one response, so a page-number paginator would refetch the same full list forever# once it holds page_size or more rows.single_page: bool = False+ primary_keys: list[str] = field(default_factory=lambda: ["id"])+ # Veeqo has no list endpoints for returns, stock entries, shipments or bundles. Tables+ # set to True explode rows that `path` already embeds in each record, so they cost no+ # extra request.+ nested: bool = False+ # Tables that need one request per parent-derived id.+ fanout: Optional[DependentEndpointConfig] = None+ default_incremental_field: Optional[str] = None@propertydef supports_incremental(self) -> bool:@@ -116,6 +127,57 @@ VEEQO_ENDPOINTS: dict[str, VeeqoEndpointConfig] = {path="/delivery_methods",partition_key="created_at",),+ # Returns are embedded in each order (`returns`). `/orders/{id}/returns` documents a+ # required `sellable_id` query param, so a per-order request can't list them all.+ "returns": VeeqoEndpointConfig(+ name="returns",+ path="/orders",+ partition_key="created_at",+ primary_keys=["order_id", "id"],+ nested=True,+ ),+ # Each product embeds its sellables, and each sellable embeds its per-warehouse stock+ # entries — the same records `/sellables/{id}/warehouses/{id}/stock_entry` returns one+ # at a time.+ "stock_entries": VeeqoEndpointConfig(+ name="stock_entries",+ path="/products",+ primary_keys=["sellable_id", "warehouse_id"],+ nested=True,+ ),+ # Shipments are embedded in each order's allocations; Veeqo returns their events from a+ # per-shipment endpoint only.+ "shipment_tracking_events": VeeqoEndpointConfig(+ name="shipment_tracking_events",+ path="/shipping/tracking_events/{shipment_id}",+ primary_keys=["shipment_id", "timestamp", "status"],+ fanout=DependentEndpointConfig(+ parent_name="orders",+ resolve_param="shipment_id",+ resolve_field="shipment_id",+ include_from_parent=["shipment_id", "order_id"],+ parent_field_renames={"shipment_id": "shipment_id", "order_id": "order_id"},+ parent_params={"page_size": DEFAULT_PAGE_SIZE},+ # A shipment deleted between the orders listing and this request 404s.+ child_response_actions=[{"status_code": 404, "action": "ignore"}],+ ),+ ),+ # Bundles ("kits") appear as sellables of type `Kit` on their product; `/kits/{id}`+ # returns the bundle with its `contents`.+ "bundle_contents": VeeqoEndpointConfig(+ name="bundle_contents",+ path="/kits/{kit_id}",+ primary_keys=["kit_id", "id"],+ fanout=DependentEndpointConfig(+ parent_name="products",+ resolve_param="kit_id",+ resolve_field="kit_id",+ include_from_parent=["kit_id", "product_id"],+ parent_field_renames={"kit_id": "kit_id", "product_id": "product_id"},+ parent_params={"page_size": DEFAULT_PAGE_SIZE},+ child_response_actions=[{"status_code": 404, "action": "ignore"}],+ ),+ ),}ENDPOINTS = tuple(VEEQO_ENDPOINTS.keys())diff --git a/products/warehouse_sources/backend/temporal/data_imports/sources/veeqo/source.py b/products/warehouse_sources/backend/temporal/data_imports/sources/veeqo/source.pyindex 159ca38753bd..d2607afaafdf 100644--- a/products/warehouse_sources/backend/temporal/data_imports/sources/veeqo/source.py+++ b/products/warehouse_sources/backend/temporal/data_imports/sources/veeqo/source.py@@ -23,6 +23,7 @@ from products.warehouse_sources.backend.temporal.data_imports.sources.generated_from products.warehouse_sources.backend.temporal.data_imports.sources.veeqo.settings import (ENDPOINTS,INCREMENTAL_FIELDS,+ VEEQO_ENDPOINTS,)from products.warehouse_sources.backend.temporal.data_imports.sources.veeqo.veeqo import (VeeqoResumeConfig,@@ -102,7 +103,9 @@ The API key gives full account access, so store it securely.force_refresh: bool = False,api_version: str | None = None,) -> list[SourceSchema]:- return build_endpoint_schemas(ENDPOINTS, INCREMENTAL_FIELDS, names)+ # Fan-out tables make one request per shipment or bundle, so they are opt-in.+ should_sync_default = {name: False for name, config in VEEQO_ENDPOINTS.items() if config.fanout is not None}+ return build_endpoint_schemas(ENDPOINTS, INCREMENTAL_FIELDS, names, should_sync_default=should_sync_default)def validate_credentials(self, config: VeeqoSourceConfig, team_id: int, schema_name: Optional[str] = None, api_version: str | None = Nonediff --git a/products/warehouse_sources/backend/temporal/data_imports/sources/veeqo/tests/test_veeqo.py b/products/warehouse_sources/backend/temporal/data_imports/sources/veeqo/tests/test_veeqo.pyindex c7a942e82084..bd311da948be 100644--- a/products/warehouse_sources/backend/temporal/data_imports/sources/veeqo/tests/test_veeqo.py+++ b/products/warehouse_sources/backend/temporal/data_imports/sources/veeqo/tests/test_veeqo.py@@ -11,6 +11,7 @@ from products.warehouse_sources.backend.temporal.data_imports.sources.common.tesScriptedResponse,SourceDriver,always,+ route,scripted_network,)from products.warehouse_sources.backend.temporal.data_imports.sources.generated_configs.veeqo import VeeqoSourceConfig@@ -216,7 +217,7 @@ class TestVeeqoSourceResponse:config = VEEQO_ENDPOINTS[endpoint]assert response is not Noneassert response.name == endpoint- assert response.primary_keys == ["id"]+ assert response.primary_keys == config.primary_keys# Veeqo documents no list ordering, so the watermark must only commit after# a successful sync (desc semantics) — asc would checkpoint ≈now mid-sync.assert response.sort_mode == "desc"@@ -226,3 +227,244 @@ class TestVeeqoSourceResponse:else:assert response.partition_mode is Noneassert response.partition_keys is None+++class TestNestedTables:+ @parameterized.expand(+ [+ (+ "returns_carry_their_order_id",+ "returns",+ [+ {"id": 1, "returns": [{"id": 10, "status": "returning"}, {"id": 11, "status": "received"}]},+ {"id": 2, "returns": []},+ {"id": 3, "returns": None},+ {"id": 4},+ ],+ [+ {"id": 10, "status": "returning", "order_id": 1},+ {"id": 11, "status": "received", "order_id": 1},+ ],+ ),+ (+ "stock_entries_flatten_every_sellable",+ "stock_entries",+ [+ {+ "id": 5,+ "sellables": [+ {+ "id": 50,+ "stock_entries": [+ {"sellable_id": 50, "warehouse_id": 1, "physical_stock_level": 3},+ {"sellable_id": 50, "warehouse_id": 2, "physical_stock_level": 0},+ ],+ },+ {"id": 51, "stock_entries": [{"sellable_id": 51, "warehouse_id": 1}]},+ {"id": 52, "stock_entries": None},+ ],+ },+ {"id": 6, "sellables": []},+ {"id": 7},+ ],+ [+ {"sellable_id": 50, "warehouse_id": 1, "physical_stock_level": 3, "product_id": 5},+ {"sellable_id": 50, "warehouse_id": 2, "physical_stock_level": 0, "product_id": 5},+ {"sellable_id": 51, "warehouse_id": 1, "product_id": 5},+ ],+ ),+ ]+ )+ def test_rows_are_exploded_from_the_parent_list(+ self, _name: str, endpoint: str, parent_page: list[dict[str, Any]], expected_rows: list[dict[str, Any]]+ ) -> None:+ result = _run([_page(parent_page)], endpoint=endpoint)++ assert result.raised is None+ assert result.paths == [VEEQO_ENDPOINTS[endpoint].path]+ assert result.rows == expected_rows++ def test_parent_page_with_no_nested_rows_still_advances(self) -> None:+ result = _run(+ [+ _page([{"id": i, "returns": []} for i in range(100)], headers={"X-Total-Pages-Count": "2"}),+ _page([{"id": 900, "returns": [{"id": 1}]}]),+ ],+ endpoint="returns",+ )++ assert result.params("page") == ["1", "2"]+ assert result.rows == [{"id": 1, "order_id": 900}]+++class TestFanoutTables:+ @parameterized.expand(+ [+ (+ "tracking_events_per_shipment",+ "shipment_tracking_events",+ {+ "/orders": [+ _page(+ [+ {+ "id": 1,+ "allocations": [+ {"id": 100, "shipment": {"id": 7001}},+ {"id": 101, "shipment": None},+ {"id": 103, "shipment": {"id": 7001}},+ ],+ },+ {"id": 2, "allocations": [{"id": 102, "shipment": {"id": 7002}}]},+ {"id": 3, "allocations": []},+ {"id": 4},+ ]+ )+ ],+ "/shipping/tracking_events/7001": [+ _page(+ [+ {+ "timestamp": "2026-01-01T10:00:00+00:00",+ "status": "in_transit",+ "description": "In transit",+ },+ {+ "timestamp": "2026-01-02T10:00:00+00:00",+ "status": "delivered",+ "description": "Delivered",+ },+ ]+ )+ ],+ # A shipment deleted after the orders listing must not fail the sync.+ "/shipping/tracking_events/7002": [_page({"error": "not found"}, status=404)],+ },+ ["/orders", "/shipping/tracking_events/7001", "/shipping/tracking_events/7002"],+ [+ {+ "timestamp": "2026-01-01T10:00:00+00:00",+ "status": "in_transit",+ "description": "In transit",+ "shipment_id": 7001,+ "order_id": 1,+ },+ {+ "timestamp": "2026-01-02T10:00:00+00:00",+ "status": "delivered",+ "description": "Delivered",+ "shipment_id": 7001,+ "order_id": 1,+ },+ ],+ ),+ (+ "bundle_contents_only_for_kits",+ "bundle_contents",+ {+ "/products": [+ _page(+ [+ {+ "id": 5,+ "sellables": [+ {"id": 50, "type": "Kit"},+ {"id": 51, "type": "ProductVariant"},+ ],+ },+ {"id": 6, "sellables": [{"id": 60, "type": "ProductVariant"}]},+ {"id": 8, "sellables": [{"id": 80, "type": "Kit"}]},+ ]+ )+ ],+ "/kits/50": [+ _page(+ {+ "id": 50,+ "type": "Kit",+ "contents": [+ {"id": 1, "kit_id": 50, "product_variant_id": 51, "quantity": 2},+ {"id": 2, "kit_id": 50, "product_variant_id": 60, "quantity": 1},+ ],+ }+ )+ ],+ "/kits/80": [_page({"id": 80, "type": "Kit", "contents": []})],+ },+ ["/products", "/kits/50", "/kits/80"],+ [+ {"id": 1, "kit_id": 50, "product_variant_id": 51, "quantity": 2, "product_id": 5},+ {"id": 2, "kit_id": 50, "product_variant_id": 60, "quantity": 1, "product_id": 5},+ ],+ ),+ ]+ )+ def test_fans_out_to_one_request_per_parent_id(+ self,+ _name: str,+ endpoint: str,+ responses: dict[str, list[ScriptedResponse]],+ expected_paths: list[str],+ expected_rows: list[dict[str, Any]],+ ) -> None:+ result = _run(route(responses), endpoint=endpoint)++ assert result.raised is None+ assert result.paths == expected_paths+ # The parent list is paged; the single-object child endpoints take no page params.+ assert result.queries[0]["page_size"] == ("100",)+ assert all("page_size" not in query and "page" not in query for query in result.queries[1:])+ assert result.rows == expected_rows++ def test_parent_list_paginates_before_fanning_out(self) -> None:+ full_orders_page = [{"id": i, "allocations": []} for i in range(99)] + [+ {"id": 99, "allocations": [{"id": 1, "shipment": {"id": 7001}}]}+ ]+ result = _run(+ route(+ {+ "/orders": [+ _page(full_orders_page, headers={"X-Total-Pages-Count": "2"}),+ _page([{"id": 200, "allocations": [{"id": 2, "shipment": {"id": 7002}}]}]),+ ],+ "/shipping/tracking_events/7001": [_page([{"timestamp": "t1", "status": "delivered"}])],+ "/shipping/tracking_events/7002": [_page([{"timestamp": "t2", "status": "delivered"}])],+ }+ ),+ endpoint="shipment_tracking_events",+ )++ assert result.raised is None+ assert [row["shipment_id"] for row in result.rows] == [7001, 7002]+ assert [query.get("page") for query in result.queries if "page_size" in query] == [("1",), ("2",)]++ def test_resume_skips_shipments_already_synced(self) -> None:+ orders = [+ {"id": 1, "allocations": [{"id": 10, "shipment": {"id": 7001}}]},+ {"id": 2, "allocations": [{"id": 20, "shipment": {"id": 7002}}]},+ ]+ result = _run(+ route(+ {+ "/orders": [_page(orders)],+ "/shipping/tracking_events/7002": [_page([{"timestamp": "t2", "status": "delivered"}])],+ }+ ),+ endpoint="shipment_tracking_events",+ resume_state=VeeqoResumeConfig(+ endpoint="shipment_tracking_events",+ fanout_state={"completed": ["/shipping/tracking_events/7001"], "current": None, "child_state": None},+ ),+ )++ assert result.raised is None+ assert result.paths == ["/orders", "/shipping/tracking_events/7002"]+ assert result.rows == [{"timestamp": "t2", "status": "delivered", "shipment_id": 7002, "order_id": 2}]+ assert result.saved_states[-1] == VeeqoResumeConfig(+ endpoint="shipment_tracking_events",+ fanout_state={+ "completed": ["/shipping/tracking_events/7001", "/shipping/tracking_events/7002"],+ "current": None,+ "child_state": None,+ },+ )diff --git a/products/warehouse_sources/backend/temporal/data_imports/sources/veeqo/tests/test_veeqo_source.py b/products/warehouse_sources/backend/temporal/data_imports/sources/veeqo/tests/test_veeqo_source.pyindex ccee8303bc74..5afe8b7a9204 100644--- a/products/warehouse_sources/backend/temporal/data_imports/sources/veeqo/tests/test_veeqo_source.py+++ b/products/warehouse_sources/backend/temporal/data_imports/sources/veeqo/tests/test_veeqo_source.py@@ -1,5 +1,6 @@import requests+from products.warehouse_sources.backend.temporal.data_imports.sources.generated_configs.veeqo import VeeqoSourceConfigfrom products.warehouse_sources.backend.temporal.data_imports.sources.veeqo.source import VeeqoSource@@ -23,3 +24,12 @@ class TestVeeqoSourceNonRetryableErrors:assert any(pattern in error_msg for pattern in patterns), (f"HTTPError message '{error_msg}' did not match any non-retryable pattern")+++class TestVeeqoSourceSchemas:+ def test_fanout_tables_are_opt_in(self) -> None:+ schemas = {schema.name: schema for schema in VeeqoSource().get_schemas(VeeqoSourceConfig(api_key="k"), 1)}++ assert not schemas["shipment_tracking_events"].should_sync_default+ assert not schemas["bundle_contents"].should_sync_default+ assert schemas["orders"].should_sync_defaultdiff --git a/products/warehouse_sources/backend/temporal/data_imports/sources/veeqo/veeqo.py b/products/warehouse_sources/backend/temporal/data_imports/sources/veeqo/veeqo.pyindex f4751209c40e..e610aeb43ee5 100644--- a/products/warehouse_sources/backend/temporal/data_imports/sources/veeqo/veeqo.py+++ b/products/warehouse_sources/backend/temporal/data_imports/sources/veeqo/veeqo.py@@ -13,6 +13,11 @@ carries the token in the ``x-api-key`` header and redacts it from logs anderror messages, and a small paginator extends the framework page-numberpaginator with Veeqo's total-pages header and a short-page stop.+Veeqo has no list endpoints for returns, stock entries, shipments or bundles.+Returns and stock entries are exploded from the order and product records that+embed them; shipment tracking events and bundle contents fan out from those+records to one request per shipment or bundle.+NOTE: these endpoint params were taken from the public API docs and could notbe curl-verified against a live account during implementation (Veeqo API keysmust be enabled by their support team). The pagination/filter handling is@@ -21,6 +26,7 @@ rather than confirmed."""import dataclasses+from collections.abc import Callable, Iterablefrom datetime import UTC, date, datetimefrom typing import Any, Optional@@ -31,10 +37,17 @@ from products.warehouse_sources.backend.temporal.data_imports.sources.common.resRESTAPIConfig,rest_api_resource,)+from products.warehouse_sources.backend.temporal.data_imports.sources.common.rest_source.fanout import (+ build_dependent_resource,+)from products.warehouse_sources.backend.temporal.data_imports.sources.common.rest_source.paginators import (PageNumberPaginator,SinglePagePaginator,)+from products.warehouse_sources.backend.temporal.data_imports.sources.common.rest_source.typing import (+ ClientConfig,+ Endpoint,+)from products.warehouse_sources.backend.temporal.data_imports.sources.common.resumable import ResumableSourceManagerfrom products.warehouse_sources.backend.temporal.data_imports.sources.common.source_helpers import validate_via_probefrom products.warehouse_sources.backend.temporal.data_imports.sources.common.typings import SourceResponse@@ -53,16 +66,19 @@ INCREMENTAL_PARAM_BY_FIELD = {}[email protected] # nosemgrep: prefer-frozen-dataclasses -- pre-existing; new field shifts the backlog finding into diffclass VeeqoResumeConfig:"""Page cursor for resumable list iteration.``page`` is the next page to fetch. ``endpoint`` scopes the state to a singleendpoint so we never replay an orders page number against products.+ Fan-out tables store the ``build_dependent_resource`` checkpoint in+ ``fanout_state`` instead."""endpoint: str- page: int+ page: Optional[int] = None+ fanout_state: Optional[dict[str, Any]] = Noneclass VeeqoPaginator(PageNumberPaginator):@@ -150,6 +166,59 @@ def _build_initial_params(return params+def _order_returns(order: dict[str, Any]) -> list[dict[str, Any]]:+ return [{**item, "order_id": order.get("id")} for item in order.get("returns") or [] if isinstance(item, dict)]+++def _product_stock_entries(product: dict[str, Any]) -> list[dict[str, Any]]:+ return [+ {**entry, "product_id": product.get("id")}+ for sellable in product.get("sellables") or []+ if isinstance(sellable, dict)+ for entry in sellable.get("stock_entries") or []+ if isinstance(entry, dict)+ ]+++def _order_shipments(order: dict[str, Any]) -> list[dict[str, Any]]:+ rows: list[dict[str, Any]] = []+ seen: set[Any] = set()+ for allocation in order.get("allocations") or []:+ shipment = allocation.get("shipment") if isinstance(allocation, dict) else None+ shipment_id = shipment.get("id") if isinstance(shipment, dict) else None+ # Allocations of one order can share a shipment; request its events once.+ if shipment_id is not None and shipment_id not in seen:+ seen.add(shipment_id)+ rows.append({"shipment_id": shipment_id, "order_id": order.get("id")})+ return rows+++def _product_kits(product: dict[str, Any]) -> list[dict[str, Any]]:+ return [+ {"kit_id": sellable["id"], "product_id": product.get("id")}+ for sellable in product.get("sellables") or []+ if isinstance(sellable, dict) and sellable.get("type") == "Kit" and sellable.get("id") is not None+ ]+++# Explodes each record of a `nested` table's path into the table's rows.+_NESTED_ROW_MAPS: dict[str, Callable[[dict[str, Any]], list[dict[str, Any]]]] = {+ "returns": _order_returns,+ "stock_entries": _product_stock_entries,+}++# Derives the ids a fan-out child requests from each parent record.+_FANOUT_PARENT_MAPS: dict[str, Callable[[dict[str, Any]], list[dict[str, Any]]]] = {+ "shipment_tracking_events": _order_shipments,+ "bundle_contents": _product_kits,+}++# `/kits/{id}` returns one bundle object; its rows are the `contents` array.+_FANOUT_CHILD_DATA_SELECTORS: dict[str, str] = {+ "bundle_contents": "contents",+}++def validate_credentials(api_key: str) -> tuple[bool, str | None]:"""Probe ``/warehouses`` — a cheap list call every account can serve.@@ -174,6 +243,30 @@ def validate_credentials(api_key: str) -> tuple[bool, str | None]:return False, f"Veeqo rejected the request (HTTP {status})."+def _source_response(+ endpoint: str,+ config: VeeqoEndpointConfig,+ items: Callable[[], Iterable[Any]],+ column_hints: Optional[dict[str, Any]],+) -> SourceResponse:+ return SourceResponse(+ name=endpoint,+ items=items,+ primary_keys=config.primary_keys,+ partition_count=1,+ partition_size=1,+ partition_mode="datetime" if config.partition_key else None,+ partition_format="month" if config.partition_key else None,+ partition_keys=[config.partition_key] if config.partition_key else None,+ # Veeqo documents no sort param and no ordering guarantee for list+ # endpoints, so declare "desc": the incremental watermark then commits+ # only after a successful sync instead of checkpointing per batch, which+ # is safe whatever order rows actually arrive in.+ sort_mode="desc",+ column_hints=column_hints,+ )++def veeqo_source(api_key: str,endpoint: str,@@ -186,27 +279,70 @@ def veeqo_source() -> SourceResponse:config = VEEQO_ENDPOINTS[endpoint]+ client_config: ClientConfig = {+ "base_url": VEEQO_BASE_URL,+ "headers": {"Accept": "application/json"},+ # api_key auth injects the key into the `x-api-key` header and redacts+ # it from logs and raised error messages.+ "auth": {+ "type": "api_key",+ "api_key": api_key,+ "name": "x-api-key",+ "location": "header",+ },+ # requests preserves the custom x-api-key header when following a+ # redirect, so a redirect response could replay the full-account key+ # to another host — refuse redirects outright.+ "allow_redirects": False,+ }++ resume: Optional[VeeqoResumeConfig] = None+ if resumable_source_manager.can_resume():+ loaded = resumable_source_manager.load_state()+ # Only replay state saved for THIS endpoint.+ if loaded is not None and loaded.endpoint == endpoint:+ resume = loaded++ if config.fanout is not None:+ parent_config = VEEQO_ENDPOINTS[config.fanout.parent_name]++ def save_fanout_checkpoint(state: Optional[dict[str, Any]]) -> None:+ if state:+ resumable_source_manager.save_state(VeeqoResumeConfig(endpoint=endpoint, fanout_state=state))++ child_endpoint_extra: Endpoint = {"paginator": SinglePagePaginator()}+ if endpoint in _FANOUT_CHILD_DATA_SELECTORS:+ child_endpoint_extra["data_selector"] = _FANOUT_CHILD_DATA_SELECTORS[endpoint]++ child = build_dependent_resource(+ endpoint_configs=VEEQO_ENDPOINTS,+ child_endpoint=endpoint,+ fanout=config.fanout,+ client_config=client_config,+ path_format_values={},+ team_id=team_id,+ job_id=job_id,+ db_incremental_field_last_value=None,+ parent_endpoint_extra={+ "data_selector_required": True,+ "paginator": VeeqoPaginator(page_size=parent_config.page_size),+ },+ child_endpoint_extra=child_endpoint_extra,+ parent_data_map=_FANOUT_PARENT_MAPS[endpoint],+ # The parent page size travels in `fanout.parent_params`; the child+ # endpoints are single-object responses that take no page size.+ page_size_param=None,+ resume_hook=save_fanout_checkpoint,+ initial_paginator_state=resume.fanout_state if resume else None,+ )+ return _source_response(endpoint, config, lambda: child, column_hints=None)+params = _build_initial_params(config, should_use_incremental_field, db_incremental_field_last_value, incremental_field)rest_config: RESTAPIConfig = {- "client": {- "base_url": VEEQO_BASE_URL,- "headers": {"Accept": "application/json"},- # api_key auth injects the key into the `x-api-key` header and redacts- # it from logs and raised error messages.- "auth": {- "type": "api_key",- "api_key": api_key,- "name": "x-api-key",- "location": "header",- },- # requests preserves the custom x-api-key header when following a- # redirect, so a redirect response could replay the full-account key- # to another host — refuse redirects outright.- "allow_redirects": False,- },+ "client": client_config,"resource_defaults": {"write_disposition": {"disposition": "merge",@@ -235,11 +371,8 @@ def veeqo_source(}initial_paginator_state: Optional[dict[str, Any]] = None- if resumable_source_manager.can_resume():- resume = resumable_source_manager.load_state()- # Only replay a page number saved for THIS endpoint.- if resume is not None and resume.endpoint == endpoint:- initial_paginator_state = {"page": resume.page}+ if resume is not None and resume.page:+ initial_paginator_state = {"page": resume.page}def save_checkpoint(state: Optional[dict[str, Any]]) -> None:# Persist only when a next page remains; the hook fires AFTER a page is@@ -257,19 +390,7 @@ def veeqo_source(initial_paginator_state=initial_paginator_state,)- return SourceResponse(- name=endpoint,- items=lambda: resource,- primary_keys=["id"],- partition_count=1,- partition_size=1,- partition_mode="datetime" if config.partition_key else None,- partition_format="month" if config.partition_key else None,- partition_keys=[config.partition_key] if config.partition_key else None,- # Veeqo documents no sort param and no ordering guarantee for list- # endpoints, so declare "desc": the incremental watermark then commits- # only after a successful sync instead of checkpointing per batch, which- # is safe whatever order rows actually arrive in.- sort_mode="desc",- column_hints=resource.column_hints,- )+ if config.nested:+ resource.add_map(_NESTED_ROW_MAPS[endpoint])++ return _source_response(endpoint, config, lambda: resource, column_hints=resource.column_hints)