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

@23blocks/block-products

v3.4.0

Published

Products block for 23blocks SDK - e-commerce, carts, inventory, catalog management

Readme

@23blocks/block-products

Products block for the 23blocks SDK - product catalog, cart, categories, and inventory management.

npm version License: MIT

Installation

npm install @23blocks/block-products @23blocks/transport-http

Overview

This package provides comprehensive e-commerce functionality including:

  • Products - Product CRUD, variations, images, stock, reviews
  • Cart - Shopping cart management and checkout
  • Categories - Category hierarchy and organization
  • Brands - Brand management
  • Vendors - Vendor/supplier management
  • Warehouses - Inventory locations
  • Channels - Sales channels
  • Collections - Product collections/groups

Quick Start

import { createHttpTransport } from '@23blocks/transport-http';
import { createProductsBlock } from '@23blocks/block-products';

// Create transport
const transport = createHttpTransport({
  baseUrl: 'https://api.yourapp.com',
  headers: () => {
    const token = localStorage.getItem('access_token');
    return token ? { Authorization: `Bearer ${token}` } : {};
  },
});

// Create block
const products = createProductsBlock(transport, {
  apiKey: 'your-api-key',
});

// List products
const { data: productList, meta } = await products.products.list({
  limit: 20,
  categoryId: 'category-123',
});

productList.forEach((product) => {
  console.log(product.name, product.price);
});

Services

products - Product Management

// List products with filtering
const { data: productList, meta } = await products.products.list({
  limit: 20,
  offset: 0,
  categoryId: 'category-id',
  brandId: 'brand-id',
  status: 'active',
});

// Get product by ID
const product = await products.products.get('product-id');

// Create product
const newProduct = await products.products.create({
  name: 'New Product',
  description: 'Product description',
  price: 99.99,
  categoryId: 'category-id',
  brandId: 'brand-id',
  sku: 'SKU-001',
  status: 'active',
});

// Update product
const updated = await products.products.update('product-id', {
  price: 89.99,
  status: 'on_sale',
});

// Delete product
await products.products.delete('product-id');

// Product variations
const { data: variations } = await products.products.listVariations('product-id');

const variation = await products.products.createVariation('product-id', {
  name: 'Size Large',
  sku: 'SKU-001-L',
  price: 99.99,
  attributes: { size: 'L', color: 'Blue' },
});

await products.products.updateVariation('product-id', 'variation-id', {
  price: 94.99,
});

await products.products.deleteVariation('product-id', 'variation-id');

// Product images
const { data: images } = await products.products.listImages('product-id');

// Product stock
const { data: stock } = await products.products.getStock('product-id');

// Product reviews
const { data: reviews } = await products.products.listReviews('product-id');

cart - Shopping Cart

// Get current cart
const cart = await products.cart.get();

// Add item to cart
const updatedCart = await products.cart.addItem({
  productId: 'product-id',
  variationId: 'variation-id', // optional
  quantity: 2,
});

// Update cart item quantity
const cart = await products.cart.updateItem('cart-item-id', {
  quantity: 3,
});

// Remove item from cart
await products.cart.removeItem('cart-item-id');

// Clear cart
await products.cart.clear();

// Update cart (coupon, shipping, etc.)
const cart = await products.cart.update({
  couponCode: 'SAVE10',
  shippingMethodId: 'shipping-method-id',
});

// Checkout
const order = await products.cart.checkout({
  shippingAddressId: 'address-id',
  billingAddressId: 'address-id',
  paymentMethodId: 'payment-method-id',
});

categories - Category Management

// List categories
const { data: categories } = await products.categories.list({
  parentId: null, // Get root categories
});

// Get category tree
const tree = await products.categories.getTree();

// Get category by ID
const category = await products.categories.get('category-id');

// Create category
const newCategory = await products.categories.create({
  name: 'Electronics',
  description: 'Electronic devices',
  parentId: null,
  slug: 'electronics',
});

// Update category
const updated = await products.categories.update('category-id', {
  name: 'Consumer Electronics',
});

// Delete category
await products.categories.delete('category-id');

brands - Brand Management

// List brands
const { data: brands } = await products.brands.list();

// Get brand by ID
const brand = await products.brands.get('brand-id');

// Create brand
const newBrand = await products.brands.create({
  name: 'Apple',
  description: 'Technology company',
  logoUrl: 'https://example.com/logo.png',
});

// Update brand
const updated = await products.brands.update('brand-id', {
  description: 'Updated description',
});

// Delete brand
await products.brands.delete('brand-id');

vendors - Vendor Management

// List vendors
const { data: vendors } = await products.vendors.list();

// Get vendor by ID
const vendor = await products.vendors.get('vendor-id');

// Create vendor
const newVendor = await products.vendors.create({
  name: 'Acme Corp',
  email: '[email protected]',
  phoneNumber: '+1234567890',
});

// Update vendor
const updated = await products.vendors.update('vendor-id', {
  email: '[email protected]',
});

// Delete vendor
await products.vendors.delete('vendor-id');

warehouses - Warehouse Management

// List warehouses
const { data: warehouses } = await products.warehouses.list();

// Get warehouse by ID
const warehouse = await products.warehouses.get('warehouse-id');

// Create warehouse
const newWarehouse = await products.warehouses.create({
  name: 'Main Warehouse',
  address: '123 Main St',
  city: 'New York',
  country: 'US',
});

// Update warehouse
const updated = await products.warehouses.update('warehouse-id', {
  name: 'Primary Warehouse',
});

// Delete warehouse
await products.warehouses.delete('warehouse-id');

channels - Sales Channels

// List channels
const { data: channels } = await products.channels.list();

// Get channel by ID
const channel = await products.channels.get('channel-id');

collections - Product Collections

// List collections
const { data: collections } = await products.collections.list();

// Get collection by ID
const collection = await products.collections.get('collection-id');

// Get products in collection
const { data: collectionProducts } = await products.collections.getProducts('collection-id');

Types

import type {
  // Product types
  Product,
  ProductVariation,
  ProductImage,
  ProductStock,
  ProductReview,
  CreateProductRequest,
  UpdateProductRequest,

  // Cart types
  Cart,
  CartDetail,
  AddToCartRequest,
  CheckoutRequest,

  // Catalog types
  Category,
  Brand,
  Vendor,
  Warehouse,
  Channel,
  Collection,
} from '@23blocks/block-products';

Product

| Property | Type | Description | |----------|------|-------------| | id | string | Product ID | | uniqueId | string | Unique identifier | | name | string | Product name | | description | string | Product description | | price | number | Base price | | compareAtPrice | number | Original price (for sales) | | sku | string | Stock keeping unit | | status | string | Product status | | categoryId | string | Category ID | | brandId | string | Brand ID | | images | ProductImage[] | Product images | | variations | ProductVariation[] | Product variations |

Cart

| Property | Type | Description | |----------|------|-------------| | id | string | Cart ID | | items | CartDetail[] | Cart items | | subtotal | number | Subtotal before discounts | | discount | number | Total discounts | | tax | number | Tax amount | | shipping | number | Shipping cost | | total | number | Final total | | couponCode | string | Applied coupon |

Error Handling

import { isBlockErrorException, ErrorCodes } from '@23blocks/contracts';

try {
  await products.cart.checkout(checkoutData);
} catch (error) {
  if (isBlockErrorException(error)) {
    switch (error.code) {
      case ErrorCodes.VALIDATION_ERROR:
        console.log('Invalid checkout data');
        break;
      case ErrorCodes.NOT_FOUND:
        console.log('Product or cart not found');
        break;
      case 'INSUFFICIENT_STOCK':
        console.log('Not enough stock available');
        break;
    }
  }
}

Related Packages

License

MIT - Copyright (c) 2024 23blocks