Expand description
§StateSet Core
Pure domain models and business logic for commerce operations. This crate has no I/O dependencies - just data structures and validation.
§Overview
stateset-core provides the foundational types for the StateSet iCommerce platform:
- Domain Models: Strongly-typed structs for all commerce entities
- Repository Traits: Abstract interfaces for data access
- Error Types: Comprehensive error handling with categorization
- Validation: Composable validation builders and traits
- Events: Domain event types for event-driven architectures
§Core Domains
| Domain | Description |
|---|---|
| Orders | Order management with line items, status tracking |
| Inventory | Stock tracking, reservations, adjustments |
| Customers | Customer profiles, addresses, contact info |
| Products | Product catalog with variants, pricing |
| Returns | Return processing, refunds, RMA |
| Manufacturing | Bill of Materials (BOM), Work Orders |
| Shipments | Shipping, tracking, carrier integration |
| Payments | Payment processing, refunds |
| Subscriptions | Recurring billing, subscription plans |
| Promotions | Discounts, coupons, promotional campaigns |
| Tax | Multi-jurisdiction tax calculation |
| Currency | Multi-currency support, exchange rates |
§Error Handling
All operations return Result<T, CommerceError>. Errors can be categorized:
use stateset_core::CommerceError;
fn handle_error(err: &CommerceError) {
if err.is_not_found() {
// Handle not found errors (404)
} else if err.is_validation() {
// Handle validation errors (400)
} else if err.is_conflict() {
// Handle conflict errors (409)
} else if err.is_database() {
// Handle database errors (500)
} else if err.is_retryable() {
// Retry the operation
}
}§Validation
Use ValidationBuilder for composable validations:
use stateset_core::{ValidationBuilder, Result};
fn validate_order(email: &str, quantity: i32) -> Result<()> {
ValidationBuilder::new()
.email("email", email)
.positive_i32("quantity", quantity)
.build()
}Or implement the Validate trait for domain models:
use stateset_core::{Validate, ValidationBuilder, Result};
struct OrderInput {
email: String,
quantity: i32,
}
impl Validate for OrderInput {
fn validate(&self) -> Result<()> {
ValidationBuilder::new()
.email("email", &self.email)
.positive_i32("quantity", self.quantity)
.build()
}
}
// Use with method chaining
// let input = OrderInput { ... }.validated()?;§Example
use stateset_core::prelude::*;
use rust_decimal_macros::dec;
// Create an order input
let order = CreateOrder {
customer_id: CustomerId::new(),
items: vec![CreateOrderItem {
sku: "SKU-001".to_string(),
name: "Widget".to_string(),
quantity: 2,
unit_price: dec!(29.99),
..Default::default()
}],
..Default::default()
};§Feature Flags
embeddings- Enable vector search via embedding servicesmetrics- Enable Prometheus metrics support
Re-exports§
pub use errors::*;pub use events::*;pub use models::*;pub use traits::*;pub use validation::*;
Modules§
- errors
- Error types for commerce operations.
- events
- Domain events for commerce operations.
- models
- Domain models for commerce operations
- prelude
- Re-export common types for convenience
- traits
- Repository traits for data access abstraction.
- validation
- Validation traits and utilities for domain models
Structs§
- Activity
LogId - Strongly-typed activity log entry identifier.
- AgentId
- Strongly-typed agent identifier (A2A commerce).
- CartId
- Strongly-typed shopping cart identifier.
- Channel
Id - Strongly-typed sales/fulfillment channel identifier.
- Company
Address Id - Strongly-typed company shipping address identifier.
- Company
Id - Strongly-typed B2B company (account) identifier.
- Contact
Id - Strongly-typed contact identifier.
- Credit
Id - Strongly-typed credit memo identifier.
- Currency
Code - ISO 4217 three-letter currency code.
- Customer
Id - Strongly-typed customer identifier.
- EdiDocument
Id - Strongly-typed EDI document identifier.
- Fraud
Rule Id - Strongly-typed fraud rule identifier.
- Fulfillment
Id - Strongly-typed fulfillment identifier.
- Gift
Card Id - Strongly-typed gift card identifier.
- Gift
Card Transaction Id - Strongly-typed gift card transaction identifier.
- Inbound
Shipment Id - Strongly-typed inbound shipment identifier.
- Inbound
Shipment Item Id - Strongly-typed inbound shipment line item identifier.
- Integration
Field Mapping Id - Strongly-typed integration field-path mapping identifier.
- Integration
Mapping Id - Strongly-typed integration field-mapping identifier.
- Inventory
Item Id - Strongly-typed inventory item identifier.
- Invoice
Id - Strongly-typed invoice identifier.
- Loyalty
Account Id - Strongly-typed loyalty account identifier.
- Loyalty
Program Id - Strongly-typed loyalty program identifier.
- Loyalty
Transaction Id - Strongly-typed loyalty transaction identifier.
- Money
- A monetary amount paired with its currency.
- OrderId
- Strongly-typed order identifier.
- Order
Item Id - Strongly-typed order line item identifier.
- Payment
Id - Strongly-typed payment identifier.
- Payment
Obligation Id - Strongly-typed payment obligation identifier.
- Prepayment
Application Id - Strongly-typed prepayment application identifier.
- Prepayment
Id - Strongly-typed prepayment identifier.
- Price
Level Id - Strongly-typed price level identifier.
- Price
Schedule Id - Strongly-typed price schedule identifier.
- Print
JobId - Strongly-typed print job identifier.
- Print
Station Id - Strongly-typed print station identifier.
- Product
Id - Strongly-typed product identifier.
- Production
Batch Id - Strongly-typed production batch identifier.
- Promotion
Id - Strongly-typed promotion identifier.
- Purchase
Order Id - Strongly-typed purchase order identifier.
- Purgatory
Line Item Id - Strongly-typed purgatory order line item identifier.
- Purgatory
Order Id - Strongly-typed purgatory (non-posted) order identifier.
- Return
Id - Strongly-typed return/RMA identifier.
- Review
Id - Strongly-typed product review identifier.
- Reward
Id - Strongly-typed reward identifier.
- Search
Config Id - Strongly-typed search configuration identifier.
- Segment
Id - Strongly-typed customer segment identifier.
- Shipment
Id - Strongly-typed shipment identifier.
- Shipping
Method Id - Strongly-typed shipping method identifier.
- Shipping
Zone Id - Strongly-typed shipping zone identifier.
- Sku
- A validated product SKU (Stock Keeping Unit).
- Stock
Snapshot Id - Strongly-typed stock snapshot identifier.
- Stock
Snapshot Line Id - Strongly-typed stock snapshot line identifier.
- Store
Credit Id - Strongly-typed store credit identifier.
- Store
Credit Transaction Id - Strongly-typed store credit transaction identifier.
- Subscription
Id - Strongly-typed subscription identifier.
- Supplier
SkuId - Strongly-typed supplier SKU identifier.
- Topology
Snapshot Id - Strongly-typed operational topology snapshot identifier.
- Transfer
Order Id - Strongly-typed transfer order identifier.
- Transfer
Order Item Id - Strongly-typed transfer order line item identifier.
- Unit
Class Id - Strongly-typed unit class identifier (e.g. Length, Weight, Volume).
- Unit
Conversion Rule Id - Strongly-typed unit conversion rule identifier.
- Unit
OfMeasure Id - Strongly-typed unit of measure identifier.
- Vendor
Credit Application Id - Strongly-typed vendor credit application identifier.
- Vendor
Credit Id - Strongly-typed vendor credit identifier.
- Vendor
Return Id - Strongly-typed vendor return identifier.
- Vendor
Return Item Id - Strongly-typed vendor return line item identifier.
- Warehouse
Id - Strongly-typed warehouse identifier.
- Warranty
Id - Strongly-typed warranty identifier.
- Wishlist
Id - Strongly-typed wishlist identifier.