npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

@lantern-ai/ecommerce-core-utility

v0.1.0

Published

TypeScript utility for ecommerce cart management and order processing with pluggable persistence, built-in validation, and type safety.

Readme

@lantern/ecommerce-core-utility

TypeScript utility for ecommerce cart management and order processing with pluggable persistence, built-in validation, and type safety.

Installation

npm install @lantern/ecommerce-core-utility

Peer Dependencies: react (for client hooks), zod

Features

  • Type-safe with full TypeScript support
  • Built-in Zod validation
  • Client & server utilities
  • Pluggable persistence adapters
  • ESM-first with React 18/19 support
  • Comprehensive error handling
  • Increment/decrement quantity support

Usage

Server-Side

import { createCartService, createOrderService } from '@lantern/ecommerce-core-utility';

const cartService = createCartService();
const orderService = createOrderService();

// Add item to cart
await cartService.addToCart({ 
  cartId: 'cart_123',
  item: { id: 'sku_1', name: 'T-shirt', priceCents: 2500, quantity: 1 }
});

// Apply coupon
await cartService.applyCoupon({ 
  cartId: 'cart_123', 
  couponCode: 'SAVE10', 
  discountCents: 1000 
});

// Create order from cart
const cart = (await cartService.getCart('cart_123')).data;
const order = await orderService.createOrder({ cart });

Client-Side

import { useCart } from '@lantern/ecommerce-core-utility';

function MyComponent() {
  const { cart, cartId, addItem, updateItem, clear } = useCart();
  
  const handleAdd = () => {
    addItem({ id: 'sku_1', name: 'T-shirt', priceCents: 2500, quantity: 1 });
  };
  
  return <button onClick={handleAdd}>Add to Cart</button>;
}

API Overview

Cart Service

createCartService(options) returns an object with:

  • addToCart(params) - Add item to cart (creates cart if needed)
  • updateItem(params) - Update item quantity
  • removeItem(params) - Remove item from cart
  • incrementItem(params) - Increase item quantity by 1
  • decrementItem(params) - Decrease item quantity by 1 (removes if becomes 0)
  • getCart(cartId) - Retrieve cart by ID
  • clearCart(cartId) - Delete cart
  • getCartSummary(cartId) - Get subtotal, discount, total, item count
  • applyCoupon(params) - Apply discount code
  • removeCoupon(cartId) - Remove discount
  • mergeCarts(params) - Merge guest and user carts

Order Service

createOrderService(options) returns an object with:

  • createOrder(params) - Create order from cart with total calculation
  • getOrder(orderId) - Retrieve order by ID
  • markPaid(orderId) - Update order status after payment

Client Utilities

  • useCart() - React hook for local cart state (localStorage)
  • initEcommerce() - Client initialization

Types

All functions return Result<T> type:

type Result<T> = 
  | { success: true; data: T }
  | { success: false; error: { message: string; code: string } }

Common Error Codes:

  • validation - Invalid input parameters
  • not_found - Cart or order not found
  • item_not_found - Item not found in cart

Key Features

  • Validation: Built-in Zod schemas validate all parameters
  • Adapter Pattern: Plug in any database (Postgres, MongoDB, Redis)
  • Quantity Management: Atomic increment/decrement operations
  • Cart Merging: Seamlessly combine guest and authenticated user carts
  • Currency Support: Configurable default currency

Custom Persistence

import { CartPersistenceAdapter } from '@lantern/ecommerce-core-utility';

const dbAdapter: CartPersistenceAdapter = {
  async getCart(id) { return await db.carts.findUnique({ where: { id } }); },
  async saveCart(cart) { await db.carts.upsert({ where: { id: cart.id }, update: cart, create: cart }); },
  async deleteCart(id) { await db.carts.delete({ where: { id } }); }
};

const cartService = createCartService({ adapter: dbAdapter });

Development

npm install        # Install dependencies
npm run build      # Build the package
npm test           # Run tests
npm run lint       # Lint code