@timardex/cluemart-server-shared 1.1.38 → 1.1.39

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 { q as SchemaAffiliateResourceType, S as SchemaOwnerType, i as SchemaRelationType, n as SchemaUserType } from '../Affiliate-BLh0EcNI.mjs';
5
+ import { O as ObjectId, G as GraphQLContext, f as SchemaCreateBulkNotificationInput } from '../index-zC8a3adw.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 { q as SchemaAffiliateResourceType, S as SchemaOwnerType, i as SchemaRelationType, n as SchemaUserType } from '../Affiliate-CBp0M850.js';
5
+ import { O as ObjectId, G as GraphQLContext, f as SchemaCreateBulkNotificationInput } from '../index-zC8a3adw.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,7 +27,7 @@ import {
26
27
  isNonVisitorResourceType,
27
28
  licenseNiceNames,
28
29
  timeFormat
29
- } from "../chunk-DJHOLZ3J.mjs";
30
+ } from "../chunk-6RUQHYTK.mjs";
30
31
  import "../chunk-6PNG5BI5.mjs";
31
32
 
32
33
  // src/service/promoCode/constants.ts
@@ -44,7 +45,7 @@ async function activeAffiliateCodeExists(affiliateCode) {
44
45
  return existing !== null;
45
46
  }
46
47
 
47
- // node_modules/@timardex/cluemart-shared/dist/chunk-2UNNIQIK.mjs
48
+ // node_modules/@timardex/cluemart-shared/dist/chunk-YRO6KEZG.mjs
48
49
  import dayjs from "dayjs";
49
50
  import customParseFormat from "dayjs/plugin/customParseFormat.js";
50
51
  import isSameOrAfter from "dayjs/plugin/isSameOrAfter.js";
@@ -117,7 +118,7 @@ var SHARE_RESOURCE_LABEL = {
117
118
  school: "School"
118
119
  };
119
120
 
120
- // node_modules/@timardex/cluemart-shared/dist/chunk-364EX22V.mjs
121
+ // node_modules/@timardex/cluemart-shared/dist/chunk-STNE7PMX.mjs
121
122
  var PROMO_CODE_PREFIX = "CM-";
122
123
  var OBJECT_ID_PATH_SEGMENT = "[a-f0-9]{24}";
123
124
  var OBJECT_ID_PATH_SEGMENT_END = `${OBJECT_ID_PATH_SEGMENT}$`;
@@ -229,7 +230,7 @@ var gameScreenIdentifierList = [
229
230
  }
230
231
  ];
231
232
 
232
- // node_modules/@timardex/cluemart-shared/dist/chunk-RCARDOVS.mjs
233
+ // node_modules/@timardex/cluemart-shared/dist/chunk-3ZPHXVUT.mjs
233
234
  import dayjs2 from "dayjs";
234
235
  var statusOptions = [
235
236
  ...Object.values(EnumInviteStatus2).map((status) => ({
@@ -1439,7 +1440,7 @@ async function getPayingStripePlanFor(userId, now, payingPlans) {
1439
1440
  if (stripe == null || stripe.subscriptionId == null) {
1440
1441
  return { hasSubscription: false, plan: null, validTypes };
1441
1442
  }
1442
- const hasActiveStatus = stripe.status === EnumSubscriptionStatus.ACTIVE || stripe.status === EnumSubscriptionStatus.TRIALING;
1443
+ const hasActiveStatus = stripe.status === EnumSubscriptionStatus2.ACTIVE || stripe.status === EnumSubscriptionStatus2.TRIALING;
1443
1444
  if (!hasActiveStatus || stripe.currentPlan == null) {
1444
1445
  return { hasSubscription: false, plan: null, validTypes };
1445
1446
  }
@@ -2334,20 +2335,24 @@ var buildLicenceReplacePipeline = ({
2334
2335
  async function replaceUserLicenceWithObject({
2335
2336
  userId,
2336
2337
  licenceObject,
2337
- protectHigherLicence = true
2338
+ protectHigherLicence = true,
2339
+ refreshExistingLicence = false
2338
2340
  }) {
2339
2341
  const user = await UserModel.findById(userId, { licences: 1 }).lean();
2340
2342
  if (!user) throw new GraphQLError("User not found");
2341
- if (user.licences?.some((l) => l.licenceType === licenceObject.licenceType)) {
2343
+ const existingLicence = user.licences?.find(
2344
+ (licence) => licence.licenceType === licenceObject.licenceType
2345
+ );
2346
+ if (existingLicence && !refreshExistingLicence) {
2342
2347
  return;
2343
2348
  }
2349
+ const category = getLicenceCategory(licenceObject.licenceType);
2344
2350
  const updatedLicenceObject = {
2345
2351
  ...licenceObject,
2346
- prevLicenceType: user.licences?.find(
2347
- (l) => getLicenceCategory(l.licenceType) === getLicenceCategory(licenceObject.licenceType)
2352
+ prevLicenceType: existingLicence && refreshExistingLicence ? existingLicence.prevLicenceType : user.licences?.find(
2353
+ (licence) => licence.licenceType && getLicenceCategory(licence.licenceType) === category
2348
2354
  )?.licenceType
2349
2355
  };
2350
- const category = getLicenceCategory(updatedLicenceObject.licenceType);
2351
2356
  if (protectHigherLicence) {
2352
2357
  const highestLicence = getHighestLicenceForCategory(
2353
2358
  user.licences,
@@ -2461,6 +2466,17 @@ var vendorLicences = [
2461
2466
  EnumUserLicence.PRO_VENDOR,
2462
2467
  EnumUserLicence.PRO_PLUS_VENDOR
2463
2468
  ];
2469
+ function isProtectedByCurrentStripeSubscription(user, licenceType, now) {
2470
+ const stripe = user.stripe;
2471
+ if (!stripe?.subscriptionId || stripe.currentPlan !== licenceType || stripe.status !== EnumSubscriptionStatus.ACTIVE && stripe.status !== EnumSubscriptionStatus.TRIALING) {
2472
+ return false;
2473
+ }
2474
+ if (stripe.cancelAtPeriodEnd !== true || !stripe.endDate) {
2475
+ return true;
2476
+ }
2477
+ const paidThrough = dayjs6(stripe.endDate);
2478
+ return !paidThrough.isValid() || paidThrough.isAfter(now);
2479
+ }
2464
2480
  async function handleVendorLicenceCompliance(user, now) {
2465
2481
  if (!user.licences || !user.vendor) {
2466
2482
  return;
@@ -2474,12 +2490,20 @@ async function handleVendorLicenceCompliance(user, now) {
2474
2490
  const proLicences = vendorLicencesOfUser.filter(
2475
2491
  (licence) => licence.licenceType !== EnumUserLicence.STANDARD_VENDOR
2476
2492
  );
2477
- const expiredProLicence = proLicences.some(
2493
+ const expiredProLicences = proLicences.filter(
2478
2494
  (licence) => !dayjs6(licence.expiryDate).isAfter(now)
2479
2495
  );
2480
- const hasValidProLicence = hasValidLicence(proLicences, vendorLicences, now);
2496
+ const stripeProtectedLicenceTypes = new Set(
2497
+ expiredProLicences.filter(
2498
+ (licence) => isProtectedByCurrentStripeSubscription(user, licence.licenceType, now)
2499
+ ).map((licence) => licence.licenceType)
2500
+ );
2501
+ const expiredProLicence = expiredProLicences.some(
2502
+ (licence) => !stripeProtectedLicenceTypes.has(licence.licenceType)
2503
+ );
2504
+ const hasValidProLicence = stripeProtectedLicenceTypes.size > 0 || hasValidLicence(proLicences, vendorLicences, now);
2481
2505
  const hasExpiredVendorLicence = vendorLicencesOfUser.some(
2482
- (licence) => !dayjs6(licence.expiryDate).isAfter(now)
2506
+ (licence) => !dayjs6(licence.expiryDate).isAfter(now) && !stripeProtectedLicenceTypes.has(licence.licenceType)
2483
2507
  );
2484
2508
  if (!hasExpiredVendorLicence) {
2485
2509
  return;
@@ -2493,7 +2517,10 @@ async function handleVendorLicenceCompliance(user, now) {
2493
2517
  "owner.userId": user._id
2494
2518
  }).lean().exec();
2495
2519
  }
2496
- await syncUserLicencesAfterExpiry(user._id, vendorLicences, now, "downgrade");
2520
+ const licencesToSync = vendorLicences.filter(
2521
+ (licenceType) => !stripeProtectedLicenceTypes.has(licenceType)
2522
+ );
2523
+ await syncUserLicencesAfterExpiry(user._id, licencesToSync, now, "downgrade");
2497
2524
  if (!expiredProLicence || !vendor || hasValidProLicence) {
2498
2525
  return;
2499
2526
  }
@@ -2582,6 +2609,13 @@ async function processUserCompliance(user, now) {
2582
2609
  }
2583
2610
 
2584
2611
  // src/service/license/compliance/ensureUserLicenseCompliance.ts
2612
+ async function ensureUserLicenseComplianceForUser(userId, now = dayjs8()) {
2613
+ const user = await UserModel.findById(userId);
2614
+ if (!user) {
2615
+ return;
2616
+ }
2617
+ await processUserCompliance(user, now);
2618
+ }
2585
2619
  async function ensureUserLicenseCompliance() {
2586
2620
  const now = dayjs8();
2587
2621
  console.log(`\u{1F50D} Checking license compliance at ${now.format()}`);
@@ -2833,7 +2867,7 @@ async function sendLicenseReminder(user, licence) {
2833
2867
  await sendPushNotifications(payload);
2834
2868
  console.log(`\u2705 Sent 7-day reminder to user ${userId} for ${licenceName}`);
2835
2869
  }
2836
- async function processLicenseReminder(user, licence, now) {
2870
+ async function processLicenseReminder(licence, now) {
2837
2871
  if (dayjs9(licence.expiryDate).isBefore(now)) {
2838
2872
  return false;
2839
2873
  }
@@ -2865,7 +2899,7 @@ async function processUserLicenseReminders(user, now) {
2865
2899
  const licenceChecks = await Promise.all(
2866
2900
  validLicences.map(async (licence) => {
2867
2901
  try {
2868
- const shouldSend = await processLicenseReminder(user, licence, now);
2902
+ const shouldSend = await processLicenseReminder(licence, now);
2869
2903
  return { licence, shouldSend };
2870
2904
  } catch (err) {
2871
2905
  console.error(
@@ -2941,6 +2975,7 @@ export {
2941
2975
  createLicenceObject,
2942
2976
  didRemoveAnyEventDates,
2943
2977
  ensureUserLicenseCompliance,
2978
+ ensureUserLicenseComplianceForUser,
2944
2979
  eventLicences,
2945
2980
  findAffiliateByPromoCode,
2946
2981
  findEventOrImportedMarketById,