@talkpilot/core-db 1.1.14 → 1.1.16

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 (291) hide show
  1. package/.cursor/rules/development.mdc +65 -65
  2. package/DEVELOPMENT.md +141 -98
  3. package/README.md +297 -160
  4. package/README_OLD.md +160 -0
  5. package/dist/connection.d.ts.map +1 -1
  6. package/dist/connection.js +10 -0
  7. package/dist/connection.js.map +1 -1
  8. package/dist/index.d.ts +4 -0
  9. package/dist/index.d.ts.map +1 -1
  10. package/dist/index.js +8 -1
  11. package/dist/index.js.map +1 -1
  12. package/dist/municipal/index.d.ts +1 -0
  13. package/dist/municipal/index.d.ts.map +1 -1
  14. package/dist/municipal/index.js +1 -0
  15. package/dist/municipal/index.js.map +1 -1
  16. package/dist/municipal/muniIssues/index.d.ts +7 -0
  17. package/dist/municipal/muniIssues/index.d.ts.map +1 -0
  18. package/dist/municipal/muniIssues/index.js +29 -0
  19. package/dist/municipal/muniIssues/index.js.map +1 -0
  20. package/dist/municipal/muniIssues/muniIssues.constants.d.ts +14 -0
  21. package/dist/municipal/muniIssues/muniIssues.constants.d.ts.map +1 -0
  22. package/dist/municipal/muniIssues/muniIssues.constants.js +17 -0
  23. package/dist/municipal/muniIssues/muniIssues.constants.js.map +1 -0
  24. package/dist/municipal/muniIssues/muniIssues.getters.d.ts +7 -0
  25. package/dist/municipal/muniIssues/muniIssues.getters.d.ts.map +1 -0
  26. package/dist/municipal/muniIssues/muniIssues.getters.js +24 -0
  27. package/dist/municipal/muniIssues/muniIssues.getters.js.map +1 -0
  28. package/dist/municipal/muniIssues/muniIssues.schema.d.ts +4 -0
  29. package/dist/municipal/muniIssues/muniIssues.schema.d.ts.map +1 -0
  30. package/dist/municipal/muniIssues/muniIssues.schema.js +63 -0
  31. package/dist/municipal/muniIssues/muniIssues.schema.js.map +1 -0
  32. package/dist/municipal/muniIssues/muniIssues.setters.d.ts +4 -0
  33. package/dist/municipal/muniIssues/muniIssues.setters.d.ts.map +1 -0
  34. package/dist/municipal/muniIssues/muniIssues.setters.js +22 -0
  35. package/dist/municipal/muniIssues/muniIssues.setters.js.map +1 -0
  36. package/dist/municipal/muniIssues/muniIssues.setup.d.ts +3 -0
  37. package/dist/municipal/muniIssues/muniIssues.setup.d.ts.map +1 -0
  38. package/dist/municipal/muniIssues/muniIssues.setup.js +61 -0
  39. package/dist/municipal/muniIssues/muniIssues.setup.js.map +1 -0
  40. package/dist/municipal/muniIssues/muniIssues.types.d.ts +30 -0
  41. package/dist/municipal/muniIssues/muniIssues.types.d.ts.map +1 -0
  42. package/dist/municipal/muniIssues/muniIssues.types.js +3 -0
  43. package/dist/municipal/muniIssues/muniIssues.types.js.map +1 -0
  44. package/dist/municipal/tickets/index.d.ts +2 -1
  45. package/dist/municipal/tickets/index.d.ts.map +1 -1
  46. package/dist/municipal/tickets/index.js +1 -0
  47. package/dist/municipal/tickets/index.js.map +1 -1
  48. package/dist/municipal/tickets/tickets.constants.d.ts +7 -0
  49. package/dist/municipal/tickets/tickets.constants.d.ts.map +1 -0
  50. package/dist/municipal/tickets/tickets.constants.js +10 -0
  51. package/dist/municipal/tickets/tickets.constants.js.map +1 -0
  52. package/dist/municipal/tickets/tickets.getters.d.ts +0 -11
  53. package/dist/municipal/tickets/tickets.getters.d.ts.map +1 -1
  54. package/dist/municipal/tickets/tickets.getters.js +0 -128
  55. package/dist/municipal/tickets/tickets.getters.js.map +1 -1
  56. package/dist/municipal/tickets/tickets.statistics.aggregation.d.ts +69 -0
  57. package/dist/municipal/tickets/tickets.statistics.aggregation.d.ts.map +1 -0
  58. package/dist/municipal/tickets/tickets.statistics.aggregation.js +99 -0
  59. package/dist/municipal/tickets/tickets.statistics.aggregation.js.map +1 -0
  60. package/dist/municipal/tickets/tickets.statistics.getters.d.ts +12 -0
  61. package/dist/municipal/tickets/tickets.statistics.getters.d.ts.map +1 -0
  62. package/dist/municipal/tickets/tickets.statistics.getters.js +80 -0
  63. package/dist/municipal/tickets/tickets.statistics.getters.js.map +1 -0
  64. package/dist/municipal/tickets/tickets.types.d.ts +15 -5
  65. package/dist/municipal/tickets/tickets.types.d.ts.map +1 -1
  66. package/dist/talkpilot/calls/calls.constants.d.ts +17 -0
  67. package/dist/talkpilot/calls/calls.constants.d.ts.map +1 -0
  68. package/dist/talkpilot/calls/calls.constants.js +20 -0
  69. package/dist/talkpilot/calls/calls.constants.js.map +1 -0
  70. package/dist/talkpilot/calls/calls.dashboard.d.ts +3 -0
  71. package/dist/talkpilot/calls/calls.dashboard.d.ts.map +1 -0
  72. package/dist/talkpilot/calls/calls.dashboard.js +191 -0
  73. package/dist/talkpilot/calls/calls.dashboard.js.map +1 -0
  74. package/dist/talkpilot/calls/calls.getters.d.ts +3 -2
  75. package/dist/talkpilot/calls/calls.getters.d.ts.map +1 -1
  76. package/dist/talkpilot/calls/calls.getters.js +1 -2
  77. package/dist/talkpilot/calls/calls.getters.js.map +1 -1
  78. package/dist/talkpilot/calls/calls.statistics.getters.d.ts +28 -0
  79. package/dist/talkpilot/calls/calls.statistics.getters.d.ts.map +1 -0
  80. package/dist/talkpilot/calls/calls.statistics.getters.js +453 -0
  81. package/dist/talkpilot/calls/calls.statistics.getters.js.map +1 -0
  82. package/dist/talkpilot/calls/calls.statistics.types.d.ts +43 -0
  83. package/dist/talkpilot/calls/calls.statistics.types.d.ts.map +1 -0
  84. package/dist/talkpilot/calls/calls.statistics.types.js +3 -0
  85. package/dist/talkpilot/calls/calls.statistics.types.js.map +1 -0
  86. package/dist/talkpilot/calls/calls.types.d.ts +8 -7
  87. package/dist/talkpilot/calls/calls.types.d.ts.map +1 -1
  88. package/dist/talkpilot/calls/calls.types.js +0 -3
  89. package/dist/talkpilot/calls/calls.types.js.map +1 -1
  90. package/dist/talkpilot/calls/dashboard/calls.dashboard.d.ts +4 -0
  91. package/dist/talkpilot/calls/dashboard/calls.dashboard.d.ts.map +1 -0
  92. package/dist/talkpilot/calls/dashboard/calls.dashboard.js +223 -0
  93. package/dist/talkpilot/calls/dashboard/calls.dashboard.js.map +1 -0
  94. package/dist/talkpilot/calls/dashboard/calls.dashboard.types.d.ts +45 -0
  95. package/dist/talkpilot/calls/dashboard/calls.dashboard.types.d.ts.map +1 -0
  96. package/dist/talkpilot/calls/dashboard/calls.dashboard.types.js +3 -0
  97. package/dist/talkpilot/calls/dashboard/calls.dashboard.types.js.map +1 -0
  98. package/dist/talkpilot/calls/index.d.ts +4 -0
  99. package/dist/talkpilot/calls/index.d.ts.map +1 -1
  100. package/dist/talkpilot/calls/index.js +4 -0
  101. package/dist/talkpilot/calls/index.js.map +1 -1
  102. package/dist/talkpilot/clientsConfig/clientsConfig.getters.d.ts +2 -1
  103. package/dist/talkpilot/clientsConfig/clientsConfig.getters.d.ts.map +1 -1
  104. package/dist/talkpilot/clientsConfig/clientsConfig.getters.js +14 -0
  105. package/dist/talkpilot/clientsConfig/clientsConfig.getters.js.map +1 -1
  106. package/dist/talkpilot/clientsConfig/clientsConfig.types.d.ts +20 -7
  107. package/dist/talkpilot/clientsConfig/clientsConfig.types.d.ts.map +1 -1
  108. package/dist/talkpilot/clientsConfig/clientsConfig.types.js +6 -0
  109. package/dist/talkpilot/clientsConfig/clientsConfig.types.js.map +1 -1
  110. package/dist/talkpilot/contextNotes/contextNotes.getters.d.ts +19 -0
  111. package/dist/talkpilot/contextNotes/contextNotes.getters.d.ts.map +1 -0
  112. package/dist/talkpilot/contextNotes/contextNotes.getters.js +55 -0
  113. package/dist/talkpilot/contextNotes/contextNotes.getters.js.map +1 -0
  114. package/dist/talkpilot/contextNotes/contextNotes.types.d.ts +19 -0
  115. package/dist/talkpilot/contextNotes/contextNotes.types.d.ts.map +1 -0
  116. package/dist/talkpilot/contextNotes/contextNotes.types.js +3 -0
  117. package/dist/talkpilot/contextNotes/contextNotes.types.js.map +1 -0
  118. package/dist/talkpilot/contextNotes/index.d.ts +3 -0
  119. package/dist/talkpilot/contextNotes/index.d.ts.map +1 -0
  120. package/dist/talkpilot/contextNotes/index.js +19 -0
  121. package/dist/talkpilot/contextNotes/index.js.map +1 -0
  122. package/dist/talkpilot/flows/flows.schema.d.ts +3 -0
  123. package/dist/talkpilot/flows/flows.schema.d.ts.map +1 -1
  124. package/dist/talkpilot/flows/flows.schema.js +2 -1
  125. package/dist/talkpilot/flows/flows.schema.js.map +1 -1
  126. package/dist/talkpilot/flows/flows.types.d.ts +2 -0
  127. package/dist/talkpilot/flows/flows.types.d.ts.map +1 -1
  128. package/dist/talkpilot/index.d.ts +3 -0
  129. package/dist/talkpilot/index.d.ts.map +1 -1
  130. package/dist/talkpilot/index.js +3 -0
  131. package/dist/talkpilot/index.js.map +1 -1
  132. package/dist/talkpilot/phone_numbers/index.d.ts +2 -2
  133. package/dist/talkpilot/phone_numbers/phone_numbers.getter.d.ts +1 -1
  134. package/dist/talkpilot/phone_numbers/phone_numbers.getter.d.ts.map +1 -1
  135. package/dist/talkpilot/phone_numbers/phone_numbers.getter.js +5 -3
  136. package/dist/talkpilot/phone_numbers/phone_numbers.getter.js.map +1 -1
  137. package/dist/talkpilot/phone_numbers/phone_numbers.schema.js +12 -12
  138. package/dist/talkpilot/phone_numbers/phone_numbers.types.d.ts +4 -4
  139. package/dist/talkpilot/products/index.d.ts +3 -0
  140. package/dist/talkpilot/products/index.d.ts.map +1 -0
  141. package/dist/talkpilot/products/index.js +19 -0
  142. package/dist/talkpilot/products/index.js.map +1 -0
  143. package/dist/talkpilot/products/products.getters.d.ts +6 -0
  144. package/dist/talkpilot/products/products.getters.d.ts.map +1 -0
  145. package/dist/talkpilot/products/products.getters.js +14 -0
  146. package/dist/talkpilot/products/products.getters.js.map +1 -0
  147. package/dist/talkpilot/products/products.types.d.ts +9 -0
  148. package/dist/talkpilot/products/products.types.d.ts.map +1 -0
  149. package/dist/talkpilot/products/products.types.js +3 -0
  150. package/dist/talkpilot/products/products.types.js.map +1 -0
  151. package/dist/talkpilot/results/index.d.ts +1 -1
  152. package/dist/talkpilot/results/index.d.ts.map +1 -1
  153. package/dist/talkpilot/results/index.js +3 -1
  154. package/dist/talkpilot/results/index.js.map +1 -1
  155. package/dist/talkpilot/results/results.getter.d.ts +3 -1
  156. package/dist/talkpilot/results/results.getter.d.ts.map +1 -1
  157. package/dist/talkpilot/results/results.getter.js +11 -2
  158. package/dist/talkpilot/results/results.getter.js.map +1 -1
  159. package/dist/talkpilot/retry_analyze/index.d.ts +3 -0
  160. package/dist/talkpilot/retry_analyze/index.d.ts.map +1 -0
  161. package/dist/talkpilot/retry_analyze/index.js +19 -0
  162. package/dist/talkpilot/retry_analyze/index.js.map +1 -0
  163. package/dist/talkpilot/retry_analyze/retryAnalyze.getters.d.ts +10 -0
  164. package/dist/talkpilot/retry_analyze/retryAnalyze.getters.d.ts.map +1 -0
  165. package/dist/talkpilot/retry_analyze/retryAnalyze.getters.js +60 -0
  166. package/dist/talkpilot/retry_analyze/retryAnalyze.getters.js.map +1 -0
  167. package/dist/talkpilot/retry_analyze/retryAnalyze.types.d.ts +12 -0
  168. package/dist/talkpilot/retry_analyze/retryAnalyze.types.d.ts.map +1 -0
  169. package/dist/talkpilot/retry_analyze/retryAnalyze.types.js +3 -0
  170. package/dist/talkpilot/retry_analyze/retryAnalyze.types.js.map +1 -0
  171. package/dist/test-utils/db-utils.d.ts.map +1 -1
  172. package/dist/test-utils/db-utils.js +2 -0
  173. package/dist/test-utils/db-utils.js.map +1 -1
  174. package/dist/test-utils/factories/index.d.ts +3 -0
  175. package/dist/test-utils/factories/index.d.ts.map +1 -1
  176. package/dist/test-utils/factories/index.js +3 -0
  177. package/dist/test-utils/factories/index.js.map +1 -1
  178. package/dist/test-utils/factories/municipal/muniIssues.d.ts +10 -0
  179. package/dist/test-utils/factories/municipal/muniIssues.d.ts.map +1 -0
  180. package/dist/test-utils/factories/municipal/muniIssues.js +30 -0
  181. package/dist/test-utils/factories/municipal/muniIssues.js.map +1 -0
  182. package/dist/test-utils/factories/talkpilot/contextNotes.d.ts +16 -0
  183. package/dist/test-utils/factories/talkpilot/contextNotes.d.ts.map +1 -0
  184. package/dist/test-utils/factories/talkpilot/contextNotes.js +33 -0
  185. package/dist/test-utils/factories/talkpilot/contextNotes.js.map +1 -0
  186. package/dist/test-utils/factories/websitalk/scans.d.ts +5 -0
  187. package/dist/test-utils/factories/websitalk/scans.d.ts.map +1 -0
  188. package/dist/test-utils/factories/websitalk/scans.js +25 -0
  189. package/dist/test-utils/factories/websitalk/scans.js.map +1 -0
  190. package/dist/utils/date.utils.d.ts +49 -0
  191. package/dist/utils/date.utils.d.ts.map +1 -0
  192. package/dist/utils/date.utils.js +108 -0
  193. package/dist/utils/date.utils.js.map +1 -0
  194. package/dist/utils/shared.types.d.ts +5 -0
  195. package/dist/utils/shared.types.d.ts.map +1 -0
  196. package/dist/utils/shared.types.js +3 -0
  197. package/dist/utils/shared.types.js.map +1 -0
  198. package/dist/websitalk/index.d.ts +7 -0
  199. package/dist/websitalk/index.d.ts.map +1 -0
  200. package/dist/websitalk/index.js +34 -0
  201. package/dist/websitalk/index.js.map +1 -0
  202. package/dist/websitalk/mongodb-client.d.ts +13 -0
  203. package/dist/websitalk/mongodb-client.d.ts.map +1 -0
  204. package/dist/websitalk/mongodb-client.js +56 -0
  205. package/dist/websitalk/mongodb-client.js.map +1 -0
  206. package/dist/websitalk/scans/index.d.ts +3 -0
  207. package/dist/websitalk/scans/index.d.ts.map +1 -0
  208. package/dist/websitalk/scans/index.js +19 -0
  209. package/dist/websitalk/scans/index.js.map +1 -0
  210. package/dist/websitalk/scans/scans.getters.d.ts +12 -0
  211. package/dist/websitalk/scans/scans.getters.d.ts.map +1 -0
  212. package/dist/websitalk/scans/scans.getters.js +74 -0
  213. package/dist/websitalk/scans/scans.getters.js.map +1 -0
  214. package/dist/websitalk/scans/scans.types.d.ts +45 -0
  215. package/dist/websitalk/scans/scans.types.d.ts.map +1 -0
  216. package/dist/websitalk/scans/scans.types.js +3 -0
  217. package/dist/websitalk/scans/scans.types.js.map +1 -0
  218. package/jest.config.js +20 -19
  219. package/package.json +46 -45
  220. package/src/connection.ts +12 -0
  221. package/src/index.ts +10 -0
  222. package/src/municipal/index.ts +1 -0
  223. package/src/municipal/muniIssues/__tests__/muniIssues.setters.spec.ts +94 -0
  224. package/src/municipal/muniIssues/__tests__/muniIssues.setup.spec.ts +92 -0
  225. package/src/municipal/muniIssues/index.ts +17 -0
  226. package/src/municipal/muniIssues/muniIssues.constants.ts +18 -0
  227. package/src/municipal/muniIssues/muniIssues.getters.ts +24 -0
  228. package/src/municipal/muniIssues/muniIssues.schema.ts +66 -0
  229. package/src/municipal/muniIssues/muniIssues.setters.ts +24 -0
  230. package/src/municipal/muniIssues/muniIssues.setup.ts +65 -0
  231. package/src/municipal/muniIssues/muniIssues.types.ts +37 -0
  232. package/src/municipal/tickets/__tests__/tickets.getters.spec.ts +1 -37
  233. package/src/municipal/tickets/__tests__/tickets.statistics.spec.ts +99 -0
  234. package/src/municipal/tickets/index.ts +9 -2
  235. package/src/municipal/tickets/tickets.constants.ts +8 -0
  236. package/src/municipal/tickets/tickets.getters.ts +0 -140
  237. package/src/municipal/tickets/tickets.statistics.aggregation.ts +110 -0
  238. package/src/municipal/tickets/tickets.statistics.getters.ts +132 -0
  239. package/src/municipal/tickets/tickets.types.ts +54 -43
  240. package/src/talkpilot/calls/__tests__/calls.dashboard.spec.ts +149 -0
  241. package/src/talkpilot/calls/__tests__/calls.spec.ts +48 -30
  242. package/src/talkpilot/calls/__tests__/calls.statistics.spec.ts +481 -0
  243. package/src/talkpilot/calls/calls.constants.ts +20 -0
  244. package/src/talkpilot/calls/calls.getters.ts +6 -6
  245. package/src/talkpilot/calls/calls.statistics.getters.ts +668 -0
  246. package/src/talkpilot/calls/calls.statistics.types.ts +48 -0
  247. package/src/talkpilot/calls/calls.types.ts +18 -14
  248. package/src/talkpilot/calls/dashboard/calls.dashboard.ts +292 -0
  249. package/src/talkpilot/calls/dashboard/calls.dashboard.types.ts +57 -0
  250. package/src/talkpilot/calls/index.ts +4 -0
  251. package/src/talkpilot/clientsConfig/__tests__/clientsConfig.getters.spec.ts +53 -0
  252. package/src/talkpilot/clientsConfig/__tests__/clientsConfig.spec.ts +91 -7
  253. package/src/talkpilot/clientsConfig/clientsConfig.getters.ts +34 -1
  254. package/src/talkpilot/clientsConfig/clientsConfig.types.ts +127 -92
  255. package/src/talkpilot/contextNotes/__tests__/contextNotes.getters.spec.ts +217 -0
  256. package/src/talkpilot/contextNotes/contextNotes.getters.ts +85 -0
  257. package/src/talkpilot/contextNotes/contextNotes.types.ts +20 -0
  258. package/src/talkpilot/contextNotes/index.ts +2 -0
  259. package/src/talkpilot/flows/__tests__/flows.schema.spec.ts +31 -2
  260. package/src/talkpilot/flows/flows.schema.ts +2 -1
  261. package/src/talkpilot/flows/flows.types.ts +3 -0
  262. package/src/talkpilot/index.ts +3 -0
  263. package/src/talkpilot/phone_numbers/__tests__/phone_numbers.spec.ts +40 -35
  264. package/src/talkpilot/phone_numbers/index.ts +2 -2
  265. package/src/talkpilot/phone_numbers/phone_numbers.getter.ts +10 -6
  266. package/src/talkpilot/phone_numbers/phone_numbers.schema.ts +12 -12
  267. package/src/talkpilot/phone_numbers/phone_numbers.types.ts +4 -4
  268. package/src/talkpilot/products/__tests__/products.getters.spec.ts +44 -0
  269. package/src/talkpilot/products/index.ts +2 -0
  270. package/src/talkpilot/products/products.getters.ts +12 -0
  271. package/src/talkpilot/products/products.types.ts +9 -0
  272. package/src/talkpilot/results/index.ts +2 -0
  273. package/src/talkpilot/results/results.getter.ts +14 -2
  274. package/src/talkpilot/retry_analyze/__tests__/retryAnalyze.getters.spec.ts +156 -0
  275. package/src/talkpilot/retry_analyze/index.ts +2 -0
  276. package/src/talkpilot/retry_analyze/retryAnalyze.getters.ts +84 -0
  277. package/src/talkpilot/retry_analyze/retryAnalyze.types.ts +13 -0
  278. package/src/test-utils/db-utils.ts +3 -1
  279. package/src/test-utils/factories/index.ts +3 -0
  280. package/src/test-utils/factories/municipal/muniIssues.ts +32 -0
  281. package/src/test-utils/factories/talkpilot/contextNotes.ts +40 -0
  282. package/src/test-utils/factories/websitalk/scans.ts +23 -0
  283. package/src/utils/date.utils.ts +126 -0
  284. package/src/utils/shared.types.ts +4 -0
  285. package/src/websitalk/index.ts +15 -0
  286. package/src/websitalk/mongodb-client.ts +61 -0
  287. package/src/websitalk/scans/__tests__/scans.spec.ts +218 -0
  288. package/src/websitalk/scans/index.ts +2 -0
  289. package/src/websitalk/scans/scans.getters.ts +113 -0
  290. package/src/websitalk/scans/scans.types.ts +53 -0
  291. package/tsconfig.json +23 -23
@@ -6,14 +6,14 @@ import {
6
6
  getClientPhoneData,
7
7
  createPhoneNumberEntity,
8
8
  createPurchasedPhoneNumber,
9
- } from '../phone_numbers.getter';
10
- import { getFlowsCollection } from '../../flows/flows.getter';
11
- import { createFlow, createPhoneNumber } from '../../../test-utils/factories';
12
- import { ObjectId } from 'mongodb';
13
-
14
- describe('db.phoneNumbers', () => {
15
- describe('getPhoneDataByPhoneNumber', () => {
16
- it('return phone number data with flow', async () => {
9
+ } from "../phone_numbers.getter";
10
+ import { getFlowsCollection } from "../../flows/flows.getter";
11
+ import { createFlow, createPhoneNumber } from "../../../test-utils/factories";
12
+ import { ObjectId } from "mongodb";
13
+
14
+ describe("db.phoneNumbers", () => {
15
+ describe("getPhoneDataByPhoneNumber", () => {
16
+ it("return phone number data with flow", async () => {
17
17
  const flow = createFlow({
18
18
  clientId: "test-client-id",
19
19
  conversationSettings: {
@@ -129,9 +129,9 @@ describe('db.phoneNumbers', () => {
129
129
  });
130
130
  });
131
131
 
132
- describe('getPhoneNumbersForFlows', () => {
133
- it('returns all phone numbers for the client with flow ObjectIds, newest first', async () => {
134
- const clientId = 'flowsClient';
132
+ describe("getPhoneNumbersForFlows", () => {
133
+ it("returns all phone numbers for the client with flow ObjectIds, newest first", async () => {
134
+ const clientId = "flowsClient";
135
135
  const flow1 = createFlow({ clientId });
136
136
  const flow2 = createFlow({ clientId });
137
137
  await getFlowsCollection().insertMany([flow1, flow2]);
@@ -139,16 +139,16 @@ describe('db.phoneNumbers', () => {
139
139
  const older = createPhoneNumber({
140
140
  client_id: clientId,
141
141
  flow_id: flow1._id,
142
- phone_number: '+100',
142
+ phone_number: "+100",
143
143
  is_primary: true,
144
- createdAt: new Date('2023-01-01'),
144
+ createdAt: new Date("2023-01-01"),
145
145
  });
146
146
  const newer = createPhoneNumber({
147
147
  client_id: clientId,
148
148
  flow_id: flow2._id,
149
- phone_number: '+200',
149
+ phone_number: "+200",
150
150
  is_primary: false,
151
- createdAt: new Date('2023-06-01'),
151
+ createdAt: new Date("2023-06-01"),
152
152
  });
153
153
 
154
154
  await getPhoneNumbersCollection().insertMany([older, newer]);
@@ -158,27 +158,30 @@ describe('db.phoneNumbers', () => {
158
158
  expect(result).toHaveLength(2);
159
159
  expect(result[0]).toEqual({
160
160
  flowId: String(flow2._id),
161
- phoneNumber: '+200',
161
+ phoneNumber: "+200",
162
162
  isPrimary: false,
163
163
  });
164
164
  expect(result[1]).toEqual({
165
165
  flowId: String(flow1._id),
166
- phoneNumber: '+100',
166
+ phoneNumber: "+100",
167
167
  isPrimary: true,
168
168
  });
169
169
  });
170
170
 
171
- it('returns an empty array when the client has no phone numbers', async () => {
172
- const result = await getPhoneNumbersForFlows('noSuchClient');
171
+ it("returns an empty array when the client has no phone numbers", async () => {
172
+ const result = await getPhoneNumbersForFlows("noSuchClient");
173
173
  expect(result).toEqual([]);
174
174
  });
175
175
 
176
- it('does not include phone numbers for other clients', async () => {
177
- const clientA = 'clientA';
178
- const clientB = 'clientB';
176
+ it("does not include phone numbers for other clients", async () => {
177
+ const clientA = "clientA";
178
+ const clientB = "clientB";
179
179
  const flow = createFlow();
180
180
  await getFlowsCollection().insertOne(flow);
181
- const phone = createPhoneNumber({ client_id: clientA, flow_id: flow._id });
181
+ const phone = createPhoneNumber({
182
+ client_id: clientA,
183
+ flow_id: flow._id,
184
+ });
182
185
  await getPhoneNumbersCollection().insertOne(phone);
183
186
 
184
187
  const result = await getPhoneNumbersForFlows(clientB);
@@ -186,9 +189,9 @@ describe('db.phoneNumbers', () => {
186
189
  });
187
190
  });
188
191
 
189
- describe('createPhoneNumberEntity', () => {
190
- it('creates first phone number as primary', async () => {
191
- const clientId = 'newClient';
192
+ describe("createPhoneNumberEntity", () => {
193
+ it("creates first phone number as primary", async () => {
194
+ const clientId = "newClient";
192
195
  const flowId = new ObjectId().toHexString();
193
196
  const phoneNumber = "+123456789";
194
197
 
@@ -215,14 +218,14 @@ describe('db.phoneNumbers', () => {
215
218
  });
216
219
  });
217
220
 
218
- describe('createPurchasedPhoneNumber', () => {
219
- it('persists a phone_numbers document with provider payload and flow', async () => {
220
- const clientId = 'purchasedClientDb';
221
+ describe("createPurchasedPhoneNumber", () => {
222
+ it("persists a phone_numbers document with provider payload and flow", async () => {
223
+ const clientId = "purchasedClientDb";
221
224
  const flowId = new ObjectId().toHexString();
222
- const phoneNumber = '+15551234567';
225
+ const phoneNumber = "+15551234567";
223
226
  const providerPayload = {
224
- provider: 'twilio' as const,
225
- provider_sid: 'PNxxxxxxxx',
227
+ provider: "twilio" as const,
228
+ provider_sid: "PNxxxxxxxx",
226
229
  };
227
230
 
228
231
  await createPurchasedPhoneNumber(
@@ -233,13 +236,15 @@ describe('db.phoneNumbers', () => {
233
236
  );
234
237
 
235
238
  // Re-read from Mongo to confirm insert succeeded (not only the function return value).
236
- const stored = await getPhoneNumbersCollection().findOne({ phone_number: phoneNumber });
239
+ const stored = await getPhoneNumbersCollection().findOne({
240
+ phone_number: phoneNumber,
241
+ });
237
242
  expect(stored).not.toBeNull();
238
243
  expect(stored).toMatchObject({
239
244
  phone_number: phoneNumber,
240
245
  client_id: clientId,
241
- provider: 'twilio',
242
- provider_sid: 'PNxxxxxxxx',
246
+ provider: "twilio",
247
+ provider_sid: "PNxxxxxxxx",
243
248
  flow_id: new ObjectId(flowId),
244
249
  });
245
250
  });
@@ -1,2 +1,2 @@
1
- export * from './phone_numbers.getter';
2
- export type * from './phone_numbers.types';
1
+ export * from "./phone_numbers.getter";
2
+ export type * from "./phone_numbers.types";
@@ -6,12 +6,12 @@ import {
6
6
  getFlowsCollection,
7
7
  ObjectId,
8
8
  findSubscriptions,
9
- } from '../index';
9
+ } from "../index";
10
10
  import {
11
11
  ClientPhoneNumberForFlow,
12
12
  PhoneNumber,
13
13
  PhoneNumberWithFlow,
14
- PurchasedPhoneProviderPayload
14
+ PurchasedPhoneProviderPayload,
15
15
  } from "./phone_numbers.types";
16
16
 
17
17
  export const getPhoneNumbersCollection = (): Collection<PhoneNumber> =>
@@ -140,13 +140,17 @@ export const createPurchasedPhoneNumber = async (
140
140
  await getPhoneNumbersCollection().insertOne(doc);
141
141
 
142
142
  const created = await getClientPhoneData(clientId, isPrimary);
143
- if (!created) throw new Error('Failed to create phoneNumber');
143
+ if (!created) throw new Error("Failed to create phoneNumber");
144
144
  return created;
145
145
  };
146
146
 
147
- export const findClientByPhoneNumber = async (phoneNumber: string): Promise<Client> => {
148
- const phoneData = await getPhoneNumbersCollection().findOne({ phone_number: phoneNumber });
149
- if (!phoneData) throw new Error('Failed to get phone data');
147
+ export const findClientByPhoneNumber = async (
148
+ phoneNumber: string,
149
+ ): Promise<Client> => {
150
+ const phoneData = await getPhoneNumbersCollection().findOne({
151
+ phone_number: phoneNumber,
152
+ });
153
+ if (!phoneData) throw new Error("Failed to get phone data");
150
154
  const clientId = phoneData.client_id;
151
155
  const client = await getClientsCollection().findOne({ clientId });
152
156
  if (!client) throw new Error("Failed to get client");
@@ -1,17 +1,17 @@
1
1
  export const phoneNumbersMongoSchema = {
2
- bsonType: 'object',
3
- required: ['client_id', 'phone_number'],
2
+ bsonType: "object",
3
+ required: ["client_id", "phone_number"],
4
4
  properties: {
5
- _id: { bsonType: 'objectId' },
6
- client_id: { bsonType: 'string' },
7
- flow_id: { bsonType: ['objectId', 'string'] },
8
- phone_number: { bsonType: 'string' },
9
- is_primary: { bsonType: 'bool' },
10
- provider: { bsonType: 'string' },
11
- provider_sid: { bsonType: 'string' },
12
- friendly_name: { bsonType: 'string' },
13
- createdAt: { bsonType: 'date' },
14
- updatedAt: { bsonType: 'date' },
5
+ _id: { bsonType: "objectId" },
6
+ client_id: { bsonType: "string" },
7
+ flow_id: { bsonType: ["objectId", "string"] },
8
+ phone_number: { bsonType: "string" },
9
+ is_primary: { bsonType: "bool" },
10
+ provider: { bsonType: "string" },
11
+ provider_sid: { bsonType: "string" },
12
+ friendly_name: { bsonType: "string" },
13
+ createdAt: { bsonType: "date" },
14
+ updatedAt: { bsonType: "date" },
15
15
  },
16
16
  additionalProperties: false,
17
17
  } as const;
@@ -1,8 +1,8 @@
1
- import { ObjectId, WithId } from 'mongodb';
2
- import { Flow } from '../flows/flows.types';
1
+ import { ObjectId, WithId } from "mongodb";
2
+ import { Flow } from "../flows/flows.types";
3
3
 
4
4
  export type PurchasedPhoneProviderPayload = {
5
- provider: 'twilio' | 'telnyx';
5
+ provider: "twilio" | "telnyx";
6
6
  provider_sid: string;
7
7
  friendly_name?: string;
8
8
  };
@@ -14,7 +14,7 @@ export type PhoneNumber = {
14
14
  phone_number: string;
15
15
  subscriptionId?: string;
16
16
  is_primary: boolean;
17
- provider?: 'twilio' | 'telnyx';
17
+ provider?: "twilio" | "telnyx";
18
18
  provider_sid?: string;
19
19
  friendly_name?: string;
20
20
  createdAt: Date;
@@ -0,0 +1,44 @@
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
+ });
@@ -0,0 +1,2 @@
1
+ export * from "./products.types";
2
+ export * from "./products.getters";
@@ -0,0 +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
+ };
@@ -0,0 +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,5 +1,7 @@
1
1
  export {
2
2
  getResultsCollection,
3
3
  initializeResultDocument,
4
+ findResultById,
5
+ findResultByCallSid,
4
6
  } from "./results.getter";
5
7
  export type * from "./results.types";
@@ -1,5 +1,5 @@
1
- import type { Collection } from "mongodb";
2
- import { getDb, ObjectId, Session } from "../index";
1
+ import { Collection, ObjectId } from "mongodb";
2
+ import { getDb, Session } from "../index";
3
3
  import type { Result } from "./results.types";
4
4
 
5
5
  export const getResultsCollection = (): Collection<Result> =>
@@ -25,3 +25,15 @@ export const initializeResultDocument = async (
25
25
  if (!result) throw new Error("Failed to initialized result");
26
26
  return result;
27
27
  };
28
+
29
+ export const findResultById = async (
30
+ resultId: string | ObjectId,
31
+ ): Promise<Result | null> => {
32
+ return getResultsCollection().findOne({ _id: new ObjectId(resultId) });
33
+ };
34
+
35
+ export const findResultByCallSid = async (
36
+ callSid: string,
37
+ ): Promise<Result | null> => {
38
+ return getResultsCollection().findOne({ "calls.callSid": callSid });
39
+ };
@@ -0,0 +1,156 @@
1
+ import { describe, it, expect, beforeEach, jest } from "@jest/globals";
2
+ import { ObjectId } from "mongodb";
3
+ import {
4
+ getAllRetryAnalyzeDocs,
5
+ upsertRetryAnalyzeDoc,
6
+ insertRetryAnalyzeDoc,
7
+ updateRetryAnalyzeErrorLog,
8
+ } from "../retryAnalyze.getters";
9
+ import { setDb } from "../../index";
10
+ import { RetryAnalyzeDoc } from "../retryAnalyze.types";
11
+
12
+ describe("retryAnalyze.getters", () => {
13
+ let mockCollection: any;
14
+ let mockDb: any;
15
+
16
+ beforeEach(() => {
17
+ mockCollection = {
18
+ find: jest.fn().mockReturnThis(),
19
+ toArray: jest.fn(),
20
+ insertOne: jest.fn(),
21
+ updateOne: jest.fn(),
22
+ deleteOne: jest.fn(),
23
+ };
24
+ mockDb = {
25
+ collection: jest.fn().mockReturnValue(mockCollection),
26
+ };
27
+ setDb(mockDb as any);
28
+ });
29
+
30
+ describe("getAllRetryAnalyzeDocs", () => {
31
+ it("should filter documents with retry >= 5 and include old format docs", async () => {
32
+ const mockDocs = [
33
+ { _id: new ObjectId(), callSid: "old-doc", errorLog: "{}" },
34
+ { _id: new ObjectId(), callSid: "retry-1", errorLog: "{}", retry: 1 },
35
+ { _id: new ObjectId(), callSid: "retry-5", errorLog: "{}", retry: 5 },
36
+ ];
37
+
38
+ mockCollection.toArray.mockResolvedValue(mockDocs);
39
+
40
+ await getAllRetryAnalyzeDocs();
41
+
42
+ expect(mockCollection.find).toHaveBeenCalledWith({
43
+ $or: [{ retry: { $lt: 5 } }, { retry: { $exists: false } }],
44
+ });
45
+ });
46
+ });
47
+
48
+ describe("upsertRetryAnalyzeDoc", () => {
49
+ const error429 = JSON.stringify({
50
+ error: {
51
+ code: 429,
52
+ message: "Resource exhausted. Please try again later.",
53
+ status: "RESOURCE_EXHAUSTED",
54
+ },
55
+ });
56
+
57
+ it("should upsert document correctly with $setOnInsert for clientId and createdAt", async () => {
58
+ const doc = {
59
+ callSid: "call-123",
60
+ errorLog: error429,
61
+ clientId: "client-1",
62
+ };
63
+
64
+ mockCollection.updateOne.mockResolvedValue({
65
+ upsertedId: new ObjectId(),
66
+ matchedCount: 0,
67
+ });
68
+
69
+ await upsertRetryAnalyzeDoc(doc);
70
+
71
+ expect(mockCollection.updateOne).toHaveBeenCalledWith(
72
+ { callSid: doc.callSid },
73
+ expect.objectContaining({
74
+ $set: expect.objectContaining({
75
+ errorLog: doc.errorLog,
76
+ updatedAt: expect.any(Date),
77
+ }),
78
+ $setOnInsert: expect.objectContaining({
79
+ createdAt: expect.any(Date),
80
+ clientId: doc.clientId,
81
+ retry: 0,
82
+ }),
83
+ }),
84
+ { upsert: true },
85
+ );
86
+ });
87
+
88
+ it("should ensure only one document exists for the same callSid even on multiple failures", async () => {
89
+ const doc = {
90
+ callSid: "CA_SINGLE_DOC",
91
+ errorLog: error429,
92
+ clientId: "client-1",
93
+ };
94
+
95
+ mockCollection.updateOne
96
+ .mockResolvedValueOnce({ upsertedId: new ObjectId(), matchedCount: 0 })
97
+ .mockResolvedValueOnce({ upsertedId: null, matchedCount: 1 });
98
+
99
+ await upsertRetryAnalyzeDoc(doc);
100
+ await upsertRetryAnalyzeDoc(doc);
101
+
102
+ expect(mockCollection.updateOne).toHaveBeenCalledWith(
103
+ { callSid: doc.callSid },
104
+ expect.objectContaining({
105
+ $setOnInsert: expect.objectContaining({ retry: 0 }),
106
+ }),
107
+ { upsert: true },
108
+ );
109
+
110
+ expect(mockCollection.updateOne).toHaveBeenLastCalledWith(
111
+ { callSid: doc.callSid },
112
+ { $inc: { retry: 1 } },
113
+ );
114
+ });
115
+ });
116
+
117
+ describe("insertRetryAnalyzeDoc", () => {
118
+ it("should perform a simple insert", async () => {
119
+ const doc: Omit<RetryAnalyzeDoc, "_id"> = {
120
+ callSid: "call-456",
121
+ retry: 0,
122
+ clientId: "client-2",
123
+ errorLog: "err",
124
+ updatedAt: new Date(),
125
+ createdAt: new Date(),
126
+ };
127
+
128
+ mockCollection.insertOne.mockResolvedValue({
129
+ insertedId: new ObjectId(),
130
+ });
131
+
132
+ await insertRetryAnalyzeDoc(doc);
133
+
134
+ expect(mockCollection.insertOne).toHaveBeenCalledWith(doc);
135
+ });
136
+ });
137
+
138
+ describe("updateRetryAnalyzeErrorLog", () => {
139
+ it("should update errorLog, updatedAt and increment retry", async () => {
140
+ const id = new ObjectId();
141
+ const errorLog = "new retry error";
142
+
143
+ mockCollection.updateOne.mockResolvedValue({ modifiedCount: 1 });
144
+
145
+ await updateRetryAnalyzeErrorLog(id, errorLog);
146
+
147
+ expect(mockCollection.updateOne).toHaveBeenCalledWith(
148
+ { _id: id },
149
+ {
150
+ $set: { errorLog, updatedAt: expect.any(Date) },
151
+ $inc: { retry: 1 },
152
+ },
153
+ );
154
+ });
155
+ });
156
+ });
@@ -0,0 +1,2 @@
1
+ export * from "./retryAnalyze.types";
2
+ export * from "./retryAnalyze.getters";
@@ -0,0 +1,84 @@
1
+ import { Collection, ObjectId } from "mongodb";
2
+ import { getDb } from "../index";
3
+ import type { RetryAnalyzeDoc, RetryAnalyzeWithId } from "./retryAnalyze.types";
4
+
5
+ const COLLECTION_NAME = "retryAnalyze";
6
+
7
+ export const getRetryAnalyzeCollection = (): Collection<RetryAnalyzeDoc> => {
8
+ return getDb().collection<RetryAnalyzeDoc>(COLLECTION_NAME);
9
+ };
10
+
11
+ export const getAllRetryAnalyzeDocs = async (): Promise<
12
+ RetryAnalyzeWithId[]
13
+ > => {
14
+ return getRetryAnalyzeCollection()
15
+ .find({
16
+ $or: [{ retry: { $lt: 5 } }, { retry: { $exists: false } }],
17
+ })
18
+ .toArray();
19
+ };
20
+
21
+ export const insertRetryAnalyzeDoc = async (
22
+ doc: Omit<RetryAnalyzeDoc, "_id">,
23
+ ): Promise<ObjectId> => {
24
+ const result = await getRetryAnalyzeCollection().insertOne(doc);
25
+ return result.insertedId;
26
+ };
27
+
28
+ export const upsertRetryAnalyzeDoc = async (
29
+ doc: Pick<RetryAnalyzeDoc, "callSid" | "errorLog" | "clientId">,
30
+ ): Promise<ObjectId | null> => {
31
+ const now = new Date();
32
+ const result = await getRetryAnalyzeCollection().updateOne(
33
+ { callSid: doc.callSid },
34
+ {
35
+ $set: {
36
+ errorLog: doc.errorLog,
37
+ updatedAt: now,
38
+ },
39
+ $setOnInsert: {
40
+ createdAt: now,
41
+ clientId: doc.clientId,
42
+ retry: 0,
43
+ },
44
+ },
45
+ { upsert: true },
46
+ );
47
+
48
+ if (result.matchedCount > 0) {
49
+ await getRetryAnalyzeCollection().updateOne(
50
+ { callSid: doc.callSid },
51
+ { $inc: { retry: 1 } },
52
+ );
53
+ }
54
+
55
+ return result.upsertedId || null;
56
+ };
57
+
58
+ export const deleteRetryAnalyzeDocById = async (
59
+ id: ObjectId,
60
+ ): Promise<boolean> => {
61
+ const result = await getRetryAnalyzeCollection().deleteOne({ _id: id });
62
+ return result.deletedCount === 1;
63
+ };
64
+
65
+ export const deleteRetryAnalyzeDocByCallSid = async (
66
+ callSid: string,
67
+ ): Promise<boolean> => {
68
+ const result = await getRetryAnalyzeCollection().deleteOne({ callSid });
69
+ return result.deletedCount === 1;
70
+ };
71
+
72
+ export const updateRetryAnalyzeErrorLog = async (
73
+ id: ObjectId,
74
+ errorLog: string,
75
+ ): Promise<boolean> => {
76
+ const result = await getRetryAnalyzeCollection().updateOne(
77
+ { _id: id },
78
+ {
79
+ $set: { errorLog, updatedAt: new Date() },
80
+ $inc: { retry: 1 },
81
+ },
82
+ );
83
+ return result.modifiedCount === 1;
84
+ };
@@ -0,0 +1,13 @@
1
+ import { ObjectId, WithId } from "mongodb";
2
+
3
+ export type RetryAnalyzeDoc = {
4
+ _id?: ObjectId;
5
+ callSid: string;
6
+ retry: number;
7
+ clientId: string;
8
+ errorLog: string;
9
+ updatedAt: Date;
10
+ createdAt: Date;
11
+ };
12
+
13
+ export type RetryAnalyzeWithId = WithId<RetryAnalyzeDoc>;
@@ -1,6 +1,6 @@
1
1
  import { MongoMemoryServer } from "mongodb-memory-server";
2
2
  import { MongoClient, Db } from "mongodb";
3
- import { setDb, setMunicipalDataDb } from "../index";
3
+ import { setDb, setMunicipalDataDb, setWebsitalkDb } from "../index";
4
4
 
5
5
  let mongoServer: MongoMemoryServer;
6
6
  let client: MongoClient;
@@ -13,8 +13,10 @@ export async function initTestDb(): Promise<Db> {
13
13
  await client.connect();
14
14
  const talkpilotDb = client.db();
15
15
  const municipalDb = client.db("municipal-data");
16
+ const websitalkDb = client.db("website-talk");
16
17
  setDb(talkpilotDb);
17
18
  setMunicipalDataDb(municipalDb);
19
+ setWebsitalkDb(websitalkDb);
18
20
  return talkpilotDb;
19
21
  }
20
22
 
@@ -3,10 +3,13 @@ export * from "./talkpilot/calls";
3
3
  export * from "./talkpilot/clientAudioBuffers";
4
4
  export * from "./talkpilot/clientsConfig";
5
5
  export * from "./talkpilot/flows";
6
+ export * from "./talkpilot/contextNotes";
6
7
  export * from "./talkpilot/groups";
7
8
  export * from "./talkpilot/phone_numbers";
8
9
  export * from "./talkpilot/sessions";
9
10
  export * from "./municipal/cities";
10
11
  export * from "./municipal/departmentsSubjects";
12
+ export * from "./municipal/muniIssues";
11
13
  export * from "./municipal/streets";
12
14
  export * from "./municipal/tickets";
15
+ export * from "./websitalk/scans";