codebase-models 2.0.5 → 2.0.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.
Files changed (72) hide show
  1. package/dist/index.d.ts +3 -1
  2. package/dist/index.js +6 -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 -9
  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 +1 -0
  28. package/dist/src/models/CustomQuery.js +30 -1
  29. package/dist/src/models/Environment.d.ts +3 -0
  30. package/dist/src/models/Environment.js +38 -0
  31. package/dist/src/models/Goal.d.ts +1 -0
  32. package/dist/src/models/Goal.js +31 -2
  33. package/dist/src/models/Page.d.ts +2 -0
  34. package/dist/src/models/Page.js +48 -0
  35. package/dist/src/models/PageElement.js +0 -1
  36. package/dist/src/models/PageTestType.js +0 -2
  37. package/dist/src/models/Report.d.ts +1 -0
  38. package/dist/src/models/Report.js +30 -0
  39. package/dist/src/models/Role.js +0 -3
  40. package/dist/src/models/Snippet.js +0 -4
  41. package/dist/src/models/StageInCustomerJourney.d.ts +1 -0
  42. package/dist/src/models/StageInCustomerJourney.js +31 -4
  43. package/dist/src/models/Test.d.ts +3 -0
  44. package/dist/src/models/Test.js +47 -2
  45. package/dist/src/models/TestTimeline.d.ts +39 -0
  46. package/dist/src/models/TestTimeline.js +79 -0
  47. package/index.ts +4 -1
  48. package/package.json +3 -2
  49. package/src/constant.ts +17 -0
  50. package/src/models/Announcement.ts +22 -0
  51. package/src/models/Audience.ts +23 -0
  52. package/src/models/BqPreCompiledData.ts +22 -0
  53. package/src/models/Client.ts +22 -0
  54. package/src/models/ClientAdditionalRevenue.ts +42 -1
  55. package/src/models/ClientLearning.ts +22 -0
  56. package/src/models/ClientLinks.ts +23 -2
  57. package/src/models/ClientNextSteps.ts +20 -0
  58. package/src/models/ClientNote.ts +22 -1
  59. package/src/models/ClientScript.ts +56 -21
  60. package/src/models/ClientStrategy.ts +24 -0
  61. package/src/models/CustomQuery.ts +22 -2
  62. package/src/models/Environment.ts +33 -1
  63. package/src/models/Goal.ts +22 -3
  64. package/src/models/Page.ts +43 -0
  65. package/src/models/PageElement.ts +0 -1
  66. package/src/models/PageTestType.ts +0 -2
  67. package/src/models/Report.ts +22 -0
  68. package/src/models/Role.ts +1 -3
  69. package/src/models/Snippet.ts +1 -4
  70. package/src/models/StageInCustomerJourney.ts +22 -4
  71. package/src/models/Test.ts +42 -4
  72. package/src/models/TestTimeline.ts +61 -0
@@ -1,8 +1,10 @@
1
1
  import mongoose, { Document, Mongoose, Schema, model } from "mongoose";
2
2
  import slug from "mongoose-slug-updater"
3
+ import { generateRandomIID } from "../constant";
3
4
  mongoose.plugin(slug)
4
5
 
5
6
  export interface IStageInCustomerJourney extends Document {
7
+ iid: string;
6
8
  name?: string;
7
9
  stages?: string;
8
10
  slug?: string;
@@ -13,11 +15,14 @@ export interface IStageInCustomerJourney extends Document {
13
15
 
14
16
  const StageInCustomerJourneySchema = new Schema<IStageInCustomerJourney>(
15
17
  {
18
+ iid: {
19
+ type: String,
20
+ unique: true,
21
+ },
16
22
  name: {
17
23
  type: String,
18
24
  required: true,
19
25
  trim: true,
20
- index: true,
21
26
  },
22
27
  stages: {
23
28
  type: String,
@@ -35,17 +40,14 @@ const StageInCustomerJourneySchema = new Schema<IStageInCustomerJourney>(
35
40
  type: mongoose.Schema.Types.ObjectId,
36
41
  default: null,
37
42
  ref: "organization",
38
- index: true,
39
43
  },
40
44
  client: {
41
45
  type: mongoose.Schema.Types.ObjectId,
42
46
  ref: "client",
43
- index: true,
44
47
  },
45
48
  isActive: {
46
49
  type: Boolean,
47
50
  default: true,
48
- index: true,
49
51
  }
50
52
  },
51
53
  {
@@ -53,6 +55,22 @@ const StageInCustomerJourneySchema = new Schema<IStageInCustomerJourney>(
53
55
  }
54
56
  );
55
57
 
58
+ StageInCustomerJourneySchema.pre('save', async function(next) {
59
+ if (!this.iid) {
60
+ let unique = false;
61
+ while (!unique) {
62
+ const id = generateRandomIID();
63
+ const existing = await mongoose.models.stageincustomerjourney.findOne({ iid: id });
64
+ if (!existing) {
65
+ this.iid = id;
66
+ unique = true;
67
+ }
68
+ }
69
+ }
70
+ next();
71
+ });
72
+
73
+ StageInCustomerJourneySchema.index({ iid: 1 }, { unique: true });
56
74
  // Compound indexes for common query patterns
57
75
  // StageInCustomerJourneySchema.index({ client: 1, slug: 1 });
58
76
  const StageInCustomerJourney = mongoose.models.stageincustomerjourney || model<IStageInCustomerJourney>(
@@ -1,6 +1,8 @@
1
1
  import mongoose, { Document, Schema, model } from "mongoose";
2
+ import { generateRandomIID } from "../constant";
2
3
 
3
4
  export interface IVariations extends Document {
5
+ iid: string;
4
6
  name: string;
5
7
  css_code: string;
6
8
  baseline: boolean;
@@ -17,6 +19,7 @@ export interface IVariations extends Document {
17
19
  export interface ITest extends Document {
18
20
  // Core test properties
19
21
  organizationId?: mongoose.Schema.Types.ObjectId;
22
+ iid: string;
20
23
  status: string;
21
24
  name: string;
22
25
  traffic_allocation: number;
@@ -47,7 +50,6 @@ export interface ITest extends Document {
47
50
  hypothesis?: mongoose.Schema.Types.ObjectId;
48
51
  trigger?: mongoose.Schema.Types.ObjectId[];
49
52
  stageincustomerjourney?: mongoose.Schema.Types.ObjectId;
50
-
51
53
  // Test configuration
52
54
  property?: mongoose.Schema.Types.Mixed;
53
55
  platform: string;
@@ -63,6 +65,7 @@ export interface ITest extends Document {
63
65
  testid: string;
64
66
  testtool: string;
65
67
  personalization: boolean;
68
+ qaMode: boolean;
66
69
  kameleoontestdetails: mongoose.Schema.Types.Mixed;
67
70
  vwotestdetails: mongoose.Schema.Types.Mixed;
68
71
  triggerevents: any[];
@@ -76,6 +79,7 @@ export interface ITest extends Document {
76
79
  }
77
80
 
78
81
  const VariationsSchema = new Schema<IVariations>({
82
+ iid: { type: String, unique: true },
79
83
  name: { type: String, required: true },
80
84
  css_code: { type: String, default: "" },
81
85
  baseline: { type: Boolean, default: false },
@@ -91,6 +95,7 @@ const VariationsSchema = new Schema<IVariations>({
91
95
 
92
96
  const TestSchema = new Schema<ITest>(
93
97
  {
98
+ iid: { type: String, unique: true },
94
99
  organizationId: {
95
100
  type: mongoose.Schema.Types.ObjectId,
96
101
  ref: "organization",
@@ -99,7 +104,7 @@ const TestSchema = new Schema<ITest>(
99
104
  status: {
100
105
  type: String,
101
106
  default: "draft",
102
- enum: ["live", "draft", "ended", "paused", "preview", "running"]
107
+ enum: ["live", "draft", "ended", "paused", "preview", "running", "discard"]
103
108
  },
104
109
  name: { type: String, required: true },
105
110
  traffic_allocation: { type: Number, default: 100 },
@@ -160,7 +165,7 @@ const TestSchema = new Schema<ITest>(
160
165
  },
161
166
  hypothesis: {
162
167
  type: mongoose.Schema.Types.ObjectId,
163
- ref: "hypos"
168
+ ref: "hypos"
164
169
  },
165
170
  trigger: {
166
171
  type: [mongoose.Schema.Types.ObjectId],
@@ -169,7 +174,8 @@ const TestSchema = new Schema<ITest>(
169
174
  },
170
175
  stageincustomerjourney: {
171
176
  type: mongoose.Schema.Types.ObjectId,
172
- ref: "stageincustomerjourney"
177
+ ref: "stageincustomerjourney",
178
+ default: null
173
179
  },
174
180
 
175
181
  // Test configuration
@@ -187,6 +193,7 @@ const TestSchema = new Schema<ITest>(
187
193
  testid: { type: String, default: null },
188
194
  testtool: { type: String, default: "" },
189
195
  personalization: { type: Boolean, default: false },
196
+ qaMode: { type: Boolean, default: false },
190
197
  kameleoontestdetails: { type: mongoose.Schema.Types.Mixed, default: null },
191
198
  vwotestdetails: { type: mongoose.Schema.Types.Mixed, default: null },
192
199
  triggerevents: { type: [], default: [] },
@@ -202,6 +209,37 @@ const TestSchema = new Schema<ITest>(
202
209
  timestamps: true
203
210
  }
204
211
  );
212
+ TestSchema.pre('save', async function(next) {
213
+ if (!this.iid) {
214
+ let unique = false;
215
+ while (!unique) {
216
+ const id = generateRandomIID();
217
+ const existing = await mongoose.models.test.findOne({ iid: id });
218
+ if (!existing) {
219
+ this.iid = id;
220
+ unique = true;
221
+ }
222
+ }
223
+ }
224
+ // For each Variation inside Test
225
+ for (const variation of this.variations) {
226
+ if (!variation.iid) {
227
+ let uniqueVar = false;
228
+ while (!uniqueVar) {
229
+ const id = generateRandomIID();
230
+ const existingVar = await mongoose.models.test.findOne({ "variations.iid": id });
231
+ if (!existingVar) {
232
+ variation.iid = id;
233
+ uniqueVar = true;
234
+ }
235
+ }
236
+ }
237
+ }
238
+ next();
239
+ });
240
+
241
+
242
+ TestSchema.index({ iid: 1 }, { unique: true });
205
243
  // Add compound indexes for better query performance
206
244
  TestSchema.index({ client: 1, status: 1 });
207
245
  TestSchema.index({ client: 1, status: 1, livedate: 1 });
@@ -0,0 +1,61 @@
1
+ import mongoose, { Document, Schema, model } from "mongoose";
2
+ import { generateRandomIID } from "../constant";
3
+
4
+ export interface ITestTimeline extends Document {
5
+ iid: string;
6
+ organizationId?: mongoose.Schema.Types.ObjectId;
7
+ test: mongoose.Schema.Types.ObjectId;
8
+ event: string;
9
+ client: mongoose.Schema.Types.ObjectId;
10
+ user: mongoose.Schema.Types.ObjectId;
11
+ changes: {
12
+ type: mongoose.Schema.Types.Mixed,
13
+ default: {},
14
+ };
15
+ }
16
+ const TestTimelineSchema = new Schema<ITestTimeline>({
17
+ iid: {
18
+ type: String,
19
+ unique: true,
20
+ },
21
+ event: {
22
+ type: String,
23
+ enum: ["test_created", "test_updated","test_status_changed", "test_deleted", "variant_created", "variant_updated", "variant_deleted"],
24
+ },
25
+ organizationId: {
26
+ type: mongoose.Schema.Types.ObjectId,
27
+ ref: "organization",
28
+ default: null,
29
+ },
30
+ client: {
31
+ type: mongoose.Schema.Types.ObjectId,
32
+ ref: "client",
33
+ },
34
+ test: {
35
+ type: mongoose.Schema.Types.ObjectId,
36
+ ref: "test",
37
+ },
38
+ user: {
39
+ type: mongoose.Schema.Types.ObjectId,
40
+ ref: "user",
41
+ },
42
+ changes: {
43
+ type: mongoose.Schema.Types.Mixed,
44
+ default: {},
45
+ },
46
+ },
47
+ {
48
+ timestamps: true,
49
+ }
50
+ );
51
+ TestTimelineSchema.pre("save", async function (next) {
52
+ if (!this.iid) {
53
+ this.iid = generateRandomIID();
54
+ }
55
+ next();
56
+ });
57
+
58
+
59
+ const TestTimeline = mongoose.models.testTimeline || model<ITestTimeline>("testTimeline", TestTimelineSchema);
60
+
61
+ export default TestTimeline;