# SDK Core URL: https://theelena.me/docs/avileo/tiendas/sdk-core Text: https://theelena.me/docs/avileo/tiendas/sdk-core.txt Description: Integra Avileo desde TypeScript o JavaScript sin depender de React. Context: environment=production; apiBaseUrl=https://tienda.theelena.me; activation=active; rubro=tiendas # SDK Core The core `@tarileo/avileo-sdk` package works in the browser, Node, edge functions, or any runtime with `fetch`. ## Create the client ```ts import { createAvileo } from '@tarileo/avileo-sdk'; const avileo = createAvileo({ baseUrl: 'https://tienda.theelena.me', clientKey: 'avileo_pk_...', }); ``` `createAvileo({ baseUrl, clientKey })` normalizes the base URL and sends `x-avileo-client-key` on every request. It also accepts: | Field | Type | Usage | | ----------- | -------------- | --------------------------------------------------- | | `baseUrl` | `string` | API base URL, with no required trailing slash. | | `clientKey` | `string` | The business public Client Key. | | `fetch` | `typeof fetch` | Custom fetch for tests, SSR, or polyfills. | | `timeoutMs` | `number` | Request timeout implemented with `AbortController`. | ## Business scope ```ts const store = avileo.business(); const profile = await store.getInfo(); ``` `avileo.business()` returns a `BusinessScope` already bound to the Client Key. Do not pass `businessSlug`; the backend resolves the tenant from the key. ## Available resources ### Profile ```ts const profile = await store.getInfo(); const canUseSessions = await store.has('sessions'); ``` `BusinessScope.getInfo()` caches the public profile for the lifetime of the scope. ### Catalog ```ts const { business, categories, products } = await store.catalog.list({ search: 'chicken', categoryId: 'cat_123', }); ``` ### Assets Before composing a hero, gallery, or visual section, inspect the tenant's real public images: ```ts const assets = await store.assets.list({ search: 'fachada', mimeType: 'image/webp', limit: 24, offset: 0, }); ``` `assets.items` contains only active, non-deleted, non-hidden image assets for the Client Key tenant. Each item exposes `id`, `description`, `mimeType`, optional `width`/`height`, `createdAt`, and an absolute stable `url` ending in `/api/v1/public/sdk/assets/:id/render`. It never exposes storage paths, signed URLs, asset metadata, original filenames, or owner data. The response also includes `total`, `limit`, and `offset` for pagination. ### Sessions ```ts const settings = await store.sessions.getSettings(); const lookup = await store.sessions.lookup({ itemCode: 'ABC-123' }); const quote = store.sessions.quoteLocal(lookup, new Date()); ``` Use sessions only if the business has that public capability. ### Carts ```ts const cart = await store.carts().create(); await cart.addItem({ productId: 'prod_1', variantId: 'var_1', quantity: 2 }); await cart.checkout({ customerName: 'Jane', customerPhone: '999999999' }); ``` `carts().create()` returns a `Cart` with a `token`. The token identifies the draft and lets you rehydrate it: ```ts const cart = store.carts().fromToken(savedToken); const sale = await cart.get(); ``` ### Orders ```ts const order = await store.orders.get(token); await store.orders.cancel(token, order.sale.version); ``` ### Payments ```ts const payment = await store.payments.get('paytoken_123'); ``` ## Direct access `createAvileo` also exposes `currentBusiness` for callers that prefer a stable property and `leads` for public lead capture.