@talkpilot/core-db 1.3.33 → 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/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/mongodb-client.d.ts.map +1 -1
- package/dist/configuration/mongodb-client.js +3 -2
- package/dist/configuration/mongodb-client.js.map +1 -1
- package/dist/configuration/prompts/prompts.getters.d.ts +7 -0
- package/dist/configuration/prompts/prompts.getters.d.ts.map +1 -1
- package/dist/configuration/prompts/prompts.getters.js +11 -2
- package/dist/configuration/prompts/prompts.getters.js.map +1 -1
- package/dist/configuration/prompts/prompts.types.d.ts +2 -0
- package/dist/configuration/prompts/prompts.types.d.ts.map +1 -1
- package/dist/connection.d.ts.map +1 -1
- package/dist/connection.js +2 -1
- package/dist/connection.js.map +1 -1
- package/package.json +1 -1
- package/src/config.ts +9 -0
- package/src/configuration/mongodb-client.ts +3 -2
- package/src/configuration/prompts/prompts.getters.ts +13 -1
- package/src/configuration/prompts/prompts.types.ts +2 -1
- package/src/connection.ts +2 -1
package/dist/config.d.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
|
+
export declare const configurationDbConfig: {
|
|
6
|
+
mongoUri: string | undefined;
|
|
7
|
+
configurationDbName: string | undefined;
|
|
8
|
+
};
|
|
9
|
+
//# sourceMappingURL=config.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"config.d.ts","sourceRoot":"","sources":["../src/config.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,eAAO,MAAM,qBAAqB;;;CAGjC,CAAC"}
|
package/dist/config.js
ADDED
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* Centralized env var access. Add new fields here instead of reading
|
|
4
|
+
* process.env directly elsewhere, so each env var has exactly one source of truth in the code.
|
|
5
|
+
*/
|
|
6
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
7
|
+
exports.configurationDbConfig = void 0;
|
|
8
|
+
exports.configurationDbConfig = {
|
|
9
|
+
mongoUri: process.env.MONGO_URI || process.env.MONGODB_URI,
|
|
10
|
+
configurationDbName: process.env.CONFIGURATION_DB_NAME,
|
|
11
|
+
};
|
|
12
|
+
//# sourceMappingURL=config.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"config.js","sourceRoot":"","sources":["../src/config.ts"],"names":[],"mappings":";AAAA;;;GAGG;;;AAEU,QAAA,qBAAqB,GAAG;IACnC,QAAQ,EAAE,OAAO,CAAC,GAAG,CAAC,SAAS,IAAI,OAAO,CAAC,GAAG,CAAC,WAAW;IAC1D,mBAAmB,EAAE,OAAO,CAAC,GAAG,CAAC,qBAAqB;CACvD,CAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"mongodb-client.d.ts","sourceRoot":"","sources":["../../src/configuration/mongodb-client.ts"],"names":[],"mappings":"AAAA,OAAO,EAAe,EAAE,EAAE,MAAM,SAAS,CAAC;
|
|
1
|
+
{"version":3,"file":"mongodb-client.d.ts","sourceRoot":"","sources":["../../src/configuration/mongodb-client.ts"],"names":[],"mappings":"AAAA,OAAO,EAAe,EAAE,EAAE,MAAM,SAAS,CAAC;AAK1C,cAAM,0BAA0B;IAC9B,OAAO,CAAC,MAAM,CAA4B;IAC1C,OAAO,CAAC,EAAE,CAAmB;IAC7B,OAAO,CAAC,QAAQ,CAAC,aAAa,CAAmB;IAE3C,OAAO,CAAC,GAAG,CAAC,EAAE,MAAM,EAAE,MAAM,CAAC,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC;IAuBrD,UAAU,IAAI,OAAO,CAAC,IAAI,CAAC;IAcjC,KAAK,IAAI,EAAE;IASX,WAAW,IAAI,OAAO;CAGvB;AAED,eAAO,MAAM,0BAA0B,4BAAmC,CAAC"}
|
|
@@ -4,6 +4,7 @@ exports.configurationMongodbClient = void 0;
|
|
|
4
4
|
const mongodb_1 = require("mongodb");
|
|
5
5
|
const index_1 = require("./index");
|
|
6
6
|
const validation_1 = require("../utils/validation");
|
|
7
|
+
const config_1 = require("../config");
|
|
7
8
|
class ConfigurationMongoDBClient {
|
|
8
9
|
client = null;
|
|
9
10
|
db = null;
|
|
@@ -12,13 +13,13 @@ class ConfigurationMongoDBClient {
|
|
|
12
13
|
if (this.client) {
|
|
13
14
|
return;
|
|
14
15
|
}
|
|
15
|
-
const mongodbUri = uri ||
|
|
16
|
+
const mongodbUri = uri || config_1.configurationDbConfig.mongoUri;
|
|
16
17
|
(0, validation_1.validateConfig)("MONGO_URI", mongodbUri);
|
|
17
18
|
(0, validation_1.validateMongoUri)(mongodbUri);
|
|
18
19
|
try {
|
|
19
20
|
this.client = new mongodb_1.MongoClient(mongodbUri);
|
|
20
21
|
await this.client.connect();
|
|
21
|
-
const targetDbName = dbName ||
|
|
22
|
+
const targetDbName = dbName || config_1.configurationDbConfig.configurationDbName || this.defaultDbName;
|
|
22
23
|
this.db = this.client.db(targetDbName);
|
|
23
24
|
(0, index_1.setDb)(this.db);
|
|
24
25
|
console.info(`[core-db] Configuration MongoDB connected: ${targetDbName}`);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"mongodb-client.js","sourceRoot":"","sources":["../../src/configuration/mongodb-client.ts"],"names":[],"mappings":";;;AAAA,qCAA0C;AAC1C,mCAAgC;AAChC,oDAAuE;
|
|
1
|
+
{"version":3,"file":"mongodb-client.js","sourceRoot":"","sources":["../../src/configuration/mongodb-client.ts"],"names":[],"mappings":";;;AAAA,qCAA0C;AAC1C,mCAAgC;AAChC,oDAAuE;AACvE,sCAAkD;AAElD,MAAM,0BAA0B;IACtB,MAAM,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AAO,KAAK,EAAE,CAAC;gBACf,OAAO,CAAC,KAAK,CAAC,8CAA8C,EAAE,KAAK,CAAC,CAAC;gBACrE,MAAM,KAAK,CAAC;YACd,CAAC;QACH,CAAC;IACH,CAAC;IAED,KAAK;QACH,IAAI,CAAC,IAAI,CAAC,EAAE,EAAE,CAAC;YACb,MAAM,IAAI,KAAK,CACb,+DAA+D,CAChE,CAAC;QACJ,CAAC;QACD,OAAO,IAAI,CAAC,EAAE,CAAC;IACjB,CAAC;IAED,WAAW;QACT,OAAO,IAAI,CAAC,MAAM,KAAK,IAAI,IAAI,IAAI,CAAC,MAAM,KAAK,SAAS,CAAC;IAC3D,CAAC;CACF;AAEY,QAAA,0BAA0B,GAAG,IAAI,0BAA0B,EAAE,CAAC"}
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { Collection, Filter } from "mongodb";
|
|
2
2
|
import { Prompt } from "./prompts.types";
|
|
3
|
+
import { KnownProductKey } from "../../talkpilot";
|
|
3
4
|
export declare const getPromptsCollection: () => Collection<Prompt>;
|
|
4
5
|
/**
|
|
5
6
|
* Get a prompt by its unique name.
|
|
@@ -18,4 +19,10 @@ export declare const findPrompts: (filter?: Filter<Prompt>) => Promise<Prompt[]>
|
|
|
18
19
|
* @returns array of all prompts
|
|
19
20
|
*/
|
|
20
21
|
export declare const getAllPrompts: () => Promise<Prompt[]>;
|
|
22
|
+
/**
|
|
23
|
+
* Get all prompts for a given product.
|
|
24
|
+
* @param productName product key
|
|
25
|
+
* @returns array of matching prompts
|
|
26
|
+
*/
|
|
27
|
+
export declare const getPromptsByProduct: (productName: KnownProductKey) => Promise<Prompt[]>;
|
|
21
28
|
//# sourceMappingURL=prompts.getters.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"prompts.getters.d.ts","sourceRoot":"","sources":["../../../src/configuration/prompts/prompts.getters.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,UAAU,EAAE,MAAM,EAAE,MAAM,SAAS,CAAC;AAC7C,OAAO,EAAE,MAAM,EAAE,MAAM,iBAAiB,CAAC;
|
|
1
|
+
{"version":3,"file":"prompts.getters.d.ts","sourceRoot":"","sources":["../../../src/configuration/prompts/prompts.getters.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,UAAU,EAAE,MAAM,EAAE,MAAM,SAAS,CAAC;AAC7C,OAAO,EAAE,MAAM,EAAE,MAAM,iBAAiB,CAAC;AACzC,OAAO,EAAE,eAAe,EAAE,MAAM,iBAAiB,CAAC;AAElD,eAAO,MAAM,oBAAoB,QAAO,UAAU,CAAC,MAAM,CAExD,CAAC;AAEF;;;;GAIG;AACH,eAAO,MAAM,eAAe,GAC1B,MAAM,MAAM,KACX,OAAO,CAAC,MAAM,GAAG,IAAI,CAEvB,CAAC;AAEF;;;;GAIG;AACH,eAAO,MAAM,WAAW,GACtB,SAAQ,MAAM,CAAC,MAAM,CAAM,KAC1B,OAAO,CAAC,MAAM,EAAE,CAElB,CAAC;AAEF;;;GAGG;AACH,eAAO,MAAM,aAAa,QAAa,OAAO,CAAC,MAAM,EAAE,CAEtD,CAAC;AAEF;;;;GAIG;AACH,eAAO,MAAM,mBAAmB,GAC9B,aAAa,eAAe,KAC3B,OAAO,CAAC,MAAM,EAAE,CAElB,CAAC"}
|
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.getAllPrompts = exports.findPrompts = exports.getPromptByName = exports.getPromptsCollection = void 0;
|
|
3
|
+
exports.getPromptsByProduct = exports.getAllPrompts = exports.findPrompts = exports.getPromptByName = exports.getPromptsCollection = void 0;
|
|
4
4
|
const index_1 = require("../index");
|
|
5
5
|
const getPromptsCollection = () => {
|
|
6
|
-
return (0, index_1.getDb)().collection("
|
|
6
|
+
return (0, index_1.getDb)().collection("prompts");
|
|
7
7
|
};
|
|
8
8
|
exports.getPromptsCollection = getPromptsCollection;
|
|
9
9
|
/**
|
|
@@ -32,4 +32,13 @@ const getAllPrompts = async () => {
|
|
|
32
32
|
return await (0, exports.findPrompts)();
|
|
33
33
|
};
|
|
34
34
|
exports.getAllPrompts = getAllPrompts;
|
|
35
|
+
/**
|
|
36
|
+
* Get all prompts for a given product.
|
|
37
|
+
* @param productName product key
|
|
38
|
+
* @returns array of matching prompts
|
|
39
|
+
*/
|
|
40
|
+
const getPromptsByProduct = async (productName) => {
|
|
41
|
+
return await (0, exports.findPrompts)({ productName });
|
|
42
|
+
};
|
|
43
|
+
exports.getPromptsByProduct = getPromptsByProduct;
|
|
35
44
|
//# sourceMappingURL=prompts.getters.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"prompts.getters.js","sourceRoot":"","sources":["../../../src/configuration/prompts/prompts.getters.ts"],"names":[],"mappings":";;;AAAA,oCAAiC;
|
|
1
|
+
{"version":3,"file":"prompts.getters.js","sourceRoot":"","sources":["../../../src/configuration/prompts/prompts.getters.ts"],"names":[],"mappings":";;;AAAA,oCAAiC;AAK1B,MAAM,oBAAoB,GAAG,GAAuB,EAAE;IAC3D,OAAO,IAAA,aAAK,GAAE,CAAC,UAAU,CAAS,SAAS,CAAC,CAAC;AAC/C,CAAC,CAAC;AAFW,QAAA,oBAAoB,wBAE/B;AAEF;;;;GAIG;AACI,MAAM,eAAe,GAAG,KAAK,EAClC,IAAY,EACY,EAAE;IAC1B,OAAO,MAAM,IAAA,4BAAoB,GAAE,CAAC,OAAO,CAAC,EAAE,IAAI,EAAE,CAAC,CAAC;AACxD,CAAC,CAAC;AAJW,QAAA,eAAe,mBAI1B;AAEF;;;;GAIG;AACI,MAAM,WAAW,GAAG,KAAK,EAC9B,SAAyB,EAAE,EACR,EAAE;IACrB,OAAO,MAAM,IAAA,4BAAoB,GAAE,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC,OAAO,EAAE,CAAC;AAC7D,CAAC,CAAC;AAJW,QAAA,WAAW,eAItB;AAEF;;;GAGG;AACI,MAAM,aAAa,GAAG,KAAK,IAAuB,EAAE;IACzD,OAAO,MAAM,IAAA,mBAAW,GAAE,CAAC;AAC7B,CAAC,CAAC;AAFW,QAAA,aAAa,iBAExB;AAEF;;;;GAIG;AACI,MAAM,mBAAmB,GAAG,KAAK,EACtC,WAA4B,EACT,EAAE;IACrB,OAAO,MAAM,IAAA,mBAAW,EAAC,EAAE,WAAW,EAAE,CAAC,CAAC;AAC5C,CAAC,CAAC;AAJW,QAAA,mBAAmB,uBAI9B"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"prompts.types.d.ts","sourceRoot":"","sources":["../../../src/configuration/prompts/prompts.types.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,SAAS,CAAC;
|
|
1
|
+
{"version":3,"file":"prompts.types.d.ts","sourceRoot":"","sources":["../../../src/configuration/prompts/prompts.types.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,SAAS,CAAC;AACnC,OAAO,EAAE,eAAe,EAAE,MAAM,iBAAiB,CAAC;AAElD,MAAM,MAAM,MAAM,GAAG;IACnB,GAAG,EAAE,QAAQ,CAAC;IACd,IAAI,EAAE,MAAM,CAAC;IACb,OAAO,EAAE,MAAM,CAAC;IAChB,WAAW,EAAE,eAAe,CAAC;IAC7B,SAAS,EAAE,IAAI,CAAC;IAChB,SAAS,EAAE,IAAI,CAAC;CACjB,CAAC"}
|
package/dist/connection.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"connection.d.ts","sourceRoot":"","sources":["../src/connection.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"connection.d.ts","sourceRoot":"","sources":["../src/connection.ts"],"names":[],"mappings":"AAQA;;;GAGG;AACH,wBAAsB,iBAAiB,kBAsDtC;AAED,wBAAsB,YAAY,IAAI,OAAO,CAAC,IAAI,CAAC,CAYlD"}
|
package/dist/connection.js
CHANGED
|
@@ -6,6 +6,7 @@ const talkpilot_1 = require("./talkpilot");
|
|
|
6
6
|
const municipal_1 = require("./municipal");
|
|
7
7
|
const websitalk_1 = require("./websitalk");
|
|
8
8
|
const configuration_1 = require("./configuration");
|
|
9
|
+
const config_1 = require("./config");
|
|
9
10
|
let isConnected = false;
|
|
10
11
|
/**
|
|
11
12
|
* Ensures the database clients are initialized.
|
|
@@ -50,7 +51,7 @@ async function ensureDbConnected() {
|
|
|
50
51
|
console.warn("[core-db] MONGO_URI is not set");
|
|
51
52
|
}
|
|
52
53
|
else {
|
|
53
|
-
const dbName =
|
|
54
|
+
const dbName = config_1.configurationDbConfig.configurationDbName;
|
|
54
55
|
await configuration_1.configurationMongodbClient.connect(configurationUri, dbName);
|
|
55
56
|
console.info(`[core-db] Connected to Configuration MongoDB: ${dbName || "configuration (default)"}`);
|
|
56
57
|
}
|
package/dist/connection.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"connection.js","sourceRoot":"","sources":["../src/connection.ts"],"names":[],"mappings":";;
|
|
1
|
+
{"version":3,"file":"connection.js","sourceRoot":"","sources":["../src/connection.ts"],"names":[],"mappings":";;AAYA,8CAsDC;AAED,oCAYC;AAhFD,2CAA4C;AAC5C,2CAAyD;AACzD,2CAAqD;AACrD,mDAA6D;AAC7D,qCAAiD;AAEjD,IAAI,WAAW,GAAG,KAAK,CAAC;AAExB;;;GAGG;AACI,KAAK,UAAU,iBAAiB;IACrC,IAAI,WAAW,EAAE,CAAC;QAChB,OAAO;IACT,CAAC;IAED,MAAM,QAAQ,GAAG,OAAO,CAAC,GAAG,CAAC,SAAS,IAAI,OAAO,CAAC,GAAG,CAAC,WAAW,CAAC;IAClE,MAAM,YAAY,GAAG,QAAQ,CAAC;IAC9B,MAAM,YAAY,GAAG,QAAQ,CAAC;IAC9B,MAAM,cAAc,GAAG,QAAQ,CAAC;IAChC,MAAM,gBAAgB,GAAG,QAAQ,CAAC;IAElC,IAAI,CAAC,YAAY,EAAE,CAAC;QAClB,OAAO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AI,CAAC,gBAAgB,EAAE,CAAC;QACtB,OAAO,CAAC,IAAI,CAAC,gCAAgC,CAAC,CAAC;IACjD,CAAC;SAAM,CAAC;QACN,MAAM,MAAM,GAAG,8BAAqB,CAAC,mBAAmB,CAAC;QACzD,MAAM,0CAA0B,CAAC,OAAO,CAAC,gBAAgB,EAAE,MAAM,CAAC,CAAC;QACnE,OAAO,CAAC,IAAI,CACV,iDAAiD,MAAM,IAAI,yBAAyB,EAAE,CACvF,CAAC;IACJ,CAAC;IAED,WAAW,GAAG,IAAI,CAAC;AACrB,CAAC;AAEM,KAAK,UAAU,YAAY;IAChC,IAAI,CAAC,WAAW,EAAE,CAAC;QACjB,OAAO;IACT,CAAC;IAED,MAAM,OAAO,CAAC,GAAG,CAAC;QAChB,yBAAa,CAAC,UAAU,EAAE;QAC1B,sCAA0B,CAAC,UAAU,EAAE;QACvC,kCAAsB,CAAC,UAAU,EAAE;QACnC,0CAA0B,CAAC,UAAU,EAAE;KACxC,CAAC,CAAC;IACH,WAAW,GAAG,KAAK,CAAC;AACtB,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
|
+
};
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { MongoClient, Db } from "mongodb";
|
|
2
2
|
import { setDb } from "./index";
|
|
3
3
|
import { validateConfig, validateMongoUri } from "../utils/validation";
|
|
4
|
+
import { configurationDbConfig } from "../config";
|
|
4
5
|
|
|
5
6
|
class ConfigurationMongoDBClient {
|
|
6
7
|
private client: MongoClient | null = null;
|
|
@@ -12,7 +13,7 @@ class ConfigurationMongoDBClient {
|
|
|
12
13
|
return;
|
|
13
14
|
}
|
|
14
15
|
|
|
15
|
-
const mongodbUri = uri ||
|
|
16
|
+
const mongodbUri = uri || configurationDbConfig.mongoUri;
|
|
16
17
|
validateConfig("MONGO_URI", mongodbUri);
|
|
17
18
|
validateMongoUri(mongodbUri!);
|
|
18
19
|
|
|
@@ -20,7 +21,7 @@ class ConfigurationMongoDBClient {
|
|
|
20
21
|
this.client = new MongoClient(mongodbUri!);
|
|
21
22
|
await this.client.connect();
|
|
22
23
|
const targetDbName =
|
|
23
|
-
dbName ||
|
|
24
|
+
dbName || configurationDbConfig.configurationDbName || this.defaultDbName;
|
|
24
25
|
this.db = this.client.db(targetDbName);
|
|
25
26
|
setDb(this.db);
|
|
26
27
|
console.info(`[core-db] Configuration MongoDB connected: ${targetDbName}`);
|
|
@@ -1,9 +1,10 @@
|
|
|
1
1
|
import { getDb } from "../index";
|
|
2
2
|
import { Collection, Filter } from "mongodb";
|
|
3
3
|
import { Prompt } from "./prompts.types";
|
|
4
|
+
import { KnownProductKey } from "../../talkpilot";
|
|
4
5
|
|
|
5
6
|
export const getPromptsCollection = (): Collection<Prompt> => {
|
|
6
|
-
return getDb().collection<Prompt>("
|
|
7
|
+
return getDb().collection<Prompt>("prompts");
|
|
7
8
|
};
|
|
8
9
|
|
|
9
10
|
/**
|
|
@@ -35,3 +36,14 @@ export const findPrompts = async (
|
|
|
35
36
|
export const getAllPrompts = async (): Promise<Prompt[]> => {
|
|
36
37
|
return await findPrompts();
|
|
37
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
|
@@ -2,6 +2,7 @@ import { mongodbClient } from "./talkpilot";
|
|
|
2
2
|
import { municipalDataMongodbClient } from "./municipal";
|
|
3
3
|
import { websitalkMongodbClient } from "./websitalk";
|
|
4
4
|
import { configurationMongodbClient } from "./configuration";
|
|
5
|
+
import { configurationDbConfig } from "./config";
|
|
5
6
|
|
|
6
7
|
let isConnected = false;
|
|
7
8
|
|
|
@@ -55,7 +56,7 @@ export async function ensureDbConnected() {
|
|
|
55
56
|
if (!configurationUri) {
|
|
56
57
|
console.warn("[core-db] MONGO_URI is not set");
|
|
57
58
|
} else {
|
|
58
|
-
const dbName =
|
|
59
|
+
const dbName = configurationDbConfig.configurationDbName;
|
|
59
60
|
await configurationMongodbClient.connect(configurationUri, dbName);
|
|
60
61
|
console.info(
|
|
61
62
|
`[core-db] Connected to Configuration MongoDB: ${dbName || "configuration (default)"}`,
|