@axova/shared 1.0.2 → 1.0.9

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 (66) hide show
  1. package/dist/index.d.ts +1 -0
  2. package/dist/index.js +2 -0
  3. package/dist/lib/db.d.ts +34226 -1
  4. package/dist/lib/db.js +21 -1
  5. package/dist/middleware/storeOwnership.js +22 -3
  6. package/dist/middleware/storeValidationMiddleware.js +16 -39
  7. package/dist/schemas/admin/admin-schema.d.ts +2 -2
  8. package/dist/schemas/ai-moderation/ai-moderation-schema.d.ts +8 -8
  9. package/dist/schemas/common/common-schemas.d.ts +71 -71
  10. package/dist/schemas/compliance/compliance-schema.d.ts +20 -20
  11. package/dist/schemas/compliance/kyc-schema.d.ts +6 -6
  12. package/dist/schemas/customer/customer-schema.d.ts +18 -18
  13. package/dist/schemas/index.d.ts +28 -0
  14. package/dist/schemas/index.js +134 -3
  15. package/dist/schemas/inventory/inventory-tables.d.ts +188 -188
  16. package/dist/schemas/inventory/lot-tables.d.ts +104 -104
  17. package/dist/schemas/order/cart-schema.d.ts +2865 -0
  18. package/dist/schemas/order/cart-schema.js +396 -0
  19. package/dist/schemas/order/order-schema.d.ts +19 -19
  20. package/dist/schemas/order/order-schema.js +8 -2
  21. package/dist/schemas/product/discount-schema.d.ts +3 -3
  22. package/dist/schemas/product/product-schema.d.ts +3 -3
  23. package/dist/schemas/store/store-audit-schema.d.ts +22 -22
  24. package/dist/schemas/store/storefront-config-schema.d.ts +434 -823
  25. package/dist/schemas/store/storefront-config-schema.js +35 -62
  26. package/dist/utils/subdomain.d.ts +1 -1
  27. package/dist/utils/subdomain.js +10 -15
  28. package/package.json +1 -1
  29. package/src/configs/index.ts +654 -654
  30. package/src/index.ts +26 -23
  31. package/src/interfaces/customer-events.ts +106 -106
  32. package/src/interfaces/inventory-events.ts +545 -545
  33. package/src/interfaces/inventory-types.ts +1004 -1004
  34. package/src/interfaces/order-events.ts +381 -381
  35. package/src/lib/auditLogger.ts +1117 -1117
  36. package/src/lib/authOrganization.ts +153 -153
  37. package/src/lib/db.ts +84 -64
  38. package/src/middleware/serviceAuth.ts +328 -328
  39. package/src/middleware/storeOwnership.ts +199 -181
  40. package/src/middleware/storeValidationMiddleware.ts +17 -50
  41. package/src/middleware/userAuth.ts +248 -248
  42. package/src/schemas/admin/admin-schema.ts +208 -208
  43. package/src/schemas/ai-moderation/ai-moderation-schema.ts +180 -180
  44. package/src/schemas/common/common-schemas.ts +108 -108
  45. package/src/schemas/compliance/compliance-schema.ts +927 -0
  46. package/src/schemas/compliance/kyc-schema.ts +649 -0
  47. package/src/schemas/customer/customer-schema.ts +576 -0
  48. package/src/schemas/index.ts +202 -3
  49. package/src/schemas/inventory/inventory-tables.ts +1927 -0
  50. package/src/schemas/inventory/lot-tables.ts +799 -0
  51. package/src/schemas/order/cart-schema.ts +652 -0
  52. package/src/schemas/order/order-schema.ts +1406 -0
  53. package/src/schemas/product/discount-relations.ts +44 -0
  54. package/src/schemas/product/discount-schema.ts +464 -0
  55. package/src/schemas/product/product-relations.ts +187 -0
  56. package/src/schemas/product/product-schema.ts +955 -0
  57. package/src/schemas/store/ethiopian_business_api.md.resolved +212 -0
  58. package/src/schemas/store/store-audit-schema.ts +1257 -0
  59. package/src/schemas/store/store-schema.ts +661 -0
  60. package/src/schemas/store/store-settings-schema.ts +231 -0
  61. package/src/schemas/store/storefront-config-schema.ts +382 -0
  62. package/src/schemas/types.ts +67 -67
  63. package/src/types/events.ts +646 -646
  64. package/src/utils/errorHandler.ts +44 -44
  65. package/src/utils/subdomain.ts +19 -23
  66. package/tsconfig.json +21 -21
@@ -1,381 +1,381 @@
1
- // Order Service Event Interfaces
2
-
3
- // Service Configuration
4
- export interface OrderServiceConfig {
5
- serviceName: string;
6
- version: string;
7
- kafkaTopics: {
8
- orderCreated: string;
9
- orderUpdated: string;
10
- orderStatusChanged: string;
11
- orderPaymentProcessed: string;
12
- orderShipped: string;
13
- orderDelivered: string;
14
- orderCancelled: string;
15
- orderRefunded: string;
16
- orderNoteAdded: string;
17
- orderItemAdded: string;
18
- orderItemRemoved: string;
19
- orderDiscountApplied: string;
20
- };
21
- features: {
22
- multiOrderTypes: boolean;
23
- advancedPayments: boolean;
24
- realTimeTracking: boolean;
25
- inventoryIntegration: boolean;
26
- advancedDiscounts: boolean;
27
- fraudDetection: boolean;
28
- subscriptionSupport: boolean;
29
- marketplaceIntegration: boolean;
30
- };
31
- limits: {
32
- maxOrderValue: number;
33
- maxItemsPerOrder: number;
34
- maxAddressesPerOrder: number;
35
- maxNotesPerOrder: number;
36
- orderRetentionDays: number;
37
- };
38
- }
39
-
40
- // Order Event Payloads
41
- export interface OrderCreatedEvent {
42
- orderId: string;
43
- orderNumber: string;
44
- storeId: string;
45
- customerId?: string;
46
- userId?: string;
47
- orderType: string;
48
- orderSource: string;
49
- status: string;
50
- totalAmount: string;
51
- currency: string;
52
- itemCount: number;
53
- isGuestOrder: boolean;
54
- paymentMethod?: string;
55
- shippingRequired: boolean;
56
- priority: string;
57
- }
58
-
59
- export interface OrderUpdatedEvent {
60
- orderId: string;
61
- orderNumber: string;
62
- storeId: string;
63
- customerId?: string;
64
- changes: Record<string, unknown>;
65
- previousValues: Record<string, unknown>;
66
- statusChanged: boolean;
67
- paymentStatusChanged: boolean;
68
- fulfillmentStatusChanged: boolean;
69
- amountChanged: boolean;
70
- }
71
-
72
- export interface OrderStatusChangedEvent {
73
- orderId: string;
74
- orderNumber: string;
75
- storeId: string;
76
- customerId?: string;
77
- fromStatus: string;
78
- toStatus: string;
79
- reason?: string;
80
- actorId: string;
81
- actorType: string;
82
- timestamp: string;
83
- }
84
-
85
- export interface OrderPaymentProcessedEvent {
86
- orderId: string;
87
- paymentId: string;
88
- transactionId?: string;
89
- paymentMethod: string;
90
- paymentProvider?: string;
91
- amount: string;
92
- currency: string;
93
- status: string;
94
- isSuccessful: boolean;
95
- failureReason?: string;
96
- }
97
-
98
- export interface OrderShippedEvent {
99
- orderId: string;
100
- fulfillmentId: string;
101
- trackingNumber?: string;
102
- trackingUrl?: string;
103
- shippingCarrier?: string;
104
- shippingService?: string;
105
- estimatedDeliveryDate?: string;
106
- packedBy?: string;
107
- shippedBy?: string;
108
- }
109
-
110
- export interface OrderDeliveredEvent {
111
- orderId: string;
112
- fulfillmentId: string;
113
- deliveredAt: string;
114
- deliveredBy?: string;
115
- signedBy?: string;
116
- deliveryLocation?: string;
117
- proofOfDelivery?: Record<string, unknown>;
118
- }
119
-
120
- export interface OrderCancelledEvent {
121
- orderId: string;
122
- orderNumber: string;
123
- storeId: string;
124
- customerId?: string;
125
- cancellationReason: string;
126
- cancelledBy: string;
127
- cancelledByType: string;
128
- refundRequired: boolean;
129
- refundAmount?: string;
130
- inventoryReleased: boolean;
131
- }
132
-
133
- export interface OrderRefundedEvent {
134
- orderId: string;
135
- paymentId: string;
136
- refundId: string;
137
- refundAmount: string;
138
- refundReason: string;
139
- refundMethod: string;
140
- isPartialRefund: boolean;
141
- processedBy: string;
142
- customerNotified: boolean;
143
- }
144
-
145
- export interface OrderNoteAddedEvent {
146
- orderId: string;
147
- noteId: string;
148
- noteType: string;
149
- content: string;
150
- isCustomerVisible: boolean;
151
- priority: string;
152
- createdBy: string;
153
- createdByName: string;
154
- requiresFollowUp: boolean;
155
- }
156
-
157
- export interface OrderItemAddedEvent {
158
- orderId: string;
159
- itemId: string;
160
- productId: string;
161
- variantId?: string;
162
- sku: string;
163
- productTitle: string;
164
- quantity: number;
165
- unitPrice: string;
166
- totalPrice: string;
167
- addedBy: string;
168
- }
169
-
170
- export interface OrderItemRemovedEvent {
171
- orderId: string;
172
- itemId: string;
173
- productId: string;
174
- sku: string;
175
- productTitle: string;
176
- quantity: number;
177
- removedBy: string;
178
- removalReason?: string;
179
- }
180
-
181
- export interface OrderDiscountAppliedEvent {
182
- orderId: string;
183
- discountId: string;
184
- discountCode?: string;
185
- discountType: string;
186
- discountAmount: string;
187
- discountPercentage?: number;
188
- appliedBy?: string;
189
- campaignId?: string;
190
- }
191
-
192
- // Service Event Types
193
- export type OrderServiceEvent =
194
- | OrderCreatedEvent
195
- | OrderUpdatedEvent
196
- | OrderStatusChangedEvent
197
- | OrderPaymentProcessedEvent
198
- | OrderShippedEvent
199
- | OrderDeliveredEvent
200
- | OrderCancelledEvent
201
- | OrderRefundedEvent
202
- | OrderNoteAddedEvent
203
- | OrderItemAddedEvent
204
- | OrderItemRemovedEvent
205
- | OrderDiscountAppliedEvent;
206
-
207
- // Event Handler Types
208
- export interface OrderEventHandler<T = OrderServiceEvent> {
209
- handle(event: T): Promise<void>;
210
- canHandle(eventType: string): boolean;
211
- priority: number;
212
- }
213
-
214
- export interface OrderEventEmitter {
215
- emit(eventType: string, data: OrderServiceEvent): Promise<void>;
216
- on(eventType: string, handler: OrderEventHandler): void;
217
- off(eventType: string, handler: OrderEventHandler): void;
218
- removeAllListeners(): void;
219
- }
220
-
221
- // Business Logic Interfaces
222
- export interface OrderCalculation {
223
- subtotal: string;
224
- taxAmount: string;
225
- shippingAmount: string;
226
- discountAmount: string;
227
- totalAmount: string;
228
- currency: string;
229
- }
230
-
231
- export interface OrderValidation {
232
- isValid: boolean;
233
- errors: string[];
234
- warnings: string[];
235
- }
236
-
237
- export interface OrderInventoryCheck {
238
- isAvailable: boolean;
239
- unavailableItems: Array<{
240
- productId: string;
241
- variantId?: string;
242
- requestedQuantity: number;
243
- availableQuantity: number;
244
- reason: string;
245
- }>;
246
- }
247
-
248
- export interface OrderFraudCheck {
249
- riskScore: number;
250
- riskLevel: "LOW" | "MEDIUM" | "HIGH" | "CRITICAL";
251
- fraudIndicators: string[];
252
- recommendation: "APPROVE" | "REVIEW" | "DECLINE";
253
- requiresManualReview: boolean;
254
- }
255
-
256
- export interface OrderShippingCalculation {
257
- rates: Array<{
258
- carrier: string;
259
- service: string;
260
- cost: string;
261
- estimatedDays: number;
262
- estimatedDeliveryDate: string;
263
- }>;
264
- recommendedRate?: {
265
- carrier: string;
266
- service: string;
267
- cost: string;
268
- };
269
- }
270
-
271
- // Advanced Features
272
- export interface OrderSplitRequest {
273
- originalOrderId: string;
274
- splitReason: string;
275
- splits: Array<{
276
- items: Array<{
277
- orderItemId: string;
278
- quantity: number;
279
- }>;
280
- shippingAddress?: Record<string, unknown>;
281
- fulfillmentType?: string;
282
- priority?: string;
283
- }>;
284
- }
285
-
286
- export interface OrderMergeRequest {
287
- orderIds: string[];
288
- mergeReason: string;
289
- newShippingAddress?: Record<string, unknown>;
290
- newPaymentMethod?: string;
291
- }
292
-
293
- export interface OrderModificationRequest {
294
- orderId: string;
295
- modificationType:
296
- | "ADD_ITEM"
297
- | "REMOVE_ITEM"
298
- | "UPDATE_QUANTITY"
299
- | "CHANGE_ADDRESS"
300
- | "CHANGE_PAYMENT";
301
- modifications: Record<string, unknown>;
302
- reason: string;
303
- requestedBy: string;
304
- }
305
-
306
- export interface OrderEscalationRequest {
307
- orderId: string;
308
- escalationType:
309
- | "PAYMENT_ISSUE"
310
- | "SHIPPING_DELAY"
311
- | "QUALITY_ISSUE"
312
- | "CUSTOMER_COMPLAINT"
313
- | "FRAUD_ALERT";
314
- priority: "LOW" | "MEDIUM" | "HIGH" | "URGENT";
315
- description: string;
316
- assignedTo?: string;
317
- department?: string;
318
- }
319
-
320
- // Reporting and Analytics
321
- export interface OrderMetrics {
322
- totalOrders: number;
323
- totalRevenue: string;
324
- averageOrderValue: string;
325
- ordersByStatus: Record<string, number>;
326
- ordersByType: Record<string, number>;
327
- ordersBySource: Record<string, number>;
328
- conversionRate: number;
329
- cancelationRate: number;
330
- refundRate: number;
331
- averageProcessingTime: number;
332
- customerSatisfactionScore?: number;
333
- }
334
-
335
- export interface OrderReportFilter {
336
- dateRange?: {
337
- start: string;
338
- end: string;
339
- };
340
- storeIds?: string[];
341
- orderTypes?: string[];
342
- orderSources?: string[];
343
- customerTypes?: string[];
344
- paymentMethods?: string[];
345
- statuses?: string[];
346
- minAmount?: number;
347
- maxAmount?: number;
348
- includeTestOrders?: boolean;
349
- }
350
-
351
- // Integration Interfaces
352
- export interface MarketplaceOrderSync {
353
- marketplacePlatform: string;
354
- externalOrderId: string;
355
- syncStatus: "PENDING" | "SUCCESS" | "FAILED";
356
- lastSyncAt?: string;
357
- syncErrors?: string[];
358
- marketplaceData?: Record<string, unknown>;
359
- }
360
-
361
- export interface InventoryReservation {
362
- orderId: string;
363
- reservations: Array<{
364
- productId: string;
365
- variantId?: string;
366
- quantity: number;
367
- locationId: string;
368
- reservedAt: string;
369
- expiresAt: string;
370
- }>;
371
- }
372
-
373
- export interface PaymentIntentRequest {
374
- orderId: string;
375
- amount: string;
376
- currency: string;
377
- paymentMethod: string;
378
- customerInfo: Record<string, unknown>;
379
- billingAddress: Record<string, unknown>;
380
- metadata?: Record<string, unknown>;
381
- }
1
+ // Order Service Event Interfaces
2
+
3
+ // Service Configuration
4
+ export interface OrderServiceConfig {
5
+ serviceName: string;
6
+ version: string;
7
+ kafkaTopics: {
8
+ orderCreated: string;
9
+ orderUpdated: string;
10
+ orderStatusChanged: string;
11
+ orderPaymentProcessed: string;
12
+ orderShipped: string;
13
+ orderDelivered: string;
14
+ orderCancelled: string;
15
+ orderRefunded: string;
16
+ orderNoteAdded: string;
17
+ orderItemAdded: string;
18
+ orderItemRemoved: string;
19
+ orderDiscountApplied: string;
20
+ };
21
+ features: {
22
+ multiOrderTypes: boolean;
23
+ advancedPayments: boolean;
24
+ realTimeTracking: boolean;
25
+ inventoryIntegration: boolean;
26
+ advancedDiscounts: boolean;
27
+ fraudDetection: boolean;
28
+ subscriptionSupport: boolean;
29
+ marketplaceIntegration: boolean;
30
+ };
31
+ limits: {
32
+ maxOrderValue: number;
33
+ maxItemsPerOrder: number;
34
+ maxAddressesPerOrder: number;
35
+ maxNotesPerOrder: number;
36
+ orderRetentionDays: number;
37
+ };
38
+ }
39
+
40
+ // Order Event Payloads
41
+ export interface OrderCreatedEvent {
42
+ orderId: string;
43
+ orderNumber: string;
44
+ storeId: string;
45
+ customerId?: string;
46
+ userId?: string;
47
+ orderType: string;
48
+ orderSource: string;
49
+ status: string;
50
+ totalAmount: string;
51
+ currency: string;
52
+ itemCount: number;
53
+ isGuestOrder: boolean;
54
+ paymentMethod?: string;
55
+ shippingRequired: boolean;
56
+ priority: string;
57
+ }
58
+
59
+ export interface OrderUpdatedEvent {
60
+ orderId: string;
61
+ orderNumber: string;
62
+ storeId: string;
63
+ customerId?: string;
64
+ changes: Record<string, unknown>;
65
+ previousValues: Record<string, unknown>;
66
+ statusChanged: boolean;
67
+ paymentStatusChanged: boolean;
68
+ fulfillmentStatusChanged: boolean;
69
+ amountChanged: boolean;
70
+ }
71
+
72
+ export interface OrderStatusChangedEvent {
73
+ orderId: string;
74
+ orderNumber: string;
75
+ storeId: string;
76
+ customerId?: string;
77
+ fromStatus: string;
78
+ toStatus: string;
79
+ reason?: string;
80
+ actorId: string;
81
+ actorType: string;
82
+ timestamp: string;
83
+ }
84
+
85
+ export interface OrderPaymentProcessedEvent {
86
+ orderId: string;
87
+ paymentId: string;
88
+ transactionId?: string;
89
+ paymentMethod: string;
90
+ paymentProvider?: string;
91
+ amount: string;
92
+ currency: string;
93
+ status: string;
94
+ isSuccessful: boolean;
95
+ failureReason?: string;
96
+ }
97
+
98
+ export interface OrderShippedEvent {
99
+ orderId: string;
100
+ fulfillmentId: string;
101
+ trackingNumber?: string;
102
+ trackingUrl?: string;
103
+ shippingCarrier?: string;
104
+ shippingService?: string;
105
+ estimatedDeliveryDate?: string;
106
+ packedBy?: string;
107
+ shippedBy?: string;
108
+ }
109
+
110
+ export interface OrderDeliveredEvent {
111
+ orderId: string;
112
+ fulfillmentId: string;
113
+ deliveredAt: string;
114
+ deliveredBy?: string;
115
+ signedBy?: string;
116
+ deliveryLocation?: string;
117
+ proofOfDelivery?: Record<string, unknown>;
118
+ }
119
+
120
+ export interface OrderCancelledEvent {
121
+ orderId: string;
122
+ orderNumber: string;
123
+ storeId: string;
124
+ customerId?: string;
125
+ cancellationReason: string;
126
+ cancelledBy: string;
127
+ cancelledByType: string;
128
+ refundRequired: boolean;
129
+ refundAmount?: string;
130
+ inventoryReleased: boolean;
131
+ }
132
+
133
+ export interface OrderRefundedEvent {
134
+ orderId: string;
135
+ paymentId: string;
136
+ refundId: string;
137
+ refundAmount: string;
138
+ refundReason: string;
139
+ refundMethod: string;
140
+ isPartialRefund: boolean;
141
+ processedBy: string;
142
+ customerNotified: boolean;
143
+ }
144
+
145
+ export interface OrderNoteAddedEvent {
146
+ orderId: string;
147
+ noteId: string;
148
+ noteType: string;
149
+ content: string;
150
+ isCustomerVisible: boolean;
151
+ priority: string;
152
+ createdBy: string;
153
+ createdByName: string;
154
+ requiresFollowUp: boolean;
155
+ }
156
+
157
+ export interface OrderItemAddedEvent {
158
+ orderId: string;
159
+ itemId: string;
160
+ productId: string;
161
+ variantId?: string;
162
+ sku: string;
163
+ productTitle: string;
164
+ quantity: number;
165
+ unitPrice: string;
166
+ totalPrice: string;
167
+ addedBy: string;
168
+ }
169
+
170
+ export interface OrderItemRemovedEvent {
171
+ orderId: string;
172
+ itemId: string;
173
+ productId: string;
174
+ sku: string;
175
+ productTitle: string;
176
+ quantity: number;
177
+ removedBy: string;
178
+ removalReason?: string;
179
+ }
180
+
181
+ export interface OrderDiscountAppliedEvent {
182
+ orderId: string;
183
+ discountId: string;
184
+ discountCode?: string;
185
+ discountType: string;
186
+ discountAmount: string;
187
+ discountPercentage?: number;
188
+ appliedBy?: string;
189
+ campaignId?: string;
190
+ }
191
+
192
+ // Service Event Types
193
+ export type OrderServiceEvent =
194
+ | OrderCreatedEvent
195
+ | OrderUpdatedEvent
196
+ | OrderStatusChangedEvent
197
+ | OrderPaymentProcessedEvent
198
+ | OrderShippedEvent
199
+ | OrderDeliveredEvent
200
+ | OrderCancelledEvent
201
+ | OrderRefundedEvent
202
+ | OrderNoteAddedEvent
203
+ | OrderItemAddedEvent
204
+ | OrderItemRemovedEvent
205
+ | OrderDiscountAppliedEvent;
206
+
207
+ // Event Handler Types
208
+ export interface OrderEventHandler<T = OrderServiceEvent> {
209
+ handle(event: T): Promise<void>;
210
+ canHandle(eventType: string): boolean;
211
+ priority: number;
212
+ }
213
+
214
+ export interface OrderEventEmitter {
215
+ emit(eventType: string, data: OrderServiceEvent): Promise<void>;
216
+ on(eventType: string, handler: OrderEventHandler): void;
217
+ off(eventType: string, handler: OrderEventHandler): void;
218
+ removeAllListeners(): void;
219
+ }
220
+
221
+ // Business Logic Interfaces
222
+ export interface OrderCalculation {
223
+ subtotal: string;
224
+ taxAmount: string;
225
+ shippingAmount: string;
226
+ discountAmount: string;
227
+ totalAmount: string;
228
+ currency: string;
229
+ }
230
+
231
+ export interface OrderValidation {
232
+ isValid: boolean;
233
+ errors: string[];
234
+ warnings: string[];
235
+ }
236
+
237
+ export interface OrderInventoryCheck {
238
+ isAvailable: boolean;
239
+ unavailableItems: Array<{
240
+ productId: string;
241
+ variantId?: string;
242
+ requestedQuantity: number;
243
+ availableQuantity: number;
244
+ reason: string;
245
+ }>;
246
+ }
247
+
248
+ export interface OrderFraudCheck {
249
+ riskScore: number;
250
+ riskLevel: "LOW" | "MEDIUM" | "HIGH" | "CRITICAL";
251
+ fraudIndicators: string[];
252
+ recommendation: "APPROVE" | "REVIEW" | "DECLINE";
253
+ requiresManualReview: boolean;
254
+ }
255
+
256
+ export interface OrderShippingCalculation {
257
+ rates: Array<{
258
+ carrier: string;
259
+ service: string;
260
+ cost: string;
261
+ estimatedDays: number;
262
+ estimatedDeliveryDate: string;
263
+ }>;
264
+ recommendedRate?: {
265
+ carrier: string;
266
+ service: string;
267
+ cost: string;
268
+ };
269
+ }
270
+
271
+ // Advanced Features
272
+ export interface OrderSplitRequest {
273
+ originalOrderId: string;
274
+ splitReason: string;
275
+ splits: Array<{
276
+ items: Array<{
277
+ orderItemId: string;
278
+ quantity: number;
279
+ }>;
280
+ shippingAddress?: Record<string, unknown>;
281
+ fulfillmentType?: string;
282
+ priority?: string;
283
+ }>;
284
+ }
285
+
286
+ export interface OrderMergeRequest {
287
+ orderIds: string[];
288
+ mergeReason: string;
289
+ newShippingAddress?: Record<string, unknown>;
290
+ newPaymentMethod?: string;
291
+ }
292
+
293
+ export interface OrderModificationRequest {
294
+ orderId: string;
295
+ modificationType:
296
+ | "ADD_ITEM"
297
+ | "REMOVE_ITEM"
298
+ | "UPDATE_QUANTITY"
299
+ | "CHANGE_ADDRESS"
300
+ | "CHANGE_PAYMENT";
301
+ modifications: Record<string, unknown>;
302
+ reason: string;
303
+ requestedBy: string;
304
+ }
305
+
306
+ export interface OrderEscalationRequest {
307
+ orderId: string;
308
+ escalationType:
309
+ | "PAYMENT_ISSUE"
310
+ | "SHIPPING_DELAY"
311
+ | "QUALITY_ISSUE"
312
+ | "CUSTOMER_COMPLAINT"
313
+ | "FRAUD_ALERT";
314
+ priority: "LOW" | "MEDIUM" | "HIGH" | "URGENT";
315
+ description: string;
316
+ assignedTo?: string;
317
+ department?: string;
318
+ }
319
+
320
+ // Reporting and Analytics
321
+ export interface OrderMetrics {
322
+ totalOrders: number;
323
+ totalRevenue: string;
324
+ averageOrderValue: string;
325
+ ordersByStatus: Record<string, number>;
326
+ ordersByType: Record<string, number>;
327
+ ordersBySource: Record<string, number>;
328
+ conversionRate: number;
329
+ cancelationRate: number;
330
+ refundRate: number;
331
+ averageProcessingTime: number;
332
+ customerSatisfactionScore?: number;
333
+ }
334
+
335
+ export interface OrderReportFilter {
336
+ dateRange?: {
337
+ start: string;
338
+ end: string;
339
+ };
340
+ storeIds?: string[];
341
+ orderTypes?: string[];
342
+ orderSources?: string[];
343
+ customerTypes?: string[];
344
+ paymentMethods?: string[];
345
+ statuses?: string[];
346
+ minAmount?: number;
347
+ maxAmount?: number;
348
+ includeTestOrders?: boolean;
349
+ }
350
+
351
+ // Integration Interfaces
352
+ export interface MarketplaceOrderSync {
353
+ marketplacePlatform: string;
354
+ externalOrderId: string;
355
+ syncStatus: "PENDING" | "SUCCESS" | "FAILED";
356
+ lastSyncAt?: string;
357
+ syncErrors?: string[];
358
+ marketplaceData?: Record<string, unknown>;
359
+ }
360
+
361
+ export interface InventoryReservation {
362
+ orderId: string;
363
+ reservations: Array<{
364
+ productId: string;
365
+ variantId?: string;
366
+ quantity: number;
367
+ locationId: string;
368
+ reservedAt: string;
369
+ expiresAt: string;
370
+ }>;
371
+ }
372
+
373
+ export interface PaymentIntentRequest {
374
+ orderId: string;
375
+ amount: string;
376
+ currency: string;
377
+ paymentMethod: string;
378
+ customerInfo: Record<string, unknown>;
379
+ billingAddress: Record<string, unknown>;
380
+ metadata?: Record<string, unknown>;
381
+ }