@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,84 @@
|
|
|
1
|
+
import { Sort, ObjectId, WithId } from 'mongodb';
|
|
2
|
+
|
|
3
|
+
export const CURRENCY_CODES = ['ILS', 'USD', 'EUR'] as const;
|
|
4
|
+
export type CurrencyCode = (typeof CURRENCY_CODES)[number];
|
|
5
|
+
|
|
6
|
+
/** Required fields for creating a new plan */
|
|
7
|
+
export const PLAN_REQUIRED_FIELDS = [
|
|
8
|
+
'productKey',
|
|
9
|
+
'name',
|
|
10
|
+
'monthlyCallQuota',
|
|
11
|
+
'currency',
|
|
12
|
+
'priceMonthlyMinor',
|
|
13
|
+
'isActive',
|
|
14
|
+
];
|
|
15
|
+
|
|
16
|
+
/** All allowed fields that can be set/updated on a plan (excluding system fields) */
|
|
17
|
+
export const PLAN_ALLOWED_FIELDS = [
|
|
18
|
+
'productKey',
|
|
19
|
+
'name',
|
|
20
|
+
'monthlyCallQuota',
|
|
21
|
+
'currency',
|
|
22
|
+
'priceMonthlyMinor',
|
|
23
|
+
'region',
|
|
24
|
+
'countryCode',
|
|
25
|
+
'isActive',
|
|
26
|
+
'originalPlanId',
|
|
27
|
+
'tax',
|
|
28
|
+
'metadata',
|
|
29
|
+
'updatedAt',
|
|
30
|
+
];
|
|
31
|
+
|
|
32
|
+
/** Logical product family, like "basic-500". Multiple regional variants can share it. */
|
|
33
|
+
export type ProductKey = 'basic-500' | 'pro-1100' | 'scale-6000' | (string & {});
|
|
34
|
+
|
|
35
|
+
/** Optional targeting to keep variants explicit */
|
|
36
|
+
export type RegionCode = 'IL' | 'EU' | 'US' | (string & {});
|
|
37
|
+
export type CountryCode = 'IL' | 'DE' | 'FR' | 'ES' | 'GB' | (string & {});
|
|
38
|
+
|
|
39
|
+
export type Tax = {
|
|
40
|
+
vatIncluded: boolean;
|
|
41
|
+
vatRatePct: number;
|
|
42
|
+
countryCode?: CountryCode;
|
|
43
|
+
};
|
|
44
|
+
|
|
45
|
+
export type Plan = {
|
|
46
|
+
productKey: ProductKey;
|
|
47
|
+
name: string;
|
|
48
|
+
monthlyCallQuota: number;
|
|
49
|
+
currency: CurrencyCode;
|
|
50
|
+
priceMonthlyMinor: number;
|
|
51
|
+
region?: RegionCode;
|
|
52
|
+
countryCode?: CountryCode;
|
|
53
|
+
isActive: boolean;
|
|
54
|
+
isFree?: boolean;
|
|
55
|
+
createdAt: Date;
|
|
56
|
+
updatedAt: Date;
|
|
57
|
+
originalPlanId?: string;
|
|
58
|
+
tax?: Tax;
|
|
59
|
+
metadata?: Record<string, unknown>;
|
|
60
|
+
};
|
|
61
|
+
|
|
62
|
+
export type SimplePlanFilter = {
|
|
63
|
+
_id?: ObjectId | string;
|
|
64
|
+
productKey?: ProductKey;
|
|
65
|
+
isActive?: boolean;
|
|
66
|
+
currency?: CurrencyCode;
|
|
67
|
+
region?: RegionCode;
|
|
68
|
+
countryCode?: CountryCode;
|
|
69
|
+
originalPlanId?: string;
|
|
70
|
+
};
|
|
71
|
+
|
|
72
|
+
export type PlanFilter = SimplePlanFilter & {
|
|
73
|
+
or?: SimplePlanFilter[];
|
|
74
|
+
and?: SimplePlanFilter[];
|
|
75
|
+
};
|
|
76
|
+
|
|
77
|
+
export type PlanQueryOptions = {
|
|
78
|
+
sort?: Sort;
|
|
79
|
+
limit?: number;
|
|
80
|
+
};
|
|
81
|
+
|
|
82
|
+
// Convenient aliases
|
|
83
|
+
export type PlanDoc = WithId<Plan>;
|
|
84
|
+
export type Plans = PlanDoc[];
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import type { Collection } from 'mongodb';
|
|
2
|
+
import { getDb, ObjectId, Session } from '../index';
|
|
3
|
+
import type { Result } from './results.types';
|
|
4
|
+
|
|
5
|
+
export const getResultsCollection = (): Collection<Result> => getDb().collection<Result>('results');
|
|
6
|
+
|
|
7
|
+
export const createRunId = (): string => {
|
|
8
|
+
return `run_${new ObjectId().toString()}`;
|
|
9
|
+
};
|
|
10
|
+
|
|
11
|
+
export const initializeResultDocument = async (
|
|
12
|
+
clientId: string,
|
|
13
|
+
session?: Session
|
|
14
|
+
): Promise<Result> => {
|
|
15
|
+
const { insertedId } = await getResultsCollection().insertOne({
|
|
16
|
+
runId: createRunId(),
|
|
17
|
+
date: new Date(),
|
|
18
|
+
calls: [],
|
|
19
|
+
sessionId: session ? session._id!.toString() : 'incomingCall',
|
|
20
|
+
sessionName: session ? session.session_name : 'incomingCall',
|
|
21
|
+
clientId,
|
|
22
|
+
});
|
|
23
|
+
const result = await getResultsCollection().findOne({ _id: insertedId });
|
|
24
|
+
if (!result) throw new Error('Failed to initialized result');
|
|
25
|
+
return result;
|
|
26
|
+
};
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
export const resultMongoSchema = {
|
|
2
|
+
bsonType: 'object',
|
|
3
|
+
required: [
|
|
4
|
+
'_id',
|
|
5
|
+
'sessionId',
|
|
6
|
+
'status',
|
|
7
|
+
'callLength',
|
|
8
|
+
'date',
|
|
9
|
+
'userAnswer',
|
|
10
|
+
'systemSessionId',
|
|
11
|
+
'clientId',
|
|
12
|
+
],
|
|
13
|
+
properties: {
|
|
14
|
+
_id: { bsonType: 'objectId' },
|
|
15
|
+
sessionId: { bsonType: 'string' },
|
|
16
|
+
status: { bsonType: 'string' },
|
|
17
|
+
callLength: { bsonType: 'string' },
|
|
18
|
+
date: { bsonType: 'date' },
|
|
19
|
+
userAnswer: { bsonType: 'string' },
|
|
20
|
+
recordingUrl: { bsonType: ['string', 'null'] },
|
|
21
|
+
systemSessionId: { bsonType: 'string' },
|
|
22
|
+
clientId: { bsonType: 'string' },
|
|
23
|
+
},
|
|
24
|
+
additionalProperties: false,
|
|
25
|
+
} as const;
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import { ObjectId } from 'mongodb';
|
|
2
|
+
|
|
3
|
+
export interface Result {
|
|
4
|
+
_id?: ObjectId;
|
|
5
|
+
calls: CallResult[];
|
|
6
|
+
clientId: string;
|
|
7
|
+
date: Date;
|
|
8
|
+
runId: string;
|
|
9
|
+
sessionId: ObjectId | string;
|
|
10
|
+
sessionName: string;
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
export interface CallResult {
|
|
14
|
+
callSid: string;
|
|
15
|
+
status: string;
|
|
16
|
+
date: Date;
|
|
17
|
+
statuses: string[];
|
|
18
|
+
userAnswer: string | null;
|
|
19
|
+
color: string | null;
|
|
20
|
+
name: string | null;
|
|
21
|
+
callLength: string;
|
|
22
|
+
answeredBy: string | null;
|
|
23
|
+
to: string;
|
|
24
|
+
from: string;
|
|
25
|
+
transcription: TranscriptionSegment[];
|
|
26
|
+
flowId: ObjectId | string;
|
|
27
|
+
recordingUrl: string | null;
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
export type TranscriptionSegment =
|
|
31
|
+
| { assistant: string; user?: never }
|
|
32
|
+
| { user: string; assistant?: never };
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
import { findSessionOfIncomingCall, getSessionsCollection } from '../sessions.getter';
|
|
2
|
+
import { getFlowsCollection } from '../../flows/flows.getter';
|
|
3
|
+
import { getPhoneNumbersCollection } from '../../phone_numbers/phone_numbers.getter';
|
|
4
|
+
import { createFlow, createPhoneNumber, createSession } from '../../../test-utils/factories';
|
|
5
|
+
import { faker } from '@faker-js/faker';
|
|
6
|
+
|
|
7
|
+
describe('sessions', () => {
|
|
8
|
+
describe('findSessionOfIncomingCall()', () => {
|
|
9
|
+
it('returns session by incoming phone number', async () => {
|
|
10
|
+
const to = faker.phone.number();
|
|
11
|
+
const from = faker.phone.number();
|
|
12
|
+
const flow = createFlow();
|
|
13
|
+
const phoneNumberData = createPhoneNumber({ phone_number: to, flow_id: flow._id });
|
|
14
|
+
const json = {
|
|
15
|
+
[faker.lorem.word()]: faker.lorem.sentence(),
|
|
16
|
+
[faker.lorem.word()]: faker.number.int(),
|
|
17
|
+
[faker.lorem.word()]: faker.datatype.boolean(),
|
|
18
|
+
[faker.lorem.word()]: faker.internet.email(),
|
|
19
|
+
};
|
|
20
|
+
|
|
21
|
+
const session = createSession({
|
|
22
|
+
flow_id: flow._id,
|
|
23
|
+
phone_numbers: [{ phoneNumber: from, gender: 'male', name: 'yakov' }],
|
|
24
|
+
json,
|
|
25
|
+
});
|
|
26
|
+
|
|
27
|
+
await getFlowsCollection().insertOne(flow);
|
|
28
|
+
await getPhoneNumbersCollection().insertOne(phoneNumberData);
|
|
29
|
+
await getSessionsCollection().insertOne(session);
|
|
30
|
+
|
|
31
|
+
const result = await findSessionOfIncomingCall(from, to);
|
|
32
|
+
expect(result).toBeDefined();
|
|
33
|
+
expect(result?.phone_numbers[0].phoneNumber).toEqual(from);
|
|
34
|
+
expect(result?.flow_id).toEqual(flow._id);
|
|
35
|
+
expect(result?.json).toEqual(json);
|
|
36
|
+
});
|
|
37
|
+
|
|
38
|
+
it('returns null if receiver phone number is not found', async () => {
|
|
39
|
+
const result = await findSessionOfIncomingCall('any-from', 'non-existent-to');
|
|
40
|
+
expect(result).toBeNull();
|
|
41
|
+
});
|
|
42
|
+
});
|
|
43
|
+
});
|
|
@@ -0,0 +1,28 @@
|
|
|
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
|
+
|
|
6
|
+
export const getSessionsCollection = (): Collection<Session> =>
|
|
7
|
+
getDb().collection<Session>('sessions');
|
|
8
|
+
|
|
9
|
+
export const findSessionById = (
|
|
10
|
+
sessionId: ObjectId,
|
|
11
|
+
clientId: string
|
|
12
|
+
): Promise<WithId<Session> | null> => {
|
|
13
|
+
return getSessionsCollection().findOne({ _id: sessionId, clientId: clientId });
|
|
14
|
+
};
|
|
15
|
+
|
|
16
|
+
export const findSessionOfIncomingCall = async (from: string, to: string) => {
|
|
17
|
+
const receiverPhoneData = await getPhoneNumbersCollection().findOne({ phone_number: to });
|
|
18
|
+
if (!receiverPhoneData) {
|
|
19
|
+
return null;
|
|
20
|
+
}
|
|
21
|
+
const session = await getSessionsCollection().findOne({
|
|
22
|
+
flow_id: new ObjectId(receiverPhoneData.flow_id),
|
|
23
|
+
phone_numbers: {
|
|
24
|
+
$elemMatch: { phoneNumber: from },
|
|
25
|
+
},
|
|
26
|
+
});
|
|
27
|
+
return session;
|
|
28
|
+
};
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
export const sessionMongoSchema = {
|
|
2
|
+
bsonType: 'object',
|
|
3
|
+
required: ['session_name'],
|
|
4
|
+
properties: {
|
|
5
|
+
_id: { bsonType: 'objectId' },
|
|
6
|
+
session_name: { bsonType: 'string' },
|
|
7
|
+
company_name: { bsonType: ['string', 'null'] },
|
|
8
|
+
flow_id: { bsonType: ['objectId', 'string', 'null'] },
|
|
9
|
+
metaKeys: {
|
|
10
|
+
bsonType: ['array', 'null'],
|
|
11
|
+
items: {
|
|
12
|
+
bsonType: 'object',
|
|
13
|
+
required: ['key'],
|
|
14
|
+
properties: {
|
|
15
|
+
key: { bsonType: 'string' },
|
|
16
|
+
value: { bsonType: 'string' },
|
|
17
|
+
},
|
|
18
|
+
},
|
|
19
|
+
},
|
|
20
|
+
phone_numbers: {
|
|
21
|
+
bsonType: 'array',
|
|
22
|
+
items: {
|
|
23
|
+
bsonType: 'object',
|
|
24
|
+
required: ['name', 'phoneNumber'],
|
|
25
|
+
properties: {
|
|
26
|
+
name: { bsonType: 'string' },
|
|
27
|
+
phoneNumber: { bsonType: 'string' },
|
|
28
|
+
},
|
|
29
|
+
},
|
|
30
|
+
},
|
|
31
|
+
voice: { bsonType: ['string', 'null'] },
|
|
32
|
+
},
|
|
33
|
+
additionalProperties: false,
|
|
34
|
+
} as const;
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import { ObjectId } from 'mongodb';
|
|
2
|
+
|
|
3
|
+
export type Session = {
|
|
4
|
+
_id?: ObjectId;
|
|
5
|
+
|
|
6
|
+
session_name: string;
|
|
7
|
+
company_name?: string | null;
|
|
8
|
+
flow_id?: ObjectId | string | null;
|
|
9
|
+
clientId: string;
|
|
10
|
+
|
|
11
|
+
metaKeys?: Array<{
|
|
12
|
+
key: string;
|
|
13
|
+
value?: string;
|
|
14
|
+
}> | null;
|
|
15
|
+
|
|
16
|
+
phone_numbers: Array<{
|
|
17
|
+
name: string;
|
|
18
|
+
phoneNumber: string;
|
|
19
|
+
gender: 'male' | 'female';
|
|
20
|
+
}>;
|
|
21
|
+
|
|
22
|
+
voice?: string | null;
|
|
23
|
+
json: Record<string, any> | null;
|
|
24
|
+
|
|
25
|
+
// Timestamps
|
|
26
|
+
createdAt?: Date;
|
|
27
|
+
updatedAt?: Date;
|
|
28
|
+
};
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
import { ObjectId } from 'mongodb';
|
|
2
|
+
import { buildSimpleQuery, buildDateRangeFilter } from '../subscriptions.getters.utils';
|
|
3
|
+
import { SimpleSubscriptionFilter } from '../subscriptions.types';
|
|
4
|
+
|
|
5
|
+
describe('subscriptions.getters.utils', () => {
|
|
6
|
+
describe('buildSimpleQuery', () => {
|
|
7
|
+
it('returns empty query when filter is empty', () => {
|
|
8
|
+
const filter: SimpleSubscriptionFilter = {};
|
|
9
|
+
const result = buildSimpleQuery(filter);
|
|
10
|
+
expect(result).toEqual({});
|
|
11
|
+
});
|
|
12
|
+
|
|
13
|
+
it('converts _id string to ObjectId', () => {
|
|
14
|
+
const id = '507f1f77bcf86cd799439011';
|
|
15
|
+
const filter: SimpleSubscriptionFilter = { _id: id };
|
|
16
|
+
const result = buildSimpleQuery(filter);
|
|
17
|
+
expect(result._id).toBeInstanceOf(ObjectId);
|
|
18
|
+
expect((result._id as ObjectId).toHexString()).toBe(id);
|
|
19
|
+
});
|
|
20
|
+
|
|
21
|
+
it('includes valid simple fields', () => {
|
|
22
|
+
const filter: SimpleSubscriptionFilter = {
|
|
23
|
+
clientId: 'abc',
|
|
24
|
+
isActive: true,
|
|
25
|
+
};
|
|
26
|
+
const result = buildSimpleQuery(filter);
|
|
27
|
+
expect(result).toEqual({ clientId: 'abc', isActive: true });
|
|
28
|
+
});
|
|
29
|
+
});
|
|
30
|
+
|
|
31
|
+
describe('buildDateRangeFilter', () => {
|
|
32
|
+
it('returns a mongo date range filter', () => {
|
|
33
|
+
const from = new Date('2023-01-01');
|
|
34
|
+
const to = new Date('2023-01-02');
|
|
35
|
+
const result = buildDateRangeFilter(from, to);
|
|
36
|
+
expect(result).toEqual({
|
|
37
|
+
$gte: from,
|
|
38
|
+
$lt: to,
|
|
39
|
+
});
|
|
40
|
+
});
|
|
41
|
+
});
|
|
42
|
+
});
|
|
@@ -0,0 +1,147 @@
|
|
|
1
|
+
import { getDb } from '../index';
|
|
2
|
+
import {
|
|
3
|
+
Subscription,
|
|
4
|
+
SubscriptionDoc,
|
|
5
|
+
SimpleSubscriptionFilter,
|
|
6
|
+
SubscriptionFilter,
|
|
7
|
+
SubscriptionQueryOptions,
|
|
8
|
+
} from './subscriptions.types';
|
|
9
|
+
import { ObjectId, Filter } from 'mongodb';
|
|
10
|
+
import { buildSimpleQuery } from './subscriptions.getters.utils';
|
|
11
|
+
|
|
12
|
+
export const getSubscriptionsCollection = () => {
|
|
13
|
+
return getDb().collection<Subscription>('subscriptions');
|
|
14
|
+
};
|
|
15
|
+
|
|
16
|
+
/**
|
|
17
|
+
* A simple filter for Subscription: each field may be a value or a MongoDB operator expression
|
|
18
|
+
*/
|
|
19
|
+
|
|
20
|
+
export const findSubscriptions = async (
|
|
21
|
+
filter?: SubscriptionFilter,
|
|
22
|
+
options?: SubscriptionQueryOptions
|
|
23
|
+
): Promise<SubscriptionDoc[]> => {
|
|
24
|
+
let query: Filter<Subscription> = {};
|
|
25
|
+
|
|
26
|
+
if (filter) {
|
|
27
|
+
const simpleFilter: SimpleSubscriptionFilter = {
|
|
28
|
+
_id: filter._id,
|
|
29
|
+
clientId: filter.clientId,
|
|
30
|
+
planId: filter.planId,
|
|
31
|
+
startDate: filter.startDate,
|
|
32
|
+
endDate: filter.endDate,
|
|
33
|
+
isActive: filter.isActive,
|
|
34
|
+
createdAt: filter.createdAt,
|
|
35
|
+
nextRenewalDate: filter.nextRenewalDate,
|
|
36
|
+
};
|
|
37
|
+
const baseQuery = buildSimpleQuery(simpleFilter);
|
|
38
|
+
if (Object.keys(baseQuery).length > 0) {
|
|
39
|
+
query = baseQuery;
|
|
40
|
+
}
|
|
41
|
+
if (filter.or && filter.or.length > 0) {
|
|
42
|
+
query.$or = filter.or.map(buildSimpleQuery);
|
|
43
|
+
}
|
|
44
|
+
if (filter.and && filter.and.length > 0) {
|
|
45
|
+
query.$and = filter.and.map(buildSimpleQuery);
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
let queryBuilder = getSubscriptionsCollection().find(query);
|
|
50
|
+
if (options?.sort) {
|
|
51
|
+
queryBuilder = queryBuilder.sort(options.sort);
|
|
52
|
+
}
|
|
53
|
+
if (options?.limit) {
|
|
54
|
+
queryBuilder = queryBuilder.limit(options.limit);
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
return await queryBuilder.toArray();
|
|
58
|
+
};
|
|
59
|
+
|
|
60
|
+
export const createSubscriptionDoc = async (
|
|
61
|
+
subscriptionData: Omit<Subscription, 'createdAt' | 'updatedAt'>
|
|
62
|
+
): Promise<SubscriptionDoc> => {
|
|
63
|
+
const now = new Date();
|
|
64
|
+
const result = await getSubscriptionsCollection().insertOne({
|
|
65
|
+
...subscriptionData,
|
|
66
|
+
createdAt: now,
|
|
67
|
+
updatedAt: now,
|
|
68
|
+
});
|
|
69
|
+
|
|
70
|
+
const subscriptions = await findSubscriptions({ _id: result.insertedId });
|
|
71
|
+
if (!subscriptions[0]) throw new Error('Failed to retrieve created subscription');
|
|
72
|
+
return subscriptions[0];
|
|
73
|
+
};
|
|
74
|
+
|
|
75
|
+
export const updateSubscriptionDoc = async (
|
|
76
|
+
subscriptionId: ObjectId,
|
|
77
|
+
updates: Partial<Subscription>
|
|
78
|
+
): Promise<SubscriptionDoc | null> => {
|
|
79
|
+
return await getSubscriptionsCollection().findOneAndUpdate(
|
|
80
|
+
{ _id: subscriptionId },
|
|
81
|
+
{
|
|
82
|
+
$set: {
|
|
83
|
+
...updates,
|
|
84
|
+
updatedAt: new Date(),
|
|
85
|
+
},
|
|
86
|
+
},
|
|
87
|
+
{
|
|
88
|
+
returnDocument: 'after',
|
|
89
|
+
}
|
|
90
|
+
);
|
|
91
|
+
};
|
|
92
|
+
|
|
93
|
+
export const incrementSubscriptionUsage = async (
|
|
94
|
+
subscriptionId: ObjectId,
|
|
95
|
+
amount: number = 1
|
|
96
|
+
): Promise<SubscriptionDoc | null> => {
|
|
97
|
+
const fieldToIncrement = 'cycles.$[activeCycle].usage.usedCalls';
|
|
98
|
+
return await getSubscriptionsCollection().findOneAndUpdate(
|
|
99
|
+
{ _id: subscriptionId, 'cycles.isActive': true },
|
|
100
|
+
{
|
|
101
|
+
$inc: { [fieldToIncrement]: amount },
|
|
102
|
+
$set: { updatedAt: new Date() },
|
|
103
|
+
},
|
|
104
|
+
{
|
|
105
|
+
arrayFilters: [{ 'activeCycle.isActive': true }],
|
|
106
|
+
returnDocument: 'after',
|
|
107
|
+
}
|
|
108
|
+
);
|
|
109
|
+
};
|
|
110
|
+
|
|
111
|
+
export const deactivateCurrentSubscriptionCycle = async (
|
|
112
|
+
subscriptionId: ObjectId,
|
|
113
|
+
nextRenewalDate: Date
|
|
114
|
+
): Promise<void> => {
|
|
115
|
+
await getSubscriptionsCollection().updateOne(
|
|
116
|
+
{ _id: subscriptionId, 'cycles.isActive': true },
|
|
117
|
+
{
|
|
118
|
+
$set: {
|
|
119
|
+
'cycles.$[activeCycle].isActive': false,
|
|
120
|
+
nextRenewalDate: nextRenewalDate,
|
|
121
|
+
updatedAt: new Date(),
|
|
122
|
+
},
|
|
123
|
+
},
|
|
124
|
+
{
|
|
125
|
+
arrayFilters: [{ 'activeCycle.isActive': true }],
|
|
126
|
+
}
|
|
127
|
+
);
|
|
128
|
+
};
|
|
129
|
+
|
|
130
|
+
export const pushNewSubscriptionCycle = async (
|
|
131
|
+
subscriptionId: ObjectId,
|
|
132
|
+
newCycle: Subscription['cycles'][number]
|
|
133
|
+
): Promise<SubscriptionDoc | null> => {
|
|
134
|
+
const result = await getSubscriptionsCollection().findOneAndUpdate(
|
|
135
|
+
{ _id: subscriptionId },
|
|
136
|
+
{
|
|
137
|
+
$push: {
|
|
138
|
+
cycles: newCycle,
|
|
139
|
+
},
|
|
140
|
+
},
|
|
141
|
+
{
|
|
142
|
+
returnDocument: 'after',
|
|
143
|
+
}
|
|
144
|
+
);
|
|
145
|
+
|
|
146
|
+
return result;
|
|
147
|
+
};
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import { ObjectId, Filter } from 'mongodb';
|
|
2
|
+
import { Subscription, SimpleSubscriptionFilter, simpleFields, SimpleField } from '../index';
|
|
3
|
+
|
|
4
|
+
export const buildSimpleQuery = (filter: SimpleSubscriptionFilter): Filter<Subscription> => {
|
|
5
|
+
const query: Filter<Subscription> = {};
|
|
6
|
+
|
|
7
|
+
if (filter._id) {
|
|
8
|
+
query._id = new ObjectId(filter._id);
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
simpleFields.forEach((field: SimpleField) => {
|
|
12
|
+
const val = filter[field];
|
|
13
|
+
if (val !== undefined) {
|
|
14
|
+
query[field] = val as any;
|
|
15
|
+
}
|
|
16
|
+
});
|
|
17
|
+
|
|
18
|
+
return query;
|
|
19
|
+
};
|
|
20
|
+
|
|
21
|
+
export const buildDateRangeFilter = (from: Date, to: Date) => {
|
|
22
|
+
return {
|
|
23
|
+
$gte: from,
|
|
24
|
+
$lt: to,
|
|
25
|
+
};
|
|
26
|
+
};
|
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
import { Filter, ObjectId, WithId, Sort } from 'mongodb';
|
|
2
|
+
import { PlanDoc } from '../plans/plans.types';
|
|
3
|
+
|
|
4
|
+
export type SubscriptionCycle = {
|
|
5
|
+
usage: {
|
|
6
|
+
usedCalls: number;
|
|
7
|
+
};
|
|
8
|
+
startDate: Date;
|
|
9
|
+
endDate: Date;
|
|
10
|
+
cycleNumber: number;
|
|
11
|
+
isActive: boolean;
|
|
12
|
+
};
|
|
13
|
+
|
|
14
|
+
export type Subscription = {
|
|
15
|
+
clientId: string;
|
|
16
|
+
planId: string;
|
|
17
|
+
planSnapshot: PlanDoc;
|
|
18
|
+
startDate: Date;
|
|
19
|
+
endDate?: Date; // optional, if we want to predefine the end date
|
|
20
|
+
isActive: boolean;
|
|
21
|
+
createdAt: Date;
|
|
22
|
+
updatedAt: Date;
|
|
23
|
+
nextRenewalDate: Date;
|
|
24
|
+
cycles: SubscriptionCycle[];
|
|
25
|
+
};
|
|
26
|
+
|
|
27
|
+
export type SubscriptionDoc = WithId<Subscription>;
|
|
28
|
+
export type Subscriptions = SubscriptionDoc[];
|
|
29
|
+
|
|
30
|
+
// Define which Subscription fields we allow in a simple filter
|
|
31
|
+
export const simpleFields = [
|
|
32
|
+
'clientId',
|
|
33
|
+
'planId',
|
|
34
|
+
'startDate',
|
|
35
|
+
'endDate',
|
|
36
|
+
'isActive',
|
|
37
|
+
'createdAt',
|
|
38
|
+
'nextRenewalDate',
|
|
39
|
+
] as const;
|
|
40
|
+
export type SimpleField = (typeof simpleFields)[number];
|
|
41
|
+
|
|
42
|
+
/**
|
|
43
|
+
* A simple filter for Subscription: each field may be a literal or a MongoDB operator
|
|
44
|
+
*/
|
|
45
|
+
export type SimpleSubscriptionFilter = {
|
|
46
|
+
_id?: ObjectId | string;
|
|
47
|
+
} & {
|
|
48
|
+
[K in keyof Subscription]?: Filter<Subscription>[K];
|
|
49
|
+
};
|
|
50
|
+
|
|
51
|
+
/**
|
|
52
|
+
* Composite filter allowing nested OR/AND arrays
|
|
53
|
+
*/
|
|
54
|
+
export type SubscriptionFilter = SimpleSubscriptionFilter & {
|
|
55
|
+
or?: SimpleSubscriptionFilter[];
|
|
56
|
+
and?: SimpleSubscriptionFilter[];
|
|
57
|
+
};
|
|
58
|
+
|
|
59
|
+
/**
|
|
60
|
+
* Query options for sorting and limiting results
|
|
61
|
+
*/
|
|
62
|
+
export type SubscriptionQueryOptions = {
|
|
63
|
+
sort?: Sort;
|
|
64
|
+
limit?: number;
|
|
65
|
+
};
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import { MongoMemoryServer } from 'mongodb-memory-server';
|
|
2
|
+
import { MongoClient, Db } from 'mongodb';
|
|
3
|
+
import { setDb, setMunicipalDataDb } from '../index';
|
|
4
|
+
|
|
5
|
+
let mongoServer: MongoMemoryServer;
|
|
6
|
+
let client: MongoClient;
|
|
7
|
+
|
|
8
|
+
export async function initTestDb(): Promise<Db> {
|
|
9
|
+
mongoServer = await MongoMemoryServer.create({
|
|
10
|
+
instance: { ip: '127.0.0.1' },
|
|
11
|
+
});
|
|
12
|
+
client = new MongoClient(mongoServer.getUri());
|
|
13
|
+
await client.connect();
|
|
14
|
+
const talkpilotDb = client.db();
|
|
15
|
+
const municipalDb = client.db('municipal-data');
|
|
16
|
+
setDb(talkpilotDb);
|
|
17
|
+
setMunicipalDataDb(municipalDb);
|
|
18
|
+
return talkpilotDb;
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
export async function closeTestDb(): Promise<void> {
|
|
22
|
+
if (client) await client.close();
|
|
23
|
+
if (mongoServer) await mongoServer.stop();
|
|
24
|
+
}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
export * from './talkpilot/agents';
|
|
2
|
+
export * from './talkpilot/calls';
|
|
3
|
+
export * from './talkpilot/clientAudioBuffers';
|
|
4
|
+
export * from './talkpilot/clientsConfig';
|
|
5
|
+
export * from './talkpilot/flows';
|
|
6
|
+
export * from './talkpilot/groups';
|
|
7
|
+
export * from './talkpilot/phone_numbers';
|
|
8
|
+
export * from './talkpilot/sessions';
|
|
9
|
+
export * from './municipal/cities';
|
|
10
|
+
export * from './municipal/departmentsSubjects';
|
|
11
|
+
export * from './municipal/streets';
|
|
12
|
+
export * from './municipal/tickets';
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { Factory } from 'fishery';
|
|
2
|
+
import { ObjectId } from 'mongodb';
|
|
3
|
+
import { faker } from '@faker-js/faker';
|
|
4
|
+
import type { City } from '../../../municipal/cities/cities.types';
|
|
5
|
+
|
|
6
|
+
export const cityFactory = Factory.define<City>(() => ({
|
|
7
|
+
_id: new ObjectId(),
|
|
8
|
+
name: faker.location.city().toLowerCase().replace(/\s/g, '_'),
|
|
9
|
+
displayName: faker.location.city(),
|
|
10
|
+
createdAt: new Date(),
|
|
11
|
+
updatedAt: new Date(),
|
|
12
|
+
}));
|
|
13
|
+
|
|
14
|
+
export function createCity(overrides?: Partial<City>): City {
|
|
15
|
+
return cityFactory.build(overrides);
|
|
16
|
+
}
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import { Factory } from 'fishery';
|
|
2
|
+
import { ObjectId } from 'mongodb';
|
|
3
|
+
import { faker } from '@faker-js/faker';
|
|
4
|
+
import type {
|
|
5
|
+
DepartmentSubject,
|
|
6
|
+
CityName,
|
|
7
|
+
} from '../../../municipal/departmentsSubjects/departmentsSubjects.types';
|
|
8
|
+
|
|
9
|
+
const VALID_CITIES: CityName[] = ['ashdod', 'maltar', 'billit', 'hashkelon', 'tests'];
|
|
10
|
+
|
|
11
|
+
export const departmentSubjectFactory = Factory.define<DepartmentSubject>(() => ({
|
|
12
|
+
_id: new ObjectId(),
|
|
13
|
+
createdAt: new Date(),
|
|
14
|
+
updatedAt: new Date(),
|
|
15
|
+
subjectName: faker.lorem.words(2),
|
|
16
|
+
subject_id: faker.string.numeric(4),
|
|
17
|
+
sub_subject_name: faker.lorem.word(),
|
|
18
|
+
sub_subject_id: faker.string.numeric(4),
|
|
19
|
+
descriptions: [faker.lorem.sentence()],
|
|
20
|
+
cityName: faker.helpers.arrayElement(VALID_CITIES),
|
|
21
|
+
guidelines: null,
|
|
22
|
+
instructions: [],
|
|
23
|
+
communications: [],
|
|
24
|
+
sla: faker.number.int({ min: 24, max: 720 }),
|
|
25
|
+
}));
|
|
26
|
+
|
|
27
|
+
export function createDepartmentSubject(overrides?: Partial<DepartmentSubject>): DepartmentSubject {
|
|
28
|
+
return departmentSubjectFactory.build(overrides);
|
|
29
|
+
}
|