@timardex/cluemart-server-shared 1.1.35 → 1.1.36
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-gqV1-654.d.ts → Affiliate-CZKOOaz_.d.ts} +62 -2
- package/dist/{Affiliate-B76iZ3fE.d.mts → Affiliate-xCVhO2Cy.d.mts} +62 -2
- package/dist/{chunk-ZVXL6B3M.mjs → chunk-DBGVZNUX.mjs} +53 -3000
- package/dist/chunk-DBGVZNUX.mjs.map +1 -0
- package/dist/index.cjs +1988 -3932
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.mts +242 -8
- package/dist/index.d.ts +242 -8
- package/dist/index.mjs +1452 -3429
- package/dist/index.mjs.map +1 -1
- package/dist/mongoose/index.cjs +10 -3000
- package/dist/mongoose/index.cjs.map +1 -1
- package/dist/mongoose/index.d.mts +4 -64
- package/dist/mongoose/index.d.ts +4 -64
- package/dist/mongoose/index.mjs +1 -1
- package/dist/service/index.cjs +1993 -3937
- package/dist/service/index.cjs.map +1 -1
- package/dist/service/index.d.mts +243 -9
- package/dist/service/index.d.ts +243 -9
- package/dist/service/index.mjs +1018 -43
- package/dist/service/index.mjs.map +1 -1
- package/package.json +3 -2
- package/dist/chunk-ZVXL6B3M.mjs.map +0 -1
package/dist/service/index.d.mts
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
import * as mongoose from 'mongoose';
|
|
2
2
|
import * as _timardex_cluemart_shared from '@timardex/cluemart-shared';
|
|
3
|
-
import { PromoCodeType, EnumAffiliateRewardType,
|
|
4
|
-
import {
|
|
3
|
+
import { PromoCodeType, EnumAffiliateRewardType, DateTimeType, EventListItemType, DateTimeWithPriceType, EnumUserLicence as EnumUserLicence$1, UserLicenceType, EnumNotificationResourceType, EnumNotificationType, EnumResourceType } from '@timardex/cluemart-shared';
|
|
4
|
+
import { p as SchemaAffiliateResourceType, S as SchemaOwnerType, i as SchemaRelationType, n as SchemaUserType } from '../Affiliate-xCVhO2Cy.mjs';
|
|
5
5
|
import { O as ObjectId, G as GraphQLContext, f as SchemaCreateBulkNotificationInput } from '../Chat-Wn7yfc3v.mjs';
|
|
6
|
-
import dayjs from 'dayjs';
|
|
6
|
+
import dayjs, { Dayjs } from 'dayjs';
|
|
7
7
|
import { DateTimeType as DateTimeType$1 } from '@timardex/cluemart-shared/types';
|
|
8
|
-
import { EnumUserLicence
|
|
8
|
+
import { EnumUserLicence } from '@timardex/cluemart-shared/enums';
|
|
9
9
|
import 'express';
|
|
10
10
|
|
|
11
11
|
/**
|
|
@@ -148,8 +148,6 @@ declare function sendPushNotifications({ data, message, title, userIds, }: Schem
|
|
|
148
148
|
*/
|
|
149
149
|
declare function updateAdStatuses(): Promise<void>;
|
|
150
150
|
|
|
151
|
-
declare function updateVendorBasedOnUserLicense(userId: ObjectId, licenceType: EnumUserLicence): Promise<void>;
|
|
152
|
-
|
|
153
151
|
/**
|
|
154
152
|
* True when `value` is a valid Mongo ObjectId string.
|
|
155
153
|
*/
|
|
@@ -196,8 +194,8 @@ declare function updateRelationDatesToUnavailable(relationDates: SchemaRelationT
|
|
|
196
194
|
|
|
197
195
|
type PayingStripeSubscriptionPlanResult = {
|
|
198
196
|
hasSubscription: boolean;
|
|
199
|
-
plan: EnumUserLicence
|
|
200
|
-
validTypes: Set<EnumUserLicence
|
|
197
|
+
plan: EnumUserLicence | null;
|
|
198
|
+
validTypes: Set<EnumUserLicence>;
|
|
201
199
|
};
|
|
202
200
|
/**
|
|
203
201
|
* Returns the paying Stripe plan when `currentPlan` is any PRO plan
|
|
@@ -215,4 +213,240 @@ declare function getPayingVendorStripeSubscriptionPlan(userId: ObjectId | string
|
|
|
215
213
|
*/
|
|
216
214
|
declare function getPayingEventStripeSubscriptionPlan(userId: ObjectId | string, now?: Date): Promise<PayingStripeSubscriptionPlanResult>;
|
|
217
215
|
|
|
218
|
-
|
|
216
|
+
declare function ensureUserLicenseCompliance(): Promise<void>;
|
|
217
|
+
|
|
218
|
+
declare const eventLicences: EnumUserLicence$1[];
|
|
219
|
+
/**
|
|
220
|
+
* Handles event licence compliance for a single user.
|
|
221
|
+
*
|
|
222
|
+
* Event licences are kept and extended on expiry — no deactivation.
|
|
223
|
+
*/
|
|
224
|
+
declare function handleEventLicenceCompliance(user: SchemaUserType, now: Dayjs): Promise<void>;
|
|
225
|
+
|
|
226
|
+
/**
|
|
227
|
+
* Builds an aggregation pipeline that atomically applies expiry rules to the
|
|
228
|
+
* `licences` array. Used by syncUserLicencesAfterExpiry for a single
|
|
229
|
+
* updateOne with no read-modify-write.
|
|
230
|
+
*
|
|
231
|
+
* downgradeBranches: PRO_* / PRO_PLUS_* licence types mapped to their STANDARD_*
|
|
232
|
+
* counterpart (e.g. pro_plus_event → standard_event). Use EnumUserLicence in the
|
|
233
|
+
* caller to avoid string drift.
|
|
234
|
+
*
|
|
235
|
+
* Note: Uses MongoDB aggregation keys "then"/"case" (required by $cond/$switch).
|
|
236
|
+
*
|
|
237
|
+
* Requires MongoDB 4.2+: this emits an updateOne aggregation pipeline (the
|
|
238
|
+
* [ { $set: ... } ] form) and uses $reduce / $indexOfArray / $regexMatch in the
|
|
239
|
+
* dedupe + standard-detection stages. The project runs MongoDB 8.0
|
|
240
|
+
* (docker-compose.yml), well above the minimum.
|
|
241
|
+
*/
|
|
242
|
+
declare function buildLicenceExpiryPipeline(params: {
|
|
243
|
+
/** Pairs of (licenceType, standardCounterpart) for downgrade; e.g. PRO_PLUS_VENDOR → STANDARD_VENDOR */
|
|
244
|
+
downgradeBranches: ReadonlyArray<{
|
|
245
|
+
case: string;
|
|
246
|
+
then: string;
|
|
247
|
+
}>;
|
|
248
|
+
licenceTypes: string[];
|
|
249
|
+
/**
|
|
250
|
+
* How expired, targeted licences are handled:
|
|
251
|
+
* - "downgrade": extend expired STANDARD_* and downgrade expired PRO_* or PRO_PLUS_* (vendor)
|
|
252
|
+
* - "extend": keep the licence as-is and extend expiryDate to oneYearFromNow (partner/event)
|
|
253
|
+
*/
|
|
254
|
+
mode?: "downgrade" | "extend";
|
|
255
|
+
nowDate: Date;
|
|
256
|
+
oneYearFromNow: Date;
|
|
257
|
+
}): object[];
|
|
258
|
+
|
|
259
|
+
declare const partnerLicences: EnumUserLicence$1[];
|
|
260
|
+
/**
|
|
261
|
+
* Handles partner licence compliance for a single user.
|
|
262
|
+
*
|
|
263
|
+
* Partner licences are kept and extended on expiry — no deactivation.
|
|
264
|
+
*/
|
|
265
|
+
declare function handlePartnerLicenceCompliance(user: SchemaUserType, now: Dayjs): Promise<void>;
|
|
266
|
+
|
|
267
|
+
/**
|
|
268
|
+
* Syncs the user's `licences` array
|
|
269
|
+
* Uses a single atomic updateOne with an aggregation pipeline so it is safe under
|
|
270
|
+
* concurrency (no read-modify-write, no lost updates).
|
|
271
|
+
*
|
|
272
|
+
* Rules (applied server-side only to licences whose licenceType is in licenceTypes):
|
|
273
|
+
* - mode "downgrade" (vendor): expired STANDARD_* → extended to one year from now;
|
|
274
|
+
* expired PRO_* or PRO_PLUS_* → downgraded to STANDARD_* with issuedDate=now and
|
|
275
|
+
* expiryDate=one year from now
|
|
276
|
+
* - mode "extend" (partner/event): expired licences are kept and their expiryDate
|
|
277
|
+
* is extended to one year from now
|
|
278
|
+
* - Non-expired or non-targeted licences are unchanged in both modes
|
|
279
|
+
*/
|
|
280
|
+
declare function syncUserLicencesAfterExpiry(userId: ObjectId, licenceTypes: EnumUserLicence$1[], now: dayjs.Dayjs, mode?: "downgrade" | "extend"): Promise<void>;
|
|
281
|
+
/**
|
|
282
|
+
* Checks if user has a valid licence of the given types
|
|
283
|
+
*/
|
|
284
|
+
declare function hasValidLicence(licences: UserLicenceType[], licenceTypes: EnumUserLicence$1[], now: dayjs.Dayjs): boolean;
|
|
285
|
+
/**
|
|
286
|
+
* Sends a deactivation notification to the user
|
|
287
|
+
*/
|
|
288
|
+
declare function sendDeactivationNotification(payload: {
|
|
289
|
+
data: {
|
|
290
|
+
resourceId: string;
|
|
291
|
+
resourceName: string;
|
|
292
|
+
resourceType: EnumNotificationResourceType;
|
|
293
|
+
};
|
|
294
|
+
message: string;
|
|
295
|
+
title: string;
|
|
296
|
+
type: EnumNotificationType;
|
|
297
|
+
userIds: ObjectId[];
|
|
298
|
+
}, userId: ObjectId, resourceName: string, resourceType: string): Promise<void>;
|
|
299
|
+
/**
|
|
300
|
+
* Processes license compliance for a single user
|
|
301
|
+
*/
|
|
302
|
+
declare function processUserCompliance(user: SchemaUserType, now: dayjs.Dayjs): Promise<void>;
|
|
303
|
+
|
|
304
|
+
declare function updateVendorBasedOnUserLicense(userId: ObjectId, licenceType: EnumUserLicence$1): Promise<void>;
|
|
305
|
+
declare const vendorLicences: EnumUserLicence$1[];
|
|
306
|
+
/**
|
|
307
|
+
* Handles vendor licence compliance for a single user
|
|
308
|
+
*/
|
|
309
|
+
declare function handleVendorLicenceCompliance(user: SchemaUserType, now: Dayjs): Promise<void>;
|
|
310
|
+
/**
|
|
311
|
+
* Checks whether a vendor's owner currently holds a PRO (or higher) vendor licence.
|
|
312
|
+
*/
|
|
313
|
+
declare function vendorOwnerHasProLicence(vendorId: string): Promise<boolean>;
|
|
314
|
+
|
|
315
|
+
/**
|
|
316
|
+
* Gets event resource information for a reminder
|
|
317
|
+
*/
|
|
318
|
+
declare function getEventResourceInfo(userId: ObjectId, eventIds: ObjectId[]): Promise<{
|
|
319
|
+
resourceId: string;
|
|
320
|
+
resourceName: string;
|
|
321
|
+
} | null>;
|
|
322
|
+
|
|
323
|
+
/**
|
|
324
|
+
* Gets partner resource information for a reminder
|
|
325
|
+
*/
|
|
326
|
+
declare function getPartnerResourceInfo(userId: ObjectId, partnerId: ObjectId): Promise<{
|
|
327
|
+
resourceId: string;
|
|
328
|
+
resourceName: string;
|
|
329
|
+
} | null>;
|
|
330
|
+
|
|
331
|
+
/**
|
|
332
|
+
* Sends license expiration reminders to users whose licenses expire in 7 days
|
|
333
|
+
*/
|
|
334
|
+
declare function remindUsersAboutLicenseExpiration(): Promise<void>;
|
|
335
|
+
|
|
336
|
+
/**
|
|
337
|
+
* Single source of truth for how a licence type is handled on expiry.
|
|
338
|
+
*
|
|
339
|
+
* - "downgrade": PRO_VENDOR / PRO_PLUS_VENDOR → downgraded to STANDARD_VENDOR.
|
|
340
|
+
* - "extend": every other licence type is auto-extended for another year.
|
|
341
|
+
*
|
|
342
|
+
* Note: `cluemart-server`'s `licenceCategoryMapping` / `licencePriority`
|
|
343
|
+
* (ModelHelpers/licenses/index.ts) is a SEPARATE concern (entitlement priority,
|
|
344
|
+
* not expiry behaviour) and is intentionally not merged here.
|
|
345
|
+
*/
|
|
346
|
+
declare function getLicenceExpiryMode(licenceType: EnumUserLicence$1): "downgrade" | "extend";
|
|
347
|
+
/**
|
|
348
|
+
* Sends a reminder notification for a license.
|
|
349
|
+
*
|
|
350
|
+
* Intentionally does NOT use the shared `notifyUsers` helper: that helper
|
|
351
|
+
* persists via `saveNotificationsInDb` (plain `insertMany`), whereas this job
|
|
352
|
+
* must claim the dedupe slot atomically through
|
|
353
|
+
* {@link checkAndCreateNotification} (upsert) so a reminder is only sent once.
|
|
354
|
+
* Push is therefore sent directly via `sendPushNotifications` only after the
|
|
355
|
+
* claim succeeds.
|
|
356
|
+
*/
|
|
357
|
+
declare function sendLicenseReminder(user: {
|
|
358
|
+
_id: ObjectId;
|
|
359
|
+
vendor?: ObjectId;
|
|
360
|
+
events?: ObjectId[];
|
|
361
|
+
partner?: ObjectId;
|
|
362
|
+
}, licence: {
|
|
363
|
+
licenceType: EnumUserLicence$1;
|
|
364
|
+
expiryDate: Date | string;
|
|
365
|
+
}): Promise<void>;
|
|
366
|
+
/**
|
|
367
|
+
* Processes a single license and sends reminder if needed
|
|
368
|
+
*
|
|
369
|
+
* Checks if a license expires within the 6.5-7.5 day window and hasn't already
|
|
370
|
+
* received a reminder. See isLicenseExpiringIn7Days for details on the reminder window.
|
|
371
|
+
*
|
|
372
|
+
* @returns true if a reminder should be sent, false otherwise
|
|
373
|
+
*/
|
|
374
|
+
declare function processLicenseReminder(user: {
|
|
375
|
+
_id: ObjectId;
|
|
376
|
+
vendor?: ObjectId;
|
|
377
|
+
events?: ObjectId[];
|
|
378
|
+
partner?: ObjectId;
|
|
379
|
+
}, licence: {
|
|
380
|
+
licenceType: EnumUserLicence$1;
|
|
381
|
+
expiryDate: Date | string;
|
|
382
|
+
}, now: dayjs.Dayjs): Promise<boolean>;
|
|
383
|
+
/**
|
|
384
|
+
* Sends a reminder for a single license, handling errors gracefully
|
|
385
|
+
*/
|
|
386
|
+
declare function sendReminderSafely(user: {
|
|
387
|
+
_id: ObjectId;
|
|
388
|
+
vendor?: ObjectId;
|
|
389
|
+
events?: ObjectId[];
|
|
390
|
+
partner?: ObjectId;
|
|
391
|
+
}, licence: UserLicenceType): Promise<boolean>;
|
|
392
|
+
/**
|
|
393
|
+
* Processes reminders for a single user's licenses
|
|
394
|
+
*/
|
|
395
|
+
declare function processUserLicenseReminders(user: SchemaUserType, now: dayjs.Dayjs): Promise<number>;
|
|
396
|
+
|
|
397
|
+
/**
|
|
398
|
+
* Gets vendor resource information for a reminder
|
|
399
|
+
*/
|
|
400
|
+
declare function getVendorResourceInfo(userId: ObjectId, vendorId: ObjectId): Promise<{
|
|
401
|
+
resourceId: string;
|
|
402
|
+
resourceName: string;
|
|
403
|
+
} | null>;
|
|
404
|
+
|
|
405
|
+
declare enum LicenceExpiryDate {
|
|
406
|
+
ONE_YEAR = "1 year",
|
|
407
|
+
ONE_MONTH = "1 month",
|
|
408
|
+
TWO_MONTHS = "2 months"
|
|
409
|
+
}
|
|
410
|
+
declare enum LicenceCategory {
|
|
411
|
+
EVENT = "event",
|
|
412
|
+
PARTNER = "partner",
|
|
413
|
+
VENDOR = "vendor",
|
|
414
|
+
AFFILIATE = "affiliate",
|
|
415
|
+
SCHOOL = "school"
|
|
416
|
+
}
|
|
417
|
+
declare const licenceCategoryMapping: Record<EnumUserLicence$1, LicenceCategory>;
|
|
418
|
+
declare const licencePriority: Record<EnumUserLicence$1, number>;
|
|
419
|
+
declare const standardLicences: readonly [EnumUserLicence$1.STANDARD_VENDOR, EnumUserLicence$1.STANDARD_EVENT, EnumUserLicence$1.STANDARD_PARTNER];
|
|
420
|
+
declare function isStandardLicence(licence: EnumUserLicence$1): licence is (typeof standardLicences)[number];
|
|
421
|
+
type LicenceUpgradeArgs = {
|
|
422
|
+
expiryDate: LicenceExpiryDate;
|
|
423
|
+
licenceType: EnumUserLicence$1;
|
|
424
|
+
userId: ObjectId;
|
|
425
|
+
};
|
|
426
|
+
type LicenceUpgradeResult = {
|
|
427
|
+
licenceObject: UserLicenceType;
|
|
428
|
+
updatedUser: SchemaUserType | null;
|
|
429
|
+
};
|
|
430
|
+
declare function getLicenceCategory(licence: EnumUserLicence$1): LicenceCategory;
|
|
431
|
+
declare function getHighestLicenceForCategory(licences: UserLicenceType[] | null | undefined, category: LicenceCategory): EnumUserLicence$1 | null;
|
|
432
|
+
declare function createLicenceObject(expiryDate: LicenceExpiryDate, licenceType: EnumUserLicence$1): UserLicenceType;
|
|
433
|
+
declare function replaceUserLicenceWithObject({ userId, licenceObject, protectHigherLicence, }: {
|
|
434
|
+
userId: ObjectId;
|
|
435
|
+
licenceObject: UserLicenceType;
|
|
436
|
+
protectHigherLicence?: boolean;
|
|
437
|
+
}): Promise<void>;
|
|
438
|
+
/**
|
|
439
|
+
* Upgrades a user's license by adding a new license object to their account.
|
|
440
|
+
* It calculates the expiry date based on the provided expiry duration and updates the user's licenses in the database.
|
|
441
|
+
* @param licenceType - The licence type to upgrade the user to.
|
|
442
|
+
* @param expiryDate - The expiry duration for the license being upgraded.
|
|
443
|
+
* @param userId - The ID of the user whose license is being upgraded.
|
|
444
|
+
* @returns An object containing the updated user and the new license object.
|
|
445
|
+
*/
|
|
446
|
+
declare const upgradeUserToLicence: ({ licenceType, expiryDate, userId, }: LicenceUpgradeArgs) => Promise<LicenceUpgradeResult>;
|
|
447
|
+
declare function checkOwnerHasLicence({ userId, resourceType, }: {
|
|
448
|
+
userId: ObjectId;
|
|
449
|
+
resourceType: EnumResourceType;
|
|
450
|
+
}): Promise<void>;
|
|
451
|
+
|
|
452
|
+
export { ACTIVE_NOT_DELETED_FILTER, type AwardAffiliateVendorSubscriptionRewardsResult, LicenceCategory, LicenceExpiryDate, type NotificationPubSub, SUBSCRIPTION_REWARD_TIMEZONE, activeAffiliateCodeExists, awardAffiliateVendorSubscriptionRewards, buildLicenceExpiryPipeline, checkOwnerHasLicence, connectToDatabase, convertObjectIdsToStrings, createLicenceObject, didRemoveAnyEventDates, ensureUserLicenseCompliance, eventLicences, findAffiliateByPromoCode, findEventOrImportedMarketById, getEventResourceInfo, getHighestLicenceForCategory, getLicenceCategory, getLicenceExpiryMode, getPartnerResourceInfo, getPayingEventStripeSubscriptionPlan, getPayingStripeSubscriptionPlan, getPayingVendorStripeSubscriptionPlan, getSubscriptionRewardPeriodBounds, getVendorResourceInfo, handleEventLicenceCompliance, handlePartnerLicenceCompliance, handleVendorLicenceCompliance, hasValidLicence, isStandardLicence, isValidObjectId, licenceCategoryMapping, licencePriority, mapVendorLicenceToSubscriptionRewardType, normalizeAffiliatePromoCodes, normalizePromoCode, notifyUsers, partnerLicences, processLicenseReminder, processUserCompliance, processUserLicenseReminders, publishNotificationEvents, remindUsersAboutLicenseExpiration, replaceUserLicenceWithObject, saveNotificationsInDb, sendDeactivationNotification, sendLicenseReminder, sendPushNotifications, sendReminderSafely, syncUserLicencesAfterExpiry, updateAdStatuses, updateAllEventDateTimeStatuses, updateRelationDatesToUnavailable, updateSingleDateTimeStatus, updateVendorBasedOnUserLicense, upgradeUserToLicence, vendorLicences, vendorOwnerHasProLicence };
|
package/dist/service/index.d.ts
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
import * as mongoose from 'mongoose';
|
|
2
2
|
import * as _timardex_cluemart_shared from '@timardex/cluemart-shared';
|
|
3
|
-
import { PromoCodeType, EnumAffiliateRewardType,
|
|
4
|
-
import {
|
|
3
|
+
import { PromoCodeType, EnumAffiliateRewardType, DateTimeType, EventListItemType, DateTimeWithPriceType, EnumUserLicence as EnumUserLicence$1, UserLicenceType, EnumNotificationResourceType, EnumNotificationType, EnumResourceType } from '@timardex/cluemart-shared';
|
|
4
|
+
import { p as SchemaAffiliateResourceType, S as SchemaOwnerType, i as SchemaRelationType, n as SchemaUserType } from '../Affiliate-CZKOOaz_.js';
|
|
5
5
|
import { O as ObjectId, G as GraphQLContext, f as SchemaCreateBulkNotificationInput } from '../Chat-Wn7yfc3v.js';
|
|
6
|
-
import dayjs from 'dayjs';
|
|
6
|
+
import dayjs, { Dayjs } from 'dayjs';
|
|
7
7
|
import { DateTimeType as DateTimeType$1 } from '@timardex/cluemart-shared/types';
|
|
8
|
-
import { EnumUserLicence
|
|
8
|
+
import { EnumUserLicence } from '@timardex/cluemart-shared/enums';
|
|
9
9
|
import 'express';
|
|
10
10
|
|
|
11
11
|
/**
|
|
@@ -148,8 +148,6 @@ declare function sendPushNotifications({ data, message, title, userIds, }: Schem
|
|
|
148
148
|
*/
|
|
149
149
|
declare function updateAdStatuses(): Promise<void>;
|
|
150
150
|
|
|
151
|
-
declare function updateVendorBasedOnUserLicense(userId: ObjectId, licenceType: EnumUserLicence): Promise<void>;
|
|
152
|
-
|
|
153
151
|
/**
|
|
154
152
|
* True when `value` is a valid Mongo ObjectId string.
|
|
155
153
|
*/
|
|
@@ -196,8 +194,8 @@ declare function updateRelationDatesToUnavailable(relationDates: SchemaRelationT
|
|
|
196
194
|
|
|
197
195
|
type PayingStripeSubscriptionPlanResult = {
|
|
198
196
|
hasSubscription: boolean;
|
|
199
|
-
plan: EnumUserLicence
|
|
200
|
-
validTypes: Set<EnumUserLicence
|
|
197
|
+
plan: EnumUserLicence | null;
|
|
198
|
+
validTypes: Set<EnumUserLicence>;
|
|
201
199
|
};
|
|
202
200
|
/**
|
|
203
201
|
* Returns the paying Stripe plan when `currentPlan` is any PRO plan
|
|
@@ -215,4 +213,240 @@ declare function getPayingVendorStripeSubscriptionPlan(userId: ObjectId | string
|
|
|
215
213
|
*/
|
|
216
214
|
declare function getPayingEventStripeSubscriptionPlan(userId: ObjectId | string, now?: Date): Promise<PayingStripeSubscriptionPlanResult>;
|
|
217
215
|
|
|
218
|
-
|
|
216
|
+
declare function ensureUserLicenseCompliance(): Promise<void>;
|
|
217
|
+
|
|
218
|
+
declare const eventLicences: EnumUserLicence$1[];
|
|
219
|
+
/**
|
|
220
|
+
* Handles event licence compliance for a single user.
|
|
221
|
+
*
|
|
222
|
+
* Event licences are kept and extended on expiry — no deactivation.
|
|
223
|
+
*/
|
|
224
|
+
declare function handleEventLicenceCompliance(user: SchemaUserType, now: Dayjs): Promise<void>;
|
|
225
|
+
|
|
226
|
+
/**
|
|
227
|
+
* Builds an aggregation pipeline that atomically applies expiry rules to the
|
|
228
|
+
* `licences` array. Used by syncUserLicencesAfterExpiry for a single
|
|
229
|
+
* updateOne with no read-modify-write.
|
|
230
|
+
*
|
|
231
|
+
* downgradeBranches: PRO_* / PRO_PLUS_* licence types mapped to their STANDARD_*
|
|
232
|
+
* counterpart (e.g. pro_plus_event → standard_event). Use EnumUserLicence in the
|
|
233
|
+
* caller to avoid string drift.
|
|
234
|
+
*
|
|
235
|
+
* Note: Uses MongoDB aggregation keys "then"/"case" (required by $cond/$switch).
|
|
236
|
+
*
|
|
237
|
+
* Requires MongoDB 4.2+: this emits an updateOne aggregation pipeline (the
|
|
238
|
+
* [ { $set: ... } ] form) and uses $reduce / $indexOfArray / $regexMatch in the
|
|
239
|
+
* dedupe + standard-detection stages. The project runs MongoDB 8.0
|
|
240
|
+
* (docker-compose.yml), well above the minimum.
|
|
241
|
+
*/
|
|
242
|
+
declare function buildLicenceExpiryPipeline(params: {
|
|
243
|
+
/** Pairs of (licenceType, standardCounterpart) for downgrade; e.g. PRO_PLUS_VENDOR → STANDARD_VENDOR */
|
|
244
|
+
downgradeBranches: ReadonlyArray<{
|
|
245
|
+
case: string;
|
|
246
|
+
then: string;
|
|
247
|
+
}>;
|
|
248
|
+
licenceTypes: string[];
|
|
249
|
+
/**
|
|
250
|
+
* How expired, targeted licences are handled:
|
|
251
|
+
* - "downgrade": extend expired STANDARD_* and downgrade expired PRO_* or PRO_PLUS_* (vendor)
|
|
252
|
+
* - "extend": keep the licence as-is and extend expiryDate to oneYearFromNow (partner/event)
|
|
253
|
+
*/
|
|
254
|
+
mode?: "downgrade" | "extend";
|
|
255
|
+
nowDate: Date;
|
|
256
|
+
oneYearFromNow: Date;
|
|
257
|
+
}): object[];
|
|
258
|
+
|
|
259
|
+
declare const partnerLicences: EnumUserLicence$1[];
|
|
260
|
+
/**
|
|
261
|
+
* Handles partner licence compliance for a single user.
|
|
262
|
+
*
|
|
263
|
+
* Partner licences are kept and extended on expiry — no deactivation.
|
|
264
|
+
*/
|
|
265
|
+
declare function handlePartnerLicenceCompliance(user: SchemaUserType, now: Dayjs): Promise<void>;
|
|
266
|
+
|
|
267
|
+
/**
|
|
268
|
+
* Syncs the user's `licences` array
|
|
269
|
+
* Uses a single atomic updateOne with an aggregation pipeline so it is safe under
|
|
270
|
+
* concurrency (no read-modify-write, no lost updates).
|
|
271
|
+
*
|
|
272
|
+
* Rules (applied server-side only to licences whose licenceType is in licenceTypes):
|
|
273
|
+
* - mode "downgrade" (vendor): expired STANDARD_* → extended to one year from now;
|
|
274
|
+
* expired PRO_* or PRO_PLUS_* → downgraded to STANDARD_* with issuedDate=now and
|
|
275
|
+
* expiryDate=one year from now
|
|
276
|
+
* - mode "extend" (partner/event): expired licences are kept and their expiryDate
|
|
277
|
+
* is extended to one year from now
|
|
278
|
+
* - Non-expired or non-targeted licences are unchanged in both modes
|
|
279
|
+
*/
|
|
280
|
+
declare function syncUserLicencesAfterExpiry(userId: ObjectId, licenceTypes: EnumUserLicence$1[], now: dayjs.Dayjs, mode?: "downgrade" | "extend"): Promise<void>;
|
|
281
|
+
/**
|
|
282
|
+
* Checks if user has a valid licence of the given types
|
|
283
|
+
*/
|
|
284
|
+
declare function hasValidLicence(licences: UserLicenceType[], licenceTypes: EnumUserLicence$1[], now: dayjs.Dayjs): boolean;
|
|
285
|
+
/**
|
|
286
|
+
* Sends a deactivation notification to the user
|
|
287
|
+
*/
|
|
288
|
+
declare function sendDeactivationNotification(payload: {
|
|
289
|
+
data: {
|
|
290
|
+
resourceId: string;
|
|
291
|
+
resourceName: string;
|
|
292
|
+
resourceType: EnumNotificationResourceType;
|
|
293
|
+
};
|
|
294
|
+
message: string;
|
|
295
|
+
title: string;
|
|
296
|
+
type: EnumNotificationType;
|
|
297
|
+
userIds: ObjectId[];
|
|
298
|
+
}, userId: ObjectId, resourceName: string, resourceType: string): Promise<void>;
|
|
299
|
+
/**
|
|
300
|
+
* Processes license compliance for a single user
|
|
301
|
+
*/
|
|
302
|
+
declare function processUserCompliance(user: SchemaUserType, now: dayjs.Dayjs): Promise<void>;
|
|
303
|
+
|
|
304
|
+
declare function updateVendorBasedOnUserLicense(userId: ObjectId, licenceType: EnumUserLicence$1): Promise<void>;
|
|
305
|
+
declare const vendorLicences: EnumUserLicence$1[];
|
|
306
|
+
/**
|
|
307
|
+
* Handles vendor licence compliance for a single user
|
|
308
|
+
*/
|
|
309
|
+
declare function handleVendorLicenceCompliance(user: SchemaUserType, now: Dayjs): Promise<void>;
|
|
310
|
+
/**
|
|
311
|
+
* Checks whether a vendor's owner currently holds a PRO (or higher) vendor licence.
|
|
312
|
+
*/
|
|
313
|
+
declare function vendorOwnerHasProLicence(vendorId: string): Promise<boolean>;
|
|
314
|
+
|
|
315
|
+
/**
|
|
316
|
+
* Gets event resource information for a reminder
|
|
317
|
+
*/
|
|
318
|
+
declare function getEventResourceInfo(userId: ObjectId, eventIds: ObjectId[]): Promise<{
|
|
319
|
+
resourceId: string;
|
|
320
|
+
resourceName: string;
|
|
321
|
+
} | null>;
|
|
322
|
+
|
|
323
|
+
/**
|
|
324
|
+
* Gets partner resource information for a reminder
|
|
325
|
+
*/
|
|
326
|
+
declare function getPartnerResourceInfo(userId: ObjectId, partnerId: ObjectId): Promise<{
|
|
327
|
+
resourceId: string;
|
|
328
|
+
resourceName: string;
|
|
329
|
+
} | null>;
|
|
330
|
+
|
|
331
|
+
/**
|
|
332
|
+
* Sends license expiration reminders to users whose licenses expire in 7 days
|
|
333
|
+
*/
|
|
334
|
+
declare function remindUsersAboutLicenseExpiration(): Promise<void>;
|
|
335
|
+
|
|
336
|
+
/**
|
|
337
|
+
* Single source of truth for how a licence type is handled on expiry.
|
|
338
|
+
*
|
|
339
|
+
* - "downgrade": PRO_VENDOR / PRO_PLUS_VENDOR → downgraded to STANDARD_VENDOR.
|
|
340
|
+
* - "extend": every other licence type is auto-extended for another year.
|
|
341
|
+
*
|
|
342
|
+
* Note: `cluemart-server`'s `licenceCategoryMapping` / `licencePriority`
|
|
343
|
+
* (ModelHelpers/licenses/index.ts) is a SEPARATE concern (entitlement priority,
|
|
344
|
+
* not expiry behaviour) and is intentionally not merged here.
|
|
345
|
+
*/
|
|
346
|
+
declare function getLicenceExpiryMode(licenceType: EnumUserLicence$1): "downgrade" | "extend";
|
|
347
|
+
/**
|
|
348
|
+
* Sends a reminder notification for a license.
|
|
349
|
+
*
|
|
350
|
+
* Intentionally does NOT use the shared `notifyUsers` helper: that helper
|
|
351
|
+
* persists via `saveNotificationsInDb` (plain `insertMany`), whereas this job
|
|
352
|
+
* must claim the dedupe slot atomically through
|
|
353
|
+
* {@link checkAndCreateNotification} (upsert) so a reminder is only sent once.
|
|
354
|
+
* Push is therefore sent directly via `sendPushNotifications` only after the
|
|
355
|
+
* claim succeeds.
|
|
356
|
+
*/
|
|
357
|
+
declare function sendLicenseReminder(user: {
|
|
358
|
+
_id: ObjectId;
|
|
359
|
+
vendor?: ObjectId;
|
|
360
|
+
events?: ObjectId[];
|
|
361
|
+
partner?: ObjectId;
|
|
362
|
+
}, licence: {
|
|
363
|
+
licenceType: EnumUserLicence$1;
|
|
364
|
+
expiryDate: Date | string;
|
|
365
|
+
}): Promise<void>;
|
|
366
|
+
/**
|
|
367
|
+
* Processes a single license and sends reminder if needed
|
|
368
|
+
*
|
|
369
|
+
* Checks if a license expires within the 6.5-7.5 day window and hasn't already
|
|
370
|
+
* received a reminder. See isLicenseExpiringIn7Days for details on the reminder window.
|
|
371
|
+
*
|
|
372
|
+
* @returns true if a reminder should be sent, false otherwise
|
|
373
|
+
*/
|
|
374
|
+
declare function processLicenseReminder(user: {
|
|
375
|
+
_id: ObjectId;
|
|
376
|
+
vendor?: ObjectId;
|
|
377
|
+
events?: ObjectId[];
|
|
378
|
+
partner?: ObjectId;
|
|
379
|
+
}, licence: {
|
|
380
|
+
licenceType: EnumUserLicence$1;
|
|
381
|
+
expiryDate: Date | string;
|
|
382
|
+
}, now: dayjs.Dayjs): Promise<boolean>;
|
|
383
|
+
/**
|
|
384
|
+
* Sends a reminder for a single license, handling errors gracefully
|
|
385
|
+
*/
|
|
386
|
+
declare function sendReminderSafely(user: {
|
|
387
|
+
_id: ObjectId;
|
|
388
|
+
vendor?: ObjectId;
|
|
389
|
+
events?: ObjectId[];
|
|
390
|
+
partner?: ObjectId;
|
|
391
|
+
}, licence: UserLicenceType): Promise<boolean>;
|
|
392
|
+
/**
|
|
393
|
+
* Processes reminders for a single user's licenses
|
|
394
|
+
*/
|
|
395
|
+
declare function processUserLicenseReminders(user: SchemaUserType, now: dayjs.Dayjs): Promise<number>;
|
|
396
|
+
|
|
397
|
+
/**
|
|
398
|
+
* Gets vendor resource information for a reminder
|
|
399
|
+
*/
|
|
400
|
+
declare function getVendorResourceInfo(userId: ObjectId, vendorId: ObjectId): Promise<{
|
|
401
|
+
resourceId: string;
|
|
402
|
+
resourceName: string;
|
|
403
|
+
} | null>;
|
|
404
|
+
|
|
405
|
+
declare enum LicenceExpiryDate {
|
|
406
|
+
ONE_YEAR = "1 year",
|
|
407
|
+
ONE_MONTH = "1 month",
|
|
408
|
+
TWO_MONTHS = "2 months"
|
|
409
|
+
}
|
|
410
|
+
declare enum LicenceCategory {
|
|
411
|
+
EVENT = "event",
|
|
412
|
+
PARTNER = "partner",
|
|
413
|
+
VENDOR = "vendor",
|
|
414
|
+
AFFILIATE = "affiliate",
|
|
415
|
+
SCHOOL = "school"
|
|
416
|
+
}
|
|
417
|
+
declare const licenceCategoryMapping: Record<EnumUserLicence$1, LicenceCategory>;
|
|
418
|
+
declare const licencePriority: Record<EnumUserLicence$1, number>;
|
|
419
|
+
declare const standardLicences: readonly [EnumUserLicence$1.STANDARD_VENDOR, EnumUserLicence$1.STANDARD_EVENT, EnumUserLicence$1.STANDARD_PARTNER];
|
|
420
|
+
declare function isStandardLicence(licence: EnumUserLicence$1): licence is (typeof standardLicences)[number];
|
|
421
|
+
type LicenceUpgradeArgs = {
|
|
422
|
+
expiryDate: LicenceExpiryDate;
|
|
423
|
+
licenceType: EnumUserLicence$1;
|
|
424
|
+
userId: ObjectId;
|
|
425
|
+
};
|
|
426
|
+
type LicenceUpgradeResult = {
|
|
427
|
+
licenceObject: UserLicenceType;
|
|
428
|
+
updatedUser: SchemaUserType | null;
|
|
429
|
+
};
|
|
430
|
+
declare function getLicenceCategory(licence: EnumUserLicence$1): LicenceCategory;
|
|
431
|
+
declare function getHighestLicenceForCategory(licences: UserLicenceType[] | null | undefined, category: LicenceCategory): EnumUserLicence$1 | null;
|
|
432
|
+
declare function createLicenceObject(expiryDate: LicenceExpiryDate, licenceType: EnumUserLicence$1): UserLicenceType;
|
|
433
|
+
declare function replaceUserLicenceWithObject({ userId, licenceObject, protectHigherLicence, }: {
|
|
434
|
+
userId: ObjectId;
|
|
435
|
+
licenceObject: UserLicenceType;
|
|
436
|
+
protectHigherLicence?: boolean;
|
|
437
|
+
}): Promise<void>;
|
|
438
|
+
/**
|
|
439
|
+
* Upgrades a user's license by adding a new license object to their account.
|
|
440
|
+
* It calculates the expiry date based on the provided expiry duration and updates the user's licenses in the database.
|
|
441
|
+
* @param licenceType - The licence type to upgrade the user to.
|
|
442
|
+
* @param expiryDate - The expiry duration for the license being upgraded.
|
|
443
|
+
* @param userId - The ID of the user whose license is being upgraded.
|
|
444
|
+
* @returns An object containing the updated user and the new license object.
|
|
445
|
+
*/
|
|
446
|
+
declare const upgradeUserToLicence: ({ licenceType, expiryDate, userId, }: LicenceUpgradeArgs) => Promise<LicenceUpgradeResult>;
|
|
447
|
+
declare function checkOwnerHasLicence({ userId, resourceType, }: {
|
|
448
|
+
userId: ObjectId;
|
|
449
|
+
resourceType: EnumResourceType;
|
|
450
|
+
}): Promise<void>;
|
|
451
|
+
|
|
452
|
+
export { ACTIVE_NOT_DELETED_FILTER, type AwardAffiliateVendorSubscriptionRewardsResult, LicenceCategory, LicenceExpiryDate, type NotificationPubSub, SUBSCRIPTION_REWARD_TIMEZONE, activeAffiliateCodeExists, awardAffiliateVendorSubscriptionRewards, buildLicenceExpiryPipeline, checkOwnerHasLicence, connectToDatabase, convertObjectIdsToStrings, createLicenceObject, didRemoveAnyEventDates, ensureUserLicenseCompliance, eventLicences, findAffiliateByPromoCode, findEventOrImportedMarketById, getEventResourceInfo, getHighestLicenceForCategory, getLicenceCategory, getLicenceExpiryMode, getPartnerResourceInfo, getPayingEventStripeSubscriptionPlan, getPayingStripeSubscriptionPlan, getPayingVendorStripeSubscriptionPlan, getSubscriptionRewardPeriodBounds, getVendorResourceInfo, handleEventLicenceCompliance, handlePartnerLicenceCompliance, handleVendorLicenceCompliance, hasValidLicence, isStandardLicence, isValidObjectId, licenceCategoryMapping, licencePriority, mapVendorLicenceToSubscriptionRewardType, normalizeAffiliatePromoCodes, normalizePromoCode, notifyUsers, partnerLicences, processLicenseReminder, processUserCompliance, processUserLicenseReminders, publishNotificationEvents, remindUsersAboutLicenseExpiration, replaceUserLicenceWithObject, saveNotificationsInDb, sendDeactivationNotification, sendLicenseReminder, sendPushNotifications, sendReminderSafely, syncUserLicencesAfterExpiry, updateAdStatuses, updateAllEventDateTimeStatuses, updateRelationDatesToUnavailable, updateSingleDateTimeStatus, updateVendorBasedOnUserLicense, upgradeUserToLicence, vendorLicences, vendorOwnerHasProLicence };
|