@talkpilot/core-db 1.1.3 → 1.1.5

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 (329) hide show
  1. package/dist/connection.d.ts +1 -1
  2. package/dist/connection.d.ts.map +1 -1
  3. package/dist/connection.js +21 -24
  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 +8 -4
  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 +30 -22
  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 +13 -25
  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 +19 -9
  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 +10 -4
  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 +13 -8
  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 +50 -29
  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 +19 -15
  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 +5 -2
  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 +9 -2
  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.map +1 -1
  98. package/dist/talkpilot/flows/flows.schema.js +87 -79
  99. package/dist/talkpilot/flows/flows.schema.js.map +1 -1
  100. package/dist/talkpilot/flows/flows.types.d.ts +16 -16
  101. package/dist/talkpilot/flows/index.d.ts +2 -2
  102. package/dist/talkpilot/groups/groups.getters.d.ts +2 -2
  103. package/dist/talkpilot/groups/groups.getters.d.ts.map +1 -1
  104. package/dist/talkpilot/groups/groups.getters.js +2 -2
  105. package/dist/talkpilot/groups/groups.getters.js.map +1 -1
  106. package/dist/talkpilot/groups/groups.types.d.ts +1 -1
  107. package/dist/talkpilot/groups/index.d.ts +3 -3
  108. package/dist/talkpilot/groups/phone.utils.d.ts +1 -1
  109. package/dist/talkpilot/groups/phone.utils.d.ts.map +1 -1
  110. package/dist/talkpilot/groups/phone.utils.js +2 -2
  111. package/dist/talkpilot/groups/phone.utils.js.map +1 -1
  112. package/dist/talkpilot/index.d.ts +16 -16
  113. package/dist/talkpilot/index.js +1 -1
  114. package/dist/talkpilot/leads/index.d.ts +2 -2
  115. package/dist/talkpilot/leads/leads.getter.d.ts +2 -2
  116. package/dist/talkpilot/leads/leads.getter.d.ts.map +1 -1
  117. package/dist/talkpilot/leads/leads.getter.js +1 -1
  118. package/dist/talkpilot/leads/leads.getter.js.map +1 -1
  119. package/dist/talkpilot/leads/leads.schema.js +16 -16
  120. package/dist/talkpilot/leads/leads.types.d.ts +1 -1
  121. package/dist/talkpilot/mongodb-client.d.ts +1 -1
  122. package/dist/talkpilot/mongodb-client.d.ts.map +1 -1
  123. package/dist/talkpilot/mongodb-client.js +16 -29
  124. package/dist/talkpilot/mongodb-client.js.map +1 -1
  125. package/dist/talkpilot/phone_numbers/index.d.ts +2 -2
  126. package/dist/talkpilot/phone_numbers/phone_numbers.getter.d.ts +3 -3
  127. package/dist/talkpilot/phone_numbers/phone_numbers.getter.d.ts.map +1 -1
  128. package/dist/talkpilot/phone_numbers/phone_numbers.getter.js +28 -13
  129. package/dist/talkpilot/phone_numbers/phone_numbers.getter.js.map +1 -1
  130. package/dist/talkpilot/phone_numbers/phone_numbers.schema.js +9 -9
  131. package/dist/talkpilot/phone_numbers/phone_numbers.types.d.ts +1 -1
  132. package/dist/talkpilot/phone_numbers/phone_numbers.types.d.ts.map +1 -1
  133. package/dist/talkpilot/plans/index.d.ts +2 -2
  134. package/dist/talkpilot/plans/plans.getters.d.ts +2 -2
  135. package/dist/talkpilot/plans/plans.getters.d.ts.map +1 -1
  136. package/dist/talkpilot/plans/plans.getters.js +3 -3
  137. package/dist/talkpilot/plans/plans.getters.js.map +1 -1
  138. package/dist/talkpilot/plans/plans.types.d.ts +4 -4
  139. package/dist/talkpilot/plans/plans.types.d.ts.map +1 -1
  140. package/dist/talkpilot/plans/plans.types.js +19 -19
  141. package/dist/talkpilot/results/index.d.ts +2 -2
  142. package/dist/talkpilot/results/index.d.ts.map +1 -1
  143. package/dist/talkpilot/results/index.js.map +1 -1
  144. package/dist/talkpilot/results/results.getter.d.ts +3 -3
  145. package/dist/talkpilot/results/results.getter.d.ts.map +1 -1
  146. package/dist/talkpilot/results/results.getter.js +4 -4
  147. package/dist/talkpilot/results/results.getter.js.map +1 -1
  148. package/dist/talkpilot/results/results.schema.js +18 -18
  149. package/dist/talkpilot/results/results.types.d.ts +1 -1
  150. package/dist/talkpilot/sessions/index.d.ts +2 -2
  151. package/dist/talkpilot/sessions/sessions.getter.d.ts +3 -3
  152. package/dist/talkpilot/sessions/sessions.getter.d.ts.map +1 -1
  153. package/dist/talkpilot/sessions/sessions.getter.js +13 -10
  154. package/dist/talkpilot/sessions/sessions.getter.js.map +1 -1
  155. package/dist/talkpilot/sessions/sessions.schema.js +17 -17
  156. package/dist/talkpilot/sessions/sessions.types.d.ts +2 -2
  157. package/dist/talkpilot/subscriptions/index.d.ts +3 -3
  158. package/dist/talkpilot/subscriptions/subscriptions.getters.d.ts +2 -2
  159. package/dist/talkpilot/subscriptions/subscriptions.getters.d.ts.map +1 -1
  160. package/dist/talkpilot/subscriptions/subscriptions.getters.js +11 -11
  161. package/dist/talkpilot/subscriptions/subscriptions.getters.js.map +1 -1
  162. package/dist/talkpilot/subscriptions/subscriptions.getters.utils.d.ts +2 -2
  163. package/dist/talkpilot/subscriptions/subscriptions.getters.utils.d.ts.map +1 -1
  164. package/dist/talkpilot/subscriptions/subscriptions.getters.utils.js.map +1 -1
  165. package/dist/talkpilot/subscriptions/subscriptions.types.d.ts +2 -2
  166. package/dist/talkpilot/subscriptions/subscriptions.types.d.ts.map +1 -1
  167. package/dist/talkpilot/subscriptions/subscriptions.types.js +7 -7
  168. package/dist/talkpilot/subscriptions/subscriptions.utils.d.ts +4 -0
  169. package/dist/talkpilot/subscriptions/subscriptions.utils.d.ts.map +1 -0
  170. package/dist/talkpilot/subscriptions/subscriptions.utils.js +20 -0
  171. package/dist/talkpilot/subscriptions/subscriptions.utils.js.map +1 -0
  172. package/dist/talkpilot/utils/query.utils.d.ts +1 -1
  173. package/dist/test-utils/db-utils.d.ts +1 -1
  174. package/dist/test-utils/db-utils.js +2 -2
  175. package/dist/test-utils/factories/index.d.ts +12 -12
  176. package/dist/test-utils/factories/municipal/cities.d.ts +2 -2
  177. package/dist/test-utils/factories/municipal/cities.d.ts.map +1 -1
  178. package/dist/test-utils/factories/municipal/cities.js +1 -1
  179. package/dist/test-utils/factories/municipal/departmentsSubjects.d.ts +2 -2
  180. package/dist/test-utils/factories/municipal/departmentsSubjects.d.ts.map +1 -1
  181. package/dist/test-utils/factories/municipal/departmentsSubjects.js +7 -1
  182. package/dist/test-utils/factories/municipal/departmentsSubjects.js.map +1 -1
  183. package/dist/test-utils/factories/municipal/streets.d.ts +2 -2
  184. package/dist/test-utils/factories/municipal/streets.d.ts.map +1 -1
  185. package/dist/test-utils/factories/municipal/streets.js +6 -1
  186. package/dist/test-utils/factories/municipal/streets.js.map +1 -1
  187. package/dist/test-utils/factories/municipal/tickets.d.ts +2 -2
  188. package/dist/test-utils/factories/municipal/tickets.d.ts.map +1 -1
  189. package/dist/test-utils/factories/municipal/tickets.js +7 -1
  190. package/dist/test-utils/factories/municipal/tickets.js.map +1 -1
  191. package/dist/test-utils/factories/talkpilot/agents.d.ts +2 -2
  192. package/dist/test-utils/factories/talkpilot/agents.d.ts.map +1 -1
  193. package/dist/test-utils/factories/talkpilot/agents.js +4 -4
  194. package/dist/test-utils/factories/talkpilot/calls.d.ts +2 -2
  195. package/dist/test-utils/factories/talkpilot/calls.d.ts.map +1 -1
  196. package/dist/test-utils/factories/talkpilot/calls.js +1 -1
  197. package/dist/test-utils/factories/talkpilot/clientAudioBuffers.d.ts +2 -2
  198. package/dist/test-utils/factories/talkpilot/clientAudioBuffers.d.ts.map +1 -1
  199. package/dist/test-utils/factories/talkpilot/clientAudioBuffers.js +1 -1
  200. package/dist/test-utils/factories/talkpilot/clientAudioBuffers.js.map +1 -1
  201. package/dist/test-utils/factories/talkpilot/clientsConfig.d.ts +2 -2
  202. package/dist/test-utils/factories/talkpilot/clientsConfig.d.ts.map +1 -1
  203. package/dist/test-utils/factories/talkpilot/clientsConfig.js.map +1 -1
  204. package/dist/test-utils/factories/talkpilot/flows.d.ts +3 -3
  205. package/dist/test-utils/factories/talkpilot/flows.d.ts.map +1 -1
  206. package/dist/test-utils/factories/talkpilot/flows.js.map +1 -1
  207. package/dist/test-utils/factories/talkpilot/groups.d.ts +2 -2
  208. package/dist/test-utils/factories/talkpilot/groups.d.ts.map +1 -1
  209. package/dist/test-utils/factories/talkpilot/groups.js +9 -9
  210. package/dist/test-utils/factories/talkpilot/groups.js.map +1 -1
  211. package/dist/test-utils/factories/talkpilot/phone_numbers.d.ts +3 -3
  212. package/dist/test-utils/factories/talkpilot/phone_numbers.d.ts.map +1 -1
  213. package/dist/test-utils/factories/talkpilot/phone_numbers.js.map +1 -1
  214. package/dist/test-utils/factories/talkpilot/sessions.d.ts +2 -2
  215. package/dist/test-utils/factories/talkpilot/sessions.d.ts.map +1 -1
  216. package/dist/test-utils/factories/talkpilot/sessions.js +1 -1
  217. package/dist/utils/validation.js +2 -2
  218. package/dist/utils/validation.js.map +1 -1
  219. package/package.json +3 -1
  220. package/src/__tests__/setup.ts +3 -3
  221. package/src/connection.ts +27 -25
  222. package/src/index.ts +9 -9
  223. package/src/municipal/__tests__/validation.spec.ts +35 -23
  224. package/src/municipal/cities/cities.getters.ts +16 -10
  225. package/src/municipal/cities/cities.types.ts +1 -1
  226. package/src/municipal/cities/index.ts +2 -2
  227. package/src/municipal/departmentsSubjects/departmentsSubjects.getters.ts +53 -44
  228. package/src/municipal/departmentsSubjects/departmentsSubjects.types.ts +5 -5
  229. package/src/municipal/departmentsSubjects/index.ts +2 -3
  230. package/src/municipal/index.ts +10 -10
  231. package/src/municipal/mongodb-client.ts +19 -26
  232. package/src/municipal/streets/index.ts +2 -2
  233. package/src/municipal/streets/streets.getters.ts +43 -23
  234. package/src/municipal/streets/streets.types.ts +1 -1
  235. package/src/municipal/systemInstructions/__tests__/getters.spec.ts +67 -52
  236. package/src/municipal/systemInstructions/__tests__/setters.spec.ts +271 -238
  237. package/src/municipal/systemInstructions/index.ts +7 -3
  238. package/src/municipal/systemInstructions/instructions.getters.ts +30 -18
  239. package/src/municipal/systemInstructions/instructions.setters.ts +43 -19
  240. package/src/municipal/systemInstructions/instructions.types.ts +10 -10
  241. package/src/municipal/tickets/__tests__/tickets.getters.spec.ts +12 -12
  242. package/src/municipal/tickets/index.ts +2 -2
  243. package/src/municipal/tickets/tickets.getters.ts +69 -42
  244. package/src/municipal/tickets/tickets.types.ts +2 -2
  245. package/src/municipal/utils/types.ts +8 -3
  246. package/src/talkpilot/__tests__/db.spec.ts +12 -12
  247. package/src/talkpilot/__tests__/mongodb-client.spec.ts +7 -8
  248. package/src/talkpilot/__tests__/validation.spec.ts +30 -24
  249. package/src/talkpilot/agents/__tests__/agents.getters.spec.ts +10 -10
  250. package/src/talkpilot/agents/agents.getters.ts +3 -3
  251. package/src/talkpilot/agents/agents.types.ts +2 -2
  252. package/src/talkpilot/agents/index.ts +2 -2
  253. package/src/talkpilot/backgroundToolResults/__tests__/backgroundToolResults.getters.spec.ts +42 -31
  254. package/src/talkpilot/backgroundToolResults/backgroundToolResults.getters.ts +11 -11
  255. package/src/talkpilot/backgroundToolResults/backgroundToolResults.types.ts +2 -3
  256. package/src/talkpilot/backgroundToolResults/index.ts +2 -2
  257. package/src/talkpilot/calls/__tests__/callStats.utils.spec.ts +27 -27
  258. package/src/talkpilot/calls/__tests__/calls.spec.ts +79 -39
  259. package/src/talkpilot/calls/calls.getters.ts +48 -28
  260. package/src/talkpilot/calls/calls.types.ts +16 -16
  261. package/src/talkpilot/calls/index.ts +2 -2
  262. package/src/talkpilot/clientAudioBuffers/__tests__/clientAudioBuffer.getters.spec.ts +73 -39
  263. package/src/talkpilot/clientAudioBuffers/clientAudioBuffer.getters.ts +18 -11
  264. package/src/talkpilot/clientAudioBuffers/clientsAudioBuffers.types.ts +2 -2
  265. package/src/talkpilot/clientAudioBuffers/index.ts +2 -2
  266. package/src/talkpilot/clients/clients.getters.ts +10 -5
  267. package/src/talkpilot/clients/clients.types.ts +1 -1
  268. package/src/talkpilot/clients/index.ts +2 -2
  269. package/src/talkpilot/clientsConfig/__tests__/clientsConfig.spec.ts +21 -18
  270. package/src/talkpilot/clientsConfig/clientsConfig.getters.ts +6 -4
  271. package/src/talkpilot/clientsConfig/clientsConfig.types.ts +17 -7
  272. package/src/talkpilot/clientsConfig/index.ts +2 -2
  273. package/src/talkpilot/flows/__tests__/flows.schema.spec.ts +38 -34
  274. package/src/talkpilot/flows/flows.getter.ts +8 -5
  275. package/src/talkpilot/flows/flows.schema.ts +87 -79
  276. package/src/talkpilot/flows/flows.types.ts +23 -23
  277. package/src/talkpilot/flows/index.ts +2 -2
  278. package/src/talkpilot/groups/__tests__/groups.spec.ts +34 -27
  279. package/src/talkpilot/groups/__tests__/phone.utils.spec.ts +20 -20
  280. package/src/talkpilot/groups/groups.getters.ts +8 -5
  281. package/src/talkpilot/groups/groups.types.ts +1 -1
  282. package/src/talkpilot/groups/index.ts +3 -3
  283. package/src/talkpilot/groups/phone.utils.ts +12 -6
  284. package/src/talkpilot/index.ts +17 -17
  285. package/src/talkpilot/leads/index.ts +2 -2
  286. package/src/talkpilot/leads/leads.getter.ts +5 -4
  287. package/src/talkpilot/leads/leads.schema.ts +16 -16
  288. package/src/talkpilot/leads/leads.types.ts +1 -1
  289. package/src/talkpilot/mongodb-client.ts +23 -33
  290. package/src/talkpilot/phone_numbers/__tests__/phone_numbers.spec.ts +84 -44
  291. package/src/talkpilot/phone_numbers/index.ts +2 -2
  292. package/src/talkpilot/phone_numbers/phone_numbers.getter.ts +44 -22
  293. package/src/talkpilot/phone_numbers/phone_numbers.schema.ts +9 -9
  294. package/src/talkpilot/phone_numbers/phone_numbers.types.ts +1 -1
  295. package/src/talkpilot/plans/__tests__/plans.spec.ts +30 -26
  296. package/src/talkpilot/plans/index.ts +2 -2
  297. package/src/talkpilot/plans/plans.getters.ts +25 -18
  298. package/src/talkpilot/plans/plans.types.ts +27 -23
  299. package/src/talkpilot/results/index.ts +5 -2
  300. package/src/talkpilot/results/results.getter.ts +9 -8
  301. package/src/talkpilot/results/results.schema.ts +18 -18
  302. package/src/talkpilot/results/results.types.ts +1 -1
  303. package/src/talkpilot/sessions/__tests__/sessions.spec.ts +65 -41
  304. package/src/talkpilot/sessions/index.ts +2 -2
  305. package/src/talkpilot/sessions/sessions.getter.ts +21 -16
  306. package/src/talkpilot/sessions/sessions.schema.ts +17 -17
  307. package/src/talkpilot/sessions/sessions.types.ts +2 -2
  308. package/src/talkpilot/subscriptions/__tests__/subscriptions.getters.utils.spec.ts +18 -15
  309. package/src/talkpilot/subscriptions/index.ts +3 -3
  310. package/src/talkpilot/subscriptions/subscriptions.getters.ts +36 -33
  311. package/src/talkpilot/subscriptions/subscriptions.getters.utils.ts +10 -3
  312. package/src/talkpilot/subscriptions/subscriptions.types.ts +9 -9
  313. package/src/talkpilot/utils/__tests__/query.utils.spec.ts +8 -8
  314. package/src/talkpilot/utils/query.utils.ts +2 -2
  315. package/src/test-utils/db-utils.ts +5 -5
  316. package/src/test-utils/factories/index.ts +12 -12
  317. package/src/test-utils/factories/municipal/cities.ts +5 -5
  318. package/src/test-utils/factories/municipal/departmentsSubjects.ts +32 -25
  319. package/src/test-utils/factories/municipal/streets.ts +10 -5
  320. package/src/test-utils/factories/municipal/tickets.ts +12 -6
  321. package/src/test-utils/factories/talkpilot/agents.ts +8 -8
  322. package/src/test-utils/factories/talkpilot/calls.ts +5 -5
  323. package/src/test-utils/factories/talkpilot/clientAudioBuffers.ts +14 -12
  324. package/src/test-utils/factories/talkpilot/clientsConfig.ts +7 -8
  325. package/src/test-utils/factories/talkpilot/flows.ts +7 -5
  326. package/src/test-utils/factories/talkpilot/groups.ts +13 -13
  327. package/src/test-utils/factories/talkpilot/phone_numbers.ts +8 -6
  328. package/src/test-utils/factories/talkpilot/sessions.ts +5 -5
  329. package/src/utils/validation.ts +4 -4
@@ -1,39 +1,52 @@
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';
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";
13
20
  const flow = createFlow({
14
21
  conversationSettings: {
15
22
  interruptions: {
16
23
  enableInterruptionDetection: true,
17
24
  interruptionWindowSeconds: 60,
18
25
  interruptionThresholdSeconds: 10,
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.',
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.",
20
28
  },
21
29
  silence: {
22
30
  enableSilenceDetection: true,
23
31
  firstWarningSilenceSeconds: 5,
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.',
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.",
25
34
  secondWarningSilenceSeconds: 10,
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.',
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.",
27
37
  disconnectSilenceSeconds: 30,
28
38
  },
29
39
  },
30
40
  });
31
- const phoneNumberData = createPhoneNumber({ phone_number: to, flow_id: flow._id });
41
+ const phoneNumberData = createPhoneNumber({
42
+ phone_number: to,
43
+ flow_id: flow._id,
44
+ });
32
45
  const json = { [faker.lorem.word()]: faker.lorem.sentence() };
33
46
 
34
47
  const session = createSession({
35
48
  flow_id: flow._id,
36
- phone_numbers: [{ phoneNumber: from, gender: 'male', name: 'yakov' }],
49
+ phone_numbers: [{ phoneNumber: from, gender: "male", name: "yakov" }],
37
50
  json,
38
51
  });
39
52
 
@@ -47,15 +60,20 @@ describe('sessions', () => {
47
60
  expect(result?.flow_id).toEqual(flow._id);
48
61
  });
49
62
 
50
- it('works with different phone number formats (with/without plus)', async () => {
51
- const toInDB = '972500000000';
52
- const fromInDB = '+972540000000';
63
+ it("works with different phone number formats (with/without plus)", async () => {
64
+ const toInDB = "972500000000";
65
+ const fromInDB = "+972540000000";
53
66
  const flow = createFlow();
54
- const phoneNumberData = createPhoneNumber({ phone_number: toInDB, flow_id: flow._id });
67
+ const phoneNumberData = createPhoneNumber({
68
+ phone_number: toInDB,
69
+ flow_id: flow._id,
70
+ });
55
71
 
56
72
  const session = createSession({
57
73
  flow_id: flow._id,
58
- phone_numbers: [{ phoneNumber: fromInDB, gender: 'female', name: 'sara' }],
74
+ phone_numbers: [
75
+ { phoneNumber: fromInDB, gender: "female", name: "sara" },
76
+ ],
59
77
  });
60
78
 
61
79
  await getFlowsCollection().insertOne(flow);
@@ -63,25 +81,28 @@ describe('sessions', () => {
63
81
  await getSessionsCollection().insertOne(session);
64
82
 
65
83
  // Search with from WITH plus (matches + in DB), to WITH plus (matches without + in DB)
66
- const result = await findSessionOfIncomingCall('+972540000000', '+972500000000');
84
+ const result = await findSessionOfIncomingCall(
85
+ "+972540000000",
86
+ "+972500000000",
87
+ );
67
88
  expect(result).not.toBeNull();
68
89
  expect(result?.phone_numbers[0].phoneNumber).toEqual(fromInDB);
69
90
  });
70
91
 
71
- it('works when flow_id is string in phone_numbers and ObjectId in session', async () => {
72
- const to = '+972501111111';
73
- const from = '+972541111111';
92
+ it("works when flow_id is string in phone_numbers and ObjectId in session", async () => {
93
+ const to = "+972501111111";
94
+ const from = "+972541111111";
74
95
  const flowId = new ObjectId();
75
-
96
+
76
97
  // Store flow_id as string in phone_numbers
77
- const phoneNumberData = createPhoneNumber({
78
- phone_number: to,
79
- flow_id: flowId.toHexString() as any
98
+ const phoneNumberData = createPhoneNumber({
99
+ phone_number: to,
100
+ flow_id: flowId.toHexString() as any,
80
101
  });
81
102
 
82
103
  const session = createSession({
83
104
  flow_id: flowId, // stored as ObjectId
84
- phone_numbers: [{ phoneNumber: from, gender: 'male', name: 'isaac' }],
105
+ phone_numbers: [{ phoneNumber: from, gender: "male", name: "isaac" }],
85
106
  });
86
107
 
87
108
  await getPhoneNumbersCollection().insertOne(phoneNumberData);
@@ -92,19 +113,19 @@ describe('sessions', () => {
92
113
  expect(result?.flow_id?.toString()).toEqual(flowId.toHexString());
93
114
  });
94
115
 
95
- it('works when flow_id is string in session', async () => {
96
- const to = '+972502222222';
97
- const from = '+972542222222';
116
+ it("works when flow_id is string in session", async () => {
117
+ const to = "+972502222222";
118
+ const from = "+972542222222";
98
119
  const flowId = new ObjectId();
99
-
100
- const phoneNumberData = createPhoneNumber({
101
- phone_number: to,
102
- flow_id: flowId
120
+
121
+ const phoneNumberData = createPhoneNumber({
122
+ phone_number: to,
123
+ flow_id: flowId,
103
124
  });
104
125
 
105
126
  const session = createSession({
106
127
  flow_id: flowId.toHexString(), // stored as string
107
- phone_numbers: [{ phoneNumber: from, gender: 'female', name: 'rivka' }],
128
+ phone_numbers: [{ phoneNumber: from, gender: "female", name: "rivka" }],
108
129
  });
109
130
 
110
131
  await getPhoneNumbersCollection().insertOne(phoneNumberData);
@@ -115,8 +136,11 @@ describe('sessions', () => {
115
136
  expect(result?.flow_id).toEqual(flowId.toHexString());
116
137
  });
117
138
 
118
- it('returns null if receiver phone number is not found', async () => {
119
- const result = await findSessionOfIncomingCall('any-from', 'non-existent-to');
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
+ );
120
144
  expect(result).toBeNull();
121
145
  });
122
146
  });
@@ -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,20 +1,22 @@
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(new Set([raw, noPlus, digitsOnly, digitsOnlyNoPlus].filter(Boolean)));
17
+ return Array.from(
18
+ new Set([raw, noPlus, digitsOnly, digitsOnlyNoPlus].filter(Boolean)),
19
+ );
18
20
  };
19
21
 
20
22
  const buildFlowIdCandidates = (flowId: unknown): Array<string | ObjectId> => {
@@ -36,9 +38,12 @@ const buildFlowIdCandidates = (flowId: unknown): Array<string | ObjectId> => {
36
38
 
37
39
  export const findSessionById = (
38
40
  sessionId: ObjectId,
39
- clientId: string
41
+ clientId: string,
40
42
  ): Promise<WithId<Session> | null> => {
41
- return getSessionsCollection().findOne({ _id: sessionId, clientId: clientId });
43
+ return getSessionsCollection().findOne({
44
+ _id: sessionId,
45
+ clientId: clientId,
46
+ });
42
47
  };
43
48
 
44
49
  export const findSessionOfIncomingCall = async (from: string, to: string) => {
@@ -68,9 +73,9 @@ export const findSessionOfIncomingCall = async (from: string, to: string) => {
68
73
  $addFields: {
69
74
  phone_numbers: {
70
75
  $filter: {
71
- input: '$phone_numbers',
72
- as: 'pn',
73
- cond: { $in: ['$$pn.phoneNumber', fromCandidates] },
76
+ input: "$phone_numbers",
77
+ as: "pn",
78
+ cond: { $in: ["$$pn.phoneNumber", fromCandidates] },
74
79
  },
75
80
  },
76
81
  },
@@ -80,7 +85,7 @@ export const findSessionOfIncomingCall = async (from: string, to: string) => {
80
85
  .toArray();
81
86
 
82
87
  if (!session) {
83
- console.info('No session found for incoming call');
88
+ console.info("No session found for incoming call");
84
89
  return null;
85
90
  }
86
91
  return session;
@@ -1,34 +1,34 @@
1
1
  export const sessionMongoSchema = {
2
- bsonType: 'object',
3
- required: ['session_name'],
2
+ bsonType: "object",
3
+ required: ["session_name"],
4
4
  properties: {
5
- _id: { bsonType: 'objectId' },
6
- session_name: { bsonType: 'string' },
7
- company_name: { bsonType: ['string', 'null'] },
8
- flow_id: { bsonType: ['objectId', 'string', 'null'] },
5
+ _id: { bsonType: "objectId" },
6
+ session_name: { bsonType: "string" },
7
+ company_name: { bsonType: ["string", "null"] },
8
+ flow_id: { bsonType: ["objectId", "string", "null"] },
9
9
  metaKeys: {
10
- bsonType: ['array', 'null'],
10
+ bsonType: ["array", "null"],
11
11
  items: {
12
- bsonType: 'object',
13
- required: ['key'],
12
+ bsonType: "object",
13
+ required: ["key"],
14
14
  properties: {
15
- key: { bsonType: 'string' },
16
- value: { bsonType: 'string' },
15
+ key: { bsonType: "string" },
16
+ value: { bsonType: "string" },
17
17
  },
18
18
  },
19
19
  },
20
20
  phone_numbers: {
21
- bsonType: 'array',
21
+ bsonType: "array",
22
22
  items: {
23
- bsonType: 'object',
24
- required: ['name', 'phoneNumber'],
23
+ bsonType: "object",
24
+ required: ["name", "phoneNumber"],
25
25
  properties: {
26
- name: { bsonType: 'string' },
27
- phoneNumber: { bsonType: 'string' },
26
+ name: { bsonType: "string" },
27
+ phoneNumber: { bsonType: "string" },
28
28
  },
29
29
  },
30
30
  },
31
- voice: { bsonType: ['string', 'null'] },
31
+ voice: { bsonType: ["string", "null"] },
32
32
  },
33
33
  additionalProperties: false,
34
34
  } as const;
@@ -1,4 +1,4 @@
1
- import { ObjectId } from 'mongodb';
1
+ import { ObjectId } from "mongodb";
2
2
 
3
3
  export type Session = {
4
4
  _id?: ObjectId;
@@ -16,7 +16,7 @@ export type Session = {
16
16
  phone_numbers: Array<{
17
17
  name: string;
18
18
  phoneNumber: string;
19
- gender: 'male' | 'female';
19
+ gender: "male" | "female";
20
20
  }>;
21
21
 
22
22
  voice?: string | null;
@@ -1,37 +1,40 @@
1
- import { ObjectId } from 'mongodb';
2
- import { buildSimpleQuery, buildDateRangeFilter } from '../subscriptions.getters.utils';
3
- import { SimpleSubscriptionFilter } from '../subscriptions.types';
1
+ import { ObjectId } from "mongodb";
2
+ import {
3
+ buildSimpleQuery,
4
+ buildDateRangeFilter,
5
+ } from "../subscriptions.getters.utils";
6
+ import { SimpleSubscriptionFilter } from "../subscriptions.types";
4
7
 
5
- describe('subscriptions.getters.utils', () => {
6
- describe('buildSimpleQuery', () => {
7
- it('returns empty query when filter is empty', () => {
8
+ describe("subscriptions.getters.utils", () => {
9
+ describe("buildSimpleQuery", () => {
10
+ it("returns empty query when filter is empty", () => {
8
11
  const filter: SimpleSubscriptionFilter = {};
9
12
  const result = buildSimpleQuery(filter);
10
13
  expect(result).toEqual({});
11
14
  });
12
15
 
13
- it('converts _id string to ObjectId', () => {
14
- const id = '507f1f77bcf86cd799439011';
16
+ it("converts _id string to ObjectId", () => {
17
+ const id = "507f1f77bcf86cd799439011";
15
18
  const filter: SimpleSubscriptionFilter = { _id: id };
16
19
  const result = buildSimpleQuery(filter);
17
20
  expect(result._id).toBeInstanceOf(ObjectId);
18
21
  expect((result._id as ObjectId).toHexString()).toBe(id);
19
22
  });
20
23
 
21
- it('includes valid simple fields', () => {
24
+ it("includes valid simple fields", () => {
22
25
  const filter: SimpleSubscriptionFilter = {
23
- clientId: 'abc',
26
+ clientId: "abc",
24
27
  isActive: true,
25
28
  };
26
29
  const result = buildSimpleQuery(filter);
27
- expect(result).toEqual({ clientId: 'abc', isActive: true });
30
+ expect(result).toEqual({ clientId: "abc", isActive: true });
28
31
  });
29
32
  });
30
33
 
31
- describe('buildDateRangeFilter', () => {
32
- it('returns a mongo date range filter', () => {
33
- const from = new Date('2023-01-01');
34
- const to = new Date('2023-01-02');
34
+ describe("buildDateRangeFilter", () => {
35
+ it("returns a mongo date range filter", () => {
36
+ const from = new Date("2023-01-01");
37
+ const to = new Date("2023-01-02");
35
38
  const result = buildDateRangeFilter(from, to);
36
39
  expect(result).toEqual({
37
40
  $gte: from,
@@ -1,3 +1,3 @@
1
- export * from './subscriptions.types';
2
- export * from './subscriptions.getters';
3
- export * from './subscriptions.getters.utils';
1
+ export * from "./subscriptions.types";
2
+ export * from "./subscriptions.getters";
3
+ export * from "./subscriptions.getters.utils";
@@ -1,17 +1,17 @@
1
- import {getDb} from '../index';
1
+ import { getDb } from "../index";
2
2
  import {
3
3
  SimpleSubscriptionFilter,
4
4
  Subscription,
5
5
  SubscriptionDoc,
6
6
  SubscriptionFilter,
7
7
  SubscriptionQueryOptions,
8
- } from './subscriptions.types';
9
- import {Filter, ObjectId} from 'mongodb';
10
- import {buildSimpleQuery} from './subscriptions.getters.utils';
11
- import {applyQueryOptions} from '../utils/query.utils';
8
+ } from "./subscriptions.types";
9
+ import { Filter, ObjectId } from "mongodb";
10
+ import { buildSimpleQuery } from "./subscriptions.getters.utils";
11
+ import { applyQueryOptions } from "../utils/query.utils";
12
12
 
13
13
  export const getSubscriptionsCollection = () => {
14
- return getDb().collection<Subscription>('subscriptions');
14
+ return getDb().collection<Subscription>("subscriptions");
15
15
  };
16
16
 
17
17
  /**
@@ -20,7 +20,7 @@ export const getSubscriptionsCollection = () => {
20
20
 
21
21
  export const findSubscriptions = async (
22
22
  filter?: SubscriptionFilter,
23
- options?: SubscriptionQueryOptions
23
+ options?: SubscriptionQueryOptions,
24
24
  ): Promise<SubscriptionDoc[]> => {
25
25
  let query: Filter<Subscription> = {};
26
26
 
@@ -51,12 +51,14 @@ export const findSubscriptions = async (
51
51
  return await applyQueryOptions(cursor, options).toArray();
52
52
  };
53
53
 
54
- export const countSubscriptions = async (query: Filter<Subscription>): Promise<number> => {
54
+ export const countSubscriptions = async (
55
+ query: Filter<Subscription>,
56
+ ): Promise<number> => {
55
57
  return getSubscriptionsCollection().countDocuments(query);
56
58
  };
57
59
 
58
60
  export const createSubscriptionDoc = async (
59
- subscriptionData: Omit<Subscription, 'createdAt' | 'updatedAt'>
61
+ subscriptionData: Omit<Subscription, "createdAt" | "updatedAt">,
60
62
  ): Promise<SubscriptionDoc> => {
61
63
  const now = new Date();
62
64
  const result = await getSubscriptionsCollection().insertOne({
@@ -66,13 +68,14 @@ export const createSubscriptionDoc = async (
66
68
  });
67
69
 
68
70
  const subscriptions = await findSubscriptions({ _id: result.insertedId });
69
- if (!subscriptions[0]) throw new Error('Failed to retrieve created subscription');
71
+ if (!subscriptions[0])
72
+ throw new Error("Failed to retrieve created subscription");
70
73
  return subscriptions[0];
71
74
  };
72
75
 
73
76
  export const updateSubscriptionDoc = async (
74
77
  subscriptionId: ObjectId,
75
- updates: Partial<Subscription>
78
+ updates: Partial<Subscription>,
76
79
  ): Promise<SubscriptionDoc | null> => {
77
80
  return await getSubscriptionsCollection().findOneAndUpdate(
78
81
  { _id: subscriptionId },
@@ -83,61 +86,61 @@ export const updateSubscriptionDoc = async (
83
86
  },
84
87
  },
85
88
  {
86
- returnDocument: 'after',
87
- }
89
+ returnDocument: "after",
90
+ },
88
91
  );
89
92
  };
90
93
 
91
94
  export const incrementSubscriptionUsage = async (
92
95
  subscriptionId: ObjectId,
93
- amount: number = 1
96
+ amount: number = 1,
94
97
  ): Promise<SubscriptionDoc | null> => {
95
- const fieldToIncrement = 'cycles.$[activeCycle].usage.usedCalls';
98
+ const fieldToIncrement = "cycles.$[activeCycle].usage.usedCalls";
96
99
  return await getSubscriptionsCollection().findOneAndUpdate(
97
- { _id: subscriptionId, 'cycles.isActive': true },
100
+ { _id: subscriptionId, "cycles.isActive": true },
98
101
  {
99
102
  $inc: { [fieldToIncrement]: amount },
100
103
  $set: { updatedAt: new Date() },
101
104
  },
102
105
  {
103
- arrayFilters: [{ 'activeCycle.isActive': true }],
104
- returnDocument: 'after',
105
- }
106
+ arrayFilters: [{ "activeCycle.isActive": true }],
107
+ returnDocument: "after",
108
+ },
106
109
  );
107
110
  };
108
111
 
109
112
  export const deactivateCurrentSubscriptionCycle = async (
110
113
  subscriptionId: ObjectId,
111
- nextRenewalDate: Date
114
+ nextRenewalDate: Date,
112
115
  ): Promise<void> => {
113
116
  await getSubscriptionsCollection().updateOne(
114
- { _id: subscriptionId, 'cycles.isActive': true },
117
+ { _id: subscriptionId, "cycles.isActive": true },
115
118
  {
116
119
  $set: {
117
- 'cycles.$[activeCycle].isActive': false,
120
+ "cycles.$[activeCycle].isActive": false,
118
121
  nextRenewalDate: nextRenewalDate,
119
122
  updatedAt: new Date(),
120
123
  },
121
124
  },
122
125
  {
123
- arrayFilters: [{ 'activeCycle.isActive': true }],
124
- }
126
+ arrayFilters: [{ "activeCycle.isActive": true }],
127
+ },
125
128
  );
126
129
  };
127
130
 
128
131
  export const pushNewSubscriptionCycle = async (
129
132
  subscriptionId: ObjectId,
130
- newCycle: Subscription['cycles'][number]
133
+ newCycle: Subscription["cycles"][number],
131
134
  ): Promise<SubscriptionDoc | null> => {
132
135
  return await getSubscriptionsCollection().findOneAndUpdate(
133
- {_id: subscriptionId},
134
- {
135
- $push: {
136
- cycles: newCycle,
137
- },
136
+ { _id: subscriptionId },
137
+ {
138
+ $push: {
139
+ cycles: newCycle,
138
140
  },
139
- {
140
- returnDocument: 'after',
141
- }
141
+ },
142
+ {
143
+ returnDocument: "after",
144
+ },
142
145
  );
143
146
  };
@@ -1,7 +1,14 @@
1
- import { ObjectId, Filter } from 'mongodb';
2
- import { Subscription, SimpleSubscriptionFilter, simpleFields, SimpleField } from '../index';
1
+ import { ObjectId, Filter } from "mongodb";
2
+ import {
3
+ Subscription,
4
+ SimpleSubscriptionFilter,
5
+ simpleFields,
6
+ SimpleField,
7
+ } from "../index";
3
8
 
4
- export const buildSimpleQuery = (filter: SimpleSubscriptionFilter): Filter<Subscription> => {
9
+ export const buildSimpleQuery = (
10
+ filter: SimpleSubscriptionFilter,
11
+ ): Filter<Subscription> => {
5
12
  const query: Filter<Subscription> = {};
6
13
 
7
14
  if (filter._id) {
@@ -1,5 +1,5 @@
1
- import { Filter, ObjectId, WithId, Sort } from 'mongodb';
2
- import { PlanDoc } from '../plans/plans.types';
1
+ import { Filter, ObjectId, WithId, Sort } from "mongodb";
2
+ import { PlanDoc } from "../plans";
3
3
 
4
4
  export type SubscriptionCycle = {
5
5
  usage: {
@@ -29,13 +29,13 @@ export type Subscriptions = SubscriptionDoc[];
29
29
 
30
30
  // Define which Subscription fields we allow in a simple filter
31
31
  export const simpleFields = [
32
- 'clientId',
33
- 'planId',
34
- 'startDate',
35
- 'endDate',
36
- 'isActive',
37
- 'createdAt',
38
- 'nextRenewalDate',
32
+ "clientId",
33
+ "planId",
34
+ "startDate",
35
+ "endDate",
36
+ "isActive",
37
+ "createdAt",
38
+ "nextRenewalDate",
39
39
  ] as const;
40
40
  export type SimpleField = (typeof simpleFields)[number];
41
41
 
@@ -1,7 +1,7 @@
1
- import { applyQueryOptions } from '../query.utils';
1
+ import { applyQueryOptions } from "../query.utils";
2
2
 
3
- describe('query.utils', () => {
4
- describe('applyQueryOptions()', () => {
3
+ describe("query.utils", () => {
4
+ describe("applyQueryOptions()", () => {
5
5
  let mockCursor: any;
6
6
 
7
7
  beforeEach(() => {
@@ -12,13 +12,13 @@ describe('query.utils', () => {
12
12
  };
13
13
  });
14
14
 
15
- it('should return cursor if no options provided', () => {
15
+ it("should return cursor if no options provided", () => {
16
16
  const result = applyQueryOptions(mockCursor);
17
17
  expect(result).toBe(mockCursor);
18
18
  expect(mockCursor.sort).not.toHaveBeenCalled();
19
19
  });
20
20
 
21
- it('should apply sort, skip, and limit', () => {
21
+ it("should apply sort, skip, and limit", () => {
22
22
  const options = {
23
23
  sort: { name: 1 },
24
24
  skip: 10,
@@ -26,20 +26,20 @@ describe('query.utils', () => {
26
26
  };
27
27
 
28
28
  const result = applyQueryOptions(mockCursor, options);
29
-
29
+
30
30
  expect(result).toBe(mockCursor);
31
31
  expect(mockCursor.sort).toHaveBeenCalledWith({ name: 1 });
32
32
  expect(mockCursor.skip).toHaveBeenCalledWith(10);
33
33
  expect(mockCursor.limit).toHaveBeenCalledWith(5);
34
34
  });
35
35
 
36
- it('should apply only sort if skip and limit are missing', () => {
36
+ it("should apply only sort if skip and limit are missing", () => {
37
37
  const options = {
38
38
  sort: { name: 1 },
39
39
  };
40
40
 
41
41
  const result = applyQueryOptions(mockCursor, options);
42
-
42
+
43
43
  expect(result).toBe(mockCursor);
44
44
  expect(mockCursor.sort).toHaveBeenCalledWith({ name: 1 });
45
45
  expect(mockCursor.skip).not.toHaveBeenCalled();
@@ -1,4 +1,4 @@
1
- import { FindCursor } from 'mongodb';
1
+ import { FindCursor } from "mongodb";
2
2
 
3
3
  export type QueryOptions = {
4
4
  sort?: any;
@@ -8,7 +8,7 @@ export type QueryOptions = {
8
8
 
9
9
  export const applyQueryOptions = <T>(
10
10
  cursor: FindCursor<T>,
11
- options?: QueryOptions
11
+ options?: QueryOptions,
12
12
  ): FindCursor<T> => {
13
13
  if (!options) return cursor;
14
14