@withvlibe/base-sdk 1.0.1 → 1.1.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -236,8 +236,7 @@ interface UsageMetric {
236
236
  period: string;
237
237
  createdAt: string;
238
238
  }
239
- interface Product {
240
- id: string;
239
+ interface Product extends BaseRecord {
241
240
  name: string;
242
241
  description?: string;
243
242
  sku?: string;
@@ -247,19 +246,21 @@ interface Product {
247
246
  stock: number;
248
247
  isActive: boolean;
249
248
  category?: string;
250
- createdAt: string;
251
- updatedAt: string;
249
+ metadata?: Record<string, any>;
252
250
  }
253
- interface Order {
254
- id: string;
251
+ interface Order extends BaseRecord {
255
252
  userId: string;
256
253
  status: 'pending' | 'processing' | 'shipped' | 'delivered' | 'cancelled';
257
254
  items: OrderItem[];
258
255
  subtotal: number;
259
256
  tax: number;
257
+ shipping: number;
260
258
  total: number;
261
259
  shippingAddress?: Address;
262
- createdAt: string;
260
+ billingAddress?: Address;
261
+ paymentMethodId?: string;
262
+ stripePaymentIntentId?: string;
263
+ notes?: string;
263
264
  }
264
265
  interface OrderItem {
265
266
  productId: string;
@@ -279,6 +280,76 @@ interface CartItem {
279
280
  productId: string;
280
281
  quantity: number;
281
282
  }
283
+ interface CartItemWithProduct {
284
+ productId: string;
285
+ quantity: number;
286
+ product: Product;
287
+ lineTotal: number;
288
+ }
289
+ interface CreateProductInput {
290
+ name: string;
291
+ description?: string;
292
+ sku?: string;
293
+ price: number;
294
+ currency: string;
295
+ images?: string[];
296
+ stock: number;
297
+ isActive?: boolean;
298
+ category?: string;
299
+ metadata?: Record<string, any>;
300
+ }
301
+ interface CreateOrderInput {
302
+ userId: string;
303
+ items: Array<{
304
+ productId: string;
305
+ quantity: number;
306
+ }>;
307
+ shippingAddress: Address;
308
+ billingAddress?: Address;
309
+ paymentMethodId?: string;
310
+ notes?: string;
311
+ }
312
+ interface OrderCalculation {
313
+ subtotal: number;
314
+ tax: number;
315
+ shipping: number;
316
+ total: number;
317
+ items: Array<{
318
+ productId: string;
319
+ name: string;
320
+ price: number;
321
+ quantity: number;
322
+ lineTotal: number;
323
+ inStock: boolean;
324
+ }>;
325
+ }
326
+ interface RevenueStats {
327
+ totalRevenue: number;
328
+ totalOrders: number;
329
+ averageOrderValue: number;
330
+ period: {
331
+ start: string;
332
+ end: string;
333
+ };
334
+ trend: {
335
+ revenue: number;
336
+ orders: number;
337
+ };
338
+ }
339
+ interface ProductStats {
340
+ productId: string;
341
+ name: string;
342
+ totalSold: number;
343
+ revenue: number;
344
+ }
345
+ interface OrderStats {
346
+ pending: number;
347
+ processing: number;
348
+ shipped: number;
349
+ delivered: number;
350
+ cancelled: number;
351
+ averageOrderValue: number;
352
+ }
282
353
  /**
283
354
  * Standard API response
284
355
  */
@@ -564,4 +635,133 @@ declare class VlibeBaseAuth {
564
635
  getBaseUrl(): string;
565
636
  }
566
637
 
567
- export { type AppCategory as A, type BasePlan as B, type ConnectStatus as C, type DatabaseConfig as D, type FeatureFlag as F, type Media as M, type Order as O, type PaymentsConfig as P, type QueryOptions as Q, type RefundOptions as R, type Subscription as S, type Transaction as T, type UsageMetric as U, VlibeBaseDatabase as V, type CheckoutOptions as a, type CheckoutSession as b, VlibeBaseAuth as c, type VlibeBaseConfig as d, type AuthConfig as e, type ColumnType as f, type TableColumn as g, type TableSchema as h, type TableInfo as i, type BaseRecord as j, type RealtimePayload as k, type VlibeUser as l, type VerifyResponse as m, type AuthSession as n, type Page as o, type Product as p, type OrderItem as q, type Address as r, type CartItem as s, type ApiResponse as t, type PaginatedResponse as u, type UseCollectionReturn as v, type UseCollectionOptions as w, type UseKVReturn as x, type UseAuthReturn as y, type UsePaymentsReturn as z };
638
+ /**
639
+ * VlibeBaseEcommerce - E-commerce functionality for Vlibe Base apps
640
+ *
641
+ * Provides specialized methods for managing products, inventory, orders,
642
+ * shopping carts, and e-commerce analytics.
643
+ */
644
+ declare class VlibeBaseEcommerce {
645
+ private db;
646
+ constructor(db: VlibeBaseDatabase);
647
+ /**
648
+ * Create a new product
649
+ * Auto-generates SKU if not provided
650
+ */
651
+ createProduct(input: CreateProductInput): Promise<Product>;
652
+ /**
653
+ * Update an existing product
654
+ */
655
+ updateProduct(productId: string, updates: Partial<Product>): Promise<Product>;
656
+ /**
657
+ * Get a single product by ID
658
+ */
659
+ getProduct(productId: string): Promise<Product | null>;
660
+ /**
661
+ * List products with filtering and pagination
662
+ */
663
+ listProducts(options?: {
664
+ category?: string;
665
+ isActive?: boolean;
666
+ sortBy?: 'name' | 'price' | 'stock' | 'created_at';
667
+ limit?: number;
668
+ offset?: number;
669
+ }): Promise<{
670
+ products: Product[];
671
+ total: number;
672
+ }>;
673
+ /**
674
+ * Soft delete a product (sets isActive = false)
675
+ */
676
+ deleteProduct(productId: string): Promise<void>;
677
+ /**
678
+ * Update product inventory with atomic operations
679
+ */
680
+ updateInventory(productId: string, quantity: number, operation: 'set' | 'increment' | 'decrement'): Promise<Product>;
681
+ /**
682
+ * Get products below stock threshold
683
+ */
684
+ getLowStockProducts(threshold?: number): Promise<Product[]>;
685
+ /**
686
+ * Bulk update inventory for multiple products
687
+ */
688
+ bulkUpdateInventory(updates: Array<{
689
+ productId: string;
690
+ quantity: number;
691
+ operation: 'set' | 'increment' | 'decrement';
692
+ }>): Promise<Product[]>;
693
+ /**
694
+ * Calculate order totals from cart items
695
+ */
696
+ calculateOrderTotal(items: CartItem[]): Promise<OrderCalculation>;
697
+ /**
698
+ * Create an order from cart items
699
+ * Reduces inventory atomically
700
+ */
701
+ createOrder(input: CreateOrderInput): Promise<Order>;
702
+ /**
703
+ * Get an order by ID
704
+ */
705
+ getOrder(orderId: string): Promise<Order | null>;
706
+ /**
707
+ * List orders with filtering
708
+ */
709
+ listOrders(options?: {
710
+ userId?: string;
711
+ status?: Order['status'];
712
+ sortBy?: 'created_at' | 'total';
713
+ limit?: number;
714
+ offset?: number;
715
+ }): Promise<{
716
+ orders: Order[];
717
+ total: number;
718
+ }>;
719
+ /**
720
+ * Update order status
721
+ */
722
+ updateOrderStatus(orderId: string, status: Order['status']): Promise<Order>;
723
+ /**
724
+ * Cancel an order and optionally restore inventory
725
+ */
726
+ cancelOrder(orderId: string, restoreInventory?: boolean): Promise<Order>;
727
+ /**
728
+ * Add item to user's cart
729
+ */
730
+ addToCart(userId: string, item: CartItem): Promise<CartItem[]>;
731
+ /**
732
+ * Update cart item quantity or remove if quantity = 0
733
+ */
734
+ updateCartItem(userId: string, productId: string, quantity: number): Promise<CartItem[]>;
735
+ /**
736
+ * Get user's cart
737
+ */
738
+ getCart(userId: string): Promise<CartItem[]>;
739
+ /**
740
+ * Get user's cart with full product details
741
+ */
742
+ getCartWithDetails(userId: string): Promise<CartItemWithProduct[]>;
743
+ /**
744
+ * Clear user's cart
745
+ */
746
+ clearCart(userId: string): Promise<void>;
747
+ /**
748
+ * Checkout - convert cart to order and clear cart
749
+ */
750
+ checkout(userId: string, shippingAddress: Address, paymentMethodId?: string): Promise<Order>;
751
+ /**
752
+ * Get revenue statistics for a time period
753
+ */
754
+ getRevenueStats(period: 'day' | 'week' | 'month' | 'year'): Promise<RevenueStats>;
755
+ /**
756
+ * Get top selling products
757
+ */
758
+ getTopProducts(limit?: number, period?: 'day' | 'week' | 'month'): Promise<ProductStats[]>;
759
+ /**
760
+ * Get order statistics by status
761
+ */
762
+ getOrderStats(): Promise<OrderStats>;
763
+ private generateSKU;
764
+ private getPeriodStart;
765
+ }
766
+
767
+ export { type AppCategory as A, type BasePlan as B, type ConnectStatus as C, type DatabaseConfig as D, type OrderStats as E, type FeatureFlag as F, type ApiResponse as G, type PaginatedResponse as H, type UseCollectionReturn as I, type UseCollectionOptions as J, type UseKVReturn as K, type UseAuthReturn as L, type Media as M, type UsePaymentsReturn as N, type Order as O, type PaymentsConfig as P, type QueryOptions as Q, type RefundOptions as R, type Subscription as S, type Transaction as T, type UsageMetric as U, VlibeBaseDatabase as V, type CheckoutOptions as a, type CheckoutSession as b, VlibeBaseAuth as c, VlibeBaseEcommerce as d, type VlibeBaseConfig as e, type AuthConfig as f, type ColumnType as g, type TableColumn as h, type TableSchema as i, type TableInfo as j, type BaseRecord as k, type RealtimePayload as l, type VlibeUser as m, type VerifyResponse as n, type AuthSession as o, type Page as p, type Product as q, type OrderItem as r, type Address as s, type CartItem as t, type CartItemWithProduct as u, type CreateProductInput as v, type CreateOrderInput as w, type OrderCalculation as x, type RevenueStats as y, type ProductStats as z };
package/dist/index.d.mts CHANGED
@@ -1,5 +1,5 @@
1
- import { P as PaymentsConfig, C as ConnectStatus, a as CheckoutOptions, b as CheckoutSession, T as Transaction, R as RefundOptions } from './VlibeBaseAuth-BxS9T0vB.mjs';
2
- export { r as Address, t as ApiResponse, A as AppCategory, e as AuthConfig, n as AuthSession, B as BasePlan, j as BaseRecord, s as CartItem, f as ColumnType, D as DatabaseConfig, F as FeatureFlag, M as Media, O as Order, q as OrderItem, o as Page, u as PaginatedResponse, p as Product, Q as QueryOptions, k as RealtimePayload, S as Subscription, g as TableColumn, i as TableInfo, h as TableSchema, U as UsageMetric, y as UseAuthReturn, w as UseCollectionOptions, v as UseCollectionReturn, x as UseKVReturn, z as UsePaymentsReturn, m as VerifyResponse, c as VlibeBaseAuth, d as VlibeBaseConfig, V as VlibeBaseDatabase, l as VlibeUser } from './VlibeBaseAuth-BxS9T0vB.mjs';
1
+ import { P as PaymentsConfig, C as ConnectStatus, a as CheckoutOptions, b as CheckoutSession, T as Transaction, R as RefundOptions } from './VlibeBaseEcommerce-DXjHdN_L.mjs';
2
+ export { s as Address, G as ApiResponse, A as AppCategory, f as AuthConfig, o as AuthSession, B as BasePlan, k as BaseRecord, t as CartItem, u as CartItemWithProduct, g as ColumnType, w as CreateOrderInput, v as CreateProductInput, D as DatabaseConfig, F as FeatureFlag, M as Media, O as Order, x as OrderCalculation, r as OrderItem, E as OrderStats, p as Page, H as PaginatedResponse, q as Product, z as ProductStats, Q as QueryOptions, l as RealtimePayload, y as RevenueStats, S as Subscription, h as TableColumn, j as TableInfo, i as TableSchema, U as UsageMetric, L as UseAuthReturn, J as UseCollectionOptions, I as UseCollectionReturn, K as UseKVReturn, N as UsePaymentsReturn, n as VerifyResponse, c as VlibeBaseAuth, e as VlibeBaseConfig, V as VlibeBaseDatabase, d as VlibeBaseEcommerce, m as VlibeUser } from './VlibeBaseEcommerce-DXjHdN_L.mjs';
3
3
 
4
4
  /**
5
5
  * VlibeBasePayments - Payment processing for Vlibe Base Apps
package/dist/index.d.ts CHANGED
@@ -1,5 +1,5 @@
1
- import { P as PaymentsConfig, C as ConnectStatus, a as CheckoutOptions, b as CheckoutSession, T as Transaction, R as RefundOptions } from './VlibeBaseAuth-BxS9T0vB.js';
2
- export { r as Address, t as ApiResponse, A as AppCategory, e as AuthConfig, n as AuthSession, B as BasePlan, j as BaseRecord, s as CartItem, f as ColumnType, D as DatabaseConfig, F as FeatureFlag, M as Media, O as Order, q as OrderItem, o as Page, u as PaginatedResponse, p as Product, Q as QueryOptions, k as RealtimePayload, S as Subscription, g as TableColumn, i as TableInfo, h as TableSchema, U as UsageMetric, y as UseAuthReturn, w as UseCollectionOptions, v as UseCollectionReturn, x as UseKVReturn, z as UsePaymentsReturn, m as VerifyResponse, c as VlibeBaseAuth, d as VlibeBaseConfig, V as VlibeBaseDatabase, l as VlibeUser } from './VlibeBaseAuth-BxS9T0vB.js';
1
+ import { P as PaymentsConfig, C as ConnectStatus, a as CheckoutOptions, b as CheckoutSession, T as Transaction, R as RefundOptions } from './VlibeBaseEcommerce-DXjHdN_L.js';
2
+ export { s as Address, G as ApiResponse, A as AppCategory, f as AuthConfig, o as AuthSession, B as BasePlan, k as BaseRecord, t as CartItem, u as CartItemWithProduct, g as ColumnType, w as CreateOrderInput, v as CreateProductInput, D as DatabaseConfig, F as FeatureFlag, M as Media, O as Order, x as OrderCalculation, r as OrderItem, E as OrderStats, p as Page, H as PaginatedResponse, q as Product, z as ProductStats, Q as QueryOptions, l as RealtimePayload, y as RevenueStats, S as Subscription, h as TableColumn, j as TableInfo, i as TableSchema, U as UsageMetric, L as UseAuthReturn, J as UseCollectionOptions, I as UseCollectionReturn, K as UseKVReturn, N as UsePaymentsReturn, n as VerifyResponse, c as VlibeBaseAuth, e as VlibeBaseConfig, V as VlibeBaseDatabase, d as VlibeBaseEcommerce, m as VlibeUser } from './VlibeBaseEcommerce-DXjHdN_L.js';
3
3
 
4
4
  /**
5
5
  * VlibeBasePayments - Payment processing for Vlibe Base Apps