@stateset/embedded-wasm
StateSet Embedded Commerce for browsers using WebAssembly.
Installation
Usage
Browser (ES Modules)
With Bundler (Webpack, Vite, etc.)
import init from '@stateset/embedded-wasm';
const commerce = await ;
// Use commerce API...
const customer = commerce..;
React Example
import from 'react';
import init from '@stateset/embedded-wasm';
API Reference
Commerce
Main entry point for all operations.
const commerce = ;
Note: Data is stored in-memory and will be lost on page refresh. For persistence, consider using IndexedDB to save/restore state.
Customers
// Create
const customer = commerce..;
// Get by ID
const customer = commerce..;
// Get by email
const customer = commerce..;
// List all
const customers = commerce..;
// Count
const count = commerce..;
// Properties
customer. // UUID string
customer. // string
customer. // string
customer. // string
customer. // "firstName lastName"
customer. // string or null
customer. // "active"
customer. // boolean
customer. // ISO 8601 string
customer. // ISO 8601 string
Orders
// Create
const order = commerce..;
// Get
const order = commerce..;
// Get items
const items = commerce..;
// List all
const orders = commerce..;
// Update status
const order = commerce..;
// Ship
const order = commerce..; // tracking optional
// Cancel
const order = commerce..;
// Count
const count = commerce..;
// Properties
order. // UUID string
order. // "ORD-123"
order. // UUID string
order. // "pending", "shipped", "cancelled", etc.
order. // number
order. // "USD"
order. // "pending", "paid", etc.
order. // "unfulfilled", "shipped", etc.
order. // string or null
order. // array of order items
order. // ISO 8601 string
order. // ISO 8601 string
Products
// Create
const product = commerce..;
// Get
const product = commerce..;
// Get variant by SKU
const variant = commerce..;
// List all
const products = commerce..;
// Count
const count = commerce..;
Inventory
// Create item
const item = commerce..;
// Get stock
const stock = commerce..;
stock. // "WIDGET-001"
stock. // "Premium Widget"
stock. // 100
stock. // 0
stock. // 100
// Adjust stock
commerce..;
commerce..;
// Reserve for order
const reservation = commerce..;
// Confirm reservation
commerce..;
// Release reservation
commerce..;
Returns
// Create return request
const ret = commerce..;
// Get
const ret = commerce..;
// Approve
const ret = commerce..;
// Reject
const ret = commerce..;
// List all
const returns = commerce..;
// Count
const count = commerce..;
Building from Source
# Install wasm-pack
|
# Build for web
# Build for Node.js
# Build for bundlers
Storage Considerations
This library uses in-memory storage, meaning all data is lost when the page refreshes. For persistence, you have several options:
- IndexedDB: Save/restore the state to IndexedDB
- LocalStorage: For small datasets, serialize to JSON
- Server Sync: Sync with a backend server
Example with localStorage:
// Save state (simplified - you'd need to implement full serialization)
// Restore state
Browser Support
- Chrome 57+
- Firefox 52+
- Safari 11+
- Edge 79+
Requires WebAssembly support.
Package Size
- WASM binary: ~200KB (gzipped: ~70KB)
- JavaScript glue code: ~35KB
License
MIT OR Apache-2.0