@contractspec/example.crm-pipeline 1.46.0 → 1.47.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 (141) hide show
  1. package/.turbo/turbo-build$colon$bundle.log +111 -36
  2. package/.turbo/turbo-build.log +109 -34
  3. package/CHANGELOG.md +56 -0
  4. package/dist/crm-pipeline.feature.d.ts +2 -2
  5. package/dist/crm-pipeline.feature.d.ts.map +1 -1
  6. package/dist/crm-pipeline.feature.js +9 -2
  7. package/dist/crm-pipeline.feature.js.map +1 -1
  8. package/dist/deal/deal.enum.d.ts +3 -3
  9. package/dist/deal/deal.enum.d.ts.map +1 -1
  10. package/dist/deal/deal.operation.d.ts +128 -128
  11. package/dist/deal/deal.operation.d.ts.map +1 -1
  12. package/dist/deal/deal.schema.d.ts +71 -71
  13. package/dist/deal/deal.test-spec.d.ts +8 -0
  14. package/dist/deal/deal.test-spec.d.ts.map +1 -0
  15. package/dist/deal/deal.test-spec.js +65 -0
  16. package/dist/deal/deal.test-spec.js.map +1 -0
  17. package/dist/entities/company.entity.d.ts +28 -28
  18. package/dist/entities/company.entity.d.ts.map +1 -1
  19. package/dist/entities/contact.entity.d.ts +32 -32
  20. package/dist/entities/contact.entity.d.ts.map +1 -1
  21. package/dist/entities/deal.entity.d.ts +53 -53
  22. package/dist/entities/index.js.map +1 -1
  23. package/dist/entities/task.entity.d.ts +43 -43
  24. package/dist/entities/task.entity.d.ts.map +1 -1
  25. package/dist/events/contact.event.d.ts +8 -8
  26. package/dist/events/contact.event.d.ts.map +1 -1
  27. package/dist/events/contact.event.js +1 -1
  28. package/dist/events/deal.event.d.ts +30 -30
  29. package/dist/events/deal.event.js +1 -1
  30. package/dist/events/task.event.d.ts +8 -8
  31. package/dist/events/task.event.d.ts.map +1 -1
  32. package/dist/events/task.event.js +1 -1
  33. package/dist/example.d.ts +2 -2
  34. package/dist/example.d.ts.map +1 -1
  35. package/dist/example.js +4 -2
  36. package/dist/example.js.map +1 -1
  37. package/dist/handlers/crm.handlers.d.ts +89 -0
  38. package/dist/handlers/crm.handlers.d.ts.map +1 -0
  39. package/dist/handlers/crm.handlers.js +172 -0
  40. package/dist/handlers/crm.handlers.js.map +1 -0
  41. package/dist/handlers/deal.handlers.js.map +1 -1
  42. package/dist/handlers/index.d.ts +2 -1
  43. package/dist/handlers/index.js +2 -1
  44. package/dist/handlers/mock-data.js.map +1 -1
  45. package/dist/index.d.ts +16 -3
  46. package/dist/index.d.ts.map +1 -1
  47. package/dist/index.js +14 -1
  48. package/dist/index.js.map +1 -1
  49. package/dist/presentations/dashboard.presentation.d.ts +3 -4
  50. package/dist/presentations/dashboard.presentation.d.ts.map +1 -1
  51. package/dist/presentations/dashboard.presentation.js +8 -5
  52. package/dist/presentations/dashboard.presentation.js.map +1 -1
  53. package/dist/presentations/pipeline.presentation.d.ts +5 -6
  54. package/dist/presentations/pipeline.presentation.d.ts.map +1 -1
  55. package/dist/presentations/pipeline.presentation.js +12 -9
  56. package/dist/presentations/pipeline.presentation.js.map +1 -1
  57. package/dist/seeders/index.d.ts +10 -0
  58. package/dist/seeders/index.d.ts.map +1 -0
  59. package/dist/seeders/index.js +47 -0
  60. package/dist/seeders/index.js.map +1 -0
  61. package/dist/shared/overlay-types.d.ts +34 -0
  62. package/dist/shared/overlay-types.d.ts.map +1 -0
  63. package/dist/shared/overlay-types.js +0 -0
  64. package/dist/ui/CrmDashboard.d.ts +7 -0
  65. package/dist/ui/CrmDashboard.d.ts.map +1 -0
  66. package/dist/ui/CrmDashboard.js +304 -0
  67. package/dist/ui/CrmDashboard.js.map +1 -0
  68. package/dist/ui/CrmDealCard.d.ts +15 -0
  69. package/dist/ui/CrmDealCard.d.ts.map +1 -0
  70. package/dist/ui/CrmDealCard.js +49 -0
  71. package/dist/ui/CrmDealCard.js.map +1 -0
  72. package/dist/ui/CrmPipelineBoard.d.ts +23 -0
  73. package/dist/ui/CrmPipelineBoard.d.ts.map +1 -0
  74. package/dist/ui/CrmPipelineBoard.js +98 -0
  75. package/dist/ui/CrmPipelineBoard.js.map +1 -0
  76. package/dist/ui/hooks/index.d.ts +3 -0
  77. package/dist/ui/hooks/index.js +6 -0
  78. package/dist/ui/hooks/useDealList.d.ts +35 -0
  79. package/dist/ui/hooks/useDealList.d.ts.map +1 -0
  80. package/dist/ui/hooks/useDealList.js +94 -0
  81. package/dist/ui/hooks/useDealList.js.map +1 -0
  82. package/dist/ui/hooks/useDealMutations.d.ts +26 -0
  83. package/dist/ui/hooks/useDealMutations.d.ts.map +1 -0
  84. package/dist/ui/hooks/useDealMutations.js +159 -0
  85. package/dist/ui/hooks/useDealMutations.js.map +1 -0
  86. package/dist/ui/index.d.ts +14 -0
  87. package/dist/ui/index.js +15 -0
  88. package/dist/ui/modals/CreateDealModal.d.ts +33 -0
  89. package/dist/ui/modals/CreateDealModal.d.ts.map +1 -0
  90. package/dist/ui/modals/CreateDealModal.js +183 -0
  91. package/dist/ui/modals/CreateDealModal.js.map +1 -0
  92. package/dist/ui/modals/DealActionsModal.d.ts +51 -0
  93. package/dist/ui/modals/DealActionsModal.d.ts.map +1 -0
  94. package/dist/ui/modals/DealActionsModal.js +372 -0
  95. package/dist/ui/modals/DealActionsModal.js.map +1 -0
  96. package/dist/ui/modals/index.d.ts +3 -0
  97. package/dist/ui/modals/index.js +4 -0
  98. package/dist/ui/overlays/demo-overlays.d.ts +19 -0
  99. package/dist/ui/overlays/demo-overlays.d.ts.map +1 -0
  100. package/dist/ui/overlays/demo-overlays.js +68 -0
  101. package/dist/ui/overlays/demo-overlays.js.map +1 -0
  102. package/dist/ui/overlays/index.d.ts +2 -0
  103. package/dist/ui/overlays/index.js +3 -0
  104. package/dist/ui/renderers/index.d.ts +3 -0
  105. package/dist/ui/renderers/index.js +4 -0
  106. package/dist/ui/renderers/pipeline.markdown.d.ts +23 -0
  107. package/dist/ui/renderers/pipeline.markdown.d.ts.map +1 -0
  108. package/dist/ui/renderers/pipeline.markdown.js +118 -0
  109. package/dist/ui/renderers/pipeline.markdown.js.map +1 -0
  110. package/dist/ui/renderers/pipeline.renderer.d.ts +9 -0
  111. package/dist/ui/renderers/pipeline.renderer.d.ts.map +1 -0
  112. package/dist/ui/renderers/pipeline.renderer.js +28 -0
  113. package/dist/ui/renderers/pipeline.renderer.js.map +1 -0
  114. package/package.json +38 -13
  115. package/src/crm-pipeline.feature.ts +3 -3
  116. package/src/deal/deal.test-spec.ts +55 -0
  117. package/src/example.ts +3 -3
  118. package/src/handlers/crm.handlers.ts +415 -0
  119. package/src/handlers/index.ts +3 -0
  120. package/src/index.ts +1 -0
  121. package/src/presentations/dashboard.presentation.ts +5 -6
  122. package/src/presentations/pipeline.presentation.ts +9 -10
  123. package/src/seeders/index.ts +35 -0
  124. package/src/shared/overlay-types.ts +39 -0
  125. package/src/ui/CrmDashboard.tsx +311 -0
  126. package/src/ui/CrmDealCard.tsx +83 -0
  127. package/src/ui/CrmPipelineBoard.tsx +136 -0
  128. package/src/ui/hooks/index.ts +10 -0
  129. package/src/ui/hooks/useDealList.ts +113 -0
  130. package/src/ui/hooks/useDealMutations.ts +174 -0
  131. package/src/ui/index.ts +18 -0
  132. package/src/ui/modals/CreateDealModal.tsx +239 -0
  133. package/src/ui/modals/DealActionsModal.tsx +424 -0
  134. package/src/ui/modals/index.ts +2 -0
  135. package/src/ui/overlays/demo-overlays.ts +68 -0
  136. package/src/ui/overlays/index.ts +1 -0
  137. package/src/ui/renderers/index.ts +6 -0
  138. package/src/ui/renderers/pipeline.markdown.ts +198 -0
  139. package/src/ui/renderers/pipeline.renderer.tsx +35 -0
  140. package/tsconfig.json +1 -1
  141. package/tsconfig.tsbuildinfo +1 -1
@@ -0,0 +1,424 @@
1
+ 'use client';
2
+
3
+ /**
4
+ * DealActionsModal - Actions for a specific deal (Win, Lose, Move)
5
+ *
6
+ * Wires to WinDealContract, LoseDealContract, MoveDealContract
7
+ * via useDealMutations hook.
8
+ */
9
+ import { useState } from 'react';
10
+ import { Button } from '@contractspec/lib.design-system';
11
+
12
+ // Local type definitions for modal props
13
+ export interface Deal {
14
+ id: string;
15
+ name: string;
16
+ value: number;
17
+ currency: string;
18
+ stageId: string;
19
+ status: 'OPEN' | 'WON' | 'LOST' | 'STALE';
20
+ }
21
+
22
+ export interface WinDealInput {
23
+ dealId: string;
24
+ wonSource?: string;
25
+ notes?: string;
26
+ }
27
+
28
+ export interface LoseDealInput {
29
+ dealId: string;
30
+ lostReason: string;
31
+ notes?: string;
32
+ }
33
+
34
+ export interface MoveDealInput {
35
+ dealId: string;
36
+ stageId: string;
37
+ }
38
+
39
+ type ActionMode = 'menu' | 'win' | 'lose' | 'move';
40
+
41
+ interface DealActionsModalProps {
42
+ isOpen: boolean;
43
+ deal: Deal | null;
44
+ stages: { id: string; name: string }[];
45
+ onClose: () => void;
46
+ onWin: (input: WinDealInput) => Promise<void>;
47
+ onLose: (input: LoseDealInput) => Promise<void>;
48
+ onMove: (input: MoveDealInput) => Promise<void>;
49
+ isLoading?: boolean;
50
+ }
51
+
52
+ function formatCurrency(value: number, currency: string): string {
53
+ return new Intl.NumberFormat('en-US', {
54
+ style: 'currency',
55
+ currency,
56
+ minimumFractionDigits: 0,
57
+ maximumFractionDigits: 0,
58
+ }).format(value);
59
+ }
60
+
61
+ export function DealActionsModal({
62
+ isOpen,
63
+ deal,
64
+ stages,
65
+ onClose,
66
+ onWin,
67
+ onLose,
68
+ onMove,
69
+ isLoading = false,
70
+ }: DealActionsModalProps) {
71
+ const [mode, setMode] = useState<ActionMode>('menu');
72
+ const [wonSource, setWonSource] = useState('');
73
+ const [lostReason, setLostReason] = useState('');
74
+ const [notes, setNotes] = useState('');
75
+ const [selectedStageId, setSelectedStageId] = useState('');
76
+ const [error, setError] = useState<string | null>(null);
77
+
78
+ const resetForm = () => {
79
+ setMode('menu');
80
+ setWonSource('');
81
+ setLostReason('');
82
+ setNotes('');
83
+ setSelectedStageId('');
84
+ setError(null);
85
+ };
86
+
87
+ const handleClose = () => {
88
+ resetForm();
89
+ onClose();
90
+ };
91
+
92
+ const handleWin = async () => {
93
+ if (!deal) return;
94
+ setError(null);
95
+
96
+ try {
97
+ await onWin({
98
+ dealId: deal.id,
99
+ wonSource: wonSource.trim() || undefined,
100
+ notes: notes.trim() || undefined,
101
+ });
102
+ handleClose();
103
+ } catch (err) {
104
+ setError(
105
+ err instanceof Error ? err.message : 'Failed to mark deal as won'
106
+ );
107
+ }
108
+ };
109
+
110
+ const handleLose = async () => {
111
+ if (!deal) return;
112
+ setError(null);
113
+
114
+ if (!lostReason.trim()) {
115
+ setError('Please provide a reason for losing the deal');
116
+ return;
117
+ }
118
+
119
+ try {
120
+ await onLose({
121
+ dealId: deal.id,
122
+ lostReason: lostReason.trim(),
123
+ notes: notes.trim() || undefined,
124
+ });
125
+ handleClose();
126
+ } catch (err) {
127
+ setError(
128
+ err instanceof Error ? err.message : 'Failed to mark deal as lost'
129
+ );
130
+ }
131
+ };
132
+
133
+ const handleMove = async () => {
134
+ if (!deal) return;
135
+ setError(null);
136
+
137
+ if (!selectedStageId) {
138
+ setError('Please select a stage');
139
+ return;
140
+ }
141
+
142
+ if (selectedStageId === deal.stageId) {
143
+ setError('Deal is already in this stage');
144
+ return;
145
+ }
146
+
147
+ try {
148
+ await onMove({
149
+ dealId: deal.id,
150
+ stageId: selectedStageId,
151
+ });
152
+ handleClose();
153
+ } catch (err) {
154
+ setError(err instanceof Error ? err.message : 'Failed to move deal');
155
+ }
156
+ };
157
+
158
+ if (!isOpen || !deal) return null;
159
+
160
+ return (
161
+ <div className="fixed inset-0 z-50 flex items-center justify-center">
162
+ {/* Backdrop */}
163
+ <div
164
+ className="bg-background/80 absolute inset-0 backdrop-blur-sm"
165
+ onClick={handleClose}
166
+ role="button"
167
+ tabIndex={0}
168
+ onKeyDown={(e) => {
169
+ if (e.key === 'Enter' || e.key === ' ') handleClose();
170
+ }}
171
+ aria-label="Close modal"
172
+ />
173
+
174
+ {/* Modal */}
175
+ <div className="bg-card border-border relative z-10 w-full max-w-md rounded-xl border p-6 shadow-xl">
176
+ {/* Deal Header */}
177
+ <div className="border-border mb-4 border-b pb-4">
178
+ <h2 className="text-xl font-semibold">{deal.name}</h2>
179
+ <p className="text-primary text-lg font-medium">
180
+ {formatCurrency(deal.value, deal.currency)}
181
+ </p>
182
+ <span
183
+ className={`mt-2 inline-flex rounded-full px-2 py-0.5 text-xs font-medium ${
184
+ deal.status === 'WON'
185
+ ? 'bg-green-100 text-green-700 dark:bg-green-900/30 dark:text-green-400'
186
+ : deal.status === 'LOST'
187
+ ? 'bg-red-100 text-red-700 dark:bg-red-900/30 dark:text-red-400'
188
+ : 'bg-blue-100 text-blue-700 dark:bg-blue-900/30 dark:text-blue-400'
189
+ }`}
190
+ >
191
+ {deal.status}
192
+ </span>
193
+ </div>
194
+
195
+ {/* Main Menu */}
196
+ {mode === 'menu' && (
197
+ <div className="space-y-3">
198
+ {deal.status === 'OPEN' && (
199
+ <>
200
+ <Button
201
+ className="w-full justify-start"
202
+ variant="ghost"
203
+ onPress={() => setMode('win')}
204
+ >
205
+ <span className="mr-2">🏆</span> Mark as Won
206
+ </Button>
207
+ <Button
208
+ className="w-full justify-start"
209
+ variant="ghost"
210
+ onPress={() => setMode('lose')}
211
+ >
212
+ <span className="mr-2">❌</span> Mark as Lost
213
+ </Button>
214
+ <Button
215
+ className="w-full justify-start"
216
+ variant="ghost"
217
+ onPress={() => {
218
+ setSelectedStageId(deal.stageId);
219
+ setMode('move');
220
+ }}
221
+ >
222
+ <span className="mr-2">➡️</span> Move to Stage
223
+ </Button>
224
+ </>
225
+ )}
226
+ {deal.status !== 'OPEN' && (
227
+ <p className="text-muted-foreground py-4 text-center">
228
+ This deal is already {deal.status.toLowerCase()}. No actions
229
+ available.
230
+ </p>
231
+ )}
232
+ <div className="border-border border-t pt-3">
233
+ <Button
234
+ className="w-full"
235
+ variant="outline"
236
+ onPress={handleClose}
237
+ >
238
+ Close
239
+ </Button>
240
+ </div>
241
+ </div>
242
+ )}
243
+
244
+ {/* Win Form */}
245
+ {mode === 'win' && (
246
+ <div className="space-y-4">
247
+ <div>
248
+ <label
249
+ htmlFor="won-source"
250
+ className="text-muted-foreground mb-1 block text-sm font-medium"
251
+ >
252
+ How did you win this deal?
253
+ </label>
254
+ <select
255
+ id="won-source"
256
+ value={wonSource}
257
+ onChange={(e) => setWonSource(e.target.value)}
258
+ className="border-input bg-background focus:ring-ring h-10 w-full rounded-md border px-3 py-2 text-sm focus:ring-2 focus:outline-none"
259
+ >
260
+ <option value="">Select a source...</option>
261
+ <option value="referral">Referral</option>
262
+ <option value="cold_outreach">Cold Outreach</option>
263
+ <option value="inbound">Inbound Lead</option>
264
+ <option value="upsell">Upsell</option>
265
+ <option value="other">Other</option>
266
+ </select>
267
+ </div>
268
+
269
+ <div>
270
+ <label
271
+ htmlFor="win-notes"
272
+ className="text-muted-foreground mb-1 block text-sm font-medium"
273
+ >
274
+ Notes (optional)
275
+ </label>
276
+ <textarea
277
+ id="win-notes"
278
+ value={notes}
279
+ onChange={(e) => setNotes(e.target.value)}
280
+ placeholder="Any additional notes about the win..."
281
+ rows={3}
282
+ className="border-input bg-background focus:ring-ring w-full rounded-md border px-3 py-2 text-sm focus:ring-2 focus:outline-none"
283
+ />
284
+ </div>
285
+
286
+ {error && (
287
+ <div className="bg-destructive/10 text-destructive rounded-md p-3 text-sm">
288
+ {error}
289
+ </div>
290
+ )}
291
+
292
+ <div className="flex justify-end gap-3 pt-2">
293
+ <Button
294
+ variant="ghost"
295
+ onPress={() => setMode('menu')}
296
+ disabled={isLoading}
297
+ >
298
+ Back
299
+ </Button>
300
+ <Button onPress={handleWin} disabled={isLoading}>
301
+ {isLoading ? 'Processing...' : '🏆 Confirm Win'}
302
+ </Button>
303
+ </div>
304
+ </div>
305
+ )}
306
+
307
+ {/* Lose Form */}
308
+ {mode === 'lose' && (
309
+ <div className="space-y-4">
310
+ <div>
311
+ <label
312
+ htmlFor="lost-reason"
313
+ className="text-muted-foreground mb-1 block text-sm font-medium"
314
+ >
315
+ Why was this deal lost? *
316
+ </label>
317
+ <select
318
+ id="lost-reason"
319
+ value={lostReason}
320
+ onChange={(e) => setLostReason(e.target.value)}
321
+ className="border-input bg-background focus:ring-ring h-10 w-full rounded-md border px-3 py-2 text-sm focus:ring-2 focus:outline-none"
322
+ >
323
+ <option value="">Select a reason...</option>
324
+ <option value="price">Price too high</option>
325
+ <option value="competitor">Lost to competitor</option>
326
+ <option value="no_budget">No budget</option>
327
+ <option value="no_decision">No decision made</option>
328
+ <option value="timing">Bad timing</option>
329
+ <option value="product_fit">Product not a fit</option>
330
+ <option value="other">Other</option>
331
+ </select>
332
+ </div>
333
+
334
+ <div>
335
+ <label
336
+ htmlFor="lose-notes"
337
+ className="text-muted-foreground mb-1 block text-sm font-medium"
338
+ >
339
+ Notes (optional)
340
+ </label>
341
+ <textarea
342
+ id="lose-notes"
343
+ value={notes}
344
+ onChange={(e) => setNotes(e.target.value)}
345
+ placeholder="Any additional details..."
346
+ rows={3}
347
+ className="border-input bg-background focus:ring-ring w-full rounded-md border px-3 py-2 text-sm focus:ring-2 focus:outline-none"
348
+ />
349
+ </div>
350
+
351
+ {error && (
352
+ <div className="bg-destructive/10 text-destructive rounded-md p-3 text-sm">
353
+ {error}
354
+ </div>
355
+ )}
356
+
357
+ <div className="flex justify-end gap-3 pt-2">
358
+ <Button
359
+ variant="ghost"
360
+ onPress={() => setMode('menu')}
361
+ disabled={isLoading}
362
+ >
363
+ Back
364
+ </Button>
365
+ <Button
366
+ variant="destructive"
367
+ onPress={handleLose}
368
+ disabled={isLoading}
369
+ >
370
+ {isLoading ? 'Processing...' : '❌ Confirm Loss'}
371
+ </Button>
372
+ </div>
373
+ </div>
374
+ )}
375
+
376
+ {/* Move Form */}
377
+ {mode === 'move' && (
378
+ <div className="space-y-4">
379
+ <div>
380
+ <label
381
+ htmlFor="move-stage"
382
+ className="text-muted-foreground mb-1 block text-sm font-medium"
383
+ >
384
+ Move to Stage
385
+ </label>
386
+ <select
387
+ id="move-stage"
388
+ value={selectedStageId}
389
+ onChange={(e) => setSelectedStageId(e.target.value)}
390
+ className="border-input bg-background focus:ring-ring h-10 w-full rounded-md border px-3 py-2 text-sm focus:ring-2 focus:outline-none"
391
+ >
392
+ {stages.map((stage) => (
393
+ <option key={stage.id} value={stage.id}>
394
+ {stage.name}
395
+ {stage.id === deal.stageId ? ' (current)' : ''}
396
+ </option>
397
+ ))}
398
+ </select>
399
+ </div>
400
+
401
+ {error && (
402
+ <div className="bg-destructive/10 text-destructive rounded-md p-3 text-sm">
403
+ {error}
404
+ </div>
405
+ )}
406
+
407
+ <div className="flex justify-end gap-3 pt-2">
408
+ <Button
409
+ variant="ghost"
410
+ onPress={() => setMode('menu')}
411
+ disabled={isLoading}
412
+ >
413
+ Back
414
+ </Button>
415
+ <Button onPress={handleMove} disabled={isLoading}>
416
+ {isLoading ? 'Moving...' : '➡️ Move Deal'}
417
+ </Button>
418
+ </div>
419
+ </div>
420
+ )}
421
+ </div>
422
+ </div>
423
+ );
424
+ }
@@ -0,0 +1,2 @@
1
+ export { CreateDealModal } from './CreateDealModal';
2
+ export { DealActionsModal } from './DealActionsModal';
@@ -0,0 +1,68 @@
1
+ /**
2
+ * Demo Overlay Definitions for CRM Pipeline
3
+ *
4
+ * These overlays customize the presentation for different contexts
5
+ * (e.g., demo users, different roles).
6
+ */
7
+ import type { OverlayDefinition } from '../../shared/overlay-types';
8
+
9
+ /**
10
+ * Demo user overlay - sample data mode
11
+ */
12
+ export const crmDemoOverlay: OverlayDefinition = {
13
+ overlayId: 'crm-pipeline.demo-user',
14
+ version: '1.0.0',
15
+ description: 'Demo mode with sample data',
16
+ appliesTo: {
17
+ feature: 'crm-pipeline',
18
+ role: 'demo',
19
+ },
20
+ modifications: [
21
+ {
22
+ type: 'hideField',
23
+ field: 'importButton',
24
+ reason: 'Not available in demo',
25
+ },
26
+ {
27
+ type: 'hideField',
28
+ field: 'exportButton',
29
+ reason: 'Not available in demo',
30
+ },
31
+ {
32
+ type: 'addBadge',
33
+ position: 'header',
34
+ label: 'Demo Mode',
35
+ variant: 'warning',
36
+ },
37
+ ],
38
+ };
39
+
40
+ /**
41
+ * Sales rep overlay - focused view for sales
42
+ */
43
+ export const crmSalesRepOverlay: OverlayDefinition = {
44
+ overlayId: 'crm-pipeline.sales-rep',
45
+ version: '1.0.0',
46
+ description: 'Sales rep focused view',
47
+ appliesTo: {
48
+ feature: 'crm-pipeline',
49
+ role: 'sales-rep',
50
+ },
51
+ modifications: [
52
+ {
53
+ type: 'hideField',
54
+ field: 'teamMetrics',
55
+ reason: 'Team metrics for managers only',
56
+ },
57
+ { type: 'hideField', field: 'pipelineSettings', reason: 'Admin only' },
58
+ { type: 'renameLabel', field: 'deals', newLabel: 'My Deals' },
59
+ ],
60
+ };
61
+
62
+ /**
63
+ * All overlays for crm-pipeline
64
+ */
65
+ export const crmOverlays: OverlayDefinition[] = [
66
+ crmDemoOverlay,
67
+ crmSalesRepOverlay,
68
+ ];
@@ -0,0 +1 @@
1
+ export * from './demo-overlays';
@@ -0,0 +1,6 @@
1
+ // CRM Pipeline renderers
2
+ export { crmPipelineReactRenderer } from './pipeline.renderer';
3
+ export {
4
+ crmPipelineMarkdownRenderer,
5
+ crmDashboardMarkdownRenderer,
6
+ } from './pipeline.markdown';
@@ -0,0 +1,198 @@
1
+ /**
2
+ * Markdown renderer for CRM Pipeline presentation
3
+ *
4
+ * Imports handlers from the hooks module to ensure correct build order.
5
+ */
6
+ import type { PresentationRenderer } from '@contractspec/lib.contracts';
7
+ import {
8
+ mockListDealsHandler,
9
+ mockGetPipelineStagesHandler,
10
+ } from '@contractspec/example.crm-pipeline/handlers';
11
+
12
+ interface DealItem {
13
+ id: string;
14
+ name: string;
15
+ value: number;
16
+ currency: string;
17
+ stageId: string;
18
+ status: string;
19
+ }
20
+
21
+ interface StageItem {
22
+ id: string;
23
+ name: string;
24
+ position: number;
25
+ }
26
+
27
+ function formatCurrency(value: number, currency = 'USD'): string {
28
+ return new Intl.NumberFormat('en-US', {
29
+ style: 'currency',
30
+ currency,
31
+ minimumFractionDigits: 0,
32
+ }).format(value);
33
+ }
34
+
35
+ /**
36
+ * Markdown renderer for CRM Pipeline Kanban view (crm-pipeline.deal.pipeline)
37
+ * Only handles PipelineKanbanView component
38
+ */
39
+ export const crmPipelineMarkdownRenderer: PresentationRenderer<{
40
+ mimeType: string;
41
+ body: string;
42
+ }> = {
43
+ target: 'markdown',
44
+ render: async (desc, _ctx) => {
45
+ // Only handle PipelineKanbanView
46
+ if (
47
+ desc.source.type !== 'component' ||
48
+ desc.source.componentKey !== 'PipelineKanbanView'
49
+ ) {
50
+ throw new Error('crmPipelineMarkdownRenderer: not PipelineKanbanView');
51
+ }
52
+
53
+ const pipelineId = 'pipeline-1';
54
+ const [dealsResult, stages] = await Promise.all([
55
+ mockListDealsHandler({ pipelineId, limit: 50 }),
56
+ mockGetPipelineStagesHandler({ pipelineId }),
57
+ ]);
58
+
59
+ const deals = dealsResult.deals as DealItem[];
60
+ const stageList = stages as StageItem[];
61
+
62
+ // Group deals by stage
63
+ const dealsByStage: Record<string, DealItem[]> = {};
64
+ for (const stage of stageList) {
65
+ dealsByStage[stage.id] = deals.filter(
66
+ (d) => d.stageId === stage.id && d.status === 'OPEN'
67
+ );
68
+ }
69
+
70
+ // Build Markdown
71
+ const lines: string[] = [
72
+ '# CRM Pipeline',
73
+ '',
74
+ `**Total Value**: ${formatCurrency(dealsResult.totalValue)}`,
75
+ `**Total Deals**: ${dealsResult.total}`,
76
+ '',
77
+ ];
78
+
79
+ for (const stage of stageList.sort((a, b) => a.position - b.position)) {
80
+ const stageDeals = dealsByStage[stage.id] ?? [];
81
+ const stageValue = stageDeals.reduce((sum, d) => sum + d.value, 0);
82
+
83
+ lines.push(`## ${stage.name}`);
84
+ lines.push(
85
+ `_${stageDeals.length} deals · ${formatCurrency(stageValue)}_`
86
+ );
87
+ lines.push('');
88
+
89
+ if (stageDeals.length === 0) {
90
+ lines.push('_No deals_');
91
+ } else {
92
+ for (const deal of stageDeals) {
93
+ lines.push(
94
+ `- **${deal.name}** - ${formatCurrency(deal.value, deal.currency)}`
95
+ );
96
+ }
97
+ }
98
+
99
+ lines.push('');
100
+ }
101
+
102
+ return {
103
+ mimeType: 'text/markdown',
104
+ body: lines.join('\n'),
105
+ };
106
+ },
107
+ };
108
+
109
+ /**
110
+ * Markdown renderer for CRM Dashboard (crm-pipeline.dashboard)
111
+ * Only handles CrmDashboard component
112
+ */
113
+ export const crmDashboardMarkdownRenderer: PresentationRenderer<{
114
+ mimeType: string;
115
+ body: string;
116
+ }> = {
117
+ target: 'markdown',
118
+ render: async (desc, _ctx) => {
119
+ // Only handle CrmDashboard
120
+ if (
121
+ desc.source.type !== 'component' ||
122
+ desc.source.componentKey !== 'CrmDashboard'
123
+ ) {
124
+ throw new Error('crmDashboardMarkdownRenderer: not CrmDashboard');
125
+ }
126
+
127
+ const pipelineId = 'pipeline-1';
128
+ const [dealsResult, stages] = await Promise.all([
129
+ mockListDealsHandler({ pipelineId, limit: 100 }),
130
+ mockGetPipelineStagesHandler({ pipelineId }),
131
+ ]);
132
+
133
+ const deals = dealsResult.deals as DealItem[];
134
+ const stageList = stages as StageItem[];
135
+
136
+ // Calculate stats
137
+ const openDeals = deals.filter((d) => d.status === 'OPEN');
138
+ const wonDeals = deals.filter((d) => d.status === 'WON');
139
+ const lostDeals = deals.filter((d) => d.status === 'LOST');
140
+ const openValue = openDeals.reduce((sum, d) => sum + d.value, 0);
141
+ const wonValue = wonDeals.reduce((sum, d) => sum + d.value, 0);
142
+
143
+ // Build dashboard markdown
144
+ const lines: string[] = [
145
+ '# CRM Dashboard',
146
+ '',
147
+ '> Sales pipeline overview and key metrics',
148
+ '',
149
+ '## Summary',
150
+ '',
151
+ '| Metric | Value |',
152
+ '|--------|-------|',
153
+ `| Total Deals | ${dealsResult.total} |`,
154
+ `| Pipeline Value | ${formatCurrency(dealsResult.totalValue)} |`,
155
+ `| Open Deals | ${openDeals.length} (${formatCurrency(openValue)}) |`,
156
+ `| Won Deals | ${wonDeals.length} (${formatCurrency(wonValue)}) |`,
157
+ `| Lost Deals | ${lostDeals.length} |`,
158
+ '',
159
+ '## Pipeline Stages',
160
+ '',
161
+ ];
162
+
163
+ // Stage summary table
164
+ lines.push('| Stage | Deals | Value |');
165
+ lines.push('|-------|-------|-------|');
166
+ for (const stage of stageList.sort((a, b) => a.position - b.position)) {
167
+ const stageDeals = openDeals.filter((d) => d.stageId === stage.id);
168
+ const stageValue = stageDeals.reduce((sum, d) => sum + d.value, 0);
169
+ lines.push(
170
+ `| ${stage.name} | ${stageDeals.length} | ${formatCurrency(stageValue)} |`
171
+ );
172
+ }
173
+
174
+ lines.push('');
175
+ lines.push('## Recent Deals');
176
+ lines.push('');
177
+
178
+ // Top 10 recent deals
179
+ const recentDeals = deals.slice(0, 10);
180
+ if (recentDeals.length === 0) {
181
+ lines.push('_No deals yet._');
182
+ } else {
183
+ lines.push('| Deal | Value | Stage | Status |');
184
+ lines.push('|------|-------|-------|--------|');
185
+ for (const deal of recentDeals) {
186
+ const stage = stageList.find((s) => s.id === deal.stageId);
187
+ lines.push(
188
+ `| ${deal.name} | ${formatCurrency(deal.value, deal.currency)} | ${stage?.name ?? '-'} | ${deal.status} |`
189
+ );
190
+ }
191
+ }
192
+
193
+ return {
194
+ mimeType: 'text/markdown',
195
+ body: lines.join('\n'),
196
+ };
197
+ },
198
+ };