@timardex/cluemart-server-shared 2.2.12 → 2.2.22

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/index.cjs CHANGED
@@ -54,6 +54,8 @@ __export(index_exports, {
54
54
  EventModel: () => EventModel,
55
55
  GameModel: () => GameModel,
56
56
  GoogleImportedMarketModel: () => GoogleImportedMarketModel,
57
+ ImpersonationAuditModel: () => ImpersonationAuditModel,
58
+ ImpersonationSessionModel: () => ImpersonationSessionModel,
57
59
  LicenceCategory: () => LicenceCategory,
58
60
  NotificationModel: () => NotificationModel,
59
61
  OwnerTypeSchema: () => OwnerTypeSchema,
@@ -116,7 +118,7 @@ __export(index_exports, {
116
118
  locationGeoSchema: () => locationGeoSchema,
117
119
  locationsSchema: () => locationsSchema,
118
120
  mapVendorLicenceToSubscriptionRewardType: () => mapVendorLicenceToSubscriptionRewardType,
119
- mongoose: () => import_mongoose37.default,
121
+ mongoose: () => import_mongoose38.default,
120
122
  normalizeAffiliatePromoCodes: () => normalizeAffiliatePromoCodes,
121
123
  normalizePromoCode: () => normalizePromoCode,
122
124
  notifyUsers: () => notifyUsers,
@@ -145,7 +147,7 @@ __export(index_exports, {
145
147
  updateAdStatuses: () => updateAdStatuses,
146
148
  updateAllEventDateTimeStatuses: () => updateAllEventDateTimeStatuses,
147
149
  updateRelationDatesToUnavailable: () => updateRelationDatesToUnavailable,
148
- updateSingleDateTimeStatus: () => import_cluemart_shared34.updateSingleDateTimeStatus,
150
+ updateSingleDateTimeStatus: () => import_cluemart_shared35.updateSingleDateTimeStatus,
149
151
  upgradeUserToLicence: () => upgradeUserToLicence,
150
152
  userLicenseSchema: () => userLicenseSchema,
151
153
  vendorOwnerHasProLicence: () => vendorOwnerHasProLicence,
@@ -2599,6 +2601,62 @@ schema24.index({ active: 1, deletedAt: 1, "owner.userId": 1 });
2599
2601
  schema24.index({ "couponData.participantUsers.userId": 1 });
2600
2602
  var CouponModel = import_mongoose32.default.models.Coupon || import_mongoose32.default.model("Coupon", schema24);
2601
2603
 
2604
+ // src/mongoose/Impersonation.ts
2605
+ var import_cluemart_shared22 = require("@timardex/cluemart-shared");
2606
+ var import_mongoose33 = __toESM(require("mongoose"));
2607
+ var MongooseSchema28 = import_mongoose33.default.Schema;
2608
+ var impersonationSessionSchema = new MongooseSchema28(
2609
+ {
2610
+ expiresAt: { expires: 0, required: true, type: Date },
2611
+ impersonatedUserId: {
2612
+ index: true,
2613
+ ref: "User",
2614
+ required: true,
2615
+ type: import_mongoose33.default.Schema.Types.ObjectId
2616
+ },
2617
+ impersonatorUserId: {
2618
+ index: true,
2619
+ ref: "User",
2620
+ required: true,
2621
+ type: import_mongoose33.default.Schema.Types.ObjectId
2622
+ },
2623
+ refreshToken: { required: true, type: String }
2624
+ },
2625
+ { timestamps: true }
2626
+ );
2627
+ var ImpersonationSessionModel = import_mongoose33.default.models.ImpersonationSession || import_mongoose33.default.model(
2628
+ "ImpersonationSession",
2629
+ impersonationSessionSchema
2630
+ );
2631
+ var impersonationAuditSchema = new MongooseSchema28(
2632
+ {
2633
+ action: { enum: ["start", "end"], required: true, type: String },
2634
+ endReason: { type: String },
2635
+ impersonatedUserId: {
2636
+ ref: "User",
2637
+ required: true,
2638
+ type: import_mongoose33.default.Schema.Types.ObjectId
2639
+ },
2640
+ impersonatorUserId: {
2641
+ ref: "User",
2642
+ required: true,
2643
+ type: import_mongoose33.default.Schema.Types.ObjectId
2644
+ },
2645
+ resourceId: { type: import_mongoose33.default.Schema.Types.ObjectId },
2646
+ resourceType: { enum: Object.values(import_cluemart_shared22.EnumResourceType), type: String },
2647
+ sessionId: {
2648
+ ref: "ImpersonationSession",
2649
+ required: true,
2650
+ type: import_mongoose33.default.Schema.Types.ObjectId
2651
+ }
2652
+ },
2653
+ { timestamps: true }
2654
+ );
2655
+ var ImpersonationAuditModel = import_mongoose33.default.models.ImpersonationAudit || import_mongoose33.default.model(
2656
+ "ImpersonationAudit",
2657
+ impersonationAuditSchema
2658
+ );
2659
+
2602
2660
  // src/service/promoCode/constants.ts
2603
2661
  var ACTIVE_NOT_DELETED_FILTER = {
2604
2662
  active: true,
@@ -2615,7 +2673,7 @@ async function activeAffiliateCodeExists(affiliateCode) {
2615
2673
  }
2616
2674
 
2617
2675
  // src/service/affiliate/awardAffiliateVendorSubscriptionRewards.ts
2618
- var import_cluemart_shared23 = require("@timardex/cluemart-shared");
2676
+ var import_cluemart_shared24 = require("@timardex/cluemart-shared");
2619
2677
  var import_utils3 = require("@timardex/cluemart-shared/utils");
2620
2678
 
2621
2679
  // src/service/saveNotificationsInDb.ts
@@ -2750,7 +2808,7 @@ async function sendPushNotifications({
2750
2808
  }
2751
2809
 
2752
2810
  // src/service/affiliate/vendorSubscriptionRewards.ts
2753
- var import_cluemart_shared22 = require("@timardex/cluemart-shared");
2811
+ var import_cluemart_shared23 = require("@timardex/cluemart-shared");
2754
2812
  var import_dayjs = __toESM(require("dayjs"));
2755
2813
  var import_timezone = __toESM(require("dayjs/plugin/timezone"));
2756
2814
  var import_utc = __toESM(require("dayjs/plugin/utc"));
@@ -2808,14 +2866,14 @@ import_dayjs.default.extend(import_timezone.default);
2808
2866
  var SUBSCRIPTION_REWARD_TIMEZONE = "Pacific/Auckland";
2809
2867
  async function mapVendorLicenceToSubscriptionRewardType(userId, now = /* @__PURE__ */ new Date()) {
2810
2868
  const { hasSubscription, validTypes } = await getPayingVendorStripeSubscriptionPlan(userId, now);
2811
- if (validTypes.has(import_cluemart_shared22.EnumUserLicence.PRO_VENDOR) || validTypes.has(import_cluemart_shared22.EnumUserLicence.PRO_PLUS_VENDOR)) {
2869
+ if (validTypes.has(import_cluemart_shared23.EnumUserLicence.PRO_VENDOR) || validTypes.has(import_cluemart_shared23.EnumUserLicence.PRO_PLUS_VENDOR)) {
2812
2870
  if (hasSubscription) {
2813
- return import_cluemart_shared22.EnumAffiliateRewardType.ACTIVE_VENDOR_PRO_SUBSCRIPTION;
2871
+ return import_cluemart_shared23.EnumAffiliateRewardType.ACTIVE_VENDOR_PRO_SUBSCRIPTION;
2814
2872
  }
2815
- return import_cluemart_shared22.EnumAffiliateRewardType.ACTIVE_VENDOR_STANDARD_SUBSCRIPTION;
2873
+ return import_cluemart_shared23.EnumAffiliateRewardType.ACTIVE_VENDOR_STANDARD_SUBSCRIPTION;
2816
2874
  }
2817
- if (validTypes.has(import_cluemart_shared22.EnumUserLicence.STANDARD_VENDOR)) {
2818
- return import_cluemart_shared22.EnumAffiliateRewardType.ACTIVE_VENDOR_STANDARD_SUBSCRIPTION;
2875
+ if (validTypes.has(import_cluemart_shared23.EnumUserLicence.STANDARD_VENDOR)) {
2876
+ return import_cluemart_shared23.EnumAffiliateRewardType.ACTIVE_VENDOR_STANDARD_SUBSCRIPTION;
2819
2877
  }
2820
2878
  return null;
2821
2879
  }
@@ -2827,7 +2885,7 @@ function getSubscriptionRewardPeriodBounds(now = /* @__PURE__ */ new Date()) {
2827
2885
 
2828
2886
  // src/service/affiliate/awardAffiliateVendorSubscriptionRewards.ts
2829
2887
  function isEligibleVendorResource(resource) {
2830
- return resource.resourceType === import_cluemart_shared23.EnumResourceType.VENDOR && resource.resourceActive === true && resource.resourceDeletedAt == null;
2888
+ return resource.resourceType === import_cluemart_shared24.EnumResourceType.VENDOR && resource.resourceActive === true && resource.resourceDeletedAt == null;
2831
2889
  }
2832
2890
  async function findAffiliatesWithActiveVendorReferrals() {
2833
2891
  return await AffiliateModel.find({
@@ -2836,7 +2894,7 @@ async function findAffiliatesWithActiveVendorReferrals() {
2836
2894
  $elemMatch: {
2837
2895
  resourceActive: true,
2838
2896
  resourceDeletedAt: null,
2839
- resourceType: import_cluemart_shared23.EnumResourceType.VENDOR
2897
+ resourceType: import_cluemart_shared24.EnumResourceType.VENDOR
2840
2898
  }
2841
2899
  },
2842
2900
  deletedAt: null
@@ -2870,11 +2928,11 @@ async function notifyAffiliateOwnerOfSubscriptionReward({
2870
2928
  data: {
2871
2929
  resourceId: String(affiliateId),
2872
2930
  resourceName: resourceNames.join(", "),
2873
- resourceType: import_cluemart_shared23.EnumNotificationResourceType.AFFILIATE_REWARD_RECEIVED
2931
+ resourceType: import_cluemart_shared24.EnumNotificationResourceType.AFFILIATE_REWARD_RECEIVED
2874
2932
  },
2875
2933
  message,
2876
2934
  title: "Affiliate points earned",
2877
- type: import_cluemart_shared23.EnumNotificationType.SYSTEM,
2935
+ type: import_cluemart_shared24.EnumNotificationType.SYSTEM,
2878
2936
  userIds: [affiliateOwnerUserId]
2879
2937
  };
2880
2938
  try {
@@ -2903,7 +2961,7 @@ async function tryAwardSubscriptionReward({
2903
2961
  resourceActive: true,
2904
2962
  resourceDeletedAt: null,
2905
2963
  resourceId: resource.resourceId,
2906
- resourceType: import_cluemart_shared23.EnumResourceType.VENDOR,
2964
+ resourceType: import_cluemart_shared24.EnumResourceType.VENDOR,
2907
2965
  rewards: {
2908
2966
  $not: {
2909
2967
  $elemMatch: {
@@ -3024,7 +3082,7 @@ function normalizeAffiliatePromoCodes(promoCodes) {
3024
3082
  }
3025
3083
 
3026
3084
  // src/service/database.ts
3027
- var import_mongoose36 = __toESM(require("mongoose"));
3085
+ var import_mongoose37 = __toESM(require("mongoose"));
3028
3086
  var connectToDatabase = async ({
3029
3087
  appName,
3030
3088
  dbName,
@@ -3037,7 +3095,7 @@ var connectToDatabase = async ({
3037
3095
  // Fallback to MongoDB Atlas connection string
3038
3096
  `mongodb+srv://${dbUser}:${dbPassword}@${dbName}.mongodb.net/?retryWrites=true&w=majority&appName=${appName}`
3039
3097
  );
3040
- await import_mongoose36.default.connect(mongoUri);
3098
+ await import_mongoose37.default.connect(mongoUri);
3041
3099
  const connectionType = mongodbUri ? "Local MongoDB" : "MongoDB Atlas";
3042
3100
  console.log(
3043
3101
  `${connectionType} connected from server/src/service/database.ts`
@@ -3050,7 +3108,7 @@ var connectToDatabase = async ({
3050
3108
 
3051
3109
  // src/types/index.ts
3052
3110
  var import_express = __toESM(require("express"));
3053
- var import_mongoose37 = __toESM(require("mongoose"));
3111
+ var import_mongoose38 = __toESM(require("mongoose"));
3054
3112
  var EnumPubSubEvents = /* @__PURE__ */ ((EnumPubSubEvents2) => {
3055
3113
  EnumPubSubEvents2["GET_CHAT_MESSAGE"] = "GET_CHAT_MESSAGE";
3056
3114
  EnumPubSubEvents2["GET_NOTIFICATIONS"] = "GET_NOTIFICATIONS";
@@ -3105,7 +3163,7 @@ async function notifyUsers({
3105
3163
  }
3106
3164
 
3107
3165
  // src/service/updateAdStatus.ts
3108
- var import_cluemart_shared24 = require("@timardex/cluemart-shared");
3166
+ var import_cluemart_shared25 = require("@timardex/cluemart-shared");
3109
3167
  async function updateAdStatuses() {
3110
3168
  const now = /* @__PURE__ */ new Date();
3111
3169
  const invalidResult = await AdModel.updateMany(
@@ -3115,50 +3173,50 @@ async function updateAdStatuses() {
3115
3173
  { end: { $exists: false } },
3116
3174
  { $expr: { $gt: ["$start", "$end"] } }
3117
3175
  ],
3118
- status: { $ne: import_cluemart_shared24.EnumAdStatus.PAUSED }
3176
+ status: { $ne: import_cluemart_shared25.EnumAdStatus.PAUSED }
3119
3177
  },
3120
- { $set: { status: import_cluemart_shared24.EnumAdStatus.PAUSED } }
3178
+ { $set: { status: import_cluemart_shared25.EnumAdStatus.PAUSED } }
3121
3179
  );
3122
3180
  const expiredResult = await AdModel.updateMany(
3123
- { end: { $lte: now }, status: { $ne: import_cluemart_shared24.EnumAdStatus.EXPIRED } },
3124
- { $set: { status: import_cluemart_shared24.EnumAdStatus.EXPIRED } }
3181
+ { end: { $lte: now }, status: { $ne: import_cluemart_shared25.EnumAdStatus.EXPIRED } },
3182
+ { $set: { status: import_cluemart_shared25.EnumAdStatus.EXPIRED } }
3125
3183
  );
3126
3184
  const eligibleBooking = {
3127
3185
  $or: [
3128
3186
  { bookingKind: { $exists: false } },
3129
3187
  { bookingKind: null },
3130
3188
  {
3131
- approvalStatus: import_cluemart_shared24.EnumAdApprovalStatus.APPROVED,
3132
- bookingKind: import_cluemart_shared24.EnumAdBookingSlotKind.RESERVED
3189
+ approvalStatus: import_cluemart_shared25.EnumAdApprovalStatus.APPROVED,
3190
+ bookingKind: import_cluemart_shared25.EnumAdBookingSlotKind.RESERVED
3133
3191
  },
3134
3192
  {
3135
- approvalStatus: import_cluemart_shared24.EnumAdApprovalStatus.APPROVED,
3136
- bookingKind: import_cluemart_shared24.EnumAdBookingSlotKind.PAID,
3137
- paymentStatus: import_cluemart_shared24.EnumAdPaymentStatus.PAID
3193
+ approvalStatus: import_cluemart_shared25.EnumAdApprovalStatus.APPROVED,
3194
+ bookingKind: import_cluemart_shared25.EnumAdBookingSlotKind.PAID,
3195
+ paymentStatus: import_cluemart_shared25.EnumAdPaymentStatus.PAID
3138
3196
  }
3139
3197
  ]
3140
3198
  };
3141
3199
  const awaitingApprovalResult = await AdModel.updateMany(
3142
3200
  {
3143
3201
  $nor: eligibleBooking.$or,
3144
- bookingKind: { $in: Object.values(import_cluemart_shared24.EnumAdBookingSlotKind) },
3202
+ bookingKind: { $in: Object.values(import_cluemart_shared25.EnumAdBookingSlotKind) },
3145
3203
  end: { $gt: now },
3146
- status: import_cluemart_shared24.EnumAdStatus.ACTIVE
3204
+ status: import_cluemart_shared25.EnumAdStatus.ACTIVE
3147
3205
  },
3148
- { $set: { status: import_cluemart_shared24.EnumAdStatus.PAUSED } }
3206
+ { $set: { status: import_cluemart_shared25.EnumAdStatus.PAUSED } }
3149
3207
  );
3150
3208
  const activeResult = await AdModel.updateMany(
3151
3209
  {
3152
3210
  end: { $gt: now },
3153
3211
  start: { $lte: now },
3154
- status: { $ne: import_cluemart_shared24.EnumAdStatus.ACTIVE },
3212
+ status: { $ne: import_cluemart_shared25.EnumAdStatus.ACTIVE },
3155
3213
  ...eligibleBooking
3156
3214
  },
3157
- { $set: { status: import_cluemart_shared24.EnumAdStatus.ACTIVE } }
3215
+ { $set: { status: import_cluemart_shared25.EnumAdStatus.ACTIVE } }
3158
3216
  );
3159
3217
  const pausedResult = await AdModel.updateMany(
3160
- { start: { $gt: now }, status: { $ne: import_cluemart_shared24.EnumAdStatus.PAUSED } },
3161
- { $set: { status: import_cluemart_shared24.EnumAdStatus.PAUSED } }
3218
+ { start: { $gt: now }, status: { $ne: import_cluemart_shared25.EnumAdStatus.PAUSED } },
3219
+ { $set: { status: import_cluemart_shared25.EnumAdStatus.PAUSED } }
3162
3220
  );
3163
3221
  console.log(
3164
3222
  `\u2705 Ad statuses updated: invalid=${invalidResult.modifiedCount}, expired=${expiredResult.modifiedCount}, awaitingApproval=${awaitingApprovalResult.modifiedCount}, active=${activeResult.modifiedCount}, paused=${pausedResult.modifiedCount}`
@@ -3166,15 +3224,15 @@ async function updateAdStatuses() {
3166
3224
  }
3167
3225
 
3168
3226
  // src/service/objectIdToString.ts
3169
- var import_mongoose39 = __toESM(require("mongoose"));
3227
+ var import_mongoose40 = __toESM(require("mongoose"));
3170
3228
  function isValidObjectId(value) {
3171
- return import_mongoose39.default.Types.ObjectId.isValid(value);
3229
+ return import_mongoose40.default.Types.ObjectId.isValid(value);
3172
3230
  }
3173
3231
  function convertObjectIdsToStrings(obj) {
3174
3232
  if (obj === null || obj === void 0) {
3175
3233
  return obj;
3176
3234
  }
3177
- if (obj instanceof import_mongoose39.default.Types.ObjectId) {
3235
+ if (obj instanceof import_mongoose40.default.Types.ObjectId) {
3178
3236
  return obj.toString();
3179
3237
  }
3180
3238
  if (obj instanceof Date) {
@@ -3194,16 +3252,19 @@ function convertObjectIdsToStrings(obj) {
3194
3252
  }
3195
3253
 
3196
3254
  // src/service/event/updateAllEventDateTimeStatuses.ts
3197
- var import_cluemart_shared26 = require("@timardex/cluemart-shared");
3198
- var import_dayjs2 = __toESM(require("dayjs"));
3255
+ var import_cluemart_shared27 = require("@timardex/cluemart-shared");
3256
+ var import_dayjs3 = __toESM(require("dayjs"));
3199
3257
 
3200
3258
  // src/service/event/archiveEndedEventDates.ts
3201
- var import_cluemart_shared25 = require("@timardex/cluemart-shared");
3259
+ var import_cluemart_shared26 = require("@timardex/cluemart-shared");
3260
+ var import_dayjs2 = __toESM(require("dayjs"));
3261
+ var import_customParseFormat = __toESM(require("dayjs/plugin/customParseFormat"));
3262
+ import_dayjs2.default.extend(import_customParseFormat.default);
3202
3263
  var ARCHIVED_STATUSES = /* @__PURE__ */ new Set([
3203
- import_cluemart_shared25.EnumEventDateStatus.ENDED
3264
+ import_cluemart_shared26.EnumEventDateStatus.ENDED
3204
3265
  ]);
3205
3266
  var DISCARDED_STATUSES = /* @__PURE__ */ new Set([
3206
- import_cluemart_shared25.EnumEventDateStatus.INVALID
3267
+ import_cluemart_shared26.EnumEventDateStatus.INVALID
3207
3268
  ]);
3208
3269
  function splitEventDatesForArchive(dateTime) {
3209
3270
  return {
@@ -3225,6 +3286,17 @@ function dedupeArchivedSlotsByStartDateTime(slots) {
3225
3286
  return true;
3226
3287
  });
3227
3288
  }
3289
+ function isPastCanceledEventDate(slot, now) {
3290
+ if (slot.dateStatus !== import_cluemart_shared26.EnumEventDateStatus.CANCELED) {
3291
+ return false;
3292
+ }
3293
+ const endDateTime = (0, import_dayjs2.default)(
3294
+ `${slot.endDate} ${slot.endTime}`,
3295
+ `${import_cluemart_shared26.dateFormat} ${import_cluemart_shared26.timeFormat}`,
3296
+ true
3297
+ );
3298
+ return endDateTime.isValid() && endDateTime.isBefore(now);
3299
+ }
3228
3300
  async function persistArchivedEventDates(eventId, slots) {
3229
3301
  if (slots.length === 0) {
3230
3302
  return;
@@ -3266,7 +3338,7 @@ async function updateModelDateTimeStatuses(model, now) {
3266
3338
  try {
3267
3339
  for await (const doc of cursor) {
3268
3340
  const dateTime = doc.dateTime.map(
3269
- (slot) => (0, import_cluemart_shared26.updateSingleDateTimeStatus)(slot, now)
3341
+ (slot) => (0, import_cluemart_shared27.updateSingleDateTimeStatus)(slot, now)
3270
3342
  );
3271
3343
  if (!hasDateTimeStatusChanges(doc.dateTime, dateTime)) {
3272
3344
  continue;
@@ -3289,7 +3361,11 @@ async function updateModelDateTimeStatuses(model, now) {
3289
3361
  }
3290
3362
  var ARCHIVABLE_EVENT_FILTER = {
3291
3363
  "dateTime.dateStatus": {
3292
- $in: [import_cluemart_shared26.EnumEventDateStatus.ENDED, import_cluemart_shared26.EnumEventDateStatus.INVALID]
3364
+ $in: [
3365
+ import_cluemart_shared27.EnumEventDateStatus.ENDED,
3366
+ import_cluemart_shared27.EnumEventDateStatus.INVALID,
3367
+ import_cluemart_shared27.EnumEventDateStatus.CANCELED
3368
+ ]
3293
3369
  },
3294
3370
  deletedAt: null
3295
3371
  };
@@ -3304,17 +3380,22 @@ async function archiveEndedAndDiscardInvalidEventDates(now) {
3304
3380
  archiveOps = [];
3305
3381
  }
3306
3382
  if (eventOps.length) {
3307
- await EventModel.bulkWrite(eventOps);
3383
+ await EventModel.bulkWrite(
3384
+ eventOps
3385
+ );
3308
3386
  eventOps = [];
3309
3387
  }
3310
3388
  };
3311
3389
  try {
3312
3390
  for await (const doc of cursor) {
3313
3391
  const updated = doc.dateTime.map(
3314
- (slot) => (0, import_cluemart_shared26.updateSingleDateTimeStatus)(slot, now)
3392
+ (slot) => (0, import_cluemart_shared27.updateSingleDateTimeStatus)(slot, now)
3315
3393
  );
3316
3394
  const { archive, discard } = splitEventDatesForArchive(updated);
3317
- if (archive.length === 0 && discard.length === 0) {
3395
+ const pastCanceled = updated.filter(
3396
+ (slot) => isPastCanceledEventDate(slot, now)
3397
+ );
3398
+ if (archive.length === 0 && discard.length === 0 && pastCanceled.length === 0) {
3318
3399
  continue;
3319
3400
  }
3320
3401
  if (archive.length > 0) {
@@ -3328,16 +3409,27 @@ async function archiveEndedAndDiscardInvalidEventDates(now) {
3328
3409
  });
3329
3410
  archivedCount += uniqueArchive.length;
3330
3411
  }
3412
+ const pullConditions = [];
3413
+ if (archive.length > 0 || discard.length > 0) {
3414
+ pullConditions.push({
3415
+ dateStatus: {
3416
+ $in: [import_cluemart_shared27.EnumEventDateStatus.ENDED, import_cluemart_shared27.EnumEventDateStatus.INVALID]
3417
+ }
3418
+ });
3419
+ }
3420
+ for (const slot of pastCanceled) {
3421
+ pullConditions.push({
3422
+ dateStatus: import_cluemart_shared27.EnumEventDateStatus.CANCELED,
3423
+ startDate: slot.startDate,
3424
+ startTime: slot.startTime
3425
+ });
3426
+ }
3331
3427
  eventOps.push({
3332
3428
  updateOne: {
3333
3429
  filter: { _id: doc._id },
3334
3430
  update: {
3335
3431
  $pull: {
3336
- dateTime: {
3337
- dateStatus: {
3338
- $in: [import_cluemart_shared26.EnumEventDateStatus.ENDED, import_cluemart_shared26.EnumEventDateStatus.INVALID]
3339
- }
3340
- }
3432
+ dateTime: { $or: pullConditions }
3341
3433
  }
3342
3434
  }
3343
3435
  }
@@ -3369,9 +3461,9 @@ async function cleanEventInfoDates(now) {
3369
3461
  try {
3370
3462
  for await (const doc of cursor) {
3371
3463
  const updated = doc.dateTime.map(
3372
- (slot) => (0, import_cluemart_shared26.updateSingleDateTimeStatus)(slot, now)
3464
+ (slot) => (0, import_cluemart_shared27.updateSingleDateTimeStatus)(slot, now)
3373
3465
  );
3374
- const kept = (0, import_cluemart_shared26.filterDatesByFutureStatus)(updated);
3466
+ const kept = (0, import_cluemart_shared27.filterDatesByFutureStatus)(updated);
3375
3467
  if (kept.length === updated.length) {
3376
3468
  continue;
3377
3469
  }
@@ -3393,7 +3485,7 @@ async function cleanEventInfoDates(now) {
3393
3485
  return removedCount;
3394
3486
  }
3395
3487
  async function updateAllEventDateTimeStatuses() {
3396
- const now = (0, import_dayjs2.default)();
3488
+ const now = (0, import_dayjs3.default)();
3397
3489
  const [eventCount, marketCount] = await Promise.all([
3398
3490
  updateModelDateTimeStatuses(EventModel, now),
3399
3491
  updateModelDateTimeStatuses(
@@ -3417,7 +3509,7 @@ async function updateAllEventDateTimeStatuses() {
3417
3509
  }
3418
3510
 
3419
3511
  // src/service/index.ts
3420
- var import_cluemart_shared34 = require("@timardex/cluemart-shared");
3512
+ var import_cluemart_shared35 = require("@timardex/cluemart-shared");
3421
3513
 
3422
3514
  // src/service/event/findEventOrImportedMarketById.ts
3423
3515
  async function findEventOrImportedMarketById(resourceId) {
@@ -3433,7 +3525,7 @@ async function findEventOrImportedMarketById(resourceId) {
3433
3525
  }
3434
3526
 
3435
3527
  // src/service/relations.ts
3436
- var import_cluemart_shared27 = require("@timardex/cluemart-shared");
3528
+ var import_cluemart_shared28 = require("@timardex/cluemart-shared");
3437
3529
  function didRemoveAnyEventDates(previousDateTime, nextDateTime) {
3438
3530
  if (!previousDateTime?.length) {
3439
3531
  return false;
@@ -3451,24 +3543,24 @@ function updateRelationDatesToUnavailable(relationDates, eventDateTime) {
3451
3543
  ) ?? false;
3452
3544
  return {
3453
3545
  ...relationDate,
3454
- status: existsInEvent ? relationDate.status : import_cluemart_shared27.EnumInviteStatus.UNAVAILABLE
3546
+ status: existsInEvent ? relationDate.status : import_cluemart_shared28.EnumInviteStatus.UNAVAILABLE
3455
3547
  };
3456
3548
  });
3457
3549
  }
3458
3550
 
3459
3551
  // src/service/license/compliance/ensureUserLicenseCompliance.ts
3460
- var import_dayjs6 = __toESM(require("dayjs"));
3552
+ var import_dayjs7 = __toESM(require("dayjs"));
3461
3553
 
3462
3554
  // src/service/license/compliance/utils.ts
3463
- var import_cluemart_shared32 = require("@timardex/cluemart-shared");
3464
- var import_dayjs5 = __toESM(require("dayjs"));
3555
+ var import_cluemart_shared33 = require("@timardex/cluemart-shared");
3556
+ var import_dayjs6 = __toESM(require("dayjs"));
3465
3557
 
3466
3558
  // src/service/license/compliance/event.ts
3467
- var import_cluemart_shared28 = require("@timardex/cluemart-shared");
3559
+ var import_cluemart_shared29 = require("@timardex/cluemart-shared");
3468
3560
  var eventLicences = [
3469
- import_cluemart_shared28.EnumUserLicence.STANDARD_EVENT,
3470
- import_cluemart_shared28.EnumUserLicence.PRO_EVENT,
3471
- import_cluemart_shared28.EnumUserLicence.PRO_PLUS_EVENT
3561
+ import_cluemart_shared29.EnumUserLicence.STANDARD_EVENT,
3562
+ import_cluemart_shared29.EnumUserLicence.PRO_EVENT,
3563
+ import_cluemart_shared29.EnumUserLicence.PRO_PLUS_EVENT
3472
3564
  ];
3473
3565
  async function handleEventLicenceCompliance(user, now) {
3474
3566
  if (!user.licences || !user.events?.length) {
@@ -3680,9 +3772,9 @@ function buildLicenceExpiryPipeline(params) {
3680
3772
  }
3681
3773
 
3682
3774
  // src/service/license/compliance/partner.ts
3683
- var import_cluemart_shared29 = require("@timardex/cluemart-shared");
3775
+ var import_cluemart_shared30 = require("@timardex/cluemart-shared");
3684
3776
  var partnerLicences = [
3685
- import_cluemart_shared29.EnumUserLicence.STANDARD_PARTNER
3777
+ import_cluemart_shared30.EnumUserLicence.STANDARD_PARTNER
3686
3778
  ];
3687
3779
  async function handlePartnerLicenceCompliance(user, now) {
3688
3780
  if (!user.licences || !user.partner) {
@@ -3692,12 +3784,12 @@ async function handlePartnerLicenceCompliance(user, now) {
3692
3784
  }
3693
3785
 
3694
3786
  // src/service/license/compliance/vendor.ts
3695
- var import_cluemart_shared31 = require("@timardex/cluemart-shared");
3696
- var import_dayjs4 = __toESM(require("dayjs"));
3787
+ var import_cluemart_shared32 = require("@timardex/cluemart-shared");
3788
+ var import_dayjs5 = __toESM(require("dayjs"));
3697
3789
 
3698
3790
  // src/service/license/models.ts
3699
- var import_cluemart_shared30 = require("@timardex/cluemart-shared");
3700
- var import_dayjs3 = __toESM(require("dayjs"));
3791
+ var import_cluemart_shared31 = require("@timardex/cluemart-shared");
3792
+ var import_dayjs4 = __toESM(require("dayjs"));
3701
3793
  var import_graphql = require("graphql");
3702
3794
  var LicenceCategory = /* @__PURE__ */ ((LicenceCategory2) => {
3703
3795
  LicenceCategory2["EVENT"] = "event";
@@ -3708,31 +3800,31 @@ var LicenceCategory = /* @__PURE__ */ ((LicenceCategory2) => {
3708
3800
  return LicenceCategory2;
3709
3801
  })(LicenceCategory || {});
3710
3802
  var licenceCategoryMapping = {
3711
- [import_cluemart_shared30.EnumUserLicence.PRO_EVENT]: "event" /* EVENT */,
3712
- [import_cluemart_shared30.EnumUserLicence.PRO_PLUS_EVENT]: "event" /* EVENT */,
3713
- [import_cluemart_shared30.EnumUserLicence.PRO_PLUS_VENDOR]: "vendor" /* VENDOR */,
3714
- [import_cluemart_shared30.EnumUserLicence.PRO_VENDOR]: "vendor" /* VENDOR */,
3715
- [import_cluemart_shared30.EnumUserLicence.STANDARD_EVENT]: "event" /* EVENT */,
3716
- [import_cluemart_shared30.EnumUserLicence.STANDARD_PARTNER]: "partner" /* PARTNER */,
3717
- [import_cluemart_shared30.EnumUserLicence.STANDARD_VENDOR]: "vendor" /* VENDOR */,
3718
- [import_cluemart_shared30.EnumUserLicence.STANDARD_AFFILIATE]: "affiliate" /* AFFILIATE */,
3719
- [import_cluemart_shared30.EnumUserLicence.STANDARD_SCHOOL]: "school" /* SCHOOL */
3803
+ [import_cluemart_shared31.EnumUserLicence.PRO_EVENT]: "event" /* EVENT */,
3804
+ [import_cluemart_shared31.EnumUserLicence.PRO_PLUS_EVENT]: "event" /* EVENT */,
3805
+ [import_cluemart_shared31.EnumUserLicence.PRO_PLUS_VENDOR]: "vendor" /* VENDOR */,
3806
+ [import_cluemart_shared31.EnumUserLicence.PRO_VENDOR]: "vendor" /* VENDOR */,
3807
+ [import_cluemart_shared31.EnumUserLicence.STANDARD_EVENT]: "event" /* EVENT */,
3808
+ [import_cluemart_shared31.EnumUserLicence.STANDARD_PARTNER]: "partner" /* PARTNER */,
3809
+ [import_cluemart_shared31.EnumUserLicence.STANDARD_VENDOR]: "vendor" /* VENDOR */,
3810
+ [import_cluemart_shared31.EnumUserLicence.STANDARD_AFFILIATE]: "affiliate" /* AFFILIATE */,
3811
+ [import_cluemart_shared31.EnumUserLicence.STANDARD_SCHOOL]: "school" /* SCHOOL */
3720
3812
  };
3721
3813
  var licencePriority = {
3722
- [import_cluemart_shared30.EnumUserLicence.PRO_PLUS_EVENT]: 3,
3723
- [import_cluemart_shared30.EnumUserLicence.PRO_EVENT]: 2,
3724
- [import_cluemart_shared30.EnumUserLicence.STANDARD_EVENT]: 1,
3725
- [import_cluemart_shared30.EnumUserLicence.PRO_PLUS_VENDOR]: 3,
3726
- [import_cluemart_shared30.EnumUserLicence.PRO_VENDOR]: 2,
3727
- [import_cluemart_shared30.EnumUserLicence.STANDARD_VENDOR]: 1,
3728
- [import_cluemart_shared30.EnumUserLicence.STANDARD_PARTNER]: 1,
3729
- [import_cluemart_shared30.EnumUserLicence.STANDARD_AFFILIATE]: 1,
3730
- [import_cluemart_shared30.EnumUserLicence.STANDARD_SCHOOL]: 1
3814
+ [import_cluemart_shared31.EnumUserLicence.PRO_PLUS_EVENT]: 3,
3815
+ [import_cluemart_shared31.EnumUserLicence.PRO_EVENT]: 2,
3816
+ [import_cluemart_shared31.EnumUserLicence.STANDARD_EVENT]: 1,
3817
+ [import_cluemart_shared31.EnumUserLicence.PRO_PLUS_VENDOR]: 3,
3818
+ [import_cluemart_shared31.EnumUserLicence.PRO_VENDOR]: 2,
3819
+ [import_cluemart_shared31.EnumUserLicence.STANDARD_VENDOR]: 1,
3820
+ [import_cluemart_shared31.EnumUserLicence.STANDARD_PARTNER]: 1,
3821
+ [import_cluemart_shared31.EnumUserLicence.STANDARD_AFFILIATE]: 1,
3822
+ [import_cluemart_shared31.EnumUserLicence.STANDARD_SCHOOL]: 1
3731
3823
  };
3732
3824
  var standardLicences = [
3733
- import_cluemart_shared30.EnumUserLicence.STANDARD_VENDOR,
3734
- import_cluemart_shared30.EnumUserLicence.STANDARD_EVENT,
3735
- import_cluemart_shared30.EnumUserLicence.STANDARD_PARTNER
3825
+ import_cluemart_shared31.EnumUserLicence.STANDARD_VENDOR,
3826
+ import_cluemart_shared31.EnumUserLicence.STANDARD_EVENT,
3827
+ import_cluemart_shared31.EnumUserLicence.STANDARD_PARTNER
3736
3828
  ];
3737
3829
  var standardLicenceSet = new Set(standardLicences);
3738
3830
  function isStandardLicence(licence) {
@@ -3746,11 +3838,11 @@ var categoryRegexMapping = {
3746
3838
  ["school" /* SCHOOL */]: /_school$/
3747
3839
  };
3748
3840
  var categoryFallbackLicence = {
3749
- ["event" /* EVENT */]: import_cluemart_shared30.EnumUserLicence.STANDARD_EVENT,
3750
- ["partner" /* PARTNER */]: import_cluemart_shared30.EnumUserLicence.STANDARD_PARTNER,
3751
- ["vendor" /* VENDOR */]: import_cluemart_shared30.EnumUserLicence.STANDARD_VENDOR,
3752
- ["affiliate" /* AFFILIATE */]: import_cluemart_shared30.EnumUserLicence.STANDARD_AFFILIATE,
3753
- ["school" /* SCHOOL */]: import_cluemart_shared30.EnumUserLicence.STANDARD_SCHOOL
3841
+ ["event" /* EVENT */]: import_cluemart_shared31.EnumUserLicence.STANDARD_EVENT,
3842
+ ["partner" /* PARTNER */]: import_cluemart_shared31.EnumUserLicence.STANDARD_PARTNER,
3843
+ ["vendor" /* VENDOR */]: import_cluemart_shared31.EnumUserLicence.STANDARD_VENDOR,
3844
+ ["affiliate" /* AFFILIATE */]: import_cluemart_shared31.EnumUserLicence.STANDARD_AFFILIATE,
3845
+ ["school" /* SCHOOL */]: import_cluemart_shared31.EnumUserLicence.STANDARD_SCHOOL
3754
3846
  };
3755
3847
  var LicenceFilterInput = {
3756
3848
  INPUT_USER_LICENCES: "$licences"
@@ -3778,13 +3870,13 @@ function getHighestLicenceForCategory(licences, category) {
3778
3870
  return highestLicence;
3779
3871
  }
3780
3872
  function createLicenceObject(expiryDate, licenceType) {
3781
- const today = (0, import_dayjs3.default)();
3873
+ const today = (0, import_dayjs4.default)();
3782
3874
  const expiryDateMapping = {
3783
- [import_cluemart_shared30.LicenceExpiryDate.ONE_YEAR]: today.add(1, "year").endOf("day").toDate(),
3784
- [import_cluemart_shared30.LicenceExpiryDate.ONE_MONTH]: today.add(1, "month").endOf("day").toDate(),
3785
- [import_cluemart_shared30.LicenceExpiryDate.TWO_MONTHS]: today.add(2, "month").endOf("day").toDate(),
3786
- [import_cluemart_shared30.LicenceExpiryDate.THREE_MONTHS]: today.add(3, "month").endOf("day").toDate(),
3787
- [import_cluemart_shared30.LicenceExpiryDate.SIX_MONTHS]: today.add(6, "month").endOf("day").toDate()
3875
+ [import_cluemart_shared31.LicenceExpiryDate.ONE_YEAR]: today.add(1, "year").endOf("day").toDate(),
3876
+ [import_cluemart_shared31.LicenceExpiryDate.ONE_MONTH]: today.add(1, "month").endOf("day").toDate(),
3877
+ [import_cluemart_shared31.LicenceExpiryDate.TWO_MONTHS]: today.add(2, "month").endOf("day").toDate(),
3878
+ [import_cluemart_shared31.LicenceExpiryDate.THREE_MONTHS]: today.add(3, "month").endOf("day").toDate(),
3879
+ [import_cluemart_shared31.LicenceExpiryDate.SIX_MONTHS]: today.add(6, "month").endOf("day").toDate()
3788
3880
  };
3789
3881
  const licenceObject = {
3790
3882
  expiryDate: expiryDateMapping[expiryDate],
@@ -3888,13 +3980,13 @@ async function checkOwnerHasLicence({
3888
3980
  const owner = await UserModel.findById(userId);
3889
3981
  if (!owner) throw new import_graphql.GraphQLError("Owner not found");
3890
3982
  const categoryByResource = {
3891
- [import_cluemart_shared30.EnumResourceType.EVENT]: "event" /* EVENT */,
3892
- [import_cluemart_shared30.EnumResourceType.PARTNER]: "partner" /* PARTNER */,
3893
- [import_cluemart_shared30.EnumResourceType.VENDOR]: "vendor" /* VENDOR */,
3894
- [import_cluemart_shared30.EnumResourceType.AFFILIATE]: "affiliate" /* AFFILIATE */,
3895
- [import_cluemart_shared30.EnumResourceType.SCHOOL]: "school" /* SCHOOL */
3983
+ [import_cluemart_shared31.EnumResourceType.EVENT]: "event" /* EVENT */,
3984
+ [import_cluemart_shared31.EnumResourceType.PARTNER]: "partner" /* PARTNER */,
3985
+ [import_cluemart_shared31.EnumResourceType.VENDOR]: "vendor" /* VENDOR */,
3986
+ [import_cluemart_shared31.EnumResourceType.AFFILIATE]: "affiliate" /* AFFILIATE */,
3987
+ [import_cluemart_shared31.EnumResourceType.SCHOOL]: "school" /* SCHOOL */
3896
3988
  };
3897
- if (!(0, import_cluemart_shared30.isNonVisitorResourceType)(resourceType)) {
3989
+ if (!(0, import_cluemart_shared31.isNonVisitorResourceType)(resourceType)) {
3898
3990
  throw new import_graphql.GraphQLError(`Invalid resource type: ${resourceType}.`);
3899
3991
  }
3900
3992
  const requiredCategory = categoryByResource[resourceType];
@@ -3974,7 +4066,7 @@ async function applyVendorDowngrade(vendor, ownerUserId) {
3974
4066
  return (result?.matchedCount ?? 0) > 0;
3975
4067
  }
3976
4068
  async function downgradeVendorProFeatures(userId, licenceType) {
3977
- const isStandardVendor = licenceType === import_cluemart_shared31.EnumUserLicence.STANDARD_VENDOR;
4069
+ const isStandardVendor = licenceType === import_cluemart_shared32.EnumUserLicence.STANDARD_VENDOR;
3978
4070
  if (!isStandardVendor) {
3979
4071
  return;
3980
4072
  }
@@ -4021,7 +4113,7 @@ async function applyVendorRestore(vendor, ownerUserId) {
4021
4113
  return (result?.matchedCount ?? 0) > 0;
4022
4114
  }
4023
4115
  async function restoreVendorProFeatures(userId, licenceType) {
4024
- const isProVendor = licenceType === import_cluemart_shared31.EnumUserLicence.PRO_VENDOR || licenceType === import_cluemart_shared31.EnumUserLicence.PRO_PLUS_VENDOR;
4116
+ const isProVendor = licenceType === import_cluemart_shared32.EnumUserLicence.PRO_VENDOR || licenceType === import_cluemart_shared32.EnumUserLicence.PRO_PLUS_VENDOR;
4025
4117
  if (!isProVendor) {
4026
4118
  return;
4027
4119
  }
@@ -4041,21 +4133,21 @@ function isProtectedByCurrentStripeSubscription(user, licenceType, now) {
4041
4133
  if (!stripe || stripe.currentPlan !== licenceType) {
4042
4134
  return false;
4043
4135
  }
4044
- const gracePeriodEndsAt = stripe.paymentGracePeriodEndsAt ? (0, import_dayjs4.default)(stripe.paymentGracePeriodEndsAt) : null;
4045
- const hasActivePaymentGracePeriod = (stripe.status === import_cluemart_shared31.EnumSubscriptionStatus.PAST_DUE || stripe.status === import_cluemart_shared31.EnumSubscriptionStatus.INACTIVE) && Boolean(stripe.paymentGraceSubscriptionId) && (!stripe.subscriptionId || stripe.subscriptionId === stripe.paymentGraceSubscriptionId) && gracePeriodEndsAt !== null && gracePeriodEndsAt.isValid() && gracePeriodEndsAt.isAfter(now);
4136
+ const gracePeriodEndsAt = stripe.paymentGracePeriodEndsAt ? (0, import_dayjs5.default)(stripe.paymentGracePeriodEndsAt) : null;
4137
+ const hasActivePaymentGracePeriod = (stripe.status === import_cluemart_shared32.EnumSubscriptionStatus.PAST_DUE || stripe.status === import_cluemart_shared32.EnumSubscriptionStatus.INACTIVE) && Boolean(stripe.paymentGraceSubscriptionId) && (!stripe.subscriptionId || stripe.subscriptionId === stripe.paymentGraceSubscriptionId) && gracePeriodEndsAt !== null && gracePeriodEndsAt.isValid() && gracePeriodEndsAt.isAfter(now);
4046
4138
  if (hasActivePaymentGracePeriod) {
4047
4139
  return true;
4048
4140
  }
4049
4141
  if (!stripe.subscriptionId) {
4050
4142
  return false;
4051
4143
  }
4052
- if (stripe.status !== import_cluemart_shared31.EnumSubscriptionStatus.ACTIVE) {
4144
+ if (stripe.status !== import_cluemart_shared32.EnumSubscriptionStatus.ACTIVE) {
4053
4145
  return false;
4054
4146
  }
4055
4147
  if (!stripe.endDate) {
4056
4148
  return false;
4057
4149
  }
4058
- const paidThrough = (0, import_dayjs4.default)(stripe.endDate);
4150
+ const paidThrough = (0, import_dayjs5.default)(stripe.endDate);
4059
4151
  return paidThrough.isValid() && paidThrough.isAfter(now);
4060
4152
  }
4061
4153
  async function handleVendorLicenceCompliance(user, now) {
@@ -4069,10 +4161,10 @@ async function handleVendorLicenceCompliance(user, now) {
4069
4161
  return;
4070
4162
  }
4071
4163
  const proLicences = vendorLicencesOfUser.filter(
4072
- (licence) => licence.licenceType !== import_cluemart_shared31.EnumUserLicence.STANDARD_VENDOR
4164
+ (licence) => licence.licenceType !== import_cluemart_shared32.EnumUserLicence.STANDARD_VENDOR
4073
4165
  );
4074
4166
  const expiredProLicences = proLicences.filter(
4075
- (licence) => !(0, import_dayjs4.default)(licence.expiryDate).isAfter(now)
4167
+ (licence) => !(0, import_dayjs5.default)(licence.expiryDate).isAfter(now)
4076
4168
  );
4077
4169
  const stripeProtectedLicenceTypes = new Set(
4078
4170
  expiredProLicences.filter(
@@ -4082,9 +4174,9 @@ async function handleVendorLicenceCompliance(user, now) {
4082
4174
  const expiredProLicence = expiredProLicences.some(
4083
4175
  (licence) => !stripeProtectedLicenceTypes.has(licence.licenceType)
4084
4176
  );
4085
- const hasValidProLicence = stripeProtectedLicenceTypes.size > 0 || hasValidLicence(proLicences, import_cluemart_shared31.vendorLicences, now);
4177
+ const hasValidProLicence = stripeProtectedLicenceTypes.size > 0 || hasValidLicence(proLicences, import_cluemart_shared32.vendorLicences, now);
4086
4178
  const hasExpiredVendorLicence = vendorLicencesOfUser.some(
4087
- (licence) => !(0, import_dayjs4.default)(licence.expiryDate).isAfter(now) && !stripeProtectedLicenceTypes.has(licence.licenceType)
4179
+ (licence) => !(0, import_dayjs5.default)(licence.expiryDate).isAfter(now) && !stripeProtectedLicenceTypes.has(licence.licenceType)
4088
4180
  );
4089
4181
  if (!hasExpiredVendorLicence) {
4090
4182
  return;
@@ -4098,7 +4190,7 @@ async function handleVendorLicenceCompliance(user, now) {
4098
4190
  "owner.userId": user._id
4099
4191
  }).lean().exec();
4100
4192
  }
4101
- const licencesToSync = import_cluemart_shared31.vendorLicences.filter(
4193
+ const licencesToSync = import_cluemart_shared32.vendorLicences.filter(
4102
4194
  (licenceType) => !stripeProtectedLicenceTypes.has(licenceType)
4103
4195
  );
4104
4196
  await syncUserLicencesAfterExpiry(user._id, licencesToSync, now, "downgrade");
@@ -4113,11 +4205,11 @@ async function handleVendorLicenceCompliance(user, now) {
4113
4205
  data: {
4114
4206
  resourceId: String(vendor._id),
4115
4207
  resourceName: vendor.name,
4116
- resourceType: import_cluemart_shared31.EnumNotificationResourceType.DOWNGRADED_VENDOR
4208
+ resourceType: import_cluemart_shared32.EnumNotificationResourceType.DOWNGRADED_VENDOR
4117
4209
  },
4118
4210
  message: `Your Vendor licence has been downgraded due to licence expiration.`,
4119
4211
  title: `Vendor Licence Downgraded`,
4120
- type: import_cluemart_shared31.EnumNotificationType.SYSTEM,
4212
+ type: import_cluemart_shared32.EnumNotificationType.SYSTEM,
4121
4213
  userIds: [user._id]
4122
4214
  };
4123
4215
  await sendDeactivationNotification(payload, user._id, vendor.name, "vendor");
@@ -4138,9 +4230,9 @@ async function vendorOwnerHasProLicence(vendorId) {
4138
4230
  if (!owner) {
4139
4231
  return false;
4140
4232
  }
4141
- const now = (0, import_dayjs4.default)();
4233
+ const now = (0, import_dayjs5.default)();
4142
4234
  const effectiveVendorLicences = owner.licences?.filter(
4143
- (licence) => licence?.licenceType && ((0, import_dayjs4.default)(licence.expiryDate).isAfter(now) || isProtectedByCurrentStripeSubscription(
4235
+ (licence) => licence?.licenceType && ((0, import_dayjs5.default)(licence.expiryDate).isAfter(now) || isProtectedByCurrentStripeSubscription(
4144
4236
  owner,
4145
4237
  licence.licenceType,
4146
4238
  now
@@ -4150,7 +4242,7 @@ async function vendorOwnerHasProLicence(vendorId) {
4150
4242
  effectiveVendorLicences,
4151
4243
  "vendor" /* VENDOR */
4152
4244
  );
4153
- return highestVendorLicence !== null && licencePriority[highestVendorLicence] >= licencePriority[import_cluemart_shared31.EnumUserLicence.PRO_VENDOR];
4245
+ return highestVendorLicence !== null && licencePriority[highestVendorLicence] >= licencePriority[import_cluemart_shared32.EnumUserLicence.PRO_VENDOR];
4154
4246
  }
4155
4247
 
4156
4248
  // src/service/license/compliance/utils.ts
@@ -4160,12 +4252,12 @@ async function syncUserLicencesAfterExpiry(userId, licenceTypes, now, mode = "do
4160
4252
  const pipeline = buildLicenceExpiryPipeline({
4161
4253
  downgradeBranches: [
4162
4254
  {
4163
- case: import_cluemart_shared32.EnumUserLicence.PRO_PLUS_VENDOR,
4164
- then: import_cluemart_shared32.EnumUserLicence.STANDARD_VENDOR
4255
+ case: import_cluemart_shared33.EnumUserLicence.PRO_PLUS_VENDOR,
4256
+ then: import_cluemart_shared33.EnumUserLicence.STANDARD_VENDOR
4165
4257
  },
4166
4258
  {
4167
- case: import_cluemart_shared32.EnumUserLicence.PRO_VENDOR,
4168
- then: import_cluemart_shared32.EnumUserLicence.STANDARD_VENDOR
4259
+ case: import_cluemart_shared33.EnumUserLicence.PRO_VENDOR,
4260
+ then: import_cluemart_shared33.EnumUserLicence.STANDARD_VENDOR
4169
4261
  }
4170
4262
  ],
4171
4263
  licenceTypes,
@@ -4177,7 +4269,7 @@ async function syncUserLicencesAfterExpiry(userId, licenceTypes, now, mode = "do
4177
4269
  }
4178
4270
  function hasValidLicence(licences, licenceTypes, now) {
4179
4271
  return licences.some(
4180
- (licence) => licenceTypes.includes(licence.licenceType) && (0, import_dayjs5.default)(licence.expiryDate).isAfter(now)
4272
+ (licence) => licenceTypes.includes(licence.licenceType) && (0, import_dayjs6.default)(licence.expiryDate).isAfter(now)
4181
4273
  );
4182
4274
  }
4183
4275
  async function sendDeactivationNotification(payload, userId, resourceName, resourceType) {
@@ -4204,7 +4296,7 @@ async function processUserCompliance(user, now) {
4204
4296
  }
4205
4297
 
4206
4298
  // src/service/license/compliance/ensureUserLicenseCompliance.ts
4207
- async function ensureUserLicenseComplianceForUser(userId, now = (0, import_dayjs6.default)()) {
4299
+ async function ensureUserLicenseComplianceForUser(userId, now = (0, import_dayjs7.default)()) {
4208
4300
  const user = await UserModel.findById(userId);
4209
4301
  if (!user) {
4210
4302
  return;
@@ -4212,7 +4304,7 @@ async function ensureUserLicenseComplianceForUser(userId, now = (0, import_dayjs
4212
4304
  await processUserCompliance(user, now);
4213
4305
  }
4214
4306
  async function ensureUserLicenseCompliance() {
4215
- const now = (0, import_dayjs6.default)();
4307
+ const now = (0, import_dayjs7.default)();
4216
4308
  console.log(`\u{1F50D} Checking license compliance at ${now.format()}`);
4217
4309
  const nowDate = now.toDate();
4218
4310
  const users = await UserModel.find({
@@ -4287,16 +4379,16 @@ async function getPartnerResourceInfo(userId, partnerId) {
4287
4379
  }
4288
4380
 
4289
4381
  // src/service/license/reminder/remindUsersAboutLicenseExpiration.ts
4290
- var import_dayjs8 = __toESM(require("dayjs"));
4382
+ var import_dayjs9 = __toESM(require("dayjs"));
4291
4383
 
4292
4384
  // src/service/license/reminder/reminderWindow.ts
4293
4385
  var REMINDER_WINDOW_MIN_HOURS = 6.5 * 24;
4294
4386
  var REMINDER_WINDOW_MAX_HOURS = 7.5 * 24;
4295
4387
 
4296
4388
  // src/service/license/reminder/utils.ts
4297
- var import_cluemart_shared33 = require("@timardex/cluemart-shared");
4389
+ var import_cluemart_shared34 = require("@timardex/cluemart-shared");
4298
4390
  var import_utils8 = require("@timardex/cluemart-shared/utils");
4299
- var import_dayjs7 = __toESM(require("dayjs"));
4391
+ var import_dayjs8 = __toESM(require("dayjs"));
4300
4392
 
4301
4393
  // src/service/license/reminder/vendor.ts
4302
4394
  async function getVendorResourceInfo(userId, vendorId) {
@@ -4355,33 +4447,33 @@ async function checkAndCreateNotification(payload) {
4355
4447
  }
4356
4448
  }
4357
4449
  function isLicenseExpiringIn7Days(expiryDate, now) {
4358
- const expiry = (0, import_dayjs7.default)(expiryDate);
4450
+ const expiry = (0, import_dayjs8.default)(expiryDate);
4359
4451
  const hoursUntilExpiry = expiry.diff(now, "hour", true);
4360
4452
  return hoursUntilExpiry >= REMINDER_WINDOW_MIN_HOURS && hoursUntilExpiry <= REMINDER_WINDOW_MAX_HOURS;
4361
4453
  }
4362
4454
  function getLicenseName(licenceType) {
4363
- return import_cluemart_shared33.licenseNiceNames[licenceType] || licenceType;
4455
+ return import_cluemart_shared34.licenseNiceNames[licenceType] || licenceType;
4364
4456
  }
4365
4457
  function getNotificationTypes(isVendorLicense, isPartnerLicense) {
4366
4458
  if (isVendorLicense) {
4367
4459
  return {
4368
- notificationType: import_cluemart_shared33.EnumNotificationType.SYSTEM,
4369
- resourceType: import_cluemart_shared33.EnumNotificationResourceType.EXPIRATION_REMINDER_VENDOR
4460
+ notificationType: import_cluemart_shared34.EnumNotificationType.SYSTEM,
4461
+ resourceType: import_cluemart_shared34.EnumNotificationResourceType.EXPIRATION_REMINDER_VENDOR
4370
4462
  };
4371
4463
  }
4372
4464
  if (isPartnerLicense) {
4373
4465
  return {
4374
- notificationType: import_cluemart_shared33.EnumNotificationType.SYSTEM,
4375
- resourceType: import_cluemart_shared33.EnumNotificationResourceType.EXPIRATION_REMINDER_PARTNER
4466
+ notificationType: import_cluemart_shared34.EnumNotificationType.SYSTEM,
4467
+ resourceType: import_cluemart_shared34.EnumNotificationResourceType.EXPIRATION_REMINDER_PARTNER
4376
4468
  };
4377
4469
  }
4378
4470
  return {
4379
- notificationType: import_cluemart_shared33.EnumNotificationType.SYSTEM,
4380
- resourceType: import_cluemart_shared33.EnumNotificationResourceType.EXPIRATION_REMINDER_EVENT
4471
+ notificationType: import_cluemart_shared34.EnumNotificationType.SYSTEM,
4472
+ resourceType: import_cluemart_shared34.EnumNotificationResourceType.EXPIRATION_REMINDER_EVENT
4381
4473
  };
4382
4474
  }
4383
4475
  async function getLicenseResourceInfo(user, licence) {
4384
- const isVendorLicense = import_cluemart_shared33.vendorLicences.includes(licence.licenceType);
4476
+ const isVendorLicense = import_cluemart_shared34.vendorLicences.includes(licence.licenceType);
4385
4477
  const isPartnerLicense = partnerLicences.includes(licence.licenceType);
4386
4478
  const licenceName = getLicenseName(licence.licenceType);
4387
4479
  const { notificationType, resourceType } = getNotificationTypes(
@@ -4429,11 +4521,11 @@ async function getLicenseResourceInfo(user, licence) {
4429
4521
  };
4430
4522
  }
4431
4523
  function getLicenceExpiryMode(licenceType) {
4432
- return licenceType === import_cluemart_shared33.EnumUserLicence.PRO_VENDOR || licenceType === import_cluemart_shared33.EnumUserLicence.PRO_PLUS_VENDOR ? "downgrade" : "extend";
4524
+ return licenceType === import_cluemart_shared34.EnumUserLicence.PRO_VENDOR || licenceType === import_cluemart_shared34.EnumUserLicence.PRO_PLUS_VENDOR ? "downgrade" : "extend";
4433
4525
  }
4434
4526
  async function sendLicenseReminder(user, licence) {
4435
4527
  const licenceName = getLicenseName(licence.licenceType);
4436
- const expiryDate = (0, import_dayjs7.default)(licence.expiryDate).format(import_cluemart_shared33.dateFormat);
4528
+ const expiryDate = (0, import_dayjs8.default)(licence.expiryDate).format(import_cluemart_shared34.dateFormat);
4437
4529
  const userId = String(user._id);
4438
4530
  const resourceInfo = await getLicenseResourceInfo(user, licence);
4439
4531
  if (!resourceInfo) {
@@ -4465,7 +4557,7 @@ async function sendLicenseReminder(user, licence) {
4465
4557
  console.log(`\u2705 Sent 7-day reminder to user ${userId} for ${licenceName}`);
4466
4558
  }
4467
4559
  async function processLicenseReminder(licence, now) {
4468
- if ((0, import_dayjs7.default)(licence.expiryDate).isBefore(now)) {
4560
+ if ((0, import_dayjs8.default)(licence.expiryDate).isBefore(now)) {
4469
4561
  return false;
4470
4562
  }
4471
4563
  if (!isLicenseExpiringIn7Days(licence.expiryDate, now)) {
@@ -4519,7 +4611,7 @@ async function processUserLicenseReminders(user, now) {
4519
4611
 
4520
4612
  // src/service/license/reminder/remindUsersAboutLicenseExpiration.ts
4521
4613
  async function remindUsersAboutLicenseExpiration() {
4522
- const now = (0, import_dayjs8.default)();
4614
+ const now = (0, import_dayjs9.default)();
4523
4615
  console.log(`\u{1F50D} Checking for licenses expiring in 7 days at ${now.format()}`);
4524
4616
  const minExpiryDate = now.add(REMINDER_WINDOW_MIN_HOURS, "hour").toDate();
4525
4617
  const maxExpiryDate = now.add(REMINDER_WINDOW_MAX_HOURS, "hour").toDate();
@@ -4582,6 +4674,8 @@ async function remindUsersAboutLicenseExpiration() {
4582
4674
  EventModel,
4583
4675
  GameModel,
4584
4676
  GoogleImportedMarketModel,
4677
+ ImpersonationAuditModel,
4678
+ ImpersonationSessionModel,
4585
4679
  LicenceCategory,
4586
4680
  NotificationModel,
4587
4681
  OwnerTypeSchema,