@talkpilot/core-db 1.3.6 → 1.3.8

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 (79) hide show
  1. package/.cursor/rules/development.mdc +65 -65
  2. package/DEVELOPMENT.md +141 -141
  3. package/README.md +243 -190
  4. package/README_OLD.md +160 -160
  5. package/dist/municipal/tickets/tickets.statistics.getters.d.ts +4 -0
  6. package/dist/municipal/tickets/tickets.statistics.getters.d.ts.map +1 -1
  7. package/dist/municipal/tickets/tickets.statistics.getters.js +30 -3
  8. package/dist/municipal/tickets/tickets.statistics.getters.js.map +1 -1
  9. package/dist/talkpilot/calls/calls.dashboard.d.ts +3 -0
  10. package/dist/talkpilot/calls/calls.dashboard.d.ts.map +1 -0
  11. package/dist/talkpilot/calls/calls.dashboard.js +191 -0
  12. package/dist/talkpilot/calls/calls.dashboard.js.map +1 -0
  13. package/dist/talkpilot/calls/calls.statistics.getters.js +12 -15
  14. package/dist/talkpilot/calls/calls.statistics.getters.js.map +1 -1
  15. package/dist/talkpilot/calls/calls.statistics.types.d.ts +4 -1
  16. package/dist/talkpilot/calls/calls.statistics.types.d.ts.map +1 -1
  17. package/dist/talkpilot/flows/flows.schema.d.ts +3 -0
  18. package/dist/talkpilot/flows/flows.schema.d.ts.map +1 -1
  19. package/dist/talkpilot/flows/flows.schema.js +1 -0
  20. package/dist/talkpilot/flows/flows.schema.js.map +1 -1
  21. package/dist/talkpilot/flows/flows.types.d.ts +1 -0
  22. package/dist/talkpilot/flows/flows.types.d.ts.map +1 -1
  23. package/jest.config.js +20 -20
  24. package/package.json +46 -46
  25. package/src/connection.ts +54 -54
  26. package/src/index.ts +26 -26
  27. package/src/municipal/index.ts +22 -22
  28. package/src/municipal/muniIssues/__tests__/muniIssues.setters.spec.ts +92 -92
  29. package/src/municipal/muniIssues/__tests__/muniIssues.setup.spec.ts +92 -92
  30. package/src/municipal/muniIssues/index.ts +17 -17
  31. package/src/municipal/muniIssues/muniIssues.constants.ts +18 -18
  32. package/src/municipal/muniIssues/muniIssues.getters.ts +24 -24
  33. package/src/municipal/muniIssues/muniIssues.schema.ts +66 -66
  34. package/src/municipal/muniIssues/muniIssues.setters.ts +24 -24
  35. package/src/municipal/muniIssues/muniIssues.setup.ts +65 -65
  36. package/src/municipal/muniIssues/muniIssues.types.ts +37 -37
  37. package/src/municipal/tickets/__tests__/tickets.getters.spec.ts +30 -30
  38. package/src/municipal/tickets/__tests__/tickets.statistics.spec.ts +68 -51
  39. package/src/municipal/tickets/index.ts +3 -3
  40. package/src/municipal/tickets/tickets.constants.ts +8 -8
  41. package/src/municipal/tickets/tickets.getters.ts +121 -121
  42. package/src/municipal/tickets/tickets.statistics.aggregation.ts +96 -96
  43. package/src/municipal/tickets/tickets.statistics.getters.ts +109 -71
  44. package/src/municipal/tickets/tickets.types.ts +53 -53
  45. package/src/talkpilot/calls/__tests__/calls.dashboard.spec.ts +149 -149
  46. package/src/talkpilot/calls/__tests__/calls.statistics.spec.ts +351 -344
  47. package/src/talkpilot/calls/calls.constants.ts +20 -20
  48. package/src/talkpilot/calls/calls.statistics.getters.ts +587 -587
  49. package/src/talkpilot/calls/calls.statistics.types.ts +47 -44
  50. package/src/talkpilot/calls/calls.types.ts +119 -119
  51. package/src/talkpilot/calls/dashboard/calls.dashboard.ts +292 -292
  52. package/src/talkpilot/calls/dashboard/calls.dashboard.types.ts +57 -57
  53. package/src/talkpilot/calls/index.ts +6 -6
  54. package/src/talkpilot/clientsConfig/__tests__/clientsConfig.spec.ts +190 -190
  55. package/src/talkpilot/contextNotes/__tests__/contextNotes.getters.spec.ts +176 -176
  56. package/src/talkpilot/contextNotes/contextNotes.getters.ts +86 -86
  57. package/src/talkpilot/contextNotes/contextNotes.types.ts +20 -20
  58. package/src/talkpilot/contextNotes/index.ts +2 -2
  59. package/src/talkpilot/flows/__tests__/flows.schema.spec.ts +96 -71
  60. package/src/talkpilot/flows/flows.schema.ts +154 -153
  61. package/src/talkpilot/flows/flows.types.ts +187 -186
  62. package/src/talkpilot/index.ts +31 -31
  63. package/src/talkpilot/products/__tests__/products.getters.spec.ts +45 -45
  64. package/src/talkpilot/products/index.ts +2 -2
  65. package/src/talkpilot/products/products.getters.ts +12 -12
  66. package/src/talkpilot/products/products.types.ts +9 -9
  67. package/src/test-utils/db-utils.ts +26 -26
  68. package/src/test-utils/factories/index.ts +15 -15
  69. package/src/test-utils/factories/municipal/muniIssues.ts +32 -32
  70. package/src/test-utils/factories/talkpilot/contextNotes.ts +33 -33
  71. package/src/test-utils/factories/websitalk/scans.ts +23 -23
  72. package/src/utils/date.utils.ts +116 -116
  73. package/src/websitalk/index.ts +15 -15
  74. package/src/websitalk/mongodb-client.ts +61 -61
  75. package/src/websitalk/scans/__tests__/scans.spec.ts +218 -218
  76. package/src/websitalk/scans/index.ts +2 -2
  77. package/src/websitalk/scans/scans.getters.ts +113 -113
  78. package/src/websitalk/scans/scans.types.ts +53 -53
  79. package/tsconfig.json +23 -23
@@ -1,57 +1,57 @@
1
- export type DashboardHeatmapMetric = {
2
- hour: number;
3
- calls: number;
4
- };
5
-
6
- export type DashboardDailyTrendMetric = {
7
- date: string;
8
- completed: number;
9
- };
10
-
11
- export type DashboardVolumeGranularity =
12
- | "hour"
13
- | "day"
14
- | "week"
15
- | "month"
16
- | "quarter"
17
- | "year";
18
-
19
- export type DashboardSummaryMetrics = {
20
- totalCalls: number;
21
- avgDurationSeconds: number;
22
- timeSavedMinutes: number;
23
- completedCount: number;
24
- busyCount: number;
25
- };
26
-
27
- export type DashboardVisualData = {
28
- volumeData: DashboardDailyTrendMetric[];
29
- volumeGranularity: DashboardVolumeGranularity;
30
- };
31
-
32
- export type DashboardReportQuery = {
33
- clientId: string;
34
- startDate: string;
35
- endDate: string;
36
- granularity?: DashboardVolumeGranularity;
37
- };
38
-
39
- export type DashboardReportResponse = {
40
- kpis: DashboardSummaryMetrics;
41
- charts: DashboardVisualData;
42
- };
43
- type RawKpiResult = {
44
- completedCount: number;
45
- busyCount: number;
46
- answeredDuration: number | null;
47
- };
48
-
49
- export type RawVolumeAggregationResult = {
50
- _id: string;
51
- completed: number;
52
- };
53
-
54
- export interface DashboardAggregationResult {
55
- kpis: RawKpiResult[];
56
- volumeData: RawVolumeAggregationResult[];
57
- }
1
+ export type DashboardHeatmapMetric = {
2
+ hour: number;
3
+ calls: number;
4
+ };
5
+
6
+ export type DashboardDailyTrendMetric = {
7
+ date: string;
8
+ completed: number;
9
+ };
10
+
11
+ export type DashboardVolumeGranularity =
12
+ | "hour"
13
+ | "day"
14
+ | "week"
15
+ | "month"
16
+ | "quarter"
17
+ | "year";
18
+
19
+ export type DashboardSummaryMetrics = {
20
+ totalCalls: number;
21
+ avgDurationSeconds: number;
22
+ timeSavedMinutes: number;
23
+ completedCount: number;
24
+ busyCount: number;
25
+ };
26
+
27
+ export type DashboardVisualData = {
28
+ volumeData: DashboardDailyTrendMetric[];
29
+ volumeGranularity: DashboardVolumeGranularity;
30
+ };
31
+
32
+ export type DashboardReportQuery = {
33
+ clientId: string;
34
+ startDate: string;
35
+ endDate: string;
36
+ granularity?: DashboardVolumeGranularity;
37
+ };
38
+
39
+ export type DashboardReportResponse = {
40
+ kpis: DashboardSummaryMetrics;
41
+ charts: DashboardVisualData;
42
+ };
43
+ type RawKpiResult = {
44
+ completedCount: number;
45
+ busyCount: number;
46
+ answeredDuration: number | null;
47
+ };
48
+
49
+ export type RawVolumeAggregationResult = {
50
+ _id: string;
51
+ completed: number;
52
+ };
53
+
54
+ export interface DashboardAggregationResult {
55
+ kpis: RawKpiResult[];
56
+ volumeData: RawVolumeAggregationResult[];
57
+ }
@@ -1,6 +1,6 @@
1
- export * from "./calls.constants";
2
- export * from "./calls.types";
3
- export * from "./calls.getters";
4
- export * from "./calls.statistics.types";
5
- export * from "./calls.statistics.getters";
6
- export * from "./dashboard/calls.dashboard";
1
+ export * from "./calls.constants";
2
+ export * from "./calls.types";
3
+ export * from "./calls.getters";
4
+ export * from "./calls.statistics.types";
5
+ export * from "./calls.statistics.getters";
6
+ export * from "./dashboard/calls.dashboard";
@@ -1,190 +1,190 @@
1
- import {
2
- createClientConfigDoc,
3
- getClientConfig,
4
- } from "../clientsConfig.getters";
5
- import { createClientConfig } from "../../../test-utils/factories";
6
-
7
- describe("db.clientsConfig", () => {
8
- describe("getClientConfig", () => {
9
- it("should return client config by clientId", async () => {
10
- const clientId = "test-client-id";
11
- const clientConfig = createClientConfig({
12
- clientId,
13
- language: "Hebrew",
14
- products: { feature1: true, feature2: false } as any,
15
- });
16
-
17
- await createClientConfigDoc(clientConfig);
18
-
19
- const result = await getClientConfig(clientId);
20
-
21
- expect(result).toMatchObject({
22
- clientId,
23
- language: "Hebrew",
24
- products: { feature1: true, feature2: false },
25
- });
26
- });
27
-
28
- it("should support websiteTalk product config", async () => {
29
- const clientId = "websiteTalk-test";
30
- const clientConfig = createClientConfig({
31
- clientId,
32
- products: {
33
- websiteTalk: {
34
- logoUrl: "https://cdn.example.com/branding/acme/logo.png",
35
- companyName: "Acme Ltd",
36
- timezone: "Asia/Jerusalem",
37
- language: "he",
38
- defaultBaseUrl: "https://acme.example",
39
- },
40
- },
41
- });
42
-
43
- await createClientConfigDoc(clientConfig);
44
-
45
- const result = await getClientConfig(clientId);
46
-
47
- expect(result).toMatchObject({
48
- clientId,
49
- products: {
50
- websiteTalk: {
51
- logoUrl: "https://cdn.example.com/branding/acme/logo.png",
52
- companyName: "Acme Ltd",
53
- timezone: "Asia/Jerusalem",
54
- language: "he",
55
- defaultBaseUrl: "https://acme.example",
56
- },
57
- },
58
- });
59
- });
60
-
61
- it("should return null for non-existent clientId", async () => {
62
- const result = await getClientConfig("non-existent-client");
63
- expect(result).toBeNull();
64
- });
65
-
66
- it("given moked_106 with both toolsPrompts when saved and retrieved then both prompts are persisted", async () => {
67
- // Given
68
- const clientId = "tools-prompts-both";
69
- const clientConfig = createClientConfig({
70
- clientId,
71
- products: {
72
- municipal: {
73
- cityName: "ashdod",
74
- timezone: "Asia/Jerusalem",
75
- moked_106: {
76
- toolsPrompts: {
77
- findSubjectsSystemPrompt: "Custom subjects prompt",
78
- findStreetsSystemPrompt: "Custom streets prompt",
79
- },
80
- },
81
- },
82
- },
83
- });
84
-
85
- // When
86
- await createClientConfigDoc(clientConfig);
87
- const result = await getClientConfig(clientId);
88
-
89
- // Then
90
- expect(result?.products.municipal?.moked_106?.toolsPrompts).toMatchObject(
91
- {
92
- findSubjectsSystemPrompt: "Custom subjects prompt",
93
- findStreetsSystemPrompt: "Custom streets prompt",
94
- },
95
- );
96
- });
97
-
98
- it("given moked_106 with findSubjectsSystemPrompt only when saved and retrieved then findStreetsSystemPrompt is undefined", async () => {
99
- // Given
100
- const clientId = "tools-prompts-subjects-only";
101
- const clientConfig = createClientConfig({
102
- clientId,
103
- products: {
104
- municipal: {
105
- cityName: "ashdod",
106
- timezone: "Asia/Jerusalem",
107
- moked_106: {
108
- toolsPrompts: {
109
- findSubjectsSystemPrompt: "Subjects only prompt",
110
- },
111
- },
112
- },
113
- },
114
- });
115
-
116
- // When
117
- await createClientConfigDoc(clientConfig);
118
- const result = await getClientConfig(clientId);
119
-
120
- // Then
121
- expect(
122
- result?.products.municipal?.moked_106?.toolsPrompts
123
- ?.findSubjectsSystemPrompt,
124
- ).toBe("Subjects only prompt");
125
- expect(
126
- result?.products.municipal?.moked_106?.toolsPrompts
127
- ?.findStreetsSystemPrompt,
128
- ).toBeUndefined();
129
- });
130
-
131
- it("given moked_106 without toolsPrompts when saved and retrieved then toolsPrompts is undefined", async () => {
132
- // Given
133
- const clientId = "tools-prompts-absent";
134
- const clientConfig = createClientConfig({
135
- clientId,
136
- products: {
137
- municipal: {
138
- cityName: "ashdod",
139
- timezone: "Asia/Jerusalem",
140
- moked_106: {
141
- avoidSaveTickets: true,
142
- },
143
- },
144
- },
145
- });
146
-
147
- // When
148
- await createClientConfigDoc(clientConfig);
149
- const result = await getClientConfig(clientId);
150
-
151
- // Then
152
- expect(
153
- result?.products.municipal?.moked_106?.toolsPrompts,
154
- ).toBeUndefined();
155
- });
156
-
157
- it("should support communications config", async () => {
158
- const clientId = "communications-test";
159
- const clientConfig = createClientConfig({
160
- clientId,
161
- communications: {
162
- sendGrid: {
163
- emailTo: ["test@example.com"],
164
- templateId: "temp-123",
165
- senderId: "sender-123",
166
- },
167
- sms: {},
168
- whatsapp: {},
169
- },
170
- });
171
-
172
- await createClientConfigDoc(clientConfig);
173
-
174
- const result = await getClientConfig(clientId);
175
-
176
- expect(result).toMatchObject({
177
- clientId,
178
- communications: {
179
- sendGrid: {
180
- emailTo: ["test@example.com"],
181
- templateId: "temp-123",
182
- senderId: "sender-123",
183
- },
184
- sms: {},
185
- whatsapp: {},
186
- },
187
- });
188
- });
189
- });
190
- });
1
+ import {
2
+ createClientConfigDoc,
3
+ getClientConfig,
4
+ } from "../clientsConfig.getters";
5
+ import { createClientConfig } from "../../../test-utils/factories";
6
+
7
+ describe("db.clientsConfig", () => {
8
+ describe("getClientConfig", () => {
9
+ it("should return client config by clientId", async () => {
10
+ const clientId = "test-client-id";
11
+ const clientConfig = createClientConfig({
12
+ clientId,
13
+ language: "Hebrew",
14
+ products: { feature1: true, feature2: false } as any,
15
+ });
16
+
17
+ await createClientConfigDoc(clientConfig);
18
+
19
+ const result = await getClientConfig(clientId);
20
+
21
+ expect(result).toMatchObject({
22
+ clientId,
23
+ language: "Hebrew",
24
+ products: { feature1: true, feature2: false },
25
+ });
26
+ });
27
+
28
+ it("should support websiteTalk product config", async () => {
29
+ const clientId = "websiteTalk-test";
30
+ const clientConfig = createClientConfig({
31
+ clientId,
32
+ products: {
33
+ websiteTalk: {
34
+ logoUrl: "https://cdn.example.com/branding/acme/logo.png",
35
+ companyName: "Acme Ltd",
36
+ timezone: "Asia/Jerusalem",
37
+ language: "he",
38
+ defaultBaseUrl: "https://acme.example",
39
+ },
40
+ },
41
+ });
42
+
43
+ await createClientConfigDoc(clientConfig);
44
+
45
+ const result = await getClientConfig(clientId);
46
+
47
+ expect(result).toMatchObject({
48
+ clientId,
49
+ products: {
50
+ websiteTalk: {
51
+ logoUrl: "https://cdn.example.com/branding/acme/logo.png",
52
+ companyName: "Acme Ltd",
53
+ timezone: "Asia/Jerusalem",
54
+ language: "he",
55
+ defaultBaseUrl: "https://acme.example",
56
+ },
57
+ },
58
+ });
59
+ });
60
+
61
+ it("should return null for non-existent clientId", async () => {
62
+ const result = await getClientConfig("non-existent-client");
63
+ expect(result).toBeNull();
64
+ });
65
+
66
+ it("given moked_106 with both toolsPrompts when saved and retrieved then both prompts are persisted", async () => {
67
+ // Given
68
+ const clientId = "tools-prompts-both";
69
+ const clientConfig = createClientConfig({
70
+ clientId,
71
+ products: {
72
+ municipal: {
73
+ cityName: "ashdod",
74
+ timezone: "Asia/Jerusalem",
75
+ moked_106: {
76
+ toolsPrompts: {
77
+ findSubjectsSystemPrompt: "Custom subjects prompt",
78
+ findStreetsSystemPrompt: "Custom streets prompt",
79
+ },
80
+ },
81
+ },
82
+ },
83
+ });
84
+
85
+ // When
86
+ await createClientConfigDoc(clientConfig);
87
+ const result = await getClientConfig(clientId);
88
+
89
+ // Then
90
+ expect(result?.products.municipal?.moked_106?.toolsPrompts).toMatchObject(
91
+ {
92
+ findSubjectsSystemPrompt: "Custom subjects prompt",
93
+ findStreetsSystemPrompt: "Custom streets prompt",
94
+ },
95
+ );
96
+ });
97
+
98
+ it("given moked_106 with findSubjectsSystemPrompt only when saved and retrieved then findStreetsSystemPrompt is undefined", async () => {
99
+ // Given
100
+ const clientId = "tools-prompts-subjects-only";
101
+ const clientConfig = createClientConfig({
102
+ clientId,
103
+ products: {
104
+ municipal: {
105
+ cityName: "ashdod",
106
+ timezone: "Asia/Jerusalem",
107
+ moked_106: {
108
+ toolsPrompts: {
109
+ findSubjectsSystemPrompt: "Subjects only prompt",
110
+ },
111
+ },
112
+ },
113
+ },
114
+ });
115
+
116
+ // When
117
+ await createClientConfigDoc(clientConfig);
118
+ const result = await getClientConfig(clientId);
119
+
120
+ // Then
121
+ expect(
122
+ result?.products.municipal?.moked_106?.toolsPrompts
123
+ ?.findSubjectsSystemPrompt,
124
+ ).toBe("Subjects only prompt");
125
+ expect(
126
+ result?.products.municipal?.moked_106?.toolsPrompts
127
+ ?.findStreetsSystemPrompt,
128
+ ).toBeUndefined();
129
+ });
130
+
131
+ it("given moked_106 without toolsPrompts when saved and retrieved then toolsPrompts is undefined", async () => {
132
+ // Given
133
+ const clientId = "tools-prompts-absent";
134
+ const clientConfig = createClientConfig({
135
+ clientId,
136
+ products: {
137
+ municipal: {
138
+ cityName: "ashdod",
139
+ timezone: "Asia/Jerusalem",
140
+ moked_106: {
141
+ avoidSaveTickets: true,
142
+ },
143
+ },
144
+ },
145
+ });
146
+
147
+ // When
148
+ await createClientConfigDoc(clientConfig);
149
+ const result = await getClientConfig(clientId);
150
+
151
+ // Then
152
+ expect(
153
+ result?.products.municipal?.moked_106?.toolsPrompts,
154
+ ).toBeUndefined();
155
+ });
156
+
157
+ it("should support communications config", async () => {
158
+ const clientId = "communications-test";
159
+ const clientConfig = createClientConfig({
160
+ clientId,
161
+ communications: {
162
+ sendGrid: {
163
+ emailTo: ["test@example.com"],
164
+ templateId: "temp-123",
165
+ senderId: "sender-123",
166
+ },
167
+ sms: {},
168
+ whatsapp: {},
169
+ },
170
+ });
171
+
172
+ await createClientConfigDoc(clientConfig);
173
+
174
+ const result = await getClientConfig(clientId);
175
+
176
+ expect(result).toMatchObject({
177
+ clientId,
178
+ communications: {
179
+ sendGrid: {
180
+ emailTo: ["test@example.com"],
181
+ templateId: "temp-123",
182
+ senderId: "sender-123",
183
+ },
184
+ sms: {},
185
+ whatsapp: {},
186
+ },
187
+ });
188
+ });
189
+ });
190
+ });