shop: remove merchants directory endpoint usage (#shop)
- Commit
7bc6d7e7454875761516728ce84e4fb97a06a872- Author
- Vayun Mathur <[email protected]>
- When
- 2026-11-09 03:01 UTC (27 days ago)
- Parents
982f7b9
The public GET /shop/v1/merchants bulk directory endpoint is gone server-side. Drop the client call and resolve merchant links from the raw link host instead of the directory listing. - ShopBackend/ShopHttpBackend: remove listMerchants. - ShopViewModel.openLink: scope by link host directly; remove the cached directory lookup (merchantFor). - ShopDtos: remove ShopMerchant/ShopMerchantsResponse and mapper; delete the now-unreferenced MerchantListing model. - ShopBackendTest: drop the directory decode test. - generate_merchant_links.py: fetch the server's own upstream (https://ucplist.ai/api/listings?category=merchants, bare JSON array; host from ucpEndpoint/url, standing from ucpStatus) instead of the removed endpoint.
Diff
scripts/shop/generate_merchant_links.py
diff --git a/scripts/shop/generate_merchant_links.py b/scripts/shop/generate_merchant_links.pyindex 401cf9269b..3fbe629640 100644--- a/scripts/shop/generate_merchant_links.py+++ b/scripts/shop/generate_merchant_links.py@@ -1,10 +1,15 @@ #!/usr/bin/env python3-"""Regenerate the Shop app's merchant link intent-filter from the live directory.+"""Regenerate the Shop app's merchant link intent-filter from the upstream directory. Android only lets an app become the default handler for web links whose hosts are declared in the manifest. Merchant sites can't host our assetlinks.json, so the filter is unverified and users approve it once in "Open by default". +Source: the server's own upstream merchant directory (UCPList) — the same feed+the server merges for search-time merchant matching. It returns a bare JSON+array of listing objects; the merchant host is derived from each listing's+`ucpEndpoint` (falling back to `url`), and `ucpStatus` names its standing.+ Rerun before each release: python3 scripts/shop/generate_merchant_links.py """ @@ -12,9 +17,10 @@ import json import pathlib import re import sys+import urllib.parse import urllib.request -DIRECTORY_URL = "https://api.maproj.org/shop/v1/merchants"+DIRECTORY_URL = "https://ucplist.ai/api/listings?category=merchants" MANIFEST = pathlib.Path(__file__).resolve().parents[2] / "shop/src/main/AndroidManifest.xml" BEGIN = "<!-- BEGIN MERCHANT LINKS (generated by scripts/shop/generate_merchant_links.py) -->" END = "<!-- END MERCHANT LINKS -->"@@ -27,14 +33,20 @@ def fetch_domains() -> list[str]: DIRECTORY_URL, headers={"Accept": "application/json", "User-Agent": "ModernApps-build/1.0"} ) with urllib.request.urlopen(request, timeout=60) as response:- merchants = json.load(response)["merchants"]+ listings = json.load(response)+ if isinstance(listings, dict):+ listings = listings.get("merchants", []) hosts = set()- for merchant in merchants:+ for merchant in listings:+ if not isinstance(merchant, dict):+ continue # Only the curated UCPList entries ("live"/"announced"); the ~10k directly verified # seed stores ("verified") would make Android's open-by-default list unusable.- if merchant.get("directoryStatus") == "verified":+ if merchant.get("ucpStatus") == "verified": continue- domain = str(merchant.get("domain", "")).strip().lower()+ endpoint = str(merchant.get("ucpEndpoint") or merchant.get("url") or "")+ domain = urllib.parse.urlparse(endpoint).hostname or ""+ domain = domain.strip().lower() if not HOST.match(domain): continue bare = domain.removeprefix("www.")
shop/src/main/java/com/vayunmathur/shop/data/MerchantListing.kt
diff --git a/shop/src/main/java/com/vayunmathur/shop/data/MerchantListing.kt b/shop/src/main/java/com/vayunmathur/shop/data/MerchantListing.ktdeleted file mode 100644index f8be39c47f..0000000000--- a/shop/src/main/java/com/vayunmathur/shop/data/MerchantListing.kt+++ /dev/null@@ -1,12 +0,0 @@-package com.vayunmathur.shop.data--/** Directory metadata is a discovery lead, never merchant access or payment authorization. */-data class MerchantListing(- val id: String,- val name: String,- val domain: String,- val siteUrl: String,- val description: String = "",- val directoryStatus: String = "unknown",- val directoryVerifiedAt: String? = null,-)
shop/src/main/java/com/vayunmathur/shop/network/ShopBackend.kt
diff --git a/shop/src/main/java/com/vayunmathur/shop/network/ShopBackend.kt b/shop/src/main/java/com/vayunmathur/shop/network/ShopBackend.ktindex 4a13fb8e14..c892be3673 100644--- a/shop/src/main/java/com/vayunmathur/shop/network/ShopBackend.kt+++ b/shop/src/main/java/com/vayunmathur/shop/network/ShopBackend.kt@@ -4,7 +4,6 @@ import com.vayunmathur.library.network.NetworkClient import com.vayunmathur.shop.data.CartLine import com.vayunmathur.shop.data.CatalogOptionSelection import com.vayunmathur.shop.data.CheckoutInputs-import com.vayunmathur.shop.data.MerchantListing import com.vayunmathur.shop.data.OrderStatusQuery import com.vayunmathur.shop.data.OrderTracking import com.vayunmathur.shop.data.UcpCheckout@@ -43,7 +42,6 @@ interface ShopBackend { suspend fun createCheckout(shop: String, lines: List<CartLine>, inputs: CheckoutInputs, idempotencyKey: String): Result<UcpCheckout> suspend fun getCheckout(shop: String, sessionId: String): Result<UcpCheckout> suspend fun updateCheckout(shop: String, sessionId: String, lines: List<CartLine>, inputs: CheckoutInputs, idempotencyKey: String): Result<UcpCheckout>- suspend fun listMerchants(refresh: Boolean = false): Result<List<MerchantListing>> /** Latest tracking per token; tokens without a merchant update yet are omitted. */ suspend fun orderStatus(orders: List<OrderStatusQuery>): Result<Map<String, OrderTracking>> }@@ -142,12 +140,6 @@ internal object ShopHttpBackend : ShopBackend { put("$BASE/checkout-sessions", json.encodeToString(request)).parseSession() } - override suspend fun listMerchants(refresh: Boolean): Result<List<MerchantListing>> =- catching {- val url = "$BASE/merchants" + if (refresh) "?refresh=true" else ""- get(url).parse<ShopMerchantsResponse>().merchants.map { it.toModel() }- }- override suspend fun orderStatus(orders: List<OrderStatusQuery>): Result<Map<String, OrderTracking>> = catching { require(
shop/src/main/java/com/vayunmathur/shop/network/ShopDtos.kt
diff --git a/shop/src/main/java/com/vayunmathur/shop/network/ShopDtos.kt b/shop/src/main/java/com/vayunmathur/shop/network/ShopDtos.ktindex 2bd1020d83..34d9c39670 100644--- a/shop/src/main/java/com/vayunmathur/shop/network/ShopDtos.kt+++ b/shop/src/main/java/com/vayunmathur/shop/network/ShopDtos.kt@@ -3,7 +3,6 @@ package com.vayunmathur.shop.network import com.vayunmathur.shop.data.CartLine import com.vayunmathur.shop.data.CatalogOptionSelection import com.vayunmathur.shop.data.CheckoutInputs-import com.vayunmathur.shop.data.MerchantListing import com.vayunmathur.shop.data.Money import com.vayunmathur.shop.data.OrderStatusQuery import com.vayunmathur.shop.data.OrderTracking@@ -201,17 +200,6 @@ data class ShopProduct( val storeName: String = "", ) -@Serializable-data class ShopMerchant(- val id: String = "",- val name: String = "",- val domain: String = "",- val siteUrl: String = "",- val description: String = "",- val directoryStatus: String = "unknown",- val directoryVerifiedAt: String? = null,-)- @Serializable data class ShopSearchResponse( val products: List<ShopProduct> = emptyList(),@@ -222,11 +210,6 @@ data class ShopProductResponse( val product: ShopProduct = ShopProduct(), ) -@Serializable-data class ShopMerchantsResponse(- val merchants: List<ShopMerchant> = emptyList(),-)- @Serializable data class ShopErrorBody( val code: String = "",@@ -273,16 +256,6 @@ internal fun ShopProduct.toModel(): UcpProduct = UcpProduct( storeName = storeName, ) -internal fun ShopMerchant.toModel(): MerchantListing = MerchantListing(- id = id,- name = name,- domain = domain,- siteUrl = siteUrl,- description = description,- directoryStatus = directoryStatus,- directoryVerifiedAt = directoryVerifiedAt,-)- internal fun ShopCheckoutSession.toModel(): UcpCheckout = UcpCheckout( checkoutId = checkoutId, status = status,
shop/src/main/java/com/vayunmathur/shop/platform/ShopViewModel.kt
diff --git a/shop/src/main/java/com/vayunmathur/shop/platform/ShopViewModel.kt b/shop/src/main/java/com/vayunmathur/shop/platform/ShopViewModel.ktindex 0b9266943e..64d7cb4847 100644--- a/shop/src/main/java/com/vayunmathur/shop/platform/ShopViewModel.kt+++ b/shop/src/main/java/com/vayunmathur/shop/platform/ShopViewModel.kt@@ -13,7 +13,6 @@ import com.vayunmathur.shop.data.NativeCheckoutState import com.vayunmathur.shop.domain.NativeCheckoutCoordinator import com.vayunmathur.shop.domain.PendingCheckoutSink import com.vayunmathur.shop.data.CartLine-import com.vayunmathur.shop.data.MerchantListing import com.vayunmathur.shop.data.OrderStore import com.vayunmathur.shop.data.EmbeddedCheckoutRequest import com.vayunmathur.shop.data.Money@@ -57,7 +56,6 @@ class ShopViewModel( private set var linkedProducts by mutableStateOf<List<UcpProduct>>(emptyList()) private set- private var merchants: List<MerchantListing>? = null var launchLinkHandled = false /** Held in memory only: the URL carries a merchant session key. */ var embeddedCheckout by mutableStateOf<EmbeddedCheckoutRequest?>(null)@@ -164,9 +162,10 @@ class ShopViewModel( val link = MerchantLinks.parse(url) ?: return viewModelScope.launch { AppInit.awaitReady()- val merchant = merchantFor(link.host)- val domain = merchant?.domain ?: link.host- val name = merchant?.name?.takeIf { it.isNotBlank() } ?: domain+ // Raw-host fallback: the link host itself scopes the search. The+ // former merchant-directory lookup is gone with the endpoint.+ val domain = link.host+ val name = domain when (link) { is MerchantLink.Product -> backend.getProductByHandle(domain, link.handle).fold( onSuccess = { product ->@@ -197,12 +196,6 @@ class ShopViewModel( if (scopedQuery.isNotBlank()) search() } - private suspend fun merchantFor(host: String): MerchantListing? {- val list = merchants ?: backend.listMerchants().getOrNull()?.also { merchants = it } ?: return null- val bare = host.removePrefix("www.")- return list.firstOrNull { it.domain == host } ?: list.firstOrNull { it.domain.removePrefix("www.") == bare }- }- fun loadCart(context: Context) { viewModelScope.launch { cart = ShopCartStore.getAll(context) } }
shop/src/test/java/com/vayunmathur/shop/network/ShopBackendTest.kt
diff --git a/shop/src/test/java/com/vayunmathur/shop/network/ShopBackendTest.kt b/shop/src/test/java/com/vayunmathur/shop/network/ShopBackendTest.ktindex 168a5c2679..67cb1a50a0 100644--- a/shop/src/test/java/com/vayunmathur/shop/network/ShopBackendTest.kt+++ b/shop/src/test/java/com/vayunmathur/shop/network/ShopBackendTest.kt@@ -140,17 +140,6 @@ class ShopBackendTest { return@runBlocking } - @Test fun merchantsDecodeDirectory() = runBlocking {- val body = """{"merchants": [{"id": "m1", "name": "Trail Store", "domain": "shop.example.com",- "siteUrl": "https://shop.example.com", "description": "Shoes",- "directoryStatus": "live", "directoryVerifiedAt": "2026-10-01"}]}"""- stub(ok(body))- val merchants = ShopHttpBackend.listMerchants().getOrThrow()- assertEquals("shop.example.com", merchants.single().domain)- assertEquals("live", merchants.single().directoryStatus)- return@runBlocking- }- @Test fun errorEnvelopeMapsToUcpErrors() = runBlocking { suspend fun errorFor(code: String, status: Int): UcpError? { val body = ShopHttpBackend.json.encodeToString(ShopErrorEnvelope(ShopErrorBody(code, "m", null)))