@talkpilot/core-db 1.1.8 → 1.1.10
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +7 -0
- package/dist/connection.d.ts +1 -1
- package/dist/connection.d.ts.map +1 -1
- package/dist/connection.js +21 -24
- package/dist/connection.js.map +1 -1
- package/dist/index.d.ts +9 -9
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js.map +1 -1
- package/dist/municipal/cities/cities.getters.d.ts +2 -2
- package/dist/municipal/cities/cities.getters.d.ts.map +1 -1
- package/dist/municipal/cities/cities.getters.js +8 -4
- package/dist/municipal/cities/cities.getters.js.map +1 -1
- package/dist/municipal/cities/cities.types.d.ts +1 -1
- package/dist/municipal/cities/index.d.ts +2 -2
- package/dist/municipal/departmentsSubjects/departmentsSubjects.getters.d.ts +3 -3
- package/dist/municipal/departmentsSubjects/departmentsSubjects.getters.d.ts.map +1 -1
- package/dist/municipal/departmentsSubjects/departmentsSubjects.getters.js +30 -22
- package/dist/municipal/departmentsSubjects/departmentsSubjects.getters.js.map +1 -1
- package/dist/municipal/departmentsSubjects/departmentsSubjects.types.d.ts +4 -4
- package/dist/municipal/departmentsSubjects/departmentsSubjects.types.d.ts.map +1 -1
- package/dist/municipal/departmentsSubjects/index.d.ts +2 -2
- package/dist/municipal/index.d.ts +8 -8
- package/dist/municipal/index.d.ts.map +1 -1
- package/dist/municipal/index.js +1 -1
- package/dist/municipal/mongodb-client.d.ts +1 -1
- package/dist/municipal/mongodb-client.d.ts.map +1 -1
- package/dist/municipal/mongodb-client.js +7 -7
- package/dist/municipal/mongodb-client.js.map +1 -1
- package/dist/municipal/streets/index.d.ts +2 -2
- package/dist/municipal/streets/streets.getters.d.ts +3 -3
- package/dist/municipal/streets/streets.getters.d.ts.map +1 -1
- package/dist/municipal/streets/streets.getters.js +19 -9
- package/dist/municipal/streets/streets.getters.js.map +1 -1
- package/dist/municipal/streets/streets.types.d.ts +1 -1
- package/dist/municipal/systemInstructions/index.d.ts +3 -3
- package/dist/municipal/systemInstructions/index.d.ts.map +1 -1
- package/dist/municipal/systemInstructions/instructions.getters.d.ts +3 -3
- package/dist/municipal/systemInstructions/instructions.getters.d.ts.map +1 -1
- package/dist/municipal/systemInstructions/instructions.getters.js +10 -4
- package/dist/municipal/systemInstructions/instructions.getters.js.map +1 -1
- package/dist/municipal/systemInstructions/instructions.setters.d.ts +2 -2
- package/dist/municipal/systemInstructions/instructions.setters.d.ts.map +1 -1
- package/dist/municipal/systemInstructions/instructions.setters.js +13 -8
- package/dist/municipal/systemInstructions/instructions.setters.js.map +1 -1
- package/dist/municipal/systemInstructions/instructions.types.d.ts +3 -3
- package/dist/municipal/systemInstructions/instructions.types.d.ts.map +1 -1
- package/dist/municipal/systemInstructions/instructions.types.js +6 -6
- package/dist/municipal/tickets/index.d.ts +2 -2
- package/dist/municipal/tickets/tickets.getters.d.ts +3 -3
- package/dist/municipal/tickets/tickets.getters.d.ts.map +1 -1
- package/dist/municipal/tickets/tickets.getters.js +50 -29
- package/dist/municipal/tickets/tickets.getters.js.map +1 -1
- package/dist/municipal/tickets/tickets.types.d.ts +1 -1
- package/dist/municipal/tickets/tickets.types.d.ts.map +1 -1
- package/dist/municipal/utils/types.d.ts +1 -1
- package/dist/municipal/utils/types.d.ts.map +1 -1
- package/dist/talkpilot/agents/agents.getters.d.ts +1 -1
- package/dist/talkpilot/agents/agents.getters.js +2 -2
- package/dist/talkpilot/agents/agents.types.d.ts +2 -2
- package/dist/talkpilot/agents/index.d.ts +2 -2
- package/dist/talkpilot/backgroundToolResults/backgroundToolResults.getters.d.ts +2 -2
- package/dist/talkpilot/backgroundToolResults/backgroundToolResults.getters.d.ts.map +1 -1
- package/dist/talkpilot/backgroundToolResults/backgroundToolResults.getters.js +1 -1
- package/dist/talkpilot/backgroundToolResults/backgroundToolResults.getters.js.map +1 -1
- package/dist/talkpilot/backgroundToolResults/backgroundToolResults.types.d.ts +2 -2
- package/dist/talkpilot/backgroundToolResults/index.d.ts +2 -2
- package/dist/talkpilot/calls/calls.getters.d.ts +4 -3
- package/dist/talkpilot/calls/calls.getters.d.ts.map +1 -1
- package/dist/talkpilot/calls/calls.getters.js +24 -16
- package/dist/talkpilot/calls/calls.getters.js.map +1 -1
- package/dist/talkpilot/calls/calls.types.d.ts +26 -3
- package/dist/talkpilot/calls/calls.types.d.ts.map +1 -1
- package/dist/talkpilot/calls/calls.types.js +2 -2
- package/dist/talkpilot/calls/index.d.ts +2 -2
- package/dist/talkpilot/clientAudioBuffers/clientAudioBuffer.getters.d.ts +2 -2
- package/dist/talkpilot/clientAudioBuffers/clientAudioBuffer.getters.d.ts.map +1 -1
- package/dist/talkpilot/clientAudioBuffers/clientAudioBuffer.getters.js +2 -2
- package/dist/talkpilot/clientAudioBuffers/clientAudioBuffer.getters.js.map +1 -1
- package/dist/talkpilot/clientAudioBuffers/clientsAudioBuffers.types.d.ts +2 -2
- package/dist/talkpilot/clientAudioBuffers/index.d.ts +2 -2
- package/dist/talkpilot/clients/clients.getters.d.ts +2 -2
- package/dist/talkpilot/clients/clients.getters.d.ts.map +1 -1
- package/dist/talkpilot/clients/clients.getters.js +5 -2
- package/dist/talkpilot/clients/clients.getters.js.map +1 -1
- package/dist/talkpilot/clients/clients.types.d.ts +1 -1
- package/dist/talkpilot/clients/index.d.ts +2 -2
- package/dist/talkpilot/clientsConfig/clientsConfig.getters.d.ts +2 -2
- package/dist/talkpilot/clientsConfig/clientsConfig.getters.d.ts.map +1 -1
- package/dist/talkpilot/clientsConfig/clientsConfig.getters.js +1 -1
- package/dist/talkpilot/clientsConfig/clientsConfig.getters.js.map +1 -1
- package/dist/talkpilot/clientsConfig/clientsConfig.types.d.ts +3 -3
- package/dist/talkpilot/clientsConfig/clientsConfig.types.d.ts.map +1 -1
- package/dist/talkpilot/clientsConfig/index.d.ts +2 -2
- package/dist/talkpilot/flows/flows.getter.d.ts +2 -2
- package/dist/talkpilot/flows/flows.getter.d.ts.map +1 -1
- package/dist/talkpilot/flows/flows.getter.js +1 -1
- package/dist/talkpilot/flows/flows.getter.js.map +1 -1
- package/dist/talkpilot/flows/flows.schema.d.ts +0 -3
- package/dist/talkpilot/flows/flows.schema.d.ts.map +1 -1
- package/dist/talkpilot/flows/flows.schema.js +87 -80
- package/dist/talkpilot/flows/flows.schema.js.map +1 -1
- package/dist/talkpilot/flows/flows.types.d.ts +16 -17
- package/dist/talkpilot/flows/flows.types.d.ts.map +1 -1
- package/dist/talkpilot/flows/index.d.ts +2 -2
- package/dist/talkpilot/groups/groups.getters.d.ts +2 -2
- package/dist/talkpilot/groups/groups.getters.d.ts.map +1 -1
- package/dist/talkpilot/groups/groups.getters.js +2 -2
- package/dist/talkpilot/groups/groups.getters.js.map +1 -1
- package/dist/talkpilot/groups/groups.types.d.ts +1 -1
- package/dist/talkpilot/groups/index.d.ts +3 -3
- package/dist/talkpilot/groups/phone.utils.d.ts +1 -1
- package/dist/talkpilot/groups/phone.utils.d.ts.map +1 -1
- package/dist/talkpilot/groups/phone.utils.js +2 -2
- package/dist/talkpilot/groups/phone.utils.js.map +1 -1
- package/dist/talkpilot/index.d.ts +16 -16
- package/dist/talkpilot/index.js +1 -1
- package/dist/talkpilot/leads/index.d.ts +2 -2
- package/dist/talkpilot/leads/leads.getter.d.ts +2 -2
- package/dist/talkpilot/leads/leads.getter.d.ts.map +1 -1
- package/dist/talkpilot/leads/leads.getter.js +1 -1
- package/dist/talkpilot/leads/leads.getter.js.map +1 -1
- package/dist/talkpilot/leads/leads.schema.js +16 -16
- package/dist/talkpilot/leads/leads.types.d.ts +1 -1
- package/dist/talkpilot/mongodb-client.d.ts +1 -1
- package/dist/talkpilot/mongodb-client.js +8 -9
- package/dist/talkpilot/mongodb-client.js.map +1 -1
- package/dist/talkpilot/phone_numbers/index.d.ts +1 -1
- package/dist/talkpilot/phone_numbers/index.d.ts.map +1 -1
- package/dist/talkpilot/phone_numbers/phone_numbers.getter.d.ts +5 -2
- package/dist/talkpilot/phone_numbers/phone_numbers.getter.d.ts.map +1 -1
- package/dist/talkpilot/phone_numbers/phone_numbers.getter.js +66 -12
- package/dist/talkpilot/phone_numbers/phone_numbers.getter.js.map +1 -1
- package/dist/talkpilot/phone_numbers/phone_numbers.schema.d.ts +11 -2
- package/dist/talkpilot/phone_numbers/phone_numbers.schema.d.ts.map +1 -1
- package/dist/talkpilot/phone_numbers/phone_numbers.schema.js +5 -2
- package/dist/talkpilot/phone_numbers/phone_numbers.schema.js.map +1 -1
- package/dist/talkpilot/phone_numbers/phone_numbers.types.d.ts +16 -3
- package/dist/talkpilot/phone_numbers/phone_numbers.types.d.ts.map +1 -1
- package/dist/talkpilot/plans/index.d.ts +2 -2
- package/dist/talkpilot/plans/plans.getters.d.ts +2 -2
- package/dist/talkpilot/plans/plans.getters.d.ts.map +1 -1
- package/dist/talkpilot/plans/plans.getters.js +3 -3
- package/dist/talkpilot/plans/plans.getters.js.map +1 -1
- package/dist/talkpilot/plans/plans.types.d.ts +4 -4
- package/dist/talkpilot/plans/plans.types.d.ts.map +1 -1
- package/dist/talkpilot/plans/plans.types.js +19 -19
- package/dist/talkpilot/results/index.d.ts +2 -2
- package/dist/talkpilot/results/index.d.ts.map +1 -1
- package/dist/talkpilot/results/index.js.map +1 -1
- package/dist/talkpilot/results/results.getter.d.ts +3 -3
- package/dist/talkpilot/results/results.getter.d.ts.map +1 -1
- package/dist/talkpilot/results/results.getter.js +4 -4
- package/dist/talkpilot/results/results.getter.js.map +1 -1
- package/dist/talkpilot/results/results.schema.js +18 -18
- package/dist/talkpilot/results/results.types.d.ts +1 -1
- package/dist/talkpilot/sessions/index.d.ts +2 -2
- package/dist/talkpilot/sessions/sessions.getter.d.ts +3 -3
- package/dist/talkpilot/sessions/sessions.getter.d.ts.map +1 -1
- package/dist/talkpilot/sessions/sessions.getter.js +13 -10
- package/dist/talkpilot/sessions/sessions.getter.js.map +1 -1
- package/dist/talkpilot/sessions/sessions.schema.js +17 -17
- package/dist/talkpilot/sessions/sessions.types.d.ts +2 -2
- package/dist/talkpilot/subscriptions/index.d.ts +3 -3
- package/dist/talkpilot/subscriptions/subscriptions.getters.d.ts +2 -2
- package/dist/talkpilot/subscriptions/subscriptions.getters.d.ts.map +1 -1
- package/dist/talkpilot/subscriptions/subscriptions.getters.js +11 -11
- package/dist/talkpilot/subscriptions/subscriptions.getters.js.map +1 -1
- package/dist/talkpilot/subscriptions/subscriptions.getters.utils.d.ts +2 -2
- package/dist/talkpilot/subscriptions/subscriptions.getters.utils.d.ts.map +1 -1
- package/dist/talkpilot/subscriptions/subscriptions.getters.utils.js.map +1 -1
- package/dist/talkpilot/subscriptions/subscriptions.types.d.ts +2 -2
- package/dist/talkpilot/subscriptions/subscriptions.types.d.ts.map +1 -1
- package/dist/talkpilot/subscriptions/subscriptions.types.js +7 -7
- package/dist/talkpilot/utils/query.utils.d.ts +1 -1
- package/dist/test-utils/db-utils.d.ts +1 -1
- package/dist/test-utils/db-utils.js +2 -2
- package/dist/test-utils/factories/index.d.ts +12 -12
- package/dist/test-utils/factories/municipal/cities.d.ts +2 -2
- package/dist/test-utils/factories/municipal/cities.d.ts.map +1 -1
- package/dist/test-utils/factories/municipal/cities.js +1 -1
- package/dist/test-utils/factories/municipal/departmentsSubjects.d.ts +2 -2
- package/dist/test-utils/factories/municipal/departmentsSubjects.d.ts.map +1 -1
- package/dist/test-utils/factories/municipal/departmentsSubjects.js +7 -1
- package/dist/test-utils/factories/municipal/departmentsSubjects.js.map +1 -1
- package/dist/test-utils/factories/municipal/streets.d.ts +2 -2
- package/dist/test-utils/factories/municipal/streets.d.ts.map +1 -1
- package/dist/test-utils/factories/municipal/streets.js +6 -1
- package/dist/test-utils/factories/municipal/streets.js.map +1 -1
- package/dist/test-utils/factories/municipal/tickets.d.ts +2 -2
- package/dist/test-utils/factories/municipal/tickets.d.ts.map +1 -1
- package/dist/test-utils/factories/municipal/tickets.js +7 -1
- package/dist/test-utils/factories/municipal/tickets.js.map +1 -1
- package/dist/test-utils/factories/talkpilot/agents.d.ts +2 -2
- package/dist/test-utils/factories/talkpilot/agents.d.ts.map +1 -1
- package/dist/test-utils/factories/talkpilot/agents.js +4 -4
- package/dist/test-utils/factories/talkpilot/calls.d.ts +2 -2
- package/dist/test-utils/factories/talkpilot/calls.d.ts.map +1 -1
- package/dist/test-utils/factories/talkpilot/calls.js +1 -1
- package/dist/test-utils/factories/talkpilot/clientAudioBuffers.d.ts +2 -2
- package/dist/test-utils/factories/talkpilot/clientAudioBuffers.d.ts.map +1 -1
- package/dist/test-utils/factories/talkpilot/clientAudioBuffers.js +1 -1
- package/dist/test-utils/factories/talkpilot/clientAudioBuffers.js.map +1 -1
- package/dist/test-utils/factories/talkpilot/clientsConfig.d.ts +2 -2
- package/dist/test-utils/factories/talkpilot/clientsConfig.d.ts.map +1 -1
- package/dist/test-utils/factories/talkpilot/clientsConfig.js.map +1 -1
- package/dist/test-utils/factories/talkpilot/flows.d.ts +3 -3
- package/dist/test-utils/factories/talkpilot/flows.d.ts.map +1 -1
- package/dist/test-utils/factories/talkpilot/flows.js.map +1 -1
- package/dist/test-utils/factories/talkpilot/groups.d.ts +2 -2
- package/dist/test-utils/factories/talkpilot/groups.d.ts.map +1 -1
- package/dist/test-utils/factories/talkpilot/groups.js +9 -9
- package/dist/test-utils/factories/talkpilot/groups.js.map +1 -1
- package/dist/test-utils/factories/talkpilot/phone_numbers.d.ts +3 -3
- package/dist/test-utils/factories/talkpilot/phone_numbers.d.ts.map +1 -1
- package/dist/test-utils/factories/talkpilot/phone_numbers.js.map +1 -1
- package/dist/test-utils/factories/talkpilot/sessions.d.ts +2 -2
- package/dist/test-utils/factories/talkpilot/sessions.d.ts.map +1 -1
- package/dist/test-utils/factories/talkpilot/sessions.js +1 -1
- package/dist/utils/validation.js +2 -2
- package/dist/utils/validation.js.map +1 -1
- package/package.json +3 -1
- package/src/__tests__/setup.ts +3 -3
- package/src/connection.ts +27 -25
- package/src/index.ts +9 -9
- package/src/municipal/__tests__/validation.spec.ts +35 -23
- package/src/municipal/cities/cities.getters.ts +16 -10
- package/src/municipal/cities/cities.types.ts +1 -1
- package/src/municipal/cities/index.ts +2 -2
- package/src/municipal/departmentsSubjects/departmentsSubjects.getters.ts +53 -44
- package/src/municipal/departmentsSubjects/departmentsSubjects.types.ts +5 -5
- package/src/municipal/departmentsSubjects/index.ts +2 -3
- package/src/municipal/index.ts +10 -10
- package/src/municipal/mongodb-client.ts +13 -10
- package/src/municipal/streets/index.ts +2 -2
- package/src/municipal/streets/streets.getters.ts +43 -23
- package/src/municipal/streets/streets.types.ts +1 -1
- package/src/municipal/systemInstructions/__tests__/getters.spec.ts +67 -52
- package/src/municipal/systemInstructions/__tests__/setters.spec.ts +271 -238
- package/src/municipal/systemInstructions/index.ts +7 -3
- package/src/municipal/systemInstructions/instructions.getters.ts +30 -18
- package/src/municipal/systemInstructions/instructions.setters.ts +43 -19
- package/src/municipal/systemInstructions/instructions.types.ts +10 -10
- package/src/municipal/tickets/__tests__/tickets.getters.spec.ts +12 -12
- package/src/municipal/tickets/index.ts +2 -2
- package/src/municipal/tickets/tickets.getters.ts +69 -42
- package/src/municipal/tickets/tickets.types.ts +2 -2
- package/src/municipal/utils/types.ts +8 -3
- package/src/talkpilot/__tests__/db.spec.ts +12 -12
- package/src/talkpilot/__tests__/mongodb-client.spec.ts +7 -8
- package/src/talkpilot/__tests__/validation.spec.ts +30 -24
- package/src/talkpilot/agents/__tests__/agents.getters.spec.ts +10 -10
- package/src/talkpilot/agents/agents.getters.ts +3 -3
- package/src/talkpilot/agents/agents.types.ts +2 -2
- package/src/talkpilot/agents/index.ts +2 -2
- package/src/talkpilot/backgroundToolResults/__tests__/backgroundToolResults.getters.spec.ts +42 -31
- package/src/talkpilot/backgroundToolResults/backgroundToolResults.getters.ts +11 -11
- package/src/talkpilot/backgroundToolResults/backgroundToolResults.types.ts +2 -3
- package/src/talkpilot/backgroundToolResults/index.ts +2 -2
- package/src/talkpilot/calls/__tests__/callStats.utils.spec.ts +27 -27
- package/src/talkpilot/calls/__tests__/calls.spec.ts +178 -40
- package/src/talkpilot/calls/calls.getters.ts +57 -27
- package/src/talkpilot/calls/calls.types.ts +39 -16
- package/src/talkpilot/calls/index.ts +2 -2
- package/src/talkpilot/clientAudioBuffers/__tests__/clientAudioBuffer.getters.spec.ts +73 -39
- package/src/talkpilot/clientAudioBuffers/clientAudioBuffer.getters.ts +18 -11
- package/src/talkpilot/clientAudioBuffers/clientsAudioBuffers.types.ts +2 -2
- package/src/talkpilot/clientAudioBuffers/index.ts +2 -2
- package/src/talkpilot/clients/clients.getters.ts +10 -5
- package/src/talkpilot/clients/clients.types.ts +1 -1
- package/src/talkpilot/clients/index.ts +2 -2
- package/src/talkpilot/clientsConfig/__tests__/clientsConfig.spec.ts +21 -18
- package/src/talkpilot/clientsConfig/clientsConfig.getters.ts +6 -4
- package/src/talkpilot/clientsConfig/clientsConfig.types.ts +10 -8
- package/src/talkpilot/clientsConfig/index.ts +2 -2
- package/src/talkpilot/flows/__tests__/flows.schema.spec.ts +38 -37
- package/src/talkpilot/flows/flows.getter.ts +8 -5
- package/src/talkpilot/flows/flows.schema.ts +87 -80
- package/src/talkpilot/flows/flows.types.ts +23 -24
- package/src/talkpilot/flows/index.ts +2 -2
- package/src/talkpilot/groups/__tests__/groups.spec.ts +34 -27
- package/src/talkpilot/groups/__tests__/phone.utils.spec.ts +20 -20
- package/src/talkpilot/groups/groups.getters.ts +8 -5
- package/src/talkpilot/groups/groups.types.ts +1 -1
- package/src/talkpilot/groups/index.ts +3 -3
- package/src/talkpilot/groups/phone.utils.ts +12 -6
- package/src/talkpilot/index.ts +17 -17
- package/src/talkpilot/leads/index.ts +2 -2
- package/src/talkpilot/leads/leads.getter.ts +5 -4
- package/src/talkpilot/leads/leads.schema.ts +16 -16
- package/src/talkpilot/leads/leads.types.ts +1 -1
- package/src/talkpilot/mongodb-client.ts +12 -12
- package/src/talkpilot/phone_numbers/__tests__/phone_numbers.spec.ts +162 -33
- package/src/talkpilot/phone_numbers/index.ts +1 -1
- package/src/talkpilot/phone_numbers/phone_numbers.getter.ts +94 -18
- package/src/talkpilot/phone_numbers/phone_numbers.schema.ts +5 -2
- package/src/talkpilot/phone_numbers/phone_numbers.types.ts +18 -3
- package/src/talkpilot/plans/__tests__/plans.spec.ts +30 -26
- package/src/talkpilot/plans/index.ts +2 -2
- package/src/talkpilot/plans/plans.getters.ts +25 -18
- package/src/talkpilot/plans/plans.types.ts +27 -23
- package/src/talkpilot/results/index.ts +5 -2
- package/src/talkpilot/results/results.getter.ts +9 -8
- package/src/talkpilot/results/results.schema.ts +18 -18
- package/src/talkpilot/results/results.types.ts +1 -1
- package/src/talkpilot/sessions/__tests__/sessions.spec.ts +65 -41
- package/src/talkpilot/sessions/index.ts +2 -2
- package/src/talkpilot/sessions/sessions.getter.ts +21 -16
- package/src/talkpilot/sessions/sessions.schema.ts +17 -17
- package/src/talkpilot/sessions/sessions.types.ts +2 -2
- package/src/talkpilot/subscriptions/__tests__/subscriptions.getters.utils.spec.ts +18 -15
- package/src/talkpilot/subscriptions/index.ts +3 -3
- package/src/talkpilot/subscriptions/subscriptions.getters.ts +36 -33
- package/src/talkpilot/subscriptions/subscriptions.getters.utils.ts +10 -3
- package/src/talkpilot/subscriptions/subscriptions.types.ts +9 -9
- package/src/talkpilot/utils/__tests__/query.utils.spec.ts +8 -8
- package/src/talkpilot/utils/query.utils.ts +2 -2
- package/src/test-utils/db-utils.ts +5 -5
- package/src/test-utils/factories/index.ts +12 -12
- package/src/test-utils/factories/municipal/cities.ts +5 -5
- package/src/test-utils/factories/municipal/departmentsSubjects.ts +32 -25
- package/src/test-utils/factories/municipal/streets.ts +10 -5
- package/src/test-utils/factories/municipal/tickets.ts +12 -6
- package/src/test-utils/factories/talkpilot/agents.ts +8 -8
- package/src/test-utils/factories/talkpilot/calls.ts +5 -5
- package/src/test-utils/factories/talkpilot/clientAudioBuffers.ts +14 -12
- package/src/test-utils/factories/talkpilot/clientsConfig.ts +7 -8
- package/src/test-utils/factories/talkpilot/flows.ts +7 -5
- package/src/test-utils/factories/talkpilot/groups.ts +13 -13
- package/src/test-utils/factories/talkpilot/phone_numbers.ts +8 -6
- package/src/test-utils/factories/talkpilot/sessions.ts +5 -5
- package/src/utils/validation.ts +4 -4
|
@@ -5,61 +5,65 @@ import {
|
|
|
5
5
|
countPlans,
|
|
6
6
|
updatePlanDoc,
|
|
7
7
|
getPlansCollection,
|
|
8
|
-
} from
|
|
9
|
-
import {
|
|
10
|
-
import { Plan } from '../plans.types';
|
|
8
|
+
} from "../plans.getters";
|
|
9
|
+
import { Plan } from "../plans.types";
|
|
11
10
|
|
|
12
|
-
describe(
|
|
13
|
-
const createTestPlan = (
|
|
14
|
-
|
|
15
|
-
|
|
11
|
+
describe("db.plans", () => {
|
|
12
|
+
const createTestPlan = (
|
|
13
|
+
overrides?: Partial<Plan>,
|
|
14
|
+
): Omit<Plan, "createdAt" | "updatedAt"> => ({
|
|
15
|
+
productKey: "basic-500",
|
|
16
|
+
name: "Basic 500",
|
|
16
17
|
monthlyCallQuota: 500,
|
|
17
|
-
currency:
|
|
18
|
+
currency: "ILS",
|
|
18
19
|
priceMonthlyMinor: 10000,
|
|
19
20
|
isActive: true,
|
|
20
21
|
...overrides,
|
|
21
22
|
});
|
|
22
23
|
|
|
23
|
-
it(
|
|
24
|
-
const planData = createTestPlan({ name:
|
|
24
|
+
it("should create and find a plan", async () => {
|
|
25
|
+
const planData = createTestPlan({ name: "CreateTest" });
|
|
25
26
|
const created = await createPlanDoc(planData);
|
|
26
|
-
|
|
27
|
+
|
|
27
28
|
expect(created._id).toBeDefined();
|
|
28
|
-
expect(created.name).toBe(
|
|
29
|
+
expect(created.name).toBe("CreateTest");
|
|
29
30
|
|
|
30
31
|
const found = await findPlans({ _id: created._id });
|
|
31
32
|
expect(found.length).toBe(1);
|
|
32
|
-
expect(found[0].name).toBe(
|
|
33
|
+
expect(found[0].name).toBe("CreateTest");
|
|
33
34
|
});
|
|
34
35
|
|
|
35
|
-
it(
|
|
36
|
+
it("should find plans by query with limit", async () => {
|
|
36
37
|
await getPlansCollection().deleteMany({});
|
|
37
|
-
await createPlanDoc(createTestPlan({ productKey:
|
|
38
|
-
await createPlanDoc(createTestPlan({ productKey:
|
|
39
|
-
await createPlanDoc(createTestPlan({ productKey:
|
|
38
|
+
await createPlanDoc(createTestPlan({ productKey: "p1", isActive: true }));
|
|
39
|
+
await createPlanDoc(createTestPlan({ productKey: "p2", isActive: true }));
|
|
40
|
+
await createPlanDoc(createTestPlan({ productKey: "p3", isActive: false }));
|
|
40
41
|
|
|
41
|
-
const activePlans = await findPlansByQuery(
|
|
42
|
+
const activePlans = await findPlansByQuery(
|
|
43
|
+
{ isActive: true },
|
|
44
|
+
{ limit: 1 },
|
|
45
|
+
);
|
|
42
46
|
expect(activePlans.length).toBe(1);
|
|
43
47
|
expect(activePlans[0].isActive).toBe(true);
|
|
44
48
|
});
|
|
45
49
|
|
|
46
|
-
it(
|
|
50
|
+
it("should count plans matching query", async () => {
|
|
47
51
|
await getPlansCollection().deleteMany({});
|
|
48
|
-
await createPlanDoc(createTestPlan({ currency:
|
|
49
|
-
await createPlanDoc(createTestPlan({ currency:
|
|
50
|
-
await createPlanDoc(createTestPlan({ currency:
|
|
52
|
+
await createPlanDoc(createTestPlan({ currency: "USD" }));
|
|
53
|
+
await createPlanDoc(createTestPlan({ currency: "USD" }));
|
|
54
|
+
await createPlanDoc(createTestPlan({ currency: "ILS" }));
|
|
51
55
|
|
|
52
|
-
const count = await countPlans({ currency:
|
|
56
|
+
const count = await countPlans({ currency: "USD" });
|
|
53
57
|
expect(count).toBe(2);
|
|
54
58
|
});
|
|
55
59
|
|
|
56
|
-
it(
|
|
60
|
+
it("should update a plan", async () => {
|
|
57
61
|
const plan = await createPlanDoc(createTestPlan({ isActive: true }));
|
|
58
62
|
const updated = await updatePlanDoc(plan._id, { isActive: false });
|
|
59
|
-
|
|
63
|
+
|
|
60
64
|
expect(updated).not.toBeNull();
|
|
61
65
|
expect(updated?.isActive).toBe(false);
|
|
62
|
-
|
|
66
|
+
|
|
63
67
|
const found = await findPlans({ _id: plan._id });
|
|
64
68
|
expect(found[0].isActive).toBe(false);
|
|
65
69
|
});
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
export * from
|
|
2
|
-
export * from
|
|
1
|
+
export * from "./plans.types";
|
|
2
|
+
export * from "./plans.getters";
|
|
@@ -1,9 +1,16 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
3
|
-
|
|
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";
|
|
4
11
|
|
|
5
12
|
export const getPlansCollection = () => {
|
|
6
|
-
return getDb().collection<Plan>(
|
|
13
|
+
return getDb().collection<Plan>("plans");
|
|
7
14
|
};
|
|
8
15
|
|
|
9
16
|
/**
|
|
@@ -42,7 +49,7 @@ const buildSimpleQuery = (filter: SimplePlanFilter): Filter<Plan> => {
|
|
|
42
49
|
*/
|
|
43
50
|
export const findPlans = async (
|
|
44
51
|
filter?: PlanFilter,
|
|
45
|
-
options?: PlanQueryOptions
|
|
52
|
+
options?: PlanQueryOptions,
|
|
46
53
|
): Promise<PlanDoc[]> => {
|
|
47
54
|
let query: Filter<Plan> = {};
|
|
48
55
|
|
|
@@ -81,7 +88,7 @@ export const findPlans = async (
|
|
|
81
88
|
|
|
82
89
|
export const findPlansByQuery = async (
|
|
83
90
|
query: Filter<Plan>,
|
|
84
|
-
options?: PlanQueryOptions
|
|
91
|
+
options?: PlanQueryOptions,
|
|
85
92
|
): Promise<PlanDoc[]> => {
|
|
86
93
|
const cursor = getPlansCollection().find(query);
|
|
87
94
|
return await applyQueryOptions(cursor, options).toArray();
|
|
@@ -92,7 +99,7 @@ export const countPlans = async (query: Filter<Plan>): Promise<number> => {
|
|
|
92
99
|
};
|
|
93
100
|
|
|
94
101
|
export const createPlanDoc = async (
|
|
95
|
-
planData: Omit<Plan,
|
|
102
|
+
planData: Omit<Plan, "createdAt" | "updatedAt">,
|
|
96
103
|
): Promise<PlanDoc> => {
|
|
97
104
|
const now = new Date();
|
|
98
105
|
const result = await getPlansCollection().insertOne({
|
|
@@ -102,24 +109,24 @@ export const createPlanDoc = async (
|
|
|
102
109
|
});
|
|
103
110
|
|
|
104
111
|
const plans = await findPlans({ _id: result.insertedId });
|
|
105
|
-
if (!plans[0]) throw new Error(
|
|
112
|
+
if (!plans[0]) throw new Error("Failed to retrieve created plan");
|
|
106
113
|
return plans[0];
|
|
107
114
|
};
|
|
108
115
|
|
|
109
116
|
export const updatePlanDoc = async (
|
|
110
117
|
planId: ObjectId,
|
|
111
|
-
updates: Partial<Omit<Plan,
|
|
118
|
+
updates: Partial<Omit<Plan, "createdAt" | "updatedAt">>,
|
|
112
119
|
): Promise<PlanDoc | null> => {
|
|
113
120
|
return await getPlansCollection().findOneAndUpdate(
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
},
|
|
121
|
+
{ _id: planId },
|
|
122
|
+
{
|
|
123
|
+
$set: {
|
|
124
|
+
...updates,
|
|
125
|
+
updatedAt: new Date(),
|
|
120
126
|
},
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
127
|
+
},
|
|
128
|
+
{
|
|
129
|
+
returnDocument: "after",
|
|
130
|
+
},
|
|
124
131
|
);
|
|
125
132
|
};
|
|
@@ -1,40 +1,44 @@
|
|
|
1
|
-
import { Sort, ObjectId, WithId } from
|
|
1
|
+
import { Sort, ObjectId, WithId } from "mongodb";
|
|
2
2
|
|
|
3
|
-
export const CURRENCY_CODES = [
|
|
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
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
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
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
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 =
|
|
33
|
+
export type ProductKey =
|
|
34
|
+
| "basic-500"
|
|
35
|
+
| "pro-1100"
|
|
36
|
+
| "scale-6000"
|
|
37
|
+
| (string & {});
|
|
34
38
|
|
|
35
39
|
/** Optional targeting to keep variants explicit */
|
|
36
|
-
export type RegionCode =
|
|
37
|
-
export type CountryCode =
|
|
40
|
+
export type RegionCode = "IL" | "EU" | "US" | (string & {});
|
|
41
|
+
export type CountryCode = "IL" | "DE" | "FR" | "ES" | "GB" | (string & {});
|
|
38
42
|
|
|
39
43
|
export type Tax = {
|
|
40
44
|
vatIncluded: boolean;
|
|
@@ -1,8 +1,9 @@
|
|
|
1
|
-
import type { Collection } from
|
|
2
|
-
import { getDb, ObjectId, Session } from
|
|
3
|
-
import type { Result } from
|
|
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> =>
|
|
5
|
+
export const getResultsCollection = (): Collection<Result> =>
|
|
6
|
+
getDb().collection<Result>("results");
|
|
6
7
|
|
|
7
8
|
export const createRunId = (): string => {
|
|
8
9
|
return `run_${new ObjectId().toString()}`;
|
|
@@ -10,17 +11,17 @@ export const createRunId = (): string => {
|
|
|
10
11
|
|
|
11
12
|
export const initializeResultDocument = async (
|
|
12
13
|
clientId: string,
|
|
13
|
-
session?: Session
|
|
14
|
+
session?: Session,
|
|
14
15
|
): Promise<Result> => {
|
|
15
16
|
const { insertedId } = await getResultsCollection().insertOne({
|
|
16
17
|
runId: createRunId(),
|
|
17
18
|
date: new Date(),
|
|
18
19
|
calls: [],
|
|
19
|
-
sessionId: session ? session._id!.toString() :
|
|
20
|
-
sessionName: session ? session.session_name :
|
|
20
|
+
sessionId: session ? session._id!.toString() : "incomingCall",
|
|
21
|
+
sessionName: session ? session.session_name : "incomingCall",
|
|
21
22
|
clientId,
|
|
22
23
|
});
|
|
23
24
|
const result = await getResultsCollection().findOne({ _id: insertedId });
|
|
24
|
-
if (!result) throw new Error(
|
|
25
|
+
if (!result) throw new Error("Failed to initialized result");
|
|
25
26
|
return result;
|
|
26
27
|
};
|
|
@@ -1,25 +1,25 @@
|
|
|
1
1
|
export const resultMongoSchema = {
|
|
2
|
-
bsonType:
|
|
2
|
+
bsonType: "object",
|
|
3
3
|
required: [
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
4
|
+
"_id",
|
|
5
|
+
"sessionId",
|
|
6
|
+
"status",
|
|
7
|
+
"callLength",
|
|
8
|
+
"date",
|
|
9
|
+
"userAnswer",
|
|
10
|
+
"systemSessionId",
|
|
11
|
+
"clientId",
|
|
12
12
|
],
|
|
13
13
|
properties: {
|
|
14
|
-
_id: { bsonType:
|
|
15
|
-
sessionId: { bsonType:
|
|
16
|
-
status: { bsonType:
|
|
17
|
-
callLength: { bsonType:
|
|
18
|
-
date: { bsonType:
|
|
19
|
-
userAnswer: { bsonType:
|
|
20
|
-
recordingUrl: { bsonType: [
|
|
21
|
-
systemSessionId: { bsonType:
|
|
22
|
-
clientId: { bsonType:
|
|
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,39 +1,52 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
import {
|
|
6
|
-
import {
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
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:
|
|
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:
|
|
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:
|
|
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({
|
|
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:
|
|
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(
|
|
51
|
-
const toInDB =
|
|
52
|
-
const fromInDB =
|
|
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({
|
|
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: [
|
|
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(
|
|
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(
|
|
72
|
-
const to =
|
|
73
|
-
const from =
|
|
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:
|
|
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(
|
|
96
|
-
const to =
|
|
97
|
-
const from =
|
|
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:
|
|
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(
|
|
119
|
-
const result = await findSessionOfIncomingCall(
|
|
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
|
|
2
|
-
export * from
|
|
1
|
+
export * from "./sessions.getter";
|
|
2
|
+
export * from "./sessions.types";
|
|
@@ -1,20 +1,22 @@
|
|
|
1
|
-
import { ObjectId } from
|
|
2
|
-
import type { Collection, WithId } from
|
|
3
|
-
import { getDb, getPhoneNumbersCollection } from
|
|
4
|
-
import type { Session } from
|
|
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>(
|
|
7
|
+
getDb().collection<Session>("sessions");
|
|
8
8
|
|
|
9
9
|
const buildPhoneCandidates = (phone: string): string[] => {
|
|
10
|
-
const raw = (phone ??
|
|
10
|
+
const raw = (phone ?? "").trim();
|
|
11
11
|
if (!raw) return [];
|
|
12
12
|
|
|
13
|
-
const noPlus = raw.startsWith(
|
|
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(
|
|
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({
|
|
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:
|
|
72
|
-
as:
|
|
73
|
-
cond: { $in: [
|
|
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(
|
|
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:
|
|
3
|
-
required: [
|
|
2
|
+
bsonType: "object",
|
|
3
|
+
required: ["session_name"],
|
|
4
4
|
properties: {
|
|
5
|
-
_id: { bsonType:
|
|
6
|
-
session_name: { bsonType:
|
|
7
|
-
company_name: { bsonType: [
|
|
8
|
-
flow_id: { bsonType: [
|
|
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: [
|
|
10
|
+
bsonType: ["array", "null"],
|
|
11
11
|
items: {
|
|
12
|
-
bsonType:
|
|
13
|
-
required: [
|
|
12
|
+
bsonType: "object",
|
|
13
|
+
required: ["key"],
|
|
14
14
|
properties: {
|
|
15
|
-
key: { bsonType:
|
|
16
|
-
value: { bsonType:
|
|
15
|
+
key: { bsonType: "string" },
|
|
16
|
+
value: { bsonType: "string" },
|
|
17
17
|
},
|
|
18
18
|
},
|
|
19
19
|
},
|
|
20
20
|
phone_numbers: {
|
|
21
|
-
bsonType:
|
|
21
|
+
bsonType: "array",
|
|
22
22
|
items: {
|
|
23
|
-
bsonType:
|
|
24
|
-
required: [
|
|
23
|
+
bsonType: "object",
|
|
24
|
+
required: ["name", "phoneNumber"],
|
|
25
25
|
properties: {
|
|
26
|
-
name: { bsonType:
|
|
27
|
-
phoneNumber: { bsonType:
|
|
26
|
+
name: { bsonType: "string" },
|
|
27
|
+
phoneNumber: { bsonType: "string" },
|
|
28
28
|
},
|
|
29
29
|
},
|
|
30
30
|
},
|
|
31
|
-
voice: { bsonType: [
|
|
31
|
+
voice: { bsonType: ["string", "null"] },
|
|
32
32
|
},
|
|
33
33
|
additionalProperties: false,
|
|
34
34
|
} as const;
|