@timardex/cluemart-server-shared 2.2.23 → 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 +231 -27
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.mts +91 -4
- package/dist/index.d.ts +91 -4
- package/dist/index.mjs +227 -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 +231 -27
- package/dist/service/index.cjs.map +1 -1
- package/dist/service/index.d.mts +90 -3
- package/dist/service/index.d.ts +90 -3
- package/dist/service/index.mjs +205 -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,6 +38,11 @@ __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,
|
|
@@ -1525,6 +1530,19 @@ var redeemedRewardSchema = new MongooseSchema12(
|
|
|
1525
1530
|
},
|
|
1526
1531
|
{ _id: false }
|
|
1527
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
|
+
);
|
|
1528
1546
|
var schema12 = new MongooseSchema12(
|
|
1529
1547
|
{
|
|
1530
1548
|
active: { default: false, required: true, type: Boolean },
|
|
@@ -1576,7 +1594,11 @@ var schema12 = new MongooseSchema12(
|
|
|
1576
1594
|
type: locationsSchema
|
|
1577
1595
|
},
|
|
1578
1596
|
nickName: { required: false, type: String },
|
|
1579
|
-
overallPoints: {
|
|
1597
|
+
overallPoints: {
|
|
1598
|
+
default: [],
|
|
1599
|
+
required: false,
|
|
1600
|
+
type: [userOverallPointsSchema]
|
|
1601
|
+
},
|
|
1580
1602
|
partner: {
|
|
1581
1603
|
ref: "Partner",
|
|
1582
1604
|
required: false,
|
|
@@ -2218,7 +2240,10 @@ var gameTypeSchema = new MongooseSchema24(
|
|
|
2218
2240
|
required: true,
|
|
2219
2241
|
type: String
|
|
2220
2242
|
},
|
|
2221
|
-
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 }
|
|
2222
2247
|
},
|
|
2223
2248
|
{ timestamps: true }
|
|
2224
2249
|
);
|
|
@@ -3159,15 +3184,189 @@ function convertObjectIdsToStrings(obj) {
|
|
|
3159
3184
|
return obj;
|
|
3160
3185
|
}
|
|
3161
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
|
+
|
|
3162
3361
|
// src/service/event/updateAllEventDateTimeStatuses.ts
|
|
3163
3362
|
var import_cluemart_shared27 = require("@timardex/cluemart-shared");
|
|
3164
|
-
var
|
|
3363
|
+
var import_dayjs4 = __toESM(require("dayjs"));
|
|
3165
3364
|
|
|
3166
3365
|
// src/service/event/archiveEndedEventDates.ts
|
|
3167
3366
|
var import_cluemart_shared26 = require("@timardex/cluemart-shared");
|
|
3168
|
-
var
|
|
3367
|
+
var import_dayjs3 = __toESM(require("dayjs"));
|
|
3169
3368
|
var import_customParseFormat = __toESM(require("dayjs/plugin/customParseFormat"));
|
|
3170
|
-
|
|
3369
|
+
import_dayjs3.default.extend(import_customParseFormat.default);
|
|
3171
3370
|
var ARCHIVED_STATUSES = /* @__PURE__ */ new Set([
|
|
3172
3371
|
import_cluemart_shared26.EnumEventDateStatus.ENDED
|
|
3173
3372
|
]);
|
|
@@ -3198,7 +3397,7 @@ function isPastCanceledEventDate(slot, now) {
|
|
|
3198
3397
|
if (slot.dateStatus !== import_cluemart_shared26.EnumEventDateStatus.CANCELED) {
|
|
3199
3398
|
return false;
|
|
3200
3399
|
}
|
|
3201
|
-
const endDateTime = (0,
|
|
3400
|
+
const endDateTime = (0, import_dayjs3.default)(
|
|
3202
3401
|
`${slot.endDate} ${slot.endTime}`,
|
|
3203
3402
|
`${import_cluemart_shared26.dateFormat} ${import_cluemart_shared26.timeFormat}`,
|
|
3204
3403
|
true
|
|
@@ -3393,7 +3592,7 @@ async function cleanEventInfoDates(now) {
|
|
|
3393
3592
|
return removedCount;
|
|
3394
3593
|
}
|
|
3395
3594
|
async function updateAllEventDateTimeStatuses() {
|
|
3396
|
-
const now = (0,
|
|
3595
|
+
const now = (0, import_dayjs4.default)();
|
|
3397
3596
|
const [eventCount, marketCount] = await Promise.all([
|
|
3398
3597
|
updateModelDateTimeStatuses(EventModel, now),
|
|
3399
3598
|
updateModelDateTimeStatuses(
|
|
@@ -3467,11 +3666,11 @@ function updateRelationDatesToUnavailable(relationDates, eventDateTime) {
|
|
|
3467
3666
|
}
|
|
3468
3667
|
|
|
3469
3668
|
// src/service/license/compliance/ensureUserLicenseCompliance.ts
|
|
3470
|
-
var
|
|
3669
|
+
var import_dayjs8 = __toESM(require("dayjs"));
|
|
3471
3670
|
|
|
3472
3671
|
// src/service/license/compliance/utils.ts
|
|
3473
3672
|
var import_cluemart_shared33 = require("@timardex/cluemart-shared");
|
|
3474
|
-
var
|
|
3673
|
+
var import_dayjs7 = __toESM(require("dayjs"));
|
|
3475
3674
|
|
|
3476
3675
|
// src/service/license/compliance/event.ts
|
|
3477
3676
|
var import_cluemart_shared29 = require("@timardex/cluemart-shared");
|
|
@@ -3703,11 +3902,11 @@ async function handlePartnerLicenceCompliance(user, now) {
|
|
|
3703
3902
|
|
|
3704
3903
|
// src/service/license/compliance/vendor.ts
|
|
3705
3904
|
var import_cluemart_shared32 = require("@timardex/cluemart-shared");
|
|
3706
|
-
var
|
|
3905
|
+
var import_dayjs6 = __toESM(require("dayjs"));
|
|
3707
3906
|
|
|
3708
3907
|
// src/service/license/models.ts
|
|
3709
3908
|
var import_cluemart_shared31 = require("@timardex/cluemart-shared");
|
|
3710
|
-
var
|
|
3909
|
+
var import_dayjs5 = __toESM(require("dayjs"));
|
|
3711
3910
|
var import_graphql = require("graphql");
|
|
3712
3911
|
var LicenceCategory = /* @__PURE__ */ ((LicenceCategory2) => {
|
|
3713
3912
|
LicenceCategory2["EVENT"] = "event";
|
|
@@ -3788,7 +3987,7 @@ function getHighestLicenceForCategory(licences, category) {
|
|
|
3788
3987
|
return highestLicence;
|
|
3789
3988
|
}
|
|
3790
3989
|
function createLicenceObject(expiryDate, licenceType) {
|
|
3791
|
-
const today = (0,
|
|
3990
|
+
const today = (0, import_dayjs5.default)();
|
|
3792
3991
|
const expiryDateMapping = {
|
|
3793
3992
|
[import_cluemart_shared31.LicenceExpiryDate.ONE_YEAR]: today.add(1, "year").endOf("day").toDate(),
|
|
3794
3993
|
[import_cluemart_shared31.LicenceExpiryDate.ONE_MONTH]: today.add(1, "month").endOf("day").toDate(),
|
|
@@ -4051,7 +4250,7 @@ function isProtectedByCurrentStripeSubscription(user, licenceType, now) {
|
|
|
4051
4250
|
if (!stripe || stripe.currentPlan !== licenceType) {
|
|
4052
4251
|
return false;
|
|
4053
4252
|
}
|
|
4054
|
-
const gracePeriodEndsAt = stripe.paymentGracePeriodEndsAt ? (0,
|
|
4253
|
+
const gracePeriodEndsAt = stripe.paymentGracePeriodEndsAt ? (0, import_dayjs6.default)(stripe.paymentGracePeriodEndsAt) : null;
|
|
4055
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);
|
|
4056
4255
|
if (hasActivePaymentGracePeriod) {
|
|
4057
4256
|
return true;
|
|
@@ -4065,7 +4264,7 @@ function isProtectedByCurrentStripeSubscription(user, licenceType, now) {
|
|
|
4065
4264
|
if (!stripe.endDate) {
|
|
4066
4265
|
return false;
|
|
4067
4266
|
}
|
|
4068
|
-
const paidThrough = (0,
|
|
4267
|
+
const paidThrough = (0, import_dayjs6.default)(stripe.endDate);
|
|
4069
4268
|
return paidThrough.isValid() && paidThrough.isAfter(now);
|
|
4070
4269
|
}
|
|
4071
4270
|
async function handleVendorLicenceCompliance(user, now) {
|
|
@@ -4082,7 +4281,7 @@ async function handleVendorLicenceCompliance(user, now) {
|
|
|
4082
4281
|
(licence) => licence.licenceType !== import_cluemart_shared32.EnumUserLicence.STANDARD_VENDOR
|
|
4083
4282
|
);
|
|
4084
4283
|
const expiredProLicences = proLicences.filter(
|
|
4085
|
-
(licence) => !(0,
|
|
4284
|
+
(licence) => !(0, import_dayjs6.default)(licence.expiryDate).isAfter(now)
|
|
4086
4285
|
);
|
|
4087
4286
|
const stripeProtectedLicenceTypes = new Set(
|
|
4088
4287
|
expiredProLicences.filter(
|
|
@@ -4094,7 +4293,7 @@ async function handleVendorLicenceCompliance(user, now) {
|
|
|
4094
4293
|
);
|
|
4095
4294
|
const hasValidProLicence = stripeProtectedLicenceTypes.size > 0 || hasValidLicence(proLicences, import_cluemart_shared32.vendorLicences, now);
|
|
4096
4295
|
const hasExpiredVendorLicence = vendorLicencesOfUser.some(
|
|
4097
|
-
(licence) => !(0,
|
|
4296
|
+
(licence) => !(0, import_dayjs6.default)(licence.expiryDate).isAfter(now) && !stripeProtectedLicenceTypes.has(licence.licenceType)
|
|
4098
4297
|
);
|
|
4099
4298
|
if (!hasExpiredVendorLicence) {
|
|
4100
4299
|
return;
|
|
@@ -4148,9 +4347,9 @@ async function vendorOwnerHasProLicence(vendorId) {
|
|
|
4148
4347
|
if (!owner) {
|
|
4149
4348
|
return false;
|
|
4150
4349
|
}
|
|
4151
|
-
const now = (0,
|
|
4350
|
+
const now = (0, import_dayjs6.default)();
|
|
4152
4351
|
const effectiveVendorLicences = owner.licences?.filter(
|
|
4153
|
-
(licence) => licence?.licenceType && ((0,
|
|
4352
|
+
(licence) => licence?.licenceType && ((0, import_dayjs6.default)(licence.expiryDate).isAfter(now) || isProtectedByCurrentStripeSubscription(
|
|
4154
4353
|
owner,
|
|
4155
4354
|
licence.licenceType,
|
|
4156
4355
|
now
|
|
@@ -4187,7 +4386,7 @@ async function syncUserLicencesAfterExpiry(userId, licenceTypes, now, mode = "do
|
|
|
4187
4386
|
}
|
|
4188
4387
|
function hasValidLicence(licences, licenceTypes, now) {
|
|
4189
4388
|
return licences.some(
|
|
4190
|
-
(licence) => licenceTypes.includes(licence.licenceType) && (0,
|
|
4389
|
+
(licence) => licenceTypes.includes(licence.licenceType) && (0, import_dayjs7.default)(licence.expiryDate).isAfter(now)
|
|
4191
4390
|
);
|
|
4192
4391
|
}
|
|
4193
4392
|
async function sendDeactivationNotification(payload, userId, resourceName, resourceType) {
|
|
@@ -4214,7 +4413,7 @@ async function processUserCompliance(user, now) {
|
|
|
4214
4413
|
}
|
|
4215
4414
|
|
|
4216
4415
|
// src/service/license/compliance/ensureUserLicenseCompliance.ts
|
|
4217
|
-
async function ensureUserLicenseComplianceForUser(userId, now = (0,
|
|
4416
|
+
async function ensureUserLicenseComplianceForUser(userId, now = (0, import_dayjs8.default)()) {
|
|
4218
4417
|
const user = await UserModel.findById(userId);
|
|
4219
4418
|
if (!user) {
|
|
4220
4419
|
return;
|
|
@@ -4222,7 +4421,7 @@ async function ensureUserLicenseComplianceForUser(userId, now = (0, import_dayjs
|
|
|
4222
4421
|
await processUserCompliance(user, now);
|
|
4223
4422
|
}
|
|
4224
4423
|
async function ensureUserLicenseCompliance() {
|
|
4225
|
-
const now = (0,
|
|
4424
|
+
const now = (0, import_dayjs8.default)();
|
|
4226
4425
|
console.log(`\u{1F50D} Checking license compliance at ${now.format()}`);
|
|
4227
4426
|
const nowDate = now.toDate();
|
|
4228
4427
|
const users = await UserModel.find({
|
|
@@ -4297,7 +4496,7 @@ async function getPartnerResourceInfo(userId, partnerId) {
|
|
|
4297
4496
|
}
|
|
4298
4497
|
|
|
4299
4498
|
// src/service/license/reminder/remindUsersAboutLicenseExpiration.ts
|
|
4300
|
-
var
|
|
4499
|
+
var import_dayjs10 = __toESM(require("dayjs"));
|
|
4301
4500
|
|
|
4302
4501
|
// src/service/license/reminder/reminderWindow.ts
|
|
4303
4502
|
var REMINDER_WINDOW_MIN_HOURS = 6.5 * 24;
|
|
@@ -4306,7 +4505,7 @@ var REMINDER_WINDOW_MAX_HOURS = 7.5 * 24;
|
|
|
4306
4505
|
// src/service/license/reminder/utils.ts
|
|
4307
4506
|
var import_cluemart_shared34 = require("@timardex/cluemart-shared");
|
|
4308
4507
|
var import_utils8 = require("@timardex/cluemart-shared/utils");
|
|
4309
|
-
var
|
|
4508
|
+
var import_dayjs9 = __toESM(require("dayjs"));
|
|
4310
4509
|
|
|
4311
4510
|
// src/service/license/reminder/vendor.ts
|
|
4312
4511
|
async function getVendorResourceInfo(userId, vendorId) {
|
|
@@ -4365,7 +4564,7 @@ async function checkAndCreateNotification(payload) {
|
|
|
4365
4564
|
}
|
|
4366
4565
|
}
|
|
4367
4566
|
function isLicenseExpiringIn7Days(expiryDate, now) {
|
|
4368
|
-
const expiry = (0,
|
|
4567
|
+
const expiry = (0, import_dayjs9.default)(expiryDate);
|
|
4369
4568
|
const hoursUntilExpiry = expiry.diff(now, "hour", true);
|
|
4370
4569
|
return hoursUntilExpiry >= REMINDER_WINDOW_MIN_HOURS && hoursUntilExpiry <= REMINDER_WINDOW_MAX_HOURS;
|
|
4371
4570
|
}
|
|
@@ -4443,7 +4642,7 @@ function getLicenceExpiryMode(licenceType) {
|
|
|
4443
4642
|
}
|
|
4444
4643
|
async function sendLicenseReminder(user, licence) {
|
|
4445
4644
|
const licenceName = getLicenseName(licence.licenceType);
|
|
4446
|
-
const expiryDate = (0,
|
|
4645
|
+
const expiryDate = (0, import_dayjs9.default)(licence.expiryDate).format(import_cluemart_shared34.dateFormat);
|
|
4447
4646
|
const userId = String(user._id);
|
|
4448
4647
|
const resourceInfo = await getLicenseResourceInfo(user, licence);
|
|
4449
4648
|
if (!resourceInfo) {
|
|
@@ -4475,7 +4674,7 @@ async function sendLicenseReminder(user, licence) {
|
|
|
4475
4674
|
console.log(`\u2705 Sent 7-day reminder to user ${userId} for ${licenceName}`);
|
|
4476
4675
|
}
|
|
4477
4676
|
async function processLicenseReminder(licence, now) {
|
|
4478
|
-
if ((0,
|
|
4677
|
+
if ((0, import_dayjs9.default)(licence.expiryDate).isBefore(now)) {
|
|
4479
4678
|
return false;
|
|
4480
4679
|
}
|
|
4481
4680
|
if (!isLicenseExpiringIn7Days(licence.expiryDate, now)) {
|
|
@@ -4529,7 +4728,7 @@ async function processUserLicenseReminders(user, now) {
|
|
|
4529
4728
|
|
|
4530
4729
|
// src/service/license/reminder/remindUsersAboutLicenseExpiration.ts
|
|
4531
4730
|
async function remindUsersAboutLicenseExpiration() {
|
|
4532
|
-
const now = (0,
|
|
4731
|
+
const now = (0, import_dayjs10.default)();
|
|
4533
4732
|
console.log(`\u{1F50D} Checking for licenses expiring in 7 days at ${now.format()}`);
|
|
4534
4733
|
const minExpiryDate = now.add(REMINDER_WINDOW_MIN_HOURS, "hour").toDate();
|
|
4535
4734
|
const maxExpiryDate = now.add(REMINDER_WINDOW_MAX_HOURS, "hour").toDate();
|
|
@@ -4576,6 +4775,11 @@ async function remindUsersAboutLicenseExpiration() {
|
|
|
4576
4775
|
activeAffiliateCodeExists,
|
|
4577
4776
|
awardAffiliateVendorSubscriptionRewards,
|
|
4578
4777
|
buildLicenceExpiryPipeline,
|
|
4778
|
+
buildUserHasEnoughPointsFilter,
|
|
4779
|
+
buildUserPointAwardEntry,
|
|
4780
|
+
buildUserPointCreditFilter,
|
|
4781
|
+
buildUserPointDebitPipeline,
|
|
4782
|
+
buildUserPointEntryRemovalPipeline,
|
|
4579
4783
|
checkOwnerHasLicence,
|
|
4580
4784
|
connectToDatabase,
|
|
4581
4785
|
convertObjectIdsToStrings,
|