@timardex/cluemart-server-shared 2.2.0 → 2.2.2

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: () => updateSingleDateTimeStatus,
150
+ updateSingleDateTimeStatus: () => import_cluemart_shared35.updateSingleDateTimeStatus,
149
151
  upgradeUserToLicence: () => upgradeUserToLicence,
150
152
  userLicenseSchema: () => userLicenseSchema,
151
153
  vendorOwnerHasProLicence: () => vendorOwnerHasProLicence,
@@ -1202,16 +1204,24 @@ var GoogleImportedMarketModel = import_mongoose10.default.models.GoogleImportedM
1202
1204
  var import_cluemart_shared9 = require("@timardex/cluemart-shared");
1203
1205
  var import_mongoose11 = __toESM(require("mongoose"));
1204
1206
  var MongooseSchema7 = import_mongoose11.default.Schema;
1207
+ var notificationDataSchema = new MongooseSchema7(
1208
+ {
1209
+ resourceId: { required: true, type: String },
1210
+ resourceName: { required: true, type: String },
1211
+ resourceType: {
1212
+ enum: Object.values(import_cluemart_shared9.EnumNotificationResourceType),
1213
+ required: true,
1214
+ type: String
1215
+ }
1216
+ },
1217
+ { _id: false }
1218
+ );
1205
1219
  var schema8 = new MongooseSchema7(
1206
1220
  {
1207
1221
  data: {
1208
- resourceId: { required: true, type: String },
1209
- resourceName: { required: true, type: String },
1210
- resourceType: {
1211
- enum: Object.values(import_cluemart_shared9.EnumNotificationResourceType),
1212
- required: true,
1213
- type: String
1214
- }
1222
+ default: null,
1223
+ required: false,
1224
+ type: notificationDataSchema
1215
1225
  },
1216
1226
  isRead: { default: false, index: true, required: true, type: Boolean },
1217
1227
  message: { required: true, type: String },
@@ -2591,6 +2601,62 @@ schema24.index({ active: 1, deletedAt: 1, "owner.userId": 1 });
2591
2601
  schema24.index({ "couponData.participantUsers.userId": 1 });
2592
2602
  var CouponModel = import_mongoose32.default.models.Coupon || import_mongoose32.default.model("Coupon", schema24);
2593
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
+
2594
2660
  // src/service/promoCode/constants.ts
2595
2661
  var ACTIVE_NOT_DELETED_FILTER = {
2596
2662
  active: true,
@@ -2607,31 +2673,30 @@ async function activeAffiliateCodeExists(affiliateCode) {
2607
2673
  }
2608
2674
 
2609
2675
  // src/service/affiliate/awardAffiliateVendorSubscriptionRewards.ts
2610
- var import_cluemart_shared23 = require("@timardex/cluemart-shared");
2676
+ var import_cluemart_shared24 = require("@timardex/cluemart-shared");
2611
2677
  var import_utils3 = require("@timardex/cluemart-shared/utils");
2612
2678
 
2613
2679
  // src/service/saveNotificationsInDb.ts
2614
2680
  async function saveNotificationsInDb(payload) {
2615
2681
  const { data, message, title, type, userIds } = payload;
2616
- console.log("NOTIFICATION DATA", JSON.stringify(payload, null, 2));
2682
+ const notifications = userIds.map((userId) => ({
2683
+ data,
2684
+ isRead: false,
2685
+ message,
2686
+ title,
2687
+ type,
2688
+ userId
2689
+ }));
2617
2690
  try {
2618
- const notifications = userIds.map((userId) => ({
2619
- data,
2620
- isRead: false,
2621
- message,
2622
- title,
2623
- type,
2624
- userId
2625
- }));
2626
2691
  await NotificationModel.insertMany(notifications);
2627
- console.log(
2628
- `Created ${notifications.length} notifications for ${userIds.length} users`
2629
- );
2630
- return [...new Set(userIds)];
2631
2692
  } catch (error) {
2632
2693
  console.error("Failed to create notifications:", error);
2633
- return [];
2694
+ throw error;
2634
2695
  }
2696
+ console.log(
2697
+ `Created ${notifications.length} notifications for ${userIds.length} users`
2698
+ );
2699
+ return [...new Set(userIds)];
2635
2700
  }
2636
2701
 
2637
2702
  // src/service/sendPushNotifications.ts
@@ -2655,7 +2720,7 @@ function createPushMessages({
2655
2720
  }
2656
2721
  messages.push({
2657
2722
  body: message,
2658
- data: { ...data },
2723
+ ...data ? { data: { ...data } } : {},
2659
2724
  sound: "tui.wav",
2660
2725
  title,
2661
2726
  to: token
@@ -2710,7 +2775,6 @@ async function sendPushNotifications({
2710
2775
  }) {
2711
2776
  const pushTokens = await PushTokenModel.find({ userId: { $in: userIds } });
2712
2777
  const expoTokens = pushTokens.map((token) => token.token);
2713
- if (!data) return;
2714
2778
  const { messages, invalidTokens } = createPushMessages({
2715
2779
  data,
2716
2780
  message,
@@ -2744,7 +2808,7 @@ async function sendPushNotifications({
2744
2808
  }
2745
2809
 
2746
2810
  // src/service/affiliate/vendorSubscriptionRewards.ts
2747
- var import_cluemart_shared22 = require("@timardex/cluemart-shared");
2811
+ var import_cluemart_shared23 = require("@timardex/cluemart-shared");
2748
2812
  var import_dayjs = __toESM(require("dayjs"));
2749
2813
  var import_timezone = __toESM(require("dayjs/plugin/timezone"));
2750
2814
  var import_utc = __toESM(require("dayjs/plugin/utc"));
@@ -2802,14 +2866,14 @@ import_dayjs.default.extend(import_timezone.default);
2802
2866
  var SUBSCRIPTION_REWARD_TIMEZONE = "Pacific/Auckland";
2803
2867
  async function mapVendorLicenceToSubscriptionRewardType(userId, now = /* @__PURE__ */ new Date()) {
2804
2868
  const { hasSubscription, validTypes } = await getPayingVendorStripeSubscriptionPlan(userId, now);
2805
- 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)) {
2806
2870
  if (hasSubscription) {
2807
- return import_cluemart_shared22.EnumAffiliateRewardType.ACTIVE_VENDOR_PRO_SUBSCRIPTION;
2871
+ return import_cluemart_shared23.EnumAffiliateRewardType.ACTIVE_VENDOR_PRO_SUBSCRIPTION;
2808
2872
  }
2809
- return import_cluemart_shared22.EnumAffiliateRewardType.ACTIVE_VENDOR_STANDARD_SUBSCRIPTION;
2873
+ return import_cluemart_shared23.EnumAffiliateRewardType.ACTIVE_VENDOR_STANDARD_SUBSCRIPTION;
2810
2874
  }
2811
- if (validTypes.has(import_cluemart_shared22.EnumUserLicence.STANDARD_VENDOR)) {
2812
- 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;
2813
2877
  }
2814
2878
  return null;
2815
2879
  }
@@ -2821,7 +2885,7 @@ function getSubscriptionRewardPeriodBounds(now = /* @__PURE__ */ new Date()) {
2821
2885
 
2822
2886
  // src/service/affiliate/awardAffiliateVendorSubscriptionRewards.ts
2823
2887
  function isEligibleVendorResource(resource) {
2824
- 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;
2825
2889
  }
2826
2890
  async function findAffiliatesWithActiveVendorReferrals() {
2827
2891
  return await AffiliateModel.find({
@@ -2830,7 +2894,7 @@ async function findAffiliatesWithActiveVendorReferrals() {
2830
2894
  $elemMatch: {
2831
2895
  resourceActive: true,
2832
2896
  resourceDeletedAt: null,
2833
- resourceType: import_cluemart_shared23.EnumResourceType.VENDOR
2897
+ resourceType: import_cluemart_shared24.EnumResourceType.VENDOR
2834
2898
  }
2835
2899
  },
2836
2900
  deletedAt: null
@@ -2864,11 +2928,11 @@ async function notifyAffiliateOwnerOfSubscriptionReward({
2864
2928
  data: {
2865
2929
  resourceId: String(affiliateId),
2866
2930
  resourceName: resourceNames.join(", "),
2867
- resourceType: import_cluemart_shared23.EnumNotificationResourceType.AFFILIATE_REWARD_RECEIVED
2931
+ resourceType: import_cluemart_shared24.EnumNotificationResourceType.AFFILIATE_REWARD_RECEIVED
2868
2932
  },
2869
2933
  message,
2870
2934
  title: "Affiliate points earned",
2871
- type: import_cluemart_shared23.EnumNotificationType.SYSTEM,
2935
+ type: import_cluemart_shared24.EnumNotificationType.SYSTEM,
2872
2936
  userIds: [affiliateOwnerUserId]
2873
2937
  };
2874
2938
  try {
@@ -2897,7 +2961,7 @@ async function tryAwardSubscriptionReward({
2897
2961
  resourceActive: true,
2898
2962
  resourceDeletedAt: null,
2899
2963
  resourceId: resource.resourceId,
2900
- resourceType: import_cluemart_shared23.EnumResourceType.VENDOR,
2964
+ resourceType: import_cluemart_shared24.EnumResourceType.VENDOR,
2901
2965
  rewards: {
2902
2966
  $not: {
2903
2967
  $elemMatch: {
@@ -3018,7 +3082,7 @@ function normalizeAffiliatePromoCodes(promoCodes) {
3018
3082
  }
3019
3083
 
3020
3084
  // src/service/database.ts
3021
- var import_mongoose36 = __toESM(require("mongoose"));
3085
+ var import_mongoose37 = __toESM(require("mongoose"));
3022
3086
  var connectToDatabase = async ({
3023
3087
  appName,
3024
3088
  dbName,
@@ -3031,7 +3095,7 @@ var connectToDatabase = async ({
3031
3095
  // Fallback to MongoDB Atlas connection string
3032
3096
  `mongodb+srv://${dbUser}:${dbPassword}@${dbName}.mongodb.net/?retryWrites=true&w=majority&appName=${appName}`
3033
3097
  );
3034
- await import_mongoose36.default.connect(mongoUri);
3098
+ await import_mongoose37.default.connect(mongoUri);
3035
3099
  const connectionType = mongodbUri ? "Local MongoDB" : "MongoDB Atlas";
3036
3100
  console.log(
3037
3101
  `${connectionType} connected from server/src/service/database.ts`
@@ -3044,7 +3108,7 @@ var connectToDatabase = async ({
3044
3108
 
3045
3109
  // src/types/index.ts
3046
3110
  var import_express = __toESM(require("express"));
3047
- var import_mongoose37 = __toESM(require("mongoose"));
3111
+ var import_mongoose38 = __toESM(require("mongoose"));
3048
3112
  var EnumPubSubEvents = /* @__PURE__ */ ((EnumPubSubEvents2) => {
3049
3113
  EnumPubSubEvents2["GET_CHAT_MESSAGE"] = "GET_CHAT_MESSAGE";
3050
3114
  EnumPubSubEvents2["GET_NOTIFICATIONS"] = "GET_NOTIFICATIONS";
@@ -3099,7 +3163,7 @@ async function notifyUsers({
3099
3163
  }
3100
3164
 
3101
3165
  // src/service/updateAdStatus.ts
3102
- var import_cluemart_shared24 = require("@timardex/cluemart-shared");
3166
+ var import_cluemart_shared25 = require("@timardex/cluemart-shared");
3103
3167
  async function updateAdStatuses() {
3104
3168
  const now = /* @__PURE__ */ new Date();
3105
3169
  const invalidResult = await AdModel.updateMany(
@@ -3109,50 +3173,50 @@ async function updateAdStatuses() {
3109
3173
  { end: { $exists: false } },
3110
3174
  { $expr: { $gt: ["$start", "$end"] } }
3111
3175
  ],
3112
- status: { $ne: import_cluemart_shared24.EnumAdStatus.PAUSED }
3176
+ status: { $ne: import_cluemart_shared25.EnumAdStatus.PAUSED }
3113
3177
  },
3114
- { $set: { status: import_cluemart_shared24.EnumAdStatus.PAUSED } }
3178
+ { $set: { status: import_cluemart_shared25.EnumAdStatus.PAUSED } }
3115
3179
  );
3116
3180
  const expiredResult = await AdModel.updateMany(
3117
- { end: { $lte: now }, status: { $ne: import_cluemart_shared24.EnumAdStatus.EXPIRED } },
3118
- { $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 } }
3119
3183
  );
3120
3184
  const eligibleBooking = {
3121
3185
  $or: [
3122
3186
  { bookingKind: { $exists: false } },
3123
3187
  { bookingKind: null },
3124
3188
  {
3125
- approvalStatus: import_cluemart_shared24.EnumAdApprovalStatus.APPROVED,
3126
- bookingKind: import_cluemart_shared24.EnumAdBookingSlotKind.RESERVED
3189
+ approvalStatus: import_cluemart_shared25.EnumAdApprovalStatus.APPROVED,
3190
+ bookingKind: import_cluemart_shared25.EnumAdBookingSlotKind.RESERVED
3127
3191
  },
3128
3192
  {
3129
- approvalStatus: import_cluemart_shared24.EnumAdApprovalStatus.APPROVED,
3130
- bookingKind: import_cluemart_shared24.EnumAdBookingSlotKind.PAID,
3131
- 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
3132
3196
  }
3133
3197
  ]
3134
3198
  };
3135
3199
  const awaitingApprovalResult = await AdModel.updateMany(
3136
3200
  {
3137
3201
  $nor: eligibleBooking.$or,
3138
- bookingKind: { $in: Object.values(import_cluemart_shared24.EnumAdBookingSlotKind) },
3202
+ bookingKind: { $in: Object.values(import_cluemart_shared25.EnumAdBookingSlotKind) },
3139
3203
  end: { $gt: now },
3140
- status: import_cluemart_shared24.EnumAdStatus.ACTIVE
3204
+ status: import_cluemart_shared25.EnumAdStatus.ACTIVE
3141
3205
  },
3142
- { $set: { status: import_cluemart_shared24.EnumAdStatus.PAUSED } }
3206
+ { $set: { status: import_cluemart_shared25.EnumAdStatus.PAUSED } }
3143
3207
  );
3144
3208
  const activeResult = await AdModel.updateMany(
3145
3209
  {
3146
3210
  end: { $gt: now },
3147
3211
  start: { $lte: now },
3148
- status: { $ne: import_cluemart_shared24.EnumAdStatus.ACTIVE },
3212
+ status: { $ne: import_cluemart_shared25.EnumAdStatus.ACTIVE },
3149
3213
  ...eligibleBooking
3150
3214
  },
3151
- { $set: { status: import_cluemart_shared24.EnumAdStatus.ACTIVE } }
3215
+ { $set: { status: import_cluemart_shared25.EnumAdStatus.ACTIVE } }
3152
3216
  );
3153
3217
  const pausedResult = await AdModel.updateMany(
3154
- { start: { $gt: now }, status: { $ne: import_cluemart_shared24.EnumAdStatus.PAUSED } },
3155
- { $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 } }
3156
3220
  );
3157
3221
  console.log(
3158
3222
  `\u2705 Ad statuses updated: invalid=${invalidResult.modifiedCount}, expired=${expiredResult.modifiedCount}, awaitingApproval=${awaitingApprovalResult.modifiedCount}, active=${activeResult.modifiedCount}, paused=${pausedResult.modifiedCount}`
@@ -3160,15 +3224,15 @@ async function updateAdStatuses() {
3160
3224
  }
3161
3225
 
3162
3226
  // src/service/objectIdToString.ts
3163
- var import_mongoose39 = __toESM(require("mongoose"));
3227
+ var import_mongoose40 = __toESM(require("mongoose"));
3164
3228
  function isValidObjectId(value) {
3165
- return import_mongoose39.default.Types.ObjectId.isValid(value);
3229
+ return import_mongoose40.default.Types.ObjectId.isValid(value);
3166
3230
  }
3167
3231
  function convertObjectIdsToStrings(obj) {
3168
3232
  if (obj === null || obj === void 0) {
3169
3233
  return obj;
3170
3234
  }
3171
- if (obj instanceof import_mongoose39.default.Types.ObjectId) {
3235
+ if (obj instanceof import_mongoose40.default.Types.ObjectId) {
3172
3236
  return obj.toString();
3173
3237
  }
3174
3238
  if (obj instanceof Date) {
@@ -3188,18 +3252,16 @@ function convertObjectIdsToStrings(obj) {
3188
3252
  }
3189
3253
 
3190
3254
  // src/service/event/updateAllEventDateTimeStatuses.ts
3191
- var import_cluemart_shared26 = require("@timardex/cluemart-shared");
3255
+ var import_cluemart_shared27 = require("@timardex/cluemart-shared");
3192
3256
  var import_dayjs2 = __toESM(require("dayjs"));
3193
- var import_customParseFormat = __toESM(require("dayjs/plugin/customParseFormat"));
3194
- var import_isoWeek = __toESM(require("dayjs/plugin/isoWeek"));
3195
3257
 
3196
3258
  // src/service/event/archiveEndedEventDates.ts
3197
- var import_cluemart_shared25 = require("@timardex/cluemart-shared");
3259
+ var import_cluemart_shared26 = require("@timardex/cluemart-shared");
3198
3260
  var ARCHIVED_STATUSES = /* @__PURE__ */ new Set([
3199
- import_cluemart_shared25.EnumEventDateStatus.ENDED
3261
+ import_cluemart_shared26.EnumEventDateStatus.ENDED
3200
3262
  ]);
3201
3263
  var DISCARDED_STATUSES = /* @__PURE__ */ new Set([
3202
- import_cluemart_shared25.EnumEventDateStatus.INVALID
3264
+ import_cluemart_shared26.EnumEventDateStatus.INVALID
3203
3265
  ]);
3204
3266
  function splitEventDatesForArchive(dateTime) {
3205
3267
  return {
@@ -3234,73 +3296,6 @@ async function persistArchivedEventDates(eventId, slots) {
3234
3296
  }
3235
3297
 
3236
3298
  // src/service/event/updateAllEventDateTimeStatuses.ts
3237
- import_dayjs2.default.extend(import_customParseFormat.default);
3238
- import_dayjs2.default.extend(import_isoWeek.default);
3239
- var MANUAL_DATE_STATUSES = /* @__PURE__ */ new Set([
3240
- import_cluemart_shared26.EnumEventDateStatus.CANCELED,
3241
- import_cluemart_shared26.EnumEventDateStatus.RE_SCHEDULED
3242
- ]);
3243
- function getFutureEventStatus(startDateTime, now) {
3244
- const hoursUntilStart = startDateTime.diff(now, "hour", true);
3245
- if (hoursUntilStart > 0 && hoursUntilStart <= 4) {
3246
- return import_cluemart_shared26.EnumEventDateStatus.STARTING_SOON;
3247
- }
3248
- if (startDateTime.isSame(now, "day")) {
3249
- return import_cluemart_shared26.EnumEventDateStatus.TODAY;
3250
- }
3251
- if (startDateTime.isSame(now.add(1, "day"), "day")) {
3252
- return import_cluemart_shared26.EnumEventDateStatus.TOMORROW;
3253
- }
3254
- if (startDateTime.isSame(now, "isoWeek")) {
3255
- return import_cluemart_shared26.EnumEventDateStatus.THIS_WEEK;
3256
- }
3257
- if (startDateTime.isSame(now.add(1, "week"), "isoWeek")) {
3258
- return import_cluemart_shared26.EnumEventDateStatus.NEXT_WEEK;
3259
- }
3260
- return import_cluemart_shared26.EnumEventDateStatus.UPCOMING;
3261
- }
3262
- function updateSingleDateTimeStatus(dateTime, now = (0, import_dayjs2.default)()) {
3263
- if (MANUAL_DATE_STATUSES.has(dateTime.dateStatus)) {
3264
- return dateTime;
3265
- }
3266
- const dateTimeFormat = `${import_cluemart_shared26.dateFormat} ${import_cluemart_shared26.timeFormat}`;
3267
- const startDateTime = (0, import_dayjs2.default)(
3268
- `${dateTime.startDate} ${dateTime.startTime}`,
3269
- dateTimeFormat,
3270
- true
3271
- );
3272
- const endDateTime = (0, import_dayjs2.default)(
3273
- `${dateTime.endDate} ${dateTime.endTime}`,
3274
- dateTimeFormat,
3275
- true
3276
- );
3277
- if (!startDateTime.isValid() || !endDateTime.isValid()) {
3278
- return {
3279
- ...dateTime,
3280
- dateStatus: import_cluemart_shared26.EnumEventDateStatus.INVALID
3281
- };
3282
- }
3283
- if (endDateTime.isBefore(startDateTime)) {
3284
- return {
3285
- ...dateTime,
3286
- dateStatus: import_cluemart_shared26.EnumEventDateStatus.INVALID
3287
- };
3288
- }
3289
- let dateStatus;
3290
- if (endDateTime.isAfter(now)) {
3291
- if (startDateTime.isAfter(now)) {
3292
- dateStatus = getFutureEventStatus(startDateTime, now);
3293
- } else {
3294
- dateStatus = import_cluemart_shared26.EnumEventDateStatus.STARTED;
3295
- }
3296
- } else {
3297
- dateStatus = import_cluemart_shared26.EnumEventDateStatus.ENDED;
3298
- }
3299
- return {
3300
- ...dateTime,
3301
- dateStatus
3302
- };
3303
- }
3304
3299
  var dateTimeStatusFilter = {
3305
3300
  dateTime: { $ne: [], $type: "array" },
3306
3301
  deletedAt: null
@@ -3329,7 +3324,7 @@ async function updateModelDateTimeStatuses(model, now) {
3329
3324
  try {
3330
3325
  for await (const doc of cursor) {
3331
3326
  const dateTime = doc.dateTime.map(
3332
- (slot) => updateSingleDateTimeStatus(slot, now)
3327
+ (slot) => (0, import_cluemart_shared27.updateSingleDateTimeStatus)(slot, now)
3333
3328
  );
3334
3329
  if (!hasDateTimeStatusChanges(doc.dateTime, dateTime)) {
3335
3330
  continue;
@@ -3352,7 +3347,7 @@ async function updateModelDateTimeStatuses(model, now) {
3352
3347
  }
3353
3348
  var ARCHIVABLE_EVENT_FILTER = {
3354
3349
  "dateTime.dateStatus": {
3355
- $in: [import_cluemart_shared26.EnumEventDateStatus.ENDED, import_cluemart_shared26.EnumEventDateStatus.INVALID]
3350
+ $in: [import_cluemart_shared27.EnumEventDateStatus.ENDED, import_cluemart_shared27.EnumEventDateStatus.INVALID]
3356
3351
  },
3357
3352
  deletedAt: null
3358
3353
  };
@@ -3374,7 +3369,7 @@ async function archiveEndedAndDiscardInvalidEventDates(now) {
3374
3369
  try {
3375
3370
  for await (const doc of cursor) {
3376
3371
  const updated = doc.dateTime.map(
3377
- (slot) => updateSingleDateTimeStatus(slot, now)
3372
+ (slot) => (0, import_cluemart_shared27.updateSingleDateTimeStatus)(slot, now)
3378
3373
  );
3379
3374
  const { archive, discard } = splitEventDatesForArchive(updated);
3380
3375
  if (archive.length === 0 && discard.length === 0) {
@@ -3398,7 +3393,7 @@ async function archiveEndedAndDiscardInvalidEventDates(now) {
3398
3393
  $pull: {
3399
3394
  dateTime: {
3400
3395
  dateStatus: {
3401
- $in: [import_cluemart_shared26.EnumEventDateStatus.ENDED, import_cluemart_shared26.EnumEventDateStatus.INVALID]
3396
+ $in: [import_cluemart_shared27.EnumEventDateStatus.ENDED, import_cluemart_shared27.EnumEventDateStatus.INVALID]
3402
3397
  }
3403
3398
  }
3404
3399
  }
@@ -3432,9 +3427,9 @@ async function cleanEventInfoDates(now) {
3432
3427
  try {
3433
3428
  for await (const doc of cursor) {
3434
3429
  const updated = doc.dateTime.map(
3435
- (slot) => updateSingleDateTimeStatus(slot, now)
3430
+ (slot) => (0, import_cluemart_shared27.updateSingleDateTimeStatus)(slot, now)
3436
3431
  );
3437
- const kept = (0, import_cluemart_shared26.filterDatesByFutureStatus)(updated);
3432
+ const kept = (0, import_cluemart_shared27.filterDatesByFutureStatus)(updated);
3438
3433
  if (kept.length === updated.length) {
3439
3434
  continue;
3440
3435
  }
@@ -3479,6 +3474,9 @@ async function updateAllEventDateTimeStatuses() {
3479
3474
  }
3480
3475
  }
3481
3476
 
3477
+ // src/service/index.ts
3478
+ var import_cluemart_shared35 = require("@timardex/cluemart-shared");
3479
+
3482
3480
  // src/service/event/findEventOrImportedMarketById.ts
3483
3481
  async function findEventOrImportedMarketById(resourceId) {
3484
3482
  if (!resourceId) {
@@ -3493,7 +3491,7 @@ async function findEventOrImportedMarketById(resourceId) {
3493
3491
  }
3494
3492
 
3495
3493
  // src/service/relations.ts
3496
- var import_cluemart_shared27 = require("@timardex/cluemart-shared");
3494
+ var import_cluemart_shared28 = require("@timardex/cluemart-shared");
3497
3495
  function didRemoveAnyEventDates(previousDateTime, nextDateTime) {
3498
3496
  if (!previousDateTime?.length) {
3499
3497
  return false;
@@ -3511,7 +3509,7 @@ function updateRelationDatesToUnavailable(relationDates, eventDateTime) {
3511
3509
  ) ?? false;
3512
3510
  return {
3513
3511
  ...relationDate,
3514
- status: existsInEvent ? relationDate.status : import_cluemart_shared27.EnumInviteStatus.UNAVAILABLE
3512
+ status: existsInEvent ? relationDate.status : import_cluemart_shared28.EnumInviteStatus.UNAVAILABLE
3515
3513
  };
3516
3514
  });
3517
3515
  }
@@ -3520,15 +3518,15 @@ function updateRelationDatesToUnavailable(relationDates, eventDateTime) {
3520
3518
  var import_dayjs6 = __toESM(require("dayjs"));
3521
3519
 
3522
3520
  // src/service/license/compliance/utils.ts
3523
- var import_cluemart_shared32 = require("@timardex/cluemart-shared");
3521
+ var import_cluemart_shared33 = require("@timardex/cluemart-shared");
3524
3522
  var import_dayjs5 = __toESM(require("dayjs"));
3525
3523
 
3526
3524
  // src/service/license/compliance/event.ts
3527
- var import_cluemart_shared28 = require("@timardex/cluemart-shared");
3525
+ var import_cluemart_shared29 = require("@timardex/cluemart-shared");
3528
3526
  var eventLicences = [
3529
- import_cluemart_shared28.EnumUserLicence.STANDARD_EVENT,
3530
- import_cluemart_shared28.EnumUserLicence.PRO_EVENT,
3531
- import_cluemart_shared28.EnumUserLicence.PRO_PLUS_EVENT
3527
+ import_cluemart_shared29.EnumUserLicence.STANDARD_EVENT,
3528
+ import_cluemart_shared29.EnumUserLicence.PRO_EVENT,
3529
+ import_cluemart_shared29.EnumUserLicence.PRO_PLUS_EVENT
3532
3530
  ];
3533
3531
  async function handleEventLicenceCompliance(user, now) {
3534
3532
  if (!user.licences || !user.events?.length) {
@@ -3740,9 +3738,9 @@ function buildLicenceExpiryPipeline(params) {
3740
3738
  }
3741
3739
 
3742
3740
  // src/service/license/compliance/partner.ts
3743
- var import_cluemart_shared29 = require("@timardex/cluemart-shared");
3741
+ var import_cluemart_shared30 = require("@timardex/cluemart-shared");
3744
3742
  var partnerLicences = [
3745
- import_cluemart_shared29.EnumUserLicence.STANDARD_PARTNER
3743
+ import_cluemart_shared30.EnumUserLicence.STANDARD_PARTNER
3746
3744
  ];
3747
3745
  async function handlePartnerLicenceCompliance(user, now) {
3748
3746
  if (!user.licences || !user.partner) {
@@ -3752,11 +3750,11 @@ async function handlePartnerLicenceCompliance(user, now) {
3752
3750
  }
3753
3751
 
3754
3752
  // src/service/license/compliance/vendor.ts
3755
- var import_cluemart_shared31 = require("@timardex/cluemart-shared");
3753
+ var import_cluemart_shared32 = require("@timardex/cluemart-shared");
3756
3754
  var import_dayjs4 = __toESM(require("dayjs"));
3757
3755
 
3758
3756
  // src/service/license/models.ts
3759
- var import_cluemart_shared30 = require("@timardex/cluemart-shared");
3757
+ var import_cluemart_shared31 = require("@timardex/cluemart-shared");
3760
3758
  var import_dayjs3 = __toESM(require("dayjs"));
3761
3759
  var import_graphql = require("graphql");
3762
3760
  var LicenceCategory = /* @__PURE__ */ ((LicenceCategory2) => {
@@ -3768,31 +3766,31 @@ var LicenceCategory = /* @__PURE__ */ ((LicenceCategory2) => {
3768
3766
  return LicenceCategory2;
3769
3767
  })(LicenceCategory || {});
3770
3768
  var licenceCategoryMapping = {
3771
- [import_cluemart_shared30.EnumUserLicence.PRO_EVENT]: "event" /* EVENT */,
3772
- [import_cluemart_shared30.EnumUserLicence.PRO_PLUS_EVENT]: "event" /* EVENT */,
3773
- [import_cluemart_shared30.EnumUserLicence.PRO_PLUS_VENDOR]: "vendor" /* VENDOR */,
3774
- [import_cluemart_shared30.EnumUserLicence.PRO_VENDOR]: "vendor" /* VENDOR */,
3775
- [import_cluemart_shared30.EnumUserLicence.STANDARD_EVENT]: "event" /* EVENT */,
3776
- [import_cluemart_shared30.EnumUserLicence.STANDARD_PARTNER]: "partner" /* PARTNER */,
3777
- [import_cluemart_shared30.EnumUserLicence.STANDARD_VENDOR]: "vendor" /* VENDOR */,
3778
- [import_cluemart_shared30.EnumUserLicence.STANDARD_AFFILIATE]: "affiliate" /* AFFILIATE */,
3779
- [import_cluemart_shared30.EnumUserLicence.STANDARD_SCHOOL]: "school" /* SCHOOL */
3769
+ [import_cluemart_shared31.EnumUserLicence.PRO_EVENT]: "event" /* EVENT */,
3770
+ [import_cluemart_shared31.EnumUserLicence.PRO_PLUS_EVENT]: "event" /* EVENT */,
3771
+ [import_cluemart_shared31.EnumUserLicence.PRO_PLUS_VENDOR]: "vendor" /* VENDOR */,
3772
+ [import_cluemart_shared31.EnumUserLicence.PRO_VENDOR]: "vendor" /* VENDOR */,
3773
+ [import_cluemart_shared31.EnumUserLicence.STANDARD_EVENT]: "event" /* EVENT */,
3774
+ [import_cluemart_shared31.EnumUserLicence.STANDARD_PARTNER]: "partner" /* PARTNER */,
3775
+ [import_cluemart_shared31.EnumUserLicence.STANDARD_VENDOR]: "vendor" /* VENDOR */,
3776
+ [import_cluemart_shared31.EnumUserLicence.STANDARD_AFFILIATE]: "affiliate" /* AFFILIATE */,
3777
+ [import_cluemart_shared31.EnumUserLicence.STANDARD_SCHOOL]: "school" /* SCHOOL */
3780
3778
  };
3781
3779
  var licencePriority = {
3782
- [import_cluemart_shared30.EnumUserLicence.PRO_PLUS_EVENT]: 3,
3783
- [import_cluemart_shared30.EnumUserLicence.PRO_EVENT]: 2,
3784
- [import_cluemart_shared30.EnumUserLicence.STANDARD_EVENT]: 1,
3785
- [import_cluemart_shared30.EnumUserLicence.PRO_PLUS_VENDOR]: 3,
3786
- [import_cluemart_shared30.EnumUserLicence.PRO_VENDOR]: 2,
3787
- [import_cluemart_shared30.EnumUserLicence.STANDARD_VENDOR]: 1,
3788
- [import_cluemart_shared30.EnumUserLicence.STANDARD_PARTNER]: 1,
3789
- [import_cluemart_shared30.EnumUserLicence.STANDARD_AFFILIATE]: 1,
3790
- [import_cluemart_shared30.EnumUserLicence.STANDARD_SCHOOL]: 1
3780
+ [import_cluemart_shared31.EnumUserLicence.PRO_PLUS_EVENT]: 3,
3781
+ [import_cluemart_shared31.EnumUserLicence.PRO_EVENT]: 2,
3782
+ [import_cluemart_shared31.EnumUserLicence.STANDARD_EVENT]: 1,
3783
+ [import_cluemart_shared31.EnumUserLicence.PRO_PLUS_VENDOR]: 3,
3784
+ [import_cluemart_shared31.EnumUserLicence.PRO_VENDOR]: 2,
3785
+ [import_cluemart_shared31.EnumUserLicence.STANDARD_VENDOR]: 1,
3786
+ [import_cluemart_shared31.EnumUserLicence.STANDARD_PARTNER]: 1,
3787
+ [import_cluemart_shared31.EnumUserLicence.STANDARD_AFFILIATE]: 1,
3788
+ [import_cluemart_shared31.EnumUserLicence.STANDARD_SCHOOL]: 1
3791
3789
  };
3792
3790
  var standardLicences = [
3793
- import_cluemart_shared30.EnumUserLicence.STANDARD_VENDOR,
3794
- import_cluemart_shared30.EnumUserLicence.STANDARD_EVENT,
3795
- import_cluemart_shared30.EnumUserLicence.STANDARD_PARTNER
3791
+ import_cluemart_shared31.EnumUserLicence.STANDARD_VENDOR,
3792
+ import_cluemart_shared31.EnumUserLicence.STANDARD_EVENT,
3793
+ import_cluemart_shared31.EnumUserLicence.STANDARD_PARTNER
3796
3794
  ];
3797
3795
  var standardLicenceSet = new Set(standardLicences);
3798
3796
  function isStandardLicence(licence) {
@@ -3806,11 +3804,11 @@ var categoryRegexMapping = {
3806
3804
  ["school" /* SCHOOL */]: /_school$/
3807
3805
  };
3808
3806
  var categoryFallbackLicence = {
3809
- ["event" /* EVENT */]: import_cluemart_shared30.EnumUserLicence.STANDARD_EVENT,
3810
- ["partner" /* PARTNER */]: import_cluemart_shared30.EnumUserLicence.STANDARD_PARTNER,
3811
- ["vendor" /* VENDOR */]: import_cluemart_shared30.EnumUserLicence.STANDARD_VENDOR,
3812
- ["affiliate" /* AFFILIATE */]: import_cluemart_shared30.EnumUserLicence.STANDARD_AFFILIATE,
3813
- ["school" /* SCHOOL */]: import_cluemart_shared30.EnumUserLicence.STANDARD_SCHOOL
3807
+ ["event" /* EVENT */]: import_cluemart_shared31.EnumUserLicence.STANDARD_EVENT,
3808
+ ["partner" /* PARTNER */]: import_cluemart_shared31.EnumUserLicence.STANDARD_PARTNER,
3809
+ ["vendor" /* VENDOR */]: import_cluemart_shared31.EnumUserLicence.STANDARD_VENDOR,
3810
+ ["affiliate" /* AFFILIATE */]: import_cluemart_shared31.EnumUserLicence.STANDARD_AFFILIATE,
3811
+ ["school" /* SCHOOL */]: import_cluemart_shared31.EnumUserLicence.STANDARD_SCHOOL
3814
3812
  };
3815
3813
  var LicenceFilterInput = {
3816
3814
  INPUT_USER_LICENCES: "$licences"
@@ -3840,11 +3838,11 @@ function getHighestLicenceForCategory(licences, category) {
3840
3838
  function createLicenceObject(expiryDate, licenceType) {
3841
3839
  const today = (0, import_dayjs3.default)();
3842
3840
  const expiryDateMapping = {
3843
- [import_cluemart_shared30.LicenceExpiryDate.ONE_YEAR]: today.add(1, "year").endOf("day").toDate(),
3844
- [import_cluemart_shared30.LicenceExpiryDate.ONE_MONTH]: today.add(1, "month").endOf("day").toDate(),
3845
- [import_cluemart_shared30.LicenceExpiryDate.TWO_MONTHS]: today.add(2, "month").endOf("day").toDate(),
3846
- [import_cluemart_shared30.LicenceExpiryDate.THREE_MONTHS]: today.add(3, "month").endOf("day").toDate(),
3847
- [import_cluemart_shared30.LicenceExpiryDate.SIX_MONTHS]: today.add(6, "month").endOf("day").toDate()
3841
+ [import_cluemart_shared31.LicenceExpiryDate.ONE_YEAR]: today.add(1, "year").endOf("day").toDate(),
3842
+ [import_cluemart_shared31.LicenceExpiryDate.ONE_MONTH]: today.add(1, "month").endOf("day").toDate(),
3843
+ [import_cluemart_shared31.LicenceExpiryDate.TWO_MONTHS]: today.add(2, "month").endOf("day").toDate(),
3844
+ [import_cluemart_shared31.LicenceExpiryDate.THREE_MONTHS]: today.add(3, "month").endOf("day").toDate(),
3845
+ [import_cluemart_shared31.LicenceExpiryDate.SIX_MONTHS]: today.add(6, "month").endOf("day").toDate()
3848
3846
  };
3849
3847
  const licenceObject = {
3850
3848
  expiryDate: expiryDateMapping[expiryDate],
@@ -3948,13 +3946,13 @@ async function checkOwnerHasLicence({
3948
3946
  const owner = await UserModel.findById(userId);
3949
3947
  if (!owner) throw new import_graphql.GraphQLError("Owner not found");
3950
3948
  const categoryByResource = {
3951
- [import_cluemart_shared30.EnumResourceType.EVENT]: "event" /* EVENT */,
3952
- [import_cluemart_shared30.EnumResourceType.PARTNER]: "partner" /* PARTNER */,
3953
- [import_cluemart_shared30.EnumResourceType.VENDOR]: "vendor" /* VENDOR */,
3954
- [import_cluemart_shared30.EnumResourceType.AFFILIATE]: "affiliate" /* AFFILIATE */,
3955
- [import_cluemart_shared30.EnumResourceType.SCHOOL]: "school" /* SCHOOL */
3949
+ [import_cluemart_shared31.EnumResourceType.EVENT]: "event" /* EVENT */,
3950
+ [import_cluemart_shared31.EnumResourceType.PARTNER]: "partner" /* PARTNER */,
3951
+ [import_cluemart_shared31.EnumResourceType.VENDOR]: "vendor" /* VENDOR */,
3952
+ [import_cluemart_shared31.EnumResourceType.AFFILIATE]: "affiliate" /* AFFILIATE */,
3953
+ [import_cluemart_shared31.EnumResourceType.SCHOOL]: "school" /* SCHOOL */
3956
3954
  };
3957
- if (!(0, import_cluemart_shared30.isNonVisitorResourceType)(resourceType)) {
3955
+ if (!(0, import_cluemart_shared31.isNonVisitorResourceType)(resourceType)) {
3958
3956
  throw new import_graphql.GraphQLError(`Invalid resource type: ${resourceType}.`);
3959
3957
  }
3960
3958
  const requiredCategory = categoryByResource[resourceType];
@@ -4034,7 +4032,7 @@ async function applyVendorDowngrade(vendor, ownerUserId) {
4034
4032
  return (result?.matchedCount ?? 0) > 0;
4035
4033
  }
4036
4034
  async function downgradeVendorProFeatures(userId, licenceType) {
4037
- const isStandardVendor = licenceType === import_cluemart_shared31.EnumUserLicence.STANDARD_VENDOR;
4035
+ const isStandardVendor = licenceType === import_cluemart_shared32.EnumUserLicence.STANDARD_VENDOR;
4038
4036
  if (!isStandardVendor) {
4039
4037
  return;
4040
4038
  }
@@ -4081,7 +4079,7 @@ async function applyVendorRestore(vendor, ownerUserId) {
4081
4079
  return (result?.matchedCount ?? 0) > 0;
4082
4080
  }
4083
4081
  async function restoreVendorProFeatures(userId, licenceType) {
4084
- const isProVendor = licenceType === import_cluemart_shared31.EnumUserLicence.PRO_VENDOR || licenceType === import_cluemart_shared31.EnumUserLicence.PRO_PLUS_VENDOR;
4082
+ const isProVendor = licenceType === import_cluemart_shared32.EnumUserLicence.PRO_VENDOR || licenceType === import_cluemart_shared32.EnumUserLicence.PRO_PLUS_VENDOR;
4085
4083
  if (!isProVendor) {
4086
4084
  return;
4087
4085
  }
@@ -4102,14 +4100,14 @@ function isProtectedByCurrentStripeSubscription(user, licenceType, now) {
4102
4100
  return false;
4103
4101
  }
4104
4102
  const gracePeriodEndsAt = stripe.paymentGracePeriodEndsAt ? (0, import_dayjs4.default)(stripe.paymentGracePeriodEndsAt) : null;
4105
- 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);
4103
+ 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);
4106
4104
  if (hasActivePaymentGracePeriod) {
4107
4105
  return true;
4108
4106
  }
4109
4107
  if (!stripe.subscriptionId) {
4110
4108
  return false;
4111
4109
  }
4112
- if (stripe.status !== import_cluemart_shared31.EnumSubscriptionStatus.ACTIVE) {
4110
+ if (stripe.status !== import_cluemart_shared32.EnumSubscriptionStatus.ACTIVE) {
4113
4111
  return false;
4114
4112
  }
4115
4113
  if (!stripe.endDate) {
@@ -4129,7 +4127,7 @@ async function handleVendorLicenceCompliance(user, now) {
4129
4127
  return;
4130
4128
  }
4131
4129
  const proLicences = vendorLicencesOfUser.filter(
4132
- (licence) => licence.licenceType !== import_cluemart_shared31.EnumUserLicence.STANDARD_VENDOR
4130
+ (licence) => licence.licenceType !== import_cluemart_shared32.EnumUserLicence.STANDARD_VENDOR
4133
4131
  );
4134
4132
  const expiredProLicences = proLicences.filter(
4135
4133
  (licence) => !(0, import_dayjs4.default)(licence.expiryDate).isAfter(now)
@@ -4142,7 +4140,7 @@ async function handleVendorLicenceCompliance(user, now) {
4142
4140
  const expiredProLicence = expiredProLicences.some(
4143
4141
  (licence) => !stripeProtectedLicenceTypes.has(licence.licenceType)
4144
4142
  );
4145
- const hasValidProLicence = stripeProtectedLicenceTypes.size > 0 || hasValidLicence(proLicences, import_cluemart_shared31.vendorLicences, now);
4143
+ const hasValidProLicence = stripeProtectedLicenceTypes.size > 0 || hasValidLicence(proLicences, import_cluemart_shared32.vendorLicences, now);
4146
4144
  const hasExpiredVendorLicence = vendorLicencesOfUser.some(
4147
4145
  (licence) => !(0, import_dayjs4.default)(licence.expiryDate).isAfter(now) && !stripeProtectedLicenceTypes.has(licence.licenceType)
4148
4146
  );
@@ -4158,7 +4156,7 @@ async function handleVendorLicenceCompliance(user, now) {
4158
4156
  "owner.userId": user._id
4159
4157
  }).lean().exec();
4160
4158
  }
4161
- const licencesToSync = import_cluemart_shared31.vendorLicences.filter(
4159
+ const licencesToSync = import_cluemart_shared32.vendorLicences.filter(
4162
4160
  (licenceType) => !stripeProtectedLicenceTypes.has(licenceType)
4163
4161
  );
4164
4162
  await syncUserLicencesAfterExpiry(user._id, licencesToSync, now, "downgrade");
@@ -4173,11 +4171,11 @@ async function handleVendorLicenceCompliance(user, now) {
4173
4171
  data: {
4174
4172
  resourceId: String(vendor._id),
4175
4173
  resourceName: vendor.name,
4176
- resourceType: import_cluemart_shared31.EnumNotificationResourceType.DOWNGRADED_VENDOR
4174
+ resourceType: import_cluemart_shared32.EnumNotificationResourceType.DOWNGRADED_VENDOR
4177
4175
  },
4178
4176
  message: `Your Vendor licence has been downgraded due to licence expiration.`,
4179
4177
  title: `Vendor Licence Downgraded`,
4180
- type: import_cluemart_shared31.EnumNotificationType.SYSTEM,
4178
+ type: import_cluemart_shared32.EnumNotificationType.SYSTEM,
4181
4179
  userIds: [user._id]
4182
4180
  };
4183
4181
  await sendDeactivationNotification(payload, user._id, vendor.name, "vendor");
@@ -4210,7 +4208,7 @@ async function vendorOwnerHasProLicence(vendorId) {
4210
4208
  effectiveVendorLicences,
4211
4209
  "vendor" /* VENDOR */
4212
4210
  );
4213
- return highestVendorLicence !== null && licencePriority[highestVendorLicence] >= licencePriority[import_cluemart_shared31.EnumUserLicence.PRO_VENDOR];
4211
+ return highestVendorLicence !== null && licencePriority[highestVendorLicence] >= licencePriority[import_cluemart_shared32.EnumUserLicence.PRO_VENDOR];
4214
4212
  }
4215
4213
 
4216
4214
  // src/service/license/compliance/utils.ts
@@ -4220,12 +4218,12 @@ async function syncUserLicencesAfterExpiry(userId, licenceTypes, now, mode = "do
4220
4218
  const pipeline = buildLicenceExpiryPipeline({
4221
4219
  downgradeBranches: [
4222
4220
  {
4223
- case: import_cluemart_shared32.EnumUserLicence.PRO_PLUS_VENDOR,
4224
- then: import_cluemart_shared32.EnumUserLicence.STANDARD_VENDOR
4221
+ case: import_cluemart_shared33.EnumUserLicence.PRO_PLUS_VENDOR,
4222
+ then: import_cluemart_shared33.EnumUserLicence.STANDARD_VENDOR
4225
4223
  },
4226
4224
  {
4227
- case: import_cluemart_shared32.EnumUserLicence.PRO_VENDOR,
4228
- then: import_cluemart_shared32.EnumUserLicence.STANDARD_VENDOR
4225
+ case: import_cluemart_shared33.EnumUserLicence.PRO_VENDOR,
4226
+ then: import_cluemart_shared33.EnumUserLicence.STANDARD_VENDOR
4229
4227
  }
4230
4228
  ],
4231
4229
  licenceTypes,
@@ -4354,7 +4352,7 @@ var REMINDER_WINDOW_MIN_HOURS = 6.5 * 24;
4354
4352
  var REMINDER_WINDOW_MAX_HOURS = 7.5 * 24;
4355
4353
 
4356
4354
  // src/service/license/reminder/utils.ts
4357
- var import_cluemart_shared33 = require("@timardex/cluemart-shared");
4355
+ var import_cluemart_shared34 = require("@timardex/cluemart-shared");
4358
4356
  var import_utils8 = require("@timardex/cluemart-shared/utils");
4359
4357
  var import_dayjs7 = __toESM(require("dayjs"));
4360
4358
 
@@ -4420,28 +4418,28 @@ function isLicenseExpiringIn7Days(expiryDate, now) {
4420
4418
  return hoursUntilExpiry >= REMINDER_WINDOW_MIN_HOURS && hoursUntilExpiry <= REMINDER_WINDOW_MAX_HOURS;
4421
4419
  }
4422
4420
  function getLicenseName(licenceType) {
4423
- return import_cluemart_shared33.licenseNiceNames[licenceType] || licenceType;
4421
+ return import_cluemart_shared34.licenseNiceNames[licenceType] || licenceType;
4424
4422
  }
4425
4423
  function getNotificationTypes(isVendorLicense, isPartnerLicense) {
4426
4424
  if (isVendorLicense) {
4427
4425
  return {
4428
- notificationType: import_cluemart_shared33.EnumNotificationType.SYSTEM,
4429
- resourceType: import_cluemart_shared33.EnumNotificationResourceType.EXPIRATION_REMINDER_VENDOR
4426
+ notificationType: import_cluemart_shared34.EnumNotificationType.SYSTEM,
4427
+ resourceType: import_cluemart_shared34.EnumNotificationResourceType.EXPIRATION_REMINDER_VENDOR
4430
4428
  };
4431
4429
  }
4432
4430
  if (isPartnerLicense) {
4433
4431
  return {
4434
- notificationType: import_cluemart_shared33.EnumNotificationType.SYSTEM,
4435
- resourceType: import_cluemart_shared33.EnumNotificationResourceType.EXPIRATION_REMINDER_PARTNER
4432
+ notificationType: import_cluemart_shared34.EnumNotificationType.SYSTEM,
4433
+ resourceType: import_cluemart_shared34.EnumNotificationResourceType.EXPIRATION_REMINDER_PARTNER
4436
4434
  };
4437
4435
  }
4438
4436
  return {
4439
- notificationType: import_cluemart_shared33.EnumNotificationType.SYSTEM,
4440
- resourceType: import_cluemart_shared33.EnumNotificationResourceType.EXPIRATION_REMINDER_EVENT
4437
+ notificationType: import_cluemart_shared34.EnumNotificationType.SYSTEM,
4438
+ resourceType: import_cluemart_shared34.EnumNotificationResourceType.EXPIRATION_REMINDER_EVENT
4441
4439
  };
4442
4440
  }
4443
4441
  async function getLicenseResourceInfo(user, licence) {
4444
- const isVendorLicense = import_cluemart_shared33.vendorLicences.includes(licence.licenceType);
4442
+ const isVendorLicense = import_cluemart_shared34.vendorLicences.includes(licence.licenceType);
4445
4443
  const isPartnerLicense = partnerLicences.includes(licence.licenceType);
4446
4444
  const licenceName = getLicenseName(licence.licenceType);
4447
4445
  const { notificationType, resourceType } = getNotificationTypes(
@@ -4489,11 +4487,11 @@ async function getLicenseResourceInfo(user, licence) {
4489
4487
  };
4490
4488
  }
4491
4489
  function getLicenceExpiryMode(licenceType) {
4492
- return licenceType === import_cluemart_shared33.EnumUserLicence.PRO_VENDOR || licenceType === import_cluemart_shared33.EnumUserLicence.PRO_PLUS_VENDOR ? "downgrade" : "extend";
4490
+ return licenceType === import_cluemart_shared34.EnumUserLicence.PRO_VENDOR || licenceType === import_cluemart_shared34.EnumUserLicence.PRO_PLUS_VENDOR ? "downgrade" : "extend";
4493
4491
  }
4494
4492
  async function sendLicenseReminder(user, licence) {
4495
4493
  const licenceName = getLicenseName(licence.licenceType);
4496
- const expiryDate = (0, import_dayjs7.default)(licence.expiryDate).format(import_cluemart_shared33.dateFormat);
4494
+ const expiryDate = (0, import_dayjs7.default)(licence.expiryDate).format(import_cluemart_shared34.dateFormat);
4497
4495
  const userId = String(user._id);
4498
4496
  const resourceInfo = await getLicenseResourceInfo(user, licence);
4499
4497
  if (!resourceInfo) {
@@ -4642,6 +4640,8 @@ async function remindUsersAboutLicenseExpiration() {
4642
4640
  EventModel,
4643
4641
  GameModel,
4644
4642
  GoogleImportedMarketModel,
4643
+ ImpersonationAuditModel,
4644
+ ImpersonationSessionModel,
4645
4645
  LicenceCategory,
4646
4646
  NotificationModel,
4647
4647
  OwnerTypeSchema,