Skip to content

feat(catalog): read a brand's Google Merchant Center products and item issues (00296, #1270 part 1) - #1582

Merged
gkhngyk merged 3 commits into
ansvisor:mainfrom
cihan-gyk:feature/merchant-center-connector
Oct 27, 2026
Merged

gkhngyk merged 3 commits into
ansvisor:mainfrom
cihan-gyk:feature/merchant-center-connector

Conversation

@cihan-gyk

Copy link
Copy Markdown
Collaborator

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/):

  • listAccounts lists the accounts the sign-in opens, plus an advanced account's sub-accounts. checkAccount checks the picked one.

  • readCatalog reads every product page (1,000 a page) into the feed parsers' item shape:

    • the price from micros;
    • the first GTIN;
    • the availability and condition enums.
  • An offer listed again under another language or feed label is kept once. The kept one isn't left to the API's order:

    • first, one with no DISAPPROVED issue;
    • then the feed label;
    • then the content language, alphabetically.

    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. syncOrders is a no-op.

Plumbing:

  • Sign-in connectors have signIn (the Composio provider) instead of fields and connect.

  • lib/catalog/sign-in.js makes the proxy request:

    • it waits on 429 and 5xx, within the call's deadline;
    • only the hosts the connector names are reached (merchantapi.googleapis.com);
    • a sign-in that's gone or refused (Composio's "no connection / expired", Google's 401) is auth, and the source then says "Reconnect it in Settings › Integrations";
    • a refusal from Composio itself (a bad API key, no "Proxy execute" permission) or Google's 403 (the project not registered with Merchant Center, a missing scope) is 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.js gets the google-merchant-center provider and a Merchant API proxy helper. The entity id helper (entityIdFor) moves there from routes/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:

  • One row per issue per item: its code, severity (not_impacted, demoted, disapproved), attribute, reporting context and description.
  • A sync replaces its source's rows. They go with their source.
  • Members read their brands' rows; only the server writes them.
  • supabase/schema.sql is rebuilt.

API:

  • GET /api/catalog/accounts.
  • POST /api/catalog/sources takes input.account.
  • GET /api/catalog/connectors lists signIns.
  • /api/integrations/config says whether googleMerchantCenter is set up.

CONNECTORS.md gets a section on platforms read with the workspace's Google sign-in. server/.env.example documents COMPOSIO_GMC_AUTH_CONFIG_ID.

@gkhngyk, the live test needs these first:

  1. A Google Cloud OAuth client with the https://www.googleapis.com/auth/content scope, and the app's verification. There's no read-only scope for the Merchant API.
  2. The Merchant API's one-time registerGcp for the project, with Ansvisor's Merchant Center account.
  3. Our own Composio auth config for GOOGLE_MERCHANT, set as COMPOSIO_GMC_AUTH_CONFIG_ID. The Composio API key needs the "Proxy execute" permission.
  4. A test Merchant Center account for the acceptance test, with one product left unapproved on purpose.

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 feature
  • fix — Bug fix
  • chore — Maintenance / dependencies
  • docs — Documentation only
  • refactor — Code change that neither fixes a bug nor adds a feature
  • test — Adding or updating tests

How to test

  1. 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.
  2. With the four items above in place, as an admin:
    • connect Google Merchant Center in Settings › Integrations;
    • GET /api/catalog/accounts lists the account;
    • POST /api/catalog/sources { kind: "merchant_center", input: { account } } adds it;
    • a sync fills the catalog, and the unapproved product's issue appears in catalog_item_issues.

00296 was tried on the dev DB in a rolled-back transaction: the table, RLS (authenticated can select, not insert), the severity check, and the cascade when the source is removed. It isn't applied on dev.

Checklist

  • Branch follows the naming convention (feature/, fix/, chore/, docs/) — see CONTRIBUTING.md
  • Commits follow Conventional Commits
  • yarn lint passes (run from web/)
  • yarn typecheck passes (run from web/)
  • yarn format:check passes (run from web/)
  • Changes are focused — one concern per PR

Also run:

  • server/: npm run format, npm run lint and npm test (2,980 tests; 2,961 before the review's fixes).
  • bash supabase/build-schema.sh: no change.
  • Root 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_up apart from auth, with logs;
  • repeated offers counted apart, their issues kept, and a fixed choice;
  • tests for account paging, the sub-account sign-in check, the read's deadline, the proxy helper, the limits, the rate-limit and Retry-After paths, and Composio's own 401 and 403;
  • the host allowlist;
  • the 30-second deadline;
  • the page-limit warning;
  • the shared 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.js replaces a source's issues as a delete, then inserts, not in one transaction;
  • a catalog cut at the page limit still marks the rest removed, and sync.js has no partial-read option yet;
  • three more copies of the org_ entity id (gsc-sync.js, ga-sync.js, action-center/execution/tools.js) could use entityIdFor.

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

cihan-gyk and others added 2 commits October 27, 2026 12:56
…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 gkhngyk left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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. anon and authenticated are revoked, then authenticated gets select only and service_role everything, as on 00278's catalog tables.
    • One policy, select, scoped to the brands of the caller's organization, in the same shape as catalog_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_id for 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 exists on the table and indexes, drop policy if exists, and the grants and comment repeat cleanly.
    • The column limits match what issuesOf clips to: 200, 100, 1,000, 2,000, 2,048 and 100 characters, and 300 countries.
    • schema.sql is main's file with 00296 appended after 00293 under its header, which is what build-schema.sh writes. 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.
  • Whose sign-in.
    • workspaceEntity takes 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.
    • proxyRequest sends GET only.
    • A call that isn't https to merchantapi.googleapis.com is 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_GONE is 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.js and composio.test.js pass.
    • 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.
  • 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/connectors also returns signIns, which the old web ignores.
    • Apply 00296 before the API deploy: a Merchant Center sync writes catalog_item_issues once the catalog is written. Feed and store syncs don't touch the table.

Before merge:

  1. 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 itemLevelIssues is 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 in readCatalog. When the cap cuts them, count it and add a line to errors, 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.list keeps 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 is ok with 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', …) when data isn't a plain object, or when products is there but isn't an array. Google leaves products out for an account with none, so an object without it still reads as no products.
  1. 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: signInFailure and syncOnce skip the log for a ConnectorHttpError. 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 as logRefusal does.
  2. 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 :listSubaccounts refusal also goes through logRefusal as not_set_up. So one listing can log up to 20 warnings that aren't problems.
    • Fix: on timeout or rate_limited during the walk, return the accounts listed so far. Skip the refusal log for that call, e.g. with a quiet option 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.

@gkhngyk

gkhngyk commented Oct 27, 2026

Copy link
Copy Markdown
Contributor

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.
@gkhngyk

gkhngyk commented Oct 27, 2026

Copy link
Copy Markdown
Contributor

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 gkhngyk left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

needs-migration Adds or edits a migration — apply it to the hosted database

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants