@timardex/cluemart-server-shared 4.1.0 → 4.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.cjs CHANGED
@@ -44,6 +44,7 @@ __export(index_exports, {
44
44
  AiImportRunModel: () => AiImportRunModel,
45
45
  AiImportedMarketModel: () => AiImportedMarketModel,
46
46
  AppSettingModel: () => AppSettingModel,
47
+ AssociateTypeSchema: () => AssociateTypeSchema,
47
48
  AuthHandoffTokenModel: () => AuthHandoffTokenModel,
48
49
  BILLING_CATALOG_COLLECTION_NAME: () => BILLING_CATALOG_COLLECTION_NAME,
49
50
  BillingCatalogModel: () => BillingCatalogModel,
@@ -83,6 +84,7 @@ __export(index_exports, {
83
84
  VendorInfoModel: () => VendorInfoModel,
84
85
  VendorModel: () => VendorModel,
85
86
  VerificationTokenModel: () => VerificationTokenModel,
87
+ acceptedAssociateUserIds: () => acceptedAssociateUserIds,
86
88
  activeAffiliateCodeExists: () => activeAffiliateCodeExists,
87
89
  awardAffiliateVendorSubscriptionRewards: () => awardAffiliateVendorSubscriptionRewards,
88
90
  baseResourceFields: () => baseResourceFields,
@@ -99,6 +101,9 @@ __export(index_exports, {
99
101
  createLicenceObject: () => createLicenceObject,
100
102
  dateTimeSchema: () => dateTimeSchema,
101
103
  dedupeArchivedSlotsByStartDateTime: () => dedupeArchivedSlotsByStartDateTime,
104
+ detachAssociateGrantsForResources: () => detachAssociateGrantsForResources,
105
+ detachStaleAssociateGrants: () => detachStaleAssociateGrants,
106
+ detachUsersFromResource: () => detachUsersFromResource,
102
107
  didRemoveAnyEventDates: () => didRemoveAnyEventDates,
103
108
  didRemoveAnyStartedDates: () => didRemoveAnyStartedDates,
104
109
  downgradeVendorProFeatures: () => downgradeVendorProFeatures,
@@ -109,6 +114,8 @@ __export(index_exports, {
109
114
  express: () => import_express.default,
110
115
  findAffiliateByPromoCode: () => findAffiliateByPromoCode,
111
116
  findEventOrImportedMarketById: () => findEventOrImportedMarketById,
117
+ getActiveLicenceForResource: () => getActiveLicenceForResource,
118
+ getAssociateAccessMeta: () => getAssociateAccessMeta,
112
119
  getBillingCatalogDefinition: () => getBillingCatalogDefinition,
113
120
  getEventResourceInfo: () => getEventResourceInfo,
114
121
  getHighestLicenceForCategory: () => getHighestLicenceForCategory,
@@ -119,11 +126,17 @@ __export(index_exports, {
119
126
  getPayingStripeSubscriptionPlan: () => getPayingStripeSubscriptionPlan,
120
127
  getPayingVendorStripeSubscriptionPlan: () => getPayingVendorStripeSubscriptionPlan,
121
128
  getSubscriptionRewardPeriodBounds: () => getSubscriptionRewardPeriodBounds,
129
+ getUserIdsWithActiveProLicence: () => getUserIdsWithActiveProLicence,
122
130
  getVendorResourceInfo: () => getVendorResourceInfo,
131
+ grantAssociateGrants: () => grantAssociateGrants,
123
132
  handleEventLicenceCompliance: () => handleEventLicenceCompliance,
124
133
  handlePartnerLicenceCompliance: () => handlePartnerLicenceCompliance,
125
134
  handleVendorLicenceCompliance: () => handleVendorLicenceCompliance,
135
+ hasActiveProLicenceForResource: () => hasActiveProLicenceForResource,
126
136
  hasValidLicence: () => hasValidLicence,
137
+ isAssociableResourceType: () => isAssociableResourceType,
138
+ isProLicence: () => isProLicence,
139
+ isProtectedByCurrentStripeSubscription: () => isProtectedByCurrentStripeSubscription,
127
140
  isStandardLicence: () => isStandardLicence,
128
141
  isValidObjectId: () => isValidObjectId,
129
142
  licenceCategoryMapping: () => licenceCategoryMapping,
@@ -131,7 +144,7 @@ __export(index_exports, {
131
144
  locationGeoSchema: () => locationGeoSchema,
132
145
  locationsSchema: () => locationsSchema,
133
146
  mapVendorLicenceToSubscriptionRewardType: () => mapVendorLicenceToSubscriptionRewardType,
134
- mongoose: () => import_mongoose44.default,
147
+ mongoose: () => import_mongoose45.default,
135
148
  normalizeAffiliatePromoCodes: () => normalizeAffiliatePromoCodes,
136
149
  normalizePromoCode: () => normalizePromoCode,
137
150
  notifyUsers: () => notifyUsers,
@@ -141,6 +154,7 @@ __export(index_exports, {
141
154
  processUserCompliance: () => processUserCompliance,
142
155
  processUserLicenseReminders: () => processUserLicenseReminders,
143
156
  publishNotificationEvents: () => publishNotificationEvents,
157
+ reconcileAssociateGrants: () => reconcileAssociateGrants,
144
158
  refundPolicySchema: () => refundPolicySchema,
145
159
  relatedPostSchema: () => relatedPostSchema,
146
160
  relationDatesSchema: () => relationDatesSchema,
@@ -160,7 +174,7 @@ __export(index_exports, {
160
174
  updateAdStatuses: () => updateAdStatuses,
161
175
  updateAllEventDateTimeStatuses: () => updateAllEventDateTimeStatuses,
162
176
  updateRelationDatesToCanceled: () => updateRelationDatesToCanceled,
163
- updateSingleDateTimeStatus: () => import_cluemart_shared38.updateSingleDateTimeStatus,
177
+ updateSingleDateTimeStatus: () => import_cluemart_shared39.updateSingleDateTimeStatus,
164
178
  upgradeUserToLicence: () => upgradeUserToLicence,
165
179
  userLicenseSchema: () => userLicenseSchema,
166
180
  vendorOwnerHasProLicence: () => vendorOwnerHasProLicence,
@@ -850,6 +864,25 @@ var OwnerTypeSchema = new MongooseSchema5(
850
864
  { _id: false }
851
865
  // Prevents Mongoose from creating an additional _id field for subdocuments
852
866
  );
867
+ var AssociateTypeSchema = new MongooseSchema5(
868
+ {
869
+ addedAt: { default: Date.now, required: false, type: Date },
870
+ email: { lowercase: true, required: true, trim: true, type: String },
871
+ respondedAt: { default: null, required: false, type: Date },
872
+ status: {
873
+ default: import_cluemart_shared8.EnumAssociateStatus.PENDING,
874
+ enum: Object.values(import_cluemart_shared8.EnumAssociateStatus),
875
+ required: true,
876
+ type: String
877
+ },
878
+ userId: {
879
+ ref: "User",
880
+ required: true,
881
+ type: import_mongoose9.default.Schema.Types.ObjectId
882
+ }
883
+ },
884
+ { _id: false }
885
+ );
853
886
  var SocialMediaTypeSchema = new MongooseSchema5(
854
887
  {
855
888
  link: { required: true, type: String },
@@ -1015,6 +1048,7 @@ var baseResourceFields = {
1015
1048
  type: [import_mongoose9.default.Schema.Types.ObjectId]
1016
1049
  },
1017
1050
  approvedAt: { default: null, required: false, type: Date },
1051
+ associates: { default: [], required: false, type: [AssociateTypeSchema] },
1018
1052
  contactDetails: { required: false, type: ContactDetailsSchema },
1019
1053
  cover: {
1020
1054
  required: true,
@@ -1896,6 +1930,29 @@ var userOverallPointsSchema = new MongooseSchema16(
1896
1930
  },
1897
1931
  { _id: false }
1898
1932
  );
1933
+ var userAssociatedResourcesSchema = new MongooseSchema16(
1934
+ {
1935
+ events: {
1936
+ default: [],
1937
+ ref: "Event",
1938
+ required: false,
1939
+ type: [import_mongoose20.default.Schema.Types.ObjectId]
1940
+ },
1941
+ partners: {
1942
+ default: [],
1943
+ ref: "Partner",
1944
+ required: false,
1945
+ type: [import_mongoose20.default.Schema.Types.ObjectId]
1946
+ },
1947
+ vendors: {
1948
+ default: [],
1949
+ ref: "Vendor",
1950
+ required: false,
1951
+ type: [import_mongoose20.default.Schema.Types.ObjectId]
1952
+ }
1953
+ },
1954
+ { _id: false }
1955
+ );
1899
1956
  var schema15 = new MongooseSchema16(
1900
1957
  {
1901
1958
  active: { default: false, required: true, type: Boolean },
@@ -1904,6 +1961,11 @@ var schema15 = new MongooseSchema16(
1904
1961
  required: false,
1905
1962
  type: import_mongoose20.default.Schema.Types.ObjectId
1906
1963
  },
1964
+ associatedResources: {
1965
+ default: () => ({ events: [], partners: [], vendors: [] }),
1966
+ required: false,
1967
+ type: userAssociatedResourcesSchema
1968
+ },
1907
1969
  avatar: {
1908
1970
  required: false,
1909
1971
  type: ResourceImageTypeSchema
@@ -1914,7 +1976,10 @@ var schema15 = new MongooseSchema16(
1914
1976
  type: import_mongoose20.default.Schema.Types.ObjectId
1915
1977
  },
1916
1978
  deletedAt: { default: null, required: false, type: Date },
1917
- email: { required: true, type: String },
1979
+ // `normalizeEmail` (`cluemart-shared`) is trim + lower-case; keeping the same
1980
+ // rule here means every write path — resolvers, seeds, scripts — stores the
1981
+ // comparable form, not only the clients that validate through `emailRequiredSchema`.
1982
+ email: { lowercase: true, required: true, trim: true, type: String },
1918
1983
  emailSentFor: {
1919
1984
  enum: Object.values(import_cluemart_shared16.EnumNotificationResourceType),
1920
1985
  required: false,
@@ -2029,6 +2094,9 @@ schema15.index({ "licences.expiryDate": 1 });
2029
2094
  schema15.index({ "licences.licenceType": 1 });
2030
2095
  schema15.index({ promoCodes: 1, active: 1, deletedAt: 1 });
2031
2096
  schema15.index({ email: "text", firstName: "text", lastName: "text" });
2097
+ schema15.index({ "associatedResources.events": 1 });
2098
+ schema15.index({ "associatedResources.partners": 1 });
2099
+ schema15.index({ "associatedResources.vendors": 1 });
2032
2100
  var UserModel = import_mongoose20.default.models.User || import_mongoose20.default.model("User", schema15);
2033
2101
 
2034
2102
  // src/mongoose/VerificationToken.ts
@@ -2162,6 +2230,7 @@ schema17.index({
2162
2230
  name: "text"
2163
2231
  });
2164
2232
  schema17.index({ deletedAt: 1, "owner.userId": 1 });
2233
+ schema17.index({ "associates.userId": 1, deletedAt: 1 });
2165
2234
  schema17.plugin(searchNamePlugin);
2166
2235
  var VendorModel = import_mongoose22.default.models.Vendor || import_mongoose22.default.model("Vendor", schema17);
2167
2236
 
@@ -2313,6 +2382,7 @@ schema20.index({ "dateTime.dateStatus": 1 });
2313
2382
  schema20.index({ slug: 1 });
2314
2383
  schema20.index({ description: "text", name: "text", tags: "text" });
2315
2384
  schema20.index({ deletedAt: 1, "owner.userId": 1 });
2385
+ schema20.index({ "associates.userId": 1, deletedAt: 1 });
2316
2386
  schema20.plugin(searchNamePlugin);
2317
2387
  var EventModel = import_mongoose25.default.models.Event || import_mongoose25.default.model("Event", schema20);
2318
2388
 
@@ -2359,6 +2429,7 @@ schema22.index({ "location.geo": "2dsphere" });
2359
2429
  schema22.index({ slug: 1 });
2360
2430
  schema22.index({ name: "text", description: "text" });
2361
2431
  schema22.index({ "owner.userId": 1, deletedAt: 1 });
2432
+ schema22.index({ "associates.userId": 1, deletedAt: 1 });
2362
2433
  schema22.plugin(searchNamePlugin);
2363
2434
  var PartnerModel = import_mongoose27.default.models.Partner || import_mongoose27.default.model("Partner", schema22);
2364
2435
 
@@ -3424,14 +3495,310 @@ function normalizeAffiliatePromoCodes(promoCodes) {
3424
3495
  return [...new Set(normalized)];
3425
3496
  }
3426
3497
 
3498
+ // src/service/associates/index.ts
3499
+ var import_cluemart_shared28 = require("@timardex/cluemart-shared");
3500
+ var import_mongoose42 = __toESM(require("mongoose"));
3501
+ function isAssociableResourceType(resourceType) {
3502
+ return resourceType === import_cluemart_shared28.EnumResourceType.EVENT || resourceType === import_cluemart_shared28.EnumResourceType.PARTNER || resourceType === import_cluemart_shared28.EnumResourceType.VENDOR;
3503
+ }
3504
+ function getAssociateAccessMeta(resourceType) {
3505
+ if (resourceType === import_cluemart_shared28.EnumResourceType.EVENT) {
3506
+ return {
3507
+ associatedField: "events",
3508
+ associatedPath: "associatedResources.events",
3509
+ associateRole: import_cluemart_shared28.EnumUserRole.ASSOCIATED_EVENT
3510
+ };
3511
+ }
3512
+ if (resourceType === import_cluemart_shared28.EnumResourceType.PARTNER) {
3513
+ return {
3514
+ associatedField: "partners",
3515
+ associatedPath: "associatedResources.partners",
3516
+ associateRole: import_cluemart_shared28.EnumUserRole.ASSOCIATED_PARTNER
3517
+ };
3518
+ }
3519
+ return {
3520
+ associatedField: "vendors",
3521
+ associatedPath: "associatedResources.vendors",
3522
+ associateRole: import_cluemart_shared28.EnumUserRole.ASSOCIATED_VENDOR
3523
+ };
3524
+ }
3525
+ var ASSOCIABLE_MODELS = {
3526
+ [import_cluemart_shared28.EnumResourceType.EVENT]: EventModel,
3527
+ [import_cluemart_shared28.EnumResourceType.PARTNER]: PartnerModel,
3528
+ [import_cluemart_shared28.EnumResourceType.VENDOR]: VendorModel
3529
+ };
3530
+ function acceptedAssociateUserIds(associates) {
3531
+ return (associates ?? []).filter((associate) => associate.status === import_cluemart_shared28.EnumAssociateStatus.ACCEPTED).map((associate) => associate.userId);
3532
+ }
3533
+ async function detachUsersFromResource({
3534
+ resourceId,
3535
+ resourceType,
3536
+ userIds
3537
+ }) {
3538
+ if (userIds.length === 0) return;
3539
+ const { associateRole, associatedPath: path } = getAssociateAccessMeta(resourceType);
3540
+ const removedResourceId = typeof resourceId === "string" ? new import_mongoose42.default.Types.ObjectId(resourceId) : resourceId;
3541
+ await UserModel.updateMany({ _id: { $in: userIds } }, [
3542
+ {
3543
+ $set: {
3544
+ [path]: {
3545
+ $setDifference: [{ $ifNull: [`$${path}`, []] }, [removedResourceId]]
3546
+ }
3547
+ }
3548
+ },
3549
+ {
3550
+ $set: {
3551
+ roles: {
3552
+ $cond: [
3553
+ { $eq: [{ $size: { $ifNull: [`$${path}`, []] } }, 0] },
3554
+ {
3555
+ $setDifference: [{ $ifNull: ["$roles", []] }, [associateRole]]
3556
+ },
3557
+ "$roles"
3558
+ ]
3559
+ }
3560
+ }
3561
+ }
3562
+ ]).exec();
3563
+ }
3564
+ async function acceptedUserIdsForResource({
3565
+ resourceId,
3566
+ resourceType
3567
+ }) {
3568
+ const model = ASSOCIABLE_MODELS[resourceType];
3569
+ const resource = await model.findOne({ _id: resourceId, deletedAt: null }).select("associates").lean().exec();
3570
+ return new Set(
3571
+ acceptedAssociateUserIds(resource?.associates).map(
3572
+ (userId) => String(userId)
3573
+ )
3574
+ );
3575
+ }
3576
+ async function grantAssociateGrants({
3577
+ resourceId,
3578
+ resourceType,
3579
+ userIds
3580
+ }) {
3581
+ if (userIds.length === 0) return;
3582
+ const acceptedUserIds = await acceptedUserIdsForResource({
3583
+ resourceId,
3584
+ resourceType
3585
+ });
3586
+ const grantUserIds = userIds.filter(
3587
+ (userId) => acceptedUserIds.has(String(userId))
3588
+ );
3589
+ if (grantUserIds.length === 0) return;
3590
+ const { associateRole, associatedPath } = getAssociateAccessMeta(resourceType);
3591
+ await UserModel.updateMany(
3592
+ { _id: { $in: grantUserIds } },
3593
+ {
3594
+ $addToSet: {
3595
+ [associatedPath]: resourceId,
3596
+ roles: associateRole
3597
+ }
3598
+ }
3599
+ ).exec();
3600
+ }
3601
+ async function detachUnlessStillAccepted({
3602
+ resourceId,
3603
+ resourceType,
3604
+ userIds
3605
+ }) {
3606
+ if (userIds.length === 0) return [];
3607
+ await detachUsersFromResource({ resourceId, resourceType, userIds });
3608
+ const acceptedAfterDetach = await acceptedUserIdsForResource({
3609
+ resourceId,
3610
+ resourceType
3611
+ });
3612
+ const restoredUserIds = userIds.filter(
3613
+ (userId) => acceptedAfterDetach.has(String(userId))
3614
+ );
3615
+ if (restoredUserIds.length === 0) return userIds;
3616
+ await grantAssociateGrants({
3617
+ resourceId,
3618
+ resourceType,
3619
+ userIds: restoredUserIds
3620
+ });
3621
+ const acceptedAfterRestore = await acceptedUserIdsForResource({
3622
+ resourceId,
3623
+ resourceType
3624
+ });
3625
+ const regressedUserIds = restoredUserIds.filter(
3626
+ (userId) => !acceptedAfterRestore.has(String(userId))
3627
+ );
3628
+ if (regressedUserIds.length > 0) {
3629
+ await detachUsersFromResource({
3630
+ resourceId,
3631
+ resourceType,
3632
+ userIds: regressedUserIds
3633
+ });
3634
+ }
3635
+ return userIds.filter((userId) => !acceptedAfterRestore.has(String(userId)));
3636
+ }
3637
+ async function detachStaleAssociateGrants({
3638
+ acceptedUserIds,
3639
+ resourceId,
3640
+ resourceType
3641
+ }) {
3642
+ const { associatedPath } = getAssociateAccessMeta(resourceType);
3643
+ const stale = await UserModel.find({
3644
+ _id: { $nin: acceptedUserIds },
3645
+ [associatedPath]: resourceId
3646
+ }).select("_id").lean().exec();
3647
+ const staleUserIds = stale.map((user) => user._id);
3648
+ return detachUnlessStillAccepted({
3649
+ resourceId,
3650
+ resourceType,
3651
+ userIds: staleUserIds
3652
+ });
3653
+ }
3654
+ async function detachAssociateGrantsForResources({
3655
+ resources
3656
+ }) {
3657
+ const result = resources.map((resource) => ({
3658
+ detachedUserIds: [],
3659
+ resourceId: resource.resourceId,
3660
+ resourceType: resource.resourceType
3661
+ }));
3662
+ const indexByType = /* @__PURE__ */ new Map();
3663
+ resources.forEach((resource, index) => {
3664
+ const entries = indexByType.get(resource.resourceType) ?? [];
3665
+ entries.push({ index, resourceId: resource.resourceId });
3666
+ indexByType.set(resource.resourceType, entries);
3667
+ });
3668
+ for (const [resourceType, entries] of indexByType) {
3669
+ const { associatedField, associatedPath } = getAssociateAccessMeta(resourceType);
3670
+ const resourceIds = entries.map((entry) => entry.resourceId);
3671
+ const wanted = new Set(resourceIds.map((resourceId) => String(resourceId)));
3672
+ const holders = await UserModel.find({
3673
+ [associatedPath]: { $in: resourceIds }
3674
+ }).select("_id associatedResources").lean().exec();
3675
+ const userIdsByResource = /* @__PURE__ */ new Map();
3676
+ for (const user of holders) {
3677
+ for (const heldResourceId of user.associatedResources?.[associatedField] ?? []) {
3678
+ const key = String(heldResourceId);
3679
+ if (!wanted.has(key)) continue;
3680
+ const userIds = userIdsByResource.get(key) ?? [];
3681
+ userIds.push(user._id);
3682
+ userIdsByResource.set(key, userIds);
3683
+ }
3684
+ }
3685
+ for (const entry of entries) {
3686
+ const userIds = userIdsByResource.get(String(entry.resourceId));
3687
+ if (!userIds || userIds.length === 0) continue;
3688
+ await detachUsersFromResource({
3689
+ resourceId: entry.resourceId,
3690
+ resourceType,
3691
+ userIds
3692
+ });
3693
+ result[entry.index].detachedUserIds = userIds;
3694
+ }
3695
+ }
3696
+ return result;
3697
+ }
3698
+ var DEFAULT_RECONCILE_BATCH_SIZE = 500;
3699
+ async function reconcileUserBatch({
3700
+ associatedField,
3701
+ model,
3702
+ resourceType,
3703
+ users
3704
+ }) {
3705
+ const heldByResource = /* @__PURE__ */ new Map();
3706
+ for (const user of users) {
3707
+ for (const resourceId of user.associatedResources?.[associatedField] ?? []) {
3708
+ const key = String(resourceId);
3709
+ const entry = heldByResource.get(key) ?? { resourceId, userIds: [] };
3710
+ entry.userIds.push(user._id);
3711
+ heldByResource.set(key, entry);
3712
+ }
3713
+ }
3714
+ if (heldByResource.size === 0) return 0;
3715
+ const resources = await model.find({
3716
+ _id: {
3717
+ $in: [...heldByResource.values()].map((entry) => entry.resourceId)
3718
+ }
3719
+ }).select("associates deletedAt").lean().exec();
3720
+ const acceptedByResource = /* @__PURE__ */ new Map();
3721
+ for (const resource of resources) {
3722
+ acceptedByResource.set(
3723
+ String(resource._id),
3724
+ resource.deletedAt ? /* @__PURE__ */ new Set() : new Set(
3725
+ acceptedAssociateUserIds(resource.associates).map(
3726
+ (userId) => String(userId)
3727
+ )
3728
+ )
3729
+ );
3730
+ }
3731
+ let detachedGrants = 0;
3732
+ for (const [key, { resourceId, userIds }] of heldByResource) {
3733
+ const accepted = acceptedByResource.get(key);
3734
+ const staleUserIds = userIds.filter(
3735
+ (userId) => !accepted?.has(String(userId))
3736
+ );
3737
+ if (staleUserIds.length === 0) continue;
3738
+ const removedUserIds = await detachUnlessStillAccepted({
3739
+ resourceId,
3740
+ resourceType,
3741
+ userIds: staleUserIds
3742
+ });
3743
+ detachedGrants += removedUserIds.length;
3744
+ }
3745
+ return detachedGrants;
3746
+ }
3747
+ async function reconcileResourceType({
3748
+ batchSize,
3749
+ resourceType
3750
+ }) {
3751
+ const { associatedField, associatedPath } = getAssociateAccessMeta(resourceType);
3752
+ const model = ASSOCIABLE_MODELS[resourceType];
3753
+ const result = {
3754
+ detachedGrants: 0,
3755
+ scannedUsers: 0
3756
+ };
3757
+ let lastId = null;
3758
+ for (; ; ) {
3759
+ const users = await UserModel.find({
3760
+ ...lastId ? { _id: { $gt: lastId } } : {},
3761
+ [associatedPath]: { $exists: true, $ne: [] }
3762
+ }).sort({ _id: 1 }).limit(batchSize).select("_id associatedResources").lean().exec();
3763
+ if (users.length === 0) break;
3764
+ result.scannedUsers += users.length;
3765
+ lastId = users[users.length - 1]._id;
3766
+ result.detachedGrants += await reconcileUserBatch({
3767
+ associatedField,
3768
+ model,
3769
+ resourceType,
3770
+ users
3771
+ });
3772
+ }
3773
+ return result;
3774
+ }
3775
+ async function reconcileAssociateGrants({
3776
+ batchSize = DEFAULT_RECONCILE_BATCH_SIZE
3777
+ } = {}) {
3778
+ const totals = {
3779
+ detachedGrants: 0,
3780
+ scannedUsers: 0
3781
+ };
3782
+ for (const resourceType of [
3783
+ import_cluemart_shared28.EnumResourceType.EVENT,
3784
+ import_cluemart_shared28.EnumResourceType.VENDOR,
3785
+ import_cluemart_shared28.EnumResourceType.PARTNER
3786
+ ]) {
3787
+ const result = await reconcileResourceType({ batchSize, resourceType });
3788
+ totals.detachedGrants += result.detachedGrants;
3789
+ totals.scannedUsers += result.scannedUsers;
3790
+ }
3791
+ return totals;
3792
+ }
3793
+
3427
3794
  // src/service/database.ts
3428
- var import_mongoose43 = __toESM(require("mongoose"));
3795
+ var import_mongoose44 = __toESM(require("mongoose"));
3429
3796
 
3430
3797
  // src/service/indexes.ts
3431
- var import_mongoose42 = __toESM(require("mongoose"));
3798
+ var import_mongoose43 = __toESM(require("mongoose"));
3432
3799
  function registeredModels() {
3433
- return import_mongoose42.default.modelNames().map((modelName) => {
3434
- const model = import_mongoose42.default.model(modelName);
3800
+ return import_mongoose43.default.modelNames().map((modelName) => {
3801
+ const model = import_mongoose43.default.model(modelName);
3435
3802
  return { createIndexes: () => model.createIndexes(), modelName };
3436
3803
  });
3437
3804
  }
@@ -3473,7 +3840,7 @@ var connectToDatabase = async ({
3473
3840
  // Fallback to MongoDB Atlas connection string
3474
3841
  `mongodb+srv://${dbUser}:${dbPassword}@${dbName}.mongodb.net/?retryWrites=true&w=majority&appName=${appName}`
3475
3842
  );
3476
- await import_mongoose43.default.connect(mongoUri);
3843
+ await import_mongoose44.default.connect(mongoUri);
3477
3844
  const connectionType = mongodbUri ? "Local MongoDB" : "MongoDB Atlas";
3478
3845
  console.log(
3479
3846
  `${connectionType} connected from server/src/service/database.ts`
@@ -3489,7 +3856,7 @@ var connectToDatabase = async ({
3489
3856
 
3490
3857
  // src/types/index.ts
3491
3858
  var import_express = __toESM(require("express"));
3492
- var import_mongoose44 = __toESM(require("mongoose"));
3859
+ var import_mongoose45 = __toESM(require("mongoose"));
3493
3860
  var EnumPubSubEvents = /* @__PURE__ */ ((EnumPubSubEvents2) => {
3494
3861
  EnumPubSubEvents2["GET_CHAT_MESSAGE"] = "GET_CHAT_MESSAGE";
3495
3862
  EnumPubSubEvents2["GET_NOTIFICATIONS"] = "GET_NOTIFICATIONS";
@@ -3544,9 +3911,9 @@ async function notifyUsers({
3544
3911
  }
3545
3912
 
3546
3913
  // src/service/updateAdStatus.ts
3547
- var import_cluemart_shared28 = require("@timardex/cluemart-shared");
3914
+ var import_cluemart_shared29 = require("@timardex/cluemart-shared");
3548
3915
  async function updateAdStatuses() {
3549
- const now = (0, import_cluemart_shared28.nzDayKey)();
3916
+ const now = (0, import_cluemart_shared29.nzDayKey)();
3550
3917
  const invalidResult = await AdModel.updateMany(
3551
3918
  {
3552
3919
  $or: [
@@ -3554,50 +3921,50 @@ async function updateAdStatuses() {
3554
3921
  { end: { $exists: false } },
3555
3922
  { $expr: { $gt: ["$start", "$end"] } }
3556
3923
  ],
3557
- status: { $ne: import_cluemart_shared28.EnumAdStatus.PAUSED }
3924
+ status: { $ne: import_cluemart_shared29.EnumAdStatus.PAUSED }
3558
3925
  },
3559
- { $set: { status: import_cluemart_shared28.EnumAdStatus.PAUSED } }
3926
+ { $set: { status: import_cluemart_shared29.EnumAdStatus.PAUSED } }
3560
3927
  );
3561
3928
  const expiredResult = await AdModel.updateMany(
3562
- { end: { $lte: now }, status: { $ne: import_cluemart_shared28.EnumAdStatus.EXPIRED } },
3563
- { $set: { status: import_cluemart_shared28.EnumAdStatus.EXPIRED } }
3929
+ { end: { $lte: now }, status: { $ne: import_cluemart_shared29.EnumAdStatus.EXPIRED } },
3930
+ { $set: { status: import_cluemart_shared29.EnumAdStatus.EXPIRED } }
3564
3931
  );
3565
3932
  const eligibleBooking = {
3566
3933
  $or: [
3567
3934
  { bookingKind: { $exists: false } },
3568
3935
  { bookingKind: null },
3569
3936
  {
3570
- approvalStatus: import_cluemart_shared28.EnumAdApprovalStatus.APPROVED,
3571
- bookingKind: import_cluemart_shared28.EnumAdBookingSlotKind.RESERVED
3937
+ approvalStatus: import_cluemart_shared29.EnumAdApprovalStatus.APPROVED,
3938
+ bookingKind: import_cluemart_shared29.EnumAdBookingSlotKind.RESERVED
3572
3939
  },
3573
3940
  {
3574
- approvalStatus: import_cluemart_shared28.EnumAdApprovalStatus.APPROVED,
3575
- bookingKind: import_cluemart_shared28.EnumAdBookingSlotKind.PAID,
3576
- paymentStatus: import_cluemart_shared28.EnumAdPaymentStatus.PAID
3941
+ approvalStatus: import_cluemart_shared29.EnumAdApprovalStatus.APPROVED,
3942
+ bookingKind: import_cluemart_shared29.EnumAdBookingSlotKind.PAID,
3943
+ paymentStatus: import_cluemart_shared29.EnumAdPaymentStatus.PAID
3577
3944
  }
3578
3945
  ]
3579
3946
  };
3580
3947
  const awaitingApprovalResult = await AdModel.updateMany(
3581
3948
  {
3582
3949
  $nor: eligibleBooking.$or,
3583
- bookingKind: { $in: Object.values(import_cluemart_shared28.EnumAdBookingSlotKind) },
3950
+ bookingKind: { $in: Object.values(import_cluemart_shared29.EnumAdBookingSlotKind) },
3584
3951
  end: { $gt: now },
3585
- status: import_cluemart_shared28.EnumAdStatus.ACTIVE
3952
+ status: import_cluemart_shared29.EnumAdStatus.ACTIVE
3586
3953
  },
3587
- { $set: { status: import_cluemart_shared28.EnumAdStatus.PAUSED } }
3954
+ { $set: { status: import_cluemart_shared29.EnumAdStatus.PAUSED } }
3588
3955
  );
3589
3956
  const activeResult = await AdModel.updateMany(
3590
3957
  {
3591
3958
  end: { $gt: now },
3592
3959
  start: { $lte: now },
3593
- status: { $ne: import_cluemart_shared28.EnumAdStatus.ACTIVE },
3960
+ status: { $ne: import_cluemart_shared29.EnumAdStatus.ACTIVE },
3594
3961
  ...eligibleBooking
3595
3962
  },
3596
- { $set: { status: import_cluemart_shared28.EnumAdStatus.ACTIVE } }
3963
+ { $set: { status: import_cluemart_shared29.EnumAdStatus.ACTIVE } }
3597
3964
  );
3598
3965
  const pausedResult = await AdModel.updateMany(
3599
- { start: { $gt: now }, status: { $ne: import_cluemart_shared28.EnumAdStatus.PAUSED } },
3600
- { $set: { status: import_cluemart_shared28.EnumAdStatus.PAUSED } }
3966
+ { start: { $gt: now }, status: { $ne: import_cluemart_shared29.EnumAdStatus.PAUSED } },
3967
+ { $set: { status: import_cluemart_shared29.EnumAdStatus.PAUSED } }
3601
3968
  );
3602
3969
  console.log(
3603
3970
  `\u2705 Ad statuses updated: invalid=${invalidResult.modifiedCount}, expired=${expiredResult.modifiedCount}, awaitingApproval=${awaitingApprovalResult.modifiedCount}, active=${activeResult.modifiedCount}, paused=${pausedResult.modifiedCount}`
@@ -3605,15 +3972,15 @@ async function updateAdStatuses() {
3605
3972
  }
3606
3973
 
3607
3974
  // src/service/objectIdToString.ts
3608
- var import_mongoose46 = __toESM(require("mongoose"));
3975
+ var import_mongoose47 = __toESM(require("mongoose"));
3609
3976
  function isValidObjectId(value) {
3610
- return import_mongoose46.default.Types.ObjectId.isValid(value);
3977
+ return import_mongoose47.default.Types.ObjectId.isValid(value);
3611
3978
  }
3612
3979
  function convertObjectIdsToStrings(obj) {
3613
3980
  if (obj === null || obj === void 0) {
3614
3981
  return obj;
3615
3982
  }
3616
- if (obj instanceof import_mongoose46.default.Types.ObjectId) {
3983
+ if (obj instanceof import_mongoose47.default.Types.ObjectId) {
3617
3984
  return obj.toString();
3618
3985
  }
3619
3986
  if (obj instanceof Date) {
@@ -3807,19 +4174,19 @@ function buildUserPointEntryRemovalPipeline(pointType, sourceId) {
3807
4174
  }
3808
4175
 
3809
4176
  // src/service/event/updateAllEventDateTimeStatuses.ts
3810
- var import_cluemart_shared30 = require("@timardex/cluemart-shared");
4177
+ var import_cluemart_shared31 = require("@timardex/cluemart-shared");
3811
4178
  var import_dayjs4 = __toESM(require("dayjs"));
3812
4179
 
3813
4180
  // src/service/event/archiveEndedEventDates.ts
3814
- var import_cluemart_shared29 = require("@timardex/cluemart-shared");
4181
+ var import_cluemart_shared30 = require("@timardex/cluemart-shared");
3815
4182
  var import_dayjs3 = __toESM(require("dayjs"));
3816
4183
  var import_customParseFormat = __toESM(require("dayjs/plugin/customParseFormat"));
3817
4184
  import_dayjs3.default.extend(import_customParseFormat.default);
3818
4185
  var ARCHIVED_STATUSES = /* @__PURE__ */ new Set([
3819
- import_cluemart_shared29.EnumEventDateStatus.ENDED
4186
+ import_cluemart_shared30.EnumEventDateStatus.ENDED
3820
4187
  ]);
3821
4188
  var DISCARDED_STATUSES = /* @__PURE__ */ new Set([
3822
- import_cluemart_shared29.EnumEventDateStatus.INVALID
4189
+ import_cluemart_shared30.EnumEventDateStatus.INVALID
3823
4190
  ]);
3824
4191
  function splitEventDatesForArchive(dateTime) {
3825
4192
  return {
@@ -3842,12 +4209,12 @@ function dedupeArchivedSlotsByStartDateTime(slots) {
3842
4209
  });
3843
4210
  }
3844
4211
  function isPastCanceledEventDate(slot, now) {
3845
- if (slot.dateStatus !== import_cluemart_shared29.EnumEventDateStatus.CANCELED) {
4212
+ if (slot.dateStatus !== import_cluemart_shared30.EnumEventDateStatus.CANCELED) {
3846
4213
  return false;
3847
4214
  }
3848
4215
  const endDateTime = (0, import_dayjs3.default)(
3849
4216
  `${slot.endDate} ${slot.endTime}`,
3850
- `${import_cluemart_shared29.dateFormat} ${import_cluemart_shared29.timeFormat}`,
4217
+ `${import_cluemart_shared30.dateFormat} ${import_cluemart_shared30.timeFormat}`,
3851
4218
  true
3852
4219
  );
3853
4220
  return endDateTime.isValid() && endDateTime.isBefore(now);
@@ -3893,7 +4260,7 @@ async function updateModelDateTimeStatuses(model, now) {
3893
4260
  try {
3894
4261
  for await (const doc of cursor) {
3895
4262
  const dateTime = doc.dateTime.map(
3896
- (slot) => (0, import_cluemart_shared30.updateSingleDateTimeStatus)(slot, now)
4263
+ (slot) => (0, import_cluemart_shared31.updateSingleDateTimeStatus)(slot, now)
3897
4264
  );
3898
4265
  if (!hasDateTimeStatusChanges(doc.dateTime, dateTime)) {
3899
4266
  continue;
@@ -3917,9 +4284,9 @@ async function updateModelDateTimeStatuses(model, now) {
3917
4284
  var ARCHIVABLE_EVENT_FILTER = {
3918
4285
  "dateTime.dateStatus": {
3919
4286
  $in: [
3920
- import_cluemart_shared30.EnumEventDateStatus.ENDED,
3921
- import_cluemart_shared30.EnumEventDateStatus.INVALID,
3922
- import_cluemart_shared30.EnumEventDateStatus.CANCELED
4287
+ import_cluemart_shared31.EnumEventDateStatus.ENDED,
4288
+ import_cluemart_shared31.EnumEventDateStatus.INVALID,
4289
+ import_cluemart_shared31.EnumEventDateStatus.CANCELED
3923
4290
  ]
3924
4291
  },
3925
4292
  deletedAt: null
@@ -3944,7 +4311,7 @@ async function archiveEndedAndDiscardInvalidEventDates(now) {
3944
4311
  try {
3945
4312
  for await (const doc of cursor) {
3946
4313
  const updated = doc.dateTime.map(
3947
- (slot) => (0, import_cluemart_shared30.updateSingleDateTimeStatus)(slot, now)
4314
+ (slot) => (0, import_cluemart_shared31.updateSingleDateTimeStatus)(slot, now)
3948
4315
  );
3949
4316
  const { archive, discard } = splitEventDatesForArchive(updated);
3950
4317
  const pastCanceled = updated.filter(
@@ -3968,13 +4335,13 @@ async function archiveEndedAndDiscardInvalidEventDates(now) {
3968
4335
  if (archive.length > 0 || discard.length > 0) {
3969
4336
  pullConditions.push({
3970
4337
  dateStatus: {
3971
- $in: [import_cluemart_shared30.EnumEventDateStatus.ENDED, import_cluemart_shared30.EnumEventDateStatus.INVALID]
4338
+ $in: [import_cluemart_shared31.EnumEventDateStatus.ENDED, import_cluemart_shared31.EnumEventDateStatus.INVALID]
3972
4339
  }
3973
4340
  });
3974
4341
  }
3975
4342
  for (const slot of pastCanceled) {
3976
4343
  pullConditions.push({
3977
- dateStatus: import_cluemart_shared30.EnumEventDateStatus.CANCELED,
4344
+ dateStatus: import_cluemart_shared31.EnumEventDateStatus.CANCELED,
3978
4345
  startDate: slot.startDate,
3979
4346
  startTime: slot.startTime
3980
4347
  });
@@ -4016,9 +4383,9 @@ async function cleanEventInfoDates(now) {
4016
4383
  try {
4017
4384
  for await (const doc of cursor) {
4018
4385
  const updated = doc.dateTime.map(
4019
- (slot) => (0, import_cluemart_shared30.updateSingleDateTimeStatus)(slot, now)
4386
+ (slot) => (0, import_cluemart_shared31.updateSingleDateTimeStatus)(slot, now)
4020
4387
  );
4021
- const kept = (0, import_cluemart_shared30.filterDatesByFutureStatus)(updated);
4388
+ const kept = (0, import_cluemart_shared31.filterDatesByFutureStatus)(updated);
4022
4389
  if (kept.length === updated.length) {
4023
4390
  continue;
4024
4391
  }
@@ -4068,7 +4435,7 @@ async function updateAllEventDateTimeStatuses() {
4068
4435
  }
4069
4436
 
4070
4437
  // src/service/index.ts
4071
- var import_cluemart_shared38 = require("@timardex/cluemart-shared");
4438
+ var import_cluemart_shared39 = require("@timardex/cluemart-shared");
4072
4439
 
4073
4440
  // src/service/event/findEventOrImportedMarketById.ts
4074
4441
  async function findEventOrImportedMarketById(resourceId) {
@@ -4085,7 +4452,7 @@ async function findEventOrImportedMarketById(resourceId) {
4085
4452
  }
4086
4453
 
4087
4454
  // src/service/relations.ts
4088
- var import_cluemart_shared31 = require("@timardex/cluemart-shared");
4455
+ var import_cluemart_shared32 = require("@timardex/cluemart-shared");
4089
4456
  function didRemoveAnyEventDates(previousDateTime, nextDateTime) {
4090
4457
  if (!previousDateTime?.length) {
4091
4458
  return false;
@@ -4101,8 +4468,8 @@ function didRemoveAnyStartedDates(previousDateTime, nextDateTime) {
4101
4468
  return false;
4102
4469
  }
4103
4470
  return previousDateTime.some(
4104
- (prev) => prev.dateStatus === import_cluemart_shared31.EnumEventDateStatus.STARTED && !nextDateTime?.some(
4105
- (next) => next.startDate === prev.startDate && next.startTime === prev.startTime && next.dateStatus === import_cluemart_shared31.EnumEventDateStatus.STARTED
4471
+ (prev) => prev.dateStatus === import_cluemart_shared32.EnumEventDateStatus.STARTED && !nextDateTime?.some(
4472
+ (next) => next.startDate === prev.startDate && next.startTime === prev.startTime && next.dateStatus === import_cluemart_shared32.EnumEventDateStatus.STARTED
4106
4473
  )
4107
4474
  );
4108
4475
  }
@@ -4113,7 +4480,7 @@ function updateRelationDatesToCanceled(relationDates, eventDateTime) {
4113
4480
  ) ?? false;
4114
4481
  return {
4115
4482
  ...relationDate,
4116
- status: existsInEvent ? relationDate.status : import_cluemart_shared31.EnumInviteStatus.CANCELED
4483
+ status: existsInEvent ? relationDate.status : import_cluemart_shared32.EnumInviteStatus.CANCELED
4117
4484
  };
4118
4485
  });
4119
4486
  }
@@ -4122,15 +4489,15 @@ function updateRelationDatesToCanceled(relationDates, eventDateTime) {
4122
4489
  var import_dayjs8 = __toESM(require("dayjs"));
4123
4490
 
4124
4491
  // src/service/license/compliance/utils.ts
4125
- var import_cluemart_shared36 = require("@timardex/cluemart-shared");
4492
+ var import_cluemart_shared37 = require("@timardex/cluemart-shared");
4126
4493
  var import_dayjs7 = __toESM(require("dayjs"));
4127
4494
 
4128
4495
  // src/service/license/compliance/event.ts
4129
- var import_cluemart_shared32 = require("@timardex/cluemart-shared");
4496
+ var import_cluemart_shared33 = require("@timardex/cluemart-shared");
4130
4497
  var eventLicences = [
4131
- import_cluemart_shared32.EnumUserLicence.STANDARD_EVENT,
4132
- import_cluemart_shared32.EnumUserLicence.PRO_EVENT,
4133
- import_cluemart_shared32.EnumUserLicence.PRO_PLUS_EVENT
4498
+ import_cluemart_shared33.EnumUserLicence.STANDARD_EVENT,
4499
+ import_cluemart_shared33.EnumUserLicence.PRO_EVENT,
4500
+ import_cluemart_shared33.EnumUserLicence.PRO_PLUS_EVENT
4134
4501
  ];
4135
4502
  async function handleEventLicenceCompliance(user, now) {
4136
4503
  if (!user.licences || !user.events?.length) {
@@ -4342,9 +4709,9 @@ function buildLicenceExpiryPipeline(params) {
4342
4709
  }
4343
4710
 
4344
4711
  // src/service/license/compliance/partner.ts
4345
- var import_cluemart_shared33 = require("@timardex/cluemart-shared");
4712
+ var import_cluemart_shared34 = require("@timardex/cluemart-shared");
4346
4713
  var partnerLicences = [
4347
- import_cluemart_shared33.EnumUserLicence.STANDARD_PARTNER
4714
+ import_cluemart_shared34.EnumUserLicence.STANDARD_PARTNER
4348
4715
  ];
4349
4716
  async function handlePartnerLicenceCompliance(user, now) {
4350
4717
  if (!user.licences || !user.partner) {
@@ -4354,52 +4721,62 @@ async function handlePartnerLicenceCompliance(user, now) {
4354
4721
  }
4355
4722
 
4356
4723
  // src/service/license/compliance/vendor.ts
4357
- var import_cluemart_shared35 = require("@timardex/cluemart-shared");
4724
+ var import_cluemart_shared36 = require("@timardex/cluemart-shared");
4358
4725
  var import_dayjs6 = __toESM(require("dayjs"));
4359
4726
 
4360
4727
  // src/service/license/models.ts
4361
- var import_cluemart_shared34 = require("@timardex/cluemart-shared");
4728
+ var import_cluemart_shared35 = require("@timardex/cluemart-shared");
4362
4729
  var import_dayjs5 = __toESM(require("dayjs"));
4363
4730
  var import_graphql = require("graphql");
4364
- var LicenceCategory = /* @__PURE__ */ ((LicenceCategory2) => {
4365
- LicenceCategory2["EVENT"] = "event";
4366
- LicenceCategory2["PARTNER"] = "partner";
4367
- LicenceCategory2["VENDOR"] = "vendor";
4368
- LicenceCategory2["AFFILIATE"] = "affiliate";
4369
- LicenceCategory2["SCHOOL"] = "school";
4370
- return LicenceCategory2;
4731
+ var LicenceCategory = /* @__PURE__ */ ((LicenceCategory3) => {
4732
+ LicenceCategory3["EVENT"] = "event";
4733
+ LicenceCategory3["PARTNER"] = "partner";
4734
+ LicenceCategory3["VENDOR"] = "vendor";
4735
+ LicenceCategory3["AFFILIATE"] = "affiliate";
4736
+ LicenceCategory3["SCHOOL"] = "school";
4737
+ return LicenceCategory3;
4371
4738
  })(LicenceCategory || {});
4372
4739
  var licenceCategoryMapping = {
4373
- [import_cluemart_shared34.EnumUserLicence.PRO_EVENT]: "event" /* EVENT */,
4374
- [import_cluemart_shared34.EnumUserLicence.PRO_PLUS_EVENT]: "event" /* EVENT */,
4375
- [import_cluemart_shared34.EnumUserLicence.PRO_PLUS_VENDOR]: "vendor" /* VENDOR */,
4376
- [import_cluemart_shared34.EnumUserLicence.PRO_VENDOR]: "vendor" /* VENDOR */,
4377
- [import_cluemart_shared34.EnumUserLicence.STANDARD_EVENT]: "event" /* EVENT */,
4378
- [import_cluemart_shared34.EnumUserLicence.STANDARD_PARTNER]: "partner" /* PARTNER */,
4379
- [import_cluemart_shared34.EnumUserLicence.STANDARD_VENDOR]: "vendor" /* VENDOR */,
4380
- [import_cluemart_shared34.EnumUserLicence.STANDARD_AFFILIATE]: "affiliate" /* AFFILIATE */,
4381
- [import_cluemart_shared34.EnumUserLicence.STANDARD_SCHOOL]: "school" /* SCHOOL */
4740
+ [import_cluemart_shared35.EnumUserLicence.PRO_EVENT]: "event" /* EVENT */,
4741
+ [import_cluemart_shared35.EnumUserLicence.PRO_PLUS_EVENT]: "event" /* EVENT */,
4742
+ [import_cluemart_shared35.EnumUserLicence.PRO_PLUS_VENDOR]: "vendor" /* VENDOR */,
4743
+ [import_cluemart_shared35.EnumUserLicence.PRO_VENDOR]: "vendor" /* VENDOR */,
4744
+ [import_cluemart_shared35.EnumUserLicence.STANDARD_EVENT]: "event" /* EVENT */,
4745
+ [import_cluemart_shared35.EnumUserLicence.STANDARD_PARTNER]: "partner" /* PARTNER */,
4746
+ [import_cluemart_shared35.EnumUserLicence.STANDARD_VENDOR]: "vendor" /* VENDOR */,
4747
+ [import_cluemart_shared35.EnumUserLicence.STANDARD_AFFILIATE]: "affiliate" /* AFFILIATE */,
4748
+ [import_cluemart_shared35.EnumUserLicence.STANDARD_SCHOOL]: "school" /* SCHOOL */
4382
4749
  };
4383
4750
  var licencePriority = {
4384
- [import_cluemart_shared34.EnumUserLicence.PRO_PLUS_EVENT]: 3,
4385
- [import_cluemart_shared34.EnumUserLicence.PRO_EVENT]: 2,
4386
- [import_cluemart_shared34.EnumUserLicence.STANDARD_EVENT]: 1,
4387
- [import_cluemart_shared34.EnumUserLicence.PRO_PLUS_VENDOR]: 3,
4388
- [import_cluemart_shared34.EnumUserLicence.PRO_VENDOR]: 2,
4389
- [import_cluemart_shared34.EnumUserLicence.STANDARD_VENDOR]: 1,
4390
- [import_cluemart_shared34.EnumUserLicence.STANDARD_PARTNER]: 1,
4391
- [import_cluemart_shared34.EnumUserLicence.STANDARD_AFFILIATE]: 1,
4392
- [import_cluemart_shared34.EnumUserLicence.STANDARD_SCHOOL]: 1
4751
+ [import_cluemart_shared35.EnumUserLicence.PRO_PLUS_EVENT]: 3,
4752
+ [import_cluemart_shared35.EnumUserLicence.PRO_EVENT]: 2,
4753
+ [import_cluemart_shared35.EnumUserLicence.STANDARD_EVENT]: 1,
4754
+ [import_cluemart_shared35.EnumUserLicence.PRO_PLUS_VENDOR]: 3,
4755
+ [import_cluemart_shared35.EnumUserLicence.PRO_VENDOR]: 2,
4756
+ [import_cluemart_shared35.EnumUserLicence.STANDARD_VENDOR]: 1,
4757
+ [import_cluemart_shared35.EnumUserLicence.STANDARD_PARTNER]: 1,
4758
+ [import_cluemart_shared35.EnumUserLicence.STANDARD_AFFILIATE]: 1,
4759
+ [import_cluemart_shared35.EnumUserLicence.STANDARD_SCHOOL]: 1
4393
4760
  };
4394
4761
  var standardLicences = [
4395
- import_cluemart_shared34.EnumUserLicence.STANDARD_VENDOR,
4396
- import_cluemart_shared34.EnumUserLicence.STANDARD_EVENT,
4397
- import_cluemart_shared34.EnumUserLicence.STANDARD_PARTNER
4762
+ import_cluemart_shared35.EnumUserLicence.STANDARD_VENDOR,
4763
+ import_cluemart_shared35.EnumUserLicence.STANDARD_EVENT,
4764
+ import_cluemart_shared35.EnumUserLicence.STANDARD_PARTNER
4398
4765
  ];
4399
4766
  var standardLicenceSet = new Set(standardLicences);
4400
4767
  function isStandardLicence(licence) {
4401
4768
  return standardLicenceSet.has(licence);
4402
4769
  }
4770
+ var proLicences = [
4771
+ import_cluemart_shared35.EnumUserLicence.PRO_EVENT,
4772
+ import_cluemart_shared35.EnumUserLicence.PRO_PLUS_EVENT,
4773
+ import_cluemart_shared35.EnumUserLicence.PRO_VENDOR,
4774
+ import_cluemart_shared35.EnumUserLicence.PRO_PLUS_VENDOR
4775
+ ];
4776
+ var proLicenceSet = new Set(proLicences);
4777
+ function isProLicence(licence) {
4778
+ return proLicenceSet.has(licence);
4779
+ }
4403
4780
  var categoryRegexMapping = {
4404
4781
  ["event" /* EVENT */]: /_event$/,
4405
4782
  ["partner" /* PARTNER */]: /_partner$/,
@@ -4408,11 +4785,11 @@ var categoryRegexMapping = {
4408
4785
  ["school" /* SCHOOL */]: /_school$/
4409
4786
  };
4410
4787
  var categoryFallbackLicence = {
4411
- ["event" /* EVENT */]: import_cluemart_shared34.EnumUserLicence.STANDARD_EVENT,
4412
- ["partner" /* PARTNER */]: import_cluemart_shared34.EnumUserLicence.STANDARD_PARTNER,
4413
- ["vendor" /* VENDOR */]: import_cluemart_shared34.EnumUserLicence.STANDARD_VENDOR,
4414
- ["affiliate" /* AFFILIATE */]: import_cluemart_shared34.EnumUserLicence.STANDARD_AFFILIATE,
4415
- ["school" /* SCHOOL */]: import_cluemart_shared34.EnumUserLicence.STANDARD_SCHOOL
4788
+ ["event" /* EVENT */]: import_cluemart_shared35.EnumUserLicence.STANDARD_EVENT,
4789
+ ["partner" /* PARTNER */]: import_cluemart_shared35.EnumUserLicence.STANDARD_PARTNER,
4790
+ ["vendor" /* VENDOR */]: import_cluemart_shared35.EnumUserLicence.STANDARD_VENDOR,
4791
+ ["affiliate" /* AFFILIATE */]: import_cluemart_shared35.EnumUserLicence.STANDARD_AFFILIATE,
4792
+ ["school" /* SCHOOL */]: import_cluemart_shared35.EnumUserLicence.STANDARD_SCHOOL
4416
4793
  };
4417
4794
  var LicenceFilterInput = {
4418
4795
  INPUT_USER_LICENCES: "$licences"
@@ -4442,11 +4819,11 @@ function getHighestLicenceForCategory(licences, category) {
4442
4819
  function createLicenceObject(expiryDate, licenceType) {
4443
4820
  const today = (0, import_dayjs5.default)();
4444
4821
  const expiryDateMapping = {
4445
- [import_cluemart_shared34.LicenceExpiryDate.ONE_YEAR]: today.add(1, "year").endOf("day").toDate(),
4446
- [import_cluemart_shared34.LicenceExpiryDate.ONE_MONTH]: today.add(1, "month").endOf("day").toDate(),
4447
- [import_cluemart_shared34.LicenceExpiryDate.TWO_MONTHS]: today.add(2, "month").endOf("day").toDate(),
4448
- [import_cluemart_shared34.LicenceExpiryDate.THREE_MONTHS]: today.add(3, "month").endOf("day").toDate(),
4449
- [import_cluemart_shared34.LicenceExpiryDate.SIX_MONTHS]: today.add(6, "month").endOf("day").toDate()
4822
+ [import_cluemart_shared35.LicenceExpiryDate.ONE_YEAR]: today.add(1, "year").endOf("day").toDate(),
4823
+ [import_cluemart_shared35.LicenceExpiryDate.ONE_MONTH]: today.add(1, "month").endOf("day").toDate(),
4824
+ [import_cluemart_shared35.LicenceExpiryDate.TWO_MONTHS]: today.add(2, "month").endOf("day").toDate(),
4825
+ [import_cluemart_shared35.LicenceExpiryDate.THREE_MONTHS]: today.add(3, "month").endOf("day").toDate(),
4826
+ [import_cluemart_shared35.LicenceExpiryDate.SIX_MONTHS]: today.add(6, "month").endOf("day").toDate()
4450
4827
  };
4451
4828
  const licenceObject = {
4452
4829
  expiryDate: expiryDateMapping[expiryDate],
@@ -4550,13 +4927,13 @@ async function checkOwnerHasLicence({
4550
4927
  const owner = await UserModel.findById(userId);
4551
4928
  if (!owner) throw new import_graphql.GraphQLError("Owner not found");
4552
4929
  const categoryByResource = {
4553
- [import_cluemart_shared34.EnumResourceType.EVENT]: "event" /* EVENT */,
4554
- [import_cluemart_shared34.EnumResourceType.PARTNER]: "partner" /* PARTNER */,
4555
- [import_cluemart_shared34.EnumResourceType.VENDOR]: "vendor" /* VENDOR */,
4556
- [import_cluemart_shared34.EnumResourceType.AFFILIATE]: "affiliate" /* AFFILIATE */,
4557
- [import_cluemart_shared34.EnumResourceType.SCHOOL]: "school" /* SCHOOL */
4930
+ [import_cluemart_shared35.EnumResourceType.EVENT]: "event" /* EVENT */,
4931
+ [import_cluemart_shared35.EnumResourceType.PARTNER]: "partner" /* PARTNER */,
4932
+ [import_cluemart_shared35.EnumResourceType.VENDOR]: "vendor" /* VENDOR */,
4933
+ [import_cluemart_shared35.EnumResourceType.AFFILIATE]: "affiliate" /* AFFILIATE */,
4934
+ [import_cluemart_shared35.EnumResourceType.SCHOOL]: "school" /* SCHOOL */
4558
4935
  };
4559
- if (!(0, import_cluemart_shared34.isNonVisitorResourceType)(resourceType)) {
4936
+ if (!(0, import_cluemart_shared35.isNonVisitorResourceType)(resourceType)) {
4560
4937
  throw new import_graphql.GraphQLError(`Invalid resource type: ${resourceType}.`);
4561
4938
  }
4562
4939
  const requiredCategory = categoryByResource[resourceType];
@@ -4578,6 +4955,128 @@ async function checkOwnerHasLicence({
4578
4955
  );
4579
4956
  }
4580
4957
  }
4958
+ var resourceLicenceCategory = {
4959
+ [import_cluemart_shared35.EnumResourceType.EVENT]: "event" /* EVENT */,
4960
+ [import_cluemart_shared35.EnumResourceType.PARTNER]: "partner" /* PARTNER */,
4961
+ [import_cluemart_shared35.EnumResourceType.VENDOR]: "vendor" /* VENDOR */
4962
+ };
4963
+ function isProtectedByCurrentStripeSubscription(user, licenceType, now) {
4964
+ const stripe = user.stripe;
4965
+ if (!stripe || stripe.currentPlan !== licenceType) {
4966
+ return false;
4967
+ }
4968
+ const gracePeriodEndsAt = stripe.paymentGracePeriodEndsAt ? (0, import_dayjs5.default)(stripe.paymentGracePeriodEndsAt) : null;
4969
+ 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);
4970
+ if (hasActivePaymentGracePeriod) {
4971
+ return true;
4972
+ }
4973
+ if (!stripe.subscriptionId) {
4974
+ return false;
4975
+ }
4976
+ if (stripe.status !== import_cluemart_shared35.EnumSubscriptionStatus.ACTIVE) {
4977
+ return false;
4978
+ }
4979
+ if (!stripe.endDate) {
4980
+ return false;
4981
+ }
4982
+ const paidThrough = (0, import_dayjs5.default)(stripe.endDate);
4983
+ return paidThrough.isValid() && paidThrough.isAfter(now);
4984
+ }
4985
+ function effectiveLicences({
4986
+ includeStripeProtected = false,
4987
+ licences,
4988
+ now,
4989
+ owner
4990
+ }) {
4991
+ const nowDayjs = (0, import_dayjs5.default)(now);
4992
+ return (licences ?? []).filter((licence) => {
4993
+ if (!licence.licenceType || licence.expiryDate == null) {
4994
+ return false;
4995
+ }
4996
+ if (new Date(licence.expiryDate).getTime() > now.getTime()) {
4997
+ return true;
4998
+ }
4999
+ return Boolean(
5000
+ includeStripeProtected && owner && isProtectedByCurrentStripeSubscription(
5001
+ owner,
5002
+ licence.licenceType,
5003
+ nowDayjs
5004
+ )
5005
+ );
5006
+ });
5007
+ }
5008
+ async function getActiveLicenceForResource({
5009
+ includeStripeProtected = false,
5010
+ userId,
5011
+ resourceType,
5012
+ now = /* @__PURE__ */ new Date()
5013
+ }) {
5014
+ const category = resourceLicenceCategory[resourceType];
5015
+ if (!category) {
5016
+ return null;
5017
+ }
5018
+ const owner = await UserModel.findById(userId, {
5019
+ licences: 1,
5020
+ ...includeStripeProtected ? { stripe: 1 } : {}
5021
+ }).lean();
5022
+ if (!owner?.licences?.length) {
5023
+ return null;
5024
+ }
5025
+ return getHighestLicenceForCategory(
5026
+ effectiveLicences({
5027
+ includeStripeProtected,
5028
+ licences: owner.licences,
5029
+ now,
5030
+ owner
5031
+ }),
5032
+ category
5033
+ );
5034
+ }
5035
+ async function getUserIdsWithActiveProLicence({
5036
+ includeStripeProtected = false,
5037
+ resourceType,
5038
+ userIds,
5039
+ now = /* @__PURE__ */ new Date()
5040
+ }) {
5041
+ const category = resourceLicenceCategory[resourceType];
5042
+ if (!category || userIds.length === 0) {
5043
+ return /* @__PURE__ */ new Set();
5044
+ }
5045
+ const owners = await UserModel.find(
5046
+ { _id: { $in: userIds } },
5047
+ { licences: 1, ...includeStripeProtected ? { stripe: 1 } : {} }
5048
+ ).lean();
5049
+ const allowed = /* @__PURE__ */ new Set();
5050
+ for (const owner of owners ?? []) {
5051
+ const activeLicence = getHighestLicenceForCategory(
5052
+ effectiveLicences({
5053
+ includeStripeProtected,
5054
+ licences: owner.licences,
5055
+ now,
5056
+ owner
5057
+ }),
5058
+ category
5059
+ );
5060
+ if (activeLicence && isProLicence(activeLicence)) {
5061
+ allowed.add(String(owner._id));
5062
+ }
5063
+ }
5064
+ return allowed;
5065
+ }
5066
+ async function hasActiveProLicenceForResource({
5067
+ includeStripeProtected = false,
5068
+ userId,
5069
+ resourceType,
5070
+ now = /* @__PURE__ */ new Date()
5071
+ }) {
5072
+ const activeLicence = await getActiveLicenceForResource({
5073
+ includeStripeProtected,
5074
+ now,
5075
+ resourceType,
5076
+ userId
5077
+ });
5078
+ return activeLicence !== null && isProLicence(activeLicence);
5079
+ }
4581
5080
 
4582
5081
  // src/service/license/compliance/vendor.ts
4583
5082
  async function findUserVendor(userId, logLabel) {
@@ -4636,7 +5135,7 @@ async function applyVendorDowngrade(vendor, ownerUserId) {
4636
5135
  return (result?.matchedCount ?? 0) > 0;
4637
5136
  }
4638
5137
  async function downgradeVendorProFeatures(userId, licenceType) {
4639
- const isStandardVendor = licenceType === import_cluemart_shared35.EnumUserLicence.STANDARD_VENDOR;
5138
+ const isStandardVendor = licenceType === import_cluemart_shared36.EnumUserLicence.STANDARD_VENDOR;
4640
5139
  if (!isStandardVendor) {
4641
5140
  return;
4642
5141
  }
@@ -4683,7 +5182,7 @@ async function applyVendorRestore(vendor, ownerUserId) {
4683
5182
  return (result?.matchedCount ?? 0) > 0;
4684
5183
  }
4685
5184
  async function restoreVendorProFeatures(userId, licenceType) {
4686
- const isProVendor = licenceType === import_cluemart_shared35.EnumUserLicence.PRO_VENDOR || licenceType === import_cluemart_shared35.EnumUserLicence.PRO_PLUS_VENDOR;
5185
+ const isProVendor = licenceType === import_cluemart_shared36.EnumUserLicence.PRO_VENDOR || licenceType === import_cluemart_shared36.EnumUserLicence.PRO_PLUS_VENDOR;
4687
5186
  if (!isProVendor) {
4688
5187
  return;
4689
5188
  }
@@ -4698,28 +5197,6 @@ async function restoreVendorProFeatures(userId, licenceType) {
4698
5197
  throw error;
4699
5198
  }
4700
5199
  }
4701
- function isProtectedByCurrentStripeSubscription(user, licenceType, now) {
4702
- const stripe = user.stripe;
4703
- if (!stripe || stripe.currentPlan !== licenceType) {
4704
- return false;
4705
- }
4706
- const gracePeriodEndsAt = stripe.paymentGracePeriodEndsAt ? (0, import_dayjs6.default)(stripe.paymentGracePeriodEndsAt) : null;
4707
- 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);
4708
- if (hasActivePaymentGracePeriod) {
4709
- return true;
4710
- }
4711
- if (!stripe.subscriptionId) {
4712
- return false;
4713
- }
4714
- if (stripe.status !== import_cluemart_shared35.EnumSubscriptionStatus.ACTIVE) {
4715
- return false;
4716
- }
4717
- if (!stripe.endDate) {
4718
- return false;
4719
- }
4720
- const paidThrough = (0, import_dayjs6.default)(stripe.endDate);
4721
- return paidThrough.isValid() && paidThrough.isAfter(now);
4722
- }
4723
5200
  async function handleVendorLicenceCompliance(user, now) {
4724
5201
  if (!user.licences || !user.vendor) {
4725
5202
  return;
@@ -4730,10 +5207,10 @@ async function handleVendorLicenceCompliance(user, now) {
4730
5207
  if (vendorLicencesOfUser.length === 0) {
4731
5208
  return;
4732
5209
  }
4733
- const proLicences = vendorLicencesOfUser.filter(
4734
- (licence) => licence.licenceType !== import_cluemart_shared35.EnumUserLicence.STANDARD_VENDOR
5210
+ const proLicences2 = vendorLicencesOfUser.filter(
5211
+ (licence) => licence.licenceType !== import_cluemart_shared36.EnumUserLicence.STANDARD_VENDOR
4735
5212
  );
4736
- const expiredProLicences = proLicences.filter(
5213
+ const expiredProLicences = proLicences2.filter(
4737
5214
  (licence) => !(0, import_dayjs6.default)(licence.expiryDate).isAfter(now)
4738
5215
  );
4739
5216
  const stripeProtectedLicenceTypes = new Set(
@@ -4744,7 +5221,7 @@ async function handleVendorLicenceCompliance(user, now) {
4744
5221
  const expiredProLicence = expiredProLicences.some(
4745
5222
  (licence) => !stripeProtectedLicenceTypes.has(licence.licenceType)
4746
5223
  );
4747
- const hasValidProLicence = stripeProtectedLicenceTypes.size > 0 || hasValidLicence(proLicences, import_cluemart_shared35.vendorLicences, now);
5224
+ const hasValidProLicence = stripeProtectedLicenceTypes.size > 0 || hasValidLicence(proLicences2, import_cluemart_shared36.vendorLicences, now);
4748
5225
  const hasExpiredVendorLicence = vendorLicencesOfUser.some(
4749
5226
  (licence) => !(0, import_dayjs6.default)(licence.expiryDate).isAfter(now) && !stripeProtectedLicenceTypes.has(licence.licenceType)
4750
5227
  );
@@ -4760,7 +5237,7 @@ async function handleVendorLicenceCompliance(user, now) {
4760
5237
  "owner.userId": user._id
4761
5238
  }).lean().exec();
4762
5239
  }
4763
- const licencesToSync = import_cluemart_shared35.vendorLicences.filter(
5240
+ const licencesToSync = import_cluemart_shared36.vendorLicences.filter(
4764
5241
  (licenceType) => !stripeProtectedLicenceTypes.has(licenceType)
4765
5242
  );
4766
5243
  await syncUserLicencesAfterExpiry(user._id, licencesToSync, now, "downgrade");
@@ -4775,11 +5252,11 @@ async function handleVendorLicenceCompliance(user, now) {
4775
5252
  data: {
4776
5253
  resourceId: String(vendor._id),
4777
5254
  resourceName: vendor.name,
4778
- resourceType: import_cluemart_shared35.EnumNotificationResourceType.DOWNGRADED_VENDOR
5255
+ resourceType: import_cluemart_shared36.EnumNotificationResourceType.DOWNGRADED_VENDOR
4779
5256
  },
4780
5257
  message: `Your Vendor licence has been downgraded due to licence expiration.`,
4781
5258
  title: `Vendor Licence Downgraded`,
4782
- type: import_cluemart_shared35.EnumNotificationType.SYSTEM,
5259
+ type: import_cluemart_shared36.EnumNotificationType.SYSTEM,
4783
5260
  userIds: [user._id]
4784
5261
  };
4785
5262
  await sendDeactivationNotification(payload, user._id, vendor.name, "vendor");
@@ -4793,26 +5270,11 @@ async function vendorOwnerHasProLicence(vendorId) {
4793
5270
  if (!vendor) {
4794
5271
  return false;
4795
5272
  }
4796
- const owner = await UserModel.findById(vendor.owner.userId, {
4797
- licences: 1,
4798
- stripe: 1
4799
- }).lean().exec();
4800
- if (!owner) {
4801
- return false;
4802
- }
4803
- const now = (0, import_dayjs6.default)();
4804
- const effectiveVendorLicences = owner.licences?.filter(
4805
- (licence) => licence?.licenceType && ((0, import_dayjs6.default)(licence.expiryDate).isAfter(now) || isProtectedByCurrentStripeSubscription(
4806
- owner,
4807
- licence.licenceType,
4808
- now
4809
- ))
4810
- );
4811
- const highestVendorLicence = getHighestLicenceForCategory(
4812
- effectiveVendorLicences,
4813
- "vendor" /* VENDOR */
4814
- );
4815
- return highestVendorLicence !== null && licencePriority[highestVendorLicence] >= licencePriority[import_cluemart_shared35.EnumUserLicence.PRO_VENDOR];
5273
+ return hasActiveProLicenceForResource({
5274
+ includeStripeProtected: true,
5275
+ resourceType: import_cluemart_shared36.EnumResourceType.VENDOR,
5276
+ userId: vendor.owner.userId
5277
+ });
4816
5278
  }
4817
5279
 
4818
5280
  // src/service/license/compliance/utils.ts
@@ -4822,12 +5284,12 @@ async function syncUserLicencesAfterExpiry(userId, licenceTypes, now, mode = "do
4822
5284
  const pipeline = buildLicenceExpiryPipeline({
4823
5285
  downgradeBranches: [
4824
5286
  {
4825
- case: import_cluemart_shared36.EnumUserLicence.PRO_PLUS_VENDOR,
4826
- then: import_cluemart_shared36.EnumUserLicence.STANDARD_VENDOR
5287
+ case: import_cluemart_shared37.EnumUserLicence.PRO_PLUS_VENDOR,
5288
+ then: import_cluemart_shared37.EnumUserLicence.STANDARD_VENDOR
4827
5289
  },
4828
5290
  {
4829
- case: import_cluemart_shared36.EnumUserLicence.PRO_VENDOR,
4830
- then: import_cluemart_shared36.EnumUserLicence.STANDARD_VENDOR
5291
+ case: import_cluemart_shared37.EnumUserLicence.PRO_VENDOR,
5292
+ then: import_cluemart_shared37.EnumUserLicence.STANDARD_VENDOR
4831
5293
  }
4832
5294
  ],
4833
5295
  licenceTypes,
@@ -4956,7 +5418,7 @@ var REMINDER_WINDOW_MIN_HOURS = 6.5 * 24;
4956
5418
  var REMINDER_WINDOW_MAX_HOURS = 7.5 * 24;
4957
5419
 
4958
5420
  // src/service/license/reminder/utils.ts
4959
- var import_cluemart_shared37 = require("@timardex/cluemart-shared");
5421
+ var import_cluemart_shared38 = require("@timardex/cluemart-shared");
4960
5422
  var import_utils8 = require("@timardex/cluemart-shared/utils");
4961
5423
  var import_dayjs9 = __toESM(require("dayjs"));
4962
5424
 
@@ -5022,28 +5484,28 @@ function isLicenseExpiringIn7Days(expiryDate, now) {
5022
5484
  return hoursUntilExpiry >= REMINDER_WINDOW_MIN_HOURS && hoursUntilExpiry <= REMINDER_WINDOW_MAX_HOURS;
5023
5485
  }
5024
5486
  function getLicenseName(licenceType) {
5025
- return import_cluemart_shared37.licenseNiceNames[licenceType] || licenceType;
5487
+ return import_cluemart_shared38.licenseNiceNames[licenceType] || licenceType;
5026
5488
  }
5027
5489
  function getNotificationTypes(isVendorLicense, isPartnerLicense) {
5028
5490
  if (isVendorLicense) {
5029
5491
  return {
5030
- notificationType: import_cluemart_shared37.EnumNotificationType.SYSTEM,
5031
- resourceType: import_cluemart_shared37.EnumNotificationResourceType.EXPIRATION_REMINDER_VENDOR
5492
+ notificationType: import_cluemart_shared38.EnumNotificationType.SYSTEM,
5493
+ resourceType: import_cluemart_shared38.EnumNotificationResourceType.EXPIRATION_REMINDER_VENDOR
5032
5494
  };
5033
5495
  }
5034
5496
  if (isPartnerLicense) {
5035
5497
  return {
5036
- notificationType: import_cluemart_shared37.EnumNotificationType.SYSTEM,
5037
- resourceType: import_cluemart_shared37.EnumNotificationResourceType.EXPIRATION_REMINDER_PARTNER
5498
+ notificationType: import_cluemart_shared38.EnumNotificationType.SYSTEM,
5499
+ resourceType: import_cluemart_shared38.EnumNotificationResourceType.EXPIRATION_REMINDER_PARTNER
5038
5500
  };
5039
5501
  }
5040
5502
  return {
5041
- notificationType: import_cluemart_shared37.EnumNotificationType.SYSTEM,
5042
- resourceType: import_cluemart_shared37.EnumNotificationResourceType.EXPIRATION_REMINDER_EVENT
5503
+ notificationType: import_cluemart_shared38.EnumNotificationType.SYSTEM,
5504
+ resourceType: import_cluemart_shared38.EnumNotificationResourceType.EXPIRATION_REMINDER_EVENT
5043
5505
  };
5044
5506
  }
5045
5507
  async function getLicenseResourceInfo(user, licence) {
5046
- const isVendorLicense = import_cluemart_shared37.vendorLicences.includes(licence.licenceType);
5508
+ const isVendorLicense = import_cluemart_shared38.vendorLicences.includes(licence.licenceType);
5047
5509
  const isPartnerLicense = partnerLicences.includes(licence.licenceType);
5048
5510
  const licenceName = getLicenseName(licence.licenceType);
5049
5511
  const { notificationType, resourceType } = getNotificationTypes(
@@ -5091,11 +5553,11 @@ async function getLicenseResourceInfo(user, licence) {
5091
5553
  };
5092
5554
  }
5093
5555
  function getLicenceExpiryMode(licenceType) {
5094
- return licenceType === import_cluemart_shared37.EnumUserLicence.PRO_VENDOR || licenceType === import_cluemart_shared37.EnumUserLicence.PRO_PLUS_VENDOR ? "downgrade" : "extend";
5556
+ return licenceType === import_cluemart_shared38.EnumUserLicence.PRO_VENDOR || licenceType === import_cluemart_shared38.EnumUserLicence.PRO_PLUS_VENDOR ? "downgrade" : "extend";
5095
5557
  }
5096
5558
  async function sendLicenseReminder(user, licence) {
5097
5559
  const licenceName = getLicenseName(licence.licenceType);
5098
- const expiryDate = (0, import_dayjs9.default)(licence.expiryDate).format(import_cluemart_shared37.dateFormat);
5560
+ const expiryDate = (0, import_dayjs9.default)(licence.expiryDate).format(import_cluemart_shared38.dateFormat);
5099
5561
  const userId = String(user._id);
5100
5562
  const resourceInfo = await getLicenseResourceInfo(user, licence);
5101
5563
  if (!resourceInfo) {
@@ -5234,6 +5696,7 @@ async function remindUsersAboutLicenseExpiration() {
5234
5696
  AiImportRunModel,
5235
5697
  AiImportedMarketModel,
5236
5698
  AppSettingModel,
5699
+ AssociateTypeSchema,
5237
5700
  AuthHandoffTokenModel,
5238
5701
  BILLING_CATALOG_COLLECTION_NAME,
5239
5702
  BillingCatalogModel,
@@ -5273,6 +5736,7 @@ async function remindUsersAboutLicenseExpiration() {
5273
5736
  VendorInfoModel,
5274
5737
  VendorModel,
5275
5738
  VerificationTokenModel,
5739
+ acceptedAssociateUserIds,
5276
5740
  activeAffiliateCodeExists,
5277
5741
  awardAffiliateVendorSubscriptionRewards,
5278
5742
  baseResourceFields,
@@ -5289,6 +5753,9 @@ async function remindUsersAboutLicenseExpiration() {
5289
5753
  createLicenceObject,
5290
5754
  dateTimeSchema,
5291
5755
  dedupeArchivedSlotsByStartDateTime,
5756
+ detachAssociateGrantsForResources,
5757
+ detachStaleAssociateGrants,
5758
+ detachUsersFromResource,
5292
5759
  didRemoveAnyEventDates,
5293
5760
  didRemoveAnyStartedDates,
5294
5761
  downgradeVendorProFeatures,
@@ -5299,6 +5766,8 @@ async function remindUsersAboutLicenseExpiration() {
5299
5766
  express,
5300
5767
  findAffiliateByPromoCode,
5301
5768
  findEventOrImportedMarketById,
5769
+ getActiveLicenceForResource,
5770
+ getAssociateAccessMeta,
5302
5771
  getBillingCatalogDefinition,
5303
5772
  getEventResourceInfo,
5304
5773
  getHighestLicenceForCategory,
@@ -5309,11 +5778,17 @@ async function remindUsersAboutLicenseExpiration() {
5309
5778
  getPayingStripeSubscriptionPlan,
5310
5779
  getPayingVendorStripeSubscriptionPlan,
5311
5780
  getSubscriptionRewardPeriodBounds,
5781
+ getUserIdsWithActiveProLicence,
5312
5782
  getVendorResourceInfo,
5783
+ grantAssociateGrants,
5313
5784
  handleEventLicenceCompliance,
5314
5785
  handlePartnerLicenceCompliance,
5315
5786
  handleVendorLicenceCompliance,
5787
+ hasActiveProLicenceForResource,
5316
5788
  hasValidLicence,
5789
+ isAssociableResourceType,
5790
+ isProLicence,
5791
+ isProtectedByCurrentStripeSubscription,
5317
5792
  isStandardLicence,
5318
5793
  isValidObjectId,
5319
5794
  licenceCategoryMapping,
@@ -5331,6 +5806,7 @@ async function remindUsersAboutLicenseExpiration() {
5331
5806
  processUserCompliance,
5332
5807
  processUserLicenseReminders,
5333
5808
  publishNotificationEvents,
5809
+ reconcileAssociateGrants,
5334
5810
  refundPolicySchema,
5335
5811
  relatedPostSchema,
5336
5812
  relationDatesSchema,