@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
package/dist/entities/store.js
CHANGED
|
@@ -1,110 +1,98 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
],
|
|
15
|
-
schema: "marketplace",
|
|
16
|
-
description: "Status of a store."
|
|
1
|
+
// @bun
|
|
2
|
+
// src/entities/store.ts
|
|
3
|
+
import {
|
|
4
|
+
defineEntity,
|
|
5
|
+
defineEntityEnum,
|
|
6
|
+
field,
|
|
7
|
+
index
|
|
8
|
+
} from "@contractspec/lib.schema";
|
|
9
|
+
var StoreStatusEnum = defineEntityEnum({
|
|
10
|
+
name: "StoreStatus",
|
|
11
|
+
values: ["PENDING", "ACTIVE", "SUSPENDED", "CLOSED"],
|
|
12
|
+
schema: "marketplace",
|
|
13
|
+
description: "Status of a store."
|
|
17
14
|
});
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
values: [
|
|
24
|
-
"INDIVIDUAL",
|
|
25
|
-
"BUSINESS",
|
|
26
|
-
"ENTERPRISE"
|
|
27
|
-
],
|
|
28
|
-
schema: "marketplace",
|
|
29
|
-
description: "Type of store account."
|
|
15
|
+
var StoreTypeEnum = defineEntityEnum({
|
|
16
|
+
name: "StoreType",
|
|
17
|
+
values: ["INDIVIDUAL", "BUSINESS", "ENTERPRISE"],
|
|
18
|
+
schema: "marketplace",
|
|
19
|
+
description: "Type of store account."
|
|
30
20
|
});
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
index.on(["averageRating"])
|
|
86
|
-
],
|
|
87
|
-
enums: [StoreStatusEnum, StoreTypeEnum]
|
|
21
|
+
var StoreEntity = defineEntity({
|
|
22
|
+
name: "Store",
|
|
23
|
+
description: "A seller storefront on the marketplace.",
|
|
24
|
+
schema: "marketplace",
|
|
25
|
+
map: "store",
|
|
26
|
+
fields: {
|
|
27
|
+
id: field.id({ description: "Unique store ID" }),
|
|
28
|
+
name: field.string({ description: "Store display name" }),
|
|
29
|
+
slug: field.string({ description: "URL-friendly identifier" }),
|
|
30
|
+
description: field.string({ isOptional: true }),
|
|
31
|
+
status: field.enum("StoreStatus", { default: "PENDING" }),
|
|
32
|
+
type: field.enum("StoreType", { default: "INDIVIDUAL" }),
|
|
33
|
+
ownerId: field.foreignKey({ description: "Store owner user ID" }),
|
|
34
|
+
organizationId: field.foreignKey({ isOptional: true }),
|
|
35
|
+
logoFileId: field.string({
|
|
36
|
+
isOptional: true,
|
|
37
|
+
description: "Logo file reference"
|
|
38
|
+
}),
|
|
39
|
+
bannerFileId: field.string({
|
|
40
|
+
isOptional: true,
|
|
41
|
+
description: "Banner file reference"
|
|
42
|
+
}),
|
|
43
|
+
email: field.string({ isOptional: true }),
|
|
44
|
+
phone: field.string({ isOptional: true }),
|
|
45
|
+
website: field.string({ isOptional: true }),
|
|
46
|
+
country: field.string({ isOptional: true }),
|
|
47
|
+
currency: field.string({ default: '"USD"' }),
|
|
48
|
+
timezone: field.string({ isOptional: true }),
|
|
49
|
+
commissionRate: field.decimal({
|
|
50
|
+
default: 0.1,
|
|
51
|
+
description: "Platform commission rate (e.g., 0.1 = 10%)"
|
|
52
|
+
}),
|
|
53
|
+
isVerified: field.boolean({ default: false }),
|
|
54
|
+
verifiedAt: field.dateTime({ isOptional: true }),
|
|
55
|
+
settings: field.json({ isOptional: true }),
|
|
56
|
+
metadata: field.json({ isOptional: true }),
|
|
57
|
+
totalProducts: field.int({ default: 0 }),
|
|
58
|
+
totalOrders: field.int({ default: 0 }),
|
|
59
|
+
totalRevenue: field.decimal({ default: 0 }),
|
|
60
|
+
averageRating: field.decimal({ default: 0 }),
|
|
61
|
+
createdAt: field.createdAt(),
|
|
62
|
+
updatedAt: field.updatedAt(),
|
|
63
|
+
products: field.hasMany("Product"),
|
|
64
|
+
orders: field.hasMany("Order"),
|
|
65
|
+
payouts: field.hasMany("Payout")
|
|
66
|
+
},
|
|
67
|
+
indexes: [
|
|
68
|
+
index.unique(["slug"]),
|
|
69
|
+
index.on(["ownerId"]),
|
|
70
|
+
index.on(["status"]),
|
|
71
|
+
index.on(["country", "status"]),
|
|
72
|
+
index.on(["averageRating"])
|
|
73
|
+
],
|
|
74
|
+
enums: [StoreStatusEnum, StoreTypeEnum]
|
|
88
75
|
});
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
indexes: [index.unique(["storeId", "categoryId"]), index.on(["categoryId"])]
|
|
76
|
+
var StoreCategoryEntity = defineEntity({
|
|
77
|
+
name: "StoreCategory",
|
|
78
|
+
description: "Category assignment for stores.",
|
|
79
|
+
schema: "marketplace",
|
|
80
|
+
map: "store_category",
|
|
81
|
+
fields: {
|
|
82
|
+
id: field.id(),
|
|
83
|
+
storeId: field.foreignKey(),
|
|
84
|
+
categoryId: field.foreignKey(),
|
|
85
|
+
isPrimary: field.boolean({ default: false }),
|
|
86
|
+
createdAt: field.createdAt(),
|
|
87
|
+
store: field.belongsTo("Store", ["storeId"], ["id"], {
|
|
88
|
+
onDelete: "Cascade"
|
|
89
|
+
})
|
|
90
|
+
},
|
|
91
|
+
indexes: [index.unique(["storeId", "categoryId"]), index.on(["categoryId"])]
|
|
106
92
|
});
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
93
|
+
export {
|
|
94
|
+
StoreTypeEnum,
|
|
95
|
+
StoreStatusEnum,
|
|
96
|
+
StoreEntity,
|
|
97
|
+
StoreCategoryEntity
|
|
98
|
+
};
|
package/dist/example.d.ts
CHANGED
|
@@ -1,7 +1,3 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
//#region src/example.d.ts
|
|
4
|
-
declare const example: _contractspec_lib_contracts0.ExampleSpec;
|
|
5
|
-
//#endregion
|
|
6
|
-
export { example as default };
|
|
1
|
+
declare const example: import("@contractspec/lib.contracts").ExampleSpec;
|
|
2
|
+
export default example;
|
|
7
3
|
//# sourceMappingURL=example.d.ts.map
|
package/dist/example.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"example.d.ts","
|
|
1
|
+
{"version":3,"file":"example.d.ts","sourceRoot":"","sources":["../src/example.ts"],"names":[],"mappings":"AAEA,QAAA,MAAM,OAAO,mDAoCX,CAAC;AAEH,eAAe,OAAO,CAAC"}
|
package/dist/example.js
CHANGED
|
@@ -1,58 +1,43 @@
|
|
|
1
|
+
// @bun
|
|
2
|
+
// src/example.ts
|
|
1
3
|
import { defineExample } from "@contractspec/lib.contracts";
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
sandbox: {
|
|
38
|
-
enabled: true,
|
|
39
|
-
modes: [
|
|
40
|
-
"playground",
|
|
41
|
-
"specs",
|
|
42
|
-
"builder",
|
|
43
|
-
"markdown",
|
|
44
|
-
"evolution"
|
|
45
|
-
]
|
|
46
|
-
},
|
|
47
|
-
studio: {
|
|
48
|
-
enabled: true,
|
|
49
|
-
installable: true
|
|
50
|
-
},
|
|
51
|
-
mcp: { enabled: true }
|
|
52
|
-
}
|
|
4
|
+
var example = defineExample({
|
|
5
|
+
meta: {
|
|
6
|
+
key: "marketplace",
|
|
7
|
+
version: "1.0.0",
|
|
8
|
+
title: "Marketplace (2-sided)",
|
|
9
|
+
description: "Two-sided marketplace with stores, products, orders, payouts, and reviews (multi-actor flows).",
|
|
10
|
+
kind: "template",
|
|
11
|
+
visibility: "public",
|
|
12
|
+
stability: "experimental",
|
|
13
|
+
owners: ["@platform.core"],
|
|
14
|
+
tags: ["marketplace", "orders", "payouts", "reviews"]
|
|
15
|
+
},
|
|
16
|
+
docs: {
|
|
17
|
+
rootDocId: "docs.examples.marketplace",
|
|
18
|
+
goalDocId: "docs.examples.marketplace.goal",
|
|
19
|
+
usageDocId: "docs.examples.marketplace.usage",
|
|
20
|
+
constraintsDocId: "docs.examples.marketplace.constraints"
|
|
21
|
+
},
|
|
22
|
+
entrypoints: {
|
|
23
|
+
packageName: "@contractspec/example.marketplace",
|
|
24
|
+
feature: "./feature",
|
|
25
|
+
contracts: "./contracts",
|
|
26
|
+
presentations: "./presentations",
|
|
27
|
+
handlers: "./handlers",
|
|
28
|
+
docs: "./docs"
|
|
29
|
+
},
|
|
30
|
+
surfaces: {
|
|
31
|
+
templates: true,
|
|
32
|
+
sandbox: {
|
|
33
|
+
enabled: true,
|
|
34
|
+
modes: ["playground", "specs", "builder", "markdown", "evolution"]
|
|
35
|
+
},
|
|
36
|
+
studio: { enabled: true, installable: true },
|
|
37
|
+
mcp: { enabled: true }
|
|
38
|
+
}
|
|
53
39
|
});
|
|
54
40
|
var example_default = example;
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
//# sourceMappingURL=example.js.map
|
|
41
|
+
export {
|
|
42
|
+
example_default as default
|
|
43
|
+
};
|
package/dist/handlers/index.d.ts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
1
|
+
export * from './marketplace.handlers';
|
|
2
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/handlers/index.ts"],"names":[],"mappings":"AAAA,cAAc,wBAAwB,CAAC"}
|
package/dist/handlers/index.js
CHANGED
|
@@ -1,3 +1,304 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
1
|
+
// @bun
|
|
2
|
+
// src/handlers/marketplace.handlers.ts
|
|
3
|
+
import { web } from "@contractspec/lib.runtime-sandbox";
|
|
4
|
+
var { generateId } = web;
|
|
5
|
+
function rowToStore(row) {
|
|
6
|
+
return {
|
|
7
|
+
id: row.id,
|
|
8
|
+
projectId: row.projectId,
|
|
9
|
+
organizationId: row.organizationId,
|
|
10
|
+
name: row.name,
|
|
11
|
+
description: row.description ?? undefined,
|
|
12
|
+
status: row.status,
|
|
13
|
+
rating: row.rating,
|
|
14
|
+
reviewCount: row.reviewCount,
|
|
15
|
+
createdAt: new Date(row.createdAt),
|
|
16
|
+
updatedAt: new Date(row.updatedAt)
|
|
17
|
+
};
|
|
18
|
+
}
|
|
19
|
+
function rowToProduct(row) {
|
|
20
|
+
return {
|
|
21
|
+
id: row.id,
|
|
22
|
+
storeId: row.storeId,
|
|
23
|
+
name: row.name,
|
|
24
|
+
description: row.description ?? undefined,
|
|
25
|
+
price: row.price,
|
|
26
|
+
currency: row.currency,
|
|
27
|
+
status: row.status,
|
|
28
|
+
stock: row.stock,
|
|
29
|
+
category: row.category ?? undefined,
|
|
30
|
+
imageUrl: row.imageUrl ?? undefined,
|
|
31
|
+
createdAt: new Date(row.createdAt),
|
|
32
|
+
updatedAt: new Date(row.updatedAt)
|
|
33
|
+
};
|
|
34
|
+
}
|
|
35
|
+
function rowToOrder(row) {
|
|
36
|
+
return {
|
|
37
|
+
id: row.id,
|
|
38
|
+
projectId: row.projectId,
|
|
39
|
+
storeId: row.storeId,
|
|
40
|
+
customerId: row.customerId,
|
|
41
|
+
status: row.status,
|
|
42
|
+
total: row.total,
|
|
43
|
+
currency: row.currency,
|
|
44
|
+
shippingAddress: row.shippingAddress ?? undefined,
|
|
45
|
+
createdAt: new Date(row.createdAt),
|
|
46
|
+
updatedAt: new Date(row.updatedAt)
|
|
47
|
+
};
|
|
48
|
+
}
|
|
49
|
+
function rowToOrderItem(row) {
|
|
50
|
+
return {
|
|
51
|
+
id: row.id,
|
|
52
|
+
orderId: row.orderId,
|
|
53
|
+
productId: row.productId,
|
|
54
|
+
quantity: row.quantity,
|
|
55
|
+
price: row.price,
|
|
56
|
+
createdAt: new Date(row.createdAt)
|
|
57
|
+
};
|
|
58
|
+
}
|
|
59
|
+
function rowToPayout(row) {
|
|
60
|
+
return {
|
|
61
|
+
id: row.id,
|
|
62
|
+
storeId: row.storeId,
|
|
63
|
+
amount: row.amount,
|
|
64
|
+
currency: row.currency,
|
|
65
|
+
status: row.status,
|
|
66
|
+
processedAt: row.processedAt ? new Date(row.processedAt) : undefined,
|
|
67
|
+
createdAt: new Date(row.createdAt)
|
|
68
|
+
};
|
|
69
|
+
}
|
|
70
|
+
function rowToReview(row) {
|
|
71
|
+
return {
|
|
72
|
+
id: row.id,
|
|
73
|
+
productId: row.productId,
|
|
74
|
+
customerId: row.customerId,
|
|
75
|
+
orderId: row.orderId ?? undefined,
|
|
76
|
+
rating: row.rating,
|
|
77
|
+
comment: row.comment ?? undefined,
|
|
78
|
+
createdAt: new Date(row.createdAt)
|
|
79
|
+
};
|
|
80
|
+
}
|
|
81
|
+
function createMarketplaceHandlers(db) {
|
|
82
|
+
async function listStores(input) {
|
|
83
|
+
const { projectId, status, search, limit = 20, offset = 0 } = input;
|
|
84
|
+
let whereClause = "WHERE projectId = ?";
|
|
85
|
+
const params = [projectId];
|
|
86
|
+
if (status && status !== "all") {
|
|
87
|
+
whereClause += " AND status = ?";
|
|
88
|
+
params.push(status);
|
|
89
|
+
}
|
|
90
|
+
if (search) {
|
|
91
|
+
whereClause += " AND name LIKE ?";
|
|
92
|
+
params.push(`%${search}%`);
|
|
93
|
+
}
|
|
94
|
+
const countResult = (await db.query(`SELECT COUNT(*) as count FROM marketplace_store ${whereClause}`, params)).rows;
|
|
95
|
+
const total = countResult[0]?.count ?? 0;
|
|
96
|
+
const rows = (await db.query(`SELECT * FROM marketplace_store ${whereClause} ORDER BY rating DESC LIMIT ? OFFSET ?`, [...params, limit, offset])).rows;
|
|
97
|
+
return {
|
|
98
|
+
stores: rows.map(rowToStore),
|
|
99
|
+
total
|
|
100
|
+
};
|
|
101
|
+
}
|
|
102
|
+
async function createStore(input, context) {
|
|
103
|
+
const id = generateId("store");
|
|
104
|
+
const now = new Date().toISOString();
|
|
105
|
+
await db.execute(`INSERT INTO marketplace_store (id, projectId, organizationId, name, description, status, rating, reviewCount, createdAt, updatedAt)
|
|
106
|
+
VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?)`, [
|
|
107
|
+
id,
|
|
108
|
+
context.projectId,
|
|
109
|
+
context.organizationId,
|
|
110
|
+
input.name,
|
|
111
|
+
input.description ?? null,
|
|
112
|
+
"PENDING",
|
|
113
|
+
0,
|
|
114
|
+
0,
|
|
115
|
+
now,
|
|
116
|
+
now
|
|
117
|
+
]);
|
|
118
|
+
const rows = (await db.query(`SELECT * FROM marketplace_store WHERE id = ?`, [id])).rows;
|
|
119
|
+
return rowToStore(rows[0]);
|
|
120
|
+
}
|
|
121
|
+
async function listProducts(input) {
|
|
122
|
+
const { storeId, status, category, search, limit = 20, offset = 0 } = input;
|
|
123
|
+
let whereClause = "WHERE 1=1";
|
|
124
|
+
const params = [];
|
|
125
|
+
if (storeId) {
|
|
126
|
+
whereClause += " AND storeId = ?";
|
|
127
|
+
params.push(storeId);
|
|
128
|
+
}
|
|
129
|
+
if (status && status !== "all") {
|
|
130
|
+
whereClause += " AND status = ?";
|
|
131
|
+
params.push(status);
|
|
132
|
+
}
|
|
133
|
+
if (category) {
|
|
134
|
+
whereClause += " AND category = ?";
|
|
135
|
+
params.push(category);
|
|
136
|
+
}
|
|
137
|
+
if (search) {
|
|
138
|
+
whereClause += " AND name LIKE ?";
|
|
139
|
+
params.push(`%${search}%`);
|
|
140
|
+
}
|
|
141
|
+
const countResult = (await db.query(`SELECT COUNT(*) as count FROM marketplace_product ${whereClause}`, params)).rows;
|
|
142
|
+
const total = countResult[0]?.count ?? 0;
|
|
143
|
+
const rows = (await db.query(`SELECT * FROM marketplace_product ${whereClause} ORDER BY createdAt DESC LIMIT ? OFFSET ?`, [...params, limit, offset])).rows;
|
|
144
|
+
return {
|
|
145
|
+
products: rows.map(rowToProduct),
|
|
146
|
+
total
|
|
147
|
+
};
|
|
148
|
+
}
|
|
149
|
+
async function addProduct(input) {
|
|
150
|
+
const id = generateId("prod");
|
|
151
|
+
const now = new Date().toISOString();
|
|
152
|
+
await db.execute(`INSERT INTO marketplace_product (id, storeId, name, description, price, currency, status, stock, category, imageUrl, createdAt, updatedAt)
|
|
153
|
+
VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)`, [
|
|
154
|
+
id,
|
|
155
|
+
input.storeId,
|
|
156
|
+
input.name,
|
|
157
|
+
input.description ?? null,
|
|
158
|
+
input.price,
|
|
159
|
+
input.currency ?? "USD",
|
|
160
|
+
"DRAFT",
|
|
161
|
+
input.stock ?? 0,
|
|
162
|
+
input.category ?? null,
|
|
163
|
+
input.imageUrl ?? null,
|
|
164
|
+
now,
|
|
165
|
+
now
|
|
166
|
+
]);
|
|
167
|
+
const rows = (await db.query(`SELECT * FROM marketplace_product WHERE id = ?`, [id])).rows;
|
|
168
|
+
return rowToProduct(rows[0]);
|
|
169
|
+
}
|
|
170
|
+
async function listOrders(input) {
|
|
171
|
+
const {
|
|
172
|
+
projectId,
|
|
173
|
+
storeId,
|
|
174
|
+
customerId,
|
|
175
|
+
status,
|
|
176
|
+
limit = 20,
|
|
177
|
+
offset = 0
|
|
178
|
+
} = input;
|
|
179
|
+
let whereClause = "WHERE projectId = ?";
|
|
180
|
+
const params = [projectId];
|
|
181
|
+
if (storeId) {
|
|
182
|
+
whereClause += " AND storeId = ?";
|
|
183
|
+
params.push(storeId);
|
|
184
|
+
}
|
|
185
|
+
if (customerId) {
|
|
186
|
+
whereClause += " AND customerId = ?";
|
|
187
|
+
params.push(customerId);
|
|
188
|
+
}
|
|
189
|
+
if (status && status !== "all") {
|
|
190
|
+
whereClause += " AND status = ?";
|
|
191
|
+
params.push(status);
|
|
192
|
+
}
|
|
193
|
+
const countResult = (await db.query(`SELECT COUNT(*) as count FROM marketplace_order ${whereClause}`, params)).rows;
|
|
194
|
+
const total = countResult[0]?.count ?? 0;
|
|
195
|
+
const revenueResult = (await db.query(`SELECT COALESCE(SUM(total), 0) as revenue FROM marketplace_order ${whereClause}`, params)).rows;
|
|
196
|
+
const totalRevenue = revenueResult[0]?.revenue ?? 0;
|
|
197
|
+
const rows = (await db.query(`SELECT * FROM marketplace_order ${whereClause} ORDER BY createdAt DESC LIMIT ? OFFSET ?`, [...params, limit, offset])).rows;
|
|
198
|
+
return {
|
|
199
|
+
orders: rows.map(rowToOrder),
|
|
200
|
+
total,
|
|
201
|
+
totalRevenue
|
|
202
|
+
};
|
|
203
|
+
}
|
|
204
|
+
async function placeOrder(input, context) {
|
|
205
|
+
const orderId = generateId("order");
|
|
206
|
+
const now = new Date().toISOString();
|
|
207
|
+
let total = 0;
|
|
208
|
+
const itemsToCreate = [];
|
|
209
|
+
for (const item of input.items) {
|
|
210
|
+
const products = (await db.query(`SELECT * FROM marketplace_product WHERE id = ?`, [
|
|
211
|
+
item.productId
|
|
212
|
+
])).rows;
|
|
213
|
+
if (!products[0]) {
|
|
214
|
+
throw new Error(`Product not found: ${item.productId}`);
|
|
215
|
+
}
|
|
216
|
+
const itemPrice = products[0].price * item.quantity;
|
|
217
|
+
total += itemPrice;
|
|
218
|
+
itemsToCreate.push({
|
|
219
|
+
productId: item.productId,
|
|
220
|
+
quantity: item.quantity,
|
|
221
|
+
price: products[0].price
|
|
222
|
+
});
|
|
223
|
+
}
|
|
224
|
+
await db.execute(`INSERT INTO marketplace_order (id, projectId, storeId, customerId, status, total, currency, shippingAddress, createdAt, updatedAt)
|
|
225
|
+
VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?)`, [
|
|
226
|
+
orderId,
|
|
227
|
+
context.projectId,
|
|
228
|
+
input.storeId,
|
|
229
|
+
context.customerId,
|
|
230
|
+
"PENDING",
|
|
231
|
+
total,
|
|
232
|
+
"USD",
|
|
233
|
+
input.shippingAddress ?? null,
|
|
234
|
+
now,
|
|
235
|
+
now
|
|
236
|
+
]);
|
|
237
|
+
for (const item of itemsToCreate) {
|
|
238
|
+
await db.execute(`INSERT INTO marketplace_order_item (id, orderId, productId, quantity, price, createdAt)
|
|
239
|
+
VALUES (?, ?, ?, ?, ?, ?)`, [
|
|
240
|
+
generateId("orditem"),
|
|
241
|
+
orderId,
|
|
242
|
+
item.productId,
|
|
243
|
+
item.quantity,
|
|
244
|
+
item.price,
|
|
245
|
+
now
|
|
246
|
+
]);
|
|
247
|
+
}
|
|
248
|
+
const rows = (await db.query(`SELECT * FROM marketplace_order WHERE id = ?`, [orderId])).rows;
|
|
249
|
+
return rowToOrder(rows[0]);
|
|
250
|
+
}
|
|
251
|
+
async function getOrderItems(orderId) {
|
|
252
|
+
const rows = (await db.query(`SELECT * FROM marketplace_order_item WHERE orderId = ?`, [
|
|
253
|
+
orderId
|
|
254
|
+
])).rows;
|
|
255
|
+
return rows.map(rowToOrderItem);
|
|
256
|
+
}
|
|
257
|
+
async function updateOrderStatus(orderId, status) {
|
|
258
|
+
const now = new Date().toISOString();
|
|
259
|
+
await db.execute(`UPDATE marketplace_order SET status = ?, updatedAt = ? WHERE id = ?`, [status, now, orderId]);
|
|
260
|
+
const rows = (await db.query(`SELECT * FROM marketplace_order WHERE id = ?`, [orderId])).rows;
|
|
261
|
+
return rowToOrder(rows[0]);
|
|
262
|
+
}
|
|
263
|
+
async function listPayouts(storeId) {
|
|
264
|
+
const rows = (await db.query(`SELECT * FROM marketplace_payout WHERE storeId = ? ORDER BY createdAt DESC`, [storeId])).rows;
|
|
265
|
+
return rows.map(rowToPayout);
|
|
266
|
+
}
|
|
267
|
+
async function listReviews(productId) {
|
|
268
|
+
const rows = (await db.query(`SELECT * FROM marketplace_review WHERE productId = ? ORDER BY createdAt DESC`, [productId])).rows;
|
|
269
|
+
return rows.map(rowToReview);
|
|
270
|
+
}
|
|
271
|
+
async function submitReview(input) {
|
|
272
|
+
const id = generateId("review");
|
|
273
|
+
const now = new Date().toISOString();
|
|
274
|
+
await db.execute(`INSERT INTO marketplace_review (id, productId, customerId, orderId, rating, comment, createdAt)
|
|
275
|
+
VALUES (?, ?, ?, ?, ?, ?, ?)`, [
|
|
276
|
+
id,
|
|
277
|
+
input.productId,
|
|
278
|
+
input.customerId,
|
|
279
|
+
input.orderId ?? null,
|
|
280
|
+
input.rating,
|
|
281
|
+
input.comment ?? null,
|
|
282
|
+
now,
|
|
283
|
+
now
|
|
284
|
+
]);
|
|
285
|
+
const rows = (await db.query(`SELECT * FROM marketplace_review WHERE id = ?`, [id])).rows;
|
|
286
|
+
return rowToReview(rows[0]);
|
|
287
|
+
}
|
|
288
|
+
return {
|
|
289
|
+
listStores,
|
|
290
|
+
createStore,
|
|
291
|
+
listProducts,
|
|
292
|
+
addProduct,
|
|
293
|
+
listOrders,
|
|
294
|
+
placeOrder,
|
|
295
|
+
getOrderItems,
|
|
296
|
+
updateOrderStatus,
|
|
297
|
+
listPayouts,
|
|
298
|
+
listReviews,
|
|
299
|
+
submitReview
|
|
300
|
+
};
|
|
301
|
+
}
|
|
302
|
+
export {
|
|
303
|
+
createMarketplaceHandlers
|
|
304
|
+
};
|