Repository navigation
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
Conversation
…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.
4 of 12 tasks
…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.
7 of 12 tasks
4 of 12 tasks
4 of 12 tasks
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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:
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)
^[a-z][a-z0-9_]{1,39}$). The server syncs only kinds it has a connector for.feed_urlanduploadthemselves: the insert policy now names those two kinds.accountnames the store to the person: a shop's domain or a seller id.urlis optional. A feed still needs one, and an upload has none.last_statusgainsauth_failed: the store refused the saved sign-in.catalog_source_credentials, one row a source, removed with it.anonandauthenticatedhave 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)CONNECTOR_CREDENTIALS_KEY. It's the envelopekey-encryption.tsuses,{ v, iv, tag, ct }, with a fresh IV each time.Connecting, updating, removing (
lib/catalog/stores.js,/api/catalog, rate-limited, admins and managers of the brand's workspace)GET /connectorslists the stores a person can connect and their fields, and whether the server can keep a sign-in.POST /sources { brandId, kind, input }:connectchecks the sign-in with the store.PUT /sources/:id/credentialsreplaces 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:disconnectrevokes the sign-in at the store where it can, best effort.POST /sources/:id/syncreads stores too.ConnectError).Syncing a store (
lib/catalog/sources.js)readCatalog.auth_failed, with "Update it in Settings › Integrations".The HTTP client for platform APIs (
server/src/connectors/http.js,requestJson)safe-fetch.jsdoes);Retry-Aftersays, else 1, 2, 4 s with jitter.rate_limited.nextLink()reads aLink: <…>; rel="next"header.Building a connector
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).syncOrdersandhandleWebhookcome with the first store that needs them.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.server/src/connectors/__example__/, not registered) is the template, with its test:CONNECTORS.md(linked fromCONTRIBUTING.md) covers the interface, the HTTP client, errors, credentials, testing, and the review checklist the issue asks for. The checklist covers:Settings › Integrations › Product catalog
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:
syncOrders) and webhooks (handleWebhook), with Shopify (feat(integrations): Shopify integration, from install to App Store listing (epic) #1265);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
auth_failedwas accepted as a status.catalog_source_credentials, and changing a source's kind or account;CONNECTOR_CREDENTIALS_KEYon the API server (openssl rand -base64 32). The web app needs nothing.CONNECTORSand run a fake store.server/src/lib/catalog/stores.test.js,server/src/connectors/__example__/example.test.js).Checklist
feature/,fix/,chore/,docs/) — see CONTRIBUTING.mdyarn lintpasses (run fromweb/)yarn typecheckpasses (run fromweb/)yarn format:checkpasses (run fromweb/)Server: format, lint and
npm test(2,631 passed). Web: format, lint, typecheck andyarn test(3,865 passed).bash supabase/build-schema.shwas run.🤖 Generated with Claude Code