@timardex/cluemart-server-shared 4.2.1 → 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-HHATQITH.mjs → chunk-VM4B5D2I.mjs} +9 -1
- package/dist/chunk-VM4B5D2I.mjs.map +1 -0
- package/dist/index.cjs +166 -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 +79 -9
- package/dist/index.mjs.map +1 -1
- package/dist/mongoose/index.cjs +8 -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 +166 -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-HHATQITH.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
|
});
|
|
@@ -2008,6 +2011,14 @@ 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" });
|
|
2010
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
|
+
);
|
|
2011
2022
|
schema15.index({ "associatedResources.events": 1 });
|
|
2012
2023
|
schema15.index({ "associatedResources.partners": 1 });
|
|
2013
2024
|
schema15.index({ "associatedResources.vendors": 1 });
|
|
@@ -4342,24 +4353,83 @@ async function updateAllEventDateTimeStatuses() {
|
|
|
4342
4353
|
}
|
|
4343
4354
|
|
|
4344
4355
|
// src/service/index.ts
|
|
4345
|
-
var
|
|
4356
|
+
var import_cluemart_shared40 = require("@timardex/cluemart-shared");
|
|
4346
4357
|
|
|
4347
4358
|
// src/service/event/findEventOrImportedMarketById.ts
|
|
4348
|
-
|
|
4349
|
-
|
|
4350
|
-
|
|
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" };
|
|
4351
4384
|
}
|
|
4352
|
-
|
|
4353
|
-
|
|
4354
|
-
|
|
4355
|
-
|
|
4356
|
-
|
|
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()
|
|
4357
4395
|
]);
|
|
4358
|
-
|
|
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
|
+
);
|
|
4359
4429
|
}
|
|
4360
4430
|
|
|
4361
4431
|
// src/service/relations.ts
|
|
4362
|
-
var
|
|
4432
|
+
var import_cluemart_shared33 = require("@timardex/cluemart-shared");
|
|
4363
4433
|
function didRemoveAnyEventDates(previousDateTime, nextDateTime) {
|
|
4364
4434
|
if (!previousDateTime?.length) {
|
|
4365
4435
|
return false;
|
|
@@ -4375,8 +4445,8 @@ function didRemoveAnyStartedDates(previousDateTime, nextDateTime) {
|
|
|
4375
4445
|
return false;
|
|
4376
4446
|
}
|
|
4377
4447
|
return previousDateTime.some(
|
|
4378
|
-
(prev) => prev.dateStatus ===
|
|
4379
|
-
(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
|
|
4380
4450
|
)
|
|
4381
4451
|
);
|
|
4382
4452
|
}
|
|
@@ -4387,7 +4457,7 @@ function updateRelationDatesToCanceled(relationDates, eventDateTime) {
|
|
|
4387
4457
|
) ?? false;
|
|
4388
4458
|
return {
|
|
4389
4459
|
...relationDate,
|
|
4390
|
-
status: existsInEvent ? relationDate.status :
|
|
4460
|
+
status: existsInEvent ? relationDate.status : import_cluemart_shared33.EnumInviteStatus.CANCELED
|
|
4391
4461
|
};
|
|
4392
4462
|
});
|
|
4393
4463
|
}
|
|
@@ -4396,15 +4466,15 @@ function updateRelationDatesToCanceled(relationDates, eventDateTime) {
|
|
|
4396
4466
|
var import_dayjs8 = __toESM(require("dayjs"));
|
|
4397
4467
|
|
|
4398
4468
|
// src/service/license/compliance/utils.ts
|
|
4399
|
-
var
|
|
4469
|
+
var import_cluemart_shared38 = require("@timardex/cluemart-shared");
|
|
4400
4470
|
var import_dayjs7 = __toESM(require("dayjs"));
|
|
4401
4471
|
|
|
4402
4472
|
// src/service/license/compliance/event.ts
|
|
4403
|
-
var
|
|
4473
|
+
var import_cluemart_shared34 = require("@timardex/cluemart-shared");
|
|
4404
4474
|
var eventLicences = [
|
|
4405
|
-
|
|
4406
|
-
|
|
4407
|
-
|
|
4475
|
+
import_cluemart_shared34.EnumUserLicence.STANDARD_EVENT,
|
|
4476
|
+
import_cluemart_shared34.EnumUserLicence.PRO_EVENT,
|
|
4477
|
+
import_cluemart_shared34.EnumUserLicence.PRO_PLUS_EVENT
|
|
4408
4478
|
];
|
|
4409
4479
|
async function handleEventLicenceCompliance(user, now) {
|
|
4410
4480
|
if (!user.licences || !user.events?.length) {
|
|
@@ -4616,9 +4686,9 @@ function buildLicenceExpiryPipeline(params) {
|
|
|
4616
4686
|
}
|
|
4617
4687
|
|
|
4618
4688
|
// src/service/license/compliance/partner.ts
|
|
4619
|
-
var
|
|
4689
|
+
var import_cluemart_shared35 = require("@timardex/cluemart-shared");
|
|
4620
4690
|
var partnerLicences = [
|
|
4621
|
-
|
|
4691
|
+
import_cluemart_shared35.EnumUserLicence.STANDARD_PARTNER
|
|
4622
4692
|
];
|
|
4623
4693
|
async function handlePartnerLicenceCompliance(user, now) {
|
|
4624
4694
|
if (!user.licences || !user.partner) {
|
|
@@ -4628,11 +4698,11 @@ async function handlePartnerLicenceCompliance(user, now) {
|
|
|
4628
4698
|
}
|
|
4629
4699
|
|
|
4630
4700
|
// src/service/license/compliance/vendor.ts
|
|
4631
|
-
var
|
|
4701
|
+
var import_cluemart_shared37 = require("@timardex/cluemart-shared");
|
|
4632
4702
|
var import_dayjs6 = __toESM(require("dayjs"));
|
|
4633
4703
|
|
|
4634
4704
|
// src/service/license/models.ts
|
|
4635
|
-
var
|
|
4705
|
+
var import_cluemart_shared36 = require("@timardex/cluemart-shared");
|
|
4636
4706
|
var import_dayjs5 = __toESM(require("dayjs"));
|
|
4637
4707
|
var import_graphql = require("graphql");
|
|
4638
4708
|
var LicenceCategory = /* @__PURE__ */ ((LicenceCategory3) => {
|
|
@@ -4644,41 +4714,41 @@ var LicenceCategory = /* @__PURE__ */ ((LicenceCategory3) => {
|
|
|
4644
4714
|
return LicenceCategory3;
|
|
4645
4715
|
})(LicenceCategory || {});
|
|
4646
4716
|
var licenceCategoryMapping = {
|
|
4647
|
-
[
|
|
4648
|
-
[
|
|
4649
|
-
[
|
|
4650
|
-
[
|
|
4651
|
-
[
|
|
4652
|
-
[
|
|
4653
|
-
[
|
|
4654
|
-
[
|
|
4655
|
-
[
|
|
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 */
|
|
4656
4726
|
};
|
|
4657
4727
|
var licencePriority = {
|
|
4658
|
-
[
|
|
4659
|
-
[
|
|
4660
|
-
[
|
|
4661
|
-
[
|
|
4662
|
-
[
|
|
4663
|
-
[
|
|
4664
|
-
[
|
|
4665
|
-
[
|
|
4666
|
-
[
|
|
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
|
|
4667
4737
|
};
|
|
4668
4738
|
var standardLicences = [
|
|
4669
|
-
|
|
4670
|
-
|
|
4671
|
-
|
|
4739
|
+
import_cluemart_shared36.EnumUserLicence.STANDARD_VENDOR,
|
|
4740
|
+
import_cluemart_shared36.EnumUserLicence.STANDARD_EVENT,
|
|
4741
|
+
import_cluemart_shared36.EnumUserLicence.STANDARD_PARTNER
|
|
4672
4742
|
];
|
|
4673
4743
|
var standardLicenceSet = new Set(standardLicences);
|
|
4674
4744
|
function isStandardLicence(licence) {
|
|
4675
4745
|
return standardLicenceSet.has(licence);
|
|
4676
4746
|
}
|
|
4677
4747
|
var proLicences = [
|
|
4678
|
-
|
|
4679
|
-
|
|
4680
|
-
|
|
4681
|
-
|
|
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
|
|
4682
4752
|
];
|
|
4683
4753
|
var proLicenceSet = new Set(proLicences);
|
|
4684
4754
|
function isProLicence(licence) {
|
|
@@ -4692,11 +4762,11 @@ var categoryRegexMapping = {
|
|
|
4692
4762
|
["school" /* SCHOOL */]: /_school$/
|
|
4693
4763
|
};
|
|
4694
4764
|
var categoryFallbackLicence = {
|
|
4695
|
-
["event" /* EVENT */]:
|
|
4696
|
-
["partner" /* PARTNER */]:
|
|
4697
|
-
["vendor" /* VENDOR */]:
|
|
4698
|
-
["affiliate" /* AFFILIATE */]:
|
|
4699
|
-
["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
|
|
4700
4770
|
};
|
|
4701
4771
|
var LicenceFilterInput = {
|
|
4702
4772
|
INPUT_USER_LICENCES: "$licences"
|
|
@@ -4726,11 +4796,11 @@ function getHighestLicenceForCategory(licences, category) {
|
|
|
4726
4796
|
function createLicenceObject(expiryDate, licenceType) {
|
|
4727
4797
|
const today = (0, import_dayjs5.default)();
|
|
4728
4798
|
const expiryDateMapping = {
|
|
4729
|
-
[
|
|
4730
|
-
[
|
|
4731
|
-
[
|
|
4732
|
-
[
|
|
4733
|
-
[
|
|
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()
|
|
4734
4804
|
};
|
|
4735
4805
|
const licenceObject = {
|
|
4736
4806
|
expiryDate: expiryDateMapping[expiryDate],
|
|
@@ -4834,13 +4904,13 @@ async function checkOwnerHasLicence({
|
|
|
4834
4904
|
const owner = await UserModel.findById(userId);
|
|
4835
4905
|
if (!owner) throw new import_graphql.GraphQLError("Owner not found");
|
|
4836
4906
|
const categoryByResource = {
|
|
4837
|
-
[
|
|
4838
|
-
[
|
|
4839
|
-
[
|
|
4840
|
-
[
|
|
4841
|
-
[
|
|
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 */
|
|
4842
4912
|
};
|
|
4843
|
-
if (!(0,
|
|
4913
|
+
if (!(0, import_cluemart_shared36.isNonVisitorResourceType)(resourceType)) {
|
|
4844
4914
|
throw new import_graphql.GraphQLError(`Invalid resource type: ${resourceType}.`);
|
|
4845
4915
|
}
|
|
4846
4916
|
const requiredCategory = categoryByResource[resourceType];
|
|
@@ -4863,9 +4933,9 @@ async function checkOwnerHasLicence({
|
|
|
4863
4933
|
}
|
|
4864
4934
|
}
|
|
4865
4935
|
var resourceLicenceCategory = {
|
|
4866
|
-
[
|
|
4867
|
-
[
|
|
4868
|
-
[
|
|
4936
|
+
[import_cluemart_shared36.EnumResourceType.EVENT]: "event" /* EVENT */,
|
|
4937
|
+
[import_cluemart_shared36.EnumResourceType.PARTNER]: "partner" /* PARTNER */,
|
|
4938
|
+
[import_cluemart_shared36.EnumResourceType.VENDOR]: "vendor" /* VENDOR */
|
|
4869
4939
|
};
|
|
4870
4940
|
function isProtectedByCurrentStripeSubscription(user, licenceType, now) {
|
|
4871
4941
|
const stripe = user.stripe;
|
|
@@ -4873,14 +4943,14 @@ function isProtectedByCurrentStripeSubscription(user, licenceType, now) {
|
|
|
4873
4943
|
return false;
|
|
4874
4944
|
}
|
|
4875
4945
|
const gracePeriodEndsAt = stripe.paymentGracePeriodEndsAt ? (0, import_dayjs5.default)(stripe.paymentGracePeriodEndsAt) : null;
|
|
4876
|
-
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);
|
|
4877
4947
|
if (hasActivePaymentGracePeriod) {
|
|
4878
4948
|
return true;
|
|
4879
4949
|
}
|
|
4880
4950
|
if (!stripe.subscriptionId) {
|
|
4881
4951
|
return false;
|
|
4882
4952
|
}
|
|
4883
|
-
if (stripe.status !==
|
|
4953
|
+
if (stripe.status !== import_cluemart_shared36.EnumSubscriptionStatus.ACTIVE) {
|
|
4884
4954
|
return false;
|
|
4885
4955
|
}
|
|
4886
4956
|
if (!stripe.endDate) {
|
|
@@ -5042,7 +5112,7 @@ async function applyVendorDowngrade(vendor, ownerUserId) {
|
|
|
5042
5112
|
return (result?.matchedCount ?? 0) > 0;
|
|
5043
5113
|
}
|
|
5044
5114
|
async function downgradeVendorProFeatures(userId, licenceType) {
|
|
5045
|
-
const isStandardVendor = licenceType ===
|
|
5115
|
+
const isStandardVendor = licenceType === import_cluemart_shared37.EnumUserLicence.STANDARD_VENDOR;
|
|
5046
5116
|
if (!isStandardVendor) {
|
|
5047
5117
|
return;
|
|
5048
5118
|
}
|
|
@@ -5089,7 +5159,7 @@ async function applyVendorRestore(vendor, ownerUserId) {
|
|
|
5089
5159
|
return (result?.matchedCount ?? 0) > 0;
|
|
5090
5160
|
}
|
|
5091
5161
|
async function restoreVendorProFeatures(userId, licenceType) {
|
|
5092
|
-
const isProVendor = licenceType ===
|
|
5162
|
+
const isProVendor = licenceType === import_cluemart_shared37.EnumUserLicence.PRO_VENDOR || licenceType === import_cluemart_shared37.EnumUserLicence.PRO_PLUS_VENDOR;
|
|
5093
5163
|
if (!isProVendor) {
|
|
5094
5164
|
return;
|
|
5095
5165
|
}
|
|
@@ -5115,7 +5185,7 @@ async function handleVendorLicenceCompliance(user, now) {
|
|
|
5115
5185
|
return;
|
|
5116
5186
|
}
|
|
5117
5187
|
const proLicences2 = vendorLicencesOfUser.filter(
|
|
5118
|
-
(licence) => licence.licenceType !==
|
|
5188
|
+
(licence) => licence.licenceType !== import_cluemart_shared37.EnumUserLicence.STANDARD_VENDOR
|
|
5119
5189
|
);
|
|
5120
5190
|
const expiredProLicences = proLicences2.filter(
|
|
5121
5191
|
(licence) => !(0, import_dayjs6.default)(licence.expiryDate).isAfter(now)
|
|
@@ -5128,7 +5198,7 @@ async function handleVendorLicenceCompliance(user, now) {
|
|
|
5128
5198
|
const expiredProLicence = expiredProLicences.some(
|
|
5129
5199
|
(licence) => !stripeProtectedLicenceTypes.has(licence.licenceType)
|
|
5130
5200
|
);
|
|
5131
|
-
const hasValidProLicence = stripeProtectedLicenceTypes.size > 0 || hasValidLicence(proLicences2,
|
|
5201
|
+
const hasValidProLicence = stripeProtectedLicenceTypes.size > 0 || hasValidLicence(proLicences2, import_cluemart_shared37.vendorLicences, now);
|
|
5132
5202
|
const hasExpiredVendorLicence = vendorLicencesOfUser.some(
|
|
5133
5203
|
(licence) => !(0, import_dayjs6.default)(licence.expiryDate).isAfter(now) && !stripeProtectedLicenceTypes.has(licence.licenceType)
|
|
5134
5204
|
);
|
|
@@ -5144,7 +5214,7 @@ async function handleVendorLicenceCompliance(user, now) {
|
|
|
5144
5214
|
"owner.userId": user._id
|
|
5145
5215
|
}).lean().exec();
|
|
5146
5216
|
}
|
|
5147
|
-
const licencesToSync =
|
|
5217
|
+
const licencesToSync = import_cluemart_shared37.vendorLicences.filter(
|
|
5148
5218
|
(licenceType) => !stripeProtectedLicenceTypes.has(licenceType)
|
|
5149
5219
|
);
|
|
5150
5220
|
await syncUserLicencesAfterExpiry(user._id, licencesToSync, now, "downgrade");
|
|
@@ -5159,11 +5229,11 @@ async function handleVendorLicenceCompliance(user, now) {
|
|
|
5159
5229
|
data: {
|
|
5160
5230
|
resourceId: String(vendor._id),
|
|
5161
5231
|
resourceName: vendor.name,
|
|
5162
|
-
resourceType:
|
|
5232
|
+
resourceType: import_cluemart_shared37.EnumNotificationResourceType.DOWNGRADED_VENDOR
|
|
5163
5233
|
},
|
|
5164
5234
|
message: `Your Vendor licence has been downgraded due to licence expiration.`,
|
|
5165
5235
|
title: `Vendor Licence Downgraded`,
|
|
5166
|
-
type:
|
|
5236
|
+
type: import_cluemart_shared37.EnumNotificationType.SYSTEM,
|
|
5167
5237
|
userIds: [user._id]
|
|
5168
5238
|
};
|
|
5169
5239
|
await sendDeactivationNotification(payload, user._id, vendor.name, "vendor");
|
|
@@ -5179,7 +5249,7 @@ async function vendorOwnerHasProLicence(vendorId) {
|
|
|
5179
5249
|
}
|
|
5180
5250
|
return hasActiveProLicenceForResource({
|
|
5181
5251
|
includeStripeProtected: true,
|
|
5182
|
-
resourceType:
|
|
5252
|
+
resourceType: import_cluemart_shared37.EnumResourceType.VENDOR,
|
|
5183
5253
|
userId: vendor.owner.userId
|
|
5184
5254
|
});
|
|
5185
5255
|
}
|
|
@@ -5191,12 +5261,12 @@ async function syncUserLicencesAfterExpiry(userId, licenceTypes, now, mode = "do
|
|
|
5191
5261
|
const pipeline = buildLicenceExpiryPipeline({
|
|
5192
5262
|
downgradeBranches: [
|
|
5193
5263
|
{
|
|
5194
|
-
case:
|
|
5195
|
-
then:
|
|
5264
|
+
case: import_cluemart_shared38.EnumUserLicence.PRO_PLUS_VENDOR,
|
|
5265
|
+
then: import_cluemart_shared38.EnumUserLicence.STANDARD_VENDOR
|
|
5196
5266
|
},
|
|
5197
5267
|
{
|
|
5198
|
-
case:
|
|
5199
|
-
then:
|
|
5268
|
+
case: import_cluemart_shared38.EnumUserLicence.PRO_VENDOR,
|
|
5269
|
+
then: import_cluemart_shared38.EnumUserLicence.STANDARD_VENDOR
|
|
5200
5270
|
}
|
|
5201
5271
|
],
|
|
5202
5272
|
licenceTypes,
|
|
@@ -5325,7 +5395,7 @@ var REMINDER_WINDOW_MIN_HOURS = 6.5 * 24;
|
|
|
5325
5395
|
var REMINDER_WINDOW_MAX_HOURS = 7.5 * 24;
|
|
5326
5396
|
|
|
5327
5397
|
// src/service/license/reminder/utils.ts
|
|
5328
|
-
var
|
|
5398
|
+
var import_cluemart_shared39 = require("@timardex/cluemart-shared");
|
|
5329
5399
|
var import_utils8 = require("@timardex/cluemart-shared/utils");
|
|
5330
5400
|
var import_dayjs9 = __toESM(require("dayjs"));
|
|
5331
5401
|
|
|
@@ -5391,28 +5461,28 @@ function isLicenseExpiringIn7Days(expiryDate, now) {
|
|
|
5391
5461
|
return hoursUntilExpiry >= REMINDER_WINDOW_MIN_HOURS && hoursUntilExpiry <= REMINDER_WINDOW_MAX_HOURS;
|
|
5392
5462
|
}
|
|
5393
5463
|
function getLicenseName(licenceType) {
|
|
5394
|
-
return
|
|
5464
|
+
return import_cluemart_shared39.licenseNiceNames[licenceType] || licenceType;
|
|
5395
5465
|
}
|
|
5396
5466
|
function getNotificationTypes(isVendorLicense, isPartnerLicense) {
|
|
5397
5467
|
if (isVendorLicense) {
|
|
5398
5468
|
return {
|
|
5399
|
-
notificationType:
|
|
5400
|
-
resourceType:
|
|
5469
|
+
notificationType: import_cluemart_shared39.EnumNotificationType.SYSTEM,
|
|
5470
|
+
resourceType: import_cluemart_shared39.EnumNotificationResourceType.EXPIRATION_REMINDER_VENDOR
|
|
5401
5471
|
};
|
|
5402
5472
|
}
|
|
5403
5473
|
if (isPartnerLicense) {
|
|
5404
5474
|
return {
|
|
5405
|
-
notificationType:
|
|
5406
|
-
resourceType:
|
|
5475
|
+
notificationType: import_cluemart_shared39.EnumNotificationType.SYSTEM,
|
|
5476
|
+
resourceType: import_cluemart_shared39.EnumNotificationResourceType.EXPIRATION_REMINDER_PARTNER
|
|
5407
5477
|
};
|
|
5408
5478
|
}
|
|
5409
5479
|
return {
|
|
5410
|
-
notificationType:
|
|
5411
|
-
resourceType:
|
|
5480
|
+
notificationType: import_cluemart_shared39.EnumNotificationType.SYSTEM,
|
|
5481
|
+
resourceType: import_cluemart_shared39.EnumNotificationResourceType.EXPIRATION_REMINDER_EVENT
|
|
5412
5482
|
};
|
|
5413
5483
|
}
|
|
5414
5484
|
async function getLicenseResourceInfo(user, licence) {
|
|
5415
|
-
const isVendorLicense =
|
|
5485
|
+
const isVendorLicense = import_cluemart_shared39.vendorLicences.includes(licence.licenceType);
|
|
5416
5486
|
const isPartnerLicense = partnerLicences.includes(licence.licenceType);
|
|
5417
5487
|
const licenceName = getLicenseName(licence.licenceType);
|
|
5418
5488
|
const { notificationType, resourceType } = getNotificationTypes(
|
|
@@ -5460,11 +5530,11 @@ async function getLicenseResourceInfo(user, licence) {
|
|
|
5460
5530
|
};
|
|
5461
5531
|
}
|
|
5462
5532
|
function getLicenceExpiryMode(licenceType) {
|
|
5463
|
-
return licenceType ===
|
|
5533
|
+
return licenceType === import_cluemart_shared39.EnumUserLicence.PRO_VENDOR || licenceType === import_cluemart_shared39.EnumUserLicence.PRO_PLUS_VENDOR ? "downgrade" : "extend";
|
|
5464
5534
|
}
|
|
5465
5535
|
async function sendLicenseReminder(user, licence) {
|
|
5466
5536
|
const licenceName = getLicenseName(licence.licenceType);
|
|
5467
|
-
const expiryDate = (0, import_dayjs9.default)(licence.expiryDate).format(
|
|
5537
|
+
const expiryDate = (0, import_dayjs9.default)(licence.expiryDate).format(import_cluemart_shared39.dateFormat);
|
|
5468
5538
|
const userId = String(user._id);
|
|
5469
5539
|
const resourceInfo = await getLicenseResourceInfo(user, licence);
|
|
5470
5540
|
if (!resourceInfo) {
|
|
@@ -5590,6 +5660,7 @@ async function remindUsersAboutLicenseExpiration() {
|
|
|
5590
5660
|
// Annotate the CommonJS export names for ESM import in node:
|
|
5591
5661
|
0 && (module.exports = {
|
|
5592
5662
|
ACTIVE_NOT_DELETED_FILTER,
|
|
5663
|
+
LIVE_RESOURCE_FILTER,
|
|
5593
5664
|
LicenceCategory,
|
|
5594
5665
|
REMINDER_WINDOW_MAX_HOURS,
|
|
5595
5666
|
REMINDER_WINDOW_MIN_HOURS,
|
|
@@ -5620,6 +5691,7 @@ async function remindUsersAboutLicenseExpiration() {
|
|
|
5620
5691
|
eventLicences,
|
|
5621
5692
|
findAffiliateByPromoCode,
|
|
5622
5693
|
findEventOrImportedMarketById,
|
|
5694
|
+
findEventOrImportedMarketDetailsById,
|
|
5623
5695
|
getActiveLicenceForResource,
|
|
5624
5696
|
getAssociateAccessMeta,
|
|
5625
5697
|
getEventResourceInfo,
|
|
@@ -5640,6 +5712,7 @@ async function remindUsersAboutLicenseExpiration() {
|
|
|
5640
5712
|
hasActiveProLicenceForResource,
|
|
5641
5713
|
hasValidLicence,
|
|
5642
5714
|
isAssociableResourceType,
|
|
5715
|
+
isLiveResource,
|
|
5643
5716
|
isProLicence,
|
|
5644
5717
|
isProtectedByCurrentStripeSubscription,
|
|
5645
5718
|
isStandardLicence,
|