codebase-models 2.0.4 → 2.0.6

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.
Files changed (64) hide show
  1. package/dist/index.d.ts +4 -1
  2. package/dist/index.js +8 -1
  3. package/dist/src/constant.d.ts +7 -0
  4. package/dist/src/constant.js +17 -0
  5. package/dist/src/models/Announcement.d.ts +1 -0
  6. package/dist/src/models/Announcement.js +31 -0
  7. package/dist/src/models/Audience.d.ts +1 -0
  8. package/dist/src/models/Audience.js +31 -0
  9. package/dist/src/models/BqPreCompiledData.d.ts +1 -0
  10. package/dist/src/models/BqPreCompiledData.js +31 -0
  11. package/dist/src/models/Client.d.ts +1 -0
  12. package/dist/src/models/Client.js +31 -0
  13. package/dist/src/models/ClientAdditionalRevenue.d.ts +3 -1
  14. package/dist/src/models/ClientAdditionalRevenue.js +48 -0
  15. package/dist/src/models/ClientLearning.d.ts +1 -0
  16. package/dist/src/models/ClientLearning.js +31 -0
  17. package/dist/src/models/ClientLinks.d.ts +1 -0
  18. package/dist/src/models/ClientLinks.js +31 -0
  19. package/dist/src/models/ClientNextSteps.d.ts +1 -0
  20. package/dist/src/models/ClientNextSteps.js +30 -0
  21. package/dist/src/models/ClientNote.d.ts +1 -0
  22. package/dist/src/models/ClientNote.js +31 -0
  23. package/dist/src/models/ClientScript.d.ts +12 -11
  24. package/dist/src/models/ClientScript.js +54 -8
  25. package/dist/src/models/ClientStrategy.d.ts +1 -0
  26. package/dist/src/models/ClientStrategy.js +31 -0
  27. package/dist/src/models/CustomQuery.d.ts +38 -0
  28. package/dist/src/models/CustomQuery.js +68 -0
  29. package/dist/src/models/Environment.d.ts +2 -0
  30. package/dist/src/models/Environment.js +34 -0
  31. package/dist/src/models/Goal.d.ts +1 -0
  32. package/dist/src/models/Goal.js +31 -1
  33. package/dist/src/models/Page.d.ts +2 -0
  34. package/dist/src/models/Page.js +48 -0
  35. package/dist/src/models/Report.d.ts +1 -0
  36. package/dist/src/models/Report.js +30 -0
  37. package/dist/src/models/StageInCustomerJourney.d.ts +1 -0
  38. package/dist/src/models/StageInCustomerJourney.js +31 -0
  39. package/dist/src/models/Test.d.ts +2 -0
  40. package/dist/src/models/Test.js +46 -2
  41. package/dist/src/models/TestTimeline.d.ts +39 -0
  42. package/dist/src/models/TestTimeline.js +79 -0
  43. package/index.ts +6 -1
  44. package/package.json +3 -2
  45. package/src/constant.ts +17 -0
  46. package/src/models/Announcement.ts +22 -0
  47. package/src/models/Audience.ts +23 -0
  48. package/src/models/BqPreCompiledData.ts +22 -0
  49. package/src/models/Client.ts +22 -0
  50. package/src/models/ClientAdditionalRevenue.ts +42 -1
  51. package/src/models/ClientLearning.ts +22 -0
  52. package/src/models/ClientLinks.ts +23 -2
  53. package/src/models/ClientNextSteps.ts +20 -0
  54. package/src/models/ClientNote.ts +22 -1
  55. package/src/models/ClientScript.ts +56 -20
  56. package/src/models/ClientStrategy.ts +24 -0
  57. package/src/models/CustomQuery.ts +49 -0
  58. package/src/models/Environment.ts +27 -0
  59. package/src/models/Goal.ts +22 -2
  60. package/src/models/Page.ts +43 -0
  61. package/src/models/Report.ts +22 -0
  62. package/src/models/StageInCustomerJourney.ts +22 -0
  63. package/src/models/Test.ts +40 -3
  64. package/src/models/TestTimeline.ts +61 -0
@@ -23,26 +23,24 @@
23
23
  /// <reference types="mongoose/types/virtuals" />
24
24
  /// <reference types="mongoose/types/inferschematype" />
25
25
  import mongoose, { Document } from "mongoose";
26
- export interface IClientScriptSchema extends Document {
27
- scriptUrl: string;
28
- viewId: string;
29
- }
30
26
  export interface IClientScript extends Document {
27
+ iid: string;
31
28
  organizationId?: mongoose.Schema.Types.ObjectId;
32
29
  client?: mongoose.Schema.Types.ObjectId;
30
+ adhere_dnt: Boolean;
31
+ allow_in_iframes: Boolean;
33
32
  viewId?: string;
34
33
  clientScriptURL: string;
35
34
  jquery_include: string;
36
35
  debug: Boolean;
37
36
  restrict_debug: Boolean;
38
- adhere_dnt: Boolean;
39
37
  max_cookie_lifetime: Number;
40
38
  activation_mode: string;
41
39
  use_antiflicker: Boolean;
42
40
  snippet_revision: Number;
41
+ snippet_version: Number;
43
42
  rules: string;
44
43
  rules_tracking: string;
45
- tracker_url: string;
46
44
  asset_url: string;
47
45
  metadata_key_exp_1: mongoose.Schema.Types.Mixed;
48
46
  metadata_key_exp_2: mongoose.Schema.Types.Mixed;
@@ -50,15 +48,18 @@ export interface IClientScript extends Document {
50
48
  metadata_key_var_1: mongoose.Schema.Types.Mixed;
51
49
  metadata_key_var_2: mongoose.Schema.Types.Mixed;
52
50
  metadata_key_var_3: mongoose.Schema.Types.Mixed;
53
- cookie_domain: string;
54
- snippet_version: Number;
51
+ logDomain: string;
55
52
  storage: string;
56
53
  run_only_on_reinit: Boolean;
57
- allow_in_iframes: Boolean;
58
54
  visual_editor_version: Number;
59
- jscode: string;
60
- csscode: string;
55
+ js: string;
56
+ css: string;
57
+ helper_js: string;
61
58
  is_spa: Boolean;
59
+ isPreview: Boolean;
60
+ goalsEnabled: Boolean;
61
+ optedOut: Boolean;
62
+ liveEventListenersSet: Boolean;
62
63
  }
63
64
  declare const ClientScript: mongoose.Model<any, {}, {}, {}, any, any>;
64
65
  export default ClientScript;
@@ -22,9 +22,23 @@ var __importStar = (this && this.__importStar) || function (mod) {
22
22
  __setModuleDefault(result, mod);
23
23
  return result;
24
24
  };
25
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
26
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
27
+ return new (P || (P = Promise))(function (resolve, reject) {
28
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
29
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
30
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
31
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
32
+ });
33
+ };
25
34
  Object.defineProperty(exports, "__esModule", { value: true });
26
35
  const mongoose_1 = __importStar(require("mongoose"));
36
+ const constant_1 = require("../constant");
27
37
  const ClientScriptSchema = new mongoose_1.Schema({
38
+ iid: {
39
+ type: String,
40
+ trim: true,
41
+ },
28
42
  organizationId: {
29
43
  type: mongoose_1.default.Schema.Types.ObjectId,
30
44
  ref: "organization",
@@ -84,10 +98,6 @@ const ClientScriptSchema = new mongoose_1.Schema({
84
98
  default: "return true;",
85
99
  trim: true,
86
100
  },
87
- tracker_url: {
88
- type: String,
89
- trim: true,
90
- },
91
101
  asset_url: {
92
102
  type: String,
93
103
  trim: true,
@@ -110,7 +120,7 @@ const ClientScriptSchema = new mongoose_1.Schema({
110
120
  metadata_key_var_3: {
111
121
  type: mongoose_1.default.Schema.Types.Mixed,
112
122
  },
113
- cookie_domain: {
123
+ logDomain: {
114
124
  type: String,
115
125
  trim: true,
116
126
  },
@@ -133,11 +143,15 @@ const ClientScriptSchema = new mongoose_1.Schema({
133
143
  visual_editor_version: {
134
144
  type: Number,
135
145
  },
136
- jscode: {
146
+ js: {
147
+ type: String,
148
+ trim: true,
149
+ },
150
+ css: {
137
151
  type: String,
138
152
  trim: true,
139
153
  },
140
- csscode: {
154
+ helper_js: {
141
155
  type: String,
142
156
  trim: true,
143
157
  },
@@ -145,14 +159,46 @@ const ClientScriptSchema = new mongoose_1.Schema({
145
159
  type: Boolean,
146
160
  default: false,
147
161
  },
162
+ isPreview: {
163
+ type: Boolean,
164
+ default: false,
165
+ },
166
+ goalsEnabled: {
167
+ type: Boolean,
168
+ default: false,
169
+ },
170
+ optedOut: {
171
+ type: Boolean,
172
+ default: false,
173
+ },
174
+ liveEventListenersSet: {
175
+ type: Boolean,
176
+ default: false,
177
+ },
148
178
  }, {
149
179
  timestamps: true,
150
180
  });
181
+ ClientScriptSchema.pre('save', function (next) {
182
+ return __awaiter(this, void 0, void 0, function* () {
183
+ if (!this.iid) {
184
+ let unique = false;
185
+ while (!unique) {
186
+ const id = (0, constant_1.generateRandomIID)();
187
+ const existing = yield mongoose_1.default.models.clientscript.findOne({ iid: id });
188
+ if (!existing) {
189
+ this.iid = id;
190
+ unique = true;
191
+ }
192
+ }
193
+ }
194
+ next();
195
+ });
196
+ });
197
+ ClientScriptSchema.index({ iid: 1 }, { unique: true });
151
198
  // Compound indexes for common query patterns
152
199
  ClientScriptSchema.index({ client: 1 });
153
200
  // Sparse indexes for optional fields
154
201
  ClientScriptSchema.index({ organisationId: 1 }, { sparse: true });
155
- ClientScriptSchema.index({ tracker_url: 1 }, { sparse: true });
156
202
  ClientScriptSchema.index({ asset_url: 1 }, { sparse: true });
157
203
  const ClientScript = mongoose_1.default.models.clientscript || (0, mongoose_1.model)("clientscript", ClientScriptSchema);
158
204
  exports.default = ClientScript;
@@ -24,6 +24,7 @@
24
24
  /// <reference types="mongoose/types/inferschematype" />
25
25
  import mongoose, { Document } from "mongoose";
26
26
  export interface IClientStrategy extends Document {
27
+ iid: string;
27
28
  year: mongoose.Schema.Types.Mixed;
28
29
  month: mongoose.Schema.Types.Mixed;
29
30
  startDate?: Date;
@@ -22,9 +22,23 @@ var __importStar = (this && this.__importStar) || function (mod) {
22
22
  __setModuleDefault(result, mod);
23
23
  return result;
24
24
  };
25
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
26
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
27
+ return new (P || (P = Promise))(function (resolve, reject) {
28
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
29
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
30
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
31
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
32
+ });
33
+ };
25
34
  Object.defineProperty(exports, "__esModule", { value: true });
26
35
  const mongoose_1 = __importStar(require("mongoose"));
36
+ const constant_1 = require("../constant");
27
37
  const ClientStrategySchema = new mongoose_1.Schema({
38
+ iid: {
39
+ type: String,
40
+ trim: true,
41
+ },
28
42
  year: {
29
43
  type: mongoose_1.default.Schema.Types.Mixed,
30
44
  required: true,
@@ -64,6 +78,23 @@ const ClientStrategySchema = new mongoose_1.Schema({
64
78
  }, {
65
79
  timestamps: true,
66
80
  });
81
+ ClientStrategySchema.pre('save', function (next) {
82
+ return __awaiter(this, void 0, void 0, function* () {
83
+ if (!this.iid) {
84
+ let unique = false;
85
+ while (!unique) {
86
+ const id = (0, constant_1.generateRandomIID)();
87
+ const existing = yield mongoose_1.default.models.clientstrategy.findOne({ iid: id });
88
+ if (!existing) {
89
+ this.iid = id;
90
+ unique = true;
91
+ }
92
+ }
93
+ }
94
+ next();
95
+ });
96
+ });
97
+ ClientStrategySchema.index({ iid: 1 }, { unique: true });
67
98
  ClientStrategySchema.index({
68
99
  year: 1,
69
100
  month: 1,
@@ -0,0 +1,38 @@
1
+ /// <reference types="mongoose/types/aggregate" />
2
+ /// <reference types="mongoose/types/callback" />
3
+ /// <reference types="mongoose/types/collection" />
4
+ /// <reference types="mongoose/types/connection" />
5
+ /// <reference types="mongoose/types/cursor" />
6
+ /// <reference types="mongoose/types/document" />
7
+ /// <reference types="mongoose/types/error" />
8
+ /// <reference types="mongoose/types/expressions" />
9
+ /// <reference types="mongoose/types/helpers" />
10
+ /// <reference types="mongoose/types/middlewares" />
11
+ /// <reference types="mongoose/types/indexes" />
12
+ /// <reference types="mongoose/types/models" />
13
+ /// <reference types="mongoose/types/mongooseoptions" />
14
+ /// <reference types="mongoose/types/pipelinestage" />
15
+ /// <reference types="mongoose/types/populate" />
16
+ /// <reference types="mongoose/types/query" />
17
+ /// <reference types="mongoose/types/schemaoptions" />
18
+ /// <reference types="mongoose/types/schematypes" />
19
+ /// <reference types="mongoose/types/session" />
20
+ /// <reference types="mongoose/types/types" />
21
+ /// <reference types="mongoose/types/utility" />
22
+ /// <reference types="mongoose/types/validation" />
23
+ /// <reference types="mongoose/types/virtuals" />
24
+ /// <reference types="mongoose/types/inferschematype" />
25
+ import mongoose, { Document } from 'mongoose';
26
+ interface ICustomQuery extends Document {
27
+ iid: string;
28
+ organizationId?: mongoose.Schema.Types.ObjectId;
29
+ title: string;
30
+ module: string;
31
+ client: mongoose.Schema.Types.ObjectId;
32
+ query: string;
33
+ createdBy?: mongoose.Schema.Types.ObjectId;
34
+ }
35
+ declare const CustomQuery: mongoose.Model<ICustomQuery, {}, {}, {}, mongoose.Document<unknown, {}, ICustomQuery> & ICustomQuery & {
36
+ _id: mongoose.Types.ObjectId;
37
+ }, any>;
38
+ export default CustomQuery;
@@ -0,0 +1,68 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
15
+ }) : function(o, v) {
16
+ o["default"] = v;
17
+ });
18
+ var __importStar = (this && this.__importStar) || function (mod) {
19
+ if (mod && mod.__esModule) return mod;
20
+ var result = {};
21
+ if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
22
+ __setModuleDefault(result, mod);
23
+ return result;
24
+ };
25
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
26
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
27
+ return new (P || (P = Promise))(function (resolve, reject) {
28
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
29
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
30
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
31
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
32
+ });
33
+ };
34
+ Object.defineProperty(exports, "__esModule", { value: true });
35
+ const mongoose_1 = __importStar(require("mongoose"));
36
+ const constant_1 = require("../constant");
37
+ const CustomQuerySchema = new mongoose_1.Schema({
38
+ iid: {
39
+ type: String,
40
+ trim: true,
41
+ },
42
+ organizationId: { type: mongoose_1.default.Schema.Types.ObjectId, ref: "organization", default: null },
43
+ title: { type: String, required: true },
44
+ module: { type: String, required: true },
45
+ client: { type: mongoose_1.default.Schema.Types.ObjectId, ref: 'client', required: true },
46
+ query: { type: String, required: true },
47
+ createdBy: { type: mongoose_1.default.Schema.Types.ObjectId, ref: 'user', default: null },
48
+ }, {
49
+ timestamps: true, // Automatically adds createdAt and updatedAt fields
50
+ });
51
+ CustomQuerySchema.pre('save', function (next) {
52
+ return __awaiter(this, void 0, void 0, function* () {
53
+ if (!this.iid) {
54
+ let unique = false;
55
+ while (!unique) {
56
+ const id = (0, constant_1.generateRandomIID)();
57
+ const existing = yield mongoose_1.default.models.customquery.findOne({ iid: id });
58
+ if (!existing) {
59
+ this.iid = id;
60
+ unique = true;
61
+ }
62
+ }
63
+ }
64
+ next();
65
+ });
66
+ });
67
+ const CustomQuery = (0, mongoose_1.model)('CustomQuery', CustomQuerySchema);
68
+ exports.default = CustomQuery;
@@ -24,11 +24,13 @@
24
24
  /// <reference types="mongoose/types/inferschematype" />
25
25
  import mongoose, { Document } from "mongoose";
26
26
  export interface IEnvironment extends Document {
27
+ iid: string;
27
28
  name: string;
28
29
  rules_js?: string;
29
30
  client?: mongoose.Schema.Types.ObjectId;
30
31
  organizationId?: mongoose.Schema.Types.ObjectId;
31
32
  isActive?: boolean;
33
+ default?: boolean;
32
34
  }
33
35
  declare const Environment: mongoose.Model<any, {}, {}, {}, any, any>;
34
36
  export default Environment;
@@ -22,9 +22,23 @@ var __importStar = (this && this.__importStar) || function (mod) {
22
22
  __setModuleDefault(result, mod);
23
23
  return result;
24
24
  };
25
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
26
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
27
+ return new (P || (P = Promise))(function (resolve, reject) {
28
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
29
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
30
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
31
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
32
+ });
33
+ };
25
34
  Object.defineProperty(exports, "__esModule", { value: true });
26
35
  const mongoose_1 = __importStar(require("mongoose"));
36
+ const constant_1 = require("../constant");
27
37
  const EnvironmentSchema = new mongoose_1.Schema({
38
+ iid: {
39
+ type: String,
40
+ trim: true,
41
+ },
28
42
  name: {
29
43
  type: String,
30
44
  required: true,
@@ -40,6 +54,10 @@ const EnvironmentSchema = new mongoose_1.Schema({
40
54
  type: mongoose_1.default.Schema.Types.ObjectId,
41
55
  ref: "organization",
42
56
  },
57
+ default: {
58
+ type: Boolean,
59
+ default: false,
60
+ },
43
61
  rules_js: {
44
62
  type: String,
45
63
  default: "return true",
@@ -52,6 +70,22 @@ const EnvironmentSchema = new mongoose_1.Schema({
52
70
  }, {
53
71
  timestamps: true
54
72
  });
73
+ EnvironmentSchema.pre('save', function (next) {
74
+ return __awaiter(this, void 0, void 0, function* () {
75
+ if (!this.iid) {
76
+ let unique = false;
77
+ while (!unique) {
78
+ const id = (0, constant_1.generateRandomIID)();
79
+ const existing = yield mongoose_1.default.models.environment.findOne({ iid: id });
80
+ if (!existing) {
81
+ this.iid = id;
82
+ unique = true;
83
+ }
84
+ }
85
+ }
86
+ next();
87
+ });
88
+ });
55
89
  // Compound indexes for common query patterns
56
90
  EnvironmentSchema.index({ client: 1, name: 1 }, { unique: true });
57
91
  EnvironmentSchema.index({ client: 1, isActive: 1 });
@@ -24,6 +24,7 @@
24
24
  /// <reference types="mongoose/types/inferschematype" />
25
25
  import mongoose, { Document } from "mongoose";
26
26
  export interface IGoal extends Document {
27
+ iid: string;
27
28
  name: string;
28
29
  details?: string;
29
30
  slug?: string;
@@ -22,14 +22,28 @@ var __importStar = (this && this.__importStar) || function (mod) {
22
22
  __setModuleDefault(result, mod);
23
23
  return result;
24
24
  };
25
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
26
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
27
+ return new (P || (P = Promise))(function (resolve, reject) {
28
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
29
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
30
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
31
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
32
+ });
33
+ };
25
34
  var __importDefault = (this && this.__importDefault) || function (mod) {
26
35
  return (mod && mod.__esModule) ? mod : { "default": mod };
27
36
  };
28
37
  Object.defineProperty(exports, "__esModule", { value: true });
29
38
  const mongoose_1 = __importStar(require("mongoose"));
30
39
  const mongoose_slug_updater_1 = __importDefault(require("mongoose-slug-updater"));
40
+ const constant_1 = require("../constant");
31
41
  mongoose_1.default.plugin(mongoose_slug_updater_1.default);
32
42
  const GoalSchema = new mongoose_1.Schema({
43
+ iid: {
44
+ type: String,
45
+ trim: true,
46
+ },
33
47
  name: {
34
48
  type: String,
35
49
  required: true,
@@ -85,10 +99,26 @@ const GoalSchema = new mongoose_1.Schema({
85
99
  }, {
86
100
  timestamps: true
87
101
  });
88
- // Compound indexes for common query patterns
102
+ GoalSchema.pre('save', function (next) {
103
+ return __awaiter(this, void 0, void 0, function* () {
104
+ if (!this.iid) {
105
+ let unique = false;
106
+ while (!unique) {
107
+ const id = (0, constant_1.generateRandomIID)();
108
+ const existing = yield mongoose_1.default.models.goal.findOne({ iid: id });
109
+ if (!existing) {
110
+ this.iid = id;
111
+ unique = true;
112
+ }
113
+ }
114
+ }
115
+ next();
116
+ });
117
+ });
89
118
  GoalSchema.index({ client: 1 });
90
119
  GoalSchema.index({ client: 1, isActive: 1 });
91
120
  GoalSchema.index({ organizationId: 1, client: 1 });
92
121
  GoalSchema.index({ client: 1, name: 1 }, { unique: true });
122
+ GoalSchema.index({ iid: 1 }, { unique: true });
93
123
  const Goal = mongoose_1.default.models.goal || (0, mongoose_1.model)("goal", GoalSchema);
94
124
  exports.default = Goal;
@@ -24,11 +24,13 @@
24
24
  /// <reference types="mongoose/types/inferschematype" />
25
25
  import mongoose, { Document } from "mongoose";
26
26
  export interface IUrltargetings extends Document {
27
+ iid: string;
27
28
  type: string;
28
29
  url: string;
29
30
  url_type: string;
30
31
  }
31
32
  export interface IPage extends Document {
33
+ iid: string;
32
34
  name: string;
33
35
  client?: mongoose.Schema.Types.ObjectId;
34
36
  organizationId?: mongoose.Schema.Types.ObjectId;
@@ -22,14 +22,28 @@ var __importStar = (this && this.__importStar) || function (mod) {
22
22
  __setModuleDefault(result, mod);
23
23
  return result;
24
24
  };
25
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
26
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
27
+ return new (P || (P = Promise))(function (resolve, reject) {
28
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
29
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
30
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
31
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
32
+ });
33
+ };
25
34
  var __importDefault = (this && this.__importDefault) || function (mod) {
26
35
  return (mod && mod.__esModule) ? mod : { "default": mod };
27
36
  };
28
37
  Object.defineProperty(exports, "__esModule", { value: true });
29
38
  const mongoose_1 = __importStar(require("mongoose"));
30
39
  const mongoose_slug_updater_1 = __importDefault(require("mongoose-slug-updater"));
40
+ const constant_1 = require("../constant");
31
41
  mongoose_1.default.plugin(mongoose_slug_updater_1.default);
32
42
  const UrltargetingsSchema = new mongoose_1.Schema({
43
+ iid: {
44
+ type: String,
45
+ unique: true,
46
+ },
33
47
  type: {
34
48
  type: String,
35
49
  required: true,
@@ -47,6 +61,10 @@ const UrltargetingsSchema = new mongoose_1.Schema({
47
61
  },
48
62
  });
49
63
  const PageSchema = new mongoose_1.Schema({
64
+ iid: {
65
+ type: String,
66
+ unique: true,
67
+ },
50
68
  name: {
51
69
  type: String,
52
70
  required: true,
@@ -100,6 +118,36 @@ const PageSchema = new mongoose_1.Schema({
100
118
  }, {
101
119
  timestamps: true
102
120
  });
121
+ PageSchema.pre('save', function (next) {
122
+ return __awaiter(this, void 0, void 0, function* () {
123
+ if (!this.iid) {
124
+ let unique = false;
125
+ while (!unique) {
126
+ const id = (0, constant_1.generateRandomIID)();
127
+ const existing = yield mongoose_1.default.models.page.findOne({ iid: id });
128
+ if (!existing) {
129
+ this.iid = id;
130
+ unique = true;
131
+ }
132
+ }
133
+ }
134
+ for (const urltargeting of this.urltargetings) {
135
+ if (!urltargeting.iid) {
136
+ let uniqueVar = false;
137
+ while (!uniqueVar) {
138
+ const id = (0, constant_1.generateRandomIID)();
139
+ const existingVar = yield mongoose_1.default.models.page.findOne({ "urltargetings.iid": id });
140
+ if (!existingVar) {
141
+ urltargeting.iid = id;
142
+ uniqueVar = true;
143
+ }
144
+ }
145
+ }
146
+ }
147
+ next();
148
+ });
149
+ });
150
+ PageSchema.index({ iid: 1 }, { unique: true });
103
151
  // Compound indexes for common query patterns
104
152
  PageSchema.index({ client: 1, name: 1 }, { unique: true });
105
153
  PageSchema.index({ client: 1, isActive: 1 });
@@ -24,6 +24,7 @@
24
24
  /// <reference types="mongoose/types/inferschematype" />
25
25
  import mongoose, { Document } from "mongoose";
26
26
  export interface IReports extends Document {
27
+ iid: string;
27
28
  name: string;
28
29
  segmentName?: string;
29
30
  reportLink?: string;
@@ -22,9 +22,23 @@ var __importStar = (this && this.__importStar) || function (mod) {
22
22
  __setModuleDefault(result, mod);
23
23
  return result;
24
24
  };
25
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
26
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
27
+ return new (P || (P = Promise))(function (resolve, reject) {
28
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
29
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
30
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
31
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
32
+ });
33
+ };
25
34
  Object.defineProperty(exports, "__esModule", { value: true });
26
35
  const mongoose_1 = __importStar(require("mongoose"));
36
+ const constant_1 = require("../constant");
27
37
  const ReportsSchema = new mongoose_1.Schema({
38
+ iid: {
39
+ type: String,
40
+ trim: true,
41
+ },
28
42
  organizationId: {
29
43
  type: mongoose_1.default.Schema.Types.ObjectId,
30
44
  ref: "organization",
@@ -63,6 +77,22 @@ const ReportsSchema = new mongoose_1.Schema({
63
77
  }, {
64
78
  timestamps: true
65
79
  });
80
+ ReportsSchema.pre('save', function (next) {
81
+ return __awaiter(this, void 0, void 0, function* () {
82
+ if (!this.iid) {
83
+ let unique = false;
84
+ while (!unique) {
85
+ const id = (0, constant_1.generateRandomIID)();
86
+ const existing = yield mongoose_1.default.models.report.findOne({ iid: id });
87
+ if (!existing) {
88
+ this.iid = id;
89
+ unique = true;
90
+ }
91
+ }
92
+ }
93
+ next();
94
+ });
95
+ });
66
96
  // Add compound indexes for better query performance
67
97
  ReportsSchema.index({ client: 1, conclusion: 1 });
68
98
  ReportsSchema.index({ test: 1, to: -1 }); // For sorting reports by date
@@ -24,6 +24,7 @@
24
24
  /// <reference types="mongoose/types/inferschematype" />
25
25
  import mongoose, { Document } from "mongoose";
26
26
  export interface IStageInCustomerJourney extends Document {
27
+ iid: string;
27
28
  name?: string;
28
29
  stages?: string;
29
30
  slug?: string;
@@ -22,14 +22,28 @@ var __importStar = (this && this.__importStar) || function (mod) {
22
22
  __setModuleDefault(result, mod);
23
23
  return result;
24
24
  };
25
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
26
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
27
+ return new (P || (P = Promise))(function (resolve, reject) {
28
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
29
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
30
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
31
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
32
+ });
33
+ };
25
34
  var __importDefault = (this && this.__importDefault) || function (mod) {
26
35
  return (mod && mod.__esModule) ? mod : { "default": mod };
27
36
  };
28
37
  Object.defineProperty(exports, "__esModule", { value: true });
29
38
  const mongoose_1 = __importStar(require("mongoose"));
30
39
  const mongoose_slug_updater_1 = __importDefault(require("mongoose-slug-updater"));
40
+ const constant_1 = require("../constant");
31
41
  mongoose_1.default.plugin(mongoose_slug_updater_1.default);
32
42
  const StageInCustomerJourneySchema = new mongoose_1.Schema({
43
+ iid: {
44
+ type: String,
45
+ unique: true,
46
+ },
33
47
  name: {
34
48
  type: String,
35
49
  required: true,
@@ -67,6 +81,23 @@ const StageInCustomerJourneySchema = new mongoose_1.Schema({
67
81
  }, {
68
82
  timestamps: true,
69
83
  });
84
+ StageInCustomerJourneySchema.pre('save', function (next) {
85
+ return __awaiter(this, void 0, void 0, function* () {
86
+ if (!this.iid) {
87
+ let unique = false;
88
+ while (!unique) {
89
+ const id = (0, constant_1.generateRandomIID)();
90
+ const existing = yield mongoose_1.default.models.stageincustomerjourney.findOne({ iid: id });
91
+ if (!existing) {
92
+ this.iid = id;
93
+ unique = true;
94
+ }
95
+ }
96
+ }
97
+ next();
98
+ });
99
+ });
100
+ StageInCustomerJourneySchema.index({ iid: 1 }, { unique: true });
70
101
  // Compound indexes for common query patterns
71
102
  // StageInCustomerJourneySchema.index({ client: 1, slug: 1 });
72
103
  const StageInCustomerJourney = mongoose_1.default.models.stageincustomerjourney || (0, mongoose_1.model)("stageincustomerjourney", StageInCustomerJourneySchema);