@okf/ootils 1.3.5 → 1.3.7

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.mjs CHANGED
@@ -1,298 +1,3 @@
1
- var __getOwnPropNames = Object.getOwnPropertyNames;
2
- var __require = /* @__PURE__ */ ((x) => typeof require !== "undefined" ? require : typeof Proxy !== "undefined" ? new Proxy(x, {
3
- get: (a, b) => (typeof require !== "undefined" ? require : a)[b]
4
- }) : x)(function(x) {
5
- if (typeof require !== "undefined") return require.apply(this, arguments);
6
- throw Error('Dynamic require of "' + x + '" is not supported');
7
- });
8
- var __commonJS = (cb, mod) => function __require2() {
9
- return mod || (0, cb[__getOwnPropNames(cb)[0]])((mod = { exports: {} }).exports, mod), mod.exports;
10
- };
11
-
12
- // src/models/Annotations.js
13
- var require_Annotations = __commonJS({
14
- "src/models/Annotations.js"(exports, module) {
15
- "use strict";
16
- var mongoose2 = __require("mongoose");
17
- var Schema = mongoose2.Schema;
18
- var AnnotationSchema = new Schema(
19
- {
20
- // Tags section - dynamic structure for various tag categories
21
- tags: {
22
- type: Map,
23
- of: new Schema({
24
- data: [
25
- {
26
- _id: { type: Schema.Types.ObjectId },
27
- display: String,
28
- tagId: String
29
- }
30
- ],
31
- collectionId: String,
32
- _id: false
33
- })
34
- },
35
- // Meta information
36
- meta: {
37
- contentType: { type: String, required: true },
38
- kp_contributed_by: {
39
- type: Schema.Types.ObjectId,
40
- ref: "user"
41
- },
42
- valuePath: String,
43
- documentId: {
44
- type: Schema.Types.ObjectId
45
- }
46
- },
47
- // Main content data - using Schema.Types.Mixed for dynamic structure
48
- main: {
49
- type: Schema.Types.Mixed,
50
- default: {}
51
- },
52
- // Annotation specific details
53
- annotations: {
54
- tags: {
55
- type: Map,
56
- _id: false,
57
- of: new Schema({
58
- collectionId: String,
59
- data: [
60
- {
61
- _id: { type: Schema.Types.ObjectId },
62
- display: String,
63
- tagId: String
64
- }
65
- ]
66
- })
67
- },
68
- fragment: {
69
- isLexical: Boolean,
70
- editorState: Object,
71
- allText: String
72
- },
73
- annoKey: String,
74
- author: {
75
- id: { type: Schema.Types.ObjectId },
76
- name: String
77
- }
78
- },
79
- embeddings: Array,
80
- contentEnhancedText: String,
81
- // // Optional chunk related fields
82
- // chunk: {
83
- // embeddings: Schema.Types.Mixed,
84
- // contentEnhancedText: String
85
- // },
86
- clusterId: String,
87
- kp_date_published: Date,
88
- createdAt: {
89
- type: Date,
90
- default: Date.now
91
- },
92
- updatedAt: {
93
- type: Date,
94
- default: Date.now
95
- },
96
- translations: Object
97
- },
98
- {
99
- timestamps: true,
100
- toJSON: { virtuals: true },
101
- toObject: { virtuals: true },
102
- strict: false
103
- // This allows for flexible document structure beyond the defined schema
104
- }
105
- );
106
- AnnotationSchema.index({ "meta.contentType": 1 });
107
- AnnotationSchema.index({ "meta.documentId": 1 });
108
- AnnotationSchema.index({ createdAt: -1 });
109
- AnnotationSchema.index({ "annotations.annoKey": 1 });
110
- AnnotationSchema.pre("save", function(next) {
111
- this.updatedAt = /* @__PURE__ */ new Date();
112
- next();
113
- });
114
- AnnotationSchema.methods.getMainField = function(fieldPath) {
115
- if (!fieldPath) return null;
116
- const parts = fieldPath.split(".");
117
- let value = this.main;
118
- for (const part of parts) {
119
- if (!value || typeof value !== "object") return null;
120
- value = value[part];
121
- }
122
- return value;
123
- };
124
- AnnotationSchema.virtual("displayTitle").get(function() {
125
- return this.main.title || "Untitled Annotation";
126
- });
127
- module.exports = AnnotationSchema;
128
- }
129
- });
130
-
131
- // src/models/PlatformConfigs.js
132
- var require_PlatformConfigs = __commonJS({
133
- "src/models/PlatformConfigs.js"(exports, module) {
134
- "use strict";
135
- var mongoose2 = __require("mongoose");
136
- var platformConfigTypes = [
137
- { id: "roles" },
138
- { id: "contentTypes" },
139
- { id: "contentCards" },
140
- { id: "profileTypes" },
141
- { id: "nav" },
142
- { id: "deployment" },
143
- { id: "userAgreement" },
144
- { id: "localeData" },
145
- { id: "theme" },
146
- { id: "tagTypes" },
147
- { id: "AI" }
148
- ];
149
- var PlatformConfigsSchema2 = new mongoose2.Schema(
150
- {
151
- type: {
152
- type: String,
153
- enum: platformConfigTypes.map((d) => d.id),
154
- unique: true
155
- },
156
- roles: Array,
157
- data: Object
158
- },
159
- { collection: "platformConfigs" }
160
- );
161
- module.exports = PlatformConfigsSchema2;
162
- }
163
- });
164
-
165
- // src/models/Tpl.js
166
- var require_Tpl = __commonJS({
167
- "src/models/Tpl.js"(exports, module) {
168
- "use strict";
169
- var mongoose2 = __require("mongoose");
170
- var TplSchema2 = new mongoose2.Schema({
171
- dateFirstPublished: Date,
172
- dateCreated: Date,
173
- dateLastPublished: Date,
174
- dateLastEdited: Date,
175
- status: {
176
- type: String,
177
- default: "published",
178
- // only cuz we dont want to go and add this property in all databases
179
- enum: ["unpublished", "editPublished", "published"]
180
- },
181
- version: {
182
- type: Number,
183
- default: 0
184
- },
185
- versionPublishedBy: {
186
- type: mongoose2.Schema.Types.ObjectId,
187
- ref: "user"
188
- // reference to the 'user' model
189
- },
190
- firstPublishedBy: {
191
- type: mongoose2.Schema.Types.ObjectId,
192
- ref: "user"
193
- // reference to the 'user' model
194
- },
195
- kp_content_type: {
196
- type: String,
197
- required: true,
198
- unique: true
199
- },
200
- category: {
201
- //to deprecate and turn into 'layout'
202
- type: String,
203
- default: "knowledgeResources2"
204
- },
205
- kp_settings: [
206
- {
207
- type: Object
208
- }
209
- ],
210
- kp_templates: {
211
- type: Object
212
- },
213
- tplMeta: Object,
214
- tplLocales: Object,
215
- indexed: Object,
216
- drafts: {
217
- active: Object
218
- },
219
- rollbacks: Object,
220
- //for 'remembering' hidden configurations
221
- // OTHER CONFIGS
222
- listing: Object,
223
- //listing page configurations. this is new, currently only used in nct
224
- general: {
225
- content: {
226
- title: String,
227
- singular: String,
228
- ctaText: String,
229
- listingDesc: String
230
- },
231
- allowQuickTagCreation: { enable: Boolean },
232
- segment: String,
233
- settingsUIStyle: String,
234
- hasUpdateType: Boolean,
235
- annotation: {
236
- enable: Boolean
237
- },
238
- participantModule: {
239
- enable: Boolean
240
- },
241
- formFieldNumbering: {
242
- enable: Boolean
243
- },
244
- postPblRedirPath: Object,
245
- templateIndex: Object,
246
- sharing: {
247
- enable: Boolean,
248
- trackShareCount: {
249
- type: Boolean,
250
- default: false
251
- }
252
- },
253
- viewsCount: {
254
- enable: {
255
- type: Boolean,
256
- default: false
257
- }
258
- },
259
- comments: {
260
- enable: Boolean
261
- },
262
- reactions: {
263
- type: Map,
264
- of: {
265
- enable: Boolean,
266
- icon: String
267
- }
268
- },
269
- csvExport: {
270
- enable: Boolean,
271
- excludeFields: Array,
272
- enableUpdateExport: Boolean,
273
- fieldsToSortAtEnd: Array,
274
- fetchBatches: {
275
- enable: Boolean,
276
- batchSize: Number
277
- }
278
- },
279
- //tci helpers - these exist only to show / not show certain UIs in the tci
280
- disableKPSettings: Boolean
281
- }
282
- //general contenttype configs. mostly the stuff inside platformConfigs > contentTypes
283
- }, {
284
- toJSON: { virtuals: true },
285
- // So `res.json()` and other `JSON.stringify()` functions include virtuals
286
- toObject: { virtuals: true }
287
- // So `toObject()` output includes virtuals
288
- });
289
- TplSchema2.virtual("layout").get(function() {
290
- return this.category;
291
- });
292
- module.exports = TplSchema2;
293
- }
294
- });
295
-
296
1
  // src/utils/getterSetterDeleter/utils/set_deleteVal.ts
297
2
  var set_deleteVal = (action, data, valuePath, value) => {
298
3
  if (valuePath === void 0) return;
@@ -663,10 +368,317 @@ var getDbByTenant = ({
663
368
  throw new Error("getDbByTenant : mongodb object doesnt exist");
664
369
  };
665
370
 
371
+ // src/models/AIChat.ts
372
+ import mongoose3 from "mongoose";
373
+
374
+ // src/models/Annotations.ts
375
+ import { Schema } from "mongoose";
376
+ var AnnotationSchema = new Schema(
377
+ {
378
+ // Tags section - dynamic structure for various tag categories
379
+ tags: {
380
+ type: Map,
381
+ of: new Schema({
382
+ data: [
383
+ {
384
+ _id: { type: Schema.Types.ObjectId },
385
+ display: String,
386
+ tagId: String
387
+ }
388
+ ],
389
+ collectionId: String
390
+ }, {
391
+ _id: false
392
+ })
393
+ },
394
+ // Meta information
395
+ meta: {
396
+ contentType: { type: String, required: true },
397
+ kp_contributed_by: {
398
+ type: Schema.Types.ObjectId,
399
+ ref: "user"
400
+ },
401
+ valuePath: String,
402
+ documentId: {
403
+ type: Schema.Types.ObjectId
404
+ }
405
+ },
406
+ // Main content data - using Schema.Types.Mixed for dynamic structure
407
+ main: {
408
+ type: Schema.Types.Mixed,
409
+ default: {}
410
+ },
411
+ // Annotation specific details
412
+ annotations: {
413
+ tags: {
414
+ type: Map,
415
+ of: new Schema({
416
+ collectionId: String,
417
+ data: [
418
+ {
419
+ _id: { type: Schema.Types.ObjectId },
420
+ display: String,
421
+ tagId: String
422
+ }
423
+ ]
424
+ }, {
425
+ _id: false
426
+ })
427
+ },
428
+ fragment: {
429
+ isLexical: Boolean,
430
+ editorState: Object,
431
+ allText: String
432
+ },
433
+ annoKey: String,
434
+ author: {
435
+ id: { type: Schema.Types.ObjectId },
436
+ name: String
437
+ }
438
+ },
439
+ embeddings: Array,
440
+ contentEnhancedText: String,
441
+ // // Optional chunk related fields
442
+ // chunk: {
443
+ // embeddings: Schema.Types.Mixed,
444
+ // contentEnhancedText: String
445
+ // },
446
+ clusterId: String,
447
+ kp_date_published: Date,
448
+ createdAt: {
449
+ type: Date,
450
+ default: Date.now
451
+ },
452
+ updatedAt: {
453
+ type: Date,
454
+ default: Date.now
455
+ },
456
+ topicId: [{ type: Schema.Types.ObjectId, ref: "generatedTopics" }],
457
+ translations: Object
458
+ },
459
+ {
460
+ timestamps: true,
461
+ toJSON: { virtuals: true },
462
+ toObject: { virtuals: true },
463
+ strict: false
464
+ // This allows for flexible document structure beyond the defined schema
465
+ }
466
+ );
467
+ AnnotationSchema.index({ "meta.contentType": 1 });
468
+ AnnotationSchema.index({ "meta.documentId": 1 });
469
+ AnnotationSchema.index({ createdAt: -1 });
470
+ AnnotationSchema.index({ "annotations.annoKey": 1 });
471
+ AnnotationSchema.index({ "kp_date_published": -1 });
472
+ AnnotationSchema.pre("save", function(next) {
473
+ this.updatedAt = /* @__PURE__ */ new Date();
474
+ next();
475
+ });
476
+ AnnotationSchema.methods.getMainField = function(fieldPath) {
477
+ if (!fieldPath) return null;
478
+ const parts = fieldPath.split(".");
479
+ let value = this.main;
480
+ for (const part of parts) {
481
+ if (!value || typeof value !== "object") return null;
482
+ value = value[part];
483
+ }
484
+ return value;
485
+ };
486
+ AnnotationSchema.virtual("displayTitle").get(function() {
487
+ return this.main?.title || "Untitled Annotation";
488
+ });
489
+ var Annotations_default = AnnotationSchema;
490
+
491
+ // src/models/AIChat.ts
492
+ var AIChatSchema = new mongoose3.Schema(
493
+ {
494
+ userId: { type: mongoose3.Schema.Types.ObjectId, index: { unique: true } },
495
+ createdAt: Date,
496
+ lastAcitivity: Date,
497
+ messages: [
498
+ {
499
+ id: String,
500
+ author: {
501
+ type: String,
502
+ enum: ["system", "user", "assistant"]
503
+ },
504
+ content: {
505
+ type: { type: String },
506
+ value: String
507
+ },
508
+ vectorSearchInfo: {
509
+ chunks: [Annotations_default]
510
+ },
511
+ args: {
512
+ query: String,
513
+ reframedQuery: String,
514
+ summary: Object
515
+ },
516
+ userFeedback: {
517
+ reaction: { type: String, enum: ["positive", "negative"] },
518
+ comments: String
519
+ }
520
+ }
521
+ ]
522
+ },
523
+ { collection: "aiChat" }
524
+ );
525
+ var AIChat_default = AIChatSchema;
526
+
527
+ // src/models/PlatformConfigs.ts
528
+ import mongoose4 from "mongoose";
529
+ var platformConfigTypes = [
530
+ "roles",
531
+ "nav",
532
+ "deployment",
533
+ "userAgreement",
534
+ "localeData",
535
+ "theme",
536
+ "AI"
537
+ ];
538
+ var PlatformConfigsSchema = new mongoose4.Schema(
539
+ {
540
+ type: {
541
+ type: String,
542
+ enum: platformConfigTypes,
543
+ unique: true
544
+ },
545
+ roles: Array,
546
+ data: Object
547
+ },
548
+ { collection: "platformConfigs" }
549
+ );
550
+ var PlatformConfigs_default = PlatformConfigsSchema;
551
+
552
+ // src/models/Tpl.ts
553
+ import mongoose5 from "mongoose";
554
+ var TplSchema = new mongoose5.Schema({
555
+ dateFirstPublished: Date,
556
+ dateCreated: Date,
557
+ dateLastPublished: Date,
558
+ dateLastEdited: Date,
559
+ status: {
560
+ type: String,
561
+ default: "published",
562
+ // only cuz we dont want to go and add this property in all databases
563
+ enum: ["unpublished", "editPublished", "published"]
564
+ },
565
+ version: {
566
+ type: Number,
567
+ default: 0
568
+ },
569
+ versionPublishedBy: {
570
+ type: mongoose5.Schema.Types.ObjectId,
571
+ ref: "user"
572
+ // reference to the 'user' model
573
+ },
574
+ firstPublishedBy: {
575
+ type: mongoose5.Schema.Types.ObjectId,
576
+ ref: "user"
577
+ // reference to the 'user' model
578
+ },
579
+ kp_content_type: {
580
+ type: String,
581
+ required: true,
582
+ unique: true
583
+ },
584
+ category: {
585
+ //to deprecate and turn into 'layout'
586
+ type: String,
587
+ default: "knowledgeResources2"
588
+ },
589
+ kp_settings: [
590
+ {
591
+ type: Object
592
+ }
593
+ ],
594
+ kp_templates: {
595
+ type: Object
596
+ },
597
+ tplMeta: Object,
598
+ tplLocales: Object,
599
+ indexed: Object,
600
+ drafts: {
601
+ active: Object
602
+ },
603
+ rollbacks: Object,
604
+ //for 'remembering' hidden configurations
605
+ // OTHER CONFIGS
606
+ listing: Object,
607
+ //listing page configurations. this is new, currently only used in nct
608
+ general: {
609
+ content: {
610
+ title: String,
611
+ singular: String,
612
+ ctaText: String,
613
+ listingDesc: String
614
+ },
615
+ allowQuickTagCreation: { enable: Boolean },
616
+ segment: String,
617
+ settingsUIStyle: String,
618
+ hasUpdateType: Boolean,
619
+ annotation: {
620
+ enable: Boolean
621
+ },
622
+ participantModule: {
623
+ enable: Boolean
624
+ },
625
+ formFieldNumbering: {
626
+ enable: Boolean
627
+ },
628
+ postPblRedirPath: Object,
629
+ templateIndex: Object,
630
+ sharing: {
631
+ enable: Boolean,
632
+ trackShareCount: {
633
+ type: Boolean,
634
+ default: false
635
+ }
636
+ },
637
+ viewsCount: {
638
+ enable: {
639
+ type: Boolean,
640
+ default: false
641
+ }
642
+ },
643
+ comments: {
644
+ enable: Boolean
645
+ },
646
+ reactions: {
647
+ type: Map,
648
+ of: {
649
+ enable: Boolean,
650
+ icon: String
651
+ }
652
+ },
653
+ csvExport: {
654
+ enable: Boolean,
655
+ excludeFields: Array,
656
+ enableUpdateExport: Boolean,
657
+ fieldsToSortAtEnd: Array,
658
+ fetchBatches: {
659
+ enable: Boolean,
660
+ batchSize: Number
661
+ }
662
+ },
663
+ onboardingFlow: Object,
664
+ //only on profile tpls
665
+ selfServeSurveyConfig: Object,
666
+ //tci helpers - these exist only to show / not show certain UIs in the tci
667
+ disableKPSettings: Boolean
668
+ }
669
+ //general contenttype configs. mostly the stuff inside platformConfigs > contentTypes
670
+ }, {
671
+ toJSON: { virtuals: true },
672
+ // So `res.json()` and other `JSON.stringify()` functions include virtuals
673
+ toObject: { virtuals: true }
674
+ // So `toObject()` output includes virtuals
675
+ });
676
+ TplSchema.virtual("layout").get(function() {
677
+ return this.category;
678
+ });
679
+ var Tpl_default = TplSchema;
680
+
666
681
  // src/db/getModelByTenant.ts
667
- var AnnotationsSchema = require_Annotations();
668
- var PlatformConfigsSchema = require_PlatformConfigs();
669
- var TplSchema = require_Tpl();
670
682
  var getModelByTenant = ({
671
683
  tenant,
672
684
  modelName,
@@ -685,22 +697,28 @@ var getModelByTenant = ({
685
697
  }
686
698
  return db.model(modelName);
687
699
  };
688
- var getAnnotationsModelByTenant = ({ tenant, env, mongodb, dbConfigs }) => getModelByTenant({
700
+ var getAnnotationsModelByTenant = ({ tenant, env, mongodb, dbConfigs, modelName }) => getModelByTenant({
689
701
  tenant,
690
- modelName: "annotations",
691
- schema: AnnotationsSchema,
702
+ modelName: modelName || "annotations",
703
+ schema: Annotations_default,
692
704
  env
693
705
  });
694
706
  var getPlatformConfigsModelByTenant = ({ tenant, env, mongodb, dbConfigs }) => getModelByTenant({
695
707
  tenant,
696
708
  modelName: "platformConfigs",
697
- schema: PlatformConfigsSchema,
709
+ schema: PlatformConfigs_default,
698
710
  env
699
711
  });
700
712
  var getTplModelByTenant = ({ tenant, env, mongodb, dbConfigs }) => getModelByTenant({
701
713
  tenant,
702
714
  modelName: "tpl",
703
- schema: TplSchema,
715
+ schema: Tpl_default,
716
+ env
717
+ });
718
+ var getAIChatModelByTenant = ({ tenant, env, mongodb, dbConfigs }) => getModelByTenant({
719
+ tenant,
720
+ modelName: "aiChat",
721
+ schema: AIChat_default,
704
722
  env
705
723
  });
706
724
 
@@ -811,10 +829,15 @@ var getAIConfigs = async ({
811
829
  });
812
830
  };
813
831
  export {
832
+ AIChat_default as AIChatSchema,
833
+ Annotations_default as AnnotationSchema,
834
+ PlatformConfigs_default as PlatformConfigsSchema,
835
+ Tpl_default as TplSchema,
814
836
  connectToRedis,
815
837
  deleteVal,
816
838
  extractAllBlocksFromTpl,
817
839
  genTagId,
840
+ getAIChatModelByTenant,
818
841
  getAIConfigs,
819
842
  getAnnotationsModelByTenant,
820
843
  getDbByTenant,
@@ -826,6 +849,7 @@ export {
826
849
  getVal,
827
850
  initializeGlobalConfig,
828
851
  multiConnectToMongoDB,
852
+ _recursExtractBlocks as recursivelyExtractBlocks,
829
853
  setVal,
830
854
  toArray,
831
855
  updateGlobalConfig
@@ -124,5 +124,31 @@ declare const extractAllBlocksFromTpl: ({ tpl, buildersWhitelist }: {
124
124
  tpl: Template;
125
125
  buildersWhitelist?: BuilderType[];
126
126
  }) => ExtractedBlock[];
127
+ /**
128
+ * Recursively extracts blocks from a hierarchical data structure.
129
+ *
130
+ * This is the core traversal function that handles nested sections and blocks.
131
+ * It preserves two critical pieces of metadata:
132
+ *
133
+ * 1. **sectionStack**: Array of parent sections - Essential for display condition handling.
134
+ * When sections have display conditions, we need to know which blocks belong to
135
+ * hidden sections to exclude them from indexes and processing.
136
+ *
137
+ * 2. **blockPath**: Dot-notation path to the block's location - Required for precise updates.
138
+ * Used when modifying block properties or updating valuePaths in display conditions.
139
+ * See 'modifyValuesAndValuePaths' for detailed usage.
140
+ *
141
+ * @param {Object} params - Extraction parameters
142
+ * @param {Block[]} params.data - Array of blocks/sections to process
143
+ * @param {Function} params.cb - Callback function to handle each extracted block
144
+ * @param {Section[]} params.sectionStack - Current stack of parent sections
145
+ * @param {string} params.blockPathPrefix - Current path prefix for building blockPath
146
+ */
147
+ declare const _recursExtractBlocks: ({ data, cb, sectionStack, blockPathPrefix }: {
148
+ data: Block[];
149
+ cb: (block: ExtractedBlock) => void;
150
+ sectionStack?: Section[];
151
+ blockPathPrefix?: string;
152
+ }) => void;
127
153
 
128
- export { deleteVal, extractAllBlocksFromTpl, genTagId, getVal, setVal, toArray };
154
+ export { deleteVal, extractAllBlocksFromTpl, genTagId, getVal, _recursExtractBlocks as recursivelyExtractBlocks, setVal, toArray };