@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.
- package/.turbo/turbo-build.log +148 -164
- package/.turbo/turbo-prebuild.log +1 -0
- package/CHANGELOG.md +39 -0
- package/dist/browser/crm-pipeline.feature.js +75 -0
- package/dist/browser/deal/deal.enum.js +18 -0
- package/dist/browser/deal/deal.operation.js +396 -0
- package/dist/browser/deal/deal.schema.js +141 -0
- package/dist/browser/deal/deal.test-spec.js +58 -0
- package/dist/browser/deal/index.js +408 -0
- package/dist/browser/docs/crm-pipeline.docblock.js +113 -0
- package/dist/browser/docs/index.js +113 -0
- package/dist/browser/entities/company.entity.js +52 -0
- package/dist/browser/entities/contact.entity.js +66 -0
- package/dist/browser/entities/deal.entity.js +107 -0
- package/dist/browser/entities/index.js +343 -0
- package/dist/browser/entities/task.entity.js +99 -0
- package/dist/browser/events/contact.event.js +31 -0
- package/dist/browser/events/deal.event.js +101 -0
- package/dist/browser/events/index.js +158 -0
- package/dist/browser/events/task.event.js +28 -0
- package/dist/browser/example.js +39 -0
- package/dist/browser/handlers/crm.handlers.js +160 -0
- package/dist/browser/handlers/deal.handlers.js +293 -0
- package/dist/browser/handlers/index.js +456 -0
- package/dist/browser/handlers/mock-data.js +165 -0
- package/dist/browser/index.js +3279 -0
- package/dist/browser/operations/index.js +407 -0
- package/dist/browser/presentations/dashboard.presentation.js +52 -0
- package/dist/browser/presentations/index.js +284 -0
- package/dist/browser/presentations/pipeline.presentation.js +233 -0
- package/dist/browser/seeders/index.js +22 -0
- package/dist/browser/shared/overlay-types.js +0 -0
- package/dist/browser/ui/CrmDashboard.js +1325 -0
- package/dist/browser/ui/CrmDealCard.js +50 -0
- package/dist/browser/ui/CrmPipelineBoard.js +160 -0
- package/dist/browser/ui/hooks/index.js +186 -0
- package/dist/browser/ui/hooks/useDealList.js +84 -0
- package/dist/browser/ui/hooks/useDealMutations.js +100 -0
- package/dist/browser/ui/index.js +1972 -0
- package/dist/browser/ui/modals/CreateDealModal.js +211 -0
- package/dist/browser/ui/modals/DealActionsModal.js +428 -0
- package/dist/browser/ui/modals/index.js +638 -0
- package/dist/browser/ui/overlays/demo-overlays.js +55 -0
- package/dist/browser/ui/overlays/index.js +55 -0
- package/dist/browser/ui/renderers/index.js +827 -0
- package/dist/browser/ui/renderers/pipeline.markdown.js +564 -0
- package/dist/browser/ui/renderers/pipeline.renderer.js +264 -0
- package/dist/crm-pipeline.feature.d.ts +1 -6
- package/dist/crm-pipeline.feature.d.ts.map +1 -1
- package/dist/crm-pipeline.feature.js +74 -164
- package/dist/deal/deal.enum.d.ts +2 -7
- package/dist/deal/deal.enum.d.ts.map +1 -1
- package/dist/deal/deal.enum.js +16 -22
- package/dist/deal/deal.operation.d.ts +444 -450
- package/dist/deal/deal.operation.d.ts.map +1 -1
- package/dist/deal/deal.operation.js +390 -263
- package/dist/deal/deal.schema.d.ts +251 -256
- package/dist/deal/deal.schema.d.ts.map +1 -1
- package/dist/deal/deal.schema.js +131 -275
- package/dist/deal/deal.test-spec.d.ts +2 -7
- package/dist/deal/deal.test-spec.d.ts.map +1 -1
- package/dist/deal/deal.test-spec.js +56 -62
- package/dist/deal/index.d.ts +7 -4
- package/dist/deal/index.d.ts.map +1 -0
- package/dist/deal/index.js +408 -4
- package/dist/docs/crm-pipeline.docblock.d.ts +2 -1
- package/dist/docs/crm-pipeline.docblock.d.ts.map +1 -0
- package/dist/docs/crm-pipeline.docblock.js +45 -51
- package/dist/docs/index.d.ts +2 -1
- package/dist/docs/index.d.ts.map +1 -0
- package/dist/docs/index.js +114 -1
- package/dist/entities/company.entity.d.ts +27 -32
- package/dist/entities/company.entity.d.ts.map +1 -1
- package/dist/entities/company.entity.js +51 -61
- package/dist/entities/contact.entity.d.ts +31 -36
- package/dist/entities/contact.entity.d.ts.map +1 -1
- package/dist/entities/contact.entity.js +65 -76
- package/dist/entities/deal.entity.d.ts +52 -57
- package/dist/entities/deal.entity.d.ts.map +1 -1
- package/dist/entities/deal.entity.js +104 -116
- package/dist/entities/index.d.ts +6 -10
- package/dist/entities/index.d.ts.map +1 -1
- package/dist/entities/index.js +342 -31
- package/dist/entities/task.entity.d.ts +42 -47
- package/dist/entities/task.entity.d.ts.map +1 -1
- package/dist/entities/task.entity.js +95 -124
- package/dist/events/contact.event.d.ts +21 -27
- package/dist/events/contact.event.d.ts.map +1 -1
- package/dist/events/contact.event.js +29 -42
- package/dist/events/deal.event.d.ts +100 -106
- package/dist/events/deal.event.d.ts.map +1 -1
- package/dist/events/deal.event.js +93 -163
- package/dist/events/index.d.ts +4 -4
- package/dist/events/index.d.ts.map +1 -0
- package/dist/events/index.js +158 -4
- package/dist/events/task.event.d.ts +21 -27
- package/dist/events/task.event.d.ts.map +1 -1
- package/dist/events/task.event.js +26 -42
- package/dist/example.d.ts +2 -6
- package/dist/example.d.ts.map +1 -1
- package/dist/example.js +38 -50
- package/dist/handlers/crm.handlers.d.ts +80 -78
- package/dist/handlers/crm.handlers.d.ts.map +1 -1
- package/dist/handlers/crm.handlers.js +155 -166
- package/dist/handlers/deal.handlers.d.ts +58 -63
- package/dist/handlers/deal.handlers.d.ts.map +1 -1
- package/dist/handlers/deal.handlers.js +279 -105
- package/dist/handlers/index.d.ts +10 -4
- package/dist/handlers/index.d.ts.map +1 -0
- package/dist/handlers/index.js +456 -4
- package/dist/handlers/mock-data.d.ts +38 -41
- package/dist/handlers/mock-data.d.ts.map +1 -1
- package/dist/handlers/mock-data.js +162 -184
- package/dist/index.d.ts +13 -42
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +3277 -53
- package/dist/node/crm-pipeline.feature.js +75 -0
- package/dist/node/deal/deal.enum.js +18 -0
- package/dist/node/deal/deal.operation.js +396 -0
- package/dist/node/deal/deal.schema.js +141 -0
- package/dist/node/deal/deal.test-spec.js +58 -0
- package/dist/node/deal/index.js +408 -0
- package/dist/node/docs/crm-pipeline.docblock.js +113 -0
- package/dist/node/docs/index.js +113 -0
- package/dist/node/entities/company.entity.js +52 -0
- package/dist/node/entities/contact.entity.js +66 -0
- package/dist/node/entities/deal.entity.js +107 -0
- package/dist/node/entities/index.js +343 -0
- package/dist/node/entities/task.entity.js +99 -0
- package/dist/node/events/contact.event.js +31 -0
- package/dist/node/events/deal.event.js +101 -0
- package/dist/node/events/index.js +158 -0
- package/dist/node/events/task.event.js +28 -0
- package/dist/node/example.js +39 -0
- package/dist/node/handlers/crm.handlers.js +160 -0
- package/dist/node/handlers/deal.handlers.js +293 -0
- package/dist/node/handlers/index.js +456 -0
- package/dist/node/handlers/mock-data.js +165 -0
- package/dist/node/index.js +3279 -0
- package/dist/node/operations/index.js +407 -0
- package/dist/node/presentations/dashboard.presentation.js +52 -0
- package/dist/node/presentations/index.js +284 -0
- package/dist/node/presentations/pipeline.presentation.js +233 -0
- package/dist/node/seeders/index.js +22 -0
- package/dist/node/shared/overlay-types.js +0 -0
- package/dist/node/ui/CrmDashboard.js +1325 -0
- package/dist/node/ui/CrmDealCard.js +50 -0
- package/dist/node/ui/CrmPipelineBoard.js +160 -0
- package/dist/node/ui/hooks/index.js +186 -0
- package/dist/node/ui/hooks/useDealList.js +84 -0
- package/dist/node/ui/hooks/useDealMutations.js +100 -0
- package/dist/node/ui/index.js +1972 -0
- package/dist/node/ui/modals/CreateDealModal.js +211 -0
- package/dist/node/ui/modals/DealActionsModal.js +428 -0
- package/dist/node/ui/modals/index.js +638 -0
- package/dist/node/ui/overlays/demo-overlays.js +55 -0
- package/dist/node/ui/overlays/index.js +55 -0
- package/dist/node/ui/renderers/index.js +827 -0
- package/dist/node/ui/renderers/pipeline.markdown.js +564 -0
- package/dist/node/ui/renderers/pipeline.renderer.js +264 -0
- package/dist/operations/index.d.ts +2 -5
- package/dist/operations/index.d.ts.map +1 -0
- package/dist/operations/index.js +407 -5
- package/dist/presentations/dashboard.presentation.d.ts +2 -7
- package/dist/presentations/dashboard.presentation.d.ts.map +1 -1
- package/dist/presentations/dashboard.presentation.js +51 -60
- package/dist/presentations/index.d.ts +3 -3
- package/dist/presentations/index.d.ts.map +1 -0
- package/dist/presentations/index.js +284 -3
- package/dist/presentations/pipeline.presentation.d.ts +4 -9
- package/dist/presentations/pipeline.presentation.d.ts.map +1 -1
- package/dist/presentations/pipeline.presentation.js +228 -116
- package/dist/seeders/index.d.ts +4 -8
- package/dist/seeders/index.d.ts.map +1 -1
- package/dist/seeders/index.js +21 -45
- package/dist/shared/overlay-types.d.ts +25 -28
- package/dist/shared/overlay-types.d.ts.map +1 -1
- package/dist/shared/overlay-types.js +1 -0
- package/dist/ui/CrmDashboard.d.ts +1 -6
- package/dist/ui/CrmDashboard.d.ts.map +1 -1
- package/dist/ui/CrmDashboard.js +1318 -296
- package/dist/ui/CrmDealCard.d.ts +8 -12
- package/dist/ui/CrmDealCard.d.ts.map +1 -1
- package/dist/ui/CrmDealCard.js +47 -45
- package/dist/ui/CrmPipelineBoard.d.ts +11 -20
- package/dist/ui/CrmPipelineBoard.d.ts.map +1 -1
- package/dist/ui/CrmPipelineBoard.js +157 -94
- package/dist/ui/hooks/index.d.ts +3 -3
- package/dist/ui/hooks/index.d.ts.map +1 -0
- package/dist/ui/hooks/index.js +185 -4
- package/dist/ui/hooks/useDealList.d.ts +28 -32
- package/dist/ui/hooks/useDealList.d.ts.map +1 -1
- package/dist/ui/hooks/useDealList.js +81 -90
- package/dist/ui/hooks/useDealMutations.d.ts +18 -22
- package/dist/ui/hooks/useDealMutations.d.ts.map +1 -1
- package/dist/ui/hooks/useDealMutations.js +97 -155
- package/dist/ui/index.d.ts +8 -14
- package/dist/ui/index.d.ts.map +1 -0
- package/dist/ui/index.js +1973 -15
- package/dist/ui/modals/CreateDealModal.d.ts +19 -29
- package/dist/ui/modals/CreateDealModal.d.ts.map +1 -1
- package/dist/ui/modals/CreateDealModal.js +209 -180
- package/dist/ui/modals/DealActionsModal.d.ts +31 -44
- package/dist/ui/modals/DealActionsModal.d.ts.map +1 -1
- package/dist/ui/modals/DealActionsModal.js +424 -367
- package/dist/ui/modals/index.d.ts +3 -3
- package/dist/ui/modals/index.d.ts.map +1 -0
- package/dist/ui/modals/index.js +638 -3
- package/dist/ui/overlays/demo-overlays.d.ts +10 -8
- package/dist/ui/overlays/demo-overlays.d.ts.map +1 -1
- package/dist/ui/overlays/demo-overlays.js +54 -66
- package/dist/ui/overlays/index.d.ts +2 -2
- package/dist/ui/overlays/index.d.ts.map +1 -0
- package/dist/ui/overlays/index.js +56 -3
- package/dist/ui/renderers/index.d.ts +3 -3
- package/dist/ui/renderers/index.d.ts.map +1 -0
- package/dist/ui/renderers/index.js +827 -3
- package/dist/ui/renderers/pipeline.markdown.d.ts +12 -11
- package/dist/ui/renderers/pipeline.markdown.d.ts.map +1 -1
- package/dist/ui/renderers/pipeline.markdown.js +560 -114
- package/dist/ui/renderers/pipeline.renderer.d.ts +9 -7
- package/dist/ui/renderers/pipeline.renderer.d.ts.map +1 -1
- package/dist/ui/renderers/pipeline.renderer.js +261 -24
- package/package.json +476 -90
- package/tsdown.config.js +1 -2
- package/.turbo/turbo-build$colon$bundle.log +0 -164
- package/dist/crm-pipeline.feature.js.map +0 -1
- package/dist/deal/deal.enum.js.map +0 -1
- package/dist/deal/deal.operation.js.map +0 -1
- package/dist/deal/deal.schema.js.map +0 -1
- package/dist/deal/deal.test-spec.js.map +0 -1
- package/dist/docs/crm-pipeline.docblock.js.map +0 -1
- package/dist/entities/company.entity.js.map +0 -1
- package/dist/entities/contact.entity.js.map +0 -1
- package/dist/entities/deal.entity.js.map +0 -1
- package/dist/entities/index.js.map +0 -1
- package/dist/entities/task.entity.js.map +0 -1
- package/dist/events/contact.event.js.map +0 -1
- package/dist/events/deal.event.js.map +0 -1
- package/dist/events/task.event.js.map +0 -1
- package/dist/example.js.map +0 -1
- package/dist/handlers/crm.handlers.js.map +0 -1
- package/dist/handlers/deal.handlers.js.map +0 -1
- package/dist/handlers/mock-data.js.map +0 -1
- package/dist/index.js.map +0 -1
- package/dist/presentations/dashboard.presentation.js.map +0 -1
- package/dist/presentations/pipeline.presentation.js.map +0 -1
- package/dist/seeders/index.js.map +0 -1
- package/dist/ui/CrmDashboard.js.map +0 -1
- package/dist/ui/CrmDealCard.js.map +0 -1
- package/dist/ui/CrmPipelineBoard.js.map +0 -1
- package/dist/ui/hooks/useDealList.js.map +0 -1
- package/dist/ui/hooks/useDealMutations.js.map +0 -1
- package/dist/ui/modals/CreateDealModal.js.map +0 -1
- package/dist/ui/modals/DealActionsModal.js.map +0 -1
- package/dist/ui/overlays/demo-overlays.js.map +0 -1
- package/dist/ui/renderers/pipeline.markdown.js.map +0 -1
- package/dist/ui/renderers/pipeline.renderer.js.map +0 -1
- package/tsconfig.tsbuildinfo +0 -1
|
@@ -0,0 +1,264 @@
|
|
|
1
|
+
// src/ui/hooks/useDealList.ts
|
|
2
|
+
import { useCallback, useEffect, useMemo, useState } from "react";
|
|
3
|
+
import { useTemplateRuntime } from "@contractspec/lib.example-shared-ui";
|
|
4
|
+
"use client";
|
|
5
|
+
function useDealList(options = {}) {
|
|
6
|
+
const { handlers, projectId } = useTemplateRuntime();
|
|
7
|
+
const { crm } = handlers;
|
|
8
|
+
const [data, setData] = useState(null);
|
|
9
|
+
const [dealsByStage, setDealsByStage] = useState({});
|
|
10
|
+
const [stages, setStages] = useState([]);
|
|
11
|
+
const [loading, setLoading] = useState(true);
|
|
12
|
+
const [error, setError] = useState(null);
|
|
13
|
+
const [page, setPage] = useState(1);
|
|
14
|
+
const pipelineId = options.pipelineId ?? "pipeline-1";
|
|
15
|
+
const fetchData = useCallback(async () => {
|
|
16
|
+
setLoading(true);
|
|
17
|
+
setError(null);
|
|
18
|
+
try {
|
|
19
|
+
const [dealsResult, stageDealsResult, stagesResult] = await Promise.all([
|
|
20
|
+
crm.listDeals({
|
|
21
|
+
projectId,
|
|
22
|
+
pipelineId,
|
|
23
|
+
stageId: options.stageId,
|
|
24
|
+
status: options.status === "all" ? undefined : options.status,
|
|
25
|
+
search: options.search,
|
|
26
|
+
limit: options.limit ?? 50,
|
|
27
|
+
offset: (page - 1) * (options.limit ?? 50)
|
|
28
|
+
}),
|
|
29
|
+
crm.getDealsByStage({ projectId, pipelineId }),
|
|
30
|
+
crm.getPipelineStages({ pipelineId })
|
|
31
|
+
]);
|
|
32
|
+
setData(dealsResult);
|
|
33
|
+
setDealsByStage(stageDealsResult);
|
|
34
|
+
setStages(stagesResult);
|
|
35
|
+
} catch (err) {
|
|
36
|
+
setError(err instanceof Error ? err : new Error("Unknown error"));
|
|
37
|
+
} finally {
|
|
38
|
+
setLoading(false);
|
|
39
|
+
}
|
|
40
|
+
}, [
|
|
41
|
+
crm,
|
|
42
|
+
projectId,
|
|
43
|
+
pipelineId,
|
|
44
|
+
options.stageId,
|
|
45
|
+
options.status,
|
|
46
|
+
options.search,
|
|
47
|
+
options.limit,
|
|
48
|
+
page
|
|
49
|
+
]);
|
|
50
|
+
useEffect(() => {
|
|
51
|
+
fetchData();
|
|
52
|
+
}, [fetchData]);
|
|
53
|
+
const stats = useMemo(() => {
|
|
54
|
+
if (!data)
|
|
55
|
+
return null;
|
|
56
|
+
const open = data.deals.filter((d) => d.status === "OPEN");
|
|
57
|
+
const won = data.deals.filter((d) => d.status === "WON");
|
|
58
|
+
const lost = data.deals.filter((d) => d.status === "LOST");
|
|
59
|
+
return {
|
|
60
|
+
total: data.total,
|
|
61
|
+
totalValue: data.totalValue,
|
|
62
|
+
openCount: open.length,
|
|
63
|
+
openValue: open.reduce((sum, d) => sum + d.value, 0),
|
|
64
|
+
wonCount: won.length,
|
|
65
|
+
wonValue: won.reduce((sum, d) => sum + d.value, 0),
|
|
66
|
+
lostCount: lost.length
|
|
67
|
+
};
|
|
68
|
+
}, [data]);
|
|
69
|
+
return {
|
|
70
|
+
data,
|
|
71
|
+
dealsByStage,
|
|
72
|
+
stages,
|
|
73
|
+
loading,
|
|
74
|
+
error,
|
|
75
|
+
stats,
|
|
76
|
+
page,
|
|
77
|
+
refetch: fetchData,
|
|
78
|
+
nextPage: () => setPage((p) => p + 1),
|
|
79
|
+
prevPage: () => page > 1 && setPage((p) => p - 1)
|
|
80
|
+
};
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
// src/ui/CrmDealCard.tsx
|
|
84
|
+
import { jsxDEV } from "react/jsx-dev-runtime";
|
|
85
|
+
"use client";
|
|
86
|
+
function formatCurrency(value, currency) {
|
|
87
|
+
return new Intl.NumberFormat("en-US", {
|
|
88
|
+
style: "currency",
|
|
89
|
+
currency,
|
|
90
|
+
minimumFractionDigits: 0,
|
|
91
|
+
maximumFractionDigits: 0
|
|
92
|
+
}).format(value);
|
|
93
|
+
}
|
|
94
|
+
function CrmDealCard({ deal, onClick }) {
|
|
95
|
+
const daysUntilClose = deal.expectedCloseDate ? Math.ceil((deal.expectedCloseDate.getTime() - Date.now()) / (1000 * 60 * 60 * 24)) : null;
|
|
96
|
+
return /* @__PURE__ */ jsxDEV("div", {
|
|
97
|
+
onClick,
|
|
98
|
+
className: "border-border bg-card cursor-pointer rounded-lg border p-3 shadow-sm transition-shadow hover:shadow-md",
|
|
99
|
+
role: "button",
|
|
100
|
+
tabIndex: 0,
|
|
101
|
+
onKeyDown: (e) => {
|
|
102
|
+
if (e.key === "Enter" || e.key === " ")
|
|
103
|
+
onClick?.();
|
|
104
|
+
},
|
|
105
|
+
children: [
|
|
106
|
+
/* @__PURE__ */ jsxDEV("h4", {
|
|
107
|
+
className: "leading-snug font-medium",
|
|
108
|
+
children: deal.name
|
|
109
|
+
}, undefined, false, undefined, this),
|
|
110
|
+
/* @__PURE__ */ jsxDEV("div", {
|
|
111
|
+
className: "text-primary mt-2 text-lg font-semibold",
|
|
112
|
+
children: formatCurrency(deal.value, deal.currency)
|
|
113
|
+
}, undefined, false, undefined, this),
|
|
114
|
+
/* @__PURE__ */ jsxDEV("div", {
|
|
115
|
+
className: "text-muted-foreground mt-3 flex items-center justify-between text-xs",
|
|
116
|
+
children: [
|
|
117
|
+
daysUntilClose !== null && /* @__PURE__ */ jsxDEV("span", {
|
|
118
|
+
className: daysUntilClose < 0 ? "text-red-500" : daysUntilClose <= 7 ? "text-yellow-600 dark:text-yellow-500" : "",
|
|
119
|
+
children: daysUntilClose < 0 ? `${Math.abs(daysUntilClose)}d overdue` : daysUntilClose === 0 ? "Due today" : `${daysUntilClose}d left`
|
|
120
|
+
}, undefined, false, undefined, this),
|
|
121
|
+
/* @__PURE__ */ jsxDEV("span", {
|
|
122
|
+
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"}`,
|
|
123
|
+
children: deal.status
|
|
124
|
+
}, undefined, false, undefined, this)
|
|
125
|
+
]
|
|
126
|
+
}, undefined, true, undefined, this)
|
|
127
|
+
]
|
|
128
|
+
}, undefined, true, undefined, this);
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
// src/ui/CrmPipelineBoard.tsx
|
|
132
|
+
import { useState as useState2 } from "react";
|
|
133
|
+
import { jsxDEV as jsxDEV2 } from "react/jsx-dev-runtime";
|
|
134
|
+
"use client";
|
|
135
|
+
function formatCurrency2(value) {
|
|
136
|
+
if (value >= 1e6)
|
|
137
|
+
return `$${(value / 1e6).toFixed(1)}M`;
|
|
138
|
+
if (value >= 1000)
|
|
139
|
+
return `$${(value / 1000).toFixed(0)}K`;
|
|
140
|
+
return `$${value}`;
|
|
141
|
+
}
|
|
142
|
+
function CrmPipelineBoard({
|
|
143
|
+
dealsByStage,
|
|
144
|
+
stages,
|
|
145
|
+
onDealClick,
|
|
146
|
+
onDealMove
|
|
147
|
+
}) {
|
|
148
|
+
const [quickMoveOpen, setQuickMoveOpen] = useState2(null);
|
|
149
|
+
const sortedStages = [...stages].sort((a, b) => a.position - b.position);
|
|
150
|
+
const handleQuickMove = (dealId, toStageId) => {
|
|
151
|
+
onDealMove?.(dealId, toStageId);
|
|
152
|
+
setQuickMoveOpen(null);
|
|
153
|
+
};
|
|
154
|
+
return /* @__PURE__ */ jsxDEV2("div", {
|
|
155
|
+
className: "flex gap-4 overflow-x-auto pb-4",
|
|
156
|
+
children: sortedStages.map((stage) => {
|
|
157
|
+
const deals = dealsByStage[stage.id] ?? [];
|
|
158
|
+
const stageValue = deals.reduce((sum, d) => sum + d.value, 0);
|
|
159
|
+
return /* @__PURE__ */ jsxDEV2("div", {
|
|
160
|
+
className: "bg-muted/30 flex w-72 flex-shrink-0 flex-col rounded-lg",
|
|
161
|
+
children: [
|
|
162
|
+
/* @__PURE__ */ jsxDEV2("div", {
|
|
163
|
+
className: "border-border flex items-center justify-between border-b px-3 py-2",
|
|
164
|
+
children: [
|
|
165
|
+
/* @__PURE__ */ jsxDEV2("div", {
|
|
166
|
+
children: [
|
|
167
|
+
/* @__PURE__ */ jsxDEV2("h3", {
|
|
168
|
+
className: "font-medium",
|
|
169
|
+
children: stage.name
|
|
170
|
+
}, undefined, false, undefined, this),
|
|
171
|
+
/* @__PURE__ */ jsxDEV2("p", {
|
|
172
|
+
className: "text-muted-foreground text-xs",
|
|
173
|
+
children: [
|
|
174
|
+
deals.length,
|
|
175
|
+
" deals · ",
|
|
176
|
+
formatCurrency2(stageValue)
|
|
177
|
+
]
|
|
178
|
+
}, undefined, true, undefined, this)
|
|
179
|
+
]
|
|
180
|
+
}, undefined, true, undefined, this),
|
|
181
|
+
/* @__PURE__ */ jsxDEV2("span", {
|
|
182
|
+
className: "bg-muted flex h-6 w-6 items-center justify-center rounded-full text-xs font-medium",
|
|
183
|
+
children: deals.length
|
|
184
|
+
}, undefined, false, undefined, this)
|
|
185
|
+
]
|
|
186
|
+
}, undefined, true, undefined, this),
|
|
187
|
+
/* @__PURE__ */ jsxDEV2("div", {
|
|
188
|
+
className: "flex flex-1 flex-col gap-2 p-2",
|
|
189
|
+
children: deals.length === 0 ? /* @__PURE__ */ jsxDEV2("div", {
|
|
190
|
+
className: "border-muted-foreground/20 text-muted-foreground flex h-24 items-center justify-center rounded-md border-2 border-dashed text-xs",
|
|
191
|
+
children: "No deals"
|
|
192
|
+
}, undefined, false, undefined, this) : deals.map((deal) => /* @__PURE__ */ jsxDEV2("div", {
|
|
193
|
+
className: "group relative",
|
|
194
|
+
children: [
|
|
195
|
+
/* @__PURE__ */ jsxDEV2(CrmDealCard, {
|
|
196
|
+
deal,
|
|
197
|
+
onClick: () => onDealClick?.(deal.id)
|
|
198
|
+
}, undefined, false, undefined, this),
|
|
199
|
+
deal.status === "OPEN" && onDealMove && /* @__PURE__ */ jsxDEV2("div", {
|
|
200
|
+
className: "absolute top-1 right-1 opacity-0 transition-opacity group-hover:opacity-100",
|
|
201
|
+
children: [
|
|
202
|
+
/* @__PURE__ */ jsxDEV2("button", {
|
|
203
|
+
type: "button",
|
|
204
|
+
onClick: (e) => {
|
|
205
|
+
e.stopPropagation();
|
|
206
|
+
setQuickMoveOpen(quickMoveOpen === deal.id ? null : deal.id);
|
|
207
|
+
},
|
|
208
|
+
className: "bg-background border-border hover:bg-muted flex h-6 w-6 items-center justify-center rounded border text-xs shadow-sm",
|
|
209
|
+
title: "Quick move",
|
|
210
|
+
children: "➡️"
|
|
211
|
+
}, undefined, false, undefined, this),
|
|
212
|
+
quickMoveOpen === deal.id && /* @__PURE__ */ jsxDEV2("div", {
|
|
213
|
+
className: "bg-card border-border absolute top-7 right-0 z-20 min-w-[140px] rounded-lg border py-1 shadow-lg",
|
|
214
|
+
children: [
|
|
215
|
+
/* @__PURE__ */ jsxDEV2("p", {
|
|
216
|
+
className: "text-muted-foreground px-3 py-1 text-xs font-medium",
|
|
217
|
+
children: "Move to:"
|
|
218
|
+
}, undefined, false, undefined, this),
|
|
219
|
+
sortedStages.filter((s) => s.id !== deal.stageId).map((s) => /* @__PURE__ */ jsxDEV2("button", {
|
|
220
|
+
type: "button",
|
|
221
|
+
onClick: (e) => {
|
|
222
|
+
e.stopPropagation();
|
|
223
|
+
handleQuickMove(deal.id, s.id);
|
|
224
|
+
},
|
|
225
|
+
className: "hover:bg-muted w-full px-3 py-1.5 text-left text-sm",
|
|
226
|
+
children: s.name
|
|
227
|
+
}, s.id, false, undefined, this))
|
|
228
|
+
]
|
|
229
|
+
}, undefined, true, undefined, this)
|
|
230
|
+
]
|
|
231
|
+
}, undefined, true, undefined, this)
|
|
232
|
+
]
|
|
233
|
+
}, deal.id, true, undefined, this))
|
|
234
|
+
}, undefined, false, undefined, this)
|
|
235
|
+
]
|
|
236
|
+
}, stage.id, true, undefined, this);
|
|
237
|
+
})
|
|
238
|
+
}, undefined, false, undefined, this);
|
|
239
|
+
}
|
|
240
|
+
|
|
241
|
+
// src/ui/renderers/pipeline.renderer.tsx
|
|
242
|
+
import { jsxDEV as jsxDEV3 } from "react/jsx-dev-runtime";
|
|
243
|
+
function CrmPipelineBoardWrapper() {
|
|
244
|
+
const { dealsByStage, stages } = useDealList();
|
|
245
|
+
return /* @__PURE__ */ jsxDEV3(CrmPipelineBoard, {
|
|
246
|
+
dealsByStage,
|
|
247
|
+
stages
|
|
248
|
+
}, undefined, false, undefined, this);
|
|
249
|
+
}
|
|
250
|
+
var crmPipelineReactRenderer = {
|
|
251
|
+
target: "react",
|
|
252
|
+
render: async (desc, _ctx) => {
|
|
253
|
+
if (desc.source.type !== "component") {
|
|
254
|
+
throw new Error("Invalid source type");
|
|
255
|
+
}
|
|
256
|
+
if (desc.source.componentKey !== "CrmPipelineView") {
|
|
257
|
+
throw new Error(`Unknown component: ${desc.source.componentKey}`);
|
|
258
|
+
}
|
|
259
|
+
return /* @__PURE__ */ jsxDEV3(CrmPipelineBoardWrapper, {}, undefined, false, undefined, this);
|
|
260
|
+
}
|
|
261
|
+
};
|
|
262
|
+
export {
|
|
263
|
+
crmPipelineReactRenderer
|
|
264
|
+
};
|
|
@@ -1,5 +1,2 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
import { CreateDealInputModel, DealLostPayloadModel, DealModel, DealMovedPayloadModel, DealWonPayloadModel, ListDealsInputModel, ListDealsOutputModel, LoseDealInputModel, MoveDealInputModel, WinDealInputModel } from "../deal/deal.schema.js";
|
|
4
|
-
import "../deal/index.js";
|
|
5
|
-
export { CreateDealContract, CreateDealInputModel, DealLostPayloadModel, DealModel, DealMovedPayloadModel, DealStatusFilterEnum, DealWonPayloadModel, ListDealsContract, ListDealsInputModel, ListDealsOutputModel, LoseDealContract, LoseDealInputModel, MoveDealContract, MoveDealInputModel, WinDealContract, WinDealInputModel };
|
|
1
|
+
export { DealStatusFilterEnum, DealModel, CreateDealInputModel, MoveDealInputModel, DealMovedPayloadModel, WinDealInputModel, DealWonPayloadModel, LoseDealInputModel, DealLostPayloadModel, ListDealsInputModel, ListDealsOutputModel, CreateDealContract, MoveDealContract, WinDealContract, LoseDealContract, ListDealsContract, } from '../deal';
|
|
2
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/operations/index.ts"],"names":[],"mappings":"AAEA,OAAO,EACL,oBAAoB,EACpB,SAAS,EACT,oBAAoB,EACpB,kBAAkB,EAClB,qBAAqB,EACrB,iBAAiB,EACjB,mBAAmB,EACnB,kBAAkB,EAClB,oBAAoB,EACpB,mBAAmB,EACnB,oBAAoB,EACpB,kBAAkB,EAClB,gBAAgB,EAChB,eAAe,EACf,gBAAgB,EAChB,iBAAiB,GAClB,MAAM,SAAS,CAAC"}
|
package/dist/operations/index.js
CHANGED
|
@@ -1,6 +1,408 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
import {
|
|
4
|
-
|
|
1
|
+
// @bun
|
|
2
|
+
// src/deal/deal.enum.ts
|
|
3
|
+
import { defineEnum } from "@contractspec/lib.schema";
|
|
4
|
+
var DealStatusEnum = defineEnum("DealStatus", [
|
|
5
|
+
"OPEN",
|
|
6
|
+
"WON",
|
|
7
|
+
"LOST",
|
|
8
|
+
"STALE"
|
|
9
|
+
]);
|
|
10
|
+
var DealStatusFilterEnum = defineEnum("DealStatusFilter", [
|
|
11
|
+
"OPEN",
|
|
12
|
+
"WON",
|
|
13
|
+
"LOST",
|
|
14
|
+
"all"
|
|
15
|
+
]);
|
|
5
16
|
|
|
6
|
-
|
|
17
|
+
// src/deal/deal.schema.ts
|
|
18
|
+
import { defineSchemaModel, ScalarTypeEnum } from "@contractspec/lib.schema";
|
|
19
|
+
var DealModel = defineSchemaModel({
|
|
20
|
+
name: "Deal",
|
|
21
|
+
description: "A deal in the CRM pipeline",
|
|
22
|
+
fields: {
|
|
23
|
+
id: { type: ScalarTypeEnum.String_unsecure(), isOptional: false },
|
|
24
|
+
name: { type: ScalarTypeEnum.String_unsecure(), isOptional: false },
|
|
25
|
+
value: { type: ScalarTypeEnum.Float_unsecure(), isOptional: false },
|
|
26
|
+
currency: { type: ScalarTypeEnum.String_unsecure(), isOptional: false },
|
|
27
|
+
pipelineId: { type: ScalarTypeEnum.String_unsecure(), isOptional: false },
|
|
28
|
+
stageId: { type: ScalarTypeEnum.String_unsecure(), isOptional: false },
|
|
29
|
+
status: { type: DealStatusEnum, isOptional: false },
|
|
30
|
+
contactId: { type: ScalarTypeEnum.String_unsecure(), isOptional: true },
|
|
31
|
+
companyId: { type: ScalarTypeEnum.String_unsecure(), isOptional: true },
|
|
32
|
+
ownerId: { type: ScalarTypeEnum.String_unsecure(), isOptional: false },
|
|
33
|
+
expectedCloseDate: { type: ScalarTypeEnum.DateTime(), isOptional: true },
|
|
34
|
+
createdAt: { type: ScalarTypeEnum.DateTime(), isOptional: false },
|
|
35
|
+
updatedAt: { type: ScalarTypeEnum.DateTime(), isOptional: false }
|
|
36
|
+
}
|
|
37
|
+
});
|
|
38
|
+
var CreateDealInputModel = defineSchemaModel({
|
|
39
|
+
name: "CreateDealInput",
|
|
40
|
+
description: "Input for creating a deal",
|
|
41
|
+
fields: {
|
|
42
|
+
name: { type: ScalarTypeEnum.NonEmptyString(), isOptional: false },
|
|
43
|
+
value: { type: ScalarTypeEnum.Float_unsecure(), isOptional: false },
|
|
44
|
+
currency: { type: ScalarTypeEnum.String_unsecure(), isOptional: true },
|
|
45
|
+
pipelineId: { type: ScalarTypeEnum.String_unsecure(), isOptional: false },
|
|
46
|
+
stageId: { type: ScalarTypeEnum.String_unsecure(), isOptional: false },
|
|
47
|
+
contactId: { type: ScalarTypeEnum.String_unsecure(), isOptional: true },
|
|
48
|
+
companyId: { type: ScalarTypeEnum.String_unsecure(), isOptional: true },
|
|
49
|
+
expectedCloseDate: { type: ScalarTypeEnum.DateTime(), isOptional: true }
|
|
50
|
+
}
|
|
51
|
+
});
|
|
52
|
+
var MoveDealInputModel = defineSchemaModel({
|
|
53
|
+
name: "MoveDealInput",
|
|
54
|
+
description: "Input for moving a deal to another stage",
|
|
55
|
+
fields: {
|
|
56
|
+
dealId: { type: ScalarTypeEnum.String_unsecure(), isOptional: false },
|
|
57
|
+
stageId: { type: ScalarTypeEnum.String_unsecure(), isOptional: false },
|
|
58
|
+
position: { type: ScalarTypeEnum.Int_unsecure(), isOptional: true }
|
|
59
|
+
}
|
|
60
|
+
});
|
|
61
|
+
var DealMovedPayloadModel = defineSchemaModel({
|
|
62
|
+
name: "DealMovedPayload",
|
|
63
|
+
fields: {
|
|
64
|
+
dealId: { type: ScalarTypeEnum.String_unsecure(), isOptional: false },
|
|
65
|
+
fromStage: { type: ScalarTypeEnum.String_unsecure(), isOptional: false },
|
|
66
|
+
toStage: { type: ScalarTypeEnum.String_unsecure(), isOptional: false }
|
|
67
|
+
}
|
|
68
|
+
});
|
|
69
|
+
var WinDealInputModel = defineSchemaModel({
|
|
70
|
+
name: "WinDealInput",
|
|
71
|
+
description: "Input for marking a deal as won",
|
|
72
|
+
fields: {
|
|
73
|
+
dealId: { type: ScalarTypeEnum.String_unsecure(), isOptional: false },
|
|
74
|
+
wonSource: { type: ScalarTypeEnum.String_unsecure(), isOptional: true },
|
|
75
|
+
notes: { type: ScalarTypeEnum.String_unsecure(), isOptional: true }
|
|
76
|
+
}
|
|
77
|
+
});
|
|
78
|
+
var DealWonPayloadModel = defineSchemaModel({
|
|
79
|
+
name: "DealWonPayload",
|
|
80
|
+
fields: {
|
|
81
|
+
dealId: { type: ScalarTypeEnum.String_unsecure(), isOptional: false },
|
|
82
|
+
value: { type: ScalarTypeEnum.Float_unsecure(), isOptional: false }
|
|
83
|
+
}
|
|
84
|
+
});
|
|
85
|
+
var LoseDealInputModel = defineSchemaModel({
|
|
86
|
+
name: "LoseDealInput",
|
|
87
|
+
description: "Input for marking a deal as lost",
|
|
88
|
+
fields: {
|
|
89
|
+
dealId: { type: ScalarTypeEnum.String_unsecure(), isOptional: false },
|
|
90
|
+
lostReason: { type: ScalarTypeEnum.String_unsecure(), isOptional: false },
|
|
91
|
+
notes: { type: ScalarTypeEnum.String_unsecure(), isOptional: true }
|
|
92
|
+
}
|
|
93
|
+
});
|
|
94
|
+
var DealLostPayloadModel = defineSchemaModel({
|
|
95
|
+
name: "DealLostPayload",
|
|
96
|
+
fields: {
|
|
97
|
+
dealId: { type: ScalarTypeEnum.String_unsecure(), isOptional: false },
|
|
98
|
+
reason: { type: ScalarTypeEnum.String_unsecure(), isOptional: false }
|
|
99
|
+
}
|
|
100
|
+
});
|
|
101
|
+
var ListDealsInputModel = defineSchemaModel({
|
|
102
|
+
name: "ListDealsInput",
|
|
103
|
+
description: "Input for listing deals",
|
|
104
|
+
fields: {
|
|
105
|
+
pipelineId: { type: ScalarTypeEnum.String_unsecure(), isOptional: true },
|
|
106
|
+
stageId: { type: ScalarTypeEnum.String_unsecure(), isOptional: true },
|
|
107
|
+
status: { type: DealStatusFilterEnum, isOptional: true },
|
|
108
|
+
ownerId: { type: ScalarTypeEnum.String_unsecure(), isOptional: true },
|
|
109
|
+
search: { type: ScalarTypeEnum.String_unsecure(), isOptional: true },
|
|
110
|
+
limit: {
|
|
111
|
+
type: ScalarTypeEnum.Int_unsecure(),
|
|
112
|
+
isOptional: true,
|
|
113
|
+
defaultValue: 20
|
|
114
|
+
},
|
|
115
|
+
offset: {
|
|
116
|
+
type: ScalarTypeEnum.Int_unsecure(),
|
|
117
|
+
isOptional: true,
|
|
118
|
+
defaultValue: 0
|
|
119
|
+
}
|
|
120
|
+
}
|
|
121
|
+
});
|
|
122
|
+
var ListDealsOutputModel = defineSchemaModel({
|
|
123
|
+
name: "ListDealsOutput",
|
|
124
|
+
description: "Output for listing deals",
|
|
125
|
+
fields: {
|
|
126
|
+
deals: { type: DealModel, isArray: true, isOptional: false },
|
|
127
|
+
total: { type: ScalarTypeEnum.Int_unsecure(), isOptional: false },
|
|
128
|
+
totalValue: { type: ScalarTypeEnum.Float_unsecure(), isOptional: false }
|
|
129
|
+
}
|
|
130
|
+
});
|
|
131
|
+
|
|
132
|
+
// src/deal/deal.operation.ts
|
|
133
|
+
import {
|
|
134
|
+
defineCommand,
|
|
135
|
+
defineQuery
|
|
136
|
+
} from "@contractspec/lib.contracts/operations";
|
|
137
|
+
var OWNERS = ["@example.crm-pipeline"];
|
|
138
|
+
var CreateDealContract = defineCommand({
|
|
139
|
+
meta: {
|
|
140
|
+
key: "crm.deal.create",
|
|
141
|
+
version: "1.0.0",
|
|
142
|
+
stability: "stable",
|
|
143
|
+
owners: [...OWNERS],
|
|
144
|
+
tags: ["crm", "deal", "create"],
|
|
145
|
+
description: "Create a new deal in the pipeline.",
|
|
146
|
+
goal: "Allow sales reps to create new opportunities.",
|
|
147
|
+
context: "Deal creation UI, quick add."
|
|
148
|
+
},
|
|
149
|
+
io: {
|
|
150
|
+
input: CreateDealInputModel,
|
|
151
|
+
output: DealModel
|
|
152
|
+
},
|
|
153
|
+
policy: {
|
|
154
|
+
auth: "user"
|
|
155
|
+
},
|
|
156
|
+
sideEffects: {
|
|
157
|
+
emits: [
|
|
158
|
+
{
|
|
159
|
+
key: "deal.created",
|
|
160
|
+
version: "1.0.0",
|
|
161
|
+
when: "Deal is created",
|
|
162
|
+
payload: DealModel
|
|
163
|
+
}
|
|
164
|
+
],
|
|
165
|
+
audit: ["deal.created"]
|
|
166
|
+
},
|
|
167
|
+
acceptance: {
|
|
168
|
+
scenarios: [
|
|
169
|
+
{
|
|
170
|
+
key: "create-deal-happy-path",
|
|
171
|
+
given: ["User is authenticated"],
|
|
172
|
+
when: ["User creates a deal with valid data"],
|
|
173
|
+
then: ["Deal is created", "DealCreated event is emitted"]
|
|
174
|
+
}
|
|
175
|
+
],
|
|
176
|
+
examples: [
|
|
177
|
+
{
|
|
178
|
+
key: "create-basic-deal",
|
|
179
|
+
input: {
|
|
180
|
+
title: "Big Corp Q3 License",
|
|
181
|
+
stageId: "stage-lead",
|
|
182
|
+
value: 50000,
|
|
183
|
+
companyId: "comp-123"
|
|
184
|
+
},
|
|
185
|
+
output: {
|
|
186
|
+
id: "deal-789",
|
|
187
|
+
title: "Big Corp Q3 License",
|
|
188
|
+
status: "open"
|
|
189
|
+
}
|
|
190
|
+
}
|
|
191
|
+
]
|
|
192
|
+
}
|
|
193
|
+
});
|
|
194
|
+
var MoveDealContract = defineCommand({
|
|
195
|
+
meta: {
|
|
196
|
+
key: "crm.deal.move",
|
|
197
|
+
version: "1.0.0",
|
|
198
|
+
stability: "stable",
|
|
199
|
+
owners: [...OWNERS],
|
|
200
|
+
tags: ["crm", "deal", "move", "kanban"],
|
|
201
|
+
description: "Move a deal to a different stage.",
|
|
202
|
+
goal: "Allow drag-and-drop stage movement in Kanban.",
|
|
203
|
+
context: "Pipeline Kanban view."
|
|
204
|
+
},
|
|
205
|
+
io: {
|
|
206
|
+
input: MoveDealInputModel,
|
|
207
|
+
output: DealModel
|
|
208
|
+
},
|
|
209
|
+
policy: {
|
|
210
|
+
auth: "user"
|
|
211
|
+
},
|
|
212
|
+
sideEffects: {
|
|
213
|
+
emits: [
|
|
214
|
+
{
|
|
215
|
+
key: "deal.moved",
|
|
216
|
+
version: "1.0.0",
|
|
217
|
+
when: "Deal stage changed",
|
|
218
|
+
payload: DealMovedPayloadModel
|
|
219
|
+
}
|
|
220
|
+
],
|
|
221
|
+
audit: ["deal.moved"]
|
|
222
|
+
},
|
|
223
|
+
acceptance: {
|
|
224
|
+
scenarios: [
|
|
225
|
+
{
|
|
226
|
+
key: "move-deal-happy-path",
|
|
227
|
+
given: ["Deal exists in stage A"],
|
|
228
|
+
when: ["User moves deal to stage B"],
|
|
229
|
+
then: ["Deal stage is updated", "DealMoved event is emitted"]
|
|
230
|
+
}
|
|
231
|
+
],
|
|
232
|
+
examples: [
|
|
233
|
+
{
|
|
234
|
+
key: "move-to-negotiation",
|
|
235
|
+
input: { dealId: "deal-789", targetStageId: "stage-negotiation" },
|
|
236
|
+
output: {
|
|
237
|
+
id: "deal-789",
|
|
238
|
+
stageId: "stage-negotiation",
|
|
239
|
+
movedAt: "2025-01-15T10:00:00Z"
|
|
240
|
+
}
|
|
241
|
+
}
|
|
242
|
+
]
|
|
243
|
+
}
|
|
244
|
+
});
|
|
245
|
+
var WinDealContract = defineCommand({
|
|
246
|
+
meta: {
|
|
247
|
+
key: "crm.deal.win",
|
|
248
|
+
version: "1.0.0",
|
|
249
|
+
stability: "stable",
|
|
250
|
+
owners: [...OWNERS],
|
|
251
|
+
tags: ["crm", "deal", "won"],
|
|
252
|
+
description: "Mark a deal as won.",
|
|
253
|
+
goal: "Close a deal as successful.",
|
|
254
|
+
context: "Deal closing flow."
|
|
255
|
+
},
|
|
256
|
+
io: {
|
|
257
|
+
input: WinDealInputModel,
|
|
258
|
+
output: DealModel
|
|
259
|
+
},
|
|
260
|
+
policy: {
|
|
261
|
+
auth: "user"
|
|
262
|
+
},
|
|
263
|
+
sideEffects: {
|
|
264
|
+
emits: [
|
|
265
|
+
{
|
|
266
|
+
key: "deal.won",
|
|
267
|
+
version: "1.0.0",
|
|
268
|
+
when: "Deal is won",
|
|
269
|
+
payload: DealWonPayloadModel
|
|
270
|
+
}
|
|
271
|
+
],
|
|
272
|
+
audit: ["deal.won"]
|
|
273
|
+
},
|
|
274
|
+
acceptance: {
|
|
275
|
+
scenarios: [
|
|
276
|
+
{
|
|
277
|
+
key: "win-deal-happy-path",
|
|
278
|
+
given: ["Deal is open"],
|
|
279
|
+
when: ["User marks deal as won"],
|
|
280
|
+
then: ["Deal status becomes WON", "DealWon event is emitted"]
|
|
281
|
+
}
|
|
282
|
+
],
|
|
283
|
+
examples: [
|
|
284
|
+
{
|
|
285
|
+
key: "mark-won",
|
|
286
|
+
input: {
|
|
287
|
+
dealId: "deal-789",
|
|
288
|
+
actualValue: 52000,
|
|
289
|
+
note: "Signed contract attached"
|
|
290
|
+
},
|
|
291
|
+
output: {
|
|
292
|
+
id: "deal-789",
|
|
293
|
+
status: "won",
|
|
294
|
+
closedAt: "2025-01-20T14:30:00Z"
|
|
295
|
+
}
|
|
296
|
+
}
|
|
297
|
+
]
|
|
298
|
+
}
|
|
299
|
+
});
|
|
300
|
+
var LoseDealContract = defineCommand({
|
|
301
|
+
meta: {
|
|
302
|
+
key: "crm.deal.lose",
|
|
303
|
+
version: "1.0.0",
|
|
304
|
+
stability: "stable",
|
|
305
|
+
owners: [...OWNERS],
|
|
306
|
+
tags: ["crm", "deal", "lost"],
|
|
307
|
+
description: "Mark a deal as lost.",
|
|
308
|
+
goal: "Close a deal as unsuccessful.",
|
|
309
|
+
context: "Deal closing flow."
|
|
310
|
+
},
|
|
311
|
+
io: {
|
|
312
|
+
input: LoseDealInputModel,
|
|
313
|
+
output: DealModel
|
|
314
|
+
},
|
|
315
|
+
policy: {
|
|
316
|
+
auth: "user"
|
|
317
|
+
},
|
|
318
|
+
sideEffects: {
|
|
319
|
+
emits: [
|
|
320
|
+
{
|
|
321
|
+
key: "deal.lost",
|
|
322
|
+
version: "1.0.0",
|
|
323
|
+
when: "Deal is lost",
|
|
324
|
+
payload: DealLostPayloadModel
|
|
325
|
+
}
|
|
326
|
+
],
|
|
327
|
+
audit: ["deal.lost"]
|
|
328
|
+
},
|
|
329
|
+
acceptance: {
|
|
330
|
+
scenarios: [
|
|
331
|
+
{
|
|
332
|
+
key: "lose-deal-happy-path",
|
|
333
|
+
given: ["Deal is open"],
|
|
334
|
+
when: ["User marks deal as lost"],
|
|
335
|
+
then: ["Deal status becomes LOST", "DealLost event is emitted"]
|
|
336
|
+
}
|
|
337
|
+
],
|
|
338
|
+
examples: [
|
|
339
|
+
{
|
|
340
|
+
key: "mark-lost",
|
|
341
|
+
input: {
|
|
342
|
+
dealId: "deal-789",
|
|
343
|
+
reason: "competitor",
|
|
344
|
+
note: "Went with cheaper option"
|
|
345
|
+
},
|
|
346
|
+
output: {
|
|
347
|
+
id: "deal-789",
|
|
348
|
+
status: "lost",
|
|
349
|
+
closedAt: "2025-01-21T09:00:00Z"
|
|
350
|
+
}
|
|
351
|
+
}
|
|
352
|
+
]
|
|
353
|
+
}
|
|
354
|
+
});
|
|
355
|
+
var ListDealsContract = defineQuery({
|
|
356
|
+
meta: {
|
|
357
|
+
key: "crm.deal.list",
|
|
358
|
+
version: "1.0.0",
|
|
359
|
+
stability: "stable",
|
|
360
|
+
owners: [...OWNERS],
|
|
361
|
+
tags: ["crm", "deal", "list"],
|
|
362
|
+
description: "List deals with filters.",
|
|
363
|
+
goal: "Show pipeline, deal lists, dashboards.",
|
|
364
|
+
context: "Pipeline view, deal list."
|
|
365
|
+
},
|
|
366
|
+
io: {
|
|
367
|
+
input: ListDealsInputModel,
|
|
368
|
+
output: ListDealsOutputModel
|
|
369
|
+
},
|
|
370
|
+
policy: {
|
|
371
|
+
auth: "user"
|
|
372
|
+
},
|
|
373
|
+
acceptance: {
|
|
374
|
+
scenarios: [
|
|
375
|
+
{
|
|
376
|
+
key: "list-deals-happy-path",
|
|
377
|
+
given: ["User has access to deals"],
|
|
378
|
+
when: ["User lists deals"],
|
|
379
|
+
then: ["List of deals is returned"]
|
|
380
|
+
}
|
|
381
|
+
],
|
|
382
|
+
examples: [
|
|
383
|
+
{
|
|
384
|
+
key: "list-filter-stage",
|
|
385
|
+
input: { stageId: "stage-lead", limit: 20 },
|
|
386
|
+
output: { items: [], total: 5, hasMore: false }
|
|
387
|
+
}
|
|
388
|
+
]
|
|
389
|
+
}
|
|
390
|
+
});
|
|
391
|
+
export {
|
|
392
|
+
WinDealInputModel,
|
|
393
|
+
WinDealContract,
|
|
394
|
+
MoveDealInputModel,
|
|
395
|
+
MoveDealContract,
|
|
396
|
+
LoseDealInputModel,
|
|
397
|
+
LoseDealContract,
|
|
398
|
+
ListDealsOutputModel,
|
|
399
|
+
ListDealsInputModel,
|
|
400
|
+
ListDealsContract,
|
|
401
|
+
DealWonPayloadModel,
|
|
402
|
+
DealStatusFilterEnum,
|
|
403
|
+
DealMovedPayloadModel,
|
|
404
|
+
DealModel,
|
|
405
|
+
DealLostPayloadModel,
|
|
406
|
+
CreateDealInputModel,
|
|
407
|
+
CreateDealContract
|
|
408
|
+
};
|