@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.
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,10 @@ 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({ email: 1 }, { name: "email_unique", unique: true });
2098
+ schema15.index({ "associatedResources.events": 1 });
2099
+ schema15.index({ "associatedResources.partners": 1 });
2100
+ schema15.index({ "associatedResources.vendors": 1 });
2032
2101
  var UserModel = import_mongoose20.default.models.User || import_mongoose20.default.model("User", schema15);
2033
2102
 
2034
2103
  // src/mongoose/VerificationToken.ts
@@ -2162,6 +2231,7 @@ schema17.index({
2162
2231
  name: "text"
2163
2232
  });
2164
2233
  schema17.index({ deletedAt: 1, "owner.userId": 1 });
2234
+ schema17.index({ "associates.userId": 1, deletedAt: 1 });
2165
2235
  schema17.plugin(searchNamePlugin);
2166
2236
  var VendorModel = import_mongoose22.default.models.Vendor || import_mongoose22.default.model("Vendor", schema17);
2167
2237
 
@@ -2313,6 +2383,7 @@ schema20.index({ "dateTime.dateStatus": 1 });
2313
2383
  schema20.index({ slug: 1 });
2314
2384
  schema20.index({ description: "text", name: "text", tags: "text" });
2315
2385
  schema20.index({ deletedAt: 1, "owner.userId": 1 });
2386
+ schema20.index({ "associates.userId": 1, deletedAt: 1 });
2316
2387
  schema20.plugin(searchNamePlugin);
2317
2388
  var EventModel = import_mongoose25.default.models.Event || import_mongoose25.default.model("Event", schema20);
2318
2389
 
@@ -2359,6 +2430,7 @@ schema22.index({ "location.geo": "2dsphere" });
2359
2430
  schema22.index({ slug: 1 });
2360
2431
  schema22.index({ name: "text", description: "text" });
2361
2432
  schema22.index({ "owner.userId": 1, deletedAt: 1 });
2433
+ schema22.index({ "associates.userId": 1, deletedAt: 1 });
2362
2434
  schema22.plugin(searchNamePlugin);
2363
2435
  var PartnerModel = import_mongoose27.default.models.Partner || import_mongoose27.default.model("Partner", schema22);
2364
2436
 
@@ -3424,14 +3496,310 @@ function normalizeAffiliatePromoCodes(promoCodes) {
3424
3496
  return [...new Set(normalized)];
3425
3497
  }
3426
3498
 
3499
+ // src/service/associates/index.ts
3500
+ var import_cluemart_shared28 = require("@timardex/cluemart-shared");
3501
+ var import_mongoose42 = __toESM(require("mongoose"));
3502
+ function isAssociableResourceType(resourceType) {
3503
+ return resourceType === import_cluemart_shared28.EnumResourceType.EVENT || resourceType === import_cluemart_shared28.EnumResourceType.PARTNER || resourceType === import_cluemart_shared28.EnumResourceType.VENDOR;
3504
+ }
3505
+ function getAssociateAccessMeta(resourceType) {
3506
+ if (resourceType === import_cluemart_shared28.EnumResourceType.EVENT) {
3507
+ return {
3508
+ associatedField: "events",
3509
+ associatedPath: "associatedResources.events",
3510
+ associateRole: import_cluemart_shared28.EnumUserRole.ASSOCIATED_EVENT
3511
+ };
3512
+ }
3513
+ if (resourceType === import_cluemart_shared28.EnumResourceType.PARTNER) {
3514
+ return {
3515
+ associatedField: "partners",
3516
+ associatedPath: "associatedResources.partners",
3517
+ associateRole: import_cluemart_shared28.EnumUserRole.ASSOCIATED_PARTNER
3518
+ };
3519
+ }
3520
+ return {
3521
+ associatedField: "vendors",
3522
+ associatedPath: "associatedResources.vendors",
3523
+ associateRole: import_cluemart_shared28.EnumUserRole.ASSOCIATED_VENDOR
3524
+ };
3525
+ }
3526
+ var ASSOCIABLE_MODELS = {
3527
+ [import_cluemart_shared28.EnumResourceType.EVENT]: EventModel,
3528
+ [import_cluemart_shared28.EnumResourceType.PARTNER]: PartnerModel,
3529
+ [import_cluemart_shared28.EnumResourceType.VENDOR]: VendorModel
3530
+ };
3531
+ function acceptedAssociateUserIds(associates) {
3532
+ return (associates ?? []).filter((associate) => associate.status === import_cluemart_shared28.EnumAssociateStatus.ACCEPTED).map((associate) => associate.userId);
3533
+ }
3534
+ async function detachUsersFromResource({
3535
+ resourceId,
3536
+ resourceType,
3537
+ userIds
3538
+ }) {
3539
+ if (userIds.length === 0) return;
3540
+ const { associateRole, associatedPath: path } = getAssociateAccessMeta(resourceType);
3541
+ const removedResourceId = typeof resourceId === "string" ? new import_mongoose42.default.Types.ObjectId(resourceId) : resourceId;
3542
+ await UserModel.updateMany({ _id: { $in: userIds } }, [
3543
+ {
3544
+ $set: {
3545
+ [path]: {
3546
+ $setDifference: [{ $ifNull: [`$${path}`, []] }, [removedResourceId]]
3547
+ }
3548
+ }
3549
+ },
3550
+ {
3551
+ $set: {
3552
+ roles: {
3553
+ $cond: [
3554
+ { $eq: [{ $size: { $ifNull: [`$${path}`, []] } }, 0] },
3555
+ {
3556
+ $setDifference: [{ $ifNull: ["$roles", []] }, [associateRole]]
3557
+ },
3558
+ "$roles"
3559
+ ]
3560
+ }
3561
+ }
3562
+ }
3563
+ ]).exec();
3564
+ }
3565
+ async function acceptedUserIdsForResource({
3566
+ resourceId,
3567
+ resourceType
3568
+ }) {
3569
+ const model = ASSOCIABLE_MODELS[resourceType];
3570
+ const resource = await model.findOne({ _id: resourceId, deletedAt: null }).select("associates").lean().exec();
3571
+ return new Set(
3572
+ acceptedAssociateUserIds(resource?.associates).map(
3573
+ (userId) => String(userId)
3574
+ )
3575
+ );
3576
+ }
3577
+ async function grantAssociateGrants({
3578
+ resourceId,
3579
+ resourceType,
3580
+ userIds
3581
+ }) {
3582
+ if (userIds.length === 0) return;
3583
+ const acceptedUserIds = await acceptedUserIdsForResource({
3584
+ resourceId,
3585
+ resourceType
3586
+ });
3587
+ const grantUserIds = userIds.filter(
3588
+ (userId) => acceptedUserIds.has(String(userId))
3589
+ );
3590
+ if (grantUserIds.length === 0) return;
3591
+ const { associateRole, associatedPath } = getAssociateAccessMeta(resourceType);
3592
+ await UserModel.updateMany(
3593
+ { _id: { $in: grantUserIds } },
3594
+ {
3595
+ $addToSet: {
3596
+ [associatedPath]: resourceId,
3597
+ roles: associateRole
3598
+ }
3599
+ }
3600
+ ).exec();
3601
+ }
3602
+ async function detachUnlessStillAccepted({
3603
+ resourceId,
3604
+ resourceType,
3605
+ userIds
3606
+ }) {
3607
+ if (userIds.length === 0) return [];
3608
+ await detachUsersFromResource({ resourceId, resourceType, userIds });
3609
+ const acceptedAfterDetach = await acceptedUserIdsForResource({
3610
+ resourceId,
3611
+ resourceType
3612
+ });
3613
+ const restoredUserIds = userIds.filter(
3614
+ (userId) => acceptedAfterDetach.has(String(userId))
3615
+ );
3616
+ if (restoredUserIds.length === 0) return userIds;
3617
+ await grantAssociateGrants({
3618
+ resourceId,
3619
+ resourceType,
3620
+ userIds: restoredUserIds
3621
+ });
3622
+ const acceptedAfterRestore = await acceptedUserIdsForResource({
3623
+ resourceId,
3624
+ resourceType
3625
+ });
3626
+ const regressedUserIds = restoredUserIds.filter(
3627
+ (userId) => !acceptedAfterRestore.has(String(userId))
3628
+ );
3629
+ if (regressedUserIds.length > 0) {
3630
+ await detachUsersFromResource({
3631
+ resourceId,
3632
+ resourceType,
3633
+ userIds: regressedUserIds
3634
+ });
3635
+ }
3636
+ return userIds.filter((userId) => !acceptedAfterRestore.has(String(userId)));
3637
+ }
3638
+ async function detachStaleAssociateGrants({
3639
+ acceptedUserIds,
3640
+ resourceId,
3641
+ resourceType
3642
+ }) {
3643
+ const { associatedPath } = getAssociateAccessMeta(resourceType);
3644
+ const stale = await UserModel.find({
3645
+ _id: { $nin: acceptedUserIds },
3646
+ [associatedPath]: resourceId
3647
+ }).select("_id").lean().exec();
3648
+ const staleUserIds = stale.map((user) => user._id);
3649
+ return detachUnlessStillAccepted({
3650
+ resourceId,
3651
+ resourceType,
3652
+ userIds: staleUserIds
3653
+ });
3654
+ }
3655
+ async function detachAssociateGrantsForResources({
3656
+ resources
3657
+ }) {
3658
+ const result = resources.map((resource) => ({
3659
+ detachedUserIds: [],
3660
+ resourceId: resource.resourceId,
3661
+ resourceType: resource.resourceType
3662
+ }));
3663
+ const indexByType = /* @__PURE__ */ new Map();
3664
+ resources.forEach((resource, index) => {
3665
+ const entries = indexByType.get(resource.resourceType) ?? [];
3666
+ entries.push({ index, resourceId: resource.resourceId });
3667
+ indexByType.set(resource.resourceType, entries);
3668
+ });
3669
+ for (const [resourceType, entries] of indexByType) {
3670
+ const { associatedField, associatedPath } = getAssociateAccessMeta(resourceType);
3671
+ const resourceIds = entries.map((entry) => entry.resourceId);
3672
+ const wanted = new Set(resourceIds.map((resourceId) => String(resourceId)));
3673
+ const holders = await UserModel.find({
3674
+ [associatedPath]: { $in: resourceIds }
3675
+ }).select("_id associatedResources").lean().exec();
3676
+ const userIdsByResource = /* @__PURE__ */ new Map();
3677
+ for (const user of holders) {
3678
+ for (const heldResourceId of user.associatedResources?.[associatedField] ?? []) {
3679
+ const key = String(heldResourceId);
3680
+ if (!wanted.has(key)) continue;
3681
+ const userIds = userIdsByResource.get(key) ?? [];
3682
+ userIds.push(user._id);
3683
+ userIdsByResource.set(key, userIds);
3684
+ }
3685
+ }
3686
+ for (const entry of entries) {
3687
+ const userIds = userIdsByResource.get(String(entry.resourceId));
3688
+ if (!userIds || userIds.length === 0) continue;
3689
+ await detachUsersFromResource({
3690
+ resourceId: entry.resourceId,
3691
+ resourceType,
3692
+ userIds
3693
+ });
3694
+ result[entry.index].detachedUserIds = userIds;
3695
+ }
3696
+ }
3697
+ return result;
3698
+ }
3699
+ var DEFAULT_RECONCILE_BATCH_SIZE = 500;
3700
+ async function reconcileUserBatch({
3701
+ associatedField,
3702
+ model,
3703
+ resourceType,
3704
+ users
3705
+ }) {
3706
+ const heldByResource = /* @__PURE__ */ new Map();
3707
+ for (const user of users) {
3708
+ for (const resourceId of user.associatedResources?.[associatedField] ?? []) {
3709
+ const key = String(resourceId);
3710
+ const entry = heldByResource.get(key) ?? { resourceId, userIds: [] };
3711
+ entry.userIds.push(user._id);
3712
+ heldByResource.set(key, entry);
3713
+ }
3714
+ }
3715
+ if (heldByResource.size === 0) return 0;
3716
+ const resources = await model.find({
3717
+ _id: {
3718
+ $in: [...heldByResource.values()].map((entry) => entry.resourceId)
3719
+ }
3720
+ }).select("associates deletedAt").lean().exec();
3721
+ const acceptedByResource = /* @__PURE__ */ new Map();
3722
+ for (const resource of resources) {
3723
+ acceptedByResource.set(
3724
+ String(resource._id),
3725
+ resource.deletedAt ? /* @__PURE__ */ new Set() : new Set(
3726
+ acceptedAssociateUserIds(resource.associates).map(
3727
+ (userId) => String(userId)
3728
+ )
3729
+ )
3730
+ );
3731
+ }
3732
+ let detachedGrants = 0;
3733
+ for (const [key, { resourceId, userIds }] of heldByResource) {
3734
+ const accepted = acceptedByResource.get(key);
3735
+ const staleUserIds = userIds.filter(
3736
+ (userId) => !accepted?.has(String(userId))
3737
+ );
3738
+ if (staleUserIds.length === 0) continue;
3739
+ const removedUserIds = await detachUnlessStillAccepted({
3740
+ resourceId,
3741
+ resourceType,
3742
+ userIds: staleUserIds
3743
+ });
3744
+ detachedGrants += removedUserIds.length;
3745
+ }
3746
+ return detachedGrants;
3747
+ }
3748
+ async function reconcileResourceType({
3749
+ batchSize,
3750
+ resourceType
3751
+ }) {
3752
+ const { associatedField, associatedPath } = getAssociateAccessMeta(resourceType);
3753
+ const model = ASSOCIABLE_MODELS[resourceType];
3754
+ const result = {
3755
+ detachedGrants: 0,
3756
+ scannedUsers: 0
3757
+ };
3758
+ let lastId = null;
3759
+ for (; ; ) {
3760
+ const users = await UserModel.find({
3761
+ ...lastId ? { _id: { $gt: lastId } } : {},
3762
+ [associatedPath]: { $exists: true, $ne: [] }
3763
+ }).sort({ _id: 1 }).limit(batchSize).select("_id associatedResources").lean().exec();
3764
+ if (users.length === 0) break;
3765
+ result.scannedUsers += users.length;
3766
+ lastId = users[users.length - 1]._id;
3767
+ result.detachedGrants += await reconcileUserBatch({
3768
+ associatedField,
3769
+ model,
3770
+ resourceType,
3771
+ users
3772
+ });
3773
+ }
3774
+ return result;
3775
+ }
3776
+ async function reconcileAssociateGrants({
3777
+ batchSize = DEFAULT_RECONCILE_BATCH_SIZE
3778
+ } = {}) {
3779
+ const totals = {
3780
+ detachedGrants: 0,
3781
+ scannedUsers: 0
3782
+ };
3783
+ for (const resourceType of [
3784
+ import_cluemart_shared28.EnumResourceType.EVENT,
3785
+ import_cluemart_shared28.EnumResourceType.VENDOR,
3786
+ import_cluemart_shared28.EnumResourceType.PARTNER
3787
+ ]) {
3788
+ const result = await reconcileResourceType({ batchSize, resourceType });
3789
+ totals.detachedGrants += result.detachedGrants;
3790
+ totals.scannedUsers += result.scannedUsers;
3791
+ }
3792
+ return totals;
3793
+ }
3794
+
3427
3795
  // src/service/database.ts
3428
- var import_mongoose43 = __toESM(require("mongoose"));
3796
+ var import_mongoose44 = __toESM(require("mongoose"));
3429
3797
 
3430
3798
  // src/service/indexes.ts
3431
- var import_mongoose42 = __toESM(require("mongoose"));
3799
+ var import_mongoose43 = __toESM(require("mongoose"));
3432
3800
  function registeredModels() {
3433
- return import_mongoose42.default.modelNames().map((modelName) => {
3434
- const model = import_mongoose42.default.model(modelName);
3801
+ return import_mongoose43.default.modelNames().map((modelName) => {
3802
+ const model = import_mongoose43.default.model(modelName);
3435
3803
  return { createIndexes: () => model.createIndexes(), modelName };
3436
3804
  });
3437
3805
  }
@@ -3473,7 +3841,7 @@ var connectToDatabase = async ({
3473
3841
  // Fallback to MongoDB Atlas connection string
3474
3842
  `mongodb+srv://${dbUser}:${dbPassword}@${dbName}.mongodb.net/?retryWrites=true&w=majority&appName=${appName}`
3475
3843
  );
3476
- await import_mongoose43.default.connect(mongoUri);
3844
+ await import_mongoose44.default.connect(mongoUri);
3477
3845
  const connectionType = mongodbUri ? "Local MongoDB" : "MongoDB Atlas";
3478
3846
  console.log(
3479
3847
  `${connectionType} connected from server/src/service/database.ts`
@@ -3489,7 +3857,7 @@ var connectToDatabase = async ({
3489
3857
 
3490
3858
  // src/types/index.ts
3491
3859
  var import_express = __toESM(require("express"));
3492
- var import_mongoose44 = __toESM(require("mongoose"));
3860
+ var import_mongoose45 = __toESM(require("mongoose"));
3493
3861
  var EnumPubSubEvents = /* @__PURE__ */ ((EnumPubSubEvents2) => {
3494
3862
  EnumPubSubEvents2["GET_CHAT_MESSAGE"] = "GET_CHAT_MESSAGE";
3495
3863
  EnumPubSubEvents2["GET_NOTIFICATIONS"] = "GET_NOTIFICATIONS";
@@ -3544,9 +3912,9 @@ async function notifyUsers({
3544
3912
  }
3545
3913
 
3546
3914
  // src/service/updateAdStatus.ts
3547
- var import_cluemart_shared28 = require("@timardex/cluemart-shared");
3915
+ var import_cluemart_shared29 = require("@timardex/cluemart-shared");
3548
3916
  async function updateAdStatuses() {
3549
- const now = (0, import_cluemart_shared28.nzDayKey)();
3917
+ const now = (0, import_cluemart_shared29.nzDayKey)();
3550
3918
  const invalidResult = await AdModel.updateMany(
3551
3919
  {
3552
3920
  $or: [
@@ -3554,50 +3922,50 @@ async function updateAdStatuses() {
3554
3922
  { end: { $exists: false } },
3555
3923
  { $expr: { $gt: ["$start", "$end"] } }
3556
3924
  ],
3557
- status: { $ne: import_cluemart_shared28.EnumAdStatus.PAUSED }
3925
+ status: { $ne: import_cluemart_shared29.EnumAdStatus.PAUSED }
3558
3926
  },
3559
- { $set: { status: import_cluemart_shared28.EnumAdStatus.PAUSED } }
3927
+ { $set: { status: import_cluemart_shared29.EnumAdStatus.PAUSED } }
3560
3928
  );
3561
3929
  const expiredResult = await AdModel.updateMany(
3562
- { end: { $lte: now }, status: { $ne: import_cluemart_shared28.EnumAdStatus.EXPIRED } },
3563
- { $set: { status: import_cluemart_shared28.EnumAdStatus.EXPIRED } }
3930
+ { end: { $lte: now }, status: { $ne: import_cluemart_shared29.EnumAdStatus.EXPIRED } },
3931
+ { $set: { status: import_cluemart_shared29.EnumAdStatus.EXPIRED } }
3564
3932
  );
3565
3933
  const eligibleBooking = {
3566
3934
  $or: [
3567
3935
  { bookingKind: { $exists: false } },
3568
3936
  { bookingKind: null },
3569
3937
  {
3570
- approvalStatus: import_cluemart_shared28.EnumAdApprovalStatus.APPROVED,
3571
- bookingKind: import_cluemart_shared28.EnumAdBookingSlotKind.RESERVED
3938
+ approvalStatus: import_cluemart_shared29.EnumAdApprovalStatus.APPROVED,
3939
+ bookingKind: import_cluemart_shared29.EnumAdBookingSlotKind.RESERVED
3572
3940
  },
3573
3941
  {
3574
- approvalStatus: import_cluemart_shared28.EnumAdApprovalStatus.APPROVED,
3575
- bookingKind: import_cluemart_shared28.EnumAdBookingSlotKind.PAID,
3576
- paymentStatus: import_cluemart_shared28.EnumAdPaymentStatus.PAID
3942
+ approvalStatus: import_cluemart_shared29.EnumAdApprovalStatus.APPROVED,
3943
+ bookingKind: import_cluemart_shared29.EnumAdBookingSlotKind.PAID,
3944
+ paymentStatus: import_cluemart_shared29.EnumAdPaymentStatus.PAID
3577
3945
  }
3578
3946
  ]
3579
3947
  };
3580
3948
  const awaitingApprovalResult = await AdModel.updateMany(
3581
3949
  {
3582
3950
  $nor: eligibleBooking.$or,
3583
- bookingKind: { $in: Object.values(import_cluemart_shared28.EnumAdBookingSlotKind) },
3951
+ bookingKind: { $in: Object.values(import_cluemart_shared29.EnumAdBookingSlotKind) },
3584
3952
  end: { $gt: now },
3585
- status: import_cluemart_shared28.EnumAdStatus.ACTIVE
3953
+ status: import_cluemart_shared29.EnumAdStatus.ACTIVE
3586
3954
  },
3587
- { $set: { status: import_cluemart_shared28.EnumAdStatus.PAUSED } }
3955
+ { $set: { status: import_cluemart_shared29.EnumAdStatus.PAUSED } }
3588
3956
  );
3589
3957
  const activeResult = await AdModel.updateMany(
3590
3958
  {
3591
3959
  end: { $gt: now },
3592
3960
  start: { $lte: now },
3593
- status: { $ne: import_cluemart_shared28.EnumAdStatus.ACTIVE },
3961
+ status: { $ne: import_cluemart_shared29.EnumAdStatus.ACTIVE },
3594
3962
  ...eligibleBooking
3595
3963
  },
3596
- { $set: { status: import_cluemart_shared28.EnumAdStatus.ACTIVE } }
3964
+ { $set: { status: import_cluemart_shared29.EnumAdStatus.ACTIVE } }
3597
3965
  );
3598
3966
  const pausedResult = await AdModel.updateMany(
3599
- { start: { $gt: now }, status: { $ne: import_cluemart_shared28.EnumAdStatus.PAUSED } },
3600
- { $set: { status: import_cluemart_shared28.EnumAdStatus.PAUSED } }
3967
+ { start: { $gt: now }, status: { $ne: import_cluemart_shared29.EnumAdStatus.PAUSED } },
3968
+ { $set: { status: import_cluemart_shared29.EnumAdStatus.PAUSED } }
3601
3969
  );
3602
3970
  console.log(
3603
3971
  `\u2705 Ad statuses updated: invalid=${invalidResult.modifiedCount}, expired=${expiredResult.modifiedCount}, awaitingApproval=${awaitingApprovalResult.modifiedCount}, active=${activeResult.modifiedCount}, paused=${pausedResult.modifiedCount}`
@@ -3605,15 +3973,15 @@ async function updateAdStatuses() {
3605
3973
  }
3606
3974
 
3607
3975
  // src/service/objectIdToString.ts
3608
- var import_mongoose46 = __toESM(require("mongoose"));
3976
+ var import_mongoose47 = __toESM(require("mongoose"));
3609
3977
  function isValidObjectId(value) {
3610
- return import_mongoose46.default.Types.ObjectId.isValid(value);
3978
+ return import_mongoose47.default.Types.ObjectId.isValid(value);
3611
3979
  }
3612
3980
  function convertObjectIdsToStrings(obj) {
3613
3981
  if (obj === null || obj === void 0) {
3614
3982
  return obj;
3615
3983
  }
3616
- if (obj instanceof import_mongoose46.default.Types.ObjectId) {
3984
+ if (obj instanceof import_mongoose47.default.Types.ObjectId) {
3617
3985
  return obj.toString();
3618
3986
  }
3619
3987
  if (obj instanceof Date) {
@@ -3807,19 +4175,19 @@ function buildUserPointEntryRemovalPipeline(pointType, sourceId) {
3807
4175
  }
3808
4176
 
3809
4177
  // src/service/event/updateAllEventDateTimeStatuses.ts
3810
- var import_cluemart_shared30 = require("@timardex/cluemart-shared");
4178
+ var import_cluemart_shared31 = require("@timardex/cluemart-shared");
3811
4179
  var import_dayjs4 = __toESM(require("dayjs"));
3812
4180
 
3813
4181
  // src/service/event/archiveEndedEventDates.ts
3814
- var import_cluemart_shared29 = require("@timardex/cluemart-shared");
4182
+ var import_cluemart_shared30 = require("@timardex/cluemart-shared");
3815
4183
  var import_dayjs3 = __toESM(require("dayjs"));
3816
4184
  var import_customParseFormat = __toESM(require("dayjs/plugin/customParseFormat"));
3817
4185
  import_dayjs3.default.extend(import_customParseFormat.default);
3818
4186
  var ARCHIVED_STATUSES = /* @__PURE__ */ new Set([
3819
- import_cluemart_shared29.EnumEventDateStatus.ENDED
4187
+ import_cluemart_shared30.EnumEventDateStatus.ENDED
3820
4188
  ]);
3821
4189
  var DISCARDED_STATUSES = /* @__PURE__ */ new Set([
3822
- import_cluemart_shared29.EnumEventDateStatus.INVALID
4190
+ import_cluemart_shared30.EnumEventDateStatus.INVALID
3823
4191
  ]);
3824
4192
  function splitEventDatesForArchive(dateTime) {
3825
4193
  return {
@@ -3842,12 +4210,12 @@ function dedupeArchivedSlotsByStartDateTime(slots) {
3842
4210
  });
3843
4211
  }
3844
4212
  function isPastCanceledEventDate(slot, now) {
3845
- if (slot.dateStatus !== import_cluemart_shared29.EnumEventDateStatus.CANCELED) {
4213
+ if (slot.dateStatus !== import_cluemart_shared30.EnumEventDateStatus.CANCELED) {
3846
4214
  return false;
3847
4215
  }
3848
4216
  const endDateTime = (0, import_dayjs3.default)(
3849
4217
  `${slot.endDate} ${slot.endTime}`,
3850
- `${import_cluemart_shared29.dateFormat} ${import_cluemart_shared29.timeFormat}`,
4218
+ `${import_cluemart_shared30.dateFormat} ${import_cluemart_shared30.timeFormat}`,
3851
4219
  true
3852
4220
  );
3853
4221
  return endDateTime.isValid() && endDateTime.isBefore(now);
@@ -3893,7 +4261,7 @@ async function updateModelDateTimeStatuses(model, now) {
3893
4261
  try {
3894
4262
  for await (const doc of cursor) {
3895
4263
  const dateTime = doc.dateTime.map(
3896
- (slot) => (0, import_cluemart_shared30.updateSingleDateTimeStatus)(slot, now)
4264
+ (slot) => (0, import_cluemart_shared31.updateSingleDateTimeStatus)(slot, now)
3897
4265
  );
3898
4266
  if (!hasDateTimeStatusChanges(doc.dateTime, dateTime)) {
3899
4267
  continue;
@@ -3917,9 +4285,9 @@ async function updateModelDateTimeStatuses(model, now) {
3917
4285
  var ARCHIVABLE_EVENT_FILTER = {
3918
4286
  "dateTime.dateStatus": {
3919
4287
  $in: [
3920
- import_cluemart_shared30.EnumEventDateStatus.ENDED,
3921
- import_cluemart_shared30.EnumEventDateStatus.INVALID,
3922
- import_cluemart_shared30.EnumEventDateStatus.CANCELED
4288
+ import_cluemart_shared31.EnumEventDateStatus.ENDED,
4289
+ import_cluemart_shared31.EnumEventDateStatus.INVALID,
4290
+ import_cluemart_shared31.EnumEventDateStatus.CANCELED
3923
4291
  ]
3924
4292
  },
3925
4293
  deletedAt: null
@@ -3944,7 +4312,7 @@ async function archiveEndedAndDiscardInvalidEventDates(now) {
3944
4312
  try {
3945
4313
  for await (const doc of cursor) {
3946
4314
  const updated = doc.dateTime.map(
3947
- (slot) => (0, import_cluemart_shared30.updateSingleDateTimeStatus)(slot, now)
4315
+ (slot) => (0, import_cluemart_shared31.updateSingleDateTimeStatus)(slot, now)
3948
4316
  );
3949
4317
  const { archive, discard } = splitEventDatesForArchive(updated);
3950
4318
  const pastCanceled = updated.filter(
@@ -3968,13 +4336,13 @@ async function archiveEndedAndDiscardInvalidEventDates(now) {
3968
4336
  if (archive.length > 0 || discard.length > 0) {
3969
4337
  pullConditions.push({
3970
4338
  dateStatus: {
3971
- $in: [import_cluemart_shared30.EnumEventDateStatus.ENDED, import_cluemart_shared30.EnumEventDateStatus.INVALID]
4339
+ $in: [import_cluemart_shared31.EnumEventDateStatus.ENDED, import_cluemart_shared31.EnumEventDateStatus.INVALID]
3972
4340
  }
3973
4341
  });
3974
4342
  }
3975
4343
  for (const slot of pastCanceled) {
3976
4344
  pullConditions.push({
3977
- dateStatus: import_cluemart_shared30.EnumEventDateStatus.CANCELED,
4345
+ dateStatus: import_cluemart_shared31.EnumEventDateStatus.CANCELED,
3978
4346
  startDate: slot.startDate,
3979
4347
  startTime: slot.startTime
3980
4348
  });
@@ -4016,9 +4384,9 @@ async function cleanEventInfoDates(now) {
4016
4384
  try {
4017
4385
  for await (const doc of cursor) {
4018
4386
  const updated = doc.dateTime.map(
4019
- (slot) => (0, import_cluemart_shared30.updateSingleDateTimeStatus)(slot, now)
4387
+ (slot) => (0, import_cluemart_shared31.updateSingleDateTimeStatus)(slot, now)
4020
4388
  );
4021
- const kept = (0, import_cluemart_shared30.filterDatesByFutureStatus)(updated);
4389
+ const kept = (0, import_cluemart_shared31.filterDatesByFutureStatus)(updated);
4022
4390
  if (kept.length === updated.length) {
4023
4391
  continue;
4024
4392
  }
@@ -4068,7 +4436,7 @@ async function updateAllEventDateTimeStatuses() {
4068
4436
  }
4069
4437
 
4070
4438
  // src/service/index.ts
4071
- var import_cluemart_shared38 = require("@timardex/cluemart-shared");
4439
+ var import_cluemart_shared39 = require("@timardex/cluemart-shared");
4072
4440
 
4073
4441
  // src/service/event/findEventOrImportedMarketById.ts
4074
4442
  async function findEventOrImportedMarketById(resourceId) {
@@ -4085,7 +4453,7 @@ async function findEventOrImportedMarketById(resourceId) {
4085
4453
  }
4086
4454
 
4087
4455
  // src/service/relations.ts
4088
- var import_cluemart_shared31 = require("@timardex/cluemart-shared");
4456
+ var import_cluemart_shared32 = require("@timardex/cluemart-shared");
4089
4457
  function didRemoveAnyEventDates(previousDateTime, nextDateTime) {
4090
4458
  if (!previousDateTime?.length) {
4091
4459
  return false;
@@ -4101,8 +4469,8 @@ function didRemoveAnyStartedDates(previousDateTime, nextDateTime) {
4101
4469
  return false;
4102
4470
  }
4103
4471
  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
4472
+ (prev) => prev.dateStatus === import_cluemart_shared32.EnumEventDateStatus.STARTED && !nextDateTime?.some(
4473
+ (next) => next.startDate === prev.startDate && next.startTime === prev.startTime && next.dateStatus === import_cluemart_shared32.EnumEventDateStatus.STARTED
4106
4474
  )
4107
4475
  );
4108
4476
  }
@@ -4113,7 +4481,7 @@ function updateRelationDatesToCanceled(relationDates, eventDateTime) {
4113
4481
  ) ?? false;
4114
4482
  return {
4115
4483
  ...relationDate,
4116
- status: existsInEvent ? relationDate.status : import_cluemart_shared31.EnumInviteStatus.CANCELED
4484
+ status: existsInEvent ? relationDate.status : import_cluemart_shared32.EnumInviteStatus.CANCELED
4117
4485
  };
4118
4486
  });
4119
4487
  }
@@ -4122,15 +4490,15 @@ function updateRelationDatesToCanceled(relationDates, eventDateTime) {
4122
4490
  var import_dayjs8 = __toESM(require("dayjs"));
4123
4491
 
4124
4492
  // src/service/license/compliance/utils.ts
4125
- var import_cluemart_shared36 = require("@timardex/cluemart-shared");
4493
+ var import_cluemart_shared37 = require("@timardex/cluemart-shared");
4126
4494
  var import_dayjs7 = __toESM(require("dayjs"));
4127
4495
 
4128
4496
  // src/service/license/compliance/event.ts
4129
- var import_cluemart_shared32 = require("@timardex/cluemart-shared");
4497
+ var import_cluemart_shared33 = require("@timardex/cluemart-shared");
4130
4498
  var eventLicences = [
4131
- import_cluemart_shared32.EnumUserLicence.STANDARD_EVENT,
4132
- import_cluemart_shared32.EnumUserLicence.PRO_EVENT,
4133
- import_cluemart_shared32.EnumUserLicence.PRO_PLUS_EVENT
4499
+ import_cluemart_shared33.EnumUserLicence.STANDARD_EVENT,
4500
+ import_cluemart_shared33.EnumUserLicence.PRO_EVENT,
4501
+ import_cluemart_shared33.EnumUserLicence.PRO_PLUS_EVENT
4134
4502
  ];
4135
4503
  async function handleEventLicenceCompliance(user, now) {
4136
4504
  if (!user.licences || !user.events?.length) {
@@ -4342,9 +4710,9 @@ function buildLicenceExpiryPipeline(params) {
4342
4710
  }
4343
4711
 
4344
4712
  // src/service/license/compliance/partner.ts
4345
- var import_cluemart_shared33 = require("@timardex/cluemart-shared");
4713
+ var import_cluemart_shared34 = require("@timardex/cluemart-shared");
4346
4714
  var partnerLicences = [
4347
- import_cluemart_shared33.EnumUserLicence.STANDARD_PARTNER
4715
+ import_cluemart_shared34.EnumUserLicence.STANDARD_PARTNER
4348
4716
  ];
4349
4717
  async function handlePartnerLicenceCompliance(user, now) {
4350
4718
  if (!user.licences || !user.partner) {
@@ -4354,52 +4722,62 @@ async function handlePartnerLicenceCompliance(user, now) {
4354
4722
  }
4355
4723
 
4356
4724
  // src/service/license/compliance/vendor.ts
4357
- var import_cluemart_shared35 = require("@timardex/cluemart-shared");
4725
+ var import_cluemart_shared36 = require("@timardex/cluemart-shared");
4358
4726
  var import_dayjs6 = __toESM(require("dayjs"));
4359
4727
 
4360
4728
  // src/service/license/models.ts
4361
- var import_cluemart_shared34 = require("@timardex/cluemart-shared");
4729
+ var import_cluemart_shared35 = require("@timardex/cluemart-shared");
4362
4730
  var import_dayjs5 = __toESM(require("dayjs"));
4363
4731
  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;
4732
+ var LicenceCategory = /* @__PURE__ */ ((LicenceCategory3) => {
4733
+ LicenceCategory3["EVENT"] = "event";
4734
+ LicenceCategory3["PARTNER"] = "partner";
4735
+ LicenceCategory3["VENDOR"] = "vendor";
4736
+ LicenceCategory3["AFFILIATE"] = "affiliate";
4737
+ LicenceCategory3["SCHOOL"] = "school";
4738
+ return LicenceCategory3;
4371
4739
  })(LicenceCategory || {});
4372
4740
  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 */
4741
+ [import_cluemart_shared35.EnumUserLicence.PRO_EVENT]: "event" /* EVENT */,
4742
+ [import_cluemart_shared35.EnumUserLicence.PRO_PLUS_EVENT]: "event" /* EVENT */,
4743
+ [import_cluemart_shared35.EnumUserLicence.PRO_PLUS_VENDOR]: "vendor" /* VENDOR */,
4744
+ [import_cluemart_shared35.EnumUserLicence.PRO_VENDOR]: "vendor" /* VENDOR */,
4745
+ [import_cluemart_shared35.EnumUserLicence.STANDARD_EVENT]: "event" /* EVENT */,
4746
+ [import_cluemart_shared35.EnumUserLicence.STANDARD_PARTNER]: "partner" /* PARTNER */,
4747
+ [import_cluemart_shared35.EnumUserLicence.STANDARD_VENDOR]: "vendor" /* VENDOR */,
4748
+ [import_cluemart_shared35.EnumUserLicence.STANDARD_AFFILIATE]: "affiliate" /* AFFILIATE */,
4749
+ [import_cluemart_shared35.EnumUserLicence.STANDARD_SCHOOL]: "school" /* SCHOOL */
4382
4750
  };
4383
4751
  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
4752
+ [import_cluemart_shared35.EnumUserLicence.PRO_PLUS_EVENT]: 3,
4753
+ [import_cluemart_shared35.EnumUserLicence.PRO_EVENT]: 2,
4754
+ [import_cluemart_shared35.EnumUserLicence.STANDARD_EVENT]: 1,
4755
+ [import_cluemart_shared35.EnumUserLicence.PRO_PLUS_VENDOR]: 3,
4756
+ [import_cluemart_shared35.EnumUserLicence.PRO_VENDOR]: 2,
4757
+ [import_cluemart_shared35.EnumUserLicence.STANDARD_VENDOR]: 1,
4758
+ [import_cluemart_shared35.EnumUserLicence.STANDARD_PARTNER]: 1,
4759
+ [import_cluemart_shared35.EnumUserLicence.STANDARD_AFFILIATE]: 1,
4760
+ [import_cluemart_shared35.EnumUserLicence.STANDARD_SCHOOL]: 1
4393
4761
  };
4394
4762
  var standardLicences = [
4395
- import_cluemart_shared34.EnumUserLicence.STANDARD_VENDOR,
4396
- import_cluemart_shared34.EnumUserLicence.STANDARD_EVENT,
4397
- import_cluemart_shared34.EnumUserLicence.STANDARD_PARTNER
4763
+ import_cluemart_shared35.EnumUserLicence.STANDARD_VENDOR,
4764
+ import_cluemart_shared35.EnumUserLicence.STANDARD_EVENT,
4765
+ import_cluemart_shared35.EnumUserLicence.STANDARD_PARTNER
4398
4766
  ];
4399
4767
  var standardLicenceSet = new Set(standardLicences);
4400
4768
  function isStandardLicence(licence) {
4401
4769
  return standardLicenceSet.has(licence);
4402
4770
  }
4771
+ var proLicences = [
4772
+ import_cluemart_shared35.EnumUserLicence.PRO_EVENT,
4773
+ import_cluemart_shared35.EnumUserLicence.PRO_PLUS_EVENT,
4774
+ import_cluemart_shared35.EnumUserLicence.PRO_VENDOR,
4775
+ import_cluemart_shared35.EnumUserLicence.PRO_PLUS_VENDOR
4776
+ ];
4777
+ var proLicenceSet = new Set(proLicences);
4778
+ function isProLicence(licence) {
4779
+ return proLicenceSet.has(licence);
4780
+ }
4403
4781
  var categoryRegexMapping = {
4404
4782
  ["event" /* EVENT */]: /_event$/,
4405
4783
  ["partner" /* PARTNER */]: /_partner$/,
@@ -4408,11 +4786,11 @@ var categoryRegexMapping = {
4408
4786
  ["school" /* SCHOOL */]: /_school$/
4409
4787
  };
4410
4788
  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
4789
+ ["event" /* EVENT */]: import_cluemart_shared35.EnumUserLicence.STANDARD_EVENT,
4790
+ ["partner" /* PARTNER */]: import_cluemart_shared35.EnumUserLicence.STANDARD_PARTNER,
4791
+ ["vendor" /* VENDOR */]: import_cluemart_shared35.EnumUserLicence.STANDARD_VENDOR,
4792
+ ["affiliate" /* AFFILIATE */]: import_cluemart_shared35.EnumUserLicence.STANDARD_AFFILIATE,
4793
+ ["school" /* SCHOOL */]: import_cluemart_shared35.EnumUserLicence.STANDARD_SCHOOL
4416
4794
  };
4417
4795
  var LicenceFilterInput = {
4418
4796
  INPUT_USER_LICENCES: "$licences"
@@ -4442,11 +4820,11 @@ function getHighestLicenceForCategory(licences, category) {
4442
4820
  function createLicenceObject(expiryDate, licenceType) {
4443
4821
  const today = (0, import_dayjs5.default)();
4444
4822
  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()
4823
+ [import_cluemart_shared35.LicenceExpiryDate.ONE_YEAR]: today.add(1, "year").endOf("day").toDate(),
4824
+ [import_cluemart_shared35.LicenceExpiryDate.ONE_MONTH]: today.add(1, "month").endOf("day").toDate(),
4825
+ [import_cluemart_shared35.LicenceExpiryDate.TWO_MONTHS]: today.add(2, "month").endOf("day").toDate(),
4826
+ [import_cluemart_shared35.LicenceExpiryDate.THREE_MONTHS]: today.add(3, "month").endOf("day").toDate(),
4827
+ [import_cluemart_shared35.LicenceExpiryDate.SIX_MONTHS]: today.add(6, "month").endOf("day").toDate()
4450
4828
  };
4451
4829
  const licenceObject = {
4452
4830
  expiryDate: expiryDateMapping[expiryDate],
@@ -4550,13 +4928,13 @@ async function checkOwnerHasLicence({
4550
4928
  const owner = await UserModel.findById(userId);
4551
4929
  if (!owner) throw new import_graphql.GraphQLError("Owner not found");
4552
4930
  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 */
4931
+ [import_cluemart_shared35.EnumResourceType.EVENT]: "event" /* EVENT */,
4932
+ [import_cluemart_shared35.EnumResourceType.PARTNER]: "partner" /* PARTNER */,
4933
+ [import_cluemart_shared35.EnumResourceType.VENDOR]: "vendor" /* VENDOR */,
4934
+ [import_cluemart_shared35.EnumResourceType.AFFILIATE]: "affiliate" /* AFFILIATE */,
4935
+ [import_cluemart_shared35.EnumResourceType.SCHOOL]: "school" /* SCHOOL */
4558
4936
  };
4559
- if (!(0, import_cluemart_shared34.isNonVisitorResourceType)(resourceType)) {
4937
+ if (!(0, import_cluemart_shared35.isNonVisitorResourceType)(resourceType)) {
4560
4938
  throw new import_graphql.GraphQLError(`Invalid resource type: ${resourceType}.`);
4561
4939
  }
4562
4940
  const requiredCategory = categoryByResource[resourceType];
@@ -4578,6 +4956,128 @@ async function checkOwnerHasLicence({
4578
4956
  );
4579
4957
  }
4580
4958
  }
4959
+ var resourceLicenceCategory = {
4960
+ [import_cluemart_shared35.EnumResourceType.EVENT]: "event" /* EVENT */,
4961
+ [import_cluemart_shared35.EnumResourceType.PARTNER]: "partner" /* PARTNER */,
4962
+ [import_cluemart_shared35.EnumResourceType.VENDOR]: "vendor" /* VENDOR */
4963
+ };
4964
+ function isProtectedByCurrentStripeSubscription(user, licenceType, now) {
4965
+ const stripe = user.stripe;
4966
+ if (!stripe || stripe.currentPlan !== licenceType) {
4967
+ return false;
4968
+ }
4969
+ const gracePeriodEndsAt = stripe.paymentGracePeriodEndsAt ? (0, import_dayjs5.default)(stripe.paymentGracePeriodEndsAt) : null;
4970
+ 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);
4971
+ if (hasActivePaymentGracePeriod) {
4972
+ return true;
4973
+ }
4974
+ if (!stripe.subscriptionId) {
4975
+ return false;
4976
+ }
4977
+ if (stripe.status !== import_cluemart_shared35.EnumSubscriptionStatus.ACTIVE) {
4978
+ return false;
4979
+ }
4980
+ if (!stripe.endDate) {
4981
+ return false;
4982
+ }
4983
+ const paidThrough = (0, import_dayjs5.default)(stripe.endDate);
4984
+ return paidThrough.isValid() && paidThrough.isAfter(now);
4985
+ }
4986
+ function effectiveLicences({
4987
+ includeStripeProtected = false,
4988
+ licences,
4989
+ now,
4990
+ owner
4991
+ }) {
4992
+ const nowDayjs = (0, import_dayjs5.default)(now);
4993
+ return (licences ?? []).filter((licence) => {
4994
+ if (!licence.licenceType || licence.expiryDate == null) {
4995
+ return false;
4996
+ }
4997
+ if (new Date(licence.expiryDate).getTime() > now.getTime()) {
4998
+ return true;
4999
+ }
5000
+ return Boolean(
5001
+ includeStripeProtected && owner && isProtectedByCurrentStripeSubscription(
5002
+ owner,
5003
+ licence.licenceType,
5004
+ nowDayjs
5005
+ )
5006
+ );
5007
+ });
5008
+ }
5009
+ async function getActiveLicenceForResource({
5010
+ includeStripeProtected = false,
5011
+ userId,
5012
+ resourceType,
5013
+ now = /* @__PURE__ */ new Date()
5014
+ }) {
5015
+ const category = resourceLicenceCategory[resourceType];
5016
+ if (!category) {
5017
+ return null;
5018
+ }
5019
+ const owner = await UserModel.findById(userId, {
5020
+ licences: 1,
5021
+ ...includeStripeProtected ? { stripe: 1 } : {}
5022
+ }).lean();
5023
+ if (!owner?.licences?.length) {
5024
+ return null;
5025
+ }
5026
+ return getHighestLicenceForCategory(
5027
+ effectiveLicences({
5028
+ includeStripeProtected,
5029
+ licences: owner.licences,
5030
+ now,
5031
+ owner
5032
+ }),
5033
+ category
5034
+ );
5035
+ }
5036
+ async function getUserIdsWithActiveProLicence({
5037
+ includeStripeProtected = false,
5038
+ resourceType,
5039
+ userIds,
5040
+ now = /* @__PURE__ */ new Date()
5041
+ }) {
5042
+ const category = resourceLicenceCategory[resourceType];
5043
+ if (!category || userIds.length === 0) {
5044
+ return /* @__PURE__ */ new Set();
5045
+ }
5046
+ const owners = await UserModel.find(
5047
+ { _id: { $in: userIds } },
5048
+ { licences: 1, ...includeStripeProtected ? { stripe: 1 } : {} }
5049
+ ).lean();
5050
+ const allowed = /* @__PURE__ */ new Set();
5051
+ for (const owner of owners ?? []) {
5052
+ const activeLicence = getHighestLicenceForCategory(
5053
+ effectiveLicences({
5054
+ includeStripeProtected,
5055
+ licences: owner.licences,
5056
+ now,
5057
+ owner
5058
+ }),
5059
+ category
5060
+ );
5061
+ if (activeLicence && isProLicence(activeLicence)) {
5062
+ allowed.add(String(owner._id));
5063
+ }
5064
+ }
5065
+ return allowed;
5066
+ }
5067
+ async function hasActiveProLicenceForResource({
5068
+ includeStripeProtected = false,
5069
+ userId,
5070
+ resourceType,
5071
+ now = /* @__PURE__ */ new Date()
5072
+ }) {
5073
+ const activeLicence = await getActiveLicenceForResource({
5074
+ includeStripeProtected,
5075
+ now,
5076
+ resourceType,
5077
+ userId
5078
+ });
5079
+ return activeLicence !== null && isProLicence(activeLicence);
5080
+ }
4581
5081
 
4582
5082
  // src/service/license/compliance/vendor.ts
4583
5083
  async function findUserVendor(userId, logLabel) {
@@ -4636,7 +5136,7 @@ async function applyVendorDowngrade(vendor, ownerUserId) {
4636
5136
  return (result?.matchedCount ?? 0) > 0;
4637
5137
  }
4638
5138
  async function downgradeVendorProFeatures(userId, licenceType) {
4639
- const isStandardVendor = licenceType === import_cluemart_shared35.EnumUserLicence.STANDARD_VENDOR;
5139
+ const isStandardVendor = licenceType === import_cluemart_shared36.EnumUserLicence.STANDARD_VENDOR;
4640
5140
  if (!isStandardVendor) {
4641
5141
  return;
4642
5142
  }
@@ -4683,7 +5183,7 @@ async function applyVendorRestore(vendor, ownerUserId) {
4683
5183
  return (result?.matchedCount ?? 0) > 0;
4684
5184
  }
4685
5185
  async function restoreVendorProFeatures(userId, licenceType) {
4686
- const isProVendor = licenceType === import_cluemart_shared35.EnumUserLicence.PRO_VENDOR || licenceType === import_cluemart_shared35.EnumUserLicence.PRO_PLUS_VENDOR;
5186
+ const isProVendor = licenceType === import_cluemart_shared36.EnumUserLicence.PRO_VENDOR || licenceType === import_cluemart_shared36.EnumUserLicence.PRO_PLUS_VENDOR;
4687
5187
  if (!isProVendor) {
4688
5188
  return;
4689
5189
  }
@@ -4698,28 +5198,6 @@ async function restoreVendorProFeatures(userId, licenceType) {
4698
5198
  throw error;
4699
5199
  }
4700
5200
  }
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
5201
  async function handleVendorLicenceCompliance(user, now) {
4724
5202
  if (!user.licences || !user.vendor) {
4725
5203
  return;
@@ -4730,10 +5208,10 @@ async function handleVendorLicenceCompliance(user, now) {
4730
5208
  if (vendorLicencesOfUser.length === 0) {
4731
5209
  return;
4732
5210
  }
4733
- const proLicences = vendorLicencesOfUser.filter(
4734
- (licence) => licence.licenceType !== import_cluemart_shared35.EnumUserLicence.STANDARD_VENDOR
5211
+ const proLicences2 = vendorLicencesOfUser.filter(
5212
+ (licence) => licence.licenceType !== import_cluemart_shared36.EnumUserLicence.STANDARD_VENDOR
4735
5213
  );
4736
- const expiredProLicences = proLicences.filter(
5214
+ const expiredProLicences = proLicences2.filter(
4737
5215
  (licence) => !(0, import_dayjs6.default)(licence.expiryDate).isAfter(now)
4738
5216
  );
4739
5217
  const stripeProtectedLicenceTypes = new Set(
@@ -4744,7 +5222,7 @@ async function handleVendorLicenceCompliance(user, now) {
4744
5222
  const expiredProLicence = expiredProLicences.some(
4745
5223
  (licence) => !stripeProtectedLicenceTypes.has(licence.licenceType)
4746
5224
  );
4747
- const hasValidProLicence = stripeProtectedLicenceTypes.size > 0 || hasValidLicence(proLicences, import_cluemart_shared35.vendorLicences, now);
5225
+ const hasValidProLicence = stripeProtectedLicenceTypes.size > 0 || hasValidLicence(proLicences2, import_cluemart_shared36.vendorLicences, now);
4748
5226
  const hasExpiredVendorLicence = vendorLicencesOfUser.some(
4749
5227
  (licence) => !(0, import_dayjs6.default)(licence.expiryDate).isAfter(now) && !stripeProtectedLicenceTypes.has(licence.licenceType)
4750
5228
  );
@@ -4760,7 +5238,7 @@ async function handleVendorLicenceCompliance(user, now) {
4760
5238
  "owner.userId": user._id
4761
5239
  }).lean().exec();
4762
5240
  }
4763
- const licencesToSync = import_cluemart_shared35.vendorLicences.filter(
5241
+ const licencesToSync = import_cluemart_shared36.vendorLicences.filter(
4764
5242
  (licenceType) => !stripeProtectedLicenceTypes.has(licenceType)
4765
5243
  );
4766
5244
  await syncUserLicencesAfterExpiry(user._id, licencesToSync, now, "downgrade");
@@ -4775,11 +5253,11 @@ async function handleVendorLicenceCompliance(user, now) {
4775
5253
  data: {
4776
5254
  resourceId: String(vendor._id),
4777
5255
  resourceName: vendor.name,
4778
- resourceType: import_cluemart_shared35.EnumNotificationResourceType.DOWNGRADED_VENDOR
5256
+ resourceType: import_cluemart_shared36.EnumNotificationResourceType.DOWNGRADED_VENDOR
4779
5257
  },
4780
5258
  message: `Your Vendor licence has been downgraded due to licence expiration.`,
4781
5259
  title: `Vendor Licence Downgraded`,
4782
- type: import_cluemart_shared35.EnumNotificationType.SYSTEM,
5260
+ type: import_cluemart_shared36.EnumNotificationType.SYSTEM,
4783
5261
  userIds: [user._id]
4784
5262
  };
4785
5263
  await sendDeactivationNotification(payload, user._id, vendor.name, "vendor");
@@ -4793,26 +5271,11 @@ async function vendorOwnerHasProLicence(vendorId) {
4793
5271
  if (!vendor) {
4794
5272
  return false;
4795
5273
  }
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];
5274
+ return hasActiveProLicenceForResource({
5275
+ includeStripeProtected: true,
5276
+ resourceType: import_cluemart_shared36.EnumResourceType.VENDOR,
5277
+ userId: vendor.owner.userId
5278
+ });
4816
5279
  }
4817
5280
 
4818
5281
  // src/service/license/compliance/utils.ts
@@ -4822,12 +5285,12 @@ async function syncUserLicencesAfterExpiry(userId, licenceTypes, now, mode = "do
4822
5285
  const pipeline = buildLicenceExpiryPipeline({
4823
5286
  downgradeBranches: [
4824
5287
  {
4825
- case: import_cluemart_shared36.EnumUserLicence.PRO_PLUS_VENDOR,
4826
- then: import_cluemart_shared36.EnumUserLicence.STANDARD_VENDOR
5288
+ case: import_cluemart_shared37.EnumUserLicence.PRO_PLUS_VENDOR,
5289
+ then: import_cluemart_shared37.EnumUserLicence.STANDARD_VENDOR
4827
5290
  },
4828
5291
  {
4829
- case: import_cluemart_shared36.EnumUserLicence.PRO_VENDOR,
4830
- then: import_cluemart_shared36.EnumUserLicence.STANDARD_VENDOR
5292
+ case: import_cluemart_shared37.EnumUserLicence.PRO_VENDOR,
5293
+ then: import_cluemart_shared37.EnumUserLicence.STANDARD_VENDOR
4831
5294
  }
4832
5295
  ],
4833
5296
  licenceTypes,
@@ -4956,7 +5419,7 @@ var REMINDER_WINDOW_MIN_HOURS = 6.5 * 24;
4956
5419
  var REMINDER_WINDOW_MAX_HOURS = 7.5 * 24;
4957
5420
 
4958
5421
  // src/service/license/reminder/utils.ts
4959
- var import_cluemart_shared37 = require("@timardex/cluemart-shared");
5422
+ var import_cluemart_shared38 = require("@timardex/cluemart-shared");
4960
5423
  var import_utils8 = require("@timardex/cluemart-shared/utils");
4961
5424
  var import_dayjs9 = __toESM(require("dayjs"));
4962
5425
 
@@ -5022,28 +5485,28 @@ function isLicenseExpiringIn7Days(expiryDate, now) {
5022
5485
  return hoursUntilExpiry >= REMINDER_WINDOW_MIN_HOURS && hoursUntilExpiry <= REMINDER_WINDOW_MAX_HOURS;
5023
5486
  }
5024
5487
  function getLicenseName(licenceType) {
5025
- return import_cluemart_shared37.licenseNiceNames[licenceType] || licenceType;
5488
+ return import_cluemart_shared38.licenseNiceNames[licenceType] || licenceType;
5026
5489
  }
5027
5490
  function getNotificationTypes(isVendorLicense, isPartnerLicense) {
5028
5491
  if (isVendorLicense) {
5029
5492
  return {
5030
- notificationType: import_cluemart_shared37.EnumNotificationType.SYSTEM,
5031
- resourceType: import_cluemart_shared37.EnumNotificationResourceType.EXPIRATION_REMINDER_VENDOR
5493
+ notificationType: import_cluemart_shared38.EnumNotificationType.SYSTEM,
5494
+ resourceType: import_cluemart_shared38.EnumNotificationResourceType.EXPIRATION_REMINDER_VENDOR
5032
5495
  };
5033
5496
  }
5034
5497
  if (isPartnerLicense) {
5035
5498
  return {
5036
- notificationType: import_cluemart_shared37.EnumNotificationType.SYSTEM,
5037
- resourceType: import_cluemart_shared37.EnumNotificationResourceType.EXPIRATION_REMINDER_PARTNER
5499
+ notificationType: import_cluemart_shared38.EnumNotificationType.SYSTEM,
5500
+ resourceType: import_cluemart_shared38.EnumNotificationResourceType.EXPIRATION_REMINDER_PARTNER
5038
5501
  };
5039
5502
  }
5040
5503
  return {
5041
- notificationType: import_cluemart_shared37.EnumNotificationType.SYSTEM,
5042
- resourceType: import_cluemart_shared37.EnumNotificationResourceType.EXPIRATION_REMINDER_EVENT
5504
+ notificationType: import_cluemart_shared38.EnumNotificationType.SYSTEM,
5505
+ resourceType: import_cluemart_shared38.EnumNotificationResourceType.EXPIRATION_REMINDER_EVENT
5043
5506
  };
5044
5507
  }
5045
5508
  async function getLicenseResourceInfo(user, licence) {
5046
- const isVendorLicense = import_cluemart_shared37.vendorLicences.includes(licence.licenceType);
5509
+ const isVendorLicense = import_cluemart_shared38.vendorLicences.includes(licence.licenceType);
5047
5510
  const isPartnerLicense = partnerLicences.includes(licence.licenceType);
5048
5511
  const licenceName = getLicenseName(licence.licenceType);
5049
5512
  const { notificationType, resourceType } = getNotificationTypes(
@@ -5091,11 +5554,11 @@ async function getLicenseResourceInfo(user, licence) {
5091
5554
  };
5092
5555
  }
5093
5556
  function getLicenceExpiryMode(licenceType) {
5094
- return licenceType === import_cluemart_shared37.EnumUserLicence.PRO_VENDOR || licenceType === import_cluemart_shared37.EnumUserLicence.PRO_PLUS_VENDOR ? "downgrade" : "extend";
5557
+ return licenceType === import_cluemart_shared38.EnumUserLicence.PRO_VENDOR || licenceType === import_cluemart_shared38.EnumUserLicence.PRO_PLUS_VENDOR ? "downgrade" : "extend";
5095
5558
  }
5096
5559
  async function sendLicenseReminder(user, licence) {
5097
5560
  const licenceName = getLicenseName(licence.licenceType);
5098
- const expiryDate = (0, import_dayjs9.default)(licence.expiryDate).format(import_cluemart_shared37.dateFormat);
5561
+ const expiryDate = (0, import_dayjs9.default)(licence.expiryDate).format(import_cluemart_shared38.dateFormat);
5099
5562
  const userId = String(user._id);
5100
5563
  const resourceInfo = await getLicenseResourceInfo(user, licence);
5101
5564
  if (!resourceInfo) {
@@ -5234,6 +5697,7 @@ async function remindUsersAboutLicenseExpiration() {
5234
5697
  AiImportRunModel,
5235
5698
  AiImportedMarketModel,
5236
5699
  AppSettingModel,
5700
+ AssociateTypeSchema,
5237
5701
  AuthHandoffTokenModel,
5238
5702
  BILLING_CATALOG_COLLECTION_NAME,
5239
5703
  BillingCatalogModel,
@@ -5273,6 +5737,7 @@ async function remindUsersAboutLicenseExpiration() {
5273
5737
  VendorInfoModel,
5274
5738
  VendorModel,
5275
5739
  VerificationTokenModel,
5740
+ acceptedAssociateUserIds,
5276
5741
  activeAffiliateCodeExists,
5277
5742
  awardAffiliateVendorSubscriptionRewards,
5278
5743
  baseResourceFields,
@@ -5289,6 +5754,9 @@ async function remindUsersAboutLicenseExpiration() {
5289
5754
  createLicenceObject,
5290
5755
  dateTimeSchema,
5291
5756
  dedupeArchivedSlotsByStartDateTime,
5757
+ detachAssociateGrantsForResources,
5758
+ detachStaleAssociateGrants,
5759
+ detachUsersFromResource,
5292
5760
  didRemoveAnyEventDates,
5293
5761
  didRemoveAnyStartedDates,
5294
5762
  downgradeVendorProFeatures,
@@ -5299,6 +5767,8 @@ async function remindUsersAboutLicenseExpiration() {
5299
5767
  express,
5300
5768
  findAffiliateByPromoCode,
5301
5769
  findEventOrImportedMarketById,
5770
+ getActiveLicenceForResource,
5771
+ getAssociateAccessMeta,
5302
5772
  getBillingCatalogDefinition,
5303
5773
  getEventResourceInfo,
5304
5774
  getHighestLicenceForCategory,
@@ -5309,11 +5779,17 @@ async function remindUsersAboutLicenseExpiration() {
5309
5779
  getPayingStripeSubscriptionPlan,
5310
5780
  getPayingVendorStripeSubscriptionPlan,
5311
5781
  getSubscriptionRewardPeriodBounds,
5782
+ getUserIdsWithActiveProLicence,
5312
5783
  getVendorResourceInfo,
5784
+ grantAssociateGrants,
5313
5785
  handleEventLicenceCompliance,
5314
5786
  handlePartnerLicenceCompliance,
5315
5787
  handleVendorLicenceCompliance,
5788
+ hasActiveProLicenceForResource,
5316
5789
  hasValidLicence,
5790
+ isAssociableResourceType,
5791
+ isProLicence,
5792
+ isProtectedByCurrentStripeSubscription,
5317
5793
  isStandardLicence,
5318
5794
  isValidObjectId,
5319
5795
  licenceCategoryMapping,
@@ -5331,6 +5807,7 @@ async function remindUsersAboutLicenseExpiration() {
5331
5807
  processUserCompliance,
5332
5808
  processUserLicenseReminders,
5333
5809
  publishNotificationEvents,
5810
+ reconcileAssociateGrants,
5334
5811
  refundPolicySchema,
5335
5812
  relatedPostSchema,
5336
5813
  relationDatesSchema,