@timardex/cluemart-server-shared 2.2.22 → 2.2.30

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -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-6AEy-gNx.mjs';
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`: a
218
+ * legacy number is written back unchanged (treating it as an empty ledger would
219
+ * delete the stored balance), while null/missing becomes an empty ledger.
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`: a
238
+ * legacy number is written back unchanged so the stored balance is never
239
+ * replaced, while null/missing becomes an empty ledger.
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
@@ -207,11 +294,24 @@ type EventOrMarket = (Pick<EventListItemType, "_id" | "name" | "dateTime"> & {
207
294
  declare function findEventOrImportedMarketById(resourceId: ObjectId | string | null | undefined): Promise<EventOrMarket>;
208
295
 
209
296
  type EventDateSlot = Pick<DateTimeType$1, "startDate" | "startTime">;
297
+ type StartedDateSlot = Pick<DateTimeType$1, "dateStatus" | "startDate" | "startTime">;
210
298
  /**
211
299
  * Returns true when at least one startDate/startTime slot from the previous
212
300
  * schedule is absent from the next schedule (i.e. a date was removed).
213
301
  */
214
302
  declare function didRemoveAnyEventDates(previousDateTime: EventDateSlot[] | undefined, nextDateTime: EventDateSlot[] | undefined): boolean;
303
+ /**
304
+ * Returns true when a slot that was `STARTED` in the previous schedule is no
305
+ * longer `STARTED` in the next schedule (e.g. canceled or rescheduled).
306
+ *
307
+ * This catches the `STARTED → CANCELED` transition that
308
+ * {@link didRemoveAnyEventDates} misses: that function only compares
309
+ * `startDate`/`startTime` presence, so a slot that still exists but whose
310
+ * `dateStatus` changed is not flagged. (Its callers filter to future-only
311
+ * schedules, which also drop `STARTED`.) Without this extra status check, a
312
+ * started slot that gets canceled would leave its relation dates untouched.
313
+ */
314
+ declare function didRemoveAnyStartedDates(previousDateTime: StartedDateSlot[] | undefined, nextDateTime: StartedDateSlot[] | undefined): boolean;
215
315
  /**
216
316
  * Helper: Update relationDates based on event's dateTime
217
317
  * Marks dates as UNAVAILABLE if they no longer exist in the event's dateTime.
@@ -493,4 +593,4 @@ declare function checkOwnerHasLicence({ userId, resourceType, }: {
493
593
  resourceType: EnumResourceType;
494
594
  }): Promise<void>;
495
595
 
496
- 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, 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 };
@@ -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-D40kRxO_.js';
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`: a
218
+ * legacy number is written back unchanged (treating it as an empty ledger would
219
+ * delete the stored balance), while null/missing becomes an empty ledger.
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`: a
238
+ * legacy number is written back unchanged so the stored balance is never
239
+ * replaced, while null/missing becomes an empty ledger.
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
@@ -207,11 +294,24 @@ type EventOrMarket = (Pick<EventListItemType, "_id" | "name" | "dateTime"> & {
207
294
  declare function findEventOrImportedMarketById(resourceId: ObjectId | string | null | undefined): Promise<EventOrMarket>;
208
295
 
209
296
  type EventDateSlot = Pick<DateTimeType$1, "startDate" | "startTime">;
297
+ type StartedDateSlot = Pick<DateTimeType$1, "dateStatus" | "startDate" | "startTime">;
210
298
  /**
211
299
  * Returns true when at least one startDate/startTime slot from the previous
212
300
  * schedule is absent from the next schedule (i.e. a date was removed).
213
301
  */
214
302
  declare function didRemoveAnyEventDates(previousDateTime: EventDateSlot[] | undefined, nextDateTime: EventDateSlot[] | undefined): boolean;
303
+ /**
304
+ * Returns true when a slot that was `STARTED` in the previous schedule is no
305
+ * longer `STARTED` in the next schedule (e.g. canceled or rescheduled).
306
+ *
307
+ * This catches the `STARTED → CANCELED` transition that
308
+ * {@link didRemoveAnyEventDates} misses: that function only compares
309
+ * `startDate`/`startTime` presence, so a slot that still exists but whose
310
+ * `dateStatus` changed is not flagged. (Its callers filter to future-only
311
+ * schedules, which also drop `STARTED`.) Without this extra status check, a
312
+ * started slot that gets canceled would leave its relation dates untouched.
313
+ */
314
+ declare function didRemoveAnyStartedDates(previousDateTime: StartedDateSlot[] | undefined, nextDateTime: StartedDateSlot[] | undefined): boolean;
215
315
  /**
216
316
  * Helper: Update relationDates based on event's dateTime
217
317
  * Marks dates as UNAVAILABLE if they no longer exist in the event's dateTime.
@@ -493,4 +593,4 @@ declare function checkOwnerHasLicence({ userId, resourceType, }: {
493
593
  resourceType: EnumResourceType;
494
594
  }): Promise<void>;
495
595
 
496
- 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, 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 };