Skip to main content

Crate stateset_core

Crate stateset_core 

Source
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

DomainDescription
OrdersOrder management with line items, status tracking
InventoryStock tracking, reservations, adjustments
CustomersCustomer profiles, addresses, contact info
ProductsProduct catalog with variants, pricing
ReturnsReturn processing, refunds, RMA
ManufacturingBill of Materials (BOM), Work Orders
ShipmentsShipping, tracking, carrier integration
PaymentsPayment processing, refunds
SubscriptionsRecurring billing, subscription plans
PromotionsDiscounts, coupons, promotional campaigns
TaxMulti-jurisdiction tax calculation
CurrencyMulti-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 services
  • metrics - 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§

ActivityLogId
Strongly-typed activity log entry identifier.
AgentId
Strongly-typed agent identifier (A2A commerce).
CartId
Strongly-typed shopping cart identifier.
ChannelId
Strongly-typed sales/fulfillment channel identifier.
CompanyAddressId
Strongly-typed company shipping address identifier.
CompanyId
Strongly-typed B2B company (account) identifier.
ContactId
Strongly-typed contact identifier.
CreditId
Strongly-typed credit memo identifier.
CurrencyCode
ISO 4217 three-letter currency code.
CustomerId
Strongly-typed customer identifier.
EdiDocumentId
Strongly-typed EDI document identifier.
FraudRuleId
Strongly-typed fraud rule identifier.
FulfillmentId
Strongly-typed fulfillment identifier.
GiftCardId
Strongly-typed gift card identifier.
GiftCardTransactionId
Strongly-typed gift card transaction identifier.
InboundShipmentId
Strongly-typed inbound shipment identifier.
InboundShipmentItemId
Strongly-typed inbound shipment line item identifier.
IntegrationFieldMappingId
Strongly-typed integration field-path mapping identifier.
IntegrationMappingId
Strongly-typed integration field-mapping identifier.
InventoryItemId
Strongly-typed inventory item identifier.
InvoiceId
Strongly-typed invoice identifier.
LoyaltyAccountId
Strongly-typed loyalty account identifier.
LoyaltyProgramId
Strongly-typed loyalty program identifier.
LoyaltyTransactionId
Strongly-typed loyalty transaction identifier.
Money
A monetary amount paired with its currency.
OrderId
Strongly-typed order identifier.
OrderItemId
Strongly-typed order line item identifier.
PaymentId
Strongly-typed payment identifier.
PaymentObligationId
Strongly-typed payment obligation identifier.
PrepaymentApplicationId
Strongly-typed prepayment application identifier.
PrepaymentId
Strongly-typed prepayment identifier.
PriceLevelId
Strongly-typed price level identifier.
PriceScheduleId
Strongly-typed price schedule identifier.
PrintJobId
Strongly-typed print job identifier.
PrintStationId
Strongly-typed print station identifier.
ProductId
Strongly-typed product identifier.
ProductionBatchId
Strongly-typed production batch identifier.
PromotionId
Strongly-typed promotion identifier.
PurchaseOrderId
Strongly-typed purchase order identifier.
PurgatoryLineItemId
Strongly-typed purgatory order line item identifier.
PurgatoryOrderId
Strongly-typed purgatory (non-posted) order identifier.
ReturnId
Strongly-typed return/RMA identifier.
ReviewId
Strongly-typed product review identifier.
RewardId
Strongly-typed reward identifier.
SearchConfigId
Strongly-typed search configuration identifier.
SegmentId
Strongly-typed customer segment identifier.
ShipmentId
Strongly-typed shipment identifier.
ShippingMethodId
Strongly-typed shipping method identifier.
ShippingZoneId
Strongly-typed shipping zone identifier.
Sku
A validated product SKU (Stock Keeping Unit).
StockSnapshotId
Strongly-typed stock snapshot identifier.
StockSnapshotLineId
Strongly-typed stock snapshot line identifier.
StoreCreditId
Strongly-typed store credit identifier.
StoreCreditTransactionId
Strongly-typed store credit transaction identifier.
SubscriptionId
Strongly-typed subscription identifier.
SupplierSkuId
Strongly-typed supplier SKU identifier.
TopologySnapshotId
Strongly-typed operational topology snapshot identifier.
TransferOrderId
Strongly-typed transfer order identifier.
TransferOrderItemId
Strongly-typed transfer order line item identifier.
UnitClassId
Strongly-typed unit class identifier (e.g. Length, Weight, Volume).
UnitConversionRuleId
Strongly-typed unit conversion rule identifier.
UnitOfMeasureId
Strongly-typed unit of measure identifier.
VendorCreditApplicationId
Strongly-typed vendor credit application identifier.
VendorCreditId
Strongly-typed vendor credit identifier.
VendorReturnId
Strongly-typed vendor return identifier.
VendorReturnItemId
Strongly-typed vendor return line item identifier.
WarehouseId
Strongly-typed warehouse identifier.
WarrantyId
Strongly-typed warranty identifier.
WishlistId
Strongly-typed wishlist identifier.