Skip to main content
This page is the curated reference. The complete, generated type reference for the root entry lives at /kit/api/core and is regenerated from the published typings.
Available from @quickbutik/kit and @quickbutik/kit/sdk. On a script-tag page the same function is Quickbutik.createShopkitClient. A client is cheap. Create one per app in the browser and one per request on the server, because the cookie accessor belongs to that request. See Storage & SSR.

createShopkitClient

Throws ShopkitConfigError synchronously for a malformed key (including a qb_pat_… token), a malformed campaign storefront id, an unknown surface, or two conflicting storefront ids.

ShopkitConfig

Only publishableKey is required.
string
required
The shop’s publishable key, qb_pk_<shopPrefix>_<secret>. Safe to ship to a browser. A qb_pat_… personal access token is rejected with a ShopkitConfigError.
string
default:"https://commerce.quickbutik.com"
Commerce API origin. Leave it unset in production. A trailing /v2 is stripped, since every request path carries its own /v2.
string
default:"https://pay.quickbutik.com"
Origin of the hosted checkout (checkout-v2). When you set it explicitly it wins over the URL the platform returns for a checkout-v2 handoff. Use it only for a preview environment or a checkout proxied onto your own domain. It is ignored for a shop on the legacy checkout.
string
Fallback base for image paths. Rarely needed, because images already arrive with an absolute url. It is the shop-scoped base without the products/ segment, for example https://cdn.quickbutik.com/images/<shopPrefix>.
ShopkitScope[] | string[] | null
default:"DEFAULT_SHOPKIT_SCOPES"
The scopes the key carries, used for a local pre-flight check that throws a named ShopkitScopeError before the request leaves the process. Pass null to turn the check off. The platform enforces scopes either way. See Errors & scopes.
'auto' | 'cookie' | 'localStorage' | 'memory' | StorageAdapter
default:"auto"
Where the cart id, checkout session id and a logged-in customer’s session are remembered. auto picks server cookies when cookies is given, then document.cookie, then localStorage, then memory. Resolution never throws; an unusable choice degrades to memory.
CookieAccessor
Server-side cookie access: get(name), plus optional set(name, value, attributes), remove(name, attributes) and getAll(). Each may return a promise. Supplying it is what lets a server render see the browser’s cart, currency and consent decision. A read-only accessor (only get) is valid; writes are then dropped silently.
Attributes for the cookies the kit writes.
Cookie consent and the shop’s analytics, on by default. <ShopkitProvider>, the elements and checkout.start() on a server client all read this one setting, so the browser and the server agree.
  • An object sets the cookie-policy revision (default 1; bump it to ask every shopper again) and the consent cookieName (default qb_consent) for all of them at once.
  • false turns the whole layer off: no banner, no consent store, no analytics, and nothing appended to hosted checkout URLs.
See Consent and analytics.
string | null
The currency to browse in ("EUR", any case) until the shopper picks one with setCurrency(). Every product read and cart request then carries ?currency=, and every checkout session and handoff carries currency. Omitted or null: the shop’s own currency, and nothing is sent. A value that is not a three-letter ISO 4217 code throws a ShopkitConfigError.It is a default, not an override: a choice made with setCurrency() is remembered under ${storageKeyPrefix}_currency and wins on later visits. See Currencies.
{ id: string; surface?: StorefrontSurface } | null
Bind this client to one campaign storefront (a Säljsida). Product reads are priced for the campaign, carts are created bound to it and checkouts are attributed to it. surface defaults to "shopkit". Also changes the default storageKeyPrefix. See Campaign storefronts.
string | null
Shorthand for storefront: { id }. May be given together with storefront only when both name the same campaign (compared case-insensitively). null and "" mean not set.
string
default:"qb"
Prefix for the remembered keys (qb_cart_id, qb_store_id, qb_checkout_session, qb_checkout_store, qb_currency, qb_customer_session). Defaults to qb_<storefront id lower-cased> on a client bound to a campaign. Change it to run two shops in one browser.
number
default:"2592000"
Lifetime of the remembered cart id (30 days).
typeof fetch
default:"globalThis.fetch"
Injected fetch, for tests or a framework’s instrumented fetch.
number
default:"15000"
Per-request timeout. 0 disables it.
number
default:"2"
Retries for transient failures (network error, 429, 5xx). Mutations carry an automatic Idempotency-Key, so a retried POST /cart cannot create a second cart. Do not wrap cart mutations in a retry loop of your own.
Record<string, string>
default:"{}"
Extra headers on every request. An authorization header is ignored; it can never override the key.
() => string | null | Promise<string | null>
Called when a request answers 401. Return a fresh key to adopt it and retry the request once. Concurrent 401s share one refresh. Return null to let the 401 surface. A 401 about the shopper rather than the key (invalid_credentials, an expired customer token) never calls it.
{ renew?: boolean }
default:"{}"
How this client treats a logged-in customer’s session. renew: false uses the access token while it is valid but never renews it; an expired one is treated as a guest for this client’s requests. Renewal is already off on storage that cannot be written (StorageAdapter.writable: false: a cookie accessor without set, or createRequestCookieStorage() without collect), because the rotated refresh token would be lost. See Customer accounts.

ShopkitClient

ProductsResource
CategoriesResource
CartResource
See Cart.
CheckoutResource
ShopResource
CustomersResource
Customer login, registration, password reset, logout, profile and club points. See Customers below.
string
The shop’s storage prefix decoded from the key (the CDN folder its images live under). Not the numeric shop id the hosted checkout needs; that one is cart.storeId.
string
Deprecated alias of shopPrefix.
string
Resolved commerce API origin.
string
Resolved hosted checkout origin.
string | null
Resolved image fallback base.
{ id: string; surface: StorefrontSurface } | null
The campaign storefront binding, or null.
ScopeGuard
string | null
The currency the client browses in: the shopper’s remembered choice, else the configured currency, else null (the shop’s own). Synchronous. With an async-only cookie accessor (Next’s cookies()) it reports the configured default; requests still read the stored choice. What prices actually came back in is on the response (product.currency, cart.currency).
string | null
The configured currency, ignoring any choice.
StorageAdapter
The resolved storage adapter.
ShopkitRuntimeInfo

setCurrency

Browse in another currency: remember it (under ${storageKeyPrefix}_currency, for a year) and notify onCurrencyChange subscribers. null forgets the choice and returns to the configured default. The cart is unchanged: it is priced per request, so the same cart reads in the new currency next time. Throws a ShopkitConfigError for a value that is not a three-letter code. A well-formed code the shop does not offer is accepted and resolves to the shop’s currency server-side. See Currencies.

onCurrencyChange

Be told when currency changes through setCurrency(). Returns an unsubscribe function. The React hooks and the elements use it to refetch prices and re-read the cart. A choice written elsewhere (another tab, a server action, a second client sharing the storageKeyPrefix) changes the next request without firing it.

Customers

Once a customer is logged in, every request the client makes carries their token as X-Customer-Token (the key keeps Authorization), so catalog, cart and checkout are priced for the customer’s group. The kit renews the token before it expires. Every call needs the customer:session scope; config() also accepts storefront:read.
Promise<CustomerAccountsConfig>
The shop’s settings: login.enabled, login.signupAllowed, login.hidePricesForGuests, login.hideAddToCartForGuests, customerGroups.enabled, customerClub.enabled and customerClub.joinMethod. Read once per client.
Promise<CustomerSession>
Log in and remember the session. Resolves with { customer, accessToken, accessTokenExpiresAt, refreshToken, refreshTokenExpiresAt }. Throws a ShopkitAuthError: invalid_credentials, customer_blocked, customer_login_disabled, rate_limited. Logging in as a different customer forgets the cart.
Promise<CustomerRegisterResult>
Create an account (1.10.0). { email, password, firstName, lastName, companyName?, companyNumber?, clubOptIn? }. Resolves with { status: "logged_in", ...session } for a new email, logged in exactly like login(); { status: "verification_required" } for the email of an earlier guest customer, where a code is emailed and resetPassword() finishes the registration; or, rarely, { status: "login_required" } when the account was created but no session could be opened. Throws a ShopkitAuthError: signup_disabled, email_taken, invalid_email, invalid_name, invalid_password, customer_login_disabled, rate_limited. See Registration.
Promise<void>
Email a one-time reset code (1.10.0) to the account with { email }. Resolves the same way whether or not the account exists. The code is valid for 30 minutes, and a new request replaces it. Throws only customer_login_disabled and rate_limited.
Promise<CustomerSession>
Set a new password with the emailed code and log in, exactly like login() (1.10.0). { email, code, password }; the code ignores case, spaces and dashes. Every other session of the customer ends. Throws a ShopkitAuthError: invalid_reset_code, invalid_password, customer_blocked, customer_login_disabled, rate_limited, or password_changed_login_required when the password was changed but no session could be opened. See Password reset.
Promise<void>
Revoke the session on the platform (best effort), then always forget it locally, with the cart id and the checkout session handle. Never throws.
Promise<Customer | null>
The profile and group. null for a guest (no request is made), or when the session ended or changed hands during the read. Concurrent calls share one request.
Promise<CustomerClub | null>
{ member, active, points: { balance, lifetime }, reward: { targetPoints, remaining }, earning: { pointsPerUnit, currency } }, or null for a guest.
Promise<void>
Adopt a session minted elsewhere: { accessToken, refreshToken?, accessTokenExpiresAt?, refreshTokenExpiresAt? }. Without accessTokenExpiresAt, the token’s own exp is used. Rejects with a ShopkitConfigError for an empty token or an unparseable expiry.
Promise<string | null>
A valid access token, renewed first when it expires within 30 seconds; null for a guest or when the session could not be renewed. Also the way to read the session explicitly from async-only storage.
() => void
Called with { customerId, customer } on login and on a newly read profile, and with null on logout or when the session ends. In a browser the same change is dispatched on document as qb:customer, with { customerId } only.
boolean
Synchronous. With an async-only adapter (Next’s cookies()) it is false until the session has been read.
Customer | null
The profile last returned by login(), register(), resetPassword() or me() in this client.
string
Who the client’s requests are made for, changing on every login and logout. Key your own caches of customer-priced data on it.
See Customer accounts.

withStorage

Returns a copy of the client bound to different storage. The copy drops any cookies accessor, so the adapter you pass is the one used. This is the idiomatic way to reuse one configuration across many server requests:

Configuration helpers

Key rotation

A 401 calls the handler, adopts the returned key and retries the request once. This is outside the normal retry budget: a 401 is a stale credential, not a transient failure.