@timardex/cluemart-server-shared 2.2.0 → 2.2.2

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,11 +1,12 @@
1
1
  import * as mongoose from 'mongoose';
2
2
  import * as _timardex_cluemart_shared from '@timardex/cluemart-shared';
3
3
  import { PromoCodeType, EnumAffiliateRewardType, DateTimeType, EventListItemType, DateTimeWithPriceType, EnumUserLicence as EnumUserLicence$1, UserLicenceType, EnumNotificationResourceType, EnumNotificationType, EnumResourceType, LicenceExpiryDate } from '@timardex/cluemart-shared';
4
- import { d as SchemaAffiliateResourceType, S as SchemaOwnerType, g as SchemaRelationType, j as SchemaUserType } from '../Affiliate-i11rkfv5.mjs';
5
- import { O as ObjectId, G as GraphQLContext, e as SchemaCreateBulkNotificationInput } from '../index-Bq-lT7a2.mjs';
6
- import dayjs, { Dayjs } from 'dayjs';
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';
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';
9
+ import dayjs, { Dayjs } from 'dayjs';
9
10
  import 'express';
10
11
 
11
12
  /**
@@ -127,9 +128,8 @@ declare function publishNotificationEvents(userId: ObjectId, pubsub: Notificatio
127
128
  * is provided) publishes GraphQL subscription events for each affected user.
128
129
  *
129
130
  * Errors are logged and swallowed; this function never throws. Instead it
130
- * returns `false` when notifications were not confirmed (an error was thrown,
131
- * or `saveNotificationsInDb` failed to persist any rows for a non-empty
132
- * `userIds`), so callers can gate success logs/metrics on the result.
131
+ * returns `false` when notifications were not confirmed, so callers can gate
132
+ * success logs/metrics on the result.
133
133
  */
134
134
  declare function notifyUsers({ payload, pubsub, }: {
135
135
  payload: SchemaCreateBulkNotificationInput;
@@ -159,14 +159,6 @@ declare function isValidObjectId(value: string): boolean;
159
159
  */
160
160
  declare function convertObjectIdsToStrings(obj: any): any;
161
161
 
162
- /**
163
- * Updates the dateStatus field for a single DateTimeType object based on the current date/time.
164
- * Manual statuses (CANCELED, RE_SCHEDULED) are preserved and returned as-is.
165
- * @param dateTime The date-time object to update
166
- * @returns A new object with an updated dateStatus value, or the original
167
- * object when the stored status is a manual override
168
- */
169
- declare function updateSingleDateTimeStatus<T extends DateTimeType>(dateTime: T, now?: dayjs.Dayjs): T;
170
162
  /**
171
163
  * Recomputes dateStatus for every dateTime slot on events and google imported
172
164
  * markets, moves ended event date slots into the event date archive, and keeps
@@ -501,4 +493,4 @@ declare function checkOwnerHasLicence({ userId, resourceType, }: {
501
493
  resourceType: EnumResourceType;
502
494
  }): Promise<void>;
503
495
 
504
- 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, updateSingleDateTimeStatus, upgradeUserToLicence, vendorOwnerHasProLicence };
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 };
@@ -1,11 +1,12 @@
1
1
  import * as mongoose from 'mongoose';
2
2
  import * as _timardex_cluemart_shared from '@timardex/cluemart-shared';
3
3
  import { PromoCodeType, EnumAffiliateRewardType, DateTimeType, EventListItemType, DateTimeWithPriceType, EnumUserLicence as EnumUserLicence$1, UserLicenceType, EnumNotificationResourceType, EnumNotificationType, EnumResourceType, LicenceExpiryDate } from '@timardex/cluemart-shared';
4
- import { d as SchemaAffiliateResourceType, S as SchemaOwnerType, g as SchemaRelationType, j as SchemaUserType } from '../Affiliate-BSF7Wm6O.js';
5
- import { O as ObjectId, G as GraphQLContext, e as SchemaCreateBulkNotificationInput } from '../index-Bq-lT7a2.js';
6
- import dayjs, { Dayjs } from 'dayjs';
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';
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';
9
+ import dayjs, { Dayjs } from 'dayjs';
9
10
  import 'express';
10
11
 
11
12
  /**
@@ -127,9 +128,8 @@ declare function publishNotificationEvents(userId: ObjectId, pubsub: Notificatio
127
128
  * is provided) publishes GraphQL subscription events for each affected user.
128
129
  *
129
130
  * Errors are logged and swallowed; this function never throws. Instead it
130
- * returns `false` when notifications were not confirmed (an error was thrown,
131
- * or `saveNotificationsInDb` failed to persist any rows for a non-empty
132
- * `userIds`), so callers can gate success logs/metrics on the result.
131
+ * returns `false` when notifications were not confirmed, so callers can gate
132
+ * success logs/metrics on the result.
133
133
  */
134
134
  declare function notifyUsers({ payload, pubsub, }: {
135
135
  payload: SchemaCreateBulkNotificationInput;
@@ -159,14 +159,6 @@ declare function isValidObjectId(value: string): boolean;
159
159
  */
160
160
  declare function convertObjectIdsToStrings(obj: any): any;
161
161
 
162
- /**
163
- * Updates the dateStatus field for a single DateTimeType object based on the current date/time.
164
- * Manual statuses (CANCELED, RE_SCHEDULED) are preserved and returned as-is.
165
- * @param dateTime The date-time object to update
166
- * @returns A new object with an updated dateStatus value, or the original
167
- * object when the stored status is a manual override
168
- */
169
- declare function updateSingleDateTimeStatus<T extends DateTimeType>(dateTime: T, now?: dayjs.Dayjs): T;
170
162
  /**
171
163
  * Recomputes dateStatus for every dateTime slot on events and google imported
172
164
  * markets, moves ended event date slots into the event date archive, and keeps
@@ -501,4 +493,4 @@ declare function checkOwnerHasLicence({ userId, resourceType, }: {
501
493
  resourceType: EnumResourceType;
502
494
  }): Promise<void>;
503
495
 
504
- 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, updateSingleDateTimeStatus, upgradeUserToLicence, vendorOwnerHasProLicence };
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 };
@@ -10,8 +10,8 @@ import {
10
10
  PushTokenModel,
11
11
  UserModel,
12
12
  VendorModel
13
- } from "../chunk-HLRUWJLN.mjs";
14
- import "../chunk-6PNG5BI5.mjs";
13
+ } from "../chunk-TIGQ6F5T.mjs";
14
+ import "../chunk-TMPPPLIW.mjs";
15
15
 
16
16
  // src/service/promoCode/constants.ts
17
17
  var ACTIVE_NOT_DELETED_FILTER = {
@@ -39,25 +39,24 @@ import { createAffiliateReward } from "@timardex/cluemart-shared/utils";
39
39
  // src/service/saveNotificationsInDb.ts
40
40
  async function saveNotificationsInDb(payload) {
41
41
  const { data, message, title, type, userIds } = payload;
42
- console.log("NOTIFICATION DATA", JSON.stringify(payload, null, 2));
42
+ const notifications = userIds.map((userId) => ({
43
+ data,
44
+ isRead: false,
45
+ message,
46
+ title,
47
+ type,
48
+ userId
49
+ }));
43
50
  try {
44
- const notifications = userIds.map((userId) => ({
45
- data,
46
- isRead: false,
47
- message,
48
- title,
49
- type,
50
- userId
51
- }));
52
51
  await NotificationModel.insertMany(notifications);
53
- console.log(
54
- `Created ${notifications.length} notifications for ${userIds.length} users`
55
- );
56
- return [...new Set(userIds)];
57
52
  } catch (error) {
58
53
  console.error("Failed to create notifications:", error);
59
- return [];
54
+ throw error;
60
55
  }
56
+ console.log(
57
+ `Created ${notifications.length} notifications for ${userIds.length} users`
58
+ );
59
+ return [...new Set(userIds)];
61
60
  }
62
61
 
63
62
  // src/service/sendPushNotifications.ts
@@ -81,7 +80,7 @@ function createPushMessages({
81
80
  }
82
81
  messages.push({
83
82
  body: message,
84
- data: { ...data },
83
+ ...data ? { data: { ...data } } : {},
85
84
  sound: "tui.wav",
86
85
  title,
87
86
  to: token
@@ -136,7 +135,6 @@ async function sendPushNotifications({
136
135
  }) {
137
136
  const pushTokens = await PushTokenModel.find({ userId: { $in: userIds } });
138
137
  const expoTokens = pushTokens.map((token) => token.token);
139
- if (!data) return;
140
138
  const { messages, invalidTokens } = createPushMessages({
141
139
  data,
142
140
  message,
@@ -615,14 +613,11 @@ function convertObjectIdsToStrings(obj) {
615
613
 
616
614
  // src/service/event/updateAllEventDateTimeStatuses.ts
617
615
  import {
618
- dateFormat,
619
616
  EnumEventDateStatus as EnumEventDateStatus2,
620
617
  filterDatesByFutureStatus,
621
- timeFormat
618
+ updateSingleDateTimeStatus
622
619
  } from "@timardex/cluemart-shared";
623
620
  import dayjs2 from "dayjs";
624
- import customParseFormat from "dayjs/plugin/customParseFormat";
625
- import isoWeek from "dayjs/plugin/isoWeek";
626
621
 
627
622
  // src/service/event/archiveEndedEventDates.ts
628
623
  import { EnumEventDateStatus } from "@timardex/cluemart-shared";
@@ -665,73 +660,6 @@ async function persistArchivedEventDates(eventId, slots) {
665
660
  }
666
661
 
667
662
  // src/service/event/updateAllEventDateTimeStatuses.ts
668
- dayjs2.extend(customParseFormat);
669
- dayjs2.extend(isoWeek);
670
- var MANUAL_DATE_STATUSES = /* @__PURE__ */ new Set([
671
- EnumEventDateStatus2.CANCELED,
672
- EnumEventDateStatus2.RE_SCHEDULED
673
- ]);
674
- function getFutureEventStatus(startDateTime, now) {
675
- const hoursUntilStart = startDateTime.diff(now, "hour", true);
676
- if (hoursUntilStart > 0 && hoursUntilStart <= 4) {
677
- return EnumEventDateStatus2.STARTING_SOON;
678
- }
679
- if (startDateTime.isSame(now, "day")) {
680
- return EnumEventDateStatus2.TODAY;
681
- }
682
- if (startDateTime.isSame(now.add(1, "day"), "day")) {
683
- return EnumEventDateStatus2.TOMORROW;
684
- }
685
- if (startDateTime.isSame(now, "isoWeek")) {
686
- return EnumEventDateStatus2.THIS_WEEK;
687
- }
688
- if (startDateTime.isSame(now.add(1, "week"), "isoWeek")) {
689
- return EnumEventDateStatus2.NEXT_WEEK;
690
- }
691
- return EnumEventDateStatus2.UPCOMING;
692
- }
693
- function updateSingleDateTimeStatus(dateTime, now = dayjs2()) {
694
- if (MANUAL_DATE_STATUSES.has(dateTime.dateStatus)) {
695
- return dateTime;
696
- }
697
- const dateTimeFormat = `${dateFormat} ${timeFormat}`;
698
- const startDateTime = dayjs2(
699
- `${dateTime.startDate} ${dateTime.startTime}`,
700
- dateTimeFormat,
701
- true
702
- );
703
- const endDateTime = dayjs2(
704
- `${dateTime.endDate} ${dateTime.endTime}`,
705
- dateTimeFormat,
706
- true
707
- );
708
- if (!startDateTime.isValid() || !endDateTime.isValid()) {
709
- return {
710
- ...dateTime,
711
- dateStatus: EnumEventDateStatus2.INVALID
712
- };
713
- }
714
- if (endDateTime.isBefore(startDateTime)) {
715
- return {
716
- ...dateTime,
717
- dateStatus: EnumEventDateStatus2.INVALID
718
- };
719
- }
720
- let dateStatus;
721
- if (endDateTime.isAfter(now)) {
722
- if (startDateTime.isAfter(now)) {
723
- dateStatus = getFutureEventStatus(startDateTime, now);
724
- } else {
725
- dateStatus = EnumEventDateStatus2.STARTED;
726
- }
727
- } else {
728
- dateStatus = EnumEventDateStatus2.ENDED;
729
- }
730
- return {
731
- ...dateTime,
732
- dateStatus
733
- };
734
- }
735
663
  var dateTimeStatusFilter = {
736
664
  dateTime: { $ne: [], $type: "array" },
737
665
  deletedAt: null
@@ -910,6 +838,9 @@ async function updateAllEventDateTimeStatuses() {
910
838
  }
911
839
  }
912
840
 
841
+ // src/service/index.ts
842
+ import { updateSingleDateTimeStatus as updateSingleDateTimeStatus2 } from "@timardex/cluemart-shared";
843
+
913
844
  // src/service/event/findEventOrImportedMarketById.ts
914
845
  async function findEventOrImportedMarketById(resourceId) {
915
846
  if (!resourceId) {
@@ -1801,7 +1732,7 @@ var REMINDER_WINDOW_MAX_HOURS = 7.5 * 24;
1801
1732
 
1802
1733
  // src/service/license/reminder/utils.ts
1803
1734
  import {
1804
- dateFormat as dateFormat2,
1735
+ dateFormat,
1805
1736
  EnumNotificationResourceType as EnumNotificationResourceType4,
1806
1737
  EnumNotificationType as EnumNotificationType4,
1807
1738
  EnumUserLicence as EnumUserLicence8,
@@ -1946,7 +1877,7 @@ function getLicenceExpiryMode(licenceType) {
1946
1877
  }
1947
1878
  async function sendLicenseReminder(user, licence) {
1948
1879
  const licenceName = getLicenseName(licence.licenceType);
1949
- const expiryDate = dayjs7(licence.expiryDate).format(dateFormat2);
1880
+ const expiryDate = dayjs7(licence.expiryDate).format(dateFormat);
1950
1881
  const userId = String(user._id);
1951
1882
  const resourceInfo = await getLicenseResourceInfo(user, licence);
1952
1883
  if (!resourceInfo) {
@@ -2131,7 +2062,7 @@ export {
2131
2062
  updateAdStatuses,
2132
2063
  updateAllEventDateTimeStatuses,
2133
2064
  updateRelationDatesToUnavailable,
2134
- updateSingleDateTimeStatus,
2065
+ updateSingleDateTimeStatus2 as updateSingleDateTimeStatus,
2135
2066
  upgradeUserToLicence,
2136
2067
  vendorOwnerHasProLicence
2137
2068
  };