@talkpilot/core-db 1.3.8 → 1.3.9

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 (97) hide show
  1. package/.claude/settings.local.json +11 -0
  2. package/.cursor/rules/development.mdc +65 -65
  3. package/DEVELOPMENT.md +141 -141
  4. package/README.md +257 -243
  5. package/README_OLD.md +160 -160
  6. package/dist/municipal/tickets/tickets.deprecated.getters.d.ts +12 -0
  7. package/dist/municipal/tickets/tickets.deprecated.getters.d.ts.map +1 -0
  8. package/dist/municipal/tickets/tickets.deprecated.getters.js +131 -0
  9. package/dist/municipal/tickets/tickets.deprecated.getters.js.map +1 -0
  10. package/dist/municipal/tickets/tickets.statistics.dates.d.ts +7 -0
  11. package/dist/municipal/tickets/tickets.statistics.dates.d.ts.map +1 -0
  12. package/dist/municipal/tickets/tickets.statistics.dates.js +40 -0
  13. package/dist/municipal/tickets/tickets.statistics.dates.js.map +1 -0
  14. package/dist/municipal/tickets/tickets.statistics.pipeline.d.ts +53 -0
  15. package/dist/municipal/tickets/tickets.statistics.pipeline.d.ts.map +1 -0
  16. package/dist/municipal/tickets/tickets.statistics.pipeline.js +112 -0
  17. package/dist/municipal/tickets/tickets.statistics.pipeline.js.map +1 -0
  18. package/dist/municipal/tickets/tickets.statistics.utils.d.ts +7 -0
  19. package/dist/municipal/tickets/tickets.statistics.utils.d.ts.map +1 -0
  20. package/dist/municipal/tickets/tickets.statistics.utils.js +40 -0
  21. package/dist/municipal/tickets/tickets.statistics.utils.js.map +1 -0
  22. package/dist/talkpilot/calls/calls.statistics.getters.d.ts.map +1 -1
  23. package/dist/talkpilot/calls/calls.statistics.getters.js +6 -3
  24. package/dist/talkpilot/calls/calls.statistics.getters.js.map +1 -1
  25. package/dist/talkpilot/calls/calls.statistics.ticketScope.d.ts +12 -0
  26. package/dist/talkpilot/calls/calls.statistics.ticketScope.d.ts.map +1 -0
  27. package/dist/talkpilot/calls/calls.statistics.ticketScope.js +37 -0
  28. package/dist/talkpilot/calls/calls.statistics.ticketScope.js.map +1 -0
  29. package/dist/talkpilot/calls/calls.statistics.tickets.d.ts +17 -0
  30. package/dist/talkpilot/calls/calls.statistics.tickets.d.ts.map +1 -0
  31. package/dist/talkpilot/calls/calls.statistics.tickets.js +33 -0
  32. package/dist/talkpilot/calls/calls.statistics.tickets.js.map +1 -0
  33. package/dist/utils/statistics.aggregation.d.ts +20 -0
  34. package/dist/utils/statistics.aggregation.d.ts.map +1 -0
  35. package/dist/utils/statistics.aggregation.js +43 -0
  36. package/dist/utils/statistics.aggregation.js.map +1 -0
  37. package/jest.config.js +20 -20
  38. package/package.json +46 -46
  39. package/src/connection.ts +54 -54
  40. package/src/index.ts +26 -26
  41. package/src/municipal/index.ts +22 -22
  42. package/src/municipal/muniIssues/__tests__/muniIssues.setters.spec.ts +92 -92
  43. package/src/municipal/muniIssues/__tests__/muniIssues.setup.spec.ts +92 -92
  44. package/src/municipal/muniIssues/index.ts +17 -17
  45. package/src/municipal/muniIssues/muniIssues.constants.ts +18 -18
  46. package/src/municipal/muniIssues/muniIssues.getters.ts +24 -24
  47. package/src/municipal/muniIssues/muniIssues.schema.ts +66 -66
  48. package/src/municipal/muniIssues/muniIssues.setters.ts +24 -24
  49. package/src/municipal/muniIssues/muniIssues.setup.ts +65 -65
  50. package/src/municipal/muniIssues/muniIssues.types.ts +37 -37
  51. package/src/municipal/tickets/__tests__/tickets.getters.spec.ts +30 -30
  52. package/src/municipal/tickets/__tests__/tickets.statistics.spec.ts +68 -68
  53. package/src/municipal/tickets/index.ts +3 -3
  54. package/src/municipal/tickets/tickets.constants.ts +8 -8
  55. package/src/municipal/tickets/tickets.getters.ts +121 -121
  56. package/src/municipal/tickets/tickets.statistics.aggregation.ts +96 -96
  57. package/src/municipal/tickets/tickets.statistics.getters.ts +109 -109
  58. package/src/municipal/tickets/tickets.types.ts +53 -53
  59. package/src/talkpilot/calls/__tests__/calls.dashboard.spec.ts +149 -149
  60. package/src/talkpilot/calls/__tests__/calls.statistics.spec.ts +375 -351
  61. package/src/talkpilot/calls/calls.constants.ts +20 -20
  62. package/src/talkpilot/calls/calls.statistics.getters.ts +590 -587
  63. package/src/talkpilot/calls/calls.statistics.types.ts +47 -47
  64. package/src/talkpilot/calls/calls.types.ts +119 -119
  65. package/src/talkpilot/calls/dashboard/calls.dashboard.ts +292 -292
  66. package/src/talkpilot/calls/dashboard/calls.dashboard.types.ts +57 -57
  67. package/src/talkpilot/calls/index.ts +6 -6
  68. package/src/talkpilot/clientsConfig/__tests__/clientsConfig.spec.ts +190 -190
  69. package/src/talkpilot/contextNotes/__tests__/contextNotes.getters.spec.ts +176 -176
  70. package/src/talkpilot/contextNotes/contextNotes.getters.ts +86 -86
  71. package/src/talkpilot/contextNotes/contextNotes.types.ts +20 -20
  72. package/src/talkpilot/contextNotes/index.ts +2 -2
  73. package/src/talkpilot/flows/__tests__/flows.schema.spec.ts +96 -96
  74. package/src/talkpilot/flows/flows.schema.ts +154 -154
  75. package/src/talkpilot/flows/flows.types.ts +187 -187
  76. package/src/talkpilot/index.ts +31 -31
  77. package/src/talkpilot/products/__tests__/products.getters.spec.ts +45 -45
  78. package/src/talkpilot/products/index.ts +2 -2
  79. package/src/talkpilot/products/products.getters.ts +12 -12
  80. package/src/talkpilot/products/products.types.ts +9 -9
  81. package/src/test-utils/db-utils.ts +26 -26
  82. package/src/test-utils/factories/index.ts +15 -15
  83. package/src/test-utils/factories/municipal/muniIssues.ts +32 -32
  84. package/src/test-utils/factories/talkpilot/contextNotes.ts +33 -33
  85. package/src/test-utils/factories/websitalk/scans.ts +23 -23
  86. package/src/utils/date.utils.ts +116 -116
  87. package/src/websitalk/index.ts +15 -15
  88. package/src/websitalk/mongodb-client.ts +61 -61
  89. package/src/websitalk/scans/__tests__/scans.spec.ts +218 -218
  90. package/src/websitalk/scans/index.ts +2 -2
  91. package/src/websitalk/scans/scans.getters.ts +113 -113
  92. package/src/websitalk/scans/scans.types.ts +53 -53
  93. package/tsconfig.json +23 -23
  94. package/dist/talkpilot/calls/calls.dashboard.d.ts +0 -3
  95. package/dist/talkpilot/calls/calls.dashboard.d.ts.map +0 -1
  96. package/dist/talkpilot/calls/calls.dashboard.js +0 -191
  97. package/dist/talkpilot/calls/calls.dashboard.js.map +0 -1
@@ -1,187 +1,187 @@
1
- import { ObjectId } from "mongodb";
2
-
3
- /* ---------- Basic helpers ---------- */
4
-
5
- export type Position = { x: number; y: number };
6
- export type HttpMethod = "GET" | "POST" | "PUT" | "PATCH" | "DELETE";
7
-
8
- export type QuestionType = "open" | "multiple" | "table";
9
- export type SelectionType = "single" | "multiple";
10
-
11
- export type Question = {
12
- id: string;
13
- type: QuestionType;
14
- text: string;
15
- repeatAnswer?: boolean;
16
- // For 'multiple' type questions:
17
- answers?: string[] | null;
18
- selectionType?: SelectionType | null; // 'single' = choose one, 'multiple' = choose one or more
19
- // For 'table' type questions:
20
- tableHeader?: string | null;
21
- tableRows?: string[] | null;
22
- tableColumns?: string[] | null; // These are the answer options shared across all rows
23
- // Note: 'table' questions can also have selectionType to indicate if each row allows single or multiple selections
24
- };
25
-
26
- export type NodeKind =
27
- | "start"
28
- | "say"
29
- | "condition"
30
- | "improvise"
31
- | "tool"
32
- | "sendMessage"
33
- | "questionsList"
34
- | "end";
35
- type BaseNode = {
36
- id: string;
37
- type: NodeKind;
38
- text: string;
39
-
40
- name?: string | null;
41
- position: Position;
42
- children?: string[] | null;
43
- successStatus?: string | null;
44
- questions?: Question[] | null;
45
- };
46
-
47
- export type StartNode = BaseNode & { type: "start" };
48
-
49
- export type SayNode = BaseNode & { type: "say" };
50
-
51
- export type ConditionNode = BaseNode & {
52
- type: "condition";
53
- conditions: Array<{
54
- conditionString: string;
55
- nodeType?: string | null;
56
- id?: string | null;
57
- }>;
58
- defaultNodeType?: string | null;
59
- defaultChild?: { id?: string } | null;
60
- };
61
-
62
- export type ImproviseNode = BaseNode & { type: "improvise" };
63
-
64
- export type FlowTool = {
65
- id: string;
66
- name: string;
67
- description?: string;
68
- url: string;
69
- method: HttpMethod;
70
- headers?: Record<string, string>;
71
- parameters: Record<string, unknown>;
72
- bodyFormat?: "json" | "form-data";
73
- preventAudioDuringTool?: boolean;
74
- sendUserAuthToken?: boolean;
75
- runInBackground?: boolean;
76
- backgroundToolType?: "backgroundToolAlways" | "backgroundToolOnce";
77
- backgroundContinuationInstructions?: string;
78
- };
79
-
80
- export type SendMethod = "sms" | "whatsapp";
81
-
82
- export type SendMessageNode = BaseNode & {
83
- type: "sendMessage";
84
- /** Which channel to use. If omitted, decide at runtime (e.g., default to whatsapp). */
85
- send_method: SendMethod;
86
- /** Destination phone (E.164 or templated string like "{{userPhone}}"). */
87
- phone_number: string;
88
- };
89
-
90
- export type ToolNode = BaseNode & {
91
- type: "tool";
92
- name: string;
93
- text: string;
94
- };
95
-
96
- export type QuestionsListNode = BaseNode & {
97
- type: "questionsList";
98
- questions: Question[];
99
- };
100
-
101
- export type EndNode = BaseNode & { type: "end" };
102
-
103
- export type Interaction =
104
- | StartNode
105
- | SayNode
106
- | ConditionNode
107
- | ImproviseNode
108
- | ToolNode
109
- | SendMessageNode
110
- | QuestionsListNode
111
- | EndNode;
112
-
113
- export type Edge = {
114
- id: string;
115
- source: string;
116
- target: string;
117
- label?: string | null;
118
- };
119
-
120
- export type MetaKey = {
121
- key: string;
122
- required?: boolean;
123
- };
124
-
125
- export type UserProperty = {
126
- name: string;
127
- description: string;
128
- };
129
-
130
- export type InterruptionSettings = {
131
- enableInterruptionDetection?: boolean;
132
- interruptionWindowSeconds?: number;
133
- interruptionThresholdSeconds?: number;
134
- interruptionInstruction?: string;
135
- };
136
-
137
- export type SilenceEscalationSettings = {
138
- enableSilenceDetection?: boolean;
139
- firstWarningSilenceSeconds?: number;
140
- firstWarningInstruction?: string;
141
- secondWarningSilenceSeconds?: number;
142
- secondWarningInstruction?: string;
143
- disconnectSilenceSeconds?: number;
144
- silenceTimeoutSeconds?: number;
145
- };
146
-
147
- export type ConversationSettings = {
148
- interruptions?: InterruptionSettings;
149
- silence?: SilenceEscalationSettings;
150
- liveTimeUpdates?: boolean;
151
- };
152
-
153
- /* ---------- The Flow object ---------- */
154
-
155
- export type Flow = {
156
- freeTextContent?: string;
157
- isFreeText?: boolean;
158
- disableGenericPrompt?: boolean;
159
- _id?: ObjectId;
160
-
161
- flowName: string;
162
- clientId: string;
163
-
164
- systemInstructions: string;
165
- initialSentence: string;
166
- voice?: string;
167
-
168
- insights: string[];
169
- conversationSettings?: ConversationSettings;
170
-
171
- interactions: Interaction[];
172
-
173
- edges?: Edge[] | null;
174
- metaKeys?: MetaKey[] | null;
175
- userProperties?: UserProperty[] | null;
176
- tools?: FlowTool[];
177
- afterCallEvent?: string;
178
-
179
- products?: string[];
180
-
181
- // AI provider configuration
182
- aiProvider?: any;
183
-
184
- // Timestamps
185
- createdAt?: Date;
186
- updatedAt?: Date;
187
- };
1
+ import { ObjectId } from "mongodb";
2
+
3
+ /* ---------- Basic helpers ---------- */
4
+
5
+ export type Position = { x: number; y: number };
6
+ export type HttpMethod = "GET" | "POST" | "PUT" | "PATCH" | "DELETE";
7
+
8
+ export type QuestionType = "open" | "multiple" | "table";
9
+ export type SelectionType = "single" | "multiple";
10
+
11
+ export type Question = {
12
+ id: string;
13
+ type: QuestionType;
14
+ text: string;
15
+ repeatAnswer?: boolean;
16
+ // For 'multiple' type questions:
17
+ answers?: string[] | null;
18
+ selectionType?: SelectionType | null; // 'single' = choose one, 'multiple' = choose one or more
19
+ // For 'table' type questions:
20
+ tableHeader?: string | null;
21
+ tableRows?: string[] | null;
22
+ tableColumns?: string[] | null; // These are the answer options shared across all rows
23
+ // Note: 'table' questions can also have selectionType to indicate if each row allows single or multiple selections
24
+ };
25
+
26
+ export type NodeKind =
27
+ | "start"
28
+ | "say"
29
+ | "condition"
30
+ | "improvise"
31
+ | "tool"
32
+ | "sendMessage"
33
+ | "questionsList"
34
+ | "end";
35
+ type BaseNode = {
36
+ id: string;
37
+ type: NodeKind;
38
+ text: string;
39
+
40
+ name?: string | null;
41
+ position: Position;
42
+ children?: string[] | null;
43
+ successStatus?: string | null;
44
+ questions?: Question[] | null;
45
+ };
46
+
47
+ export type StartNode = BaseNode & { type: "start" };
48
+
49
+ export type SayNode = BaseNode & { type: "say" };
50
+
51
+ export type ConditionNode = BaseNode & {
52
+ type: "condition";
53
+ conditions: Array<{
54
+ conditionString: string;
55
+ nodeType?: string | null;
56
+ id?: string | null;
57
+ }>;
58
+ defaultNodeType?: string | null;
59
+ defaultChild?: { id?: string } | null;
60
+ };
61
+
62
+ export type ImproviseNode = BaseNode & { type: "improvise" };
63
+
64
+ export type FlowTool = {
65
+ id: string;
66
+ name: string;
67
+ description?: string;
68
+ url: string;
69
+ method: HttpMethod;
70
+ headers?: Record<string, string>;
71
+ parameters: Record<string, unknown>;
72
+ bodyFormat?: "json" | "form-data";
73
+ preventAudioDuringTool?: boolean;
74
+ sendUserAuthToken?: boolean;
75
+ runInBackground?: boolean;
76
+ backgroundToolType?: "backgroundToolAlways" | "backgroundToolOnce";
77
+ backgroundContinuationInstructions?: string;
78
+ };
79
+
80
+ export type SendMethod = "sms" | "whatsapp";
81
+
82
+ export type SendMessageNode = BaseNode & {
83
+ type: "sendMessage";
84
+ /** Which channel to use. If omitted, decide at runtime (e.g., default to whatsapp). */
85
+ send_method: SendMethod;
86
+ /** Destination phone (E.164 or templated string like "{{userPhone}}"). */
87
+ phone_number: string;
88
+ };
89
+
90
+ export type ToolNode = BaseNode & {
91
+ type: "tool";
92
+ name: string;
93
+ text: string;
94
+ };
95
+
96
+ export type QuestionsListNode = BaseNode & {
97
+ type: "questionsList";
98
+ questions: Question[];
99
+ };
100
+
101
+ export type EndNode = BaseNode & { type: "end" };
102
+
103
+ export type Interaction =
104
+ | StartNode
105
+ | SayNode
106
+ | ConditionNode
107
+ | ImproviseNode
108
+ | ToolNode
109
+ | SendMessageNode
110
+ | QuestionsListNode
111
+ | EndNode;
112
+
113
+ export type Edge = {
114
+ id: string;
115
+ source: string;
116
+ target: string;
117
+ label?: string | null;
118
+ };
119
+
120
+ export type MetaKey = {
121
+ key: string;
122
+ required?: boolean;
123
+ };
124
+
125
+ export type UserProperty = {
126
+ name: string;
127
+ description: string;
128
+ };
129
+
130
+ export type InterruptionSettings = {
131
+ enableInterruptionDetection?: boolean;
132
+ interruptionWindowSeconds?: number;
133
+ interruptionThresholdSeconds?: number;
134
+ interruptionInstruction?: string;
135
+ };
136
+
137
+ export type SilenceEscalationSettings = {
138
+ enableSilenceDetection?: boolean;
139
+ firstWarningSilenceSeconds?: number;
140
+ firstWarningInstruction?: string;
141
+ secondWarningSilenceSeconds?: number;
142
+ secondWarningInstruction?: string;
143
+ disconnectSilenceSeconds?: number;
144
+ silenceTimeoutSeconds?: number;
145
+ };
146
+
147
+ export type ConversationSettings = {
148
+ interruptions?: InterruptionSettings;
149
+ silence?: SilenceEscalationSettings;
150
+ liveTimeUpdates?: boolean;
151
+ };
152
+
153
+ /* ---------- The Flow object ---------- */
154
+
155
+ export type Flow = {
156
+ freeTextContent?: string;
157
+ isFreeText?: boolean;
158
+ disableGenericPrompt?: boolean;
159
+ _id?: ObjectId;
160
+
161
+ flowName: string;
162
+ clientId: string;
163
+
164
+ systemInstructions: string;
165
+ initialSentence: string;
166
+ voice?: string;
167
+
168
+ insights: string[];
169
+ conversationSettings?: ConversationSettings;
170
+
171
+ interactions: Interaction[];
172
+
173
+ edges?: Edge[] | null;
174
+ metaKeys?: MetaKey[] | null;
175
+ userProperties?: UserProperty[] | null;
176
+ tools?: FlowTool[];
177
+ afterCallEvent?: string;
178
+
179
+ products?: string[];
180
+
181
+ // AI provider configuration
182
+ aiProvider?: any;
183
+
184
+ // Timestamps
185
+ createdAt?: Date;
186
+ updatedAt?: Date;
187
+ };
@@ -1,31 +1,31 @@
1
- import { Db, ObjectId as MongoObjectId } from "mongodb";
2
-
3
- export * from "./flows";
4
- export * from "./contextNotes";
5
- export * from "./products";
6
- export * from "./results";
7
- export * from "./sessions";
8
- export * from "./phone_numbers";
9
- export * from "./leads";
10
- export * from "./clients";
11
- export * from "./agents";
12
- export * from "./plans";
13
- export * from "./subscriptions";
14
- export * from "./groups";
15
- export * from "./calls";
16
- export * from "./clientAudioBuffers";
17
- export * from "./clientsConfig";
18
- export * from "./backgroundToolResults";
19
- export * from "./retry_analyze";
20
- export { mongodbClient } from "./mongodb-client";
21
-
22
- let db: Db;
23
- export const setDb = (d: Db) => {
24
- db = d;
25
- };
26
- export const getDb = (): Db => {
27
- if (!db) throw new Error("DB not initialised");
28
- return db;
29
- };
30
-
31
- export const ObjectId = MongoObjectId;
1
+ import { Db, ObjectId as MongoObjectId } from "mongodb";
2
+
3
+ export * from "./flows";
4
+ export * from "./contextNotes";
5
+ export * from "./products";
6
+ export * from "./results";
7
+ export * from "./sessions";
8
+ export * from "./phone_numbers";
9
+ export * from "./leads";
10
+ export * from "./clients";
11
+ export * from "./agents";
12
+ export * from "./plans";
13
+ export * from "./subscriptions";
14
+ export * from "./groups";
15
+ export * from "./calls";
16
+ export * from "./clientAudioBuffers";
17
+ export * from "./clientsConfig";
18
+ export * from "./backgroundToolResults";
19
+ export * from "./retry_analyze";
20
+ export { mongodbClient } from "./mongodb-client";
21
+
22
+ let db: Db;
23
+ export const setDb = (d: Db) => {
24
+ db = d;
25
+ };
26
+ export const getDb = (): Db => {
27
+ if (!db) throw new Error("DB not initialised");
28
+ return db;
29
+ };
30
+
31
+ export const ObjectId = MongoObjectId;
@@ -1,45 +1,45 @@
1
- import { getProductsCollection, getAllProducts } from "../products.getters";
2
- import { ObjectId } from "../../index";
3
-
4
- describe("products getters", () => {
5
- it('should return the "products" collection', () => {
6
- const collection = getProductsCollection();
7
- expect(collection.collectionName).toBe("products");
8
- });
9
-
10
- it("should return all product documents", async () => {
11
- await getProductsCollection().insertMany([
12
- { _id: new ObjectId(), name: "Municipal" },
13
- { _id: new ObjectId(), name: "Clinics" },
14
- ]);
15
-
16
- const results = await getAllProducts();
17
- expect(results.length).toBeGreaterThanOrEqual(2);
18
- expect(results.map((p) => p.name)).toEqual(
19
- expect.arrayContaining(["Municipal", "Clinics"]),
20
- );
21
- });
22
-
23
- it("should store and retrieve displayName locale map", async () => {
24
- const id = new ObjectId();
25
- await getProductsCollection().insertOne({
26
- _id: id,
27
- name: "Municipal",
28
- displayName: { he: "עירייה", en: "Municipal" },
29
- });
30
-
31
- const results = await getAllProducts();
32
- const saved = results.find((p) => p._id.equals(id));
33
- expect(saved?.displayName).toEqual({ he: "עירייה", en: "Municipal" });
34
- });
35
-
36
- it("should return products without displayName without error", async () => {
37
- const id = new ObjectId();
38
- await getProductsCollection().insertOne({ _id: id, name: "Rcure" });
39
-
40
- const results = await getAllProducts();
41
- const saved = results.find((p) => p._id.equals(id));
42
- expect(saved?.displayName).toBeUndefined();
43
- });
44
-
45
- });
1
+ import { getProductsCollection, getAllProducts } from "../products.getters";
2
+ import { ObjectId } from "../../index";
3
+
4
+ describe("products getters", () => {
5
+ it('should return the "products" collection', () => {
6
+ const collection = getProductsCollection();
7
+ expect(collection.collectionName).toBe("products");
8
+ });
9
+
10
+ it("should return all product documents", async () => {
11
+ await getProductsCollection().insertMany([
12
+ { _id: new ObjectId(), name: "Municipal" },
13
+ { _id: new ObjectId(), name: "Clinics" },
14
+ ]);
15
+
16
+ const results = await getAllProducts();
17
+ expect(results.length).toBeGreaterThanOrEqual(2);
18
+ expect(results.map((p) => p.name)).toEqual(
19
+ expect.arrayContaining(["Municipal", "Clinics"]),
20
+ );
21
+ });
22
+
23
+ it("should store and retrieve displayName locale map", async () => {
24
+ const id = new ObjectId();
25
+ await getProductsCollection().insertOne({
26
+ _id: id,
27
+ name: "Municipal",
28
+ displayName: { he: "עירייה", en: "Municipal" },
29
+ });
30
+
31
+ const results = await getAllProducts();
32
+ const saved = results.find((p) => p._id.equals(id));
33
+ expect(saved?.displayName).toEqual({ he: "עירייה", en: "Municipal" });
34
+ });
35
+
36
+ it("should return products without displayName without error", async () => {
37
+ const id = new ObjectId();
38
+ await getProductsCollection().insertOne({ _id: id, name: "Rcure" });
39
+
40
+ const results = await getAllProducts();
41
+ const saved = results.find((p) => p._id.equals(id));
42
+ expect(saved?.displayName).toBeUndefined();
43
+ });
44
+
45
+ });
@@ -1,2 +1,2 @@
1
- export * from "./products.types";
2
- export * from "./products.getters";
1
+ export * from "./products.types";
2
+ export * from "./products.getters";
@@ -1,12 +1,12 @@
1
- import { Collection, WithId } from "mongodb";
2
- import { getDb } from "../index";
3
- import type { Product } from "./products.types";
4
-
5
- export const getProductsCollection = (): Collection<Product> => {
6
- return getDb().collection<Product>("products");
7
- };
8
-
9
- /** Returns all product documents */
10
- export const getAllProducts = (): Promise<WithId<Product>[]> => {
11
- return getProductsCollection().find().toArray();
12
- };
1
+ import { Collection, WithId } from "mongodb";
2
+ import { getDb } from "../index";
3
+ import type { Product } from "./products.types";
4
+
5
+ export const getProductsCollection = (): Collection<Product> => {
6
+ return getDb().collection<Product>("products");
7
+ };
8
+
9
+ /** Returns all product documents */
10
+ export const getAllProducts = (): Promise<WithId<Product>[]> => {
11
+ return getProductsCollection().find().toArray();
12
+ };
@@ -1,9 +1,9 @@
1
- import { ObjectId } from "mongodb";
2
-
3
- export type Product = {
4
- _id: ObjectId;
5
- /** Internal product name */
6
- name: string;
7
- /** Map from language name to display name, e.g. {en, Municipal} */
8
- displayName?: Record<string, string>;
9
- };
1
+ import { ObjectId } from "mongodb";
2
+
3
+ export type Product = {
4
+ _id: ObjectId;
5
+ /** Internal product name */
6
+ name: string;
7
+ /** Map from language name to display name, e.g. {en, Municipal} */
8
+ displayName?: Record<string, string>;
9
+ };
@@ -1,26 +1,26 @@
1
- import { MongoMemoryServer } from "mongodb-memory-server";
2
- import { MongoClient, Db } from "mongodb";
3
- import { setDb, setMunicipalDataDb, setWebsitalkDb } from "../index";
4
-
5
- let mongoServer: MongoMemoryServer;
6
- let client: MongoClient;
7
-
8
- export async function initTestDb(): Promise<Db> {
9
- mongoServer = await MongoMemoryServer.create({
10
- instance: { ip: "127.0.0.1" },
11
- });
12
- client = new MongoClient(mongoServer.getUri());
13
- await client.connect();
14
- const talkpilotDb = client.db();
15
- const municipalDb = client.db("municipal-data");
16
- const websitalkDb = client.db("website-talk");
17
- setDb(talkpilotDb);
18
- setMunicipalDataDb(municipalDb);
19
- setWebsitalkDb(websitalkDb);
20
- return talkpilotDb;
21
- }
22
-
23
- export async function closeTestDb(): Promise<void> {
24
- if (client) await client.close();
25
- if (mongoServer) await mongoServer.stop();
26
- }
1
+ import { MongoMemoryServer } from "mongodb-memory-server";
2
+ import { MongoClient, Db } from "mongodb";
3
+ import { setDb, setMunicipalDataDb, setWebsitalkDb } from "../index";
4
+
5
+ let mongoServer: MongoMemoryServer;
6
+ let client: MongoClient;
7
+
8
+ export async function initTestDb(): Promise<Db> {
9
+ mongoServer = await MongoMemoryServer.create({
10
+ instance: { ip: "127.0.0.1" },
11
+ });
12
+ client = new MongoClient(mongoServer.getUri());
13
+ await client.connect();
14
+ const talkpilotDb = client.db();
15
+ const municipalDb = client.db("municipal-data");
16
+ const websitalkDb = client.db("website-talk");
17
+ setDb(talkpilotDb);
18
+ setMunicipalDataDb(municipalDb);
19
+ setWebsitalkDb(websitalkDb);
20
+ return talkpilotDb;
21
+ }
22
+
23
+ export async function closeTestDb(): Promise<void> {
24
+ if (client) await client.close();
25
+ if (mongoServer) await mongoServer.stop();
26
+ }
@@ -1,15 +1,15 @@
1
- export * from "./talkpilot/agents";
2
- export * from "./talkpilot/calls";
3
- export * from "./talkpilot/clientAudioBuffers";
4
- export * from "./talkpilot/clientsConfig";
5
- export * from "./talkpilot/flows";
6
- export * from "./talkpilot/contextNotes";
7
- export * from "./talkpilot/groups";
8
- export * from "./talkpilot/phone_numbers";
9
- export * from "./talkpilot/sessions";
10
- export * from "./municipal/cities";
11
- export * from "./municipal/departmentsSubjects";
12
- export * from "./municipal/muniIssues";
13
- export * from "./municipal/streets";
14
- export * from "./municipal/tickets";
15
- export * from "./websitalk/scans";
1
+ export * from "./talkpilot/agents";
2
+ export * from "./talkpilot/calls";
3
+ export * from "./talkpilot/clientAudioBuffers";
4
+ export * from "./talkpilot/clientsConfig";
5
+ export * from "./talkpilot/flows";
6
+ export * from "./talkpilot/contextNotes";
7
+ export * from "./talkpilot/groups";
8
+ export * from "./talkpilot/phone_numbers";
9
+ export * from "./talkpilot/sessions";
10
+ export * from "./municipal/cities";
11
+ export * from "./municipal/departmentsSubjects";
12
+ export * from "./municipal/muniIssues";
13
+ export * from "./municipal/streets";
14
+ export * from "./municipal/tickets";
15
+ export * from "./websitalk/scans";