@timardex/cluemart-server-shared 2.2.23 → 2.3.0
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
package/dist/service/index.d.mts
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import * as mongoose from 'mongoose';
|
|
2
2
|
import * as _timardex_cluemart_shared from '@timardex/cluemart-shared';
|
|
3
|
-
import { PromoCodeType, EnumAffiliateRewardType, DateTimeType, EventListItemType, DateTimeWithPriceType, EnumUserLicence as EnumUserLicence$1, UserLicenceType, EnumNotificationResourceType, EnumNotificationType, EnumResourceType, LicenceExpiryDate } from '@timardex/cluemart-shared';
|
|
3
|
+
import { PromoCodeType, EnumAffiliateRewardType, EnumPointType, UserOverallPointsEntry, DateTimeType, EventListItemType, DateTimeWithPriceType, EnumUserLicence as EnumUserLicence$1, UserLicenceType, EnumNotificationResourceType, EnumNotificationType, EnumResourceType, LicenceExpiryDate } from '@timardex/cluemart-shared';
|
|
4
4
|
export { updateSingleDateTimeStatus } from '@timardex/cluemart-shared';
|
|
5
|
-
import { d as SchemaAffiliateResourceType, S as SchemaOwnerType, g as SchemaRelationType, j as SchemaUserType } from '../Affiliate-
|
|
5
|
+
import { d as SchemaAffiliateResourceType, S as SchemaOwnerType, g as SchemaRelationType, j as SchemaUserType } from '../Affiliate-DIAzxxfs.mjs';
|
|
6
6
|
import { O as ObjectId, G as GraphQLContext, e as SchemaCreateBulkNotificationInput } from '../index-CmtBYjpi.mjs';
|
|
7
7
|
import { DateTimeType as DateTimeType$1 } from '@timardex/cluemart-shared/types';
|
|
8
8
|
import { EnumUserLicence } from '@timardex/cluemart-shared/enums';
|
|
@@ -159,6 +159,93 @@ declare function isValidObjectId(value: string): boolean;
|
|
|
159
159
|
*/
|
|
160
160
|
declare function convertObjectIdsToStrings(obj: any): any;
|
|
161
161
|
|
|
162
|
+
/**
|
|
163
|
+
* One ledger entry for an award.
|
|
164
|
+
*
|
|
165
|
+
* `User.overallPoints` is append-only: awarding points must push a new entry so
|
|
166
|
+
* previously earned points are never replaced.
|
|
167
|
+
*
|
|
168
|
+
* `sourceId` is the idempotency key for the award (e.g. the game row `_id`).
|
|
169
|
+
* Pass it whenever the award can be retried, so `buildUserPointCreditFilter`
|
|
170
|
+
* can dedupe it.
|
|
171
|
+
*
|
|
172
|
+
* `undefined` is the only "no key" value: an empty string is stored as-is so the
|
|
173
|
+
* entry always matches what `buildUserPointCreditFilter` searches for (a
|
|
174
|
+
* truthiness check here would drop `""` from the entry while the filter still
|
|
175
|
+
* looked for it, silently disabling dedupe).
|
|
176
|
+
*/
|
|
177
|
+
declare function buildUserPointAwardEntry(pointType: EnumPointType, points: number, sourceId?: string): UserOverallPointsEntry;
|
|
178
|
+
/**
|
|
179
|
+
* Filter for an idempotent award: matches the user only when no ledger entry
|
|
180
|
+
* already carries `sourceId`.
|
|
181
|
+
*
|
|
182
|
+
* Uses `$not` + `$elemMatch` rather than a dotted `$ne` so the "no entry with
|
|
183
|
+
* this key" intent is explicit and cannot be mistaken for a per-element
|
|
184
|
+
* comparison. Combined with `$push` of
|
|
185
|
+
* `buildUserPointAwardEntry(..., sourceId)`, running the award twice credits it
|
|
186
|
+
* once. This replaces a cross-document transaction (unavailable on standalone
|
|
187
|
+
* MongoDB) for "credit points, then mark the source as done" flows.
|
|
188
|
+
*/
|
|
189
|
+
declare function buildUserPointCreditFilter(userId: unknown, sourceId: string): {
|
|
190
|
+
_id: unknown;
|
|
191
|
+
overallPoints: {
|
|
192
|
+
$not: {
|
|
193
|
+
$elemMatch: {
|
|
194
|
+
sourceId: string;
|
|
195
|
+
};
|
|
196
|
+
};
|
|
197
|
+
};
|
|
198
|
+
};
|
|
199
|
+
/**
|
|
200
|
+
* Matches users whose spendable total (sum of every ledger entry) covers
|
|
201
|
+
* `amount`. Legacy numeric values contribute 0 until the startup migration runs.
|
|
202
|
+
*/
|
|
203
|
+
declare function buildUserHasEnoughPointsFilter(amount: number): {
|
|
204
|
+
$expr: {
|
|
205
|
+
$gte: (number | {
|
|
206
|
+
$sum: {
|
|
207
|
+
$ifNull: (string | never[])[];
|
|
208
|
+
};
|
|
209
|
+
})[];
|
|
210
|
+
};
|
|
211
|
+
};
|
|
212
|
+
/**
|
|
213
|
+
* Debits `amount` from the oldest entries first (FIFO), flooring every entry at
|
|
214
|
+
* 0 and dropping emptied ones. Pair with `buildUserHasEnoughPointsFilter` so
|
|
215
|
+
* the full amount is always covered.
|
|
216
|
+
*
|
|
217
|
+
* Non-array `overallPoints` values are handled by `buildLedgerWriteExpr`:
|
|
218
|
+
* null/missing becomes an empty ledger, while any other shape is left untouched
|
|
219
|
+
* rather than replaced.
|
|
220
|
+
*/
|
|
221
|
+
declare function buildUserPointDebitPipeline(amount: number): {
|
|
222
|
+
$set: {
|
|
223
|
+
overallPoints: {
|
|
224
|
+
$cond: object[];
|
|
225
|
+
};
|
|
226
|
+
};
|
|
227
|
+
}[];
|
|
228
|
+
/**
|
|
229
|
+
* Removes the first ledger entry matching `pointType` (and `sourceId`, when
|
|
230
|
+
* given), reversing a single award. `$pull` cannot be used because it would
|
|
231
|
+
* remove every entry of that type.
|
|
232
|
+
*
|
|
233
|
+
* Always pass `sourceId` when the award carries one: matching on `pointType`
|
|
234
|
+
* alone would remove an unrelated award of the same type (e.g. checking out of
|
|
235
|
+
* one event stripping a different event's check-in points).
|
|
236
|
+
*
|
|
237
|
+
* Non-array `overallPoints` values are handled by `buildLedgerWriteExpr`:
|
|
238
|
+
* null/missing becomes an empty ledger, while any other shape is left untouched
|
|
239
|
+
* rather than replaced.
|
|
240
|
+
*/
|
|
241
|
+
declare function buildUserPointEntryRemovalPipeline(pointType: EnumPointType, sourceId?: string): {
|
|
242
|
+
$set: {
|
|
243
|
+
overallPoints: {
|
|
244
|
+
$cond: object[];
|
|
245
|
+
};
|
|
246
|
+
};
|
|
247
|
+
}[];
|
|
248
|
+
|
|
162
249
|
/**
|
|
163
250
|
* Recomputes dateStatus for every dateTime slot on events and google imported
|
|
164
251
|
* markets, moves ended event date slots into the event date archive, and keeps
|
|
@@ -506,4 +593,4 @@ declare function checkOwnerHasLicence({ userId, resourceType, }: {
|
|
|
506
593
|
resourceType: EnumResourceType;
|
|
507
594
|
}): Promise<void>;
|
|
508
595
|
|
|
509
|
-
export { ACTIVE_NOT_DELETED_FILTER, type AwardAffiliateVendorSubscriptionRewardsResult, LicenceCategory, type NotificationPubSub, REMINDER_WINDOW_MAX_HOURS, REMINDER_WINDOW_MIN_HOURS, SUBSCRIPTION_REWARD_TIMEZONE, activeAffiliateCodeExists, awardAffiliateVendorSubscriptionRewards, buildLicenceExpiryPipeline, checkOwnerHasLicence, connectToDatabase, convertObjectIdsToStrings, createLicenceObject, dedupeArchivedSlotsByStartDateTime, didRemoveAnyEventDates, didRemoveAnyStartedDates, downgradeVendorProFeatures, ensureUserLicenseCompliance, ensureUserLicenseComplianceForUser, 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, persistArchivedEventDates, processLicenseReminder, processUserCompliance, processUserLicenseReminders, publishNotificationEvents, remindUsersAboutLicenseExpiration, replaceUserLicenceWithObject, restoreVendorProFeatures, saveNotificationsInDb, sendDeactivationNotification, sendLicenseReminder, sendPushNotifications, sendReminderSafely, splitEventDatesForArchive, syncUserLicencesAfterExpiry, updateAdStatuses, updateAllEventDateTimeStatuses, updateRelationDatesToUnavailable, upgradeUserToLicence, vendorOwnerHasProLicence };
|
|
596
|
+
export { ACTIVE_NOT_DELETED_FILTER, type AwardAffiliateVendorSubscriptionRewardsResult, LicenceCategory, type NotificationPubSub, REMINDER_WINDOW_MAX_HOURS, REMINDER_WINDOW_MIN_HOURS, SUBSCRIPTION_REWARD_TIMEZONE, activeAffiliateCodeExists, awardAffiliateVendorSubscriptionRewards, buildLicenceExpiryPipeline, buildUserHasEnoughPointsFilter, buildUserPointAwardEntry, buildUserPointCreditFilter, buildUserPointDebitPipeline, buildUserPointEntryRemovalPipeline, checkOwnerHasLicence, connectToDatabase, convertObjectIdsToStrings, createLicenceObject, dedupeArchivedSlotsByStartDateTime, didRemoveAnyEventDates, didRemoveAnyStartedDates, downgradeVendorProFeatures, ensureUserLicenseCompliance, ensureUserLicenseComplianceForUser, 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, persistArchivedEventDates, processLicenseReminder, processUserCompliance, processUserLicenseReminders, publishNotificationEvents, remindUsersAboutLicenseExpiration, replaceUserLicenceWithObject, restoreVendorProFeatures, saveNotificationsInDb, sendDeactivationNotification, sendLicenseReminder, sendPushNotifications, sendReminderSafely, splitEventDatesForArchive, syncUserLicencesAfterExpiry, updateAdStatuses, updateAllEventDateTimeStatuses, updateRelationDatesToUnavailable, upgradeUserToLicence, vendorOwnerHasProLicence };
|
package/dist/service/index.d.ts
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import * as mongoose from 'mongoose';
|
|
2
2
|
import * as _timardex_cluemart_shared from '@timardex/cluemart-shared';
|
|
3
|
-
import { PromoCodeType, EnumAffiliateRewardType, DateTimeType, EventListItemType, DateTimeWithPriceType, EnumUserLicence as EnumUserLicence$1, UserLicenceType, EnumNotificationResourceType, EnumNotificationType, EnumResourceType, LicenceExpiryDate } from '@timardex/cluemart-shared';
|
|
3
|
+
import { PromoCodeType, EnumAffiliateRewardType, EnumPointType, UserOverallPointsEntry, DateTimeType, EventListItemType, DateTimeWithPriceType, EnumUserLicence as EnumUserLicence$1, UserLicenceType, EnumNotificationResourceType, EnumNotificationType, EnumResourceType, LicenceExpiryDate } from '@timardex/cluemart-shared';
|
|
4
4
|
export { updateSingleDateTimeStatus } from '@timardex/cluemart-shared';
|
|
5
|
-
import { d as SchemaAffiliateResourceType, S as SchemaOwnerType, g as SchemaRelationType, j as SchemaUserType } from '../Affiliate-
|
|
5
|
+
import { d as SchemaAffiliateResourceType, S as SchemaOwnerType, g as SchemaRelationType, j as SchemaUserType } from '../Affiliate-zioeZDyH.js';
|
|
6
6
|
import { O as ObjectId, G as GraphQLContext, e as SchemaCreateBulkNotificationInput } from '../index-CmtBYjpi.js';
|
|
7
7
|
import { DateTimeType as DateTimeType$1 } from '@timardex/cluemart-shared/types';
|
|
8
8
|
import { EnumUserLicence } from '@timardex/cluemart-shared/enums';
|
|
@@ -159,6 +159,93 @@ declare function isValidObjectId(value: string): boolean;
|
|
|
159
159
|
*/
|
|
160
160
|
declare function convertObjectIdsToStrings(obj: any): any;
|
|
161
161
|
|
|
162
|
+
/**
|
|
163
|
+
* One ledger entry for an award.
|
|
164
|
+
*
|
|
165
|
+
* `User.overallPoints` is append-only: awarding points must push a new entry so
|
|
166
|
+
* previously earned points are never replaced.
|
|
167
|
+
*
|
|
168
|
+
* `sourceId` is the idempotency key for the award (e.g. the game row `_id`).
|
|
169
|
+
* Pass it whenever the award can be retried, so `buildUserPointCreditFilter`
|
|
170
|
+
* can dedupe it.
|
|
171
|
+
*
|
|
172
|
+
* `undefined` is the only "no key" value: an empty string is stored as-is so the
|
|
173
|
+
* entry always matches what `buildUserPointCreditFilter` searches for (a
|
|
174
|
+
* truthiness check here would drop `""` from the entry while the filter still
|
|
175
|
+
* looked for it, silently disabling dedupe).
|
|
176
|
+
*/
|
|
177
|
+
declare function buildUserPointAwardEntry(pointType: EnumPointType, points: number, sourceId?: string): UserOverallPointsEntry;
|
|
178
|
+
/**
|
|
179
|
+
* Filter for an idempotent award: matches the user only when no ledger entry
|
|
180
|
+
* already carries `sourceId`.
|
|
181
|
+
*
|
|
182
|
+
* Uses `$not` + `$elemMatch` rather than a dotted `$ne` so the "no entry with
|
|
183
|
+
* this key" intent is explicit and cannot be mistaken for a per-element
|
|
184
|
+
* comparison. Combined with `$push` of
|
|
185
|
+
* `buildUserPointAwardEntry(..., sourceId)`, running the award twice credits it
|
|
186
|
+
* once. This replaces a cross-document transaction (unavailable on standalone
|
|
187
|
+
* MongoDB) for "credit points, then mark the source as done" flows.
|
|
188
|
+
*/
|
|
189
|
+
declare function buildUserPointCreditFilter(userId: unknown, sourceId: string): {
|
|
190
|
+
_id: unknown;
|
|
191
|
+
overallPoints: {
|
|
192
|
+
$not: {
|
|
193
|
+
$elemMatch: {
|
|
194
|
+
sourceId: string;
|
|
195
|
+
};
|
|
196
|
+
};
|
|
197
|
+
};
|
|
198
|
+
};
|
|
199
|
+
/**
|
|
200
|
+
* Matches users whose spendable total (sum of every ledger entry) covers
|
|
201
|
+
* `amount`. Legacy numeric values contribute 0 until the startup migration runs.
|
|
202
|
+
*/
|
|
203
|
+
declare function buildUserHasEnoughPointsFilter(amount: number): {
|
|
204
|
+
$expr: {
|
|
205
|
+
$gte: (number | {
|
|
206
|
+
$sum: {
|
|
207
|
+
$ifNull: (string | never[])[];
|
|
208
|
+
};
|
|
209
|
+
})[];
|
|
210
|
+
};
|
|
211
|
+
};
|
|
212
|
+
/**
|
|
213
|
+
* Debits `amount` from the oldest entries first (FIFO), flooring every entry at
|
|
214
|
+
* 0 and dropping emptied ones. Pair with `buildUserHasEnoughPointsFilter` so
|
|
215
|
+
* the full amount is always covered.
|
|
216
|
+
*
|
|
217
|
+
* Non-array `overallPoints` values are handled by `buildLedgerWriteExpr`:
|
|
218
|
+
* null/missing becomes an empty ledger, while any other shape is left untouched
|
|
219
|
+
* rather than replaced.
|
|
220
|
+
*/
|
|
221
|
+
declare function buildUserPointDebitPipeline(amount: number): {
|
|
222
|
+
$set: {
|
|
223
|
+
overallPoints: {
|
|
224
|
+
$cond: object[];
|
|
225
|
+
};
|
|
226
|
+
};
|
|
227
|
+
}[];
|
|
228
|
+
/**
|
|
229
|
+
* Removes the first ledger entry matching `pointType` (and `sourceId`, when
|
|
230
|
+
* given), reversing a single award. `$pull` cannot be used because it would
|
|
231
|
+
* remove every entry of that type.
|
|
232
|
+
*
|
|
233
|
+
* Always pass `sourceId` when the award carries one: matching on `pointType`
|
|
234
|
+
* alone would remove an unrelated award of the same type (e.g. checking out of
|
|
235
|
+
* one event stripping a different event's check-in points).
|
|
236
|
+
*
|
|
237
|
+
* Non-array `overallPoints` values are handled by `buildLedgerWriteExpr`:
|
|
238
|
+
* null/missing becomes an empty ledger, while any other shape is left untouched
|
|
239
|
+
* rather than replaced.
|
|
240
|
+
*/
|
|
241
|
+
declare function buildUserPointEntryRemovalPipeline(pointType: EnumPointType, sourceId?: string): {
|
|
242
|
+
$set: {
|
|
243
|
+
overallPoints: {
|
|
244
|
+
$cond: object[];
|
|
245
|
+
};
|
|
246
|
+
};
|
|
247
|
+
}[];
|
|
248
|
+
|
|
162
249
|
/**
|
|
163
250
|
* Recomputes dateStatus for every dateTime slot on events and google imported
|
|
164
251
|
* markets, moves ended event date slots into the event date archive, and keeps
|
|
@@ -506,4 +593,4 @@ declare function checkOwnerHasLicence({ userId, resourceType, }: {
|
|
|
506
593
|
resourceType: EnumResourceType;
|
|
507
594
|
}): Promise<void>;
|
|
508
595
|
|
|
509
|
-
export { ACTIVE_NOT_DELETED_FILTER, type AwardAffiliateVendorSubscriptionRewardsResult, LicenceCategory, type NotificationPubSub, REMINDER_WINDOW_MAX_HOURS, REMINDER_WINDOW_MIN_HOURS, SUBSCRIPTION_REWARD_TIMEZONE, activeAffiliateCodeExists, awardAffiliateVendorSubscriptionRewards, buildLicenceExpiryPipeline, checkOwnerHasLicence, connectToDatabase, convertObjectIdsToStrings, createLicenceObject, dedupeArchivedSlotsByStartDateTime, didRemoveAnyEventDates, didRemoveAnyStartedDates, downgradeVendorProFeatures, ensureUserLicenseCompliance, ensureUserLicenseComplianceForUser, 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, persistArchivedEventDates, processLicenseReminder, processUserCompliance, processUserLicenseReminders, publishNotificationEvents, remindUsersAboutLicenseExpiration, replaceUserLicenceWithObject, restoreVendorProFeatures, saveNotificationsInDb, sendDeactivationNotification, sendLicenseReminder, sendPushNotifications, sendReminderSafely, splitEventDatesForArchive, syncUserLicencesAfterExpiry, updateAdStatuses, updateAllEventDateTimeStatuses, updateRelationDatesToUnavailable, upgradeUserToLicence, vendorOwnerHasProLicence };
|
|
596
|
+
export { ACTIVE_NOT_DELETED_FILTER, type AwardAffiliateVendorSubscriptionRewardsResult, LicenceCategory, type NotificationPubSub, REMINDER_WINDOW_MAX_HOURS, REMINDER_WINDOW_MIN_HOURS, SUBSCRIPTION_REWARD_TIMEZONE, activeAffiliateCodeExists, awardAffiliateVendorSubscriptionRewards, buildLicenceExpiryPipeline, buildUserHasEnoughPointsFilter, buildUserPointAwardEntry, buildUserPointCreditFilter, buildUserPointDebitPipeline, buildUserPointEntryRemovalPipeline, checkOwnerHasLicence, connectToDatabase, convertObjectIdsToStrings, createLicenceObject, dedupeArchivedSlotsByStartDateTime, didRemoveAnyEventDates, didRemoveAnyStartedDates, downgradeVendorProFeatures, ensureUserLicenseCompliance, ensureUserLicenseComplianceForUser, 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, persistArchivedEventDates, processLicenseReminder, processUserCompliance, processUserLicenseReminders, publishNotificationEvents, remindUsersAboutLicenseExpiration, replaceUserLicenceWithObject, restoreVendorProFeatures, saveNotificationsInDb, sendDeactivationNotification, sendLicenseReminder, sendPushNotifications, sendReminderSafely, splitEventDatesForArchive, syncUserLicencesAfterExpiry, updateAdStatuses, updateAllEventDateTimeStatuses, updateRelationDatesToUnavailable, upgradeUserToLicence, vendorOwnerHasProLicence };
|
package/dist/service/index.mjs
CHANGED
|
@@ -10,7 +10,7 @@ import {
|
|
|
10
10
|
PushTokenModel,
|
|
11
11
|
UserModel,
|
|
12
12
|
VendorModel
|
|
13
|
-
} from "../chunk-
|
|
13
|
+
} from "../chunk-XGBC5DCX.mjs";
|
|
14
14
|
import "../chunk-TMPPPLIW.mjs";
|
|
15
15
|
|
|
16
16
|
// src/service/promoCode/constants.ts
|
|
@@ -611,13 +611,187 @@ function convertObjectIdsToStrings(obj) {
|
|
|
611
611
|
return obj;
|
|
612
612
|
}
|
|
613
613
|
|
|
614
|
+
// src/service/userPoints.ts
|
|
615
|
+
import dayjs2 from "dayjs";
|
|
616
|
+
function assertValidPointAmount(amount, label) {
|
|
617
|
+
if (!Number.isFinite(amount) || amount < 0) {
|
|
618
|
+
throw new RangeError(
|
|
619
|
+
`Invalid user point ${label}: ${String(amount)}. Expected a finite, non-negative number.`
|
|
620
|
+
);
|
|
621
|
+
}
|
|
622
|
+
}
|
|
623
|
+
function buildUserPointAwardEntry(pointType, points, sourceId) {
|
|
624
|
+
assertValidPointAmount(points, "award");
|
|
625
|
+
return {
|
|
626
|
+
createdAt: dayjs2().toDate(),
|
|
627
|
+
points,
|
|
628
|
+
pointType,
|
|
629
|
+
...sourceId === void 0 ? {} : { sourceId }
|
|
630
|
+
};
|
|
631
|
+
}
|
|
632
|
+
function buildUserPointCreditFilter(userId, sourceId) {
|
|
633
|
+
return {
|
|
634
|
+
_id: userId,
|
|
635
|
+
overallPoints: { $not: { $elemMatch: { sourceId } } }
|
|
636
|
+
};
|
|
637
|
+
}
|
|
638
|
+
function buildUserHasEnoughPointsFilter(amount) {
|
|
639
|
+
assertValidPointAmount(amount, "threshold");
|
|
640
|
+
return {
|
|
641
|
+
$expr: {
|
|
642
|
+
$gte: [{ $sum: { $ifNull: ["$overallPoints.points", []] } }, amount]
|
|
643
|
+
}
|
|
644
|
+
};
|
|
645
|
+
}
|
|
646
|
+
function buildLedgerWriteExpr(computedLedger) {
|
|
647
|
+
return {
|
|
648
|
+
$cond: [
|
|
649
|
+
{ $isArray: "$overallPoints" },
|
|
650
|
+
computedLedger,
|
|
651
|
+
{ $ifNull: ["$overallPoints", []] }
|
|
652
|
+
]
|
|
653
|
+
};
|
|
654
|
+
}
|
|
655
|
+
function buildUserPointDebitPipeline(amount) {
|
|
656
|
+
assertValidPointAmount(amount, "debit");
|
|
657
|
+
const debitedLedger = {
|
|
658
|
+
$let: {
|
|
659
|
+
vars: {
|
|
660
|
+
sorted: {
|
|
661
|
+
$sortArray: {
|
|
662
|
+
input: { $ifNull: ["$overallPoints", []] },
|
|
663
|
+
sortBy: { createdAt: 1 }
|
|
664
|
+
}
|
|
665
|
+
}
|
|
666
|
+
},
|
|
667
|
+
in: {
|
|
668
|
+
$let: {
|
|
669
|
+
vars: {
|
|
670
|
+
debited: {
|
|
671
|
+
$reduce: {
|
|
672
|
+
initialValue: { budget: amount, entries: [] },
|
|
673
|
+
in: {
|
|
674
|
+
$let: {
|
|
675
|
+
vars: { available: { $ifNull: ["$$this.points", 0] } },
|
|
676
|
+
in: {
|
|
677
|
+
budget: {
|
|
678
|
+
$subtract: [
|
|
679
|
+
"$$value.budget",
|
|
680
|
+
{ $min: ["$$available", "$$value.budget"] }
|
|
681
|
+
]
|
|
682
|
+
},
|
|
683
|
+
entries: {
|
|
684
|
+
$concatArrays: [
|
|
685
|
+
"$$value.entries",
|
|
686
|
+
[
|
|
687
|
+
{
|
|
688
|
+
$mergeObjects: [
|
|
689
|
+
"$$this",
|
|
690
|
+
{
|
|
691
|
+
points: {
|
|
692
|
+
$subtract: [
|
|
693
|
+
"$$available",
|
|
694
|
+
{
|
|
695
|
+
$min: ["$$available", "$$value.budget"]
|
|
696
|
+
}
|
|
697
|
+
]
|
|
698
|
+
}
|
|
699
|
+
}
|
|
700
|
+
]
|
|
701
|
+
}
|
|
702
|
+
]
|
|
703
|
+
]
|
|
704
|
+
}
|
|
705
|
+
}
|
|
706
|
+
}
|
|
707
|
+
},
|
|
708
|
+
input: "$$sorted"
|
|
709
|
+
}
|
|
710
|
+
}
|
|
711
|
+
},
|
|
712
|
+
in: {
|
|
713
|
+
$filter: {
|
|
714
|
+
as: "entry",
|
|
715
|
+
cond: { $gt: ["$$entry.points", 0] },
|
|
716
|
+
input: "$$debited.entries"
|
|
717
|
+
}
|
|
718
|
+
}
|
|
719
|
+
}
|
|
720
|
+
}
|
|
721
|
+
}
|
|
722
|
+
};
|
|
723
|
+
return [
|
|
724
|
+
{
|
|
725
|
+
$set: {
|
|
726
|
+
overallPoints: buildLedgerWriteExpr(debitedLedger)
|
|
727
|
+
}
|
|
728
|
+
}
|
|
729
|
+
];
|
|
730
|
+
}
|
|
731
|
+
function buildUserPointEntryRemovalPipeline(pointType, sourceId) {
|
|
732
|
+
const indexExpression = sourceId === void 0 ? { $indexOfArray: ["$$entries.pointType", pointType] } : {
|
|
733
|
+
$indexOfArray: [
|
|
734
|
+
{
|
|
735
|
+
$map: {
|
|
736
|
+
as: "entry",
|
|
737
|
+
in: {
|
|
738
|
+
$and: [
|
|
739
|
+
{ $eq: ["$$entry.pointType", pointType] },
|
|
740
|
+
{ $eq: ["$$entry.sourceId", sourceId] }
|
|
741
|
+
]
|
|
742
|
+
},
|
|
743
|
+
input: "$$entries"
|
|
744
|
+
}
|
|
745
|
+
},
|
|
746
|
+
true
|
|
747
|
+
]
|
|
748
|
+
};
|
|
749
|
+
const entriesAfterRemoval = {
|
|
750
|
+
$let: {
|
|
751
|
+
vars: { entries: { $ifNull: ["$overallPoints", []] } },
|
|
752
|
+
in: {
|
|
753
|
+
$let: {
|
|
754
|
+
vars: {
|
|
755
|
+
index: indexExpression
|
|
756
|
+
},
|
|
757
|
+
in: {
|
|
758
|
+
$cond: [
|
|
759
|
+
{ $lt: ["$$index", 0] },
|
|
760
|
+
"$$entries",
|
|
761
|
+
{
|
|
762
|
+
$concatArrays: [
|
|
763
|
+
{ $slice: ["$$entries", "$$index"] },
|
|
764
|
+
{
|
|
765
|
+
$slice: [
|
|
766
|
+
"$$entries",
|
|
767
|
+
{ $add: ["$$index", 1] },
|
|
768
|
+
{ $size: "$$entries" }
|
|
769
|
+
]
|
|
770
|
+
}
|
|
771
|
+
]
|
|
772
|
+
}
|
|
773
|
+
]
|
|
774
|
+
}
|
|
775
|
+
}
|
|
776
|
+
}
|
|
777
|
+
}
|
|
778
|
+
};
|
|
779
|
+
return [
|
|
780
|
+
{
|
|
781
|
+
$set: {
|
|
782
|
+
overallPoints: buildLedgerWriteExpr(entriesAfterRemoval)
|
|
783
|
+
}
|
|
784
|
+
}
|
|
785
|
+
];
|
|
786
|
+
}
|
|
787
|
+
|
|
614
788
|
// src/service/event/updateAllEventDateTimeStatuses.ts
|
|
615
789
|
import {
|
|
616
790
|
EnumEventDateStatus as EnumEventDateStatus2,
|
|
617
791
|
filterDatesByFutureStatus,
|
|
618
792
|
updateSingleDateTimeStatus
|
|
619
793
|
} from "@timardex/cluemart-shared";
|
|
620
|
-
import
|
|
794
|
+
import dayjs4 from "dayjs";
|
|
621
795
|
|
|
622
796
|
// src/service/event/archiveEndedEventDates.ts
|
|
623
797
|
import {
|
|
@@ -625,9 +799,9 @@ import {
|
|
|
625
799
|
dateFormat,
|
|
626
800
|
timeFormat
|
|
627
801
|
} from "@timardex/cluemart-shared";
|
|
628
|
-
import
|
|
802
|
+
import dayjs3 from "dayjs";
|
|
629
803
|
import customParseFormat from "dayjs/plugin/customParseFormat";
|
|
630
|
-
|
|
804
|
+
dayjs3.extend(customParseFormat);
|
|
631
805
|
var ARCHIVED_STATUSES = /* @__PURE__ */ new Set([
|
|
632
806
|
EnumEventDateStatus.ENDED
|
|
633
807
|
]);
|
|
@@ -658,7 +832,7 @@ function isPastCanceledEventDate(slot, now) {
|
|
|
658
832
|
if (slot.dateStatus !== EnumEventDateStatus.CANCELED) {
|
|
659
833
|
return false;
|
|
660
834
|
}
|
|
661
|
-
const endDateTime =
|
|
835
|
+
const endDateTime = dayjs3(
|
|
662
836
|
`${slot.endDate} ${slot.endTime}`,
|
|
663
837
|
`${dateFormat} ${timeFormat}`,
|
|
664
838
|
true
|
|
@@ -853,7 +1027,7 @@ async function cleanEventInfoDates(now) {
|
|
|
853
1027
|
return removedCount;
|
|
854
1028
|
}
|
|
855
1029
|
async function updateAllEventDateTimeStatuses() {
|
|
856
|
-
const now =
|
|
1030
|
+
const now = dayjs4();
|
|
857
1031
|
const [eventCount, marketCount] = await Promise.all([
|
|
858
1032
|
updateModelDateTimeStatuses(EventModel, now),
|
|
859
1033
|
updateModelDateTimeStatuses(
|
|
@@ -930,13 +1104,13 @@ function updateRelationDatesToUnavailable(relationDates, eventDateTime) {
|
|
|
930
1104
|
}
|
|
931
1105
|
|
|
932
1106
|
// src/service/license/compliance/ensureUserLicenseCompliance.ts
|
|
933
|
-
import
|
|
1107
|
+
import dayjs8 from "dayjs";
|
|
934
1108
|
|
|
935
1109
|
// src/service/license/compliance/utils.ts
|
|
936
1110
|
import {
|
|
937
1111
|
EnumUserLicence as EnumUserLicence7
|
|
938
1112
|
} from "@timardex/cluemart-shared";
|
|
939
|
-
import
|
|
1113
|
+
import dayjs7 from "dayjs";
|
|
940
1114
|
|
|
941
1115
|
// src/service/license/compliance/event.ts
|
|
942
1116
|
import { EnumUserLicence as EnumUserLicence3 } from "@timardex/cluemart-shared";
|
|
@@ -1174,7 +1348,7 @@ import {
|
|
|
1174
1348
|
EnumUserLicence as EnumUserLicence6,
|
|
1175
1349
|
vendorLicences
|
|
1176
1350
|
} from "@timardex/cluemart-shared";
|
|
1177
|
-
import
|
|
1351
|
+
import dayjs6 from "dayjs";
|
|
1178
1352
|
|
|
1179
1353
|
// src/service/license/models.ts
|
|
1180
1354
|
import {
|
|
@@ -1183,7 +1357,7 @@ import {
|
|
|
1183
1357
|
isNonVisitorResourceType,
|
|
1184
1358
|
LicenceExpiryDate
|
|
1185
1359
|
} from "@timardex/cluemart-shared";
|
|
1186
|
-
import
|
|
1360
|
+
import dayjs5 from "dayjs";
|
|
1187
1361
|
import { GraphQLError } from "graphql";
|
|
1188
1362
|
var LicenceCategory = /* @__PURE__ */ ((LicenceCategory2) => {
|
|
1189
1363
|
LicenceCategory2["EVENT"] = "event";
|
|
@@ -1264,7 +1438,7 @@ function getHighestLicenceForCategory(licences, category) {
|
|
|
1264
1438
|
return highestLicence;
|
|
1265
1439
|
}
|
|
1266
1440
|
function createLicenceObject(expiryDate, licenceType) {
|
|
1267
|
-
const today =
|
|
1441
|
+
const today = dayjs5();
|
|
1268
1442
|
const expiryDateMapping = {
|
|
1269
1443
|
[LicenceExpiryDate.ONE_YEAR]: today.add(1, "year").endOf("day").toDate(),
|
|
1270
1444
|
[LicenceExpiryDate.ONE_MONTH]: today.add(1, "month").endOf("day").toDate(),
|
|
@@ -1527,7 +1701,7 @@ function isProtectedByCurrentStripeSubscription(user, licenceType, now) {
|
|
|
1527
1701
|
if (!stripe || stripe.currentPlan !== licenceType) {
|
|
1528
1702
|
return false;
|
|
1529
1703
|
}
|
|
1530
|
-
const gracePeriodEndsAt = stripe.paymentGracePeriodEndsAt ?
|
|
1704
|
+
const gracePeriodEndsAt = stripe.paymentGracePeriodEndsAt ? dayjs6(stripe.paymentGracePeriodEndsAt) : null;
|
|
1531
1705
|
const hasActivePaymentGracePeriod = (stripe.status === EnumSubscriptionStatus2.PAST_DUE || stripe.status === EnumSubscriptionStatus2.INACTIVE) && Boolean(stripe.paymentGraceSubscriptionId) && (!stripe.subscriptionId || stripe.subscriptionId === stripe.paymentGraceSubscriptionId) && gracePeriodEndsAt !== null && gracePeriodEndsAt.isValid() && gracePeriodEndsAt.isAfter(now);
|
|
1532
1706
|
if (hasActivePaymentGracePeriod) {
|
|
1533
1707
|
return true;
|
|
@@ -1541,7 +1715,7 @@ function isProtectedByCurrentStripeSubscription(user, licenceType, now) {
|
|
|
1541
1715
|
if (!stripe.endDate) {
|
|
1542
1716
|
return false;
|
|
1543
1717
|
}
|
|
1544
|
-
const paidThrough =
|
|
1718
|
+
const paidThrough = dayjs6(stripe.endDate);
|
|
1545
1719
|
return paidThrough.isValid() && paidThrough.isAfter(now);
|
|
1546
1720
|
}
|
|
1547
1721
|
async function handleVendorLicenceCompliance(user, now) {
|
|
@@ -1558,7 +1732,7 @@ async function handleVendorLicenceCompliance(user, now) {
|
|
|
1558
1732
|
(licence) => licence.licenceType !== EnumUserLicence6.STANDARD_VENDOR
|
|
1559
1733
|
);
|
|
1560
1734
|
const expiredProLicences = proLicences.filter(
|
|
1561
|
-
(licence) => !
|
|
1735
|
+
(licence) => !dayjs6(licence.expiryDate).isAfter(now)
|
|
1562
1736
|
);
|
|
1563
1737
|
const stripeProtectedLicenceTypes = new Set(
|
|
1564
1738
|
expiredProLicences.filter(
|
|
@@ -1570,7 +1744,7 @@ async function handleVendorLicenceCompliance(user, now) {
|
|
|
1570
1744
|
);
|
|
1571
1745
|
const hasValidProLicence = stripeProtectedLicenceTypes.size > 0 || hasValidLicence(proLicences, vendorLicences, now);
|
|
1572
1746
|
const hasExpiredVendorLicence = vendorLicencesOfUser.some(
|
|
1573
|
-
(licence) => !
|
|
1747
|
+
(licence) => !dayjs6(licence.expiryDate).isAfter(now) && !stripeProtectedLicenceTypes.has(licence.licenceType)
|
|
1574
1748
|
);
|
|
1575
1749
|
if (!hasExpiredVendorLicence) {
|
|
1576
1750
|
return;
|
|
@@ -1624,9 +1798,9 @@ async function vendorOwnerHasProLicence(vendorId) {
|
|
|
1624
1798
|
if (!owner) {
|
|
1625
1799
|
return false;
|
|
1626
1800
|
}
|
|
1627
|
-
const now =
|
|
1801
|
+
const now = dayjs6();
|
|
1628
1802
|
const effectiveVendorLicences = owner.licences?.filter(
|
|
1629
|
-
(licence) => licence?.licenceType && (
|
|
1803
|
+
(licence) => licence?.licenceType && (dayjs6(licence.expiryDate).isAfter(now) || isProtectedByCurrentStripeSubscription(
|
|
1630
1804
|
owner,
|
|
1631
1805
|
licence.licenceType,
|
|
1632
1806
|
now
|
|
@@ -1663,7 +1837,7 @@ async function syncUserLicencesAfterExpiry(userId, licenceTypes, now, mode = "do
|
|
|
1663
1837
|
}
|
|
1664
1838
|
function hasValidLicence(licences, licenceTypes, now) {
|
|
1665
1839
|
return licences.some(
|
|
1666
|
-
(licence) => licenceTypes.includes(licence.licenceType) &&
|
|
1840
|
+
(licence) => licenceTypes.includes(licence.licenceType) && dayjs7(licence.expiryDate).isAfter(now)
|
|
1667
1841
|
);
|
|
1668
1842
|
}
|
|
1669
1843
|
async function sendDeactivationNotification(payload, userId, resourceName, resourceType) {
|
|
@@ -1690,7 +1864,7 @@ async function processUserCompliance(user, now) {
|
|
|
1690
1864
|
}
|
|
1691
1865
|
|
|
1692
1866
|
// src/service/license/compliance/ensureUserLicenseCompliance.ts
|
|
1693
|
-
async function ensureUserLicenseComplianceForUser(userId, now =
|
|
1867
|
+
async function ensureUserLicenseComplianceForUser(userId, now = dayjs8()) {
|
|
1694
1868
|
const user = await UserModel.findById(userId);
|
|
1695
1869
|
if (!user) {
|
|
1696
1870
|
return;
|
|
@@ -1698,7 +1872,7 @@ async function ensureUserLicenseComplianceForUser(userId, now = dayjs7()) {
|
|
|
1698
1872
|
await processUserCompliance(user, now);
|
|
1699
1873
|
}
|
|
1700
1874
|
async function ensureUserLicenseCompliance() {
|
|
1701
|
-
const now =
|
|
1875
|
+
const now = dayjs8();
|
|
1702
1876
|
console.log(`\u{1F50D} Checking license compliance at ${now.format()}`);
|
|
1703
1877
|
const nowDate = now.toDate();
|
|
1704
1878
|
const users = await UserModel.find({
|
|
@@ -1773,7 +1947,7 @@ async function getPartnerResourceInfo(userId, partnerId) {
|
|
|
1773
1947
|
}
|
|
1774
1948
|
|
|
1775
1949
|
// src/service/license/reminder/remindUsersAboutLicenseExpiration.ts
|
|
1776
|
-
import
|
|
1950
|
+
import dayjs10 from "dayjs";
|
|
1777
1951
|
|
|
1778
1952
|
// src/service/license/reminder/reminderWindow.ts
|
|
1779
1953
|
var REMINDER_WINDOW_MIN_HOURS = 6.5 * 24;
|
|
@@ -1789,7 +1963,7 @@ import {
|
|
|
1789
1963
|
vendorLicences as vendorLicences2
|
|
1790
1964
|
} from "@timardex/cluemart-shared";
|
|
1791
1965
|
import { formatDate } from "@timardex/cluemart-shared/utils";
|
|
1792
|
-
import
|
|
1966
|
+
import dayjs9 from "dayjs";
|
|
1793
1967
|
|
|
1794
1968
|
// src/service/license/reminder/vendor.ts
|
|
1795
1969
|
async function getVendorResourceInfo(userId, vendorId) {
|
|
@@ -1848,7 +2022,7 @@ async function checkAndCreateNotification(payload) {
|
|
|
1848
2022
|
}
|
|
1849
2023
|
}
|
|
1850
2024
|
function isLicenseExpiringIn7Days(expiryDate, now) {
|
|
1851
|
-
const expiry =
|
|
2025
|
+
const expiry = dayjs9(expiryDate);
|
|
1852
2026
|
const hoursUntilExpiry = expiry.diff(now, "hour", true);
|
|
1853
2027
|
return hoursUntilExpiry >= REMINDER_WINDOW_MIN_HOURS && hoursUntilExpiry <= REMINDER_WINDOW_MAX_HOURS;
|
|
1854
2028
|
}
|
|
@@ -1926,7 +2100,7 @@ function getLicenceExpiryMode(licenceType) {
|
|
|
1926
2100
|
}
|
|
1927
2101
|
async function sendLicenseReminder(user, licence) {
|
|
1928
2102
|
const licenceName = getLicenseName(licence.licenceType);
|
|
1929
|
-
const expiryDate =
|
|
2103
|
+
const expiryDate = dayjs9(licence.expiryDate).format(dateFormat2);
|
|
1930
2104
|
const userId = String(user._id);
|
|
1931
2105
|
const resourceInfo = await getLicenseResourceInfo(user, licence);
|
|
1932
2106
|
if (!resourceInfo) {
|
|
@@ -1958,7 +2132,7 @@ async function sendLicenseReminder(user, licence) {
|
|
|
1958
2132
|
console.log(`\u2705 Sent 7-day reminder to user ${userId} for ${licenceName}`);
|
|
1959
2133
|
}
|
|
1960
2134
|
async function processLicenseReminder(licence, now) {
|
|
1961
|
-
if (
|
|
2135
|
+
if (dayjs9(licence.expiryDate).isBefore(now)) {
|
|
1962
2136
|
return false;
|
|
1963
2137
|
}
|
|
1964
2138
|
if (!isLicenseExpiringIn7Days(licence.expiryDate, now)) {
|
|
@@ -2012,7 +2186,7 @@ async function processUserLicenseReminders(user, now) {
|
|
|
2012
2186
|
|
|
2013
2187
|
// src/service/license/reminder/remindUsersAboutLicenseExpiration.ts
|
|
2014
2188
|
async function remindUsersAboutLicenseExpiration() {
|
|
2015
|
-
const now =
|
|
2189
|
+
const now = dayjs10();
|
|
2016
2190
|
console.log(`\u{1F50D} Checking for licenses expiring in 7 days at ${now.format()}`);
|
|
2017
2191
|
const minExpiryDate = now.add(REMINDER_WINDOW_MIN_HOURS, "hour").toDate();
|
|
2018
2192
|
const maxExpiryDate = now.add(REMINDER_WINDOW_MAX_HOURS, "hour").toDate();
|
|
@@ -2058,6 +2232,11 @@ export {
|
|
|
2058
2232
|
activeAffiliateCodeExists,
|
|
2059
2233
|
awardAffiliateVendorSubscriptionRewards,
|
|
2060
2234
|
buildLicenceExpiryPipeline,
|
|
2235
|
+
buildUserHasEnoughPointsFilter,
|
|
2236
|
+
buildUserPointAwardEntry,
|
|
2237
|
+
buildUserPointCreditFilter,
|
|
2238
|
+
buildUserPointDebitPipeline,
|
|
2239
|
+
buildUserPointEntryRemovalPipeline,
|
|
2061
2240
|
checkOwnerHasLicence,
|
|
2062
2241
|
connectToDatabase,
|
|
2063
2242
|
convertObjectIdsToStrings,
|