@timardex/cluemart-server-shared 4.0.8 → 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-TSKI3WB2.mjs → chunk-ABW2L2HY.mjs} +81 -2
- package/dist/chunk-ABW2L2HY.mjs.map +1 -0
- package/dist/index.cjs +665 -169
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.mts +294 -10
- package/dist/index.d.ts +294 -10
- package/dist/index.mjs +558 -70
- package/dist/index.mjs.map +1 -1
- package/dist/mongoose/index.cjs +80 -1
- package/dist/mongoose/index.cjs.map +1 -1
- package/dist/mongoose/index.d.mts +57 -9
- package/dist/mongoose/index.d.ts +57 -9
- package/dist/mongoose/index.mjs +3 -1
- package/dist/service/index.cjs +662 -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-TSKI3WB2.mjs.map +0 -1
package/dist/index.cjs
CHANGED
|
@@ -44,6 +44,7 @@ __export(index_exports, {
|
|
|
44
44
|
AiImportRunModel: () => AiImportRunModel,
|
|
45
45
|
AiImportedMarketModel: () => AiImportedMarketModel,
|
|
46
46
|
AppSettingModel: () => AppSettingModel,
|
|
47
|
+
AssociateTypeSchema: () => AssociateTypeSchema,
|
|
47
48
|
AuthHandoffTokenModel: () => AuthHandoffTokenModel,
|
|
48
49
|
BILLING_CATALOG_COLLECTION_NAME: () => BILLING_CATALOG_COLLECTION_NAME,
|
|
49
50
|
BillingCatalogModel: () => BillingCatalogModel,
|
|
@@ -83,6 +84,7 @@ __export(index_exports, {
|
|
|
83
84
|
VendorInfoModel: () => VendorInfoModel,
|
|
84
85
|
VendorModel: () => VendorModel,
|
|
85
86
|
VerificationTokenModel: () => VerificationTokenModel,
|
|
87
|
+
acceptedAssociateUserIds: () => acceptedAssociateUserIds,
|
|
86
88
|
activeAffiliateCodeExists: () => activeAffiliateCodeExists,
|
|
87
89
|
awardAffiliateVendorSubscriptionRewards: () => awardAffiliateVendorSubscriptionRewards,
|
|
88
90
|
baseResourceFields: () => baseResourceFields,
|
|
@@ -99,6 +101,9 @@ __export(index_exports, {
|
|
|
99
101
|
createLicenceObject: () => createLicenceObject,
|
|
100
102
|
dateTimeSchema: () => dateTimeSchema,
|
|
101
103
|
dedupeArchivedSlotsByStartDateTime: () => dedupeArchivedSlotsByStartDateTime,
|
|
104
|
+
detachAssociateGrantsForResources: () => detachAssociateGrantsForResources,
|
|
105
|
+
detachStaleAssociateGrants: () => detachStaleAssociateGrants,
|
|
106
|
+
detachUsersFromResource: () => detachUsersFromResource,
|
|
102
107
|
didRemoveAnyEventDates: () => didRemoveAnyEventDates,
|
|
103
108
|
didRemoveAnyStartedDates: () => didRemoveAnyStartedDates,
|
|
104
109
|
downgradeVendorProFeatures: () => downgradeVendorProFeatures,
|
|
@@ -109,6 +114,8 @@ __export(index_exports, {
|
|
|
109
114
|
express: () => import_express.default,
|
|
110
115
|
findAffiliateByPromoCode: () => findAffiliateByPromoCode,
|
|
111
116
|
findEventOrImportedMarketById: () => findEventOrImportedMarketById,
|
|
117
|
+
getActiveLicenceForResource: () => getActiveLicenceForResource,
|
|
118
|
+
getAssociateAccessMeta: () => getAssociateAccessMeta,
|
|
112
119
|
getBillingCatalogDefinition: () => getBillingCatalogDefinition,
|
|
113
120
|
getEventResourceInfo: () => getEventResourceInfo,
|
|
114
121
|
getHighestLicenceForCategory: () => getHighestLicenceForCategory,
|
|
@@ -119,11 +126,17 @@ __export(index_exports, {
|
|
|
119
126
|
getPayingStripeSubscriptionPlan: () => getPayingStripeSubscriptionPlan,
|
|
120
127
|
getPayingVendorStripeSubscriptionPlan: () => getPayingVendorStripeSubscriptionPlan,
|
|
121
128
|
getSubscriptionRewardPeriodBounds: () => getSubscriptionRewardPeriodBounds,
|
|
129
|
+
getUserIdsWithActiveProLicence: () => getUserIdsWithActiveProLicence,
|
|
122
130
|
getVendorResourceInfo: () => getVendorResourceInfo,
|
|
131
|
+
grantAssociateGrants: () => grantAssociateGrants,
|
|
123
132
|
handleEventLicenceCompliance: () => handleEventLicenceCompliance,
|
|
124
133
|
handlePartnerLicenceCompliance: () => handlePartnerLicenceCompliance,
|
|
125
134
|
handleVendorLicenceCompliance: () => handleVendorLicenceCompliance,
|
|
135
|
+
hasActiveProLicenceForResource: () => hasActiveProLicenceForResource,
|
|
126
136
|
hasValidLicence: () => hasValidLicence,
|
|
137
|
+
isAssociableResourceType: () => isAssociableResourceType,
|
|
138
|
+
isProLicence: () => isProLicence,
|
|
139
|
+
isProtectedByCurrentStripeSubscription: () => isProtectedByCurrentStripeSubscription,
|
|
127
140
|
isStandardLicence: () => isStandardLicence,
|
|
128
141
|
isValidObjectId: () => isValidObjectId,
|
|
129
142
|
licenceCategoryMapping: () => licenceCategoryMapping,
|
|
@@ -131,7 +144,7 @@ __export(index_exports, {
|
|
|
131
144
|
locationGeoSchema: () => locationGeoSchema,
|
|
132
145
|
locationsSchema: () => locationsSchema,
|
|
133
146
|
mapVendorLicenceToSubscriptionRewardType: () => mapVendorLicenceToSubscriptionRewardType,
|
|
134
|
-
mongoose: () =>
|
|
147
|
+
mongoose: () => import_mongoose45.default,
|
|
135
148
|
normalizeAffiliatePromoCodes: () => normalizeAffiliatePromoCodes,
|
|
136
149
|
normalizePromoCode: () => normalizePromoCode,
|
|
137
150
|
notifyUsers: () => notifyUsers,
|
|
@@ -141,6 +154,7 @@ __export(index_exports, {
|
|
|
141
154
|
processUserCompliance: () => processUserCompliance,
|
|
142
155
|
processUserLicenseReminders: () => processUserLicenseReminders,
|
|
143
156
|
publishNotificationEvents: () => publishNotificationEvents,
|
|
157
|
+
reconcileAssociateGrants: () => reconcileAssociateGrants,
|
|
144
158
|
refundPolicySchema: () => refundPolicySchema,
|
|
145
159
|
relatedPostSchema: () => relatedPostSchema,
|
|
146
160
|
relationDatesSchema: () => relationDatesSchema,
|
|
@@ -160,7 +174,7 @@ __export(index_exports, {
|
|
|
160
174
|
updateAdStatuses: () => updateAdStatuses,
|
|
161
175
|
updateAllEventDateTimeStatuses: () => updateAllEventDateTimeStatuses,
|
|
162
176
|
updateRelationDatesToCanceled: () => updateRelationDatesToCanceled,
|
|
163
|
-
updateSingleDateTimeStatus: () =>
|
|
177
|
+
updateSingleDateTimeStatus: () => import_cluemart_shared39.updateSingleDateTimeStatus,
|
|
164
178
|
upgradeUserToLicence: () => upgradeUserToLicence,
|
|
165
179
|
userLicenseSchema: () => userLicenseSchema,
|
|
166
180
|
vendorOwnerHasProLicence: () => vendorOwnerHasProLicence,
|
|
@@ -850,6 +864,25 @@ var OwnerTypeSchema = new MongooseSchema5(
|
|
|
850
864
|
{ _id: false }
|
|
851
865
|
// Prevents Mongoose from creating an additional _id field for subdocuments
|
|
852
866
|
);
|
|
867
|
+
var AssociateTypeSchema = new MongooseSchema5(
|
|
868
|
+
{
|
|
869
|
+
addedAt: { default: Date.now, required: false, type: Date },
|
|
870
|
+
email: { lowercase: true, required: true, trim: true, type: String },
|
|
871
|
+
respondedAt: { default: null, required: false, type: Date },
|
|
872
|
+
status: {
|
|
873
|
+
default: import_cluemart_shared8.EnumAssociateStatus.PENDING,
|
|
874
|
+
enum: Object.values(import_cluemart_shared8.EnumAssociateStatus),
|
|
875
|
+
required: true,
|
|
876
|
+
type: String
|
|
877
|
+
},
|
|
878
|
+
userId: {
|
|
879
|
+
ref: "User",
|
|
880
|
+
required: true,
|
|
881
|
+
type: import_mongoose9.default.Schema.Types.ObjectId
|
|
882
|
+
}
|
|
883
|
+
},
|
|
884
|
+
{ _id: false }
|
|
885
|
+
);
|
|
853
886
|
var SocialMediaTypeSchema = new MongooseSchema5(
|
|
854
887
|
{
|
|
855
888
|
link: { required: true, type: String },
|
|
@@ -1015,6 +1048,7 @@ var baseResourceFields = {
|
|
|
1015
1048
|
type: [import_mongoose9.default.Schema.Types.ObjectId]
|
|
1016
1049
|
},
|
|
1017
1050
|
approvedAt: { default: null, required: false, type: Date },
|
|
1051
|
+
associates: { default: [], required: false, type: [AssociateTypeSchema] },
|
|
1018
1052
|
contactDetails: { required: false, type: ContactDetailsSchema },
|
|
1019
1053
|
cover: {
|
|
1020
1054
|
required: true,
|
|
@@ -1281,6 +1315,8 @@ var schema8 = new MongooseSchema7(
|
|
|
1281
1315
|
missingFields: { required: false, type: [String] },
|
|
1282
1316
|
name: { required: true, type: String },
|
|
1283
1317
|
openingHours: { required: false, type: [String] },
|
|
1318
|
+
publicationCityUnknown: { default: false, required: false, type: Boolean },
|
|
1319
|
+
publicationKey: { required: false, type: String },
|
|
1284
1320
|
rainOrShine: { required: true, type: Boolean },
|
|
1285
1321
|
rating: { required: false, type: Number },
|
|
1286
1322
|
region: { required: false, type: String },
|
|
@@ -1292,6 +1328,7 @@ var schema8 = new MongooseSchema7(
|
|
|
1292
1328
|
required: false,
|
|
1293
1329
|
type: import_mongoose11.default.Schema.Types.ObjectId
|
|
1294
1330
|
},
|
|
1331
|
+
reviewerEditedAt: { default: null, required: false, type: Date },
|
|
1295
1332
|
reviewStatus: {
|
|
1296
1333
|
default: import_cluemart_shared10.EnumImportedMarketReviewStatus.PENDING,
|
|
1297
1334
|
enum: Object.values(import_cluemart_shared10.EnumImportedMarketReviewStatus),
|
|
@@ -1328,6 +1365,16 @@ schema8.index({
|
|
|
1328
1365
|
_id: 1
|
|
1329
1366
|
});
|
|
1330
1367
|
schema8.index({ region: 1, searchName: 1 });
|
|
1368
|
+
schema8.index(
|
|
1369
|
+
{ publicationKey: 1 },
|
|
1370
|
+
{
|
|
1371
|
+
name: "ai_market_publication_key",
|
|
1372
|
+
partialFilterExpression: {
|
|
1373
|
+
publicationKey: { $exists: true, $type: "string" }
|
|
1374
|
+
},
|
|
1375
|
+
unique: true
|
|
1376
|
+
}
|
|
1377
|
+
);
|
|
1331
1378
|
schema8.index({ slug: 1 });
|
|
1332
1379
|
schema8.index({ reviewStatus: 1 });
|
|
1333
1380
|
schema8.index({ description: "text", name: "text" });
|
|
@@ -1883,6 +1930,29 @@ var userOverallPointsSchema = new MongooseSchema16(
|
|
|
1883
1930
|
},
|
|
1884
1931
|
{ _id: false }
|
|
1885
1932
|
);
|
|
1933
|
+
var userAssociatedResourcesSchema = new MongooseSchema16(
|
|
1934
|
+
{
|
|
1935
|
+
events: {
|
|
1936
|
+
default: [],
|
|
1937
|
+
ref: "Event",
|
|
1938
|
+
required: false,
|
|
1939
|
+
type: [import_mongoose20.default.Schema.Types.ObjectId]
|
|
1940
|
+
},
|
|
1941
|
+
partners: {
|
|
1942
|
+
default: [],
|
|
1943
|
+
ref: "Partner",
|
|
1944
|
+
required: false,
|
|
1945
|
+
type: [import_mongoose20.default.Schema.Types.ObjectId]
|
|
1946
|
+
},
|
|
1947
|
+
vendors: {
|
|
1948
|
+
default: [],
|
|
1949
|
+
ref: "Vendor",
|
|
1950
|
+
required: false,
|
|
1951
|
+
type: [import_mongoose20.default.Schema.Types.ObjectId]
|
|
1952
|
+
}
|
|
1953
|
+
},
|
|
1954
|
+
{ _id: false }
|
|
1955
|
+
);
|
|
1886
1956
|
var schema15 = new MongooseSchema16(
|
|
1887
1957
|
{
|
|
1888
1958
|
active: { default: false, required: true, type: Boolean },
|
|
@@ -1891,6 +1961,11 @@ var schema15 = new MongooseSchema16(
|
|
|
1891
1961
|
required: false,
|
|
1892
1962
|
type: import_mongoose20.default.Schema.Types.ObjectId
|
|
1893
1963
|
},
|
|
1964
|
+
associatedResources: {
|
|
1965
|
+
default: () => ({ events: [], partners: [], vendors: [] }),
|
|
1966
|
+
required: false,
|
|
1967
|
+
type: userAssociatedResourcesSchema
|
|
1968
|
+
},
|
|
1894
1969
|
avatar: {
|
|
1895
1970
|
required: false,
|
|
1896
1971
|
type: ResourceImageTypeSchema
|
|
@@ -1901,7 +1976,10 @@ var schema15 = new MongooseSchema16(
|
|
|
1901
1976
|
type: import_mongoose20.default.Schema.Types.ObjectId
|
|
1902
1977
|
},
|
|
1903
1978
|
deletedAt: { default: null, required: false, type: Date },
|
|
1904
|
-
|
|
1979
|
+
// `normalizeEmail` (`cluemart-shared`) is trim + lower-case; keeping the same
|
|
1980
|
+
// rule here means every write path — resolvers, seeds, scripts — stores the
|
|
1981
|
+
// comparable form, not only the clients that validate through `emailRequiredSchema`.
|
|
1982
|
+
email: { lowercase: true, required: true, trim: true, type: String },
|
|
1905
1983
|
emailSentFor: {
|
|
1906
1984
|
enum: Object.values(import_cluemart_shared16.EnumNotificationResourceType),
|
|
1907
1985
|
required: false,
|
|
@@ -2016,6 +2094,9 @@ schema15.index({ "licences.expiryDate": 1 });
|
|
|
2016
2094
|
schema15.index({ "licences.licenceType": 1 });
|
|
2017
2095
|
schema15.index({ promoCodes: 1, active: 1, deletedAt: 1 });
|
|
2018
2096
|
schema15.index({ email: "text", firstName: "text", lastName: "text" });
|
|
2097
|
+
schema15.index({ "associatedResources.events": 1 });
|
|
2098
|
+
schema15.index({ "associatedResources.partners": 1 });
|
|
2099
|
+
schema15.index({ "associatedResources.vendors": 1 });
|
|
2019
2100
|
var UserModel = import_mongoose20.default.models.User || import_mongoose20.default.model("User", schema15);
|
|
2020
2101
|
|
|
2021
2102
|
// src/mongoose/VerificationToken.ts
|
|
@@ -2149,6 +2230,7 @@ schema17.index({
|
|
|
2149
2230
|
name: "text"
|
|
2150
2231
|
});
|
|
2151
2232
|
schema17.index({ deletedAt: 1, "owner.userId": 1 });
|
|
2233
|
+
schema17.index({ "associates.userId": 1, deletedAt: 1 });
|
|
2152
2234
|
schema17.plugin(searchNamePlugin);
|
|
2153
2235
|
var VendorModel = import_mongoose22.default.models.Vendor || import_mongoose22.default.model("Vendor", schema17);
|
|
2154
2236
|
|
|
@@ -2254,6 +2336,13 @@ var schema20 = new MongooseSchema21(
|
|
|
2254
2336
|
{
|
|
2255
2337
|
...baseResourceFields,
|
|
2256
2338
|
// Importing base resource fields from global.ts
|
|
2339
|
+
// Claim link of the AI-imported market this event was created from, the
|
|
2340
|
+
// counterpart of `googlePlaceId`. Written once by `createEvent`.
|
|
2341
|
+
aiImportedMarketSourceKey: {
|
|
2342
|
+
default: null,
|
|
2343
|
+
required: false,
|
|
2344
|
+
type: String
|
|
2345
|
+
},
|
|
2257
2346
|
claimed: { default: true, required: false, type: Boolean },
|
|
2258
2347
|
dateTime: { required: true, type: [dateTimeSchema] },
|
|
2259
2348
|
eventInfoId: {
|
|
@@ -2293,6 +2382,7 @@ schema20.index({ "dateTime.dateStatus": 1 });
|
|
|
2293
2382
|
schema20.index({ slug: 1 });
|
|
2294
2383
|
schema20.index({ description: "text", name: "text", tags: "text" });
|
|
2295
2384
|
schema20.index({ deletedAt: 1, "owner.userId": 1 });
|
|
2385
|
+
schema20.index({ "associates.userId": 1, deletedAt: 1 });
|
|
2296
2386
|
schema20.plugin(searchNamePlugin);
|
|
2297
2387
|
var EventModel = import_mongoose25.default.models.Event || import_mongoose25.default.model("Event", schema20);
|
|
2298
2388
|
|
|
@@ -2339,6 +2429,7 @@ schema22.index({ "location.geo": "2dsphere" });
|
|
|
2339
2429
|
schema22.index({ slug: 1 });
|
|
2340
2430
|
schema22.index({ name: "text", description: "text" });
|
|
2341
2431
|
schema22.index({ "owner.userId": 1, deletedAt: 1 });
|
|
2432
|
+
schema22.index({ "associates.userId": 1, deletedAt: 1 });
|
|
2342
2433
|
schema22.plugin(searchNamePlugin);
|
|
2343
2434
|
var PartnerModel = import_mongoose27.default.models.Partner || import_mongoose27.default.model("Partner", schema22);
|
|
2344
2435
|
|
|
@@ -3404,14 +3495,310 @@ function normalizeAffiliatePromoCodes(promoCodes) {
|
|
|
3404
3495
|
return [...new Set(normalized)];
|
|
3405
3496
|
}
|
|
3406
3497
|
|
|
3498
|
+
// src/service/associates/index.ts
|
|
3499
|
+
var import_cluemart_shared28 = require("@timardex/cluemart-shared");
|
|
3500
|
+
var import_mongoose42 = __toESM(require("mongoose"));
|
|
3501
|
+
function isAssociableResourceType(resourceType) {
|
|
3502
|
+
return resourceType === import_cluemart_shared28.EnumResourceType.EVENT || resourceType === import_cluemart_shared28.EnumResourceType.PARTNER || resourceType === import_cluemart_shared28.EnumResourceType.VENDOR;
|
|
3503
|
+
}
|
|
3504
|
+
function getAssociateAccessMeta(resourceType) {
|
|
3505
|
+
if (resourceType === import_cluemart_shared28.EnumResourceType.EVENT) {
|
|
3506
|
+
return {
|
|
3507
|
+
associatedField: "events",
|
|
3508
|
+
associatedPath: "associatedResources.events",
|
|
3509
|
+
associateRole: import_cluemart_shared28.EnumUserRole.ASSOCIATED_EVENT
|
|
3510
|
+
};
|
|
3511
|
+
}
|
|
3512
|
+
if (resourceType === import_cluemart_shared28.EnumResourceType.PARTNER) {
|
|
3513
|
+
return {
|
|
3514
|
+
associatedField: "partners",
|
|
3515
|
+
associatedPath: "associatedResources.partners",
|
|
3516
|
+
associateRole: import_cluemart_shared28.EnumUserRole.ASSOCIATED_PARTNER
|
|
3517
|
+
};
|
|
3518
|
+
}
|
|
3519
|
+
return {
|
|
3520
|
+
associatedField: "vendors",
|
|
3521
|
+
associatedPath: "associatedResources.vendors",
|
|
3522
|
+
associateRole: import_cluemart_shared28.EnumUserRole.ASSOCIATED_VENDOR
|
|
3523
|
+
};
|
|
3524
|
+
}
|
|
3525
|
+
var ASSOCIABLE_MODELS = {
|
|
3526
|
+
[import_cluemart_shared28.EnumResourceType.EVENT]: EventModel,
|
|
3527
|
+
[import_cluemart_shared28.EnumResourceType.PARTNER]: PartnerModel,
|
|
3528
|
+
[import_cluemart_shared28.EnumResourceType.VENDOR]: VendorModel
|
|
3529
|
+
};
|
|
3530
|
+
function acceptedAssociateUserIds(associates) {
|
|
3531
|
+
return (associates ?? []).filter((associate) => associate.status === import_cluemart_shared28.EnumAssociateStatus.ACCEPTED).map((associate) => associate.userId);
|
|
3532
|
+
}
|
|
3533
|
+
async function detachUsersFromResource({
|
|
3534
|
+
resourceId,
|
|
3535
|
+
resourceType,
|
|
3536
|
+
userIds
|
|
3537
|
+
}) {
|
|
3538
|
+
if (userIds.length === 0) return;
|
|
3539
|
+
const { associateRole, associatedPath: path } = getAssociateAccessMeta(resourceType);
|
|
3540
|
+
const removedResourceId = typeof resourceId === "string" ? new import_mongoose42.default.Types.ObjectId(resourceId) : resourceId;
|
|
3541
|
+
await UserModel.updateMany({ _id: { $in: userIds } }, [
|
|
3542
|
+
{
|
|
3543
|
+
$set: {
|
|
3544
|
+
[path]: {
|
|
3545
|
+
$setDifference: [{ $ifNull: [`$${path}`, []] }, [removedResourceId]]
|
|
3546
|
+
}
|
|
3547
|
+
}
|
|
3548
|
+
},
|
|
3549
|
+
{
|
|
3550
|
+
$set: {
|
|
3551
|
+
roles: {
|
|
3552
|
+
$cond: [
|
|
3553
|
+
{ $eq: [{ $size: { $ifNull: [`$${path}`, []] } }, 0] },
|
|
3554
|
+
{
|
|
3555
|
+
$setDifference: [{ $ifNull: ["$roles", []] }, [associateRole]]
|
|
3556
|
+
},
|
|
3557
|
+
"$roles"
|
|
3558
|
+
]
|
|
3559
|
+
}
|
|
3560
|
+
}
|
|
3561
|
+
}
|
|
3562
|
+
]).exec();
|
|
3563
|
+
}
|
|
3564
|
+
async function acceptedUserIdsForResource({
|
|
3565
|
+
resourceId,
|
|
3566
|
+
resourceType
|
|
3567
|
+
}) {
|
|
3568
|
+
const model = ASSOCIABLE_MODELS[resourceType];
|
|
3569
|
+
const resource = await model.findOne({ _id: resourceId, deletedAt: null }).select("associates").lean().exec();
|
|
3570
|
+
return new Set(
|
|
3571
|
+
acceptedAssociateUserIds(resource?.associates).map(
|
|
3572
|
+
(userId) => String(userId)
|
|
3573
|
+
)
|
|
3574
|
+
);
|
|
3575
|
+
}
|
|
3576
|
+
async function grantAssociateGrants({
|
|
3577
|
+
resourceId,
|
|
3578
|
+
resourceType,
|
|
3579
|
+
userIds
|
|
3580
|
+
}) {
|
|
3581
|
+
if (userIds.length === 0) return;
|
|
3582
|
+
const acceptedUserIds = await acceptedUserIdsForResource({
|
|
3583
|
+
resourceId,
|
|
3584
|
+
resourceType
|
|
3585
|
+
});
|
|
3586
|
+
const grantUserIds = userIds.filter(
|
|
3587
|
+
(userId) => acceptedUserIds.has(String(userId))
|
|
3588
|
+
);
|
|
3589
|
+
if (grantUserIds.length === 0) return;
|
|
3590
|
+
const { associateRole, associatedPath } = getAssociateAccessMeta(resourceType);
|
|
3591
|
+
await UserModel.updateMany(
|
|
3592
|
+
{ _id: { $in: grantUserIds } },
|
|
3593
|
+
{
|
|
3594
|
+
$addToSet: {
|
|
3595
|
+
[associatedPath]: resourceId,
|
|
3596
|
+
roles: associateRole
|
|
3597
|
+
}
|
|
3598
|
+
}
|
|
3599
|
+
).exec();
|
|
3600
|
+
}
|
|
3601
|
+
async function detachUnlessStillAccepted({
|
|
3602
|
+
resourceId,
|
|
3603
|
+
resourceType,
|
|
3604
|
+
userIds
|
|
3605
|
+
}) {
|
|
3606
|
+
if (userIds.length === 0) return [];
|
|
3607
|
+
await detachUsersFromResource({ resourceId, resourceType, userIds });
|
|
3608
|
+
const acceptedAfterDetach = await acceptedUserIdsForResource({
|
|
3609
|
+
resourceId,
|
|
3610
|
+
resourceType
|
|
3611
|
+
});
|
|
3612
|
+
const restoredUserIds = userIds.filter(
|
|
3613
|
+
(userId) => acceptedAfterDetach.has(String(userId))
|
|
3614
|
+
);
|
|
3615
|
+
if (restoredUserIds.length === 0) return userIds;
|
|
3616
|
+
await grantAssociateGrants({
|
|
3617
|
+
resourceId,
|
|
3618
|
+
resourceType,
|
|
3619
|
+
userIds: restoredUserIds
|
|
3620
|
+
});
|
|
3621
|
+
const acceptedAfterRestore = await acceptedUserIdsForResource({
|
|
3622
|
+
resourceId,
|
|
3623
|
+
resourceType
|
|
3624
|
+
});
|
|
3625
|
+
const regressedUserIds = restoredUserIds.filter(
|
|
3626
|
+
(userId) => !acceptedAfterRestore.has(String(userId))
|
|
3627
|
+
);
|
|
3628
|
+
if (regressedUserIds.length > 0) {
|
|
3629
|
+
await detachUsersFromResource({
|
|
3630
|
+
resourceId,
|
|
3631
|
+
resourceType,
|
|
3632
|
+
userIds: regressedUserIds
|
|
3633
|
+
});
|
|
3634
|
+
}
|
|
3635
|
+
return userIds.filter((userId) => !acceptedAfterRestore.has(String(userId)));
|
|
3636
|
+
}
|
|
3637
|
+
async function detachStaleAssociateGrants({
|
|
3638
|
+
acceptedUserIds,
|
|
3639
|
+
resourceId,
|
|
3640
|
+
resourceType
|
|
3641
|
+
}) {
|
|
3642
|
+
const { associatedPath } = getAssociateAccessMeta(resourceType);
|
|
3643
|
+
const stale = await UserModel.find({
|
|
3644
|
+
_id: { $nin: acceptedUserIds },
|
|
3645
|
+
[associatedPath]: resourceId
|
|
3646
|
+
}).select("_id").lean().exec();
|
|
3647
|
+
const staleUserIds = stale.map((user) => user._id);
|
|
3648
|
+
return detachUnlessStillAccepted({
|
|
3649
|
+
resourceId,
|
|
3650
|
+
resourceType,
|
|
3651
|
+
userIds: staleUserIds
|
|
3652
|
+
});
|
|
3653
|
+
}
|
|
3654
|
+
async function detachAssociateGrantsForResources({
|
|
3655
|
+
resources
|
|
3656
|
+
}) {
|
|
3657
|
+
const result = resources.map((resource) => ({
|
|
3658
|
+
detachedUserIds: [],
|
|
3659
|
+
resourceId: resource.resourceId,
|
|
3660
|
+
resourceType: resource.resourceType
|
|
3661
|
+
}));
|
|
3662
|
+
const indexByType = /* @__PURE__ */ new Map();
|
|
3663
|
+
resources.forEach((resource, index) => {
|
|
3664
|
+
const entries = indexByType.get(resource.resourceType) ?? [];
|
|
3665
|
+
entries.push({ index, resourceId: resource.resourceId });
|
|
3666
|
+
indexByType.set(resource.resourceType, entries);
|
|
3667
|
+
});
|
|
3668
|
+
for (const [resourceType, entries] of indexByType) {
|
|
3669
|
+
const { associatedField, associatedPath } = getAssociateAccessMeta(resourceType);
|
|
3670
|
+
const resourceIds = entries.map((entry) => entry.resourceId);
|
|
3671
|
+
const wanted = new Set(resourceIds.map((resourceId) => String(resourceId)));
|
|
3672
|
+
const holders = await UserModel.find({
|
|
3673
|
+
[associatedPath]: { $in: resourceIds }
|
|
3674
|
+
}).select("_id associatedResources").lean().exec();
|
|
3675
|
+
const userIdsByResource = /* @__PURE__ */ new Map();
|
|
3676
|
+
for (const user of holders) {
|
|
3677
|
+
for (const heldResourceId of user.associatedResources?.[associatedField] ?? []) {
|
|
3678
|
+
const key = String(heldResourceId);
|
|
3679
|
+
if (!wanted.has(key)) continue;
|
|
3680
|
+
const userIds = userIdsByResource.get(key) ?? [];
|
|
3681
|
+
userIds.push(user._id);
|
|
3682
|
+
userIdsByResource.set(key, userIds);
|
|
3683
|
+
}
|
|
3684
|
+
}
|
|
3685
|
+
for (const entry of entries) {
|
|
3686
|
+
const userIds = userIdsByResource.get(String(entry.resourceId));
|
|
3687
|
+
if (!userIds || userIds.length === 0) continue;
|
|
3688
|
+
await detachUsersFromResource({
|
|
3689
|
+
resourceId: entry.resourceId,
|
|
3690
|
+
resourceType,
|
|
3691
|
+
userIds
|
|
3692
|
+
});
|
|
3693
|
+
result[entry.index].detachedUserIds = userIds;
|
|
3694
|
+
}
|
|
3695
|
+
}
|
|
3696
|
+
return result;
|
|
3697
|
+
}
|
|
3698
|
+
var DEFAULT_RECONCILE_BATCH_SIZE = 500;
|
|
3699
|
+
async function reconcileUserBatch({
|
|
3700
|
+
associatedField,
|
|
3701
|
+
model,
|
|
3702
|
+
resourceType,
|
|
3703
|
+
users
|
|
3704
|
+
}) {
|
|
3705
|
+
const heldByResource = /* @__PURE__ */ new Map();
|
|
3706
|
+
for (const user of users) {
|
|
3707
|
+
for (const resourceId of user.associatedResources?.[associatedField] ?? []) {
|
|
3708
|
+
const key = String(resourceId);
|
|
3709
|
+
const entry = heldByResource.get(key) ?? { resourceId, userIds: [] };
|
|
3710
|
+
entry.userIds.push(user._id);
|
|
3711
|
+
heldByResource.set(key, entry);
|
|
3712
|
+
}
|
|
3713
|
+
}
|
|
3714
|
+
if (heldByResource.size === 0) return 0;
|
|
3715
|
+
const resources = await model.find({
|
|
3716
|
+
_id: {
|
|
3717
|
+
$in: [...heldByResource.values()].map((entry) => entry.resourceId)
|
|
3718
|
+
}
|
|
3719
|
+
}).select("associates deletedAt").lean().exec();
|
|
3720
|
+
const acceptedByResource = /* @__PURE__ */ new Map();
|
|
3721
|
+
for (const resource of resources) {
|
|
3722
|
+
acceptedByResource.set(
|
|
3723
|
+
String(resource._id),
|
|
3724
|
+
resource.deletedAt ? /* @__PURE__ */ new Set() : new Set(
|
|
3725
|
+
acceptedAssociateUserIds(resource.associates).map(
|
|
3726
|
+
(userId) => String(userId)
|
|
3727
|
+
)
|
|
3728
|
+
)
|
|
3729
|
+
);
|
|
3730
|
+
}
|
|
3731
|
+
let detachedGrants = 0;
|
|
3732
|
+
for (const [key, { resourceId, userIds }] of heldByResource) {
|
|
3733
|
+
const accepted = acceptedByResource.get(key);
|
|
3734
|
+
const staleUserIds = userIds.filter(
|
|
3735
|
+
(userId) => !accepted?.has(String(userId))
|
|
3736
|
+
);
|
|
3737
|
+
if (staleUserIds.length === 0) continue;
|
|
3738
|
+
const removedUserIds = await detachUnlessStillAccepted({
|
|
3739
|
+
resourceId,
|
|
3740
|
+
resourceType,
|
|
3741
|
+
userIds: staleUserIds
|
|
3742
|
+
});
|
|
3743
|
+
detachedGrants += removedUserIds.length;
|
|
3744
|
+
}
|
|
3745
|
+
return detachedGrants;
|
|
3746
|
+
}
|
|
3747
|
+
async function reconcileResourceType({
|
|
3748
|
+
batchSize,
|
|
3749
|
+
resourceType
|
|
3750
|
+
}) {
|
|
3751
|
+
const { associatedField, associatedPath } = getAssociateAccessMeta(resourceType);
|
|
3752
|
+
const model = ASSOCIABLE_MODELS[resourceType];
|
|
3753
|
+
const result = {
|
|
3754
|
+
detachedGrants: 0,
|
|
3755
|
+
scannedUsers: 0
|
|
3756
|
+
};
|
|
3757
|
+
let lastId = null;
|
|
3758
|
+
for (; ; ) {
|
|
3759
|
+
const users = await UserModel.find({
|
|
3760
|
+
...lastId ? { _id: { $gt: lastId } } : {},
|
|
3761
|
+
[associatedPath]: { $exists: true, $ne: [] }
|
|
3762
|
+
}).sort({ _id: 1 }).limit(batchSize).select("_id associatedResources").lean().exec();
|
|
3763
|
+
if (users.length === 0) break;
|
|
3764
|
+
result.scannedUsers += users.length;
|
|
3765
|
+
lastId = users[users.length - 1]._id;
|
|
3766
|
+
result.detachedGrants += await reconcileUserBatch({
|
|
3767
|
+
associatedField,
|
|
3768
|
+
model,
|
|
3769
|
+
resourceType,
|
|
3770
|
+
users
|
|
3771
|
+
});
|
|
3772
|
+
}
|
|
3773
|
+
return result;
|
|
3774
|
+
}
|
|
3775
|
+
async function reconcileAssociateGrants({
|
|
3776
|
+
batchSize = DEFAULT_RECONCILE_BATCH_SIZE
|
|
3777
|
+
} = {}) {
|
|
3778
|
+
const totals = {
|
|
3779
|
+
detachedGrants: 0,
|
|
3780
|
+
scannedUsers: 0
|
|
3781
|
+
};
|
|
3782
|
+
for (const resourceType of [
|
|
3783
|
+
import_cluemart_shared28.EnumResourceType.EVENT,
|
|
3784
|
+
import_cluemart_shared28.EnumResourceType.VENDOR,
|
|
3785
|
+
import_cluemart_shared28.EnumResourceType.PARTNER
|
|
3786
|
+
]) {
|
|
3787
|
+
const result = await reconcileResourceType({ batchSize, resourceType });
|
|
3788
|
+
totals.detachedGrants += result.detachedGrants;
|
|
3789
|
+
totals.scannedUsers += result.scannedUsers;
|
|
3790
|
+
}
|
|
3791
|
+
return totals;
|
|
3792
|
+
}
|
|
3793
|
+
|
|
3407
3794
|
// src/service/database.ts
|
|
3408
|
-
var
|
|
3795
|
+
var import_mongoose44 = __toESM(require("mongoose"));
|
|
3409
3796
|
|
|
3410
3797
|
// src/service/indexes.ts
|
|
3411
|
-
var
|
|
3798
|
+
var import_mongoose43 = __toESM(require("mongoose"));
|
|
3412
3799
|
function registeredModels() {
|
|
3413
|
-
return
|
|
3414
|
-
const model =
|
|
3800
|
+
return import_mongoose43.default.modelNames().map((modelName) => {
|
|
3801
|
+
const model = import_mongoose43.default.model(modelName);
|
|
3415
3802
|
return { createIndexes: () => model.createIndexes(), modelName };
|
|
3416
3803
|
});
|
|
3417
3804
|
}
|
|
@@ -3453,7 +3840,7 @@ var connectToDatabase = async ({
|
|
|
3453
3840
|
// Fallback to MongoDB Atlas connection string
|
|
3454
3841
|
`mongodb+srv://${dbUser}:${dbPassword}@${dbName}.mongodb.net/?retryWrites=true&w=majority&appName=${appName}`
|
|
3455
3842
|
);
|
|
3456
|
-
await
|
|
3843
|
+
await import_mongoose44.default.connect(mongoUri);
|
|
3457
3844
|
const connectionType = mongodbUri ? "Local MongoDB" : "MongoDB Atlas";
|
|
3458
3845
|
console.log(
|
|
3459
3846
|
`${connectionType} connected from server/src/service/database.ts`
|
|
@@ -3469,7 +3856,7 @@ var connectToDatabase = async ({
|
|
|
3469
3856
|
|
|
3470
3857
|
// src/types/index.ts
|
|
3471
3858
|
var import_express = __toESM(require("express"));
|
|
3472
|
-
var
|
|
3859
|
+
var import_mongoose45 = __toESM(require("mongoose"));
|
|
3473
3860
|
var EnumPubSubEvents = /* @__PURE__ */ ((EnumPubSubEvents2) => {
|
|
3474
3861
|
EnumPubSubEvents2["GET_CHAT_MESSAGE"] = "GET_CHAT_MESSAGE";
|
|
3475
3862
|
EnumPubSubEvents2["GET_NOTIFICATIONS"] = "GET_NOTIFICATIONS";
|
|
@@ -3524,9 +3911,9 @@ async function notifyUsers({
|
|
|
3524
3911
|
}
|
|
3525
3912
|
|
|
3526
3913
|
// src/service/updateAdStatus.ts
|
|
3527
|
-
var
|
|
3914
|
+
var import_cluemart_shared29 = require("@timardex/cluemart-shared");
|
|
3528
3915
|
async function updateAdStatuses() {
|
|
3529
|
-
const now = (0,
|
|
3916
|
+
const now = (0, import_cluemart_shared29.nzDayKey)();
|
|
3530
3917
|
const invalidResult = await AdModel.updateMany(
|
|
3531
3918
|
{
|
|
3532
3919
|
$or: [
|
|
@@ -3534,50 +3921,50 @@ async function updateAdStatuses() {
|
|
|
3534
3921
|
{ end: { $exists: false } },
|
|
3535
3922
|
{ $expr: { $gt: ["$start", "$end"] } }
|
|
3536
3923
|
],
|
|
3537
|
-
status: { $ne:
|
|
3924
|
+
status: { $ne: import_cluemart_shared29.EnumAdStatus.PAUSED }
|
|
3538
3925
|
},
|
|
3539
|
-
{ $set: { status:
|
|
3926
|
+
{ $set: { status: import_cluemart_shared29.EnumAdStatus.PAUSED } }
|
|
3540
3927
|
);
|
|
3541
3928
|
const expiredResult = await AdModel.updateMany(
|
|
3542
|
-
{ end: { $lte: now }, status: { $ne:
|
|
3543
|
-
{ $set: { status:
|
|
3929
|
+
{ end: { $lte: now }, status: { $ne: import_cluemart_shared29.EnumAdStatus.EXPIRED } },
|
|
3930
|
+
{ $set: { status: import_cluemart_shared29.EnumAdStatus.EXPIRED } }
|
|
3544
3931
|
);
|
|
3545
3932
|
const eligibleBooking = {
|
|
3546
3933
|
$or: [
|
|
3547
3934
|
{ bookingKind: { $exists: false } },
|
|
3548
3935
|
{ bookingKind: null },
|
|
3549
3936
|
{
|
|
3550
|
-
approvalStatus:
|
|
3551
|
-
bookingKind:
|
|
3937
|
+
approvalStatus: import_cluemart_shared29.EnumAdApprovalStatus.APPROVED,
|
|
3938
|
+
bookingKind: import_cluemart_shared29.EnumAdBookingSlotKind.RESERVED
|
|
3552
3939
|
},
|
|
3553
3940
|
{
|
|
3554
|
-
approvalStatus:
|
|
3555
|
-
bookingKind:
|
|
3556
|
-
paymentStatus:
|
|
3941
|
+
approvalStatus: import_cluemart_shared29.EnumAdApprovalStatus.APPROVED,
|
|
3942
|
+
bookingKind: import_cluemart_shared29.EnumAdBookingSlotKind.PAID,
|
|
3943
|
+
paymentStatus: import_cluemart_shared29.EnumAdPaymentStatus.PAID
|
|
3557
3944
|
}
|
|
3558
3945
|
]
|
|
3559
3946
|
};
|
|
3560
3947
|
const awaitingApprovalResult = await AdModel.updateMany(
|
|
3561
3948
|
{
|
|
3562
3949
|
$nor: eligibleBooking.$or,
|
|
3563
|
-
bookingKind: { $in: Object.values(
|
|
3950
|
+
bookingKind: { $in: Object.values(import_cluemart_shared29.EnumAdBookingSlotKind) },
|
|
3564
3951
|
end: { $gt: now },
|
|
3565
|
-
status:
|
|
3952
|
+
status: import_cluemart_shared29.EnumAdStatus.ACTIVE
|
|
3566
3953
|
},
|
|
3567
|
-
{ $set: { status:
|
|
3954
|
+
{ $set: { status: import_cluemart_shared29.EnumAdStatus.PAUSED } }
|
|
3568
3955
|
);
|
|
3569
3956
|
const activeResult = await AdModel.updateMany(
|
|
3570
3957
|
{
|
|
3571
3958
|
end: { $gt: now },
|
|
3572
3959
|
start: { $lte: now },
|
|
3573
|
-
status: { $ne:
|
|
3960
|
+
status: { $ne: import_cluemart_shared29.EnumAdStatus.ACTIVE },
|
|
3574
3961
|
...eligibleBooking
|
|
3575
3962
|
},
|
|
3576
|
-
{ $set: { status:
|
|
3963
|
+
{ $set: { status: import_cluemart_shared29.EnumAdStatus.ACTIVE } }
|
|
3577
3964
|
);
|
|
3578
3965
|
const pausedResult = await AdModel.updateMany(
|
|
3579
|
-
{ start: { $gt: now }, status: { $ne:
|
|
3580
|
-
{ $set: { status:
|
|
3966
|
+
{ start: { $gt: now }, status: { $ne: import_cluemart_shared29.EnumAdStatus.PAUSED } },
|
|
3967
|
+
{ $set: { status: import_cluemart_shared29.EnumAdStatus.PAUSED } }
|
|
3581
3968
|
);
|
|
3582
3969
|
console.log(
|
|
3583
3970
|
`\u2705 Ad statuses updated: invalid=${invalidResult.modifiedCount}, expired=${expiredResult.modifiedCount}, awaitingApproval=${awaitingApprovalResult.modifiedCount}, active=${activeResult.modifiedCount}, paused=${pausedResult.modifiedCount}`
|
|
@@ -3585,15 +3972,15 @@ async function updateAdStatuses() {
|
|
|
3585
3972
|
}
|
|
3586
3973
|
|
|
3587
3974
|
// src/service/objectIdToString.ts
|
|
3588
|
-
var
|
|
3975
|
+
var import_mongoose47 = __toESM(require("mongoose"));
|
|
3589
3976
|
function isValidObjectId(value) {
|
|
3590
|
-
return
|
|
3977
|
+
return import_mongoose47.default.Types.ObjectId.isValid(value);
|
|
3591
3978
|
}
|
|
3592
3979
|
function convertObjectIdsToStrings(obj) {
|
|
3593
3980
|
if (obj === null || obj === void 0) {
|
|
3594
3981
|
return obj;
|
|
3595
3982
|
}
|
|
3596
|
-
if (obj instanceof
|
|
3983
|
+
if (obj instanceof import_mongoose47.default.Types.ObjectId) {
|
|
3597
3984
|
return obj.toString();
|
|
3598
3985
|
}
|
|
3599
3986
|
if (obj instanceof Date) {
|
|
@@ -3787,19 +4174,19 @@ function buildUserPointEntryRemovalPipeline(pointType, sourceId) {
|
|
|
3787
4174
|
}
|
|
3788
4175
|
|
|
3789
4176
|
// src/service/event/updateAllEventDateTimeStatuses.ts
|
|
3790
|
-
var
|
|
4177
|
+
var import_cluemart_shared31 = require("@timardex/cluemart-shared");
|
|
3791
4178
|
var import_dayjs4 = __toESM(require("dayjs"));
|
|
3792
4179
|
|
|
3793
4180
|
// src/service/event/archiveEndedEventDates.ts
|
|
3794
|
-
var
|
|
4181
|
+
var import_cluemart_shared30 = require("@timardex/cluemart-shared");
|
|
3795
4182
|
var import_dayjs3 = __toESM(require("dayjs"));
|
|
3796
4183
|
var import_customParseFormat = __toESM(require("dayjs/plugin/customParseFormat"));
|
|
3797
4184
|
import_dayjs3.default.extend(import_customParseFormat.default);
|
|
3798
4185
|
var ARCHIVED_STATUSES = /* @__PURE__ */ new Set([
|
|
3799
|
-
|
|
4186
|
+
import_cluemart_shared30.EnumEventDateStatus.ENDED
|
|
3800
4187
|
]);
|
|
3801
4188
|
var DISCARDED_STATUSES = /* @__PURE__ */ new Set([
|
|
3802
|
-
|
|
4189
|
+
import_cluemart_shared30.EnumEventDateStatus.INVALID
|
|
3803
4190
|
]);
|
|
3804
4191
|
function splitEventDatesForArchive(dateTime) {
|
|
3805
4192
|
return {
|
|
@@ -3822,12 +4209,12 @@ function dedupeArchivedSlotsByStartDateTime(slots) {
|
|
|
3822
4209
|
});
|
|
3823
4210
|
}
|
|
3824
4211
|
function isPastCanceledEventDate(slot, now) {
|
|
3825
|
-
if (slot.dateStatus !==
|
|
4212
|
+
if (slot.dateStatus !== import_cluemart_shared30.EnumEventDateStatus.CANCELED) {
|
|
3826
4213
|
return false;
|
|
3827
4214
|
}
|
|
3828
4215
|
const endDateTime = (0, import_dayjs3.default)(
|
|
3829
4216
|
`${slot.endDate} ${slot.endTime}`,
|
|
3830
|
-
`${
|
|
4217
|
+
`${import_cluemart_shared30.dateFormat} ${import_cluemart_shared30.timeFormat}`,
|
|
3831
4218
|
true
|
|
3832
4219
|
);
|
|
3833
4220
|
return endDateTime.isValid() && endDateTime.isBefore(now);
|
|
@@ -3873,7 +4260,7 @@ async function updateModelDateTimeStatuses(model, now) {
|
|
|
3873
4260
|
try {
|
|
3874
4261
|
for await (const doc of cursor) {
|
|
3875
4262
|
const dateTime = doc.dateTime.map(
|
|
3876
|
-
(slot) => (0,
|
|
4263
|
+
(slot) => (0, import_cluemart_shared31.updateSingleDateTimeStatus)(slot, now)
|
|
3877
4264
|
);
|
|
3878
4265
|
if (!hasDateTimeStatusChanges(doc.dateTime, dateTime)) {
|
|
3879
4266
|
continue;
|
|
@@ -3897,9 +4284,9 @@ async function updateModelDateTimeStatuses(model, now) {
|
|
|
3897
4284
|
var ARCHIVABLE_EVENT_FILTER = {
|
|
3898
4285
|
"dateTime.dateStatus": {
|
|
3899
4286
|
$in: [
|
|
3900
|
-
|
|
3901
|
-
|
|
3902
|
-
|
|
4287
|
+
import_cluemart_shared31.EnumEventDateStatus.ENDED,
|
|
4288
|
+
import_cluemart_shared31.EnumEventDateStatus.INVALID,
|
|
4289
|
+
import_cluemart_shared31.EnumEventDateStatus.CANCELED
|
|
3903
4290
|
]
|
|
3904
4291
|
},
|
|
3905
4292
|
deletedAt: null
|
|
@@ -3924,7 +4311,7 @@ async function archiveEndedAndDiscardInvalidEventDates(now) {
|
|
|
3924
4311
|
try {
|
|
3925
4312
|
for await (const doc of cursor) {
|
|
3926
4313
|
const updated = doc.dateTime.map(
|
|
3927
|
-
(slot) => (0,
|
|
4314
|
+
(slot) => (0, import_cluemart_shared31.updateSingleDateTimeStatus)(slot, now)
|
|
3928
4315
|
);
|
|
3929
4316
|
const { archive, discard } = splitEventDatesForArchive(updated);
|
|
3930
4317
|
const pastCanceled = updated.filter(
|
|
@@ -3948,13 +4335,13 @@ async function archiveEndedAndDiscardInvalidEventDates(now) {
|
|
|
3948
4335
|
if (archive.length > 0 || discard.length > 0) {
|
|
3949
4336
|
pullConditions.push({
|
|
3950
4337
|
dateStatus: {
|
|
3951
|
-
$in: [
|
|
4338
|
+
$in: [import_cluemart_shared31.EnumEventDateStatus.ENDED, import_cluemart_shared31.EnumEventDateStatus.INVALID]
|
|
3952
4339
|
}
|
|
3953
4340
|
});
|
|
3954
4341
|
}
|
|
3955
4342
|
for (const slot of pastCanceled) {
|
|
3956
4343
|
pullConditions.push({
|
|
3957
|
-
dateStatus:
|
|
4344
|
+
dateStatus: import_cluemart_shared31.EnumEventDateStatus.CANCELED,
|
|
3958
4345
|
startDate: slot.startDate,
|
|
3959
4346
|
startTime: slot.startTime
|
|
3960
4347
|
});
|
|
@@ -3996,9 +4383,9 @@ async function cleanEventInfoDates(now) {
|
|
|
3996
4383
|
try {
|
|
3997
4384
|
for await (const doc of cursor) {
|
|
3998
4385
|
const updated = doc.dateTime.map(
|
|
3999
|
-
(slot) => (0,
|
|
4386
|
+
(slot) => (0, import_cluemart_shared31.updateSingleDateTimeStatus)(slot, now)
|
|
4000
4387
|
);
|
|
4001
|
-
const kept = (0,
|
|
4388
|
+
const kept = (0, import_cluemart_shared31.filterDatesByFutureStatus)(updated);
|
|
4002
4389
|
if (kept.length === updated.length) {
|
|
4003
4390
|
continue;
|
|
4004
4391
|
}
|
|
@@ -4048,7 +4435,7 @@ async function updateAllEventDateTimeStatuses() {
|
|
|
4048
4435
|
}
|
|
4049
4436
|
|
|
4050
4437
|
// src/service/index.ts
|
|
4051
|
-
var
|
|
4438
|
+
var import_cluemart_shared39 = require("@timardex/cluemart-shared");
|
|
4052
4439
|
|
|
4053
4440
|
// src/service/event/findEventOrImportedMarketById.ts
|
|
4054
4441
|
async function findEventOrImportedMarketById(resourceId) {
|
|
@@ -4065,7 +4452,7 @@ async function findEventOrImportedMarketById(resourceId) {
|
|
|
4065
4452
|
}
|
|
4066
4453
|
|
|
4067
4454
|
// src/service/relations.ts
|
|
4068
|
-
var
|
|
4455
|
+
var import_cluemart_shared32 = require("@timardex/cluemart-shared");
|
|
4069
4456
|
function didRemoveAnyEventDates(previousDateTime, nextDateTime) {
|
|
4070
4457
|
if (!previousDateTime?.length) {
|
|
4071
4458
|
return false;
|
|
@@ -4081,8 +4468,8 @@ function didRemoveAnyStartedDates(previousDateTime, nextDateTime) {
|
|
|
4081
4468
|
return false;
|
|
4082
4469
|
}
|
|
4083
4470
|
return previousDateTime.some(
|
|
4084
|
-
(prev) => prev.dateStatus ===
|
|
4085
|
-
(next) => next.startDate === prev.startDate && next.startTime === prev.startTime && next.dateStatus ===
|
|
4471
|
+
(prev) => prev.dateStatus === import_cluemart_shared32.EnumEventDateStatus.STARTED && !nextDateTime?.some(
|
|
4472
|
+
(next) => next.startDate === prev.startDate && next.startTime === prev.startTime && next.dateStatus === import_cluemart_shared32.EnumEventDateStatus.STARTED
|
|
4086
4473
|
)
|
|
4087
4474
|
);
|
|
4088
4475
|
}
|
|
@@ -4093,7 +4480,7 @@ function updateRelationDatesToCanceled(relationDates, eventDateTime) {
|
|
|
4093
4480
|
) ?? false;
|
|
4094
4481
|
return {
|
|
4095
4482
|
...relationDate,
|
|
4096
|
-
status: existsInEvent ? relationDate.status :
|
|
4483
|
+
status: existsInEvent ? relationDate.status : import_cluemart_shared32.EnumInviteStatus.CANCELED
|
|
4097
4484
|
};
|
|
4098
4485
|
});
|
|
4099
4486
|
}
|
|
@@ -4102,15 +4489,15 @@ function updateRelationDatesToCanceled(relationDates, eventDateTime) {
|
|
|
4102
4489
|
var import_dayjs8 = __toESM(require("dayjs"));
|
|
4103
4490
|
|
|
4104
4491
|
// src/service/license/compliance/utils.ts
|
|
4105
|
-
var
|
|
4492
|
+
var import_cluemart_shared37 = require("@timardex/cluemart-shared");
|
|
4106
4493
|
var import_dayjs7 = __toESM(require("dayjs"));
|
|
4107
4494
|
|
|
4108
4495
|
// src/service/license/compliance/event.ts
|
|
4109
|
-
var
|
|
4496
|
+
var import_cluemart_shared33 = require("@timardex/cluemart-shared");
|
|
4110
4497
|
var eventLicences = [
|
|
4111
|
-
|
|
4112
|
-
|
|
4113
|
-
|
|
4498
|
+
import_cluemart_shared33.EnumUserLicence.STANDARD_EVENT,
|
|
4499
|
+
import_cluemart_shared33.EnumUserLicence.PRO_EVENT,
|
|
4500
|
+
import_cluemart_shared33.EnumUserLicence.PRO_PLUS_EVENT
|
|
4114
4501
|
];
|
|
4115
4502
|
async function handleEventLicenceCompliance(user, now) {
|
|
4116
4503
|
if (!user.licences || !user.events?.length) {
|
|
@@ -4322,9 +4709,9 @@ function buildLicenceExpiryPipeline(params) {
|
|
|
4322
4709
|
}
|
|
4323
4710
|
|
|
4324
4711
|
// src/service/license/compliance/partner.ts
|
|
4325
|
-
var
|
|
4712
|
+
var import_cluemart_shared34 = require("@timardex/cluemart-shared");
|
|
4326
4713
|
var partnerLicences = [
|
|
4327
|
-
|
|
4714
|
+
import_cluemart_shared34.EnumUserLicence.STANDARD_PARTNER
|
|
4328
4715
|
];
|
|
4329
4716
|
async function handlePartnerLicenceCompliance(user, now) {
|
|
4330
4717
|
if (!user.licences || !user.partner) {
|
|
@@ -4334,52 +4721,62 @@ async function handlePartnerLicenceCompliance(user, now) {
|
|
|
4334
4721
|
}
|
|
4335
4722
|
|
|
4336
4723
|
// src/service/license/compliance/vendor.ts
|
|
4337
|
-
var
|
|
4724
|
+
var import_cluemart_shared36 = require("@timardex/cluemart-shared");
|
|
4338
4725
|
var import_dayjs6 = __toESM(require("dayjs"));
|
|
4339
4726
|
|
|
4340
4727
|
// src/service/license/models.ts
|
|
4341
|
-
var
|
|
4728
|
+
var import_cluemart_shared35 = require("@timardex/cluemart-shared");
|
|
4342
4729
|
var import_dayjs5 = __toESM(require("dayjs"));
|
|
4343
4730
|
var import_graphql = require("graphql");
|
|
4344
|
-
var LicenceCategory = /* @__PURE__ */ ((
|
|
4345
|
-
|
|
4346
|
-
|
|
4347
|
-
|
|
4348
|
-
|
|
4349
|
-
|
|
4350
|
-
return
|
|
4731
|
+
var LicenceCategory = /* @__PURE__ */ ((LicenceCategory3) => {
|
|
4732
|
+
LicenceCategory3["EVENT"] = "event";
|
|
4733
|
+
LicenceCategory3["PARTNER"] = "partner";
|
|
4734
|
+
LicenceCategory3["VENDOR"] = "vendor";
|
|
4735
|
+
LicenceCategory3["AFFILIATE"] = "affiliate";
|
|
4736
|
+
LicenceCategory3["SCHOOL"] = "school";
|
|
4737
|
+
return LicenceCategory3;
|
|
4351
4738
|
})(LicenceCategory || {});
|
|
4352
4739
|
var licenceCategoryMapping = {
|
|
4353
|
-
[
|
|
4354
|
-
[
|
|
4355
|
-
[
|
|
4356
|
-
[
|
|
4357
|
-
[
|
|
4358
|
-
[
|
|
4359
|
-
[
|
|
4360
|
-
[
|
|
4361
|
-
[
|
|
4740
|
+
[import_cluemart_shared35.EnumUserLicence.PRO_EVENT]: "event" /* EVENT */,
|
|
4741
|
+
[import_cluemart_shared35.EnumUserLicence.PRO_PLUS_EVENT]: "event" /* EVENT */,
|
|
4742
|
+
[import_cluemart_shared35.EnumUserLicence.PRO_PLUS_VENDOR]: "vendor" /* VENDOR */,
|
|
4743
|
+
[import_cluemart_shared35.EnumUserLicence.PRO_VENDOR]: "vendor" /* VENDOR */,
|
|
4744
|
+
[import_cluemart_shared35.EnumUserLicence.STANDARD_EVENT]: "event" /* EVENT */,
|
|
4745
|
+
[import_cluemart_shared35.EnumUserLicence.STANDARD_PARTNER]: "partner" /* PARTNER */,
|
|
4746
|
+
[import_cluemart_shared35.EnumUserLicence.STANDARD_VENDOR]: "vendor" /* VENDOR */,
|
|
4747
|
+
[import_cluemart_shared35.EnumUserLicence.STANDARD_AFFILIATE]: "affiliate" /* AFFILIATE */,
|
|
4748
|
+
[import_cluemart_shared35.EnumUserLicence.STANDARD_SCHOOL]: "school" /* SCHOOL */
|
|
4362
4749
|
};
|
|
4363
4750
|
var licencePriority = {
|
|
4364
|
-
[
|
|
4365
|
-
[
|
|
4366
|
-
[
|
|
4367
|
-
[
|
|
4368
|
-
[
|
|
4369
|
-
[
|
|
4370
|
-
[
|
|
4371
|
-
[
|
|
4372
|
-
[
|
|
4751
|
+
[import_cluemart_shared35.EnumUserLicence.PRO_PLUS_EVENT]: 3,
|
|
4752
|
+
[import_cluemart_shared35.EnumUserLicence.PRO_EVENT]: 2,
|
|
4753
|
+
[import_cluemart_shared35.EnumUserLicence.STANDARD_EVENT]: 1,
|
|
4754
|
+
[import_cluemart_shared35.EnumUserLicence.PRO_PLUS_VENDOR]: 3,
|
|
4755
|
+
[import_cluemart_shared35.EnumUserLicence.PRO_VENDOR]: 2,
|
|
4756
|
+
[import_cluemart_shared35.EnumUserLicence.STANDARD_VENDOR]: 1,
|
|
4757
|
+
[import_cluemart_shared35.EnumUserLicence.STANDARD_PARTNER]: 1,
|
|
4758
|
+
[import_cluemart_shared35.EnumUserLicence.STANDARD_AFFILIATE]: 1,
|
|
4759
|
+
[import_cluemart_shared35.EnumUserLicence.STANDARD_SCHOOL]: 1
|
|
4373
4760
|
};
|
|
4374
4761
|
var standardLicences = [
|
|
4375
|
-
|
|
4376
|
-
|
|
4377
|
-
|
|
4762
|
+
import_cluemart_shared35.EnumUserLicence.STANDARD_VENDOR,
|
|
4763
|
+
import_cluemart_shared35.EnumUserLicence.STANDARD_EVENT,
|
|
4764
|
+
import_cluemart_shared35.EnumUserLicence.STANDARD_PARTNER
|
|
4378
4765
|
];
|
|
4379
4766
|
var standardLicenceSet = new Set(standardLicences);
|
|
4380
4767
|
function isStandardLicence(licence) {
|
|
4381
4768
|
return standardLicenceSet.has(licence);
|
|
4382
4769
|
}
|
|
4770
|
+
var proLicences = [
|
|
4771
|
+
import_cluemart_shared35.EnumUserLicence.PRO_EVENT,
|
|
4772
|
+
import_cluemart_shared35.EnumUserLicence.PRO_PLUS_EVENT,
|
|
4773
|
+
import_cluemart_shared35.EnumUserLicence.PRO_VENDOR,
|
|
4774
|
+
import_cluemart_shared35.EnumUserLicence.PRO_PLUS_VENDOR
|
|
4775
|
+
];
|
|
4776
|
+
var proLicenceSet = new Set(proLicences);
|
|
4777
|
+
function isProLicence(licence) {
|
|
4778
|
+
return proLicenceSet.has(licence);
|
|
4779
|
+
}
|
|
4383
4780
|
var categoryRegexMapping = {
|
|
4384
4781
|
["event" /* EVENT */]: /_event$/,
|
|
4385
4782
|
["partner" /* PARTNER */]: /_partner$/,
|
|
@@ -4388,11 +4785,11 @@ var categoryRegexMapping = {
|
|
|
4388
4785
|
["school" /* SCHOOL */]: /_school$/
|
|
4389
4786
|
};
|
|
4390
4787
|
var categoryFallbackLicence = {
|
|
4391
|
-
["event" /* EVENT */]:
|
|
4392
|
-
["partner" /* PARTNER */]:
|
|
4393
|
-
["vendor" /* VENDOR */]:
|
|
4394
|
-
["affiliate" /* AFFILIATE */]:
|
|
4395
|
-
["school" /* SCHOOL */]:
|
|
4788
|
+
["event" /* EVENT */]: import_cluemart_shared35.EnumUserLicence.STANDARD_EVENT,
|
|
4789
|
+
["partner" /* PARTNER */]: import_cluemart_shared35.EnumUserLicence.STANDARD_PARTNER,
|
|
4790
|
+
["vendor" /* VENDOR */]: import_cluemart_shared35.EnumUserLicence.STANDARD_VENDOR,
|
|
4791
|
+
["affiliate" /* AFFILIATE */]: import_cluemart_shared35.EnumUserLicence.STANDARD_AFFILIATE,
|
|
4792
|
+
["school" /* SCHOOL */]: import_cluemart_shared35.EnumUserLicence.STANDARD_SCHOOL
|
|
4396
4793
|
};
|
|
4397
4794
|
var LicenceFilterInput = {
|
|
4398
4795
|
INPUT_USER_LICENCES: "$licences"
|
|
@@ -4422,11 +4819,11 @@ function getHighestLicenceForCategory(licences, category) {
|
|
|
4422
4819
|
function createLicenceObject(expiryDate, licenceType) {
|
|
4423
4820
|
const today = (0, import_dayjs5.default)();
|
|
4424
4821
|
const expiryDateMapping = {
|
|
4425
|
-
[
|
|
4426
|
-
[
|
|
4427
|
-
[
|
|
4428
|
-
[
|
|
4429
|
-
[
|
|
4822
|
+
[import_cluemart_shared35.LicenceExpiryDate.ONE_YEAR]: today.add(1, "year").endOf("day").toDate(),
|
|
4823
|
+
[import_cluemart_shared35.LicenceExpiryDate.ONE_MONTH]: today.add(1, "month").endOf("day").toDate(),
|
|
4824
|
+
[import_cluemart_shared35.LicenceExpiryDate.TWO_MONTHS]: today.add(2, "month").endOf("day").toDate(),
|
|
4825
|
+
[import_cluemart_shared35.LicenceExpiryDate.THREE_MONTHS]: today.add(3, "month").endOf("day").toDate(),
|
|
4826
|
+
[import_cluemart_shared35.LicenceExpiryDate.SIX_MONTHS]: today.add(6, "month").endOf("day").toDate()
|
|
4430
4827
|
};
|
|
4431
4828
|
const licenceObject = {
|
|
4432
4829
|
expiryDate: expiryDateMapping[expiryDate],
|
|
@@ -4530,13 +4927,13 @@ async function checkOwnerHasLicence({
|
|
|
4530
4927
|
const owner = await UserModel.findById(userId);
|
|
4531
4928
|
if (!owner) throw new import_graphql.GraphQLError("Owner not found");
|
|
4532
4929
|
const categoryByResource = {
|
|
4533
|
-
[
|
|
4534
|
-
[
|
|
4535
|
-
[
|
|
4536
|
-
[
|
|
4537
|
-
[
|
|
4930
|
+
[import_cluemart_shared35.EnumResourceType.EVENT]: "event" /* EVENT */,
|
|
4931
|
+
[import_cluemart_shared35.EnumResourceType.PARTNER]: "partner" /* PARTNER */,
|
|
4932
|
+
[import_cluemart_shared35.EnumResourceType.VENDOR]: "vendor" /* VENDOR */,
|
|
4933
|
+
[import_cluemart_shared35.EnumResourceType.AFFILIATE]: "affiliate" /* AFFILIATE */,
|
|
4934
|
+
[import_cluemart_shared35.EnumResourceType.SCHOOL]: "school" /* SCHOOL */
|
|
4538
4935
|
};
|
|
4539
|
-
if (!(0,
|
|
4936
|
+
if (!(0, import_cluemart_shared35.isNonVisitorResourceType)(resourceType)) {
|
|
4540
4937
|
throw new import_graphql.GraphQLError(`Invalid resource type: ${resourceType}.`);
|
|
4541
4938
|
}
|
|
4542
4939
|
const requiredCategory = categoryByResource[resourceType];
|
|
@@ -4558,6 +4955,128 @@ async function checkOwnerHasLicence({
|
|
|
4558
4955
|
);
|
|
4559
4956
|
}
|
|
4560
4957
|
}
|
|
4958
|
+
var resourceLicenceCategory = {
|
|
4959
|
+
[import_cluemart_shared35.EnumResourceType.EVENT]: "event" /* EVENT */,
|
|
4960
|
+
[import_cluemart_shared35.EnumResourceType.PARTNER]: "partner" /* PARTNER */,
|
|
4961
|
+
[import_cluemart_shared35.EnumResourceType.VENDOR]: "vendor" /* VENDOR */
|
|
4962
|
+
};
|
|
4963
|
+
function isProtectedByCurrentStripeSubscription(user, licenceType, now) {
|
|
4964
|
+
const stripe = user.stripe;
|
|
4965
|
+
if (!stripe || stripe.currentPlan !== licenceType) {
|
|
4966
|
+
return false;
|
|
4967
|
+
}
|
|
4968
|
+
const gracePeriodEndsAt = stripe.paymentGracePeriodEndsAt ? (0, import_dayjs5.default)(stripe.paymentGracePeriodEndsAt) : null;
|
|
4969
|
+
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);
|
|
4970
|
+
if (hasActivePaymentGracePeriod) {
|
|
4971
|
+
return true;
|
|
4972
|
+
}
|
|
4973
|
+
if (!stripe.subscriptionId) {
|
|
4974
|
+
return false;
|
|
4975
|
+
}
|
|
4976
|
+
if (stripe.status !== import_cluemart_shared35.EnumSubscriptionStatus.ACTIVE) {
|
|
4977
|
+
return false;
|
|
4978
|
+
}
|
|
4979
|
+
if (!stripe.endDate) {
|
|
4980
|
+
return false;
|
|
4981
|
+
}
|
|
4982
|
+
const paidThrough = (0, import_dayjs5.default)(stripe.endDate);
|
|
4983
|
+
return paidThrough.isValid() && paidThrough.isAfter(now);
|
|
4984
|
+
}
|
|
4985
|
+
function effectiveLicences({
|
|
4986
|
+
includeStripeProtected = false,
|
|
4987
|
+
licences,
|
|
4988
|
+
now,
|
|
4989
|
+
owner
|
|
4990
|
+
}) {
|
|
4991
|
+
const nowDayjs = (0, import_dayjs5.default)(now);
|
|
4992
|
+
return (licences ?? []).filter((licence) => {
|
|
4993
|
+
if (!licence.licenceType || licence.expiryDate == null) {
|
|
4994
|
+
return false;
|
|
4995
|
+
}
|
|
4996
|
+
if (new Date(licence.expiryDate).getTime() > now.getTime()) {
|
|
4997
|
+
return true;
|
|
4998
|
+
}
|
|
4999
|
+
return Boolean(
|
|
5000
|
+
includeStripeProtected && owner && isProtectedByCurrentStripeSubscription(
|
|
5001
|
+
owner,
|
|
5002
|
+
licence.licenceType,
|
|
5003
|
+
nowDayjs
|
|
5004
|
+
)
|
|
5005
|
+
);
|
|
5006
|
+
});
|
|
5007
|
+
}
|
|
5008
|
+
async function getActiveLicenceForResource({
|
|
5009
|
+
includeStripeProtected = false,
|
|
5010
|
+
userId,
|
|
5011
|
+
resourceType,
|
|
5012
|
+
now = /* @__PURE__ */ new Date()
|
|
5013
|
+
}) {
|
|
5014
|
+
const category = resourceLicenceCategory[resourceType];
|
|
5015
|
+
if (!category) {
|
|
5016
|
+
return null;
|
|
5017
|
+
}
|
|
5018
|
+
const owner = await UserModel.findById(userId, {
|
|
5019
|
+
licences: 1,
|
|
5020
|
+
...includeStripeProtected ? { stripe: 1 } : {}
|
|
5021
|
+
}).lean();
|
|
5022
|
+
if (!owner?.licences?.length) {
|
|
5023
|
+
return null;
|
|
5024
|
+
}
|
|
5025
|
+
return getHighestLicenceForCategory(
|
|
5026
|
+
effectiveLicences({
|
|
5027
|
+
includeStripeProtected,
|
|
5028
|
+
licences: owner.licences,
|
|
5029
|
+
now,
|
|
5030
|
+
owner
|
|
5031
|
+
}),
|
|
5032
|
+
category
|
|
5033
|
+
);
|
|
5034
|
+
}
|
|
5035
|
+
async function getUserIdsWithActiveProLicence({
|
|
5036
|
+
includeStripeProtected = false,
|
|
5037
|
+
resourceType,
|
|
5038
|
+
userIds,
|
|
5039
|
+
now = /* @__PURE__ */ new Date()
|
|
5040
|
+
}) {
|
|
5041
|
+
const category = resourceLicenceCategory[resourceType];
|
|
5042
|
+
if (!category || userIds.length === 0) {
|
|
5043
|
+
return /* @__PURE__ */ new Set();
|
|
5044
|
+
}
|
|
5045
|
+
const owners = await UserModel.find(
|
|
5046
|
+
{ _id: { $in: userIds } },
|
|
5047
|
+
{ licences: 1, ...includeStripeProtected ? { stripe: 1 } : {} }
|
|
5048
|
+
).lean();
|
|
5049
|
+
const allowed = /* @__PURE__ */ new Set();
|
|
5050
|
+
for (const owner of owners ?? []) {
|
|
5051
|
+
const activeLicence = getHighestLicenceForCategory(
|
|
5052
|
+
effectiveLicences({
|
|
5053
|
+
includeStripeProtected,
|
|
5054
|
+
licences: owner.licences,
|
|
5055
|
+
now,
|
|
5056
|
+
owner
|
|
5057
|
+
}),
|
|
5058
|
+
category
|
|
5059
|
+
);
|
|
5060
|
+
if (activeLicence && isProLicence(activeLicence)) {
|
|
5061
|
+
allowed.add(String(owner._id));
|
|
5062
|
+
}
|
|
5063
|
+
}
|
|
5064
|
+
return allowed;
|
|
5065
|
+
}
|
|
5066
|
+
async function hasActiveProLicenceForResource({
|
|
5067
|
+
includeStripeProtected = false,
|
|
5068
|
+
userId,
|
|
5069
|
+
resourceType,
|
|
5070
|
+
now = /* @__PURE__ */ new Date()
|
|
5071
|
+
}) {
|
|
5072
|
+
const activeLicence = await getActiveLicenceForResource({
|
|
5073
|
+
includeStripeProtected,
|
|
5074
|
+
now,
|
|
5075
|
+
resourceType,
|
|
5076
|
+
userId
|
|
5077
|
+
});
|
|
5078
|
+
return activeLicence !== null && isProLicence(activeLicence);
|
|
5079
|
+
}
|
|
4561
5080
|
|
|
4562
5081
|
// src/service/license/compliance/vendor.ts
|
|
4563
5082
|
async function findUserVendor(userId, logLabel) {
|
|
@@ -4616,7 +5135,7 @@ async function applyVendorDowngrade(vendor, ownerUserId) {
|
|
|
4616
5135
|
return (result?.matchedCount ?? 0) > 0;
|
|
4617
5136
|
}
|
|
4618
5137
|
async function downgradeVendorProFeatures(userId, licenceType) {
|
|
4619
|
-
const isStandardVendor = licenceType ===
|
|
5138
|
+
const isStandardVendor = licenceType === import_cluemart_shared36.EnumUserLicence.STANDARD_VENDOR;
|
|
4620
5139
|
if (!isStandardVendor) {
|
|
4621
5140
|
return;
|
|
4622
5141
|
}
|
|
@@ -4663,7 +5182,7 @@ async function applyVendorRestore(vendor, ownerUserId) {
|
|
|
4663
5182
|
return (result?.matchedCount ?? 0) > 0;
|
|
4664
5183
|
}
|
|
4665
5184
|
async function restoreVendorProFeatures(userId, licenceType) {
|
|
4666
|
-
const isProVendor = licenceType ===
|
|
5185
|
+
const isProVendor = licenceType === import_cluemart_shared36.EnumUserLicence.PRO_VENDOR || licenceType === import_cluemart_shared36.EnumUserLicence.PRO_PLUS_VENDOR;
|
|
4667
5186
|
if (!isProVendor) {
|
|
4668
5187
|
return;
|
|
4669
5188
|
}
|
|
@@ -4678,28 +5197,6 @@ async function restoreVendorProFeatures(userId, licenceType) {
|
|
|
4678
5197
|
throw error;
|
|
4679
5198
|
}
|
|
4680
5199
|
}
|
|
4681
|
-
function isProtectedByCurrentStripeSubscription(user, licenceType, now) {
|
|
4682
|
-
const stripe = user.stripe;
|
|
4683
|
-
if (!stripe || stripe.currentPlan !== licenceType) {
|
|
4684
|
-
return false;
|
|
4685
|
-
}
|
|
4686
|
-
const gracePeriodEndsAt = stripe.paymentGracePeriodEndsAt ? (0, import_dayjs6.default)(stripe.paymentGracePeriodEndsAt) : null;
|
|
4687
|
-
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);
|
|
4688
|
-
if (hasActivePaymentGracePeriod) {
|
|
4689
|
-
return true;
|
|
4690
|
-
}
|
|
4691
|
-
if (!stripe.subscriptionId) {
|
|
4692
|
-
return false;
|
|
4693
|
-
}
|
|
4694
|
-
if (stripe.status !== import_cluemart_shared35.EnumSubscriptionStatus.ACTIVE) {
|
|
4695
|
-
return false;
|
|
4696
|
-
}
|
|
4697
|
-
if (!stripe.endDate) {
|
|
4698
|
-
return false;
|
|
4699
|
-
}
|
|
4700
|
-
const paidThrough = (0, import_dayjs6.default)(stripe.endDate);
|
|
4701
|
-
return paidThrough.isValid() && paidThrough.isAfter(now);
|
|
4702
|
-
}
|
|
4703
5200
|
async function handleVendorLicenceCompliance(user, now) {
|
|
4704
5201
|
if (!user.licences || !user.vendor) {
|
|
4705
5202
|
return;
|
|
@@ -4710,10 +5207,10 @@ async function handleVendorLicenceCompliance(user, now) {
|
|
|
4710
5207
|
if (vendorLicencesOfUser.length === 0) {
|
|
4711
5208
|
return;
|
|
4712
5209
|
}
|
|
4713
|
-
const
|
|
4714
|
-
(licence) => licence.licenceType !==
|
|
5210
|
+
const proLicences2 = vendorLicencesOfUser.filter(
|
|
5211
|
+
(licence) => licence.licenceType !== import_cluemart_shared36.EnumUserLicence.STANDARD_VENDOR
|
|
4715
5212
|
);
|
|
4716
|
-
const expiredProLicences =
|
|
5213
|
+
const expiredProLicences = proLicences2.filter(
|
|
4717
5214
|
(licence) => !(0, import_dayjs6.default)(licence.expiryDate).isAfter(now)
|
|
4718
5215
|
);
|
|
4719
5216
|
const stripeProtectedLicenceTypes = new Set(
|
|
@@ -4724,7 +5221,7 @@ async function handleVendorLicenceCompliance(user, now) {
|
|
|
4724
5221
|
const expiredProLicence = expiredProLicences.some(
|
|
4725
5222
|
(licence) => !stripeProtectedLicenceTypes.has(licence.licenceType)
|
|
4726
5223
|
);
|
|
4727
|
-
const hasValidProLicence = stripeProtectedLicenceTypes.size > 0 || hasValidLicence(
|
|
5224
|
+
const hasValidProLicence = stripeProtectedLicenceTypes.size > 0 || hasValidLicence(proLicences2, import_cluemart_shared36.vendorLicences, now);
|
|
4728
5225
|
const hasExpiredVendorLicence = vendorLicencesOfUser.some(
|
|
4729
5226
|
(licence) => !(0, import_dayjs6.default)(licence.expiryDate).isAfter(now) && !stripeProtectedLicenceTypes.has(licence.licenceType)
|
|
4730
5227
|
);
|
|
@@ -4740,7 +5237,7 @@ async function handleVendorLicenceCompliance(user, now) {
|
|
|
4740
5237
|
"owner.userId": user._id
|
|
4741
5238
|
}).lean().exec();
|
|
4742
5239
|
}
|
|
4743
|
-
const licencesToSync =
|
|
5240
|
+
const licencesToSync = import_cluemart_shared36.vendorLicences.filter(
|
|
4744
5241
|
(licenceType) => !stripeProtectedLicenceTypes.has(licenceType)
|
|
4745
5242
|
);
|
|
4746
5243
|
await syncUserLicencesAfterExpiry(user._id, licencesToSync, now, "downgrade");
|
|
@@ -4755,11 +5252,11 @@ async function handleVendorLicenceCompliance(user, now) {
|
|
|
4755
5252
|
data: {
|
|
4756
5253
|
resourceId: String(vendor._id),
|
|
4757
5254
|
resourceName: vendor.name,
|
|
4758
|
-
resourceType:
|
|
5255
|
+
resourceType: import_cluemart_shared36.EnumNotificationResourceType.DOWNGRADED_VENDOR
|
|
4759
5256
|
},
|
|
4760
5257
|
message: `Your Vendor licence has been downgraded due to licence expiration.`,
|
|
4761
5258
|
title: `Vendor Licence Downgraded`,
|
|
4762
|
-
type:
|
|
5259
|
+
type: import_cluemart_shared36.EnumNotificationType.SYSTEM,
|
|
4763
5260
|
userIds: [user._id]
|
|
4764
5261
|
};
|
|
4765
5262
|
await sendDeactivationNotification(payload, user._id, vendor.name, "vendor");
|
|
@@ -4773,26 +5270,11 @@ async function vendorOwnerHasProLicence(vendorId) {
|
|
|
4773
5270
|
if (!vendor) {
|
|
4774
5271
|
return false;
|
|
4775
5272
|
}
|
|
4776
|
-
|
|
4777
|
-
|
|
4778
|
-
|
|
4779
|
-
|
|
4780
|
-
|
|
4781
|
-
return false;
|
|
4782
|
-
}
|
|
4783
|
-
const now = (0, import_dayjs6.default)();
|
|
4784
|
-
const effectiveVendorLicences = owner.licences?.filter(
|
|
4785
|
-
(licence) => licence?.licenceType && ((0, import_dayjs6.default)(licence.expiryDate).isAfter(now) || isProtectedByCurrentStripeSubscription(
|
|
4786
|
-
owner,
|
|
4787
|
-
licence.licenceType,
|
|
4788
|
-
now
|
|
4789
|
-
))
|
|
4790
|
-
);
|
|
4791
|
-
const highestVendorLicence = getHighestLicenceForCategory(
|
|
4792
|
-
effectiveVendorLicences,
|
|
4793
|
-
"vendor" /* VENDOR */
|
|
4794
|
-
);
|
|
4795
|
-
return highestVendorLicence !== null && licencePriority[highestVendorLicence] >= licencePriority[import_cluemart_shared35.EnumUserLicence.PRO_VENDOR];
|
|
5273
|
+
return hasActiveProLicenceForResource({
|
|
5274
|
+
includeStripeProtected: true,
|
|
5275
|
+
resourceType: import_cluemart_shared36.EnumResourceType.VENDOR,
|
|
5276
|
+
userId: vendor.owner.userId
|
|
5277
|
+
});
|
|
4796
5278
|
}
|
|
4797
5279
|
|
|
4798
5280
|
// src/service/license/compliance/utils.ts
|
|
@@ -4802,12 +5284,12 @@ async function syncUserLicencesAfterExpiry(userId, licenceTypes, now, mode = "do
|
|
|
4802
5284
|
const pipeline = buildLicenceExpiryPipeline({
|
|
4803
5285
|
downgradeBranches: [
|
|
4804
5286
|
{
|
|
4805
|
-
case:
|
|
4806
|
-
then:
|
|
5287
|
+
case: import_cluemart_shared37.EnumUserLicence.PRO_PLUS_VENDOR,
|
|
5288
|
+
then: import_cluemart_shared37.EnumUserLicence.STANDARD_VENDOR
|
|
4807
5289
|
},
|
|
4808
5290
|
{
|
|
4809
|
-
case:
|
|
4810
|
-
then:
|
|
5291
|
+
case: import_cluemart_shared37.EnumUserLicence.PRO_VENDOR,
|
|
5292
|
+
then: import_cluemart_shared37.EnumUserLicence.STANDARD_VENDOR
|
|
4811
5293
|
}
|
|
4812
5294
|
],
|
|
4813
5295
|
licenceTypes,
|
|
@@ -4936,7 +5418,7 @@ var REMINDER_WINDOW_MIN_HOURS = 6.5 * 24;
|
|
|
4936
5418
|
var REMINDER_WINDOW_MAX_HOURS = 7.5 * 24;
|
|
4937
5419
|
|
|
4938
5420
|
// src/service/license/reminder/utils.ts
|
|
4939
|
-
var
|
|
5421
|
+
var import_cluemart_shared38 = require("@timardex/cluemart-shared");
|
|
4940
5422
|
var import_utils8 = require("@timardex/cluemart-shared/utils");
|
|
4941
5423
|
var import_dayjs9 = __toESM(require("dayjs"));
|
|
4942
5424
|
|
|
@@ -5002,28 +5484,28 @@ function isLicenseExpiringIn7Days(expiryDate, now) {
|
|
|
5002
5484
|
return hoursUntilExpiry >= REMINDER_WINDOW_MIN_HOURS && hoursUntilExpiry <= REMINDER_WINDOW_MAX_HOURS;
|
|
5003
5485
|
}
|
|
5004
5486
|
function getLicenseName(licenceType) {
|
|
5005
|
-
return
|
|
5487
|
+
return import_cluemart_shared38.licenseNiceNames[licenceType] || licenceType;
|
|
5006
5488
|
}
|
|
5007
5489
|
function getNotificationTypes(isVendorLicense, isPartnerLicense) {
|
|
5008
5490
|
if (isVendorLicense) {
|
|
5009
5491
|
return {
|
|
5010
|
-
notificationType:
|
|
5011
|
-
resourceType:
|
|
5492
|
+
notificationType: import_cluemart_shared38.EnumNotificationType.SYSTEM,
|
|
5493
|
+
resourceType: import_cluemart_shared38.EnumNotificationResourceType.EXPIRATION_REMINDER_VENDOR
|
|
5012
5494
|
};
|
|
5013
5495
|
}
|
|
5014
5496
|
if (isPartnerLicense) {
|
|
5015
5497
|
return {
|
|
5016
|
-
notificationType:
|
|
5017
|
-
resourceType:
|
|
5498
|
+
notificationType: import_cluemart_shared38.EnumNotificationType.SYSTEM,
|
|
5499
|
+
resourceType: import_cluemart_shared38.EnumNotificationResourceType.EXPIRATION_REMINDER_PARTNER
|
|
5018
5500
|
};
|
|
5019
5501
|
}
|
|
5020
5502
|
return {
|
|
5021
|
-
notificationType:
|
|
5022
|
-
resourceType:
|
|
5503
|
+
notificationType: import_cluemart_shared38.EnumNotificationType.SYSTEM,
|
|
5504
|
+
resourceType: import_cluemart_shared38.EnumNotificationResourceType.EXPIRATION_REMINDER_EVENT
|
|
5023
5505
|
};
|
|
5024
5506
|
}
|
|
5025
5507
|
async function getLicenseResourceInfo(user, licence) {
|
|
5026
|
-
const isVendorLicense =
|
|
5508
|
+
const isVendorLicense = import_cluemart_shared38.vendorLicences.includes(licence.licenceType);
|
|
5027
5509
|
const isPartnerLicense = partnerLicences.includes(licence.licenceType);
|
|
5028
5510
|
const licenceName = getLicenseName(licence.licenceType);
|
|
5029
5511
|
const { notificationType, resourceType } = getNotificationTypes(
|
|
@@ -5071,11 +5553,11 @@ async function getLicenseResourceInfo(user, licence) {
|
|
|
5071
5553
|
};
|
|
5072
5554
|
}
|
|
5073
5555
|
function getLicenceExpiryMode(licenceType) {
|
|
5074
|
-
return licenceType ===
|
|
5556
|
+
return licenceType === import_cluemart_shared38.EnumUserLicence.PRO_VENDOR || licenceType === import_cluemart_shared38.EnumUserLicence.PRO_PLUS_VENDOR ? "downgrade" : "extend";
|
|
5075
5557
|
}
|
|
5076
5558
|
async function sendLicenseReminder(user, licence) {
|
|
5077
5559
|
const licenceName = getLicenseName(licence.licenceType);
|
|
5078
|
-
const expiryDate = (0, import_dayjs9.default)(licence.expiryDate).format(
|
|
5560
|
+
const expiryDate = (0, import_dayjs9.default)(licence.expiryDate).format(import_cluemart_shared38.dateFormat);
|
|
5079
5561
|
const userId = String(user._id);
|
|
5080
5562
|
const resourceInfo = await getLicenseResourceInfo(user, licence);
|
|
5081
5563
|
if (!resourceInfo) {
|
|
@@ -5214,6 +5696,7 @@ async function remindUsersAboutLicenseExpiration() {
|
|
|
5214
5696
|
AiImportRunModel,
|
|
5215
5697
|
AiImportedMarketModel,
|
|
5216
5698
|
AppSettingModel,
|
|
5699
|
+
AssociateTypeSchema,
|
|
5217
5700
|
AuthHandoffTokenModel,
|
|
5218
5701
|
BILLING_CATALOG_COLLECTION_NAME,
|
|
5219
5702
|
BillingCatalogModel,
|
|
@@ -5253,6 +5736,7 @@ async function remindUsersAboutLicenseExpiration() {
|
|
|
5253
5736
|
VendorInfoModel,
|
|
5254
5737
|
VendorModel,
|
|
5255
5738
|
VerificationTokenModel,
|
|
5739
|
+
acceptedAssociateUserIds,
|
|
5256
5740
|
activeAffiliateCodeExists,
|
|
5257
5741
|
awardAffiliateVendorSubscriptionRewards,
|
|
5258
5742
|
baseResourceFields,
|
|
@@ -5269,6 +5753,9 @@ async function remindUsersAboutLicenseExpiration() {
|
|
|
5269
5753
|
createLicenceObject,
|
|
5270
5754
|
dateTimeSchema,
|
|
5271
5755
|
dedupeArchivedSlotsByStartDateTime,
|
|
5756
|
+
detachAssociateGrantsForResources,
|
|
5757
|
+
detachStaleAssociateGrants,
|
|
5758
|
+
detachUsersFromResource,
|
|
5272
5759
|
didRemoveAnyEventDates,
|
|
5273
5760
|
didRemoveAnyStartedDates,
|
|
5274
5761
|
downgradeVendorProFeatures,
|
|
@@ -5279,6 +5766,8 @@ async function remindUsersAboutLicenseExpiration() {
|
|
|
5279
5766
|
express,
|
|
5280
5767
|
findAffiliateByPromoCode,
|
|
5281
5768
|
findEventOrImportedMarketById,
|
|
5769
|
+
getActiveLicenceForResource,
|
|
5770
|
+
getAssociateAccessMeta,
|
|
5282
5771
|
getBillingCatalogDefinition,
|
|
5283
5772
|
getEventResourceInfo,
|
|
5284
5773
|
getHighestLicenceForCategory,
|
|
@@ -5289,11 +5778,17 @@ async function remindUsersAboutLicenseExpiration() {
|
|
|
5289
5778
|
getPayingStripeSubscriptionPlan,
|
|
5290
5779
|
getPayingVendorStripeSubscriptionPlan,
|
|
5291
5780
|
getSubscriptionRewardPeriodBounds,
|
|
5781
|
+
getUserIdsWithActiveProLicence,
|
|
5292
5782
|
getVendorResourceInfo,
|
|
5783
|
+
grantAssociateGrants,
|
|
5293
5784
|
handleEventLicenceCompliance,
|
|
5294
5785
|
handlePartnerLicenceCompliance,
|
|
5295
5786
|
handleVendorLicenceCompliance,
|
|
5787
|
+
hasActiveProLicenceForResource,
|
|
5296
5788
|
hasValidLicence,
|
|
5789
|
+
isAssociableResourceType,
|
|
5790
|
+
isProLicence,
|
|
5791
|
+
isProtectedByCurrentStripeSubscription,
|
|
5297
5792
|
isStandardLicence,
|
|
5298
5793
|
isValidObjectId,
|
|
5299
5794
|
licenceCategoryMapping,
|
|
@@ -5311,6 +5806,7 @@ async function remindUsersAboutLicenseExpiration() {
|
|
|
5311
5806
|
processUserCompliance,
|
|
5312
5807
|
processUserLicenseReminders,
|
|
5313
5808
|
publishNotificationEvents,
|
|
5809
|
+
reconcileAssociateGrants,
|
|
5314
5810
|
refundPolicySchema,
|
|
5315
5811
|
relatedPostSchema,
|
|
5316
5812
|
relationDatesSchema,
|