Files
worldmonitor/docs/api/TradeService.openapi.json
Elie Habib 4c11b46be3 feat(trade): add US Treasury customs revenue to Trade Policy panel (#1663)
* feat(trade): add US Treasury customs revenue to Trade Policy panel

US customs duties revenue spiked 4-5x under Trump tariffs (from
$7B/month to $27-31B/month) but the WTO tariff data only goes to
2024. Adds Treasury MTS data showing monthly customs revenue.

- Add GetCustomsRevenue RPC (proto, handler, cache tier)
- Add Treasury fetch to seed-supply-chain-trade.mjs (free API, no key)
- Add Revenue tab to TradePolicyPanel with FYTD YoY comparison
- Fix WTO gate: per-tab gating so Revenue works without WTO key
- Wire bootstrap hydration, health, seed-health tracking

* test(trade): add customs revenue feature tests

22 structural tests covering:
- Handler: raw key mode, empty-cache behavior, correct Redis key
- Seed: Treasury API URL, classification filter, timeout, row
  validation, amount conversion, sort order, seed-meta naming
- Panel: WTO gate fix (per-tab not panel-wide), revenue tab
  defaults when WTO key missing, dynamic FYTD comparison
- Client: no WTO feature gate, bootstrap hydration, type exports

* fix(trade): align FYTD comparison by fiscal month count

Prior FY comparison was filtering by calendar month, which compared
5 months of FY2026 (Oct-Feb) against only 2 months of FY2025
(Jan-Feb), inflating the YoY percentage. Now takes the first N
months of the prior FY matching the current FY month count.

* fix(trade): register treasury_revenue DataSourceId and localize revenue tab

- Add treasury_revenue to DataSourceId union type so freshness
  tracking actually works (was silently ignored)
- Register in data-freshness.ts source config + gap messages
- Add i18n keys: revenue tab label, empty state, unavailable banner
- Update infoTooltip to include Revenue tab description

* fix(trade): complete revenue tab localization

Use t() for all remaining hardcoded strings: footer source labels,
FYTD summary headline, prior-year comparison, and table column
headers. Wire the fytdLabel/vsPriorFy keys that were added but
not used.

* fix(test): update revenue source assertion for localized string
2026-03-15 19:04:23 +04:00

1 line
14 KiB
JSON

{"components":{"schemas":{"CustomsRevenueMonth":{"description":"Monthly US customs duties revenue from Treasury MTS data.","properties":{"calendarMonth":{"format":"int32","type":"integer"},"calendarYear":{"format":"int32","type":"integer"},"fiscalYear":{"format":"int32","type":"integer"},"fytdAmountBillions":{"format":"double","type":"number"},"monthlyAmountBillions":{"format":"double","type":"number"},"recordDate":{"type":"string"}},"type":"object"},"Error":{"description":"Error is returned when a handler encounters an error. It contains a simple error message that the developer can customize.","properties":{"message":{"description":"Error message (e.g., 'user not found', 'database connection failed')","type":"string"}},"type":"object"},"FieldViolation":{"description":"FieldViolation describes a single validation error for a specific field.","properties":{"description":{"description":"Human-readable description of the validation violation (e.g., 'must be a valid email address', 'required field missing')","type":"string"},"field":{"description":"The field path that failed validation (e.g., 'user.email' for nested fields). For header validation, this will be the header name (e.g., 'X-API-Key')","type":"string"}},"required":["field","description"],"type":"object"},"GetCustomsRevenueRequest":{"type":"object"},"GetCustomsRevenueResponse":{"properties":{"fetchedAt":{"type":"string"},"months":{"items":{"$ref":"#/components/schemas/CustomsRevenueMonth"},"type":"array"},"upstreamUnavailable":{"type":"boolean"}},"type":"object"},"GetTariffTrendsRequest":{"description":"Request for tariff timeseries data.","properties":{"partnerCountry":{"description":"WTO member code of partner country (e.g. \"156\" = China).","type":"string"},"productSector":{"description":"Product sector filter (HS chapter). Empty = aggregate.","type":"string"},"reportingCountry":{"description":"WTO member code of reporting country (e.g. \"840\" = US).","type":"string"},"years":{"description":"Number of years to look back (default 10, max 30).","format":"int32","type":"integer"}},"type":"object"},"GetTariffTrendsResponse":{"description":"Response containing tariff trend datapoints.","properties":{"datapoints":{"items":{"$ref":"#/components/schemas/TariffDataPoint"},"type":"array"},"fetchedAt":{"description":"ISO 8601 timestamp when data was fetched from WTO.","type":"string"},"upstreamUnavailable":{"description":"True if upstream fetch failed and results may be stale/empty.","type":"boolean"}},"type":"object"},"GetTradeBarriersRequest":{"description":"Request for SPS/TBT trade barrier notifications.","properties":{"countries":{"items":{"description":"WTO member codes to filter by. Empty = all.","type":"string"},"type":"array"},"limit":{"description":"Max results to return (server caps at 100).","format":"int32","type":"integer"},"measureType":{"description":"Filter by measure type: \"SPS\", \"TBT\", or empty for both.","type":"string"}},"type":"object"},"GetTradeBarriersResponse":{"description":"Response containing trade barrier notifications.","properties":{"barriers":{"items":{"$ref":"#/components/schemas/TradeBarrier"},"type":"array"},"fetchedAt":{"description":"ISO 8601 timestamp when data was fetched from WTO.","type":"string"},"upstreamUnavailable":{"description":"True if upstream fetch failed and results may be stale/empty.","type":"boolean"}},"type":"object"},"GetTradeFlowsRequest":{"description":"Request for bilateral trade flow data.","properties":{"partnerCountry":{"description":"WTO member code of partner country.","type":"string"},"reportingCountry":{"description":"WTO member code of reporting country.","type":"string"},"years":{"description":"Number of years to look back (default 10, max 30).","format":"int32","type":"integer"}},"type":"object"},"GetTradeFlowsResponse":{"description":"Response containing trade flow records.","properties":{"fetchedAt":{"description":"ISO 8601 timestamp when data was fetched from WTO.","type":"string"},"flows":{"items":{"$ref":"#/components/schemas/TradeFlowRecord"},"type":"array"},"upstreamUnavailable":{"description":"True if upstream fetch failed and results may be stale/empty.","type":"boolean"}},"type":"object"},"GetTradeRestrictionsRequest":{"description":"Request for quantitative restriction data.","properties":{"countries":{"items":{"description":"WTO member codes to filter by. Empty = all.","type":"string"},"type":"array"},"limit":{"description":"Max results to return (server caps at 100).","format":"int32","type":"integer"}},"type":"object"},"GetTradeRestrictionsResponse":{"description":"Response containing trade restrictions and fetch metadata.","properties":{"fetchedAt":{"description":"ISO 8601 timestamp when data was fetched from WTO.","type":"string"},"restrictions":{"items":{"$ref":"#/components/schemas/TradeRestriction"},"type":"array"},"upstreamUnavailable":{"description":"True if upstream fetch failed and results may be stale/empty.","type":"boolean"}},"type":"object"},"TariffDataPoint":{"description":"Single tariff data point for a reporter-partner-product combination.","properties":{"boundRate":{"description":"WTO bound tariff rate (percentage).","format":"double","type":"number"},"indicatorCode":{"description":"WTO indicator code used for this datapoint.","type":"string"},"partnerCountry":{"description":"WTO member code of partner country.","type":"string"},"productSector":{"description":"Product sector or HS chapter.","type":"string"},"reportingCountry":{"description":"WTO member code of reporting country.","type":"string"},"tariffRate":{"description":"Applied MFN tariff rate (percentage).","format":"double","type":"number"},"year":{"description":"Year of observation.","format":"int32","type":"integer"}},"type":"object"},"TradeBarrier":{"description":"SPS or TBT trade barrier notification.","properties":{"dateDistributed":{"description":"ISO 8601 date when notification was distributed.","type":"string"},"id":{"description":"Unique barrier notification identifier.","type":"string"},"measureType":{"description":"Measure classification: \"SPS\" or \"TBT\".","type":"string"},"notifyingCountry":{"description":"Country that notified the measure.","type":"string"},"objective":{"description":"Stated objective of the measure.","type":"string"},"productDescription":{"description":"Product description or affected goods.","type":"string"},"sourceUrl":{"description":"WTO source document URL (must be http/https protocol).","type":"string"},"status":{"description":"Status of the notification.","type":"string"},"title":{"description":"Title of the notification.","type":"string"}},"type":"object"},"TradeFlowRecord":{"description":"Bilateral trade flow record for a reporting-partner pair.","properties":{"exportValueUsd":{"description":"Merchandise export value in millions USD.","format":"double","type":"number"},"importValueUsd":{"description":"Merchandise import value in millions USD.","format":"double","type":"number"},"partnerCountry":{"description":"WTO member code of partner country.","type":"string"},"productSector":{"description":"Product sector or HS chapter.","type":"string"},"reportingCountry":{"description":"WTO member code of reporting country.","type":"string"},"year":{"description":"Year of observation.","format":"int32","type":"integer"},"yoyExportChange":{"description":"Year-over-year export change (percentage).","format":"double","type":"number"},"yoyImportChange":{"description":"Year-over-year import change (percentage).","format":"double","type":"number"}},"type":"object"},"TradeRestriction":{"description":"Quantitative restriction or export control measure notified to WTO.","properties":{"affectedCountry":{"description":"Country affected by the restriction.","type":"string"},"description":{"description":"Human-readable description of the measure.","type":"string"},"id":{"description":"Unique restriction identifier from WTO.","type":"string"},"measureType":{"description":"Measure classification: \"QR\", \"EXPORT_BAN\", \"IMPORT_BAN\", \"LICENSING\".","type":"string"},"notifiedAt":{"description":"ISO 8601 date when measure was notified.","type":"string"},"productSector":{"description":"Product sector or HS chapter description.","type":"string"},"reportingCountry":{"description":"ISO 3166-1 alpha-3 or WTO member code of reporting country.","type":"string"},"sourceUrl":{"description":"WTO source document URL (must be http/https protocol).","type":"string"},"status":{"description":"Current status: \"IN_FORCE\", \"TERMINATED\", \"NOTIFIED\".","type":"string"}},"type":"object"},"ValidationError":{"description":"ValidationError is returned when request validation fails. It contains a list of field violations describing what went wrong.","properties":{"violations":{"description":"List of validation violations","items":{"$ref":"#/components/schemas/FieldViolation"},"type":"array"}},"required":["violations"],"type":"object"}}},"info":{"title":"TradeService API","version":"1.0.0"},"openapi":"3.1.0","paths":{"/api/trade/v1/get-customs-revenue":{"get":{"description":"Get US customs duties revenue (Treasury MTS data, seeded by Railway).","operationId":"GetCustomsRevenue","responses":{"200":{"content":{"application/json":{"schema":{"$ref":"#/components/schemas/GetCustomsRevenueResponse"}}},"description":"Successful response"},"400":{"content":{"application/json":{"schema":{"$ref":"#/components/schemas/ValidationError"}}},"description":"Validation error"},"default":{"content":{"application/json":{"schema":{"$ref":"#/components/schemas/Error"}}},"description":"Error response"}},"summary":"GetCustomsRevenue","tags":["TradeService"]}},"/api/trade/v1/get-tariff-trends":{"get":{"description":"Get tariff rate timeseries for a country pair.","operationId":"GetTariffTrends","parameters":[{"description":"WTO member code of reporting country (e.g. \"840\" = US).","in":"query","name":"reporting_country","required":false,"schema":{"type":"string"}},{"description":"WTO member code of partner country (e.g. \"156\" = China).","in":"query","name":"partner_country","required":false,"schema":{"type":"string"}},{"description":"Product sector filter (HS chapter). Empty = aggregate.","in":"query","name":"product_sector","required":false,"schema":{"type":"string"}},{"description":"Number of years to look back (default 10, max 30).","in":"query","name":"years","required":false,"schema":{"format":"int32","type":"integer"}}],"responses":{"200":{"content":{"application/json":{"schema":{"$ref":"#/components/schemas/GetTariffTrendsResponse"}}},"description":"Successful response"},"400":{"content":{"application/json":{"schema":{"$ref":"#/components/schemas/ValidationError"}}},"description":"Validation error"},"default":{"content":{"application/json":{"schema":{"$ref":"#/components/schemas/Error"}}},"description":"Error response"}},"summary":"GetTariffTrends","tags":["TradeService"]}},"/api/trade/v1/get-trade-barriers":{"get":{"description":"Get SPS/TBT barrier notifications.","operationId":"GetTradeBarriers","parameters":[{"description":"WTO member codes to filter by. Empty = all.","in":"query","name":"countries","required":false,"schema":{"type":"string"}},{"description":"Filter by measure type: \"SPS\", \"TBT\", or empty for both.","in":"query","name":"measure_type","required":false,"schema":{"type":"string"}},{"description":"Max results to return (server caps at 100).","in":"query","name":"limit","required":false,"schema":{"format":"int32","type":"integer"}}],"responses":{"200":{"content":{"application/json":{"schema":{"$ref":"#/components/schemas/GetTradeBarriersResponse"}}},"description":"Successful response"},"400":{"content":{"application/json":{"schema":{"$ref":"#/components/schemas/ValidationError"}}},"description":"Validation error"},"default":{"content":{"application/json":{"schema":{"$ref":"#/components/schemas/Error"}}},"description":"Error response"}},"summary":"GetTradeBarriers","tags":["TradeService"]}},"/api/trade/v1/get-trade-flows":{"get":{"description":"Get bilateral merchandise trade flows.","operationId":"GetTradeFlows","parameters":[{"description":"WTO member code of reporting country.","in":"query","name":"reporting_country","required":false,"schema":{"type":"string"}},{"description":"WTO member code of partner country.","in":"query","name":"partner_country","required":false,"schema":{"type":"string"}},{"description":"Number of years to look back (default 10, max 30).","in":"query","name":"years","required":false,"schema":{"format":"int32","type":"integer"}}],"responses":{"200":{"content":{"application/json":{"schema":{"$ref":"#/components/schemas/GetTradeFlowsResponse"}}},"description":"Successful response"},"400":{"content":{"application/json":{"schema":{"$ref":"#/components/schemas/ValidationError"}}},"description":"Validation error"},"default":{"content":{"application/json":{"schema":{"$ref":"#/components/schemas/Error"}}},"description":"Error response"}},"summary":"GetTradeFlows","tags":["TradeService"]}},"/api/trade/v1/get-trade-restrictions":{"get":{"description":"Get quantitative restrictions and export controls.","operationId":"GetTradeRestrictions","parameters":[{"description":"WTO member codes to filter by. Empty = all.","in":"query","name":"countries","required":false,"schema":{"type":"string"}},{"description":"Max results to return (server caps at 100).","in":"query","name":"limit","required":false,"schema":{"format":"int32","type":"integer"}}],"responses":{"200":{"content":{"application/json":{"schema":{"$ref":"#/components/schemas/GetTradeRestrictionsResponse"}}},"description":"Successful response"},"400":{"content":{"application/json":{"schema":{"$ref":"#/components/schemas/ValidationError"}}},"description":"Validation error"},"default":{"content":{"application/json":{"schema":{"$ref":"#/components/schemas/Error"}}},"description":"Error response"}},"summary":"GetTradeRestrictions","tags":["TradeService"]}}}}