@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.
- 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 +13 -25
- 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 +3 -3
- package/dist/talkpilot/calls/calls.getters.d.ts.map +1 -1
- package/dist/talkpilot/calls/calls.getters.js +19 -15
- package/dist/talkpilot/calls/calls.getters.js.map +1 -1
- package/dist/talkpilot/calls/calls.types.d.ts +3 -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 +9 -2
- 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.map +1 -1
- package/dist/talkpilot/flows/flows.schema.js +87 -79
- package/dist/talkpilot/flows/flows.schema.js.map +1 -1
- package/dist/talkpilot/flows/flows.types.d.ts +16 -16
- 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.d.ts.map +1 -1
- package/dist/talkpilot/mongodb-client.js +16 -29
- package/dist/talkpilot/mongodb-client.js.map +1 -1
- package/dist/talkpilot/phone_numbers/index.d.ts +2 -2
- package/dist/talkpilot/phone_numbers/phone_numbers.getter.d.ts +3 -3
- package/dist/talkpilot/phone_numbers/phone_numbers.getter.d.ts.map +1 -1
- package/dist/talkpilot/phone_numbers/phone_numbers.getter.js +28 -13
- package/dist/talkpilot/phone_numbers/phone_numbers.getter.js.map +1 -1
- package/dist/talkpilot/phone_numbers/phone_numbers.schema.js +9 -9
- package/dist/talkpilot/phone_numbers/phone_numbers.types.d.ts +1 -1
- 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/subscriptions/subscriptions.utils.d.ts +4 -0
- package/dist/talkpilot/subscriptions/subscriptions.utils.d.ts.map +1 -0
- package/dist/talkpilot/subscriptions/subscriptions.utils.js +20 -0
- package/dist/talkpilot/subscriptions/subscriptions.utils.js.map +1 -0
- 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 +19 -26
- 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 +79 -39
- package/src/talkpilot/calls/calls.getters.ts +48 -28
- package/src/talkpilot/calls/calls.types.ts +16 -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 +17 -7
- package/src/talkpilot/clientsConfig/index.ts +2 -2
- package/src/talkpilot/flows/__tests__/flows.schema.spec.ts +38 -34
- package/src/talkpilot/flows/flows.getter.ts +8 -5
- package/src/talkpilot/flows/flows.schema.ts +87 -79
- package/src/talkpilot/flows/flows.types.ts +23 -23
- 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 +23 -33
- package/src/talkpilot/phone_numbers/__tests__/phone_numbers.spec.ts +84 -44
- package/src/talkpilot/phone_numbers/index.ts +2 -2
- package/src/talkpilot/phone_numbers/phone_numbers.getter.ts +44 -22
- package/src/talkpilot/phone_numbers/phone_numbers.schema.ts +9 -9
- package/src/talkpilot/phone_numbers/phone_numbers.types.ts +1 -1
- 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
|
@@ -1,11 +1,17 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
1
|
+
import {
|
|
2
|
+
Call,
|
|
3
|
+
CallDoc,
|
|
4
|
+
CallQueryOptions,
|
|
5
|
+
CallUpdateParams,
|
|
6
|
+
getDb,
|
|
7
|
+
} from "../index";
|
|
8
|
+
import type { CallsByHour, CountOpts, DateRange } from "./calls.types";
|
|
9
|
+
import { Filter, ObjectId } from "mongodb";
|
|
10
|
+
import * as process from "node:process";
|
|
11
|
+
import { applyQueryOptions } from "../utils/query.utils";
|
|
6
12
|
|
|
7
13
|
export const getCallsCollection = () => {
|
|
8
|
-
return getDb().collection<Call>(
|
|
14
|
+
return getDb().collection<Call>("calls");
|
|
9
15
|
};
|
|
10
16
|
|
|
11
17
|
export const getCallByCallSid = (callSid: string) => {
|
|
@@ -13,7 +19,9 @@ export const getCallByCallSid = (callSid: string) => {
|
|
|
13
19
|
};
|
|
14
20
|
|
|
15
21
|
export const getCallsByPhoneNumber = (phoneNumber: string) => {
|
|
16
|
-
return getCallsCollection()
|
|
22
|
+
return getCallsCollection()
|
|
23
|
+
.find({ customerPhoneNumber: phoneNumber })
|
|
24
|
+
.toArray();
|
|
17
25
|
};
|
|
18
26
|
|
|
19
27
|
export const getCallsByClient = (clientId: string) => {
|
|
@@ -24,20 +32,22 @@ export const getCallsByFlow = (flowId: ObjectId) => {
|
|
|
24
32
|
return getCallsCollection().find({ flowId }).toArray();
|
|
25
33
|
};
|
|
26
34
|
|
|
27
|
-
export const createCallDoc = (
|
|
35
|
+
export const createCallDoc = (
|
|
36
|
+
call: Omit<Call, "createdAt" | "updatedAt" | "env">,
|
|
37
|
+
) => {
|
|
28
38
|
return getCallsCollection().insertOne({
|
|
29
39
|
...call,
|
|
30
40
|
createdAt: new Date(),
|
|
31
41
|
updatedAt: new Date(),
|
|
32
|
-
env: process.env.ENV ??
|
|
42
|
+
env: process.env.ENV ?? "unknown",
|
|
33
43
|
});
|
|
34
44
|
};
|
|
35
45
|
|
|
36
46
|
export const updateCallByCallSid = async (
|
|
37
47
|
callSid: string,
|
|
38
|
-
updates: CallUpdateParams
|
|
48
|
+
updates: CallUpdateParams,
|
|
39
49
|
): Promise<CallDoc | null> => {
|
|
40
|
-
|
|
50
|
+
return await getCallsCollection().findOneAndUpdate(
|
|
41
51
|
{ callSid: callSid },
|
|
42
52
|
{
|
|
43
53
|
$set: {
|
|
@@ -45,15 +55,17 @@ export const updateCallByCallSid = async (
|
|
|
45
55
|
updatedAt: new Date(),
|
|
46
56
|
},
|
|
47
57
|
},
|
|
48
|
-
{ returnDocument:
|
|
58
|
+
{ returnDocument: "after" },
|
|
49
59
|
);
|
|
50
|
-
|
|
51
|
-
return result;
|
|
52
60
|
};
|
|
53
61
|
|
|
54
62
|
// get calls by client and date range
|
|
55
63
|
//client here is the user id
|
|
56
|
-
export const getCallsByClientAndDateRange = (
|
|
64
|
+
export const getCallsByClientAndDateRange = (
|
|
65
|
+
clientId: string,
|
|
66
|
+
startDate: Date,
|
|
67
|
+
endDate: Date,
|
|
68
|
+
) => {
|
|
57
69
|
return getCallsCollection()
|
|
58
70
|
.find({
|
|
59
71
|
clientId,
|
|
@@ -67,7 +79,7 @@ export const getCallsByClientAndDateRange = (clientId: string, startDate: Date,
|
|
|
67
79
|
|
|
68
80
|
export const findCallsByQuery = async (
|
|
69
81
|
query: Filter<Call>,
|
|
70
|
-
options?: CallQueryOptions
|
|
82
|
+
options?: CallQueryOptions,
|
|
71
83
|
): Promise<CallDoc[]> => {
|
|
72
84
|
const cursor = getCallsCollection().find(query);
|
|
73
85
|
return await applyQueryOptions(cursor, options).toArray();
|
|
@@ -124,7 +136,7 @@ export const range = {
|
|
|
124
136
|
|
|
125
137
|
export function startOfDay(d: Date = new Date()): Date {
|
|
126
138
|
const x = new Date(d);
|
|
127
|
-
x.
|
|
139
|
+
x.setUTCHours(0, 0, 0, 0);
|
|
128
140
|
return x;
|
|
129
141
|
}
|
|
130
142
|
|
|
@@ -142,21 +154,29 @@ export async function getCallsStatsForDateRange(
|
|
|
142
154
|
clientId: string,
|
|
143
155
|
startStr: string,
|
|
144
156
|
endStr: string,
|
|
145
|
-
timezone: string
|
|
157
|
+
timezone: string,
|
|
146
158
|
): Promise<{ count: number; totalLen: number; completed: number }> {
|
|
147
159
|
const coll = getCallsCollection();
|
|
148
160
|
const out = await coll
|
|
149
|
-
.aggregate<{
|
|
161
|
+
.aggregate<{
|
|
162
|
+
_id: null;
|
|
163
|
+
count: number;
|
|
164
|
+
totalLen: number;
|
|
165
|
+
completed: number;
|
|
166
|
+
}>([
|
|
150
167
|
// 1. Restrict to the given client
|
|
151
168
|
{ $match: { clientId } },
|
|
152
169
|
// 2. Derive dateLocal (createdAt as YYYY-MM-DD in timezone) and isCompleted (agentHungUp or status='completed')
|
|
153
170
|
{
|
|
154
171
|
$addFields: {
|
|
155
172
|
dateLocal: {
|
|
156
|
-
$dateToString: { format:
|
|
173
|
+
$dateToString: { format: "%Y-%m-%d", date: "$createdAt", timezone },
|
|
157
174
|
},
|
|
158
175
|
isCompleted: {
|
|
159
|
-
$or: [
|
|
176
|
+
$or: [
|
|
177
|
+
{ $eq: ["$agentHungUp", true] },
|
|
178
|
+
{ $eq: ["$status", "completed"] },
|
|
179
|
+
],
|
|
160
180
|
},
|
|
161
181
|
},
|
|
162
182
|
},
|
|
@@ -167,8 +187,8 @@ export async function getCallsStatsForDateRange(
|
|
|
167
187
|
$group: {
|
|
168
188
|
_id: null,
|
|
169
189
|
count: { $sum: 1 },
|
|
170
|
-
totalLen: { $sum:
|
|
171
|
-
completed: { $sum: { $cond: [
|
|
190
|
+
totalLen: { $sum: "$callLength" },
|
|
191
|
+
completed: { $sum: { $cond: ["$isCompleted", 1, 0] } },
|
|
172
192
|
},
|
|
173
193
|
},
|
|
174
194
|
])
|
|
@@ -186,7 +206,7 @@ export async function getCallsStatsForDateRange(
|
|
|
186
206
|
export async function getCallsHourlyAggregation(
|
|
187
207
|
clientId: string,
|
|
188
208
|
dateStr: string,
|
|
189
|
-
timezone: string
|
|
209
|
+
timezone: string,
|
|
190
210
|
): Promise<CallsByHour[]> {
|
|
191
211
|
const coll = getCallsCollection();
|
|
192
212
|
const rows = await coll
|
|
@@ -197,22 +217,22 @@ export async function getCallsHourlyAggregation(
|
|
|
197
217
|
{
|
|
198
218
|
$addFields: {
|
|
199
219
|
dateLocal: {
|
|
200
|
-
$dateToString: { format:
|
|
220
|
+
$dateToString: { format: "%Y-%m-%d", date: "$createdAt", timezone },
|
|
201
221
|
},
|
|
202
|
-
hour: { $hour: { date:
|
|
222
|
+
hour: { $hour: { date: "$createdAt", timezone } },
|
|
203
223
|
},
|
|
204
224
|
},
|
|
205
225
|
// 3. Keep only the requested date
|
|
206
226
|
{ $match: { dateLocal: dateStr } },
|
|
207
227
|
// 4. Group by hour, sum calls per hour
|
|
208
|
-
{ $group: { _id:
|
|
228
|
+
{ $group: { _id: "$hour", calls: { $sum: 1 } } },
|
|
209
229
|
// 5. Order by hour ascending (0..23)
|
|
210
230
|
{ $sort: { _id: 1 } },
|
|
211
231
|
])
|
|
212
232
|
.toArray();
|
|
213
233
|
|
|
214
234
|
return rows.map((r: any) => ({
|
|
215
|
-
hour: `${String(r._id).padStart(2,
|
|
235
|
+
hour: `${String(r._id).padStart(2, "0")}:00`,
|
|
216
236
|
calls: r.calls,
|
|
217
237
|
}));
|
|
218
238
|
}
|
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
import { ObjectId, Sort, WithId } from
|
|
2
|
-
import { TranscriptionSegment } from
|
|
1
|
+
import { ObjectId, Sort, WithId } from "mongodb";
|
|
2
|
+
import { TranscriptionSegment } from "../results";
|
|
3
3
|
|
|
4
|
-
export const CONFERENCE_ROLE_CUSTOMER =
|
|
5
|
-
export const CONFERENCE_ROLE_SUPERVISOR =
|
|
4
|
+
export const CONFERENCE_ROLE_CUSTOMER = "customer" as const;
|
|
5
|
+
export const CONFERENCE_ROLE_SUPERVISOR = "supervisor" as const;
|
|
6
6
|
|
|
7
7
|
export type ConferenceRole =
|
|
8
8
|
| typeof CONFERENCE_ROLE_CUSTOMER
|
|
@@ -62,18 +62,18 @@ export type CallsFilterParams = {
|
|
|
62
62
|
};
|
|
63
63
|
|
|
64
64
|
export type ImmutableCallFields =
|
|
65
|
-
|
|
|
66
|
-
|
|
|
67
|
-
|
|
|
68
|
-
|
|
|
69
|
-
|
|
|
70
|
-
|
|
|
71
|
-
|
|
|
72
|
-
|
|
|
73
|
-
|
|
|
74
|
-
|
|
|
75
|
-
|
|
|
76
|
-
|
|
|
65
|
+
| "customerPhoneNumber"
|
|
66
|
+
| "agentPhoneNumber"
|
|
67
|
+
| "isIncomingCall"
|
|
68
|
+
| "isOutgoingCall"
|
|
69
|
+
| "sessionId"
|
|
70
|
+
| "callSid"
|
|
71
|
+
| "flowId"
|
|
72
|
+
| "clientId"
|
|
73
|
+
| "runId"
|
|
74
|
+
| "resultId"
|
|
75
|
+
| "env"
|
|
76
|
+
| "createdAt";
|
|
77
77
|
|
|
78
78
|
export type CallUpdateParams = Partial<Omit<Call, ImmutableCallFields>>;
|
|
79
79
|
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
export * from
|
|
2
|
-
export * from
|
|
1
|
+
export * from "./calls.types";
|
|
2
|
+
export * from "./calls.getters";
|
|
@@ -4,46 +4,66 @@ import {
|
|
|
4
4
|
findClientAudioBuffersByCallSidAndRange,
|
|
5
5
|
getMergedAudioByCallSid,
|
|
6
6
|
getAudioChunksByCallSid,
|
|
7
|
-
} from
|
|
8
|
-
import { ObjectId } from
|
|
9
|
-
import { createAudioBufferInput } from
|
|
7
|
+
} from "../clientAudioBuffer.getters";
|
|
8
|
+
import { ObjectId } from "../../index";
|
|
9
|
+
import { createAudioBufferInput } from "../../../test-utils/factories";
|
|
10
10
|
|
|
11
|
-
describe(
|
|
11
|
+
describe("clientAudioBuffers getters", () => {
|
|
12
12
|
it('should return the "clientAudioBuffers" collection', () => {
|
|
13
13
|
const collection = getClientAudioBuffersCollection();
|
|
14
|
-
expect(collection.collectionName).toBe(
|
|
14
|
+
expect(collection.collectionName).toBe("clientAudioBuffers");
|
|
15
15
|
});
|
|
16
16
|
|
|
17
|
-
it(
|
|
17
|
+
it("should insert a client audio buffer and return insertedId", async () => {
|
|
18
18
|
const inputToCheck = createAudioBufferInput();
|
|
19
19
|
const result = await insertClientAudioBuffer(inputToCheck);
|
|
20
20
|
expect(result.insertedId).toBeInstanceOf(ObjectId);
|
|
21
21
|
|
|
22
|
-
const savedDoc = await getClientAudioBuffersCollection().findOne({
|
|
22
|
+
const savedDoc = await getClientAudioBuffersCollection().findOne({
|
|
23
|
+
_id: result.insertedId,
|
|
24
|
+
});
|
|
23
25
|
expect(savedDoc).toBeDefined();
|
|
24
26
|
expect(savedDoc?.createdAt).toBeInstanceOf(Date);
|
|
25
27
|
expect(savedDoc?.expiresAt).toBeInstanceOf(Date);
|
|
26
28
|
});
|
|
27
29
|
|
|
28
|
-
it(
|
|
29
|
-
const callSid =
|
|
30
|
-
await insertClientAudioBuffer(
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
await insertClientAudioBuffer(
|
|
30
|
+
it("should return only buffers in the specified bucketStartMs range", async () => {
|
|
31
|
+
const callSid = "CA1234567890abcdef1234567890abcdef";
|
|
32
|
+
await insertClientAudioBuffer(
|
|
33
|
+
createAudioBufferInput({ callSid, bucketStartMs: 500 }),
|
|
34
|
+
);
|
|
35
|
+
await insertClientAudioBuffer(
|
|
36
|
+
createAudioBufferInput({ callSid, bucketStartMs: 1000 }),
|
|
37
|
+
);
|
|
38
|
+
await insertClientAudioBuffer(
|
|
39
|
+
createAudioBufferInput({ callSid, bucketStartMs: 3000 }),
|
|
40
|
+
);
|
|
41
|
+
await insertClientAudioBuffer(
|
|
42
|
+
createAudioBufferInput({ callSid, bucketStartMs: 6000 }),
|
|
43
|
+
);
|
|
34
44
|
|
|
35
|
-
const result = await findClientAudioBuffersByCallSidAndRange(
|
|
45
|
+
const result = await findClientAudioBuffersByCallSidAndRange(
|
|
46
|
+
callSid,
|
|
47
|
+
500,
|
|
48
|
+
3000,
|
|
49
|
+
);
|
|
36
50
|
expect(result).toHaveLength(3);
|
|
37
51
|
const bucketStartValues = result.map((doc) => doc.bucketStartMs);
|
|
38
52
|
const bucketStartsSorted = bucketStartValues.sort((a, b) => a - b);
|
|
39
53
|
expect(bucketStartsSorted).toEqual([500, 1000, 3000]);
|
|
40
54
|
});
|
|
41
55
|
|
|
42
|
-
it(
|
|
43
|
-
const callSid =
|
|
44
|
-
await insertClientAudioBuffer(
|
|
45
|
-
|
|
46
|
-
|
|
56
|
+
it("should return all buffers when no range is provided", async () => {
|
|
57
|
+
const callSid = "CA1234567890abcdef1234567890abcdeg";
|
|
58
|
+
await insertClientAudioBuffer(
|
|
59
|
+
createAudioBufferInput({ callSid, bucketStartMs: 500 }),
|
|
60
|
+
);
|
|
61
|
+
await insertClientAudioBuffer(
|
|
62
|
+
createAudioBufferInput({ callSid, bucketStartMs: 1000 }),
|
|
63
|
+
);
|
|
64
|
+
await insertClientAudioBuffer(
|
|
65
|
+
createAudioBufferInput({ callSid, bucketStartMs: 3000 }),
|
|
66
|
+
);
|
|
47
67
|
|
|
48
68
|
const result = await findClientAudioBuffersByCallSidAndRange(callSid);
|
|
49
69
|
expect(result).toHaveLength(3);
|
|
@@ -52,21 +72,33 @@ describe('clientAudioBuffers getters', () => {
|
|
|
52
72
|
expect(bucketStartsSorted).toEqual([500, 1000, 3000]);
|
|
53
73
|
});
|
|
54
74
|
|
|
55
|
-
it(
|
|
56
|
-
const callSid =
|
|
75
|
+
it("should merge audio buffers by callSid in chronological order", async () => {
|
|
76
|
+
const callSid = "CA1234567890abcdef1234567890abcdeh";
|
|
57
77
|
|
|
58
78
|
const firstBuffer = Buffer.from([1, 2]);
|
|
59
79
|
const secondBuffer = Buffer.from([3]);
|
|
60
80
|
const thirdBuffer = Buffer.from([4, 5]);
|
|
61
81
|
|
|
62
82
|
await insertClientAudioBuffer(
|
|
63
|
-
|
|
83
|
+
createAudioBufferInput({
|
|
84
|
+
callSid,
|
|
85
|
+
bucketStartMs: 1000,
|
|
86
|
+
data: secondBuffer,
|
|
87
|
+
}),
|
|
64
88
|
);
|
|
65
89
|
await insertClientAudioBuffer(
|
|
66
|
-
|
|
90
|
+
createAudioBufferInput({
|
|
91
|
+
callSid,
|
|
92
|
+
bucketStartMs: 500,
|
|
93
|
+
data: firstBuffer,
|
|
94
|
+
}),
|
|
67
95
|
);
|
|
68
96
|
await insertClientAudioBuffer(
|
|
69
|
-
|
|
97
|
+
createAudioBufferInput({
|
|
98
|
+
callSid,
|
|
99
|
+
bucketStartMs: 3000,
|
|
100
|
+
data: thirdBuffer,
|
|
101
|
+
}),
|
|
70
102
|
);
|
|
71
103
|
|
|
72
104
|
const merged = await getMergedAudioByCallSid(callSid, 10);
|
|
@@ -77,8 +109,8 @@ describe('clientAudioBuffers getters', () => {
|
|
|
77
109
|
expect(merged.equals(expected)).toBe(true);
|
|
78
110
|
});
|
|
79
111
|
|
|
80
|
-
it(
|
|
81
|
-
const callSid =
|
|
112
|
+
it("should return all audio chunks when less than or equal to limit buffers exist", async () => {
|
|
113
|
+
const callSid = "CA1234567890abcdef1234567890abclt";
|
|
82
114
|
|
|
83
115
|
const limit = 30;
|
|
84
116
|
const buffers: Buffer[] = [];
|
|
@@ -86,11 +118,11 @@ describe('clientAudioBuffers getters', () => {
|
|
|
86
118
|
const buf = Buffer.from([i]);
|
|
87
119
|
buffers.push(buf);
|
|
88
120
|
await insertClientAudioBuffer(
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
121
|
+
createAudioBufferInput({
|
|
122
|
+
callSid,
|
|
123
|
+
bucketStartMs: 1000 + i * 1000,
|
|
124
|
+
data: buf,
|
|
125
|
+
}),
|
|
94
126
|
);
|
|
95
127
|
}
|
|
96
128
|
|
|
@@ -101,8 +133,8 @@ describe('clientAudioBuffers getters', () => {
|
|
|
101
133
|
expect(Buffer.concat(chunks).equals(Buffer.concat(buffers))).toBe(true);
|
|
102
134
|
});
|
|
103
135
|
|
|
104
|
-
it(
|
|
105
|
-
const callSid =
|
|
136
|
+
it("should return only the last N audio chunks when more than limit buffers exist", async () => {
|
|
137
|
+
const callSid = "CA1234567890abcdef1234567890abclm";
|
|
106
138
|
|
|
107
139
|
const limit = 30;
|
|
108
140
|
const buffers: Buffer[] = [];
|
|
@@ -110,17 +142,19 @@ describe('clientAudioBuffers getters', () => {
|
|
|
110
142
|
const buf = Buffer.from([i]);
|
|
111
143
|
buffers.push(buf);
|
|
112
144
|
await insertClientAudioBuffer(
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
145
|
+
createAudioBufferInput({
|
|
146
|
+
callSid,
|
|
147
|
+
bucketStartMs: 1000 + i * 1000,
|
|
148
|
+
data: buf,
|
|
149
|
+
}),
|
|
118
150
|
);
|
|
119
151
|
}
|
|
120
152
|
|
|
121
153
|
const chunks = await getAudioChunksByCallSid(callSid, limit);
|
|
122
154
|
const expectedBuffers = buffers.slice(-limit);
|
|
123
155
|
expect(chunks).toHaveLength(expectedBuffers.length);
|
|
124
|
-
expect(Buffer.concat(chunks).equals(Buffer.concat(expectedBuffers))).toBe(
|
|
156
|
+
expect(Buffer.concat(chunks).equals(Buffer.concat(expectedBuffers))).toBe(
|
|
157
|
+
true,
|
|
158
|
+
);
|
|
125
159
|
});
|
|
126
160
|
});
|
|
@@ -1,17 +1,18 @@
|
|
|
1
|
-
import { getDb } from
|
|
1
|
+
import { getDb } from "../index";
|
|
2
2
|
import {
|
|
3
3
|
ClientAudioBufferDoc,
|
|
4
4
|
ClientAudioBufferType,
|
|
5
5
|
CreateAudioBufferInput,
|
|
6
|
-
} from
|
|
7
|
-
import { Collection, InsertOneResult } from
|
|
6
|
+
} from "./clientsAudioBuffers.types";
|
|
7
|
+
import { Collection, InsertOneResult } from "mongodb";
|
|
8
8
|
|
|
9
|
-
const getClientAudioBuffersCollection =
|
|
10
|
-
|
|
11
|
-
|
|
9
|
+
const getClientAudioBuffersCollection =
|
|
10
|
+
(): Collection<ClientAudioBufferType> => {
|
|
11
|
+
return getDb().collection<ClientAudioBufferType>("clientAudioBuffers");
|
|
12
|
+
};
|
|
12
13
|
|
|
13
14
|
const insertClientAudioBuffer = async (
|
|
14
|
-
audioBufferInput: CreateAudioBufferInput
|
|
15
|
+
audioBufferInput: CreateAudioBufferInput,
|
|
15
16
|
): Promise<InsertOneResult<ClientAudioBufferType>> => {
|
|
16
17
|
const collection = getClientAudioBuffersCollection();
|
|
17
18
|
const realtimeDate = new Date();
|
|
@@ -27,7 +28,7 @@ const insertClientAudioBuffer = async (
|
|
|
27
28
|
};
|
|
28
29
|
const clientAudioBufferMongoDocument: ClientAudioBufferType = {
|
|
29
30
|
...inputFieldsForDocument,
|
|
30
|
-
codec:
|
|
31
|
+
codec: "mulaw",
|
|
31
32
|
sampleRateHz: 8000,
|
|
32
33
|
channels: 1,
|
|
33
34
|
createdAt: realtimeDate,
|
|
@@ -39,7 +40,7 @@ const insertClientAudioBuffer = async (
|
|
|
39
40
|
const findClientAudioBuffersByCallSidAndRange = async (
|
|
40
41
|
callSid: string,
|
|
41
42
|
startMs?: number,
|
|
42
|
-
endMs?: number
|
|
43
|
+
endMs?: number,
|
|
43
44
|
): Promise<ClientAudioBufferDoc[]> => {
|
|
44
45
|
const collection = getClientAudioBuffersCollection();
|
|
45
46
|
if (startMs === undefined) {
|
|
@@ -57,7 +58,10 @@ const findClientAudioBuffersByCallSidAndRange = async (
|
|
|
57
58
|
.toArray();
|
|
58
59
|
};
|
|
59
60
|
|
|
60
|
-
const getAudioChunksByCallSid = async (
|
|
61
|
+
const getAudioChunksByCallSid = async (
|
|
62
|
+
callSid: string,
|
|
63
|
+
limit?: number,
|
|
64
|
+
): Promise<Buffer[]> => {
|
|
61
65
|
const query = getClientAudioBuffersCollection().find({ callSid });
|
|
62
66
|
if (limit) {
|
|
63
67
|
query.sort({ bucketStartMs: -1 }).limit(limit);
|
|
@@ -80,7 +84,10 @@ const getAudioChunksByCallSid = async (callSid: string, limit?: number): Promise
|
|
|
80
84
|
});
|
|
81
85
|
};
|
|
82
86
|
|
|
83
|
-
const getMergedAudioByCallSid = async (
|
|
87
|
+
const getMergedAudioByCallSid = async (
|
|
88
|
+
callSid: string,
|
|
89
|
+
limit: number,
|
|
90
|
+
): Promise<Buffer> => {
|
|
84
91
|
const buffers = await getAudioChunksByCallSid(callSid, limit);
|
|
85
92
|
|
|
86
93
|
if (!buffers.length) {
|
|
@@ -1,11 +1,11 @@
|
|
|
1
|
-
import { WithId } from
|
|
1
|
+
import { WithId } from "mongodb";
|
|
2
2
|
|
|
3
3
|
export type ClientAudioBufferType = {
|
|
4
4
|
callSid: string;
|
|
5
5
|
clientId: string;
|
|
6
6
|
bucketStartMs: number;
|
|
7
7
|
bucketDurationMs: number;
|
|
8
|
-
codec:
|
|
8
|
+
codec: "mulaw";
|
|
9
9
|
sampleRateHz: 8000;
|
|
10
10
|
channels: 1;
|
|
11
11
|
data: Buffer;
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
export * from
|
|
2
|
-
export * from
|
|
1
|
+
export * from "./clientAudioBuffer.getters";
|
|
2
|
+
export * from "./clientsAudioBuffers.types";
|
|
@@ -1,11 +1,16 @@
|
|
|
1
|
-
import { getDb, Client } from
|
|
2
|
-
import { Collection } from
|
|
1
|
+
import { getDb, Client } from "../index";
|
|
2
|
+
import { Collection } from "mongodb";
|
|
3
3
|
|
|
4
4
|
export const getClientsCollection = (): Collection<Client> => {
|
|
5
|
-
return getDb().collection<Client>(
|
|
5
|
+
return getDb().collection<Client>("clients");
|
|
6
6
|
};
|
|
7
7
|
|
|
8
|
-
export const getClientByAPIKey = async (
|
|
9
|
-
|
|
8
|
+
export const getClientByAPIKey = async (
|
|
9
|
+
apiKey: string,
|
|
10
|
+
): Promise<Client | null> => {
|
|
11
|
+
const client = await getClientsCollection().findOne({
|
|
12
|
+
apiKey,
|
|
13
|
+
isActive: true,
|
|
14
|
+
});
|
|
10
15
|
return client ? client : null;
|
|
11
16
|
};
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
export * from
|
|
2
|
-
export * from
|
|
1
|
+
export * from "./clients.getters";
|
|
2
|
+
export * from "./clients.types";
|
|
@@ -1,13 +1,16 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
1
|
+
import {
|
|
2
|
+
createClientConfigDoc,
|
|
3
|
+
getClientConfig,
|
|
4
|
+
} from "../clientsConfig.getters";
|
|
5
|
+
import { createClientConfig } from "../../../test-utils/factories";
|
|
3
6
|
|
|
4
|
-
describe(
|
|
5
|
-
describe(
|
|
6
|
-
it(
|
|
7
|
-
const clientId =
|
|
7
|
+
describe("db.clientsConfig", () => {
|
|
8
|
+
describe("getClientConfig", () => {
|
|
9
|
+
it("should return client config by clientId", async () => {
|
|
10
|
+
const clientId = "test-client-id";
|
|
8
11
|
const clientConfig = createClientConfig({
|
|
9
12
|
clientId,
|
|
10
|
-
language:
|
|
13
|
+
language: "Hebrew",
|
|
11
14
|
products: { feature1: true, feature2: false } as any,
|
|
12
15
|
});
|
|
13
16
|
|
|
@@ -17,25 +20,25 @@ describe('db.clientsConfig', () => {
|
|
|
17
20
|
|
|
18
21
|
expect(result).toMatchObject({
|
|
19
22
|
clientId,
|
|
20
|
-
language:
|
|
23
|
+
language: "Hebrew",
|
|
21
24
|
products: { feature1: true, feature2: false },
|
|
22
25
|
});
|
|
23
26
|
});
|
|
24
27
|
|
|
25
|
-
it(
|
|
26
|
-
const result = await getClientConfig(
|
|
28
|
+
it("should return null for non-existent clientId", async () => {
|
|
29
|
+
const result = await getClientConfig("non-existent-client");
|
|
27
30
|
expect(result).toBeNull();
|
|
28
31
|
});
|
|
29
32
|
|
|
30
|
-
it(
|
|
31
|
-
const clientId =
|
|
33
|
+
it("should support communications config", async () => {
|
|
34
|
+
const clientId = "communications-test";
|
|
32
35
|
const clientConfig = createClientConfig({
|
|
33
36
|
clientId,
|
|
34
37
|
communications: {
|
|
35
38
|
sendGrid: {
|
|
36
|
-
emailTo: [
|
|
37
|
-
templateId:
|
|
38
|
-
senderId:
|
|
39
|
+
emailTo: ["test@example.com"],
|
|
40
|
+
templateId: "temp-123",
|
|
41
|
+
senderId: "sender-123",
|
|
39
42
|
},
|
|
40
43
|
sms: {},
|
|
41
44
|
whatsapp: {},
|
|
@@ -50,9 +53,9 @@ describe('db.clientsConfig', () => {
|
|
|
50
53
|
clientId,
|
|
51
54
|
communications: {
|
|
52
55
|
sendGrid: {
|
|
53
|
-
emailTo: [
|
|
54
|
-
templateId:
|
|
55
|
-
senderId:
|
|
56
|
+
emailTo: ["test@example.com"],
|
|
57
|
+
templateId: "temp-123",
|
|
58
|
+
senderId: "sender-123",
|
|
56
59
|
},
|
|
57
60
|
sms: {},
|
|
58
61
|
whatsapp: {},
|
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
import { ClientConfigDoc, getDb, findClientByPhoneNumber } from
|
|
2
|
-
import { Collection } from
|
|
1
|
+
import { ClientConfigDoc, getDb, findClientByPhoneNumber } from "../index";
|
|
2
|
+
import { Collection } from "mongodb";
|
|
3
3
|
|
|
4
4
|
export const getClientsConfigCollection = (): Collection<ClientConfigDoc> => {
|
|
5
|
-
return getDb().collection<ClientConfigDoc>(
|
|
5
|
+
return getDb().collection<ClientConfigDoc>("clientsConfig");
|
|
6
6
|
};
|
|
7
7
|
|
|
8
8
|
export const getClientConfig = (clientId: string) => {
|
|
@@ -15,6 +15,8 @@ export const getClientConfigByPhone = async (phone: string) => {
|
|
|
15
15
|
return getClientConfig(client.clientId);
|
|
16
16
|
};
|
|
17
17
|
|
|
18
|
-
export const createClientConfigDoc = async (
|
|
18
|
+
export const createClientConfigDoc = async (
|
|
19
|
+
clientConfig: ClientConfigDoc,
|
|
20
|
+
): Promise<void> => {
|
|
19
21
|
await getClientsConfigCollection().insertOne(clientConfig);
|
|
20
22
|
};
|