@talkpilot/core-db 1.3.34 → 1.3.35
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 -54
- package/dist/config.d.ts +9 -0
- package/dist/config.d.ts.map +1 -0
- package/dist/config.js +12 -0
- package/dist/config.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 +57 -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 +28 -0
- package/dist/configuration/prompts/prompts.getters.d.ts.map +1 -0
- package/dist/configuration/prompts/prompts.getters.js +44 -0
- package/dist/configuration/prompts/prompts.getters.js.map +1 -0
- package/dist/configuration/prompts/prompts.types.d.ts +11 -0
- package/dist/configuration/prompts/prompts.types.d.ts.map +1 -0
- package/dist/{talkpilot/clients/clients.quota.types.js → configuration/prompts/prompts.types.js} +1 -1
- package/dist/configuration/prompts/prompts.types.js.map +1 -0
- package/dist/connection.d.ts.map +1 -1
- package/dist/connection.js +12 -0
- package/dist/connection.js.map +1 -1
- package/dist/index.d.ts +2 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +6 -1
- package/dist/index.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/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/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/config.ts +9 -0
- package/src/configuration/index.ts +15 -0
- package/src/configuration/mongodb-client.ts +62 -0
- package/src/configuration/prompts/index.ts +2 -0
- package/src/configuration/prompts/prompts.getters.ts +49 -0
- package/src/configuration/prompts/prompts.types.ts +11 -0
- package/src/connection.ts +14 -0
- package/src/index.ts +7 -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
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.computeReconcileDiff = computeReconcileDiff;
|
|
4
|
+
function computeReconcileDiff(config, now = new Date()) {
|
|
5
|
+
const { source, dbRecords, getSourceKey, getDbKey, buildInsertOp, buildUpdateOp, buildDeactivateOp, shouldDeactivate = () => true, } = config;
|
|
6
|
+
const dbByKey = new Map(dbRecords.map((dbRecord) => [getDbKey(dbRecord), dbRecord]));
|
|
7
|
+
const sourceKeys = new Set();
|
|
8
|
+
const bulkOps = [];
|
|
9
|
+
const counts = { inserted: 0, updated: 0, deactivated: 0, exists: 0 };
|
|
10
|
+
for (const sourceRecord of source) {
|
|
11
|
+
const key = getSourceKey(sourceRecord);
|
|
12
|
+
sourceKeys.add(key);
|
|
13
|
+
const dbRecord = dbByKey.get(key);
|
|
14
|
+
if (!dbRecord) {
|
|
15
|
+
bulkOps.push(buildInsertOp(sourceRecord, now));
|
|
16
|
+
counts.inserted++;
|
|
17
|
+
continue;
|
|
18
|
+
}
|
|
19
|
+
const updateOp = buildUpdateOp(sourceRecord, dbRecord, now);
|
|
20
|
+
if (updateOp) {
|
|
21
|
+
bulkOps.push(updateOp);
|
|
22
|
+
counts.updated++;
|
|
23
|
+
}
|
|
24
|
+
else {
|
|
25
|
+
counts.exists++;
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
for (const dbRecord of dbRecords) {
|
|
29
|
+
if (!sourceKeys.has(getDbKey(dbRecord)) && shouldDeactivate(dbRecord)) {
|
|
30
|
+
bulkOps.push(buildDeactivateOp(dbRecord, now));
|
|
31
|
+
counts.deactivated++;
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
return { bulkOps, counts };
|
|
35
|
+
}
|
|
36
|
+
//# sourceMapping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AAC,CAAC;QAC5D,IAAI,QAAQ,EAAE,CAAC;YACb,OAAO,CAAC,IAAI,CAAC,QAAQ,CAAC,CAAC;YACvB,MAAM,CAAC,OAAO,EAAE,CAAC;QACnB,CAAC;aAAM,CAAC;YACN,MAAM,CAAC,MAAM,EAAE,CAAC;QAClB,CAAC;IACH,CAAC;IAED,KAAK,MAAM,QAAQ,IAAI,SAAS,EAAE,CAAC;QACjC,IAAI,CAAC,UAAU,CAAC,GAAG,CAAC,QAAQ,CAAC,QAAQ,CAAC,CAAC,IAAI,gBAAgB,CAAC,QAAQ,CAAC,EAAE,CAAC;YACtE,OAAO,CAAC,IAAI,CAAC,iBAAiB,CAAC,QAAQ,EAAE,GAAG,CAAC,CAAC,CAAC;YAC/C,MAAM,CAAC,WAAW,EAAE,CAAC;QACvB,CAAC;IACH,CAAC;IAED,OAAO,EAAE,OAAO,EAAE,MAAM,EAAE,CAAC;AAC7B,CAAC"}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import { BulkWriteOptions, Collection, Document } from "mongodb";
|
|
2
|
+
import { BulkWriteOp } from "./reconcile.types";
|
|
3
|
+
export interface ExecuteReconcileBulkWriteResult {
|
|
4
|
+
errors: string[];
|
|
5
|
+
}
|
|
6
|
+
export declare function executeReconcileBulkWrite<TDb extends Document>(collection: Collection<TDb>, bulkOps: BulkWriteOp<TDb>[], options?: BulkWriteOptions): Promise<ExecuteReconcileBulkWriteResult>;
|
|
7
|
+
//# sourceMappingURL=reconcile.execute.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"reconcile.execute.d.ts","sourceRoot":"","sources":["../../src/reconcile/reconcile.execute.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,gBAAgB,EAAE,UAAU,EAAE,QAAQ,EAAuB,MAAM,SAAS,CAAC;AACtF,OAAO,EAAE,WAAW,EAAE,MAAM,mBAAmB,CAAC;AAEhD,MAAM,WAAW,+BAA+B;IAC9C,MAAM,EAAE,MAAM,EAAE,CAAC;CAClB;AAED,wBAAsB,yBAAyB,CAAC,GAAG,SAAS,QAAQ,EAClE,UAAU,EAAE,UAAU,CAAC,GAAG,CAAC,EAC3B,OAAO,EAAE,WAAW,CAAC,GAAG,CAAC,EAAE,EAC3B,OAAO,GAAE,gBAAqC,GAC7C,OAAO,CAAC,+BAA+B,CAAC,CAa1C"}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.executeReconcileBulkWrite = executeReconcileBulkWrite;
|
|
4
|
+
const mongodb_1 = require("mongodb");
|
|
5
|
+
async function executeReconcileBulkWrite(collection, bulkOps, options = { ordered: false }) {
|
|
6
|
+
if (bulkOps.length === 0)
|
|
7
|
+
return { errors: [] };
|
|
8
|
+
try {
|
|
9
|
+
await collection.bulkWrite(bulkOps, options);
|
|
10
|
+
return { errors: [] };
|
|
11
|
+
}
|
|
12
|
+
catch (err) {
|
|
13
|
+
if (err instanceof mongodb_1.MongoBulkWriteError) {
|
|
14
|
+
const writeErrors = [err.writeErrors].flat();
|
|
15
|
+
return { errors: writeErrors.map((writeError) => `Write error: ${writeError.errmsg}`) };
|
|
16
|
+
}
|
|
17
|
+
return { errors: [err instanceof Error ? err.message : String(err)] };
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
//# sourceMappingURL=reconcile.execute.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"reconcile.execute.js","sourceRoot":"","sources":["../../src/reconcile/reconcile.execute.ts"],"names":[],"mappings":";;AAOA,8DAiBC;AAxBD,qCAAsF;AAO/E,KAAK,UAAU,yBAAyB,CAC7C,UAA2B,EAC3B,OAA2B,EAC3B,UAA4B,EAAE,OAAO,EAAE,KAAK,EAAE;IAE9C,IAAI,OAAO,CAAC,MAAM,KAAK,CAAC;QAAE,OAAO,EAAE,MAAM,EAAE,EAAE,EAAE,CAAC;IAEhD,IAAI,CAAC;QACH,MAAM,UAAU,CAAC,SAAS,CAAC,OAAO,EAAE,OAAO,CAAC,CAAC;QAC7C,OAAO,EAAE,MAAM,EAAE,EAAE,EAAE,CAAC;IACxB,CAAC;IAAC,OAAO,GAAG,EAAE,CAAC;QACb,IAAI,GAAG,YAAY,6BAAmB,EAAE,CAAC;YACvC,MAAM,WAAW,GAAG,CAAC,GAAG,CAAC,WAAW,CAAC,CAAC,IAAI,EAAE,CAAC;YAC7C,OAAO,EAAE,MAAM,EAAE,WAAW,CAAC,GAAG,CAAC,CAAC,UAAU,EAAE,EAAE,CAAC,gBAAgB,UAAU,CAAC,MAAM,EAAE,CAAC,EAAE,CAAC;QAC1F,CAAC;QACD,OAAO,EAAE,MAAM,EAAE,CAAC,GAAG,YAAY,KAAK,CAAC,CAAC,CAAC,GAAG,CAAC,OAAO,CAAC,CAAC,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC,EAAE,CAAC;IACxE,CAAC;AACH,CAAC"}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { Document, Filter } from "mongodb";
|
|
2
|
+
import { BulkWriteOp } from "./reconcile.types";
|
|
3
|
+
/**
|
|
4
|
+
* updateOne with a plain $set — e.g. a deactivation:
|
|
5
|
+
* buildSetOp({ _id }, { isActive: false, updatedAt: now })
|
|
6
|
+
*/
|
|
7
|
+
export declare function buildSetOp<T extends Document>(filter: Filter<T>, setFields: Partial<T>): BulkWriteOp<T>;
|
|
8
|
+
/**
|
|
9
|
+
* updateOne with $set + $setOnInsert + upsert:true.
|
|
10
|
+
*/
|
|
11
|
+
export declare function buildUpsertOp<T extends Document>(filter: Filter<T>, setFields: Partial<T>, setOnInsertFields?: Partial<T>): BulkWriteOp<T>;
|
|
12
|
+
//# sourceMappingURL=reconcile.ops.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"reconcile.ops.d.ts","sourceRoot":"","sources":["../../src/reconcile/reconcile.ops.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,EAAE,MAAM,SAAS,CAAC;AAC3C,OAAO,EAAE,WAAW,EAAE,MAAM,mBAAmB,CAAC;AAEhD;;;GAGG;AACH,wBAAgB,UAAU,CAAC,CAAC,SAAS,QAAQ,EAAE,MAAM,EAAE,MAAM,CAAC,CAAC,CAAC,EAAE,SAAS,EAAE,OAAO,CAAC,CAAC,CAAC,GAAG,WAAW,CAAC,CAAC,CAAC,CAEvG;AAED;;GAEG;AACH,wBAAgB,aAAa,CAAC,CAAC,SAAS,QAAQ,EAC9C,MAAM,EAAE,MAAM,CAAC,CAAC,CAAC,EACjB,SAAS,EAAE,OAAO,CAAC,CAAC,CAAC,EACrB,iBAAiB,GAAE,OAAO,CAAC,CAAC,CAAM,GACjC,WAAW,CAAC,CAAC,CAAC,CAQhB"}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.buildSetOp = buildSetOp;
|
|
4
|
+
exports.buildUpsertOp = buildUpsertOp;
|
|
5
|
+
/**
|
|
6
|
+
* updateOne with a plain $set — e.g. a deactivation:
|
|
7
|
+
* buildSetOp({ _id }, { isActive: false, updatedAt: now })
|
|
8
|
+
*/
|
|
9
|
+
function buildSetOp(filter, setFields) {
|
|
10
|
+
return { updateOne: { filter, update: { $set: setFields } } };
|
|
11
|
+
}
|
|
12
|
+
/**
|
|
13
|
+
* updateOne with $set + $setOnInsert + upsert:true.
|
|
14
|
+
*/
|
|
15
|
+
function buildUpsertOp(filter, setFields, setOnInsertFields = {}) {
|
|
16
|
+
return {
|
|
17
|
+
updateOne: {
|
|
18
|
+
filter,
|
|
19
|
+
update: { $set: setFields, $setOnInsert: setOnInsertFields },
|
|
20
|
+
upsert: true,
|
|
21
|
+
},
|
|
22
|
+
};
|
|
23
|
+
}
|
|
24
|
+
//# sourceMappingURL=reconcile.ops.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"reconcile.ops.js","sourceRoot":"","sources":["../../src/reconcile/reconcile.ops.ts"],"names":[],"mappings":";;AAOA,gCAEC;AAKD,sCAYC;AAvBD;;;GAGG;AACH,SAAgB,UAAU,CAAqB,MAAiB,EAAE,SAAqB;IACrF,OAAO,EAAE,SAAS,EAAE,EAAE,MAAM,EAAE,MAAM,EAAE,EAAE,IAAI,EAAE,SAAS,EAAE,EAAE,EAAE,CAAC;AAChE,CAAC;AAED;;GAEG;AACH,SAAgB,aAAa,CAC3B,MAAiB,EACjB,SAAqB,EACrB,oBAAgC,EAAE;IAElC,OAAO;QACL,SAAS,EAAE;YACT,MAAM;YACN,MAAM,EAAE,EAAE,IAAI,EAAE,SAAS,EAAE,YAAY,EAAE,iBAAiB,EAAE;YAC5D,MAAM,EAAE,IAAI;SACb;KACF,CAAC;AACJ,CAAC"}
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import { AnyBulkWriteOperation, Document } from "mongodb";
|
|
2
|
+
export type BulkWriteOp<T extends Document> = AnyBulkWriteOperation<T>;
|
|
3
|
+
export interface ReconcileCounts {
|
|
4
|
+
inserted: number;
|
|
5
|
+
updated: number;
|
|
6
|
+
deactivated: number;
|
|
7
|
+
exists: number;
|
|
8
|
+
}
|
|
9
|
+
export interface ReconcileDiffResult<TDb extends Document> {
|
|
10
|
+
bulkOps: BulkWriteOp<TDb>[];
|
|
11
|
+
counts: ReconcileCounts;
|
|
12
|
+
}
|
|
13
|
+
export interface ReconcileConfig<TSource, TDb extends Document, TKey extends string | number> {
|
|
14
|
+
source: TSource[];
|
|
15
|
+
dbRecords: TDb[];
|
|
16
|
+
getSourceKey: (source: TSource) => TKey;
|
|
17
|
+
getDbKey: (dbRecord: TDb) => TKey;
|
|
18
|
+
buildInsertOp: (source: TSource, now: Date) => BulkWriteOp<TDb>;
|
|
19
|
+
/** Return null when unchanged — counted as `exists`, no op emitted. */
|
|
20
|
+
buildUpdateOp: (source: TSource, existing: TDb, now: Date) => BulkWriteOp<TDb> | null;
|
|
21
|
+
/**
|
|
22
|
+
* Called for every dbRecord missing from source (and passing shouldDeactivate).
|
|
23
|
+
* The caller decides the op shape entirely — typically via buildSetOp.
|
|
24
|
+
*/
|
|
25
|
+
buildDeactivateOp: (dbRecord: TDb, now: Date) => BulkWriteOp<TDb>;
|
|
26
|
+
/**
|
|
27
|
+
* Whether a missing dbRecord should even be considered for deactivation.
|
|
28
|
+
* Defaults to always true — core-db has no opinion on what "already inactive" means.
|
|
29
|
+
*/
|
|
30
|
+
shouldDeactivate?: (dbRecord: TDb) => boolean;
|
|
31
|
+
}
|
|
32
|
+
//# sourceMappingURL=reconcile.types.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"reconcile.types.d.ts","sourceRoot":"","sources":["../../src/reconcile/reconcile.types.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,qBAAqB,EAAE,QAAQ,EAAE,MAAM,SAAS,CAAC;AAE1D,MAAM,MAAM,WAAW,CAAC,CAAC,SAAS,QAAQ,IAAI,qBAAqB,CAAC,CAAC,CAAC,CAAC;AAEvE,MAAM,WAAW,eAAe;IAC9B,QAAQ,EAAE,MAAM,CAAC;IACjB,OAAO,EAAE,MAAM,CAAC;IAChB,WAAW,EAAE,MAAM,CAAC;IACpB,MAAM,EAAE,MAAM,CAAC;CAChB;AAED,MAAM,WAAW,mBAAmB,CAAC,GAAG,SAAS,QAAQ;IACvD,OAAO,EAAE,WAAW,CAAC,GAAG,CAAC,EAAE,CAAC;IAC5B,MAAM,EAAE,eAAe,CAAC;CACzB;AAED,MAAM,WAAW,eAAe,CAAC,OAAO,EAAE,GAAG,SAAS,QAAQ,EAAE,IAAI,SAAS,MAAM,GAAG,MAAM;IAC1F,MAAM,EAAE,OAAO,EAAE,CAAC;IAClB,SAAS,EAAE,GAAG,EAAE,CAAC;IACjB,YAAY,EAAE,CAAC,MAAM,EAAE,OAAO,KAAK,IAAI,CAAC;IACxC,QAAQ,EAAE,CAAC,QAAQ,EAAE,GAAG,KAAK,IAAI,CAAC;IAClC,aAAa,EAAE,CAAC,MAAM,EAAE,OAAO,EAAE,GAAG,EAAE,IAAI,KAAK,WAAW,CAAC,GAAG,CAAC,CAAC;IAChE,uEAAuE;IACvE,aAAa,EAAE,CAAC,MAAM,EAAE,OAAO,EAAE,QAAQ,EAAE,GAAG,EAAE,GAAG,EAAE,IAAI,KAAK,WAAW,CAAC,GAAG,CAAC,GAAG,IAAI,CAAC;IACtF;;;OAGG;IACH,iBAAiB,EAAE,CAAC,QAAQ,EAAE,GAAG,EAAE,GAAG,EAAE,IAAI,KAAK,WAAW,CAAC,GAAG,CAAC,CAAC;IAClE;;;OAGG;IACH,gBAAgB,CAAC,EAAE,CAAC,QAAQ,EAAE,GAAG,KAAK,OAAO,CAAC;CAC/C"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"reconcile.types.js","sourceRoot":"","sources":["../../src/reconcile/reconcile.types.ts"],"names":[],"mappings":""}
|
|
@@ -1,6 +1,4 @@
|
|
|
1
1
|
import { ObjectId } from "mongodb";
|
|
2
|
-
import { ClientQuotaSettings } from "./clients.quota.types";
|
|
3
|
-
export type { QuotaThresholdAlert, ClientQuotaSettings, QuotaAlertInput, ClientQuotaUsage, ClientQuotaState } from "./clients.quota.types";
|
|
4
2
|
export type Client = {
|
|
5
3
|
_id?: ObjectId;
|
|
6
4
|
createdAt: Date;
|
|
@@ -10,7 +8,6 @@ export type Client = {
|
|
|
10
8
|
apiKey?: string | null;
|
|
11
9
|
credits: number;
|
|
12
10
|
managedBy?: string;
|
|
13
|
-
quota?: ClientQuotaSettings;
|
|
14
11
|
};
|
|
15
12
|
export type ClientDoc = Client & {
|
|
16
13
|
_id: ObjectId;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"clients.types.d.ts","sourceRoot":"","sources":["../../../src/talkpilot/clients/clients.types.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,SAAS,CAAC;
|
|
1
|
+
{"version":3,"file":"clients.types.d.ts","sourceRoot":"","sources":["../../../src/talkpilot/clients/clients.types.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,SAAS,CAAC;AAEnC,MAAM,MAAM,MAAM,GAAG;IACnB,GAAG,CAAC,EAAE,QAAQ,CAAC;IACf,SAAS,EAAE,IAAI,CAAC;IAChB,SAAS,EAAE,IAAI,CAAC;IAChB,QAAQ,EAAE,MAAM,CAAC;IACjB,QAAQ,CAAC,EAAE,OAAO,GAAG,IAAI,CAAC;IAC1B,MAAM,CAAC,EAAE,MAAM,GAAG,IAAI,CAAC;IACvB,OAAO,EAAE,MAAM,CAAC;IAChB,SAAS,CAAC,EAAE,MAAM,CAAC;CACpB,CAAC;AAEF,MAAM,MAAM,SAAS,GAAG,MAAM,GAAG;IAAE,GAAG,EAAE,QAAQ,CAAA;CAAE,CAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/talkpilot/clients/index.ts"],"names":[],"mappings":"AAAA,cAAc,mBAAmB,CAAC;AAClC,cAAc,iBAAiB,CAAC
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/talkpilot/clients/index.ts"],"names":[],"mappings":"AAAA,cAAc,mBAAmB,CAAC;AAClC,cAAc,iBAAiB,CAAC"}
|
|
@@ -16,6 +16,4 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
|
16
16
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
17
|
__exportStar(require("./clients.getters"), exports);
|
|
18
18
|
__exportStar(require("./clients.types"), exports);
|
|
19
|
-
__exportStar(require("./clients.quota.getters"), exports);
|
|
20
|
-
__exportStar(require("./clients.quota.types"), exports);
|
|
21
19
|
//# sourceMappingURL=index.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/talkpilot/clients/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,oDAAkC;AAClC,kDAAgC
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/talkpilot/clients/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,oDAAkC;AAClC,kDAAgC"}
|
|
@@ -2,15 +2,10 @@ import { ClientConfigDoc, Products, KnownProductKey } from "../index";
|
|
|
2
2
|
import { Collection } from "mongodb";
|
|
3
3
|
export declare const getClientsConfigCollection: () => Collection<ClientConfigDoc>;
|
|
4
4
|
export declare const getClientConfig: (clientId: string) => Promise<import("mongodb").WithId<ClientConfigDoc> | null>;
|
|
5
|
-
export declare const getClientDisplayName: (clientId: string) => Promise<string>;
|
|
6
5
|
export declare const getClientConfigByPhone: (phone: string) => Promise<import("mongodb").WithId<ClientConfigDoc> | null>;
|
|
7
6
|
export declare const createClientConfigDoc: (clientConfig: ClientConfigDoc) => Promise<void>;
|
|
8
7
|
export declare function updateProductConfig<K extends KnownProductKey>(clientId: string, productKey: K, updates: Partial<Products[K]>): Promise<void>;
|
|
9
8
|
export declare const getActiveScanId: (clientId: string) => Promise<string | undefined>;
|
|
10
9
|
export declare const updateActiveScanId: (clientId: string, scanId: string) => Promise<void>;
|
|
11
10
|
export declare const clearActiveScanId: (clientId: string) => Promise<void>;
|
|
12
|
-
export declare function listClientIdsWithConfiguredQuota(): Promise<string[]>;
|
|
13
|
-
export declare function incrementClientQuotaUsage(clientId: string, amount?: number): Promise<void>;
|
|
14
|
-
export declare function resetClientQuotaUsage(clientId: string): Promise<void>;
|
|
15
|
-
export { getClientQuotaState, updateQuotaAlertsConfig, markQuotaAlertSent, markQuotaExpiredSent, resetClientQuotaSettings, } from "../clients/clients.quota.getters";
|
|
16
11
|
//# sourceMappingURL=clientsConfig.getters.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"clientsConfig.getters.d.ts","sourceRoot":"","sources":["../../../src/talkpilot/clientsConfig/clientsConfig.getters.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,eAAe,EAGf,QAAQ,EAER,eAAe,EAChB,MAAM,UAAU,CAAC;AAClB,OAAO,EAAE,UAAU,EAAE,MAAM,SAAS,CAAC;
|
|
1
|
+
{"version":3,"file":"clientsConfig.getters.d.ts","sourceRoot":"","sources":["../../../src/talkpilot/clientsConfig/clientsConfig.getters.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,eAAe,EAGf,QAAQ,EAER,eAAe,EAChB,MAAM,UAAU,CAAC;AAClB,OAAO,EAAE,UAAU,EAAE,MAAM,SAAS,CAAC;AAErC,eAAO,MAAM,0BAA0B,QAAO,UAAU,CAAC,eAAe,CAEvE,CAAC;AAEF,eAAO,MAAM,eAAe,GAAI,UAAU,MAAM,8DAE/C,CAAC;AAEF,eAAO,MAAM,sBAAsB,GAAU,OAAO,MAAM,8DAIzD,CAAC;AAEF,eAAO,MAAM,qBAAqB,GAChC,cAAc,eAAe,KAC5B,OAAO,CAAC,IAAI,CAEd,CAAC;AAEF,wBAAsB,mBAAmB,CAAC,CAAC,SAAS,eAAe,EACjE,QAAQ,EAAE,MAAM,EAChB,UAAU,EAAE,CAAC,EACb,OAAO,EAAE,OAAO,CAAC,QAAQ,CAAC,CAAC,CAAC,CAAC,GAC5B,OAAO,CAAC,IAAI,CAAC,CAoBf;AAED,eAAO,MAAM,eAAe,GAC1B,UAAU,MAAM,KACf,OAAO,CAAC,MAAM,GAAG,SAAS,CAG5B,CAAC;AAEF,eAAO,MAAM,kBAAkB,GAC7B,UAAU,MAAM,EAChB,QAAQ,MAAM,KACb,OAAO,CAAC,IAAI,CAEd,CAAC;AAEF,eAAO,MAAM,iBAAiB,GAAU,UAAU,MAAM,KAAG,OAAO,CAAC,IAAI,CAQtE,CAAC"}
|
|
@@ -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
|
+
{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ACH,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,OAA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AG,OAAO,CAAC;CACxB,CAAC;AAEF,MAAM,MAAM,kBAAkB,GAC1B,QAAQ,GACR,SAAS,GACT,SAAS,GACT,QAAQ,GACR,SAAS,GACT,CAAC,MAAM,GAAG,EAAE,CAAC,CAAC;AAElB,MAAM,MAAM,cAAc,GAAG;IAC3B,OAAO,EAAE,MAAM,EAAE,CAAC;IAClB,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,QAAQ,CAAC,EAAE,MAAM,CAAC;CACnB,CAAC;AAEF,MAAM,MAAM,SAAS,GAAG,EAAE,CAAC;AAE3B,MAAM,MAAM,cAAc,GAAG,EAAE,CAAC;AAEhC,MAAM,MAAM,oBAAoB,GAAG;IACjC,QAAQ,CAAC,EAAE,cAAc,CAAC;IAC1B,GAAG,CAAC,EAAE,SAAS,CAAC;IAChB,QAAQ,CAAC,EAAE,cAAc,CAAC;CAC3B,CAAC;AAEF,MAAM,MAAM,YAAY,CAAC,CAAC,SAAS,QAAQ,GAAG,QAAQ,IAAI;IACxD,QAAQ,EAAE,MAAM,CAAC;IACjB,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,QAAQ,CAAC,EAAE,kBAAkB,CAAC;IAC9B,QAAQ,EAAE,CAAC,CAAC;IACZ,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,cAAc,CAAC,EAAE,oBAAoB,CAAC;IACtC,oBAAoB,CAAC,EAAE,oBAAoB,CAAC;CAC7C,CAAC;AAEF,MAAM,MAAM,eAAe,CAAC,CAAC,SAAS,QAAQ,GAAG,QAAQ,IAAI,MAAM,CACjE,YAAY,CAAC,CAAC,CAAC,CAChB,CAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"clientsConfig.types.js","sourceRoot":"","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":[],"mappings":";;AAYA,gCAeC;AAED,kCAGC;AAhCD,iEAA0D;AAC1D,qCAA0C;AAC1C,oCAKkB;AAElB,IAAI,WAA8B,CAAC;AACnC,IAAI,MAAmB,CAAC;AAEjB,KAAK,UAAU,UAAU;IAC9B,WAAW,GAAG,MAAM,yCAAiB,CAAC,MAAM,CAAC;QAC3C,QAAQ,EAAE,EAAE,EAAE,EAAE,WAAW,EAAE;KAC9B,CAAC,CAAC;IACH,MAAM,GAAG,IAAI,qBAAW,CAAC,WAAW,CAAC,MAAM,EAAE,CAAC,CAAC;IAC/C,MAAM,MAAM,CAAC,OAAO,EAAE,CAAC;IACvB,MAAM,WAAW,GAAG,MAAM,CAAC,EAAE,EAAE,CAAC;IAChC,MAAM,WAAW,GAAG,MAAM,CAAC,EAAE,CAAC,gBAAgB,CAAC,CAAC;IAChD,MAAM,WAAW,GAAG,MAAM,CAAC,EAAE,CAAC,cAAc,CAAC,CAAC;IAC9C,MAAM,eAAe,GAAG,MAAM,CAAC,EAAE,CAAC,eAAe,CAAC,CAAC;IACnD,IAAA,aAAK,EAAC,WAAW,CAAC,CAAC;IACnB,IAAA,0BAAkB,EAAC,WAAW,CAAC,CAAC;IAChC,IAAA,sBAAc,EAAC,WAAW,CAAC,CAAC;IAC5B,IAAA,0BAAkB,EAAC,eAAe,CAAC,CAAC;IACpC,OAAO,WAAW,CAAC;AACrB,CAAC;AAEM,KAAK,UAAU,WAAW;IAC/B,IAAI,MAAM;QAAE,MAAM,MAAM,CAAC,KAAK,EAAE,CAAC;IACjC,IAAI,WAAW;QAAE,MAAM,WAAW,CAAC,IAAI,EAAE,CAAC;AAC5C,CAAC"}
|
package/package.json
CHANGED
package/src/config.ts
ADDED
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Centralized env var access. Add new fields here instead of reading
|
|
3
|
+
* process.env directly elsewhere, so each env var has exactly one source of truth in the code.
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
export const configurationDbConfig = {
|
|
7
|
+
mongoUri: process.env.MONGO_URI || process.env.MONGODB_URI,
|
|
8
|
+
configurationDbName: process.env.CONFIGURATION_DB_NAME,
|
|
9
|
+
};
|
|
@@ -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,62 @@
|
|
|
1
|
+
import { MongoClient, Db } from "mongodb";
|
|
2
|
+
import { setDb } from "./index";
|
|
3
|
+
import { validateConfig, validateMongoUri } from "../utils/validation";
|
|
4
|
+
import { configurationDbConfig } from "../config";
|
|
5
|
+
|
|
6
|
+
class ConfigurationMongoDBClient {
|
|
7
|
+
private client: MongoClient | null = null;
|
|
8
|
+
private db: Db | null = null;
|
|
9
|
+
private readonly defaultDbName = "configuration";
|
|
10
|
+
|
|
11
|
+
async connect(uri?: string, dbName?: string): Promise<void> {
|
|
12
|
+
if (this.client) {
|
|
13
|
+
return;
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
const mongodbUri = uri || configurationDbConfig.mongoUri;
|
|
17
|
+
validateConfig("MONGO_URI", mongodbUri);
|
|
18
|
+
validateMongoUri(mongodbUri!);
|
|
19
|
+
|
|
20
|
+
try {
|
|
21
|
+
this.client = new MongoClient(mongodbUri!);
|
|
22
|
+
await this.client.connect();
|
|
23
|
+
const targetDbName =
|
|
24
|
+
dbName || configurationDbConfig.configurationDbName || this.defaultDbName;
|
|
25
|
+
this.db = this.client.db(targetDbName);
|
|
26
|
+
setDb(this.db);
|
|
27
|
+
console.info(`[core-db] Configuration MongoDB connected: ${targetDbName}`);
|
|
28
|
+
} catch (error) {
|
|
29
|
+
console.error("[core-db] Configuration connection failed", error);
|
|
30
|
+
throw error;
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
async disconnect(): Promise<void> {
|
|
35
|
+
if (this.client) {
|
|
36
|
+
try {
|
|
37
|
+
await this.client.close();
|
|
38
|
+
this.client = null;
|
|
39
|
+
this.db = null;
|
|
40
|
+
console.info("Configuration MongoDB disconnected successfully");
|
|
41
|
+
} catch (error) {
|
|
42
|
+
console.error("[core-db] Configuration disconnection failed", error);
|
|
43
|
+
throw error;
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
getDb(): Db {
|
|
49
|
+
if (!this.db) {
|
|
50
|
+
throw new Error(
|
|
51
|
+
"Configuration database not initialized. Call connect() first.",
|
|
52
|
+
);
|
|
53
|
+
}
|
|
54
|
+
return this.db;
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
isConnected(): boolean {
|
|
58
|
+
return this.client !== null && this.client !== undefined;
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
export const configurationMongodbClient = new ConfigurationMongoDBClient();
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
import { getDb } from "../index";
|
|
2
|
+
import { Collection, Filter } from "mongodb";
|
|
3
|
+
import { Prompt } from "./prompts.types";
|
|
4
|
+
import { KnownProductKey } from "../../talkpilot";
|
|
5
|
+
|
|
6
|
+
export const getPromptsCollection = (): Collection<Prompt> => {
|
|
7
|
+
return getDb().collection<Prompt>("prompts");
|
|
8
|
+
};
|
|
9
|
+
|
|
10
|
+
/**
|
|
11
|
+
* Get a prompt by its unique name.
|
|
12
|
+
* @param name prompt name
|
|
13
|
+
* @returns the prompt or null if not found
|
|
14
|
+
*/
|
|
15
|
+
export const getPromptByName = async (
|
|
16
|
+
name: string,
|
|
17
|
+
): Promise<Prompt | null> => {
|
|
18
|
+
return await getPromptsCollection().findOne({ name });
|
|
19
|
+
};
|
|
20
|
+
|
|
21
|
+
/**
|
|
22
|
+
* Find prompts by filter.
|
|
23
|
+
* @param filter filter to apply
|
|
24
|
+
* @returns array of matching prompts
|
|
25
|
+
*/
|
|
26
|
+
export const findPrompts = async (
|
|
27
|
+
filter: Filter<Prompt> = {},
|
|
28
|
+
): Promise<Prompt[]> => {
|
|
29
|
+
return await getPromptsCollection().find(filter).toArray();
|
|
30
|
+
};
|
|
31
|
+
|
|
32
|
+
/**
|
|
33
|
+
* Get all prompts.
|
|
34
|
+
* @returns array of all prompts
|
|
35
|
+
*/
|
|
36
|
+
export const getAllPrompts = async (): Promise<Prompt[]> => {
|
|
37
|
+
return await findPrompts();
|
|
38
|
+
};
|
|
39
|
+
|
|
40
|
+
/**
|
|
41
|
+
* Get all prompts for a given product.
|
|
42
|
+
* @param productName product key
|
|
43
|
+
* @returns array of matching prompts
|
|
44
|
+
*/
|
|
45
|
+
export const getPromptsByProduct = async (
|
|
46
|
+
productName: KnownProductKey,
|
|
47
|
+
): Promise<Prompt[]> => {
|
|
48
|
+
return await findPrompts({ productName });
|
|
49
|
+
};
|
package/src/connection.ts
CHANGED
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
import { mongodbClient } from "./talkpilot";
|
|
2
2
|
import { municipalDataMongodbClient } from "./municipal";
|
|
3
3
|
import { websitalkMongodbClient } from "./websitalk";
|
|
4
|
+
import { configurationMongodbClient } from "./configuration";
|
|
5
|
+
import { configurationDbConfig } from "./config";
|
|
4
6
|
|
|
5
7
|
let isConnected = false;
|
|
6
8
|
|
|
@@ -17,6 +19,7 @@ export async function ensureDbConnected() {
|
|
|
17
19
|
const talkpilotUri = mongoUri;
|
|
18
20
|
const municipalUri = mongoUri;
|
|
19
21
|
const websiteTalkUri = mongoUri;
|
|
22
|
+
const configurationUri = mongoUri;
|
|
20
23
|
|
|
21
24
|
if (!talkpilotUri) {
|
|
22
25
|
console.warn("[core-db] MONGO_URI is not set");
|
|
@@ -50,6 +53,16 @@ export async function ensureDbConnected() {
|
|
|
50
53
|
);
|
|
51
54
|
}
|
|
52
55
|
|
|
56
|
+
if (!configurationUri) {
|
|
57
|
+
console.warn("[core-db] MONGO_URI is not set");
|
|
58
|
+
} else {
|
|
59
|
+
const dbName = configurationDbConfig.configurationDbName;
|
|
60
|
+
await configurationMongodbClient.connect(configurationUri, dbName);
|
|
61
|
+
console.info(
|
|
62
|
+
`[core-db] Connected to Configuration MongoDB: ${dbName || "configuration (default)"}`,
|
|
63
|
+
);
|
|
64
|
+
}
|
|
65
|
+
|
|
53
66
|
isConnected = true;
|
|
54
67
|
}
|
|
55
68
|
|
|
@@ -62,6 +75,7 @@ export async function disconnectDb(): Promise<void> {
|
|
|
62
75
|
mongodbClient.disconnect(),
|
|
63
76
|
municipalDataMongodbClient.disconnect(),
|
|
64
77
|
websitalkMongodbClient.disconnect(),
|
|
78
|
+
configurationMongodbClient.disconnect(),
|
|
65
79
|
]);
|
|
66
80
|
isConnected = false;
|
|
67
81
|
}
|
package/src/index.ts
CHANGED
|
@@ -27,6 +27,13 @@ export * from "./websitalk/scans/scans.getters";
|
|
|
27
27
|
export type * from "./websitalk/scans/scans.types";
|
|
28
28
|
export * from "./websitalk/websiteUrls";
|
|
29
29
|
|
|
30
|
+
export {
|
|
31
|
+
configurationMongodbClient,
|
|
32
|
+
getDb as getConfigurationDb,
|
|
33
|
+
setDb as setConfigurationDb,
|
|
34
|
+
} from "./configuration";
|
|
35
|
+
export * from "./configuration/prompts";
|
|
36
|
+
|
|
30
37
|
export { ObjectId } from "mongodb";
|
|
31
38
|
export type { Filter } from "mongodb";
|
|
32
39
|
export type { AnyBulkWriteOperation as BulkWriteOp } from "mongodb";
|