@talkpilot/core-db 1.3.89 → 1.3.90
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/README.md +0 -72
- package/dist/talkpilot/calls/calls.constants.d.ts +1 -11
- package/dist/talkpilot/calls/calls.constants.d.ts.map +1 -1
- package/dist/talkpilot/calls/calls.constants.js +1 -11
- package/dist/talkpilot/calls/calls.constants.js.map +1 -1
- package/dist/talkpilot/calls/calls.getters.d.ts +1 -8
- package/dist/talkpilot/calls/calls.getters.d.ts.map +1 -1
- package/dist/talkpilot/calls/calls.getters.js +1 -216
- package/dist/talkpilot/calls/calls.getters.js.map +1 -1
- package/dist/talkpilot/calls/calls.types.d.ts +0 -45
- package/dist/talkpilot/calls/calls.types.d.ts.map +1 -1
- package/dist/talkpilot/clients/clients.getters.d.ts +0 -6
- package/dist/talkpilot/clients/clients.getters.d.ts.map +1 -1
- package/dist/talkpilot/clients/clients.getters.js +1 -62
- package/dist/talkpilot/clients/clients.getters.js.map +1 -1
- package/dist/talkpilot/clients/clients.types.d.ts +0 -53
- package/dist/talkpilot/clients/clients.types.d.ts.map +1 -1
- package/dist/talkpilot/clients/index.d.ts +0 -2
- package/dist/talkpilot/clients/index.d.ts.map +1 -1
- package/dist/talkpilot/clients/index.js +0 -2
- package/dist/talkpilot/clients/index.js.map +1 -1
- package/dist/talkpilot/flows/flows.schema.d.ts +9 -0
- package/dist/talkpilot/flows/flows.schema.d.ts.map +1 -1
- package/dist/talkpilot/flows/flows.schema.js +7 -0
- package/dist/talkpilot/flows/flows.schema.js.map +1 -1
- package/dist/talkpilot/flows/flows.types.d.ts +3 -0
- package/dist/talkpilot/flows/flows.types.d.ts.map +1 -1
- package/dist/talkpilot/index.d.ts +0 -1
- package/dist/talkpilot/index.d.ts.map +1 -1
- package/dist/talkpilot/index.js +0 -1
- package/dist/talkpilot/index.js.map +1 -1
- package/dist/talkpilot/phone_numbers/phone_numbers.getter.d.ts +1 -9
- package/dist/talkpilot/phone_numbers/phone_numbers.getter.d.ts.map +1 -1
- package/dist/talkpilot/phone_numbers/phone_numbers.getter.js +1 -70
- package/dist/talkpilot/phone_numbers/phone_numbers.getter.js.map +1 -1
- package/dist/talkpilot/phone_numbers/phone_numbers.types.d.ts +0 -5
- package/dist/talkpilot/phone_numbers/phone_numbers.types.d.ts.map +1 -1
- 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/factories/index.d.ts +0 -2
- package/dist/test-utils/factories/index.d.ts.map +1 -1
- package/dist/test-utils/factories/index.js +0 -2
- package/dist/test-utils/factories/index.js.map +1 -1
- package/dist/websitalk/scanResources/scanResources.getters.d.ts.map +1 -1
- package/dist/websitalk/scanResources/scanResources.getters.js +1 -2
- package/dist/websitalk/scanResources/scanResources.getters.js.map +1 -1
- package/dist/websitalk/scanResources/scanResources.utils.d.ts +1 -1
- package/dist/websitalk/scanResources/scanResources.utils.d.ts.map +1 -1
- package/dist/websitalk/scanResources/scanResources.utils.js +3 -3
- package/dist/websitalk/scanResources/scanResources.utils.js.map +1 -1
- package/package.json +1 -1
- package/src/talkpilot/calls/calls.constants.ts +0 -14
- package/src/talkpilot/calls/calls.getters.ts +0 -320
- package/src/talkpilot/calls/calls.types.ts +0 -52
- package/src/talkpilot/clients/clients.getters.ts +2 -91
- package/src/talkpilot/clients/clients.types.ts +0 -58
- package/src/talkpilot/clients/index.ts +0 -2
- package/src/talkpilot/flows/__tests__/flows.schema.spec.ts +11 -0
- package/src/talkpilot/flows/flows.schema.ts +7 -0
- package/src/talkpilot/flows/flows.types.ts +1 -0
- package/src/talkpilot/index.ts +0 -1
- package/src/talkpilot/phone_numbers/__tests__/phone_numbers.spec.ts +13 -284
- package/src/talkpilot/phone_numbers/phone_numbers.getter.ts +1 -89
- package/src/talkpilot/phone_numbers/phone_numbers.types.ts +0 -6
- package/src/test-utils/factories/index.ts +0 -2
- package/src/websitalk/scanResources/scanResources.getters.ts +6 -2
- package/src/websitalk/scanResources/scanResources.utils.ts +3 -2
- package/dist/talkpilot/auditLogs/auditLogs.getters.d.ts +0 -8
- package/dist/talkpilot/auditLogs/auditLogs.getters.d.ts.map +0 -1
- package/dist/talkpilot/auditLogs/auditLogs.getters.js +0 -26
- package/dist/talkpilot/auditLogs/auditLogs.getters.js.map +0 -1
- package/dist/talkpilot/auditLogs/auditLogs.types.d.ts +0 -11
- package/dist/talkpilot/auditLogs/auditLogs.types.d.ts.map +0 -1
- package/dist/talkpilot/auditLogs/auditLogs.types.js +0 -3
- package/dist/talkpilot/auditLogs/auditLogs.types.js.map +0 -1
- package/dist/talkpilot/auditLogs/index.d.ts +0 -3
- package/dist/talkpilot/auditLogs/index.d.ts.map +0 -1
- package/dist/talkpilot/auditLogs/index.js +0 -19
- package/dist/talkpilot/auditLogs/index.js.map +0 -1
- package/dist/talkpilot/clients/clients.constants.d.ts +0 -4
- package/dist/talkpilot/clients/clients.constants.d.ts.map +0 -1
- package/dist/talkpilot/clients/clients.constants.js +0 -7
- package/dist/talkpilot/clients/clients.constants.js.map +0 -1
- package/dist/talkpilot/clients/clients.lifecycle.d.ts +0 -10
- package/dist/talkpilot/clients/clients.lifecycle.d.ts.map +0 -1
- package/dist/talkpilot/clients/clients.lifecycle.js +0 -109
- package/dist/talkpilot/clients/clients.lifecycle.js.map +0 -1
- package/dist/test-utils/factories/talkpilot/clients.d.ts +0 -14
- package/dist/test-utils/factories/talkpilot/clients.d.ts.map +0 -1
- package/dist/test-utils/factories/talkpilot/clients.js +0 -19
- package/dist/test-utils/factories/talkpilot/clients.js.map +0 -1
- package/dist/test-utils/factories/talkpilot/results.d.ts +0 -16
- package/dist/test-utils/factories/talkpilot/results.d.ts.map +0 -1
- package/dist/test-utils/factories/talkpilot/results.js +0 -40
- package/dist/test-utils/factories/talkpilot/results.js.map +0 -1
- package/dist/utils/regex.utils.d.ts +0 -2
- package/dist/utils/regex.utils.d.ts.map +0 -1
- package/dist/utils/regex.utils.js +0 -6
- package/dist/utils/regex.utils.js.map +0 -1
- package/src/talkpilot/auditLogs/__tests__/auditLogs.spec.ts +0 -91
- package/src/talkpilot/auditLogs/auditLogs.getters.ts +0 -26
- package/src/talkpilot/auditLogs/auditLogs.types.ts +0 -12
- package/src/talkpilot/auditLogs/index.ts +0 -2
- package/src/talkpilot/calls/__tests__/calls.statistics.getters.spec.ts +0 -559
- package/src/talkpilot/clients/__tests__/clients.getters.spec.ts +0 -224
- package/src/talkpilot/clients/__tests__/clients.lifecycle.spec.ts +0 -194
- package/src/talkpilot/clients/clients.constants.ts +0 -4
- package/src/talkpilot/clients/clients.lifecycle.ts +0 -132
- package/src/test-utils/factories/talkpilot/clients.ts +0 -21
- package/src/test-utils/factories/talkpilot/results.ts +0 -43
- package/src/utils/regex.utils.ts +0 -2
|
@@ -2,8 +2,6 @@ import { ObjectId } from "mongodb";
|
|
|
2
2
|
import { BOARD_COLUMN_STATUSES } from "./scanResources.constants";
|
|
3
3
|
import type { BoardColumn, UrlTaskStatus } from "./scanResources.types";
|
|
4
4
|
|
|
5
|
-
export { escapeRegex } from "../../utils/regex.utils";
|
|
6
|
-
|
|
7
5
|
const STATUS_TO_COLUMN: Record<UrlTaskStatus, BoardColumn> = Object.entries(
|
|
8
6
|
BOARD_COLUMN_STATUSES,
|
|
9
7
|
).reduce(
|
|
@@ -28,3 +26,6 @@ export const encodeCursor = (id: ObjectId): string =>
|
|
|
28
26
|
|
|
29
27
|
export const decodeCursor = (cursor: string): ObjectId =>
|
|
30
28
|
new ObjectId(Buffer.from(cursor, "base64").toString("utf-8"));
|
|
29
|
+
|
|
30
|
+
export const escapeRegex = (text: string): string =>
|
|
31
|
+
text.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
|
|
@@ -1,8 +0,0 @@
|
|
|
1
|
-
import { Collection } from "mongodb";
|
|
2
|
-
import { QueryOptions } from "../utils/query.utils";
|
|
3
|
-
import { AuditLogDoc, AuditLogEntry } from "./auditLogs.types";
|
|
4
|
-
export declare const getAuditLogsCollection: () => Collection<AuditLogEntry>;
|
|
5
|
-
export declare const insertAuditLog: (entry: AuditLogEntry) => Promise<void>;
|
|
6
|
-
export declare const findAuditLogs: (options: Pick<QueryOptions, "skip"> & Required<Pick<QueryOptions, "limit">>) => Promise<AuditLogDoc[]>;
|
|
7
|
-
export declare const countAuditLogs: () => Promise<number>;
|
|
8
|
-
//# sourceMappingURL=auditLogs.getters.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"auditLogs.getters.d.ts","sourceRoot":"","sources":["../../../src/talkpilot/auditLogs/auditLogs.getters.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,SAAS,CAAC;AAErC,OAAO,EAAqB,YAAY,EAAE,MAAM,sBAAsB,CAAC;AACvE,OAAO,EAAE,WAAW,EAAE,aAAa,EAAE,MAAM,mBAAmB,CAAC;AAE/D,eAAO,MAAM,sBAAsB,QAAO,UAAU,CAAC,aAAa,CAEjE,CAAC;AAEF,eAAO,MAAM,cAAc,GAAU,OAAO,aAAa,KAAG,OAAO,CAAC,IAAI,CAEvE,CAAC;AAEF,eAAO,MAAM,aAAa,GACxB,SAAS,IAAI,CAAC,YAAY,EAAE,MAAM,CAAC,GAAG,QAAQ,CAAC,IAAI,CAAC,YAAY,EAAE,OAAO,CAAC,CAAC,KAC1E,OAAO,CAAC,WAAW,EAAE,CAMvB,CAAC;AAEF,eAAO,MAAM,cAAc,QAAa,OAAO,CAAC,MAAM,CAErD,CAAC"}
|
|
@@ -1,26 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.countAuditLogs = exports.findAuditLogs = exports.insertAuditLog = exports.getAuditLogsCollection = void 0;
|
|
4
|
-
const index_1 = require("../index");
|
|
5
|
-
const query_utils_1 = require("../utils/query.utils");
|
|
6
|
-
const getAuditLogsCollection = () => {
|
|
7
|
-
return (0, index_1.getDb)().collection("auditLogs");
|
|
8
|
-
};
|
|
9
|
-
exports.getAuditLogsCollection = getAuditLogsCollection;
|
|
10
|
-
const insertAuditLog = async (entry) => {
|
|
11
|
-
await (0, exports.getAuditLogsCollection)().insertOne(entry);
|
|
12
|
-
};
|
|
13
|
-
exports.insertAuditLog = insertAuditLog;
|
|
14
|
-
const findAuditLogs = async (options) => {
|
|
15
|
-
const cursor = (0, exports.getAuditLogsCollection)().find({});
|
|
16
|
-
return (0, query_utils_1.applyQueryOptions)(cursor, {
|
|
17
|
-
sort: { timestamp: -1 },
|
|
18
|
-
...options,
|
|
19
|
-
}).toArray();
|
|
20
|
-
};
|
|
21
|
-
exports.findAuditLogs = findAuditLogs;
|
|
22
|
-
const countAuditLogs = async () => {
|
|
23
|
-
return (0, exports.getAuditLogsCollection)().countDocuments({});
|
|
24
|
-
};
|
|
25
|
-
exports.countAuditLogs = countAuditLogs;
|
|
26
|
-
//# sourceMappingURL=auditLogs.getters.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"auditLogs.getters.js","sourceRoot":"","sources":["../../../src/talkpilot/auditLogs/auditLogs.getters.ts"],"names":[],"mappings":";;;AACA,oCAAiC;AACjC,sDAAuE;AAGhE,MAAM,sBAAsB,GAAG,GAA8B,EAAE;IACpE,OAAO,IAAA,aAAK,GAAE,CAAC,UAAU,CAAgB,WAAW,CAAC,CAAC;AACxD,CAAC,CAAC;AAFW,QAAA,sBAAsB,0BAEjC;AAEK,MAAM,cAAc,GAAG,KAAK,EAAE,KAAoB,EAAiB,EAAE;IAC1E,MAAM,IAAA,8BAAsB,GAAE,CAAC,SAAS,CAAC,KAAK,CAAC,CAAC;AAClD,CAAC,CAAC;AAFW,QAAA,cAAc,kBAEzB;AAEK,MAAM,aAAa,GAAG,KAAK,EAChC,OAA2E,EACnD,EAAE;IAC1B,MAAM,MAAM,GAAG,IAAA,8BAAsB,GAAE,CAAC,IAAI,CAAC,EAAE,CAAC,CAAC;IACjD,OAAO,IAAA,+BAAiB,EAAC,MAAM,EAAE;QAC/B,IAAI,EAAE,EAAE,SAAS,EAAE,CAAC,CAAC,EAAE;QACvB,GAAG,OAAO;KACX,CAAC,CAAC,OAAO,EAAE,CAAC;AACf,CAAC,CAAC;AARW,QAAA,aAAa,iBAQxB;AAEK,MAAM,cAAc,GAAG,KAAK,IAAqB,EAAE;IACxD,OAAO,IAAA,8BAAsB,GAAE,CAAC,cAAc,CAAC,EAAE,CAAC,CAAC;AACrD,CAAC,CAAC;AAFW,QAAA,cAAc,kBAEzB"}
|
|
@@ -1,11 +0,0 @@
|
|
|
1
|
-
import { WithId } from "mongodb";
|
|
2
|
-
export type AuditLogEntry = {
|
|
3
|
-
clientId: string;
|
|
4
|
-
adminEmail: string;
|
|
5
|
-
action: "delete";
|
|
6
|
-
timestamp: Date;
|
|
7
|
-
allSucceeded?: boolean;
|
|
8
|
-
failedCollections?: string[];
|
|
9
|
-
};
|
|
10
|
-
export type AuditLogDoc = WithId<AuditLogEntry>;
|
|
11
|
-
//# sourceMappingURL=auditLogs.types.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"auditLogs.types.d.ts","sourceRoot":"","sources":["../../../src/talkpilot/auditLogs/auditLogs.types.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,SAAS,CAAC;AAEjC,MAAM,MAAM,aAAa,GAAG;IAC1B,QAAQ,EAAE,MAAM,CAAC;IACjB,UAAU,EAAE,MAAM,CAAC;IACnB,MAAM,EAAE,QAAQ,CAAC;IACjB,SAAS,EAAE,IAAI,CAAC;IAChB,YAAY,CAAC,EAAE,OAAO,CAAC;IACvB,iBAAiB,CAAC,EAAE,MAAM,EAAE,CAAC;CAC9B,CAAC;AAEF,MAAM,MAAM,WAAW,GAAG,MAAM,CAAC,aAAa,CAAC,CAAC"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"auditLogs.types.js","sourceRoot":"","sources":["../../../src/talkpilot/auditLogs/auditLogs.types.ts"],"names":[],"mappings":""}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/talkpilot/auditLogs/index.ts"],"names":[],"mappings":"AAAA,cAAc,mBAAmB,CAAC;AAClC,cAAc,qBAAqB,CAAC"}
|
|
@@ -1,19 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
-
if (k2 === undefined) k2 = k;
|
|
4
|
-
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
-
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
-
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
-
}
|
|
8
|
-
Object.defineProperty(o, k2, desc);
|
|
9
|
-
}) : (function(o, m, k, k2) {
|
|
10
|
-
if (k2 === undefined) k2 = k;
|
|
11
|
-
o[k2] = m[k];
|
|
12
|
-
}));
|
|
13
|
-
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
14
|
-
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
|
-
};
|
|
16
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
-
__exportStar(require("./auditLogs.types"), exports);
|
|
18
|
-
__exportStar(require("./auditLogs.getters"), exports);
|
|
19
|
-
//# sourceMappingURL=index.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/talkpilot/auditLogs/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,oDAAkC;AAClC,sDAAoC"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"clients.constants.d.ts","sourceRoot":"","sources":["../../../src/talkpilot/clients/clients.constants.ts"],"names":[],"mappings":"AAAA,iGAAiG;AACjG,eAAO,MAAM,eAAe,EAAE,MAAM,EAAkB,CAAC;AAEvD,eAAO,MAAM,gBAAgB,8BAA+B,CAAC"}
|
|
@@ -1,7 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.BACKOFFICE_ROLES = exports.DELETE_DENYLIST = void 0;
|
|
4
|
-
/** Collections to always skip during client deletion — e.g. auditLogs, which must survive it. */
|
|
5
|
-
exports.DELETE_DENYLIST = ["auditLogs"];
|
|
6
|
-
exports.BACKOFFICE_ROLES = ["admin", "viewer"];
|
|
7
|
-
//# sourceMappingURL=clients.constants.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"clients.constants.js","sourceRoot":"","sources":["../../../src/talkpilot/clients/clients.constants.ts"],"names":[],"mappings":";;;AAAA,iGAAiG;AACpF,QAAA,eAAe,GAAa,CAAC,WAAW,CAAC,CAAC;AAE1C,QAAA,gBAAgB,GAAG,CAAC,OAAO,EAAE,QAAQ,CAAU,CAAC"}
|
|
@@ -1,10 +0,0 @@
|
|
|
1
|
-
import { DeleteClientDataSummary } from "./clients.types";
|
|
2
|
-
export declare const clientExistsInAnyCollection: (clientId: string) => Promise<boolean>;
|
|
3
|
-
/**
|
|
4
|
-
* Deletes a client's data across talkpilot/municipal collections and logs the action.
|
|
5
|
-
*
|
|
6
|
-
* ⚠️ Does NOT delete website-talk data — `scans`/`websiteUrls` are the lookup key an
|
|
7
|
-
* external API needs to clean up that domain. Callers must invoke that API separately.
|
|
8
|
-
*/
|
|
9
|
-
export declare const deleteClientDataAcrossDomains: (clientId: string, adminEmail: string) => Promise<DeleteClientDataSummary>;
|
|
10
|
-
//# sourceMappingURL=clients.lifecycle.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"clients.lifecycle.d.ts","sourceRoot":"","sources":["../../../src/talkpilot/clients/clients.lifecycle.ts"],"names":[],"mappings":"AAKA,OAAO,EAIL,uBAAuB,EACxB,MAAM,iBAAiB,CAAC;AAoBzB,eAAO,MAAM,2BAA2B,GACtC,UAAU,MAAM,KACf,OAAO,CAAC,OAAO,CAMjB,CAAC;AA6CF;;;;;GAKG;AACH,eAAO,MAAM,6BAA6B,GACxC,UAAU,MAAM,EAChB,YAAY,MAAM,KACjB,OAAO,CAAC,uBAAuB,CAuCjC,CAAC"}
|
|
@@ -1,109 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.deleteClientDataAcrossDomains = exports.clientExistsInAnyCollection = void 0;
|
|
4
|
-
const index_1 = require("../index");
|
|
5
|
-
const municipal_1 = require("../../municipal");
|
|
6
|
-
const clients_constants_1 = require("./clients.constants");
|
|
7
|
-
// Skips websitalk on purpose — see the warning on `deleteClientDataAcrossDomains` below.
|
|
8
|
-
const findClientMatchInDb = async (db, clientId) => {
|
|
9
|
-
const collections = await db.listCollections().toArray();
|
|
10
|
-
return Promise.all(collections
|
|
11
|
-
.filter((c) => !clients_constants_1.DELETE_DENYLIST.includes(c.name))
|
|
12
|
-
.map(async (c) => {
|
|
13
|
-
const doc = await db
|
|
14
|
-
.collection(c.name)
|
|
15
|
-
.findOne({ $or: [{ clientId }, { client_id: clientId }] });
|
|
16
|
-
return { collectionName: c.name, matched: !!doc };
|
|
17
|
-
}));
|
|
18
|
-
};
|
|
19
|
-
const clientExistsInAnyCollection = async (clientId) => {
|
|
20
|
-
const [talkpilotResults, municipalResults] = await Promise.all([
|
|
21
|
-
findClientMatchInDb((0, index_1.getDb)(), clientId),
|
|
22
|
-
findClientMatchInDb((0, municipal_1.getDb)(), clientId),
|
|
23
|
-
]);
|
|
24
|
-
return [...talkpilotResults, ...municipalResults].some((r) => r.matched);
|
|
25
|
-
};
|
|
26
|
-
exports.clientExistsInAnyCollection = clientExistsInAnyCollection;
|
|
27
|
-
const deleteClientFromDb = async (db, clientId) => {
|
|
28
|
-
const collections = await db.listCollections().toArray();
|
|
29
|
-
return Promise.all(collections
|
|
30
|
-
.filter((c) => !clients_constants_1.DELETE_DENYLIST.includes(c.name))
|
|
31
|
-
.map(async (c) => {
|
|
32
|
-
try {
|
|
33
|
-
const result = await db
|
|
34
|
-
.collection(c.name)
|
|
35
|
-
.deleteMany({ $or: [{ clientId }, { client_id: clientId }] });
|
|
36
|
-
return {
|
|
37
|
-
collectionName: c.name,
|
|
38
|
-
deletedCount: result.deletedCount,
|
|
39
|
-
success: true,
|
|
40
|
-
};
|
|
41
|
-
}
|
|
42
|
-
catch (error) {
|
|
43
|
-
return {
|
|
44
|
-
collectionName: c.name,
|
|
45
|
-
deletedCount: 0,
|
|
46
|
-
success: false,
|
|
47
|
-
error: error instanceof Error ? error.message : String(error),
|
|
48
|
-
};
|
|
49
|
-
}
|
|
50
|
-
}));
|
|
51
|
-
};
|
|
52
|
-
// The data is already deleted at this point — a failed audit write must not abort the caller.
|
|
53
|
-
const tryInsertAuditLog = async (entry) => {
|
|
54
|
-
try {
|
|
55
|
-
await (0, index_1.insertAuditLog)(entry);
|
|
56
|
-
return { auditLogged: true };
|
|
57
|
-
}
|
|
58
|
-
catch (error) {
|
|
59
|
-
return {
|
|
60
|
-
auditLogged: false,
|
|
61
|
-
auditError: error instanceof Error ? error.message : String(error),
|
|
62
|
-
};
|
|
63
|
-
}
|
|
64
|
-
};
|
|
65
|
-
/**
|
|
66
|
-
* Deletes a client's data across talkpilot/municipal collections and logs the action.
|
|
67
|
-
*
|
|
68
|
-
* ⚠️ Does NOT delete website-talk data — `scans`/`websiteUrls` are the lookup key an
|
|
69
|
-
* external API needs to clean up that domain. Callers must invoke that API separately.
|
|
70
|
-
*/
|
|
71
|
-
const deleteClientDataAcrossDomains = async (clientId, adminEmail) => {
|
|
72
|
-
const exists = await (0, exports.clientExistsInAnyCollection)(clientId);
|
|
73
|
-
if (!exists) {
|
|
74
|
-
return {
|
|
75
|
-
clientId,
|
|
76
|
-
deleted: false,
|
|
77
|
-
reason: "Client does not exist in any collection",
|
|
78
|
-
};
|
|
79
|
-
}
|
|
80
|
-
const [talkpilotResults, municipalResults] = await Promise.all([
|
|
81
|
-
deleteClientFromDb((0, index_1.getDb)(), clientId),
|
|
82
|
-
deleteClientFromDb((0, municipal_1.getDb)(), clientId),
|
|
83
|
-
]);
|
|
84
|
-
const results = [...talkpilotResults, ...municipalResults];
|
|
85
|
-
const allSucceeded = results.every((r) => r.success);
|
|
86
|
-
const auditResult = await tryInsertAuditLog({
|
|
87
|
-
clientId,
|
|
88
|
-
adminEmail,
|
|
89
|
-
action: "delete",
|
|
90
|
-
timestamp: new Date(),
|
|
91
|
-
allSucceeded,
|
|
92
|
-
...(allSucceeded
|
|
93
|
-
? {}
|
|
94
|
-
: {
|
|
95
|
-
failedCollections: results
|
|
96
|
-
.filter((r) => !r.success)
|
|
97
|
-
.map((r) => r.collectionName),
|
|
98
|
-
}),
|
|
99
|
-
});
|
|
100
|
-
return {
|
|
101
|
-
clientId,
|
|
102
|
-
deleted: true,
|
|
103
|
-
results,
|
|
104
|
-
allSucceeded,
|
|
105
|
-
...auditResult,
|
|
106
|
-
};
|
|
107
|
-
};
|
|
108
|
-
exports.deleteClientDataAcrossDomains = deleteClientDataAcrossDomains;
|
|
109
|
-
//# sourceMappingURL=clients.lifecycle.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"clients.lifecycle.js","sourceRoot":"","sources":["../../../src/talkpilot/clients/clients.lifecycle.ts"],"names":[],"mappings":";;;AACA,oCAAiD;AAEjD,+CAA8D;AAC9D,2DAAsD;AAQtD,yFAAyF;AACzF,MAAM,mBAAmB,GAAG,KAAK,EAC/B,EAAM,EACN,QAAgB,EACY,EAAE;IAC9B,MAAM,WAAW,GAAG,MAAM,EAAE,CAAC,eAA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AA1CW,QAAA,6BAA6B,iCA0CxC"}
|
|
@@ -1,14 +0,0 @@
|
|
|
1
|
-
import { Factory } from "fishery";
|
|
2
|
-
import { ObjectId } from "mongodb";
|
|
3
|
-
import type { Client } from "../../../talkpilot";
|
|
4
|
-
export declare const clientFactory: Factory<Client & {
|
|
5
|
-
_id?: ObjectId;
|
|
6
|
-
}, any, Client & {
|
|
7
|
-
_id?: ObjectId;
|
|
8
|
-
}, import("fishery").DeepPartialObject<Client & {
|
|
9
|
-
_id?: ObjectId;
|
|
10
|
-
}>>;
|
|
11
|
-
export declare function createClient(overrides?: Partial<Client>): Client & {
|
|
12
|
-
_id?: ObjectId;
|
|
13
|
-
};
|
|
14
|
-
//# sourceMappingURL=clients.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"clients.d.ts","sourceRoot":"","sources":["../../../../src/test-utils/factories/talkpilot/clients.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,SAAS,CAAC;AAClC,OAAO,EAAE,QAAQ,EAAE,MAAM,SAAS,CAAC;AAEnC,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,oBAAoB,CAAC;AAEjD,eAAO,MAAM,aAAa;UAAmC,QAAQ;;UAAR,QAAQ;;UAAR,QAAQ;GASpE,CAAC;AAEF,wBAAgB,YAAY,CAC1B,SAAS,CAAC,EAAE,OAAO,CAAC,MAAM,CAAC,GAC1B,MAAM,GAAG;IAAE,GAAG,CAAC,EAAE,QAAQ,CAAA;CAAE,CAE7B"}
|
|
@@ -1,19 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.clientFactory = void 0;
|
|
4
|
-
exports.createClient = createClient;
|
|
5
|
-
const fishery_1 = require("fishery");
|
|
6
|
-
const mongodb_1 = require("mongodb");
|
|
7
|
-
const faker_1 = require("@faker-js/faker");
|
|
8
|
-
exports.clientFactory = fishery_1.Factory.define(() => ({
|
|
9
|
-
_id: new mongodb_1.ObjectId(),
|
|
10
|
-
clientId: faker_1.faker.string.uuid(),
|
|
11
|
-
isActive: true,
|
|
12
|
-
credits: faker_1.faker.number.int({ min: 0, max: 1000 }),
|
|
13
|
-
createdAt: new Date(),
|
|
14
|
-
updatedAt: new Date(),
|
|
15
|
-
}));
|
|
16
|
-
function createClient(overrides) {
|
|
17
|
-
return exports.clientFactory.build(overrides);
|
|
18
|
-
}
|
|
19
|
-
//# sourceMappingURL=clients.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"clients.js","sourceRoot":"","sources":["../../../../src/test-utils/factories/talkpilot/clients.ts"],"names":[],"mappings":";;;AAgBA,oCAIC;AApBD,qCAAkC;AAClC,qCAAmC;AACnC,2CAAwC;AAG3B,QAAA,aAAa,GAAG,iBAAO,CAAC,MAAM,CACzC,GAAG,EAAE,CAAC,CAAC;IACL,GAAG,EAAE,IAAI,kBAAQ,EAAE;IACnB,QAAQ,EAAE,aAAK,CAAC,MAAM,CAAC,IAAI,EAAE;IAC7B,QAAQ,EAAE,IAAI;IACd,OAAO,EAAE,aAAK,CAAC,MAAM,CAAC,GAAG,CAAC,EAAE,GAAG,EAAE,CAAC,EAAE,GAAG,EAAE,IAAI,EAAE,CAAC;IAChD,SAAS,EAAE,IAAI,IAAI,EAAE;IACrB,SAAS,EAAE,IAAI,IAAI,EAAE;CACtB,CAAC,CACH,CAAC;AAEF,SAAgB,YAAY,CAC1B,SAA2B;IAE3B,OAAO,qBAAa,CAAC,KAAK,CAAC,SAAS,CAAC,CAAC;AACxC,CAAC"}
|
|
@@ -1,16 +0,0 @@
|
|
|
1
|
-
import { Factory } from "fishery";
|
|
2
|
-
import { ObjectId } from "mongodb";
|
|
3
|
-
import type { Result, CallResult } from "../../../talkpilot";
|
|
4
|
-
export declare const callResultFactory: Factory<CallResult, any, CallResult, import("fishery").DeepPartialObject<CallResult>>;
|
|
5
|
-
export declare function createCallResult(overrides?: Partial<CallResult>): CallResult;
|
|
6
|
-
export declare const resultFactory: Factory<Result & {
|
|
7
|
-
_id?: ObjectId;
|
|
8
|
-
}, any, Result & {
|
|
9
|
-
_id?: ObjectId;
|
|
10
|
-
}, import("fishery").DeepPartialObject<Result & {
|
|
11
|
-
_id?: ObjectId;
|
|
12
|
-
}>>;
|
|
13
|
-
export declare function createResult(overrides?: Partial<Result>): Result & {
|
|
14
|
-
_id?: ObjectId;
|
|
15
|
-
};
|
|
16
|
-
//# sourceMappingURL=results.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"results.d.ts","sourceRoot":"","sources":["../../../../src/test-utils/factories/talkpilot/results.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,SAAS,CAAC;AAClC,OAAO,EAAE,QAAQ,EAAE,MAAM,SAAS,CAAC;AAEnC,OAAO,KAAK,EAAE,MAAM,EAAE,UAAU,EAAE,MAAM,oBAAoB,CAAC;AAE7D,eAAO,MAAM,iBAAiB,uFAe3B,CAAC;AAEJ,wBAAgB,gBAAgB,CAAC,SAAS,CAAC,EAAE,OAAO,CAAC,UAAU,CAAC,GAAG,UAAU,CAE5E;AAED,eAAO,MAAM,aAAa;UAAmC,QAAQ;;UAAR,QAAQ;;UAAR,QAAQ;GAUpE,CAAC;AAEF,wBAAgB,YAAY,CAC1B,SAAS,CAAC,EAAE,OAAO,CAAC,MAAM,CAAC,GAC1B,MAAM,GAAG;IAAE,GAAG,CAAC,EAAE,QAAQ,CAAA;CAAE,CAE7B"}
|
|
@@ -1,40 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.resultFactory = exports.callResultFactory = void 0;
|
|
4
|
-
exports.createCallResult = createCallResult;
|
|
5
|
-
exports.createResult = createResult;
|
|
6
|
-
const fishery_1 = require("fishery");
|
|
7
|
-
const mongodb_1 = require("mongodb");
|
|
8
|
-
const faker_1 = require("@faker-js/faker");
|
|
9
|
-
exports.callResultFactory = fishery_1.Factory.define(() => ({
|
|
10
|
-
callSid: `CA${faker_1.faker.string.alphanumeric(32)}`,
|
|
11
|
-
status: "completed",
|
|
12
|
-
date: new Date(),
|
|
13
|
-
statuses: ["completed"],
|
|
14
|
-
userAnswer: null,
|
|
15
|
-
color: null,
|
|
16
|
-
name: null,
|
|
17
|
-
callLength: "60 seconds",
|
|
18
|
-
answeredBy: null,
|
|
19
|
-
to: faker_1.faker.phone.number(),
|
|
20
|
-
from: faker_1.faker.phone.number(),
|
|
21
|
-
transcription: [],
|
|
22
|
-
flowId: new mongodb_1.ObjectId().toString(),
|
|
23
|
-
recordingUrl: null,
|
|
24
|
-
}));
|
|
25
|
-
function createCallResult(overrides) {
|
|
26
|
-
return exports.callResultFactory.build(overrides);
|
|
27
|
-
}
|
|
28
|
-
exports.resultFactory = fishery_1.Factory.define(() => ({
|
|
29
|
-
_id: new mongodb_1.ObjectId(),
|
|
30
|
-
calls: [],
|
|
31
|
-
clientId: faker_1.faker.string.uuid(),
|
|
32
|
-
date: new Date(),
|
|
33
|
-
runId: `run_${new mongodb_1.ObjectId().toString()}`,
|
|
34
|
-
sessionId: "incomingCall",
|
|
35
|
-
sessionName: "incomingCall",
|
|
36
|
-
}));
|
|
37
|
-
function createResult(overrides) {
|
|
38
|
-
return exports.resultFactory.build(overrides);
|
|
39
|
-
}
|
|
40
|
-
//# sourceMappingURL=results.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"results.js","sourceRoot":"","sources":["../../../../src/test-utils/factories/talkpilot/results.ts"],"names":[],"mappings":";;;AAsBA,4CAEC;AAcD,oCAIC;AA1CD,qCAAkC;AAClC,qCAAmC;AACnC,2CAAwC;AAG3B,QAAA,iBAAiB,GAAG,iBAAO,CAAC,MAAM,CAAa,GAAG,EAAE,CAAC,CAAC;IACjE,OAAO,EAAE,KAAK,aAAK,CAAC,MAAM,CAAC,YAAY,CAAC,E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 -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"regex.utils.js","sourceRoot":"","sources":["../../src/utils/regex.utils.ts"],"names":[],"mappings":";;;AAAO,MAAM,WAAW,GAAG,CAAC,IAAY,EAAU,EAAE,CAClD,IAAI,CAAC,OAAO,CAAC,qBAAqB,EAAE,MAAM,CAAC,CAAC;AADjC,QAAA,WAAW,eACsB"}
|
|
@@ -1,91 +0,0 @@
|
|
|
1
|
-
import {
|
|
2
|
-
insertAuditLog,
|
|
3
|
-
getAuditLogsCollection,
|
|
4
|
-
findAuditLogs,
|
|
5
|
-
countAuditLogs,
|
|
6
|
-
} from "../auditLogs.getters";
|
|
7
|
-
import { AuditLogEntry } from "../auditLogs.types";
|
|
8
|
-
|
|
9
|
-
describe("db.auditLogs", () => {
|
|
10
|
-
describe("insertAuditLog", () => {
|
|
11
|
-
it("should write an entry that can be read back with all fields intact", async () => {
|
|
12
|
-
const entry: AuditLogEntry = {
|
|
13
|
-
clientId: "deletedClient1",
|
|
14
|
-
adminEmail: "admin@callai.co.il",
|
|
15
|
-
action: "delete",
|
|
16
|
-
timestamp: new Date("2026-07-15T10:00:00.000Z"),
|
|
17
|
-
};
|
|
18
|
-
|
|
19
|
-
await insertAuditLog(entry);
|
|
20
|
-
|
|
21
|
-
const stored = await getAuditLogsCollection().findOne({
|
|
22
|
-
clientId: "deletedClient1",
|
|
23
|
-
});
|
|
24
|
-
expect(stored).toMatchObject(entry);
|
|
25
|
-
});
|
|
26
|
-
});
|
|
27
|
-
|
|
28
|
-
describe("findAuditLogs", () => {
|
|
29
|
-
const seed = async () => {
|
|
30
|
-
await insertAuditLog({
|
|
31
|
-
clientId: "clientA",
|
|
32
|
-
adminEmail: "admin@callai.co.il",
|
|
33
|
-
action: "delete",
|
|
34
|
-
timestamp: new Date("2026-01-01T00:00:00.000Z"),
|
|
35
|
-
});
|
|
36
|
-
await insertAuditLog({
|
|
37
|
-
clientId: "clientB",
|
|
38
|
-
adminEmail: "admin@callai.co.il",
|
|
39
|
-
action: "delete",
|
|
40
|
-
timestamp: new Date("2026-02-01T00:00:00.000Z"),
|
|
41
|
-
});
|
|
42
|
-
await insertAuditLog({
|
|
43
|
-
clientId: "clientC",
|
|
44
|
-
adminEmail: "admin@callai.co.il",
|
|
45
|
-
action: "delete",
|
|
46
|
-
timestamp: new Date("2026-03-01T00:00:00.000Z"),
|
|
47
|
-
});
|
|
48
|
-
};
|
|
49
|
-
|
|
50
|
-
it("should return a page of entries, newest first", async () => {
|
|
51
|
-
await seed();
|
|
52
|
-
|
|
53
|
-
const page = await findAuditLogs({ limit: 2 });
|
|
54
|
-
|
|
55
|
-
expect(page).toHaveLength(2);
|
|
56
|
-
expect(page.map((e) => e.clientId)).toEqual(["clientC", "clientB"]);
|
|
57
|
-
});
|
|
58
|
-
|
|
59
|
-
it("should skip entries for later pages", async () => {
|
|
60
|
-
await seed();
|
|
61
|
-
|
|
62
|
-
const page = await findAuditLogs({ skip: 2, limit: 2 });
|
|
63
|
-
|
|
64
|
-
expect(page).toHaveLength(1);
|
|
65
|
-
expect(page[0].clientId).toBe("clientA");
|
|
66
|
-
});
|
|
67
|
-
});
|
|
68
|
-
|
|
69
|
-
describe("countAuditLogs", () => {
|
|
70
|
-
it("should return the total number of entries regardless of pagination", async () => {
|
|
71
|
-
await insertAuditLog({
|
|
72
|
-
clientId: "clientA",
|
|
73
|
-
adminEmail: "admin@callai.co.il",
|
|
74
|
-
action: "delete",
|
|
75
|
-
timestamp: new Date(),
|
|
76
|
-
});
|
|
77
|
-
await insertAuditLog({
|
|
78
|
-
clientId: "clientB",
|
|
79
|
-
adminEmail: "admin@callai.co.il",
|
|
80
|
-
action: "delete",
|
|
81
|
-
timestamp: new Date(),
|
|
82
|
-
});
|
|
83
|
-
|
|
84
|
-
expect(await countAuditLogs()).toBe(2);
|
|
85
|
-
});
|
|
86
|
-
|
|
87
|
-
it("should return 0 when there are no entries", async () => {
|
|
88
|
-
expect(await countAuditLogs()).toBe(0);
|
|
89
|
-
});
|
|
90
|
-
});
|
|
91
|
-
});
|
|
@@ -1,26 +0,0 @@
|
|
|
1
|
-
import { Collection } from "mongodb";
|
|
2
|
-
import { getDb } from "../index";
|
|
3
|
-
import { applyQueryOptions, QueryOptions } from "../utils/query.utils";
|
|
4
|
-
import { AuditLogDoc, AuditLogEntry } from "./auditLogs.types";
|
|
5
|
-
|
|
6
|
-
export const getAuditLogsCollection = (): Collection<AuditLogEntry> => {
|
|
7
|
-
return getDb().collection<AuditLogEntry>("auditLogs");
|
|
8
|
-
};
|
|
9
|
-
|
|
10
|
-
export const insertAuditLog = async (entry: AuditLogEntry): Promise<void> => {
|
|
11
|
-
await getAuditLogsCollection().insertOne(entry);
|
|
12
|
-
};
|
|
13
|
-
|
|
14
|
-
export const findAuditLogs = async (
|
|
15
|
-
options: Pick<QueryOptions, "skip"> & Required<Pick<QueryOptions, "limit">>,
|
|
16
|
-
): Promise<AuditLogDoc[]> => {
|
|
17
|
-
const cursor = getAuditLogsCollection().find({});
|
|
18
|
-
return applyQueryOptions(cursor, {
|
|
19
|
-
sort: { timestamp: -1 },
|
|
20
|
-
...options,
|
|
21
|
-
}).toArray();
|
|
22
|
-
};
|
|
23
|
-
|
|
24
|
-
export const countAuditLogs = async (): Promise<number> => {
|
|
25
|
-
return getAuditLogsCollection().countDocuments({});
|
|
26
|
-
};
|
|
@@ -1,12 +0,0 @@
|
|
|
1
|
-
import { WithId } from "mongodb";
|
|
2
|
-
|
|
3
|
-
export type AuditLogEntry = {
|
|
4
|
-
clientId: string;
|
|
5
|
-
adminEmail: string;
|
|
6
|
-
action: "delete";
|
|
7
|
-
timestamp: Date;
|
|
8
|
-
allSucceeded?: boolean;
|
|
9
|
-
failedCollections?: string[];
|
|
10
|
-
};
|
|
11
|
-
|
|
12
|
-
export type AuditLogDoc = WithId<AuditLogEntry>;
|