@talkpilot/core-db 1.3.32 → 1.3.33
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 +12 -23
- package/dist/bulkWrite/bulkWrite.ops.d.ts +17 -0
- package/dist/bulkWrite/bulkWrite.ops.d.ts.map +1 -0
- package/dist/bulkWrite/bulkWrite.ops.js +35 -0
- package/dist/bulkWrite/bulkWrite.ops.js.map +1 -0
- package/dist/bulkWrite/bulkWrite.types.d.ts +4 -0
- package/dist/bulkWrite/bulkWrite.types.d.ts.map +1 -0
- package/dist/{talkpilot/clients/clients.quota.types.js → bulkWrite/bulkWrite.types.js} +1 -1
- package/dist/bulkWrite/bulkWrite.types.js.map +1 -0
- package/dist/bulkWrite/index.d.ts +3 -0
- package/dist/bulkWrite/index.d.ts.map +1 -0
- package/dist/bulkWrite/index.js +19 -0
- package/dist/bulkWrite/index.js.map +1 -0
- package/dist/configuration/index.d.ts +7 -0
- package/dist/configuration/index.d.ts.map +1 -0
- package/dist/configuration/index.js +34 -0
- package/dist/configuration/index.js.map +1 -0
- package/dist/configuration/mongodb-client.d.ts +13 -0
- package/dist/configuration/mongodb-client.d.ts.map +1 -0
- package/dist/configuration/mongodb-client.js +56 -0
- package/dist/configuration/mongodb-client.js.map +1 -0
- package/dist/configuration/prompts/index.d.ts +3 -0
- package/dist/configuration/prompts/index.d.ts.map +1 -0
- package/dist/configuration/prompts/index.js +18 -0
- package/dist/configuration/prompts/index.js.map +1 -0
- package/dist/configuration/prompts/prompts.getters.d.ts +21 -0
- package/dist/configuration/prompts/prompts.getters.d.ts.map +1 -0
- package/dist/configuration/prompts/prompts.getters.js +35 -0
- package/dist/configuration/prompts/prompts.getters.js.map +1 -0
- package/dist/configuration/prompts/prompts.types.d.ts +9 -0
- package/dist/configuration/prompts/prompts.types.d.ts.map +1 -0
- package/dist/configuration/prompts/prompts.types.js +3 -0
- package/dist/configuration/prompts/prompts.types.js.map +1 -0
- package/dist/connection.d.ts.map +1 -1
- package/dist/connection.js +11 -0
- package/dist/connection.js.map +1 -1
- package/dist/index.d.ts +8 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +11 -1
- package/dist/index.js.map +1 -1
- package/dist/municipal/departmentsSubjects/departmentsSubjects.getters.d.ts +15 -1
- package/dist/municipal/departmentsSubjects/departmentsSubjects.getters.d.ts.map +1 -1
- package/dist/municipal/departmentsSubjects/departmentsSubjects.getters.js +24 -1
- package/dist/municipal/departmentsSubjects/departmentsSubjects.getters.js.map +1 -1
- package/dist/municipal/departmentsSubjects/departmentsSubjects.setters.d.ts +10 -0
- package/dist/municipal/departmentsSubjects/departmentsSubjects.setters.d.ts.map +1 -0
- package/dist/municipal/departmentsSubjects/departmentsSubjects.setters.js +15 -0
- package/dist/municipal/departmentsSubjects/departmentsSubjects.setters.js.map +1 -0
- package/dist/municipal/departmentsSubjects/departmentsSubjects.types.d.ts +1 -0
- package/dist/municipal/departmentsSubjects/departmentsSubjects.types.d.ts.map +1 -1
- package/dist/municipal/streets/streets.getters.d.ts +2 -1
- package/dist/municipal/streets/streets.getters.d.ts.map +1 -1
- package/dist/municipal/streets/streets.getters.js +6 -1
- package/dist/municipal/streets/streets.getters.js.map +1 -1
- package/dist/municipal/streets/streets.setters.d.ts +10 -0
- package/dist/municipal/streets/streets.setters.d.ts.map +1 -0
- package/dist/municipal/streets/streets.setters.js +15 -0
- package/dist/municipal/streets/streets.setters.js.map +1 -0
- package/dist/municipal/streets/streets.types.d.ts +1 -0
- package/dist/municipal/streets/streets.types.d.ts.map +1 -1
- package/dist/reconcile/index.d.ts +5 -0
- package/dist/reconcile/index.d.ts.map +1 -0
- package/dist/reconcile/index.js +21 -0
- package/dist/reconcile/index.js.map +1 -0
- package/dist/reconcile/reconcile.diff.d.ts +4 -0
- package/dist/reconcile/reconcile.diff.d.ts.map +1 -0
- package/dist/reconcile/reconcile.diff.js +36 -0
- package/dist/reconcile/reconcile.diff.js.map +1 -0
- package/dist/reconcile/reconcile.execute.d.ts +7 -0
- package/dist/reconcile/reconcile.execute.d.ts.map +1 -0
- package/dist/reconcile/reconcile.execute.js +20 -0
- package/dist/reconcile/reconcile.execute.js.map +1 -0
- package/dist/reconcile/reconcile.ops.d.ts +12 -0
- package/dist/reconcile/reconcile.ops.d.ts.map +1 -0
- package/dist/reconcile/reconcile.ops.js +24 -0
- package/dist/reconcile/reconcile.ops.js.map +1 -0
- package/dist/reconcile/reconcile.types.d.ts +32 -0
- package/dist/reconcile/reconcile.types.d.ts.map +1 -0
- package/dist/reconcile/reconcile.types.js +3 -0
- package/dist/reconcile/reconcile.types.js.map +1 -0
- package/dist/talkpilot/clients/clients.types.d.ts +0 -3
- 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/clientsConfig/clientsConfig.getters.d.ts +0 -5
- package/dist/talkpilot/clientsConfig/clientsConfig.getters.d.ts.map +1 -1
- package/dist/talkpilot/clientsConfig/clientsConfig.getters.js +1 -37
- package/dist/talkpilot/clientsConfig/clientsConfig.getters.js.map +1 -1
- package/dist/talkpilot/clientsConfig/clientsConfig.types.d.ts +3 -3
- package/dist/talkpilot/clientsConfig/clientsConfig.types.d.ts.map +1 -1
- package/dist/talkpilot/clientsConfig/clientsConfig.types.js.map +1 -1
- package/dist/test-utils/db-utils.d.ts.map +1 -1
- package/dist/test-utils/db-utils.js +2 -0
- package/dist/test-utils/db-utils.js.map +1 -1
- package/package.json +1 -1
- package/src/bulkWrite/__tests__/bulkWrite.spec.ts +65 -0
- package/src/bulkWrite/bulkWrite.ops.ts +45 -0
- package/src/bulkWrite/bulkWrite.types.ts +4 -0
- package/src/bulkWrite/index.ts +2 -0
- package/src/configuration/index.ts +15 -0
- package/src/configuration/mongodb-client.ts +61 -0
- package/src/configuration/prompts/index.ts +2 -0
- package/src/configuration/prompts/prompts.getters.ts +37 -0
- package/src/configuration/prompts/prompts.types.ts +10 -0
- package/src/connection.ts +13 -0
- package/src/index.ts +14 -0
- package/src/municipal/departmentsSubjects/__tests__/departmentsSubjects.spec.ts +272 -0
- package/src/municipal/departmentsSubjects/departmentsSubjects.getters.ts +38 -3
- package/src/municipal/departmentsSubjects/departmentsSubjects.types.ts +1 -0
- package/src/municipal/streets/__tests__/streets.spec.ts +253 -0
- package/src/municipal/streets/streets.getters.ts +16 -1
- package/src/municipal/streets/streets.types.ts +1 -0
- package/src/talkpilot/clients/clients.types.ts +0 -4
- package/src/talkpilot/clients/index.ts +0 -2
- package/src/talkpilot/clientsConfig/__tests__/clientsConfig.spec.ts +0 -26
- package/src/talkpilot/clientsConfig/clientsConfig.getters.ts +0 -54
- package/src/talkpilot/clientsConfig/clientsConfig.types.ts +3 -4
- package/src/test-utils/db-utils.ts +8 -1
- package/dist/talkpilot/clients/clients.quota.constants.d.ts +0 -2
- package/dist/talkpilot/clients/clients.quota.constants.d.ts.map +0 -1
- package/dist/talkpilot/clients/clients.quota.constants.js +0 -5
- package/dist/talkpilot/clients/clients.quota.constants.js.map +0 -1
- package/dist/talkpilot/clients/clients.quota.getters.d.ts +0 -7
- package/dist/talkpilot/clients/clients.quota.getters.d.ts.map +0 -1
- package/dist/talkpilot/clients/clients.quota.getters.js +0 -80
- package/dist/talkpilot/clients/clients.quota.getters.js.map +0 -1
- package/dist/talkpilot/clients/clients.quota.types.d.ts +0 -24
- package/dist/talkpilot/clients/clients.quota.types.d.ts.map +0 -1
- package/dist/talkpilot/clients/clients.quota.types.js.map +0 -1
- package/dist/talkpilot/clients/clients.quota.utils.d.ts +0 -8
- package/dist/talkpilot/clients/clients.quota.utils.d.ts.map +0 -1
- package/dist/talkpilot/clients/clients.quota.utils.js +0 -45
- package/dist/talkpilot/clients/clients.quota.utils.js.map +0 -1
- package/src/talkpilot/clients/__tests__/clients.quota.spec.ts +0 -123
- package/src/talkpilot/clients/clients.quota.getters.ts +0 -119
- package/src/talkpilot/clients/clients.quota.types.ts +0 -27
|
@@ -1,12 +1,8 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.
|
|
3
|
+
exports.clearActiveScanId = exports.updateActiveScanId = exports.getActiveScanId = exports.createClientConfigDoc = exports.getClientConfigByPhone = exports.getClientConfig = exports.getClientsConfigCollection = void 0;
|
|
4
4
|
exports.updateProductConfig = updateProductConfig;
|
|
5
|
-
exports.listClientIdsWithConfiguredQuota = listClientIdsWithConfiguredQuota;
|
|
6
|
-
exports.incrementClientQuotaUsage = incrementClientQuotaUsage;
|
|
7
|
-
exports.resetClientQuotaUsage = resetClientQuotaUsage;
|
|
8
5
|
const index_1 = require("../index");
|
|
9
|
-
const clients_quota_getters_1 = require("../clients/clients.quota.getters");
|
|
10
6
|
const getClientsConfigCollection = () => {
|
|
11
7
|
return (0, index_1.getDb)().collection("clientsConfig");
|
|
12
8
|
};
|
|
@@ -15,12 +11,6 @@ const getClientConfig = (clientId) => {
|
|
|
15
11
|
return (0, exports.getClientsConfigCollection)().findOne({ clientId });
|
|
16
12
|
};
|
|
17
13
|
exports.getClientConfig = getClientConfig;
|
|
18
|
-
const getClientDisplayName = async (clientId) => {
|
|
19
|
-
const doc = await (0, exports.getClientsConfigCollection)().findOne({ clientId }, { projection: { "quota.clientDisplayName": 1, _id: 0 } });
|
|
20
|
-
const name = doc?.quota?.clientDisplayName?.trim();
|
|
21
|
-
return name || "-";
|
|
22
|
-
};
|
|
23
|
-
exports.getClientDisplayName = getClientDisplayName;
|
|
24
14
|
const getClientConfigByPhone = async (phone) => {
|
|
25
15
|
const client = await (0, index_1.findClientByPhoneNumber)(phone);
|
|
26
16
|
if (!client)
|
|
@@ -61,30 +51,4 @@ const clearActiveScanId = async (clientId) => {
|
|
|
61
51
|
}
|
|
62
52
|
};
|
|
63
53
|
exports.clearActiveScanId = clearActiveScanId;
|
|
64
|
-
async function listClientIdsWithConfiguredQuota() {
|
|
65
|
-
const docs = await (0, exports.getClientsConfigCollection)()
|
|
66
|
-
.find({ "quota.totalQuota": { $exists: true, $ne: null } })
|
|
67
|
-
.project({ clientId: 1, _id: 0 })
|
|
68
|
-
.toArray();
|
|
69
|
-
return docs.map(({ clientId }) => clientId);
|
|
70
|
-
}
|
|
71
|
-
async function incrementClientQuotaUsage(clientId, amount = 1) {
|
|
72
|
-
const result = await (0, exports.getClientsConfigCollection)().updateOne({ clientId, "quota.totalQuota": { $exists: true } }, { $inc: { "quota.usedQuota": amount } });
|
|
73
|
-
if (result.matchedCount === 0) {
|
|
74
|
-
return;
|
|
75
|
-
}
|
|
76
|
-
}
|
|
77
|
-
async function resetClientQuotaUsage(clientId) {
|
|
78
|
-
const result = await (0, exports.getClientsConfigCollection)().updateOne({ clientId }, { $set: { "quota.usedQuota": 0 } });
|
|
79
|
-
if (result.matchedCount === 0) {
|
|
80
|
-
throw new Error(`No client config found for clientId: ${clientId}`);
|
|
81
|
-
}
|
|
82
|
-
await (0, clients_quota_getters_1.resetClientQuotaSettings)(clientId);
|
|
83
|
-
}
|
|
84
|
-
var clients_quota_getters_2 = require("../clients/clients.quota.getters");
|
|
85
|
-
Object.defineProperty(exports, "getClientQuotaState", { enumerable: true, get: function () { return clients_quota_getters_2.getClientQuotaState; } });
|
|
86
|
-
Object.defineProperty(exports, "updateQuotaAlertsConfig", { enumerable: true, get: function () { return clients_quota_getters_2.updateQuotaAlertsConfig; } });
|
|
87
|
-
Object.defineProperty(exports, "markQuotaAlertSent", { enumerable: true, get: function () { return clients_quota_getters_2.markQuotaAlertSent; } });
|
|
88
|
-
Object.defineProperty(exports, "markQuotaExpiredSent", { enumerable: true, get: function () { return clients_quota_getters_2.markQuotaExpiredSent; } });
|
|
89
|
-
Object.defineProperty(exports, "resetClientQuotaSettings", { enumerable: true, get: function () { return clients_quota_getters_2.resetClientQuotaSettings; } });
|
|
90
54
|
//# sourceMappingURL=clientsConfig.getters.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"clientsConfig.getters.js","sourceRoot":"","sources":["../../../src/talkpilot/clientsConfig/clientsConfig.getters.ts"],"names":[],"mappings":";;;
|
|
1
|
+
{"version":3,"file":"clientsConfig.getters.js","sourceRoot":"","sources":["../../../src/talkpilot/clientsConfig/clientsConfig.getters.ts"],"names":[],"mappings":";;;AA8BA,kDAwBC;AAtDD,oCAOkB;AAGX,MAAM,0BAA0B,GAAG,GAAgC,EAAE;IAC1E,OAAO,IAAA,aAAK,GAAE,CAAC,UAAU,CAAkB,eAAe,CAAC,CAAC;AAC9D,CAAC,CAAC;AAFW,QAAA,0BAA0B,8BAErC;AAEK,MAAM,eAAe,GAAG,CAAC,QAAgB,EAAE,EAAE;IAClD,OAAO,IAAA,kCAA0B,GAAE,CAAC,OAAO,CAAC,EAAE,QAAQ,EAAE,CAAC,CAAC;AAC5D,CAAC,CAAC;AAFW,QAAA,eAAe,mBAE1B;AAEK,MAAM,sBAAsB,GAAG,KAAK,EAAE,KAAa,EAAE,EAAE;IAC5D,MAAM,MAAM,GAAG,MAAM,IAAA,+BAAuB,EAAC,KAAK,CAAC,CAAC;IACpD,IAAI,CAAC,MAAM;QAAE,OAAO,IAAI,CAAC;IACzB,OAAO,IAAA,uBAAe,EAAC,MAAM,CAAC,QAAQ,CAAC,CAAC;AAC1C,CAAC,CAAC;AAJW,QAAA,sBAAsB,0BAIjC;AAEK,MAAM,qBAAqB,GAAG,KAAK,EACxC,YAA6B,EACd,EAAE;IACjB,MAAM,IAAA,kCAA0B,GAAE,CAAC,SAAS,CAAC,YAAY,CAAC,CAAC;AAC7D,CAAC,CAAC;AAJW,QAAA,qBAAqB,yBAIhC;AAEK,KAAK,UAAU,mBAAmB,CACvC,QAAgB,EAChB,UAAa,EACb,OAA6B;IAE7B,IAAI,CAAC,0BAAkB,CAAC,QAAQ,CAAC,UAA6B,CAAC,EAAE,CAAC;QAChE,MAAM,IAAI,K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AAE,EAAE,EAAE,CACxD,CAAC;IACF,IAAI,MAAM,CAAC,YAAY,KAAK,CAAC,EAAE,CAAC;QAC9B,MAAM,IAAI,KAAK,CAAC,wCAAwC,QAAQ,EAAE,CAAC,CAAC;IACtE,CAAC;AACH,CAAC,CAAC;AARW,QAAA,iBAAiB,qBAQ5B"}
|
|
@@ -9,10 +9,12 @@ export type InitiateCallForShortSlaConfig = {
|
|
|
9
9
|
}[];
|
|
10
10
|
flow_id?: string | string[];
|
|
11
11
|
};
|
|
12
|
-
/** Per-tool LLM system prompt overrides. Falls back to
|
|
12
|
+
/** Per-tool LLM system prompt overrides. Falls back to configuration-db defaults when absent. */
|
|
13
13
|
export type Moked106ToolPrompts = {
|
|
14
14
|
findSubjectsSystemPrompt?: string;
|
|
15
15
|
findStreetsSystemPrompt?: string;
|
|
16
|
+
transcriptionStreetSystemPrompt?: string;
|
|
17
|
+
transcriptionSubjectSystemPrompt?: string;
|
|
16
18
|
};
|
|
17
19
|
/** Feature flags and behavior config for the moked_106 municipal call-center product. */
|
|
18
20
|
export type Moked106Config = {
|
|
@@ -73,7 +75,6 @@ export type CommunicationsConfig = {
|
|
|
73
75
|
sms?: SmsConfig;
|
|
74
76
|
whatsapp?: WhatsappConfig;
|
|
75
77
|
};
|
|
76
|
-
import type { ClientQuotaUsage } from "../clients/clients.quota.types";
|
|
77
78
|
export type ClientConfig<P extends Products = Products> = {
|
|
78
79
|
clientId: string;
|
|
79
80
|
phoneNumber?: string;
|
|
@@ -82,7 +83,6 @@ export type ClientConfig<P extends Products = Products> = {
|
|
|
82
83
|
timezone?: string;
|
|
83
84
|
communications?: CommunicationsConfig;
|
|
84
85
|
callLengthThresholds?: CallLengthThresholds;
|
|
85
|
-
quota?: ClientQuotaUsage;
|
|
86
86
|
};
|
|
87
87
|
export type ClientConfigDoc<P extends Products = Products> = WithId<ClientConfig<P>>;
|
|
88
88
|
//# sourceMappingURL=clientsConfig.types.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"clientsConfig.types.d.ts","sourceRoot":"","sources":["../../../src/talkpilot/clientsConfig/clientsConfig.types.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,SAAS,CAAC;AACjC,OAAO,EAAE,oBAAoB,EAAE,MAAM,0BAA0B,CAAC;AAMhE,MAAM,MAAM,6BAA6B,GAAG;IAC1C,MAAM,EAAE,OAAO,CAAC;IAChB,SAAS,EAAE,MAAM,CAAC;IAClB,QAAQ,CAAC,EAAE;QAAE,IAAI,EAAE,MAAM,CAAC;QAAC,WAAW,EAAE,MAAM,CAAA;KAAE,EAAE,CAAC;IACnD,OAAO,CAAC,EAAE,MAAM,GAAG,MAAM,EAAE,CAAC;CAC7B,CAAC;AAEF,
|
|
1
|
+
{"version":3,"file":"clientsConfig.types.d.ts","sourceRoot":"","sources":["../../../src/talkpilot/clientsConfig/clientsConfig.types.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,SAAS,CAAC;AACjC,OAAO,EAAE,oBAAoB,EAAE,MAAM,0BAA0B,CAAC;AAMhE,MAAM,MAAM,6BAA6B,GAAG;IAC1C,MAAM,EAAE,OAAO,CAAC;IAChB,SAAS,EAAE,MAAM,CAAC;IAClB,QAAQ,CAAC,EAAE;QAAE,IAAI,EAAE,MAAM,CAAC;QAAC,WAAW,EAAE,MAAM,CAAA;KAAE,EAAE,CAAC;IACnD,OAAO,CAAC,EAAE,MAAM,GAAG,MAAM,EAAE,CAAC;CAC7B,CAAC;AAEF,iGAAiG;AACjG,MAAM,MAAM,mBAAmB,GAAG;IAChC,wBAAwB,CAAC,EAAE,MAAM,CAAC;IAClC,uBAAuB,CAAC,EAAE,MAAM,CAAC;IACjC,+BAA+B,CAAC,EAAE,MAAM,CAAC;IACzC,gCAAgC,CAAC,EAAE,MAAM,CAAC;CAC3C,CAAC;AAEF,yFAAyF;AACzF,MAAM,MAAM,cAAc,GAAG;IAC3B,2BAA2B,CAAC,E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oot":"","sources":["../../../src/talkpilot/clientsConfig/clientsConfig.types.ts"],"names":[],"mappings":";;;
|
|
1
|
+
{"version":3,"file":"clientsConfig.types.js","sourceRoot":"","sources":["../../../src/talkpilot/clientsConfig/clientsConfig.types.ts"],"names":[],"mappings":";;;AA+Ba,QAAA,kBAAkB,GAAG;IAChC,WAAW;IACX,SAAS;IACT,aAAa;CACL,CAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"db-utils.d.ts","sourceRoot":"","sources":["../../src/test-utils/db-utils.ts"],"names":[],"mappings":"AACA,OAAO,EAAe,EAAE,EAAE,MAAM,SAAS,CAAC;
|
|
1
|
+
{"version":3,"file":"db-utils.d.ts","sourceRoot":"","sources":["../../src/test-utils/db-utils.ts"],"names":[],"mappings":"AACA,OAAO,EAAe,EAAE,EAAE,MAAM,SAAS,CAAC;AAW1C,wBAAsB,UAAU,IAAI,OAAO,CAAC,EAAE,CAAC,CAe9C;AAED,wBAAsB,WAAW,IAAI,OAAO,CAAC,IAAI,CAAC,CAGjD"}
|
|
@@ -16,9 +16,11 @@ async function initTestDb() {
|
|
|
16
16
|
const talkpilotDb = client.db();
|
|
17
17
|
const municipalDb = client.db("municipal-data");
|
|
18
18
|
const websitalkDb = client.db("website-talk");
|
|
19
|
+
const configurationDb = client.db("configuration");
|
|
19
20
|
(0, index_1.setDb)(talkpilotDb);
|
|
20
21
|
(0, index_1.setMunicipalDataDb)(municipalDb);
|
|
21
22
|
(0, index_1.setWebsitalkDb)(websitalkDb);
|
|
23
|
+
(0, index_1.setConfigurationDb)(configurationDb);
|
|
22
24
|
return talkpilotDb;
|
|
23
25
|
}
|
|
24
26
|
async function closeTestDb() {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"db-utils.js","sourceRoot":"","sources":["../../src/test-utils/db-utils.ts"],"names":[],"mappings":";;
|
|
1
|
+
{"version":3,"file":"db-utils.js","sourceRoot":"","sources":["../../src/test-utils/db-utils.ts"],"names":[],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oc {
|
|
9
|
+
_id: string;
|
|
10
|
+
key: string;
|
|
11
|
+
value: string;
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
describe("buildSetOp", () => {
|
|
15
|
+
it("returns a plain $set updateOne with no upsert", () => {
|
|
16
|
+
const op = buildSetOp<TestDoc>({ key: "k1" }, { value: "v2" });
|
|
17
|
+
expect(op).toEqual({
|
|
18
|
+
updateOne: { filter: { key: "k1" }, update: { $set: { value: "v2" } } },
|
|
19
|
+
});
|
|
20
|
+
});
|
|
21
|
+
});
|
|
22
|
+
|
|
23
|
+
describe("buildUpsertOp", () => {
|
|
24
|
+
it("returns $set + $setOnInsert + upsert:true", () => {
|
|
25
|
+
const op = buildUpsertOp<TestDoc>(
|
|
26
|
+
{ key: "k1" },
|
|
27
|
+
{ value: "v1" },
|
|
28
|
+
{ key: "k1" },
|
|
29
|
+
);
|
|
30
|
+
expect(op).toEqual({
|
|
31
|
+
updateOne: {
|
|
32
|
+
filter: { key: "k1" },
|
|
33
|
+
update: { $set: { value: "v1" }, $setOnInsert: { key: "k1" } },
|
|
34
|
+
upsert: true,
|
|
35
|
+
},
|
|
36
|
+
});
|
|
37
|
+
});
|
|
38
|
+
|
|
39
|
+
it("defaults $setOnInsert to an empty object when omitted", () => {
|
|
40
|
+
const op = buildUpsertOp<TestDoc>({ key: "k1" }, { value: "v1" });
|
|
41
|
+
expect(op).toEqual({
|
|
42
|
+
updateOne: {
|
|
43
|
+
filter: { key: "k1" },
|
|
44
|
+
update: { $set: { value: "v1" }, $setOnInsert: {} },
|
|
45
|
+
upsert: true,
|
|
46
|
+
},
|
|
47
|
+
});
|
|
48
|
+
});
|
|
49
|
+
});
|
|
50
|
+
|
|
51
|
+
describe("buildInsertOp", () => {
|
|
52
|
+
it("returns an insertOne with the given document", () => {
|
|
53
|
+
const op = buildInsertOp<TestDoc>({ _id: "1", key: "k1", value: "v1" });
|
|
54
|
+
expect(op).toEqual({
|
|
55
|
+
insertOne: { document: { _id: "1", key: "k1", value: "v1" } },
|
|
56
|
+
});
|
|
57
|
+
});
|
|
58
|
+
});
|
|
59
|
+
|
|
60
|
+
describe("buildDeleteOp", () => {
|
|
61
|
+
it("returns a deleteOne matching filter", () => {
|
|
62
|
+
const op = buildDeleteOp<TestDoc>({ key: "k1" });
|
|
63
|
+
expect(op).toEqual({ deleteOne: { filter: { key: "k1" } } });
|
|
64
|
+
});
|
|
65
|
+
});
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
import { Document, Filter, OptionalId } from "mongodb";
|
|
2
|
+
import { BulkWriteOp } from "./bulkWrite.types";
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* Updates specific fields on the record matching filter.
|
|
6
|
+
* Does nothing if no record matches.
|
|
7
|
+
*/
|
|
8
|
+
export function buildSetOp<T extends Document>(
|
|
9
|
+
filter: Filter<T>,
|
|
10
|
+
setFields: Partial<T>,
|
|
11
|
+
): BulkWriteOp<T> {
|
|
12
|
+
return { updateOne: { filter, update: { $set: setFields } } };
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
/**
|
|
16
|
+
* Updates specific fields on the record matching the filter or creates a new record if none matches.
|
|
17
|
+
* setOnInsertFields are only applied when a new record is created; they're ignored on an update.
|
|
18
|
+
*/
|
|
19
|
+
export function buildUpsertOp<T extends Document>(
|
|
20
|
+
filter: Filter<T>,
|
|
21
|
+
setFields: Partial<T>,
|
|
22
|
+
setOnInsertFields: Partial<T> = {},
|
|
23
|
+
): BulkWriteOp<T> {
|
|
24
|
+
return {
|
|
25
|
+
updateOne: {
|
|
26
|
+
filter,
|
|
27
|
+
update: { $set: setFields, $setOnInsert: setOnInsertFields },
|
|
28
|
+
upsert: true,
|
|
29
|
+
},
|
|
30
|
+
};
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
/** Creates a new record. */
|
|
34
|
+
export function buildInsertOp<T extends Document>(
|
|
35
|
+
document: OptionalId<T>,
|
|
36
|
+
): BulkWriteOp<T> {
|
|
37
|
+
return { insertOne: { document } };
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
/** Permanently removes the record matching the filter. */
|
|
41
|
+
export function buildDeleteOp<T extends Document>(
|
|
42
|
+
filter: Filter<T>,
|
|
43
|
+
): BulkWriteOp<T> {
|
|
44
|
+
return { deleteOne: { filter } };
|
|
45
|
+
}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { Db, ObjectId as MongoObjectId } from "mongodb";
|
|
2
|
+
|
|
3
|
+
export * from "./prompts";
|
|
4
|
+
export { configurationMongodbClient } from "./mongodb-client";
|
|
5
|
+
|
|
6
|
+
let db: Db;
|
|
7
|
+
export const setDb = (d: Db) => {
|
|
8
|
+
db = d;
|
|
9
|
+
};
|
|
10
|
+
|
|
11
|
+
export const getDb = (): Db => {
|
|
12
|
+
if (!db) throw new Error("Configuration DB not initialised");
|
|
13
|
+
return db;
|
|
14
|
+
};
|
|
15
|
+
export const ObjectId = MongoObjectId;
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
import { MongoClient, Db } from "mongodb";
|
|
2
|
+
import { setDb } from "./index";
|
|
3
|
+
import { validateConfig, validateMongoUri } from "../utils/validation";
|
|
4
|
+
|
|
5
|
+
class ConfigurationMongoDBClient {
|
|
6
|
+
private client: MongoClient | null = null;
|
|
7
|
+
private db: Db | null = null;
|
|
8
|
+
private readonly defaultDbName = "configuration";
|
|
9
|
+
|
|
10
|
+
async connect(uri?: string, dbName?: string): Promise<void> {
|
|
11
|
+
if (this.client) {
|
|
12
|
+
return;
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
const mongodbUri = uri || process.env.MONGO_URI || process.env.MONGODB_URI;
|
|
16
|
+
validateConfig("MONGO_URI", mongodbUri);
|
|
17
|
+
validateMongoUri(mongodbUri!);
|
|
18
|
+
|
|
19
|
+
try {
|
|
20
|
+
this.client = new MongoClient(mongodbUri!);
|
|
21
|
+
await this.client.connect();
|
|
22
|
+
const targetDbName =
|
|
23
|
+
dbName || process.env.CONFIGURATION_DB_NAME || this.defaultDbName;
|
|
24
|
+
this.db = this.client.db(targetDbName);
|
|
25
|
+
setDb(this.db);
|
|
26
|
+
console.info(`[core-db] Configuration MongoDB connected: ${targetDbName}`);
|
|
27
|
+
} catch (error) {
|
|
28
|
+
console.error("[core-db] Configuration connection failed", error);
|
|
29
|
+
throw error;
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
async disconnect(): Promise<void> {
|
|
34
|
+
if (this.client) {
|
|
35
|
+
try {
|
|
36
|
+
await this.client.close();
|
|
37
|
+
this.client = null;
|
|
38
|
+
this.db = null;
|
|
39
|
+
console.info("Configuration MongoDB disconnected successfully");
|
|
40
|
+
} catch (error) {
|
|
41
|
+
console.error("[core-db] Configuration disconnection failed", error);
|
|
42
|
+
throw error;
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
getDb(): Db {
|
|
48
|
+
if (!this.db) {
|
|
49
|
+
throw new Error(
|
|
50
|
+
"Configuration database not initialized. Call connect() first.",
|
|
51
|
+
);
|
|
52
|
+
}
|
|
53
|
+
return this.db;
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
isConnected(): boolean {
|
|
57
|
+
return this.client !== null && this.client !== undefined;
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
export const configurationMongodbClient = new ConfigurationMongoDBClient();
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import { getDb } from "../index";
|
|
2
|
+
import { Collection, Filter } from "mongodb";
|
|
3
|
+
import { Prompt } from "./prompts.types";
|
|
4
|
+
|
|
5
|
+
export const getPromptsCollection = (): Collection<Prompt> => {
|
|
6
|
+
return getDb().collection<Prompt>("Prompts");
|
|
7
|
+
};
|
|
8
|
+
|
|
9
|
+
/**
|
|
10
|
+
* Get a prompt by its unique name.
|
|
11
|
+
* @param name prompt name
|
|
12
|
+
* @returns the prompt or null if not found
|
|
13
|
+
*/
|
|
14
|
+
export const getPromptByName = async (
|
|
15
|
+
name: string,
|
|
16
|
+
): Promise<Prompt | null> => {
|
|
17
|
+
return await getPromptsCollection().findOne({ name });
|
|
18
|
+
};
|
|
19
|
+
|
|
20
|
+
/**
|
|
21
|
+
* Find prompts by filter.
|
|
22
|
+
* @param filter filter to apply
|
|
23
|
+
* @returns array of matching prompts
|
|
24
|
+
*/
|
|
25
|
+
export const findPrompts = async (
|
|
26
|
+
filter: Filter<Prompt> = {},
|
|
27
|
+
): Promise<Prompt[]> => {
|
|
28
|
+
return await getPromptsCollection().find(filter).toArray();
|
|
29
|
+
};
|
|
30
|
+
|
|
31
|
+
/**
|
|
32
|
+
* Get all prompts.
|
|
33
|
+
* @returns array of all prompts
|
|
34
|
+
*/
|
|
35
|
+
export const getAllPrompts = async (): Promise<Prompt[]> => {
|
|
36
|
+
return await findPrompts();
|
|
37
|
+
};
|
package/src/connection.ts
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { mongodbClient } from "./talkpilot";
|
|
2
2
|
import { municipalDataMongodbClient } from "./municipal";
|
|
3
3
|
import { websitalkMongodbClient } from "./websitalk";
|
|
4
|
+
import { configurationMongodbClient } from "./configuration";
|
|
4
5
|
|
|
5
6
|
let isConnected = false;
|
|
6
7
|
|
|
@@ -17,6 +18,7 @@ export async function ensureDbConnected() {
|
|
|
17
18
|
const talkpilotUri = mongoUri;
|
|
18
19
|
const municipalUri = mongoUri;
|
|
19
20
|
const websiteTalkUri = mongoUri;
|
|
21
|
+
const configurationUri = mongoUri;
|
|
20
22
|
|
|
21
23
|
if (!talkpilotUri) {
|
|
22
24
|
console.warn("[core-db] MONGO_URI is not set");
|
|
@@ -50,6 +52,16 @@ export async function ensureDbConnected() {
|
|
|
50
52
|
);
|
|
51
53
|
}
|
|
52
54
|
|
|
55
|
+
if (!configurationUri) {
|
|
56
|
+
console.warn("[core-db] MONGO_URI is not set");
|
|
57
|
+
} else {
|
|
58
|
+
const dbName = process.env.CONFIGURATION_DB_NAME;
|
|
59
|
+
await configurationMongodbClient.connect(configurationUri, dbName);
|
|
60
|
+
console.info(
|
|
61
|
+
`[core-db] Connected to Configuration MongoDB: ${dbName || "configuration (default)"}`,
|
|
62
|
+
);
|
|
63
|
+
}
|
|
64
|
+
|
|
53
65
|
isConnected = true;
|
|
54
66
|
}
|
|
55
67
|
|
|
@@ -62,6 +74,7 @@ export async function disconnectDb(): Promise<void> {
|
|
|
62
74
|
mongodbClient.disconnect(),
|
|
63
75
|
municipalDataMongodbClient.disconnect(),
|
|
64
76
|
websitalkMongodbClient.disconnect(),
|
|
77
|
+
configurationMongodbClient.disconnect(),
|
|
65
78
|
]);
|
|
66
79
|
isConnected = false;
|
|
67
80
|
}
|
package/src/index.ts
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
// TalkPilot DB exports
|
|
2
2
|
export * from "./talkpilot";
|
|
3
3
|
export * from "./connection";
|
|
4
|
+
export * from "./bulkWrite";
|
|
4
5
|
|
|
5
6
|
export {
|
|
6
7
|
municipalDataMongodbClient,
|
|
@@ -25,3 +26,16 @@ export {
|
|
|
25
26
|
export * from "./websitalk/scans/scans.getters";
|
|
26
27
|
export type * from "./websitalk/scans/scans.types";
|
|
27
28
|
export * from "./websitalk/websiteUrls";
|
|
29
|
+
|
|
30
|
+
export {
|
|
31
|
+
configurationMongodbClient,
|
|
32
|
+
getDb as getConfigurationDb,
|
|
33
|
+
setDb as setConfigurationDb,
|
|
34
|
+
} from "./configuration";
|
|
35
|
+
export * from "./configuration/prompts";
|
|
36
|
+
|
|
37
|
+
export { ObjectId } from "mongodb";
|
|
38
|
+
export type { Filter } from "mongodb";
|
|
39
|
+
export type { AnyBulkWriteOperation as BulkWriteOp } from "mongodb";
|
|
40
|
+
export { MongoBulkWriteError as BulkWriteError } from "mongodb";
|
|
41
|
+
export type { OptionalUnlessRequiredId } from "mongodb";
|