@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,14 +1,14 @@
1
1
  export const phoneNumbersMongoSchema = {
2
- bsonType: "object",
3
- required: ["client_id", "flow_id", "phone_number"],
2
+ bsonType: 'object',
3
+ required: ['client_id', 'flow_id', 'phone_number'],
4
4
  properties: {
5
- _id: { bsonType: "objectId" },
6
- client_id: { bsonType: "string" },
7
- flow_id: { bsonType: "string" },
8
- phone_number: { bsonType: "string" },
9
- is_primary: { bsonType: "bool" },
10
- createdAt: { bsonType: "date" },
11
- updatedAt: { bsonType: "date" },
5
+ _id: { bsonType: 'objectId' },
6
+ client_id: { bsonType: 'string' },
7
+ flow_id: { bsonType: 'string' },
8
+ phone_number: { bsonType: 'string' },
9
+ is_primary: { bsonType: 'bool' },
10
+ createdAt: { bsonType: 'date' },
11
+ updatedAt: { bsonType: 'date' },
12
12
  },
13
13
  additionalProperties: false,
14
14
  } as const;
@@ -1,5 +1,5 @@
1
1
  import { ObjectId, WithId } from "mongodb";
2
- import { Flow } from "../flows";
2
+ import { Flow } from "../flows/flows.types";
3
3
 
4
4
  export type PhoneNumber = {
5
5
  _id?: ObjectId;
@@ -5,65 +5,61 @@ import {
5
5
  countPlans,
6
6
  updatePlanDoc,
7
7
  getPlansCollection,
8
- } from "../plans.getters";
9
- import { Plan } from "../plans.types";
8
+ } from '../plans.getters';
9
+ import { ObjectId } from 'mongodb';
10
+ import { Plan } from '../plans.types';
10
11
 
11
- describe("db.plans", () => {
12
- const createTestPlan = (
13
- overrides?: Partial<Plan>,
14
- ): Omit<Plan, "createdAt" | "updatedAt"> => ({
15
- productKey: "basic-500",
16
- name: "Basic 500",
12
+ describe('db.plans', () => {
13
+ const createTestPlan = (overrides?: Partial<Plan>): Omit<Plan, 'createdAt' | 'updatedAt'> => ({
14
+ productKey: 'basic-500',
15
+ name: 'Basic 500',
17
16
  monthlyCallQuota: 500,
18
- currency: "ILS",
17
+ currency: 'ILS',
19
18
  priceMonthlyMinor: 10000,
20
19
  isActive: true,
21
20
  ...overrides,
22
21
  });
23
22
 
24
- it("should create and find a plan", async () => {
25
- const planData = createTestPlan({ name: "CreateTest" });
23
+ it('should create and find a plan', async () => {
24
+ const planData = createTestPlan({ name: 'CreateTest' });
26
25
  const created = await createPlanDoc(planData);
27
-
26
+
28
27
  expect(created._id).toBeDefined();
29
- expect(created.name).toBe("CreateTest");
28
+ expect(created.name).toBe('CreateTest');
30
29
 
31
30
  const found = await findPlans({ _id: created._id });
32
31
  expect(found.length).toBe(1);
33
- expect(found[0].name).toBe("CreateTest");
32
+ expect(found[0].name).toBe('CreateTest');
34
33
  });
35
34
 
36
- it("should find plans by query with limit", async () => {
35
+ it('should find plans by query with limit', async () => {
37
36
  await getPlansCollection().deleteMany({});
38
- await createPlanDoc(createTestPlan({ productKey: "p1", isActive: true }));
39
- await createPlanDoc(createTestPlan({ productKey: "p2", isActive: true }));
40
- await createPlanDoc(createTestPlan({ productKey: "p3", isActive: false }));
37
+ await createPlanDoc(createTestPlan({ productKey: 'p1', isActive: true }));
38
+ await createPlanDoc(createTestPlan({ productKey: 'p2', isActive: true }));
39
+ await createPlanDoc(createTestPlan({ productKey: 'p3', isActive: false }));
41
40
 
42
- const activePlans = await findPlansByQuery(
43
- { isActive: true },
44
- { limit: 1 },
45
- );
41
+ const activePlans = await findPlansByQuery({ isActive: true }, { limit: 1 });
46
42
  expect(activePlans.length).toBe(1);
47
43
  expect(activePlans[0].isActive).toBe(true);
48
44
  });
49
45
 
50
- it("should count plans matching query", async () => {
46
+ it('should count plans matching query', async () => {
51
47
  await getPlansCollection().deleteMany({});
52
- await createPlanDoc(createTestPlan({ currency: "USD" }));
53
- await createPlanDoc(createTestPlan({ currency: "USD" }));
54
- await createPlanDoc(createTestPlan({ currency: "ILS" }));
48
+ await createPlanDoc(createTestPlan({ currency: 'USD' }));
49
+ await createPlanDoc(createTestPlan({ currency: 'USD' }));
50
+ await createPlanDoc(createTestPlan({ currency: 'ILS' }));
55
51
 
56
- const count = await countPlans({ currency: "USD" });
52
+ const count = await countPlans({ currency: 'USD' });
57
53
  expect(count).toBe(2);
58
54
  });
59
55
 
60
- it("should update a plan", async () => {
56
+ it('should update a plan', async () => {
61
57
  const plan = await createPlanDoc(createTestPlan({ isActive: true }));
62
58
  const updated = await updatePlanDoc(plan._id, { isActive: false });
63
-
59
+
64
60
  expect(updated).not.toBeNull();
65
61
  expect(updated?.isActive).toBe(false);
66
-
62
+
67
63
  const found = await findPlans({ _id: plan._id });
68
64
  expect(found[0].isActive).toBe(false);
69
65
  });
@@ -1,2 +1,2 @@
1
- export * from "./plans.types";
2
- export * from "./plans.getters";
1
+ export * from './plans.types';
2
+ export * from './plans.getters';
@@ -1,16 +1,9 @@
1
- import {
2
- getDb,
3
- Plan,
4
- PlanDoc,
5
- PlanFilter,
6
- PlanQueryOptions,
7
- SimplePlanFilter,
8
- } from "../index";
9
- import { Filter, ObjectId } from "mongodb";
10
- import { applyQueryOptions } from "../utils/query.utils";
1
+ import {getDb, Plan, PlanDoc, PlanFilter, PlanQueryOptions, SimplePlanFilter} from '../index';
2
+ import {Filter, ObjectId} from 'mongodb';
3
+ import {applyQueryOptions} from '../utils/query.utils';
11
4
 
12
5
  export const getPlansCollection = () => {
13
- return getDb().collection<Plan>("plans");
6
+ return getDb().collection<Plan>('plans');
14
7
  };
15
8
 
16
9
  /**
@@ -49,7 +42,7 @@ const buildSimpleQuery = (filter: SimplePlanFilter): Filter<Plan> => {
49
42
  */
50
43
  export const findPlans = async (
51
44
  filter?: PlanFilter,
52
- options?: PlanQueryOptions,
45
+ options?: PlanQueryOptions
53
46
  ): Promise<PlanDoc[]> => {
54
47
  let query: Filter<Plan> = {};
55
48
 
@@ -88,7 +81,7 @@ export const findPlans = async (
88
81
 
89
82
  export const findPlansByQuery = async (
90
83
  query: Filter<Plan>,
91
- options?: PlanQueryOptions,
84
+ options?: PlanQueryOptions
92
85
  ): Promise<PlanDoc[]> => {
93
86
  const cursor = getPlansCollection().find(query);
94
87
  return await applyQueryOptions(cursor, options).toArray();
@@ -99,7 +92,7 @@ export const countPlans = async (query: Filter<Plan>): Promise<number> => {
99
92
  };
100
93
 
101
94
  export const createPlanDoc = async (
102
- planData: Omit<Plan, "createdAt" | "updatedAt">,
95
+ planData: Omit<Plan, 'createdAt' | 'updatedAt'>
103
96
  ): Promise<PlanDoc> => {
104
97
  const now = new Date();
105
98
  const result = await getPlansCollection().insertOne({
@@ -109,24 +102,24 @@ export const createPlanDoc = async (
109
102
  });
110
103
 
111
104
  const plans = await findPlans({ _id: result.insertedId });
112
- if (!plans[0]) throw new Error("Failed to retrieve created plan");
105
+ if (!plans[0]) throw new Error('Failed to retrieve created plan');
113
106
  return plans[0];
114
107
  };
115
108
 
116
109
  export const updatePlanDoc = async (
117
110
  planId: ObjectId,
118
- updates: Partial<Omit<Plan, "createdAt" | "updatedAt">>,
111
+ updates: Partial<Omit<Plan, 'createdAt' | 'updatedAt'>>
119
112
  ): Promise<PlanDoc | null> => {
120
113
  return await getPlansCollection().findOneAndUpdate(
121
- { _id: planId },
122
- {
123
- $set: {
124
- ...updates,
125
- updatedAt: new Date(),
114
+ {_id: planId},
115
+ {
116
+ $set: {
117
+ ...updates,
118
+ updatedAt: new Date(),
119
+ },
126
120
  },
127
- },
128
- {
129
- returnDocument: "after",
130
- },
121
+ {
122
+ returnDocument: 'after',
123
+ }
131
124
  );
132
125
  };
@@ -1,44 +1,40 @@
1
- import { Sort, ObjectId, WithId } from "mongodb";
1
+ import { Sort, ObjectId, WithId } from 'mongodb';
2
2
 
3
- export const CURRENCY_CODES = ["ILS", "USD", "EUR"] as const;
3
+ export const CURRENCY_CODES = ['ILS', 'USD', 'EUR'] as const;
4
4
  export type CurrencyCode = (typeof CURRENCY_CODES)[number];
5
5
 
6
6
  /** Required fields for creating a new plan */
7
7
  export const PLAN_REQUIRED_FIELDS = [
8
- "productKey",
9
- "name",
10
- "monthlyCallQuota",
11
- "currency",
12
- "priceMonthlyMinor",
13
- "isActive",
8
+ 'productKey',
9
+ 'name',
10
+ 'monthlyCallQuota',
11
+ 'currency',
12
+ 'priceMonthlyMinor',
13
+ 'isActive',
14
14
  ];
15
15
 
16
16
  /** All allowed fields that can be set/updated on a plan (excluding system fields) */
17
17
  export const PLAN_ALLOWED_FIELDS = [
18
- "productKey",
19
- "name",
20
- "monthlyCallQuota",
21
- "currency",
22
- "priceMonthlyMinor",
23
- "region",
24
- "countryCode",
25
- "isActive",
26
- "originalPlanId",
27
- "tax",
28
- "metadata",
29
- "updatedAt",
18
+ 'productKey',
19
+ 'name',
20
+ 'monthlyCallQuota',
21
+ 'currency',
22
+ 'priceMonthlyMinor',
23
+ 'region',
24
+ 'countryCode',
25
+ 'isActive',
26
+ 'originalPlanId',
27
+ 'tax',
28
+ 'metadata',
29
+ 'updatedAt',
30
30
  ];
31
31
 
32
32
  /** Logical product family, like "basic-500". Multiple regional variants can share it. */
33
- export type ProductKey =
34
- | "basic-500"
35
- | "pro-1100"
36
- | "scale-6000"
37
- | (string & {});
33
+ export type ProductKey = 'basic-500' | 'pro-1100' | 'scale-6000' | (string & {});
38
34
 
39
35
  /** Optional targeting to keep variants explicit */
40
- export type RegionCode = "IL" | "EU" | "US" | (string & {});
41
- export type CountryCode = "IL" | "DE" | "FR" | "ES" | "GB" | (string & {});
36
+ export type RegionCode = 'IL' | 'EU' | 'US' | (string & {});
37
+ export type CountryCode = 'IL' | 'DE' | 'FR' | 'ES' | 'GB' | (string & {});
42
38
 
43
39
  export type Tax = {
44
40
  vatIncluded: boolean;
@@ -1,5 +1,2 @@
1
- export {
2
- getResultsCollection,
3
- initializeResultDocument,
4
- } from "./results.getter";
5
- export type * from "./results.types";
1
+ export { getResultsCollection, initializeResultDocument } from './results.getter';
2
+ export type * from './results.types';
@@ -1,9 +1,8 @@
1
- import type { Collection } from "mongodb";
2
- import { getDb, ObjectId, Session } from "../index";
3
- import type { Result } from "./results.types";
1
+ import type { Collection } from 'mongodb';
2
+ import { getDb, ObjectId, Session } from '../index';
3
+ import type { Result } from './results.types';
4
4
 
5
- export const getResultsCollection = (): Collection<Result> =>
6
- getDb().collection<Result>("results");
5
+ export const getResultsCollection = (): Collection<Result> => getDb().collection<Result>('results');
7
6
 
8
7
  export const createRunId = (): string => {
9
8
  return `run_${new ObjectId().toString()}`;
@@ -11,17 +10,17 @@ export const createRunId = (): string => {
11
10
 
12
11
  export const initializeResultDocument = async (
13
12
  clientId: string,
14
- session?: Session,
13
+ session?: Session
15
14
  ): Promise<Result> => {
16
15
  const { insertedId } = await getResultsCollection().insertOne({
17
16
  runId: createRunId(),
18
17
  date: new Date(),
19
18
  calls: [],
20
- sessionId: session ? session._id!.toString() : "incomingCall",
21
- sessionName: session ? session.session_name : "incomingCall",
19
+ sessionId: session ? session._id!.toString() : 'incomingCall',
20
+ sessionName: session ? session.session_name : 'incomingCall',
22
21
  clientId,
23
22
  });
24
23
  const result = await getResultsCollection().findOne({ _id: insertedId });
25
- if (!result) throw new Error("Failed to initialized result");
24
+ if (!result) throw new Error('Failed to initialized result');
26
25
  return result;
27
26
  };
@@ -1,25 +1,25 @@
1
1
  export const resultMongoSchema = {
2
- bsonType: "object",
2
+ bsonType: 'object',
3
3
  required: [
4
- "_id",
5
- "sessionId",
6
- "status",
7
- "callLength",
8
- "date",
9
- "userAnswer",
10
- "systemSessionId",
11
- "clientId",
4
+ '_id',
5
+ 'sessionId',
6
+ 'status',
7
+ 'callLength',
8
+ 'date',
9
+ 'userAnswer',
10
+ 'systemSessionId',
11
+ 'clientId',
12
12
  ],
13
13
  properties: {
14
- _id: { bsonType: "objectId" },
15
- sessionId: { bsonType: "string" },
16
- status: { bsonType: "string" },
17
- callLength: { bsonType: "string" },
18
- date: { bsonType: "date" },
19
- userAnswer: { bsonType: "string" },
20
- recordingUrl: { bsonType: ["string", "null"] },
21
- systemSessionId: { bsonType: "string" },
22
- clientId: { bsonType: "string" },
14
+ _id: { bsonType: 'objectId' },
15
+ sessionId: { bsonType: 'string' },
16
+ status: { bsonType: 'string' },
17
+ callLength: { bsonType: 'string' },
18
+ date: { bsonType: 'date' },
19
+ userAnswer: { bsonType: 'string' },
20
+ recordingUrl: { bsonType: ['string', 'null'] },
21
+ systemSessionId: { bsonType: 'string' },
22
+ clientId: { bsonType: 'string' },
23
23
  },
24
24
  additionalProperties: false,
25
25
  } as const;
@@ -1,4 +1,4 @@
1
- import { ObjectId } from "mongodb";
1
+ import { ObjectId } from 'mongodb';
2
2
 
3
3
  export interface Result {
4
4
  _id?: ObjectId;
@@ -1,52 +1,39 @@
1
- import {
2
- findSessionOfIncomingCall,
3
- getSessionsCollection,
4
- } from "../sessions.getter";
5
- import { getFlowsCollection } from "../../flows";
6
- import { getPhoneNumbersCollection } from "../../phone_numbers";
7
- import {
8
- createFlow,
9
- createPhoneNumber,
10
- createSession,
11
- } from "../../../test-utils/factories";
12
- import { faker } from "@faker-js/faker";
13
- import { ObjectId } from "mongodb";
14
-
15
- describe("sessions", () => {
16
- describe("findSessionOfIncomingCall()", () => {
17
- it("returns session by incoming phone number", async () => {
18
- const to = "+972500000000";
19
- const from = "+972540000000";
1
+ import { findSessionOfIncomingCall, getSessionsCollection } from '../sessions.getter';
2
+ import { getFlowsCollection } from '../../flows/flows.getter';
3
+ import { getPhoneNumbersCollection } from '../../phone_numbers/phone_numbers.getter';
4
+ import { createFlow, createPhoneNumber, createSession } from '../../../test-utils/factories';
5
+ import { faker } from '@faker-js/faker';
6
+ import { ObjectId } from 'mongodb';
7
+
8
+ describe('sessions', () => {
9
+ describe('findSessionOfIncomingCall()', () => {
10
+ it('returns session by incoming phone number', async () => {
11
+ const to = '+972500000000';
12
+ const from = '+972540000000';
20
13
  const flow = createFlow({
21
14
  conversationSettings: {
22
15
  interruptions: {
23
16
  enableInterruptionDetection: true,
24
17
  interruptionWindowSeconds: 60,
25
18
  interruptionThresholdSeconds: 10,
26
- interruptionInstruction:
27
- "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.",
19
+ 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.',
28
20
  },
29
21
  silence: {
30
22
  enableSilenceDetection: true,
31
23
  firstWarningSilenceSeconds: 5,
32
- firstWarningInstruction:
33
- "I have not heard you for a few seconds. If you are still on the line, please say something so we can continue.",
24
+ firstWarningInstruction: 'I have not heard you for a few seconds. If you are still on the line, please say something so we can continue.',
34
25
  secondWarningSilenceSeconds: 10,
35
- secondWarningInstruction:
36
- "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.",
26
+ 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.',
37
27
  disconnectSilenceSeconds: 30,
38
28
  },
39
29
  },
40
30
  });
41
- const phoneNumberData = createPhoneNumber({
42
- phone_number: to,
43
- flow_id: flow._id,
44
- });
31
+ const phoneNumberData = createPhoneNumber({ phone_number: to, flow_id: flow._id });
45
32
  const json = { [faker.lorem.word()]: faker.lorem.sentence() };
46
33
 
47
34
  const session = createSession({
48
35
  flow_id: flow._id,
49
- phone_numbers: [{ phoneNumber: from, gender: "male", name: "yakov" }],
36
+ phone_numbers: [{ phoneNumber: from, gender: 'male', name: 'yakov' }],
50
37
  json,
51
38
  });
52
39
 
@@ -60,20 +47,15 @@ describe("sessions", () => {
60
47
  expect(result?.flow_id).toEqual(flow._id);
61
48
  });
62
49
 
63
- it("works with different phone number formats (with/without plus)", async () => {
64
- const toInDB = "972500000000";
65
- const fromInDB = "+972540000000";
50
+ it('works with different phone number formats (with/without plus)', async () => {
51
+ const toInDB = '972500000000';
52
+ const fromInDB = '+972540000000';
66
53
  const flow = createFlow();
67
- const phoneNumberData = createPhoneNumber({
68
- phone_number: toInDB,
69
- flow_id: flow._id,
70
- });
54
+ const phoneNumberData = createPhoneNumber({ phone_number: toInDB, flow_id: flow._id });
71
55
 
72
56
  const session = createSession({
73
57
  flow_id: flow._id,
74
- phone_numbers: [
75
- { phoneNumber: fromInDB, gender: "female", name: "sara" },
76
- ],
58
+ phone_numbers: [{ phoneNumber: fromInDB, gender: 'female', name: 'sara' }],
77
59
  });
78
60
 
79
61
  await getFlowsCollection().insertOne(flow);
@@ -81,28 +63,25 @@ describe("sessions", () => {
81
63
  await getSessionsCollection().insertOne(session);
82
64
 
83
65
  // Search with from WITH plus (matches + in DB), to WITH plus (matches without + in DB)
84
- const result = await findSessionOfIncomingCall(
85
- "+972540000000",
86
- "+972500000000",
87
- );
66
+ const result = await findSessionOfIncomingCall('+972540000000', '+972500000000');
88
67
  expect(result).not.toBeNull();
89
68
  expect(result?.phone_numbers[0].phoneNumber).toEqual(fromInDB);
90
69
  });
91
70
 
92
- it("works when flow_id is string in phone_numbers and ObjectId in session", async () => {
93
- const to = "+972501111111";
94
- const from = "+972541111111";
71
+ it('works when flow_id is string in phone_numbers and ObjectId in session', async () => {
72
+ const to = '+972501111111';
73
+ const from = '+972541111111';
95
74
  const flowId = new ObjectId();
96
-
75
+
97
76
  // Store flow_id as string in phone_numbers
98
- const phoneNumberData = createPhoneNumber({
99
- phone_number: to,
100
- flow_id: flowId.toHexString() as any,
77
+ const phoneNumberData = createPhoneNumber({
78
+ phone_number: to,
79
+ flow_id: flowId.toHexString() as any
101
80
  });
102
81
 
103
82
  const session = createSession({
104
83
  flow_id: flowId, // stored as ObjectId
105
- phone_numbers: [{ phoneNumber: from, gender: "male", name: "isaac" }],
84
+ phone_numbers: [{ phoneNumber: from, gender: 'male', name: 'isaac' }],
106
85
  });
107
86
 
108
87
  await getPhoneNumbersCollection().insertOne(phoneNumberData);
@@ -113,19 +92,19 @@ describe("sessions", () => {
113
92
  expect(result?.flow_id?.toString()).toEqual(flowId.toHexString());
114
93
  });
115
94
 
116
- it("works when flow_id is string in session", async () => {
117
- const to = "+972502222222";
118
- const from = "+972542222222";
95
+ it('works when flow_id is string in session', async () => {
96
+ const to = '+972502222222';
97
+ const from = '+972542222222';
119
98
  const flowId = new ObjectId();
120
-
121
- const phoneNumberData = createPhoneNumber({
122
- phone_number: to,
123
- flow_id: flowId,
99
+
100
+ const phoneNumberData = createPhoneNumber({
101
+ phone_number: to,
102
+ flow_id: flowId
124
103
  });
125
104
 
126
105
  const session = createSession({
127
106
  flow_id: flowId.toHexString(), // stored as string
128
- phone_numbers: [{ phoneNumber: from, gender: "female", name: "rivka" }],
107
+ phone_numbers: [{ phoneNumber: from, gender: 'female', name: 'rivka' }],
129
108
  });
130
109
 
131
110
  await getPhoneNumbersCollection().insertOne(phoneNumberData);
@@ -136,11 +115,8 @@ describe("sessions", () => {
136
115
  expect(result?.flow_id).toEqual(flowId.toHexString());
137
116
  });
138
117
 
139
- it("returns null if receiver phone number is not found", async () => {
140
- const result = await findSessionOfIncomingCall(
141
- "any-from",
142
- "non-existent-to",
143
- );
118
+ it('returns null if receiver phone number is not found', async () => {
119
+ const result = await findSessionOfIncomingCall('any-from', 'non-existent-to');
144
120
  expect(result).toBeNull();
145
121
  });
146
122
  });
@@ -1,2 +1,2 @@
1
- export * from "./sessions.getter";
2
- export * from "./sessions.types";
1
+ export * from './sessions.getter';
2
+ export * from './sessions.types';
@@ -1,22 +1,20 @@
1
- import { ObjectId } from "mongodb";
2
- import type { Collection, WithId } from "mongodb";
3
- import { getDb, getPhoneNumbersCollection } from "../index";
4
- import type { Session } from "./sessions.types";
1
+ import { ObjectId } from 'mongodb';
2
+ import type { Collection, WithId } from 'mongodb';
3
+ import { getDb, getPhoneNumbersCollection } from '../index';
4
+ import type { Session } from './sessions.types';
5
5
 
6
6
  export const getSessionsCollection = (): Collection<Session> =>
7
- getDb().collection<Session>("sessions");
7
+ getDb().collection<Session>('sessions');
8
8
 
9
9
  const buildPhoneCandidates = (phone: string): string[] => {
10
- const raw = (phone ?? "").trim();
10
+ const raw = (phone ?? '').trim();
11
11
  if (!raw) return [];
12
12
 
13
- const noPlus = raw.startsWith("+") ? raw.slice(1) : raw;
14
- const digitsOnly = raw.replace(/\D/g, "");
15
- const digitsOnlyNoPlus = noPlus.replace(/\D/g, "");
13
+ const noPlus = raw.startsWith('+') ? raw.slice(1) : raw;
14
+ const digitsOnly = raw.replace(/\D/g, '');
15
+ const digitsOnlyNoPlus = noPlus.replace(/\D/g, '');
16
16
 
17
- return Array.from(
18
- new Set([raw, noPlus, digitsOnly, digitsOnlyNoPlus].filter(Boolean)),
19
- );
17
+ return Array.from(new Set([raw, noPlus, digitsOnly, digitsOnlyNoPlus].filter(Boolean)));
20
18
  };
21
19
 
22
20
  const buildFlowIdCandidates = (flowId: unknown): Array<string | ObjectId> => {
@@ -38,12 +36,9 @@ const buildFlowIdCandidates = (flowId: unknown): Array<string | ObjectId> => {
38
36
 
39
37
  export const findSessionById = (
40
38
  sessionId: ObjectId,
41
- clientId: string,
39
+ clientId: string
42
40
  ): Promise<WithId<Session> | null> => {
43
- return getSessionsCollection().findOne({
44
- _id: sessionId,
45
- clientId: clientId,
46
- });
41
+ return getSessionsCollection().findOne({ _id: sessionId, clientId: clientId });
47
42
  };
48
43
 
49
44
  export const findSessionOfIncomingCall = async (from: string, to: string) => {
@@ -73,9 +68,9 @@ export const findSessionOfIncomingCall = async (from: string, to: string) => {
73
68
  $addFields: {
74
69
  phone_numbers: {
75
70
  $filter: {
76
- input: "$phone_numbers",
77
- as: "pn",
78
- cond: { $in: ["$$pn.phoneNumber", fromCandidates] },
71
+ input: '$phone_numbers',
72
+ as: 'pn',
73
+ cond: { $in: ['$$pn.phoneNumber', fromCandidates] },
79
74
  },
80
75
  },
81
76
  },
@@ -85,7 +80,7 @@ export const findSessionOfIncomingCall = async (from: string, to: string) => {
85
80
  .toArray();
86
81
 
87
82
  if (!session) {
88
- console.info("No session found for incoming call");
83
+ console.info('No session found for incoming call');
89
84
  return null;
90
85
  }
91
86
  return session;