Skip to content

feat(catalog): connect a store with its own sign-in, kept encrypted by the API, with a connector harness and CONNECTORS.md (00282, #1263 part 3) - #1501

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

gkhngyk merged 3 commits into
mainfrom
feature/catalog-store-connections

Conversation

@gkhngyk

@gkhngyk gkhngyk commented Oct 25, 2026

Copy link
Copy Markdown
Contributor

Summary

#1263, part 3: store connections. Part 2 (#1493) added catalog sources: a feed URL and an upload. This adds what a store or marketplace read with the brand's own sign-in needs, so a connector can be built and tested without the core team:

  • an encrypted credential store;
  • the connect, update and remove flow;
  • an HTTP client for platform APIs;
  • a test harness with an example connector;
  • the contributor guide, CONNECTORS.md.

No store connector is registered yet. WooCommerce (#1275), Walmart (#1273) and Trendyol / Hepsiburada (#1276) sign in with API keys, which this supports as is.

Sources (00282)

  • Kind: a source's kind is now its connector's, any short slug (^[a-z][a-z0-9_]{1,39}$). The server syncs only kinds it has a connector for.
  • Who adds what:
    • Members still add only feed_url and upload themselves: the insert policy now names those two kinds.
    • A store is connected through the API, which checks the sign-in with the store first. So a store source never exists without its sign-in.
  • New columns and values:
    • account names the store to the person: a shop's domain or a seller id.
    • A store's url is optional. A feed still needs one, and an upload has none.
    • last_status gains auth_failed: the store refused the saved sign-in.
  • Daily run: it reads every kind but uploads. The due index follows that.
  • Credentials: they live in a new table, catalog_source_credentials, one row a source, removed with it.
    • Only the service role can read or write it. anon and authenticated have no grant at all, so they can't even tell that a row exists.

How a sign-in is kept (server/src/lib/catalog/credentials.js)

  • Encryption: the API encrypts it with AES-256-GCM under a key only it holds, CONNECTOR_CREDENTIALS_KEY. It's the envelope key-encryption.ts uses, { v, iv, tag, ct }, with a fresh IV each time.
  • Bound to its source: the source's id is the GCM associated data, so an envelope copied onto another source's row doesn't open.
  • The web app never holds it. What the person types goes from the browser to the API over its proxy, as the file upload does. Their sign-in never goes through a server action or a log.
  • Without the key: Settings says store connections aren't set up, and feeds and uploads work as before.

Connecting, updating, removing (lib/catalog/stores.js, /api/catalog, rate-limited, admins and managers of the brand's workspace)

  • GET /connectors lists the stores a person can connect and their fields, and whether the server can keep a sign-in.
  • POST /sources { brandId, kind, input }:
    • The connector's connect checks the sign-in with the store.
    • The source is made and the sign-in kept. If keeping it fails, the source is removed again.
    • The store is then read without waiting.
    • A brand connects each store account once.
  • PUT /sources/:id/credentials replaces the sign-in. It's refused when the new sign-in is another store's account, because the products are kept by source. It clears the last refusal, and reads the store again.
  • DELETE /sources/:id:
    • The connector's disconnect revokes the sign-in at the store where it can, best effort.
    • Then the source goes, with its sign-in (FK cascade) and its products (00279's trigger).
  • POST /sources/:id/sync reads stores too.
  • What the person sees when it fails:
    • The connector's own words for what to fix (ConnectError).
    • "The store refused this sign-in" for a 401 / 403.
    • Plain words otherwise.
    • What they typed never goes in a log: only a broken connector's error name is logged.

Syncing a store (lib/catalog/sources.js)

  • The saved sign-in is opened and handed to readCatalog.
  • A missing or unopenable sign-in, or a 401 / 403 from the store, records auth_failed, with "Update it in Settings › Integrations".
  • A rate limit, a timeout or a server error is recorded in plain words. The next daily run tries again.
  • Logs: an unexpected error is logged with every credential value taken out of its message.

The HTTP client for platform APIs (server/src/connectors/http.js, requestJson)

  • Where it can go: a store's address is often the brand's own, so it's reached like any address a person gives:
    • public addresses only, checked in the connection's own DNS lookup (as safe-fetch.js does);
    • standard ports;
    • no redirects, which would carry the sign-in to another host.
  • Retries:
    • It tries again on 429, 502, 503, 504 and dropped connections.
    • It waits as long as Retry-After says, else 1, 2, 4 s with jitter.
    • A wait over a minute ends the run as rate_limited.
  • Errors name the method, host and path only: never the query, the headers or the body.
  • Paging: nextLink() reads a Link: <…>; rel="next" header.

Building a connector

  • The interface is in server/src/connectors/index.js:
    • kind, label, fields (what the person types; a secret one is a password field);
    • connect(input, ctx) → { account, url?, label?, credentials };
    • readCatalog(source, ctx) → feed items;
    • disconnect (optional).
    • syncOrders and handleWebhook come with the first store that needs them.
  • The harness (server/src/connectors/testing.js):
    • startFakeApi(routes) serves a fake of the platform's API on a local port, and gives the connector the real HTTP client, reaching only that fake host, with its waits recorded instead of slept.
    • runSync(connector, source, …) syncs through the real plumbing into an in-memory catalog.
  • The example connector (server/src/connectors/__example__/, not registered) is the template, with its test:
    • connect with a right and a wrong key;
    • paging;
    • a 429 waited out;
    • a refused key recorded without being logged;
    • a product that can't be kept.
  • CONNECTORS.md (linked from CONTRIBUTING.md) covers the interface, the HTTP client, errors, credentials, testing, and the review checklist the issue asks for. The checklist covers:
    • least access;
    • credentials only in the store;
    • no buyer personal data;
    • revoke and deletion requests;
    • rate limits and platform data rules;
    • sandbox accounts only.

Settings › Integrations › Product catalog

  • Connect a store: when the API has store connectors, there's a "Connect a store" row, with a button for each, for admins and managers.
    • The button opens a form built from the connector's fields. A secret field is typed as a password and never shown again.
    • A note under the form says the sign-in is checked with the store, kept encrypted and used only to read the catalog.
  • A store's row:
    • It reads "{Platform} · {account}".
    • It shows Sync now, and Update sign-in, which opens the same form.
    • A refused sign-in shows "Sign-in refused" with the reason.
    • Removing it goes through the API.
  • No connectors or no key: with no store connectors (as now), nothing changes on the card. Without the key, the row says store connections aren't set up.

Related issue

Part of #1263 (part 3). This covers the issue's credentials, plumbing (retries, rate limits, logs without credentials), test harness and CONNECTORS.md.

Still to come:

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. Apply 00282. It was dry-run on the hosted DB in a rolled-back transaction:
    • The service role made a store source with credentials.
    • These were refused:
      • a kind that isn't a slug;
      • a feed without a URL;
      • an upload with a URL.
    • auth_failed was accepted as a status.
    • An admin of the brand:
      • added a feed;
      • was refused when adding a store source directly;
      • was refused reading or writing catalog_source_credentials, and changing a source's kind or account;
      • deleted the store source, and its credentials went with it.
    • Anon can't read the credentials.
  2. Set CONNECTOR_CREDENTIALS_KEY on the API server (openssl rand -base64 32). The web app needs nothing.
  3. Check Settings › Integrations › Product catalog: with no store connector registered, it looks as before.
    • To try the flow, register the example connector locally in CONNECTORS and run a fake store.
    • The tests do this end to end (server/src/lib/catalog/stores.test.js, server/src/connectors/__example__/example.test.js).

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

Server: format, lint and npm test (2,631 passed). Web: format, lint, typecheck and yarn test (3,865 passed). bash supabase/build-schema.sh was run.

🤖 Generated with Claude Code

…y the API, with a connector harness and CONNECTORS.md (00282, #1263 part 3)

- 00282: a source's kind is its connector's slug; members still add only
  feeds and uploads; `account`, `auth_failed`; the daily run reads every
  kind but uploads; `catalog_source_credentials`, service role only.
- Sign-ins sealed with AES-256-GCM under CONNECTOR_CREDENTIALS_KEY, bound
  to their source's id; the web app never holds them.
- /api/catalog: list connectors, connect, update a sign-in, remove a store;
  stores sync daily and on demand, a refused sign-in recorded as such.
- connectors/http.js: public addresses only, no redirects, retries on 429
  and 5xx as Retry-After says, errors without query, headers or body.
- connectors/testing.js harness and an example store connector with its
  test; Settings card connects a store from its connector's fields.
@github-actions github-actions Bot added the needs-migration Adds or edits a migration — apply it to the hosted database label Oct 25, 2026
…keep a malformed body out of the log (#1263)

- connectors/http.js: https only (the harness may call its fake over
  http); a compressed answer cut off part way fails instead of hanging;
  a POST is tried again only after a 429.
- A store's sync stops its calls after 10 minutes, and a source isn't
  read twice at once.
- 00282: a brand connects each store account once (unique index), and
  members delete only feeds and uploads directly: a store is removed
  through the API, which revokes its sign-in first.
- Logger: redact `err.body`, which the body parser attaches with a
  malformed request's whole body.
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