Skip to content

feat(catalog): add the product catalog and its batch sync (00278, #1263 part 1) - #1489

Merged
gkhngyk merged 3 commits into
mainfrom
feature/catalog-model
Oct 25, 2026
Merged

gkhngyk merged 3 commits into
mainfrom
feature/catalog-model

Conversation

@gkhngyk

@gkhngyk gkhngyk commented Oct 25, 2026

Copy link
Copy Markdown
Contributor

Summary

#1263, part 1: the catalog model and its batch sync. This gives every catalog source one shape to write into. The connections, credentials, the connector interface, the feed URL connector with its daily sync and CSV upload, and CONNECTORS.md follow in later parts.

Stacked on #1488 (the feed parsers, #1264). Its own change is the last commit. Merge #1488 first.

Tables (00278), all a brand's:

  • catalog_products, keyed by (brand_id, source, external_id): title, description, the product's brand, URL and product type. A feed's item group is one product; an item with no group is its own.
  • catalog_variants, under their product: SKU, GTIN, MPN, a marketplace item id (ASIN), URL, price and sale price with a currency, availability, condition, and the options that make the variant as attributes (color, size, material).
  • catalog_images: a product's or a variant's images, in order.
  • catalog_categories: a flat list per brand, from the product type as written. catalog_product_categories holds a product's categories (several).
  • Every value has a length check, addresses must be http(s), currencies are three letters, and attributes is a small object.
  • Access: RLS is on. Members read their brands' rows. authenticated has no insert, update or delete, anon has nothing, and only the service role writes.

Sync (server/src/lib/catalog/sync.js): syncCatalog(brandId, source, items) takes the feed parsers' items. Every source will go through it.

  • Rows are upserted in place on (brand, source, external id), 500 at a time, and reads page past 1,000 rows.
  • Each row's content_hash covers its content. A row that didn't change isn't written, so syncing the same file again writes nothing.
  • A product or variant gone from the source gets removed_at and is never deleted. One that comes back is live again.
  • A changed product's images and categories are written again.
  • A group's product title is the words its items share ("Trailrunner Hiking Boot - Red" / "- Blue" → "Trailrunner Hiking Boot").
  • Values are clipped to the columns' limits, and an address that isn't http(s) is left out, so one odd product doesn't fail a sync.
  • It returns what changed: added, changed, removed and unchanged, for products and variants.

Related issue

Part of #1263 (part 1 of several). Builds on #1264 (#1488).

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/catalog. The sync runs against an in-memory stand-in for the tables:
    • the RSS fixture becomes 2 products and 4 variants, with images and a category;
    • a second sync of the same feed writes nothing;
    • a product dropped from the feed is marked removed, and is live again when it comes back;
    • a changed price writes only that variant (and its product's images);
    • sources and brands stay apart;
    • odd addresses are left out and long values clipped;
    • a 10,000-row CSV becomes 2,500 products and 10,000 variants, and a re-import writes nothing.
  2. 00278 was dry-run on the hosted DB in a rolled-back transaction:
    • a brand's member reads its products, variants, images, categories and links;
    • a member's insert, update and delete are refused;
    • another organization's member sees nothing, and anon can't read.

Checklist

  • Branch follows the naming convention (feature/, fix/, chore/, docs/) — see CONTRIBUTING.md
  • Commits follow Conventional Commits
  • Server npm test, npm run lint and npm run format:check pass; schema.sql rebuilt
  • Changes are focused — one concern per PR

🤖 Generated with Claude Code

…og CSVs into one item shape (#1264)

A pure library under server/src/lib/feeds: an RFC 4180 reader, RSS 2.0 and Atom Google feeds read one item at a time, and a Meta catalog CSV, each into the catalog's item shape. Products missing a required field or repeating an id are skipped with their row or item number; a file that isn't a feed fails once.
… part 1)

Tables for a brand's products, variants, images and categories, keyed by (brand, source, external id), read by members and written only by the server. syncCatalog writes a source's feed items in place, skips unchanged rows by content hash, and marks a product or variant gone from the source as removed.
@github-actions github-actions Bot added the needs-migration Adds or edits a migration — apply it to the hosted database label Oct 25, 2026
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.

1 participant