1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
//! # 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:
//!
//! ```rust
//! 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:
//!
//! ```rust
//! 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:
//!
//! ```rust
//! 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
//!
//! ```rust
//! 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
// This crate has extensive surface area; enforcing `missing_docs` across the whole
// API makes `-D warnings` builds impractical. We keep the option to enable it for
// docs builds instead.
pub use *;
pub use *;
pub use *;
pub use *;
pub use *;
pub use *;
// Re-export strongly-typed primitives so downstream crates can import from
// `stateset_core` directly without depending on `stateset-primitives`.
pub use ;
/// Re-export common types for convenience