@timardex/cluemart-server-shared 5.0.0 → 5.3.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.cjs CHANGED
@@ -89,6 +89,7 @@ __export(index_exports, {
89
89
  activeAffiliateCodeExists: () => activeAffiliateCodeExists,
90
90
  awardAffiliateVendorSubscriptionRewards: () => awardAffiliateVendorSubscriptionRewards,
91
91
  baseResourceFields: () => baseResourceFields,
92
+ buildAssociatesWriteGuard: () => buildAssociatesWriteGuard,
92
93
  buildInitialBillingCatalogEntries: () => buildInitialBillingCatalogEntries,
93
94
  buildLicenceExpiryPipeline: () => buildLicenceExpiryPipeline,
94
95
  buildUserHasEnoughPointsFilter: () => buildUserHasEnoughPointsFilter,
@@ -153,6 +154,7 @@ __export(index_exports, {
153
154
  notifyUsers: () => notifyUsers,
154
155
  partnerLicences: () => partnerLicences,
155
156
  persistArchivedEventDates: () => persistArchivedEventDates,
157
+ pinAssociateTimestamp: () => pinAssociateTimestamp,
156
158
  processLicenseReminder: () => processLicenseReminder,
157
159
  processUserCompliance: () => processUserCompliance,
158
160
  processUserLicenseReminders: () => processUserLicenseReminders,
@@ -1205,6 +1207,11 @@ var schema7 = new MongooseSchema6(
1205
1207
  type: ResourceImageTypeSchema
1206
1208
  },
1207
1209
  dateTime: [dateTimeSchema],
1210
+ deactivatedReason: {
1211
+ enum: Object.values(import_cluemart_shared9.EnumImportedMarketDeactivationReason),
1212
+ required: false,
1213
+ type: String
1214
+ },
1208
1215
  deletedAt: { default: null, required: false, type: Date },
1209
1216
  description: { required: true, type: String },
1210
1217
  earliestStartDate: { default: null, required: false, type: Date },
@@ -2209,8 +2216,11 @@ var schema17 = new MongooseSchema18(
2209
2216
  categories: { required: true, type: [CategorySchema] },
2210
2217
  categoriesNames: { default: [], required: false, type: [String] },
2211
2218
  claimed: { default: true, required: false, type: Boolean },
2219
+ downgradeNotifiedAt: { default: null, required: false, type: Date },
2212
2220
  downgradeSnapshot: { required: false, type: downgradeSnapshotSchema },
2221
+ featuresDowngraded: { default: false, required: false, type: Boolean },
2213
2222
  foodTruck: { required: true, type: Boolean },
2223
+ licenceEpoch: { default: 0, required: false, type: Number },
2214
2224
  products: { required: false, type: productWrapperSchema },
2215
2225
  shareRelation: { required: false, type: socialShareResourceSchema },
2216
2226
  unregisteredVendorId: {
@@ -3539,6 +3549,38 @@ var ASSOCIABLE_MODELS = {
3539
3549
  [import_cluemart_shared28.EnumResourceType.PARTNER]: PartnerModel,
3540
3550
  [import_cluemart_shared28.EnumResourceType.VENDOR]: VendorModel
3541
3551
  };
3552
+ function pinAssociateTimestamp(value) {
3553
+ return value == null ? null : { $in: [value, null] };
3554
+ }
3555
+ function buildAssociatesWriteGuard({
3556
+ canManage,
3557
+ nextAssociates,
3558
+ snapshot
3559
+ }) {
3560
+ if (!canManage) {
3561
+ return null;
3562
+ }
3563
+ const previous = snapshot ?? [];
3564
+ const emptyListFilter = {
3565
+ $or: [{ associates: { $size: 0 } }, { associates: null }]
3566
+ };
3567
+ return {
3568
+ filter: previous.length > 0 ? {
3569
+ $and: previous.map((associate) => ({
3570
+ associates: {
3571
+ $elemMatch: {
3572
+ addedAt: pinAssociateTimestamp(associate.addedAt),
3573
+ respondedAt: pinAssociateTimestamp(associate.respondedAt),
3574
+ status: associate.status,
3575
+ userId: associate.userId
3576
+ }
3577
+ }
3578
+ })),
3579
+ associates: { $size: previous.length }
3580
+ } : emptyListFilter,
3581
+ update: { associates: nextAssociates }
3582
+ };
3583
+ }
3542
3584
  function acceptedAssociateUserIds(associates) {
3543
3585
  return (associates ?? []).filter((associate) => associate.status === import_cluemart_shared28.EnumAssociateStatus.ACCEPTED).map((associate) => associate.userId);
3544
3586
  }
@@ -3578,7 +3620,10 @@ async function acceptedUserIdsForResource({
3578
3620
  resourceType
3579
3621
  }) {
3580
3622
  const model = ASSOCIABLE_MODELS[resourceType];
3581
- const resource = await model.findOne({ _id: resourceId, deletedAt: null }).select("associates").lean().exec();
3623
+ const resource = await model.findOne({ _id: resourceId, deletedAt: null }).select("associates featuresDowngraded").lean().exec();
3624
+ if (resource?.featuresDowngraded) {
3625
+ return /* @__PURE__ */ new Set();
3626
+ }
3582
3627
  return new Set(
3583
3628
  acceptedAssociateUserIds(resource?.associates).map(
3584
3629
  (userId) => String(userId)
@@ -3728,12 +3773,12 @@ async function reconcileUserBatch({
3728
3773
  _id: {
3729
3774
  $in: [...heldByResource.values()].map((entry) => entry.resourceId)
3730
3775
  }
3731
- }).select("associates deletedAt").lean().exec();
3776
+ }).select("associates deletedAt featuresDowngraded").lean().exec();
3732
3777
  const acceptedByResource = /* @__PURE__ */ new Map();
3733
3778
  for (const resource of resources) {
3734
3779
  acceptedByResource.set(
3735
3780
  String(resource._id),
3736
- resource.deletedAt ? /* @__PURE__ */ new Set() : new Set(
3781
+ resource.deletedAt || resource.featuresDowngraded ? /* @__PURE__ */ new Set() : new Set(
3737
3782
  acceptedAssociateUserIds(resource.associates).map(
3738
3783
  (userId) => String(userId)
3739
3784
  )
@@ -4799,13 +4844,13 @@ var import_dayjs6 = __toESM(require("dayjs"));
4799
4844
  var import_cluemart_shared36 = require("@timardex/cluemart-shared");
4800
4845
  var import_dayjs5 = __toESM(require("dayjs"));
4801
4846
  var import_graphql = require("graphql");
4802
- var LicenceCategory = /* @__PURE__ */ ((LicenceCategory3) => {
4803
- LicenceCategory3["EVENT"] = "event";
4804
- LicenceCategory3["PARTNER"] = "partner";
4805
- LicenceCategory3["VENDOR"] = "vendor";
4806
- LicenceCategory3["AFFILIATE"] = "affiliate";
4807
- LicenceCategory3["SCHOOL"] = "school";
4808
- return LicenceCategory3;
4847
+ var LicenceCategory = /* @__PURE__ */ ((LicenceCategory2) => {
4848
+ LicenceCategory2["EVENT"] = "event";
4849
+ LicenceCategory2["PARTNER"] = "partner";
4850
+ LicenceCategory2["VENDOR"] = "vendor";
4851
+ LicenceCategory2["AFFILIATE"] = "affiliate";
4852
+ LicenceCategory2["SCHOOL"] = "school";
4853
+ return LicenceCategory2;
4809
4854
  })(LicenceCategory || {});
4810
4855
  var licenceCategoryMapping = {
4811
4856
  [import_cluemart_shared36.EnumUserLicence.PRO_EVENT]: "event" /* EVENT */,
@@ -4829,25 +4874,8 @@ var licencePriority = {
4829
4874
  [import_cluemart_shared36.EnumUserLicence.STANDARD_AFFILIATE]: 1,
4830
4875
  [import_cluemart_shared36.EnumUserLicence.STANDARD_SCHOOL]: 1
4831
4876
  };
4832
- var standardLicences = [
4833
- import_cluemart_shared36.EnumUserLicence.STANDARD_VENDOR,
4834
- import_cluemart_shared36.EnumUserLicence.STANDARD_EVENT,
4835
- import_cluemart_shared36.EnumUserLicence.STANDARD_PARTNER
4836
- ];
4837
- var standardLicenceSet = new Set(standardLicences);
4838
- function isStandardLicence(licence) {
4839
- return standardLicenceSet.has(licence);
4840
- }
4841
- var proLicences = [
4842
- import_cluemart_shared36.EnumUserLicence.PRO_EVENT,
4843
- import_cluemart_shared36.EnumUserLicence.PRO_PLUS_EVENT,
4844
- import_cluemart_shared36.EnumUserLicence.PRO_VENDOR,
4845
- import_cluemart_shared36.EnumUserLicence.PRO_PLUS_VENDOR
4846
- ];
4847
- var proLicenceSet = new Set(proLicences);
4848
- function isProLicence(licence) {
4849
- return proLicenceSet.has(licence);
4850
- }
4877
+ var isStandardLicence = import_cluemart_shared36.isStandardLicenceType;
4878
+ var isProLicence = import_cluemart_shared36.isProLicenceType;
4851
4879
  var categoryRegexMapping = {
4852
4880
  ["event" /* EVENT */]: /_event$/,
4853
4881
  ["partner" /* PARTNER */]: /_partner$/,
@@ -5170,30 +5198,134 @@ async function findUserVendor(userId, logLabel) {
5170
5198
  }
5171
5199
  return vendor;
5172
5200
  }
5201
+ async function downgradeStillApplies(ownerUserId) {
5202
+ const hasActiveProLicence = await hasActiveProLicenceForResource({
5203
+ includeStripeProtected: true,
5204
+ resourceType: import_cluemart_shared37.EnumResourceType.VENDOR,
5205
+ userId: ownerUserId
5206
+ });
5207
+ return !hasActiveProLicence;
5208
+ }
5173
5209
  async function applyVendorDowngrade(vendor, ownerUserId) {
5174
- const updateData = {};
5175
- updateData.availability = {
5176
- corporate: false,
5177
- private: false,
5178
- school: false
5179
- };
5180
- updateData.products = {
5181
- active: false,
5182
- productsList: vendor.products?.productsList ?? []
5183
- };
5184
- updateData.calendar = {
5185
- active: false,
5186
- calendarData: vendor.calendar?.calendarData ?? []
5187
- };
5188
- updateData.downgradeSnapshot = {
5189
- availability: vendor.availability,
5190
- calendarActive: vendor.calendar?.active,
5191
- productsActive: vendor.products?.active
5210
+ let current = vendor;
5211
+ for (let attempt = 0; attempt < 2; attempt += 1) {
5212
+ if (!await downgradeStillApplies(ownerUserId)) {
5213
+ console.info(
5214
+ "[applyVendorDowngrade] owner holds an active PRO licence again; skipping the downgrade",
5215
+ { vendorId: String(current._id) }
5216
+ );
5217
+ return "skipped";
5218
+ }
5219
+ const associatesGuard = buildAssociatesWriteGuard({
5220
+ canManage: true,
5221
+ nextAssociates: [],
5222
+ snapshot: current.associates
5223
+ });
5224
+ if (!associatesGuard) {
5225
+ return "skipped";
5226
+ }
5227
+ const result = await VendorModel.updateOne(
5228
+ {
5229
+ _id: current._id,
5230
+ active: true,
5231
+ deletedAt: null,
5232
+ // Already downgraded: another run got there first and its snapshot is
5233
+ // the original state this one must not overwrite.
5234
+ featuresDowngraded: { $ne: true },
5235
+ // Upgrades bump this in their own write; `null` covers vendors that
5236
+ // predate the field.
5237
+ licenceEpoch: { $in: [current.licenceEpoch ?? 0, null] },
5238
+ "owner.userId": ownerUserId,
5239
+ ...associatesGuard.filter
5240
+ },
5241
+ {
5242
+ $inc: { licenceEpoch: 1 },
5243
+ $set: {
5244
+ ...associatesGuard.update,
5245
+ availability: {
5246
+ corporate: false,
5247
+ private: false,
5248
+ school: false
5249
+ },
5250
+ calendar: {
5251
+ active: false,
5252
+ calendarData: current.calendar?.calendarData ?? []
5253
+ },
5254
+ downgradeSnapshot: {
5255
+ availability: current.availability,
5256
+ calendarActive: current.calendar?.active,
5257
+ productsActive: current.products?.active
5258
+ },
5259
+ featuresDowngraded: true,
5260
+ // STANDARD_VENDOR keeps only the first 6 images active.
5261
+ images: (current.images ?? []).map((image, index) => ({
5262
+ ...image,
5263
+ active: index < 6
5264
+ })),
5265
+ products: {
5266
+ active: false,
5267
+ productsList: current.products?.productsList ?? []
5268
+ }
5269
+ }
5270
+ }
5271
+ );
5272
+ if ((result?.matchedCount ?? 0) > 0) {
5273
+ break;
5274
+ }
5275
+ const fresh = await VendorModel.findById(current._id).lean().exec();
5276
+ if (!fresh) {
5277
+ return "skipped";
5278
+ }
5279
+ if (fresh.featuresDowngraded === true) {
5280
+ console.info(
5281
+ "[applyVendorDowngrade] vendor is already downgraded; licence sync can proceed",
5282
+ { vendorId: String(fresh._id) }
5283
+ );
5284
+ return "already-downgraded";
5285
+ }
5286
+ current = fresh;
5287
+ if (attempt === 1) {
5288
+ console.warn(
5289
+ "[applyVendorDowngrade] vendor changed under the downgrade; left to the next compliance run",
5290
+ { vendorId: String(current._id) }
5291
+ );
5292
+ return "skipped";
5293
+ }
5294
+ }
5295
+ try {
5296
+ await detachStaleAssociateGrants({
5297
+ acceptedUserIds: [],
5298
+ resourceId: current._id,
5299
+ resourceType: import_cluemart_shared37.EnumResourceType.VENDOR
5300
+ });
5301
+ } catch (error) {
5302
+ console.error(
5303
+ "[applyVendorDowngrade] grant detach failed; left to reconciliation",
5304
+ error
5305
+ );
5306
+ }
5307
+ return "applied";
5308
+ }
5309
+ async function applyVendorRestore(vendor, ownerUserId) {
5310
+ const snapshot = vendor.downgradeSnapshot;
5311
+ const updateData = {
5312
+ availability: {
5313
+ corporate: snapshot?.availability?.corporate ?? true,
5314
+ private: snapshot?.availability?.private ?? true,
5315
+ school: snapshot?.availability?.school ?? true
5316
+ },
5317
+ calendar: {
5318
+ active: snapshot?.calendarActive ?? true,
5319
+ calendarData: vendor.calendar?.calendarData ?? []
5320
+ },
5321
+ downgradeNotifiedAt: null,
5322
+ featuresDowngraded: false,
5323
+ images: (vendor.images ?? []).map((image) => ({ ...image, active: true })),
5324
+ products: {
5325
+ active: snapshot?.productsActive ?? true,
5326
+ productsList: vendor.products?.productsList ?? []
5327
+ }
5192
5328
  };
5193
- updateData.images = (vendor.images ?? []).map((image, index) => ({
5194
- ...image,
5195
- active: index < 6
5196
- }));
5197
5329
  const result = await VendorModel.updateOne(
5198
5330
  {
5199
5331
  _id: vendor._id,
@@ -5201,7 +5333,7 @@ async function applyVendorDowngrade(vendor, ownerUserId) {
5201
5333
  deletedAt: null,
5202
5334
  "owner.userId": ownerUserId
5203
5335
  },
5204
- { $set: updateData }
5336
+ { $inc: { licenceEpoch: 1 }, $set: updateData }
5205
5337
  );
5206
5338
  return (result?.matchedCount ?? 0) > 0;
5207
5339
  }
@@ -5221,37 +5353,6 @@ async function downgradeVendorProFeatures(userId, licenceType) {
5221
5353
  throw error;
5222
5354
  }
5223
5355
  }
5224
- async function applyVendorRestore(vendor, ownerUserId) {
5225
- const updateData = {};
5226
- const snapshot = vendor.downgradeSnapshot;
5227
- updateData.availability = {
5228
- corporate: snapshot?.availability?.corporate ?? true,
5229
- private: snapshot?.availability?.private ?? true,
5230
- school: snapshot?.availability?.school ?? true
5231
- };
5232
- updateData.products = {
5233
- active: snapshot?.productsActive ?? true,
5234
- productsList: vendor.products?.productsList ?? []
5235
- };
5236
- updateData.calendar = {
5237
- active: snapshot?.calendarActive ?? true,
5238
- calendarData: vendor.calendar?.calendarData ?? []
5239
- };
5240
- updateData.images = (vendor.images ?? []).map((image) => ({
5241
- ...image,
5242
- active: true
5243
- }));
5244
- const result = await VendorModel.updateOne(
5245
- {
5246
- _id: vendor._id,
5247
- active: true,
5248
- deletedAt: null,
5249
- "owner.userId": ownerUserId
5250
- },
5251
- { $set: updateData }
5252
- );
5253
- return (result?.matchedCount ?? 0) > 0;
5254
- }
5255
5356
  async function restoreVendorProFeatures(userId, licenceType) {
5256
5357
  const isProVendor = licenceType === import_cluemart_shared37.EnumUserLicence.PRO_VENDOR || licenceType === import_cluemart_shared37.EnumUserLicence.PRO_PLUS_VENDOR;
5257
5358
  if (!isProVendor) {
@@ -5268,6 +5369,61 @@ async function restoreVendorProFeatures(userId, licenceType) {
5268
5369
  throw error;
5269
5370
  }
5270
5371
  }
5372
+ var NOTIFICATION_CLAIM_LEASE_MS = 60 * 60 * 1e3;
5373
+ async function notifyVendorDowngrade(vendorId, ownerUserId) {
5374
+ if (!await downgradeStillApplies(ownerUserId)) {
5375
+ return false;
5376
+ }
5377
+ const claimedAt = /* @__PURE__ */ new Date();
5378
+ const claimed = await VendorModel.findOneAndUpdate(
5379
+ {
5380
+ $or: [
5381
+ { downgradeNotifiedAt: null },
5382
+ {
5383
+ downgradeNotifiedAt: {
5384
+ $lt: new Date(claimedAt.getTime() - NOTIFICATION_CLAIM_LEASE_MS)
5385
+ }
5386
+ }
5387
+ ],
5388
+ _id: vendorId,
5389
+ active: true,
5390
+ deletedAt: null,
5391
+ // A re-upgrade that restored the vendor has flipped this back, so its
5392
+ // owner is not told about a downgrade that no longer holds.
5393
+ featuresDowngraded: true
5394
+ },
5395
+ { $set: { downgradeNotifiedAt: claimedAt } },
5396
+ { new: false }
5397
+ ).lean().exec();
5398
+ if (!claimed) {
5399
+ return false;
5400
+ }
5401
+ const sent = await sendDeactivationNotification(
5402
+ {
5403
+ data: {
5404
+ resourceId: String(claimed._id),
5405
+ resourceName: claimed.name,
5406
+ resourceType: import_cluemart_shared37.EnumNotificationResourceType.DOWNGRADED_VENDOR
5407
+ },
5408
+ message: `Your Vendor licence has been downgraded due to licence expiration.`,
5409
+ title: `Vendor Licence Downgraded`,
5410
+ type: import_cluemart_shared37.EnumNotificationType.SYSTEM,
5411
+ userIds: [ownerUserId]
5412
+ },
5413
+ ownerUserId,
5414
+ claimed.name,
5415
+ "vendor",
5416
+ claimed.downgradeNotifiedAt ?? null
5417
+ );
5418
+ if (sent) {
5419
+ return true;
5420
+ }
5421
+ await VendorModel.updateOne(
5422
+ { _id: vendorId, downgradeNotifiedAt: claimedAt },
5423
+ { $set: { downgradeNotifiedAt: null } }
5424
+ );
5425
+ return false;
5426
+ }
5271
5427
  async function handleVendorLicenceCompliance(user, now) {
5272
5428
  if (!user.licences || !user.vendor) {
5273
5429
  return;
@@ -5278,10 +5434,10 @@ async function handleVendorLicenceCompliance(user, now) {
5278
5434
  if (vendorLicencesOfUser.length === 0) {
5279
5435
  return;
5280
5436
  }
5281
- const proLicences2 = vendorLicencesOfUser.filter(
5437
+ const proLicences = vendorLicencesOfUser.filter(
5282
5438
  (licence) => licence.licenceType !== import_cluemart_shared37.EnumUserLicence.STANDARD_VENDOR
5283
5439
  );
5284
- const expiredProLicences = proLicences2.filter(
5440
+ const expiredProLicences = proLicences.filter(
5285
5441
  (licence) => !(0, import_dayjs6.default)(licence.expiryDate).isAfter(now)
5286
5442
  );
5287
5443
  const stripeProtectedLicenceTypes = new Set(
@@ -5292,7 +5448,7 @@ async function handleVendorLicenceCompliance(user, now) {
5292
5448
  const expiredProLicence = expiredProLicences.some(
5293
5449
  (licence) => !stripeProtectedLicenceTypes.has(licence.licenceType)
5294
5450
  );
5295
- const hasValidProLicence = stripeProtectedLicenceTypes.size > 0 || hasValidLicence(proLicences2, import_cluemart_shared37.vendorLicences, now);
5451
+ const hasValidProLicence = stripeProtectedLicenceTypes.size > 0 || hasValidLicence(proLicences, import_cluemart_shared37.vendorLicences, now);
5296
5452
  const hasExpiredVendorLicence = vendorLicencesOfUser.some(
5297
5453
  (licence) => !(0, import_dayjs6.default)(licence.expiryDate).isAfter(now) && !stripeProtectedLicenceTypes.has(licence.licenceType)
5298
5454
  );
@@ -5308,29 +5464,27 @@ async function handleVendorLicenceCompliance(user, now) {
5308
5464
  "owner.userId": user._id
5309
5465
  }).lean().exec();
5310
5466
  }
5467
+ const needsDowngrade = expiredProLicence && Boolean(vendor) && !hasValidProLicence;
5468
+ const outcome = needsDowngrade && vendor ? await applyVendorDowngrade(vendor, user._id) : "skipped";
5311
5469
  const licencesToSync = import_cluemart_shared37.vendorLicences.filter(
5312
5470
  (licenceType) => !stripeProtectedLicenceTypes.has(licenceType)
5313
5471
  );
5314
- await syncUserLicencesAfterExpiry(user._id, licencesToSync, now, "downgrade");
5315
- if (!expiredProLicence || !vendor || hasValidProLicence) {
5472
+ if (!needsDowngrade) {
5473
+ await syncUserLicencesAfterExpiry(
5474
+ user._id,
5475
+ licencesToSync,
5476
+ now,
5477
+ "downgrade"
5478
+ );
5316
5479
  return;
5317
5480
  }
5318
- const downgraded = await applyVendorDowngrade(vendor, user._id);
5319
- if (!downgraded) {
5481
+ if (outcome === "skipped" || !vendor) {
5320
5482
  return;
5321
5483
  }
5322
- const payload = {
5323
- data: {
5324
- resourceId: String(vendor._id),
5325
- resourceName: vendor.name,
5326
- resourceType: import_cluemart_shared37.EnumNotificationResourceType.DOWNGRADED_VENDOR
5327
- },
5328
- message: `Your Vendor licence has been downgraded due to licence expiration.`,
5329
- title: `Vendor Licence Downgraded`,
5330
- type: import_cluemart_shared37.EnumNotificationType.SYSTEM,
5331
- userIds: [user._id]
5332
- };
5333
- await sendDeactivationNotification(payload, user._id, vendor.name, "vendor");
5484
+ if (!await notifyVendorDowngrade(vendor._id, user._id)) {
5485
+ return;
5486
+ }
5487
+ await syncUserLicencesAfterExpiry(user._id, licencesToSync, now, "downgrade");
5334
5488
  }
5335
5489
  async function vendorOwnerHasProLicence(vendorId) {
5336
5490
  const vendor = await VendorModel.findOne({
@@ -5375,17 +5529,35 @@ function hasValidLicence(licences, licenceTypes, now) {
5375
5529
  (licence) => licenceTypes.includes(licence.licenceType) && (0, import_dayjs7.default)(licence.expiryDate).isAfter(now)
5376
5530
  );
5377
5531
  }
5378
- async function sendDeactivationNotification(payload, userId, resourceName, resourceType) {
5532
+ async function deactivationNoticeStored(payload, userId, since) {
5533
+ const stored = await NotificationModel.exists({
5534
+ createdAt: { $gte: since },
5535
+ "data.resourceId": payload.data.resourceId,
5536
+ "data.resourceType": payload.data.resourceType,
5537
+ title: payload.title,
5538
+ type: payload.type,
5539
+ userId
5540
+ });
5541
+ return stored !== null;
5542
+ }
5543
+ async function sendDeactivationNotification(payload, userId, resourceName, resourceType, retryOf = null) {
5544
+ if (retryOf && await deactivationNoticeStored(payload, userId, retryOf)) {
5545
+ console.log(
5546
+ `\u{1F501} ${resourceType} notification already stored for user ${String(userId)} for "${resourceName}"`
5547
+ );
5548
+ return true;
5549
+ }
5379
5550
  const sent = await notifyUsers({ payload });
5380
5551
  if (!sent) {
5381
5552
  console.error(
5382
5553
  `\u274C ${resourceType} notification not confirmed for user ${String(userId)} for "${resourceName}"`
5383
5554
  );
5384
- return;
5555
+ return false;
5385
5556
  }
5386
5557
  console.log(
5387
5558
  `\u2705 Sent ${resourceType} notification to user ${String(userId)} for "${resourceName}"`
5388
5559
  );
5560
+ return true;
5389
5561
  }
5390
5562
  async function processUserCompliance(user, now) {
5391
5563
  if (!user.licences) {
@@ -5812,6 +5984,7 @@ async function remindUsersAboutLicenseExpiration() {
5812
5984
  activeAffiliateCodeExists,
5813
5985
  awardAffiliateVendorSubscriptionRewards,
5814
5986
  baseResourceFields,
5987
+ buildAssociatesWriteGuard,
5815
5988
  buildInitialBillingCatalogEntries,
5816
5989
  buildLicenceExpiryPipeline,
5817
5990
  buildUserHasEnoughPointsFilter,
@@ -5876,6 +6049,7 @@ async function remindUsersAboutLicenseExpiration() {
5876
6049
  notifyUsers,
5877
6050
  partnerLicences,
5878
6051
  persistArchivedEventDates,
6052
+ pinAssociateTimestamp,
5879
6053
  processLicenseReminder,
5880
6054
  processUserCompliance,
5881
6055
  processUserLicenseReminders,