@contractspec/example.crm-pipeline 3.7.17 → 3.7.18
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 +135 -135
- package/CHANGELOG.md +20 -0
- package/dist/browser/crm-pipeline.feature.js +1 -82
- package/dist/browser/deal/deal.enum.js +1 -18
- package/dist/browser/deal/deal.operation.js +1 -396
- package/dist/browser/deal/deal.schema.js +1 -141
- package/dist/browser/deal/deal.test-spec.js +1 -58
- package/dist/browser/deal/index.js +1 -408
- package/dist/browser/docs/crm-pipeline.docblock.js +5 -49
- package/dist/browser/docs/index.js +5 -49
- package/dist/browser/entities/company.entity.js +1 -52
- package/dist/browser/entities/contact.entity.js +1 -66
- package/dist/browser/entities/deal.entity.js +1 -107
- package/dist/browser/entities/index.js +1 -343
- package/dist/browser/entities/task.entity.js +1 -99
- package/dist/browser/events/contact.event.js +1 -31
- package/dist/browser/events/deal.event.js +1 -101
- package/dist/browser/events/index.js +1 -158
- package/dist/browser/events/task.event.js +1 -28
- package/dist/browser/example.js +1 -39
- package/dist/browser/handlers/crm.handlers.js +2 -171
- package/dist/browser/handlers/deal.handlers.js +1 -293
- package/dist/browser/handlers/index.js +2 -467
- package/dist/browser/handlers/mock-data.js +1 -165
- package/dist/browser/index.js +8 -3461
- package/dist/browser/operations/index.js +1 -407
- package/dist/browser/presentations/dashboard.presentation.js +1 -55
- package/dist/browser/presentations/index.js +1 -290
- package/dist/browser/presentations/pipeline.presentation.js +1 -236
- package/dist/browser/seeders/index.js +1 -22
- package/dist/browser/ui/CrmDashboard.js +1 -1547
- package/dist/browser/ui/CrmDealCard.js +1 -50
- package/dist/browser/ui/CrmPipelineBoard.js +1 -160
- package/dist/browser/ui/hooks/index.js +1 -197
- package/dist/browser/ui/hooks/useDealList.js +1 -95
- package/dist/browser/ui/hooks/useDealMutations.js +1 -100
- package/dist/browser/ui/index.js +4 -2205
- package/dist/browser/ui/modals/CreateDealModal.js +1 -211
- package/dist/browser/ui/modals/DealActionsModal.js +1 -428
- package/dist/browser/ui/modals/index.js +1 -638
- package/dist/browser/ui/overlays/demo-overlays.js +1 -55
- package/dist/browser/ui/overlays/index.js +1 -55
- package/dist/browser/ui/renderers/index.js +4 -849
- package/dist/browser/ui/renderers/pipeline.markdown.js +4 -575
- package/dist/browser/ui/renderers/pipeline.renderer.js +1 -275
- package/dist/browser/ui/tables/DealListTab.js +1 -390
- package/dist/crm-pipeline.feature.js +1 -82
- package/dist/deal/deal.enum.js +1 -18
- package/dist/deal/deal.operation.js +1 -396
- package/dist/deal/deal.schema.js +1 -141
- package/dist/deal/deal.test-spec.js +1 -58
- package/dist/deal/index.js +1 -408
- package/dist/docs/crm-pipeline.docblock.js +5 -49
- package/dist/docs/index.js +5 -49
- package/dist/entities/company.entity.js +1 -52
- package/dist/entities/contact.entity.js +1 -66
- package/dist/entities/deal.entity.js +1 -107
- package/dist/entities/index.js +1 -343
- package/dist/entities/task.entity.js +1 -99
- package/dist/events/contact.event.js +1 -31
- package/dist/events/deal.event.js +1 -101
- package/dist/events/index.js +1 -158
- package/dist/events/task.event.js +1 -28
- package/dist/example.js +1 -39
- package/dist/handlers/crm.handlers.js +2 -171
- package/dist/handlers/deal.handlers.js +1 -293
- package/dist/handlers/index.js +2 -467
- package/dist/handlers/mock-data.js +1 -165
- package/dist/index.js +8 -3461
- package/dist/node/crm-pipeline.feature.js +1 -82
- package/dist/node/deal/deal.enum.js +1 -18
- package/dist/node/deal/deal.operation.js +1 -396
- package/dist/node/deal/deal.schema.js +1 -141
- package/dist/node/deal/deal.test-spec.js +1 -58
- package/dist/node/deal/index.js +1 -408
- package/dist/node/docs/crm-pipeline.docblock.js +5 -49
- package/dist/node/docs/index.js +5 -49
- package/dist/node/entities/company.entity.js +1 -52
- package/dist/node/entities/contact.entity.js +1 -66
- package/dist/node/entities/deal.entity.js +1 -107
- package/dist/node/entities/index.js +1 -343
- package/dist/node/entities/task.entity.js +1 -99
- package/dist/node/events/contact.event.js +1 -31
- package/dist/node/events/deal.event.js +1 -101
- package/dist/node/events/index.js +1 -158
- package/dist/node/events/task.event.js +1 -28
- package/dist/node/example.js +1 -39
- package/dist/node/handlers/crm.handlers.js +2 -171
- package/dist/node/handlers/deal.handlers.js +1 -293
- package/dist/node/handlers/index.js +2 -467
- package/dist/node/handlers/mock-data.js +1 -165
- package/dist/node/index.js +8 -3461
- package/dist/node/operations/index.js +1 -407
- package/dist/node/presentations/dashboard.presentation.js +1 -55
- package/dist/node/presentations/index.js +1 -290
- package/dist/node/presentations/pipeline.presentation.js +1 -236
- package/dist/node/seeders/index.js +1 -22
- package/dist/node/ui/CrmDashboard.js +1 -1547
- package/dist/node/ui/CrmDealCard.js +1 -50
- package/dist/node/ui/CrmPipelineBoard.js +1 -160
- package/dist/node/ui/hooks/index.js +1 -197
- package/dist/node/ui/hooks/useDealList.js +1 -95
- package/dist/node/ui/hooks/useDealMutations.js +1 -100
- package/dist/node/ui/index.js +4 -2205
- package/dist/node/ui/modals/CreateDealModal.js +1 -211
- package/dist/node/ui/modals/DealActionsModal.js +1 -428
- package/dist/node/ui/modals/index.js +1 -638
- package/dist/node/ui/overlays/demo-overlays.js +1 -55
- package/dist/node/ui/overlays/index.js +1 -55
- package/dist/node/ui/renderers/index.js +4 -849
- package/dist/node/ui/renderers/pipeline.markdown.js +4 -575
- package/dist/node/ui/renderers/pipeline.renderer.js +1 -275
- package/dist/node/ui/tables/DealListTab.js +1 -390
- package/dist/operations/index.js +1 -407
- package/dist/presentations/dashboard.presentation.js +1 -55
- package/dist/presentations/index.js +1 -290
- package/dist/presentations/pipeline.presentation.js +1 -236
- package/dist/seeders/index.js +1 -22
- package/dist/ui/CrmDashboard.js +1 -1547
- package/dist/ui/CrmDealCard.js +1 -50
- package/dist/ui/CrmPipelineBoard.js +1 -160
- package/dist/ui/hooks/index.js +1 -197
- package/dist/ui/hooks/useDealList.js +1 -95
- package/dist/ui/hooks/useDealMutations.js +1 -100
- package/dist/ui/index.js +4 -2205
- package/dist/ui/modals/CreateDealModal.js +1 -211
- package/dist/ui/modals/DealActionsModal.js +1 -428
- package/dist/ui/modals/index.js +1 -638
- package/dist/ui/overlays/demo-overlays.js +1 -55
- package/dist/ui/overlays/index.js +1 -55
- package/dist/ui/renderers/index.js +4 -849
- package/dist/ui/renderers/pipeline.markdown.js +4 -575
- package/dist/ui/renderers/pipeline.renderer.js +1 -275
- package/dist/ui/tables/DealListTab.js +1 -390
- package/package.json +13 -13
|
@@ -1,100 +1,2 @@
|
|
|
1
1
|
// @bun
|
|
2
|
-
|
|
3
|
-
import {
|
|
4
|
-
defineEntity,
|
|
5
|
-
defineEntityEnum,
|
|
6
|
-
field,
|
|
7
|
-
index
|
|
8
|
-
} from "@contractspec/lib.schema";
|
|
9
|
-
var TaskTypeEnum = defineEntityEnum({
|
|
10
|
-
name: "TaskType",
|
|
11
|
-
values: ["CALL", "EMAIL", "MEETING", "TODO", "FOLLOW_UP", "OTHER"],
|
|
12
|
-
schema: "crm",
|
|
13
|
-
description: "Type of CRM task."
|
|
14
|
-
});
|
|
15
|
-
var TaskPriorityEnum = defineEntityEnum({
|
|
16
|
-
name: "TaskPriority",
|
|
17
|
-
values: ["LOW", "NORMAL", "HIGH", "URGENT"],
|
|
18
|
-
schema: "crm",
|
|
19
|
-
description: "Priority of a task."
|
|
20
|
-
});
|
|
21
|
-
var TaskStatusEnum = defineEntityEnum({
|
|
22
|
-
name: "TaskStatus",
|
|
23
|
-
values: ["PENDING", "IN_PROGRESS", "COMPLETED", "CANCELLED"],
|
|
24
|
-
schema: "crm",
|
|
25
|
-
description: "Status of a task."
|
|
26
|
-
});
|
|
27
|
-
var TaskEntity = defineEntity({
|
|
28
|
-
name: "Task",
|
|
29
|
-
description: "A task or follow-up activity.",
|
|
30
|
-
schema: "crm",
|
|
31
|
-
map: "task",
|
|
32
|
-
fields: {
|
|
33
|
-
id: field.id(),
|
|
34
|
-
title: field.string({ description: "Task title" }),
|
|
35
|
-
description: field.string({ isOptional: true }),
|
|
36
|
-
type: field.enum("TaskType", { default: "TODO" }),
|
|
37
|
-
priority: field.enum("TaskPriority", { default: "NORMAL" }),
|
|
38
|
-
status: field.enum("TaskStatus", { default: "PENDING" }),
|
|
39
|
-
dueDate: field.dateTime({ isOptional: true }),
|
|
40
|
-
reminderAt: field.dateTime({ isOptional: true }),
|
|
41
|
-
contactId: field.string({ isOptional: true }),
|
|
42
|
-
dealId: field.string({ isOptional: true }),
|
|
43
|
-
companyId: field.string({ isOptional: true }),
|
|
44
|
-
organizationId: field.foreignKey(),
|
|
45
|
-
assignedTo: field.foreignKey({ description: "User assigned to this task" }),
|
|
46
|
-
createdBy: field.foreignKey(),
|
|
47
|
-
completedAt: field.dateTime({ isOptional: true }),
|
|
48
|
-
completedBy: field.string({ isOptional: true }),
|
|
49
|
-
createdAt: field.createdAt(),
|
|
50
|
-
updatedAt: field.updatedAt(),
|
|
51
|
-
contact: field.belongsTo("Contact", ["contactId"], ["id"]),
|
|
52
|
-
deal: field.belongsTo("Deal", ["dealId"], ["id"]),
|
|
53
|
-
company: field.belongsTo("Company", ["companyId"], ["id"])
|
|
54
|
-
},
|
|
55
|
-
indexes: [
|
|
56
|
-
index.on(["organizationId", "assignedTo", "status"]),
|
|
57
|
-
index.on(["dueDate", "status"]),
|
|
58
|
-
index.on(["contactId"]),
|
|
59
|
-
index.on(["dealId"])
|
|
60
|
-
],
|
|
61
|
-
enums: [TaskTypeEnum, TaskPriorityEnum, TaskStatusEnum]
|
|
62
|
-
});
|
|
63
|
-
var ActivityEntity = defineEntity({
|
|
64
|
-
name: "Activity",
|
|
65
|
-
description: "An activity/interaction logged in the CRM.",
|
|
66
|
-
schema: "crm",
|
|
67
|
-
map: "activity",
|
|
68
|
-
fields: {
|
|
69
|
-
id: field.id(),
|
|
70
|
-
type: field.enum("TaskType"),
|
|
71
|
-
subject: field.string(),
|
|
72
|
-
description: field.string({ isOptional: true }),
|
|
73
|
-
contactId: field.string({ isOptional: true }),
|
|
74
|
-
dealId: field.string({ isOptional: true }),
|
|
75
|
-
companyId: field.string({ isOptional: true }),
|
|
76
|
-
organizationId: field.foreignKey(),
|
|
77
|
-
performedBy: field.foreignKey(),
|
|
78
|
-
outcome: field.string({ isOptional: true }),
|
|
79
|
-
occurredAt: field.dateTime(),
|
|
80
|
-
duration: field.int({
|
|
81
|
-
isOptional: true,
|
|
82
|
-
description: "Duration in minutes"
|
|
83
|
-
}),
|
|
84
|
-
createdAt: field.createdAt(),
|
|
85
|
-
contact: field.belongsTo("Contact", ["contactId"], ["id"]),
|
|
86
|
-
deal: field.belongsTo("Deal", ["dealId"], ["id"]),
|
|
87
|
-
company: field.belongsTo("Company", ["companyId"], ["id"])
|
|
88
|
-
},
|
|
89
|
-
indexes: [
|
|
90
|
-
index.on(["contactId", "occurredAt"]),
|
|
91
|
-
index.on(["dealId", "occurredAt"])
|
|
92
|
-
]
|
|
93
|
-
});
|
|
94
|
-
export {
|
|
95
|
-
TaskTypeEnum,
|
|
96
|
-
TaskStatusEnum,
|
|
97
|
-
TaskPriorityEnum,
|
|
98
|
-
TaskEntity,
|
|
99
|
-
ActivityEntity
|
|
100
|
-
};
|
|
2
|
+
import{defineEntity as B,defineEntityEnum as z,field as j,index as q}from"@contractspec/lib.schema";var C=z({name:"TaskType",values:["CALL","EMAIL","MEETING","TODO","FOLLOW_UP","OTHER"],schema:"crm",description:"Type of CRM task."}),D=z({name:"TaskPriority",values:["LOW","NORMAL","HIGH","URGENT"],schema:"crm",description:"Priority of a task."}),F=z({name:"TaskStatus",values:["PENDING","IN_PROGRESS","COMPLETED","CANCELLED"],schema:"crm",description:"Status of a task."}),H=B({name:"Task",description:"A task or follow-up activity.",schema:"crm",map:"task",fields:{id:j.id(),title:j.string({description:"Task title"}),description:j.string({isOptional:!0}),type:j.enum("TaskType",{default:"TODO"}),priority:j.enum("TaskPriority",{default:"NORMAL"}),status:j.enum("TaskStatus",{default:"PENDING"}),dueDate:j.dateTime({isOptional:!0}),reminderAt:j.dateTime({isOptional:!0}),contactId:j.string({isOptional:!0}),dealId:j.string({isOptional:!0}),companyId:j.string({isOptional:!0}),organizationId:j.foreignKey(),assignedTo:j.foreignKey({description:"User assigned to this task"}),createdBy:j.foreignKey(),completedAt:j.dateTime({isOptional:!0}),completedBy:j.string({isOptional:!0}),createdAt:j.createdAt(),updatedAt:j.updatedAt(),contact:j.belongsTo("Contact",["contactId"],["id"]),deal:j.belongsTo("Deal",["dealId"],["id"]),company:j.belongsTo("Company",["companyId"],["id"])},indexes:[q.on(["organizationId","assignedTo","status"]),q.on(["dueDate","status"]),q.on(["contactId"]),q.on(["dealId"])],enums:[C,D,F]}),I=B({name:"Activity",description:"An activity/interaction logged in the CRM.",schema:"crm",map:"activity",fields:{id:j.id(),type:j.enum("TaskType"),subject:j.string(),description:j.string({isOptional:!0}),contactId:j.string({isOptional:!0}),dealId:j.string({isOptional:!0}),companyId:j.string({isOptional:!0}),organizationId:j.foreignKey(),performedBy:j.foreignKey(),outcome:j.string({isOptional:!0}),occurredAt:j.dateTime(),duration:j.int({isOptional:!0,description:"Duration in minutes"}),createdAt:j.createdAt(),contact:j.belongsTo("Contact",["contactId"],["id"]),deal:j.belongsTo("Deal",["dealId"],["id"]),company:j.belongsTo("Company",["companyId"],["id"])},indexes:[q.on(["contactId","occurredAt"]),q.on(["dealId","occurredAt"])]});export{C as TaskTypeEnum,F as TaskStatusEnum,D as TaskPriorityEnum,H as TaskEntity,I as ActivityEntity};
|
|
@@ -1,32 +1,2 @@
|
|
|
1
1
|
// @bun
|
|
2
|
-
|
|
3
|
-
import { defineEvent } from "@contractspec/lib.contracts-spec";
|
|
4
|
-
import { defineSchemaModel, ScalarTypeEnum } from "@contractspec/lib.schema";
|
|
5
|
-
var ContactCreatedPayload = defineSchemaModel({
|
|
6
|
-
name: "ContactCreatedPayload",
|
|
7
|
-
description: "Payload when a contact is created",
|
|
8
|
-
fields: {
|
|
9
|
-
contactId: { type: ScalarTypeEnum.String_unsecure(), isOptional: false },
|
|
10
|
-
email: { type: ScalarTypeEnum.EmailAddress(), isOptional: true },
|
|
11
|
-
organizationId: {
|
|
12
|
-
type: ScalarTypeEnum.String_unsecure(),
|
|
13
|
-
isOptional: false
|
|
14
|
-
},
|
|
15
|
-
ownerId: { type: ScalarTypeEnum.String_unsecure(), isOptional: false },
|
|
16
|
-
createdAt: { type: ScalarTypeEnum.DateTime(), isOptional: false }
|
|
17
|
-
}
|
|
18
|
-
});
|
|
19
|
-
var ContactCreatedEvent = defineEvent({
|
|
20
|
-
meta: {
|
|
21
|
-
key: "contact.created",
|
|
22
|
-
version: "1.0.0",
|
|
23
|
-
description: "A new contact has been created.",
|
|
24
|
-
stability: "stable",
|
|
25
|
-
owners: ["@crm-team"],
|
|
26
|
-
tags: ["contact", "created"]
|
|
27
|
-
},
|
|
28
|
-
payload: ContactCreatedPayload
|
|
29
|
-
});
|
|
30
|
-
export {
|
|
31
|
-
ContactCreatedEvent
|
|
32
|
-
};
|
|
2
|
+
import{defineEvent as j}from"@contractspec/lib.contracts-spec";import{defineSchemaModel as k,ScalarTypeEnum as g}from"@contractspec/lib.schema";var q=k({name:"ContactCreatedPayload",description:"Payload when a contact is created",fields:{contactId:{type:g.String_unsecure(),isOptional:!1},email:{type:g.EmailAddress(),isOptional:!0},organizationId:{type:g.String_unsecure(),isOptional:!1},ownerId:{type:g.String_unsecure(),isOptional:!1},createdAt:{type:g.DateTime(),isOptional:!1}}}),z=j({meta:{key:"contact.created",version:"1.0.0",description:"A new contact has been created.",stability:"stable",owners:["@crm-team"],tags:["contact","created"]},payload:q});export{z as ContactCreatedEvent};
|
|
@@ -1,102 +1,2 @@
|
|
|
1
1
|
// @bun
|
|
2
|
-
|
|
3
|
-
import { defineEvent } from "@contractspec/lib.contracts-spec";
|
|
4
|
-
import { defineSchemaModel, ScalarTypeEnum } from "@contractspec/lib.schema";
|
|
5
|
-
var DealCreatedPayload = defineSchemaModel({
|
|
6
|
-
name: "DealCreatedPayload",
|
|
7
|
-
description: "Payload when a deal is created",
|
|
8
|
-
fields: {
|
|
9
|
-
dealId: { type: ScalarTypeEnum.String_unsecure(), isOptional: false },
|
|
10
|
-
name: { type: ScalarTypeEnum.String_unsecure(), isOptional: false },
|
|
11
|
-
value: { type: ScalarTypeEnum.Float_unsecure(), isOptional: false },
|
|
12
|
-
pipelineId: { type: ScalarTypeEnum.String_unsecure(), isOptional: false },
|
|
13
|
-
stageId: { type: ScalarTypeEnum.String_unsecure(), isOptional: false },
|
|
14
|
-
ownerId: { type: ScalarTypeEnum.String_unsecure(), isOptional: false },
|
|
15
|
-
createdAt: { type: ScalarTypeEnum.DateTime(), isOptional: false }
|
|
16
|
-
}
|
|
17
|
-
});
|
|
18
|
-
var DealMovedPayload = defineSchemaModel({
|
|
19
|
-
name: "DealMovedEventPayload",
|
|
20
|
-
description: "Payload when a deal is moved to another stage",
|
|
21
|
-
fields: {
|
|
22
|
-
dealId: { type: ScalarTypeEnum.String_unsecure(), isOptional: false },
|
|
23
|
-
fromStageId: { type: ScalarTypeEnum.String_unsecure(), isOptional: false },
|
|
24
|
-
toStageId: { type: ScalarTypeEnum.String_unsecure(), isOptional: false },
|
|
25
|
-
movedBy: { type: ScalarTypeEnum.String_unsecure(), isOptional: false },
|
|
26
|
-
movedAt: { type: ScalarTypeEnum.DateTime(), isOptional: false }
|
|
27
|
-
}
|
|
28
|
-
});
|
|
29
|
-
var DealWonPayload = defineSchemaModel({
|
|
30
|
-
name: "DealWonEventPayload",
|
|
31
|
-
description: "Payload when a deal is won",
|
|
32
|
-
fields: {
|
|
33
|
-
dealId: { type: ScalarTypeEnum.String_unsecure(), isOptional: false },
|
|
34
|
-
value: { type: ScalarTypeEnum.Float_unsecure(), isOptional: false },
|
|
35
|
-
currency: { type: ScalarTypeEnum.String_unsecure(), isOptional: false },
|
|
36
|
-
contactId: { type: ScalarTypeEnum.String_unsecure(), isOptional: true },
|
|
37
|
-
companyId: { type: ScalarTypeEnum.String_unsecure(), isOptional: true },
|
|
38
|
-
ownerId: { type: ScalarTypeEnum.String_unsecure(), isOptional: false },
|
|
39
|
-
wonAt: { type: ScalarTypeEnum.DateTime(), isOptional: false }
|
|
40
|
-
}
|
|
41
|
-
});
|
|
42
|
-
var DealLostPayload = defineSchemaModel({
|
|
43
|
-
name: "DealLostEventPayload",
|
|
44
|
-
description: "Payload when a deal is lost",
|
|
45
|
-
fields: {
|
|
46
|
-
dealId: { type: ScalarTypeEnum.String_unsecure(), isOptional: false },
|
|
47
|
-
value: { type: ScalarTypeEnum.Float_unsecure(), isOptional: false },
|
|
48
|
-
reason: { type: ScalarTypeEnum.String_unsecure(), isOptional: false },
|
|
49
|
-
ownerId: { type: ScalarTypeEnum.String_unsecure(), isOptional: false },
|
|
50
|
-
lostAt: { type: ScalarTypeEnum.DateTime(), isOptional: false }
|
|
51
|
-
}
|
|
52
|
-
});
|
|
53
|
-
var DealCreatedEvent = defineEvent({
|
|
54
|
-
meta: {
|
|
55
|
-
key: "deal.created",
|
|
56
|
-
version: "1.0.0",
|
|
57
|
-
description: "A new deal has been created.",
|
|
58
|
-
stability: "stable",
|
|
59
|
-
owners: ["@crm-team"],
|
|
60
|
-
tags: ["deal", "created"]
|
|
61
|
-
},
|
|
62
|
-
payload: DealCreatedPayload
|
|
63
|
-
});
|
|
64
|
-
var DealMovedEvent = defineEvent({
|
|
65
|
-
meta: {
|
|
66
|
-
key: "deal.moved",
|
|
67
|
-
version: "1.0.0",
|
|
68
|
-
description: "A deal has been moved to a different stage.",
|
|
69
|
-
stability: "stable",
|
|
70
|
-
owners: ["@crm-team"],
|
|
71
|
-
tags: ["deal", "moved"]
|
|
72
|
-
},
|
|
73
|
-
payload: DealMovedPayload
|
|
74
|
-
});
|
|
75
|
-
var DealWonEvent = defineEvent({
|
|
76
|
-
meta: {
|
|
77
|
-
key: "deal.won",
|
|
78
|
-
version: "1.0.0",
|
|
79
|
-
description: "A deal has been won.",
|
|
80
|
-
stability: "stable",
|
|
81
|
-
owners: ["@crm-team"],
|
|
82
|
-
tags: ["deal", "won"]
|
|
83
|
-
},
|
|
84
|
-
payload: DealWonPayload
|
|
85
|
-
});
|
|
86
|
-
var DealLostEvent = defineEvent({
|
|
87
|
-
meta: {
|
|
88
|
-
key: "deal.lost",
|
|
89
|
-
version: "1.0.0",
|
|
90
|
-
description: "A deal has been lost.",
|
|
91
|
-
stability: "stable",
|
|
92
|
-
owners: ["@crm-team"],
|
|
93
|
-
tags: ["deal", "lost"]
|
|
94
|
-
},
|
|
95
|
-
payload: DealLostPayload
|
|
96
|
-
});
|
|
97
|
-
export {
|
|
98
|
-
DealWonEvent,
|
|
99
|
-
DealMovedEvent,
|
|
100
|
-
DealLostEvent,
|
|
101
|
-
DealCreatedEvent
|
|
102
|
-
};
|
|
2
|
+
import{defineEvent as j}from"@contractspec/lib.contracts-spec";import{defineSchemaModel as k,ScalarTypeEnum as g}from"@contractspec/lib.schema";var q=k({name:"DealCreatedPayload",description:"Payload when a deal is created",fields:{dealId:{type:g.String_unsecure(),isOptional:!1},name:{type:g.String_unsecure(),isOptional:!1},value:{type:g.Float_unsecure(),isOptional:!1},pipelineId:{type:g.String_unsecure(),isOptional:!1},stageId:{type:g.String_unsecure(),isOptional:!1},ownerId:{type:g.String_unsecure(),isOptional:!1},createdAt:{type:g.DateTime(),isOptional:!1}}}),w=k({name:"DealMovedEventPayload",description:"Payload when a deal is moved to another stage",fields:{dealId:{type:g.String_unsecure(),isOptional:!1},fromStageId:{type:g.String_unsecure(),isOptional:!1},toStageId:{type:g.String_unsecure(),isOptional:!1},movedBy:{type:g.String_unsecure(),isOptional:!1},movedAt:{type:g.DateTime(),isOptional:!1}}}),x=k({name:"DealWonEventPayload",description:"Payload when a deal is won",fields:{dealId:{type:g.String_unsecure(),isOptional:!1},value:{type:g.Float_unsecure(),isOptional:!1},currency:{type:g.String_unsecure(),isOptional:!1},contactId:{type:g.String_unsecure(),isOptional:!0},companyId:{type:g.String_unsecure(),isOptional:!0},ownerId:{type:g.String_unsecure(),isOptional:!1},wonAt:{type:g.DateTime(),isOptional:!1}}}),z=k({name:"DealLostEventPayload",description:"Payload when a deal is lost",fields:{dealId:{type:g.String_unsecure(),isOptional:!1},value:{type:g.Float_unsecure(),isOptional:!1},reason:{type:g.String_unsecure(),isOptional:!1},ownerId:{type:g.String_unsecure(),isOptional:!1},lostAt:{type:g.DateTime(),isOptional:!1}}}),F=j({meta:{key:"deal.created",version:"1.0.0",description:"A new deal has been created.",stability:"stable",owners:["@crm-team"],tags:["deal","created"]},payload:q}),G=j({meta:{key:"deal.moved",version:"1.0.0",description:"A deal has been moved to a different stage.",stability:"stable",owners:["@crm-team"],tags:["deal","moved"]},payload:w}),H=j({meta:{key:"deal.won",version:"1.0.0",description:"A deal has been won.",stability:"stable",owners:["@crm-team"],tags:["deal","won"]},payload:x}),I=j({meta:{key:"deal.lost",version:"1.0.0",description:"A deal has been lost.",stability:"stable",owners:["@crm-team"],tags:["deal","lost"]},payload:z});export{H as DealWonEvent,G as DealMovedEvent,I as DealLostEvent,F as DealCreatedEvent};
|
package/dist/events/index.js
CHANGED
|
@@ -1,159 +1,2 @@
|
|
|
1
1
|
// @bun
|
|
2
|
-
|
|
3
|
-
import { defineEvent } from "@contractspec/lib.contracts-spec";
|
|
4
|
-
import { defineSchemaModel, ScalarTypeEnum } from "@contractspec/lib.schema";
|
|
5
|
-
var ContactCreatedPayload = defineSchemaModel({
|
|
6
|
-
name: "ContactCreatedPayload",
|
|
7
|
-
description: "Payload when a contact is created",
|
|
8
|
-
fields: {
|
|
9
|
-
contactId: { type: ScalarTypeEnum.String_unsecure(), isOptional: false },
|
|
10
|
-
email: { type: ScalarTypeEnum.EmailAddress(), isOptional: true },
|
|
11
|
-
organizationId: {
|
|
12
|
-
type: ScalarTypeEnum.String_unsecure(),
|
|
13
|
-
isOptional: false
|
|
14
|
-
},
|
|
15
|
-
ownerId: { type: ScalarTypeEnum.String_unsecure(), isOptional: false },
|
|
16
|
-
createdAt: { type: ScalarTypeEnum.DateTime(), isOptional: false }
|
|
17
|
-
}
|
|
18
|
-
});
|
|
19
|
-
var ContactCreatedEvent = defineEvent({
|
|
20
|
-
meta: {
|
|
21
|
-
key: "contact.created",
|
|
22
|
-
version: "1.0.0",
|
|
23
|
-
description: "A new contact has been created.",
|
|
24
|
-
stability: "stable",
|
|
25
|
-
owners: ["@crm-team"],
|
|
26
|
-
tags: ["contact", "created"]
|
|
27
|
-
},
|
|
28
|
-
payload: ContactCreatedPayload
|
|
29
|
-
});
|
|
30
|
-
|
|
31
|
-
// src/events/deal.event.ts
|
|
32
|
-
import { defineEvent as defineEvent2 } from "@contractspec/lib.contracts-spec";
|
|
33
|
-
import { defineSchemaModel as defineSchemaModel2, ScalarTypeEnum as ScalarTypeEnum2 } from "@contractspec/lib.schema";
|
|
34
|
-
var DealCreatedPayload = defineSchemaModel2({
|
|
35
|
-
name: "DealCreatedPayload",
|
|
36
|
-
description: "Payload when a deal is created",
|
|
37
|
-
fields: {
|
|
38
|
-
dealId: { type: ScalarTypeEnum2.String_unsecure(), isOptional: false },
|
|
39
|
-
name: { type: ScalarTypeEnum2.String_unsecure(), isOptional: false },
|
|
40
|
-
value: { type: ScalarTypeEnum2.Float_unsecure(), isOptional: false },
|
|
41
|
-
pipelineId: { type: ScalarTypeEnum2.String_unsecure(), isOptional: false },
|
|
42
|
-
stageId: { type: ScalarTypeEnum2.String_unsecure(), isOptional: false },
|
|
43
|
-
ownerId: { type: ScalarTypeEnum2.String_unsecure(), isOptional: false },
|
|
44
|
-
createdAt: { type: ScalarTypeEnum2.DateTime(), isOptional: false }
|
|
45
|
-
}
|
|
46
|
-
});
|
|
47
|
-
var DealMovedPayload = defineSchemaModel2({
|
|
48
|
-
name: "DealMovedEventPayload",
|
|
49
|
-
description: "Payload when a deal is moved to another stage",
|
|
50
|
-
fields: {
|
|
51
|
-
dealId: { type: ScalarTypeEnum2.String_unsecure(), isOptional: false },
|
|
52
|
-
fromStageId: { type: ScalarTypeEnum2.String_unsecure(), isOptional: false },
|
|
53
|
-
toStageId: { type: ScalarTypeEnum2.String_unsecure(), isOptional: false },
|
|
54
|
-
movedBy: { type: ScalarTypeEnum2.String_unsecure(), isOptional: false },
|
|
55
|
-
movedAt: { type: ScalarTypeEnum2.DateTime(), isOptional: false }
|
|
56
|
-
}
|
|
57
|
-
});
|
|
58
|
-
var DealWonPayload = defineSchemaModel2({
|
|
59
|
-
name: "DealWonEventPayload",
|
|
60
|
-
description: "Payload when a deal is won",
|
|
61
|
-
fields: {
|
|
62
|
-
dealId: { type: ScalarTypeEnum2.String_unsecure(), isOptional: false },
|
|
63
|
-
value: { type: ScalarTypeEnum2.Float_unsecure(), isOptional: false },
|
|
64
|
-
currency: { type: ScalarTypeEnum2.String_unsecure(), isOptional: false },
|
|
65
|
-
contactId: { type: ScalarTypeEnum2.String_unsecure(), isOptional: true },
|
|
66
|
-
companyId: { type: ScalarTypeEnum2.String_unsecure(), isOptional: true },
|
|
67
|
-
ownerId: { type: ScalarTypeEnum2.String_unsecure(), isOptional: false },
|
|
68
|
-
wonAt: { type: ScalarTypeEnum2.DateTime(), isOptional: false }
|
|
69
|
-
}
|
|
70
|
-
});
|
|
71
|
-
var DealLostPayload = defineSchemaModel2({
|
|
72
|
-
name: "DealLostEventPayload",
|
|
73
|
-
description: "Payload when a deal is lost",
|
|
74
|
-
fields: {
|
|
75
|
-
dealId: { type: ScalarTypeEnum2.String_unsecure(), isOptional: false },
|
|
76
|
-
value: { type: ScalarTypeEnum2.Float_unsecure(), isOptional: false },
|
|
77
|
-
reason: { type: ScalarTypeEnum2.String_unsecure(), isOptional: false },
|
|
78
|
-
ownerId: { type: ScalarTypeEnum2.String_unsecure(), isOptional: false },
|
|
79
|
-
lostAt: { type: ScalarTypeEnum2.DateTime(), isOptional: false }
|
|
80
|
-
}
|
|
81
|
-
});
|
|
82
|
-
var DealCreatedEvent = defineEvent2({
|
|
83
|
-
meta: {
|
|
84
|
-
key: "deal.created",
|
|
85
|
-
version: "1.0.0",
|
|
86
|
-
description: "A new deal has been created.",
|
|
87
|
-
stability: "stable",
|
|
88
|
-
owners: ["@crm-team"],
|
|
89
|
-
tags: ["deal", "created"]
|
|
90
|
-
},
|
|
91
|
-
payload: DealCreatedPayload
|
|
92
|
-
});
|
|
93
|
-
var DealMovedEvent = defineEvent2({
|
|
94
|
-
meta: {
|
|
95
|
-
key: "deal.moved",
|
|
96
|
-
version: "1.0.0",
|
|
97
|
-
description: "A deal has been moved to a different stage.",
|
|
98
|
-
stability: "stable",
|
|
99
|
-
owners: ["@crm-team"],
|
|
100
|
-
tags: ["deal", "moved"]
|
|
101
|
-
},
|
|
102
|
-
payload: DealMovedPayload
|
|
103
|
-
});
|
|
104
|
-
var DealWonEvent = defineEvent2({
|
|
105
|
-
meta: {
|
|
106
|
-
key: "deal.won",
|
|
107
|
-
version: "1.0.0",
|
|
108
|
-
description: "A deal has been won.",
|
|
109
|
-
stability: "stable",
|
|
110
|
-
owners: ["@crm-team"],
|
|
111
|
-
tags: ["deal", "won"]
|
|
112
|
-
},
|
|
113
|
-
payload: DealWonPayload
|
|
114
|
-
});
|
|
115
|
-
var DealLostEvent = defineEvent2({
|
|
116
|
-
meta: {
|
|
117
|
-
key: "deal.lost",
|
|
118
|
-
version: "1.0.0",
|
|
119
|
-
description: "A deal has been lost.",
|
|
120
|
-
stability: "stable",
|
|
121
|
-
owners: ["@crm-team"],
|
|
122
|
-
tags: ["deal", "lost"]
|
|
123
|
-
},
|
|
124
|
-
payload: DealLostPayload
|
|
125
|
-
});
|
|
126
|
-
|
|
127
|
-
// src/events/task.event.ts
|
|
128
|
-
import { defineEvent as defineEvent3 } from "@contractspec/lib.contracts-spec";
|
|
129
|
-
import { defineSchemaModel as defineSchemaModel3, ScalarTypeEnum as ScalarTypeEnum3 } from "@contractspec/lib.schema";
|
|
130
|
-
var TaskCompletedPayload = defineSchemaModel3({
|
|
131
|
-
name: "TaskCompletedPayload",
|
|
132
|
-
description: "Payload when a task is completed",
|
|
133
|
-
fields: {
|
|
134
|
-
taskId: { type: ScalarTypeEnum3.String_unsecure(), isOptional: false },
|
|
135
|
-
type: { type: ScalarTypeEnum3.String_unsecure(), isOptional: false },
|
|
136
|
-
assignedTo: { type: ScalarTypeEnum3.String_unsecure(), isOptional: false },
|
|
137
|
-
completedBy: { type: ScalarTypeEnum3.String_unsecure(), isOptional: false },
|
|
138
|
-
completedAt: { type: ScalarTypeEnum3.DateTime(), isOptional: false }
|
|
139
|
-
}
|
|
140
|
-
});
|
|
141
|
-
var TaskCompletedEvent = defineEvent3({
|
|
142
|
-
meta: {
|
|
143
|
-
key: "task.completed",
|
|
144
|
-
version: "1.0.0",
|
|
145
|
-
description: "A task has been completed.",
|
|
146
|
-
stability: "stable",
|
|
147
|
-
owners: ["@crm-team"],
|
|
148
|
-
tags: ["task", "lifecycle"]
|
|
149
|
-
},
|
|
150
|
-
payload: TaskCompletedPayload
|
|
151
|
-
});
|
|
152
|
-
export {
|
|
153
|
-
TaskCompletedEvent,
|
|
154
|
-
DealWonEvent,
|
|
155
|
-
DealMovedEvent,
|
|
156
|
-
DealLostEvent,
|
|
157
|
-
DealCreatedEvent,
|
|
158
|
-
ContactCreatedEvent
|
|
159
|
-
};
|
|
2
|
+
import{defineEvent as z}from"@contractspec/lib.contracts-spec";import{defineSchemaModel as A,ScalarTypeEnum as g}from"@contractspec/lib.schema";var B=A({name:"ContactCreatedPayload",description:"Payload when a contact is created",fields:{contactId:{type:g.String_unsecure(),isOptional:!1},email:{type:g.EmailAddress(),isOptional:!0},organizationId:{type:g.String_unsecure(),isOptional:!1},ownerId:{type:g.String_unsecure(),isOptional:!1},createdAt:{type:g.DateTime(),isOptional:!1}}}),R=z({meta:{key:"contact.created",version:"1.0.0",description:"A new contact has been created.",stability:"stable",owners:["@crm-team"],tags:["contact","created"]},payload:B});import{defineEvent as q}from"@contractspec/lib.contracts-spec";import{defineSchemaModel as w,ScalarTypeEnum as x}from"@contractspec/lib.schema";var F=w({name:"DealCreatedPayload",description:"Payload when a deal is created",fields:{dealId:{type:x.String_unsecure(),isOptional:!1},name:{type:x.String_unsecure(),isOptional:!1},value:{type:x.Float_unsecure(),isOptional:!1},pipelineId:{type:x.String_unsecure(),isOptional:!1},stageId:{type:x.String_unsecure(),isOptional:!1},ownerId:{type:x.String_unsecure(),isOptional:!1},createdAt:{type:x.DateTime(),isOptional:!1}}}),G=w({name:"DealMovedEventPayload",description:"Payload when a deal is moved to another stage",fields:{dealId:{type:x.String_unsecure(),isOptional:!1},fromStageId:{type:x.String_unsecure(),isOptional:!1},toStageId:{type:x.String_unsecure(),isOptional:!1},movedBy:{type:x.String_unsecure(),isOptional:!1},movedAt:{type:x.DateTime(),isOptional:!1}}}),H=w({name:"DealWonEventPayload",description:"Payload when a deal is won",fields:{dealId:{type:x.String_unsecure(),isOptional:!1},value:{type:x.Float_unsecure(),isOptional:!1},currency:{type:x.String_unsecure(),isOptional:!1},contactId:{type:x.String_unsecure(),isOptional:!0},companyId:{type:x.String_unsecure(),isOptional:!0},ownerId:{type:x.String_unsecure(),isOptional:!1},wonAt:{type:x.DateTime(),isOptional:!1}}}),I=w({name:"DealLostEventPayload",description:"Payload when a deal is lost",fields:{dealId:{type:x.String_unsecure(),isOptional:!1},value:{type:x.Float_unsecure(),isOptional:!1},reason:{type:x.String_unsecure(),isOptional:!1},ownerId:{type:x.String_unsecure(),isOptional:!1},lostAt:{type:x.DateTime(),isOptional:!1}}}),Y=q({meta:{key:"deal.created",version:"1.0.0",description:"A new deal has been created.",stability:"stable",owners:["@crm-team"],tags:["deal","created"]},payload:F}),Z=q({meta:{key:"deal.moved",version:"1.0.0",description:"A deal has been moved to a different stage.",stability:"stable",owners:["@crm-team"],tags:["deal","moved"]},payload:G}),_=q({meta:{key:"deal.won",version:"1.0.0",description:"A deal has been won.",stability:"stable",owners:["@crm-team"],tags:["deal","won"]},payload:H}),$=q({meta:{key:"deal.lost",version:"1.0.0",description:"A deal has been lost.",stability:"stable",owners:["@crm-team"],tags:["deal","lost"]},payload:I});import{defineEvent as J}from"@contractspec/lib.contracts-spec";import{defineSchemaModel as K,ScalarTypeEnum as j}from"@contractspec/lib.schema";var N=K({name:"TaskCompletedPayload",description:"Payload when a task is completed",fields:{taskId:{type:j.String_unsecure(),isOptional:!1},type:{type:j.String_unsecure(),isOptional:!1},assignedTo:{type:j.String_unsecure(),isOptional:!1},completedBy:{type:j.String_unsecure(),isOptional:!1},completedAt:{type:j.DateTime(),isOptional:!1}}}),C=J({meta:{key:"task.completed",version:"1.0.0",description:"A task has been completed.",stability:"stable",owners:["@crm-team"],tags:["task","lifecycle"]},payload:N});export{C as TaskCompletedEvent,_ as DealWonEvent,Z as DealMovedEvent,$ as DealLostEvent,Y as DealCreatedEvent,R as ContactCreatedEvent};
|
|
@@ -1,29 +1,2 @@
|
|
|
1
1
|
// @bun
|
|
2
|
-
|
|
3
|
-
import { defineEvent } from "@contractspec/lib.contracts-spec";
|
|
4
|
-
import { defineSchemaModel, ScalarTypeEnum } from "@contractspec/lib.schema";
|
|
5
|
-
var TaskCompletedPayload = defineSchemaModel({
|
|
6
|
-
name: "TaskCompletedPayload",
|
|
7
|
-
description: "Payload when a task is completed",
|
|
8
|
-
fields: {
|
|
9
|
-
taskId: { type: ScalarTypeEnum.String_unsecure(), isOptional: false },
|
|
10
|
-
type: { type: ScalarTypeEnum.String_unsecure(), isOptional: false },
|
|
11
|
-
assignedTo: { type: ScalarTypeEnum.String_unsecure(), isOptional: false },
|
|
12
|
-
completedBy: { type: ScalarTypeEnum.String_unsecure(), isOptional: false },
|
|
13
|
-
completedAt: { type: ScalarTypeEnum.DateTime(), isOptional: false }
|
|
14
|
-
}
|
|
15
|
-
});
|
|
16
|
-
var TaskCompletedEvent = defineEvent({
|
|
17
|
-
meta: {
|
|
18
|
-
key: "task.completed",
|
|
19
|
-
version: "1.0.0",
|
|
20
|
-
description: "A task has been completed.",
|
|
21
|
-
stability: "stable",
|
|
22
|
-
owners: ["@crm-team"],
|
|
23
|
-
tags: ["task", "lifecycle"]
|
|
24
|
-
},
|
|
25
|
-
payload: TaskCompletedPayload
|
|
26
|
-
});
|
|
27
|
-
export {
|
|
28
|
-
TaskCompletedEvent
|
|
29
|
-
};
|
|
2
|
+
import{defineEvent as j}from"@contractspec/lib.contracts-spec";import{defineSchemaModel as q,ScalarTypeEnum as g}from"@contractspec/lib.schema";var w=q({name:"TaskCompletedPayload",description:"Payload when a task is completed",fields:{taskId:{type:g.String_unsecure(),isOptional:!1},type:{type:g.String_unsecure(),isOptional:!1},assignedTo:{type:g.String_unsecure(),isOptional:!1},completedBy:{type:g.String_unsecure(),isOptional:!1},completedAt:{type:g.DateTime(),isOptional:!1}}}),A=j({meta:{key:"task.completed",version:"1.0.0",description:"A task has been completed.",stability:"stable",owners:["@crm-team"],tags:["task","lifecycle"]},payload:w});export{A as TaskCompletedEvent};
|
package/dist/example.js
CHANGED
|
@@ -1,40 +1,2 @@
|
|
|
1
1
|
// @bun
|
|
2
|
-
|
|
3
|
-
import { defineExample } from "@contractspec/lib.contracts-spec";
|
|
4
|
-
var example = defineExample({
|
|
5
|
-
meta: {
|
|
6
|
-
key: "crm-pipeline",
|
|
7
|
-
version: "1.0.0",
|
|
8
|
-
title: "CRM Pipeline",
|
|
9
|
-
description: "Sales CRM with contacts, companies, deals, pipelines, and tasks.",
|
|
10
|
-
kind: "template",
|
|
11
|
-
visibility: "public",
|
|
12
|
-
stability: "experimental",
|
|
13
|
-
owners: ["@platform.core"],
|
|
14
|
-
tags: ["crm", "sales", "pipeline", "deals"]
|
|
15
|
-
},
|
|
16
|
-
docs: {
|
|
17
|
-
rootDocId: "docs.examples.crm-pipeline"
|
|
18
|
-
},
|
|
19
|
-
entrypoints: {
|
|
20
|
-
packageName: "@contractspec/example.crm-pipeline",
|
|
21
|
-
feature: "./feature",
|
|
22
|
-
contracts: "./contracts",
|
|
23
|
-
presentations: "./presentations",
|
|
24
|
-
handlers: "./handlers",
|
|
25
|
-
docs: "./docs"
|
|
26
|
-
},
|
|
27
|
-
surfaces: {
|
|
28
|
-
templates: true,
|
|
29
|
-
sandbox: {
|
|
30
|
-
enabled: true,
|
|
31
|
-
modes: ["playground", "specs", "builder", "markdown", "evolution"]
|
|
32
|
-
},
|
|
33
|
-
studio: { enabled: true, installable: true },
|
|
34
|
-
mcp: { enabled: true }
|
|
35
|
-
}
|
|
36
|
-
});
|
|
37
|
-
var example_default = example;
|
|
38
|
-
export {
|
|
39
|
-
example_default as default
|
|
40
|
-
};
|
|
2
|
+
import{defineExample as g}from"@contractspec/lib.contracts-spec";var h=g({meta:{key:"crm-pipeline",version:"1.0.0",title:"CRM Pipeline",description:"Sales CRM with contacts, companies, deals, pipelines, and tasks.",kind:"template",visibility:"public",stability:"experimental",owners:["@platform.core"],tags:["crm","sales","pipeline","deals"]},docs:{rootDocId:"docs.examples.crm-pipeline"},entrypoints:{packageName:"@contractspec/example.crm-pipeline",feature:"./feature",contracts:"./contracts",presentations:"./presentations",handlers:"./handlers",docs:"./docs"},surfaces:{templates:!0,sandbox:{enabled:!0,modes:["playground","specs","builder","markdown","evolution"]},studio:{enabled:!0,installable:!0},mcp:{enabled:!0}}}),q=h;export{q as default};
|
|
@@ -1,172 +1,3 @@
|
|
|
1
1
|
// @bun
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
var { generateId } = web;
|
|
5
|
-
function rowToDeal(row) {
|
|
6
|
-
return {
|
|
7
|
-
id: row.id,
|
|
8
|
-
projectId: row.projectId,
|
|
9
|
-
name: row.name,
|
|
10
|
-
value: row.value,
|
|
11
|
-
currency: row.currency,
|
|
12
|
-
pipelineId: row.pipelineId,
|
|
13
|
-
stageId: row.stageId,
|
|
14
|
-
status: row.status,
|
|
15
|
-
contactId: row.contactId ?? undefined,
|
|
16
|
-
companyId: row.companyId ?? undefined,
|
|
17
|
-
ownerId: row.ownerId,
|
|
18
|
-
expectedCloseDate: row.expectedCloseDate ? new Date(row.expectedCloseDate) : undefined,
|
|
19
|
-
wonSource: row.wonSource ?? undefined,
|
|
20
|
-
lostReason: row.lostReason ?? undefined,
|
|
21
|
-
notes: row.notes ?? undefined,
|
|
22
|
-
createdAt: new Date(row.createdAt),
|
|
23
|
-
updatedAt: new Date(row.updatedAt)
|
|
24
|
-
};
|
|
25
|
-
}
|
|
26
|
-
var DEAL_SORT_COLUMNS = {
|
|
27
|
-
name: "name",
|
|
28
|
-
value: "value",
|
|
29
|
-
status: "status",
|
|
30
|
-
expectedCloseDate: "expectedCloseDate",
|
|
31
|
-
updatedAt: "updatedAt"
|
|
32
|
-
};
|
|
33
|
-
function createCrmHandlers(db) {
|
|
34
|
-
async function listDeals(input) {
|
|
35
|
-
const {
|
|
36
|
-
projectId,
|
|
37
|
-
pipelineId,
|
|
38
|
-
stageId,
|
|
39
|
-
status,
|
|
40
|
-
ownerId,
|
|
41
|
-
search,
|
|
42
|
-
limit = 20,
|
|
43
|
-
offset = 0,
|
|
44
|
-
sortBy = "value",
|
|
45
|
-
sortDirection = "desc"
|
|
46
|
-
} = input;
|
|
47
|
-
let whereClause = "WHERE projectId = ?";
|
|
48
|
-
const params = [projectId];
|
|
49
|
-
if (pipelineId) {
|
|
50
|
-
whereClause += " AND pipelineId = ?";
|
|
51
|
-
params.push(pipelineId);
|
|
52
|
-
}
|
|
53
|
-
if (stageId) {
|
|
54
|
-
whereClause += " AND stageId = ?";
|
|
55
|
-
params.push(stageId);
|
|
56
|
-
}
|
|
57
|
-
if (status && status !== "all") {
|
|
58
|
-
whereClause += " AND status = ?";
|
|
59
|
-
params.push(status);
|
|
60
|
-
}
|
|
61
|
-
if (ownerId) {
|
|
62
|
-
whereClause += " AND ownerId = ?";
|
|
63
|
-
params.push(ownerId);
|
|
64
|
-
}
|
|
65
|
-
if (search) {
|
|
66
|
-
whereClause += " AND name LIKE ?";
|
|
67
|
-
params.push(`%${search}%`);
|
|
68
|
-
}
|
|
69
|
-
const countResult = (await db.query(`SELECT COUNT(*) as count FROM crm_deal ${whereClause}`, params)).rows;
|
|
70
|
-
const total = countResult[0]?.count ?? 0;
|
|
71
|
-
const valueResult = (await db.query(`SELECT COALESCE(SUM(value), 0) as total FROM crm_deal ${whereClause}`, params)).rows;
|
|
72
|
-
const totalValue = valueResult[0]?.total ?? 0;
|
|
73
|
-
const orderByColumn = DEAL_SORT_COLUMNS[sortBy] ?? DEAL_SORT_COLUMNS.value;
|
|
74
|
-
const orderByDirection = sortDirection === "asc" ? "ASC" : "DESC";
|
|
75
|
-
const dealRows = (await db.query(`SELECT * FROM crm_deal ${whereClause} ORDER BY ${orderByColumn} ${orderByDirection} LIMIT ? OFFSET ?`, [...params, limit, offset])).rows;
|
|
76
|
-
return {
|
|
77
|
-
deals: dealRows.map(rowToDeal),
|
|
78
|
-
total,
|
|
79
|
-
totalValue
|
|
80
|
-
};
|
|
81
|
-
}
|
|
82
|
-
async function createDeal(input, context) {
|
|
83
|
-
const id = generateId("deal");
|
|
84
|
-
const now = new Date().toISOString();
|
|
85
|
-
await db.execute(`INSERT INTO crm_deal (id, projectId, pipelineId, stageId, name, value, currency, status, contactId, companyId, ownerId, expectedCloseDate, createdAt, updatedAt)
|
|
86
|
-
VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)`, [
|
|
87
|
-
id,
|
|
88
|
-
context.projectId,
|
|
89
|
-
input.pipelineId,
|
|
90
|
-
input.stageId,
|
|
91
|
-
input.name,
|
|
92
|
-
input.value,
|
|
93
|
-
input.currency ?? "USD",
|
|
94
|
-
"OPEN",
|
|
95
|
-
input.contactId ?? null,
|
|
96
|
-
input.companyId ?? null,
|
|
97
|
-
context.ownerId,
|
|
98
|
-
input.expectedCloseDate?.toISOString() ?? null,
|
|
99
|
-
now,
|
|
100
|
-
now
|
|
101
|
-
]);
|
|
102
|
-
const rows = (await db.query(`SELECT * FROM crm_deal WHERE id = ?`, [id])).rows;
|
|
103
|
-
if (!rows[0]) {
|
|
104
|
-
throw new Error("Failed to create deal");
|
|
105
|
-
}
|
|
106
|
-
return rowToDeal(rows[0]);
|
|
107
|
-
}
|
|
108
|
-
async function moveDeal(input) {
|
|
109
|
-
const now = new Date().toISOString();
|
|
110
|
-
const existing = (await db.query(`SELECT * FROM crm_deal WHERE id = ?`, [input.dealId])).rows;
|
|
111
|
-
if (!existing[0]) {
|
|
112
|
-
throw new Error("NOT_FOUND");
|
|
113
|
-
}
|
|
114
|
-
const stage = (await db.query(`SELECT * FROM crm_stage WHERE id = ?`, [input.stageId])).rows;
|
|
115
|
-
if (!stage[0]) {
|
|
116
|
-
throw new Error("INVALID_STAGE");
|
|
117
|
-
}
|
|
118
|
-
await db.execute(`UPDATE crm_deal SET stageId = ?, updatedAt = ? WHERE id = ?`, [input.stageId, now, input.dealId]);
|
|
119
|
-
const rows = (await db.query(`SELECT * FROM crm_deal WHERE id = ?`, [input.dealId])).rows;
|
|
120
|
-
return rowToDeal(rows[0]);
|
|
121
|
-
}
|
|
122
|
-
async function winDeal(input) {
|
|
123
|
-
const now = new Date().toISOString();
|
|
124
|
-
const existing = (await db.query(`SELECT * FROM crm_deal WHERE id = ?`, [input.dealId])).rows;
|
|
125
|
-
if (!existing[0]) {
|
|
126
|
-
throw new Error("NOT_FOUND");
|
|
127
|
-
}
|
|
128
|
-
await db.execute(`UPDATE crm_deal SET status = 'WON', wonSource = ?, notes = ?, updatedAt = ? WHERE id = ?`, [input.wonSource ?? null, input.notes ?? null, now, input.dealId]);
|
|
129
|
-
const rows = (await db.query(`SELECT * FROM crm_deal WHERE id = ?`, [input.dealId])).rows;
|
|
130
|
-
return rowToDeal(rows[0]);
|
|
131
|
-
}
|
|
132
|
-
async function loseDeal(input) {
|
|
133
|
-
const now = new Date().toISOString();
|
|
134
|
-
const existing = (await db.query(`SELECT * FROM crm_deal WHERE id = ?`, [input.dealId])).rows;
|
|
135
|
-
if (!existing[0]) {
|
|
136
|
-
throw new Error("NOT_FOUND");
|
|
137
|
-
}
|
|
138
|
-
await db.execute(`UPDATE crm_deal SET status = 'LOST', lostReason = ?, notes = ?, updatedAt = ? WHERE id = ?`, [input.lostReason, input.notes ?? null, now, input.dealId]);
|
|
139
|
-
const rows = (await db.query(`SELECT * FROM crm_deal WHERE id = ?`, [input.dealId])).rows;
|
|
140
|
-
return rowToDeal(rows[0]);
|
|
141
|
-
}
|
|
142
|
-
async function getDealsByStage(input) {
|
|
143
|
-
const deals = (await db.query(`SELECT * FROM crm_deal WHERE projectId = ? AND pipelineId = ? AND status = 'OPEN' ORDER BY value DESC`, [input.projectId, input.pipelineId])).rows;
|
|
144
|
-
const stages = (await db.query(`SELECT * FROM crm_stage WHERE pipelineId = ? ORDER BY position`, [input.pipelineId])).rows;
|
|
145
|
-
const grouped = {};
|
|
146
|
-
for (const stage of stages) {
|
|
147
|
-
grouped[stage.id] = deals.filter((d) => d.stageId === stage.id).map(rowToDeal);
|
|
148
|
-
}
|
|
149
|
-
return grouped;
|
|
150
|
-
}
|
|
151
|
-
async function getPipelineStages(input) {
|
|
152
|
-
const rows = (await db.query(`SELECT * FROM crm_stage WHERE pipelineId = ? ORDER BY position`, [input.pipelineId])).rows;
|
|
153
|
-
return rows.map((row) => ({
|
|
154
|
-
id: row.id,
|
|
155
|
-
pipelineId: row.pipelineId,
|
|
156
|
-
name: row.name,
|
|
157
|
-
position: row.position
|
|
158
|
-
}));
|
|
159
|
-
}
|
|
160
|
-
return {
|
|
161
|
-
listDeals,
|
|
162
|
-
createDeal,
|
|
163
|
-
moveDeal,
|
|
164
|
-
winDeal,
|
|
165
|
-
loseDeal,
|
|
166
|
-
getDealsByStage,
|
|
167
|
-
getPipelineStages
|
|
168
|
-
};
|
|
169
|
-
}
|
|
170
|
-
export {
|
|
171
|
-
createCrmHandlers
|
|
172
|
-
};
|
|
2
|
+
import{web as L}from"@contractspec/lib.runtime-sandbox";var{generateId:O}=L;function Q(k){return{id:k.id,projectId:k.projectId,name:k.name,value:k.value,currency:k.currency,pipelineId:k.pipelineId,stageId:k.stageId,status:k.status,contactId:k.contactId??void 0,companyId:k.companyId??void 0,ownerId:k.ownerId,expectedCloseDate:k.expectedCloseDate?new Date(k.expectedCloseDate):void 0,wonSource:k.wonSource??void 0,lostReason:k.lostReason??void 0,notes:k.notes??void 0,createdAt:new Date(k.createdAt),updatedAt:new Date(k.updatedAt)}}var Y={name:"name",value:"value",status:"status",expectedCloseDate:"expectedCloseDate",updatedAt:"updatedAt"};function T(k){async function Z(q){let{projectId:F,pipelineId:z,stageId:G,status:H,ownerId:W,search:X,limit:A=20,offset:E=0,sortBy:M="value",sortDirection:N="desc"}=q,J="WHERE projectId = ?",K=[F];if(z)J+=" AND pipelineId = ?",K.push(z);if(G)J+=" AND stageId = ?",K.push(G);if(H&&H!=="all")J+=" AND status = ?",K.push(H);if(W)J+=" AND ownerId = ?",K.push(W);if(X)J+=" AND name LIKE ?",K.push(`%${X}%`);let R=(await k.query(`SELECT COUNT(*) as count FROM crm_deal ${J}`,K)).rows[0]?.count??0,U=(await k.query(`SELECT COALESCE(SUM(value), 0) as total FROM crm_deal ${J}`,K)).rows[0]?.total??0,y=Y[M]??Y.value,B=N==="asc"?"ASC":"DESC";return{deals:(await k.query(`SELECT * FROM crm_deal ${J} ORDER BY ${y} ${B} LIMIT ? OFFSET ?`,[...K,A,E])).rows.map(Q),total:R,totalValue:U}}async function $(q,F){let z=O("deal"),G=new Date().toISOString();await k.execute(`INSERT INTO crm_deal (id, projectId, pipelineId, stageId, name, value, currency, status, contactId, companyId, ownerId, expectedCloseDate, createdAt, updatedAt)
|
|
3
|
+
VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)`,[z,F.projectId,q.pipelineId,q.stageId,q.name,q.value,q.currency??"USD","OPEN",q.contactId??null,q.companyId??null,F.ownerId,q.expectedCloseDate?.toISOString()??null,G,G]);let H=(await k.query("SELECT * FROM crm_deal WHERE id = ?",[z])).rows;if(!H[0])throw Error("Failed to create deal");return Q(H[0])}async function j(q){let F=new Date().toISOString();if(!(await k.query("SELECT * FROM crm_deal WHERE id = ?",[q.dealId])).rows[0])throw Error("NOT_FOUND");if(!(await k.query("SELECT * FROM crm_stage WHERE id = ?",[q.stageId])).rows[0])throw Error("INVALID_STAGE");await k.execute("UPDATE crm_deal SET stageId = ?, updatedAt = ? WHERE id = ?",[q.stageId,F,q.dealId]);let H=(await k.query("SELECT * FROM crm_deal WHERE id = ?",[q.dealId])).rows;return Q(H[0])}async function v(q){let F=new Date().toISOString();if(!(await k.query("SELECT * FROM crm_deal WHERE id = ?",[q.dealId])).rows[0])throw Error("NOT_FOUND");await k.execute("UPDATE crm_deal SET status = 'WON', wonSource = ?, notes = ?, updatedAt = ? WHERE id = ?",[q.wonSource??null,q.notes??null,F,q.dealId]);let G=(await k.query("SELECT * FROM crm_deal WHERE id = ?",[q.dealId])).rows;return Q(G[0])}async function P(q){let F=new Date().toISOString();if(!(await k.query("SELECT * FROM crm_deal WHERE id = ?",[q.dealId])).rows[0])throw Error("NOT_FOUND");await k.execute("UPDATE crm_deal SET status = 'LOST', lostReason = ?, notes = ?, updatedAt = ? WHERE id = ?",[q.lostReason,q.notes??null,F,q.dealId]);let G=(await k.query("SELECT * FROM crm_deal WHERE id = ?",[q.dealId])).rows;return Q(G[0])}async function V(q){let F=(await k.query("SELECT * FROM crm_deal WHERE projectId = ? AND pipelineId = ? AND status = 'OPEN' ORDER BY value DESC",[q.projectId,q.pipelineId])).rows,z=(await k.query("SELECT * FROM crm_stage WHERE pipelineId = ? ORDER BY position",[q.pipelineId])).rows,G={};for(let H of z)G[H.id]=F.filter((W)=>W.stageId===H.id).map(Q);return G}async function f(q){return(await k.query("SELECT * FROM crm_stage WHERE pipelineId = ? ORDER BY position",[q.pipelineId])).rows.map((z)=>({id:z.id,pipelineId:z.pipelineId,name:z.name,position:z.position}))}return{listDeals:Z,createDeal:$,moveDeal:j,winDeal:v,loseDeal:P,getDealsByStage:V,getPipelineStages:f}}export{T as createCrmHandlers};
|