@varyar/vy-ecom-core
v2.2.0
Published
VarYar product, category, and bill API client for Ecommerce platforms
Maintainers
Readme
@varyar/vy-ecom-core
One-import client for the VarYar Ecommerce API. Products, categories, and bills — all in two lines. Works with any storefront.
Install
npm install @varyar/vy-ecom-coreQuick start
import { vy } from "@varyar/vy-ecom-core";
// Products
const { products } = await vy().getProducts();
const tee = await vy().getProductBySlug("classic-tee");
const featured = await vy().getFeaturedProducts(4);
// Categories
const categories = await vy().getCategories();
// Bill (on checkout)
const bill = await vy().createBill({
client_order_id: "ORD-123",
total_amount: 49900,
line_items: [{ name: "Classic Tee", quantity: 1, unit_price: 49900, total_price: 49900 }],
});
// Patch bill after payment webhook
await vy().updateBillStatus({ bill_id: bill.bill_id, payment_status: "paid" });Environment variables
Set these in your .env:
VARYAR_BASE_URL=https://varyar-ecommerce.vercel.app
VARYAR_BUSINESS_UID=VYB-XXXXXXXX
VARYAR_INBOUND_API_KEY=your_inbound_keyAPI
vy(config?) — singleton factory
Returns a cached VyEssentials instance. Pass config to override env vars or create a
separate named instance.
const vy2 = new VyEssentials({ baseUrl: "...", businessUid: "...", apiKey: "..." });Products
| Method | Returns |
|---|---|
| vy().getProducts({ page?, pageSize? }) | { products, total, page, pageSize } |
| vy().getProductById(id) | VyProduct \| null |
| vy().getProductBySlug(slug) | VyProduct \| null |
| vy().getFeaturedProducts(limit?) | VyProduct[] |
| vy().getProductsByCategory(categoryId) | VyProduct[] |
Categories
| Method | Returns |
|---|---|
| vy().getCategories() | VyCategory[] |
| vy().getCategoryById(id) | VyCategory \| null |
Bills
| Method | Returns |
|---|---|
| vy().createBill(input) | VyBillResult |
| vy().updateBillStatus(patch) | void |
Notes
- Server-only. Never import this in client bundles — it reads
process.env. - All product/category reads filter
is_active: trueautomatically. getProductBySlugandgetProductsByCategoryfetch the full page internally. For large catalogs add a slug/category index on the ecommerce side.
