Skip to content
Aystra

DevelopersDocs

Storefront SDK

Run your own front end on Aystra Storefront. One import, no keys, typed methods for catalog, booking, orders and reviews.

v1.0.0 · Preview · Updated

Preview. v1 is not live yet. Names and signatures may still change before launch. Request early access

Quick start

The Storefront SDK lets your own site read a shop’s catalog and take its orders and bookings. The shop owner manages everything in Aystra Storefront; your code only calls the SDK.

v1 is in preview. The module address below goes live at launch; until then, request early access and we will set up a storefront for you to build against.

<script type="module">
  import getStorefront from 'https://cdn.aystra.co/storefront-sdk/v1/sdk.js';

  const storefront = await getStorefront();
  const services = await storefront.getServices();
  for (const service of services) {
    console.log(service.name.en, service.price, service.duration_minutes);
  }
</script>

That is the whole setup. There is no access token to copy and nothing secret in your code.

Every method below has a Run button that answers from a simulated shop, so you can see real response shapes and each error case. To see the calls in order on a working site, open the example flows.

Install

The SDK is an ES module on the Aystra CDN. getStorefront is its default export; AystraError is a named export.

import getStorefront, { AystraError } from 'https://cdn.aystra.co/storefront-sdk/v1/sdk.js'

Import it from any <script type="module"> or from your own module code. Nothing is added to window.

v1 always serves the latest 1.x release, so fixes reach your site without a deploy.

To lock an exact release, import the pinned address and give its hash in an import map. The browser then refuses the file if a single byte differs. Each release note lists its hash.

<script type="importmap">
  {
    "integrity": {
      "https://cdn.aystra.co/storefront-sdk/1.0.0/sdk.js": "sha384-…"
    }
  }
</script>
<script type="module">
  import getStorefront from 'https://cdn.aystra.co/storefront-sdk/1.0.0/sdk.js';
</script>

Pin when your site goes through a release review or a security audit. Use v1 otherwise.

getStorefront()

const storefront = await getStorefront(options?)

Returns a promise for the storefront. It finds the shop from the page’s own domain (location.hostname), so on the shop’s live site you pass nothing.

Option Type Default What it does
domain string location.hostname The shop’s domain. Set it on preview and staging hosts.
locale 'en' | 'uk' | 'es' 'en' Language recorded on orders.
timeoutMs number 15000 How long a request may take before it fails.
const storefront = await getStorefront({ domain: 'studio-example.com' })

Text fields come in all three languages at once, as { en, uk, es }. Pick the one your page shows: service.name.en. Fields that may be empty use null per language. Prices are plain numbers in the shop’s currency.

Catalog

getProducts()

Every published product, in the order the shop owner set in the admin.

storefront.getProducts(): Promise<Product[]>

const products = await storefront.getProducts()

A product with status: "unavailable" is listed but cannot be ordered.

ResponseSimulated data

Press Run to call getProducts with this case.

Errors: rate_limited, storefront_not_found

getProduct()

One product for a product page, with its variants and prices.

storefront.getProduct({ slug }): Promise<Product>

ParameterTypeNotes
slugstringRequired. From a product list or your URL.
const product = await storefront.getProduct({ slug: 'nail-polish' })

ResponseSimulated data

Press Run to call getProduct with this case.

Errors: product_not_found, rate_limited, storefront_not_found

getProductCategories()

Categories for the shop menu.

storefront.getProductCategories(): Promise<Category[]>

const categories = await storefront.getProductCategories()

Categories marked for both products and services appear here and in getServiceCategories(). Empty categories are left out.

ResponseSimulated data

Press Run to call getProductCategories with this case.

Errors: rate_limited, storefront_not_found

getProductsByCategory()

The products in one category.

storefront.getProductsByCategory({ slug }): Promise<Product[]>

ParameterTypeNotes
slugstringRequired. A product category slug.
const products = await storefront.getProductsByCategory({ slug: 'nail-care' })

ResponseSimulated data

Press Run to call getProductsByCategory with this case.

Errors: category_not_found, rate_limited, storefront_not_found

getServices()

Every bookable service, with price, duration, add-ons and the staff who perform it (provider_ids).

storefront.getServices(): Promise<Service[]>

const services = await storefront.getServices()

ResponseSimulated data

Press Run to call getServices with this case.

Errors: rate_limited, storefront_not_found

getService()

One service for a service page or a booking form.

storefront.getService({ slug }): Promise<Service>

ParameterTypeNotes
slugstringRequired.
const service = await storefront.getService({ slug: 'classic-manicure' })

ResponseSimulated data

Press Run to call getService with this case.

Errors: service_not_found, rate_limited, storefront_not_found

getServiceCategories()

Categories for the services menu.

storefront.getServiceCategories(): Promise<Category[]>

const categories = await storefront.getServiceCategories()

ResponseSimulated data

Press Run to call getServiceCategories with this case.

Errors: rate_limited, storefront_not_found

getServicesByCategory()

The services in one category.

storefront.getServicesByCategory({ slug }): Promise<Service[]>

ParameterTypeNotes
slugstringRequired. A service category slug.
const services = await storefront.getServicesByCategory({ slug: 'manicure' })

ResponseSimulated data

Press Run to call getServicesByCategory with this case.

Errors: category_not_found, rate_limited, storefront_not_found

getPackages()

Bundles of services sold together, with price, list_price and how long they stay valid.

storefront.getPackages(): Promise<Package[]>

const packages = await storefront.getPackages()

ResponseSimulated data

Press Run to call getPackages with this case.

Errors: rate_limited, storefront_not_found

getGallery()

Images for a portfolio page, each with a responsive srcset and alt text.

storefront.getGallery(): Promise<GalleryImage[]>

const images = await storefront.getGallery()

ResponseSimulated data

Press Run to call getGallery with this case.

Errors: rate_limited, storefront_not_found

Booking

getStaff()

Staff members with their working hours, for a "choose who" step.

storefront.getStaff(): Promise<Staff[]>

const staff = await storefront.getStaff()

ResponseSimulated data

Press Run to call getStaff with this case.

Errors: rate_limited, storefront_not_found

getOpenDates()

Days that still have at least one free slot, for a calendar. Past days, closed days and fully booked days are left out.

storefront.getOpenDates({ service, from, to, staff? }): Promise<OpenDates>

ParameterTypeNotes
servicenumberRequired.
from, tostringRequired. YYYY-MM-DD, at most 62 days apart.
staffnumber | 'any'Optional. Defaults to 'any'.
const openDates = await storefront.getOpenDates({ service: 11, from: '2027-01-04', to: '2027-01-31' })

ResponseSimulated data

Press Run to call getOpenDates with this case.

Errors: rate_limited, storefront_not_found

getAvailability()

Every slot of one day, free or taken. Show times in the returned timezone, not the visitor’s.

storefront.getAvailability({ service, staff, date }): Promise<Availability>

ParameterTypeNotes
servicenumberRequired.
staffnumber | 'any'Required. With 'any', each free slot says which staff member it belongs to.
datestringRequired. YYYY-MM-DD
const day = await storefront.getAvailability({ service: 11, staff: 'any', date: '2027-01-05' })

ResponseSimulated data

Press Run to call getAvailability with this case.

Errors: rate_limited, storefront_not_found

getTimeOff()

Holidays and days off in a range. staff: null means the whole shop is closed.

storefront.getTimeOff({ from, to, staff? }): Promise<TimeOff[]>

ParameterTypeNotes
from, tostringRequired. YYYY-MM-DD
staffnumberOptional. Only this staff member, plus days the whole shop is closed.
const timeOff = await storefront.getTimeOff({ from: '2027-01-01', to: '2027-01-31' })

ResponseSimulated data

Press Run to call getTimeOff with this case.

Errors: rate_limited, storefront_not_found

createAppointment()

Books a slot. It appears in the shop’s calendar at once. Show the returned code to the customer.

storefront.createAppointment(input): Promise<CreateAppointmentResult>

ParameterTypeNotes
servicenumberRequired.
staffnumber | 'any'Required.
start_atstringRequired. A free slot’s start_at from getAvailability().
customer{ name, email?, phone? }Required. Email or phone is required.
notesstringOptional.
addons{ addon, quantity }[]Optional.
const booking = await storefront.createAppointment({
  service: 11,
  staff: 'any',
  start_at: '2027-01-05T10:00:00+01:00',
  customer: { name: 'Ada Example', email: 'ada@example.com' },
})

On slot_taken, load the day again with getAvailability() and ask the customer to pick another time.

ResponseSimulated data

Press Run to call createAppointment with this case.

Errors: slot_taken, slot_unavailable, invalid_input, bot_check_failed, rate_limited

Orders and promo codes

validatePromoCode()

Checks a code before checkout. A code that does not apply returns { ok: false, reason }, not an error.

storefront.validatePromoCode({ code }): Promise<PromoValidation>

ParameterTypeNotes
codestringRequired. Case does not matter.
const promo = await storefront.validatePromoCode({ code: 'WINTER10' })

ResponseSimulated data

Press Run to call validatePromoCode with this case.

createOrder()

Places an order. The shop sees it in the admin at once. Prices and discounts are calculated on the server, so prices sent from the page are never used.

storefront.createOrder(input): Promise<CreateOrderResult>

ParameterTypeNotes
namestringRequired.
email, phonestringRequired. At least one.
items{ slug, quantity, variant? }[]Optional. Items, packages or both.
packages{ slug, quantity? }[]Optional.
promo_codestringOptional.
pickup_day, pickup_timestringOptional. When the shop offers pickup.
notesstringOptional.
const order = await storefront.createOrder({
  name: 'Ada Example',
  email: 'ada@example.com',
  items: [
    { slug: 'cuticle-oil', quantity: 2 },
    { slug: 'nail-polish', quantity: 1, variant: 1031 },
  ],
  promo_code: 'WINTER10',
})

ResponseSimulated data

Press Run to call createOrder with this case.

Errors: product_unavailable, invalid_input, bot_check_failed, rate_limited

Reviews

getReviews()

Published reviews with rating, comment, author and date.

storefront.getReviews(): Promise<Review[]>

const reviews = await storefront.getReviews()

ResponseSimulated data

Press Run to call getReviews with this case.

Errors: rate_limited, storefront_not_found

createReview()

Only real customers can review: the order must be fulfilled, or the appointment completed. New reviews wait for the shop owner’s approval.

storefront.createReview(input): Promise<CreateReviewResult>

ParameterTypeNotes
source_type'order' | 'appointment'Required.
source_id, codenumber, stringRequired. From the order or booking result.
customer_emailstringRequired. The email used for that order or booking.
ratingnumberRequired. 1 to 5.
titlestringOptional.
commentstringRequired.
const review = await storefront.createReview({
  source_type: 'order',
  source_id: 5001,
  code: 'LMN-4K2P',
  customer_email: 'ada@example.com',
  rating: 5,
  comment: 'Lovely oil, will buy again.',
})

ResponseSimulated data

Press Run to call createReview with this case.

Errors: not_ratable, invalid_input

Errors

Every failed call rejects with an AystraError:

import getStorefront, { AystraError } from 'https://cdn.aystra.co/storefront-sdk/v1/sdk.js'

try {
  await storefront.createOrder(input)
} catch (err) {
  if (err instanceof AystraError && err.code === 'rate_limited') {
    // wait and retry
  }
  console.error(err.status, err.code, err.detail)
}

code is stable and safe to branch on. detail is a sentence for you, not for the customer.

code Status Meaning
storefront_not_found 404 No shop is registered for this domain. Check domain.
product_not_found, service_not_found, category_not_found 404 No published item with this slug.
invalid_input 400 A field is missing or malformed. detail names it.
product_unavailable 409 An item is out of stock or no longer sold.
slot_taken 409 The slot was booked a moment ago.
slot_unavailable 409 The slot is outside working hours or blocked.
not_ratable 409 The order is not fulfilled, or the appointment not completed, yet.
bot_check_failed 403 The request did not pass the browser check.
rate_limited 429 Too many requests. Wait for retryAfter seconds.

Limits

Each shop has fair-use limits per visitor and per site, high enough for normal browsing and checkout. Over the limit, calls fail with rate_limited and err.retryAfter says how many seconds to wait. Catalog reads are cached at the edge, so reading the same list twice is cheap.

Security

  • No secrets in the browser. The SDK takes no key or token, so there is nothing to leak from your page source.
  • Only your domains. Calls are accepted only from domains registered to the shop in the Aystra admin.
  • Bot check on writes. Orders, bookings and reviews pass an invisible Cloudflare check inside the SDK. Your code does nothing extra and your visitors see no puzzle.
  • Totals on the server. Prices and discounts are recalculated by Aystra; a changed price in the browser has no effect.

Versioning

  • /storefront-sdk/v1/sdk.js receives fixes and new methods, never breaking changes.
  • /storefront-sdk/1.0.0/sdk.js and every other pinned release never change.
  • A breaking change ships as v2, at a new address, and v1 keeps working.

Coming later

  • Customer credits, such as remaining visits on a package. They arrive with customer login.
  • Website chat that answers from the shop’s FAQ, using the shop’s own AI provider key.

Tell us what you are building.

Take the two-minute estimate or send a note. We read it the same day.