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