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