@contractspec/example.marketplace 1.56.1 → 1.58.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 +40 -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 -138
  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 -7
  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 -15
  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 +529 -110
  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
@@ -0,0 +1,167 @@
1
+ // src/entities/order.ts
2
+ import {
3
+ defineEntity,
4
+ defineEntityEnum,
5
+ field,
6
+ index
7
+ } from "@contractspec/lib.schema";
8
+ var OrderStatusEnum = defineEntityEnum({
9
+ name: "OrderStatus",
10
+ values: [
11
+ "PENDING",
12
+ "PAID",
13
+ "PROCESSING",
14
+ "SHIPPED",
15
+ "DELIVERED",
16
+ "COMPLETED",
17
+ "CANCELLED",
18
+ "REFUNDED",
19
+ "PARTIALLY_REFUNDED",
20
+ "DISPUTED"
21
+ ],
22
+ schema: "marketplace",
23
+ description: "Status of an order."
24
+ });
25
+ var PaymentStatusEnum = defineEntityEnum({
26
+ name: "PaymentStatus",
27
+ values: [
28
+ "PENDING",
29
+ "AUTHORIZED",
30
+ "CAPTURED",
31
+ "FAILED",
32
+ "REFUNDED",
33
+ "VOIDED"
34
+ ],
35
+ schema: "marketplace",
36
+ description: "Status of payment."
37
+ });
38
+ var OrderEntity = defineEntity({
39
+ name: "Order",
40
+ description: "A purchase order on the marketplace.",
41
+ schema: "marketplace",
42
+ map: "order",
43
+ fields: {
44
+ id: field.id({ description: "Unique order ID" }),
45
+ orderNumber: field.string({ description: "Human-readable order number" }),
46
+ buyerId: field.foreignKey({ description: "Buyer user ID" }),
47
+ storeId: field.foreignKey({ description: "Seller store ID" }),
48
+ status: field.enum("OrderStatus", { default: "PENDING" }),
49
+ paymentStatus: field.enum("PaymentStatus", { default: "PENDING" }),
50
+ subtotal: field.decimal({ description: "Sum of item prices" }),
51
+ shippingTotal: field.decimal({ default: 0 }),
52
+ taxTotal: field.decimal({ default: 0 }),
53
+ discountTotal: field.decimal({ default: 0 }),
54
+ total: field.decimal({ description: "Final total" }),
55
+ currency: field.string({ default: '"USD"' }),
56
+ platformFee: field.decimal({ description: "Platform commission amount" }),
57
+ sellerPayout: field.decimal({ description: "Amount due to seller" }),
58
+ shippingAddress: field.json({ isOptional: true }),
59
+ billingAddress: field.json({ isOptional: true }),
60
+ shippingMethod: field.string({ isOptional: true }),
61
+ trackingNumber: field.string({ isOptional: true }),
62
+ trackingUrl: field.string({ isOptional: true }),
63
+ paymentMethod: field.string({ isOptional: true }),
64
+ paymentIntentId: field.string({ isOptional: true }),
65
+ buyerNote: field.string({ isOptional: true }),
66
+ sellerNote: field.string({ isOptional: true }),
67
+ internalNote: field.string({ isOptional: true }),
68
+ createdAt: field.createdAt(),
69
+ updatedAt: field.updatedAt(),
70
+ paidAt: field.dateTime({ isOptional: true }),
71
+ shippedAt: field.dateTime({ isOptional: true }),
72
+ deliveredAt: field.dateTime({ isOptional: true }),
73
+ completedAt: field.dateTime({ isOptional: true }),
74
+ cancelledAt: field.dateTime({ isOptional: true }),
75
+ store: field.belongsTo("Store", ["storeId"], ["id"]),
76
+ items: field.hasMany("OrderItem"),
77
+ refunds: field.hasMany("Refund")
78
+ },
79
+ indexes: [
80
+ index.unique(["orderNumber"]),
81
+ index.on(["buyerId", "status"]),
82
+ index.on(["storeId", "status"]),
83
+ index.on(["status", "createdAt"]),
84
+ index.on(["paymentStatus"]),
85
+ index.on(["createdAt"])
86
+ ],
87
+ enums: [OrderStatusEnum, PaymentStatusEnum]
88
+ });
89
+ var OrderItemEntity = defineEntity({
90
+ name: "OrderItem",
91
+ description: "An item within an order.",
92
+ schema: "marketplace",
93
+ map: "order_item",
94
+ fields: {
95
+ id: field.id(),
96
+ orderId: field.foreignKey(),
97
+ productId: field.foreignKey(),
98
+ variantId: field.string({ isOptional: true }),
99
+ productName: field.string(),
100
+ variantName: field.string({ isOptional: true }),
101
+ sku: field.string({ isOptional: true }),
102
+ unitPrice: field.decimal(),
103
+ quantity: field.int(),
104
+ subtotal: field.decimal(),
105
+ quantityFulfilled: field.int({ default: 0 }),
106
+ quantityRefunded: field.int({ default: 0 }),
107
+ createdAt: field.createdAt(),
108
+ updatedAt: field.updatedAt(),
109
+ order: field.belongsTo("Order", ["orderId"], ["id"], {
110
+ onDelete: "Cascade"
111
+ }),
112
+ product: field.belongsTo("Product", ["productId"], ["id"])
113
+ },
114
+ indexes: [index.on(["orderId"]), index.on(["productId"])]
115
+ });
116
+ var RefundEntity = defineEntity({
117
+ name: "Refund",
118
+ description: "A refund for an order.",
119
+ schema: "marketplace",
120
+ map: "refund",
121
+ fields: {
122
+ id: field.id(),
123
+ orderId: field.foreignKey(),
124
+ amount: field.decimal(),
125
+ currency: field.string(),
126
+ reason: field.string(),
127
+ notes: field.string({ isOptional: true }),
128
+ status: field.string({ default: '"PENDING"' }),
129
+ refundId: field.string({
130
+ isOptional: true,
131
+ description: "Payment provider refund ID"
132
+ }),
133
+ issuedBy: field.foreignKey({ description: "User who issued the refund" }),
134
+ createdAt: field.createdAt(),
135
+ processedAt: field.dateTime({ isOptional: true }),
136
+ order: field.belongsTo("Order", ["orderId"], ["id"]),
137
+ items: field.hasMany("RefundItem")
138
+ },
139
+ indexes: [index.on(["orderId"]), index.on(["status"])]
140
+ });
141
+ var RefundItemEntity = defineEntity({
142
+ name: "RefundItem",
143
+ description: "An item within a refund.",
144
+ schema: "marketplace",
145
+ map: "refund_item",
146
+ fields: {
147
+ id: field.id(),
148
+ refundId: field.foreignKey(),
149
+ orderItemId: field.foreignKey(),
150
+ quantity: field.int(),
151
+ amount: field.decimal(),
152
+ createdAt: field.createdAt(),
153
+ refund: field.belongsTo("Refund", ["refundId"], ["id"], {
154
+ onDelete: "Cascade"
155
+ }),
156
+ orderItem: field.belongsTo("OrderItem", ["orderItemId"], ["id"])
157
+ },
158
+ indexes: [index.on(["refundId"]), index.on(["orderItemId"])]
159
+ });
160
+ export {
161
+ RefundItemEntity,
162
+ RefundEntity,
163
+ PaymentStatusEnum,
164
+ OrderStatusEnum,
165
+ OrderItemEntity,
166
+ OrderEntity
167
+ };
@@ -0,0 +1,142 @@
1
+ // src/entities/payout.ts
2
+ import {
3
+ defineEntity,
4
+ defineEntityEnum,
5
+ field,
6
+ index
7
+ } from "@contractspec/lib.schema";
8
+ var PayoutStatusEnum = defineEntityEnum({
9
+ name: "PayoutStatus",
10
+ values: ["PENDING", "PROCESSING", "PAID", "FAILED", "CANCELLED"],
11
+ schema: "marketplace",
12
+ description: "Status of a payout."
13
+ });
14
+ var PayoutScheduleEnum = defineEntityEnum({
15
+ name: "PayoutSchedule",
16
+ values: ["DAILY", "WEEKLY", "BIWEEKLY", "MONTHLY", "MANUAL"],
17
+ schema: "marketplace",
18
+ description: "Payout schedule frequency."
19
+ });
20
+ var PayoutEntity = defineEntity({
21
+ name: "Payout",
22
+ description: "A payout to a seller.",
23
+ schema: "marketplace",
24
+ map: "payout",
25
+ fields: {
26
+ id: field.id({ description: "Unique payout ID" }),
27
+ storeId: field.foreignKey(),
28
+ payoutNumber: field.string({ description: "Human-readable payout number" }),
29
+ status: field.enum("PayoutStatus", { default: "PENDING" }),
30
+ grossAmount: field.decimal({ description: "Total before fees" }),
31
+ platformFees: field.decimal({ description: "Platform fees deducted" }),
32
+ otherDeductions: field.decimal({ default: 0 }),
33
+ netAmount: field.decimal({ description: "Final payout amount" }),
34
+ currency: field.string({ default: '"USD"' }),
35
+ periodStart: field.dateTime({ description: "Start of payout period" }),
36
+ periodEnd: field.dateTime({ description: "End of payout period" }),
37
+ paymentMethod: field.string({ isOptional: true }),
38
+ paymentReference: field.string({ isOptional: true }),
39
+ bankAccountId: field.string({ isOptional: true }),
40
+ bankAccountLast4: field.string({ isOptional: true }),
41
+ notes: field.string({ isOptional: true }),
42
+ failureReason: field.string({ isOptional: true }),
43
+ orderCount: field.int({ default: 0 }),
44
+ createdAt: field.createdAt(),
45
+ updatedAt: field.updatedAt(),
46
+ scheduledAt: field.dateTime({ isOptional: true }),
47
+ processedAt: field.dateTime({ isOptional: true }),
48
+ paidAt: field.dateTime({ isOptional: true }),
49
+ store: field.belongsTo("Store", ["storeId"], ["id"]),
50
+ items: field.hasMany("PayoutItem")
51
+ },
52
+ indexes: [
53
+ index.unique(["payoutNumber"]),
54
+ index.on(["storeId", "status"]),
55
+ index.on(["status", "scheduledAt"]),
56
+ index.on(["periodStart", "periodEnd"])
57
+ ],
58
+ enums: [PayoutStatusEnum]
59
+ });
60
+ var PayoutItemEntity = defineEntity({
61
+ name: "PayoutItem",
62
+ description: "An order included in a payout.",
63
+ schema: "marketplace",
64
+ map: "payout_item",
65
+ fields: {
66
+ id: field.id(),
67
+ payoutId: field.foreignKey(),
68
+ orderId: field.foreignKey(),
69
+ orderTotal: field.decimal(),
70
+ platformFee: field.decimal(),
71
+ netAmount: field.decimal(),
72
+ createdAt: field.createdAt(),
73
+ payout: field.belongsTo("Payout", ["payoutId"], ["id"], {
74
+ onDelete: "Cascade"
75
+ }),
76
+ order: field.belongsTo("Order", ["orderId"], ["id"])
77
+ },
78
+ indexes: [index.on(["payoutId"]), index.on(["orderId"])]
79
+ });
80
+ var BankAccountEntity = defineEntity({
81
+ name: "BankAccount",
82
+ description: "A bank account for receiving payouts.",
83
+ schema: "marketplace",
84
+ map: "bank_account",
85
+ fields: {
86
+ id: field.id(),
87
+ storeId: field.foreignKey(),
88
+ accountHolderName: field.string(),
89
+ accountType: field.string({ default: '"CHECKING"' }),
90
+ bankName: field.string({ isOptional: true }),
91
+ last4: field.string({ description: "Last 4 digits of account" }),
92
+ routingLast4: field.string({ isOptional: true }),
93
+ externalId: field.string({
94
+ isOptional: true,
95
+ description: "External provider account ID"
96
+ }),
97
+ isDefault: field.boolean({ default: false }),
98
+ isVerified: field.boolean({ default: false }),
99
+ createdAt: field.createdAt(),
100
+ updatedAt: field.updatedAt(),
101
+ verifiedAt: field.dateTime({ isOptional: true }),
102
+ store: field.belongsTo("Store", ["storeId"], ["id"])
103
+ },
104
+ indexes: [index.on(["storeId", "isDefault"]), index.on(["externalId"])]
105
+ });
106
+ var PayoutSettingsEntity = defineEntity({
107
+ name: "PayoutSettings",
108
+ description: "Payout configuration for a store.",
109
+ schema: "marketplace",
110
+ map: "payout_settings",
111
+ fields: {
112
+ id: field.id(),
113
+ storeId: field.foreignKey(),
114
+ schedule: field.enum("PayoutSchedule", { default: "WEEKLY" }),
115
+ dayOfWeek: field.int({
116
+ isOptional: true,
117
+ description: "Day for weekly/biweekly (0=Sunday)"
118
+ }),
119
+ dayOfMonth: field.int({
120
+ isOptional: true,
121
+ description: "Day for monthly (1-28)"
122
+ }),
123
+ minimumPayout: field.decimal({
124
+ default: 50,
125
+ description: "Minimum amount for payout"
126
+ }),
127
+ defaultBankAccountId: field.string({ isOptional: true }),
128
+ createdAt: field.createdAt(),
129
+ updatedAt: field.updatedAt(),
130
+ store: field.belongsTo("Store", ["storeId"], ["id"])
131
+ },
132
+ indexes: [index.unique(["storeId"])],
133
+ enums: [PayoutScheduleEnum]
134
+ });
135
+ export {
136
+ PayoutStatusEnum,
137
+ PayoutSettingsEntity,
138
+ PayoutScheduleEnum,
139
+ PayoutItemEntity,
140
+ PayoutEntity,
141
+ BankAccountEntity
142
+ };
@@ -0,0 +1,152 @@
1
+ // src/entities/product.ts
2
+ import {
3
+ defineEntity,
4
+ defineEntityEnum,
5
+ field,
6
+ index
7
+ } from "@contractspec/lib.schema";
8
+ var ProductStatusEnum = defineEntityEnum({
9
+ name: "ProductStatus",
10
+ values: [
11
+ "DRAFT",
12
+ "PENDING_REVIEW",
13
+ "ACTIVE",
14
+ "OUT_OF_STOCK",
15
+ "DISCONTINUED",
16
+ "REJECTED"
17
+ ],
18
+ schema: "marketplace",
19
+ description: "Status of a product listing."
20
+ });
21
+ var ProductTypeEnum = defineEntityEnum({
22
+ name: "ProductType",
23
+ values: ["PHYSICAL", "DIGITAL", "SERVICE", "SUBSCRIPTION"],
24
+ schema: "marketplace",
25
+ description: "Type of product."
26
+ });
27
+ var ProductEntity = defineEntity({
28
+ name: "Product",
29
+ description: "A product listing on the marketplace.",
30
+ schema: "marketplace",
31
+ map: "product",
32
+ fields: {
33
+ id: field.id({ description: "Unique product ID" }),
34
+ storeId: field.foreignKey(),
35
+ name: field.string({ description: "Product name" }),
36
+ slug: field.string({ description: "URL-friendly identifier" }),
37
+ description: field.string({ isOptional: true }),
38
+ shortDescription: field.string({ isOptional: true }),
39
+ status: field.enum("ProductStatus", { default: "DRAFT" }),
40
+ type: field.enum("ProductType", { default: "PHYSICAL" }),
41
+ price: field.decimal({ description: "Base price" }),
42
+ compareAtPrice: field.decimal({
43
+ isOptional: true,
44
+ description: "Original price for showing discounts"
45
+ }),
46
+ currency: field.string({ default: '"USD"' }),
47
+ sku: field.string({ isOptional: true }),
48
+ barcode: field.string({ isOptional: true }),
49
+ quantity: field.int({ default: 0 }),
50
+ trackInventory: field.boolean({ default: true }),
51
+ allowBackorder: field.boolean({ default: false }),
52
+ lowStockThreshold: field.int({ default: 5 }),
53
+ weight: field.decimal({ isOptional: true }),
54
+ weightUnit: field.string({ default: '"kg"' }),
55
+ categoryId: field.string({ isOptional: true }),
56
+ tags: field.string({ isArray: true }),
57
+ primaryImageId: field.string({ isOptional: true }),
58
+ seoTitle: field.string({ isOptional: true }),
59
+ seoDescription: field.string({ isOptional: true }),
60
+ attributes: field.json({
61
+ isOptional: true,
62
+ description: "Custom product attributes"
63
+ }),
64
+ reviewCount: field.int({ default: 0 }),
65
+ averageRating: field.decimal({ default: 0 }),
66
+ totalSold: field.int({ default: 0 }),
67
+ createdAt: field.createdAt(),
68
+ updatedAt: field.updatedAt(),
69
+ publishedAt: field.dateTime({ isOptional: true }),
70
+ store: field.belongsTo("Store", ["storeId"], ["id"]),
71
+ variants: field.hasMany("ProductVariant"),
72
+ orderItems: field.hasMany("OrderItem"),
73
+ reviews: field.hasMany("Review")
74
+ },
75
+ indexes: [
76
+ index.unique(["storeId", "slug"]),
77
+ index.on(["storeId", "status"]),
78
+ index.on(["status", "publishedAt"]),
79
+ index.on(["categoryId", "status"]),
80
+ index.on(["averageRating"]),
81
+ index.on(["totalSold"]),
82
+ index.on(["price"])
83
+ ],
84
+ enums: [ProductStatusEnum, ProductTypeEnum]
85
+ });
86
+ var ProductVariantEntity = defineEntity({
87
+ name: "ProductVariant",
88
+ description: "A variant of a product with specific options.",
89
+ schema: "marketplace",
90
+ map: "product_variant",
91
+ fields: {
92
+ id: field.id(),
93
+ productId: field.foreignKey(),
94
+ name: field.string({ description: 'Variant name (e.g., "Large / Blue")' }),
95
+ options: field.json({
96
+ description: 'Variant options (e.g., {size: "L", color: "Blue"})'
97
+ }),
98
+ price: field.decimal({ description: "Variant-specific price" }),
99
+ compareAtPrice: field.decimal({ isOptional: true }),
100
+ sku: field.string({ isOptional: true }),
101
+ barcode: field.string({ isOptional: true }),
102
+ quantity: field.int({ default: 0 }),
103
+ imageId: field.string({ isOptional: true }),
104
+ isActive: field.boolean({ default: true }),
105
+ position: field.int({ default: 0 }),
106
+ createdAt: field.createdAt(),
107
+ updatedAt: field.updatedAt(),
108
+ product: field.belongsTo("Product", ["productId"], ["id"], {
109
+ onDelete: "Cascade"
110
+ })
111
+ },
112
+ indexes: [
113
+ index.on(["productId", "sku"]),
114
+ index.on(["productId", "position"]),
115
+ index.on(["barcode"])
116
+ ]
117
+ });
118
+ var CategoryEntity = defineEntity({
119
+ name: "Category",
120
+ description: "Product category for organization.",
121
+ schema: "marketplace",
122
+ map: "category",
123
+ fields: {
124
+ id: field.id(),
125
+ name: field.string(),
126
+ slug: field.string(),
127
+ description: field.string({ isOptional: true }),
128
+ parentId: field.string({ isOptional: true }),
129
+ path: field.string({ description: "Full path for hierarchical queries" }),
130
+ level: field.int({ default: 0 }),
131
+ position: field.int({ default: 0 }),
132
+ imageId: field.string({ isOptional: true }),
133
+ isActive: field.boolean({ default: true }),
134
+ createdAt: field.createdAt(),
135
+ updatedAt: field.updatedAt(),
136
+ parent: field.belongsTo("Category", ["parentId"], ["id"]),
137
+ children: field.hasMany("Category")
138
+ },
139
+ indexes: [
140
+ index.unique(["slug"]),
141
+ index.on(["parentId", "position"]),
142
+ index.on(["path"]),
143
+ index.on(["isActive"])
144
+ ]
145
+ });
146
+ export {
147
+ ProductVariantEntity,
148
+ ProductTypeEnum,
149
+ ProductStatusEnum,
150
+ ProductEntity,
151
+ CategoryEntity
152
+ };
@@ -0,0 +1,129 @@
1
+ // src/entities/review.ts
2
+ import {
3
+ defineEntity,
4
+ defineEntityEnum,
5
+ field,
6
+ index
7
+ } from "@contractspec/lib.schema";
8
+ var ReviewStatusEnum = defineEntityEnum({
9
+ name: "ReviewStatus",
10
+ values: ["PENDING", "APPROVED", "REJECTED", "FLAGGED"],
11
+ schema: "marketplace",
12
+ description: "Status of a review."
13
+ });
14
+ var ReviewTypeEnum = defineEntityEnum({
15
+ name: "ReviewType",
16
+ values: ["PRODUCT", "STORE", "ORDER"],
17
+ schema: "marketplace",
18
+ description: "Type of review."
19
+ });
20
+ var ReviewEntity = defineEntity({
21
+ name: "Review",
22
+ description: "A customer review on the marketplace.",
23
+ schema: "marketplace",
24
+ map: "review",
25
+ fields: {
26
+ id: field.id({ description: "Unique review ID" }),
27
+ type: field.enum("ReviewType", { default: "PRODUCT" }),
28
+ productId: field.string({ isOptional: true }),
29
+ storeId: field.string({ isOptional: true }),
30
+ orderId: field.string({ isOptional: true }),
31
+ orderItemId: field.string({ isOptional: true }),
32
+ authorId: field.foreignKey({ description: "Reviewer user ID" }),
33
+ rating: field.int({ description: "Rating 1-5" }),
34
+ title: field.string({ isOptional: true }),
35
+ content: field.string({ isOptional: true }),
36
+ isVerifiedPurchase: field.boolean({ default: false }),
37
+ status: field.enum("ReviewStatus", { default: "PENDING" }),
38
+ hasMedia: field.boolean({ default: false }),
39
+ helpfulCount: field.int({ default: 0 }),
40
+ notHelpfulCount: field.int({ default: 0 }),
41
+ moderatedBy: field.string({ isOptional: true }),
42
+ moderatedAt: field.dateTime({ isOptional: true }),
43
+ moderationNote: field.string({ isOptional: true }),
44
+ hasResponse: field.boolean({ default: false }),
45
+ createdAt: field.createdAt(),
46
+ updatedAt: field.updatedAt(),
47
+ product: field.belongsTo("Product", ["productId"], ["id"]),
48
+ store: field.belongsTo("Store", ["storeId"], ["id"]),
49
+ responses: field.hasMany("ReviewResponse"),
50
+ votes: field.hasMany("ReviewVote")
51
+ },
52
+ indexes: [
53
+ index.on(["productId", "status", "createdAt"]),
54
+ index.on(["storeId", "status", "createdAt"]),
55
+ index.on(["authorId"]),
56
+ index.on(["orderId"]),
57
+ index.on(["status"]),
58
+ index.on(["rating"]),
59
+ index.on(["isVerifiedPurchase", "status"])
60
+ ],
61
+ enums: [ReviewStatusEnum, ReviewTypeEnum]
62
+ });
63
+ var ReviewResponseEntity = defineEntity({
64
+ name: "ReviewResponse",
65
+ description: "A seller response to a review.",
66
+ schema: "marketplace",
67
+ map: "review_response",
68
+ fields: {
69
+ id: field.id(),
70
+ reviewId: field.foreignKey(),
71
+ authorId: field.foreignKey(),
72
+ content: field.string(),
73
+ createdAt: field.createdAt(),
74
+ updatedAt: field.updatedAt(),
75
+ review: field.belongsTo("Review", ["reviewId"], ["id"], {
76
+ onDelete: "Cascade"
77
+ })
78
+ },
79
+ indexes: [index.on(["reviewId"]), index.on(["authorId"])]
80
+ });
81
+ var ReviewVoteEntity = defineEntity({
82
+ name: "ReviewVote",
83
+ description: "A helpfulness vote on a review.",
84
+ schema: "marketplace",
85
+ map: "review_vote",
86
+ fields: {
87
+ id: field.id(),
88
+ reviewId: field.foreignKey(),
89
+ userId: field.foreignKey(),
90
+ isHelpful: field.boolean(),
91
+ createdAt: field.createdAt(),
92
+ review: field.belongsTo("Review", ["reviewId"], ["id"], {
93
+ onDelete: "Cascade"
94
+ })
95
+ },
96
+ indexes: [index.unique(["reviewId", "userId"]), index.on(["userId"])]
97
+ });
98
+ var ReviewReportEntity = defineEntity({
99
+ name: "ReviewReport",
100
+ description: "A report/flag on a review.",
101
+ schema: "marketplace",
102
+ map: "review_report",
103
+ fields: {
104
+ id: field.id(),
105
+ reviewId: field.foreignKey(),
106
+ reporterId: field.foreignKey(),
107
+ reason: field.string({ description: "Report reason category" }),
108
+ details: field.string({ isOptional: true }),
109
+ status: field.string({ default: '"PENDING"' }),
110
+ resolvedBy: field.string({ isOptional: true }),
111
+ resolvedAt: field.dateTime({ isOptional: true }),
112
+ resolution: field.string({ isOptional: true }),
113
+ createdAt: field.createdAt(),
114
+ review: field.belongsTo("Review", ["reviewId"], ["id"])
115
+ },
116
+ indexes: [
117
+ index.on(["reviewId"]),
118
+ index.on(["status"]),
119
+ index.on(["reporterId"])
120
+ ]
121
+ });
122
+ export {
123
+ ReviewVoteEntity,
124
+ ReviewTypeEnum,
125
+ ReviewStatusEnum,
126
+ ReviewResponseEntity,
127
+ ReviewReportEntity,
128
+ ReviewEntity
129
+ };
@@ -0,0 +1,97 @@
1
+ // src/entities/store.ts
2
+ import {
3
+ defineEntity,
4
+ defineEntityEnum,
5
+ field,
6
+ index
7
+ } from "@contractspec/lib.schema";
8
+ var StoreStatusEnum = defineEntityEnum({
9
+ name: "StoreStatus",
10
+ values: ["PENDING", "ACTIVE", "SUSPENDED", "CLOSED"],
11
+ schema: "marketplace",
12
+ description: "Status of a store."
13
+ });
14
+ var StoreTypeEnum = defineEntityEnum({
15
+ name: "StoreType",
16
+ values: ["INDIVIDUAL", "BUSINESS", "ENTERPRISE"],
17
+ schema: "marketplace",
18
+ description: "Type of store account."
19
+ });
20
+ var StoreEntity = defineEntity({
21
+ name: "Store",
22
+ description: "A seller storefront on the marketplace.",
23
+ schema: "marketplace",
24
+ map: "store",
25
+ fields: {
26
+ id: field.id({ description: "Unique store ID" }),
27
+ name: field.string({ description: "Store display name" }),
28
+ slug: field.string({ description: "URL-friendly identifier" }),
29
+ description: field.string({ isOptional: true }),
30
+ status: field.enum("StoreStatus", { default: "PENDING" }),
31
+ type: field.enum("StoreType", { default: "INDIVIDUAL" }),
32
+ ownerId: field.foreignKey({ description: "Store owner user ID" }),
33
+ organizationId: field.foreignKey({ isOptional: true }),
34
+ logoFileId: field.string({
35
+ isOptional: true,
36
+ description: "Logo file reference"
37
+ }),
38
+ bannerFileId: field.string({
39
+ isOptional: true,
40
+ description: "Banner file reference"
41
+ }),
42
+ email: field.string({ isOptional: true }),
43
+ phone: field.string({ isOptional: true }),
44
+ website: field.string({ isOptional: true }),
45
+ country: field.string({ isOptional: true }),
46
+ currency: field.string({ default: '"USD"' }),
47
+ timezone: field.string({ isOptional: true }),
48
+ commissionRate: field.decimal({
49
+ default: 0.1,
50
+ description: "Platform commission rate (e.g., 0.1 = 10%)"
51
+ }),
52
+ isVerified: field.boolean({ default: false }),
53
+ verifiedAt: field.dateTime({ isOptional: true }),
54
+ settings: field.json({ isOptional: true }),
55
+ metadata: field.json({ isOptional: true }),
56
+ totalProducts: field.int({ default: 0 }),
57
+ totalOrders: field.int({ default: 0 }),
58
+ totalRevenue: field.decimal({ default: 0 }),
59
+ averageRating: field.decimal({ default: 0 }),
60
+ createdAt: field.createdAt(),
61
+ updatedAt: field.updatedAt(),
62
+ products: field.hasMany("Product"),
63
+ orders: field.hasMany("Order"),
64
+ payouts: field.hasMany("Payout")
65
+ },
66
+ indexes: [
67
+ index.unique(["slug"]),
68
+ index.on(["ownerId"]),
69
+ index.on(["status"]),
70
+ index.on(["country", "status"]),
71
+ index.on(["averageRating"])
72
+ ],
73
+ enums: [StoreStatusEnum, StoreTypeEnum]
74
+ });
75
+ var StoreCategoryEntity = defineEntity({
76
+ name: "StoreCategory",
77
+ description: "Category assignment for stores.",
78
+ schema: "marketplace",
79
+ map: "store_category",
80
+ fields: {
81
+ id: field.id(),
82
+ storeId: field.foreignKey(),
83
+ categoryId: field.foreignKey(),
84
+ isPrimary: field.boolean({ default: false }),
85
+ createdAt: field.createdAt(),
86
+ store: field.belongsTo("Store", ["storeId"], ["id"], {
87
+ onDelete: "Cascade"
88
+ })
89
+ },
90
+ indexes: [index.unique(["storeId", "categoryId"]), index.on(["categoryId"])]
91
+ });
92
+ export {
93
+ StoreTypeEnum,
94
+ StoreStatusEnum,
95
+ StoreEntity,
96
+ StoreCategoryEntity
97
+ };