Configuration
All StorefrontClientConfig options
StorefrontClientConfig
| Option | Type | Required | Description |
|---|---|---|---|
publicKey | string | ✅ | Public storefront key (sfp_…). Safe to expose in the browser. |
baseUrl | string | ✅ | API base URL — https://api.avvyr.com in production. |
marketId | string | ✅ | ID of the market to scope all requests to. |
privateKey | string | — | Private key (sfs_…). Server-side only. |
fetch | typeof fetch | — | Custom fetch implementation. Useful in edge runtimes or tests. |
headers | Record<string, string> | — | Extra headers added to every request. |
Per-request access tokens
The client manages two tokens internally — you don't set them in the config:
| Token | Set by | Used for |
|---|---|---|
cartAccessToken | cart.create() / cart.redeemShared() | x-cart-token header on all cart mutation endpoints |
customerAccessToken | auth.login() / auth.verifyMagicLink() | Authorization: Bearer header |
Both tokens are stored on the HttpClient instance and sent automatically on subsequent calls.
Multiple markets
Create one client per market when you need to handle multiple simultaneously:
const seClient = createStorefrontClient({ ..., marketId: 'market-id-se' })
const noClient = createStorefrontClient({ ..., marketId: 'market-id-no' })
Custom fetch (edge / tests)
// Cloudflare Workers
const client = createStorefrontClient({
publicKey: env.STOREFRONT_PUBLIC_KEY,
baseUrl: 'https://api.avvyr.com',
marketId: env.MARKET_ID,
fetch: fetch, // Workers global fetch
})
// Mocking in tests
const client = createStorefrontClient({
publicKey: 'sfp_test',
baseUrl: 'https://api.avvyr.com',
marketId: 'test-market',
fetch: mockFetch,
})