@composable-os/pack-deals 0.0.0-stage → 0.1.0-beta.10
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 +49 -0
- package/dist/automations.js +173 -0
- package/dist/client/index.d.ts +87 -0
- package/dist/client/index.js +25 -0
- package/dist/dashboards.d.ts +3 -0
- package/dist/dashboards.js +318 -0
- package/dist/index.d.ts +643 -0
- package/dist/index.js +388 -0
- package/dist/tools.d.ts +21 -0
- package/dist/tools.js +90 -0
- package/package.json +30 -4
- package/README.md +0 -3
|
@@ -0,0 +1,318 @@
|
|
|
1
|
+
const OWNER = "(:owner IS NULL OR d.owner = :owner)";
|
|
2
|
+
const CLOSED_IN_RANGE = "d.closed_at >= :date_from AND d.closed_at < :date_to";
|
|
3
|
+
const ownerFilter = { field: "owner", op: "eq", value: { $param: "owner" } };
|
|
4
|
+
const closedInRange = (status) => ({
|
|
5
|
+
and: [
|
|
6
|
+
{ field: "status", op: "eq", value: status },
|
|
7
|
+
{ field: "closedAt", op: "gte", value: { $param: "date_from" } },
|
|
8
|
+
{ field: "closedAt", op: "lt", value: { $param: "date_to" } },
|
|
9
|
+
ownerFilter,
|
|
10
|
+
],
|
|
11
|
+
});
|
|
12
|
+
const FILTERS = [
|
|
13
|
+
{ type: "dateRange", id: "date", label: "Closed", default: "this_quarter" },
|
|
14
|
+
{ type: "user", id: "owner", label: "Owner", default: "anyone" },
|
|
15
|
+
];
|
|
16
|
+
export const salesOverview = {
|
|
17
|
+
title: "Sales overview",
|
|
18
|
+
description: "Open pipeline, forecast, wins and win rate across your deals.",
|
|
19
|
+
home: true,
|
|
20
|
+
filters: FILTERS,
|
|
21
|
+
widgets: [
|
|
22
|
+
{
|
|
23
|
+
id: "won",
|
|
24
|
+
type: "kpi",
|
|
25
|
+
title: "Won",
|
|
26
|
+
description: "Value of deals won in the period, against the previous period.",
|
|
27
|
+
sql: `SELECT coalesce(sum(d.value), 0) AS value, count(*) AS deals FROM rec_x_deals_deal d WHERE d.status = 'won' AND ${CLOSED_IN_RANGE} AND ${OWNER}`,
|
|
28
|
+
mapping: { value: "value" },
|
|
29
|
+
options: { format: "currency", compare: true },
|
|
30
|
+
clickThrough: { object: "deals.deal", filter: closedInRange("won") },
|
|
31
|
+
layout: { w: 3, h: 1 },
|
|
32
|
+
},
|
|
33
|
+
{
|
|
34
|
+
id: "win-rate",
|
|
35
|
+
type: "kpi",
|
|
36
|
+
title: "Win rate",
|
|
37
|
+
description: "Deals won out of deals closed (won or lost) in the period.",
|
|
38
|
+
sql: `SELECT CASE WHEN count(*) = 0 THEN NULL ELSE round(100.0 * sum(d.status = 'won') / count(*), 1) END AS value, count(*) AS deals FROM rec_x_deals_deal d WHERE d.status IN ('won', 'lost') AND ${CLOSED_IN_RANGE} AND ${OWNER}`,
|
|
39
|
+
mapping: { value: "value" },
|
|
40
|
+
options: { format: "percent", compare: true },
|
|
41
|
+
clickThrough: {
|
|
42
|
+
object: "deals.deal",
|
|
43
|
+
filter: {
|
|
44
|
+
and: [
|
|
45
|
+
{ field: "status", op: "in", value: ["won", "lost"] },
|
|
46
|
+
{ field: "closedAt", op: "gte", value: { $param: "date_from" } },
|
|
47
|
+
{ field: "closedAt", op: "lt", value: { $param: "date_to" } },
|
|
48
|
+
ownerFilter,
|
|
49
|
+
],
|
|
50
|
+
},
|
|
51
|
+
},
|
|
52
|
+
layout: { w: 3, h: 1 },
|
|
53
|
+
},
|
|
54
|
+
{
|
|
55
|
+
id: "average-deal",
|
|
56
|
+
type: "kpi",
|
|
57
|
+
title: "Average deal size",
|
|
58
|
+
description: "Average value of deals won in the period.",
|
|
59
|
+
sql: `SELECT round(avg(d.value), 2) AS value, count(*) AS deals FROM rec_x_deals_deal d WHERE d.status = 'won' AND ${CLOSED_IN_RANGE} AND ${OWNER}`,
|
|
60
|
+
mapping: { value: "value" },
|
|
61
|
+
options: { format: "currency", compare: true },
|
|
62
|
+
clickThrough: { object: "deals.deal", filter: closedInRange("won") },
|
|
63
|
+
layout: { w: 3, h: 1 },
|
|
64
|
+
},
|
|
65
|
+
{
|
|
66
|
+
id: "open-pipeline",
|
|
67
|
+
type: "kpi",
|
|
68
|
+
title: "Open pipeline",
|
|
69
|
+
description: "Value of all open deals (not limited to the period).",
|
|
70
|
+
sql: `SELECT coalesce(sum(d.value), 0) AS value, count(*) AS deals FROM rec_x_deals_deal d WHERE d.status = 'open' AND ${OWNER}`,
|
|
71
|
+
mapping: { value: "value" },
|
|
72
|
+
options: { format: "currency", compare: false },
|
|
73
|
+
clickThrough: {
|
|
74
|
+
object: "deals.deal",
|
|
75
|
+
filter: { and: [{ field: "status", op: "eq", value: "open" }, ownerFilter] },
|
|
76
|
+
},
|
|
77
|
+
layout: { w: 3, h: 1 },
|
|
78
|
+
},
|
|
79
|
+
{
|
|
80
|
+
id: "pipeline-by-stage",
|
|
81
|
+
type: "bar",
|
|
82
|
+
title: "Open pipeline by stage",
|
|
83
|
+
sql: [
|
|
84
|
+
"SELECT s.id AS stage_id, p.name || ': ' || s.name AS label, count(*) AS deals,",
|
|
85
|
+
" coalesce(sum(d.value), 0) AS value",
|
|
86
|
+
"FROM rec_x_deals_deal d",
|
|
87
|
+
"JOIN rec_x_deals_stage s ON s.id = d.stage",
|
|
88
|
+
"JOIN rec_x_deals_pipeline p ON p.id = s.pipeline",
|
|
89
|
+
`WHERE d.status = 'open' AND ${OWNER}`,
|
|
90
|
+
"GROUP BY s.id, p.name, s.name, p.position, s.position",
|
|
91
|
+
"ORDER BY p.position, p.name, s.position",
|
|
92
|
+
].join("\n"),
|
|
93
|
+
mapping: { x: "label", y: "value" },
|
|
94
|
+
options: { orientation: "horizontal", format: "currency" },
|
|
95
|
+
clickThrough: {
|
|
96
|
+
object: "deals.deal",
|
|
97
|
+
filter: {
|
|
98
|
+
and: [
|
|
99
|
+
{ field: "status", op: "eq", value: "open" },
|
|
100
|
+
{ field: "stage", op: "eq", value: { $row: "stage_id" } },
|
|
101
|
+
ownerFilter,
|
|
102
|
+
],
|
|
103
|
+
},
|
|
104
|
+
},
|
|
105
|
+
layout: { w: 6, h: 3 },
|
|
106
|
+
},
|
|
107
|
+
{
|
|
108
|
+
id: "weighted-forecast",
|
|
109
|
+
type: "bar",
|
|
110
|
+
title: "Weighted forecast by close month",
|
|
111
|
+
description: "Open deals by expected close month: value × probability.",
|
|
112
|
+
sql: [
|
|
113
|
+
"SELECT month, round(sum(weighted), 2) AS weighted, count(*) AS deals,",
|
|
114
|
+
" month || '-01' AS month_start, date(month || '-01', '+1 month') AS month_end",
|
|
115
|
+
"FROM (",
|
|
116
|
+
" SELECT substr(d.expected_close, 1, 7) AS month,",
|
|
117
|
+
" coalesce(d.value, 0) * coalesce(d.probability, 0) / 100.0 AS weighted",
|
|
118
|
+
" FROM rec_x_deals_deal d",
|
|
119
|
+
` WHERE d.status = 'open' AND d.expected_close >= '0000-01-01' AND ${OWNER}`,
|
|
120
|
+
")",
|
|
121
|
+
"GROUP BY month ORDER BY month",
|
|
122
|
+
].join("\n"),
|
|
123
|
+
mapping: { x: "month", y: "weighted" },
|
|
124
|
+
options: { format: "currency" },
|
|
125
|
+
clickThrough: {
|
|
126
|
+
object: "deals.deal",
|
|
127
|
+
filter: {
|
|
128
|
+
and: [
|
|
129
|
+
{ field: "status", op: "eq", value: "open" },
|
|
130
|
+
{ field: "expectedClose", op: "gte", value: { $row: "month_start" } },
|
|
131
|
+
{ field: "expectedClose", op: "lt", value: { $row: "month_end" } },
|
|
132
|
+
ownerFilter,
|
|
133
|
+
],
|
|
134
|
+
},
|
|
135
|
+
},
|
|
136
|
+
layout: { w: 6, h: 3 },
|
|
137
|
+
},
|
|
138
|
+
{
|
|
139
|
+
id: "deals-by-owner",
|
|
140
|
+
type: "leaderboard",
|
|
141
|
+
title: "Open pipeline by owner",
|
|
142
|
+
sql: [
|
|
143
|
+
"SELECT d.owner AS owner_id, u.name AS label, coalesce(sum(d.value), 0) AS value,",
|
|
144
|
+
" count(*) AS deals",
|
|
145
|
+
"FROM rec_x_deals_deal d JOIN rec_user u ON u.id = d.owner",
|
|
146
|
+
`WHERE d.status = 'open' AND ${OWNER}`,
|
|
147
|
+
"GROUP BY d.owner, u.name ORDER BY value DESC, label",
|
|
148
|
+
].join("\n"),
|
|
149
|
+
mapping: { label: "label", value: "value" },
|
|
150
|
+
options: { format: "currency", limit: 10 },
|
|
151
|
+
clickThrough: {
|
|
152
|
+
object: "deals.deal",
|
|
153
|
+
filter: {
|
|
154
|
+
and: [
|
|
155
|
+
{ field: "status", op: "eq", value: "open" },
|
|
156
|
+
{ field: "owner", op: "eq", value: { $row: "owner_id" } },
|
|
157
|
+
],
|
|
158
|
+
},
|
|
159
|
+
},
|
|
160
|
+
layout: { w: 6, h: 3 },
|
|
161
|
+
},
|
|
162
|
+
{
|
|
163
|
+
id: "won-by-month",
|
|
164
|
+
type: "bar",
|
|
165
|
+
title: "Won by month",
|
|
166
|
+
sql: [
|
|
167
|
+
"SELECT month, coalesce(sum(value), 0) AS value, count(*) AS deals,",
|
|
168
|
+
" month || '-01T00:00:00.000Z' AS month_start,",
|
|
169
|
+
" strftime('%Y-%m-%dT%H:%M:%fZ', month || '-01', '+1 month') AS month_end",
|
|
170
|
+
"FROM (",
|
|
171
|
+
" SELECT substr(d.closed_at, 1, 7) AS month, d.value AS value",
|
|
172
|
+
" FROM rec_x_deals_deal d",
|
|
173
|
+
` WHERE d.status = 'won' AND ${CLOSED_IN_RANGE} AND ${OWNER}`,
|
|
174
|
+
")",
|
|
175
|
+
"GROUP BY month ORDER BY month",
|
|
176
|
+
].join("\n"),
|
|
177
|
+
mapping: { x: "month", y: "value" },
|
|
178
|
+
options: { format: "currency" },
|
|
179
|
+
clickThrough: {
|
|
180
|
+
object: "deals.deal",
|
|
181
|
+
filter: {
|
|
182
|
+
and: [
|
|
183
|
+
...closedInRange("won").and,
|
|
184
|
+
{ field: "closedAt", op: "gte", value: { $row: "month_start" } },
|
|
185
|
+
{ field: "closedAt", op: "lt", value: { $row: "month_end" } },
|
|
186
|
+
],
|
|
187
|
+
},
|
|
188
|
+
},
|
|
189
|
+
layout: { w: 6, h: 3 },
|
|
190
|
+
},
|
|
191
|
+
],
|
|
192
|
+
};
|
|
193
|
+
export const pipelineHealth = {
|
|
194
|
+
title: "Pipeline health",
|
|
195
|
+
description: "Stalled deals, slipped close dates and how long deals sit in each stage.",
|
|
196
|
+
filters: [FILTERS[1]],
|
|
197
|
+
widgets: [
|
|
198
|
+
{
|
|
199
|
+
id: "slipped",
|
|
200
|
+
type: "kpi",
|
|
201
|
+
title: "Slipped close dates",
|
|
202
|
+
description: "Open deals whose expected close date has passed.",
|
|
203
|
+
sql: `SELECT count(*) AS value, count(*) AS deals FROM rec_x_deals_deal d WHERE d.status = 'open' AND d.expected_close < :today AND ${OWNER}`,
|
|
204
|
+
mapping: { value: "value" },
|
|
205
|
+
options: { compare: false },
|
|
206
|
+
clickThrough: {
|
|
207
|
+
object: "deals.deal",
|
|
208
|
+
filter: {
|
|
209
|
+
and: [
|
|
210
|
+
{ field: "status", op: "eq", value: "open" },
|
|
211
|
+
{ field: "expectedClose", op: "lt", value: { $param: "today" } },
|
|
212
|
+
ownerFilter,
|
|
213
|
+
],
|
|
214
|
+
},
|
|
215
|
+
},
|
|
216
|
+
layout: { w: 6, h: 1 },
|
|
217
|
+
},
|
|
218
|
+
{
|
|
219
|
+
id: "slipped-value",
|
|
220
|
+
type: "kpi",
|
|
221
|
+
title: "Value at risk",
|
|
222
|
+
description: "Value of open deals whose expected close date has passed.",
|
|
223
|
+
sql: `SELECT coalesce(sum(d.value), 0) AS value, count(*) AS deals FROM rec_x_deals_deal d WHERE d.status = 'open' AND d.expected_close < :today AND ${OWNER}`,
|
|
224
|
+
mapping: { value: "value" },
|
|
225
|
+
options: { format: "currency", compare: false },
|
|
226
|
+
clickThrough: {
|
|
227
|
+
object: "deals.deal",
|
|
228
|
+
filter: {
|
|
229
|
+
and: [
|
|
230
|
+
{ field: "status", op: "eq", value: "open" },
|
|
231
|
+
{ field: "expectedClose", op: "lt", value: { $param: "today" } },
|
|
232
|
+
ownerFilter,
|
|
233
|
+
],
|
|
234
|
+
},
|
|
235
|
+
},
|
|
236
|
+
layout: { w: 6, h: 1 },
|
|
237
|
+
},
|
|
238
|
+
{
|
|
239
|
+
id: "time-in-stage",
|
|
240
|
+
type: "bar",
|
|
241
|
+
title: "Days in current stage (open deals)",
|
|
242
|
+
sql: [
|
|
243
|
+
"SELECT s.id AS stage_id, p.name || ': ' || s.name AS label,",
|
|
244
|
+
" round(avg(h.days_in_stage), 1) AS days, count(*) AS deals",
|
|
245
|
+
"FROM rec_stage_history h",
|
|
246
|
+
"JOIN rec_x_deals_deal d ON d.id = h.record_id AND d.stage = h.stage_id",
|
|
247
|
+
"JOIN rec_x_deals_stage s ON s.id = h.stage_id",
|
|
248
|
+
"JOIN rec_x_deals_pipeline p ON p.id = s.pipeline",
|
|
249
|
+
`WHERE h.object_type = 'deals.deal' AND h.left_at IS NULL AND d.status = 'open' AND ${OWNER}`,
|
|
250
|
+
"GROUP BY s.id, p.name, s.name, p.position, s.position",
|
|
251
|
+
"ORDER BY p.position, p.name, s.position",
|
|
252
|
+
].join("\n"),
|
|
253
|
+
mapping: { x: "label", y: "days" },
|
|
254
|
+
options: { orientation: "horizontal" },
|
|
255
|
+
clickThrough: {
|
|
256
|
+
object: "deals.deal",
|
|
257
|
+
filter: {
|
|
258
|
+
and: [
|
|
259
|
+
{ field: "status", op: "eq", value: "open" },
|
|
260
|
+
{ field: "stage", op: "eq", value: { $row: "stage_id" } },
|
|
261
|
+
ownerFilter,
|
|
262
|
+
],
|
|
263
|
+
},
|
|
264
|
+
},
|
|
265
|
+
layout: { w: 6, h: 3 },
|
|
266
|
+
},
|
|
267
|
+
{
|
|
268
|
+
id: "stalled",
|
|
269
|
+
type: "table",
|
|
270
|
+
title: "Stalled deals",
|
|
271
|
+
description: "Open deals with no activity in 14 days, the longest quiet first.",
|
|
272
|
+
sql: [
|
|
273
|
+
"SELECT d.id AS id, d.name AS deal, s.name AS stage, d.value AS value,",
|
|
274
|
+
" d.expected_close AS expected_close, u.name AS owner",
|
|
275
|
+
"FROM rec_x_deals_deal d",
|
|
276
|
+
"JOIN rec_x_deals_stage s ON s.id = d.stage",
|
|
277
|
+
"LEFT JOIN rec_user u ON u.id = d.owner",
|
|
278
|
+
`WHERE d.status = 'open' AND ${OWNER}`,
|
|
279
|
+
" AND d.created_at < strftime('%Y-%m-%dT%H:%M:%fZ', :now, '-14 days')",
|
|
280
|
+
" AND NOT EXISTS (",
|
|
281
|
+
" SELECT 1 FROM rec_activity_link l JOIN rec_activity a ON a.id = l.activity_id",
|
|
282
|
+
" WHERE l.object_type = 'deals.deal' AND l.record_id = d.id",
|
|
283
|
+
" AND a.occurred_at >= strftime('%Y-%m-%dT%H:%M:%fZ', :now, '-14 days'))",
|
|
284
|
+
" AND NOT EXISTS (",
|
|
285
|
+
" SELECT 1 FROM rec_stage_history h",
|
|
286
|
+
" WHERE h.object_type = 'deals.deal' AND h.record_id = d.id",
|
|
287
|
+
" AND h.entered_at >= strftime('%Y-%m-%dT%H:%M:%fZ', :now, '-14 days'))",
|
|
288
|
+
"ORDER BY d.updated_at, d.id",
|
|
289
|
+
].join("\n"),
|
|
290
|
+
mapping: { columns: ["deal", "stage", "value", "expected_close", "owner"] },
|
|
291
|
+
options: { limit: 20 },
|
|
292
|
+
clickThrough: {
|
|
293
|
+
object: "deals.deal",
|
|
294
|
+
filter: { field: "id", op: "eq", value: { $row: "id" } },
|
|
295
|
+
},
|
|
296
|
+
layout: { w: 6, h: 3 },
|
|
297
|
+
},
|
|
298
|
+
{
|
|
299
|
+
id: "slipped-list",
|
|
300
|
+
type: "table",
|
|
301
|
+
title: "Slipped close dates",
|
|
302
|
+
sql: [
|
|
303
|
+
"SELECT d.id AS id, d.name AS deal, d.expected_close AS expected_close, d.value AS value,",
|
|
304
|
+
" u.name AS owner",
|
|
305
|
+
"FROM rec_x_deals_deal d LEFT JOIN rec_user u ON u.id = d.owner",
|
|
306
|
+
`WHERE d.status = 'open' AND d.expected_close < :today AND ${OWNER}`,
|
|
307
|
+
"ORDER BY d.expected_close, d.id",
|
|
308
|
+
].join("\n"),
|
|
309
|
+
mapping: { columns: ["deal", "expected_close", "value", "owner"] },
|
|
310
|
+
options: { limit: 20 },
|
|
311
|
+
clickThrough: {
|
|
312
|
+
object: "deals.deal",
|
|
313
|
+
filter: { field: "id", op: "eq", value: { $row: "id" } },
|
|
314
|
+
},
|
|
315
|
+
layout: { w: 6, h: 3 },
|
|
316
|
+
},
|
|
317
|
+
],
|
|
318
|
+
};
|