@selorax/data
v0.1.2
Published
SeloraX data SDK — typed storefront reads (products, store, collections).
Readme
@selorax/data
Typed storefront data SDK for the SeloraX Pages platform — read products, the store, categories, and collections from the storefront API.
npm i @selorax/data0.1.0 · pre-1.0 (expect 0.x minor bumps for breaking changes).
What it is
SeloraX Pages renders file-based storefronts (HTML/TSX) on a multi-tenant runtime. The data plane — products, the store, catalog — is served by the storefront API (/api/storefront/v1). @selorax/data is the typed client for that API: a set of small async read functions plus the TypeScript types for what they return.
It is one of the building blocks the @selorax/pages-cli and @selorax/runtime wire together, but it's a plain HTTP client with no SeloraX-runtime dependency, so you can use it standalone (e.g. in your own scripts or a custom renderer).
Usage
Reads take explicit context — (apiUrl, auth) — there is no module-level singleton, so the same SDK is safe to use for many tenants in one process.
import { getStore, getProducts, getProduct, makeBoundSdk } from '@selorax/data';
const apiUrl = 'https://your-host/api/storefront/v1';
const auth = { storeId: 22, secretKey: 'sk_live_…' }; // a per-tenant secret key
const store = await getStore(apiUrl, auth); // → Store
const { items, meta } = await getProducts(apiUrl, auth, { page: 1 }); // → { items: ProductCard[], meta }
const product = await getProduct(apiUrl, auth, 'gan-fast-charger'); // → Product (by slug)Auth (SeloraxAuth)
interface SeloraxAuth {
storeId: number;
secretKey?: string; // per-tenant secret key (sk_…) ← what most consumers use
serviceToken?: string; // platform service token (+ X-Selorax-Store-Id header) — internal
}Pass a secretKey for normal per-tenant access. serviceToken is the platform-internal mode.
Read functions
| Function | Returns |
|---|---|
| getStore(apiUrl, auth) | Store — name, settings, branding |
| getProduct(apiUrl, auth, slug) | Product — price, variants, gallery |
| getProducts(apiUrl, auth, opts?) | { items: ProductCard[]; meta: ListMeta } |
| getBestsellers(apiUrl, auth, opts?) | bestseller feed (same shape) |
| getCategories(apiUrl, auth) / getCategory(apiUrl, auth, slug) | category list / one category |
| getCollections(apiUrl, auth) / getCollectionProducts(apiUrl, auth, slug, opts?) | collections / a collection's products |
All return types are exported (Store, Product, Variant, Sku, ProductCard, Category, Collection, ListMeta, ProductFeedOpts, …).
makeBoundSdk — arg-free reads for tenant code
When rendering a tenant page you don't want to thread (apiUrl, auth) through every call. makeBoundSdk binds them once and returns an SDK whose methods are arg-free — this is what the runtime hands to tenant TSX (import { getStore } from '@selorax/data' resolves to the bound instance):
import { makeBoundSdk } from '@selorax/data';
const sdk = makeBoundSdk({ apiUrl, auth });
const store = await sdk.getStore(); // no args
const product = await sdk.getProduct(slug);Notes
- No singleton / no global state — every read is explicit-context, so it's concurrency- and multi-tenant-safe.
- Responses are unwrapped from the API's
{ data, … }envelope for you. - ESM only; ships compiled
dist/+.d.ts.
Part of SeloraX Pages
@selorax/data · @selorax/runtime · @selorax/platform · @selorax/compiler · @selorax/pages-cli
