@okf/ootils 1.3.9 → 1.3.11
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/node.d.mts +68 -91
- package/dist/node.d.ts +68 -91
- package/dist/node.js +648 -442
- package/dist/node.mjs +653 -440
- package/package.json +1 -1
package/dist/node.js
CHANGED
|
@@ -33,6 +33,613 @@ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__ge
|
|
|
33
33
|
));
|
|
34
34
|
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
35
35
|
|
|
36
|
+
// src/models/Annotations.ts
|
|
37
|
+
var Annotations_exports = {};
|
|
38
|
+
__export(Annotations_exports, {
|
|
39
|
+
default: () => Annotations_default
|
|
40
|
+
});
|
|
41
|
+
var import_mongoose, AnnotationSchema, Annotations_default;
|
|
42
|
+
var init_Annotations = __esm({
|
|
43
|
+
"src/models/Annotations.ts"() {
|
|
44
|
+
"use strict";
|
|
45
|
+
import_mongoose = require("mongoose");
|
|
46
|
+
AnnotationSchema = new import_mongoose.Schema(
|
|
47
|
+
{
|
|
48
|
+
// Tags section - dynamic structure for various tag categories
|
|
49
|
+
tags: {
|
|
50
|
+
type: Map,
|
|
51
|
+
of: new import_mongoose.Schema({
|
|
52
|
+
data: [
|
|
53
|
+
{
|
|
54
|
+
_id: { type: import_mongoose.Schema.Types.ObjectId },
|
|
55
|
+
display: String,
|
|
56
|
+
tagId: String
|
|
57
|
+
}
|
|
58
|
+
],
|
|
59
|
+
collectionId: String
|
|
60
|
+
}, {
|
|
61
|
+
_id: false
|
|
62
|
+
})
|
|
63
|
+
},
|
|
64
|
+
// Meta information
|
|
65
|
+
meta: {
|
|
66
|
+
contentType: { type: String, required: true },
|
|
67
|
+
kp_contributed_by: {
|
|
68
|
+
type: import_mongoose.Schema.Types.ObjectId,
|
|
69
|
+
ref: "user"
|
|
70
|
+
},
|
|
71
|
+
valuePath: String,
|
|
72
|
+
documentId: {
|
|
73
|
+
type: import_mongoose.Schema.Types.ObjectId
|
|
74
|
+
}
|
|
75
|
+
},
|
|
76
|
+
// Main content data - using Schema.Types.Mixed for dynamic structure
|
|
77
|
+
main: {
|
|
78
|
+
type: import_mongoose.Schema.Types.Mixed,
|
|
79
|
+
default: {}
|
|
80
|
+
},
|
|
81
|
+
// Annotation specific details
|
|
82
|
+
annotations: {
|
|
83
|
+
tags: {
|
|
84
|
+
type: Map,
|
|
85
|
+
of: new import_mongoose.Schema({
|
|
86
|
+
collectionId: String,
|
|
87
|
+
data: [
|
|
88
|
+
{
|
|
89
|
+
_id: { type: import_mongoose.Schema.Types.ObjectId },
|
|
90
|
+
display: String,
|
|
91
|
+
tagId: String
|
|
92
|
+
}
|
|
93
|
+
]
|
|
94
|
+
}, {
|
|
95
|
+
_id: false
|
|
96
|
+
})
|
|
97
|
+
},
|
|
98
|
+
fragment: {
|
|
99
|
+
isLexical: Boolean,
|
|
100
|
+
editorState: Object,
|
|
101
|
+
allText: String
|
|
102
|
+
},
|
|
103
|
+
annoKey: String,
|
|
104
|
+
author: {
|
|
105
|
+
id: { type: import_mongoose.Schema.Types.ObjectId },
|
|
106
|
+
name: String
|
|
107
|
+
}
|
|
108
|
+
},
|
|
109
|
+
embeddings: Array,
|
|
110
|
+
contentEnhancedText: String,
|
|
111
|
+
// // Optional chunk related fields
|
|
112
|
+
// chunk: {
|
|
113
|
+
// embeddings: Schema.Types.Mixed,
|
|
114
|
+
// contentEnhancedText: String
|
|
115
|
+
// },
|
|
116
|
+
clusterId: String,
|
|
117
|
+
kp_date_published: Date,
|
|
118
|
+
createdAt: {
|
|
119
|
+
type: Date,
|
|
120
|
+
default: Date.now
|
|
121
|
+
},
|
|
122
|
+
updatedAt: {
|
|
123
|
+
type: Date,
|
|
124
|
+
default: Date.now
|
|
125
|
+
},
|
|
126
|
+
topicId: [{ type: import_mongoose.Schema.Types.ObjectId, ref: "generatedTopics" }],
|
|
127
|
+
translations: Object
|
|
128
|
+
},
|
|
129
|
+
{
|
|
130
|
+
timestamps: true,
|
|
131
|
+
toJSON: { virtuals: true },
|
|
132
|
+
toObject: { virtuals: true },
|
|
133
|
+
strict: false
|
|
134
|
+
// This allows for flexible document structure beyond the defined schema
|
|
135
|
+
}
|
|
136
|
+
);
|
|
137
|
+
AnnotationSchema.index({ "meta.contentType": 1 });
|
|
138
|
+
AnnotationSchema.index({ "meta.documentId": 1 });
|
|
139
|
+
AnnotationSchema.index({ createdAt: -1 });
|
|
140
|
+
AnnotationSchema.index({ "annotations.annoKey": 1 });
|
|
141
|
+
AnnotationSchema.index({ "kp_date_published": -1 });
|
|
142
|
+
AnnotationSchema.pre("save", function(next) {
|
|
143
|
+
this.updatedAt = /* @__PURE__ */ new Date();
|
|
144
|
+
next();
|
|
145
|
+
});
|
|
146
|
+
AnnotationSchema.methods.getMainField = function(fieldPath) {
|
|
147
|
+
if (!fieldPath) return null;
|
|
148
|
+
const parts = fieldPath.split(".");
|
|
149
|
+
let value = this.main;
|
|
150
|
+
for (const part of parts) {
|
|
151
|
+
if (!value || typeof value !== "object") return null;
|
|
152
|
+
value = value[part];
|
|
153
|
+
}
|
|
154
|
+
return value;
|
|
155
|
+
};
|
|
156
|
+
AnnotationSchema.virtual("displayTitle").get(function() {
|
|
157
|
+
return this.main?.title || "Untitled Annotation";
|
|
158
|
+
});
|
|
159
|
+
Annotations_default = AnnotationSchema;
|
|
160
|
+
}
|
|
161
|
+
});
|
|
162
|
+
|
|
163
|
+
// src/models/PlatformConfigs.ts
|
|
164
|
+
var PlatformConfigs_exports = {};
|
|
165
|
+
__export(PlatformConfigs_exports, {
|
|
166
|
+
default: () => PlatformConfigs_default
|
|
167
|
+
});
|
|
168
|
+
var import_mongoose2, platformConfigTypes, PlatformConfigsSchema, PlatformConfigs_default;
|
|
169
|
+
var init_PlatformConfigs = __esm({
|
|
170
|
+
"src/models/PlatformConfigs.ts"() {
|
|
171
|
+
"use strict";
|
|
172
|
+
import_mongoose2 = __toESM(require("mongoose"));
|
|
173
|
+
platformConfigTypes = [
|
|
174
|
+
"roles",
|
|
175
|
+
"nav",
|
|
176
|
+
"deployment",
|
|
177
|
+
"userAgreement",
|
|
178
|
+
"localeData",
|
|
179
|
+
"theme",
|
|
180
|
+
"AI"
|
|
181
|
+
];
|
|
182
|
+
PlatformConfigsSchema = new import_mongoose2.default.Schema(
|
|
183
|
+
{
|
|
184
|
+
type: {
|
|
185
|
+
type: String,
|
|
186
|
+
enum: platformConfigTypes,
|
|
187
|
+
unique: true
|
|
188
|
+
},
|
|
189
|
+
roles: Array,
|
|
190
|
+
data: Object
|
|
191
|
+
},
|
|
192
|
+
{ collection: "platformConfigs" }
|
|
193
|
+
);
|
|
194
|
+
PlatformConfigs_default = PlatformConfigsSchema;
|
|
195
|
+
}
|
|
196
|
+
});
|
|
197
|
+
|
|
198
|
+
// src/models/Tpl.ts
|
|
199
|
+
var Tpl_exports = {};
|
|
200
|
+
__export(Tpl_exports, {
|
|
201
|
+
default: () => Tpl_default
|
|
202
|
+
});
|
|
203
|
+
var import_mongoose3, TplSchema, Tpl_default;
|
|
204
|
+
var init_Tpl = __esm({
|
|
205
|
+
"src/models/Tpl.ts"() {
|
|
206
|
+
"use strict";
|
|
207
|
+
import_mongoose3 = __toESM(require("mongoose"));
|
|
208
|
+
TplSchema = new import_mongoose3.default.Schema({
|
|
209
|
+
dateFirstPublished: Date,
|
|
210
|
+
dateCreated: Date,
|
|
211
|
+
dateLastPublished: Date,
|
|
212
|
+
dateLastEdited: Date,
|
|
213
|
+
status: {
|
|
214
|
+
type: String,
|
|
215
|
+
default: "published",
|
|
216
|
+
// only cuz we dont want to go and add this property in all databases
|
|
217
|
+
enum: ["unpublished", "editPublished", "published"]
|
|
218
|
+
},
|
|
219
|
+
version: {
|
|
220
|
+
type: Number,
|
|
221
|
+
default: 0
|
|
222
|
+
},
|
|
223
|
+
versionPublishedBy: {
|
|
224
|
+
type: import_mongoose3.default.Schema.Types.ObjectId,
|
|
225
|
+
ref: "user"
|
|
226
|
+
// reference to the 'user' model
|
|
227
|
+
},
|
|
228
|
+
firstPublishedBy: {
|
|
229
|
+
type: import_mongoose3.default.Schema.Types.ObjectId,
|
|
230
|
+
ref: "user"
|
|
231
|
+
// reference to the 'user' model
|
|
232
|
+
},
|
|
233
|
+
kp_content_type: {
|
|
234
|
+
type: String,
|
|
235
|
+
required: true,
|
|
236
|
+
unique: true
|
|
237
|
+
},
|
|
238
|
+
category: {
|
|
239
|
+
//to deprecate and turn into 'layout'
|
|
240
|
+
type: String,
|
|
241
|
+
default: "knowledgeResources2"
|
|
242
|
+
},
|
|
243
|
+
kp_settings: [
|
|
244
|
+
{
|
|
245
|
+
type: Object
|
|
246
|
+
}
|
|
247
|
+
],
|
|
248
|
+
kp_templates: {
|
|
249
|
+
type: Object
|
|
250
|
+
},
|
|
251
|
+
tplMeta: Object,
|
|
252
|
+
tplLocales: Object,
|
|
253
|
+
indexed: Object,
|
|
254
|
+
drafts: {
|
|
255
|
+
active: Object
|
|
256
|
+
},
|
|
257
|
+
rollbacks: Object,
|
|
258
|
+
//for 'remembering' hidden configurations
|
|
259
|
+
// OTHER CONFIGS
|
|
260
|
+
listing: Object,
|
|
261
|
+
//listing page configurations. this is new, currently only used in nct
|
|
262
|
+
general: {
|
|
263
|
+
content: {
|
|
264
|
+
title: String,
|
|
265
|
+
singular: String,
|
|
266
|
+
ctaText: String,
|
|
267
|
+
listingDesc: String
|
|
268
|
+
},
|
|
269
|
+
allowQuickTagCreation: { enable: Boolean },
|
|
270
|
+
segment: String,
|
|
271
|
+
settingsUIStyle: String,
|
|
272
|
+
hasUpdateType: Boolean,
|
|
273
|
+
annotation: {
|
|
274
|
+
enable: Boolean
|
|
275
|
+
},
|
|
276
|
+
participantModule: {
|
|
277
|
+
enable: Boolean
|
|
278
|
+
},
|
|
279
|
+
formFieldNumbering: {
|
|
280
|
+
enable: Boolean
|
|
281
|
+
},
|
|
282
|
+
postPblRedirPath: Object,
|
|
283
|
+
templateIndex: Object,
|
|
284
|
+
sharing: {
|
|
285
|
+
enable: Boolean,
|
|
286
|
+
trackShareCount: {
|
|
287
|
+
type: Boolean,
|
|
288
|
+
default: false
|
|
289
|
+
}
|
|
290
|
+
},
|
|
291
|
+
viewsCount: {
|
|
292
|
+
enable: {
|
|
293
|
+
type: Boolean,
|
|
294
|
+
default: false
|
|
295
|
+
}
|
|
296
|
+
},
|
|
297
|
+
comments: {
|
|
298
|
+
enable: Boolean
|
|
299
|
+
},
|
|
300
|
+
reactions: {
|
|
301
|
+
type: Map,
|
|
302
|
+
of: {
|
|
303
|
+
enable: Boolean,
|
|
304
|
+
icon: String
|
|
305
|
+
}
|
|
306
|
+
},
|
|
307
|
+
csvExport: {
|
|
308
|
+
enable: Boolean,
|
|
309
|
+
excludeFields: Array,
|
|
310
|
+
enableUpdateExport: Boolean,
|
|
311
|
+
fieldsToSortAtEnd: Array,
|
|
312
|
+
fetchBatches: {
|
|
313
|
+
enable: Boolean,
|
|
314
|
+
batchSize: Number
|
|
315
|
+
}
|
|
316
|
+
},
|
|
317
|
+
onboardingFlow: Object,
|
|
318
|
+
//only on profile tpls
|
|
319
|
+
selfServeSurveyConfig: Object,
|
|
320
|
+
//tci helpers - these exist only to show / not show certain UIs in the tci
|
|
321
|
+
disableKPSettings: Boolean
|
|
322
|
+
}
|
|
323
|
+
//general contenttype configs. mostly the stuff inside platformConfigs > contentTypes
|
|
324
|
+
}, {
|
|
325
|
+
toJSON: { virtuals: true },
|
|
326
|
+
// So `res.json()` and other `JSON.stringify()` functions include virtuals
|
|
327
|
+
toObject: { virtuals: true }
|
|
328
|
+
// So `toObject()` output includes virtuals
|
|
329
|
+
});
|
|
330
|
+
TplSchema.virtual("layout").get(function() {
|
|
331
|
+
return this.category;
|
|
332
|
+
});
|
|
333
|
+
Tpl_default = TplSchema;
|
|
334
|
+
}
|
|
335
|
+
});
|
|
336
|
+
|
|
337
|
+
// src/db/MongoConnector.js
|
|
338
|
+
var require_MongoConnector = __commonJS({
|
|
339
|
+
"src/db/MongoConnector.js"(exports2, module2) {
|
|
340
|
+
"use strict";
|
|
341
|
+
var mongoose5 = require("mongoose");
|
|
342
|
+
var AnnotationsSchema = (init_Annotations(), __toCommonJS(Annotations_exports));
|
|
343
|
+
var PlatformConfigsSchema2 = (init_PlatformConfigs(), __toCommonJS(PlatformConfigs_exports));
|
|
344
|
+
var TplSchema2 = (init_Tpl(), __toCommonJS(Tpl_exports));
|
|
345
|
+
var MongoConnector3 = class _MongoConnector {
|
|
346
|
+
constructor(options) {
|
|
347
|
+
this.clusterConnections = {};
|
|
348
|
+
this.env = options.env;
|
|
349
|
+
this.dbConfigs = options.dbConfigs;
|
|
350
|
+
this.mongoOptions = options.mongoOptions || {
|
|
351
|
+
maxPoolSize: 20,
|
|
352
|
+
serverSelectionTimeoutMS: 5e3,
|
|
353
|
+
socketTimeoutMS: 45e3,
|
|
354
|
+
family: 4
|
|
355
|
+
};
|
|
356
|
+
_MongoConnector.instance = this;
|
|
357
|
+
if (!this.env) {
|
|
358
|
+
throw new Error("Environment must be provided in constructor options");
|
|
359
|
+
}
|
|
360
|
+
if (!this.dbConfigs) {
|
|
361
|
+
throw new Error("dbConfigs must be provided in constructor options");
|
|
362
|
+
}
|
|
363
|
+
}
|
|
364
|
+
/**
|
|
365
|
+
* Creates multiple MongoDB clusterConnections based on configuration (SYNCHRONOUS)
|
|
366
|
+
* @returns Object containing named database clusterConnections
|
|
367
|
+
*/
|
|
368
|
+
multiConnectToMongoDB() {
|
|
369
|
+
const { connectTo } = this.dbConfigs[this.env];
|
|
370
|
+
if (!connectTo) {
|
|
371
|
+
throw new Error(
|
|
372
|
+
`No connection configuration found for environment: ${this.env}`
|
|
373
|
+
);
|
|
374
|
+
}
|
|
375
|
+
connectTo.forEach((connectToEnv) => {
|
|
376
|
+
const { CLUSTER_NAME, DB_URI } = this.dbConfigs[connectToEnv];
|
|
377
|
+
if (!CLUSTER_NAME || !DB_URI) {
|
|
378
|
+
throw new Error(
|
|
379
|
+
`Missing CLUSTER_NAME or DB_URI for environment: ${connectToEnv}`
|
|
380
|
+
);
|
|
381
|
+
}
|
|
382
|
+
this.clusterConnections[CLUSTER_NAME] = mongoose5.createConnection(
|
|
383
|
+
DB_URI,
|
|
384
|
+
this.mongoOptions
|
|
385
|
+
);
|
|
386
|
+
this.clusterConnections[CLUSTER_NAME].on("open", () => {
|
|
387
|
+
console.log(`\u2705 Mongoose connection open to ${CLUSTER_NAME}`);
|
|
388
|
+
});
|
|
389
|
+
this.clusterConnections[CLUSTER_NAME].on("error", (err) => {
|
|
390
|
+
console.error(
|
|
391
|
+
`\u274C Mongoose connection error: ${err.message} with connection info ${CLUSTER_NAME}`
|
|
392
|
+
);
|
|
393
|
+
process.exit(1);
|
|
394
|
+
});
|
|
395
|
+
this.clusterConnections[CLUSTER_NAME].on("disconnected", () => {
|
|
396
|
+
console.log(`\u{1F50C} Mongoose disconnected from ${CLUSTER_NAME}`);
|
|
397
|
+
});
|
|
398
|
+
this.clusterConnections[CLUSTER_NAME].on("reconnected", () => {
|
|
399
|
+
console.log(`\u{1F504} Mongoose reconnected to ${CLUSTER_NAME}`);
|
|
400
|
+
});
|
|
401
|
+
});
|
|
402
|
+
console.log(
|
|
403
|
+
`\u{1F389} Connected to ${Object.keys(this.clusterConnections).length} MongoDB databases`
|
|
404
|
+
);
|
|
405
|
+
return this.clusterConnections;
|
|
406
|
+
}
|
|
407
|
+
async multiConnectToMongoDBAsync() {
|
|
408
|
+
const { connectTo } = this.dbConfigs[this.env];
|
|
409
|
+
if (!connectTo) {
|
|
410
|
+
throw new Error(
|
|
411
|
+
`No connection configuration found for environment: ${this.env}`
|
|
412
|
+
);
|
|
413
|
+
}
|
|
414
|
+
await Promise.all(
|
|
415
|
+
connectTo.map(async (connectToEnv) => {
|
|
416
|
+
const { CLUSTER_NAME, DB_URI } = this.dbConfigs[connectToEnv];
|
|
417
|
+
if (!CLUSTER_NAME || !DB_URI) {
|
|
418
|
+
throw new Error(
|
|
419
|
+
`Missing CLUSTER_NAME or DB_URI for environment: ${connectToEnv}`
|
|
420
|
+
);
|
|
421
|
+
}
|
|
422
|
+
this.clusterConnections[CLUSTER_NAME] = await mongoose5.createConnection(
|
|
423
|
+
DB_URI,
|
|
424
|
+
this.mongoOptions
|
|
425
|
+
);
|
|
426
|
+
console.log(`Connected to MongoDB: ${CLUSTER_NAME}`);
|
|
427
|
+
})
|
|
428
|
+
);
|
|
429
|
+
return this.clusterConnections;
|
|
430
|
+
}
|
|
431
|
+
// Static method to get the full instance
|
|
432
|
+
static getInstance() {
|
|
433
|
+
if (!_MongoConnector.instance) {
|
|
434
|
+
throw new Error("MongoConnector not initialized");
|
|
435
|
+
}
|
|
436
|
+
return _MongoConnector.instance;
|
|
437
|
+
}
|
|
438
|
+
// Static method to get connections
|
|
439
|
+
static getClusterConnections() {
|
|
440
|
+
if (!_MongoConnector.instance) {
|
|
441
|
+
throw new Error("MongoConnector not initialized");
|
|
442
|
+
}
|
|
443
|
+
return _MongoConnector.instance.clusterConnections;
|
|
444
|
+
}
|
|
445
|
+
// Static method to get environment
|
|
446
|
+
static getEnv() {
|
|
447
|
+
if (!_MongoConnector.instance) {
|
|
448
|
+
throw new Error("MongoConnector not initialized");
|
|
449
|
+
}
|
|
450
|
+
return _MongoConnector.instance.env;
|
|
451
|
+
}
|
|
452
|
+
// Static method to get db configs
|
|
453
|
+
static getDbConfigs() {
|
|
454
|
+
if (!_MongoConnector.instance) {
|
|
455
|
+
throw new Error("MongoConnector not initialized");
|
|
456
|
+
}
|
|
457
|
+
return _MongoConnector.instance.dbConfigs;
|
|
458
|
+
}
|
|
459
|
+
/**
|
|
460
|
+
* Helper function to close clusterConnections object
|
|
461
|
+
*/
|
|
462
|
+
async closeConnectionsObject(clusterConnections) {
|
|
463
|
+
const closePromises = Object.entries(clusterConnections).map(
|
|
464
|
+
async ([clusterName, connection]) => {
|
|
465
|
+
try {
|
|
466
|
+
if (connection.readyState === 1) {
|
|
467
|
+
await connection.close();
|
|
468
|
+
console.log(`\u2705 Closed MongoDB connection: ${clusterName}`);
|
|
469
|
+
}
|
|
470
|
+
} catch (error) {
|
|
471
|
+
console.error(
|
|
472
|
+
`\u274C Error closing MongoDB connection ${clusterName}:`,
|
|
473
|
+
error
|
|
474
|
+
);
|
|
475
|
+
}
|
|
476
|
+
}
|
|
477
|
+
);
|
|
478
|
+
await Promise.all(closePromises);
|
|
479
|
+
}
|
|
480
|
+
/**
|
|
481
|
+
* Graceful shutdown - close all MongoDB clusterConnections
|
|
482
|
+
*/
|
|
483
|
+
async closeAllConnections() {
|
|
484
|
+
if (Object.keys(this.clusterConnections).length === 0) {
|
|
485
|
+
console.log("No active MongoDB cluster connections to close");
|
|
486
|
+
return;
|
|
487
|
+
}
|
|
488
|
+
console.log("\u{1F6D1} Closing MongoDB cluster connections gracefully...");
|
|
489
|
+
await this.closeConnectionsObject(this.clusterConnections);
|
|
490
|
+
this.clusterConnections = {};
|
|
491
|
+
console.log("\u{1F389} All MongoDB clusterConnections closed gracefully");
|
|
492
|
+
}
|
|
493
|
+
};
|
|
494
|
+
MongoConnector3.instance = null;
|
|
495
|
+
module2.exports = {
|
|
496
|
+
MongoConnector: MongoConnector3
|
|
497
|
+
};
|
|
498
|
+
}
|
|
499
|
+
});
|
|
500
|
+
|
|
501
|
+
// src/db/getDbByTenant.js
|
|
502
|
+
var getDbByTenant_exports = {};
|
|
503
|
+
__export(getDbByTenant_exports, {
|
|
504
|
+
getDbByTenant: () => getDbByTenant
|
|
505
|
+
});
|
|
506
|
+
var import_mongoose4, import_MongoConnector, getDbByTenant;
|
|
507
|
+
var init_getDbByTenant = __esm({
|
|
508
|
+
"src/db/getDbByTenant.js"() {
|
|
509
|
+
"use strict";
|
|
510
|
+
import_mongoose4 = require("mongoose");
|
|
511
|
+
import_MongoConnector = __toESM(require_MongoConnector());
|
|
512
|
+
getDbByTenant = ({
|
|
513
|
+
tenant,
|
|
514
|
+
env: _env
|
|
515
|
+
}) => {
|
|
516
|
+
if (!tenant) throw new Error("tenant id has not been provided");
|
|
517
|
+
const env = _env || import_MongoConnector.MongoConnector.getEnv();
|
|
518
|
+
const dbConfigs = import_MongoConnector.MongoConnector.getDbConfigs();
|
|
519
|
+
const clusterConnections = import_MongoConnector.MongoConnector.getClusterConnections();
|
|
520
|
+
const { CLUSTER_NAME } = dbConfigs[env];
|
|
521
|
+
const dbName = `${tenant}_${env}`;
|
|
522
|
+
const connection = clusterConnections[CLUSTER_NAME];
|
|
523
|
+
if (!connection) {
|
|
524
|
+
throw new Error(`Connection not found for cluster: ${CLUSTER_NAME}`);
|
|
525
|
+
}
|
|
526
|
+
return connection.useDb(dbName, { useCache: true });
|
|
527
|
+
};
|
|
528
|
+
}
|
|
529
|
+
});
|
|
530
|
+
|
|
531
|
+
// src/models/AIChat.ts
|
|
532
|
+
var import_mongoose5, AIChatSchema, AIChat_default;
|
|
533
|
+
var init_AIChat = __esm({
|
|
534
|
+
"src/models/AIChat.ts"() {
|
|
535
|
+
"use strict";
|
|
536
|
+
import_mongoose5 = __toESM(require("mongoose"));
|
|
537
|
+
init_Annotations();
|
|
538
|
+
AIChatSchema = new import_mongoose5.default.Schema(
|
|
539
|
+
{
|
|
540
|
+
userId: { type: import_mongoose5.default.Schema.Types.ObjectId, index: { unique: true } },
|
|
541
|
+
createdAt: Date,
|
|
542
|
+
lastAcitivity: Date,
|
|
543
|
+
messages: [
|
|
544
|
+
{
|
|
545
|
+
id: String,
|
|
546
|
+
author: {
|
|
547
|
+
type: String,
|
|
548
|
+
enum: ["system", "user", "assistant"]
|
|
549
|
+
},
|
|
550
|
+
content: {
|
|
551
|
+
type: { type: String },
|
|
552
|
+
value: String
|
|
553
|
+
},
|
|
554
|
+
vectorSearchInfo: {
|
|
555
|
+
chunks: [Annotations_default]
|
|
556
|
+
},
|
|
557
|
+
args: {
|
|
558
|
+
query: String,
|
|
559
|
+
reframedQuery: String,
|
|
560
|
+
summary: Object
|
|
561
|
+
},
|
|
562
|
+
userFeedback: {
|
|
563
|
+
reaction: { type: String, enum: ["positive", "negative"] },
|
|
564
|
+
comments: String
|
|
565
|
+
}
|
|
566
|
+
}
|
|
567
|
+
]
|
|
568
|
+
},
|
|
569
|
+
{ collection: "aiChat" }
|
|
570
|
+
);
|
|
571
|
+
AIChat_default = AIChatSchema;
|
|
572
|
+
}
|
|
573
|
+
});
|
|
574
|
+
|
|
575
|
+
// src/models/index.ts
|
|
576
|
+
var models_exports = {};
|
|
577
|
+
__export(models_exports, {
|
|
578
|
+
AIChatSchema: () => AIChat_default,
|
|
579
|
+
AnnotationSchema: () => Annotations_default,
|
|
580
|
+
PlatformConfigsSchema: () => PlatformConfigs_default,
|
|
581
|
+
TplSchema: () => Tpl_default
|
|
582
|
+
});
|
|
583
|
+
var init_models = __esm({
|
|
584
|
+
"src/models/index.ts"() {
|
|
585
|
+
"use strict";
|
|
586
|
+
init_AIChat();
|
|
587
|
+
init_Annotations();
|
|
588
|
+
init_PlatformConfigs();
|
|
589
|
+
init_Tpl();
|
|
590
|
+
}
|
|
591
|
+
});
|
|
592
|
+
|
|
593
|
+
// src/db/getModelByTenant.js
|
|
594
|
+
var require_getModelByTenant = __commonJS({
|
|
595
|
+
"src/db/getModelByTenant.js"(exports2, module2) {
|
|
596
|
+
"use strict";
|
|
597
|
+
var { getDbByTenant: getDbByTenant2 } = (init_getDbByTenant(), __toCommonJS(getDbByTenant_exports));
|
|
598
|
+
var { AIChatSchema: AIChatSchema2, AnnotationSchema: AnnotationSchema2, PlatformConfigsSchema: PlatformConfigsSchema2, TplSchema: TplSchema2 } = (init_models(), __toCommonJS(models_exports));
|
|
599
|
+
var getModelByTenant2 = ({ tenant, modelName, schema, env }) => {
|
|
600
|
+
if (!tenant) {
|
|
601
|
+
throw new Error("tenant id has not been provided");
|
|
602
|
+
}
|
|
603
|
+
const db = getDbByTenant2({ tenant, env });
|
|
604
|
+
if (!Object.keys(db.models).includes(modelName)) {
|
|
605
|
+
return db.model(modelName, schema);
|
|
606
|
+
}
|
|
607
|
+
return db.model(modelName);
|
|
608
|
+
};
|
|
609
|
+
var getAnnotationsModelByTenant2 = ({ tenant, env, mongodb, dbConfigs, modelName }) => getModelByTenant2({
|
|
610
|
+
tenant,
|
|
611
|
+
modelName: modelName || "annotations",
|
|
612
|
+
schema: AnnotationSchema2,
|
|
613
|
+
env
|
|
614
|
+
});
|
|
615
|
+
var getPlatformConfigsModelByTenant2 = ({ tenant, env, mongodb, dbConfigs }) => getModelByTenant2({
|
|
616
|
+
tenant,
|
|
617
|
+
modelName: "platformConfigs",
|
|
618
|
+
schema: PlatformConfigsSchema2,
|
|
619
|
+
env
|
|
620
|
+
});
|
|
621
|
+
var getTplModelByTenant2 = ({ tenant, env, mongodb, dbConfigs }) => getModelByTenant2({
|
|
622
|
+
tenant,
|
|
623
|
+
modelName: "tpl",
|
|
624
|
+
schema: TplSchema2,
|
|
625
|
+
env
|
|
626
|
+
});
|
|
627
|
+
var getAIChatModelByTenant2 = ({ tenant, env, mongodb, dbConfigs }) => getModelByTenant2({
|
|
628
|
+
tenant,
|
|
629
|
+
modelName: "aiChat",
|
|
630
|
+
schema: AIChatSchema2,
|
|
631
|
+
env
|
|
632
|
+
});
|
|
633
|
+
module2.exports = {
|
|
634
|
+
getModelByTenant: getModelByTenant2,
|
|
635
|
+
getAIChatModelByTenant: getAIChatModelByTenant2,
|
|
636
|
+
getAnnotationsModelByTenant: getAnnotationsModelByTenant2,
|
|
637
|
+
getPlatformConfigsModelByTenant: getPlatformConfigsModelByTenant2,
|
|
638
|
+
getTplModelByTenant: getTplModelByTenant2
|
|
639
|
+
};
|
|
640
|
+
}
|
|
641
|
+
});
|
|
642
|
+
|
|
36
643
|
// src/bullmq/WorkerManager.js
|
|
37
644
|
var require_WorkerManager = __commonJS({
|
|
38
645
|
"src/bullmq/WorkerManager.js"(exports2, module2) {
|
|
@@ -272,8 +879,32 @@ var init_GLOBAL_BULLMQ_CONFIG = __esm({
|
|
|
272
879
|
}
|
|
273
880
|
},
|
|
274
881
|
// Chunk Processing Queue
|
|
275
|
-
|
|
276
|
-
id: "
|
|
882
|
+
CREATE_CHUNKS_QUEUE: {
|
|
883
|
+
id: "create-chunks-queue",
|
|
884
|
+
queueConfig: {
|
|
885
|
+
defaultJobOptions: {
|
|
886
|
+
backoff: {
|
|
887
|
+
type: "exponential",
|
|
888
|
+
delay: 2e3
|
|
889
|
+
},
|
|
890
|
+
attempts: 3,
|
|
891
|
+
removeOnComplete: 100,
|
|
892
|
+
removeOnFail: 50
|
|
893
|
+
}
|
|
894
|
+
},
|
|
895
|
+
workerConfig: {
|
|
896
|
+
concurrency: 10,
|
|
897
|
+
// Process 10 jobs at once for chunk processing
|
|
898
|
+
limiter: {
|
|
899
|
+
max: 5,
|
|
900
|
+
// Max 50 jobs per...
|
|
901
|
+
duration: 6e4
|
|
902
|
+
// ...60 seconds (higher throughput for chunking)
|
|
903
|
+
}
|
|
904
|
+
}
|
|
905
|
+
},
|
|
906
|
+
CREATE_ANNOS_QUEUE: {
|
|
907
|
+
id: "create-annos-queue",
|
|
277
908
|
queueConfig: {
|
|
278
909
|
defaultJobOptions: {
|
|
279
910
|
backoff: {
|
|
@@ -342,6 +973,7 @@ __export(node_exports, {
|
|
|
342
973
|
BaseProducer: () => import_BaseProducer.BaseProducer,
|
|
343
974
|
BaseWorker: () => import_BaseWorker.BaseWorker,
|
|
344
975
|
GET_GLOBAL_BULLMQ_CONFIG: () => import_GET_GLOBAL_BULLMQ_CONFIG.GET_GLOBAL_BULLMQ_CONFIG,
|
|
976
|
+
MongoConnector: () => import_MongoConnector2.MongoConnector,
|
|
345
977
|
PlatformConfigsSchema: () => PlatformConfigs_default,
|
|
346
978
|
TplSchema: () => Tpl_default,
|
|
347
979
|
WorkerManager: () => import_WorkerManager.WorkerManager,
|
|
@@ -349,19 +981,17 @@ __export(node_exports, {
|
|
|
349
981
|
deleteVal: () => deleteVal,
|
|
350
982
|
extractAllBlocksFromTpl: () => extractAllBlocksFromTpl,
|
|
351
983
|
genTagId: () => genTagId,
|
|
352
|
-
getAIChatModelByTenant: () => getAIChatModelByTenant,
|
|
984
|
+
getAIChatModelByTenant: () => import_getModelByTenant.getAIChatModelByTenant,
|
|
353
985
|
getAIConfigs: () => getAIConfigs,
|
|
354
|
-
getAnnotationsModelByTenant: () => getAnnotationsModelByTenant,
|
|
355
|
-
getChunksModelByTenant: () => getChunksModelByTenant,
|
|
986
|
+
getAnnotationsModelByTenant: () => import_getModelByTenant.getAnnotationsModelByTenant,
|
|
356
987
|
getDbByTenant: () => getDbByTenant,
|
|
357
|
-
getModelByTenant: () => getModelByTenant,
|
|
358
|
-
getPlatformConfigsModelByTenant: () => getPlatformConfigsModelByTenant,
|
|
988
|
+
getModelByTenant: () => import_getModelByTenant.getModelByTenant,
|
|
989
|
+
getPlatformConfigsModelByTenant: () => import_getModelByTenant.getPlatformConfigsModelByTenant,
|
|
359
990
|
getRedisClient: () => getRedisClient,
|
|
360
991
|
getTpl: () => getTpl,
|
|
361
|
-
getTplModelByTenant: () => getTplModelByTenant,
|
|
992
|
+
getTplModelByTenant: () => import_getModelByTenant.getTplModelByTenant,
|
|
362
993
|
getVal: () => getVal,
|
|
363
994
|
initializeGlobalConfig: () => initializeGlobalConfig,
|
|
364
|
-
multiConnectToMongoDB: () => multiConnectToMongoDB,
|
|
365
995
|
recursivelyExtractBlocks: () => _recursExtractBlocks,
|
|
366
996
|
setVal: () => setVal,
|
|
367
997
|
toArray: () => toArray,
|
|
@@ -644,18 +1274,12 @@ var _extractBlocksFromSomeBuilders = ({
|
|
|
644
1274
|
}
|
|
645
1275
|
};
|
|
646
1276
|
|
|
647
|
-
// src/
|
|
648
|
-
var
|
|
1277
|
+
// src/node.ts
|
|
1278
|
+
var import_MongoConnector2 = __toESM(require_MongoConnector());
|
|
1279
|
+
init_getDbByTenant();
|
|
649
1280
|
|
|
650
1281
|
// src/db/getGlobalConfig.ts
|
|
651
1282
|
var globalConfig = {};
|
|
652
|
-
var getGlobalConfig = () => {
|
|
653
|
-
return {
|
|
654
|
-
env: globalConfig.env,
|
|
655
|
-
dbConfigs: globalConfig.dbConfigs ? { ...globalConfig.dbConfigs } : void 0,
|
|
656
|
-
mongodb: globalConfig.mongodb ? { ...globalConfig.mongodb } : void 0
|
|
657
|
-
};
|
|
658
|
-
};
|
|
659
1283
|
var initializeGlobalConfig = (config) => {
|
|
660
1284
|
globalConfig = {
|
|
661
1285
|
env: config.env,
|
|
@@ -675,429 +1299,11 @@ var updateGlobalConfig = (updates) => {
|
|
|
675
1299
|
console.log("Global config updated:", Object.keys(updates));
|
|
676
1300
|
};
|
|
677
1301
|
|
|
678
|
-
// src/
|
|
679
|
-
var
|
|
680
|
-
// Note: These legacy options are no longer needed in newer versions of mongoose
|
|
681
|
-
// useUnifiedTopology, useNewUrlParser, useCreateIndex, useFindAndModify are deprecated
|
|
682
|
-
maxPoolSize: 20
|
|
683
|
-
// replaces poolSize
|
|
684
|
-
};
|
|
685
|
-
var multiConnectToMongoDB = ({ env, dbConfigs } = {}) => {
|
|
686
|
-
const globalConfig2 = getGlobalConfig();
|
|
687
|
-
const actualEnv = env || globalConfig2.env;
|
|
688
|
-
const actualDbConfigs = dbConfigs || globalConfig2.dbConfigs;
|
|
689
|
-
if (!actualEnv) {
|
|
690
|
-
throw new Error("Environment not provided and not found in global config");
|
|
691
|
-
}
|
|
692
|
-
if (!actualDbConfigs) {
|
|
693
|
-
throw new Error("dbConfigs not provided and not found in global config");
|
|
694
|
-
}
|
|
695
|
-
const { connectTo } = actualDbConfigs[actualEnv];
|
|
696
|
-
if (!connectTo) {
|
|
697
|
-
throw new Error(`No connection configuration found for environment: ${actualEnv}`);
|
|
698
|
-
}
|
|
699
|
-
const dbConnections = {};
|
|
700
|
-
connectTo.forEach((connectToEnv) => {
|
|
701
|
-
const { CLUSTER_NAME, DB_URI } = actualDbConfigs[connectToEnv];
|
|
702
|
-
if (!CLUSTER_NAME || !DB_URI) {
|
|
703
|
-
throw new Error(`Missing CLUSTER_NAME or DB_URI for environment: ${connectToEnv}`);
|
|
704
|
-
}
|
|
705
|
-
dbConnections[CLUSTER_NAME] = import_mongoose.default.createConnection(DB_URI, mongoOptions);
|
|
706
|
-
dbConnections[CLUSTER_NAME].on("open", () => {
|
|
707
|
-
console.log(`Mongoose connection open to ${CLUSTER_NAME}`);
|
|
708
|
-
});
|
|
709
|
-
dbConnections[CLUSTER_NAME].on("error", (err) => {
|
|
710
|
-
console.log(`Mongoose connection error: ${err.message} with connection info ${CLUSTER_NAME}`);
|
|
711
|
-
process.exit(1);
|
|
712
|
-
});
|
|
713
|
-
});
|
|
714
|
-
return dbConnections;
|
|
715
|
-
};
|
|
716
|
-
|
|
717
|
-
// src/db/getDbByTenant.ts
|
|
718
|
-
var getDbByTenant = ({
|
|
719
|
-
tenant,
|
|
720
|
-
env
|
|
721
|
-
}) => {
|
|
722
|
-
if (!tenant) throw new Error("tenant id has not been provided");
|
|
723
|
-
const globalConfig2 = getGlobalConfig();
|
|
724
|
-
const actualEnv = env || globalConfig2.env;
|
|
725
|
-
const dbConfigs = globalConfig2.dbConfigs;
|
|
726
|
-
const mongodb = globalConfig2.mongodb;
|
|
727
|
-
if (!dbConfigs) {
|
|
728
|
-
throw new Error("dbConfigs not found in global config");
|
|
729
|
-
}
|
|
730
|
-
if (!actualEnv) {
|
|
731
|
-
throw new Error("env not provided and not found in global config");
|
|
732
|
-
}
|
|
733
|
-
const { CLUSTER_NAME } = dbConfigs[actualEnv];
|
|
734
|
-
const dbName = `${tenant}_${actualEnv}`;
|
|
735
|
-
if (mongodb) {
|
|
736
|
-
const db = mongodb[CLUSTER_NAME].useDb(dbName, { useCache: true });
|
|
737
|
-
return db;
|
|
738
|
-
}
|
|
739
|
-
throw new Error("getDbByTenant : mongodb object doesnt exist");
|
|
740
|
-
};
|
|
741
|
-
|
|
742
|
-
// src/models/AIChat.ts
|
|
743
|
-
var import_mongoose3 = __toESM(require("mongoose"));
|
|
744
|
-
|
|
745
|
-
// src/models/Annotations.ts
|
|
746
|
-
var import_mongoose2 = require("mongoose");
|
|
747
|
-
var AnnotationSchema = new import_mongoose2.Schema(
|
|
748
|
-
{
|
|
749
|
-
// Tags section - dynamic structure for various tag categories
|
|
750
|
-
tags: {
|
|
751
|
-
type: Map,
|
|
752
|
-
of: new import_mongoose2.Schema({
|
|
753
|
-
data: [
|
|
754
|
-
{
|
|
755
|
-
_id: { type: import_mongoose2.Schema.Types.ObjectId },
|
|
756
|
-
display: String,
|
|
757
|
-
tagId: String
|
|
758
|
-
}
|
|
759
|
-
],
|
|
760
|
-
collectionId: String
|
|
761
|
-
}, {
|
|
762
|
-
_id: false
|
|
763
|
-
})
|
|
764
|
-
},
|
|
765
|
-
// Meta information
|
|
766
|
-
meta: {
|
|
767
|
-
contentType: { type: String, required: true },
|
|
768
|
-
kp_contributed_by: {
|
|
769
|
-
type: import_mongoose2.Schema.Types.ObjectId,
|
|
770
|
-
ref: "user"
|
|
771
|
-
},
|
|
772
|
-
valuePath: String,
|
|
773
|
-
documentId: {
|
|
774
|
-
type: import_mongoose2.Schema.Types.ObjectId
|
|
775
|
-
}
|
|
776
|
-
},
|
|
777
|
-
// Main content data - using Schema.Types.Mixed for dynamic structure
|
|
778
|
-
main: {
|
|
779
|
-
type: import_mongoose2.Schema.Types.Mixed,
|
|
780
|
-
default: {}
|
|
781
|
-
},
|
|
782
|
-
// Annotation specific details
|
|
783
|
-
annotations: {
|
|
784
|
-
tags: {
|
|
785
|
-
type: Map,
|
|
786
|
-
of: new import_mongoose2.Schema({
|
|
787
|
-
collectionId: String,
|
|
788
|
-
data: [
|
|
789
|
-
{
|
|
790
|
-
_id: { type: import_mongoose2.Schema.Types.ObjectId },
|
|
791
|
-
display: String,
|
|
792
|
-
tagId: String
|
|
793
|
-
}
|
|
794
|
-
]
|
|
795
|
-
}, {
|
|
796
|
-
_id: false
|
|
797
|
-
})
|
|
798
|
-
},
|
|
799
|
-
fragment: {
|
|
800
|
-
isLexical: Boolean,
|
|
801
|
-
editorState: Object,
|
|
802
|
-
allText: String
|
|
803
|
-
},
|
|
804
|
-
annoKey: String,
|
|
805
|
-
author: {
|
|
806
|
-
id: { type: import_mongoose2.Schema.Types.ObjectId },
|
|
807
|
-
name: String
|
|
808
|
-
}
|
|
809
|
-
},
|
|
810
|
-
embeddings: Array,
|
|
811
|
-
contentEnhancedText: String,
|
|
812
|
-
// // Optional chunk related fields
|
|
813
|
-
// chunk: {
|
|
814
|
-
// embeddings: Schema.Types.Mixed,
|
|
815
|
-
// contentEnhancedText: String
|
|
816
|
-
// },
|
|
817
|
-
clusterId: String,
|
|
818
|
-
kp_date_published: Date,
|
|
819
|
-
createdAt: {
|
|
820
|
-
type: Date,
|
|
821
|
-
default: Date.now
|
|
822
|
-
},
|
|
823
|
-
updatedAt: {
|
|
824
|
-
type: Date,
|
|
825
|
-
default: Date.now
|
|
826
|
-
},
|
|
827
|
-
topicId: [{ type: import_mongoose2.Schema.Types.ObjectId, ref: "generatedTopics" }],
|
|
828
|
-
translations: Object
|
|
829
|
-
},
|
|
830
|
-
{
|
|
831
|
-
timestamps: true,
|
|
832
|
-
toJSON: { virtuals: true },
|
|
833
|
-
toObject: { virtuals: true },
|
|
834
|
-
strict: false
|
|
835
|
-
// This allows for flexible document structure beyond the defined schema
|
|
836
|
-
}
|
|
837
|
-
);
|
|
838
|
-
AnnotationSchema.index({ "meta.contentType": 1 });
|
|
839
|
-
AnnotationSchema.index({ "meta.documentId": 1 });
|
|
840
|
-
AnnotationSchema.index({ createdAt: -1 });
|
|
841
|
-
AnnotationSchema.index({ "annotations.annoKey": 1 });
|
|
842
|
-
AnnotationSchema.index({ "kp_date_published": -1 });
|
|
843
|
-
AnnotationSchema.pre("save", function(next) {
|
|
844
|
-
this.updatedAt = /* @__PURE__ */ new Date();
|
|
845
|
-
next();
|
|
846
|
-
});
|
|
847
|
-
AnnotationSchema.methods.getMainField = function(fieldPath) {
|
|
848
|
-
if (!fieldPath) return null;
|
|
849
|
-
const parts = fieldPath.split(".");
|
|
850
|
-
let value = this.main;
|
|
851
|
-
for (const part of parts) {
|
|
852
|
-
if (!value || typeof value !== "object") return null;
|
|
853
|
-
value = value[part];
|
|
854
|
-
}
|
|
855
|
-
return value;
|
|
856
|
-
};
|
|
857
|
-
AnnotationSchema.virtual("displayTitle").get(function() {
|
|
858
|
-
return this.main?.title || "Untitled Annotation";
|
|
859
|
-
});
|
|
860
|
-
var Annotations_default = AnnotationSchema;
|
|
861
|
-
|
|
862
|
-
// src/models/AIChat.ts
|
|
863
|
-
var AIChatSchema = new import_mongoose3.default.Schema(
|
|
864
|
-
{
|
|
865
|
-
userId: { type: import_mongoose3.default.Schema.Types.ObjectId, index: { unique: true } },
|
|
866
|
-
createdAt: Date,
|
|
867
|
-
lastAcitivity: Date,
|
|
868
|
-
messages: [
|
|
869
|
-
{
|
|
870
|
-
id: String,
|
|
871
|
-
author: {
|
|
872
|
-
type: String,
|
|
873
|
-
enum: ["system", "user", "assistant"]
|
|
874
|
-
},
|
|
875
|
-
content: {
|
|
876
|
-
type: { type: String },
|
|
877
|
-
value: String
|
|
878
|
-
},
|
|
879
|
-
vectorSearchInfo: {
|
|
880
|
-
chunks: [Annotations_default]
|
|
881
|
-
},
|
|
882
|
-
args: {
|
|
883
|
-
query: String,
|
|
884
|
-
reframedQuery: String,
|
|
885
|
-
summary: Object
|
|
886
|
-
},
|
|
887
|
-
userFeedback: {
|
|
888
|
-
reaction: { type: String, enum: ["positive", "negative"] },
|
|
889
|
-
comments: String
|
|
890
|
-
}
|
|
891
|
-
}
|
|
892
|
-
]
|
|
893
|
-
},
|
|
894
|
-
{ collection: "aiChat" }
|
|
895
|
-
);
|
|
896
|
-
var AIChat_default = AIChatSchema;
|
|
897
|
-
|
|
898
|
-
// src/models/PlatformConfigs.ts
|
|
899
|
-
var import_mongoose4 = __toESM(require("mongoose"));
|
|
900
|
-
var platformConfigTypes = [
|
|
901
|
-
"roles",
|
|
902
|
-
"nav",
|
|
903
|
-
"deployment",
|
|
904
|
-
"userAgreement",
|
|
905
|
-
"localeData",
|
|
906
|
-
"theme",
|
|
907
|
-
"AI"
|
|
908
|
-
];
|
|
909
|
-
var PlatformConfigsSchema = new import_mongoose4.default.Schema(
|
|
910
|
-
{
|
|
911
|
-
type: {
|
|
912
|
-
type: String,
|
|
913
|
-
enum: platformConfigTypes,
|
|
914
|
-
unique: true
|
|
915
|
-
},
|
|
916
|
-
roles: Array,
|
|
917
|
-
data: Object
|
|
918
|
-
},
|
|
919
|
-
{ collection: "platformConfigs" }
|
|
920
|
-
);
|
|
921
|
-
var PlatformConfigs_default = PlatformConfigsSchema;
|
|
922
|
-
|
|
923
|
-
// src/models/Tpl.ts
|
|
924
|
-
var import_mongoose5 = __toESM(require("mongoose"));
|
|
925
|
-
var TplSchema = new import_mongoose5.default.Schema({
|
|
926
|
-
dateFirstPublished: Date,
|
|
927
|
-
dateCreated: Date,
|
|
928
|
-
dateLastPublished: Date,
|
|
929
|
-
dateLastEdited: Date,
|
|
930
|
-
status: {
|
|
931
|
-
type: String,
|
|
932
|
-
default: "published",
|
|
933
|
-
// only cuz we dont want to go and add this property in all databases
|
|
934
|
-
enum: ["unpublished", "editPublished", "published"]
|
|
935
|
-
},
|
|
936
|
-
version: {
|
|
937
|
-
type: Number,
|
|
938
|
-
default: 0
|
|
939
|
-
},
|
|
940
|
-
versionPublishedBy: {
|
|
941
|
-
type: import_mongoose5.default.Schema.Types.ObjectId,
|
|
942
|
-
ref: "user"
|
|
943
|
-
// reference to the 'user' model
|
|
944
|
-
},
|
|
945
|
-
firstPublishedBy: {
|
|
946
|
-
type: import_mongoose5.default.Schema.Types.ObjectId,
|
|
947
|
-
ref: "user"
|
|
948
|
-
// reference to the 'user' model
|
|
949
|
-
},
|
|
950
|
-
kp_content_type: {
|
|
951
|
-
type: String,
|
|
952
|
-
required: true,
|
|
953
|
-
unique: true
|
|
954
|
-
},
|
|
955
|
-
category: {
|
|
956
|
-
//to deprecate and turn into 'layout'
|
|
957
|
-
type: String,
|
|
958
|
-
default: "knowledgeResources2"
|
|
959
|
-
},
|
|
960
|
-
kp_settings: [
|
|
961
|
-
{
|
|
962
|
-
type: Object
|
|
963
|
-
}
|
|
964
|
-
],
|
|
965
|
-
kp_templates: {
|
|
966
|
-
type: Object
|
|
967
|
-
},
|
|
968
|
-
tplMeta: Object,
|
|
969
|
-
tplLocales: Object,
|
|
970
|
-
indexed: Object,
|
|
971
|
-
drafts: {
|
|
972
|
-
active: Object
|
|
973
|
-
},
|
|
974
|
-
rollbacks: Object,
|
|
975
|
-
//for 'remembering' hidden configurations
|
|
976
|
-
// OTHER CONFIGS
|
|
977
|
-
listing: Object,
|
|
978
|
-
//listing page configurations. this is new, currently only used in nct
|
|
979
|
-
general: {
|
|
980
|
-
content: {
|
|
981
|
-
title: String,
|
|
982
|
-
singular: String,
|
|
983
|
-
ctaText: String,
|
|
984
|
-
listingDesc: String
|
|
985
|
-
},
|
|
986
|
-
allowQuickTagCreation: { enable: Boolean },
|
|
987
|
-
segment: String,
|
|
988
|
-
settingsUIStyle: String,
|
|
989
|
-
hasUpdateType: Boolean,
|
|
990
|
-
annotation: {
|
|
991
|
-
enable: Boolean
|
|
992
|
-
},
|
|
993
|
-
participantModule: {
|
|
994
|
-
enable: Boolean
|
|
995
|
-
},
|
|
996
|
-
formFieldNumbering: {
|
|
997
|
-
enable: Boolean
|
|
998
|
-
},
|
|
999
|
-
postPblRedirPath: Object,
|
|
1000
|
-
templateIndex: Object,
|
|
1001
|
-
sharing: {
|
|
1002
|
-
enable: Boolean,
|
|
1003
|
-
trackShareCount: {
|
|
1004
|
-
type: Boolean,
|
|
1005
|
-
default: false
|
|
1006
|
-
}
|
|
1007
|
-
},
|
|
1008
|
-
viewsCount: {
|
|
1009
|
-
enable: {
|
|
1010
|
-
type: Boolean,
|
|
1011
|
-
default: false
|
|
1012
|
-
}
|
|
1013
|
-
},
|
|
1014
|
-
comments: {
|
|
1015
|
-
enable: Boolean
|
|
1016
|
-
},
|
|
1017
|
-
reactions: {
|
|
1018
|
-
type: Map,
|
|
1019
|
-
of: {
|
|
1020
|
-
enable: Boolean,
|
|
1021
|
-
icon: String
|
|
1022
|
-
}
|
|
1023
|
-
},
|
|
1024
|
-
csvExport: {
|
|
1025
|
-
enable: Boolean,
|
|
1026
|
-
excludeFields: Array,
|
|
1027
|
-
enableUpdateExport: Boolean,
|
|
1028
|
-
fieldsToSortAtEnd: Array,
|
|
1029
|
-
fetchBatches: {
|
|
1030
|
-
enable: Boolean,
|
|
1031
|
-
batchSize: Number
|
|
1032
|
-
}
|
|
1033
|
-
},
|
|
1034
|
-
onboardingFlow: Object,
|
|
1035
|
-
//only on profile tpls
|
|
1036
|
-
selfServeSurveyConfig: Object,
|
|
1037
|
-
//tci helpers - these exist only to show / not show certain UIs in the tci
|
|
1038
|
-
disableKPSettings: Boolean
|
|
1039
|
-
}
|
|
1040
|
-
//general contenttype configs. mostly the stuff inside platformConfigs > contentTypes
|
|
1041
|
-
}, {
|
|
1042
|
-
toJSON: { virtuals: true },
|
|
1043
|
-
// So `res.json()` and other `JSON.stringify()` functions include virtuals
|
|
1044
|
-
toObject: { virtuals: true }
|
|
1045
|
-
// So `toObject()` output includes virtuals
|
|
1046
|
-
});
|
|
1047
|
-
TplSchema.virtual("layout").get(function() {
|
|
1048
|
-
return this.category;
|
|
1049
|
-
});
|
|
1050
|
-
var Tpl_default = TplSchema;
|
|
1302
|
+
// src/node.ts
|
|
1303
|
+
var import_getModelByTenant = __toESM(require_getModelByTenant());
|
|
1051
1304
|
|
|
1052
|
-
// src/
|
|
1053
|
-
|
|
1054
|
-
tenant,
|
|
1055
|
-
modelName,
|
|
1056
|
-
schema,
|
|
1057
|
-
env
|
|
1058
|
-
}) => {
|
|
1059
|
-
if (!tenant) {
|
|
1060
|
-
throw new Error("tenant id has not been provided");
|
|
1061
|
-
}
|
|
1062
|
-
const db = getDbByTenant({
|
|
1063
|
-
tenant,
|
|
1064
|
-
env
|
|
1065
|
-
});
|
|
1066
|
-
if (!Object.keys(db.models).includes(modelName)) {
|
|
1067
|
-
return db.model(modelName, schema);
|
|
1068
|
-
}
|
|
1069
|
-
return db.model(modelName);
|
|
1070
|
-
};
|
|
1071
|
-
var getAnnotationsModelByTenant = ({ tenant, env, mongodb, dbConfigs, modelName }) => getModelByTenant({
|
|
1072
|
-
tenant,
|
|
1073
|
-
modelName: modelName || "annotations",
|
|
1074
|
-
schema: Annotations_default,
|
|
1075
|
-
env
|
|
1076
|
-
});
|
|
1077
|
-
var getChunksModelByTenant = ({ tenant, env, mongodb, dbConfigs, modelName }) => getModelByTenant({
|
|
1078
|
-
tenant,
|
|
1079
|
-
modelName: modelName || "chunks",
|
|
1080
|
-
schema: Annotations_default,
|
|
1081
|
-
env
|
|
1082
|
-
});
|
|
1083
|
-
var getPlatformConfigsModelByTenant = ({ tenant, env, mongodb, dbConfigs }) => getModelByTenant({
|
|
1084
|
-
tenant,
|
|
1085
|
-
modelName: "platformConfigs",
|
|
1086
|
-
schema: PlatformConfigs_default,
|
|
1087
|
-
env
|
|
1088
|
-
});
|
|
1089
|
-
var getTplModelByTenant = ({ tenant, env, mongodb, dbConfigs }) => getModelByTenant({
|
|
1090
|
-
tenant,
|
|
1091
|
-
modelName: "tpl",
|
|
1092
|
-
schema: Tpl_default,
|
|
1093
|
-
env
|
|
1094
|
-
});
|
|
1095
|
-
var getAIChatModelByTenant = ({ tenant, env, mongodb, dbConfigs }) => getModelByTenant({
|
|
1096
|
-
tenant,
|
|
1097
|
-
modelName: "aiChat",
|
|
1098
|
-
schema: AIChat_default,
|
|
1099
|
-
env
|
|
1100
|
-
});
|
|
1305
|
+
// src/redis/functions.ts
|
|
1306
|
+
init_getDbByTenant();
|
|
1101
1307
|
|
|
1102
1308
|
// src/redis/index.ts
|
|
1103
1309
|
var import_ioredis = __toESM(require("ioredis"));
|
|
@@ -1207,6 +1413,7 @@ var getAIConfigs = async ({
|
|
|
1207
1413
|
};
|
|
1208
1414
|
|
|
1209
1415
|
// src/node.ts
|
|
1416
|
+
init_models();
|
|
1210
1417
|
var import_WorkerManager = __toESM(require_WorkerManager());
|
|
1211
1418
|
var import_BaseProducer = __toESM(require_BaseProducer());
|
|
1212
1419
|
var import_BaseWorker = __toESM(require_BaseWorker());
|
|
@@ -1218,6 +1425,7 @@ var import_GET_GLOBAL_BULLMQ_CONFIG = __toESM(require_GET_GLOBAL_BULLMQ_CONFIG()
|
|
|
1218
1425
|
BaseProducer,
|
|
1219
1426
|
BaseWorker,
|
|
1220
1427
|
GET_GLOBAL_BULLMQ_CONFIG,
|
|
1428
|
+
MongoConnector,
|
|
1221
1429
|
PlatformConfigsSchema,
|
|
1222
1430
|
TplSchema,
|
|
1223
1431
|
WorkerManager,
|
|
@@ -1228,7 +1436,6 @@ var import_GET_GLOBAL_BULLMQ_CONFIG = __toESM(require_GET_GLOBAL_BULLMQ_CONFIG()
|
|
|
1228
1436
|
getAIChatModelByTenant,
|
|
1229
1437
|
getAIConfigs,
|
|
1230
1438
|
getAnnotationsModelByTenant,
|
|
1231
|
-
getChunksModelByTenant,
|
|
1232
1439
|
getDbByTenant,
|
|
1233
1440
|
getModelByTenant,
|
|
1234
1441
|
getPlatformConfigsModelByTenant,
|
|
@@ -1237,7 +1444,6 @@ var import_GET_GLOBAL_BULLMQ_CONFIG = __toESM(require_GET_GLOBAL_BULLMQ_CONFIG()
|
|
|
1237
1444
|
getTplModelByTenant,
|
|
1238
1445
|
getVal,
|
|
1239
1446
|
initializeGlobalConfig,
|
|
1240
|
-
multiConnectToMongoDB,
|
|
1241
1447
|
recursivelyExtractBlocks,
|
|
1242
1448
|
setVal,
|
|
1243
1449
|
toArray,
|