@talkpilot/core-db 1.2.2 → 1.3.1
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/.cursor/rules/development.mdc +65 -65
- package/DEVELOPMENT.md +98 -98
- package/README.md +139 -139
- package/README_OLD.md +160 -160
- package/dist/talkpilot/calls/calls.types.d.ts +2 -1
- package/dist/talkpilot/calls/calls.types.d.ts.map +1 -1
- package/dist/talkpilot/calls/calls.types.js.map +1 -1
- package/dist/talkpilot/calls/dashboard/calls.dashboard.d.ts +1 -33
- package/dist/talkpilot/calls/dashboard/calls.dashboard.d.ts.map +1 -1
- package/dist/talkpilot/calls/dashboard/calls.dashboard.js +146 -131
- package/dist/talkpilot/calls/dashboard/calls.dashboard.js.map +1 -1
- package/dist/talkpilot/calls/dashboard/calls.dashboard.types.d.ts +6 -27
- package/dist/talkpilot/calls/dashboard/calls.dashboard.types.d.ts.map +1 -1
- package/jest.config.js +19 -19
- package/package.json +46 -46
- package/src/talkpilot/calls/__tests__/calls.dashboard.spec.ts +111 -8
- package/src/talkpilot/calls/calls.types.ts +2 -1
- package/src/talkpilot/calls/dashboard/calls.dashboard.ts +197 -148
- package/src/talkpilot/calls/dashboard/calls.dashboard.types.ts +12 -25
- package/src/talkpilot/clientsConfig/__tests__/clientsConfig.spec.ts +0 -7
- package/tsconfig.json +23 -23
- package/dist/talkpilot/calls/calls.dashboard.d.ts +0 -3
- package/dist/talkpilot/calls/calls.dashboard.d.ts.map +0 -1
- package/dist/talkpilot/calls/calls.dashboard.js +0 -191
- package/dist/talkpilot/calls/calls.dashboard.js.map +0 -1
|
@@ -3,58 +3,168 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
3
3
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
4
|
};
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
exports.buildCallLengthBucketsPipeline = buildCallLengthBucketsPipeline;
|
|
7
6
|
exports.getDashboardStats = getDashboardStats;
|
|
8
7
|
const dayjs_1 = __importDefault(require("dayjs"));
|
|
9
8
|
const calls_getters_1 = require("../calls.getters");
|
|
10
9
|
const clientsConfig_1 = require("../../clientsConfig");
|
|
11
10
|
const utc_1 = __importDefault(require("dayjs/plugin/utc"));
|
|
12
11
|
const timezone_1 = __importDefault(require("dayjs/plugin/timezone"));
|
|
12
|
+
const isoWeek_1 = __importDefault(require("dayjs/plugin/isoWeek"));
|
|
13
|
+
const quarterOfYear_1 = __importDefault(require("dayjs/plugin/quarterOfYear"));
|
|
13
14
|
const DEFAULT_KPI_DATA = {
|
|
14
|
-
totalCalls: 0,
|
|
15
|
-
totalDuration: 0,
|
|
16
15
|
completedCount: 0,
|
|
17
|
-
failedCount: 0,
|
|
18
|
-
noAnswerCount: 0,
|
|
19
16
|
busyCount: 0,
|
|
17
|
+
answeredDuration: 0,
|
|
20
18
|
};
|
|
21
19
|
dayjs_1.default.extend(utc_1.default);
|
|
22
20
|
dayjs_1.default.extend(timezone_1.default);
|
|
21
|
+
dayjs_1.default.extend(isoWeek_1.default);
|
|
22
|
+
dayjs_1.default.extend(quarterOfYear_1.default);
|
|
23
|
+
const BUCKET_UNIT = {
|
|
24
|
+
hour: "hour",
|
|
25
|
+
day: "day",
|
|
26
|
+
week: "isoWeek",
|
|
27
|
+
month: "month",
|
|
28
|
+
quarter: "quarter",
|
|
29
|
+
year: "year",
|
|
30
|
+
};
|
|
31
|
+
function formatBucketKey(bucketStart, granularity) {
|
|
32
|
+
switch (granularity) {
|
|
33
|
+
case "hour":
|
|
34
|
+
return bucketStart.format("YYYY-MM-DDTHH:00");
|
|
35
|
+
case "day":
|
|
36
|
+
case "week":
|
|
37
|
+
return bucketStart.format("YYYY-MM-DD");
|
|
38
|
+
case "month":
|
|
39
|
+
return bucketStart.format("YYYY-MM");
|
|
40
|
+
case "quarter":
|
|
41
|
+
return `${bucketStart.format("YYYY")}-Q${bucketStart.quarter()}`;
|
|
42
|
+
case "year":
|
|
43
|
+
return bucketStart.format("YYYY");
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
function generateBucketKeys(startDateObj, endDateObj, granularity, timezone) {
|
|
47
|
+
const unitName = BUCKET_UNIT[granularity];
|
|
48
|
+
const startOfUnit = unitName;
|
|
49
|
+
const stepUnit = (unitName === "isoWeek" ? "week" : unitName);
|
|
50
|
+
const end = (0, dayjs_1.default)(endDateObj).tz(timezone);
|
|
51
|
+
let cursor = (0, dayjs_1.default)(startDateObj).tz(timezone).startOf(startOfUnit);
|
|
52
|
+
const keys = [];
|
|
53
|
+
while (cursor.isBefore(end) || cursor.isSame(end, startOfUnit)) {
|
|
54
|
+
keys.push(formatBucketKey(cursor, granularity));
|
|
55
|
+
cursor = cursor.add(1, stepUnit);
|
|
56
|
+
}
|
|
57
|
+
return keys;
|
|
58
|
+
}
|
|
59
|
+
function fillVolumeGaps(bucketKeys, volumeDataRaw) {
|
|
60
|
+
const completedByKey = new Map(volumeDataRaw.map((d) => [d.date, d.completed]));
|
|
61
|
+
return bucketKeys.map((date) => ({
|
|
62
|
+
date,
|
|
63
|
+
completed: completedByKey.get(date) ?? 0,
|
|
64
|
+
}));
|
|
65
|
+
}
|
|
66
|
+
function resolveVolumeGranularity(startDateObj, endDateObj) {
|
|
67
|
+
const spanDays = (0, dayjs_1.default)(endDateObj).diff((0, dayjs_1.default)(startDateObj), "day");
|
|
68
|
+
if (spanDays <= 2)
|
|
69
|
+
return "hour";
|
|
70
|
+
if (spanDays <= 60)
|
|
71
|
+
return "day";
|
|
72
|
+
if (spanDays <= 365)
|
|
73
|
+
return "week";
|
|
74
|
+
if (spanDays <= 730)
|
|
75
|
+
return "month";
|
|
76
|
+
if (spanDays <= 1460)
|
|
77
|
+
return "quarter";
|
|
78
|
+
return "year";
|
|
79
|
+
}
|
|
80
|
+
const VOLUME_DATE_FORMATS = {
|
|
81
|
+
hour: "%Y-%m-%dT%H:00",
|
|
82
|
+
day: "%Y-%m-%d",
|
|
83
|
+
month: "%Y-%m",
|
|
84
|
+
year: "%Y",
|
|
85
|
+
};
|
|
86
|
+
function buildVolumeBucketIdExpression(timezone, granularity) {
|
|
87
|
+
if (granularity === "week") {
|
|
88
|
+
return {
|
|
89
|
+
$dateToString: {
|
|
90
|
+
format: "%Y-%m-%d",
|
|
91
|
+
date: {
|
|
92
|
+
$dateTrunc: {
|
|
93
|
+
date: "$createdAt",
|
|
94
|
+
unit: "week",
|
|
95
|
+
timezone,
|
|
96
|
+
startOfWeek: "monday",
|
|
97
|
+
},
|
|
98
|
+
},
|
|
99
|
+
timezone,
|
|
100
|
+
},
|
|
101
|
+
};
|
|
102
|
+
}
|
|
103
|
+
if (granularity === "quarter") {
|
|
104
|
+
return {
|
|
105
|
+
$concat: [
|
|
106
|
+
{ $toString: { $year: { date: "$createdAt", timezone } } },
|
|
107
|
+
"-Q",
|
|
108
|
+
{
|
|
109
|
+
$toString: {
|
|
110
|
+
$add: [
|
|
111
|
+
{
|
|
112
|
+
$trunc: {
|
|
113
|
+
$divide: [
|
|
114
|
+
{
|
|
115
|
+
$subtract: [
|
|
116
|
+
{ $month: { date: "$createdAt", timezone } },
|
|
117
|
+
1,
|
|
118
|
+
],
|
|
119
|
+
},
|
|
120
|
+
3,
|
|
121
|
+
],
|
|
122
|
+
},
|
|
123
|
+
},
|
|
124
|
+
1,
|
|
125
|
+
],
|
|
126
|
+
},
|
|
127
|
+
},
|
|
128
|
+
],
|
|
129
|
+
};
|
|
130
|
+
}
|
|
131
|
+
return {
|
|
132
|
+
$dateToString: {
|
|
133
|
+
format: VOLUME_DATE_FORMATS[granularity],
|
|
134
|
+
date: "$createdAt",
|
|
135
|
+
timezone,
|
|
136
|
+
},
|
|
137
|
+
};
|
|
138
|
+
}
|
|
23
139
|
function buildKpisPipeline() {
|
|
24
140
|
return [
|
|
25
141
|
{
|
|
26
142
|
$group: {
|
|
27
143
|
_id: null,
|
|
28
|
-
totalCalls: { $sum: 1 },
|
|
29
|
-
totalDuration: { $sum: "$callLength" },
|
|
30
144
|
completedCount: {
|
|
31
145
|
$sum: { $cond: [{ $eq: ["$status", "completed"] }, 1, 0] },
|
|
32
146
|
},
|
|
33
|
-
failedCount: {
|
|
34
|
-
$sum: { $cond: [{ $eq: ["$status", "failed"] }, 1, 0] },
|
|
35
|
-
},
|
|
36
|
-
noAnswerCount: {
|
|
37
|
-
$sum: { $cond: [{ $eq: ["$status", "no-answer"] }, 1, 0] },
|
|
38
|
-
},
|
|
39
147
|
busyCount: {
|
|
40
148
|
$sum: { $cond: [{ $eq: ["$status", "busy"] }, 1, 0] },
|
|
41
149
|
},
|
|
150
|
+
answeredDuration: {
|
|
151
|
+
$sum: {
|
|
152
|
+
$cond: [
|
|
153
|
+
{ $in: ["$status", ["completed", "busy"]] },
|
|
154
|
+
"$callLength",
|
|
155
|
+
0,
|
|
156
|
+
],
|
|
157
|
+
},
|
|
158
|
+
},
|
|
42
159
|
},
|
|
43
160
|
},
|
|
44
161
|
];
|
|
45
162
|
}
|
|
46
|
-
function
|
|
163
|
+
function buildVolumeDataPipeline(timezone, granularity) {
|
|
47
164
|
return [
|
|
48
165
|
{
|
|
49
166
|
$group: {
|
|
50
|
-
_id:
|
|
51
|
-
$dateToString: {
|
|
52
|
-
format: "%Y-%m-%d",
|
|
53
|
-
date: "$createdAt",
|
|
54
|
-
timezone: timezone,
|
|
55
|
-
},
|
|
56
|
-
},
|
|
57
|
-
count: { $sum: 1 },
|
|
167
|
+
_id: buildVolumeBucketIdExpression(timezone, granularity),
|
|
58
168
|
completed: {
|
|
59
169
|
$sum: { $cond: [{ $eq: ["$status", "completed"] }, 1, 0] },
|
|
60
170
|
},
|
|
@@ -63,86 +173,13 @@ function buildDailyDataPipeline(timezone) {
|
|
|
63
173
|
{ $sort: { _id: 1 } },
|
|
64
174
|
];
|
|
65
175
|
}
|
|
66
|
-
function buildHourlyDataPipeline(timezone) {
|
|
67
|
-
return [
|
|
68
|
-
{
|
|
69
|
-
$group: {
|
|
70
|
-
_id: {
|
|
71
|
-
day: {
|
|
72
|
-
$dateToString: {
|
|
73
|
-
format: "%Y-%m-%d",
|
|
74
|
-
date: "$createdAt",
|
|
75
|
-
timezone: timezone,
|
|
76
|
-
},
|
|
77
|
-
},
|
|
78
|
-
hour: { $hour: { date: "$createdAt", timezone: timezone } },
|
|
79
|
-
},
|
|
80
|
-
count: { $sum: 1 },
|
|
81
|
-
},
|
|
82
|
-
},
|
|
83
|
-
];
|
|
84
|
-
}
|
|
85
|
-
function buildCallLengthBucketsPipeline(thresholds) {
|
|
86
|
-
const { shortThreshold, mediumThreshold } = thresholds;
|
|
87
|
-
return [
|
|
88
|
-
{
|
|
89
|
-
$group: {
|
|
90
|
-
_id: null,
|
|
91
|
-
short: {
|
|
92
|
-
$sum: { $cond: [{ $lt: ["$callLength", shortThreshold] }, 1, 0] },
|
|
93
|
-
},
|
|
94
|
-
medium: {
|
|
95
|
-
$sum: {
|
|
96
|
-
$cond: [
|
|
97
|
-
{
|
|
98
|
-
$and: [
|
|
99
|
-
{ $gte: ["$callLength", shortThreshold] },
|
|
100
|
-
{ $lte: ["$callLength", mediumThreshold] },
|
|
101
|
-
],
|
|
102
|
-
},
|
|
103
|
-
1,
|
|
104
|
-
0,
|
|
105
|
-
],
|
|
106
|
-
},
|
|
107
|
-
},
|
|
108
|
-
long: {
|
|
109
|
-
$sum: { $cond: [{ $gt: ["$callLength", mediumThreshold] }, 1, 0] },
|
|
110
|
-
},
|
|
111
|
-
},
|
|
112
|
-
},
|
|
113
|
-
];
|
|
114
|
-
}
|
|
115
|
-
function buildHeatmapData(hourlyDataRaw) {
|
|
116
|
-
const heatmapMap = new Map();
|
|
117
|
-
for (const bucket of hourlyDataRaw) {
|
|
118
|
-
const dayKey = bucket._id.day;
|
|
119
|
-
const hour = bucket._id.hour;
|
|
120
|
-
if (!heatmapMap.has(dayKey))
|
|
121
|
-
heatmapMap.set(dayKey, new Map());
|
|
122
|
-
heatmapMap.get(dayKey).set(hour, bucket.count);
|
|
123
|
-
}
|
|
124
|
-
const toSortedBuckets = (map) => Array.from(map.entries())
|
|
125
|
-
.sort(([a], [b]) => a - b)
|
|
126
|
-
.map(([h, c]) => ({
|
|
127
|
-
hour: h,
|
|
128
|
-
calls: c,
|
|
129
|
-
}));
|
|
130
|
-
const heatmap = {};
|
|
131
|
-
for (const [day, hourMap] of Array.from(heatmapMap.entries()).sort()) {
|
|
132
|
-
heatmap[day] = toSortedBuckets(hourMap);
|
|
133
|
-
}
|
|
134
|
-
return heatmap;
|
|
135
|
-
}
|
|
136
176
|
async function getDashboardStats(params) {
|
|
137
|
-
const { clientId, startDate, endDate } = params;
|
|
177
|
+
const { clientId, startDate, endDate, granularity: requestedGranularity, } = params;
|
|
138
178
|
const clientConfig = await (0, clientsConfig_1.getClientConfig)(clientId);
|
|
139
179
|
const timezone = clientConfig?.timezone ?? "UTC";
|
|
140
|
-
const startDateObj = dayjs_1.default.tz(
|
|
141
|
-
const endDateObj = dayjs_1.default.tz(
|
|
142
|
-
const
|
|
143
|
-
shortThreshold: clientConfig?.callLengthThresholds?.shortThreshold ?? 60,
|
|
144
|
-
mediumThreshold: clientConfig?.callLengthThresholds?.mediumThreshold ?? 180,
|
|
145
|
-
};
|
|
180
|
+
const startDateObj = (0, dayjs_1.default)(startDate).tz(timezone).startOf("day").toDate();
|
|
181
|
+
const endDateObj = (0, dayjs_1.default)(endDate).tz(timezone).endOf("day").toDate();
|
|
182
|
+
const granularity = requestedGranularity ?? resolveVolumeGranularity(startDateObj, endDateObj);
|
|
146
183
|
const pipeline = [
|
|
147
184
|
{
|
|
148
185
|
$match: {
|
|
@@ -153,9 +190,7 @@ async function getDashboardStats(params) {
|
|
|
153
190
|
{
|
|
154
191
|
$facet: {
|
|
155
192
|
kpis: buildKpisPipeline(),
|
|
156
|
-
|
|
157
|
-
hourlyData: buildHourlyDataPipeline(timezone),
|
|
158
|
-
callLengthBuckets: buildCallLengthBucketsPipeline(thresholds),
|
|
193
|
+
volumeData: buildVolumeDataPipeline(timezone, granularity),
|
|
159
194
|
},
|
|
160
195
|
},
|
|
161
196
|
];
|
|
@@ -164,43 +199,23 @@ async function getDashboardStats(params) {
|
|
|
164
199
|
.aggregate(pipeline)
|
|
165
200
|
.toArray();
|
|
166
201
|
const kpiData = aggregatedResult?.kpis?.[0] ?? DEFAULT_KPI_DATA;
|
|
167
|
-
const
|
|
168
|
-
const
|
|
169
|
-
const
|
|
170
|
-
short: 0,
|
|
171
|
-
medium: 0,
|
|
172
|
-
long: 0,
|
|
173
|
-
};
|
|
202
|
+
const volumeDataRaw = aggregatedResult?.volumeData ?? [];
|
|
203
|
+
const answeredCount = kpiData.completedCount + kpiData.busyCount;
|
|
204
|
+
const answeredDuration = kpiData.answeredDuration ?? 0;
|
|
174
205
|
const kpis = {
|
|
175
|
-
totalCalls:
|
|
176
|
-
avgDurationSeconds:
|
|
177
|
-
|
|
178
|
-
: 0,
|
|
179
|
-
timeSavedMinutes: Math.round((kpiData.totalDuration ?? 0) / 60),
|
|
180
|
-
successRate: kpiData.totalCalls > 0
|
|
181
|
-
? Math.round((kpiData.completedCount / kpiData.totalCalls) * 1000) / 10
|
|
182
|
-
: 0,
|
|
206
|
+
totalCalls: answeredCount,
|
|
207
|
+
avgDurationSeconds: answeredCount > 0 ? Math.round(answeredDuration / answeredCount) : 0,
|
|
208
|
+
timeSavedMinutes: Math.round(answeredDuration / 60),
|
|
183
209
|
completedCount: kpiData.completedCount,
|
|
184
|
-
failedCount: kpiData.failedCount,
|
|
185
|
-
noAnswerCount: kpiData.noAnswerCount,
|
|
186
210
|
busyCount: kpiData.busyCount,
|
|
187
211
|
};
|
|
188
|
-
const
|
|
189
|
-
|
|
190
|
-
count: d.count,
|
|
191
|
-
completed: d.completed,
|
|
192
|
-
}));
|
|
193
|
-
const heatmap = buildHeatmapData(hourlyDataRaw);
|
|
212
|
+
const bucketKeys = generateBucketKeys(startDateObj, endDateObj, granularity, timezone);
|
|
213
|
+
const volumeData = fillVolumeGaps(bucketKeys, volumeDataRaw.map((d) => ({ date: d._id, completed: d.completed })));
|
|
194
214
|
const response = {
|
|
195
215
|
kpis,
|
|
196
216
|
charts: {
|
|
197
217
|
volumeData,
|
|
198
|
-
|
|
199
|
-
callLengthBuckets: {
|
|
200
|
-
short: callLengthRaw.short,
|
|
201
|
-
medium: callLengthRaw.medium,
|
|
202
|
-
long: callLengthRaw.long,
|
|
203
|
-
},
|
|
218
|
+
volumeGranularity: granularity,
|
|
204
219
|
},
|
|
205
220
|
};
|
|
206
221
|
return response;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"calls.dashboard.js","sourceRoot":"","sources":["../../../../src/talkpilot/calls/dashboard/calls.dashboard.ts"],"names":[],"mappings":";;;;;
|
|
1
|
+
{"version":3,"file":"calls.dashboard.js","sourceRoot":"","sources":["../../../../src/talkpilot/calls/dashboard/calls.dashboard.ts"],"names":[],"mappings":";;;;;AA2NA,8CAwEC;AAnSD,kDAA0B;AAC1B,oDAAsD;AACtD,uDAAsD;AACtD,2DAAmC;AACnC,qEAAmD;AACnD,mEAA2C;AAC3C,+EAAuD;AAgBvD,MAAM,gBAAgB,GAAG;IACvB,cAAc,EAAE,CAAC;IACjB,SAAS,EAAE,CAAC;IACZ,gBAAgB,EAAE,CAAC;CACpB,CAAC;AAEF,eAAK,CAAC,MAAM,CAAC,aAAG,CAAC,CAAC;AAClB,eAAK,CAAC,MAAM,CAAC,kBAAc,CAAC,CAAC;AAC7B,eAAK,CAAC,MAAM,CAAC,iBAAO,CAAC,CAAC;AACtB,eAAK,CAAC,MAAM,CAAC,uBAAa,CAAC,CAAC;AAE5B,MAAM,WAAW,GAA+C;IAC9D,IAAI,EAAE,MAAM;IACZ,GAAG,EAAE,KAAK;IACV,IAAI,EAAE,SAAS;IACf,KAAK,EAAE,OAAO;IACd,OAAO,EAAE,SAAS;IAClB,IAAI,EAAE,MAAM;CACb,CAAC;AAEF,SAAS,eAAe,CACtB,WAAwB,EACxB,WAAuC;IAEvC,QAAQ,WAAW,EAA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AAC,CAAC,EAAE,IAAI,EAAE,CAAC,CAAC,GAAG,EAAE,SAAS,EAAE,CAAC,CAAC,SAAS,EAAE,CAAC,CAAC,CACpE,CAAC;IAEF,MAAM,QAAQ,GAA4B;QACxC,IAAI;QACJ,MAAM,EAAE;YACN,UAAU;YACV,iBAAiB,EAAE,WAAW;SAC/B;KACF,CAAC;IACF,OAAO,QAAQ,CAAC;AAClB,CAAC"}
|
|
@@ -4,63 +4,42 @@ export type DashboardHeatmapMetric = {
|
|
|
4
4
|
};
|
|
5
5
|
export type DashboardDailyTrendMetric = {
|
|
6
6
|
date: string;
|
|
7
|
-
count: number;
|
|
8
7
|
completed: number;
|
|
9
8
|
};
|
|
10
|
-
export type
|
|
11
|
-
short: number;
|
|
12
|
-
medium: number;
|
|
13
|
-
long: number;
|
|
14
|
-
};
|
|
9
|
+
export type DashboardVolumeGranularity = "hour" | "day" | "week" | "month" | "quarter" | "year";
|
|
15
10
|
export type DashboardSummaryMetrics = {
|
|
16
11
|
totalCalls: number;
|
|
17
12
|
avgDurationSeconds: number;
|
|
18
13
|
timeSavedMinutes: number;
|
|
19
|
-
successRate: number;
|
|
20
14
|
completedCount: number;
|
|
21
|
-
failedCount: number;
|
|
22
|
-
noAnswerCount: number;
|
|
23
15
|
busyCount: number;
|
|
24
16
|
};
|
|
25
17
|
export type DashboardVisualData = {
|
|
26
18
|
volumeData: DashboardDailyTrendMetric[];
|
|
27
|
-
|
|
28
|
-
callLengthBuckets: DashboardDurationSegments;
|
|
19
|
+
volumeGranularity: DashboardVolumeGranularity;
|
|
29
20
|
};
|
|
30
21
|
export type DashboardReportQuery = {
|
|
31
22
|
clientId: string;
|
|
32
23
|
startDate: string;
|
|
33
24
|
endDate: string;
|
|
25
|
+
granularity?: DashboardVolumeGranularity;
|
|
34
26
|
};
|
|
35
27
|
export type DashboardReportResponse = {
|
|
36
28
|
kpis: DashboardSummaryMetrics;
|
|
37
29
|
charts: DashboardVisualData;
|
|
38
30
|
};
|
|
39
31
|
type RawKpiResult = {
|
|
40
|
-
totalCalls: number;
|
|
41
|
-
totalDuration: number | null;
|
|
42
32
|
completedCount: number;
|
|
43
|
-
failedCount: number;
|
|
44
|
-
noAnswerCount: number;
|
|
45
33
|
busyCount: number;
|
|
34
|
+
answeredDuration: number | null;
|
|
46
35
|
};
|
|
47
|
-
export type
|
|
36
|
+
export type RawVolumeAggregationResult = {
|
|
48
37
|
_id: string;
|
|
49
|
-
count: number;
|
|
50
38
|
completed: number;
|
|
51
39
|
};
|
|
52
|
-
export type RawHourlyAggregationResult = {
|
|
53
|
-
_id: {
|
|
54
|
-
day: string;
|
|
55
|
-
hour: number;
|
|
56
|
-
};
|
|
57
|
-
count: number;
|
|
58
|
-
};
|
|
59
40
|
export interface DashboardAggregationResult {
|
|
60
41
|
kpis: RawKpiResult[];
|
|
61
|
-
|
|
62
|
-
hourlyData: RawHourlyAggregationResult[];
|
|
63
|
-
callLengthBuckets: DashboardDurationSegments[];
|
|
42
|
+
volumeData: RawVolumeAggregationResult[];
|
|
64
43
|
}
|
|
65
44
|
export {};
|
|
66
45
|
//# sourceMappingURL=calls.dashboard.types.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"calls.dashboard.types.d.ts","sourceRoot":"","sources":["../../../../src/talkpilot/calls/dashboard/calls.dashboard.types.ts"],"names":[],"mappings":"AAAA,MAAM,MAAM,sBAAsB,GAAG;IACnC,IAAI,EAAE,MAAM,CAAC;IACb,KAAK,EAAE,MAAM,CAAC;CACf,CAAC;AAEF,MAAM,MAAM,yBAAyB,GAAG;IACtC,IAAI,EAAE,MAAM,CAAC;IACb,
|
|
1
|
+
{"version":3,"file":"calls.dashboard.types.d.ts","sourceRoot":"","sources":["../../../../src/talkpilot/calls/dashboard/calls.dashboard.types.ts"],"names":[],"mappings":"AAAA,MAAM,MAAM,sBAAsB,GAAG;IACnC,IAAI,EAAE,MAAM,CAAC;IACb,KAAK,EAAE,MAAM,CAAC;CACf,CAAC;AAEF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JestConfigWithTsJest} */
|
|
2
|
-
module.exports = {
|
|
3
|
-
preset: 'ts-jest',
|
|
4
|
-
testEnvironment: 'node',
|
|
5
|
-
roots: ['<rootDir>/src'],
|
|
6
|
-
testPathIgnorePatterns: ['<rootDir>/src/__tests__/legacy/'],
|
|
7
|
-
testMatch: ['**/__tests__/**/*.spec.ts', '**/*.spec.ts'],
|
|
8
|
-
transform: {
|
|
9
|
-
'^.+\\.tsx?$': ['ts-jest', {
|
|
10
|
-
tsconfig: 'tsconfig.json',
|
|
11
|
-
}],
|
|
12
|
-
},
|
|
13
|
-
setupFilesAfterEnv: ['<rootDir>/src/__tests__/setup.ts'],
|
|
14
|
-
verbose: true,
|
|
15
|
-
forceExit: true,
|
|
16
|
-
clearMocks: true,
|
|
17
|
-
resetMocks: true,
|
|
18
|
-
restoreMocks: true,
|
|
19
|
-
};
|
|
1
|
+
/** @type {import('ts-jest').JestConfigWithTsJest} */
|
|
2
|
+
module.exports = {
|
|
3
|
+
preset: 'ts-jest',
|
|
4
|
+
testEnvironment: 'node',
|
|
5
|
+
roots: ['<rootDir>/src'],
|
|
6
|
+
testPathIgnorePatterns: ['<rootDir>/src/__tests__/legacy/'],
|
|
7
|
+
testMatch: ['**/__tests__/**/*.spec.ts', '**/*.spec.ts'],
|
|
8
|
+
transform: {
|
|
9
|
+
'^.+\\.tsx?$': ['ts-jest', {
|
|
10
|
+
tsconfig: 'tsconfig.json',
|
|
11
|
+
}],
|
|
12
|
+
},
|
|
13
|
+
setupFilesAfterEnv: ['<rootDir>/src/__tests__/setup.ts'],
|
|
14
|
+
verbose: true,
|
|
15
|
+
forceExit: true,
|
|
16
|
+
clearMocks: true,
|
|
17
|
+
resetMocks: true,
|
|
18
|
+
restoreMocks: true,
|
|
19
|
+
};
|
package/package.json
CHANGED
|
@@ -1,46 +1,46 @@
|
|
|
1
|
-
{
|
|
2
|
-
"name": "@talkpilot/core-db",
|
|
3
|
-
"version": "1.
|
|
4
|
-
"description": "Core database package for centralized connections and ORM integration.",
|
|
5
|
-
"main": "dist/index.js",
|
|
6
|
-
"types": "dist/index.d.ts",
|
|
7
|
-
"scripts": {
|
|
8
|
-
"build": "tsc",
|
|
9
|
-
"dev": "tsc --watch",
|
|
10
|
-
"test": "jest",
|
|
11
|
-
"lint": "eslint 'src/**/*.{ts,tsx}'",
|
|
12
|
-
"format": "prettier --write \"src/**/*.{ts,tsx}\"",
|
|
13
|
-
"prepare": "npm run build"
|
|
14
|
-
},
|
|
15
|
-
"keywords": [
|
|
16
|
-
"database",
|
|
17
|
-
"orm",
|
|
18
|
-
"typescript",
|
|
19
|
-
"postgres",
|
|
20
|
-
"db-client"
|
|
21
|
-
],
|
|
22
|
-
"author": "",
|
|
23
|
-
"license": "MIT",
|
|
24
|
-
"dependencies": {
|
|
25
|
-
"dayjs": "^1.11.21",
|
|
26
|
-
"express": "^4.18.0",
|
|
27
|
-
"google-libphonenumber": "^3.2.0",
|
|
28
|
-
"mongodb": "^6.11.0"
|
|
29
|
-
},
|
|
30
|
-
"devDependencies": {
|
|
31
|
-
"@faker-js/faker": "^8.0.0",
|
|
32
|
-
"@types/express": "^4.17.0",
|
|
33
|
-
"@types/google-libphonenumber": "^7.4.0",
|
|
34
|
-
"@types/jest": "^29.0.0",
|
|
35
|
-
"@types/node": "^20.0.0",
|
|
36
|
-
"fishery": "^2.4.0",
|
|
37
|
-
"jest": "^29.0.0",
|
|
38
|
-
"mongodb-memory-server": "^10.0.0",
|
|
39
|
-
"prettier": "^3.8.2",
|
|
40
|
-
"ts-jest": "^29.0.0",
|
|
41
|
-
"typescript": "^5.0.0"
|
|
42
|
-
},
|
|
43
|
-
"publishConfig": {
|
|
44
|
-
"access": "public"
|
|
45
|
-
}
|
|
46
|
-
}
|
|
1
|
+
{
|
|
2
|
+
"name": "@talkpilot/core-db",
|
|
3
|
+
"version": "1.3.1",
|
|
4
|
+
"description": "Core database package for centralized connections and ORM integration.",
|
|
5
|
+
"main": "dist/index.js",
|
|
6
|
+
"types": "dist/index.d.ts",
|
|
7
|
+
"scripts": {
|
|
8
|
+
"build": "tsc",
|
|
9
|
+
"dev": "tsc --watch",
|
|
10
|
+
"test": "jest",
|
|
11
|
+
"lint": "eslint 'src/**/*.{ts,tsx}'",
|
|
12
|
+
"format": "prettier --write \"src/**/*.{ts,tsx}\"",
|
|
13
|
+
"prepare": "npm run build"
|
|
14
|
+
},
|
|
15
|
+
"keywords": [
|
|
16
|
+
"database",
|
|
17
|
+
"orm",
|
|
18
|
+
"typescript",
|
|
19
|
+
"postgres",
|
|
20
|
+
"db-client"
|
|
21
|
+
],
|
|
22
|
+
"author": "",
|
|
23
|
+
"license": "MIT",
|
|
24
|
+
"dependencies": {
|
|
25
|
+
"dayjs": "^1.11.21",
|
|
26
|
+
"express": "^4.18.0",
|
|
27
|
+
"google-libphonenumber": "^3.2.0",
|
|
28
|
+
"mongodb": "^6.11.0"
|
|
29
|
+
},
|
|
30
|
+
"devDependencies": {
|
|
31
|
+
"@faker-js/faker": "^8.0.0",
|
|
32
|
+
"@types/express": "^4.17.0",
|
|
33
|
+
"@types/google-libphonenumber": "^7.4.0",
|
|
34
|
+
"@types/jest": "^29.0.0",
|
|
35
|
+
"@types/node": "^20.0.0",
|
|
36
|
+
"fishery": "^2.4.0",
|
|
37
|
+
"jest": "^29.0.0",
|
|
38
|
+
"mongodb-memory-server": "^10.0.0",
|
|
39
|
+
"prettier": "^3.8.2",
|
|
40
|
+
"ts-jest": "^29.0.0",
|
|
41
|
+
"typescript": "^5.0.0"
|
|
42
|
+
},
|
|
43
|
+
"publishConfig": {
|
|
44
|
+
"access": "public"
|
|
45
|
+
}
|
|
46
|
+
}
|