@timardex/cluemart-server-shared 2.3.0 → 2.5.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.
@@ -7,7 +7,8 @@ import {
7
7
  EnumAdStatus,
8
8
  EnumAdStyle,
9
9
  EnumAdType,
10
- EnumResourceType
10
+ EnumResourceType,
11
+ isUtcMidnight
11
12
  } from "@timardex/cluemart-shared";
12
13
  import mongoose from "mongoose";
13
14
  var MongooseSchema = mongoose.Schema;
@@ -40,7 +41,6 @@ var schemaAdresource = new MongooseSchema({
40
41
  var schema = new MongooseSchema(
41
42
  {
42
43
  active: { default: true, type: Boolean },
43
- adminManaged: { default: false, type: Boolean },
44
44
  approvalStatus: {
45
45
  enum: Object.values(EnumAdApprovalStatus),
46
46
  required: false,
@@ -56,9 +56,14 @@ var schema = new MongooseSchema(
56
56
  required: false,
57
57
  type: String
58
58
  },
59
- clicks: { default: 0, required: true, type: Number },
60
- end: { required: true, type: Date },
61
- impressions: { default: 0, required: true, type: Number },
59
+ end: {
60
+ required: true,
61
+ type: Date,
62
+ validate: {
63
+ message: "end must be a UTC-midnight day key.",
64
+ validator: isUtcMidnight
65
+ }
66
+ },
62
67
  paymentStatus: {
63
68
  enum: Object.values(EnumAdPaymentStatus),
64
69
  required: false,
@@ -71,7 +76,14 @@ var schema = new MongooseSchema(
71
76
  required: true,
72
77
  type: [String]
73
78
  },
74
- start: { required: true, type: Date },
79
+ start: {
80
+ required: true,
81
+ type: Date,
82
+ validate: {
83
+ message: "start must be a UTC-midnight day key.",
84
+ validator: isUtcMidnight
85
+ }
86
+ },
75
87
  status: {
76
88
  default: EnumAdStatus.ACTIVE,
77
89
  enum: Object.values(EnumAdStatus),
@@ -105,6 +117,7 @@ schema.index(
105
117
  var AdModel = mongoose.models.Ad || mongoose.model("Ad", schema);
106
118
 
107
119
  // src/mongoose/ad/AdBillingCatalog.ts
120
+ import { EnumAdShowOn as EnumAdShowOn2 } from "@timardex/cluemart-shared";
108
121
  import mongoose2 from "mongoose";
109
122
  var AD_BILLING_CATALOG_COLLECTION_NAME = "adBillingCatalog";
110
123
  var schema2 = new mongoose2.Schema(
@@ -118,7 +131,7 @@ var schema2 = new mongoose2.Schema(
118
131
  type: String
119
132
  },
120
133
  key: {
121
- enum: ["front_page_day", "market_search_day"],
134
+ enum: Object.values(EnumAdShowOn2),
122
135
  immutable: true,
123
136
  required: true,
124
137
  type: String,
@@ -148,8 +161,8 @@ import {
148
161
  EnumAdApprovalStatus as EnumAdApprovalStatus2,
149
162
  EnumAdBookingSlotKind as EnumAdBookingSlotKind2,
150
163
  EnumAdBookingState,
151
- EnumAdEntitlementSource,
152
- EnumAdShowOn as EnumAdShowOn2
164
+ EnumAdShowOn as EnumAdShowOn3,
165
+ isUtcMidnight as isUtcMidnight2
153
166
  } from "@timardex/cluemart-shared";
154
167
  import mongoose3 from "mongoose";
155
168
  var liveStates = [
@@ -157,7 +170,6 @@ var liveStates = [
157
170
  EnumAdBookingState.PENDING_APPROVAL,
158
171
  EnumAdBookingState.APPROVED
159
172
  ];
160
- var placementValues = [EnumAdShowOn2.FRONT_PAGE, EnumAdShowOn2.MARKET_SEARCH];
161
173
  var schema3 = new mongoose3.Schema(
162
174
  {
163
175
  adId: { default: null, ref: "Ad", type: String },
@@ -171,19 +183,16 @@ var schema3 = new mongoose3.Schema(
171
183
  currency: { default: null, lowercase: true, type: String },
172
184
  dayKey: {
173
185
  immutable: true,
174
- match: /^\d{4}-\d{2}-\d{2}$/,
175
186
  required: true,
176
- type: String
177
- },
178
- entitlementClaimKey: { default: null, type: String },
179
- entitlementSource: {
180
- default: null,
181
- enum: Object.values(EnumAdEntitlementSource),
182
- type: String
187
+ type: Date,
188
+ validate: {
189
+ message: "dayKey must be a UTC-midnight day key.",
190
+ validator: isUtcMidnight2
191
+ }
183
192
  },
184
193
  expiresAt: { default: null, type: Date },
185
194
  placement: {
186
- enum: placementValues,
195
+ enum: Object.values(EnumAdShowOn3),
187
196
  immutable: true,
188
197
  required: true,
189
198
  type: String
@@ -198,6 +207,7 @@ var schema3 = new mongoose3.Schema(
198
207
  },
199
208
  resource: { required: true, type: schemaAdresource },
200
209
  slotKind: {
210
+ default: EnumAdBookingSlotKind2.PAID,
201
211
  enum: Object.values(EnumAdBookingSlotKind2),
202
212
  immutable: true,
203
213
  required: true,
@@ -224,7 +234,7 @@ schema3.pre(
224
234
  this.invalidate("slotNumber", "Ad booking slot must be an integer.");
225
235
  return;
226
236
  }
227
- const maximum = this.slotKind === EnumAdBookingSlotKind2.PAID ? 30 : 7;
237
+ const maximum = 30;
228
238
  if (this.slotNumber < 1 || this.slotNumber > maximum) {
229
239
  this.invalidate(
230
240
  "slotNumber",
@@ -261,26 +271,6 @@ schema3.index(
261
271
  unique: true
262
272
  }
263
273
  );
264
- schema3.index(
265
- { entitlementClaimKey: 1 },
266
- {
267
- partialFilterExpression: {
268
- entitlementClaimKey: { $type: "string" },
269
- state: { $in: liveStates }
270
- },
271
- unique: true
272
- }
273
- );
274
- schema3.index(
275
- { adId: 1, region: 1, placement: 1, dayKey: 1 },
276
- {
277
- partialFilterExpression: {
278
- entitlementSource: EnumAdEntitlementSource.ADMIN,
279
- state: { $in: liveStates }
280
- },
281
- unique: true
282
- }
283
- );
284
274
  schema3.index(
285
275
  { stripeCheckoutSessionId: 1 },
286
276
  {
@@ -290,79 +280,67 @@ schema3.index(
290
280
  );
291
281
  var AdBookingModel = mongoose3.models.AdBooking || mongoose3.model("AdBooking", schema3);
292
282
 
293
- // src/mongoose/ad/AdImpression.ts
294
- import { EnumAdShowOn as EnumAdShowOn3 } from "@timardex/cluemart-shared";
283
+ // src/mongoose/ad/AdMetrics.ts
284
+ import {
285
+ EnumAdPlatform,
286
+ EnumAdShowOn as EnumAdShowOn4,
287
+ isUtcMidnight as isUtcMidnight3
288
+ } from "@timardex/cluemart-shared";
295
289
  import mongoose4 from "mongoose";
296
290
  var schema4 = new mongoose4.Schema(
297
291
  {
298
- _id: { required: true, type: String },
299
- adId: { required: true, type: String },
300
- dayKey: { match: /^\d{4}-\d{2}-\d{2}$/, required: true, type: String },
292
+ adId: { ref: "Ad", required: true, type: String },
293
+ clicks: { default: 0, required: true, type: Number },
294
+ date: {
295
+ immutable: true,
296
+ required: true,
297
+ type: Date,
298
+ validate: {
299
+ message: "date must be a UTC-midnight day key.",
300
+ validator: isUtcMidnight3
301
+ }
302
+ },
303
+ impressions: { default: 0, required: true, type: Number },
301
304
  placement: {
302
- enum: [EnumAdShowOn3.FRONT_PAGE, EnumAdShowOn3.MARKET_SEARCH],
305
+ enum: Object.values(EnumAdShowOn4),
306
+ immutable: true,
303
307
  required: true,
304
308
  type: String
305
309
  },
306
- recordedAt: { default: Date.now, required: true, type: Date },
307
- viewerSlotKey: { required: true, type: String }
310
+ platform: {
311
+ enum: Object.values(EnumAdPlatform),
312
+ immutable: true,
313
+ required: true,
314
+ type: String
315
+ }
308
316
  },
309
- { collection: "adImpressions" }
317
+ { timestamps: true }
310
318
  );
311
- schema4.index({ adId: 1, recordedAt: 1 });
312
- schema4.index({ adId: 1, placement: 1, viewerSlotKey: 1 }, { unique: true });
313
- schema4.index({ recordedAt: 1 }, { expireAfterSeconds: 7 * 24 * 60 * 60 });
314
- schema4.index({ dayKey: 1, placement: 1, adId: 1 });
315
- var AdImpressionModel = mongoose4.models.AdImpression || mongoose4.model("AdImpression", schema4, "adImpressions");
319
+ schema4.index({ adId: 1, date: 1, placement: 1, platform: 1 }, { unique: true });
320
+ var AdMetricsModel = mongoose4.models.AdMetrics || mongoose4.model("AdMetrics", schema4);
316
321
 
317
322
  // src/mongoose/ad/AdSettings.ts
318
323
  import mongoose5 from "mongoose";
319
324
  var DEFAULT_AD_SETTINGS = {
320
325
  _id: "default",
321
- approvalRequired: true,
322
- minAppearancesPerHour: 12,
323
- paidSlotsPerPlacement: 30,
324
- reservedSlotsPerPlacement: 7,
325
- rotationSeconds: 8
326
+ approvalRequired: true
326
327
  };
327
328
  var schema5 = new mongoose5.Schema(
328
329
  {
329
330
  _id: { default: "default", enum: ["default"], type: String },
330
331
  approvalRequired: { default: true, required: true, type: Boolean },
331
332
  minAppearancesPerHour: {
332
- default: 12,
333
+ max: 12,
333
334
  min: 1,
334
- required: true,
335
335
  type: Number,
336
- validate: {
337
- message: "Minimum appearances per hour must be a whole number.",
338
- validator: Number.isInteger
339
- }
340
- },
341
- paidSlotsPerPlacement: {
342
- default: 30,
343
- enum: [30],
344
- immutable: true,
345
- type: Number
336
+ validate: Number.isInteger
346
337
  },
347
- reservedSlotsPerPlacement: {
348
- default: 7,
349
- enum: [7],
350
- immutable: true,
351
- type: Number
352
- },
353
- rotationSeconds: { default: 8, enum: [8], immutable: true, type: Number }
338
+ paidSlotsPerPlacement: { enum: [30], immutable: true, type: Number },
339
+ reservedSlotsPerPlacement: { enum: [7], immutable: true, type: Number },
340
+ rotationSeconds: { enum: [8], immutable: true, type: Number }
354
341
  },
355
342
  { collection: "adSettings", timestamps: true }
356
343
  );
357
- schema5.pre("validate", function validateRotationCapacity() {
358
- const availableRotationsPerHour = 3600 / this.rotationSeconds;
359
- if (this.minAppearancesPerHour * (this.paidSlotsPerPlacement + this.reservedSlotsPerPlacement) > availableRotationsPerHour) {
360
- this.invalidate(
361
- "minAppearancesPerHour",
362
- "The configured minimum exceeds the available rotation slots."
363
- );
364
- }
365
- });
366
344
  var AdSettingsModel = mongoose5.models.AdSettings || mongoose5.model("AdSettings", schema5, "adSettings");
367
345
 
368
346
  // src/mongoose/BillingCatalog.ts
@@ -2604,7 +2582,7 @@ export {
2604
2582
  AD_BILLING_CATALOG_COLLECTION_NAME,
2605
2583
  AdBillingCatalogModel,
2606
2584
  AdBookingModel,
2607
- AdImpressionModel,
2585
+ AdMetricsModel,
2608
2586
  DEFAULT_AD_SETTINGS,
2609
2587
  AdSettingsModel,
2610
2588
  BILLING_CATALOG_COLLECTION_NAME,
@@ -2655,4 +2633,4 @@ export {
2655
2633
  ImpersonationSessionModel,
2656
2634
  ImpersonationAuditModel
2657
2635
  };
2658
- //# sourceMappingURL=chunk-XGBC5DCX.mjs.map
2636
+ //# sourceMappingURL=chunk-T5TP2XMR.mjs.map