@timardex/cluemart-server-shared 4.1.0 → 4.2.1

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.
@@ -35,6 +35,7 @@ __export(service_exports, {
35
35
  REMINDER_WINDOW_MAX_HOURS: () => REMINDER_WINDOW_MAX_HOURS,
36
36
  REMINDER_WINDOW_MIN_HOURS: () => REMINDER_WINDOW_MIN_HOURS,
37
37
  SUBSCRIPTION_REWARD_TIMEZONE: () => SUBSCRIPTION_REWARD_TIMEZONE,
38
+ acceptedAssociateUserIds: () => acceptedAssociateUserIds,
38
39
  activeAffiliateCodeExists: () => activeAffiliateCodeExists,
39
40
  awardAffiliateVendorSubscriptionRewards: () => awardAffiliateVendorSubscriptionRewards,
40
41
  buildLicenceExpiryPipeline: () => buildLicenceExpiryPipeline,
@@ -48,6 +49,9 @@ __export(service_exports, {
48
49
  convertObjectIdsToStrings: () => convertObjectIdsToStrings,
49
50
  createLicenceObject: () => createLicenceObject,
50
51
  dedupeArchivedSlotsByStartDateTime: () => dedupeArchivedSlotsByStartDateTime,
52
+ detachAssociateGrantsForResources: () => detachAssociateGrantsForResources,
53
+ detachStaleAssociateGrants: () => detachStaleAssociateGrants,
54
+ detachUsersFromResource: () => detachUsersFromResource,
51
55
  didRemoveAnyEventDates: () => didRemoveAnyEventDates,
52
56
  didRemoveAnyStartedDates: () => didRemoveAnyStartedDates,
53
57
  downgradeVendorProFeatures: () => downgradeVendorProFeatures,
@@ -57,6 +61,8 @@ __export(service_exports, {
57
61
  eventLicences: () => eventLicences,
58
62
  findAffiliateByPromoCode: () => findAffiliateByPromoCode,
59
63
  findEventOrImportedMarketById: () => findEventOrImportedMarketById,
64
+ getActiveLicenceForResource: () => getActiveLicenceForResource,
65
+ getAssociateAccessMeta: () => getAssociateAccessMeta,
60
66
  getEventResourceInfo: () => getEventResourceInfo,
61
67
  getHighestLicenceForCategory: () => getHighestLicenceForCategory,
62
68
  getLicenceCategory: () => getLicenceCategory,
@@ -66,11 +72,17 @@ __export(service_exports, {
66
72
  getPayingStripeSubscriptionPlan: () => getPayingStripeSubscriptionPlan,
67
73
  getPayingVendorStripeSubscriptionPlan: () => getPayingVendorStripeSubscriptionPlan,
68
74
  getSubscriptionRewardPeriodBounds: () => getSubscriptionRewardPeriodBounds,
75
+ getUserIdsWithActiveProLicence: () => getUserIdsWithActiveProLicence,
69
76
  getVendorResourceInfo: () => getVendorResourceInfo,
77
+ grantAssociateGrants: () => grantAssociateGrants,
70
78
  handleEventLicenceCompliance: () => handleEventLicenceCompliance,
71
79
  handlePartnerLicenceCompliance: () => handlePartnerLicenceCompliance,
72
80
  handleVendorLicenceCompliance: () => handleVendorLicenceCompliance,
81
+ hasActiveProLicenceForResource: () => hasActiveProLicenceForResource,
73
82
  hasValidLicence: () => hasValidLicence,
83
+ isAssociableResourceType: () => isAssociableResourceType,
84
+ isProLicence: () => isProLicence,
85
+ isProtectedByCurrentStripeSubscription: () => isProtectedByCurrentStripeSubscription,
74
86
  isStandardLicence: () => isStandardLicence,
75
87
  isValidObjectId: () => isValidObjectId,
76
88
  licenceCategoryMapping: () => licenceCategoryMapping,
@@ -85,6 +97,7 @@ __export(service_exports, {
85
97
  processUserCompliance: () => processUserCompliance,
86
98
  processUserLicenseReminders: () => processUserLicenseReminders,
87
99
  publishNotificationEvents: () => publishNotificationEvents,
100
+ reconcileAssociateGrants: () => reconcileAssociateGrants,
88
101
  remindUsersAboutLicenseExpiration: () => remindUsersAboutLicenseExpiration,
89
102
  replaceUserLicenceWithObject: () => replaceUserLicenceWithObject,
90
103
  restoreVendorProFeatures: () => restoreVendorProFeatures,
@@ -98,7 +111,7 @@ __export(service_exports, {
98
111
  updateAdStatuses: () => updateAdStatuses,
99
112
  updateAllEventDateTimeStatuses: () => updateAllEventDateTimeStatuses,
100
113
  updateRelationDatesToCanceled: () => updateRelationDatesToCanceled,
101
- updateSingleDateTimeStatus: () => import_cluemart_shared38.updateSingleDateTimeStatus,
114
+ updateSingleDateTimeStatus: () => import_cluemart_shared39.updateSingleDateTimeStatus,
102
115
  upgradeUserToLicence: () => upgradeUserToLicence,
103
116
  vendorOwnerHasProLicence: () => vendorOwnerHasProLicence
104
117
  });
@@ -766,6 +779,25 @@ var OwnerTypeSchema = new MongooseSchema5(
766
779
  { _id: false }
767
780
  // Prevents Mongoose from creating an additional _id field for subdocuments
768
781
  );
782
+ var AssociateTypeSchema = new MongooseSchema5(
783
+ {
784
+ addedAt: { default: Date.now, required: false, type: Date },
785
+ email: { lowercase: true, required: true, trim: true, type: String },
786
+ respondedAt: { default: null, required: false, type: Date },
787
+ status: {
788
+ default: import_cluemart_shared8.EnumAssociateStatus.PENDING,
789
+ enum: Object.values(import_cluemart_shared8.EnumAssociateStatus),
790
+ required: true,
791
+ type: String
792
+ },
793
+ userId: {
794
+ ref: "User",
795
+ required: true,
796
+ type: import_mongoose9.default.Schema.Types.ObjectId
797
+ }
798
+ },
799
+ { _id: false }
800
+ );
769
801
  var SocialMediaTypeSchema = new MongooseSchema5(
770
802
  {
771
803
  link: { required: true, type: String },
@@ -931,6 +963,7 @@ var baseResourceFields = {
931
963
  type: [import_mongoose9.default.Schema.Types.ObjectId]
932
964
  },
933
965
  approvedAt: { default: null, required: false, type: Date },
966
+ associates: { default: [], required: false, type: [AssociateTypeSchema] },
934
967
  contactDetails: { required: false, type: ContactDetailsSchema },
935
968
  cover: {
936
969
  required: true,
@@ -1810,6 +1843,29 @@ var userOverallPointsSchema = new MongooseSchema16(
1810
1843
  },
1811
1844
  { _id: false }
1812
1845
  );
1846
+ var userAssociatedResourcesSchema = new MongooseSchema16(
1847
+ {
1848
+ events: {
1849
+ default: [],
1850
+ ref: "Event",
1851
+ required: false,
1852
+ type: [import_mongoose20.default.Schema.Types.ObjectId]
1853
+ },
1854
+ partners: {
1855
+ default: [],
1856
+ ref: "Partner",
1857
+ required: false,
1858
+ type: [import_mongoose20.default.Schema.Types.ObjectId]
1859
+ },
1860
+ vendors: {
1861
+ default: [],
1862
+ ref: "Vendor",
1863
+ required: false,
1864
+ type: [import_mongoose20.default.Schema.Types.ObjectId]
1865
+ }
1866
+ },
1867
+ { _id: false }
1868
+ );
1813
1869
  var schema15 = new MongooseSchema16(
1814
1870
  {
1815
1871
  active: { default: false, required: true, type: Boolean },
@@ -1818,6 +1874,11 @@ var schema15 = new MongooseSchema16(
1818
1874
  required: false,
1819
1875
  type: import_mongoose20.default.Schema.Types.ObjectId
1820
1876
  },
1877
+ associatedResources: {
1878
+ default: () => ({ events: [], partners: [], vendors: [] }),
1879
+ required: false,
1880
+ type: userAssociatedResourcesSchema
1881
+ },
1821
1882
  avatar: {
1822
1883
  required: false,
1823
1884
  type: ResourceImageTypeSchema
@@ -1828,7 +1889,10 @@ var schema15 = new MongooseSchema16(
1828
1889
  type: import_mongoose20.default.Schema.Types.ObjectId
1829
1890
  },
1830
1891
  deletedAt: { default: null, required: false, type: Date },
1831
- email: { required: true, type: String },
1892
+ // `normalizeEmail` (`cluemart-shared`) is trim + lower-case; keeping the same
1893
+ // rule here means every write path — resolvers, seeds, scripts — stores the
1894
+ // comparable form, not only the clients that validate through `emailRequiredSchema`.
1895
+ email: { lowercase: true, required: true, trim: true, type: String },
1832
1896
  emailSentFor: {
1833
1897
  enum: Object.values(import_cluemart_shared16.EnumNotificationResourceType),
1834
1898
  required: false,
@@ -1943,6 +2007,10 @@ schema15.index({ "licences.expiryDate": 1 });
1943
2007
  schema15.index({ "licences.licenceType": 1 });
1944
2008
  schema15.index({ promoCodes: 1, active: 1, deletedAt: 1 });
1945
2009
  schema15.index({ email: "text", firstName: "text", lastName: "text" });
2010
+ schema15.index({ email: 1 }, { name: "email_unique", unique: true });
2011
+ schema15.index({ "associatedResources.events": 1 });
2012
+ schema15.index({ "associatedResources.partners": 1 });
2013
+ schema15.index({ "associatedResources.vendors": 1 });
1946
2014
  var UserModel = import_mongoose20.default.models.User || import_mongoose20.default.model("User", schema15);
1947
2015
 
1948
2016
  // src/mongoose/VerificationToken.ts
@@ -2076,6 +2144,7 @@ schema17.index({
2076
2144
  name: "text"
2077
2145
  });
2078
2146
  schema17.index({ deletedAt: 1, "owner.userId": 1 });
2147
+ schema17.index({ "associates.userId": 1, deletedAt: 1 });
2079
2148
  schema17.plugin(searchNamePlugin);
2080
2149
  var VendorModel = import_mongoose22.default.models.Vendor || import_mongoose22.default.model("Vendor", schema17);
2081
2150
 
@@ -2227,6 +2296,7 @@ schema20.index({ "dateTime.dateStatus": 1 });
2227
2296
  schema20.index({ slug: 1 });
2228
2297
  schema20.index({ description: "text", name: "text", tags: "text" });
2229
2298
  schema20.index({ deletedAt: 1, "owner.userId": 1 });
2299
+ schema20.index({ "associates.userId": 1, deletedAt: 1 });
2230
2300
  schema20.plugin(searchNamePlugin);
2231
2301
  var EventModel = import_mongoose25.default.models.Event || import_mongoose25.default.model("Event", schema20);
2232
2302
 
@@ -2273,6 +2343,7 @@ schema22.index({ "location.geo": "2dsphere" });
2273
2343
  schema22.index({ slug: 1 });
2274
2344
  schema22.index({ name: "text", description: "text" });
2275
2345
  schema22.index({ "owner.userId": 1, deletedAt: 1 });
2346
+ schema22.index({ "associates.userId": 1, deletedAt: 1 });
2276
2347
  schema22.plugin(searchNamePlugin);
2277
2348
  var PartnerModel = import_mongoose27.default.models.Partner || import_mongoose27.default.model("Partner", schema22);
2278
2349
 
@@ -3338,14 +3409,310 @@ function normalizeAffiliatePromoCodes(promoCodes) {
3338
3409
  return [...new Set(normalized)];
3339
3410
  }
3340
3411
 
3412
+ // src/service/associates/index.ts
3413
+ var import_cluemart_shared28 = require("@timardex/cluemart-shared");
3414
+ var import_mongoose42 = __toESM(require("mongoose"));
3415
+ function isAssociableResourceType(resourceType) {
3416
+ return resourceType === import_cluemart_shared28.EnumResourceType.EVENT || resourceType === import_cluemart_shared28.EnumResourceType.PARTNER || resourceType === import_cluemart_shared28.EnumResourceType.VENDOR;
3417
+ }
3418
+ function getAssociateAccessMeta(resourceType) {
3419
+ if (resourceType === import_cluemart_shared28.EnumResourceType.EVENT) {
3420
+ return {
3421
+ associatedField: "events",
3422
+ associatedPath: "associatedResources.events",
3423
+ associateRole: import_cluemart_shared28.EnumUserRole.ASSOCIATED_EVENT
3424
+ };
3425
+ }
3426
+ if (resourceType === import_cluemart_shared28.EnumResourceType.PARTNER) {
3427
+ return {
3428
+ associatedField: "partners",
3429
+ associatedPath: "associatedResources.partners",
3430
+ associateRole: import_cluemart_shared28.EnumUserRole.ASSOCIATED_PARTNER
3431
+ };
3432
+ }
3433
+ return {
3434
+ associatedField: "vendors",
3435
+ associatedPath: "associatedResources.vendors",
3436
+ associateRole: import_cluemart_shared28.EnumUserRole.ASSOCIATED_VENDOR
3437
+ };
3438
+ }
3439
+ var ASSOCIABLE_MODELS = {
3440
+ [import_cluemart_shared28.EnumResourceType.EVENT]: EventModel,
3441
+ [import_cluemart_shared28.EnumResourceType.PARTNER]: PartnerModel,
3442
+ [import_cluemart_shared28.EnumResourceType.VENDOR]: VendorModel
3443
+ };
3444
+ function acceptedAssociateUserIds(associates) {
3445
+ return (associates ?? []).filter((associate) => associate.status === import_cluemart_shared28.EnumAssociateStatus.ACCEPTED).map((associate) => associate.userId);
3446
+ }
3447
+ async function detachUsersFromResource({
3448
+ resourceId,
3449
+ resourceType,
3450
+ userIds
3451
+ }) {
3452
+ if (userIds.length === 0) return;
3453
+ const { associateRole, associatedPath: path } = getAssociateAccessMeta(resourceType);
3454
+ const removedResourceId = typeof resourceId === "string" ? new import_mongoose42.default.Types.ObjectId(resourceId) : resourceId;
3455
+ await UserModel.updateMany({ _id: { $in: userIds } }, [
3456
+ {
3457
+ $set: {
3458
+ [path]: {
3459
+ $setDifference: [{ $ifNull: [`$${path}`, []] }, [removedResourceId]]
3460
+ }
3461
+ }
3462
+ },
3463
+ {
3464
+ $set: {
3465
+ roles: {
3466
+ $cond: [
3467
+ { $eq: [{ $size: { $ifNull: [`$${path}`, []] } }, 0] },
3468
+ {
3469
+ $setDifference: [{ $ifNull: ["$roles", []] }, [associateRole]]
3470
+ },
3471
+ "$roles"
3472
+ ]
3473
+ }
3474
+ }
3475
+ }
3476
+ ]).exec();
3477
+ }
3478
+ async function acceptedUserIdsForResource({
3479
+ resourceId,
3480
+ resourceType
3481
+ }) {
3482
+ const model = ASSOCIABLE_MODELS[resourceType];
3483
+ const resource = await model.findOne({ _id: resourceId, deletedAt: null }).select("associates").lean().exec();
3484
+ return new Set(
3485
+ acceptedAssociateUserIds(resource?.associates).map(
3486
+ (userId) => String(userId)
3487
+ )
3488
+ );
3489
+ }
3490
+ async function grantAssociateGrants({
3491
+ resourceId,
3492
+ resourceType,
3493
+ userIds
3494
+ }) {
3495
+ if (userIds.length === 0) return;
3496
+ const acceptedUserIds = await acceptedUserIdsForResource({
3497
+ resourceId,
3498
+ resourceType
3499
+ });
3500
+ const grantUserIds = userIds.filter(
3501
+ (userId) => acceptedUserIds.has(String(userId))
3502
+ );
3503
+ if (grantUserIds.length === 0) return;
3504
+ const { associateRole, associatedPath } = getAssociateAccessMeta(resourceType);
3505
+ await UserModel.updateMany(
3506
+ { _id: { $in: grantUserIds } },
3507
+ {
3508
+ $addToSet: {
3509
+ [associatedPath]: resourceId,
3510
+ roles: associateRole
3511
+ }
3512
+ }
3513
+ ).exec();
3514
+ }
3515
+ async function detachUnlessStillAccepted({
3516
+ resourceId,
3517
+ resourceType,
3518
+ userIds
3519
+ }) {
3520
+ if (userIds.length === 0) return [];
3521
+ await detachUsersFromResource({ resourceId, resourceType, userIds });
3522
+ const acceptedAfterDetach = await acceptedUserIdsForResource({
3523
+ resourceId,
3524
+ resourceType
3525
+ });
3526
+ const restoredUserIds = userIds.filter(
3527
+ (userId) => acceptedAfterDetach.has(String(userId))
3528
+ );
3529
+ if (restoredUserIds.length === 0) return userIds;
3530
+ await grantAssociateGrants({
3531
+ resourceId,
3532
+ resourceType,
3533
+ userIds: restoredUserIds
3534
+ });
3535
+ const acceptedAfterRestore = await acceptedUserIdsForResource({
3536
+ resourceId,
3537
+ resourceType
3538
+ });
3539
+ const regressedUserIds = restoredUserIds.filter(
3540
+ (userId) => !acceptedAfterRestore.has(String(userId))
3541
+ );
3542
+ if (regressedUserIds.length > 0) {
3543
+ await detachUsersFromResource({
3544
+ resourceId,
3545
+ resourceType,
3546
+ userIds: regressedUserIds
3547
+ });
3548
+ }
3549
+ return userIds.filter((userId) => !acceptedAfterRestore.has(String(userId)));
3550
+ }
3551
+ async function detachStaleAssociateGrants({
3552
+ acceptedUserIds,
3553
+ resourceId,
3554
+ resourceType
3555
+ }) {
3556
+ const { associatedPath } = getAssociateAccessMeta(resourceType);
3557
+ const stale = await UserModel.find({
3558
+ _id: { $nin: acceptedUserIds },
3559
+ [associatedPath]: resourceId
3560
+ }).select("_id").lean().exec();
3561
+ const staleUserIds = stale.map((user) => user._id);
3562
+ return detachUnlessStillAccepted({
3563
+ resourceId,
3564
+ resourceType,
3565
+ userIds: staleUserIds
3566
+ });
3567
+ }
3568
+ async function detachAssociateGrantsForResources({
3569
+ resources
3570
+ }) {
3571
+ const result = resources.map((resource) => ({
3572
+ detachedUserIds: [],
3573
+ resourceId: resource.resourceId,
3574
+ resourceType: resource.resourceType
3575
+ }));
3576
+ const indexByType = /* @__PURE__ */ new Map();
3577
+ resources.forEach((resource, index) => {
3578
+ const entries = indexByType.get(resource.resourceType) ?? [];
3579
+ entries.push({ index, resourceId: resource.resourceId });
3580
+ indexByType.set(resource.resourceType, entries);
3581
+ });
3582
+ for (const [resourceType, entries] of indexByType) {
3583
+ const { associatedField, associatedPath } = getAssociateAccessMeta(resourceType);
3584
+ const resourceIds = entries.map((entry) => entry.resourceId);
3585
+ const wanted = new Set(resourceIds.map((resourceId) => String(resourceId)));
3586
+ const holders = await UserModel.find({
3587
+ [associatedPath]: { $in: resourceIds }
3588
+ }).select("_id associatedResources").lean().exec();
3589
+ const userIdsByResource = /* @__PURE__ */ new Map();
3590
+ for (const user of holders) {
3591
+ for (const heldResourceId of user.associatedResources?.[associatedField] ?? []) {
3592
+ const key = String(heldResourceId);
3593
+ if (!wanted.has(key)) continue;
3594
+ const userIds = userIdsByResource.get(key) ?? [];
3595
+ userIds.push(user._id);
3596
+ userIdsByResource.set(key, userIds);
3597
+ }
3598
+ }
3599
+ for (const entry of entries) {
3600
+ const userIds = userIdsByResource.get(String(entry.resourceId));
3601
+ if (!userIds || userIds.length === 0) continue;
3602
+ await detachUsersFromResource({
3603
+ resourceId: entry.resourceId,
3604
+ resourceType,
3605
+ userIds
3606
+ });
3607
+ result[entry.index].detachedUserIds = userIds;
3608
+ }
3609
+ }
3610
+ return result;
3611
+ }
3612
+ var DEFAULT_RECONCILE_BATCH_SIZE = 500;
3613
+ async function reconcileUserBatch({
3614
+ associatedField,
3615
+ model,
3616
+ resourceType,
3617
+ users
3618
+ }) {
3619
+ const heldByResource = /* @__PURE__ */ new Map();
3620
+ for (const user of users) {
3621
+ for (const resourceId of user.associatedResources?.[associatedField] ?? []) {
3622
+ const key = String(resourceId);
3623
+ const entry = heldByResource.get(key) ?? { resourceId, userIds: [] };
3624
+ entry.userIds.push(user._id);
3625
+ heldByResource.set(key, entry);
3626
+ }
3627
+ }
3628
+ if (heldByResource.size === 0) return 0;
3629
+ const resources = await model.find({
3630
+ _id: {
3631
+ $in: [...heldByResource.values()].map((entry) => entry.resourceId)
3632
+ }
3633
+ }).select("associates deletedAt").lean().exec();
3634
+ const acceptedByResource = /* @__PURE__ */ new Map();
3635
+ for (const resource of resources) {
3636
+ acceptedByResource.set(
3637
+ String(resource._id),
3638
+ resource.deletedAt ? /* @__PURE__ */ new Set() : new Set(
3639
+ acceptedAssociateUserIds(resource.associates).map(
3640
+ (userId) => String(userId)
3641
+ )
3642
+ )
3643
+ );
3644
+ }
3645
+ let detachedGrants = 0;
3646
+ for (const [key, { resourceId, userIds }] of heldByResource) {
3647
+ const accepted = acceptedByResource.get(key);
3648
+ const staleUserIds = userIds.filter(
3649
+ (userId) => !accepted?.has(String(userId))
3650
+ );
3651
+ if (staleUserIds.length === 0) continue;
3652
+ const removedUserIds = await detachUnlessStillAccepted({
3653
+ resourceId,
3654
+ resourceType,
3655
+ userIds: staleUserIds
3656
+ });
3657
+ detachedGrants += removedUserIds.length;
3658
+ }
3659
+ return detachedGrants;
3660
+ }
3661
+ async function reconcileResourceType({
3662
+ batchSize,
3663
+ resourceType
3664
+ }) {
3665
+ const { associatedField, associatedPath } = getAssociateAccessMeta(resourceType);
3666
+ const model = ASSOCIABLE_MODELS[resourceType];
3667
+ const result = {
3668
+ detachedGrants: 0,
3669
+ scannedUsers: 0
3670
+ };
3671
+ let lastId = null;
3672
+ for (; ; ) {
3673
+ const users = await UserModel.find({
3674
+ ...lastId ? { _id: { $gt: lastId } } : {},
3675
+ [associatedPath]: { $exists: true, $ne: [] }
3676
+ }).sort({ _id: 1 }).limit(batchSize).select("_id associatedResources").lean().exec();
3677
+ if (users.length === 0) break;
3678
+ result.scannedUsers += users.length;
3679
+ lastId = users[users.length - 1]._id;
3680
+ result.detachedGrants += await reconcileUserBatch({
3681
+ associatedField,
3682
+ model,
3683
+ resourceType,
3684
+ users
3685
+ });
3686
+ }
3687
+ return result;
3688
+ }
3689
+ async function reconcileAssociateGrants({
3690
+ batchSize = DEFAULT_RECONCILE_BATCH_SIZE
3691
+ } = {}) {
3692
+ const totals = {
3693
+ detachedGrants: 0,
3694
+ scannedUsers: 0
3695
+ };
3696
+ for (const resourceType of [
3697
+ import_cluemart_shared28.EnumResourceType.EVENT,
3698
+ import_cluemart_shared28.EnumResourceType.VENDOR,
3699
+ import_cluemart_shared28.EnumResourceType.PARTNER
3700
+ ]) {
3701
+ const result = await reconcileResourceType({ batchSize, resourceType });
3702
+ totals.detachedGrants += result.detachedGrants;
3703
+ totals.scannedUsers += result.scannedUsers;
3704
+ }
3705
+ return totals;
3706
+ }
3707
+
3341
3708
  // src/service/database.ts
3342
- var import_mongoose43 = __toESM(require("mongoose"));
3709
+ var import_mongoose44 = __toESM(require("mongoose"));
3343
3710
 
3344
3711
  // src/service/indexes.ts
3345
- var import_mongoose42 = __toESM(require("mongoose"));
3712
+ var import_mongoose43 = __toESM(require("mongoose"));
3346
3713
  function registeredModels() {
3347
- return import_mongoose42.default.modelNames().map((modelName) => {
3348
- const model = import_mongoose42.default.model(modelName);
3714
+ return import_mongoose43.default.modelNames().map((modelName) => {
3715
+ const model = import_mongoose43.default.model(modelName);
3349
3716
  return { createIndexes: () => model.createIndexes(), modelName };
3350
3717
  });
3351
3718
  }
@@ -3387,7 +3754,7 @@ var connectToDatabase = async ({
3387
3754
  // Fallback to MongoDB Atlas connection string
3388
3755
  `mongodb+srv://${dbUser}:${dbPassword}@${dbName}.mongodb.net/?retryWrites=true&w=majority&appName=${appName}`
3389
3756
  );
3390
- await import_mongoose43.default.connect(mongoUri);
3757
+ await import_mongoose44.default.connect(mongoUri);
3391
3758
  const connectionType = mongodbUri ? "Local MongoDB" : "MongoDB Atlas";
3392
3759
  console.log(
3393
3760
  `${connectionType} connected from server/src/service/database.ts`
@@ -3403,7 +3770,7 @@ var connectToDatabase = async ({
3403
3770
 
3404
3771
  // src/types/index.ts
3405
3772
  var import_express = __toESM(require("express"));
3406
- var import_mongoose44 = __toESM(require("mongoose"));
3773
+ var import_mongoose45 = __toESM(require("mongoose"));
3407
3774
 
3408
3775
  // src/service/notifyUsers.ts
3409
3776
  async function publishNotificationEvents(userId, pubsub) {
@@ -3451,9 +3818,9 @@ async function notifyUsers({
3451
3818
  }
3452
3819
 
3453
3820
  // src/service/updateAdStatus.ts
3454
- var import_cluemart_shared28 = require("@timardex/cluemart-shared");
3821
+ var import_cluemart_shared29 = require("@timardex/cluemart-shared");
3455
3822
  async function updateAdStatuses() {
3456
- const now = (0, import_cluemart_shared28.nzDayKey)();
3823
+ const now = (0, import_cluemart_shared29.nzDayKey)();
3457
3824
  const invalidResult = await AdModel.updateMany(
3458
3825
  {
3459
3826
  $or: [
@@ -3461,50 +3828,50 @@ async function updateAdStatuses() {
3461
3828
  { end: { $exists: false } },
3462
3829
  { $expr: { $gt: ["$start", "$end"] } }
3463
3830
  ],
3464
- status: { $ne: import_cluemart_shared28.EnumAdStatus.PAUSED }
3831
+ status: { $ne: import_cluemart_shared29.EnumAdStatus.PAUSED }
3465
3832
  },
3466
- { $set: { status: import_cluemart_shared28.EnumAdStatus.PAUSED } }
3833
+ { $set: { status: import_cluemart_shared29.EnumAdStatus.PAUSED } }
3467
3834
  );
3468
3835
  const expiredResult = await AdModel.updateMany(
3469
- { end: { $lte: now }, status: { $ne: import_cluemart_shared28.EnumAdStatus.EXPIRED } },
3470
- { $set: { status: import_cluemart_shared28.EnumAdStatus.EXPIRED } }
3836
+ { end: { $lte: now }, status: { $ne: import_cluemart_shared29.EnumAdStatus.EXPIRED } },
3837
+ { $set: { status: import_cluemart_shared29.EnumAdStatus.EXPIRED } }
3471
3838
  );
3472
3839
  const eligibleBooking = {
3473
3840
  $or: [
3474
3841
  { bookingKind: { $exists: false } },
3475
3842
  { bookingKind: null },
3476
3843
  {
3477
- approvalStatus: import_cluemart_shared28.EnumAdApprovalStatus.APPROVED,
3478
- bookingKind: import_cluemart_shared28.EnumAdBookingSlotKind.RESERVED
3844
+ approvalStatus: import_cluemart_shared29.EnumAdApprovalStatus.APPROVED,
3845
+ bookingKind: import_cluemart_shared29.EnumAdBookingSlotKind.RESERVED
3479
3846
  },
3480
3847
  {
3481
- approvalStatus: import_cluemart_shared28.EnumAdApprovalStatus.APPROVED,
3482
- bookingKind: import_cluemart_shared28.EnumAdBookingSlotKind.PAID,
3483
- paymentStatus: import_cluemart_shared28.EnumAdPaymentStatus.PAID
3848
+ approvalStatus: import_cluemart_shared29.EnumAdApprovalStatus.APPROVED,
3849
+ bookingKind: import_cluemart_shared29.EnumAdBookingSlotKind.PAID,
3850
+ paymentStatus: import_cluemart_shared29.EnumAdPaymentStatus.PAID
3484
3851
  }
3485
3852
  ]
3486
3853
  };
3487
3854
  const awaitingApprovalResult = await AdModel.updateMany(
3488
3855
  {
3489
3856
  $nor: eligibleBooking.$or,
3490
- bookingKind: { $in: Object.values(import_cluemart_shared28.EnumAdBookingSlotKind) },
3857
+ bookingKind: { $in: Object.values(import_cluemart_shared29.EnumAdBookingSlotKind) },
3491
3858
  end: { $gt: now },
3492
- status: import_cluemart_shared28.EnumAdStatus.ACTIVE
3859
+ status: import_cluemart_shared29.EnumAdStatus.ACTIVE
3493
3860
  },
3494
- { $set: { status: import_cluemart_shared28.EnumAdStatus.PAUSED } }
3861
+ { $set: { status: import_cluemart_shared29.EnumAdStatus.PAUSED } }
3495
3862
  );
3496
3863
  const activeResult = await AdModel.updateMany(
3497
3864
  {
3498
3865
  end: { $gt: now },
3499
3866
  start: { $lte: now },
3500
- status: { $ne: import_cluemart_shared28.EnumAdStatus.ACTIVE },
3867
+ status: { $ne: import_cluemart_shared29.EnumAdStatus.ACTIVE },
3501
3868
  ...eligibleBooking
3502
3869
  },
3503
- { $set: { status: import_cluemart_shared28.EnumAdStatus.ACTIVE } }
3870
+ { $set: { status: import_cluemart_shared29.EnumAdStatus.ACTIVE } }
3504
3871
  );
3505
3872
  const pausedResult = await AdModel.updateMany(
3506
- { start: { $gt: now }, status: { $ne: import_cluemart_shared28.EnumAdStatus.PAUSED } },
3507
- { $set: { status: import_cluemart_shared28.EnumAdStatus.PAUSED } }
3873
+ { start: { $gt: now }, status: { $ne: import_cluemart_shared29.EnumAdStatus.PAUSED } },
3874
+ { $set: { status: import_cluemart_shared29.EnumAdStatus.PAUSED } }
3508
3875
  );
3509
3876
  console.log(
3510
3877
  `\u2705 Ad statuses updated: invalid=${invalidResult.modifiedCount}, expired=${expiredResult.modifiedCount}, awaitingApproval=${awaitingApprovalResult.modifiedCount}, active=${activeResult.modifiedCount}, paused=${pausedResult.modifiedCount}`
@@ -3512,15 +3879,15 @@ async function updateAdStatuses() {
3512
3879
  }
3513
3880
 
3514
3881
  // src/service/objectIdToString.ts
3515
- var import_mongoose46 = __toESM(require("mongoose"));
3882
+ var import_mongoose47 = __toESM(require("mongoose"));
3516
3883
  function isValidObjectId(value) {
3517
- return import_mongoose46.default.Types.ObjectId.isValid(value);
3884
+ return import_mongoose47.default.Types.ObjectId.isValid(value);
3518
3885
  }
3519
3886
  function convertObjectIdsToStrings(obj) {
3520
3887
  if (obj === null || obj === void 0) {
3521
3888
  return obj;
3522
3889
  }
3523
- if (obj instanceof import_mongoose46.default.Types.ObjectId) {
3890
+ if (obj instanceof import_mongoose47.default.Types.ObjectId) {
3524
3891
  return obj.toString();
3525
3892
  }
3526
3893
  if (obj instanceof Date) {
@@ -3714,19 +4081,19 @@ function buildUserPointEntryRemovalPipeline(pointType, sourceId) {
3714
4081
  }
3715
4082
 
3716
4083
  // src/service/event/updateAllEventDateTimeStatuses.ts
3717
- var import_cluemart_shared30 = require("@timardex/cluemart-shared");
4084
+ var import_cluemart_shared31 = require("@timardex/cluemart-shared");
3718
4085
  var import_dayjs4 = __toESM(require("dayjs"));
3719
4086
 
3720
4087
  // src/service/event/archiveEndedEventDates.ts
3721
- var import_cluemart_shared29 = require("@timardex/cluemart-shared");
4088
+ var import_cluemart_shared30 = require("@timardex/cluemart-shared");
3722
4089
  var import_dayjs3 = __toESM(require("dayjs"));
3723
4090
  var import_customParseFormat = __toESM(require("dayjs/plugin/customParseFormat"));
3724
4091
  import_dayjs3.default.extend(import_customParseFormat.default);
3725
4092
  var ARCHIVED_STATUSES = /* @__PURE__ */ new Set([
3726
- import_cluemart_shared29.EnumEventDateStatus.ENDED
4093
+ import_cluemart_shared30.EnumEventDateStatus.ENDED
3727
4094
  ]);
3728
4095
  var DISCARDED_STATUSES = /* @__PURE__ */ new Set([
3729
- import_cluemart_shared29.EnumEventDateStatus.INVALID
4096
+ import_cluemart_shared30.EnumEventDateStatus.INVALID
3730
4097
  ]);
3731
4098
  function splitEventDatesForArchive(dateTime) {
3732
4099
  return {
@@ -3749,12 +4116,12 @@ function dedupeArchivedSlotsByStartDateTime(slots) {
3749
4116
  });
3750
4117
  }
3751
4118
  function isPastCanceledEventDate(slot, now) {
3752
- if (slot.dateStatus !== import_cluemart_shared29.EnumEventDateStatus.CANCELED) {
4119
+ if (slot.dateStatus !== import_cluemart_shared30.EnumEventDateStatus.CANCELED) {
3753
4120
  return false;
3754
4121
  }
3755
4122
  const endDateTime = (0, import_dayjs3.default)(
3756
4123
  `${slot.endDate} ${slot.endTime}`,
3757
- `${import_cluemart_shared29.dateFormat} ${import_cluemart_shared29.timeFormat}`,
4124
+ `${import_cluemart_shared30.dateFormat} ${import_cluemart_shared30.timeFormat}`,
3758
4125
  true
3759
4126
  );
3760
4127
  return endDateTime.isValid() && endDateTime.isBefore(now);
@@ -3800,7 +4167,7 @@ async function updateModelDateTimeStatuses(model, now) {
3800
4167
  try {
3801
4168
  for await (const doc of cursor) {
3802
4169
  const dateTime = doc.dateTime.map(
3803
- (slot) => (0, import_cluemart_shared30.updateSingleDateTimeStatus)(slot, now)
4170
+ (slot) => (0, import_cluemart_shared31.updateSingleDateTimeStatus)(slot, now)
3804
4171
  );
3805
4172
  if (!hasDateTimeStatusChanges(doc.dateTime, dateTime)) {
3806
4173
  continue;
@@ -3824,9 +4191,9 @@ async function updateModelDateTimeStatuses(model, now) {
3824
4191
  var ARCHIVABLE_EVENT_FILTER = {
3825
4192
  "dateTime.dateStatus": {
3826
4193
  $in: [
3827
- import_cluemart_shared30.EnumEventDateStatus.ENDED,
3828
- import_cluemart_shared30.EnumEventDateStatus.INVALID,
3829
- import_cluemart_shared30.EnumEventDateStatus.CANCELED
4194
+ import_cluemart_shared31.EnumEventDateStatus.ENDED,
4195
+ import_cluemart_shared31.EnumEventDateStatus.INVALID,
4196
+ import_cluemart_shared31.EnumEventDateStatus.CANCELED
3830
4197
  ]
3831
4198
  },
3832
4199
  deletedAt: null
@@ -3851,7 +4218,7 @@ async function archiveEndedAndDiscardInvalidEventDates(now) {
3851
4218
  try {
3852
4219
  for await (const doc of cursor) {
3853
4220
  const updated = doc.dateTime.map(
3854
- (slot) => (0, import_cluemart_shared30.updateSingleDateTimeStatus)(slot, now)
4221
+ (slot) => (0, import_cluemart_shared31.updateSingleDateTimeStatus)(slot, now)
3855
4222
  );
3856
4223
  const { archive, discard } = splitEventDatesForArchive(updated);
3857
4224
  const pastCanceled = updated.filter(
@@ -3875,13 +4242,13 @@ async function archiveEndedAndDiscardInvalidEventDates(now) {
3875
4242
  if (archive.length > 0 || discard.length > 0) {
3876
4243
  pullConditions.push({
3877
4244
  dateStatus: {
3878
- $in: [import_cluemart_shared30.EnumEventDateStatus.ENDED, import_cluemart_shared30.EnumEventDateStatus.INVALID]
4245
+ $in: [import_cluemart_shared31.EnumEventDateStatus.ENDED, import_cluemart_shared31.EnumEventDateStatus.INVALID]
3879
4246
  }
3880
4247
  });
3881
4248
  }
3882
4249
  for (const slot of pastCanceled) {
3883
4250
  pullConditions.push({
3884
- dateStatus: import_cluemart_shared30.EnumEventDateStatus.CANCELED,
4251
+ dateStatus: import_cluemart_shared31.EnumEventDateStatus.CANCELED,
3885
4252
  startDate: slot.startDate,
3886
4253
  startTime: slot.startTime
3887
4254
  });
@@ -3923,9 +4290,9 @@ async function cleanEventInfoDates(now) {
3923
4290
  try {
3924
4291
  for await (const doc of cursor) {
3925
4292
  const updated = doc.dateTime.map(
3926
- (slot) => (0, import_cluemart_shared30.updateSingleDateTimeStatus)(slot, now)
4293
+ (slot) => (0, import_cluemart_shared31.updateSingleDateTimeStatus)(slot, now)
3927
4294
  );
3928
- const kept = (0, import_cluemart_shared30.filterDatesByFutureStatus)(updated);
4295
+ const kept = (0, import_cluemart_shared31.filterDatesByFutureStatus)(updated);
3929
4296
  if (kept.length === updated.length) {
3930
4297
  continue;
3931
4298
  }
@@ -3975,7 +4342,7 @@ async function updateAllEventDateTimeStatuses() {
3975
4342
  }
3976
4343
 
3977
4344
  // src/service/index.ts
3978
- var import_cluemart_shared38 = require("@timardex/cluemart-shared");
4345
+ var import_cluemart_shared39 = require("@timardex/cluemart-shared");
3979
4346
 
3980
4347
  // src/service/event/findEventOrImportedMarketById.ts
3981
4348
  async function findEventOrImportedMarketById(resourceId) {
@@ -3992,7 +4359,7 @@ async function findEventOrImportedMarketById(resourceId) {
3992
4359
  }
3993
4360
 
3994
4361
  // src/service/relations.ts
3995
- var import_cluemart_shared31 = require("@timardex/cluemart-shared");
4362
+ var import_cluemart_shared32 = require("@timardex/cluemart-shared");
3996
4363
  function didRemoveAnyEventDates(previousDateTime, nextDateTime) {
3997
4364
  if (!previousDateTime?.length) {
3998
4365
  return false;
@@ -4008,8 +4375,8 @@ function didRemoveAnyStartedDates(previousDateTime, nextDateTime) {
4008
4375
  return false;
4009
4376
  }
4010
4377
  return previousDateTime.some(
4011
- (prev) => prev.dateStatus === import_cluemart_shared31.EnumEventDateStatus.STARTED && !nextDateTime?.some(
4012
- (next) => next.startDate === prev.startDate && next.startTime === prev.startTime && next.dateStatus === import_cluemart_shared31.EnumEventDateStatus.STARTED
4378
+ (prev) => prev.dateStatus === import_cluemart_shared32.EnumEventDateStatus.STARTED && !nextDateTime?.some(
4379
+ (next) => next.startDate === prev.startDate && next.startTime === prev.startTime && next.dateStatus === import_cluemart_shared32.EnumEventDateStatus.STARTED
4013
4380
  )
4014
4381
  );
4015
4382
  }
@@ -4020,7 +4387,7 @@ function updateRelationDatesToCanceled(relationDates, eventDateTime) {
4020
4387
  ) ?? false;
4021
4388
  return {
4022
4389
  ...relationDate,
4023
- status: existsInEvent ? relationDate.status : import_cluemart_shared31.EnumInviteStatus.CANCELED
4390
+ status: existsInEvent ? relationDate.status : import_cluemart_shared32.EnumInviteStatus.CANCELED
4024
4391
  };
4025
4392
  });
4026
4393
  }
@@ -4029,15 +4396,15 @@ function updateRelationDatesToCanceled(relationDates, eventDateTime) {
4029
4396
  var import_dayjs8 = __toESM(require("dayjs"));
4030
4397
 
4031
4398
  // src/service/license/compliance/utils.ts
4032
- var import_cluemart_shared36 = require("@timardex/cluemart-shared");
4399
+ var import_cluemart_shared37 = require("@timardex/cluemart-shared");
4033
4400
  var import_dayjs7 = __toESM(require("dayjs"));
4034
4401
 
4035
4402
  // src/service/license/compliance/event.ts
4036
- var import_cluemart_shared32 = require("@timardex/cluemart-shared");
4403
+ var import_cluemart_shared33 = require("@timardex/cluemart-shared");
4037
4404
  var eventLicences = [
4038
- import_cluemart_shared32.EnumUserLicence.STANDARD_EVENT,
4039
- import_cluemart_shared32.EnumUserLicence.PRO_EVENT,
4040
- import_cluemart_shared32.EnumUserLicence.PRO_PLUS_EVENT
4405
+ import_cluemart_shared33.EnumUserLicence.STANDARD_EVENT,
4406
+ import_cluemart_shared33.EnumUserLicence.PRO_EVENT,
4407
+ import_cluemart_shared33.EnumUserLicence.PRO_PLUS_EVENT
4041
4408
  ];
4042
4409
  async function handleEventLicenceCompliance(user, now) {
4043
4410
  if (!user.licences || !user.events?.length) {
@@ -4249,9 +4616,9 @@ function buildLicenceExpiryPipeline(params) {
4249
4616
  }
4250
4617
 
4251
4618
  // src/service/license/compliance/partner.ts
4252
- var import_cluemart_shared33 = require("@timardex/cluemart-shared");
4619
+ var import_cluemart_shared34 = require("@timardex/cluemart-shared");
4253
4620
  var partnerLicences = [
4254
- import_cluemart_shared33.EnumUserLicence.STANDARD_PARTNER
4621
+ import_cluemart_shared34.EnumUserLicence.STANDARD_PARTNER
4255
4622
  ];
4256
4623
  async function handlePartnerLicenceCompliance(user, now) {
4257
4624
  if (!user.licences || !user.partner) {
@@ -4261,52 +4628,62 @@ async function handlePartnerLicenceCompliance(user, now) {
4261
4628
  }
4262
4629
 
4263
4630
  // src/service/license/compliance/vendor.ts
4264
- var import_cluemart_shared35 = require("@timardex/cluemart-shared");
4631
+ var import_cluemart_shared36 = require("@timardex/cluemart-shared");
4265
4632
  var import_dayjs6 = __toESM(require("dayjs"));
4266
4633
 
4267
4634
  // src/service/license/models.ts
4268
- var import_cluemart_shared34 = require("@timardex/cluemart-shared");
4635
+ var import_cluemart_shared35 = require("@timardex/cluemart-shared");
4269
4636
  var import_dayjs5 = __toESM(require("dayjs"));
4270
4637
  var import_graphql = require("graphql");
4271
- var LicenceCategory = /* @__PURE__ */ ((LicenceCategory2) => {
4272
- LicenceCategory2["EVENT"] = "event";
4273
- LicenceCategory2["PARTNER"] = "partner";
4274
- LicenceCategory2["VENDOR"] = "vendor";
4275
- LicenceCategory2["AFFILIATE"] = "affiliate";
4276
- LicenceCategory2["SCHOOL"] = "school";
4277
- return LicenceCategory2;
4638
+ var LicenceCategory = /* @__PURE__ */ ((LicenceCategory3) => {
4639
+ LicenceCategory3["EVENT"] = "event";
4640
+ LicenceCategory3["PARTNER"] = "partner";
4641
+ LicenceCategory3["VENDOR"] = "vendor";
4642
+ LicenceCategory3["AFFILIATE"] = "affiliate";
4643
+ LicenceCategory3["SCHOOL"] = "school";
4644
+ return LicenceCategory3;
4278
4645
  })(LicenceCategory || {});
4279
4646
  var licenceCategoryMapping = {
4280
- [import_cluemart_shared34.EnumUserLicence.PRO_EVENT]: "event" /* EVENT */,
4281
- [import_cluemart_shared34.EnumUserLicence.PRO_PLUS_EVENT]: "event" /* EVENT */,
4282
- [import_cluemart_shared34.EnumUserLicence.PRO_PLUS_VENDOR]: "vendor" /* VENDOR */,
4283
- [import_cluemart_shared34.EnumUserLicence.PRO_VENDOR]: "vendor" /* VENDOR */,
4284
- [import_cluemart_shared34.EnumUserLicence.STANDARD_EVENT]: "event" /* EVENT */,
4285
- [import_cluemart_shared34.EnumUserLicence.STANDARD_PARTNER]: "partner" /* PARTNER */,
4286
- [import_cluemart_shared34.EnumUserLicence.STANDARD_VENDOR]: "vendor" /* VENDOR */,
4287
- [import_cluemart_shared34.EnumUserLicence.STANDARD_AFFILIATE]: "affiliate" /* AFFILIATE */,
4288
- [import_cluemart_shared34.EnumUserLicence.STANDARD_SCHOOL]: "school" /* SCHOOL */
4647
+ [import_cluemart_shared35.EnumUserLicence.PRO_EVENT]: "event" /* EVENT */,
4648
+ [import_cluemart_shared35.EnumUserLicence.PRO_PLUS_EVENT]: "event" /* EVENT */,
4649
+ [import_cluemart_shared35.EnumUserLicence.PRO_PLUS_VENDOR]: "vendor" /* VENDOR */,
4650
+ [import_cluemart_shared35.EnumUserLicence.PRO_VENDOR]: "vendor" /* VENDOR */,
4651
+ [import_cluemart_shared35.EnumUserLicence.STANDARD_EVENT]: "event" /* EVENT */,
4652
+ [import_cluemart_shared35.EnumUserLicence.STANDARD_PARTNER]: "partner" /* PARTNER */,
4653
+ [import_cluemart_shared35.EnumUserLicence.STANDARD_VENDOR]: "vendor" /* VENDOR */,
4654
+ [import_cluemart_shared35.EnumUserLicence.STANDARD_AFFILIATE]: "affiliate" /* AFFILIATE */,
4655
+ [import_cluemart_shared35.EnumUserLicence.STANDARD_SCHOOL]: "school" /* SCHOOL */
4289
4656
  };
4290
4657
  var licencePriority = {
4291
- [import_cluemart_shared34.EnumUserLicence.PRO_PLUS_EVENT]: 3,
4292
- [import_cluemart_shared34.EnumUserLicence.PRO_EVENT]: 2,
4293
- [import_cluemart_shared34.EnumUserLicence.STANDARD_EVENT]: 1,
4294
- [import_cluemart_shared34.EnumUserLicence.PRO_PLUS_VENDOR]: 3,
4295
- [import_cluemart_shared34.EnumUserLicence.PRO_VENDOR]: 2,
4296
- [import_cluemart_shared34.EnumUserLicence.STANDARD_VENDOR]: 1,
4297
- [import_cluemart_shared34.EnumUserLicence.STANDARD_PARTNER]: 1,
4298
- [import_cluemart_shared34.EnumUserLicence.STANDARD_AFFILIATE]: 1,
4299
- [import_cluemart_shared34.EnumUserLicence.STANDARD_SCHOOL]: 1
4658
+ [import_cluemart_shared35.EnumUserLicence.PRO_PLUS_EVENT]: 3,
4659
+ [import_cluemart_shared35.EnumUserLicence.PRO_EVENT]: 2,
4660
+ [import_cluemart_shared35.EnumUserLicence.STANDARD_EVENT]: 1,
4661
+ [import_cluemart_shared35.EnumUserLicence.PRO_PLUS_VENDOR]: 3,
4662
+ [import_cluemart_shared35.EnumUserLicence.PRO_VENDOR]: 2,
4663
+ [import_cluemart_shared35.EnumUserLicence.STANDARD_VENDOR]: 1,
4664
+ [import_cluemart_shared35.EnumUserLicence.STANDARD_PARTNER]: 1,
4665
+ [import_cluemart_shared35.EnumUserLicence.STANDARD_AFFILIATE]: 1,
4666
+ [import_cluemart_shared35.EnumUserLicence.STANDARD_SCHOOL]: 1
4300
4667
  };
4301
4668
  var standardLicences = [
4302
- import_cluemart_shared34.EnumUserLicence.STANDARD_VENDOR,
4303
- import_cluemart_shared34.EnumUserLicence.STANDARD_EVENT,
4304
- import_cluemart_shared34.EnumUserLicence.STANDARD_PARTNER
4669
+ import_cluemart_shared35.EnumUserLicence.STANDARD_VENDOR,
4670
+ import_cluemart_shared35.EnumUserLicence.STANDARD_EVENT,
4671
+ import_cluemart_shared35.EnumUserLicence.STANDARD_PARTNER
4305
4672
  ];
4306
4673
  var standardLicenceSet = new Set(standardLicences);
4307
4674
  function isStandardLicence(licence) {
4308
4675
  return standardLicenceSet.has(licence);
4309
4676
  }
4677
+ var proLicences = [
4678
+ import_cluemart_shared35.EnumUserLicence.PRO_EVENT,
4679
+ import_cluemart_shared35.EnumUserLicence.PRO_PLUS_EVENT,
4680
+ import_cluemart_shared35.EnumUserLicence.PRO_VENDOR,
4681
+ import_cluemart_shared35.EnumUserLicence.PRO_PLUS_VENDOR
4682
+ ];
4683
+ var proLicenceSet = new Set(proLicences);
4684
+ function isProLicence(licence) {
4685
+ return proLicenceSet.has(licence);
4686
+ }
4310
4687
  var categoryRegexMapping = {
4311
4688
  ["event" /* EVENT */]: /_event$/,
4312
4689
  ["partner" /* PARTNER */]: /_partner$/,
@@ -4315,11 +4692,11 @@ var categoryRegexMapping = {
4315
4692
  ["school" /* SCHOOL */]: /_school$/
4316
4693
  };
4317
4694
  var categoryFallbackLicence = {
4318
- ["event" /* EVENT */]: import_cluemart_shared34.EnumUserLicence.STANDARD_EVENT,
4319
- ["partner" /* PARTNER */]: import_cluemart_shared34.EnumUserLicence.STANDARD_PARTNER,
4320
- ["vendor" /* VENDOR */]: import_cluemart_shared34.EnumUserLicence.STANDARD_VENDOR,
4321
- ["affiliate" /* AFFILIATE */]: import_cluemart_shared34.EnumUserLicence.STANDARD_AFFILIATE,
4322
- ["school" /* SCHOOL */]: import_cluemart_shared34.EnumUserLicence.STANDARD_SCHOOL
4695
+ ["event" /* EVENT */]: import_cluemart_shared35.EnumUserLicence.STANDARD_EVENT,
4696
+ ["partner" /* PARTNER */]: import_cluemart_shared35.EnumUserLicence.STANDARD_PARTNER,
4697
+ ["vendor" /* VENDOR */]: import_cluemart_shared35.EnumUserLicence.STANDARD_VENDOR,
4698
+ ["affiliate" /* AFFILIATE */]: import_cluemart_shared35.EnumUserLicence.STANDARD_AFFILIATE,
4699
+ ["school" /* SCHOOL */]: import_cluemart_shared35.EnumUserLicence.STANDARD_SCHOOL
4323
4700
  };
4324
4701
  var LicenceFilterInput = {
4325
4702
  INPUT_USER_LICENCES: "$licences"
@@ -4349,11 +4726,11 @@ function getHighestLicenceForCategory(licences, category) {
4349
4726
  function createLicenceObject(expiryDate, licenceType) {
4350
4727
  const today = (0, import_dayjs5.default)();
4351
4728
  const expiryDateMapping = {
4352
- [import_cluemart_shared34.LicenceExpiryDate.ONE_YEAR]: today.add(1, "year").endOf("day").toDate(),
4353
- [import_cluemart_shared34.LicenceExpiryDate.ONE_MONTH]: today.add(1, "month").endOf("day").toDate(),
4354
- [import_cluemart_shared34.LicenceExpiryDate.TWO_MONTHS]: today.add(2, "month").endOf("day").toDate(),
4355
- [import_cluemart_shared34.LicenceExpiryDate.THREE_MONTHS]: today.add(3, "month").endOf("day").toDate(),
4356
- [import_cluemart_shared34.LicenceExpiryDate.SIX_MONTHS]: today.add(6, "month").endOf("day").toDate()
4729
+ [import_cluemart_shared35.LicenceExpiryDate.ONE_YEAR]: today.add(1, "year").endOf("day").toDate(),
4730
+ [import_cluemart_shared35.LicenceExpiryDate.ONE_MONTH]: today.add(1, "month").endOf("day").toDate(),
4731
+ [import_cluemart_shared35.LicenceExpiryDate.TWO_MONTHS]: today.add(2, "month").endOf("day").toDate(),
4732
+ [import_cluemart_shared35.LicenceExpiryDate.THREE_MONTHS]: today.add(3, "month").endOf("day").toDate(),
4733
+ [import_cluemart_shared35.LicenceExpiryDate.SIX_MONTHS]: today.add(6, "month").endOf("day").toDate()
4357
4734
  };
4358
4735
  const licenceObject = {
4359
4736
  expiryDate: expiryDateMapping[expiryDate],
@@ -4457,13 +4834,13 @@ async function checkOwnerHasLicence({
4457
4834
  const owner = await UserModel.findById(userId);
4458
4835
  if (!owner) throw new import_graphql.GraphQLError("Owner not found");
4459
4836
  const categoryByResource = {
4460
- [import_cluemart_shared34.EnumResourceType.EVENT]: "event" /* EVENT */,
4461
- [import_cluemart_shared34.EnumResourceType.PARTNER]: "partner" /* PARTNER */,
4462
- [import_cluemart_shared34.EnumResourceType.VENDOR]: "vendor" /* VENDOR */,
4463
- [import_cluemart_shared34.EnumResourceType.AFFILIATE]: "affiliate" /* AFFILIATE */,
4464
- [import_cluemart_shared34.EnumResourceType.SCHOOL]: "school" /* SCHOOL */
4837
+ [import_cluemart_shared35.EnumResourceType.EVENT]: "event" /* EVENT */,
4838
+ [import_cluemart_shared35.EnumResourceType.PARTNER]: "partner" /* PARTNER */,
4839
+ [import_cluemart_shared35.EnumResourceType.VENDOR]: "vendor" /* VENDOR */,
4840
+ [import_cluemart_shared35.EnumResourceType.AFFILIATE]: "affiliate" /* AFFILIATE */,
4841
+ [import_cluemart_shared35.EnumResourceType.SCHOOL]: "school" /* SCHOOL */
4465
4842
  };
4466
- if (!(0, import_cluemart_shared34.isNonVisitorResourceType)(resourceType)) {
4843
+ if (!(0, import_cluemart_shared35.isNonVisitorResourceType)(resourceType)) {
4467
4844
  throw new import_graphql.GraphQLError(`Invalid resource type: ${resourceType}.`);
4468
4845
  }
4469
4846
  const requiredCategory = categoryByResource[resourceType];
@@ -4485,6 +4862,128 @@ async function checkOwnerHasLicence({
4485
4862
  );
4486
4863
  }
4487
4864
  }
4865
+ var resourceLicenceCategory = {
4866
+ [import_cluemart_shared35.EnumResourceType.EVENT]: "event" /* EVENT */,
4867
+ [import_cluemart_shared35.EnumResourceType.PARTNER]: "partner" /* PARTNER */,
4868
+ [import_cluemart_shared35.EnumResourceType.VENDOR]: "vendor" /* VENDOR */
4869
+ };
4870
+ function isProtectedByCurrentStripeSubscription(user, licenceType, now) {
4871
+ const stripe = user.stripe;
4872
+ if (!stripe || stripe.currentPlan !== licenceType) {
4873
+ return false;
4874
+ }
4875
+ const gracePeriodEndsAt = stripe.paymentGracePeriodEndsAt ? (0, import_dayjs5.default)(stripe.paymentGracePeriodEndsAt) : null;
4876
+ const hasActivePaymentGracePeriod = (stripe.status === import_cluemart_shared35.EnumSubscriptionStatus.PAST_DUE || stripe.status === import_cluemart_shared35.EnumSubscriptionStatus.INACTIVE) && Boolean(stripe.paymentGraceSubscriptionId) && (!stripe.subscriptionId || stripe.subscriptionId === stripe.paymentGraceSubscriptionId) && gracePeriodEndsAt !== null && gracePeriodEndsAt.isValid() && gracePeriodEndsAt.isAfter(now);
4877
+ if (hasActivePaymentGracePeriod) {
4878
+ return true;
4879
+ }
4880
+ if (!stripe.subscriptionId) {
4881
+ return false;
4882
+ }
4883
+ if (stripe.status !== import_cluemart_shared35.EnumSubscriptionStatus.ACTIVE) {
4884
+ return false;
4885
+ }
4886
+ if (!stripe.endDate) {
4887
+ return false;
4888
+ }
4889
+ const paidThrough = (0, import_dayjs5.default)(stripe.endDate);
4890
+ return paidThrough.isValid() && paidThrough.isAfter(now);
4891
+ }
4892
+ function effectiveLicences({
4893
+ includeStripeProtected = false,
4894
+ licences,
4895
+ now,
4896
+ owner
4897
+ }) {
4898
+ const nowDayjs = (0, import_dayjs5.default)(now);
4899
+ return (licences ?? []).filter((licence) => {
4900
+ if (!licence.licenceType || licence.expiryDate == null) {
4901
+ return false;
4902
+ }
4903
+ if (new Date(licence.expiryDate).getTime() > now.getTime()) {
4904
+ return true;
4905
+ }
4906
+ return Boolean(
4907
+ includeStripeProtected && owner && isProtectedByCurrentStripeSubscription(
4908
+ owner,
4909
+ licence.licenceType,
4910
+ nowDayjs
4911
+ )
4912
+ );
4913
+ });
4914
+ }
4915
+ async function getActiveLicenceForResource({
4916
+ includeStripeProtected = false,
4917
+ userId,
4918
+ resourceType,
4919
+ now = /* @__PURE__ */ new Date()
4920
+ }) {
4921
+ const category = resourceLicenceCategory[resourceType];
4922
+ if (!category) {
4923
+ return null;
4924
+ }
4925
+ const owner = await UserModel.findById(userId, {
4926
+ licences: 1,
4927
+ ...includeStripeProtected ? { stripe: 1 } : {}
4928
+ }).lean();
4929
+ if (!owner?.licences?.length) {
4930
+ return null;
4931
+ }
4932
+ return getHighestLicenceForCategory(
4933
+ effectiveLicences({
4934
+ includeStripeProtected,
4935
+ licences: owner.licences,
4936
+ now,
4937
+ owner
4938
+ }),
4939
+ category
4940
+ );
4941
+ }
4942
+ async function getUserIdsWithActiveProLicence({
4943
+ includeStripeProtected = false,
4944
+ resourceType,
4945
+ userIds,
4946
+ now = /* @__PURE__ */ new Date()
4947
+ }) {
4948
+ const category = resourceLicenceCategory[resourceType];
4949
+ if (!category || userIds.length === 0) {
4950
+ return /* @__PURE__ */ new Set();
4951
+ }
4952
+ const owners = await UserModel.find(
4953
+ { _id: { $in: userIds } },
4954
+ { licences: 1, ...includeStripeProtected ? { stripe: 1 } : {} }
4955
+ ).lean();
4956
+ const allowed = /* @__PURE__ */ new Set();
4957
+ for (const owner of owners ?? []) {
4958
+ const activeLicence = getHighestLicenceForCategory(
4959
+ effectiveLicences({
4960
+ includeStripeProtected,
4961
+ licences: owner.licences,
4962
+ now,
4963
+ owner
4964
+ }),
4965
+ category
4966
+ );
4967
+ if (activeLicence && isProLicence(activeLicence)) {
4968
+ allowed.add(String(owner._id));
4969
+ }
4970
+ }
4971
+ return allowed;
4972
+ }
4973
+ async function hasActiveProLicenceForResource({
4974
+ includeStripeProtected = false,
4975
+ userId,
4976
+ resourceType,
4977
+ now = /* @__PURE__ */ new Date()
4978
+ }) {
4979
+ const activeLicence = await getActiveLicenceForResource({
4980
+ includeStripeProtected,
4981
+ now,
4982
+ resourceType,
4983
+ userId
4984
+ });
4985
+ return activeLicence !== null && isProLicence(activeLicence);
4986
+ }
4488
4987
 
4489
4988
  // src/service/license/compliance/vendor.ts
4490
4989
  async function findUserVendor(userId, logLabel) {
@@ -4543,7 +5042,7 @@ async function applyVendorDowngrade(vendor, ownerUserId) {
4543
5042
  return (result?.matchedCount ?? 0) > 0;
4544
5043
  }
4545
5044
  async function downgradeVendorProFeatures(userId, licenceType) {
4546
- const isStandardVendor = licenceType === import_cluemart_shared35.EnumUserLicence.STANDARD_VENDOR;
5045
+ const isStandardVendor = licenceType === import_cluemart_shared36.EnumUserLicence.STANDARD_VENDOR;
4547
5046
  if (!isStandardVendor) {
4548
5047
  return;
4549
5048
  }
@@ -4590,7 +5089,7 @@ async function applyVendorRestore(vendor, ownerUserId) {
4590
5089
  return (result?.matchedCount ?? 0) > 0;
4591
5090
  }
4592
5091
  async function restoreVendorProFeatures(userId, licenceType) {
4593
- const isProVendor = licenceType === import_cluemart_shared35.EnumUserLicence.PRO_VENDOR || licenceType === import_cluemart_shared35.EnumUserLicence.PRO_PLUS_VENDOR;
5092
+ const isProVendor = licenceType === import_cluemart_shared36.EnumUserLicence.PRO_VENDOR || licenceType === import_cluemart_shared36.EnumUserLicence.PRO_PLUS_VENDOR;
4594
5093
  if (!isProVendor) {
4595
5094
  return;
4596
5095
  }
@@ -4605,28 +5104,6 @@ async function restoreVendorProFeatures(userId, licenceType) {
4605
5104
  throw error;
4606
5105
  }
4607
5106
  }
4608
- function isProtectedByCurrentStripeSubscription(user, licenceType, now) {
4609
- const stripe = user.stripe;
4610
- if (!stripe || stripe.currentPlan !== licenceType) {
4611
- return false;
4612
- }
4613
- const gracePeriodEndsAt = stripe.paymentGracePeriodEndsAt ? (0, import_dayjs6.default)(stripe.paymentGracePeriodEndsAt) : null;
4614
- const hasActivePaymentGracePeriod = (stripe.status === import_cluemart_shared35.EnumSubscriptionStatus.PAST_DUE || stripe.status === import_cluemart_shared35.EnumSubscriptionStatus.INACTIVE) && Boolean(stripe.paymentGraceSubscriptionId) && (!stripe.subscriptionId || stripe.subscriptionId === stripe.paymentGraceSubscriptionId) && gracePeriodEndsAt !== null && gracePeriodEndsAt.isValid() && gracePeriodEndsAt.isAfter(now);
4615
- if (hasActivePaymentGracePeriod) {
4616
- return true;
4617
- }
4618
- if (!stripe.subscriptionId) {
4619
- return false;
4620
- }
4621
- if (stripe.status !== import_cluemart_shared35.EnumSubscriptionStatus.ACTIVE) {
4622
- return false;
4623
- }
4624
- if (!stripe.endDate) {
4625
- return false;
4626
- }
4627
- const paidThrough = (0, import_dayjs6.default)(stripe.endDate);
4628
- return paidThrough.isValid() && paidThrough.isAfter(now);
4629
- }
4630
5107
  async function handleVendorLicenceCompliance(user, now) {
4631
5108
  if (!user.licences || !user.vendor) {
4632
5109
  return;
@@ -4637,10 +5114,10 @@ async function handleVendorLicenceCompliance(user, now) {
4637
5114
  if (vendorLicencesOfUser.length === 0) {
4638
5115
  return;
4639
5116
  }
4640
- const proLicences = vendorLicencesOfUser.filter(
4641
- (licence) => licence.licenceType !== import_cluemart_shared35.EnumUserLicence.STANDARD_VENDOR
5117
+ const proLicences2 = vendorLicencesOfUser.filter(
5118
+ (licence) => licence.licenceType !== import_cluemart_shared36.EnumUserLicence.STANDARD_VENDOR
4642
5119
  );
4643
- const expiredProLicences = proLicences.filter(
5120
+ const expiredProLicences = proLicences2.filter(
4644
5121
  (licence) => !(0, import_dayjs6.default)(licence.expiryDate).isAfter(now)
4645
5122
  );
4646
5123
  const stripeProtectedLicenceTypes = new Set(
@@ -4651,7 +5128,7 @@ async function handleVendorLicenceCompliance(user, now) {
4651
5128
  const expiredProLicence = expiredProLicences.some(
4652
5129
  (licence) => !stripeProtectedLicenceTypes.has(licence.licenceType)
4653
5130
  );
4654
- const hasValidProLicence = stripeProtectedLicenceTypes.size > 0 || hasValidLicence(proLicences, import_cluemart_shared35.vendorLicences, now);
5131
+ const hasValidProLicence = stripeProtectedLicenceTypes.size > 0 || hasValidLicence(proLicences2, import_cluemart_shared36.vendorLicences, now);
4655
5132
  const hasExpiredVendorLicence = vendorLicencesOfUser.some(
4656
5133
  (licence) => !(0, import_dayjs6.default)(licence.expiryDate).isAfter(now) && !stripeProtectedLicenceTypes.has(licence.licenceType)
4657
5134
  );
@@ -4667,7 +5144,7 @@ async function handleVendorLicenceCompliance(user, now) {
4667
5144
  "owner.userId": user._id
4668
5145
  }).lean().exec();
4669
5146
  }
4670
- const licencesToSync = import_cluemart_shared35.vendorLicences.filter(
5147
+ const licencesToSync = import_cluemart_shared36.vendorLicences.filter(
4671
5148
  (licenceType) => !stripeProtectedLicenceTypes.has(licenceType)
4672
5149
  );
4673
5150
  await syncUserLicencesAfterExpiry(user._id, licencesToSync, now, "downgrade");
@@ -4682,11 +5159,11 @@ async function handleVendorLicenceCompliance(user, now) {
4682
5159
  data: {
4683
5160
  resourceId: String(vendor._id),
4684
5161
  resourceName: vendor.name,
4685
- resourceType: import_cluemart_shared35.EnumNotificationResourceType.DOWNGRADED_VENDOR
5162
+ resourceType: import_cluemart_shared36.EnumNotificationResourceType.DOWNGRADED_VENDOR
4686
5163
  },
4687
5164
  message: `Your Vendor licence has been downgraded due to licence expiration.`,
4688
5165
  title: `Vendor Licence Downgraded`,
4689
- type: import_cluemart_shared35.EnumNotificationType.SYSTEM,
5166
+ type: import_cluemart_shared36.EnumNotificationType.SYSTEM,
4690
5167
  userIds: [user._id]
4691
5168
  };
4692
5169
  await sendDeactivationNotification(payload, user._id, vendor.name, "vendor");
@@ -4700,26 +5177,11 @@ async function vendorOwnerHasProLicence(vendorId) {
4700
5177
  if (!vendor) {
4701
5178
  return false;
4702
5179
  }
4703
- const owner = await UserModel.findById(vendor.owner.userId, {
4704
- licences: 1,
4705
- stripe: 1
4706
- }).lean().exec();
4707
- if (!owner) {
4708
- return false;
4709
- }
4710
- const now = (0, import_dayjs6.default)();
4711
- const effectiveVendorLicences = owner.licences?.filter(
4712
- (licence) => licence?.licenceType && ((0, import_dayjs6.default)(licence.expiryDate).isAfter(now) || isProtectedByCurrentStripeSubscription(
4713
- owner,
4714
- licence.licenceType,
4715
- now
4716
- ))
4717
- );
4718
- const highestVendorLicence = getHighestLicenceForCategory(
4719
- effectiveVendorLicences,
4720
- "vendor" /* VENDOR */
4721
- );
4722
- return highestVendorLicence !== null && licencePriority[highestVendorLicence] >= licencePriority[import_cluemart_shared35.EnumUserLicence.PRO_VENDOR];
5180
+ return hasActiveProLicenceForResource({
5181
+ includeStripeProtected: true,
5182
+ resourceType: import_cluemart_shared36.EnumResourceType.VENDOR,
5183
+ userId: vendor.owner.userId
5184
+ });
4723
5185
  }
4724
5186
 
4725
5187
  // src/service/license/compliance/utils.ts
@@ -4729,12 +5191,12 @@ async function syncUserLicencesAfterExpiry(userId, licenceTypes, now, mode = "do
4729
5191
  const pipeline = buildLicenceExpiryPipeline({
4730
5192
  downgradeBranches: [
4731
5193
  {
4732
- case: import_cluemart_shared36.EnumUserLicence.PRO_PLUS_VENDOR,
4733
- then: import_cluemart_shared36.EnumUserLicence.STANDARD_VENDOR
5194
+ case: import_cluemart_shared37.EnumUserLicence.PRO_PLUS_VENDOR,
5195
+ then: import_cluemart_shared37.EnumUserLicence.STANDARD_VENDOR
4734
5196
  },
4735
5197
  {
4736
- case: import_cluemart_shared36.EnumUserLicence.PRO_VENDOR,
4737
- then: import_cluemart_shared36.EnumUserLicence.STANDARD_VENDOR
5198
+ case: import_cluemart_shared37.EnumUserLicence.PRO_VENDOR,
5199
+ then: import_cluemart_shared37.EnumUserLicence.STANDARD_VENDOR
4738
5200
  }
4739
5201
  ],
4740
5202
  licenceTypes,
@@ -4863,7 +5325,7 @@ var REMINDER_WINDOW_MIN_HOURS = 6.5 * 24;
4863
5325
  var REMINDER_WINDOW_MAX_HOURS = 7.5 * 24;
4864
5326
 
4865
5327
  // src/service/license/reminder/utils.ts
4866
- var import_cluemart_shared37 = require("@timardex/cluemart-shared");
5328
+ var import_cluemart_shared38 = require("@timardex/cluemart-shared");
4867
5329
  var import_utils8 = require("@timardex/cluemart-shared/utils");
4868
5330
  var import_dayjs9 = __toESM(require("dayjs"));
4869
5331
 
@@ -4929,28 +5391,28 @@ function isLicenseExpiringIn7Days(expiryDate, now) {
4929
5391
  return hoursUntilExpiry >= REMINDER_WINDOW_MIN_HOURS && hoursUntilExpiry <= REMINDER_WINDOW_MAX_HOURS;
4930
5392
  }
4931
5393
  function getLicenseName(licenceType) {
4932
- return import_cluemart_shared37.licenseNiceNames[licenceType] || licenceType;
5394
+ return import_cluemart_shared38.licenseNiceNames[licenceType] || licenceType;
4933
5395
  }
4934
5396
  function getNotificationTypes(isVendorLicense, isPartnerLicense) {
4935
5397
  if (isVendorLicense) {
4936
5398
  return {
4937
- notificationType: import_cluemart_shared37.EnumNotificationType.SYSTEM,
4938
- resourceType: import_cluemart_shared37.EnumNotificationResourceType.EXPIRATION_REMINDER_VENDOR
5399
+ notificationType: import_cluemart_shared38.EnumNotificationType.SYSTEM,
5400
+ resourceType: import_cluemart_shared38.EnumNotificationResourceType.EXPIRATION_REMINDER_VENDOR
4939
5401
  };
4940
5402
  }
4941
5403
  if (isPartnerLicense) {
4942
5404
  return {
4943
- notificationType: import_cluemart_shared37.EnumNotificationType.SYSTEM,
4944
- resourceType: import_cluemart_shared37.EnumNotificationResourceType.EXPIRATION_REMINDER_PARTNER
5405
+ notificationType: import_cluemart_shared38.EnumNotificationType.SYSTEM,
5406
+ resourceType: import_cluemart_shared38.EnumNotificationResourceType.EXPIRATION_REMINDER_PARTNER
4945
5407
  };
4946
5408
  }
4947
5409
  return {
4948
- notificationType: import_cluemart_shared37.EnumNotificationType.SYSTEM,
4949
- resourceType: import_cluemart_shared37.EnumNotificationResourceType.EXPIRATION_REMINDER_EVENT
5410
+ notificationType: import_cluemart_shared38.EnumNotificationType.SYSTEM,
5411
+ resourceType: import_cluemart_shared38.EnumNotificationResourceType.EXPIRATION_REMINDER_EVENT
4950
5412
  };
4951
5413
  }
4952
5414
  async function getLicenseResourceInfo(user, licence) {
4953
- const isVendorLicense = import_cluemart_shared37.vendorLicences.includes(licence.licenceType);
5415
+ const isVendorLicense = import_cluemart_shared38.vendorLicences.includes(licence.licenceType);
4954
5416
  const isPartnerLicense = partnerLicences.includes(licence.licenceType);
4955
5417
  const licenceName = getLicenseName(licence.licenceType);
4956
5418
  const { notificationType, resourceType } = getNotificationTypes(
@@ -4998,11 +5460,11 @@ async function getLicenseResourceInfo(user, licence) {
4998
5460
  };
4999
5461
  }
5000
5462
  function getLicenceExpiryMode(licenceType) {
5001
- return licenceType === import_cluemart_shared37.EnumUserLicence.PRO_VENDOR || licenceType === import_cluemart_shared37.EnumUserLicence.PRO_PLUS_VENDOR ? "downgrade" : "extend";
5463
+ return licenceType === import_cluemart_shared38.EnumUserLicence.PRO_VENDOR || licenceType === import_cluemart_shared38.EnumUserLicence.PRO_PLUS_VENDOR ? "downgrade" : "extend";
5002
5464
  }
5003
5465
  async function sendLicenseReminder(user, licence) {
5004
5466
  const licenceName = getLicenseName(licence.licenceType);
5005
- const expiryDate = (0, import_dayjs9.default)(licence.expiryDate).format(import_cluemart_shared37.dateFormat);
5467
+ const expiryDate = (0, import_dayjs9.default)(licence.expiryDate).format(import_cluemart_shared38.dateFormat);
5006
5468
  const userId = String(user._id);
5007
5469
  const resourceInfo = await getLicenseResourceInfo(user, licence);
5008
5470
  if (!resourceInfo) {
@@ -5132,6 +5594,7 @@ async function remindUsersAboutLicenseExpiration() {
5132
5594
  REMINDER_WINDOW_MAX_HOURS,
5133
5595
  REMINDER_WINDOW_MIN_HOURS,
5134
5596
  SUBSCRIPTION_REWARD_TIMEZONE,
5597
+ acceptedAssociateUserIds,
5135
5598
  activeAffiliateCodeExists,
5136
5599
  awardAffiliateVendorSubscriptionRewards,
5137
5600
  buildLicenceExpiryPipeline,
@@ -5145,6 +5608,9 @@ async function remindUsersAboutLicenseExpiration() {
5145
5608
  convertObjectIdsToStrings,
5146
5609
  createLicenceObject,
5147
5610
  dedupeArchivedSlotsByStartDateTime,
5611
+ detachAssociateGrantsForResources,
5612
+ detachStaleAssociateGrants,
5613
+ detachUsersFromResource,
5148
5614
  didRemoveAnyEventDates,
5149
5615
  didRemoveAnyStartedDates,
5150
5616
  downgradeVendorProFeatures,
@@ -5154,6 +5620,8 @@ async function remindUsersAboutLicenseExpiration() {
5154
5620
  eventLicences,
5155
5621
  findAffiliateByPromoCode,
5156
5622
  findEventOrImportedMarketById,
5623
+ getActiveLicenceForResource,
5624
+ getAssociateAccessMeta,
5157
5625
  getEventResourceInfo,
5158
5626
  getHighestLicenceForCategory,
5159
5627
  getLicenceCategory,
@@ -5163,11 +5631,17 @@ async function remindUsersAboutLicenseExpiration() {
5163
5631
  getPayingStripeSubscriptionPlan,
5164
5632
  getPayingVendorStripeSubscriptionPlan,
5165
5633
  getSubscriptionRewardPeriodBounds,
5634
+ getUserIdsWithActiveProLicence,
5166
5635
  getVendorResourceInfo,
5636
+ grantAssociateGrants,
5167
5637
  handleEventLicenceCompliance,
5168
5638
  handlePartnerLicenceCompliance,
5169
5639
  handleVendorLicenceCompliance,
5640
+ hasActiveProLicenceForResource,
5170
5641
  hasValidLicence,
5642
+ isAssociableResourceType,
5643
+ isProLicence,
5644
+ isProtectedByCurrentStripeSubscription,
5171
5645
  isStandardLicence,
5172
5646
  isValidObjectId,
5173
5647
  licenceCategoryMapping,
@@ -5182,6 +5656,7 @@ async function remindUsersAboutLicenseExpiration() {
5182
5656
  processUserCompliance,
5183
5657
  processUserLicenseReminders,
5184
5658
  publishNotificationEvents,
5659
+ reconcileAssociateGrants,
5185
5660
  remindUsersAboutLicenseExpiration,
5186
5661
  replaceUserLicenceWithObject,
5187
5662
  restoreVendorProFeatures,