@okf/ootils 1.3.10 → 1.4.0
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 +69 -87
- package/dist/node.d.ts +69 -87
- package/dist/node.js +648 -434
- package/dist/node.mjs +653 -433
- 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,18 +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,
|
|
986
|
+
getAnnotationsModelByTenant: () => import_getModelByTenant.getAnnotationsModelByTenant,
|
|
355
987
|
getDbByTenant: () => getDbByTenant,
|
|
356
|
-
getModelByTenant: () => getModelByTenant,
|
|
357
|
-
getPlatformConfigsModelByTenant: () => getPlatformConfigsModelByTenant,
|
|
988
|
+
getModelByTenant: () => import_getModelByTenant.getModelByTenant,
|
|
989
|
+
getPlatformConfigsModelByTenant: () => import_getModelByTenant.getPlatformConfigsModelByTenant,
|
|
358
990
|
getRedisClient: () => getRedisClient,
|
|
359
991
|
getTpl: () => getTpl,
|
|
360
|
-
getTplModelByTenant: () => getTplModelByTenant,
|
|
992
|
+
getTplModelByTenant: () => import_getModelByTenant.getTplModelByTenant,
|
|
361
993
|
getVal: () => getVal,
|
|
362
994
|
initializeGlobalConfig: () => initializeGlobalConfig,
|
|
363
|
-
multiConnectToMongoDB: () => multiConnectToMongoDB,
|
|
364
995
|
recursivelyExtractBlocks: () => _recursExtractBlocks,
|
|
365
996
|
setVal: () => setVal,
|
|
366
997
|
toArray: () => toArray,
|
|
@@ -643,18 +1274,12 @@ var _extractBlocksFromSomeBuilders = ({
|
|
|
643
1274
|
}
|
|
644
1275
|
};
|
|
645
1276
|
|
|
646
|
-
// src/
|
|
647
|
-
var
|
|
1277
|
+
// src/node.ts
|
|
1278
|
+
var import_MongoConnector2 = __toESM(require_MongoConnector());
|
|
1279
|
+
init_getDbByTenant();
|
|
648
1280
|
|
|
649
1281
|
// src/db/getGlobalConfig.ts
|
|
650
1282
|
var globalConfig = {};
|
|
651
|
-
var getGlobalConfig = () => {
|
|
652
|
-
return {
|
|
653
|
-
env: globalConfig.env,
|
|
654
|
-
dbConfigs: globalConfig.dbConfigs ? { ...globalConfig.dbConfigs } : void 0,
|
|
655
|
-
mongodb: globalConfig.mongodb ? { ...globalConfig.mongodb } : void 0
|
|
656
|
-
};
|
|
657
|
-
};
|
|
658
1283
|
var initializeGlobalConfig = (config) => {
|
|
659
1284
|
globalConfig = {
|
|
660
1285
|
env: config.env,
|
|
@@ -674,423 +1299,11 @@ var updateGlobalConfig = (updates) => {
|
|
|
674
1299
|
console.log("Global config updated:", Object.keys(updates));
|
|
675
1300
|
};
|
|
676
1301
|
|
|
677
|
-
// src/
|
|
678
|
-
var
|
|
679
|
-
// Note: These legacy options are no longer needed in newer versions of mongoose
|
|
680
|
-
// useUnifiedTopology, useNewUrlParser, useCreateIndex, useFindAndModify are deprecated
|
|
681
|
-
maxPoolSize: 20
|
|
682
|
-
// replaces poolSize
|
|
683
|
-
};
|
|
684
|
-
var multiConnectToMongoDB = ({ env, dbConfigs } = {}) => {
|
|
685
|
-
const globalConfig2 = getGlobalConfig();
|
|
686
|
-
const actualEnv = env || globalConfig2.env;
|
|
687
|
-
const actualDbConfigs = dbConfigs || globalConfig2.dbConfigs;
|
|
688
|
-
if (!actualEnv) {
|
|
689
|
-
throw new Error("Environment not provided and not found in global config");
|
|
690
|
-
}
|
|
691
|
-
if (!actualDbConfigs) {
|
|
692
|
-
throw new Error("dbConfigs not provided and not found in global config");
|
|
693
|
-
}
|
|
694
|
-
const { connectTo } = actualDbConfigs[actualEnv];
|
|
695
|
-
if (!connectTo) {
|
|
696
|
-
throw new Error(`No connection configuration found for environment: ${actualEnv}`);
|
|
697
|
-
}
|
|
698
|
-
const dbConnections = {};
|
|
699
|
-
connectTo.forEach((connectToEnv) => {
|
|
700
|
-
const { CLUSTER_NAME, DB_URI } = actualDbConfigs[connectToEnv];
|
|
701
|
-
if (!CLUSTER_NAME || !DB_URI) {
|
|
702
|
-
throw new Error(`Missing CLUSTER_NAME or DB_URI for environment: ${connectToEnv}`);
|
|
703
|
-
}
|
|
704
|
-
dbConnections[CLUSTER_NAME] = import_mongoose.default.createConnection(DB_URI, mongoOptions);
|
|
705
|
-
dbConnections[CLUSTER_NAME].on("open", () => {
|
|
706
|
-
console.log(`Mongoose connection open to ${CLUSTER_NAME}`);
|
|
707
|
-
});
|
|
708
|
-
dbConnections[CLUSTER_NAME].on("error", (err) => {
|
|
709
|
-
console.log(`Mongoose connection error: ${err.message} with connection info ${CLUSTER_NAME}`);
|
|
710
|
-
process.exit(1);
|
|
711
|
-
});
|
|
712
|
-
});
|
|
713
|
-
return dbConnections;
|
|
714
|
-
};
|
|
715
|
-
|
|
716
|
-
// src/db/getDbByTenant.ts
|
|
717
|
-
var getDbByTenant = ({
|
|
718
|
-
tenant,
|
|
719
|
-
env
|
|
720
|
-
}) => {
|
|
721
|
-
if (!tenant) throw new Error("tenant id has not been provided");
|
|
722
|
-
const globalConfig2 = getGlobalConfig();
|
|
723
|
-
const actualEnv = env || globalConfig2.env;
|
|
724
|
-
const dbConfigs = globalConfig2.dbConfigs;
|
|
725
|
-
const mongodb = globalConfig2.mongodb;
|
|
726
|
-
if (!dbConfigs) {
|
|
727
|
-
throw new Error("dbConfigs not found in global config");
|
|
728
|
-
}
|
|
729
|
-
if (!actualEnv) {
|
|
730
|
-
throw new Error("env not provided and not found in global config");
|
|
731
|
-
}
|
|
732
|
-
const { CLUSTER_NAME } = dbConfigs[actualEnv];
|
|
733
|
-
const dbName = `${tenant}_${actualEnv}`;
|
|
734
|
-
if (mongodb) {
|
|
735
|
-
const db = mongodb[CLUSTER_NAME].useDb(dbName, { useCache: true });
|
|
736
|
-
return db;
|
|
737
|
-
}
|
|
738
|
-
throw new Error("getDbByTenant : mongodb object doesnt exist");
|
|
739
|
-
};
|
|
740
|
-
|
|
741
|
-
// src/models/AIChat.ts
|
|
742
|
-
var import_mongoose3 = __toESM(require("mongoose"));
|
|
743
|
-
|
|
744
|
-
// src/models/Annotations.ts
|
|
745
|
-
var import_mongoose2 = require("mongoose");
|
|
746
|
-
var AnnotationSchema = new import_mongoose2.Schema(
|
|
747
|
-
{
|
|
748
|
-
// Tags section - dynamic structure for various tag categories
|
|
749
|
-
tags: {
|
|
750
|
-
type: Map,
|
|
751
|
-
of: new import_mongoose2.Schema({
|
|
752
|
-
data: [
|
|
753
|
-
{
|
|
754
|
-
_id: { type: import_mongoose2.Schema.Types.ObjectId },
|
|
755
|
-
display: String,
|
|
756
|
-
tagId: String
|
|
757
|
-
}
|
|
758
|
-
],
|
|
759
|
-
collectionId: String
|
|
760
|
-
}, {
|
|
761
|
-
_id: false
|
|
762
|
-
})
|
|
763
|
-
},
|
|
764
|
-
// Meta information
|
|
765
|
-
meta: {
|
|
766
|
-
contentType: { type: String, required: true },
|
|
767
|
-
kp_contributed_by: {
|
|
768
|
-
type: import_mongoose2.Schema.Types.ObjectId,
|
|
769
|
-
ref: "user"
|
|
770
|
-
},
|
|
771
|
-
valuePath: String,
|
|
772
|
-
documentId: {
|
|
773
|
-
type: import_mongoose2.Schema.Types.ObjectId
|
|
774
|
-
}
|
|
775
|
-
},
|
|
776
|
-
// Main content data - using Schema.Types.Mixed for dynamic structure
|
|
777
|
-
main: {
|
|
778
|
-
type: import_mongoose2.Schema.Types.Mixed,
|
|
779
|
-
default: {}
|
|
780
|
-
},
|
|
781
|
-
// Annotation specific details
|
|
782
|
-
annotations: {
|
|
783
|
-
tags: {
|
|
784
|
-
type: Map,
|
|
785
|
-
of: new import_mongoose2.Schema({
|
|
786
|
-
collectionId: String,
|
|
787
|
-
data: [
|
|
788
|
-
{
|
|
789
|
-
_id: { type: import_mongoose2.Schema.Types.ObjectId },
|
|
790
|
-
display: String,
|
|
791
|
-
tagId: String
|
|
792
|
-
}
|
|
793
|
-
]
|
|
794
|
-
}, {
|
|
795
|
-
_id: false
|
|
796
|
-
})
|
|
797
|
-
},
|
|
798
|
-
fragment: {
|
|
799
|
-
isLexical: Boolean,
|
|
800
|
-
editorState: Object,
|
|
801
|
-
allText: String
|
|
802
|
-
},
|
|
803
|
-
annoKey: String,
|
|
804
|
-
author: {
|
|
805
|
-
id: { type: import_mongoose2.Schema.Types.ObjectId },
|
|
806
|
-
name: String
|
|
807
|
-
}
|
|
808
|
-
},
|
|
809
|
-
embeddings: Array,
|
|
810
|
-
contentEnhancedText: String,
|
|
811
|
-
// // Optional chunk related fields
|
|
812
|
-
// chunk: {
|
|
813
|
-
// embeddings: Schema.Types.Mixed,
|
|
814
|
-
// contentEnhancedText: String
|
|
815
|
-
// },
|
|
816
|
-
clusterId: String,
|
|
817
|
-
kp_date_published: Date,
|
|
818
|
-
createdAt: {
|
|
819
|
-
type: Date,
|
|
820
|
-
default: Date.now
|
|
821
|
-
},
|
|
822
|
-
updatedAt: {
|
|
823
|
-
type: Date,
|
|
824
|
-
default: Date.now
|
|
825
|
-
},
|
|
826
|
-
topicId: [{ type: import_mongoose2.Schema.Types.ObjectId, ref: "generatedTopics" }],
|
|
827
|
-
translations: Object
|
|
828
|
-
},
|
|
829
|
-
{
|
|
830
|
-
timestamps: true,
|
|
831
|
-
toJSON: { virtuals: true },
|
|
832
|
-
toObject: { virtuals: true },
|
|
833
|
-
strict: false
|
|
834
|
-
// This allows for flexible document structure beyond the defined schema
|
|
835
|
-
}
|
|
836
|
-
);
|
|
837
|
-
AnnotationSchema.index({ "meta.contentType": 1 });
|
|
838
|
-
AnnotationSchema.index({ "meta.documentId": 1 });
|
|
839
|
-
AnnotationSchema.index({ createdAt: -1 });
|
|
840
|
-
AnnotationSchema.index({ "annotations.annoKey": 1 });
|
|
841
|
-
AnnotationSchema.index({ "kp_date_published": -1 });
|
|
842
|
-
AnnotationSchema.pre("save", function(next) {
|
|
843
|
-
this.updatedAt = /* @__PURE__ */ new Date();
|
|
844
|
-
next();
|
|
845
|
-
});
|
|
846
|
-
AnnotationSchema.methods.getMainField = function(fieldPath) {
|
|
847
|
-
if (!fieldPath) return null;
|
|
848
|
-
const parts = fieldPath.split(".");
|
|
849
|
-
let value = this.main;
|
|
850
|
-
for (const part of parts) {
|
|
851
|
-
if (!value || typeof value !== "object") return null;
|
|
852
|
-
value = value[part];
|
|
853
|
-
}
|
|
854
|
-
return value;
|
|
855
|
-
};
|
|
856
|
-
AnnotationSchema.virtual("displayTitle").get(function() {
|
|
857
|
-
return this.main?.title || "Untitled Annotation";
|
|
858
|
-
});
|
|
859
|
-
var Annotations_default = AnnotationSchema;
|
|
860
|
-
|
|
861
|
-
// src/models/AIChat.ts
|
|
862
|
-
var AIChatSchema = new import_mongoose3.default.Schema(
|
|
863
|
-
{
|
|
864
|
-
userId: { type: import_mongoose3.default.Schema.Types.ObjectId, index: { unique: true } },
|
|
865
|
-
createdAt: Date,
|
|
866
|
-
lastAcitivity: Date,
|
|
867
|
-
messages: [
|
|
868
|
-
{
|
|
869
|
-
id: String,
|
|
870
|
-
author: {
|
|
871
|
-
type: String,
|
|
872
|
-
enum: ["system", "user", "assistant"]
|
|
873
|
-
},
|
|
874
|
-
content: {
|
|
875
|
-
type: { type: String },
|
|
876
|
-
value: String
|
|
877
|
-
},
|
|
878
|
-
vectorSearchInfo: {
|
|
879
|
-
chunks: [Annotations_default]
|
|
880
|
-
},
|
|
881
|
-
args: {
|
|
882
|
-
query: String,
|
|
883
|
-
reframedQuery: String,
|
|
884
|
-
summary: Object
|
|
885
|
-
},
|
|
886
|
-
userFeedback: {
|
|
887
|
-
reaction: { type: String, enum: ["positive", "negative"] },
|
|
888
|
-
comments: String
|
|
889
|
-
}
|
|
890
|
-
}
|
|
891
|
-
]
|
|
892
|
-
},
|
|
893
|
-
{ collection: "aiChat" }
|
|
894
|
-
);
|
|
895
|
-
var AIChat_default = AIChatSchema;
|
|
896
|
-
|
|
897
|
-
// src/models/PlatformConfigs.ts
|
|
898
|
-
var import_mongoose4 = __toESM(require("mongoose"));
|
|
899
|
-
var platformConfigTypes = [
|
|
900
|
-
"roles",
|
|
901
|
-
"nav",
|
|
902
|
-
"deployment",
|
|
903
|
-
"userAgreement",
|
|
904
|
-
"localeData",
|
|
905
|
-
"theme",
|
|
906
|
-
"AI"
|
|
907
|
-
];
|
|
908
|
-
var PlatformConfigsSchema = new import_mongoose4.default.Schema(
|
|
909
|
-
{
|
|
910
|
-
type: {
|
|
911
|
-
type: String,
|
|
912
|
-
enum: platformConfigTypes,
|
|
913
|
-
unique: true
|
|
914
|
-
},
|
|
915
|
-
roles: Array,
|
|
916
|
-
data: Object
|
|
917
|
-
},
|
|
918
|
-
{ collection: "platformConfigs" }
|
|
919
|
-
);
|
|
920
|
-
var PlatformConfigs_default = PlatformConfigsSchema;
|
|
921
|
-
|
|
922
|
-
// src/models/Tpl.ts
|
|
923
|
-
var import_mongoose5 = __toESM(require("mongoose"));
|
|
924
|
-
var TplSchema = new import_mongoose5.default.Schema({
|
|
925
|
-
dateFirstPublished: Date,
|
|
926
|
-
dateCreated: Date,
|
|
927
|
-
dateLastPublished: Date,
|
|
928
|
-
dateLastEdited: Date,
|
|
929
|
-
status: {
|
|
930
|
-
type: String,
|
|
931
|
-
default: "published",
|
|
932
|
-
// only cuz we dont want to go and add this property in all databases
|
|
933
|
-
enum: ["unpublished", "editPublished", "published"]
|
|
934
|
-
},
|
|
935
|
-
version: {
|
|
936
|
-
type: Number,
|
|
937
|
-
default: 0
|
|
938
|
-
},
|
|
939
|
-
versionPublishedBy: {
|
|
940
|
-
type: import_mongoose5.default.Schema.Types.ObjectId,
|
|
941
|
-
ref: "user"
|
|
942
|
-
// reference to the 'user' model
|
|
943
|
-
},
|
|
944
|
-
firstPublishedBy: {
|
|
945
|
-
type: import_mongoose5.default.Schema.Types.ObjectId,
|
|
946
|
-
ref: "user"
|
|
947
|
-
// reference to the 'user' model
|
|
948
|
-
},
|
|
949
|
-
kp_content_type: {
|
|
950
|
-
type: String,
|
|
951
|
-
required: true,
|
|
952
|
-
unique: true
|
|
953
|
-
},
|
|
954
|
-
category: {
|
|
955
|
-
//to deprecate and turn into 'layout'
|
|
956
|
-
type: String,
|
|
957
|
-
default: "knowledgeResources2"
|
|
958
|
-
},
|
|
959
|
-
kp_settings: [
|
|
960
|
-
{
|
|
961
|
-
type: Object
|
|
962
|
-
}
|
|
963
|
-
],
|
|
964
|
-
kp_templates: {
|
|
965
|
-
type: Object
|
|
966
|
-
},
|
|
967
|
-
tplMeta: Object,
|
|
968
|
-
tplLocales: Object,
|
|
969
|
-
indexed: Object,
|
|
970
|
-
drafts: {
|
|
971
|
-
active: Object
|
|
972
|
-
},
|
|
973
|
-
rollbacks: Object,
|
|
974
|
-
//for 'remembering' hidden configurations
|
|
975
|
-
// OTHER CONFIGS
|
|
976
|
-
listing: Object,
|
|
977
|
-
//listing page configurations. this is new, currently only used in nct
|
|
978
|
-
general: {
|
|
979
|
-
content: {
|
|
980
|
-
title: String,
|
|
981
|
-
singular: String,
|
|
982
|
-
ctaText: String,
|
|
983
|
-
listingDesc: String
|
|
984
|
-
},
|
|
985
|
-
allowQuickTagCreation: { enable: Boolean },
|
|
986
|
-
segment: String,
|
|
987
|
-
settingsUIStyle: String,
|
|
988
|
-
hasUpdateType: Boolean,
|
|
989
|
-
annotation: {
|
|
990
|
-
enable: Boolean
|
|
991
|
-
},
|
|
992
|
-
participantModule: {
|
|
993
|
-
enable: Boolean
|
|
994
|
-
},
|
|
995
|
-
formFieldNumbering: {
|
|
996
|
-
enable: Boolean
|
|
997
|
-
},
|
|
998
|
-
postPblRedirPath: Object,
|
|
999
|
-
templateIndex: Object,
|
|
1000
|
-
sharing: {
|
|
1001
|
-
enable: Boolean,
|
|
1002
|
-
trackShareCount: {
|
|
1003
|
-
type: Boolean,
|
|
1004
|
-
default: false
|
|
1005
|
-
}
|
|
1006
|
-
},
|
|
1007
|
-
viewsCount: {
|
|
1008
|
-
enable: {
|
|
1009
|
-
type: Boolean,
|
|
1010
|
-
default: false
|
|
1011
|
-
}
|
|
1012
|
-
},
|
|
1013
|
-
comments: {
|
|
1014
|
-
enable: Boolean
|
|
1015
|
-
},
|
|
1016
|
-
reactions: {
|
|
1017
|
-
type: Map,
|
|
1018
|
-
of: {
|
|
1019
|
-
enable: Boolean,
|
|
1020
|
-
icon: String
|
|
1021
|
-
}
|
|
1022
|
-
},
|
|
1023
|
-
csvExport: {
|
|
1024
|
-
enable: Boolean,
|
|
1025
|
-
excludeFields: Array,
|
|
1026
|
-
enableUpdateExport: Boolean,
|
|
1027
|
-
fieldsToSortAtEnd: Array,
|
|
1028
|
-
fetchBatches: {
|
|
1029
|
-
enable: Boolean,
|
|
1030
|
-
batchSize: Number
|
|
1031
|
-
}
|
|
1032
|
-
},
|
|
1033
|
-
onboardingFlow: Object,
|
|
1034
|
-
//only on profile tpls
|
|
1035
|
-
selfServeSurveyConfig: Object,
|
|
1036
|
-
//tci helpers - these exist only to show / not show certain UIs in the tci
|
|
1037
|
-
disableKPSettings: Boolean
|
|
1038
|
-
}
|
|
1039
|
-
//general contenttype configs. mostly the stuff inside platformConfigs > contentTypes
|
|
1040
|
-
}, {
|
|
1041
|
-
toJSON: { virtuals: true },
|
|
1042
|
-
// So `res.json()` and other `JSON.stringify()` functions include virtuals
|
|
1043
|
-
toObject: { virtuals: true }
|
|
1044
|
-
// So `toObject()` output includes virtuals
|
|
1045
|
-
});
|
|
1046
|
-
TplSchema.virtual("layout").get(function() {
|
|
1047
|
-
return this.category;
|
|
1048
|
-
});
|
|
1049
|
-
var Tpl_default = TplSchema;
|
|
1302
|
+
// src/node.ts
|
|
1303
|
+
var import_getModelByTenant = __toESM(require_getModelByTenant());
|
|
1050
1304
|
|
|
1051
|
-
// src/
|
|
1052
|
-
|
|
1053
|
-
tenant,
|
|
1054
|
-
modelName,
|
|
1055
|
-
schema,
|
|
1056
|
-
env
|
|
1057
|
-
}) => {
|
|
1058
|
-
if (!tenant) {
|
|
1059
|
-
throw new Error("tenant id has not been provided");
|
|
1060
|
-
}
|
|
1061
|
-
const db = getDbByTenant({
|
|
1062
|
-
tenant,
|
|
1063
|
-
env
|
|
1064
|
-
});
|
|
1065
|
-
if (!Object.keys(db.models).includes(modelName)) {
|
|
1066
|
-
return db.model(modelName, schema);
|
|
1067
|
-
}
|
|
1068
|
-
return db.model(modelName);
|
|
1069
|
-
};
|
|
1070
|
-
var getAnnotationsModelByTenant = ({ tenant, env, mongodb, dbConfigs, modelName }) => getModelByTenant({
|
|
1071
|
-
tenant,
|
|
1072
|
-
modelName: modelName || "annotations",
|
|
1073
|
-
schema: Annotations_default,
|
|
1074
|
-
env
|
|
1075
|
-
});
|
|
1076
|
-
var getPlatformConfigsModelByTenant = ({ tenant, env, mongodb, dbConfigs }) => getModelByTenant({
|
|
1077
|
-
tenant,
|
|
1078
|
-
modelName: "platformConfigs",
|
|
1079
|
-
schema: PlatformConfigs_default,
|
|
1080
|
-
env
|
|
1081
|
-
});
|
|
1082
|
-
var getTplModelByTenant = ({ tenant, env, mongodb, dbConfigs }) => getModelByTenant({
|
|
1083
|
-
tenant,
|
|
1084
|
-
modelName: "tpl",
|
|
1085
|
-
schema: Tpl_default,
|
|
1086
|
-
env
|
|
1087
|
-
});
|
|
1088
|
-
var getAIChatModelByTenant = ({ tenant, env, mongodb, dbConfigs }) => getModelByTenant({
|
|
1089
|
-
tenant,
|
|
1090
|
-
modelName: "aiChat",
|
|
1091
|
-
schema: AIChat_default,
|
|
1092
|
-
env
|
|
1093
|
-
});
|
|
1305
|
+
// src/redis/functions.ts
|
|
1306
|
+
init_getDbByTenant();
|
|
1094
1307
|
|
|
1095
1308
|
// src/redis/index.ts
|
|
1096
1309
|
var import_ioredis = __toESM(require("ioredis"));
|
|
@@ -1200,6 +1413,7 @@ var getAIConfigs = async ({
|
|
|
1200
1413
|
};
|
|
1201
1414
|
|
|
1202
1415
|
// src/node.ts
|
|
1416
|
+
init_models();
|
|
1203
1417
|
var import_WorkerManager = __toESM(require_WorkerManager());
|
|
1204
1418
|
var import_BaseProducer = __toESM(require_BaseProducer());
|
|
1205
1419
|
var import_BaseWorker = __toESM(require_BaseWorker());
|
|
@@ -1211,6 +1425,7 @@ var import_GET_GLOBAL_BULLMQ_CONFIG = __toESM(require_GET_GLOBAL_BULLMQ_CONFIG()
|
|
|
1211
1425
|
BaseProducer,
|
|
1212
1426
|
BaseWorker,
|
|
1213
1427
|
GET_GLOBAL_BULLMQ_CONFIG,
|
|
1428
|
+
MongoConnector,
|
|
1214
1429
|
PlatformConfigsSchema,
|
|
1215
1430
|
TplSchema,
|
|
1216
1431
|
WorkerManager,
|
|
@@ -1229,7 +1444,6 @@ var import_GET_GLOBAL_BULLMQ_CONFIG = __toESM(require_GET_GLOBAL_BULLMQ_CONFIG()
|
|
|
1229
1444
|
getTplModelByTenant,
|
|
1230
1445
|
getVal,
|
|
1231
1446
|
initializeGlobalConfig,
|
|
1232
|
-
multiConnectToMongoDB,
|
|
1233
1447
|
recursivelyExtractBlocks,
|
|
1234
1448
|
setVal,
|
|
1235
1449
|
toArray,
|