@talkpilot/core-db 1.0.1
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/.cursor/rules/development.mdc +65 -0
- package/DEVELOPMENT.md +98 -0
- package/README.md +140 -0
- package/dist/index.d.ts +7 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +29 -0
- package/dist/index.js.map +1 -0
- package/dist/municipal/cities/cities.getters.d.ts +9 -0
- package/dist/municipal/cities/cities.getters.d.ts.map +1 -0
- package/dist/municipal/cities/cities.getters.js +38 -0
- package/dist/municipal/cities/cities.getters.js.map +1 -0
- package/dist/municipal/cities/cities.types.d.ts +10 -0
- package/dist/municipal/cities/cities.types.d.ts.map +1 -0
- package/dist/municipal/cities/cities.types.js +3 -0
- package/dist/municipal/cities/cities.types.js.map +1 -0
- package/dist/municipal/cities/index.d.ts +3 -0
- package/dist/municipal/cities/index.d.ts.map +1 -0
- package/dist/municipal/cities/index.js +18 -0
- package/dist/municipal/cities/index.js.map +1 -0
- package/dist/municipal/departmentsSubjects/departmentsSubjects.getters.d.ts +62 -0
- package/dist/municipal/departmentsSubjects/departmentsSubjects.getters.d.ts.map +1 -0
- package/dist/municipal/departmentsSubjects/departmentsSubjects.getters.js +180 -0
- package/dist/municipal/departmentsSubjects/departmentsSubjects.getters.js.map +1 -0
- package/dist/municipal/departmentsSubjects/departmentsSubjects.types.d.ts +69 -0
- package/dist/municipal/departmentsSubjects/departmentsSubjects.types.d.ts.map +1 -0
- package/dist/municipal/departmentsSubjects/departmentsSubjects.types.js +3 -0
- package/dist/municipal/departmentsSubjects/departmentsSubjects.types.js.map +1 -0
- package/dist/municipal/departmentsSubjects/index.d.ts +3 -0
- package/dist/municipal/departmentsSubjects/index.d.ts.map +1 -0
- package/dist/municipal/departmentsSubjects/index.js +18 -0
- package/dist/municipal/departmentsSubjects/index.js.map +1 -0
- package/dist/municipal/index.d.ts +10 -0
- package/dist/municipal/index.d.ts.map +1 -0
- package/dist/municipal/index.js +37 -0
- package/dist/municipal/index.js.map +1 -0
- package/dist/municipal/mongodb-client.d.ts +13 -0
- package/dist/municipal/mongodb-client.d.ts.map +1 -0
- package/dist/municipal/mongodb-client.js +56 -0
- package/dist/municipal/mongodb-client.js.map +1 -0
- package/dist/municipal/streets/index.d.ts +3 -0
- package/dist/municipal/streets/index.d.ts.map +1 -0
- package/dist/municipal/streets/index.js +18 -0
- package/dist/municipal/streets/index.js.map +1 -0
- package/dist/municipal/streets/streets.getters.d.ts +21 -0
- package/dist/municipal/streets/streets.getters.d.ts.map +1 -0
- package/dist/municipal/streets/streets.getters.js +85 -0
- package/dist/municipal/streets/streets.getters.js.map +1 -0
- package/dist/municipal/streets/streets.types.d.ts +16 -0
- package/dist/municipal/streets/streets.types.d.ts.map +1 -0
- package/dist/municipal/streets/streets.types.js +3 -0
- package/dist/municipal/streets/streets.types.js.map +1 -0
- package/dist/municipal/tickets/index.d.ts +3 -0
- package/dist/municipal/tickets/index.d.ts.map +1 -0
- package/dist/municipal/tickets/index.js +18 -0
- package/dist/municipal/tickets/index.js.map +1 -0
- package/dist/municipal/tickets/tickets.getters.d.ts +44 -0
- package/dist/municipal/tickets/tickets.getters.d.ts.map +1 -0
- package/dist/municipal/tickets/tickets.getters.js +199 -0
- package/dist/municipal/tickets/tickets.getters.js.map +1 -0
- package/dist/municipal/tickets/tickets.types.d.ts +35 -0
- package/dist/municipal/tickets/tickets.types.d.ts.map +1 -0
- package/dist/municipal/tickets/tickets.types.js +3 -0
- package/dist/municipal/tickets/tickets.types.js.map +1 -0
- package/dist/talkpilot/agents/agents.getters.d.ts +9 -0
- package/dist/talkpilot/agents/agents.getters.d.ts.map +1 -0
- package/dist/talkpilot/agents/agents.getters.js +34 -0
- package/dist/talkpilot/agents/agents.getters.js.map +1 -0
- package/dist/talkpilot/agents/agents.types.d.ts +13 -0
- package/dist/talkpilot/agents/agents.types.d.ts.map +1 -0
- package/dist/talkpilot/agents/agents.types.js +3 -0
- package/dist/talkpilot/agents/agents.types.js.map +1 -0
- package/dist/talkpilot/agents/index.d.ts +3 -0
- package/dist/talkpilot/agents/index.d.ts.map +1 -0
- package/dist/talkpilot/agents/index.js +19 -0
- package/dist/talkpilot/agents/index.js.map +1 -0
- package/dist/talkpilot/calls/calls.getters.d.ts +24 -0
- package/dist/talkpilot/calls/calls.getters.d.ts.map +1 -0
- package/dist/talkpilot/calls/calls.getters.js +151 -0
- package/dist/talkpilot/calls/calls.getters.js.map +1 -0
- package/dist/talkpilot/calls/calls.types.d.ts +32 -0
- package/dist/talkpilot/calls/calls.types.d.ts.map +1 -0
- package/dist/talkpilot/calls/calls.types.js +3 -0
- package/dist/talkpilot/calls/calls.types.js.map +1 -0
- package/dist/talkpilot/calls/index.d.ts +3 -0
- package/dist/talkpilot/calls/index.d.ts.map +1 -0
- package/dist/talkpilot/calls/index.js +19 -0
- package/dist/talkpilot/calls/index.js.map +1 -0
- package/dist/talkpilot/clientAudioBuffers/clientAudioBuffer.getters.d.ts +9 -0
- package/dist/talkpilot/clientAudioBuffers/clientAudioBuffer.getters.d.ts.map +1 -0
- package/dist/talkpilot/clientAudioBuffers/clientAudioBuffer.getters.js +76 -0
- package/dist/talkpilot/clientAudioBuffers/clientAudioBuffer.getters.js.map +1 -0
- package/dist/talkpilot/clientAudioBuffers/clientsAudioBuffers.types.d.ts +23 -0
- package/dist/talkpilot/clientAudioBuffers/clientsAudioBuffers.types.d.ts.map +1 -0
- package/dist/talkpilot/clientAudioBuffers/clientsAudioBuffers.types.js +3 -0
- package/dist/talkpilot/clientAudioBuffers/clientsAudioBuffers.types.js.map +1 -0
- package/dist/talkpilot/clients/clients.getters.d.ts +5 -0
- package/dist/talkpilot/clients/clients.getters.d.ts.map +1 -0
- package/dist/talkpilot/clients/clients.getters.js +14 -0
- package/dist/talkpilot/clients/clients.getters.js.map +1 -0
- package/dist/talkpilot/clients/clients.types.d.ts +12 -0
- package/dist/talkpilot/clients/clients.types.d.ts.map +1 -0
- package/dist/talkpilot/clients/clients.types.js +3 -0
- package/dist/talkpilot/clients/clients.types.js.map +1 -0
- package/dist/talkpilot/clients/index.d.ts +3 -0
- package/dist/talkpilot/clients/index.d.ts.map +1 -0
- package/dist/talkpilot/clients/index.js +18 -0
- package/dist/talkpilot/clients/index.js.map +1 -0
- package/dist/talkpilot/clientsConfig/clientsConfig.getters.d.ts +7 -0
- package/dist/talkpilot/clientsConfig/clientsConfig.getters.d.ts.map +1 -0
- package/dist/talkpilot/clientsConfig/clientsConfig.getters.js +21 -0
- package/dist/talkpilot/clientsConfig/clientsConfig.getters.js.map +1 -0
- package/dist/talkpilot/clientsConfig/clientsConfig.types.d.ts +53 -0
- package/dist/talkpilot/clientsConfig/clientsConfig.types.d.ts.map +1 -0
- package/dist/talkpilot/clientsConfig/clientsConfig.types.js +3 -0
- package/dist/talkpilot/clientsConfig/clientsConfig.types.js.map +1 -0
- package/dist/talkpilot/clientsConfig/index.d.ts +3 -0
- package/dist/talkpilot/clientsConfig/index.d.ts.map +1 -0
- package/dist/talkpilot/clientsConfig/index.js +19 -0
- package/dist/talkpilot/clientsConfig/index.js.map +1 -0
- package/dist/talkpilot/flows/flows.getter.d.ts +5 -0
- package/dist/talkpilot/flows/flows.getter.d.ts.map +1 -0
- package/dist/talkpilot/flows/flows.getter.js +13 -0
- package/dist/talkpilot/flows/flows.getter.js.map +1 -0
- package/dist/talkpilot/flows/flows.schema.d.ts +154 -0
- package/dist/talkpilot/flows/flows.schema.d.ts.map +1 -0
- package/dist/talkpilot/flows/flows.schema.js +94 -0
- package/dist/talkpilot/flows/flows.schema.js.map +1 -0
- package/dist/talkpilot/flows/flows.types.d.ts +116 -0
- package/dist/talkpilot/flows/flows.types.d.ts.map +1 -0
- package/dist/talkpilot/flows/flows.types.js +3 -0
- package/dist/talkpilot/flows/flows.types.js.map +1 -0
- package/dist/talkpilot/flows/index.d.ts +3 -0
- package/dist/talkpilot/flows/index.d.ts.map +1 -0
- package/dist/talkpilot/flows/index.js +6 -0
- package/dist/talkpilot/flows/index.js.map +1 -0
- package/dist/talkpilot/groups/groups.getters.d.ts +8 -0
- package/dist/talkpilot/groups/groups.getters.d.ts.map +1 -0
- package/dist/talkpilot/groups/groups.getters.js +26 -0
- package/dist/talkpilot/groups/groups.getters.js.map +1 -0
- package/dist/talkpilot/groups/groups.types.d.ts +26 -0
- package/dist/talkpilot/groups/groups.types.d.ts.map +1 -0
- package/dist/talkpilot/groups/groups.types.js +3 -0
- package/dist/talkpilot/groups/groups.types.js.map +1 -0
- package/dist/talkpilot/groups/index.d.ts +3 -0
- package/dist/talkpilot/groups/index.d.ts.map +1 -0
- package/dist/talkpilot/groups/index.js +19 -0
- package/dist/talkpilot/groups/index.js.map +1 -0
- package/dist/talkpilot/groups/phone.utils.d.ts +4 -0
- package/dist/talkpilot/groups/phone.utils.d.ts.map +1 -0
- package/dist/talkpilot/groups/phone.utils.js +42 -0
- package/dist/talkpilot/groups/phone.utils.js.map +1 -0
- package/dist/talkpilot/index.d.ts +19 -0
- package/dist/talkpilot/index.d.ts.map +1 -0
- package/dist/talkpilot/index.js +46 -0
- package/dist/talkpilot/index.js.map +1 -0
- package/dist/talkpilot/leads/index.d.ts +3 -0
- package/dist/talkpilot/leads/index.d.ts.map +1 -0
- package/dist/talkpilot/leads/index.js +6 -0
- package/dist/talkpilot/leads/index.js.map +1 -0
- package/dist/talkpilot/leads/leads.getter.d.ts +4 -0
- package/dist/talkpilot/leads/leads.getter.d.ts.map +1 -0
- package/dist/talkpilot/leads/leads.getter.js +7 -0
- package/dist/talkpilot/leads/leads.getter.js.map +1 -0
- package/dist/talkpilot/leads/leads.schema.d.ts +50 -0
- package/dist/talkpilot/leads/leads.schema.d.ts.map +1 -0
- package/dist/talkpilot/leads/leads.schema.js +37 -0
- package/dist/talkpilot/leads/leads.schema.js.map +1 -0
- package/dist/talkpilot/leads/leads.types.d.ts +18 -0
- package/dist/talkpilot/leads/leads.types.d.ts.map +1 -0
- package/dist/talkpilot/leads/leads.types.js +3 -0
- package/dist/talkpilot/leads/leads.types.js.map +1 -0
- package/dist/talkpilot/mongodb-client.d.ts +13 -0
- package/dist/talkpilot/mongodb-client.d.ts.map +1 -0
- package/dist/talkpilot/mongodb-client.js +71 -0
- package/dist/talkpilot/mongodb-client.js.map +1 -0
- package/dist/talkpilot/phone_numbers/index.d.ts +3 -0
- package/dist/talkpilot/phone_numbers/index.d.ts.map +1 -0
- package/dist/talkpilot/phone_numbers/index.js +18 -0
- package/dist/talkpilot/phone_numbers/index.js.map +1 -0
- package/dist/talkpilot/phone_numbers/phone_numbers.getter.d.ts +8 -0
- package/dist/talkpilot/phone_numbers/phone_numbers.getter.d.ts.map +1 -0
- package/dist/talkpilot/phone_numbers/phone_numbers.getter.js +44 -0
- package/dist/talkpilot/phone_numbers/phone_numbers.getter.js.map +1 -0
- package/dist/talkpilot/phone_numbers/phone_numbers.schema.d.ts +29 -0
- package/dist/talkpilot/phone_numbers/phone_numbers.schema.d.ts.map +1 -0
- package/dist/talkpilot/phone_numbers/phone_numbers.schema.js +18 -0
- package/dist/talkpilot/phone_numbers/phone_numbers.schema.js.map +1 -0
- package/dist/talkpilot/phone_numbers/phone_numbers.types.d.ts +16 -0
- package/dist/talkpilot/phone_numbers/phone_numbers.types.d.ts.map +1 -0
- package/dist/talkpilot/phone_numbers/phone_numbers.types.js +3 -0
- package/dist/talkpilot/phone_numbers/phone_numbers.types.js.map +1 -0
- package/dist/talkpilot/plans/index.d.ts +3 -0
- package/dist/talkpilot/plans/index.d.ts.map +1 -0
- package/dist/talkpilot/plans/index.js +19 -0
- package/dist/talkpilot/plans/index.js.map +1 -0
- package/dist/talkpilot/plans/plans.getters.d.ts +10 -0
- package/dist/talkpilot/plans/plans.getters.d.ts.map +1 -0
- package/dist/talkpilot/plans/plans.getters.js +103 -0
- package/dist/talkpilot/plans/plans.getters.js.map +1 -0
- package/dist/talkpilot/plans/plans.types.d.ts +53 -0
- package/dist/talkpilot/plans/plans.types.d.ts.map +1 -0
- package/dist/talkpilot/plans/plans.types.js +29 -0
- package/dist/talkpilot/plans/plans.types.js.map +1 -0
- package/dist/talkpilot/results/index.d.ts +3 -0
- package/dist/talkpilot/results/index.d.ts.map +1 -0
- package/dist/talkpilot/results/index.js +6 -0
- package/dist/talkpilot/results/index.js.map +1 -0
- package/dist/talkpilot/results/results.getter.d.ts +7 -0
- package/dist/talkpilot/results/results.getter.d.ts.map +1 -0
- package/dist/talkpilot/results/results.getter.js +26 -0
- package/dist/talkpilot/results/results.getter.js.map +1 -0
- package/dist/talkpilot/results/results.schema.d.ts +35 -0
- package/dist/talkpilot/results/results.schema.d.ts.map +1 -0
- package/dist/talkpilot/results/results.schema.js +29 -0
- package/dist/talkpilot/results/results.schema.js.map +1 -0
- package/dist/talkpilot/results/results.types.d.ts +34 -0
- package/dist/talkpilot/results/results.types.d.ts.map +1 -0
- package/dist/talkpilot/results/results.types.js +3 -0
- package/dist/talkpilot/results/results.types.js.map +1 -0
- package/dist/talkpilot/sessions/index.d.ts +3 -0
- package/dist/talkpilot/sessions/index.d.ts.map +1 -0
- package/dist/talkpilot/sessions/index.js +6 -0
- package/dist/talkpilot/sessions/index.js.map +1 -0
- package/dist/talkpilot/sessions/sessions.getter.d.ts +7 -0
- package/dist/talkpilot/sessions/sessions.getter.d.ts.map +1 -0
- package/dist/talkpilot/sessions/sessions.getter.js +26 -0
- package/dist/talkpilot/sessions/sessions.getter.js.map +1 -0
- package/dist/talkpilot/sessions/sessions.schema.d.ts +53 -0
- package/dist/talkpilot/sessions/sessions.schema.d.ts.map +1 -0
- package/dist/talkpilot/sessions/sessions.schema.js +38 -0
- package/dist/talkpilot/sessions/sessions.schema.js.map +1 -0
- package/dist/talkpilot/sessions/sessions.types.d.ts +22 -0
- package/dist/talkpilot/sessions/sessions.types.d.ts.map +1 -0
- package/dist/talkpilot/sessions/sessions.types.js +3 -0
- package/dist/talkpilot/sessions/sessions.types.js.map +1 -0
- package/dist/talkpilot/subscriptions/index.d.ts +4 -0
- package/dist/talkpilot/subscriptions/index.d.ts.map +1 -0
- package/dist/talkpilot/subscriptions/index.js +20 -0
- package/dist/talkpilot/subscriptions/index.js.map +1 -0
- package/dist/talkpilot/subscriptions/subscriptions.getters.d.ts +13 -0
- package/dist/talkpilot/subscriptions/subscriptions.getters.d.ts.map +1 -0
- package/dist/talkpilot/subscriptions/subscriptions.getters.js +105 -0
- package/dist/talkpilot/subscriptions/subscriptions.getters.js.map +1 -0
- package/dist/talkpilot/subscriptions/subscriptions.getters.utils.d.ts +8 -0
- package/dist/talkpilot/subscriptions/subscriptions.getters.utils.d.ts.map +1 -0
- package/dist/talkpilot/subscriptions/subscriptions.getters.utils.js +27 -0
- package/dist/talkpilot/subscriptions/subscriptions.getters.utils.js.map +1 -0
- package/dist/talkpilot/subscriptions/subscriptions.types.d.ts +50 -0
- package/dist/talkpilot/subscriptions/subscriptions.types.d.ts.map +1 -0
- package/dist/talkpilot/subscriptions/subscriptions.types.js +14 -0
- package/dist/talkpilot/subscriptions/subscriptions.types.js.map +1 -0
- 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/test-utils/db-utils.d.ts +4 -0
- package/dist/test-utils/db-utils.d.ts.map +1 -0
- package/dist/test-utils/db-utils.js +28 -0
- package/dist/test-utils/db-utils.js.map +1 -0
- package/dist/test-utils/factories/index.d.ts +13 -0
- package/dist/test-utils/factories/index.d.ts.map +1 -0
- package/dist/test-utils/factories/index.js +29 -0
- package/dist/test-utils/factories/index.js.map +1 -0
- package/dist/test-utils/factories/municipal/cities.d.ts +5 -0
- package/dist/test-utils/factories/municipal/cities.d.ts.map +1 -0
- package/dist/test-utils/factories/municipal/cities.js +18 -0
- package/dist/test-utils/factories/municipal/cities.js.map +1 -0
- package/dist/test-utils/factories/municipal/departmentsSubjects.d.ts +5 -0
- package/dist/test-utils/factories/municipal/departmentsSubjects.d.ts.map +1 -0
- package/dist/test-utils/factories/municipal/departmentsSubjects.js +27 -0
- package/dist/test-utils/factories/municipal/departmentsSubjects.js.map +1 -0
- package/dist/test-utils/factories/municipal/streets.d.ts +5 -0
- package/dist/test-utils/factories/municipal/streets.d.ts.map +1 -0
- package/dist/test-utils/factories/municipal/streets.js +19 -0
- package/dist/test-utils/factories/municipal/streets.js.map +1 -0
- package/dist/test-utils/factories/municipal/tickets.d.ts +5 -0
- package/dist/test-utils/factories/municipal/tickets.d.ts.map +1 -0
- package/dist/test-utils/factories/municipal/tickets.js +27 -0
- package/dist/test-utils/factories/municipal/tickets.js.map +1 -0
- package/dist/test-utils/factories/talkpilot/agents.d.ts +5 -0
- package/dist/test-utils/factories/talkpilot/agents.d.ts.map +1 -0
- package/dist/test-utils/factories/talkpilot/agents.js +21 -0
- package/dist/test-utils/factories/talkpilot/agents.js.map +1 -0
- package/dist/test-utils/factories/talkpilot/calls.d.ts +6 -0
- package/dist/test-utils/factories/talkpilot/calls.d.ts.map +1 -0
- package/dist/test-utils/factories/talkpilot/calls.js +39 -0
- package/dist/test-utils/factories/talkpilot/calls.js.map +1 -0
- package/dist/test-utils/factories/talkpilot/clientAudioBuffers.d.ts +5 -0
- package/dist/test-utils/factories/talkpilot/clientAudioBuffers.d.ts.map +1 -0
- package/dist/test-utils/factories/talkpilot/clientAudioBuffers.js +18 -0
- package/dist/test-utils/factories/talkpilot/clientAudioBuffers.js.map +1 -0
- package/dist/test-utils/factories/talkpilot/clientsConfig.d.ts +5 -0
- package/dist/test-utils/factories/talkpilot/clientsConfig.d.ts.map +1 -0
- package/dist/test-utils/factories/talkpilot/clientsConfig.js +18 -0
- package/dist/test-utils/factories/talkpilot/clientsConfig.js.map +1 -0
- package/dist/test-utils/factories/talkpilot/flows.d.ts +14 -0
- package/dist/test-utils/factories/talkpilot/flows.d.ts.map +1 -0
- package/dist/test-utils/factories/talkpilot/flows.js +33 -0
- package/dist/test-utils/factories/talkpilot/flows.js.map +1 -0
- package/dist/test-utils/factories/talkpilot/groups.d.ts +6 -0
- package/dist/test-utils/factories/talkpilot/groups.d.ts.map +1 -0
- package/dist/test-utils/factories/talkpilot/groups.js +34 -0
- package/dist/test-utils/factories/talkpilot/groups.js.map +1 -0
- package/dist/test-utils/factories/talkpilot/phone_numbers.d.ts +16 -0
- package/dist/test-utils/factories/talkpilot/phone_numbers.d.ts.map +1 -0
- package/dist/test-utils/factories/talkpilot/phone_numbers.js +20 -0
- package/dist/test-utils/factories/talkpilot/phone_numbers.js.map +1 -0
- package/dist/test-utils/factories/talkpilot/sessions.d.ts +5 -0
- package/dist/test-utils/factories/talkpilot/sessions.d.ts.map +1 -0
- package/dist/test-utils/factories/talkpilot/sessions.js +37 -0
- package/dist/test-utils/factories/talkpilot/sessions.js.map +1 -0
- package/dist/utils/validation.d.ts +7 -0
- package/dist/utils/validation.d.ts.map +1 -0
- package/dist/utils/validation.js +23 -0
- package/dist/utils/validation.js.map +1 -0
- package/jest.config.js +22 -0
- package/package.json +43 -0
- package/src/__tests__/setup.ts +20 -0
- package/src/index.ts +13 -0
- package/src/municipal/__tests__/validation.spec.ts +50 -0
- package/src/municipal/cities/cities.getters.ts +44 -0
- package/src/municipal/cities/cities.types.ts +11 -0
- package/src/municipal/cities/index.ts +2 -0
- package/src/municipal/departmentsSubjects/departmentsSubjects.getters.ts +273 -0
- package/src/municipal/departmentsSubjects/departmentsSubjects.types.ts +76 -0
- package/src/municipal/departmentsSubjects/index.ts +11 -0
- package/src/municipal/index.ts +18 -0
- package/src/municipal/mongodb-client.ts +58 -0
- package/src/municipal/streets/index.ts +2 -0
- package/src/municipal/streets/streets.getters.ts +105 -0
- package/src/municipal/streets/streets.types.ts +18 -0
- package/src/municipal/tickets/__tests__/tickets.getters.spec.ts +30 -0
- package/src/municipal/tickets/index.ts +2 -0
- package/src/municipal/tickets/tickets.getters.ts +234 -0
- package/src/municipal/tickets/tickets.types.ts +39 -0
- package/src/talkpilot/__tests__/db.spec.ts +38 -0
- package/src/talkpilot/__tests__/mongodb-client.spec.ts +19 -0
- package/src/talkpilot/__tests__/validation.spec.ts +62 -0
- package/src/talkpilot/agents/__tests__/agents.getters.spec.ts +29 -0
- package/src/talkpilot/agents/agents.getters.ts +34 -0
- package/src/talkpilot/agents/agents.types.ts +14 -0
- package/src/talkpilot/agents/index.ts +2 -0
- package/src/talkpilot/calls/__tests__/calls.spec.ts +56 -0
- package/src/talkpilot/calls/calls.getters.ts +134 -0
- package/src/talkpilot/calls/calls.types.ts +45 -0
- package/src/talkpilot/calls/index.ts +2 -0
- package/src/talkpilot/clientAudioBuffers/__tests__/clientAudioBuffer.getters.spec.ts +78 -0
- package/src/talkpilot/clientAudioBuffers/clientAudioBuffer.getters.ts +101 -0
- package/src/talkpilot/clientAudioBuffers/clientsAudioBuffers.types.ts +25 -0
- package/src/talkpilot/clients/clients.getters.ts +11 -0
- package/src/talkpilot/clients/clients.types.ts +12 -0
- package/src/talkpilot/clients/index.ts +2 -0
- package/src/talkpilot/clientsConfig/__tests__/clientsConfig.spec.ts +28 -0
- package/src/talkpilot/clientsConfig/clientsConfig.getters.ts +20 -0
- package/src/talkpilot/clientsConfig/clientsConfig.types.ts +55 -0
- package/src/talkpilot/clientsConfig/index.ts +2 -0
- package/src/talkpilot/flows/flows.getter.ts +11 -0
- package/src/talkpilot/flows/flows.schema.ts +90 -0
- package/src/talkpilot/flows/flows.types.ts +151 -0
- package/src/talkpilot/flows/index.ts +2 -0
- package/src/talkpilot/groups/__tests__/groups.spec.ts +83 -0
- package/src/talkpilot/groups/__tests__/phone.utils.spec.ts +32 -0
- package/src/talkpilot/groups/groups.getters.ts +27 -0
- package/src/talkpilot/groups/groups.types.ts +29 -0
- package/src/talkpilot/groups/index.ts +2 -0
- package/src/talkpilot/groups/phone.utils.ts +40 -0
- package/src/talkpilot/index.ts +27 -0
- package/src/talkpilot/leads/index.ts +2 -0
- package/src/talkpilot/leads/leads.getter.ts +5 -0
- package/src/talkpilot/leads/leads.schema.ts +33 -0
- package/src/talkpilot/leads/leads.types.ts +20 -0
- package/src/talkpilot/mongodb-client.ts +78 -0
- package/src/talkpilot/phone_numbers/__tests__/phone_numbers.spec.ts +43 -0
- package/src/talkpilot/phone_numbers/index.ts +2 -0
- package/src/talkpilot/phone_numbers/phone_numbers.getter.ts +47 -0
- package/src/talkpilot/phone_numbers/phone_numbers.schema.ts +14 -0
- package/src/talkpilot/phone_numbers/phone_numbers.types.ts +15 -0
- package/src/talkpilot/plans/index.ts +2 -0
- package/src/talkpilot/plans/plans.getters.ts +121 -0
- package/src/talkpilot/plans/plans.types.ts +84 -0
- package/src/talkpilot/results/index.ts +2 -0
- package/src/talkpilot/results/results.getter.ts +26 -0
- package/src/talkpilot/results/results.schema.ts +25 -0
- package/src/talkpilot/results/results.types.ts +32 -0
- package/src/talkpilot/sessions/__tests__/sessions.spec.ts +43 -0
- package/src/talkpilot/sessions/index.ts +2 -0
- package/src/talkpilot/sessions/sessions.getter.ts +28 -0
- package/src/talkpilot/sessions/sessions.schema.ts +34 -0
- package/src/talkpilot/sessions/sessions.types.ts +28 -0
- package/src/talkpilot/subscriptions/__tests__/subscriptions.getters.utils.spec.ts +42 -0
- package/src/talkpilot/subscriptions/index.ts +3 -0
- package/src/talkpilot/subscriptions/subscriptions.getters.ts +147 -0
- package/src/talkpilot/subscriptions/subscriptions.getters.utils.ts +26 -0
- package/src/talkpilot/subscriptions/subscriptions.types.ts +65 -0
- package/src/test-utils/db-utils.ts +24 -0
- package/src/test-utils/factories/index.ts +12 -0
- package/src/test-utils/factories/municipal/cities.ts +16 -0
- package/src/test-utils/factories/municipal/departmentsSubjects.ts +29 -0
- package/src/test-utils/factories/municipal/streets.ts +17 -0
- package/src/test-utils/factories/municipal/tickets.ts +27 -0
- package/src/test-utils/factories/talkpilot/agents.ts +19 -0
- package/src/test-utils/factories/talkpilot/calls.ts +37 -0
- package/src/test-utils/factories/talkpilot/clientAudioBuffers.ts +18 -0
- package/src/test-utils/factories/talkpilot/clientsConfig.ts +19 -0
- package/src/test-utils/factories/talkpilot/flows.ts +31 -0
- package/src/test-utils/factories/talkpilot/groups.ts +33 -0
- package/src/test-utils/factories/talkpilot/phone_numbers.ts +20 -0
- package/src/test-utils/factories/talkpilot/sessions.ts +35 -0
- package/src/utils/validation.ts +23 -0
- package/tsconfig.json +27 -0
|
@@ -0,0 +1,83 @@
|
|
|
1
|
+
import { ObjectId } from 'mongodb';
|
|
2
|
+
import { faker } from '@faker-js/faker';
|
|
3
|
+
import {
|
|
4
|
+
getGroupsCollection,
|
|
5
|
+
findGroups,
|
|
6
|
+
createGroup,
|
|
7
|
+
updateGroup,
|
|
8
|
+
removeGroup,
|
|
9
|
+
} from '../groups.getters';
|
|
10
|
+
import { createGroup as createGroupDoc } from '../../../test-utils/factories';
|
|
11
|
+
|
|
12
|
+
describe('db.groups', () => {
|
|
13
|
+
describe('getGroupsCollection', () => {
|
|
14
|
+
it('returns the "groups" collection', () => {
|
|
15
|
+
expect(getGroupsCollection().collectionName).toBe('groups');
|
|
16
|
+
});
|
|
17
|
+
});
|
|
18
|
+
|
|
19
|
+
describe('findGroups', () => {
|
|
20
|
+
it('returns groups matching the provided filter', async () => {
|
|
21
|
+
const clientId = faker.string.uuid();
|
|
22
|
+
const g1 = createGroupDoc({ clientId, name: 'Group A' });
|
|
23
|
+
const g2 = createGroupDoc({ clientId, name: 'Group B' });
|
|
24
|
+
const gOther = createGroupDoc({ clientId: faker.string.uuid(), name: 'Group C' });
|
|
25
|
+
|
|
26
|
+
await getGroupsCollection().insertMany([g1, g2, gOther]);
|
|
27
|
+
|
|
28
|
+
const result = await findGroups({ clientId });
|
|
29
|
+
const names = result.map((g) => g.name).sort();
|
|
30
|
+
|
|
31
|
+
expect(result).toHaveLength(2);
|
|
32
|
+
expect(names).toEqual(['Group A', 'Group B']);
|
|
33
|
+
});
|
|
34
|
+
});
|
|
35
|
+
|
|
36
|
+
describe('createGroup', () => {
|
|
37
|
+
it('inserts a group and returns insertedId', async () => {
|
|
38
|
+
const toInsert = createGroupDoc({ name: 'New Group' });
|
|
39
|
+
|
|
40
|
+
const insertedId = await createGroup(toInsert);
|
|
41
|
+
expect(insertedId).toBeInstanceOf(ObjectId);
|
|
42
|
+
|
|
43
|
+
const fromDb = await getGroupsCollection().findOne({ _id: insertedId });
|
|
44
|
+
expect(fromDb?.name).toBe('New Group');
|
|
45
|
+
expect(fromDb?.clientId).toBe(toInsert.clientId);
|
|
46
|
+
});
|
|
47
|
+
});
|
|
48
|
+
|
|
49
|
+
describe('updateGroup', () => {
|
|
50
|
+
it('updates the group and sets updatedAt, returning the updated document', async () => {
|
|
51
|
+
const original = createGroupDoc({ name: 'Before', description: 'Old desc' });
|
|
52
|
+
const { insertedId } = await getGroupsCollection().insertOne(original);
|
|
53
|
+
const before = await getGroupsCollection().findOne({ _id: insertedId });
|
|
54
|
+
|
|
55
|
+
// Add a small delay to ensure updatedAt will be different
|
|
56
|
+
await new Promise((resolve) => setTimeout(resolve, 10));
|
|
57
|
+
|
|
58
|
+
const res = await updateGroup(
|
|
59
|
+
{ _id: insertedId },
|
|
60
|
+
{ name: 'After', description: 'New desc' }
|
|
61
|
+
);
|
|
62
|
+
|
|
63
|
+
expect(res?._id).toEqual(insertedId);
|
|
64
|
+
expect(res?.name).toBe('After');
|
|
65
|
+
expect(res?.description).toBe('New desc');
|
|
66
|
+
expect(new Date(res!.updatedAt).getTime()).toBeGreaterThan(
|
|
67
|
+
new Date(before!.updatedAt).getTime()
|
|
68
|
+
);
|
|
69
|
+
});
|
|
70
|
+
});
|
|
71
|
+
|
|
72
|
+
describe('removeGroup', () => {
|
|
73
|
+
it('removes a group by string id', async () => {
|
|
74
|
+
const { insertedId } = await getGroupsCollection().insertOne(createGroupDoc());
|
|
75
|
+
|
|
76
|
+
const result = await removeGroup(insertedId.toHexString());
|
|
77
|
+
expect(result.deletedCount).toBe(1);
|
|
78
|
+
|
|
79
|
+
const check = await getGroupsCollection().findOne({ _id: insertedId });
|
|
80
|
+
expect(check).toBeNull();
|
|
81
|
+
});
|
|
82
|
+
});
|
|
83
|
+
});
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import { enrichPhoneNumber, isValidE164 } from '../phone.utils';
|
|
2
|
+
|
|
3
|
+
describe('Phone Utilities', () => {
|
|
4
|
+
describe('enrichPhoneNumber', () => {
|
|
5
|
+
it('should enrich Israeli number', () => {
|
|
6
|
+
const result = enrichPhoneNumber('+972507725874');
|
|
7
|
+
expect(result?.e164).toBe('+972507725874');
|
|
8
|
+
expect(result?.region).toBeDefined();
|
|
9
|
+
expect(result?.countryCallingCode).toBe('972');
|
|
10
|
+
});
|
|
11
|
+
|
|
12
|
+
it('should enrich US number', () => {
|
|
13
|
+
const result = enrichPhoneNumber('+12025551234');
|
|
14
|
+
expect(result?.region).toBe('US');
|
|
15
|
+
expect(result?.countryCallingCode).toBe('1');
|
|
16
|
+
});
|
|
17
|
+
|
|
18
|
+
it('should return null for invalid', () => {
|
|
19
|
+
expect(enrichPhoneNumber('invalid')).toBeNull();
|
|
20
|
+
expect(enrichPhoneNumber('0507725874')).toBeNull();
|
|
21
|
+
});
|
|
22
|
+
});
|
|
23
|
+
|
|
24
|
+
describe('isValidE164', () => {
|
|
25
|
+
it('should validate E.164 format', () => {
|
|
26
|
+
expect(isValidE164('+972508832983')).toBe(true);
|
|
27
|
+
expect(isValidE164('+12025551234')).toBe(true);
|
|
28
|
+
expect(isValidE164('0501234567')).toBe(false);
|
|
29
|
+
expect(isValidE164('invalid')).toBe(false);
|
|
30
|
+
});
|
|
31
|
+
});
|
|
32
|
+
});
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import { getDb, ObjectId, Group } from '../index';
|
|
2
|
+
import { Collection, Filter } from 'mongodb';
|
|
3
|
+
|
|
4
|
+
export const getGroupsCollection = (): Collection<Group> => {
|
|
5
|
+
return getDb().collection<Group>('groups');
|
|
6
|
+
};
|
|
7
|
+
|
|
8
|
+
export const findGroups = async (filter: Filter<Group>): Promise<Group[]> => {
|
|
9
|
+
return await getGroupsCollection().find(filter).toArray();
|
|
10
|
+
};
|
|
11
|
+
|
|
12
|
+
export const createGroup = async (group: Group) => {
|
|
13
|
+
const { insertedId } = await getGroupsCollection().insertOne(group);
|
|
14
|
+
return insertedId;
|
|
15
|
+
};
|
|
16
|
+
|
|
17
|
+
export const updateGroup = async (filter: Filter<Group>, data: Partial<Group>) => {
|
|
18
|
+
return await getGroupsCollection().findOneAndUpdate(
|
|
19
|
+
filter,
|
|
20
|
+
{ $set: { ...data, updatedAt: new Date() } },
|
|
21
|
+
{ returnDocument: 'after' }
|
|
22
|
+
);
|
|
23
|
+
};
|
|
24
|
+
|
|
25
|
+
export const removeGroup = async (groupId: string) => {
|
|
26
|
+
return await getGroupsCollection().deleteOne({ _id: new ObjectId(groupId) });
|
|
27
|
+
};
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import { WithId } from 'mongodb';
|
|
2
|
+
export type E164 = `+${string}`;
|
|
3
|
+
export type CountryISO = Uppercase<string>;
|
|
4
|
+
|
|
5
|
+
export type Phone = {
|
|
6
|
+
e164: E164;
|
|
7
|
+
region?: CountryISO;
|
|
8
|
+
countryCallingCode?: string;
|
|
9
|
+
national?: string;
|
|
10
|
+
ext?: string;
|
|
11
|
+
formatted?: string;
|
|
12
|
+
};
|
|
13
|
+
|
|
14
|
+
export type GroupContact = {
|
|
15
|
+
name: string;
|
|
16
|
+
phone: Phone;
|
|
17
|
+
gender: string;
|
|
18
|
+
};
|
|
19
|
+
|
|
20
|
+
export type Group = {
|
|
21
|
+
clientId: string;
|
|
22
|
+
createdAt: Date;
|
|
23
|
+
updatedAt: Date;
|
|
24
|
+
name: string;
|
|
25
|
+
description: string;
|
|
26
|
+
contacts: GroupContact[];
|
|
27
|
+
};
|
|
28
|
+
|
|
29
|
+
export type GroupDoc = WithId<Group>;
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
import { PhoneNumberUtil, PhoneNumberFormat } from 'google-libphonenumber';
|
|
2
|
+
import type { Phone, E164, CountryISO } from './groups.types';
|
|
3
|
+
|
|
4
|
+
const phoneUtil = PhoneNumberUtil.getInstance();
|
|
5
|
+
|
|
6
|
+
export const enrichPhoneNumber = (e164: string): Phone | null => {
|
|
7
|
+
try {
|
|
8
|
+
const phoneNumber = phoneUtil.parse(e164, 'ZZ');
|
|
9
|
+
if (!phoneUtil.isValidNumber(phoneNumber)) {
|
|
10
|
+
return null;
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
const normalizedE164 = phoneUtil.format(phoneNumber, PhoneNumberFormat.E164) as E164;
|
|
14
|
+
const region = phoneUtil.getRegionCodeForNumber(phoneNumber) as CountryISO;
|
|
15
|
+
const countryCallingCode = phoneNumber.getCountryCode()?.toString();
|
|
16
|
+
const national = phoneNumber.getNationalNumber()?.toString();
|
|
17
|
+
const ext = phoneNumber.getExtension() || undefined;
|
|
18
|
+
const formatted = phoneUtil.format(phoneNumber, PhoneNumberFormat.INTERNATIONAL);
|
|
19
|
+
|
|
20
|
+
return {
|
|
21
|
+
e164: normalizedE164,
|
|
22
|
+
region,
|
|
23
|
+
countryCallingCode,
|
|
24
|
+
national,
|
|
25
|
+
ext,
|
|
26
|
+
formatted,
|
|
27
|
+
};
|
|
28
|
+
} catch (error) {
|
|
29
|
+
return null;
|
|
30
|
+
}
|
|
31
|
+
};
|
|
32
|
+
|
|
33
|
+
export const isValidE164 = (e164: string): boolean => {
|
|
34
|
+
try {
|
|
35
|
+
const phoneNumber = phoneUtil.parse(e164, 'ZZ');
|
|
36
|
+
return phoneUtil.isValidNumber(phoneNumber);
|
|
37
|
+
} catch (error) {
|
|
38
|
+
return false;
|
|
39
|
+
}
|
|
40
|
+
};
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import { Db, ObjectId as MongoObjectId } from 'mongodb';
|
|
2
|
+
|
|
3
|
+
export * from './flows';
|
|
4
|
+
export * from './results';
|
|
5
|
+
export * from './sessions';
|
|
6
|
+
export * from './phone_numbers';
|
|
7
|
+
export * from './leads';
|
|
8
|
+
export * from './clients';
|
|
9
|
+
export * from './agents';
|
|
10
|
+
export * from './plans';
|
|
11
|
+
export * from './subscriptions';
|
|
12
|
+
export * from './groups';
|
|
13
|
+
export * from './calls';
|
|
14
|
+
export * from './clientAudioBuffers/clientAudioBuffer.getters';
|
|
15
|
+
export * from './clientsConfig';
|
|
16
|
+
export { mongodbClient } from './mongodb-client';
|
|
17
|
+
|
|
18
|
+
let db: Db;
|
|
19
|
+
export const setDb = (d: Db) => {
|
|
20
|
+
db = d;
|
|
21
|
+
};
|
|
22
|
+
export const getDb = (): Db => {
|
|
23
|
+
if (!db) throw new Error('DB not initialised');
|
|
24
|
+
return db;
|
|
25
|
+
};
|
|
26
|
+
|
|
27
|
+
export const ObjectId = MongoObjectId;
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
export const leadsMongoSchema = {
|
|
2
|
+
bsonType: 'object',
|
|
3
|
+
required: ['flowId', 'clientId', 'createdAt', 'leads'],
|
|
4
|
+
properties: {
|
|
5
|
+
_id: { bsonType: 'objectId' },
|
|
6
|
+
flowId: { bsonType: 'string' },
|
|
7
|
+
clientId: { bsonType: 'string' },
|
|
8
|
+
createdAt: { bsonType: 'date' },
|
|
9
|
+
leads: {
|
|
10
|
+
bsonType: 'array',
|
|
11
|
+
items: {
|
|
12
|
+
bsonType: 'object',
|
|
13
|
+
required: ['callSid', 'timestamp'],
|
|
14
|
+
properties: {
|
|
15
|
+
callSid: { bsonType: 'string' },
|
|
16
|
+
timestamp: { bsonType: 'date' },
|
|
17
|
+
properties: {
|
|
18
|
+
bsonType: 'array',
|
|
19
|
+
items: {
|
|
20
|
+
bsonType: 'object',
|
|
21
|
+
required: ['name', 'value'],
|
|
22
|
+
properties: {
|
|
23
|
+
name: { bsonType: 'string' },
|
|
24
|
+
value: { bsonType: 'string' },
|
|
25
|
+
},
|
|
26
|
+
},
|
|
27
|
+
},
|
|
28
|
+
},
|
|
29
|
+
},
|
|
30
|
+
},
|
|
31
|
+
},
|
|
32
|
+
additionalProperties: false,
|
|
33
|
+
} as const;
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { ObjectId } from 'mongodb';
|
|
2
|
+
|
|
3
|
+
export interface LeadProperty {
|
|
4
|
+
name: string;
|
|
5
|
+
value: string;
|
|
6
|
+
}
|
|
7
|
+
|
|
8
|
+
export interface LeadItem {
|
|
9
|
+
callSid: string;
|
|
10
|
+
timestamp: Date;
|
|
11
|
+
properties?: LeadProperty[];
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
export interface Lead {
|
|
15
|
+
_id?: ObjectId;
|
|
16
|
+
flowId: ObjectId;
|
|
17
|
+
clientId: string;
|
|
18
|
+
createdAt: Date;
|
|
19
|
+
leads: LeadItem[];
|
|
20
|
+
}
|
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
import { MongoClient, Db } from 'mongodb';
|
|
2
|
+
import { setDb } from './index';
|
|
3
|
+
import { validateConfig, validateMongoUri } from '../utils/validation';
|
|
4
|
+
|
|
5
|
+
class MongoDBClient {
|
|
6
|
+
private client: MongoClient | null = null;
|
|
7
|
+
private db: Db | null = null;
|
|
8
|
+
|
|
9
|
+
private extractDatabaseName(uri: string): string | null {
|
|
10
|
+
try {
|
|
11
|
+
const url = new URL(uri);
|
|
12
|
+
const dbName = url.pathname.slice(1);
|
|
13
|
+
return dbName || null;
|
|
14
|
+
} catch {
|
|
15
|
+
return null;
|
|
16
|
+
}
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
async connect(uri?: string, databaseName?: string): Promise<void> {
|
|
20
|
+
if (this.client) {
|
|
21
|
+
return;
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
const mongodbUri = uri || process.env.MONGO_URI || process.env.MONGODB_URI;
|
|
25
|
+
validateConfig('MONGO_URI', mongodbUri);
|
|
26
|
+
validateMongoUri(mongodbUri!);
|
|
27
|
+
|
|
28
|
+
try {
|
|
29
|
+
this.client = new MongoClient(mongodbUri!);
|
|
30
|
+
await this.client.connect();
|
|
31
|
+
|
|
32
|
+
const dbNameFromUri = this.extractDatabaseName(mongodbUri!);
|
|
33
|
+
const dbNameFromEnv = process.env.MONGODB_DB_NAME;
|
|
34
|
+
const dbName = databaseName || dbNameFromUri || dbNameFromEnv;
|
|
35
|
+
|
|
36
|
+
if (!dbName) {
|
|
37
|
+
throw new Error(
|
|
38
|
+
'[core-db] Database name not specified. Please pass databaseName to connect(), ' +
|
|
39
|
+
'add it to the URI, or set MONGODB_DB_NAME.'
|
|
40
|
+
);
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
this.db = this.client.db(dbName);
|
|
44
|
+
setDb(this.db);
|
|
45
|
+
console.info(`[core-db] TalkPilot MongoDB connected: ${dbName}`);
|
|
46
|
+
} catch (error) {
|
|
47
|
+
console.error('[core-db] TalkPilot connection failed', error as Error);
|
|
48
|
+
throw error;
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
async disconnect(): Promise<void> {
|
|
53
|
+
if (this.client) {
|
|
54
|
+
try {
|
|
55
|
+
await this.client.close();
|
|
56
|
+
this.client = null;
|
|
57
|
+
this.db = null;
|
|
58
|
+
console.info('MongoDB disconnected successfully');
|
|
59
|
+
} catch (error) {
|
|
60
|
+
console.error('Error disconnecting from MongoDB', error as Error);
|
|
61
|
+
throw error;
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
getDb(): Db {
|
|
67
|
+
if (!this.db) {
|
|
68
|
+
throw new Error('Database not initialized. Call connect() first.');
|
|
69
|
+
}
|
|
70
|
+
return this.db;
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
isConnected(): boolean {
|
|
74
|
+
return this.client !== null && this.client !== undefined;
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
export const mongodbClient = new MongoDBClient();
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
import {
|
|
2
|
+
getPhoneDataByPhoneNumber,
|
|
3
|
+
getPhoneNumbersCollection,
|
|
4
|
+
getClientPhoneNumber,
|
|
5
|
+
} from '../phone_numbers.getter';
|
|
6
|
+
import { getFlowsCollection } from '../../flows/flows.getter';
|
|
7
|
+
import { createFlow, createPhoneNumber } from '../../../test-utils/factories';
|
|
8
|
+
|
|
9
|
+
describe('db.phoneNumbers', () => {
|
|
10
|
+
describe('getPhoneDataByPhoneNumber', () => {
|
|
11
|
+
it('return phone number data with flow', async () => {
|
|
12
|
+
const flow = createFlow({ clientId: 'test-client-id' });
|
|
13
|
+
const phoneData = createPhoneNumber({ flow_id: flow._id, client_id: 'test-client-id' });
|
|
14
|
+
|
|
15
|
+
await getFlowsCollection().insertOne(flow);
|
|
16
|
+
await getPhoneNumbersCollection().insertOne(phoneData);
|
|
17
|
+
|
|
18
|
+
const result = await getPhoneDataByPhoneNumber(phoneData.phone_number);
|
|
19
|
+
|
|
20
|
+
expect(result).toBeDefined();
|
|
21
|
+
expect(result).toMatchObject({
|
|
22
|
+
client_id: phoneData.client_id,
|
|
23
|
+
phone_number: phoneData.phone_number,
|
|
24
|
+
flow_id: flow._id,
|
|
25
|
+
});
|
|
26
|
+
// Specifically check if the flow was joined correctly
|
|
27
|
+
expect(result?.flow.flowName).toBe(flow.flowName);
|
|
28
|
+
});
|
|
29
|
+
});
|
|
30
|
+
|
|
31
|
+
describe('getClientPhoneNumber', () => {
|
|
32
|
+
it('return phone number by client id', async () => {
|
|
33
|
+
const flow = createFlow();
|
|
34
|
+
const phoneData = createPhoneNumber({ flow_id: flow._id });
|
|
35
|
+
|
|
36
|
+
await getFlowsCollection().insertOne(flow);
|
|
37
|
+
await getPhoneNumbersCollection().insertOne(phoneData);
|
|
38
|
+
|
|
39
|
+
const result = await getClientPhoneNumber(phoneData.client_id);
|
|
40
|
+
expect(result).toBe(phoneData.phone_number);
|
|
41
|
+
});
|
|
42
|
+
});
|
|
43
|
+
});
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
import type { Collection } from 'mongodb';
|
|
2
|
+
import { getDb, ObjectId } from '../index';
|
|
3
|
+
import { findFlowById } from '../flows/flows.getter';
|
|
4
|
+
import type { PhoneNumber, PhoneNumberWithFlow } from './phone_numbers.types';
|
|
5
|
+
|
|
6
|
+
export const getPhoneNumbersCollection = (): Collection<PhoneNumber> =>
|
|
7
|
+
getDb().collection<PhoneNumber>('phone_numbers');
|
|
8
|
+
|
|
9
|
+
export const getPhoneDataByPhoneNumber = async (
|
|
10
|
+
phoneNumber: string
|
|
11
|
+
): Promise<PhoneNumberWithFlow | null> => {
|
|
12
|
+
const phoneData = await getPhoneNumbersCollection().findOne({ phone_number: phoneNumber });
|
|
13
|
+
if (!phoneData) return null;
|
|
14
|
+
const flow = await findFlowById(phoneData.flow_id, phoneData.client_id);
|
|
15
|
+
if (!flow) return null;
|
|
16
|
+
return { ...phoneData, flow };
|
|
17
|
+
};
|
|
18
|
+
|
|
19
|
+
export const getClientPhoneNumber = async (clientId: string): Promise<string | null> => {
|
|
20
|
+
return (await getPhoneNumbersCollection().findOne({ client_id: clientId }))?.phone_number ?? null;
|
|
21
|
+
};
|
|
22
|
+
|
|
23
|
+
export const getClientPhoneData = async (clientId: string): Promise<PhoneNumber | null> => {
|
|
24
|
+
const phoneNumberData = await getPhoneNumbersCollection().findOne({
|
|
25
|
+
client_id: clientId,
|
|
26
|
+
});
|
|
27
|
+
return phoneNumberData;
|
|
28
|
+
};
|
|
29
|
+
|
|
30
|
+
export const createPhoneNumberEntity = async (
|
|
31
|
+
phoneNumber: string,
|
|
32
|
+
flowId: string,
|
|
33
|
+
clientId: string,
|
|
34
|
+
isPrimary = true,
|
|
35
|
+
): Promise<PhoneNumber> => {
|
|
36
|
+
await getPhoneNumbersCollection().insertOne({
|
|
37
|
+
phone_number: phoneNumber,
|
|
38
|
+
flow_id: new ObjectId(flowId),
|
|
39
|
+
client_id: clientId,
|
|
40
|
+
is_primary: isPrimary,
|
|
41
|
+
createdAt: new Date(),
|
|
42
|
+
updatedAt: new Date(),
|
|
43
|
+
});
|
|
44
|
+
const phoneNumberData = await getClientPhoneData(clientId);
|
|
45
|
+
if (!phoneNumberData) throw new Error('Failed to create phoneNumber');
|
|
46
|
+
return phoneNumberData;
|
|
47
|
+
};
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
export const phoneNumbersMongoSchema = {
|
|
2
|
+
bsonType: 'object',
|
|
3
|
+
required: ['client_id', 'flow_id', 'phone_number'],
|
|
4
|
+
properties: {
|
|
5
|
+
_id: { bsonType: 'objectId' },
|
|
6
|
+
client_id: { bsonType: 'string' },
|
|
7
|
+
flow_id: { bsonType: 'string' },
|
|
8
|
+
phone_number: { bsonType: 'string' },
|
|
9
|
+
is_primary: { bsonType: 'bool' },
|
|
10
|
+
createdAt: { bsonType: 'date' },
|
|
11
|
+
updatedAt: { bsonType: 'date' },
|
|
12
|
+
},
|
|
13
|
+
additionalProperties: false,
|
|
14
|
+
} as const;
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { ObjectId, WithId } from "mongodb";
|
|
2
|
+
import { Flow } from "../flows/flows.types";
|
|
3
|
+
|
|
4
|
+
export type PhoneNumber = {
|
|
5
|
+
_id?: ObjectId;
|
|
6
|
+
client_id: string;
|
|
7
|
+
flow_id: ObjectId;
|
|
8
|
+
phone_number: string;
|
|
9
|
+
subscriptionId?: string;
|
|
10
|
+
is_primary: boolean;
|
|
11
|
+
createdAt: Date;
|
|
12
|
+
updatedAt: Date;
|
|
13
|
+
};
|
|
14
|
+
|
|
15
|
+
export type PhoneNumberWithFlow = WithId<PhoneNumber> & { flow: Flow };
|
|
@@ -0,0 +1,121 @@
|
|
|
1
|
+
import { Plan, getDb, PlanDoc, PlanFilter, SimplePlanFilter, PlanQueryOptions } from '../index';
|
|
2
|
+
import { ObjectId, Filter } from 'mongodb';
|
|
3
|
+
|
|
4
|
+
export const getPlansCollection = () => {
|
|
5
|
+
return getDb().collection<Plan>('plans');
|
|
6
|
+
};
|
|
7
|
+
|
|
8
|
+
/**
|
|
9
|
+
* Converts a simple filter to MongoDB query format
|
|
10
|
+
*/
|
|
11
|
+
const buildSimpleQuery = (filter: SimplePlanFilter): Filter<Plan> => {
|
|
12
|
+
const query: Filter<Plan> = {};
|
|
13
|
+
|
|
14
|
+
if (filter._id) {
|
|
15
|
+
query._id = new ObjectId(filter._id);
|
|
16
|
+
}
|
|
17
|
+
if (filter.productKey !== undefined) {
|
|
18
|
+
query.productKey = filter.productKey;
|
|
19
|
+
}
|
|
20
|
+
if (filter.isActive !== undefined) {
|
|
21
|
+
query.isActive = filter.isActive;
|
|
22
|
+
}
|
|
23
|
+
if (filter.currency !== undefined) {
|
|
24
|
+
query.currency = filter.currency;
|
|
25
|
+
}
|
|
26
|
+
if (filter.region !== undefined) {
|
|
27
|
+
query.region = filter.region;
|
|
28
|
+
}
|
|
29
|
+
if (filter.countryCode !== undefined) {
|
|
30
|
+
query.countryCode = filter.countryCode;
|
|
31
|
+
}
|
|
32
|
+
if (filter.originalPlanId !== undefined) {
|
|
33
|
+
query.originalPlanId = filter.originalPlanId;
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
return query;
|
|
37
|
+
};
|
|
38
|
+
|
|
39
|
+
/**
|
|
40
|
+
* Generic function to find plans with flexible filtering
|
|
41
|
+
*/
|
|
42
|
+
export const findPlans = async (
|
|
43
|
+
filter?: PlanFilter,
|
|
44
|
+
options?: PlanQueryOptions
|
|
45
|
+
): Promise<PlanDoc[]> => {
|
|
46
|
+
let query: Filter<Plan> = {};
|
|
47
|
+
|
|
48
|
+
if (filter) {
|
|
49
|
+
// Build the base query from simple filter properties
|
|
50
|
+
const simpleFilter: SimplePlanFilter = {
|
|
51
|
+
_id: filter._id,
|
|
52
|
+
productKey: filter.productKey,
|
|
53
|
+
isActive: filter.isActive,
|
|
54
|
+
currency: filter.currency,
|
|
55
|
+
region: filter.region,
|
|
56
|
+
countryCode: filter.countryCode,
|
|
57
|
+
originalPlanId: filter.originalPlanId,
|
|
58
|
+
};
|
|
59
|
+
|
|
60
|
+
// Apply simple filters if any are present
|
|
61
|
+
const baseQuery = buildSimpleQuery(simpleFilter);
|
|
62
|
+
if (Object.keys(baseQuery).length > 0) {
|
|
63
|
+
query = baseQuery;
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
// Add OR conditions if present
|
|
67
|
+
if (filter.or && filter.or.length > 0) {
|
|
68
|
+
query.$or = filter.or.map(buildSimpleQuery);
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
// Add AND conditions if present
|
|
72
|
+
if (filter.and && filter.and.length > 0) {
|
|
73
|
+
query.$and = filter.and.map(buildSimpleQuery);
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
let queryBuilder = getPlansCollection().find(query);
|
|
78
|
+
|
|
79
|
+
if (options?.sort) {
|
|
80
|
+
queryBuilder = queryBuilder.sort(options.sort);
|
|
81
|
+
}
|
|
82
|
+
if (options?.limit) {
|
|
83
|
+
queryBuilder = queryBuilder.limit(options.limit);
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
return await queryBuilder.toArray();
|
|
87
|
+
};
|
|
88
|
+
|
|
89
|
+
export const createPlanDoc = async (
|
|
90
|
+
planData: Omit<Plan, 'createdAt' | 'updatedAt'>
|
|
91
|
+
): Promise<PlanDoc> => {
|
|
92
|
+
const now = new Date();
|
|
93
|
+
const result = await getPlansCollection().insertOne({
|
|
94
|
+
...planData,
|
|
95
|
+
createdAt: now,
|
|
96
|
+
updatedAt: now,
|
|
97
|
+
});
|
|
98
|
+
|
|
99
|
+
const plans = await findPlans({ _id: result.insertedId });
|
|
100
|
+
if (!plans[0]) throw new Error('Failed to retrieve created plan');
|
|
101
|
+
return plans[0];
|
|
102
|
+
};
|
|
103
|
+
|
|
104
|
+
export const updatePlanDoc = async (
|
|
105
|
+
planId: ObjectId,
|
|
106
|
+
updates: Partial<Pick<Plan, 'isActive'>>
|
|
107
|
+
): Promise<PlanDoc | null> => {
|
|
108
|
+
const result = await getPlansCollection().findOneAndUpdate(
|
|
109
|
+
{ _id: planId },
|
|
110
|
+
{
|
|
111
|
+
$set: {
|
|
112
|
+
...updates,
|
|
113
|
+
updatedAt: new Date(),
|
|
114
|
+
},
|
|
115
|
+
},
|
|
116
|
+
{
|
|
117
|
+
returnDocument: 'after',
|
|
118
|
+
}
|
|
119
|
+
);
|
|
120
|
+
return result;
|
|
121
|
+
};
|