@timardex/cluemart-server-shared 2.2.22 → 2.2.30
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-6AEy-gNx.d.mts → Affiliate-DIAzxxfs.d.mts} +2 -2
- package/dist/{Affiliate-D40kRxO_.d.ts → Affiliate-zioeZDyH.d.ts} +2 -2
- package/dist/{chunk-TIGQ6F5T.mjs → chunk-XGBC5DCX.mjs} +24 -3
- package/dist/chunk-XGBC5DCX.mjs.map +1 -0
- package/dist/index.cjs +243 -27
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.mts +104 -4
- package/dist/index.d.ts +104 -4
- package/dist/index.mjs +239 -27
- package/dist/index.mjs.map +1 -1
- package/dist/mongoose/index.cjs +22 -2
- package/dist/mongoose/index.cjs.map +1 -1
- package/dist/mongoose/index.d.mts +2 -2
- package/dist/mongoose/index.d.ts +2 -2
- package/dist/mongoose/index.mjs +1 -1
- package/dist/service/index.cjs +243 -27
- package/dist/service/index.cjs.map +1 -1
- package/dist/service/index.d.mts +103 -3
- package/dist/service/index.d.ts +103 -3
- package/dist/service/index.mjs +217 -26
- package/dist/service/index.mjs.map +1 -1
- package/package.json +2 -2
- package/dist/chunk-TIGQ6F5T.mjs.map +0 -1
|
@@ -3,8 +3,8 @@ import { AdType, AdDailyPriceType, AdBookingType, EnumAdShowOn, AdSettingsType,
|
|
|
3
3
|
import mongoose__default from 'mongoose';
|
|
4
4
|
import { O as ObjectId } from '../index-CmtBYjpi.mjs';
|
|
5
5
|
export { C as ChatModel, N as NotificationModel, S as SchemaChatMessageReactionType, a as SchemaChatMessageReplyPreviewType, b as SchemaChatMessageSeenType, c as SchemaChatMessageType, d as SchemaChatType, e as SchemaCreateBulkNotificationInput, f as SchemaNotificationType, g as SchemaParticipantType } from '../index-CmtBYjpi.mjs';
|
|
6
|
-
import { S as SchemaOwnerType } from '../Affiliate-
|
|
7
|
-
export { A as AffiliateModel, C as CategorySchema, a as ContactDetailsSchema, O as OwnerTypeSchema, R as RelationModel, b as RelationTypeSchema, c as ResourceImageTypeSchema, d as SchemaAffiliateResourceType, e as SchemaAffiliateReward, f as SchemaRelatedPostType, g as SchemaRelationType, h as SchemaStripeSubscription, i as SchemaUserActivityEvent, j as SchemaUserType, k as SocialMediaTypeSchema, U as UserModel, l as baseResourceFields, m as dateTimeSchema, n as locationGeoSchema, o as locationsSchema, r as relatedPostSchema, p as relationDatesSchema, s as socialShareResourceSchema, t as termsAgreementSchema, u as userLicenseSchema } from '../Affiliate-
|
|
6
|
+
import { S as SchemaOwnerType } from '../Affiliate-DIAzxxfs.mjs';
|
|
7
|
+
export { A as AffiliateModel, C as CategorySchema, a as ContactDetailsSchema, O as OwnerTypeSchema, R as RelationModel, b as RelationTypeSchema, c as ResourceImageTypeSchema, d as SchemaAffiliateResourceType, e as SchemaAffiliateReward, f as SchemaRelatedPostType, g as SchemaRelationType, h as SchemaStripeSubscription, i as SchemaUserActivityEvent, j as SchemaUserType, k as SocialMediaTypeSchema, U as UserModel, l as baseResourceFields, m as dateTimeSchema, n as locationGeoSchema, o as locationsSchema, r as relatedPostSchema, p as relationDatesSchema, s as socialShareResourceSchema, t as termsAgreementSchema, u as userLicenseSchema } from '../Affiliate-DIAzxxfs.mjs';
|
|
8
8
|
import '@timardex/cluemart-shared/types';
|
|
9
9
|
import 'express';
|
|
10
10
|
|
package/dist/mongoose/index.d.ts
CHANGED
|
@@ -3,8 +3,8 @@ import { AdType, AdDailyPriceType, AdBookingType, EnumAdShowOn, AdSettingsType,
|
|
|
3
3
|
import mongoose__default from 'mongoose';
|
|
4
4
|
import { O as ObjectId } from '../index-CmtBYjpi.js';
|
|
5
5
|
export { C as ChatModel, N as NotificationModel, S as SchemaChatMessageReactionType, a as SchemaChatMessageReplyPreviewType, b as SchemaChatMessageSeenType, c as SchemaChatMessageType, d as SchemaChatType, e as SchemaCreateBulkNotificationInput, f as SchemaNotificationType, g as SchemaParticipantType } from '../index-CmtBYjpi.js';
|
|
6
|
-
import { S as SchemaOwnerType } from '../Affiliate-
|
|
7
|
-
export { A as AffiliateModel, C as CategorySchema, a as ContactDetailsSchema, O as OwnerTypeSchema, R as RelationModel, b as RelationTypeSchema, c as ResourceImageTypeSchema, d as SchemaAffiliateResourceType, e as SchemaAffiliateReward, f as SchemaRelatedPostType, g as SchemaRelationType, h as SchemaStripeSubscription, i as SchemaUserActivityEvent, j as SchemaUserType, k as SocialMediaTypeSchema, U as UserModel, l as baseResourceFields, m as dateTimeSchema, n as locationGeoSchema, o as locationsSchema, r as relatedPostSchema, p as relationDatesSchema, s as socialShareResourceSchema, t as termsAgreementSchema, u as userLicenseSchema } from '../Affiliate-
|
|
6
|
+
import { S as SchemaOwnerType } from '../Affiliate-zioeZDyH.js';
|
|
7
|
+
export { A as AffiliateModel, C as CategorySchema, a as ContactDetailsSchema, O as OwnerTypeSchema, R as RelationModel, b as RelationTypeSchema, c as ResourceImageTypeSchema, d as SchemaAffiliateResourceType, e as SchemaAffiliateReward, f as SchemaRelatedPostType, g as SchemaRelationType, h as SchemaStripeSubscription, i as SchemaUserActivityEvent, j as SchemaUserType, k as SocialMediaTypeSchema, U as UserModel, l as baseResourceFields, m as dateTimeSchema, n as locationGeoSchema, o as locationsSchema, r as relatedPostSchema, p as relationDatesSchema, s as socialShareResourceSchema, t as termsAgreementSchema, u as userLicenseSchema } from '../Affiliate-zioeZDyH.js';
|
|
8
8
|
import '@timardex/cluemart-shared/types';
|
|
9
9
|
import 'express';
|
|
10
10
|
|
package/dist/mongoose/index.mjs
CHANGED
package/dist/service/index.cjs
CHANGED
|
@@ -38,12 +38,18 @@ __export(service_exports, {
|
|
|
38
38
|
activeAffiliateCodeExists: () => activeAffiliateCodeExists,
|
|
39
39
|
awardAffiliateVendorSubscriptionRewards: () => awardAffiliateVendorSubscriptionRewards,
|
|
40
40
|
buildLicenceExpiryPipeline: () => buildLicenceExpiryPipeline,
|
|
41
|
+
buildUserHasEnoughPointsFilter: () => buildUserHasEnoughPointsFilter,
|
|
42
|
+
buildUserPointAwardEntry: () => buildUserPointAwardEntry,
|
|
43
|
+
buildUserPointCreditFilter: () => buildUserPointCreditFilter,
|
|
44
|
+
buildUserPointDebitPipeline: () => buildUserPointDebitPipeline,
|
|
45
|
+
buildUserPointEntryRemovalPipeline: () => buildUserPointEntryRemovalPipeline,
|
|
41
46
|
checkOwnerHasLicence: () => checkOwnerHasLicence,
|
|
42
47
|
connectToDatabase: () => connectToDatabase,
|
|
43
48
|
convertObjectIdsToStrings: () => convertObjectIdsToStrings,
|
|
44
49
|
createLicenceObject: () => createLicenceObject,
|
|
45
50
|
dedupeArchivedSlotsByStartDateTime: () => dedupeArchivedSlotsByStartDateTime,
|
|
46
51
|
didRemoveAnyEventDates: () => didRemoveAnyEventDates,
|
|
52
|
+
didRemoveAnyStartedDates: () => didRemoveAnyStartedDates,
|
|
47
53
|
downgradeVendorProFeatures: () => downgradeVendorProFeatures,
|
|
48
54
|
ensureUserLicenseCompliance: () => ensureUserLicenseCompliance,
|
|
49
55
|
ensureUserLicenseComplianceForUser: () => ensureUserLicenseComplianceForUser,
|
|
@@ -1524,6 +1530,19 @@ var redeemedRewardSchema = new MongooseSchema12(
|
|
|
1524
1530
|
},
|
|
1525
1531
|
{ _id: false }
|
|
1526
1532
|
);
|
|
1533
|
+
var userOverallPointsSchema = new MongooseSchema12(
|
|
1534
|
+
{
|
|
1535
|
+
createdAt: { required: true, type: Date },
|
|
1536
|
+
points: { default: 0, required: true, type: Number },
|
|
1537
|
+
pointType: {
|
|
1538
|
+
enum: Object.values(import_cluemart_shared13.EnumPointType),
|
|
1539
|
+
required: true,
|
|
1540
|
+
type: String
|
|
1541
|
+
},
|
|
1542
|
+
sourceId: { required: false, type: String }
|
|
1543
|
+
},
|
|
1544
|
+
{ _id: false }
|
|
1545
|
+
);
|
|
1527
1546
|
var schema12 = new MongooseSchema12(
|
|
1528
1547
|
{
|
|
1529
1548
|
active: { default: false, required: true, type: Boolean },
|
|
@@ -1575,7 +1594,11 @@ var schema12 = new MongooseSchema12(
|
|
|
1575
1594
|
type: locationsSchema
|
|
1576
1595
|
},
|
|
1577
1596
|
nickName: { required: false, type: String },
|
|
1578
|
-
overallPoints: {
|
|
1597
|
+
overallPoints: {
|
|
1598
|
+
default: [],
|
|
1599
|
+
required: false,
|
|
1600
|
+
type: [userOverallPointsSchema]
|
|
1601
|
+
},
|
|
1579
1602
|
partner: {
|
|
1580
1603
|
ref: "Partner",
|
|
1581
1604
|
required: false,
|
|
@@ -2217,7 +2240,10 @@ var gameTypeSchema = new MongooseSchema24(
|
|
|
2217
2240
|
required: true,
|
|
2218
2241
|
type: String
|
|
2219
2242
|
},
|
|
2220
|
-
gameTypeId: { required: true, type: String }
|
|
2243
|
+
gameTypeId: { required: true, type: String },
|
|
2244
|
+
// See `GameType.pointsCredited`: absent means "completed before the marker
|
|
2245
|
+
// existed", which must not be re-credited.
|
|
2246
|
+
pointsCredited: { required: false, type: Boolean }
|
|
2221
2247
|
},
|
|
2222
2248
|
{ timestamps: true }
|
|
2223
2249
|
);
|
|
@@ -3158,15 +3184,189 @@ function convertObjectIdsToStrings(obj) {
|
|
|
3158
3184
|
return obj;
|
|
3159
3185
|
}
|
|
3160
3186
|
|
|
3187
|
+
// src/service/userPoints.ts
|
|
3188
|
+
var import_dayjs2 = __toESM(require("dayjs"));
|
|
3189
|
+
function assertValidPointAmount(amount, label) {
|
|
3190
|
+
if (!Number.isFinite(amount) || amount < 0) {
|
|
3191
|
+
throw new RangeError(
|
|
3192
|
+
`Invalid user point ${label}: ${String(amount)}. Expected a finite, non-negative number.`
|
|
3193
|
+
);
|
|
3194
|
+
}
|
|
3195
|
+
}
|
|
3196
|
+
function buildUserPointAwardEntry(pointType, points, sourceId) {
|
|
3197
|
+
assertValidPointAmount(points, "award");
|
|
3198
|
+
return {
|
|
3199
|
+
createdAt: (0, import_dayjs2.default)().toDate(),
|
|
3200
|
+
points,
|
|
3201
|
+
pointType,
|
|
3202
|
+
...sourceId === void 0 ? {} : { sourceId }
|
|
3203
|
+
};
|
|
3204
|
+
}
|
|
3205
|
+
function buildUserPointCreditFilter(userId, sourceId) {
|
|
3206
|
+
return {
|
|
3207
|
+
_id: userId,
|
|
3208
|
+
overallPoints: { $not: { $elemMatch: { sourceId } } }
|
|
3209
|
+
};
|
|
3210
|
+
}
|
|
3211
|
+
function buildUserHasEnoughPointsFilter(amount) {
|
|
3212
|
+
assertValidPointAmount(amount, "threshold");
|
|
3213
|
+
return {
|
|
3214
|
+
$expr: {
|
|
3215
|
+
$gte: [{ $sum: { $ifNull: ["$overallPoints.points", []] } }, amount]
|
|
3216
|
+
}
|
|
3217
|
+
};
|
|
3218
|
+
}
|
|
3219
|
+
function buildLedgerWriteExpr(computedLedger) {
|
|
3220
|
+
return {
|
|
3221
|
+
$cond: [
|
|
3222
|
+
{ $isArray: "$overallPoints" },
|
|
3223
|
+
computedLedger,
|
|
3224
|
+
{ $ifNull: ["$overallPoints", []] }
|
|
3225
|
+
]
|
|
3226
|
+
};
|
|
3227
|
+
}
|
|
3228
|
+
function buildUserPointDebitPipeline(amount) {
|
|
3229
|
+
assertValidPointAmount(amount, "debit");
|
|
3230
|
+
const debitedLedger = {
|
|
3231
|
+
$let: {
|
|
3232
|
+
vars: {
|
|
3233
|
+
sorted: {
|
|
3234
|
+
$sortArray: {
|
|
3235
|
+
input: { $ifNull: ["$overallPoints", []] },
|
|
3236
|
+
sortBy: { createdAt: 1 }
|
|
3237
|
+
}
|
|
3238
|
+
}
|
|
3239
|
+
},
|
|
3240
|
+
in: {
|
|
3241
|
+
$let: {
|
|
3242
|
+
vars: {
|
|
3243
|
+
debited: {
|
|
3244
|
+
$reduce: {
|
|
3245
|
+
initialValue: { budget: amount, entries: [] },
|
|
3246
|
+
in: {
|
|
3247
|
+
$let: {
|
|
3248
|
+
vars: { available: { $ifNull: ["$$this.points", 0] } },
|
|
3249
|
+
in: {
|
|
3250
|
+
budget: {
|
|
3251
|
+
$subtract: [
|
|
3252
|
+
"$$value.budget",
|
|
3253
|
+
{ $min: ["$$available", "$$value.budget"] }
|
|
3254
|
+
]
|
|
3255
|
+
},
|
|
3256
|
+
entries: {
|
|
3257
|
+
$concatArrays: [
|
|
3258
|
+
"$$value.entries",
|
|
3259
|
+
[
|
|
3260
|
+
{
|
|
3261
|
+
$mergeObjects: [
|
|
3262
|
+
"$$this",
|
|
3263
|
+
{
|
|
3264
|
+
points: {
|
|
3265
|
+
$subtract: [
|
|
3266
|
+
"$$available",
|
|
3267
|
+
{
|
|
3268
|
+
$min: ["$$available", "$$value.budget"]
|
|
3269
|
+
}
|
|
3270
|
+
]
|
|
3271
|
+
}
|
|
3272
|
+
}
|
|
3273
|
+
]
|
|
3274
|
+
}
|
|
3275
|
+
]
|
|
3276
|
+
]
|
|
3277
|
+
}
|
|
3278
|
+
}
|
|
3279
|
+
}
|
|
3280
|
+
},
|
|
3281
|
+
input: "$$sorted"
|
|
3282
|
+
}
|
|
3283
|
+
}
|
|
3284
|
+
},
|
|
3285
|
+
in: {
|
|
3286
|
+
$filter: {
|
|
3287
|
+
as: "entry",
|
|
3288
|
+
cond: { $gt: ["$$entry.points", 0] },
|
|
3289
|
+
input: "$$debited.entries"
|
|
3290
|
+
}
|
|
3291
|
+
}
|
|
3292
|
+
}
|
|
3293
|
+
}
|
|
3294
|
+
}
|
|
3295
|
+
};
|
|
3296
|
+
return [
|
|
3297
|
+
{
|
|
3298
|
+
$set: {
|
|
3299
|
+
overallPoints: buildLedgerWriteExpr(debitedLedger)
|
|
3300
|
+
}
|
|
3301
|
+
}
|
|
3302
|
+
];
|
|
3303
|
+
}
|
|
3304
|
+
function buildUserPointEntryRemovalPipeline(pointType, sourceId) {
|
|
3305
|
+
const indexExpression = sourceId === void 0 ? { $indexOfArray: ["$$entries.pointType", pointType] } : {
|
|
3306
|
+
$indexOfArray: [
|
|
3307
|
+
{
|
|
3308
|
+
$map: {
|
|
3309
|
+
as: "entry",
|
|
3310
|
+
in: {
|
|
3311
|
+
$and: [
|
|
3312
|
+
{ $eq: ["$$entry.pointType", pointType] },
|
|
3313
|
+
{ $eq: ["$$entry.sourceId", sourceId] }
|
|
3314
|
+
]
|
|
3315
|
+
},
|
|
3316
|
+
input: "$$entries"
|
|
3317
|
+
}
|
|
3318
|
+
},
|
|
3319
|
+
true
|
|
3320
|
+
]
|
|
3321
|
+
};
|
|
3322
|
+
const entriesAfterRemoval = {
|
|
3323
|
+
$let: {
|
|
3324
|
+
vars: { entries: { $ifNull: ["$overallPoints", []] } },
|
|
3325
|
+
in: {
|
|
3326
|
+
$let: {
|
|
3327
|
+
vars: {
|
|
3328
|
+
index: indexExpression
|
|
3329
|
+
},
|
|
3330
|
+
in: {
|
|
3331
|
+
$cond: [
|
|
3332
|
+
{ $lt: ["$$index", 0] },
|
|
3333
|
+
"$$entries",
|
|
3334
|
+
{
|
|
3335
|
+
$concatArrays: [
|
|
3336
|
+
{ $slice: ["$$entries", "$$index"] },
|
|
3337
|
+
{
|
|
3338
|
+
$slice: [
|
|
3339
|
+
"$$entries",
|
|
3340
|
+
{ $add: ["$$index", 1] },
|
|
3341
|
+
{ $size: "$$entries" }
|
|
3342
|
+
]
|
|
3343
|
+
}
|
|
3344
|
+
]
|
|
3345
|
+
}
|
|
3346
|
+
]
|
|
3347
|
+
}
|
|
3348
|
+
}
|
|
3349
|
+
}
|
|
3350
|
+
}
|
|
3351
|
+
};
|
|
3352
|
+
return [
|
|
3353
|
+
{
|
|
3354
|
+
$set: {
|
|
3355
|
+
overallPoints: buildLedgerWriteExpr(entriesAfterRemoval)
|
|
3356
|
+
}
|
|
3357
|
+
}
|
|
3358
|
+
];
|
|
3359
|
+
}
|
|
3360
|
+
|
|
3161
3361
|
// src/service/event/updateAllEventDateTimeStatuses.ts
|
|
3162
3362
|
var import_cluemart_shared27 = require("@timardex/cluemart-shared");
|
|
3163
|
-
var
|
|
3363
|
+
var import_dayjs4 = __toESM(require("dayjs"));
|
|
3164
3364
|
|
|
3165
3365
|
// src/service/event/archiveEndedEventDates.ts
|
|
3166
3366
|
var import_cluemart_shared26 = require("@timardex/cluemart-shared");
|
|
3167
|
-
var
|
|
3367
|
+
var import_dayjs3 = __toESM(require("dayjs"));
|
|
3168
3368
|
var import_customParseFormat = __toESM(require("dayjs/plugin/customParseFormat"));
|
|
3169
|
-
|
|
3369
|
+
import_dayjs3.default.extend(import_customParseFormat.default);
|
|
3170
3370
|
var ARCHIVED_STATUSES = /* @__PURE__ */ new Set([
|
|
3171
3371
|
import_cluemart_shared26.EnumEventDateStatus.ENDED
|
|
3172
3372
|
]);
|
|
@@ -3197,7 +3397,7 @@ function isPastCanceledEventDate(slot, now) {
|
|
|
3197
3397
|
if (slot.dateStatus !== import_cluemart_shared26.EnumEventDateStatus.CANCELED) {
|
|
3198
3398
|
return false;
|
|
3199
3399
|
}
|
|
3200
|
-
const endDateTime = (0,
|
|
3400
|
+
const endDateTime = (0, import_dayjs3.default)(
|
|
3201
3401
|
`${slot.endDate} ${slot.endTime}`,
|
|
3202
3402
|
`${import_cluemart_shared26.dateFormat} ${import_cluemart_shared26.timeFormat}`,
|
|
3203
3403
|
true
|
|
@@ -3392,7 +3592,7 @@ async function cleanEventInfoDates(now) {
|
|
|
3392
3592
|
return removedCount;
|
|
3393
3593
|
}
|
|
3394
3594
|
async function updateAllEventDateTimeStatuses() {
|
|
3395
|
-
const now = (0,
|
|
3595
|
+
const now = (0, import_dayjs4.default)();
|
|
3396
3596
|
const [eventCount, marketCount] = await Promise.all([
|
|
3397
3597
|
updateModelDateTimeStatuses(EventModel, now),
|
|
3398
3598
|
updateModelDateTimeStatuses(
|
|
@@ -3443,6 +3643,16 @@ function didRemoveAnyEventDates(previousDateTime, nextDateTime) {
|
|
|
3443
3643
|
)
|
|
3444
3644
|
);
|
|
3445
3645
|
}
|
|
3646
|
+
function didRemoveAnyStartedDates(previousDateTime, nextDateTime) {
|
|
3647
|
+
if (!previousDateTime?.length) {
|
|
3648
|
+
return false;
|
|
3649
|
+
}
|
|
3650
|
+
return previousDateTime.some(
|
|
3651
|
+
(prev) => prev.dateStatus === import_cluemart_shared28.EnumEventDateStatus.STARTED && !nextDateTime?.some(
|
|
3652
|
+
(next) => next.startDate === prev.startDate && next.startTime === prev.startTime && next.dateStatus === import_cluemart_shared28.EnumEventDateStatus.STARTED
|
|
3653
|
+
)
|
|
3654
|
+
);
|
|
3655
|
+
}
|
|
3446
3656
|
function updateRelationDatesToUnavailable(relationDates, eventDateTime) {
|
|
3447
3657
|
return relationDates.map((relationDate) => {
|
|
3448
3658
|
const existsInEvent = eventDateTime?.some(
|
|
@@ -3456,11 +3666,11 @@ function updateRelationDatesToUnavailable(relationDates, eventDateTime) {
|
|
|
3456
3666
|
}
|
|
3457
3667
|
|
|
3458
3668
|
// src/service/license/compliance/ensureUserLicenseCompliance.ts
|
|
3459
|
-
var
|
|
3669
|
+
var import_dayjs8 = __toESM(require("dayjs"));
|
|
3460
3670
|
|
|
3461
3671
|
// src/service/license/compliance/utils.ts
|
|
3462
3672
|
var import_cluemart_shared33 = require("@timardex/cluemart-shared");
|
|
3463
|
-
var
|
|
3673
|
+
var import_dayjs7 = __toESM(require("dayjs"));
|
|
3464
3674
|
|
|
3465
3675
|
// src/service/license/compliance/event.ts
|
|
3466
3676
|
var import_cluemart_shared29 = require("@timardex/cluemart-shared");
|
|
@@ -3692,11 +3902,11 @@ async function handlePartnerLicenceCompliance(user, now) {
|
|
|
3692
3902
|
|
|
3693
3903
|
// src/service/license/compliance/vendor.ts
|
|
3694
3904
|
var import_cluemart_shared32 = require("@timardex/cluemart-shared");
|
|
3695
|
-
var
|
|
3905
|
+
var import_dayjs6 = __toESM(require("dayjs"));
|
|
3696
3906
|
|
|
3697
3907
|
// src/service/license/models.ts
|
|
3698
3908
|
var import_cluemart_shared31 = require("@timardex/cluemart-shared");
|
|
3699
|
-
var
|
|
3909
|
+
var import_dayjs5 = __toESM(require("dayjs"));
|
|
3700
3910
|
var import_graphql = require("graphql");
|
|
3701
3911
|
var LicenceCategory = /* @__PURE__ */ ((LicenceCategory2) => {
|
|
3702
3912
|
LicenceCategory2["EVENT"] = "event";
|
|
@@ -3777,7 +3987,7 @@ function getHighestLicenceForCategory(licences, category) {
|
|
|
3777
3987
|
return highestLicence;
|
|
3778
3988
|
}
|
|
3779
3989
|
function createLicenceObject(expiryDate, licenceType) {
|
|
3780
|
-
const today = (0,
|
|
3990
|
+
const today = (0, import_dayjs5.default)();
|
|
3781
3991
|
const expiryDateMapping = {
|
|
3782
3992
|
[import_cluemart_shared31.LicenceExpiryDate.ONE_YEAR]: today.add(1, "year").endOf("day").toDate(),
|
|
3783
3993
|
[import_cluemart_shared31.LicenceExpiryDate.ONE_MONTH]: today.add(1, "month").endOf("day").toDate(),
|
|
@@ -4040,7 +4250,7 @@ function isProtectedByCurrentStripeSubscription(user, licenceType, now) {
|
|
|
4040
4250
|
if (!stripe || stripe.currentPlan !== licenceType) {
|
|
4041
4251
|
return false;
|
|
4042
4252
|
}
|
|
4043
|
-
const gracePeriodEndsAt = stripe.paymentGracePeriodEndsAt ? (0,
|
|
4253
|
+
const gracePeriodEndsAt = stripe.paymentGracePeriodEndsAt ? (0, import_dayjs6.default)(stripe.paymentGracePeriodEndsAt) : null;
|
|
4044
4254
|
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);
|
|
4045
4255
|
if (hasActivePaymentGracePeriod) {
|
|
4046
4256
|
return true;
|
|
@@ -4054,7 +4264,7 @@ function isProtectedByCurrentStripeSubscription(user, licenceType, now) {
|
|
|
4054
4264
|
if (!stripe.endDate) {
|
|
4055
4265
|
return false;
|
|
4056
4266
|
}
|
|
4057
|
-
const paidThrough = (0,
|
|
4267
|
+
const paidThrough = (0, import_dayjs6.default)(stripe.endDate);
|
|
4058
4268
|
return paidThrough.isValid() && paidThrough.isAfter(now);
|
|
4059
4269
|
}
|
|
4060
4270
|
async function handleVendorLicenceCompliance(user, now) {
|
|
@@ -4071,7 +4281,7 @@ async function handleVendorLicenceCompliance(user, now) {
|
|
|
4071
4281
|
(licence) => licence.licenceType !== import_cluemart_shared32.EnumUserLicence.STANDARD_VENDOR
|
|
4072
4282
|
);
|
|
4073
4283
|
const expiredProLicences = proLicences.filter(
|
|
4074
|
-
(licence) => !(0,
|
|
4284
|
+
(licence) => !(0, import_dayjs6.default)(licence.expiryDate).isAfter(now)
|
|
4075
4285
|
);
|
|
4076
4286
|
const stripeProtectedLicenceTypes = new Set(
|
|
4077
4287
|
expiredProLicences.filter(
|
|
@@ -4083,7 +4293,7 @@ async function handleVendorLicenceCompliance(user, now) {
|
|
|
4083
4293
|
);
|
|
4084
4294
|
const hasValidProLicence = stripeProtectedLicenceTypes.size > 0 || hasValidLicence(proLicences, import_cluemart_shared32.vendorLicences, now);
|
|
4085
4295
|
const hasExpiredVendorLicence = vendorLicencesOfUser.some(
|
|
4086
|
-
(licence) => !(0,
|
|
4296
|
+
(licence) => !(0, import_dayjs6.default)(licence.expiryDate).isAfter(now) && !stripeProtectedLicenceTypes.has(licence.licenceType)
|
|
4087
4297
|
);
|
|
4088
4298
|
if (!hasExpiredVendorLicence) {
|
|
4089
4299
|
return;
|
|
@@ -4137,9 +4347,9 @@ async function vendorOwnerHasProLicence(vendorId) {
|
|
|
4137
4347
|
if (!owner) {
|
|
4138
4348
|
return false;
|
|
4139
4349
|
}
|
|
4140
|
-
const now = (0,
|
|
4350
|
+
const now = (0, import_dayjs6.default)();
|
|
4141
4351
|
const effectiveVendorLicences = owner.licences?.filter(
|
|
4142
|
-
(licence) => licence?.licenceType && ((0,
|
|
4352
|
+
(licence) => licence?.licenceType && ((0, import_dayjs6.default)(licence.expiryDate).isAfter(now) || isProtectedByCurrentStripeSubscription(
|
|
4143
4353
|
owner,
|
|
4144
4354
|
licence.licenceType,
|
|
4145
4355
|
now
|
|
@@ -4176,7 +4386,7 @@ async function syncUserLicencesAfterExpiry(userId, licenceTypes, now, mode = "do
|
|
|
4176
4386
|
}
|
|
4177
4387
|
function hasValidLicence(licences, licenceTypes, now) {
|
|
4178
4388
|
return licences.some(
|
|
4179
|
-
(licence) => licenceTypes.includes(licence.licenceType) && (0,
|
|
4389
|
+
(licence) => licenceTypes.includes(licence.licenceType) && (0, import_dayjs7.default)(licence.expiryDate).isAfter(now)
|
|
4180
4390
|
);
|
|
4181
4391
|
}
|
|
4182
4392
|
async function sendDeactivationNotification(payload, userId, resourceName, resourceType) {
|
|
@@ -4203,7 +4413,7 @@ async function processUserCompliance(user, now) {
|
|
|
4203
4413
|
}
|
|
4204
4414
|
|
|
4205
4415
|
// src/service/license/compliance/ensureUserLicenseCompliance.ts
|
|
4206
|
-
async function ensureUserLicenseComplianceForUser(userId, now = (0,
|
|
4416
|
+
async function ensureUserLicenseComplianceForUser(userId, now = (0, import_dayjs8.default)()) {
|
|
4207
4417
|
const user = await UserModel.findById(userId);
|
|
4208
4418
|
if (!user) {
|
|
4209
4419
|
return;
|
|
@@ -4211,7 +4421,7 @@ async function ensureUserLicenseComplianceForUser(userId, now = (0, import_dayjs
|
|
|
4211
4421
|
await processUserCompliance(user, now);
|
|
4212
4422
|
}
|
|
4213
4423
|
async function ensureUserLicenseCompliance() {
|
|
4214
|
-
const now = (0,
|
|
4424
|
+
const now = (0, import_dayjs8.default)();
|
|
4215
4425
|
console.log(`\u{1F50D} Checking license compliance at ${now.format()}`);
|
|
4216
4426
|
const nowDate = now.toDate();
|
|
4217
4427
|
const users = await UserModel.find({
|
|
@@ -4286,7 +4496,7 @@ async function getPartnerResourceInfo(userId, partnerId) {
|
|
|
4286
4496
|
}
|
|
4287
4497
|
|
|
4288
4498
|
// src/service/license/reminder/remindUsersAboutLicenseExpiration.ts
|
|
4289
|
-
var
|
|
4499
|
+
var import_dayjs10 = __toESM(require("dayjs"));
|
|
4290
4500
|
|
|
4291
4501
|
// src/service/license/reminder/reminderWindow.ts
|
|
4292
4502
|
var REMINDER_WINDOW_MIN_HOURS = 6.5 * 24;
|
|
@@ -4295,7 +4505,7 @@ var REMINDER_WINDOW_MAX_HOURS = 7.5 * 24;
|
|
|
4295
4505
|
// src/service/license/reminder/utils.ts
|
|
4296
4506
|
var import_cluemart_shared34 = require("@timardex/cluemart-shared");
|
|
4297
4507
|
var import_utils8 = require("@timardex/cluemart-shared/utils");
|
|
4298
|
-
var
|
|
4508
|
+
var import_dayjs9 = __toESM(require("dayjs"));
|
|
4299
4509
|
|
|
4300
4510
|
// src/service/license/reminder/vendor.ts
|
|
4301
4511
|
async function getVendorResourceInfo(userId, vendorId) {
|
|
@@ -4354,7 +4564,7 @@ async function checkAndCreateNotification(payload) {
|
|
|
4354
4564
|
}
|
|
4355
4565
|
}
|
|
4356
4566
|
function isLicenseExpiringIn7Days(expiryDate, now) {
|
|
4357
|
-
const expiry = (0,
|
|
4567
|
+
const expiry = (0, import_dayjs9.default)(expiryDate);
|
|
4358
4568
|
const hoursUntilExpiry = expiry.diff(now, "hour", true);
|
|
4359
4569
|
return hoursUntilExpiry >= REMINDER_WINDOW_MIN_HOURS && hoursUntilExpiry <= REMINDER_WINDOW_MAX_HOURS;
|
|
4360
4570
|
}
|
|
@@ -4432,7 +4642,7 @@ function getLicenceExpiryMode(licenceType) {
|
|
|
4432
4642
|
}
|
|
4433
4643
|
async function sendLicenseReminder(user, licence) {
|
|
4434
4644
|
const licenceName = getLicenseName(licence.licenceType);
|
|
4435
|
-
const expiryDate = (0,
|
|
4645
|
+
const expiryDate = (0, import_dayjs9.default)(licence.expiryDate).format(import_cluemart_shared34.dateFormat);
|
|
4436
4646
|
const userId = String(user._id);
|
|
4437
4647
|
const resourceInfo = await getLicenseResourceInfo(user, licence);
|
|
4438
4648
|
if (!resourceInfo) {
|
|
@@ -4464,7 +4674,7 @@ async function sendLicenseReminder(user, licence) {
|
|
|
4464
4674
|
console.log(`\u2705 Sent 7-day reminder to user ${userId} for ${licenceName}`);
|
|
4465
4675
|
}
|
|
4466
4676
|
async function processLicenseReminder(licence, now) {
|
|
4467
|
-
if ((0,
|
|
4677
|
+
if ((0, import_dayjs9.default)(licence.expiryDate).isBefore(now)) {
|
|
4468
4678
|
return false;
|
|
4469
4679
|
}
|
|
4470
4680
|
if (!isLicenseExpiringIn7Days(licence.expiryDate, now)) {
|
|
@@ -4518,7 +4728,7 @@ async function processUserLicenseReminders(user, now) {
|
|
|
4518
4728
|
|
|
4519
4729
|
// src/service/license/reminder/remindUsersAboutLicenseExpiration.ts
|
|
4520
4730
|
async function remindUsersAboutLicenseExpiration() {
|
|
4521
|
-
const now = (0,
|
|
4731
|
+
const now = (0, import_dayjs10.default)();
|
|
4522
4732
|
console.log(`\u{1F50D} Checking for licenses expiring in 7 days at ${now.format()}`);
|
|
4523
4733
|
const minExpiryDate = now.add(REMINDER_WINDOW_MIN_HOURS, "hour").toDate();
|
|
4524
4734
|
const maxExpiryDate = now.add(REMINDER_WINDOW_MAX_HOURS, "hour").toDate();
|
|
@@ -4565,12 +4775,18 @@ async function remindUsersAboutLicenseExpiration() {
|
|
|
4565
4775
|
activeAffiliateCodeExists,
|
|
4566
4776
|
awardAffiliateVendorSubscriptionRewards,
|
|
4567
4777
|
buildLicenceExpiryPipeline,
|
|
4778
|
+
buildUserHasEnoughPointsFilter,
|
|
4779
|
+
buildUserPointAwardEntry,
|
|
4780
|
+
buildUserPointCreditFilter,
|
|
4781
|
+
buildUserPointDebitPipeline,
|
|
4782
|
+
buildUserPointEntryRemovalPipeline,
|
|
4568
4783
|
checkOwnerHasLicence,
|
|
4569
4784
|
connectToDatabase,
|
|
4570
4785
|
convertObjectIdsToStrings,
|
|
4571
4786
|
createLicenceObject,
|
|
4572
4787
|
dedupeArchivedSlotsByStartDateTime,
|
|
4573
4788
|
didRemoveAnyEventDates,
|
|
4789
|
+
didRemoveAnyStartedDates,
|
|
4574
4790
|
downgradeVendorProFeatures,
|
|
4575
4791
|
ensureUserLicenseCompliance,
|
|
4576
4792
|
ensureUserLicenseComplianceForUser,
|