@contractspec/example.crm-pipeline 1.46.1 → 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 (132) hide show
  1. package/.turbo/turbo-build$colon$bundle.log +106 -31
  2. package/.turbo/turbo-build.log +109 -34
  3. package/CHANGELOG.md +44 -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.operation.d.ts +6 -6
  9. package/dist/deal/deal.test-spec.d.ts +8 -0
  10. package/dist/deal/deal.test-spec.d.ts.map +1 -0
  11. package/dist/deal/deal.test-spec.js +65 -0
  12. package/dist/deal/deal.test-spec.js.map +1 -0
  13. package/dist/entities/company.entity.d.ts +28 -28
  14. package/dist/entities/contact.entity.d.ts +32 -32
  15. package/dist/entities/index.js.map +1 -1
  16. package/dist/entities/task.entity.d.ts +43 -43
  17. package/dist/events/contact.event.d.ts +8 -8
  18. package/dist/events/contact.event.js +1 -1
  19. package/dist/events/deal.event.d.ts +5 -5
  20. package/dist/events/deal.event.js +1 -1
  21. package/dist/events/task.event.d.ts +2 -2
  22. package/dist/events/task.event.d.ts.map +1 -1
  23. package/dist/events/task.event.js +1 -1
  24. package/dist/example.d.ts +2 -2
  25. package/dist/example.d.ts.map +1 -1
  26. package/dist/example.js +4 -2
  27. package/dist/example.js.map +1 -1
  28. package/dist/handlers/crm.handlers.d.ts +89 -0
  29. package/dist/handlers/crm.handlers.d.ts.map +1 -0
  30. package/dist/handlers/crm.handlers.js +172 -0
  31. package/dist/handlers/crm.handlers.js.map +1 -0
  32. package/dist/handlers/deal.handlers.js.map +1 -1
  33. package/dist/handlers/index.d.ts +2 -1
  34. package/dist/handlers/index.js +2 -1
  35. package/dist/handlers/mock-data.js.map +1 -1
  36. package/dist/index.d.ts +14 -1
  37. package/dist/index.d.ts.map +1 -1
  38. package/dist/index.js +14 -1
  39. package/dist/index.js.map +1 -1
  40. package/dist/presentations/dashboard.presentation.d.ts +3 -4
  41. package/dist/presentations/dashboard.presentation.d.ts.map +1 -1
  42. package/dist/presentations/dashboard.presentation.js +8 -5
  43. package/dist/presentations/dashboard.presentation.js.map +1 -1
  44. package/dist/presentations/pipeline.presentation.d.ts +5 -6
  45. package/dist/presentations/pipeline.presentation.d.ts.map +1 -1
  46. package/dist/presentations/pipeline.presentation.js +12 -9
  47. package/dist/presentations/pipeline.presentation.js.map +1 -1
  48. package/dist/seeders/index.d.ts +10 -0
  49. package/dist/seeders/index.d.ts.map +1 -0
  50. package/dist/seeders/index.js +47 -0
  51. package/dist/seeders/index.js.map +1 -0
  52. package/dist/shared/overlay-types.d.ts +34 -0
  53. package/dist/shared/overlay-types.d.ts.map +1 -0
  54. package/dist/shared/overlay-types.js +0 -0
  55. package/dist/ui/CrmDashboard.d.ts +7 -0
  56. package/dist/ui/CrmDashboard.d.ts.map +1 -0
  57. package/dist/ui/CrmDashboard.js +304 -0
  58. package/dist/ui/CrmDashboard.js.map +1 -0
  59. package/dist/ui/CrmDealCard.d.ts +15 -0
  60. package/dist/ui/CrmDealCard.d.ts.map +1 -0
  61. package/dist/ui/CrmDealCard.js +49 -0
  62. package/dist/ui/CrmDealCard.js.map +1 -0
  63. package/dist/ui/CrmPipelineBoard.d.ts +23 -0
  64. package/dist/ui/CrmPipelineBoard.d.ts.map +1 -0
  65. package/dist/ui/CrmPipelineBoard.js +98 -0
  66. package/dist/ui/CrmPipelineBoard.js.map +1 -0
  67. package/dist/ui/hooks/index.d.ts +3 -0
  68. package/dist/ui/hooks/index.js +6 -0
  69. package/dist/ui/hooks/useDealList.d.ts +35 -0
  70. package/dist/ui/hooks/useDealList.d.ts.map +1 -0
  71. package/dist/ui/hooks/useDealList.js +94 -0
  72. package/dist/ui/hooks/useDealList.js.map +1 -0
  73. package/dist/ui/hooks/useDealMutations.d.ts +26 -0
  74. package/dist/ui/hooks/useDealMutations.d.ts.map +1 -0
  75. package/dist/ui/hooks/useDealMutations.js +159 -0
  76. package/dist/ui/hooks/useDealMutations.js.map +1 -0
  77. package/dist/ui/index.d.ts +14 -0
  78. package/dist/ui/index.js +15 -0
  79. package/dist/ui/modals/CreateDealModal.d.ts +33 -0
  80. package/dist/ui/modals/CreateDealModal.d.ts.map +1 -0
  81. package/dist/ui/modals/CreateDealModal.js +183 -0
  82. package/dist/ui/modals/CreateDealModal.js.map +1 -0
  83. package/dist/ui/modals/DealActionsModal.d.ts +51 -0
  84. package/dist/ui/modals/DealActionsModal.d.ts.map +1 -0
  85. package/dist/ui/modals/DealActionsModal.js +372 -0
  86. package/dist/ui/modals/DealActionsModal.js.map +1 -0
  87. package/dist/ui/modals/index.d.ts +3 -0
  88. package/dist/ui/modals/index.js +4 -0
  89. package/dist/ui/overlays/demo-overlays.d.ts +19 -0
  90. package/dist/ui/overlays/demo-overlays.d.ts.map +1 -0
  91. package/dist/ui/overlays/demo-overlays.js +68 -0
  92. package/dist/ui/overlays/demo-overlays.js.map +1 -0
  93. package/dist/ui/overlays/index.d.ts +2 -0
  94. package/dist/ui/overlays/index.js +3 -0
  95. package/dist/ui/renderers/index.d.ts +3 -0
  96. package/dist/ui/renderers/index.js +4 -0
  97. package/dist/ui/renderers/pipeline.markdown.d.ts +23 -0
  98. package/dist/ui/renderers/pipeline.markdown.d.ts.map +1 -0
  99. package/dist/ui/renderers/pipeline.markdown.js +118 -0
  100. package/dist/ui/renderers/pipeline.markdown.js.map +1 -0
  101. package/dist/ui/renderers/pipeline.renderer.d.ts +9 -0
  102. package/dist/ui/renderers/pipeline.renderer.d.ts.map +1 -0
  103. package/dist/ui/renderers/pipeline.renderer.js +28 -0
  104. package/dist/ui/renderers/pipeline.renderer.js.map +1 -0
  105. package/package.json +38 -13
  106. package/src/crm-pipeline.feature.ts +3 -3
  107. package/src/deal/deal.test-spec.ts +55 -0
  108. package/src/example.ts +3 -3
  109. package/src/handlers/crm.handlers.ts +415 -0
  110. package/src/handlers/index.ts +3 -0
  111. package/src/index.ts +1 -0
  112. package/src/presentations/dashboard.presentation.ts +5 -6
  113. package/src/presentations/pipeline.presentation.ts +9 -10
  114. package/src/seeders/index.ts +35 -0
  115. package/src/shared/overlay-types.ts +39 -0
  116. package/src/ui/CrmDashboard.tsx +311 -0
  117. package/src/ui/CrmDealCard.tsx +83 -0
  118. package/src/ui/CrmPipelineBoard.tsx +136 -0
  119. package/src/ui/hooks/index.ts +10 -0
  120. package/src/ui/hooks/useDealList.ts +113 -0
  121. package/src/ui/hooks/useDealMutations.ts +174 -0
  122. package/src/ui/index.ts +18 -0
  123. package/src/ui/modals/CreateDealModal.tsx +239 -0
  124. package/src/ui/modals/DealActionsModal.tsx +424 -0
  125. package/src/ui/modals/index.ts +2 -0
  126. package/src/ui/overlays/demo-overlays.ts +68 -0
  127. package/src/ui/overlays/index.ts +1 -0
  128. package/src/ui/renderers/index.ts +6 -0
  129. package/src/ui/renderers/pipeline.markdown.ts +198 -0
  130. package/src/ui/renderers/pipeline.renderer.tsx +35 -0
  131. package/tsconfig.json +1 -1
  132. package/tsconfig.tsbuildinfo +1 -1
@@ -0,0 +1,415 @@
1
+ /**
2
+ * Runtime-local CRM handlers
3
+ *
4
+ * These handlers work with the in-browser SQLite database
5
+ * instead of in-memory mock arrays.
6
+ */
7
+ import type { DatabasePort, DbRow } from '@contractspec/lib.runtime-sandbox';
8
+ /* eslint-disable @typescript-eslint/no-non-null-assertion */
9
+ import { web } from '@contractspec/lib.runtime-sandbox';
10
+ const { generateId } = web;
11
+
12
+ // ============ Types ============
13
+
14
+ export interface Deal {
15
+ id: string;
16
+ projectId: string;
17
+ name: string;
18
+ value: number;
19
+ currency: string;
20
+ pipelineId: string;
21
+ stageId: string;
22
+ status: 'OPEN' | 'WON' | 'LOST' | 'STALE';
23
+ contactId?: string;
24
+ companyId?: string;
25
+ ownerId: string;
26
+ expectedCloseDate?: Date;
27
+ wonSource?: string;
28
+ lostReason?: string;
29
+ notes?: string;
30
+ createdAt: Date;
31
+ updatedAt: Date;
32
+ }
33
+
34
+ export interface Stage {
35
+ id: string;
36
+ pipelineId: string;
37
+ name: string;
38
+ position: number;
39
+ }
40
+
41
+ export interface CreateDealInput {
42
+ name: string;
43
+ value: number;
44
+ currency?: string;
45
+ pipelineId: string;
46
+ stageId: string;
47
+ contactId?: string;
48
+ companyId?: string;
49
+ expectedCloseDate?: Date;
50
+ }
51
+
52
+ export interface MoveDealInput {
53
+ dealId: string;
54
+ stageId: string;
55
+ }
56
+
57
+ export interface WinDealInput {
58
+ dealId: string;
59
+ wonSource?: string;
60
+ notes?: string;
61
+ }
62
+
63
+ export interface LoseDealInput {
64
+ dealId: string;
65
+ lostReason: string;
66
+ notes?: string;
67
+ }
68
+
69
+ export interface ListDealsInput {
70
+ projectId: string;
71
+ pipelineId?: string;
72
+ stageId?: string;
73
+ status?: 'OPEN' | 'WON' | 'LOST' | 'all';
74
+ ownerId?: string;
75
+ search?: string;
76
+ limit?: number;
77
+ offset?: number;
78
+ }
79
+
80
+ export interface ListDealsOutput {
81
+ deals: Deal[];
82
+ total: number;
83
+ totalValue: number;
84
+ }
85
+
86
+ // ============ Row Type ============
87
+
88
+ // Note: We don't use DbRow generics here - just cast the results
89
+ // to the expected types since we know the schema
90
+
91
+ interface DealRow {
92
+ id: string;
93
+ projectId: string;
94
+ name: string;
95
+ value: number;
96
+ currency: string;
97
+ pipelineId: string;
98
+ stageId: string;
99
+ status: string;
100
+ contactId: string | null;
101
+ companyId: string | null;
102
+ ownerId: string;
103
+ expectedCloseDate: string | null;
104
+ wonSource: string | null;
105
+ lostReason: string | null;
106
+ notes: string | null;
107
+ createdAt: string;
108
+ updatedAt: string;
109
+ }
110
+
111
+ interface StageRow {
112
+ id: string;
113
+ pipelineId: string;
114
+ name: string;
115
+ position: number;
116
+ }
117
+
118
+ function rowToDeal(row: DealRow): Deal {
119
+ return {
120
+ id: row.id,
121
+ projectId: row.projectId,
122
+ name: row.name,
123
+ value: row.value,
124
+ currency: row.currency,
125
+ pipelineId: row.pipelineId,
126
+ stageId: row.stageId,
127
+ status: row.status as Deal['status'],
128
+ contactId: row.contactId ?? undefined,
129
+ companyId: row.companyId ?? undefined,
130
+ ownerId: row.ownerId,
131
+ expectedCloseDate: row.expectedCloseDate
132
+ ? new Date(row.expectedCloseDate)
133
+ : undefined,
134
+ wonSource: row.wonSource ?? undefined,
135
+ lostReason: row.lostReason ?? undefined,
136
+ notes: row.notes ?? undefined,
137
+ createdAt: new Date(row.createdAt),
138
+ updatedAt: new Date(row.updatedAt),
139
+ };
140
+ }
141
+
142
+ // ============ Handler Factory ============
143
+
144
+ export function createCrmHandlers(db: DatabasePort) {
145
+ /**
146
+ * List deals with filtering
147
+ */
148
+ async function listDeals(input: ListDealsInput): Promise<ListDealsOutput> {
149
+ const {
150
+ projectId,
151
+ pipelineId,
152
+ stageId,
153
+ status,
154
+ ownerId,
155
+ search,
156
+ limit = 20,
157
+ offset = 0,
158
+ } = input;
159
+
160
+ let whereClause = 'WHERE projectId = ?';
161
+ const params: (string | number)[] = [projectId];
162
+
163
+ if (pipelineId) {
164
+ whereClause += ' AND pipelineId = ?';
165
+ params.push(pipelineId);
166
+ }
167
+
168
+ if (stageId) {
169
+ whereClause += ' AND stageId = ?';
170
+ params.push(stageId);
171
+ }
172
+
173
+ if (status && status !== 'all') {
174
+ whereClause += ' AND status = ?';
175
+ params.push(status);
176
+ }
177
+
178
+ if (ownerId) {
179
+ whereClause += ' AND ownerId = ?';
180
+ params.push(ownerId);
181
+ }
182
+
183
+ if (search) {
184
+ whereClause += ' AND name LIKE ?';
185
+ params.push(`%${search}%`);
186
+ }
187
+
188
+ // Get total count
189
+ const countResult = (
190
+ await db.query(
191
+ `SELECT COUNT(*) as count FROM crm_deal ${whereClause}`,
192
+ params
193
+ )
194
+ ).rows as DbRow[];
195
+ const total = (countResult[0]?.count as number) ?? 0;
196
+
197
+ // Get total value
198
+ const valueResult = (
199
+ await db.query(
200
+ `SELECT COALESCE(SUM(value), 0) as total FROM crm_deal ${whereClause}`,
201
+ params
202
+ )
203
+ ).rows as DbRow[];
204
+ const totalValue = (valueResult[0]?.total as number) ?? 0;
205
+
206
+ // Get paginated deals
207
+ const dealRows = (
208
+ await db.query(
209
+ `SELECT * FROM crm_deal ${whereClause} ORDER BY value DESC LIMIT ? OFFSET ?`,
210
+ [...params, limit, offset]
211
+ )
212
+ ).rows as unknown as DealRow[];
213
+
214
+ return {
215
+ deals: dealRows.map(rowToDeal),
216
+ total,
217
+ totalValue,
218
+ };
219
+ }
220
+
221
+ /**
222
+ * Create a new deal
223
+ */
224
+ async function createDeal(
225
+ input: CreateDealInput,
226
+ context: { projectId: string; ownerId: string }
227
+ ): Promise<Deal> {
228
+ const id = generateId('deal');
229
+ const now = new Date().toISOString();
230
+
231
+ await db.execute(
232
+ `INSERT INTO crm_deal (id, projectId, pipelineId, stageId, name, value, currency, status, contactId, companyId, ownerId, expectedCloseDate, createdAt, updatedAt)
233
+ VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)`,
234
+ [
235
+ id,
236
+ context.projectId,
237
+ input.pipelineId,
238
+ input.stageId,
239
+ input.name,
240
+ input.value,
241
+ input.currency ?? 'USD',
242
+ 'OPEN',
243
+ input.contactId ?? null,
244
+ input.companyId ?? null,
245
+ context.ownerId,
246
+ input.expectedCloseDate?.toISOString() ?? null,
247
+ now,
248
+ now,
249
+ ]
250
+ );
251
+
252
+ const rows = (await db.query(`SELECT * FROM crm_deal WHERE id = ?`, [id]))
253
+ .rows as unknown as DealRow[];
254
+
255
+ if (!rows[0]) {
256
+ throw new Error('Failed to create deal');
257
+ }
258
+
259
+ return rowToDeal(rows[0]);
260
+ }
261
+
262
+ /**
263
+ * Move a deal to a different stage
264
+ */
265
+ async function moveDeal(input: MoveDealInput): Promise<Deal> {
266
+ const now = new Date().toISOString();
267
+
268
+ // Verify deal exists
269
+ const existing = (
270
+ await db.query(`SELECT * FROM crm_deal WHERE id = ?`, [input.dealId])
271
+ ).rows as unknown as DealRow[];
272
+
273
+ if (!existing[0]) {
274
+ throw new Error('NOT_FOUND');
275
+ }
276
+
277
+ // Verify stage exists
278
+ const stage = (
279
+ await db.query(`SELECT * FROM crm_stage WHERE id = ?`, [input.stageId])
280
+ ).rows as unknown as StageRow[];
281
+
282
+ if (!stage[0]) {
283
+ throw new Error('INVALID_STAGE');
284
+ }
285
+
286
+ await db.execute(
287
+ `UPDATE crm_deal SET stageId = ?, updatedAt = ? WHERE id = ?`,
288
+ [input.stageId, now, input.dealId]
289
+ );
290
+
291
+ const rows = (
292
+ await db.query(`SELECT * FROM crm_deal WHERE id = ?`, [input.dealId])
293
+ ).rows as unknown as DealRow[];
294
+
295
+ return rowToDeal(rows[0]!);
296
+ }
297
+
298
+ /**
299
+ * Mark a deal as won
300
+ */
301
+ async function winDeal(input: WinDealInput): Promise<Deal> {
302
+ const now = new Date().toISOString();
303
+
304
+ // Verify deal exists
305
+ const existing = (
306
+ await db.query(`SELECT * FROM crm_deal WHERE id = ?`, [input.dealId])
307
+ ).rows as unknown as DealRow[];
308
+
309
+ if (!existing[0]) {
310
+ throw new Error('NOT_FOUND');
311
+ }
312
+
313
+ await db.execute(
314
+ `UPDATE crm_deal SET status = 'WON', wonSource = ?, notes = ?, updatedAt = ? WHERE id = ?`,
315
+ [input.wonSource ?? null, input.notes ?? null, now, input.dealId]
316
+ );
317
+
318
+ const rows = (
319
+ await db.query(`SELECT * FROM crm_deal WHERE id = ?`, [input.dealId])
320
+ ).rows as unknown as DealRow[];
321
+
322
+ return rowToDeal(rows[0]!);
323
+ }
324
+
325
+ /**
326
+ * Mark a deal as lost
327
+ */
328
+ async function loseDeal(input: LoseDealInput): Promise<Deal> {
329
+ const now = new Date().toISOString();
330
+
331
+ // Verify deal exists
332
+ const existing = (
333
+ await db.query(`SELECT * FROM crm_deal WHERE id = ?`, [input.dealId])
334
+ ).rows as unknown as DealRow[];
335
+
336
+ if (!existing[0]) {
337
+ throw new Error('NOT_FOUND');
338
+ }
339
+
340
+ await db.execute(
341
+ `UPDATE crm_deal SET status = 'LOST', lostReason = ?, notes = ?, updatedAt = ? WHERE id = ?`,
342
+ [input.lostReason, input.notes ?? null, now, input.dealId]
343
+ );
344
+
345
+ const rows = (
346
+ await db.query(`SELECT * FROM crm_deal WHERE id = ?`, [input.dealId])
347
+ ).rows as unknown as DealRow[];
348
+
349
+ return rowToDeal(rows[0]!);
350
+ }
351
+
352
+ /**
353
+ * Get deals grouped by stage
354
+ */
355
+ async function getDealsByStage(input: {
356
+ projectId: string;
357
+ pipelineId: string;
358
+ }): Promise<Record<string, Deal[]>> {
359
+ const deals = (
360
+ await db.query(
361
+ `SELECT * FROM crm_deal WHERE projectId = ? AND pipelineId = ? AND status = 'OPEN' ORDER BY value DESC`,
362
+ [input.projectId, input.pipelineId]
363
+ )
364
+ ).rows as unknown as DealRow[];
365
+
366
+ const stages = (
367
+ await db.query(
368
+ `SELECT * FROM crm_stage WHERE pipelineId = ? ORDER BY position`,
369
+ [input.pipelineId]
370
+ )
371
+ ).rows as unknown as StageRow[];
372
+
373
+ const grouped: Record<string, Deal[]> = {};
374
+ for (const stage of stages) {
375
+ grouped[stage.id] = deals
376
+ .filter((d) => d.stageId === stage.id)
377
+ .map(rowToDeal);
378
+ }
379
+
380
+ return grouped;
381
+ }
382
+
383
+ /**
384
+ * Get pipeline stages
385
+ */
386
+ async function getPipelineStages(input: {
387
+ pipelineId: string;
388
+ }): Promise<Stage[]> {
389
+ const rows = (
390
+ await db.query(
391
+ `SELECT * FROM crm_stage WHERE pipelineId = ? ORDER BY position`,
392
+ [input.pipelineId]
393
+ )
394
+ ).rows as unknown as StageRow[];
395
+
396
+ return rows.map((row) => ({
397
+ id: row.id,
398
+ pipelineId: row.pipelineId,
399
+ name: row.name,
400
+ position: row.position,
401
+ }));
402
+ }
403
+
404
+ return {
405
+ listDeals,
406
+ createDeal,
407
+ moveDeal,
408
+ winDeal,
409
+ loseDeal,
410
+ getDealsByStage,
411
+ getPipelineStages,
412
+ };
413
+ }
414
+
415
+ export type CrmHandlers = ReturnType<typeof createCrmHandlers>;
@@ -25,3 +25,6 @@ export {
25
25
  type ListDealsInput,
26
26
  type ListDealsOutput,
27
27
  } from './deal.handlers';
28
+
29
+ // Runtime handlers (PGLite)
30
+ export * from './crm.handlers';
package/src/index.ts CHANGED
@@ -6,6 +6,7 @@ export * from './operations';
6
6
  export * from './events';
7
7
  export * from './handlers';
8
8
  export * from './presentations';
9
+ export * from './ui';
9
10
  export * from './crm-pipeline.feature';
10
11
  export { default as example } from './example';
11
12
  import './docs';
@@ -1,13 +1,12 @@
1
1
  /**
2
2
  * CRM Dashboard Presentation Descriptor
3
3
  */
4
- import type { PresentationSpec } from '@contractspec/lib.contracts';
5
- import { StabilityEnum } from '@contractspec/lib.contracts';
4
+ import { definePresentation, StabilityEnum } from '@contractspec/lib.contracts';
6
5
 
7
6
  /**
8
7
  * Main CRM dashboard presentation.
9
8
  */
10
- export const CrmDashboardPresentation: PresentationSpec = {
9
+ export const CrmDashboardPresentation = definePresentation({
11
10
  meta: {
12
11
  key: 'crm.dashboard',
13
12
  version: '1.0.0',
@@ -30,12 +29,12 @@ export const CrmDashboardPresentation: PresentationSpec = {
30
29
  policy: {
31
30
  flags: ['crm.enabled'],
32
31
  },
33
- };
32
+ });
34
33
 
35
34
  /**
36
35
  * Pipeline metrics presentation.
37
36
  */
38
- export const PipelineMetricsPresentation: PresentationSpec = {
37
+ export const PipelineMetricsPresentation = definePresentation({
39
38
  meta: {
40
39
  key: 'crm.pipeline.metrics',
41
40
  version: '1.0.0',
@@ -57,4 +56,4 @@ export const PipelineMetricsPresentation: PresentationSpec = {
57
56
  policy: {
58
57
  flags: ['crm.metrics.enabled'],
59
58
  },
60
- };
59
+ });
@@ -1,14 +1,13 @@
1
1
  /**
2
2
  * Pipeline Presentation Descriptors
3
3
  */
4
- import type { PresentationSpec } from '@contractspec/lib.contracts';
5
- import { StabilityEnum } from '@contractspec/lib.contracts';
4
+ import { definePresentation, StabilityEnum } from '@contractspec/lib.contracts';
6
5
  import { DealModel } from '../deal/deal.schema';
7
6
 
8
7
  /**
9
8
  * Kanban board presentation for the sales pipeline.
10
9
  */
11
- export const PipelineKanbanPresentation: PresentationSpec = {
10
+ export const PipelineKanbanPresentation = definePresentation({
12
11
  meta: {
13
12
  key: 'crm.pipeline.kanban',
14
13
  version: '1.0.0',
@@ -31,12 +30,12 @@ export const PipelineKanbanPresentation: PresentationSpec = {
31
30
  policy: {
32
31
  flags: ['crm.pipeline.enabled'],
33
32
  },
34
- };
33
+ });
35
34
 
36
35
  /**
37
36
  * List view of deals with filtering.
38
37
  */
39
- export const DealListPresentation: PresentationSpec = {
38
+ export const DealListPresentation = definePresentation({
40
39
  meta: {
41
40
  key: 'crm.deal.list',
42
41
  version: '1.0.0',
@@ -59,12 +58,12 @@ export const DealListPresentation: PresentationSpec = {
59
58
  policy: {
60
59
  flags: ['crm.deals.enabled'],
61
60
  },
62
- };
61
+ });
63
62
 
64
63
  /**
65
64
  * Deal detail presentation.
66
65
  */
67
- export const DealDetailPresentation: PresentationSpec = {
66
+ export const DealDetailPresentation = definePresentation({
68
67
  meta: {
69
68
  key: 'crm.deal.detail',
70
69
  version: '1.0.0',
@@ -87,12 +86,12 @@ export const DealDetailPresentation: PresentationSpec = {
87
86
  policy: {
88
87
  flags: ['crm.deals.enabled'],
89
88
  },
90
- };
89
+ });
91
90
 
92
91
  /**
93
92
  * Deal card for kanban board.
94
93
  */
95
- export const DealCardPresentation: PresentationSpec = {
94
+ export const DealCardPresentation = definePresentation({
96
95
  meta: {
97
96
  key: 'crm.deal.card',
98
97
  version: '1.0.0',
@@ -115,4 +114,4 @@ export const DealCardPresentation: PresentationSpec = {
115
114
  policy: {
116
115
  flags: ['crm.deals.enabled'],
117
116
  },
118
- };
117
+ });
@@ -0,0 +1,35 @@
1
+ import type { DatabasePort } from '@contractspec/lib.runtime-sandbox';
2
+
3
+ export async function seedCrmPipeline(params: {
4
+ projectId: string;
5
+ db: DatabasePort;
6
+ }) {
7
+ const { projectId, db } = params;
8
+
9
+ const existing = await db.query(
10
+ `SELECT COUNT(*) as count FROM crm_pipeline WHERE "projectId" = $1`,
11
+ [projectId]
12
+ );
13
+ if ((existing.rows[0]?.count as number) > 0) return;
14
+
15
+ const pipelineId = 'pipeline_sales';
16
+ await db.execute(
17
+ `INSERT INTO crm_pipeline (id, "projectId", name) VALUES ($1, $2, $3)`,
18
+ [pipelineId, projectId, 'Sales Pipeline']
19
+ );
20
+
21
+ const stages = [
22
+ { id: 'stage_lead', name: 'Lead', position: 1 },
23
+ { id: 'stage_contact', name: 'Contact Made', position: 2 },
24
+ { id: 'stage_proposal', name: 'Proposal', position: 3 },
25
+ { id: 'stage_negotiation', name: 'Negotiation', position: 4 },
26
+ { id: 'stage_closed', name: 'Closed', position: 5 },
27
+ ];
28
+
29
+ for (const stage of stages) {
30
+ await db.execute(
31
+ `INSERT INTO crm_stage (id, "pipelineId", name, position) VALUES ($1, $2, $3, $4)`,
32
+ [stage.id, pipelineId, stage.name, stage.position]
33
+ );
34
+ }
35
+ }
@@ -0,0 +1,39 @@
1
+ export interface OverlayDefinition {
2
+ overlayId: string;
3
+ version: string;
4
+ description: string;
5
+ appliesTo: Record<string, string>;
6
+ modifications: OverlayModification[];
7
+ }
8
+
9
+ export type OverlayModification =
10
+ | HideFieldModification
11
+ | RenameLabelModification
12
+ | AddBadgeModification
13
+ | SetLimitModification;
14
+
15
+ export interface HideFieldModification {
16
+ type: 'hideField';
17
+ field: string;
18
+ reason?: string;
19
+ }
20
+
21
+ export interface RenameLabelModification {
22
+ type: 'renameLabel';
23
+ field: string;
24
+ newLabel: string;
25
+ }
26
+
27
+ export interface AddBadgeModification {
28
+ type: 'addBadge';
29
+ position: 'header' | 'footer';
30
+ label: string;
31
+ variant: 'warning' | 'info' | 'error' | 'success' | 'default';
32
+ }
33
+
34
+ export interface SetLimitModification {
35
+ type: 'setLimit';
36
+ field: string;
37
+ max: number;
38
+ message: string;
39
+ }