commerce-kit
Version:
102 lines (99 loc) • 3.18 kB
TypeScript
import { q as YnsProviderConfig, k as ProductBrowseParams, l as ProductBrowseResult, m as ProductGetParams, P as Product, o as ProductSearchParams, p as ProductSearchResult, a as CartAddParams, C as Cart, f as CartUpdateParams, e as CartRemoveParams, b as CartClearParams, c as CartGetParams, h as OrderGetParams, O as Order, i as OrderListParams, j as OrderListResult } from './provider-CeP9uHnB.js';
/**
* YNS Commerce client - zero-config constructor with GraphQL support
* Reads configuration from environment variables by default
*
* @example
* ```typescript
* import { Commerce } from "commerce-kit/yns";
*
* // Zero config - uses YNS_ENDPOINT and YNS_TOKEN from environment
* const commerce = new Commerce();
*
* // GraphQL field selection supported
* const products = await commerce.product.browse({
* first: 10,
* fields: ["id", "name", "price", "category.name"]
* });
*
* const orders = await commerce.order.list({ first: 5 });
* ```
*/
declare class Commerce {
private config;
private provider?;
private providerPromise?;
constructor(config?: YnsProviderConfig);
/**
* Detect YNS configuration from environment variables
*/
private detectFromEnv;
/**
* Lazy-load and cache provider instance
*/
private getProvider;
/**
* Load YNS provider
*/
private loadProvider;
/**
* Product operations - YNS specific with GraphQL support
*/
get product(): {
/**
* Browse/list products with GraphQL field selection
*/
browse: (params?: ProductBrowseParams) => Promise<ProductBrowseResult>;
/**
* Get single product by ID or slug with field selection
*/
get: (params: ProductGetParams) => Promise<Product | null>;
/**
* Search products with GraphQL support
*/
search: (params: ProductSearchParams) => Promise<ProductSearchResult>;
};
/**
* Cart operations - Simplified API
*/
get cart(): {
/**
* Add items to cart (additive behavior)
* If cartId is provided, adds to existing quantity
* If no cartId, creates new cart
*/
add: (params: CartAddParams) => Promise<Cart>;
/**
* Update item in cart (absolute behavior)
* Sets quantity to exact number
* Requires cartId
*/
update: (params: CartUpdateParams) => Promise<Cart>;
/**
* Remove specific item from cart
*/
remove: (params: CartRemoveParams) => Promise<Cart>;
/**
* Clear entire cart
*/
clear: (params: CartClearParams) => Promise<Cart>;
/**
* Get cart details
*/
get: (params: CartGetParams) => Promise<Cart | null>;
};
/**
* Order operations - YNS specific
*/
get order(): {
/**
* Get single order
*/
get: (params: OrderGetParams) => Promise<Order | null>;
/**
* List orders with GraphQL field selection
*/
list: (params?: OrderListParams) => Promise<OrderListResult>;
};
}
export { Commerce };