@talkpilot/core-db 1.3.17 → 1.3.19

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 (80) hide show
  1. package/README.md +199 -58
  2. package/dist/index.d.ts +1 -0
  3. package/dist/index.d.ts.map +1 -1
  4. package/dist/index.js +1 -0
  5. package/dist/index.js.map +1 -1
  6. package/dist/municipal/index.d.ts +1 -1
  7. package/dist/municipal/index.d.ts.map +1 -1
  8. package/dist/municipal/tickets/tickets.statistics.getters.d.ts.map +1 -1
  9. package/dist/municipal/tickets/tickets.statistics.getters.js +6 -2
  10. package/dist/municipal/tickets/tickets.statistics.getters.js.map +1 -1
  11. package/dist/talkpilot/clientsConfig/clientsConfig.getters.d.ts +3 -0
  12. package/dist/talkpilot/clientsConfig/clientsConfig.getters.d.ts.map +1 -1
  13. package/dist/talkpilot/clientsConfig/clientsConfig.getters.js +17 -1
  14. package/dist/talkpilot/clientsConfig/clientsConfig.getters.js.map +1 -1
  15. package/dist/talkpilot/clientsConfig/clientsConfig.types.d.ts +2 -2
  16. package/dist/talkpilot/clientsConfig/clientsConfig.types.d.ts.map +1 -1
  17. package/dist/talkpilot/flows/flows.schema.d.ts +3 -0
  18. package/dist/talkpilot/flows/flows.schema.d.ts.map +1 -1
  19. package/dist/talkpilot/flows/flows.schema.js +1 -0
  20. package/dist/talkpilot/flows/flows.schema.js.map +1 -1
  21. package/dist/talkpilot/flows/flows.setter.d.ts +13 -0
  22. package/dist/talkpilot/flows/flows.setter.d.ts.map +1 -0
  23. package/dist/talkpilot/flows/flows.setter.js +90 -0
  24. package/dist/talkpilot/flows/flows.setter.js.map +1 -0
  25. package/dist/talkpilot/flows/flows.types.d.ts +2 -0
  26. package/dist/talkpilot/flows/flows.types.d.ts.map +1 -1
  27. package/dist/talkpilot/phone_numbers/phone_numbers.getter.d.ts +1 -0
  28. package/dist/talkpilot/phone_numbers/phone_numbers.getter.d.ts.map +1 -1
  29. package/dist/talkpilot/phone_numbers/phone_numbers.getter.js +8 -1
  30. package/dist/talkpilot/phone_numbers/phone_numbers.getter.js.map +1 -1
  31. package/dist/test-utils/factories/index.d.ts +1 -0
  32. package/dist/test-utils/factories/index.d.ts.map +1 -1
  33. package/dist/test-utils/factories/index.js +1 -0
  34. package/dist/test-utils/factories/index.js.map +1 -1
  35. package/dist/test-utils/factories/websitalk/scans.d.ts.map +1 -1
  36. package/dist/test-utils/factories/websitalk/scans.js +2 -1
  37. package/dist/test-utils/factories/websitalk/scans.js.map +1 -1
  38. package/dist/websitalk/index.d.ts +1 -0
  39. package/dist/websitalk/index.d.ts.map +1 -1
  40. package/dist/websitalk/index.js +1 -0
  41. package/dist/websitalk/index.js.map +1 -1
  42. package/dist/websitalk/scans/index.d.ts +2 -0
  43. package/dist/websitalk/scans/index.d.ts.map +1 -1
  44. package/dist/websitalk/scans/index.js +2 -0
  45. package/dist/websitalk/scans/index.js.map +1 -1
  46. package/dist/websitalk/scans/scans.getters.d.ts +10 -3
  47. package/dist/websitalk/scans/scans.getters.d.ts.map +1 -1
  48. package/dist/websitalk/scans/scans.getters.js +49 -9
  49. package/dist/websitalk/scans/scans.getters.js.map +1 -1
  50. package/dist/websitalk/scans/scans.types.d.ts +3 -8
  51. package/dist/websitalk/scans/scans.types.d.ts.map +1 -1
  52. package/package.json +1 -1
  53. package/src/index.ts +1 -0
  54. package/src/municipal/index.ts +1 -1
  55. package/src/municipal/tickets/tickets.statistics.getters.ts +16 -3
  56. package/src/talkpilot/calls/__tests__/calls.statistics.spec.ts +6 -4
  57. package/src/talkpilot/clientsConfig/__tests__/clientsConfig.getters.spec.ts +57 -5
  58. package/src/talkpilot/clientsConfig/__tests__/clientsConfig.spec.ts +0 -4
  59. package/src/talkpilot/clientsConfig/clientsConfig.getters.ts +24 -0
  60. package/src/talkpilot/clientsConfig/clientsConfig.types.ts +2 -2
  61. package/src/talkpilot/flows/__tests__/flows.schema.spec.ts +3 -0
  62. package/src/talkpilot/flows/flows.schema.ts +1 -0
  63. package/src/talkpilot/flows/flows.types.ts +2 -0
  64. package/src/talkpilot/phone_numbers/phone_numbers.getter.ts +13 -0
  65. package/src/test-utils/factories/index.ts +1 -0
  66. package/src/test-utils/factories/websitalk/scans.ts +2 -1
  67. package/src/test-utils/factories/websitalk/websiteUrls.ts +17 -0
  68. package/src/websitalk/index.ts +1 -0
  69. package/src/websitalk/scans/__tests__/scans.spec.ts +121 -26
  70. package/src/websitalk/scans/index.ts +2 -0
  71. package/src/websitalk/scans/scans.constants.ts +15 -0
  72. package/src/websitalk/scans/scans.getters.ts +64 -17
  73. package/src/websitalk/scans/scans.types.ts +3 -11
  74. package/src/websitalk/scans/scans.utils.ts +5 -0
  75. package/src/websitalk/websiteUrls/__tests__/websiteUrls.spec.ts +77 -0
  76. package/src/websitalk/websiteUrls/index.ts +2 -0
  77. package/src/websitalk/websiteUrls/websiteUrls.getters.ts +65 -0
  78. package/src/websitalk/websiteUrls/websiteUrls.types.ts +13 -0
  79. package/tsconfig.json +4 -4
  80. package/README_OLD.md +0 -160
@@ -0,0 +1,77 @@
1
+ import {
2
+ createWebsiteUrl,
3
+ getWebsiteUrlsByClient,
4
+ getWebsiteUrlById,
5
+ getWebsiteUrlsCollection,
6
+ updateWebsiteUrl,
7
+ deleteWebsiteUrl,
8
+ } from "../websiteUrls.getters";
9
+ import { createWebsiteUrlFixture } from "../../../test-utils/factories/websitalk/websiteUrls";
10
+
11
+ describe("db.websitalk.websiteUrls", () => {
12
+ const clientId = "test-client";
13
+
14
+ describe("createWebsiteUrl", () => {
15
+ it("should create a website URL configuration", async () => {
16
+ const id = await createWebsiteUrl({
17
+ clientId,
18
+ name: "Primary",
19
+ baseUrl: "https://example.com",
20
+ });
21
+
22
+ const saved = await getWebsiteUrlById(id.toString());
23
+ expect(saved).toMatchObject({
24
+ clientId,
25
+ name: "Primary",
26
+ baseUrl: "https://example.com",
27
+ });
28
+ expect(saved?.createdAt).toBeInstanceOf(Date);
29
+ expect(saved?.updatedAt).toBeInstanceOf(Date);
30
+ });
31
+ });
32
+
33
+ describe("getWebsiteUrlsByClient", () => {
34
+ it("should return all configurations for a client", async () => {
35
+ await getWebsiteUrlsCollection().insertMany([
36
+ createWebsiteUrlFixture({ clientId, name: "A" }),
37
+ createWebsiteUrlFixture({ clientId, name: "B" }),
38
+ createWebsiteUrlFixture({ clientId: "other-client", name: "Other" }),
39
+ ]);
40
+
41
+ const results = await getWebsiteUrlsByClient(clientId);
42
+ expect(results).toHaveLength(2);
43
+ expect(results.map((doc) => doc.name)).toEqual(["A", "B"]);
44
+ });
45
+ });
46
+
47
+ describe("updateWebsiteUrl", () => {
48
+ it("should update name and baseUrl", async () => {
49
+ const id = await createWebsiteUrl({
50
+ clientId,
51
+ name: "Old",
52
+ baseUrl: "https://old.example",
53
+ });
54
+
55
+ const updated = await updateWebsiteUrl(id.toString(), {
56
+ name: "New",
57
+ baseUrl: "https://new.example",
58
+ });
59
+
60
+ expect(updated?.name).toBe("New");
61
+ expect(updated?.baseUrl).toBe("https://new.example");
62
+ });
63
+ });
64
+
65
+ describe("deleteWebsiteUrl", () => {
66
+ it("should delete the website and return true", async () => {
67
+ const id = await createWebsiteUrl({
68
+ clientId: "delete-client",
69
+ name: "Gone",
70
+ baseUrl: "https://gone.example",
71
+ });
72
+
73
+ expect(await deleteWebsiteUrl(id.toString())).toBe(true);
74
+ expect(await getWebsiteUrlById(id.toString())).toBeNull();
75
+ });
76
+ });
77
+ });
@@ -0,0 +1,2 @@
1
+ export * from "./websiteUrls.types";
2
+ export * from "./websiteUrls.getters";
@@ -0,0 +1,65 @@
1
+ import { Collection, Filter, ObjectId as MongoObjectId } from "mongodb";
2
+ import { getDb, ObjectId } from "../index";
3
+ import type {
4
+ CreateWebsiteUrlInput,
5
+ WebsiteUrl,
6
+ WebsiteUrlDoc,
7
+ } from "./websiteUrls.types";
8
+
9
+ export const getWebsiteUrlsCollection = (): Collection<WebsiteUrl> => {
10
+ return getDb().collection<WebsiteUrl>("websiteUrls");
11
+ };
12
+
13
+ export const getWebsiteUrlsByClient = async (
14
+ clientId: string,
15
+ ): Promise<WebsiteUrlDoc[]> => {
16
+ return getWebsiteUrlsCollection()
17
+ .find({ clientId })
18
+ .sort({ createdAt: 1 })
19
+ .toArray();
20
+ };
21
+
22
+ export const getWebsiteUrlById = async (
23
+ id: string,
24
+ ): Promise<WebsiteUrlDoc | null> => {
25
+ return getWebsiteUrlsCollection().findOne({ _id: new ObjectId(id) });
26
+ };
27
+
28
+ export const findWebsiteUrls = async (
29
+ filter: Filter<WebsiteUrl> = {},
30
+ ): Promise<WebsiteUrlDoc[]> => {
31
+ return getWebsiteUrlsCollection().find(filter).toArray();
32
+ };
33
+
34
+ export const createWebsiteUrl = async (
35
+ input: CreateWebsiteUrlInput,
36
+ ): Promise<MongoObjectId> => {
37
+ const now = new Date();
38
+ const { insertedId } = await getWebsiteUrlsCollection().insertOne({
39
+ clientId: input.clientId,
40
+ name: input.name,
41
+ baseUrl: input.baseUrl,
42
+ createdAt: now,
43
+ updatedAt: now,
44
+ });
45
+
46
+ return insertedId;
47
+ };
48
+
49
+ export const updateWebsiteUrl = async (
50
+ id: string,
51
+ updates: Partial<Pick<WebsiteUrl, "name" | "baseUrl">>,
52
+ ): Promise<WebsiteUrlDoc | null> => {
53
+ return getWebsiteUrlsCollection().findOneAndUpdate(
54
+ { _id: new ObjectId(id) },
55
+ { $set: { ...updates, updatedAt: new Date() } },
56
+ { returnDocument: "after" },
57
+ );
58
+ };
59
+
60
+ export const deleteWebsiteUrl = async (id: string): Promise<boolean> => {
61
+ const result = await getWebsiteUrlsCollection().deleteOne({
62
+ _id: new ObjectId(id),
63
+ });
64
+ return result.deletedCount === 1;
65
+ };
@@ -0,0 +1,13 @@
1
+ import { ObjectId } from "mongodb";
2
+
3
+ export type WebsiteUrl = {
4
+ clientId: string;
5
+ name: string;
6
+ baseUrl: string;
7
+ createdAt: Date;
8
+ updatedAt: Date;
9
+ };
10
+
11
+ export type WebsiteUrlDoc = WebsiteUrl & { _id: ObjectId };
12
+
13
+ export type CreateWebsiteUrlInput = Omit<WebsiteUrl, "createdAt" | "updatedAt">;
package/tsconfig.json CHANGED
@@ -1,8 +1,9 @@
1
1
  {
2
2
  "compilerOptions": {
3
3
  "target": "ES2022",
4
- "module": "CommonJS",
5
- "moduleResolution": "node",
4
+ "module": "Node16",
5
+ "moduleResolution": "node16",
6
+ "isolatedModules": true,
6
7
  "lib": ["ES2022"],
7
8
  "declaration": true,
8
9
  "declarationMap": true,
@@ -15,8 +16,7 @@
15
16
  "skipLibCheck": true,
16
17
  "resolveJsonModule": true,
17
18
  "experimentalDecorators": true,
18
- "emitDecoratorMetadata": true,
19
- "baseUrl": "."
19
+ "emitDecoratorMetadata": true
20
20
  },
21
21
  "include": ["src/**/*"],
22
22
  "exclude": ["node_modules", "dist", "test", "**/*.test.ts", "**/__tests__/*", "**/*.spec.ts"]
package/README_OLD.md DELETED
@@ -1,160 +0,0 @@
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
-