Skip to content

feat(content): check each draft's shopping links after a catalog sync and show it in the Library (00352, shopping path, part 7a) - #1615

Merged
gkhngyk merged 41 commits into
ansvisor:mainfrom
cihan-gyk:feature/shopping-path-check
Oct 28, 2026
Merged

gkhngyk merged 41 commits into
ansvisor:mainfrom
cihan-gyk:feature/shopping-path-check

Conversation

@cihan-gyk

@cihan-gyk cihan-gyk commented Oct 27, 2026 •

Copy link
Copy Markdown
Collaborator

Summary

E-commerce Shopping path, part 7a of 7: the shopping link check. After each catalog sync, every draft's shopping path is checked against the catalog. For each product link it asks: is the product sold out, refused, or gone? Library shows the result.

From main. The parts below it are merged (#1587, #1588, #1591, #1592, #1607, #1610). This PR's own change is its commits after #1610's head:

  • 56823a6, the check. Its subject says wip: it's the side session's commit, kept as made, so the squash title is this PR's;
  • cba4f87, which aligns it with part 6's rules;
  • f9548fc and 9e98003, the pre-push review's fixes;
  • da87590, which merges main in.

Parts 7b (#1616) and 7c (#1617) are stacked on this one.

The check (server/src/lib/shopping-check.js):

  • When: after each catalog sync (catalog/sources.js afterSync → queueShoppingCheck).
  • What it reads: the live page when the draft is published, otherwise the draft.
  • What it finds:
    • a product link to a product no longer for sale: sold out, refused, or removed from the catalog;
    • a category the path has that the page no longer links.
  • The same rules as part 6's editor checks:
    • removed and left-out products count only when they don't sell;
    • relative links are read against the page, then the brand's primary site;
    • variants are read by brand.
  • A live page is trusted only when it is the page:
    • It must be on the brand's site (brandSite), before the request and after redirects.
    • It must have at least 20 words, as task-checks.js asks.
    • A live page that links nothing from its path while its draft does is read from the draft instead. A bot wall or a page that draws its links in JavaScript doesn't read as fixed.
  • Reads: in chunks of 100 ids (readIn, readAllRpcRows). A removed product is named by its title, from the path or the catalog.
  • Ended plans: a brand whose plan ended is skipped (isBrandActive, feat(server): stop every automatic process for a workspace whose plan ended #1608).
  • Storage: results go to content_shopping_checks (migration 00352). Members read their brands' rows; only the service role writes. Rows for drafts that no longer have a path are dropped.

Library:

  • A Shopping path column (OK, the count to fix, or "Not checked yet") and a ?shopping= filter.
  • The filter sits beside main's Last send (feat(content): filter the Library by each page's last send to the CMS #1567); the list filters by created date, then shopping path, then last send.
  • The checks are read in their own query, which tolerates failure. So the Library still lists its drafts before 00352 is applied; they show "Not checked yet".

Related issue

Part of the e-commerce shopping journey (#1263–#1285 area). Follows #1610.

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/lib/shopping-check.test.js src/lib/catalog
  2. cd web && yarn vitest run src/lib/actions "src/app/[locale]/(dashboard)/dashboard/content/library"
  3. With 00352 applied and a brand with a catalog:
    • sync the catalog;
    • a draft whose path links a sold-out product shows "1 to fix" in Library's Shopping path column, and the filter finds it.

Checked in the browser at 1024 px, light and dark, against the dev DB with 00352 applied. The Library lists the drafts with the Shopping path column and filter beside Last send, and nothing scrolls sideways. The dev catalog is empty, so no check rows were made; the logic is covered by the tests.

Checklist

  • Branch follows the naming convention (feature/, fix/, chore/, docs/) — see CONTRIBUTING.md
  • Commits follow Conventional Commits — all but 56823a6's wip, see above
  • 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

Checks were run at the top of the 7a → 7b → 7c stack:

  • server/: npm run format, npm run lint and npm test (3,391 tests). Two timing tests that failed under load pass alone.
  • web/: yarn format, yarn lint (0 errors), yarn typecheck, yarn test (4,368 tests; the editor page's test file timed out under load and its 271 tests pass alone) and yarn build.
  • bash supabase/build-schema.sh leaves schema.sql as committed.

For you, @gkhngyk:

  • Apply 00352 before the API deploy. Until it's applied, the API's check fails after each sync and keeps nothing. The web is safe either way.
  • Follow-ups (not here):
    • An open action's text isn't refreshed when other products sell out.
    • Actions aren't closed when their draft is archived, deleted or unpublished.
    • The live-page cap (50 per run) picks by draft id; oldest check first would rotate them.

🤖 Generated with Claude Code

cihan-gyk and others added 30 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]>
…account in Settings › Integrations (ansvisor#1270 part 2)

- Settings › Integrations gets a "Stores and marketplaces" group: a Google
  Merchant Center card that connects the workspace's Google sign-in like
  Search Console and Analytics, then lets the active brand pick one of the
  accounts it opens (GET /api/catalog/accounts) and add it as a catalog
  source.
- Product catalog names the account "Google Merchant Center · Name (id)"
  and its row reads "N products · M with issues · synced …"; no sign-in
  button for it (the sign-in is the workspace's). The card reads its
  sources again when an account is added above.
- The Shopping page's My Products tab links to Settings › Integrations to
  bring in the catalog.
- catalog-client: signIns in listStoreConnectors, listSignInAccounts,
  connectSignInAccount, not_connected; CatalogCounts.issues;
  IntegrationProvider 'google-merchant-center'. Words in en.json.

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]>
… integrations by kind, and say what the catalog is for (ansvisor#1270 review)

- The picked account belongs to the brand it was picked for: switching
  brands clears it, an add goes to the brand clicked for, one add at once.
  Accounts already added are marked and can't be picked; a failed list read
  offers Try again; members get their own line.
- Integrations' group headings are h3 headings; Webflow moves to a
  "Content management systems" group (IntegrationGroup).
- Shopping › My Products' catalog note says what the catalog does (the
  editor's product-page checks), only while the brand has no source.
- "1 with an issue"; a fixed platform name before /connectors is read;
  stores.errors.not_connected.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
…eated offers, and note advanced accounts (ansvisor#1270 review)

- settings.merchantCenter.errors.not_configured says who fixes it (the
  server's set-up, or the Google account's access), with Try again.
- A source's line shows "N listed again, kept once" (last_counts.repeated).
- With several accounts, a note says an advanced account holds no products:
  pick the store's own sub-account.
- Every StoreError has a message (checked at typecheck); the Shopping note
  is _catalog-note.tsx.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
… site (00350, shopping path part 1)

The shopping path links a buying guide or a comparison to the category's own
page, so each catalog category is matched, on every read, to one of the
brand's site pages whose address reads as a category page (the editor's
page-type rule: /collections/, /category/, /c/, /shop/, WooCommerce's
/product-category/; never a product page or a themed collection). Best
match: the last path segment is the category's name, then the title or h1
holds it, then most of its words; ties go to the more cited, then visited
page.

- 00350: catalog_category_pages keeps a person's decision (a page, or none)
  by category name; catalog_category_counts(brand) gives live products and
  how many are in stock (service role only).
- lib/catalog/category-pages.js: categorySlug, matchCategoryPages,
  categoryPages(brandId), setCategoryPage (page must be on the brand's
  domains).
- API: GET /api/catalog/categories (members), PUT and DELETE (admins and
  managers).

Co-Authored-By: Claude Opus 5.5 <[email protected]>
…rations and let admins change it (shopping path part 1)

- Category pages, under the product catalog in Stores and marketplaces:
  each category of the active brand with its products and how many are
  in stock, its page on the site, and how it was found (its address or
  title names the category, most of its words, set by hand). Shown once
  the catalog has categories.
- Admins and managers change a page (it must be on the brand's site), set
  none, or put a hand-set one back to the automatic match; members see
  the table.
- catalog-client: listCategoryPages, setCategoryPage, resetCategoryPage;
  words in settings.catalog.categories.
- The API calls a person's decision 'manual' whether it's a page or none.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
…(00351, shopping path part 2)

On an online shop, a buying guide, a best-of list or a comparison links the
right category page and products in stock that Merchant Center accepts. The
API picks them for the draft's topic and keeps them on the draft:

- Topic: the title's words count 3, the brief's keywords 2, its goal and
  headings 1.
- Categories: with a page on the site (00350) and stock, the best first,
  a second only when it scores half the first's (2 at most).
- Products: the picked categories' first, then the brand's (2,000 scored,
  the best 40 read in full); offered when they have a link, a variant in
  stock and Merchant Center doesn't refuse that variant; the cheapest such
  variant's price, and its non-refusing issues (e.g. missing GTIN). How
  many by page type: best-of 8, buying guide 5, comparison and
  alternatives 4, guide 4, blog post 3. The best left out are kept with
  why (sold out, refused, no link).
- The person's choices survive a rebuild: locked and added products stay
  (counted in the page's number), removed ones never come back.
- 00351 content_drafts.shopping_path jsonb (64 KB at most); members edit
  it like the brief.
- POST /api/content-drafts/:draftId/shopping-path { brandId }: { path },
  or { path: null, reason } ('not_a_shop', 'page_type', 'no_catalog').

Co-Authored-By: Claude Opus 5.5 <[email protected]>
…s Brief tab (shopping path part 3)

Brief › Shopping path, above the brief, for a page type that links products
(best-of, buying guide, comparison, alternatives, guide, blog post) on an
e-commerce brand:

- Pick from the catalog the first time (POST /:draftId/shopping-path), Pick
  again after; why a draft takes none (not a shop, page type, no catalog).
- The category page with where it goes (in the intro and at the end).
- Each product with its price (sale price first, en-US in its currency),
  In stock or Low stock, its Merchant Center issues, and its place by page
  type (Top picks #n, Compared #n, linked in the text).
- Lock (kept when picked again or rewritten), Remove (saved at once),
  Swap (removed, then picked again for the next best), Add product (search
  the catalog's names, then picked again with it kept).
- The best products left out, with why (sold out, Merchant Center refuses
  it, no page to link).
- actions/shopping-path.ts: read and save through RLS like the brief,
  build through the API, search the catalog. lib/content/shopping-path.ts:
  the path's schema, which pages take one, places, changes. Words in
  contentEditor.editor.shopping; shopping_path in types/supabase.ts.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
…ts only (shopping path part 4)

The Content Agent now writes with the draft's shopping path:

- A new page: the writer is told the category page (name it in the
  opening, point to it again at the end) and the products in order with
  the catalog's price and stock only, never another spec (a placeholder
  instead). It writes text, so the names it wrote are linked afterwards
  (shopping-links.js linkShoppingPath): each target the first time a
  paragraph or a list item names it, never in a heading or inside a link;
  products first, longest names first; a category's last word singular or
  plural too.
- A page it changes (rewrite from brief, suggestions, rule fixes): the
  path's pages join the pages it may link to, first in the prompt whatever
  the rules, and in the allow list (anything else is still unwrapped).
- The path's names and prices are given to the number and people guards,
  so the catalog's price isn't turned into a placeholder.
- content-links.js: linkTargetsPrompt and linkAllowList read
  targets.shopping; startDraftWriting and fixDraftRules read
  shopping_path.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
… hand or with the agent (shopping path part 5)

- + Insert › Products (the toolbar and the empty-line menu), on an online
  shop's draft: search the catalog by name, pick 1 to 4, Insert. One shows
  as a card, more as a grid: each product's picture, name and price (its
  cheapest variant in stock, sale price first), linked to its page. An HTML
  block with inline styles and no words of its own, so every export and
  CMS shows it as written, in any language.
- The agent's new page on a list, a buying guide or a comparison with two
  products or more gets the same grid from its shopping path, at the end of
  the section that links the products most (else before the last H2, else
  at the end).
- The markup is written twice, web (lib/content/product-block.ts) and
  server (lib/shopping-blocks.js); both tests expect the same string.
- actions/shopping-path.ts getProductsForBlock reads products, variants
  and images through RLS; catalog_images added to types/supabase.ts.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
…s own rule (shopping path part 1 review)

- A malformed % in a page address no longer breaks the read.
- Pages and categories are prepared once, with a word index; site_pages
  isn't read when nothing can match.
- GET uses the general limiter; PUT/DELETE get their own bucket.
- The category-page rule is the editor's (page-types.ts), checked on both
  sides by one fixture list; /blog/category/ and pages marked first
  (best-of, size guides, -vs-, policies) aren't category pages.
- Parent words count; a one-word category matches by address only.
- Turkish and German letters fold (lib/letters.js, shared with Webflow).
- The table is read again when sources change; editing resets per brand.
- catalog_category_counts counts the web's four in-stock values.
- PUT refuses a category the catalog doesn't have; messages fit the routes.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
…publish (shopping path part 6)

On an online shop's page with a shopping path:

- Rules › Links and sources gets three Shopping rules: it links its
  category page; it links the path's products (3 by default, or all of a
  smaller path; a product card or grid counts); and none it links is sold
  out, refused by Merchant Center for free listings, or gone from the
  catalog. The last isn't the agent's to fix (NOT_FOR_AGENT).
- Before you publish gets a Shopping links row: the products to swap by
  name and why, else a missing link to the category page, else how many
  work. Read fresh when it opens.
- readPage reads the links inside HTML blocks too (htmlBlockLinks).
- getShoppingCheck reads the path's products against the catalog now (in
  stock as feed-match.ts reads it; a refusal counts for FREE_LISTINGS or
  no destination); useShoppingCheck feeds the rules and the dialog.
- catalog_item_issues added to types/supabase.ts; words in
  contentEditor.editor.rules and beforePublish.shopping.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
…talog row, with one stock rule (shopping path part 2 review)

- Locked and added products are read by id from the brand's own catalog,
  always kept; a removed or unknown one is left out as 'gone'.
- Every read is chunked and paged past PostgREST's 1,000-row cap.
- The route has its own bucket (shoppingPathLimiter); descriptions are cut
  to 400 characters once read.
- More stop words and years, letters folded as category pages do, and
  'no_match' when nothing fits.
- A refusal counts only for free listings or an empty context.
- One stock list (catalog/stock.js), the same as feed-match.ts and 00350.
- The saved path is read through Zod; a bad one is taken as none and
  logged. Writes are capped to 64 KB and conditional on builtAt/savedAt
  (409 'changed').

Co-Authored-By: Claude Opus 5.5 <[email protected]>
The table was 640 px wide in a 417 px card at 1024 px. The Change buttons
sat out of sight, and the header's screen-reader label, outside the
scroll box, scrolled the whole page sideways.

- How a page was found is now a line under it, so four columns fit.
- While a category is being changed, its form takes the button's cell
  as well.
- The scroll box contains its label (`relative`).
- Addresses wrap only where they must ([overflow-wrap:anywhere]).

Co-Authored-By: Claude Opus 5.5 <[email protected]>
… new path shape (shopping path part 3 review)

- The schema takes the API's shape: 'gone' and a missing title for a
  product left out, 'no_match', savedAt, availability in lowercase with
  underscores, and the same caps as the server. A reason it doesn't
  know reads as a general line instead of failing.
- A change is saved before the path is picked again, so a failed pick
  (429, 502) doesn't lose it.
- A save writes only locked, removed and added, and only over the path
  that was read (builtAt and savedAt). Otherwise it answers 'changed' and
  the tab reads the path again. A build's 409 'changed' and 429 have
  their own lines.
- An unreadable saved path, 'no_match' or an unknown reason offers "Pick
  from the catalog".
- Links must be http(s); others show without a link.
- The search has its own error; the Lock button has a fixed name with
  aria-pressed.
- Removed: the unused fromCatalog string.
- Rows are keyed by their place and name; the category path wraps with
  [overflow-wrap:anywhere].

Co-Authored-By: Claude Opus 5.5 <[email protected]>
… the catalog and the brand's site give them (shopping path part 4 review)

- shoppingPathFor reads the path once per run through readShoppingPath. A
  bad shape counts as no path and is logged; the run goes on.
- Prices pass in their usual forms ($189, 189 USD, ₺1.299,00), with the
  sign matching the currency; any other price becomes a placeholder.
- Stock is read fresh from catalog_variants at write time and named
  through stock.js. Unknown stock says nothing.
- Links: https and the brand's own domains only (brandSite, shared with
  category pages).
- Product names match case-sensitively and category names don't. Letters
  are folded, and singulars come from category pages.
- The fix path guards prices and names too.
- A name or address is used once. A product name's numbers are free only
  where the name stands.
- The prompt takes as many products as the page type links, 40 at most,
  locked and added ones kept.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
…uct-blocks

# Conflicts:
#	server/src/lib/content-writer.js
…he grid as a list (shopping path part 5 review)

- The agent's grid takes only products in stock, counted after the
  filter, with the price and stock read fresh by shoppingPathFor.
- Insert › Products:
  - A product is offered only when it's in stock and has an https page.
    Search hits show the price, or "Sold out" or "No page to link", and
    can't be picked when they're out.
  - At insert, a product sold out meanwhile is left out with a toast.
  - Each product's variants and image are read on their own: no shared
    row cap; an image with no variant first.
  - The cheapest variant in stock is picked by sale_price ?? price, with
    one stock reading shared with feed-match.ts (variantStock).
  - Cancel or Esc while inserting inserts nothing.
  - The search has its own error; picks survive a new search and can be
    taken back; Insert shows it's working; the count is aria-live.
- The markup has spaces and line breaks, so text exports read each
  product apart. Webflow gets the grid as a <ul> list. Links are https,
  without tracking or a hash, the same on both sides (a shared
  fixture). A price of 0 is none; a sale price counts only under the
  price, for the agent's price line too.
- The grid goes before the last H2 when no section links the products.
- Tests for the writer's grid, getProductsForBlock and the toolbar's
  Products button. Docs: Insert › Products in the Content Editor guide.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
…rules-check

# Conflicts:
#	web/src/lib/actions/shopping-path.ts
…, its removed products and Brief's changes (shopping path part 6 review)

- getShoppingCheck reads products, variants and Merchant Center issues in
  100-id chunks, paged past 1,000 rows, with the brand taken from the
  draft. Stock is read by variantStock, contexts normalised as the
  server's.
- Products removed or left out of the path are checked too, when they
  can't be sold. They count for shopLinksLive only, and its words say
  to remove or replace the link on the page.
- Brief's Shopping path tells the editor when it changes, so the check
  reads again.
- One link collector (PageRead.links) for Rules and Before you publish,
  HTML blocks included, so the product grid counts in both.
- shopProductLinks counts only products that can be sold.
- A failed read shows as failed, and a re-read keeps the last result.
- Before you publish:
  - shows reading and failed rows, and "N of M products linked";
  - the bad list is capped with "+N more", as Rules names the products.
- shopLinksLive alone gets its own not-for-agent message.
- Relative links resolve against the page's address or the brand's
  domain.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
cihan-gyk and others added 9 commits October 27, 2026 19:30
…rary's Shopping path column (shopping path part 7a, before merging part 6's review)
…after each catalog sync, as the editor's Rules now do

Part 6's review widened the editor's link check. The daily check after
a catalog sync (lib/shopping-check.js) now reads a page the same way:
- a product the person removed from the path, or the path left out, is
  checked too. It counts, at the catalog's page for it, only when it no
  longer sells: the page may still link it;
- "products" and "products linked" count the path's products that sell;
- a draft's relative link ("/products/x") is read against its page,
  else the brand's primary site;
- catalog variants are read by the brand too.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
…h-check

# Conflicts:
#	web/messages/en.json
#	web/src/app/[locale]/(dashboard)/dashboard/content/library/page.tsx
… Library lists its drafts before 00352 is applied

Co-Authored-By: Claude Opus 5.5 <[email protected]>
…page, name removed products, and skip ended plans

A live page is read only on the brand's site and with words enough to be
the page; one that links none of the path while its draft does is read
from its draft. A removed product is named by its catalog title, and a
brand whose workspace's plan ended isn't checked (ansvisor#1608).

Co-Authored-By: Claude Opus 5.5 <[email protected]>
…d test its live-page deadline and draft cap

Skip a link longer than 2,048 characters when a page's links are read.
Test the 3-minute live-page deadline, and that no row is dropped when a
run stops at its most drafts.
@gkhngyk

gkhngyk commented Oct 28, 2026

Copy link
Copy Markdown
Contributor

I took the review's before-merge item over (2aadf2a): pageHrefs skips an href over 2,048 characters, with a test, plus tests for the 3-minute deadline and the 1,000-draft cap guard. The trailing-slash strip in linkKey is made linear in #1700, which should go first. The other follow-ups stay with you.

@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 with 2aadf2a (an href over 2,048 characters is skipped; the deadline and draft-cap guards are tested) and #1700 on main (the link key is read in time near its length). 00352 is applied to production. The main merge keeps both sides in the catalog test db (not_is and lt) and the Library table (ShoppingPathMark and the CMS mark's comment). The remaining follow-ups stay open.

Separately: _before-publish.test.tsx's "opens and folds the code with one button, its focus on the code it opens" (#1622) fails about half the time on main, alone too: worth a look in a follow-up.

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