@timardex/cluemart-server-shared 4.1.0 → 4.2.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-CpoM9_Bb.d.mts → Affiliate-Bilg9mgw.d.mts} +43 -4
- package/dist/{Affiliate-YoKkDGxN.d.ts → Affiliate-CfG8ctIo.d.ts} +43 -4
- package/dist/{chunk-U5WL3CZR.mjs → chunk-ABW2L2HY.mjs} +61 -2
- package/dist/chunk-ABW2L2HY.mjs.map +1 -0
- package/dist/index.cjs +645 -169
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.mts +252 -10
- package/dist/index.d.ts +252 -10
- package/dist/index.mjs +538 -70
- package/dist/index.mjs.map +1 -1
- package/dist/mongoose/index.cjs +60 -1
- package/dist/mongoose/index.cjs.map +1 -1
- package/dist/mongoose/index.d.mts +15 -9
- package/dist/mongoose/index.d.ts +15 -9
- package/dist/mongoose/index.mjs +3 -1
- package/dist/service/index.cjs +642 -168
- package/dist/service/index.cjs.map +1 -1
- package/dist/service/index.d.mts +200 -3
- package/dist/service/index.d.ts +200 -3
- package/dist/service/index.mjs +477 -68
- package/dist/service/index.mjs.map +1 -1
- package/package.json +2 -2
- package/dist/chunk-U5WL3CZR.mjs.map +0 -1
package/dist/service/index.cjs
CHANGED
|
@@ -35,6 +35,7 @@ __export(service_exports, {
|
|
|
35
35
|
REMINDER_WINDOW_MAX_HOURS: () => REMINDER_WINDOW_MAX_HOURS,
|
|
36
36
|
REMINDER_WINDOW_MIN_HOURS: () => REMINDER_WINDOW_MIN_HOURS,
|
|
37
37
|
SUBSCRIPTION_REWARD_TIMEZONE: () => SUBSCRIPTION_REWARD_TIMEZONE,
|
|
38
|
+
acceptedAssociateUserIds: () => acceptedAssociateUserIds,
|
|
38
39
|
activeAffiliateCodeExists: () => activeAffiliateCodeExists,
|
|
39
40
|
awardAffiliateVendorSubscriptionRewards: () => awardAffiliateVendorSubscriptionRewards,
|
|
40
41
|
buildLicenceExpiryPipeline: () => buildLicenceExpiryPipeline,
|
|
@@ -48,6 +49,9 @@ __export(service_exports, {
|
|
|
48
49
|
convertObjectIdsToStrings: () => convertObjectIdsToStrings,
|
|
49
50
|
createLicenceObject: () => createLicenceObject,
|
|
50
51
|
dedupeArchivedSlotsByStartDateTime: () => dedupeArchivedSlotsByStartDateTime,
|
|
52
|
+
detachAssociateGrantsForResources: () => detachAssociateGrantsForResources,
|
|
53
|
+
detachStaleAssociateGrants: () => detachStaleAssociateGrants,
|
|
54
|
+
detachUsersFromResource: () => detachUsersFromResource,
|
|
51
55
|
didRemoveAnyEventDates: () => didRemoveAnyEventDates,
|
|
52
56
|
didRemoveAnyStartedDates: () => didRemoveAnyStartedDates,
|
|
53
57
|
downgradeVendorProFeatures: () => downgradeVendorProFeatures,
|
|
@@ -57,6 +61,8 @@ __export(service_exports, {
|
|
|
57
61
|
eventLicences: () => eventLicences,
|
|
58
62
|
findAffiliateByPromoCode: () => findAffiliateByPromoCode,
|
|
59
63
|
findEventOrImportedMarketById: () => findEventOrImportedMarketById,
|
|
64
|
+
getActiveLicenceForResource: () => getActiveLicenceForResource,
|
|
65
|
+
getAssociateAccessMeta: () => getAssociateAccessMeta,
|
|
60
66
|
getEventResourceInfo: () => getEventResourceInfo,
|
|
61
67
|
getHighestLicenceForCategory: () => getHighestLicenceForCategory,
|
|
62
68
|
getLicenceCategory: () => getLicenceCategory,
|
|
@@ -66,11 +72,17 @@ __export(service_exports, {
|
|
|
66
72
|
getPayingStripeSubscriptionPlan: () => getPayingStripeSubscriptionPlan,
|
|
67
73
|
getPayingVendorStripeSubscriptionPlan: () => getPayingVendorStripeSubscriptionPlan,
|
|
68
74
|
getSubscriptionRewardPeriodBounds: () => getSubscriptionRewardPeriodBounds,
|
|
75
|
+
getUserIdsWithActiveProLicence: () => getUserIdsWithActiveProLicence,
|
|
69
76
|
getVendorResourceInfo: () => getVendorResourceInfo,
|
|
77
|
+
grantAssociateGrants: () => grantAssociateGrants,
|
|
70
78
|
handleEventLicenceCompliance: () => handleEventLicenceCompliance,
|
|
71
79
|
handlePartnerLicenceCompliance: () => handlePartnerLicenceCompliance,
|
|
72
80
|
handleVendorLicenceCompliance: () => handleVendorLicenceCompliance,
|
|
81
|
+
hasActiveProLicenceForResource: () => hasActiveProLicenceForResource,
|
|
73
82
|
hasValidLicence: () => hasValidLicence,
|
|
83
|
+
isAssociableResourceType: () => isAssociableResourceType,
|
|
84
|
+
isProLicence: () => isProLicence,
|
|
85
|
+
isProtectedByCurrentStripeSubscription: () => isProtectedByCurrentStripeSubscription,
|
|
74
86
|
isStandardLicence: () => isStandardLicence,
|
|
75
87
|
isValidObjectId: () => isValidObjectId,
|
|
76
88
|
licenceCategoryMapping: () => licenceCategoryMapping,
|
|
@@ -85,6 +97,7 @@ __export(service_exports, {
|
|
|
85
97
|
processUserCompliance: () => processUserCompliance,
|
|
86
98
|
processUserLicenseReminders: () => processUserLicenseReminders,
|
|
87
99
|
publishNotificationEvents: () => publishNotificationEvents,
|
|
100
|
+
reconcileAssociateGrants: () => reconcileAssociateGrants,
|
|
88
101
|
remindUsersAboutLicenseExpiration: () => remindUsersAboutLicenseExpiration,
|
|
89
102
|
replaceUserLicenceWithObject: () => replaceUserLicenceWithObject,
|
|
90
103
|
restoreVendorProFeatures: () => restoreVendorProFeatures,
|
|
@@ -98,7 +111,7 @@ __export(service_exports, {
|
|
|
98
111
|
updateAdStatuses: () => updateAdStatuses,
|
|
99
112
|
updateAllEventDateTimeStatuses: () => updateAllEventDateTimeStatuses,
|
|
100
113
|
updateRelationDatesToCanceled: () => updateRelationDatesToCanceled,
|
|
101
|
-
updateSingleDateTimeStatus: () =>
|
|
114
|
+
updateSingleDateTimeStatus: () => import_cluemart_shared39.updateSingleDateTimeStatus,
|
|
102
115
|
upgradeUserToLicence: () => upgradeUserToLicence,
|
|
103
116
|
vendorOwnerHasProLicence: () => vendorOwnerHasProLicence
|
|
104
117
|
});
|
|
@@ -766,6 +779,25 @@ var OwnerTypeSchema = new MongooseSchema5(
|
|
|
766
779
|
{ _id: false }
|
|
767
780
|
// Prevents Mongoose from creating an additional _id field for subdocuments
|
|
768
781
|
);
|
|
782
|
+
var AssociateTypeSchema = new MongooseSchema5(
|
|
783
|
+
{
|
|
784
|
+
addedAt: { default: Date.now, required: false, type: Date },
|
|
785
|
+
email: { lowercase: true, required: true, trim: true, type: String },
|
|
786
|
+
respondedAt: { default: null, required: false, type: Date },
|
|
787
|
+
status: {
|
|
788
|
+
default: import_cluemart_shared8.EnumAssociateStatus.PENDING,
|
|
789
|
+
enum: Object.values(import_cluemart_shared8.EnumAssociateStatus),
|
|
790
|
+
required: true,
|
|
791
|
+
type: String
|
|
792
|
+
},
|
|
793
|
+
userId: {
|
|
794
|
+
ref: "User",
|
|
795
|
+
required: true,
|
|
796
|
+
type: import_mongoose9.default.Schema.Types.ObjectId
|
|
797
|
+
}
|
|
798
|
+
},
|
|
799
|
+
{ _id: false }
|
|
800
|
+
);
|
|
769
801
|
var SocialMediaTypeSchema = new MongooseSchema5(
|
|
770
802
|
{
|
|
771
803
|
link: { required: true, type: String },
|
|
@@ -931,6 +963,7 @@ var baseResourceFields = {
|
|
|
931
963
|
type: [import_mongoose9.default.Schema.Types.ObjectId]
|
|
932
964
|
},
|
|
933
965
|
approvedAt: { default: null, required: false, type: Date },
|
|
966
|
+
associates: { default: [], required: false, type: [AssociateTypeSchema] },
|
|
934
967
|
contactDetails: { required: false, type: ContactDetailsSchema },
|
|
935
968
|
cover: {
|
|
936
969
|
required: true,
|
|
@@ -1810,6 +1843,29 @@ var userOverallPointsSchema = new MongooseSchema16(
|
|
|
1810
1843
|
},
|
|
1811
1844
|
{ _id: false }
|
|
1812
1845
|
);
|
|
1846
|
+
var userAssociatedResourcesSchema = new MongooseSchema16(
|
|
1847
|
+
{
|
|
1848
|
+
events: {
|
|
1849
|
+
default: [],
|
|
1850
|
+
ref: "Event",
|
|
1851
|
+
required: false,
|
|
1852
|
+
type: [import_mongoose20.default.Schema.Types.ObjectId]
|
|
1853
|
+
},
|
|
1854
|
+
partners: {
|
|
1855
|
+
default: [],
|
|
1856
|
+
ref: "Partner",
|
|
1857
|
+
required: false,
|
|
1858
|
+
type: [import_mongoose20.default.Schema.Types.ObjectId]
|
|
1859
|
+
},
|
|
1860
|
+
vendors: {
|
|
1861
|
+
default: [],
|
|
1862
|
+
ref: "Vendor",
|
|
1863
|
+
required: false,
|
|
1864
|
+
type: [import_mongoose20.default.Schema.Types.ObjectId]
|
|
1865
|
+
}
|
|
1866
|
+
},
|
|
1867
|
+
{ _id: false }
|
|
1868
|
+
);
|
|
1813
1869
|
var schema15 = new MongooseSchema16(
|
|
1814
1870
|
{
|
|
1815
1871
|
active: { default: false, required: true, type: Boolean },
|
|
@@ -1818,6 +1874,11 @@ var schema15 = new MongooseSchema16(
|
|
|
1818
1874
|
required: false,
|
|
1819
1875
|
type: import_mongoose20.default.Schema.Types.ObjectId
|
|
1820
1876
|
},
|
|
1877
|
+
associatedResources: {
|
|
1878
|
+
default: () => ({ events: [], partners: [], vendors: [] }),
|
|
1879
|
+
required: false,
|
|
1880
|
+
type: userAssociatedResourcesSchema
|
|
1881
|
+
},
|
|
1821
1882
|
avatar: {
|
|
1822
1883
|
required: false,
|
|
1823
1884
|
type: ResourceImageTypeSchema
|
|
@@ -1828,7 +1889,10 @@ var schema15 = new MongooseSchema16(
|
|
|
1828
1889
|
type: import_mongoose20.default.Schema.Types.ObjectId
|
|
1829
1890
|
},
|
|
1830
1891
|
deletedAt: { default: null, required: false, type: Date },
|
|
1831
|
-
|
|
1892
|
+
// `normalizeEmail` (`cluemart-shared`) is trim + lower-case; keeping the same
|
|
1893
|
+
// rule here means every write path — resolvers, seeds, scripts — stores the
|
|
1894
|
+
// comparable form, not only the clients that validate through `emailRequiredSchema`.
|
|
1895
|
+
email: { lowercase: true, required: true, trim: true, type: String },
|
|
1832
1896
|
emailSentFor: {
|
|
1833
1897
|
enum: Object.values(import_cluemart_shared16.EnumNotificationResourceType),
|
|
1834
1898
|
required: false,
|
|
@@ -1943,6 +2007,9 @@ schema15.index({ "licences.expiryDate": 1 });
|
|
|
1943
2007
|
schema15.index({ "licences.licenceType": 1 });
|
|
1944
2008
|
schema15.index({ promoCodes: 1, active: 1, deletedAt: 1 });
|
|
1945
2009
|
schema15.index({ email: "text", firstName: "text", lastName: "text" });
|
|
2010
|
+
schema15.index({ "associatedResources.events": 1 });
|
|
2011
|
+
schema15.index({ "associatedResources.partners": 1 });
|
|
2012
|
+
schema15.index({ "associatedResources.vendors": 1 });
|
|
1946
2013
|
var UserModel = import_mongoose20.default.models.User || import_mongoose20.default.model("User", schema15);
|
|
1947
2014
|
|
|
1948
2015
|
// src/mongoose/VerificationToken.ts
|
|
@@ -2076,6 +2143,7 @@ schema17.index({
|
|
|
2076
2143
|
name: "text"
|
|
2077
2144
|
});
|
|
2078
2145
|
schema17.index({ deletedAt: 1, "owner.userId": 1 });
|
|
2146
|
+
schema17.index({ "associates.userId": 1, deletedAt: 1 });
|
|
2079
2147
|
schema17.plugin(searchNamePlugin);
|
|
2080
2148
|
var VendorModel = import_mongoose22.default.models.Vendor || import_mongoose22.default.model("Vendor", schema17);
|
|
2081
2149
|
|
|
@@ -2227,6 +2295,7 @@ schema20.index({ "dateTime.dateStatus": 1 });
|
|
|
2227
2295
|
schema20.index({ slug: 1 });
|
|
2228
2296
|
schema20.index({ description: "text", name: "text", tags: "text" });
|
|
2229
2297
|
schema20.index({ deletedAt: 1, "owner.userId": 1 });
|
|
2298
|
+
schema20.index({ "associates.userId": 1, deletedAt: 1 });
|
|
2230
2299
|
schema20.plugin(searchNamePlugin);
|
|
2231
2300
|
var EventModel = import_mongoose25.default.models.Event || import_mongoose25.default.model("Event", schema20);
|
|
2232
2301
|
|
|
@@ -2273,6 +2342,7 @@ schema22.index({ "location.geo": "2dsphere" });
|
|
|
2273
2342
|
schema22.index({ slug: 1 });
|
|
2274
2343
|
schema22.index({ name: "text", description: "text" });
|
|
2275
2344
|
schema22.index({ "owner.userId": 1, deletedAt: 1 });
|
|
2345
|
+
schema22.index({ "associates.userId": 1, deletedAt: 1 });
|
|
2276
2346
|
schema22.plugin(searchNamePlugin);
|
|
2277
2347
|
var PartnerModel = import_mongoose27.default.models.Partner || import_mongoose27.default.model("Partner", schema22);
|
|
2278
2348
|
|
|
@@ -3338,14 +3408,310 @@ function normalizeAffiliatePromoCodes(promoCodes) {
|
|
|
3338
3408
|
return [...new Set(normalized)];
|
|
3339
3409
|
}
|
|
3340
3410
|
|
|
3411
|
+
// src/service/associates/index.ts
|
|
3412
|
+
var import_cluemart_shared28 = require("@timardex/cluemart-shared");
|
|
3413
|
+
var import_mongoose42 = __toESM(require("mongoose"));
|
|
3414
|
+
function isAssociableResourceType(resourceType) {
|
|
3415
|
+
return resourceType === import_cluemart_shared28.EnumResourceType.EVENT || resourceType === import_cluemart_shared28.EnumResourceType.PARTNER || resourceType === import_cluemart_shared28.EnumResourceType.VENDOR;
|
|
3416
|
+
}
|
|
3417
|
+
function getAssociateAccessMeta(resourceType) {
|
|
3418
|
+
if (resourceType === import_cluemart_shared28.EnumResourceType.EVENT) {
|
|
3419
|
+
return {
|
|
3420
|
+
associatedField: "events",
|
|
3421
|
+
associatedPath: "associatedResources.events",
|
|
3422
|
+
associateRole: import_cluemart_shared28.EnumUserRole.ASSOCIATED_EVENT
|
|
3423
|
+
};
|
|
3424
|
+
}
|
|
3425
|
+
if (resourceType === import_cluemart_shared28.EnumResourceType.PARTNER) {
|
|
3426
|
+
return {
|
|
3427
|
+
associatedField: "partners",
|
|
3428
|
+
associatedPath: "associatedResources.partners",
|
|
3429
|
+
associateRole: import_cluemart_shared28.EnumUserRole.ASSOCIATED_PARTNER
|
|
3430
|
+
};
|
|
3431
|
+
}
|
|
3432
|
+
return {
|
|
3433
|
+
associatedField: "vendors",
|
|
3434
|
+
associatedPath: "associatedResources.vendors",
|
|
3435
|
+
associateRole: import_cluemart_shared28.EnumUserRole.ASSOCIATED_VENDOR
|
|
3436
|
+
};
|
|
3437
|
+
}
|
|
3438
|
+
var ASSOCIABLE_MODELS = {
|
|
3439
|
+
[import_cluemart_shared28.EnumResourceType.EVENT]: EventModel,
|
|
3440
|
+
[import_cluemart_shared28.EnumResourceType.PARTNER]: PartnerModel,
|
|
3441
|
+
[import_cluemart_shared28.EnumResourceType.VENDOR]: VendorModel
|
|
3442
|
+
};
|
|
3443
|
+
function acceptedAssociateUserIds(associates) {
|
|
3444
|
+
return (associates ?? []).filter((associate) => associate.status === import_cluemart_shared28.EnumAssociateStatus.ACCEPTED).map((associate) => associate.userId);
|
|
3445
|
+
}
|
|
3446
|
+
async function detachUsersFromResource({
|
|
3447
|
+
resourceId,
|
|
3448
|
+
resourceType,
|
|
3449
|
+
userIds
|
|
3450
|
+
}) {
|
|
3451
|
+
if (userIds.length === 0) return;
|
|
3452
|
+
const { associateRole, associatedPath: path } = getAssociateAccessMeta(resourceType);
|
|
3453
|
+
const removedResourceId = typeof resourceId === "string" ? new import_mongoose42.default.Types.ObjectId(resourceId) : resourceId;
|
|
3454
|
+
await UserModel.updateMany({ _id: { $in: userIds } }, [
|
|
3455
|
+
{
|
|
3456
|
+
$set: {
|
|
3457
|
+
[path]: {
|
|
3458
|
+
$setDifference: [{ $ifNull: [`$${path}`, []] }, [removedResourceId]]
|
|
3459
|
+
}
|
|
3460
|
+
}
|
|
3461
|
+
},
|
|
3462
|
+
{
|
|
3463
|
+
$set: {
|
|
3464
|
+
roles: {
|
|
3465
|
+
$cond: [
|
|
3466
|
+
{ $eq: [{ $size: { $ifNull: [`$${path}`, []] } }, 0] },
|
|
3467
|
+
{
|
|
3468
|
+
$setDifference: [{ $ifNull: ["$roles", []] }, [associateRole]]
|
|
3469
|
+
},
|
|
3470
|
+
"$roles"
|
|
3471
|
+
]
|
|
3472
|
+
}
|
|
3473
|
+
}
|
|
3474
|
+
}
|
|
3475
|
+
]).exec();
|
|
3476
|
+
}
|
|
3477
|
+
async function acceptedUserIdsForResource({
|
|
3478
|
+
resourceId,
|
|
3479
|
+
resourceType
|
|
3480
|
+
}) {
|
|
3481
|
+
const model = ASSOCIABLE_MODELS[resourceType];
|
|
3482
|
+
const resource = await model.findOne({ _id: resourceId, deletedAt: null }).select("associates").lean().exec();
|
|
3483
|
+
return new Set(
|
|
3484
|
+
acceptedAssociateUserIds(resource?.associates).map(
|
|
3485
|
+
(userId) => String(userId)
|
|
3486
|
+
)
|
|
3487
|
+
);
|
|
3488
|
+
}
|
|
3489
|
+
async function grantAssociateGrants({
|
|
3490
|
+
resourceId,
|
|
3491
|
+
resourceType,
|
|
3492
|
+
userIds
|
|
3493
|
+
}) {
|
|
3494
|
+
if (userIds.length === 0) return;
|
|
3495
|
+
const acceptedUserIds = await acceptedUserIdsForResource({
|
|
3496
|
+
resourceId,
|
|
3497
|
+
resourceType
|
|
3498
|
+
});
|
|
3499
|
+
const grantUserIds = userIds.filter(
|
|
3500
|
+
(userId) => acceptedUserIds.has(String(userId))
|
|
3501
|
+
);
|
|
3502
|
+
if (grantUserIds.length === 0) return;
|
|
3503
|
+
const { associateRole, associatedPath } = getAssociateAccessMeta(resourceType);
|
|
3504
|
+
await UserModel.updateMany(
|
|
3505
|
+
{ _id: { $in: grantUserIds } },
|
|
3506
|
+
{
|
|
3507
|
+
$addToSet: {
|
|
3508
|
+
[associatedPath]: resourceId,
|
|
3509
|
+
roles: associateRole
|
|
3510
|
+
}
|
|
3511
|
+
}
|
|
3512
|
+
).exec();
|
|
3513
|
+
}
|
|
3514
|
+
async function detachUnlessStillAccepted({
|
|
3515
|
+
resourceId,
|
|
3516
|
+
resourceType,
|
|
3517
|
+
userIds
|
|
3518
|
+
}) {
|
|
3519
|
+
if (userIds.length === 0) return [];
|
|
3520
|
+
await detachUsersFromResource({ resourceId, resourceType, userIds });
|
|
3521
|
+
const acceptedAfterDetach = await acceptedUserIdsForResource({
|
|
3522
|
+
resourceId,
|
|
3523
|
+
resourceType
|
|
3524
|
+
});
|
|
3525
|
+
const restoredUserIds = userIds.filter(
|
|
3526
|
+
(userId) => acceptedAfterDetach.has(String(userId))
|
|
3527
|
+
);
|
|
3528
|
+
if (restoredUserIds.length === 0) return userIds;
|
|
3529
|
+
await grantAssociateGrants({
|
|
3530
|
+
resourceId,
|
|
3531
|
+
resourceType,
|
|
3532
|
+
userIds: restoredUserIds
|
|
3533
|
+
});
|
|
3534
|
+
const acceptedAfterRestore = await acceptedUserIdsForResource({
|
|
3535
|
+
resourceId,
|
|
3536
|
+
resourceType
|
|
3537
|
+
});
|
|
3538
|
+
const regressedUserIds = restoredUserIds.filter(
|
|
3539
|
+
(userId) => !acceptedAfterRestore.has(String(userId))
|
|
3540
|
+
);
|
|
3541
|
+
if (regressedUserIds.length > 0) {
|
|
3542
|
+
await detachUsersFromResource({
|
|
3543
|
+
resourceId,
|
|
3544
|
+
resourceType,
|
|
3545
|
+
userIds: regressedUserIds
|
|
3546
|
+
});
|
|
3547
|
+
}
|
|
3548
|
+
return userIds.filter((userId) => !acceptedAfterRestore.has(String(userId)));
|
|
3549
|
+
}
|
|
3550
|
+
async function detachStaleAssociateGrants({
|
|
3551
|
+
acceptedUserIds,
|
|
3552
|
+
resourceId,
|
|
3553
|
+
resourceType
|
|
3554
|
+
}) {
|
|
3555
|
+
const { associatedPath } = getAssociateAccessMeta(resourceType);
|
|
3556
|
+
const stale = await UserModel.find({
|
|
3557
|
+
_id: { $nin: acceptedUserIds },
|
|
3558
|
+
[associatedPath]: resourceId
|
|
3559
|
+
}).select("_id").lean().exec();
|
|
3560
|
+
const staleUserIds = stale.map((user) => user._id);
|
|
3561
|
+
return detachUnlessStillAccepted({
|
|
3562
|
+
resourceId,
|
|
3563
|
+
resourceType,
|
|
3564
|
+
userIds: staleUserIds
|
|
3565
|
+
});
|
|
3566
|
+
}
|
|
3567
|
+
async function detachAssociateGrantsForResources({
|
|
3568
|
+
resources
|
|
3569
|
+
}) {
|
|
3570
|
+
const result = resources.map((resource) => ({
|
|
3571
|
+
detachedUserIds: [],
|
|
3572
|
+
resourceId: resource.resourceId,
|
|
3573
|
+
resourceType: resource.resourceType
|
|
3574
|
+
}));
|
|
3575
|
+
const indexByType = /* @__PURE__ */ new Map();
|
|
3576
|
+
resources.forEach((resource, index) => {
|
|
3577
|
+
const entries = indexByType.get(resource.resourceType) ?? [];
|
|
3578
|
+
entries.push({ index, resourceId: resource.resourceId });
|
|
3579
|
+
indexByType.set(resource.resourceType, entries);
|
|
3580
|
+
});
|
|
3581
|
+
for (const [resourceType, entries] of indexByType) {
|
|
3582
|
+
const { associatedField, associatedPath } = getAssociateAccessMeta(resourceType);
|
|
3583
|
+
const resourceIds = entries.map((entry) => entry.resourceId);
|
|
3584
|
+
const wanted = new Set(resourceIds.map((resourceId) => String(resourceId)));
|
|
3585
|
+
const holders = await UserModel.find({
|
|
3586
|
+
[associatedPath]: { $in: resourceIds }
|
|
3587
|
+
}).select("_id associatedResources").lean().exec();
|
|
3588
|
+
const userIdsByResource = /* @__PURE__ */ new Map();
|
|
3589
|
+
for (const user of holders) {
|
|
3590
|
+
for (const heldResourceId of user.associatedResources?.[associatedField] ?? []) {
|
|
3591
|
+
const key = String(heldResourceId);
|
|
3592
|
+
if (!wanted.has(key)) continue;
|
|
3593
|
+
const userIds = userIdsByResource.get(key) ?? [];
|
|
3594
|
+
userIds.push(user._id);
|
|
3595
|
+
userIdsByResource.set(key, userIds);
|
|
3596
|
+
}
|
|
3597
|
+
}
|
|
3598
|
+
for (const entry of entries) {
|
|
3599
|
+
const userIds = userIdsByResource.get(String(entry.resourceId));
|
|
3600
|
+
if (!userIds || userIds.length === 0) continue;
|
|
3601
|
+
await detachUsersFromResource({
|
|
3602
|
+
resourceId: entry.resourceId,
|
|
3603
|
+
resourceType,
|
|
3604
|
+
userIds
|
|
3605
|
+
});
|
|
3606
|
+
result[entry.index].detachedUserIds = userIds;
|
|
3607
|
+
}
|
|
3608
|
+
}
|
|
3609
|
+
return result;
|
|
3610
|
+
}
|
|
3611
|
+
var DEFAULT_RECONCILE_BATCH_SIZE = 500;
|
|
3612
|
+
async function reconcileUserBatch({
|
|
3613
|
+
associatedField,
|
|
3614
|
+
model,
|
|
3615
|
+
resourceType,
|
|
3616
|
+
users
|
|
3617
|
+
}) {
|
|
3618
|
+
const heldByResource = /* @__PURE__ */ new Map();
|
|
3619
|
+
for (const user of users) {
|
|
3620
|
+
for (const resourceId of user.associatedResources?.[associatedField] ?? []) {
|
|
3621
|
+
const key = String(resourceId);
|
|
3622
|
+
const entry = heldByResource.get(key) ?? { resourceId, userIds: [] };
|
|
3623
|
+
entry.userIds.push(user._id);
|
|
3624
|
+
heldByResource.set(key, entry);
|
|
3625
|
+
}
|
|
3626
|
+
}
|
|
3627
|
+
if (heldByResource.size === 0) return 0;
|
|
3628
|
+
const resources = await model.find({
|
|
3629
|
+
_id: {
|
|
3630
|
+
$in: [...heldByResource.values()].map((entry) => entry.resourceId)
|
|
3631
|
+
}
|
|
3632
|
+
}).select("associates deletedAt").lean().exec();
|
|
3633
|
+
const acceptedByResource = /* @__PURE__ */ new Map();
|
|
3634
|
+
for (const resource of resources) {
|
|
3635
|
+
acceptedByResource.set(
|
|
3636
|
+
String(resource._id),
|
|
3637
|
+
resource.deletedAt ? /* @__PURE__ */ new Set() : new Set(
|
|
3638
|
+
acceptedAssociateUserIds(resource.associates).map(
|
|
3639
|
+
(userId) => String(userId)
|
|
3640
|
+
)
|
|
3641
|
+
)
|
|
3642
|
+
);
|
|
3643
|
+
}
|
|
3644
|
+
let detachedGrants = 0;
|
|
3645
|
+
for (const [key, { resourceId, userIds }] of heldByResource) {
|
|
3646
|
+
const accepted = acceptedByResource.get(key);
|
|
3647
|
+
const staleUserIds = userIds.filter(
|
|
3648
|
+
(userId) => !accepted?.has(String(userId))
|
|
3649
|
+
);
|
|
3650
|
+
if (staleUserIds.length === 0) continue;
|
|
3651
|
+
const removedUserIds = await detachUnlessStillAccepted({
|
|
3652
|
+
resourceId,
|
|
3653
|
+
resourceType,
|
|
3654
|
+
userIds: staleUserIds
|
|
3655
|
+
});
|
|
3656
|
+
detachedGrants += removedUserIds.length;
|
|
3657
|
+
}
|
|
3658
|
+
return detachedGrants;
|
|
3659
|
+
}
|
|
3660
|
+
async function reconcileResourceType({
|
|
3661
|
+
batchSize,
|
|
3662
|
+
resourceType
|
|
3663
|
+
}) {
|
|
3664
|
+
const { associatedField, associatedPath } = getAssociateAccessMeta(resourceType);
|
|
3665
|
+
const model = ASSOCIABLE_MODELS[resourceType];
|
|
3666
|
+
const result = {
|
|
3667
|
+
detachedGrants: 0,
|
|
3668
|
+
scannedUsers: 0
|
|
3669
|
+
};
|
|
3670
|
+
let lastId = null;
|
|
3671
|
+
for (; ; ) {
|
|
3672
|
+
const users = await UserModel.find({
|
|
3673
|
+
...lastId ? { _id: { $gt: lastId } } : {},
|
|
3674
|
+
[associatedPath]: { $exists: true, $ne: [] }
|
|
3675
|
+
}).sort({ _id: 1 }).limit(batchSize).select("_id associatedResources").lean().exec();
|
|
3676
|
+
if (users.length === 0) break;
|
|
3677
|
+
result.scannedUsers += users.length;
|
|
3678
|
+
lastId = users[users.length - 1]._id;
|
|
3679
|
+
result.detachedGrants += await reconcileUserBatch({
|
|
3680
|
+
associatedField,
|
|
3681
|
+
model,
|
|
3682
|
+
resourceType,
|
|
3683
|
+
users
|
|
3684
|
+
});
|
|
3685
|
+
}
|
|
3686
|
+
return result;
|
|
3687
|
+
}
|
|
3688
|
+
async function reconcileAssociateGrants({
|
|
3689
|
+
batchSize = DEFAULT_RECONCILE_BATCH_SIZE
|
|
3690
|
+
} = {}) {
|
|
3691
|
+
const totals = {
|
|
3692
|
+
detachedGrants: 0,
|
|
3693
|
+
scannedUsers: 0
|
|
3694
|
+
};
|
|
3695
|
+
for (const resourceType of [
|
|
3696
|
+
import_cluemart_shared28.EnumResourceType.EVENT,
|
|
3697
|
+
import_cluemart_shared28.EnumResourceType.VENDOR,
|
|
3698
|
+
import_cluemart_shared28.EnumResourceType.PARTNER
|
|
3699
|
+
]) {
|
|
3700
|
+
const result = await reconcileResourceType({ batchSize, resourceType });
|
|
3701
|
+
totals.detachedGrants += result.detachedGrants;
|
|
3702
|
+
totals.scannedUsers += result.scannedUsers;
|
|
3703
|
+
}
|
|
3704
|
+
return totals;
|
|
3705
|
+
}
|
|
3706
|
+
|
|
3341
3707
|
// src/service/database.ts
|
|
3342
|
-
var
|
|
3708
|
+
var import_mongoose44 = __toESM(require("mongoose"));
|
|
3343
3709
|
|
|
3344
3710
|
// src/service/indexes.ts
|
|
3345
|
-
var
|
|
3711
|
+
var import_mongoose43 = __toESM(require("mongoose"));
|
|
3346
3712
|
function registeredModels() {
|
|
3347
|
-
return
|
|
3348
|
-
const model =
|
|
3713
|
+
return import_mongoose43.default.modelNames().map((modelName) => {
|
|
3714
|
+
const model = import_mongoose43.default.model(modelName);
|
|
3349
3715
|
return { createIndexes: () => model.createIndexes(), modelName };
|
|
3350
3716
|
});
|
|
3351
3717
|
}
|
|
@@ -3387,7 +3753,7 @@ var connectToDatabase = async ({
|
|
|
3387
3753
|
// Fallback to MongoDB Atlas connection string
|
|
3388
3754
|
`mongodb+srv://${dbUser}:${dbPassword}@${dbName}.mongodb.net/?retryWrites=true&w=majority&appName=${appName}`
|
|
3389
3755
|
);
|
|
3390
|
-
await
|
|
3756
|
+
await import_mongoose44.default.connect(mongoUri);
|
|
3391
3757
|
const connectionType = mongodbUri ? "Local MongoDB" : "MongoDB Atlas";
|
|
3392
3758
|
console.log(
|
|
3393
3759
|
`${connectionType} connected from server/src/service/database.ts`
|
|
@@ -3403,7 +3769,7 @@ var connectToDatabase = async ({
|
|
|
3403
3769
|
|
|
3404
3770
|
// src/types/index.ts
|
|
3405
3771
|
var import_express = __toESM(require("express"));
|
|
3406
|
-
var
|
|
3772
|
+
var import_mongoose45 = __toESM(require("mongoose"));
|
|
3407
3773
|
|
|
3408
3774
|
// src/service/notifyUsers.ts
|
|
3409
3775
|
async function publishNotificationEvents(userId, pubsub) {
|
|
@@ -3451,9 +3817,9 @@ async function notifyUsers({
|
|
|
3451
3817
|
}
|
|
3452
3818
|
|
|
3453
3819
|
// src/service/updateAdStatus.ts
|
|
3454
|
-
var
|
|
3820
|
+
var import_cluemart_shared29 = require("@timardex/cluemart-shared");
|
|
3455
3821
|
async function updateAdStatuses() {
|
|
3456
|
-
const now = (0,
|
|
3822
|
+
const now = (0, import_cluemart_shared29.nzDayKey)();
|
|
3457
3823
|
const invalidResult = await AdModel.updateMany(
|
|
3458
3824
|
{
|
|
3459
3825
|
$or: [
|
|
@@ -3461,50 +3827,50 @@ async function updateAdStatuses() {
|
|
|
3461
3827
|
{ end: { $exists: false } },
|
|
3462
3828
|
{ $expr: { $gt: ["$start", "$end"] } }
|
|
3463
3829
|
],
|
|
3464
|
-
status: { $ne:
|
|
3830
|
+
status: { $ne: import_cluemart_shared29.EnumAdStatus.PAUSED }
|
|
3465
3831
|
},
|
|
3466
|
-
{ $set: { status:
|
|
3832
|
+
{ $set: { status: import_cluemart_shared29.EnumAdStatus.PAUSED } }
|
|
3467
3833
|
);
|
|
3468
3834
|
const expiredResult = await AdModel.updateMany(
|
|
3469
|
-
{ end: { $lte: now }, status: { $ne:
|
|
3470
|
-
{ $set: { status:
|
|
3835
|
+
{ end: { $lte: now }, status: { $ne: import_cluemart_shared29.EnumAdStatus.EXPIRED } },
|
|
3836
|
+
{ $set: { status: import_cluemart_shared29.EnumAdStatus.EXPIRED } }
|
|
3471
3837
|
);
|
|
3472
3838
|
const eligibleBooking = {
|
|
3473
3839
|
$or: [
|
|
3474
3840
|
{ bookingKind: { $exists: false } },
|
|
3475
3841
|
{ bookingKind: null },
|
|
3476
3842
|
{
|
|
3477
|
-
approvalStatus:
|
|
3478
|
-
bookingKind:
|
|
3843
|
+
approvalStatus: import_cluemart_shared29.EnumAdApprovalStatus.APPROVED,
|
|
3844
|
+
bookingKind: import_cluemart_shared29.EnumAdBookingSlotKind.RESERVED
|
|
3479
3845
|
},
|
|
3480
3846
|
{
|
|
3481
|
-
approvalStatus:
|
|
3482
|
-
bookingKind:
|
|
3483
|
-
paymentStatus:
|
|
3847
|
+
approvalStatus: import_cluemart_shared29.EnumAdApprovalStatus.APPROVED,
|
|
3848
|
+
bookingKind: import_cluemart_shared29.EnumAdBookingSlotKind.PAID,
|
|
3849
|
+
paymentStatus: import_cluemart_shared29.EnumAdPaymentStatus.PAID
|
|
3484
3850
|
}
|
|
3485
3851
|
]
|
|
3486
3852
|
};
|
|
3487
3853
|
const awaitingApprovalResult = await AdModel.updateMany(
|
|
3488
3854
|
{
|
|
3489
3855
|
$nor: eligibleBooking.$or,
|
|
3490
|
-
bookingKind: { $in: Object.values(
|
|
3856
|
+
bookingKind: { $in: Object.values(import_cluemart_shared29.EnumAdBookingSlotKind) },
|
|
3491
3857
|
end: { $gt: now },
|
|
3492
|
-
status:
|
|
3858
|
+
status: import_cluemart_shared29.EnumAdStatus.ACTIVE
|
|
3493
3859
|
},
|
|
3494
|
-
{ $set: { status:
|
|
3860
|
+
{ $set: { status: import_cluemart_shared29.EnumAdStatus.PAUSED } }
|
|
3495
3861
|
);
|
|
3496
3862
|
const activeResult = await AdModel.updateMany(
|
|
3497
3863
|
{
|
|
3498
3864
|
end: { $gt: now },
|
|
3499
3865
|
start: { $lte: now },
|
|
3500
|
-
status: { $ne:
|
|
3866
|
+
status: { $ne: import_cluemart_shared29.EnumAdStatus.ACTIVE },
|
|
3501
3867
|
...eligibleBooking
|
|
3502
3868
|
},
|
|
3503
|
-
{ $set: { status:
|
|
3869
|
+
{ $set: { status: import_cluemart_shared29.EnumAdStatus.ACTIVE } }
|
|
3504
3870
|
);
|
|
3505
3871
|
const pausedResult = await AdModel.updateMany(
|
|
3506
|
-
{ start: { $gt: now }, status: { $ne:
|
|
3507
|
-
{ $set: { status:
|
|
3872
|
+
{ start: { $gt: now }, status: { $ne: import_cluemart_shared29.EnumAdStatus.PAUSED } },
|
|
3873
|
+
{ $set: { status: import_cluemart_shared29.EnumAdStatus.PAUSED } }
|
|
3508
3874
|
);
|
|
3509
3875
|
console.log(
|
|
3510
3876
|
`\u2705 Ad statuses updated: invalid=${invalidResult.modifiedCount}, expired=${expiredResult.modifiedCount}, awaitingApproval=${awaitingApprovalResult.modifiedCount}, active=${activeResult.modifiedCount}, paused=${pausedResult.modifiedCount}`
|
|
@@ -3512,15 +3878,15 @@ async function updateAdStatuses() {
|
|
|
3512
3878
|
}
|
|
3513
3879
|
|
|
3514
3880
|
// src/service/objectIdToString.ts
|
|
3515
|
-
var
|
|
3881
|
+
var import_mongoose47 = __toESM(require("mongoose"));
|
|
3516
3882
|
function isValidObjectId(value) {
|
|
3517
|
-
return
|
|
3883
|
+
return import_mongoose47.default.Types.ObjectId.isValid(value);
|
|
3518
3884
|
}
|
|
3519
3885
|
function convertObjectIdsToStrings(obj) {
|
|
3520
3886
|
if (obj === null || obj === void 0) {
|
|
3521
3887
|
return obj;
|
|
3522
3888
|
}
|
|
3523
|
-
if (obj instanceof
|
|
3889
|
+
if (obj instanceof import_mongoose47.default.Types.ObjectId) {
|
|
3524
3890
|
return obj.toString();
|
|
3525
3891
|
}
|
|
3526
3892
|
if (obj instanceof Date) {
|
|
@@ -3714,19 +4080,19 @@ function buildUserPointEntryRemovalPipeline(pointType, sourceId) {
|
|
|
3714
4080
|
}
|
|
3715
4081
|
|
|
3716
4082
|
// src/service/event/updateAllEventDateTimeStatuses.ts
|
|
3717
|
-
var
|
|
4083
|
+
var import_cluemart_shared31 = require("@timardex/cluemart-shared");
|
|
3718
4084
|
var import_dayjs4 = __toESM(require("dayjs"));
|
|
3719
4085
|
|
|
3720
4086
|
// src/service/event/archiveEndedEventDates.ts
|
|
3721
|
-
var
|
|
4087
|
+
var import_cluemart_shared30 = require("@timardex/cluemart-shared");
|
|
3722
4088
|
var import_dayjs3 = __toESM(require("dayjs"));
|
|
3723
4089
|
var import_customParseFormat = __toESM(require("dayjs/plugin/customParseFormat"));
|
|
3724
4090
|
import_dayjs3.default.extend(import_customParseFormat.default);
|
|
3725
4091
|
var ARCHIVED_STATUSES = /* @__PURE__ */ new Set([
|
|
3726
|
-
|
|
4092
|
+
import_cluemart_shared30.EnumEventDateStatus.ENDED
|
|
3727
4093
|
]);
|
|
3728
4094
|
var DISCARDED_STATUSES = /* @__PURE__ */ new Set([
|
|
3729
|
-
|
|
4095
|
+
import_cluemart_shared30.EnumEventDateStatus.INVALID
|
|
3730
4096
|
]);
|
|
3731
4097
|
function splitEventDatesForArchive(dateTime) {
|
|
3732
4098
|
return {
|
|
@@ -3749,12 +4115,12 @@ function dedupeArchivedSlotsByStartDateTime(slots) {
|
|
|
3749
4115
|
});
|
|
3750
4116
|
}
|
|
3751
4117
|
function isPastCanceledEventDate(slot, now) {
|
|
3752
|
-
if (slot.dateStatus !==
|
|
4118
|
+
if (slot.dateStatus !== import_cluemart_shared30.EnumEventDateStatus.CANCELED) {
|
|
3753
4119
|
return false;
|
|
3754
4120
|
}
|
|
3755
4121
|
const endDateTime = (0, import_dayjs3.default)(
|
|
3756
4122
|
`${slot.endDate} ${slot.endTime}`,
|
|
3757
|
-
`${
|
|
4123
|
+
`${import_cluemart_shared30.dateFormat} ${import_cluemart_shared30.timeFormat}`,
|
|
3758
4124
|
true
|
|
3759
4125
|
);
|
|
3760
4126
|
return endDateTime.isValid() && endDateTime.isBefore(now);
|
|
@@ -3800,7 +4166,7 @@ async function updateModelDateTimeStatuses(model, now) {
|
|
|
3800
4166
|
try {
|
|
3801
4167
|
for await (const doc of cursor) {
|
|
3802
4168
|
const dateTime = doc.dateTime.map(
|
|
3803
|
-
(slot) => (0,
|
|
4169
|
+
(slot) => (0, import_cluemart_shared31.updateSingleDateTimeStatus)(slot, now)
|
|
3804
4170
|
);
|
|
3805
4171
|
if (!hasDateTimeStatusChanges(doc.dateTime, dateTime)) {
|
|
3806
4172
|
continue;
|
|
@@ -3824,9 +4190,9 @@ async function updateModelDateTimeStatuses(model, now) {
|
|
|
3824
4190
|
var ARCHIVABLE_EVENT_FILTER = {
|
|
3825
4191
|
"dateTime.dateStatus": {
|
|
3826
4192
|
$in: [
|
|
3827
|
-
|
|
3828
|
-
|
|
3829
|
-
|
|
4193
|
+
import_cluemart_shared31.EnumEventDateStatus.ENDED,
|
|
4194
|
+
import_cluemart_shared31.EnumEventDateStatus.INVALID,
|
|
4195
|
+
import_cluemart_shared31.EnumEventDateStatus.CANCELED
|
|
3830
4196
|
]
|
|
3831
4197
|
},
|
|
3832
4198
|
deletedAt: null
|
|
@@ -3851,7 +4217,7 @@ async function archiveEndedAndDiscardInvalidEventDates(now) {
|
|
|
3851
4217
|
try {
|
|
3852
4218
|
for await (const doc of cursor) {
|
|
3853
4219
|
const updated = doc.dateTime.map(
|
|
3854
|
-
(slot) => (0,
|
|
4220
|
+
(slot) => (0, import_cluemart_shared31.updateSingleDateTimeStatus)(slot, now)
|
|
3855
4221
|
);
|
|
3856
4222
|
const { archive, discard } = splitEventDatesForArchive(updated);
|
|
3857
4223
|
const pastCanceled = updated.filter(
|
|
@@ -3875,13 +4241,13 @@ async function archiveEndedAndDiscardInvalidEventDates(now) {
|
|
|
3875
4241
|
if (archive.length > 0 || discard.length > 0) {
|
|
3876
4242
|
pullConditions.push({
|
|
3877
4243
|
dateStatus: {
|
|
3878
|
-
$in: [
|
|
4244
|
+
$in: [import_cluemart_shared31.EnumEventDateStatus.ENDED, import_cluemart_shared31.EnumEventDateStatus.INVALID]
|
|
3879
4245
|
}
|
|
3880
4246
|
});
|
|
3881
4247
|
}
|
|
3882
4248
|
for (const slot of pastCanceled) {
|
|
3883
4249
|
pullConditions.push({
|
|
3884
|
-
dateStatus:
|
|
4250
|
+
dateStatus: import_cluemart_shared31.EnumEventDateStatus.CANCELED,
|
|
3885
4251
|
startDate: slot.startDate,
|
|
3886
4252
|
startTime: slot.startTime
|
|
3887
4253
|
});
|
|
@@ -3923,9 +4289,9 @@ async function cleanEventInfoDates(now) {
|
|
|
3923
4289
|
try {
|
|
3924
4290
|
for await (const doc of cursor) {
|
|
3925
4291
|
const updated = doc.dateTime.map(
|
|
3926
|
-
(slot) => (0,
|
|
4292
|
+
(slot) => (0, import_cluemart_shared31.updateSingleDateTimeStatus)(slot, now)
|
|
3927
4293
|
);
|
|
3928
|
-
const kept = (0,
|
|
4294
|
+
const kept = (0, import_cluemart_shared31.filterDatesByFutureStatus)(updated);
|
|
3929
4295
|
if (kept.length === updated.length) {
|
|
3930
4296
|
continue;
|
|
3931
4297
|
}
|
|
@@ -3975,7 +4341,7 @@ async function updateAllEventDateTimeStatuses() {
|
|
|
3975
4341
|
}
|
|
3976
4342
|
|
|
3977
4343
|
// src/service/index.ts
|
|
3978
|
-
var
|
|
4344
|
+
var import_cluemart_shared39 = require("@timardex/cluemart-shared");
|
|
3979
4345
|
|
|
3980
4346
|
// src/service/event/findEventOrImportedMarketById.ts
|
|
3981
4347
|
async function findEventOrImportedMarketById(resourceId) {
|
|
@@ -3992,7 +4358,7 @@ async function findEventOrImportedMarketById(resourceId) {
|
|
|
3992
4358
|
}
|
|
3993
4359
|
|
|
3994
4360
|
// src/service/relations.ts
|
|
3995
|
-
var
|
|
4361
|
+
var import_cluemart_shared32 = require("@timardex/cluemart-shared");
|
|
3996
4362
|
function didRemoveAnyEventDates(previousDateTime, nextDateTime) {
|
|
3997
4363
|
if (!previousDateTime?.length) {
|
|
3998
4364
|
return false;
|
|
@@ -4008,8 +4374,8 @@ function didRemoveAnyStartedDates(previousDateTime, nextDateTime) {
|
|
|
4008
4374
|
return false;
|
|
4009
4375
|
}
|
|
4010
4376
|
return previousDateTime.some(
|
|
4011
|
-
(prev) => prev.dateStatus ===
|
|
4012
|
-
(next) => next.startDate === prev.startDate && next.startTime === prev.startTime && next.dateStatus ===
|
|
4377
|
+
(prev) => prev.dateStatus === import_cluemart_shared32.EnumEventDateStatus.STARTED && !nextDateTime?.some(
|
|
4378
|
+
(next) => next.startDate === prev.startDate && next.startTime === prev.startTime && next.dateStatus === import_cluemart_shared32.EnumEventDateStatus.STARTED
|
|
4013
4379
|
)
|
|
4014
4380
|
);
|
|
4015
4381
|
}
|
|
@@ -4020,7 +4386,7 @@ function updateRelationDatesToCanceled(relationDates, eventDateTime) {
|
|
|
4020
4386
|
) ?? false;
|
|
4021
4387
|
return {
|
|
4022
4388
|
...relationDate,
|
|
4023
|
-
status: existsInEvent ? relationDate.status :
|
|
4389
|
+
status: existsInEvent ? relationDate.status : import_cluemart_shared32.EnumInviteStatus.CANCELED
|
|
4024
4390
|
};
|
|
4025
4391
|
});
|
|
4026
4392
|
}
|
|
@@ -4029,15 +4395,15 @@ function updateRelationDatesToCanceled(relationDates, eventDateTime) {
|
|
|
4029
4395
|
var import_dayjs8 = __toESM(require("dayjs"));
|
|
4030
4396
|
|
|
4031
4397
|
// src/service/license/compliance/utils.ts
|
|
4032
|
-
var
|
|
4398
|
+
var import_cluemart_shared37 = require("@timardex/cluemart-shared");
|
|
4033
4399
|
var import_dayjs7 = __toESM(require("dayjs"));
|
|
4034
4400
|
|
|
4035
4401
|
// src/service/license/compliance/event.ts
|
|
4036
|
-
var
|
|
4402
|
+
var import_cluemart_shared33 = require("@timardex/cluemart-shared");
|
|
4037
4403
|
var eventLicences = [
|
|
4038
|
-
|
|
4039
|
-
|
|
4040
|
-
|
|
4404
|
+
import_cluemart_shared33.EnumUserLicence.STANDARD_EVENT,
|
|
4405
|
+
import_cluemart_shared33.EnumUserLicence.PRO_EVENT,
|
|
4406
|
+
import_cluemart_shared33.EnumUserLicence.PRO_PLUS_EVENT
|
|
4041
4407
|
];
|
|
4042
4408
|
async function handleEventLicenceCompliance(user, now) {
|
|
4043
4409
|
if (!user.licences || !user.events?.length) {
|
|
@@ -4249,9 +4615,9 @@ function buildLicenceExpiryPipeline(params) {
|
|
|
4249
4615
|
}
|
|
4250
4616
|
|
|
4251
4617
|
// src/service/license/compliance/partner.ts
|
|
4252
|
-
var
|
|
4618
|
+
var import_cluemart_shared34 = require("@timardex/cluemart-shared");
|
|
4253
4619
|
var partnerLicences = [
|
|
4254
|
-
|
|
4620
|
+
import_cluemart_shared34.EnumUserLicence.STANDARD_PARTNER
|
|
4255
4621
|
];
|
|
4256
4622
|
async function handlePartnerLicenceCompliance(user, now) {
|
|
4257
4623
|
if (!user.licences || !user.partner) {
|
|
@@ -4261,52 +4627,62 @@ async function handlePartnerLicenceCompliance(user, now) {
|
|
|
4261
4627
|
}
|
|
4262
4628
|
|
|
4263
4629
|
// src/service/license/compliance/vendor.ts
|
|
4264
|
-
var
|
|
4630
|
+
var import_cluemart_shared36 = require("@timardex/cluemart-shared");
|
|
4265
4631
|
var import_dayjs6 = __toESM(require("dayjs"));
|
|
4266
4632
|
|
|
4267
4633
|
// src/service/license/models.ts
|
|
4268
|
-
var
|
|
4634
|
+
var import_cluemart_shared35 = require("@timardex/cluemart-shared");
|
|
4269
4635
|
var import_dayjs5 = __toESM(require("dayjs"));
|
|
4270
4636
|
var import_graphql = require("graphql");
|
|
4271
|
-
var LicenceCategory = /* @__PURE__ */ ((
|
|
4272
|
-
|
|
4273
|
-
|
|
4274
|
-
|
|
4275
|
-
|
|
4276
|
-
|
|
4277
|
-
return
|
|
4637
|
+
var LicenceCategory = /* @__PURE__ */ ((LicenceCategory3) => {
|
|
4638
|
+
LicenceCategory3["EVENT"] = "event";
|
|
4639
|
+
LicenceCategory3["PARTNER"] = "partner";
|
|
4640
|
+
LicenceCategory3["VENDOR"] = "vendor";
|
|
4641
|
+
LicenceCategory3["AFFILIATE"] = "affiliate";
|
|
4642
|
+
LicenceCategory3["SCHOOL"] = "school";
|
|
4643
|
+
return LicenceCategory3;
|
|
4278
4644
|
})(LicenceCategory || {});
|
|
4279
4645
|
var licenceCategoryMapping = {
|
|
4280
|
-
[
|
|
4281
|
-
[
|
|
4282
|
-
[
|
|
4283
|
-
[
|
|
4284
|
-
[
|
|
4285
|
-
[
|
|
4286
|
-
[
|
|
4287
|
-
[
|
|
4288
|
-
[
|
|
4646
|
+
[import_cluemart_shared35.EnumUserLicence.PRO_EVENT]: "event" /* EVENT */,
|
|
4647
|
+
[import_cluemart_shared35.EnumUserLicence.PRO_PLUS_EVENT]: "event" /* EVENT */,
|
|
4648
|
+
[import_cluemart_shared35.EnumUserLicence.PRO_PLUS_VENDOR]: "vendor" /* VENDOR */,
|
|
4649
|
+
[import_cluemart_shared35.EnumUserLicence.PRO_VENDOR]: "vendor" /* VENDOR */,
|
|
4650
|
+
[import_cluemart_shared35.EnumUserLicence.STANDARD_EVENT]: "event" /* EVENT */,
|
|
4651
|
+
[import_cluemart_shared35.EnumUserLicence.STANDARD_PARTNER]: "partner" /* PARTNER */,
|
|
4652
|
+
[import_cluemart_shared35.EnumUserLicence.STANDARD_VENDOR]: "vendor" /* VENDOR */,
|
|
4653
|
+
[import_cluemart_shared35.EnumUserLicence.STANDARD_AFFILIATE]: "affiliate" /* AFFILIATE */,
|
|
4654
|
+
[import_cluemart_shared35.EnumUserLicence.STANDARD_SCHOOL]: "school" /* SCHOOL */
|
|
4289
4655
|
};
|
|
4290
4656
|
var licencePriority = {
|
|
4291
|
-
[
|
|
4292
|
-
[
|
|
4293
|
-
[
|
|
4294
|
-
[
|
|
4295
|
-
[
|
|
4296
|
-
[
|
|
4297
|
-
[
|
|
4298
|
-
[
|
|
4299
|
-
[
|
|
4657
|
+
[import_cluemart_shared35.EnumUserLicence.PRO_PLUS_EVENT]: 3,
|
|
4658
|
+
[import_cluemart_shared35.EnumUserLicence.PRO_EVENT]: 2,
|
|
4659
|
+
[import_cluemart_shared35.EnumUserLicence.STANDARD_EVENT]: 1,
|
|
4660
|
+
[import_cluemart_shared35.EnumUserLicence.PRO_PLUS_VENDOR]: 3,
|
|
4661
|
+
[import_cluemart_shared35.EnumUserLicence.PRO_VENDOR]: 2,
|
|
4662
|
+
[import_cluemart_shared35.EnumUserLicence.STANDARD_VENDOR]: 1,
|
|
4663
|
+
[import_cluemart_shared35.EnumUserLicence.STANDARD_PARTNER]: 1,
|
|
4664
|
+
[import_cluemart_shared35.EnumUserLicence.STANDARD_AFFILIATE]: 1,
|
|
4665
|
+
[import_cluemart_shared35.EnumUserLicence.STANDARD_SCHOOL]: 1
|
|
4300
4666
|
};
|
|
4301
4667
|
var standardLicences = [
|
|
4302
|
-
|
|
4303
|
-
|
|
4304
|
-
|
|
4668
|
+
import_cluemart_shared35.EnumUserLicence.STANDARD_VENDOR,
|
|
4669
|
+
import_cluemart_shared35.EnumUserLicence.STANDARD_EVENT,
|
|
4670
|
+
import_cluemart_shared35.EnumUserLicence.STANDARD_PARTNER
|
|
4305
4671
|
];
|
|
4306
4672
|
var standardLicenceSet = new Set(standardLicences);
|
|
4307
4673
|
function isStandardLicence(licence) {
|
|
4308
4674
|
return standardLicenceSet.has(licence);
|
|
4309
4675
|
}
|
|
4676
|
+
var proLicences = [
|
|
4677
|
+
import_cluemart_shared35.EnumUserLicence.PRO_EVENT,
|
|
4678
|
+
import_cluemart_shared35.EnumUserLicence.PRO_PLUS_EVENT,
|
|
4679
|
+
import_cluemart_shared35.EnumUserLicence.PRO_VENDOR,
|
|
4680
|
+
import_cluemart_shared35.EnumUserLicence.PRO_PLUS_VENDOR
|
|
4681
|
+
];
|
|
4682
|
+
var proLicenceSet = new Set(proLicences);
|
|
4683
|
+
function isProLicence(licence) {
|
|
4684
|
+
return proLicenceSet.has(licence);
|
|
4685
|
+
}
|
|
4310
4686
|
var categoryRegexMapping = {
|
|
4311
4687
|
["event" /* EVENT */]: /_event$/,
|
|
4312
4688
|
["partner" /* PARTNER */]: /_partner$/,
|
|
@@ -4315,11 +4691,11 @@ var categoryRegexMapping = {
|
|
|
4315
4691
|
["school" /* SCHOOL */]: /_school$/
|
|
4316
4692
|
};
|
|
4317
4693
|
var categoryFallbackLicence = {
|
|
4318
|
-
["event" /* EVENT */]:
|
|
4319
|
-
["partner" /* PARTNER */]:
|
|
4320
|
-
["vendor" /* VENDOR */]:
|
|
4321
|
-
["affiliate" /* AFFILIATE */]:
|
|
4322
|
-
["school" /* SCHOOL */]:
|
|
4694
|
+
["event" /* EVENT */]: import_cluemart_shared35.EnumUserLicence.STANDARD_EVENT,
|
|
4695
|
+
["partner" /* PARTNER */]: import_cluemart_shared35.EnumUserLicence.STANDARD_PARTNER,
|
|
4696
|
+
["vendor" /* VENDOR */]: import_cluemart_shared35.EnumUserLicence.STANDARD_VENDOR,
|
|
4697
|
+
["affiliate" /* AFFILIATE */]: import_cluemart_shared35.EnumUserLicence.STANDARD_AFFILIATE,
|
|
4698
|
+
["school" /* SCHOOL */]: import_cluemart_shared35.EnumUserLicence.STANDARD_SCHOOL
|
|
4323
4699
|
};
|
|
4324
4700
|
var LicenceFilterInput = {
|
|
4325
4701
|
INPUT_USER_LICENCES: "$licences"
|
|
@@ -4349,11 +4725,11 @@ function getHighestLicenceForCategory(licences, category) {
|
|
|
4349
4725
|
function createLicenceObject(expiryDate, licenceType) {
|
|
4350
4726
|
const today = (0, import_dayjs5.default)();
|
|
4351
4727
|
const expiryDateMapping = {
|
|
4352
|
-
[
|
|
4353
|
-
[
|
|
4354
|
-
[
|
|
4355
|
-
[
|
|
4356
|
-
[
|
|
4728
|
+
[import_cluemart_shared35.LicenceExpiryDate.ONE_YEAR]: today.add(1, "year").endOf("day").toDate(),
|
|
4729
|
+
[import_cluemart_shared35.LicenceExpiryDate.ONE_MONTH]: today.add(1, "month").endOf("day").toDate(),
|
|
4730
|
+
[import_cluemart_shared35.LicenceExpiryDate.TWO_MONTHS]: today.add(2, "month").endOf("day").toDate(),
|
|
4731
|
+
[import_cluemart_shared35.LicenceExpiryDate.THREE_MONTHS]: today.add(3, "month").endOf("day").toDate(),
|
|
4732
|
+
[import_cluemart_shared35.LicenceExpiryDate.SIX_MONTHS]: today.add(6, "month").endOf("day").toDate()
|
|
4357
4733
|
};
|
|
4358
4734
|
const licenceObject = {
|
|
4359
4735
|
expiryDate: expiryDateMapping[expiryDate],
|
|
@@ -4457,13 +4833,13 @@ async function checkOwnerHasLicence({
|
|
|
4457
4833
|
const owner = await UserModel.findById(userId);
|
|
4458
4834
|
if (!owner) throw new import_graphql.GraphQLError("Owner not found");
|
|
4459
4835
|
const categoryByResource = {
|
|
4460
|
-
[
|
|
4461
|
-
[
|
|
4462
|
-
[
|
|
4463
|
-
[
|
|
4464
|
-
[
|
|
4836
|
+
[import_cluemart_shared35.EnumResourceType.EVENT]: "event" /* EVENT */,
|
|
4837
|
+
[import_cluemart_shared35.EnumResourceType.PARTNER]: "partner" /* PARTNER */,
|
|
4838
|
+
[import_cluemart_shared35.EnumResourceType.VENDOR]: "vendor" /* VENDOR */,
|
|
4839
|
+
[import_cluemart_shared35.EnumResourceType.AFFILIATE]: "affiliate" /* AFFILIATE */,
|
|
4840
|
+
[import_cluemart_shared35.EnumResourceType.SCHOOL]: "school" /* SCHOOL */
|
|
4465
4841
|
};
|
|
4466
|
-
if (!(0,
|
|
4842
|
+
if (!(0, import_cluemart_shared35.isNonVisitorResourceType)(resourceType)) {
|
|
4467
4843
|
throw new import_graphql.GraphQLError(`Invalid resource type: ${resourceType}.`);
|
|
4468
4844
|
}
|
|
4469
4845
|
const requiredCategory = categoryByResource[resourceType];
|
|
@@ -4485,6 +4861,128 @@ async function checkOwnerHasLicence({
|
|
|
4485
4861
|
);
|
|
4486
4862
|
}
|
|
4487
4863
|
}
|
|
4864
|
+
var resourceLicenceCategory = {
|
|
4865
|
+
[import_cluemart_shared35.EnumResourceType.EVENT]: "event" /* EVENT */,
|
|
4866
|
+
[import_cluemart_shared35.EnumResourceType.PARTNER]: "partner" /* PARTNER */,
|
|
4867
|
+
[import_cluemart_shared35.EnumResourceType.VENDOR]: "vendor" /* VENDOR */
|
|
4868
|
+
};
|
|
4869
|
+
function isProtectedByCurrentStripeSubscription(user, licenceType, now) {
|
|
4870
|
+
const stripe = user.stripe;
|
|
4871
|
+
if (!stripe || stripe.currentPlan !== licenceType) {
|
|
4872
|
+
return false;
|
|
4873
|
+
}
|
|
4874
|
+
const gracePeriodEndsAt = stripe.paymentGracePeriodEndsAt ? (0, import_dayjs5.default)(stripe.paymentGracePeriodEndsAt) : null;
|
|
4875
|
+
const hasActivePaymentGracePeriod = (stripe.status === import_cluemart_shared35.EnumSubscriptionStatus.PAST_DUE || stripe.status === import_cluemart_shared35.EnumSubscriptionStatus.INACTIVE) && Boolean(stripe.paymentGraceSubscriptionId) && (!stripe.subscriptionId || stripe.subscriptionId === stripe.paymentGraceSubscriptionId) && gracePeriodEndsAt !== null && gracePeriodEndsAt.isValid() && gracePeriodEndsAt.isAfter(now);
|
|
4876
|
+
if (hasActivePaymentGracePeriod) {
|
|
4877
|
+
return true;
|
|
4878
|
+
}
|
|
4879
|
+
if (!stripe.subscriptionId) {
|
|
4880
|
+
return false;
|
|
4881
|
+
}
|
|
4882
|
+
if (stripe.status !== import_cluemart_shared35.EnumSubscriptionStatus.ACTIVE) {
|
|
4883
|
+
return false;
|
|
4884
|
+
}
|
|
4885
|
+
if (!stripe.endDate) {
|
|
4886
|
+
return false;
|
|
4887
|
+
}
|
|
4888
|
+
const paidThrough = (0, import_dayjs5.default)(stripe.endDate);
|
|
4889
|
+
return paidThrough.isValid() && paidThrough.isAfter(now);
|
|
4890
|
+
}
|
|
4891
|
+
function effectiveLicences({
|
|
4892
|
+
includeStripeProtected = false,
|
|
4893
|
+
licences,
|
|
4894
|
+
now,
|
|
4895
|
+
owner
|
|
4896
|
+
}) {
|
|
4897
|
+
const nowDayjs = (0, import_dayjs5.default)(now);
|
|
4898
|
+
return (licences ?? []).filter((licence) => {
|
|
4899
|
+
if (!licence.licenceType || licence.expiryDate == null) {
|
|
4900
|
+
return false;
|
|
4901
|
+
}
|
|
4902
|
+
if (new Date(licence.expiryDate).getTime() > now.getTime()) {
|
|
4903
|
+
return true;
|
|
4904
|
+
}
|
|
4905
|
+
return Boolean(
|
|
4906
|
+
includeStripeProtected && owner && isProtectedByCurrentStripeSubscription(
|
|
4907
|
+
owner,
|
|
4908
|
+
licence.licenceType,
|
|
4909
|
+
nowDayjs
|
|
4910
|
+
)
|
|
4911
|
+
);
|
|
4912
|
+
});
|
|
4913
|
+
}
|
|
4914
|
+
async function getActiveLicenceForResource({
|
|
4915
|
+
includeStripeProtected = false,
|
|
4916
|
+
userId,
|
|
4917
|
+
resourceType,
|
|
4918
|
+
now = /* @__PURE__ */ new Date()
|
|
4919
|
+
}) {
|
|
4920
|
+
const category = resourceLicenceCategory[resourceType];
|
|
4921
|
+
if (!category) {
|
|
4922
|
+
return null;
|
|
4923
|
+
}
|
|
4924
|
+
const owner = await UserModel.findById(userId, {
|
|
4925
|
+
licences: 1,
|
|
4926
|
+
...includeStripeProtected ? { stripe: 1 } : {}
|
|
4927
|
+
}).lean();
|
|
4928
|
+
if (!owner?.licences?.length) {
|
|
4929
|
+
return null;
|
|
4930
|
+
}
|
|
4931
|
+
return getHighestLicenceForCategory(
|
|
4932
|
+
effectiveLicences({
|
|
4933
|
+
includeStripeProtected,
|
|
4934
|
+
licences: owner.licences,
|
|
4935
|
+
now,
|
|
4936
|
+
owner
|
|
4937
|
+
}),
|
|
4938
|
+
category
|
|
4939
|
+
);
|
|
4940
|
+
}
|
|
4941
|
+
async function getUserIdsWithActiveProLicence({
|
|
4942
|
+
includeStripeProtected = false,
|
|
4943
|
+
resourceType,
|
|
4944
|
+
userIds,
|
|
4945
|
+
now = /* @__PURE__ */ new Date()
|
|
4946
|
+
}) {
|
|
4947
|
+
const category = resourceLicenceCategory[resourceType];
|
|
4948
|
+
if (!category || userIds.length === 0) {
|
|
4949
|
+
return /* @__PURE__ */ new Set();
|
|
4950
|
+
}
|
|
4951
|
+
const owners = await UserModel.find(
|
|
4952
|
+
{ _id: { $in: userIds } },
|
|
4953
|
+
{ licences: 1, ...includeStripeProtected ? { stripe: 1 } : {} }
|
|
4954
|
+
).lean();
|
|
4955
|
+
const allowed = /* @__PURE__ */ new Set();
|
|
4956
|
+
for (const owner of owners ?? []) {
|
|
4957
|
+
const activeLicence = getHighestLicenceForCategory(
|
|
4958
|
+
effectiveLicences({
|
|
4959
|
+
includeStripeProtected,
|
|
4960
|
+
licences: owner.licences,
|
|
4961
|
+
now,
|
|
4962
|
+
owner
|
|
4963
|
+
}),
|
|
4964
|
+
category
|
|
4965
|
+
);
|
|
4966
|
+
if (activeLicence && isProLicence(activeLicence)) {
|
|
4967
|
+
allowed.add(String(owner._id));
|
|
4968
|
+
}
|
|
4969
|
+
}
|
|
4970
|
+
return allowed;
|
|
4971
|
+
}
|
|
4972
|
+
async function hasActiveProLicenceForResource({
|
|
4973
|
+
includeStripeProtected = false,
|
|
4974
|
+
userId,
|
|
4975
|
+
resourceType,
|
|
4976
|
+
now = /* @__PURE__ */ new Date()
|
|
4977
|
+
}) {
|
|
4978
|
+
const activeLicence = await getActiveLicenceForResource({
|
|
4979
|
+
includeStripeProtected,
|
|
4980
|
+
now,
|
|
4981
|
+
resourceType,
|
|
4982
|
+
userId
|
|
4983
|
+
});
|
|
4984
|
+
return activeLicence !== null && isProLicence(activeLicence);
|
|
4985
|
+
}
|
|
4488
4986
|
|
|
4489
4987
|
// src/service/license/compliance/vendor.ts
|
|
4490
4988
|
async function findUserVendor(userId, logLabel) {
|
|
@@ -4543,7 +5041,7 @@ async function applyVendorDowngrade(vendor, ownerUserId) {
|
|
|
4543
5041
|
return (result?.matchedCount ?? 0) > 0;
|
|
4544
5042
|
}
|
|
4545
5043
|
async function downgradeVendorProFeatures(userId, licenceType) {
|
|
4546
|
-
const isStandardVendor = licenceType ===
|
|
5044
|
+
const isStandardVendor = licenceType === import_cluemart_shared36.EnumUserLicence.STANDARD_VENDOR;
|
|
4547
5045
|
if (!isStandardVendor) {
|
|
4548
5046
|
return;
|
|
4549
5047
|
}
|
|
@@ -4590,7 +5088,7 @@ async function applyVendorRestore(vendor, ownerUserId) {
|
|
|
4590
5088
|
return (result?.matchedCount ?? 0) > 0;
|
|
4591
5089
|
}
|
|
4592
5090
|
async function restoreVendorProFeatures(userId, licenceType) {
|
|
4593
|
-
const isProVendor = licenceType ===
|
|
5091
|
+
const isProVendor = licenceType === import_cluemart_shared36.EnumUserLicence.PRO_VENDOR || licenceType === import_cluemart_shared36.EnumUserLicence.PRO_PLUS_VENDOR;
|
|
4594
5092
|
if (!isProVendor) {
|
|
4595
5093
|
return;
|
|
4596
5094
|
}
|
|
@@ -4605,28 +5103,6 @@ async function restoreVendorProFeatures(userId, licenceType) {
|
|
|
4605
5103
|
throw error;
|
|
4606
5104
|
}
|
|
4607
5105
|
}
|
|
4608
|
-
function isProtectedByCurrentStripeSubscription(user, licenceType, now) {
|
|
4609
|
-
const stripe = user.stripe;
|
|
4610
|
-
if (!stripe || stripe.currentPlan !== licenceType) {
|
|
4611
|
-
return false;
|
|
4612
|
-
}
|
|
4613
|
-
const gracePeriodEndsAt = stripe.paymentGracePeriodEndsAt ? (0, import_dayjs6.default)(stripe.paymentGracePeriodEndsAt) : null;
|
|
4614
|
-
const hasActivePaymentGracePeriod = (stripe.status === import_cluemart_shared35.EnumSubscriptionStatus.PAST_DUE || stripe.status === import_cluemart_shared35.EnumSubscriptionStatus.INACTIVE) && Boolean(stripe.paymentGraceSubscriptionId) && (!stripe.subscriptionId || stripe.subscriptionId === stripe.paymentGraceSubscriptionId) && gracePeriodEndsAt !== null && gracePeriodEndsAt.isValid() && gracePeriodEndsAt.isAfter(now);
|
|
4615
|
-
if (hasActivePaymentGracePeriod) {
|
|
4616
|
-
return true;
|
|
4617
|
-
}
|
|
4618
|
-
if (!stripe.subscriptionId) {
|
|
4619
|
-
return false;
|
|
4620
|
-
}
|
|
4621
|
-
if (stripe.status !== import_cluemart_shared35.EnumSubscriptionStatus.ACTIVE) {
|
|
4622
|
-
return false;
|
|
4623
|
-
}
|
|
4624
|
-
if (!stripe.endDate) {
|
|
4625
|
-
return false;
|
|
4626
|
-
}
|
|
4627
|
-
const paidThrough = (0, import_dayjs6.default)(stripe.endDate);
|
|
4628
|
-
return paidThrough.isValid() && paidThrough.isAfter(now);
|
|
4629
|
-
}
|
|
4630
5106
|
async function handleVendorLicenceCompliance(user, now) {
|
|
4631
5107
|
if (!user.licences || !user.vendor) {
|
|
4632
5108
|
return;
|
|
@@ -4637,10 +5113,10 @@ async function handleVendorLicenceCompliance(user, now) {
|
|
|
4637
5113
|
if (vendorLicencesOfUser.length === 0) {
|
|
4638
5114
|
return;
|
|
4639
5115
|
}
|
|
4640
|
-
const
|
|
4641
|
-
(licence) => licence.licenceType !==
|
|
5116
|
+
const proLicences2 = vendorLicencesOfUser.filter(
|
|
5117
|
+
(licence) => licence.licenceType !== import_cluemart_shared36.EnumUserLicence.STANDARD_VENDOR
|
|
4642
5118
|
);
|
|
4643
|
-
const expiredProLicences =
|
|
5119
|
+
const expiredProLicences = proLicences2.filter(
|
|
4644
5120
|
(licence) => !(0, import_dayjs6.default)(licence.expiryDate).isAfter(now)
|
|
4645
5121
|
);
|
|
4646
5122
|
const stripeProtectedLicenceTypes = new Set(
|
|
@@ -4651,7 +5127,7 @@ async function handleVendorLicenceCompliance(user, now) {
|
|
|
4651
5127
|
const expiredProLicence = expiredProLicences.some(
|
|
4652
5128
|
(licence) => !stripeProtectedLicenceTypes.has(licence.licenceType)
|
|
4653
5129
|
);
|
|
4654
|
-
const hasValidProLicence = stripeProtectedLicenceTypes.size > 0 || hasValidLicence(
|
|
5130
|
+
const hasValidProLicence = stripeProtectedLicenceTypes.size > 0 || hasValidLicence(proLicences2, import_cluemart_shared36.vendorLicences, now);
|
|
4655
5131
|
const hasExpiredVendorLicence = vendorLicencesOfUser.some(
|
|
4656
5132
|
(licence) => !(0, import_dayjs6.default)(licence.expiryDate).isAfter(now) && !stripeProtectedLicenceTypes.has(licence.licenceType)
|
|
4657
5133
|
);
|
|
@@ -4667,7 +5143,7 @@ async function handleVendorLicenceCompliance(user, now) {
|
|
|
4667
5143
|
"owner.userId": user._id
|
|
4668
5144
|
}).lean().exec();
|
|
4669
5145
|
}
|
|
4670
|
-
const licencesToSync =
|
|
5146
|
+
const licencesToSync = import_cluemart_shared36.vendorLicences.filter(
|
|
4671
5147
|
(licenceType) => !stripeProtectedLicenceTypes.has(licenceType)
|
|
4672
5148
|
);
|
|
4673
5149
|
await syncUserLicencesAfterExpiry(user._id, licencesToSync, now, "downgrade");
|
|
@@ -4682,11 +5158,11 @@ async function handleVendorLicenceCompliance(user, now) {
|
|
|
4682
5158
|
data: {
|
|
4683
5159
|
resourceId: String(vendor._id),
|
|
4684
5160
|
resourceName: vendor.name,
|
|
4685
|
-
resourceType:
|
|
5161
|
+
resourceType: import_cluemart_shared36.EnumNotificationResourceType.DOWNGRADED_VENDOR
|
|
4686
5162
|
},
|
|
4687
5163
|
message: `Your Vendor licence has been downgraded due to licence expiration.`,
|
|
4688
5164
|
title: `Vendor Licence Downgraded`,
|
|
4689
|
-
type:
|
|
5165
|
+
type: import_cluemart_shared36.EnumNotificationType.SYSTEM,
|
|
4690
5166
|
userIds: [user._id]
|
|
4691
5167
|
};
|
|
4692
5168
|
await sendDeactivationNotification(payload, user._id, vendor.name, "vendor");
|
|
@@ -4700,26 +5176,11 @@ async function vendorOwnerHasProLicence(vendorId) {
|
|
|
4700
5176
|
if (!vendor) {
|
|
4701
5177
|
return false;
|
|
4702
5178
|
}
|
|
4703
|
-
|
|
4704
|
-
|
|
4705
|
-
|
|
4706
|
-
|
|
4707
|
-
|
|
4708
|
-
return false;
|
|
4709
|
-
}
|
|
4710
|
-
const now = (0, import_dayjs6.default)();
|
|
4711
|
-
const effectiveVendorLicences = owner.licences?.filter(
|
|
4712
|
-
(licence) => licence?.licenceType && ((0, import_dayjs6.default)(licence.expiryDate).isAfter(now) || isProtectedByCurrentStripeSubscription(
|
|
4713
|
-
owner,
|
|
4714
|
-
licence.licenceType,
|
|
4715
|
-
now
|
|
4716
|
-
))
|
|
4717
|
-
);
|
|
4718
|
-
const highestVendorLicence = getHighestLicenceForCategory(
|
|
4719
|
-
effectiveVendorLicences,
|
|
4720
|
-
"vendor" /* VENDOR */
|
|
4721
|
-
);
|
|
4722
|
-
return highestVendorLicence !== null && licencePriority[highestVendorLicence] >= licencePriority[import_cluemart_shared35.EnumUserLicence.PRO_VENDOR];
|
|
5179
|
+
return hasActiveProLicenceForResource({
|
|
5180
|
+
includeStripeProtected: true,
|
|
5181
|
+
resourceType: import_cluemart_shared36.EnumResourceType.VENDOR,
|
|
5182
|
+
userId: vendor.owner.userId
|
|
5183
|
+
});
|
|
4723
5184
|
}
|
|
4724
5185
|
|
|
4725
5186
|
// src/service/license/compliance/utils.ts
|
|
@@ -4729,12 +5190,12 @@ async function syncUserLicencesAfterExpiry(userId, licenceTypes, now, mode = "do
|
|
|
4729
5190
|
const pipeline = buildLicenceExpiryPipeline({
|
|
4730
5191
|
downgradeBranches: [
|
|
4731
5192
|
{
|
|
4732
|
-
case:
|
|
4733
|
-
then:
|
|
5193
|
+
case: import_cluemart_shared37.EnumUserLicence.PRO_PLUS_VENDOR,
|
|
5194
|
+
then: import_cluemart_shared37.EnumUserLicence.STANDARD_VENDOR
|
|
4734
5195
|
},
|
|
4735
5196
|
{
|
|
4736
|
-
case:
|
|
4737
|
-
then:
|
|
5197
|
+
case: import_cluemart_shared37.EnumUserLicence.PRO_VENDOR,
|
|
5198
|
+
then: import_cluemart_shared37.EnumUserLicence.STANDARD_VENDOR
|
|
4738
5199
|
}
|
|
4739
5200
|
],
|
|
4740
5201
|
licenceTypes,
|
|
@@ -4863,7 +5324,7 @@ var REMINDER_WINDOW_MIN_HOURS = 6.5 * 24;
|
|
|
4863
5324
|
var REMINDER_WINDOW_MAX_HOURS = 7.5 * 24;
|
|
4864
5325
|
|
|
4865
5326
|
// src/service/license/reminder/utils.ts
|
|
4866
|
-
var
|
|
5327
|
+
var import_cluemart_shared38 = require("@timardex/cluemart-shared");
|
|
4867
5328
|
var import_utils8 = require("@timardex/cluemart-shared/utils");
|
|
4868
5329
|
var import_dayjs9 = __toESM(require("dayjs"));
|
|
4869
5330
|
|
|
@@ -4929,28 +5390,28 @@ function isLicenseExpiringIn7Days(expiryDate, now) {
|
|
|
4929
5390
|
return hoursUntilExpiry >= REMINDER_WINDOW_MIN_HOURS && hoursUntilExpiry <= REMINDER_WINDOW_MAX_HOURS;
|
|
4930
5391
|
}
|
|
4931
5392
|
function getLicenseName(licenceType) {
|
|
4932
|
-
return
|
|
5393
|
+
return import_cluemart_shared38.licenseNiceNames[licenceType] || licenceType;
|
|
4933
5394
|
}
|
|
4934
5395
|
function getNotificationTypes(isVendorLicense, isPartnerLicense) {
|
|
4935
5396
|
if (isVendorLicense) {
|
|
4936
5397
|
return {
|
|
4937
|
-
notificationType:
|
|
4938
|
-
resourceType:
|
|
5398
|
+
notificationType: import_cluemart_shared38.EnumNotificationType.SYSTEM,
|
|
5399
|
+
resourceType: import_cluemart_shared38.EnumNotificationResourceType.EXPIRATION_REMINDER_VENDOR
|
|
4939
5400
|
};
|
|
4940
5401
|
}
|
|
4941
5402
|
if (isPartnerLicense) {
|
|
4942
5403
|
return {
|
|
4943
|
-
notificationType:
|
|
4944
|
-
resourceType:
|
|
5404
|
+
notificationType: import_cluemart_shared38.EnumNotificationType.SYSTEM,
|
|
5405
|
+
resourceType: import_cluemart_shared38.EnumNotificationResourceType.EXPIRATION_REMINDER_PARTNER
|
|
4945
5406
|
};
|
|
4946
5407
|
}
|
|
4947
5408
|
return {
|
|
4948
|
-
notificationType:
|
|
4949
|
-
resourceType:
|
|
5409
|
+
notificationType: import_cluemart_shared38.EnumNotificationType.SYSTEM,
|
|
5410
|
+
resourceType: import_cluemart_shared38.EnumNotificationResourceType.EXPIRATION_REMINDER_EVENT
|
|
4950
5411
|
};
|
|
4951
5412
|
}
|
|
4952
5413
|
async function getLicenseResourceInfo(user, licence) {
|
|
4953
|
-
const isVendorLicense =
|
|
5414
|
+
const isVendorLicense = import_cluemart_shared38.vendorLicences.includes(licence.licenceType);
|
|
4954
5415
|
const isPartnerLicense = partnerLicences.includes(licence.licenceType);
|
|
4955
5416
|
const licenceName = getLicenseName(licence.licenceType);
|
|
4956
5417
|
const { notificationType, resourceType } = getNotificationTypes(
|
|
@@ -4998,11 +5459,11 @@ async function getLicenseResourceInfo(user, licence) {
|
|
|
4998
5459
|
};
|
|
4999
5460
|
}
|
|
5000
5461
|
function getLicenceExpiryMode(licenceType) {
|
|
5001
|
-
return licenceType ===
|
|
5462
|
+
return licenceType === import_cluemart_shared38.EnumUserLicence.PRO_VENDOR || licenceType === import_cluemart_shared38.EnumUserLicence.PRO_PLUS_VENDOR ? "downgrade" : "extend";
|
|
5002
5463
|
}
|
|
5003
5464
|
async function sendLicenseReminder(user, licence) {
|
|
5004
5465
|
const licenceName = getLicenseName(licence.licenceType);
|
|
5005
|
-
const expiryDate = (0, import_dayjs9.default)(licence.expiryDate).format(
|
|
5466
|
+
const expiryDate = (0, import_dayjs9.default)(licence.expiryDate).format(import_cluemart_shared38.dateFormat);
|
|
5006
5467
|
const userId = String(user._id);
|
|
5007
5468
|
const resourceInfo = await getLicenseResourceInfo(user, licence);
|
|
5008
5469
|
if (!resourceInfo) {
|
|
@@ -5132,6 +5593,7 @@ async function remindUsersAboutLicenseExpiration() {
|
|
|
5132
5593
|
REMINDER_WINDOW_MAX_HOURS,
|
|
5133
5594
|
REMINDER_WINDOW_MIN_HOURS,
|
|
5134
5595
|
SUBSCRIPTION_REWARD_TIMEZONE,
|
|
5596
|
+
acceptedAssociateUserIds,
|
|
5135
5597
|
activeAffiliateCodeExists,
|
|
5136
5598
|
awardAffiliateVendorSubscriptionRewards,
|
|
5137
5599
|
buildLicenceExpiryPipeline,
|
|
@@ -5145,6 +5607,9 @@ async function remindUsersAboutLicenseExpiration() {
|
|
|
5145
5607
|
convertObjectIdsToStrings,
|
|
5146
5608
|
createLicenceObject,
|
|
5147
5609
|
dedupeArchivedSlotsByStartDateTime,
|
|
5610
|
+
detachAssociateGrantsForResources,
|
|
5611
|
+
detachStaleAssociateGrants,
|
|
5612
|
+
detachUsersFromResource,
|
|
5148
5613
|
didRemoveAnyEventDates,
|
|
5149
5614
|
didRemoveAnyStartedDates,
|
|
5150
5615
|
downgradeVendorProFeatures,
|
|
@@ -5154,6 +5619,8 @@ async function remindUsersAboutLicenseExpiration() {
|
|
|
5154
5619
|
eventLicences,
|
|
5155
5620
|
findAffiliateByPromoCode,
|
|
5156
5621
|
findEventOrImportedMarketById,
|
|
5622
|
+
getActiveLicenceForResource,
|
|
5623
|
+
getAssociateAccessMeta,
|
|
5157
5624
|
getEventResourceInfo,
|
|
5158
5625
|
getHighestLicenceForCategory,
|
|
5159
5626
|
getLicenceCategory,
|
|
@@ -5163,11 +5630,17 @@ async function remindUsersAboutLicenseExpiration() {
|
|
|
5163
5630
|
getPayingStripeSubscriptionPlan,
|
|
5164
5631
|
getPayingVendorStripeSubscriptionPlan,
|
|
5165
5632
|
getSubscriptionRewardPeriodBounds,
|
|
5633
|
+
getUserIdsWithActiveProLicence,
|
|
5166
5634
|
getVendorResourceInfo,
|
|
5635
|
+
grantAssociateGrants,
|
|
5167
5636
|
handleEventLicenceCompliance,
|
|
5168
5637
|
handlePartnerLicenceCompliance,
|
|
5169
5638
|
handleVendorLicenceCompliance,
|
|
5639
|
+
hasActiveProLicenceForResource,
|
|
5170
5640
|
hasValidLicence,
|
|
5641
|
+
isAssociableResourceType,
|
|
5642
|
+
isProLicence,
|
|
5643
|
+
isProtectedByCurrentStripeSubscription,
|
|
5171
5644
|
isStandardLicence,
|
|
5172
5645
|
isValidObjectId,
|
|
5173
5646
|
licenceCategoryMapping,
|
|
@@ -5182,6 +5655,7 @@ async function remindUsersAboutLicenseExpiration() {
|
|
|
5182
5655
|
processUserCompliance,
|
|
5183
5656
|
processUserLicenseReminders,
|
|
5184
5657
|
publishNotificationEvents,
|
|
5658
|
+
reconcileAssociateGrants,
|
|
5185
5659
|
remindUsersAboutLicenseExpiration,
|
|
5186
5660
|
replaceUserLicenceWithObject,
|
|
5187
5661
|
restoreVendorProFeatures,
|