@marianmeres/ecsuite 1.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (49) hide show
  1. package/AGENTS.md +218 -0
  2. package/API.md +865 -0
  3. package/LICENSE +21 -0
  4. package/README.md +149 -0
  5. package/dist/adapters/mock/cart.d.ts +20 -0
  6. package/dist/adapters/mock/cart.js +86 -0
  7. package/dist/adapters/mock/customer.d.ts +20 -0
  8. package/dist/adapters/mock/customer.js +58 -0
  9. package/dist/adapters/mock/mod.d.ts +9 -0
  10. package/dist/adapters/mock/mod.js +9 -0
  11. package/dist/adapters/mock/order.d.ts +20 -0
  12. package/dist/adapters/mock/order.js +66 -0
  13. package/dist/adapters/mock/payment.d.ts +20 -0
  14. package/dist/adapters/mock/payment.js +55 -0
  15. package/dist/adapters/mock/product.d.ts +25 -0
  16. package/dist/adapters/mock/product.js +60 -0
  17. package/dist/adapters/mock/wishlist.d.ts +20 -0
  18. package/dist/adapters/mock/wishlist.js +70 -0
  19. package/dist/adapters/mod.d.ts +6 -0
  20. package/dist/adapters/mod.js +6 -0
  21. package/dist/domains/base.d.ts +83 -0
  22. package/dist/domains/base.js +187 -0
  23. package/dist/domains/cart.d.ts +96 -0
  24. package/dist/domains/cart.js +287 -0
  25. package/dist/domains/customer.d.ts +74 -0
  26. package/dist/domains/customer.js +183 -0
  27. package/dist/domains/mod.d.ts +13 -0
  28. package/dist/domains/mod.js +13 -0
  29. package/dist/domains/order.d.ts +83 -0
  30. package/dist/domains/order.js +233 -0
  31. package/dist/domains/payment.d.ts +83 -0
  32. package/dist/domains/payment.js +175 -0
  33. package/dist/domains/product.d.ts +130 -0
  34. package/dist/domains/product.js +241 -0
  35. package/dist/domains/wishlist.d.ts +101 -0
  36. package/dist/domains/wishlist.js +256 -0
  37. package/dist/mod.d.ts +28 -0
  38. package/dist/mod.js +32 -0
  39. package/dist/suite.d.ts +115 -0
  40. package/dist/suite.js +168 -0
  41. package/dist/types/adapter.d.ts +77 -0
  42. package/dist/types/adapter.js +7 -0
  43. package/dist/types/events.d.ts +111 -0
  44. package/dist/types/events.js +7 -0
  45. package/dist/types/mod.d.ts +9 -0
  46. package/dist/types/mod.js +9 -0
  47. package/dist/types/state.d.ts +61 -0
  48. package/dist/types/state.js +7 -0
  49. package/package.json +28 -0
@@ -0,0 +1,115 @@
1
+ /**
2
+ * @module suite
3
+ *
4
+ * ECSuite - Main orchestrator for e-commerce frontend state management.
5
+ * Coordinates all domain managers, provides shared event system, and manages context.
6
+ */
7
+ import { type Subscriber, type Unsubscriber } from "@marianmeres/pubsub";
8
+ import type { CartAdapter, CustomerAdapter, OrderAdapter, PaymentAdapter, ProductAdapter, WishlistAdapter } from "./types/adapter.js";
9
+ import type { DomainContext } from "./types/state.js";
10
+ import type { ECSuiteEventType, ECSuiteEvent } from "./types/events.js";
11
+ import { CartManager } from "./domains/cart.js";
12
+ import { WishlistManager } from "./domains/wishlist.js";
13
+ import { OrderManager } from "./domains/order.js";
14
+ import { CustomerManager } from "./domains/customer.js";
15
+ import { PaymentManager } from "./domains/payment.js";
16
+ import { ProductManager } from "./domains/product.js";
17
+ import type { StorageType } from "./domains/base.js";
18
+ /** Configuration for ECSuite */
19
+ export interface ECSuiteConfig {
20
+ /** Initial context (customerId, sessionId) */
21
+ context?: DomainContext;
22
+ /** Adapters for server communication */
23
+ adapters?: {
24
+ cart?: CartAdapter;
25
+ wishlist?: WishlistAdapter;
26
+ order?: OrderAdapter;
27
+ customer?: CustomerAdapter;
28
+ payment?: PaymentAdapter;
29
+ product?: ProductAdapter;
30
+ };
31
+ /** Storage configuration */
32
+ storage?: {
33
+ /** Cart storage key (default: "ecsuite:cart") */
34
+ cartKey?: string;
35
+ /** Wishlist storage key (default: "ecsuite:wishlist") */
36
+ wishlistKey?: string;
37
+ /** Storage type for persisted domains (default: "local") */
38
+ type?: StorageType;
39
+ };
40
+ /** Product cache TTL in milliseconds (default: 5 minutes) */
41
+ productCacheTtl?: number;
42
+ /** Auto-initialize on creation (default: true) */
43
+ autoInitialize?: boolean;
44
+ }
45
+ /**
46
+ * Main ECSuite class - orchestrates all e-commerce domain managers.
47
+ *
48
+ * Provides unified access to cart, wishlist, order, customer, payment, and product domains
49
+ * with shared event system and context management.
50
+ *
51
+ * @example
52
+ * ```typescript
53
+ * const suite = createECSuite({
54
+ * context: { customerId: "user-123" },
55
+ * adapters: { cart: myCartAdapter },
56
+ * });
57
+ *
58
+ * suite.cart.subscribe((state) => console.log(state));
59
+ * await suite.cart.addItem({ product_id: "prod-1", quantity: 1 });
60
+ * ```
61
+ */
62
+ export declare class ECSuite {
63
+ private readonly _clog;
64
+ private readonly _pubsub;
65
+ private _context;
66
+ /** Cart domain manager */
67
+ readonly cart: CartManager;
68
+ /** Wishlist domain manager */
69
+ readonly wishlist: WishlistManager;
70
+ /** Order domain manager */
71
+ readonly order: OrderManager;
72
+ /** Customer domain manager */
73
+ readonly customer: CustomerManager;
74
+ /** Payment domain manager */
75
+ readonly payment: PaymentManager;
76
+ /** Product domain manager (read-only with caching) */
77
+ readonly product: ProductManager;
78
+ constructor(config?: ECSuiteConfig);
79
+ /** Initialize all domains */
80
+ initialize(): Promise<void>;
81
+ /** Update context across all domains */
82
+ setContext(context: DomainContext): void;
83
+ /** Get the current context */
84
+ getContext(): DomainContext;
85
+ /** Subscribe to specific event type */
86
+ on(eventType: ECSuiteEventType, callback: Subscriber): Unsubscriber;
87
+ /** Subscribe to all events (receives { event, data } envelope) */
88
+ onAny(callback: (envelope: {
89
+ event: string;
90
+ data: ECSuiteEvent;
91
+ }) => void): Unsubscriber;
92
+ /** Subscribe once to an event */
93
+ once(eventType: ECSuiteEventType, callback: Subscriber): Unsubscriber;
94
+ /** Reset all domains to initial state */
95
+ reset(): void;
96
+ }
97
+ /**
98
+ * Factory function to create an ECSuite instance.
99
+ *
100
+ * @param config - Optional configuration for the suite
101
+ * @returns A new ECSuite instance
102
+ *
103
+ * @example
104
+ * ```typescript
105
+ * const suite = createECSuite({
106
+ * context: { customerId: "user-123" },
107
+ * adapters: {
108
+ * cart: myCartAdapter,
109
+ * wishlist: myWishlistAdapter,
110
+ * },
111
+ * storage: { type: "local" },
112
+ * });
113
+ * ```
114
+ */
115
+ export declare function createECSuite(config?: ECSuiteConfig): ECSuite;
package/dist/suite.js ADDED
@@ -0,0 +1,168 @@
1
+ /**
2
+ * @module suite
3
+ *
4
+ * ECSuite - Main orchestrator for e-commerce frontend state management.
5
+ * Coordinates all domain managers, provides shared event system, and manages context.
6
+ */
7
+ import { createClog } from "@marianmeres/clog";
8
+ import { createPubSub } from "@marianmeres/pubsub";
9
+ import { CartManager } from "./domains/cart.js";
10
+ import { WishlistManager } from "./domains/wishlist.js";
11
+ import { OrderManager } from "./domains/order.js";
12
+ import { CustomerManager } from "./domains/customer.js";
13
+ import { PaymentManager } from "./domains/payment.js";
14
+ import { ProductManager } from "./domains/product.js";
15
+ /**
16
+ * Main ECSuite class - orchestrates all e-commerce domain managers.
17
+ *
18
+ * Provides unified access to cart, wishlist, order, customer, payment, and product domains
19
+ * with shared event system and context management.
20
+ *
21
+ * @example
22
+ * ```typescript
23
+ * const suite = createECSuite({
24
+ * context: { customerId: "user-123" },
25
+ * adapters: { cart: myCartAdapter },
26
+ * });
27
+ *
28
+ * suite.cart.subscribe((state) => console.log(state));
29
+ * await suite.cart.addItem({ product_id: "prod-1", quantity: 1 });
30
+ * ```
31
+ */
32
+ export class ECSuite {
33
+ _clog = createClog("ecsuite", { color: "auto" });
34
+ _pubsub;
35
+ _context;
36
+ /** Cart domain manager */
37
+ cart;
38
+ /** Wishlist domain manager */
39
+ wishlist;
40
+ /** Order domain manager */
41
+ order;
42
+ /** Customer domain manager */
43
+ customer;
44
+ /** Payment domain manager */
45
+ payment;
46
+ /** Product domain manager (read-only with caching) */
47
+ product;
48
+ constructor(config = {}) {
49
+ this._clog.debug("creating suite", {
50
+ hasAdapters: !!config.adapters,
51
+ autoInitialize: config.autoInitialize !== false,
52
+ });
53
+ this._pubsub = createPubSub();
54
+ this._context = config.context ?? {};
55
+ const storageType = config.storage?.type ?? "local";
56
+ // Initialize domain managers with shared pubsub
57
+ this.cart = new CartManager({
58
+ adapter: config.adapters?.cart,
59
+ context: this._context,
60
+ pubsub: this._pubsub,
61
+ storageKey: config.storage?.cartKey ?? "ecsuite:cart",
62
+ storageType,
63
+ });
64
+ this.wishlist = new WishlistManager({
65
+ adapter: config.adapters?.wishlist,
66
+ context: this._context,
67
+ pubsub: this._pubsub,
68
+ storageKey: config.storage?.wishlistKey ?? "ecsuite:wishlist",
69
+ storageType,
70
+ });
71
+ this.order = new OrderManager({
72
+ adapter: config.adapters?.order,
73
+ context: this._context,
74
+ pubsub: this._pubsub,
75
+ });
76
+ this.customer = new CustomerManager({
77
+ adapter: config.adapters?.customer,
78
+ context: this._context,
79
+ pubsub: this._pubsub,
80
+ });
81
+ this.payment = new PaymentManager({
82
+ adapter: config.adapters?.payment,
83
+ context: this._context,
84
+ pubsub: this._pubsub,
85
+ });
86
+ this.product = new ProductManager({
87
+ adapter: config.adapters?.product,
88
+ context: this._context,
89
+ pubsub: this._pubsub,
90
+ cacheTtl: config.productCacheTtl,
91
+ });
92
+ // Auto-initialize if configured
93
+ if (config.autoInitialize !== false) {
94
+ this.initialize();
95
+ }
96
+ }
97
+ /** Initialize all domains */
98
+ async initialize() {
99
+ this._clog.debug("initializing all domains");
100
+ await Promise.all([
101
+ this.cart.initialize(),
102
+ this.wishlist.initialize(),
103
+ this.order.initialize(),
104
+ this.customer.initialize(),
105
+ this.payment.initialize(),
106
+ // Note: ProductManager doesn't have initialize() - it's lazy-loaded
107
+ ]);
108
+ this._clog.debug("all domains initialized");
109
+ }
110
+ /** Update context across all domains */
111
+ setContext(context) {
112
+ this._clog.debug("setContext", context);
113
+ this._context = { ...this._context, ...context };
114
+ this.cart.setContext(context);
115
+ this.wishlist.setContext(context);
116
+ this.order.setContext(context);
117
+ this.customer.setContext(context);
118
+ this.payment.setContext(context);
119
+ this.product.setContext(context);
120
+ }
121
+ /** Get the current context */
122
+ getContext() {
123
+ return { ...this._context };
124
+ }
125
+ /** Subscribe to specific event type */
126
+ on(eventType, callback) {
127
+ return this._pubsub.subscribe(eventType, callback);
128
+ }
129
+ /** Subscribe to all events (receives { event, data } envelope) */
130
+ onAny(callback) {
131
+ return this._pubsub.subscribe("*", callback);
132
+ }
133
+ /** Subscribe once to an event */
134
+ once(eventType, callback) {
135
+ return this._pubsub.subscribeOnce(eventType, callback);
136
+ }
137
+ /** Reset all domains to initial state */
138
+ reset() {
139
+ this._clog.debug("reset all domains");
140
+ this.cart.reset();
141
+ this.wishlist.reset();
142
+ this.order.reset();
143
+ this.customer.reset();
144
+ this.payment.reset();
145
+ this.product.clearCache();
146
+ }
147
+ }
148
+ /**
149
+ * Factory function to create an ECSuite instance.
150
+ *
151
+ * @param config - Optional configuration for the suite
152
+ * @returns A new ECSuite instance
153
+ *
154
+ * @example
155
+ * ```typescript
156
+ * const suite = createECSuite({
157
+ * context: { customerId: "user-123" },
158
+ * adapters: {
159
+ * cart: myCartAdapter,
160
+ * wishlist: myWishlistAdapter,
161
+ * },
162
+ * storage: { type: "local" },
163
+ * });
164
+ * ```
165
+ */
166
+ export function createECSuite(config) {
167
+ return new ECSuite(config);
168
+ }
@@ -0,0 +1,77 @@
1
+ /**
2
+ * @module types/adapter
3
+ *
4
+ * Adapter interface definitions for server communication.
5
+ * Implement these interfaces to connect ECSuite to your backend.
6
+ */
7
+ import type { CartData, CartItem, CustomerData, OrderData, PaymentData, ProductData, UUID } from "@marianmeres/collection-types";
8
+ import type { DomainContext, WishlistData } from "./state.js";
9
+ /** Base adapter result */
10
+ export interface AdapterResult<T> {
11
+ success: boolean;
12
+ data?: T;
13
+ error?: {
14
+ code: string;
15
+ message: string;
16
+ };
17
+ }
18
+ /** Cart adapter interface */
19
+ export interface CartAdapter {
20
+ /** Fetch current cart from server */
21
+ fetch(ctx: DomainContext): Promise<AdapterResult<CartData>>;
22
+ /** Add item to cart */
23
+ addItem(item: CartItem, ctx: DomainContext): Promise<AdapterResult<CartData>>;
24
+ /** Update item quantity */
25
+ updateItem(productId: UUID, quantity: number, ctx: DomainContext): Promise<AdapterResult<CartData>>;
26
+ /** Remove item from cart */
27
+ removeItem(productId: UUID, ctx: DomainContext): Promise<AdapterResult<CartData>>;
28
+ /** Clear all items */
29
+ clear(ctx: DomainContext): Promise<AdapterResult<CartData>>;
30
+ /** Sync full cart state (for optimistic update reconciliation) */
31
+ sync(cart: CartData, ctx: DomainContext): Promise<AdapterResult<CartData>>;
32
+ }
33
+ /** Wishlist adapter interface */
34
+ export interface WishlistAdapter {
35
+ /** Fetch current wishlist from server */
36
+ fetch(ctx: DomainContext): Promise<AdapterResult<WishlistData>>;
37
+ /** Add item to wishlist */
38
+ addItem(productId: UUID, ctx: DomainContext): Promise<AdapterResult<WishlistData>>;
39
+ /** Remove item from wishlist */
40
+ removeItem(productId: UUID, ctx: DomainContext): Promise<AdapterResult<WishlistData>>;
41
+ /** Clear all items */
42
+ clear(ctx: DomainContext): Promise<AdapterResult<WishlistData>>;
43
+ /** Sync full wishlist state */
44
+ sync(wishlist: WishlistData, ctx: DomainContext): Promise<AdapterResult<WishlistData>>;
45
+ }
46
+ /** Order create payload (status is set by server) */
47
+ export type OrderCreatePayload = Omit<OrderData, "status">;
48
+ /** Order adapter interface (read + create only) */
49
+ export interface OrderAdapter {
50
+ /** Fetch all orders for customer */
51
+ fetchAll(ctx: DomainContext): Promise<AdapterResult<OrderData[]>>;
52
+ /** Fetch single order by ID */
53
+ fetchOne(orderId: UUID, ctx: DomainContext): Promise<AdapterResult<OrderData>>;
54
+ /** Create new order */
55
+ create(order: OrderCreatePayload, ctx: DomainContext): Promise<AdapterResult<OrderData>>;
56
+ }
57
+ /** Customer adapter interface (read + limited update) */
58
+ export interface CustomerAdapter {
59
+ /** Fetch customer data */
60
+ fetch(ctx: DomainContext): Promise<AdapterResult<CustomerData>>;
61
+ /** Update customer data (partial) */
62
+ update(data: Partial<CustomerData>, ctx: DomainContext): Promise<AdapterResult<CustomerData>>;
63
+ }
64
+ /** Payment adapter interface (read-only) */
65
+ export interface PaymentAdapter {
66
+ /** Fetch payments for an order */
67
+ fetchForOrder(orderId: UUID, ctx: DomainContext): Promise<AdapterResult<PaymentData[]>>;
68
+ /** Fetch single payment by ID */
69
+ fetchOne(paymentId: UUID, ctx: DomainContext): Promise<AdapterResult<PaymentData>>;
70
+ }
71
+ /** Product adapter interface (read-only with batch support) */
72
+ export interface ProductAdapter {
73
+ /** Fetch single product by ID */
74
+ fetchOne(productId: UUID, ctx: DomainContext): Promise<AdapterResult<ProductData>>;
75
+ /** Fetch multiple products by IDs */
76
+ fetchMany(productIds: UUID[], ctx: DomainContext): Promise<AdapterResult<ProductData[]>>;
77
+ }
@@ -0,0 +1,7 @@
1
+ /**
2
+ * @module types/adapter
3
+ *
4
+ * Adapter interface definitions for server communication.
5
+ * Implement these interfaces to connect ECSuite to your backend.
6
+ */
7
+ export {};
@@ -0,0 +1,111 @@
1
+ /**
2
+ * @module types/events
3
+ *
4
+ * Event type definitions for the ECSuite event system.
5
+ * Subscribe to these events to react to domain state changes.
6
+ */
7
+ import type { UUID } from "@marianmeres/collection-types";
8
+ import type { DomainError, DomainState } from "./state.js";
9
+ /** Domain identifiers */
10
+ export type DomainName = "cart" | "wishlist" | "order" | "customer" | "payment" | "product";
11
+ /** Event types emitted by the suite */
12
+ export type ECSuiteEventType = "domain:state:changed" | "domain:error" | "domain:synced" | "cart:item:added" | "cart:item:updated" | "cart:item:removed" | "cart:cleared" | "wishlist:item:added" | "wishlist:item:removed" | "wishlist:cleared" | "order:created" | "order:fetched" | "customer:updated" | "customer:fetched" | "payment:fetched" | "product:fetched";
13
+ /** Base event data */
14
+ export interface ECSuiteEventBase {
15
+ /** Event timestamp */
16
+ timestamp: number;
17
+ /** Domain that emitted the event */
18
+ domain: DomainName;
19
+ }
20
+ /** State change event */
21
+ export interface StateChangedEvent extends ECSuiteEventBase {
22
+ type: "domain:state:changed";
23
+ previousState: DomainState;
24
+ newState: DomainState;
25
+ }
26
+ /** Error event */
27
+ export interface ErrorEvent extends ECSuiteEventBase {
28
+ type: "domain:error";
29
+ error: DomainError;
30
+ }
31
+ /** Sync completed event */
32
+ export interface SyncedEvent extends ECSuiteEventBase {
33
+ type: "domain:synced";
34
+ }
35
+ /** Cart item added event */
36
+ export interface CartItemAddedEvent extends ECSuiteEventBase {
37
+ type: "cart:item:added";
38
+ domain: "cart";
39
+ productId: UUID;
40
+ quantity: number;
41
+ }
42
+ /** Cart item updated event */
43
+ export interface CartItemUpdatedEvent extends ECSuiteEventBase {
44
+ type: "cart:item:updated";
45
+ domain: "cart";
46
+ productId: UUID;
47
+ previousQuantity: number;
48
+ newQuantity: number;
49
+ }
50
+ /** Cart item removed event */
51
+ export interface CartItemRemovedEvent extends ECSuiteEventBase {
52
+ type: "cart:item:removed";
53
+ domain: "cart";
54
+ productId: UUID;
55
+ }
56
+ /** Cart cleared event */
57
+ export interface CartClearedEvent extends ECSuiteEventBase {
58
+ type: "cart:cleared";
59
+ domain: "cart";
60
+ }
61
+ /** Wishlist item added event */
62
+ export interface WishlistItemAddedEvent extends ECSuiteEventBase {
63
+ type: "wishlist:item:added";
64
+ domain: "wishlist";
65
+ productId: UUID;
66
+ }
67
+ /** Wishlist item removed event */
68
+ export interface WishlistItemRemovedEvent extends ECSuiteEventBase {
69
+ type: "wishlist:item:removed";
70
+ domain: "wishlist";
71
+ productId: UUID;
72
+ }
73
+ /** Wishlist cleared event */
74
+ export interface WishlistClearedEvent extends ECSuiteEventBase {
75
+ type: "wishlist:cleared";
76
+ domain: "wishlist";
77
+ }
78
+ /** Order created event */
79
+ export interface OrderCreatedEvent extends ECSuiteEventBase {
80
+ type: "order:created";
81
+ domain: "order";
82
+ orderId?: UUID;
83
+ }
84
+ /** Order fetched event */
85
+ export interface OrderFetchedEvent extends ECSuiteEventBase {
86
+ type: "order:fetched";
87
+ domain: "order";
88
+ }
89
+ /** Customer updated event */
90
+ export interface CustomerUpdatedEvent extends ECSuiteEventBase {
91
+ type: "customer:updated";
92
+ domain: "customer";
93
+ }
94
+ /** Customer fetched event */
95
+ export interface CustomerFetchedEvent extends ECSuiteEventBase {
96
+ type: "customer:fetched";
97
+ domain: "customer";
98
+ }
99
+ /** Payment fetched event */
100
+ export interface PaymentFetchedEvent extends ECSuiteEventBase {
101
+ type: "payment:fetched";
102
+ domain: "payment";
103
+ }
104
+ /** Product fetched event */
105
+ export interface ProductFetchedEvent extends ECSuiteEventBase {
106
+ type: "product:fetched";
107
+ domain: "product";
108
+ productId: UUID;
109
+ }
110
+ /** All event types union */
111
+ export type ECSuiteEvent = StateChangedEvent | ErrorEvent | SyncedEvent | CartItemAddedEvent | CartItemUpdatedEvent | CartItemRemovedEvent | CartClearedEvent | WishlistItemAddedEvent | WishlistItemRemovedEvent | WishlistClearedEvent | OrderCreatedEvent | OrderFetchedEvent | CustomerUpdatedEvent | CustomerFetchedEvent | PaymentFetchedEvent | ProductFetchedEvent;
@@ -0,0 +1,7 @@
1
+ /**
2
+ * @module types/events
3
+ *
4
+ * Event type definitions for the ECSuite event system.
5
+ * Subscribe to these events to react to domain state changes.
6
+ */
7
+ export {};
@@ -0,0 +1,9 @@
1
+ /**
2
+ * @module types
3
+ *
4
+ * Type exports for @marianmeres/ecsuite.
5
+ * Re-exports all types from state, adapter, and events modules.
6
+ */
7
+ export * from "./state.js";
8
+ export * from "./adapter.js";
9
+ export * from "./events.js";
@@ -0,0 +1,9 @@
1
+ /**
2
+ * @module types
3
+ *
4
+ * Type exports for @marianmeres/ecsuite.
5
+ * Re-exports all types from state, adapter, and events modules.
6
+ */
7
+ export * from "./state.js";
8
+ export * from "./adapter.js";
9
+ export * from "./events.js";
@@ -0,0 +1,61 @@
1
+ /**
2
+ * @module types/state
3
+ *
4
+ * Domain state and context type definitions.
5
+ * Core types for domain state management and data structures.
6
+ */
7
+ import type { CartItem, ProductData, UUID } from "@marianmeres/collection-types";
8
+ /** Domain state progression */
9
+ export type DomainState = "initializing" | "ready" | "syncing" | "error";
10
+ /** Error information structure */
11
+ export interface DomainError {
12
+ /** Error code for programmatic handling */
13
+ code: string;
14
+ /** Human-readable message */
15
+ message: string;
16
+ /** Operation that failed */
17
+ operation: string;
18
+ /** Original error for debugging */
19
+ originalError?: unknown;
20
+ }
21
+ /** Base state wrapper for all domains */
22
+ export interface DomainStateWrapper<T> {
23
+ /** Current domain state */
24
+ state: DomainState;
25
+ /** Domain data (null during initialization or after critical error) */
26
+ data: T | null;
27
+ /** Error information when state is "error" */
28
+ error: DomainError | null;
29
+ /** Timestamp of last successful sync */
30
+ lastSyncedAt: number | null;
31
+ }
32
+ /** Context passed to adapters and events */
33
+ export interface DomainContext {
34
+ /** Optional customer ID */
35
+ customerId?: UUID;
36
+ /** Optional session ID */
37
+ sessionId?: UUID;
38
+ }
39
+ /** Wishlist item structure (not yet in collection-types) */
40
+ export interface WishlistItem {
41
+ /** Product model_id reference */
42
+ product_id: UUID;
43
+ /** Timestamp when item was added */
44
+ added_at?: number;
45
+ }
46
+ /** Wishlist data structure (not yet in collection-types) */
47
+ export interface WishlistData {
48
+ items: WishlistItem[];
49
+ }
50
+ /** Cart item enriched with product data */
51
+ export interface EnrichedCartItem extends CartItem {
52
+ /** Product data (null if not found) */
53
+ product: ProductData | null;
54
+ /** Line total: quantity * price (0 if no product or price) */
55
+ lineTotal: number;
56
+ }
57
+ /** Wishlist item enriched with product data */
58
+ export interface EnrichedWishlistItem extends WishlistItem {
59
+ /** Product data (null if not found) */
60
+ product: ProductData | null;
61
+ }
@@ -0,0 +1,7 @@
1
+ /**
2
+ * @module types/state
3
+ *
4
+ * Domain state and context type definitions.
5
+ * Core types for domain state management and data structures.
6
+ */
7
+ export {};
package/package.json ADDED
@@ -0,0 +1,28 @@
1
+ {
2
+ "name": "@marianmeres/ecsuite",
3
+ "version": "1.0.0",
4
+ "type": "module",
5
+ "main": "dist/mod.js",
6
+ "types": "dist/mod.d.ts",
7
+ "exports": {
8
+ ".": {
9
+ "types": "./dist/mod.d.ts",
10
+ "import": "./dist/mod.js"
11
+ }
12
+ },
13
+ "author": "Marian Meres",
14
+ "license": "MIT",
15
+ "dependencies": {
16
+ "@marianmeres/clog": "^3.15.0",
17
+ "@marianmeres/collection-types": "^1.11.0",
18
+ "@marianmeres/pubsub": "^2.4.5",
19
+ "@marianmeres/store": "^2.4.2"
20
+ },
21
+ "repository": {
22
+ "type": "git",
23
+ "url": "git+https://github.com/marianmeres/ecsuite.git"
24
+ },
25
+ "bugs": {
26
+ "url": "https://github.com/marianmeres/ecsuite/issues"
27
+ }
28
+ }