@contractspec/example.marketplace 1.57.0 → 1.59.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 (302) hide show
  1. package/dist/browser/docs/index.js +103 -0
  2. package/dist/browser/docs/marketplace.docblock.js +103 -0
  3. package/dist/browser/entities/index.js +721 -0
  4. package/dist/browser/entities/order.js +167 -0
  5. package/dist/browser/entities/payout.js +142 -0
  6. package/dist/browser/entities/product.js +152 -0
  7. package/dist/browser/entities/review.js +129 -0
  8. package/dist/browser/entities/store.js +97 -0
  9. package/dist/browser/example.js +42 -0
  10. package/dist/browser/handlers/index.js +303 -0
  11. package/dist/browser/handlers/marketplace.handlers.js +303 -0
  12. package/dist/browser/index.js +2016 -0
  13. package/dist/browser/marketplace.capability.js +40 -0
  14. package/dist/browser/marketplace.feature.js +137 -0
  15. package/dist/browser/order/index.js +307 -0
  16. package/dist/browser/order/order.enum.js +17 -0
  17. package/dist/browser/order/order.event.js +131 -0
  18. package/dist/browser/order/order.operations.js +172 -0
  19. package/dist/browser/order/order.presentation.js +153 -0
  20. package/dist/browser/order/order.schema.js +79 -0
  21. package/dist/browser/payout/index.js +152 -0
  22. package/dist/browser/payout/payout.enum.js +12 -0
  23. package/dist/browser/payout/payout.event.js +55 -0
  24. package/dist/browser/payout/payout.operations.js +94 -0
  25. package/dist/browser/payout/payout.presentation.js +111 -0
  26. package/dist/browser/payout/payout.schema.js +61 -0
  27. package/dist/browser/product/index.js +249 -0
  28. package/dist/browser/product/product.enum.js +13 -0
  29. package/dist/browser/product/product.event.js +74 -0
  30. package/dist/browser/product/product.operations.js +171 -0
  31. package/dist/browser/product/product.presentation.js +158 -0
  32. package/dist/browser/product/product.schema.js +84 -0
  33. package/dist/browser/review/index.js +206 -0
  34. package/dist/browser/review/review.enum.js +11 -0
  35. package/dist/browser/review/review.event.js +50 -0
  36. package/dist/browser/review/review.operations.js +152 -0
  37. package/dist/browser/review/review.presentation.js +123 -0
  38. package/dist/browser/review/review.schema.js +74 -0
  39. package/dist/browser/seeders/index.js +12 -0
  40. package/dist/browser/store/index.js +142 -0
  41. package/dist/browser/store/store.enum.js +11 -0
  42. package/dist/browser/store/store.event.js +52 -0
  43. package/dist/browser/store/store.operations.js +88 -0
  44. package/dist/browser/store/store.presentation.js +94 -0
  45. package/dist/browser/store/store.schema.js +43 -0
  46. package/dist/browser/tests/operations.test-spec.js +139 -0
  47. package/dist/browser/ui/MarketplaceDashboard.js +418 -0
  48. package/dist/browser/ui/hooks/index.js +59 -0
  49. package/dist/browser/ui/hooks/useMarketplaceData.js +56 -0
  50. package/dist/browser/ui/index.js +668 -0
  51. package/dist/browser/ui/renderers/index.js +248 -0
  52. package/dist/browser/ui/renderers/marketplace.markdown.js +248 -0
  53. package/dist/docs/index.d.ts +2 -1
  54. package/dist/docs/index.d.ts.map +1 -0
  55. package/dist/docs/index.js +104 -1
  56. package/dist/docs/marketplace.docblock.d.ts +2 -1
  57. package/dist/docs/marketplace.docblock.d.ts.map +1 -0
  58. package/dist/docs/marketplace.docblock.js +46 -57
  59. package/dist/entities/index.d.ts +302 -307
  60. package/dist/entities/index.d.ts.map +1 -1
  61. package/dist/entities/index.js +719 -43
  62. package/dist/entities/order.d.ts +77 -82
  63. package/dist/entities/order.d.ts.map +1 -1
  64. package/dist/entities/order.js +162 -167
  65. package/dist/entities/payout.d.ts +64 -69
  66. package/dist/entities/payout.d.ts.map +1 -1
  67. package/dist/entities/payout.js +137 -156
  68. package/dist/entities/product.d.ts +69 -74
  69. package/dist/entities/product.d.ts.map +1 -1
  70. package/dist/entities/product.js +148 -156
  71. package/dist/entities/review.d.ts +55 -60
  72. package/dist/entities/review.d.ts.map +1 -1
  73. package/dist/entities/review.js +124 -146
  74. package/dist/entities/store.d.ts +40 -45
  75. package/dist/entities/store.d.ts.map +1 -1
  76. package/dist/entities/store.js +94 -106
  77. package/dist/example.d.ts +2 -6
  78. package/dist/example.d.ts.map +1 -1
  79. package/dist/example.js +41 -55
  80. package/dist/handlers/index.d.ts +2 -2
  81. package/dist/handlers/index.d.ts.map +1 -0
  82. package/dist/handlers/index.js +304 -3
  83. package/dist/handlers/marketplace.handlers.d.ts +138 -137
  84. package/dist/handlers/marketplace.handlers.d.ts.map +1 -1
  85. package/dist/handlers/marketplace.handlers.js +284 -309
  86. package/dist/index.d.ts +13 -31
  87. package/dist/index.d.ts.map +1 -0
  88. package/dist/index.js +2017 -32
  89. package/dist/marketplace.capability.d.ts +3 -8
  90. package/dist/marketplace.capability.d.ts.map +1 -1
  91. package/dist/marketplace.capability.js +41 -34
  92. package/dist/marketplace.feature.d.ts +1 -6
  93. package/dist/marketplace.feature.d.ts.map +1 -1
  94. package/dist/marketplace.feature.js +136 -313
  95. package/dist/node/docs/index.js +103 -0
  96. package/dist/node/docs/marketplace.docblock.js +103 -0
  97. package/dist/node/entities/index.js +721 -0
  98. package/dist/node/entities/order.js +167 -0
  99. package/dist/node/entities/payout.js +142 -0
  100. package/dist/node/entities/product.js +152 -0
  101. package/dist/node/entities/review.js +129 -0
  102. package/dist/node/entities/store.js +97 -0
  103. package/dist/node/example.js +42 -0
  104. package/dist/node/handlers/index.js +303 -0
  105. package/dist/node/handlers/marketplace.handlers.js +303 -0
  106. package/dist/node/index.js +2016 -0
  107. package/dist/node/marketplace.capability.js +40 -0
  108. package/dist/node/marketplace.feature.js +137 -0
  109. package/dist/node/order/index.js +307 -0
  110. package/dist/node/order/order.enum.js +17 -0
  111. package/dist/node/order/order.event.js +131 -0
  112. package/dist/node/order/order.operations.js +172 -0
  113. package/dist/node/order/order.presentation.js +153 -0
  114. package/dist/node/order/order.schema.js +79 -0
  115. package/dist/node/payout/index.js +152 -0
  116. package/dist/node/payout/payout.enum.js +12 -0
  117. package/dist/node/payout/payout.event.js +55 -0
  118. package/dist/node/payout/payout.operations.js +94 -0
  119. package/dist/node/payout/payout.presentation.js +111 -0
  120. package/dist/node/payout/payout.schema.js +61 -0
  121. package/dist/node/product/index.js +249 -0
  122. package/dist/node/product/product.enum.js +13 -0
  123. package/dist/node/product/product.event.js +74 -0
  124. package/dist/node/product/product.operations.js +171 -0
  125. package/dist/node/product/product.presentation.js +158 -0
  126. package/dist/node/product/product.schema.js +84 -0
  127. package/dist/node/review/index.js +206 -0
  128. package/dist/node/review/review.enum.js +11 -0
  129. package/dist/node/review/review.event.js +50 -0
  130. package/dist/node/review/review.operations.js +152 -0
  131. package/dist/node/review/review.presentation.js +123 -0
  132. package/dist/node/review/review.schema.js +74 -0
  133. package/dist/node/seeders/index.js +12 -0
  134. package/dist/node/store/index.js +142 -0
  135. package/dist/node/store/store.enum.js +11 -0
  136. package/dist/node/store/store.event.js +52 -0
  137. package/dist/node/store/store.operations.js +88 -0
  138. package/dist/node/store/store.presentation.js +94 -0
  139. package/dist/node/store/store.schema.js +43 -0
  140. package/dist/node/tests/operations.test-spec.js +139 -0
  141. package/dist/node/ui/MarketplaceDashboard.js +418 -0
  142. package/dist/node/ui/hooks/index.js +59 -0
  143. package/dist/node/ui/hooks/useMarketplaceData.js +56 -0
  144. package/dist/node/ui/index.js +668 -0
  145. package/dist/node/ui/renderers/index.js +248 -0
  146. package/dist/node/ui/renderers/marketplace.markdown.js +248 -0
  147. package/dist/order/index.d.ts +8 -5
  148. package/dist/order/index.d.ts.map +1 -0
  149. package/dist/order/index.js +307 -5
  150. package/dist/order/order.enum.d.ts +1 -6
  151. package/dist/order/order.enum.d.ts.map +1 -1
  152. package/dist/order/order.enum.js +16 -20
  153. package/dist/order/order.event.d.ts +133 -139
  154. package/dist/order/order.event.d.ts.map +1 -1
  155. package/dist/order/order.event.js +121 -205
  156. package/dist/order/order.operations.d.ts +291 -297
  157. package/dist/order/order.operations.d.ts.map +1 -1
  158. package/dist/order/order.operations.js +169 -115
  159. package/dist/order/order.presentation.d.ts +3 -8
  160. package/dist/order/order.presentation.d.ts.map +1 -1
  161. package/dist/order/order.presentation.js +149 -81
  162. package/dist/order/order.schema.d.ts +143 -148
  163. package/dist/order/order.schema.d.ts.map +1 -1
  164. package/dist/order/order.schema.js +75 -150
  165. package/dist/payout/index.d.ts +8 -5
  166. package/dist/payout/index.d.ts.map +1 -0
  167. package/dist/payout/index.js +152 -5
  168. package/dist/payout/payout.enum.d.ts +1 -6
  169. package/dist/payout/payout.enum.d.ts.map +1 -1
  170. package/dist/payout/payout.enum.js +11 -15
  171. package/dist/payout/payout.event.d.ts +54 -60
  172. package/dist/payout/payout.event.d.ts.map +1 -1
  173. package/dist/payout/payout.event.js +51 -87
  174. package/dist/payout/payout.operations.d.ts +82 -88
  175. package/dist/payout/payout.operations.d.ts.map +1 -1
  176. package/dist/payout/payout.operations.js +92 -50
  177. package/dist/payout/payout.presentation.d.ts +2 -7
  178. package/dist/payout/payout.presentation.d.ts.map +1 -1
  179. package/dist/payout/payout.presentation.js +108 -56
  180. package/dist/payout/payout.schema.d.ts +139 -144
  181. package/dist/payout/payout.schema.d.ts.map +1 -1
  182. package/dist/payout/payout.schema.js +58 -112
  183. package/dist/product/index.d.ts +8 -5
  184. package/dist/product/index.d.ts.map +1 -0
  185. package/dist/product/index.js +249 -5
  186. package/dist/product/product.enum.d.ts +1 -6
  187. package/dist/product/product.enum.d.ts.map +1 -1
  188. package/dist/product/product.enum.js +12 -16
  189. package/dist/product/product.event.d.ts +63 -69
  190. package/dist/product/product.event.d.ts.map +1 -1
  191. package/dist/product/product.event.js +68 -113
  192. package/dist/product/product.operations.d.ts +225 -231
  193. package/dist/product/product.operations.d.ts.map +1 -1
  194. package/dist/product/product.operations.js +168 -104
  195. package/dist/product/product.presentation.d.ts +3 -8
  196. package/dist/product/product.presentation.d.ts.map +1 -1
  197. package/dist/product/product.presentation.js +154 -81
  198. package/dist/product/product.schema.d.ts +196 -201
  199. package/dist/product/product.schema.d.ts.map +1 -1
  200. package/dist/product/product.schema.js +80 -171
  201. package/dist/review/index.d.ts +8 -5
  202. package/dist/review/index.d.ts.map +1 -0
  203. package/dist/review/index.js +206 -5
  204. package/dist/review/review.enum.d.ts +1 -6
  205. package/dist/review/review.enum.d.ts.map +1 -1
  206. package/dist/review/review.enum.js +10 -14
  207. package/dist/review/review.event.d.ts +46 -52
  208. package/dist/review/review.event.d.ts.map +1 -1
  209. package/dist/review/review.event.js +46 -79
  210. package/dist/review/review.operations.d.ts +190 -196
  211. package/dist/review/review.operations.d.ts.map +1 -1
  212. package/dist/review/review.operations.js +149 -102
  213. package/dist/review/review.presentation.d.ts +2 -7
  214. package/dist/review/review.presentation.d.ts.map +1 -1
  215. package/dist/review/review.presentation.js +120 -56
  216. package/dist/review/review.schema.d.ts +164 -169
  217. package/dist/review/review.schema.d.ts.map +1 -1
  218. package/dist/review/review.schema.js +70 -151
  219. package/dist/seeders/index.d.ts +4 -8
  220. package/dist/seeders/index.d.ts.map +1 -1
  221. package/dist/seeders/index.js +11 -16
  222. package/dist/store/index.d.ts +8 -5
  223. package/dist/store/index.d.ts.map +1 -0
  224. package/dist/store/index.js +142 -5
  225. package/dist/store/store.enum.d.ts +1 -6
  226. package/dist/store/store.enum.d.ts.map +1 -1
  227. package/dist/store/store.enum.js +10 -14
  228. package/dist/store/store.event.d.ts +42 -48
  229. package/dist/store/store.event.d.ts.map +1 -1
  230. package/dist/store/store.event.js +48 -75
  231. package/dist/store/store.operations.d.ts +98 -104
  232. package/dist/store/store.operations.d.ts.map +1 -1
  233. package/dist/store/store.operations.js +86 -58
  234. package/dist/store/store.presentation.d.ts +2 -7
  235. package/dist/store/store.presentation.d.ts.map +1 -1
  236. package/dist/store/store.presentation.js +91 -56
  237. package/dist/store/store.schema.d.ts +70 -75
  238. package/dist/store/store.schema.d.ts.map +1 -1
  239. package/dist/store/store.schema.js +41 -90
  240. package/dist/tests/operations.test-spec.d.ts +5 -10
  241. package/dist/tests/operations.test-spec.d.ts.map +1 -1
  242. package/dist/tests/operations.test-spec.js +134 -146
  243. package/dist/ui/MarketplaceDashboard.d.ts +1 -6
  244. package/dist/ui/MarketplaceDashboard.d.ts.map +1 -1
  245. package/dist/ui/MarketplaceDashboard.js +413 -313
  246. package/dist/ui/hooks/index.d.ts +2 -2
  247. package/dist/ui/hooks/index.d.ts.map +1 -0
  248. package/dist/ui/hooks/index.js +59 -4
  249. package/dist/ui/hooks/useMarketplaceData.d.ts +16 -20
  250. package/dist/ui/hooks/useMarketplaceData.d.ts.map +1 -1
  251. package/dist/ui/hooks/useMarketplaceData.js +53 -60
  252. package/dist/ui/index.d.ts +7 -6
  253. package/dist/ui/index.d.ts.map +1 -0
  254. package/dist/ui/index.js +668 -5
  255. package/dist/ui/renderers/index.d.ts +2 -2
  256. package/dist/ui/renderers/index.d.ts.map +1 -0
  257. package/dist/ui/renderers/index.js +249 -3
  258. package/dist/ui/renderers/marketplace.markdown.d.ts +13 -14
  259. package/dist/ui/renderers/marketplace.markdown.d.ts.map +1 -1
  260. package/dist/ui/renderers/marketplace.markdown.js +241 -236
  261. package/package.json +528 -109
  262. package/dist/docs/marketplace.docblock.js.map +0 -1
  263. package/dist/entities/index.js.map +0 -1
  264. package/dist/entities/order.js.map +0 -1
  265. package/dist/entities/payout.js.map +0 -1
  266. package/dist/entities/product.js.map +0 -1
  267. package/dist/entities/review.js.map +0 -1
  268. package/dist/entities/store.js.map +0 -1
  269. package/dist/example.js.map +0 -1
  270. package/dist/handlers/marketplace.handlers.js.map +0 -1
  271. package/dist/marketplace.capability.js.map +0 -1
  272. package/dist/marketplace.feature.js.map +0 -1
  273. package/dist/order/order.enum.js.map +0 -1
  274. package/dist/order/order.event.js.map +0 -1
  275. package/dist/order/order.operations.js.map +0 -1
  276. package/dist/order/order.presentation.js.map +0 -1
  277. package/dist/order/order.schema.js.map +0 -1
  278. package/dist/payout/payout.enum.js.map +0 -1
  279. package/dist/payout/payout.event.js.map +0 -1
  280. package/dist/payout/payout.operations.js.map +0 -1
  281. package/dist/payout/payout.presentation.js.map +0 -1
  282. package/dist/payout/payout.schema.js.map +0 -1
  283. package/dist/product/product.enum.js.map +0 -1
  284. package/dist/product/product.event.js.map +0 -1
  285. package/dist/product/product.operations.js.map +0 -1
  286. package/dist/product/product.presentation.js.map +0 -1
  287. package/dist/product/product.schema.js.map +0 -1
  288. package/dist/review/review.enum.js.map +0 -1
  289. package/dist/review/review.event.js.map +0 -1
  290. package/dist/review/review.operations.js.map +0 -1
  291. package/dist/review/review.presentation.js.map +0 -1
  292. package/dist/review/review.schema.js.map +0 -1
  293. package/dist/seeders/index.js.map +0 -1
  294. package/dist/store/store.enum.js.map +0 -1
  295. package/dist/store/store.event.js.map +0 -1
  296. package/dist/store/store.operations.js.map +0 -1
  297. package/dist/store/store.presentation.js.map +0 -1
  298. package/dist/store/store.schema.js.map +0 -1
  299. package/dist/tests/operations.test-spec.js.map +0 -1
  300. package/dist/ui/MarketplaceDashboard.js.map +0 -1
  301. package/dist/ui/hooks/useMarketplaceData.js.map +0 -1
  302. package/dist/ui/renderers/marketplace.markdown.js.map +0 -1
package/dist/index.js CHANGED
@@ -1,32 +1,2017 @@
1
- import { StoreStatusEnum } from "./store/store.enum.js";
2
- import { CreateStoreInputModel, StoreModel } from "./store/store.schema.js";
3
- import { CreateStoreContract } from "./store/store.operations.js";
4
- import { StoreCreatedEvent, StoreStatusChangedEvent } from "./store/store.event.js";
5
- import "./store/index.js";
6
- import { ProductStatusEnum } from "./product/product.enum.js";
7
- import { CreateProductInputModel, ListProductsInputModel, ListProductsOutputModel, ProductModel } from "./product/product.schema.js";
8
- import { CreateProductContract, ListProductsContract } from "./product/product.operations.js";
9
- import { InventoryUpdatedEvent, ProductCreatedEvent, ProductPublishedEvent } from "./product/product.event.js";
10
- import "./product/index.js";
11
- import { OrderStatusEnum } from "./order/order.enum.js";
12
- import { CreateOrderInputModel, OrderItemModel, OrderModel, UpdateOrderStatusInputModel } from "./order/order.schema.js";
13
- import { CreateOrderContract, UpdateOrderStatusContract } from "./order/order.operations.js";
14
- import { OrderCompletedEvent, OrderCreatedEvent, OrderPaidEvent, OrderShippedEvent, OrderStatusUpdatedEvent } from "./order/order.event.js";
15
- import "./order/index.js";
16
- import { PayoutStatusEnum } from "./payout/payout.enum.js";
17
- import { ListPayoutsInputModel, ListPayoutsOutputModel, PayoutModel } from "./payout/payout.schema.js";
18
- import { ListPayoutsContract } from "./payout/payout.operations.js";
19
- import { PayoutCreatedEvent, PayoutPaidEvent } from "./payout/payout.event.js";
20
- import "./payout/index.js";
21
- import { ReviewStatusEnum } from "./review/review.enum.js";
22
- import { CreateReviewInputModel, ListReviewsInputModel, ListReviewsOutputModel, ReviewModel } from "./review/review.schema.js";
23
- import { CreateReviewContract, ListReviewsContract } from "./review/review.operations.js";
24
- import { ReviewCreatedEvent, ReviewRespondedEvent } from "./review/review.event.js";
25
- import "./review/index.js";
26
- import { createMarketplaceHandlers } from "./handlers/marketplace.handlers.js";
27
- import { marketplaceDashboardMarkdownRenderer, orderListMarkdownRenderer, productCatalogMarkdownRenderer } from "./ui/renderers/marketplace.markdown.js";
28
- import { useMarketplaceData } from "./ui/hooks/useMarketplaceData.js";
29
- import { MarketplaceDashboard } from "./ui/MarketplaceDashboard.js";
30
- import "./ui/index.js";
31
-
32
- export { CreateOrderContract, CreateOrderInputModel, CreateProductContract, CreateProductInputModel, CreateReviewContract, CreateReviewInputModel, CreateStoreContract, CreateStoreInputModel, InventoryUpdatedEvent, ListPayoutsContract, ListPayoutsInputModel, ListPayoutsOutputModel, ListProductsContract, ListProductsInputModel, ListProductsOutputModel, ListReviewsContract, ListReviewsInputModel, ListReviewsOutputModel, MarketplaceDashboard, OrderCompletedEvent, OrderCreatedEvent, OrderItemModel, OrderModel, OrderPaidEvent, OrderShippedEvent, OrderStatusEnum, OrderStatusUpdatedEvent, PayoutCreatedEvent, PayoutModel, PayoutPaidEvent, PayoutStatusEnum, ProductCreatedEvent, ProductModel, ProductPublishedEvent, ProductStatusEnum, ReviewCreatedEvent, ReviewModel, ReviewRespondedEvent, ReviewStatusEnum, StoreCreatedEvent, StoreModel, StoreStatusChangedEvent, StoreStatusEnum, UpdateOrderStatusContract, UpdateOrderStatusInputModel, createMarketplaceHandlers, marketplaceDashboardMarkdownRenderer, orderListMarkdownRenderer, productCatalogMarkdownRenderer, useMarketplaceData };
1
+ // @bun
2
+ // src/handlers/marketplace.handlers.ts
3
+ import { web } from "@contractspec/lib.runtime-sandbox";
4
+ var { generateId } = web;
5
+ function rowToStore(row) {
6
+ return {
7
+ id: row.id,
8
+ projectId: row.projectId,
9
+ organizationId: row.organizationId,
10
+ name: row.name,
11
+ description: row.description ?? undefined,
12
+ status: row.status,
13
+ rating: row.rating,
14
+ reviewCount: row.reviewCount,
15
+ createdAt: new Date(row.createdAt),
16
+ updatedAt: new Date(row.updatedAt)
17
+ };
18
+ }
19
+ function rowToProduct(row) {
20
+ return {
21
+ id: row.id,
22
+ storeId: row.storeId,
23
+ name: row.name,
24
+ description: row.description ?? undefined,
25
+ price: row.price,
26
+ currency: row.currency,
27
+ status: row.status,
28
+ stock: row.stock,
29
+ category: row.category ?? undefined,
30
+ imageUrl: row.imageUrl ?? undefined,
31
+ createdAt: new Date(row.createdAt),
32
+ updatedAt: new Date(row.updatedAt)
33
+ };
34
+ }
35
+ function rowToOrder(row) {
36
+ return {
37
+ id: row.id,
38
+ projectId: row.projectId,
39
+ storeId: row.storeId,
40
+ customerId: row.customerId,
41
+ status: row.status,
42
+ total: row.total,
43
+ currency: row.currency,
44
+ shippingAddress: row.shippingAddress ?? undefined,
45
+ createdAt: new Date(row.createdAt),
46
+ updatedAt: new Date(row.updatedAt)
47
+ };
48
+ }
49
+ function rowToOrderItem(row) {
50
+ return {
51
+ id: row.id,
52
+ orderId: row.orderId,
53
+ productId: row.productId,
54
+ quantity: row.quantity,
55
+ price: row.price,
56
+ createdAt: new Date(row.createdAt)
57
+ };
58
+ }
59
+ function rowToPayout(row) {
60
+ return {
61
+ id: row.id,
62
+ storeId: row.storeId,
63
+ amount: row.amount,
64
+ currency: row.currency,
65
+ status: row.status,
66
+ processedAt: row.processedAt ? new Date(row.processedAt) : undefined,
67
+ createdAt: new Date(row.createdAt)
68
+ };
69
+ }
70
+ function rowToReview(row) {
71
+ return {
72
+ id: row.id,
73
+ productId: row.productId,
74
+ customerId: row.customerId,
75
+ orderId: row.orderId ?? undefined,
76
+ rating: row.rating,
77
+ comment: row.comment ?? undefined,
78
+ createdAt: new Date(row.createdAt)
79
+ };
80
+ }
81
+ function createMarketplaceHandlers(db) {
82
+ async function listStores(input) {
83
+ const { projectId, status, search, limit = 20, offset = 0 } = input;
84
+ let whereClause = "WHERE projectId = ?";
85
+ const params = [projectId];
86
+ if (status && status !== "all") {
87
+ whereClause += " AND status = ?";
88
+ params.push(status);
89
+ }
90
+ if (search) {
91
+ whereClause += " AND name LIKE ?";
92
+ params.push(`%${search}%`);
93
+ }
94
+ const countResult = (await db.query(`SELECT COUNT(*) as count FROM marketplace_store ${whereClause}`, params)).rows;
95
+ const total = countResult[0]?.count ?? 0;
96
+ const rows = (await db.query(`SELECT * FROM marketplace_store ${whereClause} ORDER BY rating DESC LIMIT ? OFFSET ?`, [...params, limit, offset])).rows;
97
+ return {
98
+ stores: rows.map(rowToStore),
99
+ total
100
+ };
101
+ }
102
+ async function createStore(input, context) {
103
+ const id = generateId("store");
104
+ const now = new Date().toISOString();
105
+ await db.execute(`INSERT INTO marketplace_store (id, projectId, organizationId, name, description, status, rating, reviewCount, createdAt, updatedAt)
106
+ VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?)`, [
107
+ id,
108
+ context.projectId,
109
+ context.organizationId,
110
+ input.name,
111
+ input.description ?? null,
112
+ "PENDING",
113
+ 0,
114
+ 0,
115
+ now,
116
+ now
117
+ ]);
118
+ const rows = (await db.query(`SELECT * FROM marketplace_store WHERE id = ?`, [id])).rows;
119
+ return rowToStore(rows[0]);
120
+ }
121
+ async function listProducts(input) {
122
+ const { storeId, status, category, search, limit = 20, offset = 0 } = input;
123
+ let whereClause = "WHERE 1=1";
124
+ const params = [];
125
+ if (storeId) {
126
+ whereClause += " AND storeId = ?";
127
+ params.push(storeId);
128
+ }
129
+ if (status && status !== "all") {
130
+ whereClause += " AND status = ?";
131
+ params.push(status);
132
+ }
133
+ if (category) {
134
+ whereClause += " AND category = ?";
135
+ params.push(category);
136
+ }
137
+ if (search) {
138
+ whereClause += " AND name LIKE ?";
139
+ params.push(`%${search}%`);
140
+ }
141
+ const countResult = (await db.query(`SELECT COUNT(*) as count FROM marketplace_product ${whereClause}`, params)).rows;
142
+ const total = countResult[0]?.count ?? 0;
143
+ const rows = (await db.query(`SELECT * FROM marketplace_product ${whereClause} ORDER BY createdAt DESC LIMIT ? OFFSET ?`, [...params, limit, offset])).rows;
144
+ return {
145
+ products: rows.map(rowToProduct),
146
+ total
147
+ };
148
+ }
149
+ async function addProduct(input) {
150
+ const id = generateId("prod");
151
+ const now = new Date().toISOString();
152
+ await db.execute(`INSERT INTO marketplace_product (id, storeId, name, description, price, currency, status, stock, category, imageUrl, createdAt, updatedAt)
153
+ VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)`, [
154
+ id,
155
+ input.storeId,
156
+ input.name,
157
+ input.description ?? null,
158
+ input.price,
159
+ input.currency ?? "USD",
160
+ "DRAFT",
161
+ input.stock ?? 0,
162
+ input.category ?? null,
163
+ input.imageUrl ?? null,
164
+ now,
165
+ now
166
+ ]);
167
+ const rows = (await db.query(`SELECT * FROM marketplace_product WHERE id = ?`, [id])).rows;
168
+ return rowToProduct(rows[0]);
169
+ }
170
+ async function listOrders(input) {
171
+ const {
172
+ projectId,
173
+ storeId,
174
+ customerId,
175
+ status,
176
+ limit = 20,
177
+ offset = 0
178
+ } = input;
179
+ let whereClause = "WHERE projectId = ?";
180
+ const params = [projectId];
181
+ if (storeId) {
182
+ whereClause += " AND storeId = ?";
183
+ params.push(storeId);
184
+ }
185
+ if (customerId) {
186
+ whereClause += " AND customerId = ?";
187
+ params.push(customerId);
188
+ }
189
+ if (status && status !== "all") {
190
+ whereClause += " AND status = ?";
191
+ params.push(status);
192
+ }
193
+ const countResult = (await db.query(`SELECT COUNT(*) as count FROM marketplace_order ${whereClause}`, params)).rows;
194
+ const total = countResult[0]?.count ?? 0;
195
+ const revenueResult = (await db.query(`SELECT COALESCE(SUM(total), 0) as revenue FROM marketplace_order ${whereClause}`, params)).rows;
196
+ const totalRevenue = revenueResult[0]?.revenue ?? 0;
197
+ const rows = (await db.query(`SELECT * FROM marketplace_order ${whereClause} ORDER BY createdAt DESC LIMIT ? OFFSET ?`, [...params, limit, offset])).rows;
198
+ return {
199
+ orders: rows.map(rowToOrder),
200
+ total,
201
+ totalRevenue
202
+ };
203
+ }
204
+ async function placeOrder(input, context) {
205
+ const orderId = generateId("order");
206
+ const now = new Date().toISOString();
207
+ let total = 0;
208
+ const itemsToCreate = [];
209
+ for (const item of input.items) {
210
+ const products = (await db.query(`SELECT * FROM marketplace_product WHERE id = ?`, [
211
+ item.productId
212
+ ])).rows;
213
+ if (!products[0]) {
214
+ throw new Error(`Product not found: ${item.productId}`);
215
+ }
216
+ const itemPrice = products[0].price * item.quantity;
217
+ total += itemPrice;
218
+ itemsToCreate.push({
219
+ productId: item.productId,
220
+ quantity: item.quantity,
221
+ price: products[0].price
222
+ });
223
+ }
224
+ await db.execute(`INSERT INTO marketplace_order (id, projectId, storeId, customerId, status, total, currency, shippingAddress, createdAt, updatedAt)
225
+ VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?)`, [
226
+ orderId,
227
+ context.projectId,
228
+ input.storeId,
229
+ context.customerId,
230
+ "PENDING",
231
+ total,
232
+ "USD",
233
+ input.shippingAddress ?? null,
234
+ now,
235
+ now
236
+ ]);
237
+ for (const item of itemsToCreate) {
238
+ await db.execute(`INSERT INTO marketplace_order_item (id, orderId, productId, quantity, price, createdAt)
239
+ VALUES (?, ?, ?, ?, ?, ?)`, [
240
+ generateId("orditem"),
241
+ orderId,
242
+ item.productId,
243
+ item.quantity,
244
+ item.price,
245
+ now
246
+ ]);
247
+ }
248
+ const rows = (await db.query(`SELECT * FROM marketplace_order WHERE id = ?`, [orderId])).rows;
249
+ return rowToOrder(rows[0]);
250
+ }
251
+ async function getOrderItems(orderId) {
252
+ const rows = (await db.query(`SELECT * FROM marketplace_order_item WHERE orderId = ?`, [
253
+ orderId
254
+ ])).rows;
255
+ return rows.map(rowToOrderItem);
256
+ }
257
+ async function updateOrderStatus(orderId, status) {
258
+ const now = new Date().toISOString();
259
+ await db.execute(`UPDATE marketplace_order SET status = ?, updatedAt = ? WHERE id = ?`, [status, now, orderId]);
260
+ const rows = (await db.query(`SELECT * FROM marketplace_order WHERE id = ?`, [orderId])).rows;
261
+ return rowToOrder(rows[0]);
262
+ }
263
+ async function listPayouts(storeId) {
264
+ const rows = (await db.query(`SELECT * FROM marketplace_payout WHERE storeId = ? ORDER BY createdAt DESC`, [storeId])).rows;
265
+ return rows.map(rowToPayout);
266
+ }
267
+ async function listReviews(productId) {
268
+ const rows = (await db.query(`SELECT * FROM marketplace_review WHERE productId = ? ORDER BY createdAt DESC`, [productId])).rows;
269
+ return rows.map(rowToReview);
270
+ }
271
+ async function submitReview(input) {
272
+ const id = generateId("review");
273
+ const now = new Date().toISOString();
274
+ await db.execute(`INSERT INTO marketplace_review (id, productId, customerId, orderId, rating, comment, createdAt)
275
+ VALUES (?, ?, ?, ?, ?, ?, ?)`, [
276
+ id,
277
+ input.productId,
278
+ input.customerId,
279
+ input.orderId ?? null,
280
+ input.rating,
281
+ input.comment ?? null,
282
+ now,
283
+ now
284
+ ]);
285
+ const rows = (await db.query(`SELECT * FROM marketplace_review WHERE id = ?`, [id])).rows;
286
+ return rowToReview(rows[0]);
287
+ }
288
+ return {
289
+ listStores,
290
+ createStore,
291
+ listProducts,
292
+ addProduct,
293
+ listOrders,
294
+ placeOrder,
295
+ getOrderItems,
296
+ updateOrderStatus,
297
+ listPayouts,
298
+ listReviews,
299
+ submitReview
300
+ };
301
+ }
302
+
303
+ // src/store/store.enum.ts
304
+ import { defineEnum } from "@contractspec/lib.schema";
305
+ var StoreStatusEnum = defineEnum("StoreStatus", [
306
+ "PENDING",
307
+ "ACTIVE",
308
+ "SUSPENDED",
309
+ "CLOSED"
310
+ ]);
311
+
312
+ // src/store/store.schema.ts
313
+ import { defineSchemaModel, ScalarTypeEnum } from "@contractspec/lib.schema";
314
+ var StoreModel = defineSchemaModel({
315
+ name: "StoreModel",
316
+ description: "A seller store",
317
+ fields: {
318
+ id: { type: ScalarTypeEnum.String_unsecure(), isOptional: false },
319
+ name: { type: ScalarTypeEnum.String_unsecure(), isOptional: false },
320
+ slug: { type: ScalarTypeEnum.String_unsecure(), isOptional: false },
321
+ description: { type: ScalarTypeEnum.String_unsecure(), isOptional: true },
322
+ status: { type: StoreStatusEnum, isOptional: false },
323
+ ownerId: { type: ScalarTypeEnum.String_unsecure(), isOptional: false },
324
+ logoFileId: { type: ScalarTypeEnum.String_unsecure(), isOptional: true },
325
+ isVerified: { type: ScalarTypeEnum.Boolean(), isOptional: false },
326
+ totalProducts: { type: ScalarTypeEnum.Int_unsecure(), isOptional: false },
327
+ averageRating: { type: ScalarTypeEnum.Float_unsecure(), isOptional: false },
328
+ createdAt: { type: ScalarTypeEnum.DateTime(), isOptional: false }
329
+ }
330
+ });
331
+ var CreateStoreInputModel = defineSchemaModel({
332
+ name: "CreateStoreInput",
333
+ fields: {
334
+ name: { type: ScalarTypeEnum.NonEmptyString(), isOptional: false },
335
+ slug: { type: ScalarTypeEnum.NonEmptyString(), isOptional: false },
336
+ description: { type: ScalarTypeEnum.String_unsecure(), isOptional: true },
337
+ email: { type: ScalarTypeEnum.EmailAddress(), isOptional: true },
338
+ country: { type: ScalarTypeEnum.String_unsecure(), isOptional: true },
339
+ currency: { type: ScalarTypeEnum.String_unsecure(), isOptional: true }
340
+ }
341
+ });
342
+
343
+ // src/store/store.operations.ts
344
+ import { defineCommand } from "@contractspec/lib.contracts/operations";
345
+ var OWNERS = ["@example.marketplace"];
346
+ var CreateStoreContract = defineCommand({
347
+ meta: {
348
+ key: "marketplace.store.create",
349
+ version: "1.0.0",
350
+ stability: "stable",
351
+ owners: [...OWNERS],
352
+ tags: ["marketplace", "store", "create"],
353
+ description: "Create a new seller store.",
354
+ goal: "Allow users to become sellers on the marketplace.",
355
+ context: "Seller onboarding."
356
+ },
357
+ io: { input: CreateStoreInputModel, output: StoreModel },
358
+ policy: { auth: "user" },
359
+ sideEffects: {
360
+ emits: [
361
+ {
362
+ key: "marketplace.store.created",
363
+ version: "1.0.0",
364
+ when: "Store is created",
365
+ payload: StoreModel
366
+ }
367
+ ],
368
+ audit: ["marketplace.store.created"]
369
+ },
370
+ acceptance: {
371
+ scenarios: [
372
+ {
373
+ key: "create-store-happy-path",
374
+ given: ["User is authenticated"],
375
+ when: ["User creates a new store"],
376
+ then: ["Store is created", "StoreCreated event is emitted"]
377
+ }
378
+ ],
379
+ examples: [
380
+ {
381
+ key: "create-fashion-store",
382
+ input: { name: "Fashion Boutique", category: "clothing" },
383
+ output: { id: "store-123", status: "active" }
384
+ }
385
+ ]
386
+ }
387
+ });
388
+
389
+ // src/store/store.event.ts
390
+ import { ScalarTypeEnum as ScalarTypeEnum2, defineSchemaModel as defineSchemaModel2 } from "@contractspec/lib.schema";
391
+ import { defineEvent } from "@contractspec/lib.contracts";
392
+ var StoreCreatedPayload = defineSchemaModel2({
393
+ name: "StoreCreatedEventPayload",
394
+ fields: {
395
+ storeId: { type: ScalarTypeEnum2.String_unsecure(), isOptional: false },
396
+ name: { type: ScalarTypeEnum2.String_unsecure(), isOptional: false },
397
+ slug: { type: ScalarTypeEnum2.String_unsecure(), isOptional: false },
398
+ ownerId: { type: ScalarTypeEnum2.String_unsecure(), isOptional: false },
399
+ timestamp: { type: ScalarTypeEnum2.DateTime(), isOptional: false }
400
+ }
401
+ });
402
+ var StoreStatusChangedPayload = defineSchemaModel2({
403
+ name: "StoreStatusChangedEventPayload",
404
+ fields: {
405
+ storeId: { type: ScalarTypeEnum2.String_unsecure(), isOptional: false },
406
+ previousStatus: {
407
+ type: ScalarTypeEnum2.String_unsecure(),
408
+ isOptional: false
409
+ },
410
+ newStatus: { type: ScalarTypeEnum2.String_unsecure(), isOptional: false },
411
+ reason: { type: ScalarTypeEnum2.String_unsecure(), isOptional: true },
412
+ timestamp: { type: ScalarTypeEnum2.DateTime(), isOptional: false }
413
+ }
414
+ });
415
+ var StoreCreatedEvent = defineEvent({
416
+ meta: {
417
+ key: "marketplace.store.created",
418
+ version: "1.0.0",
419
+ description: "A new seller store has been created.",
420
+ stability: "experimental",
421
+ owners: ["@marketplace-team"],
422
+ tags: ["marketplace", "store"]
423
+ },
424
+ payload: StoreCreatedPayload
425
+ });
426
+ var StoreStatusChangedEvent = defineEvent({
427
+ meta: {
428
+ key: "marketplace.store.statusChanged",
429
+ version: "1.0.0",
430
+ description: "A store status has changed.",
431
+ stability: "experimental",
432
+ owners: ["@marketplace-team"],
433
+ tags: ["marketplace", "store"]
434
+ },
435
+ payload: StoreStatusChangedPayload
436
+ });
437
+ // src/product/product.enum.ts
438
+ import { defineEnum as defineEnum2 } from "@contractspec/lib.schema";
439
+ var ProductStatusEnum = defineEnum2("ProductStatus", [
440
+ "DRAFT",
441
+ "PENDING_REVIEW",
442
+ "ACTIVE",
443
+ "OUT_OF_STOCK",
444
+ "DISCONTINUED",
445
+ "REJECTED"
446
+ ]);
447
+
448
+ // src/product/product.schema.ts
449
+ import { defineSchemaModel as defineSchemaModel3, ScalarTypeEnum as ScalarTypeEnum3 } from "@contractspec/lib.schema";
450
+ var ProductModel = defineSchemaModel3({
451
+ name: "ProductModel",
452
+ description: "A product listing",
453
+ fields: {
454
+ id: { type: ScalarTypeEnum3.String_unsecure(), isOptional: false },
455
+ storeId: { type: ScalarTypeEnum3.String_unsecure(), isOptional: false },
456
+ name: { type: ScalarTypeEnum3.String_unsecure(), isOptional: false },
457
+ slug: { type: ScalarTypeEnum3.String_unsecure(), isOptional: false },
458
+ description: { type: ScalarTypeEnum3.String_unsecure(), isOptional: true },
459
+ status: { type: ProductStatusEnum, isOptional: false },
460
+ price: { type: ScalarTypeEnum3.Float_unsecure(), isOptional: false },
461
+ currency: { type: ScalarTypeEnum3.String_unsecure(), isOptional: false },
462
+ quantity: { type: ScalarTypeEnum3.Int_unsecure(), isOptional: false },
463
+ categoryId: { type: ScalarTypeEnum3.String_unsecure(), isOptional: true },
464
+ primaryImageId: {
465
+ type: ScalarTypeEnum3.String_unsecure(),
466
+ isOptional: true
467
+ },
468
+ averageRating: { type: ScalarTypeEnum3.Float_unsecure(), isOptional: false },
469
+ totalSold: { type: ScalarTypeEnum3.Int_unsecure(), isOptional: false },
470
+ createdAt: { type: ScalarTypeEnum3.DateTime(), isOptional: false }
471
+ }
472
+ });
473
+ var CreateProductInputModel = defineSchemaModel3({
474
+ name: "CreateProductInput",
475
+ fields: {
476
+ storeId: { type: ScalarTypeEnum3.String_unsecure(), isOptional: false },
477
+ name: { type: ScalarTypeEnum3.NonEmptyString(), isOptional: false },
478
+ slug: { type: ScalarTypeEnum3.NonEmptyString(), isOptional: false },
479
+ description: { type: ScalarTypeEnum3.String_unsecure(), isOptional: true },
480
+ price: { type: ScalarTypeEnum3.Float_unsecure(), isOptional: false },
481
+ currency: { type: ScalarTypeEnum3.String_unsecure(), isOptional: true },
482
+ quantity: { type: ScalarTypeEnum3.Int_unsecure(), isOptional: true },
483
+ categoryId: { type: ScalarTypeEnum3.String_unsecure(), isOptional: true },
484
+ sku: { type: ScalarTypeEnum3.String_unsecure(), isOptional: true }
485
+ }
486
+ });
487
+ var ListProductsInputModel = defineSchemaModel3({
488
+ name: "ListProductsInput",
489
+ fields: {
490
+ storeId: { type: ScalarTypeEnum3.String_unsecure(), isOptional: true },
491
+ categoryId: { type: ScalarTypeEnum3.String_unsecure(), isOptional: true },
492
+ status: { type: ProductStatusEnum, isOptional: true },
493
+ search: { type: ScalarTypeEnum3.String_unsecure(), isOptional: true },
494
+ minPrice: { type: ScalarTypeEnum3.Float_unsecure(), isOptional: true },
495
+ maxPrice: { type: ScalarTypeEnum3.Float_unsecure(), isOptional: true },
496
+ limit: {
497
+ type: ScalarTypeEnum3.Int_unsecure(),
498
+ isOptional: true,
499
+ defaultValue: 20
500
+ },
501
+ offset: {
502
+ type: ScalarTypeEnum3.Int_unsecure(),
503
+ isOptional: true,
504
+ defaultValue: 0
505
+ }
506
+ }
507
+ });
508
+ var ListProductsOutputModel = defineSchemaModel3({
509
+ name: "ListProductsOutput",
510
+ fields: {
511
+ products: { type: ProductModel, isArray: true, isOptional: false },
512
+ total: { type: ScalarTypeEnum3.Int_unsecure(), isOptional: false }
513
+ }
514
+ });
515
+
516
+ // src/product/product.operations.ts
517
+ import {
518
+ defineCommand as defineCommand2,
519
+ defineQuery
520
+ } from "@contractspec/lib.contracts/operations";
521
+ var OWNERS2 = ["@example.marketplace"];
522
+ var CreateProductContract = defineCommand2({
523
+ meta: {
524
+ key: "marketplace.product.create",
525
+ version: "1.0.0",
526
+ stability: "stable",
527
+ owners: [...OWNERS2],
528
+ tags: ["marketplace", "product", "create"],
529
+ description: "Create a new product listing.",
530
+ goal: "Allow sellers to list products.",
531
+ context: "Product management."
532
+ },
533
+ io: { input: CreateProductInputModel, output: ProductModel },
534
+ policy: { auth: "user" },
535
+ sideEffects: {
536
+ emits: [
537
+ {
538
+ key: "marketplace.product.created",
539
+ version: "1.0.0",
540
+ when: "Product is created",
541
+ payload: ProductModel
542
+ }
543
+ ],
544
+ audit: ["marketplace.product.created"]
545
+ },
546
+ acceptance: {
547
+ scenarios: [
548
+ {
549
+ key: "create-product-happy-path",
550
+ given: ["User is a seller"],
551
+ when: ["User creates a product listing"],
552
+ then: ["Product is created", "ProductCreated event is emitted"]
553
+ }
554
+ ],
555
+ examples: [
556
+ {
557
+ key: "create-t-shirt",
558
+ input: {
559
+ title: "Classic T-Shirt",
560
+ price: 25,
561
+ stock: 100,
562
+ storeId: "store-123"
563
+ },
564
+ output: {
565
+ id: "prod-456",
566
+ title: "Classic T-Shirt",
567
+ status: "published"
568
+ }
569
+ }
570
+ ]
571
+ }
572
+ });
573
+ var ListProductsContract = defineQuery({
574
+ meta: {
575
+ key: "marketplace.product.list",
576
+ version: "1.0.0",
577
+ stability: "stable",
578
+ owners: [...OWNERS2],
579
+ tags: ["marketplace", "product", "list"],
580
+ description: "List products with filters.",
581
+ goal: "Browse products on the marketplace.",
582
+ context: "Product catalog, search."
583
+ },
584
+ io: { input: ListProductsInputModel, output: ListProductsOutputModel },
585
+ policy: { auth: "anonymous" },
586
+ acceptance: {
587
+ scenarios: [
588
+ {
589
+ key: "list-products-happy-path",
590
+ given: ["Products exist"],
591
+ when: ["User searches for products"],
592
+ then: ["List of products is returned"]
593
+ }
594
+ ],
595
+ examples: [
596
+ {
597
+ key: "search-t-shirts",
598
+ input: { search: "t-shirt", limit: 20 },
599
+ output: { items: [], total: 50, hasMore: true }
600
+ }
601
+ ]
602
+ }
603
+ });
604
+
605
+ // src/product/product.event.ts
606
+ import { ScalarTypeEnum as ScalarTypeEnum4, defineSchemaModel as defineSchemaModel4 } from "@contractspec/lib.schema";
607
+ import { defineEvent as defineEvent2 } from "@contractspec/lib.contracts";
608
+ var ProductCreatedPayload = defineSchemaModel4({
609
+ name: "ProductCreatedEventPayload",
610
+ fields: {
611
+ productId: { type: ScalarTypeEnum4.String_unsecure(), isOptional: false },
612
+ storeId: { type: ScalarTypeEnum4.String_unsecure(), isOptional: false },
613
+ name: { type: ScalarTypeEnum4.String_unsecure(), isOptional: false },
614
+ price: { type: ScalarTypeEnum4.Float_unsecure(), isOptional: false },
615
+ currency: { type: ScalarTypeEnum4.String_unsecure(), isOptional: false },
616
+ timestamp: { type: ScalarTypeEnum4.DateTime(), isOptional: false }
617
+ }
618
+ });
619
+ var ProductPublishedPayload = defineSchemaModel4({
620
+ name: "ProductPublishedEventPayload",
621
+ fields: {
622
+ productId: { type: ScalarTypeEnum4.String_unsecure(), isOptional: false },
623
+ storeId: { type: ScalarTypeEnum4.String_unsecure(), isOptional: false },
624
+ timestamp: { type: ScalarTypeEnum4.DateTime(), isOptional: false }
625
+ }
626
+ });
627
+ var InventoryUpdatedPayload = defineSchemaModel4({
628
+ name: "InventoryUpdatedEventPayload",
629
+ fields: {
630
+ productId: { type: ScalarTypeEnum4.String_unsecure(), isOptional: false },
631
+ variantId: { type: ScalarTypeEnum4.String_unsecure(), isOptional: true },
632
+ previousQuantity: {
633
+ type: ScalarTypeEnum4.Int_unsecure(),
634
+ isOptional: false
635
+ },
636
+ newQuantity: { type: ScalarTypeEnum4.Int_unsecure(), isOptional: false },
637
+ reason: { type: ScalarTypeEnum4.String_unsecure(), isOptional: false },
638
+ timestamp: { type: ScalarTypeEnum4.DateTime(), isOptional: false }
639
+ }
640
+ });
641
+ var ProductCreatedEvent = defineEvent2({
642
+ meta: {
643
+ key: "marketplace.product.created",
644
+ version: "1.0.0",
645
+ description: "A new product has been created.",
646
+ stability: "experimental",
647
+ owners: ["@marketplace-team"],
648
+ tags: ["marketplace", "product"]
649
+ },
650
+ payload: ProductCreatedPayload
651
+ });
652
+ var ProductPublishedEvent = defineEvent2({
653
+ meta: {
654
+ key: "marketplace.product.published",
655
+ version: "1.0.0",
656
+ description: "A product has been published.",
657
+ stability: "experimental",
658
+ owners: ["@marketplace-team"],
659
+ tags: ["marketplace", "product"]
660
+ },
661
+ payload: ProductPublishedPayload
662
+ });
663
+ var InventoryUpdatedEvent = defineEvent2({
664
+ meta: {
665
+ key: "marketplace.inventory.updated",
666
+ version: "1.0.0",
667
+ description: "Product inventory has been updated.",
668
+ stability: "experimental",
669
+ owners: ["@marketplace-team"],
670
+ tags: ["marketplace", "product", "inventory"]
671
+ },
672
+ payload: InventoryUpdatedPayload
673
+ });
674
+ // src/order/order.enum.ts
675
+ import { defineEnum as defineEnum3 } from "@contractspec/lib.schema";
676
+ var OrderStatusEnum = defineEnum3("OrderStatus", [
677
+ "PENDING",
678
+ "PAID",
679
+ "PROCESSING",
680
+ "SHIPPED",
681
+ "DELIVERED",
682
+ "COMPLETED",
683
+ "CANCELLED",
684
+ "REFUNDED",
685
+ "PARTIALLY_REFUNDED",
686
+ "DISPUTED"
687
+ ]);
688
+
689
+ // src/order/order.schema.ts
690
+ import { defineSchemaModel as defineSchemaModel5, ScalarTypeEnum as ScalarTypeEnum5 } from "@contractspec/lib.schema";
691
+ var OrderItemModel = defineSchemaModel5({
692
+ name: "OrderItemModel",
693
+ fields: {
694
+ id: { type: ScalarTypeEnum5.String_unsecure(), isOptional: false },
695
+ productId: { type: ScalarTypeEnum5.String_unsecure(), isOptional: false },
696
+ productName: { type: ScalarTypeEnum5.String_unsecure(), isOptional: false },
697
+ unitPrice: { type: ScalarTypeEnum5.Float_unsecure(), isOptional: false },
698
+ quantity: { type: ScalarTypeEnum5.Int_unsecure(), isOptional: false },
699
+ subtotal: { type: ScalarTypeEnum5.Float_unsecure(), isOptional: false }
700
+ }
701
+ });
702
+ var OrderModel = defineSchemaModel5({
703
+ name: "OrderModel",
704
+ description: "An order",
705
+ fields: {
706
+ id: { type: ScalarTypeEnum5.String_unsecure(), isOptional: false },
707
+ orderNumber: { type: ScalarTypeEnum5.String_unsecure(), isOptional: false },
708
+ buyerId: { type: ScalarTypeEnum5.String_unsecure(), isOptional: false },
709
+ storeId: { type: ScalarTypeEnum5.String_unsecure(), isOptional: false },
710
+ status: { type: OrderStatusEnum, isOptional: false },
711
+ subtotal: { type: ScalarTypeEnum5.Float_unsecure(), isOptional: false },
712
+ shippingTotal: { type: ScalarTypeEnum5.Float_unsecure(), isOptional: false },
713
+ taxTotal: { type: ScalarTypeEnum5.Float_unsecure(), isOptional: false },
714
+ total: { type: ScalarTypeEnum5.Float_unsecure(), isOptional: false },
715
+ currency: { type: ScalarTypeEnum5.String_unsecure(), isOptional: false },
716
+ items: { type: OrderItemModel, isArray: true, isOptional: true },
717
+ createdAt: { type: ScalarTypeEnum5.DateTime(), isOptional: false }
718
+ }
719
+ });
720
+ var CreateOrderInputModel = defineSchemaModel5({
721
+ name: "CreateOrderInput",
722
+ fields: {
723
+ storeId: { type: ScalarTypeEnum5.String_unsecure(), isOptional: false },
724
+ items: {
725
+ type: ScalarTypeEnum5.JSON(),
726
+ isOptional: false,
727
+ description: "Array of {productId, variantId?, quantity}"
728
+ },
729
+ shippingAddress: { type: ScalarTypeEnum5.JSON(), isOptional: true },
730
+ billingAddress: { type: ScalarTypeEnum5.JSON(), isOptional: true },
731
+ buyerNote: { type: ScalarTypeEnum5.String_unsecure(), isOptional: true }
732
+ }
733
+ });
734
+ var UpdateOrderStatusInputModel = defineSchemaModel5({
735
+ name: "UpdateOrderStatusInput",
736
+ fields: {
737
+ orderId: { type: ScalarTypeEnum5.String_unsecure(), isOptional: false },
738
+ status: { type: OrderStatusEnum, isOptional: false },
739
+ trackingNumber: {
740
+ type: ScalarTypeEnum5.String_unsecure(),
741
+ isOptional: true
742
+ },
743
+ trackingUrl: { type: ScalarTypeEnum5.String_unsecure(), isOptional: true },
744
+ note: { type: ScalarTypeEnum5.String_unsecure(), isOptional: true }
745
+ }
746
+ });
747
+
748
+ // src/order/order.operations.ts
749
+ import { defineCommand as defineCommand3 } from "@contractspec/lib.contracts/operations";
750
+ var OWNERS3 = ["@example.marketplace"];
751
+ var CreateOrderContract = defineCommand3({
752
+ meta: {
753
+ key: "marketplace.order.create",
754
+ version: "1.0.0",
755
+ stability: "stable",
756
+ owners: [...OWNERS3],
757
+ tags: ["marketplace", "order", "create"],
758
+ description: "Create a new order.",
759
+ goal: "Allow buyers to purchase products.",
760
+ context: "Checkout flow."
761
+ },
762
+ io: { input: CreateOrderInputModel, output: OrderModel },
763
+ policy: { auth: "user" },
764
+ sideEffects: {
765
+ emits: [
766
+ {
767
+ key: "marketplace.order.created",
768
+ version: "1.0.0",
769
+ when: "Order is created",
770
+ payload: OrderModel
771
+ }
772
+ ],
773
+ audit: ["marketplace.order.created"]
774
+ },
775
+ acceptance: {
776
+ scenarios: [
777
+ {
778
+ key: "create-order-happy-path",
779
+ given: ["User is authenticated"],
780
+ when: ["User creates order with valid items"],
781
+ then: ["Order is created", "OrderCreated event is emitted"]
782
+ }
783
+ ],
784
+ examples: [
785
+ {
786
+ key: "create-basic-order",
787
+ input: {
788
+ storeId: "store-123",
789
+ items: [{ productId: "prod-456", quantity: 1, unitPrice: 100 }]
790
+ },
791
+ output: { id: "order-789", status: "pending", total: 100 }
792
+ }
793
+ ]
794
+ }
795
+ });
796
+ var UpdateOrderStatusContract = defineCommand3({
797
+ meta: {
798
+ key: "marketplace.order.updateStatus",
799
+ version: "1.0.0",
800
+ stability: "stable",
801
+ owners: [...OWNERS3],
802
+ tags: ["marketplace", "order", "status"],
803
+ description: "Update order status.",
804
+ goal: "Track order fulfillment.",
805
+ context: "Order management."
806
+ },
807
+ io: { input: UpdateOrderStatusInputModel, output: OrderModel },
808
+ policy: { auth: "user" },
809
+ sideEffects: {
810
+ emits: [
811
+ {
812
+ key: "marketplace.order.statusUpdated",
813
+ version: "1.0.0",
814
+ when: "Status changes",
815
+ payload: OrderModel
816
+ }
817
+ ],
818
+ audit: ["marketplace.order.statusUpdated"]
819
+ },
820
+ acceptance: {
821
+ scenarios: [
822
+ {
823
+ key: "update-status-happy-path",
824
+ given: ["Order exists"],
825
+ when: ["Seller updates order status"],
826
+ then: ["Status is updated", "OrderStatusUpdated event is emitted"]
827
+ }
828
+ ],
829
+ examples: [
830
+ {
831
+ key: "mark-shipped",
832
+ input: {
833
+ orderId: "order-789",
834
+ status: "shipped",
835
+ trackingNumber: "TRACK123"
836
+ },
837
+ output: { id: "order-789", status: "shipped" }
838
+ }
839
+ ]
840
+ }
841
+ });
842
+
843
+ // src/order/order.event.ts
844
+ import { ScalarTypeEnum as ScalarTypeEnum6, defineSchemaModel as defineSchemaModel6 } from "@contractspec/lib.schema";
845
+ import { defineEvent as defineEvent3 } from "@contractspec/lib.contracts";
846
+ var OrderCreatedPayload = defineSchemaModel6({
847
+ name: "OrderCreatedEventPayload",
848
+ fields: {
849
+ orderId: { type: ScalarTypeEnum6.String_unsecure(), isOptional: false },
850
+ orderNumber: { type: ScalarTypeEnum6.String_unsecure(), isOptional: false },
851
+ buyerId: { type: ScalarTypeEnum6.String_unsecure(), isOptional: false },
852
+ storeId: { type: ScalarTypeEnum6.String_unsecure(), isOptional: false },
853
+ total: { type: ScalarTypeEnum6.Float_unsecure(), isOptional: false },
854
+ currency: { type: ScalarTypeEnum6.String_unsecure(), isOptional: false },
855
+ itemCount: { type: ScalarTypeEnum6.Int_unsecure(), isOptional: false },
856
+ timestamp: { type: ScalarTypeEnum6.DateTime(), isOptional: false }
857
+ }
858
+ });
859
+ var OrderPaidPayload = defineSchemaModel6({
860
+ name: "OrderPaidEventPayload",
861
+ fields: {
862
+ orderId: { type: ScalarTypeEnum6.String_unsecure(), isOptional: false },
863
+ orderNumber: { type: ScalarTypeEnum6.String_unsecure(), isOptional: false },
864
+ total: { type: ScalarTypeEnum6.Float_unsecure(), isOptional: false },
865
+ paymentMethod: {
866
+ type: ScalarTypeEnum6.String_unsecure(),
867
+ isOptional: false
868
+ },
869
+ timestamp: { type: ScalarTypeEnum6.DateTime(), isOptional: false }
870
+ }
871
+ });
872
+ var OrderStatusUpdatedPayload = defineSchemaModel6({
873
+ name: "OrderStatusUpdatedEventPayload",
874
+ fields: {
875
+ orderId: { type: ScalarTypeEnum6.String_unsecure(), isOptional: false },
876
+ orderNumber: { type: ScalarTypeEnum6.String_unsecure(), isOptional: false },
877
+ previousStatus: {
878
+ type: ScalarTypeEnum6.String_unsecure(),
879
+ isOptional: false
880
+ },
881
+ newStatus: { type: ScalarTypeEnum6.String_unsecure(), isOptional: false },
882
+ updatedBy: { type: ScalarTypeEnum6.String_unsecure(), isOptional: false },
883
+ timestamp: { type: ScalarTypeEnum6.DateTime(), isOptional: false }
884
+ }
885
+ });
886
+ var OrderShippedPayload = defineSchemaModel6({
887
+ name: "OrderShippedEventPayload",
888
+ fields: {
889
+ orderId: { type: ScalarTypeEnum6.String_unsecure(), isOptional: false },
890
+ orderNumber: { type: ScalarTypeEnum6.String_unsecure(), isOptional: false },
891
+ trackingNumber: {
892
+ type: ScalarTypeEnum6.String_unsecure(),
893
+ isOptional: true
894
+ },
895
+ trackingUrl: { type: ScalarTypeEnum6.String_unsecure(), isOptional: true },
896
+ carrier: { type: ScalarTypeEnum6.String_unsecure(), isOptional: true },
897
+ timestamp: { type: ScalarTypeEnum6.DateTime(), isOptional: false }
898
+ }
899
+ });
900
+ var OrderCompletedPayload = defineSchemaModel6({
901
+ name: "OrderCompletedEventPayload",
902
+ fields: {
903
+ orderId: { type: ScalarTypeEnum6.String_unsecure(), isOptional: false },
904
+ orderNumber: { type: ScalarTypeEnum6.String_unsecure(), isOptional: false },
905
+ buyerId: { type: ScalarTypeEnum6.String_unsecure(), isOptional: false },
906
+ storeId: { type: ScalarTypeEnum6.String_unsecure(), isOptional: false },
907
+ total: { type: ScalarTypeEnum6.Float_unsecure(), isOptional: false },
908
+ sellerPayout: { type: ScalarTypeEnum6.Float_unsecure(), isOptional: false },
909
+ timestamp: { type: ScalarTypeEnum6.DateTime(), isOptional: false }
910
+ }
911
+ });
912
+ var OrderCreatedEvent = defineEvent3({
913
+ meta: {
914
+ key: "marketplace.order.created",
915
+ version: "1.0.0",
916
+ description: "A new order has been created.",
917
+ stability: "experimental",
918
+ owners: ["@marketplace-team"],
919
+ tags: ["marketplace", "order"]
920
+ },
921
+ payload: OrderCreatedPayload
922
+ });
923
+ var OrderPaidEvent = defineEvent3({
924
+ meta: {
925
+ key: "marketplace.order.paid",
926
+ version: "1.0.0",
927
+ description: "An order has been paid.",
928
+ stability: "experimental",
929
+ owners: ["@marketplace-team"],
930
+ tags: ["marketplace", "order"]
931
+ },
932
+ payload: OrderPaidPayload
933
+ });
934
+ var OrderStatusUpdatedEvent = defineEvent3({
935
+ meta: {
936
+ key: "marketplace.order.statusUpdated",
937
+ version: "1.0.0",
938
+ description: "An order status has been updated.",
939
+ stability: "experimental",
940
+ owners: ["@marketplace-team"],
941
+ tags: ["marketplace", "order"]
942
+ },
943
+ payload: OrderStatusUpdatedPayload
944
+ });
945
+ var OrderShippedEvent = defineEvent3({
946
+ meta: {
947
+ key: "marketplace.order.shipped",
948
+ version: "1.0.0",
949
+ description: "An order has been shipped.",
950
+ stability: "experimental",
951
+ owners: ["@marketplace-team"],
952
+ tags: ["marketplace", "order"]
953
+ },
954
+ payload: OrderShippedPayload
955
+ });
956
+ var OrderCompletedEvent = defineEvent3({
957
+ meta: {
958
+ key: "marketplace.order.completed",
959
+ version: "1.0.0",
960
+ description: "An order has been completed.",
961
+ stability: "experimental",
962
+ owners: ["@marketplace-team"],
963
+ tags: ["marketplace", "order"]
964
+ },
965
+ payload: OrderCompletedPayload
966
+ });
967
+ // src/payout/payout.enum.ts
968
+ import { defineEnum as defineEnum4 } from "@contractspec/lib.schema";
969
+ var PayoutStatusEnum = defineEnum4("PayoutStatus", [
970
+ "PENDING",
971
+ "PROCESSING",
972
+ "PAID",
973
+ "FAILED",
974
+ "CANCELLED"
975
+ ]);
976
+
977
+ // src/payout/payout.schema.ts
978
+ import { defineSchemaModel as defineSchemaModel7, ScalarTypeEnum as ScalarTypeEnum7 } from "@contractspec/lib.schema";
979
+ var PayoutModel = defineSchemaModel7({
980
+ name: "PayoutModel",
981
+ description: "A payout to seller",
982
+ fields: {
983
+ id: { type: ScalarTypeEnum7.String_unsecure(), isOptional: false },
984
+ payoutNumber: { type: ScalarTypeEnum7.String_unsecure(), isOptional: false },
985
+ storeId: { type: ScalarTypeEnum7.String_unsecure(), isOptional: false },
986
+ status: { type: PayoutStatusEnum, isOptional: false },
987
+ grossAmount: { type: ScalarTypeEnum7.Float_unsecure(), isOptional: false },
988
+ platformFees: { type: ScalarTypeEnum7.Float_unsecure(), isOptional: false },
989
+ netAmount: { type: ScalarTypeEnum7.Float_unsecure(), isOptional: false },
990
+ currency: { type: ScalarTypeEnum7.String_unsecure(), isOptional: false },
991
+ periodStart: { type: ScalarTypeEnum7.DateTime(), isOptional: false },
992
+ periodEnd: { type: ScalarTypeEnum7.DateTime(), isOptional: false },
993
+ orderCount: { type: ScalarTypeEnum7.Int_unsecure(), isOptional: false },
994
+ createdAt: { type: ScalarTypeEnum7.DateTime(), isOptional: false },
995
+ paidAt: { type: ScalarTypeEnum7.DateTime(), isOptional: true }
996
+ }
997
+ });
998
+ var ListPayoutsInputModel = defineSchemaModel7({
999
+ name: "ListPayoutsInput",
1000
+ fields: {
1001
+ storeId: { type: ScalarTypeEnum7.String_unsecure(), isOptional: false },
1002
+ status: { type: PayoutStatusEnum, isOptional: true },
1003
+ limit: {
1004
+ type: ScalarTypeEnum7.Int_unsecure(),
1005
+ isOptional: true,
1006
+ defaultValue: 20
1007
+ },
1008
+ offset: {
1009
+ type: ScalarTypeEnum7.Int_unsecure(),
1010
+ isOptional: true,
1011
+ defaultValue: 0
1012
+ }
1013
+ }
1014
+ });
1015
+ var ListPayoutsOutputModel = defineSchemaModel7({
1016
+ name: "ListPayoutsOutput",
1017
+ fields: {
1018
+ payouts: { type: PayoutModel, isArray: true, isOptional: false },
1019
+ total: { type: ScalarTypeEnum7.Int_unsecure(), isOptional: false },
1020
+ totalPending: { type: ScalarTypeEnum7.Float_unsecure(), isOptional: false }
1021
+ }
1022
+ });
1023
+
1024
+ // src/payout/payout.operations.ts
1025
+ import { defineQuery as defineQuery2 } from "@contractspec/lib.contracts/operations";
1026
+ var OWNERS4 = ["@example.marketplace"];
1027
+ var ListPayoutsContract = defineQuery2({
1028
+ meta: {
1029
+ key: "marketplace.payout.list",
1030
+ version: "1.0.0",
1031
+ stability: "stable",
1032
+ owners: [...OWNERS4],
1033
+ tags: ["marketplace", "payout", "list"],
1034
+ description: "List payouts for a store.",
1035
+ goal: "View payout history.",
1036
+ context: "Seller dashboard."
1037
+ },
1038
+ io: { input: ListPayoutsInputModel, output: ListPayoutsOutputModel },
1039
+ policy: { auth: "user" },
1040
+ acceptance: {
1041
+ scenarios: [
1042
+ {
1043
+ key: "list-payouts-happy-path",
1044
+ given: ["Store has payout history"],
1045
+ when: ["Seller lists payouts"],
1046
+ then: ["List of payouts is returned"]
1047
+ }
1048
+ ],
1049
+ examples: [
1050
+ {
1051
+ key: "list-recent",
1052
+ input: { limit: 10, offset: 0 },
1053
+ output: { items: [], total: 5, hasMore: false }
1054
+ }
1055
+ ]
1056
+ }
1057
+ });
1058
+
1059
+ // src/payout/payout.event.ts
1060
+ import { ScalarTypeEnum as ScalarTypeEnum8, defineSchemaModel as defineSchemaModel8 } from "@contractspec/lib.schema";
1061
+ import { defineEvent as defineEvent4 } from "@contractspec/lib.contracts";
1062
+ var PayoutCreatedPayload = defineSchemaModel8({
1063
+ name: "PayoutCreatedEventPayload",
1064
+ fields: {
1065
+ payoutId: { type: ScalarTypeEnum8.String_unsecure(), isOptional: false },
1066
+ payoutNumber: { type: ScalarTypeEnum8.String_unsecure(), isOptional: false },
1067
+ storeId: { type: ScalarTypeEnum8.String_unsecure(), isOptional: false },
1068
+ netAmount: { type: ScalarTypeEnum8.Float_unsecure(), isOptional: false },
1069
+ currency: { type: ScalarTypeEnum8.String_unsecure(), isOptional: false },
1070
+ orderCount: { type: ScalarTypeEnum8.Int_unsecure(), isOptional: false },
1071
+ timestamp: { type: ScalarTypeEnum8.DateTime(), isOptional: false }
1072
+ }
1073
+ });
1074
+ var PayoutPaidPayload = defineSchemaModel8({
1075
+ name: "PayoutPaidEventPayload",
1076
+ fields: {
1077
+ payoutId: { type: ScalarTypeEnum8.String_unsecure(), isOptional: false },
1078
+ payoutNumber: { type: ScalarTypeEnum8.String_unsecure(), isOptional: false },
1079
+ storeId: { type: ScalarTypeEnum8.String_unsecure(), isOptional: false },
1080
+ netAmount: { type: ScalarTypeEnum8.Float_unsecure(), isOptional: false },
1081
+ paymentReference: {
1082
+ type: ScalarTypeEnum8.String_unsecure(),
1083
+ isOptional: true
1084
+ },
1085
+ timestamp: { type: ScalarTypeEnum8.DateTime(), isOptional: false }
1086
+ }
1087
+ });
1088
+ var PayoutCreatedEvent = defineEvent4({
1089
+ meta: {
1090
+ key: "marketplace.payout.created",
1091
+ version: "1.0.0",
1092
+ description: "A payout has been created.",
1093
+ stability: "experimental",
1094
+ owners: ["@marketplace-team"],
1095
+ tags: ["marketplace", "payout"]
1096
+ },
1097
+ payload: PayoutCreatedPayload
1098
+ });
1099
+ var PayoutPaidEvent = defineEvent4({
1100
+ meta: {
1101
+ key: "marketplace.payout.paid",
1102
+ version: "1.0.0",
1103
+ description: "A payout has been sent.",
1104
+ stability: "experimental",
1105
+ owners: ["@marketplace-team"],
1106
+ tags: ["marketplace", "payout"]
1107
+ },
1108
+ payload: PayoutPaidPayload
1109
+ });
1110
+ // src/review/review.enum.ts
1111
+ import { defineEnum as defineEnum5 } from "@contractspec/lib.schema";
1112
+ var ReviewStatusEnum = defineEnum5("ReviewStatus", [
1113
+ "PENDING",
1114
+ "APPROVED",
1115
+ "REJECTED",
1116
+ "FLAGGED"
1117
+ ]);
1118
+
1119
+ // src/review/review.schema.ts
1120
+ import { defineSchemaModel as defineSchemaModel9, ScalarTypeEnum as ScalarTypeEnum9 } from "@contractspec/lib.schema";
1121
+ var ReviewModel = defineSchemaModel9({
1122
+ name: "ReviewModel",
1123
+ description: "A customer review",
1124
+ fields: {
1125
+ id: { type: ScalarTypeEnum9.String_unsecure(), isOptional: false },
1126
+ productId: { type: ScalarTypeEnum9.String_unsecure(), isOptional: true },
1127
+ storeId: { type: ScalarTypeEnum9.String_unsecure(), isOptional: true },
1128
+ authorId: { type: ScalarTypeEnum9.String_unsecure(), isOptional: false },
1129
+ rating: { type: ScalarTypeEnum9.Int_unsecure(), isOptional: false },
1130
+ title: { type: ScalarTypeEnum9.String_unsecure(), isOptional: true },
1131
+ content: { type: ScalarTypeEnum9.String_unsecure(), isOptional: true },
1132
+ status: { type: ReviewStatusEnum, isOptional: false },
1133
+ isVerifiedPurchase: { type: ScalarTypeEnum9.Boolean(), isOptional: false },
1134
+ helpfulCount: { type: ScalarTypeEnum9.Int_unsecure(), isOptional: false },
1135
+ hasResponse: { type: ScalarTypeEnum9.Boolean(), isOptional: false },
1136
+ createdAt: { type: ScalarTypeEnum9.DateTime(), isOptional: false }
1137
+ }
1138
+ });
1139
+ var CreateReviewInputModel = defineSchemaModel9({
1140
+ name: "CreateReviewInput",
1141
+ fields: {
1142
+ productId: { type: ScalarTypeEnum9.String_unsecure(), isOptional: true },
1143
+ storeId: { type: ScalarTypeEnum9.String_unsecure(), isOptional: true },
1144
+ orderId: { type: ScalarTypeEnum9.String_unsecure(), isOptional: true },
1145
+ rating: { type: ScalarTypeEnum9.Int_unsecure(), isOptional: false },
1146
+ title: { type: ScalarTypeEnum9.String_unsecure(), isOptional: true },
1147
+ content: { type: ScalarTypeEnum9.String_unsecure(), isOptional: true }
1148
+ }
1149
+ });
1150
+ var ListReviewsInputModel = defineSchemaModel9({
1151
+ name: "ListReviewsInput",
1152
+ fields: {
1153
+ productId: { type: ScalarTypeEnum9.String_unsecure(), isOptional: true },
1154
+ storeId: { type: ScalarTypeEnum9.String_unsecure(), isOptional: true },
1155
+ status: { type: ReviewStatusEnum, isOptional: true },
1156
+ minRating: { type: ScalarTypeEnum9.Int_unsecure(), isOptional: true },
1157
+ limit: {
1158
+ type: ScalarTypeEnum9.Int_unsecure(),
1159
+ isOptional: true,
1160
+ defaultValue: 20
1161
+ },
1162
+ offset: {
1163
+ type: ScalarTypeEnum9.Int_unsecure(),
1164
+ isOptional: true,
1165
+ defaultValue: 0
1166
+ }
1167
+ }
1168
+ });
1169
+ var ListReviewsOutputModel = defineSchemaModel9({
1170
+ name: "ListReviewsOutput",
1171
+ fields: {
1172
+ reviews: { type: ReviewModel, isArray: true, isOptional: false },
1173
+ total: { type: ScalarTypeEnum9.Int_unsecure(), isOptional: false },
1174
+ averageRating: { type: ScalarTypeEnum9.Float_unsecure(), isOptional: false },
1175
+ ratingDistribution: { type: ScalarTypeEnum9.JSON(), isOptional: false }
1176
+ }
1177
+ });
1178
+
1179
+ // src/review/review.operations.ts
1180
+ import {
1181
+ defineCommand as defineCommand4,
1182
+ defineQuery as defineQuery3
1183
+ } from "@contractspec/lib.contracts/operations";
1184
+ var OWNERS5 = ["@example.marketplace"];
1185
+ var CreateReviewContract = defineCommand4({
1186
+ meta: {
1187
+ key: "marketplace.review.create",
1188
+ version: "1.0.0",
1189
+ stability: "stable",
1190
+ owners: [...OWNERS5],
1191
+ tags: ["marketplace", "review", "create"],
1192
+ description: "Create a product/store review.",
1193
+ goal: "Allow buyers to leave feedback.",
1194
+ context: "Post-purchase."
1195
+ },
1196
+ io: { input: CreateReviewInputModel, output: ReviewModel },
1197
+ policy: { auth: "user" },
1198
+ sideEffects: {
1199
+ emits: [
1200
+ {
1201
+ key: "marketplace.review.created",
1202
+ version: "1.0.0",
1203
+ when: "Review is created",
1204
+ payload: ReviewModel
1205
+ }
1206
+ ],
1207
+ audit: ["marketplace.review.created"]
1208
+ },
1209
+ acceptance: {
1210
+ scenarios: [
1211
+ {
1212
+ key: "create-review-happy-path",
1213
+ given: ["User purchased product"],
1214
+ when: ["User leaves a review"],
1215
+ then: ["Review is created", "ReviewCreated event is emitted"]
1216
+ }
1217
+ ],
1218
+ examples: [
1219
+ {
1220
+ key: "create-5-star",
1221
+ input: { productId: "prod-456", rating: 5, comment: "Great product!" },
1222
+ output: { id: "rev-789", status: "published" }
1223
+ }
1224
+ ]
1225
+ }
1226
+ });
1227
+ var ListReviewsContract = defineQuery3({
1228
+ meta: {
1229
+ key: "marketplace.review.list",
1230
+ version: "1.0.0",
1231
+ stability: "stable",
1232
+ owners: [...OWNERS5],
1233
+ tags: ["marketplace", "review", "list"],
1234
+ description: "List reviews with filters.",
1235
+ goal: "Display product/store reviews.",
1236
+ context: "Product page, store page."
1237
+ },
1238
+ io: { input: ListReviewsInputModel, output: ListReviewsOutputModel },
1239
+ policy: { auth: "anonymous" },
1240
+ acceptance: {
1241
+ scenarios: [
1242
+ {
1243
+ key: "list-reviews-happy-path",
1244
+ given: ["Product has reviews"],
1245
+ when: ["User views reviews"],
1246
+ then: ["List of reviews is returned"]
1247
+ }
1248
+ ],
1249
+ examples: [
1250
+ {
1251
+ key: "list-product-reviews",
1252
+ input: { productId: "prod-456", limit: 10 },
1253
+ output: { items: [], total: 10, hasMore: false }
1254
+ }
1255
+ ]
1256
+ }
1257
+ });
1258
+
1259
+ // src/review/review.event.ts
1260
+ import { ScalarTypeEnum as ScalarTypeEnum10, defineSchemaModel as defineSchemaModel10 } from "@contractspec/lib.schema";
1261
+ import { defineEvent as defineEvent5 } from "@contractspec/lib.contracts";
1262
+ var ReviewCreatedPayload = defineSchemaModel10({
1263
+ name: "ReviewCreatedEventPayload",
1264
+ fields: {
1265
+ reviewId: { type: ScalarTypeEnum10.String_unsecure(), isOptional: false },
1266
+ productId: { type: ScalarTypeEnum10.String_unsecure(), isOptional: true },
1267
+ storeId: { type: ScalarTypeEnum10.String_unsecure(), isOptional: true },
1268
+ authorId: { type: ScalarTypeEnum10.String_unsecure(), isOptional: false },
1269
+ rating: { type: ScalarTypeEnum10.Int_unsecure(), isOptional: false },
1270
+ isVerifiedPurchase: { type: ScalarTypeEnum10.Boolean(), isOptional: false },
1271
+ timestamp: { type: ScalarTypeEnum10.DateTime(), isOptional: false }
1272
+ }
1273
+ });
1274
+ var ReviewRespondedPayload = defineSchemaModel10({
1275
+ name: "ReviewRespondedEventPayload",
1276
+ fields: {
1277
+ reviewId: { type: ScalarTypeEnum10.String_unsecure(), isOptional: false },
1278
+ responseId: { type: ScalarTypeEnum10.String_unsecure(), isOptional: false },
1279
+ authorId: { type: ScalarTypeEnum10.String_unsecure(), isOptional: false },
1280
+ timestamp: { type: ScalarTypeEnum10.DateTime(), isOptional: false }
1281
+ }
1282
+ });
1283
+ var ReviewCreatedEvent = defineEvent5({
1284
+ meta: {
1285
+ key: "marketplace.review.created",
1286
+ version: "1.0.0",
1287
+ description: "A review has been created.",
1288
+ stability: "experimental",
1289
+ owners: ["@marketplace-team"],
1290
+ tags: ["marketplace", "review"]
1291
+ },
1292
+ payload: ReviewCreatedPayload
1293
+ });
1294
+ var ReviewRespondedEvent = defineEvent5({
1295
+ meta: {
1296
+ key: "marketplace.review.responded",
1297
+ version: "1.0.0",
1298
+ description: "A seller has responded to a review.",
1299
+ stability: "experimental",
1300
+ owners: ["@marketplace-team"],
1301
+ tags: ["marketplace", "review"]
1302
+ },
1303
+ payload: ReviewRespondedPayload
1304
+ });
1305
+ // src/ui/renderers/marketplace.markdown.ts
1306
+ var mockStores = [
1307
+ {
1308
+ id: "store-1",
1309
+ name: "Tech Gadgets Store",
1310
+ status: "ACTIVE",
1311
+ productCount: 45,
1312
+ rating: 4.8
1313
+ },
1314
+ {
1315
+ id: "store-2",
1316
+ name: "Home & Garden",
1317
+ status: "ACTIVE",
1318
+ productCount: 120,
1319
+ rating: 4.5
1320
+ },
1321
+ {
1322
+ id: "store-3",
1323
+ name: "Fashion Boutique",
1324
+ status: "PENDING",
1325
+ productCount: 0,
1326
+ rating: 0
1327
+ }
1328
+ ];
1329
+ var mockProducts = [
1330
+ {
1331
+ id: "prod-1",
1332
+ name: "Wireless Earbuds",
1333
+ storeId: "store-1",
1334
+ price: 79.99,
1335
+ currency: "USD",
1336
+ status: "ACTIVE",
1337
+ stock: 150
1338
+ },
1339
+ {
1340
+ id: "prod-2",
1341
+ name: "Smart Watch",
1342
+ storeId: "store-1",
1343
+ price: 249.99,
1344
+ currency: "USD",
1345
+ status: "ACTIVE",
1346
+ stock: 50
1347
+ },
1348
+ {
1349
+ id: "prod-3",
1350
+ name: "Garden Tools Set",
1351
+ storeId: "store-2",
1352
+ price: 89.99,
1353
+ currency: "USD",
1354
+ status: "ACTIVE",
1355
+ stock: 30
1356
+ },
1357
+ {
1358
+ id: "prod-4",
1359
+ name: "Indoor Plant Kit",
1360
+ storeId: "store-2",
1361
+ price: 45.99,
1362
+ currency: "USD",
1363
+ status: "ACTIVE",
1364
+ stock: 75
1365
+ },
1366
+ {
1367
+ id: "prod-5",
1368
+ name: "LED Desk Lamp",
1369
+ storeId: "store-1",
1370
+ price: 34.99,
1371
+ currency: "USD",
1372
+ status: "OUT_OF_STOCK",
1373
+ stock: 0
1374
+ }
1375
+ ];
1376
+ var mockOrders = [
1377
+ {
1378
+ id: "ord-1",
1379
+ storeId: "store-1",
1380
+ customerId: "cust-1",
1381
+ total: 329.98,
1382
+ currency: "USD",
1383
+ status: "DELIVERED",
1384
+ itemCount: 2,
1385
+ createdAt: "2024-01-15T10:00:00Z"
1386
+ },
1387
+ {
1388
+ id: "ord-2",
1389
+ storeId: "store-2",
1390
+ customerId: "cust-2",
1391
+ total: 135.98,
1392
+ currency: "USD",
1393
+ status: "SHIPPED",
1394
+ itemCount: 2,
1395
+ createdAt: "2024-01-14T14:00:00Z"
1396
+ },
1397
+ {
1398
+ id: "ord-3",
1399
+ storeId: "store-1",
1400
+ customerId: "cust-3",
1401
+ total: 79.99,
1402
+ currency: "USD",
1403
+ status: "PROCESSING",
1404
+ itemCount: 1,
1405
+ createdAt: "2024-01-16T08:00:00Z"
1406
+ },
1407
+ {
1408
+ id: "ord-4",
1409
+ storeId: "store-2",
1410
+ customerId: "cust-4",
1411
+ total: 45.99,
1412
+ currency: "USD",
1413
+ status: "PENDING",
1414
+ itemCount: 1,
1415
+ createdAt: "2024-01-16T12:00:00Z"
1416
+ }
1417
+ ];
1418
+ function formatCurrency(value, currency = "USD") {
1419
+ return new Intl.NumberFormat("en-US", {
1420
+ style: "currency",
1421
+ currency,
1422
+ minimumFractionDigits: 2
1423
+ }).format(value);
1424
+ }
1425
+ var marketplaceDashboardMarkdownRenderer = {
1426
+ target: "markdown",
1427
+ render: async (desc) => {
1428
+ if (desc.source.type !== "component" || desc.source.componentKey !== "MarketplaceDashboard") {
1429
+ throw new Error("marketplaceDashboardMarkdownRenderer: not MarketplaceDashboard");
1430
+ }
1431
+ const stores = mockStores;
1432
+ const products = mockProducts;
1433
+ const orders = mockOrders;
1434
+ const activeStores = stores.filter((s) => s.status === "ACTIVE");
1435
+ const activeProducts = products.filter((p) => p.status === "ACTIVE");
1436
+ const totalRevenue = orders.reduce((sum, o) => sum + o.total, 0);
1437
+ const pendingOrders = orders.filter((o) => o.status === "PENDING" || o.status === "PROCESSING");
1438
+ const lines = [
1439
+ "# Marketplace Dashboard",
1440
+ "",
1441
+ "> Two-sided marketplace overview",
1442
+ "",
1443
+ "## Summary",
1444
+ "",
1445
+ "| Metric | Value |",
1446
+ "|--------|-------|",
1447
+ `| Active Stores | ${activeStores.length} |`,
1448
+ `| Active Products | ${activeProducts.length} |`,
1449
+ `| Total Orders | ${orders.length} |`,
1450
+ `| Total Revenue | ${formatCurrency(totalRevenue)} |`,
1451
+ `| Pending Orders | ${pendingOrders.length} |`,
1452
+ "",
1453
+ "## Top Stores",
1454
+ "",
1455
+ "| Store | Products | Rating | Status |",
1456
+ "|-------|----------|--------|--------|"
1457
+ ];
1458
+ for (const store of stores.slice(0, 5)) {
1459
+ lines.push(`| ${store.name} | ${store.productCount} | \u2B50 ${store.rating || "N/A"} | ${store.status} |`);
1460
+ }
1461
+ lines.push("");
1462
+ lines.push("## Recent Orders");
1463
+ lines.push("");
1464
+ lines.push("| Order | Items | Total | Status | Date |");
1465
+ lines.push("|-------|-------|-------|--------|------|");
1466
+ for (const order of orders.slice(0, 10)) {
1467
+ const date = new Date(order.createdAt).toLocaleDateString();
1468
+ lines.push(`| ${order.id} | ${order.itemCount} | ${formatCurrency(order.total, order.currency)} | ${order.status} | ${date} |`);
1469
+ }
1470
+ return {
1471
+ mimeType: "text/markdown",
1472
+ body: lines.join(`
1473
+ `)
1474
+ };
1475
+ }
1476
+ };
1477
+ var productCatalogMarkdownRenderer = {
1478
+ target: "markdown",
1479
+ render: async (desc) => {
1480
+ if (desc.source.type !== "component" || desc.source.componentKey !== "ProductCatalog") {
1481
+ throw new Error("productCatalogMarkdownRenderer: not ProductCatalog");
1482
+ }
1483
+ const products = mockProducts;
1484
+ const stores = mockStores;
1485
+ const lines = [
1486
+ "# Product Catalog",
1487
+ "",
1488
+ "> Browse products across all marketplace stores",
1489
+ ""
1490
+ ];
1491
+ for (const store of stores.filter((s) => s.status === "ACTIVE")) {
1492
+ const storeProducts = products.filter((p) => p.storeId === store.id);
1493
+ if (storeProducts.length === 0)
1494
+ continue;
1495
+ lines.push(`## ${store.name}`);
1496
+ lines.push("");
1497
+ lines.push("| Product | Price | Stock | Status |");
1498
+ lines.push("|---------|-------|-------|--------|");
1499
+ for (const product of storeProducts) {
1500
+ const stockStatus = product.stock > 0 ? `${product.stock} in stock` : "Out of stock";
1501
+ lines.push(`| ${product.name} | ${formatCurrency(product.price, product.currency)} | ${stockStatus} | ${product.status} |`);
1502
+ }
1503
+ lines.push("");
1504
+ }
1505
+ return {
1506
+ mimeType: "text/markdown",
1507
+ body: lines.join(`
1508
+ `)
1509
+ };
1510
+ }
1511
+ };
1512
+ var orderListMarkdownRenderer = {
1513
+ target: "markdown",
1514
+ render: async (desc) => {
1515
+ if (desc.source.type !== "component" || desc.source.componentKey !== "OrderList") {
1516
+ throw new Error("orderListMarkdownRenderer: not OrderList");
1517
+ }
1518
+ const orders = mockOrders;
1519
+ const stores = mockStores;
1520
+ const lines = [
1521
+ "# Orders",
1522
+ "",
1523
+ "> Manage marketplace orders",
1524
+ "",
1525
+ "| Order ID | Store | Items | Total | Status | Created |",
1526
+ "|----------|-------|-------|-------|--------|---------|"
1527
+ ];
1528
+ for (const order of orders) {
1529
+ const store = stores.find((s) => s.id === order.storeId);
1530
+ const date = new Date(order.createdAt).toLocaleDateString();
1531
+ lines.push(`| ${order.id} | ${store?.name ?? "Unknown"} | ${order.itemCount} | ${formatCurrency(order.total, order.currency)} | ${order.status} | ${date} |`);
1532
+ }
1533
+ lines.push("");
1534
+ lines.push("## Order Status Legend");
1535
+ lines.push("");
1536
+ lines.push("- **PENDING**: Awaiting payment confirmation");
1537
+ lines.push("- **PROCESSING**: Being prepared");
1538
+ lines.push("- **SHIPPED**: In transit");
1539
+ lines.push("- **DELIVERED**: Order completed");
1540
+ lines.push("- **CANCELLED**: Order cancelled");
1541
+ return {
1542
+ mimeType: "text/markdown",
1543
+ body: lines.join(`
1544
+ `)
1545
+ };
1546
+ }
1547
+ };
1548
+ // src/ui/hooks/useMarketplaceData.ts
1549
+ import { useCallback, useEffect, useState } from "react";
1550
+ import { useTemplateRuntime } from "@contractspec/lib.example-shared-ui";
1551
+ "use client";
1552
+ function useMarketplaceData(projectId = "local-project") {
1553
+ const { handlers } = useTemplateRuntime();
1554
+ const marketplace = handlers.marketplace;
1555
+ const [stores, setStores] = useState([]);
1556
+ const [products, setProducts] = useState([]);
1557
+ const [orders, setOrders] = useState([]);
1558
+ const [loading, setLoading] = useState(true);
1559
+ const [error, setError] = useState(null);
1560
+ const [totalRevenue, setTotalRevenue] = useState(0);
1561
+ const fetchData = useCallback(async () => {
1562
+ try {
1563
+ setLoading(true);
1564
+ setError(null);
1565
+ const [storeResult, productResult, orderResult] = await Promise.all([
1566
+ marketplace.listStores({ projectId, limit: 100 }),
1567
+ marketplace.listProducts({ limit: 100 }),
1568
+ marketplace.listOrders({ projectId, limit: 100 })
1569
+ ]);
1570
+ setStores(storeResult.stores);
1571
+ setProducts(productResult.products);
1572
+ setOrders(orderResult.orders);
1573
+ setTotalRevenue(orderResult.totalRevenue);
1574
+ } catch (err) {
1575
+ setError(err instanceof Error ? err : new Error("Failed to load marketplace"));
1576
+ } finally {
1577
+ setLoading(false);
1578
+ }
1579
+ }, [marketplace, projectId]);
1580
+ useEffect(() => {
1581
+ fetchData();
1582
+ }, [fetchData]);
1583
+ const stats = {
1584
+ totalStores: stores.length,
1585
+ activeStores: stores.filter((s) => s.status === "ACTIVE").length,
1586
+ totalProducts: products.length,
1587
+ totalOrders: orders.length,
1588
+ totalRevenue,
1589
+ pendingOrders: orders.filter((o) => o.status === "PENDING").length
1590
+ };
1591
+ return {
1592
+ stores,
1593
+ products,
1594
+ orders,
1595
+ loading,
1596
+ error,
1597
+ stats,
1598
+ refetch: fetchData
1599
+ };
1600
+ }
1601
+
1602
+ // src/ui/MarketplaceDashboard.tsx
1603
+ import { useState as useState2 } from "react";
1604
+ import {
1605
+ Button,
1606
+ ErrorState,
1607
+ LoaderBlock,
1608
+ StatCard,
1609
+ StatCardGroup
1610
+ } from "@contractspec/lib.design-system";
1611
+ import { jsxDEV } from "react/jsx-dev-runtime";
1612
+ "use client";
1613
+ var STATUS_COLORS = {
1614
+ ACTIVE: "bg-green-100 text-green-700 dark:bg-green-900/30 dark:text-green-400",
1615
+ PENDING: "bg-yellow-100 text-yellow-700 dark:bg-yellow-900/30 dark:text-yellow-400",
1616
+ SUSPENDED: "bg-red-100 text-red-700 dark:bg-red-900/30 dark:text-red-400",
1617
+ DRAFT: "bg-gray-100 text-gray-700 dark:bg-gray-900/30 dark:text-gray-400",
1618
+ OUT_OF_STOCK: "bg-orange-100 text-orange-700 dark:bg-orange-900/30 dark:text-orange-400",
1619
+ ARCHIVED: "bg-gray-100 text-gray-700 dark:bg-gray-900/30 dark:text-gray-400",
1620
+ CONFIRMED: "bg-blue-100 text-blue-700 dark:bg-blue-900/30 dark:text-blue-400",
1621
+ PROCESSING: "bg-indigo-100 text-indigo-700 dark:bg-indigo-900/30 dark:text-indigo-400",
1622
+ SHIPPED: "bg-purple-100 text-purple-700 dark:bg-purple-900/30 dark:text-purple-400",
1623
+ DELIVERED: "bg-green-100 text-green-700 dark:bg-green-900/30 dark:text-green-400",
1624
+ CANCELLED: "bg-red-100 text-red-700 dark:bg-red-900/30 dark:text-red-400"
1625
+ };
1626
+ function formatCurrency2(value, currency = "USD") {
1627
+ return new Intl.NumberFormat("en-US", {
1628
+ style: "currency",
1629
+ currency,
1630
+ minimumFractionDigits: 0,
1631
+ maximumFractionDigits: 2
1632
+ }).format(value);
1633
+ }
1634
+ function MarketplaceDashboard() {
1635
+ const [activeTab, setActiveTab] = useState2("stores");
1636
+ const { stores, products, orders, loading, error, stats, refetch } = useMarketplaceData();
1637
+ const tabs = [
1638
+ { id: "stores", label: "Stores", icon: "\uD83C\uDFEA" },
1639
+ { id: "products", label: "Products", icon: "\uD83D\uDCE6" },
1640
+ { id: "orders", label: "Orders", icon: "\uD83D\uDED2" }
1641
+ ];
1642
+ if (loading) {
1643
+ return /* @__PURE__ */ jsxDEV(LoaderBlock, {
1644
+ label: "Loading Marketplace..."
1645
+ }, undefined, false, undefined, this);
1646
+ }
1647
+ if (error) {
1648
+ return /* @__PURE__ */ jsxDEV(ErrorState, {
1649
+ title: "Failed to load Marketplace",
1650
+ description: error.message,
1651
+ onRetry: refetch,
1652
+ retryLabel: "Retry"
1653
+ }, undefined, false, undefined, this);
1654
+ }
1655
+ return /* @__PURE__ */ jsxDEV("div", {
1656
+ className: "space-y-6",
1657
+ children: [
1658
+ /* @__PURE__ */ jsxDEV("div", {
1659
+ className: "flex items-center justify-between",
1660
+ children: [
1661
+ /* @__PURE__ */ jsxDEV("h2", {
1662
+ className: "text-2xl font-bold",
1663
+ children: "Marketplace"
1664
+ }, undefined, false, undefined, this),
1665
+ /* @__PURE__ */ jsxDEV(Button, {
1666
+ onClick: () => alert("Create store modal"),
1667
+ children: [
1668
+ /* @__PURE__ */ jsxDEV("span", {
1669
+ className: "mr-2",
1670
+ children: "+"
1671
+ }, undefined, false, undefined, this),
1672
+ " New Store"
1673
+ ]
1674
+ }, undefined, true, undefined, this)
1675
+ ]
1676
+ }, undefined, true, undefined, this),
1677
+ /* @__PURE__ */ jsxDEV(StatCardGroup, {
1678
+ children: [
1679
+ /* @__PURE__ */ jsxDEV(StatCard, {
1680
+ label: "Stores",
1681
+ value: stats.totalStores,
1682
+ hint: `${stats.activeStores} active`
1683
+ }, undefined, false, undefined, this),
1684
+ /* @__PURE__ */ jsxDEV(StatCard, {
1685
+ label: "Products",
1686
+ value: stats.totalProducts,
1687
+ hint: "listed"
1688
+ }, undefined, false, undefined, this),
1689
+ /* @__PURE__ */ jsxDEV(StatCard, {
1690
+ label: "Orders",
1691
+ value: stats.totalOrders,
1692
+ hint: `${stats.pendingOrders} pending`
1693
+ }, undefined, false, undefined, this),
1694
+ /* @__PURE__ */ jsxDEV(StatCard, {
1695
+ label: "Revenue",
1696
+ value: formatCurrency2(stats.totalRevenue),
1697
+ hint: "total"
1698
+ }, undefined, false, undefined, this)
1699
+ ]
1700
+ }, undefined, true, undefined, this),
1701
+ /* @__PURE__ */ jsxDEV("nav", {
1702
+ className: "bg-muted flex gap-1 rounded-lg p-1",
1703
+ role: "tablist",
1704
+ children: tabs.map((tab) => /* @__PURE__ */ jsxDEV(Button, {
1705
+ type: "button",
1706
+ role: "tab",
1707
+ "aria-selected": activeTab === tab.id,
1708
+ onClick: () => setActiveTab(tab.id),
1709
+ className: `flex flex-1 items-center justify-center gap-2 rounded-md px-4 py-2 text-sm font-medium transition-colors ${activeTab === tab.id ? "bg-background text-foreground shadow-sm" : "text-muted-foreground hover:text-foreground"}`,
1710
+ children: [
1711
+ /* @__PURE__ */ jsxDEV("span", {
1712
+ children: tab.icon
1713
+ }, undefined, false, undefined, this),
1714
+ tab.label
1715
+ ]
1716
+ }, tab.id, true, undefined, this))
1717
+ }, undefined, false, undefined, this),
1718
+ /* @__PURE__ */ jsxDEV("div", {
1719
+ className: "min-h-[400px]",
1720
+ role: "tabpanel",
1721
+ children: [
1722
+ activeTab === "stores" && /* @__PURE__ */ jsxDEV("div", {
1723
+ className: "border-border rounded-lg border",
1724
+ children: /* @__PURE__ */ jsxDEV("table", {
1725
+ className: "w-full",
1726
+ children: [
1727
+ /* @__PURE__ */ jsxDEV("thead", {
1728
+ className: "border-border bg-muted/30 border-b",
1729
+ children: /* @__PURE__ */ jsxDEV("tr", {
1730
+ children: [
1731
+ /* @__PURE__ */ jsxDEV("th", {
1732
+ className: "px-4 py-3 text-left text-sm font-medium",
1733
+ children: "Store"
1734
+ }, undefined, false, undefined, this),
1735
+ /* @__PURE__ */ jsxDEV("th", {
1736
+ className: "px-4 py-3 text-left text-sm font-medium",
1737
+ children: "Status"
1738
+ }, undefined, false, undefined, this),
1739
+ /* @__PURE__ */ jsxDEV("th", {
1740
+ className: "px-4 py-3 text-left text-sm font-medium",
1741
+ children: "Rating"
1742
+ }, undefined, false, undefined, this),
1743
+ /* @__PURE__ */ jsxDEV("th", {
1744
+ className: "px-4 py-3 text-left text-sm font-medium",
1745
+ children: "Reviews"
1746
+ }, undefined, false, undefined, this)
1747
+ ]
1748
+ }, undefined, true, undefined, this)
1749
+ }, undefined, false, undefined, this),
1750
+ /* @__PURE__ */ jsxDEV("tbody", {
1751
+ className: "divide-border divide-y",
1752
+ children: [
1753
+ stores.map((store) => /* @__PURE__ */ jsxDEV("tr", {
1754
+ className: "hover:bg-muted/50",
1755
+ children: [
1756
+ /* @__PURE__ */ jsxDEV("td", {
1757
+ className: "px-4 py-3",
1758
+ children: [
1759
+ /* @__PURE__ */ jsxDEV("div", {
1760
+ className: "font-medium",
1761
+ children: store.name
1762
+ }, undefined, false, undefined, this),
1763
+ /* @__PURE__ */ jsxDEV("div", {
1764
+ className: "text-muted-foreground text-sm",
1765
+ children: store.description
1766
+ }, undefined, false, undefined, this)
1767
+ ]
1768
+ }, undefined, true, undefined, this),
1769
+ /* @__PURE__ */ jsxDEV("td", {
1770
+ className: "px-4 py-3",
1771
+ children: /* @__PURE__ */ jsxDEV("span", {
1772
+ className: `inline-flex rounded-full px-2 py-0.5 text-xs font-medium ${STATUS_COLORS[store.status] ?? ""}`,
1773
+ children: store.status
1774
+ }, undefined, false, undefined, this)
1775
+ }, undefined, false, undefined, this),
1776
+ /* @__PURE__ */ jsxDEV("td", {
1777
+ className: "px-4 py-3",
1778
+ children: /* @__PURE__ */ jsxDEV("span", {
1779
+ className: "flex items-center gap-1",
1780
+ children: [
1781
+ "\u2B50 ",
1782
+ store.rating.toFixed(1)
1783
+ ]
1784
+ }, undefined, true, undefined, this)
1785
+ }, undefined, false, undefined, this),
1786
+ /* @__PURE__ */ jsxDEV("td", {
1787
+ className: "text-muted-foreground px-4 py-3 text-sm",
1788
+ children: [
1789
+ store.reviewCount,
1790
+ " reviews"
1791
+ ]
1792
+ }, undefined, true, undefined, this)
1793
+ ]
1794
+ }, store.id, true, undefined, this)),
1795
+ stores.length === 0 && /* @__PURE__ */ jsxDEV("tr", {
1796
+ children: /* @__PURE__ */ jsxDEV("td", {
1797
+ colSpan: 4,
1798
+ className: "text-muted-foreground px-4 py-8 text-center",
1799
+ children: "No stores found"
1800
+ }, undefined, false, undefined, this)
1801
+ }, undefined, false, undefined, this)
1802
+ ]
1803
+ }, undefined, true, undefined, this)
1804
+ ]
1805
+ }, undefined, true, undefined, this)
1806
+ }, undefined, false, undefined, this),
1807
+ activeTab === "products" && /* @__PURE__ */ jsxDEV("div", {
1808
+ className: "border-border rounded-lg border",
1809
+ children: /* @__PURE__ */ jsxDEV("table", {
1810
+ className: "w-full",
1811
+ children: [
1812
+ /* @__PURE__ */ jsxDEV("thead", {
1813
+ className: "border-border bg-muted/30 border-b",
1814
+ children: /* @__PURE__ */ jsxDEV("tr", {
1815
+ children: [
1816
+ /* @__PURE__ */ jsxDEV("th", {
1817
+ className: "px-4 py-3 text-left text-sm font-medium",
1818
+ children: "Product"
1819
+ }, undefined, false, undefined, this),
1820
+ /* @__PURE__ */ jsxDEV("th", {
1821
+ className: "px-4 py-3 text-left text-sm font-medium",
1822
+ children: "Price"
1823
+ }, undefined, false, undefined, this),
1824
+ /* @__PURE__ */ jsxDEV("th", {
1825
+ className: "px-4 py-3 text-left text-sm font-medium",
1826
+ children: "Stock"
1827
+ }, undefined, false, undefined, this),
1828
+ /* @__PURE__ */ jsxDEV("th", {
1829
+ className: "px-4 py-3 text-left text-sm font-medium",
1830
+ children: "Status"
1831
+ }, undefined, false, undefined, this)
1832
+ ]
1833
+ }, undefined, true, undefined, this)
1834
+ }, undefined, false, undefined, this),
1835
+ /* @__PURE__ */ jsxDEV("tbody", {
1836
+ className: "divide-border divide-y",
1837
+ children: [
1838
+ products.map((product) => /* @__PURE__ */ jsxDEV("tr", {
1839
+ className: "hover:bg-muted/50",
1840
+ children: [
1841
+ /* @__PURE__ */ jsxDEV("td", {
1842
+ className: "px-4 py-3",
1843
+ children: [
1844
+ /* @__PURE__ */ jsxDEV("div", {
1845
+ className: "font-medium",
1846
+ children: product.name
1847
+ }, undefined, false, undefined, this),
1848
+ /* @__PURE__ */ jsxDEV("div", {
1849
+ className: "text-muted-foreground text-sm",
1850
+ children: product.category
1851
+ }, undefined, false, undefined, this)
1852
+ ]
1853
+ }, undefined, true, undefined, this),
1854
+ /* @__PURE__ */ jsxDEV("td", {
1855
+ className: "px-4 py-3 font-mono",
1856
+ children: formatCurrency2(product.price, product.currency)
1857
+ }, undefined, false, undefined, this),
1858
+ /* @__PURE__ */ jsxDEV("td", {
1859
+ className: "px-4 py-3",
1860
+ children: product.stock
1861
+ }, undefined, false, undefined, this),
1862
+ /* @__PURE__ */ jsxDEV("td", {
1863
+ className: "px-4 py-3",
1864
+ children: /* @__PURE__ */ jsxDEV("span", {
1865
+ className: `inline-flex rounded-full px-2 py-0.5 text-xs font-medium ${STATUS_COLORS[product.status] ?? ""}`,
1866
+ children: product.status
1867
+ }, undefined, false, undefined, this)
1868
+ }, undefined, false, undefined, this)
1869
+ ]
1870
+ }, product.id, true, undefined, this)),
1871
+ products.length === 0 && /* @__PURE__ */ jsxDEV("tr", {
1872
+ children: /* @__PURE__ */ jsxDEV("td", {
1873
+ colSpan: 4,
1874
+ className: "text-muted-foreground px-4 py-8 text-center",
1875
+ children: "No products found"
1876
+ }, undefined, false, undefined, this)
1877
+ }, undefined, false, undefined, this)
1878
+ ]
1879
+ }, undefined, true, undefined, this)
1880
+ ]
1881
+ }, undefined, true, undefined, this)
1882
+ }, undefined, false, undefined, this),
1883
+ activeTab === "orders" && /* @__PURE__ */ jsxDEV("div", {
1884
+ className: "border-border rounded-lg border",
1885
+ children: /* @__PURE__ */ jsxDEV("table", {
1886
+ className: "w-full",
1887
+ children: [
1888
+ /* @__PURE__ */ jsxDEV("thead", {
1889
+ className: "border-border bg-muted/30 border-b",
1890
+ children: /* @__PURE__ */ jsxDEV("tr", {
1891
+ children: [
1892
+ /* @__PURE__ */ jsxDEV("th", {
1893
+ className: "px-4 py-3 text-left text-sm font-medium",
1894
+ children: "Order ID"
1895
+ }, undefined, false, undefined, this),
1896
+ /* @__PURE__ */ jsxDEV("th", {
1897
+ className: "px-4 py-3 text-left text-sm font-medium",
1898
+ children: "Customer"
1899
+ }, undefined, false, undefined, this),
1900
+ /* @__PURE__ */ jsxDEV("th", {
1901
+ className: "px-4 py-3 text-left text-sm font-medium",
1902
+ children: "Total"
1903
+ }, undefined, false, undefined, this),
1904
+ /* @__PURE__ */ jsxDEV("th", {
1905
+ className: "px-4 py-3 text-left text-sm font-medium",
1906
+ children: "Status"
1907
+ }, undefined, false, undefined, this),
1908
+ /* @__PURE__ */ jsxDEV("th", {
1909
+ className: "px-4 py-3 text-left text-sm font-medium",
1910
+ children: "Date"
1911
+ }, undefined, false, undefined, this)
1912
+ ]
1913
+ }, undefined, true, undefined, this)
1914
+ }, undefined, false, undefined, this),
1915
+ /* @__PURE__ */ jsxDEV("tbody", {
1916
+ className: "divide-border divide-y",
1917
+ children: [
1918
+ orders.map((order) => /* @__PURE__ */ jsxDEV("tr", {
1919
+ className: "hover:bg-muted/50",
1920
+ children: [
1921
+ /* @__PURE__ */ jsxDEV("td", {
1922
+ className: "px-4 py-3 font-mono text-sm",
1923
+ children: order.id
1924
+ }, undefined, false, undefined, this),
1925
+ /* @__PURE__ */ jsxDEV("td", {
1926
+ className: "px-4 py-3 text-sm",
1927
+ children: order.customerId
1928
+ }, undefined, false, undefined, this),
1929
+ /* @__PURE__ */ jsxDEV("td", {
1930
+ className: "px-4 py-3 font-mono",
1931
+ children: formatCurrency2(order.total, order.currency)
1932
+ }, undefined, false, undefined, this),
1933
+ /* @__PURE__ */ jsxDEV("td", {
1934
+ className: "px-4 py-3",
1935
+ children: /* @__PURE__ */ jsxDEV("span", {
1936
+ className: `inline-flex rounded-full px-2 py-0.5 text-xs font-medium ${STATUS_COLORS[order.status] ?? ""}`,
1937
+ children: order.status
1938
+ }, undefined, false, undefined, this)
1939
+ }, undefined, false, undefined, this),
1940
+ /* @__PURE__ */ jsxDEV("td", {
1941
+ className: "text-muted-foreground px-4 py-3 text-sm",
1942
+ children: order.createdAt.toLocaleDateString()
1943
+ }, undefined, false, undefined, this)
1944
+ ]
1945
+ }, order.id, true, undefined, this)),
1946
+ orders.length === 0 && /* @__PURE__ */ jsxDEV("tr", {
1947
+ children: /* @__PURE__ */ jsxDEV("td", {
1948
+ colSpan: 5,
1949
+ className: "text-muted-foreground px-4 py-8 text-center",
1950
+ children: "No orders found"
1951
+ }, undefined, false, undefined, this)
1952
+ }, undefined, false, undefined, this)
1953
+ ]
1954
+ }, undefined, true, undefined, this)
1955
+ ]
1956
+ }, undefined, true, undefined, this)
1957
+ }, undefined, false, undefined, this)
1958
+ ]
1959
+ }, undefined, true, undefined, this)
1960
+ ]
1961
+ }, undefined, true, undefined, this);
1962
+ }
1963
+
1964
+ // src/ui/hooks/index.ts
1965
+ "use client";
1966
+ export {
1967
+ useMarketplaceData,
1968
+ productCatalogMarkdownRenderer,
1969
+ orderListMarkdownRenderer,
1970
+ marketplaceDashboardMarkdownRenderer,
1971
+ createMarketplaceHandlers,
1972
+ UpdateOrderStatusInputModel,
1973
+ UpdateOrderStatusContract,
1974
+ StoreStatusEnum,
1975
+ StoreStatusChangedEvent,
1976
+ StoreModel,
1977
+ StoreCreatedEvent,
1978
+ ReviewStatusEnum,
1979
+ ReviewRespondedEvent,
1980
+ ReviewModel,
1981
+ ReviewCreatedEvent,
1982
+ ProductStatusEnum,
1983
+ ProductPublishedEvent,
1984
+ ProductModel,
1985
+ ProductCreatedEvent,
1986
+ PayoutStatusEnum,
1987
+ PayoutPaidEvent,
1988
+ PayoutModel,
1989
+ PayoutCreatedEvent,
1990
+ OrderStatusUpdatedEvent,
1991
+ OrderStatusEnum,
1992
+ OrderShippedEvent,
1993
+ OrderPaidEvent,
1994
+ OrderModel,
1995
+ OrderItemModel,
1996
+ OrderCreatedEvent,
1997
+ OrderCompletedEvent,
1998
+ MarketplaceDashboard,
1999
+ ListReviewsOutputModel,
2000
+ ListReviewsInputModel,
2001
+ ListReviewsContract,
2002
+ ListProductsOutputModel,
2003
+ ListProductsInputModel,
2004
+ ListProductsContract,
2005
+ ListPayoutsOutputModel,
2006
+ ListPayoutsInputModel,
2007
+ ListPayoutsContract,
2008
+ InventoryUpdatedEvent,
2009
+ CreateStoreInputModel,
2010
+ CreateStoreContract,
2011
+ CreateReviewInputModel,
2012
+ CreateReviewContract,
2013
+ CreateProductInputModel,
2014
+ CreateProductContract,
2015
+ CreateOrderInputModel,
2016
+ CreateOrderContract
2017
+ };