@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.
- package/.cursor/rules/development.mdc +65 -65
- package/DEVELOPMENT.md +141 -141
- package/README.md +243 -190
- package/README_OLD.md +160 -160
- package/dist/municipal/tickets/tickets.statistics.getters.d.ts +4 -0
- package/dist/municipal/tickets/tickets.statistics.getters.d.ts.map +1 -1
- package/dist/municipal/tickets/tickets.statistics.getters.js +30 -3
- package/dist/municipal/tickets/tickets.statistics.getters.js.map +1 -1
- package/dist/talkpilot/calls/calls.dashboard.d.ts +3 -0
- package/dist/talkpilot/calls/calls.dashboard.d.ts.map +1 -0
- package/dist/talkpilot/calls/calls.dashboard.js +191 -0
- package/dist/talkpilot/calls/calls.dashboard.js.map +1 -0
- package/dist/talkpilot/calls/calls.statistics.getters.js +12 -15
- package/dist/talkpilot/calls/calls.statistics.getters.js.map +1 -1
- package/dist/talkpilot/calls/calls.statistics.types.d.ts +4 -1
- package/dist/talkpilot/calls/calls.statistics.types.d.ts.map +1 -1
- package/dist/talkpilot/flows/flows.schema.d.ts +3 -0
- package/dist/talkpilot/flows/flows.schema.d.ts.map +1 -1
- package/dist/talkpilot/flows/flows.schema.js +1 -0
- package/dist/talkpilot/flows/flows.schema.js.map +1 -1
- package/dist/talkpilot/flows/flows.types.d.ts +1 -0
- package/dist/talkpilot/flows/flows.types.d.ts.map +1 -1
- package/jest.config.js +20 -20
- package/package.json +46 -46
- package/src/connection.ts +54 -54
- package/src/index.ts +26 -26
- package/src/municipal/index.ts +22 -22
- package/src/municipal/muniIssues/__tests__/muniIssues.setters.spec.ts +92 -92
- package/src/municipal/muniIssues/__tests__/muniIssues.setup.spec.ts +92 -92
- package/src/municipal/muniIssues/index.ts +17 -17
- package/src/municipal/muniIssues/muniIssues.constants.ts +18 -18
- package/src/municipal/muniIssues/muniIssues.getters.ts +24 -24
- package/src/municipal/muniIssues/muniIssues.schema.ts +66 -66
- package/src/municipal/muniIssues/muniIssues.setters.ts +24 -24
- package/src/municipal/muniIssues/muniIssues.setup.ts +65 -65
- package/src/municipal/muniIssues/muniIssues.types.ts +37 -37
- package/src/municipal/tickets/__tests__/tickets.getters.spec.ts +30 -30
- package/src/municipal/tickets/__tests__/tickets.statistics.spec.ts +68 -51
- package/src/municipal/tickets/index.ts +3 -3
- package/src/municipal/tickets/tickets.constants.ts +8 -8
- package/src/municipal/tickets/tickets.getters.ts +121 -121
- package/src/municipal/tickets/tickets.statistics.aggregation.ts +96 -96
- package/src/municipal/tickets/tickets.statistics.getters.ts +109 -71
- package/src/municipal/tickets/tickets.types.ts +53 -53
- package/src/talkpilot/calls/__tests__/calls.dashboard.spec.ts +149 -149
- package/src/talkpilot/calls/__tests__/calls.statistics.spec.ts +351 -344
- package/src/talkpilot/calls/calls.constants.ts +20 -20
- package/src/talkpilot/calls/calls.statistics.getters.ts +587 -587
- package/src/talkpilot/calls/calls.statistics.types.ts +47 -44
- package/src/talkpilot/calls/calls.types.ts +119 -119
- package/src/talkpilot/calls/dashboard/calls.dashboard.ts +292 -292
- package/src/talkpilot/calls/dashboard/calls.dashboard.types.ts +57 -57
- package/src/talkpilot/calls/index.ts +6 -6
- package/src/talkpilot/clientsConfig/__tests__/clientsConfig.spec.ts +190 -190
- package/src/talkpilot/contextNotes/__tests__/contextNotes.getters.spec.ts +176 -176
- package/src/talkpilot/contextNotes/contextNotes.getters.ts +86 -86
- package/src/talkpilot/contextNotes/contextNotes.types.ts +20 -20
- package/src/talkpilot/contextNotes/index.ts +2 -2
- package/src/talkpilot/flows/__tests__/flows.schema.spec.ts +96 -71
- package/src/talkpilot/flows/flows.schema.ts +154 -153
- package/src/talkpilot/flows/flows.types.ts +187 -186
- package/src/talkpilot/index.ts +31 -31
- package/src/talkpilot/products/__tests__/products.getters.spec.ts +45 -45
- package/src/talkpilot/products/index.ts +2 -2
- package/src/talkpilot/products/products.getters.ts +12 -12
- package/src/talkpilot/products/products.types.ts +9 -9
- package/src/test-utils/db-utils.ts +26 -26
- package/src/test-utils/factories/index.ts +15 -15
- package/src/test-utils/factories/municipal/muniIssues.ts +32 -32
- package/src/test-utils/factories/talkpilot/contextNotes.ts +33 -33
- package/src/test-utils/factories/websitalk/scans.ts +23 -23
- package/src/utils/date.utils.ts +116 -116
- package/src/websitalk/index.ts +15 -15
- package/src/websitalk/mongodb-client.ts +61 -61
- package/src/websitalk/scans/__tests__/scans.spec.ts +218 -218
- package/src/websitalk/scans/index.ts +2 -2
- package/src/websitalk/scans/scans.getters.ts +113 -113
- package/src/websitalk/scans/scans.types.ts +53 -53
- package/tsconfig.json +23 -23
|
@@ -1,186 +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
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
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
|
+
};
|
package/src/talkpilot/index.ts
CHANGED
|
@@ -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";
|