@talkpilot/core-db 1.3.80 → 1.3.82

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 (102) hide show
  1. package/AGENTS.md +1 -1
  2. package/README.md +4 -29
  3. package/dist/index.d.ts +1 -0
  4. package/dist/index.d.ts.map +1 -1
  5. package/dist/index.js +1 -0
  6. package/dist/index.js.map +1 -1
  7. package/dist/municipal/index.d.ts +1 -0
  8. package/dist/municipal/index.d.ts.map +1 -1
  9. package/dist/municipal/index.js +1 -0
  10. package/dist/municipal/index.js.map +1 -1
  11. package/dist/municipal/muniIssues/index.d.ts +2 -2
  12. package/dist/municipal/muniIssues/index.d.ts.map +1 -1
  13. package/dist/municipal/muniIssues/index.js +3 -1
  14. package/dist/municipal/muniIssues/index.js.map +1 -1
  15. package/dist/municipal/muniIssues/muniIssues.constants.d.ts +4 -0
  16. package/dist/municipal/muniIssues/muniIssues.constants.d.ts.map +1 -1
  17. package/dist/municipal/muniIssues/muniIssues.constants.js +10 -1
  18. package/dist/municipal/muniIssues/muniIssues.constants.js.map +1 -1
  19. package/dist/municipal/muniIssues/muniIssues.getters.d.ts +6 -1
  20. package/dist/municipal/muniIssues/muniIssues.getters.d.ts.map +1 -1
  21. package/dist/municipal/muniIssues/muniIssues.getters.js +31 -1
  22. package/dist/municipal/muniIssues/muniIssues.getters.js.map +1 -1
  23. package/dist/municipal/muniIssues/muniIssues.schema.d.ts.map +1 -1
  24. package/dist/municipal/muniIssues/muniIssues.schema.js +18 -0
  25. package/dist/municipal/muniIssues/muniIssues.schema.js.map +1 -1
  26. package/dist/municipal/muniIssues/muniIssues.setters.d.ts +9 -1
  27. package/dist/municipal/muniIssues/muniIssues.setters.d.ts.map +1 -1
  28. package/dist/municipal/muniIssues/muniIssues.setters.js +52 -2
  29. package/dist/municipal/muniIssues/muniIssues.setters.js.map +1 -1
  30. package/dist/municipal/muniIssues/muniIssues.types.d.ts +24 -2
  31. package/dist/municipal/muniIssues/muniIssues.types.d.ts.map +1 -1
  32. package/dist/municipal/residents/index.d.ts +5 -0
  33. package/dist/municipal/residents/index.d.ts.map +1 -0
  34. package/dist/municipal/residents/index.js +24 -0
  35. package/dist/municipal/residents/index.js.map +1 -0
  36. package/dist/municipal/residents/residents.constants.d.ts +3 -0
  37. package/dist/municipal/residents/residents.constants.d.ts.map +1 -0
  38. package/dist/municipal/residents/residents.constants.js +6 -0
  39. package/dist/municipal/residents/residents.constants.js.map +1 -0
  40. package/dist/municipal/residents/residents.getters.d.ts +9 -0
  41. package/dist/municipal/residents/residents.getters.d.ts.map +1 -0
  42. package/dist/municipal/residents/residents.getters.js +32 -0
  43. package/dist/municipal/residents/residents.getters.js.map +1 -0
  44. package/dist/municipal/residents/residents.schema.d.ts +4 -0
  45. package/dist/municipal/residents/residents.schema.d.ts.map +1 -0
  46. package/dist/municipal/residents/residents.schema.js +29 -0
  47. package/dist/municipal/residents/residents.schema.js.map +1 -0
  48. package/dist/municipal/residents/residents.types.d.ts +15 -0
  49. package/dist/municipal/residents/residents.types.d.ts.map +1 -0
  50. package/dist/municipal/residents/residents.types.js +3 -0
  51. package/dist/municipal/residents/residents.types.js.map +1 -0
  52. package/dist/talkpilot/calls/calls.constants.d.ts +0 -7
  53. package/dist/talkpilot/calls/calls.constants.d.ts.map +1 -1
  54. package/dist/talkpilot/calls/calls.constants.js +1 -8
  55. package/dist/talkpilot/calls/calls.constants.js.map +1 -1
  56. package/dist/talkpilot/calls/calls.getters.d.ts +1 -2
  57. package/dist/talkpilot/calls/calls.getters.d.ts.map +1 -1
  58. package/dist/talkpilot/calls/calls.getters.js +1 -6
  59. package/dist/talkpilot/calls/calls.getters.js.map +1 -1
  60. package/dist/talkpilot/calls/calls.types.d.ts +2 -4
  61. package/dist/talkpilot/calls/calls.types.d.ts.map +1 -1
  62. package/dist/talkpilot/flows/flows.schema.d.ts +28 -0
  63. package/dist/talkpilot/flows/flows.schema.d.ts.map +1 -1
  64. package/dist/talkpilot/flows/flows.schema.js +16 -0
  65. package/dist/talkpilot/flows/flows.schema.js.map +1 -1
  66. package/dist/talkpilot/flows/flows.types.d.ts +8 -0
  67. package/dist/talkpilot/flows/flows.types.d.ts.map +1 -1
  68. package/dist/test-utils/factories/index.d.ts +1 -0
  69. package/dist/test-utils/factories/index.d.ts.map +1 -1
  70. package/dist/test-utils/factories/index.js +1 -0
  71. package/dist/test-utils/factories/index.js.map +1 -1
  72. package/dist/test-utils/factories/municipal/residents.d.ts +5 -0
  73. package/dist/test-utils/factories/municipal/residents.d.ts.map +1 -0
  74. package/dist/test-utils/factories/municipal/residents.js +22 -0
  75. package/dist/test-utils/factories/municipal/residents.js.map +1 -0
  76. package/package.json +1 -1
  77. package/src/index.ts +1 -0
  78. package/src/municipal/index.ts +1 -0
  79. package/src/municipal/muniIssues/__tests__/muniIssues.getters.spec.ts +66 -0
  80. package/src/municipal/muniIssues/__tests__/muniIssues.setters.spec.ts +106 -1
  81. package/src/municipal/muniIssues/__tests__/muniIssues.setup.spec.ts +1 -0
  82. package/src/municipal/muniIssues/index.ts +6 -0
  83. package/src/municipal/muniIssues/muniIssues.constants.ts +11 -0
  84. package/src/municipal/muniIssues/muniIssues.getters.ts +46 -2
  85. package/src/municipal/muniIssues/muniIssues.schema.ts +20 -0
  86. package/src/municipal/muniIssues/muniIssues.setters.ts +72 -3
  87. package/src/municipal/muniIssues/muniIssues.types.ts +36 -4
  88. package/src/municipal/residents/__tests__/residents.spec.ts +92 -0
  89. package/src/municipal/residents/index.ts +4 -0
  90. package/src/municipal/residents/residents.constants.ts +2 -0
  91. package/src/municipal/residents/residents.getters.ts +42 -0
  92. package/src/municipal/residents/residents.schema.ts +28 -0
  93. package/src/municipal/residents/residents.types.ts +17 -0
  94. package/src/talkpilot/calls/__tests__/calls.spec.ts +0 -48
  95. package/src/talkpilot/calls/calls.constants.ts +0 -8
  96. package/src/talkpilot/calls/calls.getters.ts +1 -19
  97. package/src/talkpilot/calls/calls.types.ts +1 -5
  98. package/src/talkpilot/flows/__tests__/flows.schema.spec.ts +28 -0
  99. package/src/talkpilot/flows/flows.schema.ts +16 -0
  100. package/src/talkpilot/flows/flows.types.ts +9 -0
  101. package/src/test-utils/factories/index.ts +1 -0
  102. package/src/test-utils/factories/municipal/residents.ts +20 -0
@@ -47,11 +47,3 @@ export const CallStatusValues = {
47
47
  } as const;
48
48
 
49
49
  export const ALL_CALL_STATUSES = Object.values(CallStatusValues);
50
-
51
- /** Who ended a connected call: our platform, the AI agent (end flow), the caller, or a human agent. */
52
- export const CallEndedByValues = {
53
- System: "system",
54
- Agent: "agent",
55
- User: "user",
56
- HumanAgent: "humanAgent",
57
- } as const;
@@ -5,13 +5,7 @@ import {
5
5
  CallUpdateParams,
6
6
  getDb,
7
7
  } from "../index";
8
- import type {
9
- CountOpts,
10
- DateRange,
11
- ToolExecution,
12
- CallStatus,
13
- CallEndedBy,
14
- } from "./calls.types";
8
+ import type { CountOpts, DateRange, ToolExecution, CallStatus } from "./calls.types";
15
9
  import {
16
10
  TOOL_EXECUTIONS_DEFAULT_LIMIT,
17
11
  TOOL_EXECUTIONS_DEFAULT_SKIP,
@@ -95,18 +89,6 @@ export const updateCallStatusByCallSid = async (
95
89
  { returnDocument: "after" },
96
90
  );
97
91
 
98
-
99
- export const setCallEndedBy = async (
100
- callSid: string,
101
- endedBy: CallEndedBy,
102
- ): Promise<boolean> => {
103
- const result = await getCallsCollection().updateOne(
104
- { callSid, endedBy: { $exists: false } },
105
- { $set: { endedBy, updatedAt: new Date() } },
106
- );
107
- return result.modifiedCount > 0;
108
- };
109
-
110
92
  export const pushToolExecution = async (
111
93
  callSid: string,
112
94
  execution: ToolExecution,
@@ -3,7 +3,6 @@ import { TranscriptionSegment } from "../results";
3
3
  import { LeadProperty } from "../leads";
4
4
 
5
5
  import {
6
- CallEndedByValues,
7
6
  CallStatusValues,
8
7
  CONFERENCE_ROLE_CUSTOMER,
9
8
  CONFERENCE_ROLE_SUPERVISOR,
@@ -16,8 +15,6 @@ export type ConferenceRole =
16
15
 
17
16
  export type CallStatus = (typeof CallStatusValues)[keyof typeof CallStatusValues];
18
17
 
19
- export type CallEndedBy = (typeof CallEndedByValues)[keyof typeof CallEndedByValues];
20
-
21
18
  /**
22
19
  * Represents the call usage information with details about charging segments and quota impact.
23
20
  */
@@ -52,7 +49,6 @@ export type Call = {
52
49
  isAnsweredByAnsweringMachine?: boolean;
53
50
  agentHungUp?: boolean;
54
51
  endReason?: string;
55
- endedBy?: CallEndedBy;
56
52
  conferenceName?: string | null;
57
53
  conferenceSid?: string | null;
58
54
  conferenceParticipantSid?: string | null;
@@ -150,7 +146,7 @@ export type ImmutableCallFields =
150
146
  | "env"
151
147
  | "createdAt";
152
148
 
153
- export type CallUpdateParams = Partial<Omit<Call, ImmutableCallFields | "endedBy">>;
149
+ export type CallUpdateParams = Partial<Omit<Call, ImmutableCallFields>>;
154
150
 
155
151
  export type CallDoc = WithId<Call>;
156
152
 
@@ -121,4 +121,32 @@ describe("flowMongoSchema", () => {
121
121
  "null",
122
122
  ]);
123
123
  });
124
+
125
+ it("defines beforeCallEvent as an optional object with url, and afterCallEvent as optional string or null", () => {
126
+ const schema: any = flowMongoSchema;
127
+
128
+ expect(schema.properties).toHaveProperty("beforeCallEvent");
129
+ expect(schema.properties.beforeCallEvent.bsonType).toEqual(["object", "null"]);
130
+ expect(schema.properties.beforeCallEvent.required).toEqual(["url"]);
131
+ expect(schema.properties.beforeCallEvent.properties).toEqual(
132
+ expect.objectContaining({
133
+ url: { bsonType: "string" },
134
+ timeoutMs: { bsonType: ["number", "null"] },
135
+ sendUserAuthToken: { bsonType: ["bool", "null"] },
136
+ wait: { bsonType: ["bool", "null"] },
137
+ })
138
+ );
139
+ expect(schema.properties.beforeCallEvent.properties.allowedKeys).toEqual({
140
+ bsonType: ["array", "null"],
141
+ items: { bsonType: "string" },
142
+ });
143
+ expect(schema.required).not.toContain("beforeCallEvent");
144
+
145
+ expect(schema.properties).toHaveProperty("afterCallEvent");
146
+ expect(schema.properties.afterCallEvent.bsonType).toEqual([
147
+ "string",
148
+ "null",
149
+ ]);
150
+ expect(schema.required).not.toContain("afterCallEvent");
151
+ });
124
152
  });
@@ -175,6 +175,22 @@ export const flowMongoSchema = {
175
175
  additionalProperties: false,
176
176
  },
177
177
  },
178
+ beforeCallEvent: {
179
+ bsonType: ["object", "null"],
180
+ required: ["url"],
181
+ properties: {
182
+ url: { bsonType: "string" },
183
+ timeoutMs: { bsonType: ["number", "null"] },
184
+ sendUserAuthToken: { bsonType: ["bool", "null"] },
185
+ allowedKeys: {
186
+ bsonType: ["array", "null"],
187
+ items: { bsonType: "string" },
188
+ },
189
+ wait: { bsonType: ["bool", "null"] },
190
+ },
191
+ additionalProperties: false,
192
+ },
193
+ afterCallEvent: { bsonType: ["string", "null"] },
178
194
  },
179
195
  additionalProperties: false,
180
196
  } as const;
@@ -167,6 +167,14 @@ export type InternalToolConfig = {
167
167
  params?: Record<string, InternalToolParamConfig>;
168
168
  };
169
169
 
170
+ export type BeforeCallEvent = {
171
+ url: string;
172
+ timeoutMs?: number;
173
+ sendUserAuthToken?: boolean;
174
+ allowedKeys?: string[];
175
+ wait?: boolean;
176
+ };
177
+
170
178
  /* ---------- The Flow object ---------- */
171
179
 
172
180
  export type Flow = {
@@ -191,6 +199,7 @@ export type Flow = {
191
199
  metaKeys?: MetaKey[] | null;
192
200
  userProperties?: UserProperty[] | null;
193
201
  tools?: FlowTool[];
202
+ beforeCallEvent?: BeforeCallEvent;
194
203
  afterCallEvent?: string;
195
204
 
196
205
  products?: string[];
@@ -10,6 +10,7 @@ export * from "./talkpilot/sessions";
10
10
  export * from "./municipal/cities";
11
11
  export * from "./municipal/departmentsSubjects";
12
12
  export * from "./municipal/muniIssues";
13
+ export * from "./municipal/residents";
13
14
  export * from "./municipal/streets";
14
15
  export * from "./municipal/tickets";
15
16
  export * from "./websitalk/scans";
@@ -0,0 +1,20 @@
1
+ import { Factory } from "fishery";
2
+ import { ObjectId } from "mongodb";
3
+ import { faker } from "@faker-js/faker";
4
+ import type { Resident } from "../../../municipal";
5
+
6
+ export const residentFactory = Factory.define<Resident>(() => ({
7
+ _id: new ObjectId(),
8
+ createdAt: new Date(),
9
+ updatedAt: new Date(),
10
+ cityName: faker.location.city(),
11
+ firstName: faker.person.firstName(),
12
+ lastName: faker.person.lastName(),
13
+ idNumber: faker.string.numeric(9),
14
+ phoneNumber: `+97250${faker.string.numeric(7)}`,
15
+ address: faker.location.streetAddress(),
16
+ }));
17
+
18
+ export function createResident(overrides?: Partial<Resident>): Resident {
19
+ return residentFactory.build(overrides);
20
+ }