@talkpilot/core-db 1.3.12 → 1.3.14

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.
Files changed (42) hide show
  1. package/.cursor/rules/development.mdc +65 -65
  2. package/DEVELOPMENT.md +141 -141
  3. package/README.md +312 -297
  4. package/dist/municipal/tickets/tickets.statistics.getters.d.ts.map +1 -1
  5. package/dist/municipal/tickets/tickets.statistics.getters.js +6 -2
  6. package/dist/municipal/tickets/tickets.statistics.getters.js.map +1 -1
  7. package/dist/talkpilot/flows/flows.schema.d.ts +3 -0
  8. package/dist/talkpilot/flows/flows.schema.d.ts.map +1 -1
  9. package/dist/talkpilot/flows/flows.schema.js +1 -0
  10. package/dist/talkpilot/flows/flows.schema.js.map +1 -1
  11. package/dist/talkpilot/flows/flows.types.d.ts +2 -0
  12. package/dist/talkpilot/flows/flows.types.d.ts.map +1 -1
  13. package/dist/talkpilot/subscriptions/subscriptions.utils.d.ts +4 -0
  14. package/dist/talkpilot/subscriptions/subscriptions.utils.d.ts.map +1 -0
  15. package/dist/talkpilot/subscriptions/subscriptions.utils.js +20 -0
  16. package/dist/talkpilot/subscriptions/subscriptions.utils.js.map +1 -0
  17. package/jest.config.js +20 -20
  18. package/package.json +46 -46
  19. package/src/municipal/muniIssues/__tests__/muniIssues.setters.spec.ts +94 -94
  20. package/src/municipal/tickets/__tests__/tickets.statistics.spec.ts +99 -99
  21. package/src/municipal/tickets/index.ts +9 -9
  22. package/src/municipal/tickets/tickets.statistics.aggregation.ts +110 -110
  23. package/src/municipal/tickets/tickets.statistics.getters.ts +145 -132
  24. package/src/municipal/tickets/tickets.types.ts +54 -54
  25. package/src/talkpilot/calls/__tests__/calls.statistics.spec.ts +483 -481
  26. package/src/talkpilot/calls/calls.statistics.getters.ts +668 -668
  27. package/src/talkpilot/calls/calls.statistics.types.ts +48 -48
  28. package/src/talkpilot/clientsConfig/clientsConfig.types.ts +127 -127
  29. package/src/talkpilot/contextNotes/__tests__/contextNotes.getters.spec.ts +217 -217
  30. package/src/talkpilot/contextNotes/contextNotes.getters.ts +85 -85
  31. package/src/talkpilot/flows/__tests__/flows.schema.spec.ts +3 -0
  32. package/src/talkpilot/flows/flows.schema.ts +1 -0
  33. package/src/talkpilot/flows/flows.types.ts +2 -0
  34. package/src/talkpilot/products/__tests__/products.getters.spec.ts +44 -44
  35. package/src/test-utils/factories/talkpilot/contextNotes.ts +40 -40
  36. package/src/utils/date.utils.ts +126 -126
  37. package/tsconfig.json +23 -23
  38. package/README_OLD.md +0 -160
  39. package/dist/talkpilot/calls/calls.dashboard.d.ts +0 -3
  40. package/dist/talkpilot/calls/calls.dashboard.d.ts.map +0 -1
  41. package/dist/talkpilot/calls/calls.dashboard.js +0 -191
  42. package/dist/talkpilot/calls/calls.dashboard.js.map +0 -1
@@ -1,132 +1,145 @@
1
- import { CityName } from "../utils/types";
2
- import {
3
- DAY_MS,
4
- endOfCalendarDayInTz,
5
- startOfCalendarDayInTz,
6
- } from "../../utils/date.utils";
7
- import { DEFAULT_LOOKBACK_DAYS } from "./tickets.constants";
8
- import {
9
- isDraftTicketExpr,
10
- runTicketStatsAggregate,
11
- subjectResolutionStages,
12
- ticketsWithCallSidMatch,
13
- } from "./tickets.statistics.aggregation";
14
- import type {
15
- TicketStatsDateRange,
16
- TicketStatsDateScope,
17
- TicketSubjectRow,
18
- } from "./tickets.types";
19
-
20
- export const resolveTicketStatsDateRange = (
21
- dateScope?: TicketStatsDateScope,
22
- ): TicketStatsDateRange => {
23
- const to = dateScope?.to ?? new Date();
24
- const from =
25
- dateScope?.from ?? new Date(to.getTime() - DEFAULT_LOOKBACK_DAYS * DAY_MS);
26
- return { from, to };
27
- };
28
-
29
- export const ticketStatsDateScopeFromYmd = (
30
- startStr: string,
31
- endStr: string,
32
- timezone: string,
33
- ): TicketStatsDateScope => ({
34
- from: startOfCalendarDayInTz(startStr, timezone),
35
- to: endOfCalendarDayInTz(endStr, timezone),
36
- });
37
-
38
- /** @deprecated Use findCallSidTicketCountsByCity instead. */
39
- export const findCallSidsWithTicketsByCity = async (
40
- cityName: CityName,
41
- dateScope?: TicketStatsDateScope,
42
- ): Promise<string[]> => {
43
- const rows = await runTicketStatsAggregate<{ _id: unknown }>([
44
- {
45
- $match: ticketsWithCallSidMatch(
46
- cityName,
47
- resolveTicketStatsDateRange(dateScope),
48
- ),
49
- },
50
- { $group: { _id: "$callSid" } },
51
- ]);
52
- return rows
53
- .filter((r) => r._id != null && r._id !== "")
54
- .map((r) => String(r._id));
55
- };
56
-
57
- export const findCallSidTicketCountsByCity = async (
58
- cityName: CityName,
59
- dateScope?: TicketStatsDateScope,
60
- ): Promise<Map<string, number>> => {
61
- const rows = await runTicketStatsAggregate<{
62
- _id: unknown;
63
- ticketCount: number;
64
- }>([
65
- {
66
- $match: ticketsWithCallSidMatch(
67
- cityName,
68
- resolveTicketStatsDateRange(dateScope),
69
- ),
70
- },
71
- { $group: { _id: "$callSid", ticketCount: { $sum: 1 } } },
72
- ]);
73
- return new Map(
74
- rows
75
- .filter((r) => r._id != null && r._id !== "")
76
- .map((r) => [String(r._id), r.ticketCount]),
77
- );
78
- };
79
-
80
- /** @deprecated Use findCallSidDraftTicketCountsByCity instead. */
81
- export const findCallSidsWithDraftTicketsByCity = async (
82
- cityName: CityName,
83
- dateScope?: TicketStatsDateScope,
84
- ): Promise<string[]> => {
85
- const rows = await runTicketStatsAggregate<{ _id: unknown }>([
86
- { $match: ticketsWithCallSidMatch(cityName, resolveTicketStatsDateRange(dateScope)) },
87
- { $match: { $expr: isDraftTicketExpr } },
88
- { $group: { _id: "$callSid" } },
89
- ]);
90
- return rows
91
- .filter((r) => r._id != null && r._id !== "")
92
- .map((r) => String(r._id));
93
- };
94
-
95
- export const findCallSidDraftTicketCountsByCity = async (
96
- cityName: CityName,
97
- dateScope?: TicketStatsDateScope,
98
- ): Promise<Map<string, number>> => {
99
- const rows = await runTicketStatsAggregate<{ _id: unknown; ticketCount: number }>([
100
- { $match: ticketsWithCallSidMatch(cityName, resolveTicketStatsDateRange(dateScope)) },
101
- { $match: { $expr: isDraftTicketExpr } },
102
- { $group: { _id: "$callSid", ticketCount: { $sum: 1 } } },
103
- ]);
104
- return new Map(
105
- rows
106
- .filter((r) => r._id != null && r._id !== "")
107
- .map((r) => [String(r._id), r.ticketCount]),
108
- );
109
- };
110
-
111
- export const findTicketSubjectRows = async (
112
- cityName: CityName,
113
- dateScope?: TicketStatsDateScope,
114
- ): Promise<TicketSubjectRow[]> => {
115
- const rows = await runTicketStatsAggregate<{
116
- callSid: unknown;
117
- subject: unknown;
118
- }>([
119
- {
120
- $match: ticketsWithCallSidMatch(
121
- cityName,
122
- resolveTicketStatsDateRange(dateScope),
123
- ),
124
- },
125
- ...subjectResolutionStages(cityName),
126
- { $project: { _id: 0, callSid: 1, subject: 1 } },
127
- ]);
128
- return rows.map((r) => ({
129
- callSid: String(r.callSid),
130
- subject: String(r.subject),
131
- }));
132
- };
1
+ import { CityName } from "../utils/types";
2
+ import {
3
+ DAY_MS,
4
+ endOfCalendarDayInTz,
5
+ startOfCalendarDayInTz,
6
+ } from "../../utils/date.utils";
7
+ import { DEFAULT_LOOKBACK_DAYS } from "./tickets.constants";
8
+ import {
9
+ isDraftTicketExpr,
10
+ runTicketStatsAggregate,
11
+ subjectResolutionStages,
12
+ ticketsWithCallSidMatch,
13
+ } from "./tickets.statistics.aggregation";
14
+ import type {
15
+ TicketStatsDateRange,
16
+ TicketStatsDateScope,
17
+ TicketSubjectRow,
18
+ } from "./tickets.types";
19
+
20
+ export const resolveTicketStatsDateRange = (
21
+ dateScope?: TicketStatsDateScope,
22
+ ): TicketStatsDateRange => {
23
+ const to = dateScope?.to ?? new Date();
24
+ const from =
25
+ dateScope?.from ?? new Date(to.getTime() - DEFAULT_LOOKBACK_DAYS * DAY_MS);
26
+ return { from, to };
27
+ };
28
+
29
+ export const ticketStatsDateScopeFromYmd = (
30
+ startStr: string,
31
+ endStr: string,
32
+ timezone: string,
33
+ ): TicketStatsDateScope => ({
34
+ from: startOfCalendarDayInTz(startStr, timezone),
35
+ to: endOfCalendarDayInTz(endStr, timezone),
36
+ });
37
+
38
+ /** @deprecated Use findCallSidTicketCountsByCity instead. */
39
+ export const findCallSidsWithTicketsByCity = async (
40
+ cityName: CityName,
41
+ dateScope?: TicketStatsDateScope,
42
+ ): Promise<string[]> => {
43
+ const rows = await runTicketStatsAggregate<{ _id: unknown }>([
44
+ {
45
+ $match: ticketsWithCallSidMatch(
46
+ cityName,
47
+ resolveTicketStatsDateRange(dateScope),
48
+ ),
49
+ },
50
+ { $group: { _id: "$callSid" } },
51
+ ]);
52
+ return rows
53
+ .filter((r) => r._id != null && r._id !== "")
54
+ .map((r) => String(r._id));
55
+ };
56
+
57
+ export const findCallSidTicketCountsByCity = async (
58
+ cityName: CityName,
59
+ dateScope?: TicketStatsDateScope,
60
+ ): Promise<Map<string, number>> => {
61
+ const rows = await runTicketStatsAggregate<{
62
+ _id: unknown;
63
+ ticketCount: number;
64
+ }>([
65
+ {
66
+ $match: ticketsWithCallSidMatch(
67
+ cityName,
68
+ resolveTicketStatsDateRange(dateScope),
69
+ ),
70
+ },
71
+ { $group: { _id: "$callSid", ticketCount: { $sum: 1 } } },
72
+ ]);
73
+ return new Map(
74
+ rows
75
+ .filter((r) => r._id != null && r._id !== "")
76
+ .map((r) => [String(r._id), r.ticketCount]),
77
+ );
78
+ };
79
+
80
+ /** @deprecated Use findCallSidDraftTicketCountsByCity instead. */
81
+ export const findCallSidsWithDraftTicketsByCity = async (
82
+ cityName: CityName,
83
+ dateScope?: TicketStatsDateScope,
84
+ ): Promise<string[]> => {
85
+ const rows = await runTicketStatsAggregate<{ _id: unknown }>([
86
+ {
87
+ $match: ticketsWithCallSidMatch(
88
+ cityName,
89
+ resolveTicketStatsDateRange(dateScope),
90
+ ),
91
+ },
92
+ { $match: { $expr: isDraftTicketExpr } },
93
+ { $group: { _id: "$callSid" } },
94
+ ]);
95
+ return rows
96
+ .filter((r) => r._id != null && r._id !== "")
97
+ .map((r) => String(r._id));
98
+ };
99
+
100
+ export const findCallSidDraftTicketCountsByCity = async (
101
+ cityName: CityName,
102
+ dateScope?: TicketStatsDateScope,
103
+ ): Promise<Map<string, number>> => {
104
+ const rows = await runTicketStatsAggregate<{
105
+ _id: unknown;
106
+ ticketCount: number;
107
+ }>([
108
+ {
109
+ $match: ticketsWithCallSidMatch(
110
+ cityName,
111
+ resolveTicketStatsDateRange(dateScope),
112
+ ),
113
+ },
114
+ { $match: { $expr: isDraftTicketExpr } },
115
+ { $group: { _id: "$callSid", ticketCount: { $sum: 1 } } },
116
+ ]);
117
+ return new Map(
118
+ rows
119
+ .filter((r) => r._id != null && r._id !== "")
120
+ .map((r) => [String(r._id), r.ticketCount]),
121
+ );
122
+ };
123
+
124
+ export const findTicketSubjectRows = async (
125
+ cityName: CityName,
126
+ dateScope?: TicketStatsDateScope,
127
+ ): Promise<TicketSubjectRow[]> => {
128
+ const rows = await runTicketStatsAggregate<{
129
+ callSid: unknown;
130
+ subject: unknown;
131
+ }>([
132
+ {
133
+ $match: ticketsWithCallSidMatch(
134
+ cityName,
135
+ resolveTicketStatsDateRange(dateScope),
136
+ ),
137
+ },
138
+ ...subjectResolutionStages(cityName),
139
+ { $project: { _id: 0, callSid: 1, subject: 1 } },
140
+ ]);
141
+ return rows.map((r) => ({
142
+ callSid: String(r.callSid),
143
+ subject: String(r.subject),
144
+ }));
145
+ };
@@ -1,54 +1,54 @@
1
- import { ObjectId, WithId } from "mongodb";
2
-
3
- import { CityName } from "../utils/types";
4
-
5
- export type Ticket = {
6
- _id: ObjectId;
7
- createdAt: Date;
8
- updatedAt: Date;
9
- callSid?: string;
10
- isDraft?: boolean;
11
- cityName: CityName;
12
- externalCallFields: {
13
- first_name?: string;
14
- last_name?: string;
15
- event_description?: string;
16
- street?: string;
17
- house_number?: string;
18
- event_subject_id?: string;
19
- event_sub_subject_id?: string;
20
- event_sub_subject_id2?: string | null;
21
- call_number?: string;
22
- status?: number;
23
- error?: string;
24
- image1?: string;
25
- image2?: string;
26
- image3?: string;
27
- file1?: string;
28
- file2?: string;
29
- file3?: string;
30
- };
31
- guestJwt?: string;
32
- };
33
-
34
- export type TicketDoc = WithId<Ticket>;
35
-
36
- export type SubjectItem = {
37
- subject: string;
38
- count: number;
39
- };
40
-
41
- export type TicketSubjectRow = {
42
- callSid: string;
43
- subject: string;
44
- };
45
-
46
- export type TicketStatsDateScope = {
47
- from?: Date;
48
- to?: Date;
49
- };
50
-
51
- export type TicketStatsDateRange = {
52
- from: Date;
53
- to: Date;
54
- };
1
+ import { ObjectId, WithId } from "mongodb";
2
+
3
+ import { CityName } from "../utils/types";
4
+
5
+ export type Ticket = {
6
+ _id: ObjectId;
7
+ createdAt: Date;
8
+ updatedAt: Date;
9
+ callSid?: string;
10
+ isDraft?: boolean;
11
+ cityName: CityName;
12
+ externalCallFields: {
13
+ first_name?: string;
14
+ last_name?: string;
15
+ event_description?: string;
16
+ street?: string;
17
+ house_number?: string;
18
+ event_subject_id?: string;
19
+ event_sub_subject_id?: string;
20
+ event_sub_subject_id2?: string | null;
21
+ call_number?: string;
22
+ status?: number;
23
+ error?: string;
24
+ image1?: string;
25
+ image2?: string;
26
+ image3?: string;
27
+ file1?: string;
28
+ file2?: string;
29
+ file3?: string;
30
+ };
31
+ guestJwt?: string;
32
+ };
33
+
34
+ export type TicketDoc = WithId<Ticket>;
35
+
36
+ export type SubjectItem = {
37
+ subject: string;
38
+ count: number;
39
+ };
40
+
41
+ export type TicketSubjectRow = {
42
+ callSid: string;
43
+ subject: string;
44
+ };
45
+
46
+ export type TicketStatsDateScope = {
47
+ from?: Date;
48
+ to?: Date;
49
+ };
50
+
51
+ export type TicketStatsDateRange = {
52
+ from: Date;
53
+ to: Date;
54
+ };