@timardex/cluemart-server-shared 2.2.21 → 2.2.23
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/index.cjs +76 -30
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.mts +14 -1
- package/dist/index.d.ts +14 -1
- package/dist/index.mjs +82 -32
- package/dist/index.mjs.map +1 -1
- package/dist/service/index.cjs +76 -30
- package/dist/service/index.cjs.map +1 -1
- package/dist/service/index.d.mts +14 -1
- package/dist/service/index.d.ts +14 -1
- package/dist/service/index.mjs +82 -32
- package/dist/service/index.mjs.map +1 -1
- package/package.json +2 -2
package/dist/index.cjs
CHANGED
|
@@ -89,6 +89,7 @@ __export(index_exports, {
|
|
|
89
89
|
dateTimeSchema: () => dateTimeSchema,
|
|
90
90
|
dedupeArchivedSlotsByStartDateTime: () => dedupeArchivedSlotsByStartDateTime,
|
|
91
91
|
didRemoveAnyEventDates: () => didRemoveAnyEventDates,
|
|
92
|
+
didRemoveAnyStartedDates: () => didRemoveAnyStartedDates,
|
|
92
93
|
downgradeVendorProFeatures: () => downgradeVendorProFeatures,
|
|
93
94
|
ensureUserLicenseCompliance: () => ensureUserLicenseCompliance,
|
|
94
95
|
ensureUserLicenseComplianceForUser: () => ensureUserLicenseComplianceForUser,
|
|
@@ -3253,10 +3254,13 @@ function convertObjectIdsToStrings(obj) {
|
|
|
3253
3254
|
|
|
3254
3255
|
// src/service/event/updateAllEventDateTimeStatuses.ts
|
|
3255
3256
|
var import_cluemart_shared27 = require("@timardex/cluemart-shared");
|
|
3256
|
-
var
|
|
3257
|
+
var import_dayjs3 = __toESM(require("dayjs"));
|
|
3257
3258
|
|
|
3258
3259
|
// src/service/event/archiveEndedEventDates.ts
|
|
3259
3260
|
var import_cluemart_shared26 = require("@timardex/cluemart-shared");
|
|
3261
|
+
var import_dayjs2 = __toESM(require("dayjs"));
|
|
3262
|
+
var import_customParseFormat = __toESM(require("dayjs/plugin/customParseFormat"));
|
|
3263
|
+
import_dayjs2.default.extend(import_customParseFormat.default);
|
|
3260
3264
|
var ARCHIVED_STATUSES = /* @__PURE__ */ new Set([
|
|
3261
3265
|
import_cluemart_shared26.EnumEventDateStatus.ENDED
|
|
3262
3266
|
]);
|
|
@@ -3283,6 +3287,17 @@ function dedupeArchivedSlotsByStartDateTime(slots) {
|
|
|
3283
3287
|
return true;
|
|
3284
3288
|
});
|
|
3285
3289
|
}
|
|
3290
|
+
function isPastCanceledEventDate(slot, now) {
|
|
3291
|
+
if (slot.dateStatus !== import_cluemart_shared26.EnumEventDateStatus.CANCELED) {
|
|
3292
|
+
return false;
|
|
3293
|
+
}
|
|
3294
|
+
const endDateTime = (0, import_dayjs2.default)(
|
|
3295
|
+
`${slot.endDate} ${slot.endTime}`,
|
|
3296
|
+
`${import_cluemart_shared26.dateFormat} ${import_cluemart_shared26.timeFormat}`,
|
|
3297
|
+
true
|
|
3298
|
+
);
|
|
3299
|
+
return endDateTime.isValid() && endDateTime.isBefore(now);
|
|
3300
|
+
}
|
|
3286
3301
|
async function persistArchivedEventDates(eventId, slots) {
|
|
3287
3302
|
if (slots.length === 0) {
|
|
3288
3303
|
return;
|
|
@@ -3347,7 +3362,11 @@ async function updateModelDateTimeStatuses(model, now) {
|
|
|
3347
3362
|
}
|
|
3348
3363
|
var ARCHIVABLE_EVENT_FILTER = {
|
|
3349
3364
|
"dateTime.dateStatus": {
|
|
3350
|
-
$in: [
|
|
3365
|
+
$in: [
|
|
3366
|
+
import_cluemart_shared27.EnumEventDateStatus.ENDED,
|
|
3367
|
+
import_cluemart_shared27.EnumEventDateStatus.INVALID,
|
|
3368
|
+
import_cluemart_shared27.EnumEventDateStatus.CANCELED
|
|
3369
|
+
]
|
|
3351
3370
|
},
|
|
3352
3371
|
deletedAt: null
|
|
3353
3372
|
};
|
|
@@ -3362,7 +3381,9 @@ async function archiveEndedAndDiscardInvalidEventDates(now) {
|
|
|
3362
3381
|
archiveOps = [];
|
|
3363
3382
|
}
|
|
3364
3383
|
if (eventOps.length) {
|
|
3365
|
-
await EventModel.bulkWrite(
|
|
3384
|
+
await EventModel.bulkWrite(
|
|
3385
|
+
eventOps
|
|
3386
|
+
);
|
|
3366
3387
|
eventOps = [];
|
|
3367
3388
|
}
|
|
3368
3389
|
};
|
|
@@ -3372,7 +3393,10 @@ async function archiveEndedAndDiscardInvalidEventDates(now) {
|
|
|
3372
3393
|
(slot) => (0, import_cluemart_shared27.updateSingleDateTimeStatus)(slot, now)
|
|
3373
3394
|
);
|
|
3374
3395
|
const { archive, discard } = splitEventDatesForArchive(updated);
|
|
3375
|
-
|
|
3396
|
+
const pastCanceled = updated.filter(
|
|
3397
|
+
(slot) => isPastCanceledEventDate(slot, now)
|
|
3398
|
+
);
|
|
3399
|
+
if (archive.length === 0 && discard.length === 0 && pastCanceled.length === 0) {
|
|
3376
3400
|
continue;
|
|
3377
3401
|
}
|
|
3378
3402
|
if (archive.length > 0) {
|
|
@@ -3386,16 +3410,27 @@ async function archiveEndedAndDiscardInvalidEventDates(now) {
|
|
|
3386
3410
|
});
|
|
3387
3411
|
archivedCount += uniqueArchive.length;
|
|
3388
3412
|
}
|
|
3413
|
+
const pullConditions = [];
|
|
3414
|
+
if (archive.length > 0 || discard.length > 0) {
|
|
3415
|
+
pullConditions.push({
|
|
3416
|
+
dateStatus: {
|
|
3417
|
+
$in: [import_cluemart_shared27.EnumEventDateStatus.ENDED, import_cluemart_shared27.EnumEventDateStatus.INVALID]
|
|
3418
|
+
}
|
|
3419
|
+
});
|
|
3420
|
+
}
|
|
3421
|
+
for (const slot of pastCanceled) {
|
|
3422
|
+
pullConditions.push({
|
|
3423
|
+
dateStatus: import_cluemart_shared27.EnumEventDateStatus.CANCELED,
|
|
3424
|
+
startDate: slot.startDate,
|
|
3425
|
+
startTime: slot.startTime
|
|
3426
|
+
});
|
|
3427
|
+
}
|
|
3389
3428
|
eventOps.push({
|
|
3390
3429
|
updateOne: {
|
|
3391
3430
|
filter: { _id: doc._id },
|
|
3392
3431
|
update: {
|
|
3393
3432
|
$pull: {
|
|
3394
|
-
dateTime: {
|
|
3395
|
-
dateStatus: {
|
|
3396
|
-
$in: [import_cluemart_shared27.EnumEventDateStatus.ENDED, import_cluemart_shared27.EnumEventDateStatus.INVALID]
|
|
3397
|
-
}
|
|
3398
|
-
}
|
|
3433
|
+
dateTime: { $or: pullConditions }
|
|
3399
3434
|
}
|
|
3400
3435
|
}
|
|
3401
3436
|
}
|
|
@@ -3451,7 +3486,7 @@ async function cleanEventInfoDates(now) {
|
|
|
3451
3486
|
return removedCount;
|
|
3452
3487
|
}
|
|
3453
3488
|
async function updateAllEventDateTimeStatuses() {
|
|
3454
|
-
const now = (0,
|
|
3489
|
+
const now = (0, import_dayjs3.default)();
|
|
3455
3490
|
const [eventCount, marketCount] = await Promise.all([
|
|
3456
3491
|
updateModelDateTimeStatuses(EventModel, now),
|
|
3457
3492
|
updateModelDateTimeStatuses(
|
|
@@ -3502,6 +3537,16 @@ function didRemoveAnyEventDates(previousDateTime, nextDateTime) {
|
|
|
3502
3537
|
)
|
|
3503
3538
|
);
|
|
3504
3539
|
}
|
|
3540
|
+
function didRemoveAnyStartedDates(previousDateTime, nextDateTime) {
|
|
3541
|
+
if (!previousDateTime?.length) {
|
|
3542
|
+
return false;
|
|
3543
|
+
}
|
|
3544
|
+
return previousDateTime.some(
|
|
3545
|
+
(prev) => prev.dateStatus === import_cluemart_shared28.EnumEventDateStatus.STARTED && !nextDateTime?.some(
|
|
3546
|
+
(next) => next.startDate === prev.startDate && next.startTime === prev.startTime && next.dateStatus === import_cluemart_shared28.EnumEventDateStatus.STARTED
|
|
3547
|
+
)
|
|
3548
|
+
);
|
|
3549
|
+
}
|
|
3505
3550
|
function updateRelationDatesToUnavailable(relationDates, eventDateTime) {
|
|
3506
3551
|
return relationDates.map((relationDate) => {
|
|
3507
3552
|
const existsInEvent = eventDateTime?.some(
|
|
@@ -3515,11 +3560,11 @@ function updateRelationDatesToUnavailable(relationDates, eventDateTime) {
|
|
|
3515
3560
|
}
|
|
3516
3561
|
|
|
3517
3562
|
// src/service/license/compliance/ensureUserLicenseCompliance.ts
|
|
3518
|
-
var
|
|
3563
|
+
var import_dayjs7 = __toESM(require("dayjs"));
|
|
3519
3564
|
|
|
3520
3565
|
// src/service/license/compliance/utils.ts
|
|
3521
3566
|
var import_cluemart_shared33 = require("@timardex/cluemart-shared");
|
|
3522
|
-
var
|
|
3567
|
+
var import_dayjs6 = __toESM(require("dayjs"));
|
|
3523
3568
|
|
|
3524
3569
|
// src/service/license/compliance/event.ts
|
|
3525
3570
|
var import_cluemart_shared29 = require("@timardex/cluemart-shared");
|
|
@@ -3751,11 +3796,11 @@ async function handlePartnerLicenceCompliance(user, now) {
|
|
|
3751
3796
|
|
|
3752
3797
|
// src/service/license/compliance/vendor.ts
|
|
3753
3798
|
var import_cluemart_shared32 = require("@timardex/cluemart-shared");
|
|
3754
|
-
var
|
|
3799
|
+
var import_dayjs5 = __toESM(require("dayjs"));
|
|
3755
3800
|
|
|
3756
3801
|
// src/service/license/models.ts
|
|
3757
3802
|
var import_cluemart_shared31 = require("@timardex/cluemart-shared");
|
|
3758
|
-
var
|
|
3803
|
+
var import_dayjs4 = __toESM(require("dayjs"));
|
|
3759
3804
|
var import_graphql = require("graphql");
|
|
3760
3805
|
var LicenceCategory = /* @__PURE__ */ ((LicenceCategory2) => {
|
|
3761
3806
|
LicenceCategory2["EVENT"] = "event";
|
|
@@ -3836,7 +3881,7 @@ function getHighestLicenceForCategory(licences, category) {
|
|
|
3836
3881
|
return highestLicence;
|
|
3837
3882
|
}
|
|
3838
3883
|
function createLicenceObject(expiryDate, licenceType) {
|
|
3839
|
-
const today = (0,
|
|
3884
|
+
const today = (0, import_dayjs4.default)();
|
|
3840
3885
|
const expiryDateMapping = {
|
|
3841
3886
|
[import_cluemart_shared31.LicenceExpiryDate.ONE_YEAR]: today.add(1, "year").endOf("day").toDate(),
|
|
3842
3887
|
[import_cluemart_shared31.LicenceExpiryDate.ONE_MONTH]: today.add(1, "month").endOf("day").toDate(),
|
|
@@ -4099,7 +4144,7 @@ function isProtectedByCurrentStripeSubscription(user, licenceType, now) {
|
|
|
4099
4144
|
if (!stripe || stripe.currentPlan !== licenceType) {
|
|
4100
4145
|
return false;
|
|
4101
4146
|
}
|
|
4102
|
-
const gracePeriodEndsAt = stripe.paymentGracePeriodEndsAt ? (0,
|
|
4147
|
+
const gracePeriodEndsAt = stripe.paymentGracePeriodEndsAt ? (0, import_dayjs5.default)(stripe.paymentGracePeriodEndsAt) : null;
|
|
4103
4148
|
const hasActivePaymentGracePeriod = (stripe.status === import_cluemart_shared32.EnumSubscriptionStatus.PAST_DUE || stripe.status === import_cluemart_shared32.EnumSubscriptionStatus.INACTIVE) && Boolean(stripe.paymentGraceSubscriptionId) && (!stripe.subscriptionId || stripe.subscriptionId === stripe.paymentGraceSubscriptionId) && gracePeriodEndsAt !== null && gracePeriodEndsAt.isValid() && gracePeriodEndsAt.isAfter(now);
|
|
4104
4149
|
if (hasActivePaymentGracePeriod) {
|
|
4105
4150
|
return true;
|
|
@@ -4113,7 +4158,7 @@ function isProtectedByCurrentStripeSubscription(user, licenceType, now) {
|
|
|
4113
4158
|
if (!stripe.endDate) {
|
|
4114
4159
|
return false;
|
|
4115
4160
|
}
|
|
4116
|
-
const paidThrough = (0,
|
|
4161
|
+
const paidThrough = (0, import_dayjs5.default)(stripe.endDate);
|
|
4117
4162
|
return paidThrough.isValid() && paidThrough.isAfter(now);
|
|
4118
4163
|
}
|
|
4119
4164
|
async function handleVendorLicenceCompliance(user, now) {
|
|
@@ -4130,7 +4175,7 @@ async function handleVendorLicenceCompliance(user, now) {
|
|
|
4130
4175
|
(licence) => licence.licenceType !== import_cluemart_shared32.EnumUserLicence.STANDARD_VENDOR
|
|
4131
4176
|
);
|
|
4132
4177
|
const expiredProLicences = proLicences.filter(
|
|
4133
|
-
(licence) => !(0,
|
|
4178
|
+
(licence) => !(0, import_dayjs5.default)(licence.expiryDate).isAfter(now)
|
|
4134
4179
|
);
|
|
4135
4180
|
const stripeProtectedLicenceTypes = new Set(
|
|
4136
4181
|
expiredProLicences.filter(
|
|
@@ -4142,7 +4187,7 @@ async function handleVendorLicenceCompliance(user, now) {
|
|
|
4142
4187
|
);
|
|
4143
4188
|
const hasValidProLicence = stripeProtectedLicenceTypes.size > 0 || hasValidLicence(proLicences, import_cluemart_shared32.vendorLicences, now);
|
|
4144
4189
|
const hasExpiredVendorLicence = vendorLicencesOfUser.some(
|
|
4145
|
-
(licence) => !(0,
|
|
4190
|
+
(licence) => !(0, import_dayjs5.default)(licence.expiryDate).isAfter(now) && !stripeProtectedLicenceTypes.has(licence.licenceType)
|
|
4146
4191
|
);
|
|
4147
4192
|
if (!hasExpiredVendorLicence) {
|
|
4148
4193
|
return;
|
|
@@ -4196,9 +4241,9 @@ async function vendorOwnerHasProLicence(vendorId) {
|
|
|
4196
4241
|
if (!owner) {
|
|
4197
4242
|
return false;
|
|
4198
4243
|
}
|
|
4199
|
-
const now = (0,
|
|
4244
|
+
const now = (0, import_dayjs5.default)();
|
|
4200
4245
|
const effectiveVendorLicences = owner.licences?.filter(
|
|
4201
|
-
(licence) => licence?.licenceType && ((0,
|
|
4246
|
+
(licence) => licence?.licenceType && ((0, import_dayjs5.default)(licence.expiryDate).isAfter(now) || isProtectedByCurrentStripeSubscription(
|
|
4202
4247
|
owner,
|
|
4203
4248
|
licence.licenceType,
|
|
4204
4249
|
now
|
|
@@ -4235,7 +4280,7 @@ async function syncUserLicencesAfterExpiry(userId, licenceTypes, now, mode = "do
|
|
|
4235
4280
|
}
|
|
4236
4281
|
function hasValidLicence(licences, licenceTypes, now) {
|
|
4237
4282
|
return licences.some(
|
|
4238
|
-
(licence) => licenceTypes.includes(licence.licenceType) && (0,
|
|
4283
|
+
(licence) => licenceTypes.includes(licence.licenceType) && (0, import_dayjs6.default)(licence.expiryDate).isAfter(now)
|
|
4239
4284
|
);
|
|
4240
4285
|
}
|
|
4241
4286
|
async function sendDeactivationNotification(payload, userId, resourceName, resourceType) {
|
|
@@ -4262,7 +4307,7 @@ async function processUserCompliance(user, now) {
|
|
|
4262
4307
|
}
|
|
4263
4308
|
|
|
4264
4309
|
// src/service/license/compliance/ensureUserLicenseCompliance.ts
|
|
4265
|
-
async function ensureUserLicenseComplianceForUser(userId, now = (0,
|
|
4310
|
+
async function ensureUserLicenseComplianceForUser(userId, now = (0, import_dayjs7.default)()) {
|
|
4266
4311
|
const user = await UserModel.findById(userId);
|
|
4267
4312
|
if (!user) {
|
|
4268
4313
|
return;
|
|
@@ -4270,7 +4315,7 @@ async function ensureUserLicenseComplianceForUser(userId, now = (0, import_dayjs
|
|
|
4270
4315
|
await processUserCompliance(user, now);
|
|
4271
4316
|
}
|
|
4272
4317
|
async function ensureUserLicenseCompliance() {
|
|
4273
|
-
const now = (0,
|
|
4318
|
+
const now = (0, import_dayjs7.default)();
|
|
4274
4319
|
console.log(`\u{1F50D} Checking license compliance at ${now.format()}`);
|
|
4275
4320
|
const nowDate = now.toDate();
|
|
4276
4321
|
const users = await UserModel.find({
|
|
@@ -4345,7 +4390,7 @@ async function getPartnerResourceInfo(userId, partnerId) {
|
|
|
4345
4390
|
}
|
|
4346
4391
|
|
|
4347
4392
|
// src/service/license/reminder/remindUsersAboutLicenseExpiration.ts
|
|
4348
|
-
var
|
|
4393
|
+
var import_dayjs9 = __toESM(require("dayjs"));
|
|
4349
4394
|
|
|
4350
4395
|
// src/service/license/reminder/reminderWindow.ts
|
|
4351
4396
|
var REMINDER_WINDOW_MIN_HOURS = 6.5 * 24;
|
|
@@ -4354,7 +4399,7 @@ var REMINDER_WINDOW_MAX_HOURS = 7.5 * 24;
|
|
|
4354
4399
|
// src/service/license/reminder/utils.ts
|
|
4355
4400
|
var import_cluemart_shared34 = require("@timardex/cluemart-shared");
|
|
4356
4401
|
var import_utils8 = require("@timardex/cluemart-shared/utils");
|
|
4357
|
-
var
|
|
4402
|
+
var import_dayjs8 = __toESM(require("dayjs"));
|
|
4358
4403
|
|
|
4359
4404
|
// src/service/license/reminder/vendor.ts
|
|
4360
4405
|
async function getVendorResourceInfo(userId, vendorId) {
|
|
@@ -4413,7 +4458,7 @@ async function checkAndCreateNotification(payload) {
|
|
|
4413
4458
|
}
|
|
4414
4459
|
}
|
|
4415
4460
|
function isLicenseExpiringIn7Days(expiryDate, now) {
|
|
4416
|
-
const expiry = (0,
|
|
4461
|
+
const expiry = (0, import_dayjs8.default)(expiryDate);
|
|
4417
4462
|
const hoursUntilExpiry = expiry.diff(now, "hour", true);
|
|
4418
4463
|
return hoursUntilExpiry >= REMINDER_WINDOW_MIN_HOURS && hoursUntilExpiry <= REMINDER_WINDOW_MAX_HOURS;
|
|
4419
4464
|
}
|
|
@@ -4491,7 +4536,7 @@ function getLicenceExpiryMode(licenceType) {
|
|
|
4491
4536
|
}
|
|
4492
4537
|
async function sendLicenseReminder(user, licence) {
|
|
4493
4538
|
const licenceName = getLicenseName(licence.licenceType);
|
|
4494
|
-
const expiryDate = (0,
|
|
4539
|
+
const expiryDate = (0, import_dayjs8.default)(licence.expiryDate).format(import_cluemart_shared34.dateFormat);
|
|
4495
4540
|
const userId = String(user._id);
|
|
4496
4541
|
const resourceInfo = await getLicenseResourceInfo(user, licence);
|
|
4497
4542
|
if (!resourceInfo) {
|
|
@@ -4523,7 +4568,7 @@ async function sendLicenseReminder(user, licence) {
|
|
|
4523
4568
|
console.log(`\u2705 Sent 7-day reminder to user ${userId} for ${licenceName}`);
|
|
4524
4569
|
}
|
|
4525
4570
|
async function processLicenseReminder(licence, now) {
|
|
4526
|
-
if ((0,
|
|
4571
|
+
if ((0, import_dayjs8.default)(licence.expiryDate).isBefore(now)) {
|
|
4527
4572
|
return false;
|
|
4528
4573
|
}
|
|
4529
4574
|
if (!isLicenseExpiringIn7Days(licence.expiryDate, now)) {
|
|
@@ -4577,7 +4622,7 @@ async function processUserLicenseReminders(user, now) {
|
|
|
4577
4622
|
|
|
4578
4623
|
// src/service/license/reminder/remindUsersAboutLicenseExpiration.ts
|
|
4579
4624
|
async function remindUsersAboutLicenseExpiration() {
|
|
4580
|
-
const now = (0,
|
|
4625
|
+
const now = (0, import_dayjs9.default)();
|
|
4581
4626
|
console.log(`\u{1F50D} Checking for licenses expiring in 7 days at ${now.format()}`);
|
|
4582
4627
|
const minExpiryDate = now.add(REMINDER_WINDOW_MIN_HOURS, "hour").toDate();
|
|
4583
4628
|
const maxExpiryDate = now.add(REMINDER_WINDOW_MAX_HOURS, "hour").toDate();
|
|
@@ -4675,6 +4720,7 @@ async function remindUsersAboutLicenseExpiration() {
|
|
|
4675
4720
|
dateTimeSchema,
|
|
4676
4721
|
dedupeArchivedSlotsByStartDateTime,
|
|
4677
4722
|
didRemoveAnyEventDates,
|
|
4723
|
+
didRemoveAnyStartedDates,
|
|
4678
4724
|
downgradeVendorProFeatures,
|
|
4679
4725
|
ensureUserLicenseCompliance,
|
|
4680
4726
|
ensureUserLicenseComplianceForUser,
|