@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/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: () =>
|
|
180
|
+
updateSingleDateTimeStatus: () => import_cluemart_shared40.updateSingleDateTimeStatus,
|
|
178
181
|
upgradeUserToLicence: () => upgradeUserToLicence,
|
|
179
182
|
userLicenseSchema: () => userLicenseSchema,
|
|
180
183
|
vendorOwnerHasProLicence: () => vendorOwnerHasProLicence,
|
|
@@ -2094,6 +2097,15 @@ schema15.index({ "licences.expiryDate": 1 });
|
|
|
2094
2097
|
schema15.index({ "licences.licenceType": 1 });
|
|
2095
2098
|
schema15.index({ promoCodes: 1, active: 1, deletedAt: 1 });
|
|
2096
2099
|
schema15.index({ email: "text", firstName: "text", lastName: "text" });
|
|
2100
|
+
schema15.index({ email: 1 }, { name: "email_unique", unique: true });
|
|
2101
|
+
schema15.index(
|
|
2102
|
+
{ email: 1 },
|
|
2103
|
+
{
|
|
2104
|
+
collation: { locale: "en", strength: 2 },
|
|
2105
|
+
name: "email_unique_normalized",
|
|
2106
|
+
unique: true
|
|
2107
|
+
}
|
|
2108
|
+
);
|
|
2097
2109
|
schema15.index({ "associatedResources.events": 1 });
|
|
2098
2110
|
schema15.index({ "associatedResources.partners": 1 });
|
|
2099
2111
|
schema15.index({ "associatedResources.vendors": 1 });
|
|
@@ -4435,24 +4447,83 @@ async function updateAllEventDateTimeStatuses() {
|
|
|
4435
4447
|
}
|
|
4436
4448
|
|
|
4437
4449
|
// src/service/index.ts
|
|
4438
|
-
var
|
|
4450
|
+
var import_cluemart_shared40 = require("@timardex/cluemart-shared");
|
|
4439
4451
|
|
|
4440
4452
|
// src/service/event/findEventOrImportedMarketById.ts
|
|
4441
|
-
|
|
4442
|
-
|
|
4443
|
-
|
|
4453
|
+
var import_cluemart_shared32 = require("@timardex/cluemart-shared");
|
|
4454
|
+
|
|
4455
|
+
// src/service/event/resourceVisibility.ts
|
|
4456
|
+
var LIVE_RESOURCE_FILTER = { active: true, deletedAt: null };
|
|
4457
|
+
function isLiveResource(resource) {
|
|
4458
|
+
return resource.active === true && resource.deletedAt == null;
|
|
4459
|
+
}
|
|
4460
|
+
|
|
4461
|
+
// src/service/event/findEventOrImportedMarketById.ts
|
|
4462
|
+
var EVENT_REFERENCE_FIELDS = "_id active dateTime deletedAt name owner";
|
|
4463
|
+
var IMPORTED_MARKET_REFERENCE_FIELDS = "_id active dateTime deletedAt name";
|
|
4464
|
+
var AI_IMPORTED_MARKET_REFERENCE_FIELDS = `${IMPORTED_MARKET_REFERENCE_FIELDS} reviewStatus`;
|
|
4465
|
+
function isAddressableAiImport(market, includeDeleted) {
|
|
4466
|
+
const isApproved = market.reviewStatus === import_cluemart_shared32.EnumImportedMarketReviewStatus.APPROVED;
|
|
4467
|
+
return includeDeleted ? isApproved || market.deletedAt != null : isApproved && isLiveResource(market);
|
|
4468
|
+
}
|
|
4469
|
+
function pickMatch(eventDoc, googleImportedDoc, aiImportedDoc, includeDeleted) {
|
|
4470
|
+
if (eventDoc && (includeDeleted || isLiveResource(eventDoc))) {
|
|
4471
|
+
return { doc: eventDoc, kind: "event" };
|
|
4472
|
+
}
|
|
4473
|
+
if (googleImportedDoc && (includeDeleted || isLiveResource(googleImportedDoc))) {
|
|
4474
|
+
return { doc: googleImportedDoc, kind: "google" };
|
|
4475
|
+
}
|
|
4476
|
+
if (aiImportedDoc && isAddressableAiImport(aiImportedDoc, includeDeleted)) {
|
|
4477
|
+
return { doc: aiImportedDoc, kind: "ai" };
|
|
4444
4478
|
}
|
|
4445
|
-
|
|
4446
|
-
|
|
4447
|
-
|
|
4448
|
-
|
|
4449
|
-
|
|
4479
|
+
return null;
|
|
4480
|
+
}
|
|
4481
|
+
function normalizeLookupId(resourceId) {
|
|
4482
|
+
return resourceId ? convertObjectIdsToStrings(resourceId) : null;
|
|
4483
|
+
}
|
|
4484
|
+
async function findReferenceRows(normalizedId) {
|
|
4485
|
+
return Promise.all([
|
|
4486
|
+
EventModel.findById(normalizedId).select(EVENT_REFERENCE_FIELDS).lean().exec(),
|
|
4487
|
+
GoogleImportedMarketModel.findById(normalizedId).select(IMPORTED_MARKET_REFERENCE_FIELDS).lean().exec(),
|
|
4488
|
+
AiImportedMarketModel.findById(normalizedId).select(AI_IMPORTED_MARKET_REFERENCE_FIELDS).lean().exec()
|
|
4450
4489
|
]);
|
|
4451
|
-
|
|
4490
|
+
}
|
|
4491
|
+
async function findDetailRows(normalizedId) {
|
|
4492
|
+
return Promise.all([
|
|
4493
|
+
EventModel.findById(normalizedId).lean().exec(),
|
|
4494
|
+
GoogleImportedMarketModel.findById(normalizedId).lean().exec(),
|
|
4495
|
+
AiImportedMarketModel.findById(normalizedId).lean().exec()
|
|
4496
|
+
]);
|
|
4497
|
+
}
|
|
4498
|
+
async function findEventOrImportedMarketById(resourceId, options = {}) {
|
|
4499
|
+
const normalizedId = normalizeLookupId(resourceId);
|
|
4500
|
+
if (!normalizedId) {
|
|
4501
|
+
return null;
|
|
4502
|
+
}
|
|
4503
|
+
const [eventDoc, googleImportedDoc, aiImportedDoc] = await findReferenceRows(normalizedId);
|
|
4504
|
+
return pickMatch(
|
|
4505
|
+
eventDoc,
|
|
4506
|
+
googleImportedDoc,
|
|
4507
|
+
aiImportedDoc,
|
|
4508
|
+
options.includeDeleted ?? false
|
|
4509
|
+
);
|
|
4510
|
+
}
|
|
4511
|
+
async function findEventOrImportedMarketDetailsById(resourceId, options = {}) {
|
|
4512
|
+
const normalizedId = normalizeLookupId(resourceId);
|
|
4513
|
+
if (!normalizedId) {
|
|
4514
|
+
return null;
|
|
4515
|
+
}
|
|
4516
|
+
const [eventDoc, googleImportedDoc, aiImportedDoc] = await findDetailRows(normalizedId);
|
|
4517
|
+
return pickMatch(
|
|
4518
|
+
eventDoc,
|
|
4519
|
+
googleImportedDoc,
|
|
4520
|
+
aiImportedDoc,
|
|
4521
|
+
options.includeDeleted ?? false
|
|
4522
|
+
);
|
|
4452
4523
|
}
|
|
4453
4524
|
|
|
4454
4525
|
// src/service/relations.ts
|
|
4455
|
-
var
|
|
4526
|
+
var import_cluemart_shared33 = require("@timardex/cluemart-shared");
|
|
4456
4527
|
function didRemoveAnyEventDates(previousDateTime, nextDateTime) {
|
|
4457
4528
|
if (!previousDateTime?.length) {
|
|
4458
4529
|
return false;
|
|
@@ -4468,8 +4539,8 @@ function didRemoveAnyStartedDates(previousDateTime, nextDateTime) {
|
|
|
4468
4539
|
return false;
|
|
4469
4540
|
}
|
|
4470
4541
|
return previousDateTime.some(
|
|
4471
|
-
(prev) => prev.dateStatus ===
|
|
4472
|
-
(next) => next.startDate === prev.startDate && next.startTime === prev.startTime && next.dateStatus ===
|
|
4542
|
+
(prev) => prev.dateStatus === import_cluemart_shared33.EnumEventDateStatus.STARTED && !nextDateTime?.some(
|
|
4543
|
+
(next) => next.startDate === prev.startDate && next.startTime === prev.startTime && next.dateStatus === import_cluemart_shared33.EnumEventDateStatus.STARTED
|
|
4473
4544
|
)
|
|
4474
4545
|
);
|
|
4475
4546
|
}
|
|
@@ -4480,7 +4551,7 @@ function updateRelationDatesToCanceled(relationDates, eventDateTime) {
|
|
|
4480
4551
|
) ?? false;
|
|
4481
4552
|
return {
|
|
4482
4553
|
...relationDate,
|
|
4483
|
-
status: existsInEvent ? relationDate.status :
|
|
4554
|
+
status: existsInEvent ? relationDate.status : import_cluemart_shared33.EnumInviteStatus.CANCELED
|
|
4484
4555
|
};
|
|
4485
4556
|
});
|
|
4486
4557
|
}
|
|
@@ -4489,15 +4560,15 @@ function updateRelationDatesToCanceled(relationDates, eventDateTime) {
|
|
|
4489
4560
|
var import_dayjs8 = __toESM(require("dayjs"));
|
|
4490
4561
|
|
|
4491
4562
|
// src/service/license/compliance/utils.ts
|
|
4492
|
-
var
|
|
4563
|
+
var import_cluemart_shared38 = require("@timardex/cluemart-shared");
|
|
4493
4564
|
var import_dayjs7 = __toESM(require("dayjs"));
|
|
4494
4565
|
|
|
4495
4566
|
// src/service/license/compliance/event.ts
|
|
4496
|
-
var
|
|
4567
|
+
var import_cluemart_shared34 = require("@timardex/cluemart-shared");
|
|
4497
4568
|
var eventLicences = [
|
|
4498
|
-
|
|
4499
|
-
|
|
4500
|
-
|
|
4569
|
+
import_cluemart_shared34.EnumUserLicence.STANDARD_EVENT,
|
|
4570
|
+
import_cluemart_shared34.EnumUserLicence.PRO_EVENT,
|
|
4571
|
+
import_cluemart_shared34.EnumUserLicence.PRO_PLUS_EVENT
|
|
4501
4572
|
];
|
|
4502
4573
|
async function handleEventLicenceCompliance(user, now) {
|
|
4503
4574
|
if (!user.licences || !user.events?.length) {
|
|
@@ -4709,9 +4780,9 @@ function buildLicenceExpiryPipeline(params) {
|
|
|
4709
4780
|
}
|
|
4710
4781
|
|
|
4711
4782
|
// src/service/license/compliance/partner.ts
|
|
4712
|
-
var
|
|
4783
|
+
var import_cluemart_shared35 = require("@timardex/cluemart-shared");
|
|
4713
4784
|
var partnerLicences = [
|
|
4714
|
-
|
|
4785
|
+
import_cluemart_shared35.EnumUserLicence.STANDARD_PARTNER
|
|
4715
4786
|
];
|
|
4716
4787
|
async function handlePartnerLicenceCompliance(user, now) {
|
|
4717
4788
|
if (!user.licences || !user.partner) {
|
|
@@ -4721,11 +4792,11 @@ async function handlePartnerLicenceCompliance(user, now) {
|
|
|
4721
4792
|
}
|
|
4722
4793
|
|
|
4723
4794
|
// src/service/license/compliance/vendor.ts
|
|
4724
|
-
var
|
|
4795
|
+
var import_cluemart_shared37 = require("@timardex/cluemart-shared");
|
|
4725
4796
|
var import_dayjs6 = __toESM(require("dayjs"));
|
|
4726
4797
|
|
|
4727
4798
|
// src/service/license/models.ts
|
|
4728
|
-
var
|
|
4799
|
+
var import_cluemart_shared36 = require("@timardex/cluemart-shared");
|
|
4729
4800
|
var import_dayjs5 = __toESM(require("dayjs"));
|
|
4730
4801
|
var import_graphql = require("graphql");
|
|
4731
4802
|
var LicenceCategory = /* @__PURE__ */ ((LicenceCategory3) => {
|
|
@@ -4737,41 +4808,41 @@ var LicenceCategory = /* @__PURE__ */ ((LicenceCategory3) => {
|
|
|
4737
4808
|
return LicenceCategory3;
|
|
4738
4809
|
})(LicenceCategory || {});
|
|
4739
4810
|
var licenceCategoryMapping = {
|
|
4740
|
-
[
|
|
4741
|
-
[
|
|
4742
|
-
[
|
|
4743
|
-
[
|
|
4744
|
-
[
|
|
4745
|
-
[
|
|
4746
|
-
[
|
|
4747
|
-
[
|
|
4748
|
-
[
|
|
4811
|
+
[import_cluemart_shared36.EnumUserLicence.PRO_EVENT]: "event" /* EVENT */,
|
|
4812
|
+
[import_cluemart_shared36.EnumUserLicence.PRO_PLUS_EVENT]: "event" /* EVENT */,
|
|
4813
|
+
[import_cluemart_shared36.EnumUserLicence.PRO_PLUS_VENDOR]: "vendor" /* VENDOR */,
|
|
4814
|
+
[import_cluemart_shared36.EnumUserLicence.PRO_VENDOR]: "vendor" /* VENDOR */,
|
|
4815
|
+
[import_cluemart_shared36.EnumUserLicence.STANDARD_EVENT]: "event" /* EVENT */,
|
|
4816
|
+
[import_cluemart_shared36.EnumUserLicence.STANDARD_PARTNER]: "partner" /* PARTNER */,
|
|
4817
|
+
[import_cluemart_shared36.EnumUserLicence.STANDARD_VENDOR]: "vendor" /* VENDOR */,
|
|
4818
|
+
[import_cluemart_shared36.EnumUserLicence.STANDARD_AFFILIATE]: "affiliate" /* AFFILIATE */,
|
|
4819
|
+
[import_cluemart_shared36.EnumUserLicence.STANDARD_SCHOOL]: "school" /* SCHOOL */
|
|
4749
4820
|
};
|
|
4750
4821
|
var licencePriority = {
|
|
4751
|
-
[
|
|
4752
|
-
[
|
|
4753
|
-
[
|
|
4754
|
-
[
|
|
4755
|
-
[
|
|
4756
|
-
[
|
|
4757
|
-
[
|
|
4758
|
-
[
|
|
4759
|
-
[
|
|
4822
|
+
[import_cluemart_shared36.EnumUserLicence.PRO_PLUS_EVENT]: 3,
|
|
4823
|
+
[import_cluemart_shared36.EnumUserLicence.PRO_EVENT]: 2,
|
|
4824
|
+
[import_cluemart_shared36.EnumUserLicence.STANDARD_EVENT]: 1,
|
|
4825
|
+
[import_cluemart_shared36.EnumUserLicence.PRO_PLUS_VENDOR]: 3,
|
|
4826
|
+
[import_cluemart_shared36.EnumUserLicence.PRO_VENDOR]: 2,
|
|
4827
|
+
[import_cluemart_shared36.EnumUserLicence.STANDARD_VENDOR]: 1,
|
|
4828
|
+
[import_cluemart_shared36.EnumUserLicence.STANDARD_PARTNER]: 1,
|
|
4829
|
+
[import_cluemart_shared36.EnumUserLicence.STANDARD_AFFILIATE]: 1,
|
|
4830
|
+
[import_cluemart_shared36.EnumUserLicence.STANDARD_SCHOOL]: 1
|
|
4760
4831
|
};
|
|
4761
4832
|
var standardLicences = [
|
|
4762
|
-
|
|
4763
|
-
|
|
4764
|
-
|
|
4833
|
+
import_cluemart_shared36.EnumUserLicence.STANDARD_VENDOR,
|
|
4834
|
+
import_cluemart_shared36.EnumUserLicence.STANDARD_EVENT,
|
|
4835
|
+
import_cluemart_shared36.EnumUserLicence.STANDARD_PARTNER
|
|
4765
4836
|
];
|
|
4766
4837
|
var standardLicenceSet = new Set(standardLicences);
|
|
4767
4838
|
function isStandardLicence(licence) {
|
|
4768
4839
|
return standardLicenceSet.has(licence);
|
|
4769
4840
|
}
|
|
4770
4841
|
var proLicences = [
|
|
4771
|
-
|
|
4772
|
-
|
|
4773
|
-
|
|
4774
|
-
|
|
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
|
|
4775
4846
|
];
|
|
4776
4847
|
var proLicenceSet = new Set(proLicences);
|
|
4777
4848
|
function isProLicence(licence) {
|
|
@@ -4785,11 +4856,11 @@ var categoryRegexMapping = {
|
|
|
4785
4856
|
["school" /* SCHOOL */]: /_school$/
|
|
4786
4857
|
};
|
|
4787
4858
|
var categoryFallbackLicence = {
|
|
4788
|
-
["event" /* EVENT */]:
|
|
4789
|
-
["partner" /* PARTNER */]:
|
|
4790
|
-
["vendor" /* VENDOR */]:
|
|
4791
|
-
["affiliate" /* AFFILIATE */]:
|
|
4792
|
-
["school" /* SCHOOL */]:
|
|
4859
|
+
["event" /* EVENT */]: import_cluemart_shared36.EnumUserLicence.STANDARD_EVENT,
|
|
4860
|
+
["partner" /* PARTNER */]: import_cluemart_shared36.EnumUserLicence.STANDARD_PARTNER,
|
|
4861
|
+
["vendor" /* VENDOR */]: import_cluemart_shared36.EnumUserLicence.STANDARD_VENDOR,
|
|
4862
|
+
["affiliate" /* AFFILIATE */]: import_cluemart_shared36.EnumUserLicence.STANDARD_AFFILIATE,
|
|
4863
|
+
["school" /* SCHOOL */]: import_cluemart_shared36.EnumUserLicence.STANDARD_SCHOOL
|
|
4793
4864
|
};
|
|
4794
4865
|
var LicenceFilterInput = {
|
|
4795
4866
|
INPUT_USER_LICENCES: "$licences"
|
|
@@ -4819,11 +4890,11 @@ function getHighestLicenceForCategory(licences, category) {
|
|
|
4819
4890
|
function createLicenceObject(expiryDate, licenceType) {
|
|
4820
4891
|
const today = (0, import_dayjs5.default)();
|
|
4821
4892
|
const expiryDateMapping = {
|
|
4822
|
-
[
|
|
4823
|
-
[
|
|
4824
|
-
[
|
|
4825
|
-
[
|
|
4826
|
-
[
|
|
4893
|
+
[import_cluemart_shared36.LicenceExpiryDate.ONE_YEAR]: today.add(1, "year").endOf("day").toDate(),
|
|
4894
|
+
[import_cluemart_shared36.LicenceExpiryDate.ONE_MONTH]: today.add(1, "month").endOf("day").toDate(),
|
|
4895
|
+
[import_cluemart_shared36.LicenceExpiryDate.TWO_MONTHS]: today.add(2, "month").endOf("day").toDate(),
|
|
4896
|
+
[import_cluemart_shared36.LicenceExpiryDate.THREE_MONTHS]: today.add(3, "month").endOf("day").toDate(),
|
|
4897
|
+
[import_cluemart_shared36.LicenceExpiryDate.SIX_MONTHS]: today.add(6, "month").endOf("day").toDate()
|
|
4827
4898
|
};
|
|
4828
4899
|
const licenceObject = {
|
|
4829
4900
|
expiryDate: expiryDateMapping[expiryDate],
|
|
@@ -4927,13 +4998,13 @@ async function checkOwnerHasLicence({
|
|
|
4927
4998
|
const owner = await UserModel.findById(userId);
|
|
4928
4999
|
if (!owner) throw new import_graphql.GraphQLError("Owner not found");
|
|
4929
5000
|
const categoryByResource = {
|
|
4930
|
-
[
|
|
4931
|
-
[
|
|
4932
|
-
[
|
|
4933
|
-
[
|
|
4934
|
-
[
|
|
5001
|
+
[import_cluemart_shared36.EnumResourceType.EVENT]: "event" /* EVENT */,
|
|
5002
|
+
[import_cluemart_shared36.EnumResourceType.PARTNER]: "partner" /* PARTNER */,
|
|
5003
|
+
[import_cluemart_shared36.EnumResourceType.VENDOR]: "vendor" /* VENDOR */,
|
|
5004
|
+
[import_cluemart_shared36.EnumResourceType.AFFILIATE]: "affiliate" /* AFFILIATE */,
|
|
5005
|
+
[import_cluemart_shared36.EnumResourceType.SCHOOL]: "school" /* SCHOOL */
|
|
4935
5006
|
};
|
|
4936
|
-
if (!(0,
|
|
5007
|
+
if (!(0, import_cluemart_shared36.isNonVisitorResourceType)(resourceType)) {
|
|
4937
5008
|
throw new import_graphql.GraphQLError(`Invalid resource type: ${resourceType}.`);
|
|
4938
5009
|
}
|
|
4939
5010
|
const requiredCategory = categoryByResource[resourceType];
|
|
@@ -4956,9 +5027,9 @@ async function checkOwnerHasLicence({
|
|
|
4956
5027
|
}
|
|
4957
5028
|
}
|
|
4958
5029
|
var resourceLicenceCategory = {
|
|
4959
|
-
[
|
|
4960
|
-
[
|
|
4961
|
-
[
|
|
5030
|
+
[import_cluemart_shared36.EnumResourceType.EVENT]: "event" /* EVENT */,
|
|
5031
|
+
[import_cluemart_shared36.EnumResourceType.PARTNER]: "partner" /* PARTNER */,
|
|
5032
|
+
[import_cluemart_shared36.EnumResourceType.VENDOR]: "vendor" /* VENDOR */
|
|
4962
5033
|
};
|
|
4963
5034
|
function isProtectedByCurrentStripeSubscription(user, licenceType, now) {
|
|
4964
5035
|
const stripe = user.stripe;
|
|
@@ -4966,14 +5037,14 @@ function isProtectedByCurrentStripeSubscription(user, licenceType, now) {
|
|
|
4966
5037
|
return false;
|
|
4967
5038
|
}
|
|
4968
5039
|
const gracePeriodEndsAt = stripe.paymentGracePeriodEndsAt ? (0, import_dayjs5.default)(stripe.paymentGracePeriodEndsAt) : null;
|
|
4969
|
-
const hasActivePaymentGracePeriod = (stripe.status ===
|
|
5040
|
+
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);
|
|
4970
5041
|
if (hasActivePaymentGracePeriod) {
|
|
4971
5042
|
return true;
|
|
4972
5043
|
}
|
|
4973
5044
|
if (!stripe.subscriptionId) {
|
|
4974
5045
|
return false;
|
|
4975
5046
|
}
|
|
4976
|
-
if (stripe.status !==
|
|
5047
|
+
if (stripe.status !== import_cluemart_shared36.EnumSubscriptionStatus.ACTIVE) {
|
|
4977
5048
|
return false;
|
|
4978
5049
|
}
|
|
4979
5050
|
if (!stripe.endDate) {
|
|
@@ -5135,7 +5206,7 @@ async function applyVendorDowngrade(vendor, ownerUserId) {
|
|
|
5135
5206
|
return (result?.matchedCount ?? 0) > 0;
|
|
5136
5207
|
}
|
|
5137
5208
|
async function downgradeVendorProFeatures(userId, licenceType) {
|
|
5138
|
-
const isStandardVendor = licenceType ===
|
|
5209
|
+
const isStandardVendor = licenceType === import_cluemart_shared37.EnumUserLicence.STANDARD_VENDOR;
|
|
5139
5210
|
if (!isStandardVendor) {
|
|
5140
5211
|
return;
|
|
5141
5212
|
}
|
|
@@ -5182,7 +5253,7 @@ async function applyVendorRestore(vendor, ownerUserId) {
|
|
|
5182
5253
|
return (result?.matchedCount ?? 0) > 0;
|
|
5183
5254
|
}
|
|
5184
5255
|
async function restoreVendorProFeatures(userId, licenceType) {
|
|
5185
|
-
const isProVendor = licenceType ===
|
|
5256
|
+
const isProVendor = licenceType === import_cluemart_shared37.EnumUserLicence.PRO_VENDOR || licenceType === import_cluemart_shared37.EnumUserLicence.PRO_PLUS_VENDOR;
|
|
5186
5257
|
if (!isProVendor) {
|
|
5187
5258
|
return;
|
|
5188
5259
|
}
|
|
@@ -5208,7 +5279,7 @@ async function handleVendorLicenceCompliance(user, now) {
|
|
|
5208
5279
|
return;
|
|
5209
5280
|
}
|
|
5210
5281
|
const proLicences2 = vendorLicencesOfUser.filter(
|
|
5211
|
-
(licence) => licence.licenceType !==
|
|
5282
|
+
(licence) => licence.licenceType !== import_cluemart_shared37.EnumUserLicence.STANDARD_VENDOR
|
|
5212
5283
|
);
|
|
5213
5284
|
const expiredProLicences = proLicences2.filter(
|
|
5214
5285
|
(licence) => !(0, import_dayjs6.default)(licence.expiryDate).isAfter(now)
|
|
@@ -5221,7 +5292,7 @@ async function handleVendorLicenceCompliance(user, now) {
|
|
|
5221
5292
|
const expiredProLicence = expiredProLicences.some(
|
|
5222
5293
|
(licence) => !stripeProtectedLicenceTypes.has(licence.licenceType)
|
|
5223
5294
|
);
|
|
5224
|
-
const hasValidProLicence = stripeProtectedLicenceTypes.size > 0 || hasValidLicence(proLicences2,
|
|
5295
|
+
const hasValidProLicence = stripeProtectedLicenceTypes.size > 0 || hasValidLicence(proLicences2, import_cluemart_shared37.vendorLicences, now);
|
|
5225
5296
|
const hasExpiredVendorLicence = vendorLicencesOfUser.some(
|
|
5226
5297
|
(licence) => !(0, import_dayjs6.default)(licence.expiryDate).isAfter(now) && !stripeProtectedLicenceTypes.has(licence.licenceType)
|
|
5227
5298
|
);
|
|
@@ -5237,7 +5308,7 @@ async function handleVendorLicenceCompliance(user, now) {
|
|
|
5237
5308
|
"owner.userId": user._id
|
|
5238
5309
|
}).lean().exec();
|
|
5239
5310
|
}
|
|
5240
|
-
const licencesToSync =
|
|
5311
|
+
const licencesToSync = import_cluemart_shared37.vendorLicences.filter(
|
|
5241
5312
|
(licenceType) => !stripeProtectedLicenceTypes.has(licenceType)
|
|
5242
5313
|
);
|
|
5243
5314
|
await syncUserLicencesAfterExpiry(user._id, licencesToSync, now, "downgrade");
|
|
@@ -5252,11 +5323,11 @@ async function handleVendorLicenceCompliance(user, now) {
|
|
|
5252
5323
|
data: {
|
|
5253
5324
|
resourceId: String(vendor._id),
|
|
5254
5325
|
resourceName: vendor.name,
|
|
5255
|
-
resourceType:
|
|
5326
|
+
resourceType: import_cluemart_shared37.EnumNotificationResourceType.DOWNGRADED_VENDOR
|
|
5256
5327
|
},
|
|
5257
5328
|
message: `Your Vendor licence has been downgraded due to licence expiration.`,
|
|
5258
5329
|
title: `Vendor Licence Downgraded`,
|
|
5259
|
-
type:
|
|
5330
|
+
type: import_cluemart_shared37.EnumNotificationType.SYSTEM,
|
|
5260
5331
|
userIds: [user._id]
|
|
5261
5332
|
};
|
|
5262
5333
|
await sendDeactivationNotification(payload, user._id, vendor.name, "vendor");
|
|
@@ -5272,7 +5343,7 @@ async function vendorOwnerHasProLicence(vendorId) {
|
|
|
5272
5343
|
}
|
|
5273
5344
|
return hasActiveProLicenceForResource({
|
|
5274
5345
|
includeStripeProtected: true,
|
|
5275
|
-
resourceType:
|
|
5346
|
+
resourceType: import_cluemart_shared37.EnumResourceType.VENDOR,
|
|
5276
5347
|
userId: vendor.owner.userId
|
|
5277
5348
|
});
|
|
5278
5349
|
}
|
|
@@ -5284,12 +5355,12 @@ async function syncUserLicencesAfterExpiry(userId, licenceTypes, now, mode = "do
|
|
|
5284
5355
|
const pipeline = buildLicenceExpiryPipeline({
|
|
5285
5356
|
downgradeBranches: [
|
|
5286
5357
|
{
|
|
5287
|
-
case:
|
|
5288
|
-
then:
|
|
5358
|
+
case: import_cluemart_shared38.EnumUserLicence.PRO_PLUS_VENDOR,
|
|
5359
|
+
then: import_cluemart_shared38.EnumUserLicence.STANDARD_VENDOR
|
|
5289
5360
|
},
|
|
5290
5361
|
{
|
|
5291
|
-
case:
|
|
5292
|
-
then:
|
|
5362
|
+
case: import_cluemart_shared38.EnumUserLicence.PRO_VENDOR,
|
|
5363
|
+
then: import_cluemart_shared38.EnumUserLicence.STANDARD_VENDOR
|
|
5293
5364
|
}
|
|
5294
5365
|
],
|
|
5295
5366
|
licenceTypes,
|
|
@@ -5418,7 +5489,7 @@ var REMINDER_WINDOW_MIN_HOURS = 6.5 * 24;
|
|
|
5418
5489
|
var REMINDER_WINDOW_MAX_HOURS = 7.5 * 24;
|
|
5419
5490
|
|
|
5420
5491
|
// src/service/license/reminder/utils.ts
|
|
5421
|
-
var
|
|
5492
|
+
var import_cluemart_shared39 = require("@timardex/cluemart-shared");
|
|
5422
5493
|
var import_utils8 = require("@timardex/cluemart-shared/utils");
|
|
5423
5494
|
var import_dayjs9 = __toESM(require("dayjs"));
|
|
5424
5495
|
|
|
@@ -5484,28 +5555,28 @@ function isLicenseExpiringIn7Days(expiryDate, now) {
|
|
|
5484
5555
|
return hoursUntilExpiry >= REMINDER_WINDOW_MIN_HOURS && hoursUntilExpiry <= REMINDER_WINDOW_MAX_HOURS;
|
|
5485
5556
|
}
|
|
5486
5557
|
function getLicenseName(licenceType) {
|
|
5487
|
-
return
|
|
5558
|
+
return import_cluemart_shared39.licenseNiceNames[licenceType] || licenceType;
|
|
5488
5559
|
}
|
|
5489
5560
|
function getNotificationTypes(isVendorLicense, isPartnerLicense) {
|
|
5490
5561
|
if (isVendorLicense) {
|
|
5491
5562
|
return {
|
|
5492
|
-
notificationType:
|
|
5493
|
-
resourceType:
|
|
5563
|
+
notificationType: import_cluemart_shared39.EnumNotificationType.SYSTEM,
|
|
5564
|
+
resourceType: import_cluemart_shared39.EnumNotificationResourceType.EXPIRATION_REMINDER_VENDOR
|
|
5494
5565
|
};
|
|
5495
5566
|
}
|
|
5496
5567
|
if (isPartnerLicense) {
|
|
5497
5568
|
return {
|
|
5498
|
-
notificationType:
|
|
5499
|
-
resourceType:
|
|
5569
|
+
notificationType: import_cluemart_shared39.EnumNotificationType.SYSTEM,
|
|
5570
|
+
resourceType: import_cluemart_shared39.EnumNotificationResourceType.EXPIRATION_REMINDER_PARTNER
|
|
5500
5571
|
};
|
|
5501
5572
|
}
|
|
5502
5573
|
return {
|
|
5503
|
-
notificationType:
|
|
5504
|
-
resourceType:
|
|
5574
|
+
notificationType: import_cluemart_shared39.EnumNotificationType.SYSTEM,
|
|
5575
|
+
resourceType: import_cluemart_shared39.EnumNotificationResourceType.EXPIRATION_REMINDER_EVENT
|
|
5505
5576
|
};
|
|
5506
5577
|
}
|
|
5507
5578
|
async function getLicenseResourceInfo(user, licence) {
|
|
5508
|
-
const isVendorLicense =
|
|
5579
|
+
const isVendorLicense = import_cluemart_shared39.vendorLicences.includes(licence.licenceType);
|
|
5509
5580
|
const isPartnerLicense = partnerLicences.includes(licence.licenceType);
|
|
5510
5581
|
const licenceName = getLicenseName(licence.licenceType);
|
|
5511
5582
|
const { notificationType, resourceType } = getNotificationTypes(
|
|
@@ -5553,11 +5624,11 @@ async function getLicenseResourceInfo(user, licence) {
|
|
|
5553
5624
|
};
|
|
5554
5625
|
}
|
|
5555
5626
|
function getLicenceExpiryMode(licenceType) {
|
|
5556
|
-
return licenceType ===
|
|
5627
|
+
return licenceType === import_cluemart_shared39.EnumUserLicence.PRO_VENDOR || licenceType === import_cluemart_shared39.EnumUserLicence.PRO_PLUS_VENDOR ? "downgrade" : "extend";
|
|
5557
5628
|
}
|
|
5558
5629
|
async function sendLicenseReminder(user, licence) {
|
|
5559
5630
|
const licenceName = getLicenseName(licence.licenceType);
|
|
5560
|
-
const expiryDate = (0, import_dayjs9.default)(licence.expiryDate).format(
|
|
5631
|
+
const expiryDate = (0, import_dayjs9.default)(licence.expiryDate).format(import_cluemart_shared39.dateFormat);
|
|
5561
5632
|
const userId = String(user._id);
|
|
5562
5633
|
const resourceInfo = await getLicenseResourceInfo(user, licence);
|
|
5563
5634
|
if (!resourceInfo) {
|
|
@@ -5713,6 +5784,7 @@ async function remindUsersAboutLicenseExpiration() {
|
|
|
5713
5784
|
GoogleImportedMarketModel,
|
|
5714
5785
|
ImpersonationAuditModel,
|
|
5715
5786
|
ImpersonationSessionModel,
|
|
5787
|
+
LIVE_RESOURCE_FILTER,
|
|
5716
5788
|
LicenceCategory,
|
|
5717
5789
|
NotificationModel,
|
|
5718
5790
|
OwnerTypeSchema,
|
|
@@ -5766,6 +5838,7 @@ async function remindUsersAboutLicenseExpiration() {
|
|
|
5766
5838
|
express,
|
|
5767
5839
|
findAffiliateByPromoCode,
|
|
5768
5840
|
findEventOrImportedMarketById,
|
|
5841
|
+
findEventOrImportedMarketDetailsById,
|
|
5769
5842
|
getActiveLicenceForResource,
|
|
5770
5843
|
getAssociateAccessMeta,
|
|
5771
5844
|
getBillingCatalogDefinition,
|
|
@@ -5787,6 +5860,7 @@ async function remindUsersAboutLicenseExpiration() {
|
|
|
5787
5860
|
hasActiveProLicenceForResource,
|
|
5788
5861
|
hasValidLicence,
|
|
5789
5862
|
isAssociableResourceType,
|
|
5863
|
+
isLiveResource,
|
|
5790
5864
|
isProLicence,
|
|
5791
5865
|
isProtectedByCurrentStripeSubscription,
|
|
5792
5866
|
isStandardLicence,
|