Skip to Content
Packages@loop/bigcommerce

@loop/bigcommerce

BigCommerce REST API client with webhook verification, product catalog mapping, and affiliate cart utilities.

Installation

pnpm add @loop/bigcommerce

Overview

Framework-agnostic BigCommerce integration for managing products, orders, customers, and carts. Includes webhook handling and RUO peptide catalog mapping.

Key features:

  • REST API client (orders, customers, products, carts)
  • Webhook signature verification + dispatch
  • Product catalog mapping (slug ↔ BigCommerce entity ID)
  • Affiliate protocol cart URL builders

Quick Start

import { BigCommerceClient } from '@loop/bigcommerce' const bc = new BigCommerceClient({ storeHash: process.env.BC_STORE_HASH!, accessToken: process.env.BC_ACCESS_TOKEN! }) // Fetch an order const order = await bc.orders.get(12345) // Get customer details const customer = await bc.customers.get(67890) // Create a cart const cart = await bc.carts.create({ lineItems: [ { productId: 123, quantity: 2 } ] })

Configuration

import { BigCommerceClient } from '@loop/bigcommerce' const bc = new BigCommerceClient({ storeHash: 'abc123xyz', // Your store hash accessToken: 'your_token', // API access token apiVersion: 'v3' // Optional, defaults to 'v3' })

API Clients

Orders

// Get order const order = await bc.orders.get(orderId) // List orders const orders = await bc.orders.list({ minId: 1000, status: 'awaiting_fulfillment' }) // Update order status await bc.orders.update(orderId, { status: 'shipped' })

Customers

// Get customer const customer = await bc.customers.get(customerId) // Create customer const newCustomer = await bc.customers.create({ email: 'user@example.com', firstName: 'John', lastName: 'Doe' }) // List customers const customers = await bc.customers.list({ email: 'user@example.com' })

Products

// Get product by ID const product = await bc.products.get(productId) // List products const products = await bc.products.list({ categories: [23], isVisible: true }) // Get product by SKU const product = await bc.products.getBySku('BPC-157-5MG')

Carts

// Create cart const cart = await bc.carts.create({ lineItems: [ { productId: 123, quantity: 1, variantId: 456 } ], customerId: 789 }) // Add item to cart await bc.carts.addItem(cartId, { productId: 123, quantity: 2 }) // Get redirect URL const redirectUrl = await bc.carts.getRedirectUrl(cartId)

Webhooks

Webhook Verification

import { verifyWebhookSignature } from '@loop/bigcommerce/webhooks' export async function POST(req: Request) { const body = await req.text() const signature = req.headers.get('x-bc-webhook-signature') const isValid = verifyWebhookSignature({ body, signature: signature!, secret: process.env.BC_WEBHOOK_SECRET! }) if (!isValid) { return new Response('Invalid signature', { status: 401 }) } // Process webhook... }

Webhook Dispatch

import { dispatchWebhook } from '@loop/bigcommerce/webhooks' const payload = JSON.parse(body) await dispatchWebhook(payload, { 'store/order/created': async (data) => { console.log('New order:', data.orderId) // Sync to database, send notifications, etc. }, 'store/cart/updated': async (data) => { console.log('Cart updated:', data.cartId) }, 'store/order/refund/created': async (data) => { console.log('Refund created:', data.refundId) } })

Supported Webhook Events

  • store/order/created
  • store/order/updated
  • store/order/archived
  • store/cart/created
  • store/cart/updated
  • store/cart/deleted
  • store/order/refund/created
  • store/customer/created
  • store/customer/updated

Product Catalog Mapping

Maps Loop protocol slugs to BigCommerce product entity IDs:

import { getProductId, getProductSlug } from '@loop/bigcommerce/product-map' // Slug → BigCommerce ID const bcId = getProductId('bpc-157-5mg') // Returns: 123 // BigCommerce ID → Slug const slug = getProductSlug(123) // Returns: 'bpc-157-5mg'

Catalog includes 50+ RUO peptides:

  • BPC-157, TB-500, GHK-Cu
  • Ipamorelin, CJC-1295, MK-677
  • Tesamorelin, Semaglutide, Tirzepatide
  • NAD+, Thymosin Beta-4, Epithalon
  • And 40+ more…

Affiliate Cart URLs

Generate affiliate cart URLs for protocol stacks:

import { buildAffiliateCartUrl } from '@loop/bigcommerce' const url = buildAffiliateCartUrl({ products: [ { slug: 'bpc-157-5mg', quantity: 2 }, { slug: 'tb-500-5mg', quantity: 1 } ], affiliateCode: 'PARTNER10', storeUrl: 'https://loopbiolabs.com' }) // Returns: https://loopbiolabs.com/cart.php?action=add&product_id=123&qty=2&product_id=456&qty=1&coupon=PARTNER10

Environment Variables

# BigCommerce API BC_STORE_HASH=abc123xyz BC_ACCESS_TOKEN=your_token_here # Webhooks BC_WEBHOOK_SECRET=your_webhook_secret

Error Handling

All API methods return Result<T, AppError> for type-safe error handling:

import { getProductId } from '@loop/bigcommerce/product-map' const result = getProductId('bpc-157-5mg') if (result.ok) { console.log('Product ID:', result.data) } else { console.error('Error:', result.error.message) }

Testing

# Run tests pnpm --filter @loop/bigcommerce test # Run specific test pnpm --filter @loop/bigcommerce test product-map

Architecture

Framework-agnostic:

  • No Next.js or framework coupling
  • Pure TypeScript
  • Composable functions
  • Injectable configuration

Type-safe:

  • Full Zod schemas for all API responses
  • TypeScript-first API
  • Runtime validation

Migration from loopbio-v2

// Old (loopbio-v2) import { bcClient } from '@/lib/integrations/bigcommerce' // New (@loop/bigcommerce) import { BigCommerceClient } from '@loop/bigcommerce' const bc = new BigCommerceClient({ ... })

Used By

@loop/bigcommerce is used by applications that integrate with BigCommerce:

Source

  • PR: #243 
  • Lines: 1,859
  • Files: 25
  • Shipped: 2026-03-21