@contractspec/example.marketplace 3.7.6 → 3.8.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (86) hide show
  1. package/README.md +64 -131
  2. package/dist/browser/entities/index.js +470 -470
  3. package/dist/browser/index.js +1257 -1019
  4. package/dist/browser/marketplace.feature.js +175 -0
  5. package/dist/browser/order/index.js +155 -155
  6. package/dist/browser/order/order.event.js +1 -1
  7. package/dist/browser/payout/index.js +71 -71
  8. package/dist/browser/payout/payout.event.js +1 -1
  9. package/dist/browser/product/index.js +104 -104
  10. package/dist/browser/product/product.event.js +1 -1
  11. package/dist/browser/review/index.js +75 -75
  12. package/dist/browser/review/review.event.js +1 -1
  13. package/dist/browser/store/index.js +68 -68
  14. package/dist/browser/store/store.event.js +1 -1
  15. package/dist/browser/ui/MarketplaceDashboard.js +328 -110
  16. package/dist/browser/ui/MarketplaceDashboard.visualizations.js +216 -0
  17. package/dist/browser/ui/hooks/index.js +1 -1
  18. package/dist/browser/ui/hooks/useMarketplaceData.js +1 -1
  19. package/dist/browser/ui/index.js +590 -359
  20. package/dist/browser/ui/renderers/index.js +190 -4
  21. package/dist/browser/ui/renderers/marketplace.markdown.js +190 -4
  22. package/dist/browser/visualizations/catalog.js +126 -0
  23. package/dist/browser/visualizations/index.js +183 -0
  24. package/dist/browser/visualizations/selectors.js +177 -0
  25. package/dist/entities/index.d.ts +110 -110
  26. package/dist/entities/index.js +470 -470
  27. package/dist/index.d.ts +4 -3
  28. package/dist/index.js +1257 -1019
  29. package/dist/marketplace.feature.js +175 -0
  30. package/dist/node/entities/index.js +470 -470
  31. package/dist/node/index.js +1257 -1019
  32. package/dist/node/marketplace.feature.js +175 -0
  33. package/dist/node/order/index.js +155 -155
  34. package/dist/node/order/order.event.js +1 -1
  35. package/dist/node/payout/index.js +71 -71
  36. package/dist/node/payout/payout.event.js +1 -1
  37. package/dist/node/product/index.js +104 -104
  38. package/dist/node/product/product.event.js +1 -1
  39. package/dist/node/review/index.js +75 -75
  40. package/dist/node/review/review.event.js +1 -1
  41. package/dist/node/store/index.js +68 -68
  42. package/dist/node/store/store.event.js +1 -1
  43. package/dist/node/ui/MarketplaceDashboard.js +328 -110
  44. package/dist/node/ui/MarketplaceDashboard.visualizations.js +216 -0
  45. package/dist/node/ui/hooks/index.js +1 -1
  46. package/dist/node/ui/hooks/useMarketplaceData.js +1 -1
  47. package/dist/node/ui/index.js +590 -359
  48. package/dist/node/ui/renderers/index.js +190 -4
  49. package/dist/node/ui/renderers/marketplace.markdown.js +190 -4
  50. package/dist/node/visualizations/catalog.js +126 -0
  51. package/dist/node/visualizations/index.js +183 -0
  52. package/dist/node/visualizations/selectors.js +177 -0
  53. package/dist/order/index.d.ts +2 -2
  54. package/dist/order/index.js +155 -155
  55. package/dist/order/order.event.js +1 -1
  56. package/dist/payout/index.d.ts +2 -2
  57. package/dist/payout/index.js +71 -71
  58. package/dist/payout/payout.event.js +1 -1
  59. package/dist/product/index.d.ts +2 -2
  60. package/dist/product/index.js +104 -104
  61. package/dist/product/product.event.js +1 -1
  62. package/dist/review/index.d.ts +2 -2
  63. package/dist/review/index.js +75 -75
  64. package/dist/review/review.event.js +1 -1
  65. package/dist/store/index.d.ts +2 -2
  66. package/dist/store/index.js +68 -68
  67. package/dist/store/store.event.js +1 -1
  68. package/dist/ui/MarketplaceDashboard.js +328 -110
  69. package/dist/ui/MarketplaceDashboard.visualizations.d.ts +5 -0
  70. package/dist/ui/MarketplaceDashboard.visualizations.js +217 -0
  71. package/dist/ui/hooks/index.d.ts +1 -1
  72. package/dist/ui/hooks/index.js +1 -1
  73. package/dist/ui/hooks/useMarketplaceData.js +1 -1
  74. package/dist/ui/index.d.ts +2 -2
  75. package/dist/ui/index.js +590 -359
  76. package/dist/ui/renderers/index.d.ts +1 -1
  77. package/dist/ui/renderers/index.js +190 -4
  78. package/dist/ui/renderers/marketplace.markdown.js +190 -4
  79. package/dist/visualizations/catalog.d.ts +10 -0
  80. package/dist/visualizations/catalog.js +127 -0
  81. package/dist/visualizations/index.d.ts +2 -0
  82. package/dist/visualizations/index.js +184 -0
  83. package/dist/visualizations/selectors.d.ts +11 -0
  84. package/dist/visualizations/selectors.js +178 -0
  85. package/dist/visualizations/selectors.test.d.ts +1 -0
  86. package/package.json +66 -10
@@ -0,0 +1,5 @@
1
+ import type { Order, Product } from '../handlers/marketplace.handlers';
2
+ export declare function MarketplaceVisualizationOverview({ products, orders, }: {
3
+ products: Product[];
4
+ orders: Order[];
5
+ }): import("react/jsx-runtime").JSX.Element;
@@ -0,0 +1,217 @@
1
+ // @bun
2
+ // src/visualizations/catalog.ts
3
+ import {
4
+ defineVisualization,
5
+ VisualizationRegistry
6
+ } from "@contractspec/lib.contracts-spec/visualizations";
7
+ var ORDER_LIST_REF = {
8
+ key: "marketplace.order.list",
9
+ version: "1.0.0"
10
+ };
11
+ var PRODUCT_LIST_REF = {
12
+ key: "marketplace.product.list",
13
+ version: "1.0.0"
14
+ };
15
+ var META = {
16
+ version: "1.0.0",
17
+ domain: "marketplace",
18
+ stability: "experimental",
19
+ owners: ["@example.marketplace"],
20
+ tags: ["marketplace", "visualization", "commerce"]
21
+ };
22
+ var MarketplaceOrderStatusVisualization = defineVisualization({
23
+ meta: {
24
+ ...META,
25
+ key: "marketplace.visualization.order-status",
26
+ title: "Order Status Breakdown",
27
+ description: "Distribution of current order states.",
28
+ goal: "Expose delivery and backlog mix at a glance.",
29
+ context: "Marketplace operations overview."
30
+ },
31
+ source: { primary: ORDER_LIST_REF, resultPath: "data" },
32
+ visualization: {
33
+ kind: "pie",
34
+ nameDimension: "status",
35
+ valueMeasure: "orders",
36
+ dimensions: [
37
+ { key: "status", label: "Status", dataPath: "status", type: "category" }
38
+ ],
39
+ measures: [
40
+ { key: "orders", label: "Orders", dataPath: "orders", format: "number" }
41
+ ],
42
+ table: { caption: "Order counts by status." }
43
+ }
44
+ });
45
+ var MarketplaceCategoryValueVisualization = defineVisualization({
46
+ meta: {
47
+ ...META,
48
+ key: "marketplace.visualization.category-value",
49
+ title: "Category Value Comparison",
50
+ description: "Catalog value by product category derived from current pricing and stock.",
51
+ goal: "Compare where the marketplace catalog is concentrated.",
52
+ context: "Merchandising overview."
53
+ },
54
+ source: { primary: PRODUCT_LIST_REF, resultPath: "data" },
55
+ visualization: {
56
+ kind: "cartesian",
57
+ variant: "bar",
58
+ xDimension: "category",
59
+ yMeasures: ["catalogValue"],
60
+ dimensions: [
61
+ {
62
+ key: "category",
63
+ label: "Category",
64
+ dataPath: "category",
65
+ type: "category"
66
+ }
67
+ ],
68
+ measures: [
69
+ {
70
+ key: "catalogValue",
71
+ label: "Catalog Value",
72
+ dataPath: "catalogValue",
73
+ format: "currency",
74
+ color: "#1d4ed8"
75
+ }
76
+ ],
77
+ table: { caption: "Catalog value by product category." }
78
+ }
79
+ });
80
+ var MarketplaceOrderActivityVisualization = defineVisualization({
81
+ meta: {
82
+ ...META,
83
+ key: "marketplace.visualization.order-activity",
84
+ title: "Recent Order Activity",
85
+ description: "Daily order volume from recent order creation timestamps.",
86
+ goal: "Show recent order activity trends.",
87
+ context: "Commerce operations trend monitoring."
88
+ },
89
+ source: { primary: ORDER_LIST_REF, resultPath: "data" },
90
+ visualization: {
91
+ kind: "cartesian",
92
+ variant: "line",
93
+ xDimension: "day",
94
+ yMeasures: ["orders"],
95
+ dimensions: [{ key: "day", label: "Day", dataPath: "day", type: "time" }],
96
+ measures: [
97
+ {
98
+ key: "orders",
99
+ label: "Orders",
100
+ dataPath: "orders",
101
+ format: "number",
102
+ color: "#0f766e"
103
+ }
104
+ ],
105
+ table: { caption: "Daily order counts." }
106
+ }
107
+ });
108
+ var MarketplaceVisualizationSpecs = [
109
+ MarketplaceOrderStatusVisualization,
110
+ MarketplaceCategoryValueVisualization,
111
+ MarketplaceOrderActivityVisualization
112
+ ];
113
+ var MarketplaceVisualizationRegistry = new VisualizationRegistry([
114
+ ...MarketplaceVisualizationSpecs
115
+ ]);
116
+ var MarketplaceVisualizationRefs = MarketplaceVisualizationSpecs.map((spec) => ({
117
+ key: spec.meta.key,
118
+ version: spec.meta.version
119
+ }));
120
+
121
+ // src/visualizations/selectors.ts
122
+ function toDayKey(value) {
123
+ const date = value instanceof Date ? value : new Date(value);
124
+ return date.toISOString().slice(0, 10);
125
+ }
126
+ function createMarketplaceVisualizationItems(products, orders) {
127
+ const orderStatus = new Map;
128
+ const orderActivity = new Map;
129
+ const categoryValue = new Map;
130
+ for (const order of orders) {
131
+ orderStatus.set(order.status, (orderStatus.get(order.status) ?? 0) + 1);
132
+ const day = toDayKey(order.createdAt);
133
+ orderActivity.set(day, (orderActivity.get(day) ?? 0) + 1);
134
+ }
135
+ for (const product of products) {
136
+ const category = product.category ?? "Uncategorized";
137
+ categoryValue.set(category, (categoryValue.get(category) ?? 0) + product.price * product.stock);
138
+ }
139
+ return [
140
+ {
141
+ key: "marketplace-order-status",
142
+ spec: MarketplaceOrderStatusVisualization,
143
+ data: {
144
+ data: Array.from(orderStatus.entries()).map(([status, count]) => ({
145
+ status,
146
+ orders: count
147
+ }))
148
+ },
149
+ title: "Order Status Breakdown",
150
+ description: "Status mix across the current order set.",
151
+ height: 260
152
+ },
153
+ {
154
+ key: "marketplace-category-value",
155
+ spec: MarketplaceCategoryValueVisualization,
156
+ data: {
157
+ data: Array.from(categoryValue.entries()).sort(([, left], [, right]) => right - left).map(([category, value]) => ({
158
+ category,
159
+ catalogValue: value
160
+ }))
161
+ },
162
+ title: "Category Value Comparison",
163
+ description: "Derived from current product pricing and stock."
164
+ },
165
+ {
166
+ key: "marketplace-order-activity",
167
+ spec: MarketplaceOrderActivityVisualization,
168
+ data: {
169
+ data: Array.from(orderActivity.entries()).sort(([left], [right]) => left.localeCompare(right)).map(([day, count]) => ({ day, orders: count }))
170
+ },
171
+ title: "Recent Order Activity",
172
+ description: "Daily order count from current order history."
173
+ }
174
+ ];
175
+ }
176
+ // src/ui/MarketplaceDashboard.visualizations.tsx
177
+ import {
178
+ VisualizationCard,
179
+ VisualizationGrid
180
+ } from "@contractspec/lib.design-system";
181
+ import { jsxDEV } from "react/jsx-dev-runtime";
182
+ "use client";
183
+ function MarketplaceVisualizationOverview({
184
+ products,
185
+ orders
186
+ }) {
187
+ const items = createMarketplaceVisualizationItems(products, orders);
188
+ return /* @__PURE__ */ jsxDEV("section", {
189
+ className: "space-y-3",
190
+ children: [
191
+ /* @__PURE__ */ jsxDEV("div", {
192
+ children: [
193
+ /* @__PURE__ */ jsxDEV("h3", {
194
+ className: "font-semibold text-lg",
195
+ children: "Commerce Visualizations"
196
+ }, undefined, false, undefined, this),
197
+ /* @__PURE__ */ jsxDEV("p", {
198
+ className: "text-muted-foreground text-sm",
199
+ children: "Order and catalog trends exposed through shared visualization contracts."
200
+ }, undefined, false, undefined, this)
201
+ ]
202
+ }, undefined, true, undefined, this),
203
+ /* @__PURE__ */ jsxDEV(VisualizationGrid, {
204
+ children: items.map((item) => /* @__PURE__ */ jsxDEV(VisualizationCard, {
205
+ data: item.data,
206
+ description: item.description,
207
+ height: item.height,
208
+ spec: item.spec,
209
+ title: item.title
210
+ }, item.key, false, undefined, this))
211
+ }, undefined, false, undefined, this)
212
+ ]
213
+ }, undefined, true, undefined, this);
214
+ }
215
+ export {
216
+ MarketplaceVisualizationOverview
217
+ };
@@ -1 +1 @@
1
- export { useMarketplaceData, type MarketplaceStats, } from './useMarketplaceData';
1
+ export { type MarketplaceStats, useMarketplaceData, } from './useMarketplaceData';
@@ -1,7 +1,7 @@
1
1
  // @bun
2
2
  // src/ui/hooks/useMarketplaceData.ts
3
- import { useCallback, useEffect, useState } from "react";
4
3
  import { useTemplateRuntime } from "@contractspec/lib.example-shared-ui";
4
+ import { useCallback, useEffect, useState } from "react";
5
5
  "use client";
6
6
  function useMarketplaceData(projectId = "local-project") {
7
7
  const { handlers } = useTemplateRuntime();
@@ -1,7 +1,7 @@
1
1
  // @bun
2
2
  // src/ui/hooks/useMarketplaceData.ts
3
- import { useCallback, useEffect, useState } from "react";
4
3
  import { useTemplateRuntime } from "@contractspec/lib.example-shared-ui";
4
+ import { useCallback, useEffect, useState } from "react";
5
5
  "use client";
6
6
  function useMarketplaceData(projectId = "local-project") {
7
7
  const { handlers } = useTemplateRuntime();
@@ -1,6 +1,6 @@
1
1
  /**
2
2
  * Marketplace Template Components
3
3
  */
4
- export * from './renderers';
5
- export { MarketplaceDashboard } from './MarketplaceDashboard';
6
4
  export * from './hooks';
5
+ export { MarketplaceDashboard } from './MarketplaceDashboard';
6
+ export * from './renderers';