Skip to content

: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.

feat(warehouse-sources): add easypromos prize inventory table (#106632)

Tom Owers930efb615214
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.md
index ac156c205a27..016b12e56ce5 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
@@ -2758,13 +2758,13 @@ Note: Diffed against the 45 /docs/\* pages in docs.easypost.com/sitemap.xml and
## Easypromos — gaps
-Today (9): `coin_transactions`, `organizing_brands`, `participations`, `points_of_sale`, `prizes`, `promotions`, `rankings`, `stages`, `users`
+Today (10): `coin_transactions`, `organizing_brands`, `participations`, `points_of_sale`, `prize_inventory`, `prizes`, `promotions`, `rankings`, `stages`, `users`
Diffed against: <https://easypromos-apiref.redoc.ly/>
-- [ ] `GET /prizes/{promotion_id}/users/{user_id} (GetUserPrizesByPromotion)` — prize awards linking users to the prizes they won - the winner fact table; `prizes` today is only the prize catalog (high)
-- [ ] `GET /prizes/inventory/{promotion_id} (GetPrizeInventoryByPromotion)` — per-prize stock and code inventory, needed for redemption/remaining-stock reporting (medium)
-- [ ] `GET /coins/{promotion_id}/users/{user_id} (GetUserBalanceVirtualCoin)` — current virtual coin balance per user; largely derivable from coin_transactions but avoids replaying the ledger (low)
+- [ ] `GET /prizes/{promotion_id}/users/{user_id} (GetUserPrizesByPromotion)` — prize awards linking users to the prizes they won - the winner fact table; `prizes` today is only the prize catalog (high). Skipped: the rationale is wrong. `prizes` already syncs `GET /prizes/{promotion_id}`, documented as "Get the list of all assigned prizes and their winners", and its rows already carry `user_id`, `stage_id`, `participation_id`, `created`, `code` and the embedded `prize_type`. The per-user route returns the same award objects filtered to one user and minus the embedded `user`, so it is a strict subset that would need a second fan-out level over every participant.
+- [x] `GET /prizes/inventory/{promotion_id} (GetPrizeInventoryByPromotion)` — per-prize stock and code inventory, needed for redemption/remaining-stock reporting (medium) — added as `prize_inventory`
+- [ ] `GET /coins/{promotion_id}/users/{user_id} (GetUserBalanceVirtualCoin)` — current virtual coin balance per user; largely derivable from coin_transactions but avoids replaying the ledger (low). Skipped: the route is keyed on a single `user_id` and the API publishes no promotion-wide balances collection, so the table costs one request per participant per sync with no server-side filter to bound it. The documented transaction endpoint does carry a running `balance`, but `coin_transactions` does not supply it today: the endpoint config points at `/coins/{promotion_id}`, which the reference documents as PUT-only, and on the documented `GET /coin_transactions/{promotion_id}` the transaction is nested under `items[].transaction`.
Note: The spec has only 35 operations and everything is promotion-scoped (the source already fans out per promotion_id). Remaining uncovered operations are write paths (participate, register, segment assignment, coin transaction creation) or single-request helpers (autologin, login token, check_requirement, validate_code, remaining participations) - none are warehouse tables.
diff --git a/products/warehouse_sources/backend/temporal/data_imports/sources/easypromos/canonical_descriptions.py b/products/warehouse_sources/backend/temporal/data_imports/sources/easypromos/canonical_descriptions.py
index c27269fe6e2f..24e2125a46ee 100644
--- a/products/warehouse_sources/backend/temporal/data_imports/sources/easypromos/canonical_descriptions.py
+++ b/products/warehouse_sources/backend/temporal/data_imports/sources/easypromos/canonical_descriptions.py
@@ -61,6 +61,22 @@ CANONICAL_DESCRIPTIONS: CanonicalDescriptions = {
"created": "Date and time the prize was assigned. ISO-8601 in UTC.",
},
},
+ "prize_inventory": {
+ "description": "Prize types defined in a promotion, with the total units available and the units already awarded. Unlike `prizes`, a prize type nobody has won yet still appears here.",
+ "docs_url": DOCS_BASE,
+ "columns": {
+ "id": "Unique identifier of the prize type within its promotion.",
+ "promotion_id": "Identifier of the promotion this prize type belongs to (added by PostHog during sync).",
+ "name": "Name of the prize type.",
+ "ref": "Reference code the organizer gave the prize type.",
+ "description": "Description of the prize type.",
+ "assignation_type": "How units of this prize type are assigned to winners.",
+ "qty": "Total units of this prize type the organizer configured, not the units remaining. The value 5000010 means unlimited.",
+ "given": "Number of units of this prize type already awarded.",
+ "image": "URL of the prize type image.",
+ "instructions": "Instructions shown to the winner for claiming the prize.",
+ },
+ },
"coin_transactions": {
"description": "Virtual coin transactions in a promotion — each records an amount, timestamp, coin type and the user performing the transaction.",
"docs_url": DOCS_BASE,
diff --git a/products/warehouse_sources/backend/temporal/data_imports/sources/easypromos/easypromos.py b/products/warehouse_sources/backend/temporal/data_imports/sources/easypromos/easypromos.py
index 49926332ce4c..e6a7dfe20e7a 100644
--- a/products/warehouse_sources/backend/temporal/data_imports/sources/easypromos/easypromos.py
+++ b/products/warehouse_sources/backend/temporal/data_imports/sources/easypromos/easypromos.py
@@ -8,7 +8,9 @@ from products.warehouse_sources.backend.temporal.data_imports.sources.common.res
rest_api_resources,
)
from products.warehouse_sources.backend.temporal.data_imports.sources.common.rest_source.paginators import (
+ BasePaginator,
JSONResponseCursorPaginator,
+ SinglePagePaginator,
)
from products.warehouse_sources.backend.temporal.data_imports.sources.common.rest_source.typing import (
ClientConfig,
@@ -68,6 +70,10 @@ def _cursor_paginator() -> JSONResponseCursorPaginator:
return JSONResponseCursorPaginator(cursor_path=_CURSOR_PATH, cursor_param=_CURSOR_PARAM)
+def _paginator(endpoint_config: EasypromosEndpointConfig) -> BasePaginator:
+ return _cursor_paginator() if endpoint_config.paginated else SinglePagePaginator()
+
+
def _inject_promotion_id(row: dict[str, Any]) -> dict[str, Any]:
if _PARENT_ID_KEY in row:
row["promotion_id"] = row.pop(_PARENT_ID_KEY)
@@ -146,7 +152,7 @@ def _fan_out_resource(
"promotion_id": {"type": "resolve", "resource": "promotions", "field": "id"},
},
"data_selector": _DATA_SELECTOR,
- "paginator": _cursor_paginator(),
+ "paginator": _paginator(endpoint_config),
},
"table_format": "delta",
}
diff --git a/products/warehouse_sources/backend/temporal/data_imports/sources/easypromos/settings.py b/products/warehouse_sources/backend/temporal/data_imports/sources/easypromos/settings.py
index 918ce0ddf9cf..6fde9cef7cb8 100644
--- a/products/warehouse_sources/backend/temporal/data_imports/sources/easypromos/settings.py
+++ b/products/warehouse_sources/backend/temporal/data_imports/sources/easypromos/settings.py
@@ -1,10 +1,12 @@
-from dataclasses import dataclass, field
+from dataclasses import field
from typing import Optional
+from posthog.dataclasses import frozen
+
from products.warehouse_sources.backend.types import IncrementalField
-@dataclass
+@frozen
class EasypromosEndpointConfig:
name: str
# Path under /v2. Fan-out children use a `{promotion_id}` placeholder filled per parent
@@ -24,6 +26,9 @@ class EasypromosEndpointConfig:
fan_out_over_promotions: bool = False
# Whether the table is selected for sync by default in the wizard.
should_sync_default: bool = True
+ # Whether the endpoint returns the `paging` envelope. A few endpoints return the whole
+ # collection in one response with no `paging` object at all.
+ paginated: bool = True
# Easypromos exposes no server-side updated-since filter — only `order=created_asc|created_desc`
# with no `created_gte`-style cutoff — so every endpoint is full refresh and advertises no
# incremental fields. Kept as an explicit (empty) field for parity with other sources.
@@ -76,6 +81,18 @@ EASYPROMOS_ENDPOINTS: dict[str, EasypromosEndpointConfig] = {
partition_key="created",
fan_out_over_promotions=True,
),
+ # GetPrizeInventoryByPromotion. The prize types defined in a promotion, each with `qty` (total
+ # units) and `given` (units already awarded) — the stock figures behind remaining-stock and
+ # redemption reporting. Distinct from `prizes`, which holds one row per awarded prize: a prize
+ # type nobody has won yet appears here and nowhere else. The response carries no `paging`
+ # object, so it is a single page.
+ "prize_inventory": EasypromosEndpointConfig(
+ name="prize_inventory",
+ path="/prizes/inventory/{promotion_id}",
+ primary_keys=["promotion_id", "id"],
+ fan_out_over_promotions=True,
+ paginated=False,
+ ),
# GetPromotionVirtualCoinTransactions. The transaction object carries an `id`; its timestamp
# field name isn't confirmed against a live account, so no partition key until verified.
"coin_transactions": EasypromosEndpointConfig(
diff --git a/products/warehouse_sources/backend/temporal/data_imports/sources/easypromos/tests/test_easypromos.py b/products/warehouse_sources/backend/temporal/data_imports/sources/easypromos/tests/test_easypromos.py
index 23c2bbbd9294..a6757097da42 100644
--- a/products/warehouse_sources/backend/temporal/data_imports/sources/easypromos/tests/test_easypromos.py
+++ b/products/warehouse_sources/backend/temporal/data_imports/sources/easypromos/tests/test_easypromos.py
@@ -207,6 +207,38 @@ class TestFanOut:
assert rows == [{"id": 9, "promotion_id": 20}, {"id": 1, "promotion_id": 30}]
assert (_url("/users/10"), None) not in session.requests
+ @mock.patch(CLIENT_SESSION_PATCH)
+ def test_prize_inventory_reads_a_body_without_a_paging_envelope(self, mock_session) -> None:
+ # /prizes/inventory/{promotion_id} returns the whole prize-type catalog with no `paging`
+ # key at all, unlike every other Easypromos list endpoint.
+ inventory_url = _url("/prizes/inventory/10")
+ session = _FakeSession(
+ {
+ (PROMOS_URL, None): _body([{"id": 10}], None),
+ (inventory_url, None): {"items": [{"id": 1, "name": "Voucher", "qty": 5, "given": 2}]},
+ }
+ )
+ mock_session.return_value = session
+ rows = _rows("prize_inventory", _make_manager())
+ assert rows == [{"id": 1, "name": "Voucher", "qty": 5, "given": 2, "promotion_id": 10}]
+ assert session.requests == [(PROMOS_URL, None), (inventory_url, None)]
+
+ @mock.patch(CLIENT_SESSION_PATCH)
+ def test_unpaginated_endpoint_does_not_follow_a_cursor(self, mock_session) -> None:
+ # An endpoint declared unpaginated must stop after one request even when the response does
+ # carry a next cursor — following it would re-read the same catalog forever.
+ inventory_url = _url("/prizes/inventory/10")
+ session = _FakeSession(
+ {
+ (PROMOS_URL, None): _body([{"id": 10}], None),
+ (inventory_url, None): _body([{"id": 1}], 7),
+ }
+ )
+ mock_session.return_value = session
+ rows = _rows("prize_inventory", _make_manager())
+ assert rows == [{"id": 1, "promotion_id": 10}]
+ assert (inventory_url, 7) not in session.requests
+
@mock.patch(CLIENT_SESSION_PATCH)
def test_checkpoint_records_fanout_progress(self, mock_session) -> None:
mock_session.return_value = _FakeSession(