@talkpilot/core-db 1.3.64 → 1.3.66
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/README.md +863 -816
- package/dist/talkpilot/auditLogs/auditLogs.getters.d.ts +8 -0
- package/dist/talkpilot/auditLogs/auditLogs.getters.d.ts.map +1 -0
- package/dist/talkpilot/auditLogs/auditLogs.getters.js +26 -0
- package/dist/talkpilot/auditLogs/auditLogs.getters.js.map +1 -0
- package/dist/talkpilot/auditLogs/auditLogs.setters.d.ts +3 -0
- package/dist/talkpilot/auditLogs/auditLogs.setters.d.ts.map +1 -0
- package/dist/talkpilot/auditLogs/auditLogs.setters.js +9 -0
- package/dist/talkpilot/auditLogs/auditLogs.setters.js.map +1 -0
- package/dist/talkpilot/auditLogs/auditLogs.types.d.ts +11 -0
- package/dist/talkpilot/auditLogs/auditLogs.types.d.ts.map +1 -0
- package/dist/talkpilot/{callTokenUsage/callTokenUsage.types.js → auditLogs/auditLogs.types.js} +1 -1
- package/dist/talkpilot/auditLogs/auditLogs.types.js.map +1 -0
- package/dist/talkpilot/auditLogs/index.d.ts +3 -0
- package/dist/talkpilot/auditLogs/index.d.ts.map +1 -0
- package/dist/talkpilot/{callTokenUsage → auditLogs}/index.js +2 -1
- package/dist/talkpilot/auditLogs/index.js.map +1 -0
- package/dist/talkpilot/calls/calls.constants.d.ts +9 -1
- package/dist/talkpilot/calls/calls.constants.d.ts.map +1 -1
- package/dist/talkpilot/calls/calls.constants.js +9 -1
- package/dist/talkpilot/calls/calls.constants.js.map +1 -1
- package/dist/talkpilot/calls/calls.getters.d.ts +7 -1
- package/dist/talkpilot/calls/calls.getters.d.ts.map +1 -1
- package/dist/talkpilot/calls/calls.getters.js +181 -1
- package/dist/talkpilot/calls/calls.getters.js.map +1 -1
- package/dist/talkpilot/calls/calls.types.d.ts +35 -0
- package/dist/talkpilot/calls/calls.types.d.ts.map +1 -1
- package/dist/talkpilot/clientDeletionLogs/clientDeletionLogs.getters.d.ts +4 -0
- package/dist/talkpilot/clientDeletionLogs/clientDeletionLogs.getters.d.ts.map +1 -0
- package/dist/talkpilot/clientDeletionLogs/clientDeletionLogs.getters.js +9 -0
- package/dist/talkpilot/clientDeletionLogs/clientDeletionLogs.getters.js.map +1 -0
- package/dist/talkpilot/clientDeletionLogs/clientDeletionLogs.setters.d.ts +3 -0
- package/dist/talkpilot/clientDeletionLogs/clientDeletionLogs.setters.d.ts.map +1 -0
- package/dist/talkpilot/clientDeletionLogs/clientDeletionLogs.setters.js +9 -0
- package/dist/talkpilot/clientDeletionLogs/clientDeletionLogs.setters.js.map +1 -0
- package/dist/talkpilot/clientDeletionLogs/clientDeletionLogs.types.d.ts +10 -0
- package/dist/talkpilot/clientDeletionLogs/clientDeletionLogs.types.d.ts.map +1 -0
- package/dist/talkpilot/clientDeletionLogs/clientDeletionLogs.types.js +3 -0
- package/dist/talkpilot/clientDeletionLogs/clientDeletionLogs.types.js.map +1 -0
- package/dist/talkpilot/clientDeletionLogs/index.d.ts +4 -0
- package/dist/talkpilot/clientDeletionLogs/index.d.ts.map +1 -0
- package/dist/talkpilot/clientDeletionLogs/index.js +20 -0
- package/dist/talkpilot/clientDeletionLogs/index.js.map +1 -0
- package/dist/talkpilot/clients/clients.constants.d.ts +3 -0
- package/dist/talkpilot/clients/clients.constants.d.ts.map +1 -0
- package/dist/talkpilot/clients/clients.constants.js +6 -0
- package/dist/talkpilot/clients/clients.constants.js.map +1 -0
- package/dist/talkpilot/clients/clients.getters.d.ts +2 -0
- package/dist/talkpilot/clients/clients.getters.d.ts.map +1 -1
- package/dist/talkpilot/clients/clients.getters.js +15 -1
- package/dist/talkpilot/clients/clients.getters.js.map +1 -1
- package/dist/talkpilot/clients/clients.lifecycle.d.ts +10 -0
- package/dist/talkpilot/clients/clients.lifecycle.d.ts.map +1 -0
- package/dist/talkpilot/clients/clients.lifecycle.js +95 -0
- package/dist/talkpilot/clients/clients.lifecycle.js.map +1 -0
- package/dist/talkpilot/clients/clients.types.d.ts +21 -0
- package/dist/talkpilot/clients/clients.types.d.ts.map +1 -1
- package/dist/talkpilot/clients/index.d.ts +2 -0
- package/dist/talkpilot/clients/index.d.ts.map +1 -1
- package/dist/talkpilot/clients/index.js +2 -0
- package/dist/talkpilot/clients/index.js.map +1 -1
- package/dist/talkpilot/index.d.ts +1 -1
- package/dist/talkpilot/index.d.ts.map +1 -1
- package/dist/talkpilot/index.js +1 -1
- package/dist/talkpilot/index.js.map +1 -1
- package/dist/talkpilot/phone_numbers/phone_numbers.getter.d.ts +9 -1
- package/dist/talkpilot/phone_numbers/phone_numbers.getter.d.ts.map +1 -1
- package/dist/talkpilot/phone_numbers/phone_numbers.getter.js +66 -1
- package/dist/talkpilot/phone_numbers/phone_numbers.getter.js.map +1 -1
- package/dist/talkpilot/phone_numbers/phone_numbers.types.d.ts +5 -0
- package/dist/talkpilot/phone_numbers/phone_numbers.types.d.ts.map +1 -1
- package/dist/talkpilot/results/results.constants.d.ts +4 -0
- package/dist/talkpilot/results/results.constants.d.ts.map +1 -0
- package/dist/talkpilot/results/results.constants.js +10 -0
- package/dist/talkpilot/results/results.constants.js.map +1 -0
- package/dist/talkpilot/results/results.statistics.getters.d.ts +12 -0
- package/dist/talkpilot/results/results.statistics.getters.d.ts.map +1 -0
- package/dist/talkpilot/results/results.statistics.getters.js +258 -0
- package/dist/talkpilot/results/results.statistics.getters.js.map +1 -0
- package/dist/talkpilot/results/results.statistics.types.d.ts +22 -0
- package/dist/talkpilot/results/results.statistics.types.d.ts.map +1 -0
- package/dist/talkpilot/results/results.statistics.types.js +3 -0
- package/dist/talkpilot/results/results.statistics.types.js.map +1 -0
- package/dist/test-utils/factories/index.d.ts +2 -0
- package/dist/test-utils/factories/index.d.ts.map +1 -1
- package/dist/test-utils/factories/index.js +2 -0
- package/dist/test-utils/factories/index.js.map +1 -1
- package/dist/test-utils/factories/talkpilot/clients.d.ts +14 -0
- package/dist/test-utils/factories/talkpilot/clients.d.ts.map +1 -0
- package/dist/test-utils/factories/talkpilot/clients.js +19 -0
- package/dist/test-utils/factories/talkpilot/clients.js.map +1 -0
- package/dist/test-utils/factories/talkpilot/results.d.ts +16 -0
- package/dist/test-utils/factories/talkpilot/results.d.ts.map +1 -0
- package/dist/test-utils/factories/talkpilot/results.js +40 -0
- package/dist/test-utils/factories/talkpilot/results.js.map +1 -0
- package/package.json +1 -1
- package/src/talkpilot/auditLogs/__tests__/auditLogs.spec.ts +91 -0
- package/src/talkpilot/auditLogs/auditLogs.getters.ts +26 -0
- package/src/talkpilot/auditLogs/auditLogs.types.ts +12 -0
- package/src/talkpilot/auditLogs/index.ts +2 -0
- package/src/talkpilot/calls/__tests__/calls.statistics.getters.spec.ts +374 -0
- package/src/talkpilot/calls/calls.constants.ts +12 -0
- package/src/talkpilot/calls/calls.getters.ts +546 -277
- package/src/talkpilot/calls/calls.types.ts +189 -149
- package/src/talkpilot/clients/__tests__/clients.getters.spec.ts +51 -0
- package/src/talkpilot/clients/__tests__/clients.lifecycle.spec.ts +166 -0
- package/src/talkpilot/clients/clients.constants.ts +2 -0
- package/src/talkpilot/clients/clients.getters.ts +13 -0
- package/src/talkpilot/clients/clients.lifecycle.ts +116 -0
- package/src/talkpilot/clients/clients.types.ts +19 -0
- package/src/talkpilot/clients/index.ts +2 -0
- package/src/talkpilot/index.ts +1 -1
- package/src/talkpilot/phone_numbers/__tests__/phone_numbers.spec.ts +257 -13
- package/src/talkpilot/phone_numbers/phone_numbers.getter.ts +85 -1
- package/src/talkpilot/phone_numbers/phone_numbers.types.ts +6 -0
- package/src/test-utils/factories/index.ts +2 -0
- package/src/test-utils/factories/talkpilot/clients.ts +21 -0
- package/src/test-utils/factories/talkpilot/results.ts +43 -0
- package/dist/talkpilot/callTokenUsage/callTokenUsage.getters.d.ts +0 -4
- package/dist/talkpilot/callTokenUsage/callTokenUsage.getters.d.ts.map +0 -1
- package/dist/talkpilot/callTokenUsage/callTokenUsage.getters.js +0 -30
- package/dist/talkpilot/callTokenUsage/callTokenUsage.getters.js.map +0 -1
- package/dist/talkpilot/callTokenUsage/callTokenUsage.types.d.ts +0 -28
- package/dist/talkpilot/callTokenUsage/callTokenUsage.types.d.ts.map +0 -1
- package/dist/talkpilot/callTokenUsage/callTokenUsage.types.js.map +0 -1
- package/dist/talkpilot/callTokenUsage/index.d.ts +0 -3
- package/dist/talkpilot/callTokenUsage/index.d.ts.map +0 -1
- package/dist/talkpilot/callTokenUsage/index.js.map +0 -1
- package/src/talkpilot/callTokenUsage/__tests__/callTokenUsage.getters.spec.ts +0 -57
- package/src/talkpilot/callTokenUsage/callTokenUsage.getters.ts +0 -42
- package/src/talkpilot/callTokenUsage/callTokenUsage.types.ts +0 -28
- package/src/talkpilot/callTokenUsage/index.ts +0 -2
|
@@ -0,0 +1,258 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.findClientIdsByCallSids = exports.aggregateSessionCallStats = exports.aggregateClientCallStats = exports.aggregateTodayCallsSummary = exports.aggregateActiveCallsSummary = void 0;
|
|
4
|
+
const results_getter_1 = require("./results.getter");
|
|
5
|
+
const date_utils_1 = require("../../utils/date.utils");
|
|
6
|
+
const calls_constants_1 = require("../calls/calls.constants");
|
|
7
|
+
const results_constants_1 = require("./results.constants");
|
|
8
|
+
const dateRangeFilter = (dateFrom, dateTo, timezone) => {
|
|
9
|
+
const today = (0, date_utils_1.formatYmdInTz)(new Date(), timezone);
|
|
10
|
+
return {
|
|
11
|
+
start: (0, date_utils_1.startOfCalendarDayInTz)(dateFrom ?? today, timezone),
|
|
12
|
+
end: (0, date_utils_1.endOfCalendarDayInTz)(dateTo ?? today, timezone),
|
|
13
|
+
};
|
|
14
|
+
};
|
|
15
|
+
const buildDateRangeMatch = (start, end, clientId) => {
|
|
16
|
+
const clientFilter = clientId ? { clientId } : {};
|
|
17
|
+
return { ...clientFilter, "calls.date": { $gte: start, $lte: end } };
|
|
18
|
+
};
|
|
19
|
+
// Filters on `clientId` (a document-level field) before `$unwind` explodes `calls[]`,
|
|
20
|
+
// so Mongo never has to unwind documents belonging to other clients.
|
|
21
|
+
const clientPreMatchStage = (clientId) => clientId ? [{ $match: { clientId } }] : [];
|
|
22
|
+
// Converts a duration string like "120 seconds" into a number (120) that can be summed inside an aggregation.
|
|
23
|
+
const durationExpr = {
|
|
24
|
+
$convert: {
|
|
25
|
+
input: {
|
|
26
|
+
$arrayElemAt: [
|
|
27
|
+
{ $split: [{ $ifNull: ["$calls.callLength", "0 seconds"] }, " "] },
|
|
28
|
+
0,
|
|
29
|
+
],
|
|
30
|
+
},
|
|
31
|
+
to: "double",
|
|
32
|
+
onError: 0,
|
|
33
|
+
onNull: 0,
|
|
34
|
+
},
|
|
35
|
+
};
|
|
36
|
+
const statusFields = {
|
|
37
|
+
totalCalls: { $sum: 1 },
|
|
38
|
+
completed: {
|
|
39
|
+
$sum: { $cond: [{ $eq: ["$calls.status", "completed"] }, 1, 0] },
|
|
40
|
+
},
|
|
41
|
+
failed: { $sum: { $cond: [{ $eq: ["$calls.status", "failed"] }, 1, 0] } },
|
|
42
|
+
noAnswer: {
|
|
43
|
+
$sum: { $cond: [{ $eq: ["$calls.status", "no-answer"] }, 1, 0] },
|
|
44
|
+
},
|
|
45
|
+
busy: { $sum: { $cond: [{ $eq: ["$calls.status", "busy"] }, 1, 0] } },
|
|
46
|
+
inProgress: {
|
|
47
|
+
$sum: { $cond: [{ $eq: ["$calls.status", "in-progress"] }, 1, 0] },
|
|
48
|
+
},
|
|
49
|
+
};
|
|
50
|
+
/** @deprecated Use aggregateActiveCallsSummaryFromCalls instead — reads the flat `calls` collection directly instead of unwinding `results.calls[]`. Counts active calls differently, see README. */
|
|
51
|
+
const aggregateActiveCallsSummary = async (clientId) => {
|
|
52
|
+
const coll = (0, results_getter_1.getResultsCollection)();
|
|
53
|
+
const twoHoursAgo = new Date(Date.now() - calls_constants_1.ACTIVE_CALLS_WINDOW_MS);
|
|
54
|
+
const activeMatch = {
|
|
55
|
+
"calls.status": { $in: calls_constants_1.ACTIVE_STATUSES },
|
|
56
|
+
"calls.date": { $gte: twoHoursAgo },
|
|
57
|
+
};
|
|
58
|
+
const facetResult = await coll
|
|
59
|
+
.aggregate([
|
|
60
|
+
...clientPreMatchStage(clientId),
|
|
61
|
+
{ $match: { "calls.date": { $gte: twoHoursAgo } } },
|
|
62
|
+
{ $unwind: "$calls" },
|
|
63
|
+
{ $match: activeMatch },
|
|
64
|
+
{
|
|
65
|
+
$facet: {
|
|
66
|
+
counts: [
|
|
67
|
+
{
|
|
68
|
+
$group: {
|
|
69
|
+
_id: null,
|
|
70
|
+
total: { $addToSet: "$calls.callSid" },
|
|
71
|
+
incoming: {
|
|
72
|
+
$addToSet: {
|
|
73
|
+
$cond: [
|
|
74
|
+
{ $eq: ["$sessionId", calls_constants_1.INCOMING_SESSION_ID] },
|
|
75
|
+
"$calls.callSid",
|
|
76
|
+
null,
|
|
77
|
+
],
|
|
78
|
+
},
|
|
79
|
+
},
|
|
80
|
+
outgoing: {
|
|
81
|
+
$addToSet: {
|
|
82
|
+
$cond: [
|
|
83
|
+
{ $ne: ["$sessionId", calls_constants_1.INCOMING_SESSION_ID] },
|
|
84
|
+
"$calls.callSid",
|
|
85
|
+
null,
|
|
86
|
+
],
|
|
87
|
+
},
|
|
88
|
+
},
|
|
89
|
+
},
|
|
90
|
+
},
|
|
91
|
+
{
|
|
92
|
+
$project: {
|
|
93
|
+
_id: 0,
|
|
94
|
+
total: { $size: "$total" },
|
|
95
|
+
incoming: {
|
|
96
|
+
$size: { $setDifference: ["$incoming", [null]] },
|
|
97
|
+
},
|
|
98
|
+
outgoing: {
|
|
99
|
+
$size: { $setDifference: ["$outgoing", [null]] },
|
|
100
|
+
},
|
|
101
|
+
},
|
|
102
|
+
},
|
|
103
|
+
],
|
|
104
|
+
activeClients: [{ $group: { _id: "$clientId" } }],
|
|
105
|
+
},
|
|
106
|
+
},
|
|
107
|
+
])
|
|
108
|
+
.next();
|
|
109
|
+
const counts = facetResult?.counts?.[0];
|
|
110
|
+
return {
|
|
111
|
+
total: counts?.total ?? 0,
|
|
112
|
+
incoming: counts?.incoming ?? 0,
|
|
113
|
+
outgoing: counts?.outgoing ?? 0,
|
|
114
|
+
activeClientIds: (facetResult?.activeClients ?? []).map((d) => d._id || "Unknown"),
|
|
115
|
+
};
|
|
116
|
+
};
|
|
117
|
+
exports.aggregateActiveCallsSummary = aggregateActiveCallsSummary;
|
|
118
|
+
/** @deprecated Use aggregateTodayCallsSummaryFromCalls instead — reads the flat `calls` collection directly instead of unwinding `results.calls[]`. Defaults to all-time, not today, see README. */
|
|
119
|
+
const aggregateTodayCallsSummary = async ({ dateFrom, dateTo, clientId, timezone = "UTC", }) => {
|
|
120
|
+
const coll = (0, results_getter_1.getResultsCollection)();
|
|
121
|
+
const { start, end } = dateRangeFilter(dateFrom, dateTo, timezone);
|
|
122
|
+
const match = buildDateRangeMatch(start, end, clientId);
|
|
123
|
+
const facetResult = await coll
|
|
124
|
+
.aggregate([
|
|
125
|
+
...clientPreMatchStage(clientId),
|
|
126
|
+
{ $match: { "calls.date": { $gte: start, $lte: end } } },
|
|
127
|
+
{ $unwind: "$calls" },
|
|
128
|
+
{ $match: match },
|
|
129
|
+
{
|
|
130
|
+
$facet: {
|
|
131
|
+
byStatus: [{ $group: { _id: "$calls.status", count: { $sum: 1 } } }],
|
|
132
|
+
byType: [
|
|
133
|
+
{
|
|
134
|
+
$group: {
|
|
135
|
+
_id: {
|
|
136
|
+
$cond: [
|
|
137
|
+
{ $eq: ["$sessionId", calls_constants_1.INCOMING_SESSION_ID] },
|
|
138
|
+
"incoming",
|
|
139
|
+
"outgoing",
|
|
140
|
+
],
|
|
141
|
+
},
|
|
142
|
+
count: { $sum: 1 },
|
|
143
|
+
},
|
|
144
|
+
},
|
|
145
|
+
],
|
|
146
|
+
total: [{ $group: { _id: null, count: { $sum: 1 } } }],
|
|
147
|
+
totalSeconds: [
|
|
148
|
+
{ $group: { _id: null, seconds: { $sum: durationExpr } } },
|
|
149
|
+
],
|
|
150
|
+
},
|
|
151
|
+
},
|
|
152
|
+
])
|
|
153
|
+
.next();
|
|
154
|
+
const byStatus = {};
|
|
155
|
+
(facetResult?.byStatus ?? []).forEach((s) => {
|
|
156
|
+
byStatus[s._id] = s.count;
|
|
157
|
+
});
|
|
158
|
+
const byType = {};
|
|
159
|
+
(facetResult?.byType ?? []).forEach((t) => {
|
|
160
|
+
byType[t._id] = t.count;
|
|
161
|
+
});
|
|
162
|
+
const totalSeconds = facetResult?.totalSeconds?.[0]?.seconds ?? 0;
|
|
163
|
+
return {
|
|
164
|
+
total: facetResult?.total?.[0]?.count ?? 0,
|
|
165
|
+
incoming: byType.incoming ?? 0,
|
|
166
|
+
outgoing: byType.outgoing ?? 0,
|
|
167
|
+
completed: byStatus.completed ?? 0,
|
|
168
|
+
failed: byStatus.failed ?? 0,
|
|
169
|
+
busy: byStatus.busy ?? 0,
|
|
170
|
+
noAnswer: byStatus["no-answer"] ?? 0,
|
|
171
|
+
totalMinutes: Math.ceil(totalSeconds / 60),
|
|
172
|
+
};
|
|
173
|
+
};
|
|
174
|
+
exports.aggregateTodayCallsSummary = aggregateTodayCallsSummary;
|
|
175
|
+
/** @deprecated Use aggregateClientCallStatsFromCalls instead — reads the flat `calls` collection directly, with a full per-status breakdown instead of a fixed 5-status set. Defaults to all-time, not today, see README. */
|
|
176
|
+
const aggregateClientCallStats = async ({ dateFrom, dateTo, clientId, timezone = "UTC", }) => {
|
|
177
|
+
const coll = (0, results_getter_1.getResultsCollection)();
|
|
178
|
+
const { start, end } = dateRangeFilter(dateFrom, dateTo, timezone);
|
|
179
|
+
const match = buildDateRangeMatch(start, end, clientId);
|
|
180
|
+
const rows = await coll
|
|
181
|
+
.aggregate([
|
|
182
|
+
...clientPreMatchStage(clientId),
|
|
183
|
+
{ $match: { "calls.date": { $gte: start, $lte: end } } },
|
|
184
|
+
{ $unwind: "$calls" },
|
|
185
|
+
{ $match: match },
|
|
186
|
+
{
|
|
187
|
+
$group: {
|
|
188
|
+
_id: "$clientId",
|
|
189
|
+
...statusFields,
|
|
190
|
+
totalSeconds: { $sum: durationExpr },
|
|
191
|
+
},
|
|
192
|
+
},
|
|
193
|
+
{ $sort: { totalCalls: -1 } },
|
|
194
|
+
])
|
|
195
|
+
.toArray();
|
|
196
|
+
return rows.map((r) => ({
|
|
197
|
+
clientId: r._id || "Unknown",
|
|
198
|
+
totalCalls: r.totalCalls,
|
|
199
|
+
completed: r.completed,
|
|
200
|
+
failed: r.failed,
|
|
201
|
+
noAnswer: r.noAnswer,
|
|
202
|
+
busy: r.busy,
|
|
203
|
+
inProgress: r.inProgress,
|
|
204
|
+
totalMinutes: Math.ceil((r.totalSeconds || 0) / 60),
|
|
205
|
+
}));
|
|
206
|
+
};
|
|
207
|
+
exports.aggregateClientCallStats = aggregateClientCallStats;
|
|
208
|
+
/** @deprecated Use aggregateSessionCallStatsFromCalls instead — reads the flat `calls` collection directly, with a full per-status breakdown instead of a fixed 5-status set. Defaults to all-time, no row limit, see README. */
|
|
209
|
+
const aggregateSessionCallStats = async ({ dateFrom, dateTo, clientId, timezone = "UTC", }) => {
|
|
210
|
+
const coll = (0, results_getter_1.getResultsCollection)();
|
|
211
|
+
const { start, end } = dateRangeFilter(dateFrom, dateTo, timezone);
|
|
212
|
+
const match = buildDateRangeMatch(start, end, clientId);
|
|
213
|
+
const rows = await coll
|
|
214
|
+
.aggregate([
|
|
215
|
+
...clientPreMatchStage(clientId),
|
|
216
|
+
{ $match: { "calls.date": { $gte: start, $lte: end } } },
|
|
217
|
+
{ $unwind: "$calls" },
|
|
218
|
+
{ $match: match },
|
|
219
|
+
{ $sort: { "calls.date": 1, "calls.callSid": 1 } },
|
|
220
|
+
{
|
|
221
|
+
$group: {
|
|
222
|
+
_id: "$sessionId",
|
|
223
|
+
sessionName: { $last: "$sessionName" },
|
|
224
|
+
...statusFields,
|
|
225
|
+
},
|
|
226
|
+
},
|
|
227
|
+
{ $sort: { totalCalls: -1 } },
|
|
228
|
+
{ $limit: results_constants_1.SESSION_STATS_LIMIT },
|
|
229
|
+
])
|
|
230
|
+
.toArray();
|
|
231
|
+
return rows.map((r) => ({
|
|
232
|
+
sessionId: r._id || "Unknown",
|
|
233
|
+
sessionName: r.sessionName || "Unknown",
|
|
234
|
+
totalCalls: r.totalCalls,
|
|
235
|
+
completed: r.completed,
|
|
236
|
+
failed: r.failed,
|
|
237
|
+
noAnswer: r.noAnswer,
|
|
238
|
+
busy: r.busy,
|
|
239
|
+
inProgress: r.inProgress,
|
|
240
|
+
}));
|
|
241
|
+
};
|
|
242
|
+
exports.aggregateSessionCallStats = aggregateSessionCallStats;
|
|
243
|
+
/** @deprecated Use findClientIdsByCallSidsFromCalls instead — reads the flat `calls` collection directly instead of unwinding `results.calls[]`. */
|
|
244
|
+
const findClientIdsByCallSids = async (callSids) => {
|
|
245
|
+
if (callSids.length === 0)
|
|
246
|
+
return new Map();
|
|
247
|
+
const docs = await (0, results_getter_1.getResultsCollection)()
|
|
248
|
+
.aggregate([
|
|
249
|
+
{ $match: { "calls.callSid": { $in: callSids } } },
|
|
250
|
+
{ $unwind: "$calls" },
|
|
251
|
+
{ $match: { "calls.callSid": { $in: callSids } } },
|
|
252
|
+
{ $project: { _id: 0, clientId: 1, callSid: "$calls.callSid" } },
|
|
253
|
+
])
|
|
254
|
+
.toArray();
|
|
255
|
+
return new Map(docs.map((d) => [d.callSid, d.clientId]));
|
|
256
|
+
};
|
|
257
|
+
exports.findClientIdsByCallSids = findClientIdsByCallSids;
|
|
258
|
+
//# sourceMappingURL=results.statistics.getters.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"results.statistics.getters.js","sourceRoot":"","sources":["../../../src/talkpilot/results/results.statistics.getters.ts"],"names":[],"mappings":";;;AAAA,qDAAwD;AACxD,uDAIgC;AAChC,8DAIkC;AAClC,2DAA0D;AAS1D,MAAM,eAAe,GAAG,CACtB,QAA4B,EAC5B,MAA0B,EAC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AAO,IAAI,GAAG,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,CAAC,OAAO,EAAE,CAAC,CAAC,QAAQ,CAAC,CAAC,CAAC,CAAC;AAC3D,CAAC,CAAC;AAfW,QAAA,uBAAuB,2BAelC"}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
export type { StatsDateRangeParams, ActiveCallsSummary, TodayCallsSummary, } from "../calls/calls.types";
|
|
2
|
+
export type ClientCallStats = {
|
|
3
|
+
clientId: string;
|
|
4
|
+
totalCalls: number;
|
|
5
|
+
completed: number;
|
|
6
|
+
failed: number;
|
|
7
|
+
noAnswer: number;
|
|
8
|
+
busy: number;
|
|
9
|
+
inProgress: number;
|
|
10
|
+
totalMinutes: number;
|
|
11
|
+
};
|
|
12
|
+
export type SessionCallStats = {
|
|
13
|
+
sessionId: string;
|
|
14
|
+
sessionName: string;
|
|
15
|
+
totalCalls: number;
|
|
16
|
+
completed: number;
|
|
17
|
+
failed: number;
|
|
18
|
+
noAnswer: number;
|
|
19
|
+
busy: number;
|
|
20
|
+
inProgress: number;
|
|
21
|
+
};
|
|
22
|
+
//# sourceMappingURL=results.statistics.types.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"results.statistics.types.d.ts","sourceRoot":"","sources":["../../../src/talkpilot/results/results.statistics.types.ts"],"names":[],"mappings":"AAAA,YAAY,EACV,oBAAoB,EACpB,kBAAkB,EAClB,iBAAiB,GAClB,MAAM,sBAAsB,CAAC;AAE9B,MAAM,MAAM,eAAe,GAAG;IAC5B,QAAQ,EAAE,MAAM,CAAC;IACjB,UAAU,EAAE,MAAM,CAAC;IACnB,SAAS,EAAE,MAAM,CAAC;IAClB,MAAM,EAAE,MAAM,CAAC;IACf,QAAQ,EAAE,MAAM,CAAC;IACjB,IAAI,EAAE,MAAM,CAAC;IACb,UAAU,EAAE,MAAM,CAAC;IACnB,YAAY,EAAE,MAAM,CAAC;CACtB,CAAC;AAEF,MAAM,MAAM,gBAAgB,GAAG;IAC7B,SAAS,EAAE,MAAM,CAAC;IAClB,WAAW,EAAE,MAAM,CAAC;IACpB,UAAU,EAAE,MAAM,CAAC;IACnB,SAAS,EAAE,MAAM,CAAC;IAClB,MAAM,EAAE,MAAM,CAAC;IACf,QAAQ,EAAE,MAAM,CAAC;IACjB,IAAI,EAAE,MAAM,CAAC;IACb,UAAU,EAAE,MAAM,CAAC;CACpB,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"results.statistics.types.js","sourceRoot":"","sources":["../../../src/talkpilot/results/results.statistics.types.ts"],"names":[],"mappings":""}
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
export * from "./talkpilot/agents";
|
|
2
|
+
export * from "./talkpilot/clients";
|
|
2
3
|
export * from "./talkpilot/calls";
|
|
3
4
|
export * from "./talkpilot/clientAudioBuffers";
|
|
4
5
|
export * from "./talkpilot/clientsConfig";
|
|
@@ -7,6 +8,7 @@ export * from "./talkpilot/contextNotes";
|
|
|
7
8
|
export * from "./talkpilot/groups";
|
|
8
9
|
export * from "./talkpilot/phone_numbers";
|
|
9
10
|
export * from "./talkpilot/sessions";
|
|
11
|
+
export * from "./talkpilot/results";
|
|
10
12
|
export * from "./municipal/cities";
|
|
11
13
|
export * from "./municipal/departmentsSubjects";
|
|
12
14
|
export * from "./municipal/muniIssues";
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/test-utils/factories/index.ts"],"names":[],"mappings":"AAAA,cAAc,oBAAoB,CAAC;AACnC,cAAc,mBAAmB,CAAC;AAClC,cAAc,gCAAgC,CAAC;AAC/C,cAAc,2BAA2B,CAAC;AAC1C,cAAc,mBAAmB,CAAC;AAClC,cAAc,0BAA0B,CAAC;AACzC,cAAc,oBAAoB,CAAC;AACnC,cAAc,2BAA2B,CAAC;AAC1C,cAAc,sBAAsB,CAAC;AACrC,cAAc,oBAAoB,CAAC;AACnC,cAAc,iCAAiC,CAAC;AAChD,cAAc,wBAAwB,CAAC;AACvC,cAAc,qBAAqB,CAAC;AACpC,cAAc,qBAAqB,CAAC;AACpC,cAAc,mBAAmB,CAAC;AAClC,cAAc,2BAA2B,CAAC;AAC1C,cAAc,yBAAyB,CAAC;AACxC,cAAc,gCAAgC,CAAC"}
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/test-utils/factories/index.ts"],"names":[],"mappings":"AAAA,cAAc,oBAAoB,CAAC;AACnC,cAAc,qBAAqB,CAAC;AACpC,cAAc,mBAAmB,CAAC;AAClC,cAAc,gCAAgC,CAAC;AAC/C,cAAc,2BAA2B,CAAC;AAC1C,cAAc,mBAAmB,CAAC;AAClC,cAAc,0BAA0B,CAAC;AACzC,cAAc,oBAAoB,CAAC;AACnC,cAAc,2BAA2B,CAAC;AAC1C,cAAc,sBAAsB,CAAC;AACrC,cAAc,qBAAqB,CAAC;AACpC,cAAc,oBAAoB,CAAC;AACnC,cAAc,iCAAiC,CAAC;AAChD,cAAc,wBAAwB,CAAC;AACvC,cAAc,qBAAqB,CAAC;AACpC,cAAc,qBAAqB,CAAC;AACpC,cAAc,mBAAmB,CAAC;AAClC,cAAc,2BAA2B,CAAC;AAC1C,cAAc,yBAAyB,CAAC;AACxC,cAAc,gCAAgC,CAAC"}
|
|
@@ -15,6 +15,7 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
|
15
15
|
};
|
|
16
16
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
17
|
__exportStar(require("./talkpilot/agents"), exports);
|
|
18
|
+
__exportStar(require("./talkpilot/clients"), exports);
|
|
18
19
|
__exportStar(require("./talkpilot/calls"), exports);
|
|
19
20
|
__exportStar(require("./talkpilot/clientAudioBuffers"), exports);
|
|
20
21
|
__exportStar(require("./talkpilot/clientsConfig"), exports);
|
|
@@ -23,6 +24,7 @@ __exportStar(require("./talkpilot/contextNotes"), exports);
|
|
|
23
24
|
__exportStar(require("./talkpilot/groups"), exports);
|
|
24
25
|
__exportStar(require("./talkpilot/phone_numbers"), exports);
|
|
25
26
|
__exportStar(require("./talkpilot/sessions"), exports);
|
|
27
|
+
__exportStar(require("./talkpilot/results"), exports);
|
|
26
28
|
__exportStar(require("./municipal/cities"), exports);
|
|
27
29
|
__exportStar(require("./municipal/departmentsSubjects"), exports);
|
|
28
30
|
__exportStar(require("./municipal/muniIssues"), exports);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/test-utils/factories/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,qDAAmC;AACnC,oDAAkC;AAClC,iEAA+C;AAC/C,4DAA0C;AAC1C,oDAAkC;AAClC,2DAAyC;AACzC,qDAAmC;AACnC,4DAA0C;AAC1C,uDAAqC;AACrC,qDAAmC;AACnC,kEAAgD;AAChD,yDAAuC;AACvC,sDAAoC;AACpC,sDAAoC;AACpC,oDAAkC;AAClC,4DAA0C;AAC1C,0DAAwC;AACxC,iEAA+C"}
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/test-utils/factories/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,qDAAmC;AACnC,sDAAoC;AACpC,oDAAkC;AAClC,iEAA+C;AAC/C,4DAA0C;AAC1C,oDAAkC;AAClC,2DAAyC;AACzC,qDAAmC;AACnC,4DAA0C;AAC1C,uDAAqC;AACrC,sDAAoC;AACpC,qDAAmC;AACnC,kEAAgD;AAChD,yDAAuC;AACvC,sDAAoC;AACpC,sDAAoC;AACpC,oDAAkC;AAClC,4DAA0C;AAC1C,0DAAwC;AACxC,iEAA+C"}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { Factory } from "fishery";
|
|
2
|
+
import { ObjectId } from "mongodb";
|
|
3
|
+
import type { Client } from "../../../talkpilot";
|
|
4
|
+
export declare const clientFactory: Factory<Client & {
|
|
5
|
+
_id?: ObjectId;
|
|
6
|
+
}, any, Client & {
|
|
7
|
+
_id?: ObjectId;
|
|
8
|
+
}, import("fishery").DeepPartialObject<Client & {
|
|
9
|
+
_id?: ObjectId;
|
|
10
|
+
}>>;
|
|
11
|
+
export declare function createClient(overrides?: Partial<Client>): Client & {
|
|
12
|
+
_id?: ObjectId;
|
|
13
|
+
};
|
|
14
|
+
//# sourceMappingURL=clients.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"clients.d.ts","sourceRoot":"","sources":["../../../../src/test-utils/factories/talkpilot/clients.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,SAAS,CAAC;AAClC,OAAO,EAAE,QAAQ,EAAE,MAAM,SAAS,CAAC;AAEnC,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,oBAAoB,CAAC;AAEjD,eAAO,MAAM,aAAa;UAAmC,QAAQ;;UAAR,QAAQ;;UAAR,QAAQ;GASpE,CAAC;AAEF,wBAAgB,YAAY,CAC1B,SAAS,CAAC,EAAE,OAAO,CAAC,MAAM,CAAC,GAC1B,MAAM,GAAG;IAAE,GAAG,CAAC,EAAE,QAAQ,CAAA;CAAE,CAE7B"}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.clientFactory = void 0;
|
|
4
|
+
exports.createClient = createClient;
|
|
5
|
+
const fishery_1 = require("fishery");
|
|
6
|
+
const mongodb_1 = require("mongodb");
|
|
7
|
+
const faker_1 = require("@faker-js/faker");
|
|
8
|
+
exports.clientFactory = fishery_1.Factory.define(() => ({
|
|
9
|
+
_id: new mongodb_1.ObjectId(),
|
|
10
|
+
clientId: faker_1.faker.string.uuid(),
|
|
11
|
+
isActive: true,
|
|
12
|
+
credits: faker_1.faker.number.int({ min: 0, max: 1000 }),
|
|
13
|
+
createdAt: new Date(),
|
|
14
|
+
updatedAt: new Date(),
|
|
15
|
+
}));
|
|
16
|
+
function createClient(overrides) {
|
|
17
|
+
return exports.clientFactory.build(overrides);
|
|
18
|
+
}
|
|
19
|
+
//# sourceMappingURL=clients.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"clients.js","sourceRoot":"","sources":["../../../../src/test-utils/factories/talkpilot/clients.ts"],"names":[],"mappings":";;;AAgBA,oCAIC;AApBD,qCAAkC;AAClC,qCAAmC;AACnC,2CAAwC;AAG3B,QAAA,aAAa,GAAG,iBAAO,CAAC,MAAM,CACzC,GAAG,EAAE,CAAC,CAAC;IACL,GAAG,EAAE,IAAI,kBAAQ,EAAE;IACnB,QAAQ,EAAE,aAAK,CAAC,MAAM,CAAC,IAAI,EAAE;IAC7B,QAAQ,EAAE,IAAI;IACd,OAAO,EAAE,aAAK,CAAC,MAAM,CAAC,GAAG,CAAC,EAAE,GAAG,EAAE,CAAC,EAAE,GAAG,EAAE,IAAI,EAAE,CAAC;IAChD,SAAS,EAAE,IAAI,IAAI,EAAE;IACrB,SAAS,EAAE,IAAI,IAAI,EAAE;CACtB,CAAC,CACH,CAAC;AAEF,SAAgB,YAAY,CAC1B,SAA2B;IAE3B,OAAO,qBAAa,CAAC,KAAK,CAAC,SAAS,CAAC,CAAC;AACxC,CAAC"}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { Factory } from "fishery";
|
|
2
|
+
import { ObjectId } from "mongodb";
|
|
3
|
+
import type { Result, CallResult } from "../../../talkpilot";
|
|
4
|
+
export declare const callResultFactory: Factory<CallResult, any, CallResult, import("fishery").DeepPartialObject<CallResult>>;
|
|
5
|
+
export declare function createCallResult(overrides?: Partial<CallResult>): CallResult;
|
|
6
|
+
export declare const resultFactory: Factory<Result & {
|
|
7
|
+
_id?: ObjectId;
|
|
8
|
+
}, any, Result & {
|
|
9
|
+
_id?: ObjectId;
|
|
10
|
+
}, import("fishery").DeepPartialObject<Result & {
|
|
11
|
+
_id?: ObjectId;
|
|
12
|
+
}>>;
|
|
13
|
+
export declare function createResult(overrides?: Partial<Result>): Result & {
|
|
14
|
+
_id?: ObjectId;
|
|
15
|
+
};
|
|
16
|
+
//# sourceMappingURL=results.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"results.d.ts","sourceRoot":"","sources":["../../../../src/test-utils/factories/talkpilot/results.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,SAAS,CAAC;AAClC,OAAO,EAAE,QAAQ,EAAE,MAAM,SAAS,CAAC;AAEnC,OAAO,KAAK,EAAE,MAAM,EAAE,UAAU,EAAE,MAAM,oBAAoB,CAAC;AAE7D,eAAO,MAAM,iBAAiB,uFAe3B,CAAC;AAEJ,wBAAgB,gBAAgB,CAAC,SAAS,CAAC,EAAE,OAAO,CAAC,UAAU,CAAC,GAAG,UAAU,CAE5E;AAED,eAAO,MAAM,aAAa;UAAmC,QAAQ;;UAAR,QAAQ;;UAAR,QAAQ;GAUpE,CAAC;AAEF,wBAAgB,YAAY,CAC1B,SAAS,CAAC,EAAE,OAAO,CAAC,MAAM,CAAC,GAC1B,MAAM,GAAG;IAAE,GAAG,CAAC,EAAE,QAAQ,CAAA;CAAE,CAE7B"}
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.resultFactory = exports.callResultFactory = void 0;
|
|
4
|
+
exports.createCallResult = createCallResult;
|
|
5
|
+
exports.createResult = createResult;
|
|
6
|
+
const fishery_1 = require("fishery");
|
|
7
|
+
const mongodb_1 = require("mongodb");
|
|
8
|
+
const faker_1 = require("@faker-js/faker");
|
|
9
|
+
exports.callResultFactory = fishery_1.Factory.define(() => ({
|
|
10
|
+
callSid: `CA${faker_1.faker.string.alphanumeric(32)}`,
|
|
11
|
+
status: "completed",
|
|
12
|
+
date: new Date(),
|
|
13
|
+
statuses: ["completed"],
|
|
14
|
+
userAnswer: null,
|
|
15
|
+
color: null,
|
|
16
|
+
name: null,
|
|
17
|
+
callLength: "60 seconds",
|
|
18
|
+
answeredBy: null,
|
|
19
|
+
to: faker_1.faker.phone.number(),
|
|
20
|
+
from: faker_1.faker.phone.number(),
|
|
21
|
+
transcription: [],
|
|
22
|
+
flowId: new mongodb_1.ObjectId().toString(),
|
|
23
|
+
recordingUrl: null,
|
|
24
|
+
}));
|
|
25
|
+
function createCallResult(overrides) {
|
|
26
|
+
return exports.callResultFactory.build(overrides);
|
|
27
|
+
}
|
|
28
|
+
exports.resultFactory = fishery_1.Factory.define(() => ({
|
|
29
|
+
_id: new mongodb_1.ObjectId(),
|
|
30
|
+
calls: [],
|
|
31
|
+
clientId: faker_1.faker.string.uuid(),
|
|
32
|
+
date: new Date(),
|
|
33
|
+
runId: `run_${new mongodb_1.ObjectId().toString()}`,
|
|
34
|
+
sessionId: "incomingCall",
|
|
35
|
+
sessionName: "incomingCall",
|
|
36
|
+
}));
|
|
37
|
+
function createResult(overrides) {
|
|
38
|
+
return exports.resultFactory.build(overrides);
|
|
39
|
+
}
|
|
40
|
+
//# sourceMappingURL=results.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"results.js","sourceRoot":"","sources":["../../../../src/test-utils/factories/talkpilot/results.ts"],"names":[],"mappings":";;;AAsBA,4CAEC;AAcD,oCAIC;AA1CD,qCAAkC;AAClC,qCAAmC;AACnC,2CAAwC;AAG3B,QAAA,iBAAiB,GAAG,iBAAO,CAAC,MAAM,CAAa,GAAG,EAAE,CAAC,CAAC;IACjE,OAAO,EAAE,KAAK,aAAK,CAAC,MAAM,CAAC,YAAY,CAAC,EAAE,CAAC,EAAE;IAC7C,MAAM,EAAE,WAAW;IACnB,IAAI,EAAE,IAAI,IAAI,EAAE;IAChB,QAAQ,EAAE,CAAC,WAAW,CAAC;IACvB,UAAU,EAAE,IAAI;IAChB,KAAK,EAAE,IAAI;IACX,IAAI,EAAE,IAAI;IACV,UAAU,EAAE,YAAY;IACxB,UAAU,EAAE,IAAI;IAChB,EAAE,EAAE,aAAK,CAAC,KAAK,CAAC,MAAM,EAAE;IACxB,IAAI,EAAE,aAAK,CAAC,KAAK,CAAC,MAAM,EAAE;IAC1B,aAAa,EAAE,EAAE;IACjB,MAAM,EAAE,IAAI,kBAAQ,EAAE,CAAC,QAAQ,EAAE;IACjC,YAAY,EAAE,IAAI;CACnB,CAAC,CAAC,CAAC;AAEJ,SAAgB,gBAAgB,CAAC,SAA+B;IAC9D,OAAO,yBAAiB,CAAC,KAAK,CAAC,SAAS,CAAC,CAAC;AAC5C,CAAC;AAEY,QAAA,aAAa,GAAG,iBAAO,CAAC,MAAM,CACzC,GAAG,EAAE,CAAC,CAAC;IACL,GAAG,EAAE,IAAI,kBAAQ,EAAE;IACnB,KAAK,EAAE,EAAE;IACT,QAAQ,EAAE,aAAK,CAAC,MAAM,CAAC,IAAI,EAAE;IAC7B,IAAI,EAAE,IAAI,IAAI,EAAE;IAChB,KAAK,EAAE,OAAO,IAAI,kBAAQ,EAAE,CAAC,QAAQ,EAAE,EAAE;IACzC,SAAS,EAAE,cAAc;IACzB,WAAW,EAAE,cAAc;CAC5B,CAAC,CACH,CAAC;AAEF,SAAgB,YAAY,CAC1B,SAA2B;IAE3B,OAAO,qBAAa,CAAC,KAAK,CAAC,SAAS,CAAC,CAAC;AACxC,CAAC"}
|
package/package.json
CHANGED
|
@@ -0,0 +1,91 @@
|
|
|
1
|
+
import {
|
|
2
|
+
insertAuditLog,
|
|
3
|
+
getAuditLogsCollection,
|
|
4
|
+
findAuditLogs,
|
|
5
|
+
countAuditLogs,
|
|
6
|
+
} from "../auditLogs.getters";
|
|
7
|
+
import { AuditLogEntry } from "../auditLogs.types";
|
|
8
|
+
|
|
9
|
+
describe("db.auditLogs", () => {
|
|
10
|
+
describe("insertAuditLog", () => {
|
|
11
|
+
it("should write an entry that can be read back with all fields intact", async () => {
|
|
12
|
+
const entry: AuditLogEntry = {
|
|
13
|
+
clientId: "deletedClient1",
|
|
14
|
+
adminEmail: "admin@callai.co.il",
|
|
15
|
+
action: "delete",
|
|
16
|
+
timestamp: new Date("2026-07-15T10:00:00.000Z"),
|
|
17
|
+
};
|
|
18
|
+
|
|
19
|
+
await insertAuditLog(entry);
|
|
20
|
+
|
|
21
|
+
const stored = await getAuditLogsCollection().findOne({
|
|
22
|
+
clientId: "deletedClient1",
|
|
23
|
+
});
|
|
24
|
+
expect(stored).toMatchObject(entry);
|
|
25
|
+
});
|
|
26
|
+
});
|
|
27
|
+
|
|
28
|
+
describe("findAuditLogs", () => {
|
|
29
|
+
const seed = async () => {
|
|
30
|
+
await insertAuditLog({
|
|
31
|
+
clientId: "clientA",
|
|
32
|
+
adminEmail: "admin@callai.co.il",
|
|
33
|
+
action: "delete",
|
|
34
|
+
timestamp: new Date("2026-01-01T00:00:00.000Z"),
|
|
35
|
+
});
|
|
36
|
+
await insertAuditLog({
|
|
37
|
+
clientId: "clientB",
|
|
38
|
+
adminEmail: "admin@callai.co.il",
|
|
39
|
+
action: "delete",
|
|
40
|
+
timestamp: new Date("2026-02-01T00:00:00.000Z"),
|
|
41
|
+
});
|
|
42
|
+
await insertAuditLog({
|
|
43
|
+
clientId: "clientC",
|
|
44
|
+
adminEmail: "admin@callai.co.il",
|
|
45
|
+
action: "delete",
|
|
46
|
+
timestamp: new Date("2026-03-01T00:00:00.000Z"),
|
|
47
|
+
});
|
|
48
|
+
};
|
|
49
|
+
|
|
50
|
+
it("should return a page of entries, newest first", async () => {
|
|
51
|
+
await seed();
|
|
52
|
+
|
|
53
|
+
const page = await findAuditLogs({ limit: 2 });
|
|
54
|
+
|
|
55
|
+
expect(page).toHaveLength(2);
|
|
56
|
+
expect(page.map((e) => e.clientId)).toEqual(["clientC", "clientB"]);
|
|
57
|
+
});
|
|
58
|
+
|
|
59
|
+
it("should skip entries for later pages", async () => {
|
|
60
|
+
await seed();
|
|
61
|
+
|
|
62
|
+
const page = await findAuditLogs({ skip: 2, limit: 2 });
|
|
63
|
+
|
|
64
|
+
expect(page).toHaveLength(1);
|
|
65
|
+
expect(page[0].clientId).toBe("clientA");
|
|
66
|
+
});
|
|
67
|
+
});
|
|
68
|
+
|
|
69
|
+
describe("countAuditLogs", () => {
|
|
70
|
+
it("should return the total number of entries regardless of pagination", async () => {
|
|
71
|
+
await insertAuditLog({
|
|
72
|
+
clientId: "clientA",
|
|
73
|
+
adminEmail: "admin@callai.co.il",
|
|
74
|
+
action: "delete",
|
|
75
|
+
timestamp: new Date(),
|
|
76
|
+
});
|
|
77
|
+
await insertAuditLog({
|
|
78
|
+
clientId: "clientB",
|
|
79
|
+
adminEmail: "admin@callai.co.il",
|
|
80
|
+
action: "delete",
|
|
81
|
+
timestamp: new Date(),
|
|
82
|
+
});
|
|
83
|
+
|
|
84
|
+
expect(await countAuditLogs()).toBe(2);
|
|
85
|
+
});
|
|
86
|
+
|
|
87
|
+
it("should return 0 when there are no entries", async () => {
|
|
88
|
+
expect(await countAuditLogs()).toBe(0);
|
|
89
|
+
});
|
|
90
|
+
});
|
|
91
|
+
});
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import { Collection } from "mongodb";
|
|
2
|
+
import { getDb } from "../index";
|
|
3
|
+
import { applyQueryOptions, QueryOptions } from "../utils/query.utils";
|
|
4
|
+
import { AuditLogDoc, AuditLogEntry } from "./auditLogs.types";
|
|
5
|
+
|
|
6
|
+
export const getAuditLogsCollection = (): Collection<AuditLogEntry> => {
|
|
7
|
+
return getDb().collection<AuditLogEntry>("auditLogs");
|
|
8
|
+
};
|
|
9
|
+
|
|
10
|
+
export const insertAuditLog = async (entry: AuditLogEntry): Promise<void> => {
|
|
11
|
+
await getAuditLogsCollection().insertOne(entry);
|
|
12
|
+
};
|
|
13
|
+
|
|
14
|
+
export const findAuditLogs = async (
|
|
15
|
+
options: Pick<QueryOptions, "skip"> & Required<Pick<QueryOptions, "limit">>,
|
|
16
|
+
): Promise<AuditLogDoc[]> => {
|
|
17
|
+
const cursor = getAuditLogsCollection().find({});
|
|
18
|
+
return applyQueryOptions(cursor, {
|
|
19
|
+
sort: { timestamp: -1 },
|
|
20
|
+
...options,
|
|
21
|
+
}).toArray();
|
|
22
|
+
};
|
|
23
|
+
|
|
24
|
+
export const countAuditLogs = async (): Promise<number> => {
|
|
25
|
+
return getAuditLogsCollection().countDocuments({});
|
|
26
|
+
};
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { WithId } from "mongodb";
|
|
2
|
+
|
|
3
|
+
export type AuditLogEntry = {
|
|
4
|
+
clientId: string;
|
|
5
|
+
adminEmail: string;
|
|
6
|
+
action: "delete";
|
|
7
|
+
timestamp: Date;
|
|
8
|
+
allSucceeded?: boolean;
|
|
9
|
+
failedCollections?: string[];
|
|
10
|
+
};
|
|
11
|
+
|
|
12
|
+
export type AuditLogDoc = WithId<AuditLogEntry>;
|