@timardex/cluemart-server-shared 1.1.38 → 2.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,8 +1,8 @@
1
1
  import * as mongoose from 'mongoose';
2
2
  import * as _timardex_cluemart_shared from '@timardex/cluemart-shared';
3
3
  import { PromoCodeType, EnumAffiliateRewardType, DateTimeType, EventListItemType, DateTimeWithPriceType, EnumUserLicence as EnumUserLicence$1, UserLicenceType, EnumNotificationResourceType, EnumNotificationType, EnumResourceType } from '@timardex/cluemart-shared';
4
- import { p as SchemaAffiliateResourceType, S as SchemaOwnerType, i as SchemaRelationType, n as SchemaUserType } from '../Affiliate-xCVhO2Cy.mjs';
5
- import { O as ObjectId, G as GraphQLContext, f as SchemaCreateBulkNotificationInput } from '../Chat-Wn7yfc3v.mjs';
4
+ import { d as SchemaAffiliateResourceType, S as SchemaOwnerType, g as SchemaRelationType, j as SchemaUserType } from '../Affiliate-CMJdECzs.mjs';
5
+ import { O as ObjectId, G as GraphQLContext, e as SchemaCreateBulkNotificationInput } from '../index-Bq-lT7a2.mjs';
6
6
  import dayjs, { Dayjs } from 'dayjs';
7
7
  import { DateTimeType as DateTimeType$1 } from '@timardex/cluemart-shared/types';
8
8
  import { EnumUserLicence } from '@timardex/cluemart-shared/enums';
@@ -213,6 +213,12 @@ declare function getPayingVendorStripeSubscriptionPlan(userId: ObjectId | string
213
213
  */
214
214
  declare function getPayingEventStripeSubscriptionPlan(userId: ObjectId | string, now?: Date): Promise<PayingStripeSubscriptionPlanResult>;
215
215
 
216
+ /**
217
+ * Runs the established compliance pipeline for one freshly loaded user.
218
+ * Stripe webhooks use this at the actual paid-through boundary; the global
219
+ * scheduled scan remains the fallback for missed or delayed webhook handling.
220
+ */
221
+ declare function ensureUserLicenseComplianceForUser(userId: ObjectId, now?: Dayjs): Promise<void>;
216
222
  declare function ensureUserLicenseCompliance(): Promise<void>;
217
223
 
218
224
  declare const eventLicences: EnumUserLicence$1[];
@@ -384,12 +390,7 @@ declare function sendLicenseReminder(user: {
384
390
  *
385
391
  * @returns true if a reminder should be sent, false otherwise
386
392
  */
387
- declare function processLicenseReminder(user: {
388
- _id: ObjectId;
389
- vendor?: ObjectId;
390
- events?: ObjectId[];
391
- partner?: ObjectId;
392
- }, licence: {
393
+ declare function processLicenseReminder(licence: {
393
394
  licenceType: EnumUserLicence$1;
394
395
  expiryDate: Date | string;
395
396
  }, now: dayjs.Dayjs): Promise<boolean>;
@@ -443,10 +444,11 @@ type LicenceUpgradeResult = {
443
444
  declare function getLicenceCategory(licence: EnumUserLicence$1): LicenceCategory;
444
445
  declare function getHighestLicenceForCategory(licences: UserLicenceType[] | null | undefined, category: LicenceCategory): EnumUserLicence$1 | null;
445
446
  declare function createLicenceObject(expiryDate: LicenceExpiryDate, licenceType: EnumUserLicence$1): UserLicenceType;
446
- declare function replaceUserLicenceWithObject({ userId, licenceObject, protectHigherLicence, }: {
447
+ declare function replaceUserLicenceWithObject({ userId, licenceObject, protectHigherLicence, refreshExistingLicence, }: {
447
448
  userId: ObjectId;
448
449
  licenceObject: UserLicenceType;
449
450
  protectHigherLicence?: boolean;
451
+ refreshExistingLicence?: boolean;
450
452
  }): Promise<void>;
451
453
  /**
452
454
  * Upgrades a user's license by adding a new license object to their account.
@@ -462,4 +464,4 @@ declare function checkOwnerHasLicence({ userId, resourceType, }: {
462
464
  resourceType: EnumResourceType;
463
465
  }): Promise<void>;
464
466
 
465
- export { ACTIVE_NOT_DELETED_FILTER, type AwardAffiliateVendorSubscriptionRewardsResult, LicenceCategory, LicenceExpiryDate, type NotificationPubSub, REMINDER_WINDOW_MAX_HOURS, REMINDER_WINDOW_MIN_HOURS, SUBSCRIPTION_REWARD_TIMEZONE, activeAffiliateCodeExists, awardAffiliateVendorSubscriptionRewards, buildLicenceExpiryPipeline, checkOwnerHasLicence, connectToDatabase, convertObjectIdsToStrings, createLicenceObject, didRemoveAnyEventDates, ensureUserLicenseCompliance, eventLicences, findAffiliateByPromoCode, findEventOrImportedMarketById, getEventResourceInfo, getHighestLicenceForCategory, getLicenceCategory, getLicenceExpiryMode, getPartnerResourceInfo, getPayingEventStripeSubscriptionPlan, getPayingStripeSubscriptionPlan, getPayingVendorStripeSubscriptionPlan, getSubscriptionRewardPeriodBounds, getVendorResourceInfo, handleEventLicenceCompliance, handlePartnerLicenceCompliance, handleVendorLicenceCompliance, hasValidLicence, isStandardLicence, isValidObjectId, licenceCategoryMapping, licencePriority, mapVendorLicenceToSubscriptionRewardType, normalizeAffiliatePromoCodes, normalizePromoCode, notifyUsers, partnerLicences, processLicenseReminder, processUserCompliance, processUserLicenseReminders, publishNotificationEvents, remindUsersAboutLicenseExpiration, replaceUserLicenceWithObject, saveNotificationsInDb, sendDeactivationNotification, sendLicenseReminder, sendPushNotifications, sendReminderSafely, syncUserLicencesAfterExpiry, updateAdStatuses, updateAllEventDateTimeStatuses, updateRelationDatesToUnavailable, updateSingleDateTimeStatus, updateVendorBasedOnUserLicense, upgradeUserToLicence, vendorLicences, vendorOwnerHasProLicence };
467
+ export { ACTIVE_NOT_DELETED_FILTER, type AwardAffiliateVendorSubscriptionRewardsResult, LicenceCategory, LicenceExpiryDate, type NotificationPubSub, REMINDER_WINDOW_MAX_HOURS, REMINDER_WINDOW_MIN_HOURS, SUBSCRIPTION_REWARD_TIMEZONE, activeAffiliateCodeExists, awardAffiliateVendorSubscriptionRewards, buildLicenceExpiryPipeline, checkOwnerHasLicence, connectToDatabase, convertObjectIdsToStrings, createLicenceObject, didRemoveAnyEventDates, ensureUserLicenseCompliance, ensureUserLicenseComplianceForUser, eventLicences, findAffiliateByPromoCode, findEventOrImportedMarketById, getEventResourceInfo, getHighestLicenceForCategory, getLicenceCategory, getLicenceExpiryMode, getPartnerResourceInfo, getPayingEventStripeSubscriptionPlan, getPayingStripeSubscriptionPlan, getPayingVendorStripeSubscriptionPlan, getSubscriptionRewardPeriodBounds, getVendorResourceInfo, handleEventLicenceCompliance, handlePartnerLicenceCompliance, handleVendorLicenceCompliance, hasValidLicence, isStandardLicence, isValidObjectId, licenceCategoryMapping, licencePriority, mapVendorLicenceToSubscriptionRewardType, normalizeAffiliatePromoCodes, normalizePromoCode, notifyUsers, partnerLicences, processLicenseReminder, processUserCompliance, processUserLicenseReminders, publishNotificationEvents, remindUsersAboutLicenseExpiration, replaceUserLicenceWithObject, saveNotificationsInDb, sendDeactivationNotification, sendLicenseReminder, sendPushNotifications, sendReminderSafely, syncUserLicencesAfterExpiry, updateAdStatuses, updateAllEventDateTimeStatuses, updateRelationDatesToUnavailable, updateSingleDateTimeStatus, updateVendorBasedOnUserLicense, upgradeUserToLicence, vendorLicences, vendorOwnerHasProLicence };
@@ -1,8 +1,8 @@
1
1
  import * as mongoose from 'mongoose';
2
2
  import * as _timardex_cluemart_shared from '@timardex/cluemart-shared';
3
3
  import { PromoCodeType, EnumAffiliateRewardType, DateTimeType, EventListItemType, DateTimeWithPriceType, EnumUserLicence as EnumUserLicence$1, UserLicenceType, EnumNotificationResourceType, EnumNotificationType, EnumResourceType } from '@timardex/cluemart-shared';
4
- import { p as SchemaAffiliateResourceType, S as SchemaOwnerType, i as SchemaRelationType, n as SchemaUserType } from '../Affiliate-CZKOOaz_.js';
5
- import { O as ObjectId, G as GraphQLContext, f as SchemaCreateBulkNotificationInput } from '../Chat-Wn7yfc3v.js';
4
+ import { d as SchemaAffiliateResourceType, S as SchemaOwnerType, g as SchemaRelationType, j as SchemaUserType } from '../Affiliate-VLZdlt5K.js';
5
+ import { O as ObjectId, G as GraphQLContext, e as SchemaCreateBulkNotificationInput } from '../index-Bq-lT7a2.js';
6
6
  import dayjs, { Dayjs } from 'dayjs';
7
7
  import { DateTimeType as DateTimeType$1 } from '@timardex/cluemart-shared/types';
8
8
  import { EnumUserLicence } from '@timardex/cluemart-shared/enums';
@@ -213,6 +213,12 @@ declare function getPayingVendorStripeSubscriptionPlan(userId: ObjectId | string
213
213
  */
214
214
  declare function getPayingEventStripeSubscriptionPlan(userId: ObjectId | string, now?: Date): Promise<PayingStripeSubscriptionPlanResult>;
215
215
 
216
+ /**
217
+ * Runs the established compliance pipeline for one freshly loaded user.
218
+ * Stripe webhooks use this at the actual paid-through boundary; the global
219
+ * scheduled scan remains the fallback for missed or delayed webhook handling.
220
+ */
221
+ declare function ensureUserLicenseComplianceForUser(userId: ObjectId, now?: Dayjs): Promise<void>;
216
222
  declare function ensureUserLicenseCompliance(): Promise<void>;
217
223
 
218
224
  declare const eventLicences: EnumUserLicence$1[];
@@ -384,12 +390,7 @@ declare function sendLicenseReminder(user: {
384
390
  *
385
391
  * @returns true if a reminder should be sent, false otherwise
386
392
  */
387
- declare function processLicenseReminder(user: {
388
- _id: ObjectId;
389
- vendor?: ObjectId;
390
- events?: ObjectId[];
391
- partner?: ObjectId;
392
- }, licence: {
393
+ declare function processLicenseReminder(licence: {
393
394
  licenceType: EnumUserLicence$1;
394
395
  expiryDate: Date | string;
395
396
  }, now: dayjs.Dayjs): Promise<boolean>;
@@ -443,10 +444,11 @@ type LicenceUpgradeResult = {
443
444
  declare function getLicenceCategory(licence: EnumUserLicence$1): LicenceCategory;
444
445
  declare function getHighestLicenceForCategory(licences: UserLicenceType[] | null | undefined, category: LicenceCategory): EnumUserLicence$1 | null;
445
446
  declare function createLicenceObject(expiryDate: LicenceExpiryDate, licenceType: EnumUserLicence$1): UserLicenceType;
446
- declare function replaceUserLicenceWithObject({ userId, licenceObject, protectHigherLicence, }: {
447
+ declare function replaceUserLicenceWithObject({ userId, licenceObject, protectHigherLicence, refreshExistingLicence, }: {
447
448
  userId: ObjectId;
448
449
  licenceObject: UserLicenceType;
449
450
  protectHigherLicence?: boolean;
451
+ refreshExistingLicence?: boolean;
450
452
  }): Promise<void>;
451
453
  /**
452
454
  * Upgrades a user's license by adding a new license object to their account.
@@ -462,4 +464,4 @@ declare function checkOwnerHasLicence({ userId, resourceType, }: {
462
464
  resourceType: EnumResourceType;
463
465
  }): Promise<void>;
464
466
 
465
- export { ACTIVE_NOT_DELETED_FILTER, type AwardAffiliateVendorSubscriptionRewardsResult, LicenceCategory, LicenceExpiryDate, type NotificationPubSub, REMINDER_WINDOW_MAX_HOURS, REMINDER_WINDOW_MIN_HOURS, SUBSCRIPTION_REWARD_TIMEZONE, activeAffiliateCodeExists, awardAffiliateVendorSubscriptionRewards, buildLicenceExpiryPipeline, checkOwnerHasLicence, connectToDatabase, convertObjectIdsToStrings, createLicenceObject, didRemoveAnyEventDates, ensureUserLicenseCompliance, eventLicences, findAffiliateByPromoCode, findEventOrImportedMarketById, getEventResourceInfo, getHighestLicenceForCategory, getLicenceCategory, getLicenceExpiryMode, getPartnerResourceInfo, getPayingEventStripeSubscriptionPlan, getPayingStripeSubscriptionPlan, getPayingVendorStripeSubscriptionPlan, getSubscriptionRewardPeriodBounds, getVendorResourceInfo, handleEventLicenceCompliance, handlePartnerLicenceCompliance, handleVendorLicenceCompliance, hasValidLicence, isStandardLicence, isValidObjectId, licenceCategoryMapping, licencePriority, mapVendorLicenceToSubscriptionRewardType, normalizeAffiliatePromoCodes, normalizePromoCode, notifyUsers, partnerLicences, processLicenseReminder, processUserCompliance, processUserLicenseReminders, publishNotificationEvents, remindUsersAboutLicenseExpiration, replaceUserLicenceWithObject, saveNotificationsInDb, sendDeactivationNotification, sendLicenseReminder, sendPushNotifications, sendReminderSafely, syncUserLicencesAfterExpiry, updateAdStatuses, updateAllEventDateTimeStatuses, updateRelationDatesToUnavailable, updateSingleDateTimeStatus, updateVendorBasedOnUserLicense, upgradeUserToLicence, vendorLicences, vendorOwnerHasProLicence };
467
+ export { ACTIVE_NOT_DELETED_FILTER, type AwardAffiliateVendorSubscriptionRewardsResult, LicenceCategory, LicenceExpiryDate, type NotificationPubSub, REMINDER_WINDOW_MAX_HOURS, REMINDER_WINDOW_MIN_HOURS, SUBSCRIPTION_REWARD_TIMEZONE, activeAffiliateCodeExists, awardAffiliateVendorSubscriptionRewards, buildLicenceExpiryPipeline, checkOwnerHasLicence, connectToDatabase, convertObjectIdsToStrings, createLicenceObject, didRemoveAnyEventDates, ensureUserLicenseCompliance, ensureUserLicenseComplianceForUser, eventLicences, findAffiliateByPromoCode, findEventOrImportedMarketById, getEventResourceInfo, getHighestLicenceForCategory, getLicenceCategory, getLicenceExpiryMode, getPartnerResourceInfo, getPayingEventStripeSubscriptionPlan, getPayingStripeSubscriptionPlan, getPayingVendorStripeSubscriptionPlan, getSubscriptionRewardPeriodBounds, getVendorResourceInfo, handleEventLicenceCompliance, handlePartnerLicenceCompliance, handleVendorLicenceCompliance, hasValidLicence, isStandardLicence, isValidObjectId, licenceCategoryMapping, licencePriority, mapVendorLicenceToSubscriptionRewardType, normalizeAffiliatePromoCodes, normalizePromoCode, notifyUsers, partnerLicences, processLicenseReminder, processUserCompliance, processUserLicenseReminders, publishNotificationEvents, remindUsersAboutLicenseExpiration, replaceUserLicenceWithObject, saveNotificationsInDb, sendDeactivationNotification, sendLicenseReminder, sendPushNotifications, sendReminderSafely, syncUserLicencesAfterExpiry, updateAdStatuses, updateAllEventDateTimeStatuses, updateRelationDatesToUnavailable, updateSingleDateTimeStatus, updateVendorBasedOnUserLicense, upgradeUserToLicence, vendorLicences, vendorOwnerHasProLicence };
@@ -13,6 +13,7 @@ import {
13
13
  EnumRegions,
14
14
  EnumResourceType,
15
15
  EnumSubscriptionStatus,
16
+ EnumSubscriptionStatus2,
16
17
  EnumUserLicence,
17
18
  EnumUserLicence2,
18
19
  EventModel,
@@ -26,8 +27,9 @@ import {
26
27
  isNonVisitorResourceType,
27
28
  licenseNiceNames,
28
29
  timeFormat
29
- } from "../chunk-DJHOLZ3J.mjs";
30
+ } from "../chunk-EGUFWI7R.mjs";
30
31
  import "../chunk-6PNG5BI5.mjs";
32
+ import "../chunk-3QS3WKRC.mjs";
31
33
 
32
34
  // src/service/promoCode/constants.ts
33
35
  var ACTIVE_NOT_DELETED_FILTER = {
@@ -44,7 +46,7 @@ async function activeAffiliateCodeExists(affiliateCode) {
44
46
  return existing !== null;
45
47
  }
46
48
 
47
- // node_modules/@timardex/cluemart-shared/dist/chunk-2UNNIQIK.mjs
49
+ // node_modules/@timardex/cluemart-shared/dist/chunk-YRO6KEZG.mjs
48
50
  import dayjs from "dayjs";
49
51
  import customParseFormat from "dayjs/plugin/customParseFormat.js";
50
52
  import isSameOrAfter from "dayjs/plugin/isSameOrAfter.js";
@@ -117,7 +119,7 @@ var SHARE_RESOURCE_LABEL = {
117
119
  school: "School"
118
120
  };
119
121
 
120
- // node_modules/@timardex/cluemart-shared/dist/chunk-364EX22V.mjs
122
+ // node_modules/@timardex/cluemart-shared/dist/chunk-JJQL6LZE.mjs
121
123
  var PROMO_CODE_PREFIX = "CM-";
122
124
  var OBJECT_ID_PATH_SEGMENT = "[a-f0-9]{24}";
123
125
  var OBJECT_ID_PATH_SEGMENT_END = `${OBJECT_ID_PATH_SEGMENT}$`;
@@ -229,7 +231,7 @@ var gameScreenIdentifierList = [
229
231
  }
230
232
  ];
231
233
 
232
- // node_modules/@timardex/cluemart-shared/dist/chunk-RCARDOVS.mjs
234
+ // node_modules/@timardex/cluemart-shared/dist/chunk-L3SNS6OJ.mjs
233
235
  import dayjs2 from "dayjs";
234
236
  var statusOptions = [
235
237
  ...Object.values(EnumInviteStatus2).map((status) => ({
@@ -1439,7 +1441,7 @@ async function getPayingStripePlanFor(userId, now, payingPlans) {
1439
1441
  if (stripe == null || stripe.subscriptionId == null) {
1440
1442
  return { hasSubscription: false, plan: null, validTypes };
1441
1443
  }
1442
- const hasActiveStatus = stripe.status === EnumSubscriptionStatus.ACTIVE || stripe.status === EnumSubscriptionStatus.TRIALING;
1444
+ const hasActiveStatus = stripe.status === EnumSubscriptionStatus2.ACTIVE || stripe.status === EnumSubscriptionStatus2.TRIALING;
1443
1445
  if (!hasActiveStatus || stripe.currentPlan == null) {
1444
1446
  return { hasSubscription: false, plan: null, validTypes };
1445
1447
  }
@@ -2334,20 +2336,24 @@ var buildLicenceReplacePipeline = ({
2334
2336
  async function replaceUserLicenceWithObject({
2335
2337
  userId,
2336
2338
  licenceObject,
2337
- protectHigherLicence = true
2339
+ protectHigherLicence = true,
2340
+ refreshExistingLicence = false
2338
2341
  }) {
2339
2342
  const user = await UserModel.findById(userId, { licences: 1 }).lean();
2340
2343
  if (!user) throw new GraphQLError("User not found");
2341
- if (user.licences?.some((l) => l.licenceType === licenceObject.licenceType)) {
2344
+ const existingLicence = user.licences?.find(
2345
+ (licence) => licence.licenceType === licenceObject.licenceType
2346
+ );
2347
+ if (existingLicence && !refreshExistingLicence) {
2342
2348
  return;
2343
2349
  }
2350
+ const category = getLicenceCategory(licenceObject.licenceType);
2344
2351
  const updatedLicenceObject = {
2345
2352
  ...licenceObject,
2346
- prevLicenceType: user.licences?.find(
2347
- (l) => getLicenceCategory(l.licenceType) === getLicenceCategory(licenceObject.licenceType)
2353
+ prevLicenceType: existingLicence && refreshExistingLicence ? existingLicence.prevLicenceType : user.licences?.find(
2354
+ (licence) => licence.licenceType && getLicenceCategory(licence.licenceType) === category
2348
2355
  )?.licenceType
2349
2356
  };
2350
- const category = getLicenceCategory(updatedLicenceObject.licenceType);
2351
2357
  if (protectHigherLicence) {
2352
2358
  const highestLicence = getHighestLicenceForCategory(
2353
2359
  user.licences,
@@ -2461,6 +2467,17 @@ var vendorLicences = [
2461
2467
  EnumUserLicence.PRO_VENDOR,
2462
2468
  EnumUserLicence.PRO_PLUS_VENDOR
2463
2469
  ];
2470
+ function isProtectedByCurrentStripeSubscription(user, licenceType, now) {
2471
+ const stripe = user.stripe;
2472
+ if (!stripe?.subscriptionId || stripe.currentPlan !== licenceType || stripe.status !== EnumSubscriptionStatus.ACTIVE && stripe.status !== EnumSubscriptionStatus.TRIALING) {
2473
+ return false;
2474
+ }
2475
+ if (stripe.cancelAtPeriodEnd !== true || !stripe.endDate) {
2476
+ return true;
2477
+ }
2478
+ const paidThrough = dayjs6(stripe.endDate);
2479
+ return !paidThrough.isValid() || paidThrough.isAfter(now);
2480
+ }
2464
2481
  async function handleVendorLicenceCompliance(user, now) {
2465
2482
  if (!user.licences || !user.vendor) {
2466
2483
  return;
@@ -2474,12 +2491,20 @@ async function handleVendorLicenceCompliance(user, now) {
2474
2491
  const proLicences = vendorLicencesOfUser.filter(
2475
2492
  (licence) => licence.licenceType !== EnumUserLicence.STANDARD_VENDOR
2476
2493
  );
2477
- const expiredProLicence = proLicences.some(
2494
+ const expiredProLicences = proLicences.filter(
2478
2495
  (licence) => !dayjs6(licence.expiryDate).isAfter(now)
2479
2496
  );
2480
- const hasValidProLicence = hasValidLicence(proLicences, vendorLicences, now);
2497
+ const stripeProtectedLicenceTypes = new Set(
2498
+ expiredProLicences.filter(
2499
+ (licence) => isProtectedByCurrentStripeSubscription(user, licence.licenceType, now)
2500
+ ).map((licence) => licence.licenceType)
2501
+ );
2502
+ const expiredProLicence = expiredProLicences.some(
2503
+ (licence) => !stripeProtectedLicenceTypes.has(licence.licenceType)
2504
+ );
2505
+ const hasValidProLicence = stripeProtectedLicenceTypes.size > 0 || hasValidLicence(proLicences, vendorLicences, now);
2481
2506
  const hasExpiredVendorLicence = vendorLicencesOfUser.some(
2482
- (licence) => !dayjs6(licence.expiryDate).isAfter(now)
2507
+ (licence) => !dayjs6(licence.expiryDate).isAfter(now) && !stripeProtectedLicenceTypes.has(licence.licenceType)
2483
2508
  );
2484
2509
  if (!hasExpiredVendorLicence) {
2485
2510
  return;
@@ -2493,7 +2518,10 @@ async function handleVendorLicenceCompliance(user, now) {
2493
2518
  "owner.userId": user._id
2494
2519
  }).lean().exec();
2495
2520
  }
2496
- await syncUserLicencesAfterExpiry(user._id, vendorLicences, now, "downgrade");
2521
+ const licencesToSync = vendorLicences.filter(
2522
+ (licenceType) => !stripeProtectedLicenceTypes.has(licenceType)
2523
+ );
2524
+ await syncUserLicencesAfterExpiry(user._id, licencesToSync, now, "downgrade");
2497
2525
  if (!expiredProLicence || !vendor || hasValidProLicence) {
2498
2526
  return;
2499
2527
  }
@@ -2582,6 +2610,13 @@ async function processUserCompliance(user, now) {
2582
2610
  }
2583
2611
 
2584
2612
  // src/service/license/compliance/ensureUserLicenseCompliance.ts
2613
+ async function ensureUserLicenseComplianceForUser(userId, now = dayjs8()) {
2614
+ const user = await UserModel.findById(userId);
2615
+ if (!user) {
2616
+ return;
2617
+ }
2618
+ await processUserCompliance(user, now);
2619
+ }
2585
2620
  async function ensureUserLicenseCompliance() {
2586
2621
  const now = dayjs8();
2587
2622
  console.log(`\u{1F50D} Checking license compliance at ${now.format()}`);
@@ -2833,7 +2868,7 @@ async function sendLicenseReminder(user, licence) {
2833
2868
  await sendPushNotifications(payload);
2834
2869
  console.log(`\u2705 Sent 7-day reminder to user ${userId} for ${licenceName}`);
2835
2870
  }
2836
- async function processLicenseReminder(user, licence, now) {
2871
+ async function processLicenseReminder(licence, now) {
2837
2872
  if (dayjs9(licence.expiryDate).isBefore(now)) {
2838
2873
  return false;
2839
2874
  }
@@ -2865,7 +2900,7 @@ async function processUserLicenseReminders(user, now) {
2865
2900
  const licenceChecks = await Promise.all(
2866
2901
  validLicences.map(async (licence) => {
2867
2902
  try {
2868
- const shouldSend = await processLicenseReminder(user, licence, now);
2903
+ const shouldSend = await processLicenseReminder(licence, now);
2869
2904
  return { licence, shouldSend };
2870
2905
  } catch (err) {
2871
2906
  console.error(
@@ -2941,6 +2976,7 @@ export {
2941
2976
  createLicenceObject,
2942
2977
  didRemoveAnyEventDates,
2943
2978
  ensureUserLicenseCompliance,
2979
+ ensureUserLicenseComplianceForUser,
2944
2980
  eventLicences,
2945
2981
  findAffiliateByPromoCode,
2946
2982
  findEventOrImportedMarketById,