@talkpilot/core-db 1.1.19 → 1.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (130) hide show
  1. package/.cursor/rules/development.mdc +65 -65
  2. package/DEVELOPMENT.md +98 -98
  3. package/README.md +160 -160
  4. package/dist/talkpilot/calls/calls.getters.d.ts +2 -1
  5. package/dist/talkpilot/calls/calls.getters.d.ts.map +1 -1
  6. package/dist/talkpilot/calls/calls.getters.js +176 -0
  7. package/dist/talkpilot/calls/calls.getters.js.map +1 -1
  8. package/dist/talkpilot/calls/calls.types.d.ts +48 -0
  9. package/dist/talkpilot/calls/calls.types.d.ts.map +1 -1
  10. package/dist/talkpilot/clientsConfig/clientsConfig.getters.d.ts +1 -0
  11. package/dist/talkpilot/clientsConfig/clientsConfig.getters.d.ts.map +1 -1
  12. package/dist/talkpilot/clientsConfig/clientsConfig.getters.js +13 -0
  13. package/dist/talkpilot/clientsConfig/clientsConfig.getters.js.map +1 -1
  14. package/jest.config.js +19 -19
  15. package/package.json +45 -45
  16. package/src/__tests__/setup.ts +20 -20
  17. package/src/connection.ts +42 -42
  18. package/src/index.ts +16 -16
  19. package/src/municipal/__tests__/validation.spec.ts +62 -62
  20. package/src/municipal/cities/cities.getters.ts +50 -50
  21. package/src/municipal/cities/cities.types.ts +11 -11
  22. package/src/municipal/cities/index.ts +2 -2
  23. package/src/municipal/departmentsSubjects/departmentsSubjects.getters.ts +282 -282
  24. package/src/municipal/departmentsSubjects/departmentsSubjects.types.ts +72 -72
  25. package/src/municipal/departmentsSubjects/index.ts +9 -9
  26. package/src/municipal/index.ts +21 -21
  27. package/src/municipal/mongodb-client.ts +61 -61
  28. package/src/municipal/streets/index.ts +2 -2
  29. package/src/municipal/streets/streets.getters.ts +125 -125
  30. package/src/municipal/streets/streets.types.ts +18 -18
  31. package/src/municipal/systemInstructions/__tests__/getters.spec.ts +113 -113
  32. package/src/municipal/systemInstructions/__tests__/setters.spec.ts +274 -274
  33. package/src/municipal/systemInstructions/index.ts +7 -7
  34. package/src/municipal/systemInstructions/instructions.getters.ts +57 -57
  35. package/src/municipal/systemInstructions/instructions.setters.ts +119 -119
  36. package/src/municipal/systemInstructions/instructions.types.ts +30 -30
  37. package/src/municipal/tickets/__tests__/tickets.getters.spec.ts +66 -66
  38. package/src/municipal/tickets/index.ts +2 -2
  39. package/src/municipal/tickets/tickets.getters.ts +261 -261
  40. package/src/municipal/tickets/tickets.types.ts +43 -43
  41. package/src/municipal/utils/types.ts +11 -11
  42. package/src/talkpilot/__tests__/db.spec.ts +38 -38
  43. package/src/talkpilot/__tests__/mongodb-client.spec.ts +18 -18
  44. package/src/talkpilot/__tests__/validation.spec.ts +68 -68
  45. package/src/talkpilot/agents/__tests__/agents.getters.spec.ts +29 -29
  46. package/src/talkpilot/agents/agents.getters.ts +34 -34
  47. package/src/talkpilot/agents/agents.types.ts +14 -14
  48. package/src/talkpilot/agents/index.ts +2 -2
  49. package/src/talkpilot/backgroundToolResults/__tests__/backgroundToolResults.getters.spec.ts +147 -147
  50. package/src/talkpilot/backgroundToolResults/backgroundToolResults.getters.ts +65 -65
  51. package/src/talkpilot/backgroundToolResults/backgroundToolResults.types.ts +23 -23
  52. package/src/talkpilot/backgroundToolResults/index.ts +2 -2
  53. package/src/talkpilot/calls/__tests__/callStats.utils.spec.ts +128 -128
  54. package/src/talkpilot/calls/__tests__/calls.spec.ts +252 -252
  55. package/src/talkpilot/calls/calls.getters.ts +446 -248
  56. package/src/talkpilot/calls/calls.types.ts +171 -115
  57. package/src/talkpilot/calls/index.ts +2 -2
  58. package/src/talkpilot/clientAudioBuffers/__tests__/clientAudioBuffer.getters.spec.ts +160 -160
  59. package/src/talkpilot/clientAudioBuffers/clientAudioBuffer.getters.ts +117 -117
  60. package/src/talkpilot/clientAudioBuffers/clientsAudioBuffers.types.ts +25 -25
  61. package/src/talkpilot/clientAudioBuffers/index.ts +2 -2
  62. package/src/talkpilot/clients/clients.getters.ts +16 -16
  63. package/src/talkpilot/clients/clients.types.ts +14 -14
  64. package/src/talkpilot/clients/index.ts +2 -2
  65. package/src/talkpilot/clientsConfig/__tests__/clientsConfig.spec.ts +106 -106
  66. package/src/talkpilot/clientsConfig/clientsConfig.getters.ts +44 -22
  67. package/src/talkpilot/clientsConfig/clientsConfig.types.ts +94 -94
  68. package/src/talkpilot/clientsConfig/index.ts +2 -2
  69. package/src/talkpilot/flows/__tests__/flows.schema.spec.ts +67 -67
  70. package/src/talkpilot/flows/flows.getter.ts +14 -14
  71. package/src/talkpilot/flows/flows.schema.ts +153 -153
  72. package/src/talkpilot/flows/flows.types.ts +184 -184
  73. package/src/talkpilot/flows/index.ts +2 -2
  74. package/src/talkpilot/groups/__tests__/groups.spec.ts +90 -90
  75. package/src/talkpilot/groups/__tests__/phone.utils.spec.ts +32 -32
  76. package/src/talkpilot/groups/groups.getters.ts +30 -30
  77. package/src/talkpilot/groups/groups.types.ts +29 -29
  78. package/src/talkpilot/groups/index.ts +3 -3
  79. package/src/talkpilot/groups/phone.utils.ts +46 -46
  80. package/src/talkpilot/index.ts +29 -29
  81. package/src/talkpilot/leads/index.ts +2 -2
  82. package/src/talkpilot/leads/leads.getter.ts +6 -6
  83. package/src/talkpilot/leads/leads.schema.ts +33 -33
  84. package/src/talkpilot/leads/leads.types.ts +20 -20
  85. package/src/talkpilot/mongodb-client.ts +78 -78
  86. package/src/talkpilot/phone_numbers/__tests__/phone_numbers.spec.ts +247 -247
  87. package/src/talkpilot/phone_numbers/index.ts +2 -2
  88. package/src/talkpilot/phone_numbers/phone_numbers.getter.ts +154 -154
  89. package/src/talkpilot/phone_numbers/phone_numbers.schema.ts +17 -17
  90. package/src/talkpilot/phone_numbers/phone_numbers.types.ts +30 -30
  91. package/src/talkpilot/plans/__tests__/plans.spec.ts +70 -70
  92. package/src/talkpilot/plans/index.ts +2 -2
  93. package/src/talkpilot/plans/plans.getters.ts +132 -132
  94. package/src/talkpilot/plans/plans.types.ts +89 -89
  95. package/src/talkpilot/results/index.ts +7 -7
  96. package/src/talkpilot/results/results.getter.ts +35 -35
  97. package/src/talkpilot/results/results.schema.ts +25 -25
  98. package/src/talkpilot/results/results.types.ts +34 -34
  99. package/src/talkpilot/retry_analyze/__tests__/retryAnalyze.getters.spec.ts +156 -156
  100. package/src/talkpilot/retry_analyze/index.ts +2 -2
  101. package/src/talkpilot/retry_analyze/retryAnalyze.getters.ts +75 -75
  102. package/src/talkpilot/retry_analyze/retryAnalyze.types.ts +13 -13
  103. package/src/talkpilot/sessions/__tests__/sessions.spec.ts +147 -147
  104. package/src/talkpilot/sessions/index.ts +2 -2
  105. package/src/talkpilot/sessions/sessions.getter.ts +92 -92
  106. package/src/talkpilot/sessions/sessions.schema.ts +34 -34
  107. package/src/talkpilot/sessions/sessions.types.ts +30 -30
  108. package/src/talkpilot/subscriptions/__tests__/subscriptions.getters.utils.spec.ts +45 -45
  109. package/src/talkpilot/subscriptions/index.ts +3 -3
  110. package/src/talkpilot/subscriptions/subscriptions.getters.ts +146 -146
  111. package/src/talkpilot/subscriptions/subscriptions.getters.utils.ts +33 -33
  112. package/src/talkpilot/subscriptions/subscriptions.types.ts +66 -66
  113. package/src/talkpilot/utils/__tests__/query.utils.spec.ts +49 -49
  114. package/src/talkpilot/utils/query.utils.ts +21 -21
  115. package/src/test-utils/db-utils.ts +24 -24
  116. package/src/test-utils/factories/index.ts +12 -12
  117. package/src/test-utils/factories/municipal/cities.ts +16 -16
  118. package/src/test-utils/factories/municipal/departmentsSubjects.ts +37 -37
  119. package/src/test-utils/factories/municipal/streets.ts +22 -22
  120. package/src/test-utils/factories/municipal/tickets.ts +39 -39
  121. package/src/test-utils/factories/talkpilot/agents.ts +19 -19
  122. package/src/test-utils/factories/talkpilot/calls.ts +37 -37
  123. package/src/test-utils/factories/talkpilot/clientAudioBuffers.ts +20 -20
  124. package/src/test-utils/factories/talkpilot/clientsConfig.ts +18 -18
  125. package/src/test-utils/factories/talkpilot/flows.ts +33 -33
  126. package/src/test-utils/factories/talkpilot/groups.ts +33 -33
  127. package/src/test-utils/factories/talkpilot/phone_numbers.ts +22 -22
  128. package/src/test-utils/factories/talkpilot/sessions.ts +35 -35
  129. package/src/utils/validation.ts +23 -23
  130. package/tsconfig.json +23 -23
@@ -1,65 +1,65 @@
1
- ---
2
- description: Development standards and conventions for the core-db package
3
- globs: src/**/*.ts
4
- alwaysApply: true
5
- ---
6
-
7
- # Development Standards
8
-
9
- This package provides a centralized database layer for multiple domains (TalkPilot and Municipal). Follow these rules to maintain consistency and reliability.
10
-
11
- ## Project Structure
12
-
13
- - **`src/talkpilot/`**: All database logic, types, and getters related to the TalkPilot domain.
14
- - **`src/municipal/`**: All database logic, types, and getters related to the Municipal Data domain.
15
- - **`src/test-utils/`**: Shared testing infrastructure, including factories and database utilities.
16
-
17
- ## Database Connection Pattern
18
-
19
- Each domain is isolated. They have their own `db` instance and must be connected independently.
20
-
21
- ```typescript
22
- import { mongodbClient, municipalDataMongodbClient } from '@talkpilot/core-db';
23
-
24
- // TalkPilot
25
- await mongodbClient.connect(uri);
26
-
27
- // Municipal
28
- await municipalDataMongodbClient.connect(uri);
29
- ```
30
-
31
- ## Creating New Getters
32
-
33
- 1. **Location**: Place getters in the relevant domain folder (e.g., `src/talkpilot/agents/agents.getters.ts`).
34
- 2. **Naming**: Use `find...` for multiple results and `get...ById` for single results.
35
- 3. **Domain isolation**: Always use the `getDb()` function from the current domain's `index.ts`.
36
-
37
- ## Environment Validation
38
-
39
- Always validate configuration "on-demand" within the `connect` methods using the validation utilities.
40
-
41
- ```typescript
42
- import { validateConfig, validateMongoUri } from '../utils/validation';
43
-
44
- async connect(uri?: string) {
45
- const mongodbUri = uri || process.env.MONGO_URI;
46
- validateConfig('MONGO_URI', mongodbUri);
47
- validateMongoUri(mongodbUri!);
48
- // ... connection logic
49
- }
50
- ```
51
-
52
- ## Testing Standards
53
-
54
- 1. **In-Memory DB**: Use `mongodb-memory-server` for all tests. It is automatically initialized in `src/__tests__/setup.ts`.
55
- 2. **Factories**: Use the Fishery factories in `src/test-utils/factories/` to generate test data.
56
- 3. **Organization**: Place tests in a `__tests__` folder within the relevant domain.
57
-
58
- ```typescript
59
- import { createAgent } from '../../../test-utils/factories';
60
-
61
- it('should find agents', async () => {
62
- const agent = createAgent({ name: 'Test' });
63
- // ... test logic
64
- });
65
- ```
1
+ ---
2
+ description: Development standards and conventions for the core-db package
3
+ globs: src/**/*.ts
4
+ alwaysApply: true
5
+ ---
6
+
7
+ # Development Standards
8
+
9
+ This package provides a centralized database layer for multiple domains (TalkPilot and Municipal). Follow these rules to maintain consistency and reliability.
10
+
11
+ ## Project Structure
12
+
13
+ - **`src/talkpilot/`**: All database logic, types, and getters related to the TalkPilot domain.
14
+ - **`src/municipal/`**: All database logic, types, and getters related to the Municipal Data domain.
15
+ - **`src/test-utils/`**: Shared testing infrastructure, including factories and database utilities.
16
+
17
+ ## Database Connection Pattern
18
+
19
+ Each domain is isolated. They have their own `db` instance and must be connected independently.
20
+
21
+ ```typescript
22
+ import { mongodbClient, municipalDataMongodbClient } from '@talkpilot/core-db';
23
+
24
+ // TalkPilot
25
+ await mongodbClient.connect(uri);
26
+
27
+ // Municipal
28
+ await municipalDataMongodbClient.connect(uri);
29
+ ```
30
+
31
+ ## Creating New Getters
32
+
33
+ 1. **Location**: Place getters in the relevant domain folder (e.g., `src/talkpilot/agents/agents.getters.ts`).
34
+ 2. **Naming**: Use `find...` for multiple results and `get...ById` for single results.
35
+ 3. **Domain isolation**: Always use the `getDb()` function from the current domain's `index.ts`.
36
+
37
+ ## Environment Validation
38
+
39
+ Always validate configuration "on-demand" within the `connect` methods using the validation utilities.
40
+
41
+ ```typescript
42
+ import { validateConfig, validateMongoUri } from '../utils/validation';
43
+
44
+ async connect(uri?: string) {
45
+ const mongodbUri = uri || process.env.MONGO_URI;
46
+ validateConfig('MONGO_URI', mongodbUri);
47
+ validateMongoUri(mongodbUri!);
48
+ // ... connection logic
49
+ }
50
+ ```
51
+
52
+ ## Testing Standards
53
+
54
+ 1. **In-Memory DB**: Use `mongodb-memory-server` for all tests. It is automatically initialized in `src/__tests__/setup.ts`.
55
+ 2. **Factories**: Use the Fishery factories in `src/test-utils/factories/` to generate test data.
56
+ 3. **Organization**: Place tests in a `__tests__` folder within the relevant domain.
57
+
58
+ ```typescript
59
+ import { createAgent } from '../../../test-utils/factories';
60
+
61
+ it('should find agents', async () => {
62
+ const agent = createAgent({ name: 'Test' });
63
+ // ... test logic
64
+ });
65
+ ```
package/DEVELOPMENT.md CHANGED
@@ -1,98 +1,98 @@
1
- # Development Guide
2
-
3
- Welcome to the `core-db` development guide. This document explains how to set up, develop, and test this package.
4
-
5
- ## Getting Started
6
-
7
- ### Prerequisites
8
-
9
- - Node.js (v18 or later)
10
- - TypeScript
11
-
12
- ### Setup
13
-
14
- 1. Install dependencies:
15
- ```bash
16
- npm install
17
- ```
18
-
19
- 2. Build the project:
20
- ```bash
21
- npm run build
22
- ```
23
-
24
- ## Local Development
25
-
26
- If you want to use this package in another project locally without publishing it:
27
-
28
- 1. In the `core-db` folder:
29
- ```bash
30
- npm link
31
- ```
32
-
33
- 2. In your PROJECT folder:
34
- ```bash
35
- npm link @talkpilot/core-db
36
- ```
37
-
38
- ## Adding a New Getter
39
-
40
- 1. **Define Types**: Add your data types in the relevant domain's `types.ts` file.
41
- 2. **Implement Getter**: Add the function in the `getters.ts` file.
42
- 3. **Export**: Ensure the getter is exported from the domain's `index.ts` and finally from the main `src/index.ts`.
43
- 4. **Test**: Create a test in the domain's `__tests__` folder.
44
-
45
- ## Testing
46
-
47
- We use Jest with `mongodb-memory-server` for fast, isolated database tests.
48
-
49
- ### Running Tests
50
-
51
- ```bash
52
- npm test
53
- ```
54
-
55
- ### Using Factories
56
-
57
- Always use factories to generate test data to keep tests clean and maintainable.
58
-
59
- ```typescript
60
- import { createCallDoc } from '../calls.getters';
61
- import { createOutGoingCallDoc } from '../../../test-utils/factories';
62
-
63
- it('should save a call', async () => {
64
- const call = createOutGoingCallDoc({ callSid: 'CA123' });
65
- await createCallDoc(call);
66
- // ... assertions
67
- });
68
- ```
69
-
70
- ## Build Process
71
-
72
- The project is built using TypeScript (`tsc`). The output is generated in the `dist/` directory.
73
-
74
- - `main`: `dist/index.js`
75
- - `types`: `dist/index.d.ts`
76
-
77
- The `prepare` script in `package.json` ensures that the project is built automatically when installed via a Git URL.
78
-
79
- ## Team Access & Authentication
80
-
81
- To allow the whole team to publish and install without adding individual npm accounts, we use a shared **npm Granular Access Token**.
82
-
83
- ### One-time Local Setup
84
-
85
- Each developer needs to add the shared token to their local npm configuration. Do **NOT** add this to the project's `.npmrc` file, as it will be committed to Git.
86
-
87
- 1. Get the shared **npm Automation Token**.
88
- 2. Open (or create) your global npm configuration file:
89
- ```bash
90
- nano ~/.npmrc
91
- ```
92
- 3. Add the following line (replace `[TOKEN]` with the actual token):
93
- ```text
94
- //registry.npmjs.org/:_authToken=[TOKEN]
95
- ```
96
- 4. Save and exit.
97
-
98
- Now you can run `npm publish` and `npm install` for scoped `@talkpilot` packages without being prompted for credentials.
1
+ # Development Guide
2
+
3
+ Welcome to the `core-db` development guide. This document explains how to set up, develop, and test this package.
4
+
5
+ ## Getting Started
6
+
7
+ ### Prerequisites
8
+
9
+ - Node.js (v18 or later)
10
+ - TypeScript
11
+
12
+ ### Setup
13
+
14
+ 1. Install dependencies:
15
+ ```bash
16
+ npm install
17
+ ```
18
+
19
+ 2. Build the project:
20
+ ```bash
21
+ npm run build
22
+ ```
23
+
24
+ ## Local Development
25
+
26
+ If you want to use this package in another project locally without publishing it:
27
+
28
+ 1. In the `core-db` folder:
29
+ ```bash
30
+ npm link
31
+ ```
32
+
33
+ 2. In your PROJECT folder:
34
+ ```bash
35
+ npm link @talkpilot/core-db
36
+ ```
37
+
38
+ ## Adding a New Getter
39
+
40
+ 1. **Define Types**: Add your data types in the relevant domain's `types.ts` file.
41
+ 2. **Implement Getter**: Add the function in the `getters.ts` file.
42
+ 3. **Export**: Ensure the getter is exported from the domain's `index.ts` and finally from the main `src/index.ts`.
43
+ 4. **Test**: Create a test in the domain's `__tests__` folder.
44
+
45
+ ## Testing
46
+
47
+ We use Jest with `mongodb-memory-server` for fast, isolated database tests.
48
+
49
+ ### Running Tests
50
+
51
+ ```bash
52
+ npm test
53
+ ```
54
+
55
+ ### Using Factories
56
+
57
+ Always use factories to generate test data to keep tests clean and maintainable.
58
+
59
+ ```typescript
60
+ import { createCallDoc } from '../calls.getters';
61
+ import { createOutGoingCallDoc } from '../../../test-utils/factories';
62
+
63
+ it('should save a call', async () => {
64
+ const call = createOutGoingCallDoc({ callSid: 'CA123' });
65
+ await createCallDoc(call);
66
+ // ... assertions
67
+ });
68
+ ```
69
+
70
+ ## Build Process
71
+
72
+ The project is built using TypeScript (`tsc`). The output is generated in the `dist/` directory.
73
+
74
+ - `main`: `dist/index.js`
75
+ - `types`: `dist/index.d.ts`
76
+
77
+ The `prepare` script in `package.json` ensures that the project is built automatically when installed via a Git URL.
78
+
79
+ ## Team Access & Authentication
80
+
81
+ To allow the whole team to publish and install without adding individual npm accounts, we use a shared **npm Granular Access Token**.
82
+
83
+ ### One-time Local Setup
84
+
85
+ Each developer needs to add the shared token to their local npm configuration. Do **NOT** add this to the project's `.npmrc` file, as it will be committed to Git.
86
+
87
+ 1. Get the shared **npm Automation Token**.
88
+ 2. Open (or create) your global npm configuration file:
89
+ ```bash
90
+ nano ~/.npmrc
91
+ ```
92
+ 3. Add the following line (replace `[TOKEN]` with the actual token):
93
+ ```text
94
+ //registry.npmjs.org/:_authToken=[TOKEN]
95
+ ```
96
+ 4. Save and exit.
97
+
98
+ Now you can run `npm publish` and `npm install` for scoped `@talkpilot` packages without being prompted for credentials.
package/README.md CHANGED
@@ -1,160 +1,160 @@
1
- # @talkpilot/core-db
2
-
3
- [NPM Version](https://www.npmjs.com/package/@talkpilot/core-db)
4
-
5
- A TypeScript-based core database management package designed to provide centralized database connections, ORM integrations, and client utilities for other projects. This package manages connections to both **TalkPilot** and **Municipal** MongoDB databases.
6
-
7
- ## Features
8
-
9
- - 🚀 **Multi-Domain Database Management**: Centralized handlers for both TalkPilot and Municipal Data domains.
10
- - 📦 **Reusable Getters**: Standardized functions for fetching data from various collections (calls, agents, leads, cities, etc.).
11
- - 🏗️ **Type-safe**: Built with TypeScript for full type safety across all your database interactions.
12
- - 🛠️ **Environment Aware**: Configurable via environment variables or explicit parameters.
13
-
14
- ## Installation
15
-
16
- This package is intended to be used as a dependency in other projects. If you're working locally, you can install it using a file path:
17
-
18
- ```bash
19
- # In your other project:
20
- npm install /path/to/core-db
21
- # or if published to a registry:
22
- npm install @talkpilot/core-db
23
- # or via GitHub
24
- npm install github:talkpilot/core-db
25
- ```
26
-
27
- ## Quick Start
28
-
29
- ### 1. Initialize Database Connections
30
-
31
- You must initialize the database clients before using any of the getters.
32
-
33
- ```typescript
34
- import { mongodbClient, municipalDataMongodbClient } from '@talkpilot/core-db';
35
-
36
- async function bootstrap() {
37
- // Initialize TalkPilot DB
38
- await mongodbClient.connect(process.env.TALKPILOT_MONGO_URI);
39
-
40
- // Initialize Municipal Data DB (optional)
41
- await municipalDataMongodbClient.connect(process.env.MUNICIPAL_MONGO_URI);
42
- }
43
-
44
- bootstrap().catch(console.error);
45
- ```
46
-
47
- ### 2. Using Getters
48
-
49
- Once initialized, you can import and use any of the exported database getters.
50
-
51
- ```typescript
52
- import { findAgents, findCities } from '@talkpilot/core-db';
53
-
54
- async function getSummary() {
55
- // Get all agents from TalkPilot DB
56
- const agents = await findAgents();
57
- console.log('Total Agents:', agents.length);
58
-
59
- // Get all cities from Municipal Data DB
60
- const cities = await findCities();
61
- console.log('Total Cities:', cities.length);
62
- }
63
- ```
64
-
65
- ## Available Domains
66
-
67
- The package exports two main sets of tools:
68
-
69
- ### TalkPilot Domain
70
-
71
- Includes access to:
72
-
73
- - `agents`, `calls`, `clients`, `flows`, `leads`, `phone_numbers`, `plans`, `results`, `sessions`, `subscriptions`, etc.
74
- - Exported as root level functions or via `mongodbClient`.
75
-
76
- ### Municipal Domain
77
-
78
- Includes access to:
79
-
80
- - `cities`, `streets`, `departmentsSubjects`, `tickets`.
81
- - Functions are prefixed where necessary or accessible via `getMunicipalDataDb`.
82
-
83
- ## Environment Variables
84
-
85
- The clients will automatically attempt to use the following environment variables if no URI is provided to the `connect()` method:
86
-
87
- - `MONGO_URI` or `MONGODB_URI`: Primary MongoDB connection string.
88
- - `MONGODB_DB_NAME`: Database name (defaults to 'municipal-data' for the municipal client if not specified).
89
-
90
- ## Development
91
-
92
- ### Setup
93
-
94
- 1. Clone the repository and install dependencies:
95
- ```bash
96
- git clone https://github.com/talkpilot/core-db.git
97
- cd core-db
98
- npm install
99
- ```
100
- 2. Build the project:
101
- ```bash
102
- npm run build
103
- ```
104
-
105
- This will generate the `dist/` directory with the compiled JavaScript and type definitions.
106
-
107
- ### Publishing New Versions
108
-
109
- To publish a new version of the package:
110
-
111
- 1. **Test your changes**:
112
- ```bash
113
- npm test
114
- ```
115
- 2. **Update the version**:
116
- ```bash
117
- # Bumps patch version (0.1.0 -> 0.1.1)
118
- npm version patch
119
- # Or for minor changes (0.1.0 -> 0.2.0)
120
- # npm version minor
121
- # Or for major changes (0.1.0 -> 1.0.0)
122
- # npm version major
123
- ```
124
- 3. **Publish to npm**:
125
- Ensure you have the shared team token in your `~/.npmrc` (see [Development Guide](./DEVELOPMENT.md#team-access--authentication)).
126
- 4. **Update in other repos**:
127
- ```bash
128
- npm update @talkpilot/core-db
129
- ```
130
-
131
- ## License
132
-
133
- MIT
134
-
135
- ---
136
-
137
- **Interested in contributing?** Check out our [Development Guide](./DEVELOPMENT.md) for standards and setup instructions.
138
-
139
- ## Release Notes
140
-
141
- ### 1.1.9
142
-
143
- - `getPhoneNumbersForFlows(clientId)` — lists each phone number linked to a flow for that client (newest first), with `flowId`, `phoneNumber`, and `isPrimary`.
144
- ### 1.1.5
145
-
146
- - `createPurchasedPhoneNumber` for API-bought numbers (Twilio/Telnyx metadata); optional `flowId` until linked to a flow. Types/schema updated accordingly.
147
-
148
- ### 1.0.16
149
-
150
- - Fixed critical issues present in version 1.0.15.
151
- - **Warning**: Version 1.0.15 is bugged and should not be used. Please use at least version 1.0.16.
152
-
153
- ### 1.0.20
154
-
155
- - Added to Moked106Config this param: withNeedAttentionCalls
156
- - withNeedAttentionCalls?: boolean
157
-
158
- ### 1.0.27
159
- - Added an optional `language` field to `ClientConfig` (e.g. Hebrew/English/Russian/French/Spanish) and updated tests.
160
-
1
+ # @talkpilot/core-db
2
+
3
+ [NPM Version](https://www.npmjs.com/package/@talkpilot/core-db)
4
+
5
+ A TypeScript-based core database management package designed to provide centralized database connections, ORM integrations, and client utilities for other projects. This package manages connections to both **TalkPilot** and **Municipal** MongoDB databases.
6
+
7
+ ## Features
8
+
9
+ - 🚀 **Multi-Domain Database Management**: Centralized handlers for both TalkPilot and Municipal Data domains.
10
+ - 📦 **Reusable Getters**: Standardized functions for fetching data from various collections (calls, agents, leads, cities, etc.).
11
+ - 🏗️ **Type-safe**: Built with TypeScript for full type safety across all your database interactions.
12
+ - 🛠️ **Environment Aware**: Configurable via environment variables or explicit parameters.
13
+
14
+ ## Installation
15
+
16
+ This package is intended to be used as a dependency in other projects. If you're working locally, you can install it using a file path:
17
+
18
+ ```bash
19
+ # In your other project:
20
+ npm install /path/to/core-db
21
+ # or if published to a registry:
22
+ npm install @talkpilot/core-db
23
+ # or via GitHub
24
+ npm install github:talkpilot/core-db
25
+ ```
26
+
27
+ ## Quick Start
28
+
29
+ ### 1. Initialize Database Connections
30
+
31
+ You must initialize the database clients before using any of the getters.
32
+
33
+ ```typescript
34
+ import { mongodbClient, municipalDataMongodbClient } from '@talkpilot/core-db';
35
+
36
+ async function bootstrap() {
37
+ // Initialize TalkPilot DB
38
+ await mongodbClient.connect(process.env.TALKPILOT_MONGO_URI);
39
+
40
+ // Initialize Municipal Data DB (optional)
41
+ await municipalDataMongodbClient.connect(process.env.MUNICIPAL_MONGO_URI);
42
+ }
43
+
44
+ bootstrap().catch(console.error);
45
+ ```
46
+
47
+ ### 2. Using Getters
48
+
49
+ Once initialized, you can import and use any of the exported database getters.
50
+
51
+ ```typescript
52
+ import { findAgents, findCities } from '@talkpilot/core-db';
53
+
54
+ async function getSummary() {
55
+ // Get all agents from TalkPilot DB
56
+ const agents = await findAgents();
57
+ console.log('Total Agents:', agents.length);
58
+
59
+ // Get all cities from Municipal Data DB
60
+ const cities = await findCities();
61
+ console.log('Total Cities:', cities.length);
62
+ }
63
+ ```
64
+
65
+ ## Available Domains
66
+
67
+ The package exports two main sets of tools:
68
+
69
+ ### TalkPilot Domain
70
+
71
+ Includes access to:
72
+
73
+ - `agents`, `calls`, `clients`, `flows`, `leads`, `phone_numbers`, `plans`, `results`, `sessions`, `subscriptions`, etc.
74
+ - Exported as root level functions or via `mongodbClient`.
75
+
76
+ ### Municipal Domain
77
+
78
+ Includes access to:
79
+
80
+ - `cities`, `streets`, `departmentsSubjects`, `tickets`.
81
+ - Functions are prefixed where necessary or accessible via `getMunicipalDataDb`.
82
+
83
+ ## Environment Variables
84
+
85
+ The clients will automatically attempt to use the following environment variables if no URI is provided to the `connect()` method:
86
+
87
+ - `MONGO_URI` or `MONGODB_URI`: Primary MongoDB connection string.
88
+ - `MONGODB_DB_NAME`: Database name (defaults to 'municipal-data' for the municipal client if not specified).
89
+
90
+ ## Development
91
+
92
+ ### Setup
93
+
94
+ 1. Clone the repository and install dependencies:
95
+ ```bash
96
+ git clone https://github.com/talkpilot/core-db.git
97
+ cd core-db
98
+ npm install
99
+ ```
100
+ 2. Build the project:
101
+ ```bash
102
+ npm run build
103
+ ```
104
+
105
+ This will generate the `dist/` directory with the compiled JavaScript and type definitions.
106
+
107
+ ### Publishing New Versions
108
+
109
+ To publish a new version of the package:
110
+
111
+ 1. **Test your changes**:
112
+ ```bash
113
+ npm test
114
+ ```
115
+ 2. **Update the version**:
116
+ ```bash
117
+ # Bumps patch version (0.1.0 -> 0.1.1)
118
+ npm version patch
119
+ # Or for minor changes (0.1.0 -> 0.2.0)
120
+ # npm version minor
121
+ # Or for major changes (0.1.0 -> 1.0.0)
122
+ # npm version major
123
+ ```
124
+ 3. **Publish to npm**:
125
+ Ensure you have the shared team token in your `~/.npmrc` (see [Development Guide](./DEVELOPMENT.md#team-access--authentication)).
126
+ 4. **Update in other repos**:
127
+ ```bash
128
+ npm update @talkpilot/core-db
129
+ ```
130
+
131
+ ## License
132
+
133
+ MIT
134
+
135
+ ---
136
+
137
+ **Interested in contributing?** Check out our [Development Guide](./DEVELOPMENT.md) for standards and setup instructions.
138
+
139
+ ## Release Notes
140
+
141
+ ### 1.1.9
142
+
143
+ - `getPhoneNumbersForFlows(clientId)` — lists each phone number linked to a flow for that client (newest first), with `flowId`, `phoneNumber`, and `isPrimary`.
144
+ ### 1.1.5
145
+
146
+ - `createPurchasedPhoneNumber` for API-bought numbers (Twilio/Telnyx metadata); optional `flowId` until linked to a flow. Types/schema updated accordingly.
147
+
148
+ ### 1.0.16
149
+
150
+ - Fixed critical issues present in version 1.0.15.
151
+ - **Warning**: Version 1.0.15 is bugged and should not be used. Please use at least version 1.0.16.
152
+
153
+ ### 1.0.20
154
+
155
+ - Added to Moked106Config this param: withNeedAttentionCalls
156
+ - withNeedAttentionCalls?: boolean
157
+
158
+ ### 1.0.27
159
+ - Added an optional `language` field to `ClientConfig` (e.g. Hebrew/English/Russian/French/Spanish) and updated tests.
160
+
@@ -1,5 +1,5 @@
1
1
  import { Call, CallDoc, CallQueryOptions, CallUpdateParams } from "../index";
2
- import type { CallsByHour, CountOpts, DateRange, ToolExecution } from "./calls.types";
2
+ import type { CallsByHour, CountOpts, DateRange, ToolExecution, DashboardStatsResult, DashboardStatsParams } from "./calls.types";
3
3
  import { Filter, ObjectId } from "mongodb";
4
4
  export declare const getCallsCollection: () => import("mongodb").Collection<Call>;
5
5
  export declare const getCallByCallSid: (callSid: string) => Promise<import("mongodb").WithId<Call> | null>;
@@ -35,4 +35,5 @@ export declare function getCallsStatsForDateRange(clientId: string, startStr: st
35
35
  * Aggregate calls by hour for a given date (createdAt converted to given timezone). Hour format "HH:mm".
36
36
  */
37
37
  export declare function getCallsHourlyAggregation(clientId: string, dateStr: string, timezone: string): Promise<CallsByHour[]>;
38
+ export declare function getDashboardStats(params: DashboardStatsParams): Promise<DashboardStatsResult>;
38
39
  //# sourceMappingURL=calls.getters.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"calls.getters.d.ts","sourceRoot":"","sources":["../../../src/talkpilot/calls/calls.getters.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,IAAI,EACJ,OAAO,EACP,gBAAgB,EAChB,gBAAgB,EAEjB,MAAM,UAAU,CAAC;AAClB,OAAO,KAAK,EAAE,WAAW,EAAE,SAAS,EAAE,SAAS,EAAE,aAAa,EAAE,MAAM,eAAe,CAAC;AACtF,OAAO,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,SAAS,CAAC;AAI3C,eAAO,MAAM,kBAAkB,0CAE9B,CAAC;AAEF,eAAO,MAAM,gBAAgB,GAAI,SAAS,MAAM,mDAE/C,CAAC;AAEF,eAAO,MAAM,qBAAqB,GAAI,aAAa,MAAM,8CAIxD,CAAC;AAEF,eAAO,MAAM,gBAAgB,GAAI,UAAU,MAAM,8CAEhD,CAAC;AAEF,eAAO,MAAM,cAAc,GAAI,QAAQ,QAAQ,8CAE9C,CAAC;AAEF,eAAO,MAAM,aAAa,GACxB,MAAM,IAAI,CAAC,IAAI,EAAE,WAAW,GAAG,WAAW,GAAG,KAAK,CAAC,qDAQpD,CAAC;AAEF,eAAO,MAAM,mBAAmB,GAC9B,SAAS,MAAM,EACf,SAAS,gBAAgB,KACxB,OAAO,CAAC,OAAO,GAAG,IAAI,CAWxB,CAAC;AAEF,eAAO,MAAM,iBAAiB,GAC5B,SAAS,MAAM,EACf,WAAW,aAAa,KACvB,OAAO,CAAC,IAAI,CAKd,CAAC;AAIF,eAAO,MAAM,4BAA4B,GACvC,UAAU,MAAM,EAChB,WAAW,IAAI,EACf,SAAS,IAAI,8CAWd,CAAC;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