Skip to content

feat(catalog): add WooCommerce connector (#1275) - #1789

Merged
gkhngyk merged 43 commits into
ansvisor:mainfrom
knockknock10:feature/woocommerce-connector-1275
Nov 1, 2026
Merged

gkhngyk merged 43 commits into
ansvisor:mainfrom
knockknock10:feature/woocommerce-connector-1275

Conversation

@knockknock10

@knockknock10 knockknock10 commented Oct 29, 2026 •

Copy link
Copy Markdown
Contributor

Summary

  • Register a WooCommerce REST API v3 connector using the existing encrypted credential store and read-only consumer keys.
  • Import paginated products, variable-product variations, categories and images; map SKU/GTIN where present, stock status, price/sale price, permalink and multi-category hierarchy.
  • Discover the store currency through one public WooCommerce Store API product response because REST v3 products omit the currency field.
  • Add normalized order/refund persistence with an incremental modified-time cursor and a five-minute overlap for second-precision timestamps. Persist only order metadata/totals and line-item product/variation IDs, quantity and revenue—never billing, shipping, customer or raw payload fields.
  • Fail closed at the pagination safety cap so an incomplete product snapshot cannot mark unseen products as removed.
  • Keep order writes retryable: an order is marked complete only after line-item replacement succeeds.
  • Add HMAC-SHA256 webhook signature verification/normalization and fake-API harness tests.

Related issue

Closes #1275

Verification on the merged tree

  • Server lint: npm run lint — passed.
  • Server format: npm run format:check — passed.
  • Server tests: npm test — 330 test files passed; 4,484 tests passed, 3 skipped.
  • Schema: bash supabase/build-schema.sh — regenerated from 320 migration files.
  • Web format, lint, TypeScript typecheck and production build — all passed locally. The earlier production-build failure was caused by client-side Roles & access code importing the server Supabase client; current upstream main includes the fix from fix(settings): keep the server Supabase client out of Roles & access, so the web build passes #1796, and this branch now includes that mainline change.
  • Local WordPress + WooCommerce REST v3 acceptance run: connected using a disposable read-only key over local HTTPS; read 6 catalog items; persisted 4 products and 6 variants; confirmed USD prices and both category links for a multi-category product. Retrieved 2 orders (including a refunded order) and persisted 2 normalized order rows plus 2 line items. Injected billing/shipping/customer data was absent from the persisted order rows.

The local acceptance run used a disposable wp-env WordPress/WooCommerce instance, a self-signed local certificate and test-only credentials. The isolated test process accepted that certificate only to reach localhost; no production TLS validation or transport code was weakened, and no merchant credentials were used.

Security review checklist

  • Least access: the connection form tells the merchant to create a REST key with Read access only.
  • Credentials: key and secret are secret form fields stored by the encrypted credential store. REST credentials are sent in the Basic Authorization header, never the URL. Fixtures use fake values; secrets are not logged or included in user-facing errors.
  • No buyer or customer personal data: the shared order writer allowlists normalized order/date/status/channel/currency/totals/refund amount and line-item product/variation IDs, quantity and revenue. Tests assert buyer, billing, shipping, customer ID, free-text line data and raw payload fields are not stored.
  • Removal: removing the store deletes its source and saved encrypted credentials. WooCommerce does not expose API-key revocation to a read-only REST key, so the merchant must revoke the key in WooCommerce › Settings › Advanced › REST API when required.
  • Rate limits: platform requests go through the connector request client; collection reads are capped at 200 pages × 100 items and 429 retry behavior is covered by the harness.
  • Platform data rules: only catalog fields and normalized order facts needed by the feature are retained; raw order/customer payloads are not persisted.
  • Tests: harness tests run with fake API responses and no network/account. A separate disposable local WordPress/WooCommerce instance was used for acceptance testing; no production credentials were used.
  • User-facing errors: connection and malformed-response errors use plain language and actionable next steps.

Webhooks

Webhook support is optional in #1275. The connector validates the raw-body HMAC-SHA256 signature and normalizes supported order/product event metadata; the shared HTTP receiver/dispatch route is not part of this change, so scheduled and on-demand sync remain the source of truth.

Upstream merge

Merged current upstream main, including the plan-row boundary fix from #1796 that resolves the web production-build failure. Kept the order-sync cursor alongside upstream's demo-brand source exclusion. The new order tables are explicitly excluded from synthetic demo data: the demo catalog is built from a product feed and must not invent merchant purchase history.

@github-actions github-actions Bot added the needs-migration Adds or edits a migration — apply it to the hosted database label Oct 29, 2026
@knockknock10
knockknock10 marked this pull request as ready for review October 29, 2026 17:50
Copilot AI balanced review requested due to automatic review settings October 29, 2026 17:50

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Copilot was unable to review this pull request because the user who requested the review has insufficient remaining quota.

An organization owner can choose the repository organization as the billing source for reviews requested by members with a paid Copilot license. Learn about Copilot code review billing.

@knockknock10

Copy link
Copy Markdown
Contributor Author

@gkhngyk The latest PR head (aa536fa) is now fully green in GitHub Actions: server lint/format/tests, web format/lint/typecheck/Vitest/production build, schema consistency, and migration guard all passed. The branch includes current upstream main and GitHub reports it mergeable. Could you please review when you have a chance? The PR description includes the local WooCommerce acceptance counts and the security checklist.

@knockknock10

Copy link
Copy Markdown
Contributor Author

@gkhngyk Final validation update for the current PR head b2edc53: GitHub Actions is fully green — server lint/format/tests, web Prettier/ESLint/typecheck/Vitest/Next.js production build, schema consistency, and migration guard all passed. Vercel is also successful, and GitHub reports the branch mergeable with no conflicts. The only remaining merge gate shown by branch protection is one approving maintainer review. The PR description has the final merged-tree test counts and the local WooCommerce acceptance/security details.

…ing and drop a store's orders with it

- Rename 00407_catalog_orders.sql to 00384 (00400-00449 is the Chat block) and rebuild schema.sql.
- Remove a store's orders when the store is removed (catalog_sources_forget).
- Ask WooCommerce to compare the cursor with GMT modified times (dates_are_gmt).
- Read at most 100 order pages a sync and move the cursor to the last change read, so a large store catches up instead of rereading the same pages.
- Keep only normalized orders past each page.
- Send the whole row in the completing upsert (placed_at is NOT NULL), write an order listed twice once, and read back only the orders being written.
- An order read that fails leaves the catalog's outcome and the cursor as they were.
gkhngyk
gkhngyk previously approved these changes Oct 31, 2026

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

Thanks for the connector. Approving with one commit on top (63a0ec1), pushed to this branch, covering the points from the last review:

  • The migration is numbered 00384 (00400–00449 is reserved), and schema.sql is rebuilt.
  • catalog_sources_forget also deletes a removed store's orders; their lines go by cascade.
  • The order cursor sends dates_are_gmt: true, the order read is capped, and the cursor moves to the last change read.
  • The completing upsert sends the whole row, an order listed twice in one read is written once, existing orders are read back only for the ids being written, and only normalized orders are kept between pages.
  • A failed order read is logged, leaves the cursor as it was and keeps the source's outcome for the products it saved.

Each change has a test that fails without it. We'll merge after a manual check against a real store.

…ts failure

The order sync reused the catalog read's client, whose single deadline
started before the products were read, so a large store's order read ran
out of time after the products and the cursor never moved. The orders now
get a fresh deadline, and a failed order read keeps its reason (and whether
it timed out) in the source's order counts next to the warning log.
…riations

The product listing sent no status, so WooCommerce's default (any) also
returned draft, pending and private products, and switched-off variations
came back as private: all saved as live products with pages shoppers can't
open. The listing now asks for status=publish, and a product or variation
whose status isn't publish is skipped, so one taken off the store is
marked removed by the next sync.

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

Approving again with c421b19: two fixes on top, described below.

  1. Only published products and enabled variations (server/src/connectors/woocommerce/index.js). The product listing didn't send a status, and WooCommerce's default is any, so draft, pending and private products came back too. Switched-off variations come back as private. All of them were saved as live products, with links shoppers can't open. The listing now asks for status=publish, and any product or variation whose status isn't publish is skipped. Rows with no status at all are still kept. A product taken off the store now drops out of the snapshot, so the next sync marks it removed. Test: keeps only published products and enabled variations.

  2. The order read gets its own deadline (server/src/lib/catalog/sources.js). The order sync reused the catalog read's client, and that client's single STORE_READ_MS deadline started before the products were read. On a large store, the products could use up the whole budget, so the order read timed out every run, the cursor never moved, and the only trace was a warning. The orders now get a fresh deadline (withDeadline). A failed order read still leaves the catalog's ok outcome and the cursor alone, as before. It now also keeps a plain-words error (and timedOut: true when time ran out) in counts.orders, next to the existing warning log. Tests: two new syncSource store cases (an order read that only fits with its own budget, and an order read that times out). The existing WooCommerce order-failure test now expects the error field.

Thanks again for the careful work on this connector!

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

LGTM

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

LGTM

@gkhngyk
gkhngyk merged commit dcef36a into ansvisor:main Nov 1, 2026
5 checks passed
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.

feat(integrations): WooCommerce connector: products, variations, categories and orders

3 participants