@timardex/cluemart-server-shared 2.2.12 → 2.2.22
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-i11rkfv5.d.mts → Affiliate-6AEy-gNx.d.mts} +1 -1
- package/dist/{Affiliate-BSF7Wm6O.d.ts → Affiliate-D40kRxO_.d.ts} +1 -1
- package/dist/{chunk-ZKHRT2PV.mjs → chunk-TIGQ6F5T.mjs} +60 -2
- package/dist/chunk-TIGQ6F5T.mjs.map +1 -0
- package/dist/{chunk-6PNG5BI5.mjs → chunk-TMPPPLIW.mjs} +1 -1
- package/dist/chunk-TMPPPLIW.mjs.map +1 -0
- package/dist/{index-Bq-lT7a2.d.mts → index-CmtBYjpi.d.mts} +4 -0
- package/dist/{index-Bq-lT7a2.d.ts → index-CmtBYjpi.d.ts} +4 -0
- package/dist/index.cjs +242 -148
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.mts +36 -2
- package/dist/index.d.ts +36 -2
- package/dist/index.mjs +145 -49
- package/dist/index.mjs.map +1 -1
- package/dist/mongoose/index.cjs +60 -0
- package/dist/mongoose/index.cjs.map +1 -1
- package/dist/mongoose/index.d.mts +36 -6
- package/dist/mongoose/index.d.ts +36 -6
- package/dist/mongoose/index.mjs +5 -1
- package/dist/service/index.cjs +237 -147
- package/dist/service/index.cjs.map +1 -1
- package/dist/service/index.d.mts +2 -2
- package/dist/service/index.d.ts +2 -2
- package/dist/service/index.mjs +72 -34
- package/dist/service/index.mjs.map +1 -1
- package/dist/types/index.cjs.map +1 -1
- package/dist/types/index.d.mts +1 -1
- package/dist/types/index.d.ts +1 -1
- package/dist/types/index.mjs +1 -1
- package/package.json +2 -2
- package/dist/chunk-6PNG5BI5.mjs.map +0 -1
- package/dist/chunk-ZKHRT2PV.mjs.map +0 -1
package/dist/service/index.cjs
CHANGED
|
@@ -91,7 +91,7 @@ __export(service_exports, {
|
|
|
91
91
|
updateAdStatuses: () => updateAdStatuses,
|
|
92
92
|
updateAllEventDateTimeStatuses: () => updateAllEventDateTimeStatuses,
|
|
93
93
|
updateRelationDatesToUnavailable: () => updateRelationDatesToUnavailable,
|
|
94
|
-
updateSingleDateTimeStatus: () =>
|
|
94
|
+
updateSingleDateTimeStatus: () => import_cluemart_shared35.updateSingleDateTimeStatus,
|
|
95
95
|
upgradeUserToLicence: () => upgradeUserToLicence,
|
|
96
96
|
vendorOwnerHasProLicence: () => vendorOwnerHasProLicence
|
|
97
97
|
});
|
|
@@ -2515,6 +2515,62 @@ schema24.index({ active: 1, deletedAt: 1, "owner.userId": 1 });
|
|
|
2515
2515
|
schema24.index({ "couponData.participantUsers.userId": 1 });
|
|
2516
2516
|
var CouponModel = import_mongoose32.default.models.Coupon || import_mongoose32.default.model("Coupon", schema24);
|
|
2517
2517
|
|
|
2518
|
+
// src/mongoose/Impersonation.ts
|
|
2519
|
+
var import_cluemart_shared22 = require("@timardex/cluemart-shared");
|
|
2520
|
+
var import_mongoose33 = __toESM(require("mongoose"));
|
|
2521
|
+
var MongooseSchema28 = import_mongoose33.default.Schema;
|
|
2522
|
+
var impersonationSessionSchema = new MongooseSchema28(
|
|
2523
|
+
{
|
|
2524
|
+
expiresAt: { expires: 0, required: true, type: Date },
|
|
2525
|
+
impersonatedUserId: {
|
|
2526
|
+
index: true,
|
|
2527
|
+
ref: "User",
|
|
2528
|
+
required: true,
|
|
2529
|
+
type: import_mongoose33.default.Schema.Types.ObjectId
|
|
2530
|
+
},
|
|
2531
|
+
impersonatorUserId: {
|
|
2532
|
+
index: true,
|
|
2533
|
+
ref: "User",
|
|
2534
|
+
required: true,
|
|
2535
|
+
type: import_mongoose33.default.Schema.Types.ObjectId
|
|
2536
|
+
},
|
|
2537
|
+
refreshToken: { required: true, type: String }
|
|
2538
|
+
},
|
|
2539
|
+
{ timestamps: true }
|
|
2540
|
+
);
|
|
2541
|
+
var ImpersonationSessionModel = import_mongoose33.default.models.ImpersonationSession || import_mongoose33.default.model(
|
|
2542
|
+
"ImpersonationSession",
|
|
2543
|
+
impersonationSessionSchema
|
|
2544
|
+
);
|
|
2545
|
+
var impersonationAuditSchema = new MongooseSchema28(
|
|
2546
|
+
{
|
|
2547
|
+
action: { enum: ["start", "end"], required: true, type: String },
|
|
2548
|
+
endReason: { type: String },
|
|
2549
|
+
impersonatedUserId: {
|
|
2550
|
+
ref: "User",
|
|
2551
|
+
required: true,
|
|
2552
|
+
type: import_mongoose33.default.Schema.Types.ObjectId
|
|
2553
|
+
},
|
|
2554
|
+
impersonatorUserId: {
|
|
2555
|
+
ref: "User",
|
|
2556
|
+
required: true,
|
|
2557
|
+
type: import_mongoose33.default.Schema.Types.ObjectId
|
|
2558
|
+
},
|
|
2559
|
+
resourceId: { type: import_mongoose33.default.Schema.Types.ObjectId },
|
|
2560
|
+
resourceType: { enum: Object.values(import_cluemart_shared22.EnumResourceType), type: String },
|
|
2561
|
+
sessionId: {
|
|
2562
|
+
ref: "ImpersonationSession",
|
|
2563
|
+
required: true,
|
|
2564
|
+
type: import_mongoose33.default.Schema.Types.ObjectId
|
|
2565
|
+
}
|
|
2566
|
+
},
|
|
2567
|
+
{ timestamps: true }
|
|
2568
|
+
);
|
|
2569
|
+
var ImpersonationAuditModel = import_mongoose33.default.models.ImpersonationAudit || import_mongoose33.default.model(
|
|
2570
|
+
"ImpersonationAudit",
|
|
2571
|
+
impersonationAuditSchema
|
|
2572
|
+
);
|
|
2573
|
+
|
|
2518
2574
|
// src/service/promoCode/constants.ts
|
|
2519
2575
|
var ACTIVE_NOT_DELETED_FILTER = {
|
|
2520
2576
|
active: true,
|
|
@@ -2531,7 +2587,7 @@ async function activeAffiliateCodeExists(affiliateCode) {
|
|
|
2531
2587
|
}
|
|
2532
2588
|
|
|
2533
2589
|
// src/service/affiliate/awardAffiliateVendorSubscriptionRewards.ts
|
|
2534
|
-
var
|
|
2590
|
+
var import_cluemart_shared24 = require("@timardex/cluemart-shared");
|
|
2535
2591
|
var import_utils3 = require("@timardex/cluemart-shared/utils");
|
|
2536
2592
|
|
|
2537
2593
|
// src/service/saveNotificationsInDb.ts
|
|
@@ -2666,7 +2722,7 @@ async function sendPushNotifications({
|
|
|
2666
2722
|
}
|
|
2667
2723
|
|
|
2668
2724
|
// src/service/affiliate/vendorSubscriptionRewards.ts
|
|
2669
|
-
var
|
|
2725
|
+
var import_cluemart_shared23 = require("@timardex/cluemart-shared");
|
|
2670
2726
|
var import_dayjs = __toESM(require("dayjs"));
|
|
2671
2727
|
var import_timezone = __toESM(require("dayjs/plugin/timezone"));
|
|
2672
2728
|
var import_utc = __toESM(require("dayjs/plugin/utc"));
|
|
@@ -2724,14 +2780,14 @@ import_dayjs.default.extend(import_timezone.default);
|
|
|
2724
2780
|
var SUBSCRIPTION_REWARD_TIMEZONE = "Pacific/Auckland";
|
|
2725
2781
|
async function mapVendorLicenceToSubscriptionRewardType(userId, now = /* @__PURE__ */ new Date()) {
|
|
2726
2782
|
const { hasSubscription, validTypes } = await getPayingVendorStripeSubscriptionPlan(userId, now);
|
|
2727
|
-
if (validTypes.has(
|
|
2783
|
+
if (validTypes.has(import_cluemart_shared23.EnumUserLicence.PRO_VENDOR) || validTypes.has(import_cluemart_shared23.EnumUserLicence.PRO_PLUS_VENDOR)) {
|
|
2728
2784
|
if (hasSubscription) {
|
|
2729
|
-
return
|
|
2785
|
+
return import_cluemart_shared23.EnumAffiliateRewardType.ACTIVE_VENDOR_PRO_SUBSCRIPTION;
|
|
2730
2786
|
}
|
|
2731
|
-
return
|
|
2787
|
+
return import_cluemart_shared23.EnumAffiliateRewardType.ACTIVE_VENDOR_STANDARD_SUBSCRIPTION;
|
|
2732
2788
|
}
|
|
2733
|
-
if (validTypes.has(
|
|
2734
|
-
return
|
|
2789
|
+
if (validTypes.has(import_cluemart_shared23.EnumUserLicence.STANDARD_VENDOR)) {
|
|
2790
|
+
return import_cluemart_shared23.EnumAffiliateRewardType.ACTIVE_VENDOR_STANDARD_SUBSCRIPTION;
|
|
2735
2791
|
}
|
|
2736
2792
|
return null;
|
|
2737
2793
|
}
|
|
@@ -2743,7 +2799,7 @@ function getSubscriptionRewardPeriodBounds(now = /* @__PURE__ */ new Date()) {
|
|
|
2743
2799
|
|
|
2744
2800
|
// src/service/affiliate/awardAffiliateVendorSubscriptionRewards.ts
|
|
2745
2801
|
function isEligibleVendorResource(resource) {
|
|
2746
|
-
return resource.resourceType ===
|
|
2802
|
+
return resource.resourceType === import_cluemart_shared24.EnumResourceType.VENDOR && resource.resourceActive === true && resource.resourceDeletedAt == null;
|
|
2747
2803
|
}
|
|
2748
2804
|
async function findAffiliatesWithActiveVendorReferrals() {
|
|
2749
2805
|
return await AffiliateModel.find({
|
|
@@ -2752,7 +2808,7 @@ async function findAffiliatesWithActiveVendorReferrals() {
|
|
|
2752
2808
|
$elemMatch: {
|
|
2753
2809
|
resourceActive: true,
|
|
2754
2810
|
resourceDeletedAt: null,
|
|
2755
|
-
resourceType:
|
|
2811
|
+
resourceType: import_cluemart_shared24.EnumResourceType.VENDOR
|
|
2756
2812
|
}
|
|
2757
2813
|
},
|
|
2758
2814
|
deletedAt: null
|
|
@@ -2786,11 +2842,11 @@ async function notifyAffiliateOwnerOfSubscriptionReward({
|
|
|
2786
2842
|
data: {
|
|
2787
2843
|
resourceId: String(affiliateId),
|
|
2788
2844
|
resourceName: resourceNames.join(", "),
|
|
2789
|
-
resourceType:
|
|
2845
|
+
resourceType: import_cluemart_shared24.EnumNotificationResourceType.AFFILIATE_REWARD_RECEIVED
|
|
2790
2846
|
},
|
|
2791
2847
|
message,
|
|
2792
2848
|
title: "Affiliate points earned",
|
|
2793
|
-
type:
|
|
2849
|
+
type: import_cluemart_shared24.EnumNotificationType.SYSTEM,
|
|
2794
2850
|
userIds: [affiliateOwnerUserId]
|
|
2795
2851
|
};
|
|
2796
2852
|
try {
|
|
@@ -2819,7 +2875,7 @@ async function tryAwardSubscriptionReward({
|
|
|
2819
2875
|
resourceActive: true,
|
|
2820
2876
|
resourceDeletedAt: null,
|
|
2821
2877
|
resourceId: resource.resourceId,
|
|
2822
|
-
resourceType:
|
|
2878
|
+
resourceType: import_cluemart_shared24.EnumResourceType.VENDOR,
|
|
2823
2879
|
rewards: {
|
|
2824
2880
|
$not: {
|
|
2825
2881
|
$elemMatch: {
|
|
@@ -2940,7 +2996,7 @@ function normalizeAffiliatePromoCodes(promoCodes) {
|
|
|
2940
2996
|
}
|
|
2941
2997
|
|
|
2942
2998
|
// src/service/database.ts
|
|
2943
|
-
var
|
|
2999
|
+
var import_mongoose37 = __toESM(require("mongoose"));
|
|
2944
3000
|
var connectToDatabase = async ({
|
|
2945
3001
|
appName,
|
|
2946
3002
|
dbName,
|
|
@@ -2953,7 +3009,7 @@ var connectToDatabase = async ({
|
|
|
2953
3009
|
// Fallback to MongoDB Atlas connection string
|
|
2954
3010
|
`mongodb+srv://${dbUser}:${dbPassword}@${dbName}.mongodb.net/?retryWrites=true&w=majority&appName=${appName}`
|
|
2955
3011
|
);
|
|
2956
|
-
await
|
|
3012
|
+
await import_mongoose37.default.connect(mongoUri);
|
|
2957
3013
|
const connectionType = mongodbUri ? "Local MongoDB" : "MongoDB Atlas";
|
|
2958
3014
|
console.log(
|
|
2959
3015
|
`${connectionType} connected from server/src/service/database.ts`
|
|
@@ -2966,7 +3022,7 @@ var connectToDatabase = async ({
|
|
|
2966
3022
|
|
|
2967
3023
|
// src/types/index.ts
|
|
2968
3024
|
var import_express = __toESM(require("express"));
|
|
2969
|
-
var
|
|
3025
|
+
var import_mongoose38 = __toESM(require("mongoose"));
|
|
2970
3026
|
|
|
2971
3027
|
// src/service/notifyUsers.ts
|
|
2972
3028
|
async function publishNotificationEvents(userId, pubsub) {
|
|
@@ -3014,7 +3070,7 @@ async function notifyUsers({
|
|
|
3014
3070
|
}
|
|
3015
3071
|
|
|
3016
3072
|
// src/service/updateAdStatus.ts
|
|
3017
|
-
var
|
|
3073
|
+
var import_cluemart_shared25 = require("@timardex/cluemart-shared");
|
|
3018
3074
|
async function updateAdStatuses() {
|
|
3019
3075
|
const now = /* @__PURE__ */ new Date();
|
|
3020
3076
|
const invalidResult = await AdModel.updateMany(
|
|
@@ -3024,50 +3080,50 @@ async function updateAdStatuses() {
|
|
|
3024
3080
|
{ end: { $exists: false } },
|
|
3025
3081
|
{ $expr: { $gt: ["$start", "$end"] } }
|
|
3026
3082
|
],
|
|
3027
|
-
status: { $ne:
|
|
3083
|
+
status: { $ne: import_cluemart_shared25.EnumAdStatus.PAUSED }
|
|
3028
3084
|
},
|
|
3029
|
-
{ $set: { status:
|
|
3085
|
+
{ $set: { status: import_cluemart_shared25.EnumAdStatus.PAUSED } }
|
|
3030
3086
|
);
|
|
3031
3087
|
const expiredResult = await AdModel.updateMany(
|
|
3032
|
-
{ end: { $lte: now }, status: { $ne:
|
|
3033
|
-
{ $set: { status:
|
|
3088
|
+
{ end: { $lte: now }, status: { $ne: import_cluemart_shared25.EnumAdStatus.EXPIRED } },
|
|
3089
|
+
{ $set: { status: import_cluemart_shared25.EnumAdStatus.EXPIRED } }
|
|
3034
3090
|
);
|
|
3035
3091
|
const eligibleBooking = {
|
|
3036
3092
|
$or: [
|
|
3037
3093
|
{ bookingKind: { $exists: false } },
|
|
3038
3094
|
{ bookingKind: null },
|
|
3039
3095
|
{
|
|
3040
|
-
approvalStatus:
|
|
3041
|
-
bookingKind:
|
|
3096
|
+
approvalStatus: import_cluemart_shared25.EnumAdApprovalStatus.APPROVED,
|
|
3097
|
+
bookingKind: import_cluemart_shared25.EnumAdBookingSlotKind.RESERVED
|
|
3042
3098
|
},
|
|
3043
3099
|
{
|
|
3044
|
-
approvalStatus:
|
|
3045
|
-
bookingKind:
|
|
3046
|
-
paymentStatus:
|
|
3100
|
+
approvalStatus: import_cluemart_shared25.EnumAdApprovalStatus.APPROVED,
|
|
3101
|
+
bookingKind: import_cluemart_shared25.EnumAdBookingSlotKind.PAID,
|
|
3102
|
+
paymentStatus: import_cluemart_shared25.EnumAdPaymentStatus.PAID
|
|
3047
3103
|
}
|
|
3048
3104
|
]
|
|
3049
3105
|
};
|
|
3050
3106
|
const awaitingApprovalResult = await AdModel.updateMany(
|
|
3051
3107
|
{
|
|
3052
3108
|
$nor: eligibleBooking.$or,
|
|
3053
|
-
bookingKind: { $in: Object.values(
|
|
3109
|
+
bookingKind: { $in: Object.values(import_cluemart_shared25.EnumAdBookingSlotKind) },
|
|
3054
3110
|
end: { $gt: now },
|
|
3055
|
-
status:
|
|
3111
|
+
status: import_cluemart_shared25.EnumAdStatus.ACTIVE
|
|
3056
3112
|
},
|
|
3057
|
-
{ $set: { status:
|
|
3113
|
+
{ $set: { status: import_cluemart_shared25.EnumAdStatus.PAUSED } }
|
|
3058
3114
|
);
|
|
3059
3115
|
const activeResult = await AdModel.updateMany(
|
|
3060
3116
|
{
|
|
3061
3117
|
end: { $gt: now },
|
|
3062
3118
|
start: { $lte: now },
|
|
3063
|
-
status: { $ne:
|
|
3119
|
+
status: { $ne: import_cluemart_shared25.EnumAdStatus.ACTIVE },
|
|
3064
3120
|
...eligibleBooking
|
|
3065
3121
|
},
|
|
3066
|
-
{ $set: { status:
|
|
3122
|
+
{ $set: { status: import_cluemart_shared25.EnumAdStatus.ACTIVE } }
|
|
3067
3123
|
);
|
|
3068
3124
|
const pausedResult = await AdModel.updateMany(
|
|
3069
|
-
{ start: { $gt: now }, status: { $ne:
|
|
3070
|
-
{ $set: { status:
|
|
3125
|
+
{ start: { $gt: now }, status: { $ne: import_cluemart_shared25.EnumAdStatus.PAUSED } },
|
|
3126
|
+
{ $set: { status: import_cluemart_shared25.EnumAdStatus.PAUSED } }
|
|
3071
3127
|
);
|
|
3072
3128
|
console.log(
|
|
3073
3129
|
`\u2705 Ad statuses updated: invalid=${invalidResult.modifiedCount}, expired=${expiredResult.modifiedCount}, awaitingApproval=${awaitingApprovalResult.modifiedCount}, active=${activeResult.modifiedCount}, paused=${pausedResult.modifiedCount}`
|
|
@@ -3075,15 +3131,15 @@ async function updateAdStatuses() {
|
|
|
3075
3131
|
}
|
|
3076
3132
|
|
|
3077
3133
|
// src/service/objectIdToString.ts
|
|
3078
|
-
var
|
|
3134
|
+
var import_mongoose40 = __toESM(require("mongoose"));
|
|
3079
3135
|
function isValidObjectId(value) {
|
|
3080
|
-
return
|
|
3136
|
+
return import_mongoose40.default.Types.ObjectId.isValid(value);
|
|
3081
3137
|
}
|
|
3082
3138
|
function convertObjectIdsToStrings(obj) {
|
|
3083
3139
|
if (obj === null || obj === void 0) {
|
|
3084
3140
|
return obj;
|
|
3085
3141
|
}
|
|
3086
|
-
if (obj instanceof
|
|
3142
|
+
if (obj instanceof import_mongoose40.default.Types.ObjectId) {
|
|
3087
3143
|
return obj.toString();
|
|
3088
3144
|
}
|
|
3089
3145
|
if (obj instanceof Date) {
|
|
@@ -3103,16 +3159,19 @@ function convertObjectIdsToStrings(obj) {
|
|
|
3103
3159
|
}
|
|
3104
3160
|
|
|
3105
3161
|
// src/service/event/updateAllEventDateTimeStatuses.ts
|
|
3106
|
-
var
|
|
3107
|
-
var
|
|
3162
|
+
var import_cluemart_shared27 = require("@timardex/cluemart-shared");
|
|
3163
|
+
var import_dayjs3 = __toESM(require("dayjs"));
|
|
3108
3164
|
|
|
3109
3165
|
// src/service/event/archiveEndedEventDates.ts
|
|
3110
|
-
var
|
|
3166
|
+
var import_cluemart_shared26 = require("@timardex/cluemart-shared");
|
|
3167
|
+
var import_dayjs2 = __toESM(require("dayjs"));
|
|
3168
|
+
var import_customParseFormat = __toESM(require("dayjs/plugin/customParseFormat"));
|
|
3169
|
+
import_dayjs2.default.extend(import_customParseFormat.default);
|
|
3111
3170
|
var ARCHIVED_STATUSES = /* @__PURE__ */ new Set([
|
|
3112
|
-
|
|
3171
|
+
import_cluemart_shared26.EnumEventDateStatus.ENDED
|
|
3113
3172
|
]);
|
|
3114
3173
|
var DISCARDED_STATUSES = /* @__PURE__ */ new Set([
|
|
3115
|
-
|
|
3174
|
+
import_cluemart_shared26.EnumEventDateStatus.INVALID
|
|
3116
3175
|
]);
|
|
3117
3176
|
function splitEventDatesForArchive(dateTime) {
|
|
3118
3177
|
return {
|
|
@@ -3134,6 +3193,17 @@ function dedupeArchivedSlotsByStartDateTime(slots) {
|
|
|
3134
3193
|
return true;
|
|
3135
3194
|
});
|
|
3136
3195
|
}
|
|
3196
|
+
function isPastCanceledEventDate(slot, now) {
|
|
3197
|
+
if (slot.dateStatus !== import_cluemart_shared26.EnumEventDateStatus.CANCELED) {
|
|
3198
|
+
return false;
|
|
3199
|
+
}
|
|
3200
|
+
const endDateTime = (0, import_dayjs2.default)(
|
|
3201
|
+
`${slot.endDate} ${slot.endTime}`,
|
|
3202
|
+
`${import_cluemart_shared26.dateFormat} ${import_cluemart_shared26.timeFormat}`,
|
|
3203
|
+
true
|
|
3204
|
+
);
|
|
3205
|
+
return endDateTime.isValid() && endDateTime.isBefore(now);
|
|
3206
|
+
}
|
|
3137
3207
|
async function persistArchivedEventDates(eventId, slots) {
|
|
3138
3208
|
if (slots.length === 0) {
|
|
3139
3209
|
return;
|
|
@@ -3175,7 +3245,7 @@ async function updateModelDateTimeStatuses(model, now) {
|
|
|
3175
3245
|
try {
|
|
3176
3246
|
for await (const doc of cursor) {
|
|
3177
3247
|
const dateTime = doc.dateTime.map(
|
|
3178
|
-
(slot) => (0,
|
|
3248
|
+
(slot) => (0, import_cluemart_shared27.updateSingleDateTimeStatus)(slot, now)
|
|
3179
3249
|
);
|
|
3180
3250
|
if (!hasDateTimeStatusChanges(doc.dateTime, dateTime)) {
|
|
3181
3251
|
continue;
|
|
@@ -3198,7 +3268,11 @@ async function updateModelDateTimeStatuses(model, now) {
|
|
|
3198
3268
|
}
|
|
3199
3269
|
var ARCHIVABLE_EVENT_FILTER = {
|
|
3200
3270
|
"dateTime.dateStatus": {
|
|
3201
|
-
$in: [
|
|
3271
|
+
$in: [
|
|
3272
|
+
import_cluemart_shared27.EnumEventDateStatus.ENDED,
|
|
3273
|
+
import_cluemart_shared27.EnumEventDateStatus.INVALID,
|
|
3274
|
+
import_cluemart_shared27.EnumEventDateStatus.CANCELED
|
|
3275
|
+
]
|
|
3202
3276
|
},
|
|
3203
3277
|
deletedAt: null
|
|
3204
3278
|
};
|
|
@@ -3213,17 +3287,22 @@ async function archiveEndedAndDiscardInvalidEventDates(now) {
|
|
|
3213
3287
|
archiveOps = [];
|
|
3214
3288
|
}
|
|
3215
3289
|
if (eventOps.length) {
|
|
3216
|
-
await EventModel.bulkWrite(
|
|
3290
|
+
await EventModel.bulkWrite(
|
|
3291
|
+
eventOps
|
|
3292
|
+
);
|
|
3217
3293
|
eventOps = [];
|
|
3218
3294
|
}
|
|
3219
3295
|
};
|
|
3220
3296
|
try {
|
|
3221
3297
|
for await (const doc of cursor) {
|
|
3222
3298
|
const updated = doc.dateTime.map(
|
|
3223
|
-
(slot) => (0,
|
|
3299
|
+
(slot) => (0, import_cluemart_shared27.updateSingleDateTimeStatus)(slot, now)
|
|
3224
3300
|
);
|
|
3225
3301
|
const { archive, discard } = splitEventDatesForArchive(updated);
|
|
3226
|
-
|
|
3302
|
+
const pastCanceled = updated.filter(
|
|
3303
|
+
(slot) => isPastCanceledEventDate(slot, now)
|
|
3304
|
+
);
|
|
3305
|
+
if (archive.length === 0 && discard.length === 0 && pastCanceled.length === 0) {
|
|
3227
3306
|
continue;
|
|
3228
3307
|
}
|
|
3229
3308
|
if (archive.length > 0) {
|
|
@@ -3237,16 +3316,27 @@ async function archiveEndedAndDiscardInvalidEventDates(now) {
|
|
|
3237
3316
|
});
|
|
3238
3317
|
archivedCount += uniqueArchive.length;
|
|
3239
3318
|
}
|
|
3319
|
+
const pullConditions = [];
|
|
3320
|
+
if (archive.length > 0 || discard.length > 0) {
|
|
3321
|
+
pullConditions.push({
|
|
3322
|
+
dateStatus: {
|
|
3323
|
+
$in: [import_cluemart_shared27.EnumEventDateStatus.ENDED, import_cluemart_shared27.EnumEventDateStatus.INVALID]
|
|
3324
|
+
}
|
|
3325
|
+
});
|
|
3326
|
+
}
|
|
3327
|
+
for (const slot of pastCanceled) {
|
|
3328
|
+
pullConditions.push({
|
|
3329
|
+
dateStatus: import_cluemart_shared27.EnumEventDateStatus.CANCELED,
|
|
3330
|
+
startDate: slot.startDate,
|
|
3331
|
+
startTime: slot.startTime
|
|
3332
|
+
});
|
|
3333
|
+
}
|
|
3240
3334
|
eventOps.push({
|
|
3241
3335
|
updateOne: {
|
|
3242
3336
|
filter: { _id: doc._id },
|
|
3243
3337
|
update: {
|
|
3244
3338
|
$pull: {
|
|
3245
|
-
dateTime: {
|
|
3246
|
-
dateStatus: {
|
|
3247
|
-
$in: [import_cluemart_shared26.EnumEventDateStatus.ENDED, import_cluemart_shared26.EnumEventDateStatus.INVALID]
|
|
3248
|
-
}
|
|
3249
|
-
}
|
|
3339
|
+
dateTime: { $or: pullConditions }
|
|
3250
3340
|
}
|
|
3251
3341
|
}
|
|
3252
3342
|
}
|
|
@@ -3278,9 +3368,9 @@ async function cleanEventInfoDates(now) {
|
|
|
3278
3368
|
try {
|
|
3279
3369
|
for await (const doc of cursor) {
|
|
3280
3370
|
const updated = doc.dateTime.map(
|
|
3281
|
-
(slot) => (0,
|
|
3371
|
+
(slot) => (0, import_cluemart_shared27.updateSingleDateTimeStatus)(slot, now)
|
|
3282
3372
|
);
|
|
3283
|
-
const kept = (0,
|
|
3373
|
+
const kept = (0, import_cluemart_shared27.filterDatesByFutureStatus)(updated);
|
|
3284
3374
|
if (kept.length === updated.length) {
|
|
3285
3375
|
continue;
|
|
3286
3376
|
}
|
|
@@ -3302,7 +3392,7 @@ async function cleanEventInfoDates(now) {
|
|
|
3302
3392
|
return removedCount;
|
|
3303
3393
|
}
|
|
3304
3394
|
async function updateAllEventDateTimeStatuses() {
|
|
3305
|
-
const now = (0,
|
|
3395
|
+
const now = (0, import_dayjs3.default)();
|
|
3306
3396
|
const [eventCount, marketCount] = await Promise.all([
|
|
3307
3397
|
updateModelDateTimeStatuses(EventModel, now),
|
|
3308
3398
|
updateModelDateTimeStatuses(
|
|
@@ -3326,7 +3416,7 @@ async function updateAllEventDateTimeStatuses() {
|
|
|
3326
3416
|
}
|
|
3327
3417
|
|
|
3328
3418
|
// src/service/index.ts
|
|
3329
|
-
var
|
|
3419
|
+
var import_cluemart_shared35 = require("@timardex/cluemart-shared");
|
|
3330
3420
|
|
|
3331
3421
|
// src/service/event/findEventOrImportedMarketById.ts
|
|
3332
3422
|
async function findEventOrImportedMarketById(resourceId) {
|
|
@@ -3342,7 +3432,7 @@ async function findEventOrImportedMarketById(resourceId) {
|
|
|
3342
3432
|
}
|
|
3343
3433
|
|
|
3344
3434
|
// src/service/relations.ts
|
|
3345
|
-
var
|
|
3435
|
+
var import_cluemart_shared28 = require("@timardex/cluemart-shared");
|
|
3346
3436
|
function didRemoveAnyEventDates(previousDateTime, nextDateTime) {
|
|
3347
3437
|
if (!previousDateTime?.length) {
|
|
3348
3438
|
return false;
|
|
@@ -3360,24 +3450,24 @@ function updateRelationDatesToUnavailable(relationDates, eventDateTime) {
|
|
|
3360
3450
|
) ?? false;
|
|
3361
3451
|
return {
|
|
3362
3452
|
...relationDate,
|
|
3363
|
-
status: existsInEvent ? relationDate.status :
|
|
3453
|
+
status: existsInEvent ? relationDate.status : import_cluemart_shared28.EnumInviteStatus.UNAVAILABLE
|
|
3364
3454
|
};
|
|
3365
3455
|
});
|
|
3366
3456
|
}
|
|
3367
3457
|
|
|
3368
3458
|
// src/service/license/compliance/ensureUserLicenseCompliance.ts
|
|
3369
|
-
var
|
|
3459
|
+
var import_dayjs7 = __toESM(require("dayjs"));
|
|
3370
3460
|
|
|
3371
3461
|
// src/service/license/compliance/utils.ts
|
|
3372
|
-
var
|
|
3373
|
-
var
|
|
3462
|
+
var import_cluemart_shared33 = require("@timardex/cluemart-shared");
|
|
3463
|
+
var import_dayjs6 = __toESM(require("dayjs"));
|
|
3374
3464
|
|
|
3375
3465
|
// src/service/license/compliance/event.ts
|
|
3376
|
-
var
|
|
3466
|
+
var import_cluemart_shared29 = require("@timardex/cluemart-shared");
|
|
3377
3467
|
var eventLicences = [
|
|
3378
|
-
|
|
3379
|
-
|
|
3380
|
-
|
|
3468
|
+
import_cluemart_shared29.EnumUserLicence.STANDARD_EVENT,
|
|
3469
|
+
import_cluemart_shared29.EnumUserLicence.PRO_EVENT,
|
|
3470
|
+
import_cluemart_shared29.EnumUserLicence.PRO_PLUS_EVENT
|
|
3381
3471
|
];
|
|
3382
3472
|
async function handleEventLicenceCompliance(user, now) {
|
|
3383
3473
|
if (!user.licences || !user.events?.length) {
|
|
@@ -3589,9 +3679,9 @@ function buildLicenceExpiryPipeline(params) {
|
|
|
3589
3679
|
}
|
|
3590
3680
|
|
|
3591
3681
|
// src/service/license/compliance/partner.ts
|
|
3592
|
-
var
|
|
3682
|
+
var import_cluemart_shared30 = require("@timardex/cluemart-shared");
|
|
3593
3683
|
var partnerLicences = [
|
|
3594
|
-
|
|
3684
|
+
import_cluemart_shared30.EnumUserLicence.STANDARD_PARTNER
|
|
3595
3685
|
];
|
|
3596
3686
|
async function handlePartnerLicenceCompliance(user, now) {
|
|
3597
3687
|
if (!user.licences || !user.partner) {
|
|
@@ -3601,12 +3691,12 @@ async function handlePartnerLicenceCompliance(user, now) {
|
|
|
3601
3691
|
}
|
|
3602
3692
|
|
|
3603
3693
|
// src/service/license/compliance/vendor.ts
|
|
3604
|
-
var
|
|
3605
|
-
var
|
|
3694
|
+
var import_cluemart_shared32 = require("@timardex/cluemart-shared");
|
|
3695
|
+
var import_dayjs5 = __toESM(require("dayjs"));
|
|
3606
3696
|
|
|
3607
3697
|
// src/service/license/models.ts
|
|
3608
|
-
var
|
|
3609
|
-
var
|
|
3698
|
+
var import_cluemart_shared31 = require("@timardex/cluemart-shared");
|
|
3699
|
+
var import_dayjs4 = __toESM(require("dayjs"));
|
|
3610
3700
|
var import_graphql = require("graphql");
|
|
3611
3701
|
var LicenceCategory = /* @__PURE__ */ ((LicenceCategory2) => {
|
|
3612
3702
|
LicenceCategory2["EVENT"] = "event";
|
|
@@ -3617,31 +3707,31 @@ var LicenceCategory = /* @__PURE__ */ ((LicenceCategory2) => {
|
|
|
3617
3707
|
return LicenceCategory2;
|
|
3618
3708
|
})(LicenceCategory || {});
|
|
3619
3709
|
var licenceCategoryMapping = {
|
|
3620
|
-
[
|
|
3621
|
-
[
|
|
3622
|
-
[
|
|
3623
|
-
[
|
|
3624
|
-
[
|
|
3625
|
-
[
|
|
3626
|
-
[
|
|
3627
|
-
[
|
|
3628
|
-
[
|
|
3710
|
+
[import_cluemart_shared31.EnumUserLicence.PRO_EVENT]: "event" /* EVENT */,
|
|
3711
|
+
[import_cluemart_shared31.EnumUserLicence.PRO_PLUS_EVENT]: "event" /* EVENT */,
|
|
3712
|
+
[import_cluemart_shared31.EnumUserLicence.PRO_PLUS_VENDOR]: "vendor" /* VENDOR */,
|
|
3713
|
+
[import_cluemart_shared31.EnumUserLicence.PRO_VENDOR]: "vendor" /* VENDOR */,
|
|
3714
|
+
[import_cluemart_shared31.EnumUserLicence.STANDARD_EVENT]: "event" /* EVENT */,
|
|
3715
|
+
[import_cluemart_shared31.EnumUserLicence.STANDARD_PARTNER]: "partner" /* PARTNER */,
|
|
3716
|
+
[import_cluemart_shared31.EnumUserLicence.STANDARD_VENDOR]: "vendor" /* VENDOR */,
|
|
3717
|
+
[import_cluemart_shared31.EnumUserLicence.STANDARD_AFFILIATE]: "affiliate" /* AFFILIATE */,
|
|
3718
|
+
[import_cluemart_shared31.EnumUserLicence.STANDARD_SCHOOL]: "school" /* SCHOOL */
|
|
3629
3719
|
};
|
|
3630
3720
|
var licencePriority = {
|
|
3631
|
-
[
|
|
3632
|
-
[
|
|
3633
|
-
[
|
|
3634
|
-
[
|
|
3635
|
-
[
|
|
3636
|
-
[
|
|
3637
|
-
[
|
|
3638
|
-
[
|
|
3639
|
-
[
|
|
3721
|
+
[import_cluemart_shared31.EnumUserLicence.PRO_PLUS_EVENT]: 3,
|
|
3722
|
+
[import_cluemart_shared31.EnumUserLicence.PRO_EVENT]: 2,
|
|
3723
|
+
[import_cluemart_shared31.EnumUserLicence.STANDARD_EVENT]: 1,
|
|
3724
|
+
[import_cluemart_shared31.EnumUserLicence.PRO_PLUS_VENDOR]: 3,
|
|
3725
|
+
[import_cluemart_shared31.EnumUserLicence.PRO_VENDOR]: 2,
|
|
3726
|
+
[import_cluemart_shared31.EnumUserLicence.STANDARD_VENDOR]: 1,
|
|
3727
|
+
[import_cluemart_shared31.EnumUserLicence.STANDARD_PARTNER]: 1,
|
|
3728
|
+
[import_cluemart_shared31.EnumUserLicence.STANDARD_AFFILIATE]: 1,
|
|
3729
|
+
[import_cluemart_shared31.EnumUserLicence.STANDARD_SCHOOL]: 1
|
|
3640
3730
|
};
|
|
3641
3731
|
var standardLicences = [
|
|
3642
|
-
|
|
3643
|
-
|
|
3644
|
-
|
|
3732
|
+
import_cluemart_shared31.EnumUserLicence.STANDARD_VENDOR,
|
|
3733
|
+
import_cluemart_shared31.EnumUserLicence.STANDARD_EVENT,
|
|
3734
|
+
import_cluemart_shared31.EnumUserLicence.STANDARD_PARTNER
|
|
3645
3735
|
];
|
|
3646
3736
|
var standardLicenceSet = new Set(standardLicences);
|
|
3647
3737
|
function isStandardLicence(licence) {
|
|
@@ -3655,11 +3745,11 @@ var categoryRegexMapping = {
|
|
|
3655
3745
|
["school" /* SCHOOL */]: /_school$/
|
|
3656
3746
|
};
|
|
3657
3747
|
var categoryFallbackLicence = {
|
|
3658
|
-
["event" /* EVENT */]:
|
|
3659
|
-
["partner" /* PARTNER */]:
|
|
3660
|
-
["vendor" /* VENDOR */]:
|
|
3661
|
-
["affiliate" /* AFFILIATE */]:
|
|
3662
|
-
["school" /* SCHOOL */]:
|
|
3748
|
+
["event" /* EVENT */]: import_cluemart_shared31.EnumUserLicence.STANDARD_EVENT,
|
|
3749
|
+
["partner" /* PARTNER */]: import_cluemart_shared31.EnumUserLicence.STANDARD_PARTNER,
|
|
3750
|
+
["vendor" /* VENDOR */]: import_cluemart_shared31.EnumUserLicence.STANDARD_VENDOR,
|
|
3751
|
+
["affiliate" /* AFFILIATE */]: import_cluemart_shared31.EnumUserLicence.STANDARD_AFFILIATE,
|
|
3752
|
+
["school" /* SCHOOL */]: import_cluemart_shared31.EnumUserLicence.STANDARD_SCHOOL
|
|
3663
3753
|
};
|
|
3664
3754
|
var LicenceFilterInput = {
|
|
3665
3755
|
INPUT_USER_LICENCES: "$licences"
|
|
@@ -3687,13 +3777,13 @@ function getHighestLicenceForCategory(licences, category) {
|
|
|
3687
3777
|
return highestLicence;
|
|
3688
3778
|
}
|
|
3689
3779
|
function createLicenceObject(expiryDate, licenceType) {
|
|
3690
|
-
const today = (0,
|
|
3780
|
+
const today = (0, import_dayjs4.default)();
|
|
3691
3781
|
const expiryDateMapping = {
|
|
3692
|
-
[
|
|
3693
|
-
[
|
|
3694
|
-
[
|
|
3695
|
-
[
|
|
3696
|
-
[
|
|
3782
|
+
[import_cluemart_shared31.LicenceExpiryDate.ONE_YEAR]: today.add(1, "year").endOf("day").toDate(),
|
|
3783
|
+
[import_cluemart_shared31.LicenceExpiryDate.ONE_MONTH]: today.add(1, "month").endOf("day").toDate(),
|
|
3784
|
+
[import_cluemart_shared31.LicenceExpiryDate.TWO_MONTHS]: today.add(2, "month").endOf("day").toDate(),
|
|
3785
|
+
[import_cluemart_shared31.LicenceExpiryDate.THREE_MONTHS]: today.add(3, "month").endOf("day").toDate(),
|
|
3786
|
+
[import_cluemart_shared31.LicenceExpiryDate.SIX_MONTHS]: today.add(6, "month").endOf("day").toDate()
|
|
3697
3787
|
};
|
|
3698
3788
|
const licenceObject = {
|
|
3699
3789
|
expiryDate: expiryDateMapping[expiryDate],
|
|
@@ -3797,13 +3887,13 @@ async function checkOwnerHasLicence({
|
|
|
3797
3887
|
const owner = await UserModel.findById(userId);
|
|
3798
3888
|
if (!owner) throw new import_graphql.GraphQLError("Owner not found");
|
|
3799
3889
|
const categoryByResource = {
|
|
3800
|
-
[
|
|
3801
|
-
[
|
|
3802
|
-
[
|
|
3803
|
-
[
|
|
3804
|
-
[
|
|
3890
|
+
[import_cluemart_shared31.EnumResourceType.EVENT]: "event" /* EVENT */,
|
|
3891
|
+
[import_cluemart_shared31.EnumResourceType.PARTNER]: "partner" /* PARTNER */,
|
|
3892
|
+
[import_cluemart_shared31.EnumResourceType.VENDOR]: "vendor" /* VENDOR */,
|
|
3893
|
+
[import_cluemart_shared31.EnumResourceType.AFFILIATE]: "affiliate" /* AFFILIATE */,
|
|
3894
|
+
[import_cluemart_shared31.EnumResourceType.SCHOOL]: "school" /* SCHOOL */
|
|
3805
3895
|
};
|
|
3806
|
-
if (!(0,
|
|
3896
|
+
if (!(0, import_cluemart_shared31.isNonVisitorResourceType)(resourceType)) {
|
|
3807
3897
|
throw new import_graphql.GraphQLError(`Invalid resource type: ${resourceType}.`);
|
|
3808
3898
|
}
|
|
3809
3899
|
const requiredCategory = categoryByResource[resourceType];
|
|
@@ -3883,7 +3973,7 @@ async function applyVendorDowngrade(vendor, ownerUserId) {
|
|
|
3883
3973
|
return (result?.matchedCount ?? 0) > 0;
|
|
3884
3974
|
}
|
|
3885
3975
|
async function downgradeVendorProFeatures(userId, licenceType) {
|
|
3886
|
-
const isStandardVendor = licenceType ===
|
|
3976
|
+
const isStandardVendor = licenceType === import_cluemart_shared32.EnumUserLicence.STANDARD_VENDOR;
|
|
3887
3977
|
if (!isStandardVendor) {
|
|
3888
3978
|
return;
|
|
3889
3979
|
}
|
|
@@ -3930,7 +4020,7 @@ async function applyVendorRestore(vendor, ownerUserId) {
|
|
|
3930
4020
|
return (result?.matchedCount ?? 0) > 0;
|
|
3931
4021
|
}
|
|
3932
4022
|
async function restoreVendorProFeatures(userId, licenceType) {
|
|
3933
|
-
const isProVendor = licenceType ===
|
|
4023
|
+
const isProVendor = licenceType === import_cluemart_shared32.EnumUserLicence.PRO_VENDOR || licenceType === import_cluemart_shared32.EnumUserLicence.PRO_PLUS_VENDOR;
|
|
3934
4024
|
if (!isProVendor) {
|
|
3935
4025
|
return;
|
|
3936
4026
|
}
|
|
@@ -3950,21 +4040,21 @@ function isProtectedByCurrentStripeSubscription(user, licenceType, now) {
|
|
|
3950
4040
|
if (!stripe || stripe.currentPlan !== licenceType) {
|
|
3951
4041
|
return false;
|
|
3952
4042
|
}
|
|
3953
|
-
const gracePeriodEndsAt = stripe.paymentGracePeriodEndsAt ? (0,
|
|
3954
|
-
const hasActivePaymentGracePeriod = (stripe.status ===
|
|
4043
|
+
const gracePeriodEndsAt = stripe.paymentGracePeriodEndsAt ? (0, import_dayjs5.default)(stripe.paymentGracePeriodEndsAt) : null;
|
|
4044
|
+
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);
|
|
3955
4045
|
if (hasActivePaymentGracePeriod) {
|
|
3956
4046
|
return true;
|
|
3957
4047
|
}
|
|
3958
4048
|
if (!stripe.subscriptionId) {
|
|
3959
4049
|
return false;
|
|
3960
4050
|
}
|
|
3961
|
-
if (stripe.status !==
|
|
4051
|
+
if (stripe.status !== import_cluemart_shared32.EnumSubscriptionStatus.ACTIVE) {
|
|
3962
4052
|
return false;
|
|
3963
4053
|
}
|
|
3964
4054
|
if (!stripe.endDate) {
|
|
3965
4055
|
return false;
|
|
3966
4056
|
}
|
|
3967
|
-
const paidThrough = (0,
|
|
4057
|
+
const paidThrough = (0, import_dayjs5.default)(stripe.endDate);
|
|
3968
4058
|
return paidThrough.isValid() && paidThrough.isAfter(now);
|
|
3969
4059
|
}
|
|
3970
4060
|
async function handleVendorLicenceCompliance(user, now) {
|
|
@@ -3978,10 +4068,10 @@ async function handleVendorLicenceCompliance(user, now) {
|
|
|
3978
4068
|
return;
|
|
3979
4069
|
}
|
|
3980
4070
|
const proLicences = vendorLicencesOfUser.filter(
|
|
3981
|
-
(licence) => licence.licenceType !==
|
|
4071
|
+
(licence) => licence.licenceType !== import_cluemart_shared32.EnumUserLicence.STANDARD_VENDOR
|
|
3982
4072
|
);
|
|
3983
4073
|
const expiredProLicences = proLicences.filter(
|
|
3984
|
-
(licence) => !(0,
|
|
4074
|
+
(licence) => !(0, import_dayjs5.default)(licence.expiryDate).isAfter(now)
|
|
3985
4075
|
);
|
|
3986
4076
|
const stripeProtectedLicenceTypes = new Set(
|
|
3987
4077
|
expiredProLicences.filter(
|
|
@@ -3991,9 +4081,9 @@ async function handleVendorLicenceCompliance(user, now) {
|
|
|
3991
4081
|
const expiredProLicence = expiredProLicences.some(
|
|
3992
4082
|
(licence) => !stripeProtectedLicenceTypes.has(licence.licenceType)
|
|
3993
4083
|
);
|
|
3994
|
-
const hasValidProLicence = stripeProtectedLicenceTypes.size > 0 || hasValidLicence(proLicences,
|
|
4084
|
+
const hasValidProLicence = stripeProtectedLicenceTypes.size > 0 || hasValidLicence(proLicences, import_cluemart_shared32.vendorLicences, now);
|
|
3995
4085
|
const hasExpiredVendorLicence = vendorLicencesOfUser.some(
|
|
3996
|
-
(licence) => !(0,
|
|
4086
|
+
(licence) => !(0, import_dayjs5.default)(licence.expiryDate).isAfter(now) && !stripeProtectedLicenceTypes.has(licence.licenceType)
|
|
3997
4087
|
);
|
|
3998
4088
|
if (!hasExpiredVendorLicence) {
|
|
3999
4089
|
return;
|
|
@@ -4007,7 +4097,7 @@ async function handleVendorLicenceCompliance(user, now) {
|
|
|
4007
4097
|
"owner.userId": user._id
|
|
4008
4098
|
}).lean().exec();
|
|
4009
4099
|
}
|
|
4010
|
-
const licencesToSync =
|
|
4100
|
+
const licencesToSync = import_cluemart_shared32.vendorLicences.filter(
|
|
4011
4101
|
(licenceType) => !stripeProtectedLicenceTypes.has(licenceType)
|
|
4012
4102
|
);
|
|
4013
4103
|
await syncUserLicencesAfterExpiry(user._id, licencesToSync, now, "downgrade");
|
|
@@ -4022,11 +4112,11 @@ async function handleVendorLicenceCompliance(user, now) {
|
|
|
4022
4112
|
data: {
|
|
4023
4113
|
resourceId: String(vendor._id),
|
|
4024
4114
|
resourceName: vendor.name,
|
|
4025
|
-
resourceType:
|
|
4115
|
+
resourceType: import_cluemart_shared32.EnumNotificationResourceType.DOWNGRADED_VENDOR
|
|
4026
4116
|
},
|
|
4027
4117
|
message: `Your Vendor licence has been downgraded due to licence expiration.`,
|
|
4028
4118
|
title: `Vendor Licence Downgraded`,
|
|
4029
|
-
type:
|
|
4119
|
+
type: import_cluemart_shared32.EnumNotificationType.SYSTEM,
|
|
4030
4120
|
userIds: [user._id]
|
|
4031
4121
|
};
|
|
4032
4122
|
await sendDeactivationNotification(payload, user._id, vendor.name, "vendor");
|
|
@@ -4047,9 +4137,9 @@ async function vendorOwnerHasProLicence(vendorId) {
|
|
|
4047
4137
|
if (!owner) {
|
|
4048
4138
|
return false;
|
|
4049
4139
|
}
|
|
4050
|
-
const now = (0,
|
|
4140
|
+
const now = (0, import_dayjs5.default)();
|
|
4051
4141
|
const effectiveVendorLicences = owner.licences?.filter(
|
|
4052
|
-
(licence) => licence?.licenceType && ((0,
|
|
4142
|
+
(licence) => licence?.licenceType && ((0, import_dayjs5.default)(licence.expiryDate).isAfter(now) || isProtectedByCurrentStripeSubscription(
|
|
4053
4143
|
owner,
|
|
4054
4144
|
licence.licenceType,
|
|
4055
4145
|
now
|
|
@@ -4059,7 +4149,7 @@ async function vendorOwnerHasProLicence(vendorId) {
|
|
|
4059
4149
|
effectiveVendorLicences,
|
|
4060
4150
|
"vendor" /* VENDOR */
|
|
4061
4151
|
);
|
|
4062
|
-
return highestVendorLicence !== null && licencePriority[highestVendorLicence] >= licencePriority[
|
|
4152
|
+
return highestVendorLicence !== null && licencePriority[highestVendorLicence] >= licencePriority[import_cluemart_shared32.EnumUserLicence.PRO_VENDOR];
|
|
4063
4153
|
}
|
|
4064
4154
|
|
|
4065
4155
|
// src/service/license/compliance/utils.ts
|
|
@@ -4069,12 +4159,12 @@ async function syncUserLicencesAfterExpiry(userId, licenceTypes, now, mode = "do
|
|
|
4069
4159
|
const pipeline = buildLicenceExpiryPipeline({
|
|
4070
4160
|
downgradeBranches: [
|
|
4071
4161
|
{
|
|
4072
|
-
case:
|
|
4073
|
-
then:
|
|
4162
|
+
case: import_cluemart_shared33.EnumUserLicence.PRO_PLUS_VENDOR,
|
|
4163
|
+
then: import_cluemart_shared33.EnumUserLicence.STANDARD_VENDOR
|
|
4074
4164
|
},
|
|
4075
4165
|
{
|
|
4076
|
-
case:
|
|
4077
|
-
then:
|
|
4166
|
+
case: import_cluemart_shared33.EnumUserLicence.PRO_VENDOR,
|
|
4167
|
+
then: import_cluemart_shared33.EnumUserLicence.STANDARD_VENDOR
|
|
4078
4168
|
}
|
|
4079
4169
|
],
|
|
4080
4170
|
licenceTypes,
|
|
@@ -4086,7 +4176,7 @@ async function syncUserLicencesAfterExpiry(userId, licenceTypes, now, mode = "do
|
|
|
4086
4176
|
}
|
|
4087
4177
|
function hasValidLicence(licences, licenceTypes, now) {
|
|
4088
4178
|
return licences.some(
|
|
4089
|
-
(licence) => licenceTypes.includes(licence.licenceType) && (0,
|
|
4179
|
+
(licence) => licenceTypes.includes(licence.licenceType) && (0, import_dayjs6.default)(licence.expiryDate).isAfter(now)
|
|
4090
4180
|
);
|
|
4091
4181
|
}
|
|
4092
4182
|
async function sendDeactivationNotification(payload, userId, resourceName, resourceType) {
|
|
@@ -4113,7 +4203,7 @@ async function processUserCompliance(user, now) {
|
|
|
4113
4203
|
}
|
|
4114
4204
|
|
|
4115
4205
|
// src/service/license/compliance/ensureUserLicenseCompliance.ts
|
|
4116
|
-
async function ensureUserLicenseComplianceForUser(userId, now = (0,
|
|
4206
|
+
async function ensureUserLicenseComplianceForUser(userId, now = (0, import_dayjs7.default)()) {
|
|
4117
4207
|
const user = await UserModel.findById(userId);
|
|
4118
4208
|
if (!user) {
|
|
4119
4209
|
return;
|
|
@@ -4121,7 +4211,7 @@ async function ensureUserLicenseComplianceForUser(userId, now = (0, import_dayjs
|
|
|
4121
4211
|
await processUserCompliance(user, now);
|
|
4122
4212
|
}
|
|
4123
4213
|
async function ensureUserLicenseCompliance() {
|
|
4124
|
-
const now = (0,
|
|
4214
|
+
const now = (0, import_dayjs7.default)();
|
|
4125
4215
|
console.log(`\u{1F50D} Checking license compliance at ${now.format()}`);
|
|
4126
4216
|
const nowDate = now.toDate();
|
|
4127
4217
|
const users = await UserModel.find({
|
|
@@ -4196,16 +4286,16 @@ async function getPartnerResourceInfo(userId, partnerId) {
|
|
|
4196
4286
|
}
|
|
4197
4287
|
|
|
4198
4288
|
// src/service/license/reminder/remindUsersAboutLicenseExpiration.ts
|
|
4199
|
-
var
|
|
4289
|
+
var import_dayjs9 = __toESM(require("dayjs"));
|
|
4200
4290
|
|
|
4201
4291
|
// src/service/license/reminder/reminderWindow.ts
|
|
4202
4292
|
var REMINDER_WINDOW_MIN_HOURS = 6.5 * 24;
|
|
4203
4293
|
var REMINDER_WINDOW_MAX_HOURS = 7.5 * 24;
|
|
4204
4294
|
|
|
4205
4295
|
// src/service/license/reminder/utils.ts
|
|
4206
|
-
var
|
|
4296
|
+
var import_cluemart_shared34 = require("@timardex/cluemart-shared");
|
|
4207
4297
|
var import_utils8 = require("@timardex/cluemart-shared/utils");
|
|
4208
|
-
var
|
|
4298
|
+
var import_dayjs8 = __toESM(require("dayjs"));
|
|
4209
4299
|
|
|
4210
4300
|
// src/service/license/reminder/vendor.ts
|
|
4211
4301
|
async function getVendorResourceInfo(userId, vendorId) {
|
|
@@ -4264,33 +4354,33 @@ async function checkAndCreateNotification(payload) {
|
|
|
4264
4354
|
}
|
|
4265
4355
|
}
|
|
4266
4356
|
function isLicenseExpiringIn7Days(expiryDate, now) {
|
|
4267
|
-
const expiry = (0,
|
|
4357
|
+
const expiry = (0, import_dayjs8.default)(expiryDate);
|
|
4268
4358
|
const hoursUntilExpiry = expiry.diff(now, "hour", true);
|
|
4269
4359
|
return hoursUntilExpiry >= REMINDER_WINDOW_MIN_HOURS && hoursUntilExpiry <= REMINDER_WINDOW_MAX_HOURS;
|
|
4270
4360
|
}
|
|
4271
4361
|
function getLicenseName(licenceType) {
|
|
4272
|
-
return
|
|
4362
|
+
return import_cluemart_shared34.licenseNiceNames[licenceType] || licenceType;
|
|
4273
4363
|
}
|
|
4274
4364
|
function getNotificationTypes(isVendorLicense, isPartnerLicense) {
|
|
4275
4365
|
if (isVendorLicense) {
|
|
4276
4366
|
return {
|
|
4277
|
-
notificationType:
|
|
4278
|
-
resourceType:
|
|
4367
|
+
notificationType: import_cluemart_shared34.EnumNotificationType.SYSTEM,
|
|
4368
|
+
resourceType: import_cluemart_shared34.EnumNotificationResourceType.EXPIRATION_REMINDER_VENDOR
|
|
4279
4369
|
};
|
|
4280
4370
|
}
|
|
4281
4371
|
if (isPartnerLicense) {
|
|
4282
4372
|
return {
|
|
4283
|
-
notificationType:
|
|
4284
|
-
resourceType:
|
|
4373
|
+
notificationType: import_cluemart_shared34.EnumNotificationType.SYSTEM,
|
|
4374
|
+
resourceType: import_cluemart_shared34.EnumNotificationResourceType.EXPIRATION_REMINDER_PARTNER
|
|
4285
4375
|
};
|
|
4286
4376
|
}
|
|
4287
4377
|
return {
|
|
4288
|
-
notificationType:
|
|
4289
|
-
resourceType:
|
|
4378
|
+
notificationType: import_cluemart_shared34.EnumNotificationType.SYSTEM,
|
|
4379
|
+
resourceType: import_cluemart_shared34.EnumNotificationResourceType.EXPIRATION_REMINDER_EVENT
|
|
4290
4380
|
};
|
|
4291
4381
|
}
|
|
4292
4382
|
async function getLicenseResourceInfo(user, licence) {
|
|
4293
|
-
const isVendorLicense =
|
|
4383
|
+
const isVendorLicense = import_cluemart_shared34.vendorLicences.includes(licence.licenceType);
|
|
4294
4384
|
const isPartnerLicense = partnerLicences.includes(licence.licenceType);
|
|
4295
4385
|
const licenceName = getLicenseName(licence.licenceType);
|
|
4296
4386
|
const { notificationType, resourceType } = getNotificationTypes(
|
|
@@ -4338,11 +4428,11 @@ async function getLicenseResourceInfo(user, licence) {
|
|
|
4338
4428
|
};
|
|
4339
4429
|
}
|
|
4340
4430
|
function getLicenceExpiryMode(licenceType) {
|
|
4341
|
-
return licenceType ===
|
|
4431
|
+
return licenceType === import_cluemart_shared34.EnumUserLicence.PRO_VENDOR || licenceType === import_cluemart_shared34.EnumUserLicence.PRO_PLUS_VENDOR ? "downgrade" : "extend";
|
|
4342
4432
|
}
|
|
4343
4433
|
async function sendLicenseReminder(user, licence) {
|
|
4344
4434
|
const licenceName = getLicenseName(licence.licenceType);
|
|
4345
|
-
const expiryDate = (0,
|
|
4435
|
+
const expiryDate = (0, import_dayjs8.default)(licence.expiryDate).format(import_cluemart_shared34.dateFormat);
|
|
4346
4436
|
const userId = String(user._id);
|
|
4347
4437
|
const resourceInfo = await getLicenseResourceInfo(user, licence);
|
|
4348
4438
|
if (!resourceInfo) {
|
|
@@ -4374,7 +4464,7 @@ async function sendLicenseReminder(user, licence) {
|
|
|
4374
4464
|
console.log(`\u2705 Sent 7-day reminder to user ${userId} for ${licenceName}`);
|
|
4375
4465
|
}
|
|
4376
4466
|
async function processLicenseReminder(licence, now) {
|
|
4377
|
-
if ((0,
|
|
4467
|
+
if ((0, import_dayjs8.default)(licence.expiryDate).isBefore(now)) {
|
|
4378
4468
|
return false;
|
|
4379
4469
|
}
|
|
4380
4470
|
if (!isLicenseExpiringIn7Days(licence.expiryDate, now)) {
|
|
@@ -4428,7 +4518,7 @@ async function processUserLicenseReminders(user, now) {
|
|
|
4428
4518
|
|
|
4429
4519
|
// src/service/license/reminder/remindUsersAboutLicenseExpiration.ts
|
|
4430
4520
|
async function remindUsersAboutLicenseExpiration() {
|
|
4431
|
-
const now = (0,
|
|
4521
|
+
const now = (0, import_dayjs9.default)();
|
|
4432
4522
|
console.log(`\u{1F50D} Checking for licenses expiring in 7 days at ${now.format()}`);
|
|
4433
4523
|
const minExpiryDate = now.add(REMINDER_WINDOW_MIN_HOURS, "hour").toDate();
|
|
4434
4524
|
const maxExpiryDate = now.add(REMINDER_WINDOW_MAX_HOURS, "hour").toDate();
|