Skip to content

feat(shopping-assistant): add a storefront shopping assistant example - #7

Merged
pronob1010 merged 1 commit into
mainfrom
feat/shopping-assistant
Oct 10, 2026
Merged

pronob1010 merged 1 commit into
mainfrom
feat/shopping-assistant

Conversation

@pronob1010

Copy link
Copy Markdown
Collaborator

A chat bubble on the storefront: the example for any app shoppers talk to (support bot, gift finder, AI assistant).

What it does

  • "green tea under 20" → product cards with Add to cart and View.
  • "where's my order?" → a guest is asked to sign in; a signed-in customer sees their last 3 orders, and only theirs.
  • Add to cart goes through the store's own cart.add, so the cart and drawer update, the store announces the change with Undo, and its limits apply.

How

Part Uses
storefront/assistant.js A storefront script in a shadow root: window.FlyCommerce.shopperToken() for each question, run('cart.add' | 'nav.goto' | 'ui.openCart'); elements built with textContent only
src/chat.ts allowStorefrontCalls() + authenticateShopper(): the store and customer come only from the verified token
src/search.ts GET /api/v1/search/products (catalog.read), then the price limit parsed from the question
src/orders.ts GET /api/v1/orders?filters[customerId]= (orders.read) for the token's customer
src/dev.ts The emulator: teas and mugs, one customer's orders and another's, and the example store page with a guest or signed-in shopper

No AI key: replies come from rules in reply(). The README and AGENTS.md show where a language model goes, with search and orders as its tools and the cart left to the shopper's click.

Without storefront.customer it still searches, and tells a signed-in shopper their orders are on their account page.

Depends on

The SDK's 0.1.0-next.4: authenticateShopper, allowStorefrontCalls, and the emulator's products, shopper tokens and store actions (getdokan/flycommerce-sdk#22). Merge after that's published.

Tests

  • test/chat.test.ts (8, against the emulator):
    • parsing words and a price;
    • search within a price;
    • nothing found;
    • only the signed-in customer's orders;
    • guest asked to sign in;
    • no storefront.customer;
    • missing or forged token refused, with CORS;
    • the bubble served with its App ID.
  • prettier --check and tsc are clean.
  • Checked in a browser with npm run dev:
    • as a guest, "green tea under 20" listed the teas and mugs under 20, leaving out the 24 teapot;
    • Add to cart showed the store's notice and Undo, and the cart count went to 1;
    • "where's my order?" asked a guest to sign in;
    • switched to signed in, it listed customer 1001's two orders and not the other customer's.

A chat bubble on the store page. A shopper asks for "green tea under 20"
and gets product cards with Add to cart, or asks "where's my order?"
and, when signed in, sees their last orders.

- The bubble is a storefront script in its own shadow root. It asks the
  store for a shopper token with each question and sends it to the
  app's server, never reading the page.
- The server checks the token with authenticateShopper(), searches with
  GET /api/v1/search/products and reads the customer's orders with
  filters[customerId], as the app.
- Add to cart, View and Open cart go through window.FlyCommerce.run(),
  so the store updates its cart and drawer, announces the change and
  offers Undo.
- Without storefront.customer it still searches, and points a signed-in
  shopper to their account page for orders.

Runs on the emulator with no account and no AI key; the README shows
where a language model goes. Needs the SDK's 0.1.0-next.4.
@pronob1010
pronob1010 merged commit dd38a2f into main Oct 10, 2026
1 check passed
@pronob1010
pronob1010 deleted the feat/shopping-assistant branch October 10, 2026 06:25
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant