Repository navigation
feat(catalog): read a brand's Google Merchant Center products and item issues (00296, #1270 part 1) - #1582
Conversation
…m issues (00296, ansvisor#1270 part 1) A Merchant Center account becomes a catalog source, read with the workspace's own Google sign-in through Composio (like Search Console and Analytics), so the token never reaches us. Calls go to the Merchant API v1 through Composio's proxy. - Connector merchant_center: lists the accounts the sign-in opens (plus an advanced account's sub-accounts), checks the picked one, reads every product page (1,000 a page) into the feed parsers' item shape (price from micros, first GTIN, availability and condition enums), keeps an offer listed again under another language or feed label once, and returns each product's item-level issues. syncOrders is a no-op. - 00296 catalog_item_issues: code, severity, attribute, reporting context, description per item; replaced each sync, removed with the source; members read, the server writes. - Plumbing: sign-in connectors (signIn instead of fields/connect), lib/catalog/sign-in.js (proxy request with 429/5xx waits, 'auth' when the sign-in is gone or refused), issue counts on last_counts, plain "Reconnect it in Settings › Integrations" words. - API: GET /api/catalog/accounts, POST /sources with input.account, signIns in GET /connectors, googleMerchantCenter in /integrations/config. - Tests with fixtures: paged list, items with and without issues, expired and refused sign-in, 429 wait, account picker, not set up. Co-Authored-By: Claude Opus 5.5 <[email protected]>
…and keep repeated offers' issues (ansvisor#1270 review) - sign-in.js: Composio's own 401/403 and Google's 403 are not_set_up, not auth; each refusal is logged by name, status and Google's reason; only the connector's hosts (merchantapi.googleapis.com) are reached. - An offer listed again under another language or feed label is counted on its own (last_counts.repeated), its issues gathered from every listing, and the kept one chosen by a fixed rule (no DISAPPROVED issue, then feed label, then content language). - Account listing and connecting share a 30 s deadline; the sub-account walk stops on a rate limit; a catalog cut at the page limit says so. - entityIdFor moves to composio.js. Tests for paging, deadlines, limits, the proxy helper and the refusal codes. Co-Authored-By: Claude Opus 5.5 <[email protected]>
gkhngyk
left a comment
There was a problem hiding this comment.
Needs changes: one thing before merge, a bound on what one read holds in memory. The migration and the sign-in checks look right. The rest are follow-ups.
What I checked:
- 00296.
- RLS is on.
anonandauthenticatedare revoked, thenauthenticatedgetsselectonly andservice_roleeverything, as on 00278's catalog tables. - One policy,
select, scoped to the brands of the caller's organization, in the same shape ascatalog_sources. Members have no insert, update or delete grant or policy, so only the server writes. - No functions. Rows go with their source and their brand by cascade, so 00279's forget trigger needn't change.
- Indexes:
source_idfor the delete each sync makes and for the cascade;(brand_id, external_id)for the per-item reads to come and the brand's cascade. - Re-runnable:
if not existson the table and indexes,drop policy if exists, and the grants and comment repeat cleanly. - The column limits match what
issuesOfclips to: 200, 100, 1,000, 2,000, 2,048 and 100 characters, and 300 countries. schema.sqlis main's file with 00296 appended after 00293 under its header, which is whatbuild-schema.shwrites. CI's schema check agrees.- No other open PR uses 00296. 00294 and 00295 (the WordPress and Framer chain) touch only the CMS tables, so 00296 can be applied before them.
- RLS is on.
- Whose sign-in.
workspaceEntitytakes the brand's own organization. Every route checks that the caller is an admin or manager in that brand's organization (assertWriter) before listing or adding. So a brand is only ever read with its own workspace's Composio connection.- An account is added only after Google answers
accounts/{id}for that sign-in (checkAccount). The id is digits only, so it can't change the path. - Members still can't insert a source that isn't a feed or an upload, or change
account: 00282's policy and the column grants.
- The token and the logs.
- Composio adds the token on its side. We keep only the connected account's id, as before.
proxyRequestsends GET only.- A call that isn't https to
merchantapi.googleapis.comis refused before the connection lookup. - A refusal logs its code, the host, the path with its ids masked, the status and Google's status and reason. It never logs the query, the page token, the account id or the body.
- People see fixed sentences, never the error's own text.
- Reads.
- 1,000 products a page, 200 pages at most. The whole read runs under the 10-minute store deadline, and waits on a 429 or a 5xx stay within it.
- A read that throws (a timeout, a refusal, a bad page) writes nothing, so the catalog and the issues stay as they were.
- Listing accounts and checking one share a 30-second deadline.
- Speed.
SIGN_IN_GONEis anchored, and its lookaheads run once from the start, so it's linear in the message.- The other new patterns are fixed-length (
accountId, the country code) or run on our own path. - No new regex runs on product text. The feed helpers it reuses get the API's fields, and the prices come from
moneyText.
- Tests.
- I ran them in an export of the head: the 121 tests in
src/connectors,src/lib/catalog,routes/catalog.test.jsandcomposio.test.jspass. - The allowlist test fails with the host check taken out.
- The whole server suite passes on the merge with main, except five timing tests in files this PR doesn't touch. They fail the same way on main on the machine I ran them on.
- I ran them in an export of the head: the 121 tests in
- Merge. Two commits on 55b49e7. It merges cleanly onto main (5bbd162), and CI is green.
- Before the API deploy.
- Server only. With the new API and the old web,
/api/catalog/connectorsalso returnssignIns, which the old web ignores. - Apply 00296 before the API deploy: a Merchant Center sync writes
catalog_item_issuesonce the catalog is written. Feed and store syncs don't touch the table.
- Server only. With the new API and the old web,
Before merge:
- Bound what one read holds in memory (
server/src/connectors/merchant-center/index.js:28-30,:259-285;server/src/lib/catalog/issues.js:49-52).- The read keeps every product of up to 200 pages in memory before the sync starts: 200,000 products, with their descriptions. It also keeps every issue of every listing. The sync then reads the source's rows already in the catalog on top of that.
- The issues have no total bound. Each listing's
itemLevelIssuesis kept whole, each issue with up to 300 countries, and all of them are inserted every day. - A feed URL is bounded at 50 MB. This bound is many times that, in the API process that also serves requests and runs the daily sweep. If that process ran out of memory, the source would keep its old
last_synced_at, so it would be first in line again the next day. - Fix:
MAX_PAGES = 50(50,000 products), close to what a 50 MB feed holds, until a larger account is tried live. The page-limit message follows the constant.- Cap the issues: e.g. 20 a listing in
issuesOf, and 100,000 a source inreadCatalog. When the cap cuts them, count it and add a line toerrors, as the page limit does. - A test for each cap.
- With a lower page limit, your follow-up (don't mark the unread rest removed when a read is cut) matters for more accounts. Merchant Center doesn't document that
products.listkeeps the same order from day to day, so a cut catalog could have different products marked removed each day. It's worth doing with this, or soon after.
Follow-ups:
2. An answer that isn't a JSON object reads as an empty account (index.js:268).
data?.products ?? []: if the proxy returns the body as text, or in another shape, the read isokwith no items. The sync then marks every product removed and clears the issues. They come back with the next good read.- Fix: throw
ConnectorHttpError('bad_response', …)whendataisn't a plain object, or whenproductsis there but isn't an array. Google leavesproductsout for an account with none, so an object without it still reads as no products.
- Log Composio's other failures (
server/src/lib/catalog/sign-in.js:170).- A Composio error that isn't a refusal (a 400 for the endpoint, a 404, the SDK's own validation error) becomes
unreachable, and nothing logs it:signInFailureandsyncOnceskip the log for aConnectorHttpError. In the live test, an endpoint Composio doesn't take would show "couldn't be reached" with nothing in the log. - Fix:
logger.warn({ provider, host, path, err: { name, status } }, '[catalog] sign-in call failed')before that throw, with the path masked aslogRefusaldoes.
- A Composio error that isn't a refusal (a 400 for the endpoint, a 404, the SDK's own validation error) becomes
- The account list fails whole when the sub-account walk runs out of time (
index.js:198-224).- The walk makes up to 21 calls, one after another, within 30 seconds. A sign-in that opens many accounts can run out of time, and the picker then says Merchant Center couldn't be reached, with no account listed.
- Each standalone account's
:listSubaccountsrefusal also goes throughlogRefusalasnot_set_up. So one listing can log up to 20 warnings that aren't problems. - Fix: on
timeoutorrate_limitedduring the walk, return the accounts listed so far. Skip the refusal log for that call, e.g. with aquietoption on the request.
For the live test, the parts only a real account shows:
- Composio's wording for a connection that's gone, and Google's for a project that isn't registered. Disconnect in Settings › Integrations, then Sync now; then revoke the app's access in the Google account, then Sync now. Both should say "Reconnect it in Settings › Integrations", and the log line should say
auth. - Whether Composio's proxy takes an absolute Merchant API URL, and a page of 1,000 products: its size limit, and the time a page takes.
- How long the listing takes for a sign-in that opens several accounts, including an advanced account.
- After moving to an API key with "Proxy execute": Search Console and Analytics still list properties and sync.
|
Taking the before-merge item over to save a round trip: MAX_PAGES 50, caps on the issues (per listing and per source, counted into errors), with tests; plus follow-up 2 (a non-object answer is a bad response, not an empty account). Please don't push to the branch meanwhile; I'll note here when it's done. |
Read 50,000 products at most, keep 20 issues a listing and 100,000 a read (an error line counts the rest), and read an answer that isn't a product list as a failed read instead of an empty account.
|
Done in the latest commit on the branch: MAX_PAGES 50, 20 issues a listing and 100,000 a read (an error line counts the rest), and an answer that isn't a product list fails the read instead of reading as an empty account (follow-up 2). Tests for each fail on the previous head. Follow-ups 3 and 4, and not marking the unread rest removed when a read is cut, are still yours. |
gkhngyk
left a comment
There was a problem hiding this comment.
Looks good. The before-merge item is in (MAX_PAGES 50, issue caps, a non-list answer fails the read), and the live test went through. 00296 is applied to production. Follow-ups 3 and 4, and not marking the unread rest removed when a read is cut, stay open for a follow-up PR.
Summary
Google Merchant Center as a source for a brand's product catalog (#1270), part 1: the server. The Settings card comes in part 2, on top of this branch.
A brand's Merchant Center account becomes a catalog source. It's read with the workspace's own Google sign-in through Composio, as Search Console and Analytics are, so the token never reaches us. Calls go to the Merchant API v1 through Composio's proxy.
The connector (
server/src/connectors/merchant-center/):listAccountslists the accounts the sign-in opens, plus an advanced account's sub-accounts.checkAccountchecks the picked one.readCatalogreads every product page (1,000 a page) into the feed parsers' item shape:An offer listed again under another language or feed label is kept once. The kept one isn't left to the API's order:
DISAPPROVEDissue;The others are counted on their own (
last_counts.repeated), not as skipped or as errors. Their issues still count: issues are gathered from every listing, merged by code, reporting context, attribute and severity, with their countries joined.With each product come its item-level issues.
syncOrdersis a no-op.Plumbing:
Sign-in connectors have
signIn(the Composio provider) instead offieldsandconnect.lib/catalog/sign-in.jsmakes the proxy request:merchantapi.googleapis.com);auth, and the source then says "Reconnect it in Settings › Integrations";not_set_up. It says Merchant Center isn't set up correctly on this server, or that the Google account can't open this account.Each refusal is logged by name, status and Google's reason. The token never is.
Issue counts go on the source (
last_counts.issues). A server without the auth config says Merchant Center isn't set up.lib/composio.jsgets thegoogle-merchant-centerprovider and a Merchant API proxy helper. The entity id helper (entityIdFor) moves there fromroutes/integrations.js, so the catalog and Integrations use one.Listing accounts and connecting one share a 30-second deadline. The sub-account walk stops on a rate limit.
A catalog cut at the page limit (200,000 products) says so in the sync's errors.
Migration
00296_catalog_item_issues:not_impacted,demoted,disapproved), attribute, reporting context and description.supabase/schema.sqlis rebuilt.API:
GET /api/catalog/accounts.POST /api/catalog/sourcestakesinput.account.GET /api/catalog/connectorslistssignIns./api/integrations/configsays whethergoogleMerchantCenteris set up.CONNECTORS.mdgets a section on platforms read with the workspace's Google sign-in.server/.env.exampledocumentsCOMPOSIO_GMC_AUTH_CONFIG_ID.@gkhngyk, the live test needs these first:
https://www.googleapis.com/auth/contentscope, and the app's verification. There's no read-only scope for the Merchant API.registerGcpfor the project, with Ansvisor's Merchant Center account.GOOGLE_MERCHANT, set asCOMPOSIO_GMC_AUTH_CONFIG_ID. The Composio API key needs the "Proxy execute" permission.Written by a side session working on the user's behalf, and handed over for the final checks, the review and this PR.
Related issue
Part of #1270. It doesn't close it: the Settings card is part 2.
Type of change
feat— New featurefix— Bug fixchore— Maintenance / dependenciesdocs— Documentation onlyrefactor— Code change that neither fixes a bug nor adds a featuretest— Adding or updating testsHow to test
cd server && npx vitest run src/connectors src/lib/catalog src/routes/catalog.test.js. The tests use fixtures: a paged list, items with and without issues, an expired and a refused sign-in, a 429 wait, the account picker, and a server without the auth config.GET /api/catalog/accountslists the account;POST /api/catalog/sources { kind: "merchant_center", input: { account } }adds it;catalog_item_issues.00296 was tried on the dev DB in a rolled-back transaction: the table, RLS (
authenticatedcan select, not insert), the severity check, and the cascade when the source is removed. It isn't applied on dev.Checklist
feature/,fix/,chore/,docs/) — see CONTRIBUTING.mdyarn lintpasses (run fromweb/)yarn typecheckpasses (run fromweb/)yarn format:checkpasses (run fromweb/)Also run:
server/:npm run format,npm run lintandnpm test(2,980 tests; 2,961 before the review's fixes).bash supabase/build-schema.sh: no change.npm run version:check: fails as on main, with the compose images at 0.2.0, not this PR's.A pre-push review's findings are folded in, in a second commit:
not_set_upapart fromauth, with logs;entityIdFor.Each new test fails with its fix reverted; the review and the fix checked 19 of them that way.
Follow-ups for separate PRs:
issues.jsreplaces a source's issues as a delete, then inserts, not in one transaction;sync.jshas no partial-read option yet;org_entity id (gsc-sync.js,ga-sync.js,action-center/execution/tools.js) could useentityIdFor.Composio's "connection gone" wording and Google's "not registered" wording are matched as documented, but not yet seen live. The live test will show them.
🤖 Generated with Claude Code