New Research: Supply Chain Attack on Axios Pulls Malicious Dependency from npm.Details →
Socket
Book a DemoSign in
Socket

@commercejs/core

Package Overview
Dependencies
Maintainers
1
Versions
4
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@commercejs/core

Commerce.js orchestration engine — createCommerce(), event bus, capability routing, webhook dispatch

latest
Source
npmnpm
Version
0.3.0
Version published
Weekly downloads
5
66.67%
Maintainers
1
Weekly downloads
 
Created
Source

@commercejs/core

Unified Commerce Orchestration Engine — createCommerce() wires adapters, payments, events, and webhooks into a single entry point.

npm TypeScript License: MIT

Overview

@commercejs/core is the orchestration layer that ties the CommerceJS ecosystem together. It takes a CommerceAdapter and optional payment providers, notification providers, and analytics providers — then exposes a single API surface for all commerce operations. Events are emitted automatically, webhooks are dispatched, and domain calls are capability-checked at runtime.

Install

npm install @commercejs/core @commercejs/types

Quick Start

import { createCommerce } from '@commercejs/core'
import { createSallaAdapter } from '@commercejs/adapter-salla'
import { TapPaymentProvider } from '@commercejs/payment-tap'

const commerce = createCommerce({
  adapter: createSallaAdapter({ accessToken: process.env.SALLA_TOKEN! }),
  payments: {
    tap: new TapPaymentProvider({
      secretKey: process.env.TAP_SECRET_KEY!,
      publishableKey: process.env.TAP_PUBLISHABLE_KEY!,
    }),
  },
  defaultPayment: 'tap',
})

// Capability-checked calls
const products = await commerce.getProducts({ query: 'shirt' })
const cart = await commerce.createCart()

// Event-driven side effects
commerce.events.on('order.created', ({ order }) => {
  console.log('New order:', order.id)
})

Multi-Adapter Composition

For advanced setups, compose multiple adapters with orchestrator factories:

import { createCompositeOrchestrator, withPlatformFallback } from '@commercejs/core'

// Merge domains from multiple sources
const orchestrator = createCompositeOrchestrator({
  sources: {
    salla: sallaAdapter,
    platform: platformAdapter,
  },
  mapping: {
    catalog: 'salla',
    store: 'salla',
    cart: 'platform',
  },
})

// Or fill gaps in a primary adapter
const full = withPlatformFallback(sallaAdapter, platformAdapter)

Notification & Analytics Providers

Register providers to automatically react to commerce events:

import { createResendProvider } from '@commercejs/notification-resend'
import { createGA4Provider } from '@commercejs/analytics-ga'

const commerce = createCommerce({
  adapter,
  notifications: {
    resend: createResendProvider({ apiKey: 're_...', from: 'store@example.com' }),
  },
  notificationRules: [
    {
      event: 'order.created',
      channel: 'email',
      provider: 'resend',
      buildMessage: (payload) => ({
        to: payload.order.customer.email,
        subject: 'Order confirmed',
      }),
    },
  ],
  analytics: [
    createGA4Provider({ measurementId: 'G-XXXXXXXXXX' }),
  ],
})

Configuration

OptionTypeRequiredDescription
adapterCommerceAdapterPlatform adapter to delegate domain calls to
paymentsRecord<string, PaymentProvider>Payment providers keyed by ID
defaultPaymentstringDefault payment provider key
webhooksWebhookEndpoint[]Webhook delivery targets
notificationsRecord<string, NotificationProvider>Notification providers keyed by ID
notificationRulesNotificationRule[]Event → notification routing rules
analyticsAnalyticsProvider[]Analytics providers (receive all events)
fetchtypeof fetchCustom fetch for HTTP calls
sign(payload, secret) => stringCustom webhook signing function

API

Catalog

MethodDescription
getProduct(params)Get a single product by ID
getProducts(params)Search/list products
getCategories(params?)List categories
getBrands()List brands

Cart

MethodDescription
createCart()Create a new cart
getCart(cartId)Retrieve a cart
addToCart(cartId, item)Add item to cart
updateCartItem(cartId, itemId, qty)Update item quantity
removeFromCart(cartId, itemId)Remove item from cart

Checkout

MethodDescription
getShippingMethods(cartId)List available shipping methods
setShippingAddress(cartId, address)Set shipping address
setBillingAddress(cartId, address)Set billing address
setShippingMethod(cartId, methodId)Select shipping method
getPaymentMethods(cartId)List payment methods
setPaymentMethod(cartId, methodId)Select payment method
placeOrder(cartId)Complete checkout and place order

Customer

MethodDescription
login(email, password)Authenticate customer
register(input)Create new customer
getCustomer()Get current customer
logout()End session
getAddresses()List saved addresses
addAddress(address)Add new address

Payments

MethodDescription
createPayment(input, providerId?)Create payment session
getPayment(sessionId, providerId)Retrieve payment status
refundPayment(input, providerId)Process refund

Event Bus

commerce.events.on('product.viewed', handler)
commerce.events.on('cart.item.added', handler)
commerce.events.on('order.created', handler)
commerce.events.on('*', wildcardHandler) // all events
commerce.events.off('order.created', handler)

Orchestrator Factories

ExportDescription
createOrchestrator(config)Wrap a single adapter as an orchestrator
createCompositeOrchestrator(config)Merge domains from multiple adapters
withPlatformFallback(primary, fallback)Fill adapter gaps with a fallback

Exports

ExportTypeDescription
createCommerceFunctionMain factory function
CommerceConfigTypeConfiguration interface
CommerceInstanceTypeReturn type of createCommerce()
createOrchestratorFunctionSingle adapter → orchestrator
createCompositeOrchestratorFunctionMulti-adapter composition
withPlatformFallbackFunctionGap-filling fallback
CommerceEventBusClassTyped event emitter
createWebhookDispatcherFunctionWebhook delivery engine

Documentation

Full docs at commerce.js.org

License

MIT

FAQs

Package last updated on 17 Feb 2026

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts