@timardex/cluemart-server-shared 1.1.35 → 1.1.37

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.d.mts CHANGED
@@ -1,13 +1,13 @@
1
1
  import * as _timardex_cluemart_shared from '@timardex/cluemart-shared';
2
- import { AdType, CreateBulkNotificationInput, NotificationType, EnumUserRole, ChatMessageType, ParticipantType, ChatType, ReportChatUser, RelatedPostType, OwnerType, SocialMediaType, ResourceImageType, Category, UserLicenceType, ResourceContactDetailsType, TermsAgreement, RelationDate, DateTimeType, LocationGeoType, LocationType, SocialShareResourceType, PosterUsageType, GoogleImportedMarket, PushTokenType, RelationType, ResourceActivityType, UserActivityEvent, UserType, VendorProductList, VendorType, VendorInfoType, UnregisteredVendorInvitationType, UnregisteredVendorType, EventType, StallType, RefundPolicy, EventInfoType, PartnerType, PostType, PostContentType, PostResource, AppSettingsType, GameType, GameDocType, SchoolType, AffiliateRewardType, AffiliateResourceType, AffiliateType, CouponType, CouponDataType, CouponParticipantUserType, PromoCodeType, EnumAffiliateRewardType, EnumUserLicence, EventListItemType, DateTimeWithPriceType } from '@timardex/cluemart-shared';
2
+ import { AdType, CreateBulkNotificationInput, NotificationType, EnumUserRole, ChatMessageType, ParticipantType, ChatType, ReportChatUser, RelatedPostType, OwnerType, SocialMediaType, ResourceImageType, Category, UserLicenceType, ResourceContactDetailsType, TermsAgreement, RelationDate, DateTimeType, LocationGeoType, LocationType, SocialShareResourceType, PosterUsageType, GoogleImportedMarket, PushTokenType, RelationType, ResourceActivityType, UserActivityEvent, UserType, VendorProductList, VendorType, VendorInfoType, UnregisteredVendorInvitationType, UnregisteredVendorType, EventType, StallType, RefundPolicy, EventInfoType, PartnerType, PostType, PostContentType, PostResource, AppSettingsType, GameType, GameDocType, SchoolType, AffiliateRewardType, AffiliateResourceType, AffiliateType, CouponType, CouponDataType, CouponParticipantUserType, PromoCodeType, EnumAffiliateRewardType, EventListItemType, DateTimeWithPriceType, EnumUserLicence as EnumUserLicence$1, EnumNotificationResourceType, EnumNotificationType, EnumResourceType } from '@timardex/cluemart-shared';
3
3
  import * as mongoose from 'mongoose';
4
4
  import mongoose__default from 'mongoose';
5
5
  export { default as mongoose } from 'mongoose';
6
6
  import { NotificationCount, DateTimeType as DateTimeType$1 } from '@timardex/cluemart-shared/types';
7
7
  import express from 'express';
8
8
  export { default as express } from 'express';
9
- import dayjs from 'dayjs';
10
- import { EnumUserLicence as EnumUserLicence$1 } from '@timardex/cluemart-shared/enums';
9
+ import dayjs, { Dayjs } from 'dayjs';
10
+ import { EnumUserLicence } from '@timardex/cluemart-shared/enums';
11
11
 
12
12
  declare const AdModel: mongoose__default.Model<AdType, {}, {}, {}, mongoose__default.Document<unknown, {}, AdType, {}, {}> & AdType & Required<{
13
13
  _id: string;
@@ -923,8 +923,6 @@ declare function sendPushNotifications({ data, message, title, userIds, }: Schem
923
923
  */
924
924
  declare function updateAdStatuses(): Promise<void>;
925
925
 
926
- declare function updateVendorBasedOnUserLicense(userId: ObjectId, licenceType: EnumUserLicence): Promise<void>;
927
-
928
926
  /**
929
927
  * True when `value` is a valid Mongo ObjectId string.
930
928
  */
@@ -971,8 +969,8 @@ declare function updateRelationDatesToUnavailable(relationDates: SchemaRelationT
971
969
 
972
970
  type PayingStripeSubscriptionPlanResult = {
973
971
  hasSubscription: boolean;
974
- plan: EnumUserLicence$1 | null;
975
- validTypes: Set<EnumUserLicence$1>;
972
+ plan: EnumUserLicence | null;
973
+ validTypes: Set<EnumUserLicence>;
976
974
  };
977
975
  /**
978
976
  * Returns the paying Stripe plan when `currentPlan` is any PRO plan
@@ -990,4 +988,253 @@ declare function getPayingVendorStripeSubscriptionPlan(userId: ObjectId | string
990
988
  */
991
989
  declare function getPayingEventStripeSubscriptionPlan(userId: ObjectId | string, now?: Date): Promise<PayingStripeSubscriptionPlanResult>;
992
990
 
993
- export { ACTIVE_NOT_DELETED_FILTER, APP_SETTINGS_ID, AdModel, AffiliateModel, AppSettingModel, type AuthUser, type AwardAffiliateVendorSubscriptionRewardsResult, CategorySchema, ChatModel, ChatReportModel, ContactDetailsSchema, type CouponDocument, CouponModel, EnumPubSubEvents, EventInfoModel, EventModel, GameModel, GoogleImportedMarketModel, type GraphQLContext, NotificationModel, type NotificationPubSub, type ObjectId, OwnerTypeSchema, PartnerModel, PostModel, PushTokenModel, RelationModel, RelationTypeSchema, ResourceActivityModel, ResourceImageTypeSchema, SUBSCRIPTION_REWARD_TIMEZONE, type SchemaAffiliateResourceType, type SchemaAffiliateReward, type SchemaChatMessageReactionType, type SchemaChatMessageReplyPreviewType, type SchemaChatMessageSeenType, type SchemaChatMessageType, type SchemaChatReportType, type SchemaChatType, type SchemaCreateBulkNotificationInput, type SchemaEventInfoType, type SchemaEventType, type SchemaGameType, type SchemaGoogleImportedMarket, type SchemaNotificationType, type SchemaOwnerType, type SchemaParticipantType, type SchemaPartnerType, type SchemaPostType, type SchemaPushTokenType, type SchemaRelatedPostType, type SchemaRelationType, type SchemaUnregisteredVendorInvitationType, type SchemaUnregisteredVendorType, type SchemaUserActivityEvent, type SchemaUserType, type SchemaVendorInfoType, type SchemaVendorType, SchoolModel, SocialMediaTypeSchema, StallTypeSchema, type SubscriptionPayload, UnregisteredVendorModel, UserModel, VendorInfoModel, VendorModel, VerificationTokenModel, type VerificationTokenType, activeAffiliateCodeExists, awardAffiliateVendorSubscriptionRewards, baseResourceFields, connectToDatabase, convertObjectIdsToStrings, dateTimeSchema, didRemoveAnyEventDates, findAffiliateByPromoCode, findEventOrImportedMarketById, getPayingEventStripeSubscriptionPlan, getPayingStripeSubscriptionPlan, getPayingVendorStripeSubscriptionPlan, getSubscriptionRewardPeriodBounds, isValidObjectId, locationGeoSchema, locationsSchema, mapVendorLicenceToSubscriptionRewardType, normalizeAffiliatePromoCodes, normalizePromoCode, notifyUsers, publishNotificationEvents, refundPolicySchema, relatedPostSchema, relationDatesSchema, resourceRelationsSchema, saveNotificationsInDb, sendPushNotifications, socialShareResourceSchema, termsAgreementSchema, updateAdStatuses, updateAllEventDateTimeStatuses, updateRelationDatesToUnavailable, updateSingleDateTimeStatus, updateVendorBasedOnUserLicense, userLicenseSchema, vendorProductTypeSchema };
991
+ declare function ensureUserLicenseCompliance(): Promise<void>;
992
+
993
+ declare const eventLicences: EnumUserLicence$1[];
994
+ /**
995
+ * Handles event licence compliance for a single user.
996
+ *
997
+ * Event licences are kept and extended on expiry — no deactivation.
998
+ */
999
+ declare function handleEventLicenceCompliance(user: SchemaUserType, now: Dayjs): Promise<void>;
1000
+
1001
+ /**
1002
+ * Builds an aggregation pipeline that atomically applies expiry rules to the
1003
+ * `licences` array. Used by syncUserLicencesAfterExpiry for a single
1004
+ * updateOne with no read-modify-write.
1005
+ *
1006
+ * downgradeBranches: PRO_* / PRO_PLUS_* licence types mapped to their STANDARD_*
1007
+ * counterpart (e.g. pro_plus_event → standard_event). Use EnumUserLicence in the
1008
+ * caller to avoid string drift.
1009
+ *
1010
+ * Note: Uses MongoDB aggregation keys "then"/"case" (required by $cond/$switch).
1011
+ *
1012
+ * Requires MongoDB 4.2+: this emits an updateOne aggregation pipeline (the
1013
+ * [ { $set: ... } ] form) and uses $reduce / $indexOfArray / $regexMatch in the
1014
+ * dedupe + standard-detection stages. The project runs MongoDB 8.0
1015
+ * (docker-compose.yml), well above the minimum.
1016
+ */
1017
+ declare function buildLicenceExpiryPipeline(params: {
1018
+ /** Pairs of (licenceType, standardCounterpart) for downgrade; e.g. PRO_PLUS_VENDOR → STANDARD_VENDOR */
1019
+ downgradeBranches: ReadonlyArray<{
1020
+ case: string;
1021
+ then: string;
1022
+ }>;
1023
+ licenceTypes: string[];
1024
+ /**
1025
+ * How expired, targeted licences are handled:
1026
+ * - "downgrade": extend expired STANDARD_* and downgrade expired PRO_* or PRO_PLUS_* (vendor)
1027
+ * - "extend": keep the licence as-is and extend expiryDate to oneYearFromNow (partner/event)
1028
+ */
1029
+ mode?: "downgrade" | "extend";
1030
+ nowDate: Date;
1031
+ oneYearFromNow: Date;
1032
+ }): object[];
1033
+
1034
+ declare const partnerLicences: EnumUserLicence$1[];
1035
+ /**
1036
+ * Handles partner licence compliance for a single user.
1037
+ *
1038
+ * Partner licences are kept and extended on expiry — no deactivation.
1039
+ */
1040
+ declare function handlePartnerLicenceCompliance(user: SchemaUserType, now: Dayjs): Promise<void>;
1041
+
1042
+ /**
1043
+ * Syncs the user's `licences` array
1044
+ * Uses a single atomic updateOne with an aggregation pipeline so it is safe under
1045
+ * concurrency (no read-modify-write, no lost updates).
1046
+ *
1047
+ * Rules (applied server-side only to licences whose licenceType is in licenceTypes):
1048
+ * - mode "downgrade" (vendor): expired STANDARD_* → extended to one year from now;
1049
+ * expired PRO_* or PRO_PLUS_* → downgraded to STANDARD_* with issuedDate=now and
1050
+ * expiryDate=one year from now
1051
+ * - mode "extend" (partner/event): expired licences are kept and their expiryDate
1052
+ * is extended to one year from now
1053
+ * - Non-expired or non-targeted licences are unchanged in both modes
1054
+ */
1055
+ declare function syncUserLicencesAfterExpiry(userId: ObjectId, licenceTypes: EnumUserLicence$1[], now: dayjs.Dayjs, mode?: "downgrade" | "extend"): Promise<void>;
1056
+ /**
1057
+ * Checks if user has a valid licence of the given types
1058
+ */
1059
+ declare function hasValidLicence(licences: UserLicenceType[], licenceTypes: EnumUserLicence$1[], now: dayjs.Dayjs): boolean;
1060
+ /**
1061
+ * Sends a deactivation notification to the user
1062
+ */
1063
+ declare function sendDeactivationNotification(payload: {
1064
+ data: {
1065
+ resourceId: string;
1066
+ resourceName: string;
1067
+ resourceType: EnumNotificationResourceType;
1068
+ };
1069
+ message: string;
1070
+ title: string;
1071
+ type: EnumNotificationType;
1072
+ userIds: ObjectId[];
1073
+ }, userId: ObjectId, resourceName: string, resourceType: string): Promise<void>;
1074
+ /**
1075
+ * Processes license compliance for a single user
1076
+ */
1077
+ declare function processUserCompliance(user: SchemaUserType, now: dayjs.Dayjs): Promise<void>;
1078
+
1079
+ declare function updateVendorBasedOnUserLicense(userId: ObjectId, licenceType: EnumUserLicence$1): Promise<void>;
1080
+ declare const vendorLicences: EnumUserLicence$1[];
1081
+ /**
1082
+ * Handles vendor licence compliance for a single user
1083
+ */
1084
+ declare function handleVendorLicenceCompliance(user: SchemaUserType, now: Dayjs): Promise<void>;
1085
+ /**
1086
+ * Checks whether a vendor's owner currently holds a PRO (or higher) vendor licence.
1087
+ */
1088
+ declare function vendorOwnerHasProLicence(vendorId: string): Promise<boolean>;
1089
+
1090
+ /**
1091
+ * Gets event resource information for a reminder
1092
+ */
1093
+ declare function getEventResourceInfo(userId: ObjectId, eventIds: ObjectId[]): Promise<{
1094
+ resourceId: string;
1095
+ resourceName: string;
1096
+ } | null>;
1097
+
1098
+ /**
1099
+ * Gets partner resource information for a reminder
1100
+ */
1101
+ declare function getPartnerResourceInfo(userId: ObjectId, partnerId: ObjectId): Promise<{
1102
+ resourceId: string;
1103
+ resourceName: string;
1104
+ } | null>;
1105
+
1106
+ /**
1107
+ * Sends license expiration reminders to users whose licenses expire in 7 days
1108
+ */
1109
+ declare function remindUsersAboutLicenseExpiration(): Promise<void>;
1110
+
1111
+ /**
1112
+ * License expiration reminder window bounds.
1113
+ *
1114
+ * A licence qualifies for the "7 days before expiry" reminder when its expiry is
1115
+ * between {@link REMINDER_WINDOW_MIN_HOURS} and {@link REMINDER_WINDOW_MAX_HOURS}
1116
+ * away.
1117
+ *
1118
+ * Expressed in hours (derived from days) because dayjs rounds fractional "day"
1119
+ * adds: `now.add(6.5, "day")` becomes 7 days and `now.add(7.5, "day")` 8 days.
1120
+ */
1121
+ declare const REMINDER_WINDOW_MIN_HOURS: number;
1122
+ declare const REMINDER_WINDOW_MAX_HOURS: number;
1123
+
1124
+ /**
1125
+ * Single source of truth for how a licence type is handled on expiry.
1126
+ *
1127
+ * - "downgrade": PRO_VENDOR / PRO_PLUS_VENDOR → downgraded to STANDARD_VENDOR.
1128
+ * - "extend": every other licence type is auto-extended for another year.
1129
+ *
1130
+ * Note: `cluemart-server`'s `licenceCategoryMapping` / `licencePriority`
1131
+ * (ModelHelpers/licenses/index.ts) is a SEPARATE concern (entitlement priority,
1132
+ * not expiry behaviour) and is intentionally not merged here.
1133
+ */
1134
+ declare function getLicenceExpiryMode(licenceType: EnumUserLicence$1): "downgrade" | "extend";
1135
+ /**
1136
+ * Sends a reminder notification for a license.
1137
+ *
1138
+ * Intentionally does NOT use the shared `notifyUsers` helper: that helper
1139
+ * persists via `saveNotificationsInDb` (plain `insertMany`), whereas this job
1140
+ * must claim the dedupe slot atomically through
1141
+ * {@link checkAndCreateNotification} (upsert) so a reminder is only sent once.
1142
+ * Push is therefore sent directly via `sendPushNotifications` only after the
1143
+ * claim succeeds.
1144
+ */
1145
+ declare function sendLicenseReminder(user: {
1146
+ _id: ObjectId;
1147
+ vendor?: ObjectId;
1148
+ events?: ObjectId[];
1149
+ partner?: ObjectId;
1150
+ }, licence: {
1151
+ licenceType: EnumUserLicence$1;
1152
+ expiryDate: Date | string;
1153
+ }): Promise<void>;
1154
+ /**
1155
+ * Processes a single license and sends reminder if needed
1156
+ *
1157
+ * Checks if a license expires within the 6.5-7.5 day window and hasn't already
1158
+ * received a reminder. See isLicenseExpiringIn7Days for details on the reminder window.
1159
+ *
1160
+ * @returns true if a reminder should be sent, false otherwise
1161
+ */
1162
+ declare function processLicenseReminder(user: {
1163
+ _id: ObjectId;
1164
+ vendor?: ObjectId;
1165
+ events?: ObjectId[];
1166
+ partner?: ObjectId;
1167
+ }, licence: {
1168
+ licenceType: EnumUserLicence$1;
1169
+ expiryDate: Date | string;
1170
+ }, now: dayjs.Dayjs): Promise<boolean>;
1171
+ /**
1172
+ * Sends a reminder for a single license, handling errors gracefully
1173
+ */
1174
+ declare function sendReminderSafely(user: {
1175
+ _id: ObjectId;
1176
+ vendor?: ObjectId;
1177
+ events?: ObjectId[];
1178
+ partner?: ObjectId;
1179
+ }, licence: UserLicenceType): Promise<boolean>;
1180
+ /**
1181
+ * Processes reminders for a single user's licenses
1182
+ */
1183
+ declare function processUserLicenseReminders(user: SchemaUserType, now: dayjs.Dayjs): Promise<number>;
1184
+
1185
+ /**
1186
+ * Gets vendor resource information for a reminder
1187
+ */
1188
+ declare function getVendorResourceInfo(userId: ObjectId, vendorId: ObjectId): Promise<{
1189
+ resourceId: string;
1190
+ resourceName: string;
1191
+ } | null>;
1192
+
1193
+ declare enum LicenceExpiryDate {
1194
+ ONE_YEAR = "1 year",
1195
+ ONE_MONTH = "1 month",
1196
+ TWO_MONTHS = "2 months"
1197
+ }
1198
+ declare enum LicenceCategory {
1199
+ EVENT = "event",
1200
+ PARTNER = "partner",
1201
+ VENDOR = "vendor",
1202
+ AFFILIATE = "affiliate",
1203
+ SCHOOL = "school"
1204
+ }
1205
+ declare const licenceCategoryMapping: Record<EnumUserLicence$1, LicenceCategory>;
1206
+ declare const licencePriority: Record<EnumUserLicence$1, number>;
1207
+ declare const standardLicences: readonly [EnumUserLicence$1.STANDARD_VENDOR, EnumUserLicence$1.STANDARD_EVENT, EnumUserLicence$1.STANDARD_PARTNER];
1208
+ declare function isStandardLicence(licence: EnumUserLicence$1): licence is (typeof standardLicences)[number];
1209
+ type LicenceUpgradeArgs = {
1210
+ expiryDate: LicenceExpiryDate;
1211
+ licenceType: EnumUserLicence$1;
1212
+ userId: ObjectId;
1213
+ };
1214
+ type LicenceUpgradeResult = {
1215
+ licenceObject: UserLicenceType;
1216
+ updatedUser: SchemaUserType | null;
1217
+ };
1218
+ declare function getLicenceCategory(licence: EnumUserLicence$1): LicenceCategory;
1219
+ declare function getHighestLicenceForCategory(licences: UserLicenceType[] | null | undefined, category: LicenceCategory): EnumUserLicence$1 | null;
1220
+ declare function createLicenceObject(expiryDate: LicenceExpiryDate, licenceType: EnumUserLicence$1): UserLicenceType;
1221
+ declare function replaceUserLicenceWithObject({ userId, licenceObject, protectHigherLicence, }: {
1222
+ userId: ObjectId;
1223
+ licenceObject: UserLicenceType;
1224
+ protectHigherLicence?: boolean;
1225
+ }): Promise<void>;
1226
+ /**
1227
+ * Upgrades a user's license by adding a new license object to their account.
1228
+ * It calculates the expiry date based on the provided expiry duration and updates the user's licenses in the database.
1229
+ * @param licenceType - The licence type to upgrade the user to.
1230
+ * @param expiryDate - The expiry duration for the license being upgraded.
1231
+ * @param userId - The ID of the user whose license is being upgraded.
1232
+ * @returns An object containing the updated user and the new license object.
1233
+ */
1234
+ declare const upgradeUserToLicence: ({ licenceType, expiryDate, userId, }: LicenceUpgradeArgs) => Promise<LicenceUpgradeResult>;
1235
+ declare function checkOwnerHasLicence({ userId, resourceType, }: {
1236
+ userId: ObjectId;
1237
+ resourceType: EnumResourceType;
1238
+ }): Promise<void>;
1239
+
1240
+ export { ACTIVE_NOT_DELETED_FILTER, APP_SETTINGS_ID, AdModel, AffiliateModel, AppSettingModel, type AuthUser, type AwardAffiliateVendorSubscriptionRewardsResult, CategorySchema, ChatModel, ChatReportModel, ContactDetailsSchema, type CouponDocument, CouponModel, EnumPubSubEvents, EventInfoModel, EventModel, GameModel, GoogleImportedMarketModel, type GraphQLContext, LicenceCategory, LicenceExpiryDate, NotificationModel, type NotificationPubSub, type ObjectId, OwnerTypeSchema, PartnerModel, PostModel, PushTokenModel, REMINDER_WINDOW_MAX_HOURS, REMINDER_WINDOW_MIN_HOURS, RelationModel, RelationTypeSchema, ResourceActivityModel, ResourceImageTypeSchema, SUBSCRIPTION_REWARD_TIMEZONE, type SchemaAffiliateResourceType, type SchemaAffiliateReward, type SchemaChatMessageReactionType, type SchemaChatMessageReplyPreviewType, type SchemaChatMessageSeenType, type SchemaChatMessageType, type SchemaChatReportType, type SchemaChatType, type SchemaCreateBulkNotificationInput, type SchemaEventInfoType, type SchemaEventType, type SchemaGameType, type SchemaGoogleImportedMarket, type SchemaNotificationType, type SchemaOwnerType, type SchemaParticipantType, type SchemaPartnerType, type SchemaPostType, type SchemaPushTokenType, type SchemaRelatedPostType, type SchemaRelationType, type SchemaUnregisteredVendorInvitationType, type SchemaUnregisteredVendorType, type SchemaUserActivityEvent, type SchemaUserType, type SchemaVendorInfoType, type SchemaVendorType, SchoolModel, SocialMediaTypeSchema, StallTypeSchema, type SubscriptionPayload, UnregisteredVendorModel, UserModel, VendorInfoModel, VendorModel, VerificationTokenModel, type VerificationTokenType, activeAffiliateCodeExists, awardAffiliateVendorSubscriptionRewards, baseResourceFields, buildLicenceExpiryPipeline, checkOwnerHasLicence, connectToDatabase, convertObjectIdsToStrings, createLicenceObject, dateTimeSchema, didRemoveAnyEventDates, ensureUserLicenseCompliance, eventLicences, findAffiliateByPromoCode, findEventOrImportedMarketById, getEventResourceInfo, getHighestLicenceForCategory, getLicenceCategory, getLicenceExpiryMode, getPartnerResourceInfo, getPayingEventStripeSubscriptionPlan, getPayingStripeSubscriptionPlan, getPayingVendorStripeSubscriptionPlan, getSubscriptionRewardPeriodBounds, getVendorResourceInfo, handleEventLicenceCompliance, handlePartnerLicenceCompliance, handleVendorLicenceCompliance, hasValidLicence, isStandardLicence, isValidObjectId, licenceCategoryMapping, licencePriority, locationGeoSchema, locationsSchema, mapVendorLicenceToSubscriptionRewardType, normalizeAffiliatePromoCodes, normalizePromoCode, notifyUsers, partnerLicences, processLicenseReminder, processUserCompliance, processUserLicenseReminders, publishNotificationEvents, refundPolicySchema, relatedPostSchema, relationDatesSchema, remindUsersAboutLicenseExpiration, replaceUserLicenceWithObject, resourceRelationsSchema, saveNotificationsInDb, sendDeactivationNotification, sendLicenseReminder, sendPushNotifications, sendReminderSafely, socialShareResourceSchema, syncUserLicencesAfterExpiry, termsAgreementSchema, updateAdStatuses, updateAllEventDateTimeStatuses, updateRelationDatesToUnavailable, updateSingleDateTimeStatus, updateVendorBasedOnUserLicense, upgradeUserToLicence, userLicenseSchema, vendorLicences, vendorOwnerHasProLicence, vendorProductTypeSchema };
package/dist/index.d.ts CHANGED
@@ -1,13 +1,13 @@
1
1
  import * as _timardex_cluemart_shared from '@timardex/cluemart-shared';
2
- import { AdType, CreateBulkNotificationInput, NotificationType, EnumUserRole, ChatMessageType, ParticipantType, ChatType, ReportChatUser, RelatedPostType, OwnerType, SocialMediaType, ResourceImageType, Category, UserLicenceType, ResourceContactDetailsType, TermsAgreement, RelationDate, DateTimeType, LocationGeoType, LocationType, SocialShareResourceType, PosterUsageType, GoogleImportedMarket, PushTokenType, RelationType, ResourceActivityType, UserActivityEvent, UserType, VendorProductList, VendorType, VendorInfoType, UnregisteredVendorInvitationType, UnregisteredVendorType, EventType, StallType, RefundPolicy, EventInfoType, PartnerType, PostType, PostContentType, PostResource, AppSettingsType, GameType, GameDocType, SchoolType, AffiliateRewardType, AffiliateResourceType, AffiliateType, CouponType, CouponDataType, CouponParticipantUserType, PromoCodeType, EnumAffiliateRewardType, EnumUserLicence, EventListItemType, DateTimeWithPriceType } from '@timardex/cluemart-shared';
2
+ import { AdType, CreateBulkNotificationInput, NotificationType, EnumUserRole, ChatMessageType, ParticipantType, ChatType, ReportChatUser, RelatedPostType, OwnerType, SocialMediaType, ResourceImageType, Category, UserLicenceType, ResourceContactDetailsType, TermsAgreement, RelationDate, DateTimeType, LocationGeoType, LocationType, SocialShareResourceType, PosterUsageType, GoogleImportedMarket, PushTokenType, RelationType, ResourceActivityType, UserActivityEvent, UserType, VendorProductList, VendorType, VendorInfoType, UnregisteredVendorInvitationType, UnregisteredVendorType, EventType, StallType, RefundPolicy, EventInfoType, PartnerType, PostType, PostContentType, PostResource, AppSettingsType, GameType, GameDocType, SchoolType, AffiliateRewardType, AffiliateResourceType, AffiliateType, CouponType, CouponDataType, CouponParticipantUserType, PromoCodeType, EnumAffiliateRewardType, EventListItemType, DateTimeWithPriceType, EnumUserLicence as EnumUserLicence$1, EnumNotificationResourceType, EnumNotificationType, EnumResourceType } from '@timardex/cluemart-shared';
3
3
  import * as mongoose from 'mongoose';
4
4
  import mongoose__default from 'mongoose';
5
5
  export { default as mongoose } from 'mongoose';
6
6
  import { NotificationCount, DateTimeType as DateTimeType$1 } from '@timardex/cluemart-shared/types';
7
7
  import express from 'express';
8
8
  export { default as express } from 'express';
9
- import dayjs from 'dayjs';
10
- import { EnumUserLicence as EnumUserLicence$1 } from '@timardex/cluemart-shared/enums';
9
+ import dayjs, { Dayjs } from 'dayjs';
10
+ import { EnumUserLicence } from '@timardex/cluemart-shared/enums';
11
11
 
12
12
  declare const AdModel: mongoose__default.Model<AdType, {}, {}, {}, mongoose__default.Document<unknown, {}, AdType, {}, {}> & AdType & Required<{
13
13
  _id: string;
@@ -923,8 +923,6 @@ declare function sendPushNotifications({ data, message, title, userIds, }: Schem
923
923
  */
924
924
  declare function updateAdStatuses(): Promise<void>;
925
925
 
926
- declare function updateVendorBasedOnUserLicense(userId: ObjectId, licenceType: EnumUserLicence): Promise<void>;
927
-
928
926
  /**
929
927
  * True when `value` is a valid Mongo ObjectId string.
930
928
  */
@@ -971,8 +969,8 @@ declare function updateRelationDatesToUnavailable(relationDates: SchemaRelationT
971
969
 
972
970
  type PayingStripeSubscriptionPlanResult = {
973
971
  hasSubscription: boolean;
974
- plan: EnumUserLicence$1 | null;
975
- validTypes: Set<EnumUserLicence$1>;
972
+ plan: EnumUserLicence | null;
973
+ validTypes: Set<EnumUserLicence>;
976
974
  };
977
975
  /**
978
976
  * Returns the paying Stripe plan when `currentPlan` is any PRO plan
@@ -990,4 +988,253 @@ declare function getPayingVendorStripeSubscriptionPlan(userId: ObjectId | string
990
988
  */
991
989
  declare function getPayingEventStripeSubscriptionPlan(userId: ObjectId | string, now?: Date): Promise<PayingStripeSubscriptionPlanResult>;
992
990
 
993
- export { ACTIVE_NOT_DELETED_FILTER, APP_SETTINGS_ID, AdModel, AffiliateModel, AppSettingModel, type AuthUser, type AwardAffiliateVendorSubscriptionRewardsResult, CategorySchema, ChatModel, ChatReportModel, ContactDetailsSchema, type CouponDocument, CouponModel, EnumPubSubEvents, EventInfoModel, EventModel, GameModel, GoogleImportedMarketModel, type GraphQLContext, NotificationModel, type NotificationPubSub, type ObjectId, OwnerTypeSchema, PartnerModel, PostModel, PushTokenModel, RelationModel, RelationTypeSchema, ResourceActivityModel, ResourceImageTypeSchema, SUBSCRIPTION_REWARD_TIMEZONE, type SchemaAffiliateResourceType, type SchemaAffiliateReward, type SchemaChatMessageReactionType, type SchemaChatMessageReplyPreviewType, type SchemaChatMessageSeenType, type SchemaChatMessageType, type SchemaChatReportType, type SchemaChatType, type SchemaCreateBulkNotificationInput, type SchemaEventInfoType, type SchemaEventType, type SchemaGameType, type SchemaGoogleImportedMarket, type SchemaNotificationType, type SchemaOwnerType, type SchemaParticipantType, type SchemaPartnerType, type SchemaPostType, type SchemaPushTokenType, type SchemaRelatedPostType, type SchemaRelationType, type SchemaUnregisteredVendorInvitationType, type SchemaUnregisteredVendorType, type SchemaUserActivityEvent, type SchemaUserType, type SchemaVendorInfoType, type SchemaVendorType, SchoolModel, SocialMediaTypeSchema, StallTypeSchema, type SubscriptionPayload, UnregisteredVendorModel, UserModel, VendorInfoModel, VendorModel, VerificationTokenModel, type VerificationTokenType, activeAffiliateCodeExists, awardAffiliateVendorSubscriptionRewards, baseResourceFields, connectToDatabase, convertObjectIdsToStrings, dateTimeSchema, didRemoveAnyEventDates, findAffiliateByPromoCode, findEventOrImportedMarketById, getPayingEventStripeSubscriptionPlan, getPayingStripeSubscriptionPlan, getPayingVendorStripeSubscriptionPlan, getSubscriptionRewardPeriodBounds, isValidObjectId, locationGeoSchema, locationsSchema, mapVendorLicenceToSubscriptionRewardType, normalizeAffiliatePromoCodes, normalizePromoCode, notifyUsers, publishNotificationEvents, refundPolicySchema, relatedPostSchema, relationDatesSchema, resourceRelationsSchema, saveNotificationsInDb, sendPushNotifications, socialShareResourceSchema, termsAgreementSchema, updateAdStatuses, updateAllEventDateTimeStatuses, updateRelationDatesToUnavailable, updateSingleDateTimeStatus, updateVendorBasedOnUserLicense, userLicenseSchema, vendorProductTypeSchema };
991
+ declare function ensureUserLicenseCompliance(): Promise<void>;
992
+
993
+ declare const eventLicences: EnumUserLicence$1[];
994
+ /**
995
+ * Handles event licence compliance for a single user.
996
+ *
997
+ * Event licences are kept and extended on expiry — no deactivation.
998
+ */
999
+ declare function handleEventLicenceCompliance(user: SchemaUserType, now: Dayjs): Promise<void>;
1000
+
1001
+ /**
1002
+ * Builds an aggregation pipeline that atomically applies expiry rules to the
1003
+ * `licences` array. Used by syncUserLicencesAfterExpiry for a single
1004
+ * updateOne with no read-modify-write.
1005
+ *
1006
+ * downgradeBranches: PRO_* / PRO_PLUS_* licence types mapped to their STANDARD_*
1007
+ * counterpart (e.g. pro_plus_event → standard_event). Use EnumUserLicence in the
1008
+ * caller to avoid string drift.
1009
+ *
1010
+ * Note: Uses MongoDB aggregation keys "then"/"case" (required by $cond/$switch).
1011
+ *
1012
+ * Requires MongoDB 4.2+: this emits an updateOne aggregation pipeline (the
1013
+ * [ { $set: ... } ] form) and uses $reduce / $indexOfArray / $regexMatch in the
1014
+ * dedupe + standard-detection stages. The project runs MongoDB 8.0
1015
+ * (docker-compose.yml), well above the minimum.
1016
+ */
1017
+ declare function buildLicenceExpiryPipeline(params: {
1018
+ /** Pairs of (licenceType, standardCounterpart) for downgrade; e.g. PRO_PLUS_VENDOR → STANDARD_VENDOR */
1019
+ downgradeBranches: ReadonlyArray<{
1020
+ case: string;
1021
+ then: string;
1022
+ }>;
1023
+ licenceTypes: string[];
1024
+ /**
1025
+ * How expired, targeted licences are handled:
1026
+ * - "downgrade": extend expired STANDARD_* and downgrade expired PRO_* or PRO_PLUS_* (vendor)
1027
+ * - "extend": keep the licence as-is and extend expiryDate to oneYearFromNow (partner/event)
1028
+ */
1029
+ mode?: "downgrade" | "extend";
1030
+ nowDate: Date;
1031
+ oneYearFromNow: Date;
1032
+ }): object[];
1033
+
1034
+ declare const partnerLicences: EnumUserLicence$1[];
1035
+ /**
1036
+ * Handles partner licence compliance for a single user.
1037
+ *
1038
+ * Partner licences are kept and extended on expiry — no deactivation.
1039
+ */
1040
+ declare function handlePartnerLicenceCompliance(user: SchemaUserType, now: Dayjs): Promise<void>;
1041
+
1042
+ /**
1043
+ * Syncs the user's `licences` array
1044
+ * Uses a single atomic updateOne with an aggregation pipeline so it is safe under
1045
+ * concurrency (no read-modify-write, no lost updates).
1046
+ *
1047
+ * Rules (applied server-side only to licences whose licenceType is in licenceTypes):
1048
+ * - mode "downgrade" (vendor): expired STANDARD_* → extended to one year from now;
1049
+ * expired PRO_* or PRO_PLUS_* → downgraded to STANDARD_* with issuedDate=now and
1050
+ * expiryDate=one year from now
1051
+ * - mode "extend" (partner/event): expired licences are kept and their expiryDate
1052
+ * is extended to one year from now
1053
+ * - Non-expired or non-targeted licences are unchanged in both modes
1054
+ */
1055
+ declare function syncUserLicencesAfterExpiry(userId: ObjectId, licenceTypes: EnumUserLicence$1[], now: dayjs.Dayjs, mode?: "downgrade" | "extend"): Promise<void>;
1056
+ /**
1057
+ * Checks if user has a valid licence of the given types
1058
+ */
1059
+ declare function hasValidLicence(licences: UserLicenceType[], licenceTypes: EnumUserLicence$1[], now: dayjs.Dayjs): boolean;
1060
+ /**
1061
+ * Sends a deactivation notification to the user
1062
+ */
1063
+ declare function sendDeactivationNotification(payload: {
1064
+ data: {
1065
+ resourceId: string;
1066
+ resourceName: string;
1067
+ resourceType: EnumNotificationResourceType;
1068
+ };
1069
+ message: string;
1070
+ title: string;
1071
+ type: EnumNotificationType;
1072
+ userIds: ObjectId[];
1073
+ }, userId: ObjectId, resourceName: string, resourceType: string): Promise<void>;
1074
+ /**
1075
+ * Processes license compliance for a single user
1076
+ */
1077
+ declare function processUserCompliance(user: SchemaUserType, now: dayjs.Dayjs): Promise<void>;
1078
+
1079
+ declare function updateVendorBasedOnUserLicense(userId: ObjectId, licenceType: EnumUserLicence$1): Promise<void>;
1080
+ declare const vendorLicences: EnumUserLicence$1[];
1081
+ /**
1082
+ * Handles vendor licence compliance for a single user
1083
+ */
1084
+ declare function handleVendorLicenceCompliance(user: SchemaUserType, now: Dayjs): Promise<void>;
1085
+ /**
1086
+ * Checks whether a vendor's owner currently holds a PRO (or higher) vendor licence.
1087
+ */
1088
+ declare function vendorOwnerHasProLicence(vendorId: string): Promise<boolean>;
1089
+
1090
+ /**
1091
+ * Gets event resource information for a reminder
1092
+ */
1093
+ declare function getEventResourceInfo(userId: ObjectId, eventIds: ObjectId[]): Promise<{
1094
+ resourceId: string;
1095
+ resourceName: string;
1096
+ } | null>;
1097
+
1098
+ /**
1099
+ * Gets partner resource information for a reminder
1100
+ */
1101
+ declare function getPartnerResourceInfo(userId: ObjectId, partnerId: ObjectId): Promise<{
1102
+ resourceId: string;
1103
+ resourceName: string;
1104
+ } | null>;
1105
+
1106
+ /**
1107
+ * Sends license expiration reminders to users whose licenses expire in 7 days
1108
+ */
1109
+ declare function remindUsersAboutLicenseExpiration(): Promise<void>;
1110
+
1111
+ /**
1112
+ * License expiration reminder window bounds.
1113
+ *
1114
+ * A licence qualifies for the "7 days before expiry" reminder when its expiry is
1115
+ * between {@link REMINDER_WINDOW_MIN_HOURS} and {@link REMINDER_WINDOW_MAX_HOURS}
1116
+ * away.
1117
+ *
1118
+ * Expressed in hours (derived from days) because dayjs rounds fractional "day"
1119
+ * adds: `now.add(6.5, "day")` becomes 7 days and `now.add(7.5, "day")` 8 days.
1120
+ */
1121
+ declare const REMINDER_WINDOW_MIN_HOURS: number;
1122
+ declare const REMINDER_WINDOW_MAX_HOURS: number;
1123
+
1124
+ /**
1125
+ * Single source of truth for how a licence type is handled on expiry.
1126
+ *
1127
+ * - "downgrade": PRO_VENDOR / PRO_PLUS_VENDOR → downgraded to STANDARD_VENDOR.
1128
+ * - "extend": every other licence type is auto-extended for another year.
1129
+ *
1130
+ * Note: `cluemart-server`'s `licenceCategoryMapping` / `licencePriority`
1131
+ * (ModelHelpers/licenses/index.ts) is a SEPARATE concern (entitlement priority,
1132
+ * not expiry behaviour) and is intentionally not merged here.
1133
+ */
1134
+ declare function getLicenceExpiryMode(licenceType: EnumUserLicence$1): "downgrade" | "extend";
1135
+ /**
1136
+ * Sends a reminder notification for a license.
1137
+ *
1138
+ * Intentionally does NOT use the shared `notifyUsers` helper: that helper
1139
+ * persists via `saveNotificationsInDb` (plain `insertMany`), whereas this job
1140
+ * must claim the dedupe slot atomically through
1141
+ * {@link checkAndCreateNotification} (upsert) so a reminder is only sent once.
1142
+ * Push is therefore sent directly via `sendPushNotifications` only after the
1143
+ * claim succeeds.
1144
+ */
1145
+ declare function sendLicenseReminder(user: {
1146
+ _id: ObjectId;
1147
+ vendor?: ObjectId;
1148
+ events?: ObjectId[];
1149
+ partner?: ObjectId;
1150
+ }, licence: {
1151
+ licenceType: EnumUserLicence$1;
1152
+ expiryDate: Date | string;
1153
+ }): Promise<void>;
1154
+ /**
1155
+ * Processes a single license and sends reminder if needed
1156
+ *
1157
+ * Checks if a license expires within the 6.5-7.5 day window and hasn't already
1158
+ * received a reminder. See isLicenseExpiringIn7Days for details on the reminder window.
1159
+ *
1160
+ * @returns true if a reminder should be sent, false otherwise
1161
+ */
1162
+ declare function processLicenseReminder(user: {
1163
+ _id: ObjectId;
1164
+ vendor?: ObjectId;
1165
+ events?: ObjectId[];
1166
+ partner?: ObjectId;
1167
+ }, licence: {
1168
+ licenceType: EnumUserLicence$1;
1169
+ expiryDate: Date | string;
1170
+ }, now: dayjs.Dayjs): Promise<boolean>;
1171
+ /**
1172
+ * Sends a reminder for a single license, handling errors gracefully
1173
+ */
1174
+ declare function sendReminderSafely(user: {
1175
+ _id: ObjectId;
1176
+ vendor?: ObjectId;
1177
+ events?: ObjectId[];
1178
+ partner?: ObjectId;
1179
+ }, licence: UserLicenceType): Promise<boolean>;
1180
+ /**
1181
+ * Processes reminders for a single user's licenses
1182
+ */
1183
+ declare function processUserLicenseReminders(user: SchemaUserType, now: dayjs.Dayjs): Promise<number>;
1184
+
1185
+ /**
1186
+ * Gets vendor resource information for a reminder
1187
+ */
1188
+ declare function getVendorResourceInfo(userId: ObjectId, vendorId: ObjectId): Promise<{
1189
+ resourceId: string;
1190
+ resourceName: string;
1191
+ } | null>;
1192
+
1193
+ declare enum LicenceExpiryDate {
1194
+ ONE_YEAR = "1 year",
1195
+ ONE_MONTH = "1 month",
1196
+ TWO_MONTHS = "2 months"
1197
+ }
1198
+ declare enum LicenceCategory {
1199
+ EVENT = "event",
1200
+ PARTNER = "partner",
1201
+ VENDOR = "vendor",
1202
+ AFFILIATE = "affiliate",
1203
+ SCHOOL = "school"
1204
+ }
1205
+ declare const licenceCategoryMapping: Record<EnumUserLicence$1, LicenceCategory>;
1206
+ declare const licencePriority: Record<EnumUserLicence$1, number>;
1207
+ declare const standardLicences: readonly [EnumUserLicence$1.STANDARD_VENDOR, EnumUserLicence$1.STANDARD_EVENT, EnumUserLicence$1.STANDARD_PARTNER];
1208
+ declare function isStandardLicence(licence: EnumUserLicence$1): licence is (typeof standardLicences)[number];
1209
+ type LicenceUpgradeArgs = {
1210
+ expiryDate: LicenceExpiryDate;
1211
+ licenceType: EnumUserLicence$1;
1212
+ userId: ObjectId;
1213
+ };
1214
+ type LicenceUpgradeResult = {
1215
+ licenceObject: UserLicenceType;
1216
+ updatedUser: SchemaUserType | null;
1217
+ };
1218
+ declare function getLicenceCategory(licence: EnumUserLicence$1): LicenceCategory;
1219
+ declare function getHighestLicenceForCategory(licences: UserLicenceType[] | null | undefined, category: LicenceCategory): EnumUserLicence$1 | null;
1220
+ declare function createLicenceObject(expiryDate: LicenceExpiryDate, licenceType: EnumUserLicence$1): UserLicenceType;
1221
+ declare function replaceUserLicenceWithObject({ userId, licenceObject, protectHigherLicence, }: {
1222
+ userId: ObjectId;
1223
+ licenceObject: UserLicenceType;
1224
+ protectHigherLicence?: boolean;
1225
+ }): Promise<void>;
1226
+ /**
1227
+ * Upgrades a user's license by adding a new license object to their account.
1228
+ * It calculates the expiry date based on the provided expiry duration and updates the user's licenses in the database.
1229
+ * @param licenceType - The licence type to upgrade the user to.
1230
+ * @param expiryDate - The expiry duration for the license being upgraded.
1231
+ * @param userId - The ID of the user whose license is being upgraded.
1232
+ * @returns An object containing the updated user and the new license object.
1233
+ */
1234
+ declare const upgradeUserToLicence: ({ licenceType, expiryDate, userId, }: LicenceUpgradeArgs) => Promise<LicenceUpgradeResult>;
1235
+ declare function checkOwnerHasLicence({ userId, resourceType, }: {
1236
+ userId: ObjectId;
1237
+ resourceType: EnumResourceType;
1238
+ }): Promise<void>;
1239
+
1240
+ export { ACTIVE_NOT_DELETED_FILTER, APP_SETTINGS_ID, AdModel, AffiliateModel, AppSettingModel, type AuthUser, type AwardAffiliateVendorSubscriptionRewardsResult, CategorySchema, ChatModel, ChatReportModel, ContactDetailsSchema, type CouponDocument, CouponModel, EnumPubSubEvents, EventInfoModel, EventModel, GameModel, GoogleImportedMarketModel, type GraphQLContext, LicenceCategory, LicenceExpiryDate, NotificationModel, type NotificationPubSub, type ObjectId, OwnerTypeSchema, PartnerModel, PostModel, PushTokenModel, REMINDER_WINDOW_MAX_HOURS, REMINDER_WINDOW_MIN_HOURS, RelationModel, RelationTypeSchema, ResourceActivityModel, ResourceImageTypeSchema, SUBSCRIPTION_REWARD_TIMEZONE, type SchemaAffiliateResourceType, type SchemaAffiliateReward, type SchemaChatMessageReactionType, type SchemaChatMessageReplyPreviewType, type SchemaChatMessageSeenType, type SchemaChatMessageType, type SchemaChatReportType, type SchemaChatType, type SchemaCreateBulkNotificationInput, type SchemaEventInfoType, type SchemaEventType, type SchemaGameType, type SchemaGoogleImportedMarket, type SchemaNotificationType, type SchemaOwnerType, type SchemaParticipantType, type SchemaPartnerType, type SchemaPostType, type SchemaPushTokenType, type SchemaRelatedPostType, type SchemaRelationType, type SchemaUnregisteredVendorInvitationType, type SchemaUnregisteredVendorType, type SchemaUserActivityEvent, type SchemaUserType, type SchemaVendorInfoType, type SchemaVendorType, SchoolModel, SocialMediaTypeSchema, StallTypeSchema, type SubscriptionPayload, UnregisteredVendorModel, UserModel, VendorInfoModel, VendorModel, VerificationTokenModel, type VerificationTokenType, activeAffiliateCodeExists, awardAffiliateVendorSubscriptionRewards, baseResourceFields, buildLicenceExpiryPipeline, checkOwnerHasLicence, connectToDatabase, convertObjectIdsToStrings, createLicenceObject, dateTimeSchema, didRemoveAnyEventDates, ensureUserLicenseCompliance, eventLicences, findAffiliateByPromoCode, findEventOrImportedMarketById, getEventResourceInfo, getHighestLicenceForCategory, getLicenceCategory, getLicenceExpiryMode, getPartnerResourceInfo, getPayingEventStripeSubscriptionPlan, getPayingStripeSubscriptionPlan, getPayingVendorStripeSubscriptionPlan, getSubscriptionRewardPeriodBounds, getVendorResourceInfo, handleEventLicenceCompliance, handlePartnerLicenceCompliance, handleVendorLicenceCompliance, hasValidLicence, isStandardLicence, isValidObjectId, licenceCategoryMapping, licencePriority, locationGeoSchema, locationsSchema, mapVendorLicenceToSubscriptionRewardType, normalizeAffiliatePromoCodes, normalizePromoCode, notifyUsers, partnerLicences, processLicenseReminder, processUserCompliance, processUserLicenseReminders, publishNotificationEvents, refundPolicySchema, relatedPostSchema, relationDatesSchema, remindUsersAboutLicenseExpiration, replaceUserLicenceWithObject, resourceRelationsSchema, saveNotificationsInDb, sendDeactivationNotification, sendLicenseReminder, sendPushNotifications, sendReminderSafely, socialShareResourceSchema, syncUserLicencesAfterExpiry, termsAgreementSchema, updateAdStatuses, updateAllEventDateTimeStatuses, updateRelationDatesToUnavailable, updateSingleDateTimeStatus, updateVendorBasedOnUserLicense, upgradeUserToLicence, userLicenseSchema, vendorLicences, vendorOwnerHasProLicence, vendorProductTypeSchema };