@timardex/cluemart-server-shared 4.2.0 → 5.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.
- package/dist/{Affiliate-CfG8ctIo.d.ts → Affiliate-CisCDggv.d.ts} +135 -4
- package/dist/{Affiliate-Bilg9mgw.d.mts → Affiliate-DfBYlDtn.d.mts} +135 -4
- package/dist/{chunk-ABW2L2HY.mjs → chunk-VM4B5D2I.mjs} +10 -1
- package/dist/chunk-VM4B5D2I.mjs.map +1 -0
- package/dist/index.cjs +167 -93
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.mts +102 -13
- package/dist/index.d.ts +102 -13
- package/dist/index.mjs +80 -9
- package/dist/index.mjs.map +1 -1
- package/dist/mongoose/index.cjs +9 -0
- package/dist/mongoose/index.cjs.map +1 -1
- package/dist/mongoose/index.d.mts +4 -135
- package/dist/mongoose/index.d.ts +4 -135
- package/dist/mongoose/index.mjs +1 -1
- package/dist/service/index.cjs +167 -93
- package/dist/service/index.cjs.map +1 -1
- package/dist/service/index.d.mts +103 -14
- package/dist/service/index.d.ts +103 -14
- package/dist/service/index.mjs +72 -10
- package/dist/service/index.mjs.map +1 -1
- package/package.json +2 -2
- package/dist/chunk-ABW2L2HY.mjs.map +0 -1
package/dist/service/index.cjs
CHANGED
|
@@ -31,6 +31,7 @@ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: tru
|
|
|
31
31
|
var service_exports = {};
|
|
32
32
|
__export(service_exports, {
|
|
33
33
|
ACTIVE_NOT_DELETED_FILTER: () => ACTIVE_NOT_DELETED_FILTER,
|
|
34
|
+
LIVE_RESOURCE_FILTER: () => LIVE_RESOURCE_FILTER,
|
|
34
35
|
LicenceCategory: () => LicenceCategory,
|
|
35
36
|
REMINDER_WINDOW_MAX_HOURS: () => REMINDER_WINDOW_MAX_HOURS,
|
|
36
37
|
REMINDER_WINDOW_MIN_HOURS: () => REMINDER_WINDOW_MIN_HOURS,
|
|
@@ -61,6 +62,7 @@ __export(service_exports, {
|
|
|
61
62
|
eventLicences: () => eventLicences,
|
|
62
63
|
findAffiliateByPromoCode: () => findAffiliateByPromoCode,
|
|
63
64
|
findEventOrImportedMarketById: () => findEventOrImportedMarketById,
|
|
65
|
+
findEventOrImportedMarketDetailsById: () => findEventOrImportedMarketDetailsById,
|
|
64
66
|
getActiveLicenceForResource: () => getActiveLicenceForResource,
|
|
65
67
|
getAssociateAccessMeta: () => getAssociateAccessMeta,
|
|
66
68
|
getEventResourceInfo: () => getEventResourceInfo,
|
|
@@ -81,6 +83,7 @@ __export(service_exports, {
|
|
|
81
83
|
hasActiveProLicenceForResource: () => hasActiveProLicenceForResource,
|
|
82
84
|
hasValidLicence: () => hasValidLicence,
|
|
83
85
|
isAssociableResourceType: () => isAssociableResourceType,
|
|
86
|
+
isLiveResource: () => isLiveResource,
|
|
84
87
|
isProLicence: () => isProLicence,
|
|
85
88
|
isProtectedByCurrentStripeSubscription: () => isProtectedByCurrentStripeSubscription,
|
|
86
89
|
isStandardLicence: () => isStandardLicence,
|
|
@@ -111,7 +114,7 @@ __export(service_exports, {
|
|
|
111
114
|
updateAdStatuses: () => updateAdStatuses,
|
|
112
115
|
updateAllEventDateTimeStatuses: () => updateAllEventDateTimeStatuses,
|
|
113
116
|
updateRelationDatesToCanceled: () => updateRelationDatesToCanceled,
|
|
114
|
-
updateSingleDateTimeStatus: () =>
|
|
117
|
+
updateSingleDateTimeStatus: () => import_cluemart_shared40.updateSingleDateTimeStatus,
|
|
115
118
|
upgradeUserToLicence: () => upgradeUserToLicence,
|
|
116
119
|
vendorOwnerHasProLicence: () => vendorOwnerHasProLicence
|
|
117
120
|
});
|
|
@@ -2007,6 +2010,15 @@ schema15.index({ "licences.expiryDate": 1 });
|
|
|
2007
2010
|
schema15.index({ "licences.licenceType": 1 });
|
|
2008
2011
|
schema15.index({ promoCodes: 1, active: 1, deletedAt: 1 });
|
|
2009
2012
|
schema15.index({ email: "text", firstName: "text", lastName: "text" });
|
|
2013
|
+
schema15.index({ email: 1 }, { name: "email_unique", unique: true });
|
|
2014
|
+
schema15.index(
|
|
2015
|
+
{ email: 1 },
|
|
2016
|
+
{
|
|
2017
|
+
collation: { locale: "en", strength: 2 },
|
|
2018
|
+
name: "email_unique_normalized",
|
|
2019
|
+
unique: true
|
|
2020
|
+
}
|
|
2021
|
+
);
|
|
2010
2022
|
schema15.index({ "associatedResources.events": 1 });
|
|
2011
2023
|
schema15.index({ "associatedResources.partners": 1 });
|
|
2012
2024
|
schema15.index({ "associatedResources.vendors": 1 });
|
|
@@ -4341,24 +4353,83 @@ async function updateAllEventDateTimeStatuses() {
|
|
|
4341
4353
|
}
|
|
4342
4354
|
|
|
4343
4355
|
// src/service/index.ts
|
|
4344
|
-
var
|
|
4356
|
+
var import_cluemart_shared40 = require("@timardex/cluemart-shared");
|
|
4345
4357
|
|
|
4346
4358
|
// src/service/event/findEventOrImportedMarketById.ts
|
|
4347
|
-
|
|
4348
|
-
|
|
4349
|
-
|
|
4359
|
+
var import_cluemart_shared32 = require("@timardex/cluemart-shared");
|
|
4360
|
+
|
|
4361
|
+
// src/service/event/resourceVisibility.ts
|
|
4362
|
+
var LIVE_RESOURCE_FILTER = { active: true, deletedAt: null };
|
|
4363
|
+
function isLiveResource(resource) {
|
|
4364
|
+
return resource.active === true && resource.deletedAt == null;
|
|
4365
|
+
}
|
|
4366
|
+
|
|
4367
|
+
// src/service/event/findEventOrImportedMarketById.ts
|
|
4368
|
+
var EVENT_REFERENCE_FIELDS = "_id active dateTime deletedAt name owner";
|
|
4369
|
+
var IMPORTED_MARKET_REFERENCE_FIELDS = "_id active dateTime deletedAt name";
|
|
4370
|
+
var AI_IMPORTED_MARKET_REFERENCE_FIELDS = `${IMPORTED_MARKET_REFERENCE_FIELDS} reviewStatus`;
|
|
4371
|
+
function isAddressableAiImport(market, includeDeleted) {
|
|
4372
|
+
const isApproved = market.reviewStatus === import_cluemart_shared32.EnumImportedMarketReviewStatus.APPROVED;
|
|
4373
|
+
return includeDeleted ? isApproved || market.deletedAt != null : isApproved && isLiveResource(market);
|
|
4374
|
+
}
|
|
4375
|
+
function pickMatch(eventDoc, googleImportedDoc, aiImportedDoc, includeDeleted) {
|
|
4376
|
+
if (eventDoc && (includeDeleted || isLiveResource(eventDoc))) {
|
|
4377
|
+
return { doc: eventDoc, kind: "event" };
|
|
4378
|
+
}
|
|
4379
|
+
if (googleImportedDoc && (includeDeleted || isLiveResource(googleImportedDoc))) {
|
|
4380
|
+
return { doc: googleImportedDoc, kind: "google" };
|
|
4381
|
+
}
|
|
4382
|
+
if (aiImportedDoc && isAddressableAiImport(aiImportedDoc, includeDeleted)) {
|
|
4383
|
+
return { doc: aiImportedDoc, kind: "ai" };
|
|
4350
4384
|
}
|
|
4351
|
-
|
|
4352
|
-
|
|
4353
|
-
|
|
4354
|
-
|
|
4355
|
-
|
|
4385
|
+
return null;
|
|
4386
|
+
}
|
|
4387
|
+
function normalizeLookupId(resourceId) {
|
|
4388
|
+
return resourceId ? convertObjectIdsToStrings(resourceId) : null;
|
|
4389
|
+
}
|
|
4390
|
+
async function findReferenceRows(normalizedId) {
|
|
4391
|
+
return Promise.all([
|
|
4392
|
+
EventModel.findById(normalizedId).select(EVENT_REFERENCE_FIELDS).lean().exec(),
|
|
4393
|
+
GoogleImportedMarketModel.findById(normalizedId).select(IMPORTED_MARKET_REFERENCE_FIELDS).lean().exec(),
|
|
4394
|
+
AiImportedMarketModel.findById(normalizedId).select(AI_IMPORTED_MARKET_REFERENCE_FIELDS).lean().exec()
|
|
4356
4395
|
]);
|
|
4357
|
-
|
|
4396
|
+
}
|
|
4397
|
+
async function findDetailRows(normalizedId) {
|
|
4398
|
+
return Promise.all([
|
|
4399
|
+
EventModel.findById(normalizedId).lean().exec(),
|
|
4400
|
+
GoogleImportedMarketModel.findById(normalizedId).lean().exec(),
|
|
4401
|
+
AiImportedMarketModel.findById(normalizedId).lean().exec()
|
|
4402
|
+
]);
|
|
4403
|
+
}
|
|
4404
|
+
async function findEventOrImportedMarketById(resourceId, options = {}) {
|
|
4405
|
+
const normalizedId = normalizeLookupId(resourceId);
|
|
4406
|
+
if (!normalizedId) {
|
|
4407
|
+
return null;
|
|
4408
|
+
}
|
|
4409
|
+
const [eventDoc, googleImportedDoc, aiImportedDoc] = await findReferenceRows(normalizedId);
|
|
4410
|
+
return pickMatch(
|
|
4411
|
+
eventDoc,
|
|
4412
|
+
googleImportedDoc,
|
|
4413
|
+
aiImportedDoc,
|
|
4414
|
+
options.includeDeleted ?? false
|
|
4415
|
+
);
|
|
4416
|
+
}
|
|
4417
|
+
async function findEventOrImportedMarketDetailsById(resourceId, options = {}) {
|
|
4418
|
+
const normalizedId = normalizeLookupId(resourceId);
|
|
4419
|
+
if (!normalizedId) {
|
|
4420
|
+
return null;
|
|
4421
|
+
}
|
|
4422
|
+
const [eventDoc, googleImportedDoc, aiImportedDoc] = await findDetailRows(normalizedId);
|
|
4423
|
+
return pickMatch(
|
|
4424
|
+
eventDoc,
|
|
4425
|
+
googleImportedDoc,
|
|
4426
|
+
aiImportedDoc,
|
|
4427
|
+
options.includeDeleted ?? false
|
|
4428
|
+
);
|
|
4358
4429
|
}
|
|
4359
4430
|
|
|
4360
4431
|
// src/service/relations.ts
|
|
4361
|
-
var
|
|
4432
|
+
var import_cluemart_shared33 = require("@timardex/cluemart-shared");
|
|
4362
4433
|
function didRemoveAnyEventDates(previousDateTime, nextDateTime) {
|
|
4363
4434
|
if (!previousDateTime?.length) {
|
|
4364
4435
|
return false;
|
|
@@ -4374,8 +4445,8 @@ function didRemoveAnyStartedDates(previousDateTime, nextDateTime) {
|
|
|
4374
4445
|
return false;
|
|
4375
4446
|
}
|
|
4376
4447
|
return previousDateTime.some(
|
|
4377
|
-
(prev) => prev.dateStatus ===
|
|
4378
|
-
(next) => next.startDate === prev.startDate && next.startTime === prev.startTime && next.dateStatus ===
|
|
4448
|
+
(prev) => prev.dateStatus === import_cluemart_shared33.EnumEventDateStatus.STARTED && !nextDateTime?.some(
|
|
4449
|
+
(next) => next.startDate === prev.startDate && next.startTime === prev.startTime && next.dateStatus === import_cluemart_shared33.EnumEventDateStatus.STARTED
|
|
4379
4450
|
)
|
|
4380
4451
|
);
|
|
4381
4452
|
}
|
|
@@ -4386,7 +4457,7 @@ function updateRelationDatesToCanceled(relationDates, eventDateTime) {
|
|
|
4386
4457
|
) ?? false;
|
|
4387
4458
|
return {
|
|
4388
4459
|
...relationDate,
|
|
4389
|
-
status: existsInEvent ? relationDate.status :
|
|
4460
|
+
status: existsInEvent ? relationDate.status : import_cluemart_shared33.EnumInviteStatus.CANCELED
|
|
4390
4461
|
};
|
|
4391
4462
|
});
|
|
4392
4463
|
}
|
|
@@ -4395,15 +4466,15 @@ function updateRelationDatesToCanceled(relationDates, eventDateTime) {
|
|
|
4395
4466
|
var import_dayjs8 = __toESM(require("dayjs"));
|
|
4396
4467
|
|
|
4397
4468
|
// src/service/license/compliance/utils.ts
|
|
4398
|
-
var
|
|
4469
|
+
var import_cluemart_shared38 = require("@timardex/cluemart-shared");
|
|
4399
4470
|
var import_dayjs7 = __toESM(require("dayjs"));
|
|
4400
4471
|
|
|
4401
4472
|
// src/service/license/compliance/event.ts
|
|
4402
|
-
var
|
|
4473
|
+
var import_cluemart_shared34 = require("@timardex/cluemart-shared");
|
|
4403
4474
|
var eventLicences = [
|
|
4404
|
-
|
|
4405
|
-
|
|
4406
|
-
|
|
4475
|
+
import_cluemart_shared34.EnumUserLicence.STANDARD_EVENT,
|
|
4476
|
+
import_cluemart_shared34.EnumUserLicence.PRO_EVENT,
|
|
4477
|
+
import_cluemart_shared34.EnumUserLicence.PRO_PLUS_EVENT
|
|
4407
4478
|
];
|
|
4408
4479
|
async function handleEventLicenceCompliance(user, now) {
|
|
4409
4480
|
if (!user.licences || !user.events?.length) {
|
|
@@ -4615,9 +4686,9 @@ function buildLicenceExpiryPipeline(params) {
|
|
|
4615
4686
|
}
|
|
4616
4687
|
|
|
4617
4688
|
// src/service/license/compliance/partner.ts
|
|
4618
|
-
var
|
|
4689
|
+
var import_cluemart_shared35 = require("@timardex/cluemart-shared");
|
|
4619
4690
|
var partnerLicences = [
|
|
4620
|
-
|
|
4691
|
+
import_cluemart_shared35.EnumUserLicence.STANDARD_PARTNER
|
|
4621
4692
|
];
|
|
4622
4693
|
async function handlePartnerLicenceCompliance(user, now) {
|
|
4623
4694
|
if (!user.licences || !user.partner) {
|
|
@@ -4627,11 +4698,11 @@ async function handlePartnerLicenceCompliance(user, now) {
|
|
|
4627
4698
|
}
|
|
4628
4699
|
|
|
4629
4700
|
// src/service/license/compliance/vendor.ts
|
|
4630
|
-
var
|
|
4701
|
+
var import_cluemart_shared37 = require("@timardex/cluemart-shared");
|
|
4631
4702
|
var import_dayjs6 = __toESM(require("dayjs"));
|
|
4632
4703
|
|
|
4633
4704
|
// src/service/license/models.ts
|
|
4634
|
-
var
|
|
4705
|
+
var import_cluemart_shared36 = require("@timardex/cluemart-shared");
|
|
4635
4706
|
var import_dayjs5 = __toESM(require("dayjs"));
|
|
4636
4707
|
var import_graphql = require("graphql");
|
|
4637
4708
|
var LicenceCategory = /* @__PURE__ */ ((LicenceCategory3) => {
|
|
@@ -4643,41 +4714,41 @@ var LicenceCategory = /* @__PURE__ */ ((LicenceCategory3) => {
|
|
|
4643
4714
|
return LicenceCategory3;
|
|
4644
4715
|
})(LicenceCategory || {});
|
|
4645
4716
|
var licenceCategoryMapping = {
|
|
4646
|
-
[
|
|
4647
|
-
[
|
|
4648
|
-
[
|
|
4649
|
-
[
|
|
4650
|
-
[
|
|
4651
|
-
[
|
|
4652
|
-
[
|
|
4653
|
-
[
|
|
4654
|
-
[
|
|
4717
|
+
[import_cluemart_shared36.EnumUserLicence.PRO_EVENT]: "event" /* EVENT */,
|
|
4718
|
+
[import_cluemart_shared36.EnumUserLicence.PRO_PLUS_EVENT]: "event" /* EVENT */,
|
|
4719
|
+
[import_cluemart_shared36.EnumUserLicence.PRO_PLUS_VENDOR]: "vendor" /* VENDOR */,
|
|
4720
|
+
[import_cluemart_shared36.EnumUserLicence.PRO_VENDOR]: "vendor" /* VENDOR */,
|
|
4721
|
+
[import_cluemart_shared36.EnumUserLicence.STANDARD_EVENT]: "event" /* EVENT */,
|
|
4722
|
+
[import_cluemart_shared36.EnumUserLicence.STANDARD_PARTNER]: "partner" /* PARTNER */,
|
|
4723
|
+
[import_cluemart_shared36.EnumUserLicence.STANDARD_VENDOR]: "vendor" /* VENDOR */,
|
|
4724
|
+
[import_cluemart_shared36.EnumUserLicence.STANDARD_AFFILIATE]: "affiliate" /* AFFILIATE */,
|
|
4725
|
+
[import_cluemart_shared36.EnumUserLicence.STANDARD_SCHOOL]: "school" /* SCHOOL */
|
|
4655
4726
|
};
|
|
4656
4727
|
var licencePriority = {
|
|
4657
|
-
[
|
|
4658
|
-
[
|
|
4659
|
-
[
|
|
4660
|
-
[
|
|
4661
|
-
[
|
|
4662
|
-
[
|
|
4663
|
-
[
|
|
4664
|
-
[
|
|
4665
|
-
[
|
|
4728
|
+
[import_cluemart_shared36.EnumUserLicence.PRO_PLUS_EVENT]: 3,
|
|
4729
|
+
[import_cluemart_shared36.EnumUserLicence.PRO_EVENT]: 2,
|
|
4730
|
+
[import_cluemart_shared36.EnumUserLicence.STANDARD_EVENT]: 1,
|
|
4731
|
+
[import_cluemart_shared36.EnumUserLicence.PRO_PLUS_VENDOR]: 3,
|
|
4732
|
+
[import_cluemart_shared36.EnumUserLicence.PRO_VENDOR]: 2,
|
|
4733
|
+
[import_cluemart_shared36.EnumUserLicence.STANDARD_VENDOR]: 1,
|
|
4734
|
+
[import_cluemart_shared36.EnumUserLicence.STANDARD_PARTNER]: 1,
|
|
4735
|
+
[import_cluemart_shared36.EnumUserLicence.STANDARD_AFFILIATE]: 1,
|
|
4736
|
+
[import_cluemart_shared36.EnumUserLicence.STANDARD_SCHOOL]: 1
|
|
4666
4737
|
};
|
|
4667
4738
|
var standardLicences = [
|
|
4668
|
-
|
|
4669
|
-
|
|
4670
|
-
|
|
4739
|
+
import_cluemart_shared36.EnumUserLicence.STANDARD_VENDOR,
|
|
4740
|
+
import_cluemart_shared36.EnumUserLicence.STANDARD_EVENT,
|
|
4741
|
+
import_cluemart_shared36.EnumUserLicence.STANDARD_PARTNER
|
|
4671
4742
|
];
|
|
4672
4743
|
var standardLicenceSet = new Set(standardLicences);
|
|
4673
4744
|
function isStandardLicence(licence) {
|
|
4674
4745
|
return standardLicenceSet.has(licence);
|
|
4675
4746
|
}
|
|
4676
4747
|
var proLicences = [
|
|
4677
|
-
|
|
4678
|
-
|
|
4679
|
-
|
|
4680
|
-
|
|
4748
|
+
import_cluemart_shared36.EnumUserLicence.PRO_EVENT,
|
|
4749
|
+
import_cluemart_shared36.EnumUserLicence.PRO_PLUS_EVENT,
|
|
4750
|
+
import_cluemart_shared36.EnumUserLicence.PRO_VENDOR,
|
|
4751
|
+
import_cluemart_shared36.EnumUserLicence.PRO_PLUS_VENDOR
|
|
4681
4752
|
];
|
|
4682
4753
|
var proLicenceSet = new Set(proLicences);
|
|
4683
4754
|
function isProLicence(licence) {
|
|
@@ -4691,11 +4762,11 @@ var categoryRegexMapping = {
|
|
|
4691
4762
|
["school" /* SCHOOL */]: /_school$/
|
|
4692
4763
|
};
|
|
4693
4764
|
var categoryFallbackLicence = {
|
|
4694
|
-
["event" /* EVENT */]:
|
|
4695
|
-
["partner" /* PARTNER */]:
|
|
4696
|
-
["vendor" /* VENDOR */]:
|
|
4697
|
-
["affiliate" /* AFFILIATE */]:
|
|
4698
|
-
["school" /* SCHOOL */]:
|
|
4765
|
+
["event" /* EVENT */]: import_cluemart_shared36.EnumUserLicence.STANDARD_EVENT,
|
|
4766
|
+
["partner" /* PARTNER */]: import_cluemart_shared36.EnumUserLicence.STANDARD_PARTNER,
|
|
4767
|
+
["vendor" /* VENDOR */]: import_cluemart_shared36.EnumUserLicence.STANDARD_VENDOR,
|
|
4768
|
+
["affiliate" /* AFFILIATE */]: import_cluemart_shared36.EnumUserLicence.STANDARD_AFFILIATE,
|
|
4769
|
+
["school" /* SCHOOL */]: import_cluemart_shared36.EnumUserLicence.STANDARD_SCHOOL
|
|
4699
4770
|
};
|
|
4700
4771
|
var LicenceFilterInput = {
|
|
4701
4772
|
INPUT_USER_LICENCES: "$licences"
|
|
@@ -4725,11 +4796,11 @@ function getHighestLicenceForCategory(licences, category) {
|
|
|
4725
4796
|
function createLicenceObject(expiryDate, licenceType) {
|
|
4726
4797
|
const today = (0, import_dayjs5.default)();
|
|
4727
4798
|
const expiryDateMapping = {
|
|
4728
|
-
[
|
|
4729
|
-
[
|
|
4730
|
-
[
|
|
4731
|
-
[
|
|
4732
|
-
[
|
|
4799
|
+
[import_cluemart_shared36.LicenceExpiryDate.ONE_YEAR]: today.add(1, "year").endOf("day").toDate(),
|
|
4800
|
+
[import_cluemart_shared36.LicenceExpiryDate.ONE_MONTH]: today.add(1, "month").endOf("day").toDate(),
|
|
4801
|
+
[import_cluemart_shared36.LicenceExpiryDate.TWO_MONTHS]: today.add(2, "month").endOf("day").toDate(),
|
|
4802
|
+
[import_cluemart_shared36.LicenceExpiryDate.THREE_MONTHS]: today.add(3, "month").endOf("day").toDate(),
|
|
4803
|
+
[import_cluemart_shared36.LicenceExpiryDate.SIX_MONTHS]: today.add(6, "month").endOf("day").toDate()
|
|
4733
4804
|
};
|
|
4734
4805
|
const licenceObject = {
|
|
4735
4806
|
expiryDate: expiryDateMapping[expiryDate],
|
|
@@ -4833,13 +4904,13 @@ async function checkOwnerHasLicence({
|
|
|
4833
4904
|
const owner = await UserModel.findById(userId);
|
|
4834
4905
|
if (!owner) throw new import_graphql.GraphQLError("Owner not found");
|
|
4835
4906
|
const categoryByResource = {
|
|
4836
|
-
[
|
|
4837
|
-
[
|
|
4838
|
-
[
|
|
4839
|
-
[
|
|
4840
|
-
[
|
|
4907
|
+
[import_cluemart_shared36.EnumResourceType.EVENT]: "event" /* EVENT */,
|
|
4908
|
+
[import_cluemart_shared36.EnumResourceType.PARTNER]: "partner" /* PARTNER */,
|
|
4909
|
+
[import_cluemart_shared36.EnumResourceType.VENDOR]: "vendor" /* VENDOR */,
|
|
4910
|
+
[import_cluemart_shared36.EnumResourceType.AFFILIATE]: "affiliate" /* AFFILIATE */,
|
|
4911
|
+
[import_cluemart_shared36.EnumResourceType.SCHOOL]: "school" /* SCHOOL */
|
|
4841
4912
|
};
|
|
4842
|
-
if (!(0,
|
|
4913
|
+
if (!(0, import_cluemart_shared36.isNonVisitorResourceType)(resourceType)) {
|
|
4843
4914
|
throw new import_graphql.GraphQLError(`Invalid resource type: ${resourceType}.`);
|
|
4844
4915
|
}
|
|
4845
4916
|
const requiredCategory = categoryByResource[resourceType];
|
|
@@ -4862,9 +4933,9 @@ async function checkOwnerHasLicence({
|
|
|
4862
4933
|
}
|
|
4863
4934
|
}
|
|
4864
4935
|
var resourceLicenceCategory = {
|
|
4865
|
-
[
|
|
4866
|
-
[
|
|
4867
|
-
[
|
|
4936
|
+
[import_cluemart_shared36.EnumResourceType.EVENT]: "event" /* EVENT */,
|
|
4937
|
+
[import_cluemart_shared36.EnumResourceType.PARTNER]: "partner" /* PARTNER */,
|
|
4938
|
+
[import_cluemart_shared36.EnumResourceType.VENDOR]: "vendor" /* VENDOR */
|
|
4868
4939
|
};
|
|
4869
4940
|
function isProtectedByCurrentStripeSubscription(user, licenceType, now) {
|
|
4870
4941
|
const stripe = user.stripe;
|
|
@@ -4872,14 +4943,14 @@ function isProtectedByCurrentStripeSubscription(user, licenceType, now) {
|
|
|
4872
4943
|
return false;
|
|
4873
4944
|
}
|
|
4874
4945
|
const gracePeriodEndsAt = stripe.paymentGracePeriodEndsAt ? (0, import_dayjs5.default)(stripe.paymentGracePeriodEndsAt) : null;
|
|
4875
|
-
const hasActivePaymentGracePeriod = (stripe.status ===
|
|
4946
|
+
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);
|
|
4876
4947
|
if (hasActivePaymentGracePeriod) {
|
|
4877
4948
|
return true;
|
|
4878
4949
|
}
|
|
4879
4950
|
if (!stripe.subscriptionId) {
|
|
4880
4951
|
return false;
|
|
4881
4952
|
}
|
|
4882
|
-
if (stripe.status !==
|
|
4953
|
+
if (stripe.status !== import_cluemart_shared36.EnumSubscriptionStatus.ACTIVE) {
|
|
4883
4954
|
return false;
|
|
4884
4955
|
}
|
|
4885
4956
|
if (!stripe.endDate) {
|
|
@@ -5041,7 +5112,7 @@ async function applyVendorDowngrade(vendor, ownerUserId) {
|
|
|
5041
5112
|
return (result?.matchedCount ?? 0) > 0;
|
|
5042
5113
|
}
|
|
5043
5114
|
async function downgradeVendorProFeatures(userId, licenceType) {
|
|
5044
|
-
const isStandardVendor = licenceType ===
|
|
5115
|
+
const isStandardVendor = licenceType === import_cluemart_shared37.EnumUserLicence.STANDARD_VENDOR;
|
|
5045
5116
|
if (!isStandardVendor) {
|
|
5046
5117
|
return;
|
|
5047
5118
|
}
|
|
@@ -5088,7 +5159,7 @@ async function applyVendorRestore(vendor, ownerUserId) {
|
|
|
5088
5159
|
return (result?.matchedCount ?? 0) > 0;
|
|
5089
5160
|
}
|
|
5090
5161
|
async function restoreVendorProFeatures(userId, licenceType) {
|
|
5091
|
-
const isProVendor = licenceType ===
|
|
5162
|
+
const isProVendor = licenceType === import_cluemart_shared37.EnumUserLicence.PRO_VENDOR || licenceType === import_cluemart_shared37.EnumUserLicence.PRO_PLUS_VENDOR;
|
|
5092
5163
|
if (!isProVendor) {
|
|
5093
5164
|
return;
|
|
5094
5165
|
}
|
|
@@ -5114,7 +5185,7 @@ async function handleVendorLicenceCompliance(user, now) {
|
|
|
5114
5185
|
return;
|
|
5115
5186
|
}
|
|
5116
5187
|
const proLicences2 = vendorLicencesOfUser.filter(
|
|
5117
|
-
(licence) => licence.licenceType !==
|
|
5188
|
+
(licence) => licence.licenceType !== import_cluemart_shared37.EnumUserLicence.STANDARD_VENDOR
|
|
5118
5189
|
);
|
|
5119
5190
|
const expiredProLicences = proLicences2.filter(
|
|
5120
5191
|
(licence) => !(0, import_dayjs6.default)(licence.expiryDate).isAfter(now)
|
|
@@ -5127,7 +5198,7 @@ async function handleVendorLicenceCompliance(user, now) {
|
|
|
5127
5198
|
const expiredProLicence = expiredProLicences.some(
|
|
5128
5199
|
(licence) => !stripeProtectedLicenceTypes.has(licence.licenceType)
|
|
5129
5200
|
);
|
|
5130
|
-
const hasValidProLicence = stripeProtectedLicenceTypes.size > 0 || hasValidLicence(proLicences2,
|
|
5201
|
+
const hasValidProLicence = stripeProtectedLicenceTypes.size > 0 || hasValidLicence(proLicences2, import_cluemart_shared37.vendorLicences, now);
|
|
5131
5202
|
const hasExpiredVendorLicence = vendorLicencesOfUser.some(
|
|
5132
5203
|
(licence) => !(0, import_dayjs6.default)(licence.expiryDate).isAfter(now) && !stripeProtectedLicenceTypes.has(licence.licenceType)
|
|
5133
5204
|
);
|
|
@@ -5143,7 +5214,7 @@ async function handleVendorLicenceCompliance(user, now) {
|
|
|
5143
5214
|
"owner.userId": user._id
|
|
5144
5215
|
}).lean().exec();
|
|
5145
5216
|
}
|
|
5146
|
-
const licencesToSync =
|
|
5217
|
+
const licencesToSync = import_cluemart_shared37.vendorLicences.filter(
|
|
5147
5218
|
(licenceType) => !stripeProtectedLicenceTypes.has(licenceType)
|
|
5148
5219
|
);
|
|
5149
5220
|
await syncUserLicencesAfterExpiry(user._id, licencesToSync, now, "downgrade");
|
|
@@ -5158,11 +5229,11 @@ async function handleVendorLicenceCompliance(user, now) {
|
|
|
5158
5229
|
data: {
|
|
5159
5230
|
resourceId: String(vendor._id),
|
|
5160
5231
|
resourceName: vendor.name,
|
|
5161
|
-
resourceType:
|
|
5232
|
+
resourceType: import_cluemart_shared37.EnumNotificationResourceType.DOWNGRADED_VENDOR
|
|
5162
5233
|
},
|
|
5163
5234
|
message: `Your Vendor licence has been downgraded due to licence expiration.`,
|
|
5164
5235
|
title: `Vendor Licence Downgraded`,
|
|
5165
|
-
type:
|
|
5236
|
+
type: import_cluemart_shared37.EnumNotificationType.SYSTEM,
|
|
5166
5237
|
userIds: [user._id]
|
|
5167
5238
|
};
|
|
5168
5239
|
await sendDeactivationNotification(payload, user._id, vendor.name, "vendor");
|
|
@@ -5178,7 +5249,7 @@ async function vendorOwnerHasProLicence(vendorId) {
|
|
|
5178
5249
|
}
|
|
5179
5250
|
return hasActiveProLicenceForResource({
|
|
5180
5251
|
includeStripeProtected: true,
|
|
5181
|
-
resourceType:
|
|
5252
|
+
resourceType: import_cluemart_shared37.EnumResourceType.VENDOR,
|
|
5182
5253
|
userId: vendor.owner.userId
|
|
5183
5254
|
});
|
|
5184
5255
|
}
|
|
@@ -5190,12 +5261,12 @@ async function syncUserLicencesAfterExpiry(userId, licenceTypes, now, mode = "do
|
|
|
5190
5261
|
const pipeline = buildLicenceExpiryPipeline({
|
|
5191
5262
|
downgradeBranches: [
|
|
5192
5263
|
{
|
|
5193
|
-
case:
|
|
5194
|
-
then:
|
|
5264
|
+
case: import_cluemart_shared38.EnumUserLicence.PRO_PLUS_VENDOR,
|
|
5265
|
+
then: import_cluemart_shared38.EnumUserLicence.STANDARD_VENDOR
|
|
5195
5266
|
},
|
|
5196
5267
|
{
|
|
5197
|
-
case:
|
|
5198
|
-
then:
|
|
5268
|
+
case: import_cluemart_shared38.EnumUserLicence.PRO_VENDOR,
|
|
5269
|
+
then: import_cluemart_shared38.EnumUserLicence.STANDARD_VENDOR
|
|
5199
5270
|
}
|
|
5200
5271
|
],
|
|
5201
5272
|
licenceTypes,
|
|
@@ -5324,7 +5395,7 @@ var REMINDER_WINDOW_MIN_HOURS = 6.5 * 24;
|
|
|
5324
5395
|
var REMINDER_WINDOW_MAX_HOURS = 7.5 * 24;
|
|
5325
5396
|
|
|
5326
5397
|
// src/service/license/reminder/utils.ts
|
|
5327
|
-
var
|
|
5398
|
+
var import_cluemart_shared39 = require("@timardex/cluemart-shared");
|
|
5328
5399
|
var import_utils8 = require("@timardex/cluemart-shared/utils");
|
|
5329
5400
|
var import_dayjs9 = __toESM(require("dayjs"));
|
|
5330
5401
|
|
|
@@ -5390,28 +5461,28 @@ function isLicenseExpiringIn7Days(expiryDate, now) {
|
|
|
5390
5461
|
return hoursUntilExpiry >= REMINDER_WINDOW_MIN_HOURS && hoursUntilExpiry <= REMINDER_WINDOW_MAX_HOURS;
|
|
5391
5462
|
}
|
|
5392
5463
|
function getLicenseName(licenceType) {
|
|
5393
|
-
return
|
|
5464
|
+
return import_cluemart_shared39.licenseNiceNames[licenceType] || licenceType;
|
|
5394
5465
|
}
|
|
5395
5466
|
function getNotificationTypes(isVendorLicense, isPartnerLicense) {
|
|
5396
5467
|
if (isVendorLicense) {
|
|
5397
5468
|
return {
|
|
5398
|
-
notificationType:
|
|
5399
|
-
resourceType:
|
|
5469
|
+
notificationType: import_cluemart_shared39.EnumNotificationType.SYSTEM,
|
|
5470
|
+
resourceType: import_cluemart_shared39.EnumNotificationResourceType.EXPIRATION_REMINDER_VENDOR
|
|
5400
5471
|
};
|
|
5401
5472
|
}
|
|
5402
5473
|
if (isPartnerLicense) {
|
|
5403
5474
|
return {
|
|
5404
|
-
notificationType:
|
|
5405
|
-
resourceType:
|
|
5475
|
+
notificationType: import_cluemart_shared39.EnumNotificationType.SYSTEM,
|
|
5476
|
+
resourceType: import_cluemart_shared39.EnumNotificationResourceType.EXPIRATION_REMINDER_PARTNER
|
|
5406
5477
|
};
|
|
5407
5478
|
}
|
|
5408
5479
|
return {
|
|
5409
|
-
notificationType:
|
|
5410
|
-
resourceType:
|
|
5480
|
+
notificationType: import_cluemart_shared39.EnumNotificationType.SYSTEM,
|
|
5481
|
+
resourceType: import_cluemart_shared39.EnumNotificationResourceType.EXPIRATION_REMINDER_EVENT
|
|
5411
5482
|
};
|
|
5412
5483
|
}
|
|
5413
5484
|
async function getLicenseResourceInfo(user, licence) {
|
|
5414
|
-
const isVendorLicense =
|
|
5485
|
+
const isVendorLicense = import_cluemart_shared39.vendorLicences.includes(licence.licenceType);
|
|
5415
5486
|
const isPartnerLicense = partnerLicences.includes(licence.licenceType);
|
|
5416
5487
|
const licenceName = getLicenseName(licence.licenceType);
|
|
5417
5488
|
const { notificationType, resourceType } = getNotificationTypes(
|
|
@@ -5459,11 +5530,11 @@ async function getLicenseResourceInfo(user, licence) {
|
|
|
5459
5530
|
};
|
|
5460
5531
|
}
|
|
5461
5532
|
function getLicenceExpiryMode(licenceType) {
|
|
5462
|
-
return licenceType ===
|
|
5533
|
+
return licenceType === import_cluemart_shared39.EnumUserLicence.PRO_VENDOR || licenceType === import_cluemart_shared39.EnumUserLicence.PRO_PLUS_VENDOR ? "downgrade" : "extend";
|
|
5463
5534
|
}
|
|
5464
5535
|
async function sendLicenseReminder(user, licence) {
|
|
5465
5536
|
const licenceName = getLicenseName(licence.licenceType);
|
|
5466
|
-
const expiryDate = (0, import_dayjs9.default)(licence.expiryDate).format(
|
|
5537
|
+
const expiryDate = (0, import_dayjs9.default)(licence.expiryDate).format(import_cluemart_shared39.dateFormat);
|
|
5467
5538
|
const userId = String(user._id);
|
|
5468
5539
|
const resourceInfo = await getLicenseResourceInfo(user, licence);
|
|
5469
5540
|
if (!resourceInfo) {
|
|
@@ -5589,6 +5660,7 @@ async function remindUsersAboutLicenseExpiration() {
|
|
|
5589
5660
|
// Annotate the CommonJS export names for ESM import in node:
|
|
5590
5661
|
0 && (module.exports = {
|
|
5591
5662
|
ACTIVE_NOT_DELETED_FILTER,
|
|
5663
|
+
LIVE_RESOURCE_FILTER,
|
|
5592
5664
|
LicenceCategory,
|
|
5593
5665
|
REMINDER_WINDOW_MAX_HOURS,
|
|
5594
5666
|
REMINDER_WINDOW_MIN_HOURS,
|
|
@@ -5619,6 +5691,7 @@ async function remindUsersAboutLicenseExpiration() {
|
|
|
5619
5691
|
eventLicences,
|
|
5620
5692
|
findAffiliateByPromoCode,
|
|
5621
5693
|
findEventOrImportedMarketById,
|
|
5694
|
+
findEventOrImportedMarketDetailsById,
|
|
5622
5695
|
getActiveLicenceForResource,
|
|
5623
5696
|
getAssociateAccessMeta,
|
|
5624
5697
|
getEventResourceInfo,
|
|
@@ -5639,6 +5712,7 @@ async function remindUsersAboutLicenseExpiration() {
|
|
|
5639
5712
|
hasActiveProLicenceForResource,
|
|
5640
5713
|
hasValidLicence,
|
|
5641
5714
|
isAssociableResourceType,
|
|
5715
|
+
isLiveResource,
|
|
5642
5716
|
isProLicence,
|
|
5643
5717
|
isProtectedByCurrentStripeSubscription,
|
|
5644
5718
|
isStandardLicence,
|