@talkpilot/core-db 1.1.7 → 1.1.8

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (330) hide show
  1. package/dist/connection.d.ts +1 -1
  2. package/dist/connection.d.ts.map +1 -1
  3. package/dist/connection.js +24 -21
  4. package/dist/connection.js.map +1 -1
  5. package/dist/index.d.ts +9 -9
  6. package/dist/index.d.ts.map +1 -1
  7. package/dist/index.js.map +1 -1
  8. package/dist/municipal/cities/cities.getters.d.ts +2 -2
  9. package/dist/municipal/cities/cities.getters.d.ts.map +1 -1
  10. package/dist/municipal/cities/cities.getters.js +4 -8
  11. package/dist/municipal/cities/cities.getters.js.map +1 -1
  12. package/dist/municipal/cities/cities.types.d.ts +1 -1
  13. package/dist/municipal/cities/index.d.ts +2 -2
  14. package/dist/municipal/departmentsSubjects/departmentsSubjects.getters.d.ts +3 -3
  15. package/dist/municipal/departmentsSubjects/departmentsSubjects.getters.d.ts.map +1 -1
  16. package/dist/municipal/departmentsSubjects/departmentsSubjects.getters.js +22 -30
  17. package/dist/municipal/departmentsSubjects/departmentsSubjects.getters.js.map +1 -1
  18. package/dist/municipal/departmentsSubjects/departmentsSubjects.types.d.ts +4 -4
  19. package/dist/municipal/departmentsSubjects/departmentsSubjects.types.d.ts.map +1 -1
  20. package/dist/municipal/departmentsSubjects/index.d.ts +2 -2
  21. package/dist/municipal/index.d.ts +8 -8
  22. package/dist/municipal/index.d.ts.map +1 -1
  23. package/dist/municipal/index.js +1 -1
  24. package/dist/municipal/mongodb-client.d.ts +1 -1
  25. package/dist/municipal/mongodb-client.d.ts.map +1 -1
  26. package/dist/municipal/mongodb-client.js +7 -7
  27. package/dist/municipal/mongodb-client.js.map +1 -1
  28. package/dist/municipal/streets/index.d.ts +2 -2
  29. package/dist/municipal/streets/streets.getters.d.ts +3 -3
  30. package/dist/municipal/streets/streets.getters.d.ts.map +1 -1
  31. package/dist/municipal/streets/streets.getters.js +9 -19
  32. package/dist/municipal/streets/streets.getters.js.map +1 -1
  33. package/dist/municipal/streets/streets.types.d.ts +1 -1
  34. package/dist/municipal/systemInstructions/index.d.ts +3 -3
  35. package/dist/municipal/systemInstructions/index.d.ts.map +1 -1
  36. package/dist/municipal/systemInstructions/instructions.getters.d.ts +3 -3
  37. package/dist/municipal/systemInstructions/instructions.getters.d.ts.map +1 -1
  38. package/dist/municipal/systemInstructions/instructions.getters.js +4 -10
  39. package/dist/municipal/systemInstructions/instructions.getters.js.map +1 -1
  40. package/dist/municipal/systemInstructions/instructions.setters.d.ts +2 -2
  41. package/dist/municipal/systemInstructions/instructions.setters.d.ts.map +1 -1
  42. package/dist/municipal/systemInstructions/instructions.setters.js +8 -13
  43. package/dist/municipal/systemInstructions/instructions.setters.js.map +1 -1
  44. package/dist/municipal/systemInstructions/instructions.types.d.ts +3 -3
  45. package/dist/municipal/systemInstructions/instructions.types.d.ts.map +1 -1
  46. package/dist/municipal/systemInstructions/instructions.types.js +6 -6
  47. package/dist/municipal/tickets/index.d.ts +2 -2
  48. package/dist/municipal/tickets/tickets.getters.d.ts +3 -3
  49. package/dist/municipal/tickets/tickets.getters.d.ts.map +1 -1
  50. package/dist/municipal/tickets/tickets.getters.js +29 -50
  51. package/dist/municipal/tickets/tickets.getters.js.map +1 -1
  52. package/dist/municipal/tickets/tickets.types.d.ts +1 -1
  53. package/dist/municipal/tickets/tickets.types.d.ts.map +1 -1
  54. package/dist/municipal/utils/types.d.ts +1 -1
  55. package/dist/municipal/utils/types.d.ts.map +1 -1
  56. package/dist/talkpilot/agents/agents.getters.d.ts +1 -1
  57. package/dist/talkpilot/agents/agents.getters.js +2 -2
  58. package/dist/talkpilot/agents/agents.types.d.ts +2 -2
  59. package/dist/talkpilot/agents/index.d.ts +2 -2
  60. package/dist/talkpilot/backgroundToolResults/backgroundToolResults.getters.d.ts +2 -2
  61. package/dist/talkpilot/backgroundToolResults/backgroundToolResults.getters.d.ts.map +1 -1
  62. package/dist/talkpilot/backgroundToolResults/backgroundToolResults.getters.js +1 -1
  63. package/dist/talkpilot/backgroundToolResults/backgroundToolResults.getters.js.map +1 -1
  64. package/dist/talkpilot/backgroundToolResults/backgroundToolResults.types.d.ts +2 -2
  65. package/dist/talkpilot/backgroundToolResults/index.d.ts +2 -2
  66. package/dist/talkpilot/calls/calls.getters.d.ts +3 -3
  67. package/dist/talkpilot/calls/calls.getters.d.ts.map +1 -1
  68. package/dist/talkpilot/calls/calls.getters.js +15 -19
  69. package/dist/talkpilot/calls/calls.getters.js.map +1 -1
  70. package/dist/talkpilot/calls/calls.types.d.ts +3 -3
  71. package/dist/talkpilot/calls/calls.types.d.ts.map +1 -1
  72. package/dist/talkpilot/calls/calls.types.js +2 -2
  73. package/dist/talkpilot/calls/index.d.ts +2 -2
  74. package/dist/talkpilot/clientAudioBuffers/clientAudioBuffer.getters.d.ts +2 -2
  75. package/dist/talkpilot/clientAudioBuffers/clientAudioBuffer.getters.d.ts.map +1 -1
  76. package/dist/talkpilot/clientAudioBuffers/clientAudioBuffer.getters.js +2 -2
  77. package/dist/talkpilot/clientAudioBuffers/clientAudioBuffer.getters.js.map +1 -1
  78. package/dist/talkpilot/clientAudioBuffers/clientsAudioBuffers.types.d.ts +2 -2
  79. package/dist/talkpilot/clientAudioBuffers/index.d.ts +2 -2
  80. package/dist/talkpilot/clients/clients.getters.d.ts +2 -2
  81. package/dist/talkpilot/clients/clients.getters.d.ts.map +1 -1
  82. package/dist/talkpilot/clients/clients.getters.js +2 -5
  83. package/dist/talkpilot/clients/clients.getters.js.map +1 -1
  84. package/dist/talkpilot/clients/clients.types.d.ts +1 -1
  85. package/dist/talkpilot/clients/index.d.ts +2 -2
  86. package/dist/talkpilot/clientsConfig/clientsConfig.getters.d.ts +2 -2
  87. package/dist/talkpilot/clientsConfig/clientsConfig.getters.d.ts.map +1 -1
  88. package/dist/talkpilot/clientsConfig/clientsConfig.getters.js +1 -1
  89. package/dist/talkpilot/clientsConfig/clientsConfig.getters.js.map +1 -1
  90. package/dist/talkpilot/clientsConfig/clientsConfig.types.d.ts +3 -3
  91. package/dist/talkpilot/clientsConfig/clientsConfig.types.d.ts.map +1 -1
  92. package/dist/talkpilot/clientsConfig/index.d.ts +2 -2
  93. package/dist/talkpilot/flows/flows.getter.d.ts +2 -2
  94. package/dist/talkpilot/flows/flows.getter.d.ts.map +1 -1
  95. package/dist/talkpilot/flows/flows.getter.js +1 -1
  96. package/dist/talkpilot/flows/flows.getter.js.map +1 -1
  97. package/dist/talkpilot/flows/flows.schema.d.ts +3 -0
  98. package/dist/talkpilot/flows/flows.schema.d.ts.map +1 -1
  99. package/dist/talkpilot/flows/flows.schema.js +80 -87
  100. package/dist/talkpilot/flows/flows.schema.js.map +1 -1
  101. package/dist/talkpilot/flows/flows.types.d.ts +17 -16
  102. package/dist/talkpilot/flows/flows.types.d.ts.map +1 -1
  103. package/dist/talkpilot/flows/index.d.ts +2 -2
  104. package/dist/talkpilot/groups/groups.getters.d.ts +2 -2
  105. package/dist/talkpilot/groups/groups.getters.d.ts.map +1 -1
  106. package/dist/talkpilot/groups/groups.getters.js +2 -2
  107. package/dist/talkpilot/groups/groups.getters.js.map +1 -1
  108. package/dist/talkpilot/groups/groups.types.d.ts +1 -1
  109. package/dist/talkpilot/groups/index.d.ts +3 -3
  110. package/dist/talkpilot/groups/phone.utils.d.ts +1 -1
  111. package/dist/talkpilot/groups/phone.utils.d.ts.map +1 -1
  112. package/dist/talkpilot/groups/phone.utils.js +2 -2
  113. package/dist/talkpilot/groups/phone.utils.js.map +1 -1
  114. package/dist/talkpilot/index.d.ts +16 -16
  115. package/dist/talkpilot/index.js +1 -1
  116. package/dist/talkpilot/leads/index.d.ts +2 -2
  117. package/dist/talkpilot/leads/leads.getter.d.ts +2 -2
  118. package/dist/talkpilot/leads/leads.getter.d.ts.map +1 -1
  119. package/dist/talkpilot/leads/leads.getter.js +1 -1
  120. package/dist/talkpilot/leads/leads.getter.js.map +1 -1
  121. package/dist/talkpilot/leads/leads.schema.js +16 -16
  122. package/dist/talkpilot/leads/leads.types.d.ts +1 -1
  123. package/dist/talkpilot/mongodb-client.d.ts +1 -1
  124. package/dist/talkpilot/mongodb-client.js +9 -8
  125. package/dist/talkpilot/mongodb-client.js.map +1 -1
  126. package/dist/talkpilot/phone_numbers/index.d.ts +2 -2
  127. package/dist/talkpilot/phone_numbers/phone_numbers.getter.d.ts +3 -3
  128. package/dist/talkpilot/phone_numbers/phone_numbers.getter.d.ts.map +1 -1
  129. package/dist/talkpilot/phone_numbers/phone_numbers.getter.js +13 -28
  130. package/dist/talkpilot/phone_numbers/phone_numbers.getter.js.map +1 -1
  131. package/dist/talkpilot/phone_numbers/phone_numbers.schema.js +9 -9
  132. package/dist/talkpilot/phone_numbers/phone_numbers.types.d.ts +1 -1
  133. package/dist/talkpilot/phone_numbers/phone_numbers.types.d.ts.map +1 -1
  134. package/dist/talkpilot/plans/index.d.ts +2 -2
  135. package/dist/talkpilot/plans/plans.getters.d.ts +2 -2
  136. package/dist/talkpilot/plans/plans.getters.d.ts.map +1 -1
  137. package/dist/talkpilot/plans/plans.getters.js +3 -3
  138. package/dist/talkpilot/plans/plans.getters.js.map +1 -1
  139. package/dist/talkpilot/plans/plans.types.d.ts +4 -4
  140. package/dist/talkpilot/plans/plans.types.d.ts.map +1 -1
  141. package/dist/talkpilot/plans/plans.types.js +19 -19
  142. package/dist/talkpilot/results/index.d.ts +2 -2
  143. package/dist/talkpilot/results/index.d.ts.map +1 -1
  144. package/dist/talkpilot/results/index.js.map +1 -1
  145. package/dist/talkpilot/results/results.getter.d.ts +3 -3
  146. package/dist/talkpilot/results/results.getter.d.ts.map +1 -1
  147. package/dist/talkpilot/results/results.getter.js +4 -4
  148. package/dist/talkpilot/results/results.getter.js.map +1 -1
  149. package/dist/talkpilot/results/results.schema.js +18 -18
  150. package/dist/talkpilot/results/results.types.d.ts +1 -1
  151. package/dist/talkpilot/sessions/index.d.ts +2 -2
  152. package/dist/talkpilot/sessions/sessions.getter.d.ts +3 -3
  153. package/dist/talkpilot/sessions/sessions.getter.d.ts.map +1 -1
  154. package/dist/talkpilot/sessions/sessions.getter.js +10 -13
  155. package/dist/talkpilot/sessions/sessions.getter.js.map +1 -1
  156. package/dist/talkpilot/sessions/sessions.schema.js +17 -17
  157. package/dist/talkpilot/sessions/sessions.types.d.ts +2 -2
  158. package/dist/talkpilot/subscriptions/index.d.ts +3 -3
  159. package/dist/talkpilot/subscriptions/subscriptions.getters.d.ts +2 -2
  160. package/dist/talkpilot/subscriptions/subscriptions.getters.d.ts.map +1 -1
  161. package/dist/talkpilot/subscriptions/subscriptions.getters.js +11 -11
  162. package/dist/talkpilot/subscriptions/subscriptions.getters.js.map +1 -1
  163. package/dist/talkpilot/subscriptions/subscriptions.getters.utils.d.ts +2 -2
  164. package/dist/talkpilot/subscriptions/subscriptions.getters.utils.d.ts.map +1 -1
  165. package/dist/talkpilot/subscriptions/subscriptions.getters.utils.js.map +1 -1
  166. package/dist/talkpilot/subscriptions/subscriptions.types.d.ts +2 -2
  167. package/dist/talkpilot/subscriptions/subscriptions.types.d.ts.map +1 -1
  168. package/dist/talkpilot/subscriptions/subscriptions.types.js +7 -7
  169. package/dist/talkpilot/utils/query.utils.d.ts +1 -1
  170. package/dist/test-utils/db-utils.d.ts +1 -1
  171. package/dist/test-utils/db-utils.js +2 -2
  172. package/dist/test-utils/factories/index.d.ts +12 -12
  173. package/dist/test-utils/factories/municipal/cities.d.ts +2 -2
  174. package/dist/test-utils/factories/municipal/cities.d.ts.map +1 -1
  175. package/dist/test-utils/factories/municipal/cities.js +1 -1
  176. package/dist/test-utils/factories/municipal/departmentsSubjects.d.ts +2 -2
  177. package/dist/test-utils/factories/municipal/departmentsSubjects.d.ts.map +1 -1
  178. package/dist/test-utils/factories/municipal/departmentsSubjects.js +1 -7
  179. package/dist/test-utils/factories/municipal/departmentsSubjects.js.map +1 -1
  180. package/dist/test-utils/factories/municipal/streets.d.ts +2 -2
  181. package/dist/test-utils/factories/municipal/streets.d.ts.map +1 -1
  182. package/dist/test-utils/factories/municipal/streets.js +1 -6
  183. package/dist/test-utils/factories/municipal/streets.js.map +1 -1
  184. package/dist/test-utils/factories/municipal/tickets.d.ts +2 -2
  185. package/dist/test-utils/factories/municipal/tickets.d.ts.map +1 -1
  186. package/dist/test-utils/factories/municipal/tickets.js +1 -7
  187. package/dist/test-utils/factories/municipal/tickets.js.map +1 -1
  188. package/dist/test-utils/factories/talkpilot/agents.d.ts +2 -2
  189. package/dist/test-utils/factories/talkpilot/agents.d.ts.map +1 -1
  190. package/dist/test-utils/factories/talkpilot/agents.js +4 -4
  191. package/dist/test-utils/factories/talkpilot/calls.d.ts +2 -2
  192. package/dist/test-utils/factories/talkpilot/calls.d.ts.map +1 -1
  193. package/dist/test-utils/factories/talkpilot/calls.js +1 -1
  194. package/dist/test-utils/factories/talkpilot/clientAudioBuffers.d.ts +2 -2
  195. package/dist/test-utils/factories/talkpilot/clientAudioBuffers.d.ts.map +1 -1
  196. package/dist/test-utils/factories/talkpilot/clientAudioBuffers.js +1 -1
  197. package/dist/test-utils/factories/talkpilot/clientAudioBuffers.js.map +1 -1
  198. package/dist/test-utils/factories/talkpilot/clientsConfig.d.ts +2 -2
  199. package/dist/test-utils/factories/talkpilot/clientsConfig.d.ts.map +1 -1
  200. package/dist/test-utils/factories/talkpilot/clientsConfig.js.map +1 -1
  201. package/dist/test-utils/factories/talkpilot/flows.d.ts +3 -3
  202. package/dist/test-utils/factories/talkpilot/flows.d.ts.map +1 -1
  203. package/dist/test-utils/factories/talkpilot/flows.js.map +1 -1
  204. package/dist/test-utils/factories/talkpilot/groups.d.ts +2 -2
  205. package/dist/test-utils/factories/talkpilot/groups.d.ts.map +1 -1
  206. package/dist/test-utils/factories/talkpilot/groups.js +9 -9
  207. package/dist/test-utils/factories/talkpilot/groups.js.map +1 -1
  208. package/dist/test-utils/factories/talkpilot/phone_numbers.d.ts +3 -3
  209. package/dist/test-utils/factories/talkpilot/phone_numbers.d.ts.map +1 -1
  210. package/dist/test-utils/factories/talkpilot/phone_numbers.js.map +1 -1
  211. package/dist/test-utils/factories/talkpilot/sessions.d.ts +2 -2
  212. package/dist/test-utils/factories/talkpilot/sessions.d.ts.map +1 -1
  213. package/dist/test-utils/factories/talkpilot/sessions.js +1 -1
  214. package/dist/utils/validation.js +2 -2
  215. package/dist/utils/validation.js.map +1 -1
  216. package/package.json +1 -3
  217. package/src/__tests__/setup.ts +3 -3
  218. package/src/connection.ts +25 -27
  219. package/src/index.ts +9 -9
  220. package/src/municipal/__tests__/validation.spec.ts +23 -35
  221. package/src/municipal/cities/cities.getters.ts +10 -16
  222. package/src/municipal/cities/cities.types.ts +1 -1
  223. package/src/municipal/cities/index.ts +2 -2
  224. package/src/municipal/departmentsSubjects/departmentsSubjects.getters.ts +44 -53
  225. package/src/municipal/departmentsSubjects/departmentsSubjects.types.ts +5 -5
  226. package/src/municipal/departmentsSubjects/index.ts +3 -2
  227. package/src/municipal/index.ts +10 -10
  228. package/src/municipal/mongodb-client.ts +10 -13
  229. package/src/municipal/streets/index.ts +2 -2
  230. package/src/municipal/streets/streets.getters.ts +23 -43
  231. package/src/municipal/streets/streets.types.ts +1 -1
  232. package/src/municipal/systemInstructions/__tests__/getters.spec.ts +52 -67
  233. package/src/municipal/systemInstructions/__tests__/setters.spec.ts +238 -271
  234. package/src/municipal/systemInstructions/index.ts +3 -7
  235. package/src/municipal/systemInstructions/instructions.getters.ts +18 -30
  236. package/src/municipal/systemInstructions/instructions.setters.ts +19 -43
  237. package/src/municipal/systemInstructions/instructions.types.ts +10 -10
  238. package/src/municipal/tickets/__tests__/tickets.getters.spec.ts +12 -12
  239. package/src/municipal/tickets/index.ts +2 -2
  240. package/src/municipal/tickets/tickets.getters.ts +42 -69
  241. package/src/municipal/tickets/tickets.types.ts +2 -2
  242. package/src/municipal/utils/types.ts +3 -8
  243. package/src/talkpilot/__tests__/db.spec.ts +12 -12
  244. package/src/talkpilot/__tests__/mongodb-client.spec.ts +8 -7
  245. package/src/talkpilot/__tests__/validation.spec.ts +24 -30
  246. package/src/talkpilot/agents/__tests__/agents.getters.spec.ts +10 -10
  247. package/src/talkpilot/agents/agents.getters.ts +3 -3
  248. package/src/talkpilot/agents/agents.types.ts +2 -2
  249. package/src/talkpilot/agents/index.ts +2 -2
  250. package/src/talkpilot/backgroundToolResults/__tests__/backgroundToolResults.getters.spec.ts +31 -42
  251. package/src/talkpilot/backgroundToolResults/backgroundToolResults.getters.ts +11 -11
  252. package/src/talkpilot/backgroundToolResults/backgroundToolResults.types.ts +3 -2
  253. package/src/talkpilot/backgroundToolResults/index.ts +2 -2
  254. package/src/talkpilot/calls/__tests__/callStats.utils.spec.ts +27 -27
  255. package/src/talkpilot/calls/__tests__/calls.spec.ts +39 -79
  256. package/src/talkpilot/calls/calls.getters.ts +28 -48
  257. package/src/talkpilot/calls/calls.types.ts +16 -16
  258. package/src/talkpilot/calls/index.ts +2 -2
  259. package/src/talkpilot/clientAudioBuffers/__tests__/clientAudioBuffer.getters.spec.ts +39 -73
  260. package/src/talkpilot/clientAudioBuffers/clientAudioBuffer.getters.ts +11 -18
  261. package/src/talkpilot/clientAudioBuffers/clientsAudioBuffers.types.ts +2 -2
  262. package/src/talkpilot/clientAudioBuffers/index.ts +2 -2
  263. package/src/talkpilot/clients/clients.getters.ts +5 -10
  264. package/src/talkpilot/clients/clients.types.ts +1 -1
  265. package/src/talkpilot/clients/index.ts +2 -2
  266. package/src/talkpilot/clientsConfig/__tests__/clientsConfig.spec.ts +18 -21
  267. package/src/talkpilot/clientsConfig/clientsConfig.getters.ts +4 -6
  268. package/src/talkpilot/clientsConfig/clientsConfig.types.ts +8 -10
  269. package/src/talkpilot/clientsConfig/index.ts +2 -2
  270. package/src/talkpilot/flows/__tests__/flows.schema.spec.ts +37 -38
  271. package/src/talkpilot/flows/flows.getter.ts +5 -8
  272. package/src/talkpilot/flows/flows.schema.ts +80 -87
  273. package/src/talkpilot/flows/flows.types.ts +24 -23
  274. package/src/talkpilot/flows/index.ts +2 -2
  275. package/src/talkpilot/groups/__tests__/groups.spec.ts +27 -34
  276. package/src/talkpilot/groups/__tests__/phone.utils.spec.ts +20 -20
  277. package/src/talkpilot/groups/groups.getters.ts +5 -8
  278. package/src/talkpilot/groups/groups.types.ts +1 -1
  279. package/src/talkpilot/groups/index.ts +3 -3
  280. package/src/talkpilot/groups/phone.utils.ts +6 -12
  281. package/src/talkpilot/index.ts +17 -17
  282. package/src/talkpilot/leads/index.ts +2 -2
  283. package/src/talkpilot/leads/leads.getter.ts +4 -5
  284. package/src/talkpilot/leads/leads.schema.ts +16 -16
  285. package/src/talkpilot/leads/leads.types.ts +1 -1
  286. package/src/talkpilot/mongodb-client.ts +12 -12
  287. package/src/talkpilot/phone_numbers/__tests__/phone_numbers.spec.ts +44 -84
  288. package/src/talkpilot/phone_numbers/index.ts +2 -2
  289. package/src/talkpilot/phone_numbers/phone_numbers.getter.ts +22 -44
  290. package/src/talkpilot/phone_numbers/phone_numbers.schema.ts +9 -9
  291. package/src/talkpilot/phone_numbers/phone_numbers.types.ts +1 -1
  292. package/src/talkpilot/plans/__tests__/plans.spec.ts +26 -30
  293. package/src/talkpilot/plans/index.ts +2 -2
  294. package/src/talkpilot/plans/plans.getters.ts +18 -25
  295. package/src/talkpilot/plans/plans.types.ts +23 -27
  296. package/src/talkpilot/results/index.ts +2 -5
  297. package/src/talkpilot/results/results.getter.ts +8 -9
  298. package/src/talkpilot/results/results.schema.ts +18 -18
  299. package/src/talkpilot/results/results.types.ts +1 -1
  300. package/src/talkpilot/sessions/__tests__/sessions.spec.ts +41 -65
  301. package/src/talkpilot/sessions/index.ts +2 -2
  302. package/src/talkpilot/sessions/sessions.getter.ts +16 -21
  303. package/src/talkpilot/sessions/sessions.schema.ts +17 -17
  304. package/src/talkpilot/sessions/sessions.types.ts +2 -2
  305. package/src/talkpilot/subscriptions/__tests__/subscriptions.getters.utils.spec.ts +15 -18
  306. package/src/talkpilot/subscriptions/index.ts +3 -3
  307. package/src/talkpilot/subscriptions/subscriptions.getters.ts +33 -36
  308. package/src/talkpilot/subscriptions/subscriptions.getters.utils.ts +3 -10
  309. package/src/talkpilot/subscriptions/subscriptions.types.ts +9 -9
  310. package/src/talkpilot/utils/__tests__/query.utils.spec.ts +8 -8
  311. package/src/talkpilot/utils/query.utils.ts +2 -2
  312. package/src/test-utils/db-utils.ts +5 -5
  313. package/src/test-utils/factories/index.ts +12 -12
  314. package/src/test-utils/factories/municipal/cities.ts +5 -5
  315. package/src/test-utils/factories/municipal/departmentsSubjects.ts +25 -32
  316. package/src/test-utils/factories/municipal/streets.ts +5 -10
  317. package/src/test-utils/factories/municipal/tickets.ts +6 -12
  318. package/src/test-utils/factories/talkpilot/agents.ts +8 -8
  319. package/src/test-utils/factories/talkpilot/calls.ts +5 -5
  320. package/src/test-utils/factories/talkpilot/clientAudioBuffers.ts +12 -14
  321. package/src/test-utils/factories/talkpilot/clientsConfig.ts +8 -7
  322. package/src/test-utils/factories/talkpilot/flows.ts +5 -7
  323. package/src/test-utils/factories/talkpilot/groups.ts +13 -13
  324. package/src/test-utils/factories/talkpilot/phone_numbers.ts +6 -8
  325. package/src/test-utils/factories/talkpilot/sessions.ts +5 -5
  326. package/src/utils/validation.ts +4 -4
  327. package/dist/talkpilot/subscriptions/subscriptions.utils.d.ts +0 -4
  328. package/dist/talkpilot/subscriptions/subscriptions.utils.d.ts.map +0 -1
  329. package/dist/talkpilot/subscriptions/subscriptions.utils.js +0 -20
  330. package/dist/talkpilot/subscriptions/subscriptions.utils.js.map +0 -1
@@ -1,32 +1,32 @@
1
- import { enrichPhoneNumber, isValidE164 } from "../phone.utils";
1
+ import { enrichPhoneNumber, isValidE164 } from '../phone.utils';
2
2
 
3
- describe("Phone Utilities", () => {
4
- describe("enrichPhoneNumber", () => {
5
- it("should enrich Israeli number", () => {
6
- const result = enrichPhoneNumber("+972507725874");
7
- expect(result?.e164).toBe("+972507725874");
3
+ describe('Phone Utilities', () => {
4
+ describe('enrichPhoneNumber', () => {
5
+ it('should enrich Israeli number', () => {
6
+ const result = enrichPhoneNumber('+972507725874');
7
+ expect(result?.e164).toBe('+972507725874');
8
8
  expect(result?.region).toBeDefined();
9
- expect(result?.countryCallingCode).toBe("972");
9
+ expect(result?.countryCallingCode).toBe('972');
10
10
  });
11
11
 
12
- it("should enrich US number", () => {
13
- const result = enrichPhoneNumber("+12025551234");
14
- expect(result?.region).toBe("US");
15
- expect(result?.countryCallingCode).toBe("1");
12
+ it('should enrich US number', () => {
13
+ const result = enrichPhoneNumber('+12025551234');
14
+ expect(result?.region).toBe('US');
15
+ expect(result?.countryCallingCode).toBe('1');
16
16
  });
17
17
 
18
- it("should return null for invalid", () => {
19
- expect(enrichPhoneNumber("invalid")).toBeNull();
20
- expect(enrichPhoneNumber("0507725874")).toBeNull();
18
+ it('should return null for invalid', () => {
19
+ expect(enrichPhoneNumber('invalid')).toBeNull();
20
+ expect(enrichPhoneNumber('0507725874')).toBeNull();
21
21
  });
22
22
  });
23
23
 
24
- describe("isValidE164", () => {
25
- it("should validate E.164 format", () => {
26
- expect(isValidE164("+972508832983")).toBe(true);
27
- expect(isValidE164("+12025551234")).toBe(true);
28
- expect(isValidE164("0501234567")).toBe(false);
29
- expect(isValidE164("invalid")).toBe(false);
24
+ describe('isValidE164', () => {
25
+ it('should validate E.164 format', () => {
26
+ expect(isValidE164('+972508832983')).toBe(true);
27
+ expect(isValidE164('+12025551234')).toBe(true);
28
+ expect(isValidE164('0501234567')).toBe(false);
29
+ expect(isValidE164('invalid')).toBe(false);
30
30
  });
31
31
  });
32
32
  });
@@ -1,8 +1,8 @@
1
- import { getDb, ObjectId, Group } from "../index";
2
- import { Collection, Filter } from "mongodb";
1
+ import { getDb, ObjectId, Group } from '../index';
2
+ import { Collection, Filter } from 'mongodb';
3
3
 
4
4
  export const getGroupsCollection = (): Collection<Group> => {
5
- return getDb().collection<Group>("groups");
5
+ return getDb().collection<Group>('groups');
6
6
  };
7
7
 
8
8
  export const findGroups = async (filter: Filter<Group>): Promise<Group[]> => {
@@ -14,14 +14,11 @@ export const createGroup = async (group: Group) => {
14
14
  return insertedId;
15
15
  };
16
16
 
17
- export const updateGroup = async (
18
- filter: Filter<Group>,
19
- data: Partial<Group>,
20
- ) => {
17
+ export const updateGroup = async (filter: Filter<Group>, data: Partial<Group>) => {
21
18
  return await getGroupsCollection().findOneAndUpdate(
22
19
  filter,
23
20
  { $set: { ...data, updatedAt: new Date() } },
24
- { returnDocument: "after" },
21
+ { returnDocument: 'after' }
25
22
  );
26
23
  };
27
24
 
@@ -1,4 +1,4 @@
1
- import { WithId } from "mongodb";
1
+ import { WithId } from 'mongodb';
2
2
  export type E164 = `+${string}`;
3
3
  export type CountryISO = Uppercase<string>;
4
4
 
@@ -1,3 +1,3 @@
1
- export * from "./groups.getters";
2
- export * from "./groups.types";
3
- export * from "./phone.utils";
1
+ export * from './groups.getters';
2
+ export * from './groups.types';
3
+ export * from './phone.utils';
@@ -1,27 +1,21 @@
1
- import { PhoneNumberUtil, PhoneNumberFormat } from "google-libphonenumber";
2
- import type { Phone, E164, CountryISO } from "./groups.types";
1
+ import { PhoneNumberUtil, PhoneNumberFormat } from 'google-libphonenumber';
2
+ import type { Phone, E164, CountryISO } from './groups.types';
3
3
 
4
4
  const phoneUtil = PhoneNumberUtil.getInstance();
5
5
 
6
6
  export const enrichPhoneNumber = (e164: string): Phone | null => {
7
7
  try {
8
- const phoneNumber = phoneUtil.parse(e164, "ZZ");
8
+ const phoneNumber = phoneUtil.parse(e164, 'ZZ');
9
9
  if (!phoneUtil.isValidNumber(phoneNumber)) {
10
10
  return null;
11
11
  }
12
12
 
13
- const normalizedE164 = phoneUtil.format(
14
- phoneNumber,
15
- PhoneNumberFormat.E164,
16
- ) as E164;
13
+ const normalizedE164 = phoneUtil.format(phoneNumber, PhoneNumberFormat.E164) as E164;
17
14
  const region = phoneUtil.getRegionCodeForNumber(phoneNumber) as CountryISO;
18
15
  const countryCallingCode = phoneNumber.getCountryCode()?.toString();
19
16
  const national = phoneNumber.getNationalNumber()?.toString();
20
17
  const ext = phoneNumber.getExtension() || undefined;
21
- const formatted = phoneUtil.format(
22
- phoneNumber,
23
- PhoneNumberFormat.INTERNATIONAL,
24
- );
18
+ const formatted = phoneUtil.format(phoneNumber, PhoneNumberFormat.INTERNATIONAL);
25
19
 
26
20
  return {
27
21
  e164: normalizedE164,
@@ -38,7 +32,7 @@ export const enrichPhoneNumber = (e164: string): Phone | null => {
38
32
 
39
33
  export const isValidE164 = (e164: string): boolean => {
40
34
  try {
41
- const phoneNumber = phoneUtil.parse(e164, "ZZ");
35
+ const phoneNumber = phoneUtil.parse(e164, 'ZZ');
42
36
  return phoneUtil.isValidNumber(phoneNumber);
43
37
  } catch (error) {
44
38
  return false;
@@ -1,27 +1,27 @@
1
- import { Db, ObjectId as MongoObjectId } from "mongodb";
1
+ import { Db, ObjectId as MongoObjectId } from 'mongodb';
2
2
 
3
- export * from "./flows";
4
- export * from "./results";
5
- export * from "./sessions";
6
- export * from "./phone_numbers";
7
- export * from "./leads";
8
- export * from "./clients";
9
- export * from "./agents";
10
- export * from "./plans";
11
- export * from "./subscriptions";
12
- export * from "./groups";
13
- export * from "./calls";
14
- export * from "./clientAudioBuffers";
15
- export * from "./clientsConfig";
16
- export * from "./backgroundToolResults";
17
- export { mongodbClient } from "./mongodb-client";
3
+ export * from './flows';
4
+ export * from './results';
5
+ export * from './sessions';
6
+ export * from './phone_numbers';
7
+ export * from './leads';
8
+ export * from './clients';
9
+ export * from './agents';
10
+ export * from './plans';
11
+ export * from './subscriptions';
12
+ export * from './groups';
13
+ export * from './calls';
14
+ export * from './clientAudioBuffers';
15
+ export * from './clientsConfig';
16
+ export * from './backgroundToolResults';
17
+ export { mongodbClient } from './mongodb-client';
18
18
 
19
19
  let db: Db;
20
20
  export const setDb = (d: Db) => {
21
21
  db = d;
22
22
  };
23
23
  export const getDb = (): Db => {
24
- if (!db) throw new Error("DB not initialised");
24
+ if (!db) throw new Error('DB not initialised');
25
25
  return db;
26
26
  };
27
27
 
@@ -1,2 +1,2 @@
1
- export { getLeadsCollection } from "./leads.getter";
2
- export type { Lead, LeadItem, LeadProperty } from "./leads.types";
1
+ export { getLeadsCollection } from './leads.getter';
2
+ export type { Lead, LeadItem, LeadProperty } from './leads.types';
@@ -1,6 +1,5 @@
1
- import type { Collection } from "mongodb";
2
- import { getDb } from "../index";
3
- import type { Lead } from "./leads.types";
1
+ import type { Collection } from 'mongodb';
2
+ import { getDb } from '../index';
3
+ import type { Lead } from './leads.types';
4
4
 
5
- export const getLeadsCollection = (): Collection<Lead> =>
6
- getDb().collection<Lead>("leads");
5
+ export const getLeadsCollection = (): Collection<Lead> => getDb().collection<Lead>('leads');
@@ -1,27 +1,27 @@
1
1
  export const leadsMongoSchema = {
2
- bsonType: "object",
3
- required: ["flowId", "clientId", "createdAt", "leads"],
2
+ bsonType: 'object',
3
+ required: ['flowId', 'clientId', 'createdAt', 'leads'],
4
4
  properties: {
5
- _id: { bsonType: "objectId" },
6
- flowId: { bsonType: "string" },
7
- clientId: { bsonType: "string" },
8
- createdAt: { bsonType: "date" },
5
+ _id: { bsonType: 'objectId' },
6
+ flowId: { bsonType: 'string' },
7
+ clientId: { bsonType: 'string' },
8
+ createdAt: { bsonType: 'date' },
9
9
  leads: {
10
- bsonType: "array",
10
+ bsonType: 'array',
11
11
  items: {
12
- bsonType: "object",
13
- required: ["callSid", "timestamp"],
12
+ bsonType: 'object',
13
+ required: ['callSid', 'timestamp'],
14
14
  properties: {
15
- callSid: { bsonType: "string" },
16
- timestamp: { bsonType: "date" },
15
+ callSid: { bsonType: 'string' },
16
+ timestamp: { bsonType: 'date' },
17
17
  properties: {
18
- bsonType: "array",
18
+ bsonType: 'array',
19
19
  items: {
20
- bsonType: "object",
21
- required: ["name", "value"],
20
+ bsonType: 'object',
21
+ required: ['name', 'value'],
22
22
  properties: {
23
- name: { bsonType: "string" },
24
- value: { bsonType: "string" },
23
+ name: { bsonType: 'string' },
24
+ value: { bsonType: 'string' },
25
25
  },
26
26
  },
27
27
  },
@@ -1,4 +1,4 @@
1
- import { ObjectId } from "mongodb";
1
+ import { ObjectId } from 'mongodb';
2
2
 
3
3
  export interface LeadProperty {
4
4
  name: string;
@@ -1,6 +1,6 @@
1
- import { MongoClient, Db } from "mongodb";
2
- import { setDb } from "./index";
3
- import { validateConfig, validateMongoUri } from "../utils/validation";
1
+ import { MongoClient, Db } from 'mongodb';
2
+ import { setDb } from './index';
3
+ import { validateConfig, validateMongoUri } from '../utils/validation';
4
4
 
5
5
  class MongoDBClient {
6
6
  private client: MongoClient | null = null;
@@ -22,7 +22,7 @@ class MongoDBClient {
22
22
  }
23
23
 
24
24
  const mongodbUri = uri || process.env.MONGO_URI || process.env.MONGODB_URI;
25
- validateConfig("MONGO_URI", mongodbUri);
25
+ validateConfig('MONGO_URI', mongodbUri);
26
26
  validateMongoUri(mongodbUri!);
27
27
 
28
28
  try {
@@ -30,13 +30,13 @@ class MongoDBClient {
30
30
  await this.client.connect();
31
31
 
32
32
  const dbNameFromUri = this.extractDatabaseName(mongodbUri!);
33
- const dbName =
34
- databaseName || process.env.TALKPILOT_DB_NAME || dbNameFromUri;
33
+ const dbNameFromEnv = process.env.MONGODB_DB_NAME;
34
+ const dbName = databaseName || dbNameFromUri || dbNameFromEnv;
35
35
 
36
36
  if (!dbName) {
37
37
  throw new Error(
38
- "[core-db] Database name not specified. Please pass databaseName to connect(), " +
39
- "add it to the URI, or set TALKPILOT_DB_NAME.",
38
+ '[core-db] Database name not specified. Please pass databaseName to connect(), ' +
39
+ 'add it to the URI, or set MONGODB_DB_NAME.'
40
40
  );
41
41
  }
42
42
 
@@ -44,7 +44,7 @@ class MongoDBClient {
44
44
  setDb(this.db);
45
45
  console.info(`[core-db] TalkPilot MongoDB connected: ${dbName}`);
46
46
  } catch (error) {
47
- console.error("[core-db] TalkPilot connection failed", error);
47
+ console.error('[core-db] TalkPilot connection failed', error as Error);
48
48
  throw error;
49
49
  }
50
50
  }
@@ -55,9 +55,9 @@ class MongoDBClient {
55
55
  await this.client.close();
56
56
  this.client = null;
57
57
  this.db = null;
58
- console.info("MongoDB disconnected successfully");
58
+ console.info('MongoDB disconnected successfully');
59
59
  } catch (error) {
60
- console.error("[core-db] Disconnection failed", error);
60
+ console.error('Error disconnecting from MongoDB', error as Error);
61
61
  throw error;
62
62
  }
63
63
  }
@@ -65,7 +65,7 @@ class MongoDBClient {
65
65
 
66
66
  getDb(): Db {
67
67
  if (!this.db) {
68
- throw new Error("Database not initialized. Call connect() first.");
68
+ throw new Error('Database not initialized. Call connect() first.');
69
69
  }
70
70
  return this.db;
71
71
  }
@@ -4,46 +4,40 @@ import {
4
4
  getClientPhoneNumber,
5
5
  getClientPhoneData,
6
6
  createPhoneNumberEntity,
7
- } from "../phone_numbers.getter";
8
- import { getFlowsCollection } from "../../flows";
9
- import { createFlow, createPhoneNumber } from "../../../test-utils/factories";
10
- import { ObjectId } from "mongodb";
11
-
12
- describe("db.phoneNumbers", () => {
13
- describe("getPhoneDataByPhoneNumber", () => {
14
- it("return phone number data with flow", async () => {
7
+ } from '../phone_numbers.getter';
8
+ import { getFlowsCollection } from '../../flows/flows.getter';
9
+ import { createFlow, createPhoneNumber } from '../../../test-utils/factories';
10
+ import { ObjectId } from 'mongodb';
11
+
12
+ describe('db.phoneNumbers', () => {
13
+ describe('getPhoneDataByPhoneNumber', () => {
14
+ it('return phone number data with flow', async () => {
15
15
  const flow = createFlow({
16
- clientId: "test-client-id",
16
+ clientId: 'test-client-id',
17
17
  conversationSettings: {
18
18
  interruptions: {
19
19
  enableInterruptionDetection: true,
20
20
  interruptionWindowSeconds: 60,
21
21
  interruptionThresholdSeconds: 10,
22
- interruptionInstruction:
23
- "I am hearing background noise that makes it hard for me to focus on what you are saying. Please try to move to a quieter place or reduce the noise so I can better assist you.",
22
+ interruptionInstruction: 'I am hearing background noise that makes it hard for me to focus on what you are saying. Please try to move to a quieter place or reduce the noise so I can better assist you.',
24
23
  },
25
24
  silence: {
26
25
  enableSilenceDetection: true,
27
26
  firstWarningSilenceSeconds: 5,
28
- firstWarningInstruction:
29
- "I have not heard you for a few seconds. If you are still on the line, please say something so we can continue.",
27
+ firstWarningInstruction: 'I have not heard you for a few seconds. If you are still on the line, please say something so we can continue.',
30
28
  secondWarningSilenceSeconds: 10,
31
- secondWarningInstruction:
32
- "I still have not heard anything from you. If you do not respond in the next few seconds, I will have to end this call.",
29
+ secondWarningInstruction: 'I still have not heard anything from you. If you do not respond in the next few seconds, I will have to end this call.',
33
30
  disconnectSilenceSeconds: 30,
34
31
  },
35
32
  },
36
33
  });
37
- const phoneData = createPhoneNumber({
38
- flow_id: flow._id,
39
- client_id: "test-client-id",
40
- });
41
-
34
+ const phoneData = createPhoneNumber({ flow_id: flow._id, client_id: 'test-client-id' });
35
+
42
36
  await getFlowsCollection().insertOne(flow);
43
37
  await getPhoneNumbersCollection().insertOne(phoneData);
44
38
 
45
39
  const result = await getPhoneDataByPhoneNumber(phoneData.phone_number);
46
-
40
+
47
41
  expect(result).toBeDefined();
48
42
  expect(result).toMatchObject({
49
43
  client_id: phoneData.client_id,
@@ -52,20 +46,15 @@ describe("db.phoneNumbers", () => {
52
46
  });
53
47
  // Specifically check if the flow was joined correctly
54
48
  expect(result?.flow.flowName).toBe(flow.flowName);
55
- expect(
56
- result?.flow.conversationSettings?.silence?.firstWarningSilenceSeconds,
57
- ).toBe(5);
49
+ expect(result?.flow.conversationSettings?.silence?.firstWarningSilenceSeconds).toBe(5);
58
50
  });
59
51
  });
60
52
 
61
- describe("getClientPhoneNumber", () => {
62
- it("return phone number by client id", async () => {
53
+ describe('getClientPhoneNumber', () => {
54
+ it('return phone number by client id', async () => {
63
55
  const flow = createFlow();
64
- const phoneData = createPhoneNumber({
65
- flow_id: flow._id,
66
- is_primary: true,
67
- });
68
-
56
+ const phoneData = createPhoneNumber({ flow_id: flow._id, is_primary: true });
57
+
69
58
  await getFlowsCollection().insertOne(flow);
70
59
  await getPhoneNumbersCollection().insertOne(phoneData);
71
60
 
@@ -74,84 +63,55 @@ describe("db.phoneNumbers", () => {
74
63
  });
75
64
  });
76
65
 
77
- describe("getClientPhoneData", () => {
78
- it("returns primary phone data by default", async () => {
79
- const clientId = "multiPhoneClient";
80
- const phone1 = createPhoneNumber({
81
- client_id: clientId,
82
- is_primary: false,
83
- phone_number: "1",
84
- createdAt: new Date("2023-01-01"),
85
- });
86
- const phone2 = createPhoneNumber({
87
- client_id: clientId,
88
- is_primary: true,
89
- phone_number: "2",
90
- createdAt: new Date("2023-01-02"),
91
- });
66
+ describe('getClientPhoneData', () => {
67
+ it('returns primary phone data by default', async () => {
68
+ const clientId = 'multiPhoneClient';
69
+ const phone1 = createPhoneNumber({ client_id: clientId, is_primary: false, phone_number: '1', createdAt: new Date('2023-01-01') });
70
+ const phone2 = createPhoneNumber({ client_id: clientId, is_primary: true, phone_number: '2', createdAt: new Date('2023-01-02') });
92
71
 
93
72
  await getPhoneNumbersCollection().insertOne(phone1);
94
73
  await getPhoneNumbersCollection().insertOne(phone2);
95
74
 
96
75
  const result = await getClientPhoneData(clientId);
97
- expect(result?.phone_number).toBe("2");
76
+ expect(result?.phone_number).toBe('2');
98
77
  });
99
78
 
100
- it("returns most recent non-primary phone data if isPrimary is false", async () => {
101
- const clientId = "multiPhoneClient2";
102
- const phone1 = createPhoneNumber({
103
- client_id: clientId,
104
- is_primary: false,
105
- phone_number: "1",
106
- createdAt: new Date("2023-01-01"),
107
- });
108
- const phone2 = createPhoneNumber({
109
- client_id: clientId,
110
- is_primary: false,
111
- phone_number: "2",
112
- createdAt: new Date("2023-01-02"),
113
- });
114
- const phone3 = createPhoneNumber({
115
- client_id: clientId,
116
- is_primary: true,
117
- phone_number: "3",
118
- createdAt: new Date("2023-01-03"),
119
- });
79
+ it('returns most recent non-primary phone data if isPrimary is false', async () => {
80
+ const clientId = 'multiPhoneClient2';
81
+ const phone1 = createPhoneNumber({ client_id: clientId, is_primary: false, phone_number: '1', createdAt: new Date('2023-01-01') });
82
+ const phone2 = createPhoneNumber({ client_id: clientId, is_primary: false, phone_number: '2', createdAt: new Date('2023-01-02') });
83
+ const phone3 = createPhoneNumber({ client_id: clientId, is_primary: true, phone_number: '3', createdAt: new Date('2023-01-03') });
120
84
 
121
85
  await getPhoneNumbersCollection().insertOne(phone1);
122
86
  await getPhoneNumbersCollection().insertOne(phone2);
123
87
  await getPhoneNumbersCollection().insertOne(phone3);
124
88
 
125
89
  const result = await getClientPhoneData(clientId, false);
126
- expect(result?.phone_number).toBe("2");
90
+ expect(result?.phone_number).toBe('2');
127
91
  });
128
92
  });
129
93
 
130
- describe("createPhoneNumberEntity", () => {
131
- it("creates first phone number as primary", async () => {
132
- const clientId = "newClient";
94
+ describe('createPhoneNumberEntity', () => {
95
+ it('creates first phone number as primary', async () => {
96
+ const clientId = 'newClient';
133
97
  const flowId = new ObjectId().toHexString();
134
- const phoneNumber = "+123456789";
98
+ const phoneNumber = '+123456789';
135
99
 
136
- const result = await createPhoneNumberEntity(
137
- phoneNumber,
138
- flowId,
139
- clientId,
140
- );
100
+ const result = await createPhoneNumberEntity(phoneNumber, flowId, clientId);
141
101
  expect(result.phone_number).toBe(phoneNumber);
142
102
  expect(result.is_primary).toBe(true);
143
103
  });
144
104
 
145
- it("creates subsequent phone number as non-primary", async () => {
146
- const clientId = "existingClient";
105
+ it('creates subsequent phone number as non-primary', async () => {
106
+ const clientId = 'existingClient';
147
107
  const flowId = new ObjectId().toHexString();
148
-
108
+
149
109
  // Create first one
150
- await createPhoneNumberEntity("+111", flowId, clientId);
151
-
110
+ await createPhoneNumberEntity('+111', flowId, clientId);
111
+
152
112
  // Create second one
153
- const result = await createPhoneNumberEntity("+222", flowId, clientId);
154
- expect(result.phone_number).toBe("+222");
113
+ const result = await createPhoneNumberEntity('+222', flowId, clientId);
114
+ expect(result.phone_number).toBe('+222');
155
115
  expect(result.is_primary).toBe(false);
156
116
  });
157
117
  });
@@ -1,2 +1,2 @@
1
- export * from "./phone_numbers.getter";
2
- export type { PhoneNumber } from "./phone_numbers.types";
1
+ export * from './phone_numbers.getter';
2
+ export type { PhoneNumber } from './phone_numbers.types';
@@ -1,4 +1,4 @@
1
- import type { Collection } from "mongodb";
1
+ import type { Collection } from 'mongodb';
2
2
  import {
3
3
  Client,
4
4
  getClientsCollection,
@@ -6,50 +6,33 @@ import {
6
6
  getFlowsCollection,
7
7
  ObjectId,
8
8
  findSubscriptions,
9
- } from "../index";
10
- import { PhoneNumber, PhoneNumberWithFlow } from "./phone_numbers.types";
9
+ } from '../index';
10
+ import { PhoneNumber, PhoneNumberWithFlow } from './phone_numbers.types';
11
11
 
12
12
  export const getPhoneNumbersCollection = (): Collection<PhoneNumber> =>
13
- getDb().collection<PhoneNumber>("phone_numbers");
13
+ getDb().collection<PhoneNumber>('phone_numbers');
14
14
 
15
15
  export const getPhoneDataByPhoneNumber = async (
16
- phoneNumber: string,
16
+ phoneNumber: string
17
17
  ): Promise<PhoneNumberWithFlow | null> => {
18
- const phoneCallData = await getPhoneNumbersCollection().findOne({
19
- phone_number: phoneNumber,
20
- });
18
+ const phoneCallData = await getPhoneNumbersCollection().findOne({ phone_number: phoneNumber });
21
19
  if (!phoneCallData) {
22
- throw new Error("PhoneNumber not found");
20
+ throw new Error('PhoneNumber not found');
23
21
  }
24
- const flow = await getFlowsCollection().findOne({
25
- _id: new ObjectId(phoneCallData.flow_id),
26
- });
22
+ const flow = await getFlowsCollection().findOne({ _id: new ObjectId(phoneCallData.flow_id) });
27
23
  if (!flow) {
28
- throw new Error("Flow not found");
24
+ throw new Error('Flow not found');
29
25
  }
30
26
  const [subscription] =
31
- (await findSubscriptions({
32
- clientId: phoneCallData.client_id,
33
- isActive: true,
34
- })) || [];
27
+ (await findSubscriptions({ clientId: phoneCallData.client_id, isActive: true })) || [];
35
28
 
36
- return {
37
- ...phoneCallData,
38
- flow,
39
- subscriptionId: subscription?._id?.toString() ?? undefined,
40
- };
29
+ return { ...phoneCallData, flow, subscriptionId: subscription?._id?.toString() ?? undefined };
41
30
  };
42
31
 
43
- export const getClientPrimaryPhoneNumber = async (
44
- clientId: string,
45
- ): Promise<string | null> => {
32
+ export const getClientPrimaryPhoneNumber = async (clientId: string): Promise<string | null> => {
46
33
  return (
47
- (
48
- await getPhoneNumbersCollection().findOne({
49
- client_id: clientId,
50
- is_primary: true,
51
- })
52
- )?.phone_number ?? null
34
+ (await getPhoneNumbersCollection().findOne({ client_id: clientId, is_primary: true }))
35
+ ?.phone_number ?? null
53
36
  );
54
37
  };
55
38
 
@@ -57,18 +40,17 @@ export const getClientPhoneNumber = getClientPrimaryPhoneNumber;
57
40
 
58
41
  export const getClientPhoneData = async (
59
42
  clientId: string,
60
- isPrimary?: boolean,
43
+ isPrimary?: boolean
61
44
  ): Promise<PhoneNumber | null> => {
62
45
  const filter = { client_id: clientId, is_primary: isPrimary !== false };
63
- const options =
64
- isPrimary === false ? { sort: { createdAt: -1 } as const } : {};
46
+ const options = isPrimary === false ? { sort: { createdAt: -1 } as const } : {};
65
47
  return getPhoneNumbersCollection().findOne(filter, options);
66
48
  };
67
49
 
68
50
  export const createPhoneNumberEntity = async (
69
51
  phoneNumber: string,
70
52
  flowId: string,
71
- clientId: string,
53
+ clientId: string
72
54
  ): Promise<PhoneNumber> => {
73
55
  const existing = await getClientPhoneData(clientId);
74
56
  const isPrimary = !existing;
@@ -82,19 +64,15 @@ export const createPhoneNumberEntity = async (
82
64
  updatedAt: new Date(),
83
65
  });
84
66
  const phoneNumberData = await getClientPhoneData(clientId, isPrimary);
85
- if (!phoneNumberData) throw new Error("Failed to create phoneNumber");
67
+ if (!phoneNumberData) throw new Error('Failed to create phoneNumber');
86
68
  return phoneNumberData;
87
69
  };
88
70
 
89
- export const findClientByPhoneNumber = async (
90
- phoneNumber: string,
91
- ): Promise<Client> => {
92
- const phoneData = await getPhoneNumbersCollection().findOne({
93
- phone_number: phoneNumber,
94
- });
95
- if (!phoneData) throw new Error("Failed to get phone data");
71
+ export const findClientByPhoneNumber = async (phoneNumber: string): Promise<Client> => {
72
+ const phoneData = await getPhoneNumbersCollection().findOne({ phone_number: phoneNumber });
73
+ if (!phoneData) throw new Error('Failed to get phone data');
96
74
  const clientId = phoneData.client_id;
97
75
  const client = await getClientsCollection().findOne({ clientId });
98
- if (!client) throw new Error("Failed to get client");
76
+ if (!client) throw new Error('Failed to get client');
99
77
  return client;
100
78
  };