@composable-os/pack-leads 0.0.0-stage → 0.1.0-beta.7
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/LICENSE +109 -0
- package/dist/automations.d.ts +26 -0
- package/dist/automations.js +50 -0
- package/dist/dashboards.d.ts +2 -0
- package/dist/dashboards.js +143 -0
- package/dist/index.d.ts +330 -0
- package/dist/index.js +218 -0
- package/dist/tools.d.ts +60 -0
- package/dist/tools.js +203 -0
- package/package.json +30 -4
- package/README.md +0 -3
package/LICENSE
ADDED
|
@@ -0,0 +1,109 @@
|
|
|
1
|
+
# Functional Source License, Version 1.1, ALv2 Future License
|
|
2
|
+
|
|
3
|
+
> This licence covers the repository except the directories listed in NOTICE. In particular, the
|
|
4
|
+
> assistant packages `packages/agent-*` (agent-core, agent-a2ui, agent-voice, agent-plugins) are
|
|
5
|
+
> licensed under the MIT License; see the LICENSE file in each of those directories (ADR 0350).
|
|
6
|
+
|
|
7
|
+
## Abbreviation
|
|
8
|
+
|
|
9
|
+
FSL-1.1-ALv2
|
|
10
|
+
|
|
11
|
+
## Notice
|
|
12
|
+
|
|
13
|
+
Copyright 2026 Tim O'Connell
|
|
14
|
+
|
|
15
|
+
## Terms and Conditions
|
|
16
|
+
|
|
17
|
+
### Licensor ("We")
|
|
18
|
+
|
|
19
|
+
The party offering the Software under these Terms and Conditions.
|
|
20
|
+
|
|
21
|
+
### The Software
|
|
22
|
+
|
|
23
|
+
The "Software" is each version of the software that we make available under
|
|
24
|
+
these Terms and Conditions, as indicated by our inclusion of these Terms and
|
|
25
|
+
Conditions with the Software.
|
|
26
|
+
|
|
27
|
+
### License Grant
|
|
28
|
+
|
|
29
|
+
Subject to your compliance with this License Grant and the Patents,
|
|
30
|
+
Redistribution and Trademark clauses below, we hereby grant you the right to
|
|
31
|
+
use, copy, modify, create derivative works, publicly perform, publicly display
|
|
32
|
+
and redistribute the Software for any Permitted Purpose identified below.
|
|
33
|
+
|
|
34
|
+
### Permitted Purpose
|
|
35
|
+
|
|
36
|
+
A Permitted Purpose is any purpose other than a Competing Use. A Competing Use
|
|
37
|
+
means making the Software available to others in a commercial product or
|
|
38
|
+
service that:
|
|
39
|
+
|
|
40
|
+
1. substitutes for the Software;
|
|
41
|
+
|
|
42
|
+
2. substitutes for any other product or service we offer using the Software
|
|
43
|
+
that exists as of the date we make the Software available; or
|
|
44
|
+
|
|
45
|
+
3. offers the same or substantially similar functionality as the Software.
|
|
46
|
+
|
|
47
|
+
Permitted Purposes specifically include using the Software:
|
|
48
|
+
|
|
49
|
+
1. for your internal use and access;
|
|
50
|
+
|
|
51
|
+
2. for non-commercial education;
|
|
52
|
+
|
|
53
|
+
3. for non-commercial research; and
|
|
54
|
+
|
|
55
|
+
4. in connection with professional services that you provide to a licensee
|
|
56
|
+
using the Software in accordance with these Terms and Conditions.
|
|
57
|
+
|
|
58
|
+
### Patents
|
|
59
|
+
|
|
60
|
+
To the extent your use for a Permitted Purpose would necessarily infringe our
|
|
61
|
+
patents, the license grant above includes a license under our patents. If you
|
|
62
|
+
make a claim against any party that the Software infringes or contributes to
|
|
63
|
+
the infringement of any patent, then your patent license to the Software ends
|
|
64
|
+
immediately.
|
|
65
|
+
|
|
66
|
+
### Redistribution
|
|
67
|
+
|
|
68
|
+
The Terms and Conditions apply to all copies, modifications and derivatives of
|
|
69
|
+
the Software.
|
|
70
|
+
|
|
71
|
+
If you redistribute any copies, modifications or derivatives of the Software,
|
|
72
|
+
you must include a copy of or a link to these Terms and Conditions and not
|
|
73
|
+
remove any copyright notices provided in or with the Software.
|
|
74
|
+
|
|
75
|
+
### Disclaimer
|
|
76
|
+
|
|
77
|
+
THE SOFTWARE IS PROVIDED "AS IS" AND WITHOUT WARRANTIES OF ANY KIND, EXPRESS OR
|
|
78
|
+
IMPLIED, INCLUDING WITHOUT LIMITATION WARRANTIES OF FITNESS FOR A PARTICULAR
|
|
79
|
+
PURPOSE, MERCHANTABILITY, TITLE OR NON-INFRINGEMENT.
|
|
80
|
+
|
|
81
|
+
IN NO EVENT WILL WE HAVE ANY LIABILITY TO YOU ARISING OUT OF OR RELATED TO THE
|
|
82
|
+
SOFTWARE, INCLUDING INDIRECT, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES,
|
|
83
|
+
EVEN IF WE HAVE BEEN INFORMED OF THEIR POSSIBILITY IN ADVANCE.
|
|
84
|
+
|
|
85
|
+
### Trademarks
|
|
86
|
+
|
|
87
|
+
Except for displaying the License Details and identifying us as the origin of
|
|
88
|
+
the Software, you have no right under these Terms and Conditions to use our
|
|
89
|
+
trademarks, trade names, service marks or product names.
|
|
90
|
+
|
|
91
|
+
## Grant of Future License
|
|
92
|
+
|
|
93
|
+
We hereby irrevocably grant you an additional license to use the Software under
|
|
94
|
+
the Apache License, Version 2.0 that is effective on the second anniversary of
|
|
95
|
+
the date we make the Software available. On or after that date, you may use the
|
|
96
|
+
Software under the Apache License, Version 2.0, in which case the following
|
|
97
|
+
will apply:
|
|
98
|
+
|
|
99
|
+
Licensed under the Apache License, Version 2.0 (the "License"); you may not use
|
|
100
|
+
this file except in compliance with the License.
|
|
101
|
+
|
|
102
|
+
You may obtain a copy of the License at
|
|
103
|
+
|
|
104
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
105
|
+
|
|
106
|
+
Unless required by applicable law or agreed to in writing, software distributed
|
|
107
|
+
under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
|
|
108
|
+
CONDITIONS OF ANY KIND, either express or implied. See the License for the
|
|
109
|
+
specific language governing permissions and limitations under the License.
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
/** Days a lead may stay New before its owner is reminded. */
|
|
2
|
+
export declare const NEW_LEAD_REMINDER_DAYS = 2;
|
|
3
|
+
export declare const notifyNewLead: import("@composable-os/sdk").AutomationSpec<{
|
|
4
|
+
readonly type: "record";
|
|
5
|
+
readonly object: "leads.lead";
|
|
6
|
+
readonly on: readonly ["created"];
|
|
7
|
+
}>;
|
|
8
|
+
export declare const remindNewLead: import("@composable-os/sdk").AutomationSpec<{
|
|
9
|
+
readonly type: "dateRelative";
|
|
10
|
+
readonly object: "leads.lead";
|
|
11
|
+
readonly field: "createdAt";
|
|
12
|
+
readonly offsetDays: 2;
|
|
13
|
+
}>;
|
|
14
|
+
export declare const leadAutomations: {
|
|
15
|
+
notifyNewLead: import("@composable-os/sdk").AutomationSpec<{
|
|
16
|
+
readonly type: "record";
|
|
17
|
+
readonly object: "leads.lead";
|
|
18
|
+
readonly on: readonly ["created"];
|
|
19
|
+
}>;
|
|
20
|
+
remindNewLead: import("@composable-os/sdk").AutomationSpec<{
|
|
21
|
+
readonly type: "dateRelative";
|
|
22
|
+
readonly object: "leads.lead";
|
|
23
|
+
readonly field: "createdAt";
|
|
24
|
+
readonly offsetDays: 2;
|
|
25
|
+
}>;
|
|
26
|
+
};
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
// The Leads automations (stage 15). Both are shipped turned off (`enabled: false`): a person turns
|
|
2
|
+
// them on under Automations. They declare their steps, so the host renders the summary from them.
|
|
3
|
+
import { defineAutomation } from "@composable-os/sdk";
|
|
4
|
+
/** Days a lead may stay New before its owner is reminded. */
|
|
5
|
+
export const NEW_LEAD_REMINDER_DAYS = 2;
|
|
6
|
+
export const notifyNewLead = defineAutomation({
|
|
7
|
+
label: "Notify the owner of a new lead",
|
|
8
|
+
description: "When a lead is created with an owner, tells the owner about it.",
|
|
9
|
+
enabled: false,
|
|
10
|
+
trigger: { type: "record", object: "leads.lead", on: ["created"] },
|
|
11
|
+
conditions: { field: "owner", op: "is_not_null" },
|
|
12
|
+
steps: [
|
|
13
|
+
{ name: "notifyOwner", notifies: [{ to: { field: "owner" }, message: "New lead: {record}" }] },
|
|
14
|
+
],
|
|
15
|
+
async run(_event, step, ctx) {
|
|
16
|
+
return step.do("notifyOwner", () => ctx.notify({ field: "owner" }, { title: "New lead: {record}", link: "record" }));
|
|
17
|
+
},
|
|
18
|
+
});
|
|
19
|
+
export const remindNewLead = defineAutomation({
|
|
20
|
+
label: "Remind the owner of a lead still new",
|
|
21
|
+
description: `${NEW_LEAD_REMINDER_DAYS} days after a lead is created, if it is still New, reminds its ` +
|
|
22
|
+
"owner to contact it.",
|
|
23
|
+
enabled: false,
|
|
24
|
+
trigger: {
|
|
25
|
+
type: "dateRelative",
|
|
26
|
+
object: "leads.lead",
|
|
27
|
+
field: "createdAt",
|
|
28
|
+
offsetDays: NEW_LEAD_REMINDER_DAYS,
|
|
29
|
+
},
|
|
30
|
+
conditions: {
|
|
31
|
+
and: [
|
|
32
|
+
{ field: "status", op: "eq", value: "new" },
|
|
33
|
+
{ field: "owner", op: "is_not_null" },
|
|
34
|
+
],
|
|
35
|
+
},
|
|
36
|
+
steps: [
|
|
37
|
+
{
|
|
38
|
+
name: "notifyOwner",
|
|
39
|
+
notifies: [{ to: { field: "owner" }, message: "{record} is still new" }],
|
|
40
|
+
},
|
|
41
|
+
],
|
|
42
|
+
async run(_event, step, ctx) {
|
|
43
|
+
return step.do("notifyOwner", () => ctx.notify({ field: "owner" }, {
|
|
44
|
+
title: "{record} is still new",
|
|
45
|
+
body: `It was created ${NEW_LEAD_REMINDER_DAYS} days ago. Contact it, or update its status.`,
|
|
46
|
+
link: "record",
|
|
47
|
+
}));
|
|
48
|
+
},
|
|
49
|
+
});
|
|
50
|
+
export const leadAutomations = { notifyNewLead, remindNewLead };
|
|
@@ -0,0 +1,143 @@
|
|
|
1
|
+
const OWNER = "(:owner IS NULL OR l.owner = :owner)";
|
|
2
|
+
const CREATED = "l.created_at >= :created_from AND l.created_at < :created_to";
|
|
3
|
+
const ownerFilter = { field: "owner", op: "eq", value: { $param: "owner" } };
|
|
4
|
+
const createdInRange = [
|
|
5
|
+
{ field: "createdAt", op: "gte", value: { $param: "created_from" } },
|
|
6
|
+
{ field: "createdAt", op: "lt", value: { $param: "created_to" } },
|
|
7
|
+
ownerFilter,
|
|
8
|
+
];
|
|
9
|
+
export const leadsDashboard = {
|
|
10
|
+
title: "Leads",
|
|
11
|
+
description: "New leads, where they come from, who has them, and how many became deals.",
|
|
12
|
+
filters: [
|
|
13
|
+
{ type: "dateRange", id: "created", label: "Created", default: "this_quarter" },
|
|
14
|
+
{ type: "user", id: "owner", label: "Owner", default: "anyone" },
|
|
15
|
+
],
|
|
16
|
+
widgets: [
|
|
17
|
+
{
|
|
18
|
+
id: "created",
|
|
19
|
+
type: "kpi",
|
|
20
|
+
title: "Leads created",
|
|
21
|
+
description: "Leads created in the period, against the previous period.",
|
|
22
|
+
sql: `SELECT count(*) AS value FROM rec_x_leads_lead l WHERE ${CREATED} AND ${OWNER}`,
|
|
23
|
+
mapping: { value: "value" },
|
|
24
|
+
options: { compare: true },
|
|
25
|
+
clickThrough: { object: "leads.lead", filter: { and: createdInRange } },
|
|
26
|
+
layout: { w: 4, h: 1 },
|
|
27
|
+
},
|
|
28
|
+
{
|
|
29
|
+
id: "open",
|
|
30
|
+
type: "kpi",
|
|
31
|
+
title: "In the inbox",
|
|
32
|
+
description: "Leads that are new or contacted (not limited to the period).",
|
|
33
|
+
sql: `SELECT count(*) AS value FROM rec_x_leads_lead l WHERE l.status IN ('new', 'contacted') AND ${OWNER}`,
|
|
34
|
+
mapping: { value: "value" },
|
|
35
|
+
options: { compare: false },
|
|
36
|
+
clickThrough: {
|
|
37
|
+
object: "leads.lead",
|
|
38
|
+
filter: {
|
|
39
|
+
and: [{ field: "status", op: "in", value: ["new", "contacted"] }, ownerFilter],
|
|
40
|
+
},
|
|
41
|
+
},
|
|
42
|
+
layout: { w: 4, h: 1 },
|
|
43
|
+
},
|
|
44
|
+
{
|
|
45
|
+
id: "converted-this-month",
|
|
46
|
+
type: "kpi",
|
|
47
|
+
title: "Converted this month",
|
|
48
|
+
description: "Leads converted into deals since the start of this month.",
|
|
49
|
+
sql: [
|
|
50
|
+
"SELECT count(*) AS value, strftime('%Y-%m-01', :today) AS month_start",
|
|
51
|
+
"FROM rec_x_leads_lead l",
|
|
52
|
+
`WHERE l.status = 'converted' AND l.converted_at >= strftime('%Y-%m-01', :today) AND ${OWNER}`,
|
|
53
|
+
].join("\n"),
|
|
54
|
+
mapping: { value: "value" },
|
|
55
|
+
options: { compare: false },
|
|
56
|
+
clickThrough: {
|
|
57
|
+
object: "leads.lead",
|
|
58
|
+
filter: {
|
|
59
|
+
and: [
|
|
60
|
+
{ field: "status", op: "eq", value: "converted" },
|
|
61
|
+
{ field: "convertedAt", op: "gte", value: { $row: "month_start" } },
|
|
62
|
+
ownerFilter,
|
|
63
|
+
],
|
|
64
|
+
},
|
|
65
|
+
},
|
|
66
|
+
layout: { w: 4, h: 1 },
|
|
67
|
+
},
|
|
68
|
+
{
|
|
69
|
+
id: "by-status",
|
|
70
|
+
type: "bar",
|
|
71
|
+
title: "Leads by status",
|
|
72
|
+
description: "Leads created in the period, by their status now.",
|
|
73
|
+
sql: [
|
|
74
|
+
"SELECT coalesce(l.status, '') AS status, count(*) AS leads",
|
|
75
|
+
"FROM rec_x_leads_lead l",
|
|
76
|
+
`WHERE ${CREATED} AND ${OWNER}`,
|
|
77
|
+
"GROUP BY l.status ORDER BY leads DESC, status",
|
|
78
|
+
].join("\n"),
|
|
79
|
+
mapping: { x: "status", y: "leads" },
|
|
80
|
+
clickThrough: {
|
|
81
|
+
object: "leads.lead",
|
|
82
|
+
filter: {
|
|
83
|
+
and: [...createdInRange, { field: "status", op: "eq", value: { $row: "status" } }],
|
|
84
|
+
},
|
|
85
|
+
},
|
|
86
|
+
layout: { w: 6, h: 3 },
|
|
87
|
+
},
|
|
88
|
+
{
|
|
89
|
+
id: "by-source",
|
|
90
|
+
type: "donut",
|
|
91
|
+
title: "Leads by source",
|
|
92
|
+
sql: [
|
|
93
|
+
"SELECT coalesce(l.source, '') AS source, count(*) AS leads",
|
|
94
|
+
"FROM rec_x_leads_lead l",
|
|
95
|
+
`WHERE ${CREATED} AND ${OWNER}`,
|
|
96
|
+
"GROUP BY l.source ORDER BY leads DESC, source",
|
|
97
|
+
].join("\n"),
|
|
98
|
+
mapping: { label: "source", value: "leads" },
|
|
99
|
+
clickThrough: {
|
|
100
|
+
object: "leads.lead",
|
|
101
|
+
filter: {
|
|
102
|
+
and: [...createdInRange, { field: "source", op: "eq", value: { $row: "source" } }],
|
|
103
|
+
},
|
|
104
|
+
},
|
|
105
|
+
layout: { w: 6, h: 3 },
|
|
106
|
+
},
|
|
107
|
+
{
|
|
108
|
+
id: "by-owner",
|
|
109
|
+
type: "bar",
|
|
110
|
+
title: "Leads by owner",
|
|
111
|
+
description: "Leads created in the period, by owner (unassigned ones under No owner).",
|
|
112
|
+
sql: [
|
|
113
|
+
"SELECT coalesce(l.owner, '') AS owner_id, coalesce(u.name, 'No owner') AS owner,",
|
|
114
|
+
" count(*) AS leads",
|
|
115
|
+
"FROM rec_x_leads_lead l LEFT JOIN rec_user u ON u.id = l.owner",
|
|
116
|
+
`WHERE ${CREATED} AND ${OWNER}`,
|
|
117
|
+
"GROUP BY l.owner, u.name ORDER BY leads DESC, owner",
|
|
118
|
+
].join("\n"),
|
|
119
|
+
mapping: { x: "owner", y: "leads" },
|
|
120
|
+
options: { orientation: "horizontal" },
|
|
121
|
+
clickThrough: {
|
|
122
|
+
object: "leads.lead",
|
|
123
|
+
filter: {
|
|
124
|
+
and: [...createdInRange, { field: "owner", op: "eq", value: { $row: "owner_id" } }],
|
|
125
|
+
},
|
|
126
|
+
},
|
|
127
|
+
layout: { w: 6, h: 3 },
|
|
128
|
+
},
|
|
129
|
+
{
|
|
130
|
+
id: "per-week",
|
|
131
|
+
type: "line",
|
|
132
|
+
title: "Leads created per week",
|
|
133
|
+
sql: [
|
|
134
|
+
"SELECT date(l.created_at, '-6 days', 'weekday 1') AS week, count(*) AS leads",
|
|
135
|
+
"FROM rec_x_leads_lead l",
|
|
136
|
+
`WHERE ${CREATED} AND ${OWNER}`,
|
|
137
|
+
"GROUP BY week ORDER BY week",
|
|
138
|
+
].join("\n"),
|
|
139
|
+
mapping: { x: "week", y: "leads" },
|
|
140
|
+
layout: { w: 6, h: 3 },
|
|
141
|
+
},
|
|
142
|
+
],
|
|
143
|
+
};
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,330 @@
|
|
|
1
|
+
export declare const SOURCES: {
|
|
2
|
+
value: string;
|
|
3
|
+
label: string;
|
|
4
|
+
}[];
|
|
5
|
+
declare const _default: import("@composable-os/sdk").Extension<{
|
|
6
|
+
readonly id: "leads";
|
|
7
|
+
readonly version: "1.0.0";
|
|
8
|
+
readonly contractVersion: 1;
|
|
9
|
+
readonly label: "Leads";
|
|
10
|
+
readonly description: string;
|
|
11
|
+
readonly permissions: {
|
|
12
|
+
readonly read: ["person", "organisation", "deals.pipeline", "deals.stage"];
|
|
13
|
+
readonly write: ["person", "deals.deal", "deals.participant"];
|
|
14
|
+
readonly operations: ["notification.send", "extensionSettings.list"];
|
|
15
|
+
readonly modules: ["ops", "log"];
|
|
16
|
+
};
|
|
17
|
+
readonly objects: {
|
|
18
|
+
readonly lead: {
|
|
19
|
+
readonly label: "Lead";
|
|
20
|
+
readonly plural: "Leads";
|
|
21
|
+
readonly icon: "target";
|
|
22
|
+
readonly titleField: "name";
|
|
23
|
+
readonly description: string;
|
|
24
|
+
readonly navigationOrder: 10;
|
|
25
|
+
readonly owner: "owner";
|
|
26
|
+
readonly requireOneOf: readonly [readonly ["person", "organisation"]];
|
|
27
|
+
readonly titleDefault: {
|
|
28
|
+
readonly from: readonly ["person", "organisation"];
|
|
29
|
+
readonly suffix: " lead";
|
|
30
|
+
};
|
|
31
|
+
readonly fields: {
|
|
32
|
+
readonly name: {
|
|
33
|
+
readonly type: "text";
|
|
34
|
+
readonly label: "Name";
|
|
35
|
+
readonly required: true;
|
|
36
|
+
readonly description: "Left blank, the person's or organisation's name followed by “lead”.";
|
|
37
|
+
};
|
|
38
|
+
readonly person: {
|
|
39
|
+
readonly type: "relation";
|
|
40
|
+
readonly label: "Person";
|
|
41
|
+
readonly to: "person";
|
|
42
|
+
};
|
|
43
|
+
readonly organisation: {
|
|
44
|
+
readonly type: "relation";
|
|
45
|
+
readonly label: "Organisation";
|
|
46
|
+
readonly to: "organisation";
|
|
47
|
+
};
|
|
48
|
+
readonly status: {
|
|
49
|
+
readonly type: "select";
|
|
50
|
+
readonly label: "Status";
|
|
51
|
+
readonly track: "timeline";
|
|
52
|
+
readonly default: "new";
|
|
53
|
+
readonly editableOptions: true;
|
|
54
|
+
readonly description: "Where the lead is. Converted is set by converting the lead; unqualified needs a reason.";
|
|
55
|
+
readonly options: readonly [{
|
|
56
|
+
readonly value: "new";
|
|
57
|
+
readonly label: "New";
|
|
58
|
+
readonly fixed: true;
|
|
59
|
+
}, {
|
|
60
|
+
readonly value: "contacted";
|
|
61
|
+
readonly label: "Contacted";
|
|
62
|
+
readonly fixed: true;
|
|
63
|
+
}, {
|
|
64
|
+
readonly value: "qualified";
|
|
65
|
+
readonly label: "Qualified";
|
|
66
|
+
readonly color: "green";
|
|
67
|
+
}, {
|
|
68
|
+
readonly value: "unqualified";
|
|
69
|
+
readonly label: "Unqualified";
|
|
70
|
+
readonly color: "red";
|
|
71
|
+
readonly fixed: true;
|
|
72
|
+
readonly requires: ["unqualifiedReason"];
|
|
73
|
+
}, {
|
|
74
|
+
readonly value: "converted";
|
|
75
|
+
readonly label: "Converted";
|
|
76
|
+
readonly fixed: true;
|
|
77
|
+
readonly requires: ["deal"];
|
|
78
|
+
}];
|
|
79
|
+
};
|
|
80
|
+
readonly source: {
|
|
81
|
+
readonly type: "select";
|
|
82
|
+
readonly label: "Source";
|
|
83
|
+
readonly editableOptions: true;
|
|
84
|
+
readonly default: "other";
|
|
85
|
+
readonly defaultSetting: "defaultSource";
|
|
86
|
+
readonly description: "Where the lead came from.";
|
|
87
|
+
readonly options: {
|
|
88
|
+
value: string;
|
|
89
|
+
label: string;
|
|
90
|
+
}[];
|
|
91
|
+
};
|
|
92
|
+
readonly owner: {
|
|
93
|
+
readonly type: "user";
|
|
94
|
+
readonly label: "Owner";
|
|
95
|
+
};
|
|
96
|
+
readonly unqualifiedReason: {
|
|
97
|
+
readonly type: "select";
|
|
98
|
+
readonly label: "Unqualified reason";
|
|
99
|
+
readonly description: "Why the lead was disqualified.";
|
|
100
|
+
readonly options: readonly [{
|
|
101
|
+
readonly value: "noBudget";
|
|
102
|
+
readonly label: "No budget";
|
|
103
|
+
}, {
|
|
104
|
+
readonly value: "noNeed";
|
|
105
|
+
readonly label: "No need";
|
|
106
|
+
}, {
|
|
107
|
+
readonly value: "noAuthority";
|
|
108
|
+
readonly label: "No authority";
|
|
109
|
+
}, {
|
|
110
|
+
readonly value: "badTiming";
|
|
111
|
+
readonly label: "Bad timing";
|
|
112
|
+
}, {
|
|
113
|
+
readonly value: "competitor";
|
|
114
|
+
readonly label: "Went with a competitor";
|
|
115
|
+
}, {
|
|
116
|
+
readonly value: "unresponsive";
|
|
117
|
+
readonly label: "Unresponsive";
|
|
118
|
+
}, {
|
|
119
|
+
readonly value: "other";
|
|
120
|
+
readonly label: "Other";
|
|
121
|
+
}];
|
|
122
|
+
};
|
|
123
|
+
readonly notes: {
|
|
124
|
+
readonly type: "longText";
|
|
125
|
+
readonly label: "Notes";
|
|
126
|
+
};
|
|
127
|
+
readonly deal: {
|
|
128
|
+
readonly type: "relation";
|
|
129
|
+
readonly label: "Deal";
|
|
130
|
+
readonly to: "deals.deal";
|
|
131
|
+
readonly readOnly: true;
|
|
132
|
+
readonly description: "The deal the lead was converted into.";
|
|
133
|
+
};
|
|
134
|
+
readonly convertedAt: {
|
|
135
|
+
readonly type: "date";
|
|
136
|
+
readonly label: "Converted on";
|
|
137
|
+
readonly readOnly: true;
|
|
138
|
+
readonly description: "Set when the lead is converted.";
|
|
139
|
+
};
|
|
140
|
+
readonly ageDays: {
|
|
141
|
+
readonly type: "formula";
|
|
142
|
+
readonly label: "Age (days)";
|
|
143
|
+
readonly expression: "dateDiff(createdAt, today(), \"day\")";
|
|
144
|
+
};
|
|
145
|
+
};
|
|
146
|
+
readonly timelineLinks: readonly ["person", "organisation"];
|
|
147
|
+
readonly indexes: readonly [readonly ["owner", "status"], readonly ["status", "createdAt"], readonly ["person"], readonly ["organisation"]];
|
|
148
|
+
};
|
|
149
|
+
};
|
|
150
|
+
readonly fields: {
|
|
151
|
+
readonly "deals.deal": {
|
|
152
|
+
readonly lead: {
|
|
153
|
+
readonly type: "relation";
|
|
154
|
+
readonly label: "Lead";
|
|
155
|
+
readonly to: "leads.lead";
|
|
156
|
+
readonly readOnly: true;
|
|
157
|
+
readonly description: "The lead this deal was converted from.";
|
|
158
|
+
};
|
|
159
|
+
};
|
|
160
|
+
};
|
|
161
|
+
readonly views: {
|
|
162
|
+
readonly leadsInbox: {
|
|
163
|
+
readonly label: "Leads inbox";
|
|
164
|
+
readonly object: "leads.lead";
|
|
165
|
+
readonly filter: {
|
|
166
|
+
readonly field: "status";
|
|
167
|
+
readonly op: "in";
|
|
168
|
+
readonly value: readonly ["new", "contacted"];
|
|
169
|
+
};
|
|
170
|
+
readonly sort: {
|
|
171
|
+
readonly field: "createdAt";
|
|
172
|
+
readonly direction: "desc";
|
|
173
|
+
};
|
|
174
|
+
readonly columns: string[];
|
|
175
|
+
};
|
|
176
|
+
readonly myLeads: {
|
|
177
|
+
readonly label: "My leads";
|
|
178
|
+
readonly object: "leads.lead";
|
|
179
|
+
readonly filter: {
|
|
180
|
+
readonly field: "owner";
|
|
181
|
+
readonly op: "eq";
|
|
182
|
+
readonly value: {
|
|
183
|
+
readonly $relative: "me";
|
|
184
|
+
};
|
|
185
|
+
};
|
|
186
|
+
readonly sort: {
|
|
187
|
+
readonly field: "createdAt";
|
|
188
|
+
readonly direction: "desc";
|
|
189
|
+
};
|
|
190
|
+
readonly columns: string[];
|
|
191
|
+
};
|
|
192
|
+
readonly unassigned: {
|
|
193
|
+
readonly label: "Unassigned";
|
|
194
|
+
readonly object: "leads.lead";
|
|
195
|
+
readonly filter: {
|
|
196
|
+
readonly field: "owner";
|
|
197
|
+
readonly op: "is_null";
|
|
198
|
+
};
|
|
199
|
+
readonly sort: {
|
|
200
|
+
readonly field: "createdAt";
|
|
201
|
+
readonly direction: "desc";
|
|
202
|
+
};
|
|
203
|
+
readonly columns: string[];
|
|
204
|
+
};
|
|
205
|
+
readonly leadsBoard: {
|
|
206
|
+
readonly label: "Leads by status";
|
|
207
|
+
readonly type: "board";
|
|
208
|
+
readonly object: "leads.lead";
|
|
209
|
+
readonly groupBy: "status";
|
|
210
|
+
readonly cardFields: ["person", "organisation", "owner", "source"];
|
|
211
|
+
readonly sort: {
|
|
212
|
+
readonly field: "createdAt";
|
|
213
|
+
readonly direction: "desc";
|
|
214
|
+
};
|
|
215
|
+
};
|
|
216
|
+
};
|
|
217
|
+
readonly recordTabs: {
|
|
218
|
+
readonly personLeads: {
|
|
219
|
+
readonly label: "Leads";
|
|
220
|
+
readonly on: "person";
|
|
221
|
+
readonly view: {
|
|
222
|
+
readonly type: "table";
|
|
223
|
+
readonly object: "leads.lead";
|
|
224
|
+
readonly relation: "person";
|
|
225
|
+
readonly columns: ["name", "status", "source", "owner", "organisation"];
|
|
226
|
+
readonly sort: {
|
|
227
|
+
readonly field: "createdAt";
|
|
228
|
+
readonly direction: "desc";
|
|
229
|
+
};
|
|
230
|
+
};
|
|
231
|
+
readonly order: 15;
|
|
232
|
+
};
|
|
233
|
+
readonly organisationLeads: {
|
|
234
|
+
readonly label: "Leads";
|
|
235
|
+
readonly on: "organisation";
|
|
236
|
+
readonly view: {
|
|
237
|
+
readonly type: "table";
|
|
238
|
+
readonly object: "leads.lead";
|
|
239
|
+
readonly relation: "organisation";
|
|
240
|
+
readonly columns: ["name", "status", "source", "owner", "person"];
|
|
241
|
+
readonly sort: {
|
|
242
|
+
readonly field: "createdAt";
|
|
243
|
+
readonly direction: "desc";
|
|
244
|
+
};
|
|
245
|
+
};
|
|
246
|
+
readonly order: 15;
|
|
247
|
+
};
|
|
248
|
+
};
|
|
249
|
+
readonly recordPanels: {
|
|
250
|
+
readonly leadDeal: {
|
|
251
|
+
readonly label: "Deal";
|
|
252
|
+
readonly on: "leads.lead";
|
|
253
|
+
readonly view: {
|
|
254
|
+
readonly type: "table";
|
|
255
|
+
readonly object: "deals.deal";
|
|
256
|
+
readonly relation: "leads.lead";
|
|
257
|
+
readonly columns: ["name", "stage", "value", "owner"];
|
|
258
|
+
};
|
|
259
|
+
};
|
|
260
|
+
};
|
|
261
|
+
readonly settings: {
|
|
262
|
+
readonly defaultSource: {
|
|
263
|
+
readonly type: "select";
|
|
264
|
+
readonly label: "Default source";
|
|
265
|
+
readonly description: "The source a new lead gets when none is given.";
|
|
266
|
+
readonly options: {
|
|
267
|
+
value: string;
|
|
268
|
+
label: string;
|
|
269
|
+
}[];
|
|
270
|
+
readonly default: "other";
|
|
271
|
+
};
|
|
272
|
+
readonly openDealAfterConvert: {
|
|
273
|
+
readonly type: "boolean";
|
|
274
|
+
readonly label: "Open the new deal after converting";
|
|
275
|
+
readonly description: "After Convert to deal, go straight to the deal.";
|
|
276
|
+
readonly default: true;
|
|
277
|
+
};
|
|
278
|
+
};
|
|
279
|
+
readonly dashboards: {
|
|
280
|
+
readonly leads: import("@composable-os/sdk").DashboardDeclaration;
|
|
281
|
+
};
|
|
282
|
+
readonly tools: {
|
|
283
|
+
readonly convert: import("@composable-os/sdk").ToolSpec<import("zod").ZodObject<{
|
|
284
|
+
leadId: import("zod").ZodString;
|
|
285
|
+
dealName: import("zod").ZodOptional<import("zod").ZodString>;
|
|
286
|
+
pipeline: import("zod").ZodOptional<import("zod").ZodString>;
|
|
287
|
+
stage: import("zod").ZodOptional<import("zod").ZodString>;
|
|
288
|
+
value: import("zod").ZodOptional<import("zod").ZodNumber>;
|
|
289
|
+
expectedClose: import("zod").ZodOptional<import("zod").ZodString>;
|
|
290
|
+
}, import("zod/v4/core").$strip>, import("zod").ZodObject<{
|
|
291
|
+
leadId: import("zod").ZodString;
|
|
292
|
+
dealId: import("zod").ZodString;
|
|
293
|
+
created: import("zod").ZodBoolean;
|
|
294
|
+
open: import("zod").ZodNullable<import("zod").ZodObject<{
|
|
295
|
+
object: import("zod").ZodString;
|
|
296
|
+
id: import("zod").ZodString;
|
|
297
|
+
}, import("zod/v4/core").$strip>>;
|
|
298
|
+
}, import("zod/v4/core").$strip>>;
|
|
299
|
+
readonly disqualify: import("@composable-os/sdk").ToolSpec<import("zod").ZodObject<{
|
|
300
|
+
leadId: import("zod").ZodString;
|
|
301
|
+
reason: import("zod").ZodEnum<{
|
|
302
|
+
noBudget: "noBudget";
|
|
303
|
+
noNeed: "noNeed";
|
|
304
|
+
noAuthority: "noAuthority";
|
|
305
|
+
badTiming: "badTiming";
|
|
306
|
+
competitor: "competitor";
|
|
307
|
+
unresponsive: "unresponsive";
|
|
308
|
+
other: "other";
|
|
309
|
+
}>;
|
|
310
|
+
}, import("zod/v4/core").$strip>, import("zod").ZodObject<{
|
|
311
|
+
leadId: import("zod").ZodString;
|
|
312
|
+
status: import("zod").ZodString;
|
|
313
|
+
reason: import("zod").ZodString;
|
|
314
|
+
}, import("zod/v4/core").$strip>>;
|
|
315
|
+
};
|
|
316
|
+
readonly automations: {
|
|
317
|
+
notifyNewLead: import("@composable-os/sdk").AutomationSpec<{
|
|
318
|
+
readonly type: "record";
|
|
319
|
+
readonly object: "leads.lead";
|
|
320
|
+
readonly on: readonly ["created"];
|
|
321
|
+
}>;
|
|
322
|
+
remindNewLead: import("@composable-os/sdk").AutomationSpec<{
|
|
323
|
+
readonly type: "dateRelative";
|
|
324
|
+
readonly object: "leads.lead";
|
|
325
|
+
readonly field: "createdAt";
|
|
326
|
+
readonly offsetDays: 2;
|
|
327
|
+
}>;
|
|
328
|
+
};
|
|
329
|
+
}>;
|
|
330
|
+
export default _default;
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,218 @@
|
|
|
1
|
+
// Leads: the second shipped extension (stage 15, ADR 0246), built on the public contract like
|
|
2
|
+
// Deals and depending on it. A lead is inbound interest linked to a real person and organisation
|
|
3
|
+
// (never copies of them), with a status, a source and an owner. Salespeople work leads from the
|
|
4
|
+
// Leads inbox, qualify or disqualify them, and convert the good ones into deals: `convert`
|
|
5
|
+
// creates a deal on the same organisation and person and links the two, copying no data. Owners
|
|
6
|
+
// of new leads come from the host's assignment rules (`owner: "owner"`).
|
|
7
|
+
import { defineExtension } from "@composable-os/sdk";
|
|
8
|
+
import { leadAutomations } from "./automations.js";
|
|
9
|
+
import { leadsDashboard } from "./dashboards.js";
|
|
10
|
+
import { convert, disqualify, UNQUALIFIED_REASONS } from "./tools.js";
|
|
11
|
+
export const SOURCES = [
|
|
12
|
+
{ value: "website", label: "Website" },
|
|
13
|
+
{ value: "referral", label: "Referral" },
|
|
14
|
+
{ value: "event", label: "Event" },
|
|
15
|
+
{ value: "outbound", label: "Outbound" },
|
|
16
|
+
{ value: "partner", label: "Partner" },
|
|
17
|
+
{ value: "import", label: "Import" },
|
|
18
|
+
{ value: "other", label: "Other" },
|
|
19
|
+
];
|
|
20
|
+
const INBOX_COLUMNS = ["name", "status", "owner", "source", "person", "organisation", "ageDays"];
|
|
21
|
+
export default defineExtension({
|
|
22
|
+
id: "leads",
|
|
23
|
+
version: "1.0.0",
|
|
24
|
+
contractVersion: 1,
|
|
25
|
+
label: "Leads",
|
|
26
|
+
description: "Inbound interest linked to a person and an organisation, worked from a leads inbox, " +
|
|
27
|
+
"qualified or disqualified, and converted into deals. Requires Deals.",
|
|
28
|
+
permissions: {
|
|
29
|
+
read: ["person", "organisation", "deals.pipeline", "deals.stage"],
|
|
30
|
+
write: ["person", "deals.deal", "deals.participant"],
|
|
31
|
+
operations: ["notification.send", "extensionSettings.list"],
|
|
32
|
+
modules: ["ops", "log"],
|
|
33
|
+
},
|
|
34
|
+
objects: {
|
|
35
|
+
lead: {
|
|
36
|
+
label: "Lead",
|
|
37
|
+
plural: "Leads",
|
|
38
|
+
icon: "target",
|
|
39
|
+
titleField: "name",
|
|
40
|
+
description: "Inbound interest: a person and/or organisation who may buy, with a status, a source and " +
|
|
41
|
+
"an owner. Converting a lead creates a deal for the same organisation and person.",
|
|
42
|
+
navigationOrder: 10,
|
|
43
|
+
owner: "owner",
|
|
44
|
+
requireOneOf: [["person", "organisation"]],
|
|
45
|
+
titleDefault: { from: ["person", "organisation"], suffix: " lead" },
|
|
46
|
+
fields: {
|
|
47
|
+
name: {
|
|
48
|
+
type: "text",
|
|
49
|
+
label: "Name",
|
|
50
|
+
required: true,
|
|
51
|
+
description: "Left blank, the person's or organisation's name followed by “lead”.",
|
|
52
|
+
},
|
|
53
|
+
person: { type: "relation", label: "Person", to: "person" },
|
|
54
|
+
organisation: { type: "relation", label: "Organisation", to: "organisation" },
|
|
55
|
+
status: {
|
|
56
|
+
type: "select",
|
|
57
|
+
label: "Status",
|
|
58
|
+
track: "timeline",
|
|
59
|
+
default: "new",
|
|
60
|
+
editableOptions: true,
|
|
61
|
+
description: "Where the lead is. Converted is set by converting the lead; unqualified needs a reason.",
|
|
62
|
+
options: [
|
|
63
|
+
{ value: "new", label: "New", fixed: true },
|
|
64
|
+
{ value: "contacted", label: "Contacted", fixed: true },
|
|
65
|
+
{ value: "qualified", label: "Qualified", color: "green" },
|
|
66
|
+
{
|
|
67
|
+
value: "unqualified",
|
|
68
|
+
label: "Unqualified",
|
|
69
|
+
color: "red",
|
|
70
|
+
fixed: true,
|
|
71
|
+
requires: ["unqualifiedReason"],
|
|
72
|
+
},
|
|
73
|
+
{ value: "converted", label: "Converted", fixed: true, requires: ["deal"] },
|
|
74
|
+
],
|
|
75
|
+
},
|
|
76
|
+
source: {
|
|
77
|
+
type: "select",
|
|
78
|
+
label: "Source",
|
|
79
|
+
editableOptions: true,
|
|
80
|
+
default: "other",
|
|
81
|
+
defaultSetting: "defaultSource",
|
|
82
|
+
description: "Where the lead came from.",
|
|
83
|
+
options: SOURCES,
|
|
84
|
+
},
|
|
85
|
+
owner: { type: "user", label: "Owner" },
|
|
86
|
+
unqualifiedReason: {
|
|
87
|
+
type: "select",
|
|
88
|
+
label: "Unqualified reason",
|
|
89
|
+
description: "Why the lead was disqualified.",
|
|
90
|
+
options: [...UNQUALIFIED_REASONS],
|
|
91
|
+
},
|
|
92
|
+
notes: { type: "longText", label: "Notes" },
|
|
93
|
+
deal: {
|
|
94
|
+
type: "relation",
|
|
95
|
+
label: "Deal",
|
|
96
|
+
to: "deals.deal",
|
|
97
|
+
readOnly: true,
|
|
98
|
+
description: "The deal the lead was converted into.",
|
|
99
|
+
},
|
|
100
|
+
convertedAt: {
|
|
101
|
+
type: "date",
|
|
102
|
+
label: "Converted on",
|
|
103
|
+
readOnly: true,
|
|
104
|
+
description: "Set when the lead is converted.",
|
|
105
|
+
},
|
|
106
|
+
ageDays: {
|
|
107
|
+
type: "formula",
|
|
108
|
+
label: "Age (days)",
|
|
109
|
+
expression: 'dateDiff(createdAt, today(), "day")',
|
|
110
|
+
},
|
|
111
|
+
},
|
|
112
|
+
// A lead's activity also shows on its person and organisation.
|
|
113
|
+
timelineLinks: ["person", "organisation"],
|
|
114
|
+
// Hot queries: the inbox (status, newest first), my leads, a person's or organisation's
|
|
115
|
+
// leads, and a converted lead's deal.
|
|
116
|
+
indexes: [["owner", "status"], ["status", "createdAt"], ["person"], ["organisation"]],
|
|
117
|
+
},
|
|
118
|
+
},
|
|
119
|
+
// A lead's deal is shown on the deal too: where it came from. Set by `convert` only.
|
|
120
|
+
fields: {
|
|
121
|
+
"deals.deal": {
|
|
122
|
+
lead: {
|
|
123
|
+
type: "relation",
|
|
124
|
+
label: "Lead",
|
|
125
|
+
to: "leads.lead",
|
|
126
|
+
readOnly: true,
|
|
127
|
+
description: "The lead this deal was converted from.",
|
|
128
|
+
},
|
|
129
|
+
},
|
|
130
|
+
},
|
|
131
|
+
views: {
|
|
132
|
+
leadsInbox: {
|
|
133
|
+
label: "Leads inbox",
|
|
134
|
+
object: "leads.lead",
|
|
135
|
+
filter: { field: "status", op: "in", value: ["new", "contacted"] },
|
|
136
|
+
sort: { field: "createdAt", direction: "desc" },
|
|
137
|
+
columns: INBOX_COLUMNS,
|
|
138
|
+
},
|
|
139
|
+
myLeads: {
|
|
140
|
+
label: "My leads",
|
|
141
|
+
object: "leads.lead",
|
|
142
|
+
filter: { field: "owner", op: "eq", value: { $relative: "me" } },
|
|
143
|
+
sort: { field: "createdAt", direction: "desc" },
|
|
144
|
+
columns: INBOX_COLUMNS,
|
|
145
|
+
},
|
|
146
|
+
unassigned: {
|
|
147
|
+
label: "Unassigned",
|
|
148
|
+
object: "leads.lead",
|
|
149
|
+
filter: { field: "owner", op: "is_null" },
|
|
150
|
+
sort: { field: "createdAt", direction: "desc" },
|
|
151
|
+
columns: INBOX_COLUMNS,
|
|
152
|
+
},
|
|
153
|
+
leadsBoard: {
|
|
154
|
+
label: "Leads by status",
|
|
155
|
+
type: "board",
|
|
156
|
+
object: "leads.lead",
|
|
157
|
+
groupBy: "status",
|
|
158
|
+
cardFields: ["person", "organisation", "owner", "source"],
|
|
159
|
+
sort: { field: "createdAt", direction: "desc" },
|
|
160
|
+
},
|
|
161
|
+
},
|
|
162
|
+
recordTabs: {
|
|
163
|
+
personLeads: {
|
|
164
|
+
label: "Leads",
|
|
165
|
+
on: "person",
|
|
166
|
+
view: {
|
|
167
|
+
type: "table",
|
|
168
|
+
object: "leads.lead",
|
|
169
|
+
relation: "person",
|
|
170
|
+
columns: ["name", "status", "source", "owner", "organisation"],
|
|
171
|
+
sort: { field: "createdAt", direction: "desc" },
|
|
172
|
+
},
|
|
173
|
+
order: 15,
|
|
174
|
+
},
|
|
175
|
+
organisationLeads: {
|
|
176
|
+
label: "Leads",
|
|
177
|
+
on: "organisation",
|
|
178
|
+
view: {
|
|
179
|
+
type: "table",
|
|
180
|
+
object: "leads.lead",
|
|
181
|
+
relation: "organisation",
|
|
182
|
+
columns: ["name", "status", "source", "owner", "person"],
|
|
183
|
+
sort: { field: "createdAt", direction: "desc" },
|
|
184
|
+
},
|
|
185
|
+
order: 15,
|
|
186
|
+
},
|
|
187
|
+
},
|
|
188
|
+
recordPanels: {
|
|
189
|
+
leadDeal: {
|
|
190
|
+
label: "Deal",
|
|
191
|
+
on: "leads.lead",
|
|
192
|
+
view: {
|
|
193
|
+
type: "table",
|
|
194
|
+
object: "deals.deal",
|
|
195
|
+
relation: "leads.lead",
|
|
196
|
+
columns: ["name", "stage", "value", "owner"],
|
|
197
|
+
},
|
|
198
|
+
},
|
|
199
|
+
},
|
|
200
|
+
settings: {
|
|
201
|
+
defaultSource: {
|
|
202
|
+
type: "select",
|
|
203
|
+
label: "Default source",
|
|
204
|
+
description: "The source a new lead gets when none is given.",
|
|
205
|
+
options: SOURCES,
|
|
206
|
+
default: "other",
|
|
207
|
+
},
|
|
208
|
+
openDealAfterConvert: {
|
|
209
|
+
type: "boolean",
|
|
210
|
+
label: "Open the new deal after converting",
|
|
211
|
+
description: "After Convert to deal, go straight to the deal.",
|
|
212
|
+
default: true,
|
|
213
|
+
},
|
|
214
|
+
},
|
|
215
|
+
dashboards: { leads: leadsDashboard },
|
|
216
|
+
tools: { convert, disqualify },
|
|
217
|
+
automations: leadAutomations,
|
|
218
|
+
});
|
package/dist/tools.d.ts
ADDED
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
import { z } from "@composable-os/sdk";
|
|
2
|
+
/** Why a lead is disqualified: the `unqualifiedReason` field's options. */
|
|
3
|
+
export declare const UNQUALIFIED_REASONS: readonly [{
|
|
4
|
+
readonly value: "noBudget";
|
|
5
|
+
readonly label: "No budget";
|
|
6
|
+
}, {
|
|
7
|
+
readonly value: "noNeed";
|
|
8
|
+
readonly label: "No need";
|
|
9
|
+
}, {
|
|
10
|
+
readonly value: "noAuthority";
|
|
11
|
+
readonly label: "No authority";
|
|
12
|
+
}, {
|
|
13
|
+
readonly value: "badTiming";
|
|
14
|
+
readonly label: "Bad timing";
|
|
15
|
+
}, {
|
|
16
|
+
readonly value: "competitor";
|
|
17
|
+
readonly label: "Went with a competitor";
|
|
18
|
+
}, {
|
|
19
|
+
readonly value: "unresponsive";
|
|
20
|
+
readonly label: "Unresponsive";
|
|
21
|
+
}, {
|
|
22
|
+
readonly value: "other";
|
|
23
|
+
readonly label: "Other";
|
|
24
|
+
}];
|
|
25
|
+
/** The deal field Leads adds (`fields["deals.deal"].lead`), by its registry name. */
|
|
26
|
+
export declare const DEAL_LEAD_FIELD = "leads.lead";
|
|
27
|
+
/** The lifecycle extension's person field, when that extension is installed. */
|
|
28
|
+
export declare const LIFECYCLE_FIELD = "lifecycle.lifecycleStage";
|
|
29
|
+
export declare const convert: import("@composable-os/sdk").ToolSpec<z.ZodObject<{
|
|
30
|
+
leadId: z.ZodString;
|
|
31
|
+
dealName: z.ZodOptional<z.ZodString>;
|
|
32
|
+
pipeline: z.ZodOptional<z.ZodString>;
|
|
33
|
+
stage: z.ZodOptional<z.ZodString>;
|
|
34
|
+
value: z.ZodOptional<z.ZodNumber>;
|
|
35
|
+
expectedClose: z.ZodOptional<z.ZodString>;
|
|
36
|
+
}, z.core.$strip>, z.ZodObject<{
|
|
37
|
+
leadId: z.ZodString;
|
|
38
|
+
dealId: z.ZodString;
|
|
39
|
+
created: z.ZodBoolean;
|
|
40
|
+
open: z.ZodNullable<z.ZodObject<{
|
|
41
|
+
object: z.ZodString;
|
|
42
|
+
id: z.ZodString;
|
|
43
|
+
}, z.core.$strip>>;
|
|
44
|
+
}, z.core.$strip>>;
|
|
45
|
+
export declare const disqualify: import("@composable-os/sdk").ToolSpec<z.ZodObject<{
|
|
46
|
+
leadId: z.ZodString;
|
|
47
|
+
reason: z.ZodEnum<{
|
|
48
|
+
noBudget: "noBudget";
|
|
49
|
+
noNeed: "noNeed";
|
|
50
|
+
noAuthority: "noAuthority";
|
|
51
|
+
badTiming: "badTiming";
|
|
52
|
+
competitor: "competitor";
|
|
53
|
+
unresponsive: "unresponsive";
|
|
54
|
+
other: "other";
|
|
55
|
+
}>;
|
|
56
|
+
}, z.core.$strip>, z.ZodObject<{
|
|
57
|
+
leadId: z.ZodString;
|
|
58
|
+
status: z.ZodString;
|
|
59
|
+
reason: z.ZodString;
|
|
60
|
+
}, z.core.$strip>>;
|
package/dist/tools.js
ADDED
|
@@ -0,0 +1,203 @@
|
|
|
1
|
+
// The Leads tools. They become operations x.leads.<tool>, run in the sandbox, and reach the CRM
|
|
2
|
+
// only through ctx.ops. A tool's CRM calls are separate operations, not one transaction, so
|
|
3
|
+
// `convert` is written to be re-run: it finds the deal it made by the deal's `leads.lead` field
|
|
4
|
+
// and finishes the remaining steps, and it sets the lead to converted last.
|
|
5
|
+
import { defineTool, OpsCallError, z } from "@composable-os/sdk";
|
|
6
|
+
/** Why a lead is disqualified: the `unqualifiedReason` field's options. */
|
|
7
|
+
export const UNQUALIFIED_REASONS = [
|
|
8
|
+
{ value: "noBudget", label: "No budget" },
|
|
9
|
+
{ value: "noNeed", label: "No need" },
|
|
10
|
+
{ value: "noAuthority", label: "No authority" },
|
|
11
|
+
{ value: "badTiming", label: "Bad timing" },
|
|
12
|
+
{ value: "competitor", label: "Went with a competitor" },
|
|
13
|
+
{ value: "unresponsive", label: "Unresponsive" },
|
|
14
|
+
{ value: "other", label: "Other" },
|
|
15
|
+
];
|
|
16
|
+
/** The deal field Leads adds (`fields["deals.deal"].lead`), by its registry name. */
|
|
17
|
+
export const DEAL_LEAD_FIELD = "leads.lead";
|
|
18
|
+
/** The lifecycle extension's person field, when that extension is installed. */
|
|
19
|
+
export const LIFECYCLE_FIELD = "lifecycle.lifecycleStage";
|
|
20
|
+
/** Lifecycle stages conversion moves forward to opportunity (later ones are left alone). */
|
|
21
|
+
const BEFORE_OPPORTUNITY = new Set([
|
|
22
|
+
null,
|
|
23
|
+
"subscriber",
|
|
24
|
+
"lead",
|
|
25
|
+
"marketingQualified",
|
|
26
|
+
"salesQualified",
|
|
27
|
+
"other",
|
|
28
|
+
]);
|
|
29
|
+
const today = () => new Date().toISOString().slice(0, 10);
|
|
30
|
+
const text = (value) => (typeof value === "string" && value ? value : null);
|
|
31
|
+
export const convert = defineTool({
|
|
32
|
+
description: "Convert a lead into a deal: creates a deal for the lead's organisation, owned by the " +
|
|
33
|
+
"lead's owner and linked to the lead, in the given pipeline and stage (default: the " +
|
|
34
|
+
"default pipeline's first stage); adds the lead's person to the deal as a participant; " +
|
|
35
|
+
"and marks the lead converted with its deal and date. No data is copied: the deal points " +
|
|
36
|
+
"at the same person and organisation records. If the lifecycle extension is installed, the " +
|
|
37
|
+
"person's lifecycle stage moves to opportunity. Safe to run again after a failure (it " +
|
|
38
|
+
"finishes without a second deal); a converted lead cannot be converted again.",
|
|
39
|
+
risk: "write",
|
|
40
|
+
recordAction: {
|
|
41
|
+
object: "leads.lead",
|
|
42
|
+
label: "Convert to deal",
|
|
43
|
+
idInput: "leadId",
|
|
44
|
+
confirm: "Create a deal from this lead and mark it converted?",
|
|
45
|
+
hideWhen: { field: "status", values: ["converted"] },
|
|
46
|
+
},
|
|
47
|
+
input: z.object({
|
|
48
|
+
leadId: z.string().min(1).describe("The lead (leads.lead record id)"),
|
|
49
|
+
dealName: z.string().min(1).max(1000).optional().describe("Default: the lead's name"),
|
|
50
|
+
pipeline: z
|
|
51
|
+
.string()
|
|
52
|
+
.min(1)
|
|
53
|
+
.optional()
|
|
54
|
+
.describe("A deals.pipeline id. Default pipeline if left out"),
|
|
55
|
+
stage: z
|
|
56
|
+
.string()
|
|
57
|
+
.min(1)
|
|
58
|
+
.optional()
|
|
59
|
+
.describe("A deals.stage id. The pipeline's first stage if left out"),
|
|
60
|
+
value: z.number().min(0).optional().describe("The deal's value, in the base currency"),
|
|
61
|
+
expectedClose: z
|
|
62
|
+
.string()
|
|
63
|
+
.regex(/^\d{4}-\d{2}-\d{2}$/)
|
|
64
|
+
.optional()
|
|
65
|
+
.describe("Expected close date, YYYY-MM-DD"),
|
|
66
|
+
}),
|
|
67
|
+
output: z.object({
|
|
68
|
+
leadId: z.string(),
|
|
69
|
+
dealId: z.string(),
|
|
70
|
+
/** False when a re-run found the deal an earlier, interrupted run created. */
|
|
71
|
+
created: z.boolean(),
|
|
72
|
+
/** The record the app opens afterwards (the "open the new deal" setting), or null. */
|
|
73
|
+
open: z.object({ object: z.string(), id: z.string() }).nullable(),
|
|
74
|
+
}),
|
|
75
|
+
async handler(input, ctx) {
|
|
76
|
+
const lead = await ctx.ops.call("record.get", {
|
|
77
|
+
object: "leads.lead",
|
|
78
|
+
id: input.leadId,
|
|
79
|
+
});
|
|
80
|
+
if (lead.values.status === "converted") {
|
|
81
|
+
throw new OpsCallError("conflict", `${lead.title ?? "This lead"} is already converted`, {
|
|
82
|
+
leadId: lead.id,
|
|
83
|
+
dealId: lead.values.deal ?? null,
|
|
84
|
+
});
|
|
85
|
+
}
|
|
86
|
+
const personId = text(lead.values.person);
|
|
87
|
+
const organisationId = text(lead.values.organisation);
|
|
88
|
+
const ownerId = text(lead.values.owner);
|
|
89
|
+
// 1. The deal: the one an interrupted run made, or a new one.
|
|
90
|
+
const existing = await ctx.ops.call("record.list", {
|
|
91
|
+
object: "deals.deal",
|
|
92
|
+
filter: { field: DEAL_LEAD_FIELD, op: "eq", value: lead.id },
|
|
93
|
+
limit: 1,
|
|
94
|
+
});
|
|
95
|
+
let deal = existing.items[0];
|
|
96
|
+
const created = !deal;
|
|
97
|
+
if (!deal) {
|
|
98
|
+
deal = await ctx.ops.call("record.create", {
|
|
99
|
+
object: "deals.deal",
|
|
100
|
+
values: {
|
|
101
|
+
name: input.dealName ?? lead.title ?? "Deal",
|
|
102
|
+
[DEAL_LEAD_FIELD]: lead.id,
|
|
103
|
+
...(organisationId ? { organisation: organisationId } : {}),
|
|
104
|
+
...(ownerId ? { owner: ownerId } : {}),
|
|
105
|
+
...(input.pipeline ? { pipeline: input.pipeline } : {}),
|
|
106
|
+
...(input.stage ? { stage: input.stage } : {}),
|
|
107
|
+
...(input.value !== undefined ? { value: input.value } : {}),
|
|
108
|
+
...(input.expectedClose ? { expectedClose: input.expectedClose } : {}),
|
|
109
|
+
},
|
|
110
|
+
});
|
|
111
|
+
}
|
|
112
|
+
// 2. The lead's person on the deal.
|
|
113
|
+
if (personId) {
|
|
114
|
+
const on = await ctx.ops.call("record.list", {
|
|
115
|
+
object: "deals.participant",
|
|
116
|
+
filter: {
|
|
117
|
+
and: [
|
|
118
|
+
{ field: "deal", op: "eq", value: deal.id },
|
|
119
|
+
{ field: "person", op: "eq", value: personId },
|
|
120
|
+
],
|
|
121
|
+
},
|
|
122
|
+
limit: 1,
|
|
123
|
+
});
|
|
124
|
+
if (!on.items.length) {
|
|
125
|
+
await ctx.ops.call("record.create", {
|
|
126
|
+
object: "deals.participant",
|
|
127
|
+
values: { deal: deal.id, person: personId, role: "other" },
|
|
128
|
+
});
|
|
129
|
+
}
|
|
130
|
+
// 3. With the lifecycle extension installed, the person becomes an opportunity.
|
|
131
|
+
const person = await ctx.ops.call("record.get", {
|
|
132
|
+
object: "person",
|
|
133
|
+
id: personId,
|
|
134
|
+
});
|
|
135
|
+
const stage = person.values[LIFECYCLE_FIELD];
|
|
136
|
+
if (LIFECYCLE_FIELD in person.values && BEFORE_OPPORTUNITY.has(text(stage))) {
|
|
137
|
+
await ctx.ops.call("record.update", {
|
|
138
|
+
object: "person",
|
|
139
|
+
id: personId,
|
|
140
|
+
values: { [LIFECYCLE_FIELD]: "opportunity" },
|
|
141
|
+
});
|
|
142
|
+
}
|
|
143
|
+
}
|
|
144
|
+
// 4. Last: the lead is converted, so a run that stopped earlier can be run again.
|
|
145
|
+
await ctx.ops.call("record.update", {
|
|
146
|
+
object: "leads.lead",
|
|
147
|
+
id: lead.id,
|
|
148
|
+
values: { status: "converted", deal: deal.id, convertedAt: today() },
|
|
149
|
+
});
|
|
150
|
+
ctx.log.info("lead converted", { leadId: lead.id, dealId: deal.id, created });
|
|
151
|
+
const settings = await ctx.ops.call("extensionSettings.list", { extension: "leads" });
|
|
152
|
+
const openDeal = settings.items[0]?.values.openDealAfterConvert !== false;
|
|
153
|
+
return {
|
|
154
|
+
leadId: lead.id,
|
|
155
|
+
dealId: deal.id,
|
|
156
|
+
created,
|
|
157
|
+
open: openDeal ? { object: "deals.deal", id: deal.id } : null,
|
|
158
|
+
};
|
|
159
|
+
},
|
|
160
|
+
});
|
|
161
|
+
export const disqualify = defineTool({
|
|
162
|
+
description: "Disqualify a lead: sets its status to unqualified with the reason (no budget, no need, no " +
|
|
163
|
+
"authority, bad timing, competitor, unresponsive or other). A converted lead cannot be " +
|
|
164
|
+
"disqualified.",
|
|
165
|
+
risk: "write",
|
|
166
|
+
recordAction: {
|
|
167
|
+
object: "leads.lead",
|
|
168
|
+
label: "Disqualify",
|
|
169
|
+
idInput: "leadId",
|
|
170
|
+
ask: { input: "reason", label: "Reason", options: UNQUALIFIED_REASONS },
|
|
171
|
+
hideWhen: { field: "status", values: ["converted", "unqualified"] },
|
|
172
|
+
},
|
|
173
|
+
input: z.object({
|
|
174
|
+
leadId: z.string().min(1).describe("The lead (leads.lead record id)"),
|
|
175
|
+
reason: z.enum([
|
|
176
|
+
"noBudget",
|
|
177
|
+
"noNeed",
|
|
178
|
+
"noAuthority",
|
|
179
|
+
"badTiming",
|
|
180
|
+
"competitor",
|
|
181
|
+
"unresponsive",
|
|
182
|
+
"other",
|
|
183
|
+
]),
|
|
184
|
+
}),
|
|
185
|
+
output: z.object({ leadId: z.string(), status: z.string(), reason: z.string() }),
|
|
186
|
+
async handler(input, ctx) {
|
|
187
|
+
const lead = await ctx.ops.call("record.get", {
|
|
188
|
+
object: "leads.lead",
|
|
189
|
+
id: input.leadId,
|
|
190
|
+
});
|
|
191
|
+
if (lead.values.status === "converted") {
|
|
192
|
+
throw new OpsCallError("conflict", `${lead.title ?? "This lead"} is already converted`, {
|
|
193
|
+
leadId: lead.id,
|
|
194
|
+
});
|
|
195
|
+
}
|
|
196
|
+
await ctx.ops.call("record.update", {
|
|
197
|
+
object: "leads.lead",
|
|
198
|
+
id: lead.id,
|
|
199
|
+
values: { status: "unqualified", unqualifiedReason: input.reason },
|
|
200
|
+
});
|
|
201
|
+
return { leadId: lead.id, status: "unqualified", reason: input.reason };
|
|
202
|
+
},
|
|
203
|
+
});
|
package/package.json
CHANGED
|
@@ -1,6 +1,32 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@composable-os/pack-leads",
|
|
3
|
-
"version": "0.
|
|
4
|
-
"
|
|
5
|
-
"
|
|
6
|
-
|
|
3
|
+
"version": "0.1.0-beta.7",
|
|
4
|
+
"license": "FSL-1.1-ALv2",
|
|
5
|
+
"type": "module",
|
|
6
|
+
"repository": {
|
|
7
|
+
"type": "git",
|
|
8
|
+
"url": "git+https://github.com/timoconnellaus/composable-os.git"
|
|
9
|
+
},
|
|
10
|
+
"homepage": "https://composableos.dev",
|
|
11
|
+
"publishConfig": {
|
|
12
|
+
"access": "public",
|
|
13
|
+
"provenance": true
|
|
14
|
+
},
|
|
15
|
+
"description": "Leads: inbound interest linked to a person and an organisation, worked from an inbox and converted into deals (stage 15, ADR 0246). Requires Deals. Bundled as source into cos-runner.",
|
|
16
|
+
"exports": {
|
|
17
|
+
".": {
|
|
18
|
+
"types": "./dist/index.d.ts",
|
|
19
|
+
"default": "./dist/index.js"
|
|
20
|
+
}
|
|
21
|
+
},
|
|
22
|
+
"files": [
|
|
23
|
+
"dist"
|
|
24
|
+
],
|
|
25
|
+
"composableOs": {
|
|
26
|
+
"label": "Leads",
|
|
27
|
+
"description": "Inbound interest worked from a leads inbox, qualified or disqualified, and converted into deals. Requires Deals."
|
|
28
|
+
},
|
|
29
|
+
"dependencies": {
|
|
30
|
+
"@composable-os/sdk": "0.1.0-beta.7"
|
|
31
|
+
}
|
|
32
|
+
}
|
package/README.md
DELETED