Svelte Commerce × Swell

Svelte Commerce on Swell

Solid core coverage: cart, checkout and sign-in are wired against Swell’s storefront API, authenticated with the store’s public key. Reviews, wishlist, vendors and states are the recorded gaps.

What works on Swell today

Cart, checkout and sign-in are wired; reviews, wishlist, vendors and states are not.

Cart

Wired: issues a real request to Swell.

Checkout

Wired: issues a real request to Swell.

Sign-in (auth)

Wired: issues a real request to Swell.

Known gaps: review, wishlist, vendor, state

23 of 43 services wired, read from CONNECTORS.md on ; npm may carry a newer patch. How coverage is measured.

What the connector calls on Swell

The connector calls Swell’s storefront (Frontend) REST API at https://{store}.swell.store/api for the shop, and reaches the Backend API at https://api.swell.store only from the server, with no /v1 prefix.

Storefront requests send Authorization: Basic with the base64 of the public key alone, and the shopper’s session, which is also the cart, travels in the X-Session header: the connector reads the rotated token from every response, replays it on every request with X-Locale and X-Currency, and keeps it in a swell-session cookie; there is no token refresh.

Requests the @misiki/swell-connector source makes, by storefront service
ServiceWhat it requests
productGET /api/products with page, limit, sort and search, and GET /api/products/{slug or id} with expand[0]=variants&expand[1]=categories
categoryGET /api/categories and GET /api/categories/{id}; a category’s products come from GET /api/products?categories=
searchGET /api/products with search, plus two one-row GET /api/products queries sorted price asc and price desc for the price range facet
cartGET /api/cart, POST /api/cart/items, PUT and DELETE /api/cart/items/{id}, PUT /api/cart/coupon with code and DELETE /api/cart/coupon
checkoutPUT /api/cart with billing: { method } (and shipping: { service } for the rate), then POST /api/cart/order
payment-methodGET /api/settings/payments, which is also where the cash on delivery method id is looked up
authPOST /api/account/login with { email, password }, POST /api/account to register, GET /api/account and POST /api/account/logout
addressGET /api/account/addresses, POST /api/account/addresses, and PUT and DELETE /api/account/addresses/{id}

Swell rules the connector follows

Read from the source of misiki-in/swell-connector at commit ce0b4c8 of . Where the code has changed since, the code is right.

Quick start

From nothing to a Svelte Commerce storefront reading Swell. You need Node.js and a Swell to point it at; the storefront holds no data of its own.

Clone it, choose the connector, point it at Swell

# 1 — get the storefront
git clone https://github.com/itswadesh/svelte-commerce
cd svelte-commerce

# 2 — one connector at a time: remove the two the storefront ships with, add this one
npm uninstall @misiki/litekart-connector @misiki/vendure-connector
npm i @misiki/swell-connector

# 3 — point it at your Swell store
echo PUBLIC_SWELL_API_URL=https://your-store.swell.store >> .env
echo PUBLIC_SWELL_API_KEY=pk_... >> .env

# 4 — run it
npm run dev

Switching works the same way on every backend: what all 26 share, from one connector at a time to store identity.

Environment variables

What Svelte Commerce reads to reach Swell
VariableRequiredWhat it does
PUBLIC_SWELL_API_URLYesYour storefront origin, such as https://<store>.swell.store. Boot fails, naming this variable, if it is missing.
PUBLIC_SWELL_API_KEYNoThe store’s public key, sent on its own as HTTP Basic to the storefront API.
PUBLIC_SWELL_STORE_IDNoThe store ID. With the secret key it authenticates Swell’s Backend API, which the connector refuses to call from a browser.
PUBLIC_SWELL_API_SECRETNoThe secret key, for Backend API calls. See the limitations before setting it.
PUBLIC_CONNECTORNoOnly when more than one connector is installed: @misiki/swell-connector names the one this build runs on.

init.ts hands the connector every PUBLIC_SWELL_* variable that is set, camel-cased. The guide also lists PUBLIC_SWELL_ACCESS_TOKEN, PUBLIC_SWELL_ACCESS_KEY and PUBLIC_SWELL_CHANNEL_ID; the connector’s source does not read them.

Every variable here begins PUBLIC_, and SvelteKit sends PUBLIC_ variables to the browser: treat each value you set as published.

What to set up on Swell

How the integration works

Swell has two APIs. The storefront API takes the public key alone as HTTP Basic, and it is the one the storefront calls. The Backend API takes the store ID and secret key, and the connector refuses to call it from a browser.

Limitations on Swell

Before you rely on it

No connector has been exercised against a live production instance of its platform; each was written from the platform’s published source. The limits every backend shares and the errors every switch can meet are on the backends page.

Offer a sandbox or a correction

FAQ

Questions about Svelte Commerce on Swell

Can I run a Swell store on Svelte Commerce today?

Cart, checkout and sign-in are wired; reviews, wishlist, vendors and states are not. Like every connector, it has not been run against a live production Swell store.

How do I switch Svelte Commerce to Swell?

Remove the connectors the storefront ships with, install @misiki/swell-connector, set PUBLIC_SWELL_API_URL in .env and start the dev server. vite.config.ts resolves whichever connector is installed, so no file in the storefront changes.

Which Swell keys does the storefront need?

The public key, for the storefront API. The secret key is for Swell’s Backend API, which the connector will not call from a browser — and because every PUBLIC_ variable reaches the browser, it is better left unset.

Sources

SWELL.md, read on ; CONNECTORS.md, read on ; the connector’s source at ce0b4c8. Where they disagree with this page, they are right. Swell is a trademark of its owner, named only to describe compatibility; see trademarks.

Read the whole guide

Chat on WhatsApp