@contractspec/example.crm-pipeline 1.57.0 → 1.59.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (259) hide show
  1. package/.turbo/turbo-build.log +148 -164
  2. package/.turbo/turbo-prebuild.log +1 -0
  3. package/CHANGELOG.md +39 -0
  4. package/dist/browser/crm-pipeline.feature.js +75 -0
  5. package/dist/browser/deal/deal.enum.js +18 -0
  6. package/dist/browser/deal/deal.operation.js +396 -0
  7. package/dist/browser/deal/deal.schema.js +141 -0
  8. package/dist/browser/deal/deal.test-spec.js +58 -0
  9. package/dist/browser/deal/index.js +408 -0
  10. package/dist/browser/docs/crm-pipeline.docblock.js +113 -0
  11. package/dist/browser/docs/index.js +113 -0
  12. package/dist/browser/entities/company.entity.js +52 -0
  13. package/dist/browser/entities/contact.entity.js +66 -0
  14. package/dist/browser/entities/deal.entity.js +107 -0
  15. package/dist/browser/entities/index.js +343 -0
  16. package/dist/browser/entities/task.entity.js +99 -0
  17. package/dist/browser/events/contact.event.js +31 -0
  18. package/dist/browser/events/deal.event.js +101 -0
  19. package/dist/browser/events/index.js +158 -0
  20. package/dist/browser/events/task.event.js +28 -0
  21. package/dist/browser/example.js +39 -0
  22. package/dist/browser/handlers/crm.handlers.js +160 -0
  23. package/dist/browser/handlers/deal.handlers.js +293 -0
  24. package/dist/browser/handlers/index.js +456 -0
  25. package/dist/browser/handlers/mock-data.js +165 -0
  26. package/dist/browser/index.js +3279 -0
  27. package/dist/browser/operations/index.js +407 -0
  28. package/dist/browser/presentations/dashboard.presentation.js +52 -0
  29. package/dist/browser/presentations/index.js +284 -0
  30. package/dist/browser/presentations/pipeline.presentation.js +233 -0
  31. package/dist/browser/seeders/index.js +22 -0
  32. package/dist/browser/shared/overlay-types.js +0 -0
  33. package/dist/browser/ui/CrmDashboard.js +1325 -0
  34. package/dist/browser/ui/CrmDealCard.js +50 -0
  35. package/dist/browser/ui/CrmPipelineBoard.js +160 -0
  36. package/dist/browser/ui/hooks/index.js +186 -0
  37. package/dist/browser/ui/hooks/useDealList.js +84 -0
  38. package/dist/browser/ui/hooks/useDealMutations.js +100 -0
  39. package/dist/browser/ui/index.js +1972 -0
  40. package/dist/browser/ui/modals/CreateDealModal.js +211 -0
  41. package/dist/browser/ui/modals/DealActionsModal.js +428 -0
  42. package/dist/browser/ui/modals/index.js +638 -0
  43. package/dist/browser/ui/overlays/demo-overlays.js +55 -0
  44. package/dist/browser/ui/overlays/index.js +55 -0
  45. package/dist/browser/ui/renderers/index.js +827 -0
  46. package/dist/browser/ui/renderers/pipeline.markdown.js +564 -0
  47. package/dist/browser/ui/renderers/pipeline.renderer.js +264 -0
  48. package/dist/crm-pipeline.feature.d.ts +1 -6
  49. package/dist/crm-pipeline.feature.d.ts.map +1 -1
  50. package/dist/crm-pipeline.feature.js +74 -164
  51. package/dist/deal/deal.enum.d.ts +2 -7
  52. package/dist/deal/deal.enum.d.ts.map +1 -1
  53. package/dist/deal/deal.enum.js +16 -22
  54. package/dist/deal/deal.operation.d.ts +444 -450
  55. package/dist/deal/deal.operation.d.ts.map +1 -1
  56. package/dist/deal/deal.operation.js +390 -263
  57. package/dist/deal/deal.schema.d.ts +251 -256
  58. package/dist/deal/deal.schema.d.ts.map +1 -1
  59. package/dist/deal/deal.schema.js +131 -275
  60. package/dist/deal/deal.test-spec.d.ts +2 -7
  61. package/dist/deal/deal.test-spec.d.ts.map +1 -1
  62. package/dist/deal/deal.test-spec.js +56 -62
  63. package/dist/deal/index.d.ts +7 -4
  64. package/dist/deal/index.d.ts.map +1 -0
  65. package/dist/deal/index.js +408 -4
  66. package/dist/docs/crm-pipeline.docblock.d.ts +2 -1
  67. package/dist/docs/crm-pipeline.docblock.d.ts.map +1 -0
  68. package/dist/docs/crm-pipeline.docblock.js +45 -51
  69. package/dist/docs/index.d.ts +2 -1
  70. package/dist/docs/index.d.ts.map +1 -0
  71. package/dist/docs/index.js +114 -1
  72. package/dist/entities/company.entity.d.ts +27 -32
  73. package/dist/entities/company.entity.d.ts.map +1 -1
  74. package/dist/entities/company.entity.js +51 -61
  75. package/dist/entities/contact.entity.d.ts +31 -36
  76. package/dist/entities/contact.entity.d.ts.map +1 -1
  77. package/dist/entities/contact.entity.js +65 -76
  78. package/dist/entities/deal.entity.d.ts +52 -57
  79. package/dist/entities/deal.entity.d.ts.map +1 -1
  80. package/dist/entities/deal.entity.js +104 -116
  81. package/dist/entities/index.d.ts +6 -10
  82. package/dist/entities/index.d.ts.map +1 -1
  83. package/dist/entities/index.js +342 -31
  84. package/dist/entities/task.entity.d.ts +42 -47
  85. package/dist/entities/task.entity.d.ts.map +1 -1
  86. package/dist/entities/task.entity.js +95 -124
  87. package/dist/events/contact.event.d.ts +21 -27
  88. package/dist/events/contact.event.d.ts.map +1 -1
  89. package/dist/events/contact.event.js +29 -42
  90. package/dist/events/deal.event.d.ts +100 -106
  91. package/dist/events/deal.event.d.ts.map +1 -1
  92. package/dist/events/deal.event.js +93 -163
  93. package/dist/events/index.d.ts +4 -4
  94. package/dist/events/index.d.ts.map +1 -0
  95. package/dist/events/index.js +158 -4
  96. package/dist/events/task.event.d.ts +21 -27
  97. package/dist/events/task.event.d.ts.map +1 -1
  98. package/dist/events/task.event.js +26 -42
  99. package/dist/example.d.ts +2 -6
  100. package/dist/example.d.ts.map +1 -1
  101. package/dist/example.js +38 -50
  102. package/dist/handlers/crm.handlers.d.ts +80 -78
  103. package/dist/handlers/crm.handlers.d.ts.map +1 -1
  104. package/dist/handlers/crm.handlers.js +155 -166
  105. package/dist/handlers/deal.handlers.d.ts +58 -63
  106. package/dist/handlers/deal.handlers.d.ts.map +1 -1
  107. package/dist/handlers/deal.handlers.js +279 -105
  108. package/dist/handlers/index.d.ts +10 -4
  109. package/dist/handlers/index.d.ts.map +1 -0
  110. package/dist/handlers/index.js +456 -4
  111. package/dist/handlers/mock-data.d.ts +38 -41
  112. package/dist/handlers/mock-data.d.ts.map +1 -1
  113. package/dist/handlers/mock-data.js +162 -184
  114. package/dist/index.d.ts +13 -42
  115. package/dist/index.d.ts.map +1 -1
  116. package/dist/index.js +3277 -53
  117. package/dist/node/crm-pipeline.feature.js +75 -0
  118. package/dist/node/deal/deal.enum.js +18 -0
  119. package/dist/node/deal/deal.operation.js +396 -0
  120. package/dist/node/deal/deal.schema.js +141 -0
  121. package/dist/node/deal/deal.test-spec.js +58 -0
  122. package/dist/node/deal/index.js +408 -0
  123. package/dist/node/docs/crm-pipeline.docblock.js +113 -0
  124. package/dist/node/docs/index.js +113 -0
  125. package/dist/node/entities/company.entity.js +52 -0
  126. package/dist/node/entities/contact.entity.js +66 -0
  127. package/dist/node/entities/deal.entity.js +107 -0
  128. package/dist/node/entities/index.js +343 -0
  129. package/dist/node/entities/task.entity.js +99 -0
  130. package/dist/node/events/contact.event.js +31 -0
  131. package/dist/node/events/deal.event.js +101 -0
  132. package/dist/node/events/index.js +158 -0
  133. package/dist/node/events/task.event.js +28 -0
  134. package/dist/node/example.js +39 -0
  135. package/dist/node/handlers/crm.handlers.js +160 -0
  136. package/dist/node/handlers/deal.handlers.js +293 -0
  137. package/dist/node/handlers/index.js +456 -0
  138. package/dist/node/handlers/mock-data.js +165 -0
  139. package/dist/node/index.js +3279 -0
  140. package/dist/node/operations/index.js +407 -0
  141. package/dist/node/presentations/dashboard.presentation.js +52 -0
  142. package/dist/node/presentations/index.js +284 -0
  143. package/dist/node/presentations/pipeline.presentation.js +233 -0
  144. package/dist/node/seeders/index.js +22 -0
  145. package/dist/node/shared/overlay-types.js +0 -0
  146. package/dist/node/ui/CrmDashboard.js +1325 -0
  147. package/dist/node/ui/CrmDealCard.js +50 -0
  148. package/dist/node/ui/CrmPipelineBoard.js +160 -0
  149. package/dist/node/ui/hooks/index.js +186 -0
  150. package/dist/node/ui/hooks/useDealList.js +84 -0
  151. package/dist/node/ui/hooks/useDealMutations.js +100 -0
  152. package/dist/node/ui/index.js +1972 -0
  153. package/dist/node/ui/modals/CreateDealModal.js +211 -0
  154. package/dist/node/ui/modals/DealActionsModal.js +428 -0
  155. package/dist/node/ui/modals/index.js +638 -0
  156. package/dist/node/ui/overlays/demo-overlays.js +55 -0
  157. package/dist/node/ui/overlays/index.js +55 -0
  158. package/dist/node/ui/renderers/index.js +827 -0
  159. package/dist/node/ui/renderers/pipeline.markdown.js +564 -0
  160. package/dist/node/ui/renderers/pipeline.renderer.js +264 -0
  161. package/dist/operations/index.d.ts +2 -5
  162. package/dist/operations/index.d.ts.map +1 -0
  163. package/dist/operations/index.js +407 -5
  164. package/dist/presentations/dashboard.presentation.d.ts +2 -7
  165. package/dist/presentations/dashboard.presentation.d.ts.map +1 -1
  166. package/dist/presentations/dashboard.presentation.js +51 -60
  167. package/dist/presentations/index.d.ts +3 -3
  168. package/dist/presentations/index.d.ts.map +1 -0
  169. package/dist/presentations/index.js +284 -3
  170. package/dist/presentations/pipeline.presentation.d.ts +4 -9
  171. package/dist/presentations/pipeline.presentation.d.ts.map +1 -1
  172. package/dist/presentations/pipeline.presentation.js +228 -116
  173. package/dist/seeders/index.d.ts +4 -8
  174. package/dist/seeders/index.d.ts.map +1 -1
  175. package/dist/seeders/index.js +21 -45
  176. package/dist/shared/overlay-types.d.ts +25 -28
  177. package/dist/shared/overlay-types.d.ts.map +1 -1
  178. package/dist/shared/overlay-types.js +1 -0
  179. package/dist/ui/CrmDashboard.d.ts +1 -6
  180. package/dist/ui/CrmDashboard.d.ts.map +1 -1
  181. package/dist/ui/CrmDashboard.js +1318 -296
  182. package/dist/ui/CrmDealCard.d.ts +8 -12
  183. package/dist/ui/CrmDealCard.d.ts.map +1 -1
  184. package/dist/ui/CrmDealCard.js +47 -45
  185. package/dist/ui/CrmPipelineBoard.d.ts +11 -20
  186. package/dist/ui/CrmPipelineBoard.d.ts.map +1 -1
  187. package/dist/ui/CrmPipelineBoard.js +157 -94
  188. package/dist/ui/hooks/index.d.ts +3 -3
  189. package/dist/ui/hooks/index.d.ts.map +1 -0
  190. package/dist/ui/hooks/index.js +185 -4
  191. package/dist/ui/hooks/useDealList.d.ts +28 -32
  192. package/dist/ui/hooks/useDealList.d.ts.map +1 -1
  193. package/dist/ui/hooks/useDealList.js +81 -90
  194. package/dist/ui/hooks/useDealMutations.d.ts +18 -22
  195. package/dist/ui/hooks/useDealMutations.d.ts.map +1 -1
  196. package/dist/ui/hooks/useDealMutations.js +97 -155
  197. package/dist/ui/index.d.ts +8 -14
  198. package/dist/ui/index.d.ts.map +1 -0
  199. package/dist/ui/index.js +1973 -15
  200. package/dist/ui/modals/CreateDealModal.d.ts +19 -29
  201. package/dist/ui/modals/CreateDealModal.d.ts.map +1 -1
  202. package/dist/ui/modals/CreateDealModal.js +209 -180
  203. package/dist/ui/modals/DealActionsModal.d.ts +31 -44
  204. package/dist/ui/modals/DealActionsModal.d.ts.map +1 -1
  205. package/dist/ui/modals/DealActionsModal.js +424 -367
  206. package/dist/ui/modals/index.d.ts +3 -3
  207. package/dist/ui/modals/index.d.ts.map +1 -0
  208. package/dist/ui/modals/index.js +638 -3
  209. package/dist/ui/overlays/demo-overlays.d.ts +10 -8
  210. package/dist/ui/overlays/demo-overlays.d.ts.map +1 -1
  211. package/dist/ui/overlays/demo-overlays.js +54 -66
  212. package/dist/ui/overlays/index.d.ts +2 -2
  213. package/dist/ui/overlays/index.d.ts.map +1 -0
  214. package/dist/ui/overlays/index.js +56 -3
  215. package/dist/ui/renderers/index.d.ts +3 -3
  216. package/dist/ui/renderers/index.d.ts.map +1 -0
  217. package/dist/ui/renderers/index.js +827 -3
  218. package/dist/ui/renderers/pipeline.markdown.d.ts +12 -11
  219. package/dist/ui/renderers/pipeline.markdown.d.ts.map +1 -1
  220. package/dist/ui/renderers/pipeline.markdown.js +560 -114
  221. package/dist/ui/renderers/pipeline.renderer.d.ts +9 -7
  222. package/dist/ui/renderers/pipeline.renderer.d.ts.map +1 -1
  223. package/dist/ui/renderers/pipeline.renderer.js +261 -24
  224. package/package.json +476 -90
  225. package/tsdown.config.js +1 -2
  226. package/.turbo/turbo-build$colon$bundle.log +0 -164
  227. package/dist/crm-pipeline.feature.js.map +0 -1
  228. package/dist/deal/deal.enum.js.map +0 -1
  229. package/dist/deal/deal.operation.js.map +0 -1
  230. package/dist/deal/deal.schema.js.map +0 -1
  231. package/dist/deal/deal.test-spec.js.map +0 -1
  232. package/dist/docs/crm-pipeline.docblock.js.map +0 -1
  233. package/dist/entities/company.entity.js.map +0 -1
  234. package/dist/entities/contact.entity.js.map +0 -1
  235. package/dist/entities/deal.entity.js.map +0 -1
  236. package/dist/entities/index.js.map +0 -1
  237. package/dist/entities/task.entity.js.map +0 -1
  238. package/dist/events/contact.event.js.map +0 -1
  239. package/dist/events/deal.event.js.map +0 -1
  240. package/dist/events/task.event.js.map +0 -1
  241. package/dist/example.js.map +0 -1
  242. package/dist/handlers/crm.handlers.js.map +0 -1
  243. package/dist/handlers/deal.handlers.js.map +0 -1
  244. package/dist/handlers/mock-data.js.map +0 -1
  245. package/dist/index.js.map +0 -1
  246. package/dist/presentations/dashboard.presentation.js.map +0 -1
  247. package/dist/presentations/pipeline.presentation.js.map +0 -1
  248. package/dist/seeders/index.js.map +0 -1
  249. package/dist/ui/CrmDashboard.js.map +0 -1
  250. package/dist/ui/CrmDealCard.js.map +0 -1
  251. package/dist/ui/CrmPipelineBoard.js.map +0 -1
  252. package/dist/ui/hooks/useDealList.js.map +0 -1
  253. package/dist/ui/hooks/useDealMutations.js.map +0 -1
  254. package/dist/ui/modals/CreateDealModal.js.map +0 -1
  255. package/dist/ui/modals/DealActionsModal.js.map +0 -1
  256. package/dist/ui/overlays/demo-overlays.js.map +0 -1
  257. package/dist/ui/renderers/pipeline.markdown.js.map +0 -1
  258. package/dist/ui/renderers/pipeline.renderer.js.map +0 -1
  259. package/tsconfig.tsbuildinfo +0 -1
@@ -1,4 +1,828 @@
1
- import { crmPipelineReactRenderer } from "./pipeline.renderer.js";
2
- import { crmDashboardMarkdownRenderer, crmPipelineMarkdownRenderer } from "./pipeline.markdown.js";
1
+ // @bun
2
+ // src/handlers/crm.handlers.ts
3
+ import { web } from "@contractspec/lib.runtime-sandbox";
4
+ var { generateId } = web;
5
+ function rowToDeal(row) {
6
+ return {
7
+ id: row.id,
8
+ projectId: row.projectId,
9
+ name: row.name,
10
+ value: row.value,
11
+ currency: row.currency,
12
+ pipelineId: row.pipelineId,
13
+ stageId: row.stageId,
14
+ status: row.status,
15
+ contactId: row.contactId ?? undefined,
16
+ companyId: row.companyId ?? undefined,
17
+ ownerId: row.ownerId,
18
+ expectedCloseDate: row.expectedCloseDate ? new Date(row.expectedCloseDate) : undefined,
19
+ wonSource: row.wonSource ?? undefined,
20
+ lostReason: row.lostReason ?? undefined,
21
+ notes: row.notes ?? undefined,
22
+ createdAt: new Date(row.createdAt),
23
+ updatedAt: new Date(row.updatedAt)
24
+ };
25
+ }
26
+ function createCrmHandlers(db) {
27
+ async function listDeals(input) {
28
+ const {
29
+ projectId,
30
+ pipelineId,
31
+ stageId,
32
+ status,
33
+ ownerId,
34
+ search,
35
+ limit = 20,
36
+ offset = 0
37
+ } = input;
38
+ let whereClause = "WHERE projectId = ?";
39
+ const params = [projectId];
40
+ if (pipelineId) {
41
+ whereClause += " AND pipelineId = ?";
42
+ params.push(pipelineId);
43
+ }
44
+ if (stageId) {
45
+ whereClause += " AND stageId = ?";
46
+ params.push(stageId);
47
+ }
48
+ if (status && status !== "all") {
49
+ whereClause += " AND status = ?";
50
+ params.push(status);
51
+ }
52
+ if (ownerId) {
53
+ whereClause += " AND ownerId = ?";
54
+ params.push(ownerId);
55
+ }
56
+ if (search) {
57
+ whereClause += " AND name LIKE ?";
58
+ params.push(`%${search}%`);
59
+ }
60
+ const countResult = (await db.query(`SELECT COUNT(*) as count FROM crm_deal ${whereClause}`, params)).rows;
61
+ const total = countResult[0]?.count ?? 0;
62
+ const valueResult = (await db.query(`SELECT COALESCE(SUM(value), 0) as total FROM crm_deal ${whereClause}`, params)).rows;
63
+ const totalValue = valueResult[0]?.total ?? 0;
64
+ const dealRows = (await db.query(`SELECT * FROM crm_deal ${whereClause} ORDER BY value DESC LIMIT ? OFFSET ?`, [...params, limit, offset])).rows;
65
+ return {
66
+ deals: dealRows.map(rowToDeal),
67
+ total,
68
+ totalValue
69
+ };
70
+ }
71
+ async function createDeal(input, context) {
72
+ const id = generateId("deal");
73
+ const now = new Date().toISOString();
74
+ await db.execute(`INSERT INTO crm_deal (id, projectId, pipelineId, stageId, name, value, currency, status, contactId, companyId, ownerId, expectedCloseDate, createdAt, updatedAt)
75
+ VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)`, [
76
+ id,
77
+ context.projectId,
78
+ input.pipelineId,
79
+ input.stageId,
80
+ input.name,
81
+ input.value,
82
+ input.currency ?? "USD",
83
+ "OPEN",
84
+ input.contactId ?? null,
85
+ input.companyId ?? null,
86
+ context.ownerId,
87
+ input.expectedCloseDate?.toISOString() ?? null,
88
+ now,
89
+ now
90
+ ]);
91
+ const rows = (await db.query(`SELECT * FROM crm_deal WHERE id = ?`, [id])).rows;
92
+ if (!rows[0]) {
93
+ throw new Error("Failed to create deal");
94
+ }
95
+ return rowToDeal(rows[0]);
96
+ }
97
+ async function moveDeal(input) {
98
+ const now = new Date().toISOString();
99
+ const existing = (await db.query(`SELECT * FROM crm_deal WHERE id = ?`, [input.dealId])).rows;
100
+ if (!existing[0]) {
101
+ throw new Error("NOT_FOUND");
102
+ }
103
+ const stage = (await db.query(`SELECT * FROM crm_stage WHERE id = ?`, [input.stageId])).rows;
104
+ if (!stage[0]) {
105
+ throw new Error("INVALID_STAGE");
106
+ }
107
+ await db.execute(`UPDATE crm_deal SET stageId = ?, updatedAt = ? WHERE id = ?`, [input.stageId, now, input.dealId]);
108
+ const rows = (await db.query(`SELECT * FROM crm_deal WHERE id = ?`, [input.dealId])).rows;
109
+ return rowToDeal(rows[0]);
110
+ }
111
+ async function winDeal(input) {
112
+ const now = new Date().toISOString();
113
+ const existing = (await db.query(`SELECT * FROM crm_deal WHERE id = ?`, [input.dealId])).rows;
114
+ if (!existing[0]) {
115
+ throw new Error("NOT_FOUND");
116
+ }
117
+ await db.execute(`UPDATE crm_deal SET status = 'WON', wonSource = ?, notes = ?, updatedAt = ? WHERE id = ?`, [input.wonSource ?? null, input.notes ?? null, now, input.dealId]);
118
+ const rows = (await db.query(`SELECT * FROM crm_deal WHERE id = ?`, [input.dealId])).rows;
119
+ return rowToDeal(rows[0]);
120
+ }
121
+ async function loseDeal(input) {
122
+ const now = new Date().toISOString();
123
+ const existing = (await db.query(`SELECT * FROM crm_deal WHERE id = ?`, [input.dealId])).rows;
124
+ if (!existing[0]) {
125
+ throw new Error("NOT_FOUND");
126
+ }
127
+ await db.execute(`UPDATE crm_deal SET status = 'LOST', lostReason = ?, notes = ?, updatedAt = ? WHERE id = ?`, [input.lostReason, input.notes ?? null, now, input.dealId]);
128
+ const rows = (await db.query(`SELECT * FROM crm_deal WHERE id = ?`, [input.dealId])).rows;
129
+ return rowToDeal(rows[0]);
130
+ }
131
+ async function getDealsByStage(input) {
132
+ const deals = (await db.query(`SELECT * FROM crm_deal WHERE projectId = ? AND pipelineId = ? AND status = 'OPEN' ORDER BY value DESC`, [input.projectId, input.pipelineId])).rows;
133
+ const stages = (await db.query(`SELECT * FROM crm_stage WHERE pipelineId = ? ORDER BY position`, [input.pipelineId])).rows;
134
+ const grouped = {};
135
+ for (const stage of stages) {
136
+ grouped[stage.id] = deals.filter((d) => d.stageId === stage.id).map(rowToDeal);
137
+ }
138
+ return grouped;
139
+ }
140
+ async function getPipelineStages(input) {
141
+ const rows = (await db.query(`SELECT * FROM crm_stage WHERE pipelineId = ? ORDER BY position`, [input.pipelineId])).rows;
142
+ return rows.map((row) => ({
143
+ id: row.id,
144
+ pipelineId: row.pipelineId,
145
+ name: row.name,
146
+ position: row.position
147
+ }));
148
+ }
149
+ return {
150
+ listDeals,
151
+ createDeal,
152
+ moveDeal,
153
+ winDeal,
154
+ loseDeal,
155
+ getDealsByStage,
156
+ getPipelineStages
157
+ };
158
+ }
3
159
 
4
- export { crmDashboardMarkdownRenderer, crmPipelineMarkdownRenderer, crmPipelineReactRenderer };
160
+ // src/handlers/mock-data.ts
161
+ var MOCK_STAGES = [
162
+ { id: "stage-1", name: "Lead", position: 1, pipelineId: "pipeline-1" },
163
+ { id: "stage-2", name: "Qualified", position: 2, pipelineId: "pipeline-1" },
164
+ { id: "stage-3", name: "Proposal", position: 3, pipelineId: "pipeline-1" },
165
+ { id: "stage-4", name: "Negotiation", position: 4, pipelineId: "pipeline-1" },
166
+ { id: "stage-5", name: "Closed", position: 5, pipelineId: "pipeline-1" }
167
+ ];
168
+ var MOCK_DEALS = [
169
+ {
170
+ id: "deal-1",
171
+ name: "Enterprise License - Acme Corp",
172
+ value: 75000,
173
+ currency: "USD",
174
+ pipelineId: "pipeline-1",
175
+ stageId: "stage-3",
176
+ status: "OPEN",
177
+ contactId: "contact-1",
178
+ companyId: "company-1",
179
+ ownerId: "user-1",
180
+ expectedCloseDate: new Date("2024-05-15T00:00:00Z"),
181
+ createdAt: new Date("2024-02-01T10:00:00Z"),
182
+ updatedAt: new Date("2024-04-10T14:30:00Z")
183
+ },
184
+ {
185
+ id: "deal-2",
186
+ name: "Startup Plan - TechStart Inc",
187
+ value: 12000,
188
+ currency: "USD",
189
+ pipelineId: "pipeline-1",
190
+ stageId: "stage-2",
191
+ status: "OPEN",
192
+ contactId: "contact-2",
193
+ companyId: "company-2",
194
+ ownerId: "user-2",
195
+ expectedCloseDate: new Date("2024-04-30T00:00:00Z"),
196
+ createdAt: new Date("2024-03-15T09:00:00Z"),
197
+ updatedAt: new Date("2024-04-08T11:15:00Z")
198
+ },
199
+ {
200
+ id: "deal-3",
201
+ name: "Professional Services - Global Ltd",
202
+ value: 45000,
203
+ currency: "USD",
204
+ pipelineId: "pipeline-1",
205
+ stageId: "stage-4",
206
+ status: "OPEN",
207
+ contactId: "contact-3",
208
+ companyId: "company-3",
209
+ ownerId: "user-1",
210
+ expectedCloseDate: new Date("2024-04-20T00:00:00Z"),
211
+ createdAt: new Date("2024-01-20T08:00:00Z"),
212
+ updatedAt: new Date("2024-04-12T16:45:00Z")
213
+ },
214
+ {
215
+ id: "deal-4",
216
+ name: "Annual Contract - SmallBiz Co",
217
+ value: 8500,
218
+ currency: "USD",
219
+ pipelineId: "pipeline-1",
220
+ stageId: "stage-1",
221
+ status: "OPEN",
222
+ contactId: "contact-4",
223
+ companyId: "company-4",
224
+ ownerId: "user-3",
225
+ createdAt: new Date("2024-04-05T12:00:00Z"),
226
+ updatedAt: new Date("2024-04-05T12:00:00Z")
227
+ },
228
+ {
229
+ id: "deal-5",
230
+ name: "Custom Integration - MegaCorp",
231
+ value: 125000,
232
+ currency: "USD",
233
+ pipelineId: "pipeline-1",
234
+ stageId: "stage-5",
235
+ status: "WON",
236
+ contactId: "contact-5",
237
+ companyId: "company-5",
238
+ ownerId: "user-1",
239
+ expectedCloseDate: new Date("2024-03-31T00:00:00Z"),
240
+ createdAt: new Date("2023-11-10T10:00:00Z"),
241
+ updatedAt: new Date("2024-03-28T09:00:00Z")
242
+ },
243
+ {
244
+ id: "deal-6",
245
+ name: "Pilot Project - NewCo",
246
+ value: 5000,
247
+ currency: "USD",
248
+ pipelineId: "pipeline-1",
249
+ stageId: "stage-2",
250
+ status: "LOST",
251
+ contactId: "contact-6",
252
+ companyId: "company-6",
253
+ ownerId: "user-2",
254
+ createdAt: new Date("2024-01-15T14:00:00Z"),
255
+ updatedAt: new Date("2024-02-28T10:30:00Z")
256
+ }
257
+ ];
258
+ var MOCK_COMPANIES = [
259
+ {
260
+ id: "company-1",
261
+ name: "Acme Corporation",
262
+ domain: "acme.com",
263
+ industry: "Technology",
264
+ size: "1000-5000",
265
+ website: "https://acme.com",
266
+ createdAt: new Date("2024-01-01T00:00:00Z")
267
+ },
268
+ {
269
+ id: "company-2",
270
+ name: "TechStart Inc",
271
+ domain: "techstart.io",
272
+ industry: "Software",
273
+ size: "10-50",
274
+ website: "https://techstart.io",
275
+ createdAt: new Date("2024-02-15T00:00:00Z")
276
+ },
277
+ {
278
+ id: "company-3",
279
+ name: "Global Ltd",
280
+ domain: "global.com",
281
+ industry: "Consulting",
282
+ size: "500-1000",
283
+ website: "https://global.com",
284
+ createdAt: new Date("2023-12-01T00:00:00Z")
285
+ }
286
+ ];
287
+ var MOCK_CONTACTS = [
288
+ {
289
+ id: "contact-1",
290
+ firstName: "John",
291
+ lastName: "Smith",
292
+ email: "john.smith@acme.com",
293
+ phone: "+1-555-0101",
294
+ title: "VP of Engineering",
295
+ companyId: "company-1",
296
+ createdAt: new Date("2024-01-05T00:00:00Z")
297
+ },
298
+ {
299
+ id: "contact-2",
300
+ firstName: "Sarah",
301
+ lastName: "Johnson",
302
+ email: "sarah@techstart.io",
303
+ phone: "+1-555-0102",
304
+ title: "CEO",
305
+ companyId: "company-2",
306
+ createdAt: new Date("2024-02-20T00:00:00Z")
307
+ },
308
+ {
309
+ id: "contact-3",
310
+ firstName: "Michael",
311
+ lastName: "Brown",
312
+ email: "michael.brown@global.com",
313
+ phone: "+1-555-0103",
314
+ title: "CTO",
315
+ companyId: "company-3",
316
+ createdAt: new Date("2023-12-10T00:00:00Z")
317
+ }
318
+ ];
319
+
320
+ // src/handlers/deal.handlers.ts
321
+ async function mockListDealsHandler(input) {
322
+ const {
323
+ pipelineId,
324
+ stageId,
325
+ status,
326
+ ownerId,
327
+ search,
328
+ limit = 20,
329
+ offset = 0
330
+ } = input;
331
+ let filtered = [...MOCK_DEALS];
332
+ if (pipelineId) {
333
+ filtered = filtered.filter((d) => d.pipelineId === pipelineId);
334
+ }
335
+ if (stageId) {
336
+ filtered = filtered.filter((d) => d.stageId === stageId);
337
+ }
338
+ if (status && status !== "all") {
339
+ filtered = filtered.filter((d) => d.status === status);
340
+ }
341
+ if (ownerId) {
342
+ filtered = filtered.filter((d) => d.ownerId === ownerId);
343
+ }
344
+ if (search) {
345
+ const q = search.toLowerCase();
346
+ filtered = filtered.filter((d) => d.name.toLowerCase().includes(q));
347
+ }
348
+ filtered.sort((a, b) => b.value - a.value);
349
+ const total = filtered.length;
350
+ const totalValue = filtered.reduce((sum, d) => sum + d.value, 0);
351
+ const deals = filtered.slice(offset, offset + limit);
352
+ return {
353
+ deals,
354
+ total,
355
+ totalValue
356
+ };
357
+ }
358
+ async function mockCreateDealHandler(input, context) {
359
+ const now = new Date;
360
+ const deal = {
361
+ id: `deal-${Date.now()}`,
362
+ name: input.name,
363
+ value: input.value,
364
+ currency: input.currency ?? "USD",
365
+ pipelineId: input.pipelineId,
366
+ stageId: input.stageId,
367
+ status: "OPEN",
368
+ contactId: input.contactId,
369
+ companyId: input.companyId,
370
+ ownerId: context.ownerId,
371
+ expectedCloseDate: input.expectedCloseDate,
372
+ createdAt: now,
373
+ updatedAt: now
374
+ };
375
+ MOCK_DEALS.push(deal);
376
+ return deal;
377
+ }
378
+ async function mockMoveDealHandler(input) {
379
+ const dealIndex = MOCK_DEALS.findIndex((d) => d.id === input.dealId);
380
+ if (dealIndex === -1) {
381
+ throw new Error("NOT_FOUND");
382
+ }
383
+ const deal = MOCK_DEALS[dealIndex];
384
+ if (!deal) {
385
+ throw new Error("NOT_FOUND");
386
+ }
387
+ const stage = MOCK_STAGES.find((s) => s.id === input.stageId);
388
+ if (!stage) {
389
+ throw new Error("INVALID_STAGE");
390
+ }
391
+ const updatedDeal = {
392
+ ...deal,
393
+ stageId: input.stageId,
394
+ updatedAt: new Date
395
+ };
396
+ MOCK_DEALS[dealIndex] = updatedDeal;
397
+ return updatedDeal;
398
+ }
399
+ async function mockWinDealHandler(input) {
400
+ const dealIndex = MOCK_DEALS.findIndex((d) => d.id === input.dealId);
401
+ if (dealIndex === -1) {
402
+ throw new Error("NOT_FOUND");
403
+ }
404
+ const deal = MOCK_DEALS[dealIndex];
405
+ if (!deal) {
406
+ throw new Error("NOT_FOUND");
407
+ }
408
+ const updatedDeal = {
409
+ ...deal,
410
+ status: "WON",
411
+ updatedAt: new Date
412
+ };
413
+ MOCK_DEALS[dealIndex] = updatedDeal;
414
+ return updatedDeal;
415
+ }
416
+ async function mockLoseDealHandler(input) {
417
+ const dealIndex = MOCK_DEALS.findIndex((d) => d.id === input.dealId);
418
+ if (dealIndex === -1) {
419
+ throw new Error("NOT_FOUND");
420
+ }
421
+ const deal = MOCK_DEALS[dealIndex];
422
+ if (!deal) {
423
+ throw new Error("NOT_FOUND");
424
+ }
425
+ const updatedDeal = {
426
+ ...deal,
427
+ status: "LOST",
428
+ updatedAt: new Date
429
+ };
430
+ MOCK_DEALS[dealIndex] = updatedDeal;
431
+ return updatedDeal;
432
+ }
433
+ async function mockGetDealsByStageHandler(input) {
434
+ const deals = MOCK_DEALS.filter((d) => d.pipelineId === input.pipelineId && d.status === "OPEN");
435
+ const grouped = {};
436
+ for (const stage of MOCK_STAGES) {
437
+ grouped[stage.id] = deals.filter((d) => d.stageId === stage.id);
438
+ }
439
+ return grouped;
440
+ }
441
+ async function mockGetPipelineStagesHandler(input) {
442
+ return MOCK_STAGES.filter((s) => s.pipelineId === input.pipelineId);
443
+ }
444
+ // src/ui/hooks/useDealList.ts
445
+ import { useCallback, useEffect, useMemo, useState } from "react";
446
+ import { useTemplateRuntime } from "@contractspec/lib.example-shared-ui";
447
+ "use client";
448
+ function useDealList(options = {}) {
449
+ const { handlers, projectId } = useTemplateRuntime();
450
+ const { crm: crm2 } = handlers;
451
+ const [data, setData] = useState(null);
452
+ const [dealsByStage, setDealsByStage] = useState({});
453
+ const [stages, setStages] = useState([]);
454
+ const [loading, setLoading] = useState(true);
455
+ const [error, setError] = useState(null);
456
+ const [page, setPage] = useState(1);
457
+ const pipelineId = options.pipelineId ?? "pipeline-1";
458
+ const fetchData = useCallback(async () => {
459
+ setLoading(true);
460
+ setError(null);
461
+ try {
462
+ const [dealsResult, stageDealsResult, stagesResult] = await Promise.all([
463
+ crm2.listDeals({
464
+ projectId,
465
+ pipelineId,
466
+ stageId: options.stageId,
467
+ status: options.status === "all" ? undefined : options.status,
468
+ search: options.search,
469
+ limit: options.limit ?? 50,
470
+ offset: (page - 1) * (options.limit ?? 50)
471
+ }),
472
+ crm2.getDealsByStage({ projectId, pipelineId }),
473
+ crm2.getPipelineStages({ pipelineId })
474
+ ]);
475
+ setData(dealsResult);
476
+ setDealsByStage(stageDealsResult);
477
+ setStages(stagesResult);
478
+ } catch (err) {
479
+ setError(err instanceof Error ? err : new Error("Unknown error"));
480
+ } finally {
481
+ setLoading(false);
482
+ }
483
+ }, [
484
+ crm2,
485
+ projectId,
486
+ pipelineId,
487
+ options.stageId,
488
+ options.status,
489
+ options.search,
490
+ options.limit,
491
+ page
492
+ ]);
493
+ useEffect(() => {
494
+ fetchData();
495
+ }, [fetchData]);
496
+ const stats = useMemo(() => {
497
+ if (!data)
498
+ return null;
499
+ const open = data.deals.filter((d) => d.status === "OPEN");
500
+ const won = data.deals.filter((d) => d.status === "WON");
501
+ const lost = data.deals.filter((d) => d.status === "LOST");
502
+ return {
503
+ total: data.total,
504
+ totalValue: data.totalValue,
505
+ openCount: open.length,
506
+ openValue: open.reduce((sum, d) => sum + d.value, 0),
507
+ wonCount: won.length,
508
+ wonValue: won.reduce((sum, d) => sum + d.value, 0),
509
+ lostCount: lost.length
510
+ };
511
+ }, [data]);
512
+ return {
513
+ data,
514
+ dealsByStage,
515
+ stages,
516
+ loading,
517
+ error,
518
+ stats,
519
+ page,
520
+ refetch: fetchData,
521
+ nextPage: () => setPage((p) => p + 1),
522
+ prevPage: () => page > 1 && setPage((p) => p - 1)
523
+ };
524
+ }
525
+
526
+ // src/ui/CrmDealCard.tsx
527
+ import { jsxDEV } from "react/jsx-dev-runtime";
528
+ "use client";
529
+ function formatCurrency(value, currency) {
530
+ return new Intl.NumberFormat("en-US", {
531
+ style: "currency",
532
+ currency,
533
+ minimumFractionDigits: 0,
534
+ maximumFractionDigits: 0
535
+ }).format(value);
536
+ }
537
+ function CrmDealCard({ deal, onClick }) {
538
+ const daysUntilClose = deal.expectedCloseDate ? Math.ceil((deal.expectedCloseDate.getTime() - Date.now()) / (1000 * 60 * 60 * 24)) : null;
539
+ return /* @__PURE__ */ jsxDEV("div", {
540
+ onClick,
541
+ className: "border-border bg-card cursor-pointer rounded-lg border p-3 shadow-sm transition-shadow hover:shadow-md",
542
+ role: "button",
543
+ tabIndex: 0,
544
+ onKeyDown: (e) => {
545
+ if (e.key === "Enter" || e.key === " ")
546
+ onClick?.();
547
+ },
548
+ children: [
549
+ /* @__PURE__ */ jsxDEV("h4", {
550
+ className: "leading-snug font-medium",
551
+ children: deal.name
552
+ }, undefined, false, undefined, this),
553
+ /* @__PURE__ */ jsxDEV("div", {
554
+ className: "text-primary mt-2 text-lg font-semibold",
555
+ children: formatCurrency(deal.value, deal.currency)
556
+ }, undefined, false, undefined, this),
557
+ /* @__PURE__ */ jsxDEV("div", {
558
+ className: "text-muted-foreground mt-3 flex items-center justify-between text-xs",
559
+ children: [
560
+ daysUntilClose !== null && /* @__PURE__ */ jsxDEV("span", {
561
+ className: daysUntilClose < 0 ? "text-red-500" : daysUntilClose <= 7 ? "text-yellow-600 dark:text-yellow-500" : "",
562
+ children: daysUntilClose < 0 ? `${Math.abs(daysUntilClose)}d overdue` : daysUntilClose === 0 ? "Due today" : `${daysUntilClose}d left`
563
+ }, undefined, false, undefined, this),
564
+ /* @__PURE__ */ jsxDEV("span", {
565
+ className: `rounded px-1.5 py-0.5 text-xs font-medium ${deal.status === "WON" ? "bg-green-100 text-green-700 dark:bg-green-900/30 dark:text-green-400" : deal.status === "LOST" ? "bg-red-100 text-red-700 dark:bg-red-900/30 dark:text-red-400" : "bg-blue-100 text-blue-700 dark:bg-blue-900/30 dark:text-blue-400"}`,
566
+ children: deal.status
567
+ }, undefined, false, undefined, this)
568
+ ]
569
+ }, undefined, true, undefined, this)
570
+ ]
571
+ }, undefined, true, undefined, this);
572
+ }
573
+
574
+ // src/ui/CrmPipelineBoard.tsx
575
+ import { useState as useState2 } from "react";
576
+ import { jsxDEV as jsxDEV2 } from "react/jsx-dev-runtime";
577
+ "use client";
578
+ function formatCurrency2(value) {
579
+ if (value >= 1e6)
580
+ return `$${(value / 1e6).toFixed(1)}M`;
581
+ if (value >= 1000)
582
+ return `$${(value / 1000).toFixed(0)}K`;
583
+ return `$${value}`;
584
+ }
585
+ function CrmPipelineBoard({
586
+ dealsByStage,
587
+ stages,
588
+ onDealClick,
589
+ onDealMove
590
+ }) {
591
+ const [quickMoveOpen, setQuickMoveOpen] = useState2(null);
592
+ const sortedStages = [...stages].sort((a, b) => a.position - b.position);
593
+ const handleQuickMove = (dealId, toStageId) => {
594
+ onDealMove?.(dealId, toStageId);
595
+ setQuickMoveOpen(null);
596
+ };
597
+ return /* @__PURE__ */ jsxDEV2("div", {
598
+ className: "flex gap-4 overflow-x-auto pb-4",
599
+ children: sortedStages.map((stage) => {
600
+ const deals = dealsByStage[stage.id] ?? [];
601
+ const stageValue = deals.reduce((sum, d) => sum + d.value, 0);
602
+ return /* @__PURE__ */ jsxDEV2("div", {
603
+ className: "bg-muted/30 flex w-72 flex-shrink-0 flex-col rounded-lg",
604
+ children: [
605
+ /* @__PURE__ */ jsxDEV2("div", {
606
+ className: "border-border flex items-center justify-between border-b px-3 py-2",
607
+ children: [
608
+ /* @__PURE__ */ jsxDEV2("div", {
609
+ children: [
610
+ /* @__PURE__ */ jsxDEV2("h3", {
611
+ className: "font-medium",
612
+ children: stage.name
613
+ }, undefined, false, undefined, this),
614
+ /* @__PURE__ */ jsxDEV2("p", {
615
+ className: "text-muted-foreground text-xs",
616
+ children: [
617
+ deals.length,
618
+ " deals \xB7 ",
619
+ formatCurrency2(stageValue)
620
+ ]
621
+ }, undefined, true, undefined, this)
622
+ ]
623
+ }, undefined, true, undefined, this),
624
+ /* @__PURE__ */ jsxDEV2("span", {
625
+ className: "bg-muted flex h-6 w-6 items-center justify-center rounded-full text-xs font-medium",
626
+ children: deals.length
627
+ }, undefined, false, undefined, this)
628
+ ]
629
+ }, undefined, true, undefined, this),
630
+ /* @__PURE__ */ jsxDEV2("div", {
631
+ className: "flex flex-1 flex-col gap-2 p-2",
632
+ children: deals.length === 0 ? /* @__PURE__ */ jsxDEV2("div", {
633
+ className: "border-muted-foreground/20 text-muted-foreground flex h-24 items-center justify-center rounded-md border-2 border-dashed text-xs",
634
+ children: "No deals"
635
+ }, undefined, false, undefined, this) : deals.map((deal) => /* @__PURE__ */ jsxDEV2("div", {
636
+ className: "group relative",
637
+ children: [
638
+ /* @__PURE__ */ jsxDEV2(CrmDealCard, {
639
+ deal,
640
+ onClick: () => onDealClick?.(deal.id)
641
+ }, undefined, false, undefined, this),
642
+ deal.status === "OPEN" && onDealMove && /* @__PURE__ */ jsxDEV2("div", {
643
+ className: "absolute top-1 right-1 opacity-0 transition-opacity group-hover:opacity-100",
644
+ children: [
645
+ /* @__PURE__ */ jsxDEV2("button", {
646
+ type: "button",
647
+ onClick: (e) => {
648
+ e.stopPropagation();
649
+ setQuickMoveOpen(quickMoveOpen === deal.id ? null : deal.id);
650
+ },
651
+ className: "bg-background border-border hover:bg-muted flex h-6 w-6 items-center justify-center rounded border text-xs shadow-sm",
652
+ title: "Quick move",
653
+ children: "\u27A1\uFE0F"
654
+ }, undefined, false, undefined, this),
655
+ quickMoveOpen === deal.id && /* @__PURE__ */ jsxDEV2("div", {
656
+ className: "bg-card border-border absolute top-7 right-0 z-20 min-w-[140px] rounded-lg border py-1 shadow-lg",
657
+ children: [
658
+ /* @__PURE__ */ jsxDEV2("p", {
659
+ className: "text-muted-foreground px-3 py-1 text-xs font-medium",
660
+ children: "Move to:"
661
+ }, undefined, false, undefined, this),
662
+ sortedStages.filter((s) => s.id !== deal.stageId).map((s) => /* @__PURE__ */ jsxDEV2("button", {
663
+ type: "button",
664
+ onClick: (e) => {
665
+ e.stopPropagation();
666
+ handleQuickMove(deal.id, s.id);
667
+ },
668
+ className: "hover:bg-muted w-full px-3 py-1.5 text-left text-sm",
669
+ children: s.name
670
+ }, s.id, false, undefined, this))
671
+ ]
672
+ }, undefined, true, undefined, this)
673
+ ]
674
+ }, undefined, true, undefined, this)
675
+ ]
676
+ }, deal.id, true, undefined, this))
677
+ }, undefined, false, undefined, this)
678
+ ]
679
+ }, stage.id, true, undefined, this);
680
+ })
681
+ }, undefined, false, undefined, this);
682
+ }
683
+
684
+ // src/ui/renderers/pipeline.renderer.tsx
685
+ import { jsxDEV as jsxDEV3 } from "react/jsx-dev-runtime";
686
+ function CrmPipelineBoardWrapper() {
687
+ const { dealsByStage, stages } = useDealList();
688
+ return /* @__PURE__ */ jsxDEV3(CrmPipelineBoard, {
689
+ dealsByStage,
690
+ stages
691
+ }, undefined, false, undefined, this);
692
+ }
693
+ var crmPipelineReactRenderer = {
694
+ target: "react",
695
+ render: async (desc, _ctx) => {
696
+ if (desc.source.type !== "component") {
697
+ throw new Error("Invalid source type");
698
+ }
699
+ if (desc.source.componentKey !== "CrmPipelineView") {
700
+ throw new Error(`Unknown component: ${desc.source.componentKey}`);
701
+ }
702
+ return /* @__PURE__ */ jsxDEV3(CrmPipelineBoardWrapper, {}, undefined, false, undefined, this);
703
+ }
704
+ };
705
+
706
+ // src/ui/renderers/pipeline.markdown.ts
707
+ function formatCurrency3(value, currency = "USD") {
708
+ return new Intl.NumberFormat("en-US", {
709
+ style: "currency",
710
+ currency,
711
+ minimumFractionDigits: 0
712
+ }).format(value);
713
+ }
714
+ var crmPipelineMarkdownRenderer = {
715
+ target: "markdown",
716
+ render: async (desc, _ctx) => {
717
+ if (desc.source.type !== "component" || desc.source.componentKey !== "PipelineKanbanView") {
718
+ throw new Error("crmPipelineMarkdownRenderer: not PipelineKanbanView");
719
+ }
720
+ const pipelineId = "pipeline-1";
721
+ const [dealsResult, stages] = await Promise.all([
722
+ mockListDealsHandler({ pipelineId, limit: 50 }),
723
+ mockGetPipelineStagesHandler({ pipelineId })
724
+ ]);
725
+ const deals = dealsResult.deals;
726
+ const stageList = stages;
727
+ const dealsByStage = {};
728
+ for (const stage of stageList) {
729
+ dealsByStage[stage.id] = deals.filter((d) => d.stageId === stage.id && d.status === "OPEN");
730
+ }
731
+ const lines = [
732
+ "# CRM Pipeline",
733
+ "",
734
+ `**Total Value**: ${formatCurrency3(dealsResult.totalValue)}`,
735
+ `**Total Deals**: ${dealsResult.total}`,
736
+ ""
737
+ ];
738
+ for (const stage of stageList.sort((a, b) => a.position - b.position)) {
739
+ const stageDeals = dealsByStage[stage.id] ?? [];
740
+ const stageValue = stageDeals.reduce((sum, d) => sum + d.value, 0);
741
+ lines.push(`## ${stage.name}`);
742
+ lines.push(`_${stageDeals.length} deals \xB7 ${formatCurrency3(stageValue)}_`);
743
+ lines.push("");
744
+ if (stageDeals.length === 0) {
745
+ lines.push("_No deals_");
746
+ } else {
747
+ for (const deal of stageDeals) {
748
+ lines.push(`- **${deal.name}** - ${formatCurrency3(deal.value, deal.currency)}`);
749
+ }
750
+ }
751
+ lines.push("");
752
+ }
753
+ return {
754
+ mimeType: "text/markdown",
755
+ body: lines.join(`
756
+ `)
757
+ };
758
+ }
759
+ };
760
+ var crmDashboardMarkdownRenderer = {
761
+ target: "markdown",
762
+ render: async (desc, _ctx) => {
763
+ if (desc.source.type !== "component" || desc.source.componentKey !== "CrmDashboard") {
764
+ throw new Error("crmDashboardMarkdownRenderer: not CrmDashboard");
765
+ }
766
+ const pipelineId = "pipeline-1";
767
+ const [dealsResult, stages] = await Promise.all([
768
+ mockListDealsHandler({ pipelineId, limit: 100 }),
769
+ mockGetPipelineStagesHandler({ pipelineId })
770
+ ]);
771
+ const deals = dealsResult.deals;
772
+ const stageList = stages;
773
+ const openDeals = deals.filter((d) => d.status === "OPEN");
774
+ const wonDeals = deals.filter((d) => d.status === "WON");
775
+ const lostDeals = deals.filter((d) => d.status === "LOST");
776
+ const openValue = openDeals.reduce((sum, d) => sum + d.value, 0);
777
+ const wonValue = wonDeals.reduce((sum, d) => sum + d.value, 0);
778
+ const lines = [
779
+ "# CRM Dashboard",
780
+ "",
781
+ "> Sales pipeline overview and key metrics",
782
+ "",
783
+ "## Summary",
784
+ "",
785
+ "| Metric | Value |",
786
+ "|--------|-------|",
787
+ `| Total Deals | ${dealsResult.total} |`,
788
+ `| Pipeline Value | ${formatCurrency3(dealsResult.totalValue)} |`,
789
+ `| Open Deals | ${openDeals.length} (${formatCurrency3(openValue)}) |`,
790
+ `| Won Deals | ${wonDeals.length} (${formatCurrency3(wonValue)}) |`,
791
+ `| Lost Deals | ${lostDeals.length} |`,
792
+ "",
793
+ "## Pipeline Stages",
794
+ ""
795
+ ];
796
+ lines.push("| Stage | Deals | Value |");
797
+ lines.push("|-------|-------|-------|");
798
+ for (const stage of stageList.sort((a, b) => a.position - b.position)) {
799
+ const stageDeals = openDeals.filter((d) => d.stageId === stage.id);
800
+ const stageValue = stageDeals.reduce((sum, d) => sum + d.value, 0);
801
+ lines.push(`| ${stage.name} | ${stageDeals.length} | ${formatCurrency3(stageValue)} |`);
802
+ }
803
+ lines.push("");
804
+ lines.push("## Recent Deals");
805
+ lines.push("");
806
+ const recentDeals = deals.slice(0, 10);
807
+ if (recentDeals.length === 0) {
808
+ lines.push("_No deals yet._");
809
+ } else {
810
+ lines.push("| Deal | Value | Stage | Status |");
811
+ lines.push("|------|-------|-------|--------|");
812
+ for (const deal of recentDeals) {
813
+ const stage = stageList.find((s) => s.id === deal.stageId);
814
+ lines.push(`| ${deal.name} | ${formatCurrency3(deal.value, deal.currency)} | ${stage?.name ?? "-"} | ${deal.status} |`);
815
+ }
816
+ }
817
+ return {
818
+ mimeType: "text/markdown",
819
+ body: lines.join(`
820
+ `)
821
+ };
822
+ }
823
+ };
824
+ export {
825
+ crmPipelineReactRenderer,
826
+ crmPipelineMarkdownRenderer,
827
+ crmDashboardMarkdownRenderer
828
+ };