@timardex/cluemart-server-shared 4.2.1 → 5.1.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
@@ -61,6 +61,7 @@ __export(index_exports, {
61
61
  GoogleImportedMarketModel: () => GoogleImportedMarketModel,
62
62
  ImpersonationAuditModel: () => ImpersonationAuditModel,
63
63
  ImpersonationSessionModel: () => ImpersonationSessionModel,
64
+ LIVE_RESOURCE_FILTER: () => LIVE_RESOURCE_FILTER,
64
65
  LicenceCategory: () => LicenceCategory,
65
66
  NotificationModel: () => NotificationModel,
66
67
  OwnerTypeSchema: () => OwnerTypeSchema,
@@ -114,6 +115,7 @@ __export(index_exports, {
114
115
  express: () => import_express.default,
115
116
  findAffiliateByPromoCode: () => findAffiliateByPromoCode,
116
117
  findEventOrImportedMarketById: () => findEventOrImportedMarketById,
118
+ findEventOrImportedMarketDetailsById: () => findEventOrImportedMarketDetailsById,
117
119
  getActiveLicenceForResource: () => getActiveLicenceForResource,
118
120
  getAssociateAccessMeta: () => getAssociateAccessMeta,
119
121
  getBillingCatalogDefinition: () => getBillingCatalogDefinition,
@@ -135,6 +137,7 @@ __export(index_exports, {
135
137
  hasActiveProLicenceForResource: () => hasActiveProLicenceForResource,
136
138
  hasValidLicence: () => hasValidLicence,
137
139
  isAssociableResourceType: () => isAssociableResourceType,
140
+ isLiveResource: () => isLiveResource,
138
141
  isProLicence: () => isProLicence,
139
142
  isProtectedByCurrentStripeSubscription: () => isProtectedByCurrentStripeSubscription,
140
143
  isStandardLicence: () => isStandardLicence,
@@ -174,7 +177,7 @@ __export(index_exports, {
174
177
  updateAdStatuses: () => updateAdStatuses,
175
178
  updateAllEventDateTimeStatuses: () => updateAllEventDateTimeStatuses,
176
179
  updateRelationDatesToCanceled: () => updateRelationDatesToCanceled,
177
- updateSingleDateTimeStatus: () => import_cluemart_shared39.updateSingleDateTimeStatus,
180
+ updateSingleDateTimeStatus: () => import_cluemart_shared40.updateSingleDateTimeStatus,
178
181
  upgradeUserToLicence: () => upgradeUserToLicence,
179
182
  userLicenseSchema: () => userLicenseSchema,
180
183
  vendorOwnerHasProLicence: () => vendorOwnerHasProLicence,
@@ -1202,6 +1205,11 @@ var schema7 = new MongooseSchema6(
1202
1205
  type: ResourceImageTypeSchema
1203
1206
  },
1204
1207
  dateTime: [dateTimeSchema],
1208
+ deactivatedReason: {
1209
+ enum: Object.values(import_cluemart_shared9.EnumImportedMarketDeactivationReason),
1210
+ required: false,
1211
+ type: String
1212
+ },
1205
1213
  deletedAt: { default: null, required: false, type: Date },
1206
1214
  description: { required: true, type: String },
1207
1215
  earliestStartDate: { default: null, required: false, type: Date },
@@ -2095,6 +2103,14 @@ schema15.index({ "licences.licenceType": 1 });
2095
2103
  schema15.index({ promoCodes: 1, active: 1, deletedAt: 1 });
2096
2104
  schema15.index({ email: "text", firstName: "text", lastName: "text" });
2097
2105
  schema15.index({ email: 1 }, { name: "email_unique", unique: true });
2106
+ schema15.index(
2107
+ { email: 1 },
2108
+ {
2109
+ collation: { locale: "en", strength: 2 },
2110
+ name: "email_unique_normalized",
2111
+ unique: true
2112
+ }
2113
+ );
2098
2114
  schema15.index({ "associatedResources.events": 1 });
2099
2115
  schema15.index({ "associatedResources.partners": 1 });
2100
2116
  schema15.index({ "associatedResources.vendors": 1 });
@@ -4436,24 +4452,83 @@ async function updateAllEventDateTimeStatuses() {
4436
4452
  }
4437
4453
 
4438
4454
  // src/service/index.ts
4439
- var import_cluemart_shared39 = require("@timardex/cluemart-shared");
4455
+ var import_cluemart_shared40 = require("@timardex/cluemart-shared");
4440
4456
 
4441
4457
  // src/service/event/findEventOrImportedMarketById.ts
4442
- async function findEventOrImportedMarketById(resourceId) {
4443
- if (!resourceId) {
4444
- return null;
4458
+ var import_cluemart_shared32 = require("@timardex/cluemart-shared");
4459
+
4460
+ // src/service/event/resourceVisibility.ts
4461
+ var LIVE_RESOURCE_FILTER = { active: true, deletedAt: null };
4462
+ function isLiveResource(resource) {
4463
+ return resource.active === true && resource.deletedAt == null;
4464
+ }
4465
+
4466
+ // src/service/event/findEventOrImportedMarketById.ts
4467
+ var EVENT_REFERENCE_FIELDS = "_id active dateTime deletedAt name owner";
4468
+ var IMPORTED_MARKET_REFERENCE_FIELDS = "_id active dateTime deletedAt name";
4469
+ var AI_IMPORTED_MARKET_REFERENCE_FIELDS = `${IMPORTED_MARKET_REFERENCE_FIELDS} reviewStatus`;
4470
+ function isAddressableAiImport(market, includeDeleted) {
4471
+ const isApproved = market.reviewStatus === import_cluemart_shared32.EnumImportedMarketReviewStatus.APPROVED;
4472
+ return includeDeleted ? isApproved || market.deletedAt != null : isApproved && isLiveResource(market);
4473
+ }
4474
+ function pickMatch(eventDoc, googleImportedDoc, aiImportedDoc, includeDeleted) {
4475
+ if (eventDoc && (includeDeleted || isLiveResource(eventDoc))) {
4476
+ return { doc: eventDoc, kind: "event" };
4477
+ }
4478
+ if (googleImportedDoc && (includeDeleted || isLiveResource(googleImportedDoc))) {
4479
+ return { doc: googleImportedDoc, kind: "google" };
4480
+ }
4481
+ if (aiImportedDoc && isAddressableAiImport(aiImportedDoc, includeDeleted)) {
4482
+ return { doc: aiImportedDoc, kind: "ai" };
4445
4483
  }
4446
- const normalizedId = convertObjectIdsToStrings(resourceId);
4447
- const [eventDoc, googleImportedDoc, aiImportedDoc] = await Promise.all([
4448
- EventModel.findById(normalizedId).select("_id name dateTime owner").lean().exec(),
4449
- GoogleImportedMarketModel.findById(normalizedId).select("_id name dateTime").lean().exec(),
4450
- AiImportedMarketModel.findById(normalizedId).select("_id name dateTime").lean().exec()
4484
+ return null;
4485
+ }
4486
+ function normalizeLookupId(resourceId) {
4487
+ return resourceId ? convertObjectIdsToStrings(resourceId) : null;
4488
+ }
4489
+ async function findReferenceRows(normalizedId) {
4490
+ return Promise.all([
4491
+ EventModel.findById(normalizedId).select(EVENT_REFERENCE_FIELDS).lean().exec(),
4492
+ GoogleImportedMarketModel.findById(normalizedId).select(IMPORTED_MARKET_REFERENCE_FIELDS).lean().exec(),
4493
+ AiImportedMarketModel.findById(normalizedId).select(AI_IMPORTED_MARKET_REFERENCE_FIELDS).lean().exec()
4451
4494
  ]);
4452
- return eventDoc ?? googleImportedDoc ?? aiImportedDoc;
4495
+ }
4496
+ async function findDetailRows(normalizedId) {
4497
+ return Promise.all([
4498
+ EventModel.findById(normalizedId).lean().exec(),
4499
+ GoogleImportedMarketModel.findById(normalizedId).lean().exec(),
4500
+ AiImportedMarketModel.findById(normalizedId).lean().exec()
4501
+ ]);
4502
+ }
4503
+ async function findEventOrImportedMarketById(resourceId, options = {}) {
4504
+ const normalizedId = normalizeLookupId(resourceId);
4505
+ if (!normalizedId) {
4506
+ return null;
4507
+ }
4508
+ const [eventDoc, googleImportedDoc, aiImportedDoc] = await findReferenceRows(normalizedId);
4509
+ return pickMatch(
4510
+ eventDoc,
4511
+ googleImportedDoc,
4512
+ aiImportedDoc,
4513
+ options.includeDeleted ?? false
4514
+ );
4515
+ }
4516
+ async function findEventOrImportedMarketDetailsById(resourceId, options = {}) {
4517
+ const normalizedId = normalizeLookupId(resourceId);
4518
+ if (!normalizedId) {
4519
+ return null;
4520
+ }
4521
+ const [eventDoc, googleImportedDoc, aiImportedDoc] = await findDetailRows(normalizedId);
4522
+ return pickMatch(
4523
+ eventDoc,
4524
+ googleImportedDoc,
4525
+ aiImportedDoc,
4526
+ options.includeDeleted ?? false
4527
+ );
4453
4528
  }
4454
4529
 
4455
4530
  // src/service/relations.ts
4456
- var import_cluemart_shared32 = require("@timardex/cluemart-shared");
4531
+ var import_cluemart_shared33 = require("@timardex/cluemart-shared");
4457
4532
  function didRemoveAnyEventDates(previousDateTime, nextDateTime) {
4458
4533
  if (!previousDateTime?.length) {
4459
4534
  return false;
@@ -4469,8 +4544,8 @@ function didRemoveAnyStartedDates(previousDateTime, nextDateTime) {
4469
4544
  return false;
4470
4545
  }
4471
4546
  return previousDateTime.some(
4472
- (prev) => prev.dateStatus === import_cluemart_shared32.EnumEventDateStatus.STARTED && !nextDateTime?.some(
4473
- (next) => next.startDate === prev.startDate && next.startTime === prev.startTime && next.dateStatus === import_cluemart_shared32.EnumEventDateStatus.STARTED
4547
+ (prev) => prev.dateStatus === import_cluemart_shared33.EnumEventDateStatus.STARTED && !nextDateTime?.some(
4548
+ (next) => next.startDate === prev.startDate && next.startTime === prev.startTime && next.dateStatus === import_cluemart_shared33.EnumEventDateStatus.STARTED
4474
4549
  )
4475
4550
  );
4476
4551
  }
@@ -4481,7 +4556,7 @@ function updateRelationDatesToCanceled(relationDates, eventDateTime) {
4481
4556
  ) ?? false;
4482
4557
  return {
4483
4558
  ...relationDate,
4484
- status: existsInEvent ? relationDate.status : import_cluemart_shared32.EnumInviteStatus.CANCELED
4559
+ status: existsInEvent ? relationDate.status : import_cluemart_shared33.EnumInviteStatus.CANCELED
4485
4560
  };
4486
4561
  });
4487
4562
  }
@@ -4490,15 +4565,15 @@ function updateRelationDatesToCanceled(relationDates, eventDateTime) {
4490
4565
  var import_dayjs8 = __toESM(require("dayjs"));
4491
4566
 
4492
4567
  // src/service/license/compliance/utils.ts
4493
- var import_cluemart_shared37 = require("@timardex/cluemart-shared");
4568
+ var import_cluemart_shared38 = require("@timardex/cluemart-shared");
4494
4569
  var import_dayjs7 = __toESM(require("dayjs"));
4495
4570
 
4496
4571
  // src/service/license/compliance/event.ts
4497
- var import_cluemart_shared33 = require("@timardex/cluemart-shared");
4572
+ var import_cluemart_shared34 = require("@timardex/cluemart-shared");
4498
4573
  var eventLicences = [
4499
- import_cluemart_shared33.EnumUserLicence.STANDARD_EVENT,
4500
- import_cluemart_shared33.EnumUserLicence.PRO_EVENT,
4501
- import_cluemart_shared33.EnumUserLicence.PRO_PLUS_EVENT
4574
+ import_cluemart_shared34.EnumUserLicence.STANDARD_EVENT,
4575
+ import_cluemart_shared34.EnumUserLicence.PRO_EVENT,
4576
+ import_cluemart_shared34.EnumUserLicence.PRO_PLUS_EVENT
4502
4577
  ];
4503
4578
  async function handleEventLicenceCompliance(user, now) {
4504
4579
  if (!user.licences || !user.events?.length) {
@@ -4710,9 +4785,9 @@ function buildLicenceExpiryPipeline(params) {
4710
4785
  }
4711
4786
 
4712
4787
  // src/service/license/compliance/partner.ts
4713
- var import_cluemart_shared34 = require("@timardex/cluemart-shared");
4788
+ var import_cluemart_shared35 = require("@timardex/cluemart-shared");
4714
4789
  var partnerLicences = [
4715
- import_cluemart_shared34.EnumUserLicence.STANDARD_PARTNER
4790
+ import_cluemart_shared35.EnumUserLicence.STANDARD_PARTNER
4716
4791
  ];
4717
4792
  async function handlePartnerLicenceCompliance(user, now) {
4718
4793
  if (!user.licences || !user.partner) {
@@ -4722,11 +4797,11 @@ async function handlePartnerLicenceCompliance(user, now) {
4722
4797
  }
4723
4798
 
4724
4799
  // src/service/license/compliance/vendor.ts
4725
- var import_cluemart_shared36 = require("@timardex/cluemart-shared");
4800
+ var import_cluemart_shared37 = require("@timardex/cluemart-shared");
4726
4801
  var import_dayjs6 = __toESM(require("dayjs"));
4727
4802
 
4728
4803
  // src/service/license/models.ts
4729
- var import_cluemart_shared35 = require("@timardex/cluemart-shared");
4804
+ var import_cluemart_shared36 = require("@timardex/cluemart-shared");
4730
4805
  var import_dayjs5 = __toESM(require("dayjs"));
4731
4806
  var import_graphql = require("graphql");
4732
4807
  var LicenceCategory = /* @__PURE__ */ ((LicenceCategory3) => {
@@ -4738,41 +4813,41 @@ var LicenceCategory = /* @__PURE__ */ ((LicenceCategory3) => {
4738
4813
  return LicenceCategory3;
4739
4814
  })(LicenceCategory || {});
4740
4815
  var licenceCategoryMapping = {
4741
- [import_cluemart_shared35.EnumUserLicence.PRO_EVENT]: "event" /* EVENT */,
4742
- [import_cluemart_shared35.EnumUserLicence.PRO_PLUS_EVENT]: "event" /* EVENT */,
4743
- [import_cluemart_shared35.EnumUserLicence.PRO_PLUS_VENDOR]: "vendor" /* VENDOR */,
4744
- [import_cluemart_shared35.EnumUserLicence.PRO_VENDOR]: "vendor" /* VENDOR */,
4745
- [import_cluemart_shared35.EnumUserLicence.STANDARD_EVENT]: "event" /* EVENT */,
4746
- [import_cluemart_shared35.EnumUserLicence.STANDARD_PARTNER]: "partner" /* PARTNER */,
4747
- [import_cluemart_shared35.EnumUserLicence.STANDARD_VENDOR]: "vendor" /* VENDOR */,
4748
- [import_cluemart_shared35.EnumUserLicence.STANDARD_AFFILIATE]: "affiliate" /* AFFILIATE */,
4749
- [import_cluemart_shared35.EnumUserLicence.STANDARD_SCHOOL]: "school" /* SCHOOL */
4816
+ [import_cluemart_shared36.EnumUserLicence.PRO_EVENT]: "event" /* EVENT */,
4817
+ [import_cluemart_shared36.EnumUserLicence.PRO_PLUS_EVENT]: "event" /* EVENT */,
4818
+ [import_cluemart_shared36.EnumUserLicence.PRO_PLUS_VENDOR]: "vendor" /* VENDOR */,
4819
+ [import_cluemart_shared36.EnumUserLicence.PRO_VENDOR]: "vendor" /* VENDOR */,
4820
+ [import_cluemart_shared36.EnumUserLicence.STANDARD_EVENT]: "event" /* EVENT */,
4821
+ [import_cluemart_shared36.EnumUserLicence.STANDARD_PARTNER]: "partner" /* PARTNER */,
4822
+ [import_cluemart_shared36.EnumUserLicence.STANDARD_VENDOR]: "vendor" /* VENDOR */,
4823
+ [import_cluemart_shared36.EnumUserLicence.STANDARD_AFFILIATE]: "affiliate" /* AFFILIATE */,
4824
+ [import_cluemart_shared36.EnumUserLicence.STANDARD_SCHOOL]: "school" /* SCHOOL */
4750
4825
  };
4751
4826
  var licencePriority = {
4752
- [import_cluemart_shared35.EnumUserLicence.PRO_PLUS_EVENT]: 3,
4753
- [import_cluemart_shared35.EnumUserLicence.PRO_EVENT]: 2,
4754
- [import_cluemart_shared35.EnumUserLicence.STANDARD_EVENT]: 1,
4755
- [import_cluemart_shared35.EnumUserLicence.PRO_PLUS_VENDOR]: 3,
4756
- [import_cluemart_shared35.EnumUserLicence.PRO_VENDOR]: 2,
4757
- [import_cluemart_shared35.EnumUserLicence.STANDARD_VENDOR]: 1,
4758
- [import_cluemart_shared35.EnumUserLicence.STANDARD_PARTNER]: 1,
4759
- [import_cluemart_shared35.EnumUserLicence.STANDARD_AFFILIATE]: 1,
4760
- [import_cluemart_shared35.EnumUserLicence.STANDARD_SCHOOL]: 1
4827
+ [import_cluemart_shared36.EnumUserLicence.PRO_PLUS_EVENT]: 3,
4828
+ [import_cluemart_shared36.EnumUserLicence.PRO_EVENT]: 2,
4829
+ [import_cluemart_shared36.EnumUserLicence.STANDARD_EVENT]: 1,
4830
+ [import_cluemart_shared36.EnumUserLicence.PRO_PLUS_VENDOR]: 3,
4831
+ [import_cluemart_shared36.EnumUserLicence.PRO_VENDOR]: 2,
4832
+ [import_cluemart_shared36.EnumUserLicence.STANDARD_VENDOR]: 1,
4833
+ [import_cluemart_shared36.EnumUserLicence.STANDARD_PARTNER]: 1,
4834
+ [import_cluemart_shared36.EnumUserLicence.STANDARD_AFFILIATE]: 1,
4835
+ [import_cluemart_shared36.EnumUserLicence.STANDARD_SCHOOL]: 1
4761
4836
  };
4762
4837
  var standardLicences = [
4763
- import_cluemart_shared35.EnumUserLicence.STANDARD_VENDOR,
4764
- import_cluemart_shared35.EnumUserLicence.STANDARD_EVENT,
4765
- import_cluemart_shared35.EnumUserLicence.STANDARD_PARTNER
4838
+ import_cluemart_shared36.EnumUserLicence.STANDARD_VENDOR,
4839
+ import_cluemart_shared36.EnumUserLicence.STANDARD_EVENT,
4840
+ import_cluemart_shared36.EnumUserLicence.STANDARD_PARTNER
4766
4841
  ];
4767
4842
  var standardLicenceSet = new Set(standardLicences);
4768
4843
  function isStandardLicence(licence) {
4769
4844
  return standardLicenceSet.has(licence);
4770
4845
  }
4771
4846
  var proLicences = [
4772
- import_cluemart_shared35.EnumUserLicence.PRO_EVENT,
4773
- import_cluemart_shared35.EnumUserLicence.PRO_PLUS_EVENT,
4774
- import_cluemart_shared35.EnumUserLicence.PRO_VENDOR,
4775
- import_cluemart_shared35.EnumUserLicence.PRO_PLUS_VENDOR
4847
+ import_cluemart_shared36.EnumUserLicence.PRO_EVENT,
4848
+ import_cluemart_shared36.EnumUserLicence.PRO_PLUS_EVENT,
4849
+ import_cluemart_shared36.EnumUserLicence.PRO_VENDOR,
4850
+ import_cluemart_shared36.EnumUserLicence.PRO_PLUS_VENDOR
4776
4851
  ];
4777
4852
  var proLicenceSet = new Set(proLicences);
4778
4853
  function isProLicence(licence) {
@@ -4786,11 +4861,11 @@ var categoryRegexMapping = {
4786
4861
  ["school" /* SCHOOL */]: /_school$/
4787
4862
  };
4788
4863
  var categoryFallbackLicence = {
4789
- ["event" /* EVENT */]: import_cluemart_shared35.EnumUserLicence.STANDARD_EVENT,
4790
- ["partner" /* PARTNER */]: import_cluemart_shared35.EnumUserLicence.STANDARD_PARTNER,
4791
- ["vendor" /* VENDOR */]: import_cluemart_shared35.EnumUserLicence.STANDARD_VENDOR,
4792
- ["affiliate" /* AFFILIATE */]: import_cluemart_shared35.EnumUserLicence.STANDARD_AFFILIATE,
4793
- ["school" /* SCHOOL */]: import_cluemart_shared35.EnumUserLicence.STANDARD_SCHOOL
4864
+ ["event" /* EVENT */]: import_cluemart_shared36.EnumUserLicence.STANDARD_EVENT,
4865
+ ["partner" /* PARTNER */]: import_cluemart_shared36.EnumUserLicence.STANDARD_PARTNER,
4866
+ ["vendor" /* VENDOR */]: import_cluemart_shared36.EnumUserLicence.STANDARD_VENDOR,
4867
+ ["affiliate" /* AFFILIATE */]: import_cluemart_shared36.EnumUserLicence.STANDARD_AFFILIATE,
4868
+ ["school" /* SCHOOL */]: import_cluemart_shared36.EnumUserLicence.STANDARD_SCHOOL
4794
4869
  };
4795
4870
  var LicenceFilterInput = {
4796
4871
  INPUT_USER_LICENCES: "$licences"
@@ -4820,11 +4895,11 @@ function getHighestLicenceForCategory(licences, category) {
4820
4895
  function createLicenceObject(expiryDate, licenceType) {
4821
4896
  const today = (0, import_dayjs5.default)();
4822
4897
  const expiryDateMapping = {
4823
- [import_cluemart_shared35.LicenceExpiryDate.ONE_YEAR]: today.add(1, "year").endOf("day").toDate(),
4824
- [import_cluemart_shared35.LicenceExpiryDate.ONE_MONTH]: today.add(1, "month").endOf("day").toDate(),
4825
- [import_cluemart_shared35.LicenceExpiryDate.TWO_MONTHS]: today.add(2, "month").endOf("day").toDate(),
4826
- [import_cluemart_shared35.LicenceExpiryDate.THREE_MONTHS]: today.add(3, "month").endOf("day").toDate(),
4827
- [import_cluemart_shared35.LicenceExpiryDate.SIX_MONTHS]: today.add(6, "month").endOf("day").toDate()
4898
+ [import_cluemart_shared36.LicenceExpiryDate.ONE_YEAR]: today.add(1, "year").endOf("day").toDate(),
4899
+ [import_cluemart_shared36.LicenceExpiryDate.ONE_MONTH]: today.add(1, "month").endOf("day").toDate(),
4900
+ [import_cluemart_shared36.LicenceExpiryDate.TWO_MONTHS]: today.add(2, "month").endOf("day").toDate(),
4901
+ [import_cluemart_shared36.LicenceExpiryDate.THREE_MONTHS]: today.add(3, "month").endOf("day").toDate(),
4902
+ [import_cluemart_shared36.LicenceExpiryDate.SIX_MONTHS]: today.add(6, "month").endOf("day").toDate()
4828
4903
  };
4829
4904
  const licenceObject = {
4830
4905
  expiryDate: expiryDateMapping[expiryDate],
@@ -4928,13 +5003,13 @@ async function checkOwnerHasLicence({
4928
5003
  const owner = await UserModel.findById(userId);
4929
5004
  if (!owner) throw new import_graphql.GraphQLError("Owner not found");
4930
5005
  const categoryByResource = {
4931
- [import_cluemart_shared35.EnumResourceType.EVENT]: "event" /* EVENT */,
4932
- [import_cluemart_shared35.EnumResourceType.PARTNER]: "partner" /* PARTNER */,
4933
- [import_cluemart_shared35.EnumResourceType.VENDOR]: "vendor" /* VENDOR */,
4934
- [import_cluemart_shared35.EnumResourceType.AFFILIATE]: "affiliate" /* AFFILIATE */,
4935
- [import_cluemart_shared35.EnumResourceType.SCHOOL]: "school" /* SCHOOL */
5006
+ [import_cluemart_shared36.EnumResourceType.EVENT]: "event" /* EVENT */,
5007
+ [import_cluemart_shared36.EnumResourceType.PARTNER]: "partner" /* PARTNER */,
5008
+ [import_cluemart_shared36.EnumResourceType.VENDOR]: "vendor" /* VENDOR */,
5009
+ [import_cluemart_shared36.EnumResourceType.AFFILIATE]: "affiliate" /* AFFILIATE */,
5010
+ [import_cluemart_shared36.EnumResourceType.SCHOOL]: "school" /* SCHOOL */
4936
5011
  };
4937
- if (!(0, import_cluemart_shared35.isNonVisitorResourceType)(resourceType)) {
5012
+ if (!(0, import_cluemart_shared36.isNonVisitorResourceType)(resourceType)) {
4938
5013
  throw new import_graphql.GraphQLError(`Invalid resource type: ${resourceType}.`);
4939
5014
  }
4940
5015
  const requiredCategory = categoryByResource[resourceType];
@@ -4957,9 +5032,9 @@ async function checkOwnerHasLicence({
4957
5032
  }
4958
5033
  }
4959
5034
  var resourceLicenceCategory = {
4960
- [import_cluemart_shared35.EnumResourceType.EVENT]: "event" /* EVENT */,
4961
- [import_cluemart_shared35.EnumResourceType.PARTNER]: "partner" /* PARTNER */,
4962
- [import_cluemart_shared35.EnumResourceType.VENDOR]: "vendor" /* VENDOR */
5035
+ [import_cluemart_shared36.EnumResourceType.EVENT]: "event" /* EVENT */,
5036
+ [import_cluemart_shared36.EnumResourceType.PARTNER]: "partner" /* PARTNER */,
5037
+ [import_cluemart_shared36.EnumResourceType.VENDOR]: "vendor" /* VENDOR */
4963
5038
  };
4964
5039
  function isProtectedByCurrentStripeSubscription(user, licenceType, now) {
4965
5040
  const stripe = user.stripe;
@@ -4967,14 +5042,14 @@ function isProtectedByCurrentStripeSubscription(user, licenceType, now) {
4967
5042
  return false;
4968
5043
  }
4969
5044
  const gracePeriodEndsAt = stripe.paymentGracePeriodEndsAt ? (0, import_dayjs5.default)(stripe.paymentGracePeriodEndsAt) : null;
4970
- const hasActivePaymentGracePeriod = (stripe.status === import_cluemart_shared35.EnumSubscriptionStatus.PAST_DUE || stripe.status === import_cluemart_shared35.EnumSubscriptionStatus.INACTIVE) && Boolean(stripe.paymentGraceSubscriptionId) && (!stripe.subscriptionId || stripe.subscriptionId === stripe.paymentGraceSubscriptionId) && gracePeriodEndsAt !== null && gracePeriodEndsAt.isValid() && gracePeriodEndsAt.isAfter(now);
5045
+ const hasActivePaymentGracePeriod = (stripe.status === import_cluemart_shared36.EnumSubscriptionStatus.PAST_DUE || stripe.status === import_cluemart_shared36.EnumSubscriptionStatus.INACTIVE) && Boolean(stripe.paymentGraceSubscriptionId) && (!stripe.subscriptionId || stripe.subscriptionId === stripe.paymentGraceSubscriptionId) && gracePeriodEndsAt !== null && gracePeriodEndsAt.isValid() && gracePeriodEndsAt.isAfter(now);
4971
5046
  if (hasActivePaymentGracePeriod) {
4972
5047
  return true;
4973
5048
  }
4974
5049
  if (!stripe.subscriptionId) {
4975
5050
  return false;
4976
5051
  }
4977
- if (stripe.status !== import_cluemart_shared35.EnumSubscriptionStatus.ACTIVE) {
5052
+ if (stripe.status !== import_cluemart_shared36.EnumSubscriptionStatus.ACTIVE) {
4978
5053
  return false;
4979
5054
  }
4980
5055
  if (!stripe.endDate) {
@@ -5136,7 +5211,7 @@ async function applyVendorDowngrade(vendor, ownerUserId) {
5136
5211
  return (result?.matchedCount ?? 0) > 0;
5137
5212
  }
5138
5213
  async function downgradeVendorProFeatures(userId, licenceType) {
5139
- const isStandardVendor = licenceType === import_cluemart_shared36.EnumUserLicence.STANDARD_VENDOR;
5214
+ const isStandardVendor = licenceType === import_cluemart_shared37.EnumUserLicence.STANDARD_VENDOR;
5140
5215
  if (!isStandardVendor) {
5141
5216
  return;
5142
5217
  }
@@ -5183,7 +5258,7 @@ async function applyVendorRestore(vendor, ownerUserId) {
5183
5258
  return (result?.matchedCount ?? 0) > 0;
5184
5259
  }
5185
5260
  async function restoreVendorProFeatures(userId, licenceType) {
5186
- const isProVendor = licenceType === import_cluemart_shared36.EnumUserLicence.PRO_VENDOR || licenceType === import_cluemart_shared36.EnumUserLicence.PRO_PLUS_VENDOR;
5261
+ const isProVendor = licenceType === import_cluemart_shared37.EnumUserLicence.PRO_VENDOR || licenceType === import_cluemart_shared37.EnumUserLicence.PRO_PLUS_VENDOR;
5187
5262
  if (!isProVendor) {
5188
5263
  return;
5189
5264
  }
@@ -5209,7 +5284,7 @@ async function handleVendorLicenceCompliance(user, now) {
5209
5284
  return;
5210
5285
  }
5211
5286
  const proLicences2 = vendorLicencesOfUser.filter(
5212
- (licence) => licence.licenceType !== import_cluemart_shared36.EnumUserLicence.STANDARD_VENDOR
5287
+ (licence) => licence.licenceType !== import_cluemart_shared37.EnumUserLicence.STANDARD_VENDOR
5213
5288
  );
5214
5289
  const expiredProLicences = proLicences2.filter(
5215
5290
  (licence) => !(0, import_dayjs6.default)(licence.expiryDate).isAfter(now)
@@ -5222,7 +5297,7 @@ async function handleVendorLicenceCompliance(user, now) {
5222
5297
  const expiredProLicence = expiredProLicences.some(
5223
5298
  (licence) => !stripeProtectedLicenceTypes.has(licence.licenceType)
5224
5299
  );
5225
- const hasValidProLicence = stripeProtectedLicenceTypes.size > 0 || hasValidLicence(proLicences2, import_cluemart_shared36.vendorLicences, now);
5300
+ const hasValidProLicence = stripeProtectedLicenceTypes.size > 0 || hasValidLicence(proLicences2, import_cluemart_shared37.vendorLicences, now);
5226
5301
  const hasExpiredVendorLicence = vendorLicencesOfUser.some(
5227
5302
  (licence) => !(0, import_dayjs6.default)(licence.expiryDate).isAfter(now) && !stripeProtectedLicenceTypes.has(licence.licenceType)
5228
5303
  );
@@ -5238,7 +5313,7 @@ async function handleVendorLicenceCompliance(user, now) {
5238
5313
  "owner.userId": user._id
5239
5314
  }).lean().exec();
5240
5315
  }
5241
- const licencesToSync = import_cluemart_shared36.vendorLicences.filter(
5316
+ const licencesToSync = import_cluemart_shared37.vendorLicences.filter(
5242
5317
  (licenceType) => !stripeProtectedLicenceTypes.has(licenceType)
5243
5318
  );
5244
5319
  await syncUserLicencesAfterExpiry(user._id, licencesToSync, now, "downgrade");
@@ -5253,11 +5328,11 @@ async function handleVendorLicenceCompliance(user, now) {
5253
5328
  data: {
5254
5329
  resourceId: String(vendor._id),
5255
5330
  resourceName: vendor.name,
5256
- resourceType: import_cluemart_shared36.EnumNotificationResourceType.DOWNGRADED_VENDOR
5331
+ resourceType: import_cluemart_shared37.EnumNotificationResourceType.DOWNGRADED_VENDOR
5257
5332
  },
5258
5333
  message: `Your Vendor licence has been downgraded due to licence expiration.`,
5259
5334
  title: `Vendor Licence Downgraded`,
5260
- type: import_cluemart_shared36.EnumNotificationType.SYSTEM,
5335
+ type: import_cluemart_shared37.EnumNotificationType.SYSTEM,
5261
5336
  userIds: [user._id]
5262
5337
  };
5263
5338
  await sendDeactivationNotification(payload, user._id, vendor.name, "vendor");
@@ -5273,7 +5348,7 @@ async function vendorOwnerHasProLicence(vendorId) {
5273
5348
  }
5274
5349
  return hasActiveProLicenceForResource({
5275
5350
  includeStripeProtected: true,
5276
- resourceType: import_cluemart_shared36.EnumResourceType.VENDOR,
5351
+ resourceType: import_cluemart_shared37.EnumResourceType.VENDOR,
5277
5352
  userId: vendor.owner.userId
5278
5353
  });
5279
5354
  }
@@ -5285,12 +5360,12 @@ async function syncUserLicencesAfterExpiry(userId, licenceTypes, now, mode = "do
5285
5360
  const pipeline = buildLicenceExpiryPipeline({
5286
5361
  downgradeBranches: [
5287
5362
  {
5288
- case: import_cluemart_shared37.EnumUserLicence.PRO_PLUS_VENDOR,
5289
- then: import_cluemart_shared37.EnumUserLicence.STANDARD_VENDOR
5363
+ case: import_cluemart_shared38.EnumUserLicence.PRO_PLUS_VENDOR,
5364
+ then: import_cluemart_shared38.EnumUserLicence.STANDARD_VENDOR
5290
5365
  },
5291
5366
  {
5292
- case: import_cluemart_shared37.EnumUserLicence.PRO_VENDOR,
5293
- then: import_cluemart_shared37.EnumUserLicence.STANDARD_VENDOR
5367
+ case: import_cluemart_shared38.EnumUserLicence.PRO_VENDOR,
5368
+ then: import_cluemart_shared38.EnumUserLicence.STANDARD_VENDOR
5294
5369
  }
5295
5370
  ],
5296
5371
  licenceTypes,
@@ -5419,7 +5494,7 @@ var REMINDER_WINDOW_MIN_HOURS = 6.5 * 24;
5419
5494
  var REMINDER_WINDOW_MAX_HOURS = 7.5 * 24;
5420
5495
 
5421
5496
  // src/service/license/reminder/utils.ts
5422
- var import_cluemart_shared38 = require("@timardex/cluemart-shared");
5497
+ var import_cluemart_shared39 = require("@timardex/cluemart-shared");
5423
5498
  var import_utils8 = require("@timardex/cluemart-shared/utils");
5424
5499
  var import_dayjs9 = __toESM(require("dayjs"));
5425
5500
 
@@ -5485,28 +5560,28 @@ function isLicenseExpiringIn7Days(expiryDate, now) {
5485
5560
  return hoursUntilExpiry >= REMINDER_WINDOW_MIN_HOURS && hoursUntilExpiry <= REMINDER_WINDOW_MAX_HOURS;
5486
5561
  }
5487
5562
  function getLicenseName(licenceType) {
5488
- return import_cluemart_shared38.licenseNiceNames[licenceType] || licenceType;
5563
+ return import_cluemart_shared39.licenseNiceNames[licenceType] || licenceType;
5489
5564
  }
5490
5565
  function getNotificationTypes(isVendorLicense, isPartnerLicense) {
5491
5566
  if (isVendorLicense) {
5492
5567
  return {
5493
- notificationType: import_cluemart_shared38.EnumNotificationType.SYSTEM,
5494
- resourceType: import_cluemart_shared38.EnumNotificationResourceType.EXPIRATION_REMINDER_VENDOR
5568
+ notificationType: import_cluemart_shared39.EnumNotificationType.SYSTEM,
5569
+ resourceType: import_cluemart_shared39.EnumNotificationResourceType.EXPIRATION_REMINDER_VENDOR
5495
5570
  };
5496
5571
  }
5497
5572
  if (isPartnerLicense) {
5498
5573
  return {
5499
- notificationType: import_cluemart_shared38.EnumNotificationType.SYSTEM,
5500
- resourceType: import_cluemart_shared38.EnumNotificationResourceType.EXPIRATION_REMINDER_PARTNER
5574
+ notificationType: import_cluemart_shared39.EnumNotificationType.SYSTEM,
5575
+ resourceType: import_cluemart_shared39.EnumNotificationResourceType.EXPIRATION_REMINDER_PARTNER
5501
5576
  };
5502
5577
  }
5503
5578
  return {
5504
- notificationType: import_cluemart_shared38.EnumNotificationType.SYSTEM,
5505
- resourceType: import_cluemart_shared38.EnumNotificationResourceType.EXPIRATION_REMINDER_EVENT
5579
+ notificationType: import_cluemart_shared39.EnumNotificationType.SYSTEM,
5580
+ resourceType: import_cluemart_shared39.EnumNotificationResourceType.EXPIRATION_REMINDER_EVENT
5506
5581
  };
5507
5582
  }
5508
5583
  async function getLicenseResourceInfo(user, licence) {
5509
- const isVendorLicense = import_cluemart_shared38.vendorLicences.includes(licence.licenceType);
5584
+ const isVendorLicense = import_cluemart_shared39.vendorLicences.includes(licence.licenceType);
5510
5585
  const isPartnerLicense = partnerLicences.includes(licence.licenceType);
5511
5586
  const licenceName = getLicenseName(licence.licenceType);
5512
5587
  const { notificationType, resourceType } = getNotificationTypes(
@@ -5554,11 +5629,11 @@ async function getLicenseResourceInfo(user, licence) {
5554
5629
  };
5555
5630
  }
5556
5631
  function getLicenceExpiryMode(licenceType) {
5557
- return licenceType === import_cluemart_shared38.EnumUserLicence.PRO_VENDOR || licenceType === import_cluemart_shared38.EnumUserLicence.PRO_PLUS_VENDOR ? "downgrade" : "extend";
5632
+ return licenceType === import_cluemart_shared39.EnumUserLicence.PRO_VENDOR || licenceType === import_cluemart_shared39.EnumUserLicence.PRO_PLUS_VENDOR ? "downgrade" : "extend";
5558
5633
  }
5559
5634
  async function sendLicenseReminder(user, licence) {
5560
5635
  const licenceName = getLicenseName(licence.licenceType);
5561
- const expiryDate = (0, import_dayjs9.default)(licence.expiryDate).format(import_cluemart_shared38.dateFormat);
5636
+ const expiryDate = (0, import_dayjs9.default)(licence.expiryDate).format(import_cluemart_shared39.dateFormat);
5562
5637
  const userId = String(user._id);
5563
5638
  const resourceInfo = await getLicenseResourceInfo(user, licence);
5564
5639
  if (!resourceInfo) {
@@ -5714,6 +5789,7 @@ async function remindUsersAboutLicenseExpiration() {
5714
5789
  GoogleImportedMarketModel,
5715
5790
  ImpersonationAuditModel,
5716
5791
  ImpersonationSessionModel,
5792
+ LIVE_RESOURCE_FILTER,
5717
5793
  LicenceCategory,
5718
5794
  NotificationModel,
5719
5795
  OwnerTypeSchema,
@@ -5767,6 +5843,7 @@ async function remindUsersAboutLicenseExpiration() {
5767
5843
  express,
5768
5844
  findAffiliateByPromoCode,
5769
5845
  findEventOrImportedMarketById,
5846
+ findEventOrImportedMarketDetailsById,
5770
5847
  getActiveLicenceForResource,
5771
5848
  getAssociateAccessMeta,
5772
5849
  getBillingCatalogDefinition,
@@ -5788,6 +5865,7 @@ async function remindUsersAboutLicenseExpiration() {
5788
5865
  hasActiveProLicenceForResource,
5789
5866
  hasValidLicence,
5790
5867
  isAssociableResourceType,
5868
+ isLiveResource,
5791
5869
  isProLicence,
5792
5870
  isProtectedByCurrentStripeSubscription,
5793
5871
  isStandardLicence,